1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, 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_Dist; use Exp_Dist;
41 with Exp_Util; use Exp_Util;
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;
87 with Warnsw; use Warnsw;
89 package body Sem_Prag is
91 ----------------------------------------------
92 -- Common Handling of Import-Export Pragmas --
93 ----------------------------------------------
95 -- In the following section, a number of Import_xxx and Export_xxx pragmas
96 -- are defined by GNAT. These are compatible with the DEC pragmas of the
97 -- same name, and all have the following common form and processing:
100 -- [Internal =>] LOCAL_NAME
101 -- [, [External =>] EXTERNAL_SYMBOL]
102 -- [, other optional parameters ]);
105 -- [Internal =>] LOCAL_NAME
106 -- [, [External =>] EXTERNAL_SYMBOL]
107 -- [, other optional parameters ]);
109 -- EXTERNAL_SYMBOL ::=
111 -- | static_string_EXPRESSION
113 -- The internal LOCAL_NAME designates the entity that is imported or
114 -- exported, and must refer to an entity in the current declarative
115 -- part (as required by the rules for LOCAL_NAME).
117 -- The external linker name is designated by the External parameter if
118 -- given, or the Internal parameter if not (if there is no External
119 -- parameter, the External parameter is a copy of the Internal name).
121 -- If the External parameter is given as a string, then this string is
122 -- treated as an external name (exactly as though it had been given as an
123 -- External_Name parameter for a normal Import pragma).
125 -- If the External parameter is given as an identifier (or there is no
126 -- External parameter, so that the Internal identifier is used), then
127 -- the external name is the characters of the identifier, translated
128 -- to all upper case letters for OpenVMS versions of GNAT, and to all
129 -- lower case letters for all other versions
131 -- Note: the external name specified or implied by any of these special
132 -- Import_xxx or Export_xxx pragmas override an external or link name
133 -- specified in a previous Import or Export pragma.
135 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
136 -- named notation, following the standard rules for subprogram calls, i.e.
137 -- parameters can be given in any order if named notation is used, and
138 -- positional and named notation can be mixed, subject to the rule that all
139 -- positional parameters must appear first.
141 -- Note: All these pragmas are implemented exactly following the DEC design
142 -- and implementation and are intended to be fully compatible with the use
143 -- of these pragmas in the DEC Ada compiler.
145 --------------------------------------------
146 -- Checking for Duplicated External Names --
147 --------------------------------------------
149 -- It is suspicious if two separate Export pragmas use the same external
150 -- name. The following table is used to diagnose this situation so that
151 -- an appropriate warning can be issued.
153 -- The Node_Id stored is for the N_String_Literal node created to hold
154 -- the value of the external name. The Sloc of this node is used to
155 -- cross-reference the location of the duplication.
157 package Externals is new Table.Table (
158 Table_Component_Type => Node_Id,
159 Table_Index_Type => Int,
160 Table_Low_Bound => 0,
161 Table_Initial => 100,
162 Table_Increment => 100,
163 Table_Name => "Name_Externals");
165 -------------------------------------
166 -- Local Subprograms and Variables --
167 -------------------------------------
169 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
170 -- This routine is used for possible casing adjustment of an explicit
171 -- external name supplied as a string literal (the node N), according to
172 -- the casing requirement of Opt.External_Name_Casing. If this is set to
173 -- As_Is, then the string literal is returned unchanged, but if it is set
174 -- to Uppercase or Lowercase, then a new string literal with appropriate
175 -- casing is constructed.
177 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
178 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
179 -- original one, following the renaming chain) is returned. Otherwise the
180 -- entity is returned unchanged. Should be in Einfo???
182 procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id);
183 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
184 -- of a Test_Case pragma if present (possibly Empty). We treat these as
185 -- spec expressions (i.e. similar to a default expression).
188 -- This is a dummy function called by the processing for pragma Reviewable.
189 -- It is there for assisting front end debugging. By placing a Reviewable
190 -- pragma in the source program, a breakpoint on rv catches this place in
191 -- the source, allowing convenient stepping to the point of interest.
193 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
194 -- Place semantic information on the argument of an Elaborate/Elaborate_All
195 -- pragma. Entity name for unit and its parents is taken from item in
196 -- previous with_clause that mentions the unit.
198 -------------------------------
199 -- Adjust_External_Name_Case --
200 -------------------------------
202 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
206 -- Adjust case of literal if required
208 if Opt.External_Name_Exp_Casing = As_Is then
212 -- Copy existing string
218 for J in 1 .. String_Length (Strval (N)) loop
219 CC := Get_String_Char (Strval (N), J);
221 if Opt.External_Name_Exp_Casing = Uppercase
222 and then CC >= Get_Char_Code ('a')
223 and then CC <= Get_Char_Code ('z')
225 Store_String_Char (CC - 32);
227 elsif Opt.External_Name_Exp_Casing = Lowercase
228 and then CC >= Get_Char_Code ('A')
229 and then CC <= Get_Char_Code ('Z')
231 Store_String_Char (CC + 32);
234 Store_String_Char (CC);
239 Make_String_Literal (Sloc (N),
240 Strval => End_String);
242 end Adjust_External_Name_Case;
244 ------------------------------
245 -- Analyze_PPC_In_Decl_Part --
246 ------------------------------
248 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
249 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
252 -- Install formals and push subprogram spec onto scope stack so that we
253 -- can see the formals from the pragma.
258 -- Preanalyze the boolean expression, we treat this as a spec expression
259 -- (i.e. similar to a default expression).
261 Preanalyze_Spec_Expression
262 (Get_Pragma_Arg (Arg1), Standard_Boolean);
264 -- Remove the subprogram from the scope stack now that the pre-analysis
265 -- of the precondition/postcondition is done.
268 end Analyze_PPC_In_Decl_Part;
274 procedure Analyze_Pragma (N : Node_Id) is
275 Loc : constant Source_Ptr := Sloc (N);
276 Pname : constant Name_Id := Pragma_Name (N);
279 Pragma_Exit : exception;
280 -- This exception is used to exit pragma processing completely. It is
281 -- used when an error is detected, and no further processing is
282 -- required. It is also used if an earlier error has left the tree in
283 -- a state where the pragma should not be processed.
286 -- Number of pragma argument associations
292 -- First four pragma arguments (pragma argument association nodes, or
293 -- Empty if the corresponding argument does not exist).
295 type Name_List is array (Natural range <>) of Name_Id;
296 type Args_List is array (Natural range <>) of Node_Id;
297 -- Types used for arguments to Check_Arg_Order and Gather_Associations
299 procedure Ada_2005_Pragma;
300 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
301 -- Ada 95 mode, these are implementation defined pragmas, so should be
302 -- caught by the No_Implementation_Pragmas restriction.
304 procedure Ada_2012_Pragma;
305 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
306 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
307 -- should be caught by the No_Implementation_Pragmas restriction.
309 procedure Check_Ada_83_Warning;
310 -- Issues a warning message for the current pragma if operating in Ada
311 -- 83 mode (used for language pragmas that are not a standard part of
312 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
315 procedure Check_Arg_Count (Required : Nat);
316 -- Check argument count for pragma is equal to given parameter. If not,
317 -- then issue an error message and raise Pragma_Exit.
319 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
320 -- Arg which can either be a pragma argument association, in which case
321 -- the check is applied to the expression of the association or an
322 -- expression directly.
324 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
325 -- Check that an argument has the right form for an EXTERNAL_NAME
326 -- parameter of an extended import/export pragma. The rule is that the
327 -- name must be an identifier or string literal (in Ada 83 mode) or a
328 -- static string expression (in Ada 95 mode).
330 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
331 -- Check the specified argument Arg to make sure that it is an
332 -- identifier. If not give error and raise Pragma_Exit.
334 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
335 -- Check the specified argument Arg to make sure that it is an integer
336 -- literal. If not give error and raise Pragma_Exit.
338 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
339 -- Check the specified argument Arg to make sure that it has the proper
340 -- syntactic form for a local name and meets the semantic requirements
341 -- for a local name. The local name is analyzed as part of the
342 -- processing for this call. In addition, the local name is required
343 -- to represent an entity at the library level.
345 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
346 -- Check the specified argument Arg to make sure that it has the proper
347 -- syntactic form for a local name and meets the semantic requirements
348 -- for a local name. The local name is analyzed as part of the
349 -- processing for this call.
351 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
352 -- Check the specified argument Arg to make sure that it is a valid
353 -- locking policy name. If not give error and raise Pragma_Exit.
355 procedure Check_Arg_Is_One_Of
358 procedure Check_Arg_Is_One_Of
360 N1, N2, N3 : Name_Id);
361 procedure Check_Arg_Is_One_Of
363 N1, N2, N3, N4, N5 : Name_Id);
364 -- Check the specified argument Arg to make sure that it is an
365 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
366 -- present). If not then give error and raise Pragma_Exit.
368 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
369 -- Check the specified argument Arg to make sure that it is a valid
370 -- queuing policy name. If not give error and raise Pragma_Exit.
372 procedure Check_Arg_Is_Static_Expression
374 Typ : Entity_Id := Empty);
375 -- Check the specified argument Arg to make sure that it is a static
376 -- expression of the given type (i.e. it will be analyzed and resolved
377 -- using this type, which can be any valid argument to Resolve, e.g.
378 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
379 -- Typ is left Empty, then any static expression is allowed.
381 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
382 -- Check the specified argument Arg to make sure that it is a valid task
383 -- dispatching policy name. If not give error and raise Pragma_Exit.
385 procedure Check_Arg_Order (Names : Name_List);
386 -- Checks for an instance of two arguments with identifiers for the
387 -- current pragma which are not in the sequence indicated by Names,
388 -- and if so, generates a fatal message about bad order of arguments.
390 procedure Check_At_Least_N_Arguments (N : Nat);
391 -- Check there are at least N arguments present
393 procedure Check_At_Most_N_Arguments (N : Nat);
394 -- Check there are no more than N arguments present
396 procedure Check_Component
399 In_Variant_Part : Boolean := False);
400 -- Examine an Unchecked_Union component for correct use of per-object
401 -- constrained subtypes, and for restrictions on finalizable components.
402 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
403 -- should be set when Comp comes from a record variant.
405 procedure Check_Duplicate_Pragma (E : Entity_Id);
406 -- Check if a pragma of the same name as the current pragma is already
407 -- chained as a rep pragma to the given entity. If so give a message
408 -- about the duplicate, and then raise Pragma_Exit so does not return.
409 -- Also checks for delayed aspect specification node in the chain.
411 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
412 -- Nam is an N_String_Literal node containing the external name set by
413 -- an Import or Export pragma (or extended Import or Export pragma).
414 -- This procedure checks for possible duplications if this is the export
415 -- case, and if found, issues an appropriate error message.
417 procedure Check_First_Subtype (Arg : Node_Id);
418 -- Checks that Arg, whose expression is an entity name, references a
421 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
422 -- Checks that the given argument has an identifier, and if so, requires
423 -- it to match the given identifier name. If there is no identifier, or
424 -- a non-matching identifier, then an error message is given and
425 -- Pragma_Exit is raised.
427 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
428 -- Checks that the given argument has an identifier, and if so, requires
429 -- it to match one of the given identifier names. If there is no
430 -- identifier, or a non-matching identifier, then an error message is
431 -- given and Pragma_Exit is raised.
433 procedure Check_In_Main_Program;
434 -- Common checks for pragmas that appear within a main program
435 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
437 procedure Check_Interrupt_Or_Attach_Handler;
438 -- Common processing for first argument of pragma Interrupt_Handler or
439 -- pragma Attach_Handler.
441 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
442 -- Check that pragma appears in a declarative part, or in a package
443 -- specification, i.e. that it does not occur in a statement sequence
446 procedure Check_No_Identifier (Arg : Node_Id);
447 -- Checks that the given argument does not have an identifier. If
448 -- an identifier is present, then an error message is issued, and
449 -- Pragma_Exit is raised.
451 procedure Check_No_Identifiers;
452 -- Checks that none of the arguments to the pragma has an identifier.
453 -- If any argument has an identifier, then an error message is issued,
454 -- and Pragma_Exit is raised.
456 procedure Check_No_Link_Name;
457 -- Checks that no link name is specified
459 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
460 -- Checks if the given argument has an identifier, and if so, requires
461 -- it to match the given identifier name. If there is a non-matching
462 -- identifier, then an error message is given and Pragma_Exit is raised.
464 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
465 -- Checks if the given argument has an identifier, and if so, requires
466 -- it to match the given identifier name. If there is a non-matching
467 -- identifier, then an error message is given and Pragma_Exit is raised.
468 -- In this version of the procedure, the identifier name is given as
469 -- a string with lower case letters.
471 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
472 -- Called to process a precondition or postcondition pragma. There are
475 -- The pragma appears after a subprogram spec
477 -- If the corresponding check is not enabled, the pragma is analyzed
478 -- but otherwise ignored and control returns with In_Body set False.
480 -- If the check is enabled, then the first step is to analyze the
481 -- pragma, but this is skipped if the subprogram spec appears within
482 -- a package specification (because this is the case where we delay
483 -- analysis till the end of the spec). Then (whether or not it was
484 -- analyzed), the pragma is chained to the subprogram in question
485 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
486 -- caller with In_Body set False.
488 -- The pragma appears at the start of subprogram body declarations
490 -- In this case an immediate return to the caller is made with
491 -- In_Body set True, and the pragma is NOT analyzed.
493 -- In all other cases, an error message for bad placement is given
495 procedure Check_Static_Constraint (Constr : Node_Id);
496 -- Constr is a constraint from an N_Subtype_Indication node from a
497 -- component constraint in an Unchecked_Union type. This routine checks
498 -- that the constraint is static as required by the restrictions for
501 procedure Check_Test_Case;
502 -- Called to process a test-case pragma. The treatment is similar to the
503 -- one for pre- and postcondition in Check_Precondition_Postcondition,
504 -- except the placement rules for the test-case pragma are stricter.
505 -- This pragma may only occur after a subprogram spec declared directly
506 -- in a package spec unit. In this case, the pragma is chained to the
507 -- subprogram in question (using Spec_TC_List and Next_Pragma) and
508 -- analysis of the pragma is delayed till the end of the spec. In
509 -- all other cases, an error message for bad placement is given.
511 procedure Check_Valid_Configuration_Pragma;
512 -- Legality checks for placement of a configuration pragma
514 procedure Check_Valid_Library_Unit_Pragma;
515 -- Legality checks for library unit pragmas. A special case arises for
516 -- pragmas in generic instances that come from copies of the original
517 -- library unit pragmas in the generic templates. In the case of other
518 -- than library level instantiations these can appear in contexts which
519 -- would normally be invalid (they only apply to the original template
520 -- and to library level instantiations), and they are simply ignored,
521 -- which is implemented by rewriting them as null statements.
523 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
524 -- Check an Unchecked_Union variant for lack of nested variants and
525 -- presence of at least one component. UU_Typ is the related Unchecked_
528 procedure Error_Pragma (Msg : String);
529 pragma No_Return (Error_Pragma);
530 -- Outputs error message for current pragma. The message contains a %
531 -- that will be replaced with the pragma name, and the flag is placed
532 -- on the pragma itself. Pragma_Exit is then raised.
534 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
535 pragma No_Return (Error_Pragma_Arg);
536 -- Outputs error message for current pragma. The message may contain
537 -- a % that will be replaced with the pragma name. The parameter Arg
538 -- may either be a pragma argument association, in which case the flag
539 -- is placed on the expression of this association, or an expression,
540 -- in which case the flag is placed directly on the expression. The
541 -- message is placed using Error_Msg_N, so the message may also contain
542 -- an & insertion character which will reference the given Arg value.
543 -- After placing the message, Pragma_Exit is raised.
545 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
546 pragma No_Return (Error_Pragma_Arg);
547 -- Similar to above form of Error_Pragma_Arg except that two messages
548 -- are provided, the second is a continuation comment starting with \.
550 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
551 pragma No_Return (Error_Pragma_Arg_Ident);
552 -- Outputs error message for current pragma. The message may contain
553 -- a % that will be replaced with the pragma name. The parameter Arg
554 -- must be a pragma argument association with a non-empty identifier
555 -- (i.e. its Chars field must be set), and the error message is placed
556 -- on the identifier. The message is placed using Error_Msg_N so
557 -- the message may also contain an & insertion character which will
558 -- reference the identifier. After placing the message, Pragma_Exit
561 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
562 pragma No_Return (Error_Pragma_Ref);
563 -- Outputs error message for current pragma. The message may contain
564 -- a % that will be replaced with the pragma name. The parameter Ref
565 -- must be an entity whose name can be referenced by & and sloc by #.
566 -- After placing the message, Pragma_Exit is raised.
568 function Find_Lib_Unit_Name return Entity_Id;
569 -- Used for a library unit pragma to find the entity to which the
570 -- library unit pragma applies, returns the entity found.
572 procedure Find_Program_Unit_Name (Id : Node_Id);
573 -- If the pragma is a compilation unit pragma, the id must denote the
574 -- compilation unit in the same compilation, and the pragma must appear
575 -- in the list of preceding or trailing pragmas. If it is a program
576 -- unit pragma that is not a compilation unit pragma, then the
577 -- identifier must be visible.
579 function Find_Unique_Parameterless_Procedure
581 Arg : Node_Id) return Entity_Id;
582 -- Used for a procedure pragma to find the unique parameterless
583 -- procedure identified by Name, returns it if it exists, otherwise
584 -- errors out and uses Arg as the pragma argument for the message.
586 procedure Fix_Error (Msg : in out String);
587 -- This is called prior to issuing an error message. Msg is a string
588 -- which typically contains the substring pragma. If the current pragma
589 -- comes from an aspect, each such "pragma" substring is replaced with
590 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
591 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
593 procedure Gather_Associations
595 Args : out Args_List);
596 -- This procedure is used to gather the arguments for a pragma that
597 -- permits arbitrary ordering of parameters using the normal rules
598 -- for named and positional parameters. The Names argument is a list
599 -- of Name_Id values that corresponds to the allowed pragma argument
600 -- association identifiers in order. The result returned in Args is
601 -- a list of corresponding expressions that are the pragma arguments.
602 -- Note that this is a list of expressions, not of pragma argument
603 -- associations (Gather_Associations has completely checked all the
604 -- optional identifiers when it returns). An entry in Args is Empty
605 -- on return if the corresponding argument is not present.
607 procedure GNAT_Pragma;
608 -- Called for all GNAT defined pragmas to check the relevant restriction
609 -- (No_Implementation_Pragmas).
611 function Is_Before_First_Decl
612 (Pragma_Node : Node_Id;
613 Decls : List_Id) return Boolean;
614 -- Return True if Pragma_Node is before the first declarative item in
615 -- Decls where Decls is the list of declarative items.
617 function Is_Configuration_Pragma return Boolean;
618 -- Determines if the placement of the current pragma is appropriate
619 -- for a configuration pragma.
621 function Is_In_Context_Clause return Boolean;
622 -- Returns True if pragma appears within the context clause of a unit,
623 -- and False for any other placement (does not generate any messages).
625 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
626 -- Analyzes the argument, and determines if it is a static string
627 -- expression, returns True if so, False if non-static or not String.
629 procedure Pragma_Misplaced;
630 pragma No_Return (Pragma_Misplaced);
631 -- Issue fatal error message for misplaced pragma
633 procedure Process_Atomic_Shared_Volatile;
634 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
635 -- Shared is an obsolete Ada 83 pragma, treated as being identical
636 -- in effect to pragma Atomic.
638 procedure Process_Compile_Time_Warning_Or_Error;
639 -- Common processing for Compile_Time_Error and Compile_Time_Warning
641 procedure Process_Convention
642 (C : out Convention_Id;
643 Ent : out Entity_Id);
644 -- Common processing for Convention, Interface, Import and Export.
645 -- Checks first two arguments of pragma, and sets the appropriate
646 -- convention value in the specified entity or entities. On return
647 -- C is the convention, Ent is the referenced entity.
649 procedure Process_Extended_Import_Export_Exception_Pragma
650 (Arg_Internal : Node_Id;
651 Arg_External : Node_Id;
654 -- Common processing for the pragmas Import/Export_Exception. The three
655 -- arguments correspond to the three named parameters of the pragma. An
656 -- argument is empty if the corresponding parameter is not present in
659 procedure Process_Extended_Import_Export_Object_Pragma
660 (Arg_Internal : Node_Id;
661 Arg_External : Node_Id;
663 -- Common processing for the pragmas Import/Export_Object. The three
664 -- arguments correspond to the three named parameters of the pragmas. An
665 -- argument is empty if the corresponding parameter is not present in
668 procedure Process_Extended_Import_Export_Internal_Arg
669 (Arg_Internal : Node_Id := Empty);
670 -- Common processing for all extended Import and Export pragmas. The
671 -- argument is the pragma parameter for the Internal argument. If
672 -- Arg_Internal is empty or inappropriate, an error message is posted.
673 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
674 -- set to identify the referenced entity.
676 procedure Process_Extended_Import_Export_Subprogram_Pragma
677 (Arg_Internal : Node_Id;
678 Arg_External : Node_Id;
679 Arg_Parameter_Types : Node_Id;
680 Arg_Result_Type : Node_Id := Empty;
681 Arg_Mechanism : Node_Id;
682 Arg_Result_Mechanism : Node_Id := Empty;
683 Arg_First_Optional_Parameter : Node_Id := Empty);
684 -- Common processing for all extended Import and Export pragmas applying
685 -- to subprograms. The caller omits any arguments that do not apply to
686 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
687 -- only in the Import_Function and Export_Function cases). The argument
688 -- names correspond to the allowed pragma association identifiers.
690 procedure Process_Generic_List;
691 -- Common processing for Share_Generic and Inline_Generic
693 procedure Process_Import_Or_Interface;
694 -- Common processing for Import of Interface
696 procedure Process_Import_Predefined_Type;
697 -- Processing for completing a type with pragma Import. This is used
698 -- to declare types that match predefined C types, especially for cases
699 -- without corresponding Ada predefined type.
701 procedure Process_Inline (Active : Boolean);
702 -- Common processing for Inline and Inline_Always. The parameter
703 -- indicates if the inline pragma is active, i.e. if it should actually
704 -- cause inlining to occur.
706 procedure Process_Interface_Name
707 (Subprogram_Def : Entity_Id;
710 -- Given the last two arguments of pragma Import, pragma Export, or
711 -- pragma Interface_Name, performs validity checks and sets the
712 -- Interface_Name field of the given subprogram entity to the
713 -- appropriate external or link name, depending on the arguments given.
714 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
715 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
716 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
717 -- nor Link_Arg is present, the interface name is set to the default
718 -- from the subprogram name.
720 procedure Process_Interrupt_Or_Attach_Handler;
721 -- Common processing for Interrupt and Attach_Handler pragmas
723 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
724 -- Common processing for Restrictions and Restriction_Warnings pragmas.
725 -- Warn is True for Restriction_Warnings, or for Restrictions if the
726 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
727 -- is not set in the Restrictions case.
729 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
730 -- Common processing for Suppress and Unsuppress. The boolean parameter
731 -- Suppress_Case is True for the Suppress case, and False for the
734 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
735 -- This procedure sets the Is_Exported flag for the given entity,
736 -- checking that the entity was not previously imported. Arg is
737 -- the argument that specified the entity. A check is also made
738 -- for exporting inappropriate entities.
740 procedure Set_Extended_Import_Export_External_Name
741 (Internal_Ent : Entity_Id;
742 Arg_External : Node_Id);
743 -- Common processing for all extended import export pragmas. The first
744 -- argument, Internal_Ent, is the internal entity, which has already
745 -- been checked for validity by the caller. Arg_External is from the
746 -- Import or Export pragma, and may be null if no External parameter
747 -- was present. If Arg_External is present and is a non-null string
748 -- (a null string is treated as the default), then the Interface_Name
749 -- field of Internal_Ent is set appropriately.
751 procedure Set_Imported (E : Entity_Id);
752 -- This procedure sets the Is_Imported flag for the given entity,
753 -- checking that it is not previously exported or imported.
755 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
756 -- Mech is a parameter passing mechanism (see Import_Function syntax
757 -- for MECHANISM_NAME). This routine checks that the mechanism argument
758 -- has the right form, and if not issues an error message. If the
759 -- argument has the right form then the Mechanism field of Ent is
760 -- set appropriately.
762 procedure Set_Ravenscar_Profile (N : Node_Id);
763 -- Activate the set of configuration pragmas and restrictions that make
764 -- up the Ravenscar Profile. N is the corresponding pragma node, which
765 -- is used for error messages on any constructs that violate the
768 ---------------------
769 -- Ada_2005_Pragma --
770 ---------------------
772 procedure Ada_2005_Pragma is
774 if Ada_Version <= Ada_95 then
775 Check_Restriction (No_Implementation_Pragmas, N);
779 ---------------------
780 -- Ada_2012_Pragma --
781 ---------------------
783 procedure Ada_2012_Pragma is
785 if Ada_Version <= Ada_2005 then
786 Check_Restriction (No_Implementation_Pragmas, N);
790 --------------------------
791 -- Check_Ada_83_Warning --
792 --------------------------
794 procedure Check_Ada_83_Warning is
796 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
797 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
799 end Check_Ada_83_Warning;
801 ---------------------
802 -- Check_Arg_Count --
803 ---------------------
805 procedure Check_Arg_Count (Required : Nat) is
807 if Arg_Count /= Required then
808 Error_Pragma ("wrong number of arguments for pragma%");
812 --------------------------------
813 -- Check_Arg_Is_External_Name --
814 --------------------------------
816 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
817 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
820 if Nkind (Argx) = N_Identifier then
824 Analyze_And_Resolve (Argx, Standard_String);
826 if Is_OK_Static_Expression (Argx) then
829 elsif Etype (Argx) = Any_Type then
832 -- An interesting special case, if we have a string literal and
833 -- we are in Ada 83 mode, then we allow it even though it will
834 -- not be flagged as static. This allows expected Ada 83 mode
835 -- use of external names which are string literals, even though
836 -- technically these are not static in Ada 83.
838 elsif Ada_Version = Ada_83
839 and then Nkind (Argx) = N_String_Literal
843 -- Static expression that raises Constraint_Error. This has
844 -- already been flagged, so just exit from pragma processing.
846 elsif Is_Static_Expression (Argx) then
849 -- Here we have a real error (non-static expression)
852 Error_Msg_Name_1 := Pname;
856 "argument for pragma% must be a identifier or "
857 & "static string expression!";
860 Flag_Non_Static_Expr (Msg, Argx);
865 end Check_Arg_Is_External_Name;
867 -----------------------------
868 -- Check_Arg_Is_Identifier --
869 -----------------------------
871 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
872 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
874 if Nkind (Argx) /= N_Identifier then
876 ("argument for pragma% must be identifier", Argx);
878 end Check_Arg_Is_Identifier;
880 ----------------------------------
881 -- Check_Arg_Is_Integer_Literal --
882 ----------------------------------
884 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
885 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
887 if Nkind (Argx) /= N_Integer_Literal then
889 ("argument for pragma% must be integer literal", Argx);
891 end Check_Arg_Is_Integer_Literal;
893 -------------------------------------------
894 -- Check_Arg_Is_Library_Level_Local_Name --
895 -------------------------------------------
899 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
900 -- | library_unit_NAME
902 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
904 Check_Arg_Is_Local_Name (Arg);
906 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
907 and then Comes_From_Source (N)
910 ("argument for pragma% must be library level entity", Arg);
912 end Check_Arg_Is_Library_Level_Local_Name;
914 -----------------------------
915 -- Check_Arg_Is_Local_Name --
916 -----------------------------
920 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
921 -- | library_unit_NAME
923 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
924 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
929 if Nkind (Argx) not in N_Direct_Name
930 and then (Nkind (Argx) /= N_Attribute_Reference
931 or else Present (Expressions (Argx))
932 or else Nkind (Prefix (Argx)) /= N_Identifier)
933 and then (not Is_Entity_Name (Argx)
934 or else not Is_Compilation_Unit (Entity (Argx)))
936 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
939 -- No further check required if not an entity name
941 if not Is_Entity_Name (Argx) then
947 Ent : constant Entity_Id := Entity (Argx);
948 Scop : constant Entity_Id := Scope (Ent);
950 -- Case of a pragma applied to a compilation unit: pragma must
951 -- occur immediately after the program unit in the compilation.
953 if Is_Compilation_Unit (Ent) then
955 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
957 -- Case of pragma placed immediately after spec
959 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
962 -- Case of pragma placed immediately after body
964 elsif Nkind (Decl) = N_Subprogram_Declaration
965 and then Present (Corresponding_Body (Decl))
969 (Parent (Unit_Declaration_Node
970 (Corresponding_Body (Decl))));
972 -- All other cases are illegal
979 -- Special restricted placement rule from 10.2.1(11.8/2)
981 elsif Is_Generic_Formal (Ent)
982 and then Prag_Id = Pragma_Preelaborable_Initialization
984 OK := List_Containing (N) =
985 Generic_Formal_Declarations
986 (Unit_Declaration_Node (Scop));
988 -- Default case, just check that the pragma occurs in the scope
989 -- of the entity denoted by the name.
992 OK := Current_Scope = Scop;
997 ("pragma% argument must be in same declarative part", Arg);
1001 end Check_Arg_Is_Local_Name;
1003 ---------------------------------
1004 -- Check_Arg_Is_Locking_Policy --
1005 ---------------------------------
1007 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1008 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1011 Check_Arg_Is_Identifier (Argx);
1013 if not Is_Locking_Policy_Name (Chars (Argx)) then
1014 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1016 end Check_Arg_Is_Locking_Policy;
1018 -------------------------
1019 -- Check_Arg_Is_One_Of --
1020 -------------------------
1022 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1023 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1026 Check_Arg_Is_Identifier (Argx);
1028 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1029 Error_Msg_Name_2 := N1;
1030 Error_Msg_Name_3 := N2;
1031 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1033 end Check_Arg_Is_One_Of;
1035 procedure Check_Arg_Is_One_Of
1037 N1, N2, N3 : Name_Id)
1039 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1042 Check_Arg_Is_Identifier (Argx);
1044 if Chars (Argx) /= N1
1045 and then Chars (Argx) /= N2
1046 and then Chars (Argx) /= N3
1048 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1050 end Check_Arg_Is_One_Of;
1052 procedure Check_Arg_Is_One_Of
1054 N1, N2, N3, N4, N5 : Name_Id)
1056 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1059 Check_Arg_Is_Identifier (Argx);
1061 if Chars (Argx) /= N1
1062 and then Chars (Argx) /= N2
1063 and then Chars (Argx) /= N3
1064 and then Chars (Argx) /= N4
1065 and then Chars (Argx) /= N5
1067 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1069 end Check_Arg_Is_One_Of;
1070 ---------------------------------
1071 -- Check_Arg_Is_Queuing_Policy --
1072 ---------------------------------
1074 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1075 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1078 Check_Arg_Is_Identifier (Argx);
1080 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1081 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1083 end Check_Arg_Is_Queuing_Policy;
1085 ------------------------------------
1086 -- Check_Arg_Is_Static_Expression --
1087 ------------------------------------
1089 procedure Check_Arg_Is_Static_Expression
1091 Typ : Entity_Id := Empty)
1093 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1096 if Present (Typ) then
1097 Analyze_And_Resolve (Argx, Typ);
1099 Analyze_And_Resolve (Argx);
1102 if Is_OK_Static_Expression (Argx) then
1105 elsif Etype (Argx) = Any_Type then
1108 -- An interesting special case, if we have a string literal and we
1109 -- are in Ada 83 mode, then we allow it even though it will not be
1110 -- flagged as static. This allows the use of Ada 95 pragmas like
1111 -- Import in Ada 83 mode. They will of course be flagged with
1112 -- warnings as usual, but will not cause errors.
1114 elsif Ada_Version = Ada_83
1115 and then Nkind (Argx) = N_String_Literal
1119 -- Static expression that raises Constraint_Error. This has already
1120 -- been flagged, so just exit from pragma processing.
1122 elsif Is_Static_Expression (Argx) then
1125 -- Finally, we have a real error
1128 Error_Msg_Name_1 := Pname;
1132 "argument for pragma% must be a static expression!";
1135 Flag_Non_Static_Expr (Msg, Argx);
1140 end Check_Arg_Is_Static_Expression;
1142 ------------------------------------------
1143 -- Check_Arg_Is_Task_Dispatching_Policy --
1144 ------------------------------------------
1146 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1147 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1150 Check_Arg_Is_Identifier (Argx);
1152 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1154 ("& is not a valid task dispatching policy name", Argx);
1156 end Check_Arg_Is_Task_Dispatching_Policy;
1158 ---------------------
1159 -- Check_Arg_Order --
1160 ---------------------
1162 procedure Check_Arg_Order (Names : Name_List) is
1165 Highest_So_Far : Natural := 0;
1166 -- Highest index in Names seen do far
1170 for J in 1 .. Arg_Count loop
1171 if Chars (Arg) /= No_Name then
1172 for K in Names'Range loop
1173 if Chars (Arg) = Names (K) then
1174 if K < Highest_So_Far then
1175 Error_Msg_Name_1 := Pname;
1177 ("parameters out of order for pragma%", Arg);
1178 Error_Msg_Name_1 := Names (K);
1179 Error_Msg_Name_2 := Names (Highest_So_Far);
1180 Error_Msg_N ("\% must appear before %", Arg);
1184 Highest_So_Far := K;
1192 end Check_Arg_Order;
1194 --------------------------------
1195 -- Check_At_Least_N_Arguments --
1196 --------------------------------
1198 procedure Check_At_Least_N_Arguments (N : Nat) is
1200 if Arg_Count < N then
1201 Error_Pragma ("too few arguments for pragma%");
1203 end Check_At_Least_N_Arguments;
1205 -------------------------------
1206 -- Check_At_Most_N_Arguments --
1207 -------------------------------
1209 procedure Check_At_Most_N_Arguments (N : Nat) is
1212 if Arg_Count > N then
1214 for J in 1 .. N loop
1216 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1219 end Check_At_Most_N_Arguments;
1221 ---------------------
1222 -- Check_Component --
1223 ---------------------
1225 procedure Check_Component
1228 In_Variant_Part : Boolean := False)
1230 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1231 Sindic : constant Node_Id :=
1232 Subtype_Indication (Component_Definition (Comp));
1233 Typ : constant Entity_Id := Etype (Comp_Id);
1235 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1236 -- Determine whether entity Id appears inside a generic body.
1237 -- Shouldn't this be in a more general place ???
1239 -------------------------
1240 -- Inside_Generic_Body --
1241 -------------------------
1243 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1248 while Present (S) and then S /= Standard_Standard loop
1249 if Ekind (S) = E_Generic_Package
1250 and then In_Package_Body (S)
1259 end Inside_Generic_Body;
1261 -- Start of processing for Check_Component
1264 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1265 -- object constraint, then the component type shall be an Unchecked_
1268 if Nkind (Sindic) = N_Subtype_Indication
1269 and then Has_Per_Object_Constraint (Comp_Id)
1270 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1273 ("component subtype subject to per-object constraint " &
1274 "must be an Unchecked_Union", Comp);
1276 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1277 -- the body of a generic unit, or within the body of any of its
1278 -- descendant library units, no part of the type of a component
1279 -- declared in a variant_part of the unchecked union type shall be of
1280 -- a formal private type or formal private extension declared within
1281 -- the formal part of the generic unit.
1283 elsif Ada_Version >= Ada_2012
1284 and then Inside_Generic_Body (UU_Typ)
1285 and then In_Variant_Part
1286 and then Is_Private_Type (Typ)
1287 and then Is_Generic_Type (Typ)
1290 ("component of Unchecked_Union cannot be of generic type", Comp);
1292 elsif Needs_Finalization (Typ) then
1294 ("component of Unchecked_Union cannot be controlled", Comp);
1296 elsif Has_Task (Typ) then
1298 ("component of Unchecked_Union cannot have tasks", Comp);
1300 end Check_Component;
1302 ----------------------------
1303 -- Check_Duplicate_Pragma --
1304 ----------------------------
1306 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1310 -- Nothing to do if this pragma comes from an aspect specification,
1311 -- since we could not be duplicating a pragma, and we dealt with the
1312 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1314 if From_Aspect_Specification (N) then
1318 -- Otherwise current pragma may duplicate previous pragma or a
1319 -- previously given aspect specification for the same pragma.
1321 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1324 Error_Msg_Name_1 := Pragma_Name (N);
1325 Error_Msg_Sloc := Sloc (P);
1327 if Nkind (P) = N_Aspect_Specification
1328 or else From_Aspect_Specification (P)
1330 Error_Msg_NE ("aspect% for & previously given#", N, E);
1332 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1337 end Check_Duplicate_Pragma;
1339 ----------------------------------
1340 -- Check_Duplicated_Export_Name --
1341 ----------------------------------
1343 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1344 String_Val : constant String_Id := Strval (Nam);
1347 -- We are only interested in the export case, and in the case of
1348 -- generics, it is the instance, not the template, that is the
1349 -- problem (the template will generate a warning in any case).
1351 if not Inside_A_Generic
1352 and then (Prag_Id = Pragma_Export
1354 Prag_Id = Pragma_Export_Procedure
1356 Prag_Id = Pragma_Export_Valued_Procedure
1358 Prag_Id = Pragma_Export_Function)
1360 for J in Externals.First .. Externals.Last loop
1361 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1362 Error_Msg_Sloc := Sloc (Externals.Table (J));
1363 Error_Msg_N ("external name duplicates name given#", Nam);
1368 Externals.Append (Nam);
1370 end Check_Duplicated_Export_Name;
1372 -------------------------
1373 -- Check_First_Subtype --
1374 -------------------------
1376 procedure Check_First_Subtype (Arg : Node_Id) is
1377 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1378 Ent : constant Entity_Id := Entity (Argx);
1381 if Is_First_Subtype (Ent) then
1384 elsif Is_Type (Ent) then
1386 ("pragma% cannot apply to subtype", Argx);
1388 elsif Is_Object (Ent) then
1390 ("pragma% cannot apply to object, requires a type", Argx);
1394 ("pragma% cannot apply to&, requires a type", Argx);
1396 end Check_First_Subtype;
1398 ----------------------
1399 -- Check_Identifier --
1400 ----------------------
1402 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1405 and then Nkind (Arg) = N_Pragma_Argument_Association
1407 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1408 Error_Msg_Name_1 := Pname;
1409 Error_Msg_Name_2 := Id;
1410 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1414 end Check_Identifier;
1416 --------------------------------
1417 -- Check_Identifier_Is_One_Of --
1418 --------------------------------
1420 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1423 and then Nkind (Arg) = N_Pragma_Argument_Association
1425 if Chars (Arg) = No_Name then
1426 Error_Msg_Name_1 := Pname;
1427 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1430 elsif Chars (Arg) /= N1
1431 and then Chars (Arg) /= N2
1433 Error_Msg_Name_1 := Pname;
1434 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1438 end Check_Identifier_Is_One_Of;
1440 ---------------------------
1441 -- Check_In_Main_Program --
1442 ---------------------------
1444 procedure Check_In_Main_Program is
1445 P : constant Node_Id := Parent (N);
1448 -- Must be at in subprogram body
1450 if Nkind (P) /= N_Subprogram_Body then
1451 Error_Pragma ("% pragma allowed only in subprogram");
1453 -- Otherwise warn if obviously not main program
1455 elsif Present (Parameter_Specifications (Specification (P)))
1456 or else not Is_Compilation_Unit (Defining_Entity (P))
1458 Error_Msg_Name_1 := Pname;
1460 ("?pragma% is only effective in main program", N);
1462 end Check_In_Main_Program;
1464 ---------------------------------------
1465 -- Check_Interrupt_Or_Attach_Handler --
1466 ---------------------------------------
1468 procedure Check_Interrupt_Or_Attach_Handler is
1469 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1470 Handler_Proc, Proc_Scope : Entity_Id;
1475 if Prag_Id = Pragma_Interrupt_Handler then
1476 Check_Restriction (No_Dynamic_Attachment, N);
1479 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1480 Proc_Scope := Scope (Handler_Proc);
1482 -- On AAMP only, a pragma Interrupt_Handler is supported for
1483 -- nonprotected parameterless procedures.
1485 if not AAMP_On_Target
1486 or else Prag_Id = Pragma_Attach_Handler
1488 if Ekind (Proc_Scope) /= E_Protected_Type then
1490 ("argument of pragma% must be protected procedure", Arg1);
1493 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1494 Error_Pragma ("pragma% must be in protected definition");
1498 if not Is_Library_Level_Entity (Proc_Scope)
1499 or else (AAMP_On_Target
1500 and then not Is_Library_Level_Entity (Handler_Proc))
1503 ("argument for pragma% must be library level entity", Arg1);
1506 -- AI05-0033: A pragma cannot appear within a generic body, because
1507 -- instance can be in a nested scope. The check that protected type
1508 -- is itself a library-level declaration is done elsewhere.
1510 -- Note: we omit this check in Codepeer mode to properly handle code
1511 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1513 if Inside_A_Generic then
1514 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1515 and then In_Package_Body (Scope (Current_Scope))
1516 and then not CodePeer_Mode
1518 Error_Pragma ("pragma% cannot be used inside a generic");
1521 end Check_Interrupt_Or_Attach_Handler;
1523 -------------------------------------------
1524 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1525 -------------------------------------------
1527 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1536 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1539 elsif Nkind_In (P, N_Package_Specification,
1544 -- Note: the following tests seem a little peculiar, because
1545 -- they test for bodies, but if we were in the statement part
1546 -- of the body, we would already have hit the handled statement
1547 -- sequence, so the only way we get here is by being in the
1548 -- declarative part of the body.
1550 elsif Nkind_In (P, N_Subprogram_Body,
1561 Error_Pragma ("pragma% is not in declarative part or package spec");
1562 end Check_Is_In_Decl_Part_Or_Package_Spec;
1564 -------------------------
1565 -- Check_No_Identifier --
1566 -------------------------
1568 procedure Check_No_Identifier (Arg : Node_Id) is
1570 if Nkind (Arg) = N_Pragma_Argument_Association
1571 and then Chars (Arg) /= No_Name
1573 Error_Pragma_Arg_Ident
1574 ("pragma% does not permit identifier& here", Arg);
1576 end Check_No_Identifier;
1578 --------------------------
1579 -- Check_No_Identifiers --
1580 --------------------------
1582 procedure Check_No_Identifiers is
1585 if Arg_Count > 0 then
1587 while Present (Arg_Node) loop
1588 Check_No_Identifier (Arg_Node);
1592 end Check_No_Identifiers;
1594 ------------------------
1595 -- Check_No_Link_Name --
1596 ------------------------
1598 procedure Check_No_Link_Name is
1601 and then Chars (Arg3) = Name_Link_Name
1606 if Present (Arg4) then
1608 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1610 end Check_No_Link_Name;
1612 -------------------------------
1613 -- Check_Optional_Identifier --
1614 -------------------------------
1616 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1619 and then Nkind (Arg) = N_Pragma_Argument_Association
1620 and then Chars (Arg) /= No_Name
1622 if Chars (Arg) /= Id then
1623 Error_Msg_Name_1 := Pname;
1624 Error_Msg_Name_2 := Id;
1625 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1629 end Check_Optional_Identifier;
1631 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1633 Name_Buffer (1 .. Id'Length) := Id;
1634 Name_Len := Id'Length;
1635 Check_Optional_Identifier (Arg, Name_Find);
1636 end Check_Optional_Identifier;
1638 --------------------------------------
1639 -- Check_Precondition_Postcondition --
1640 --------------------------------------
1642 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1646 procedure Chain_PPC (PO : Node_Id);
1647 -- If PO is an entry or a [generic] subprogram declaration node, then
1648 -- the precondition/postcondition applies to this subprogram and the
1649 -- processing for the pragma is completed. Otherwise the pragma is
1656 procedure Chain_PPC (PO : Node_Id) is
1661 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1662 if not From_Aspect_Specification (N) then
1664 ("pragma% cannot be applied to abstract subprogram");
1666 elsif Class_Present (N) then
1671 ("aspect % requires ''Class for abstract subprogram");
1674 -- AI05-0230: The same restriction applies to null procedures. For
1675 -- compatibility with earlier uses of the Ada pragma, apply this
1676 -- rule only to aspect specifications.
1678 -- The above discrpency needs documentation. Robert is dubious
1679 -- about whether it is a good idea ???
1681 elsif Nkind (PO) = N_Subprogram_Declaration
1682 and then Nkind (Specification (PO)) = N_Procedure_Specification
1683 and then Null_Present (Specification (PO))
1684 and then From_Aspect_Specification (N)
1685 and then not Class_Present (N)
1688 ("aspect % requires ''Class for null procedure");
1690 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1691 N_Generic_Subprogram_Declaration,
1692 N_Entry_Declaration)
1697 -- Here if we have [generic] subprogram or entry declaration
1699 if Nkind (PO) = N_Entry_Declaration then
1700 S := Defining_Entity (PO);
1702 S := Defining_Unit_Name (Specification (PO));
1705 -- Make sure we do not have the case of a precondition pragma when
1706 -- the Pre'Class aspect is present.
1708 -- We do this by looking at pragmas already chained to the entity
1709 -- since the aspect derived pragma will be put on this list first.
1711 if Pragma_Name (N) = Name_Precondition then
1712 if not From_Aspect_Specification (N) then
1713 P := Spec_PPC_List (Contract (S));
1714 while Present (P) loop
1715 if Pragma_Name (P) = Name_Precondition
1716 and then From_Aspect_Specification (P)
1717 and then Class_Present (P)
1719 Error_Msg_Sloc := Sloc (P);
1721 ("pragma% not allowed, `Pre''Class` aspect given#");
1724 P := Next_Pragma (P);
1729 -- Similarly check for Pre with inherited Pre'Class. Note that
1730 -- we cover the aspect case as well here.
1732 if Pragma_Name (N) = Name_Precondition
1733 and then not Class_Present (N)
1736 Inherited : constant Subprogram_List :=
1737 Inherited_Subprograms (S);
1741 for J in Inherited'Range loop
1742 P := Spec_PPC_List (Contract (Inherited (J)));
1743 while Present (P) loop
1744 if Pragma_Name (P) = Name_Precondition
1745 and then Class_Present (P)
1747 Error_Msg_Sloc := Sloc (P);
1749 ("pragma% not allowed, `Pre''Class` "
1750 & "aspect inherited from#");
1753 P := Next_Pragma (P);
1759 -- Note: we do not analyze the pragma at this point. Instead we
1760 -- delay this analysis until the end of the declarative part in
1761 -- which the pragma appears. This implements the required delay
1762 -- in this analysis, allowing forward references. The analysis
1763 -- happens at the end of Analyze_Declarations.
1765 -- Chain spec PPC pragma to list for subprogram
1767 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1768 Set_Spec_PPC_List (Contract (S), N);
1770 -- Return indicating spec case
1776 -- Start of processing for Check_Precondition_Postcondition
1779 if not Is_List_Member (N) then
1783 -- Preanalyze message argument if present. Visibility in this
1784 -- argument is established at the point of pragma occurrence.
1786 if Arg_Count = 2 then
1787 Check_Optional_Identifier (Arg2, Name_Message);
1788 Preanalyze_Spec_Expression
1789 (Get_Pragma_Arg (Arg2), Standard_String);
1792 -- Record if pragma is disabled
1794 if Check_Enabled (Pname) then
1795 Set_SCO_Pragma_Enabled (Loc);
1798 -- If we are within an inlined body, the legality of the pragma
1799 -- has been checked already.
1801 if In_Inlined_Body then
1806 -- Search prior declarations
1809 while Present (Prev (P)) loop
1812 -- If the previous node is a generic subprogram, do not go to to
1813 -- the original node, which is the unanalyzed tree: we need to
1814 -- attach the pre/postconditions to the analyzed version at this
1815 -- point. They get propagated to the original tree when analyzing
1816 -- the corresponding body.
1818 if Nkind (P) not in N_Generic_Declaration then
1819 PO := Original_Node (P);
1824 -- Skip past prior pragma
1826 if Nkind (PO) = N_Pragma then
1829 -- Skip stuff not coming from source
1831 elsif not Comes_From_Source (PO) then
1833 -- The condition may apply to a subprogram instantiation
1835 if Nkind (PO) = N_Subprogram_Declaration
1836 and then Present (Generic_Parent (Specification (PO)))
1841 -- For all other cases of non source code, do nothing
1847 -- Only remaining possibility is subprogram declaration
1855 -- If we fall through loop, pragma is at start of list, so see if it
1856 -- is at the start of declarations of a subprogram body.
1858 if Nkind (Parent (N)) = N_Subprogram_Body
1859 and then List_Containing (N) = Declarations (Parent (N))
1861 if Operating_Mode /= Generate_Code
1862 or else Inside_A_Generic
1864 -- Analyze pragma expression for correctness and for ASIS use
1866 Preanalyze_Spec_Expression
1867 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1873 -- See if it is in the pragmas after a library level subprogram
1875 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1877 -- In formal verification mode, analyze pragma expression for
1878 -- correctness, as it is not expanded later.
1881 Analyze_PPC_In_Decl_Part
1882 (N, Defining_Entity (Unit (Parent (Parent (N)))));
1885 Chain_PPC (Unit (Parent (Parent (N))));
1889 -- If we fall through, pragma was misplaced
1892 end Check_Precondition_Postcondition;
1894 -----------------------------
1895 -- Check_Static_Constraint --
1896 -----------------------------
1898 -- Note: for convenience in writing this procedure, in addition to
1899 -- the officially (i.e. by spec) allowed argument which is always a
1900 -- constraint, it also allows ranges and discriminant associations.
1901 -- Above is not clear ???
1903 procedure Check_Static_Constraint (Constr : Node_Id) is
1905 procedure Require_Static (E : Node_Id);
1906 -- Require given expression to be static expression
1908 --------------------
1909 -- Require_Static --
1910 --------------------
1912 procedure Require_Static (E : Node_Id) is
1914 if not Is_OK_Static_Expression (E) then
1915 Flag_Non_Static_Expr
1916 ("non-static constraint not allowed in Unchecked_Union!", E);
1921 -- Start of processing for Check_Static_Constraint
1924 case Nkind (Constr) is
1925 when N_Discriminant_Association =>
1926 Require_Static (Expression (Constr));
1929 Require_Static (Low_Bound (Constr));
1930 Require_Static (High_Bound (Constr));
1932 when N_Attribute_Reference =>
1933 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1934 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1936 when N_Range_Constraint =>
1937 Check_Static_Constraint (Range_Expression (Constr));
1939 when N_Index_Or_Discriminant_Constraint =>
1943 IDC := First (Constraints (Constr));
1944 while Present (IDC) loop
1945 Check_Static_Constraint (IDC);
1953 end Check_Static_Constraint;
1955 ---------------------
1956 -- Check_Test_Case --
1957 ---------------------
1959 procedure Check_Test_Case is
1963 procedure Chain_TC (PO : Node_Id);
1964 -- If PO is a [generic] subprogram declaration node, then the
1965 -- test-case applies to this subprogram and the processing for the
1966 -- pragma is completed. Otherwise the pragma is misplaced.
1972 procedure Chain_TC (PO : Node_Id) is
1976 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1977 if From_Aspect_Specification (N) then
1979 ("aspect% cannot be applied to abstract subprogram");
1982 ("pragma% cannot be applied to abstract subprogram");
1985 elsif Nkind (PO) = N_Entry_Declaration then
1986 if From_Aspect_Specification (N) then
1987 Error_Pragma ("aspect% cannot be applied to entry");
1989 Error_Pragma ("pragma% cannot be applied to entry");
1992 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1993 N_Generic_Subprogram_Declaration)
1998 -- Here if we have [generic] subprogram declaration
2000 S := Defining_Unit_Name (Specification (PO));
2002 -- Note: we do not analyze the pragma at this point. Instead we
2003 -- delay this analysis until the end of the declarative part in
2004 -- which the pragma appears. This implements the required delay
2005 -- in this analysis, allowing forward references. The analysis
2006 -- happens at the end of Analyze_Declarations.
2008 -- There should not be another test case with the same name
2009 -- associated to this subprogram.
2012 Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2016 TC := Spec_TC_List (Contract (S));
2017 while Present (TC) loop
2020 (Name, Get_Name_From_Test_Case_Pragma (TC))
2022 Error_Msg_Sloc := Sloc (TC);
2024 if From_Aspect_Specification (N) then
2025 Error_Pragma ("name for aspect% is already used#");
2027 Error_Pragma ("name for pragma% is already used#");
2031 TC := Next_Pragma (TC);
2035 -- Chain spec TC pragma to list for subprogram
2037 Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2038 Set_Spec_TC_List (Contract (S), N);
2041 -- Start of processing for Check_Test_Case
2044 if not Is_List_Member (N) then
2048 -- Test cases should only appear in package spec unit
2050 if Get_Source_Unit (N) = No_Unit
2051 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
2052 N_Package_Declaration,
2053 N_Generic_Package_Declaration)
2058 -- Search prior declarations
2061 while Present (Prev (P)) loop
2064 -- If the previous node is a generic subprogram, do not go to to
2065 -- the original node, which is the unanalyzed tree: we need to
2066 -- attach the test-case to the analyzed version at this point.
2067 -- They get propagated to the original tree when analyzing the
2068 -- corresponding body.
2070 if Nkind (P) not in N_Generic_Declaration then
2071 PO := Original_Node (P);
2076 -- Skip past prior pragma
2078 if Nkind (PO) = N_Pragma then
2081 -- Skip stuff not coming from source
2083 elsif not Comes_From_Source (PO) then
2086 -- Only remaining possibility is subprogram declaration. First
2087 -- check that it is declared directly in a package declaration.
2088 -- This may be either the package declaration for the current unit
2089 -- being defined or a local package declaration.
2091 elsif not Present (Parent (Parent (PO)))
2092 or else not Present (Parent (Parent (Parent (PO))))
2093 or else not Nkind_In (Parent (Parent (PO)),
2094 N_Package_Declaration,
2095 N_Generic_Package_Declaration)
2105 -- If we fall through, pragma was misplaced
2108 end Check_Test_Case;
2110 --------------------------------------
2111 -- Check_Valid_Configuration_Pragma --
2112 --------------------------------------
2114 -- A configuration pragma must appear in the context clause of a
2115 -- compilation unit, and only other pragmas may precede it. Note that
2116 -- the test also allows use in a configuration pragma file.
2118 procedure Check_Valid_Configuration_Pragma is
2120 if not Is_Configuration_Pragma then
2121 Error_Pragma ("incorrect placement for configuration pragma%");
2123 end Check_Valid_Configuration_Pragma;
2125 -------------------------------------
2126 -- Check_Valid_Library_Unit_Pragma --
2127 -------------------------------------
2129 procedure Check_Valid_Library_Unit_Pragma is
2131 Parent_Node : Node_Id;
2132 Unit_Name : Entity_Id;
2133 Unit_Kind : Node_Kind;
2134 Unit_Node : Node_Id;
2135 Sindex : Source_File_Index;
2138 if not Is_List_Member (N) then
2142 Plist := List_Containing (N);
2143 Parent_Node := Parent (Plist);
2145 if Parent_Node = Empty then
2148 -- Case of pragma appearing after a compilation unit. In this case
2149 -- it must have an argument with the corresponding name and must
2150 -- be part of the following pragmas of its parent.
2152 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2153 if Plist /= Pragmas_After (Parent_Node) then
2156 elsif Arg_Count = 0 then
2158 ("argument required if outside compilation unit");
2161 Check_No_Identifiers;
2162 Check_Arg_Count (1);
2163 Unit_Node := Unit (Parent (Parent_Node));
2164 Unit_Kind := Nkind (Unit_Node);
2166 Analyze (Get_Pragma_Arg (Arg1));
2168 if Unit_Kind = N_Generic_Subprogram_Declaration
2169 or else Unit_Kind = N_Subprogram_Declaration
2171 Unit_Name := Defining_Entity (Unit_Node);
2173 elsif Unit_Kind in N_Generic_Instantiation then
2174 Unit_Name := Defining_Entity (Unit_Node);
2177 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2180 if Chars (Unit_Name) /=
2181 Chars (Entity (Get_Pragma_Arg (Arg1)))
2184 ("pragma% argument is not current unit name", Arg1);
2187 if Ekind (Unit_Name) = E_Package
2188 and then Present (Renamed_Entity (Unit_Name))
2190 Error_Pragma ("pragma% not allowed for renamed package");
2194 -- Pragma appears other than after a compilation unit
2197 -- Here we check for the generic instantiation case and also
2198 -- for the case of processing a generic formal package. We
2199 -- detect these cases by noting that the Sloc on the node
2200 -- does not belong to the current compilation unit.
2202 Sindex := Source_Index (Current_Sem_Unit);
2204 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2205 Rewrite (N, Make_Null_Statement (Loc));
2208 -- If before first declaration, the pragma applies to the
2209 -- enclosing unit, and the name if present must be this name.
2211 elsif Is_Before_First_Decl (N, Plist) then
2212 Unit_Node := Unit_Declaration_Node (Current_Scope);
2213 Unit_Kind := Nkind (Unit_Node);
2215 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2218 elsif Unit_Kind = N_Subprogram_Body
2219 and then not Acts_As_Spec (Unit_Node)
2223 elsif Nkind (Parent_Node) = N_Package_Body then
2226 elsif Nkind (Parent_Node) = N_Package_Specification
2227 and then Plist = Private_Declarations (Parent_Node)
2231 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2232 or else Nkind (Parent_Node) =
2233 N_Generic_Subprogram_Declaration)
2234 and then Plist = Generic_Formal_Declarations (Parent_Node)
2238 elsif Arg_Count > 0 then
2239 Analyze (Get_Pragma_Arg (Arg1));
2241 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2243 ("name in pragma% must be enclosing unit", Arg1);
2246 -- It is legal to have no argument in this context
2252 -- Error if not before first declaration. This is because a
2253 -- library unit pragma argument must be the name of a library
2254 -- unit (RM 10.1.5(7)), but the only names permitted in this
2255 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2256 -- generic subprogram declarations or generic instantiations.
2260 ("pragma% misplaced, must be before first declaration");
2264 end Check_Valid_Library_Unit_Pragma;
2270 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2271 Clist : constant Node_Id := Component_List (Variant);
2275 if not Is_Non_Empty_List (Component_Items (Clist)) then
2277 ("Unchecked_Union may not have empty component list",
2282 Comp := First (Component_Items (Clist));
2283 while Present (Comp) loop
2284 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2293 procedure Error_Pragma (Msg : String) is
2294 MsgF : String := Msg;
2296 Error_Msg_Name_1 := Pname;
2298 Error_Msg_N (MsgF, N);
2302 ----------------------
2303 -- Error_Pragma_Arg --
2304 ----------------------
2306 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2307 MsgF : String := Msg;
2309 Error_Msg_Name_1 := Pname;
2311 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2313 end Error_Pragma_Arg;
2315 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2316 MsgF : String := Msg1;
2318 Error_Msg_Name_1 := Pname;
2320 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2321 Error_Pragma_Arg (Msg2, Arg);
2322 end Error_Pragma_Arg;
2324 ----------------------------
2325 -- Error_Pragma_Arg_Ident --
2326 ----------------------------
2328 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2329 MsgF : String := Msg;
2331 Error_Msg_Name_1 := Pname;
2333 Error_Msg_N (MsgF, Arg);
2335 end Error_Pragma_Arg_Ident;
2337 ----------------------
2338 -- Error_Pragma_Ref --
2339 ----------------------
2341 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2342 MsgF : String := Msg;
2344 Error_Msg_Name_1 := Pname;
2346 Error_Msg_Sloc := Sloc (Ref);
2347 Error_Msg_NE (MsgF, N, Ref);
2349 end Error_Pragma_Ref;
2351 ------------------------
2352 -- Find_Lib_Unit_Name --
2353 ------------------------
2355 function Find_Lib_Unit_Name return Entity_Id is
2357 -- Return inner compilation unit entity, for case of nested
2358 -- categorization pragmas. This happens in generic unit.
2360 if Nkind (Parent (N)) = N_Package_Specification
2361 and then Defining_Entity (Parent (N)) /= Current_Scope
2363 return Defining_Entity (Parent (N));
2365 return Current_Scope;
2367 end Find_Lib_Unit_Name;
2369 ----------------------------
2370 -- Find_Program_Unit_Name --
2371 ----------------------------
2373 procedure Find_Program_Unit_Name (Id : Node_Id) is
2374 Unit_Name : Entity_Id;
2375 Unit_Kind : Node_Kind;
2376 P : constant Node_Id := Parent (N);
2379 if Nkind (P) = N_Compilation_Unit then
2380 Unit_Kind := Nkind (Unit (P));
2382 if Unit_Kind = N_Subprogram_Declaration
2383 or else Unit_Kind = N_Package_Declaration
2384 or else Unit_Kind in N_Generic_Declaration
2386 Unit_Name := Defining_Entity (Unit (P));
2388 if Chars (Id) = Chars (Unit_Name) then
2389 Set_Entity (Id, Unit_Name);
2390 Set_Etype (Id, Etype (Unit_Name));
2392 Set_Etype (Id, Any_Type);
2394 ("cannot find program unit referenced by pragma%");
2398 Set_Etype (Id, Any_Type);
2399 Error_Pragma ("pragma% inapplicable to this unit");
2405 end Find_Program_Unit_Name;
2407 -----------------------------------------
2408 -- Find_Unique_Parameterless_Procedure --
2409 -----------------------------------------
2411 function Find_Unique_Parameterless_Procedure
2413 Arg : Node_Id) return Entity_Id
2415 Proc : Entity_Id := Empty;
2418 -- The body of this procedure needs some comments ???
2420 if not Is_Entity_Name (Name) then
2422 ("argument of pragma% must be entity name", Arg);
2424 elsif not Is_Overloaded (Name) then
2425 Proc := Entity (Name);
2427 if Ekind (Proc) /= E_Procedure
2428 or else Present (First_Formal (Proc))
2431 ("argument of pragma% must be parameterless procedure", Arg);
2436 Found : Boolean := False;
2438 Index : Interp_Index;
2441 Get_First_Interp (Name, Index, It);
2442 while Present (It.Nam) loop
2445 if Ekind (Proc) = E_Procedure
2446 and then No (First_Formal (Proc))
2450 Set_Entity (Name, Proc);
2451 Set_Is_Overloaded (Name, False);
2454 ("ambiguous handler name for pragma% ", Arg);
2458 Get_Next_Interp (Index, It);
2463 ("argument of pragma% must be parameterless procedure",
2466 Proc := Entity (Name);
2472 end Find_Unique_Parameterless_Procedure;
2478 procedure Fix_Error (Msg : in out String) is
2480 if From_Aspect_Specification (N) then
2481 for J in Msg'First .. Msg'Last - 5 loop
2482 if Msg (J .. J + 5) = "pragma" then
2483 Msg (J .. J + 5) := "aspect";
2487 if Error_Msg_Name_1 = Name_Precondition then
2488 Error_Msg_Name_1 := Name_Pre;
2489 elsif Error_Msg_Name_1 = Name_Postcondition then
2490 Error_Msg_Name_1 := Name_Post;
2495 -------------------------
2496 -- Gather_Associations --
2497 -------------------------
2499 procedure Gather_Associations
2501 Args : out Args_List)
2506 -- Initialize all parameters to Empty
2508 for J in Args'Range loop
2512 -- That's all we have to do if there are no argument associations
2514 if No (Pragma_Argument_Associations (N)) then
2518 -- Otherwise first deal with any positional parameters present
2520 Arg := First (Pragma_Argument_Associations (N));
2521 for Index in Args'Range loop
2522 exit when No (Arg) or else Chars (Arg) /= No_Name;
2523 Args (Index) := Get_Pragma_Arg (Arg);
2527 -- Positional parameters all processed, if any left, then we
2528 -- have too many positional parameters.
2530 if Present (Arg) and then Chars (Arg) = No_Name then
2532 ("too many positional associations for pragma%", Arg);
2535 -- Process named parameters if any are present
2537 while Present (Arg) loop
2538 if Chars (Arg) = No_Name then
2540 ("positional association cannot follow named association",
2544 for Index in Names'Range loop
2545 if Names (Index) = Chars (Arg) then
2546 if Present (Args (Index)) then
2548 ("duplicate argument association for pragma%", Arg);
2550 Args (Index) := Get_Pragma_Arg (Arg);
2555 if Index = Names'Last then
2556 Error_Msg_Name_1 := Pname;
2557 Error_Msg_N ("pragma% does not allow & argument", Arg);
2559 -- Check for possible misspelling
2561 for Index1 in Names'Range loop
2562 if Is_Bad_Spelling_Of
2563 (Chars (Arg), Names (Index1))
2565 Error_Msg_Name_1 := Names (Index1);
2566 Error_Msg_N -- CODEFIX
2567 ("\possible misspelling of%", Arg);
2579 end Gather_Associations;
2585 procedure GNAT_Pragma is
2587 Check_Restriction (No_Implementation_Pragmas, N);
2590 --------------------------
2591 -- Is_Before_First_Decl --
2592 --------------------------
2594 function Is_Before_First_Decl
2595 (Pragma_Node : Node_Id;
2596 Decls : List_Id) return Boolean
2598 Item : Node_Id := First (Decls);
2601 -- Only other pragmas can come before this pragma
2604 if No (Item) or else Nkind (Item) /= N_Pragma then
2607 elsif Item = Pragma_Node then
2613 end Is_Before_First_Decl;
2615 -----------------------------
2616 -- Is_Configuration_Pragma --
2617 -----------------------------
2619 -- A configuration pragma must appear in the context clause of a
2620 -- compilation unit, and only other pragmas may precede it. Note that
2621 -- the test below also permits use in a configuration pragma file.
2623 function Is_Configuration_Pragma return Boolean is
2624 Lis : constant List_Id := List_Containing (N);
2625 Par : constant Node_Id := Parent (N);
2629 -- If no parent, then we are in the configuration pragma file,
2630 -- so the placement is definitely appropriate.
2635 -- Otherwise we must be in the context clause of a compilation unit
2636 -- and the only thing allowed before us in the context list is more
2637 -- configuration pragmas.
2639 elsif Nkind (Par) = N_Compilation_Unit
2640 and then Context_Items (Par) = Lis
2647 elsif Nkind (Prg) /= N_Pragma then
2657 end Is_Configuration_Pragma;
2659 --------------------------
2660 -- Is_In_Context_Clause --
2661 --------------------------
2663 function Is_In_Context_Clause return Boolean is
2665 Parent_Node : Node_Id;
2668 if not Is_List_Member (N) then
2672 Plist := List_Containing (N);
2673 Parent_Node := Parent (Plist);
2675 if Parent_Node = Empty
2676 or else Nkind (Parent_Node) /= N_Compilation_Unit
2677 or else Context_Items (Parent_Node) /= Plist
2684 end Is_In_Context_Clause;
2686 ---------------------------------
2687 -- Is_Static_String_Expression --
2688 ---------------------------------
2690 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2691 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2694 Analyze_And_Resolve (Argx);
2695 return Is_OK_Static_Expression (Argx)
2696 and then Nkind (Argx) = N_String_Literal;
2697 end Is_Static_String_Expression;
2699 ----------------------
2700 -- Pragma_Misplaced --
2701 ----------------------
2703 procedure Pragma_Misplaced is
2705 Error_Pragma ("incorrect placement of pragma%");
2706 end Pragma_Misplaced;
2708 ------------------------------------
2709 -- Process Atomic_Shared_Volatile --
2710 ------------------------------------
2712 procedure Process_Atomic_Shared_Volatile is
2719 procedure Set_Atomic (E : Entity_Id);
2720 -- Set given type as atomic, and if no explicit alignment was given,
2721 -- set alignment to unknown, since back end knows what the alignment
2722 -- requirements are for atomic arrays. Note: this step is necessary
2723 -- for derived types.
2729 procedure Set_Atomic (E : Entity_Id) is
2733 if not Has_Alignment_Clause (E) then
2734 Set_Alignment (E, Uint_0);
2738 -- Start of processing for Process_Atomic_Shared_Volatile
2741 Check_Ada_83_Warning;
2742 Check_No_Identifiers;
2743 Check_Arg_Count (1);
2744 Check_Arg_Is_Local_Name (Arg1);
2745 E_Id := Get_Pragma_Arg (Arg1);
2747 if Etype (E_Id) = Any_Type then
2752 D := Declaration_Node (E);
2755 -- Check duplicate before we chain ourselves!
2757 Check_Duplicate_Pragma (E);
2759 -- Now check appropriateness of the entity
2762 if Rep_Item_Too_Early (E, N)
2764 Rep_Item_Too_Late (E, N)
2768 Check_First_Subtype (Arg1);
2771 if Prag_Id /= Pragma_Volatile then
2773 Set_Atomic (Underlying_Type (E));
2774 Set_Atomic (Base_Type (E));
2777 -- Attribute belongs on the base type. If the view of the type is
2778 -- currently private, it also belongs on the underlying type.
2780 Set_Is_Volatile (Base_Type (E));
2781 Set_Is_Volatile (Underlying_Type (E));
2783 Set_Treat_As_Volatile (E);
2784 Set_Treat_As_Volatile (Underlying_Type (E));
2786 elsif K = N_Object_Declaration
2787 or else (K = N_Component_Declaration
2788 and then Original_Record_Component (E) = E)
2790 if Rep_Item_Too_Late (E, N) then
2794 if Prag_Id /= Pragma_Volatile then
2797 -- If the object declaration has an explicit initialization, a
2798 -- temporary may have to be created to hold the expression, to
2799 -- ensure that access to the object remain atomic.
2801 if Nkind (Parent (E)) = N_Object_Declaration
2802 and then Present (Expression (Parent (E)))
2804 Set_Has_Delayed_Freeze (E);
2807 -- An interesting improvement here. If an object of type X is
2808 -- declared atomic, and the type X is not atomic, that's a
2809 -- pity, since it may not have appropriate alignment etc. We
2810 -- can rescue this in the special case where the object and
2811 -- type are in the same unit by just setting the type as
2812 -- atomic, so that the back end will process it as atomic.
2814 Utyp := Underlying_Type (Etype (E));
2817 and then Sloc (E) > No_Location
2818 and then Sloc (Utyp) > No_Location
2820 Get_Source_File_Index (Sloc (E)) =
2821 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2823 Set_Is_Atomic (Underlying_Type (Etype (E)));
2827 Set_Is_Volatile (E);
2828 Set_Treat_As_Volatile (E);
2832 ("inappropriate entity for pragma%", Arg1);
2834 end Process_Atomic_Shared_Volatile;
2836 -------------------------------------------
2837 -- Process_Compile_Time_Warning_Or_Error --
2838 -------------------------------------------
2840 procedure Process_Compile_Time_Warning_Or_Error is
2841 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2844 Check_Arg_Count (2);
2845 Check_No_Identifiers;
2846 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2847 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2849 if Compile_Time_Known_Value (Arg1x) then
2850 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2852 Str : constant String_Id :=
2853 Strval (Get_Pragma_Arg (Arg2));
2854 Len : constant Int := String_Length (Str);
2859 Cent : constant Entity_Id :=
2860 Cunit_Entity (Current_Sem_Unit);
2862 Force : constant Boolean :=
2863 Prag_Id = Pragma_Compile_Time_Warning
2865 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2866 and then (Ekind (Cent) /= E_Package
2867 or else not In_Private_Part (Cent));
2868 -- Set True if this is the warning case, and we are in the
2869 -- visible part of a package spec, or in a subprogram spec,
2870 -- in which case we want to force the client to see the
2871 -- warning, even though it is not in the main unit.
2874 -- Loop through segments of message separated by line feeds.
2875 -- We output these segments as separate messages with
2876 -- continuation marks for all but the first.
2881 Error_Msg_Strlen := 0;
2883 -- Loop to copy characters from argument to error message
2887 exit when Ptr > Len;
2888 CC := Get_String_Char (Str, Ptr);
2891 -- Ignore wide chars ??? else store character
2893 if In_Character_Range (CC) then
2894 C := Get_Character (CC);
2895 exit when C = ASCII.LF;
2896 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2897 Error_Msg_String (Error_Msg_Strlen) := C;
2901 -- Here with one line ready to go
2903 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2905 -- If this is a warning in a spec, then we want clients
2906 -- to see the warning, so mark the message with the
2907 -- special sequence !! to force the warning. In the case
2908 -- of a package spec, we do not force this if we are in
2909 -- the private part of the spec.
2912 if Cont = False then
2913 Error_Msg_N ("<~!!", Arg1);
2916 Error_Msg_N ("\<~!!", Arg1);
2919 -- Error, rather than warning, or in a body, so we do not
2920 -- need to force visibility for client (error will be
2921 -- output in any case, and this is the situation in which
2922 -- we do not want a client to get a warning, since the
2923 -- warning is in the body or the spec private part).
2926 if Cont = False then
2927 Error_Msg_N ("<~", Arg1);
2930 Error_Msg_N ("\<~", Arg1);
2934 exit when Ptr > Len;
2939 end Process_Compile_Time_Warning_Or_Error;
2941 ------------------------
2942 -- Process_Convention --
2943 ------------------------
2945 procedure Process_Convention
2946 (C : out Convention_Id;
2947 Ent : out Entity_Id)
2953 Comp_Unit : Unit_Number_Type;
2955 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2956 -- Called if we have more than one Export/Import/Convention pragma.
2957 -- This is generally illegal, but we have a special case of allowing
2958 -- Import and Interface to coexist if they specify the convention in
2959 -- a consistent manner. We are allowed to do this, since Interface is
2960 -- an implementation defined pragma, and we choose to do it since we
2961 -- know Rational allows this combination. S is the entity id of the
2962 -- subprogram in question. This procedure also sets the special flag
2963 -- Import_Interface_Present in both pragmas in the case where we do
2964 -- have matching Import and Interface pragmas.
2966 procedure Set_Convention_From_Pragma (E : Entity_Id);
2967 -- Set convention in entity E, and also flag that the entity has a
2968 -- convention pragma. If entity is for a private or incomplete type,
2969 -- also set convention and flag on underlying type. This procedure
2970 -- also deals with the special case of C_Pass_By_Copy convention.
2972 -------------------------------
2973 -- Diagnose_Multiple_Pragmas --
2974 -------------------------------
2976 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2977 Pdec : constant Node_Id := Declaration_Node (S);
2981 function Same_Convention (Decl : Node_Id) return Boolean;
2982 -- Decl is a pragma node. This function returns True if this
2983 -- pragma has a first argument that is an identifier with a
2984 -- Chars field corresponding to the Convention_Id C.
2986 function Same_Name (Decl : Node_Id) return Boolean;
2987 -- Decl is a pragma node. This function returns True if this
2988 -- pragma has a second argument that is an identifier with a
2989 -- Chars field that matches the Chars of the current subprogram.
2991 ---------------------
2992 -- Same_Convention --
2993 ---------------------
2995 function Same_Convention (Decl : Node_Id) return Boolean is
2996 Arg1 : constant Node_Id :=
2997 First (Pragma_Argument_Associations (Decl));
3000 if Present (Arg1) then
3002 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3004 if Nkind (Arg) = N_Identifier
3005 and then Is_Convention_Name (Chars (Arg))
3006 and then Get_Convention_Id (Chars (Arg)) = C
3014 end Same_Convention;
3020 function Same_Name (Decl : Node_Id) return Boolean is
3021 Arg1 : constant Node_Id :=
3022 First (Pragma_Argument_Associations (Decl));
3030 Arg2 := Next (Arg1);
3037 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3039 if Nkind (Arg) = N_Identifier
3040 and then Chars (Arg) = Chars (S)
3049 -- Start of processing for Diagnose_Multiple_Pragmas
3054 -- Definitely give message if we have Convention/Export here
3056 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3059 -- If we have an Import or Export, scan back from pragma to
3060 -- find any previous pragma applying to the same procedure.
3061 -- The scan will be terminated by the start of the list, or
3062 -- hitting the subprogram declaration. This won't allow one
3063 -- pragma to appear in the public part and one in the private
3064 -- part, but that seems very unlikely in practice.
3068 while Present (Decl) and then Decl /= Pdec loop
3070 -- Look for pragma with same name as us
3072 if Nkind (Decl) = N_Pragma
3073 and then Same_Name (Decl)
3075 -- Give error if same as our pragma or Export/Convention
3077 if Pragma_Name (Decl) = Name_Export
3079 Pragma_Name (Decl) = Name_Convention
3081 Pragma_Name (Decl) = Pragma_Name (N)
3085 -- Case of Import/Interface or the other way round
3087 elsif Pragma_Name (Decl) = Name_Interface
3089 Pragma_Name (Decl) = Name_Import
3091 -- Here we know that we have Import and Interface. It
3092 -- doesn't matter which way round they are. See if
3093 -- they specify the same convention. If so, all OK,
3094 -- and set special flags to stop other messages
3096 if Same_Convention (Decl) then
3097 Set_Import_Interface_Present (N);
3098 Set_Import_Interface_Present (Decl);
3101 -- If different conventions, special message
3104 Error_Msg_Sloc := Sloc (Decl);
3106 ("convention differs from that given#", Arg1);
3116 -- Give message if needed if we fall through those tests
3120 ("at most one Convention/Export/Import pragma is allowed",
3123 end Diagnose_Multiple_Pragmas;
3125 --------------------------------
3126 -- Set_Convention_From_Pragma --
3127 --------------------------------
3129 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3131 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3132 -- for an overridden dispatching operation. Technically this is
3133 -- an amendment and should only be done in Ada 2005 mode. However,
3134 -- this is clearly a mistake, since the problem that is addressed
3135 -- by this AI is that there is a clear gap in the RM!
3137 if Is_Dispatching_Operation (E)
3138 and then Present (Overridden_Operation (E))
3139 and then C /= Convention (Overridden_Operation (E))
3142 ("cannot change convention for " &
3143 "overridden dispatching operation",
3147 -- Set the convention
3149 Set_Convention (E, C);
3150 Set_Has_Convention_Pragma (E);
3152 if Is_Incomplete_Or_Private_Type (E)
3153 and then Present (Underlying_Type (E))
3155 Set_Convention (Underlying_Type (E), C);
3156 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3159 -- A class-wide type should inherit the convention of the specific
3160 -- root type (although this isn't specified clearly by the RM).
3162 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3163 Set_Convention (Class_Wide_Type (E), C);
3166 -- If the entity is a record type, then check for special case of
3167 -- C_Pass_By_Copy, which is treated the same as C except that the
3168 -- special record flag is set. This convention is only permitted
3169 -- on record types (see AI95-00131).
3171 if Cname = Name_C_Pass_By_Copy then
3172 if Is_Record_Type (E) then
3173 Set_C_Pass_By_Copy (Base_Type (E));
3174 elsif Is_Incomplete_Or_Private_Type (E)
3175 and then Is_Record_Type (Underlying_Type (E))
3177 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3180 ("C_Pass_By_Copy convention allowed only for record type",
3185 -- If the entity is a derived boolean type, check for the special
3186 -- case of convention C, C++, or Fortran, where we consider any
3187 -- nonzero value to represent true.
3189 if Is_Discrete_Type (E)
3190 and then Root_Type (Etype (E)) = Standard_Boolean
3196 C = Convention_Fortran)
3198 Set_Nonzero_Is_True (Base_Type (E));
3200 end Set_Convention_From_Pragma;
3202 -- Start of processing for Process_Convention
3205 Check_At_Least_N_Arguments (2);
3206 Check_Optional_Identifier (Arg1, Name_Convention);
3207 Check_Arg_Is_Identifier (Arg1);
3208 Cname := Chars (Get_Pragma_Arg (Arg1));
3210 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3211 -- tested again below to set the critical flag).
3213 if Cname = Name_C_Pass_By_Copy then
3216 -- Otherwise we must have something in the standard convention list
3218 elsif Is_Convention_Name (Cname) then
3219 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3221 -- In DEC VMS, it seems that there is an undocumented feature that
3222 -- any unrecognized convention is treated as the default, which for
3223 -- us is convention C. It does not seem so terrible to do this
3224 -- unconditionally, silently in the VMS case, and with a warning
3225 -- in the non-VMS case.
3228 if Warn_On_Export_Import and not OpenVMS_On_Target then
3230 ("?unrecognized convention name, C assumed",
3231 Get_Pragma_Arg (Arg1));
3237 Check_Optional_Identifier (Arg2, Name_Entity);
3238 Check_Arg_Is_Local_Name (Arg2);
3240 Id := Get_Pragma_Arg (Arg2);
3243 if not Is_Entity_Name (Id) then
3244 Error_Pragma_Arg ("entity name required", Arg2);
3249 -- Set entity to return
3253 -- Ada_Pass_By_Copy special checking
3255 if C = Convention_Ada_Pass_By_Copy then
3256 if not Is_First_Subtype (E) then
3258 ("convention `Ada_Pass_By_Copy` only "
3259 & "allowed for types", Arg2);
3262 if Is_By_Reference_Type (E) then
3264 ("convention `Ada_Pass_By_Copy` not allowed for "
3265 & "by-reference type", Arg1);
3269 -- Ada_Pass_By_Reference special checking
3271 if C = Convention_Ada_Pass_By_Reference then
3272 if not Is_First_Subtype (E) then
3274 ("convention `Ada_Pass_By_Reference` only "
3275 & "allowed for types", Arg2);
3278 if Is_By_Copy_Type (E) then
3280 ("convention `Ada_Pass_By_Reference` not allowed for "
3281 & "by-copy type", Arg1);
3285 -- Go to renamed subprogram if present, since convention applies to
3286 -- the actual renamed entity, not to the renaming entity. If the
3287 -- subprogram is inherited, go to parent subprogram.
3289 if Is_Subprogram (E)
3290 and then Present (Alias (E))
3292 if Nkind (Parent (Declaration_Node (E))) =
3293 N_Subprogram_Renaming_Declaration
3295 if Scope (E) /= Scope (Alias (E)) then
3297 ("cannot apply pragma% to non-local entity&#", E);
3302 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3303 N_Private_Extension_Declaration)
3304 and then Scope (E) = Scope (Alias (E))
3308 -- Return the parent subprogram the entity was inherited from
3314 -- Check that we are not applying this to a specless body
3316 if Is_Subprogram (E)
3317 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3320 ("pragma% requires separate spec and must come before body");
3323 -- Check that we are not applying this to a named constant
3325 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3326 Error_Msg_Name_1 := Pname;
3328 ("cannot apply pragma% to named constant!",
3329 Get_Pragma_Arg (Arg2));
3331 ("\supply appropriate type for&!", Arg2);
3334 if Ekind (E) = E_Enumeration_Literal then
3335 Error_Pragma ("enumeration literal not allowed for pragma%");
3338 -- Check for rep item appearing too early or too late
3340 if Etype (E) = Any_Type
3341 or else Rep_Item_Too_Early (E, N)
3345 elsif Present (Underlying_Type (E)) then
3346 E := Underlying_Type (E);
3349 if Rep_Item_Too_Late (E, N) then
3353 if Has_Convention_Pragma (E) then
3354 Diagnose_Multiple_Pragmas (E);
3356 elsif Convention (E) = Convention_Protected
3357 or else Ekind (Scope (E)) = E_Protected_Type
3360 ("a protected operation cannot be given a different convention",
3364 -- For Intrinsic, a subprogram is required
3366 if C = Convention_Intrinsic
3367 and then not Is_Subprogram (E)
3368 and then not Is_Generic_Subprogram (E)
3371 ("second argument of pragma% must be a subprogram", Arg2);
3374 -- For Stdcall, a subprogram, variable or subprogram type is required
3376 if C = Convention_Stdcall
3377 and then not Is_Subprogram (E)
3378 and then not Is_Generic_Subprogram (E)
3379 and then Ekind (E) /= E_Variable
3382 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3385 ("second argument of pragma% must be subprogram (type)",
3389 if not Is_Subprogram (E)
3390 and then not Is_Generic_Subprogram (E)
3392 Set_Convention_From_Pragma (E);
3395 Check_First_Subtype (Arg2);
3396 Set_Convention_From_Pragma (Base_Type (E));
3398 -- For subprograms, we must set the convention on the
3399 -- internally generated directly designated type as well.
3401 if Ekind (E) = E_Access_Subprogram_Type then
3402 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3406 -- For the subprogram case, set proper convention for all homonyms
3407 -- in same scope and the same declarative part, i.e. the same
3408 -- compilation unit.
3411 Comp_Unit := Get_Source_Unit (E);
3412 Set_Convention_From_Pragma (E);
3414 -- Treat a pragma Import as an implicit body, for GPS use
3416 if Prag_Id = Pragma_Import then
3417 Generate_Reference (E, Id, 'b');
3420 -- Loop through the homonyms of the pragma argument's entity
3425 exit when No (E1) or else Scope (E1) /= Current_Scope;
3427 -- Do not set the pragma on inherited operations or on formal
3430 if Comes_From_Source (E1)
3431 and then Comp_Unit = Get_Source_Unit (E1)
3432 and then not Is_Formal_Subprogram (E1)
3433 and then Nkind (Original_Node (Parent (E1))) /=
3434 N_Full_Type_Declaration
3436 if Present (Alias (E1))
3437 and then Scope (E1) /= Scope (Alias (E1))
3440 ("cannot apply pragma% to non-local entity& declared#",
3444 Set_Convention_From_Pragma (E1);
3446 if Prag_Id = Pragma_Import then
3447 Generate_Reference (E1, Id, 'b');
3451 -- For aspect case, do NOT apply to homonyms
3453 exit when From_Aspect_Specification (N);
3456 end Process_Convention;
3458 -----------------------------------------------------
3459 -- Process_Extended_Import_Export_Exception_Pragma --
3460 -----------------------------------------------------
3462 procedure Process_Extended_Import_Export_Exception_Pragma
3463 (Arg_Internal : Node_Id;
3464 Arg_External : Node_Id;
3472 if not OpenVMS_On_Target then
3474 ("?pragma% ignored (applies only to Open'V'M'S)");
3477 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3478 Def_Id := Entity (Arg_Internal);
3480 if Ekind (Def_Id) /= E_Exception then
3482 ("pragma% must refer to declared exception", Arg_Internal);
3485 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3487 if Present (Arg_Form) then
3488 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3491 if Present (Arg_Form)
3492 and then Chars (Arg_Form) = Name_Ada
3496 Set_Is_VMS_Exception (Def_Id);
3497 Set_Exception_Code (Def_Id, No_Uint);
3500 if Present (Arg_Code) then
3501 if not Is_VMS_Exception (Def_Id) then
3503 ("Code option for pragma% not allowed for Ada case",
3507 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3508 Code_Val := Expr_Value (Arg_Code);
3510 if not UI_Is_In_Int_Range (Code_Val) then
3512 ("Code option for pragma% must be in 32-bit range",
3516 Set_Exception_Code (Def_Id, Code_Val);
3519 end Process_Extended_Import_Export_Exception_Pragma;
3521 -------------------------------------------------
3522 -- Process_Extended_Import_Export_Internal_Arg --
3523 -------------------------------------------------
3525 procedure Process_Extended_Import_Export_Internal_Arg
3526 (Arg_Internal : Node_Id := Empty)
3529 if No (Arg_Internal) then
3530 Error_Pragma ("Internal parameter required for pragma%");
3533 if Nkind (Arg_Internal) = N_Identifier then
3536 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3537 and then (Prag_Id = Pragma_Import_Function
3539 Prag_Id = Pragma_Export_Function)
3545 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3548 Check_Arg_Is_Local_Name (Arg_Internal);
3549 end Process_Extended_Import_Export_Internal_Arg;
3551 --------------------------------------------------
3552 -- Process_Extended_Import_Export_Object_Pragma --
3553 --------------------------------------------------
3555 procedure Process_Extended_Import_Export_Object_Pragma
3556 (Arg_Internal : Node_Id;
3557 Arg_External : Node_Id;
3563 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3564 Def_Id := Entity (Arg_Internal);
3566 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3568 ("pragma% must designate an object", Arg_Internal);
3571 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3573 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3576 ("previous Common/Psect_Object applies, pragma % not permitted",
3580 if Rep_Item_Too_Late (Def_Id, N) then
3584 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3586 if Present (Arg_Size) then
3587 Check_Arg_Is_External_Name (Arg_Size);
3590 -- Export_Object case
3592 if Prag_Id = Pragma_Export_Object then
3593 if not Is_Library_Level_Entity (Def_Id) then
3595 ("argument for pragma% must be library level entity",
3599 if Ekind (Current_Scope) = E_Generic_Package then
3600 Error_Pragma ("pragma& cannot appear in a generic unit");
3603 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3605 ("exported object must have compile time known size",
3609 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3610 Error_Msg_N ("?duplicate Export_Object pragma", N);
3612 Set_Exported (Def_Id, Arg_Internal);
3615 -- Import_Object case
3618 if Is_Concurrent_Type (Etype (Def_Id)) then
3620 ("cannot use pragma% for task/protected object",
3624 if Ekind (Def_Id) = E_Constant then
3626 ("cannot import a constant", Arg_Internal);
3629 if Warn_On_Export_Import
3630 and then Has_Discriminants (Etype (Def_Id))
3633 ("imported value must be initialized?", Arg_Internal);
3636 if Warn_On_Export_Import
3637 and then Is_Access_Type (Etype (Def_Id))
3640 ("cannot import object of an access type?", Arg_Internal);
3643 if Warn_On_Export_Import
3644 and then Is_Imported (Def_Id)
3647 ("?duplicate Import_Object pragma", N);
3649 -- Check for explicit initialization present. Note that an
3650 -- initialization generated by the code generator, e.g. for an
3651 -- access type, does not count here.
3653 elsif Present (Expression (Parent (Def_Id)))
3656 (Original_Node (Expression (Parent (Def_Id))))
3658 Error_Msg_Sloc := Sloc (Def_Id);
3660 ("imported entities cannot be initialized (RM B.1(24))",
3661 "\no initialization allowed for & declared#", Arg1);
3663 Set_Imported (Def_Id);
3664 Note_Possible_Modification (Arg_Internal, Sure => False);
3667 end Process_Extended_Import_Export_Object_Pragma;
3669 ------------------------------------------------------
3670 -- Process_Extended_Import_Export_Subprogram_Pragma --
3671 ------------------------------------------------------
3673 procedure Process_Extended_Import_Export_Subprogram_Pragma
3674 (Arg_Internal : Node_Id;
3675 Arg_External : Node_Id;
3676 Arg_Parameter_Types : Node_Id;
3677 Arg_Result_Type : Node_Id := Empty;
3678 Arg_Mechanism : Node_Id;
3679 Arg_Result_Mechanism : Node_Id := Empty;
3680 Arg_First_Optional_Parameter : Node_Id := Empty)
3686 Ambiguous : Boolean;
3690 function Same_Base_Type
3692 Formal : Entity_Id) return Boolean;
3693 -- Determines if Ptype references the type of Formal. Note that only
3694 -- the base types need to match according to the spec. Ptype here is
3695 -- the argument from the pragma, which is either a type name, or an
3696 -- access attribute.
3698 --------------------
3699 -- Same_Base_Type --
3700 --------------------
3702 function Same_Base_Type
3704 Formal : Entity_Id) return Boolean
3706 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3710 -- Case where pragma argument is typ'Access
3712 if Nkind (Ptype) = N_Attribute_Reference
3713 and then Attribute_Name (Ptype) = Name_Access
3715 Pref := Prefix (Ptype);
3718 if not Is_Entity_Name (Pref)
3719 or else Entity (Pref) = Any_Type
3724 -- We have a match if the corresponding argument is of an
3725 -- anonymous access type, and its designated type matches the
3726 -- type of the prefix of the access attribute
3728 return Ekind (Ftyp) = E_Anonymous_Access_Type
3729 and then Base_Type (Entity (Pref)) =
3730 Base_Type (Etype (Designated_Type (Ftyp)));
3732 -- Case where pragma argument is a type name
3737 if not Is_Entity_Name (Ptype)
3738 or else Entity (Ptype) = Any_Type
3743 -- We have a match if the corresponding argument is of the type
3744 -- given in the pragma (comparing base types)
3746 return Base_Type (Entity (Ptype)) = Ftyp;
3750 -- Start of processing for
3751 -- Process_Extended_Import_Export_Subprogram_Pragma
3754 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3758 -- Loop through homonyms (overloadings) of the entity
3760 Hom_Id := Entity (Arg_Internal);
3761 while Present (Hom_Id) loop
3762 Def_Id := Get_Base_Subprogram (Hom_Id);
3764 -- We need a subprogram in the current scope
3766 if not Is_Subprogram (Def_Id)
3767 or else Scope (Def_Id) /= Current_Scope
3774 -- Pragma cannot apply to subprogram body
3776 if Is_Subprogram (Def_Id)
3777 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3781 ("pragma% requires separate spec"
3782 & " and must come before body");
3785 -- Test result type if given, note that the result type
3786 -- parameter can only be present for the function cases.
3788 if Present (Arg_Result_Type)
3789 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3793 elsif Etype (Def_Id) /= Standard_Void_Type
3795 (Pname = Name_Export_Procedure
3797 Pname = Name_Import_Procedure)
3801 -- Test parameter types if given. Note that this parameter
3802 -- has not been analyzed (and must not be, since it is
3803 -- semantic nonsense), so we get it as the parser left it.
3805 elsif Present (Arg_Parameter_Types) then
3806 Check_Matching_Types : declare
3811 Formal := First_Formal (Def_Id);
3813 if Nkind (Arg_Parameter_Types) = N_Null then
3814 if Present (Formal) then
3818 -- A list of one type, e.g. (List) is parsed as
3819 -- a parenthesized expression.
3821 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3822 and then Paren_Count (Arg_Parameter_Types) = 1
3825 or else Present (Next_Formal (Formal))
3830 Same_Base_Type (Arg_Parameter_Types, Formal);
3833 -- A list of more than one type is parsed as a aggregate
3835 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3836 and then Paren_Count (Arg_Parameter_Types) = 0
3838 Ptype := First (Expressions (Arg_Parameter_Types));
3839 while Present (Ptype) or else Present (Formal) loop
3842 or else not Same_Base_Type (Ptype, Formal)
3847 Next_Formal (Formal);
3852 -- Anything else is of the wrong form
3856 ("wrong form for Parameter_Types parameter",
3857 Arg_Parameter_Types);
3859 end Check_Matching_Types;
3862 -- Match is now False if the entry we found did not match
3863 -- either a supplied Parameter_Types or Result_Types argument
3869 -- Ambiguous case, the flag Ambiguous shows if we already
3870 -- detected this and output the initial messages.
3873 if not Ambiguous then
3875 Error_Msg_Name_1 := Pname;
3877 ("pragma% does not uniquely identify subprogram!",
3879 Error_Msg_Sloc := Sloc (Ent);
3880 Error_Msg_N ("matching subprogram #!", N);
3884 Error_Msg_Sloc := Sloc (Def_Id);
3885 Error_Msg_N ("matching subprogram #!", N);
3890 Hom_Id := Homonym (Hom_Id);
3893 -- See if we found an entry
3896 if not Ambiguous then
3897 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3899 ("pragma% cannot be given for generic subprogram");
3902 ("pragma% does not identify local subprogram");
3909 -- Import pragmas must be for imported entities
3911 if Prag_Id = Pragma_Import_Function
3913 Prag_Id = Pragma_Import_Procedure
3915 Prag_Id = Pragma_Import_Valued_Procedure
3917 if not Is_Imported (Ent) then
3919 ("pragma Import or Interface must precede pragma%");
3922 -- Here we have the Export case which can set the entity as exported
3924 -- But does not do so if the specified external name is null, since
3925 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3926 -- compatible) to request no external name.
3928 elsif Nkind (Arg_External) = N_String_Literal
3929 and then String_Length (Strval (Arg_External)) = 0
3933 -- In all other cases, set entity as exported
3936 Set_Exported (Ent, Arg_Internal);
3939 -- Special processing for Valued_Procedure cases
3941 if Prag_Id = Pragma_Import_Valued_Procedure
3943 Prag_Id = Pragma_Export_Valued_Procedure
3945 Formal := First_Formal (Ent);
3948 Error_Pragma ("at least one parameter required for pragma%");
3950 elsif Ekind (Formal) /= E_Out_Parameter then
3951 Error_Pragma ("first parameter must have mode out for pragma%");
3954 Set_Is_Valued_Procedure (Ent);
3958 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3960 -- Process Result_Mechanism argument if present. We have already
3961 -- checked that this is only allowed for the function case.
3963 if Present (Arg_Result_Mechanism) then
3964 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3967 -- Process Mechanism parameter if present. Note that this parameter
3968 -- is not analyzed, and must not be analyzed since it is semantic
3969 -- nonsense, so we get it in exactly as the parser left it.
3971 if Present (Arg_Mechanism) then
3979 -- A single mechanism association without a formal parameter
3980 -- name is parsed as a parenthesized expression. All other
3981 -- cases are parsed as aggregates, so we rewrite the single
3982 -- parameter case as an aggregate for consistency.
3984 if Nkind (Arg_Mechanism) /= N_Aggregate
3985 and then Paren_Count (Arg_Mechanism) = 1
3987 Rewrite (Arg_Mechanism,
3988 Make_Aggregate (Sloc (Arg_Mechanism),
3989 Expressions => New_List (
3990 Relocate_Node (Arg_Mechanism))));
3993 -- Case of only mechanism name given, applies to all formals
3995 if Nkind (Arg_Mechanism) /= N_Aggregate then
3996 Formal := First_Formal (Ent);
3997 while Present (Formal) loop
3998 Set_Mechanism_Value (Formal, Arg_Mechanism);
3999 Next_Formal (Formal);
4002 -- Case of list of mechanism associations given
4005 if Null_Record_Present (Arg_Mechanism) then
4007 ("inappropriate form for Mechanism parameter",
4011 -- Deal with positional ones first
4013 Formal := First_Formal (Ent);
4015 if Present (Expressions (Arg_Mechanism)) then
4016 Mname := First (Expressions (Arg_Mechanism));
4017 while Present (Mname) loop
4020 ("too many mechanism associations", Mname);
4023 Set_Mechanism_Value (Formal, Mname);
4024 Next_Formal (Formal);
4029 -- Deal with named entries
4031 if Present (Component_Associations (Arg_Mechanism)) then
4032 Massoc := First (Component_Associations (Arg_Mechanism));
4033 while Present (Massoc) loop
4034 Choice := First (Choices (Massoc));
4036 if Nkind (Choice) /= N_Identifier
4037 or else Present (Next (Choice))
4040 ("incorrect form for mechanism association",
4044 Formal := First_Formal (Ent);
4048 ("parameter name & not present", Choice);
4051 if Chars (Choice) = Chars (Formal) then
4053 (Formal, Expression (Massoc));
4055 -- Set entity on identifier (needed by ASIS)
4057 Set_Entity (Choice, Formal);
4062 Next_Formal (Formal);
4072 -- Process First_Optional_Parameter argument if present. We have
4073 -- already checked that this is only allowed for the Import case.
4075 if Present (Arg_First_Optional_Parameter) then
4076 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4078 ("first optional parameter must be formal parameter name",
4079 Arg_First_Optional_Parameter);
4082 Formal := First_Formal (Ent);
4086 ("specified formal parameter& not found",
4087 Arg_First_Optional_Parameter);
4090 exit when Chars (Formal) =
4091 Chars (Arg_First_Optional_Parameter);
4093 Next_Formal (Formal);
4096 Set_First_Optional_Parameter (Ent, Formal);
4098 -- Check specified and all remaining formals have right form
4100 while Present (Formal) loop
4101 if Ekind (Formal) /= E_In_Parameter then
4103 ("optional formal& is not of mode in!",
4104 Arg_First_Optional_Parameter, Formal);
4107 Dval := Default_Value (Formal);
4111 ("optional formal& does not have default value!",
4112 Arg_First_Optional_Parameter, Formal);
4114 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4119 ("default value for optional formal& is non-static!",
4120 Arg_First_Optional_Parameter, Formal);
4124 Set_Is_Optional_Parameter (Formal);
4125 Next_Formal (Formal);
4128 end Process_Extended_Import_Export_Subprogram_Pragma;
4130 --------------------------
4131 -- Process_Generic_List --
4132 --------------------------
4134 procedure Process_Generic_List is
4139 Check_No_Identifiers;
4140 Check_At_Least_N_Arguments (1);
4143 while Present (Arg) loop
4144 Exp := Get_Pragma_Arg (Arg);
4147 if not Is_Entity_Name (Exp)
4149 (not Is_Generic_Instance (Entity (Exp))
4151 not Is_Generic_Unit (Entity (Exp)))
4154 ("pragma% argument must be name of generic unit/instance",
4160 end Process_Generic_List;
4162 ------------------------------------
4163 -- Process_Import_Predefined_Type --
4164 ------------------------------------
4166 procedure Process_Import_Predefined_Type is
4167 Loc : constant Source_Ptr := Sloc (N);
4169 Ftyp : Node_Id := Empty;
4175 String_To_Name_Buffer (Strval (Expression (Arg3)));
4178 Elmt := First_Elmt (Predefined_Float_Types);
4179 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4183 Ftyp := Node (Elmt);
4185 if Present (Ftyp) then
4187 -- Don't build a derived type declaration, because predefined C
4188 -- types have no declaration anywhere, so cannot really be named.
4189 -- Instead build a full type declaration, starting with an
4190 -- appropriate type definition is built
4192 if Is_Floating_Point_Type (Ftyp) then
4193 Def := Make_Floating_Point_Definition (Loc,
4194 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4195 Make_Real_Range_Specification (Loc,
4196 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4197 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4199 -- Should never have a predefined type we cannot handle
4202 raise Program_Error;
4205 -- Build and insert a Full_Type_Declaration, which will be
4206 -- analyzed as soon as this list entry has been analyzed.
4208 Decl := Make_Full_Type_Declaration (Loc,
4209 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4210 Type_Definition => Def);
4212 Insert_After (N, Decl);
4213 Mark_Rewrite_Insertion (Decl);
4216 Error_Pragma_Arg ("no matching type found for pragma%",
4219 end Process_Import_Predefined_Type;
4221 ---------------------------------
4222 -- Process_Import_Or_Interface --
4223 ---------------------------------
4225 procedure Process_Import_Or_Interface is
4231 Process_Convention (C, Def_Id);
4232 Kill_Size_Check_Code (Def_Id);
4233 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4235 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4237 -- We do not permit Import to apply to a renaming declaration
4239 if Present (Renamed_Object (Def_Id)) then
4241 ("pragma% not allowed for object renaming", Arg2);
4243 -- User initialization is not allowed for imported object, but
4244 -- the object declaration may contain a default initialization,
4245 -- that will be discarded. Note that an explicit initialization
4246 -- only counts if it comes from source, otherwise it is simply
4247 -- the code generator making an implicit initialization explicit.
4249 elsif Present (Expression (Parent (Def_Id)))
4250 and then Comes_From_Source (Expression (Parent (Def_Id)))
4252 Error_Msg_Sloc := Sloc (Def_Id);
4254 ("no initialization allowed for declaration of& #",
4255 "\imported entities cannot be initialized (RM B.1(24))",
4259 Set_Imported (Def_Id);
4260 Process_Interface_Name (Def_Id, Arg3, Arg4);
4262 -- Note that we do not set Is_Public here. That's because we
4263 -- only want to set it if there is no address clause, and we
4264 -- don't know that yet, so we delay that processing till
4267 -- pragma Import completes deferred constants
4269 if Ekind (Def_Id) = E_Constant then
4270 Set_Has_Completion (Def_Id);
4273 -- It is not possible to import a constant of an unconstrained
4274 -- array type (e.g. string) because there is no simple way to
4275 -- write a meaningful subtype for it.
4277 if Is_Array_Type (Etype (Def_Id))
4278 and then not Is_Constrained (Etype (Def_Id))
4281 ("imported constant& must have a constrained subtype",
4286 elsif Is_Subprogram (Def_Id)
4287 or else Is_Generic_Subprogram (Def_Id)
4289 -- If the name is overloaded, pragma applies to all of the denoted
4290 -- entities in the same declarative part.
4293 while Present (Hom_Id) loop
4294 Def_Id := Get_Base_Subprogram (Hom_Id);
4296 -- Ignore inherited subprograms because the pragma will apply
4297 -- to the parent operation, which is the one called.
4299 if Is_Overloadable (Def_Id)
4300 and then Present (Alias (Def_Id))
4304 -- If it is not a subprogram, it must be in an outer scope and
4305 -- pragma does not apply.
4307 elsif not Is_Subprogram (Def_Id)
4308 and then not Is_Generic_Subprogram (Def_Id)
4312 -- The pragma does not apply to primitives of interfaces
4314 elsif Is_Dispatching_Operation (Def_Id)
4315 and then Present (Find_Dispatching_Type (Def_Id))
4316 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4320 -- Verify that the homonym is in the same declarative part (not
4321 -- just the same scope).
4323 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4324 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4329 Set_Imported (Def_Id);
4331 -- Reject an Import applied to an abstract subprogram
4333 if Is_Subprogram (Def_Id)
4334 and then Is_Abstract_Subprogram (Def_Id)
4336 Error_Msg_Sloc := Sloc (Def_Id);
4338 ("cannot import abstract subprogram& declared#",
4342 -- Special processing for Convention_Intrinsic
4344 if C = Convention_Intrinsic then
4346 -- Link_Name argument not allowed for intrinsic
4350 Set_Is_Intrinsic_Subprogram (Def_Id);
4352 -- If no external name is present, then check that this
4353 -- is a valid intrinsic subprogram. If an external name
4354 -- is present, then this is handled by the back end.
4357 Check_Intrinsic_Subprogram
4358 (Def_Id, Get_Pragma_Arg (Arg2));
4362 -- All interfaced procedures need an external symbol created
4363 -- for them since they are always referenced from another
4366 Set_Is_Public (Def_Id);
4368 -- Verify that the subprogram does not have a completion
4369 -- through a renaming declaration. For other completions the
4370 -- pragma appears as a too late representation.
4373 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4377 and then Nkind (Decl) = N_Subprogram_Declaration
4378 and then Present (Corresponding_Body (Decl))
4379 and then Nkind (Unit_Declaration_Node
4380 (Corresponding_Body (Decl))) =
4381 N_Subprogram_Renaming_Declaration
4383 Error_Msg_Sloc := Sloc (Def_Id);
4385 ("cannot import&, renaming already provided for " &
4386 "declaration #", N, Def_Id);
4390 Set_Has_Completion (Def_Id);
4391 Process_Interface_Name (Def_Id, Arg3, Arg4);
4394 if Is_Compilation_Unit (Hom_Id) then
4396 -- Its possible homonyms are not affected by the pragma.
4397 -- Such homonyms might be present in the context of other
4398 -- units being compiled.
4403 Hom_Id := Homonym (Hom_Id);
4407 -- When the convention is Java or CIL, we also allow Import to be
4408 -- given for packages, generic packages, exceptions, record
4409 -- components, and access to subprograms.
4411 elsif (C = Convention_Java or else C = Convention_CIL)
4413 (Is_Package_Or_Generic_Package (Def_Id)
4414 or else Ekind (Def_Id) = E_Exception
4415 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4416 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4418 Set_Imported (Def_Id);
4419 Set_Is_Public (Def_Id);
4420 Process_Interface_Name (Def_Id, Arg3, Arg4);
4422 -- Import a CPP class
4424 elsif Is_Record_Type (Def_Id)
4425 and then C = Convention_CPP
4427 -- Types treated as CPP classes must be declared limited (note:
4428 -- this used to be a warning but there is no real benefit to it
4429 -- since we did effectively intend to treat the type as limited
4432 if not Is_Limited_Type (Def_Id) then
4434 ("imported 'C'P'P type must be limited",
4435 Get_Pragma_Arg (Arg2));
4438 Set_Is_CPP_Class (Def_Id);
4440 -- Imported CPP types must not have discriminants (because C++
4441 -- classes do not have discriminants).
4443 if Has_Discriminants (Def_Id) then
4445 ("imported 'C'P'P type cannot have discriminants",
4446 First (Discriminant_Specifications
4447 (Declaration_Node (Def_Id))));
4450 -- Components of imported CPP types must not have default
4451 -- expressions because the constructor (if any) is on the
4455 Tdef : constant Node_Id :=
4456 Type_Definition (Declaration_Node (Def_Id));
4461 if Nkind (Tdef) = N_Record_Definition then
4462 Clist := Component_List (Tdef);
4465 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4466 Clist := Component_List (Record_Extension_Part (Tdef));
4469 if Present (Clist) then
4470 Comp := First (Component_Items (Clist));
4471 while Present (Comp) loop
4472 if Present (Expression (Comp)) then
4474 ("component of imported 'C'P'P type cannot have" &
4475 " default expression", Expression (Comp));
4483 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4485 Check_Arg_Count (3);
4486 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4488 Process_Import_Predefined_Type;
4492 ("second argument of pragma% must be object, subprogram" &
4493 " or incomplete type",
4497 -- If this pragma applies to a compilation unit, then the unit, which
4498 -- is a subprogram, does not require (or allow) a body. We also do
4499 -- not need to elaborate imported procedures.
4501 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4503 Cunit : constant Node_Id := Parent (Parent (N));
4505 Set_Body_Required (Cunit, False);
4508 end Process_Import_Or_Interface;
4510 --------------------
4511 -- Process_Inline --
4512 --------------------
4514 procedure Process_Inline (Active : Boolean) is
4521 Effective : Boolean := False;
4522 -- Set True if inline has some effect, i.e. if there is at least one
4523 -- subprogram set as inlined as a result of the use of the pragma.
4525 procedure Make_Inline (Subp : Entity_Id);
4526 -- Subp is the defining unit name of the subprogram declaration. Set
4527 -- the flag, as well as the flag in the corresponding body, if there
4530 procedure Set_Inline_Flags (Subp : Entity_Id);
4531 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4532 -- Has_Pragma_Inline_Always for the Inline_Always case.
4534 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4535 -- Returns True if it can be determined at this stage that inlining
4536 -- is not possible, for example if the body is available and contains
4537 -- exception handlers, we prevent inlining, since otherwise we can
4538 -- get undefined symbols at link time. This function also emits a
4539 -- warning if front-end inlining is enabled and the pragma appears
4542 -- ??? is business with link symbols still valid, or does it relate
4543 -- to front end ZCX which is being phased out ???
4545 ---------------------------
4546 -- Inlining_Not_Possible --
4547 ---------------------------
4549 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4550 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4554 if Nkind (Decl) = N_Subprogram_Body then
4555 Stats := Handled_Statement_Sequence (Decl);
4556 return Present (Exception_Handlers (Stats))
4557 or else Present (At_End_Proc (Stats));
4559 elsif Nkind (Decl) = N_Subprogram_Declaration
4560 and then Present (Corresponding_Body (Decl))
4562 if Front_End_Inlining
4563 and then Analyzed (Corresponding_Body (Decl))
4565 Error_Msg_N ("pragma appears too late, ignored?", N);
4568 -- If the subprogram is a renaming as body, the body is just a
4569 -- call to the renamed subprogram, and inlining is trivially
4573 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4574 N_Subprogram_Renaming_Declaration
4580 Handled_Statement_Sequence
4581 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4584 Present (Exception_Handlers (Stats))
4585 or else Present (At_End_Proc (Stats));
4589 -- If body is not available, assume the best, the check is
4590 -- performed again when compiling enclosing package bodies.
4594 end Inlining_Not_Possible;
4600 procedure Make_Inline (Subp : Entity_Id) is
4601 Kind : constant Entity_Kind := Ekind (Subp);
4602 Inner_Subp : Entity_Id := Subp;
4605 -- Ignore if bad type, avoid cascaded error
4607 if Etype (Subp) = Any_Type then
4611 -- Ignore if all inlining is suppressed
4613 elsif Suppress_All_Inlining then
4617 -- If inlining is not possible, for now do not treat as an error
4619 elsif Inlining_Not_Possible (Subp) then
4623 -- Here we have a candidate for inlining, but we must exclude
4624 -- derived operations. Otherwise we would end up trying to inline
4625 -- a phantom declaration, and the result would be to drag in a
4626 -- body which has no direct inlining associated with it. That
4627 -- would not only be inefficient but would also result in the
4628 -- backend doing cross-unit inlining in cases where it was
4629 -- definitely inappropriate to do so.
4631 -- However, a simple Comes_From_Source test is insufficient, since
4632 -- we do want to allow inlining of generic instances which also do
4633 -- not come from source. We also need to recognize specs generated
4634 -- by the front-end for bodies that carry the pragma. Finally,
4635 -- predefined operators do not come from source but are not
4636 -- inlineable either.
4638 elsif Is_Generic_Instance (Subp)
4639 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4643 elsif not Comes_From_Source (Subp)
4644 and then Scope (Subp) /= Standard_Standard
4650 -- The referenced entity must either be the enclosing entity, or
4651 -- an entity declared within the current open scope.
4653 if Present (Scope (Subp))
4654 and then Scope (Subp) /= Current_Scope
4655 and then Subp /= Current_Scope
4658 ("argument of% must be entity in current scope", Assoc);
4662 -- Processing for procedure, operator or function. If subprogram
4663 -- is aliased (as for an instance) indicate that the renamed
4664 -- entity (if declared in the same unit) is inlined.
4666 if Is_Subprogram (Subp) then
4667 Inner_Subp := Ultimate_Alias (Inner_Subp);
4669 if In_Same_Source_Unit (Subp, Inner_Subp) then
4670 Set_Inline_Flags (Inner_Subp);
4672 Decl := Parent (Parent (Inner_Subp));
4674 if Nkind (Decl) = N_Subprogram_Declaration
4675 and then Present (Corresponding_Body (Decl))
4677 Set_Inline_Flags (Corresponding_Body (Decl));
4679 elsif Is_Generic_Instance (Subp) then
4681 -- Indicate that the body needs to be created for
4682 -- inlining subsequent calls. The instantiation node
4683 -- follows the declaration of the wrapper package
4686 if Scope (Subp) /= Standard_Standard
4688 Need_Subprogram_Instance_Body
4689 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4695 -- Inline is a program unit pragma (RM 10.1.5) and cannot
4696 -- appear in a formal part to apply to a formal subprogram.
4697 -- Do not apply check within an instance or a formal package
4698 -- the test will have been applied to the original generic.
4700 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4701 and then List_Containing (Decl) = List_Containing (N)
4702 and then not In_Instance
4705 ("Inline cannot apply to a formal subprogram", N);
4711 -- For a generic subprogram set flag as well, for use at the point
4712 -- of instantiation, to determine whether the body should be
4715 elsif Is_Generic_Subprogram (Subp) then
4716 Set_Inline_Flags (Subp);
4719 -- Literals are by definition inlined
4721 elsif Kind = E_Enumeration_Literal then
4724 -- Anything else is an error
4728 ("expect subprogram name for pragma%", Assoc);
4732 ----------------------
4733 -- Set_Inline_Flags --
4734 ----------------------
4736 procedure Set_Inline_Flags (Subp : Entity_Id) is
4739 Set_Is_Inlined (Subp);
4742 if not Has_Pragma_Inline (Subp) then
4743 Set_Has_Pragma_Inline (Subp);
4747 if Prag_Id = Pragma_Inline_Always then
4748 Set_Has_Pragma_Inline_Always (Subp);
4750 end Set_Inline_Flags;
4752 -- Start of processing for Process_Inline
4755 Check_No_Identifiers;
4756 Check_At_Least_N_Arguments (1);
4759 Inline_Processing_Required := True;
4763 while Present (Assoc) loop
4764 Subp_Id := Get_Pragma_Arg (Assoc);
4768 if Is_Entity_Name (Subp_Id) then
4769 Subp := Entity (Subp_Id);
4771 if Subp = Any_Id then
4773 -- If previous error, avoid cascaded errors
4781 -- For the pragma case, climb homonym chain. This is
4782 -- what implements allowing the pragma in the renaming
4783 -- case, with the result applying to the ancestors.
4785 if not From_Aspect_Specification (N) then
4786 while Present (Homonym (Subp))
4787 and then Scope (Homonym (Subp)) = Current_Scope
4789 Make_Inline (Homonym (Subp));
4790 Subp := Homonym (Subp);
4798 ("inappropriate argument for pragma%", Assoc);
4801 and then Warn_On_Redundant_Constructs
4802 and then not Suppress_All_Inlining
4804 if Inlining_Not_Possible (Subp) then
4806 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4809 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4817 ----------------------------
4818 -- Process_Interface_Name --
4819 ----------------------------
4821 procedure Process_Interface_Name
4822 (Subprogram_Def : Entity_Id;
4828 String_Val : String_Id;
4830 procedure Check_Form_Of_Interface_Name
4832 Ext_Name_Case : Boolean);
4833 -- SN is a string literal node for an interface name. This routine
4834 -- performs some minimal checks that the name is reasonable. In
4835 -- particular that no spaces or other obviously incorrect characters
4836 -- appear. This is only a warning, since any characters are allowed.
4837 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4839 ----------------------------------
4840 -- Check_Form_Of_Interface_Name --
4841 ----------------------------------
4843 procedure Check_Form_Of_Interface_Name
4845 Ext_Name_Case : Boolean)
4847 S : constant String_Id := Strval (Expr_Value_S (SN));
4848 SL : constant Nat := String_Length (S);
4853 Error_Msg_N ("interface name cannot be null string", SN);
4856 for J in 1 .. SL loop
4857 C := Get_String_Char (S, J);
4859 -- Look for dubious character and issue unconditional warning.
4860 -- Definitely dubious if not in character range.
4862 if not In_Character_Range (C)
4864 -- For all cases except CLI target,
4865 -- commas, spaces and slashes are dubious (in CLI, we use
4866 -- commas and backslashes in external names to specify
4867 -- assembly version and public key, while slashes and spaces
4868 -- can be used in names to mark nested classes and
4871 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4872 and then (Get_Character (C) = ','
4874 Get_Character (C) = '\'))
4875 or else (VM_Target /= CLI_Target
4876 and then (Get_Character (C) = ' '
4878 Get_Character (C) = '/'))
4881 ("?interface name contains illegal character",
4882 Sloc (SN) + Source_Ptr (J));
4885 end Check_Form_Of_Interface_Name;
4887 -- Start of processing for Process_Interface_Name
4890 if No (Link_Arg) then
4891 if No (Ext_Arg) then
4892 if VM_Target = CLI_Target
4893 and then Ekind (Subprogram_Def) = E_Package
4894 and then Nkind (Parent (Subprogram_Def)) =
4895 N_Package_Specification
4896 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4901 (Generic_Parent (Parent (Subprogram_Def))));
4906 elsif Chars (Ext_Arg) = Name_Link_Name then
4908 Link_Nam := Expression (Ext_Arg);
4911 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4912 Ext_Nam := Expression (Ext_Arg);
4917 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4918 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4919 Ext_Nam := Expression (Ext_Arg);
4920 Link_Nam := Expression (Link_Arg);
4923 -- Check expressions for external name and link name are static
4925 if Present (Ext_Nam) then
4926 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4927 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4929 -- Verify that external name is not the name of a local entity,
4930 -- which would hide the imported one and could lead to run-time
4931 -- surprises. The problem can only arise for entities declared in
4932 -- a package body (otherwise the external name is fully qualified
4933 -- and will not conflict).
4941 if Prag_Id = Pragma_Import then
4942 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4944 E := Entity_Id (Get_Name_Table_Info (Nam));
4946 if Nam /= Chars (Subprogram_Def)
4947 and then Present (E)
4948 and then not Is_Overloadable (E)
4949 and then Is_Immediately_Visible (E)
4950 and then not Is_Imported (E)
4951 and then Ekind (Scope (E)) = E_Package
4954 while Present (Par) loop
4955 if Nkind (Par) = N_Package_Body then
4956 Error_Msg_Sloc := Sloc (E);
4958 ("imported entity is hidden by & declared#",
4963 Par := Parent (Par);
4970 if Present (Link_Nam) then
4971 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4972 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4975 -- If there is no link name, just set the external name
4977 if No (Link_Nam) then
4978 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4980 -- For the Link_Name case, the given literal is preceded by an
4981 -- asterisk, which indicates to GCC that the given name should be
4982 -- taken literally, and in particular that no prepending of
4983 -- underlines should occur, even in systems where this is the
4989 if VM_Target = No_VM then
4990 Store_String_Char (Get_Char_Code ('*'));
4993 String_Val := Strval (Expr_Value_S (Link_Nam));
4994 Store_String_Chars (String_Val);
4996 Make_String_Literal (Sloc (Link_Nam),
4997 Strval => End_String);
5000 -- Set the interface name. If the entity is a generic instance, use
5001 -- its alias, which is the callable entity.
5003 if Is_Generic_Instance (Subprogram_Def) then
5004 Set_Encoded_Interface_Name
5005 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5007 Set_Encoded_Interface_Name
5008 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5011 -- We allow duplicated export names in CIL/Java, as they are always
5012 -- enclosed in a namespace that differentiates them, and overloaded
5013 -- entities are supported by the VM.
5015 if Convention (Subprogram_Def) /= Convention_CIL
5017 Convention (Subprogram_Def) /= Convention_Java
5019 Check_Duplicated_Export_Name (Link_Nam);
5021 end Process_Interface_Name;
5023 -----------------------------------------
5024 -- Process_Interrupt_Or_Attach_Handler --
5025 -----------------------------------------
5027 procedure Process_Interrupt_Or_Attach_Handler is
5028 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5029 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5030 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5033 Set_Is_Interrupt_Handler (Handler_Proc);
5035 -- If the pragma is not associated with a handler procedure within a
5036 -- protected type, then it must be for a nonprotected procedure for
5037 -- the AAMP target, in which case we don't associate a representation
5038 -- item with the procedure's scope.
5040 if Ekind (Proc_Scope) = E_Protected_Type then
5041 if Prag_Id = Pragma_Interrupt_Handler
5043 Prag_Id = Pragma_Attach_Handler
5045 Record_Rep_Item (Proc_Scope, N);
5048 end Process_Interrupt_Or_Attach_Handler;
5050 --------------------------------------------------
5051 -- Process_Restrictions_Or_Restriction_Warnings --
5052 --------------------------------------------------
5054 -- Note: some of the simple identifier cases were handled in par-prag,
5055 -- but it is harmless (and more straightforward) to simply handle all
5056 -- cases here, even if it means we repeat a bit of work in some cases.
5058 procedure Process_Restrictions_Or_Restriction_Warnings
5062 R_Id : Restriction_Id;
5067 procedure Check_Unit_Name (N : Node_Id);
5068 -- Checks unit name parameter for No_Dependence. Returns if it has
5069 -- an appropriate form, otherwise raises pragma argument error.
5071 ---------------------
5072 -- Check_Unit_Name --
5073 ---------------------
5075 procedure Check_Unit_Name (N : Node_Id) is
5077 if Nkind (N) = N_Selected_Component then
5078 Check_Unit_Name (Prefix (N));
5079 Check_Unit_Name (Selector_Name (N));
5081 elsif Nkind (N) = N_Identifier then
5086 ("wrong form for unit name for No_Dependence", N);
5088 end Check_Unit_Name;
5090 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5093 -- Ignore all Restrictions pragma in CodePeer mode
5095 if CodePeer_Mode then
5099 Check_Ada_83_Warning;
5100 Check_At_Least_N_Arguments (1);
5101 Check_Valid_Configuration_Pragma;
5104 while Present (Arg) loop
5106 Expr := Get_Pragma_Arg (Arg);
5108 -- Case of no restriction identifier present
5110 if Id = No_Name then
5111 if Nkind (Expr) /= N_Identifier then
5113 ("invalid form for restriction", Arg);
5118 (Process_Restriction_Synonyms (Expr));
5120 if R_Id not in All_Boolean_Restrictions then
5121 Error_Msg_Name_1 := Pname;
5123 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5125 -- Check for possible misspelling
5127 for J in Restriction_Id loop
5129 Rnm : constant String := Restriction_Id'Image (J);
5132 Name_Buffer (1 .. Rnm'Length) := Rnm;
5133 Name_Len := Rnm'Length;
5134 Set_Casing (All_Lower_Case);
5136 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5138 (Identifier_Casing (Current_Source_File));
5139 Error_Msg_String (1 .. Rnm'Length) :=
5140 Name_Buffer (1 .. Name_Len);
5141 Error_Msg_Strlen := Rnm'Length;
5142 Error_Msg_N -- CODEFIX
5143 ("\possible misspelling of ""~""",
5144 Get_Pragma_Arg (Arg));
5153 if Implementation_Restriction (R_Id) then
5154 Check_Restriction (No_Implementation_Restrictions, Arg);
5157 -- If this is a warning, then set the warning unless we already
5158 -- have a real restriction active (we never want a warning to
5159 -- override a real restriction).
5162 if not Restriction_Active (R_Id) then
5163 Set_Restriction (R_Id, N);
5164 Restriction_Warnings (R_Id) := True;
5167 -- If real restriction case, then set it and make sure that the
5168 -- restriction warning flag is off, since a real restriction
5169 -- always overrides a warning.
5172 Set_Restriction (R_Id, N);
5173 Restriction_Warnings (R_Id) := False;
5176 -- Check for obsolescent restrictions in Ada 2005 mode
5179 and then Ada_Version >= Ada_2005
5180 and then (R_Id = No_Asynchronous_Control
5182 R_Id = No_Unchecked_Deallocation
5184 R_Id = No_Unchecked_Conversion)
5186 Check_Restriction (No_Obsolescent_Features, N);
5189 -- A very special case that must be processed here: pragma
5190 -- Restrictions (No_Exceptions) turns off all run-time
5191 -- checking. This is a bit dubious in terms of the formal
5192 -- language definition, but it is what is intended by RM
5193 -- H.4(12). Restriction_Warnings never affects generated code
5194 -- so this is done only in the real restriction case.
5196 if R_Id = No_Exceptions and then not Warn then
5197 Scope_Suppress := (others => True);
5200 -- Case of No_Dependence => unit-name. Note that the parser
5201 -- already made the necessary entry in the No_Dependence table.
5203 elsif Id = Name_No_Dependence then
5204 Check_Unit_Name (Expr);
5206 -- All other cases of restriction identifier present
5209 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5210 Analyze_And_Resolve (Expr, Any_Integer);
5212 if R_Id not in All_Parameter_Restrictions then
5214 ("invalid restriction parameter identifier", Arg);
5216 elsif not Is_OK_Static_Expression (Expr) then
5217 Flag_Non_Static_Expr
5218 ("value must be static expression!", Expr);
5221 elsif not Is_Integer_Type (Etype (Expr))
5222 or else Expr_Value (Expr) < 0
5225 ("value must be non-negative integer", Arg);
5228 -- Restriction pragma is active
5230 Val := Expr_Value (Expr);
5232 if not UI_Is_In_Int_Range (Val) then
5234 ("pragma ignored, value too large?", Arg);
5237 -- Warning case. If the real restriction is active, then we
5238 -- ignore the request, since warning never overrides a real
5239 -- restriction. Otherwise we set the proper warning. Note that
5240 -- this circuit sets the warning again if it is already set,
5241 -- which is what we want, since the constant may have changed.
5244 if not Restriction_Active (R_Id) then
5246 (R_Id, N, Integer (UI_To_Int (Val)));
5247 Restriction_Warnings (R_Id) := True;
5250 -- Real restriction case, set restriction and make sure warning
5251 -- flag is off since real restriction always overrides warning.
5254 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5255 Restriction_Warnings (R_Id) := False;
5261 end Process_Restrictions_Or_Restriction_Warnings;
5263 ---------------------------------
5264 -- Process_Suppress_Unsuppress --
5265 ---------------------------------
5267 -- Note: this procedure makes entries in the check suppress data
5268 -- structures managed by Sem. See spec of package Sem for full
5269 -- details on how we handle recording of check suppression.
5271 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5276 In_Package_Spec : constant Boolean :=
5277 Is_Package_Or_Generic_Package (Current_Scope)
5278 and then not In_Package_Body (Current_Scope);
5280 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5281 -- Used to suppress a single check on the given entity
5283 --------------------------------
5284 -- Suppress_Unsuppress_Echeck --
5285 --------------------------------
5287 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5289 Set_Checks_May_Be_Suppressed (E);
5291 if In_Package_Spec then
5292 Push_Global_Suppress_Stack_Entry
5295 Suppress => Suppress_Case);
5298 Push_Local_Suppress_Stack_Entry
5301 Suppress => Suppress_Case);
5304 -- If this is a first subtype, and the base type is distinct,
5305 -- then also set the suppress flags on the base type.
5307 if Is_First_Subtype (E)
5308 and then Etype (E) /= E
5310 Suppress_Unsuppress_Echeck (Etype (E), C);
5312 end Suppress_Unsuppress_Echeck;
5314 -- Start of processing for Process_Suppress_Unsuppress
5317 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5318 -- user code: we want to generate checks for analysis purposes, as
5319 -- set respectively by -gnatC and -gnatd.F
5321 if (CodePeer_Mode or Alfa_Mode)
5322 and then Comes_From_Source (N)
5327 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5328 -- declarative part or a package spec (RM 11.5(5)).
5330 if not Is_Configuration_Pragma then
5331 Check_Is_In_Decl_Part_Or_Package_Spec;
5334 Check_At_Least_N_Arguments (1);
5335 Check_At_Most_N_Arguments (2);
5336 Check_No_Identifier (Arg1);
5337 Check_Arg_Is_Identifier (Arg1);
5339 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5341 if C = No_Check_Id then
5343 ("argument of pragma% is not valid check name", Arg1);
5346 if not Suppress_Case
5347 and then (C = All_Checks or else C = Overflow_Check)
5349 Opt.Overflow_Checks_Unsuppressed := True;
5352 if Arg_Count = 1 then
5354 -- Make an entry in the local scope suppress table. This is the
5355 -- table that directly shows the current value of the scope
5356 -- suppress check for any check id value.
5358 if C = All_Checks then
5360 -- For All_Checks, we set all specific predefined checks with
5361 -- the exception of Elaboration_Check, which is handled
5362 -- specially because of not wanting All_Checks to have the
5363 -- effect of deactivating static elaboration order processing.
5365 for J in Scope_Suppress'Range loop
5366 if J /= Elaboration_Check then
5367 Scope_Suppress (J) := Suppress_Case;
5371 -- If not All_Checks, and predefined check, then set appropriate
5372 -- scope entry. Note that we will set Elaboration_Check if this
5373 -- is explicitly specified.
5375 elsif C in Predefined_Check_Id then
5376 Scope_Suppress (C) := Suppress_Case;
5379 -- Also make an entry in the Local_Entity_Suppress table
5381 Push_Local_Suppress_Stack_Entry
5384 Suppress => Suppress_Case);
5386 -- Case of two arguments present, where the check is suppressed for
5387 -- a specified entity (given as the second argument of the pragma)
5390 -- This is obsolescent in Ada 2005 mode
5392 if Ada_Version >= Ada_2005 then
5393 Check_Restriction (No_Obsolescent_Features, Arg2);
5396 Check_Optional_Identifier (Arg2, Name_On);
5397 E_Id := Get_Pragma_Arg (Arg2);
5400 if not Is_Entity_Name (E_Id) then
5402 ("second argument of pragma% must be entity name", Arg2);
5411 -- Enforce RM 11.5(7) which requires that for a pragma that
5412 -- appears within a package spec, the named entity must be
5413 -- within the package spec. We allow the package name itself
5414 -- to be mentioned since that makes sense, although it is not
5415 -- strictly allowed by 11.5(7).
5418 and then E /= Current_Scope
5419 and then Scope (E) /= Current_Scope
5422 ("entity in pragma% is not in package spec (RM 11.5(7))",
5426 -- Loop through homonyms. As noted below, in the case of a package
5427 -- spec, only homonyms within the package spec are considered.
5430 Suppress_Unsuppress_Echeck (E, C);
5432 if Is_Generic_Instance (E)
5433 and then Is_Subprogram (E)
5434 and then Present (Alias (E))
5436 Suppress_Unsuppress_Echeck (Alias (E), C);
5439 -- Move to next homonym if not aspect spec case
5441 exit when From_Aspect_Specification (N);
5445 -- If we are within a package specification, the pragma only
5446 -- applies to homonyms in the same scope.
5448 exit when In_Package_Spec
5449 and then Scope (E) /= Current_Scope;
5452 end Process_Suppress_Unsuppress;
5458 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5460 if Is_Imported (E) then
5462 ("cannot export entity& that was previously imported", Arg);
5464 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5466 ("cannot export entity& that has an address clause", Arg);
5469 Set_Is_Exported (E);
5471 -- Generate a reference for entity explicitly, because the
5472 -- identifier may be overloaded and name resolution will not
5475 Generate_Reference (E, Arg);
5477 -- Deal with exporting non-library level entity
5479 if not Is_Library_Level_Entity (E) then
5481 -- Not allowed at all for subprograms
5483 if Is_Subprogram (E) then
5484 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5486 -- Otherwise set public and statically allocated
5490 Set_Is_Statically_Allocated (E);
5492 -- Warn if the corresponding W flag is set and the pragma comes
5493 -- from source. The latter may not be true e.g. on VMS where we
5494 -- expand export pragmas for exception codes associated with
5495 -- imported or exported exceptions. We do not want to generate
5496 -- a warning for something that the user did not write.
5498 if Warn_On_Export_Import
5499 and then Comes_From_Source (Arg)
5502 ("?& has been made static as a result of Export", Arg, E);
5504 ("\this usage is non-standard and non-portable", Arg);
5509 if Warn_On_Export_Import and then Is_Type (E) then
5510 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5513 if Warn_On_Export_Import and Inside_A_Generic then
5515 ("all instances of& will have the same external name?", Arg, E);
5519 ----------------------------------------------
5520 -- Set_Extended_Import_Export_External_Name --
5521 ----------------------------------------------
5523 procedure Set_Extended_Import_Export_External_Name
5524 (Internal_Ent : Entity_Id;
5525 Arg_External : Node_Id)
5527 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5531 if No (Arg_External) then
5535 Check_Arg_Is_External_Name (Arg_External);
5537 if Nkind (Arg_External) = N_String_Literal then
5538 if String_Length (Strval (Arg_External)) = 0 then
5541 New_Name := Adjust_External_Name_Case (Arg_External);
5544 elsif Nkind (Arg_External) = N_Identifier then
5545 New_Name := Get_Default_External_Name (Arg_External);
5547 -- Check_Arg_Is_External_Name should let through only identifiers and
5548 -- string literals or static string expressions (which are folded to
5549 -- string literals).
5552 raise Program_Error;
5555 -- If we already have an external name set (by a prior normal Import
5556 -- or Export pragma), then the external names must match
5558 if Present (Interface_Name (Internal_Ent)) then
5559 Check_Matching_Internal_Names : declare
5560 S1 : constant String_Id := Strval (Old_Name);
5561 S2 : constant String_Id := Strval (New_Name);
5564 -- Called if names do not match
5570 procedure Mismatch is
5572 Error_Msg_Sloc := Sloc (Old_Name);
5574 ("external name does not match that given #",
5578 -- Start of processing for Check_Matching_Internal_Names
5581 if String_Length (S1) /= String_Length (S2) then
5585 for J in 1 .. String_Length (S1) loop
5586 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5591 end Check_Matching_Internal_Names;
5593 -- Otherwise set the given name
5596 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5597 Check_Duplicated_Export_Name (New_Name);
5599 end Set_Extended_Import_Export_External_Name;
5605 procedure Set_Imported (E : Entity_Id) is
5607 -- Error message if already imported or exported
5609 if Is_Exported (E) or else Is_Imported (E) then
5611 -- Error if being set Exported twice
5613 if Is_Exported (E) then
5614 Error_Msg_NE ("entity& was previously exported", N, E);
5616 -- OK if Import/Interface case
5618 elsif Import_Interface_Present (N) then
5621 -- Error if being set Imported twice
5624 Error_Msg_NE ("entity& was previously imported", N, E);
5627 Error_Msg_Name_1 := Pname;
5629 ("\(pragma% applies to all previous entities)", N);
5631 Error_Msg_Sloc := Sloc (E);
5632 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5634 -- Here if not previously imported or exported, OK to import
5637 Set_Is_Imported (E);
5639 -- If the entity is an object that is not at the library level,
5640 -- then it is statically allocated. We do not worry about objects
5641 -- with address clauses in this context since they are not really
5642 -- imported in the linker sense.
5645 and then not Is_Library_Level_Entity (E)
5646 and then No (Address_Clause (E))
5648 Set_Is_Statically_Allocated (E);
5655 -------------------------
5656 -- Set_Mechanism_Value --
5657 -------------------------
5659 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5660 -- analyzed, since it is semantic nonsense), so we get it in the exact
5661 -- form created by the parser.
5663 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5666 Mech_Name_Id : Name_Id;
5668 procedure Bad_Class;
5669 -- Signal bad descriptor class name
5671 procedure Bad_Mechanism;
5672 -- Signal bad mechanism name
5678 procedure Bad_Class is
5680 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5683 -------------------------
5684 -- Bad_Mechanism_Value --
5685 -------------------------
5687 procedure Bad_Mechanism is
5689 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5692 -- Start of processing for Set_Mechanism_Value
5695 if Mechanism (Ent) /= Default_Mechanism then
5697 ("mechanism for & has already been set", Mech_Name, Ent);
5700 -- MECHANISM_NAME ::= value | reference | descriptor |
5703 if Nkind (Mech_Name) = N_Identifier then
5704 if Chars (Mech_Name) = Name_Value then
5705 Set_Mechanism (Ent, By_Copy);
5708 elsif Chars (Mech_Name) = Name_Reference then
5709 Set_Mechanism (Ent, By_Reference);
5712 elsif Chars (Mech_Name) = Name_Descriptor then
5713 Check_VMS (Mech_Name);
5715 -- Descriptor => Short_Descriptor if pragma was given
5717 if Short_Descriptors then
5718 Set_Mechanism (Ent, By_Short_Descriptor);
5720 Set_Mechanism (Ent, By_Descriptor);
5725 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5726 Check_VMS (Mech_Name);
5727 Set_Mechanism (Ent, By_Short_Descriptor);
5730 elsif Chars (Mech_Name) = Name_Copy then
5732 ("bad mechanism name, Value assumed", Mech_Name);
5738 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5739 -- short_descriptor (CLASS_NAME)
5740 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5742 -- Note: this form is parsed as an indexed component
5744 elsif Nkind (Mech_Name) = N_Indexed_Component then
5745 Class := First (Expressions (Mech_Name));
5747 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5748 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5749 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5750 or else Present (Next (Class))
5754 Mech_Name_Id := Chars (Prefix (Mech_Name));
5756 -- Change Descriptor => Short_Descriptor if pragma was given
5758 if Mech_Name_Id = Name_Descriptor
5759 and then Short_Descriptors
5761 Mech_Name_Id := Name_Short_Descriptor;
5765 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5766 -- short_descriptor (Class => CLASS_NAME)
5767 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5769 -- Note: this form is parsed as a function call
5771 elsif Nkind (Mech_Name) = N_Function_Call then
5772 Param := First (Parameter_Associations (Mech_Name));
5774 if Nkind (Name (Mech_Name)) /= N_Identifier
5775 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5776 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5777 or else Present (Next (Param))
5778 or else No (Selector_Name (Param))
5779 or else Chars (Selector_Name (Param)) /= Name_Class
5783 Class := Explicit_Actual_Parameter (Param);
5784 Mech_Name_Id := Chars (Name (Mech_Name));
5791 -- Fall through here with Class set to descriptor class name
5793 Check_VMS (Mech_Name);
5795 if Nkind (Class) /= N_Identifier then
5798 elsif Mech_Name_Id = Name_Descriptor
5799 and then Chars (Class) = Name_UBS
5801 Set_Mechanism (Ent, By_Descriptor_UBS);
5803 elsif Mech_Name_Id = Name_Descriptor
5804 and then Chars (Class) = Name_UBSB
5806 Set_Mechanism (Ent, By_Descriptor_UBSB);
5808 elsif Mech_Name_Id = Name_Descriptor
5809 and then Chars (Class) = Name_UBA
5811 Set_Mechanism (Ent, By_Descriptor_UBA);
5813 elsif Mech_Name_Id = Name_Descriptor
5814 and then Chars (Class) = Name_S
5816 Set_Mechanism (Ent, By_Descriptor_S);
5818 elsif Mech_Name_Id = Name_Descriptor
5819 and then Chars (Class) = Name_SB
5821 Set_Mechanism (Ent, By_Descriptor_SB);
5823 elsif Mech_Name_Id = Name_Descriptor
5824 and then Chars (Class) = Name_A
5826 Set_Mechanism (Ent, By_Descriptor_A);
5828 elsif Mech_Name_Id = Name_Descriptor
5829 and then Chars (Class) = Name_NCA
5831 Set_Mechanism (Ent, By_Descriptor_NCA);
5833 elsif Mech_Name_Id = Name_Short_Descriptor
5834 and then Chars (Class) = Name_UBS
5836 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5838 elsif Mech_Name_Id = Name_Short_Descriptor
5839 and then Chars (Class) = Name_UBSB
5841 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5843 elsif Mech_Name_Id = Name_Short_Descriptor
5844 and then Chars (Class) = Name_UBA
5846 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5848 elsif Mech_Name_Id = Name_Short_Descriptor
5849 and then Chars (Class) = Name_S
5851 Set_Mechanism (Ent, By_Short_Descriptor_S);
5853 elsif Mech_Name_Id = Name_Short_Descriptor
5854 and then Chars (Class) = Name_SB
5856 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5858 elsif Mech_Name_Id = Name_Short_Descriptor
5859 and then Chars (Class) = Name_A
5861 Set_Mechanism (Ent, By_Short_Descriptor_A);
5863 elsif Mech_Name_Id = Name_Short_Descriptor
5864 and then Chars (Class) = Name_NCA
5866 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5871 end Set_Mechanism_Value;
5873 ---------------------------
5874 -- Set_Ravenscar_Profile --
5875 ---------------------------
5877 -- The tasks to be done here are
5879 -- Set required policies
5881 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5882 -- pragma Locking_Policy (Ceiling_Locking)
5884 -- Set Detect_Blocking mode
5886 -- Set required restrictions (see System.Rident for detailed list)
5888 -- Set the No_Dependence rules
5889 -- No_Dependence => Ada.Asynchronous_Task_Control
5890 -- No_Dependence => Ada.Calendar
5891 -- No_Dependence => Ada.Execution_Time.Group_Budget
5892 -- No_Dependence => Ada.Execution_Time.Timers
5893 -- No_Dependence => Ada.Task_Attributes
5894 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5896 procedure Set_Ravenscar_Profile (N : Node_Id) is
5897 Prefix_Entity : Entity_Id;
5898 Selector_Entity : Entity_Id;
5899 Prefix_Node : Node_Id;
5903 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5905 if Task_Dispatching_Policy /= ' '
5906 and then Task_Dispatching_Policy /= 'F'
5908 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5909 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5911 -- Set the FIFO_Within_Priorities policy, but always preserve
5912 -- System_Location since we like the error message with the run time
5916 Task_Dispatching_Policy := 'F';
5918 if Task_Dispatching_Policy_Sloc /= System_Location then
5919 Task_Dispatching_Policy_Sloc := Loc;
5923 -- pragma Locking_Policy (Ceiling_Locking)
5925 if Locking_Policy /= ' '
5926 and then Locking_Policy /= 'C'
5928 Error_Msg_Sloc := Locking_Policy_Sloc;
5929 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5931 -- Set the Ceiling_Locking policy, but preserve System_Location since
5932 -- we like the error message with the run time name.
5935 Locking_Policy := 'C';
5937 if Locking_Policy_Sloc /= System_Location then
5938 Locking_Policy_Sloc := Loc;
5942 -- pragma Detect_Blocking
5944 Detect_Blocking := True;
5946 -- Set the corresponding restrictions
5948 Set_Profile_Restrictions
5949 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5951 -- Set the No_Dependence restrictions
5953 -- The following No_Dependence restrictions:
5954 -- No_Dependence => Ada.Asynchronous_Task_Control
5955 -- No_Dependence => Ada.Calendar
5956 -- No_Dependence => Ada.Task_Attributes
5957 -- are already set by previous call to Set_Profile_Restrictions.
5959 -- Set the following restrictions which were added to Ada 2005:
5960 -- No_Dependence => Ada.Execution_Time.Group_Budget
5961 -- No_Dependence => Ada.Execution_Time.Timers
5963 if Ada_Version >= Ada_2005 then
5964 Name_Buffer (1 .. 3) := "ada";
5967 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5969 Name_Buffer (1 .. 14) := "execution_time";
5972 Selector_Entity := Make_Identifier (Loc, Name_Find);
5975 Make_Selected_Component
5977 Prefix => Prefix_Entity,
5978 Selector_Name => Selector_Entity);
5980 Name_Buffer (1 .. 13) := "group_budgets";
5983 Selector_Entity := Make_Identifier (Loc, Name_Find);
5986 Make_Selected_Component
5988 Prefix => Prefix_Node,
5989 Selector_Name => Selector_Entity);
5991 Set_Restriction_No_Dependence
5993 Warn => Treat_Restrictions_As_Warnings,
5994 Profile => Ravenscar);
5996 Name_Buffer (1 .. 6) := "timers";
5999 Selector_Entity := Make_Identifier (Loc, Name_Find);
6002 Make_Selected_Component
6004 Prefix => Prefix_Node,
6005 Selector_Name => Selector_Entity);
6007 Set_Restriction_No_Dependence
6009 Warn => Treat_Restrictions_As_Warnings,
6010 Profile => Ravenscar);
6013 -- Set the following restrictions which was added to Ada 2012 (see
6015 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6017 if Ada_Version >= Ada_2012 then
6018 Name_Buffer (1 .. 6) := "system";
6021 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6023 Name_Buffer (1 .. 15) := "multiprocessors";
6026 Selector_Entity := Make_Identifier (Loc, Name_Find);
6029 Make_Selected_Component
6031 Prefix => Prefix_Entity,
6032 Selector_Name => Selector_Entity);
6034 Name_Buffer (1 .. 19) := "dispatching_domains";
6037 Selector_Entity := Make_Identifier (Loc, Name_Find);
6040 Make_Selected_Component
6042 Prefix => Prefix_Node,
6043 Selector_Name => Selector_Entity);
6045 Set_Restriction_No_Dependence
6047 Warn => Treat_Restrictions_As_Warnings,
6048 Profile => Ravenscar);
6050 end Set_Ravenscar_Profile;
6052 -- Start of processing for Analyze_Pragma
6055 -- The following code is a defense against recursion. Not clear that
6056 -- this can happen legitimately, but perhaps some error situations
6057 -- can cause it, and we did see this recursion during testing.
6059 if Analyzed (N) then
6062 Set_Analyzed (N, True);
6065 -- Deal with unrecognized pragma
6067 if not Is_Pragma_Name (Pname) then
6068 if Warn_On_Unrecognized_Pragma then
6069 Error_Msg_Name_1 := Pname;
6070 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6072 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6073 if Is_Bad_Spelling_Of (Pname, PN) then
6074 Error_Msg_Name_1 := PN;
6075 Error_Msg_N -- CODEFIX
6076 ("\?possible misspelling of %!", Pragma_Identifier (N));
6085 -- Here to start processing for recognized pragma
6087 Prag_Id := Get_Pragma_Id (Pname);
6097 if Present (Pragma_Argument_Associations (N)) then
6098 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6099 Arg1 := First (Pragma_Argument_Associations (N));
6101 if Present (Arg1) then
6102 Arg2 := Next (Arg1);
6104 if Present (Arg2) then
6105 Arg3 := Next (Arg2);
6107 if Present (Arg3) then
6108 Arg4 := Next (Arg3);
6114 -- An enumeration type defines the pragmas that are supported by the
6115 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6116 -- into the corresponding enumeration value for the following case.
6124 -- pragma Abort_Defer;
6126 when Pragma_Abort_Defer =>
6128 Check_Arg_Count (0);
6130 -- The only required semantic processing is to check the
6131 -- placement. This pragma must appear at the start of the
6132 -- statement sequence of a handled sequence of statements.
6134 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6135 or else N /= First (Statements (Parent (N)))
6146 -- Note: this pragma also has some specific processing in Par.Prag
6147 -- because we want to set the Ada version mode during parsing.
6149 when Pragma_Ada_83 =>
6151 Check_Arg_Count (0);
6153 -- We really should check unconditionally for proper configuration
6154 -- pragma placement, since we really don't want mixed Ada modes
6155 -- within a single unit, and the GNAT reference manual has always
6156 -- said this was a configuration pragma, but we did not check and
6157 -- are hesitant to add the check now.
6159 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6160 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6161 -- or Ada 2012 mode.
6163 if Ada_Version >= Ada_2005 then
6164 Check_Valid_Configuration_Pragma;
6167 -- Now set Ada 83 mode
6169 Ada_Version := Ada_83;
6170 Ada_Version_Explicit := Ada_Version;
6178 -- Note: this pragma also has some specific processing in Par.Prag
6179 -- because we want to set the Ada 83 version mode during parsing.
6181 when Pragma_Ada_95 =>
6183 Check_Arg_Count (0);
6185 -- We really should check unconditionally for proper configuration
6186 -- pragma placement, since we really don't want mixed Ada modes
6187 -- within a single unit, and the GNAT reference manual has always
6188 -- said this was a configuration pragma, but we did not check and
6189 -- are hesitant to add the check now.
6191 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
6192 -- or Ada 95, so we must check if we are in Ada 2005 mode.
6194 if Ada_Version >= Ada_2005 then
6195 Check_Valid_Configuration_Pragma;
6198 -- Now set Ada 95 mode
6200 Ada_Version := Ada_95;
6201 Ada_Version_Explicit := Ada_Version;
6203 ---------------------
6204 -- Ada_05/Ada_2005 --
6205 ---------------------
6208 -- pragma Ada_05 (LOCAL_NAME);
6211 -- pragma Ada_2005 (LOCAL_NAME):
6213 -- Note: these pragmas also have some specific processing in Par.Prag
6214 -- because we want to set the Ada 2005 version mode during parsing.
6216 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6222 if Arg_Count = 1 then
6223 Check_Arg_Is_Local_Name (Arg1);
6224 E_Id := Get_Pragma_Arg (Arg1);
6226 if Etype (E_Id) = Any_Type then
6230 Set_Is_Ada_2005_Only (Entity (E_Id));
6233 Check_Arg_Count (0);
6235 -- For Ada_2005 we unconditionally enforce the documented
6236 -- configuration pragma placement, since we do not want to
6237 -- tolerate mixed modes in a unit involving Ada 2005. That
6238 -- would cause real difficulties for those cases where there
6239 -- are incompatibilities between Ada 95 and Ada 2005.
6241 Check_Valid_Configuration_Pragma;
6243 -- Now set appropriate Ada mode
6245 Ada_Version := Ada_2005;
6246 Ada_Version_Explicit := Ada_2005;
6250 ---------------------
6251 -- Ada_12/Ada_2012 --
6252 ---------------------
6255 -- pragma Ada_12 (LOCAL_NAME);
6258 -- pragma Ada_2012 (LOCAL_NAME):
6260 -- Note: these pragmas also have some specific processing in Par.Prag
6261 -- because we want to set the Ada 2012 version mode during parsing.
6263 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6269 if Arg_Count = 1 then
6270 Check_Arg_Is_Local_Name (Arg1);
6271 E_Id := Get_Pragma_Arg (Arg1);
6273 if Etype (E_Id) = Any_Type then
6277 Set_Is_Ada_2012_Only (Entity (E_Id));
6280 Check_Arg_Count (0);
6282 -- For Ada_2012 we unconditionally enforce the documented
6283 -- configuration pragma placement, since we do not want to
6284 -- tolerate mixed modes in a unit involving Ada 2012. That
6285 -- would cause real difficulties for those cases where there
6286 -- are incompatibilities between Ada 95 and Ada 2012. We could
6287 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6289 Check_Valid_Configuration_Pragma;
6291 -- Now set appropriate Ada mode
6293 Ada_Version := Ada_2012;
6294 Ada_Version_Explicit := Ada_2012;
6298 ----------------------
6299 -- All_Calls_Remote --
6300 ----------------------
6302 -- pragma All_Calls_Remote [(library_package_NAME)];
6304 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6305 Lib_Entity : Entity_Id;
6308 Check_Ada_83_Warning;
6309 Check_Valid_Library_Unit_Pragma;
6311 if Nkind (N) = N_Null_Statement then
6315 Lib_Entity := Find_Lib_Unit_Name;
6317 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6319 if Present (Lib_Entity)
6320 and then not Debug_Flag_U
6322 if not Is_Remote_Call_Interface (Lib_Entity) then
6323 Error_Pragma ("pragma% only apply to rci unit");
6325 -- Set flag for entity of the library unit
6328 Set_Has_All_Calls_Remote (Lib_Entity);
6332 end All_Calls_Remote;
6338 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6339 -- ARG ::= NAME | EXPRESSION
6341 -- The first two arguments are by convention intended to refer to an
6342 -- external tool and a tool-specific function. These arguments are
6345 when Pragma_Annotate => Annotate : declare
6351 Check_At_Least_N_Arguments (1);
6352 Check_Arg_Is_Identifier (Arg1);
6353 Check_No_Identifiers;
6356 -- Second parameter is optional, it is never analyzed
6361 -- Here if we have a second parameter
6364 -- Second parameter must be identifier
6366 Check_Arg_Is_Identifier (Arg2);
6368 -- Process remaining parameters if any
6371 while Present (Arg) loop
6372 Exp := Get_Pragma_Arg (Arg);
6375 if Is_Entity_Name (Exp) then
6378 -- For string literals, we assume Standard_String as the
6379 -- type, unless the string contains wide or wide_wide
6382 elsif Nkind (Exp) = N_String_Literal then
6383 if Has_Wide_Wide_Character (Exp) then
6384 Resolve (Exp, Standard_Wide_Wide_String);
6385 elsif Has_Wide_Character (Exp) then
6386 Resolve (Exp, Standard_Wide_String);
6388 Resolve (Exp, Standard_String);
6391 elsif Is_Overloaded (Exp) then
6393 ("ambiguous argument for pragma%", Exp);
6408 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6409 -- [, [Message =>] Static_String_EXPRESSION]);
6411 when Pragma_Assert => Assert : declare
6417 Check_At_Least_N_Arguments (1);
6418 Check_At_Most_N_Arguments (2);
6419 Check_Arg_Order ((Name_Check, Name_Message));
6420 Check_Optional_Identifier (Arg1, Name_Check);
6422 -- We treat pragma Assert as equivalent to:
6424 -- pragma Check (Assertion, condition [, msg]);
6426 -- So rewrite pragma in this manner, and analyze the result
6428 Expr := Get_Pragma_Arg (Arg1);
6430 Make_Pragma_Argument_Association (Loc,
6431 Expression => Make_Identifier (Loc, Name_Assertion)),
6433 Make_Pragma_Argument_Association (Sloc (Expr),
6434 Expression => Expr));
6436 if Arg_Count > 1 then
6437 Check_Optional_Identifier (Arg2, Name_Message);
6438 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6439 Append_To (Newa, Relocate_Node (Arg2));
6444 Chars => Name_Check,
6445 Pragma_Argument_Associations => Newa));
6449 ----------------------
6450 -- Assertion_Policy --
6451 ----------------------
6453 -- pragma Assertion_Policy (Check | Disable |Ignore)
6455 when Pragma_Assertion_Policy => Assertion_Policy : declare
6460 Check_Valid_Configuration_Pragma;
6461 Check_Arg_Count (1);
6462 Check_No_Identifiers;
6463 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6465 -- We treat pragma Assertion_Policy as equivalent to:
6467 -- pragma Check_Policy (Assertion, policy)
6469 -- So rewrite the pragma in that manner and link on to the chain
6470 -- of Check_Policy pragmas, marking the pragma as analyzed.
6472 Policy := Get_Pragma_Arg (Arg1);
6476 Chars => Name_Check_Policy,
6478 Pragma_Argument_Associations => New_List (
6479 Make_Pragma_Argument_Association (Loc,
6480 Expression => Make_Identifier (Loc, Name_Assertion)),
6482 Make_Pragma_Argument_Association (Loc,
6484 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6487 Set_Next_Pragma (N, Opt.Check_Policy_List);
6488 Opt.Check_Policy_List := N;
6489 end Assertion_Policy;
6491 ------------------------------
6492 -- Assume_No_Invalid_Values --
6493 ------------------------------
6495 -- pragma Assume_No_Invalid_Values (On | Off);
6497 when Pragma_Assume_No_Invalid_Values =>
6499 Check_Valid_Configuration_Pragma;
6500 Check_Arg_Count (1);
6501 Check_No_Identifiers;
6502 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6504 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6505 Assume_No_Invalid_Values := True;
6507 Assume_No_Invalid_Values := False;
6514 -- pragma AST_Entry (entry_IDENTIFIER);
6516 when Pragma_AST_Entry => AST_Entry : declare
6522 Check_Arg_Count (1);
6523 Check_No_Identifiers;
6524 Check_Arg_Is_Local_Name (Arg1);
6525 Ent := Entity (Get_Pragma_Arg (Arg1));
6527 -- Note: the implementation of the AST_Entry pragma could handle
6528 -- the entry family case fine, but for now we are consistent with
6529 -- the DEC rules, and do not allow the pragma, which of course
6530 -- has the effect of also forbidding the attribute.
6532 if Ekind (Ent) /= E_Entry then
6534 ("pragma% argument must be simple entry name", Arg1);
6536 elsif Is_AST_Entry (Ent) then
6538 ("duplicate % pragma for entry", Arg1);
6540 elsif Has_Homonym (Ent) then
6542 ("pragma% argument cannot specify overloaded entry", Arg1);
6546 FF : constant Entity_Id := First_Formal (Ent);
6549 if Present (FF) then
6550 if Present (Next_Formal (FF)) then
6552 ("entry for pragma% can have only one argument",
6555 elsif Parameter_Mode (FF) /= E_In_Parameter then
6557 ("entry parameter for pragma% must have mode IN",
6563 Set_Is_AST_Entry (Ent);
6571 -- pragma Asynchronous (LOCAL_NAME);
6573 when Pragma_Asynchronous => Asynchronous : declare
6581 procedure Process_Async_Pragma;
6582 -- Common processing for procedure and access-to-procedure case
6584 --------------------------
6585 -- Process_Async_Pragma --
6586 --------------------------
6588 procedure Process_Async_Pragma is
6591 Set_Is_Asynchronous (Nm);
6595 -- The formals should be of mode IN (RM E.4.1(6))
6598 while Present (S) loop
6599 Formal := Defining_Identifier (S);
6601 if Nkind (Formal) = N_Defining_Identifier
6602 and then Ekind (Formal) /= E_In_Parameter
6605 ("pragma% procedure can only have IN parameter",
6612 Set_Is_Asynchronous (Nm);
6613 end Process_Async_Pragma;
6615 -- Start of processing for pragma Asynchronous
6618 Check_Ada_83_Warning;
6619 Check_No_Identifiers;
6620 Check_Arg_Count (1);
6621 Check_Arg_Is_Local_Name (Arg1);
6623 if Debug_Flag_U then
6627 C_Ent := Cunit_Entity (Current_Sem_Unit);
6628 Analyze (Get_Pragma_Arg (Arg1));
6629 Nm := Entity (Get_Pragma_Arg (Arg1));
6631 if not Is_Remote_Call_Interface (C_Ent)
6632 and then not Is_Remote_Types (C_Ent)
6634 -- This pragma should only appear in an RCI or Remote Types
6635 -- unit (RM E.4.1(4)).
6638 ("pragma% not in Remote_Call_Interface or " &
6639 "Remote_Types unit");
6642 if Ekind (Nm) = E_Procedure
6643 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6645 if not Is_Remote_Call_Interface (Nm) then
6647 ("pragma% cannot be applied on non-remote procedure",
6651 L := Parameter_Specifications (Parent (Nm));
6652 Process_Async_Pragma;
6655 elsif Ekind (Nm) = E_Function then
6657 ("pragma% cannot be applied to function", Arg1);
6659 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6660 if Is_Record_Type (Nm) then
6662 -- A record type that is the Equivalent_Type for a remote
6663 -- access-to-subprogram type.
6665 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6668 -- A non-expanded RAS type (distribution is not enabled)
6670 N := Declaration_Node (Nm);
6673 if Nkind (N) = N_Full_Type_Declaration
6674 and then Nkind (Type_Definition (N)) =
6675 N_Access_Procedure_Definition
6677 L := Parameter_Specifications (Type_Definition (N));
6678 Process_Async_Pragma;
6680 if Is_Asynchronous (Nm)
6681 and then Expander_Active
6682 and then Get_PCS_Name /= Name_No_DSA
6684 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6689 ("pragma% cannot reference access-to-function type",
6693 -- Only other possibility is Access-to-class-wide type
6695 elsif Is_Access_Type (Nm)
6696 and then Is_Class_Wide_Type (Designated_Type (Nm))
6698 Check_First_Subtype (Arg1);
6699 Set_Is_Asynchronous (Nm);
6700 if Expander_Active then
6701 RACW_Type_Is_Asynchronous (Nm);
6705 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6713 -- pragma Atomic (LOCAL_NAME);
6715 when Pragma_Atomic =>
6716 Process_Atomic_Shared_Volatile;
6718 -----------------------
6719 -- Atomic_Components --
6720 -----------------------
6722 -- pragma Atomic_Components (array_LOCAL_NAME);
6724 -- This processing is shared by Volatile_Components
6726 when Pragma_Atomic_Components |
6727 Pragma_Volatile_Components =>
6729 Atomic_Components : declare
6736 Check_Ada_83_Warning;
6737 Check_No_Identifiers;
6738 Check_Arg_Count (1);
6739 Check_Arg_Is_Local_Name (Arg1);
6740 E_Id := Get_Pragma_Arg (Arg1);
6742 if Etype (E_Id) = Any_Type then
6748 Check_Duplicate_Pragma (E);
6750 if Rep_Item_Too_Early (E, N)
6752 Rep_Item_Too_Late (E, N)
6757 D := Declaration_Node (E);
6760 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6762 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6763 and then Nkind (D) = N_Object_Declaration
6764 and then Nkind (Object_Definition (D)) =
6765 N_Constrained_Array_Definition)
6767 -- The flag is set on the object, or on the base type
6769 if Nkind (D) /= N_Object_Declaration then
6773 Set_Has_Volatile_Components (E);
6775 if Prag_Id = Pragma_Atomic_Components then
6776 Set_Has_Atomic_Components (E);
6780 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6782 end Atomic_Components;
6784 --------------------
6785 -- Attach_Handler --
6786 --------------------
6788 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6790 when Pragma_Attach_Handler =>
6791 Check_Ada_83_Warning;
6792 Check_No_Identifiers;
6793 Check_Arg_Count (2);
6795 if No_Run_Time_Mode then
6796 Error_Msg_CRT ("Attach_Handler pragma", N);
6798 Check_Interrupt_Or_Attach_Handler;
6800 -- The expression that designates the attribute may depend on a
6801 -- discriminant, and is therefore a per- object expression, to
6802 -- be expanded in the init proc. If expansion is enabled, then
6803 -- perform semantic checks on a copy only.
6805 if Expander_Active then
6807 Temp : constant Node_Id :=
6808 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6810 Set_Parent (Temp, N);
6811 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6815 Analyze (Get_Pragma_Arg (Arg2));
6816 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6819 Process_Interrupt_Or_Attach_Handler;
6822 --------------------
6823 -- C_Pass_By_Copy --
6824 --------------------
6826 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6828 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6834 Check_Valid_Configuration_Pragma;
6835 Check_Arg_Count (1);
6836 Check_Optional_Identifier (Arg1, "max_size");
6838 Arg := Get_Pragma_Arg (Arg1);
6839 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6841 Val := Expr_Value (Arg);
6845 ("maximum size for pragma% must be positive", Arg1);
6847 elsif UI_Is_In_Int_Range (Val) then
6848 Default_C_Record_Mechanism := UI_To_Int (Val);
6850 -- If a giant value is given, Int'Last will do well enough.
6851 -- If sometime someone complains that a record larger than
6852 -- two gigabytes is not copied, we will worry about it then!
6855 Default_C_Record_Mechanism := Mechanism_Type'Last;
6863 -- pragma Check ([Name =>] IDENTIFIER,
6864 -- [Check =>] Boolean_EXPRESSION
6865 -- [,[Message =>] String_EXPRESSION]);
6867 when Pragma_Check => Check : declare
6872 -- Set True if category of assertions referenced by Name enabled
6876 Check_At_Least_N_Arguments (2);
6877 Check_At_Most_N_Arguments (3);
6878 Check_Optional_Identifier (Arg1, Name_Name);
6879 Check_Optional_Identifier (Arg2, Name_Check);
6881 if Arg_Count = 3 then
6882 Check_Optional_Identifier (Arg3, Name_Message);
6883 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6886 Check_Arg_Is_Identifier (Arg1);
6888 -- Completely ignore if disabled
6890 if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
6891 Rewrite (N, Make_Null_Statement (Loc));
6896 -- Indicate if pragma is enabled. The Original_Node reference here
6897 -- is to deal with pragma Assert rewritten as a Check pragma.
6899 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6902 Set_SCO_Pragma_Enabled (Loc);
6905 -- If expansion is active and the check is not enabled then we
6906 -- rewrite the Check as:
6908 -- if False and then condition then
6912 -- The reason we do this rewriting during semantic analysis rather
6913 -- than as part of normal expansion is that we cannot analyze and
6914 -- expand the code for the boolean expression directly, or it may
6915 -- cause insertion of actions that would escape the attempt to
6916 -- suppress the check code.
6918 -- Note that the Sloc for the if statement corresponds to the
6919 -- argument condition, not the pragma itself. The reason for this
6920 -- is that we may generate a warning if the condition is False at
6921 -- compile time, and we do not want to delete this warning when we
6922 -- delete the if statement.
6924 Expr := Get_Pragma_Arg (Arg2);
6926 if Expander_Active and then not Check_On then
6927 Eloc := Sloc (Expr);
6930 Make_If_Statement (Eloc,
6932 Make_And_Then (Eloc,
6933 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6934 Right_Opnd => Expr),
6935 Then_Statements => New_List (
6936 Make_Null_Statement (Eloc))));
6943 Analyze_And_Resolve (Expr, Any_Boolean);
6951 -- pragma Check_Name (check_IDENTIFIER);
6953 when Pragma_Check_Name =>
6954 Check_No_Identifiers;
6956 Check_Valid_Configuration_Pragma;
6957 Check_Arg_Count (1);
6958 Check_Arg_Is_Identifier (Arg1);
6961 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6964 for J in Check_Names.First .. Check_Names.Last loop
6965 if Check_Names.Table (J) = Nam then
6970 Check_Names.Append (Nam);
6977 -- pragma Check_Policy (
6978 -- [Name =>] IDENTIFIER,
6979 -- [Policy =>] POLICY_IDENTIFIER);
6981 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
6983 -- Note: this is a configuration pragma, but it is allowed to appear
6986 when Pragma_Check_Policy =>
6988 Check_Arg_Count (2);
6989 Check_Optional_Identifier (Arg1, Name_Name);
6990 Check_Optional_Identifier (Arg2, Name_Policy);
6992 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
6994 -- A Check_Policy pragma can appear either as a configuration
6995 -- pragma, or in a declarative part or a package spec (see RM
6996 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6997 -- followed for Check_Policy).
6999 if not Is_Configuration_Pragma then
7000 Check_Is_In_Decl_Part_Or_Package_Spec;
7003 Set_Next_Pragma (N, Opt.Check_Policy_List);
7004 Opt.Check_Policy_List := N;
7006 ---------------------
7007 -- CIL_Constructor --
7008 ---------------------
7010 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7012 -- Processing for this pragma is shared with Java_Constructor
7018 -- pragma Comment (static_string_EXPRESSION)
7020 -- Processing for pragma Comment shares the circuitry for pragma
7021 -- Ident. The only differences are that Ident enforces a limit of 31
7022 -- characters on its argument, and also enforces limitations on
7023 -- placement for DEC compatibility. Pragma Comment shares neither of
7024 -- these restrictions.
7030 -- pragma Common_Object (
7031 -- [Internal =>] LOCAL_NAME
7032 -- [, [External =>] EXTERNAL_SYMBOL]
7033 -- [, [Size =>] EXTERNAL_SYMBOL]);
7035 -- Processing for this pragma is shared with Psect_Object
7037 ------------------------
7038 -- Compile_Time_Error --
7039 ------------------------
7041 -- pragma Compile_Time_Error
7042 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7044 when Pragma_Compile_Time_Error =>
7046 Process_Compile_Time_Warning_Or_Error;
7048 --------------------------
7049 -- Compile_Time_Warning --
7050 --------------------------
7052 -- pragma Compile_Time_Warning
7053 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7055 when Pragma_Compile_Time_Warning =>
7057 Process_Compile_Time_Warning_Or_Error;
7063 when Pragma_Compiler_Unit =>
7065 Check_Arg_Count (0);
7066 Set_Is_Compiler_Unit (Get_Source_Unit (N));
7068 -----------------------------
7069 -- Complete_Representation --
7070 -----------------------------
7072 -- pragma Complete_Representation;
7074 when Pragma_Complete_Representation =>
7076 Check_Arg_Count (0);
7078 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7080 ("pragma & must appear within record representation clause");
7083 ----------------------------
7084 -- Complex_Representation --
7085 ----------------------------
7087 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7089 when Pragma_Complex_Representation => Complex_Representation : declare
7096 Check_Arg_Count (1);
7097 Check_Optional_Identifier (Arg1, Name_Entity);
7098 Check_Arg_Is_Local_Name (Arg1);
7099 E_Id := Get_Pragma_Arg (Arg1);
7101 if Etype (E_Id) = Any_Type then
7107 if not Is_Record_Type (E) then
7109 ("argument for pragma% must be record type", Arg1);
7112 Ent := First_Entity (E);
7115 or else No (Next_Entity (Ent))
7116 or else Present (Next_Entity (Next_Entity (Ent)))
7117 or else not Is_Floating_Point_Type (Etype (Ent))
7118 or else Etype (Ent) /= Etype (Next_Entity (Ent))
7121 ("record for pragma% must have two fields of the same "
7122 & "floating-point type", Arg1);
7125 Set_Has_Complex_Representation (Base_Type (E));
7127 -- We need to treat the type has having a non-standard
7128 -- representation, for back-end purposes, even though in
7129 -- general a complex will have the default representation
7130 -- of a record with two real components.
7132 Set_Has_Non_Standard_Rep (Base_Type (E));
7134 end Complex_Representation;
7136 -------------------------
7137 -- Component_Alignment --
7138 -------------------------
7140 -- pragma Component_Alignment (
7141 -- [Form =>] ALIGNMENT_CHOICE
7142 -- [, [Name =>] type_LOCAL_NAME]);
7144 -- ALIGNMENT_CHOICE ::=
7146 -- | Component_Size_4
7150 when Pragma_Component_Alignment => Component_AlignmentP : declare
7151 Args : Args_List (1 .. 2);
7152 Names : constant Name_List (1 .. 2) := (
7156 Form : Node_Id renames Args (1);
7157 Name : Node_Id renames Args (2);
7159 Atype : Component_Alignment_Kind;
7164 Gather_Associations (Names, Args);
7167 Error_Pragma ("missing Form argument for pragma%");
7170 Check_Arg_Is_Identifier (Form);
7172 -- Get proper alignment, note that Default = Component_Size on all
7173 -- machines we have so far, and we want to set this value rather
7174 -- than the default value to indicate that it has been explicitly
7175 -- set (and thus will not get overridden by the default component
7176 -- alignment for the current scope)
7178 if Chars (Form) = Name_Component_Size then
7179 Atype := Calign_Component_Size;
7181 elsif Chars (Form) = Name_Component_Size_4 then
7182 Atype := Calign_Component_Size_4;
7184 elsif Chars (Form) = Name_Default then
7185 Atype := Calign_Component_Size;
7187 elsif Chars (Form) = Name_Storage_Unit then
7188 Atype := Calign_Storage_Unit;
7192 ("invalid Form parameter for pragma%", Form);
7195 -- Case with no name, supplied, affects scope table entry
7199 (Scope_Stack.Last).Component_Alignment_Default := Atype;
7201 -- Case of name supplied
7204 Check_Arg_Is_Local_Name (Name);
7206 Typ := Entity (Name);
7209 or else Rep_Item_Too_Early (Typ, N)
7213 Typ := Underlying_Type (Typ);
7216 if not Is_Record_Type (Typ)
7217 and then not Is_Array_Type (Typ)
7220 ("Name parameter of pragma% must identify record or " &
7221 "array type", Name);
7224 -- An explicit Component_Alignment pragma overrides an
7225 -- implicit pragma Pack, but not an explicit one.
7227 if not Has_Pragma_Pack (Base_Type (Typ)) then
7228 Set_Is_Packed (Base_Type (Typ), False);
7229 Set_Component_Alignment (Base_Type (Typ), Atype);
7232 end Component_AlignmentP;
7238 -- pragma Controlled (first_subtype_LOCAL_NAME);
7240 when Pragma_Controlled => Controlled : declare
7244 Check_No_Identifiers;
7245 Check_Arg_Count (1);
7246 Check_Arg_Is_Local_Name (Arg1);
7247 Arg := Get_Pragma_Arg (Arg1);
7249 if not Is_Entity_Name (Arg)
7250 or else not Is_Access_Type (Entity (Arg))
7252 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7254 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7262 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
7263 -- [Entity =>] LOCAL_NAME);
7265 when Pragma_Convention => Convention : declare
7268 pragma Warnings (Off, C);
7269 pragma Warnings (Off, E);
7271 Check_Arg_Order ((Name_Convention, Name_Entity));
7272 Check_Ada_83_Warning;
7273 Check_Arg_Count (2);
7274 Process_Convention (C, E);
7277 ---------------------------
7278 -- Convention_Identifier --
7279 ---------------------------
7281 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
7282 -- [Convention =>] convention_IDENTIFIER);
7284 when Pragma_Convention_Identifier => Convention_Identifier : declare
7290 Check_Arg_Order ((Name_Name, Name_Convention));
7291 Check_Arg_Count (2);
7292 Check_Optional_Identifier (Arg1, Name_Name);
7293 Check_Optional_Identifier (Arg2, Name_Convention);
7294 Check_Arg_Is_Identifier (Arg1);
7295 Check_Arg_Is_Identifier (Arg2);
7296 Idnam := Chars (Get_Pragma_Arg (Arg1));
7297 Cname := Chars (Get_Pragma_Arg (Arg2));
7299 if Is_Convention_Name (Cname) then
7300 Record_Convention_Identifier
7301 (Idnam, Get_Convention_Id (Cname));
7304 ("second arg for % pragma must be convention", Arg2);
7306 end Convention_Identifier;
7312 -- pragma CPP_Class ([Entity =>] local_NAME)
7314 when Pragma_CPP_Class => CPP_Class : declare
7319 if Warn_On_Obsolescent_Feature then
7321 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7322 " by pragma import?", N);
7326 Check_Arg_Count (1);
7327 Check_Optional_Identifier (Arg1, Name_Entity);
7328 Check_Arg_Is_Local_Name (Arg1);
7330 Arg := Get_Pragma_Arg (Arg1);
7333 if Etype (Arg) = Any_Type then
7337 if not Is_Entity_Name (Arg)
7338 or else not Is_Type (Entity (Arg))
7340 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7343 Typ := Entity (Arg);
7345 if not Is_Tagged_Type (Typ) then
7346 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7349 -- Types treated as CPP classes must be declared limited (note:
7350 -- this used to be a warning but there is no real benefit to it
7351 -- since we did effectively intend to treat the type as limited
7354 if not Is_Limited_Type (Typ) then
7356 ("imported 'C'P'P type must be limited",
7357 Get_Pragma_Arg (Arg1));
7360 Set_Is_CPP_Class (Typ);
7361 Set_Convention (Typ, Convention_CPP);
7363 -- Imported CPP types must not have discriminants (because C++
7364 -- classes do not have discriminants).
7366 if Has_Discriminants (Typ) then
7368 ("imported 'C'P'P type cannot have discriminants",
7369 First (Discriminant_Specifications
7370 (Declaration_Node (Typ))));
7373 -- Components of imported CPP types must not have default
7374 -- expressions because the constructor (if any) is in the
7377 if Is_Incomplete_Or_Private_Type (Typ)
7378 and then No (Underlying_Type (Typ))
7380 -- It should be an error to apply pragma CPP to a private
7381 -- type if the underlying type is not visible (as it is
7382 -- for any representation item). For now, for backward
7383 -- compatibility we do nothing but we cannot check components
7384 -- because they are not available at this stage. All this code
7385 -- will be removed when we cleanup this obsolete GNAT pragma???
7391 Tdef : constant Node_Id :=
7392 Type_Definition (Declaration_Node (Typ));
7397 if Nkind (Tdef) = N_Record_Definition then
7398 Clist := Component_List (Tdef);
7400 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7401 Clist := Component_List (Record_Extension_Part (Tdef));
7404 if Present (Clist) then
7405 Comp := First (Component_Items (Clist));
7406 while Present (Comp) loop
7407 if Present (Expression (Comp)) then
7409 ("component of imported 'C'P'P type cannot have" &
7410 " default expression", Expression (Comp));
7420 ---------------------
7421 -- CPP_Constructor --
7422 ---------------------
7424 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7425 -- [, [External_Name =>] static_string_EXPRESSION ]
7426 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7428 when Pragma_CPP_Constructor => CPP_Constructor : declare
7432 Tag_Typ : Entity_Id;
7436 Check_At_Least_N_Arguments (1);
7437 Check_At_Most_N_Arguments (3);
7438 Check_Optional_Identifier (Arg1, Name_Entity);
7439 Check_Arg_Is_Local_Name (Arg1);
7441 Id := Get_Pragma_Arg (Arg1);
7442 Find_Program_Unit_Name (Id);
7444 -- If we did not find the name, we are done
7446 if Etype (Id) = Any_Type then
7450 Def_Id := Entity (Id);
7452 -- Check if already defined as constructor
7454 if Is_Constructor (Def_Id) then
7456 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7460 if Ekind (Def_Id) = E_Function
7461 and then (Is_CPP_Class (Etype (Def_Id))
7462 or else (Is_Class_Wide_Type (Etype (Def_Id))
7464 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7466 if Arg_Count >= 2 then
7467 Set_Imported (Def_Id);
7468 Set_Is_Public (Def_Id);
7469 Process_Interface_Name (Def_Id, Arg2, Arg3);
7472 Set_Has_Completion (Def_Id);
7473 Set_Is_Constructor (Def_Id);
7475 -- Imported C++ constructors are not dispatching primitives
7476 -- because in C++ they don't have a dispatch table slot.
7477 -- However, in Ada the constructor has the profile of a
7478 -- function that returns a tagged type and therefore it has
7479 -- been treated as a primitive operation during semantic
7480 -- analysis. We now remove it from the list of primitive
7481 -- operations of the type.
7483 if Is_Tagged_Type (Etype (Def_Id))
7484 and then not Is_Class_Wide_Type (Etype (Def_Id))
7486 pragma Assert (Is_Dispatching_Operation (Def_Id));
7487 Tag_Typ := Etype (Def_Id);
7489 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7490 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7494 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7495 Set_Is_Dispatching_Operation (Def_Id, False);
7498 -- For backward compatibility, if the constructor returns a
7499 -- class wide type, and we internally change the return type to
7500 -- the corresponding root type.
7502 if Is_Class_Wide_Type (Etype (Def_Id)) then
7503 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7507 ("pragma% requires function returning a 'C'P'P_Class type",
7510 end CPP_Constructor;
7516 when Pragma_CPP_Virtual => CPP_Virtual : declare
7520 if Warn_On_Obsolescent_Feature then
7522 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7531 when Pragma_CPP_Vtable => CPP_Vtable : declare
7535 if Warn_On_Obsolescent_Feature then
7537 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7546 -- pragma CPU (EXPRESSION);
7548 when Pragma_CPU => CPU : declare
7549 P : constant Node_Id := Parent (N);
7554 Check_No_Identifiers;
7555 Check_Arg_Count (1);
7559 if Nkind (P) = N_Subprogram_Body then
7560 Check_In_Main_Program;
7562 Arg := Get_Pragma_Arg (Arg1);
7563 Analyze_And_Resolve (Arg, Any_Integer);
7567 if not Is_Static_Expression (Arg) then
7568 Flag_Non_Static_Expr
7569 ("main subprogram affinity is not static!", Arg);
7572 -- If constraint error, then we already signalled an error
7574 elsif Raises_Constraint_Error (Arg) then
7577 -- Otherwise check in range
7581 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7582 -- This is the entity System.Multiprocessors.CPU_Range;
7584 Val : constant Uint := Expr_Value (Arg);
7587 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7589 Val > Expr_Value (Type_High_Bound (CPU_Id))
7592 ("main subprogram CPU is out of range", Arg1);
7598 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7602 elsif Nkind (P) = N_Task_Definition then
7603 Arg := Get_Pragma_Arg (Arg1);
7605 -- The expression must be analyzed in the special manner
7606 -- described in "Handling of Default and Per-Object
7607 -- Expressions" in sem.ads.
7609 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7611 -- Anything else is incorrect
7617 if Has_Pragma_CPU (P) then
7618 Error_Pragma ("duplicate pragma% not allowed");
7620 Set_Has_Pragma_CPU (P, True);
7622 if Nkind (P) = N_Task_Definition then
7623 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7632 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7634 when Pragma_Debug => Debug : declare
7641 -- Skip analysis if disabled
7643 if Debug_Pragmas_Disabled then
7644 Rewrite (N, Make_Null_Statement (Loc));
7651 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7654 if Debug_Pragmas_Enabled then
7655 Set_SCO_Pragma_Enabled (Loc);
7658 if Arg_Count = 2 then
7661 Left_Opnd => Relocate_Node (Cond),
7662 Right_Opnd => Get_Pragma_Arg (Arg1));
7663 Call := Get_Pragma_Arg (Arg2);
7665 Call := Get_Pragma_Arg (Arg1);
7669 N_Indexed_Component,
7672 N_Selected_Component)
7674 -- If this pragma Debug comes from source, its argument was
7675 -- parsed as a name form (which is syntactically identical).
7676 -- Change it to a procedure call statement now.
7678 Change_Name_To_Procedure_Call_Statement (Call);
7680 elsif Nkind (Call) = N_Procedure_Call_Statement then
7682 -- Already in the form of a procedure call statement: nothing
7683 -- to do (could happen in case of an internally generated
7689 -- All other cases: diagnose error
7692 ("argument of pragma% is not procedure call", Sloc (Call));
7696 -- Rewrite into a conditional with an appropriate condition. We
7697 -- wrap the procedure call in a block so that overhead from e.g.
7698 -- use of the secondary stack does not generate execution overhead
7699 -- for suppressed conditions.
7701 Rewrite (N, Make_Implicit_If_Statement (N,
7703 Then_Statements => New_List (
7704 Make_Block_Statement (Loc,
7705 Handled_Statement_Sequence =>
7706 Make_Handled_Sequence_Of_Statements (Loc,
7707 Statements => New_List (Relocate_Node (Call)))))));
7715 -- pragma Debug_Policy (Check | Ignore)
7717 when Pragma_Debug_Policy =>
7719 Check_Arg_Count (1);
7720 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7721 Debug_Pragmas_Enabled :=
7722 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7723 Debug_Pragmas_Disabled :=
7724 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
7726 ---------------------
7727 -- Detect_Blocking --
7728 ---------------------
7730 -- pragma Detect_Blocking;
7732 when Pragma_Detect_Blocking =>
7734 Check_Arg_Count (0);
7735 Check_Valid_Configuration_Pragma;
7736 Detect_Blocking := True;
7738 --------------------------
7739 -- Default_Storage_Pool --
7740 --------------------------
7742 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7744 when Pragma_Default_Storage_Pool =>
7746 Check_Arg_Count (1);
7748 -- Default_Storage_Pool can appear as a configuration pragma, or
7749 -- in a declarative part or a package spec.
7751 if not Is_Configuration_Pragma then
7752 Check_Is_In_Decl_Part_Or_Package_Spec;
7755 -- Case of Default_Storage_Pool (null);
7757 if Nkind (Expression (Arg1)) = N_Null then
7758 Analyze (Expression (Arg1));
7760 -- This is an odd case, this is not really an expression, so
7761 -- we don't have a type for it. So just set the type to Empty.
7763 Set_Etype (Expression (Arg1), Empty);
7765 -- Case of Default_Storage_Pool (storage_pool_NAME);
7768 -- If it's a configuration pragma, then the only allowed
7769 -- argument is "null".
7771 if Is_Configuration_Pragma then
7772 Error_Pragma_Arg ("NULL expected", Arg1);
7775 -- The expected type for a non-"null" argument is
7776 -- Root_Storage_Pool'Class.
7779 (Get_Pragma_Arg (Arg1),
7780 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7783 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7784 -- for an access type will use this information to set the
7785 -- appropriate attributes of the access type.
7787 Default_Pool := Expression (Arg1);
7793 when Pragma_Dimension =>
7795 Check_Arg_Count (4);
7796 Check_No_Identifiers;
7797 Check_Arg_Is_Local_Name (Arg1);
7799 if not Is_Type (Arg1) then
7800 Error_Pragma ("first argument for pragma% must be subtype");
7803 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7804 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7805 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7811 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7813 when Pragma_Discard_Names => Discard_Names : declare
7818 Check_Ada_83_Warning;
7820 -- Deal with configuration pragma case
7822 if Arg_Count = 0 and then Is_Configuration_Pragma then
7823 Global_Discard_Names := True;
7826 -- Otherwise, check correct appropriate context
7829 Check_Is_In_Decl_Part_Or_Package_Spec;
7831 if Arg_Count = 0 then
7833 -- If there is no parameter, then from now on this pragma
7834 -- applies to any enumeration, exception or tagged type
7835 -- defined in the current declarative part, and recursively
7836 -- to any nested scope.
7838 Set_Discard_Names (Current_Scope);
7842 Check_Arg_Count (1);
7843 Check_Optional_Identifier (Arg1, Name_On);
7844 Check_Arg_Is_Local_Name (Arg1);
7846 E_Id := Get_Pragma_Arg (Arg1);
7848 if Etype (E_Id) = Any_Type then
7854 if (Is_First_Subtype (E)
7856 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7857 or else Ekind (E) = E_Exception
7859 Set_Discard_Names (E);
7862 ("inappropriate entity for pragma%", Arg1);
7873 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7875 when Pragma_Elaborate => Elaborate : declare
7880 -- Pragma must be in context items list of a compilation unit
7882 if not Is_In_Context_Clause then
7886 -- Must be at least one argument
7888 if Arg_Count = 0 then
7889 Error_Pragma ("pragma% requires at least one argument");
7892 -- In Ada 83 mode, there can be no items following it in the
7893 -- context list except other pragmas and implicit with clauses
7894 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7895 -- placement rule does not apply.
7897 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7899 while Present (Citem) loop
7900 if Nkind (Citem) = N_Pragma
7901 or else (Nkind (Citem) = N_With_Clause
7902 and then Implicit_With (Citem))
7907 ("(Ada 83) pragma% must be at end of context clause");
7914 -- Finally, the arguments must all be units mentioned in a with
7915 -- clause in the same context clause. Note we already checked (in
7916 -- Par.Prag) that the arguments are all identifiers or selected
7920 Outer : while Present (Arg) loop
7921 Citem := First (List_Containing (N));
7922 Inner : while Citem /= N loop
7923 if Nkind (Citem) = N_With_Clause
7924 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7926 Set_Elaborate_Present (Citem, True);
7927 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7928 Generate_Reference (Entity (Name (Citem)), Citem);
7930 -- With the pragma present, elaboration calls on
7931 -- subprograms from the named unit need no further
7932 -- checks, as long as the pragma appears in the current
7933 -- compilation unit. If the pragma appears in some unit
7934 -- in the context, there might still be a need for an
7935 -- Elaborate_All_Desirable from the current compilation
7936 -- to the named unit, so we keep the check enabled.
7938 if In_Extended_Main_Source_Unit (N) then
7939 Set_Suppress_Elaboration_Warnings
7940 (Entity (Name (Citem)));
7951 ("argument of pragma% is not with'ed unit", Arg);
7957 -- Give a warning if operating in static mode with -gnatwl
7958 -- (elaboration warnings enabled) switch set.
7960 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7962 ("?use of pragma Elaborate may not be safe", N);
7964 ("?use pragma Elaborate_All instead if possible", N);
7972 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7974 when Pragma_Elaborate_All => Elaborate_All : declare
7979 Check_Ada_83_Warning;
7981 -- Pragma must be in context items list of a compilation unit
7983 if not Is_In_Context_Clause then
7987 -- Must be at least one argument
7989 if Arg_Count = 0 then
7990 Error_Pragma ("pragma% requires at least one argument");
7993 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7994 -- have to appear at the end of the context clause, but may
7995 -- appear mixed in with other items, even in Ada 83 mode.
7997 -- Final check: the arguments must all be units mentioned in
7998 -- a with clause in the same context clause. Note that we
7999 -- already checked (in Par.Prag) that all the arguments are
8000 -- either identifiers or selected components.
8003 Outr : while Present (Arg) loop
8004 Citem := First (List_Containing (N));
8005 Innr : while Citem /= N loop
8006 if Nkind (Citem) = N_With_Clause
8007 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8009 Set_Elaborate_All_Present (Citem, True);
8010 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8012 -- Suppress warnings and elaboration checks on the named
8013 -- unit if the pragma is in the current compilation, as
8014 -- for pragma Elaborate.
8016 if In_Extended_Main_Source_Unit (N) then
8017 Set_Suppress_Elaboration_Warnings
8018 (Entity (Name (Citem)));
8027 Set_Error_Posted (N);
8029 ("argument of pragma% is not with'ed unit", Arg);
8036 --------------------
8037 -- Elaborate_Body --
8038 --------------------
8040 -- pragma Elaborate_Body [( library_unit_NAME )];
8042 when Pragma_Elaborate_Body => Elaborate_Body : declare
8043 Cunit_Node : Node_Id;
8044 Cunit_Ent : Entity_Id;
8047 Check_Ada_83_Warning;
8048 Check_Valid_Library_Unit_Pragma;
8050 if Nkind (N) = N_Null_Statement then
8054 Cunit_Node := Cunit (Current_Sem_Unit);
8055 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8057 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8060 Error_Pragma ("pragma% must refer to a spec, not a body");
8062 Set_Body_Required (Cunit_Node, True);
8063 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8065 -- If we are in dynamic elaboration mode, then we suppress
8066 -- elaboration warnings for the unit, since it is definitely
8067 -- fine NOT to do dynamic checks at the first level (and such
8068 -- checks will be suppressed because no elaboration boolean
8069 -- is created for Elaborate_Body packages).
8071 -- But in the static model of elaboration, Elaborate_Body is
8072 -- definitely NOT good enough to ensure elaboration safety on
8073 -- its own, since the body may WITH other units that are not
8074 -- safe from an elaboration point of view, so a client must
8075 -- still do an Elaborate_All on such units.
8077 -- Debug flag -gnatdD restores the old behavior of 3.13, where
8078 -- Elaborate_Body always suppressed elab warnings.
8080 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8081 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8086 ------------------------
8087 -- Elaboration_Checks --
8088 ------------------------
8090 -- pragma Elaboration_Checks (Static | Dynamic);
8092 when Pragma_Elaboration_Checks =>
8094 Check_Arg_Count (1);
8095 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8096 Dynamic_Elaboration_Checks :=
8097 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8103 -- pragma Eliminate (
8104 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
8105 -- [,[Entity =>] IDENTIFIER |
8106 -- SELECTED_COMPONENT |
8108 -- [, OVERLOADING_RESOLUTION]);
8110 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8113 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8116 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8118 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8119 -- Result_Type => result_SUBTYPE_NAME]
8121 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8122 -- SUBTYPE_NAME ::= STRING_LITERAL
8124 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8125 -- SOURCE_TRACE ::= STRING_LITERAL
8127 when Pragma_Eliminate => Eliminate : declare
8128 Args : Args_List (1 .. 5);
8129 Names : constant Name_List (1 .. 5) := (
8132 Name_Parameter_Types,
8134 Name_Source_Location);
8136 Unit_Name : Node_Id renames Args (1);
8137 Entity : Node_Id renames Args (2);
8138 Parameter_Types : Node_Id renames Args (3);
8139 Result_Type : Node_Id renames Args (4);
8140 Source_Location : Node_Id renames Args (5);
8144 Check_Valid_Configuration_Pragma;
8145 Gather_Associations (Names, Args);
8147 if No (Unit_Name) then
8148 Error_Pragma ("missing Unit_Name argument for pragma%");
8152 and then (Present (Parameter_Types)
8154 Present (Result_Type)
8156 Present (Source_Location))
8158 Error_Pragma ("missing Entity argument for pragma%");
8161 if (Present (Parameter_Types)
8163 Present (Result_Type))
8165 Present (Source_Location)
8168 ("parameter profile and source location cannot " &
8169 "be used together in pragma%");
8172 Process_Eliminate_Pragma
8186 -- [ Convention =>] convention_IDENTIFIER,
8187 -- [ Entity =>] local_NAME
8188 -- [, [External_Name =>] static_string_EXPRESSION ]
8189 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8191 when Pragma_Export => Export : declare
8195 pragma Warnings (Off, C);
8198 Check_Ada_83_Warning;
8204 Check_At_Least_N_Arguments (2);
8205 Check_At_Most_N_Arguments (4);
8206 Process_Convention (C, Def_Id);
8208 if Ekind (Def_Id) /= E_Constant then
8209 Note_Possible_Modification
8210 (Get_Pragma_Arg (Arg2), Sure => False);
8213 Process_Interface_Name (Def_Id, Arg3, Arg4);
8214 Set_Exported (Def_Id, Arg2);
8216 -- If the entity is a deferred constant, propagate the information
8217 -- to the full view, because gigi elaborates the full view only.
8219 if Ekind (Def_Id) = E_Constant
8220 and then Present (Full_View (Def_Id))
8223 Id2 : constant Entity_Id := Full_View (Def_Id);
8225 Set_Is_Exported (Id2, Is_Exported (Def_Id));
8226 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
8227 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8232 ----------------------
8233 -- Export_Exception --
8234 ----------------------
8236 -- pragma Export_Exception (
8237 -- [Internal =>] LOCAL_NAME
8238 -- [, [External =>] EXTERNAL_SYMBOL]
8239 -- [, [Form =>] Ada | VMS]
8240 -- [, [Code =>] static_integer_EXPRESSION]);
8242 when Pragma_Export_Exception => Export_Exception : declare
8243 Args : Args_List (1 .. 4);
8244 Names : constant Name_List (1 .. 4) := (
8250 Internal : Node_Id renames Args (1);
8251 External : Node_Id renames Args (2);
8252 Form : Node_Id renames Args (3);
8253 Code : Node_Id renames Args (4);
8258 if Inside_A_Generic then
8259 Error_Pragma ("pragma% cannot be used for generic entities");
8262 Gather_Associations (Names, Args);
8263 Process_Extended_Import_Export_Exception_Pragma (
8264 Arg_Internal => Internal,
8265 Arg_External => External,
8269 if not Is_VMS_Exception (Entity (Internal)) then
8270 Set_Exported (Entity (Internal), Internal);
8272 end Export_Exception;
8274 ---------------------
8275 -- Export_Function --
8276 ---------------------
8278 -- pragma Export_Function (
8279 -- [Internal =>] LOCAL_NAME
8280 -- [, [External =>] EXTERNAL_SYMBOL]
8281 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8282 -- [, [Result_Type =>] TYPE_DESIGNATOR]
8283 -- [, [Mechanism =>] MECHANISM]
8284 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8286 -- EXTERNAL_SYMBOL ::=
8288 -- | static_string_EXPRESSION
8290 -- PARAMETER_TYPES ::=
8292 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8294 -- TYPE_DESIGNATOR ::=
8296 -- | subtype_Name ' Access
8300 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8302 -- MECHANISM_ASSOCIATION ::=
8303 -- [formal_parameter_NAME =>] MECHANISM_NAME
8305 -- MECHANISM_NAME ::=
8308 -- | Descriptor [([Class =>] CLASS_NAME)]
8310 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8312 when Pragma_Export_Function => Export_Function : declare
8313 Args : Args_List (1 .. 6);
8314 Names : constant Name_List (1 .. 6) := (
8317 Name_Parameter_Types,
8320 Name_Result_Mechanism);
8322 Internal : Node_Id renames Args (1);
8323 External : Node_Id renames Args (2);
8324 Parameter_Types : Node_Id renames Args (3);
8325 Result_Type : Node_Id renames Args (4);
8326 Mechanism : Node_Id renames Args (5);
8327 Result_Mechanism : Node_Id renames Args (6);
8331 Gather_Associations (Names, Args);
8332 Process_Extended_Import_Export_Subprogram_Pragma (
8333 Arg_Internal => Internal,
8334 Arg_External => External,
8335 Arg_Parameter_Types => Parameter_Types,
8336 Arg_Result_Type => Result_Type,
8337 Arg_Mechanism => Mechanism,
8338 Arg_Result_Mechanism => Result_Mechanism);
8339 end Export_Function;
8345 -- pragma Export_Object (
8346 -- [Internal =>] LOCAL_NAME
8347 -- [, [External =>] EXTERNAL_SYMBOL]
8348 -- [, [Size =>] EXTERNAL_SYMBOL]);
8350 -- EXTERNAL_SYMBOL ::=
8352 -- | static_string_EXPRESSION
8354 -- PARAMETER_TYPES ::=
8356 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8358 -- TYPE_DESIGNATOR ::=
8360 -- | subtype_Name ' Access
8364 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8366 -- MECHANISM_ASSOCIATION ::=
8367 -- [formal_parameter_NAME =>] MECHANISM_NAME
8369 -- MECHANISM_NAME ::=
8372 -- | Descriptor [([Class =>] CLASS_NAME)]
8374 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8376 when Pragma_Export_Object => Export_Object : declare
8377 Args : Args_List (1 .. 3);
8378 Names : constant Name_List (1 .. 3) := (
8383 Internal : Node_Id renames Args (1);
8384 External : Node_Id renames Args (2);
8385 Size : Node_Id renames Args (3);
8389 Gather_Associations (Names, Args);
8390 Process_Extended_Import_Export_Object_Pragma (
8391 Arg_Internal => Internal,
8392 Arg_External => External,
8396 ----------------------
8397 -- Export_Procedure --
8398 ----------------------
8400 -- pragma Export_Procedure (
8401 -- [Internal =>] LOCAL_NAME
8402 -- [, [External =>] EXTERNAL_SYMBOL]
8403 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8404 -- [, [Mechanism =>] MECHANISM]);
8406 -- EXTERNAL_SYMBOL ::=
8408 -- | static_string_EXPRESSION
8410 -- PARAMETER_TYPES ::=
8412 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8414 -- TYPE_DESIGNATOR ::=
8416 -- | subtype_Name ' Access
8420 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8422 -- MECHANISM_ASSOCIATION ::=
8423 -- [formal_parameter_NAME =>] MECHANISM_NAME
8425 -- MECHANISM_NAME ::=
8428 -- | Descriptor [([Class =>] CLASS_NAME)]
8430 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8432 when Pragma_Export_Procedure => Export_Procedure : declare
8433 Args : Args_List (1 .. 4);
8434 Names : constant Name_List (1 .. 4) := (
8437 Name_Parameter_Types,
8440 Internal : Node_Id renames Args (1);
8441 External : Node_Id renames Args (2);
8442 Parameter_Types : Node_Id renames Args (3);
8443 Mechanism : Node_Id renames Args (4);
8447 Gather_Associations (Names, Args);
8448 Process_Extended_Import_Export_Subprogram_Pragma (
8449 Arg_Internal => Internal,
8450 Arg_External => External,
8451 Arg_Parameter_Types => Parameter_Types,
8452 Arg_Mechanism => Mechanism);
8453 end Export_Procedure;
8459 -- pragma Export_Value (
8460 -- [Value =>] static_integer_EXPRESSION,
8461 -- [Link_Name =>] static_string_EXPRESSION);
8463 when Pragma_Export_Value =>
8465 Check_Arg_Order ((Name_Value, Name_Link_Name));
8466 Check_Arg_Count (2);
8468 Check_Optional_Identifier (Arg1, Name_Value);
8469 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8471 Check_Optional_Identifier (Arg2, Name_Link_Name);
8472 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8474 -----------------------------
8475 -- Export_Valued_Procedure --
8476 -----------------------------
8478 -- pragma Export_Valued_Procedure (
8479 -- [Internal =>] LOCAL_NAME
8480 -- [, [External =>] EXTERNAL_SYMBOL,]
8481 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8482 -- [, [Mechanism =>] MECHANISM]);
8484 -- EXTERNAL_SYMBOL ::=
8486 -- | static_string_EXPRESSION
8488 -- PARAMETER_TYPES ::=
8490 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8492 -- TYPE_DESIGNATOR ::=
8494 -- | subtype_Name ' Access
8498 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8500 -- MECHANISM_ASSOCIATION ::=
8501 -- [formal_parameter_NAME =>] MECHANISM_NAME
8503 -- MECHANISM_NAME ::=
8506 -- | Descriptor [([Class =>] CLASS_NAME)]
8508 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8510 when Pragma_Export_Valued_Procedure =>
8511 Export_Valued_Procedure : declare
8512 Args : Args_List (1 .. 4);
8513 Names : constant Name_List (1 .. 4) := (
8516 Name_Parameter_Types,
8519 Internal : Node_Id renames Args (1);
8520 External : Node_Id renames Args (2);
8521 Parameter_Types : Node_Id renames Args (3);
8522 Mechanism : Node_Id renames Args (4);
8526 Gather_Associations (Names, Args);
8527 Process_Extended_Import_Export_Subprogram_Pragma (
8528 Arg_Internal => Internal,
8529 Arg_External => External,
8530 Arg_Parameter_Types => Parameter_Types,
8531 Arg_Mechanism => Mechanism);
8532 end Export_Valued_Procedure;
8538 -- pragma Extend_System ([Name =>] Identifier);
8540 when Pragma_Extend_System => Extend_System : declare
8543 Check_Valid_Configuration_Pragma;
8544 Check_Arg_Count (1);
8545 Check_Optional_Identifier (Arg1, Name_Name);
8546 Check_Arg_Is_Identifier (Arg1);
8548 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8551 and then Name_Buffer (1 .. 4) = "aux_"
8553 if Present (System_Extend_Pragma_Arg) then
8554 if Chars (Get_Pragma_Arg (Arg1)) =
8555 Chars (Expression (System_Extend_Pragma_Arg))
8559 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8560 Error_Pragma ("pragma% conflicts with that #");
8564 System_Extend_Pragma_Arg := Arg1;
8566 if not GNAT_Mode then
8567 System_Extend_Unit := Arg1;
8571 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8575 ------------------------
8576 -- Extensions_Allowed --
8577 ------------------------
8579 -- pragma Extensions_Allowed (ON | OFF);
8581 when Pragma_Extensions_Allowed =>
8583 Check_Arg_Count (1);
8584 Check_No_Identifiers;
8585 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8587 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8588 Extensions_Allowed := True;
8589 Ada_Version := Ada_Version_Type'Last;
8592 Extensions_Allowed := False;
8593 Ada_Version := Ada_Version_Explicit;
8600 -- pragma External (
8601 -- [ Convention =>] convention_IDENTIFIER,
8602 -- [ Entity =>] local_NAME
8603 -- [, [External_Name =>] static_string_EXPRESSION ]
8604 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8606 when Pragma_External => External : declare
8610 pragma Warnings (Off, C);
8619 Check_At_Least_N_Arguments (2);
8620 Check_At_Most_N_Arguments (4);
8621 Process_Convention (C, Def_Id);
8622 Note_Possible_Modification
8623 (Get_Pragma_Arg (Arg2), Sure => False);
8624 Process_Interface_Name (Def_Id, Arg3, Arg4);
8625 Set_Exported (Def_Id, Arg2);
8628 --------------------------
8629 -- External_Name_Casing --
8630 --------------------------
8632 -- pragma External_Name_Casing (
8633 -- UPPERCASE | LOWERCASE
8634 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8636 when Pragma_External_Name_Casing => External_Name_Casing : declare
8639 Check_No_Identifiers;
8641 if Arg_Count = 2 then
8643 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8645 case Chars (Get_Pragma_Arg (Arg2)) is
8647 Opt.External_Name_Exp_Casing := As_Is;
8649 when Name_Uppercase =>
8650 Opt.External_Name_Exp_Casing := Uppercase;
8652 when Name_Lowercase =>
8653 Opt.External_Name_Exp_Casing := Lowercase;
8660 Check_Arg_Count (1);
8663 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8665 case Chars (Get_Pragma_Arg (Arg1)) is
8666 when Name_Uppercase =>
8667 Opt.External_Name_Imp_Casing := Uppercase;
8669 when Name_Lowercase =>
8670 Opt.External_Name_Imp_Casing := Lowercase;
8675 end External_Name_Casing;
8677 --------------------------
8678 -- Favor_Top_Level --
8679 --------------------------
8681 -- pragma Favor_Top_Level (type_NAME);
8683 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8684 Named_Entity : Entity_Id;
8688 Check_No_Identifiers;
8689 Check_Arg_Count (1);
8690 Check_Arg_Is_Local_Name (Arg1);
8691 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8693 -- If it's an access-to-subprogram type (in particular, not a
8694 -- subtype), set the flag on that type.
8696 if Is_Access_Subprogram_Type (Named_Entity) then
8697 Set_Can_Use_Internal_Rep (Named_Entity, False);
8699 -- Otherwise it's an error (name denotes the wrong sort of entity)
8703 ("access-to-subprogram type expected",
8704 Get_Pragma_Arg (Arg1));
8706 end Favor_Top_Level;
8712 -- pragma Fast_Math;
8714 when Pragma_Fast_Math =>
8716 Check_No_Identifiers;
8717 Check_Valid_Configuration_Pragma;
8720 ---------------------------
8721 -- Finalize_Storage_Only --
8722 ---------------------------
8724 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8726 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8727 Assoc : constant Node_Id := Arg1;
8728 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8733 Check_No_Identifiers;
8734 Check_Arg_Count (1);
8735 Check_Arg_Is_Local_Name (Arg1);
8737 Find_Type (Type_Id);
8738 Typ := Entity (Type_Id);
8741 or else Rep_Item_Too_Early (Typ, N)
8745 Typ := Underlying_Type (Typ);
8748 if not Is_Controlled (Typ) then
8749 Error_Pragma ("pragma% must specify controlled type");
8752 Check_First_Subtype (Arg1);
8754 if Finalize_Storage_Only (Typ) then
8755 Error_Pragma ("duplicate pragma%, only one allowed");
8757 elsif not Rep_Item_Too_Late (Typ, N) then
8758 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8760 end Finalize_Storage;
8762 --------------------------
8763 -- Float_Representation --
8764 --------------------------
8766 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8768 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8770 when Pragma_Float_Representation => Float_Representation : declare
8778 if Arg_Count = 1 then
8779 Check_Valid_Configuration_Pragma;
8781 Check_Arg_Count (2);
8782 Check_Optional_Identifier (Arg2, Name_Entity);
8783 Check_Arg_Is_Local_Name (Arg2);
8786 Check_No_Identifier (Arg1);
8787 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8789 if not OpenVMS_On_Target then
8790 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8792 ("?pragma% ignored (applies only to Open'V'M'S)");
8798 -- One argument case
8800 if Arg_Count = 1 then
8801 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8802 if Opt.Float_Format = 'I' then
8803 Error_Pragma ("'I'E'E'E format previously specified");
8806 Opt.Float_Format := 'V';
8809 if Opt.Float_Format = 'V' then
8810 Error_Pragma ("'V'A'X format previously specified");
8813 Opt.Float_Format := 'I';
8816 Set_Standard_Fpt_Formats;
8818 -- Two argument case
8821 Argx := Get_Pragma_Arg (Arg2);
8823 if not Is_Entity_Name (Argx)
8824 or else not Is_Floating_Point_Type (Entity (Argx))
8827 ("second argument of% pragma must be floating-point type",
8831 Ent := Entity (Argx);
8832 Digs := UI_To_Int (Digits_Value (Ent));
8834 -- Two arguments, VAX_Float case
8836 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8838 when 6 => Set_F_Float (Ent);
8839 when 9 => Set_D_Float (Ent);
8840 when 15 => Set_G_Float (Ent);
8844 ("wrong digits value, must be 6,9 or 15", Arg2);
8847 -- Two arguments, IEEE_Float case
8851 when 6 => Set_IEEE_Short (Ent);
8852 when 15 => Set_IEEE_Long (Ent);
8856 ("wrong digits value, must be 6 or 15", Arg2);
8860 end Float_Representation;
8866 -- pragma Ident (static_string_EXPRESSION)
8868 -- Note: pragma Comment shares this processing. Pragma Comment is
8869 -- identical to Ident, except that the restriction of the argument to
8870 -- 31 characters and the placement restrictions are not enforced for
8873 when Pragma_Ident | Pragma_Comment => Ident : declare
8878 Check_Arg_Count (1);
8879 Check_No_Identifiers;
8880 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8883 -- For pragma Ident, preserve DEC compatibility by requiring the
8884 -- pragma to appear in a declarative part or package spec.
8886 if Prag_Id = Pragma_Ident then
8887 Check_Is_In_Decl_Part_Or_Package_Spec;
8890 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8897 GP := Parent (Parent (N));
8899 if Nkind_In (GP, N_Package_Declaration,
8900 N_Generic_Package_Declaration)
8905 -- If we have a compilation unit, then record the ident value,
8906 -- checking for improper duplication.
8908 if Nkind (GP) = N_Compilation_Unit then
8909 CS := Ident_String (Current_Sem_Unit);
8911 if Present (CS) then
8913 -- For Ident, we do not permit multiple instances
8915 if Prag_Id = Pragma_Ident then
8916 Error_Pragma ("duplicate% pragma not permitted");
8918 -- For Comment, we concatenate the string, unless we want
8919 -- to preserve the tree structure for ASIS.
8921 elsif not ASIS_Mode then
8922 Start_String (Strval (CS));
8923 Store_String_Char (' ');
8924 Store_String_Chars (Strval (Str));
8925 Set_Strval (CS, End_String);
8929 -- In VMS, the effect of IDENT is achieved by passing
8930 -- --identification=name as a --for-linker switch.
8932 if OpenVMS_On_Target then
8935 ("--for-linker=--identification=");
8936 String_To_Name_Buffer (Strval (Str));
8937 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8939 -- Only the last processed IDENT is saved. The main
8940 -- purpose is so an IDENT associated with a main
8941 -- procedure will be used in preference to an IDENT
8942 -- associated with a with'd package.
8944 Replace_Linker_Option_String
8945 (End_String, "--for-linker=--identification=");
8948 Set_Ident_String (Current_Sem_Unit, Str);
8951 -- For subunits, we just ignore the Ident, since in GNAT these
8952 -- are not separate object files, and hence not separate units
8953 -- in the unit table.
8955 elsif Nkind (GP) = N_Subunit then
8958 -- Otherwise we have a misplaced pragma Ident, but we ignore
8959 -- this if we are in an instantiation, since it comes from
8960 -- a generic, and has no relevance to the instantiation.
8962 elsif Prag_Id = Pragma_Ident then
8963 if Instantiation_Location (Loc) = No_Location then
8964 Error_Pragma ("pragma% only allowed at outer level");
8974 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8975 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8977 when Pragma_Implemented => Implemented : declare
8978 Proc_Id : Entity_Id;
8983 Check_Arg_Count (2);
8984 Check_No_Identifiers;
8985 Check_Arg_Is_Identifier (Arg1);
8986 Check_Arg_Is_Local_Name (Arg1);
8988 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8990 -- Extract the name of the local procedure
8992 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8994 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8995 -- primitive procedure of a synchronized tagged type.
8997 if Ekind (Proc_Id) = E_Procedure
8998 and then Is_Primitive (Proc_Id)
8999 and then Present (First_Formal (Proc_Id))
9001 Typ := Etype (First_Formal (Proc_Id));
9003 if Is_Tagged_Type (Typ)
9006 -- Check for a protected, a synchronized or a task interface
9008 ((Is_Interface (Typ)
9009 and then Is_Synchronized_Interface (Typ))
9011 -- Check for a protected type or a task type that implements
9015 (Is_Concurrent_Record_Type (Typ)
9016 and then Present (Interfaces (Typ)))
9018 -- Check for a private record extension with keyword
9022 (Ekind_In (Typ, E_Record_Type_With_Private,
9023 E_Record_Subtype_With_Private)
9024 and then Synchronized_Present (Parent (Typ))))
9029 ("controlling formal must be of synchronized " &
9030 "tagged type", Arg1);
9034 -- Procedures declared inside a protected type must be accepted
9036 elsif Ekind (Proc_Id) = E_Procedure
9037 and then Is_Protected_Type (Scope (Proc_Id))
9041 -- The first argument is not a primitive procedure
9045 ("pragma % must be applied to a primitive procedure", Arg1);
9049 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9050 -- By_Protected_Procedure to the primitive procedure of a task
9053 if Chars (Arg2) = Name_By_Protected_Procedure
9054 and then Is_Interface (Typ)
9055 and then Is_Task_Interface (Typ)
9058 ("implementation kind By_Protected_Procedure cannot be " &
9059 "applied to a task interface primitive", Arg2);
9063 Record_Rep_Item (Proc_Id, N);
9066 ----------------------
9067 -- Implicit_Packing --
9068 ----------------------
9070 -- pragma Implicit_Packing;
9072 when Pragma_Implicit_Packing =>
9074 Check_Arg_Count (0);
9075 Implicit_Packing := True;
9082 -- [Convention =>] convention_IDENTIFIER,
9083 -- [Entity =>] local_NAME
9084 -- [, [External_Name =>] static_string_EXPRESSION ]
9085 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9087 when Pragma_Import =>
9088 Check_Ada_83_Warning;
9094 Check_At_Least_N_Arguments (2);
9095 Check_At_Most_N_Arguments (4);
9096 Process_Import_Or_Interface;
9098 ----------------------
9099 -- Import_Exception --
9100 ----------------------
9102 -- pragma Import_Exception (
9103 -- [Internal =>] LOCAL_NAME
9104 -- [, [External =>] EXTERNAL_SYMBOL]
9105 -- [, [Form =>] Ada | VMS]
9106 -- [, [Code =>] static_integer_EXPRESSION]);
9108 when Pragma_Import_Exception => Import_Exception : declare
9109 Args : Args_List (1 .. 4);
9110 Names : constant Name_List (1 .. 4) := (
9116 Internal : Node_Id renames Args (1);
9117 External : Node_Id renames Args (2);
9118 Form : Node_Id renames Args (3);
9119 Code : Node_Id renames Args (4);
9123 Gather_Associations (Names, Args);
9125 if Present (External) and then Present (Code) then
9127 ("cannot give both External and Code options for pragma%");
9130 Process_Extended_Import_Export_Exception_Pragma (
9131 Arg_Internal => Internal,
9132 Arg_External => External,
9136 if not Is_VMS_Exception (Entity (Internal)) then
9137 Set_Imported (Entity (Internal));
9139 end Import_Exception;
9141 ---------------------
9142 -- Import_Function --
9143 ---------------------
9145 -- pragma Import_Function (
9146 -- [Internal =>] LOCAL_NAME,
9147 -- [, [External =>] EXTERNAL_SYMBOL]
9148 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9149 -- [, [Result_Type =>] SUBTYPE_MARK]
9150 -- [, [Mechanism =>] MECHANISM]
9151 -- [, [Result_Mechanism =>] MECHANISM_NAME]
9152 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9154 -- EXTERNAL_SYMBOL ::=
9156 -- | static_string_EXPRESSION
9158 -- PARAMETER_TYPES ::=
9160 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9162 -- TYPE_DESIGNATOR ::=
9164 -- | subtype_Name ' Access
9168 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9170 -- MECHANISM_ASSOCIATION ::=
9171 -- [formal_parameter_NAME =>] MECHANISM_NAME
9173 -- MECHANISM_NAME ::=
9176 -- | Descriptor [([Class =>] CLASS_NAME)]
9178 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9180 when Pragma_Import_Function => Import_Function : declare
9181 Args : Args_List (1 .. 7);
9182 Names : constant Name_List (1 .. 7) := (
9185 Name_Parameter_Types,
9188 Name_Result_Mechanism,
9189 Name_First_Optional_Parameter);
9191 Internal : Node_Id renames Args (1);
9192 External : Node_Id renames Args (2);
9193 Parameter_Types : Node_Id renames Args (3);
9194 Result_Type : Node_Id renames Args (4);
9195 Mechanism : Node_Id renames Args (5);
9196 Result_Mechanism : Node_Id renames Args (6);
9197 First_Optional_Parameter : Node_Id renames Args (7);
9201 Gather_Associations (Names, Args);
9202 Process_Extended_Import_Export_Subprogram_Pragma (
9203 Arg_Internal => Internal,
9204 Arg_External => External,
9205 Arg_Parameter_Types => Parameter_Types,
9206 Arg_Result_Type => Result_Type,
9207 Arg_Mechanism => Mechanism,
9208 Arg_Result_Mechanism => Result_Mechanism,
9209 Arg_First_Optional_Parameter => First_Optional_Parameter);
9210 end Import_Function;
9216 -- pragma Import_Object (
9217 -- [Internal =>] LOCAL_NAME
9218 -- [, [External =>] EXTERNAL_SYMBOL]
9219 -- [, [Size =>] EXTERNAL_SYMBOL]);
9221 -- EXTERNAL_SYMBOL ::=
9223 -- | static_string_EXPRESSION
9225 when Pragma_Import_Object => Import_Object : declare
9226 Args : Args_List (1 .. 3);
9227 Names : constant Name_List (1 .. 3) := (
9232 Internal : Node_Id renames Args (1);
9233 External : Node_Id renames Args (2);
9234 Size : Node_Id renames Args (3);
9238 Gather_Associations (Names, Args);
9239 Process_Extended_Import_Export_Object_Pragma (
9240 Arg_Internal => Internal,
9241 Arg_External => External,
9245 ----------------------
9246 -- Import_Procedure --
9247 ----------------------
9249 -- pragma Import_Procedure (
9250 -- [Internal =>] LOCAL_NAME
9251 -- [, [External =>] EXTERNAL_SYMBOL]
9252 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9253 -- [, [Mechanism =>] MECHANISM]
9254 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9256 -- EXTERNAL_SYMBOL ::=
9258 -- | static_string_EXPRESSION
9260 -- PARAMETER_TYPES ::=
9262 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9264 -- TYPE_DESIGNATOR ::=
9266 -- | subtype_Name ' Access
9270 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9272 -- MECHANISM_ASSOCIATION ::=
9273 -- [formal_parameter_NAME =>] MECHANISM_NAME
9275 -- MECHANISM_NAME ::=
9278 -- | Descriptor [([Class =>] CLASS_NAME)]
9280 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9282 when Pragma_Import_Procedure => Import_Procedure : declare
9283 Args : Args_List (1 .. 5);
9284 Names : constant Name_List (1 .. 5) := (
9287 Name_Parameter_Types,
9289 Name_First_Optional_Parameter);
9291 Internal : Node_Id renames Args (1);
9292 External : Node_Id renames Args (2);
9293 Parameter_Types : Node_Id renames Args (3);
9294 Mechanism : Node_Id renames Args (4);
9295 First_Optional_Parameter : Node_Id renames Args (5);
9299 Gather_Associations (Names, Args);
9300 Process_Extended_Import_Export_Subprogram_Pragma (
9301 Arg_Internal => Internal,
9302 Arg_External => External,
9303 Arg_Parameter_Types => Parameter_Types,
9304 Arg_Mechanism => Mechanism,
9305 Arg_First_Optional_Parameter => First_Optional_Parameter);
9306 end Import_Procedure;
9308 -----------------------------
9309 -- Import_Valued_Procedure --
9310 -----------------------------
9312 -- pragma Import_Valued_Procedure (
9313 -- [Internal =>] LOCAL_NAME
9314 -- [, [External =>] EXTERNAL_SYMBOL]
9315 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9316 -- [, [Mechanism =>] MECHANISM]
9317 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9319 -- EXTERNAL_SYMBOL ::=
9321 -- | static_string_EXPRESSION
9323 -- PARAMETER_TYPES ::=
9325 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9327 -- TYPE_DESIGNATOR ::=
9329 -- | subtype_Name ' Access
9333 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9335 -- MECHANISM_ASSOCIATION ::=
9336 -- [formal_parameter_NAME =>] MECHANISM_NAME
9338 -- MECHANISM_NAME ::=
9341 -- | Descriptor [([Class =>] CLASS_NAME)]
9343 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9345 when Pragma_Import_Valued_Procedure =>
9346 Import_Valued_Procedure : declare
9347 Args : Args_List (1 .. 5);
9348 Names : constant Name_List (1 .. 5) := (
9351 Name_Parameter_Types,
9353 Name_First_Optional_Parameter);
9355 Internal : Node_Id renames Args (1);
9356 External : Node_Id renames Args (2);
9357 Parameter_Types : Node_Id renames Args (3);
9358 Mechanism : Node_Id renames Args (4);
9359 First_Optional_Parameter : Node_Id renames Args (5);
9363 Gather_Associations (Names, Args);
9364 Process_Extended_Import_Export_Subprogram_Pragma (
9365 Arg_Internal => Internal,
9366 Arg_External => External,
9367 Arg_Parameter_Types => Parameter_Types,
9368 Arg_Mechanism => Mechanism,
9369 Arg_First_Optional_Parameter => First_Optional_Parameter);
9370 end Import_Valued_Procedure;
9376 -- pragma Independent (LOCAL_NAME);
9378 when Pragma_Independent => Independent : declare
9385 Check_Ada_83_Warning;
9387 Check_No_Identifiers;
9388 Check_Arg_Count (1);
9389 Check_Arg_Is_Local_Name (Arg1);
9390 E_Id := Get_Pragma_Arg (Arg1);
9392 if Etype (E_Id) = Any_Type then
9397 D := Declaration_Node (E);
9400 -- Check duplicate before we chain ourselves!
9402 Check_Duplicate_Pragma (E);
9404 -- Check appropriate entity
9407 if Rep_Item_Too_Early (E, N)
9409 Rep_Item_Too_Late (E, N)
9413 Check_First_Subtype (Arg1);
9416 elsif K = N_Object_Declaration
9417 or else (K = N_Component_Declaration
9418 and then Original_Record_Component (E) = E)
9420 if Rep_Item_Too_Late (E, N) then
9426 ("inappropriate entity for pragma%", Arg1);
9429 Independence_Checks.Append ((N, E));
9432 ----------------------------
9433 -- Independent_Components --
9434 ----------------------------
9436 -- pragma Atomic_Components (array_LOCAL_NAME);
9438 -- This processing is shared by Volatile_Components
9440 when Pragma_Independent_Components => Independent_Components : declare
9447 Check_Ada_83_Warning;
9449 Check_No_Identifiers;
9450 Check_Arg_Count (1);
9451 Check_Arg_Is_Local_Name (Arg1);
9452 E_Id := Get_Pragma_Arg (Arg1);
9454 if Etype (E_Id) = Any_Type then
9460 -- Check duplicate before we chain ourselves!
9462 Check_Duplicate_Pragma (E);
9464 -- Check appropriate entity
9466 if Rep_Item_Too_Early (E, N)
9468 Rep_Item_Too_Late (E, N)
9473 D := Declaration_Node (E);
9476 if (K = N_Full_Type_Declaration
9477 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9479 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9480 and then Nkind (D) = N_Object_Declaration
9481 and then Nkind (Object_Definition (D)) =
9482 N_Constrained_Array_Definition)
9484 Independence_Checks.Append ((N, E));
9487 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9489 end Independent_Components;
9491 ------------------------
9492 -- Initialize_Scalars --
9493 ------------------------
9495 -- pragma Initialize_Scalars;
9497 when Pragma_Initialize_Scalars =>
9499 Check_Arg_Count (0);
9500 Check_Valid_Configuration_Pragma;
9501 Check_Restriction (No_Initialize_Scalars, N);
9503 -- Initialize_Scalars creates false positives in CodePeer, and
9504 -- incorrect negative results in Alfa mode, so ignore this pragma
9507 if not Restriction_Active (No_Initialize_Scalars)
9508 and then not (CodePeer_Mode or Alfa_Mode)
9510 Init_Or_Norm_Scalars := True;
9511 Initialize_Scalars := True;
9518 -- pragma Inline ( NAME {, NAME} );
9520 when Pragma_Inline =>
9522 -- Pragma is active if inlining option is active
9524 Process_Inline (Inline_Active);
9530 -- pragma Inline_Always ( NAME {, NAME} );
9532 when Pragma_Inline_Always =>
9535 -- Pragma always active unless in CodePeer or Alfa mode, since
9536 -- this causes walk order issues.
9538 if not (CodePeer_Mode or Alfa_Mode) then
9539 Process_Inline (True);
9542 --------------------
9543 -- Inline_Generic --
9544 --------------------
9546 -- pragma Inline_Generic (NAME {, NAME});
9548 when Pragma_Inline_Generic =>
9550 Process_Generic_List;
9552 ----------------------
9553 -- Inspection_Point --
9554 ----------------------
9556 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9558 when Pragma_Inspection_Point => Inspection_Point : declare
9563 if Arg_Count > 0 then
9566 Exp := Get_Pragma_Arg (Arg);
9569 if not Is_Entity_Name (Exp)
9570 or else not Is_Object (Entity (Exp))
9572 Error_Pragma_Arg ("object name required", Arg);
9579 end Inspection_Point;
9585 -- pragma Interface (
9586 -- [ Convention =>] convention_IDENTIFIER,
9587 -- [ Entity =>] local_NAME
9588 -- [, [External_Name =>] static_string_EXPRESSION ]
9589 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9591 when Pragma_Interface =>
9598 Check_At_Least_N_Arguments (2);
9599 Check_At_Most_N_Arguments (4);
9600 Process_Import_Or_Interface;
9602 -- In Ada 2005, the permission to use Interface (a reserved word)
9603 -- as a pragma name is considered an obsolescent feature.
9605 if Ada_Version >= Ada_2005 then
9607 (No_Obsolescent_Features, Pragma_Identifier (N));
9610 --------------------
9611 -- Interface_Name --
9612 --------------------
9614 -- pragma Interface_Name (
9615 -- [ Entity =>] local_NAME
9616 -- [,[External_Name =>] static_string_EXPRESSION ]
9617 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9619 when Pragma_Interface_Name => Interface_Name : declare
9628 ((Name_Entity, Name_External_Name, Name_Link_Name));
9629 Check_At_Least_N_Arguments (2);
9630 Check_At_Most_N_Arguments (3);
9631 Id := Get_Pragma_Arg (Arg1);
9634 if not Is_Entity_Name (Id) then
9636 ("first argument for pragma% must be entity name", Arg1);
9637 elsif Etype (Id) = Any_Type then
9640 Def_Id := Entity (Id);
9643 -- Special DEC-compatible processing for the object case, forces
9644 -- object to be imported.
9646 if Ekind (Def_Id) = E_Variable then
9647 Kill_Size_Check_Code (Def_Id);
9648 Note_Possible_Modification (Id, Sure => False);
9650 -- Initialization is not allowed for imported variable
9652 if Present (Expression (Parent (Def_Id)))
9653 and then Comes_From_Source (Expression (Parent (Def_Id)))
9655 Error_Msg_Sloc := Sloc (Def_Id);
9657 ("no initialization allowed for declaration of& #",
9661 -- For compatibility, support VADS usage of providing both
9662 -- pragmas Interface and Interface_Name to obtain the effect
9663 -- of a single Import pragma.
9665 if Is_Imported (Def_Id)
9666 and then Present (First_Rep_Item (Def_Id))
9667 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9669 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9673 Set_Imported (Def_Id);
9676 Set_Is_Public (Def_Id);
9677 Process_Interface_Name (Def_Id, Arg2, Arg3);
9680 -- Otherwise must be subprogram
9682 elsif not Is_Subprogram (Def_Id) then
9684 ("argument of pragma% is not subprogram", Arg1);
9687 Check_At_Most_N_Arguments (3);
9691 -- Loop through homonyms
9694 Def_Id := Get_Base_Subprogram (Hom_Id);
9696 if Is_Imported (Def_Id) then
9697 Process_Interface_Name (Def_Id, Arg2, Arg3);
9701 exit when From_Aspect_Specification (N);
9702 Hom_Id := Homonym (Hom_Id);
9704 exit when No (Hom_Id)
9705 or else Scope (Hom_Id) /= Current_Scope;
9710 ("argument of pragma% is not imported subprogram",
9716 -----------------------
9717 -- Interrupt_Handler --
9718 -----------------------
9720 -- pragma Interrupt_Handler (handler_NAME);
9722 when Pragma_Interrupt_Handler =>
9723 Check_Ada_83_Warning;
9724 Check_Arg_Count (1);
9725 Check_No_Identifiers;
9727 if No_Run_Time_Mode then
9728 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9730 Check_Interrupt_Or_Attach_Handler;
9731 Process_Interrupt_Or_Attach_Handler;
9734 ------------------------
9735 -- Interrupt_Priority --
9736 ------------------------
9738 -- pragma Interrupt_Priority [(EXPRESSION)];
9740 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9741 P : constant Node_Id := Parent (N);
9745 Check_Ada_83_Warning;
9747 if Arg_Count /= 0 then
9748 Arg := Get_Pragma_Arg (Arg1);
9749 Check_Arg_Count (1);
9750 Check_No_Identifiers;
9752 -- The expression must be analyzed in the special manner
9753 -- described in "Handling of Default and Per-Object
9754 -- Expressions" in sem.ads.
9756 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9759 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9763 elsif Has_Pragma_Priority (P) then
9764 Error_Pragma ("duplicate pragma% not allowed");
9767 Set_Has_Pragma_Priority (P, True);
9768 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9770 end Interrupt_Priority;
9772 ---------------------
9773 -- Interrupt_State --
9774 ---------------------
9776 -- pragma Interrupt_State (
9777 -- [Name =>] INTERRUPT_ID,
9778 -- [State =>] INTERRUPT_STATE);
9780 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9781 -- INTERRUPT_STATE => System | Runtime | User
9783 -- Note: if the interrupt id is given as an identifier, then it must
9784 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9785 -- given as a static integer expression which must be in the range of
9786 -- Ada.Interrupts.Interrupt_ID.
9788 when Pragma_Interrupt_State => Interrupt_State : declare
9790 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9791 -- This is the entity Ada.Interrupts.Interrupt_ID;
9793 State_Type : Character;
9794 -- Set to 's'/'r'/'u' for System/Runtime/User
9797 -- Index to entry in Interrupt_States table
9800 -- Value of interrupt
9802 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9803 -- The first argument to the pragma
9805 Int_Ent : Entity_Id;
9806 -- Interrupt entity in Ada.Interrupts.Names
9810 Check_Arg_Order ((Name_Name, Name_State));
9811 Check_Arg_Count (2);
9813 Check_Optional_Identifier (Arg1, Name_Name);
9814 Check_Optional_Identifier (Arg2, Name_State);
9815 Check_Arg_Is_Identifier (Arg2);
9817 -- First argument is identifier
9819 if Nkind (Arg1X) = N_Identifier then
9821 -- Search list of names in Ada.Interrupts.Names
9823 Int_Ent := First_Entity (RTE (RE_Names));
9825 if No (Int_Ent) then
9826 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9828 elsif Chars (Int_Ent) = Chars (Arg1X) then
9829 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9833 Next_Entity (Int_Ent);
9836 -- First argument is not an identifier, so it must be a static
9837 -- expression of type Ada.Interrupts.Interrupt_ID.
9840 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9841 Int_Val := Expr_Value (Arg1X);
9843 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9845 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9848 ("value not in range of type " &
9849 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9855 case Chars (Get_Pragma_Arg (Arg2)) is
9856 when Name_Runtime => State_Type := 'r';
9857 when Name_System => State_Type := 's';
9858 when Name_User => State_Type := 'u';
9861 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9864 -- Check if entry is already stored
9866 IST_Num := Interrupt_States.First;
9868 -- If entry not found, add it
9870 if IST_Num > Interrupt_States.Last then
9871 Interrupt_States.Append
9872 ((Interrupt_Number => UI_To_Int (Int_Val),
9873 Interrupt_State => State_Type,
9874 Pragma_Loc => Loc));
9877 -- Case of entry for the same entry
9879 elsif Int_Val = Interrupt_States.Table (IST_Num).
9882 -- If state matches, done, no need to make redundant entry
9885 State_Type = Interrupt_States.Table (IST_Num).
9888 -- Otherwise if state does not match, error
9891 Interrupt_States.Table (IST_Num).Pragma_Loc;
9893 ("state conflicts with that given #", Arg2);
9897 IST_Num := IST_Num + 1;
9899 end Interrupt_State;
9906 -- ([Entity =>] type_LOCAL_NAME,
9907 -- [Check =>] EXPRESSION
9908 -- [,[Message =>] String_Expression]);
9910 when Pragma_Invariant => Invariant : declare
9915 pragma Unreferenced (Discard);
9919 Check_At_Least_N_Arguments (2);
9920 Check_At_Most_N_Arguments (3);
9921 Check_Optional_Identifier (Arg1, Name_Entity);
9922 Check_Optional_Identifier (Arg2, Name_Check);
9924 if Arg_Count = 3 then
9925 Check_Optional_Identifier (Arg3, Name_Message);
9926 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9929 Check_Arg_Is_Local_Name (Arg1);
9931 Type_Id := Get_Pragma_Arg (Arg1);
9932 Find_Type (Type_Id);
9933 Typ := Entity (Type_Id);
9935 if Typ = Any_Type then
9938 elsif not Ekind_In (Typ, E_Private_Type,
9939 E_Record_Type_With_Private,
9940 E_Limited_Private_Type)
9943 ("pragma% only allowed for private type", Arg1);
9946 -- Note that the type has at least one invariant, and also that
9947 -- it has inheritable invariants if we have Invariant'Class.
9949 Set_Has_Invariants (Typ);
9951 if Class_Present (N) then
9952 Set_Has_Inheritable_Invariants (Typ);
9955 -- The remaining processing is simply to link the pragma on to
9956 -- the rep item chain, for processing when the type is frozen.
9957 -- This is accomplished by a call to Rep_Item_Too_Late.
9959 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9962 ----------------------
9963 -- Java_Constructor --
9964 ----------------------
9966 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9968 -- Also handles pragma CIL_Constructor
9970 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9971 Java_Constructor : declare
9972 Convention : Convention_Id;
9976 This_Formal : Entity_Id;
9980 Check_Arg_Count (1);
9981 Check_Optional_Identifier (Arg1, Name_Entity);
9982 Check_Arg_Is_Local_Name (Arg1);
9984 Id := Get_Pragma_Arg (Arg1);
9985 Find_Program_Unit_Name (Id);
9987 -- If we did not find the name, we are done
9989 if Etype (Id) = Any_Type then
9993 -- Check wrong use of pragma in wrong VM target
9995 if VM_Target = No_VM then
9998 elsif VM_Target = CLI_Target
9999 and then Prag_Id = Pragma_Java_Constructor
10001 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10003 elsif VM_Target = JVM_Target
10004 and then Prag_Id = Pragma_CIL_Constructor
10006 Error_Pragma ("must use pragma 'Java_'Constructor");
10010 when Pragma_CIL_Constructor => Convention := Convention_CIL;
10011 when Pragma_Java_Constructor => Convention := Convention_Java;
10012 when others => null;
10015 Hom_Id := Entity (Id);
10017 -- Loop through homonyms
10020 Def_Id := Get_Base_Subprogram (Hom_Id);
10022 -- The constructor is required to be a function
10024 if Ekind (Def_Id) /= E_Function then
10025 if VM_Target = JVM_Target then
10027 ("pragma% requires function returning a " &
10028 "'Java access type", Def_Id);
10031 ("pragma% requires function returning a " &
10032 "'C'I'L access type", Def_Id);
10036 -- Check arguments: For tagged type the first formal must be
10037 -- named "this" and its type must be a named access type
10038 -- designating a class-wide tagged type that has convention
10039 -- CIL/Java. The first formal must also have a null default
10040 -- value. For example:
10042 -- type Typ is tagged ...
10043 -- type Ref is access all Typ;
10044 -- pragma Convention (CIL, Typ);
10046 -- function New_Typ (This : Ref) return Ref;
10047 -- function New_Typ (This : Ref; I : Integer) return Ref;
10048 -- pragma Cil_Constructor (New_Typ);
10050 -- Reason: The first formal must NOT be a primitive of the
10053 -- This rule also applies to constructors of delegates used
10054 -- to interface with standard target libraries. For example:
10056 -- type Delegate is access procedure ...
10057 -- pragma Import (CIL, Delegate, ...);
10059 -- function new_Delegate
10060 -- (This : Delegate := null; ... ) return Delegate;
10062 -- For value-types this rule does not apply.
10064 if not Is_Value_Type (Etype (Def_Id)) then
10065 if No (First_Formal (Def_Id)) then
10066 Error_Msg_Name_1 := Pname;
10067 Error_Msg_N ("% function must have parameters", Def_Id);
10071 -- In the JRE library we have several occurrences in which
10072 -- the "this" parameter is not the first formal.
10074 This_Formal := First_Formal (Def_Id);
10076 -- In the JRE library we have several occurrences in which
10077 -- the "this" parameter is not the first formal. Search for
10080 if VM_Target = JVM_Target then
10081 while Present (This_Formal)
10082 and then Get_Name_String (Chars (This_Formal)) /= "this"
10084 Next_Formal (This_Formal);
10087 if No (This_Formal) then
10088 This_Formal := First_Formal (Def_Id);
10092 -- Warning: The first parameter should be named "this".
10093 -- We temporarily allow it because we have the following
10094 -- case in the Java runtime (file s-osinte.ads) ???
10096 -- function new_Thread
10097 -- (Self_Id : System.Address) return Thread_Id;
10098 -- pragma Java_Constructor (new_Thread);
10100 if VM_Target = JVM_Target
10101 and then Get_Name_String (Chars (First_Formal (Def_Id)))
10103 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10107 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10108 Error_Msg_Name_1 := Pname;
10110 ("first formal of % function must be named `this`",
10111 Parent (This_Formal));
10113 elsif not Is_Access_Type (Etype (This_Formal)) then
10114 Error_Msg_Name_1 := Pname;
10116 ("first formal of % function must be an access type",
10117 Parameter_Type (Parent (This_Formal)));
10119 -- For delegates the type of the first formal must be a
10120 -- named access-to-subprogram type (see previous example)
10122 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10123 and then Ekind (Etype (This_Formal))
10124 /= E_Access_Subprogram_Type
10126 Error_Msg_Name_1 := Pname;
10128 ("first formal of % function must be a named access" &
10129 " to subprogram type",
10130 Parameter_Type (Parent (This_Formal)));
10132 -- Warning: We should reject anonymous access types because
10133 -- the constructor must not be handled as a primitive of the
10134 -- tagged type. We temporarily allow it because this profile
10135 -- is currently generated by cil2ada???
10137 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10138 and then not Ekind_In (Etype (This_Formal),
10140 E_General_Access_Type,
10141 E_Anonymous_Access_Type)
10143 Error_Msg_Name_1 := Pname;
10145 ("first formal of % function must be a named access" &
10147 Parameter_Type (Parent (This_Formal)));
10149 elsif Atree.Convention
10150 (Designated_Type (Etype (This_Formal))) /= Convention
10152 Error_Msg_Name_1 := Pname;
10154 if Convention = Convention_Java then
10156 ("pragma% requires convention 'Cil in designated" &
10158 Parameter_Type (Parent (This_Formal)));
10161 ("pragma% requires convention 'Java in designated" &
10163 Parameter_Type (Parent (This_Formal)));
10166 elsif No (Expression (Parent (This_Formal)))
10167 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10169 Error_Msg_Name_1 := Pname;
10171 ("pragma% requires first formal with default `null`",
10172 Parameter_Type (Parent (This_Formal)));
10176 -- Check result type: the constructor must be a function
10178 -- * a value type (only allowed in the CIL compiler)
10179 -- * an access-to-subprogram type with convention Java/CIL
10180 -- * an access-type designating a type that has convention
10183 if Is_Value_Type (Etype (Def_Id)) then
10186 -- Access-to-subprogram type with convention Java/CIL
10188 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10189 if Atree.Convention (Etype (Def_Id)) /= Convention then
10190 if Convention = Convention_Java then
10192 ("pragma% requires function returning a " &
10193 "'Java access type", Arg1);
10195 pragma Assert (Convention = Convention_CIL);
10197 ("pragma% requires function returning a " &
10198 "'C'I'L access type", Arg1);
10202 elsif Ekind (Etype (Def_Id)) in Access_Kind then
10203 if not Ekind_In (Etype (Def_Id), E_Access_Type,
10204 E_General_Access_Type)
10207 (Designated_Type (Etype (Def_Id))) /= Convention
10209 Error_Msg_Name_1 := Pname;
10211 if Convention = Convention_Java then
10213 ("pragma% requires function returning a named" &
10214 "'Java access type", Arg1);
10217 ("pragma% requires function returning a named" &
10218 "'C'I'L access type", Arg1);
10223 Set_Is_Constructor (Def_Id);
10224 Set_Convention (Def_Id, Convention);
10225 Set_Is_Imported (Def_Id);
10227 exit when From_Aspect_Specification (N);
10228 Hom_Id := Homonym (Hom_Id);
10230 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10232 end Java_Constructor;
10234 ----------------------
10235 -- Java_Interface --
10236 ----------------------
10238 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
10240 when Pragma_Java_Interface => Java_Interface : declare
10246 Check_Arg_Count (1);
10247 Check_Optional_Identifier (Arg1, Name_Entity);
10248 Check_Arg_Is_Local_Name (Arg1);
10250 Arg := Get_Pragma_Arg (Arg1);
10253 if Etype (Arg) = Any_Type then
10257 if not Is_Entity_Name (Arg)
10258 or else not Is_Type (Entity (Arg))
10260 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10263 Typ := Underlying_Type (Entity (Arg));
10265 -- For now simply check some of the semantic constraints on the
10266 -- type. This currently leaves out some restrictions on interface
10267 -- types, namely that the parent type must be java.lang.Object.Typ
10268 -- and that all primitives of the type should be declared
10271 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10272 Error_Pragma_Arg ("pragma% requires an abstract "
10273 & "tagged type", Arg1);
10275 elsif not Has_Discriminants (Typ)
10276 or else Ekind (Etype (First_Discriminant (Typ)))
10277 /= E_Anonymous_Access_Type
10279 not Is_Class_Wide_Type
10280 (Designated_Type (Etype (First_Discriminant (Typ))))
10283 ("type must have a class-wide access discriminant", Arg1);
10285 end Java_Interface;
10291 -- pragma Keep_Names ([On => ] local_NAME);
10293 when Pragma_Keep_Names => Keep_Names : declare
10298 Check_Arg_Count (1);
10299 Check_Optional_Identifier (Arg1, Name_On);
10300 Check_Arg_Is_Local_Name (Arg1);
10302 Arg := Get_Pragma_Arg (Arg1);
10305 if Etype (Arg) = Any_Type then
10309 if not Is_Entity_Name (Arg)
10310 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10313 ("pragma% requires a local enumeration type", Arg1);
10316 Set_Discard_Names (Entity (Arg), False);
10323 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10325 when Pragma_License =>
10327 Check_Arg_Count (1);
10328 Check_No_Identifiers;
10329 Check_Valid_Configuration_Pragma;
10330 Check_Arg_Is_Identifier (Arg1);
10333 Sind : constant Source_File_Index :=
10334 Source_Index (Current_Sem_Unit);
10337 case Chars (Get_Pragma_Arg (Arg1)) is
10339 Set_License (Sind, GPL);
10341 when Name_Modified_GPL =>
10342 Set_License (Sind, Modified_GPL);
10344 when Name_Restricted =>
10345 Set_License (Sind, Restricted);
10347 when Name_Unrestricted =>
10348 Set_License (Sind, Unrestricted);
10351 Error_Pragma_Arg ("invalid license name", Arg1);
10359 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10361 when Pragma_Link_With => Link_With : declare
10367 if Operating_Mode = Generate_Code
10368 and then In_Extended_Main_Source_Unit (N)
10370 Check_At_Least_N_Arguments (1);
10371 Check_No_Identifiers;
10372 Check_Is_In_Decl_Part_Or_Package_Spec;
10373 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10377 while Present (Arg) loop
10378 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10380 -- Store argument, converting sequences of spaces to a
10381 -- single null character (this is one of the differences
10382 -- in processing between Link_With and Linker_Options).
10384 Arg_Store : declare
10385 C : constant Char_Code := Get_Char_Code (' ');
10386 S : constant String_Id :=
10387 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10388 L : constant Nat := String_Length (S);
10391 procedure Skip_Spaces;
10392 -- Advance F past any spaces
10398 procedure Skip_Spaces is
10400 while F <= L and then Get_String_Char (S, F) = C loop
10405 -- Start of processing for Arg_Store
10408 Skip_Spaces; -- skip leading spaces
10410 -- Loop through characters, changing any embedded
10411 -- sequence of spaces to a single null character (this
10412 -- is how Link_With/Linker_Options differ)
10415 if Get_String_Char (S, F) = C then
10418 Store_String_Char (ASCII.NUL);
10421 Store_String_Char (Get_String_Char (S, F));
10429 if Present (Arg) then
10430 Store_String_Char (ASCII.NUL);
10434 Store_Linker_Option_String (End_String);
10442 -- pragma Linker_Alias (
10443 -- [Entity =>] LOCAL_NAME
10444 -- [Target =>] static_string_EXPRESSION);
10446 when Pragma_Linker_Alias =>
10448 Check_Arg_Order ((Name_Entity, Name_Target));
10449 Check_Arg_Count (2);
10450 Check_Optional_Identifier (Arg1, Name_Entity);
10451 Check_Optional_Identifier (Arg2, Name_Target);
10452 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10453 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10455 -- The only processing required is to link this item on to the
10456 -- list of rep items for the given entity. This is accomplished
10457 -- by the call to Rep_Item_Too_Late (when no error is detected
10458 -- and False is returned).
10460 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10463 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10466 ------------------------
10467 -- Linker_Constructor --
10468 ------------------------
10470 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10472 -- Code is shared with Linker_Destructor
10474 -----------------------
10475 -- Linker_Destructor --
10476 -----------------------
10478 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10480 when Pragma_Linker_Constructor |
10481 Pragma_Linker_Destructor =>
10482 Linker_Constructor : declare
10488 Check_Arg_Count (1);
10489 Check_No_Identifiers;
10490 Check_Arg_Is_Local_Name (Arg1);
10491 Arg1_X := Get_Pragma_Arg (Arg1);
10493 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10495 if not Is_Library_Level_Entity (Proc) then
10497 ("argument for pragma% must be library level entity", Arg1);
10500 -- The only processing required is to link this item on to the
10501 -- list of rep items for the given entity. This is accomplished
10502 -- by the call to Rep_Item_Too_Late (when no error is detected
10503 -- and False is returned).
10505 if Rep_Item_Too_Late (Proc, N) then
10508 Set_Has_Gigi_Rep_Item (Proc);
10510 end Linker_Constructor;
10512 --------------------
10513 -- Linker_Options --
10514 --------------------
10516 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10518 when Pragma_Linker_Options => Linker_Options : declare
10522 Check_Ada_83_Warning;
10523 Check_No_Identifiers;
10524 Check_Arg_Count (1);
10525 Check_Is_In_Decl_Part_Or_Package_Spec;
10526 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10527 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10530 while Present (Arg) loop
10531 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10532 Store_String_Char (ASCII.NUL);
10534 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10538 if Operating_Mode = Generate_Code
10539 and then In_Extended_Main_Source_Unit (N)
10541 Store_Linker_Option_String (End_String);
10543 end Linker_Options;
10545 --------------------
10546 -- Linker_Section --
10547 --------------------
10549 -- pragma Linker_Section (
10550 -- [Entity =>] LOCAL_NAME
10551 -- [Section =>] static_string_EXPRESSION);
10553 when Pragma_Linker_Section =>
10555 Check_Arg_Order ((Name_Entity, Name_Section));
10556 Check_Arg_Count (2);
10557 Check_Optional_Identifier (Arg1, Name_Entity);
10558 Check_Optional_Identifier (Arg2, Name_Section);
10559 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10560 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10562 -- This pragma applies only to objects
10564 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10565 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10568 -- The only processing required is to link this item on to the
10569 -- list of rep items for the given entity. This is accomplished
10570 -- by the call to Rep_Item_Too_Late (when no error is detected
10571 -- and False is returned).
10573 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10576 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10583 -- pragma List (On | Off)
10585 -- There is nothing to do here, since we did all the processing for
10586 -- this pragma in Par.Prag (so that it works properly even in syntax
10589 when Pragma_List =>
10592 --------------------
10593 -- Locking_Policy --
10594 --------------------
10596 -- pragma Locking_Policy (policy_IDENTIFIER);
10598 when Pragma_Locking_Policy => declare
10602 Check_Ada_83_Warning;
10603 Check_Arg_Count (1);
10604 Check_No_Identifiers;
10605 Check_Arg_Is_Locking_Policy (Arg1);
10606 Check_Valid_Configuration_Pragma;
10607 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10608 LP := Fold_Upper (Name_Buffer (1));
10610 if Locking_Policy /= ' '
10611 and then Locking_Policy /= LP
10613 Error_Msg_Sloc := Locking_Policy_Sloc;
10614 Error_Pragma ("locking policy incompatible with policy#");
10616 -- Set new policy, but always preserve System_Location since we
10617 -- like the error message with the run time name.
10620 Locking_Policy := LP;
10622 if Locking_Policy_Sloc /= System_Location then
10623 Locking_Policy_Sloc := Loc;
10632 -- pragma Long_Float (D_Float | G_Float);
10634 when Pragma_Long_Float =>
10636 Check_Valid_Configuration_Pragma;
10637 Check_Arg_Count (1);
10638 Check_No_Identifier (Arg1);
10639 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10641 if not OpenVMS_On_Target then
10642 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10647 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10648 if Opt.Float_Format_Long = 'G' then
10649 Error_Pragma ("G_Float previously specified");
10652 Opt.Float_Format_Long := 'D';
10654 -- G_Float case (this is the default, does not need overriding)
10657 if Opt.Float_Format_Long = 'D' then
10658 Error_Pragma ("D_Float previously specified");
10661 Opt.Float_Format_Long := 'G';
10664 Set_Standard_Fpt_Formats;
10666 -----------------------
10667 -- Machine_Attribute --
10668 -----------------------
10670 -- pragma Machine_Attribute (
10671 -- [Entity =>] LOCAL_NAME,
10672 -- [Attribute_Name =>] static_string_EXPRESSION
10673 -- [, [Info =>] static_EXPRESSION] );
10675 when Pragma_Machine_Attribute => Machine_Attribute : declare
10676 Def_Id : Entity_Id;
10680 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10682 if Arg_Count = 3 then
10683 Check_Optional_Identifier (Arg3, Name_Info);
10684 Check_Arg_Is_Static_Expression (Arg3);
10686 Check_Arg_Count (2);
10689 Check_Optional_Identifier (Arg1, Name_Entity);
10690 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10691 Check_Arg_Is_Local_Name (Arg1);
10692 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10693 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10695 if Is_Access_Type (Def_Id) then
10696 Def_Id := Designated_Type (Def_Id);
10699 if Rep_Item_Too_Early (Def_Id, N) then
10703 Def_Id := Underlying_Type (Def_Id);
10705 -- The only processing required is to link this item on to the
10706 -- list of rep items for the given entity. This is accomplished
10707 -- by the call to Rep_Item_Too_Late (when no error is detected
10708 -- and False is returned).
10710 if Rep_Item_Too_Late (Def_Id, N) then
10713 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10715 end Machine_Attribute;
10722 -- (MAIN_OPTION [, MAIN_OPTION]);
10725 -- [STACK_SIZE =>] static_integer_EXPRESSION
10726 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10727 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10729 when Pragma_Main => Main : declare
10730 Args : Args_List (1 .. 3);
10731 Names : constant Name_List (1 .. 3) := (
10733 Name_Task_Stack_Size_Default,
10734 Name_Time_Slicing_Enabled);
10740 Gather_Associations (Names, Args);
10742 for J in 1 .. 2 loop
10743 if Present (Args (J)) then
10744 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10748 if Present (Args (3)) then
10749 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10753 while Present (Nod) loop
10754 if Nkind (Nod) = N_Pragma
10755 and then Pragma_Name (Nod) = Name_Main
10757 Error_Msg_Name_1 := Pname;
10758 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10769 -- pragma Main_Storage
10770 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10772 -- MAIN_STORAGE_OPTION ::=
10773 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10774 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10776 when Pragma_Main_Storage => Main_Storage : declare
10777 Args : Args_List (1 .. 2);
10778 Names : constant Name_List (1 .. 2) := (
10779 Name_Working_Storage,
10786 Gather_Associations (Names, Args);
10788 for J in 1 .. 2 loop
10789 if Present (Args (J)) then
10790 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10794 Check_In_Main_Program;
10797 while Present (Nod) loop
10798 if Nkind (Nod) = N_Pragma
10799 and then Pragma_Name (Nod) = Name_Main_Storage
10801 Error_Msg_Name_1 := Pname;
10802 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10813 -- pragma Memory_Size (NUMERIC_LITERAL)
10815 when Pragma_Memory_Size =>
10818 -- Memory size is simply ignored
10820 Check_No_Identifiers;
10821 Check_Arg_Count (1);
10822 Check_Arg_Is_Integer_Literal (Arg1);
10830 -- The only correct use of this pragma is on its own in a file, in
10831 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10832 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10833 -- check for a file containing nothing but a No_Body pragma). If we
10834 -- attempt to process it during normal semantics processing, it means
10835 -- it was misplaced.
10837 when Pragma_No_Body =>
10845 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10847 when Pragma_No_Return => No_Return : declare
10855 Check_At_Least_N_Arguments (1);
10857 -- Loop through arguments of pragma
10860 while Present (Arg) loop
10861 Check_Arg_Is_Local_Name (Arg);
10862 Id := Get_Pragma_Arg (Arg);
10865 if not Is_Entity_Name (Id) then
10866 Error_Pragma_Arg ("entity name required", Arg);
10869 if Etype (Id) = Any_Type then
10873 -- Loop to find matching procedures
10878 and then Scope (E) = Current_Scope
10880 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10883 -- Set flag on any alias as well
10885 if Is_Overloadable (E) and then Present (Alias (E)) then
10886 Set_No_Return (Alias (E));
10892 exit when From_Aspect_Specification (N);
10897 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10908 -- pragma No_Run_Time;
10910 -- Note: this pragma is retained for backwards compatibility. See
10911 -- body of Rtsfind for full details on its handling.
10913 when Pragma_No_Run_Time =>
10915 Check_Valid_Configuration_Pragma;
10916 Check_Arg_Count (0);
10918 No_Run_Time_Mode := True;
10919 Configurable_Run_Time_Mode := True;
10921 -- Set Duration to 32 bits if word size is 32
10923 if Ttypes.System_Word_Size = 32 then
10924 Duration_32_Bits_On_Target := True;
10927 -- Set appropriate restrictions
10929 Set_Restriction (No_Finalization, N);
10930 Set_Restriction (No_Exception_Handlers, N);
10931 Set_Restriction (Max_Tasks, N, 0);
10932 Set_Restriction (No_Tasking, N);
10934 ------------------------
10935 -- No_Strict_Aliasing --
10936 ------------------------
10938 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10940 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10945 Check_At_Most_N_Arguments (1);
10947 if Arg_Count = 0 then
10948 Check_Valid_Configuration_Pragma;
10949 Opt.No_Strict_Aliasing := True;
10952 Check_Optional_Identifier (Arg2, Name_Entity);
10953 Check_Arg_Is_Local_Name (Arg1);
10954 E_Id := Entity (Get_Pragma_Arg (Arg1));
10956 if E_Id = Any_Type then
10958 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10959 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10962 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10964 end No_Strict_Aliasing;
10966 -----------------------
10967 -- Normalize_Scalars --
10968 -----------------------
10970 -- pragma Normalize_Scalars;
10972 when Pragma_Normalize_Scalars =>
10973 Check_Ada_83_Warning;
10974 Check_Arg_Count (0);
10975 Check_Valid_Configuration_Pragma;
10977 -- Normalize_Scalars creates false positives in CodePeer, and
10978 -- incorrect negative results in Alfa mode, so ignore this pragma
10981 if not (CodePeer_Mode or Alfa_Mode) then
10982 Normalize_Scalars := True;
10983 Init_Or_Norm_Scalars := True;
10990 -- pragma Obsolescent;
10992 -- pragma Obsolescent (
10993 -- [Message =>] static_string_EXPRESSION
10994 -- [,[Version =>] Ada_05]]);
10996 -- pragma Obsolescent (
10997 -- [Entity =>] NAME
10998 -- [,[Message =>] static_string_EXPRESSION
10999 -- [,[Version =>] Ada_05]] );
11001 when Pragma_Obsolescent => Obsolescent : declare
11005 procedure Set_Obsolescent (E : Entity_Id);
11006 -- Given an entity Ent, mark it as obsolescent if appropriate
11008 ---------------------
11009 -- Set_Obsolescent --
11010 ---------------------
11012 procedure Set_Obsolescent (E : Entity_Id) is
11021 -- Entity name was given
11023 if Present (Ename) then
11025 -- If entity name matches, we are fine. Save entity in
11026 -- pragma argument, for ASIS use.
11028 if Chars (Ename) = Chars (Ent) then
11029 Set_Entity (Ename, Ent);
11030 Generate_Reference (Ent, Ename);
11032 -- If entity name does not match, only possibility is an
11033 -- enumeration literal from an enumeration type declaration.
11035 elsif Ekind (Ent) /= E_Enumeration_Type then
11037 ("pragma % entity name does not match declaration");
11040 Ent := First_Literal (E);
11044 ("pragma % entity name does not match any " &
11045 "enumeration literal");
11047 elsif Chars (Ent) = Chars (Ename) then
11048 Set_Entity (Ename, Ent);
11049 Generate_Reference (Ent, Ename);
11053 Ent := Next_Literal (Ent);
11059 -- Ent points to entity to be marked
11061 if Arg_Count >= 1 then
11063 -- Deal with static string argument
11065 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11066 S := Strval (Get_Pragma_Arg (Arg1));
11068 for J in 1 .. String_Length (S) loop
11069 if not In_Character_Range (Get_String_Char (S, J)) then
11071 ("pragma% argument does not allow wide characters",
11076 Obsolescent_Warnings.Append
11077 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11079 -- Check for Ada_05 parameter
11081 if Arg_Count /= 1 then
11082 Check_Arg_Count (2);
11085 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11088 Check_Arg_Is_Identifier (Argx);
11090 if Chars (Argx) /= Name_Ada_05 then
11091 Error_Msg_Name_2 := Name_Ada_05;
11093 ("only allowed argument for pragma% is %", Argx);
11096 if Ada_Version_Explicit < Ada_2005
11097 or else not Warn_On_Ada_2005_Compatibility
11105 -- Set flag if pragma active
11108 Set_Is_Obsolescent (Ent);
11112 end Set_Obsolescent;
11114 -- Start of processing for pragma Obsolescent
11119 Check_At_Most_N_Arguments (3);
11121 -- See if first argument specifies an entity name
11125 (Chars (Arg1) = Name_Entity
11127 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11129 N_Operator_Symbol))
11131 Ename := Get_Pragma_Arg (Arg1);
11133 -- Eliminate first argument, so we can share processing
11137 Arg_Count := Arg_Count - 1;
11139 -- No Entity name argument given
11145 if Arg_Count >= 1 then
11146 Check_Optional_Identifier (Arg1, Name_Message);
11148 if Arg_Count = 2 then
11149 Check_Optional_Identifier (Arg2, Name_Version);
11153 -- Get immediately preceding declaration
11156 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11160 -- Cases where we do not follow anything other than another pragma
11164 -- First case: library level compilation unit declaration with
11165 -- the pragma immediately following the declaration.
11167 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11169 (Defining_Entity (Unit (Parent (Parent (N)))));
11172 -- Case 2: library unit placement for package
11176 Ent : constant Entity_Id := Find_Lib_Unit_Name;
11178 if Is_Package_Or_Generic_Package (Ent) then
11179 Set_Obsolescent (Ent);
11185 -- Cases where we must follow a declaration
11188 if Nkind (Decl) not in N_Declaration
11189 and then Nkind (Decl) not in N_Later_Decl_Item
11190 and then Nkind (Decl) not in N_Generic_Declaration
11191 and then Nkind (Decl) not in N_Renaming_Declaration
11194 ("pragma% misplaced, "
11195 & "must immediately follow a declaration");
11198 Set_Obsolescent (Defining_Entity (Decl));
11208 -- pragma Optimize (Time | Space | Off);
11210 -- The actual check for optimize is done in Gigi. Note that this
11211 -- pragma does not actually change the optimization setting, it
11212 -- simply checks that it is consistent with the pragma.
11214 when Pragma_Optimize =>
11215 Check_No_Identifiers;
11216 Check_Arg_Count (1);
11217 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11219 ------------------------
11220 -- Optimize_Alignment --
11221 ------------------------
11223 -- pragma Optimize_Alignment (Time | Space | Off);
11225 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11227 Check_No_Identifiers;
11228 Check_Arg_Count (1);
11229 Check_Valid_Configuration_Pragma;
11232 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11236 Opt.Optimize_Alignment := 'T';
11238 Opt.Optimize_Alignment := 'S';
11240 Opt.Optimize_Alignment := 'O';
11242 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11246 -- Set indication that mode is set locally. If we are in fact in a
11247 -- configuration pragma file, this setting is harmless since the
11248 -- switch will get reset anyway at the start of each unit.
11250 Optimize_Alignment_Local := True;
11251 end Optimize_Alignment;
11257 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11259 when Pragma_Ordered => Ordered : declare
11260 Assoc : constant Node_Id := Arg1;
11266 Check_No_Identifiers;
11267 Check_Arg_Count (1);
11268 Check_Arg_Is_Local_Name (Arg1);
11270 Type_Id := Get_Pragma_Arg (Assoc);
11271 Find_Type (Type_Id);
11272 Typ := Entity (Type_Id);
11274 if Typ = Any_Type then
11277 Typ := Underlying_Type (Typ);
11280 if not Is_Enumeration_Type (Typ) then
11281 Error_Pragma ("pragma% must specify enumeration type");
11284 Check_First_Subtype (Arg1);
11285 Set_Has_Pragma_Ordered (Base_Type (Typ));
11292 -- pragma Pack (first_subtype_LOCAL_NAME);
11294 when Pragma_Pack => Pack : declare
11295 Assoc : constant Node_Id := Arg1;
11299 Ignore : Boolean := False;
11302 Check_No_Identifiers;
11303 Check_Arg_Count (1);
11304 Check_Arg_Is_Local_Name (Arg1);
11306 Type_Id := Get_Pragma_Arg (Assoc);
11307 Find_Type (Type_Id);
11308 Typ := Entity (Type_Id);
11311 or else Rep_Item_Too_Early (Typ, N)
11315 Typ := Underlying_Type (Typ);
11318 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11319 Error_Pragma ("pragma% must specify array or record type");
11322 Check_First_Subtype (Arg1);
11323 Check_Duplicate_Pragma (Typ);
11327 if Is_Array_Type (Typ) then
11328 Ctyp := Component_Type (Typ);
11330 -- Ignore pack that does nothing
11332 if Known_Static_Esize (Ctyp)
11333 and then Known_Static_RM_Size (Ctyp)
11334 and then Esize (Ctyp) = RM_Size (Ctyp)
11335 and then Addressable (Esize (Ctyp))
11340 -- Process OK pragma Pack. Note that if there is a separate
11341 -- component clause present, the Pack will be cancelled. This
11342 -- processing is in Freeze.
11344 if not Rep_Item_Too_Late (Typ, N) then
11346 -- In the context of static code analysis, we do not need
11347 -- complex front-end expansions related to pragma Pack,
11348 -- so disable handling of pragma Pack in these cases.
11350 if CodePeer_Mode or Alfa_Mode then
11353 -- Don't attempt any packing for VM targets. We possibly
11354 -- could deal with some cases of array bit-packing, but we
11355 -- don't bother, since this is not a typical kind of
11356 -- representation in the VM context anyway (and would not
11357 -- for example work nicely with the debugger).
11359 elsif VM_Target /= No_VM then
11360 if not GNAT_Mode then
11362 ("?pragma% ignored in this configuration");
11365 -- Normal case where we do the pack action
11369 Set_Is_Packed (Base_Type (Typ));
11370 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11373 Set_Has_Pragma_Pack (Base_Type (Typ));
11377 -- For record types, the pack is always effective
11379 else pragma Assert (Is_Record_Type (Typ));
11380 if not Rep_Item_Too_Late (Typ, N) then
11382 -- Ignore pack request with warning in VM mode (skip warning
11383 -- if we are compiling GNAT run time library).
11385 if VM_Target /= No_VM then
11386 if not GNAT_Mode then
11388 ("?pragma% ignored in this configuration");
11391 -- Normal case of pack request active
11394 Set_Is_Packed (Base_Type (Typ));
11395 Set_Has_Pragma_Pack (Base_Type (Typ));
11396 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11408 -- There is nothing to do here, since we did all the processing for
11409 -- this pragma in Par.Prag (so that it works properly even in syntax
11412 when Pragma_Page =>
11419 -- pragma Passive [(PASSIVE_FORM)];
11421 -- PASSIVE_FORM ::= Semaphore | No
11423 when Pragma_Passive =>
11426 if Nkind (Parent (N)) /= N_Task_Definition then
11427 Error_Pragma ("pragma% must be within task definition");
11430 if Arg_Count /= 0 then
11431 Check_Arg_Count (1);
11432 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11435 ----------------------------------
11436 -- Preelaborable_Initialization --
11437 ----------------------------------
11439 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11441 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11446 Check_Arg_Count (1);
11447 Check_No_Identifiers;
11448 Check_Arg_Is_Identifier (Arg1);
11449 Check_Arg_Is_Local_Name (Arg1);
11450 Check_First_Subtype (Arg1);
11451 Ent := Entity (Get_Pragma_Arg (Arg1));
11453 if not (Is_Private_Type (Ent)
11455 Is_Protected_Type (Ent)
11457 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11460 ("pragma % can only be applied to private, formal derived or "
11461 & "protected type",
11465 -- Give an error if the pragma is applied to a protected type that
11466 -- does not qualify (due to having entries, or due to components
11467 -- that do not qualify).
11469 if Is_Protected_Type (Ent)
11470 and then not Has_Preelaborable_Initialization (Ent)
11473 ("protected type & does not have preelaborable " &
11474 "initialization", Ent);
11476 -- Otherwise mark the type as definitely having preelaborable
11480 Set_Known_To_Have_Preelab_Init (Ent);
11483 if Has_Pragma_Preelab_Init (Ent)
11484 and then Warn_On_Redundant_Constructs
11486 Error_Pragma ("?duplicate pragma%!");
11488 Set_Has_Pragma_Preelab_Init (Ent);
11492 --------------------
11493 -- Persistent_BSS --
11494 --------------------
11496 -- pragma Persistent_BSS [(object_NAME)];
11498 when Pragma_Persistent_BSS => Persistent_BSS : declare
11505 Check_At_Most_N_Arguments (1);
11507 -- Case of application to specific object (one argument)
11509 if Arg_Count = 1 then
11510 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11512 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11514 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11517 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11520 Ent := Entity (Get_Pragma_Arg (Arg1));
11521 Decl := Parent (Ent);
11523 if Rep_Item_Too_Late (Ent, N) then
11527 if Present (Expression (Decl)) then
11529 ("object for pragma% cannot have initialization", Arg1);
11532 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11534 ("object type for pragma% is not potentially persistent",
11538 Check_Duplicate_Pragma (Ent);
11541 Make_Linker_Section_Pragma
11542 (Ent, Sloc (N), ".persistent.bss");
11543 Insert_After (N, Prag);
11546 -- Case of use as configuration pragma with no arguments
11549 Check_Valid_Configuration_Pragma;
11550 Persistent_BSS_Mode := True;
11552 end Persistent_BSS;
11558 -- pragma Polling (ON | OFF);
11560 when Pragma_Polling =>
11562 Check_Arg_Count (1);
11563 Check_No_Identifiers;
11564 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11565 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11567 -------------------
11568 -- Postcondition --
11569 -------------------
11571 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
11572 -- [,[Message =>] String_EXPRESSION]);
11574 when Pragma_Postcondition => Postcondition : declare
11576 pragma Warnings (Off, In_Body);
11580 Check_At_Least_N_Arguments (1);
11581 Check_At_Most_N_Arguments (2);
11582 Check_Optional_Identifier (Arg1, Name_Check);
11584 -- All we need to do here is call the common check procedure,
11585 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11587 Check_Precondition_Postcondition (In_Body);
11594 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
11595 -- [,[Message =>] String_EXPRESSION]);
11597 when Pragma_Precondition => Precondition : declare
11602 Check_At_Least_N_Arguments (1);
11603 Check_At_Most_N_Arguments (2);
11604 Check_Optional_Identifier (Arg1, Name_Check);
11605 Check_Precondition_Postcondition (In_Body);
11607 -- If in spec, nothing more to do. If in body, then we convert the
11608 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11609 -- this whether or not precondition checks are enabled. That works
11610 -- fine since pragma Check will do this check, and will also
11611 -- analyze the condition itself in the proper context.
11616 Chars => Name_Check,
11617 Pragma_Argument_Associations => New_List (
11618 Make_Pragma_Argument_Association (Loc,
11619 Expression => Make_Identifier (Loc, Name_Precondition)),
11621 Make_Pragma_Argument_Association (Sloc (Arg1),
11622 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11624 if Arg_Count = 2 then
11625 Append_To (Pragma_Argument_Associations (N),
11626 Make_Pragma_Argument_Association (Sloc (Arg2),
11627 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11638 -- pragma Predicate
11639 -- ([Entity =>] type_LOCAL_NAME,
11640 -- [Check =>] EXPRESSION);
11642 when Pragma_Predicate => Predicate : declare
11647 pragma Unreferenced (Discard);
11651 Check_Arg_Count (2);
11652 Check_Optional_Identifier (Arg1, Name_Entity);
11653 Check_Optional_Identifier (Arg2, Name_Check);
11655 Check_Arg_Is_Local_Name (Arg1);
11657 Type_Id := Get_Pragma_Arg (Arg1);
11658 Find_Type (Type_Id);
11659 Typ := Entity (Type_Id);
11661 if Typ = Any_Type then
11665 -- The remaining processing is simply to link the pragma on to
11666 -- the rep item chain, for processing when the type is frozen.
11667 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11668 -- mark the type as having predicates.
11670 Set_Has_Predicates (Typ);
11671 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11678 -- pragma Preelaborate [(library_unit_NAME)];
11680 -- Set the flag Is_Preelaborated of program unit name entity
11682 when Pragma_Preelaborate => Preelaborate : declare
11683 Pa : constant Node_Id := Parent (N);
11684 Pk : constant Node_Kind := Nkind (Pa);
11688 Check_Ada_83_Warning;
11689 Check_Valid_Library_Unit_Pragma;
11691 if Nkind (N) = N_Null_Statement then
11695 Ent := Find_Lib_Unit_Name;
11696 Check_Duplicate_Pragma (Ent);
11698 -- This filters out pragmas inside generic parent then
11699 -- show up inside instantiation
11702 and then not (Pk = N_Package_Specification
11703 and then Present (Generic_Parent (Pa)))
11705 if not Debug_Flag_U then
11706 Set_Is_Preelaborated (Ent);
11707 Set_Suppress_Elaboration_Warnings (Ent);
11712 ---------------------
11713 -- Preelaborate_05 --
11714 ---------------------
11716 -- pragma Preelaborate_05 [(library_unit_NAME)];
11718 -- This pragma is useable only in GNAT_Mode, where it is used like
11719 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11720 -- (otherwise it is ignored). This is used to implement AI-362 which
11721 -- recategorizes some run-time packages in Ada 2005 mode.
11723 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11728 Check_Valid_Library_Unit_Pragma;
11730 if not GNAT_Mode then
11731 Error_Pragma ("pragma% only available in GNAT mode");
11734 if Nkind (N) = N_Null_Statement then
11738 -- This is one of the few cases where we need to test the value of
11739 -- Ada_Version_Explicit rather than Ada_Version (which is always
11740 -- set to Ada_2012 in a predefined unit), we need to know the
11741 -- explicit version set to know if this pragma is active.
11743 if Ada_Version_Explicit >= Ada_2005 then
11744 Ent := Find_Lib_Unit_Name;
11745 Set_Is_Preelaborated (Ent);
11746 Set_Suppress_Elaboration_Warnings (Ent);
11748 end Preelaborate_05;
11754 -- pragma Priority (EXPRESSION);
11756 when Pragma_Priority => Priority : declare
11757 P : constant Node_Id := Parent (N);
11761 Check_No_Identifiers;
11762 Check_Arg_Count (1);
11766 if Nkind (P) = N_Subprogram_Body then
11767 Check_In_Main_Program;
11769 Arg := Get_Pragma_Arg (Arg1);
11770 Analyze_And_Resolve (Arg, Standard_Integer);
11774 if not Is_Static_Expression (Arg) then
11775 Flag_Non_Static_Expr
11776 ("main subprogram priority is not static!", Arg);
11779 -- If constraint error, then we already signalled an error
11781 elsif Raises_Constraint_Error (Arg) then
11784 -- Otherwise check in range
11788 Val : constant Uint := Expr_Value (Arg);
11792 or else Val > Expr_Value (Expression
11793 (Parent (RTE (RE_Max_Priority))))
11796 ("main subprogram priority is out of range", Arg1);
11802 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11804 -- Load an arbitrary entity from System.Tasking to make sure
11805 -- this package is implicitly with'ed, since we need to have
11806 -- the tasking run-time active for the pragma Priority to have
11810 Discard : Entity_Id;
11811 pragma Warnings (Off, Discard);
11813 Discard := RTE (RE_Task_List);
11816 -- Task or Protected, must be of type Integer
11818 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11819 Arg := Get_Pragma_Arg (Arg1);
11821 -- The expression must be analyzed in the special manner
11822 -- described in "Handling of Default and Per-Object
11823 -- Expressions" in sem.ads.
11825 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11827 if not Is_Static_Expression (Arg) then
11828 Check_Restriction (Static_Priorities, Arg);
11831 -- Anything else is incorrect
11837 if Has_Pragma_Priority (P) then
11838 Error_Pragma ("duplicate pragma% not allowed");
11840 Set_Has_Pragma_Priority (P, True);
11842 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11843 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11844 -- exp_ch9 should use this ???
11849 -----------------------------------
11850 -- Priority_Specific_Dispatching --
11851 -----------------------------------
11853 -- pragma Priority_Specific_Dispatching (
11854 -- policy_IDENTIFIER,
11855 -- first_priority_EXPRESSION,
11856 -- last_priority_EXPRESSION);
11858 when Pragma_Priority_Specific_Dispatching =>
11859 Priority_Specific_Dispatching : declare
11860 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11861 -- This is the entity System.Any_Priority;
11864 Lower_Bound : Node_Id;
11865 Upper_Bound : Node_Id;
11871 Check_Arg_Count (3);
11872 Check_No_Identifiers;
11873 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11874 Check_Valid_Configuration_Pragma;
11875 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11876 DP := Fold_Upper (Name_Buffer (1));
11878 Lower_Bound := Get_Pragma_Arg (Arg2);
11879 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11880 Lower_Val := Expr_Value (Lower_Bound);
11882 Upper_Bound := Get_Pragma_Arg (Arg3);
11883 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11884 Upper_Val := Expr_Value (Upper_Bound);
11886 -- It is not allowed to use Task_Dispatching_Policy and
11887 -- Priority_Specific_Dispatching in the same partition.
11889 if Task_Dispatching_Policy /= ' ' then
11890 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11892 ("pragma% incompatible with Task_Dispatching_Policy#");
11894 -- Check lower bound in range
11896 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11898 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11901 ("first_priority is out of range", Arg2);
11903 -- Check upper bound in range
11905 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11907 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11910 ("last_priority is out of range", Arg3);
11912 -- Check that the priority range is valid
11914 elsif Lower_Val > Upper_Val then
11916 ("last_priority_expression must be greater than" &
11917 " or equal to first_priority_expression");
11919 -- Store the new policy, but always preserve System_Location since
11920 -- we like the error message with the run-time name.
11923 -- Check overlapping in the priority ranges specified in other
11924 -- Priority_Specific_Dispatching pragmas within the same
11925 -- partition. We can only check those we know about!
11928 Specific_Dispatching.First .. Specific_Dispatching.Last
11930 if Specific_Dispatching.Table (J).First_Priority in
11931 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11932 or else Specific_Dispatching.Table (J).Last_Priority in
11933 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11936 Specific_Dispatching.Table (J).Pragma_Loc;
11938 ("priority range overlaps with "
11939 & "Priority_Specific_Dispatching#");
11943 -- The use of Priority_Specific_Dispatching is incompatible
11944 -- with Task_Dispatching_Policy.
11946 if Task_Dispatching_Policy /= ' ' then
11947 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11949 ("Priority_Specific_Dispatching incompatible "
11950 & "with Task_Dispatching_Policy#");
11953 -- The use of Priority_Specific_Dispatching forces ceiling
11956 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11957 Error_Msg_Sloc := Locking_Policy_Sloc;
11959 ("Priority_Specific_Dispatching incompatible "
11960 & "with Locking_Policy#");
11962 -- Set the Ceiling_Locking policy, but preserve System_Location
11963 -- since we like the error message with the run time name.
11966 Locking_Policy := 'C';
11968 if Locking_Policy_Sloc /= System_Location then
11969 Locking_Policy_Sloc := Loc;
11973 -- Add entry in the table
11975 Specific_Dispatching.Append
11976 ((Dispatching_Policy => DP,
11977 First_Priority => UI_To_Int (Lower_Val),
11978 Last_Priority => UI_To_Int (Upper_Val),
11979 Pragma_Loc => Loc));
11981 end Priority_Specific_Dispatching;
11987 -- pragma Profile (profile_IDENTIFIER);
11989 -- profile_IDENTIFIER => Restricted | Ravenscar
11991 when Pragma_Profile =>
11993 Check_Arg_Count (1);
11994 Check_Valid_Configuration_Pragma;
11995 Check_No_Identifiers;
11998 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12000 if Chars (Argx) = Name_Ravenscar then
12001 Set_Ravenscar_Profile (N);
12002 elsif Chars (Argx) = Name_Restricted then
12003 Set_Profile_Restrictions
12004 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12006 Error_Pragma_Arg ("& is not a valid profile", Argx);
12010 ----------------------
12011 -- Profile_Warnings --
12012 ----------------------
12014 -- pragma Profile_Warnings (profile_IDENTIFIER);
12016 -- profile_IDENTIFIER => Restricted | Ravenscar
12018 when Pragma_Profile_Warnings =>
12020 Check_Arg_Count (1);
12021 Check_Valid_Configuration_Pragma;
12022 Check_No_Identifiers;
12025 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12027 if Chars (Argx) = Name_Ravenscar then
12028 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
12029 elsif Chars (Argx) = Name_Restricted then
12030 Set_Profile_Restrictions (Restricted, N, Warn => True);
12032 Error_Pragma_Arg ("& is not a valid profile", Argx);
12036 --------------------------
12037 -- Propagate_Exceptions --
12038 --------------------------
12040 -- pragma Propagate_Exceptions;
12042 -- Note: this pragma is obsolete and has no effect
12044 when Pragma_Propagate_Exceptions =>
12046 Check_Arg_Count (0);
12048 if In_Extended_Main_Source_Unit (N) then
12049 Propagate_Exceptions := True;
12056 -- pragma Psect_Object (
12057 -- [Internal =>] LOCAL_NAME,
12058 -- [, [External =>] EXTERNAL_SYMBOL]
12059 -- [, [Size =>] EXTERNAL_SYMBOL]);
12061 when Pragma_Psect_Object | Pragma_Common_Object =>
12062 Psect_Object : declare
12063 Args : Args_List (1 .. 3);
12064 Names : constant Name_List (1 .. 3) := (
12069 Internal : Node_Id renames Args (1);
12070 External : Node_Id renames Args (2);
12071 Size : Node_Id renames Args (3);
12073 Def_Id : Entity_Id;
12075 procedure Check_Too_Long (Arg : Node_Id);
12076 -- Posts message if the argument is an identifier with more
12077 -- than 31 characters, or a string literal with more than
12078 -- 31 characters, and we are operating under VMS
12080 --------------------
12081 -- Check_Too_Long --
12082 --------------------
12084 procedure Check_Too_Long (Arg : Node_Id) is
12085 X : constant Node_Id := Original_Node (Arg);
12088 if not Nkind_In (X, N_String_Literal, N_Identifier) then
12090 ("inappropriate argument for pragma %", Arg);
12093 if OpenVMS_On_Target then
12094 if (Nkind (X) = N_String_Literal
12095 and then String_Length (Strval (X)) > 31)
12097 (Nkind (X) = N_Identifier
12098 and then Length_Of_Name (Chars (X)) > 31)
12101 ("argument for pragma % is longer than 31 characters",
12105 end Check_Too_Long;
12107 -- Start of processing for Common_Object/Psect_Object
12111 Gather_Associations (Names, Args);
12112 Process_Extended_Import_Export_Internal_Arg (Internal);
12114 Def_Id := Entity (Internal);
12116 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12118 ("pragma% must designate an object", Internal);
12121 Check_Too_Long (Internal);
12123 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12125 ("cannot use pragma% for imported/exported object",
12129 if Is_Concurrent_Type (Etype (Internal)) then
12131 ("cannot specify pragma % for task/protected object",
12135 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12137 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12139 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12142 if Ekind (Def_Id) = E_Constant then
12144 ("cannot specify pragma % for a constant", Internal);
12147 if Is_Record_Type (Etype (Internal)) then
12153 Ent := First_Entity (Etype (Internal));
12154 while Present (Ent) loop
12155 Decl := Declaration_Node (Ent);
12157 if Ekind (Ent) = E_Component
12158 and then Nkind (Decl) = N_Component_Declaration
12159 and then Present (Expression (Decl))
12160 and then Warn_On_Export_Import
12163 ("?object for pragma % has defaults", Internal);
12173 if Present (Size) then
12174 Check_Too_Long (Size);
12177 if Present (External) then
12178 Check_Arg_Is_External_Name (External);
12179 Check_Too_Long (External);
12182 -- If all error tests pass, link pragma on to the rep item chain
12184 Record_Rep_Item (Def_Id, N);
12191 -- pragma Pure [(library_unit_NAME)];
12193 when Pragma_Pure => Pure : declare
12197 Check_Ada_83_Warning;
12198 Check_Valid_Library_Unit_Pragma;
12200 if Nkind (N) = N_Null_Statement then
12204 Ent := Find_Lib_Unit_Name;
12206 Set_Has_Pragma_Pure (Ent);
12207 Set_Suppress_Elaboration_Warnings (Ent);
12214 -- pragma Pure_05 [(library_unit_NAME)];
12216 -- This pragma is useable only in GNAT_Mode, where it is used like
12217 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
12218 -- it is ignored). It may be used after a pragma Preelaborate, in
12219 -- which case it overrides the effect of the pragma Preelaborate.
12220 -- This is used to implement AI-362 which recategorizes some run-time
12221 -- packages in Ada 2005 mode.
12223 when Pragma_Pure_05 => Pure_05 : declare
12228 Check_Valid_Library_Unit_Pragma;
12230 if not GNAT_Mode then
12231 Error_Pragma ("pragma% only available in GNAT mode");
12234 if Nkind (N) = N_Null_Statement then
12238 -- This is one of the few cases where we need to test the value of
12239 -- Ada_Version_Explicit rather than Ada_Version (which is always
12240 -- set to Ada_2012 in a predefined unit), we need to know the
12241 -- explicit version set to know if this pragma is active.
12243 if Ada_Version_Explicit >= Ada_2005 then
12244 Ent := Find_Lib_Unit_Name;
12245 Set_Is_Preelaborated (Ent, False);
12247 Set_Suppress_Elaboration_Warnings (Ent);
12251 -------------------
12252 -- Pure_Function --
12253 -------------------
12255 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12257 when Pragma_Pure_Function => Pure_Function : declare
12260 Def_Id : Entity_Id;
12261 Effective : Boolean := False;
12265 Check_Arg_Count (1);
12266 Check_Optional_Identifier (Arg1, Name_Entity);
12267 Check_Arg_Is_Local_Name (Arg1);
12268 E_Id := Get_Pragma_Arg (Arg1);
12270 if Error_Posted (E_Id) then
12274 -- Loop through homonyms (overloadings) of referenced entity
12276 E := Entity (E_Id);
12278 if Present (E) then
12280 Def_Id := Get_Base_Subprogram (E);
12282 if not Ekind_In (Def_Id, E_Function,
12283 E_Generic_Function,
12287 ("pragma% requires a function name", Arg1);
12290 Set_Is_Pure (Def_Id);
12292 if not Has_Pragma_Pure_Function (Def_Id) then
12293 Set_Has_Pragma_Pure_Function (Def_Id);
12297 exit when From_Aspect_Specification (N);
12299 exit when No (E) or else Scope (E) /= Current_Scope;
12303 and then Warn_On_Redundant_Constructs
12306 ("pragma Pure_Function on& is redundant?",
12312 --------------------
12313 -- Queuing_Policy --
12314 --------------------
12316 -- pragma Queuing_Policy (policy_IDENTIFIER);
12318 when Pragma_Queuing_Policy => declare
12322 Check_Ada_83_Warning;
12323 Check_Arg_Count (1);
12324 Check_No_Identifiers;
12325 Check_Arg_Is_Queuing_Policy (Arg1);
12326 Check_Valid_Configuration_Pragma;
12327 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12328 QP := Fold_Upper (Name_Buffer (1));
12330 if Queuing_Policy /= ' '
12331 and then Queuing_Policy /= QP
12333 Error_Msg_Sloc := Queuing_Policy_Sloc;
12334 Error_Pragma ("queuing policy incompatible with policy#");
12336 -- Set new policy, but always preserve System_Location since we
12337 -- like the error message with the run time name.
12340 Queuing_Policy := QP;
12342 if Queuing_Policy_Sloc /= System_Location then
12343 Queuing_Policy_Sloc := Loc;
12348 -----------------------
12349 -- Relative_Deadline --
12350 -----------------------
12352 -- pragma Relative_Deadline (time_span_EXPRESSION);
12354 when Pragma_Relative_Deadline => Relative_Deadline : declare
12355 P : constant Node_Id := Parent (N);
12360 Check_No_Identifiers;
12361 Check_Arg_Count (1);
12363 Arg := Get_Pragma_Arg (Arg1);
12365 -- The expression must be analyzed in the special manner described
12366 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12368 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12372 if Nkind (P) = N_Subprogram_Body then
12373 Check_In_Main_Program;
12377 elsif Nkind (P) = N_Task_Definition then
12380 -- Anything else is incorrect
12386 if Has_Relative_Deadline_Pragma (P) then
12387 Error_Pragma ("duplicate pragma% not allowed");
12389 Set_Has_Relative_Deadline_Pragma (P, True);
12391 if Nkind (P) = N_Task_Definition then
12392 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12395 end Relative_Deadline;
12397 ---------------------------
12398 -- Remote_Call_Interface --
12399 ---------------------------
12401 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12403 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12404 Cunit_Node : Node_Id;
12405 Cunit_Ent : Entity_Id;
12409 Check_Ada_83_Warning;
12410 Check_Valid_Library_Unit_Pragma;
12412 if Nkind (N) = N_Null_Statement then
12416 Cunit_Node := Cunit (Current_Sem_Unit);
12417 K := Nkind (Unit (Cunit_Node));
12418 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12420 if K = N_Package_Declaration
12421 or else K = N_Generic_Package_Declaration
12422 or else K = N_Subprogram_Declaration
12423 or else K = N_Generic_Subprogram_Declaration
12424 or else (K = N_Subprogram_Body
12425 and then Acts_As_Spec (Unit (Cunit_Node)))
12430 "pragma% must apply to package or subprogram declaration");
12433 Set_Is_Remote_Call_Interface (Cunit_Ent);
12434 end Remote_Call_Interface;
12440 -- pragma Remote_Types [(library_unit_NAME)];
12442 when Pragma_Remote_Types => Remote_Types : declare
12443 Cunit_Node : Node_Id;
12444 Cunit_Ent : Entity_Id;
12447 Check_Ada_83_Warning;
12448 Check_Valid_Library_Unit_Pragma;
12450 if Nkind (N) = N_Null_Statement then
12454 Cunit_Node := Cunit (Current_Sem_Unit);
12455 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12457 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12458 N_Generic_Package_Declaration)
12461 ("pragma% can only apply to a package declaration");
12464 Set_Is_Remote_Types (Cunit_Ent);
12471 -- pragma Ravenscar;
12473 when Pragma_Ravenscar =>
12475 Check_Arg_Count (0);
12476 Check_Valid_Configuration_Pragma;
12477 Set_Ravenscar_Profile (N);
12479 if Warn_On_Obsolescent_Feature then
12480 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12481 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12484 -------------------------
12485 -- Restricted_Run_Time --
12486 -------------------------
12488 -- pragma Restricted_Run_Time;
12490 when Pragma_Restricted_Run_Time =>
12492 Check_Arg_Count (0);
12493 Check_Valid_Configuration_Pragma;
12494 Set_Profile_Restrictions
12495 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12497 if Warn_On_Obsolescent_Feature then
12499 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12500 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12507 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12510 -- restriction_IDENTIFIER
12511 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12513 when Pragma_Restrictions =>
12514 Process_Restrictions_Or_Restriction_Warnings
12515 (Warn => Treat_Restrictions_As_Warnings);
12517 --------------------------
12518 -- Restriction_Warnings --
12519 --------------------------
12521 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12524 -- restriction_IDENTIFIER
12525 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12527 when Pragma_Restriction_Warnings =>
12529 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12535 -- pragma Reviewable;
12537 when Pragma_Reviewable =>
12538 Check_Ada_83_Warning;
12539 Check_Arg_Count (0);
12541 -- Call dummy debugging function rv. This is done to assist front
12542 -- end debugging. By placing a Reviewable pragma in the source
12543 -- program, a breakpoint on rv catches this place in the source,
12544 -- allowing convenient stepping to the point of interest.
12548 --------------------------
12549 -- Short_Circuit_And_Or --
12550 --------------------------
12552 when Pragma_Short_Circuit_And_Or =>
12554 Check_Arg_Count (0);
12555 Check_Valid_Configuration_Pragma;
12556 Short_Circuit_And_Or := True;
12558 -------------------
12559 -- Share_Generic --
12560 -------------------
12562 -- pragma Share_Generic (NAME {, NAME});
12564 when Pragma_Share_Generic =>
12566 Process_Generic_List;
12572 -- pragma Shared (LOCAL_NAME);
12574 when Pragma_Shared =>
12576 Process_Atomic_Shared_Volatile;
12578 --------------------
12579 -- Shared_Passive --
12580 --------------------
12582 -- pragma Shared_Passive [(library_unit_NAME)];
12584 -- Set the flag Is_Shared_Passive of program unit name entity
12586 when Pragma_Shared_Passive => Shared_Passive : declare
12587 Cunit_Node : Node_Id;
12588 Cunit_Ent : Entity_Id;
12591 Check_Ada_83_Warning;
12592 Check_Valid_Library_Unit_Pragma;
12594 if Nkind (N) = N_Null_Statement then
12598 Cunit_Node := Cunit (Current_Sem_Unit);
12599 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12601 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12602 N_Generic_Package_Declaration)
12605 ("pragma% can only apply to a package declaration");
12608 Set_Is_Shared_Passive (Cunit_Ent);
12609 end Shared_Passive;
12611 -----------------------
12612 -- Short_Descriptors --
12613 -----------------------
12615 -- pragma Short_Descriptors;
12617 when Pragma_Short_Descriptors =>
12619 Check_Arg_Count (0);
12620 Check_Valid_Configuration_Pragma;
12621 Short_Descriptors := True;
12623 ----------------------
12624 -- Source_File_Name --
12625 ----------------------
12627 -- There are five forms for this pragma:
12629 -- pragma Source_File_Name (
12630 -- [UNIT_NAME =>] unit_NAME,
12631 -- BODY_FILE_NAME => STRING_LITERAL
12632 -- [, [INDEX =>] INTEGER_LITERAL]);
12634 -- pragma Source_File_Name (
12635 -- [UNIT_NAME =>] unit_NAME,
12636 -- SPEC_FILE_NAME => STRING_LITERAL
12637 -- [, [INDEX =>] INTEGER_LITERAL]);
12639 -- pragma Source_File_Name (
12640 -- BODY_FILE_NAME => STRING_LITERAL
12641 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12642 -- [, CASING => CASING_SPEC]);
12644 -- pragma Source_File_Name (
12645 -- SPEC_FILE_NAME => STRING_LITERAL
12646 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12647 -- [, CASING => CASING_SPEC]);
12649 -- pragma Source_File_Name (
12650 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12651 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12652 -- [, CASING => CASING_SPEC]);
12654 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12656 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12657 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12658 -- only be used when no project file is used, while SFNP can only be
12659 -- used when a project file is used.
12661 -- No processing here. Processing was completed during parsing, since
12662 -- we need to have file names set as early as possible. Units are
12663 -- loaded well before semantic processing starts.
12665 -- The only processing we defer to this point is the check for
12666 -- correct placement.
12668 when Pragma_Source_File_Name =>
12670 Check_Valid_Configuration_Pragma;
12672 ------------------------------
12673 -- Source_File_Name_Project --
12674 ------------------------------
12676 -- See Source_File_Name for syntax
12678 -- No processing here. Processing was completed during parsing, since
12679 -- we need to have file names set as early as possible. Units are
12680 -- loaded well before semantic processing starts.
12682 -- The only processing we defer to this point is the check for
12683 -- correct placement.
12685 when Pragma_Source_File_Name_Project =>
12687 Check_Valid_Configuration_Pragma;
12689 -- Check that a pragma Source_File_Name_Project is used only in a
12690 -- configuration pragmas file.
12692 -- Pragmas Source_File_Name_Project should only be generated by
12693 -- the Project Manager in configuration pragmas files.
12695 -- This is really an ugly test. It seems to depend on some
12696 -- accidental and undocumented property. At the very least it
12697 -- needs to be documented, but it would be better to have a
12698 -- clean way of testing if we are in a configuration file???
12700 if Present (Parent (N)) then
12702 ("pragma% can only appear in a configuration pragmas file");
12705 ----------------------
12706 -- Source_Reference --
12707 ----------------------
12709 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12711 -- Nothing to do, all processing completed in Par.Prag, since we need
12712 -- the information for possible parser messages that are output.
12714 when Pragma_Source_Reference =>
12717 --------------------------------
12718 -- Static_Elaboration_Desired --
12719 --------------------------------
12721 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12723 when Pragma_Static_Elaboration_Desired =>
12725 Check_At_Most_N_Arguments (1);
12727 if Is_Compilation_Unit (Current_Scope)
12728 and then Ekind (Current_Scope) = E_Package
12730 Set_Static_Elaboration_Desired (Current_Scope, True);
12732 Error_Pragma ("pragma% must apply to a library-level package");
12739 -- pragma Storage_Size (EXPRESSION);
12741 when Pragma_Storage_Size => Storage_Size : declare
12742 P : constant Node_Id := Parent (N);
12746 Check_No_Identifiers;
12747 Check_Arg_Count (1);
12749 -- The expression must be analyzed in the special manner described
12750 -- in "Handling of Default Expressions" in sem.ads.
12752 Arg := Get_Pragma_Arg (Arg1);
12753 Preanalyze_Spec_Expression (Arg, Any_Integer);
12755 if not Is_Static_Expression (Arg) then
12756 Check_Restriction (Static_Storage_Size, Arg);
12759 if Nkind (P) /= N_Task_Definition then
12764 if Has_Storage_Size_Pragma (P) then
12765 Error_Pragma ("duplicate pragma% not allowed");
12767 Set_Has_Storage_Size_Pragma (P, True);
12770 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12771 -- ??? exp_ch9 should use this!
12779 -- pragma Storage_Unit (NUMERIC_LITERAL);
12781 -- Only permitted argument is System'Storage_Unit value
12783 when Pragma_Storage_Unit =>
12784 Check_No_Identifiers;
12785 Check_Arg_Count (1);
12786 Check_Arg_Is_Integer_Literal (Arg1);
12788 if Intval (Get_Pragma_Arg (Arg1)) /=
12789 UI_From_Int (Ttypes.System_Storage_Unit)
12791 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12793 ("the only allowed argument for pragma% is ^", Arg1);
12796 --------------------
12797 -- Stream_Convert --
12798 --------------------
12800 -- pragma Stream_Convert (
12801 -- [Entity =>] type_LOCAL_NAME,
12802 -- [Read =>] function_NAME,
12803 -- [Write =>] function NAME);
12805 when Pragma_Stream_Convert => Stream_Convert : declare
12807 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12808 -- Check that the given argument is the name of a local function
12809 -- of one argument that is not overloaded earlier in the current
12810 -- local scope. A check is also made that the argument is a
12811 -- function with one parameter.
12813 --------------------------------------
12814 -- Check_OK_Stream_Convert_Function --
12815 --------------------------------------
12817 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12821 Check_Arg_Is_Local_Name (Arg);
12822 Ent := Entity (Get_Pragma_Arg (Arg));
12824 if Has_Homonym (Ent) then
12826 ("argument for pragma% may not be overloaded", Arg);
12829 if Ekind (Ent) /= E_Function
12830 or else No (First_Formal (Ent))
12831 or else Present (Next_Formal (First_Formal (Ent)))
12834 ("argument for pragma% must be" &
12835 " function of one argument", Arg);
12837 end Check_OK_Stream_Convert_Function;
12839 -- Start of processing for Stream_Convert
12843 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12844 Check_Arg_Count (3);
12845 Check_Optional_Identifier (Arg1, Name_Entity);
12846 Check_Optional_Identifier (Arg2, Name_Read);
12847 Check_Optional_Identifier (Arg3, Name_Write);
12848 Check_Arg_Is_Local_Name (Arg1);
12849 Check_OK_Stream_Convert_Function (Arg2);
12850 Check_OK_Stream_Convert_Function (Arg3);
12853 Typ : constant Entity_Id :=
12854 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12855 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12856 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12859 Check_First_Subtype (Arg1);
12861 -- Check for too early or too late. Note that we don't enforce
12862 -- the rule about primitive operations in this case, since, as
12863 -- is the case for explicit stream attributes themselves, these
12864 -- restrictions are not appropriate. Note that the chaining of
12865 -- the pragma by Rep_Item_Too_Late is actually the critical
12866 -- processing done for this pragma.
12868 if Rep_Item_Too_Early (Typ, N)
12870 Rep_Item_Too_Late (Typ, N, FOnly => True)
12875 -- Return if previous error
12877 if Etype (Typ) = Any_Type
12879 Etype (Read) = Any_Type
12881 Etype (Write) = Any_Type
12888 if Underlying_Type (Etype (Read)) /= Typ then
12890 ("incorrect return type for function&", Arg2);
12893 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12895 ("incorrect parameter type for function&", Arg3);
12898 if Underlying_Type (Etype (First_Formal (Read))) /=
12899 Underlying_Type (Etype (Write))
12902 ("result type of & does not match Read parameter type",
12906 end Stream_Convert;
12908 -------------------------
12909 -- Style_Checks (GNAT) --
12910 -------------------------
12912 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12914 -- This is processed by the parser since some of the style checks
12915 -- take place during source scanning and parsing. This means that
12916 -- we don't need to issue error messages here.
12918 when Pragma_Style_Checks => Style_Checks : declare
12919 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12925 Check_No_Identifiers;
12927 -- Two argument form
12929 if Arg_Count = 2 then
12930 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12937 E_Id := Get_Pragma_Arg (Arg2);
12940 if not Is_Entity_Name (E_Id) then
12942 ("second argument of pragma% must be entity name",
12946 E := Entity (E_Id);
12952 Set_Suppress_Style_Checks (E,
12953 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12954 exit when No (Homonym (E));
12960 -- One argument form
12963 Check_Arg_Count (1);
12965 if Nkind (A) = N_String_Literal then
12969 Slen : constant Natural := Natural (String_Length (S));
12970 Options : String (1 .. Slen);
12976 C := Get_String_Char (S, Int (J));
12977 exit when not In_Character_Range (C);
12978 Options (J) := Get_Character (C);
12980 -- If at end of string, set options. As per discussion
12981 -- above, no need to check for errors, since we issued
12982 -- them in the parser.
12985 Set_Style_Check_Options (Options);
12993 elsif Nkind (A) = N_Identifier then
12994 if Chars (A) = Name_All_Checks then
12996 Set_GNAT_Style_Check_Options;
12998 Set_Default_Style_Check_Options;
13001 elsif Chars (A) = Name_On then
13002 Style_Check := True;
13004 elsif Chars (A) = Name_Off then
13005 Style_Check := False;
13015 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13017 when Pragma_Subtitle =>
13019 Check_Arg_Count (1);
13020 Check_Optional_Identifier (Arg1, Name_Subtitle);
13021 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13028 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13030 when Pragma_Suppress =>
13031 Process_Suppress_Unsuppress (True);
13037 -- pragma Suppress_All;
13039 -- The only check made here is that the pragma has no arguments.
13040 -- There are no placement rules, and the processing required (setting
13041 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
13042 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
13043 -- then creates and inserts a pragma Suppress (All_Checks).
13045 when Pragma_Suppress_All =>
13047 Check_Arg_Count (0);
13049 -------------------------
13050 -- Suppress_Debug_Info --
13051 -------------------------
13053 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13055 when Pragma_Suppress_Debug_Info =>
13057 Check_Arg_Count (1);
13058 Check_Optional_Identifier (Arg1, Name_Entity);
13059 Check_Arg_Is_Local_Name (Arg1);
13060 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13062 ----------------------------------
13063 -- Suppress_Exception_Locations --
13064 ----------------------------------
13066 -- pragma Suppress_Exception_Locations;
13068 when Pragma_Suppress_Exception_Locations =>
13070 Check_Arg_Count (0);
13071 Check_Valid_Configuration_Pragma;
13072 Exception_Locations_Suppressed := True;
13074 -----------------------------
13075 -- Suppress_Initialization --
13076 -----------------------------
13078 -- pragma Suppress_Initialization ([Entity =>] type_Name);
13080 when Pragma_Suppress_Initialization => Suppress_Init : declare
13086 Check_Arg_Count (1);
13087 Check_Optional_Identifier (Arg1, Name_Entity);
13088 Check_Arg_Is_Local_Name (Arg1);
13090 E_Id := Get_Pragma_Arg (Arg1);
13092 if Etype (E_Id) = Any_Type then
13096 E := Entity (E_Id);
13098 if not Is_Type (E) then
13099 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13102 if Rep_Item_Too_Early (E, N)
13104 Rep_Item_Too_Late (E, N, FOnly => True)
13109 -- For incomplete/private type, set flag on full view
13111 if Is_Incomplete_Or_Private_Type (E) then
13112 if No (Full_View (Base_Type (E))) then
13114 ("argument of pragma% cannot be an incomplete type", Arg1);
13116 Set_Suppress_Initialization (Full_View (Base_Type (E)));
13119 -- For first subtype, set flag on base type
13121 elsif Is_First_Subtype (E) then
13122 Set_Suppress_Initialization (Base_Type (E));
13124 -- For other than first subtype, set flag on subtype itself
13127 Set_Suppress_Initialization (E);
13135 -- pragma System_Name (DIRECT_NAME);
13137 -- Syntax check: one argument, which must be the identifier GNAT or
13138 -- the identifier GCC, no other identifiers are acceptable.
13140 when Pragma_System_Name =>
13142 Check_No_Identifiers;
13143 Check_Arg_Count (1);
13144 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13146 -----------------------------
13147 -- Task_Dispatching_Policy --
13148 -----------------------------
13150 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13152 when Pragma_Task_Dispatching_Policy => declare
13156 Check_Ada_83_Warning;
13157 Check_Arg_Count (1);
13158 Check_No_Identifiers;
13159 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13160 Check_Valid_Configuration_Pragma;
13161 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13162 DP := Fold_Upper (Name_Buffer (1));
13164 if Task_Dispatching_Policy /= ' '
13165 and then Task_Dispatching_Policy /= DP
13167 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13169 ("task dispatching policy incompatible with policy#");
13171 -- Set new policy, but always preserve System_Location since we
13172 -- like the error message with the run time name.
13175 Task_Dispatching_Policy := DP;
13177 if Task_Dispatching_Policy_Sloc /= System_Location then
13178 Task_Dispatching_Policy_Sloc := Loc;
13187 -- pragma Task_Info (EXPRESSION);
13189 when Pragma_Task_Info => Task_Info : declare
13190 P : constant Node_Id := Parent (N);
13195 if Nkind (P) /= N_Task_Definition then
13196 Error_Pragma ("pragma% must appear in task definition");
13199 Check_No_Identifiers;
13200 Check_Arg_Count (1);
13202 Analyze_And_Resolve
13203 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13205 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13209 if Has_Task_Info_Pragma (P) then
13210 Error_Pragma ("duplicate pragma% not allowed");
13212 Set_Has_Task_Info_Pragma (P, True);
13220 -- pragma Task_Name (string_EXPRESSION);
13222 when Pragma_Task_Name => Task_Name : declare
13223 P : constant Node_Id := Parent (N);
13227 Check_No_Identifiers;
13228 Check_Arg_Count (1);
13230 Arg := Get_Pragma_Arg (Arg1);
13232 -- The expression is used in the call to Create_Task, and must be
13233 -- expanded there, not in the context of the current spec. It must
13234 -- however be analyzed to capture global references, in case it
13235 -- appears in a generic context.
13237 Preanalyze_And_Resolve (Arg, Standard_String);
13239 if Nkind (P) /= N_Task_Definition then
13243 if Has_Task_Name_Pragma (P) then
13244 Error_Pragma ("duplicate pragma% not allowed");
13246 Set_Has_Task_Name_Pragma (P, True);
13247 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13255 -- pragma Task_Storage (
13256 -- [Task_Type =>] LOCAL_NAME,
13257 -- [Top_Guard =>] static_integer_EXPRESSION);
13259 when Pragma_Task_Storage => Task_Storage : declare
13260 Args : Args_List (1 .. 2);
13261 Names : constant Name_List (1 .. 2) := (
13265 Task_Type : Node_Id renames Args (1);
13266 Top_Guard : Node_Id renames Args (2);
13272 Gather_Associations (Names, Args);
13274 if No (Task_Type) then
13276 ("missing task_type argument for pragma%");
13279 Check_Arg_Is_Local_Name (Task_Type);
13281 Ent := Entity (Task_Type);
13283 if not Is_Task_Type (Ent) then
13285 ("argument for pragma% must be task type", Task_Type);
13288 if No (Top_Guard) then
13290 ("pragma% takes two arguments", Task_Type);
13292 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13295 Check_First_Subtype (Task_Type);
13297 if Rep_Item_Too_Late (Ent, N) then
13306 -- pragma Test_Case ([Name =>] Static_String_EXPRESSION
13307 -- ,[Mode =>] MODE_TYPE
13308 -- [, Requires => Boolean_EXPRESSION]
13309 -- [, Ensures => Boolean_EXPRESSION]);
13311 -- MODE_TYPE ::= Nominal | Robustness
13313 when Pragma_Test_Case => Test_Case : declare
13316 Check_At_Least_N_Arguments (2);
13317 Check_At_Most_N_Arguments (4);
13319 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13321 Check_Optional_Identifier (Arg1, Name_Name);
13322 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13323 Check_Optional_Identifier (Arg2, Name_Mode);
13324 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
13326 if Arg_Count = 4 then
13327 Check_Identifier (Arg3, Name_Requires);
13328 Check_Identifier (Arg4, Name_Ensures);
13330 elsif Arg_Count = 3 then
13331 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13337 --------------------------
13338 -- Thread_Local_Storage --
13339 --------------------------
13341 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13343 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13349 Check_Arg_Count (1);
13350 Check_Optional_Identifier (Arg1, Name_Entity);
13351 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13353 Id := Get_Pragma_Arg (Arg1);
13356 if not Is_Entity_Name (Id)
13357 or else Ekind (Entity (Id)) /= E_Variable
13359 Error_Pragma_Arg ("local variable name required", Arg1);
13364 if Rep_Item_Too_Early (E, N)
13365 or else Rep_Item_Too_Late (E, N)
13370 Set_Has_Pragma_Thread_Local_Storage (E);
13371 Set_Has_Gigi_Rep_Item (E);
13372 end Thread_Local_Storage;
13378 -- pragma Time_Slice (static_duration_EXPRESSION);
13380 when Pragma_Time_Slice => Time_Slice : declare
13386 Check_Arg_Count (1);
13387 Check_No_Identifiers;
13388 Check_In_Main_Program;
13389 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13391 if not Error_Posted (Arg1) then
13393 while Present (Nod) loop
13394 if Nkind (Nod) = N_Pragma
13395 and then Pragma_Name (Nod) = Name_Time_Slice
13397 Error_Msg_Name_1 := Pname;
13398 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13405 -- Process only if in main unit
13407 if Get_Source_Unit (Loc) = Main_Unit then
13408 Opt.Time_Slice_Set := True;
13409 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13411 if Val <= Ureal_0 then
13412 Opt.Time_Slice_Value := 0;
13414 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13415 Opt.Time_Slice_Value := 1_000_000_000;
13418 Opt.Time_Slice_Value :=
13419 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13428 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13430 -- TITLING_OPTION ::=
13431 -- [Title =>] STRING_LITERAL
13432 -- | [Subtitle =>] STRING_LITERAL
13434 when Pragma_Title => Title : declare
13435 Args : Args_List (1 .. 2);
13436 Names : constant Name_List (1 .. 2) := (
13442 Gather_Associations (Names, Args);
13445 for J in 1 .. 2 loop
13446 if Present (Args (J)) then
13447 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13452 ---------------------
13453 -- Unchecked_Union --
13454 ---------------------
13456 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13458 when Pragma_Unchecked_Union => Unchecked_Union : declare
13459 Assoc : constant Node_Id := Arg1;
13460 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13471 Check_No_Identifiers;
13472 Check_Arg_Count (1);
13473 Check_Arg_Is_Local_Name (Arg1);
13475 Find_Type (Type_Id);
13476 Typ := Entity (Type_Id);
13479 or else Rep_Item_Too_Early (Typ, N)
13483 Typ := Underlying_Type (Typ);
13486 if Rep_Item_Too_Late (Typ, N) then
13490 Check_First_Subtype (Arg1);
13492 -- Note remaining cases are references to a type in the current
13493 -- declarative part. If we find an error, we post the error on
13494 -- the relevant type declaration at an appropriate point.
13496 if not Is_Record_Type (Typ) then
13497 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13500 elsif Is_Tagged_Type (Typ) then
13501 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13504 elsif Is_Limited_Type (Typ) then
13506 ("Unchecked_Union must not be limited record type", Typ);
13507 Explain_Limited_Type (Typ, Typ);
13511 if not Has_Discriminants (Typ) then
13513 ("Unchecked_Union must have one discriminant", Typ);
13517 Discr := First_Discriminant (Typ);
13518 while Present (Discr) loop
13519 if No (Discriminant_Default_Value (Discr)) then
13521 ("Unchecked_Union discriminant must have default value",
13525 Next_Discriminant (Discr);
13528 Tdef := Type_Definition (Declaration_Node (Typ));
13529 Clist := Component_List (Tdef);
13531 Comp := First (Component_Items (Clist));
13532 while Present (Comp) loop
13533 Check_Component (Comp, Typ);
13537 if No (Clist) or else No (Variant_Part (Clist)) then
13539 ("Unchecked_Union must have variant part",
13544 Vpart := Variant_Part (Clist);
13546 Variant := First (Variants (Vpart));
13547 while Present (Variant) loop
13548 Check_Variant (Variant, Typ);
13553 Set_Is_Unchecked_Union (Typ);
13554 Set_Convention (Typ, Convention_C);
13555 Set_Has_Unchecked_Union (Base_Type (Typ));
13556 Set_Is_Unchecked_Union (Base_Type (Typ));
13557 end Unchecked_Union;
13559 ------------------------
13560 -- Unimplemented_Unit --
13561 ------------------------
13563 -- pragma Unimplemented_Unit;
13565 -- Note: this only gives an error if we are generating code, or if
13566 -- we are in a generic library unit (where the pragma appears in the
13567 -- body, not in the spec).
13569 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13570 Cunitent : constant Entity_Id :=
13571 Cunit_Entity (Get_Source_Unit (Loc));
13572 Ent_Kind : constant Entity_Kind :=
13577 Check_Arg_Count (0);
13579 if Operating_Mode = Generate_Code
13580 or else Ent_Kind = E_Generic_Function
13581 or else Ent_Kind = E_Generic_Procedure
13582 or else Ent_Kind = E_Generic_Package
13584 Get_Name_String (Chars (Cunitent));
13585 Set_Casing (Mixed_Case);
13586 Write_Str (Name_Buffer (1 .. Name_Len));
13587 Write_Str (" is not supported in this configuration");
13589 raise Unrecoverable_Error;
13591 end Unimplemented_Unit;
13593 ------------------------
13594 -- Universal_Aliasing --
13595 ------------------------
13597 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13599 when Pragma_Universal_Aliasing => Universal_Alias : declare
13604 Check_Arg_Count (1);
13605 Check_Optional_Identifier (Arg2, Name_Entity);
13606 Check_Arg_Is_Local_Name (Arg1);
13607 E_Id := Entity (Get_Pragma_Arg (Arg1));
13609 if E_Id = Any_Type then
13611 elsif No (E_Id) or else not Is_Type (E_Id) then
13612 Error_Pragma_Arg ("pragma% requires type", Arg1);
13615 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13616 end Universal_Alias;
13618 --------------------
13619 -- Universal_Data --
13620 --------------------
13622 -- pragma Universal_Data [(library_unit_NAME)];
13624 when Pragma_Universal_Data =>
13627 -- If this is a configuration pragma, then set the universal
13628 -- addressing option, otherwise confirm that the pragma satisfies
13629 -- the requirements of library unit pragma placement and leave it
13630 -- to the GNAAMP back end to detect the pragma (avoids transitive
13631 -- setting of the option due to withed units).
13633 if Is_Configuration_Pragma then
13634 Universal_Addressing_On_AAMP := True;
13636 Check_Valid_Library_Unit_Pragma;
13639 if not AAMP_On_Target then
13640 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13647 -- pragma Unmodified (local_Name {, local_Name});
13649 when Pragma_Unmodified => Unmodified : declare
13650 Arg_Node : Node_Id;
13651 Arg_Expr : Node_Id;
13652 Arg_Ent : Entity_Id;
13656 Check_At_Least_N_Arguments (1);
13658 -- Loop through arguments
13661 while Present (Arg_Node) loop
13662 Check_No_Identifier (Arg_Node);
13664 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13665 -- in fact generate reference, so that the entity will have a
13666 -- reference, which will inhibit any warnings about it not
13667 -- being referenced, and also properly show up in the ali file
13668 -- as a reference. But this reference is recorded before the
13669 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13670 -- generated for this reference.
13672 Check_Arg_Is_Local_Name (Arg_Node);
13673 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13675 if Is_Entity_Name (Arg_Expr) then
13676 Arg_Ent := Entity (Arg_Expr);
13678 if not Is_Assignable (Arg_Ent) then
13680 ("pragma% can only be applied to a variable",
13683 Set_Has_Pragma_Unmodified (Arg_Ent);
13695 -- pragma Unreferenced (local_Name {, local_Name});
13697 -- or when used in a context clause:
13699 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13701 when Pragma_Unreferenced => Unreferenced : declare
13702 Arg_Node : Node_Id;
13703 Arg_Expr : Node_Id;
13704 Arg_Ent : Entity_Id;
13709 Check_At_Least_N_Arguments (1);
13711 -- Check case of appearing within context clause
13713 if Is_In_Context_Clause then
13715 -- The arguments must all be units mentioned in a with clause
13716 -- in the same context clause. Note we already checked (in
13717 -- Par.Prag) that the arguments are either identifiers or
13718 -- selected components.
13721 while Present (Arg_Node) loop
13722 Citem := First (List_Containing (N));
13723 while Citem /= N loop
13724 if Nkind (Citem) = N_With_Clause
13726 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13728 Set_Has_Pragma_Unreferenced
13731 (Library_Unit (Citem))));
13733 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13742 ("argument of pragma% is not with'ed unit", Arg_Node);
13748 -- Case of not in list of context items
13752 while Present (Arg_Node) loop
13753 Check_No_Identifier (Arg_Node);
13755 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13756 -- will in fact generate reference, so that the entity will
13757 -- have a reference, which will inhibit any warnings about
13758 -- it not being referenced, and also properly show up in the
13759 -- ali file as a reference. But this reference is recorded
13760 -- before the Has_Pragma_Unreferenced flag is set, so that
13761 -- no warning is generated for this reference.
13763 Check_Arg_Is_Local_Name (Arg_Node);
13764 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13766 if Is_Entity_Name (Arg_Expr) then
13767 Arg_Ent := Entity (Arg_Expr);
13769 -- If the entity is overloaded, the pragma applies to the
13770 -- most recent overloading, as documented. In this case,
13771 -- name resolution does not generate a reference, so it
13772 -- must be done here explicitly.
13774 if Is_Overloaded (Arg_Expr) then
13775 Generate_Reference (Arg_Ent, N);
13778 Set_Has_Pragma_Unreferenced (Arg_Ent);
13786 --------------------------
13787 -- Unreferenced_Objects --
13788 --------------------------
13790 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13792 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13793 Arg_Node : Node_Id;
13794 Arg_Expr : Node_Id;
13798 Check_At_Least_N_Arguments (1);
13801 while Present (Arg_Node) loop
13802 Check_No_Identifier (Arg_Node);
13803 Check_Arg_Is_Local_Name (Arg_Node);
13804 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13806 if not Is_Entity_Name (Arg_Expr)
13807 or else not Is_Type (Entity (Arg_Expr))
13810 ("argument for pragma% must be type or subtype", Arg_Node);
13813 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13816 end Unreferenced_Objects;
13818 ------------------------------
13819 -- Unreserve_All_Interrupts --
13820 ------------------------------
13822 -- pragma Unreserve_All_Interrupts;
13824 when Pragma_Unreserve_All_Interrupts =>
13826 Check_Arg_Count (0);
13828 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13829 Unreserve_All_Interrupts := True;
13836 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13838 when Pragma_Unsuppress =>
13840 Process_Suppress_Unsuppress (False);
13842 -------------------
13843 -- Use_VADS_Size --
13844 -------------------
13846 -- pragma Use_VADS_Size;
13848 when Pragma_Use_VADS_Size =>
13850 Check_Arg_Count (0);
13851 Check_Valid_Configuration_Pragma;
13852 Use_VADS_Size := True;
13854 ---------------------
13855 -- Validity_Checks --
13856 ---------------------
13858 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13860 when Pragma_Validity_Checks => Validity_Checks : declare
13861 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13867 Check_Arg_Count (1);
13868 Check_No_Identifiers;
13870 if Nkind (A) = N_String_Literal then
13874 Slen : constant Natural := Natural (String_Length (S));
13875 Options : String (1 .. Slen);
13881 C := Get_String_Char (S, Int (J));
13882 exit when not In_Character_Range (C);
13883 Options (J) := Get_Character (C);
13886 Set_Validity_Check_Options (Options);
13894 elsif Nkind (A) = N_Identifier then
13896 if Chars (A) = Name_All_Checks then
13897 Set_Validity_Check_Options ("a");
13899 elsif Chars (A) = Name_On then
13900 Validity_Checks_On := True;
13902 elsif Chars (A) = Name_Off then
13903 Validity_Checks_On := False;
13907 end Validity_Checks;
13913 -- pragma Volatile (LOCAL_NAME);
13915 when Pragma_Volatile =>
13916 Process_Atomic_Shared_Volatile;
13918 -------------------------
13919 -- Volatile_Components --
13920 -------------------------
13922 -- pragma Volatile_Components (array_LOCAL_NAME);
13924 -- Volatile is handled by the same circuit as Atomic_Components
13930 -- pragma Warnings (On | Off);
13931 -- pragma Warnings (On | Off, LOCAL_NAME);
13932 -- pragma Warnings (static_string_EXPRESSION);
13933 -- pragma Warnings (On | Off, STRING_LITERAL);
13935 when Pragma_Warnings => Warnings : begin
13937 Check_At_Least_N_Arguments (1);
13938 Check_No_Identifiers;
13940 -- If debug flag -gnatd.i is set, pragma is ignored
13942 if Debug_Flag_Dot_I then
13946 -- Process various forms of the pragma
13949 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13952 -- One argument case
13954 if Arg_Count = 1 then
13956 -- On/Off one argument case was processed by parser
13958 if Nkind (Argx) = N_Identifier
13960 (Chars (Argx) = Name_On
13962 Chars (Argx) = Name_Off)
13966 -- One argument case must be ON/OFF or static string expr
13968 elsif not Is_Static_String_Expression (Arg1) then
13970 ("argument of pragma% must be On/Off or " &
13971 "static string expression", Arg1);
13973 -- One argument string expression case
13977 Lit : constant Node_Id := Expr_Value_S (Argx);
13978 Str : constant String_Id := Strval (Lit);
13979 Len : constant Nat := String_Length (Str);
13987 while J <= Len loop
13988 C := Get_String_Char (Str, J);
13989 OK := In_Character_Range (C);
13992 Chr := Get_Character (C);
13996 if J < Len and then Chr = '.' then
13998 C := Get_String_Char (Str, J);
13999 Chr := Get_Character (C);
14001 if not Set_Dot_Warning_Switch (Chr) then
14003 ("invalid warning switch character " &
14010 OK := Set_Warning_Switch (Chr);
14016 ("invalid warning switch character " & Chr,
14025 -- Two or more arguments (must be two)
14028 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14029 Check_At_Most_N_Arguments (2);
14037 E_Id := Get_Pragma_Arg (Arg2);
14040 -- In the expansion of an inlined body, a reference to
14041 -- the formal may be wrapped in a conversion if the
14042 -- actual is a conversion. Retrieve the real entity name.
14044 if (In_Instance_Body
14045 or else In_Inlined_Body)
14046 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14048 E_Id := Expression (E_Id);
14051 -- Entity name case
14053 if Is_Entity_Name (E_Id) then
14054 E := Entity (E_Id);
14061 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14064 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14065 and then Warn_On_Warnings_Off
14067 Warnings_Off_Pragmas.Append ((N, E));
14070 if Is_Enumeration_Type (E) then
14074 Lit := First_Literal (E);
14075 while Present (Lit) loop
14076 Set_Warnings_Off (Lit);
14077 Next_Literal (Lit);
14082 exit when No (Homonym (E));
14087 -- Error if not entity or static string literal case
14089 elsif not Is_Static_String_Expression (Arg2) then
14091 ("second argument of pragma% must be entity " &
14092 "name or static string expression", Arg2);
14094 -- String literal case
14097 String_To_Name_Buffer
14098 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14100 -- Note on configuration pragma case: If this is a
14101 -- configuration pragma, then for an OFF pragma, we
14102 -- just set Config True in the call, which is all
14103 -- that needs to be done. For the case of ON, this
14104 -- is normally an error, unless it is canceling the
14105 -- effect of a previous OFF pragma in the same file.
14106 -- In any other case, an error will be signalled (ON
14107 -- with no matching OFF).
14109 if Chars (Argx) = Name_Off then
14110 Set_Specific_Warning_Off
14111 (Loc, Name_Buffer (1 .. Name_Len),
14112 Config => Is_Configuration_Pragma);
14114 elsif Chars (Argx) = Name_On then
14115 Set_Specific_Warning_On
14116 (Loc, Name_Buffer (1 .. Name_Len), Err);
14120 ("?pragma Warnings On with no " &
14121 "matching Warnings Off",
14131 -------------------
14132 -- Weak_External --
14133 -------------------
14135 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
14137 when Pragma_Weak_External => Weak_External : declare
14142 Check_Arg_Count (1);
14143 Check_Optional_Identifier (Arg1, Name_Entity);
14144 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14145 Ent := Entity (Get_Pragma_Arg (Arg1));
14147 if Rep_Item_Too_Early (Ent, N) then
14150 Ent := Underlying_Type (Ent);
14153 -- The only processing required is to link this item on to the
14154 -- list of rep items for the given entity. This is accomplished
14155 -- by the call to Rep_Item_Too_Late (when no error is detected
14156 -- and False is returned).
14158 if Rep_Item_Too_Late (Ent, N) then
14161 Set_Has_Gigi_Rep_Item (Ent);
14165 -----------------------------
14166 -- Wide_Character_Encoding --
14167 -----------------------------
14169 -- pragma Wide_Character_Encoding (IDENTIFIER);
14171 when Pragma_Wide_Character_Encoding =>
14174 -- Nothing to do, handled in parser. Note that we do not enforce
14175 -- configuration pragma placement, this pragma can appear at any
14176 -- place in the source, allowing mixed encodings within a single
14181 --------------------
14182 -- Unknown_Pragma --
14183 --------------------
14185 -- Should be impossible, since the case of an unknown pragma is
14186 -- separately processed before the case statement is entered.
14188 when Unknown_Pragma =>
14189 raise Program_Error;
14192 -- AI05-0144: detect dangerous order dependence. Disabled for now,
14193 -- until AI is formally approved.
14195 -- Check_Order_Dependence;
14198 when Pragma_Exit => null;
14199 end Analyze_Pragma;
14201 -----------------------------
14202 -- Analyze_TC_In_Decl_Part --
14203 -----------------------------
14205 procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14207 -- Install formals and push subprogram spec onto scope stack so that we
14208 -- can see the formals from the pragma.
14210 Install_Formals (S);
14213 -- Preanalyze the boolean expressions, we treat these as spec
14214 -- expressions (i.e. similar to a default expression).
14216 Preanalyze_TC_Args (Get_Requires_From_Test_Case_Pragma (N),
14217 Get_Ensures_From_Test_Case_Pragma (N));
14219 -- Remove the subprogram from the scope stack now that the pre-analysis
14220 -- of the expressions in the test-case is done.
14223 end Analyze_TC_In_Decl_Part;
14225 --------------------
14226 -- Check_Disabled --
14227 --------------------
14229 function Check_Disabled (Nam : Name_Id) return Boolean is
14233 -- Loop through entries in check policy list
14235 PP := Opt.Check_Policy_List;
14237 -- If there are no specific entries that matched, then nothing is
14238 -- disabled, so return False.
14243 -- Here we have an entry see if it matches
14247 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14249 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14250 return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14252 PP := Next_Pragma (PP);
14257 end Check_Disabled;
14259 -------------------
14260 -- Check_Enabled --
14261 -------------------
14263 function Check_Enabled (Nam : Name_Id) return Boolean is
14267 -- Loop through entries in check policy list
14269 PP := Opt.Check_Policy_List;
14271 -- If there are no specific entries that matched, then we let the
14272 -- setting of assertions govern. Note that this provides the needed
14273 -- compatibility with the RM for the cases of assertion, invariant,
14274 -- precondition, predicate, and postcondition.
14277 return Assertions_Enabled;
14279 -- Here we have an entry see if it matches
14283 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14286 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14287 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14288 when Name_On | Name_Check =>
14290 when Name_Off | Name_Ignore =>
14293 raise Program_Error;
14297 PP := Next_Pragma (PP);
14304 ---------------------------------
14305 -- Delay_Config_Pragma_Analyze --
14306 ---------------------------------
14308 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14310 return Pragma_Name (N) = Name_Interrupt_State
14312 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14313 end Delay_Config_Pragma_Analyze;
14315 -------------------------
14316 -- Get_Base_Subprogram --
14317 -------------------------
14319 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14320 Result : Entity_Id;
14323 -- Follow subprogram renaming chain
14326 while Is_Subprogram (Result)
14328 Nkind (Parent (Declaration_Node (Result))) =
14329 N_Subprogram_Renaming_Declaration
14330 and then Present (Alias (Result))
14332 Result := Alias (Result);
14336 end Get_Base_Subprogram;
14342 procedure Initialize is
14347 -----------------------------
14348 -- Is_Config_Static_String --
14349 -----------------------------
14351 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14353 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14354 -- This is an internal recursive function that is just like the outer
14355 -- function except that it adds the string to the name buffer rather
14356 -- than placing the string in the name buffer.
14358 ------------------------------
14359 -- Add_Config_Static_String --
14360 ------------------------------
14362 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14369 if Nkind (N) = N_Op_Concat then
14370 if Add_Config_Static_String (Left_Opnd (N)) then
14371 N := Right_Opnd (N);
14377 if Nkind (N) /= N_String_Literal then
14378 Error_Msg_N ("string literal expected for pragma argument", N);
14382 for J in 1 .. String_Length (Strval (N)) loop
14383 C := Get_String_Char (Strval (N), J);
14385 if not In_Character_Range (C) then
14387 ("string literal contains invalid wide character",
14388 Sloc (N) + 1 + Source_Ptr (J));
14392 Add_Char_To_Name_Buffer (Get_Character (C));
14397 end Add_Config_Static_String;
14399 -- Start of processing for Is_Config_Static_String
14404 return Add_Config_Static_String (Arg);
14405 end Is_Config_Static_String;
14407 -----------------------------------------
14408 -- Is_Non_Significant_Pragma_Reference --
14409 -----------------------------------------
14411 -- This function makes use of the following static table which indicates
14412 -- whether a given pragma is significant.
14414 -- -1 indicates that references in any argument position are significant
14415 -- 0 indicates that appearance in any argument is not significant
14416 -- +n indicates that appearance as argument n is significant, but all
14417 -- other arguments are not significant
14418 -- 99 special processing required (e.g. for pragma Check)
14420 Sig_Flags : constant array (Pragma_Id) of Int :=
14421 (Pragma_AST_Entry => -1,
14422 Pragma_Abort_Defer => -1,
14423 Pragma_Ada_83 => -1,
14424 Pragma_Ada_95 => -1,
14425 Pragma_Ada_05 => -1,
14426 Pragma_Ada_2005 => -1,
14427 Pragma_Ada_12 => -1,
14428 Pragma_Ada_2012 => -1,
14429 Pragma_All_Calls_Remote => -1,
14430 Pragma_Annotate => -1,
14431 Pragma_Assert => -1,
14432 Pragma_Assertion_Policy => 0,
14433 Pragma_Assume_No_Invalid_Values => 0,
14434 Pragma_Asynchronous => -1,
14435 Pragma_Atomic => 0,
14436 Pragma_Atomic_Components => 0,
14437 Pragma_Attach_Handler => -1,
14438 Pragma_Check => 99,
14439 Pragma_Check_Name => 0,
14440 Pragma_Check_Policy => 0,
14441 Pragma_CIL_Constructor => -1,
14442 Pragma_CPP_Class => 0,
14443 Pragma_CPP_Constructor => 0,
14444 Pragma_CPP_Virtual => 0,
14445 Pragma_CPP_Vtable => 0,
14447 Pragma_C_Pass_By_Copy => 0,
14448 Pragma_Comment => 0,
14449 Pragma_Common_Object => -1,
14450 Pragma_Compile_Time_Error => -1,
14451 Pragma_Compile_Time_Warning => -1,
14452 Pragma_Compiler_Unit => 0,
14453 Pragma_Complete_Representation => 0,
14454 Pragma_Complex_Representation => 0,
14455 Pragma_Component_Alignment => -1,
14456 Pragma_Controlled => 0,
14457 Pragma_Convention => 0,
14458 Pragma_Convention_Identifier => 0,
14459 Pragma_Debug => -1,
14460 Pragma_Debug_Policy => 0,
14461 Pragma_Detect_Blocking => -1,
14462 Pragma_Default_Storage_Pool => -1,
14463 Pragma_Dimension => -1,
14464 Pragma_Discard_Names => 0,
14465 Pragma_Elaborate => -1,
14466 Pragma_Elaborate_All => -1,
14467 Pragma_Elaborate_Body => -1,
14468 Pragma_Elaboration_Checks => -1,
14469 Pragma_Eliminate => -1,
14470 Pragma_Export => -1,
14471 Pragma_Export_Exception => -1,
14472 Pragma_Export_Function => -1,
14473 Pragma_Export_Object => -1,
14474 Pragma_Export_Procedure => -1,
14475 Pragma_Export_Value => -1,
14476 Pragma_Export_Valued_Procedure => -1,
14477 Pragma_Extend_System => -1,
14478 Pragma_Extensions_Allowed => -1,
14479 Pragma_External => -1,
14480 Pragma_Favor_Top_Level => -1,
14481 Pragma_External_Name_Casing => -1,
14482 Pragma_Fast_Math => -1,
14483 Pragma_Finalize_Storage_Only => 0,
14484 Pragma_Float_Representation => 0,
14485 Pragma_Ident => -1,
14486 Pragma_Implemented => -1,
14487 Pragma_Implicit_Packing => 0,
14488 Pragma_Import => +2,
14489 Pragma_Import_Exception => 0,
14490 Pragma_Import_Function => 0,
14491 Pragma_Import_Object => 0,
14492 Pragma_Import_Procedure => 0,
14493 Pragma_Import_Valued_Procedure => 0,
14494 Pragma_Independent => 0,
14495 Pragma_Independent_Components => 0,
14496 Pragma_Initialize_Scalars => -1,
14497 Pragma_Inline => 0,
14498 Pragma_Inline_Always => 0,
14499 Pragma_Inline_Generic => 0,
14500 Pragma_Inspection_Point => -1,
14501 Pragma_Interface => +2,
14502 Pragma_Interface_Name => +2,
14503 Pragma_Interrupt_Handler => -1,
14504 Pragma_Interrupt_Priority => -1,
14505 Pragma_Interrupt_State => -1,
14506 Pragma_Invariant => -1,
14507 Pragma_Java_Constructor => -1,
14508 Pragma_Java_Interface => -1,
14509 Pragma_Keep_Names => 0,
14510 Pragma_License => -1,
14511 Pragma_Link_With => -1,
14512 Pragma_Linker_Alias => -1,
14513 Pragma_Linker_Constructor => -1,
14514 Pragma_Linker_Destructor => -1,
14515 Pragma_Linker_Options => -1,
14516 Pragma_Linker_Section => -1,
14518 Pragma_Locking_Policy => -1,
14519 Pragma_Long_Float => -1,
14520 Pragma_Machine_Attribute => -1,
14522 Pragma_Main_Storage => -1,
14523 Pragma_Memory_Size => -1,
14524 Pragma_No_Return => 0,
14525 Pragma_No_Body => 0,
14526 Pragma_No_Run_Time => -1,
14527 Pragma_No_Strict_Aliasing => -1,
14528 Pragma_Normalize_Scalars => -1,
14529 Pragma_Obsolescent => 0,
14530 Pragma_Optimize => -1,
14531 Pragma_Optimize_Alignment => -1,
14532 Pragma_Ordered => 0,
14535 Pragma_Passive => -1,
14536 Pragma_Preelaborable_Initialization => -1,
14537 Pragma_Polling => -1,
14538 Pragma_Persistent_BSS => 0,
14539 Pragma_Postcondition => -1,
14540 Pragma_Precondition => -1,
14541 Pragma_Predicate => -1,
14542 Pragma_Preelaborate => -1,
14543 Pragma_Preelaborate_05 => -1,
14544 Pragma_Priority => -1,
14545 Pragma_Priority_Specific_Dispatching => -1,
14546 Pragma_Profile => 0,
14547 Pragma_Profile_Warnings => 0,
14548 Pragma_Propagate_Exceptions => -1,
14549 Pragma_Psect_Object => -1,
14551 Pragma_Pure_05 => -1,
14552 Pragma_Pure_Function => -1,
14553 Pragma_Queuing_Policy => -1,
14554 Pragma_Ravenscar => -1,
14555 Pragma_Relative_Deadline => -1,
14556 Pragma_Remote_Call_Interface => -1,
14557 Pragma_Remote_Types => -1,
14558 Pragma_Restricted_Run_Time => -1,
14559 Pragma_Restriction_Warnings => -1,
14560 Pragma_Restrictions => -1,
14561 Pragma_Reviewable => -1,
14562 Pragma_Short_Circuit_And_Or => -1,
14563 Pragma_Share_Generic => -1,
14564 Pragma_Shared => -1,
14565 Pragma_Shared_Passive => -1,
14566 Pragma_Short_Descriptors => 0,
14567 Pragma_Source_File_Name => -1,
14568 Pragma_Source_File_Name_Project => -1,
14569 Pragma_Source_Reference => -1,
14570 Pragma_Storage_Size => -1,
14571 Pragma_Storage_Unit => -1,
14572 Pragma_Static_Elaboration_Desired => -1,
14573 Pragma_Stream_Convert => -1,
14574 Pragma_Style_Checks => -1,
14575 Pragma_Subtitle => -1,
14576 Pragma_Suppress => 0,
14577 Pragma_Suppress_Exception_Locations => 0,
14578 Pragma_Suppress_All => -1,
14579 Pragma_Suppress_Debug_Info => 0,
14580 Pragma_Suppress_Initialization => 0,
14581 Pragma_System_Name => -1,
14582 Pragma_Task_Dispatching_Policy => -1,
14583 Pragma_Task_Info => -1,
14584 Pragma_Task_Name => -1,
14585 Pragma_Task_Storage => 0,
14586 Pragma_Test_Case => -1,
14587 Pragma_Thread_Local_Storage => 0,
14588 Pragma_Time_Slice => -1,
14589 Pragma_Title => -1,
14590 Pragma_Unchecked_Union => 0,
14591 Pragma_Unimplemented_Unit => -1,
14592 Pragma_Universal_Aliasing => -1,
14593 Pragma_Universal_Data => -1,
14594 Pragma_Unmodified => -1,
14595 Pragma_Unreferenced => -1,
14596 Pragma_Unreferenced_Objects => -1,
14597 Pragma_Unreserve_All_Interrupts => -1,
14598 Pragma_Unsuppress => 0,
14599 Pragma_Use_VADS_Size => -1,
14600 Pragma_Validity_Checks => -1,
14601 Pragma_Volatile => 0,
14602 Pragma_Volatile_Components => 0,
14603 Pragma_Warnings => -1,
14604 Pragma_Weak_External => -1,
14605 Pragma_Wide_Character_Encoding => 0,
14606 Unknown_Pragma => 0);
14608 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14617 if Nkind (P) /= N_Pragma_Argument_Association then
14621 Id := Get_Pragma_Id (Parent (P));
14622 C := Sig_Flags (Id);
14634 -- For pragma Check, the first argument is not significant,
14635 -- the second and the third (if present) arguments are
14638 when Pragma_Check =>
14640 P = First (Pragma_Argument_Associations (Parent (P)));
14643 raise Program_Error;
14647 A := First (Pragma_Argument_Associations (Parent (P)));
14648 for J in 1 .. C - 1 loop
14656 return A = P; -- is this wrong way round ???
14659 end Is_Non_Significant_Pragma_Reference;
14661 ------------------------------
14662 -- Is_Pragma_String_Literal --
14663 ------------------------------
14665 -- This function returns true if the corresponding pragma argument is a
14666 -- static string expression. These are the only cases in which string
14667 -- literals can appear as pragma arguments. We also allow a string literal
14668 -- as the first argument to pragma Assert (although it will of course
14669 -- always generate a type error).
14671 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14672 Pragn : constant Node_Id := Parent (Par);
14673 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14674 Pname : constant Name_Id := Pragma_Name (Pragn);
14680 N := First (Assoc);
14687 if Pname = Name_Assert then
14690 elsif Pname = Name_Export then
14693 elsif Pname = Name_Ident then
14696 elsif Pname = Name_Import then
14699 elsif Pname = Name_Interface_Name then
14702 elsif Pname = Name_Linker_Alias then
14705 elsif Pname = Name_Linker_Section then
14708 elsif Pname = Name_Machine_Attribute then
14711 elsif Pname = Name_Source_File_Name then
14714 elsif Pname = Name_Source_Reference then
14717 elsif Pname = Name_Title then
14720 elsif Pname = Name_Subtitle then
14726 end Is_Pragma_String_Literal;
14728 ------------------------
14729 -- Preanalyze_TC_Args --
14730 ------------------------
14732 procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id) is
14734 -- Preanalyze the boolean expressions, we treat these as spec
14735 -- expressions (i.e. similar to a default expression).
14737 if Present (Arg_Req) then
14738 Preanalyze_Spec_Expression
14739 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
14742 if Present (Arg_Ens) then
14743 Preanalyze_Spec_Expression
14744 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
14746 end Preanalyze_TC_Args;
14748 --------------------------------------
14749 -- Process_Compilation_Unit_Pragmas --
14750 --------------------------------------
14752 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14754 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14755 -- strange because it comes at the end of the unit. Rational has the
14756 -- same name for a pragma, but treats it as a program unit pragma, In
14757 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14758 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14759 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14760 -- the context clause to ensure the correct processing.
14762 if Has_Pragma_Suppress_All (N) then
14763 Prepend_To (Context_Items (N),
14764 Make_Pragma (Sloc (N),
14765 Chars => Name_Suppress,
14766 Pragma_Argument_Associations => New_List (
14767 Make_Pragma_Argument_Association (Sloc (N),
14768 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14771 -- Nothing else to do at the current time!
14773 end Process_Compilation_Unit_Pragmas;
14784 --------------------------------
14785 -- Set_Encoded_Interface_Name --
14786 --------------------------------
14788 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14789 Str : constant String_Id := Strval (S);
14790 Len : constant Int := String_Length (Str);
14795 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14798 -- Stores encoded value of character code CC. The encoding we use an
14799 -- underscore followed by four lower case hex digits.
14805 procedure Encode is
14807 Store_String_Char (Get_Char_Code ('_'));
14809 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14811 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14813 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14815 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14818 -- Start of processing for Set_Encoded_Interface_Name
14821 -- If first character is asterisk, this is a link name, and we leave it
14822 -- completely unmodified. We also ignore null strings (the latter case
14823 -- happens only in error cases) and no encoding should occur for Java or
14824 -- AAMP interface names.
14827 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14828 or else VM_Target /= No_VM
14829 or else AAMP_On_Target
14831 Set_Interface_Name (E, S);
14836 CC := Get_String_Char (Str, J);
14838 exit when not In_Character_Range (CC);
14840 C := Get_Character (CC);
14842 exit when C /= '_' and then C /= '$'
14843 and then C not in '0' .. '9'
14844 and then C not in 'a' .. 'z'
14845 and then C not in 'A' .. 'Z';
14848 Set_Interface_Name (E, S);
14856 -- Here we need to encode. The encoding we use as follows:
14857 -- three underscores + four hex digits (lower case)
14861 for J in 1 .. String_Length (Str) loop
14862 CC := Get_String_Char (Str, J);
14864 if not In_Character_Range (CC) then
14867 C := Get_Character (CC);
14869 if C = '_' or else C = '$'
14870 or else C in '0' .. '9'
14871 or else C in 'a' .. 'z'
14872 or else C in 'A' .. 'Z'
14874 Store_String_Char (CC);
14881 Set_Interface_Name (E,
14882 Make_String_Literal (Sloc (S),
14883 Strval => End_String));
14885 end Set_Encoded_Interface_Name;
14887 -------------------
14888 -- Set_Unit_Name --
14889 -------------------
14891 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14896 if Nkind (N) = N_Identifier
14897 and then Nkind (With_Item) = N_Identifier
14899 Set_Entity (N, Entity (With_Item));
14901 elsif Nkind (N) = N_Selected_Component then
14902 Change_Selected_Component_To_Expanded_Name (N);
14903 Set_Entity (N, Entity (With_Item));
14904 Set_Entity (Selector_Name (N), Entity (N));
14906 Pref := Prefix (N);
14907 Scop := Scope (Entity (N));
14908 while Nkind (Pref) = N_Selected_Component loop
14909 Change_Selected_Component_To_Expanded_Name (Pref);
14910 Set_Entity (Selector_Name (Pref), Scop);
14911 Set_Entity (Pref, Scop);
14912 Pref := Prefix (Pref);
14913 Scop := Scope (Scop);
14916 Set_Entity (Pref, Scop);