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_String_Literal (Arg : Node_Id);
339 -- Check the specified argument Arg to make sure that it is a string
340 -- literal. If not give error and raise Pragma_Exit.
342 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
343 -- Check the specified argument Arg to make sure that it has the proper
344 -- syntactic form for a local name and meets the semantic requirements
345 -- for a local name. The local name is analyzed as part of the
346 -- processing for this call. In addition, the local name is required
347 -- to represent an entity at the library level.
349 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
350 -- Check the specified argument Arg to make sure that it has the proper
351 -- syntactic form for a local name and meets the semantic requirements
352 -- for a local name. The local name is analyzed as part of the
353 -- processing for this call.
355 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
356 -- Check the specified argument Arg to make sure that it is a valid
357 -- locking policy name. If not give error and raise Pragma_Exit.
359 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
360 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
361 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
362 -- Check the specified argument Arg to make sure that it is an
363 -- identifier whose name matches either N1 or N2 (or N3 if present).
364 -- If not then give error and raise Pragma_Exit.
366 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
367 -- Check the specified argument Arg to make sure that it is a valid
368 -- queuing policy name. If not give error and raise Pragma_Exit.
370 procedure Check_Arg_Is_Static_Expression
372 Typ : Entity_Id := Empty);
373 -- Check the specified argument Arg to make sure that it is a static
374 -- expression of the given type (i.e. it will be analyzed and resolved
375 -- using this type, which can be any valid argument to Resolve, e.g.
376 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
377 -- Typ is left Empty, then any static expression is allowed.
379 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
380 -- Check the specified argument Arg to make sure that it is a valid task
381 -- dispatching policy name. If not give error and raise Pragma_Exit.
383 procedure Check_Arg_Order (Names : Name_List);
384 -- Checks for an instance of two arguments with identifiers for the
385 -- current pragma which are not in the sequence indicated by Names,
386 -- and if so, generates a fatal message about bad order of arguments.
388 procedure Check_At_Least_N_Arguments (N : Nat);
389 -- Check there are at least N arguments present
391 procedure Check_At_Most_N_Arguments (N : Nat);
392 -- Check there are no more than N arguments present
394 procedure Check_Component
397 In_Variant_Part : Boolean := False);
398 -- Examine an Unchecked_Union component for correct use of per-object
399 -- constrained subtypes, and for restrictions on finalizable components.
400 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
401 -- should be set when Comp comes from a record variant.
403 procedure Check_Duplicate_Pragma (E : Entity_Id);
404 -- Check if a pragma of the same name as the current pragma is already
405 -- chained as a rep pragma to the given entity. If so give a message
406 -- about the duplicate, and then raise Pragma_Exit so does not return.
407 -- Also checks for delayed aspect specification node in the chain.
409 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
410 -- Nam is an N_String_Literal node containing the external name set by
411 -- an Import or Export pragma (or extended Import or Export pragma).
412 -- This procedure checks for possible duplications if this is the export
413 -- case, and if found, issues an appropriate error message.
415 procedure Check_First_Subtype (Arg : Node_Id);
416 -- Checks that Arg, whose expression is an entity name, references a
419 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
420 -- Checks that the given argument has an identifier, and if so, requires
421 -- it to match the given identifier name. If there is no identifier, or
422 -- a non-matching identifier, then an error message is given and
423 -- Pragma_Exit is raised.
425 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
426 -- Checks that the given argument has an identifier, and if so, requires
427 -- it to match one of the given identifier names. If there is no
428 -- identifier, or a non-matching identifier, then an error message is
429 -- given and Pragma_Exit is raised.
431 procedure Check_In_Main_Program;
432 -- Common checks for pragmas that appear within a main program
433 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
435 procedure Check_Interrupt_Or_Attach_Handler;
436 -- Common processing for first argument of pragma Interrupt_Handler or
437 -- pragma Attach_Handler.
439 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
440 -- Check that pragma appears in a declarative part, or in a package
441 -- specification, i.e. that it does not occur in a statement sequence
444 procedure Check_No_Identifier (Arg : Node_Id);
445 -- Checks that the given argument does not have an identifier. If
446 -- an identifier is present, then an error message is issued, and
447 -- Pragma_Exit is raised.
449 procedure Check_No_Identifiers;
450 -- Checks that none of the arguments to the pragma has an identifier.
451 -- If any argument has an identifier, then an error message is issued,
452 -- and Pragma_Exit is raised.
454 procedure Check_No_Link_Name;
455 -- Checks that no link name is specified
457 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
458 -- Checks if the given argument has an identifier, and if so, requires
459 -- it to match the given identifier name. If there is a non-matching
460 -- identifier, then an error message is given and Pragma_Exit is raised.
462 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
463 -- Checks if the given argument has an identifier, and if so, requires
464 -- it to match the given identifier name. If there is a non-matching
465 -- identifier, then an error message is given and Pragma_Exit is raised.
466 -- In this version of the procedure, the identifier name is given as
467 -- a string with lower case letters.
469 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
470 -- Called to process a precondition or postcondition pragma. There are
473 -- The pragma appears after a subprogram spec
475 -- If the corresponding check is not enabled, the pragma is analyzed
476 -- but otherwise ignored and control returns with In_Body set False.
478 -- If the check is enabled, then the first step is to analyze the
479 -- pragma, but this is skipped if the subprogram spec appears within
480 -- a package specification (because this is the case where we delay
481 -- analysis till the end of the spec). Then (whether or not it was
482 -- analyzed), the pragma is chained to the subprogram in question
483 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
484 -- caller with In_Body set False.
486 -- The pragma appears at the start of subprogram body declarations
488 -- In this case an immediate return to the caller is made with
489 -- In_Body set True, and the pragma is NOT analyzed.
491 -- In all other cases, an error message for bad placement is given
493 procedure Check_Static_Constraint (Constr : Node_Id);
494 -- Constr is a constraint from an N_Subtype_Indication node from a
495 -- component constraint in an Unchecked_Union type. This routine checks
496 -- that the constraint is static as required by the restrictions for
499 procedure Check_Test_Case;
500 -- Called to process a test-case pragma. The treatment is similar to the
501 -- one for pre- and postcondition in Check_Precondition_Postcondition.
502 -- There are three cases:
504 -- The pragma appears after a subprogram spec
506 -- The first step is to analyze the pragma, but this is skipped if
507 -- the subprogram spec appears within a package specification
508 -- (because this is the case where we delay analysis till the end of
509 -- the spec). Then (whether or not it was analyzed), the pragma is
510 -- chained to the subprogram in question (using Spec_TC_List and
513 -- The pragma appears at the start of subprogram body declarations
515 -- In this case an immediate return to the caller is made, and the
516 -- pragma is NOT analyzed.
518 -- In all other cases, an error message for bad placement is given
520 procedure Check_Valid_Configuration_Pragma;
521 -- Legality checks for placement of a configuration pragma
523 procedure Check_Valid_Library_Unit_Pragma;
524 -- Legality checks for library unit pragmas. A special case arises for
525 -- pragmas in generic instances that come from copies of the original
526 -- library unit pragmas in the generic templates. In the case of other
527 -- than library level instantiations these can appear in contexts which
528 -- would normally be invalid (they only apply to the original template
529 -- and to library level instantiations), and they are simply ignored,
530 -- which is implemented by rewriting them as null statements.
532 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
533 -- Check an Unchecked_Union variant for lack of nested variants and
534 -- presence of at least one component. UU_Typ is the related Unchecked_
537 procedure Error_Pragma (Msg : String);
538 pragma No_Return (Error_Pragma);
539 -- Outputs error message for current pragma. The message contains a %
540 -- that will be replaced with the pragma name, and the flag is placed
541 -- on the pragma itself. Pragma_Exit is then raised.
543 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
544 pragma No_Return (Error_Pragma_Arg);
545 -- Outputs error message for current pragma. The message may contain
546 -- a % that will be replaced with the pragma name. The parameter Arg
547 -- may either be a pragma argument association, in which case the flag
548 -- is placed on the expression of this association, or an expression,
549 -- in which case the flag is placed directly on the expression. The
550 -- message is placed using Error_Msg_N, so the message may also contain
551 -- an & insertion character which will reference the given Arg value.
552 -- After placing the message, Pragma_Exit is raised.
554 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
555 pragma No_Return (Error_Pragma_Arg);
556 -- Similar to above form of Error_Pragma_Arg except that two messages
557 -- are provided, the second is a continuation comment starting with \.
559 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
560 pragma No_Return (Error_Pragma_Arg_Ident);
561 -- Outputs error message for current pragma. The message may contain
562 -- a % that will be replaced with the pragma name. The parameter Arg
563 -- must be a pragma argument association with a non-empty identifier
564 -- (i.e. its Chars field must be set), and the error message is placed
565 -- on the identifier. The message is placed using Error_Msg_N so
566 -- the message may also contain an & insertion character which will
567 -- reference the identifier. After placing the message, Pragma_Exit
570 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
571 pragma No_Return (Error_Pragma_Ref);
572 -- Outputs error message for current pragma. The message may contain
573 -- a % that will be replaced with the pragma name. The parameter Ref
574 -- must be an entity whose name can be referenced by & and sloc by #.
575 -- After placing the message, Pragma_Exit is raised.
577 function Find_Lib_Unit_Name return Entity_Id;
578 -- Used for a library unit pragma to find the entity to which the
579 -- library unit pragma applies, returns the entity found.
581 procedure Find_Program_Unit_Name (Id : Node_Id);
582 -- If the pragma is a compilation unit pragma, the id must denote the
583 -- compilation unit in the same compilation, and the pragma must appear
584 -- in the list of preceding or trailing pragmas. If it is a program
585 -- unit pragma that is not a compilation unit pragma, then the
586 -- identifier must be visible.
588 function Find_Unique_Parameterless_Procedure
590 Arg : Node_Id) return Entity_Id;
591 -- Used for a procedure pragma to find the unique parameterless
592 -- procedure identified by Name, returns it if it exists, otherwise
593 -- errors out and uses Arg as the pragma argument for the message.
595 procedure Fix_Error (Msg : in out String);
596 -- This is called prior to issuing an error message. Msg is a string
597 -- which typically contains the substring pragma. If the current pragma
598 -- comes from an aspect, each such "pragma" substring is replaced with
599 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
600 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
602 procedure Gather_Associations
604 Args : out Args_List);
605 -- This procedure is used to gather the arguments for a pragma that
606 -- permits arbitrary ordering of parameters using the normal rules
607 -- for named and positional parameters. The Names argument is a list
608 -- of Name_Id values that corresponds to the allowed pragma argument
609 -- association identifiers in order. The result returned in Args is
610 -- a list of corresponding expressions that are the pragma arguments.
611 -- Note that this is a list of expressions, not of pragma argument
612 -- associations (Gather_Associations has completely checked all the
613 -- optional identifiers when it returns). An entry in Args is Empty
614 -- on return if the corresponding argument is not present.
616 procedure GNAT_Pragma;
617 -- Called for all GNAT defined pragmas to check the relevant restriction
618 -- (No_Implementation_Pragmas).
620 function Is_Before_First_Decl
621 (Pragma_Node : Node_Id;
622 Decls : List_Id) return Boolean;
623 -- Return True if Pragma_Node is before the first declarative item in
624 -- Decls where Decls is the list of declarative items.
626 function Is_Configuration_Pragma return Boolean;
627 -- Determines if the placement of the current pragma is appropriate
628 -- for a configuration pragma.
630 function Is_In_Context_Clause return Boolean;
631 -- Returns True if pragma appears within the context clause of a unit,
632 -- and False for any other placement (does not generate any messages).
634 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
635 -- Analyzes the argument, and determines if it is a static string
636 -- expression, returns True if so, False if non-static or not String.
638 procedure Pragma_Misplaced;
639 pragma No_Return (Pragma_Misplaced);
640 -- Issue fatal error message for misplaced pragma
642 procedure Process_Atomic_Shared_Volatile;
643 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
644 -- Shared is an obsolete Ada 83 pragma, treated as being identical
645 -- in effect to pragma Atomic.
647 procedure Process_Compile_Time_Warning_Or_Error;
648 -- Common processing for Compile_Time_Error and Compile_Time_Warning
650 procedure Process_Convention
651 (C : out Convention_Id;
652 Ent : out Entity_Id);
653 -- Common processing for Convention, Interface, Import and Export.
654 -- Checks first two arguments of pragma, and sets the appropriate
655 -- convention value in the specified entity or entities. On return
656 -- C is the convention, Ent is the referenced entity.
658 procedure Process_Extended_Import_Export_Exception_Pragma
659 (Arg_Internal : Node_Id;
660 Arg_External : Node_Id;
663 -- Common processing for the pragmas Import/Export_Exception. The three
664 -- arguments correspond to the three named parameters of the pragma. An
665 -- argument is empty if the corresponding parameter is not present in
668 procedure Process_Extended_Import_Export_Object_Pragma
669 (Arg_Internal : Node_Id;
670 Arg_External : Node_Id;
672 -- Common processing for the pragmas Import/Export_Object. The three
673 -- arguments correspond to the three named parameters of the pragmas. An
674 -- argument is empty if the corresponding parameter is not present in
677 procedure Process_Extended_Import_Export_Internal_Arg
678 (Arg_Internal : Node_Id := Empty);
679 -- Common processing for all extended Import and Export pragmas. The
680 -- argument is the pragma parameter for the Internal argument. If
681 -- Arg_Internal is empty or inappropriate, an error message is posted.
682 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
683 -- set to identify the referenced entity.
685 procedure Process_Extended_Import_Export_Subprogram_Pragma
686 (Arg_Internal : Node_Id;
687 Arg_External : Node_Id;
688 Arg_Parameter_Types : Node_Id;
689 Arg_Result_Type : Node_Id := Empty;
690 Arg_Mechanism : Node_Id;
691 Arg_Result_Mechanism : Node_Id := Empty;
692 Arg_First_Optional_Parameter : Node_Id := Empty);
693 -- Common processing for all extended Import and Export pragmas applying
694 -- to subprograms. The caller omits any arguments that do not apply to
695 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
696 -- only in the Import_Function and Export_Function cases). The argument
697 -- names correspond to the allowed pragma association identifiers.
699 procedure Process_Generic_List;
700 -- Common processing for Share_Generic and Inline_Generic
702 procedure Process_Import_Or_Interface;
703 -- Common processing for Import of Interface
705 procedure Process_Import_Predefined_Type;
706 -- Processing for completing a type with pragma Import. This is used
707 -- to declare types that match predefined C types, especially for cases
708 -- without corresponding Ada predefined type.
710 procedure Process_Inline (Active : Boolean);
711 -- Common processing for Inline and Inline_Always. The parameter
712 -- indicates if the inline pragma is active, i.e. if it should actually
713 -- cause inlining to occur.
715 procedure Process_Interface_Name
716 (Subprogram_Def : Entity_Id;
719 -- Given the last two arguments of pragma Import, pragma Export, or
720 -- pragma Interface_Name, performs validity checks and sets the
721 -- Interface_Name field of the given subprogram entity to the
722 -- appropriate external or link name, depending on the arguments given.
723 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
724 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
725 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
726 -- nor Link_Arg is present, the interface name is set to the default
727 -- from the subprogram name.
729 procedure Process_Interrupt_Or_Attach_Handler;
730 -- Common processing for Interrupt and Attach_Handler pragmas
732 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
733 -- Common processing for Restrictions and Restriction_Warnings pragmas.
734 -- Warn is True for Restriction_Warnings, or for Restrictions if the
735 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
736 -- is not set in the Restrictions case.
738 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
739 -- Common processing for Suppress and Unsuppress. The boolean parameter
740 -- Suppress_Case is True for the Suppress case, and False for the
743 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
744 -- This procedure sets the Is_Exported flag for the given entity,
745 -- checking that the entity was not previously imported. Arg is
746 -- the argument that specified the entity. A check is also made
747 -- for exporting inappropriate entities.
749 procedure Set_Extended_Import_Export_External_Name
750 (Internal_Ent : Entity_Id;
751 Arg_External : Node_Id);
752 -- Common processing for all extended import export pragmas. The first
753 -- argument, Internal_Ent, is the internal entity, which has already
754 -- been checked for validity by the caller. Arg_External is from the
755 -- Import or Export pragma, and may be null if no External parameter
756 -- was present. If Arg_External is present and is a non-null string
757 -- (a null string is treated as the default), then the Interface_Name
758 -- field of Internal_Ent is set appropriately.
760 procedure Set_Imported (E : Entity_Id);
761 -- This procedure sets the Is_Imported flag for the given entity,
762 -- checking that it is not previously exported or imported.
764 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
765 -- Mech is a parameter passing mechanism (see Import_Function syntax
766 -- for MECHANISM_NAME). This routine checks that the mechanism argument
767 -- has the right form, and if not issues an error message. If the
768 -- argument has the right form then the Mechanism field of Ent is
769 -- set appropriately.
771 procedure Set_Ravenscar_Profile (N : Node_Id);
772 -- Activate the set of configuration pragmas and restrictions that make
773 -- up the Ravenscar Profile. N is the corresponding pragma node, which
774 -- is used for error messages on any constructs that violate the
777 ---------------------
778 -- Ada_2005_Pragma --
779 ---------------------
781 procedure Ada_2005_Pragma is
783 if Ada_Version <= Ada_95 then
784 Check_Restriction (No_Implementation_Pragmas, N);
788 ---------------------
789 -- Ada_2012_Pragma --
790 ---------------------
792 procedure Ada_2012_Pragma is
794 if Ada_Version <= Ada_2005 then
795 Check_Restriction (No_Implementation_Pragmas, N);
799 --------------------------
800 -- Check_Ada_83_Warning --
801 --------------------------
803 procedure Check_Ada_83_Warning is
805 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
806 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
808 end Check_Ada_83_Warning;
810 ---------------------
811 -- Check_Arg_Count --
812 ---------------------
814 procedure Check_Arg_Count (Required : Nat) is
816 if Arg_Count /= Required then
817 Error_Pragma ("wrong number of arguments for pragma%");
821 --------------------------------
822 -- Check_Arg_Is_External_Name --
823 --------------------------------
825 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
826 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
829 if Nkind (Argx) = N_Identifier then
833 Analyze_And_Resolve (Argx, Standard_String);
835 if Is_OK_Static_Expression (Argx) then
838 elsif Etype (Argx) = Any_Type then
841 -- An interesting special case, if we have a string literal and
842 -- we are in Ada 83 mode, then we allow it even though it will
843 -- not be flagged as static. This allows expected Ada 83 mode
844 -- use of external names which are string literals, even though
845 -- technically these are not static in Ada 83.
847 elsif Ada_Version = Ada_83
848 and then Nkind (Argx) = N_String_Literal
852 -- Static expression that raises Constraint_Error. This has
853 -- already been flagged, so just exit from pragma processing.
855 elsif Is_Static_Expression (Argx) then
858 -- Here we have a real error (non-static expression)
861 Error_Msg_Name_1 := Pname;
865 "argument for pragma% must be a identifier or "
866 & "static string expression!";
869 Flag_Non_Static_Expr (Msg, Argx);
874 end Check_Arg_Is_External_Name;
876 -----------------------------
877 -- Check_Arg_Is_Identifier --
878 -----------------------------
880 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
881 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
883 if Nkind (Argx) /= N_Identifier then
885 ("argument for pragma% must be identifier", Argx);
887 end Check_Arg_Is_Identifier;
889 ----------------------------------
890 -- Check_Arg_Is_Integer_Literal --
891 ----------------------------------
893 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
894 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
896 if Nkind (Argx) /= N_Integer_Literal then
898 ("argument for pragma% must be integer literal", Argx);
900 end Check_Arg_Is_Integer_Literal;
902 ---------------------------------
903 -- Check_Arg_Is_String_Literal --
904 ---------------------------------
906 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
907 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
909 if Nkind (Argx) /= N_String_Literal then
911 ("argument for pragma% must be string literal", Argx);
913 end Check_Arg_Is_String_Literal;
915 -------------------------------------------
916 -- Check_Arg_Is_Library_Level_Local_Name --
917 -------------------------------------------
921 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
922 -- | library_unit_NAME
924 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
926 Check_Arg_Is_Local_Name (Arg);
928 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
929 and then Comes_From_Source (N)
932 ("argument for pragma% must be library level entity", Arg);
934 end Check_Arg_Is_Library_Level_Local_Name;
936 -----------------------------
937 -- Check_Arg_Is_Local_Name --
938 -----------------------------
942 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
943 -- | library_unit_NAME
945 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
946 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
951 if Nkind (Argx) not in N_Direct_Name
952 and then (Nkind (Argx) /= N_Attribute_Reference
953 or else Present (Expressions (Argx))
954 or else Nkind (Prefix (Argx)) /= N_Identifier)
955 and then (not Is_Entity_Name (Argx)
956 or else not Is_Compilation_Unit (Entity (Argx)))
958 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
961 -- No further check required if not an entity name
963 if not Is_Entity_Name (Argx) then
969 Ent : constant Entity_Id := Entity (Argx);
970 Scop : constant Entity_Id := Scope (Ent);
972 -- Case of a pragma applied to a compilation unit: pragma must
973 -- occur immediately after the program unit in the compilation.
975 if Is_Compilation_Unit (Ent) then
977 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
979 -- Case of pragma placed immediately after spec
981 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
984 -- Case of pragma placed immediately after body
986 elsif Nkind (Decl) = N_Subprogram_Declaration
987 and then Present (Corresponding_Body (Decl))
991 (Parent (Unit_Declaration_Node
992 (Corresponding_Body (Decl))));
994 -- All other cases are illegal
1001 -- Special restricted placement rule from 10.2.1(11.8/2)
1003 elsif Is_Generic_Formal (Ent)
1004 and then Prag_Id = Pragma_Preelaborable_Initialization
1006 OK := List_Containing (N) =
1007 Generic_Formal_Declarations
1008 (Unit_Declaration_Node (Scop));
1010 -- Default case, just check that the pragma occurs in the scope
1011 -- of the entity denoted by the name.
1014 OK := Current_Scope = Scop;
1019 ("pragma% argument must be in same declarative part", Arg);
1023 end Check_Arg_Is_Local_Name;
1025 ---------------------------------
1026 -- Check_Arg_Is_Locking_Policy --
1027 ---------------------------------
1029 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1030 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1033 Check_Arg_Is_Identifier (Argx);
1035 if not Is_Locking_Policy_Name (Chars (Argx)) then
1036 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1038 end Check_Arg_Is_Locking_Policy;
1040 -------------------------
1041 -- Check_Arg_Is_One_Of --
1042 -------------------------
1044 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1045 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1048 Check_Arg_Is_Identifier (Argx);
1050 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1051 Error_Msg_Name_2 := N1;
1052 Error_Msg_Name_3 := N2;
1053 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1055 end Check_Arg_Is_One_Of;
1057 procedure Check_Arg_Is_One_Of
1059 N1, N2, N3 : Name_Id)
1061 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1064 Check_Arg_Is_Identifier (Argx);
1066 if Chars (Argx) /= N1
1067 and then Chars (Argx) /= N2
1068 and then Chars (Argx) /= N3
1070 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1072 end Check_Arg_Is_One_Of;
1074 procedure Check_Arg_Is_One_Of
1076 N1, N2, N3, N4 : Name_Id)
1078 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1081 Check_Arg_Is_Identifier (Argx);
1083 if Chars (Argx) /= N1
1084 and then Chars (Argx) /= N2
1085 and then Chars (Argx) /= N3
1086 and then Chars (Argx) /= N4
1088 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1090 end Check_Arg_Is_One_Of;
1092 ---------------------------------
1093 -- Check_Arg_Is_Queuing_Policy --
1094 ---------------------------------
1096 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1097 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1100 Check_Arg_Is_Identifier (Argx);
1102 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1103 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1105 end Check_Arg_Is_Queuing_Policy;
1107 ------------------------------------
1108 -- Check_Arg_Is_Static_Expression --
1109 ------------------------------------
1111 procedure Check_Arg_Is_Static_Expression
1113 Typ : Entity_Id := Empty)
1115 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1118 if Present (Typ) then
1119 Analyze_And_Resolve (Argx, Typ);
1121 Analyze_And_Resolve (Argx);
1124 if Is_OK_Static_Expression (Argx) then
1127 elsif Etype (Argx) = Any_Type then
1130 -- An interesting special case, if we have a string literal and we
1131 -- are in Ada 83 mode, then we allow it even though it will not be
1132 -- flagged as static. This allows the use of Ada 95 pragmas like
1133 -- Import in Ada 83 mode. They will of course be flagged with
1134 -- warnings as usual, but will not cause errors.
1136 elsif Ada_Version = Ada_83
1137 and then Nkind (Argx) = N_String_Literal
1141 -- Static expression that raises Constraint_Error. This has already
1142 -- been flagged, so just exit from pragma processing.
1144 elsif Is_Static_Expression (Argx) then
1147 -- Finally, we have a real error
1150 Error_Msg_Name_1 := Pname;
1154 "argument for pragma% must be a static expression!";
1157 Flag_Non_Static_Expr (Msg, Argx);
1162 end Check_Arg_Is_Static_Expression;
1164 ------------------------------------------
1165 -- Check_Arg_Is_Task_Dispatching_Policy --
1166 ------------------------------------------
1168 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1169 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1172 Check_Arg_Is_Identifier (Argx);
1174 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1176 ("& is not a valid task dispatching policy name", Argx);
1178 end Check_Arg_Is_Task_Dispatching_Policy;
1180 ---------------------
1181 -- Check_Arg_Order --
1182 ---------------------
1184 procedure Check_Arg_Order (Names : Name_List) is
1187 Highest_So_Far : Natural := 0;
1188 -- Highest index in Names seen do far
1192 for J in 1 .. Arg_Count loop
1193 if Chars (Arg) /= No_Name then
1194 for K in Names'Range loop
1195 if Chars (Arg) = Names (K) then
1196 if K < Highest_So_Far then
1197 Error_Msg_Name_1 := Pname;
1199 ("parameters out of order for pragma%", Arg);
1200 Error_Msg_Name_1 := Names (K);
1201 Error_Msg_Name_2 := Names (Highest_So_Far);
1202 Error_Msg_N ("\% must appear before %", Arg);
1206 Highest_So_Far := K;
1214 end Check_Arg_Order;
1216 --------------------------------
1217 -- Check_At_Least_N_Arguments --
1218 --------------------------------
1220 procedure Check_At_Least_N_Arguments (N : Nat) is
1222 if Arg_Count < N then
1223 Error_Pragma ("too few arguments for pragma%");
1225 end Check_At_Least_N_Arguments;
1227 -------------------------------
1228 -- Check_At_Most_N_Arguments --
1229 -------------------------------
1231 procedure Check_At_Most_N_Arguments (N : Nat) is
1234 if Arg_Count > N then
1236 for J in 1 .. N loop
1238 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1241 end Check_At_Most_N_Arguments;
1243 ---------------------
1244 -- Check_Component --
1245 ---------------------
1247 procedure Check_Component
1250 In_Variant_Part : Boolean := False)
1252 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1253 Sindic : constant Node_Id :=
1254 Subtype_Indication (Component_Definition (Comp));
1255 Typ : constant Entity_Id := Etype (Comp_Id);
1257 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1258 -- Determine whether entity Id appears inside a generic body.
1259 -- Shouldn't this be in a more general place ???
1261 -------------------------
1262 -- Inside_Generic_Body --
1263 -------------------------
1265 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1270 while Present (S) and then S /= Standard_Standard loop
1271 if Ekind (S) = E_Generic_Package
1272 and then In_Package_Body (S)
1281 end Inside_Generic_Body;
1283 -- Start of processing for Check_Component
1286 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1287 -- object constraint, then the component type shall be an Unchecked_
1290 if Nkind (Sindic) = N_Subtype_Indication
1291 and then Has_Per_Object_Constraint (Comp_Id)
1292 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1295 ("component subtype subject to per-object constraint " &
1296 "must be an Unchecked_Union", Comp);
1298 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1299 -- the body of a generic unit, or within the body of any of its
1300 -- descendant library units, no part of the type of a component
1301 -- declared in a variant_part of the unchecked union type shall be of
1302 -- a formal private type or formal private extension declared within
1303 -- the formal part of the generic unit.
1305 elsif Ada_Version >= Ada_2012
1306 and then Inside_Generic_Body (UU_Typ)
1307 and then In_Variant_Part
1308 and then Is_Private_Type (Typ)
1309 and then Is_Generic_Type (Typ)
1312 ("component of Unchecked_Union cannot be of generic type", Comp);
1314 elsif Needs_Finalization (Typ) then
1316 ("component of Unchecked_Union cannot be controlled", Comp);
1318 elsif Has_Task (Typ) then
1320 ("component of Unchecked_Union cannot have tasks", Comp);
1322 end Check_Component;
1324 ----------------------------
1325 -- Check_Duplicate_Pragma --
1326 ----------------------------
1328 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1332 -- Nothing to do if this pragma comes from an aspect specification,
1333 -- since we could not be duplicating a pragma, and we dealt with the
1334 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1336 if From_Aspect_Specification (N) then
1340 -- Otherwise current pragma may duplicate previous pragma or a
1341 -- previously given aspect specification for the same pragma.
1343 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1346 Error_Msg_Name_1 := Pragma_Name (N);
1347 Error_Msg_Sloc := Sloc (P);
1349 if Nkind (P) = N_Aspect_Specification
1350 or else From_Aspect_Specification (P)
1352 Error_Msg_NE ("aspect% for & previously given#", N, E);
1354 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1359 end Check_Duplicate_Pragma;
1361 ----------------------------------
1362 -- Check_Duplicated_Export_Name --
1363 ----------------------------------
1365 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1366 String_Val : constant String_Id := Strval (Nam);
1369 -- We are only interested in the export case, and in the case of
1370 -- generics, it is the instance, not the template, that is the
1371 -- problem (the template will generate a warning in any case).
1373 if not Inside_A_Generic
1374 and then (Prag_Id = Pragma_Export
1376 Prag_Id = Pragma_Export_Procedure
1378 Prag_Id = Pragma_Export_Valued_Procedure
1380 Prag_Id = Pragma_Export_Function)
1382 for J in Externals.First .. Externals.Last loop
1383 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1384 Error_Msg_Sloc := Sloc (Externals.Table (J));
1385 Error_Msg_N ("external name duplicates name given#", Nam);
1390 Externals.Append (Nam);
1392 end Check_Duplicated_Export_Name;
1394 -------------------------
1395 -- Check_First_Subtype --
1396 -------------------------
1398 procedure Check_First_Subtype (Arg : Node_Id) is
1399 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1400 Ent : constant Entity_Id := Entity (Argx);
1403 if Is_First_Subtype (Ent) then
1406 elsif Is_Type (Ent) then
1408 ("pragma% cannot apply to subtype", Argx);
1410 elsif Is_Object (Ent) then
1412 ("pragma% cannot apply to object, requires a type", Argx);
1416 ("pragma% cannot apply to&, requires a type", Argx);
1418 end Check_First_Subtype;
1420 ----------------------
1421 -- Check_Identifier --
1422 ----------------------
1424 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1427 and then Nkind (Arg) = N_Pragma_Argument_Association
1429 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1430 Error_Msg_Name_1 := Pname;
1431 Error_Msg_Name_2 := Id;
1432 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1436 end Check_Identifier;
1438 --------------------------------
1439 -- Check_Identifier_Is_One_Of --
1440 --------------------------------
1442 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1445 and then Nkind (Arg) = N_Pragma_Argument_Association
1447 if Chars (Arg) = No_Name then
1448 Error_Msg_Name_1 := Pname;
1449 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1452 elsif Chars (Arg) /= N1
1453 and then Chars (Arg) /= N2
1455 Error_Msg_Name_1 := Pname;
1456 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1460 end Check_Identifier_Is_One_Of;
1462 ---------------------------
1463 -- Check_In_Main_Program --
1464 ---------------------------
1466 procedure Check_In_Main_Program is
1467 P : constant Node_Id := Parent (N);
1470 -- Must be at in subprogram body
1472 if Nkind (P) /= N_Subprogram_Body then
1473 Error_Pragma ("% pragma allowed only in subprogram");
1475 -- Otherwise warn if obviously not main program
1477 elsif Present (Parameter_Specifications (Specification (P)))
1478 or else not Is_Compilation_Unit (Defining_Entity (P))
1480 Error_Msg_Name_1 := Pname;
1482 ("?pragma% is only effective in main program", N);
1484 end Check_In_Main_Program;
1486 ---------------------------------------
1487 -- Check_Interrupt_Or_Attach_Handler --
1488 ---------------------------------------
1490 procedure Check_Interrupt_Or_Attach_Handler is
1491 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1492 Handler_Proc, Proc_Scope : Entity_Id;
1497 if Prag_Id = Pragma_Interrupt_Handler then
1498 Check_Restriction (No_Dynamic_Attachment, N);
1501 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1502 Proc_Scope := Scope (Handler_Proc);
1504 -- On AAMP only, a pragma Interrupt_Handler is supported for
1505 -- nonprotected parameterless procedures.
1507 if not AAMP_On_Target
1508 or else Prag_Id = Pragma_Attach_Handler
1510 if Ekind (Proc_Scope) /= E_Protected_Type then
1512 ("argument of pragma% must be protected procedure", Arg1);
1515 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1516 Error_Pragma ("pragma% must be in protected definition");
1520 if not Is_Library_Level_Entity (Proc_Scope)
1521 or else (AAMP_On_Target
1522 and then not Is_Library_Level_Entity (Handler_Proc))
1525 ("argument for pragma% must be library level entity", Arg1);
1528 -- AI05-0033: A pragma cannot appear within a generic body, because
1529 -- instance can be in a nested scope. The check that protected type
1530 -- is itself a library-level declaration is done elsewhere.
1532 -- Note: we omit this check in Codepeer mode to properly handle code
1533 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1535 if Inside_A_Generic then
1536 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1537 and then In_Package_Body (Scope (Current_Scope))
1538 and then not CodePeer_Mode
1540 Error_Pragma ("pragma% cannot be used inside a generic");
1543 end Check_Interrupt_Or_Attach_Handler;
1545 -------------------------------------------
1546 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1547 -------------------------------------------
1549 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1558 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1561 elsif Nkind_In (P, N_Package_Specification,
1566 -- Note: the following tests seem a little peculiar, because
1567 -- they test for bodies, but if we were in the statement part
1568 -- of the body, we would already have hit the handled statement
1569 -- sequence, so the only way we get here is by being in the
1570 -- declarative part of the body.
1572 elsif Nkind_In (P, N_Subprogram_Body,
1583 Error_Pragma ("pragma% is not in declarative part or package spec");
1584 end Check_Is_In_Decl_Part_Or_Package_Spec;
1586 -------------------------
1587 -- Check_No_Identifier --
1588 -------------------------
1590 procedure Check_No_Identifier (Arg : Node_Id) is
1592 if Nkind (Arg) = N_Pragma_Argument_Association
1593 and then Chars (Arg) /= No_Name
1595 Error_Pragma_Arg_Ident
1596 ("pragma% does not permit identifier& here", Arg);
1598 end Check_No_Identifier;
1600 --------------------------
1601 -- Check_No_Identifiers --
1602 --------------------------
1604 procedure Check_No_Identifiers is
1607 if Arg_Count > 0 then
1609 while Present (Arg_Node) loop
1610 Check_No_Identifier (Arg_Node);
1614 end Check_No_Identifiers;
1616 ------------------------
1617 -- Check_No_Link_Name --
1618 ------------------------
1620 procedure Check_No_Link_Name is
1623 and then Chars (Arg3) = Name_Link_Name
1628 if Present (Arg4) then
1630 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1632 end Check_No_Link_Name;
1634 -------------------------------
1635 -- Check_Optional_Identifier --
1636 -------------------------------
1638 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1641 and then Nkind (Arg) = N_Pragma_Argument_Association
1642 and then Chars (Arg) /= No_Name
1644 if Chars (Arg) /= Id then
1645 Error_Msg_Name_1 := Pname;
1646 Error_Msg_Name_2 := Id;
1647 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1651 end Check_Optional_Identifier;
1653 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1655 Name_Buffer (1 .. Id'Length) := Id;
1656 Name_Len := Id'Length;
1657 Check_Optional_Identifier (Arg, Name_Find);
1658 end Check_Optional_Identifier;
1660 --------------------------------------
1661 -- Check_Precondition_Postcondition --
1662 --------------------------------------
1664 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1668 procedure Chain_PPC (PO : Node_Id);
1669 -- If PO is an entry or a [generic] subprogram declaration node, then
1670 -- the precondition/postcondition applies to this subprogram and the
1671 -- processing for the pragma is completed. Otherwise the pragma is
1678 procedure Chain_PPC (PO : Node_Id) is
1683 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1684 if not From_Aspect_Specification (N) then
1686 ("pragma% cannot be applied to abstract subprogram");
1688 elsif Class_Present (N) then
1693 ("aspect % requires ''Class for abstract subprogram");
1696 -- AI05-0230: The same restriction applies to null procedures. For
1697 -- compatibility with earlier uses of the Ada pragma, apply this
1698 -- rule only to aspect specifications.
1700 -- The above discrpency needs documentation. Robert is dubious
1701 -- about whether it is a good idea ???
1703 elsif Nkind (PO) = N_Subprogram_Declaration
1704 and then Nkind (Specification (PO)) = N_Procedure_Specification
1705 and then Null_Present (Specification (PO))
1706 and then From_Aspect_Specification (N)
1707 and then not Class_Present (N)
1710 ("aspect % requires ''Class for null procedure");
1712 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1713 N_Generic_Subprogram_Declaration,
1714 N_Entry_Declaration)
1719 -- Here if we have [generic] subprogram or entry declaration
1721 if Nkind (PO) = N_Entry_Declaration then
1722 S := Defining_Entity (PO);
1724 S := Defining_Unit_Name (Specification (PO));
1727 -- Make sure we do not have the case of a precondition pragma when
1728 -- the Pre'Class aspect is present.
1730 -- We do this by looking at pragmas already chained to the entity
1731 -- since the aspect derived pragma will be put on this list first.
1733 if Pragma_Name (N) = Name_Precondition then
1734 if not From_Aspect_Specification (N) then
1735 P := Spec_PPC_List (Contract (S));
1736 while Present (P) loop
1737 if Pragma_Name (P) = Name_Precondition
1738 and then From_Aspect_Specification (P)
1739 and then Class_Present (P)
1741 Error_Msg_Sloc := Sloc (P);
1743 ("pragma% not allowed, `Pre''Class` aspect given#");
1746 P := Next_Pragma (P);
1751 -- Similarly check for Pre with inherited Pre'Class. Note that
1752 -- we cover the aspect case as well here.
1754 if Pragma_Name (N) = Name_Precondition
1755 and then not Class_Present (N)
1758 Inherited : constant Subprogram_List :=
1759 Inherited_Subprograms (S);
1763 for J in Inherited'Range loop
1764 P := Spec_PPC_List (Contract (Inherited (J)));
1765 while Present (P) loop
1766 if Pragma_Name (P) = Name_Precondition
1767 and then Class_Present (P)
1769 Error_Msg_Sloc := Sloc (P);
1771 ("pragma% not allowed, `Pre''Class` "
1772 & "aspect inherited from#");
1775 P := Next_Pragma (P);
1781 -- Note: we do not analyze the pragma at this point. Instead we
1782 -- delay this analysis until the end of the declarative part in
1783 -- which the pragma appears. This implements the required delay
1784 -- in this analysis, allowing forward references. The analysis
1785 -- happens at the end of Analyze_Declarations.
1787 -- Chain spec PPC pragma to list for subprogram
1789 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1790 Set_Spec_PPC_List (Contract (S), N);
1792 -- Return indicating spec case
1798 -- Start of processing for Check_Precondition_Postcondition
1801 if not Is_List_Member (N) then
1805 -- Preanalyze message argument if present. Visibility in this
1806 -- argument is established at the point of pragma occurrence.
1808 if Arg_Count = 2 then
1809 Check_Optional_Identifier (Arg2, Name_Message);
1810 Preanalyze_Spec_Expression
1811 (Get_Pragma_Arg (Arg2), Standard_String);
1814 -- Record if pragma is enabled
1816 if Check_Enabled (Pname) then
1817 Set_SCO_Pragma_Enabled (Loc);
1820 -- If we are within an inlined body, the legality of the pragma
1821 -- has been checked already.
1823 if In_Inlined_Body then
1828 -- Search prior declarations
1831 while Present (Prev (P)) loop
1834 -- If the previous node is a generic subprogram, do not go to to
1835 -- the original node, which is the unanalyzed tree: we need to
1836 -- attach the pre/postconditions to the analyzed version at this
1837 -- point. They get propagated to the original tree when analyzing
1838 -- the corresponding body.
1840 if Nkind (P) not in N_Generic_Declaration then
1841 PO := Original_Node (P);
1846 -- Skip past prior pragma
1848 if Nkind (PO) = N_Pragma then
1851 -- Skip stuff not coming from source
1853 elsif not Comes_From_Source (PO) then
1855 -- The condition may apply to a subprogram instantiation
1857 if Nkind (PO) = N_Subprogram_Declaration
1858 and then Present (Generic_Parent (Specification (PO)))
1863 -- For all other cases of non source code, do nothing
1869 -- Only remaining possibility is subprogram declaration
1877 -- If we fall through loop, pragma is at start of list, so see if it
1878 -- is at the start of declarations of a subprogram body.
1880 if Nkind (Parent (N)) = N_Subprogram_Body
1881 and then List_Containing (N) = Declarations (Parent (N))
1883 if Operating_Mode /= Generate_Code
1884 or else Inside_A_Generic
1886 -- Analyze pragma expression for correctness and for ASIS use
1888 Preanalyze_Spec_Expression
1889 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1895 -- See if it is in the pragmas after a library level subprogram
1897 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1898 Chain_PPC (Unit (Parent (Parent (N))));
1902 -- If we fall through, pragma was misplaced
1905 end Check_Precondition_Postcondition;
1907 -----------------------------
1908 -- Check_Static_Constraint --
1909 -----------------------------
1911 -- Note: for convenience in writing this procedure, in addition to
1912 -- the officially (i.e. by spec) allowed argument which is always a
1913 -- constraint, it also allows ranges and discriminant associations.
1914 -- Above is not clear ???
1916 procedure Check_Static_Constraint (Constr : Node_Id) is
1918 procedure Require_Static (E : Node_Id);
1919 -- Require given expression to be static expression
1921 --------------------
1922 -- Require_Static --
1923 --------------------
1925 procedure Require_Static (E : Node_Id) is
1927 if not Is_OK_Static_Expression (E) then
1928 Flag_Non_Static_Expr
1929 ("non-static constraint not allowed in Unchecked_Union!", E);
1934 -- Start of processing for Check_Static_Constraint
1937 case Nkind (Constr) is
1938 when N_Discriminant_Association =>
1939 Require_Static (Expression (Constr));
1942 Require_Static (Low_Bound (Constr));
1943 Require_Static (High_Bound (Constr));
1945 when N_Attribute_Reference =>
1946 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1947 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1949 when N_Range_Constraint =>
1950 Check_Static_Constraint (Range_Expression (Constr));
1952 when N_Index_Or_Discriminant_Constraint =>
1956 IDC := First (Constraints (Constr));
1957 while Present (IDC) loop
1958 Check_Static_Constraint (IDC);
1966 end Check_Static_Constraint;
1968 ---------------------
1969 -- Check_Test_Case --
1970 ---------------------
1972 procedure Check_Test_Case is
1976 procedure Chain_TC (PO : Node_Id);
1977 -- If PO is an entry or a [generic] subprogram declaration node, then
1978 -- the test-case applies to this subprogram and the processing for
1979 -- the pragma is completed. Otherwise the pragma is misplaced.
1985 procedure Chain_TC (PO : Node_Id) is
1989 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1990 if From_Aspect_Specification (N) then
1992 ("aspect% cannot be applied to abstract subprogram");
1995 ("pragma% cannot be applied to abstract subprogram");
1998 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1999 N_Generic_Subprogram_Declaration,
2000 N_Entry_Declaration)
2005 -- Here if we have [generic] subprogram or entry declaration
2007 if Nkind (PO) = N_Entry_Declaration then
2008 S := Defining_Entity (PO);
2010 S := Defining_Unit_Name (Specification (PO));
2013 -- Note: we do not analyze the pragma at this point. Instead we
2014 -- delay this analysis until the end of the declarative part in
2015 -- which the pragma appears. This implements the required delay
2016 -- in this analysis, allowing forward references. The analysis
2017 -- happens at the end of Analyze_Declarations.
2019 -- There should not be another test case with the same name
2020 -- associated to this subprogram.
2023 Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2027 TC := Spec_TC_List (Contract (S));
2028 while Present (TC) loop
2031 (Name, Get_Name_From_Test_Case_Pragma (TC))
2033 Error_Msg_Sloc := Sloc (TC);
2035 if From_Aspect_Specification (N) then
2036 Error_Pragma ("name for aspect% is already used#");
2038 Error_Pragma ("name for pragma% is already used#");
2042 TC := Next_Pragma (TC);
2046 -- Chain spec TC pragma to list for subprogram
2048 Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2049 Set_Spec_TC_List (Contract (S), N);
2052 -- Start of processing for Check_Test_Case
2055 if not Is_List_Member (N) then
2059 -- Search prior declarations
2062 while Present (Prev (P)) loop
2065 -- If the previous node is a generic subprogram, do not go to to
2066 -- the original node, which is the unanalyzed tree: we need to
2067 -- attach the test-case to the analyzed version at this point.
2068 -- They get propagated to the original tree when analyzing the
2069 -- corresponding body.
2071 if Nkind (P) not in N_Generic_Declaration then
2072 PO := Original_Node (P);
2077 -- Skip past prior pragma
2079 if Nkind (PO) = N_Pragma then
2082 -- Skip stuff not coming from source
2084 elsif not Comes_From_Source (PO) then
2087 -- Only remaining possibility is subprogram declaration
2095 -- If we fall through loop, pragma is at start of list, so see if it
2096 -- is in the pragmas after a library level subprogram.
2098 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2099 Chain_TC (Unit (Parent (Parent (N))));
2103 -- If we fall through, pragma was misplaced
2106 end Check_Test_Case;
2108 --------------------------------------
2109 -- Check_Valid_Configuration_Pragma --
2110 --------------------------------------
2112 -- A configuration pragma must appear in the context clause of a
2113 -- compilation unit, and only other pragmas may precede it. Note that
2114 -- the test also allows use in a configuration pragma file.
2116 procedure Check_Valid_Configuration_Pragma is
2118 if not Is_Configuration_Pragma then
2119 Error_Pragma ("incorrect placement for configuration pragma%");
2121 end Check_Valid_Configuration_Pragma;
2123 -------------------------------------
2124 -- Check_Valid_Library_Unit_Pragma --
2125 -------------------------------------
2127 procedure Check_Valid_Library_Unit_Pragma is
2129 Parent_Node : Node_Id;
2130 Unit_Name : Entity_Id;
2131 Unit_Kind : Node_Kind;
2132 Unit_Node : Node_Id;
2133 Sindex : Source_File_Index;
2136 if not Is_List_Member (N) then
2140 Plist := List_Containing (N);
2141 Parent_Node := Parent (Plist);
2143 if Parent_Node = Empty then
2146 -- Case of pragma appearing after a compilation unit. In this case
2147 -- it must have an argument with the corresponding name and must
2148 -- be part of the following pragmas of its parent.
2150 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2151 if Plist /= Pragmas_After (Parent_Node) then
2154 elsif Arg_Count = 0 then
2156 ("argument required if outside compilation unit");
2159 Check_No_Identifiers;
2160 Check_Arg_Count (1);
2161 Unit_Node := Unit (Parent (Parent_Node));
2162 Unit_Kind := Nkind (Unit_Node);
2164 Analyze (Get_Pragma_Arg (Arg1));
2166 if Unit_Kind = N_Generic_Subprogram_Declaration
2167 or else Unit_Kind = N_Subprogram_Declaration
2169 Unit_Name := Defining_Entity (Unit_Node);
2171 elsif Unit_Kind in N_Generic_Instantiation then
2172 Unit_Name := Defining_Entity (Unit_Node);
2175 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2178 if Chars (Unit_Name) /=
2179 Chars (Entity (Get_Pragma_Arg (Arg1)))
2182 ("pragma% argument is not current unit name", Arg1);
2185 if Ekind (Unit_Name) = E_Package
2186 and then Present (Renamed_Entity (Unit_Name))
2188 Error_Pragma ("pragma% not allowed for renamed package");
2192 -- Pragma appears other than after a compilation unit
2195 -- Here we check for the generic instantiation case and also
2196 -- for the case of processing a generic formal package. We
2197 -- detect these cases by noting that the Sloc on the node
2198 -- does not belong to the current compilation unit.
2200 Sindex := Source_Index (Current_Sem_Unit);
2202 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2203 Rewrite (N, Make_Null_Statement (Loc));
2206 -- If before first declaration, the pragma applies to the
2207 -- enclosing unit, and the name if present must be this name.
2209 elsif Is_Before_First_Decl (N, Plist) then
2210 Unit_Node := Unit_Declaration_Node (Current_Scope);
2211 Unit_Kind := Nkind (Unit_Node);
2213 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2216 elsif Unit_Kind = N_Subprogram_Body
2217 and then not Acts_As_Spec (Unit_Node)
2221 elsif Nkind (Parent_Node) = N_Package_Body then
2224 elsif Nkind (Parent_Node) = N_Package_Specification
2225 and then Plist = Private_Declarations (Parent_Node)
2229 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2230 or else Nkind (Parent_Node) =
2231 N_Generic_Subprogram_Declaration)
2232 and then Plist = Generic_Formal_Declarations (Parent_Node)
2236 elsif Arg_Count > 0 then
2237 Analyze (Get_Pragma_Arg (Arg1));
2239 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2241 ("name in pragma% must be enclosing unit", Arg1);
2244 -- It is legal to have no argument in this context
2250 -- Error if not before first declaration. This is because a
2251 -- library unit pragma argument must be the name of a library
2252 -- unit (RM 10.1.5(7)), but the only names permitted in this
2253 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2254 -- generic subprogram declarations or generic instantiations.
2258 ("pragma% misplaced, must be before first declaration");
2262 end Check_Valid_Library_Unit_Pragma;
2268 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2269 Clist : constant Node_Id := Component_List (Variant);
2273 if not Is_Non_Empty_List (Component_Items (Clist)) then
2275 ("Unchecked_Union may not have empty component list",
2280 Comp := First (Component_Items (Clist));
2281 while Present (Comp) loop
2282 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2291 procedure Error_Pragma (Msg : String) is
2292 MsgF : String := Msg;
2294 Error_Msg_Name_1 := Pname;
2296 Error_Msg_N (MsgF, N);
2300 ----------------------
2301 -- Error_Pragma_Arg --
2302 ----------------------
2304 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2305 MsgF : String := Msg;
2307 Error_Msg_Name_1 := Pname;
2309 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2311 end Error_Pragma_Arg;
2313 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2314 MsgF : String := Msg1;
2316 Error_Msg_Name_1 := Pname;
2318 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2319 Error_Pragma_Arg (Msg2, Arg);
2320 end Error_Pragma_Arg;
2322 ----------------------------
2323 -- Error_Pragma_Arg_Ident --
2324 ----------------------------
2326 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2327 MsgF : String := Msg;
2329 Error_Msg_Name_1 := Pname;
2331 Error_Msg_N (MsgF, Arg);
2333 end Error_Pragma_Arg_Ident;
2335 ----------------------
2336 -- Error_Pragma_Ref --
2337 ----------------------
2339 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2340 MsgF : String := Msg;
2342 Error_Msg_Name_1 := Pname;
2344 Error_Msg_Sloc := Sloc (Ref);
2345 Error_Msg_NE (MsgF, N, Ref);
2347 end Error_Pragma_Ref;
2349 ------------------------
2350 -- Find_Lib_Unit_Name --
2351 ------------------------
2353 function Find_Lib_Unit_Name return Entity_Id is
2355 -- Return inner compilation unit entity, for case of nested
2356 -- categorization pragmas. This happens in generic unit.
2358 if Nkind (Parent (N)) = N_Package_Specification
2359 and then Defining_Entity (Parent (N)) /= Current_Scope
2361 return Defining_Entity (Parent (N));
2363 return Current_Scope;
2365 end Find_Lib_Unit_Name;
2367 ----------------------------
2368 -- Find_Program_Unit_Name --
2369 ----------------------------
2371 procedure Find_Program_Unit_Name (Id : Node_Id) is
2372 Unit_Name : Entity_Id;
2373 Unit_Kind : Node_Kind;
2374 P : constant Node_Id := Parent (N);
2377 if Nkind (P) = N_Compilation_Unit then
2378 Unit_Kind := Nkind (Unit (P));
2380 if Unit_Kind = N_Subprogram_Declaration
2381 or else Unit_Kind = N_Package_Declaration
2382 or else Unit_Kind in N_Generic_Declaration
2384 Unit_Name := Defining_Entity (Unit (P));
2386 if Chars (Id) = Chars (Unit_Name) then
2387 Set_Entity (Id, Unit_Name);
2388 Set_Etype (Id, Etype (Unit_Name));
2390 Set_Etype (Id, Any_Type);
2392 ("cannot find program unit referenced by pragma%");
2396 Set_Etype (Id, Any_Type);
2397 Error_Pragma ("pragma% inapplicable to this unit");
2403 end Find_Program_Unit_Name;
2405 -----------------------------------------
2406 -- Find_Unique_Parameterless_Procedure --
2407 -----------------------------------------
2409 function Find_Unique_Parameterless_Procedure
2411 Arg : Node_Id) return Entity_Id
2413 Proc : Entity_Id := Empty;
2416 -- The body of this procedure needs some comments ???
2418 if not Is_Entity_Name (Name) then
2420 ("argument of pragma% must be entity name", Arg);
2422 elsif not Is_Overloaded (Name) then
2423 Proc := Entity (Name);
2425 if Ekind (Proc) /= E_Procedure
2426 or else Present (First_Formal (Proc))
2429 ("argument of pragma% must be parameterless procedure", Arg);
2434 Found : Boolean := False;
2436 Index : Interp_Index;
2439 Get_First_Interp (Name, Index, It);
2440 while Present (It.Nam) loop
2443 if Ekind (Proc) = E_Procedure
2444 and then No (First_Formal (Proc))
2448 Set_Entity (Name, Proc);
2449 Set_Is_Overloaded (Name, False);
2452 ("ambiguous handler name for pragma% ", Arg);
2456 Get_Next_Interp (Index, It);
2461 ("argument of pragma% must be parameterless procedure",
2464 Proc := Entity (Name);
2470 end Find_Unique_Parameterless_Procedure;
2476 procedure Fix_Error (Msg : in out String) is
2478 if From_Aspect_Specification (N) then
2479 for J in Msg'First .. Msg'Last - 5 loop
2480 if Msg (J .. J + 5) = "pragma" then
2481 Msg (J .. J + 5) := "aspect";
2485 if Error_Msg_Name_1 = Name_Precondition then
2486 Error_Msg_Name_1 := Name_Pre;
2487 elsif Error_Msg_Name_1 = Name_Postcondition then
2488 Error_Msg_Name_1 := Name_Post;
2493 -------------------------
2494 -- Gather_Associations --
2495 -------------------------
2497 procedure Gather_Associations
2499 Args : out Args_List)
2504 -- Initialize all parameters to Empty
2506 for J in Args'Range loop
2510 -- That's all we have to do if there are no argument associations
2512 if No (Pragma_Argument_Associations (N)) then
2516 -- Otherwise first deal with any positional parameters present
2518 Arg := First (Pragma_Argument_Associations (N));
2519 for Index in Args'Range loop
2520 exit when No (Arg) or else Chars (Arg) /= No_Name;
2521 Args (Index) := Get_Pragma_Arg (Arg);
2525 -- Positional parameters all processed, if any left, then we
2526 -- have too many positional parameters.
2528 if Present (Arg) and then Chars (Arg) = No_Name then
2530 ("too many positional associations for pragma%", Arg);
2533 -- Process named parameters if any are present
2535 while Present (Arg) loop
2536 if Chars (Arg) = No_Name then
2538 ("positional association cannot follow named association",
2542 for Index in Names'Range loop
2543 if Names (Index) = Chars (Arg) then
2544 if Present (Args (Index)) then
2546 ("duplicate argument association for pragma%", Arg);
2548 Args (Index) := Get_Pragma_Arg (Arg);
2553 if Index = Names'Last then
2554 Error_Msg_Name_1 := Pname;
2555 Error_Msg_N ("pragma% does not allow & argument", Arg);
2557 -- Check for possible misspelling
2559 for Index1 in Names'Range loop
2560 if Is_Bad_Spelling_Of
2561 (Chars (Arg), Names (Index1))
2563 Error_Msg_Name_1 := Names (Index1);
2564 Error_Msg_N -- CODEFIX
2565 ("\possible misspelling of%", Arg);
2577 end Gather_Associations;
2583 procedure GNAT_Pragma is
2585 Check_Restriction (No_Implementation_Pragmas, N);
2588 --------------------------
2589 -- Is_Before_First_Decl --
2590 --------------------------
2592 function Is_Before_First_Decl
2593 (Pragma_Node : Node_Id;
2594 Decls : List_Id) return Boolean
2596 Item : Node_Id := First (Decls);
2599 -- Only other pragmas can come before this pragma
2602 if No (Item) or else Nkind (Item) /= N_Pragma then
2605 elsif Item = Pragma_Node then
2611 end Is_Before_First_Decl;
2613 -----------------------------
2614 -- Is_Configuration_Pragma --
2615 -----------------------------
2617 -- A configuration pragma must appear in the context clause of a
2618 -- compilation unit, and only other pragmas may precede it. Note that
2619 -- the test below also permits use in a configuration pragma file.
2621 function Is_Configuration_Pragma return Boolean is
2622 Lis : constant List_Id := List_Containing (N);
2623 Par : constant Node_Id := Parent (N);
2627 -- If no parent, then we are in the configuration pragma file,
2628 -- so the placement is definitely appropriate.
2633 -- Otherwise we must be in the context clause of a compilation unit
2634 -- and the only thing allowed before us in the context list is more
2635 -- configuration pragmas.
2637 elsif Nkind (Par) = N_Compilation_Unit
2638 and then Context_Items (Par) = Lis
2645 elsif Nkind (Prg) /= N_Pragma then
2655 end Is_Configuration_Pragma;
2657 --------------------------
2658 -- Is_In_Context_Clause --
2659 --------------------------
2661 function Is_In_Context_Clause return Boolean is
2663 Parent_Node : Node_Id;
2666 if not Is_List_Member (N) then
2670 Plist := List_Containing (N);
2671 Parent_Node := Parent (Plist);
2673 if Parent_Node = Empty
2674 or else Nkind (Parent_Node) /= N_Compilation_Unit
2675 or else Context_Items (Parent_Node) /= Plist
2682 end Is_In_Context_Clause;
2684 ---------------------------------
2685 -- Is_Static_String_Expression --
2686 ---------------------------------
2688 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2689 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2692 Analyze_And_Resolve (Argx);
2693 return Is_OK_Static_Expression (Argx)
2694 and then Nkind (Argx) = N_String_Literal;
2695 end Is_Static_String_Expression;
2697 ----------------------
2698 -- Pragma_Misplaced --
2699 ----------------------
2701 procedure Pragma_Misplaced is
2703 Error_Pragma ("incorrect placement of pragma%");
2704 end Pragma_Misplaced;
2706 ------------------------------------
2707 -- Process Atomic_Shared_Volatile --
2708 ------------------------------------
2710 procedure Process_Atomic_Shared_Volatile is
2717 procedure Set_Atomic (E : Entity_Id);
2718 -- Set given type as atomic, and if no explicit alignment was given,
2719 -- set alignment to unknown, since back end knows what the alignment
2720 -- requirements are for atomic arrays. Note: this step is necessary
2721 -- for derived types.
2727 procedure Set_Atomic (E : Entity_Id) is
2731 if not Has_Alignment_Clause (E) then
2732 Set_Alignment (E, Uint_0);
2736 -- Start of processing for Process_Atomic_Shared_Volatile
2739 Check_Ada_83_Warning;
2740 Check_No_Identifiers;
2741 Check_Arg_Count (1);
2742 Check_Arg_Is_Local_Name (Arg1);
2743 E_Id := Get_Pragma_Arg (Arg1);
2745 if Etype (E_Id) = Any_Type then
2750 D := Declaration_Node (E);
2753 -- Check duplicate before we chain ourselves!
2755 Check_Duplicate_Pragma (E);
2757 -- Now check appropriateness of the entity
2760 if Rep_Item_Too_Early (E, N)
2762 Rep_Item_Too_Late (E, N)
2766 Check_First_Subtype (Arg1);
2769 if Prag_Id /= Pragma_Volatile then
2771 Set_Atomic (Underlying_Type (E));
2772 Set_Atomic (Base_Type (E));
2775 -- Attribute belongs on the base type. If the view of the type is
2776 -- currently private, it also belongs on the underlying type.
2778 Set_Is_Volatile (Base_Type (E));
2779 Set_Is_Volatile (Underlying_Type (E));
2781 Set_Treat_As_Volatile (E);
2782 Set_Treat_As_Volatile (Underlying_Type (E));
2784 elsif K = N_Object_Declaration
2785 or else (K = N_Component_Declaration
2786 and then Original_Record_Component (E) = E)
2788 if Rep_Item_Too_Late (E, N) then
2792 if Prag_Id /= Pragma_Volatile then
2795 -- If the object declaration has an explicit initialization, a
2796 -- temporary may have to be created to hold the expression, to
2797 -- ensure that access to the object remain atomic.
2799 if Nkind (Parent (E)) = N_Object_Declaration
2800 and then Present (Expression (Parent (E)))
2802 Set_Has_Delayed_Freeze (E);
2805 -- An interesting improvement here. If an object of type X is
2806 -- declared atomic, and the type X is not atomic, that's a
2807 -- pity, since it may not have appropriate alignment etc. We
2808 -- can rescue this in the special case where the object and
2809 -- type are in the same unit by just setting the type as
2810 -- atomic, so that the back end will process it as atomic.
2812 Utyp := Underlying_Type (Etype (E));
2815 and then Sloc (E) > No_Location
2816 and then Sloc (Utyp) > No_Location
2818 Get_Source_File_Index (Sloc (E)) =
2819 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2821 Set_Is_Atomic (Underlying_Type (Etype (E)));
2825 Set_Is_Volatile (E);
2826 Set_Treat_As_Volatile (E);
2830 ("inappropriate entity for pragma%", Arg1);
2832 end Process_Atomic_Shared_Volatile;
2834 -------------------------------------------
2835 -- Process_Compile_Time_Warning_Or_Error --
2836 -------------------------------------------
2838 procedure Process_Compile_Time_Warning_Or_Error is
2839 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2842 Check_Arg_Count (2);
2843 Check_No_Identifiers;
2844 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2845 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2847 if Compile_Time_Known_Value (Arg1x) then
2848 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2850 Str : constant String_Id :=
2851 Strval (Get_Pragma_Arg (Arg2));
2852 Len : constant Int := String_Length (Str);
2857 Cent : constant Entity_Id :=
2858 Cunit_Entity (Current_Sem_Unit);
2860 Force : constant Boolean :=
2861 Prag_Id = Pragma_Compile_Time_Warning
2863 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2864 and then (Ekind (Cent) /= E_Package
2865 or else not In_Private_Part (Cent));
2866 -- Set True if this is the warning case, and we are in the
2867 -- visible part of a package spec, or in a subprogram spec,
2868 -- in which case we want to force the client to see the
2869 -- warning, even though it is not in the main unit.
2872 -- Loop through segments of message separated by line feeds.
2873 -- We output these segments as separate messages with
2874 -- continuation marks for all but the first.
2879 Error_Msg_Strlen := 0;
2881 -- Loop to copy characters from argument to error message
2885 exit when Ptr > Len;
2886 CC := Get_String_Char (Str, Ptr);
2889 -- Ignore wide chars ??? else store character
2891 if In_Character_Range (CC) then
2892 C := Get_Character (CC);
2893 exit when C = ASCII.LF;
2894 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2895 Error_Msg_String (Error_Msg_Strlen) := C;
2899 -- Here with one line ready to go
2901 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2903 -- If this is a warning in a spec, then we want clients
2904 -- to see the warning, so mark the message with the
2905 -- special sequence !! to force the warning. In the case
2906 -- of a package spec, we do not force this if we are in
2907 -- the private part of the spec.
2910 if Cont = False then
2911 Error_Msg_N ("<~!!", Arg1);
2914 Error_Msg_N ("\<~!!", Arg1);
2917 -- Error, rather than warning, or in a body, so we do not
2918 -- need to force visibility for client (error will be
2919 -- output in any case, and this is the situation in which
2920 -- we do not want a client to get a warning, since the
2921 -- warning is in the body or the spec private part).
2924 if Cont = False then
2925 Error_Msg_N ("<~", Arg1);
2928 Error_Msg_N ("\<~", Arg1);
2932 exit when Ptr > Len;
2937 end Process_Compile_Time_Warning_Or_Error;
2939 ------------------------
2940 -- Process_Convention --
2941 ------------------------
2943 procedure Process_Convention
2944 (C : out Convention_Id;
2945 Ent : out Entity_Id)
2951 Comp_Unit : Unit_Number_Type;
2953 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2954 -- Called if we have more than one Export/Import/Convention pragma.
2955 -- This is generally illegal, but we have a special case of allowing
2956 -- Import and Interface to coexist if they specify the convention in
2957 -- a consistent manner. We are allowed to do this, since Interface is
2958 -- an implementation defined pragma, and we choose to do it since we
2959 -- know Rational allows this combination. S is the entity id of the
2960 -- subprogram in question. This procedure also sets the special flag
2961 -- Import_Interface_Present in both pragmas in the case where we do
2962 -- have matching Import and Interface pragmas.
2964 procedure Set_Convention_From_Pragma (E : Entity_Id);
2965 -- Set convention in entity E, and also flag that the entity has a
2966 -- convention pragma. If entity is for a private or incomplete type,
2967 -- also set convention and flag on underlying type. This procedure
2968 -- also deals with the special case of C_Pass_By_Copy convention.
2970 -------------------------------
2971 -- Diagnose_Multiple_Pragmas --
2972 -------------------------------
2974 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2975 Pdec : constant Node_Id := Declaration_Node (S);
2979 function Same_Convention (Decl : Node_Id) return Boolean;
2980 -- Decl is a pragma node. This function returns True if this
2981 -- pragma has a first argument that is an identifier with a
2982 -- Chars field corresponding to the Convention_Id C.
2984 function Same_Name (Decl : Node_Id) return Boolean;
2985 -- Decl is a pragma node. This function returns True if this
2986 -- pragma has a second argument that is an identifier with a
2987 -- Chars field that matches the Chars of the current subprogram.
2989 ---------------------
2990 -- Same_Convention --
2991 ---------------------
2993 function Same_Convention (Decl : Node_Id) return Boolean is
2994 Arg1 : constant Node_Id :=
2995 First (Pragma_Argument_Associations (Decl));
2998 if Present (Arg1) then
3000 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3002 if Nkind (Arg) = N_Identifier
3003 and then Is_Convention_Name (Chars (Arg))
3004 and then Get_Convention_Id (Chars (Arg)) = C
3012 end Same_Convention;
3018 function Same_Name (Decl : Node_Id) return Boolean is
3019 Arg1 : constant Node_Id :=
3020 First (Pragma_Argument_Associations (Decl));
3028 Arg2 := Next (Arg1);
3035 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3037 if Nkind (Arg) = N_Identifier
3038 and then Chars (Arg) = Chars (S)
3047 -- Start of processing for Diagnose_Multiple_Pragmas
3052 -- Definitely give message if we have Convention/Export here
3054 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3057 -- If we have an Import or Export, scan back from pragma to
3058 -- find any previous pragma applying to the same procedure.
3059 -- The scan will be terminated by the start of the list, or
3060 -- hitting the subprogram declaration. This won't allow one
3061 -- pragma to appear in the public part and one in the private
3062 -- part, but that seems very unlikely in practice.
3066 while Present (Decl) and then Decl /= Pdec loop
3068 -- Look for pragma with same name as us
3070 if Nkind (Decl) = N_Pragma
3071 and then Same_Name (Decl)
3073 -- Give error if same as our pragma or Export/Convention
3075 if Pragma_Name (Decl) = Name_Export
3077 Pragma_Name (Decl) = Name_Convention
3079 Pragma_Name (Decl) = Pragma_Name (N)
3083 -- Case of Import/Interface or the other way round
3085 elsif Pragma_Name (Decl) = Name_Interface
3087 Pragma_Name (Decl) = Name_Import
3089 -- Here we know that we have Import and Interface. It
3090 -- doesn't matter which way round they are. See if
3091 -- they specify the same convention. If so, all OK,
3092 -- and set special flags to stop other messages
3094 if Same_Convention (Decl) then
3095 Set_Import_Interface_Present (N);
3096 Set_Import_Interface_Present (Decl);
3099 -- If different conventions, special message
3102 Error_Msg_Sloc := Sloc (Decl);
3104 ("convention differs from that given#", Arg1);
3114 -- Give message if needed if we fall through those tests
3118 ("at most one Convention/Export/Import pragma is allowed",
3121 end Diagnose_Multiple_Pragmas;
3123 --------------------------------
3124 -- Set_Convention_From_Pragma --
3125 --------------------------------
3127 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3129 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3130 -- for an overridden dispatching operation. Technically this is
3131 -- an amendment and should only be done in Ada 2005 mode. However,
3132 -- this is clearly a mistake, since the problem that is addressed
3133 -- by this AI is that there is a clear gap in the RM!
3135 if Is_Dispatching_Operation (E)
3136 and then Present (Overridden_Operation (E))
3137 and then C /= Convention (Overridden_Operation (E))
3140 ("cannot change convention for " &
3141 "overridden dispatching operation",
3145 -- Set the convention
3147 Set_Convention (E, C);
3148 Set_Has_Convention_Pragma (E);
3150 if Is_Incomplete_Or_Private_Type (E)
3151 and then Present (Underlying_Type (E))
3153 Set_Convention (Underlying_Type (E), C);
3154 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3157 -- A class-wide type should inherit the convention of the specific
3158 -- root type (although this isn't specified clearly by the RM).
3160 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3161 Set_Convention (Class_Wide_Type (E), C);
3164 -- If the entity is a record type, then check for special case of
3165 -- C_Pass_By_Copy, which is treated the same as C except that the
3166 -- special record flag is set. This convention is only permitted
3167 -- on record types (see AI95-00131).
3169 if Cname = Name_C_Pass_By_Copy then
3170 if Is_Record_Type (E) then
3171 Set_C_Pass_By_Copy (Base_Type (E));
3172 elsif Is_Incomplete_Or_Private_Type (E)
3173 and then Is_Record_Type (Underlying_Type (E))
3175 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3178 ("C_Pass_By_Copy convention allowed only for record type",
3183 -- If the entity is a derived boolean type, check for the special
3184 -- case of convention C, C++, or Fortran, where we consider any
3185 -- nonzero value to represent true.
3187 if Is_Discrete_Type (E)
3188 and then Root_Type (Etype (E)) = Standard_Boolean
3194 C = Convention_Fortran)
3196 Set_Nonzero_Is_True (Base_Type (E));
3198 end Set_Convention_From_Pragma;
3200 -- Start of processing for Process_Convention
3203 Check_At_Least_N_Arguments (2);
3204 Check_Optional_Identifier (Arg1, Name_Convention);
3205 Check_Arg_Is_Identifier (Arg1);
3206 Cname := Chars (Get_Pragma_Arg (Arg1));
3208 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3209 -- tested again below to set the critical flag).
3211 if Cname = Name_C_Pass_By_Copy then
3214 -- Otherwise we must have something in the standard convention list
3216 elsif Is_Convention_Name (Cname) then
3217 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3219 -- In DEC VMS, it seems that there is an undocumented feature that
3220 -- any unrecognized convention is treated as the default, which for
3221 -- us is convention C. It does not seem so terrible to do this
3222 -- unconditionally, silently in the VMS case, and with a warning
3223 -- in the non-VMS case.
3226 if Warn_On_Export_Import and not OpenVMS_On_Target then
3228 ("?unrecognized convention name, C assumed",
3229 Get_Pragma_Arg (Arg1));
3235 Check_Optional_Identifier (Arg2, Name_Entity);
3236 Check_Arg_Is_Local_Name (Arg2);
3238 Id := Get_Pragma_Arg (Arg2);
3241 if not Is_Entity_Name (Id) then
3242 Error_Pragma_Arg ("entity name required", Arg2);
3247 -- Set entity to return
3251 -- Ada_Pass_By_Copy special checking
3253 if C = Convention_Ada_Pass_By_Copy then
3254 if not Is_First_Subtype (E) then
3256 ("convention `Ada_Pass_By_Copy` only "
3257 & "allowed for types", Arg2);
3260 if Is_By_Reference_Type (E) then
3262 ("convention `Ada_Pass_By_Copy` not allowed for "
3263 & "by-reference type", Arg1);
3267 -- Ada_Pass_By_Reference special checking
3269 if C = Convention_Ada_Pass_By_Reference then
3270 if not Is_First_Subtype (E) then
3272 ("convention `Ada_Pass_By_Reference` only "
3273 & "allowed for types", Arg2);
3276 if Is_By_Copy_Type (E) then
3278 ("convention `Ada_Pass_By_Reference` not allowed for "
3279 & "by-copy type", Arg1);
3283 -- Go to renamed subprogram if present, since convention applies to
3284 -- the actual renamed entity, not to the renaming entity. If the
3285 -- subprogram is inherited, go to parent subprogram.
3287 if Is_Subprogram (E)
3288 and then Present (Alias (E))
3290 if Nkind (Parent (Declaration_Node (E))) =
3291 N_Subprogram_Renaming_Declaration
3293 if Scope (E) /= Scope (Alias (E)) then
3295 ("cannot apply pragma% to non-local entity&#", E);
3300 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3301 N_Private_Extension_Declaration)
3302 and then Scope (E) = Scope (Alias (E))
3306 -- Return the parent subprogram the entity was inherited from
3312 -- Check that we are not applying this to a specless body
3314 if Is_Subprogram (E)
3315 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3318 ("pragma% requires separate spec and must come before body");
3321 -- Check that we are not applying this to a named constant
3323 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3324 Error_Msg_Name_1 := Pname;
3326 ("cannot apply pragma% to named constant!",
3327 Get_Pragma_Arg (Arg2));
3329 ("\supply appropriate type for&!", Arg2);
3332 if Ekind (E) = E_Enumeration_Literal then
3333 Error_Pragma ("enumeration literal not allowed for pragma%");
3336 -- Check for rep item appearing too early or too late
3338 if Etype (E) = Any_Type
3339 or else Rep_Item_Too_Early (E, N)
3343 elsif Present (Underlying_Type (E)) then
3344 E := Underlying_Type (E);
3347 if Rep_Item_Too_Late (E, N) then
3351 if Has_Convention_Pragma (E) then
3352 Diagnose_Multiple_Pragmas (E);
3354 elsif Convention (E) = Convention_Protected
3355 or else Ekind (Scope (E)) = E_Protected_Type
3358 ("a protected operation cannot be given a different convention",
3362 -- For Intrinsic, a subprogram is required
3364 if C = Convention_Intrinsic
3365 and then not Is_Subprogram (E)
3366 and then not Is_Generic_Subprogram (E)
3369 ("second argument of pragma% must be a subprogram", Arg2);
3372 -- For Stdcall, a subprogram, variable or subprogram type is required
3374 if C = Convention_Stdcall
3375 and then not Is_Subprogram (E)
3376 and then not Is_Generic_Subprogram (E)
3377 and then Ekind (E) /= E_Variable
3380 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3383 ("second argument of pragma% must be subprogram (type)",
3387 if not Is_Subprogram (E)
3388 and then not Is_Generic_Subprogram (E)
3390 Set_Convention_From_Pragma (E);
3393 Check_First_Subtype (Arg2);
3394 Set_Convention_From_Pragma (Base_Type (E));
3396 -- For subprograms, we must set the convention on the
3397 -- internally generated directly designated type as well.
3399 if Ekind (E) = E_Access_Subprogram_Type then
3400 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3404 -- For the subprogram case, set proper convention for all homonyms
3405 -- in same scope and the same declarative part, i.e. the same
3406 -- compilation unit.
3409 Comp_Unit := Get_Source_Unit (E);
3410 Set_Convention_From_Pragma (E);
3412 -- Treat a pragma Import as an implicit body, for GPS use
3414 if Prag_Id = Pragma_Import then
3415 Generate_Reference (E, Id, 'b');
3418 -- Loop through the homonyms of the pragma argument's entity
3423 exit when No (E1) or else Scope (E1) /= Current_Scope;
3425 -- Do not set the pragma on inherited operations or on formal
3428 if Comes_From_Source (E1)
3429 and then Comp_Unit = Get_Source_Unit (E1)
3430 and then not Is_Formal_Subprogram (E1)
3431 and then Nkind (Original_Node (Parent (E1))) /=
3432 N_Full_Type_Declaration
3434 if Present (Alias (E1))
3435 and then Scope (E1) /= Scope (Alias (E1))
3438 ("cannot apply pragma% to non-local entity& declared#",
3442 Set_Convention_From_Pragma (E1);
3444 if Prag_Id = Pragma_Import then
3445 Generate_Reference (E1, Id, 'b');
3449 -- For aspect case, do NOT apply to homonyms
3451 exit when From_Aspect_Specification (N);
3454 end Process_Convention;
3456 -----------------------------------------------------
3457 -- Process_Extended_Import_Export_Exception_Pragma --
3458 -----------------------------------------------------
3460 procedure Process_Extended_Import_Export_Exception_Pragma
3461 (Arg_Internal : Node_Id;
3462 Arg_External : Node_Id;
3470 if not OpenVMS_On_Target then
3472 ("?pragma% ignored (applies only to Open'V'M'S)");
3475 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3476 Def_Id := Entity (Arg_Internal);
3478 if Ekind (Def_Id) /= E_Exception then
3480 ("pragma% must refer to declared exception", Arg_Internal);
3483 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3485 if Present (Arg_Form) then
3486 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3489 if Present (Arg_Form)
3490 and then Chars (Arg_Form) = Name_Ada
3494 Set_Is_VMS_Exception (Def_Id);
3495 Set_Exception_Code (Def_Id, No_Uint);
3498 if Present (Arg_Code) then
3499 if not Is_VMS_Exception (Def_Id) then
3501 ("Code option for pragma% not allowed for Ada case",
3505 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3506 Code_Val := Expr_Value (Arg_Code);
3508 if not UI_Is_In_Int_Range (Code_Val) then
3510 ("Code option for pragma% must be in 32-bit range",
3514 Set_Exception_Code (Def_Id, Code_Val);
3517 end Process_Extended_Import_Export_Exception_Pragma;
3519 -------------------------------------------------
3520 -- Process_Extended_Import_Export_Internal_Arg --
3521 -------------------------------------------------
3523 procedure Process_Extended_Import_Export_Internal_Arg
3524 (Arg_Internal : Node_Id := Empty)
3527 if No (Arg_Internal) then
3528 Error_Pragma ("Internal parameter required for pragma%");
3531 if Nkind (Arg_Internal) = N_Identifier then
3534 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3535 and then (Prag_Id = Pragma_Import_Function
3537 Prag_Id = Pragma_Export_Function)
3543 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3546 Check_Arg_Is_Local_Name (Arg_Internal);
3547 end Process_Extended_Import_Export_Internal_Arg;
3549 --------------------------------------------------
3550 -- Process_Extended_Import_Export_Object_Pragma --
3551 --------------------------------------------------
3553 procedure Process_Extended_Import_Export_Object_Pragma
3554 (Arg_Internal : Node_Id;
3555 Arg_External : Node_Id;
3561 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3562 Def_Id := Entity (Arg_Internal);
3564 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3566 ("pragma% must designate an object", Arg_Internal);
3569 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3571 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3574 ("previous Common/Psect_Object applies, pragma % not permitted",
3578 if Rep_Item_Too_Late (Def_Id, N) then
3582 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3584 if Present (Arg_Size) then
3585 Check_Arg_Is_External_Name (Arg_Size);
3588 -- Export_Object case
3590 if Prag_Id = Pragma_Export_Object then
3591 if not Is_Library_Level_Entity (Def_Id) then
3593 ("argument for pragma% must be library level entity",
3597 if Ekind (Current_Scope) = E_Generic_Package then
3598 Error_Pragma ("pragma& cannot appear in a generic unit");
3601 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3603 ("exported object must have compile time known size",
3607 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3608 Error_Msg_N ("?duplicate Export_Object pragma", N);
3610 Set_Exported (Def_Id, Arg_Internal);
3613 -- Import_Object case
3616 if Is_Concurrent_Type (Etype (Def_Id)) then
3618 ("cannot use pragma% for task/protected object",
3622 if Ekind (Def_Id) = E_Constant then
3624 ("cannot import a constant", Arg_Internal);
3627 if Warn_On_Export_Import
3628 and then Has_Discriminants (Etype (Def_Id))
3631 ("imported value must be initialized?", Arg_Internal);
3634 if Warn_On_Export_Import
3635 and then Is_Access_Type (Etype (Def_Id))
3638 ("cannot import object of an access type?", Arg_Internal);
3641 if Warn_On_Export_Import
3642 and then Is_Imported (Def_Id)
3645 ("?duplicate Import_Object pragma", N);
3647 -- Check for explicit initialization present. Note that an
3648 -- initialization generated by the code generator, e.g. for an
3649 -- access type, does not count here.
3651 elsif Present (Expression (Parent (Def_Id)))
3654 (Original_Node (Expression (Parent (Def_Id))))
3656 Error_Msg_Sloc := Sloc (Def_Id);
3658 ("imported entities cannot be initialized (RM B.1(24))",
3659 "\no initialization allowed for & declared#", Arg1);
3661 Set_Imported (Def_Id);
3662 Note_Possible_Modification (Arg_Internal, Sure => False);
3665 end Process_Extended_Import_Export_Object_Pragma;
3667 ------------------------------------------------------
3668 -- Process_Extended_Import_Export_Subprogram_Pragma --
3669 ------------------------------------------------------
3671 procedure Process_Extended_Import_Export_Subprogram_Pragma
3672 (Arg_Internal : Node_Id;
3673 Arg_External : Node_Id;
3674 Arg_Parameter_Types : Node_Id;
3675 Arg_Result_Type : Node_Id := Empty;
3676 Arg_Mechanism : Node_Id;
3677 Arg_Result_Mechanism : Node_Id := Empty;
3678 Arg_First_Optional_Parameter : Node_Id := Empty)
3684 Ambiguous : Boolean;
3688 function Same_Base_Type
3690 Formal : Entity_Id) return Boolean;
3691 -- Determines if Ptype references the type of Formal. Note that only
3692 -- the base types need to match according to the spec. Ptype here is
3693 -- the argument from the pragma, which is either a type name, or an
3694 -- access attribute.
3696 --------------------
3697 -- Same_Base_Type --
3698 --------------------
3700 function Same_Base_Type
3702 Formal : Entity_Id) return Boolean
3704 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3708 -- Case where pragma argument is typ'Access
3710 if Nkind (Ptype) = N_Attribute_Reference
3711 and then Attribute_Name (Ptype) = Name_Access
3713 Pref := Prefix (Ptype);
3716 if not Is_Entity_Name (Pref)
3717 or else Entity (Pref) = Any_Type
3722 -- We have a match if the corresponding argument is of an
3723 -- anonymous access type, and its designated type matches the
3724 -- type of the prefix of the access attribute
3726 return Ekind (Ftyp) = E_Anonymous_Access_Type
3727 and then Base_Type (Entity (Pref)) =
3728 Base_Type (Etype (Designated_Type (Ftyp)));
3730 -- Case where pragma argument is a type name
3735 if not Is_Entity_Name (Ptype)
3736 or else Entity (Ptype) = Any_Type
3741 -- We have a match if the corresponding argument is of the type
3742 -- given in the pragma (comparing base types)
3744 return Base_Type (Entity (Ptype)) = Ftyp;
3748 -- Start of processing for
3749 -- Process_Extended_Import_Export_Subprogram_Pragma
3752 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3756 -- Loop through homonyms (overloadings) of the entity
3758 Hom_Id := Entity (Arg_Internal);
3759 while Present (Hom_Id) loop
3760 Def_Id := Get_Base_Subprogram (Hom_Id);
3762 -- We need a subprogram in the current scope
3764 if not Is_Subprogram (Def_Id)
3765 or else Scope (Def_Id) /= Current_Scope
3772 -- Pragma cannot apply to subprogram body
3774 if Is_Subprogram (Def_Id)
3775 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3779 ("pragma% requires separate spec"
3780 & " and must come before body");
3783 -- Test result type if given, note that the result type
3784 -- parameter can only be present for the function cases.
3786 if Present (Arg_Result_Type)
3787 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3791 elsif Etype (Def_Id) /= Standard_Void_Type
3793 (Pname = Name_Export_Procedure
3795 Pname = Name_Import_Procedure)
3799 -- Test parameter types if given. Note that this parameter
3800 -- has not been analyzed (and must not be, since it is
3801 -- semantic nonsense), so we get it as the parser left it.
3803 elsif Present (Arg_Parameter_Types) then
3804 Check_Matching_Types : declare
3809 Formal := First_Formal (Def_Id);
3811 if Nkind (Arg_Parameter_Types) = N_Null then
3812 if Present (Formal) then
3816 -- A list of one type, e.g. (List) is parsed as
3817 -- a parenthesized expression.
3819 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3820 and then Paren_Count (Arg_Parameter_Types) = 1
3823 or else Present (Next_Formal (Formal))
3828 Same_Base_Type (Arg_Parameter_Types, Formal);
3831 -- A list of more than one type is parsed as a aggregate
3833 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3834 and then Paren_Count (Arg_Parameter_Types) = 0
3836 Ptype := First (Expressions (Arg_Parameter_Types));
3837 while Present (Ptype) or else Present (Formal) loop
3840 or else not Same_Base_Type (Ptype, Formal)
3845 Next_Formal (Formal);
3850 -- Anything else is of the wrong form
3854 ("wrong form for Parameter_Types parameter",
3855 Arg_Parameter_Types);
3857 end Check_Matching_Types;
3860 -- Match is now False if the entry we found did not match
3861 -- either a supplied Parameter_Types or Result_Types argument
3867 -- Ambiguous case, the flag Ambiguous shows if we already
3868 -- detected this and output the initial messages.
3871 if not Ambiguous then
3873 Error_Msg_Name_1 := Pname;
3875 ("pragma% does not uniquely identify subprogram!",
3877 Error_Msg_Sloc := Sloc (Ent);
3878 Error_Msg_N ("matching subprogram #!", N);
3882 Error_Msg_Sloc := Sloc (Def_Id);
3883 Error_Msg_N ("matching subprogram #!", N);
3888 Hom_Id := Homonym (Hom_Id);
3891 -- See if we found an entry
3894 if not Ambiguous then
3895 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3897 ("pragma% cannot be given for generic subprogram");
3900 ("pragma% does not identify local subprogram");
3907 -- Import pragmas must be for imported entities
3909 if Prag_Id = Pragma_Import_Function
3911 Prag_Id = Pragma_Import_Procedure
3913 Prag_Id = Pragma_Import_Valued_Procedure
3915 if not Is_Imported (Ent) then
3917 ("pragma Import or Interface must precede pragma%");
3920 -- Here we have the Export case which can set the entity as exported
3922 -- But does not do so if the specified external name is null, since
3923 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3924 -- compatible) to request no external name.
3926 elsif Nkind (Arg_External) = N_String_Literal
3927 and then String_Length (Strval (Arg_External)) = 0
3931 -- In all other cases, set entity as exported
3934 Set_Exported (Ent, Arg_Internal);
3937 -- Special processing for Valued_Procedure cases
3939 if Prag_Id = Pragma_Import_Valued_Procedure
3941 Prag_Id = Pragma_Export_Valued_Procedure
3943 Formal := First_Formal (Ent);
3946 Error_Pragma ("at least one parameter required for pragma%");
3948 elsif Ekind (Formal) /= E_Out_Parameter then
3949 Error_Pragma ("first parameter must have mode out for pragma%");
3952 Set_Is_Valued_Procedure (Ent);
3956 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3958 -- Process Result_Mechanism argument if present. We have already
3959 -- checked that this is only allowed for the function case.
3961 if Present (Arg_Result_Mechanism) then
3962 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3965 -- Process Mechanism parameter if present. Note that this parameter
3966 -- is not analyzed, and must not be analyzed since it is semantic
3967 -- nonsense, so we get it in exactly as the parser left it.
3969 if Present (Arg_Mechanism) then
3977 -- A single mechanism association without a formal parameter
3978 -- name is parsed as a parenthesized expression. All other
3979 -- cases are parsed as aggregates, so we rewrite the single
3980 -- parameter case as an aggregate for consistency.
3982 if Nkind (Arg_Mechanism) /= N_Aggregate
3983 and then Paren_Count (Arg_Mechanism) = 1
3985 Rewrite (Arg_Mechanism,
3986 Make_Aggregate (Sloc (Arg_Mechanism),
3987 Expressions => New_List (
3988 Relocate_Node (Arg_Mechanism))));
3991 -- Case of only mechanism name given, applies to all formals
3993 if Nkind (Arg_Mechanism) /= N_Aggregate then
3994 Formal := First_Formal (Ent);
3995 while Present (Formal) loop
3996 Set_Mechanism_Value (Formal, Arg_Mechanism);
3997 Next_Formal (Formal);
4000 -- Case of list of mechanism associations given
4003 if Null_Record_Present (Arg_Mechanism) then
4005 ("inappropriate form for Mechanism parameter",
4009 -- Deal with positional ones first
4011 Formal := First_Formal (Ent);
4013 if Present (Expressions (Arg_Mechanism)) then
4014 Mname := First (Expressions (Arg_Mechanism));
4015 while Present (Mname) loop
4018 ("too many mechanism associations", Mname);
4021 Set_Mechanism_Value (Formal, Mname);
4022 Next_Formal (Formal);
4027 -- Deal with named entries
4029 if Present (Component_Associations (Arg_Mechanism)) then
4030 Massoc := First (Component_Associations (Arg_Mechanism));
4031 while Present (Massoc) loop
4032 Choice := First (Choices (Massoc));
4034 if Nkind (Choice) /= N_Identifier
4035 or else Present (Next (Choice))
4038 ("incorrect form for mechanism association",
4042 Formal := First_Formal (Ent);
4046 ("parameter name & not present", Choice);
4049 if Chars (Choice) = Chars (Formal) then
4051 (Formal, Expression (Massoc));
4053 -- Set entity on identifier (needed by ASIS)
4055 Set_Entity (Choice, Formal);
4060 Next_Formal (Formal);
4070 -- Process First_Optional_Parameter argument if present. We have
4071 -- already checked that this is only allowed for the Import case.
4073 if Present (Arg_First_Optional_Parameter) then
4074 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4076 ("first optional parameter must be formal parameter name",
4077 Arg_First_Optional_Parameter);
4080 Formal := First_Formal (Ent);
4084 ("specified formal parameter& not found",
4085 Arg_First_Optional_Parameter);
4088 exit when Chars (Formal) =
4089 Chars (Arg_First_Optional_Parameter);
4091 Next_Formal (Formal);
4094 Set_First_Optional_Parameter (Ent, Formal);
4096 -- Check specified and all remaining formals have right form
4098 while Present (Formal) loop
4099 if Ekind (Formal) /= E_In_Parameter then
4101 ("optional formal& is not of mode in!",
4102 Arg_First_Optional_Parameter, Formal);
4105 Dval := Default_Value (Formal);
4109 ("optional formal& does not have default value!",
4110 Arg_First_Optional_Parameter, Formal);
4112 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4117 ("default value for optional formal& is non-static!",
4118 Arg_First_Optional_Parameter, Formal);
4122 Set_Is_Optional_Parameter (Formal);
4123 Next_Formal (Formal);
4126 end Process_Extended_Import_Export_Subprogram_Pragma;
4128 --------------------------
4129 -- Process_Generic_List --
4130 --------------------------
4132 procedure Process_Generic_List is
4137 Check_No_Identifiers;
4138 Check_At_Least_N_Arguments (1);
4141 while Present (Arg) loop
4142 Exp := Get_Pragma_Arg (Arg);
4145 if not Is_Entity_Name (Exp)
4147 (not Is_Generic_Instance (Entity (Exp))
4149 not Is_Generic_Unit (Entity (Exp)))
4152 ("pragma% argument must be name of generic unit/instance",
4158 end Process_Generic_List;
4160 ------------------------------------
4161 -- Process_Import_Predefined_Type --
4162 ------------------------------------
4164 procedure Process_Import_Predefined_Type is
4165 Loc : constant Source_Ptr := Sloc (N);
4167 Ftyp : Node_Id := Empty;
4173 String_To_Name_Buffer (Strval (Expression (Arg3)));
4176 Elmt := First_Elmt (Predefined_Float_Types);
4177 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4181 Ftyp := Node (Elmt);
4183 if Present (Ftyp) then
4185 -- Don't build a derived type declaration, because predefined C
4186 -- types have no declaration anywhere, so cannot really be named.
4187 -- Instead build a full type declaration, starting with an
4188 -- appropriate type definition is built
4190 if Is_Floating_Point_Type (Ftyp) then
4191 Def := Make_Floating_Point_Definition (Loc,
4192 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4193 Make_Real_Range_Specification (Loc,
4194 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4195 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4197 -- Should never have a predefined type we cannot handle
4200 raise Program_Error;
4203 -- Build and insert a Full_Type_Declaration, which will be
4204 -- analyzed as soon as this list entry has been analyzed.
4206 Decl := Make_Full_Type_Declaration (Loc,
4207 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4208 Type_Definition => Def);
4210 Insert_After (N, Decl);
4211 Mark_Rewrite_Insertion (Decl);
4214 Error_Pragma_Arg ("no matching type found for pragma%",
4217 end Process_Import_Predefined_Type;
4219 ---------------------------------
4220 -- Process_Import_Or_Interface --
4221 ---------------------------------
4223 procedure Process_Import_Or_Interface is
4229 Process_Convention (C, Def_Id);
4230 Kill_Size_Check_Code (Def_Id);
4231 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4233 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4235 -- We do not permit Import to apply to a renaming declaration
4237 if Present (Renamed_Object (Def_Id)) then
4239 ("pragma% not allowed for object renaming", Arg2);
4241 -- User initialization is not allowed for imported object, but
4242 -- the object declaration may contain a default initialization,
4243 -- that will be discarded. Note that an explicit initialization
4244 -- only counts if it comes from source, otherwise it is simply
4245 -- the code generator making an implicit initialization explicit.
4247 elsif Present (Expression (Parent (Def_Id)))
4248 and then Comes_From_Source (Expression (Parent (Def_Id)))
4250 Error_Msg_Sloc := Sloc (Def_Id);
4252 ("no initialization allowed for declaration of& #",
4253 "\imported entities cannot be initialized (RM B.1(24))",
4257 Set_Imported (Def_Id);
4258 Process_Interface_Name (Def_Id, Arg3, Arg4);
4260 -- Note that we do not set Is_Public here. That's because we
4261 -- only want to set it if there is no address clause, and we
4262 -- don't know that yet, so we delay that processing till
4265 -- pragma Import completes deferred constants
4267 if Ekind (Def_Id) = E_Constant then
4268 Set_Has_Completion (Def_Id);
4271 -- It is not possible to import a constant of an unconstrained
4272 -- array type (e.g. string) because there is no simple way to
4273 -- write a meaningful subtype for it.
4275 if Is_Array_Type (Etype (Def_Id))
4276 and then not Is_Constrained (Etype (Def_Id))
4279 ("imported constant& must have a constrained subtype",
4284 elsif Is_Subprogram (Def_Id)
4285 or else Is_Generic_Subprogram (Def_Id)
4287 -- If the name is overloaded, pragma applies to all of the denoted
4288 -- entities in the same declarative part.
4291 while Present (Hom_Id) loop
4292 Def_Id := Get_Base_Subprogram (Hom_Id);
4294 -- Ignore inherited subprograms because the pragma will apply
4295 -- to the parent operation, which is the one called.
4297 if Is_Overloadable (Def_Id)
4298 and then Present (Alias (Def_Id))
4302 -- If it is not a subprogram, it must be in an outer scope and
4303 -- pragma does not apply.
4305 elsif not Is_Subprogram (Def_Id)
4306 and then not Is_Generic_Subprogram (Def_Id)
4310 -- The pragma does not apply to primitives of interfaces
4312 elsif Is_Dispatching_Operation (Def_Id)
4313 and then Present (Find_Dispatching_Type (Def_Id))
4314 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4318 -- Verify that the homonym is in the same declarative part (not
4319 -- just the same scope).
4321 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4322 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4327 Set_Imported (Def_Id);
4329 -- Reject an Import applied to an abstract subprogram
4331 if Is_Subprogram (Def_Id)
4332 and then Is_Abstract_Subprogram (Def_Id)
4334 Error_Msg_Sloc := Sloc (Def_Id);
4336 ("cannot import abstract subprogram& declared#",
4340 -- Special processing for Convention_Intrinsic
4342 if C = Convention_Intrinsic then
4344 -- Link_Name argument not allowed for intrinsic
4348 Set_Is_Intrinsic_Subprogram (Def_Id);
4350 -- If no external name is present, then check that this
4351 -- is a valid intrinsic subprogram. If an external name
4352 -- is present, then this is handled by the back end.
4355 Check_Intrinsic_Subprogram
4356 (Def_Id, Get_Pragma_Arg (Arg2));
4360 -- All interfaced procedures need an external symbol created
4361 -- for them since they are always referenced from another
4364 Set_Is_Public (Def_Id);
4366 -- Verify that the subprogram does not have a completion
4367 -- through a renaming declaration. For other completions the
4368 -- pragma appears as a too late representation.
4371 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4375 and then Nkind (Decl) = N_Subprogram_Declaration
4376 and then Present (Corresponding_Body (Decl))
4377 and then Nkind (Unit_Declaration_Node
4378 (Corresponding_Body (Decl))) =
4379 N_Subprogram_Renaming_Declaration
4381 Error_Msg_Sloc := Sloc (Def_Id);
4383 ("cannot import&, renaming already provided for " &
4384 "declaration #", N, Def_Id);
4388 Set_Has_Completion (Def_Id);
4389 Process_Interface_Name (Def_Id, Arg3, Arg4);
4392 if Is_Compilation_Unit (Hom_Id) then
4394 -- Its possible homonyms are not affected by the pragma.
4395 -- Such homonyms might be present in the context of other
4396 -- units being compiled.
4401 Hom_Id := Homonym (Hom_Id);
4405 -- When the convention is Java or CIL, we also allow Import to be
4406 -- given for packages, generic packages, exceptions, record
4407 -- components, and access to subprograms.
4409 elsif (C = Convention_Java or else C = Convention_CIL)
4411 (Is_Package_Or_Generic_Package (Def_Id)
4412 or else Ekind (Def_Id) = E_Exception
4413 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4414 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4416 Set_Imported (Def_Id);
4417 Set_Is_Public (Def_Id);
4418 Process_Interface_Name (Def_Id, Arg3, Arg4);
4420 -- Import a CPP class
4422 elsif Is_Record_Type (Def_Id)
4423 and then C = Convention_CPP
4425 -- Types treated as CPP classes must be declared limited (note:
4426 -- this used to be a warning but there is no real benefit to it
4427 -- since we did effectively intend to treat the type as limited
4430 if not Is_Limited_Type (Def_Id) then
4432 ("imported 'C'P'P type must be limited",
4433 Get_Pragma_Arg (Arg2));
4436 Set_Is_CPP_Class (Def_Id);
4438 -- Imported CPP types must not have discriminants (because C++
4439 -- classes do not have discriminants).
4441 if Has_Discriminants (Def_Id) then
4443 ("imported 'C'P'P type cannot have discriminants",
4444 First (Discriminant_Specifications
4445 (Declaration_Node (Def_Id))));
4448 -- Components of imported CPP types must not have default
4449 -- expressions because the constructor (if any) is on the
4453 Tdef : constant Node_Id :=
4454 Type_Definition (Declaration_Node (Def_Id));
4459 if Nkind (Tdef) = N_Record_Definition then
4460 Clist := Component_List (Tdef);
4463 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4464 Clist := Component_List (Record_Extension_Part (Tdef));
4467 if Present (Clist) then
4468 Comp := First (Component_Items (Clist));
4469 while Present (Comp) loop
4470 if Present (Expression (Comp)) then
4472 ("component of imported 'C'P'P type cannot have" &
4473 " default expression", Expression (Comp));
4481 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4483 Check_Arg_Count (3);
4484 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4486 Process_Import_Predefined_Type;
4490 ("second argument of pragma% must be object, subprogram" &
4491 " or incomplete type",
4495 -- If this pragma applies to a compilation unit, then the unit, which
4496 -- is a subprogram, does not require (or allow) a body. We also do
4497 -- not need to elaborate imported procedures.
4499 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4501 Cunit : constant Node_Id := Parent (Parent (N));
4503 Set_Body_Required (Cunit, False);
4506 end Process_Import_Or_Interface;
4508 --------------------
4509 -- Process_Inline --
4510 --------------------
4512 procedure Process_Inline (Active : Boolean) is
4519 Effective : Boolean := False;
4520 -- Set True if inline has some effect, i.e. if there is at least one
4521 -- subprogram set as inlined as a result of the use of the pragma.
4523 procedure Make_Inline (Subp : Entity_Id);
4524 -- Subp is the defining unit name of the subprogram declaration. Set
4525 -- the flag, as well as the flag in the corresponding body, if there
4528 procedure Set_Inline_Flags (Subp : Entity_Id);
4529 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4530 -- Has_Pragma_Inline_Always for the Inline_Always case.
4532 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4533 -- Returns True if it can be determined at this stage that inlining
4534 -- is not possible, for example if the body is available and contains
4535 -- exception handlers, we prevent inlining, since otherwise we can
4536 -- get undefined symbols at link time. This function also emits a
4537 -- warning if front-end inlining is enabled and the pragma appears
4540 -- ??? is business with link symbols still valid, or does it relate
4541 -- to front end ZCX which is being phased out ???
4543 ---------------------------
4544 -- Inlining_Not_Possible --
4545 ---------------------------
4547 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4548 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4552 if Nkind (Decl) = N_Subprogram_Body then
4553 Stats := Handled_Statement_Sequence (Decl);
4554 return Present (Exception_Handlers (Stats))
4555 or else Present (At_End_Proc (Stats));
4557 elsif Nkind (Decl) = N_Subprogram_Declaration
4558 and then Present (Corresponding_Body (Decl))
4560 if Front_End_Inlining
4561 and then Analyzed (Corresponding_Body (Decl))
4563 Error_Msg_N ("pragma appears too late, ignored?", N);
4566 -- If the subprogram is a renaming as body, the body is just a
4567 -- call to the renamed subprogram, and inlining is trivially
4571 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4572 N_Subprogram_Renaming_Declaration
4578 Handled_Statement_Sequence
4579 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4582 Present (Exception_Handlers (Stats))
4583 or else Present (At_End_Proc (Stats));
4587 -- If body is not available, assume the best, the check is
4588 -- performed again when compiling enclosing package bodies.
4592 end Inlining_Not_Possible;
4598 procedure Make_Inline (Subp : Entity_Id) is
4599 Kind : constant Entity_Kind := Ekind (Subp);
4600 Inner_Subp : Entity_Id := Subp;
4603 -- Ignore if bad type, avoid cascaded error
4605 if Etype (Subp) = Any_Type then
4609 -- Ignore if all inlining is suppressed
4611 elsif Suppress_All_Inlining then
4615 -- If inlining is not possible, for now do not treat as an error
4617 elsif Inlining_Not_Possible (Subp) then
4621 -- Here we have a candidate for inlining, but we must exclude
4622 -- derived operations. Otherwise we would end up trying to inline
4623 -- a phantom declaration, and the result would be to drag in a
4624 -- body which has no direct inlining associated with it. That
4625 -- would not only be inefficient but would also result in the
4626 -- backend doing cross-unit inlining in cases where it was
4627 -- definitely inappropriate to do so.
4629 -- However, a simple Comes_From_Source test is insufficient, since
4630 -- we do want to allow inlining of generic instances which also do
4631 -- not come from source. We also need to recognize specs generated
4632 -- by the front-end for bodies that carry the pragma. Finally,
4633 -- predefined operators do not come from source but are not
4634 -- inlineable either.
4636 elsif Is_Generic_Instance (Subp)
4637 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4641 elsif not Comes_From_Source (Subp)
4642 and then Scope (Subp) /= Standard_Standard
4648 -- The referenced entity must either be the enclosing entity, or
4649 -- an entity declared within the current open scope.
4651 if Present (Scope (Subp))
4652 and then Scope (Subp) /= Current_Scope
4653 and then Subp /= Current_Scope
4656 ("argument of% must be entity in current scope", Assoc);
4660 -- Processing for procedure, operator or function. If subprogram
4661 -- is aliased (as for an instance) indicate that the renamed
4662 -- entity (if declared in the same unit) is inlined.
4664 if Is_Subprogram (Subp) then
4665 Inner_Subp := Ultimate_Alias (Inner_Subp);
4667 if In_Same_Source_Unit (Subp, Inner_Subp) then
4668 Set_Inline_Flags (Inner_Subp);
4670 Decl := Parent (Parent (Inner_Subp));
4672 if Nkind (Decl) = N_Subprogram_Declaration
4673 and then Present (Corresponding_Body (Decl))
4675 Set_Inline_Flags (Corresponding_Body (Decl));
4677 elsif Is_Generic_Instance (Subp) then
4679 -- Indicate that the body needs to be created for
4680 -- inlining subsequent calls. The instantiation node
4681 -- follows the declaration of the wrapper package
4684 if Scope (Subp) /= Standard_Standard
4686 Need_Subprogram_Instance_Body
4687 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4697 -- For a generic subprogram set flag as well, for use at the point
4698 -- of instantiation, to determine whether the body should be
4701 elsif Is_Generic_Subprogram (Subp) then
4702 Set_Inline_Flags (Subp);
4705 -- Literals are by definition inlined
4707 elsif Kind = E_Enumeration_Literal then
4710 -- Anything else is an error
4714 ("expect subprogram name for pragma%", Assoc);
4718 ----------------------
4719 -- Set_Inline_Flags --
4720 ----------------------
4722 procedure Set_Inline_Flags (Subp : Entity_Id) is
4725 Set_Is_Inlined (Subp);
4728 if not Has_Pragma_Inline (Subp) then
4729 Set_Has_Pragma_Inline (Subp);
4733 if Prag_Id = Pragma_Inline_Always then
4734 Set_Has_Pragma_Inline_Always (Subp);
4736 end Set_Inline_Flags;
4738 -- Start of processing for Process_Inline
4741 Check_No_Identifiers;
4742 Check_At_Least_N_Arguments (1);
4745 Inline_Processing_Required := True;
4749 while Present (Assoc) loop
4750 Subp_Id := Get_Pragma_Arg (Assoc);
4754 if Is_Entity_Name (Subp_Id) then
4755 Subp := Entity (Subp_Id);
4757 if Subp = Any_Id then
4759 -- If previous error, avoid cascaded errors
4767 -- For the pragma case, climb homonym chain. This is
4768 -- what implements allowing the pragma in the renaming
4769 -- case, with the result applying to the ancestors.
4771 if not From_Aspect_Specification (N) then
4772 while Present (Homonym (Subp))
4773 and then Scope (Homonym (Subp)) = Current_Scope
4775 Make_Inline (Homonym (Subp));
4776 Subp := Homonym (Subp);
4784 ("inappropriate argument for pragma%", Assoc);
4787 and then Warn_On_Redundant_Constructs
4788 and then not Suppress_All_Inlining
4790 if Inlining_Not_Possible (Subp) then
4792 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4795 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4803 ----------------------------
4804 -- Process_Interface_Name --
4805 ----------------------------
4807 procedure Process_Interface_Name
4808 (Subprogram_Def : Entity_Id;
4814 String_Val : String_Id;
4816 procedure Check_Form_Of_Interface_Name
4818 Ext_Name_Case : Boolean);
4819 -- SN is a string literal node for an interface name. This routine
4820 -- performs some minimal checks that the name is reasonable. In
4821 -- particular that no spaces or other obviously incorrect characters
4822 -- appear. This is only a warning, since any characters are allowed.
4823 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4825 ----------------------------------
4826 -- Check_Form_Of_Interface_Name --
4827 ----------------------------------
4829 procedure Check_Form_Of_Interface_Name
4831 Ext_Name_Case : Boolean)
4833 S : constant String_Id := Strval (Expr_Value_S (SN));
4834 SL : constant Nat := String_Length (S);
4839 Error_Msg_N ("interface name cannot be null string", SN);
4842 for J in 1 .. SL loop
4843 C := Get_String_Char (S, J);
4845 -- Look for dubious character and issue unconditional warning.
4846 -- Definitely dubious if not in character range.
4848 if not In_Character_Range (C)
4850 -- For all cases except CLI target,
4851 -- commas, spaces and slashes are dubious (in CLI, we use
4852 -- commas and backslashes in external names to specify
4853 -- assembly version and public key, while slashes and spaces
4854 -- can be used in names to mark nested classes and
4857 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4858 and then (Get_Character (C) = ','
4860 Get_Character (C) = '\'))
4861 or else (VM_Target /= CLI_Target
4862 and then (Get_Character (C) = ' '
4864 Get_Character (C) = '/'))
4867 ("?interface name contains illegal character",
4868 Sloc (SN) + Source_Ptr (J));
4871 end Check_Form_Of_Interface_Name;
4873 -- Start of processing for Process_Interface_Name
4876 if No (Link_Arg) then
4877 if No (Ext_Arg) then
4878 if VM_Target = CLI_Target
4879 and then Ekind (Subprogram_Def) = E_Package
4880 and then Nkind (Parent (Subprogram_Def)) =
4881 N_Package_Specification
4882 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4887 (Generic_Parent (Parent (Subprogram_Def))));
4892 elsif Chars (Ext_Arg) = Name_Link_Name then
4894 Link_Nam := Expression (Ext_Arg);
4897 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4898 Ext_Nam := Expression (Ext_Arg);
4903 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4904 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4905 Ext_Nam := Expression (Ext_Arg);
4906 Link_Nam := Expression (Link_Arg);
4909 -- Check expressions for external name and link name are static
4911 if Present (Ext_Nam) then
4912 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4913 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4915 -- Verify that external name is not the name of a local entity,
4916 -- which would hide the imported one and could lead to run-time
4917 -- surprises. The problem can only arise for entities declared in
4918 -- a package body (otherwise the external name is fully qualified
4919 -- and will not conflict).
4927 if Prag_Id = Pragma_Import then
4928 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4930 E := Entity_Id (Get_Name_Table_Info (Nam));
4932 if Nam /= Chars (Subprogram_Def)
4933 and then Present (E)
4934 and then not Is_Overloadable (E)
4935 and then Is_Immediately_Visible (E)
4936 and then not Is_Imported (E)
4937 and then Ekind (Scope (E)) = E_Package
4940 while Present (Par) loop
4941 if Nkind (Par) = N_Package_Body then
4942 Error_Msg_Sloc := Sloc (E);
4944 ("imported entity is hidden by & declared#",
4949 Par := Parent (Par);
4956 if Present (Link_Nam) then
4957 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4958 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4961 -- If there is no link name, just set the external name
4963 if No (Link_Nam) then
4964 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4966 -- For the Link_Name case, the given literal is preceded by an
4967 -- asterisk, which indicates to GCC that the given name should be
4968 -- taken literally, and in particular that no prepending of
4969 -- underlines should occur, even in systems where this is the
4975 if VM_Target = No_VM then
4976 Store_String_Char (Get_Char_Code ('*'));
4979 String_Val := Strval (Expr_Value_S (Link_Nam));
4980 Store_String_Chars (String_Val);
4982 Make_String_Literal (Sloc (Link_Nam),
4983 Strval => End_String);
4986 -- Set the interface name. If the entity is a generic instance, use
4987 -- its alias, which is the callable entity.
4989 if Is_Generic_Instance (Subprogram_Def) then
4990 Set_Encoded_Interface_Name
4991 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
4993 Set_Encoded_Interface_Name
4994 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4997 -- We allow duplicated export names in CIL/Java, as they are always
4998 -- enclosed in a namespace that differentiates them, and overloaded
4999 -- entities are supported by the VM.
5001 if Convention (Subprogram_Def) /= Convention_CIL
5003 Convention (Subprogram_Def) /= Convention_Java
5005 Check_Duplicated_Export_Name (Link_Nam);
5007 end Process_Interface_Name;
5009 -----------------------------------------
5010 -- Process_Interrupt_Or_Attach_Handler --
5011 -----------------------------------------
5013 procedure Process_Interrupt_Or_Attach_Handler is
5014 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5015 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5016 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5019 Set_Is_Interrupt_Handler (Handler_Proc);
5021 -- If the pragma is not associated with a handler procedure within a
5022 -- protected type, then it must be for a nonprotected procedure for
5023 -- the AAMP target, in which case we don't associate a representation
5024 -- item with the procedure's scope.
5026 if Ekind (Proc_Scope) = E_Protected_Type then
5027 if Prag_Id = Pragma_Interrupt_Handler
5029 Prag_Id = Pragma_Attach_Handler
5031 Record_Rep_Item (Proc_Scope, N);
5034 end Process_Interrupt_Or_Attach_Handler;
5036 --------------------------------------------------
5037 -- Process_Restrictions_Or_Restriction_Warnings --
5038 --------------------------------------------------
5040 -- Note: some of the simple identifier cases were handled in par-prag,
5041 -- but it is harmless (and more straightforward) to simply handle all
5042 -- cases here, even if it means we repeat a bit of work in some cases.
5044 procedure Process_Restrictions_Or_Restriction_Warnings
5048 R_Id : Restriction_Id;
5053 procedure Check_Unit_Name (N : Node_Id);
5054 -- Checks unit name parameter for No_Dependence. Returns if it has
5055 -- an appropriate form, otherwise raises pragma argument error.
5057 ---------------------
5058 -- Check_Unit_Name --
5059 ---------------------
5061 procedure Check_Unit_Name (N : Node_Id) is
5063 if Nkind (N) = N_Selected_Component then
5064 Check_Unit_Name (Prefix (N));
5065 Check_Unit_Name (Selector_Name (N));
5067 elsif Nkind (N) = N_Identifier then
5072 ("wrong form for unit name for No_Dependence", N);
5074 end Check_Unit_Name;
5076 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5079 -- Ignore all Restrictions pragma in CodePeer mode
5081 if CodePeer_Mode then
5085 Check_Ada_83_Warning;
5086 Check_At_Least_N_Arguments (1);
5087 Check_Valid_Configuration_Pragma;
5090 while Present (Arg) loop
5092 Expr := Get_Pragma_Arg (Arg);
5094 -- Case of no restriction identifier present
5096 if Id = No_Name then
5097 if Nkind (Expr) /= N_Identifier then
5099 ("invalid form for restriction", Arg);
5104 (Process_Restriction_Synonyms (Expr));
5106 if R_Id not in All_Boolean_Restrictions then
5107 Error_Msg_Name_1 := Pname;
5109 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5111 -- Check for possible misspelling
5113 for J in Restriction_Id loop
5115 Rnm : constant String := Restriction_Id'Image (J);
5118 Name_Buffer (1 .. Rnm'Length) := Rnm;
5119 Name_Len := Rnm'Length;
5120 Set_Casing (All_Lower_Case);
5122 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5124 (Identifier_Casing (Current_Source_File));
5125 Error_Msg_String (1 .. Rnm'Length) :=
5126 Name_Buffer (1 .. Name_Len);
5127 Error_Msg_Strlen := Rnm'Length;
5128 Error_Msg_N -- CODEFIX
5129 ("\possible misspelling of ""~""",
5130 Get_Pragma_Arg (Arg));
5139 if Implementation_Restriction (R_Id) then
5140 Check_Restriction (No_Implementation_Restrictions, Arg);
5143 -- If this is a warning, then set the warning unless we already
5144 -- have a real restriction active (we never want a warning to
5145 -- override a real restriction).
5148 if not Restriction_Active (R_Id) then
5149 Set_Restriction (R_Id, N);
5150 Restriction_Warnings (R_Id) := True;
5153 -- If real restriction case, then set it and make sure that the
5154 -- restriction warning flag is off, since a real restriction
5155 -- always overrides a warning.
5158 Set_Restriction (R_Id, N);
5159 Restriction_Warnings (R_Id) := False;
5162 -- Check for obsolescent restrictions in Ada 2005 mode
5165 and then Ada_Version >= Ada_2005
5166 and then (R_Id = No_Asynchronous_Control
5168 R_Id = No_Unchecked_Deallocation
5170 R_Id = No_Unchecked_Conversion)
5172 Check_Restriction (No_Obsolescent_Features, N);
5175 -- A very special case that must be processed here: pragma
5176 -- Restrictions (No_Exceptions) turns off all run-time
5177 -- checking. This is a bit dubious in terms of the formal
5178 -- language definition, but it is what is intended by RM
5179 -- H.4(12). Restriction_Warnings never affects generated code
5180 -- so this is done only in the real restriction case.
5182 if R_Id = No_Exceptions and then not Warn then
5183 Scope_Suppress := (others => True);
5186 -- Case of No_Dependence => unit-name. Note that the parser
5187 -- already made the necessary entry in the No_Dependence table.
5189 elsif Id = Name_No_Dependence then
5190 Check_Unit_Name (Expr);
5192 -- All other cases of restriction identifier present
5195 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5196 Analyze_And_Resolve (Expr, Any_Integer);
5198 if R_Id not in All_Parameter_Restrictions then
5200 ("invalid restriction parameter identifier", Arg);
5202 elsif not Is_OK_Static_Expression (Expr) then
5203 Flag_Non_Static_Expr
5204 ("value must be static expression!", Expr);
5207 elsif not Is_Integer_Type (Etype (Expr))
5208 or else Expr_Value (Expr) < 0
5211 ("value must be non-negative integer", Arg);
5214 -- Restriction pragma is active
5216 Val := Expr_Value (Expr);
5218 if not UI_Is_In_Int_Range (Val) then
5220 ("pragma ignored, value too large?", Arg);
5223 -- Warning case. If the real restriction is active, then we
5224 -- ignore the request, since warning never overrides a real
5225 -- restriction. Otherwise we set the proper warning. Note that
5226 -- this circuit sets the warning again if it is already set,
5227 -- which is what we want, since the constant may have changed.
5230 if not Restriction_Active (R_Id) then
5232 (R_Id, N, Integer (UI_To_Int (Val)));
5233 Restriction_Warnings (R_Id) := True;
5236 -- Real restriction case, set restriction and make sure warning
5237 -- flag is off since real restriction always overrides warning.
5240 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5241 Restriction_Warnings (R_Id) := False;
5247 end Process_Restrictions_Or_Restriction_Warnings;
5249 ---------------------------------
5250 -- Process_Suppress_Unsuppress --
5251 ---------------------------------
5253 -- Note: this procedure makes entries in the check suppress data
5254 -- structures managed by Sem. See spec of package Sem for full
5255 -- details on how we handle recording of check suppression.
5257 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5262 In_Package_Spec : constant Boolean :=
5263 Is_Package_Or_Generic_Package (Current_Scope)
5264 and then not In_Package_Body (Current_Scope);
5266 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5267 -- Used to suppress a single check on the given entity
5269 --------------------------------
5270 -- Suppress_Unsuppress_Echeck --
5271 --------------------------------
5273 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5275 Set_Checks_May_Be_Suppressed (E);
5277 if In_Package_Spec then
5278 Push_Global_Suppress_Stack_Entry
5281 Suppress => Suppress_Case);
5284 Push_Local_Suppress_Stack_Entry
5287 Suppress => Suppress_Case);
5290 -- If this is a first subtype, and the base type is distinct,
5291 -- then also set the suppress flags on the base type.
5293 if Is_First_Subtype (E)
5294 and then Etype (E) /= E
5296 Suppress_Unsuppress_Echeck (Etype (E), C);
5298 end Suppress_Unsuppress_Echeck;
5300 -- Start of processing for Process_Suppress_Unsuppress
5303 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
5304 -- we want to generate checks for analysis purposes, as set by -gnatC
5306 if CodePeer_Mode and then Comes_From_Source (N) then
5310 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5311 -- declarative part or a package spec (RM 11.5(5)).
5313 if not Is_Configuration_Pragma then
5314 Check_Is_In_Decl_Part_Or_Package_Spec;
5317 Check_At_Least_N_Arguments (1);
5318 Check_At_Most_N_Arguments (2);
5319 Check_No_Identifier (Arg1);
5320 Check_Arg_Is_Identifier (Arg1);
5322 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5324 if C = No_Check_Id then
5326 ("argument of pragma% is not valid check name", Arg1);
5329 if not Suppress_Case
5330 and then (C = All_Checks or else C = Overflow_Check)
5332 Opt.Overflow_Checks_Unsuppressed := True;
5335 if Arg_Count = 1 then
5337 -- Make an entry in the local scope suppress table. This is the
5338 -- table that directly shows the current value of the scope
5339 -- suppress check for any check id value.
5341 if C = All_Checks then
5343 -- For All_Checks, we set all specific predefined checks with
5344 -- the exception of Elaboration_Check, which is handled
5345 -- specially because of not wanting All_Checks to have the
5346 -- effect of deactivating static elaboration order processing.
5348 for J in Scope_Suppress'Range loop
5349 if J /= Elaboration_Check then
5350 Scope_Suppress (J) := Suppress_Case;
5354 -- If not All_Checks, and predefined check, then set appropriate
5355 -- scope entry. Note that we will set Elaboration_Check if this
5356 -- is explicitly specified.
5358 elsif C in Predefined_Check_Id then
5359 Scope_Suppress (C) := Suppress_Case;
5362 -- Also make an entry in the Local_Entity_Suppress table
5364 Push_Local_Suppress_Stack_Entry
5367 Suppress => Suppress_Case);
5369 -- Case of two arguments present, where the check is suppressed for
5370 -- a specified entity (given as the second argument of the pragma)
5373 -- This is obsolescent in Ada 2005 mode
5375 if Ada_Version >= Ada_2005 then
5376 Check_Restriction (No_Obsolescent_Features, Arg2);
5379 Check_Optional_Identifier (Arg2, Name_On);
5380 E_Id := Get_Pragma_Arg (Arg2);
5383 if not Is_Entity_Name (E_Id) then
5385 ("second argument of pragma% must be entity name", Arg2);
5394 -- Enforce RM 11.5(7) which requires that for a pragma that
5395 -- appears within a package spec, the named entity must be
5396 -- within the package spec. We allow the package name itself
5397 -- to be mentioned since that makes sense, although it is not
5398 -- strictly allowed by 11.5(7).
5401 and then E /= Current_Scope
5402 and then Scope (E) /= Current_Scope
5405 ("entity in pragma% is not in package spec (RM 11.5(7))",
5409 -- Loop through homonyms. As noted below, in the case of a package
5410 -- spec, only homonyms within the package spec are considered.
5413 Suppress_Unsuppress_Echeck (E, C);
5415 if Is_Generic_Instance (E)
5416 and then Is_Subprogram (E)
5417 and then Present (Alias (E))
5419 Suppress_Unsuppress_Echeck (Alias (E), C);
5422 -- Move to next homonym if not aspect spec case
5424 exit when From_Aspect_Specification (N);
5428 -- If we are within a package specification, the pragma only
5429 -- applies to homonyms in the same scope.
5431 exit when In_Package_Spec
5432 and then Scope (E) /= Current_Scope;
5435 end Process_Suppress_Unsuppress;
5441 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5443 if Is_Imported (E) then
5445 ("cannot export entity& that was previously imported", Arg);
5447 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5449 ("cannot export entity& that has an address clause", Arg);
5452 Set_Is_Exported (E);
5454 -- Generate a reference for entity explicitly, because the
5455 -- identifier may be overloaded and name resolution will not
5458 Generate_Reference (E, Arg);
5460 -- Deal with exporting non-library level entity
5462 if not Is_Library_Level_Entity (E) then
5464 -- Not allowed at all for subprograms
5466 if Is_Subprogram (E) then
5467 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5469 -- Otherwise set public and statically allocated
5473 Set_Is_Statically_Allocated (E);
5475 -- Warn if the corresponding W flag is set and the pragma comes
5476 -- from source. The latter may not be true e.g. on VMS where we
5477 -- expand export pragmas for exception codes associated with
5478 -- imported or exported exceptions. We do not want to generate
5479 -- a warning for something that the user did not write.
5481 if Warn_On_Export_Import
5482 and then Comes_From_Source (Arg)
5485 ("?& has been made static as a result of Export", Arg, E);
5487 ("\this usage is non-standard and non-portable", Arg);
5492 if Warn_On_Export_Import and then Is_Type (E) then
5493 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5496 if Warn_On_Export_Import and Inside_A_Generic then
5498 ("all instances of& will have the same external name?", Arg, E);
5502 ----------------------------------------------
5503 -- Set_Extended_Import_Export_External_Name --
5504 ----------------------------------------------
5506 procedure Set_Extended_Import_Export_External_Name
5507 (Internal_Ent : Entity_Id;
5508 Arg_External : Node_Id)
5510 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5514 if No (Arg_External) then
5518 Check_Arg_Is_External_Name (Arg_External);
5520 if Nkind (Arg_External) = N_String_Literal then
5521 if String_Length (Strval (Arg_External)) = 0 then
5524 New_Name := Adjust_External_Name_Case (Arg_External);
5527 elsif Nkind (Arg_External) = N_Identifier then
5528 New_Name := Get_Default_External_Name (Arg_External);
5530 -- Check_Arg_Is_External_Name should let through only identifiers and
5531 -- string literals or static string expressions (which are folded to
5532 -- string literals).
5535 raise Program_Error;
5538 -- If we already have an external name set (by a prior normal Import
5539 -- or Export pragma), then the external names must match
5541 if Present (Interface_Name (Internal_Ent)) then
5542 Check_Matching_Internal_Names : declare
5543 S1 : constant String_Id := Strval (Old_Name);
5544 S2 : constant String_Id := Strval (New_Name);
5547 -- Called if names do not match
5553 procedure Mismatch is
5555 Error_Msg_Sloc := Sloc (Old_Name);
5557 ("external name does not match that given #",
5561 -- Start of processing for Check_Matching_Internal_Names
5564 if String_Length (S1) /= String_Length (S2) then
5568 for J in 1 .. String_Length (S1) loop
5569 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5574 end Check_Matching_Internal_Names;
5576 -- Otherwise set the given name
5579 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5580 Check_Duplicated_Export_Name (New_Name);
5582 end Set_Extended_Import_Export_External_Name;
5588 procedure Set_Imported (E : Entity_Id) is
5590 -- Error message if already imported or exported
5592 if Is_Exported (E) or else Is_Imported (E) then
5594 -- Error if being set Exported twice
5596 if Is_Exported (E) then
5597 Error_Msg_NE ("entity& was previously exported", N, E);
5599 -- OK if Import/Interface case
5601 elsif Import_Interface_Present (N) then
5604 -- Error if being set Imported twice
5607 Error_Msg_NE ("entity& was previously imported", N, E);
5610 Error_Msg_Name_1 := Pname;
5612 ("\(pragma% applies to all previous entities)", N);
5614 Error_Msg_Sloc := Sloc (E);
5615 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5617 -- Here if not previously imported or exported, OK to import
5620 Set_Is_Imported (E);
5622 -- If the entity is an object that is not at the library level,
5623 -- then it is statically allocated. We do not worry about objects
5624 -- with address clauses in this context since they are not really
5625 -- imported in the linker sense.
5628 and then not Is_Library_Level_Entity (E)
5629 and then No (Address_Clause (E))
5631 Set_Is_Statically_Allocated (E);
5638 -------------------------
5639 -- Set_Mechanism_Value --
5640 -------------------------
5642 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5643 -- analyzed, since it is semantic nonsense), so we get it in the exact
5644 -- form created by the parser.
5646 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5649 Mech_Name_Id : Name_Id;
5651 procedure Bad_Class;
5652 -- Signal bad descriptor class name
5654 procedure Bad_Mechanism;
5655 -- Signal bad mechanism name
5661 procedure Bad_Class is
5663 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5666 -------------------------
5667 -- Bad_Mechanism_Value --
5668 -------------------------
5670 procedure Bad_Mechanism is
5672 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5675 -- Start of processing for Set_Mechanism_Value
5678 if Mechanism (Ent) /= Default_Mechanism then
5680 ("mechanism for & has already been set", Mech_Name, Ent);
5683 -- MECHANISM_NAME ::= value | reference | descriptor |
5686 if Nkind (Mech_Name) = N_Identifier then
5687 if Chars (Mech_Name) = Name_Value then
5688 Set_Mechanism (Ent, By_Copy);
5691 elsif Chars (Mech_Name) = Name_Reference then
5692 Set_Mechanism (Ent, By_Reference);
5695 elsif Chars (Mech_Name) = Name_Descriptor then
5696 Check_VMS (Mech_Name);
5698 -- Descriptor => Short_Descriptor if pragma was given
5700 if Short_Descriptors then
5701 Set_Mechanism (Ent, By_Short_Descriptor);
5703 Set_Mechanism (Ent, By_Descriptor);
5708 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5709 Check_VMS (Mech_Name);
5710 Set_Mechanism (Ent, By_Short_Descriptor);
5713 elsif Chars (Mech_Name) = Name_Copy then
5715 ("bad mechanism name, Value assumed", Mech_Name);
5721 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5722 -- short_descriptor (CLASS_NAME)
5723 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5725 -- Note: this form is parsed as an indexed component
5727 elsif Nkind (Mech_Name) = N_Indexed_Component then
5728 Class := First (Expressions (Mech_Name));
5730 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5731 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5732 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5733 or else Present (Next (Class))
5737 Mech_Name_Id := Chars (Prefix (Mech_Name));
5739 -- Change Descriptor => Short_Descriptor if pragma was given
5741 if Mech_Name_Id = Name_Descriptor
5742 and then Short_Descriptors
5744 Mech_Name_Id := Name_Short_Descriptor;
5748 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5749 -- short_descriptor (Class => CLASS_NAME)
5750 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5752 -- Note: this form is parsed as a function call
5754 elsif Nkind (Mech_Name) = N_Function_Call then
5755 Param := First (Parameter_Associations (Mech_Name));
5757 if Nkind (Name (Mech_Name)) /= N_Identifier
5758 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5759 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5760 or else Present (Next (Param))
5761 or else No (Selector_Name (Param))
5762 or else Chars (Selector_Name (Param)) /= Name_Class
5766 Class := Explicit_Actual_Parameter (Param);
5767 Mech_Name_Id := Chars (Name (Mech_Name));
5774 -- Fall through here with Class set to descriptor class name
5776 Check_VMS (Mech_Name);
5778 if Nkind (Class) /= N_Identifier then
5781 elsif Mech_Name_Id = Name_Descriptor
5782 and then Chars (Class) = Name_UBS
5784 Set_Mechanism (Ent, By_Descriptor_UBS);
5786 elsif Mech_Name_Id = Name_Descriptor
5787 and then Chars (Class) = Name_UBSB
5789 Set_Mechanism (Ent, By_Descriptor_UBSB);
5791 elsif Mech_Name_Id = Name_Descriptor
5792 and then Chars (Class) = Name_UBA
5794 Set_Mechanism (Ent, By_Descriptor_UBA);
5796 elsif Mech_Name_Id = Name_Descriptor
5797 and then Chars (Class) = Name_S
5799 Set_Mechanism (Ent, By_Descriptor_S);
5801 elsif Mech_Name_Id = Name_Descriptor
5802 and then Chars (Class) = Name_SB
5804 Set_Mechanism (Ent, By_Descriptor_SB);
5806 elsif Mech_Name_Id = Name_Descriptor
5807 and then Chars (Class) = Name_A
5809 Set_Mechanism (Ent, By_Descriptor_A);
5811 elsif Mech_Name_Id = Name_Descriptor
5812 and then Chars (Class) = Name_NCA
5814 Set_Mechanism (Ent, By_Descriptor_NCA);
5816 elsif Mech_Name_Id = Name_Short_Descriptor
5817 and then Chars (Class) = Name_UBS
5819 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5821 elsif Mech_Name_Id = Name_Short_Descriptor
5822 and then Chars (Class) = Name_UBSB
5824 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5826 elsif Mech_Name_Id = Name_Short_Descriptor
5827 and then Chars (Class) = Name_UBA
5829 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5831 elsif Mech_Name_Id = Name_Short_Descriptor
5832 and then Chars (Class) = Name_S
5834 Set_Mechanism (Ent, By_Short_Descriptor_S);
5836 elsif Mech_Name_Id = Name_Short_Descriptor
5837 and then Chars (Class) = Name_SB
5839 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5841 elsif Mech_Name_Id = Name_Short_Descriptor
5842 and then Chars (Class) = Name_A
5844 Set_Mechanism (Ent, By_Short_Descriptor_A);
5846 elsif Mech_Name_Id = Name_Short_Descriptor
5847 and then Chars (Class) = Name_NCA
5849 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5854 end Set_Mechanism_Value;
5856 ---------------------------
5857 -- Set_Ravenscar_Profile --
5858 ---------------------------
5860 -- The tasks to be done here are
5862 -- Set required policies
5864 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5865 -- pragma Locking_Policy (Ceiling_Locking)
5867 -- Set Detect_Blocking mode
5869 -- Set required restrictions (see System.Rident for detailed list)
5871 -- Set the No_Dependence rules
5872 -- No_Dependence => Ada.Asynchronous_Task_Control
5873 -- No_Dependence => Ada.Calendar
5874 -- No_Dependence => Ada.Execution_Time.Group_Budget
5875 -- No_Dependence => Ada.Execution_Time.Timers
5876 -- No_Dependence => Ada.Task_Attributes
5877 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5879 procedure Set_Ravenscar_Profile (N : Node_Id) is
5880 Prefix_Entity : Entity_Id;
5881 Selector_Entity : Entity_Id;
5882 Prefix_Node : Node_Id;
5886 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5888 if Task_Dispatching_Policy /= ' '
5889 and then Task_Dispatching_Policy /= 'F'
5891 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5892 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5894 -- Set the FIFO_Within_Priorities policy, but always preserve
5895 -- System_Location since we like the error message with the run time
5899 Task_Dispatching_Policy := 'F';
5901 if Task_Dispatching_Policy_Sloc /= System_Location then
5902 Task_Dispatching_Policy_Sloc := Loc;
5906 -- pragma Locking_Policy (Ceiling_Locking)
5908 if Locking_Policy /= ' '
5909 and then Locking_Policy /= 'C'
5911 Error_Msg_Sloc := Locking_Policy_Sloc;
5912 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5914 -- Set the Ceiling_Locking policy, but preserve System_Location since
5915 -- we like the error message with the run time name.
5918 Locking_Policy := 'C';
5920 if Locking_Policy_Sloc /= System_Location then
5921 Locking_Policy_Sloc := Loc;
5925 -- pragma Detect_Blocking
5927 Detect_Blocking := True;
5929 -- Set the corresponding restrictions
5931 Set_Profile_Restrictions
5932 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5934 -- Set the No_Dependence restrictions
5936 -- The following No_Dependence restrictions:
5937 -- No_Dependence => Ada.Asynchronous_Task_Control
5938 -- No_Dependence => Ada.Calendar
5939 -- No_Dependence => Ada.Task_Attributes
5940 -- are already set by previous call to Set_Profile_Restrictions.
5942 -- Set the following restrictions which were added to Ada 2005:
5943 -- No_Dependence => Ada.Execution_Time.Group_Budget
5944 -- No_Dependence => Ada.Execution_Time.Timers
5946 if Ada_Version >= Ada_2005 then
5947 Name_Buffer (1 .. 3) := "ada";
5950 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5952 Name_Buffer (1 .. 14) := "execution_time";
5955 Selector_Entity := Make_Identifier (Loc, Name_Find);
5958 Make_Selected_Component
5960 Prefix => Prefix_Entity,
5961 Selector_Name => Selector_Entity);
5963 Name_Buffer (1 .. 13) := "group_budgets";
5966 Selector_Entity := Make_Identifier (Loc, Name_Find);
5969 Make_Selected_Component
5971 Prefix => Prefix_Node,
5972 Selector_Name => Selector_Entity);
5974 Set_Restriction_No_Dependence
5976 Warn => Treat_Restrictions_As_Warnings,
5977 Profile => Ravenscar);
5979 Name_Buffer (1 .. 6) := "timers";
5982 Selector_Entity := Make_Identifier (Loc, Name_Find);
5985 Make_Selected_Component
5987 Prefix => Prefix_Node,
5988 Selector_Name => Selector_Entity);
5990 Set_Restriction_No_Dependence
5992 Warn => Treat_Restrictions_As_Warnings,
5993 Profile => Ravenscar);
5996 -- Set the following restrictions which was added to Ada 2012 (see
5998 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6000 if Ada_Version >= Ada_2012 then
6001 Name_Buffer (1 .. 6) := "system";
6004 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6006 Name_Buffer (1 .. 15) := "multiprocessors";
6009 Selector_Entity := Make_Identifier (Loc, Name_Find);
6012 Make_Selected_Component
6014 Prefix => Prefix_Entity,
6015 Selector_Name => Selector_Entity);
6017 Name_Buffer (1 .. 19) := "dispatching_domains";
6020 Selector_Entity := Make_Identifier (Loc, Name_Find);
6023 Make_Selected_Component
6025 Prefix => Prefix_Node,
6026 Selector_Name => Selector_Entity);
6028 Set_Restriction_No_Dependence
6030 Warn => Treat_Restrictions_As_Warnings,
6031 Profile => Ravenscar);
6033 end Set_Ravenscar_Profile;
6035 -- Start of processing for Analyze_Pragma
6038 -- The following code is a defense against recursion. Not clear that
6039 -- this can happen legitimately, but perhaps some error situations
6040 -- can cause it, and we did see this recursion during testing.
6042 if Analyzed (N) then
6045 Set_Analyzed (N, True);
6048 -- Deal with unrecognized pragma
6050 if not Is_Pragma_Name (Pname) then
6051 if Warn_On_Unrecognized_Pragma then
6052 Error_Msg_Name_1 := Pname;
6053 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6055 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6056 if Is_Bad_Spelling_Of (Pname, PN) then
6057 Error_Msg_Name_1 := PN;
6058 Error_Msg_N -- CODEFIX
6059 ("\?possible misspelling of %!", Pragma_Identifier (N));
6068 -- Here to start processing for recognized pragma
6070 Prag_Id := Get_Pragma_Id (Pname);
6080 if Present (Pragma_Argument_Associations (N)) then
6081 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6082 Arg1 := First (Pragma_Argument_Associations (N));
6084 if Present (Arg1) then
6085 Arg2 := Next (Arg1);
6087 if Present (Arg2) then
6088 Arg3 := Next (Arg2);
6090 if Present (Arg3) then
6091 Arg4 := Next (Arg3);
6097 -- An enumeration type defines the pragmas that are supported by the
6098 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6099 -- into the corresponding enumeration value for the following case.
6107 -- pragma Abort_Defer;
6109 when Pragma_Abort_Defer =>
6111 Check_Arg_Count (0);
6113 -- The only required semantic processing is to check the
6114 -- placement. This pragma must appear at the start of the
6115 -- statement sequence of a handled sequence of statements.
6117 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6118 or else N /= First (Statements (Parent (N)))
6129 -- Note: this pragma also has some specific processing in Par.Prag
6130 -- because we want to set the Ada version mode during parsing.
6132 when Pragma_Ada_83 =>
6134 Check_Arg_Count (0);
6136 -- We really should check unconditionally for proper configuration
6137 -- pragma placement, since we really don't want mixed Ada modes
6138 -- within a single unit, and the GNAT reference manual has always
6139 -- said this was a configuration pragma, but we did not check and
6140 -- are hesitant to add the check now.
6142 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6143 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6144 -- or Ada 2012 mode.
6146 if Ada_Version >= Ada_2005 then
6147 Check_Valid_Configuration_Pragma;
6150 -- Now set Ada 83 mode
6152 Ada_Version := Ada_83;
6153 Ada_Version_Explicit := Ada_Version;
6161 -- Note: this pragma also has some specific processing in Par.Prag
6162 -- because we want to set the Ada 83 version mode during parsing.
6164 when Pragma_Ada_95 =>
6166 Check_Arg_Count (0);
6168 -- We really should check unconditionally for proper configuration
6169 -- pragma placement, since we really don't want mixed Ada modes
6170 -- within a single unit, and the GNAT reference manual has always
6171 -- said this was a configuration pragma, but we did not check and
6172 -- are hesitant to add the check now.
6174 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
6175 -- or Ada 95, so we must check if we are in Ada 2005 mode.
6177 if Ada_Version >= Ada_2005 then
6178 Check_Valid_Configuration_Pragma;
6181 -- Now set Ada 95 mode
6183 Ada_Version := Ada_95;
6184 Ada_Version_Explicit := Ada_Version;
6186 ---------------------
6187 -- Ada_05/Ada_2005 --
6188 ---------------------
6191 -- pragma Ada_05 (LOCAL_NAME);
6194 -- pragma Ada_2005 (LOCAL_NAME):
6196 -- Note: these pragmas also have some specific processing in Par.Prag
6197 -- because we want to set the Ada 2005 version mode during parsing.
6199 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6205 if Arg_Count = 1 then
6206 Check_Arg_Is_Local_Name (Arg1);
6207 E_Id := Get_Pragma_Arg (Arg1);
6209 if Etype (E_Id) = Any_Type then
6213 Set_Is_Ada_2005_Only (Entity (E_Id));
6216 Check_Arg_Count (0);
6218 -- For Ada_2005 we unconditionally enforce the documented
6219 -- configuration pragma placement, since we do not want to
6220 -- tolerate mixed modes in a unit involving Ada 2005. That
6221 -- would cause real difficulties for those cases where there
6222 -- are incompatibilities between Ada 95 and Ada 2005.
6224 Check_Valid_Configuration_Pragma;
6226 -- Now set appropriate Ada mode
6228 Ada_Version := Ada_2005;
6229 Ada_Version_Explicit := Ada_2005;
6233 ---------------------
6234 -- Ada_12/Ada_2012 --
6235 ---------------------
6238 -- pragma Ada_12 (LOCAL_NAME);
6241 -- pragma Ada_2012 (LOCAL_NAME):
6243 -- Note: these pragmas also have some specific processing in Par.Prag
6244 -- because we want to set the Ada 2012 version mode during parsing.
6246 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6252 if Arg_Count = 1 then
6253 Check_Arg_Is_Local_Name (Arg1);
6254 E_Id := Get_Pragma_Arg (Arg1);
6256 if Etype (E_Id) = Any_Type then
6260 Set_Is_Ada_2012_Only (Entity (E_Id));
6263 Check_Arg_Count (0);
6265 -- For Ada_2012 we unconditionally enforce the documented
6266 -- configuration pragma placement, since we do not want to
6267 -- tolerate mixed modes in a unit involving Ada 2012. That
6268 -- would cause real difficulties for those cases where there
6269 -- are incompatibilities between Ada 95 and Ada 2012. We could
6270 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6272 Check_Valid_Configuration_Pragma;
6274 -- Now set appropriate Ada mode
6276 Ada_Version := Ada_2012;
6277 Ada_Version_Explicit := Ada_2012;
6281 ----------------------
6282 -- All_Calls_Remote --
6283 ----------------------
6285 -- pragma All_Calls_Remote [(library_package_NAME)];
6287 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6288 Lib_Entity : Entity_Id;
6291 Check_Ada_83_Warning;
6292 Check_Valid_Library_Unit_Pragma;
6294 if Nkind (N) = N_Null_Statement then
6298 Lib_Entity := Find_Lib_Unit_Name;
6300 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6302 if Present (Lib_Entity)
6303 and then not Debug_Flag_U
6305 if not Is_Remote_Call_Interface (Lib_Entity) then
6306 Error_Pragma ("pragma% only apply to rci unit");
6308 -- Set flag for entity of the library unit
6311 Set_Has_All_Calls_Remote (Lib_Entity);
6315 end All_Calls_Remote;
6321 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6322 -- ARG ::= NAME | EXPRESSION
6324 -- The first two arguments are by convention intended to refer to an
6325 -- external tool and a tool-specific function. These arguments are
6328 when Pragma_Annotate => Annotate : declare
6334 Check_At_Least_N_Arguments (1);
6335 Check_Arg_Is_Identifier (Arg1);
6336 Check_No_Identifiers;
6339 -- Second parameter is optional, it is never analyzed
6344 -- Here if we have a second parameter
6347 -- Second parameter must be identifier
6349 Check_Arg_Is_Identifier (Arg2);
6351 -- Process remaining parameters if any
6354 while Present (Arg) loop
6355 Exp := Get_Pragma_Arg (Arg);
6358 if Is_Entity_Name (Exp) then
6361 -- For string literals, we assume Standard_String as the
6362 -- type, unless the string contains wide or wide_wide
6365 elsif Nkind (Exp) = N_String_Literal then
6366 if Has_Wide_Wide_Character (Exp) then
6367 Resolve (Exp, Standard_Wide_Wide_String);
6368 elsif Has_Wide_Character (Exp) then
6369 Resolve (Exp, Standard_Wide_String);
6371 Resolve (Exp, Standard_String);
6374 elsif Is_Overloaded (Exp) then
6376 ("ambiguous argument for pragma%", Exp);
6391 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6392 -- [, [Message =>] Static_String_EXPRESSION]);
6394 when Pragma_Assert => Assert : declare
6400 Check_At_Least_N_Arguments (1);
6401 Check_At_Most_N_Arguments (2);
6402 Check_Arg_Order ((Name_Check, Name_Message));
6403 Check_Optional_Identifier (Arg1, Name_Check);
6405 -- We treat pragma Assert as equivalent to:
6407 -- pragma Check (Assertion, condition [, msg]);
6409 -- So rewrite pragma in this manner, and analyze the result
6411 Expr := Get_Pragma_Arg (Arg1);
6413 Make_Pragma_Argument_Association (Loc,
6414 Expression => Make_Identifier (Loc, Name_Assertion)),
6416 Make_Pragma_Argument_Association (Sloc (Expr),
6417 Expression => Expr));
6419 if Arg_Count > 1 then
6420 Check_Optional_Identifier (Arg2, Name_Message);
6421 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6422 Append_To (Newa, Relocate_Node (Arg2));
6427 Chars => Name_Check,
6428 Pragma_Argument_Associations => Newa));
6432 ----------------------
6433 -- Assertion_Policy --
6434 ----------------------
6436 -- pragma Assertion_Policy (Check | Ignore)
6438 when Pragma_Assertion_Policy => Assertion_Policy : declare
6443 Check_Valid_Configuration_Pragma;
6444 Check_Arg_Count (1);
6445 Check_No_Identifiers;
6446 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6448 -- We treat pragma Assertion_Policy as equivalent to:
6450 -- pragma Check_Policy (Assertion, policy)
6452 -- So rewrite the pragma in that manner and link on to the chain
6453 -- of Check_Policy pragmas, marking the pragma as analyzed.
6455 Policy := Get_Pragma_Arg (Arg1);
6459 Chars => Name_Check_Policy,
6461 Pragma_Argument_Associations => New_List (
6462 Make_Pragma_Argument_Association (Loc,
6463 Expression => Make_Identifier (Loc, Name_Assertion)),
6465 Make_Pragma_Argument_Association (Loc,
6467 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6470 Set_Next_Pragma (N, Opt.Check_Policy_List);
6471 Opt.Check_Policy_List := N;
6472 end Assertion_Policy;
6474 ------------------------------
6475 -- Assume_No_Invalid_Values --
6476 ------------------------------
6478 -- pragma Assume_No_Invalid_Values (On | Off);
6480 when Pragma_Assume_No_Invalid_Values =>
6482 Check_Valid_Configuration_Pragma;
6483 Check_Arg_Count (1);
6484 Check_No_Identifiers;
6485 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6487 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6488 Assume_No_Invalid_Values := True;
6490 Assume_No_Invalid_Values := False;
6497 -- pragma AST_Entry (entry_IDENTIFIER);
6499 when Pragma_AST_Entry => AST_Entry : declare
6505 Check_Arg_Count (1);
6506 Check_No_Identifiers;
6507 Check_Arg_Is_Local_Name (Arg1);
6508 Ent := Entity (Get_Pragma_Arg (Arg1));
6510 -- Note: the implementation of the AST_Entry pragma could handle
6511 -- the entry family case fine, but for now we are consistent with
6512 -- the DEC rules, and do not allow the pragma, which of course
6513 -- has the effect of also forbidding the attribute.
6515 if Ekind (Ent) /= E_Entry then
6517 ("pragma% argument must be simple entry name", Arg1);
6519 elsif Is_AST_Entry (Ent) then
6521 ("duplicate % pragma for entry", Arg1);
6523 elsif Has_Homonym (Ent) then
6525 ("pragma% argument cannot specify overloaded entry", Arg1);
6529 FF : constant Entity_Id := First_Formal (Ent);
6532 if Present (FF) then
6533 if Present (Next_Formal (FF)) then
6535 ("entry for pragma% can have only one argument",
6538 elsif Parameter_Mode (FF) /= E_In_Parameter then
6540 ("entry parameter for pragma% must have mode IN",
6546 Set_Is_AST_Entry (Ent);
6554 -- pragma Asynchronous (LOCAL_NAME);
6556 when Pragma_Asynchronous => Asynchronous : declare
6564 procedure Process_Async_Pragma;
6565 -- Common processing for procedure and access-to-procedure case
6567 --------------------------
6568 -- Process_Async_Pragma --
6569 --------------------------
6571 procedure Process_Async_Pragma is
6574 Set_Is_Asynchronous (Nm);
6578 -- The formals should be of mode IN (RM E.4.1(6))
6581 while Present (S) loop
6582 Formal := Defining_Identifier (S);
6584 if Nkind (Formal) = N_Defining_Identifier
6585 and then Ekind (Formal) /= E_In_Parameter
6588 ("pragma% procedure can only have IN parameter",
6595 Set_Is_Asynchronous (Nm);
6596 end Process_Async_Pragma;
6598 -- Start of processing for pragma Asynchronous
6601 Check_Ada_83_Warning;
6602 Check_No_Identifiers;
6603 Check_Arg_Count (1);
6604 Check_Arg_Is_Local_Name (Arg1);
6606 if Debug_Flag_U then
6610 C_Ent := Cunit_Entity (Current_Sem_Unit);
6611 Analyze (Get_Pragma_Arg (Arg1));
6612 Nm := Entity (Get_Pragma_Arg (Arg1));
6614 if not Is_Remote_Call_Interface (C_Ent)
6615 and then not Is_Remote_Types (C_Ent)
6617 -- This pragma should only appear in an RCI or Remote Types
6618 -- unit (RM E.4.1(4)).
6621 ("pragma% not in Remote_Call_Interface or " &
6622 "Remote_Types unit");
6625 if Ekind (Nm) = E_Procedure
6626 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6628 if not Is_Remote_Call_Interface (Nm) then
6630 ("pragma% cannot be applied on non-remote procedure",
6634 L := Parameter_Specifications (Parent (Nm));
6635 Process_Async_Pragma;
6638 elsif Ekind (Nm) = E_Function then
6640 ("pragma% cannot be applied to function", Arg1);
6642 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6643 if Is_Record_Type (Nm) then
6645 -- A record type that is the Equivalent_Type for a remote
6646 -- access-to-subprogram type.
6648 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6651 -- A non-expanded RAS type (distribution is not enabled)
6653 N := Declaration_Node (Nm);
6656 if Nkind (N) = N_Full_Type_Declaration
6657 and then Nkind (Type_Definition (N)) =
6658 N_Access_Procedure_Definition
6660 L := Parameter_Specifications (Type_Definition (N));
6661 Process_Async_Pragma;
6663 if Is_Asynchronous (Nm)
6664 and then Expander_Active
6665 and then Get_PCS_Name /= Name_No_DSA
6667 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6672 ("pragma% cannot reference access-to-function type",
6676 -- Only other possibility is Access-to-class-wide type
6678 elsif Is_Access_Type (Nm)
6679 and then Is_Class_Wide_Type (Designated_Type (Nm))
6681 Check_First_Subtype (Arg1);
6682 Set_Is_Asynchronous (Nm);
6683 if Expander_Active then
6684 RACW_Type_Is_Asynchronous (Nm);
6688 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6696 -- pragma Atomic (LOCAL_NAME);
6698 when Pragma_Atomic =>
6699 Process_Atomic_Shared_Volatile;
6701 -----------------------
6702 -- Atomic_Components --
6703 -----------------------
6705 -- pragma Atomic_Components (array_LOCAL_NAME);
6707 -- This processing is shared by Volatile_Components
6709 when Pragma_Atomic_Components |
6710 Pragma_Volatile_Components =>
6712 Atomic_Components : declare
6719 Check_Ada_83_Warning;
6720 Check_No_Identifiers;
6721 Check_Arg_Count (1);
6722 Check_Arg_Is_Local_Name (Arg1);
6723 E_Id := Get_Pragma_Arg (Arg1);
6725 if Etype (E_Id) = Any_Type then
6731 Check_Duplicate_Pragma (E);
6733 if Rep_Item_Too_Early (E, N)
6735 Rep_Item_Too_Late (E, N)
6740 D := Declaration_Node (E);
6743 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6745 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6746 and then Nkind (D) = N_Object_Declaration
6747 and then Nkind (Object_Definition (D)) =
6748 N_Constrained_Array_Definition)
6750 -- The flag is set on the object, or on the base type
6752 if Nkind (D) /= N_Object_Declaration then
6756 Set_Has_Volatile_Components (E);
6758 if Prag_Id = Pragma_Atomic_Components then
6759 Set_Has_Atomic_Components (E);
6763 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6765 end Atomic_Components;
6767 --------------------
6768 -- Attach_Handler --
6769 --------------------
6771 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6773 when Pragma_Attach_Handler =>
6774 Check_Ada_83_Warning;
6775 Check_No_Identifiers;
6776 Check_Arg_Count (2);
6778 if No_Run_Time_Mode then
6779 Error_Msg_CRT ("Attach_Handler pragma", N);
6781 Check_Interrupt_Or_Attach_Handler;
6783 -- The expression that designates the attribute may depend on a
6784 -- discriminant, and is therefore a per- object expression, to
6785 -- be expanded in the init proc. If expansion is enabled, then
6786 -- perform semantic checks on a copy only.
6788 if Expander_Active then
6790 Temp : constant Node_Id :=
6791 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6793 Set_Parent (Temp, N);
6794 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6798 Analyze (Get_Pragma_Arg (Arg2));
6799 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6802 Process_Interrupt_Or_Attach_Handler;
6805 --------------------
6806 -- C_Pass_By_Copy --
6807 --------------------
6809 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6811 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6817 Check_Valid_Configuration_Pragma;
6818 Check_Arg_Count (1);
6819 Check_Optional_Identifier (Arg1, "max_size");
6821 Arg := Get_Pragma_Arg (Arg1);
6822 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6824 Val := Expr_Value (Arg);
6828 ("maximum size for pragma% must be positive", Arg1);
6830 elsif UI_Is_In_Int_Range (Val) then
6831 Default_C_Record_Mechanism := UI_To_Int (Val);
6833 -- If a giant value is given, Int'Last will do well enough.
6834 -- If sometime someone complains that a record larger than
6835 -- two gigabytes is not copied, we will worry about it then!
6838 Default_C_Record_Mechanism := Mechanism_Type'Last;
6846 -- pragma Check ([Name =>] Identifier,
6847 -- [Check =>] Boolean_Expression
6848 -- [,[Message =>] String_Expression]);
6850 when Pragma_Check => Check : declare
6855 -- Set True if category of assertions referenced by Name enabled
6859 Check_At_Least_N_Arguments (2);
6860 Check_At_Most_N_Arguments (3);
6861 Check_Optional_Identifier (Arg1, Name_Name);
6862 Check_Optional_Identifier (Arg2, Name_Check);
6864 if Arg_Count = 3 then
6865 Check_Optional_Identifier (Arg3, Name_Message);
6866 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6869 Check_Arg_Is_Identifier (Arg1);
6871 -- Indicate if pragma is enabled. The Original_Node reference here
6872 -- is to deal with pragma Assert rewritten as a Check pragma.
6874 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6877 Set_SCO_Pragma_Enabled (Loc);
6880 -- If expansion is active and the check is not enabled then we
6881 -- rewrite the Check as:
6883 -- if False and then condition then
6887 -- The reason we do this rewriting during semantic analysis rather
6888 -- than as part of normal expansion is that we cannot analyze and
6889 -- expand the code for the boolean expression directly, or it may
6890 -- cause insertion of actions that would escape the attempt to
6891 -- suppress the check code.
6893 -- Note that the Sloc for the if statement corresponds to the
6894 -- argument condition, not the pragma itself. The reason for this
6895 -- is that we may generate a warning if the condition is False at
6896 -- compile time, and we do not want to delete this warning when we
6897 -- delete the if statement.
6899 Expr := Get_Pragma_Arg (Arg2);
6901 if Expander_Active and then not Check_On then
6902 Eloc := Sloc (Expr);
6905 Make_If_Statement (Eloc,
6907 Make_And_Then (Eloc,
6908 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6909 Right_Opnd => Expr),
6910 Then_Statements => New_List (
6911 Make_Null_Statement (Eloc))));
6918 Analyze_And_Resolve (Expr, Any_Boolean);
6926 -- pragma Check_Name (check_IDENTIFIER);
6928 when Pragma_Check_Name =>
6929 Check_No_Identifiers;
6931 Check_Valid_Configuration_Pragma;
6932 Check_Arg_Count (1);
6933 Check_Arg_Is_Identifier (Arg1);
6936 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6939 for J in Check_Names.First .. Check_Names.Last loop
6940 if Check_Names.Table (J) = Nam then
6945 Check_Names.Append (Nam);
6952 -- pragma Check_Policy (
6953 -- [Name =>] IDENTIFIER,
6954 -- [Policy =>] POLICY_IDENTIFIER);
6956 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6958 -- Note: this is a configuration pragma, but it is allowed to appear
6961 when Pragma_Check_Policy =>
6963 Check_Arg_Count (2);
6964 Check_Optional_Identifier (Arg1, Name_Name);
6965 Check_Optional_Identifier (Arg2, Name_Policy);
6967 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6969 -- A Check_Policy pragma can appear either as a configuration
6970 -- pragma, or in a declarative part or a package spec (see RM
6971 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6972 -- followed for Check_Policy).
6974 if not Is_Configuration_Pragma then
6975 Check_Is_In_Decl_Part_Or_Package_Spec;
6978 Set_Next_Pragma (N, Opt.Check_Policy_List);
6979 Opt.Check_Policy_List := N;
6981 ---------------------
6982 -- CIL_Constructor --
6983 ---------------------
6985 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6987 -- Processing for this pragma is shared with Java_Constructor
6993 -- pragma Comment (static_string_EXPRESSION)
6995 -- Processing for pragma Comment shares the circuitry for pragma
6996 -- Ident. The only differences are that Ident enforces a limit of 31
6997 -- characters on its argument, and also enforces limitations on
6998 -- placement for DEC compatibility. Pragma Comment shares neither of
6999 -- these restrictions.
7005 -- pragma Common_Object (
7006 -- [Internal =>] LOCAL_NAME
7007 -- [, [External =>] EXTERNAL_SYMBOL]
7008 -- [, [Size =>] EXTERNAL_SYMBOL]);
7010 -- Processing for this pragma is shared with Psect_Object
7012 ------------------------
7013 -- Compile_Time_Error --
7014 ------------------------
7016 -- pragma Compile_Time_Error
7017 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7019 when Pragma_Compile_Time_Error =>
7021 Process_Compile_Time_Warning_Or_Error;
7023 --------------------------
7024 -- Compile_Time_Warning --
7025 --------------------------
7027 -- pragma Compile_Time_Warning
7028 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7030 when Pragma_Compile_Time_Warning =>
7032 Process_Compile_Time_Warning_Or_Error;
7038 when Pragma_Compiler_Unit =>
7040 Check_Arg_Count (0);
7041 Set_Is_Compiler_Unit (Get_Source_Unit (N));
7043 -----------------------------
7044 -- Complete_Representation --
7045 -----------------------------
7047 -- pragma Complete_Representation;
7049 when Pragma_Complete_Representation =>
7051 Check_Arg_Count (0);
7053 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7055 ("pragma & must appear within record representation clause");
7058 ----------------------------
7059 -- Complex_Representation --
7060 ----------------------------
7062 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7064 when Pragma_Complex_Representation => Complex_Representation : declare
7071 Check_Arg_Count (1);
7072 Check_Optional_Identifier (Arg1, Name_Entity);
7073 Check_Arg_Is_Local_Name (Arg1);
7074 E_Id := Get_Pragma_Arg (Arg1);
7076 if Etype (E_Id) = Any_Type then
7082 if not Is_Record_Type (E) then
7084 ("argument for pragma% must be record type", Arg1);
7087 Ent := First_Entity (E);
7090 or else No (Next_Entity (Ent))
7091 or else Present (Next_Entity (Next_Entity (Ent)))
7092 or else not Is_Floating_Point_Type (Etype (Ent))
7093 or else Etype (Ent) /= Etype (Next_Entity (Ent))
7096 ("record for pragma% must have two fields of the same "
7097 & "floating-point type", Arg1);
7100 Set_Has_Complex_Representation (Base_Type (E));
7102 -- We need to treat the type has having a non-standard
7103 -- representation, for back-end purposes, even though in
7104 -- general a complex will have the default representation
7105 -- of a record with two real components.
7107 Set_Has_Non_Standard_Rep (Base_Type (E));
7109 end Complex_Representation;
7111 -------------------------
7112 -- Component_Alignment --
7113 -------------------------
7115 -- pragma Component_Alignment (
7116 -- [Form =>] ALIGNMENT_CHOICE
7117 -- [, [Name =>] type_LOCAL_NAME]);
7119 -- ALIGNMENT_CHOICE ::=
7121 -- | Component_Size_4
7125 when Pragma_Component_Alignment => Component_AlignmentP : declare
7126 Args : Args_List (1 .. 2);
7127 Names : constant Name_List (1 .. 2) := (
7131 Form : Node_Id renames Args (1);
7132 Name : Node_Id renames Args (2);
7134 Atype : Component_Alignment_Kind;
7139 Gather_Associations (Names, Args);
7142 Error_Pragma ("missing Form argument for pragma%");
7145 Check_Arg_Is_Identifier (Form);
7147 -- Get proper alignment, note that Default = Component_Size on all
7148 -- machines we have so far, and we want to set this value rather
7149 -- than the default value to indicate that it has been explicitly
7150 -- set (and thus will not get overridden by the default component
7151 -- alignment for the current scope)
7153 if Chars (Form) = Name_Component_Size then
7154 Atype := Calign_Component_Size;
7156 elsif Chars (Form) = Name_Component_Size_4 then
7157 Atype := Calign_Component_Size_4;
7159 elsif Chars (Form) = Name_Default then
7160 Atype := Calign_Component_Size;
7162 elsif Chars (Form) = Name_Storage_Unit then
7163 Atype := Calign_Storage_Unit;
7167 ("invalid Form parameter for pragma%", Form);
7170 -- Case with no name, supplied, affects scope table entry
7174 (Scope_Stack.Last).Component_Alignment_Default := Atype;
7176 -- Case of name supplied
7179 Check_Arg_Is_Local_Name (Name);
7181 Typ := Entity (Name);
7184 or else Rep_Item_Too_Early (Typ, N)
7188 Typ := Underlying_Type (Typ);
7191 if not Is_Record_Type (Typ)
7192 and then not Is_Array_Type (Typ)
7195 ("Name parameter of pragma% must identify record or " &
7196 "array type", Name);
7199 -- An explicit Component_Alignment pragma overrides an
7200 -- implicit pragma Pack, but not an explicit one.
7202 if not Has_Pragma_Pack (Base_Type (Typ)) then
7203 Set_Is_Packed (Base_Type (Typ), False);
7204 Set_Component_Alignment (Base_Type (Typ), Atype);
7207 end Component_AlignmentP;
7213 -- pragma Controlled (first_subtype_LOCAL_NAME);
7215 when Pragma_Controlled => Controlled : declare
7219 Check_No_Identifiers;
7220 Check_Arg_Count (1);
7221 Check_Arg_Is_Local_Name (Arg1);
7222 Arg := Get_Pragma_Arg (Arg1);
7224 if not Is_Entity_Name (Arg)
7225 or else not Is_Access_Type (Entity (Arg))
7227 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7229 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7237 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
7238 -- [Entity =>] LOCAL_NAME);
7240 when Pragma_Convention => Convention : declare
7243 pragma Warnings (Off, C);
7244 pragma Warnings (Off, E);
7246 Check_Arg_Order ((Name_Convention, Name_Entity));
7247 Check_Ada_83_Warning;
7248 Check_Arg_Count (2);
7249 Process_Convention (C, E);
7252 ---------------------------
7253 -- Convention_Identifier --
7254 ---------------------------
7256 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
7257 -- [Convention =>] convention_IDENTIFIER);
7259 when Pragma_Convention_Identifier => Convention_Identifier : declare
7265 Check_Arg_Order ((Name_Name, Name_Convention));
7266 Check_Arg_Count (2);
7267 Check_Optional_Identifier (Arg1, Name_Name);
7268 Check_Optional_Identifier (Arg2, Name_Convention);
7269 Check_Arg_Is_Identifier (Arg1);
7270 Check_Arg_Is_Identifier (Arg2);
7271 Idnam := Chars (Get_Pragma_Arg (Arg1));
7272 Cname := Chars (Get_Pragma_Arg (Arg2));
7274 if Is_Convention_Name (Cname) then
7275 Record_Convention_Identifier
7276 (Idnam, Get_Convention_Id (Cname));
7279 ("second arg for % pragma must be convention", Arg2);
7281 end Convention_Identifier;
7287 -- pragma CPP_Class ([Entity =>] local_NAME)
7289 when Pragma_CPP_Class => CPP_Class : declare
7294 if Warn_On_Obsolescent_Feature then
7296 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7297 " by pragma import?", N);
7301 Check_Arg_Count (1);
7302 Check_Optional_Identifier (Arg1, Name_Entity);
7303 Check_Arg_Is_Local_Name (Arg1);
7305 Arg := Get_Pragma_Arg (Arg1);
7308 if Etype (Arg) = Any_Type then
7312 if not Is_Entity_Name (Arg)
7313 or else not Is_Type (Entity (Arg))
7315 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7318 Typ := Entity (Arg);
7320 if not Is_Tagged_Type (Typ) then
7321 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7324 -- Types treated as CPP classes must be declared limited (note:
7325 -- this used to be a warning but there is no real benefit to it
7326 -- since we did effectively intend to treat the type as limited
7329 if not Is_Limited_Type (Typ) then
7331 ("imported 'C'P'P type must be limited",
7332 Get_Pragma_Arg (Arg1));
7335 Set_Is_CPP_Class (Typ);
7336 Set_Convention (Typ, Convention_CPP);
7338 -- Imported CPP types must not have discriminants (because C++
7339 -- classes do not have discriminants).
7341 if Has_Discriminants (Typ) then
7343 ("imported 'C'P'P type cannot have discriminants",
7344 First (Discriminant_Specifications
7345 (Declaration_Node (Typ))));
7348 -- Components of imported CPP types must not have default
7349 -- expressions because the constructor (if any) is in the
7352 if Is_Incomplete_Or_Private_Type (Typ)
7353 and then No (Underlying_Type (Typ))
7355 -- It should be an error to apply pragma CPP to a private
7356 -- type if the underlying type is not visible (as it is
7357 -- for any representation item). For now, for backward
7358 -- compatibility we do nothing but we cannot check components
7359 -- because they are not available at this stage. All this code
7360 -- will be removed when we cleanup this obsolete GNAT pragma???
7366 Tdef : constant Node_Id :=
7367 Type_Definition (Declaration_Node (Typ));
7372 if Nkind (Tdef) = N_Record_Definition then
7373 Clist := Component_List (Tdef);
7375 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7376 Clist := Component_List (Record_Extension_Part (Tdef));
7379 if Present (Clist) then
7380 Comp := First (Component_Items (Clist));
7381 while Present (Comp) loop
7382 if Present (Expression (Comp)) then
7384 ("component of imported 'C'P'P type cannot have" &
7385 " default expression", Expression (Comp));
7395 ---------------------
7396 -- CPP_Constructor --
7397 ---------------------
7399 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7400 -- [, [External_Name =>] static_string_EXPRESSION ]
7401 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7403 when Pragma_CPP_Constructor => CPP_Constructor : declare
7407 Tag_Typ : Entity_Id;
7411 Check_At_Least_N_Arguments (1);
7412 Check_At_Most_N_Arguments (3);
7413 Check_Optional_Identifier (Arg1, Name_Entity);
7414 Check_Arg_Is_Local_Name (Arg1);
7416 Id := Get_Pragma_Arg (Arg1);
7417 Find_Program_Unit_Name (Id);
7419 -- If we did not find the name, we are done
7421 if Etype (Id) = Any_Type then
7425 Def_Id := Entity (Id);
7427 -- Check if already defined as constructor
7429 if Is_Constructor (Def_Id) then
7431 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7435 if Ekind (Def_Id) = E_Function
7436 and then (Is_CPP_Class (Etype (Def_Id))
7437 or else (Is_Class_Wide_Type (Etype (Def_Id))
7439 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7441 if Arg_Count >= 2 then
7442 Set_Imported (Def_Id);
7443 Set_Is_Public (Def_Id);
7444 Process_Interface_Name (Def_Id, Arg2, Arg3);
7447 Set_Has_Completion (Def_Id);
7448 Set_Is_Constructor (Def_Id);
7450 -- Imported C++ constructors are not dispatching primitives
7451 -- because in C++ they don't have a dispatch table slot.
7452 -- However, in Ada the constructor has the profile of a
7453 -- function that returns a tagged type and therefore it has
7454 -- been treated as a primitive operation during semantic
7455 -- analysis. We now remove it from the list of primitive
7456 -- operations of the type.
7458 if Is_Tagged_Type (Etype (Def_Id))
7459 and then not Is_Class_Wide_Type (Etype (Def_Id))
7461 pragma Assert (Is_Dispatching_Operation (Def_Id));
7462 Tag_Typ := Etype (Def_Id);
7464 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7465 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7469 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7470 Set_Is_Dispatching_Operation (Def_Id, False);
7473 -- For backward compatibility, if the constructor returns a
7474 -- class wide type, and we internally change the return type to
7475 -- the corresponding root type.
7477 if Is_Class_Wide_Type (Etype (Def_Id)) then
7478 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7482 ("pragma% requires function returning a 'C'P'P_Class type",
7485 end CPP_Constructor;
7491 when Pragma_CPP_Virtual => CPP_Virtual : declare
7495 if Warn_On_Obsolescent_Feature then
7497 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7506 when Pragma_CPP_Vtable => CPP_Vtable : declare
7510 if Warn_On_Obsolescent_Feature then
7512 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7521 -- pragma CPU (EXPRESSION);
7523 when Pragma_CPU => CPU : declare
7524 P : constant Node_Id := Parent (N);
7529 Check_No_Identifiers;
7530 Check_Arg_Count (1);
7534 if Nkind (P) = N_Subprogram_Body then
7535 Check_In_Main_Program;
7537 Arg := Get_Pragma_Arg (Arg1);
7538 Analyze_And_Resolve (Arg, Any_Integer);
7542 if not Is_Static_Expression (Arg) then
7543 Flag_Non_Static_Expr
7544 ("main subprogram affinity is not static!", Arg);
7547 -- If constraint error, then we already signalled an error
7549 elsif Raises_Constraint_Error (Arg) then
7552 -- Otherwise check in range
7556 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7557 -- This is the entity System.Multiprocessors.CPU_Range;
7559 Val : constant Uint := Expr_Value (Arg);
7562 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7564 Val > Expr_Value (Type_High_Bound (CPU_Id))
7567 ("main subprogram CPU is out of range", Arg1);
7573 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7577 elsif Nkind (P) = N_Task_Definition then
7578 Arg := Get_Pragma_Arg (Arg1);
7580 -- The expression must be analyzed in the special manner
7581 -- described in "Handling of Default and Per-Object
7582 -- Expressions" in sem.ads.
7584 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7586 -- Anything else is incorrect
7592 if Has_Pragma_CPU (P) then
7593 Error_Pragma ("duplicate pragma% not allowed");
7595 Set_Has_Pragma_CPU (P, True);
7597 if Nkind (P) = N_Task_Definition then
7598 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7607 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7609 when Pragma_Debug => Debug : declare
7618 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7621 if Arg_Count = 2 then
7624 Left_Opnd => Relocate_Node (Cond),
7625 Right_Opnd => Get_Pragma_Arg (Arg1));
7626 Call := Get_Pragma_Arg (Arg2);
7628 Call := Get_Pragma_Arg (Arg1);
7632 N_Indexed_Component,
7635 N_Selected_Component)
7637 -- If this pragma Debug comes from source, its argument was
7638 -- parsed as a name form (which is syntactically identical).
7639 -- Change it to a procedure call statement now.
7641 Change_Name_To_Procedure_Call_Statement (Call);
7643 elsif Nkind (Call) = N_Procedure_Call_Statement then
7645 -- Already in the form of a procedure call statement: nothing
7646 -- to do (could happen in case of an internally generated
7652 -- All other cases: diagnose error
7655 ("argument of pragma% is not procedure call", Sloc (Call));
7659 -- Rewrite into a conditional with an appropriate condition. We
7660 -- wrap the procedure call in a block so that overhead from e.g.
7661 -- use of the secondary stack does not generate execution overhead
7662 -- for suppressed conditions.
7664 Rewrite (N, Make_Implicit_If_Statement (N,
7666 Then_Statements => New_List (
7667 Make_Block_Statement (Loc,
7668 Handled_Statement_Sequence =>
7669 Make_Handled_Sequence_Of_Statements (Loc,
7670 Statements => New_List (Relocate_Node (Call)))))));
7678 -- pragma Debug_Policy (Check | Ignore)
7680 when Pragma_Debug_Policy =>
7682 Check_Arg_Count (1);
7683 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7684 Debug_Pragmas_Enabled :=
7685 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7687 ---------------------
7688 -- Detect_Blocking --
7689 ---------------------
7691 -- pragma Detect_Blocking;
7693 when Pragma_Detect_Blocking =>
7695 Check_Arg_Count (0);
7696 Check_Valid_Configuration_Pragma;
7697 Detect_Blocking := True;
7699 --------------------------
7700 -- Default_Storage_Pool --
7701 --------------------------
7703 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7705 when Pragma_Default_Storage_Pool =>
7707 Check_Arg_Count (1);
7709 -- Default_Storage_Pool can appear as a configuration pragma, or
7710 -- in a declarative part or a package spec.
7712 if not Is_Configuration_Pragma then
7713 Check_Is_In_Decl_Part_Or_Package_Spec;
7716 -- Case of Default_Storage_Pool (null);
7718 if Nkind (Expression (Arg1)) = N_Null then
7719 Analyze (Expression (Arg1));
7721 -- This is an odd case, this is not really an expression, so
7722 -- we don't have a type for it. So just set the type to Empty.
7724 Set_Etype (Expression (Arg1), Empty);
7726 -- Case of Default_Storage_Pool (storage_pool_NAME);
7729 -- If it's a configuration pragma, then the only allowed
7730 -- argument is "null".
7732 if Is_Configuration_Pragma then
7733 Error_Pragma_Arg ("NULL expected", Arg1);
7736 -- The expected type for a non-"null" argument is
7737 -- Root_Storage_Pool'Class.
7740 (Get_Pragma_Arg (Arg1),
7741 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7744 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7745 -- for an access type will use this information to set the
7746 -- appropriate attributes of the access type.
7748 Default_Pool := Expression (Arg1);
7754 when Pragma_Dimension =>
7756 Check_Arg_Count (4);
7757 Check_No_Identifiers;
7758 Check_Arg_Is_Local_Name (Arg1);
7760 if not Is_Type (Arg1) then
7761 Error_Pragma ("first argument for pragma% must be subtype");
7764 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7765 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7766 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7772 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7774 when Pragma_Discard_Names => Discard_Names : declare
7779 Check_Ada_83_Warning;
7781 -- Deal with configuration pragma case
7783 if Arg_Count = 0 and then Is_Configuration_Pragma then
7784 Global_Discard_Names := True;
7787 -- Otherwise, check correct appropriate context
7790 Check_Is_In_Decl_Part_Or_Package_Spec;
7792 if Arg_Count = 0 then
7794 -- If there is no parameter, then from now on this pragma
7795 -- applies to any enumeration, exception or tagged type
7796 -- defined in the current declarative part, and recursively
7797 -- to any nested scope.
7799 Set_Discard_Names (Current_Scope);
7803 Check_Arg_Count (1);
7804 Check_Optional_Identifier (Arg1, Name_On);
7805 Check_Arg_Is_Local_Name (Arg1);
7807 E_Id := Get_Pragma_Arg (Arg1);
7809 if Etype (E_Id) = Any_Type then
7815 if (Is_First_Subtype (E)
7817 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7818 or else Ekind (E) = E_Exception
7820 Set_Discard_Names (E);
7823 ("inappropriate entity for pragma%", Arg1);
7834 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7836 when Pragma_Elaborate => Elaborate : declare
7841 -- Pragma must be in context items list of a compilation unit
7843 if not Is_In_Context_Clause then
7847 -- Must be at least one argument
7849 if Arg_Count = 0 then
7850 Error_Pragma ("pragma% requires at least one argument");
7853 -- In Ada 83 mode, there can be no items following it in the
7854 -- context list except other pragmas and implicit with clauses
7855 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7856 -- placement rule does not apply.
7858 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7860 while Present (Citem) loop
7861 if Nkind (Citem) = N_Pragma
7862 or else (Nkind (Citem) = N_With_Clause
7863 and then Implicit_With (Citem))
7868 ("(Ada 83) pragma% must be at end of context clause");
7875 -- Finally, the arguments must all be units mentioned in a with
7876 -- clause in the same context clause. Note we already checked (in
7877 -- Par.Prag) that the arguments are all identifiers or selected
7881 Outer : while Present (Arg) loop
7882 Citem := First (List_Containing (N));
7883 Inner : while Citem /= N loop
7884 if Nkind (Citem) = N_With_Clause
7885 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7887 Set_Elaborate_Present (Citem, True);
7888 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7889 Generate_Reference (Entity (Name (Citem)), Citem);
7891 -- With the pragma present, elaboration calls on
7892 -- subprograms from the named unit need no further
7893 -- checks, as long as the pragma appears in the current
7894 -- compilation unit. If the pragma appears in some unit
7895 -- in the context, there might still be a need for an
7896 -- Elaborate_All_Desirable from the current compilation
7897 -- to the named unit, so we keep the check enabled.
7899 if In_Extended_Main_Source_Unit (N) then
7900 Set_Suppress_Elaboration_Warnings
7901 (Entity (Name (Citem)));
7912 ("argument of pragma% is not with'ed unit", Arg);
7918 -- Give a warning if operating in static mode with -gnatwl
7919 -- (elaboration warnings enabled) switch set.
7921 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7923 ("?use of pragma Elaborate may not be safe", N);
7925 ("?use pragma Elaborate_All instead if possible", N);
7933 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7935 when Pragma_Elaborate_All => Elaborate_All : declare
7940 Check_Ada_83_Warning;
7942 -- Pragma must be in context items list of a compilation unit
7944 if not Is_In_Context_Clause then
7948 -- Must be at least one argument
7950 if Arg_Count = 0 then
7951 Error_Pragma ("pragma% requires at least one argument");
7954 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7955 -- have to appear at the end of the context clause, but may
7956 -- appear mixed in with other items, even in Ada 83 mode.
7958 -- Final check: the arguments must all be units mentioned in
7959 -- a with clause in the same context clause. Note that we
7960 -- already checked (in Par.Prag) that all the arguments are
7961 -- either identifiers or selected components.
7964 Outr : while Present (Arg) loop
7965 Citem := First (List_Containing (N));
7966 Innr : while Citem /= N loop
7967 if Nkind (Citem) = N_With_Clause
7968 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7970 Set_Elaborate_All_Present (Citem, True);
7971 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7973 -- Suppress warnings and elaboration checks on the named
7974 -- unit if the pragma is in the current compilation, as
7975 -- for pragma Elaborate.
7977 if In_Extended_Main_Source_Unit (N) then
7978 Set_Suppress_Elaboration_Warnings
7979 (Entity (Name (Citem)));
7988 Set_Error_Posted (N);
7990 ("argument of pragma% is not with'ed unit", Arg);
7997 --------------------
7998 -- Elaborate_Body --
7999 --------------------
8001 -- pragma Elaborate_Body [( library_unit_NAME )];
8003 when Pragma_Elaborate_Body => Elaborate_Body : declare
8004 Cunit_Node : Node_Id;
8005 Cunit_Ent : Entity_Id;
8008 Check_Ada_83_Warning;
8009 Check_Valid_Library_Unit_Pragma;
8011 if Nkind (N) = N_Null_Statement then
8015 Cunit_Node := Cunit (Current_Sem_Unit);
8016 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8018 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8021 Error_Pragma ("pragma% must refer to a spec, not a body");
8023 Set_Body_Required (Cunit_Node, True);
8024 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8026 -- If we are in dynamic elaboration mode, then we suppress
8027 -- elaboration warnings for the unit, since it is definitely
8028 -- fine NOT to do dynamic checks at the first level (and such
8029 -- checks will be suppressed because no elaboration boolean
8030 -- is created for Elaborate_Body packages).
8032 -- But in the static model of elaboration, Elaborate_Body is
8033 -- definitely NOT good enough to ensure elaboration safety on
8034 -- its own, since the body may WITH other units that are not
8035 -- safe from an elaboration point of view, so a client must
8036 -- still do an Elaborate_All on such units.
8038 -- Debug flag -gnatdD restores the old behavior of 3.13, where
8039 -- Elaborate_Body always suppressed elab warnings.
8041 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8042 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8047 ------------------------
8048 -- Elaboration_Checks --
8049 ------------------------
8051 -- pragma Elaboration_Checks (Static | Dynamic);
8053 when Pragma_Elaboration_Checks =>
8055 Check_Arg_Count (1);
8056 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8057 Dynamic_Elaboration_Checks :=
8058 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8064 -- pragma Eliminate (
8065 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
8066 -- [,[Entity =>] IDENTIFIER |
8067 -- SELECTED_COMPONENT |
8069 -- [, OVERLOADING_RESOLUTION]);
8071 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8074 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8077 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8079 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8080 -- Result_Type => result_SUBTYPE_NAME]
8082 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8083 -- SUBTYPE_NAME ::= STRING_LITERAL
8085 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8086 -- SOURCE_TRACE ::= STRING_LITERAL
8088 when Pragma_Eliminate => Eliminate : declare
8089 Args : Args_List (1 .. 5);
8090 Names : constant Name_List (1 .. 5) := (
8093 Name_Parameter_Types,
8095 Name_Source_Location);
8097 Unit_Name : Node_Id renames Args (1);
8098 Entity : Node_Id renames Args (2);
8099 Parameter_Types : Node_Id renames Args (3);
8100 Result_Type : Node_Id renames Args (4);
8101 Source_Location : Node_Id renames Args (5);
8105 Check_Valid_Configuration_Pragma;
8106 Gather_Associations (Names, Args);
8108 if No (Unit_Name) then
8109 Error_Pragma ("missing Unit_Name argument for pragma%");
8113 and then (Present (Parameter_Types)
8115 Present (Result_Type)
8117 Present (Source_Location))
8119 Error_Pragma ("missing Entity argument for pragma%");
8122 if (Present (Parameter_Types)
8124 Present (Result_Type))
8126 Present (Source_Location)
8129 ("parameter profile and source location cannot " &
8130 "be used together in pragma%");
8133 Process_Eliminate_Pragma
8147 -- [ Convention =>] convention_IDENTIFIER,
8148 -- [ Entity =>] local_NAME
8149 -- [, [External_Name =>] static_string_EXPRESSION ]
8150 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8152 when Pragma_Export => Export : declare
8156 pragma Warnings (Off, C);
8159 Check_Ada_83_Warning;
8165 Check_At_Least_N_Arguments (2);
8166 Check_At_Most_N_Arguments (4);
8167 Process_Convention (C, Def_Id);
8169 if Ekind (Def_Id) /= E_Constant then
8170 Note_Possible_Modification
8171 (Get_Pragma_Arg (Arg2), Sure => False);
8174 Process_Interface_Name (Def_Id, Arg3, Arg4);
8175 Set_Exported (Def_Id, Arg2);
8177 -- If the entity is a deferred constant, propagate the information
8178 -- to the full view, because gigi elaborates the full view only.
8180 if Ekind (Def_Id) = E_Constant
8181 and then Present (Full_View (Def_Id))
8184 Id2 : constant Entity_Id := Full_View (Def_Id);
8186 Set_Is_Exported (Id2, Is_Exported (Def_Id));
8187 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
8188 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8193 ----------------------
8194 -- Export_Exception --
8195 ----------------------
8197 -- pragma Export_Exception (
8198 -- [Internal =>] LOCAL_NAME
8199 -- [, [External =>] EXTERNAL_SYMBOL]
8200 -- [, [Form =>] Ada | VMS]
8201 -- [, [Code =>] static_integer_EXPRESSION]);
8203 when Pragma_Export_Exception => Export_Exception : declare
8204 Args : Args_List (1 .. 4);
8205 Names : constant Name_List (1 .. 4) := (
8211 Internal : Node_Id renames Args (1);
8212 External : Node_Id renames Args (2);
8213 Form : Node_Id renames Args (3);
8214 Code : Node_Id renames Args (4);
8219 if Inside_A_Generic then
8220 Error_Pragma ("pragma% cannot be used for generic entities");
8223 Gather_Associations (Names, Args);
8224 Process_Extended_Import_Export_Exception_Pragma (
8225 Arg_Internal => Internal,
8226 Arg_External => External,
8230 if not Is_VMS_Exception (Entity (Internal)) then
8231 Set_Exported (Entity (Internal), Internal);
8233 end Export_Exception;
8235 ---------------------
8236 -- Export_Function --
8237 ---------------------
8239 -- pragma Export_Function (
8240 -- [Internal =>] LOCAL_NAME
8241 -- [, [External =>] EXTERNAL_SYMBOL]
8242 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8243 -- [, [Result_Type =>] TYPE_DESIGNATOR]
8244 -- [, [Mechanism =>] MECHANISM]
8245 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8247 -- EXTERNAL_SYMBOL ::=
8249 -- | static_string_EXPRESSION
8251 -- PARAMETER_TYPES ::=
8253 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8255 -- TYPE_DESIGNATOR ::=
8257 -- | subtype_Name ' Access
8261 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8263 -- MECHANISM_ASSOCIATION ::=
8264 -- [formal_parameter_NAME =>] MECHANISM_NAME
8266 -- MECHANISM_NAME ::=
8269 -- | Descriptor [([Class =>] CLASS_NAME)]
8271 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8273 when Pragma_Export_Function => Export_Function : declare
8274 Args : Args_List (1 .. 6);
8275 Names : constant Name_List (1 .. 6) := (
8278 Name_Parameter_Types,
8281 Name_Result_Mechanism);
8283 Internal : Node_Id renames Args (1);
8284 External : Node_Id renames Args (2);
8285 Parameter_Types : Node_Id renames Args (3);
8286 Result_Type : Node_Id renames Args (4);
8287 Mechanism : Node_Id renames Args (5);
8288 Result_Mechanism : Node_Id renames Args (6);
8292 Gather_Associations (Names, Args);
8293 Process_Extended_Import_Export_Subprogram_Pragma (
8294 Arg_Internal => Internal,
8295 Arg_External => External,
8296 Arg_Parameter_Types => Parameter_Types,
8297 Arg_Result_Type => Result_Type,
8298 Arg_Mechanism => Mechanism,
8299 Arg_Result_Mechanism => Result_Mechanism);
8300 end Export_Function;
8306 -- pragma Export_Object (
8307 -- [Internal =>] LOCAL_NAME
8308 -- [, [External =>] EXTERNAL_SYMBOL]
8309 -- [, [Size =>] EXTERNAL_SYMBOL]);
8311 -- EXTERNAL_SYMBOL ::=
8313 -- | static_string_EXPRESSION
8315 -- PARAMETER_TYPES ::=
8317 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8319 -- TYPE_DESIGNATOR ::=
8321 -- | subtype_Name ' Access
8325 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8327 -- MECHANISM_ASSOCIATION ::=
8328 -- [formal_parameter_NAME =>] MECHANISM_NAME
8330 -- MECHANISM_NAME ::=
8333 -- | Descriptor [([Class =>] CLASS_NAME)]
8335 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8337 when Pragma_Export_Object => Export_Object : declare
8338 Args : Args_List (1 .. 3);
8339 Names : constant Name_List (1 .. 3) := (
8344 Internal : Node_Id renames Args (1);
8345 External : Node_Id renames Args (2);
8346 Size : Node_Id renames Args (3);
8350 Gather_Associations (Names, Args);
8351 Process_Extended_Import_Export_Object_Pragma (
8352 Arg_Internal => Internal,
8353 Arg_External => External,
8357 ----------------------
8358 -- Export_Procedure --
8359 ----------------------
8361 -- pragma Export_Procedure (
8362 -- [Internal =>] LOCAL_NAME
8363 -- [, [External =>] EXTERNAL_SYMBOL]
8364 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8365 -- [, [Mechanism =>] MECHANISM]);
8367 -- EXTERNAL_SYMBOL ::=
8369 -- | static_string_EXPRESSION
8371 -- PARAMETER_TYPES ::=
8373 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8375 -- TYPE_DESIGNATOR ::=
8377 -- | subtype_Name ' Access
8381 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8383 -- MECHANISM_ASSOCIATION ::=
8384 -- [formal_parameter_NAME =>] MECHANISM_NAME
8386 -- MECHANISM_NAME ::=
8389 -- | Descriptor [([Class =>] CLASS_NAME)]
8391 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8393 when Pragma_Export_Procedure => Export_Procedure : declare
8394 Args : Args_List (1 .. 4);
8395 Names : constant Name_List (1 .. 4) := (
8398 Name_Parameter_Types,
8401 Internal : Node_Id renames Args (1);
8402 External : Node_Id renames Args (2);
8403 Parameter_Types : Node_Id renames Args (3);
8404 Mechanism : Node_Id renames Args (4);
8408 Gather_Associations (Names, Args);
8409 Process_Extended_Import_Export_Subprogram_Pragma (
8410 Arg_Internal => Internal,
8411 Arg_External => External,
8412 Arg_Parameter_Types => Parameter_Types,
8413 Arg_Mechanism => Mechanism);
8414 end Export_Procedure;
8420 -- pragma Export_Value (
8421 -- [Value =>] static_integer_EXPRESSION,
8422 -- [Link_Name =>] static_string_EXPRESSION);
8424 when Pragma_Export_Value =>
8426 Check_Arg_Order ((Name_Value, Name_Link_Name));
8427 Check_Arg_Count (2);
8429 Check_Optional_Identifier (Arg1, Name_Value);
8430 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8432 Check_Optional_Identifier (Arg2, Name_Link_Name);
8433 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8435 -----------------------------
8436 -- Export_Valued_Procedure --
8437 -----------------------------
8439 -- pragma Export_Valued_Procedure (
8440 -- [Internal =>] LOCAL_NAME
8441 -- [, [External =>] EXTERNAL_SYMBOL,]
8442 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8443 -- [, [Mechanism =>] MECHANISM]);
8445 -- EXTERNAL_SYMBOL ::=
8447 -- | static_string_EXPRESSION
8449 -- PARAMETER_TYPES ::=
8451 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8453 -- TYPE_DESIGNATOR ::=
8455 -- | subtype_Name ' Access
8459 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8461 -- MECHANISM_ASSOCIATION ::=
8462 -- [formal_parameter_NAME =>] MECHANISM_NAME
8464 -- MECHANISM_NAME ::=
8467 -- | Descriptor [([Class =>] CLASS_NAME)]
8469 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8471 when Pragma_Export_Valued_Procedure =>
8472 Export_Valued_Procedure : declare
8473 Args : Args_List (1 .. 4);
8474 Names : constant Name_List (1 .. 4) := (
8477 Name_Parameter_Types,
8480 Internal : Node_Id renames Args (1);
8481 External : Node_Id renames Args (2);
8482 Parameter_Types : Node_Id renames Args (3);
8483 Mechanism : Node_Id renames Args (4);
8487 Gather_Associations (Names, Args);
8488 Process_Extended_Import_Export_Subprogram_Pragma (
8489 Arg_Internal => Internal,
8490 Arg_External => External,
8491 Arg_Parameter_Types => Parameter_Types,
8492 Arg_Mechanism => Mechanism);
8493 end Export_Valued_Procedure;
8499 -- pragma Extend_System ([Name =>] Identifier);
8501 when Pragma_Extend_System => Extend_System : declare
8504 Check_Valid_Configuration_Pragma;
8505 Check_Arg_Count (1);
8506 Check_Optional_Identifier (Arg1, Name_Name);
8507 Check_Arg_Is_Identifier (Arg1);
8509 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8512 and then Name_Buffer (1 .. 4) = "aux_"
8514 if Present (System_Extend_Pragma_Arg) then
8515 if Chars (Get_Pragma_Arg (Arg1)) =
8516 Chars (Expression (System_Extend_Pragma_Arg))
8520 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8521 Error_Pragma ("pragma% conflicts with that #");
8525 System_Extend_Pragma_Arg := Arg1;
8527 if not GNAT_Mode then
8528 System_Extend_Unit := Arg1;
8532 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8536 ------------------------
8537 -- Extensions_Allowed --
8538 ------------------------
8540 -- pragma Extensions_Allowed (ON | OFF);
8542 when Pragma_Extensions_Allowed =>
8544 Check_Arg_Count (1);
8545 Check_No_Identifiers;
8546 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8548 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8549 Extensions_Allowed := True;
8550 Ada_Version := Ada_Version_Type'Last;
8553 Extensions_Allowed := False;
8554 Ada_Version := Ada_Version_Explicit;
8561 -- pragma External (
8562 -- [ Convention =>] convention_IDENTIFIER,
8563 -- [ Entity =>] local_NAME
8564 -- [, [External_Name =>] static_string_EXPRESSION ]
8565 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8567 when Pragma_External => External : declare
8571 pragma Warnings (Off, C);
8580 Check_At_Least_N_Arguments (2);
8581 Check_At_Most_N_Arguments (4);
8582 Process_Convention (C, Def_Id);
8583 Note_Possible_Modification
8584 (Get_Pragma_Arg (Arg2), Sure => False);
8585 Process_Interface_Name (Def_Id, Arg3, Arg4);
8586 Set_Exported (Def_Id, Arg2);
8589 --------------------------
8590 -- External_Name_Casing --
8591 --------------------------
8593 -- pragma External_Name_Casing (
8594 -- UPPERCASE | LOWERCASE
8595 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8597 when Pragma_External_Name_Casing => External_Name_Casing : declare
8600 Check_No_Identifiers;
8602 if Arg_Count = 2 then
8604 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8606 case Chars (Get_Pragma_Arg (Arg2)) is
8608 Opt.External_Name_Exp_Casing := As_Is;
8610 when Name_Uppercase =>
8611 Opt.External_Name_Exp_Casing := Uppercase;
8613 when Name_Lowercase =>
8614 Opt.External_Name_Exp_Casing := Lowercase;
8621 Check_Arg_Count (1);
8624 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8626 case Chars (Get_Pragma_Arg (Arg1)) is
8627 when Name_Uppercase =>
8628 Opt.External_Name_Imp_Casing := Uppercase;
8630 when Name_Lowercase =>
8631 Opt.External_Name_Imp_Casing := Lowercase;
8636 end External_Name_Casing;
8638 --------------------------
8639 -- Favor_Top_Level --
8640 --------------------------
8642 -- pragma Favor_Top_Level (type_NAME);
8644 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8645 Named_Entity : Entity_Id;
8649 Check_No_Identifiers;
8650 Check_Arg_Count (1);
8651 Check_Arg_Is_Local_Name (Arg1);
8652 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8654 -- If it's an access-to-subprogram type (in particular, not a
8655 -- subtype), set the flag on that type.
8657 if Is_Access_Subprogram_Type (Named_Entity) then
8658 Set_Can_Use_Internal_Rep (Named_Entity, False);
8660 -- Otherwise it's an error (name denotes the wrong sort of entity)
8664 ("access-to-subprogram type expected",
8665 Get_Pragma_Arg (Arg1));
8667 end Favor_Top_Level;
8673 -- pragma Fast_Math;
8675 when Pragma_Fast_Math =>
8677 Check_No_Identifiers;
8678 Check_Valid_Configuration_Pragma;
8681 ---------------------------
8682 -- Finalize_Storage_Only --
8683 ---------------------------
8685 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8687 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8688 Assoc : constant Node_Id := Arg1;
8689 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8694 Check_No_Identifiers;
8695 Check_Arg_Count (1);
8696 Check_Arg_Is_Local_Name (Arg1);
8698 Find_Type (Type_Id);
8699 Typ := Entity (Type_Id);
8702 or else Rep_Item_Too_Early (Typ, N)
8706 Typ := Underlying_Type (Typ);
8709 if not Is_Controlled (Typ) then
8710 Error_Pragma ("pragma% must specify controlled type");
8713 Check_First_Subtype (Arg1);
8715 if Finalize_Storage_Only (Typ) then
8716 Error_Pragma ("duplicate pragma%, only one allowed");
8718 elsif not Rep_Item_Too_Late (Typ, N) then
8719 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8721 end Finalize_Storage;
8723 --------------------------
8724 -- Float_Representation --
8725 --------------------------
8727 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8729 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8731 when Pragma_Float_Representation => Float_Representation : declare
8739 if Arg_Count = 1 then
8740 Check_Valid_Configuration_Pragma;
8742 Check_Arg_Count (2);
8743 Check_Optional_Identifier (Arg2, Name_Entity);
8744 Check_Arg_Is_Local_Name (Arg2);
8747 Check_No_Identifier (Arg1);
8748 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8750 if not OpenVMS_On_Target then
8751 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8753 ("?pragma% ignored (applies only to Open'V'M'S)");
8759 -- One argument case
8761 if Arg_Count = 1 then
8762 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8763 if Opt.Float_Format = 'I' then
8764 Error_Pragma ("'I'E'E'E format previously specified");
8767 Opt.Float_Format := 'V';
8770 if Opt.Float_Format = 'V' then
8771 Error_Pragma ("'V'A'X format previously specified");
8774 Opt.Float_Format := 'I';
8777 Set_Standard_Fpt_Formats;
8779 -- Two argument case
8782 Argx := Get_Pragma_Arg (Arg2);
8784 if not Is_Entity_Name (Argx)
8785 or else not Is_Floating_Point_Type (Entity (Argx))
8788 ("second argument of% pragma must be floating-point type",
8792 Ent := Entity (Argx);
8793 Digs := UI_To_Int (Digits_Value (Ent));
8795 -- Two arguments, VAX_Float case
8797 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8799 when 6 => Set_F_Float (Ent);
8800 when 9 => Set_D_Float (Ent);
8801 when 15 => Set_G_Float (Ent);
8805 ("wrong digits value, must be 6,9 or 15", Arg2);
8808 -- Two arguments, IEEE_Float case
8812 when 6 => Set_IEEE_Short (Ent);
8813 when 15 => Set_IEEE_Long (Ent);
8817 ("wrong digits value, must be 6 or 15", Arg2);
8821 end Float_Representation;
8827 -- pragma Ident (static_string_EXPRESSION)
8829 -- Note: pragma Comment shares this processing. Pragma Comment is
8830 -- identical to Ident, except that the restriction of the argument to
8831 -- 31 characters and the placement restrictions are not enforced for
8834 when Pragma_Ident | Pragma_Comment => Ident : declare
8839 Check_Arg_Count (1);
8840 Check_No_Identifiers;
8841 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8844 -- For pragma Ident, preserve DEC compatibility by requiring the
8845 -- pragma to appear in a declarative part or package spec.
8847 if Prag_Id = Pragma_Ident then
8848 Check_Is_In_Decl_Part_Or_Package_Spec;
8851 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8858 GP := Parent (Parent (N));
8860 if Nkind_In (GP, N_Package_Declaration,
8861 N_Generic_Package_Declaration)
8866 -- If we have a compilation unit, then record the ident value,
8867 -- checking for improper duplication.
8869 if Nkind (GP) = N_Compilation_Unit then
8870 CS := Ident_String (Current_Sem_Unit);
8872 if Present (CS) then
8874 -- For Ident, we do not permit multiple instances
8876 if Prag_Id = Pragma_Ident then
8877 Error_Pragma ("duplicate% pragma not permitted");
8879 -- For Comment, we concatenate the string, unless we want
8880 -- to preserve the tree structure for ASIS.
8882 elsif not ASIS_Mode then
8883 Start_String (Strval (CS));
8884 Store_String_Char (' ');
8885 Store_String_Chars (Strval (Str));
8886 Set_Strval (CS, End_String);
8890 -- In VMS, the effect of IDENT is achieved by passing
8891 -- --identification=name as a --for-linker switch.
8893 if OpenVMS_On_Target then
8896 ("--for-linker=--identification=");
8897 String_To_Name_Buffer (Strval (Str));
8898 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8900 -- Only the last processed IDENT is saved. The main
8901 -- purpose is so an IDENT associated with a main
8902 -- procedure will be used in preference to an IDENT
8903 -- associated with a with'd package.
8905 Replace_Linker_Option_String
8906 (End_String, "--for-linker=--identification=");
8909 Set_Ident_String (Current_Sem_Unit, Str);
8912 -- For subunits, we just ignore the Ident, since in GNAT these
8913 -- are not separate object files, and hence not separate units
8914 -- in the unit table.
8916 elsif Nkind (GP) = N_Subunit then
8919 -- Otherwise we have a misplaced pragma Ident, but we ignore
8920 -- this if we are in an instantiation, since it comes from
8921 -- a generic, and has no relevance to the instantiation.
8923 elsif Prag_Id = Pragma_Ident then
8924 if Instantiation_Location (Loc) = No_Location then
8925 Error_Pragma ("pragma% only allowed at outer level");
8935 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8936 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8938 when Pragma_Implemented => Implemented : declare
8939 Proc_Id : Entity_Id;
8944 Check_Arg_Count (2);
8945 Check_No_Identifiers;
8946 Check_Arg_Is_Identifier (Arg1);
8947 Check_Arg_Is_Local_Name (Arg1);
8949 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8951 -- Extract the name of the local procedure
8953 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8955 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8956 -- primitive procedure of a synchronized tagged type.
8958 if Ekind (Proc_Id) = E_Procedure
8959 and then Is_Primitive (Proc_Id)
8960 and then Present (First_Formal (Proc_Id))
8962 Typ := Etype (First_Formal (Proc_Id));
8964 if Is_Tagged_Type (Typ)
8967 -- Check for a protected, a synchronized or a task interface
8969 ((Is_Interface (Typ)
8970 and then Is_Synchronized_Interface (Typ))
8972 -- Check for a protected type or a task type that implements
8976 (Is_Concurrent_Record_Type (Typ)
8977 and then Present (Interfaces (Typ)))
8979 -- Check for a private record extension with keyword
8983 (Ekind_In (Typ, E_Record_Type_With_Private,
8984 E_Record_Subtype_With_Private)
8985 and then Synchronized_Present (Parent (Typ))))
8990 ("controlling formal must be of synchronized " &
8991 "tagged type", Arg1);
8995 -- Procedures declared inside a protected type must be accepted
8997 elsif Ekind (Proc_Id) = E_Procedure
8998 and then Is_Protected_Type (Scope (Proc_Id))
9002 -- The first argument is not a primitive procedure
9006 ("pragma % must be applied to a primitive procedure", Arg1);
9010 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9011 -- By_Protected_Procedure to the primitive procedure of a task
9014 if Chars (Arg2) = Name_By_Protected_Procedure
9015 and then Is_Interface (Typ)
9016 and then Is_Task_Interface (Typ)
9019 ("implementation kind By_Protected_Procedure cannot be " &
9020 "applied to a task interface primitive", Arg2);
9024 Record_Rep_Item (Proc_Id, N);
9027 ----------------------
9028 -- Implicit_Packing --
9029 ----------------------
9031 -- pragma Implicit_Packing;
9033 when Pragma_Implicit_Packing =>
9035 Check_Arg_Count (0);
9036 Implicit_Packing := True;
9043 -- [Convention =>] convention_IDENTIFIER,
9044 -- [Entity =>] local_NAME
9045 -- [, [External_Name =>] static_string_EXPRESSION ]
9046 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9048 when Pragma_Import =>
9049 Check_Ada_83_Warning;
9055 Check_At_Least_N_Arguments (2);
9056 Check_At_Most_N_Arguments (4);
9057 Process_Import_Or_Interface;
9059 ----------------------
9060 -- Import_Exception --
9061 ----------------------
9063 -- pragma Import_Exception (
9064 -- [Internal =>] LOCAL_NAME
9065 -- [, [External =>] EXTERNAL_SYMBOL]
9066 -- [, [Form =>] Ada | VMS]
9067 -- [, [Code =>] static_integer_EXPRESSION]);
9069 when Pragma_Import_Exception => Import_Exception : declare
9070 Args : Args_List (1 .. 4);
9071 Names : constant Name_List (1 .. 4) := (
9077 Internal : Node_Id renames Args (1);
9078 External : Node_Id renames Args (2);
9079 Form : Node_Id renames Args (3);
9080 Code : Node_Id renames Args (4);
9084 Gather_Associations (Names, Args);
9086 if Present (External) and then Present (Code) then
9088 ("cannot give both External and Code options for pragma%");
9091 Process_Extended_Import_Export_Exception_Pragma (
9092 Arg_Internal => Internal,
9093 Arg_External => External,
9097 if not Is_VMS_Exception (Entity (Internal)) then
9098 Set_Imported (Entity (Internal));
9100 end Import_Exception;
9102 ---------------------
9103 -- Import_Function --
9104 ---------------------
9106 -- pragma Import_Function (
9107 -- [Internal =>] LOCAL_NAME,
9108 -- [, [External =>] EXTERNAL_SYMBOL]
9109 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9110 -- [, [Result_Type =>] SUBTYPE_MARK]
9111 -- [, [Mechanism =>] MECHANISM]
9112 -- [, [Result_Mechanism =>] MECHANISM_NAME]
9113 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9115 -- EXTERNAL_SYMBOL ::=
9117 -- | static_string_EXPRESSION
9119 -- PARAMETER_TYPES ::=
9121 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9123 -- TYPE_DESIGNATOR ::=
9125 -- | subtype_Name ' Access
9129 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9131 -- MECHANISM_ASSOCIATION ::=
9132 -- [formal_parameter_NAME =>] MECHANISM_NAME
9134 -- MECHANISM_NAME ::=
9137 -- | Descriptor [([Class =>] CLASS_NAME)]
9139 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9141 when Pragma_Import_Function => Import_Function : declare
9142 Args : Args_List (1 .. 7);
9143 Names : constant Name_List (1 .. 7) := (
9146 Name_Parameter_Types,
9149 Name_Result_Mechanism,
9150 Name_First_Optional_Parameter);
9152 Internal : Node_Id renames Args (1);
9153 External : Node_Id renames Args (2);
9154 Parameter_Types : Node_Id renames Args (3);
9155 Result_Type : Node_Id renames Args (4);
9156 Mechanism : Node_Id renames Args (5);
9157 Result_Mechanism : Node_Id renames Args (6);
9158 First_Optional_Parameter : Node_Id renames Args (7);
9162 Gather_Associations (Names, Args);
9163 Process_Extended_Import_Export_Subprogram_Pragma (
9164 Arg_Internal => Internal,
9165 Arg_External => External,
9166 Arg_Parameter_Types => Parameter_Types,
9167 Arg_Result_Type => Result_Type,
9168 Arg_Mechanism => Mechanism,
9169 Arg_Result_Mechanism => Result_Mechanism,
9170 Arg_First_Optional_Parameter => First_Optional_Parameter);
9171 end Import_Function;
9177 -- pragma Import_Object (
9178 -- [Internal =>] LOCAL_NAME
9179 -- [, [External =>] EXTERNAL_SYMBOL]
9180 -- [, [Size =>] EXTERNAL_SYMBOL]);
9182 -- EXTERNAL_SYMBOL ::=
9184 -- | static_string_EXPRESSION
9186 when Pragma_Import_Object => Import_Object : declare
9187 Args : Args_List (1 .. 3);
9188 Names : constant Name_List (1 .. 3) := (
9193 Internal : Node_Id renames Args (1);
9194 External : Node_Id renames Args (2);
9195 Size : Node_Id renames Args (3);
9199 Gather_Associations (Names, Args);
9200 Process_Extended_Import_Export_Object_Pragma (
9201 Arg_Internal => Internal,
9202 Arg_External => External,
9206 ----------------------
9207 -- Import_Procedure --
9208 ----------------------
9210 -- pragma Import_Procedure (
9211 -- [Internal =>] LOCAL_NAME
9212 -- [, [External =>] EXTERNAL_SYMBOL]
9213 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9214 -- [, [Mechanism =>] MECHANISM]
9215 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9217 -- EXTERNAL_SYMBOL ::=
9219 -- | static_string_EXPRESSION
9221 -- PARAMETER_TYPES ::=
9223 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9225 -- TYPE_DESIGNATOR ::=
9227 -- | subtype_Name ' Access
9231 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9233 -- MECHANISM_ASSOCIATION ::=
9234 -- [formal_parameter_NAME =>] MECHANISM_NAME
9236 -- MECHANISM_NAME ::=
9239 -- | Descriptor [([Class =>] CLASS_NAME)]
9241 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9243 when Pragma_Import_Procedure => Import_Procedure : declare
9244 Args : Args_List (1 .. 5);
9245 Names : constant Name_List (1 .. 5) := (
9248 Name_Parameter_Types,
9250 Name_First_Optional_Parameter);
9252 Internal : Node_Id renames Args (1);
9253 External : Node_Id renames Args (2);
9254 Parameter_Types : Node_Id renames Args (3);
9255 Mechanism : Node_Id renames Args (4);
9256 First_Optional_Parameter : Node_Id renames Args (5);
9260 Gather_Associations (Names, Args);
9261 Process_Extended_Import_Export_Subprogram_Pragma (
9262 Arg_Internal => Internal,
9263 Arg_External => External,
9264 Arg_Parameter_Types => Parameter_Types,
9265 Arg_Mechanism => Mechanism,
9266 Arg_First_Optional_Parameter => First_Optional_Parameter);
9267 end Import_Procedure;
9269 -----------------------------
9270 -- Import_Valued_Procedure --
9271 -----------------------------
9273 -- pragma Import_Valued_Procedure (
9274 -- [Internal =>] LOCAL_NAME
9275 -- [, [External =>] EXTERNAL_SYMBOL]
9276 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9277 -- [, [Mechanism =>] MECHANISM]
9278 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9280 -- EXTERNAL_SYMBOL ::=
9282 -- | static_string_EXPRESSION
9284 -- PARAMETER_TYPES ::=
9286 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9288 -- TYPE_DESIGNATOR ::=
9290 -- | subtype_Name ' Access
9294 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9296 -- MECHANISM_ASSOCIATION ::=
9297 -- [formal_parameter_NAME =>] MECHANISM_NAME
9299 -- MECHANISM_NAME ::=
9302 -- | Descriptor [([Class =>] CLASS_NAME)]
9304 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9306 when Pragma_Import_Valued_Procedure =>
9307 Import_Valued_Procedure : declare
9308 Args : Args_List (1 .. 5);
9309 Names : constant Name_List (1 .. 5) := (
9312 Name_Parameter_Types,
9314 Name_First_Optional_Parameter);
9316 Internal : Node_Id renames Args (1);
9317 External : Node_Id renames Args (2);
9318 Parameter_Types : Node_Id renames Args (3);
9319 Mechanism : Node_Id renames Args (4);
9320 First_Optional_Parameter : Node_Id renames Args (5);
9324 Gather_Associations (Names, Args);
9325 Process_Extended_Import_Export_Subprogram_Pragma (
9326 Arg_Internal => Internal,
9327 Arg_External => External,
9328 Arg_Parameter_Types => Parameter_Types,
9329 Arg_Mechanism => Mechanism,
9330 Arg_First_Optional_Parameter => First_Optional_Parameter);
9331 end Import_Valued_Procedure;
9337 -- pragma Independent (LOCAL_NAME);
9339 when Pragma_Independent => Independent : declare
9346 Check_Ada_83_Warning;
9348 Check_No_Identifiers;
9349 Check_Arg_Count (1);
9350 Check_Arg_Is_Local_Name (Arg1);
9351 E_Id := Get_Pragma_Arg (Arg1);
9353 if Etype (E_Id) = Any_Type then
9358 D := Declaration_Node (E);
9361 -- Check duplicate before we chain ourselves!
9363 Check_Duplicate_Pragma (E);
9365 -- Check appropriate entity
9368 if Rep_Item_Too_Early (E, N)
9370 Rep_Item_Too_Late (E, N)
9374 Check_First_Subtype (Arg1);
9377 elsif K = N_Object_Declaration
9378 or else (K = N_Component_Declaration
9379 and then Original_Record_Component (E) = E)
9381 if Rep_Item_Too_Late (E, N) then
9387 ("inappropriate entity for pragma%", Arg1);
9390 Independence_Checks.Append ((N, E));
9393 ----------------------------
9394 -- Independent_Components --
9395 ----------------------------
9397 -- pragma Atomic_Components (array_LOCAL_NAME);
9399 -- This processing is shared by Volatile_Components
9401 when Pragma_Independent_Components => Independent_Components : declare
9408 Check_Ada_83_Warning;
9410 Check_No_Identifiers;
9411 Check_Arg_Count (1);
9412 Check_Arg_Is_Local_Name (Arg1);
9413 E_Id := Get_Pragma_Arg (Arg1);
9415 if Etype (E_Id) = Any_Type then
9421 -- Check duplicate before we chain ourselves!
9423 Check_Duplicate_Pragma (E);
9425 -- Check appropriate entity
9427 if Rep_Item_Too_Early (E, N)
9429 Rep_Item_Too_Late (E, N)
9434 D := Declaration_Node (E);
9437 if (K = N_Full_Type_Declaration
9438 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9440 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9441 and then Nkind (D) = N_Object_Declaration
9442 and then Nkind (Object_Definition (D)) =
9443 N_Constrained_Array_Definition)
9445 Independence_Checks.Append ((N, E));
9448 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9450 end Independent_Components;
9452 ------------------------
9453 -- Initialize_Scalars --
9454 ------------------------
9456 -- pragma Initialize_Scalars;
9458 when Pragma_Initialize_Scalars =>
9460 Check_Arg_Count (0);
9461 Check_Valid_Configuration_Pragma;
9462 Check_Restriction (No_Initialize_Scalars, N);
9464 -- Initialize_Scalars creates false positives in CodePeer,
9465 -- so ignore this pragma in this mode.
9467 if not Restriction_Active (No_Initialize_Scalars)
9468 and then not CodePeer_Mode
9470 Init_Or_Norm_Scalars := True;
9471 Initialize_Scalars := True;
9478 -- pragma Inline ( NAME {, NAME} );
9480 when Pragma_Inline =>
9482 -- Pragma is active if inlining option is active
9484 Process_Inline (Inline_Active);
9490 -- pragma Inline_Always ( NAME {, NAME} );
9492 when Pragma_Inline_Always =>
9495 -- Pragma always active unless in CodePeer mode, since this causes
9496 -- walk order issues.
9498 if not CodePeer_Mode then
9499 Process_Inline (True);
9502 --------------------
9503 -- Inline_Generic --
9504 --------------------
9506 -- pragma Inline_Generic (NAME {, NAME});
9508 when Pragma_Inline_Generic =>
9510 Process_Generic_List;
9512 ----------------------
9513 -- Inspection_Point --
9514 ----------------------
9516 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9518 when Pragma_Inspection_Point => Inspection_Point : declare
9523 if Arg_Count > 0 then
9526 Exp := Get_Pragma_Arg (Arg);
9529 if not Is_Entity_Name (Exp)
9530 or else not Is_Object (Entity (Exp))
9532 Error_Pragma_Arg ("object name required", Arg);
9539 end Inspection_Point;
9545 -- pragma Interface (
9546 -- [ Convention =>] convention_IDENTIFIER,
9547 -- [ Entity =>] local_NAME
9548 -- [, [External_Name =>] static_string_EXPRESSION ]
9549 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9551 when Pragma_Interface =>
9558 Check_At_Least_N_Arguments (2);
9559 Check_At_Most_N_Arguments (4);
9560 Process_Import_Or_Interface;
9562 -- In Ada 2005, the permission to use Interface (a reserved word)
9563 -- as a pragma name is considered an obsolescent feature.
9565 if Ada_Version >= Ada_2005 then
9567 (No_Obsolescent_Features, Pragma_Identifier (N));
9570 --------------------
9571 -- Interface_Name --
9572 --------------------
9574 -- pragma Interface_Name (
9575 -- [ Entity =>] local_NAME
9576 -- [,[External_Name =>] static_string_EXPRESSION ]
9577 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9579 when Pragma_Interface_Name => Interface_Name : declare
9588 ((Name_Entity, Name_External_Name, Name_Link_Name));
9589 Check_At_Least_N_Arguments (2);
9590 Check_At_Most_N_Arguments (3);
9591 Id := Get_Pragma_Arg (Arg1);
9594 if not Is_Entity_Name (Id) then
9596 ("first argument for pragma% must be entity name", Arg1);
9597 elsif Etype (Id) = Any_Type then
9600 Def_Id := Entity (Id);
9603 -- Special DEC-compatible processing for the object case, forces
9604 -- object to be imported.
9606 if Ekind (Def_Id) = E_Variable then
9607 Kill_Size_Check_Code (Def_Id);
9608 Note_Possible_Modification (Id, Sure => False);
9610 -- Initialization is not allowed for imported variable
9612 if Present (Expression (Parent (Def_Id)))
9613 and then Comes_From_Source (Expression (Parent (Def_Id)))
9615 Error_Msg_Sloc := Sloc (Def_Id);
9617 ("no initialization allowed for declaration of& #",
9621 -- For compatibility, support VADS usage of providing both
9622 -- pragmas Interface and Interface_Name to obtain the effect
9623 -- of a single Import pragma.
9625 if Is_Imported (Def_Id)
9626 and then Present (First_Rep_Item (Def_Id))
9627 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9629 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9633 Set_Imported (Def_Id);
9636 Set_Is_Public (Def_Id);
9637 Process_Interface_Name (Def_Id, Arg2, Arg3);
9640 -- Otherwise must be subprogram
9642 elsif not Is_Subprogram (Def_Id) then
9644 ("argument of pragma% is not subprogram", Arg1);
9647 Check_At_Most_N_Arguments (3);
9651 -- Loop through homonyms
9654 Def_Id := Get_Base_Subprogram (Hom_Id);
9656 if Is_Imported (Def_Id) then
9657 Process_Interface_Name (Def_Id, Arg2, Arg3);
9661 exit when From_Aspect_Specification (N);
9662 Hom_Id := Homonym (Hom_Id);
9664 exit when No (Hom_Id)
9665 or else Scope (Hom_Id) /= Current_Scope;
9670 ("argument of pragma% is not imported subprogram",
9676 -----------------------
9677 -- Interrupt_Handler --
9678 -----------------------
9680 -- pragma Interrupt_Handler (handler_NAME);
9682 when Pragma_Interrupt_Handler =>
9683 Check_Ada_83_Warning;
9684 Check_Arg_Count (1);
9685 Check_No_Identifiers;
9687 if No_Run_Time_Mode then
9688 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9690 Check_Interrupt_Or_Attach_Handler;
9691 Process_Interrupt_Or_Attach_Handler;
9694 ------------------------
9695 -- Interrupt_Priority --
9696 ------------------------
9698 -- pragma Interrupt_Priority [(EXPRESSION)];
9700 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9701 P : constant Node_Id := Parent (N);
9705 Check_Ada_83_Warning;
9707 if Arg_Count /= 0 then
9708 Arg := Get_Pragma_Arg (Arg1);
9709 Check_Arg_Count (1);
9710 Check_No_Identifiers;
9712 -- The expression must be analyzed in the special manner
9713 -- described in "Handling of Default and Per-Object
9714 -- Expressions" in sem.ads.
9716 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9719 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9723 elsif Has_Pragma_Priority (P) then
9724 Error_Pragma ("duplicate pragma% not allowed");
9727 Set_Has_Pragma_Priority (P, True);
9728 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9730 end Interrupt_Priority;
9732 ---------------------
9733 -- Interrupt_State --
9734 ---------------------
9736 -- pragma Interrupt_State (
9737 -- [Name =>] INTERRUPT_ID,
9738 -- [State =>] INTERRUPT_STATE);
9740 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9741 -- INTERRUPT_STATE => System | Runtime | User
9743 -- Note: if the interrupt id is given as an identifier, then it must
9744 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9745 -- given as a static integer expression which must be in the range of
9746 -- Ada.Interrupts.Interrupt_ID.
9748 when Pragma_Interrupt_State => Interrupt_State : declare
9750 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9751 -- This is the entity Ada.Interrupts.Interrupt_ID;
9753 State_Type : Character;
9754 -- Set to 's'/'r'/'u' for System/Runtime/User
9757 -- Index to entry in Interrupt_States table
9760 -- Value of interrupt
9762 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9763 -- The first argument to the pragma
9765 Int_Ent : Entity_Id;
9766 -- Interrupt entity in Ada.Interrupts.Names
9770 Check_Arg_Order ((Name_Name, Name_State));
9771 Check_Arg_Count (2);
9773 Check_Optional_Identifier (Arg1, Name_Name);
9774 Check_Optional_Identifier (Arg2, Name_State);
9775 Check_Arg_Is_Identifier (Arg2);
9777 -- First argument is identifier
9779 if Nkind (Arg1X) = N_Identifier then
9781 -- Search list of names in Ada.Interrupts.Names
9783 Int_Ent := First_Entity (RTE (RE_Names));
9785 if No (Int_Ent) then
9786 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9788 elsif Chars (Int_Ent) = Chars (Arg1X) then
9789 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9793 Next_Entity (Int_Ent);
9796 -- First argument is not an identifier, so it must be a static
9797 -- expression of type Ada.Interrupts.Interrupt_ID.
9800 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9801 Int_Val := Expr_Value (Arg1X);
9803 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9805 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9808 ("value not in range of type " &
9809 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9815 case Chars (Get_Pragma_Arg (Arg2)) is
9816 when Name_Runtime => State_Type := 'r';
9817 when Name_System => State_Type := 's';
9818 when Name_User => State_Type := 'u';
9821 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9824 -- Check if entry is already stored
9826 IST_Num := Interrupt_States.First;
9828 -- If entry not found, add it
9830 if IST_Num > Interrupt_States.Last then
9831 Interrupt_States.Append
9832 ((Interrupt_Number => UI_To_Int (Int_Val),
9833 Interrupt_State => State_Type,
9834 Pragma_Loc => Loc));
9837 -- Case of entry for the same entry
9839 elsif Int_Val = Interrupt_States.Table (IST_Num).
9842 -- If state matches, done, no need to make redundant entry
9845 State_Type = Interrupt_States.Table (IST_Num).
9848 -- Otherwise if state does not match, error
9851 Interrupt_States.Table (IST_Num).Pragma_Loc;
9853 ("state conflicts with that given #", Arg2);
9857 IST_Num := IST_Num + 1;
9859 end Interrupt_State;
9866 -- ([Entity =>] type_LOCAL_NAME,
9867 -- [Check =>] EXPRESSION
9868 -- [,[Message =>] String_Expression]);
9870 when Pragma_Invariant => Invariant : declare
9875 pragma Unreferenced (Discard);
9879 Check_At_Least_N_Arguments (2);
9880 Check_At_Most_N_Arguments (3);
9881 Check_Optional_Identifier (Arg1, Name_Entity);
9882 Check_Optional_Identifier (Arg2, Name_Check);
9884 if Arg_Count = 3 then
9885 Check_Optional_Identifier (Arg3, Name_Message);
9886 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9889 Check_Arg_Is_Local_Name (Arg1);
9891 Type_Id := Get_Pragma_Arg (Arg1);
9892 Find_Type (Type_Id);
9893 Typ := Entity (Type_Id);
9895 if Typ = Any_Type then
9898 elsif not Ekind_In (Typ, E_Private_Type,
9899 E_Record_Type_With_Private,
9900 E_Limited_Private_Type)
9903 ("pragma% only allowed for private type", Arg1);
9906 -- Note that the type has at least one invariant, and also that
9907 -- it has inheritable invariants if we have Invariant'Class.
9909 Set_Has_Invariants (Typ);
9911 if Class_Present (N) then
9912 Set_Has_Inheritable_Invariants (Typ);
9915 -- The remaining processing is simply to link the pragma on to
9916 -- the rep item chain, for processing when the type is frozen.
9917 -- This is accomplished by a call to Rep_Item_Too_Late.
9919 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9922 ----------------------
9923 -- Java_Constructor --
9924 ----------------------
9926 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9928 -- Also handles pragma CIL_Constructor
9930 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9931 Java_Constructor : declare
9932 Convention : Convention_Id;
9936 This_Formal : Entity_Id;
9940 Check_Arg_Count (1);
9941 Check_Optional_Identifier (Arg1, Name_Entity);
9942 Check_Arg_Is_Local_Name (Arg1);
9944 Id := Get_Pragma_Arg (Arg1);
9945 Find_Program_Unit_Name (Id);
9947 -- If we did not find the name, we are done
9949 if Etype (Id) = Any_Type then
9953 -- Check wrong use of pragma in wrong VM target
9955 if VM_Target = No_VM then
9958 elsif VM_Target = CLI_Target
9959 and then Prag_Id = Pragma_Java_Constructor
9961 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9963 elsif VM_Target = JVM_Target
9964 and then Prag_Id = Pragma_CIL_Constructor
9966 Error_Pragma ("must use pragma 'Java_'Constructor");
9970 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9971 when Pragma_Java_Constructor => Convention := Convention_Java;
9972 when others => null;
9975 Hom_Id := Entity (Id);
9977 -- Loop through homonyms
9980 Def_Id := Get_Base_Subprogram (Hom_Id);
9982 -- The constructor is required to be a function
9984 if Ekind (Def_Id) /= E_Function then
9985 if VM_Target = JVM_Target then
9987 ("pragma% requires function returning a " &
9988 "'Java access type", Def_Id);
9991 ("pragma% requires function returning a " &
9992 "'C'I'L access type", Def_Id);
9996 -- Check arguments: For tagged type the first formal must be
9997 -- named "this" and its type must be a named access type
9998 -- designating a class-wide tagged type that has convention
9999 -- CIL/Java. The first formal must also have a null default
10000 -- value. For example:
10002 -- type Typ is tagged ...
10003 -- type Ref is access all Typ;
10004 -- pragma Convention (CIL, Typ);
10006 -- function New_Typ (This : Ref) return Ref;
10007 -- function New_Typ (This : Ref; I : Integer) return Ref;
10008 -- pragma Cil_Constructor (New_Typ);
10010 -- Reason: The first formal must NOT be a primitive of the
10013 -- This rule also applies to constructors of delegates used
10014 -- to interface with standard target libraries. For example:
10016 -- type Delegate is access procedure ...
10017 -- pragma Import (CIL, Delegate, ...);
10019 -- function new_Delegate
10020 -- (This : Delegate := null; ... ) return Delegate;
10022 -- For value-types this rule does not apply.
10024 if not Is_Value_Type (Etype (Def_Id)) then
10025 if No (First_Formal (Def_Id)) then
10026 Error_Msg_Name_1 := Pname;
10027 Error_Msg_N ("% function must have parameters", Def_Id);
10031 -- In the JRE library we have several occurrences in which
10032 -- the "this" parameter is not the first formal.
10034 This_Formal := First_Formal (Def_Id);
10036 -- In the JRE library we have several occurrences in which
10037 -- the "this" parameter is not the first formal. Search for
10040 if VM_Target = JVM_Target then
10041 while Present (This_Formal)
10042 and then Get_Name_String (Chars (This_Formal)) /= "this"
10044 Next_Formal (This_Formal);
10047 if No (This_Formal) then
10048 This_Formal := First_Formal (Def_Id);
10052 -- Warning: The first parameter should be named "this".
10053 -- We temporarily allow it because we have the following
10054 -- case in the Java runtime (file s-osinte.ads) ???
10056 -- function new_Thread
10057 -- (Self_Id : System.Address) return Thread_Id;
10058 -- pragma Java_Constructor (new_Thread);
10060 if VM_Target = JVM_Target
10061 and then Get_Name_String (Chars (First_Formal (Def_Id)))
10063 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10067 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10068 Error_Msg_Name_1 := Pname;
10070 ("first formal of % function must be named `this`",
10071 Parent (This_Formal));
10073 elsif not Is_Access_Type (Etype (This_Formal)) then
10074 Error_Msg_Name_1 := Pname;
10076 ("first formal of % function must be an access type",
10077 Parameter_Type (Parent (This_Formal)));
10079 -- For delegates the type of the first formal must be a
10080 -- named access-to-subprogram type (see previous example)
10082 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10083 and then Ekind (Etype (This_Formal))
10084 /= E_Access_Subprogram_Type
10086 Error_Msg_Name_1 := Pname;
10088 ("first formal of % function must be a named access" &
10089 " to subprogram type",
10090 Parameter_Type (Parent (This_Formal)));
10092 -- Warning: We should reject anonymous access types because
10093 -- the constructor must not be handled as a primitive of the
10094 -- tagged type. We temporarily allow it because this profile
10095 -- is currently generated by cil2ada???
10097 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10098 and then not Ekind_In (Etype (This_Formal),
10100 E_General_Access_Type,
10101 E_Anonymous_Access_Type)
10103 Error_Msg_Name_1 := Pname;
10105 ("first formal of % function must be a named access" &
10107 Parameter_Type (Parent (This_Formal)));
10109 elsif Atree.Convention
10110 (Designated_Type (Etype (This_Formal))) /= Convention
10112 Error_Msg_Name_1 := Pname;
10114 if Convention = Convention_Java then
10116 ("pragma% requires convention 'Cil in designated" &
10118 Parameter_Type (Parent (This_Formal)));
10121 ("pragma% requires convention 'Java in designated" &
10123 Parameter_Type (Parent (This_Formal)));
10126 elsif No (Expression (Parent (This_Formal)))
10127 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10129 Error_Msg_Name_1 := Pname;
10131 ("pragma% requires first formal with default `null`",
10132 Parameter_Type (Parent (This_Formal)));
10136 -- Check result type: the constructor must be a function
10138 -- * a value type (only allowed in the CIL compiler)
10139 -- * an access-to-subprogram type with convention Java/CIL
10140 -- * an access-type designating a type that has convention
10143 if Is_Value_Type (Etype (Def_Id)) then
10146 -- Access-to-subprogram type with convention Java/CIL
10148 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10149 if Atree.Convention (Etype (Def_Id)) /= Convention then
10150 if Convention = Convention_Java then
10152 ("pragma% requires function returning a " &
10153 "'Java access type", Arg1);
10155 pragma Assert (Convention = Convention_CIL);
10157 ("pragma% requires function returning a " &
10158 "'C'I'L access type", Arg1);
10162 elsif Ekind (Etype (Def_Id)) in Access_Kind then
10163 if not Ekind_In (Etype (Def_Id), E_Access_Type,
10164 E_General_Access_Type)
10167 (Designated_Type (Etype (Def_Id))) /= Convention
10169 Error_Msg_Name_1 := Pname;
10171 if Convention = Convention_Java then
10173 ("pragma% requires function returning a named" &
10174 "'Java access type", Arg1);
10177 ("pragma% requires function returning a named" &
10178 "'C'I'L access type", Arg1);
10183 Set_Is_Constructor (Def_Id);
10184 Set_Convention (Def_Id, Convention);
10185 Set_Is_Imported (Def_Id);
10187 exit when From_Aspect_Specification (N);
10188 Hom_Id := Homonym (Hom_Id);
10190 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10192 end Java_Constructor;
10194 ----------------------
10195 -- Java_Interface --
10196 ----------------------
10198 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
10200 when Pragma_Java_Interface => Java_Interface : declare
10206 Check_Arg_Count (1);
10207 Check_Optional_Identifier (Arg1, Name_Entity);
10208 Check_Arg_Is_Local_Name (Arg1);
10210 Arg := Get_Pragma_Arg (Arg1);
10213 if Etype (Arg) = Any_Type then
10217 if not Is_Entity_Name (Arg)
10218 or else not Is_Type (Entity (Arg))
10220 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10223 Typ := Underlying_Type (Entity (Arg));
10225 -- For now simply check some of the semantic constraints on the
10226 -- type. This currently leaves out some restrictions on interface
10227 -- types, namely that the parent type must be java.lang.Object.Typ
10228 -- and that all primitives of the type should be declared
10231 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10232 Error_Pragma_Arg ("pragma% requires an abstract "
10233 & "tagged type", Arg1);
10235 elsif not Has_Discriminants (Typ)
10236 or else Ekind (Etype (First_Discriminant (Typ)))
10237 /= E_Anonymous_Access_Type
10239 not Is_Class_Wide_Type
10240 (Designated_Type (Etype (First_Discriminant (Typ))))
10243 ("type must have a class-wide access discriminant", Arg1);
10245 end Java_Interface;
10251 -- pragma Keep_Names ([On => ] local_NAME);
10253 when Pragma_Keep_Names => Keep_Names : declare
10258 Check_Arg_Count (1);
10259 Check_Optional_Identifier (Arg1, Name_On);
10260 Check_Arg_Is_Local_Name (Arg1);
10262 Arg := Get_Pragma_Arg (Arg1);
10265 if Etype (Arg) = Any_Type then
10269 if not Is_Entity_Name (Arg)
10270 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10273 ("pragma% requires a local enumeration type", Arg1);
10276 Set_Discard_Names (Entity (Arg), False);
10283 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10285 when Pragma_License =>
10287 Check_Arg_Count (1);
10288 Check_No_Identifiers;
10289 Check_Valid_Configuration_Pragma;
10290 Check_Arg_Is_Identifier (Arg1);
10293 Sind : constant Source_File_Index :=
10294 Source_Index (Current_Sem_Unit);
10297 case Chars (Get_Pragma_Arg (Arg1)) is
10299 Set_License (Sind, GPL);
10301 when Name_Modified_GPL =>
10302 Set_License (Sind, Modified_GPL);
10304 when Name_Restricted =>
10305 Set_License (Sind, Restricted);
10307 when Name_Unrestricted =>
10308 Set_License (Sind, Unrestricted);
10311 Error_Pragma_Arg ("invalid license name", Arg1);
10319 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10321 when Pragma_Link_With => Link_With : declare
10327 if Operating_Mode = Generate_Code
10328 and then In_Extended_Main_Source_Unit (N)
10330 Check_At_Least_N_Arguments (1);
10331 Check_No_Identifiers;
10332 Check_Is_In_Decl_Part_Or_Package_Spec;
10333 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10337 while Present (Arg) loop
10338 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10340 -- Store argument, converting sequences of spaces to a
10341 -- single null character (this is one of the differences
10342 -- in processing between Link_With and Linker_Options).
10344 Arg_Store : declare
10345 C : constant Char_Code := Get_Char_Code (' ');
10346 S : constant String_Id :=
10347 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10348 L : constant Nat := String_Length (S);
10351 procedure Skip_Spaces;
10352 -- Advance F past any spaces
10358 procedure Skip_Spaces is
10360 while F <= L and then Get_String_Char (S, F) = C loop
10365 -- Start of processing for Arg_Store
10368 Skip_Spaces; -- skip leading spaces
10370 -- Loop through characters, changing any embedded
10371 -- sequence of spaces to a single null character (this
10372 -- is how Link_With/Linker_Options differ)
10375 if Get_String_Char (S, F) = C then
10378 Store_String_Char (ASCII.NUL);
10381 Store_String_Char (Get_String_Char (S, F));
10389 if Present (Arg) then
10390 Store_String_Char (ASCII.NUL);
10394 Store_Linker_Option_String (End_String);
10402 -- pragma Linker_Alias (
10403 -- [Entity =>] LOCAL_NAME
10404 -- [Target =>] static_string_EXPRESSION);
10406 when Pragma_Linker_Alias =>
10408 Check_Arg_Order ((Name_Entity, Name_Target));
10409 Check_Arg_Count (2);
10410 Check_Optional_Identifier (Arg1, Name_Entity);
10411 Check_Optional_Identifier (Arg2, Name_Target);
10412 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10413 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10415 -- The only processing required is to link this item on to the
10416 -- list of rep items for the given entity. This is accomplished
10417 -- by the call to Rep_Item_Too_Late (when no error is detected
10418 -- and False is returned).
10420 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10423 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10426 ------------------------
10427 -- Linker_Constructor --
10428 ------------------------
10430 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10432 -- Code is shared with Linker_Destructor
10434 -----------------------
10435 -- Linker_Destructor --
10436 -----------------------
10438 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10440 when Pragma_Linker_Constructor |
10441 Pragma_Linker_Destructor =>
10442 Linker_Constructor : declare
10448 Check_Arg_Count (1);
10449 Check_No_Identifiers;
10450 Check_Arg_Is_Local_Name (Arg1);
10451 Arg1_X := Get_Pragma_Arg (Arg1);
10453 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10455 if not Is_Library_Level_Entity (Proc) then
10457 ("argument for pragma% must be library level entity", Arg1);
10460 -- The only processing required is to link this item on to the
10461 -- list of rep items for the given entity. This is accomplished
10462 -- by the call to Rep_Item_Too_Late (when no error is detected
10463 -- and False is returned).
10465 if Rep_Item_Too_Late (Proc, N) then
10468 Set_Has_Gigi_Rep_Item (Proc);
10470 end Linker_Constructor;
10472 --------------------
10473 -- Linker_Options --
10474 --------------------
10476 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10478 when Pragma_Linker_Options => Linker_Options : declare
10482 Check_Ada_83_Warning;
10483 Check_No_Identifiers;
10484 Check_Arg_Count (1);
10485 Check_Is_In_Decl_Part_Or_Package_Spec;
10486 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10487 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10490 while Present (Arg) loop
10491 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10492 Store_String_Char (ASCII.NUL);
10494 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10498 if Operating_Mode = Generate_Code
10499 and then In_Extended_Main_Source_Unit (N)
10501 Store_Linker_Option_String (End_String);
10503 end Linker_Options;
10505 --------------------
10506 -- Linker_Section --
10507 --------------------
10509 -- pragma Linker_Section (
10510 -- [Entity =>] LOCAL_NAME
10511 -- [Section =>] static_string_EXPRESSION);
10513 when Pragma_Linker_Section =>
10515 Check_Arg_Order ((Name_Entity, Name_Section));
10516 Check_Arg_Count (2);
10517 Check_Optional_Identifier (Arg1, Name_Entity);
10518 Check_Optional_Identifier (Arg2, Name_Section);
10519 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10520 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10522 -- This pragma applies only to objects
10524 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10525 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10528 -- The only processing required is to link this item on to the
10529 -- list of rep items for the given entity. This is accomplished
10530 -- by the call to Rep_Item_Too_Late (when no error is detected
10531 -- and False is returned).
10533 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10536 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10543 -- pragma List (On | Off)
10545 -- There is nothing to do here, since we did all the processing for
10546 -- this pragma in Par.Prag (so that it works properly even in syntax
10549 when Pragma_List =>
10552 --------------------
10553 -- Locking_Policy --
10554 --------------------
10556 -- pragma Locking_Policy (policy_IDENTIFIER);
10558 when Pragma_Locking_Policy => declare
10562 Check_Ada_83_Warning;
10563 Check_Arg_Count (1);
10564 Check_No_Identifiers;
10565 Check_Arg_Is_Locking_Policy (Arg1);
10566 Check_Valid_Configuration_Pragma;
10567 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10568 LP := Fold_Upper (Name_Buffer (1));
10570 if Locking_Policy /= ' '
10571 and then Locking_Policy /= LP
10573 Error_Msg_Sloc := Locking_Policy_Sloc;
10574 Error_Pragma ("locking policy incompatible with policy#");
10576 -- Set new policy, but always preserve System_Location since we
10577 -- like the error message with the run time name.
10580 Locking_Policy := LP;
10582 if Locking_Policy_Sloc /= System_Location then
10583 Locking_Policy_Sloc := Loc;
10592 -- pragma Long_Float (D_Float | G_Float);
10594 when Pragma_Long_Float =>
10596 Check_Valid_Configuration_Pragma;
10597 Check_Arg_Count (1);
10598 Check_No_Identifier (Arg1);
10599 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10601 if not OpenVMS_On_Target then
10602 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10607 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10608 if Opt.Float_Format_Long = 'G' then
10609 Error_Pragma ("G_Float previously specified");
10612 Opt.Float_Format_Long := 'D';
10614 -- G_Float case (this is the default, does not need overriding)
10617 if Opt.Float_Format_Long = 'D' then
10618 Error_Pragma ("D_Float previously specified");
10621 Opt.Float_Format_Long := 'G';
10624 Set_Standard_Fpt_Formats;
10626 -----------------------
10627 -- Machine_Attribute --
10628 -----------------------
10630 -- pragma Machine_Attribute (
10631 -- [Entity =>] LOCAL_NAME,
10632 -- [Attribute_Name =>] static_string_EXPRESSION
10633 -- [, [Info =>] static_EXPRESSION] );
10635 when Pragma_Machine_Attribute => Machine_Attribute : declare
10636 Def_Id : Entity_Id;
10640 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10642 if Arg_Count = 3 then
10643 Check_Optional_Identifier (Arg3, Name_Info);
10644 Check_Arg_Is_Static_Expression (Arg3);
10646 Check_Arg_Count (2);
10649 Check_Optional_Identifier (Arg1, Name_Entity);
10650 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10651 Check_Arg_Is_Local_Name (Arg1);
10652 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10653 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10655 if Is_Access_Type (Def_Id) then
10656 Def_Id := Designated_Type (Def_Id);
10659 if Rep_Item_Too_Early (Def_Id, N) then
10663 Def_Id := Underlying_Type (Def_Id);
10665 -- The only processing required is to link this item on to the
10666 -- list of rep items for the given entity. This is accomplished
10667 -- by the call to Rep_Item_Too_Late (when no error is detected
10668 -- and False is returned).
10670 if Rep_Item_Too_Late (Def_Id, N) then
10673 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10675 end Machine_Attribute;
10682 -- (MAIN_OPTION [, MAIN_OPTION]);
10685 -- [STACK_SIZE =>] static_integer_EXPRESSION
10686 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10687 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10689 when Pragma_Main => Main : declare
10690 Args : Args_List (1 .. 3);
10691 Names : constant Name_List (1 .. 3) := (
10693 Name_Task_Stack_Size_Default,
10694 Name_Time_Slicing_Enabled);
10700 Gather_Associations (Names, Args);
10702 for J in 1 .. 2 loop
10703 if Present (Args (J)) then
10704 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10708 if Present (Args (3)) then
10709 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10713 while Present (Nod) loop
10714 if Nkind (Nod) = N_Pragma
10715 and then Pragma_Name (Nod) = Name_Main
10717 Error_Msg_Name_1 := Pname;
10718 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10729 -- pragma Main_Storage
10730 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10732 -- MAIN_STORAGE_OPTION ::=
10733 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10734 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10736 when Pragma_Main_Storage => Main_Storage : declare
10737 Args : Args_List (1 .. 2);
10738 Names : constant Name_List (1 .. 2) := (
10739 Name_Working_Storage,
10746 Gather_Associations (Names, Args);
10748 for J in 1 .. 2 loop
10749 if Present (Args (J)) then
10750 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10754 Check_In_Main_Program;
10757 while Present (Nod) loop
10758 if Nkind (Nod) = N_Pragma
10759 and then Pragma_Name (Nod) = Name_Main_Storage
10761 Error_Msg_Name_1 := Pname;
10762 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10773 -- pragma Memory_Size (NUMERIC_LITERAL)
10775 when Pragma_Memory_Size =>
10778 -- Memory size is simply ignored
10780 Check_No_Identifiers;
10781 Check_Arg_Count (1);
10782 Check_Arg_Is_Integer_Literal (Arg1);
10790 -- The only correct use of this pragma is on its own in a file, in
10791 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10792 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10793 -- check for a file containing nothing but a No_Body pragma). If we
10794 -- attempt to process it during normal semantics processing, it means
10795 -- it was misplaced.
10797 when Pragma_No_Body =>
10805 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10807 when Pragma_No_Return => No_Return : declare
10815 Check_At_Least_N_Arguments (1);
10817 -- Loop through arguments of pragma
10820 while Present (Arg) loop
10821 Check_Arg_Is_Local_Name (Arg);
10822 Id := Get_Pragma_Arg (Arg);
10825 if not Is_Entity_Name (Id) then
10826 Error_Pragma_Arg ("entity name required", Arg);
10829 if Etype (Id) = Any_Type then
10833 -- Loop to find matching procedures
10838 and then Scope (E) = Current_Scope
10840 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10843 -- Set flag on any alias as well
10845 if Is_Overloadable (E) and then Present (Alias (E)) then
10846 Set_No_Return (Alias (E));
10852 exit when From_Aspect_Specification (N);
10857 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10868 -- pragma No_Run_Time;
10870 -- Note: this pragma is retained for backwards compatibility. See
10871 -- body of Rtsfind for full details on its handling.
10873 when Pragma_No_Run_Time =>
10875 Check_Valid_Configuration_Pragma;
10876 Check_Arg_Count (0);
10878 No_Run_Time_Mode := True;
10879 Configurable_Run_Time_Mode := True;
10881 -- Set Duration to 32 bits if word size is 32
10883 if Ttypes.System_Word_Size = 32 then
10884 Duration_32_Bits_On_Target := True;
10887 -- Set appropriate restrictions
10889 Set_Restriction (No_Finalization, N);
10890 Set_Restriction (No_Exception_Handlers, N);
10891 Set_Restriction (Max_Tasks, N, 0);
10892 Set_Restriction (No_Tasking, N);
10894 ------------------------
10895 -- No_Strict_Aliasing --
10896 ------------------------
10898 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10900 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10905 Check_At_Most_N_Arguments (1);
10907 if Arg_Count = 0 then
10908 Check_Valid_Configuration_Pragma;
10909 Opt.No_Strict_Aliasing := True;
10912 Check_Optional_Identifier (Arg2, Name_Entity);
10913 Check_Arg_Is_Local_Name (Arg1);
10914 E_Id := Entity (Get_Pragma_Arg (Arg1));
10916 if E_Id = Any_Type then
10918 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10919 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10922 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10924 end No_Strict_Aliasing;
10926 -----------------------
10927 -- Normalize_Scalars --
10928 -----------------------
10930 -- pragma Normalize_Scalars;
10932 when Pragma_Normalize_Scalars =>
10933 Check_Ada_83_Warning;
10934 Check_Arg_Count (0);
10935 Check_Valid_Configuration_Pragma;
10937 -- Normalize_Scalars creates false positives in CodePeer, so
10938 -- ignore this pragma in this mode.
10940 if not CodePeer_Mode then
10941 Normalize_Scalars := True;
10942 Init_Or_Norm_Scalars := True;
10949 -- pragma Obsolescent;
10951 -- pragma Obsolescent (
10952 -- [Message =>] static_string_EXPRESSION
10953 -- [,[Version =>] Ada_05]]);
10955 -- pragma Obsolescent (
10956 -- [Entity =>] NAME
10957 -- [,[Message =>] static_string_EXPRESSION
10958 -- [,[Version =>] Ada_05]] );
10960 when Pragma_Obsolescent => Obsolescent : declare
10964 procedure Set_Obsolescent (E : Entity_Id);
10965 -- Given an entity Ent, mark it as obsolescent if appropriate
10967 ---------------------
10968 -- Set_Obsolescent --
10969 ---------------------
10971 procedure Set_Obsolescent (E : Entity_Id) is
10980 -- Entity name was given
10982 if Present (Ename) then
10984 -- If entity name matches, we are fine. Save entity in
10985 -- pragma argument, for ASIS use.
10987 if Chars (Ename) = Chars (Ent) then
10988 Set_Entity (Ename, Ent);
10989 Generate_Reference (Ent, Ename);
10991 -- If entity name does not match, only possibility is an
10992 -- enumeration literal from an enumeration type declaration.
10994 elsif Ekind (Ent) /= E_Enumeration_Type then
10996 ("pragma % entity name does not match declaration");
10999 Ent := First_Literal (E);
11003 ("pragma % entity name does not match any " &
11004 "enumeration literal");
11006 elsif Chars (Ent) = Chars (Ename) then
11007 Set_Entity (Ename, Ent);
11008 Generate_Reference (Ent, Ename);
11012 Ent := Next_Literal (Ent);
11018 -- Ent points to entity to be marked
11020 if Arg_Count >= 1 then
11022 -- Deal with static string argument
11024 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11025 S := Strval (Get_Pragma_Arg (Arg1));
11027 for J in 1 .. String_Length (S) loop
11028 if not In_Character_Range (Get_String_Char (S, J)) then
11030 ("pragma% argument does not allow wide characters",
11035 Obsolescent_Warnings.Append
11036 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11038 -- Check for Ada_05 parameter
11040 if Arg_Count /= 1 then
11041 Check_Arg_Count (2);
11044 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11047 Check_Arg_Is_Identifier (Argx);
11049 if Chars (Argx) /= Name_Ada_05 then
11050 Error_Msg_Name_2 := Name_Ada_05;
11052 ("only allowed argument for pragma% is %", Argx);
11055 if Ada_Version_Explicit < Ada_2005
11056 or else not Warn_On_Ada_2005_Compatibility
11064 -- Set flag if pragma active
11067 Set_Is_Obsolescent (Ent);
11071 end Set_Obsolescent;
11073 -- Start of processing for pragma Obsolescent
11078 Check_At_Most_N_Arguments (3);
11080 -- See if first argument specifies an entity name
11084 (Chars (Arg1) = Name_Entity
11086 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11088 N_Operator_Symbol))
11090 Ename := Get_Pragma_Arg (Arg1);
11092 -- Eliminate first argument, so we can share processing
11096 Arg_Count := Arg_Count - 1;
11098 -- No Entity name argument given
11104 if Arg_Count >= 1 then
11105 Check_Optional_Identifier (Arg1, Name_Message);
11107 if Arg_Count = 2 then
11108 Check_Optional_Identifier (Arg2, Name_Version);
11112 -- Get immediately preceding declaration
11115 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11119 -- Cases where we do not follow anything other than another pragma
11123 -- First case: library level compilation unit declaration with
11124 -- the pragma immediately following the declaration.
11126 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11128 (Defining_Entity (Unit (Parent (Parent (N)))));
11131 -- Case 2: library unit placement for package
11135 Ent : constant Entity_Id := Find_Lib_Unit_Name;
11137 if Is_Package_Or_Generic_Package (Ent) then
11138 Set_Obsolescent (Ent);
11144 -- Cases where we must follow a declaration
11147 if Nkind (Decl) not in N_Declaration
11148 and then Nkind (Decl) not in N_Later_Decl_Item
11149 and then Nkind (Decl) not in N_Generic_Declaration
11150 and then Nkind (Decl) not in N_Renaming_Declaration
11153 ("pragma% misplaced, "
11154 & "must immediately follow a declaration");
11157 Set_Obsolescent (Defining_Entity (Decl));
11167 -- pragma Optimize (Time | Space | Off);
11169 -- The actual check for optimize is done in Gigi. Note that this
11170 -- pragma does not actually change the optimization setting, it
11171 -- simply checks that it is consistent with the pragma.
11173 when Pragma_Optimize =>
11174 Check_No_Identifiers;
11175 Check_Arg_Count (1);
11176 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11178 ------------------------
11179 -- Optimize_Alignment --
11180 ------------------------
11182 -- pragma Optimize_Alignment (Time | Space | Off);
11184 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11186 Check_No_Identifiers;
11187 Check_Arg_Count (1);
11188 Check_Valid_Configuration_Pragma;
11191 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11195 Opt.Optimize_Alignment := 'T';
11197 Opt.Optimize_Alignment := 'S';
11199 Opt.Optimize_Alignment := 'O';
11201 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11205 -- Set indication that mode is set locally. If we are in fact in a
11206 -- configuration pragma file, this setting is harmless since the
11207 -- switch will get reset anyway at the start of each unit.
11209 Optimize_Alignment_Local := True;
11210 end Optimize_Alignment;
11216 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11218 when Pragma_Ordered => Ordered : declare
11219 Assoc : constant Node_Id := Arg1;
11225 Check_No_Identifiers;
11226 Check_Arg_Count (1);
11227 Check_Arg_Is_Local_Name (Arg1);
11229 Type_Id := Get_Pragma_Arg (Assoc);
11230 Find_Type (Type_Id);
11231 Typ := Entity (Type_Id);
11233 if Typ = Any_Type then
11236 Typ := Underlying_Type (Typ);
11239 if not Is_Enumeration_Type (Typ) then
11240 Error_Pragma ("pragma% must specify enumeration type");
11243 Check_First_Subtype (Arg1);
11244 Set_Has_Pragma_Ordered (Base_Type (Typ));
11251 -- pragma Pack (first_subtype_LOCAL_NAME);
11253 when Pragma_Pack => Pack : declare
11254 Assoc : constant Node_Id := Arg1;
11258 Ignore : Boolean := False;
11261 Check_No_Identifiers;
11262 Check_Arg_Count (1);
11263 Check_Arg_Is_Local_Name (Arg1);
11265 Type_Id := Get_Pragma_Arg (Assoc);
11266 Find_Type (Type_Id);
11267 Typ := Entity (Type_Id);
11270 or else Rep_Item_Too_Early (Typ, N)
11274 Typ := Underlying_Type (Typ);
11277 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11278 Error_Pragma ("pragma% must specify array or record type");
11281 Check_First_Subtype (Arg1);
11282 Check_Duplicate_Pragma (Typ);
11286 if Is_Array_Type (Typ) then
11287 Ctyp := Component_Type (Typ);
11289 -- Ignore pack that does nothing
11291 if Known_Static_Esize (Ctyp)
11292 and then Known_Static_RM_Size (Ctyp)
11293 and then Esize (Ctyp) = RM_Size (Ctyp)
11294 and then Addressable (Esize (Ctyp))
11299 -- Process OK pragma Pack. Note that if there is a separate
11300 -- component clause present, the Pack will be cancelled. This
11301 -- processing is in Freeze.
11303 if not Rep_Item_Too_Late (Typ, N) then
11305 -- In the context of static code analysis, we do not need
11306 -- complex front-end expansions related to pragma Pack,
11307 -- so disable handling of pragma Pack in this case.
11309 if CodePeer_Mode then
11312 -- Don't attempt any packing for VM targets. We possibly
11313 -- could deal with some cases of array bit-packing, but we
11314 -- don't bother, since this is not a typical kind of
11315 -- representation in the VM context anyway (and would not
11316 -- for example work nicely with the debugger).
11318 elsif VM_Target /= No_VM then
11319 if not GNAT_Mode then
11321 ("?pragma% ignored in this configuration");
11324 -- Normal case where we do the pack action
11328 Set_Is_Packed (Base_Type (Typ));
11329 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11332 Set_Has_Pragma_Pack (Base_Type (Typ));
11336 -- For record types, the pack is always effective
11338 else pragma Assert (Is_Record_Type (Typ));
11339 if not Rep_Item_Too_Late (Typ, N) then
11341 -- Ignore pack request with warning in VM mode (skip warning
11342 -- if we are compiling GNAT run time library).
11344 if VM_Target /= No_VM then
11345 if not GNAT_Mode then
11347 ("?pragma% ignored in this configuration");
11350 -- Normal case of pack request active
11353 Set_Is_Packed (Base_Type (Typ));
11354 Set_Has_Pragma_Pack (Base_Type (Typ));
11355 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11367 -- There is nothing to do here, since we did all the processing for
11368 -- this pragma in Par.Prag (so that it works properly even in syntax
11371 when Pragma_Page =>
11378 -- pragma Passive [(PASSIVE_FORM)];
11380 -- PASSIVE_FORM ::= Semaphore | No
11382 when Pragma_Passive =>
11385 if Nkind (Parent (N)) /= N_Task_Definition then
11386 Error_Pragma ("pragma% must be within task definition");
11389 if Arg_Count /= 0 then
11390 Check_Arg_Count (1);
11391 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11394 ----------------------------------
11395 -- Preelaborable_Initialization --
11396 ----------------------------------
11398 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11400 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11405 Check_Arg_Count (1);
11406 Check_No_Identifiers;
11407 Check_Arg_Is_Identifier (Arg1);
11408 Check_Arg_Is_Local_Name (Arg1);
11409 Check_First_Subtype (Arg1);
11410 Ent := Entity (Get_Pragma_Arg (Arg1));
11412 if not (Is_Private_Type (Ent)
11414 Is_Protected_Type (Ent)
11416 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11419 ("pragma % can only be applied to private, formal derived or "
11420 & "protected type",
11424 -- Give an error if the pragma is applied to a protected type that
11425 -- does not qualify (due to having entries, or due to components
11426 -- that do not qualify).
11428 if Is_Protected_Type (Ent)
11429 and then not Has_Preelaborable_Initialization (Ent)
11432 ("protected type & does not have preelaborable " &
11433 "initialization", Ent);
11435 -- Otherwise mark the type as definitely having preelaborable
11439 Set_Known_To_Have_Preelab_Init (Ent);
11442 if Has_Pragma_Preelab_Init (Ent)
11443 and then Warn_On_Redundant_Constructs
11445 Error_Pragma ("?duplicate pragma%!");
11447 Set_Has_Pragma_Preelab_Init (Ent);
11451 --------------------
11452 -- Persistent_BSS --
11453 --------------------
11455 -- pragma Persistent_BSS [(object_NAME)];
11457 when Pragma_Persistent_BSS => Persistent_BSS : declare
11464 Check_At_Most_N_Arguments (1);
11466 -- Case of application to specific object (one argument)
11468 if Arg_Count = 1 then
11469 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11471 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11473 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11476 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11479 Ent := Entity (Get_Pragma_Arg (Arg1));
11480 Decl := Parent (Ent);
11482 if Rep_Item_Too_Late (Ent, N) then
11486 if Present (Expression (Decl)) then
11488 ("object for pragma% cannot have initialization", Arg1);
11491 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11493 ("object type for pragma% is not potentially persistent",
11497 Check_Duplicate_Pragma (Ent);
11500 Make_Linker_Section_Pragma
11501 (Ent, Sloc (N), ".persistent.bss");
11502 Insert_After (N, Prag);
11505 -- Case of use as configuration pragma with no arguments
11508 Check_Valid_Configuration_Pragma;
11509 Persistent_BSS_Mode := True;
11511 end Persistent_BSS;
11517 -- pragma Polling (ON | OFF);
11519 when Pragma_Polling =>
11521 Check_Arg_Count (1);
11522 Check_No_Identifiers;
11523 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11524 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11526 -------------------
11527 -- Postcondition --
11528 -------------------
11530 -- pragma Postcondition ([Check =>] Boolean_Expression
11531 -- [,[Message =>] String_Expression]);
11533 when Pragma_Postcondition => Postcondition : declare
11535 pragma Warnings (Off, In_Body);
11539 Check_At_Least_N_Arguments (1);
11540 Check_At_Most_N_Arguments (2);
11541 Check_Optional_Identifier (Arg1, Name_Check);
11543 -- All we need to do here is call the common check procedure,
11544 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11546 Check_Precondition_Postcondition (In_Body);
11553 -- pragma Precondition ([Check =>] Boolean_Expression
11554 -- [,[Message =>] String_Expression]);
11556 when Pragma_Precondition => Precondition : declare
11561 Check_At_Least_N_Arguments (1);
11562 Check_At_Most_N_Arguments (2);
11563 Check_Optional_Identifier (Arg1, Name_Check);
11564 Check_Precondition_Postcondition (In_Body);
11566 -- If in spec, nothing more to do. If in body, then we convert the
11567 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11568 -- this whether or not precondition checks are enabled. That works
11569 -- fine since pragma Check will do this check, and will also
11570 -- analyze the condition itself in the proper context.
11575 Chars => Name_Check,
11576 Pragma_Argument_Associations => New_List (
11577 Make_Pragma_Argument_Association (Loc,
11578 Expression => Make_Identifier (Loc, Name_Precondition)),
11580 Make_Pragma_Argument_Association (Sloc (Arg1),
11581 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11583 if Arg_Count = 2 then
11584 Append_To (Pragma_Argument_Associations (N),
11585 Make_Pragma_Argument_Association (Sloc (Arg2),
11586 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11597 -- pragma Predicate
11598 -- ([Entity =>] type_LOCAL_NAME,
11599 -- [Check =>] EXPRESSION);
11601 when Pragma_Predicate => Predicate : declare
11606 pragma Unreferenced (Discard);
11610 Check_Arg_Count (2);
11611 Check_Optional_Identifier (Arg1, Name_Entity);
11612 Check_Optional_Identifier (Arg2, Name_Check);
11614 Check_Arg_Is_Local_Name (Arg1);
11616 Type_Id := Get_Pragma_Arg (Arg1);
11617 Find_Type (Type_Id);
11618 Typ := Entity (Type_Id);
11620 if Typ = Any_Type then
11624 -- The remaining processing is simply to link the pragma on to
11625 -- the rep item chain, for processing when the type is frozen.
11626 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11627 -- mark the type as having predicates.
11629 Set_Has_Predicates (Typ);
11630 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11637 -- pragma Preelaborate [(library_unit_NAME)];
11639 -- Set the flag Is_Preelaborated of program unit name entity
11641 when Pragma_Preelaborate => Preelaborate : declare
11642 Pa : constant Node_Id := Parent (N);
11643 Pk : constant Node_Kind := Nkind (Pa);
11647 Check_Ada_83_Warning;
11648 Check_Valid_Library_Unit_Pragma;
11650 if Nkind (N) = N_Null_Statement then
11654 Ent := Find_Lib_Unit_Name;
11655 Check_Duplicate_Pragma (Ent);
11657 -- This filters out pragmas inside generic parent then
11658 -- show up inside instantiation
11661 and then not (Pk = N_Package_Specification
11662 and then Present (Generic_Parent (Pa)))
11664 if not Debug_Flag_U then
11665 Set_Is_Preelaborated (Ent);
11666 Set_Suppress_Elaboration_Warnings (Ent);
11671 ---------------------
11672 -- Preelaborate_05 --
11673 ---------------------
11675 -- pragma Preelaborate_05 [(library_unit_NAME)];
11677 -- This pragma is useable only in GNAT_Mode, where it is used like
11678 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11679 -- (otherwise it is ignored). This is used to implement AI-362 which
11680 -- recategorizes some run-time packages in Ada 2005 mode.
11682 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11687 Check_Valid_Library_Unit_Pragma;
11689 if not GNAT_Mode then
11690 Error_Pragma ("pragma% only available in GNAT mode");
11693 if Nkind (N) = N_Null_Statement then
11697 -- This is one of the few cases where we need to test the value of
11698 -- Ada_Version_Explicit rather than Ada_Version (which is always
11699 -- set to Ada_2012 in a predefined unit), we need to know the
11700 -- explicit version set to know if this pragma is active.
11702 if Ada_Version_Explicit >= Ada_2005 then
11703 Ent := Find_Lib_Unit_Name;
11704 Set_Is_Preelaborated (Ent);
11705 Set_Suppress_Elaboration_Warnings (Ent);
11707 end Preelaborate_05;
11713 -- pragma Priority (EXPRESSION);
11715 when Pragma_Priority => Priority : declare
11716 P : constant Node_Id := Parent (N);
11720 Check_No_Identifiers;
11721 Check_Arg_Count (1);
11725 if Nkind (P) = N_Subprogram_Body then
11726 Check_In_Main_Program;
11728 Arg := Get_Pragma_Arg (Arg1);
11729 Analyze_And_Resolve (Arg, Standard_Integer);
11733 if not Is_Static_Expression (Arg) then
11734 Flag_Non_Static_Expr
11735 ("main subprogram priority is not static!", Arg);
11738 -- If constraint error, then we already signalled an error
11740 elsif Raises_Constraint_Error (Arg) then
11743 -- Otherwise check in range
11747 Val : constant Uint := Expr_Value (Arg);
11751 or else Val > Expr_Value (Expression
11752 (Parent (RTE (RE_Max_Priority))))
11755 ("main subprogram priority is out of range", Arg1);
11761 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11763 -- Load an arbitrary entity from System.Tasking to make sure
11764 -- this package is implicitly with'ed, since we need to have
11765 -- the tasking run-time active for the pragma Priority to have
11769 Discard : Entity_Id;
11770 pragma Warnings (Off, Discard);
11772 Discard := RTE (RE_Task_List);
11775 -- Task or Protected, must be of type Integer
11777 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11778 Arg := Get_Pragma_Arg (Arg1);
11780 -- The expression must be analyzed in the special manner
11781 -- described in "Handling of Default and Per-Object
11782 -- Expressions" in sem.ads.
11784 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11786 if not Is_Static_Expression (Arg) then
11787 Check_Restriction (Static_Priorities, Arg);
11790 -- Anything else is incorrect
11796 if Has_Pragma_Priority (P) then
11797 Error_Pragma ("duplicate pragma% not allowed");
11799 Set_Has_Pragma_Priority (P, True);
11801 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11802 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11803 -- exp_ch9 should use this ???
11808 -----------------------------------
11809 -- Priority_Specific_Dispatching --
11810 -----------------------------------
11812 -- pragma Priority_Specific_Dispatching (
11813 -- policy_IDENTIFIER,
11814 -- first_priority_EXPRESSION,
11815 -- last_priority_EXPRESSION);
11817 when Pragma_Priority_Specific_Dispatching =>
11818 Priority_Specific_Dispatching : declare
11819 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11820 -- This is the entity System.Any_Priority;
11823 Lower_Bound : Node_Id;
11824 Upper_Bound : Node_Id;
11830 Check_Arg_Count (3);
11831 Check_No_Identifiers;
11832 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11833 Check_Valid_Configuration_Pragma;
11834 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11835 DP := Fold_Upper (Name_Buffer (1));
11837 Lower_Bound := Get_Pragma_Arg (Arg2);
11838 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11839 Lower_Val := Expr_Value (Lower_Bound);
11841 Upper_Bound := Get_Pragma_Arg (Arg3);
11842 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11843 Upper_Val := Expr_Value (Upper_Bound);
11845 -- It is not allowed to use Task_Dispatching_Policy and
11846 -- Priority_Specific_Dispatching in the same partition.
11848 if Task_Dispatching_Policy /= ' ' then
11849 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11851 ("pragma% incompatible with Task_Dispatching_Policy#");
11853 -- Check lower bound in range
11855 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11857 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11860 ("first_priority is out of range", Arg2);
11862 -- Check upper bound in range
11864 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11866 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11869 ("last_priority is out of range", Arg3);
11871 -- Check that the priority range is valid
11873 elsif Lower_Val > Upper_Val then
11875 ("last_priority_expression must be greater than" &
11876 " or equal to first_priority_expression");
11878 -- Store the new policy, but always preserve System_Location since
11879 -- we like the error message with the run-time name.
11882 -- Check overlapping in the priority ranges specified in other
11883 -- Priority_Specific_Dispatching pragmas within the same
11884 -- partition. We can only check those we know about!
11887 Specific_Dispatching.First .. Specific_Dispatching.Last
11889 if Specific_Dispatching.Table (J).First_Priority in
11890 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11891 or else Specific_Dispatching.Table (J).Last_Priority in
11892 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11895 Specific_Dispatching.Table (J).Pragma_Loc;
11897 ("priority range overlaps with "
11898 & "Priority_Specific_Dispatching#");
11902 -- The use of Priority_Specific_Dispatching is incompatible
11903 -- with Task_Dispatching_Policy.
11905 if Task_Dispatching_Policy /= ' ' then
11906 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11908 ("Priority_Specific_Dispatching incompatible "
11909 & "with Task_Dispatching_Policy#");
11912 -- The use of Priority_Specific_Dispatching forces ceiling
11915 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11916 Error_Msg_Sloc := Locking_Policy_Sloc;
11918 ("Priority_Specific_Dispatching incompatible "
11919 & "with Locking_Policy#");
11921 -- Set the Ceiling_Locking policy, but preserve System_Location
11922 -- since we like the error message with the run time name.
11925 Locking_Policy := 'C';
11927 if Locking_Policy_Sloc /= System_Location then
11928 Locking_Policy_Sloc := Loc;
11932 -- Add entry in the table
11934 Specific_Dispatching.Append
11935 ((Dispatching_Policy => DP,
11936 First_Priority => UI_To_Int (Lower_Val),
11937 Last_Priority => UI_To_Int (Upper_Val),
11938 Pragma_Loc => Loc));
11940 end Priority_Specific_Dispatching;
11946 -- pragma Profile (profile_IDENTIFIER);
11948 -- profile_IDENTIFIER => Restricted | Ravenscar
11950 when Pragma_Profile =>
11952 Check_Arg_Count (1);
11953 Check_Valid_Configuration_Pragma;
11954 Check_No_Identifiers;
11957 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11959 if Chars (Argx) = Name_Ravenscar then
11960 Set_Ravenscar_Profile (N);
11961 elsif Chars (Argx) = Name_Restricted then
11962 Set_Profile_Restrictions
11963 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11965 Error_Pragma_Arg ("& is not a valid profile", Argx);
11969 ----------------------
11970 -- Profile_Warnings --
11971 ----------------------
11973 -- pragma Profile_Warnings (profile_IDENTIFIER);
11975 -- profile_IDENTIFIER => Restricted | Ravenscar
11977 when Pragma_Profile_Warnings =>
11979 Check_Arg_Count (1);
11980 Check_Valid_Configuration_Pragma;
11981 Check_No_Identifiers;
11984 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11986 if Chars (Argx) = Name_Ravenscar then
11987 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11988 elsif Chars (Argx) = Name_Restricted then
11989 Set_Profile_Restrictions (Restricted, N, Warn => True);
11991 Error_Pragma_Arg ("& is not a valid profile", Argx);
11995 --------------------------
11996 -- Propagate_Exceptions --
11997 --------------------------
11999 -- pragma Propagate_Exceptions;
12001 -- Note: this pragma is obsolete and has no effect
12003 when Pragma_Propagate_Exceptions =>
12005 Check_Arg_Count (0);
12007 if In_Extended_Main_Source_Unit (N) then
12008 Propagate_Exceptions := True;
12015 -- pragma Psect_Object (
12016 -- [Internal =>] LOCAL_NAME,
12017 -- [, [External =>] EXTERNAL_SYMBOL]
12018 -- [, [Size =>] EXTERNAL_SYMBOL]);
12020 when Pragma_Psect_Object | Pragma_Common_Object =>
12021 Psect_Object : declare
12022 Args : Args_List (1 .. 3);
12023 Names : constant Name_List (1 .. 3) := (
12028 Internal : Node_Id renames Args (1);
12029 External : Node_Id renames Args (2);
12030 Size : Node_Id renames Args (3);
12032 Def_Id : Entity_Id;
12034 procedure Check_Too_Long (Arg : Node_Id);
12035 -- Posts message if the argument is an identifier with more
12036 -- than 31 characters, or a string literal with more than
12037 -- 31 characters, and we are operating under VMS
12039 --------------------
12040 -- Check_Too_Long --
12041 --------------------
12043 procedure Check_Too_Long (Arg : Node_Id) is
12044 X : constant Node_Id := Original_Node (Arg);
12047 if not Nkind_In (X, N_String_Literal, N_Identifier) then
12049 ("inappropriate argument for pragma %", Arg);
12052 if OpenVMS_On_Target then
12053 if (Nkind (X) = N_String_Literal
12054 and then String_Length (Strval (X)) > 31)
12056 (Nkind (X) = N_Identifier
12057 and then Length_Of_Name (Chars (X)) > 31)
12060 ("argument for pragma % is longer than 31 characters",
12064 end Check_Too_Long;
12066 -- Start of processing for Common_Object/Psect_Object
12070 Gather_Associations (Names, Args);
12071 Process_Extended_Import_Export_Internal_Arg (Internal);
12073 Def_Id := Entity (Internal);
12075 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12077 ("pragma% must designate an object", Internal);
12080 Check_Too_Long (Internal);
12082 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12084 ("cannot use pragma% for imported/exported object",
12088 if Is_Concurrent_Type (Etype (Internal)) then
12090 ("cannot specify pragma % for task/protected object",
12094 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12096 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12098 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12101 if Ekind (Def_Id) = E_Constant then
12103 ("cannot specify pragma % for a constant", Internal);
12106 if Is_Record_Type (Etype (Internal)) then
12112 Ent := First_Entity (Etype (Internal));
12113 while Present (Ent) loop
12114 Decl := Declaration_Node (Ent);
12116 if Ekind (Ent) = E_Component
12117 and then Nkind (Decl) = N_Component_Declaration
12118 and then Present (Expression (Decl))
12119 and then Warn_On_Export_Import
12122 ("?object for pragma % has defaults", Internal);
12132 if Present (Size) then
12133 Check_Too_Long (Size);
12136 if Present (External) then
12137 Check_Arg_Is_External_Name (External);
12138 Check_Too_Long (External);
12141 -- If all error tests pass, link pragma on to the rep item chain
12143 Record_Rep_Item (Def_Id, N);
12150 -- pragma Pure [(library_unit_NAME)];
12152 when Pragma_Pure => Pure : declare
12156 Check_Ada_83_Warning;
12157 Check_Valid_Library_Unit_Pragma;
12159 if Nkind (N) = N_Null_Statement then
12163 Ent := Find_Lib_Unit_Name;
12165 Set_Has_Pragma_Pure (Ent);
12166 Set_Suppress_Elaboration_Warnings (Ent);
12173 -- pragma Pure_05 [(library_unit_NAME)];
12175 -- This pragma is useable only in GNAT_Mode, where it is used like
12176 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
12177 -- it is ignored). It may be used after a pragma Preelaborate, in
12178 -- which case it overrides the effect of the pragma Preelaborate.
12179 -- This is used to implement AI-362 which recategorizes some run-time
12180 -- packages in Ada 2005 mode.
12182 when Pragma_Pure_05 => Pure_05 : declare
12187 Check_Valid_Library_Unit_Pragma;
12189 if not GNAT_Mode then
12190 Error_Pragma ("pragma% only available in GNAT mode");
12193 if Nkind (N) = N_Null_Statement then
12197 -- This is one of the few cases where we need to test the value of
12198 -- Ada_Version_Explicit rather than Ada_Version (which is always
12199 -- set to Ada_2012 in a predefined unit), we need to know the
12200 -- explicit version set to know if this pragma is active.
12202 if Ada_Version_Explicit >= Ada_2005 then
12203 Ent := Find_Lib_Unit_Name;
12204 Set_Is_Preelaborated (Ent, False);
12206 Set_Suppress_Elaboration_Warnings (Ent);
12210 -------------------
12211 -- Pure_Function --
12212 -------------------
12214 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12216 when Pragma_Pure_Function => Pure_Function : declare
12219 Def_Id : Entity_Id;
12220 Effective : Boolean := False;
12224 Check_Arg_Count (1);
12225 Check_Optional_Identifier (Arg1, Name_Entity);
12226 Check_Arg_Is_Local_Name (Arg1);
12227 E_Id := Get_Pragma_Arg (Arg1);
12229 if Error_Posted (E_Id) then
12233 -- Loop through homonyms (overloadings) of referenced entity
12235 E := Entity (E_Id);
12237 if Present (E) then
12239 Def_Id := Get_Base_Subprogram (E);
12241 if not Ekind_In (Def_Id, E_Function,
12242 E_Generic_Function,
12246 ("pragma% requires a function name", Arg1);
12249 Set_Is_Pure (Def_Id);
12251 if not Has_Pragma_Pure_Function (Def_Id) then
12252 Set_Has_Pragma_Pure_Function (Def_Id);
12256 exit when From_Aspect_Specification (N);
12258 exit when No (E) or else Scope (E) /= Current_Scope;
12262 and then Warn_On_Redundant_Constructs
12265 ("pragma Pure_Function on& is redundant?",
12271 --------------------
12272 -- Queuing_Policy --
12273 --------------------
12275 -- pragma Queuing_Policy (policy_IDENTIFIER);
12277 when Pragma_Queuing_Policy => declare
12281 Check_Ada_83_Warning;
12282 Check_Arg_Count (1);
12283 Check_No_Identifiers;
12284 Check_Arg_Is_Queuing_Policy (Arg1);
12285 Check_Valid_Configuration_Pragma;
12286 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12287 QP := Fold_Upper (Name_Buffer (1));
12289 if Queuing_Policy /= ' '
12290 and then Queuing_Policy /= QP
12292 Error_Msg_Sloc := Queuing_Policy_Sloc;
12293 Error_Pragma ("queuing policy incompatible with policy#");
12295 -- Set new policy, but always preserve System_Location since we
12296 -- like the error message with the run time name.
12299 Queuing_Policy := QP;
12301 if Queuing_Policy_Sloc /= System_Location then
12302 Queuing_Policy_Sloc := Loc;
12307 -----------------------
12308 -- Relative_Deadline --
12309 -----------------------
12311 -- pragma Relative_Deadline (time_span_EXPRESSION);
12313 when Pragma_Relative_Deadline => Relative_Deadline : declare
12314 P : constant Node_Id := Parent (N);
12319 Check_No_Identifiers;
12320 Check_Arg_Count (1);
12322 Arg := Get_Pragma_Arg (Arg1);
12324 -- The expression must be analyzed in the special manner described
12325 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12327 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12331 if Nkind (P) = N_Subprogram_Body then
12332 Check_In_Main_Program;
12336 elsif Nkind (P) = N_Task_Definition then
12339 -- Anything else is incorrect
12345 if Has_Relative_Deadline_Pragma (P) then
12346 Error_Pragma ("duplicate pragma% not allowed");
12348 Set_Has_Relative_Deadline_Pragma (P, True);
12350 if Nkind (P) = N_Task_Definition then
12351 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12354 end Relative_Deadline;
12356 ---------------------------
12357 -- Remote_Call_Interface --
12358 ---------------------------
12360 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12362 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12363 Cunit_Node : Node_Id;
12364 Cunit_Ent : Entity_Id;
12368 Check_Ada_83_Warning;
12369 Check_Valid_Library_Unit_Pragma;
12371 if Nkind (N) = N_Null_Statement then
12375 Cunit_Node := Cunit (Current_Sem_Unit);
12376 K := Nkind (Unit (Cunit_Node));
12377 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12379 if K = N_Package_Declaration
12380 or else K = N_Generic_Package_Declaration
12381 or else K = N_Subprogram_Declaration
12382 or else K = N_Generic_Subprogram_Declaration
12383 or else (K = N_Subprogram_Body
12384 and then Acts_As_Spec (Unit (Cunit_Node)))
12389 "pragma% must apply to package or subprogram declaration");
12392 Set_Is_Remote_Call_Interface (Cunit_Ent);
12393 end Remote_Call_Interface;
12399 -- pragma Remote_Types [(library_unit_NAME)];
12401 when Pragma_Remote_Types => Remote_Types : declare
12402 Cunit_Node : Node_Id;
12403 Cunit_Ent : Entity_Id;
12406 Check_Ada_83_Warning;
12407 Check_Valid_Library_Unit_Pragma;
12409 if Nkind (N) = N_Null_Statement then
12413 Cunit_Node := Cunit (Current_Sem_Unit);
12414 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12416 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12417 N_Generic_Package_Declaration)
12420 ("pragma% can only apply to a package declaration");
12423 Set_Is_Remote_Types (Cunit_Ent);
12430 -- pragma Ravenscar;
12432 when Pragma_Ravenscar =>
12434 Check_Arg_Count (0);
12435 Check_Valid_Configuration_Pragma;
12436 Set_Ravenscar_Profile (N);
12438 if Warn_On_Obsolescent_Feature then
12439 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12440 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12443 -------------------------
12444 -- Restricted_Run_Time --
12445 -------------------------
12447 -- pragma Restricted_Run_Time;
12449 when Pragma_Restricted_Run_Time =>
12451 Check_Arg_Count (0);
12452 Check_Valid_Configuration_Pragma;
12453 Set_Profile_Restrictions
12454 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12456 if Warn_On_Obsolescent_Feature then
12458 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12459 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12466 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12469 -- restriction_IDENTIFIER
12470 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12472 when Pragma_Restrictions =>
12473 Process_Restrictions_Or_Restriction_Warnings
12474 (Warn => Treat_Restrictions_As_Warnings);
12476 --------------------------
12477 -- Restriction_Warnings --
12478 --------------------------
12480 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12483 -- restriction_IDENTIFIER
12484 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12486 when Pragma_Restriction_Warnings =>
12488 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12494 -- pragma Reviewable;
12496 when Pragma_Reviewable =>
12497 Check_Ada_83_Warning;
12498 Check_Arg_Count (0);
12500 -- Call dummy debugging function rv. This is done to assist front
12501 -- end debugging. By placing a Reviewable pragma in the source
12502 -- program, a breakpoint on rv catches this place in the source,
12503 -- allowing convenient stepping to the point of interest.
12507 --------------------------
12508 -- Short_Circuit_And_Or --
12509 --------------------------
12511 when Pragma_Short_Circuit_And_Or =>
12513 Check_Arg_Count (0);
12514 Check_Valid_Configuration_Pragma;
12515 Short_Circuit_And_Or := True;
12517 -------------------
12518 -- Share_Generic --
12519 -------------------
12521 -- pragma Share_Generic (NAME {, NAME});
12523 when Pragma_Share_Generic =>
12525 Process_Generic_List;
12531 -- pragma Shared (LOCAL_NAME);
12533 when Pragma_Shared =>
12535 Process_Atomic_Shared_Volatile;
12537 --------------------
12538 -- Shared_Passive --
12539 --------------------
12541 -- pragma Shared_Passive [(library_unit_NAME)];
12543 -- Set the flag Is_Shared_Passive of program unit name entity
12545 when Pragma_Shared_Passive => Shared_Passive : declare
12546 Cunit_Node : Node_Id;
12547 Cunit_Ent : Entity_Id;
12550 Check_Ada_83_Warning;
12551 Check_Valid_Library_Unit_Pragma;
12553 if Nkind (N) = N_Null_Statement then
12557 Cunit_Node := Cunit (Current_Sem_Unit);
12558 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12560 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12561 N_Generic_Package_Declaration)
12564 ("pragma% can only apply to a package declaration");
12567 Set_Is_Shared_Passive (Cunit_Ent);
12568 end Shared_Passive;
12570 -----------------------
12571 -- Short_Descriptors --
12572 -----------------------
12574 -- pragma Short_Descriptors;
12576 when Pragma_Short_Descriptors =>
12578 Check_Arg_Count (0);
12579 Check_Valid_Configuration_Pragma;
12580 Short_Descriptors := True;
12582 ----------------------
12583 -- Source_File_Name --
12584 ----------------------
12586 -- There are five forms for this pragma:
12588 -- pragma Source_File_Name (
12589 -- [UNIT_NAME =>] unit_NAME,
12590 -- BODY_FILE_NAME => STRING_LITERAL
12591 -- [, [INDEX =>] INTEGER_LITERAL]);
12593 -- pragma Source_File_Name (
12594 -- [UNIT_NAME =>] unit_NAME,
12595 -- SPEC_FILE_NAME => STRING_LITERAL
12596 -- [, [INDEX =>] INTEGER_LITERAL]);
12598 -- pragma Source_File_Name (
12599 -- BODY_FILE_NAME => STRING_LITERAL
12600 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12601 -- [, CASING => CASING_SPEC]);
12603 -- pragma Source_File_Name (
12604 -- SPEC_FILE_NAME => STRING_LITERAL
12605 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12606 -- [, CASING => CASING_SPEC]);
12608 -- pragma Source_File_Name (
12609 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12610 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12611 -- [, CASING => CASING_SPEC]);
12613 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12615 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12616 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12617 -- only be used when no project file is used, while SFNP can only be
12618 -- used when a project file is used.
12620 -- No processing here. Processing was completed during parsing, since
12621 -- we need to have file names set as early as possible. Units are
12622 -- loaded well before semantic processing starts.
12624 -- The only processing we defer to this point is the check for
12625 -- correct placement.
12627 when Pragma_Source_File_Name =>
12629 Check_Valid_Configuration_Pragma;
12631 ------------------------------
12632 -- Source_File_Name_Project --
12633 ------------------------------
12635 -- See Source_File_Name for syntax
12637 -- No processing here. Processing was completed during parsing, since
12638 -- we need to have file names set as early as possible. Units are
12639 -- loaded well before semantic processing starts.
12641 -- The only processing we defer to this point is the check for
12642 -- correct placement.
12644 when Pragma_Source_File_Name_Project =>
12646 Check_Valid_Configuration_Pragma;
12648 -- Check that a pragma Source_File_Name_Project is used only in a
12649 -- configuration pragmas file.
12651 -- Pragmas Source_File_Name_Project should only be generated by
12652 -- the Project Manager in configuration pragmas files.
12654 -- This is really an ugly test. It seems to depend on some
12655 -- accidental and undocumented property. At the very least it
12656 -- needs to be documented, but it would be better to have a
12657 -- clean way of testing if we are in a configuration file???
12659 if Present (Parent (N)) then
12661 ("pragma% can only appear in a configuration pragmas file");
12664 ----------------------
12665 -- Source_Reference --
12666 ----------------------
12668 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12670 -- Nothing to do, all processing completed in Par.Prag, since we need
12671 -- the information for possible parser messages that are output.
12673 when Pragma_Source_Reference =>
12676 --------------------------------
12677 -- Static_Elaboration_Desired --
12678 --------------------------------
12680 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12682 when Pragma_Static_Elaboration_Desired =>
12684 Check_At_Most_N_Arguments (1);
12686 if Is_Compilation_Unit (Current_Scope)
12687 and then Ekind (Current_Scope) = E_Package
12689 Set_Static_Elaboration_Desired (Current_Scope, True);
12691 Error_Pragma ("pragma% must apply to a library-level package");
12698 -- pragma Storage_Size (EXPRESSION);
12700 when Pragma_Storage_Size => Storage_Size : declare
12701 P : constant Node_Id := Parent (N);
12705 Check_No_Identifiers;
12706 Check_Arg_Count (1);
12708 -- The expression must be analyzed in the special manner described
12709 -- in "Handling of Default Expressions" in sem.ads.
12711 Arg := Get_Pragma_Arg (Arg1);
12712 Preanalyze_Spec_Expression (Arg, Any_Integer);
12714 if not Is_Static_Expression (Arg) then
12715 Check_Restriction (Static_Storage_Size, Arg);
12718 if Nkind (P) /= N_Task_Definition then
12723 if Has_Storage_Size_Pragma (P) then
12724 Error_Pragma ("duplicate pragma% not allowed");
12726 Set_Has_Storage_Size_Pragma (P, True);
12729 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12730 -- ??? exp_ch9 should use this!
12738 -- pragma Storage_Unit (NUMERIC_LITERAL);
12740 -- Only permitted argument is System'Storage_Unit value
12742 when Pragma_Storage_Unit =>
12743 Check_No_Identifiers;
12744 Check_Arg_Count (1);
12745 Check_Arg_Is_Integer_Literal (Arg1);
12747 if Intval (Get_Pragma_Arg (Arg1)) /=
12748 UI_From_Int (Ttypes.System_Storage_Unit)
12750 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12752 ("the only allowed argument for pragma% is ^", Arg1);
12755 --------------------
12756 -- Stream_Convert --
12757 --------------------
12759 -- pragma Stream_Convert (
12760 -- [Entity =>] type_LOCAL_NAME,
12761 -- [Read =>] function_NAME,
12762 -- [Write =>] function NAME);
12764 when Pragma_Stream_Convert => Stream_Convert : declare
12766 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12767 -- Check that the given argument is the name of a local function
12768 -- of one argument that is not overloaded earlier in the current
12769 -- local scope. A check is also made that the argument is a
12770 -- function with one parameter.
12772 --------------------------------------
12773 -- Check_OK_Stream_Convert_Function --
12774 --------------------------------------
12776 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12780 Check_Arg_Is_Local_Name (Arg);
12781 Ent := Entity (Get_Pragma_Arg (Arg));
12783 if Has_Homonym (Ent) then
12785 ("argument for pragma% may not be overloaded", Arg);
12788 if Ekind (Ent) /= E_Function
12789 or else No (First_Formal (Ent))
12790 or else Present (Next_Formal (First_Formal (Ent)))
12793 ("argument for pragma% must be" &
12794 " function of one argument", Arg);
12796 end Check_OK_Stream_Convert_Function;
12798 -- Start of processing for Stream_Convert
12802 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12803 Check_Arg_Count (3);
12804 Check_Optional_Identifier (Arg1, Name_Entity);
12805 Check_Optional_Identifier (Arg2, Name_Read);
12806 Check_Optional_Identifier (Arg3, Name_Write);
12807 Check_Arg_Is_Local_Name (Arg1);
12808 Check_OK_Stream_Convert_Function (Arg2);
12809 Check_OK_Stream_Convert_Function (Arg3);
12812 Typ : constant Entity_Id :=
12813 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12814 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12815 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12818 Check_First_Subtype (Arg1);
12820 -- Check for too early or too late. Note that we don't enforce
12821 -- the rule about primitive operations in this case, since, as
12822 -- is the case for explicit stream attributes themselves, these
12823 -- restrictions are not appropriate. Note that the chaining of
12824 -- the pragma by Rep_Item_Too_Late is actually the critical
12825 -- processing done for this pragma.
12827 if Rep_Item_Too_Early (Typ, N)
12829 Rep_Item_Too_Late (Typ, N, FOnly => True)
12834 -- Return if previous error
12836 if Etype (Typ) = Any_Type
12838 Etype (Read) = Any_Type
12840 Etype (Write) = Any_Type
12847 if Underlying_Type (Etype (Read)) /= Typ then
12849 ("incorrect return type for function&", Arg2);
12852 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12854 ("incorrect parameter type for function&", Arg3);
12857 if Underlying_Type (Etype (First_Formal (Read))) /=
12858 Underlying_Type (Etype (Write))
12861 ("result type of & does not match Read parameter type",
12865 end Stream_Convert;
12867 -------------------------
12868 -- Style_Checks (GNAT) --
12869 -------------------------
12871 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12873 -- This is processed by the parser since some of the style checks
12874 -- take place during source scanning and parsing. This means that
12875 -- we don't need to issue error messages here.
12877 when Pragma_Style_Checks => Style_Checks : declare
12878 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12884 Check_No_Identifiers;
12886 -- Two argument form
12888 if Arg_Count = 2 then
12889 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12896 E_Id := Get_Pragma_Arg (Arg2);
12899 if not Is_Entity_Name (E_Id) then
12901 ("second argument of pragma% must be entity name",
12905 E := Entity (E_Id);
12911 Set_Suppress_Style_Checks (E,
12912 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12913 exit when No (Homonym (E));
12919 -- One argument form
12922 Check_Arg_Count (1);
12924 if Nkind (A) = N_String_Literal then
12928 Slen : constant Natural := Natural (String_Length (S));
12929 Options : String (1 .. Slen);
12935 C := Get_String_Char (S, Int (J));
12936 exit when not In_Character_Range (C);
12937 Options (J) := Get_Character (C);
12939 -- If at end of string, set options. As per discussion
12940 -- above, no need to check for errors, since we issued
12941 -- them in the parser.
12944 Set_Style_Check_Options (Options);
12952 elsif Nkind (A) = N_Identifier then
12953 if Chars (A) = Name_All_Checks then
12955 Set_GNAT_Style_Check_Options;
12957 Set_Default_Style_Check_Options;
12960 elsif Chars (A) = Name_On then
12961 Style_Check := True;
12963 elsif Chars (A) = Name_Off then
12964 Style_Check := False;
12974 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12976 when Pragma_Subtitle =>
12978 Check_Arg_Count (1);
12979 Check_Optional_Identifier (Arg1, Name_Subtitle);
12980 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12987 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12989 when Pragma_Suppress =>
12990 Process_Suppress_Unsuppress (True);
12996 -- pragma Suppress_All;
12998 -- The only check made here is that the pragma has no arguments.
12999 -- There are no placement rules, and the processing required (setting
13000 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
13001 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
13002 -- then creates and inserts a pragma Suppress (All_Checks).
13004 when Pragma_Suppress_All =>
13006 Check_Arg_Count (0);
13008 -------------------------
13009 -- Suppress_Debug_Info --
13010 -------------------------
13012 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13014 when Pragma_Suppress_Debug_Info =>
13016 Check_Arg_Count (1);
13017 Check_Optional_Identifier (Arg1, Name_Entity);
13018 Check_Arg_Is_Local_Name (Arg1);
13019 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13021 ----------------------------------
13022 -- Suppress_Exception_Locations --
13023 ----------------------------------
13025 -- pragma Suppress_Exception_Locations;
13027 when Pragma_Suppress_Exception_Locations =>
13029 Check_Arg_Count (0);
13030 Check_Valid_Configuration_Pragma;
13031 Exception_Locations_Suppressed := True;
13033 -----------------------------
13034 -- Suppress_Initialization --
13035 -----------------------------
13037 -- pragma Suppress_Initialization ([Entity =>] type_Name);
13039 when Pragma_Suppress_Initialization => Suppress_Init : declare
13045 Check_Arg_Count (1);
13046 Check_Optional_Identifier (Arg1, Name_Entity);
13047 Check_Arg_Is_Local_Name (Arg1);
13049 E_Id := Get_Pragma_Arg (Arg1);
13051 if Etype (E_Id) = Any_Type then
13055 E := Entity (E_Id);
13057 if not Is_Type (E) then
13058 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13061 if Rep_Item_Too_Early (E, N)
13063 Rep_Item_Too_Late (E, N, FOnly => True)
13068 -- For incomplete/private type, set flag on full view
13070 if Is_Incomplete_Or_Private_Type (E) then
13071 if No (Full_View (Base_Type (E))) then
13073 ("argument of pragma% cannot be an incomplete type", Arg1);
13075 Set_Suppress_Initialization (Full_View (Base_Type (E)));
13078 -- For first subtype, set flag on base type
13080 elsif Is_First_Subtype (E) then
13081 Set_Suppress_Initialization (Base_Type (E));
13083 -- For other than first subtype, set flag on subtype itself
13086 Set_Suppress_Initialization (E);
13094 -- pragma System_Name (DIRECT_NAME);
13096 -- Syntax check: one argument, which must be the identifier GNAT or
13097 -- the identifier GCC, no other identifiers are acceptable.
13099 when Pragma_System_Name =>
13101 Check_No_Identifiers;
13102 Check_Arg_Count (1);
13103 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13105 -----------------------------
13106 -- Task_Dispatching_Policy --
13107 -----------------------------
13109 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13111 when Pragma_Task_Dispatching_Policy => declare
13115 Check_Ada_83_Warning;
13116 Check_Arg_Count (1);
13117 Check_No_Identifiers;
13118 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13119 Check_Valid_Configuration_Pragma;
13120 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13121 DP := Fold_Upper (Name_Buffer (1));
13123 if Task_Dispatching_Policy /= ' '
13124 and then Task_Dispatching_Policy /= DP
13126 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13128 ("task dispatching policy incompatible with policy#");
13130 -- Set new policy, but always preserve System_Location since we
13131 -- like the error message with the run time name.
13134 Task_Dispatching_Policy := DP;
13136 if Task_Dispatching_Policy_Sloc /= System_Location then
13137 Task_Dispatching_Policy_Sloc := Loc;
13146 -- pragma Task_Info (EXPRESSION);
13148 when Pragma_Task_Info => Task_Info : declare
13149 P : constant Node_Id := Parent (N);
13154 if Nkind (P) /= N_Task_Definition then
13155 Error_Pragma ("pragma% must appear in task definition");
13158 Check_No_Identifiers;
13159 Check_Arg_Count (1);
13161 Analyze_And_Resolve
13162 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13164 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13168 if Has_Task_Info_Pragma (P) then
13169 Error_Pragma ("duplicate pragma% not allowed");
13171 Set_Has_Task_Info_Pragma (P, True);
13179 -- pragma Task_Name (string_EXPRESSION);
13181 when Pragma_Task_Name => Task_Name : declare
13182 P : constant Node_Id := Parent (N);
13186 Check_No_Identifiers;
13187 Check_Arg_Count (1);
13189 Arg := Get_Pragma_Arg (Arg1);
13191 -- The expression is used in the call to Create_Task, and must be
13192 -- expanded there, not in the context of the current spec. It must
13193 -- however be analyzed to capture global references, in case it
13194 -- appears in a generic context.
13196 Preanalyze_And_Resolve (Arg, Standard_String);
13198 if Nkind (P) /= N_Task_Definition then
13202 if Has_Task_Name_Pragma (P) then
13203 Error_Pragma ("duplicate pragma% not allowed");
13205 Set_Has_Task_Name_Pragma (P, True);
13206 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13214 -- pragma Task_Storage (
13215 -- [Task_Type =>] LOCAL_NAME,
13216 -- [Top_Guard =>] static_integer_EXPRESSION);
13218 when Pragma_Task_Storage => Task_Storage : declare
13219 Args : Args_List (1 .. 2);
13220 Names : constant Name_List (1 .. 2) := (
13224 Task_Type : Node_Id renames Args (1);
13225 Top_Guard : Node_Id renames Args (2);
13231 Gather_Associations (Names, Args);
13233 if No (Task_Type) then
13235 ("missing task_type argument for pragma%");
13238 Check_Arg_Is_Local_Name (Task_Type);
13240 Ent := Entity (Task_Type);
13242 if not Is_Task_Type (Ent) then
13244 ("argument for pragma% must be task type", Task_Type);
13247 if No (Top_Guard) then
13249 ("pragma% takes two arguments", Task_Type);
13251 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13254 Check_First_Subtype (Task_Type);
13256 if Rep_Item_Too_Late (Ent, N) then
13265 -- pragma Test_Case ([Name =>] String_Expression
13266 -- ,[Mode =>] (Normal | Robustness)
13267 -- [, Requires => Boolean_Expression]
13268 -- [, Ensures => Boolean_Expression]);
13270 when Pragma_Test_Case => Test_Case : declare
13274 Check_At_Least_N_Arguments (3);
13275 Check_At_Most_N_Arguments (4);
13277 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13279 Check_Optional_Identifier (Arg1, Name_Name);
13280 Check_Arg_Is_String_Literal (Arg1);
13281 Check_Optional_Identifier (Arg2, Name_Mode);
13282 Check_Arg_Is_One_Of (Arg2, Name_Normal, Name_Robustness);
13283 if Arg_Count = 4 then
13284 Check_Identifier (Arg3, Name_Requires);
13285 Check_Identifier (Arg4, Name_Ensures);
13287 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13293 --------------------------
13294 -- Thread_Local_Storage --
13295 --------------------------
13297 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13299 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13305 Check_Arg_Count (1);
13306 Check_Optional_Identifier (Arg1, Name_Entity);
13307 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13309 Id := Get_Pragma_Arg (Arg1);
13312 if not Is_Entity_Name (Id)
13313 or else Ekind (Entity (Id)) /= E_Variable
13315 Error_Pragma_Arg ("local variable name required", Arg1);
13320 if Rep_Item_Too_Early (E, N)
13321 or else Rep_Item_Too_Late (E, N)
13326 Set_Has_Pragma_Thread_Local_Storage (E);
13327 Set_Has_Gigi_Rep_Item (E);
13328 end Thread_Local_Storage;
13334 -- pragma Time_Slice (static_duration_EXPRESSION);
13336 when Pragma_Time_Slice => Time_Slice : declare
13342 Check_Arg_Count (1);
13343 Check_No_Identifiers;
13344 Check_In_Main_Program;
13345 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13347 if not Error_Posted (Arg1) then
13349 while Present (Nod) loop
13350 if Nkind (Nod) = N_Pragma
13351 and then Pragma_Name (Nod) = Name_Time_Slice
13353 Error_Msg_Name_1 := Pname;
13354 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13361 -- Process only if in main unit
13363 if Get_Source_Unit (Loc) = Main_Unit then
13364 Opt.Time_Slice_Set := True;
13365 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13367 if Val <= Ureal_0 then
13368 Opt.Time_Slice_Value := 0;
13370 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13371 Opt.Time_Slice_Value := 1_000_000_000;
13374 Opt.Time_Slice_Value :=
13375 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13384 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13386 -- TITLING_OPTION ::=
13387 -- [Title =>] STRING_LITERAL
13388 -- | [Subtitle =>] STRING_LITERAL
13390 when Pragma_Title => Title : declare
13391 Args : Args_List (1 .. 2);
13392 Names : constant Name_List (1 .. 2) := (
13398 Gather_Associations (Names, Args);
13401 for J in 1 .. 2 loop
13402 if Present (Args (J)) then
13403 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13408 ---------------------
13409 -- Unchecked_Union --
13410 ---------------------
13412 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13414 when Pragma_Unchecked_Union => Unchecked_Union : declare
13415 Assoc : constant Node_Id := Arg1;
13416 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13427 Check_No_Identifiers;
13428 Check_Arg_Count (1);
13429 Check_Arg_Is_Local_Name (Arg1);
13431 Find_Type (Type_Id);
13432 Typ := Entity (Type_Id);
13435 or else Rep_Item_Too_Early (Typ, N)
13439 Typ := Underlying_Type (Typ);
13442 if Rep_Item_Too_Late (Typ, N) then
13446 Check_First_Subtype (Arg1);
13448 -- Note remaining cases are references to a type in the current
13449 -- declarative part. If we find an error, we post the error on
13450 -- the relevant type declaration at an appropriate point.
13452 if not Is_Record_Type (Typ) then
13453 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13456 elsif Is_Tagged_Type (Typ) then
13457 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13460 elsif Is_Limited_Type (Typ) then
13462 ("Unchecked_Union must not be limited record type", Typ);
13463 Explain_Limited_Type (Typ, Typ);
13467 if not Has_Discriminants (Typ) then
13469 ("Unchecked_Union must have one discriminant", Typ);
13473 Discr := First_Discriminant (Typ);
13474 while Present (Discr) loop
13475 if No (Discriminant_Default_Value (Discr)) then
13477 ("Unchecked_Union discriminant must have default value",
13481 Next_Discriminant (Discr);
13484 Tdef := Type_Definition (Declaration_Node (Typ));
13485 Clist := Component_List (Tdef);
13487 Comp := First (Component_Items (Clist));
13488 while Present (Comp) loop
13489 Check_Component (Comp, Typ);
13493 if No (Clist) or else No (Variant_Part (Clist)) then
13495 ("Unchecked_Union must have variant part",
13500 Vpart := Variant_Part (Clist);
13502 Variant := First (Variants (Vpart));
13503 while Present (Variant) loop
13504 Check_Variant (Variant, Typ);
13509 Set_Is_Unchecked_Union (Typ);
13510 Set_Convention (Typ, Convention_C);
13511 Set_Has_Unchecked_Union (Base_Type (Typ));
13512 Set_Is_Unchecked_Union (Base_Type (Typ));
13513 end Unchecked_Union;
13515 ------------------------
13516 -- Unimplemented_Unit --
13517 ------------------------
13519 -- pragma Unimplemented_Unit;
13521 -- Note: this only gives an error if we are generating code, or if
13522 -- we are in a generic library unit (where the pragma appears in the
13523 -- body, not in the spec).
13525 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13526 Cunitent : constant Entity_Id :=
13527 Cunit_Entity (Get_Source_Unit (Loc));
13528 Ent_Kind : constant Entity_Kind :=
13533 Check_Arg_Count (0);
13535 if Operating_Mode = Generate_Code
13536 or else Ent_Kind = E_Generic_Function
13537 or else Ent_Kind = E_Generic_Procedure
13538 or else Ent_Kind = E_Generic_Package
13540 Get_Name_String (Chars (Cunitent));
13541 Set_Casing (Mixed_Case);
13542 Write_Str (Name_Buffer (1 .. Name_Len));
13543 Write_Str (" is not supported in this configuration");
13545 raise Unrecoverable_Error;
13547 end Unimplemented_Unit;
13549 ------------------------
13550 -- Universal_Aliasing --
13551 ------------------------
13553 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13555 when Pragma_Universal_Aliasing => Universal_Alias : declare
13560 Check_Arg_Count (1);
13561 Check_Optional_Identifier (Arg2, Name_Entity);
13562 Check_Arg_Is_Local_Name (Arg1);
13563 E_Id := Entity (Get_Pragma_Arg (Arg1));
13565 if E_Id = Any_Type then
13567 elsif No (E_Id) or else not Is_Type (E_Id) then
13568 Error_Pragma_Arg ("pragma% requires type", Arg1);
13571 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13572 end Universal_Alias;
13574 --------------------
13575 -- Universal_Data --
13576 --------------------
13578 -- pragma Universal_Data [(library_unit_NAME)];
13580 when Pragma_Universal_Data =>
13583 -- If this is a configuration pragma, then set the universal
13584 -- addressing option, otherwise confirm that the pragma satisfies
13585 -- the requirements of library unit pragma placement and leave it
13586 -- to the GNAAMP back end to detect the pragma (avoids transitive
13587 -- setting of the option due to withed units).
13589 if Is_Configuration_Pragma then
13590 Universal_Addressing_On_AAMP := True;
13592 Check_Valid_Library_Unit_Pragma;
13595 if not AAMP_On_Target then
13596 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13603 -- pragma Unmodified (local_Name {, local_Name});
13605 when Pragma_Unmodified => Unmodified : declare
13606 Arg_Node : Node_Id;
13607 Arg_Expr : Node_Id;
13608 Arg_Ent : Entity_Id;
13612 Check_At_Least_N_Arguments (1);
13614 -- Loop through arguments
13617 while Present (Arg_Node) loop
13618 Check_No_Identifier (Arg_Node);
13620 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13621 -- in fact generate reference, so that the entity will have a
13622 -- reference, which will inhibit any warnings about it not
13623 -- being referenced, and also properly show up in the ali file
13624 -- as a reference. But this reference is recorded before the
13625 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13626 -- generated for this reference.
13628 Check_Arg_Is_Local_Name (Arg_Node);
13629 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13631 if Is_Entity_Name (Arg_Expr) then
13632 Arg_Ent := Entity (Arg_Expr);
13634 if not Is_Assignable (Arg_Ent) then
13636 ("pragma% can only be applied to a variable",
13639 Set_Has_Pragma_Unmodified (Arg_Ent);
13651 -- pragma Unreferenced (local_Name {, local_Name});
13653 -- or when used in a context clause:
13655 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13657 when Pragma_Unreferenced => Unreferenced : declare
13658 Arg_Node : Node_Id;
13659 Arg_Expr : Node_Id;
13660 Arg_Ent : Entity_Id;
13665 Check_At_Least_N_Arguments (1);
13667 -- Check case of appearing within context clause
13669 if Is_In_Context_Clause then
13671 -- The arguments must all be units mentioned in a with clause
13672 -- in the same context clause. Note we already checked (in
13673 -- Par.Prag) that the arguments are either identifiers or
13674 -- selected components.
13677 while Present (Arg_Node) loop
13678 Citem := First (List_Containing (N));
13679 while Citem /= N loop
13680 if Nkind (Citem) = N_With_Clause
13682 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13684 Set_Has_Pragma_Unreferenced
13687 (Library_Unit (Citem))));
13689 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13698 ("argument of pragma% is not with'ed unit", Arg_Node);
13704 -- Case of not in list of context items
13708 while Present (Arg_Node) loop
13709 Check_No_Identifier (Arg_Node);
13711 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13712 -- will in fact generate reference, so that the entity will
13713 -- have a reference, which will inhibit any warnings about
13714 -- it not being referenced, and also properly show up in the
13715 -- ali file as a reference. But this reference is recorded
13716 -- before the Has_Pragma_Unreferenced flag is set, so that
13717 -- no warning is generated for this reference.
13719 Check_Arg_Is_Local_Name (Arg_Node);
13720 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13722 if Is_Entity_Name (Arg_Expr) then
13723 Arg_Ent := Entity (Arg_Expr);
13725 -- If the entity is overloaded, the pragma applies to the
13726 -- most recent overloading, as documented. In this case,
13727 -- name resolution does not generate a reference, so it
13728 -- must be done here explicitly.
13730 if Is_Overloaded (Arg_Expr) then
13731 Generate_Reference (Arg_Ent, N);
13734 Set_Has_Pragma_Unreferenced (Arg_Ent);
13742 --------------------------
13743 -- Unreferenced_Objects --
13744 --------------------------
13746 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13748 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13749 Arg_Node : Node_Id;
13750 Arg_Expr : Node_Id;
13754 Check_At_Least_N_Arguments (1);
13757 while Present (Arg_Node) loop
13758 Check_No_Identifier (Arg_Node);
13759 Check_Arg_Is_Local_Name (Arg_Node);
13760 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13762 if not Is_Entity_Name (Arg_Expr)
13763 or else not Is_Type (Entity (Arg_Expr))
13766 ("argument for pragma% must be type or subtype", Arg_Node);
13769 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13772 end Unreferenced_Objects;
13774 ------------------------------
13775 -- Unreserve_All_Interrupts --
13776 ------------------------------
13778 -- pragma Unreserve_All_Interrupts;
13780 when Pragma_Unreserve_All_Interrupts =>
13782 Check_Arg_Count (0);
13784 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13785 Unreserve_All_Interrupts := True;
13792 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13794 when Pragma_Unsuppress =>
13796 Process_Suppress_Unsuppress (False);
13798 -------------------
13799 -- Use_VADS_Size --
13800 -------------------
13802 -- pragma Use_VADS_Size;
13804 when Pragma_Use_VADS_Size =>
13806 Check_Arg_Count (0);
13807 Check_Valid_Configuration_Pragma;
13808 Use_VADS_Size := True;
13810 ---------------------
13811 -- Validity_Checks --
13812 ---------------------
13814 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13816 when Pragma_Validity_Checks => Validity_Checks : declare
13817 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13823 Check_Arg_Count (1);
13824 Check_No_Identifiers;
13826 if Nkind (A) = N_String_Literal then
13830 Slen : constant Natural := Natural (String_Length (S));
13831 Options : String (1 .. Slen);
13837 C := Get_String_Char (S, Int (J));
13838 exit when not In_Character_Range (C);
13839 Options (J) := Get_Character (C);
13842 Set_Validity_Check_Options (Options);
13850 elsif Nkind (A) = N_Identifier then
13852 if Chars (A) = Name_All_Checks then
13853 Set_Validity_Check_Options ("a");
13855 elsif Chars (A) = Name_On then
13856 Validity_Checks_On := True;
13858 elsif Chars (A) = Name_Off then
13859 Validity_Checks_On := False;
13863 end Validity_Checks;
13869 -- pragma Volatile (LOCAL_NAME);
13871 when Pragma_Volatile =>
13872 Process_Atomic_Shared_Volatile;
13874 -------------------------
13875 -- Volatile_Components --
13876 -------------------------
13878 -- pragma Volatile_Components (array_LOCAL_NAME);
13880 -- Volatile is handled by the same circuit as Atomic_Components
13886 -- pragma Warnings (On | Off);
13887 -- pragma Warnings (On | Off, LOCAL_NAME);
13888 -- pragma Warnings (static_string_EXPRESSION);
13889 -- pragma Warnings (On | Off, STRING_LITERAL);
13891 when Pragma_Warnings => Warnings : begin
13893 Check_At_Least_N_Arguments (1);
13894 Check_No_Identifiers;
13896 -- If debug flag -gnatd.i is set, pragma is ignored
13898 if Debug_Flag_Dot_I then
13902 -- Process various forms of the pragma
13905 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13908 -- One argument case
13910 if Arg_Count = 1 then
13912 -- On/Off one argument case was processed by parser
13914 if Nkind (Argx) = N_Identifier
13916 (Chars (Argx) = Name_On
13918 Chars (Argx) = Name_Off)
13922 -- One argument case must be ON/OFF or static string expr
13924 elsif not Is_Static_String_Expression (Arg1) then
13926 ("argument of pragma% must be On/Off or " &
13927 "static string expression", Arg1);
13929 -- One argument string expression case
13933 Lit : constant Node_Id := Expr_Value_S (Argx);
13934 Str : constant String_Id := Strval (Lit);
13935 Len : constant Nat := String_Length (Str);
13943 while J <= Len loop
13944 C := Get_String_Char (Str, J);
13945 OK := In_Character_Range (C);
13948 Chr := Get_Character (C);
13952 if J < Len and then Chr = '.' then
13954 C := Get_String_Char (Str, J);
13955 Chr := Get_Character (C);
13957 if not Set_Dot_Warning_Switch (Chr) then
13959 ("invalid warning switch character " &
13966 OK := Set_Warning_Switch (Chr);
13972 ("invalid warning switch character " & Chr,
13981 -- Two or more arguments (must be two)
13984 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13985 Check_At_Most_N_Arguments (2);
13993 E_Id := Get_Pragma_Arg (Arg2);
13996 -- In the expansion of an inlined body, a reference to
13997 -- the formal may be wrapped in a conversion if the
13998 -- actual is a conversion. Retrieve the real entity name.
14000 if (In_Instance_Body
14001 or else In_Inlined_Body)
14002 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14004 E_Id := Expression (E_Id);
14007 -- Entity name case
14009 if Is_Entity_Name (E_Id) then
14010 E := Entity (E_Id);
14017 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14020 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14021 and then Warn_On_Warnings_Off
14023 Warnings_Off_Pragmas.Append ((N, E));
14026 if Is_Enumeration_Type (E) then
14030 Lit := First_Literal (E);
14031 while Present (Lit) loop
14032 Set_Warnings_Off (Lit);
14033 Next_Literal (Lit);
14038 exit when No (Homonym (E));
14043 -- Error if not entity or static string literal case
14045 elsif not Is_Static_String_Expression (Arg2) then
14047 ("second argument of pragma% must be entity " &
14048 "name or static string expression", Arg2);
14050 -- String literal case
14053 String_To_Name_Buffer
14054 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14056 -- Note on configuration pragma case: If this is a
14057 -- configuration pragma, then for an OFF pragma, we
14058 -- just set Config True in the call, which is all
14059 -- that needs to be done. For the case of ON, this
14060 -- is normally an error, unless it is canceling the
14061 -- effect of a previous OFF pragma in the same file.
14062 -- In any other case, an error will be signalled (ON
14063 -- with no matching OFF).
14065 if Chars (Argx) = Name_Off then
14066 Set_Specific_Warning_Off
14067 (Loc, Name_Buffer (1 .. Name_Len),
14068 Config => Is_Configuration_Pragma);
14070 elsif Chars (Argx) = Name_On then
14071 Set_Specific_Warning_On
14072 (Loc, Name_Buffer (1 .. Name_Len), Err);
14076 ("?pragma Warnings On with no " &
14077 "matching Warnings Off",
14087 -------------------
14088 -- Weak_External --
14089 -------------------
14091 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
14093 when Pragma_Weak_External => Weak_External : declare
14098 Check_Arg_Count (1);
14099 Check_Optional_Identifier (Arg1, Name_Entity);
14100 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14101 Ent := Entity (Get_Pragma_Arg (Arg1));
14103 if Rep_Item_Too_Early (Ent, N) then
14106 Ent := Underlying_Type (Ent);
14109 -- The only processing required is to link this item on to the
14110 -- list of rep items for the given entity. This is accomplished
14111 -- by the call to Rep_Item_Too_Late (when no error is detected
14112 -- and False is returned).
14114 if Rep_Item_Too_Late (Ent, N) then
14117 Set_Has_Gigi_Rep_Item (Ent);
14121 -----------------------------
14122 -- Wide_Character_Encoding --
14123 -----------------------------
14125 -- pragma Wide_Character_Encoding (IDENTIFIER);
14127 when Pragma_Wide_Character_Encoding =>
14130 -- Nothing to do, handled in parser. Note that we do not enforce
14131 -- configuration pragma placement, this pragma can appear at any
14132 -- place in the source, allowing mixed encodings within a single
14137 --------------------
14138 -- Unknown_Pragma --
14139 --------------------
14141 -- Should be impossible, since the case of an unknown pragma is
14142 -- separately processed before the case statement is entered.
14144 when Unknown_Pragma =>
14145 raise Program_Error;
14148 -- AI05-0144: detect dangerous order dependence. Disabled for now,
14149 -- until AI is formally approved.
14151 -- Check_Order_Dependence;
14154 when Pragma_Exit => null;
14155 end Analyze_Pragma;
14157 -----------------------------
14158 -- Analyze_TC_In_Decl_Part --
14159 -----------------------------
14161 procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14163 -- Install formals and push subprogram spec onto scope stack so that we
14164 -- can see the formals from the pragma.
14166 Install_Formals (S);
14169 -- Preanalyze the boolean expressions, we treat these as spec
14170 -- expressions (i.e. similar to a default expression).
14172 Preanalyze_TC_Args (Get_Requires_From_Test_Case_Pragma (N),
14173 Get_Ensures_From_Test_Case_Pragma (N));
14175 -- Remove the subprogram from the scope stack now that the pre-analysis
14176 -- of the expressions in the test-case is done.
14179 end Analyze_TC_In_Decl_Part;
14181 -------------------
14182 -- Check_Enabled --
14183 -------------------
14185 function Check_Enabled (Nam : Name_Id) return Boolean is
14189 -- Loop through entries in check policy list
14191 PP := Opt.Check_Policy_List;
14193 -- If there are no specific entries that matched, then we let the
14194 -- setting of assertions govern. Note that this provides the needed
14195 -- compatibility with the RM for the cases of assertion, invariant,
14196 -- precondition, predicate, and postcondition.
14199 return Assertions_Enabled;
14201 -- Here we have an entry see if it matches
14205 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14208 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14209 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14210 when Name_On | Name_Check =>
14212 when Name_Off | Name_Ignore =>
14215 raise Program_Error;
14219 PP := Next_Pragma (PP);
14226 ---------------------------------
14227 -- Delay_Config_Pragma_Analyze --
14228 ---------------------------------
14230 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14232 return Pragma_Name (N) = Name_Interrupt_State
14234 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14235 end Delay_Config_Pragma_Analyze;
14237 -------------------------
14238 -- Get_Base_Subprogram --
14239 -------------------------
14241 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14242 Result : Entity_Id;
14245 -- Follow subprogram renaming chain
14248 while Is_Subprogram (Result)
14250 Nkind (Parent (Declaration_Node (Result))) =
14251 N_Subprogram_Renaming_Declaration
14252 and then Present (Alias (Result))
14254 Result := Alias (Result);
14258 end Get_Base_Subprogram;
14264 procedure Initialize is
14269 -----------------------------
14270 -- Is_Config_Static_String --
14271 -----------------------------
14273 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14275 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14276 -- This is an internal recursive function that is just like the outer
14277 -- function except that it adds the string to the name buffer rather
14278 -- than placing the string in the name buffer.
14280 ------------------------------
14281 -- Add_Config_Static_String --
14282 ------------------------------
14284 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14291 if Nkind (N) = N_Op_Concat then
14292 if Add_Config_Static_String (Left_Opnd (N)) then
14293 N := Right_Opnd (N);
14299 if Nkind (N) /= N_String_Literal then
14300 Error_Msg_N ("string literal expected for pragma argument", N);
14304 for J in 1 .. String_Length (Strval (N)) loop
14305 C := Get_String_Char (Strval (N), J);
14307 if not In_Character_Range (C) then
14309 ("string literal contains invalid wide character",
14310 Sloc (N) + 1 + Source_Ptr (J));
14314 Add_Char_To_Name_Buffer (Get_Character (C));
14319 end Add_Config_Static_String;
14321 -- Start of processing for Is_Config_Static_String
14326 return Add_Config_Static_String (Arg);
14327 end Is_Config_Static_String;
14329 -----------------------------------------
14330 -- Is_Non_Significant_Pragma_Reference --
14331 -----------------------------------------
14333 -- This function makes use of the following static table which indicates
14334 -- whether a given pragma is significant.
14336 -- -1 indicates that references in any argument position are significant
14337 -- 0 indicates that appearance in any argument is not significant
14338 -- +n indicates that appearance as argument n is significant, but all
14339 -- other arguments are not significant
14340 -- 99 special processing required (e.g. for pragma Check)
14342 Sig_Flags : constant array (Pragma_Id) of Int :=
14343 (Pragma_AST_Entry => -1,
14344 Pragma_Abort_Defer => -1,
14345 Pragma_Ada_83 => -1,
14346 Pragma_Ada_95 => -1,
14347 Pragma_Ada_05 => -1,
14348 Pragma_Ada_2005 => -1,
14349 Pragma_Ada_12 => -1,
14350 Pragma_Ada_2012 => -1,
14351 Pragma_All_Calls_Remote => -1,
14352 Pragma_Annotate => -1,
14353 Pragma_Assert => -1,
14354 Pragma_Assertion_Policy => 0,
14355 Pragma_Assume_No_Invalid_Values => 0,
14356 Pragma_Asynchronous => -1,
14357 Pragma_Atomic => 0,
14358 Pragma_Atomic_Components => 0,
14359 Pragma_Attach_Handler => -1,
14360 Pragma_Check => 99,
14361 Pragma_Check_Name => 0,
14362 Pragma_Check_Policy => 0,
14363 Pragma_CIL_Constructor => -1,
14364 Pragma_CPP_Class => 0,
14365 Pragma_CPP_Constructor => 0,
14366 Pragma_CPP_Virtual => 0,
14367 Pragma_CPP_Vtable => 0,
14369 Pragma_C_Pass_By_Copy => 0,
14370 Pragma_Comment => 0,
14371 Pragma_Common_Object => -1,
14372 Pragma_Compile_Time_Error => -1,
14373 Pragma_Compile_Time_Warning => -1,
14374 Pragma_Compiler_Unit => 0,
14375 Pragma_Complete_Representation => 0,
14376 Pragma_Complex_Representation => 0,
14377 Pragma_Component_Alignment => -1,
14378 Pragma_Controlled => 0,
14379 Pragma_Convention => 0,
14380 Pragma_Convention_Identifier => 0,
14381 Pragma_Debug => -1,
14382 Pragma_Debug_Policy => 0,
14383 Pragma_Detect_Blocking => -1,
14384 Pragma_Default_Storage_Pool => -1,
14385 Pragma_Dimension => -1,
14386 Pragma_Discard_Names => 0,
14387 Pragma_Elaborate => -1,
14388 Pragma_Elaborate_All => -1,
14389 Pragma_Elaborate_Body => -1,
14390 Pragma_Elaboration_Checks => -1,
14391 Pragma_Eliminate => -1,
14392 Pragma_Export => -1,
14393 Pragma_Export_Exception => -1,
14394 Pragma_Export_Function => -1,
14395 Pragma_Export_Object => -1,
14396 Pragma_Export_Procedure => -1,
14397 Pragma_Export_Value => -1,
14398 Pragma_Export_Valued_Procedure => -1,
14399 Pragma_Extend_System => -1,
14400 Pragma_Extensions_Allowed => -1,
14401 Pragma_External => -1,
14402 Pragma_Favor_Top_Level => -1,
14403 Pragma_External_Name_Casing => -1,
14404 Pragma_Fast_Math => -1,
14405 Pragma_Finalize_Storage_Only => 0,
14406 Pragma_Float_Representation => 0,
14407 Pragma_Ident => -1,
14408 Pragma_Implemented => -1,
14409 Pragma_Implicit_Packing => 0,
14410 Pragma_Import => +2,
14411 Pragma_Import_Exception => 0,
14412 Pragma_Import_Function => 0,
14413 Pragma_Import_Object => 0,
14414 Pragma_Import_Procedure => 0,
14415 Pragma_Import_Valued_Procedure => 0,
14416 Pragma_Independent => 0,
14417 Pragma_Independent_Components => 0,
14418 Pragma_Initialize_Scalars => -1,
14419 Pragma_Inline => 0,
14420 Pragma_Inline_Always => 0,
14421 Pragma_Inline_Generic => 0,
14422 Pragma_Inspection_Point => -1,
14423 Pragma_Interface => +2,
14424 Pragma_Interface_Name => +2,
14425 Pragma_Interrupt_Handler => -1,
14426 Pragma_Interrupt_Priority => -1,
14427 Pragma_Interrupt_State => -1,
14428 Pragma_Invariant => -1,
14429 Pragma_Java_Constructor => -1,
14430 Pragma_Java_Interface => -1,
14431 Pragma_Keep_Names => 0,
14432 Pragma_License => -1,
14433 Pragma_Link_With => -1,
14434 Pragma_Linker_Alias => -1,
14435 Pragma_Linker_Constructor => -1,
14436 Pragma_Linker_Destructor => -1,
14437 Pragma_Linker_Options => -1,
14438 Pragma_Linker_Section => -1,
14440 Pragma_Locking_Policy => -1,
14441 Pragma_Long_Float => -1,
14442 Pragma_Machine_Attribute => -1,
14444 Pragma_Main_Storage => -1,
14445 Pragma_Memory_Size => -1,
14446 Pragma_No_Return => 0,
14447 Pragma_No_Body => 0,
14448 Pragma_No_Run_Time => -1,
14449 Pragma_No_Strict_Aliasing => -1,
14450 Pragma_Normalize_Scalars => -1,
14451 Pragma_Obsolescent => 0,
14452 Pragma_Optimize => -1,
14453 Pragma_Optimize_Alignment => -1,
14454 Pragma_Ordered => 0,
14457 Pragma_Passive => -1,
14458 Pragma_Preelaborable_Initialization => -1,
14459 Pragma_Polling => -1,
14460 Pragma_Persistent_BSS => 0,
14461 Pragma_Postcondition => -1,
14462 Pragma_Precondition => -1,
14463 Pragma_Predicate => -1,
14464 Pragma_Preelaborate => -1,
14465 Pragma_Preelaborate_05 => -1,
14466 Pragma_Priority => -1,
14467 Pragma_Priority_Specific_Dispatching => -1,
14468 Pragma_Profile => 0,
14469 Pragma_Profile_Warnings => 0,
14470 Pragma_Propagate_Exceptions => -1,
14471 Pragma_Psect_Object => -1,
14473 Pragma_Pure_05 => -1,
14474 Pragma_Pure_Function => -1,
14475 Pragma_Queuing_Policy => -1,
14476 Pragma_Ravenscar => -1,
14477 Pragma_Relative_Deadline => -1,
14478 Pragma_Remote_Call_Interface => -1,
14479 Pragma_Remote_Types => -1,
14480 Pragma_Restricted_Run_Time => -1,
14481 Pragma_Restriction_Warnings => -1,
14482 Pragma_Restrictions => -1,
14483 Pragma_Reviewable => -1,
14484 Pragma_Short_Circuit_And_Or => -1,
14485 Pragma_Share_Generic => -1,
14486 Pragma_Shared => -1,
14487 Pragma_Shared_Passive => -1,
14488 Pragma_Short_Descriptors => 0,
14489 Pragma_Source_File_Name => -1,
14490 Pragma_Source_File_Name_Project => -1,
14491 Pragma_Source_Reference => -1,
14492 Pragma_Storage_Size => -1,
14493 Pragma_Storage_Unit => -1,
14494 Pragma_Static_Elaboration_Desired => -1,
14495 Pragma_Stream_Convert => -1,
14496 Pragma_Style_Checks => -1,
14497 Pragma_Subtitle => -1,
14498 Pragma_Suppress => 0,
14499 Pragma_Suppress_Exception_Locations => 0,
14500 Pragma_Suppress_All => -1,
14501 Pragma_Suppress_Debug_Info => 0,
14502 Pragma_Suppress_Initialization => 0,
14503 Pragma_System_Name => -1,
14504 Pragma_Task_Dispatching_Policy => -1,
14505 Pragma_Task_Info => -1,
14506 Pragma_Task_Name => -1,
14507 Pragma_Task_Storage => 0,
14508 Pragma_Test_Case => -1,
14509 Pragma_Thread_Local_Storage => 0,
14510 Pragma_Time_Slice => -1,
14511 Pragma_Title => -1,
14512 Pragma_Unchecked_Union => 0,
14513 Pragma_Unimplemented_Unit => -1,
14514 Pragma_Universal_Aliasing => -1,
14515 Pragma_Universal_Data => -1,
14516 Pragma_Unmodified => -1,
14517 Pragma_Unreferenced => -1,
14518 Pragma_Unreferenced_Objects => -1,
14519 Pragma_Unreserve_All_Interrupts => -1,
14520 Pragma_Unsuppress => 0,
14521 Pragma_Use_VADS_Size => -1,
14522 Pragma_Validity_Checks => -1,
14523 Pragma_Volatile => 0,
14524 Pragma_Volatile_Components => 0,
14525 Pragma_Warnings => -1,
14526 Pragma_Weak_External => -1,
14527 Pragma_Wide_Character_Encoding => 0,
14528 Unknown_Pragma => 0);
14530 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14539 if Nkind (P) /= N_Pragma_Argument_Association then
14543 Id := Get_Pragma_Id (Parent (P));
14544 C := Sig_Flags (Id);
14556 -- For pragma Check, the first argument is not significant,
14557 -- the second and the third (if present) arguments are
14560 when Pragma_Check =>
14562 P = First (Pragma_Argument_Associations (Parent (P)));
14565 raise Program_Error;
14569 A := First (Pragma_Argument_Associations (Parent (P)));
14570 for J in 1 .. C - 1 loop
14578 return A = P; -- is this wrong way round ???
14581 end Is_Non_Significant_Pragma_Reference;
14583 ------------------------------
14584 -- Is_Pragma_String_Literal --
14585 ------------------------------
14587 -- This function returns true if the corresponding pragma argument is a
14588 -- static string expression. These are the only cases in which string
14589 -- literals can appear as pragma arguments. We also allow a string literal
14590 -- as the first argument to pragma Assert (although it will of course
14591 -- always generate a type error).
14593 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14594 Pragn : constant Node_Id := Parent (Par);
14595 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14596 Pname : constant Name_Id := Pragma_Name (Pragn);
14602 N := First (Assoc);
14609 if Pname = Name_Assert then
14612 elsif Pname = Name_Export then
14615 elsif Pname = Name_Ident then
14618 elsif Pname = Name_Import then
14621 elsif Pname = Name_Interface_Name then
14624 elsif Pname = Name_Linker_Alias then
14627 elsif Pname = Name_Linker_Section then
14630 elsif Pname = Name_Machine_Attribute then
14633 elsif Pname = Name_Source_File_Name then
14636 elsif Pname = Name_Source_Reference then
14639 elsif Pname = Name_Title then
14642 elsif Pname = Name_Subtitle then
14648 end Is_Pragma_String_Literal;
14650 ------------------------
14651 -- Preanalyze_TC_Args --
14652 ------------------------
14654 procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id) is
14656 -- Preanalyze the boolean expressions, we treat these as spec
14657 -- expressions (i.e. similar to a default expression).
14659 if Present (Arg_Req) then
14660 Preanalyze_Spec_Expression
14661 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
14664 if Present (Arg_Ens) then
14665 Preanalyze_Spec_Expression
14666 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
14668 end Preanalyze_TC_Args;
14670 --------------------------------------
14671 -- Process_Compilation_Unit_Pragmas --
14672 --------------------------------------
14674 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14676 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14677 -- strange because it comes at the end of the unit. Rational has the
14678 -- same name for a pragma, but treats it as a program unit pragma, In
14679 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14680 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14681 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14682 -- the context clause to ensure the correct processing.
14684 if Has_Pragma_Suppress_All (N) then
14685 Prepend_To (Context_Items (N),
14686 Make_Pragma (Sloc (N),
14687 Chars => Name_Suppress,
14688 Pragma_Argument_Associations => New_List (
14689 Make_Pragma_Argument_Association (Sloc (N),
14690 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14693 -- Nothing else to do at the current time!
14695 end Process_Compilation_Unit_Pragmas;
14706 --------------------------------
14707 -- Set_Encoded_Interface_Name --
14708 --------------------------------
14710 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14711 Str : constant String_Id := Strval (S);
14712 Len : constant Int := String_Length (Str);
14717 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14720 -- Stores encoded value of character code CC. The encoding we use an
14721 -- underscore followed by four lower case hex digits.
14727 procedure Encode is
14729 Store_String_Char (Get_Char_Code ('_'));
14731 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14733 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14735 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14737 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14740 -- Start of processing for Set_Encoded_Interface_Name
14743 -- If first character is asterisk, this is a link name, and we leave it
14744 -- completely unmodified. We also ignore null strings (the latter case
14745 -- happens only in error cases) and no encoding should occur for Java or
14746 -- AAMP interface names.
14749 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14750 or else VM_Target /= No_VM
14751 or else AAMP_On_Target
14753 Set_Interface_Name (E, S);
14758 CC := Get_String_Char (Str, J);
14760 exit when not In_Character_Range (CC);
14762 C := Get_Character (CC);
14764 exit when C /= '_' and then C /= '$'
14765 and then C not in '0' .. '9'
14766 and then C not in 'a' .. 'z'
14767 and then C not in 'A' .. 'Z';
14770 Set_Interface_Name (E, S);
14778 -- Here we need to encode. The encoding we use as follows:
14779 -- three underscores + four hex digits (lower case)
14783 for J in 1 .. String_Length (Str) loop
14784 CC := Get_String_Char (Str, J);
14786 if not In_Character_Range (CC) then
14789 C := Get_Character (CC);
14791 if C = '_' or else C = '$'
14792 or else C in '0' .. '9'
14793 or else C in 'a' .. 'z'
14794 or else C in 'A' .. 'Z'
14796 Store_String_Char (CC);
14803 Set_Interface_Name (E,
14804 Make_String_Literal (Sloc (S),
14805 Strval => End_String));
14807 end Set_Encoded_Interface_Name;
14809 -------------------
14810 -- Set_Unit_Name --
14811 -------------------
14813 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14818 if Nkind (N) = N_Identifier
14819 and then Nkind (With_Item) = N_Identifier
14821 Set_Entity (N, Entity (With_Item));
14823 elsif Nkind (N) = N_Selected_Component then
14824 Change_Selected_Component_To_Expanded_Name (N);
14825 Set_Entity (N, Entity (With_Item));
14826 Set_Entity (Selector_Name (N), Entity (N));
14828 Pref := Prefix (N);
14829 Scop := Scope (Entity (N));
14830 while Nkind (Pref) = N_Selected_Component loop
14831 Change_Selected_Component_To_Expanded_Name (Pref);
14832 Set_Entity (Selector_Name (Pref), Scop);
14833 Set_Entity (Pref, Scop);
14834 Pref := Prefix (Pref);
14835 Scop := Scope (Scop);
14838 Set_Entity (Pref, Scop);