1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
32 with Atree; use Atree;
33 with Casing; use Casing;
34 with Checks; use Checks;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with Elists; use Elists;
39 with Errout; use Errout;
40 with Exp_Ch7; use Exp_Ch7;
41 with Exp_Dist; use Exp_Dist;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref; use Lib.Xref;
45 with Namet.Sp; use Namet.Sp;
46 with Nlists; use Nlists;
47 with Nmake; use Nmake;
49 with Output; use Output;
50 with Par_SCO; use Par_SCO;
51 with Restrict; use Restrict;
52 with Rident; use Rident;
53 with Rtsfind; use Rtsfind;
55 with Sem_Aux; use Sem_Aux;
56 with Sem_Ch3; use Sem_Ch3;
57 with Sem_Ch6; use Sem_Ch6;
58 with Sem_Ch8; use Sem_Ch8;
59 with Sem_Ch12; use Sem_Ch12;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Dist; use Sem_Dist;
62 with Sem_Elim; use Sem_Elim;
63 with Sem_Eval; use Sem_Eval;
64 with Sem_Intr; use Sem_Intr;
65 with Sem_Mech; use Sem_Mech;
66 with Sem_Res; use Sem_Res;
67 with Sem_Type; use Sem_Type;
68 with Sem_Util; use Sem_Util;
69 with Sem_VFpt; use Sem_VFpt;
70 with Sem_Warn; use Sem_Warn;
71 with Stand; use Stand;
72 with Sinfo; use Sinfo;
73 with Sinfo.CN; use Sinfo.CN;
74 with Sinput; use Sinput;
75 with Snames; use Snames;
76 with Stringt; use Stringt;
77 with Stylesw; use Stylesw;
79 with Targparm; use Targparm;
80 with Tbuild; use Tbuild;
82 with Uintp; use Uintp;
83 with Uname; use Uname;
84 with Urealp; use Urealp;
85 with Validsw; use Validsw;
87 package body Sem_Prag is
89 ----------------------------------------------
90 -- Common Handling of Import-Export Pragmas --
91 ----------------------------------------------
93 -- In the following section, a number of Import_xxx and Export_xxx
94 -- pragmas are defined by GNAT. These are compatible with the DEC
95 -- pragmas of the same name, and all have the following common
96 -- form and processing:
99 -- [Internal =>] LOCAL_NAME
100 -- [, [External =>] EXTERNAL_SYMBOL]
101 -- [, other optional parameters ]);
104 -- [Internal =>] LOCAL_NAME
105 -- [, [External =>] EXTERNAL_SYMBOL]
106 -- [, other optional parameters ]);
108 -- EXTERNAL_SYMBOL ::=
110 -- | static_string_EXPRESSION
112 -- The internal LOCAL_NAME designates the entity that is imported or
113 -- exported, and must refer to an entity in the current declarative
114 -- part (as required by the rules for LOCAL_NAME).
116 -- The external linker name is designated by the External parameter if
117 -- given, or the Internal parameter if not (if there is no External
118 -- parameter, the External parameter is a copy of the Internal name).
120 -- If the External parameter is given as a string, then this string is
121 -- treated as an external name (exactly as though it had been given as an
122 -- External_Name parameter for a normal Import pragma).
124 -- If the External parameter is given as an identifier (or there is no
125 -- External parameter, so that the Internal identifier is used), then
126 -- the external name is the characters of the identifier, translated
127 -- to all upper case letters for OpenVMS versions of GNAT, and to all
128 -- lower case letters for all other versions
130 -- Note: the external name specified or implied by any of these special
131 -- Import_xxx or Export_xxx pragmas override an external or link name
132 -- specified in a previous Import or Export pragma.
134 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
135 -- named notation, following the standard rules for subprogram calls, i.e.
136 -- parameters can be given in any order if named notation is used, and
137 -- positional and named notation can be mixed, subject to the rule that all
138 -- positional parameters must appear first.
140 -- Note: All these pragmas are implemented exactly following the DEC design
141 -- and implementation and are intended to be fully compatible with the use
142 -- of these pragmas in the DEC Ada compiler.
144 --------------------------------------------
145 -- Checking for Duplicated External Names --
146 --------------------------------------------
148 -- It is suspicious if two separate Export pragmas use the same external
149 -- name. The following table is used to diagnose this situation so that
150 -- an appropriate warning can be issued.
152 -- The Node_Id stored is for the N_String_Literal node created to hold
153 -- the value of the external name. The Sloc of this node is used to
154 -- cross-reference the location of the duplication.
156 package Externals is new Table.Table (
157 Table_Component_Type => Node_Id,
158 Table_Index_Type => Int,
159 Table_Low_Bound => 0,
160 Table_Initial => 100,
161 Table_Increment => 100,
162 Table_Name => "Name_Externals");
164 -------------------------------------
165 -- Local Subprograms and Variables --
166 -------------------------------------
168 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
169 -- This routine is used for possible casing adjustment of an explicit
170 -- external name supplied as a string literal (the node N), according to
171 -- the casing requirement of Opt.External_Name_Casing. If this is set to
172 -- As_Is, then the string literal is returned unchanged, but if it is set
173 -- to Uppercase or Lowercase, then a new string literal with appropriate
174 -- casing is constructed.
176 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
177 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
178 -- original one, following the renaming chain) is returned. Otherwise the
179 -- entity is returned unchanged. Should be in Einfo???
182 -- This is a dummy function called by the processing for pragma Reviewable.
183 -- It is there for assisting front end debugging. By placing a Reviewable
184 -- pragma in the source program, a breakpoint on rv catches this place in
185 -- the source, allowing convenient stepping to the point of interest.
187 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
188 -- Place semantic information on the argument of an Elaborate/Elaborate_All
189 -- pragma. Entity name for unit and its parents is taken from item in
190 -- previous with_clause that mentions the unit.
192 -------------------------------
193 -- Adjust_External_Name_Case --
194 -------------------------------
196 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
200 -- Adjust case of literal if required
202 if Opt.External_Name_Exp_Casing = As_Is then
206 -- Copy existing string
212 for J in 1 .. String_Length (Strval (N)) loop
213 CC := Get_String_Char (Strval (N), J);
215 if Opt.External_Name_Exp_Casing = Uppercase
216 and then CC >= Get_Char_Code ('a')
217 and then CC <= Get_Char_Code ('z')
219 Store_String_Char (CC - 32);
221 elsif Opt.External_Name_Exp_Casing = Lowercase
222 and then CC >= Get_Char_Code ('A')
223 and then CC <= Get_Char_Code ('Z')
225 Store_String_Char (CC + 32);
228 Store_String_Char (CC);
233 Make_String_Literal (Sloc (N),
234 Strval => End_String);
236 end Adjust_External_Name_Case;
238 ------------------------------
239 -- Analyze_PPC_In_Decl_Part --
240 ------------------------------
242 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
243 Arg1 : constant Node_Id :=
244 First (Pragma_Argument_Associations (N));
245 Arg2 : constant Node_Id := Next (Arg1);
248 -- Install formals and push subprogram spec onto scope stack so that we
249 -- can see the formals from the pragma.
254 -- Preanalyze the boolean expression, we treat this as a spec expression
255 -- (i.e. similar to a default expression).
257 Preanalyze_Spec_Expression
258 (Get_Pragma_Arg (Arg1), Standard_Boolean);
260 -- If there is a message argument, analyze it the same way
262 if Present (Arg2) then
263 Preanalyze_Spec_Expression
264 (Get_Pragma_Arg (Arg2), Standard_String);
267 -- Remove the subprogram from the scope stack now that the pre-analysis
268 -- of the precondition/postcondition is done.
271 end Analyze_PPC_In_Decl_Part;
277 procedure Analyze_Pragma (N : Node_Id) is
278 Loc : constant Source_Ptr := Sloc (N);
279 Pname : constant Name_Id := Pragma_Name (N);
282 Sense : constant Boolean := not Aspect_Cancel (N);
283 -- Sense is True if we have the normal case of a pragma that is active
284 -- and turns the corresponding aspect on. It is false only for the case
285 -- of a pragma coming from an aspect which is explicitly turned off by
286 -- using aspect => False. If Sense is False, the effect of the pragma
287 -- is to turn the corresponding aspect off.
289 Pragma_Exit : exception;
290 -- This exception is used to exit pragma processing completely. It is
291 -- used when an error is detected, and no further processing is
292 -- required. It is also used if an earlier error has left the tree in
293 -- a state where the pragma should not be processed.
296 -- Number of pragma argument associations
302 -- First four pragma arguments (pragma argument association nodes, or
303 -- Empty if the corresponding argument does not exist).
305 type Name_List is array (Natural range <>) of Name_Id;
306 type Args_List is array (Natural range <>) of Node_Id;
307 -- Types used for arguments to Check_Arg_Order and Gather_Associations
309 procedure Ada_2005_Pragma;
310 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
311 -- Ada 95 mode, these are implementation defined pragmas, so should be
312 -- caught by the No_Implementation_Pragmas restriction.
314 procedure Ada_2012_Pragma;
315 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
316 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
317 -- should be caught by the No_Implementation_Pragmas restriction.
319 procedure Check_Ada_83_Warning;
320 -- Issues a warning message for the current pragma if operating in Ada
321 -- 83 mode (used for language pragmas that are not a standard part of
322 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
325 procedure Check_Arg_Count (Required : Nat);
326 -- Check argument count for pragma is equal to given parameter. If not,
327 -- then issue an error message and raise Pragma_Exit.
329 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
330 -- Arg which can either be a pragma argument association, in which case
331 -- the check is applied to the expression of the association or an
332 -- expression directly.
334 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
335 -- Check that an argument has the right form for an EXTERNAL_NAME
336 -- parameter of an extended import/export pragma. The rule is that the
337 -- name must be an identifier or string literal (in Ada 83 mode) or a
338 -- static string expression (in Ada 95 mode).
340 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
341 -- Check the specified argument Arg to make sure that it is an
342 -- identifier. If not give error and raise Pragma_Exit.
344 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
345 -- Check the specified argument Arg to make sure that it is an integer
346 -- literal. If not give error and raise Pragma_Exit.
348 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
349 -- Check the specified argument Arg to make sure that it has the proper
350 -- syntactic form for a local name and meets the semantic requirements
351 -- for a local name. The local name is analyzed as part of the
352 -- processing for this call. In addition, the local name is required
353 -- to represent an entity at the library level.
355 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
356 -- Check the specified argument Arg to make sure that it has the proper
357 -- syntactic form for a local name and meets the semantic requirements
358 -- for a local name. The local name is analyzed as part of the
359 -- processing for this call.
361 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
362 -- Check the specified argument Arg to make sure that it is a valid
363 -- locking policy name. If not give error and raise Pragma_Exit.
365 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
366 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
367 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
368 -- Check the specified argument Arg to make sure that it is an
369 -- identifier whose name matches either N1 or N2 (or N3 if present).
370 -- If not then give error and raise Pragma_Exit.
372 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
373 -- Check the specified argument Arg to make sure that it is a valid
374 -- queuing policy name. If not give error and raise Pragma_Exit.
376 procedure Check_Arg_Is_Static_Expression
378 Typ : Entity_Id := Empty);
379 -- Check the specified argument Arg to make sure that it is a static
380 -- expression of the given type (i.e. it will be analyzed and resolved
381 -- using this type, which can be any valid argument to Resolve, e.g.
382 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
383 -- Typ is left Empty, then any static expression is allowed.
385 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
386 -- Check the specified argument Arg to make sure that it is a valid task
387 -- dispatching policy name. If not give error and raise Pragma_Exit.
389 procedure Check_Arg_Order (Names : Name_List);
390 -- Checks for an instance of two arguments with identifiers for the
391 -- current pragma which are not in the sequence indicated by Names,
392 -- and if so, generates a fatal message about bad order of arguments.
394 procedure Check_At_Least_N_Arguments (N : Nat);
395 -- Check there are at least N arguments present
397 procedure Check_At_Most_N_Arguments (N : Nat);
398 -- Check there are no more than N arguments present
400 procedure Check_Component
403 In_Variant_Part : Boolean := False);
404 -- Examine an Unchecked_Union component for correct use of per-object
405 -- constrained subtypes, and for restrictions on finalizable components.
406 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
407 -- should be set when Comp comes from a record variant.
409 procedure Check_Duplicate_Pragma (E : Entity_Id);
410 -- Check if a pragma of the same name as the current pragma is already
411 -- chained as a rep pragma to the given entity. If so give a message
412 -- about the duplicate, and then raise Pragma_Exit so does not return.
413 -- Also checks for delayed aspect specification node in the chain.
415 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
416 -- Nam is an N_String_Literal node containing the external name set by
417 -- an Import or Export pragma (or extended Import or Export pragma).
418 -- This procedure checks for possible duplications if this is the export
419 -- case, and if found, issues an appropriate error message.
421 procedure Check_First_Subtype (Arg : Node_Id);
422 -- Checks that Arg, whose expression is an entity name referencing a
423 -- subtype, does not reference a type that is not a first subtype.
425 procedure Check_In_Main_Program;
426 -- Common checks for pragmas that appear within a main program
427 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline).
429 procedure Check_Interrupt_Or_Attach_Handler;
430 -- Common processing for first argument of pragma Interrupt_Handler or
431 -- pragma Attach_Handler.
433 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
434 -- Check that pragma appears in a declarative part, or in a package
435 -- specification, i.e. that it does not occur in a statement sequence
438 procedure Check_No_Identifier (Arg : Node_Id);
439 -- Checks that the given argument does not have an identifier. If
440 -- an identifier is present, then an error message is issued, and
441 -- Pragma_Exit is raised.
443 procedure Check_No_Identifiers;
444 -- Checks that none of the arguments to the pragma has an identifier.
445 -- If any argument has an identifier, then an error message is issued,
446 -- and Pragma_Exit is raised.
448 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
449 -- Checks if the given argument has an identifier, and if so, requires
450 -- it to match the given identifier name. If there is a non-matching
451 -- identifier, then an error message is given and Error_Pragmas raised.
453 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
454 -- Checks if the given argument has an identifier, and if so, requires
455 -- it to match the given identifier name. If there is a non-matching
456 -- identifier, then an error message is given and Error_Pragmas raised.
457 -- In this version of the procedure, the identifier name is given as
458 -- a string with lower case letters.
460 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
461 -- Called to process a precondition or postcondition pragma. There are
464 -- The pragma appears after a subprogram spec
466 -- If the corresponding check is not enabled, the pragma is analyzed
467 -- but otherwise ignored and control returns with In_Body set False.
469 -- If the check is enabled, then the first step is to analyze the
470 -- pragma, but this is skipped if the subprogram spec appears within
471 -- a package specification (because this is the case where we delay
472 -- analysis till the end of the spec). Then (whether or not it was
473 -- analyzed), the pragma is chained to the subprogram in question
474 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
475 -- caller with In_Body set False.
477 -- The pragma appears at the start of subprogram body declarations
479 -- In this case an immediate return to the caller is made with
480 -- In_Body set True, and the pragma is NOT analyzed.
482 -- In all other cases, an error message for bad placement is given
484 procedure Check_Static_Constraint (Constr : Node_Id);
485 -- Constr is a constraint from an N_Subtype_Indication node from a
486 -- component constraint in an Unchecked_Union type. This routine checks
487 -- that the constraint is static as required by the restrictions for
490 procedure Check_Valid_Configuration_Pragma;
491 -- Legality checks for placement of a configuration pragma
493 procedure Check_Valid_Library_Unit_Pragma;
494 -- Legality checks for library unit pragmas. A special case arises for
495 -- pragmas in generic instances that come from copies of the original
496 -- library unit pragmas in the generic templates. In the case of other
497 -- than library level instantiations these can appear in contexts which
498 -- would normally be invalid (they only apply to the original template
499 -- and to library level instantiations), and they are simply ignored,
500 -- which is implemented by rewriting them as null statements.
502 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
503 -- Check an Unchecked_Union variant for lack of nested variants and
504 -- presence of at least one component. UU_Typ is the related Unchecked_
507 procedure Error_Pragma (Msg : String);
508 pragma No_Return (Error_Pragma);
509 -- Outputs error message for current pragma. The message contains a %
510 -- that will be replaced with the pragma name, and the flag is placed
511 -- on the pragma itself. Pragma_Exit is then raised.
513 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
514 pragma No_Return (Error_Pragma_Arg);
515 -- Outputs error message for current pragma. The message may contain
516 -- a % that will be replaced with the pragma name. The parameter Arg
517 -- may either be a pragma argument association, in which case the flag
518 -- is placed on the expression of this association, or an expression,
519 -- in which case the flag is placed directly on the expression. The
520 -- message is placed using Error_Msg_N, so the message may also contain
521 -- an & insertion character which will reference the given Arg value.
522 -- After placing the message, Pragma_Exit is raised.
524 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
525 pragma No_Return (Error_Pragma_Arg);
526 -- Similar to above form of Error_Pragma_Arg except that two messages
527 -- are provided, the second is a continuation comment starting with \.
529 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
530 pragma No_Return (Error_Pragma_Arg_Ident);
531 -- Outputs error message for current pragma. The message may contain
532 -- a % that will be replaced with the pragma name. The parameter Arg
533 -- must be a pragma argument association with a non-empty identifier
534 -- (i.e. its Chars field must be set), and the error message is placed
535 -- on the identifier. The message is placed using Error_Msg_N so
536 -- the message may also contain an & insertion character which will
537 -- reference the identifier. After placing the message, Pragma_Exit
540 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
541 pragma No_Return (Error_Pragma_Ref);
542 -- Outputs error message for current pragma. The message may contain
543 -- a % that will be replaced with the pragma name. The parameter Ref
544 -- must be an entity whose name can be referenced by & and sloc by #.
545 -- After placing the message, Pragma_Exit is raised.
547 function Find_Lib_Unit_Name return Entity_Id;
548 -- Used for a library unit pragma to find the entity to which the
549 -- library unit pragma applies, returns the entity found.
551 procedure Find_Program_Unit_Name (Id : Node_Id);
552 -- If the pragma is a compilation unit pragma, the id must denote the
553 -- compilation unit in the same compilation, and the pragma must appear
554 -- in the list of preceding or trailing pragmas. If it is a program
555 -- unit pragma that is not a compilation unit pragma, then the
556 -- identifier must be visible.
558 function Find_Unique_Parameterless_Procedure
560 Arg : Node_Id) return Entity_Id;
561 -- Used for a procedure pragma to find the unique parameterless
562 -- procedure identified by Name, returns it if it exists, otherwise
563 -- errors out and uses Arg as the pragma argument for the message.
565 procedure Fix_Error (Msg : in out String);
566 -- This is called prior to issuing an error message. Msg is a string
567 -- which typically contains the substring pragma. If the current pragma
568 -- comes from an aspect, each such "pragma" substring is replaced with
569 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
570 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
572 procedure Gather_Associations
574 Args : out Args_List);
575 -- This procedure is used to gather the arguments for a pragma that
576 -- permits arbitrary ordering of parameters using the normal rules
577 -- for named and positional parameters. The Names argument is a list
578 -- of Name_Id values that corresponds to the allowed pragma argument
579 -- association identifiers in order. The result returned in Args is
580 -- a list of corresponding expressions that are the pragma arguments.
581 -- Note that this is a list of expressions, not of pragma argument
582 -- associations (Gather_Associations has completely checked all the
583 -- optional identifiers when it returns). An entry in Args is Empty
584 -- on return if the corresponding argument is not present.
586 procedure GNAT_Pragma;
587 -- Called for all GNAT defined pragmas to check the relevant restriction
588 -- (No_Implementation_Pragmas).
590 function Is_Before_First_Decl
591 (Pragma_Node : Node_Id;
592 Decls : List_Id) return Boolean;
593 -- Return True if Pragma_Node is before the first declarative item in
594 -- Decls where Decls is the list of declarative items.
596 function Is_Configuration_Pragma return Boolean;
597 -- Determines if the placement of the current pragma is appropriate
598 -- for a configuration pragma.
600 function Is_In_Context_Clause return Boolean;
601 -- Returns True if pragma appears within the context clause of a unit,
602 -- and False for any other placement (does not generate any messages).
604 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
605 -- Analyzes the argument, and determines if it is a static string
606 -- expression, returns True if so, False if non-static or not String.
608 procedure Pragma_Misplaced;
609 pragma No_Return (Pragma_Misplaced);
610 -- Issue fatal error message for misplaced pragma
612 procedure Process_Atomic_Shared_Volatile;
613 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
614 -- Shared is an obsolete Ada 83 pragma, treated as being identical
615 -- in effect to pragma Atomic.
617 procedure Process_Compile_Time_Warning_Or_Error;
618 -- Common processing for Compile_Time_Error and Compile_Time_Warning
620 procedure Process_Convention
621 (C : out Convention_Id;
622 Ent : out Entity_Id);
623 -- Common processing for Convention, Interface, Import and Export.
624 -- Checks first two arguments of pragma, and sets the appropriate
625 -- convention value in the specified entity or entities. On return
626 -- C is the convention, Ent is the referenced entity.
628 procedure Process_Extended_Import_Export_Exception_Pragma
629 (Arg_Internal : Node_Id;
630 Arg_External : Node_Id;
633 -- Common processing for the pragmas Import/Export_Exception. The three
634 -- arguments correspond to the three named parameters of the pragma. An
635 -- argument is empty if the corresponding parameter is not present in
638 procedure Process_Extended_Import_Export_Object_Pragma
639 (Arg_Internal : Node_Id;
640 Arg_External : Node_Id;
642 -- Common processing for the pragmas Import/Export_Object. The three
643 -- arguments correspond to the three named parameters of the pragmas. An
644 -- argument is empty if the corresponding parameter is not present in
647 procedure Process_Extended_Import_Export_Internal_Arg
648 (Arg_Internal : Node_Id := Empty);
649 -- Common processing for all extended Import and Export pragmas. The
650 -- argument is the pragma parameter for the Internal argument. If
651 -- Arg_Internal is empty or inappropriate, an error message is posted.
652 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
653 -- set to identify the referenced entity.
655 procedure Process_Extended_Import_Export_Subprogram_Pragma
656 (Arg_Internal : Node_Id;
657 Arg_External : Node_Id;
658 Arg_Parameter_Types : Node_Id;
659 Arg_Result_Type : Node_Id := Empty;
660 Arg_Mechanism : Node_Id;
661 Arg_Result_Mechanism : Node_Id := Empty;
662 Arg_First_Optional_Parameter : Node_Id := Empty);
663 -- Common processing for all extended Import and Export pragmas applying
664 -- to subprograms. The caller omits any arguments that do not apply to
665 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
666 -- only in the Import_Function and Export_Function cases). The argument
667 -- names correspond to the allowed pragma association identifiers.
669 procedure Process_Generic_List;
670 -- Common processing for Share_Generic and Inline_Generic
672 procedure Process_Import_Or_Interface;
673 -- Common processing for Import of Interface
675 procedure Process_Inline (Active : Boolean);
676 -- Common processing for Inline and Inline_Always. The parameter
677 -- indicates if the inline pragma is active, i.e. if it should actually
678 -- cause inlining to occur.
680 procedure Process_Interface_Name
681 (Subprogram_Def : Entity_Id;
684 -- Given the last two arguments of pragma Import, pragma Export, or
685 -- pragma Interface_Name, performs validity checks and sets the
686 -- Interface_Name field of the given subprogram entity to the
687 -- appropriate external or link name, depending on the arguments given.
688 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
689 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
690 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
691 -- nor Link_Arg is present, the interface name is set to the default
692 -- from the subprogram name.
694 procedure Process_Interrupt_Or_Attach_Handler;
695 -- Common processing for Interrupt and Attach_Handler pragmas
697 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
698 -- Common processing for Restrictions and Restriction_Warnings pragmas.
699 -- Warn is True for Restriction_Warnings, or for Restrictions if the
700 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
701 -- is not set in the Restrictions case.
703 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
704 -- Common processing for Suppress and Unsuppress. The boolean parameter
705 -- Suppress_Case is True for the Suppress case, and False for the
708 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
709 -- This procedure sets the Is_Exported flag for the given entity,
710 -- checking that the entity was not previously imported. Arg is
711 -- the argument that specified the entity. A check is also made
712 -- for exporting inappropriate entities.
714 procedure Set_Extended_Import_Export_External_Name
715 (Internal_Ent : Entity_Id;
716 Arg_External : Node_Id);
717 -- Common processing for all extended import export pragmas. The first
718 -- argument, Internal_Ent, is the internal entity, which has already
719 -- been checked for validity by the caller. Arg_External is from the
720 -- Import or Export pragma, and may be null if no External parameter
721 -- was present. If Arg_External is present and is a non-null string
722 -- (a null string is treated as the default), then the Interface_Name
723 -- field of Internal_Ent is set appropriately.
725 procedure Set_Imported (E : Entity_Id);
726 -- This procedure sets the Is_Imported flag for the given entity,
727 -- checking that it is not previously exported or imported.
729 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
730 -- Mech is a parameter passing mechanism (see Import_Function syntax
731 -- for MECHANISM_NAME). This routine checks that the mechanism argument
732 -- has the right form, and if not issues an error message. If the
733 -- argument has the right form then the Mechanism field of Ent is
734 -- set appropriately.
736 procedure Set_Ravenscar_Profile (N : Node_Id);
737 -- Activate the set of configuration pragmas and restrictions that make
738 -- up the Ravenscar Profile. N is the corresponding pragma node, which
739 -- is used for error messages on any constructs that violate the
742 ---------------------
743 -- Ada_2005_Pragma --
744 ---------------------
746 procedure Ada_2005_Pragma is
748 if Ada_Version <= Ada_95 then
749 Check_Restriction (No_Implementation_Pragmas, N);
753 ---------------------
754 -- Ada_2012_Pragma --
755 ---------------------
757 procedure Ada_2012_Pragma is
759 if Ada_Version <= Ada_2005 then
760 Check_Restriction (No_Implementation_Pragmas, N);
764 --------------------------
765 -- Check_Ada_83_Warning --
766 --------------------------
768 procedure Check_Ada_83_Warning is
770 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
771 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
773 end Check_Ada_83_Warning;
775 ---------------------
776 -- Check_Arg_Count --
777 ---------------------
779 procedure Check_Arg_Count (Required : Nat) is
781 if Arg_Count /= Required then
782 Error_Pragma ("wrong number of arguments for pragma%");
786 --------------------------------
787 -- Check_Arg_Is_External_Name --
788 --------------------------------
790 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
791 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
794 if Nkind (Argx) = N_Identifier then
798 Analyze_And_Resolve (Argx, Standard_String);
800 if Is_OK_Static_Expression (Argx) then
803 elsif Etype (Argx) = Any_Type then
806 -- An interesting special case, if we have a string literal and
807 -- we are in Ada 83 mode, then we allow it even though it will
808 -- not be flagged as static. This allows expected Ada 83 mode
809 -- use of external names which are string literals, even though
810 -- technically these are not static in Ada 83.
812 elsif Ada_Version = Ada_83
813 and then Nkind (Argx) = N_String_Literal
817 -- Static expression that raises Constraint_Error. This has
818 -- already been flagged, so just exit from pragma processing.
820 elsif Is_Static_Expression (Argx) then
823 -- Here we have a real error (non-static expression)
826 Error_Msg_Name_1 := Pname;
830 "argument for pragma% must be a identifier or "
831 & "static string expression!";
834 Flag_Non_Static_Expr (Msg, Argx);
839 end Check_Arg_Is_External_Name;
841 -----------------------------
842 -- Check_Arg_Is_Identifier --
843 -----------------------------
845 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
846 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
848 if Nkind (Argx) /= N_Identifier then
850 ("argument for pragma% must be identifier", Argx);
852 end Check_Arg_Is_Identifier;
854 ----------------------------------
855 -- Check_Arg_Is_Integer_Literal --
856 ----------------------------------
858 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
859 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
861 if Nkind (Argx) /= N_Integer_Literal then
863 ("argument for pragma% must be integer literal", Argx);
865 end Check_Arg_Is_Integer_Literal;
867 -------------------------------------------
868 -- Check_Arg_Is_Library_Level_Local_Name --
869 -------------------------------------------
873 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
874 -- | library_unit_NAME
876 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
878 Check_Arg_Is_Local_Name (Arg);
880 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
881 and then Comes_From_Source (N)
884 ("argument for pragma% must be library level entity", Arg);
886 end Check_Arg_Is_Library_Level_Local_Name;
888 -----------------------------
889 -- Check_Arg_Is_Local_Name --
890 -----------------------------
894 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
895 -- | library_unit_NAME
897 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
898 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
903 if Nkind (Argx) not in N_Direct_Name
904 and then (Nkind (Argx) /= N_Attribute_Reference
905 or else Present (Expressions (Argx))
906 or else Nkind (Prefix (Argx)) /= N_Identifier)
907 and then (not Is_Entity_Name (Argx)
908 or else not Is_Compilation_Unit (Entity (Argx)))
910 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
913 if Is_Entity_Name (Argx)
914 and then Scope (Entity (Argx)) /= Current_Scope
917 ("pragma% argument must be in same declarative part", Arg);
919 end Check_Arg_Is_Local_Name;
921 ---------------------------------
922 -- Check_Arg_Is_Locking_Policy --
923 ---------------------------------
925 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
926 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
929 Check_Arg_Is_Identifier (Argx);
931 if not Is_Locking_Policy_Name (Chars (Argx)) then
933 ("& is not a valid locking policy name", Argx);
935 end Check_Arg_Is_Locking_Policy;
937 -------------------------
938 -- Check_Arg_Is_One_Of --
939 -------------------------
941 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
942 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
945 Check_Arg_Is_Identifier (Argx);
947 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
948 Error_Msg_Name_2 := N1;
949 Error_Msg_Name_3 := N2;
950 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
952 end Check_Arg_Is_One_Of;
954 procedure Check_Arg_Is_One_Of
956 N1, N2, N3 : Name_Id)
958 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
961 Check_Arg_Is_Identifier (Argx);
963 if Chars (Argx) /= N1
964 and then Chars (Argx) /= N2
965 and then Chars (Argx) /= N3
967 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
969 end Check_Arg_Is_One_Of;
971 procedure Check_Arg_Is_One_Of
973 N1, N2, N3, N4 : Name_Id)
975 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
978 Check_Arg_Is_Identifier (Argx);
980 if Chars (Argx) /= N1
981 and then Chars (Argx) /= N2
982 and then Chars (Argx) /= N3
983 and then Chars (Argx) /= N4
985 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
987 end Check_Arg_Is_One_Of;
989 ---------------------------------
990 -- Check_Arg_Is_Queuing_Policy --
991 ---------------------------------
993 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
994 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
997 Check_Arg_Is_Identifier (Argx);
999 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1001 ("& is not a valid queuing policy name", Argx);
1003 end Check_Arg_Is_Queuing_Policy;
1005 ------------------------------------
1006 -- Check_Arg_Is_Static_Expression --
1007 ------------------------------------
1009 procedure Check_Arg_Is_Static_Expression
1011 Typ : Entity_Id := Empty)
1013 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1016 if Present (Typ) then
1017 Analyze_And_Resolve (Argx, Typ);
1019 Analyze_And_Resolve (Argx);
1022 if Is_OK_Static_Expression (Argx) then
1025 elsif Etype (Argx) = Any_Type then
1028 -- An interesting special case, if we have a string literal and we
1029 -- are in Ada 83 mode, then we allow it even though it will not be
1030 -- flagged as static. This allows the use of Ada 95 pragmas like
1031 -- Import in Ada 83 mode. They will of course be flagged with
1032 -- warnings as usual, but will not cause errors.
1034 elsif Ada_Version = Ada_83
1035 and then Nkind (Argx) = N_String_Literal
1039 -- Static expression that raises Constraint_Error. This has already
1040 -- been flagged, so just exit from pragma processing.
1042 elsif Is_Static_Expression (Argx) then
1045 -- Finally, we have a real error
1048 Error_Msg_Name_1 := Pname;
1052 "argument for pragma% must be a static expression!";
1055 Flag_Non_Static_Expr (Msg, Argx);
1060 end Check_Arg_Is_Static_Expression;
1062 ------------------------------------------
1063 -- Check_Arg_Is_Task_Dispatching_Policy --
1064 ------------------------------------------
1066 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1067 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1070 Check_Arg_Is_Identifier (Argx);
1072 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1074 ("& is not a valid task dispatching policy name", Argx);
1076 end Check_Arg_Is_Task_Dispatching_Policy;
1078 ---------------------
1079 -- Check_Arg_Order --
1080 ---------------------
1082 procedure Check_Arg_Order (Names : Name_List) is
1085 Highest_So_Far : Natural := 0;
1086 -- Highest index in Names seen do far
1090 for J in 1 .. Arg_Count loop
1091 if Chars (Arg) /= No_Name then
1092 for K in Names'Range loop
1093 if Chars (Arg) = Names (K) then
1094 if K < Highest_So_Far then
1095 Error_Msg_Name_1 := Pname;
1097 ("parameters out of order for pragma%", Arg);
1098 Error_Msg_Name_1 := Names (K);
1099 Error_Msg_Name_2 := Names (Highest_So_Far);
1100 Error_Msg_N ("\% must appear before %", Arg);
1104 Highest_So_Far := K;
1112 end Check_Arg_Order;
1114 --------------------------------
1115 -- Check_At_Least_N_Arguments --
1116 --------------------------------
1118 procedure Check_At_Least_N_Arguments (N : Nat) is
1120 if Arg_Count < N then
1121 Error_Pragma ("too few arguments for pragma%");
1123 end Check_At_Least_N_Arguments;
1125 -------------------------------
1126 -- Check_At_Most_N_Arguments --
1127 -------------------------------
1129 procedure Check_At_Most_N_Arguments (N : Nat) is
1132 if Arg_Count > N then
1134 for J in 1 .. N loop
1136 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1139 end Check_At_Most_N_Arguments;
1141 ---------------------
1142 -- Check_Component --
1143 ---------------------
1145 procedure Check_Component
1148 In_Variant_Part : Boolean := False)
1150 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1151 Sindic : constant Node_Id :=
1152 Subtype_Indication (Component_Definition (Comp));
1153 Typ : constant Entity_Id := Etype (Comp_Id);
1155 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1156 -- Determine whether entity Id appears inside a generic body
1158 -------------------------
1159 -- Inside_Generic_Body --
1160 -------------------------
1162 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1163 S : Entity_Id := Id;
1167 and then S /= Standard_Standard
1169 if Ekind (S) = E_Generic_Package
1170 and then In_Package_Body (S)
1179 end Inside_Generic_Body;
1181 -- Start of processing for Check_Component
1184 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1185 -- object constraint, then the component type shall be an Unchecked_
1188 if Nkind (Sindic) = N_Subtype_Indication
1189 and then Has_Per_Object_Constraint (Comp_Id)
1190 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1193 ("component subtype subject to per-object constraint " &
1194 "must be an Unchecked_Union", Comp);
1196 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1197 -- the body of a generic unit, or within the body of any of its
1198 -- descendant library units, no part of the type of a component
1199 -- declared in a variant_part of the unchecked union type shall be of
1200 -- a formal private type or formal private extension declared within
1201 -- the formal part of the generic unit.
1203 elsif Ada_Version >= Ada_2012
1204 and then Inside_Generic_Body (UU_Typ)
1205 and then In_Variant_Part
1206 and then Is_Private_Type (Typ)
1207 and then Is_Generic_Type (Typ)
1210 ("component of Unchecked_Union cannot be of generic type", Comp);
1212 elsif Needs_Finalization (Typ) then
1214 ("component of Unchecked_Union cannot be controlled", Comp);
1216 elsif Has_Task (Typ) then
1218 ("component of Unchecked_Union cannot have tasks", Comp);
1220 end Check_Component;
1222 ----------------------------
1223 -- Check_Duplicate_Pragma --
1224 ----------------------------
1226 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1230 -- Nothing to do if this pragma comes from an aspect specification,
1231 -- since we could not be duplicating a pragma, and we dealt with the
1232 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1234 if From_Aspect_Specification (N) then
1238 -- Otherwise current pragma may duplicate previous pragma or a
1239 -- previously given aspect specification for the same pragma.
1241 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1244 Error_Msg_Name_1 := Pragma_Name (N);
1245 Error_Msg_Sloc := Sloc (P);
1247 if Nkind (P) = N_Aspect_Specification
1248 or else From_Aspect_Specification (P)
1250 Error_Msg_NE ("aspect% for & previously specified#", N, E);
1252 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1257 end Check_Duplicate_Pragma;
1259 ----------------------------------
1260 -- Check_Duplicated_Export_Name --
1261 ----------------------------------
1263 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1264 String_Val : constant String_Id := Strval (Nam);
1267 -- We are only interested in the export case, and in the case of
1268 -- generics, it is the instance, not the template, that is the
1269 -- problem (the template will generate a warning in any case).
1271 if not Inside_A_Generic
1272 and then (Prag_Id = Pragma_Export
1274 Prag_Id = Pragma_Export_Procedure
1276 Prag_Id = Pragma_Export_Valued_Procedure
1278 Prag_Id = Pragma_Export_Function)
1280 for J in Externals.First .. Externals.Last loop
1281 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1282 Error_Msg_Sloc := Sloc (Externals.Table (J));
1283 Error_Msg_N ("external name duplicates name given#", Nam);
1288 Externals.Append (Nam);
1290 end Check_Duplicated_Export_Name;
1292 -------------------------
1293 -- Check_First_Subtype --
1294 -------------------------
1296 procedure Check_First_Subtype (Arg : Node_Id) is
1297 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1299 if not Is_First_Subtype (Entity (Argx)) then
1301 ("pragma% cannot apply to subtype", Argx);
1303 end Check_First_Subtype;
1305 ---------------------------
1306 -- Check_In_Main_Program --
1307 ---------------------------
1309 procedure Check_In_Main_Program is
1310 P : constant Node_Id := Parent (N);
1313 -- Must be at in subprogram body
1315 if Nkind (P) /= N_Subprogram_Body then
1316 Error_Pragma ("% pragma allowed only in subprogram");
1318 -- Otherwise warn if obviously not main program
1320 elsif Present (Parameter_Specifications (Specification (P)))
1321 or else not Is_Compilation_Unit (Defining_Entity (P))
1323 Error_Msg_Name_1 := Pname;
1325 ("?pragma% is only effective in main program", N);
1327 end Check_In_Main_Program;
1329 ---------------------------------------
1330 -- Check_Interrupt_Or_Attach_Handler --
1331 ---------------------------------------
1333 procedure Check_Interrupt_Or_Attach_Handler is
1334 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1335 Handler_Proc, Proc_Scope : Entity_Id;
1340 if Prag_Id = Pragma_Interrupt_Handler then
1341 Check_Restriction (No_Dynamic_Attachment, N);
1344 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1345 Proc_Scope := Scope (Handler_Proc);
1347 -- On AAMP only, a pragma Interrupt_Handler is supported for
1348 -- nonprotected parameterless procedures.
1350 if not AAMP_On_Target
1351 or else Prag_Id = Pragma_Attach_Handler
1353 if Ekind (Proc_Scope) /= E_Protected_Type then
1355 ("argument of pragma% must be protected procedure", Arg1);
1358 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1359 Error_Pragma ("pragma% must be in protected definition");
1363 if not Is_Library_Level_Entity (Proc_Scope)
1364 or else (AAMP_On_Target
1365 and then not Is_Library_Level_Entity (Handler_Proc))
1368 ("argument for pragma% must be library level entity", Arg1);
1371 -- AI05-0033: A pragma cannot appear within a generic body, because
1372 -- instance can be in a nested scope. The check that protected type
1373 -- is itself a library-level declaration is done elsewhere.
1375 -- Note: we omit this check in Codepeer mode to properly handle code
1376 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1378 if Inside_A_Generic then
1379 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1380 and then In_Package_Body (Scope (Current_Scope))
1381 and then not CodePeer_Mode
1383 Error_Pragma ("pragma% cannot be used inside a generic");
1386 end Check_Interrupt_Or_Attach_Handler;
1388 -------------------------------------------
1389 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1390 -------------------------------------------
1392 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1401 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1404 elsif Nkind_In (P, N_Package_Specification,
1409 -- Note: the following tests seem a little peculiar, because
1410 -- they test for bodies, but if we were in the statement part
1411 -- of the body, we would already have hit the handled statement
1412 -- sequence, so the only way we get here is by being in the
1413 -- declarative part of the body.
1415 elsif Nkind_In (P, N_Subprogram_Body,
1426 Error_Pragma ("pragma% is not in declarative part or package spec");
1427 end Check_Is_In_Decl_Part_Or_Package_Spec;
1429 -------------------------
1430 -- Check_No_Identifier --
1431 -------------------------
1433 procedure Check_No_Identifier (Arg : Node_Id) is
1435 if Nkind (Arg) = N_Pragma_Argument_Association
1436 and then Chars (Arg) /= No_Name
1438 Error_Pragma_Arg_Ident
1439 ("pragma% does not permit identifier& here", Arg);
1441 end Check_No_Identifier;
1443 --------------------------
1444 -- Check_No_Identifiers --
1445 --------------------------
1447 procedure Check_No_Identifiers is
1450 if Arg_Count > 0 then
1452 while Present (Arg_Node) loop
1453 Check_No_Identifier (Arg_Node);
1457 end Check_No_Identifiers;
1459 -------------------------------
1460 -- Check_Optional_Identifier --
1461 -------------------------------
1463 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1466 and then Nkind (Arg) = N_Pragma_Argument_Association
1467 and then Chars (Arg) /= No_Name
1469 if Chars (Arg) /= Id then
1470 Error_Msg_Name_1 := Pname;
1471 Error_Msg_Name_2 := Id;
1472 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1476 end Check_Optional_Identifier;
1478 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1480 Name_Buffer (1 .. Id'Length) := Id;
1481 Name_Len := Id'Length;
1482 Check_Optional_Identifier (Arg, Name_Find);
1483 end Check_Optional_Identifier;
1485 --------------------------------------
1486 -- Check_Precondition_Postcondition --
1487 --------------------------------------
1489 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1493 procedure Chain_PPC (PO : Node_Id);
1494 -- If PO is a subprogram declaration node (or a generic subprogram
1495 -- declaration node), then the precondition/postcondition applies
1496 -- to this subprogram and the processing for the pragma is completed.
1497 -- Otherwise the pragma is misplaced.
1503 procedure Chain_PPC (PO : Node_Id) is
1508 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1509 if not From_Aspect_Specification (N) then
1511 ("pragma% cannot be applied to abstract subprogram");
1513 elsif Class_Present (N) then
1515 ("aspect `%''Class` not implemented yet");
1519 ("aspect % requires ''Class for abstract subprogram");
1522 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1523 N_Generic_Subprogram_Declaration)
1528 -- Here if we have subprogram or generic subprogram declaration
1530 S := Defining_Unit_Name (Specification (PO));
1532 -- Make sure we do not have the case of a pre/postcondition
1533 -- pragma when the corresponding aspect is present. This is
1534 -- never allowed. We allow either pragmas or aspects, not both.
1536 -- We do this by looking at pragmas already chained to the entity
1537 -- since the aspect derived pragma will be put on this list first.
1539 if not From_Aspect_Specification (N) then
1540 P := Spec_PPC_List (S);
1541 while Present (P) loop
1542 if Pragma_Name (P) = Pragma_Name (N)
1543 and then From_Aspect_Specification (P)
1545 Error_Msg_Sloc := Sloc (P);
1547 if Prag_Id = Pragma_Precondition then
1548 Error_Msg_Name_2 := Name_Pre;
1550 Error_Msg_Name_2 := Name_Post;
1554 ("pragma% not allowed, % aspect given#");
1557 P := Next_Pragma (P);
1561 -- Analyze the pragma unless it appears within a package spec,
1562 -- which is the case where we delay the analysis of the PPC until
1563 -- the end of the package declarations (for details, see
1564 -- Analyze_Package_Specification.Analyze_PPCs).
1566 if not Is_Package_Or_Generic_Package (Scope (S)) then
1567 Analyze_PPC_In_Decl_Part (N, S);
1570 -- Chain spec PPC pragma to list for subprogram
1572 Set_Next_Pragma (N, Spec_PPC_List (S));
1573 Set_Spec_PPC_List (S, N);
1575 -- Return indicating spec case
1581 -- Start of processing for Check_Precondition_Postcondition
1584 if not Is_List_Member (N) then
1588 -- Record if pragma is enabled
1590 if Check_Enabled (Pname) then
1591 Set_Pragma_Enabled (N);
1592 Set_SCO_Pragma_Enabled (Loc);
1595 -- If we are within an inlined body, the legality of the pragma
1596 -- has been checked already.
1598 if In_Inlined_Body then
1603 -- Search prior declarations
1606 while Present (Prev (P)) loop
1609 -- If the previous node is a generic subprogram, do not go to to
1610 -- the original node, which is the unanalyzed tree: we need to
1611 -- attach the pre/postconditions to the analyzed version at this
1612 -- point. They get propagated to the original tree when analyzing
1613 -- the corresponding body.
1615 if Nkind (P) not in N_Generic_Declaration then
1616 PO := Original_Node (P);
1621 -- Skip past prior pragma
1623 if Nkind (PO) = N_Pragma then
1626 -- Skip stuff not coming from source
1628 elsif not Comes_From_Source (PO) then
1631 -- Only remaining possibility is subprogram declaration
1639 -- If we fall through loop, pragma is at start of list, so see if it
1640 -- is at the start of declarations of a subprogram body.
1642 if Nkind (Parent (N)) = N_Subprogram_Body
1643 and then List_Containing (N) = Declarations (Parent (N))
1645 if Operating_Mode /= Generate_Code
1646 or else Inside_A_Generic
1649 -- Analyze expression in pragma, for correctness
1650 -- and for ASIS use.
1652 Preanalyze_Spec_Expression
1653 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1659 -- See if it is in the pragmas after a library level subprogram
1661 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1662 Chain_PPC (Unit (Parent (Parent (N))));
1666 -- If we fall through, pragma was misplaced
1669 end Check_Precondition_Postcondition;
1671 -----------------------------
1672 -- Check_Static_Constraint --
1673 -----------------------------
1675 -- Note: for convenience in writing this procedure, in addition to
1676 -- the officially (i.e. by spec) allowed argument which is always a
1677 -- constraint, it also allows ranges and discriminant associations.
1678 -- Above is not clear ???
1680 procedure Check_Static_Constraint (Constr : Node_Id) is
1682 procedure Require_Static (E : Node_Id);
1683 -- Require given expression to be static expression
1685 --------------------
1686 -- Require_Static --
1687 --------------------
1689 procedure Require_Static (E : Node_Id) is
1691 if not Is_OK_Static_Expression (E) then
1692 Flag_Non_Static_Expr
1693 ("non-static constraint not allowed in Unchecked_Union!", E);
1698 -- Start of processing for Check_Static_Constraint
1701 case Nkind (Constr) is
1702 when N_Discriminant_Association =>
1703 Require_Static (Expression (Constr));
1706 Require_Static (Low_Bound (Constr));
1707 Require_Static (High_Bound (Constr));
1709 when N_Attribute_Reference =>
1710 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1711 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1713 when N_Range_Constraint =>
1714 Check_Static_Constraint (Range_Expression (Constr));
1716 when N_Index_Or_Discriminant_Constraint =>
1720 IDC := First (Constraints (Constr));
1721 while Present (IDC) loop
1722 Check_Static_Constraint (IDC);
1730 end Check_Static_Constraint;
1732 --------------------------------------
1733 -- Check_Valid_Configuration_Pragma --
1734 --------------------------------------
1736 -- A configuration pragma must appear in the context clause of a
1737 -- compilation unit, and only other pragmas may precede it. Note that
1738 -- the test also allows use in a configuration pragma file.
1740 procedure Check_Valid_Configuration_Pragma is
1742 if not Is_Configuration_Pragma then
1743 Error_Pragma ("incorrect placement for configuration pragma%");
1745 end Check_Valid_Configuration_Pragma;
1747 -------------------------------------
1748 -- Check_Valid_Library_Unit_Pragma --
1749 -------------------------------------
1751 procedure Check_Valid_Library_Unit_Pragma is
1753 Parent_Node : Node_Id;
1754 Unit_Name : Entity_Id;
1755 Unit_Kind : Node_Kind;
1756 Unit_Node : Node_Id;
1757 Sindex : Source_File_Index;
1760 if not Is_List_Member (N) then
1764 Plist := List_Containing (N);
1765 Parent_Node := Parent (Plist);
1767 if Parent_Node = Empty then
1770 -- Case of pragma appearing after a compilation unit. In this case
1771 -- it must have an argument with the corresponding name and must
1772 -- be part of the following pragmas of its parent.
1774 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1775 if Plist /= Pragmas_After (Parent_Node) then
1778 elsif Arg_Count = 0 then
1780 ("argument required if outside compilation unit");
1783 Check_No_Identifiers;
1784 Check_Arg_Count (1);
1785 Unit_Node := Unit (Parent (Parent_Node));
1786 Unit_Kind := Nkind (Unit_Node);
1788 Analyze (Get_Pragma_Arg (Arg1));
1790 if Unit_Kind = N_Generic_Subprogram_Declaration
1791 or else Unit_Kind = N_Subprogram_Declaration
1793 Unit_Name := Defining_Entity (Unit_Node);
1795 elsif Unit_Kind in N_Generic_Instantiation then
1796 Unit_Name := Defining_Entity (Unit_Node);
1799 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1802 if Chars (Unit_Name) /=
1803 Chars (Entity (Get_Pragma_Arg (Arg1)))
1806 ("pragma% argument is not current unit name", Arg1);
1809 if Ekind (Unit_Name) = E_Package
1810 and then Present (Renamed_Entity (Unit_Name))
1812 Error_Pragma ("pragma% not allowed for renamed package");
1816 -- Pragma appears other than after a compilation unit
1819 -- Here we check for the generic instantiation case and also
1820 -- for the case of processing a generic formal package. We
1821 -- detect these cases by noting that the Sloc on the node
1822 -- does not belong to the current compilation unit.
1824 Sindex := Source_Index (Current_Sem_Unit);
1826 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1827 Rewrite (N, Make_Null_Statement (Loc));
1830 -- If before first declaration, the pragma applies to the
1831 -- enclosing unit, and the name if present must be this name.
1833 elsif Is_Before_First_Decl (N, Plist) then
1834 Unit_Node := Unit_Declaration_Node (Current_Scope);
1835 Unit_Kind := Nkind (Unit_Node);
1837 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1840 elsif Unit_Kind = N_Subprogram_Body
1841 and then not Acts_As_Spec (Unit_Node)
1845 elsif Nkind (Parent_Node) = N_Package_Body then
1848 elsif Nkind (Parent_Node) = N_Package_Specification
1849 and then Plist = Private_Declarations (Parent_Node)
1853 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1854 or else Nkind (Parent_Node) =
1855 N_Generic_Subprogram_Declaration)
1856 and then Plist = Generic_Formal_Declarations (Parent_Node)
1860 elsif Arg_Count > 0 then
1861 Analyze (Get_Pragma_Arg (Arg1));
1863 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
1865 ("name in pragma% must be enclosing unit", Arg1);
1868 -- It is legal to have no argument in this context
1874 -- Error if not before first declaration. This is because a
1875 -- library unit pragma argument must be the name of a library
1876 -- unit (RM 10.1.5(7)), but the only names permitted in this
1877 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1878 -- generic subprogram declarations or generic instantiations.
1882 ("pragma% misplaced, must be before first declaration");
1886 end Check_Valid_Library_Unit_Pragma;
1892 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
1893 Clist : constant Node_Id := Component_List (Variant);
1897 if not Is_Non_Empty_List (Component_Items (Clist)) then
1899 ("Unchecked_Union may not have empty component list",
1904 Comp := First (Component_Items (Clist));
1905 while Present (Comp) loop
1906 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
1915 procedure Error_Pragma (Msg : String) is
1916 MsgF : String := Msg;
1918 Error_Msg_Name_1 := Pname;
1920 Error_Msg_N (MsgF, N);
1924 ----------------------
1925 -- Error_Pragma_Arg --
1926 ----------------------
1928 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1929 MsgF : String := Msg;
1931 Error_Msg_Name_1 := Pname;
1933 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
1935 end Error_Pragma_Arg;
1937 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1938 MsgF : String := Msg1;
1940 Error_Msg_Name_1 := Pname;
1942 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
1943 Error_Pragma_Arg (Msg2, Arg);
1944 end Error_Pragma_Arg;
1946 ----------------------------
1947 -- Error_Pragma_Arg_Ident --
1948 ----------------------------
1950 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1951 MsgF : String := Msg;
1953 Error_Msg_Name_1 := Pname;
1955 Error_Msg_N (MsgF, Arg);
1957 end Error_Pragma_Arg_Ident;
1959 ----------------------
1960 -- Error_Pragma_Ref --
1961 ----------------------
1963 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
1964 MsgF : String := Msg;
1966 Error_Msg_Name_1 := Pname;
1968 Error_Msg_Sloc := Sloc (Ref);
1969 Error_Msg_NE (MsgF, N, Ref);
1971 end Error_Pragma_Ref;
1973 ------------------------
1974 -- Find_Lib_Unit_Name --
1975 ------------------------
1977 function Find_Lib_Unit_Name return Entity_Id is
1979 -- Return inner compilation unit entity, for case of nested
1980 -- categorization pragmas. This happens in generic unit.
1982 if Nkind (Parent (N)) = N_Package_Specification
1983 and then Defining_Entity (Parent (N)) /= Current_Scope
1985 return Defining_Entity (Parent (N));
1987 return Current_Scope;
1989 end Find_Lib_Unit_Name;
1991 ----------------------------
1992 -- Find_Program_Unit_Name --
1993 ----------------------------
1995 procedure Find_Program_Unit_Name (Id : Node_Id) is
1996 Unit_Name : Entity_Id;
1997 Unit_Kind : Node_Kind;
1998 P : constant Node_Id := Parent (N);
2001 if Nkind (P) = N_Compilation_Unit then
2002 Unit_Kind := Nkind (Unit (P));
2004 if Unit_Kind = N_Subprogram_Declaration
2005 or else Unit_Kind = N_Package_Declaration
2006 or else Unit_Kind in N_Generic_Declaration
2008 Unit_Name := Defining_Entity (Unit (P));
2010 if Chars (Id) = Chars (Unit_Name) then
2011 Set_Entity (Id, Unit_Name);
2012 Set_Etype (Id, Etype (Unit_Name));
2014 Set_Etype (Id, Any_Type);
2016 ("cannot find program unit referenced by pragma%");
2020 Set_Etype (Id, Any_Type);
2021 Error_Pragma ("pragma% inapplicable to this unit");
2027 end Find_Program_Unit_Name;
2029 -----------------------------------------
2030 -- Find_Unique_Parameterless_Procedure --
2031 -----------------------------------------
2033 function Find_Unique_Parameterless_Procedure
2035 Arg : Node_Id) return Entity_Id
2037 Proc : Entity_Id := Empty;
2040 -- The body of this procedure needs some comments ???
2042 if not Is_Entity_Name (Name) then
2044 ("argument of pragma% must be entity name", Arg);
2046 elsif not Is_Overloaded (Name) then
2047 Proc := Entity (Name);
2049 if Ekind (Proc) /= E_Procedure
2050 or else Present (First_Formal (Proc))
2053 ("argument of pragma% must be parameterless procedure", Arg);
2058 Found : Boolean := False;
2060 Index : Interp_Index;
2063 Get_First_Interp (Name, Index, It);
2064 while Present (It.Nam) loop
2067 if Ekind (Proc) = E_Procedure
2068 and then No (First_Formal (Proc))
2072 Set_Entity (Name, Proc);
2073 Set_Is_Overloaded (Name, False);
2076 ("ambiguous handler name for pragma% ", Arg);
2080 Get_Next_Interp (Index, It);
2085 ("argument of pragma% must be parameterless procedure",
2088 Proc := Entity (Name);
2094 end Find_Unique_Parameterless_Procedure;
2100 procedure Fix_Error (Msg : in out String) is
2102 if From_Aspect_Specification (N) then
2103 for J in Msg'First .. Msg'Last - 5 loop
2104 if Msg (J .. J + 5) = "pragma" then
2105 Msg (J .. J + 5) := "aspect";
2109 if Error_Msg_Name_1 = Name_Precondition then
2110 Error_Msg_Name_1 := Name_Pre;
2111 elsif Error_Msg_Name_1 = Name_Postcondition then
2112 Error_Msg_Name_1 := Name_Post;
2117 -------------------------
2118 -- Gather_Associations --
2119 -------------------------
2121 procedure Gather_Associations
2123 Args : out Args_List)
2128 -- Initialize all parameters to Empty
2130 for J in Args'Range loop
2134 -- That's all we have to do if there are no argument associations
2136 if No (Pragma_Argument_Associations (N)) then
2140 -- Otherwise first deal with any positional parameters present
2142 Arg := First (Pragma_Argument_Associations (N));
2143 for Index in Args'Range loop
2144 exit when No (Arg) or else Chars (Arg) /= No_Name;
2145 Args (Index) := Get_Pragma_Arg (Arg);
2149 -- Positional parameters all processed, if any left, then we
2150 -- have too many positional parameters.
2152 if Present (Arg) and then Chars (Arg) = No_Name then
2154 ("too many positional associations for pragma%", Arg);
2157 -- Process named parameters if any are present
2159 while Present (Arg) loop
2160 if Chars (Arg) = No_Name then
2162 ("positional association cannot follow named association",
2166 for Index in Names'Range loop
2167 if Names (Index) = Chars (Arg) then
2168 if Present (Args (Index)) then
2170 ("duplicate argument association for pragma%", Arg);
2172 Args (Index) := Get_Pragma_Arg (Arg);
2177 if Index = Names'Last then
2178 Error_Msg_Name_1 := Pname;
2179 Error_Msg_N ("pragma% does not allow & argument", Arg);
2181 -- Check for possible misspelling
2183 for Index1 in Names'Range loop
2184 if Is_Bad_Spelling_Of
2185 (Chars (Arg), Names (Index1))
2187 Error_Msg_Name_1 := Names (Index1);
2188 Error_Msg_N -- CODEFIX
2189 ("\possible misspelling of%", Arg);
2201 end Gather_Associations;
2207 procedure GNAT_Pragma is
2209 Check_Restriction (No_Implementation_Pragmas, N);
2212 --------------------------
2213 -- Is_Before_First_Decl --
2214 --------------------------
2216 function Is_Before_First_Decl
2217 (Pragma_Node : Node_Id;
2218 Decls : List_Id) return Boolean
2220 Item : Node_Id := First (Decls);
2223 -- Only other pragmas can come before this pragma
2226 if No (Item) or else Nkind (Item) /= N_Pragma then
2229 elsif Item = Pragma_Node then
2235 end Is_Before_First_Decl;
2237 -----------------------------
2238 -- Is_Configuration_Pragma --
2239 -----------------------------
2241 -- A configuration pragma must appear in the context clause of a
2242 -- compilation unit, and only other pragmas may precede it. Note that
2243 -- the test below also permits use in a configuration pragma file.
2245 function Is_Configuration_Pragma return Boolean is
2246 Lis : constant List_Id := List_Containing (N);
2247 Par : constant Node_Id := Parent (N);
2251 -- If no parent, then we are in the configuration pragma file,
2252 -- so the placement is definitely appropriate.
2257 -- Otherwise we must be in the context clause of a compilation unit
2258 -- and the only thing allowed before us in the context list is more
2259 -- configuration pragmas.
2261 elsif Nkind (Par) = N_Compilation_Unit
2262 and then Context_Items (Par) = Lis
2269 elsif Nkind (Prg) /= N_Pragma then
2279 end Is_Configuration_Pragma;
2281 --------------------------
2282 -- Is_In_Context_Clause --
2283 --------------------------
2285 function Is_In_Context_Clause return Boolean is
2287 Parent_Node : Node_Id;
2290 if not Is_List_Member (N) then
2294 Plist := List_Containing (N);
2295 Parent_Node := Parent (Plist);
2297 if Parent_Node = Empty
2298 or else Nkind (Parent_Node) /= N_Compilation_Unit
2299 or else Context_Items (Parent_Node) /= Plist
2306 end Is_In_Context_Clause;
2308 ---------------------------------
2309 -- Is_Static_String_Expression --
2310 ---------------------------------
2312 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2313 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2316 Analyze_And_Resolve (Argx);
2317 return Is_OK_Static_Expression (Argx)
2318 and then Nkind (Argx) = N_String_Literal;
2319 end Is_Static_String_Expression;
2321 ----------------------
2322 -- Pragma_Misplaced --
2323 ----------------------
2325 procedure Pragma_Misplaced is
2327 Error_Pragma ("incorrect placement of pragma%");
2328 end Pragma_Misplaced;
2330 ------------------------------------
2331 -- Process Atomic_Shared_Volatile --
2332 ------------------------------------
2334 procedure Process_Atomic_Shared_Volatile is
2341 procedure Set_Atomic (E : Entity_Id);
2342 -- Set given type as atomic, and if no explicit alignment was given,
2343 -- set alignment to unknown, since back end knows what the alignment
2344 -- requirements are for atomic arrays. Note: this step is necessary
2345 -- for derived types.
2351 procedure Set_Atomic (E : Entity_Id) is
2353 Set_Is_Atomic (E, Sense);
2355 if Sense and then not Has_Alignment_Clause (E) then
2356 Set_Alignment (E, Uint_0);
2360 -- Start of processing for Process_Atomic_Shared_Volatile
2363 Check_Ada_83_Warning;
2364 Check_No_Identifiers;
2365 Check_Arg_Count (1);
2366 Check_Arg_Is_Local_Name (Arg1);
2367 E_Id := Get_Pragma_Arg (Arg1);
2369 if Etype (E_Id) = Any_Type then
2374 D := Declaration_Node (E);
2377 -- Check duplicate before we chain ourselves!
2379 Check_Duplicate_Pragma (E);
2381 -- Now check appropriateness of the entity
2384 if Rep_Item_Too_Early (E, N)
2386 Rep_Item_Too_Late (E, N)
2390 Check_First_Subtype (Arg1);
2393 if Prag_Id /= Pragma_Volatile then
2395 Set_Atomic (Underlying_Type (E));
2396 Set_Atomic (Base_Type (E));
2399 -- Attribute belongs on the base type. If the view of the type is
2400 -- currently private, it also belongs on the underlying type.
2402 Set_Is_Volatile (Base_Type (E), Sense);
2403 Set_Is_Volatile (Underlying_Type (E), Sense);
2405 Set_Treat_As_Volatile (E, Sense);
2406 Set_Treat_As_Volatile (Underlying_Type (E), Sense);
2408 elsif K = N_Object_Declaration
2409 or else (K = N_Component_Declaration
2410 and then Original_Record_Component (E) = E)
2412 if Rep_Item_Too_Late (E, N) then
2416 if Prag_Id /= Pragma_Volatile then
2417 Set_Is_Atomic (E, Sense);
2419 -- If the object declaration has an explicit initialization, a
2420 -- temporary may have to be created to hold the expression, to
2421 -- ensure that access to the object remain atomic.
2423 if Nkind (Parent (E)) = N_Object_Declaration
2424 and then Present (Expression (Parent (E)))
2427 Set_Has_Delayed_Freeze (E);
2430 -- An interesting improvement here. If an object of type X is
2431 -- declared atomic, and the type X is not atomic, that's a
2432 -- pity, since it may not have appropriate alignment etc. We
2433 -- can rescue this in the special case where the object and
2434 -- type are in the same unit by just setting the type as
2435 -- atomic, so that the back end will process it as atomic.
2437 Utyp := Underlying_Type (Etype (E));
2440 and then Sloc (E) > No_Location
2441 and then Sloc (Utyp) > No_Location
2443 Get_Source_File_Index (Sloc (E)) =
2444 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2446 Set_Is_Atomic (Underlying_Type (Etype (E)), Sense);
2450 Set_Is_Volatile (E);
2451 Set_Treat_As_Volatile (E);
2455 ("inappropriate entity for pragma%", Arg1);
2457 end Process_Atomic_Shared_Volatile;
2459 -------------------------------------------
2460 -- Process_Compile_Time_Warning_Or_Error --
2461 -------------------------------------------
2463 procedure Process_Compile_Time_Warning_Or_Error is
2464 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2467 Check_Arg_Count (2);
2468 Check_No_Identifiers;
2469 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2470 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2472 if Compile_Time_Known_Value (Arg1x) then
2473 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2475 Str : constant String_Id :=
2476 Strval (Get_Pragma_Arg (Arg2));
2477 Len : constant Int := String_Length (Str);
2482 Cent : constant Entity_Id :=
2483 Cunit_Entity (Current_Sem_Unit);
2485 Force : constant Boolean :=
2486 Prag_Id = Pragma_Compile_Time_Warning
2488 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2489 and then (Ekind (Cent) /= E_Package
2490 or else not In_Private_Part (Cent));
2491 -- Set True if this is the warning case, and we are in the
2492 -- visible part of a package spec, or in a subprogram spec,
2493 -- in which case we want to force the client to see the
2494 -- warning, even though it is not in the main unit.
2497 -- Loop through segments of message separated by line feeds.
2498 -- We output these segments as separate messages with
2499 -- continuation marks for all but the first.
2504 Error_Msg_Strlen := 0;
2506 -- Loop to copy characters from argument to error message
2510 exit when Ptr > Len;
2511 CC := Get_String_Char (Str, Ptr);
2514 -- Ignore wide chars ??? else store character
2516 if In_Character_Range (CC) then
2517 C := Get_Character (CC);
2518 exit when C = ASCII.LF;
2519 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2520 Error_Msg_String (Error_Msg_Strlen) := C;
2524 -- Here with one line ready to go
2526 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2528 -- If this is a warning in a spec, then we want clients
2529 -- to see the warning, so mark the message with the
2530 -- special sequence !! to force the warning. In the case
2531 -- of a package spec, we do not force this if we are in
2532 -- the private part of the spec.
2535 if Cont = False then
2536 Error_Msg_N ("<~!!", Arg1);
2539 Error_Msg_N ("\<~!!", Arg1);
2542 -- Error, rather than warning, or in a body, so we do not
2543 -- need to force visibility for client (error will be
2544 -- output in any case, and this is the situation in which
2545 -- we do not want a client to get a warning, since the
2546 -- warning is in the body or the spec private part).
2549 if Cont = False then
2550 Error_Msg_N ("<~", Arg1);
2553 Error_Msg_N ("\<~", Arg1);
2557 exit when Ptr > Len;
2562 end Process_Compile_Time_Warning_Or_Error;
2564 ------------------------
2565 -- Process_Convention --
2566 ------------------------
2568 procedure Process_Convention
2569 (C : out Convention_Id;
2570 Ent : out Entity_Id)
2576 Comp_Unit : Unit_Number_Type;
2578 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2579 -- Called if we have more than one Export/Import/Convention pragma.
2580 -- This is generally illegal, but we have a special case of allowing
2581 -- Import and Interface to coexist if they specify the convention in
2582 -- a consistent manner. We are allowed to do this, since Interface is
2583 -- an implementation defined pragma, and we choose to do it since we
2584 -- know Rational allows this combination. S is the entity id of the
2585 -- subprogram in question. This procedure also sets the special flag
2586 -- Import_Interface_Present in both pragmas in the case where we do
2587 -- have matching Import and Interface pragmas.
2589 procedure Set_Convention_From_Pragma (E : Entity_Id);
2590 -- Set convention in entity E, and also flag that the entity has a
2591 -- convention pragma. If entity is for a private or incomplete type,
2592 -- also set convention and flag on underlying type. This procedure
2593 -- also deals with the special case of C_Pass_By_Copy convention.
2595 -------------------------------
2596 -- Diagnose_Multiple_Pragmas --
2597 -------------------------------
2599 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2600 Pdec : constant Node_Id := Declaration_Node (S);
2604 function Same_Convention (Decl : Node_Id) return Boolean;
2605 -- Decl is a pragma node. This function returns True if this
2606 -- pragma has a first argument that is an identifier with a
2607 -- Chars field corresponding to the Convention_Id C.
2609 function Same_Name (Decl : Node_Id) return Boolean;
2610 -- Decl is a pragma node. This function returns True if this
2611 -- pragma has a second argument that is an identifier with a
2612 -- Chars field that matches the Chars of the current subprogram.
2614 ---------------------
2615 -- Same_Convention --
2616 ---------------------
2618 function Same_Convention (Decl : Node_Id) return Boolean is
2619 Arg1 : constant Node_Id :=
2620 First (Pragma_Argument_Associations (Decl));
2623 if Present (Arg1) then
2625 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2627 if Nkind (Arg) = N_Identifier
2628 and then Is_Convention_Name (Chars (Arg))
2629 and then Get_Convention_Id (Chars (Arg)) = C
2637 end Same_Convention;
2643 function Same_Name (Decl : Node_Id) return Boolean is
2644 Arg1 : constant Node_Id :=
2645 First (Pragma_Argument_Associations (Decl));
2653 Arg2 := Next (Arg1);
2660 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2662 if Nkind (Arg) = N_Identifier
2663 and then Chars (Arg) = Chars (S)
2672 -- Start of processing for Diagnose_Multiple_Pragmas
2677 -- Definitely give message if we have Convention/Export here
2679 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
2682 -- If we have an Import or Export, scan back from pragma to
2683 -- find any previous pragma applying to the same procedure.
2684 -- The scan will be terminated by the start of the list, or
2685 -- hitting the subprogram declaration. This won't allow one
2686 -- pragma to appear in the public part and one in the private
2687 -- part, but that seems very unlikely in practice.
2691 while Present (Decl) and then Decl /= Pdec loop
2693 -- Look for pragma with same name as us
2695 if Nkind (Decl) = N_Pragma
2696 and then Same_Name (Decl)
2698 -- Give error if same as our pragma or Export/Convention
2700 if Pragma_Name (Decl) = Name_Export
2702 Pragma_Name (Decl) = Name_Convention
2704 Pragma_Name (Decl) = Pragma_Name (N)
2708 -- Case of Import/Interface or the other way round
2710 elsif Pragma_Name (Decl) = Name_Interface
2712 Pragma_Name (Decl) = Name_Import
2714 -- Here we know that we have Import and Interface. It
2715 -- doesn't matter which way round they are. See if
2716 -- they specify the same convention. If so, all OK,
2717 -- and set special flags to stop other messages
2719 if Same_Convention (Decl) then
2720 Set_Import_Interface_Present (N);
2721 Set_Import_Interface_Present (Decl);
2724 -- If different conventions, special message
2727 Error_Msg_Sloc := Sloc (Decl);
2729 ("convention differs from that given#", Arg1);
2739 -- Give message if needed if we fall through those tests
2743 ("at most one Convention/Export/Import pragma is allowed",
2746 end Diagnose_Multiple_Pragmas;
2748 --------------------------------
2749 -- Set_Convention_From_Pragma --
2750 --------------------------------
2752 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2754 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2755 -- for an overridden dispatching operation. Technically this is
2756 -- an amendment and should only be done in Ada 2005 mode. However,
2757 -- this is clearly a mistake, since the problem that is addressed
2758 -- by this AI is that there is a clear gap in the RM!
2760 if Is_Dispatching_Operation (E)
2761 and then Present (Overridden_Operation (E))
2762 and then C /= Convention (Overridden_Operation (E))
2765 ("cannot change convention for " &
2766 "overridden dispatching operation",
2770 -- Set the convention
2772 Set_Convention (E, C);
2773 Set_Has_Convention_Pragma (E);
2775 if Is_Incomplete_Or_Private_Type (E) then
2776 Set_Convention (Underlying_Type (E), C);
2777 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2780 -- A class-wide type should inherit the convention of the specific
2781 -- root type (although this isn't specified clearly by the RM).
2783 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2784 Set_Convention (Class_Wide_Type (E), C);
2787 -- If the entity is a record type, then check for special case of
2788 -- C_Pass_By_Copy, which is treated the same as C except that the
2789 -- special record flag is set. This convention is only permitted
2790 -- on record types (see AI95-00131).
2792 if Cname = Name_C_Pass_By_Copy then
2793 if Is_Record_Type (E) then
2794 Set_C_Pass_By_Copy (Base_Type (E));
2795 elsif Is_Incomplete_Or_Private_Type (E)
2796 and then Is_Record_Type (Underlying_Type (E))
2798 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2801 ("C_Pass_By_Copy convention allowed only for record type",
2806 -- If the entity is a derived boolean type, check for the special
2807 -- case of convention C, C++, or Fortran, where we consider any
2808 -- nonzero value to represent true.
2810 if Is_Discrete_Type (E)
2811 and then Root_Type (Etype (E)) = Standard_Boolean
2817 C = Convention_Fortran)
2819 Set_Nonzero_Is_True (Base_Type (E));
2821 end Set_Convention_From_Pragma;
2823 -- Start of processing for Process_Convention
2826 Check_At_Least_N_Arguments (2);
2827 Check_Optional_Identifier (Arg1, Name_Convention);
2828 Check_Arg_Is_Identifier (Arg1);
2829 Cname := Chars (Get_Pragma_Arg (Arg1));
2831 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2832 -- tested again below to set the critical flag).
2833 if Cname = Name_C_Pass_By_Copy then
2836 -- Otherwise we must have something in the standard convention list
2838 elsif Is_Convention_Name (Cname) then
2839 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
2841 -- In DEC VMS, it seems that there is an undocumented feature that
2842 -- any unrecognized convention is treated as the default, which for
2843 -- us is convention C. It does not seem so terrible to do this
2844 -- unconditionally, silently in the VMS case, and with a warning
2845 -- in the non-VMS case.
2848 if Warn_On_Export_Import and not OpenVMS_On_Target then
2850 ("?unrecognized convention name, C assumed",
2851 Get_Pragma_Arg (Arg1));
2857 Check_Optional_Identifier (Arg2, Name_Entity);
2858 Check_Arg_Is_Local_Name (Arg2);
2860 Id := Get_Pragma_Arg (Arg2);
2863 if not Is_Entity_Name (Id) then
2864 Error_Pragma_Arg ("entity name required", Arg2);
2869 -- Set entity to return
2873 -- Go to renamed subprogram if present, since convention applies to
2874 -- the actual renamed entity, not to the renaming entity. If the
2875 -- subprogram is inherited, go to parent subprogram.
2877 if Is_Subprogram (E)
2878 and then Present (Alias (E))
2880 if Nkind (Parent (Declaration_Node (E))) =
2881 N_Subprogram_Renaming_Declaration
2883 if Scope (E) /= Scope (Alias (E)) then
2885 ("cannot apply pragma% to non-local entity&#", E);
2890 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
2891 N_Private_Extension_Declaration)
2892 and then Scope (E) = Scope (Alias (E))
2896 -- Return the parent subprogram the entity was inherited from
2902 -- Check that we are not applying this to a specless body
2904 if Is_Subprogram (E)
2905 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2908 ("pragma% requires separate spec and must come before body");
2911 -- Check that we are not applying this to a named constant
2913 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
2914 Error_Msg_Name_1 := Pname;
2916 ("cannot apply pragma% to named constant!",
2917 Get_Pragma_Arg (Arg2));
2919 ("\supply appropriate type for&!", Arg2);
2922 if Ekind (E) = E_Enumeration_Literal then
2923 Error_Pragma ("enumeration literal not allowed for pragma%");
2926 -- Check for rep item appearing too early or too late
2928 if Etype (E) = Any_Type
2929 or else Rep_Item_Too_Early (E, N)
2933 E := Underlying_Type (E);
2936 if Rep_Item_Too_Late (E, N) then
2940 if Has_Convention_Pragma (E) then
2941 Diagnose_Multiple_Pragmas (E);
2943 elsif Convention (E) = Convention_Protected
2944 or else Ekind (Scope (E)) = E_Protected_Type
2947 ("a protected operation cannot be given a different convention",
2951 -- For Intrinsic, a subprogram is required
2953 if C = Convention_Intrinsic
2954 and then not Is_Subprogram (E)
2955 and then not Is_Generic_Subprogram (E)
2958 ("second argument of pragma% must be a subprogram", Arg2);
2961 -- For Stdcall, a subprogram, variable or subprogram type is required
2963 if C = Convention_Stdcall
2964 and then not Is_Subprogram (E)
2965 and then not Is_Generic_Subprogram (E)
2966 and then Ekind (E) /= E_Variable
2969 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2972 ("second argument of pragma% must be subprogram (type)",
2976 if not Is_Subprogram (E)
2977 and then not Is_Generic_Subprogram (E)
2979 Set_Convention_From_Pragma (E);
2982 Check_First_Subtype (Arg2);
2983 Set_Convention_From_Pragma (Base_Type (E));
2985 -- For subprograms, we must set the convention on the
2986 -- internally generated directly designated type as well.
2988 if Ekind (E) = E_Access_Subprogram_Type then
2989 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2993 -- For the subprogram case, set proper convention for all homonyms
2994 -- in same scope and the same declarative part, i.e. the same
2995 -- compilation unit.
2998 Comp_Unit := Get_Source_Unit (E);
2999 Set_Convention_From_Pragma (E);
3001 -- Treat a pragma Import as an implicit body, for GPS use
3003 if Prag_Id = Pragma_Import then
3004 Generate_Reference (E, Id, 'b');
3007 -- Loop through the homonyms of the pragma argument's entity
3012 exit when No (E1) or else Scope (E1) /= Current_Scope;
3014 -- Do not set the pragma on inherited operations or on formal
3017 if Comes_From_Source (E1)
3018 and then Comp_Unit = Get_Source_Unit (E1)
3019 and then not Is_Formal_Subprogram (E1)
3020 and then Nkind (Original_Node (Parent (E1))) /=
3021 N_Full_Type_Declaration
3023 if Present (Alias (E1))
3024 and then Scope (E1) /= Scope (Alias (E1))
3027 ("cannot apply pragma% to non-local entity& declared#",
3031 Set_Convention_From_Pragma (E1);
3033 if Prag_Id = Pragma_Import then
3034 Generate_Reference (E1, Id, 'b');
3038 -- For aspect case, do NOT apply to homonyms
3040 exit when From_Aspect_Specification (N);
3043 end Process_Convention;
3045 -----------------------------------------------------
3046 -- Process_Extended_Import_Export_Exception_Pragma --
3047 -----------------------------------------------------
3049 procedure Process_Extended_Import_Export_Exception_Pragma
3050 (Arg_Internal : Node_Id;
3051 Arg_External : Node_Id;
3059 if not OpenVMS_On_Target then
3061 ("?pragma% ignored (applies only to Open'V'M'S)");
3064 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3065 Def_Id := Entity (Arg_Internal);
3067 if Ekind (Def_Id) /= E_Exception then
3069 ("pragma% must refer to declared exception", Arg_Internal);
3072 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3074 if Present (Arg_Form) then
3075 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3078 if Present (Arg_Form)
3079 and then Chars (Arg_Form) = Name_Ada
3083 Set_Is_VMS_Exception (Def_Id);
3084 Set_Exception_Code (Def_Id, No_Uint);
3087 if Present (Arg_Code) then
3088 if not Is_VMS_Exception (Def_Id) then
3090 ("Code option for pragma% not allowed for Ada case",
3094 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3095 Code_Val := Expr_Value (Arg_Code);
3097 if not UI_Is_In_Int_Range (Code_Val) then
3099 ("Code option for pragma% must be in 32-bit range",
3103 Set_Exception_Code (Def_Id, Code_Val);
3106 end Process_Extended_Import_Export_Exception_Pragma;
3108 -------------------------------------------------
3109 -- Process_Extended_Import_Export_Internal_Arg --
3110 -------------------------------------------------
3112 procedure Process_Extended_Import_Export_Internal_Arg
3113 (Arg_Internal : Node_Id := Empty)
3116 if No (Arg_Internal) then
3117 Error_Pragma ("Internal parameter required for pragma%");
3120 if Nkind (Arg_Internal) = N_Identifier then
3123 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3124 and then (Prag_Id = Pragma_Import_Function
3126 Prag_Id = Pragma_Export_Function)
3132 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3135 Check_Arg_Is_Local_Name (Arg_Internal);
3136 end Process_Extended_Import_Export_Internal_Arg;
3138 --------------------------------------------------
3139 -- Process_Extended_Import_Export_Object_Pragma --
3140 --------------------------------------------------
3142 procedure Process_Extended_Import_Export_Object_Pragma
3143 (Arg_Internal : Node_Id;
3144 Arg_External : Node_Id;
3150 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3151 Def_Id := Entity (Arg_Internal);
3153 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3155 ("pragma% must designate an object", Arg_Internal);
3158 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3160 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3163 ("previous Common/Psect_Object applies, pragma % not permitted",
3167 if Rep_Item_Too_Late (Def_Id, N) then
3171 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3173 if Present (Arg_Size) then
3174 Check_Arg_Is_External_Name (Arg_Size);
3177 -- Export_Object case
3179 if Prag_Id = Pragma_Export_Object then
3180 if not Is_Library_Level_Entity (Def_Id) then
3182 ("argument for pragma% must be library level entity",
3186 if Ekind (Current_Scope) = E_Generic_Package then
3187 Error_Pragma ("pragma& cannot appear in a generic unit");
3190 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3192 ("exported object must have compile time known size",
3196 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3197 Error_Msg_N ("?duplicate Export_Object pragma", N);
3199 Set_Exported (Def_Id, Arg_Internal);
3202 -- Import_Object case
3205 if Is_Concurrent_Type (Etype (Def_Id)) then
3207 ("cannot use pragma% for task/protected object",
3211 if Ekind (Def_Id) = E_Constant then
3213 ("cannot import a constant", Arg_Internal);
3216 if Warn_On_Export_Import
3217 and then Has_Discriminants (Etype (Def_Id))
3220 ("imported value must be initialized?", Arg_Internal);
3223 if Warn_On_Export_Import
3224 and then Is_Access_Type (Etype (Def_Id))
3227 ("cannot import object of an access type?", Arg_Internal);
3230 if Warn_On_Export_Import
3231 and then Is_Imported (Def_Id)
3234 ("?duplicate Import_Object pragma", N);
3236 -- Check for explicit initialization present. Note that an
3237 -- initialization generated by the code generator, e.g. for an
3238 -- access type, does not count here.
3240 elsif Present (Expression (Parent (Def_Id)))
3243 (Original_Node (Expression (Parent (Def_Id))))
3245 Error_Msg_Sloc := Sloc (Def_Id);
3247 ("imported entities cannot be initialized (RM B.1(24))",
3248 "\no initialization allowed for & declared#", Arg1);
3250 Set_Imported (Def_Id);
3251 Note_Possible_Modification (Arg_Internal, Sure => False);
3254 end Process_Extended_Import_Export_Object_Pragma;
3256 ------------------------------------------------------
3257 -- Process_Extended_Import_Export_Subprogram_Pragma --
3258 ------------------------------------------------------
3260 procedure Process_Extended_Import_Export_Subprogram_Pragma
3261 (Arg_Internal : Node_Id;
3262 Arg_External : Node_Id;
3263 Arg_Parameter_Types : Node_Id;
3264 Arg_Result_Type : Node_Id := Empty;
3265 Arg_Mechanism : Node_Id;
3266 Arg_Result_Mechanism : Node_Id := Empty;
3267 Arg_First_Optional_Parameter : Node_Id := Empty)
3273 Ambiguous : Boolean;
3277 function Same_Base_Type
3279 Formal : Entity_Id) return Boolean;
3280 -- Determines if Ptype references the type of Formal. Note that only
3281 -- the base types need to match according to the spec. Ptype here is
3282 -- the argument from the pragma, which is either a type name, or an
3283 -- access attribute.
3285 --------------------
3286 -- Same_Base_Type --
3287 --------------------
3289 function Same_Base_Type
3291 Formal : Entity_Id) return Boolean
3293 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3297 -- Case where pragma argument is typ'Access
3299 if Nkind (Ptype) = N_Attribute_Reference
3300 and then Attribute_Name (Ptype) = Name_Access
3302 Pref := Prefix (Ptype);
3305 if not Is_Entity_Name (Pref)
3306 or else Entity (Pref) = Any_Type
3311 -- We have a match if the corresponding argument is of an
3312 -- anonymous access type, and its designated type matches the
3313 -- type of the prefix of the access attribute
3315 return Ekind (Ftyp) = E_Anonymous_Access_Type
3316 and then Base_Type (Entity (Pref)) =
3317 Base_Type (Etype (Designated_Type (Ftyp)));
3319 -- Case where pragma argument is a type name
3324 if not Is_Entity_Name (Ptype)
3325 or else Entity (Ptype) = Any_Type
3330 -- We have a match if the corresponding argument is of the type
3331 -- given in the pragma (comparing base types)
3333 return Base_Type (Entity (Ptype)) = Ftyp;
3337 -- Start of processing for
3338 -- Process_Extended_Import_Export_Subprogram_Pragma
3341 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3345 -- Loop through homonyms (overloadings) of the entity
3347 Hom_Id := Entity (Arg_Internal);
3348 while Present (Hom_Id) loop
3349 Def_Id := Get_Base_Subprogram (Hom_Id);
3351 -- We need a subprogram in the current scope
3353 if not Is_Subprogram (Def_Id)
3354 or else Scope (Def_Id) /= Current_Scope
3361 -- Pragma cannot apply to subprogram body
3363 if Is_Subprogram (Def_Id)
3364 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3368 ("pragma% requires separate spec"
3369 & " and must come before body");
3372 -- Test result type if given, note that the result type
3373 -- parameter can only be present for the function cases.
3375 if Present (Arg_Result_Type)
3376 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3380 elsif Etype (Def_Id) /= Standard_Void_Type
3382 (Pname = Name_Export_Procedure
3384 Pname = Name_Import_Procedure)
3388 -- Test parameter types if given. Note that this parameter
3389 -- has not been analyzed (and must not be, since it is
3390 -- semantic nonsense), so we get it as the parser left it.
3392 elsif Present (Arg_Parameter_Types) then
3393 Check_Matching_Types : declare
3398 Formal := First_Formal (Def_Id);
3400 if Nkind (Arg_Parameter_Types) = N_Null then
3401 if Present (Formal) then
3405 -- A list of one type, e.g. (List) is parsed as
3406 -- a parenthesized expression.
3408 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3409 and then Paren_Count (Arg_Parameter_Types) = 1
3412 or else Present (Next_Formal (Formal))
3417 Same_Base_Type (Arg_Parameter_Types, Formal);
3420 -- A list of more than one type is parsed as a aggregate
3422 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3423 and then Paren_Count (Arg_Parameter_Types) = 0
3425 Ptype := First (Expressions (Arg_Parameter_Types));
3426 while Present (Ptype) or else Present (Formal) loop
3429 or else not Same_Base_Type (Ptype, Formal)
3434 Next_Formal (Formal);
3439 -- Anything else is of the wrong form
3443 ("wrong form for Parameter_Types parameter",
3444 Arg_Parameter_Types);
3446 end Check_Matching_Types;
3449 -- Match is now False if the entry we found did not match
3450 -- either a supplied Parameter_Types or Result_Types argument
3456 -- Ambiguous case, the flag Ambiguous shows if we already
3457 -- detected this and output the initial messages.
3460 if not Ambiguous then
3462 Error_Msg_Name_1 := Pname;
3464 ("pragma% does not uniquely identify subprogram!",
3466 Error_Msg_Sloc := Sloc (Ent);
3467 Error_Msg_N ("matching subprogram #!", N);
3471 Error_Msg_Sloc := Sloc (Def_Id);
3472 Error_Msg_N ("matching subprogram #!", N);
3477 Hom_Id := Homonym (Hom_Id);
3480 -- See if we found an entry
3483 if not Ambiguous then
3484 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3486 ("pragma% cannot be given for generic subprogram");
3489 ("pragma% does not identify local subprogram");
3496 -- Import pragmas must be for imported entities
3498 if Prag_Id = Pragma_Import_Function
3500 Prag_Id = Pragma_Import_Procedure
3502 Prag_Id = Pragma_Import_Valued_Procedure
3504 if not Is_Imported (Ent) then
3506 ("pragma Import or Interface must precede pragma%");
3509 -- Here we have the Export case which can set the entity as exported
3511 -- But does not do so if the specified external name is null, since
3512 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3513 -- compatible) to request no external name.
3515 elsif Nkind (Arg_External) = N_String_Literal
3516 and then String_Length (Strval (Arg_External)) = 0
3520 -- In all other cases, set entity as exported
3523 Set_Exported (Ent, Arg_Internal);
3526 -- Special processing for Valued_Procedure cases
3528 if Prag_Id = Pragma_Import_Valued_Procedure
3530 Prag_Id = Pragma_Export_Valued_Procedure
3532 Formal := First_Formal (Ent);
3535 Error_Pragma ("at least one parameter required for pragma%");
3537 elsif Ekind (Formal) /= E_Out_Parameter then
3538 Error_Pragma ("first parameter must have mode out for pragma%");
3541 Set_Is_Valued_Procedure (Ent);
3545 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3547 -- Process Result_Mechanism argument if present. We have already
3548 -- checked that this is only allowed for the function case.
3550 if Present (Arg_Result_Mechanism) then
3551 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3554 -- Process Mechanism parameter if present. Note that this parameter
3555 -- is not analyzed, and must not be analyzed since it is semantic
3556 -- nonsense, so we get it in exactly as the parser left it.
3558 if Present (Arg_Mechanism) then
3566 -- A single mechanism association without a formal parameter
3567 -- name is parsed as a parenthesized expression. All other
3568 -- cases are parsed as aggregates, so we rewrite the single
3569 -- parameter case as an aggregate for consistency.
3571 if Nkind (Arg_Mechanism) /= N_Aggregate
3572 and then Paren_Count (Arg_Mechanism) = 1
3574 Rewrite (Arg_Mechanism,
3575 Make_Aggregate (Sloc (Arg_Mechanism),
3576 Expressions => New_List (
3577 Relocate_Node (Arg_Mechanism))));
3580 -- Case of only mechanism name given, applies to all formals
3582 if Nkind (Arg_Mechanism) /= N_Aggregate then
3583 Formal := First_Formal (Ent);
3584 while Present (Formal) loop
3585 Set_Mechanism_Value (Formal, Arg_Mechanism);
3586 Next_Formal (Formal);
3589 -- Case of list of mechanism associations given
3592 if Null_Record_Present (Arg_Mechanism) then
3594 ("inappropriate form for Mechanism parameter",
3598 -- Deal with positional ones first
3600 Formal := First_Formal (Ent);
3602 if Present (Expressions (Arg_Mechanism)) then
3603 Mname := First (Expressions (Arg_Mechanism));
3604 while Present (Mname) loop
3607 ("too many mechanism associations", Mname);
3610 Set_Mechanism_Value (Formal, Mname);
3611 Next_Formal (Formal);
3616 -- Deal with named entries
3618 if Present (Component_Associations (Arg_Mechanism)) then
3619 Massoc := First (Component_Associations (Arg_Mechanism));
3620 while Present (Massoc) loop
3621 Choice := First (Choices (Massoc));
3623 if Nkind (Choice) /= N_Identifier
3624 or else Present (Next (Choice))
3627 ("incorrect form for mechanism association",
3631 Formal := First_Formal (Ent);
3635 ("parameter name & not present", Choice);
3638 if Chars (Choice) = Chars (Formal) then
3640 (Formal, Expression (Massoc));
3642 -- Set entity on identifier for ASIS
3644 Set_Entity (Choice, Formal);
3649 Next_Formal (Formal);
3659 -- Process First_Optional_Parameter argument if present. We have
3660 -- already checked that this is only allowed for the Import case.
3662 if Present (Arg_First_Optional_Parameter) then
3663 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3665 ("first optional parameter must be formal parameter name",
3666 Arg_First_Optional_Parameter);
3669 Formal := First_Formal (Ent);
3673 ("specified formal parameter& not found",
3674 Arg_First_Optional_Parameter);
3677 exit when Chars (Formal) =
3678 Chars (Arg_First_Optional_Parameter);
3680 Next_Formal (Formal);
3683 Set_First_Optional_Parameter (Ent, Formal);
3685 -- Check specified and all remaining formals have right form
3687 while Present (Formal) loop
3688 if Ekind (Formal) /= E_In_Parameter then
3690 ("optional formal& is not of mode in!",
3691 Arg_First_Optional_Parameter, Formal);
3694 Dval := Default_Value (Formal);
3698 ("optional formal& does not have default value!",
3699 Arg_First_Optional_Parameter, Formal);
3701 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3706 ("default value for optional formal& is non-static!",
3707 Arg_First_Optional_Parameter, Formal);
3711 Set_Is_Optional_Parameter (Formal);
3712 Next_Formal (Formal);
3715 end Process_Extended_Import_Export_Subprogram_Pragma;
3717 --------------------------
3718 -- Process_Generic_List --
3719 --------------------------
3721 procedure Process_Generic_List is
3726 Check_No_Identifiers;
3727 Check_At_Least_N_Arguments (1);
3730 while Present (Arg) loop
3731 Exp := Get_Pragma_Arg (Arg);
3734 if not Is_Entity_Name (Exp)
3736 (not Is_Generic_Instance (Entity (Exp))
3738 not Is_Generic_Unit (Entity (Exp)))
3741 ("pragma% argument must be name of generic unit/instance",
3747 end Process_Generic_List;
3749 ---------------------------------
3750 -- Process_Import_Or_Interface --
3751 ---------------------------------
3753 procedure Process_Import_Or_Interface is
3759 Process_Convention (C, Def_Id);
3760 Kill_Size_Check_Code (Def_Id);
3761 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
3763 if Ekind_In (Def_Id, E_Variable, E_Constant) then
3765 -- We do not permit Import to apply to a renaming declaration
3767 if Present (Renamed_Object (Def_Id)) then
3769 ("pragma% not allowed for object renaming", Arg2);
3771 -- User initialization is not allowed for imported object, but
3772 -- the object declaration may contain a default initialization,
3773 -- that will be discarded. Note that an explicit initialization
3774 -- only counts if it comes from source, otherwise it is simply
3775 -- the code generator making an implicit initialization explicit.
3777 elsif Present (Expression (Parent (Def_Id)))
3778 and then Comes_From_Source (Expression (Parent (Def_Id)))
3780 Error_Msg_Sloc := Sloc (Def_Id);
3782 ("no initialization allowed for declaration of& #",
3783 "\imported entities cannot be initialized (RM B.1(24))",
3787 Set_Imported (Def_Id);
3788 Process_Interface_Name (Def_Id, Arg3, Arg4);
3790 -- Note that we do not set Is_Public here. That's because we
3791 -- only want to set it if there is no address clause, and we
3792 -- don't know that yet, so we delay that processing till
3795 -- pragma Import completes deferred constants
3797 if Ekind (Def_Id) = E_Constant then
3798 Set_Has_Completion (Def_Id);
3801 -- It is not possible to import a constant of an unconstrained
3802 -- array type (e.g. string) because there is no simple way to
3803 -- write a meaningful subtype for it.
3805 if Is_Array_Type (Etype (Def_Id))
3806 and then not Is_Constrained (Etype (Def_Id))
3809 ("imported constant& must have a constrained subtype",
3814 elsif Is_Subprogram (Def_Id)
3815 or else Is_Generic_Subprogram (Def_Id)
3817 -- If the name is overloaded, pragma applies to all of the
3818 -- denoted entities in the same declarative part.
3821 while Present (Hom_Id) loop
3822 Def_Id := Get_Base_Subprogram (Hom_Id);
3824 -- Ignore inherited subprograms because the pragma will
3825 -- apply to the parent operation, which is the one called.
3827 if Is_Overloadable (Def_Id)
3828 and then Present (Alias (Def_Id))
3832 -- If it is not a subprogram, it must be in an outer scope and
3833 -- pragma does not apply.
3835 elsif not Is_Subprogram (Def_Id)
3836 and then not Is_Generic_Subprogram (Def_Id)
3840 -- Verify that the homonym is in the same declarative part (not
3841 -- just the same scope).
3843 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3844 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3849 Set_Imported (Def_Id);
3851 -- Reject an Import applied to an abstract subprogram
3853 if Is_Subprogram (Def_Id)
3854 and then Is_Abstract_Subprogram (Def_Id)
3856 Error_Msg_Sloc := Sloc (Def_Id);
3858 ("cannot import abstract subprogram& declared#",
3862 -- Special processing for Convention_Intrinsic
3864 if C = Convention_Intrinsic then
3866 -- Link_Name argument not allowed for intrinsic
3869 and then Chars (Arg3) = Name_Link_Name
3874 if Present (Arg4) then
3876 ("Link_Name argument not allowed for " &
3881 Set_Is_Intrinsic_Subprogram (Def_Id);
3883 -- If no external name is present, then check that this
3884 -- is a valid intrinsic subprogram. If an external name
3885 -- is present, then this is handled by the back end.
3888 Check_Intrinsic_Subprogram
3889 (Def_Id, Get_Pragma_Arg (Arg2));
3893 -- All interfaced procedures need an external symbol created
3894 -- for them since they are always referenced from another
3897 Set_Is_Public (Def_Id);
3899 -- Verify that the subprogram does not have a completion
3900 -- through a renaming declaration. For other completions the
3901 -- pragma appears as a too late representation.
3904 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3908 and then Nkind (Decl) = N_Subprogram_Declaration
3909 and then Present (Corresponding_Body (Decl))
3910 and then Nkind (Unit_Declaration_Node
3911 (Corresponding_Body (Decl))) =
3912 N_Subprogram_Renaming_Declaration
3914 Error_Msg_Sloc := Sloc (Def_Id);
3916 ("cannot import&, renaming already provided for " &
3917 "declaration #", N, Def_Id);
3921 Set_Has_Completion (Def_Id);
3922 Process_Interface_Name (Def_Id, Arg3, Arg4);
3925 if Is_Compilation_Unit (Hom_Id) then
3927 -- Its possible homonyms are not affected by the pragma.
3928 -- Such homonyms might be present in the context of other
3929 -- units being compiled.
3934 Hom_Id := Homonym (Hom_Id);
3938 -- When the convention is Java or CIL, we also allow Import to be
3939 -- given for packages, generic packages, exceptions, record
3940 -- components, and access to subprograms.
3942 elsif (C = Convention_Java or else C = Convention_CIL)
3944 (Is_Package_Or_Generic_Package (Def_Id)
3945 or else Ekind (Def_Id) = E_Exception
3946 or else Ekind (Def_Id) = E_Access_Subprogram_Type
3947 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3949 Set_Imported (Def_Id);
3950 Set_Is_Public (Def_Id);
3951 Process_Interface_Name (Def_Id, Arg3, Arg4);
3953 -- Import a CPP class
3955 elsif Is_Record_Type (Def_Id)
3956 and then C = Convention_CPP
3958 -- Types treated as CPP classes are treated as limited, but we
3959 -- don't require them to be declared this way. A warning is
3960 -- issued to encourage the user to declare them as limited.
3961 -- This is not an error, for compatibility reasons, because
3962 -- these types have been supported this way for some time.
3964 if not Is_Limited_Type (Def_Id) then
3966 ("imported 'C'P'P type should be " &
3967 "explicitly declared limited?",
3968 Get_Pragma_Arg (Arg2));
3970 ("\type will be considered limited",
3971 Get_Pragma_Arg (Arg2));
3974 Set_Is_CPP_Class (Def_Id);
3975 Set_Is_Limited_Record (Def_Id);
3977 -- Imported CPP types must not have discriminants (because C++
3978 -- classes do not have discriminants).
3980 if Has_Discriminants (Def_Id) then
3982 ("imported 'C'P'P type cannot have discriminants",
3983 First (Discriminant_Specifications
3984 (Declaration_Node (Def_Id))));
3987 -- Components of imported CPP types must not have default
3988 -- expressions because the constructor (if any) is on the
3992 Tdef : constant Node_Id :=
3993 Type_Definition (Declaration_Node (Def_Id));
3998 if Nkind (Tdef) = N_Record_Definition then
3999 Clist := Component_List (Tdef);
4002 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4003 Clist := Component_List (Record_Extension_Part (Tdef));
4006 if Present (Clist) then
4007 Comp := First (Component_Items (Clist));
4008 while Present (Comp) loop
4009 if Present (Expression (Comp)) then
4011 ("component of imported 'C'P'P type cannot have" &
4012 " default expression", Expression (Comp));
4022 ("second argument of pragma% must be object or subprogram",
4026 -- If this pragma applies to a compilation unit, then the unit, which
4027 -- is a subprogram, does not require (or allow) a body. We also do
4028 -- not need to elaborate imported procedures.
4030 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4032 Cunit : constant Node_Id := Parent (Parent (N));
4034 Set_Body_Required (Cunit, False);
4037 end Process_Import_Or_Interface;
4039 --------------------
4040 -- Process_Inline --
4041 --------------------
4043 procedure Process_Inline (Active : Boolean) is
4049 Effective : Boolean := False;
4051 procedure Make_Inline (Subp : Entity_Id);
4052 -- Subp is the defining unit name of the subprogram declaration. Set
4053 -- the flag, as well as the flag in the corresponding body, if there
4056 procedure Set_Inline_Flags (Subp : Entity_Id);
4057 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4058 -- Has_Pragma_Inline_Always for the Inline_Always case.
4060 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4061 -- Returns True if it can be determined at this stage that inlining
4062 -- is not possible, for example if the body is available and contains
4063 -- exception handlers, we prevent inlining, since otherwise we can
4064 -- get undefined symbols at link time. This function also emits a
4065 -- warning if front-end inlining is enabled and the pragma appears
4068 -- ??? is business with link symbols still valid, or does it relate
4069 -- to front end ZCX which is being phased out ???
4071 ---------------------------
4072 -- Inlining_Not_Possible --
4073 ---------------------------
4075 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4076 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4080 if Nkind (Decl) = N_Subprogram_Body then
4081 Stats := Handled_Statement_Sequence (Decl);
4082 return Present (Exception_Handlers (Stats))
4083 or else Present (At_End_Proc (Stats));
4085 elsif Nkind (Decl) = N_Subprogram_Declaration
4086 and then Present (Corresponding_Body (Decl))
4088 if Front_End_Inlining
4089 and then Analyzed (Corresponding_Body (Decl))
4091 Error_Msg_N ("pragma appears too late, ignored?", N);
4094 -- If the subprogram is a renaming as body, the body is just a
4095 -- call to the renamed subprogram, and inlining is trivially
4099 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4100 N_Subprogram_Renaming_Declaration
4106 Handled_Statement_Sequence
4107 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4110 Present (Exception_Handlers (Stats))
4111 or else Present (At_End_Proc (Stats));
4115 -- If body is not available, assume the best, the check is
4116 -- performed again when compiling enclosing package bodies.
4120 end Inlining_Not_Possible;
4126 procedure Make_Inline (Subp : Entity_Id) is
4127 Kind : constant Entity_Kind := Ekind (Subp);
4128 Inner_Subp : Entity_Id := Subp;
4131 -- Ignore if bad type, avoid cascaded error
4133 if Etype (Subp) = Any_Type then
4137 -- Ignore if all inlining is suppressed
4139 elsif Suppress_All_Inlining then
4143 -- If inlining is not possible, for now do not treat as an error
4145 elsif Inlining_Not_Possible (Subp) then
4149 -- Here we have a candidate for inlining, but we must exclude
4150 -- derived operations. Otherwise we would end up trying to inline
4151 -- a phantom declaration, and the result would be to drag in a
4152 -- body which has no direct inlining associated with it. That
4153 -- would not only be inefficient but would also result in the
4154 -- backend doing cross-unit inlining in cases where it was
4155 -- definitely inappropriate to do so.
4157 -- However, a simple Comes_From_Source test is insufficient, since
4158 -- we do want to allow inlining of generic instances which also do
4159 -- not come from source. We also need to recognize specs generated
4160 -- by the front-end for bodies that carry the pragma. Finally,
4161 -- predefined operators do not come from source but are not
4162 -- inlineable either.
4164 elsif Is_Generic_Instance (Subp)
4165 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4169 elsif not Comes_From_Source (Subp)
4170 and then Scope (Subp) /= Standard_Standard
4176 -- The referenced entity must either be the enclosing entity, or
4177 -- an entity declared within the current open scope.
4179 if Present (Scope (Subp))
4180 and then Scope (Subp) /= Current_Scope
4181 and then Subp /= Current_Scope
4184 ("argument of% must be entity in current scope", Assoc);
4188 -- Processing for procedure, operator or function. If subprogram
4189 -- is aliased (as for an instance) indicate that the renamed
4190 -- entity (if declared in the same unit) is inlined.
4192 if Is_Subprogram (Subp) then
4198 Inner_Subp := Ultimate_Alias (Inner_Subp);
4200 if In_Same_Source_Unit (Subp, Inner_Subp) then
4201 Set_Inline_Flags (Inner_Subp);
4203 Decl := Parent (Parent (Inner_Subp));
4205 if Nkind (Decl) = N_Subprogram_Declaration
4206 and then Present (Corresponding_Body (Decl))
4208 Set_Inline_Flags (Corresponding_Body (Decl));
4210 elsif Is_Generic_Instance (Subp) then
4212 -- Indicate that the body needs to be created for
4213 -- inlining subsequent calls. The instantiation node
4214 -- follows the declaration of the wrapper package
4217 if Scope (Subp) /= Standard_Standard
4219 Need_Subprogram_Instance_Body
4220 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4230 -- For a generic subprogram set flag as well, for use at the point
4231 -- of instantiation, to determine whether the body should be
4234 elsif Is_Generic_Subprogram (Subp) then
4235 Set_Inline_Flags (Subp);
4238 -- Literals are by definition inlined
4240 elsif Kind = E_Enumeration_Literal then
4243 -- Anything else is an error
4247 ("expect subprogram name for pragma%", Assoc);
4251 ----------------------
4252 -- Set_Inline_Flags --
4253 ----------------------
4255 procedure Set_Inline_Flags (Subp : Entity_Id) is
4258 Set_Is_Inlined (Subp, Sense);
4261 if not Has_Pragma_Inline (Subp) then
4262 Set_Has_Pragma_Inline (Subp, Sense);
4266 if Prag_Id = Pragma_Inline_Always then
4267 Set_Has_Pragma_Inline_Always (Subp, Sense);
4269 end Set_Inline_Flags;
4271 -- Start of processing for Process_Inline
4274 Check_No_Identifiers;
4275 Check_At_Least_N_Arguments (1);
4278 Inline_Processing_Required := True;
4282 while Present (Assoc) loop
4283 Subp_Id := Get_Pragma_Arg (Assoc);
4287 if Is_Entity_Name (Subp_Id) then
4288 Subp := Entity (Subp_Id);
4290 if Subp = Any_Id then
4292 -- If previous error, avoid cascaded errors
4300 if not From_Aspect_Specification (N) then
4301 while Present (Homonym (Subp))
4302 and then Scope (Homonym (Subp)) = Current_Scope
4304 Make_Inline (Homonym (Subp));
4305 Subp := Homonym (Subp);
4313 ("inappropriate argument for pragma%", Assoc);
4316 and then Warn_On_Redundant_Constructs
4317 and then not Suppress_All_Inlining
4319 if Inlining_Not_Possible (Subp) then
4321 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4324 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4332 ----------------------------
4333 -- Process_Interface_Name --
4334 ----------------------------
4336 procedure Process_Interface_Name
4337 (Subprogram_Def : Entity_Id;
4343 String_Val : String_Id;
4345 procedure Check_Form_Of_Interface_Name
4347 Ext_Name_Case : Boolean);
4348 -- SN is a string literal node for an interface name. This routine
4349 -- performs some minimal checks that the name is reasonable. In
4350 -- particular that no spaces or other obviously incorrect characters
4351 -- appear. This is only a warning, since any characters are allowed.
4352 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4354 ----------------------------------
4355 -- Check_Form_Of_Interface_Name --
4356 ----------------------------------
4358 procedure Check_Form_Of_Interface_Name
4360 Ext_Name_Case : Boolean)
4362 S : constant String_Id := Strval (Expr_Value_S (SN));
4363 SL : constant Nat := String_Length (S);
4368 Error_Msg_N ("interface name cannot be null string", SN);
4371 for J in 1 .. SL loop
4372 C := Get_String_Char (S, J);
4374 -- Look for dubious character and issue unconditional warning.
4375 -- Definitely dubious if not in character range.
4377 if not In_Character_Range (C)
4379 -- For all cases except CLI target,
4380 -- commas, spaces and slashes are dubious (in CLI, we use
4381 -- commas and backslashes in external names to specify
4382 -- assembly version and public key, while slashes and spaces
4383 -- can be used in names to mark nested classes and
4386 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4387 and then (Get_Character (C) = ','
4389 Get_Character (C) = '\'))
4390 or else (VM_Target /= CLI_Target
4391 and then (Get_Character (C) = ' '
4393 Get_Character (C) = '/'))
4396 ("?interface name contains illegal character",
4397 Sloc (SN) + Source_Ptr (J));
4400 end Check_Form_Of_Interface_Name;
4402 -- Start of processing for Process_Interface_Name
4405 if No (Link_Arg) then
4406 if No (Ext_Arg) then
4407 if VM_Target = CLI_Target
4408 and then Ekind (Subprogram_Def) = E_Package
4409 and then Nkind (Parent (Subprogram_Def)) =
4410 N_Package_Specification
4411 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4416 (Generic_Parent (Parent (Subprogram_Def))));
4421 elsif Chars (Ext_Arg) = Name_Link_Name then
4423 Link_Nam := Expression (Ext_Arg);
4426 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4427 Ext_Nam := Expression (Ext_Arg);
4432 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4433 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4434 Ext_Nam := Expression (Ext_Arg);
4435 Link_Nam := Expression (Link_Arg);
4438 -- Check expressions for external name and link name are static
4440 if Present (Ext_Nam) then
4441 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4442 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4444 -- Verify that external name is not the name of a local entity,
4445 -- which would hide the imported one and could lead to run-time
4446 -- surprises. The problem can only arise for entities declared in
4447 -- a package body (otherwise the external name is fully qualified
4448 -- and will not conflict).
4456 if Prag_Id = Pragma_Import then
4457 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4459 E := Entity_Id (Get_Name_Table_Info (Nam));
4461 if Nam /= Chars (Subprogram_Def)
4462 and then Present (E)
4463 and then not Is_Overloadable (E)
4464 and then Is_Immediately_Visible (E)
4465 and then not Is_Imported (E)
4466 and then Ekind (Scope (E)) = E_Package
4469 while Present (Par) loop
4470 if Nkind (Par) = N_Package_Body then
4471 Error_Msg_Sloc := Sloc (E);
4473 ("imported entity is hidden by & declared#",
4478 Par := Parent (Par);
4485 if Present (Link_Nam) then
4486 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4487 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4490 -- If there is no link name, just set the external name
4492 if No (Link_Nam) then
4493 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4495 -- For the Link_Name case, the given literal is preceded by an
4496 -- asterisk, which indicates to GCC that the given name should be
4497 -- taken literally, and in particular that no prepending of
4498 -- underlines should occur, even in systems where this is the
4504 if VM_Target = No_VM then
4505 Store_String_Char (Get_Char_Code ('*'));
4508 String_Val := Strval (Expr_Value_S (Link_Nam));
4509 Store_String_Chars (String_Val);
4511 Make_String_Literal (Sloc (Link_Nam),
4512 Strval => End_String);
4515 Set_Encoded_Interface_Name
4516 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4518 -- We allow duplicated export names in CIL, as they are always
4519 -- enclosed in a namespace that differentiates them, and overloaded
4520 -- entities are supported by the VM.
4522 if Convention (Subprogram_Def) /= Convention_CIL then
4523 Check_Duplicated_Export_Name (Link_Nam);
4525 end Process_Interface_Name;
4527 -----------------------------------------
4528 -- Process_Interrupt_Or_Attach_Handler --
4529 -----------------------------------------
4531 procedure Process_Interrupt_Or_Attach_Handler is
4532 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4533 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4534 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4537 Set_Is_Interrupt_Handler (Handler_Proc);
4539 -- If the pragma is not associated with a handler procedure within a
4540 -- protected type, then it must be for a nonprotected procedure for
4541 -- the AAMP target, in which case we don't associate a representation
4542 -- item with the procedure's scope.
4544 if Ekind (Proc_Scope) = E_Protected_Type then
4545 if Prag_Id = Pragma_Interrupt_Handler
4547 Prag_Id = Pragma_Attach_Handler
4549 Record_Rep_Item (Proc_Scope, N);
4552 end Process_Interrupt_Or_Attach_Handler;
4554 --------------------------------------------------
4555 -- Process_Restrictions_Or_Restriction_Warnings --
4556 --------------------------------------------------
4558 -- Note: some of the simple identifier cases were handled in par-prag,
4559 -- but it is harmless (and more straightforward) to simply handle all
4560 -- cases here, even if it means we repeat a bit of work in some cases.
4562 procedure Process_Restrictions_Or_Restriction_Warnings
4566 R_Id : Restriction_Id;
4571 procedure Check_Unit_Name (N : Node_Id);
4572 -- Checks unit name parameter for No_Dependence. Returns if it has
4573 -- an appropriate form, otherwise raises pragma argument error.
4575 ---------------------
4576 -- Check_Unit_Name --
4577 ---------------------
4579 procedure Check_Unit_Name (N : Node_Id) is
4581 if Nkind (N) = N_Selected_Component then
4582 Check_Unit_Name (Prefix (N));
4583 Check_Unit_Name (Selector_Name (N));
4585 elsif Nkind (N) = N_Identifier then
4590 ("wrong form for unit name for No_Dependence", N);
4592 end Check_Unit_Name;
4594 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4597 Check_Ada_83_Warning;
4598 Check_At_Least_N_Arguments (1);
4599 Check_Valid_Configuration_Pragma;
4602 while Present (Arg) loop
4604 Expr := Get_Pragma_Arg (Arg);
4606 -- Case of no restriction identifier present
4608 if Id = No_Name then
4609 if Nkind (Expr) /= N_Identifier then
4611 ("invalid form for restriction", Arg);
4616 (Process_Restriction_Synonyms (Expr));
4618 if R_Id not in All_Boolean_Restrictions then
4619 Error_Msg_Name_1 := Pname;
4621 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4623 -- Check for possible misspelling
4625 for J in Restriction_Id loop
4627 Rnm : constant String := Restriction_Id'Image (J);
4630 Name_Buffer (1 .. Rnm'Length) := Rnm;
4631 Name_Len := Rnm'Length;
4632 Set_Casing (All_Lower_Case);
4634 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4636 (Identifier_Casing (Current_Source_File));
4637 Error_Msg_String (1 .. Rnm'Length) :=
4638 Name_Buffer (1 .. Name_Len);
4639 Error_Msg_Strlen := Rnm'Length;
4640 Error_Msg_N -- CODEFIX
4641 ("\possible misspelling of ""~""",
4642 Get_Pragma_Arg (Arg));
4651 if Implementation_Restriction (R_Id) then
4652 Check_Restriction (No_Implementation_Restrictions, Arg);
4655 -- If this is a warning, then set the warning unless we already
4656 -- have a real restriction active (we never want a warning to
4657 -- override a real restriction).
4660 if not Restriction_Active (R_Id) then
4661 Set_Restriction (R_Id, N);
4662 Restriction_Warnings (R_Id) := True;
4665 -- If real restriction case, then set it and make sure that the
4666 -- restriction warning flag is off, since a real restriction
4667 -- always overrides a warning.
4670 Set_Restriction (R_Id, N);
4671 Restriction_Warnings (R_Id) := False;
4674 -- Check for obsolescent restrictions in Ada 2005 mode
4677 and then Ada_Version >= Ada_2005
4678 and then (R_Id = No_Asynchronous_Control
4680 R_Id = No_Unchecked_Deallocation
4682 R_Id = No_Unchecked_Conversion)
4684 Check_Restriction (No_Obsolescent_Features, N);
4687 -- A very special case that must be processed here: pragma
4688 -- Restrictions (No_Exceptions) turns off all run-time
4689 -- checking. This is a bit dubious in terms of the formal
4690 -- language definition, but it is what is intended by RM
4691 -- H.4(12). Restriction_Warnings never affects generated code
4692 -- so this is done only in the real restriction case.
4694 if R_Id = No_Exceptions and then not Warn then
4695 Scope_Suppress := (others => True);
4698 -- Case of No_Dependence => unit-name. Note that the parser
4699 -- already made the necessary entry in the No_Dependence table.
4701 elsif Id = Name_No_Dependence then
4702 Check_Unit_Name (Expr);
4704 -- All other cases of restriction identifier present
4707 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4708 Analyze_And_Resolve (Expr, Any_Integer);
4710 if R_Id not in All_Parameter_Restrictions then
4712 ("invalid restriction parameter identifier", Arg);
4714 elsif not Is_OK_Static_Expression (Expr) then
4715 Flag_Non_Static_Expr
4716 ("value must be static expression!", Expr);
4719 elsif not Is_Integer_Type (Etype (Expr))
4720 or else Expr_Value (Expr) < 0
4723 ("value must be non-negative integer", Arg);
4726 -- Restriction pragma is active
4728 Val := Expr_Value (Expr);
4730 if not UI_Is_In_Int_Range (Val) then
4732 ("pragma ignored, value too large?", Arg);
4735 -- Warning case. If the real restriction is active, then we
4736 -- ignore the request, since warning never overrides a real
4737 -- restriction. Otherwise we set the proper warning. Note that
4738 -- this circuit sets the warning again if it is already set,
4739 -- which is what we want, since the constant may have changed.
4742 if not Restriction_Active (R_Id) then
4744 (R_Id, N, Integer (UI_To_Int (Val)));
4745 Restriction_Warnings (R_Id) := True;
4748 -- Real restriction case, set restriction and make sure warning
4749 -- flag is off since real restriction always overrides warning.
4752 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4753 Restriction_Warnings (R_Id) := False;
4759 end Process_Restrictions_Or_Restriction_Warnings;
4761 ---------------------------------
4762 -- Process_Suppress_Unsuppress --
4763 ---------------------------------
4765 -- Note: this procedure makes entries in the check suppress data
4766 -- structures managed by Sem. See spec of package Sem for full
4767 -- details on how we handle recording of check suppression.
4769 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4774 In_Package_Spec : constant Boolean :=
4775 Is_Package_Or_Generic_Package (Current_Scope)
4776 and then not In_Package_Body (Current_Scope);
4778 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4779 -- Used to suppress a single check on the given entity
4781 --------------------------------
4782 -- Suppress_Unsuppress_Echeck --
4783 --------------------------------
4785 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4787 Set_Checks_May_Be_Suppressed (E);
4789 if In_Package_Spec then
4790 Push_Global_Suppress_Stack_Entry
4793 Suppress => Suppress_Case);
4796 Push_Local_Suppress_Stack_Entry
4799 Suppress => Suppress_Case);
4802 -- If this is a first subtype, and the base type is distinct,
4803 -- then also set the suppress flags on the base type.
4805 if Is_First_Subtype (E)
4806 and then Etype (E) /= E
4808 Suppress_Unsuppress_Echeck (Etype (E), C);
4810 end Suppress_Unsuppress_Echeck;
4812 -- Start of processing for Process_Suppress_Unsuppress
4815 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
4816 -- we want to generate checks for analysis purposes, as set by -gnatC
4818 if CodePeer_Mode and then Comes_From_Source (N) then
4822 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
4823 -- declarative part or a package spec (RM 11.5(5)).
4825 if not Is_Configuration_Pragma then
4826 Check_Is_In_Decl_Part_Or_Package_Spec;
4829 Check_At_Least_N_Arguments (1);
4830 Check_At_Most_N_Arguments (2);
4831 Check_No_Identifier (Arg1);
4832 Check_Arg_Is_Identifier (Arg1);
4834 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
4836 if C = No_Check_Id then
4838 ("argument of pragma% is not valid check name", Arg1);
4841 if not Suppress_Case
4842 and then (C = All_Checks or else C = Overflow_Check)
4844 Opt.Overflow_Checks_Unsuppressed := True;
4847 if Arg_Count = 1 then
4849 -- Make an entry in the local scope suppress table. This is the
4850 -- table that directly shows the current value of the scope
4851 -- suppress check for any check id value.
4853 if C = All_Checks then
4855 -- For All_Checks, we set all specific predefined checks with
4856 -- the exception of Elaboration_Check, which is handled
4857 -- specially because of not wanting All_Checks to have the
4858 -- effect of deactivating static elaboration order processing.
4860 for J in Scope_Suppress'Range loop
4861 if J /= Elaboration_Check then
4862 Scope_Suppress (J) := Suppress_Case;
4866 -- If not All_Checks, and predefined check, then set appropriate
4867 -- scope entry. Note that we will set Elaboration_Check if this
4868 -- is explicitly specified.
4870 elsif C in Predefined_Check_Id then
4871 Scope_Suppress (C) := Suppress_Case;
4874 -- Also make an entry in the Local_Entity_Suppress table
4876 Push_Local_Suppress_Stack_Entry
4879 Suppress => Suppress_Case);
4881 -- Case of two arguments present, where the check is suppressed for
4882 -- a specified entity (given as the second argument of the pragma)
4885 -- This is obsolescent in Ada 2005 mode
4887 if Ada_Version >= Ada_2005 then
4888 Check_Restriction (No_Obsolescent_Features, Arg2);
4891 Check_Optional_Identifier (Arg2, Name_On);
4892 E_Id := Get_Pragma_Arg (Arg2);
4895 if not Is_Entity_Name (E_Id) then
4897 ("second argument of pragma% must be entity name", Arg2);
4906 -- Enforce RM 11.5(7) which requires that for a pragma that
4907 -- appears within a package spec, the named entity must be
4908 -- within the package spec. We allow the package name itself
4909 -- to be mentioned since that makes sense, although it is not
4910 -- strictly allowed by 11.5(7).
4913 and then E /= Current_Scope
4914 and then Scope (E) /= Current_Scope
4917 ("entity in pragma% is not in package spec (RM 11.5(7))",
4921 -- Loop through homonyms. As noted below, in the case of a package
4922 -- spec, only homonyms within the package spec are considered.
4925 Suppress_Unsuppress_Echeck (E, C);
4927 if Is_Generic_Instance (E)
4928 and then Is_Subprogram (E)
4929 and then Present (Alias (E))
4931 Suppress_Unsuppress_Echeck (Alias (E), C);
4934 -- Move to next homonym if not aspect spec case
4936 exit when From_Aspect_Specification (N);
4940 -- If we are within a package specification, the pragma only
4941 -- applies to homonyms in the same scope.
4943 exit when In_Package_Spec
4944 and then Scope (E) /= Current_Scope;
4947 end Process_Suppress_Unsuppress;
4953 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
4955 if Is_Imported (E) then
4957 ("cannot export entity& that was previously imported", Arg);
4959 elsif Present (Address_Clause (E)) then
4961 ("cannot export entity& that has an address clause", Arg);
4964 Set_Is_Exported (E);
4966 -- Generate a reference for entity explicitly, because the
4967 -- identifier may be overloaded and name resolution will not
4970 Generate_Reference (E, Arg);
4972 -- Deal with exporting non-library level entity
4974 if not Is_Library_Level_Entity (E) then
4976 -- Not allowed at all for subprograms
4978 if Is_Subprogram (E) then
4979 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
4981 -- Otherwise set public and statically allocated
4985 Set_Is_Statically_Allocated (E);
4987 -- Warn if the corresponding W flag is set and the pragma comes
4988 -- from source. The latter may not be true e.g. on VMS where we
4989 -- expand export pragmas for exception codes associated with
4990 -- imported or exported exceptions. We do not want to generate
4991 -- a warning for something that the user did not write.
4993 if Warn_On_Export_Import
4994 and then Comes_From_Source (Arg)
4997 ("?& has been made static as a result of Export", Arg, E);
4999 ("\this usage is non-standard and non-portable", Arg);
5004 if Warn_On_Export_Import and then Is_Type (E) then
5005 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5008 if Warn_On_Export_Import and Inside_A_Generic then
5010 ("all instances of& will have the same external name?", Arg, E);
5014 ----------------------------------------------
5015 -- Set_Extended_Import_Export_External_Name --
5016 ----------------------------------------------
5018 procedure Set_Extended_Import_Export_External_Name
5019 (Internal_Ent : Entity_Id;
5020 Arg_External : Node_Id)
5022 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5026 if No (Arg_External) then
5030 Check_Arg_Is_External_Name (Arg_External);
5032 if Nkind (Arg_External) = N_String_Literal then
5033 if String_Length (Strval (Arg_External)) = 0 then
5036 New_Name := Adjust_External_Name_Case (Arg_External);
5039 elsif Nkind (Arg_External) = N_Identifier then
5040 New_Name := Get_Default_External_Name (Arg_External);
5042 -- Check_Arg_Is_External_Name should let through only identifiers and
5043 -- string literals or static string expressions (which are folded to
5044 -- string literals).
5047 raise Program_Error;
5050 -- If we already have an external name set (by a prior normal Import
5051 -- or Export pragma), then the external names must match
5053 if Present (Interface_Name (Internal_Ent)) then
5054 Check_Matching_Internal_Names : declare
5055 S1 : constant String_Id := Strval (Old_Name);
5056 S2 : constant String_Id := Strval (New_Name);
5059 -- Called if names do not match
5065 procedure Mismatch is
5067 Error_Msg_Sloc := Sloc (Old_Name);
5069 ("external name does not match that given #",
5073 -- Start of processing for Check_Matching_Internal_Names
5076 if String_Length (S1) /= String_Length (S2) then
5080 for J in 1 .. String_Length (S1) loop
5081 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5086 end Check_Matching_Internal_Names;
5088 -- Otherwise set the given name
5091 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5092 Check_Duplicated_Export_Name (New_Name);
5094 end Set_Extended_Import_Export_External_Name;
5100 procedure Set_Imported (E : Entity_Id) is
5102 -- Error message if already imported or exported
5104 if Is_Exported (E) or else Is_Imported (E) then
5106 -- Error if being set Exported twice
5108 if Is_Exported (E) then
5109 Error_Msg_NE ("entity& was previously exported", N, E);
5111 -- OK if Import/Interface case
5113 elsif Import_Interface_Present (N) then
5116 -- Error if being set Imported twice
5119 Error_Msg_NE ("entity& was previously imported", N, E);
5122 Error_Msg_Name_1 := Pname;
5124 ("\(pragma% applies to all previous entities)", N);
5126 Error_Msg_Sloc := Sloc (E);
5127 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5129 -- Here if not previously imported or exported, OK to import
5132 Set_Is_Imported (E);
5134 -- If the entity is an object that is not at the library level,
5135 -- then it is statically allocated. We do not worry about objects
5136 -- with address clauses in this context since they are not really
5137 -- imported in the linker sense.
5140 and then not Is_Library_Level_Entity (E)
5141 and then No (Address_Clause (E))
5143 Set_Is_Statically_Allocated (E);
5150 -------------------------
5151 -- Set_Mechanism_Value --
5152 -------------------------
5154 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5155 -- analyzed, since it is semantic nonsense), so we get it in the exact
5156 -- form created by the parser.
5158 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5161 Mech_Name_Id : Name_Id;
5163 procedure Bad_Class;
5164 -- Signal bad descriptor class name
5166 procedure Bad_Mechanism;
5167 -- Signal bad mechanism name
5173 procedure Bad_Class is
5175 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5178 -------------------------
5179 -- Bad_Mechanism_Value --
5180 -------------------------
5182 procedure Bad_Mechanism is
5184 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5187 -- Start of processing for Set_Mechanism_Value
5190 if Mechanism (Ent) /= Default_Mechanism then
5192 ("mechanism for & has already been set", Mech_Name, Ent);
5195 -- MECHANISM_NAME ::= value | reference | descriptor |
5198 if Nkind (Mech_Name) = N_Identifier then
5199 if Chars (Mech_Name) = Name_Value then
5200 Set_Mechanism (Ent, By_Copy);
5203 elsif Chars (Mech_Name) = Name_Reference then
5204 Set_Mechanism (Ent, By_Reference);
5207 elsif Chars (Mech_Name) = Name_Descriptor then
5208 Check_VMS (Mech_Name);
5210 -- Descriptor => Short_Descriptor if pragma was given
5212 if Short_Descriptors then
5213 Set_Mechanism (Ent, By_Short_Descriptor);
5215 Set_Mechanism (Ent, By_Descriptor);
5220 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5221 Check_VMS (Mech_Name);
5222 Set_Mechanism (Ent, By_Short_Descriptor);
5225 elsif Chars (Mech_Name) = Name_Copy then
5227 ("bad mechanism name, Value assumed", Mech_Name);
5233 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5234 -- short_descriptor (CLASS_NAME)
5235 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5237 -- Note: this form is parsed as an indexed component
5239 elsif Nkind (Mech_Name) = N_Indexed_Component then
5240 Class := First (Expressions (Mech_Name));
5242 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5243 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5244 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5245 or else Present (Next (Class))
5249 Mech_Name_Id := Chars (Prefix (Mech_Name));
5251 -- Change Descriptor => Short_Descriptor if pragma was given
5253 if Mech_Name_Id = Name_Descriptor
5254 and then Short_Descriptors
5256 Mech_Name_Id := Name_Short_Descriptor;
5260 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5261 -- short_descriptor (Class => CLASS_NAME)
5262 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5264 -- Note: this form is parsed as a function call
5266 elsif Nkind (Mech_Name) = N_Function_Call then
5267 Param := First (Parameter_Associations (Mech_Name));
5269 if Nkind (Name (Mech_Name)) /= N_Identifier
5270 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5271 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5272 or else Present (Next (Param))
5273 or else No (Selector_Name (Param))
5274 or else Chars (Selector_Name (Param)) /= Name_Class
5278 Class := Explicit_Actual_Parameter (Param);
5279 Mech_Name_Id := Chars (Name (Mech_Name));
5286 -- Fall through here with Class set to descriptor class name
5288 Check_VMS (Mech_Name);
5290 if Nkind (Class) /= N_Identifier then
5293 elsif Mech_Name_Id = Name_Descriptor
5294 and then Chars (Class) = Name_UBS
5296 Set_Mechanism (Ent, By_Descriptor_UBS);
5298 elsif Mech_Name_Id = Name_Descriptor
5299 and then Chars (Class) = Name_UBSB
5301 Set_Mechanism (Ent, By_Descriptor_UBSB);
5303 elsif Mech_Name_Id = Name_Descriptor
5304 and then Chars (Class) = Name_UBA
5306 Set_Mechanism (Ent, By_Descriptor_UBA);
5308 elsif Mech_Name_Id = Name_Descriptor
5309 and then Chars (Class) = Name_S
5311 Set_Mechanism (Ent, By_Descriptor_S);
5313 elsif Mech_Name_Id = Name_Descriptor
5314 and then Chars (Class) = Name_SB
5316 Set_Mechanism (Ent, By_Descriptor_SB);
5318 elsif Mech_Name_Id = Name_Descriptor
5319 and then Chars (Class) = Name_A
5321 Set_Mechanism (Ent, By_Descriptor_A);
5323 elsif Mech_Name_Id = Name_Descriptor
5324 and then Chars (Class) = Name_NCA
5326 Set_Mechanism (Ent, By_Descriptor_NCA);
5328 elsif Mech_Name_Id = Name_Short_Descriptor
5329 and then Chars (Class) = Name_UBS
5331 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5333 elsif Mech_Name_Id = Name_Short_Descriptor
5334 and then Chars (Class) = Name_UBSB
5336 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5338 elsif Mech_Name_Id = Name_Short_Descriptor
5339 and then Chars (Class) = Name_UBA
5341 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5343 elsif Mech_Name_Id = Name_Short_Descriptor
5344 and then Chars (Class) = Name_S
5346 Set_Mechanism (Ent, By_Short_Descriptor_S);
5348 elsif Mech_Name_Id = Name_Short_Descriptor
5349 and then Chars (Class) = Name_SB
5351 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5353 elsif Mech_Name_Id = Name_Short_Descriptor
5354 and then Chars (Class) = Name_A
5356 Set_Mechanism (Ent, By_Short_Descriptor_A);
5358 elsif Mech_Name_Id = Name_Short_Descriptor
5359 and then Chars (Class) = Name_NCA
5361 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5366 end Set_Mechanism_Value;
5368 ---------------------------
5369 -- Set_Ravenscar_Profile --
5370 ---------------------------
5372 -- The tasks to be done here are
5374 -- Set required policies
5376 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5377 -- pragma Locking_Policy (Ceiling_Locking)
5379 -- Set Detect_Blocking mode
5381 -- Set required restrictions (see System.Rident for detailed list)
5383 procedure Set_Ravenscar_Profile (N : Node_Id) is
5385 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5387 if Task_Dispatching_Policy /= ' '
5388 and then Task_Dispatching_Policy /= 'F'
5390 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5391 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5393 -- Set the FIFO_Within_Priorities policy, but always preserve
5394 -- System_Location since we like the error message with the run time
5398 Task_Dispatching_Policy := 'F';
5400 if Task_Dispatching_Policy_Sloc /= System_Location then
5401 Task_Dispatching_Policy_Sloc := Loc;
5405 -- pragma Locking_Policy (Ceiling_Locking)
5407 if Locking_Policy /= ' '
5408 and then Locking_Policy /= 'C'
5410 Error_Msg_Sloc := Locking_Policy_Sloc;
5411 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5413 -- Set the Ceiling_Locking policy, but preserve System_Location since
5414 -- we like the error message with the run time name.
5417 Locking_Policy := 'C';
5419 if Locking_Policy_Sloc /= System_Location then
5420 Locking_Policy_Sloc := Loc;
5424 -- pragma Detect_Blocking
5426 Detect_Blocking := True;
5428 -- Set the corresponding restrictions
5430 Set_Profile_Restrictions
5431 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5432 end Set_Ravenscar_Profile;
5434 -- Start of processing for Analyze_Pragma
5437 -- Deal with unrecognized pragma
5439 if not Is_Pragma_Name (Pname) then
5440 if Warn_On_Unrecognized_Pragma then
5441 Error_Msg_Name_1 := Pname;
5442 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5444 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5445 if Is_Bad_Spelling_Of (Pname, PN) then
5446 Error_Msg_Name_1 := PN;
5447 Error_Msg_N -- CODEFIX
5448 ("\?possible misspelling of %!", Pragma_Identifier (N));
5457 -- Here to start processing for recognized pragma
5459 Prag_Id := Get_Pragma_Id (Pname);
5468 if Present (Pragma_Argument_Associations (N)) then
5469 Arg1 := First (Pragma_Argument_Associations (N));
5471 if Present (Arg1) then
5472 Arg2 := Next (Arg1);
5474 if Present (Arg2) then
5475 Arg3 := Next (Arg2);
5477 if Present (Arg3) then
5478 Arg4 := Next (Arg3);
5484 -- Count number of arguments
5491 while Present (Arg_Node) loop
5492 Arg_Count := Arg_Count + 1;
5497 -- An enumeration type defines the pragmas that are supported by the
5498 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5499 -- into the corresponding enumeration value for the following case.
5507 -- pragma Abort_Defer;
5509 when Pragma_Abort_Defer =>
5511 Check_Arg_Count (0);
5513 -- The only required semantic processing is to check the
5514 -- placement. This pragma must appear at the start of the
5515 -- statement sequence of a handled sequence of statements.
5517 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5518 or else N /= First (Statements (Parent (N)))
5529 -- Note: this pragma also has some specific processing in Par.Prag
5530 -- because we want to set the Ada version mode during parsing.
5532 when Pragma_Ada_83 =>
5534 Check_Arg_Count (0);
5536 -- We really should check unconditionally for proper configuration
5537 -- pragma placement, since we really don't want mixed Ada modes
5538 -- within a single unit, and the GNAT reference manual has always
5539 -- said this was a configuration pragma, but we did not check and
5540 -- are hesitant to add the check now.
5542 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5543 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5544 -- or Ada 2012 mode.
5546 if Ada_Version >= Ada_2005 then
5547 Check_Valid_Configuration_Pragma;
5550 -- Now set Ada 83 mode
5552 Ada_Version := Ada_83;
5553 Ada_Version_Explicit := Ada_Version;
5561 -- Note: this pragma also has some specific processing in Par.Prag
5562 -- because we want to set the Ada 83 version mode during parsing.
5564 when Pragma_Ada_95 =>
5566 Check_Arg_Count (0);
5568 -- We really should check unconditionally for proper configuration
5569 -- pragma placement, since we really don't want mixed Ada modes
5570 -- within a single unit, and the GNAT reference manual has always
5571 -- said this was a configuration pragma, but we did not check and
5572 -- are hesitant to add the check now.
5574 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5575 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5577 if Ada_Version >= Ada_2005 then
5578 Check_Valid_Configuration_Pragma;
5581 -- Now set Ada 95 mode
5583 Ada_Version := Ada_95;
5584 Ada_Version_Explicit := Ada_Version;
5586 ---------------------
5587 -- Ada_05/Ada_2005 --
5588 ---------------------
5591 -- pragma Ada_05 (LOCAL_NAME);
5594 -- pragma Ada_2005 (LOCAL_NAME):
5596 -- Note: these pragmas also have some specific processing in Par.Prag
5597 -- because we want to set the Ada 2005 version mode during parsing.
5599 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5605 if Arg_Count = 1 then
5606 Check_Arg_Is_Local_Name (Arg1);
5607 E_Id := Get_Pragma_Arg (Arg1);
5609 if Etype (E_Id) = Any_Type then
5613 Set_Is_Ada_2005_Only (Entity (E_Id));
5616 Check_Arg_Count (0);
5618 -- For Ada_2005 we unconditionally enforce the documented
5619 -- configuration pragma placement, since we do not want to
5620 -- tolerate mixed modes in a unit involving Ada 2005. That
5621 -- would cause real difficulties for those cases where there
5622 -- are incompatibilities between Ada 95 and Ada 2005.
5624 Check_Valid_Configuration_Pragma;
5626 -- Now set appropriate Ada mode
5629 Ada_Version := Ada_2005;
5631 Ada_Version := Ada_Version_Default;
5634 Ada_Version_Explicit := Ada_2005;
5638 ---------------------
5639 -- Ada_12/Ada_2012 --
5640 ---------------------
5643 -- pragma Ada_12 (LOCAL_NAME);
5646 -- pragma Ada_2012 (LOCAL_NAME):
5648 -- Note: these pragmas also have some specific processing in Par.Prag
5649 -- because we want to set the Ada 2012 version mode during parsing.
5651 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5657 if Arg_Count = 1 then
5658 Check_Arg_Is_Local_Name (Arg1);
5659 E_Id := Get_Pragma_Arg (Arg1);
5661 if Etype (E_Id) = Any_Type then
5665 Set_Is_Ada_2012_Only (Entity (E_Id));
5668 Check_Arg_Count (0);
5670 -- For Ada_2012 we unconditionally enforce the documented
5671 -- configuration pragma placement, since we do not want to
5672 -- tolerate mixed modes in a unit involving Ada 2012. That
5673 -- would cause real difficulties for those cases where there
5674 -- are incompatibilities between Ada 95 and Ada 2012. We could
5675 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5677 Check_Valid_Configuration_Pragma;
5679 -- Now set appropriate Ada mode
5682 Ada_Version := Ada_2012;
5684 Ada_Version := Ada_Version_Default;
5687 Ada_Version_Explicit := Ada_2012;
5691 ----------------------
5692 -- All_Calls_Remote --
5693 ----------------------
5695 -- pragma All_Calls_Remote [(library_package_NAME)];
5697 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5698 Lib_Entity : Entity_Id;
5701 Check_Ada_83_Warning;
5702 Check_Valid_Library_Unit_Pragma;
5704 if Nkind (N) = N_Null_Statement then
5708 Lib_Entity := Find_Lib_Unit_Name;
5710 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5712 if Present (Lib_Entity)
5713 and then not Debug_Flag_U
5715 if not Is_Remote_Call_Interface (Lib_Entity) then
5716 Error_Pragma ("pragma% only apply to rci unit");
5718 -- Set flag for entity of the library unit
5721 Set_Has_All_Calls_Remote (Lib_Entity);
5725 end All_Calls_Remote;
5731 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
5732 -- ARG ::= NAME | EXPRESSION
5734 -- The first two arguments are by convention intended to refer to an
5735 -- external tool and a tool-specific function. These arguments are
5738 when Pragma_Annotate => Annotate : begin
5740 Check_At_Least_N_Arguments (1);
5741 Check_Arg_Is_Identifier (Arg1);
5742 Check_No_Identifiers;
5750 -- Second unanalyzed parameter is optional
5756 while Present (Arg) loop
5757 Exp := Get_Pragma_Arg (Arg);
5760 if Is_Entity_Name (Exp) then
5763 -- For string literals, we assume Standard_String as the
5764 -- type, unless the string contains wide or wide_wide
5767 elsif Nkind (Exp) = N_String_Literal then
5768 if Has_Wide_Wide_Character (Exp) then
5769 Resolve (Exp, Standard_Wide_Wide_String);
5770 elsif Has_Wide_Character (Exp) then
5771 Resolve (Exp, Standard_Wide_String);
5773 Resolve (Exp, Standard_String);
5776 elsif Is_Overloaded (Exp) then
5778 ("ambiguous argument for pragma%", Exp);
5794 -- pragma Assert ([Check =>] Boolean_EXPRESSION
5795 -- [, [Message =>] Static_String_EXPRESSION]);
5797 when Pragma_Assert => Assert : declare
5803 Check_At_Least_N_Arguments (1);
5804 Check_At_Most_N_Arguments (2);
5805 Check_Arg_Order ((Name_Check, Name_Message));
5806 Check_Optional_Identifier (Arg1, Name_Check);
5808 -- We treat pragma Assert as equivalent to:
5810 -- pragma Check (Assertion, condition [, msg]);
5812 -- So rewrite pragma in this manner, and analyze the result
5814 Expr := Get_Pragma_Arg (Arg1);
5816 Make_Pragma_Argument_Association (Loc,
5818 Make_Identifier (Loc,
5819 Chars => Name_Assertion)),
5821 Make_Pragma_Argument_Association (Sloc (Expr),
5822 Expression => Expr));
5824 if Arg_Count > 1 then
5825 Check_Optional_Identifier (Arg2, Name_Message);
5826 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
5827 Append_To (Newa, Relocate_Node (Arg2));
5832 Chars => Name_Check,
5833 Pragma_Argument_Associations => Newa));
5837 ----------------------
5838 -- Assertion_Policy --
5839 ----------------------
5841 -- pragma Assertion_Policy (Check | Ignore)
5843 when Pragma_Assertion_Policy => Assertion_Policy : declare
5848 Check_Valid_Configuration_Pragma;
5849 Check_Arg_Count (1);
5850 Check_No_Identifiers;
5851 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5853 -- We treat pragma Assertion_Policy as equivalent to:
5855 -- pragma Check_Policy (Assertion, policy)
5857 -- So rewrite the pragma in that manner and link on to the chain
5858 -- of Check_Policy pragmas, marking the pragma as analyzed.
5860 Policy := Get_Pragma_Arg (Arg1);
5864 Chars => Name_Check_Policy,
5866 Pragma_Argument_Associations => New_List (
5867 Make_Pragma_Argument_Association (Loc,
5869 Make_Identifier (Loc,
5870 Chars => Name_Assertion)),
5872 Make_Pragma_Argument_Association (Loc,
5874 Make_Identifier (Sloc (Policy),
5875 Chars => Chars (Policy))))));
5878 Set_Next_Pragma (N, Opt.Check_Policy_List);
5879 Opt.Check_Policy_List := N;
5880 end Assertion_Policy;
5882 ------------------------------
5883 -- Assume_No_Invalid_Values --
5884 ------------------------------
5886 -- pragma Assume_No_Invalid_Values (On | Off);
5888 when Pragma_Assume_No_Invalid_Values =>
5890 Check_Valid_Configuration_Pragma;
5891 Check_Arg_Count (1);
5892 Check_No_Identifiers;
5893 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5895 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
5896 Assume_No_Invalid_Values := True;
5898 Assume_No_Invalid_Values := False;
5905 -- pragma AST_Entry (entry_IDENTIFIER);
5907 when Pragma_AST_Entry => AST_Entry : declare
5913 Check_Arg_Count (1);
5914 Check_No_Identifiers;
5915 Check_Arg_Is_Local_Name (Arg1);
5916 Ent := Entity (Get_Pragma_Arg (Arg1));
5918 -- Note: the implementation of the AST_Entry pragma could handle
5919 -- the entry family case fine, but for now we are consistent with
5920 -- the DEC rules, and do not allow the pragma, which of course
5921 -- has the effect of also forbidding the attribute.
5923 if Ekind (Ent) /= E_Entry then
5925 ("pragma% argument must be simple entry name", Arg1);
5927 elsif Is_AST_Entry (Ent) then
5929 ("duplicate % pragma for entry", Arg1);
5931 elsif Has_Homonym (Ent) then
5933 ("pragma% argument cannot specify overloaded entry", Arg1);
5937 FF : constant Entity_Id := First_Formal (Ent);
5940 if Present (FF) then
5941 if Present (Next_Formal (FF)) then
5943 ("entry for pragma% can have only one argument",
5946 elsif Parameter_Mode (FF) /= E_In_Parameter then
5948 ("entry parameter for pragma% must have mode IN",
5954 Set_Is_AST_Entry (Ent);
5962 -- pragma Asynchronous (LOCAL_NAME);
5964 when Pragma_Asynchronous => Asynchronous : declare
5972 procedure Process_Async_Pragma;
5973 -- Common processing for procedure and access-to-procedure case
5975 --------------------------
5976 -- Process_Async_Pragma --
5977 --------------------------
5979 procedure Process_Async_Pragma is
5982 Set_Is_Asynchronous (Nm);
5986 -- The formals should be of mode IN (RM E.4.1(6))
5989 while Present (S) loop
5990 Formal := Defining_Identifier (S);
5992 if Nkind (Formal) = N_Defining_Identifier
5993 and then Ekind (Formal) /= E_In_Parameter
5996 ("pragma% procedure can only have IN parameter",
6003 Set_Is_Asynchronous (Nm);
6004 end Process_Async_Pragma;
6006 -- Start of processing for pragma Asynchronous
6009 Check_Ada_83_Warning;
6010 Check_No_Identifiers;
6011 Check_Arg_Count (1);
6012 Check_Arg_Is_Local_Name (Arg1);
6014 if Debug_Flag_U then
6018 C_Ent := Cunit_Entity (Current_Sem_Unit);
6019 Analyze (Get_Pragma_Arg (Arg1));
6020 Nm := Entity (Get_Pragma_Arg (Arg1));
6022 if not Is_Remote_Call_Interface (C_Ent)
6023 and then not Is_Remote_Types (C_Ent)
6025 -- This pragma should only appear in an RCI or Remote Types
6026 -- unit (RM E.4.1(4)).
6029 ("pragma% not in Remote_Call_Interface or " &
6030 "Remote_Types unit");
6033 if Ekind (Nm) = E_Procedure
6034 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6036 if not Is_Remote_Call_Interface (Nm) then
6038 ("pragma% cannot be applied on non-remote procedure",
6042 L := Parameter_Specifications (Parent (Nm));
6043 Process_Async_Pragma;
6046 elsif Ekind (Nm) = E_Function then
6048 ("pragma% cannot be applied to function", Arg1);
6050 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6052 if Is_Record_Type (Nm) then
6054 -- A record type that is the Equivalent_Type for a remote
6055 -- access-to-subprogram type.
6057 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6060 -- A non-expanded RAS type (distribution is not enabled)
6062 N := Declaration_Node (Nm);
6065 if Nkind (N) = N_Full_Type_Declaration
6066 and then Nkind (Type_Definition (N)) =
6067 N_Access_Procedure_Definition
6069 L := Parameter_Specifications (Type_Definition (N));
6070 Process_Async_Pragma;
6072 if Is_Asynchronous (Nm)
6073 and then Expander_Active
6074 and then Get_PCS_Name /= Name_No_DSA
6076 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6081 ("pragma% cannot reference access-to-function type",
6085 -- Only other possibility is Access-to-class-wide type
6087 elsif Is_Access_Type (Nm)
6088 and then Is_Class_Wide_Type (Designated_Type (Nm))
6090 Check_First_Subtype (Arg1);
6091 Set_Is_Asynchronous (Nm);
6092 if Expander_Active then
6093 RACW_Type_Is_Asynchronous (Nm);
6097 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6105 -- pragma Atomic (LOCAL_NAME);
6107 when Pragma_Atomic =>
6108 Process_Atomic_Shared_Volatile;
6110 -----------------------
6111 -- Atomic_Components --
6112 -----------------------
6114 -- pragma Atomic_Components (array_LOCAL_NAME);
6116 -- This processing is shared by Volatile_Components
6118 when Pragma_Atomic_Components |
6119 Pragma_Volatile_Components =>
6121 Atomic_Components : declare
6128 Check_Ada_83_Warning;
6129 Check_No_Identifiers;
6130 Check_Arg_Count (1);
6131 Check_Arg_Is_Local_Name (Arg1);
6132 E_Id := Get_Pragma_Arg (Arg1);
6134 if Etype (E_Id) = Any_Type then
6140 Check_Duplicate_Pragma (E);
6142 if Rep_Item_Too_Early (E, N)
6144 Rep_Item_Too_Late (E, N)
6149 D := Declaration_Node (E);
6152 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6154 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6155 and then Nkind (D) = N_Object_Declaration
6156 and then Nkind (Object_Definition (D)) =
6157 N_Constrained_Array_Definition)
6159 -- The flag is set on the object, or on the base type
6161 if Nkind (D) /= N_Object_Declaration then
6165 Set_Has_Volatile_Components (E, Sense);
6167 if Prag_Id = Pragma_Atomic_Components then
6168 Set_Has_Atomic_Components (E, Sense);
6172 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6174 end Atomic_Components;
6176 --------------------
6177 -- Attach_Handler --
6178 --------------------
6180 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6182 when Pragma_Attach_Handler =>
6183 Check_Ada_83_Warning;
6184 Check_No_Identifiers;
6185 Check_Arg_Count (2);
6187 if No_Run_Time_Mode then
6188 Error_Msg_CRT ("Attach_Handler pragma", N);
6190 Check_Interrupt_Or_Attach_Handler;
6192 -- The expression that designates the attribute may depend on a
6193 -- discriminant, and is therefore a per- object expression, to
6194 -- be expanded in the init proc. If expansion is enabled, then
6195 -- perform semantic checks on a copy only.
6197 if Expander_Active then
6199 Temp : constant Node_Id :=
6200 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6202 Set_Parent (Temp, N);
6203 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6207 Analyze (Get_Pragma_Arg (Arg2));
6208 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6211 Process_Interrupt_Or_Attach_Handler;
6214 --------------------
6215 -- C_Pass_By_Copy --
6216 --------------------
6218 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6220 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6226 Check_Valid_Configuration_Pragma;
6227 Check_Arg_Count (1);
6228 Check_Optional_Identifier (Arg1, "max_size");
6230 Arg := Get_Pragma_Arg (Arg1);
6231 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6233 Val := Expr_Value (Arg);
6237 ("maximum size for pragma% must be positive", Arg1);
6239 elsif UI_Is_In_Int_Range (Val) then
6240 Default_C_Record_Mechanism := UI_To_Int (Val);
6242 -- If a giant value is given, Int'Last will do well enough.
6243 -- If sometime someone complains that a record larger than
6244 -- two gigabytes is not copied, we will worry about it then!
6247 Default_C_Record_Mechanism := Mechanism_Type'Last;
6255 -- pragma Check ([Name =>] Identifier,
6256 -- [Check =>] Boolean_Expression
6257 -- [,[Message =>] String_Expression]);
6259 when Pragma_Check => Check : declare
6264 -- Set True if category of assertions referenced by Name enabled
6268 Check_At_Least_N_Arguments (2);
6269 Check_At_Most_N_Arguments (3);
6270 Check_Optional_Identifier (Arg1, Name_Name);
6271 Check_Optional_Identifier (Arg2, Name_Check);
6273 if Arg_Count = 3 then
6274 Check_Optional_Identifier (Arg3, Name_Message);
6275 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6278 Check_Arg_Is_Identifier (Arg1);
6280 -- Indicate if pragma is enabled. The Original_Node reference here
6281 -- is to deal with pragma Assert rewritten as a Check pragma.
6283 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6286 Set_Pragma_Enabled (N);
6287 Set_Pragma_Enabled (Original_Node (N));
6288 Set_SCO_Pragma_Enabled (Loc);
6291 -- If expansion is active and the check is not enabled then we
6292 -- rewrite the Check as:
6294 -- if False and then condition then
6298 -- The reason we do this rewriting during semantic analysis rather
6299 -- than as part of normal expansion is that we cannot analyze and
6300 -- expand the code for the boolean expression directly, or it may
6301 -- cause insertion of actions that would escape the attempt to
6302 -- suppress the check code.
6304 -- Note that the Sloc for the if statement corresponds to the
6305 -- argument condition, not the pragma itself. The reason for this
6306 -- is that we may generate a warning if the condition is False at
6307 -- compile time, and we do not want to delete this warning when we
6308 -- delete the if statement.
6310 Expr := Get_Pragma_Arg (Arg2);
6312 if Expander_Active and then not Check_On then
6313 Eloc := Sloc (Expr);
6316 Make_If_Statement (Eloc,
6318 Make_And_Then (Eloc,
6319 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6320 Right_Opnd => Expr),
6321 Then_Statements => New_List (
6322 Make_Null_Statement (Eloc))));
6329 Analyze_And_Resolve (Expr, Any_Boolean);
6337 -- pragma Check_Name (check_IDENTIFIER);
6339 when Pragma_Check_Name =>
6340 Check_No_Identifiers;
6342 Check_Valid_Configuration_Pragma;
6343 Check_Arg_Count (1);
6344 Check_Arg_Is_Identifier (Arg1);
6347 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6350 for J in Check_Names.First .. Check_Names.Last loop
6351 if Check_Names.Table (J) = Nam then
6356 Check_Names.Append (Nam);
6363 -- pragma Check_Policy (
6364 -- [Name =>] IDENTIFIER,
6365 -- [Policy =>] POLICY_IDENTIFIER);
6367 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6369 -- Note: this is a configuration pragma, but it is allowed to appear
6372 when Pragma_Check_Policy =>
6374 Check_Arg_Count (2);
6375 Check_Optional_Identifier (Arg1, Name_Name);
6376 Check_Optional_Identifier (Arg2, Name_Policy);
6378 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6380 -- A Check_Policy pragma can appear either as a configuration
6381 -- pragma, or in a declarative part or a package spec (see RM
6382 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6383 -- followed for Check_Policy).
6385 if not Is_Configuration_Pragma then
6386 Check_Is_In_Decl_Part_Or_Package_Spec;
6389 Set_Next_Pragma (N, Opt.Check_Policy_List);
6390 Opt.Check_Policy_List := N;
6392 ---------------------
6393 -- CIL_Constructor --
6394 ---------------------
6396 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6398 -- Processing for this pragma is shared with Java_Constructor
6404 -- pragma Comment (static_string_EXPRESSION)
6406 -- Processing for pragma Comment shares the circuitry for pragma
6407 -- Ident. The only differences are that Ident enforces a limit of 31
6408 -- characters on its argument, and also enforces limitations on
6409 -- placement for DEC compatibility. Pragma Comment shares neither of
6410 -- these restrictions.
6416 -- pragma Common_Object (
6417 -- [Internal =>] LOCAL_NAME
6418 -- [, [External =>] EXTERNAL_SYMBOL]
6419 -- [, [Size =>] EXTERNAL_SYMBOL]);
6421 -- Processing for this pragma is shared with Psect_Object
6423 ------------------------
6424 -- Compile_Time_Error --
6425 ------------------------
6427 -- pragma Compile_Time_Error
6428 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6430 when Pragma_Compile_Time_Error =>
6432 Process_Compile_Time_Warning_Or_Error;
6434 --------------------------
6435 -- Compile_Time_Warning --
6436 --------------------------
6438 -- pragma Compile_Time_Warning
6439 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6441 when Pragma_Compile_Time_Warning =>
6443 Process_Compile_Time_Warning_Or_Error;
6449 when Pragma_Compiler_Unit =>
6451 Check_Arg_Count (0);
6452 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6454 -----------------------------
6455 -- Complete_Representation --
6456 -----------------------------
6458 -- pragma Complete_Representation;
6460 when Pragma_Complete_Representation =>
6462 Check_Arg_Count (0);
6464 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6466 ("pragma & must appear within record representation clause");
6469 ----------------------------
6470 -- Complex_Representation --
6471 ----------------------------
6473 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6475 when Pragma_Complex_Representation => Complex_Representation : declare
6482 Check_Arg_Count (1);
6483 Check_Optional_Identifier (Arg1, Name_Entity);
6484 Check_Arg_Is_Local_Name (Arg1);
6485 E_Id := Get_Pragma_Arg (Arg1);
6487 if Etype (E_Id) = Any_Type then
6493 if not Is_Record_Type (E) then
6495 ("argument for pragma% must be record type", Arg1);
6498 Ent := First_Entity (E);
6501 or else No (Next_Entity (Ent))
6502 or else Present (Next_Entity (Next_Entity (Ent)))
6503 or else not Is_Floating_Point_Type (Etype (Ent))
6504 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6507 ("record for pragma% must have two fields of the same "
6508 & "floating-point type", Arg1);
6511 Set_Has_Complex_Representation (Base_Type (E));
6513 -- We need to treat the type has having a non-standard
6514 -- representation, for back-end purposes, even though in
6515 -- general a complex will have the default representation
6516 -- of a record with two real components.
6518 Set_Has_Non_Standard_Rep (Base_Type (E));
6520 end Complex_Representation;
6522 -------------------------
6523 -- Component_Alignment --
6524 -------------------------
6526 -- pragma Component_Alignment (
6527 -- [Form =>] ALIGNMENT_CHOICE
6528 -- [, [Name =>] type_LOCAL_NAME]);
6530 -- ALIGNMENT_CHOICE ::=
6532 -- | Component_Size_4
6536 when Pragma_Component_Alignment => Component_AlignmentP : declare
6537 Args : Args_List (1 .. 2);
6538 Names : constant Name_List (1 .. 2) := (
6542 Form : Node_Id renames Args (1);
6543 Name : Node_Id renames Args (2);
6545 Atype : Component_Alignment_Kind;
6550 Gather_Associations (Names, Args);
6553 Error_Pragma ("missing Form argument for pragma%");
6556 Check_Arg_Is_Identifier (Form);
6558 -- Get proper alignment, note that Default = Component_Size on all
6559 -- machines we have so far, and we want to set this value rather
6560 -- than the default value to indicate that it has been explicitly
6561 -- set (and thus will not get overridden by the default component
6562 -- alignment for the current scope)
6564 if Chars (Form) = Name_Component_Size then
6565 Atype := Calign_Component_Size;
6567 elsif Chars (Form) = Name_Component_Size_4 then
6568 Atype := Calign_Component_Size_4;
6570 elsif Chars (Form) = Name_Default then
6571 Atype := Calign_Component_Size;
6573 elsif Chars (Form) = Name_Storage_Unit then
6574 Atype := Calign_Storage_Unit;
6578 ("invalid Form parameter for pragma%", Form);
6581 -- Case with no name, supplied, affects scope table entry
6585 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6587 -- Case of name supplied
6590 Check_Arg_Is_Local_Name (Name);
6592 Typ := Entity (Name);
6595 or else Rep_Item_Too_Early (Typ, N)
6599 Typ := Underlying_Type (Typ);
6602 if not Is_Record_Type (Typ)
6603 and then not Is_Array_Type (Typ)
6606 ("Name parameter of pragma% must identify record or " &
6607 "array type", Name);
6610 -- An explicit Component_Alignment pragma overrides an
6611 -- implicit pragma Pack, but not an explicit one.
6613 if not Has_Pragma_Pack (Base_Type (Typ)) then
6614 Set_Is_Packed (Base_Type (Typ), False);
6615 Set_Component_Alignment (Base_Type (Typ), Atype);
6618 end Component_AlignmentP;
6624 -- pragma Controlled (first_subtype_LOCAL_NAME);
6626 when Pragma_Controlled => Controlled : declare
6630 Check_No_Identifiers;
6631 Check_Arg_Count (1);
6632 Check_Arg_Is_Local_Name (Arg1);
6633 Arg := Get_Pragma_Arg (Arg1);
6635 if not Is_Entity_Name (Arg)
6636 or else not Is_Access_Type (Entity (Arg))
6638 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6640 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6648 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6649 -- [Entity =>] LOCAL_NAME);
6651 when Pragma_Convention => Convention : declare
6654 pragma Warnings (Off, C);
6655 pragma Warnings (Off, E);
6657 Check_Arg_Order ((Name_Convention, Name_Entity));
6658 Check_Ada_83_Warning;
6659 Check_Arg_Count (2);
6660 Process_Convention (C, E);
6663 ---------------------------
6664 -- Convention_Identifier --
6665 ---------------------------
6667 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6668 -- [Convention =>] convention_IDENTIFIER);
6670 when Pragma_Convention_Identifier => Convention_Identifier : declare
6676 Check_Arg_Order ((Name_Name, Name_Convention));
6677 Check_Arg_Count (2);
6678 Check_Optional_Identifier (Arg1, Name_Name);
6679 Check_Optional_Identifier (Arg2, Name_Convention);
6680 Check_Arg_Is_Identifier (Arg1);
6681 Check_Arg_Is_Identifier (Arg2);
6682 Idnam := Chars (Get_Pragma_Arg (Arg1));
6683 Cname := Chars (Get_Pragma_Arg (Arg2));
6685 if Is_Convention_Name (Cname) then
6686 Record_Convention_Identifier
6687 (Idnam, Get_Convention_Id (Cname));
6690 ("second arg for % pragma must be convention", Arg2);
6692 end Convention_Identifier;
6698 -- pragma CPP_Class ([Entity =>] local_NAME)
6700 when Pragma_CPP_Class => CPP_Class : declare
6705 if Warn_On_Obsolescent_Feature then
6707 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6708 " by pragma import?", N);
6712 Check_Arg_Count (1);
6713 Check_Optional_Identifier (Arg1, Name_Entity);
6714 Check_Arg_Is_Local_Name (Arg1);
6716 Arg := Get_Pragma_Arg (Arg1);
6719 if Etype (Arg) = Any_Type then
6723 if not Is_Entity_Name (Arg)
6724 or else not Is_Type (Entity (Arg))
6726 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6729 Typ := Entity (Arg);
6731 if not Is_Tagged_Type (Typ) then
6732 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6735 -- Types treated as CPP classes are treated as limited, but we
6736 -- don't require them to be declared this way. A warning is issued
6737 -- to encourage the user to declare them as limited. This is not
6738 -- an error, for compatibility reasons, because these types have
6739 -- been supported this way for some time.
6741 if not Is_Limited_Type (Typ) then
6743 ("imported 'C'P'P type should be " &
6744 "explicitly declared limited?",
6745 Get_Pragma_Arg (Arg1));
6747 ("\type will be considered limited",
6748 Get_Pragma_Arg (Arg1));
6751 Set_Is_CPP_Class (Typ);
6752 Set_Is_Limited_Record (Typ);
6753 Set_Convention (Typ, Convention_CPP);
6755 -- Imported CPP types must not have discriminants (because C++
6756 -- classes do not have discriminants).
6758 if Has_Discriminants (Typ) then
6760 ("imported 'C'P'P type cannot have discriminants",
6761 First (Discriminant_Specifications
6762 (Declaration_Node (Typ))));
6765 -- Components of imported CPP types must not have default
6766 -- expressions because the constructor (if any) is in the
6769 if Is_Incomplete_Or_Private_Type (Typ)
6770 and then No (Underlying_Type (Typ))
6772 -- It should be an error to apply pragma CPP to a private
6773 -- type if the underlying type is not visible (as it is
6774 -- for any representation item). For now, for backward
6775 -- compatibility we do nothing but we cannot check components
6776 -- because they are not available at this stage. All this code
6777 -- will be removed when we cleanup this obsolete GNAT pragma???
6783 Tdef : constant Node_Id :=
6784 Type_Definition (Declaration_Node (Typ));
6789 if Nkind (Tdef) = N_Record_Definition then
6790 Clist := Component_List (Tdef);
6792 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
6793 Clist := Component_List (Record_Extension_Part (Tdef));
6796 if Present (Clist) then
6797 Comp := First (Component_Items (Clist));
6798 while Present (Comp) loop
6799 if Present (Expression (Comp)) then
6801 ("component of imported 'C'P'P type cannot have" &
6802 " default expression", Expression (Comp));
6812 ---------------------
6813 -- CPP_Constructor --
6814 ---------------------
6816 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
6817 -- [, [External_Name =>] static_string_EXPRESSION ]
6818 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6820 when Pragma_CPP_Constructor => CPP_Constructor : declare
6824 Tag_Typ : Entity_Id;
6828 Check_At_Least_N_Arguments (1);
6829 Check_At_Most_N_Arguments (3);
6830 Check_Optional_Identifier (Arg1, Name_Entity);
6831 Check_Arg_Is_Local_Name (Arg1);
6833 Id := Get_Pragma_Arg (Arg1);
6834 Find_Program_Unit_Name (Id);
6836 -- If we did not find the name, we are done
6838 if Etype (Id) = Any_Type then
6842 Def_Id := Entity (Id);
6844 -- Check if already defined as constructor
6846 if Is_Constructor (Def_Id) then
6848 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
6852 if Ekind (Def_Id) = E_Function
6853 and then (Is_CPP_Class (Etype (Def_Id))
6854 or else (Is_Class_Wide_Type (Etype (Def_Id))
6856 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
6858 if Arg_Count >= 2 then
6859 Set_Imported (Def_Id);
6860 Set_Is_Public (Def_Id);
6861 Process_Interface_Name (Def_Id, Arg2, Arg3);
6864 Set_Has_Completion (Def_Id);
6865 Set_Is_Constructor (Def_Id);
6867 -- Imported C++ constructors are not dispatching primitives
6868 -- because in C++ they don't have a dispatch table slot.
6869 -- However, in Ada the constructor has the profile of a
6870 -- function that returns a tagged type and therefore it has
6871 -- been treated as a primitive operation during semantic
6872 -- analysis. We now remove it from the list of primitive
6873 -- operations of the type.
6875 if Is_Tagged_Type (Etype (Def_Id))
6876 and then not Is_Class_Wide_Type (Etype (Def_Id))
6878 pragma Assert (Is_Dispatching_Operation (Def_Id));
6879 Tag_Typ := Etype (Def_Id);
6881 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
6882 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
6886 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
6887 Set_Is_Dispatching_Operation (Def_Id, False);
6890 -- For backward compatibility, if the constructor returns a
6891 -- class wide type, and we internally change the return type to
6892 -- the corresponding root type.
6894 if Is_Class_Wide_Type (Etype (Def_Id)) then
6895 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
6899 ("pragma% requires function returning a 'C'P'P_Class type",
6902 end CPP_Constructor;
6908 when Pragma_CPP_Virtual => CPP_Virtual : declare
6912 if Warn_On_Obsolescent_Feature then
6914 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
6923 when Pragma_CPP_Vtable => CPP_Vtable : declare
6927 if Warn_On_Obsolescent_Feature then
6929 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
6938 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
6940 when Pragma_Debug => Debug : declare
6948 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
6951 if Arg_Count = 2 then
6954 Left_Opnd => Relocate_Node (Cond),
6955 Right_Opnd => Get_Pragma_Arg (Arg1));
6958 -- Rewrite into a conditional with an appropriate condition. We
6959 -- wrap the procedure call in a block so that overhead from e.g.
6960 -- use of the secondary stack does not generate execution overhead
6961 -- for suppressed conditions.
6963 Rewrite (N, Make_Implicit_If_Statement (N,
6965 Then_Statements => New_List (
6966 Make_Block_Statement (Loc,
6967 Handled_Statement_Sequence =>
6968 Make_Handled_Sequence_Of_Statements (Loc,
6969 Statements => New_List (
6970 Relocate_Node (Debug_Statement (N))))))));
6978 -- pragma Debug_Policy (Check | Ignore)
6980 when Pragma_Debug_Policy =>
6982 Check_Arg_Count (1);
6983 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6984 Debug_Pragmas_Enabled :=
6985 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
6987 ---------------------
6988 -- Detect_Blocking --
6989 ---------------------
6991 -- pragma Detect_Blocking;
6993 when Pragma_Detect_Blocking =>
6995 Check_Arg_Count (0);
6996 Check_Valid_Configuration_Pragma;
6997 Detect_Blocking := True;
7003 when Pragma_Dimension =>
7005 Check_Arg_Count (4);
7006 Check_No_Identifiers;
7007 Check_Arg_Is_Local_Name (Arg1);
7009 if not Is_Type (Arg1) then
7010 Error_Pragma ("first argument for pragma% must be subtype");
7013 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7014 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7015 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7021 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7023 when Pragma_Discard_Names => Discard_Names : declare
7028 Check_Ada_83_Warning;
7030 -- Deal with configuration pragma case
7032 if Arg_Count = 0 and then Is_Configuration_Pragma then
7033 Global_Discard_Names := True;
7036 -- Otherwise, check correct appropriate context
7039 Check_Is_In_Decl_Part_Or_Package_Spec;
7041 if Arg_Count = 0 then
7043 -- If there is no parameter, then from now on this pragma
7044 -- applies to any enumeration, exception or tagged type
7045 -- defined in the current declarative part, and recursively
7046 -- to any nested scope.
7048 Set_Discard_Names (Current_Scope, Sense);
7052 Check_Arg_Count (1);
7053 Check_Optional_Identifier (Arg1, Name_On);
7054 Check_Arg_Is_Local_Name (Arg1);
7056 E_Id := Get_Pragma_Arg (Arg1);
7058 if Etype (E_Id) = Any_Type then
7064 if (Is_First_Subtype (E)
7066 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7067 or else Ekind (E) = E_Exception
7069 Set_Discard_Names (E, Sense);
7072 ("inappropriate entity for pragma%", Arg1);
7083 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7085 when Pragma_Elaborate => Elaborate : declare
7090 -- Pragma must be in context items list of a compilation unit
7092 if not Is_In_Context_Clause then
7096 -- Must be at least one argument
7098 if Arg_Count = 0 then
7099 Error_Pragma ("pragma% requires at least one argument");
7102 -- In Ada 83 mode, there can be no items following it in the
7103 -- context list except other pragmas and implicit with clauses
7104 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7105 -- placement rule does not apply.
7107 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7109 while Present (Citem) loop
7110 if Nkind (Citem) = N_Pragma
7111 or else (Nkind (Citem) = N_With_Clause
7112 and then Implicit_With (Citem))
7117 ("(Ada 83) pragma% must be at end of context clause");
7124 -- Finally, the arguments must all be units mentioned in a with
7125 -- clause in the same context clause. Note we already checked (in
7126 -- Par.Prag) that the arguments are all identifiers or selected
7130 Outer : while Present (Arg) loop
7131 Citem := First (List_Containing (N));
7132 Inner : while Citem /= N loop
7133 if Nkind (Citem) = N_With_Clause
7134 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7136 Set_Elaborate_Present (Citem, True);
7137 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7139 -- With the pragma present, elaboration calls on
7140 -- subprograms from the named unit need no further
7141 -- checks, as long as the pragma appears in the current
7142 -- compilation unit. If the pragma appears in some unit
7143 -- in the context, there might still be a need for an
7144 -- Elaborate_All_Desirable from the current compilation
7145 -- to the named unit, so we keep the check enabled.
7147 if In_Extended_Main_Source_Unit (N) then
7148 Set_Suppress_Elaboration_Warnings
7149 (Entity (Name (Citem)));
7160 ("argument of pragma% is not with'ed unit", Arg);
7166 -- Give a warning if operating in static mode with -gnatwl
7167 -- (elaboration warnings enabled) switch set.
7169 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7171 ("?use of pragma Elaborate may not be safe", N);
7173 ("?use pragma Elaborate_All instead if possible", N);
7181 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7183 when Pragma_Elaborate_All => Elaborate_All : declare
7188 Check_Ada_83_Warning;
7190 -- Pragma must be in context items list of a compilation unit
7192 if not Is_In_Context_Clause then
7196 -- Must be at least one argument
7198 if Arg_Count = 0 then
7199 Error_Pragma ("pragma% requires at least one argument");
7202 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7203 -- have to appear at the end of the context clause, but may
7204 -- appear mixed in with other items, even in Ada 83 mode.
7206 -- Final check: the arguments must all be units mentioned in
7207 -- a with clause in the same context clause. Note that we
7208 -- already checked (in Par.Prag) that all the arguments are
7209 -- either identifiers or selected components.
7212 Outr : while Present (Arg) loop
7213 Citem := First (List_Containing (N));
7214 Innr : while Citem /= N loop
7215 if Nkind (Citem) = N_With_Clause
7216 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7218 Set_Elaborate_All_Present (Citem, True);
7219 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7221 -- Suppress warnings and elaboration checks on the named
7222 -- unit if the pragma is in the current compilation, as
7223 -- for pragma Elaborate.
7225 if In_Extended_Main_Source_Unit (N) then
7226 Set_Suppress_Elaboration_Warnings
7227 (Entity (Name (Citem)));
7236 Set_Error_Posted (N);
7238 ("argument of pragma% is not with'ed unit", Arg);
7245 --------------------
7246 -- Elaborate_Body --
7247 --------------------
7249 -- pragma Elaborate_Body [( library_unit_NAME )];
7251 when Pragma_Elaborate_Body => Elaborate_Body : declare
7252 Cunit_Node : Node_Id;
7253 Cunit_Ent : Entity_Id;
7256 Check_Ada_83_Warning;
7257 Check_Valid_Library_Unit_Pragma;
7259 if Nkind (N) = N_Null_Statement then
7263 Cunit_Node := Cunit (Current_Sem_Unit);
7264 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7266 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7269 Error_Pragma ("pragma% must refer to a spec, not a body");
7271 Set_Body_Required (Cunit_Node, True);
7272 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7274 -- If we are in dynamic elaboration mode, then we suppress
7275 -- elaboration warnings for the unit, since it is definitely
7276 -- fine NOT to do dynamic checks at the first level (and such
7277 -- checks will be suppressed because no elaboration boolean
7278 -- is created for Elaborate_Body packages).
7280 -- But in the static model of elaboration, Elaborate_Body is
7281 -- definitely NOT good enough to ensure elaboration safety on
7282 -- its own, since the body may WITH other units that are not
7283 -- safe from an elaboration point of view, so a client must
7284 -- still do an Elaborate_All on such units.
7286 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7287 -- Elaborate_Body always suppressed elab warnings.
7289 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7290 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7295 ------------------------
7296 -- Elaboration_Checks --
7297 ------------------------
7299 -- pragma Elaboration_Checks (Static | Dynamic);
7301 when Pragma_Elaboration_Checks =>
7303 Check_Arg_Count (1);
7304 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7305 Dynamic_Elaboration_Checks :=
7306 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7312 -- pragma Eliminate (
7313 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7314 -- [,[Entity =>] IDENTIFIER |
7315 -- SELECTED_COMPONENT |
7317 -- [, OVERLOADING_RESOLUTION]);
7319 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7322 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7325 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7327 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7328 -- Result_Type => result_SUBTYPE_NAME]
7330 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7331 -- SUBTYPE_NAME ::= STRING_LITERAL
7333 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7334 -- SOURCE_TRACE ::= STRING_LITERAL
7336 when Pragma_Eliminate => Eliminate : declare
7337 Args : Args_List (1 .. 5);
7338 Names : constant Name_List (1 .. 5) := (
7341 Name_Parameter_Types,
7343 Name_Source_Location);
7345 Unit_Name : Node_Id renames Args (1);
7346 Entity : Node_Id renames Args (2);
7347 Parameter_Types : Node_Id renames Args (3);
7348 Result_Type : Node_Id renames Args (4);
7349 Source_Location : Node_Id renames Args (5);
7353 Check_Valid_Configuration_Pragma;
7354 Gather_Associations (Names, Args);
7356 if No (Unit_Name) then
7357 Error_Pragma ("missing Unit_Name argument for pragma%");
7361 and then (Present (Parameter_Types)
7363 Present (Result_Type)
7365 Present (Source_Location))
7367 Error_Pragma ("missing Entity argument for pragma%");
7370 if (Present (Parameter_Types)
7372 Present (Result_Type))
7374 Present (Source_Location)
7377 ("parameter profile and source location cannot " &
7378 "be used together in pragma%");
7381 Process_Eliminate_Pragma
7395 -- [ Convention =>] convention_IDENTIFIER,
7396 -- [ Entity =>] local_NAME
7397 -- [, [External_Name =>] static_string_EXPRESSION ]
7398 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7400 when Pragma_Export => Export : declare
7404 pragma Warnings (Off, C);
7407 Check_Ada_83_Warning;
7413 Check_At_Least_N_Arguments (2);
7414 Check_At_Most_N_Arguments (4);
7415 Process_Convention (C, Def_Id);
7417 if Ekind (Def_Id) /= E_Constant then
7418 Note_Possible_Modification
7419 (Get_Pragma_Arg (Arg2), Sure => False);
7422 Process_Interface_Name (Def_Id, Arg3, Arg4);
7423 Set_Exported (Def_Id, Arg2);
7425 -- If the entity is a deferred constant, propagate the information
7426 -- to the full view, because gigi elaborates the full view only.
7428 if Ekind (Def_Id) = E_Constant
7429 and then Present (Full_View (Def_Id))
7432 Id2 : constant Entity_Id := Full_View (Def_Id);
7434 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7435 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7436 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7441 ----------------------
7442 -- Export_Exception --
7443 ----------------------
7445 -- pragma Export_Exception (
7446 -- [Internal =>] LOCAL_NAME
7447 -- [, [External =>] EXTERNAL_SYMBOL]
7448 -- [, [Form =>] Ada | VMS]
7449 -- [, [Code =>] static_integer_EXPRESSION]);
7451 when Pragma_Export_Exception => Export_Exception : declare
7452 Args : Args_List (1 .. 4);
7453 Names : constant Name_List (1 .. 4) := (
7459 Internal : Node_Id renames Args (1);
7460 External : Node_Id renames Args (2);
7461 Form : Node_Id renames Args (3);
7462 Code : Node_Id renames Args (4);
7467 if Inside_A_Generic then
7468 Error_Pragma ("pragma% cannot be used for generic entities");
7471 Gather_Associations (Names, Args);
7472 Process_Extended_Import_Export_Exception_Pragma (
7473 Arg_Internal => Internal,
7474 Arg_External => External,
7478 if not Is_VMS_Exception (Entity (Internal)) then
7479 Set_Exported (Entity (Internal), Internal);
7481 end Export_Exception;
7483 ---------------------
7484 -- Export_Function --
7485 ---------------------
7487 -- pragma Export_Function (
7488 -- [Internal =>] LOCAL_NAME
7489 -- [, [External =>] EXTERNAL_SYMBOL]
7490 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7491 -- [, [Result_Type =>] TYPE_DESIGNATOR]
7492 -- [, [Mechanism =>] MECHANISM]
7493 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
7495 -- EXTERNAL_SYMBOL ::=
7497 -- | static_string_EXPRESSION
7499 -- PARAMETER_TYPES ::=
7501 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7503 -- TYPE_DESIGNATOR ::=
7505 -- | subtype_Name ' Access
7509 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7511 -- MECHANISM_ASSOCIATION ::=
7512 -- [formal_parameter_NAME =>] MECHANISM_NAME
7514 -- MECHANISM_NAME ::=
7517 -- | Descriptor [([Class =>] CLASS_NAME)]
7519 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7521 when Pragma_Export_Function => Export_Function : declare
7522 Args : Args_List (1 .. 6);
7523 Names : constant Name_List (1 .. 6) := (
7526 Name_Parameter_Types,
7529 Name_Result_Mechanism);
7531 Internal : Node_Id renames Args (1);
7532 External : Node_Id renames Args (2);
7533 Parameter_Types : Node_Id renames Args (3);
7534 Result_Type : Node_Id renames Args (4);
7535 Mechanism : Node_Id renames Args (5);
7536 Result_Mechanism : Node_Id renames Args (6);
7540 Gather_Associations (Names, Args);
7541 Process_Extended_Import_Export_Subprogram_Pragma (
7542 Arg_Internal => Internal,
7543 Arg_External => External,
7544 Arg_Parameter_Types => Parameter_Types,
7545 Arg_Result_Type => Result_Type,
7546 Arg_Mechanism => Mechanism,
7547 Arg_Result_Mechanism => Result_Mechanism);
7548 end Export_Function;
7554 -- pragma Export_Object (
7555 -- [Internal =>] LOCAL_NAME
7556 -- [, [External =>] EXTERNAL_SYMBOL]
7557 -- [, [Size =>] EXTERNAL_SYMBOL]);
7559 -- EXTERNAL_SYMBOL ::=
7561 -- | static_string_EXPRESSION
7563 -- PARAMETER_TYPES ::=
7565 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7567 -- TYPE_DESIGNATOR ::=
7569 -- | subtype_Name ' Access
7573 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7575 -- MECHANISM_ASSOCIATION ::=
7576 -- [formal_parameter_NAME =>] MECHANISM_NAME
7578 -- MECHANISM_NAME ::=
7581 -- | Descriptor [([Class =>] CLASS_NAME)]
7583 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7585 when Pragma_Export_Object => Export_Object : declare
7586 Args : Args_List (1 .. 3);
7587 Names : constant Name_List (1 .. 3) := (
7592 Internal : Node_Id renames Args (1);
7593 External : Node_Id renames Args (2);
7594 Size : Node_Id renames Args (3);
7598 Gather_Associations (Names, Args);
7599 Process_Extended_Import_Export_Object_Pragma (
7600 Arg_Internal => Internal,
7601 Arg_External => External,
7605 ----------------------
7606 -- Export_Procedure --
7607 ----------------------
7609 -- pragma Export_Procedure (
7610 -- [Internal =>] LOCAL_NAME
7611 -- [, [External =>] EXTERNAL_SYMBOL]
7612 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7613 -- [, [Mechanism =>] MECHANISM]);
7615 -- EXTERNAL_SYMBOL ::=
7617 -- | static_string_EXPRESSION
7619 -- PARAMETER_TYPES ::=
7621 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7623 -- TYPE_DESIGNATOR ::=
7625 -- | subtype_Name ' Access
7629 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7631 -- MECHANISM_ASSOCIATION ::=
7632 -- [formal_parameter_NAME =>] MECHANISM_NAME
7634 -- MECHANISM_NAME ::=
7637 -- | Descriptor [([Class =>] CLASS_NAME)]
7639 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7641 when Pragma_Export_Procedure => Export_Procedure : declare
7642 Args : Args_List (1 .. 4);
7643 Names : constant Name_List (1 .. 4) := (
7646 Name_Parameter_Types,
7649 Internal : Node_Id renames Args (1);
7650 External : Node_Id renames Args (2);
7651 Parameter_Types : Node_Id renames Args (3);
7652 Mechanism : Node_Id renames Args (4);
7656 Gather_Associations (Names, Args);
7657 Process_Extended_Import_Export_Subprogram_Pragma (
7658 Arg_Internal => Internal,
7659 Arg_External => External,
7660 Arg_Parameter_Types => Parameter_Types,
7661 Arg_Mechanism => Mechanism);
7662 end Export_Procedure;
7668 -- pragma Export_Value (
7669 -- [Value =>] static_integer_EXPRESSION,
7670 -- [Link_Name =>] static_string_EXPRESSION);
7672 when Pragma_Export_Value =>
7674 Check_Arg_Order ((Name_Value, Name_Link_Name));
7675 Check_Arg_Count (2);
7677 Check_Optional_Identifier (Arg1, Name_Value);
7678 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7680 Check_Optional_Identifier (Arg2, Name_Link_Name);
7681 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7683 -----------------------------
7684 -- Export_Valued_Procedure --
7685 -----------------------------
7687 -- pragma Export_Valued_Procedure (
7688 -- [Internal =>] LOCAL_NAME
7689 -- [, [External =>] EXTERNAL_SYMBOL,]
7690 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7691 -- [, [Mechanism =>] MECHANISM]);
7693 -- EXTERNAL_SYMBOL ::=
7695 -- | static_string_EXPRESSION
7697 -- PARAMETER_TYPES ::=
7699 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7701 -- TYPE_DESIGNATOR ::=
7703 -- | subtype_Name ' Access
7707 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7709 -- MECHANISM_ASSOCIATION ::=
7710 -- [formal_parameter_NAME =>] MECHANISM_NAME
7712 -- MECHANISM_NAME ::=
7715 -- | Descriptor [([Class =>] CLASS_NAME)]
7717 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7719 when Pragma_Export_Valued_Procedure =>
7720 Export_Valued_Procedure : declare
7721 Args : Args_List (1 .. 4);
7722 Names : constant Name_List (1 .. 4) := (
7725 Name_Parameter_Types,
7728 Internal : Node_Id renames Args (1);
7729 External : Node_Id renames Args (2);
7730 Parameter_Types : Node_Id renames Args (3);
7731 Mechanism : Node_Id renames Args (4);
7735 Gather_Associations (Names, Args);
7736 Process_Extended_Import_Export_Subprogram_Pragma (
7737 Arg_Internal => Internal,
7738 Arg_External => External,
7739 Arg_Parameter_Types => Parameter_Types,
7740 Arg_Mechanism => Mechanism);
7741 end Export_Valued_Procedure;
7747 -- pragma Extend_System ([Name =>] Identifier);
7749 when Pragma_Extend_System => Extend_System : declare
7752 Check_Valid_Configuration_Pragma;
7753 Check_Arg_Count (1);
7754 Check_Optional_Identifier (Arg1, Name_Name);
7755 Check_Arg_Is_Identifier (Arg1);
7757 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
7760 and then Name_Buffer (1 .. 4) = "aux_"
7762 if Present (System_Extend_Pragma_Arg) then
7763 if Chars (Get_Pragma_Arg (Arg1)) =
7764 Chars (Expression (System_Extend_Pragma_Arg))
7768 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
7769 Error_Pragma ("pragma% conflicts with that #");
7773 System_Extend_Pragma_Arg := Arg1;
7775 if not GNAT_Mode then
7776 System_Extend_Unit := Arg1;
7780 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
7784 ------------------------
7785 -- Extensions_Allowed --
7786 ------------------------
7788 -- pragma Extensions_Allowed (ON | OFF);
7790 when Pragma_Extensions_Allowed =>
7792 Check_Arg_Count (1);
7793 Check_No_Identifiers;
7794 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7796 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
7797 Extensions_Allowed := True;
7798 Ada_Version := Ada_Version_Type'Last;
7801 Extensions_Allowed := False;
7802 Ada_Version := Ada_Version_Explicit;
7809 -- pragma External (
7810 -- [ Convention =>] convention_IDENTIFIER,
7811 -- [ Entity =>] local_NAME
7812 -- [, [External_Name =>] static_string_EXPRESSION ]
7813 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7815 when Pragma_External => External : declare
7819 pragma Warnings (Off, C);
7828 Check_At_Least_N_Arguments (2);
7829 Check_At_Most_N_Arguments (4);
7830 Process_Convention (C, Def_Id);
7831 Note_Possible_Modification
7832 (Get_Pragma_Arg (Arg2), Sure => False);
7833 Process_Interface_Name (Def_Id, Arg3, Arg4);
7834 Set_Exported (Def_Id, Arg2);
7837 --------------------------
7838 -- External_Name_Casing --
7839 --------------------------
7841 -- pragma External_Name_Casing (
7842 -- UPPERCASE | LOWERCASE
7843 -- [, AS_IS | UPPERCASE | LOWERCASE]);
7845 when Pragma_External_Name_Casing => External_Name_Casing : declare
7848 Check_No_Identifiers;
7850 if Arg_Count = 2 then
7852 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
7854 case Chars (Get_Pragma_Arg (Arg2)) is
7856 Opt.External_Name_Exp_Casing := As_Is;
7858 when Name_Uppercase =>
7859 Opt.External_Name_Exp_Casing := Uppercase;
7861 when Name_Lowercase =>
7862 Opt.External_Name_Exp_Casing := Lowercase;
7869 Check_Arg_Count (1);
7872 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
7874 case Chars (Get_Pragma_Arg (Arg1)) is
7875 when Name_Uppercase =>
7876 Opt.External_Name_Imp_Casing := Uppercase;
7878 when Name_Lowercase =>
7879 Opt.External_Name_Imp_Casing := Lowercase;
7884 end External_Name_Casing;
7886 --------------------------
7887 -- Favor_Top_Level --
7888 --------------------------
7890 -- pragma Favor_Top_Level (type_NAME);
7892 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
7893 Named_Entity : Entity_Id;
7897 Check_No_Identifiers;
7898 Check_Arg_Count (1);
7899 Check_Arg_Is_Local_Name (Arg1);
7900 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
7902 -- If it's an access-to-subprogram type (in particular, not a
7903 -- subtype), set the flag on that type.
7905 if Is_Access_Subprogram_Type (Named_Entity) then
7907 Set_Can_Use_Internal_Rep (Named_Entity, False);
7910 -- Otherwise it's an error (name denotes the wrong sort of entity)
7914 ("access-to-subprogram type expected",
7915 Get_Pragma_Arg (Arg1));
7917 end Favor_Top_Level;
7923 -- pragma Fast_Math;
7925 when Pragma_Fast_Math =>
7927 Check_No_Identifiers;
7928 Check_Valid_Configuration_Pragma;
7931 ---------------------------
7932 -- Finalize_Storage_Only --
7933 ---------------------------
7935 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
7937 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
7938 Assoc : constant Node_Id := Arg1;
7939 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
7944 Check_No_Identifiers;
7945 Check_Arg_Count (1);
7946 Check_Arg_Is_Local_Name (Arg1);
7948 Find_Type (Type_Id);
7949 Typ := Entity (Type_Id);
7952 or else Rep_Item_Too_Early (Typ, N)
7956 Typ := Underlying_Type (Typ);
7959 if not Is_Controlled (Typ) then
7960 Error_Pragma ("pragma% must specify controlled type");
7963 Check_First_Subtype (Arg1);
7965 if Finalize_Storage_Only (Typ) then
7966 Error_Pragma ("duplicate pragma%, only one allowed");
7968 elsif not Rep_Item_Too_Late (Typ, N) then
7969 Set_Finalize_Storage_Only (Base_Type (Typ), True);
7971 end Finalize_Storage;
7973 --------------------------
7974 -- Float_Representation --
7975 --------------------------
7977 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
7979 -- FLOAT_REP ::= VAX_Float | IEEE_Float
7981 when Pragma_Float_Representation => Float_Representation : declare
7989 if Arg_Count = 1 then
7990 Check_Valid_Configuration_Pragma;
7992 Check_Arg_Count (2);
7993 Check_Optional_Identifier (Arg2, Name_Entity);
7994 Check_Arg_Is_Local_Name (Arg2);
7997 Check_No_Identifier (Arg1);
7998 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8000 if not OpenVMS_On_Target then
8001 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8003 ("?pragma% ignored (applies only to Open'V'M'S)");
8009 -- One argument case
8011 if Arg_Count = 1 then
8012 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8013 if Opt.Float_Format = 'I' then
8014 Error_Pragma ("'I'E'E'E format previously specified");
8017 Opt.Float_Format := 'V';
8020 if Opt.Float_Format = 'V' then
8021 Error_Pragma ("'V'A'X format previously specified");
8024 Opt.Float_Format := 'I';
8027 Set_Standard_Fpt_Formats;
8029 -- Two argument case
8032 Argx := Get_Pragma_Arg (Arg2);
8034 if not Is_Entity_Name (Argx)
8035 or else not Is_Floating_Point_Type (Entity (Argx))
8038 ("second argument of% pragma must be floating-point type",
8042 Ent := Entity (Argx);
8043 Digs := UI_To_Int (Digits_Value (Ent));
8045 -- Two arguments, VAX_Float case
8047 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8049 when 6 => Set_F_Float (Ent);
8050 when 9 => Set_D_Float (Ent);
8051 when 15 => Set_G_Float (Ent);
8055 ("wrong digits value, must be 6,9 or 15", Arg2);
8058 -- Two arguments, IEEE_Float case
8062 when 6 => Set_IEEE_Short (Ent);
8063 when 15 => Set_IEEE_Long (Ent);
8067 ("wrong digits value, must be 6 or 15", Arg2);
8071 end Float_Representation;
8077 -- pragma Ident (static_string_EXPRESSION)
8079 -- Note: pragma Comment shares this processing. Pragma Comment is
8080 -- identical to Ident, except that the restriction of the argument to
8081 -- 31 characters and the placement restrictions are not enforced for
8084 when Pragma_Ident | Pragma_Comment => Ident : declare
8089 Check_Arg_Count (1);
8090 Check_No_Identifiers;
8091 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8094 -- For pragma Ident, preserve DEC compatibility by requiring the
8095 -- pragma to appear in a declarative part or package spec.
8097 if Prag_Id = Pragma_Ident then
8098 Check_Is_In_Decl_Part_Or_Package_Spec;
8101 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8108 GP := Parent (Parent (N));
8110 if Nkind_In (GP, N_Package_Declaration,
8111 N_Generic_Package_Declaration)
8116 -- If we have a compilation unit, then record the ident value,
8117 -- checking for improper duplication.
8119 if Nkind (GP) = N_Compilation_Unit then
8120 CS := Ident_String (Current_Sem_Unit);
8122 if Present (CS) then
8124 -- For Ident, we do not permit multiple instances
8126 if Prag_Id = Pragma_Ident then
8127 Error_Pragma ("duplicate% pragma not permitted");
8129 -- For Comment, we concatenate the string, unless we want
8130 -- to preserve the tree structure for ASIS.
8132 elsif not ASIS_Mode then
8133 Start_String (Strval (CS));
8134 Store_String_Char (' ');
8135 Store_String_Chars (Strval (Str));
8136 Set_Strval (CS, End_String);
8140 -- In VMS, the effect of IDENT is achieved by passing
8141 -- --identification=name as a --for-linker switch.
8143 if OpenVMS_On_Target then
8146 ("--for-linker=--identification=");
8147 String_To_Name_Buffer (Strval (Str));
8148 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8150 -- Only the last processed IDENT is saved. The main
8151 -- purpose is so an IDENT associated with a main
8152 -- procedure will be used in preference to an IDENT
8153 -- associated with a with'd package.
8155 Replace_Linker_Option_String
8156 (End_String, "--for-linker=--identification=");
8159 Set_Ident_String (Current_Sem_Unit, Str);
8162 -- For subunits, we just ignore the Ident, since in GNAT these
8163 -- are not separate object files, and hence not separate units
8164 -- in the unit table.
8166 elsif Nkind (GP) = N_Subunit then
8169 -- Otherwise we have a misplaced pragma Ident, but we ignore
8170 -- this if we are in an instantiation, since it comes from
8171 -- a generic, and has no relevance to the instantiation.
8173 elsif Prag_Id = Pragma_Ident then
8174 if Instantiation_Location (Loc) = No_Location then
8175 Error_Pragma ("pragma% only allowed at outer level");
8185 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8186 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8188 when Pragma_Implemented => Implemented : declare
8189 Proc_Id : Entity_Id;
8194 Check_Arg_Count (2);
8195 Check_No_Identifiers;
8196 Check_Arg_Is_Identifier (Arg1);
8197 Check_Arg_Is_Local_Name (Arg1);
8199 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8201 -- Extract the name of the local procedure
8203 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8205 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8206 -- primitive procedure of a synchronized tagged type.
8208 if Ekind (Proc_Id) = E_Procedure
8209 and then Is_Primitive (Proc_Id)
8210 and then Present (First_Formal (Proc_Id))
8212 Typ := Etype (First_Formal (Proc_Id));
8214 if Is_Tagged_Type (Typ)
8217 -- Check for a protected, a synchronized or a task interface
8219 ((Is_Interface (Typ)
8220 and then Is_Synchronized_Interface (Typ))
8222 -- Check for a protected type or a task type that implements
8226 (Is_Concurrent_Record_Type (Typ)
8227 and then Present (Interfaces (Typ)))
8229 -- Check for a private record extension with keyword
8233 (Ekind_In (Typ, E_Record_Type_With_Private,
8234 E_Record_Subtype_With_Private)
8235 and then Synchronized_Present (Parent (Typ))))
8240 ("controlling formal must be of synchronized " &
8241 "tagged type", Arg1);
8245 -- Procedures declared inside a protected type must be accepted
8247 elsif Ekind (Proc_Id) = E_Procedure
8248 and then Is_Protected_Type (Scope (Proc_Id))
8252 -- The first argument is not a primitive procedure
8256 ("pragma % must be applied to a primitive procedure", Arg1);
8260 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8261 -- By_Protected_Procedure to the primitive procedure of a task
8264 if Chars (Arg2) = Name_By_Protected_Procedure
8265 and then Is_Interface (Typ)
8266 and then Is_Task_Interface (Typ)
8269 ("implementation kind By_Protected_Procedure cannot be " &
8270 "applied to a task interface primitive", Arg2);
8274 Record_Rep_Item (Proc_Id, N);
8277 ----------------------
8278 -- Implicit_Packing --
8279 ----------------------
8281 -- pragma Implicit_Packing;
8283 when Pragma_Implicit_Packing =>
8285 Check_Arg_Count (0);
8286 Implicit_Packing := True;
8293 -- [Convention =>] convention_IDENTIFIER,
8294 -- [Entity =>] local_NAME
8295 -- [, [External_Name =>] static_string_EXPRESSION ]
8296 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8298 when Pragma_Import =>
8299 Check_Ada_83_Warning;
8305 Check_At_Least_N_Arguments (2);
8306 Check_At_Most_N_Arguments (4);
8307 Process_Import_Or_Interface;
8309 ----------------------
8310 -- Import_Exception --
8311 ----------------------
8313 -- pragma Import_Exception (
8314 -- [Internal =>] LOCAL_NAME
8315 -- [, [External =>] EXTERNAL_SYMBOL]
8316 -- [, [Form =>] Ada | VMS]
8317 -- [, [Code =>] static_integer_EXPRESSION]);
8319 when Pragma_Import_Exception => Import_Exception : declare
8320 Args : Args_List (1 .. 4);
8321 Names : constant Name_List (1 .. 4) := (
8327 Internal : Node_Id renames Args (1);
8328 External : Node_Id renames Args (2);
8329 Form : Node_Id renames Args (3);
8330 Code : Node_Id renames Args (4);
8334 Gather_Associations (Names, Args);
8336 if Present (External) and then Present (Code) then
8338 ("cannot give both External and Code options for pragma%");
8341 Process_Extended_Import_Export_Exception_Pragma (
8342 Arg_Internal => Internal,
8343 Arg_External => External,
8347 if not Is_VMS_Exception (Entity (Internal)) then
8348 Set_Imported (Entity (Internal));
8350 end Import_Exception;
8352 ---------------------
8353 -- Import_Function --
8354 ---------------------
8356 -- pragma Import_Function (
8357 -- [Internal =>] LOCAL_NAME,
8358 -- [, [External =>] EXTERNAL_SYMBOL]
8359 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8360 -- [, [Result_Type =>] SUBTYPE_MARK]
8361 -- [, [Mechanism =>] MECHANISM]
8362 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8363 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8365 -- EXTERNAL_SYMBOL ::=
8367 -- | static_string_EXPRESSION
8369 -- PARAMETER_TYPES ::=
8371 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8373 -- TYPE_DESIGNATOR ::=
8375 -- | subtype_Name ' Access
8379 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8381 -- MECHANISM_ASSOCIATION ::=
8382 -- [formal_parameter_NAME =>] MECHANISM_NAME
8384 -- MECHANISM_NAME ::=
8387 -- | Descriptor [([Class =>] CLASS_NAME)]
8389 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8391 when Pragma_Import_Function => Import_Function : declare
8392 Args : Args_List (1 .. 7);
8393 Names : constant Name_List (1 .. 7) := (
8396 Name_Parameter_Types,
8399 Name_Result_Mechanism,
8400 Name_First_Optional_Parameter);
8402 Internal : Node_Id renames Args (1);
8403 External : Node_Id renames Args (2);
8404 Parameter_Types : Node_Id renames Args (3);
8405 Result_Type : Node_Id renames Args (4);
8406 Mechanism : Node_Id renames Args (5);
8407 Result_Mechanism : Node_Id renames Args (6);
8408 First_Optional_Parameter : Node_Id renames Args (7);
8412 Gather_Associations (Names, Args);
8413 Process_Extended_Import_Export_Subprogram_Pragma (
8414 Arg_Internal => Internal,
8415 Arg_External => External,
8416 Arg_Parameter_Types => Parameter_Types,
8417 Arg_Result_Type => Result_Type,
8418 Arg_Mechanism => Mechanism,
8419 Arg_Result_Mechanism => Result_Mechanism,
8420 Arg_First_Optional_Parameter => First_Optional_Parameter);
8421 end Import_Function;
8427 -- pragma Import_Object (
8428 -- [Internal =>] LOCAL_NAME
8429 -- [, [External =>] EXTERNAL_SYMBOL]
8430 -- [, [Size =>] EXTERNAL_SYMBOL]);
8432 -- EXTERNAL_SYMBOL ::=
8434 -- | static_string_EXPRESSION
8436 when Pragma_Import_Object => Import_Object : declare
8437 Args : Args_List (1 .. 3);
8438 Names : constant Name_List (1 .. 3) := (
8443 Internal : Node_Id renames Args (1);
8444 External : Node_Id renames Args (2);
8445 Size : Node_Id renames Args (3);
8449 Gather_Associations (Names, Args);
8450 Process_Extended_Import_Export_Object_Pragma (
8451 Arg_Internal => Internal,
8452 Arg_External => External,
8456 ----------------------
8457 -- Import_Procedure --
8458 ----------------------
8460 -- pragma Import_Procedure (
8461 -- [Internal =>] LOCAL_NAME
8462 -- [, [External =>] EXTERNAL_SYMBOL]
8463 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8464 -- [, [Mechanism =>] MECHANISM]
8465 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8467 -- EXTERNAL_SYMBOL ::=
8469 -- | static_string_EXPRESSION
8471 -- PARAMETER_TYPES ::=
8473 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8475 -- TYPE_DESIGNATOR ::=
8477 -- | subtype_Name ' Access
8481 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8483 -- MECHANISM_ASSOCIATION ::=
8484 -- [formal_parameter_NAME =>] MECHANISM_NAME
8486 -- MECHANISM_NAME ::=
8489 -- | Descriptor [([Class =>] CLASS_NAME)]
8491 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8493 when Pragma_Import_Procedure => Import_Procedure : declare
8494 Args : Args_List (1 .. 5);
8495 Names : constant Name_List (1 .. 5) := (
8498 Name_Parameter_Types,
8500 Name_First_Optional_Parameter);
8502 Internal : Node_Id renames Args (1);
8503 External : Node_Id renames Args (2);
8504 Parameter_Types : Node_Id renames Args (3);
8505 Mechanism : Node_Id renames Args (4);
8506 First_Optional_Parameter : Node_Id renames Args (5);
8510 Gather_Associations (Names, Args);
8511 Process_Extended_Import_Export_Subprogram_Pragma (
8512 Arg_Internal => Internal,
8513 Arg_External => External,
8514 Arg_Parameter_Types => Parameter_Types,
8515 Arg_Mechanism => Mechanism,
8516 Arg_First_Optional_Parameter => First_Optional_Parameter);
8517 end Import_Procedure;
8519 -----------------------------
8520 -- Import_Valued_Procedure --
8521 -----------------------------
8523 -- pragma Import_Valued_Procedure (
8524 -- [Internal =>] LOCAL_NAME
8525 -- [, [External =>] EXTERNAL_SYMBOL]
8526 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8527 -- [, [Mechanism =>] MECHANISM]
8528 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8530 -- EXTERNAL_SYMBOL ::=
8532 -- | static_string_EXPRESSION
8534 -- PARAMETER_TYPES ::=
8536 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8538 -- TYPE_DESIGNATOR ::=
8540 -- | subtype_Name ' Access
8544 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8546 -- MECHANISM_ASSOCIATION ::=
8547 -- [formal_parameter_NAME =>] MECHANISM_NAME
8549 -- MECHANISM_NAME ::=
8552 -- | Descriptor [([Class =>] CLASS_NAME)]
8554 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8556 when Pragma_Import_Valued_Procedure =>
8557 Import_Valued_Procedure : declare
8558 Args : Args_List (1 .. 5);
8559 Names : constant Name_List (1 .. 5) := (
8562 Name_Parameter_Types,
8564 Name_First_Optional_Parameter);
8566 Internal : Node_Id renames Args (1);
8567 External : Node_Id renames Args (2);
8568 Parameter_Types : Node_Id renames Args (3);
8569 Mechanism : Node_Id renames Args (4);
8570 First_Optional_Parameter : Node_Id renames Args (5);
8574 Gather_Associations (Names, Args);
8575 Process_Extended_Import_Export_Subprogram_Pragma (
8576 Arg_Internal => Internal,
8577 Arg_External => External,
8578 Arg_Parameter_Types => Parameter_Types,
8579 Arg_Mechanism => Mechanism,
8580 Arg_First_Optional_Parameter => First_Optional_Parameter);
8581 end Import_Valued_Procedure;
8587 -- pragma Independent (LOCAL_NAME);
8589 when Pragma_Independent => Independent : declare
8596 Check_Ada_83_Warning;
8598 Check_No_Identifiers;
8599 Check_Arg_Count (1);
8600 Check_Arg_Is_Local_Name (Arg1);
8601 E_Id := Get_Pragma_Arg (Arg1);
8603 if Etype (E_Id) = Any_Type then
8608 D := Declaration_Node (E);
8611 -- Check duplicate before we chain ourselves!
8613 Check_Duplicate_Pragma (E);
8615 -- Check appropriate entity
8618 if Rep_Item_Too_Early (E, N)
8620 Rep_Item_Too_Late (E, N)
8624 Check_First_Subtype (Arg1);
8627 elsif K = N_Object_Declaration
8628 or else (K = N_Component_Declaration
8629 and then Original_Record_Component (E) = E)
8631 if Rep_Item_Too_Late (E, N) then
8637 ("inappropriate entity for pragma%", Arg1);
8640 Independence_Checks.Append ((N, E));
8643 ----------------------------
8644 -- Independent_Components --
8645 ----------------------------
8647 -- pragma Atomic_Components (array_LOCAL_NAME);
8649 -- This processing is shared by Volatile_Components
8651 when Pragma_Independent_Components => Independent_Components : declare
8658 Check_Ada_83_Warning;
8660 Check_No_Identifiers;
8661 Check_Arg_Count (1);
8662 Check_Arg_Is_Local_Name (Arg1);
8663 E_Id := Get_Pragma_Arg (Arg1);
8665 if Etype (E_Id) = Any_Type then
8671 -- Check duplicate before we chain ourselves!
8673 Check_Duplicate_Pragma (E);
8675 -- Check appropriate entity
8677 if Rep_Item_Too_Early (E, N)
8679 Rep_Item_Too_Late (E, N)
8684 D := Declaration_Node (E);
8687 if (K = N_Full_Type_Declaration
8688 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
8690 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
8691 and then Nkind (D) = N_Object_Declaration
8692 and then Nkind (Object_Definition (D)) =
8693 N_Constrained_Array_Definition)
8695 Independence_Checks.Append ((N, E));
8698 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
8700 end Independent_Components;
8702 ------------------------
8703 -- Initialize_Scalars --
8704 ------------------------
8706 -- pragma Initialize_Scalars;
8708 when Pragma_Initialize_Scalars =>
8710 Check_Arg_Count (0);
8711 Check_Valid_Configuration_Pragma;
8712 Check_Restriction (No_Initialize_Scalars, N);
8714 -- Initialize_Scalars creates false positives in CodePeer,
8715 -- so ignore this pragma in this mode.
8717 if not Restriction_Active (No_Initialize_Scalars)
8718 and then not CodePeer_Mode
8720 Init_Or_Norm_Scalars := True;
8721 Initialize_Scalars := True;
8728 -- pragma Inline ( NAME {, NAME} );
8730 when Pragma_Inline =>
8732 -- Pragma is active if inlining option is active
8734 Process_Inline (Inline_Active);
8740 -- pragma Inline_Always ( NAME {, NAME} );
8742 when Pragma_Inline_Always =>
8745 -- Pragma always active unless in CodePeer mode, since this causes
8746 -- walk order issues.
8748 if not CodePeer_Mode then
8749 Process_Inline (True);
8752 --------------------
8753 -- Inline_Generic --
8754 --------------------
8756 -- pragma Inline_Generic (NAME {, NAME});
8758 when Pragma_Inline_Generic =>
8760 Process_Generic_List;
8762 ----------------------
8763 -- Inspection_Point --
8764 ----------------------
8766 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
8768 when Pragma_Inspection_Point => Inspection_Point : declare
8773 if Arg_Count > 0 then
8776 Exp := Get_Pragma_Arg (Arg);
8779 if not Is_Entity_Name (Exp)
8780 or else not Is_Object (Entity (Exp))
8782 Error_Pragma_Arg ("object name required", Arg);
8789 end Inspection_Point;
8795 -- pragma Interface (
8796 -- [ Convention =>] convention_IDENTIFIER,
8797 -- [ Entity =>] local_NAME
8798 -- [, [External_Name =>] static_string_EXPRESSION ]
8799 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8801 when Pragma_Interface =>
8808 Check_At_Least_N_Arguments (2);
8809 Check_At_Most_N_Arguments (4);
8810 Process_Import_Or_Interface;
8812 -- In Ada 2005, the permission to use Interface (a reserved word)
8813 -- as a pragma name is considered an obsolescent feature.
8815 if Ada_Version >= Ada_2005 then
8817 (No_Obsolescent_Features, Pragma_Identifier (N));
8820 --------------------
8821 -- Interface_Name --
8822 --------------------
8824 -- pragma Interface_Name (
8825 -- [ Entity =>] local_NAME
8826 -- [,[External_Name =>] static_string_EXPRESSION ]
8827 -- [,[Link_Name =>] static_string_EXPRESSION ]);
8829 when Pragma_Interface_Name => Interface_Name : declare
8838 ((Name_Entity, Name_External_Name, Name_Link_Name));
8839 Check_At_Least_N_Arguments (2);
8840 Check_At_Most_N_Arguments (3);
8841 Id := Get_Pragma_Arg (Arg1);
8844 if not Is_Entity_Name (Id) then
8846 ("first argument for pragma% must be entity name", Arg1);
8847 elsif Etype (Id) = Any_Type then
8850 Def_Id := Entity (Id);
8853 -- Special DEC-compatible processing for the object case, forces
8854 -- object to be imported.
8856 if Ekind (Def_Id) = E_Variable then
8857 Kill_Size_Check_Code (Def_Id);
8858 Note_Possible_Modification (Id, Sure => False);
8860 -- Initialization is not allowed for imported variable
8862 if Present (Expression (Parent (Def_Id)))
8863 and then Comes_From_Source (Expression (Parent (Def_Id)))
8865 Error_Msg_Sloc := Sloc (Def_Id);
8867 ("no initialization allowed for declaration of& #",
8871 -- For compatibility, support VADS usage of providing both
8872 -- pragmas Interface and Interface_Name to obtain the effect
8873 -- of a single Import pragma.
8875 if Is_Imported (Def_Id)
8876 and then Present (First_Rep_Item (Def_Id))
8877 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
8879 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
8883 Set_Imported (Def_Id);
8886 Set_Is_Public (Def_Id);
8887 Process_Interface_Name (Def_Id, Arg2, Arg3);
8890 -- Otherwise must be subprogram
8892 elsif not Is_Subprogram (Def_Id) then
8894 ("argument of pragma% is not subprogram", Arg1);
8897 Check_At_Most_N_Arguments (3);
8901 -- Loop through homonyms
8904 Def_Id := Get_Base_Subprogram (Hom_Id);
8906 if Is_Imported (Def_Id) then
8907 Process_Interface_Name (Def_Id, Arg2, Arg3);
8911 exit when From_Aspect_Specification (N);
8912 Hom_Id := Homonym (Hom_Id);
8914 exit when No (Hom_Id)
8915 or else Scope (Hom_Id) /= Current_Scope;
8920 ("argument of pragma% is not imported subprogram",
8926 -----------------------
8927 -- Interrupt_Handler --
8928 -----------------------
8930 -- pragma Interrupt_Handler (handler_NAME);
8932 when Pragma_Interrupt_Handler =>
8933 Check_Ada_83_Warning;
8934 Check_Arg_Count (1);
8935 Check_No_Identifiers;
8937 if No_Run_Time_Mode then
8938 Error_Msg_CRT ("Interrupt_Handler pragma", N);
8940 Check_Interrupt_Or_Attach_Handler;
8941 Process_Interrupt_Or_Attach_Handler;
8944 ------------------------
8945 -- Interrupt_Priority --
8946 ------------------------
8948 -- pragma Interrupt_Priority [(EXPRESSION)];
8950 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
8951 P : constant Node_Id := Parent (N);
8955 Check_Ada_83_Warning;
8957 if Arg_Count /= 0 then
8958 Arg := Get_Pragma_Arg (Arg1);
8959 Check_Arg_Count (1);
8960 Check_No_Identifiers;
8962 -- The expression must be analyzed in the special manner
8963 -- described in "Handling of Default and Per-Object
8964 -- Expressions" in sem.ads.
8966 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
8969 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
8973 elsif Has_Priority_Pragma (P) then
8974 Error_Pragma ("duplicate pragma% not allowed");
8977 Set_Has_Priority_Pragma (P, True);
8978 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8980 end Interrupt_Priority;
8982 ---------------------
8983 -- Interrupt_State --
8984 ---------------------
8986 -- pragma Interrupt_State (
8987 -- [Name =>] INTERRUPT_ID,
8988 -- [State =>] INTERRUPT_STATE);
8990 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
8991 -- INTERRUPT_STATE => System | Runtime | User
8993 -- Note: if the interrupt id is given as an identifier, then it must
8994 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
8995 -- given as a static integer expression which must be in the range of
8996 -- Ada.Interrupts.Interrupt_ID.
8998 when Pragma_Interrupt_State => Interrupt_State : declare
9000 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9001 -- This is the entity Ada.Interrupts.Interrupt_ID;
9003 State_Type : Character;
9004 -- Set to 's'/'r'/'u' for System/Runtime/User
9007 -- Index to entry in Interrupt_States table
9010 -- Value of interrupt
9012 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9013 -- The first argument to the pragma
9015 Int_Ent : Entity_Id;
9016 -- Interrupt entity in Ada.Interrupts.Names
9020 Check_Arg_Order ((Name_Name, Name_State));
9021 Check_Arg_Count (2);
9023 Check_Optional_Identifier (Arg1, Name_Name);
9024 Check_Optional_Identifier (Arg2, Name_State);
9025 Check_Arg_Is_Identifier (Arg2);
9027 -- First argument is identifier
9029 if Nkind (Arg1X) = N_Identifier then
9031 -- Search list of names in Ada.Interrupts.Names
9033 Int_Ent := First_Entity (RTE (RE_Names));
9035 if No (Int_Ent) then
9036 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9038 elsif Chars (Int_Ent) = Chars (Arg1X) then
9039 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9043 Next_Entity (Int_Ent);
9046 -- First argument is not an identifier, so it must be a static
9047 -- expression of type Ada.Interrupts.Interrupt_ID.
9050 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9051 Int_Val := Expr_Value (Arg1X);
9053 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9055 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9058 ("value not in range of type " &
9059 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9065 case Chars (Get_Pragma_Arg (Arg2)) is
9066 when Name_Runtime => State_Type := 'r';
9067 when Name_System => State_Type := 's';
9068 when Name_User => State_Type := 'u';
9071 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9074 -- Check if entry is already stored
9076 IST_Num := Interrupt_States.First;
9078 -- If entry not found, add it
9080 if IST_Num > Interrupt_States.Last then
9081 Interrupt_States.Append
9082 ((Interrupt_Number => UI_To_Int (Int_Val),
9083 Interrupt_State => State_Type,
9084 Pragma_Loc => Loc));
9087 -- Case of entry for the same entry
9089 elsif Int_Val = Interrupt_States.Table (IST_Num).
9092 -- If state matches, done, no need to make redundant entry
9095 State_Type = Interrupt_States.Table (IST_Num).
9098 -- Otherwise if state does not match, error
9101 Interrupt_States.Table (IST_Num).Pragma_Loc;
9103 ("state conflicts with that given #", Arg2);
9107 IST_Num := IST_Num + 1;
9109 end Interrupt_State;
9111 ----------------------
9112 -- Java_Constructor --
9113 ----------------------
9115 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9117 -- Also handles pragma CIL_Constructor
9119 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9120 Java_Constructor : declare
9121 Convention : Convention_Id;
9125 This_Formal : Entity_Id;
9129 Check_Arg_Count (1);
9130 Check_Optional_Identifier (Arg1, Name_Entity);
9131 Check_Arg_Is_Local_Name (Arg1);
9133 Id := Get_Pragma_Arg (Arg1);
9134 Find_Program_Unit_Name (Id);
9136 -- If we did not find the name, we are done
9138 if Etype (Id) = Any_Type then
9142 -- Check wrong use of pragma in wrong VM target
9144 if VM_Target = No_VM then
9147 elsif VM_Target = CLI_Target
9148 and then Prag_Id = Pragma_Java_Constructor
9150 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9152 elsif VM_Target = JVM_Target
9153 and then Prag_Id = Pragma_CIL_Constructor
9155 Error_Pragma ("must use pragma 'Java_'Constructor");
9159 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9160 when Pragma_Java_Constructor => Convention := Convention_Java;
9161 when others => null;
9164 Hom_Id := Entity (Id);
9166 -- Loop through homonyms
9169 Def_Id := Get_Base_Subprogram (Hom_Id);
9171 -- The constructor is required to be a function
9173 if Ekind (Def_Id) /= E_Function then
9174 if VM_Target = JVM_Target then
9176 ("pragma% requires function returning a " &
9177 "'Java access type", Def_Id);
9180 ("pragma% requires function returning a " &
9181 "'C'I'L access type", Def_Id);
9185 -- Check arguments: For tagged type the first formal must be
9186 -- named "this" and its type must be a named access type
9187 -- designating a class-wide tagged type that has convention
9188 -- CIL/Java. The first formal must also have a null default
9189 -- value. For example:
9191 -- type Typ is tagged ...
9192 -- type Ref is access all Typ;
9193 -- pragma Convention (CIL, Typ);
9195 -- function New_Typ (This : Ref) return Ref;
9196 -- function New_Typ (This : Ref; I : Integer) return Ref;
9197 -- pragma Cil_Constructor (New_Typ);
9199 -- Reason: The first formal must NOT be a primitive of the
9202 -- This rule also applies to constructors of delegates used
9203 -- to interface with standard target libraries. For example:
9205 -- type Delegate is access procedure ...
9206 -- pragma Import (CIL, Delegate, ...);
9208 -- function new_Delegate
9209 -- (This : Delegate := null; ... ) return Delegate;
9211 -- For value-types this rule does not apply.
9213 if not Is_Value_Type (Etype (Def_Id)) then
9214 if No (First_Formal (Def_Id)) then
9215 Error_Msg_Name_1 := Pname;
9216 Error_Msg_N ("% function must have parameters", Def_Id);
9220 -- In the JRE library we have several occurrences in which
9221 -- the "this" parameter is not the first formal.
9223 This_Formal := First_Formal (Def_Id);
9225 -- In the JRE library we have several occurrences in which
9226 -- the "this" parameter is not the first formal. Search for
9229 if VM_Target = JVM_Target then
9230 while Present (This_Formal)
9231 and then Get_Name_String (Chars (This_Formal)) /= "this"
9233 Next_Formal (This_Formal);
9236 if No (This_Formal) then
9237 This_Formal := First_Formal (Def_Id);
9241 -- Warning: The first parameter should be named "this".
9242 -- We temporarily allow it because we have the following
9243 -- case in the Java runtime (file s-osinte.ads) ???
9245 -- function new_Thread
9246 -- (Self_Id : System.Address) return Thread_Id;
9247 -- pragma Java_Constructor (new_Thread);
9249 if VM_Target = JVM_Target
9250 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9252 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9256 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9257 Error_Msg_Name_1 := Pname;
9259 ("first formal of % function must be named `this`",
9260 Parent (This_Formal));
9262 elsif not Is_Access_Type (Etype (This_Formal)) then
9263 Error_Msg_Name_1 := Pname;
9265 ("first formal of % function must be an access type",
9266 Parameter_Type (Parent (This_Formal)));
9268 -- For delegates the type of the first formal must be a
9269 -- named access-to-subprogram type (see previous example)
9271 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9272 and then Ekind (Etype (This_Formal))
9273 /= E_Access_Subprogram_Type
9275 Error_Msg_Name_1 := Pname;
9277 ("first formal of % function must be a named access" &
9278 " to subprogram type",
9279 Parameter_Type (Parent (This_Formal)));
9281 -- Warning: We should reject anonymous access types because
9282 -- the constructor must not be handled as a primitive of the
9283 -- tagged type. We temporarily allow it because this profile
9284 -- is currently generated by cil2ada???
9286 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9287 and then not Ekind_In (Etype (This_Formal),
9289 E_General_Access_Type,
9290 E_Anonymous_Access_Type)
9292 Error_Msg_Name_1 := Pname;
9294 ("first formal of % function must be a named access" &
9296 Parameter_Type (Parent (This_Formal)));
9298 elsif Atree.Convention
9299 (Designated_Type (Etype (This_Formal))) /= Convention
9301 Error_Msg_Name_1 := Pname;
9303 if Convention = Convention_Java then
9305 ("pragma% requires convention 'Cil in designated" &
9307 Parameter_Type (Parent (This_Formal)));
9310 ("pragma% requires convention 'Java in designated" &
9312 Parameter_Type (Parent (This_Formal)));
9315 elsif No (Expression (Parent (This_Formal)))
9316 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9318 Error_Msg_Name_1 := Pname;
9320 ("pragma% requires first formal with default `null`",
9321 Parameter_Type (Parent (This_Formal)));
9325 -- Check result type: the constructor must be a function
9327 -- * a value type (only allowed in the CIL compiler)
9328 -- * an access-to-subprogram type with convention Java/CIL
9329 -- * an access-type designating a type that has convention
9332 if Is_Value_Type (Etype (Def_Id)) then
9335 -- Access-to-subprogram type with convention Java/CIL
9337 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9338 if Atree.Convention (Etype (Def_Id)) /= Convention then
9339 if Convention = Convention_Java then
9341 ("pragma% requires function returning a " &
9342 "'Java access type", Arg1);
9344 pragma Assert (Convention = Convention_CIL);
9346 ("pragma% requires function returning a " &
9347 "'C'I'L access type", Arg1);
9351 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9352 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9353 E_General_Access_Type)
9356 (Designated_Type (Etype (Def_Id))) /= Convention
9358 Error_Msg_Name_1 := Pname;
9360 if Convention = Convention_Java then
9362 ("pragma% requires function returning a named" &
9363 "'Java access type", Arg1);
9366 ("pragma% requires function returning a named" &
9367 "'C'I'L access type", Arg1);
9372 Set_Is_Constructor (Def_Id);
9373 Set_Convention (Def_Id, Convention);
9374 Set_Is_Imported (Def_Id);
9376 exit when From_Aspect_Specification (N);
9377 Hom_Id := Homonym (Hom_Id);
9379 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9381 end Java_Constructor;
9383 ----------------------
9384 -- Java_Interface --
9385 ----------------------
9387 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
9389 when Pragma_Java_Interface => Java_Interface : declare
9395 Check_Arg_Count (1);
9396 Check_Optional_Identifier (Arg1, Name_Entity);
9397 Check_Arg_Is_Local_Name (Arg1);
9399 Arg := Get_Pragma_Arg (Arg1);
9402 if Etype (Arg) = Any_Type then
9406 if not Is_Entity_Name (Arg)
9407 or else not Is_Type (Entity (Arg))
9409 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
9412 Typ := Underlying_Type (Entity (Arg));
9414 -- For now simply check some of the semantic constraints on the
9415 -- type. This currently leaves out some restrictions on interface
9416 -- types, namely that the parent type must be java.lang.Object.Typ
9417 -- and that all primitives of the type should be declared
9420 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
9421 Error_Pragma_Arg ("pragma% requires an abstract "
9422 & "tagged type", Arg1);
9424 elsif not Has_Discriminants (Typ)
9425 or else Ekind (Etype (First_Discriminant (Typ)))
9426 /= E_Anonymous_Access_Type
9428 not Is_Class_Wide_Type
9429 (Designated_Type (Etype (First_Discriminant (Typ))))
9432 ("type must have a class-wide access discriminant", Arg1);
9440 -- pragma Keep_Names ([On => ] local_NAME);
9442 when Pragma_Keep_Names => Keep_Names : declare
9447 Check_Arg_Count (1);
9448 Check_Optional_Identifier (Arg1, Name_On);
9449 Check_Arg_Is_Local_Name (Arg1);
9451 Arg := Get_Pragma_Arg (Arg1);
9454 if Etype (Arg) = Any_Type then
9458 if not Is_Entity_Name (Arg)
9459 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
9462 ("pragma% requires a local enumeration type", Arg1);
9465 Set_Discard_Names (Entity (Arg), False);
9472 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
9474 when Pragma_License =>
9476 Check_Arg_Count (1);
9477 Check_No_Identifiers;
9478 Check_Valid_Configuration_Pragma;
9479 Check_Arg_Is_Identifier (Arg1);
9482 Sind : constant Source_File_Index :=
9483 Source_Index (Current_Sem_Unit);
9486 case Chars (Get_Pragma_Arg (Arg1)) is
9488 Set_License (Sind, GPL);
9490 when Name_Modified_GPL =>
9491 Set_License (Sind, Modified_GPL);
9493 when Name_Restricted =>
9494 Set_License (Sind, Restricted);
9496 when Name_Unrestricted =>
9497 Set_License (Sind, Unrestricted);
9500 Error_Pragma_Arg ("invalid license name", Arg1);
9508 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
9510 when Pragma_Link_With => Link_With : declare
9516 if Operating_Mode = Generate_Code
9517 and then In_Extended_Main_Source_Unit (N)
9519 Check_At_Least_N_Arguments (1);
9520 Check_No_Identifiers;
9521 Check_Is_In_Decl_Part_Or_Package_Spec;
9522 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9526 while Present (Arg) loop
9527 Check_Arg_Is_Static_Expression (Arg, Standard_String);
9529 -- Store argument, converting sequences of spaces to a
9530 -- single null character (this is one of the differences
9531 -- in processing between Link_With and Linker_Options).
9534 C : constant Char_Code := Get_Char_Code (' ');
9535 S : constant String_Id :=
9536 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
9537 L : constant Nat := String_Length (S);
9540 procedure Skip_Spaces;
9541 -- Advance F past any spaces
9547 procedure Skip_Spaces is
9549 while F <= L and then Get_String_Char (S, F) = C loop
9554 -- Start of processing for Arg_Store
9557 Skip_Spaces; -- skip leading spaces
9559 -- Loop through characters, changing any embedded
9560 -- sequence of spaces to a single null character (this
9561 -- is how Link_With/Linker_Options differ)
9564 if Get_String_Char (S, F) = C then
9567 Store_String_Char (ASCII.NUL);
9570 Store_String_Char (Get_String_Char (S, F));
9578 if Present (Arg) then
9579 Store_String_Char (ASCII.NUL);
9583 Store_Linker_Option_String (End_String);
9591 -- pragma Linker_Alias (
9592 -- [Entity =>] LOCAL_NAME
9593 -- [Target =>] static_string_EXPRESSION);
9595 when Pragma_Linker_Alias =>
9597 Check_Arg_Order ((Name_Entity, Name_Target));
9598 Check_Arg_Count (2);
9599 Check_Optional_Identifier (Arg1, Name_Entity);
9600 Check_Optional_Identifier (Arg2, Name_Target);
9601 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9602 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9604 -- The only processing required is to link this item on to the
9605 -- list of rep items for the given entity. This is accomplished
9606 -- by the call to Rep_Item_Too_Late (when no error is detected
9607 -- and False is returned).
9609 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
9612 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
9615 ------------------------
9616 -- Linker_Constructor --
9617 ------------------------
9619 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
9621 -- Code is shared with Linker_Destructor
9623 -----------------------
9624 -- Linker_Destructor --
9625 -----------------------
9627 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
9629 when Pragma_Linker_Constructor |
9630 Pragma_Linker_Destructor =>
9631 Linker_Constructor : declare
9637 Check_Arg_Count (1);
9638 Check_No_Identifiers;
9639 Check_Arg_Is_Local_Name (Arg1);
9640 Arg1_X := Get_Pragma_Arg (Arg1);
9642 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
9644 if not Is_Library_Level_Entity (Proc) then
9646 ("argument for pragma% must be library level entity", Arg1);
9649 -- The only processing required is to link this item on to the
9650 -- list of rep items for the given entity. This is accomplished
9651 -- by the call to Rep_Item_Too_Late (when no error is detected
9652 -- and False is returned).
9654 if Rep_Item_Too_Late (Proc, N) then
9657 Set_Has_Gigi_Rep_Item (Proc);
9659 end Linker_Constructor;
9661 --------------------
9662 -- Linker_Options --
9663 --------------------
9665 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
9667 when Pragma_Linker_Options => Linker_Options : declare
9671 Check_Ada_83_Warning;
9672 Check_No_Identifiers;
9673 Check_Arg_Count (1);
9674 Check_Is_In_Decl_Part_Or_Package_Spec;
9675 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9676 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
9679 while Present (Arg) loop
9680 Check_Arg_Is_Static_Expression (Arg, Standard_String);
9681 Store_String_Char (ASCII.NUL);
9683 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
9687 if Operating_Mode = Generate_Code
9688 and then In_Extended_Main_Source_Unit (N)
9690 Store_Linker_Option_String (End_String);
9694 --------------------
9695 -- Linker_Section --
9696 --------------------
9698 -- pragma Linker_Section (
9699 -- [Entity =>] LOCAL_NAME
9700 -- [Section =>] static_string_EXPRESSION);
9702 when Pragma_Linker_Section =>
9704 Check_Arg_Order ((Name_Entity, Name_Section));
9705 Check_Arg_Count (2);
9706 Check_Optional_Identifier (Arg1, Name_Entity);
9707 Check_Optional_Identifier (Arg2, Name_Section);
9708 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9709 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9711 -- This pragma applies only to objects
9713 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
9714 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
9717 -- The only processing required is to link this item on to the
9718 -- list of rep items for the given entity. This is accomplished
9719 -- by the call to Rep_Item_Too_Late (when no error is detected
9720 -- and False is returned).
9722 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
9725 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
9732 -- pragma List (On | Off)
9734 -- There is nothing to do here, since we did all the processing for
9735 -- this pragma in Par.Prag (so that it works properly even in syntax
9741 --------------------
9742 -- Locking_Policy --
9743 --------------------
9745 -- pragma Locking_Policy (policy_IDENTIFIER);
9747 when Pragma_Locking_Policy => declare
9751 Check_Ada_83_Warning;
9752 Check_Arg_Count (1);
9753 Check_No_Identifiers;
9754 Check_Arg_Is_Locking_Policy (Arg1);
9755 Check_Valid_Configuration_Pragma;
9756 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
9757 LP := Fold_Upper (Name_Buffer (1));
9759 if Locking_Policy /= ' '
9760 and then Locking_Policy /= LP
9762 Error_Msg_Sloc := Locking_Policy_Sloc;
9763 Error_Pragma ("locking policy incompatible with policy#");
9765 -- Set new policy, but always preserve System_Location since we
9766 -- like the error message with the run time name.
9769 Locking_Policy := LP;
9771 if Locking_Policy_Sloc /= System_Location then
9772 Locking_Policy_Sloc := Loc;
9781 -- pragma Long_Float (D_Float | G_Float);
9783 when Pragma_Long_Float =>
9785 Check_Valid_Configuration_Pragma;
9786 Check_Arg_Count (1);
9787 Check_No_Identifier (Arg1);
9788 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
9790 if not OpenVMS_On_Target then
9791 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
9796 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
9797 if Opt.Float_Format_Long = 'G' then
9798 Error_Pragma ("G_Float previously specified");
9801 Opt.Float_Format_Long := 'D';
9803 -- G_Float case (this is the default, does not need overriding)
9806 if Opt.Float_Format_Long = 'D' then
9807 Error_Pragma ("D_Float previously specified");
9810 Opt.Float_Format_Long := 'G';
9813 Set_Standard_Fpt_Formats;
9815 -----------------------
9816 -- Machine_Attribute --
9817 -----------------------
9819 -- pragma Machine_Attribute (
9820 -- [Entity =>] LOCAL_NAME,
9821 -- [Attribute_Name =>] static_string_EXPRESSION
9822 -- [, [Info =>] static_EXPRESSION] );
9824 when Pragma_Machine_Attribute => Machine_Attribute : declare
9829 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
9831 if Arg_Count = 3 then
9832 Check_Optional_Identifier (Arg3, Name_Info);
9833 Check_Arg_Is_Static_Expression (Arg3);
9835 Check_Arg_Count (2);
9838 Check_Optional_Identifier (Arg1, Name_Entity);
9839 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
9840 Check_Arg_Is_Local_Name (Arg1);
9841 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9842 Def_Id := Entity (Get_Pragma_Arg (Arg1));
9844 if Is_Access_Type (Def_Id) then
9845 Def_Id := Designated_Type (Def_Id);
9848 if Rep_Item_Too_Early (Def_Id, N) then
9852 Def_Id := Underlying_Type (Def_Id);
9854 -- The only processing required is to link this item on to the
9855 -- list of rep items for the given entity. This is accomplished
9856 -- by the call to Rep_Item_Too_Late (when no error is detected
9857 -- and False is returned).
9859 if Rep_Item_Too_Late (Def_Id, N) then
9862 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
9864 end Machine_Attribute;
9871 -- (MAIN_OPTION [, MAIN_OPTION]);
9874 -- [STACK_SIZE =>] static_integer_EXPRESSION
9875 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
9876 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
9878 when Pragma_Main => Main : declare
9879 Args : Args_List (1 .. 3);
9880 Names : constant Name_List (1 .. 3) := (
9882 Name_Task_Stack_Size_Default,
9883 Name_Time_Slicing_Enabled);
9889 Gather_Associations (Names, Args);
9891 for J in 1 .. 2 loop
9892 if Present (Args (J)) then
9893 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
9897 if Present (Args (3)) then
9898 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
9902 while Present (Nod) loop
9903 if Nkind (Nod) = N_Pragma
9904 and then Pragma_Name (Nod) = Name_Main
9906 Error_Msg_Name_1 := Pname;
9907 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9918 -- pragma Main_Storage
9919 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
9921 -- MAIN_STORAGE_OPTION ::=
9922 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
9923 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
9925 when Pragma_Main_Storage => Main_Storage : declare
9926 Args : Args_List (1 .. 2);
9927 Names : constant Name_List (1 .. 2) := (
9928 Name_Working_Storage,
9935 Gather_Associations (Names, Args);
9937 for J in 1 .. 2 loop
9938 if Present (Args (J)) then
9939 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
9943 Check_In_Main_Program;
9946 while Present (Nod) loop
9947 if Nkind (Nod) = N_Pragma
9948 and then Pragma_Name (Nod) = Name_Main_Storage
9950 Error_Msg_Name_1 := Pname;
9951 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9962 -- pragma Memory_Size (NUMERIC_LITERAL)
9964 when Pragma_Memory_Size =>
9967 -- Memory size is simply ignored
9969 Check_No_Identifiers;
9970 Check_Arg_Count (1);
9971 Check_Arg_Is_Integer_Literal (Arg1);
9979 -- The only correct use of this pragma is on its own in a file, in
9980 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
9981 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
9982 -- check for a file containing nothing but a No_Body pragma). If we
9983 -- attempt to process it during normal semantics processing, it means
9984 -- it was misplaced.
9986 when Pragma_No_Body =>
9994 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
9996 when Pragma_No_Return => No_Return : declare
10004 Check_At_Least_N_Arguments (1);
10006 -- Loop through arguments of pragma
10009 while Present (Arg) loop
10010 Check_Arg_Is_Local_Name (Arg);
10011 Id := Get_Pragma_Arg (Arg);
10014 if not Is_Entity_Name (Id) then
10015 Error_Pragma_Arg ("entity name required", Arg);
10018 if Etype (Id) = Any_Type then
10022 -- Loop to find matching procedures
10027 and then Scope (E) = Current_Scope
10029 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10032 -- Set flag on any alias as well
10034 if Is_Overloadable (E) and then Present (Alias (E)) then
10035 Set_No_Return (Alias (E));
10041 exit when From_Aspect_Specification (N);
10046 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10057 -- pragma No_Run_Time;
10059 -- Note: this pragma is retained for backwards compatibility. See
10060 -- body of Rtsfind for full details on its handling.
10062 when Pragma_No_Run_Time =>
10064 Check_Valid_Configuration_Pragma;
10065 Check_Arg_Count (0);
10067 No_Run_Time_Mode := True;
10068 Configurable_Run_Time_Mode := True;
10070 -- Set Duration to 32 bits if word size is 32
10072 if Ttypes.System_Word_Size = 32 then
10073 Duration_32_Bits_On_Target := True;
10076 -- Set appropriate restrictions
10078 Set_Restriction (No_Finalization, N);
10079 Set_Restriction (No_Exception_Handlers, N);
10080 Set_Restriction (Max_Tasks, N, 0);
10081 Set_Restriction (No_Tasking, N);
10083 ------------------------
10084 -- No_Strict_Aliasing --
10085 ------------------------
10087 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10089 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10094 Check_At_Most_N_Arguments (1);
10096 if Arg_Count = 0 then
10097 Check_Valid_Configuration_Pragma;
10098 Opt.No_Strict_Aliasing := True;
10101 Check_Optional_Identifier (Arg2, Name_Entity);
10102 Check_Arg_Is_Local_Name (Arg1);
10103 E_Id := Entity (Get_Pragma_Arg (Arg1));
10105 if E_Id = Any_Type then
10107 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10108 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10111 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10113 end No_Strict_Aliasing;
10115 -----------------------
10116 -- Normalize_Scalars --
10117 -----------------------
10119 -- pragma Normalize_Scalars;
10121 when Pragma_Normalize_Scalars =>
10122 Check_Ada_83_Warning;
10123 Check_Arg_Count (0);
10124 Check_Valid_Configuration_Pragma;
10126 -- Normalize_Scalars creates false positives in CodePeer, so
10127 -- ignore this pragma in this mode.
10129 if not CodePeer_Mode then
10130 Normalize_Scalars := True;
10131 Init_Or_Norm_Scalars := True;
10138 -- pragma Obsolescent;
10140 -- pragma Obsolescent (
10141 -- [Message =>] static_string_EXPRESSION
10142 -- [,[Version =>] Ada_05]]);
10144 -- pragma Obsolescent (
10145 -- [Entity =>] NAME
10146 -- [,[Message =>] static_string_EXPRESSION
10147 -- [,[Version =>] Ada_05]] );
10149 when Pragma_Obsolescent => Obsolescent : declare
10153 procedure Set_Obsolescent (E : Entity_Id);
10154 -- Given an entity Ent, mark it as obsolescent if appropriate
10156 ---------------------
10157 -- Set_Obsolescent --
10158 ---------------------
10160 procedure Set_Obsolescent (E : Entity_Id) is
10169 -- Entity name was given
10171 if Present (Ename) then
10173 -- If entity name matches, we are fine. Save entity in
10174 -- pragma argument, for ASIS use.
10176 if Chars (Ename) = Chars (Ent) then
10177 Set_Entity (Ename, Ent);
10178 Generate_Reference (Ent, Ename);
10180 -- If entity name does not match, only possibility is an
10181 -- enumeration literal from an enumeration type declaration.
10183 elsif Ekind (Ent) /= E_Enumeration_Type then
10185 ("pragma % entity name does not match declaration");
10188 Ent := First_Literal (E);
10192 ("pragma % entity name does not match any " &
10193 "enumeration literal");
10195 elsif Chars (Ent) = Chars (Ename) then
10196 Set_Entity (Ename, Ent);
10197 Generate_Reference (Ent, Ename);
10201 Ent := Next_Literal (Ent);
10207 -- Ent points to entity to be marked
10209 if Arg_Count >= 1 then
10211 -- Deal with static string argument
10213 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10214 S := Strval (Get_Pragma_Arg (Arg1));
10216 for J in 1 .. String_Length (S) loop
10217 if not In_Character_Range (Get_String_Char (S, J)) then
10219 ("pragma% argument does not allow wide characters",
10224 Obsolescent_Warnings.Append
10225 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10227 -- Check for Ada_05 parameter
10229 if Arg_Count /= 1 then
10230 Check_Arg_Count (2);
10233 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10236 Check_Arg_Is_Identifier (Argx);
10238 if Chars (Argx) /= Name_Ada_05 then
10239 Error_Msg_Name_2 := Name_Ada_05;
10241 ("only allowed argument for pragma% is %", Argx);
10244 if Ada_Version_Explicit < Ada_2005
10245 or else not Warn_On_Ada_2005_Compatibility
10253 -- Set flag if pragma active
10256 Set_Is_Obsolescent (Ent);
10260 end Set_Obsolescent;
10262 -- Start of processing for pragma Obsolescent
10267 Check_At_Most_N_Arguments (3);
10269 -- See if first argument specifies an entity name
10273 (Chars (Arg1) = Name_Entity
10275 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10277 N_Operator_Symbol))
10279 Ename := Get_Pragma_Arg (Arg1);
10281 -- Eliminate first argument, so we can share processing
10285 Arg_Count := Arg_Count - 1;
10287 -- No Entity name argument given
10293 if Arg_Count >= 1 then
10294 Check_Optional_Identifier (Arg1, Name_Message);
10296 if Arg_Count = 2 then
10297 Check_Optional_Identifier (Arg2, Name_Version);
10301 -- Get immediately preceding declaration
10304 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10308 -- Cases where we do not follow anything other than another pragma
10312 -- First case: library level compilation unit declaration with
10313 -- the pragma immediately following the declaration.
10315 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10317 (Defining_Entity (Unit (Parent (Parent (N)))));
10320 -- Case 2: library unit placement for package
10324 Ent : constant Entity_Id := Find_Lib_Unit_Name;
10326 if Is_Package_Or_Generic_Package (Ent) then
10327 Set_Obsolescent (Ent);
10333 -- Cases where we must follow a declaration
10336 if Nkind (Decl) not in N_Declaration
10337 and then Nkind (Decl) not in N_Later_Decl_Item
10338 and then Nkind (Decl) not in N_Generic_Declaration
10339 and then Nkind (Decl) not in N_Renaming_Declaration
10342 ("pragma% misplaced, "
10343 & "must immediately follow a declaration");
10346 Set_Obsolescent (Defining_Entity (Decl));
10356 -- pragma Optimize (Time | Space | Off);
10358 -- The actual check for optimize is done in Gigi. Note that this
10359 -- pragma does not actually change the optimization setting, it
10360 -- simply checks that it is consistent with the pragma.
10362 when Pragma_Optimize =>
10363 Check_No_Identifiers;
10364 Check_Arg_Count (1);
10365 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10367 ------------------------
10368 -- Optimize_Alignment --
10369 ------------------------
10371 -- pragma Optimize_Alignment (Time | Space | Off);
10373 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10375 Check_No_Identifiers;
10376 Check_Arg_Count (1);
10377 Check_Valid_Configuration_Pragma;
10380 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10384 Opt.Optimize_Alignment := 'T';
10386 Opt.Optimize_Alignment := 'S';
10388 Opt.Optimize_Alignment := 'O';
10390 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10394 -- Set indication that mode is set locally. If we are in fact in a
10395 -- configuration pragma file, this setting is harmless since the
10396 -- switch will get reset anyway at the start of each unit.
10398 Optimize_Alignment_Local := True;
10399 end Optimize_Alignment;
10405 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
10407 when Pragma_Ordered => Ordered : declare
10408 Assoc : constant Node_Id := Arg1;
10414 Check_No_Identifiers;
10415 Check_Arg_Count (1);
10416 Check_Arg_Is_Local_Name (Arg1);
10418 Type_Id := Get_Pragma_Arg (Assoc);
10419 Find_Type (Type_Id);
10420 Typ := Entity (Type_Id);
10422 if Typ = Any_Type then
10425 Typ := Underlying_Type (Typ);
10428 if not Is_Enumeration_Type (Typ) then
10429 Error_Pragma ("pragma% must specify enumeration type");
10432 Check_First_Subtype (Arg1);
10433 Set_Has_Pragma_Ordered (Base_Type (Typ));
10440 -- pragma Pack (first_subtype_LOCAL_NAME);
10442 when Pragma_Pack => Pack : declare
10443 Assoc : constant Node_Id := Arg1;
10447 Ignore : Boolean := False;
10450 Check_No_Identifiers;
10451 Check_Arg_Count (1);
10452 Check_Arg_Is_Local_Name (Arg1);
10454 Type_Id := Get_Pragma_Arg (Assoc);
10455 Find_Type (Type_Id);
10456 Typ := Entity (Type_Id);
10459 or else Rep_Item_Too_Early (Typ, N)
10463 Typ := Underlying_Type (Typ);
10466 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
10467 Error_Pragma ("pragma% must specify array or record type");
10470 Check_First_Subtype (Arg1);
10471 Check_Duplicate_Pragma (Typ);
10475 if Is_Array_Type (Typ) then
10476 Ctyp := Component_Type (Typ);
10478 -- Ignore pack that does nothing
10480 if Known_Static_Esize (Ctyp)
10481 and then Known_Static_RM_Size (Ctyp)
10482 and then Esize (Ctyp) = RM_Size (Ctyp)
10483 and then Addressable (Esize (Ctyp))
10488 -- Process OK pragma Pack. Note that if there is a separate
10489 -- component clause present, the Pack will be cancelled. This
10490 -- processing is in Freeze.
10492 if not Rep_Item_Too_Late (Typ, N) then
10494 -- In the context of static code analysis, we do not need
10495 -- complex front-end expansions related to pragma Pack,
10496 -- so disable handling of pragma Pack in this case.
10498 if CodePeer_Mode then
10501 -- Don't attempt any packing for VM targets. We possibly
10502 -- could deal with some cases of array bit-packing, but we
10503 -- don't bother, since this is not a typical kind of
10504 -- representation in the VM context anyway (and would not
10505 -- for example work nicely with the debugger).
10507 elsif VM_Target /= No_VM then
10508 if not GNAT_Mode then
10510 ("?pragma% ignored in this configuration");
10513 -- Normal case where we do the pack action
10517 Set_Is_Packed (Base_Type (Typ), Sense);
10518 Set_Has_Non_Standard_Rep (Base_Type (Typ), Sense);
10521 Set_Has_Pragma_Pack (Base_Type (Typ), Sense);
10523 -- Complete reset action for Aspect_Cancel case
10525 if Sense = False then
10527 -- Cancel size unless explicitly set
10529 if not Has_Size_Clause (Typ)
10530 and then not Has_Object_Size_Clause (Typ)
10532 Set_Esize (Typ, Uint_0);
10533 Set_RM_Size (Typ, Uint_0);
10534 Set_Alignment (Typ, Uint_0);
10535 Set_Packed_Array_Type (Typ, Empty);
10538 -- Reset component size unless explicitly set
10540 if not Has_Component_Size_Clause (Typ) then
10541 if Known_Static_Esize (Ctyp)
10542 and then Known_Static_RM_Size (Ctyp)
10543 and then Esize (Ctyp) = RM_Size (Ctyp)
10544 and then Addressable (Esize (Ctyp))
10547 (Base_Type (Typ), Esize (Ctyp));
10550 (Base_Type (Typ), Uint_0);
10557 -- For record types, the pack is always effective
10559 else pragma Assert (Is_Record_Type (Typ));
10560 if not Rep_Item_Too_Late (Typ, N) then
10562 -- Ignore pack request with warning in VM mode (skip warning
10563 -- if we are compiling GNAT run time library).
10565 if VM_Target /= No_VM then
10566 if not GNAT_Mode then
10568 ("?pragma% ignored in this configuration");
10571 -- Normal case of pack request active
10574 Set_Is_Packed (Base_Type (Typ), Sense);
10575 Set_Has_Pragma_Pack (Base_Type (Typ), Sense);
10576 Set_Has_Non_Standard_Rep (Base_Type (Typ), Sense);
10578 -- Complete reset action for Aspect_Cancel case
10580 if Sense = False then
10582 -- Cancel size if not explicitly given
10584 if not Has_Size_Clause (Typ)
10585 and then not Has_Object_Size_Clause (Typ)
10587 Set_Esize (Typ, Uint_0);
10588 Set_Alignment (Typ, Uint_0);
10602 -- There is nothing to do here, since we did all the processing for
10603 -- this pragma in Par.Prag (so that it works properly even in syntax
10606 when Pragma_Page =>
10613 -- pragma Passive [(PASSIVE_FORM)];
10615 -- PASSIVE_FORM ::= Semaphore | No
10617 when Pragma_Passive =>
10620 if Nkind (Parent (N)) /= N_Task_Definition then
10621 Error_Pragma ("pragma% must be within task definition");
10624 if Arg_Count /= 0 then
10625 Check_Arg_Count (1);
10626 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
10629 ----------------------------------
10630 -- Preelaborable_Initialization --
10631 ----------------------------------
10633 -- pragma Preelaborable_Initialization (DIRECT_NAME);
10635 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
10640 Check_Arg_Count (1);
10641 Check_No_Identifiers;
10642 Check_Arg_Is_Identifier (Arg1);
10643 Check_Arg_Is_Local_Name (Arg1);
10644 Check_First_Subtype (Arg1);
10645 Ent := Entity (Get_Pragma_Arg (Arg1));
10647 if not Is_Private_Type (Ent)
10648 and then not Is_Protected_Type (Ent)
10651 ("pragma % can only be applied to private or protected type",
10655 -- Give an error if the pragma is applied to a protected type that
10656 -- does not qualify (due to having entries, or due to components
10657 -- that do not qualify).
10659 if Is_Protected_Type (Ent)
10660 and then not Has_Preelaborable_Initialization (Ent)
10663 ("protected type & does not have preelaborable " &
10664 "initialization", Ent);
10666 -- Otherwise mark the type as definitely having preelaborable
10670 Set_Known_To_Have_Preelab_Init (Ent);
10673 if Has_Pragma_Preelab_Init (Ent)
10674 and then Warn_On_Redundant_Constructs
10676 Error_Pragma ("?duplicate pragma%!");
10678 Set_Has_Pragma_Preelab_Init (Ent);
10682 --------------------
10683 -- Persistent_BSS --
10684 --------------------
10686 -- pragma Persistent_BSS [(object_NAME)];
10688 when Pragma_Persistent_BSS => Persistent_BSS : declare
10695 Check_At_Most_N_Arguments (1);
10697 -- Case of application to specific object (one argument)
10699 if Arg_Count = 1 then
10700 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10702 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
10704 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
10707 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
10710 Ent := Entity (Get_Pragma_Arg (Arg1));
10711 Decl := Parent (Ent);
10713 if Rep_Item_Too_Late (Ent, N) then
10717 if Present (Expression (Decl)) then
10719 ("object for pragma% cannot have initialization", Arg1);
10722 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
10724 ("object type for pragma% is not potentially persistent",
10728 Check_Duplicate_Pragma (Ent);
10732 Make_Linker_Section_Pragma
10733 (Ent, Sloc (N), ".persistent.bss");
10734 Insert_After (N, Prag);
10738 -- Case of use as configuration pragma with no arguments
10741 Check_Valid_Configuration_Pragma;
10742 Persistent_BSS_Mode := True;
10744 end Persistent_BSS;
10750 -- pragma Polling (ON | OFF);
10752 when Pragma_Polling =>
10754 Check_Arg_Count (1);
10755 Check_No_Identifiers;
10756 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10757 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
10759 -------------------
10760 -- Postcondition --
10761 -------------------
10763 -- pragma Postcondition ([Check =>] Boolean_Expression
10764 -- [,[Message =>] String_Expression]);
10766 when Pragma_Postcondition => Postcondition : declare
10768 pragma Warnings (Off, In_Body);
10772 Check_At_Least_N_Arguments (1);
10773 Check_At_Most_N_Arguments (2);
10774 Check_Optional_Identifier (Arg1, Name_Check);
10776 -- All we need to do here is call the common check procedure,
10777 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
10779 Check_Precondition_Postcondition (In_Body);
10786 -- pragma Precondition ([Check =>] Boolean_Expression
10787 -- [,[Message =>] String_Expression]);
10789 when Pragma_Precondition => Precondition : declare
10794 Check_At_Least_N_Arguments (1);
10795 Check_At_Most_N_Arguments (2);
10796 Check_Optional_Identifier (Arg1, Name_Check);
10798 Check_Precondition_Postcondition (In_Body);
10800 -- If in spec, nothing more to do. If in body, then we convert the
10801 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
10802 -- this whether or not precondition checks are enabled. That works
10803 -- fine since pragma Check will do this check, and will also
10804 -- analyze the condition itself in the proper context.
10807 if Arg_Count = 2 then
10808 Check_Optional_Identifier (Arg3, Name_Message);
10809 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
10814 Chars => Name_Check,
10815 Pragma_Argument_Associations => New_List (
10816 Make_Pragma_Argument_Association (Loc,
10818 Make_Identifier (Loc,
10819 Chars => Name_Precondition)),
10821 Make_Pragma_Argument_Association (Sloc (Arg1),
10822 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
10824 if Arg_Count = 2 then
10825 Append_To (Pragma_Argument_Associations (N),
10826 Make_Pragma_Argument_Association (Sloc (Arg2),
10827 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
10838 -- pragma Preelaborate [(library_unit_NAME)];
10840 -- Set the flag Is_Preelaborated of program unit name entity
10842 when Pragma_Preelaborate => Preelaborate : declare
10843 Pa : constant Node_Id := Parent (N);
10844 Pk : constant Node_Kind := Nkind (Pa);
10848 Check_Ada_83_Warning;
10849 Check_Valid_Library_Unit_Pragma;
10851 if Nkind (N) = N_Null_Statement then
10855 Ent := Find_Lib_Unit_Name;
10856 Check_Duplicate_Pragma (Ent);
10858 -- This filters out pragmas inside generic parent then
10859 -- show up inside instantiation
10862 and then not (Pk = N_Package_Specification
10863 and then Present (Generic_Parent (Pa)))
10865 if not Debug_Flag_U then
10866 Set_Is_Preelaborated (Ent, Sense);
10867 Set_Suppress_Elaboration_Warnings (Ent, Sense);
10872 ---------------------
10873 -- Preelaborate_05 --
10874 ---------------------
10876 -- pragma Preelaborate_05 [(library_unit_NAME)];
10878 -- This pragma is useable only in GNAT_Mode, where it is used like
10879 -- pragma Preelaborate but it is only effective in Ada 2005 mode
10880 -- (otherwise it is ignored). This is used to implement AI-362 which
10881 -- recategorizes some run-time packages in Ada 2005 mode.
10883 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
10888 Check_Valid_Library_Unit_Pragma;
10890 if not GNAT_Mode then
10891 Error_Pragma ("pragma% only available in GNAT mode");
10894 if Nkind (N) = N_Null_Statement then
10898 -- This is one of the few cases where we need to test the value of
10899 -- Ada_Version_Explicit rather than Ada_Version (which is always
10900 -- set to Ada_2012 in a predefined unit), we need to know the
10901 -- explicit version set to know if this pragma is active.
10903 if Ada_Version_Explicit >= Ada_2005 then
10904 Ent := Find_Lib_Unit_Name;
10905 Set_Is_Preelaborated (Ent);
10906 Set_Suppress_Elaboration_Warnings (Ent);
10908 end Preelaborate_05;
10914 -- pragma Priority (EXPRESSION);
10916 when Pragma_Priority => Priority : declare
10917 P : constant Node_Id := Parent (N);
10921 Check_No_Identifiers;
10922 Check_Arg_Count (1);
10926 if Nkind (P) = N_Subprogram_Body then
10927 Check_In_Main_Program;
10929 Arg := Get_Pragma_Arg (Arg1);
10930 Analyze_And_Resolve (Arg, Standard_Integer);
10934 if not Is_Static_Expression (Arg) then
10935 Flag_Non_Static_Expr
10936 ("main subprogram priority is not static!", Arg);
10939 -- If constraint error, then we already signalled an error
10941 elsif Raises_Constraint_Error (Arg) then
10944 -- Otherwise check in range
10948 Val : constant Uint := Expr_Value (Arg);
10952 or else Val > Expr_Value (Expression
10953 (Parent (RTE (RE_Max_Priority))))
10956 ("main subprogram priority is out of range", Arg1);
10962 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
10964 -- Load an arbitrary entity from System.Tasking to make sure
10965 -- this package is implicitly with'ed, since we need to have
10966 -- the tasking run-time active for the pragma Priority to have
10970 Discard : Entity_Id;
10971 pragma Warnings (Off, Discard);
10973 Discard := RTE (RE_Task_List);
10976 -- Task or Protected, must be of type Integer
10978 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
10979 Arg := Get_Pragma_Arg (Arg1);
10981 -- The expression must be analyzed in the special manner
10982 -- described in "Handling of Default and Per-Object
10983 -- Expressions" in sem.ads.
10985 Preanalyze_Spec_Expression (Arg, Standard_Integer);
10987 if not Is_Static_Expression (Arg) then
10988 Check_Restriction (Static_Priorities, Arg);
10991 -- Anything else is incorrect
10997 if Has_Priority_Pragma (P) then
10998 Error_Pragma ("duplicate pragma% not allowed");
11000 Set_Has_Priority_Pragma (P, True);
11002 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11003 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11004 -- exp_ch9 should use this ???
11009 -----------------------------------
11010 -- Priority_Specific_Dispatching --
11011 -----------------------------------
11013 -- pragma Priority_Specific_Dispatching (
11014 -- policy_IDENTIFIER,
11015 -- first_priority_EXPRESSION,
11016 -- last_priority_EXPRESSION);
11018 when Pragma_Priority_Specific_Dispatching =>
11019 Priority_Specific_Dispatching : declare
11020 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11021 -- This is the entity System.Any_Priority;
11024 Lower_Bound : Node_Id;
11025 Upper_Bound : Node_Id;
11031 Check_Arg_Count (3);
11032 Check_No_Identifiers;
11033 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11034 Check_Valid_Configuration_Pragma;
11035 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11036 DP := Fold_Upper (Name_Buffer (1));
11038 Lower_Bound := Get_Pragma_Arg (Arg2);
11039 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11040 Lower_Val := Expr_Value (Lower_Bound);
11042 Upper_Bound := Get_Pragma_Arg (Arg3);
11043 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11044 Upper_Val := Expr_Value (Upper_Bound);
11046 -- It is not allowed to use Task_Dispatching_Policy and
11047 -- Priority_Specific_Dispatching in the same partition.
11049 if Task_Dispatching_Policy /= ' ' then
11050 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11052 ("pragma% incompatible with Task_Dispatching_Policy#");
11054 -- Check lower bound in range
11056 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11058 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11061 ("first_priority is out of range", Arg2);
11063 -- Check upper bound in range
11065 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11067 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11070 ("last_priority is out of range", Arg3);
11072 -- Check that the priority range is valid
11074 elsif Lower_Val > Upper_Val then
11076 ("last_priority_expression must be greater than" &
11077 " or equal to first_priority_expression");
11079 -- Store the new policy, but always preserve System_Location since
11080 -- we like the error message with the run-time name.
11083 -- Check overlapping in the priority ranges specified in other
11084 -- Priority_Specific_Dispatching pragmas within the same
11085 -- partition. We can only check those we know about!
11088 Specific_Dispatching.First .. Specific_Dispatching.Last
11090 if Specific_Dispatching.Table (J).First_Priority in
11091 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11092 or else Specific_Dispatching.Table (J).Last_Priority in
11093 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11096 Specific_Dispatching.Table (J).Pragma_Loc;
11098 ("priority range overlaps with "
11099 & "Priority_Specific_Dispatching#");
11103 -- The use of Priority_Specific_Dispatching is incompatible
11104 -- with Task_Dispatching_Policy.
11106 if Task_Dispatching_Policy /= ' ' then
11107 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11109 ("Priority_Specific_Dispatching incompatible "
11110 & "with Task_Dispatching_Policy#");
11113 -- The use of Priority_Specific_Dispatching forces ceiling
11116 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11117 Error_Msg_Sloc := Locking_Policy_Sloc;
11119 ("Priority_Specific_Dispatching incompatible "
11120 & "with Locking_Policy#");
11122 -- Set the Ceiling_Locking policy, but preserve System_Location
11123 -- since we like the error message with the run time name.
11126 Locking_Policy := 'C';
11128 if Locking_Policy_Sloc /= System_Location then
11129 Locking_Policy_Sloc := Loc;
11133 -- Add entry in the table
11135 Specific_Dispatching.Append
11136 ((Dispatching_Policy => DP,
11137 First_Priority => UI_To_Int (Lower_Val),
11138 Last_Priority => UI_To_Int (Upper_Val),
11139 Pragma_Loc => Loc));
11141 end Priority_Specific_Dispatching;
11147 -- pragma Profile (profile_IDENTIFIER);
11149 -- profile_IDENTIFIER => Restricted | Ravenscar
11151 when Pragma_Profile =>
11153 Check_Arg_Count (1);
11154 Check_Valid_Configuration_Pragma;
11155 Check_No_Identifiers;
11158 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11160 if Chars (Argx) = Name_Ravenscar then
11161 Set_Ravenscar_Profile (N);
11162 elsif Chars (Argx) = Name_Restricted then
11163 Set_Profile_Restrictions
11164 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11166 Error_Pragma_Arg ("& is not a valid profile", Argx);
11170 ----------------------
11171 -- Profile_Warnings --
11172 ----------------------
11174 -- pragma Profile_Warnings (profile_IDENTIFIER);
11176 -- profile_IDENTIFIER => Restricted | Ravenscar
11178 when Pragma_Profile_Warnings =>
11180 Check_Arg_Count (1);
11181 Check_Valid_Configuration_Pragma;
11182 Check_No_Identifiers;
11185 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11187 if Chars (Argx) = Name_Ravenscar then
11188 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11189 elsif Chars (Argx) = Name_Restricted then
11190 Set_Profile_Restrictions (Restricted, N, Warn => True);
11192 Error_Pragma_Arg ("& is not a valid profile", Argx);
11196 --------------------------
11197 -- Propagate_Exceptions --
11198 --------------------------
11200 -- pragma Propagate_Exceptions;
11202 -- Note: this pragma is obsolete and has no effect
11204 when Pragma_Propagate_Exceptions =>
11206 Check_Arg_Count (0);
11208 if In_Extended_Main_Source_Unit (N) then
11209 Propagate_Exceptions := True;
11216 -- pragma Psect_Object (
11217 -- [Internal =>] LOCAL_NAME,
11218 -- [, [External =>] EXTERNAL_SYMBOL]
11219 -- [, [Size =>] EXTERNAL_SYMBOL]);
11221 when Pragma_Psect_Object | Pragma_Common_Object =>
11222 Psect_Object : declare
11223 Args : Args_List (1 .. 3);
11224 Names : constant Name_List (1 .. 3) := (
11229 Internal : Node_Id renames Args (1);
11230 External : Node_Id renames Args (2);
11231 Size : Node_Id renames Args (3);
11233 Def_Id : Entity_Id;
11235 procedure Check_Too_Long (Arg : Node_Id);
11236 -- Posts message if the argument is an identifier with more
11237 -- than 31 characters, or a string literal with more than
11238 -- 31 characters, and we are operating under VMS
11240 --------------------
11241 -- Check_Too_Long --
11242 --------------------
11244 procedure Check_Too_Long (Arg : Node_Id) is
11245 X : constant Node_Id := Original_Node (Arg);
11248 if not Nkind_In (X, N_String_Literal, N_Identifier) then
11250 ("inappropriate argument for pragma %", Arg);
11253 if OpenVMS_On_Target then
11254 if (Nkind (X) = N_String_Literal
11255 and then String_Length (Strval (X)) > 31)
11257 (Nkind (X) = N_Identifier
11258 and then Length_Of_Name (Chars (X)) > 31)
11261 ("argument for pragma % is longer than 31 characters",
11265 end Check_Too_Long;
11267 -- Start of processing for Common_Object/Psect_Object
11271 Gather_Associations (Names, Args);
11272 Process_Extended_Import_Export_Internal_Arg (Internal);
11274 Def_Id := Entity (Internal);
11276 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11278 ("pragma% must designate an object", Internal);
11281 Check_Too_Long (Internal);
11283 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11285 ("cannot use pragma% for imported/exported object",
11289 if Is_Concurrent_Type (Etype (Internal)) then
11291 ("cannot specify pragma % for task/protected object",
11295 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11297 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11299 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11302 if Ekind (Def_Id) = E_Constant then
11304 ("cannot specify pragma % for a constant", Internal);
11307 if Is_Record_Type (Etype (Internal)) then
11313 Ent := First_Entity (Etype (Internal));
11314 while Present (Ent) loop
11315 Decl := Declaration_Node (Ent);
11317 if Ekind (Ent) = E_Component
11318 and then Nkind (Decl) = N_Component_Declaration
11319 and then Present (Expression (Decl))
11320 and then Warn_On_Export_Import
11323 ("?object for pragma % has defaults", Internal);
11333 if Present (Size) then
11334 Check_Too_Long (Size);
11337 if Present (External) then
11338 Check_Arg_Is_External_Name (External);
11339 Check_Too_Long (External);
11342 -- If all error tests pass, link pragma on to the rep item chain
11344 Record_Rep_Item (Def_Id, N);
11351 -- pragma Pure [(library_unit_NAME)];
11353 when Pragma_Pure => Pure : declare
11357 Check_Ada_83_Warning;
11358 Check_Valid_Library_Unit_Pragma;
11360 if Nkind (N) = N_Null_Statement then
11364 Ent := Find_Lib_Unit_Name;
11366 Set_Has_Pragma_Pure (Ent);
11367 Set_Suppress_Elaboration_Warnings (Ent);
11374 -- pragma Pure_05 [(library_unit_NAME)];
11376 -- This pragma is useable only in GNAT_Mode, where it is used like
11377 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11378 -- it is ignored). It may be used after a pragma Preelaborate, in
11379 -- which case it overrides the effect of the pragma Preelaborate.
11380 -- This is used to implement AI-362 which recategorizes some run-time
11381 -- packages in Ada 2005 mode.
11383 when Pragma_Pure_05 => Pure_05 : declare
11388 Check_Valid_Library_Unit_Pragma;
11390 if not GNAT_Mode then
11391 Error_Pragma ("pragma% only available in GNAT mode");
11394 if Nkind (N) = N_Null_Statement then
11398 -- This is one of the few cases where we need to test the value of
11399 -- Ada_Version_Explicit rather than Ada_Version (which is always
11400 -- set to Ada_2012 in a predefined unit), we need to know the
11401 -- explicit version set to know if this pragma is active.
11403 if Ada_Version_Explicit >= Ada_2005 then
11404 Ent := Find_Lib_Unit_Name;
11405 Set_Is_Preelaborated (Ent, False);
11407 Set_Suppress_Elaboration_Warnings (Ent);
11411 -------------------
11412 -- Pure_Function --
11413 -------------------
11415 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
11417 when Pragma_Pure_Function => Pure_Function : declare
11420 Def_Id : Entity_Id;
11421 Effective : Boolean := False;
11425 Check_Arg_Count (1);
11426 Check_Optional_Identifier (Arg1, Name_Entity);
11427 Check_Arg_Is_Local_Name (Arg1);
11428 E_Id := Get_Pragma_Arg (Arg1);
11430 if Error_Posted (E_Id) then
11434 -- Loop through homonyms (overloadings) of referenced entity
11436 E := Entity (E_Id);
11438 if Present (E) then
11440 Def_Id := Get_Base_Subprogram (E);
11442 if not Ekind_In (Def_Id, E_Function,
11443 E_Generic_Function,
11447 ("pragma% requires a function name", Arg1);
11450 Set_Is_Pure (Def_Id, Sense);
11452 if not Has_Pragma_Pure_Function (Def_Id) then
11453 Set_Has_Pragma_Pure_Function (Def_Id, Sense);
11454 Effective := Sense;
11457 exit when From_Aspect_Specification (N);
11459 exit when No (E) or else Scope (E) /= Current_Scope;
11462 if Sense and then not Effective
11463 and then Warn_On_Redundant_Constructs
11466 ("pragma Pure_Function on& is redundant?",
11472 --------------------
11473 -- Queuing_Policy --
11474 --------------------
11476 -- pragma Queuing_Policy (policy_IDENTIFIER);
11478 when Pragma_Queuing_Policy => declare
11482 Check_Ada_83_Warning;
11483 Check_Arg_Count (1);
11484 Check_No_Identifiers;
11485 Check_Arg_Is_Queuing_Policy (Arg1);
11486 Check_Valid_Configuration_Pragma;
11487 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11488 QP := Fold_Upper (Name_Buffer (1));
11490 if Queuing_Policy /= ' '
11491 and then Queuing_Policy /= QP
11493 Error_Msg_Sloc := Queuing_Policy_Sloc;
11494 Error_Pragma ("queuing policy incompatible with policy#");
11496 -- Set new policy, but always preserve System_Location since we
11497 -- like the error message with the run time name.
11500 Queuing_Policy := QP;
11502 if Queuing_Policy_Sloc /= System_Location then
11503 Queuing_Policy_Sloc := Loc;
11508 -----------------------
11509 -- Relative_Deadline --
11510 -----------------------
11512 -- pragma Relative_Deadline (time_span_EXPRESSION);
11514 when Pragma_Relative_Deadline => Relative_Deadline : declare
11515 P : constant Node_Id := Parent (N);
11520 Check_No_Identifiers;
11521 Check_Arg_Count (1);
11523 Arg := Get_Pragma_Arg (Arg1);
11525 -- The expression must be analyzed in the special manner described
11526 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
11528 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
11532 if Nkind (P) = N_Subprogram_Body then
11533 Check_In_Main_Program;
11537 elsif Nkind (P) = N_Task_Definition then
11540 -- Anything else is incorrect
11546 if Has_Relative_Deadline_Pragma (P) then
11547 Error_Pragma ("duplicate pragma% not allowed");
11549 Set_Has_Relative_Deadline_Pragma (P, True);
11551 if Nkind (P) = N_Task_Definition then
11552 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11555 end Relative_Deadline;
11557 ---------------------------
11558 -- Remote_Call_Interface --
11559 ---------------------------
11561 -- pragma Remote_Call_Interface [(library_unit_NAME)];
11563 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
11564 Cunit_Node : Node_Id;
11565 Cunit_Ent : Entity_Id;
11569 Check_Ada_83_Warning;
11570 Check_Valid_Library_Unit_Pragma;
11572 if Nkind (N) = N_Null_Statement then
11576 Cunit_Node := Cunit (Current_Sem_Unit);
11577 K := Nkind (Unit (Cunit_Node));
11578 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
11580 if K = N_Package_Declaration
11581 or else K = N_Generic_Package_Declaration
11582 or else K = N_Subprogram_Declaration
11583 or else K = N_Generic_Subprogram_Declaration
11584 or else (K = N_Subprogram_Body
11585 and then Acts_As_Spec (Unit (Cunit_Node)))
11590 "pragma% must apply to package or subprogram declaration");
11593 Set_Is_Remote_Call_Interface (Cunit_Ent);
11594 end Remote_Call_Interface;
11600 -- pragma Remote_Types [(library_unit_NAME)];
11602 when Pragma_Remote_Types => Remote_Types : declare
11603 Cunit_Node : Node_Id;
11604 Cunit_Ent : Entity_Id;
11607 Check_Ada_83_Warning;
11608 Check_Valid_Library_Unit_Pragma;
11610 if Nkind (N) = N_Null_Statement then
11614 Cunit_Node := Cunit (Current_Sem_Unit);
11615 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
11617 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
11618 N_Generic_Package_Declaration)
11621 ("pragma% can only apply to a package declaration");
11624 Set_Is_Remote_Types (Cunit_Ent);
11631 -- pragma Ravenscar;
11633 when Pragma_Ravenscar =>
11635 Check_Arg_Count (0);
11636 Check_Valid_Configuration_Pragma;
11637 Set_Ravenscar_Profile (N);
11639 if Warn_On_Obsolescent_Feature then
11640 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
11641 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
11644 -------------------------
11645 -- Restricted_Run_Time --
11646 -------------------------
11648 -- pragma Restricted_Run_Time;
11650 when Pragma_Restricted_Run_Time =>
11652 Check_Arg_Count (0);
11653 Check_Valid_Configuration_Pragma;
11654 Set_Profile_Restrictions
11655 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11657 if Warn_On_Obsolescent_Feature then
11659 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
11660 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
11667 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
11670 -- restriction_IDENTIFIER
11671 -- | restriction_parameter_IDENTIFIER => EXPRESSION
11673 when Pragma_Restrictions =>
11674 Process_Restrictions_Or_Restriction_Warnings
11675 (Warn => Treat_Restrictions_As_Warnings);
11677 --------------------------
11678 -- Restriction_Warnings --
11679 --------------------------
11681 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
11684 -- restriction_IDENTIFIER
11685 -- | restriction_parameter_IDENTIFIER => EXPRESSION
11687 when Pragma_Restriction_Warnings =>
11689 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
11695 -- pragma Reviewable;
11697 when Pragma_Reviewable =>
11698 Check_Ada_83_Warning;
11699 Check_Arg_Count (0);
11701 -- Call dummy debugging function rv. This is done to assist front
11702 -- end debugging. By placing a Reviewable pragma in the source
11703 -- program, a breakpoint on rv catches this place in the source,
11704 -- allowing convenient stepping to the point of interest.
11708 --------------------------
11709 -- Short_Circuit_And_Or --
11710 --------------------------
11712 when Pragma_Short_Circuit_And_Or =>
11714 Check_Arg_Count (0);
11715 Check_Valid_Configuration_Pragma;
11716 Short_Circuit_And_Or := True;
11718 -------------------
11719 -- Share_Generic --
11720 -------------------
11722 -- pragma Share_Generic (NAME {, NAME});
11724 when Pragma_Share_Generic =>
11726 Process_Generic_List;
11732 -- pragma Shared (LOCAL_NAME);
11734 when Pragma_Shared =>
11736 Process_Atomic_Shared_Volatile;
11738 --------------------
11739 -- Shared_Passive --
11740 --------------------
11742 -- pragma Shared_Passive [(library_unit_NAME)];
11744 -- Set the flag Is_Shared_Passive of program unit name entity
11746 when Pragma_Shared_Passive => Shared_Passive : declare
11747 Cunit_Node : Node_Id;
11748 Cunit_Ent : Entity_Id;
11751 Check_Ada_83_Warning;
11752 Check_Valid_Library_Unit_Pragma;
11754 if Nkind (N) = N_Null_Statement then
11758 Cunit_Node := Cunit (Current_Sem_Unit);
11759 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
11761 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
11762 N_Generic_Package_Declaration)
11765 ("pragma% can only apply to a package declaration");
11768 Set_Is_Shared_Passive (Cunit_Ent);
11769 end Shared_Passive;
11771 -----------------------
11772 -- Short_Descriptors --
11773 -----------------------
11775 -- pragma Short_Descriptors;
11777 when Pragma_Short_Descriptors =>
11779 Check_Arg_Count (0);
11780 Check_Valid_Configuration_Pragma;
11781 Short_Descriptors := True;
11783 ----------------------
11784 -- Source_File_Name --
11785 ----------------------
11787 -- There are five forms for this pragma:
11789 -- pragma Source_File_Name (
11790 -- [UNIT_NAME =>] unit_NAME,
11791 -- BODY_FILE_NAME => STRING_LITERAL
11792 -- [, [INDEX =>] INTEGER_LITERAL]);
11794 -- pragma Source_File_Name (
11795 -- [UNIT_NAME =>] unit_NAME,
11796 -- SPEC_FILE_NAME => STRING_LITERAL
11797 -- [, [INDEX =>] INTEGER_LITERAL]);
11799 -- pragma Source_File_Name (
11800 -- BODY_FILE_NAME => STRING_LITERAL
11801 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11802 -- [, CASING => CASING_SPEC]);
11804 -- pragma Source_File_Name (
11805 -- SPEC_FILE_NAME => STRING_LITERAL
11806 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11807 -- [, CASING => CASING_SPEC]);
11809 -- pragma Source_File_Name (
11810 -- SUBUNIT_FILE_NAME => STRING_LITERAL
11811 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11812 -- [, CASING => CASING_SPEC]);
11814 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
11816 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
11817 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
11818 -- only be used when no project file is used, while SFNP can only be
11819 -- used when a project file is used.
11821 -- No processing here. Processing was completed during parsing, since
11822 -- we need to have file names set as early as possible. Units are
11823 -- loaded well before semantic processing starts.
11825 -- The only processing we defer to this point is the check for
11826 -- correct placement.
11828 when Pragma_Source_File_Name =>
11830 Check_Valid_Configuration_Pragma;
11832 ------------------------------
11833 -- Source_File_Name_Project --
11834 ------------------------------
11836 -- See Source_File_Name for syntax
11838 -- No processing here. Processing was completed during parsing, since
11839 -- we need to have file names set as early as possible. Units are
11840 -- loaded well before semantic processing starts.
11842 -- The only processing we defer to this point is the check for
11843 -- correct placement.
11845 when Pragma_Source_File_Name_Project =>
11847 Check_Valid_Configuration_Pragma;
11849 -- Check that a pragma Source_File_Name_Project is used only in a
11850 -- configuration pragmas file.
11852 -- Pragmas Source_File_Name_Project should only be generated by
11853 -- the Project Manager in configuration pragmas files.
11855 -- This is really an ugly test. It seems to depend on some
11856 -- accidental and undocumented property. At the very least it
11857 -- needs to be documented, but it would be better to have a
11858 -- clean way of testing if we are in a configuration file???
11860 if Present (Parent (N)) then
11862 ("pragma% can only appear in a configuration pragmas file");
11865 ----------------------
11866 -- Source_Reference --
11867 ----------------------
11869 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
11871 -- Nothing to do, all processing completed in Par.Prag, since we need
11872 -- the information for possible parser messages that are output.
11874 when Pragma_Source_Reference =>
11877 --------------------------------
11878 -- Static_Elaboration_Desired --
11879 --------------------------------
11881 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
11883 when Pragma_Static_Elaboration_Desired =>
11885 Check_At_Most_N_Arguments (1);
11887 if Is_Compilation_Unit (Current_Scope)
11888 and then Ekind (Current_Scope) = E_Package
11890 Set_Static_Elaboration_Desired (Current_Scope, True);
11892 Error_Pragma ("pragma% must apply to a library-level package");
11899 -- pragma Storage_Size (EXPRESSION);
11901 when Pragma_Storage_Size => Storage_Size : declare
11902 P : constant Node_Id := Parent (N);
11906 Check_No_Identifiers;
11907 Check_Arg_Count (1);
11909 -- The expression must be analyzed in the special manner described
11910 -- in "Handling of Default Expressions" in sem.ads.
11912 Arg := Get_Pragma_Arg (Arg1);
11913 Preanalyze_Spec_Expression (Arg, Any_Integer);
11915 if not Is_Static_Expression (Arg) then
11916 Check_Restriction (Static_Storage_Size, Arg);
11919 if Nkind (P) /= N_Task_Definition then
11924 if Has_Storage_Size_Pragma (P) then
11925 Error_Pragma ("duplicate pragma% not allowed");
11927 Set_Has_Storage_Size_Pragma (P, True);
11930 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11931 -- ??? exp_ch9 should use this!
11939 -- pragma Storage_Unit (NUMERIC_LITERAL);
11941 -- Only permitted argument is System'Storage_Unit value
11943 when Pragma_Storage_Unit =>
11944 Check_No_Identifiers;
11945 Check_Arg_Count (1);
11946 Check_Arg_Is_Integer_Literal (Arg1);
11948 if Intval (Get_Pragma_Arg (Arg1)) /=
11949 UI_From_Int (Ttypes.System_Storage_Unit)
11951 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
11953 ("the only allowed argument for pragma% is ^", Arg1);
11956 --------------------
11957 -- Stream_Convert --
11958 --------------------
11960 -- pragma Stream_Convert (
11961 -- [Entity =>] type_LOCAL_NAME,
11962 -- [Read =>] function_NAME,
11963 -- [Write =>] function NAME);
11965 when Pragma_Stream_Convert => Stream_Convert : declare
11967 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
11968 -- Check that the given argument is the name of a local function
11969 -- of one argument that is not overloaded earlier in the current
11970 -- local scope. A check is also made that the argument is a
11971 -- function with one parameter.
11973 --------------------------------------
11974 -- Check_OK_Stream_Convert_Function --
11975 --------------------------------------
11977 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
11981 Check_Arg_Is_Local_Name (Arg);
11982 Ent := Entity (Get_Pragma_Arg (Arg));
11984 if Has_Homonym (Ent) then
11986 ("argument for pragma% may not be overloaded", Arg);
11989 if Ekind (Ent) /= E_Function
11990 or else No (First_Formal (Ent))
11991 or else Present (Next_Formal (First_Formal (Ent)))
11994 ("argument for pragma% must be" &
11995 " function of one argument", Arg);
11997 end Check_OK_Stream_Convert_Function;
11999 -- Start of processing for Stream_Convert
12003 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12004 Check_Arg_Count (3);
12005 Check_Optional_Identifier (Arg1, Name_Entity);
12006 Check_Optional_Identifier (Arg2, Name_Read);
12007 Check_Optional_Identifier (Arg3, Name_Write);
12008 Check_Arg_Is_Local_Name (Arg1);
12009 Check_OK_Stream_Convert_Function (Arg2);
12010 Check_OK_Stream_Convert_Function (Arg3);
12013 Typ : constant Entity_Id :=
12014 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12015 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12016 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12019 Check_First_Subtype (Arg1);
12021 -- Check for too early or too late. Note that we don't enforce
12022 -- the rule about primitive operations in this case, since, as
12023 -- is the case for explicit stream attributes themselves, these
12024 -- restrictions are not appropriate. Note that the chaining of
12025 -- the pragma by Rep_Item_Too_Late is actually the critical
12026 -- processing done for this pragma.
12028 if Rep_Item_Too_Early (Typ, N)
12030 Rep_Item_Too_Late (Typ, N, FOnly => True)
12035 -- Return if previous error
12037 if Etype (Typ) = Any_Type
12039 Etype (Read) = Any_Type
12041 Etype (Write) = Any_Type
12048 if Underlying_Type (Etype (Read)) /= Typ then
12050 ("incorrect return type for function&", Arg2);
12053 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12055 ("incorrect parameter type for function&", Arg3);
12058 if Underlying_Type (Etype (First_Formal (Read))) /=
12059 Underlying_Type (Etype (Write))
12062 ("result type of & does not match Read parameter type",
12066 end Stream_Convert;
12068 -------------------------
12069 -- Style_Checks (GNAT) --
12070 -------------------------
12072 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12074 -- This is processed by the parser since some of the style checks
12075 -- take place during source scanning and parsing. This means that
12076 -- we don't need to issue error messages here.
12078 when Pragma_Style_Checks => Style_Checks : declare
12079 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12085 Check_No_Identifiers;
12087 -- Two argument form
12089 if Arg_Count = 2 then
12090 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12097 E_Id := Get_Pragma_Arg (Arg2);
12100 if not Is_Entity_Name (E_Id) then
12102 ("second argument of pragma% must be entity name",
12106 E := Entity (E_Id);
12112 Set_Suppress_Style_Checks (E,
12113 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12114 exit when No (Homonym (E));
12120 -- One argument form
12123 Check_Arg_Count (1);
12125 if Nkind (A) = N_String_Literal then
12129 Slen : constant Natural := Natural (String_Length (S));
12130 Options : String (1 .. Slen);
12136 C := Get_String_Char (S, Int (J));
12137 exit when not In_Character_Range (C);
12138 Options (J) := Get_Character (C);
12140 -- If at end of string, set options. As per discussion
12141 -- above, no need to check for errors, since we issued
12142 -- them in the parser.
12145 Set_Style_Check_Options (Options);
12153 elsif Nkind (A) = N_Identifier then
12154 if Chars (A) = Name_All_Checks then
12156 Set_GNAT_Style_Check_Options;
12158 Set_Default_Style_Check_Options;
12161 elsif Chars (A) = Name_On then
12162 Style_Check := True;
12164 elsif Chars (A) = Name_Off then
12165 Style_Check := False;
12175 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12177 when Pragma_Subtitle =>
12179 Check_Arg_Count (1);
12180 Check_Optional_Identifier (Arg1, Name_Subtitle);
12181 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12188 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12190 when Pragma_Suppress =>
12191 Process_Suppress_Unsuppress (True);
12197 -- pragma Suppress_All;
12199 -- The only check made here is that the pragma appears in the proper
12200 -- place, i.e. following a compilation unit. If indeed it appears in
12201 -- this context, then the parser has already inserted an equivalent
12202 -- pragma Suppress (All_Checks) to get the required effect.
12204 when Pragma_Suppress_All =>
12206 Check_Arg_Count (0);
12208 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
12209 or else not Is_List_Member (N)
12210 or else List_Containing (N) /= Pragmas_After (Parent (N))
12212 if not CodePeer_Mode then
12214 ("misplaced pragma%, must follow compilation unit");
12218 -------------------------
12219 -- Suppress_Debug_Info --
12220 -------------------------
12222 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12224 when Pragma_Suppress_Debug_Info =>
12226 Check_Arg_Count (1);
12227 Check_Optional_Identifier (Arg1, Name_Entity);
12228 Check_Arg_Is_Local_Name (Arg1);
12229 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)), Sense);
12231 ----------------------------------
12232 -- Suppress_Exception_Locations --
12233 ----------------------------------
12235 -- pragma Suppress_Exception_Locations;
12237 when Pragma_Suppress_Exception_Locations =>
12239 Check_Arg_Count (0);
12240 Check_Valid_Configuration_Pragma;
12241 Exception_Locations_Suppressed := True;
12243 -----------------------------
12244 -- Suppress_Initialization --
12245 -----------------------------
12247 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12249 when Pragma_Suppress_Initialization => Suppress_Init : declare
12255 Check_Arg_Count (1);
12256 Check_Optional_Identifier (Arg1, Name_Entity);
12257 Check_Arg_Is_Local_Name (Arg1);
12259 E_Id := Get_Pragma_Arg (Arg1);
12261 if Etype (E_Id) = Any_Type then
12265 E := Entity (E_Id);
12267 if Is_Type (E) then
12268 if Is_Incomplete_Or_Private_Type (E) then
12269 if No (Full_View (Base_Type (E))) then
12271 ("argument of pragma% cannot be an incomplete type",
12274 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
12277 Set_Suppress_Init_Proc (Base_Type (E));
12282 ("pragma% requires argument that is a type name", Arg1);
12290 -- pragma System_Name (DIRECT_NAME);
12292 -- Syntax check: one argument, which must be the identifier GNAT or
12293 -- the identifier GCC, no other identifiers are acceptable.
12295 when Pragma_System_Name =>
12297 Check_No_Identifiers;
12298 Check_Arg_Count (1);
12299 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12301 -----------------------------
12302 -- Task_Dispatching_Policy --
12303 -----------------------------
12305 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12307 when Pragma_Task_Dispatching_Policy => declare
12311 Check_Ada_83_Warning;
12312 Check_Arg_Count (1);
12313 Check_No_Identifiers;
12314 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12315 Check_Valid_Configuration_Pragma;
12316 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12317 DP := Fold_Upper (Name_Buffer (1));
12319 if Task_Dispatching_Policy /= ' '
12320 and then Task_Dispatching_Policy /= DP
12322 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12324 ("task dispatching policy incompatible with policy#");
12326 -- Set new policy, but always preserve System_Location since we
12327 -- like the error message with the run time name.
12330 Task_Dispatching_Policy := DP;
12332 if Task_Dispatching_Policy_Sloc /= System_Location then
12333 Task_Dispatching_Policy_Sloc := Loc;
12342 -- pragma Task_Info (EXPRESSION);
12344 when Pragma_Task_Info => Task_Info : declare
12345 P : constant Node_Id := Parent (N);
12350 if Nkind (P) /= N_Task_Definition then
12351 Error_Pragma ("pragma% must appear in task definition");
12354 Check_No_Identifiers;
12355 Check_Arg_Count (1);
12357 Analyze_And_Resolve
12358 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12360 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12364 if Has_Task_Info_Pragma (P) then
12365 Error_Pragma ("duplicate pragma% not allowed");
12367 Set_Has_Task_Info_Pragma (P, True);
12375 -- pragma Task_Name (string_EXPRESSION);
12377 when Pragma_Task_Name => Task_Name : declare
12378 P : constant Node_Id := Parent (N);
12382 Check_No_Identifiers;
12383 Check_Arg_Count (1);
12385 Arg := Get_Pragma_Arg (Arg1);
12387 -- The expression is used in the call to Create_Task, and must be
12388 -- expanded there, not in the context of the current spec. It must
12389 -- however be analyzed to capture global references, in case it
12390 -- appears in a generic context.
12392 Preanalyze_And_Resolve (Arg, Standard_String);
12394 if Nkind (P) /= N_Task_Definition then
12398 if Has_Task_Name_Pragma (P) then
12399 Error_Pragma ("duplicate pragma% not allowed");
12401 Set_Has_Task_Name_Pragma (P, True);
12402 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12410 -- pragma Task_Storage (
12411 -- [Task_Type =>] LOCAL_NAME,
12412 -- [Top_Guard =>] static_integer_EXPRESSION);
12414 when Pragma_Task_Storage => Task_Storage : declare
12415 Args : Args_List (1 .. 2);
12416 Names : constant Name_List (1 .. 2) := (
12420 Task_Type : Node_Id renames Args (1);
12421 Top_Guard : Node_Id renames Args (2);
12427 Gather_Associations (Names, Args);
12429 if No (Task_Type) then
12431 ("missing task_type argument for pragma%");
12434 Check_Arg_Is_Local_Name (Task_Type);
12436 Ent := Entity (Task_Type);
12438 if not Is_Task_Type (Ent) then
12440 ("argument for pragma% must be task type", Task_Type);
12443 if No (Top_Guard) then
12445 ("pragma% takes two arguments", Task_Type);
12447 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
12450 Check_First_Subtype (Task_Type);
12452 if Rep_Item_Too_Late (Ent, N) then
12457 --------------------------
12458 -- Thread_Local_Storage --
12459 --------------------------
12461 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
12463 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
12469 Check_Arg_Count (1);
12470 Check_Optional_Identifier (Arg1, Name_Entity);
12471 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12473 Id := Get_Pragma_Arg (Arg1);
12476 if not Is_Entity_Name (Id)
12477 or else Ekind (Entity (Id)) /= E_Variable
12479 Error_Pragma_Arg ("local variable name required", Arg1);
12484 if Rep_Item_Too_Early (E, N)
12485 or else Rep_Item_Too_Late (E, N)
12490 Set_Has_Pragma_Thread_Local_Storage (E);
12491 Set_Has_Gigi_Rep_Item (E);
12492 end Thread_Local_Storage;
12498 -- pragma Time_Slice (static_duration_EXPRESSION);
12500 when Pragma_Time_Slice => Time_Slice : declare
12506 Check_Arg_Count (1);
12507 Check_No_Identifiers;
12508 Check_In_Main_Program;
12509 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
12511 if not Error_Posted (Arg1) then
12513 while Present (Nod) loop
12514 if Nkind (Nod) = N_Pragma
12515 and then Pragma_Name (Nod) = Name_Time_Slice
12517 Error_Msg_Name_1 := Pname;
12518 Error_Msg_N ("duplicate pragma% not permitted", Nod);
12525 -- Process only if in main unit
12527 if Get_Source_Unit (Loc) = Main_Unit then
12528 Opt.Time_Slice_Set := True;
12529 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
12531 if Val <= Ureal_0 then
12532 Opt.Time_Slice_Value := 0;
12534 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
12535 Opt.Time_Slice_Value := 1_000_000_000;
12538 Opt.Time_Slice_Value :=
12539 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
12548 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
12550 -- TITLING_OPTION ::=
12551 -- [Title =>] STRING_LITERAL
12552 -- | [Subtitle =>] STRING_LITERAL
12554 when Pragma_Title => Title : declare
12555 Args : Args_List (1 .. 2);
12556 Names : constant Name_List (1 .. 2) := (
12562 Gather_Associations (Names, Args);
12565 for J in 1 .. 2 loop
12566 if Present (Args (J)) then
12567 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
12572 ---------------------
12573 -- Unchecked_Union --
12574 ---------------------
12576 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
12578 when Pragma_Unchecked_Union => Unchecked_Union : declare
12579 Assoc : constant Node_Id := Arg1;
12580 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
12591 Check_No_Identifiers;
12592 Check_Arg_Count (1);
12593 Check_Arg_Is_Local_Name (Arg1);
12595 Find_Type (Type_Id);
12596 Typ := Entity (Type_Id);
12599 or else Rep_Item_Too_Early (Typ, N)
12603 Typ := Underlying_Type (Typ);
12606 if Rep_Item_Too_Late (Typ, N) then
12610 Check_First_Subtype (Arg1);
12612 -- Note remaining cases are references to a type in the current
12613 -- declarative part. If we find an error, we post the error on
12614 -- the relevant type declaration at an appropriate point.
12616 if not Is_Record_Type (Typ) then
12617 Error_Msg_N ("Unchecked_Union must be record type", Typ);
12620 elsif Is_Tagged_Type (Typ) then
12621 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
12624 elsif Is_Limited_Type (Typ) then
12626 ("Unchecked_Union must not be limited record type", Typ);
12627 Explain_Limited_Type (Typ, Typ);
12631 if not Has_Discriminants (Typ) then
12633 ("Unchecked_Union must have one discriminant", Typ);
12637 Discr := First_Discriminant (Typ);
12638 while Present (Discr) loop
12639 if No (Discriminant_Default_Value (Discr)) then
12641 ("Unchecked_Union discriminant must have default value",
12645 Next_Discriminant (Discr);
12648 Tdef := Type_Definition (Declaration_Node (Typ));
12649 Clist := Component_List (Tdef);
12651 Comp := First (Component_Items (Clist));
12652 while Present (Comp) loop
12653 Check_Component (Comp, Typ);
12657 if No (Clist) or else No (Variant_Part (Clist)) then
12659 ("Unchecked_Union must have variant part",
12664 Vpart := Variant_Part (Clist);
12666 Variant := First (Variants (Vpart));
12667 while Present (Variant) loop
12668 Check_Variant (Variant, Typ);
12673 Set_Is_Unchecked_Union (Typ, Sense);
12676 Set_Convention (Typ, Convention_C);
12679 Set_Has_Unchecked_Union (Base_Type (Typ), Sense);
12680 Set_Is_Unchecked_Union (Base_Type (Typ), Sense);
12681 end Unchecked_Union;
12683 ------------------------
12684 -- Unimplemented_Unit --
12685 ------------------------
12687 -- pragma Unimplemented_Unit;
12689 -- Note: this only gives an error if we are generating code, or if
12690 -- we are in a generic library unit (where the pragma appears in the
12691 -- body, not in the spec).
12693 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
12694 Cunitent : constant Entity_Id :=
12695 Cunit_Entity (Get_Source_Unit (Loc));
12696 Ent_Kind : constant Entity_Kind :=
12701 Check_Arg_Count (0);
12703 if Operating_Mode = Generate_Code
12704 or else Ent_Kind = E_Generic_Function
12705 or else Ent_Kind = E_Generic_Procedure
12706 or else Ent_Kind = E_Generic_Package
12708 Get_Name_String (Chars (Cunitent));
12709 Set_Casing (Mixed_Case);
12710 Write_Str (Name_Buffer (1 .. Name_Len));
12711 Write_Str (" is not supported in this configuration");
12713 raise Unrecoverable_Error;
12715 end Unimplemented_Unit;
12717 ------------------------
12718 -- Universal_Aliasing --
12719 ------------------------
12721 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
12723 when Pragma_Universal_Aliasing => Universal_Alias : declare
12728 Check_Arg_Count (1);
12729 Check_Optional_Identifier (Arg2, Name_Entity);
12730 Check_Arg_Is_Local_Name (Arg1);
12731 E_Id := Entity (Get_Pragma_Arg (Arg1));
12733 if E_Id = Any_Type then
12735 elsif No (E_Id) or else not Is_Type (E_Id) then
12736 Error_Pragma_Arg ("pragma% requires type", Arg1);
12739 Set_Universal_Aliasing (Implementation_Base_Type (E_Id), Sense);
12740 end Universal_Alias;
12742 --------------------
12743 -- Universal_Data --
12744 --------------------
12746 -- pragma Universal_Data [(library_unit_NAME)];
12748 when Pragma_Universal_Data =>
12751 -- If this is a configuration pragma, then set the universal
12752 -- addressing option, otherwise confirm that the pragma satisfies
12753 -- the requirements of library unit pragma placement and leave it
12754 -- to the GNAAMP back end to detect the pragma (avoids transitive
12755 -- setting of the option due to withed units).
12757 if Is_Configuration_Pragma then
12758 Universal_Addressing_On_AAMP := True;
12760 Check_Valid_Library_Unit_Pragma;
12763 if not AAMP_On_Target then
12764 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
12771 -- pragma Unmodified (local_Name {, local_Name});
12773 when Pragma_Unmodified => Unmodified : declare
12774 Arg_Node : Node_Id;
12775 Arg_Expr : Node_Id;
12776 Arg_Ent : Entity_Id;
12780 Check_At_Least_N_Arguments (1);
12782 -- Loop through arguments
12785 while Present (Arg_Node) loop
12786 Check_No_Identifier (Arg_Node);
12788 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
12789 -- in fact generate reference, so that the entity will have a
12790 -- reference, which will inhibit any warnings about it not
12791 -- being referenced, and also properly show up in the ali file
12792 -- as a reference. But this reference is recorded before the
12793 -- Has_Pragma_Unreferenced flag is set, so that no warning is
12794 -- generated for this reference.
12796 Check_Arg_Is_Local_Name (Arg_Node);
12797 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12799 if Is_Entity_Name (Arg_Expr) then
12800 Arg_Ent := Entity (Arg_Expr);
12802 if not Is_Assignable (Arg_Ent) then
12804 ("pragma% can only be applied to a variable",
12807 Set_Has_Pragma_Unmodified (Arg_Ent, Sense);
12819 -- pragma Unreferenced (local_Name {, local_Name});
12821 -- or when used in a context clause:
12823 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
12825 when Pragma_Unreferenced => Unreferenced : declare
12826 Arg_Node : Node_Id;
12827 Arg_Expr : Node_Id;
12828 Arg_Ent : Entity_Id;
12833 Check_At_Least_N_Arguments (1);
12835 -- Check case of appearing within context clause
12837 if Is_In_Context_Clause then
12839 -- The arguments must all be units mentioned in a with clause
12840 -- in the same context clause. Note we already checked (in
12841 -- Par.Prag) that the arguments are either identifiers or
12842 -- selected components.
12845 while Present (Arg_Node) loop
12846 Citem := First (List_Containing (N));
12847 while Citem /= N loop
12848 if Nkind (Citem) = N_With_Clause
12850 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
12852 Set_Has_Pragma_Unreferenced
12855 (Library_Unit (Citem))));
12857 (Get_Pragma_Arg (Arg_Node), Name (Citem));
12866 ("argument of pragma% is not with'ed unit", Arg_Node);
12872 -- Case of not in list of context items
12876 while Present (Arg_Node) loop
12877 Check_No_Identifier (Arg_Node);
12879 -- Note: the analyze call done by Check_Arg_Is_Local_Name
12880 -- will in fact generate reference, so that the entity will
12881 -- have a reference, which will inhibit any warnings about
12882 -- it not being referenced, and also properly show up in the
12883 -- ali file as a reference. But this reference is recorded
12884 -- before the Has_Pragma_Unreferenced flag is set, so that
12885 -- no warning is generated for this reference.
12887 Check_Arg_Is_Local_Name (Arg_Node);
12888 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12890 if Is_Entity_Name (Arg_Expr) then
12891 Arg_Ent := Entity (Arg_Expr);
12893 -- If the entity is overloaded, the pragma applies to the
12894 -- most recent overloading, as documented. In this case,
12895 -- name resolution does not generate a reference, so it
12896 -- must be done here explicitly.
12898 if Is_Overloaded (Arg_Expr) then
12899 Generate_Reference (Arg_Ent, N);
12902 Set_Has_Pragma_Unreferenced (Arg_Ent, Sense);
12910 --------------------------
12911 -- Unreferenced_Objects --
12912 --------------------------
12914 -- pragma Unreferenced_Objects (local_Name {, local_Name});
12916 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
12917 Arg_Node : Node_Id;
12918 Arg_Expr : Node_Id;
12922 Check_At_Least_N_Arguments (1);
12925 while Present (Arg_Node) loop
12926 Check_No_Identifier (Arg_Node);
12927 Check_Arg_Is_Local_Name (Arg_Node);
12928 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12930 if not Is_Entity_Name (Arg_Expr)
12931 or else not Is_Type (Entity (Arg_Expr))
12934 ("argument for pragma% must be type or subtype", Arg_Node);
12937 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr), Sense);
12940 end Unreferenced_Objects;
12942 ------------------------------
12943 -- Unreserve_All_Interrupts --
12944 ------------------------------
12946 -- pragma Unreserve_All_Interrupts;
12948 when Pragma_Unreserve_All_Interrupts =>
12950 Check_Arg_Count (0);
12952 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
12953 Unreserve_All_Interrupts := True;
12960 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
12962 when Pragma_Unsuppress =>
12964 Process_Suppress_Unsuppress (False);
12966 -------------------
12967 -- Use_VADS_Size --
12968 -------------------
12970 -- pragma Use_VADS_Size;
12972 when Pragma_Use_VADS_Size =>
12974 Check_Arg_Count (0);
12975 Check_Valid_Configuration_Pragma;
12976 Use_VADS_Size := True;
12978 ---------------------
12979 -- Validity_Checks --
12980 ---------------------
12982 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12984 when Pragma_Validity_Checks => Validity_Checks : declare
12985 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12991 Check_Arg_Count (1);
12992 Check_No_Identifiers;
12994 if Nkind (A) = N_String_Literal then
12998 Slen : constant Natural := Natural (String_Length (S));
12999 Options : String (1 .. Slen);
13005 C := Get_String_Char (S, Int (J));
13006 exit when not In_Character_Range (C);
13007 Options (J) := Get_Character (C);
13010 Set_Validity_Check_Options (Options);
13018 elsif Nkind (A) = N_Identifier then
13020 if Chars (A) = Name_All_Checks then
13021 Set_Validity_Check_Options ("a");
13023 elsif Chars (A) = Name_On then
13024 Validity_Checks_On := True;
13026 elsif Chars (A) = Name_Off then
13027 Validity_Checks_On := False;
13031 end Validity_Checks;
13037 -- pragma Volatile (LOCAL_NAME);
13039 when Pragma_Volatile =>
13040 Process_Atomic_Shared_Volatile;
13042 -------------------------
13043 -- Volatile_Components --
13044 -------------------------
13046 -- pragma Volatile_Components (array_LOCAL_NAME);
13048 -- Volatile is handled by the same circuit as Atomic_Components
13054 -- pragma Warnings (On | Off);
13055 -- pragma Warnings (On | Off, LOCAL_NAME);
13056 -- pragma Warnings (static_string_EXPRESSION);
13057 -- pragma Warnings (On | Off, STRING_LITERAL);
13059 when Pragma_Warnings => Warnings : begin
13061 Check_At_Least_N_Arguments (1);
13062 Check_No_Identifiers;
13064 -- If debug flag -gnatd.i is set, pragma is ignored
13066 if Debug_Flag_Dot_I then
13070 -- Process various forms of the pragma
13073 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13076 -- One argument case
13078 if Arg_Count = 1 then
13080 -- On/Off one argument case was processed by parser
13082 if Nkind (Argx) = N_Identifier
13084 (Chars (Argx) = Name_On
13086 Chars (Argx) = Name_Off)
13090 -- One argument case must be ON/OFF or static string expr
13092 elsif not Is_Static_String_Expression (Arg1) then
13094 ("argument of pragma% must be On/Off or " &
13095 "static string expression", Arg1);
13097 -- One argument string expression case
13101 Lit : constant Node_Id := Expr_Value_S (Argx);
13102 Str : constant String_Id := Strval (Lit);
13103 Len : constant Nat := String_Length (Str);
13111 while J <= Len loop
13112 C := Get_String_Char (Str, J);
13113 OK := In_Character_Range (C);
13116 Chr := Get_Character (C);
13120 if J < Len and then Chr = '.' then
13122 C := Get_String_Char (Str, J);
13123 Chr := Get_Character (C);
13125 if not Set_Dot_Warning_Switch (Chr) then
13127 ("invalid warning switch character " &
13134 OK := Set_Warning_Switch (Chr);
13140 ("invalid warning switch character " & Chr,
13149 -- Two or more arguments (must be two)
13152 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13153 Check_At_Most_N_Arguments (2);
13161 E_Id := Get_Pragma_Arg (Arg2);
13164 -- In the expansion of an inlined body, a reference to
13165 -- the formal may be wrapped in a conversion if the
13166 -- actual is a conversion. Retrieve the real entity name.
13168 if (In_Instance_Body
13169 or else In_Inlined_Body)
13170 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13172 E_Id := Expression (E_Id);
13175 -- Entity name case
13177 if Is_Entity_Name (E_Id) then
13178 E := Entity (E_Id);
13185 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13188 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13189 and then Warn_On_Warnings_Off
13191 Warnings_Off_Pragmas.Append ((N, E));
13194 if Is_Enumeration_Type (E) then
13198 Lit := First_Literal (E);
13199 while Present (Lit) loop
13200 Set_Warnings_Off (Lit);
13201 Next_Literal (Lit);
13206 exit when No (Homonym (E));
13211 -- Error if not entity or static string literal case
13213 elsif not Is_Static_String_Expression (Arg2) then
13215 ("second argument of pragma% must be entity " &
13216 "name or static string expression", Arg2);
13218 -- String literal case
13221 String_To_Name_Buffer
13222 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13224 -- Note on configuration pragma case: If this is a
13225 -- configuration pragma, then for an OFF pragma, we
13226 -- just set Config True in the call, which is all
13227 -- that needs to be done. For the case of ON, this
13228 -- is normally an error, unless it is canceling the
13229 -- effect of a previous OFF pragma in the same file.
13230 -- In any other case, an error will be signalled (ON
13231 -- with no matching OFF).
13233 if Chars (Argx) = Name_Off then
13234 Set_Specific_Warning_Off
13235 (Loc, Name_Buffer (1 .. Name_Len),
13236 Config => Is_Configuration_Pragma);
13238 elsif Chars (Argx) = Name_On then
13239 Set_Specific_Warning_On
13240 (Loc, Name_Buffer (1 .. Name_Len), Err);
13244 ("?pragma Warnings On with no " &
13245 "matching Warnings Off",
13255 -------------------
13256 -- Weak_External --
13257 -------------------
13259 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13261 when Pragma_Weak_External => Weak_External : declare
13266 Check_Arg_Count (1);
13267 Check_Optional_Identifier (Arg1, Name_Entity);
13268 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13269 Ent := Entity (Get_Pragma_Arg (Arg1));
13271 if Rep_Item_Too_Early (Ent, N) then
13274 Ent := Underlying_Type (Ent);
13277 -- The only processing required is to link this item on to the
13278 -- list of rep items for the given entity. This is accomplished
13279 -- by the call to Rep_Item_Too_Late (when no error is detected
13280 -- and False is returned).
13282 if Rep_Item_Too_Late (Ent, N) then
13285 Set_Has_Gigi_Rep_Item (Ent);
13289 -----------------------------
13290 -- Wide_Character_Encoding --
13291 -----------------------------
13293 -- pragma Wide_Character_Encoding (IDENTIFIER);
13295 when Pragma_Wide_Character_Encoding =>
13298 -- Nothing to do, handled in parser. Note that we do not enforce
13299 -- configuration pragma placement, this pragma can appear at any
13300 -- place in the source, allowing mixed encodings within a single
13305 --------------------
13306 -- Unknown_Pragma --
13307 --------------------
13309 -- Should be impossible, since the case of an unknown pragma is
13310 -- separately processed before the case statement is entered.
13312 when Unknown_Pragma =>
13313 raise Program_Error;
13316 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13317 -- until AI is formally approved.
13319 -- Check_Order_Dependence;
13322 when Pragma_Exit => null;
13323 end Analyze_Pragma;
13325 -------------------
13326 -- Check_Enabled --
13327 -------------------
13329 function Check_Enabled (Nam : Name_Id) return Boolean is
13333 PP := Opt.Check_Policy_List;
13336 return Assertions_Enabled;
13339 Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
13342 Chars (Expression (Last (Pragma_Argument_Associations (PP))))
13344 when Name_On | Name_Check =>
13346 when Name_Off | Name_Ignore =>
13349 raise Program_Error;
13353 PP := Next_Pragma (PP);
13358 ---------------------------------
13359 -- Delay_Config_Pragma_Analyze --
13360 ---------------------------------
13362 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13364 return Pragma_Name (N) = Name_Interrupt_State
13366 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13367 end Delay_Config_Pragma_Analyze;
13369 -------------------------
13370 -- Get_Base_Subprogram --
13371 -------------------------
13373 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13374 Result : Entity_Id;
13377 -- Follow subprogram renaming chain
13380 while Is_Subprogram (Result)
13382 (Is_Generic_Instance (Result)
13383 or else Nkind (Parent (Declaration_Node (Result))) =
13384 N_Subprogram_Renaming_Declaration)
13385 and then Present (Alias (Result))
13387 Result := Alias (Result);
13391 end Get_Base_Subprogram;
13397 procedure Initialize is
13402 -----------------------------
13403 -- Is_Config_Static_String --
13404 -----------------------------
13406 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13408 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
13409 -- This is an internal recursive function that is just like the outer
13410 -- function except that it adds the string to the name buffer rather
13411 -- than placing the string in the name buffer.
13413 ------------------------------
13414 -- Add_Config_Static_String --
13415 ------------------------------
13417 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
13424 if Nkind (N) = N_Op_Concat then
13425 if Add_Config_Static_String (Left_Opnd (N)) then
13426 N := Right_Opnd (N);
13432 if Nkind (N) /= N_String_Literal then
13433 Error_Msg_N ("string literal expected for pragma argument", N);
13437 for J in 1 .. String_Length (Strval (N)) loop
13438 C := Get_String_Char (Strval (N), J);
13440 if not In_Character_Range (C) then
13442 ("string literal contains invalid wide character",
13443 Sloc (N) + 1 + Source_Ptr (J));
13447 Add_Char_To_Name_Buffer (Get_Character (C));
13452 end Add_Config_Static_String;
13454 -- Start of processing for Is_Config_Static_String
13459 return Add_Config_Static_String (Arg);
13460 end Is_Config_Static_String;
13462 -----------------------------------------
13463 -- Is_Non_Significant_Pragma_Reference --
13464 -----------------------------------------
13466 -- This function makes use of the following static table which indicates
13467 -- whether a given pragma is significant.
13469 -- -1 indicates that references in any argument position are significant
13470 -- 0 indicates that appearence in any argument is not significant
13471 -- +n indicates that appearence as argument n is significant, but all
13472 -- other arguments are not significant
13473 -- 99 special processing required (e.g. for pragma Check)
13475 Sig_Flags : constant array (Pragma_Id) of Int :=
13476 (Pragma_AST_Entry => -1,
13477 Pragma_Abort_Defer => -1,
13478 Pragma_Ada_83 => -1,
13479 Pragma_Ada_95 => -1,
13480 Pragma_Ada_05 => -1,
13481 Pragma_Ada_2005 => -1,
13482 Pragma_Ada_12 => -1,
13483 Pragma_Ada_2012 => -1,
13484 Pragma_All_Calls_Remote => -1,
13485 Pragma_Annotate => -1,
13486 Pragma_Assert => -1,
13487 Pragma_Assertion_Policy => 0,
13488 Pragma_Assume_No_Invalid_Values => 0,
13489 Pragma_Asynchronous => -1,
13490 Pragma_Atomic => 0,
13491 Pragma_Atomic_Components => 0,
13492 Pragma_Attach_Handler => -1,
13493 Pragma_Check => 99,
13494 Pragma_Check_Name => 0,
13495 Pragma_Check_Policy => 0,
13496 Pragma_CIL_Constructor => -1,
13497 Pragma_CPP_Class => 0,
13498 Pragma_CPP_Constructor => 0,
13499 Pragma_CPP_Virtual => 0,
13500 Pragma_CPP_Vtable => 0,
13501 Pragma_C_Pass_By_Copy => 0,
13502 Pragma_Comment => 0,
13503 Pragma_Common_Object => -1,
13504 Pragma_Compile_Time_Error => -1,
13505 Pragma_Compile_Time_Warning => -1,
13506 Pragma_Compiler_Unit => 0,
13507 Pragma_Complete_Representation => 0,
13508 Pragma_Complex_Representation => 0,
13509 Pragma_Component_Alignment => -1,
13510 Pragma_Controlled => 0,
13511 Pragma_Convention => 0,
13512 Pragma_Convention_Identifier => 0,
13513 Pragma_Debug => -1,
13514 Pragma_Debug_Policy => 0,
13515 Pragma_Detect_Blocking => -1,
13516 Pragma_Dimension => -1,
13517 Pragma_Discard_Names => 0,
13518 Pragma_Elaborate => -1,
13519 Pragma_Elaborate_All => -1,
13520 Pragma_Elaborate_Body => -1,
13521 Pragma_Elaboration_Checks => -1,
13522 Pragma_Eliminate => -1,
13523 Pragma_Export => -1,
13524 Pragma_Export_Exception => -1,
13525 Pragma_Export_Function => -1,
13526 Pragma_Export_Object => -1,
13527 Pragma_Export_Procedure => -1,
13528 Pragma_Export_Value => -1,
13529 Pragma_Export_Valued_Procedure => -1,
13530 Pragma_Extend_System => -1,
13531 Pragma_Extensions_Allowed => -1,
13532 Pragma_External => -1,
13533 Pragma_Favor_Top_Level => -1,
13534 Pragma_External_Name_Casing => -1,
13535 Pragma_Fast_Math => -1,
13536 Pragma_Finalize_Storage_Only => 0,
13537 Pragma_Float_Representation => 0,
13538 Pragma_Ident => -1,
13539 Pragma_Implemented => -1,
13540 Pragma_Implicit_Packing => 0,
13541 Pragma_Import => +2,
13542 Pragma_Import_Exception => 0,
13543 Pragma_Import_Function => 0,
13544 Pragma_Import_Object => 0,
13545 Pragma_Import_Procedure => 0,
13546 Pragma_Import_Valued_Procedure => 0,
13547 Pragma_Independent => 0,
13548 Pragma_Independent_Components => 0,
13549 Pragma_Initialize_Scalars => -1,
13550 Pragma_Inline => 0,
13551 Pragma_Inline_Always => 0,
13552 Pragma_Inline_Generic => 0,
13553 Pragma_Inspection_Point => -1,
13554 Pragma_Interface => +2,
13555 Pragma_Interface_Name => +2,
13556 Pragma_Interrupt_Handler => -1,
13557 Pragma_Interrupt_Priority => -1,
13558 Pragma_Interrupt_State => -1,
13559 Pragma_Java_Constructor => -1,
13560 Pragma_Java_Interface => -1,
13561 Pragma_Keep_Names => 0,
13562 Pragma_License => -1,
13563 Pragma_Link_With => -1,
13564 Pragma_Linker_Alias => -1,
13565 Pragma_Linker_Constructor => -1,
13566 Pragma_Linker_Destructor => -1,
13567 Pragma_Linker_Options => -1,
13568 Pragma_Linker_Section => -1,
13570 Pragma_Locking_Policy => -1,
13571 Pragma_Long_Float => -1,
13572 Pragma_Machine_Attribute => -1,
13574 Pragma_Main_Storage => -1,
13575 Pragma_Memory_Size => -1,
13576 Pragma_No_Return => 0,
13577 Pragma_No_Body => 0,
13578 Pragma_No_Run_Time => -1,
13579 Pragma_No_Strict_Aliasing => -1,
13580 Pragma_Normalize_Scalars => -1,
13581 Pragma_Obsolescent => 0,
13582 Pragma_Optimize => -1,
13583 Pragma_Optimize_Alignment => -1,
13584 Pragma_Ordered => 0,
13587 Pragma_Passive => -1,
13588 Pragma_Preelaborable_Initialization => -1,
13589 Pragma_Polling => -1,
13590 Pragma_Persistent_BSS => 0,
13591 Pragma_Postcondition => -1,
13592 Pragma_Precondition => -1,
13593 Pragma_Preelaborate => -1,
13594 Pragma_Preelaborate_05 => -1,
13595 Pragma_Priority => -1,
13596 Pragma_Priority_Specific_Dispatching => -1,
13597 Pragma_Profile => 0,
13598 Pragma_Profile_Warnings => 0,
13599 Pragma_Propagate_Exceptions => -1,
13600 Pragma_Psect_Object => -1,
13602 Pragma_Pure_05 => -1,
13603 Pragma_Pure_Function => -1,
13604 Pragma_Queuing_Policy => -1,
13605 Pragma_Ravenscar => -1,
13606 Pragma_Relative_Deadline => -1,
13607 Pragma_Remote_Call_Interface => -1,
13608 Pragma_Remote_Types => -1,
13609 Pragma_Restricted_Run_Time => -1,
13610 Pragma_Restriction_Warnings => -1,
13611 Pragma_Restrictions => -1,
13612 Pragma_Reviewable => -1,
13613 Pragma_Short_Circuit_And_Or => -1,
13614 Pragma_Share_Generic => -1,
13615 Pragma_Shared => -1,
13616 Pragma_Shared_Passive => -1,
13617 Pragma_Short_Descriptors => 0,
13618 Pragma_Source_File_Name => -1,
13619 Pragma_Source_File_Name_Project => -1,
13620 Pragma_Source_Reference => -1,
13621 Pragma_Storage_Size => -1,
13622 Pragma_Storage_Unit => -1,
13623 Pragma_Static_Elaboration_Desired => -1,
13624 Pragma_Stream_Convert => -1,
13625 Pragma_Style_Checks => -1,
13626 Pragma_Subtitle => -1,
13627 Pragma_Suppress => 0,
13628 Pragma_Suppress_Exception_Locations => 0,
13629 Pragma_Suppress_All => -1,
13630 Pragma_Suppress_Debug_Info => 0,
13631 Pragma_Suppress_Initialization => 0,
13632 Pragma_System_Name => -1,
13633 Pragma_Task_Dispatching_Policy => -1,
13634 Pragma_Task_Info => -1,
13635 Pragma_Task_Name => -1,
13636 Pragma_Task_Storage => 0,
13637 Pragma_Thread_Local_Storage => 0,
13638 Pragma_Time_Slice => -1,
13639 Pragma_Title => -1,
13640 Pragma_Unchecked_Union => 0,
13641 Pragma_Unimplemented_Unit => -1,
13642 Pragma_Universal_Aliasing => -1,
13643 Pragma_Universal_Data => -1,
13644 Pragma_Unmodified => -1,
13645 Pragma_Unreferenced => -1,
13646 Pragma_Unreferenced_Objects => -1,
13647 Pragma_Unreserve_All_Interrupts => -1,
13648 Pragma_Unsuppress => 0,
13649 Pragma_Use_VADS_Size => -1,
13650 Pragma_Validity_Checks => -1,
13651 Pragma_Volatile => 0,
13652 Pragma_Volatile_Components => 0,
13653 Pragma_Warnings => -1,
13654 Pragma_Weak_External => -1,
13655 Pragma_Wide_Character_Encoding => 0,
13656 Unknown_Pragma => 0);
13658 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
13667 if Nkind (P) /= N_Pragma_Argument_Association then
13671 Id := Get_Pragma_Id (Parent (P));
13672 C := Sig_Flags (Id);
13684 -- For pragma Check, the first argument is not significant,
13685 -- the second and the third (if present) arguments are
13688 when Pragma_Check =>
13690 P = First (Pragma_Argument_Associations (Parent (P)));
13693 raise Program_Error;
13697 A := First (Pragma_Argument_Associations (Parent (P)));
13698 for J in 1 .. C - 1 loop
13706 return A = P; -- is this wrong way round ???
13709 end Is_Non_Significant_Pragma_Reference;
13711 ------------------------------
13712 -- Is_Pragma_String_Literal --
13713 ------------------------------
13715 -- This function returns true if the corresponding pragma argument is a
13716 -- static string expression. These are the only cases in which string
13717 -- literals can appear as pragma arguments. We also allow a string literal
13718 -- as the first argument to pragma Assert (although it will of course
13719 -- always generate a type error).
13721 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
13722 Pragn : constant Node_Id := Parent (Par);
13723 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
13724 Pname : constant Name_Id := Pragma_Name (Pragn);
13730 N := First (Assoc);
13737 if Pname = Name_Assert then
13740 elsif Pname = Name_Export then
13743 elsif Pname = Name_Ident then
13746 elsif Pname = Name_Import then
13749 elsif Pname = Name_Interface_Name then
13752 elsif Pname = Name_Linker_Alias then
13755 elsif Pname = Name_Linker_Section then
13758 elsif Pname = Name_Machine_Attribute then
13761 elsif Pname = Name_Source_File_Name then
13764 elsif Pname = Name_Source_Reference then
13767 elsif Pname = Name_Title then
13770 elsif Pname = Name_Subtitle then
13776 end Is_Pragma_String_Literal;
13778 --------------------------------------
13779 -- Process_Compilation_Unit_Pragmas --
13780 --------------------------------------
13782 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
13784 -- A special check for pragma Suppress_All, a very strange DEC pragma,
13785 -- strange because it comes at the end of the unit. If we have a pragma
13786 -- Suppress_All in the Pragmas_After of the current unit, then we insert
13787 -- a pragma Suppress (All_Checks) at the start of the context clause to
13788 -- ensure the correct processing.
13791 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
13795 if Present (PA) then
13797 while Present (P) loop
13798 if Pragma_Name (P) = Name_Suppress_All then
13799 Prepend_To (Context_Items (N),
13800 Make_Pragma (Sloc (P),
13801 Chars => Name_Suppress,
13802 Pragma_Argument_Associations => New_List (
13803 Make_Pragma_Argument_Association (Sloc (P),
13805 Make_Identifier (Sloc (P),
13806 Chars => Name_All_Checks)))));
13814 end Process_Compilation_Unit_Pragmas;
13825 --------------------------------
13826 -- Set_Encoded_Interface_Name --
13827 --------------------------------
13829 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
13830 Str : constant String_Id := Strval (S);
13831 Len : constant Int := String_Length (Str);
13836 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
13839 -- Stores encoded value of character code CC. The encoding we use an
13840 -- underscore followed by four lower case hex digits.
13846 procedure Encode is
13848 Store_String_Char (Get_Char_Code ('_'));
13850 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
13852 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
13854 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
13856 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
13859 -- Start of processing for Set_Encoded_Interface_Name
13862 -- If first character is asterisk, this is a link name, and we leave it
13863 -- completely unmodified. We also ignore null strings (the latter case
13864 -- happens only in error cases) and no encoding should occur for Java or
13865 -- AAMP interface names.
13868 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
13869 or else VM_Target /= No_VM
13870 or else AAMP_On_Target
13872 Set_Interface_Name (E, S);
13877 CC := Get_String_Char (Str, J);
13879 exit when not In_Character_Range (CC);
13881 C := Get_Character (CC);
13883 exit when C /= '_' and then C /= '$'
13884 and then C not in '0' .. '9'
13885 and then C not in 'a' .. 'z'
13886 and then C not in 'A' .. 'Z';
13889 Set_Interface_Name (E, S);
13897 -- Here we need to encode. The encoding we use as follows:
13898 -- three underscores + four hex digits (lower case)
13902 for J in 1 .. String_Length (Str) loop
13903 CC := Get_String_Char (Str, J);
13905 if not In_Character_Range (CC) then
13908 C := Get_Character (CC);
13910 if C = '_' or else C = '$'
13911 or else C in '0' .. '9'
13912 or else C in 'a' .. 'z'
13913 or else C in 'A' .. 'Z'
13915 Store_String_Char (CC);
13922 Set_Interface_Name (E,
13923 Make_String_Literal (Sloc (S),
13924 Strval => End_String));
13926 end Set_Encoded_Interface_Name;
13928 -------------------
13929 -- Set_Unit_Name --
13930 -------------------
13932 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
13937 if Nkind (N) = N_Identifier
13938 and then Nkind (With_Item) = N_Identifier
13940 Set_Entity (N, Entity (With_Item));
13942 elsif Nkind (N) = N_Selected_Component then
13943 Change_Selected_Component_To_Expanded_Name (N);
13944 Set_Entity (N, Entity (With_Item));
13945 Set_Entity (Selector_Name (N), Entity (N));
13947 Pref := Prefix (N);
13948 Scop := Scope (Entity (N));
13949 while Nkind (Pref) = N_Selected_Component loop
13950 Change_Selected_Component_To_Expanded_Name (Pref);
13951 Set_Entity (Selector_Name (Pref), Scop);
13952 Set_Entity (Pref, Scop);
13953 Pref := Prefix (Pref);
13954 Scop := Scope (Scop);
13957 Set_Entity (Pref, Scop);