* tree-ssa-pre.c (grand_bitmap_obstack): New.
[official-gcc.git] / gcc / ada / sem_prag.adb
blob02b194739624585f68c908ecf61c3f1c8a90c6e0
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ P R A G --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2004, Free Software Foundation, Inc. --
10 -- --
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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 -- This unit contains the semantic processing for all pragmas, both language
28 -- and implementation defined. For most pragmas, the parser only does the
29 -- most basic job of checking the syntax, so Sem_Prag also contains the code
30 -- to complete the syntax checks. Certain pragmas are handled partially or
31 -- completely by the parser (see Par.Prag for further details).
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with Elists; use Elists;
39 with Errout; use Errout;
40 with Exp_Dist; use Exp_Dist;
41 with Fname; use Fname;
42 with Hostparm; use Hostparm;
43 with Lib; use Lib;
44 with Lib.Writ; use Lib.Writ;
45 with Lib.Xref; use Lib.Xref;
46 with Namet; use Namet;
47 with Nlists; use Nlists;
48 with Nmake; use Nmake;
49 with Opt; use Opt;
50 with Output; use Output;
51 with Restrict; use Restrict;
52 with Rident; use Rident;
53 with Rtsfind; use Rtsfind;
54 with Sem; use Sem;
55 with Sem_Ch3; use Sem_Ch3;
56 with Sem_Ch8; use Sem_Ch8;
57 with Sem_Ch13; use Sem_Ch13;
58 with Sem_Disp; use Sem_Disp;
59 with Sem_Elim; use Sem_Elim;
60 with Sem_Eval; use Sem_Eval;
61 with Sem_Intr; use Sem_Intr;
62 with Sem_Mech; use Sem_Mech;
63 with Sem_Res; use Sem_Res;
64 with Sem_Type; use Sem_Type;
65 with Sem_Util; use Sem_Util;
66 with Sem_VFpt; use Sem_VFpt;
67 with Stand; use Stand;
68 with Sinfo; use Sinfo;
69 with Sinfo.CN; use Sinfo.CN;
70 with Sinput; use Sinput;
71 with Snames; use Snames;
72 with Stringt; use Stringt;
73 with Stylesw; use Stylesw;
74 with Table;
75 with Targparm; use Targparm;
76 with Tbuild; use Tbuild;
77 with Ttypes;
78 with Uintp; use Uintp;
79 with Urealp; use Urealp;
80 with Validsw; use Validsw;
82 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
84 package body Sem_Prag is
86 ----------------------------------------------
87 -- Common Handling of Import-Export Pragmas --
88 ----------------------------------------------
90 -- In the following section, a number of Import_xxx and Export_xxx
91 -- pragmas are defined by GNAT. These are compatible with the DEC
92 -- pragmas of the same name, and all have the following common
93 -- form and processing:
95 -- pragma Export_xxx
96 -- [Internal =>] LOCAL_NAME,
97 -- [, [External =>] EXTERNAL_SYMBOL]
98 -- [, other optional parameters ]);
100 -- pragma Import_xxx
101 -- [Internal =>] LOCAL_NAME,
102 -- [, [External =>] EXTERNAL_SYMBOL]
103 -- [, other optional parameters ]);
105 -- EXTERNAL_SYMBOL ::=
106 -- IDENTIFIER
107 -- | static_string_EXPRESSION
109 -- The internal LOCAL_NAME designates the entity that is imported or
110 -- exported, and must refer to an entity in the current declarative
111 -- part (as required by the rules for LOCAL_NAME).
113 -- The external linker name is designated by the External parameter
114 -- if given, or the Internal parameter if not (if there is no External
115 -- parameter, the External parameter is a copy of the Internal name).
117 -- If the External parameter is given as a string, then this string
118 -- is treated as an external name (exactly as though it had been given
119 -- as an External_Name parameter for a normal Import pragma).
121 -- If the External parameter is given as an identifier (or there is no
122 -- External parameter, so that the Internal identifier is used), then
123 -- the external name is the characters of the identifier, translated
124 -- to all upper case letters for OpenVMS versions of GNAT, and to all
125 -- lower case letters for all other versions
127 -- Note: the external name specified or implied by any of these special
128 -- Import_xxx or Export_xxx pragmas override an external or link name
129 -- specified in a previous Import or Export pragma.
131 -- Note: these and all other DEC-compatible GNAT pragmas allow full
132 -- use of named notation, following the standard rules for subprogram
133 -- calls, i.e. parameters can be given in any order if named notation
134 -- is used, and positional and named notation can be mixed, subject to
135 -- the rule that all positional parameters must appear first.
137 -- Note: All these pragmas are implemented exactly following the DEC
138 -- design and implementation and are intended to be fully compatible
139 -- with the use of these pragmas in the DEC Ada compiler.
141 --------------------------------------------
142 -- Checking for Duplicated External Names --
143 --------------------------------------------
145 -- It is suspicious if two separate Export pragmas use the same external
146 -- name. The following table is used to diagnose this situation so that
147 -- an appropriate warning can be issued.
149 -- The Node_Id stored is for the N_String_Literal node created to
150 -- hold the value of the external name. The Sloc of this node is
151 -- used to cross-reference the location of the duplication.
153 package Externals is new Table.Table (
154 Table_Component_Type => Node_Id,
155 Table_Index_Type => Int,
156 Table_Low_Bound => 0,
157 Table_Initial => 100,
158 Table_Increment => 100,
159 Table_Name => "Name_Externals");
161 -------------------------------------
162 -- Local Subprograms and Variables --
163 -------------------------------------
165 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
166 -- This routine is used for possible casing adjustment of an explicit
167 -- external name supplied as a string literal (the node N), according
168 -- to the casing requirement of Opt.External_Name_Casing. If this is
169 -- set to As_Is, then the string literal is returned unchanged, but if
170 -- it is set to Uppercase or Lowercase, then a new string literal with
171 -- appropriate casing is constructed.
173 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
174 -- If Def_Id refers to a renamed subprogram, then the base subprogram
175 -- (the original one, following the renaming chain) is returned.
176 -- Otherwise the entity is returned unchanged. Should be in Einfo???
178 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
179 -- Place semantic information on the argument of an Elaborate or
180 -- Elaborate_All pragma. Entity name for unit and its parents is
181 -- taken from item in previous with_clause that mentions the unit.
183 -------------------------------
184 -- Adjust_External_Name_Case --
185 -------------------------------
187 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
188 CC : Char_Code;
190 begin
191 -- Adjust case of literal if required
193 if Opt.External_Name_Exp_Casing = As_Is then
194 return N;
196 else
197 -- Copy existing string
199 Start_String;
201 -- Set proper casing
203 for J in 1 .. String_Length (Strval (N)) loop
204 CC := Get_String_Char (Strval (N), J);
206 if Opt.External_Name_Exp_Casing = Uppercase
207 and then CC >= Get_Char_Code ('a')
208 and then CC <= Get_Char_Code ('z')
209 then
210 Store_String_Char (CC - 32);
212 elsif Opt.External_Name_Exp_Casing = Lowercase
213 and then CC >= Get_Char_Code ('A')
214 and then CC <= Get_Char_Code ('Z')
215 then
216 Store_String_Char (CC + 32);
218 else
219 Store_String_Char (CC);
220 end if;
221 end loop;
223 return
224 Make_String_Literal (Sloc (N),
225 Strval => End_String);
226 end if;
227 end Adjust_External_Name_Case;
229 --------------------
230 -- Analyze_Pragma --
231 --------------------
233 procedure Analyze_Pragma (N : Node_Id) is
234 Loc : constant Source_Ptr := Sloc (N);
235 Prag_Id : Pragma_Id;
237 Pragma_Exit : exception;
238 -- This exception is used to exit pragma processing completely. It
239 -- is used when an error is detected, and in other situations where
240 -- it is known that no further processing is required.
242 Arg_Count : Nat;
243 -- Number of pragma argument associations
245 Arg1 : Node_Id;
246 Arg2 : Node_Id;
247 Arg3 : Node_Id;
248 Arg4 : Node_Id;
249 -- First four pragma arguments (pragma argument association nodes,
250 -- or Empty if the corresponding argument does not exist).
252 procedure Check_Ada_83_Warning;
253 -- Issues a warning message for the current pragma if operating in Ada
254 -- 83 mode (used for language pragmas that are not a standard part of
255 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
256 -- of 95 pragma.
258 procedure Check_Arg_Count (Required : Nat);
259 -- Check argument count for pragma is equal to given parameter.
260 -- If not, then issue an error message and raise Pragma_Exit.
262 -- Note: all routines whose name is Check_Arg_Is_xxx take an
263 -- argument Arg which can either be a pragma argument association,
264 -- in which case the check is applied to the expression of the
265 -- association or an expression directly.
267 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
268 -- Check that an argument has the right form for an EXTERNAL_NAME
269 -- parameter of an extended import/export pragma. The rule is that
270 -- the name must be an identifier or string literal (in Ada 83 mode)
271 -- or a static string expression (in Ada 95 mode).
273 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
274 -- Check the specified argument Arg to make sure that it is an
275 -- identifier. If not give error and raise Pragma_Exit.
277 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
278 -- Check the specified argument Arg to make sure that it is an
279 -- integer literal. If not give error and raise Pragma_Exit.
281 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
282 -- Check the specified argument Arg to make sure that it has the
283 -- proper syntactic form for a local name and meets the semantic
284 -- requirements for a local name. The local name is analyzed as
285 -- part of the processing for this call. In addition, the local
286 -- name is required to represent an entity at the library level.
288 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
289 -- Check the specified argument Arg to make sure that it has the
290 -- proper syntactic form for a local name and meets the semantic
291 -- requirements for a local name. The local name is analyzed as
292 -- part of the processing for this call.
294 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
295 -- Check the specified argument Arg to make sure that it is a valid
296 -- locking policy name. If not give error and raise Pragma_Exit.
298 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
299 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
300 -- Check the specified argument Arg to make sure that it is an
301 -- identifier whose name matches either N1 or N2 (or N3 if present).
302 -- If not then give error and raise Pragma_Exit.
304 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
305 -- Check the specified argument Arg to make sure that it is a valid
306 -- queuing policy name. If not give error and raise Pragma_Exit.
308 procedure Check_Arg_Is_Static_Expression
309 (Arg : Node_Id;
310 Typ : Entity_Id);
311 -- Check the specified argument Arg to make sure that it is a static
312 -- expression of the given type (i.e. it will be analyzed and resolved
313 -- using this type, which can be any valid argument to Resolve, e.g.
314 -- Any_Integer is OK). If not, given error and raise Pragma_Exit.
316 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
317 -- Check the specified argument Arg to make sure that it is a
318 -- string literal. If not give error and raise Pragma_Exit
320 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
321 -- Check the specified argument Arg to make sure that it is a valid
322 -- valid task dispatching policy name. If not give error and raise
323 -- Pragma_Exit.
325 procedure Check_At_Least_N_Arguments (N : Nat);
326 -- Check there are at least N arguments present
328 procedure Check_At_Most_N_Arguments (N : Nat);
329 -- Check there are no more than N arguments present
331 procedure Check_Component (Comp : Node_Id);
332 -- Examine Unchecked_Union component for correct use of per-object
333 -- constrained subtypes.
335 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
336 -- Nam is an N_String_Literal node containing the external name set
337 -- by an Import or Export pragma (or extended Import or Export pragma).
338 -- This procedure checks for possible duplications if this is the
339 -- export case, and if found, issues an appropriate error message.
341 procedure Check_First_Subtype (Arg : Node_Id);
342 -- Checks that Arg, whose expression is an entity name referencing
343 -- a subtype, does not reference a type that is not a first subtype.
345 procedure Check_In_Main_Program;
346 -- Common checks for pragmas that appear within a main program
347 -- (Priority, Main_Storage, Time_Slice).
349 procedure Check_Interrupt_Or_Attach_Handler;
350 -- Common processing for first argument of pragma Interrupt_Handler
351 -- or pragma Attach_Handler.
353 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
354 -- Check that pragma appears in a declarative part, or in a package
355 -- specification, i.e. that it does not occur in a statement sequence
356 -- in a body.
358 procedure Check_No_Identifier (Arg : Node_Id);
359 -- Checks that the given argument does not have an identifier. If
360 -- an identifier is present, then an error message is issued, and
361 -- Pragma_Exit is raised.
363 procedure Check_No_Identifiers;
364 -- Checks that none of the arguments to the pragma has an identifier.
365 -- If any argument has an identifier, then an error message is issued,
366 -- and Pragma_Exit is raised.
368 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
369 -- Checks if the given argument has an identifier, and if so, requires
370 -- it to match the given identifier name. If there is a non-matching
371 -- identifier, then an error message is given and Error_Pragmas raised.
373 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
374 -- Checks if the given argument has an identifier, and if so, requires
375 -- it to match the given identifier name. If there is a non-matching
376 -- identifier, then an error message is given and Error_Pragmas raised.
377 -- In this version of the procedure, the identifier name is given as
378 -- a string with lower case letters.
380 procedure Check_Static_Constraint (Constr : Node_Id);
381 -- Constr is a constraint from an N_Subtype_Indication node from a
382 -- component constraint in an Unchecked_Union type. This routine checks
383 -- that the constraint is static as required by the restrictions for
384 -- Unchecked_Union.
386 procedure Check_Valid_Configuration_Pragma;
387 -- Legality checks for placement of a configuration pragma
389 procedure Check_Valid_Library_Unit_Pragma;
390 -- Legality checks for library unit pragmas. A special case arises for
391 -- pragmas in generic instances that come from copies of the original
392 -- library unit pragmas in the generic templates. In the case of other
393 -- than library level instantiations these can appear in contexts which
394 -- would normally be invalid (they only apply to the original template
395 -- and to library level instantiations), and they are simply ignored,
396 -- which is implemented by rewriting them as null statements.
398 procedure Check_Variant (Variant : Node_Id);
399 -- Check Unchecked_Union variant for lack of nested variants and
400 -- presence of at least one component.
402 procedure Error_Pragma (Msg : String);
403 pragma No_Return (Error_Pragma);
404 -- Outputs error message for current pragma. The message contains an %
405 -- that will be replaced with the pragma name, and the flag is placed
406 -- on the pragma itself. Pragma_Exit is then raised.
408 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
409 pragma No_Return (Error_Pragma_Arg);
410 -- Outputs error message for current pragma. The message may contain
411 -- a % that will be replaced with the pragma name. The parameter Arg
412 -- may either be a pragma argument association, in which case the flag
413 -- is placed on the expression of this association, or an expression,
414 -- in which case the flag is placed directly on the expression. The
415 -- message is placed using Error_Msg_N, so the message may also contain
416 -- an & insertion character which will reference the given Arg value.
417 -- After placing the message, Pragma_Exit is raised.
419 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
420 pragma No_Return (Error_Pragma_Arg);
421 -- Similar to above form of Error_Pragma_Arg except that two messages
422 -- are provided, the second is a continuation comment starting with \.
424 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
425 pragma No_Return (Error_Pragma_Arg_Ident);
426 -- Outputs error message for current pragma. The message may contain
427 -- a % that will be replaced with the pragma name. The parameter Arg
428 -- must be a pragma argument association with a non-empty identifier
429 -- (i.e. its Chars field must be set), and the error message is placed
430 -- on the identifier. The message is placed using Error_Msg_N so
431 -- the message may also contain an & insertion character which will
432 -- reference the identifier. After placing the message, Pragma_Exit
433 -- is raised.
435 function Find_Lib_Unit_Name return Entity_Id;
436 -- Used for a library unit pragma to find the entity to which the
437 -- library unit pragma applies, returns the entity found.
439 procedure Find_Program_Unit_Name (Id : Node_Id);
440 -- If the pragma is a compilation unit pragma, the id must denote the
441 -- compilation unit in the same compilation, and the pragma must appear
442 -- in the list of preceding or trailing pragmas. If it is a program
443 -- unit pragma that is not a compilation unit pragma, then the
444 -- identifier must be visible.
446 type Name_List is array (Natural range <>) of Name_Id;
447 type Args_List is array (Natural range <>) of Node_Id;
448 procedure Gather_Associations
449 (Names : Name_List;
450 Args : out Args_List);
451 -- This procedure is used to gather the arguments for a pragma that
452 -- permits arbitrary ordering of parameters using the normal rules
453 -- for named and positional parameters. The Names argument is a list
454 -- of Name_Id values that corresponds to the allowed pragma argument
455 -- association identifiers in order. The result returned in Args is
456 -- a list of corresponding expressions that are the pragma arguments.
457 -- Note that this is a list of expressions, not of pragma argument
458 -- associations (Gather_Associations has completely checked all the
459 -- optional identifiers when it returns). An entry in Args is Empty
460 -- on return if the corresponding argument is not present.
462 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
463 -- All the routines that check pragma arguments take either a pragma
464 -- argument association (in which case the expression of the argument
465 -- association is checked), or the expression directly. The function
466 -- Get_Pragma_Arg is a utility used to deal with these two cases. If
467 -- Arg is a pragma argument association node, then its expression is
468 -- returned, otherwise Arg is returned unchanged.
470 procedure GNAT_Pragma;
471 -- Called for all GNAT defined pragmas to note the use of the feature,
472 -- and also check the relevant restriction (No_Implementation_Pragmas).
474 function Is_Before_First_Decl
475 (Pragma_Node : Node_Id;
476 Decls : List_Id) return Boolean;
477 -- Return True if Pragma_Node is before the first declarative item in
478 -- Decls where Decls is the list of declarative items.
480 function Is_Configuration_Pragma return Boolean;
481 -- Deterermines if the placement of the current pragma is appropriate
482 -- for a configuration pragma (precedes the current compilation unit)
484 procedure Pragma_Misplaced;
485 -- Issue fatal error message for misplaced pragma
487 procedure Process_Atomic_Shared_Volatile;
488 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
489 -- Shared is an obsolete Ada 83 pragma, treated as being identical
490 -- in effect to pragma Atomic.
492 procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
493 -- Common procesing for Convention, Interface, Import and Export.
494 -- Checks first two arguments of pragma, and sets the appropriate
495 -- convention value in the specified entity or entities. On return
496 -- C is the convention, E is the referenced entity.
498 procedure Process_Extended_Import_Export_Exception_Pragma
499 (Arg_Internal : Node_Id;
500 Arg_External : Node_Id;
501 Arg_Form : Node_Id;
502 Arg_Code : Node_Id);
503 -- Common processing for the pragmas Import/Export_Exception.
504 -- The three arguments correspond to the three named parameters of
505 -- the pragma. An argument is empty if the corresponding parameter
506 -- is not present in the pragma.
508 procedure Process_Extended_Import_Export_Object_Pragma
509 (Arg_Internal : Node_Id;
510 Arg_External : Node_Id;
511 Arg_Size : Node_Id);
512 -- Common processing for the pragmass Import/Export_Object.
513 -- The three arguments correspond to the three named parameters
514 -- of the pragmas. An argument is empty if the corresponding
515 -- parameter is not present in the pragma.
517 procedure Process_Extended_Import_Export_Internal_Arg
518 (Arg_Internal : Node_Id := Empty);
519 -- Common processing for all extended Import and Export pragmas. The
520 -- argument is the pragma parameter for the Internal argument. If
521 -- Arg_Internal is empty or inappropriate, an error message is posted.
522 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
523 -- set to identify the referenced entity.
525 procedure Process_Extended_Import_Export_Subprogram_Pragma
526 (Arg_Internal : Node_Id;
527 Arg_External : Node_Id;
528 Arg_Parameter_Types : Node_Id;
529 Arg_Result_Type : Node_Id := Empty;
530 Arg_Mechanism : Node_Id;
531 Arg_Result_Mechanism : Node_Id := Empty;
532 Arg_First_Optional_Parameter : Node_Id := Empty);
533 -- Common processing for all extended Import and Export pragmas
534 -- applying to subprograms. The caller omits any arguments that do
535 -- bnot apply to the pragma in question (for example, Arg_Result_Type
536 -- can be non-Empty only in the Import_Function and Export_Function
537 -- cases). The argument names correspond to the allowed pragma
538 -- association identifiers.
540 procedure Process_Generic_List;
541 -- Common processing for Share_Generic and Inline_Generic
543 procedure Process_Import_Or_Interface;
544 -- Common processing for Import of Interface
546 procedure Process_Inline (Active : Boolean);
547 -- Common processing for Inline and Inline_Always. The parameter
548 -- indicates if the inline pragma is active, i.e. if it should
549 -- actually cause inlining to occur.
551 procedure Process_Interface_Name
552 (Subprogram_Def : Entity_Id;
553 Ext_Arg : Node_Id;
554 Link_Arg : Node_Id);
555 -- Given the last two arguments of pragma Import, pragma Export, or
556 -- pragma Interface_Name, performs validity checks and sets the
557 -- Interface_Name field of the given subprogram entity to the
558 -- appropriate external or link name, depending on the arguments
559 -- given. Ext_Arg is always present, but Link_Arg may be missing.
560 -- Note that Ext_Arg may represent the Link_Name if Link_Arg is
561 -- missing, and appropriate named notation is used for Ext_Arg.
562 -- If neither Ext_Arg nor Link_Arg is present, the interface name
563 -- is set to the default from the subprogram name.
565 procedure Process_Interrupt_Or_Attach_Handler;
566 -- Common processing for Interrupt and Attach_Handler pragmas
568 procedure Process_Restrictions_Or_Restriction_Warnings;
569 -- Common processing for Restrictions and Restriction_Warnings pragmas
571 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
572 -- Common processing for Suppress and Unsuppress. The boolean parameter
573 -- Suppress_Case is True for the Suppress case, and False for the
574 -- Unsuppress case.
576 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
577 -- This procedure sets the Is_Exported flag for the given entity,
578 -- checking that the entity was not previously imported. Arg is
579 -- the argument that specified the entity. A check is also made
580 -- for exporting inappropriate entities.
582 procedure Set_Extended_Import_Export_External_Name
583 (Internal_Ent : Entity_Id;
584 Arg_External : Node_Id);
585 -- Common processing for all extended import export pragmas. The first
586 -- argument, Internal_Ent, is the internal entity, which has already
587 -- been checked for validity by the caller. Arg_External is from the
588 -- Import or Export pragma, and may be null if no External parameter
589 -- was present. If Arg_External is present and is a non-null string
590 -- (a null string is treated as the default), then the Interface_Name
591 -- field of Internal_Ent is set appropriately.
593 procedure Set_Imported (E : Entity_Id);
594 -- This procedure sets the Is_Imported flag for the given entity,
595 -- checking that it is not previously exported or imported.
597 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
598 -- Mech is a parameter passing mechanism (see Import_Function syntax
599 -- for MECHANISM_NAME). This routine checks that the mechanism argument
600 -- has the right form, and if not issues an error message. If the
601 -- argument has the right form then the Mechanism field of Ent is
602 -- set appropriately.
604 procedure Set_Ravenscar_Profile (N : Node_Id);
605 -- Activate the set of configuration pragmas and restrictions that
606 -- make up the Ravenscar Profile. N is the corresponding pragma
607 -- node, which is used for error messages on any constructs
608 -- that violate the profile.
610 --------------------------
611 -- Check_Ada_83_Warning --
612 --------------------------
614 procedure Check_Ada_83_Warning is
615 begin
616 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
617 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
618 end if;
619 end Check_Ada_83_Warning;
621 ---------------------
622 -- Check_Arg_Count --
623 ---------------------
625 procedure Check_Arg_Count (Required : Nat) is
626 begin
627 if Arg_Count /= Required then
628 Error_Pragma ("wrong number of arguments for pragma%");
629 end if;
630 end Check_Arg_Count;
632 --------------------------------
633 -- Check_Arg_Is_External_Name --
634 --------------------------------
636 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
637 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
639 begin
640 if Nkind (Argx) = N_Identifier then
641 return;
643 else
644 Analyze_And_Resolve (Argx, Standard_String);
646 if Is_OK_Static_Expression (Argx) then
647 return;
649 elsif Etype (Argx) = Any_Type then
650 raise Pragma_Exit;
652 -- An interesting special case, if we have a string literal and
653 -- we are in Ada 83 mode, then we allow it even though it will
654 -- not be flagged as static. This allows expected Ada 83 mode
655 -- use of external names which are string literals, even though
656 -- technically these are not static in Ada 83.
658 elsif Ada_Version = Ada_83
659 and then Nkind (Argx) = N_String_Literal
660 then
661 return;
663 -- Static expression that raises Constraint_Error. This has
664 -- already been flagged, so just exit from pragma processing.
666 elsif Is_Static_Expression (Argx) then
667 raise Pragma_Exit;
669 -- Here we have a real error (non-static expression)
671 else
672 Error_Msg_Name_1 := Chars (N);
673 Flag_Non_Static_Expr
674 ("argument for pragma% must be a identifier or " &
675 "static string expression!", Argx);
676 raise Pragma_Exit;
677 end if;
678 end if;
679 end Check_Arg_Is_External_Name;
681 -----------------------------
682 -- Check_Arg_Is_Identifier --
683 -----------------------------
685 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
686 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
687 begin
688 if Nkind (Argx) /= N_Identifier then
689 Error_Pragma_Arg
690 ("argument for pragma% must be identifier", Argx);
691 end if;
692 end Check_Arg_Is_Identifier;
694 ----------------------------------
695 -- Check_Arg_Is_Integer_Literal --
696 ----------------------------------
698 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
699 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
700 begin
701 if Nkind (Argx) /= N_Integer_Literal then
702 Error_Pragma_Arg
703 ("argument for pragma% must be integer literal", Argx);
704 end if;
705 end Check_Arg_Is_Integer_Literal;
707 -------------------------------------------
708 -- Check_Arg_Is_Library_Level_Local_Name --
709 -------------------------------------------
711 -- LOCAL_NAME ::=
712 -- DIRECT_NAME
713 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
714 -- | library_unit_NAME
716 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
717 begin
718 Check_Arg_Is_Local_Name (Arg);
720 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
721 and then Comes_From_Source (N)
722 then
723 Error_Pragma_Arg
724 ("argument for pragma% must be library level entity", Arg);
725 end if;
726 end Check_Arg_Is_Library_Level_Local_Name;
728 -----------------------------
729 -- Check_Arg_Is_Local_Name --
730 -----------------------------
732 -- LOCAL_NAME ::=
733 -- DIRECT_NAME
734 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
735 -- | library_unit_NAME
737 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
738 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
740 begin
741 Analyze (Argx);
743 if Nkind (Argx) not in N_Direct_Name
744 and then (Nkind (Argx) /= N_Attribute_Reference
745 or else Present (Expressions (Argx))
746 or else Nkind (Prefix (Argx)) /= N_Identifier)
747 and then (not Is_Entity_Name (Argx)
748 or else not Is_Compilation_Unit (Entity (Argx)))
749 then
750 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
751 end if;
753 if Is_Entity_Name (Argx)
754 and then Scope (Entity (Argx)) /= Current_Scope
755 then
756 Error_Pragma_Arg
757 ("pragma% argument must be in same declarative part", Arg);
758 end if;
759 end Check_Arg_Is_Local_Name;
761 ---------------------------------
762 -- Check_Arg_Is_Locking_Policy --
763 ---------------------------------
765 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
766 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
768 begin
769 Check_Arg_Is_Identifier (Argx);
771 if not Is_Locking_Policy_Name (Chars (Argx)) then
772 Error_Pragma_Arg
773 ("& is not a valid locking policy name", Argx);
774 end if;
775 end Check_Arg_Is_Locking_Policy;
777 -------------------------
778 -- Check_Arg_Is_One_Of --
779 -------------------------
781 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
782 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
784 begin
785 Check_Arg_Is_Identifier (Argx);
787 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
788 Error_Msg_Name_2 := N1;
789 Error_Msg_Name_3 := N2;
790 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
791 end if;
792 end Check_Arg_Is_One_Of;
794 procedure Check_Arg_Is_One_Of
795 (Arg : Node_Id;
796 N1, N2, N3 : Name_Id)
798 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
800 begin
801 Check_Arg_Is_Identifier (Argx);
803 if Chars (Argx) /= N1
804 and then Chars (Argx) /= N2
805 and then Chars (Argx) /= N3
806 then
807 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
808 end if;
809 end Check_Arg_Is_One_Of;
811 ---------------------------------
812 -- Check_Arg_Is_Queuing_Policy --
813 ---------------------------------
815 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
816 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
818 begin
819 Check_Arg_Is_Identifier (Argx);
821 if not Is_Queuing_Policy_Name (Chars (Argx)) then
822 Error_Pragma_Arg
823 ("& is not a valid queuing policy name", Argx);
824 end if;
825 end Check_Arg_Is_Queuing_Policy;
827 ------------------------------------
828 -- Check_Arg_Is_Static_Expression --
829 ------------------------------------
831 procedure Check_Arg_Is_Static_Expression
832 (Arg : Node_Id;
833 Typ : Entity_Id)
835 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
837 begin
838 Analyze_And_Resolve (Argx, Typ);
840 if Is_OK_Static_Expression (Argx) then
841 return;
843 elsif Etype (Argx) = Any_Type then
844 raise Pragma_Exit;
846 -- An interesting special case, if we have a string literal and
847 -- we are in Ada 83 mode, then we allow it even though it will
848 -- not be flagged as static. This allows the use of Ada 95
849 -- pragmas like Import in Ada 83 mode. They will of course be
850 -- flagged with warnings as usual, but will not cause errors.
852 elsif Ada_Version = Ada_83
853 and then Nkind (Argx) = N_String_Literal
854 then
855 return;
857 -- Static expression that raises Constraint_Error. This has
858 -- already been flagged, so just exit from pragma processing.
860 elsif Is_Static_Expression (Argx) then
861 raise Pragma_Exit;
863 -- Finally, we have a real error
865 else
866 Error_Msg_Name_1 := Chars (N);
867 Flag_Non_Static_Expr
868 ("argument for pragma% must be a static expression!", Argx);
869 raise Pragma_Exit;
870 end if;
871 end Check_Arg_Is_Static_Expression;
873 ---------------------------------
874 -- Check_Arg_Is_String_Literal --
875 ---------------------------------
877 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
878 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
880 begin
881 if Nkind (Argx) /= N_String_Literal then
882 Error_Pragma_Arg
883 ("argument for pragma% must be string literal", Argx);
884 end if;
886 end Check_Arg_Is_String_Literal;
888 ------------------------------------------
889 -- Check_Arg_Is_Task_Dispatching_Policy --
890 ------------------------------------------
892 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
893 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
895 begin
896 Check_Arg_Is_Identifier (Argx);
898 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
899 Error_Pragma_Arg
900 ("& is not a valid task dispatching policy name", Argx);
901 end if;
902 end Check_Arg_Is_Task_Dispatching_Policy;
904 --------------------------------
905 -- Check_At_Least_N_Arguments --
906 --------------------------------
908 procedure Check_At_Least_N_Arguments (N : Nat) is
909 begin
910 if Arg_Count < N then
911 Error_Pragma ("too few arguments for pragma%");
912 end if;
913 end Check_At_Least_N_Arguments;
915 -------------------------------
916 -- Check_At_Most_N_Arguments --
917 -------------------------------
919 procedure Check_At_Most_N_Arguments (N : Nat) is
920 Arg : Node_Id;
922 begin
923 if Arg_Count > N then
924 Arg := Arg1;
926 for J in 1 .. N loop
927 Next (Arg);
928 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
929 end loop;
930 end if;
931 end Check_At_Most_N_Arguments;
933 ---------------------
934 -- Check_Component --
935 ---------------------
937 procedure Check_Component (Comp : Node_Id) is
938 begin
939 if Nkind (Comp) = N_Component_Declaration then
940 declare
941 Sindic : constant Node_Id :=
942 Subtype_Indication (Component_Definition (Comp));
944 begin
945 if Nkind (Sindic) = N_Subtype_Indication then
947 -- Ada 2005 (AI-216): If a component subtype is subject to
948 -- a per-object constraint, then the component type shall
949 -- be an Unchecked_Union.
951 if Has_Per_Object_Constraint (Defining_Identifier (Comp))
952 and then
953 not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
954 then
955 Error_Msg_N ("component subtype subject to per-object" &
956 " constraint must be an Unchecked_Union", Comp);
957 end if;
958 end if;
959 end;
960 end if;
961 end Check_Component;
963 ----------------------------------
964 -- Check_Duplicated_Export_Name --
965 ----------------------------------
967 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
968 String_Val : constant String_Id := Strval (Nam);
970 begin
971 -- We are only interested in the export case, and in the case of
972 -- generics, it is the instance, not the template, that is the
973 -- problem (the template will generate a warning in any case).
975 if not Inside_A_Generic
976 and then (Prag_Id = Pragma_Export
977 or else
978 Prag_Id = Pragma_Export_Procedure
979 or else
980 Prag_Id = Pragma_Export_Valued_Procedure
981 or else
982 Prag_Id = Pragma_Export_Function)
983 then
984 for J in Externals.First .. Externals.Last loop
985 if String_Equal (String_Val, Strval (Externals.Table (J))) then
986 Error_Msg_Sloc := Sloc (Externals.Table (J));
987 Error_Msg_N ("external name duplicates name given#", Nam);
988 exit;
989 end if;
990 end loop;
992 Externals.Append (Nam);
993 end if;
994 end Check_Duplicated_Export_Name;
996 -------------------------
997 -- Check_First_Subtype --
998 -------------------------
1000 procedure Check_First_Subtype (Arg : Node_Id) is
1001 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1003 begin
1004 if not Is_First_Subtype (Entity (Argx)) then
1005 Error_Pragma_Arg
1006 ("pragma% cannot apply to subtype", Argx);
1007 end if;
1008 end Check_First_Subtype;
1010 ---------------------------
1011 -- Check_In_Main_Program --
1012 ---------------------------
1014 procedure Check_In_Main_Program is
1015 P : constant Node_Id := Parent (N);
1017 begin
1018 -- Must be at in subprogram body
1020 if Nkind (P) /= N_Subprogram_Body then
1021 Error_Pragma ("% pragma allowed only in subprogram");
1023 -- Otherwise warn if obviously not main program
1025 elsif Present (Parameter_Specifications (Specification (P)))
1026 or else not Is_Compilation_Unit (Defining_Entity (P))
1027 then
1028 Error_Msg_Name_1 := Chars (N);
1029 Error_Msg_N
1030 ("?pragma% is only effective in main program", N);
1031 end if;
1032 end Check_In_Main_Program;
1034 ---------------------------------------
1035 -- Check_Interrupt_Or_Attach_Handler --
1036 ---------------------------------------
1038 procedure Check_Interrupt_Or_Attach_Handler is
1039 Arg1_X : constant Node_Id := Expression (Arg1);
1041 begin
1042 Analyze (Arg1_X);
1044 if not Is_Entity_Name (Arg1_X) then
1045 Error_Pragma_Arg
1046 ("argument of pragma% must be entity name", Arg1);
1048 elsif Prag_Id = Pragma_Interrupt_Handler then
1049 Check_Restriction (No_Dynamic_Attachment, N);
1050 end if;
1052 declare
1053 Handler_Proc : Entity_Id := Empty;
1054 Proc_Scope : Entity_Id;
1055 Found : Boolean := False;
1057 begin
1058 if not Is_Overloaded (Arg1_X) then
1059 Handler_Proc := Entity (Arg1_X);
1061 else
1062 declare
1063 It : Interp;
1064 Index : Interp_Index;
1066 begin
1067 Get_First_Interp (Arg1_X, Index, It);
1068 while Present (It.Nam) loop
1069 Handler_Proc := It.Nam;
1071 if Ekind (Handler_Proc) = E_Procedure
1072 and then No (First_Formal (Handler_Proc))
1073 then
1074 if not Found then
1075 Found := True;
1076 Set_Entity (Arg1_X, Handler_Proc);
1077 Set_Is_Overloaded (Arg1_X, False);
1078 else
1079 Error_Pragma_Arg
1080 ("ambiguous handler name for pragma% ", Arg1);
1081 end if;
1082 end if;
1084 Get_Next_Interp (Index, It);
1085 end loop;
1087 if not Found then
1088 Error_Pragma_Arg
1089 ("argument of pragma% must be parameterless procedure",
1090 Arg1);
1091 else
1092 Handler_Proc := Entity (Arg1_X);
1093 end if;
1094 end;
1095 end if;
1097 Proc_Scope := Scope (Handler_Proc);
1099 -- On AAMP only, a pragma Interrupt_Handler is supported for
1100 -- nonprotected parameterless procedures.
1102 if AAMP_On_Target
1103 and then Prag_Id = Pragma_Interrupt_Handler
1104 then
1105 if Ekind (Handler_Proc) /= E_Procedure then
1106 Error_Pragma_Arg
1107 ("argument of pragma% must be a procedure", Arg1);
1108 end if;
1110 elsif Ekind (Handler_Proc) /= E_Procedure
1111 or else Ekind (Proc_Scope) /= E_Protected_Type
1112 then
1113 Error_Pragma_Arg
1114 ("argument of pragma% must be protected procedure", Arg1);
1115 end if;
1117 if (not AAMP_On_Target or else Prag_Id = Pragma_Attach_Handler)
1118 and then Ekind (Proc_Scope) = E_Protected_Type
1119 then
1120 if Parent (N) /=
1121 Protected_Definition (Parent (Proc_Scope))
1122 then
1123 Error_Pragma ("pragma% must be in protected definition");
1124 end if;
1125 end if;
1127 if not Is_Library_Level_Entity (Proc_Scope)
1128 or else (AAMP_On_Target
1129 and then not Is_Library_Level_Entity (Handler_Proc))
1130 then
1131 Error_Pragma_Arg
1132 ("pragma% requires library-level entity", Arg1);
1133 end if;
1135 if Present (First_Formal (Handler_Proc)) then
1136 Error_Pragma_Arg
1137 ("argument of pragma% must be parameterless procedure",
1138 Arg1);
1139 end if;
1140 end;
1141 end Check_Interrupt_Or_Attach_Handler;
1143 -------------------------------------------
1144 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1145 -------------------------------------------
1147 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1148 P : Node_Id;
1150 begin
1151 P := Parent (N);
1152 loop
1153 if No (P) then
1154 exit;
1156 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1157 exit;
1159 elsif Nkind (P) = N_Package_Specification then
1160 return;
1162 elsif Nkind (P) = N_Block_Statement then
1163 return;
1165 -- Note: the following tests seem a little peculiar, because
1166 -- they test for bodies, but if we were in the statement part
1167 -- of the body, we would already have hit the handled statement
1168 -- sequence, so the only way we get here is by being in the
1169 -- declarative part of the body.
1171 elsif Nkind (P) = N_Subprogram_Body
1172 or else Nkind (P) = N_Package_Body
1173 or else Nkind (P) = N_Task_Body
1174 or else Nkind (P) = N_Entry_Body
1175 then
1176 return;
1177 end if;
1179 P := Parent (P);
1180 end loop;
1182 Error_Pragma ("pragma% is not in declarative part or package spec");
1183 end Check_Is_In_Decl_Part_Or_Package_Spec;
1185 -------------------------
1186 -- Check_No_Identifier --
1187 -------------------------
1189 procedure Check_No_Identifier (Arg : Node_Id) is
1190 begin
1191 if Chars (Arg) /= No_Name then
1192 Error_Pragma_Arg_Ident
1193 ("pragma% does not permit identifier& here", Arg);
1194 end if;
1195 end Check_No_Identifier;
1197 --------------------------
1198 -- Check_No_Identifiers --
1199 --------------------------
1201 procedure Check_No_Identifiers is
1202 Arg_Node : Node_Id;
1204 begin
1205 if Arg_Count > 0 then
1206 Arg_Node := Arg1;
1208 while Present (Arg_Node) loop
1209 Check_No_Identifier (Arg_Node);
1210 Next (Arg_Node);
1211 end loop;
1212 end if;
1213 end Check_No_Identifiers;
1215 -------------------------------
1216 -- Check_Optional_Identifier --
1217 -------------------------------
1219 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1220 begin
1221 if Present (Arg) and then Chars (Arg) /= No_Name then
1222 if Chars (Arg) /= Id then
1223 Error_Msg_Name_1 := Chars (N);
1224 Error_Msg_Name_2 := Id;
1225 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1226 raise Pragma_Exit;
1227 end if;
1228 end if;
1229 end Check_Optional_Identifier;
1231 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1232 begin
1233 Name_Buffer (1 .. Id'Length) := Id;
1234 Name_Len := Id'Length;
1235 Check_Optional_Identifier (Arg, Name_Find);
1236 end Check_Optional_Identifier;
1238 -----------------------------
1239 -- Check_Static_Constraint --
1240 -----------------------------
1242 -- Note: for convenience in writing this procedure, in addition to
1243 -- the officially (i.e. by spec) allowed argument which is always
1244 -- a constraint, it also allows ranges and discriminant associations.
1245 -- Above is not clear ???
1247 procedure Check_Static_Constraint (Constr : Node_Id) is
1249 --------------------
1250 -- Require_Static --
1251 --------------------
1253 procedure Require_Static (E : Node_Id);
1254 -- Require given expression to be static expression
1256 procedure Require_Static (E : Node_Id) is
1257 begin
1258 if not Is_OK_Static_Expression (E) then
1259 Flag_Non_Static_Expr
1260 ("non-static constraint not allowed in Unchecked_Union!", E);
1261 raise Pragma_Exit;
1262 end if;
1263 end Require_Static;
1265 -- Start of processing for Check_Static_Constraint
1267 begin
1268 case Nkind (Constr) is
1269 when N_Discriminant_Association =>
1270 Require_Static (Expression (Constr));
1272 when N_Range =>
1273 Require_Static (Low_Bound (Constr));
1274 Require_Static (High_Bound (Constr));
1276 when N_Attribute_Reference =>
1277 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1278 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1280 when N_Range_Constraint =>
1281 Check_Static_Constraint (Range_Expression (Constr));
1283 when N_Index_Or_Discriminant_Constraint =>
1284 declare
1285 IDC : Entity_Id := First (Constraints (Constr));
1286 begin
1287 while Present (IDC) loop
1288 Check_Static_Constraint (IDC);
1289 Next (IDC);
1290 end loop;
1291 end;
1293 when others =>
1294 null;
1295 end case;
1296 end Check_Static_Constraint;
1298 --------------------------------------
1299 -- Check_Valid_Configuration_Pragma --
1300 --------------------------------------
1302 -- A configuration pragma must appear in the context clause of
1303 -- a compilation unit, at the start of the list (i.e. only other
1304 -- pragmas may precede it).
1306 procedure Check_Valid_Configuration_Pragma is
1307 begin
1308 if not Is_Configuration_Pragma then
1309 Error_Pragma ("incorrect placement for configuration pragma%");
1310 end if;
1311 end Check_Valid_Configuration_Pragma;
1313 -------------------------------------
1314 -- Check_Valid_Library_Unit_Pragma --
1315 -------------------------------------
1317 procedure Check_Valid_Library_Unit_Pragma is
1318 Plist : List_Id;
1319 Parent_Node : Node_Id;
1320 Unit_Name : Entity_Id;
1321 Unit_Kind : Node_Kind;
1322 Unit_Node : Node_Id;
1323 Sindex : Source_File_Index;
1325 begin
1326 if not Is_List_Member (N) then
1327 Pragma_Misplaced;
1329 else
1330 Plist := List_Containing (N);
1331 Parent_Node := Parent (Plist);
1333 if Parent_Node = Empty then
1334 Pragma_Misplaced;
1336 -- Case of pragma appearing after a compilation unit. In this
1337 -- case it must have an argument with the corresponding name
1338 -- and must be part of the following pragmas of its parent.
1340 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1341 if Plist /= Pragmas_After (Parent_Node) then
1342 Pragma_Misplaced;
1344 elsif Arg_Count = 0 then
1345 Error_Pragma
1346 ("argument required if outside compilation unit");
1348 else
1349 Check_No_Identifiers;
1350 Check_Arg_Count (1);
1351 Unit_Node := Unit (Parent (Parent_Node));
1352 Unit_Kind := Nkind (Unit_Node);
1354 Analyze (Expression (Arg1));
1356 if Unit_Kind = N_Generic_Subprogram_Declaration
1357 or else Unit_Kind = N_Subprogram_Declaration
1358 then
1359 Unit_Name := Defining_Entity (Unit_Node);
1361 elsif Unit_Kind = N_Function_Instantiation
1362 or else Unit_Kind = N_Package_Instantiation
1363 or else Unit_Kind = N_Procedure_Instantiation
1364 then
1365 Unit_Name := Defining_Entity (Unit_Node);
1367 else
1368 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1369 end if;
1371 if Chars (Unit_Name) /=
1372 Chars (Entity (Expression (Arg1)))
1373 then
1374 Error_Pragma_Arg
1375 ("pragma% argument is not current unit name", Arg1);
1376 end if;
1378 if Ekind (Unit_Name) = E_Package
1379 and then Present (Renamed_Entity (Unit_Name))
1380 then
1381 Error_Pragma ("pragma% not allowed for renamed package");
1382 end if;
1383 end if;
1385 -- Pragma appears other than after a compilation unit
1387 else
1388 -- Here we check for the generic instantiation case and also
1389 -- for the case of processing a generic formal package. We
1390 -- detect these cases by noting that the Sloc on the node
1391 -- does not belong to the current compilation unit.
1393 Sindex := Source_Index (Current_Sem_Unit);
1395 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1396 Rewrite (N, Make_Null_Statement (Loc));
1397 return;
1399 -- If before first declaration, the pragma applies to the
1400 -- enclosing unit, and the name if present must be this name.
1402 elsif Is_Before_First_Decl (N, Plist) then
1403 Unit_Node := Unit_Declaration_Node (Current_Scope);
1404 Unit_Kind := Nkind (Unit_Node);
1406 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1407 Pragma_Misplaced;
1409 elsif Unit_Kind = N_Subprogram_Body
1410 and then not Acts_As_Spec (Unit_Node)
1411 then
1412 Pragma_Misplaced;
1414 elsif Nkind (Parent_Node) = N_Package_Body then
1415 Pragma_Misplaced;
1417 elsif Nkind (Parent_Node) = N_Package_Specification
1418 and then Plist = Private_Declarations (Parent_Node)
1419 then
1420 Pragma_Misplaced;
1422 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1423 or else Nkind (Parent_Node)
1424 = N_Generic_Subprogram_Declaration)
1425 and then Plist = Generic_Formal_Declarations (Parent_Node)
1426 then
1427 Pragma_Misplaced;
1429 elsif Arg_Count > 0 then
1430 Analyze (Expression (Arg1));
1432 if Entity (Expression (Arg1)) /= Current_Scope then
1433 Error_Pragma_Arg
1434 ("name in pragma% must be enclosing unit", Arg1);
1435 end if;
1437 -- It is legal to have no argument in this context
1439 else
1440 return;
1441 end if;
1443 -- Error if not before first declaration. This is because a
1444 -- library unit pragma argument must be the name of a library
1445 -- unit (RM 10.1.5(7)), but the only names permitted in this
1446 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1447 -- generic subprogram declarations or generic instantiations.
1449 else
1450 Error_Pragma
1451 ("pragma% misplaced, must be before first declaration");
1452 end if;
1453 end if;
1454 end if;
1455 end Check_Valid_Library_Unit_Pragma;
1457 -------------------
1458 -- Check_Variant --
1459 -------------------
1461 procedure Check_Variant (Variant : Node_Id) is
1462 Clist : constant Node_Id := Component_List (Variant);
1463 Comp : Node_Id;
1465 begin
1466 if Present (Variant_Part (Clist)) then
1467 Error_Msg_N
1468 ("Unchecked_Union may not have nested variants",
1469 Variant_Part (Clist));
1470 end if;
1472 if not Is_Non_Empty_List (Component_Items (Clist)) then
1473 Error_Msg_N
1474 ("Unchecked_Union may not have empty component list",
1475 Variant);
1476 return;
1477 end if;
1479 Comp := First (Component_Items (Clist));
1480 while Present (Comp) loop
1482 Check_Component (Comp);
1483 Next (Comp);
1485 end loop;
1486 end Check_Variant;
1488 ------------------
1489 -- Error_Pragma --
1490 ------------------
1492 procedure Error_Pragma (Msg : String) is
1493 begin
1494 Error_Msg_Name_1 := Chars (N);
1495 Error_Msg_N (Msg, N);
1496 raise Pragma_Exit;
1497 end Error_Pragma;
1499 ----------------------
1500 -- Error_Pragma_Arg --
1501 ----------------------
1503 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1504 begin
1505 Error_Msg_Name_1 := Chars (N);
1506 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1507 raise Pragma_Exit;
1508 end Error_Pragma_Arg;
1510 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1511 begin
1512 Error_Msg_Name_1 := Chars (N);
1513 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1514 Error_Pragma_Arg (Msg2, Arg);
1515 end Error_Pragma_Arg;
1517 ----------------------------
1518 -- Error_Pragma_Arg_Ident --
1519 ----------------------------
1521 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1522 begin
1523 Error_Msg_Name_1 := Chars (N);
1524 Error_Msg_N (Msg, Arg);
1525 raise Pragma_Exit;
1526 end Error_Pragma_Arg_Ident;
1528 ------------------------
1529 -- Find_Lib_Unit_Name --
1530 ------------------------
1532 function Find_Lib_Unit_Name return Entity_Id is
1533 begin
1534 -- Return inner compilation unit entity, for case of nested
1535 -- categorization pragmas. This happens in generic unit.
1537 if Nkind (Parent (N)) = N_Package_Specification
1538 and then Defining_Entity (Parent (N)) /= Current_Scope
1539 then
1540 return Defining_Entity (Parent (N));
1541 else
1542 return Current_Scope;
1543 end if;
1544 end Find_Lib_Unit_Name;
1546 ----------------------------
1547 -- Find_Program_Unit_Name --
1548 ----------------------------
1550 procedure Find_Program_Unit_Name (Id : Node_Id) is
1551 Unit_Name : Entity_Id;
1552 Unit_Kind : Node_Kind;
1553 P : constant Node_Id := Parent (N);
1555 begin
1556 if Nkind (P) = N_Compilation_Unit then
1557 Unit_Kind := Nkind (Unit (P));
1559 if Unit_Kind = N_Subprogram_Declaration
1560 or else Unit_Kind = N_Package_Declaration
1561 or else Unit_Kind in N_Generic_Declaration
1562 then
1563 Unit_Name := Defining_Entity (Unit (P));
1565 if Chars (Id) = Chars (Unit_Name) then
1566 Set_Entity (Id, Unit_Name);
1567 Set_Etype (Id, Etype (Unit_Name));
1568 else
1569 Set_Etype (Id, Any_Type);
1570 Error_Pragma
1571 ("cannot find program unit referenced by pragma%");
1572 end if;
1574 else
1575 Set_Etype (Id, Any_Type);
1576 Error_Pragma ("pragma% inapplicable to this unit");
1577 end if;
1579 else
1580 Analyze (Id);
1581 end if;
1583 end Find_Program_Unit_Name;
1585 -------------------------
1586 -- Gather_Associations --
1587 -------------------------
1589 procedure Gather_Associations
1590 (Names : Name_List;
1591 Args : out Args_List)
1593 Arg : Node_Id;
1595 begin
1596 -- Initialize all parameters to Empty
1598 for J in Args'Range loop
1599 Args (J) := Empty;
1600 end loop;
1602 -- That's all we have to do if there are no argument associations
1604 if No (Pragma_Argument_Associations (N)) then
1605 return;
1606 end if;
1608 -- Otherwise first deal with any positional parameters present
1610 Arg := First (Pragma_Argument_Associations (N));
1612 for Index in Args'Range loop
1613 exit when No (Arg) or else Chars (Arg) /= No_Name;
1614 Args (Index) := Expression (Arg);
1615 Next (Arg);
1616 end loop;
1618 -- Positional parameters all processed, if any left, then we
1619 -- have too many positional parameters.
1621 if Present (Arg) and then Chars (Arg) = No_Name then
1622 Error_Pragma_Arg
1623 ("too many positional associations for pragma%", Arg);
1624 end if;
1626 -- Process named parameters if any are present
1628 while Present (Arg) loop
1629 if Chars (Arg) = No_Name then
1630 Error_Pragma_Arg
1631 ("positional association cannot follow named association",
1632 Arg);
1634 else
1635 for Index in Names'Range loop
1636 if Names (Index) = Chars (Arg) then
1637 if Present (Args (Index)) then
1638 Error_Pragma_Arg
1639 ("duplicate argument association for pragma%", Arg);
1640 else
1641 Args (Index) := Expression (Arg);
1642 exit;
1643 end if;
1644 end if;
1646 if Index = Names'Last then
1647 Error_Msg_Name_1 := Chars (N);
1648 Error_Msg_N ("pragma% does not allow & argument", Arg);
1650 -- Check for possible misspelling
1652 for Index1 in Names'Range loop
1653 if Is_Bad_Spelling_Of
1654 (Get_Name_String (Chars (Arg)),
1655 Get_Name_String (Names (Index1)))
1656 then
1657 Error_Msg_Name_1 := Names (Index1);
1658 Error_Msg_N ("\possible misspelling of%", Arg);
1659 exit;
1660 end if;
1661 end loop;
1663 raise Pragma_Exit;
1664 end if;
1665 end loop;
1666 end if;
1668 Next (Arg);
1669 end loop;
1670 end Gather_Associations;
1672 --------------------
1673 -- Get_Pragma_Arg --
1674 --------------------
1676 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
1677 begin
1678 if Nkind (Arg) = N_Pragma_Argument_Association then
1679 return Expression (Arg);
1680 else
1681 return Arg;
1682 end if;
1683 end Get_Pragma_Arg;
1685 -----------------
1686 -- GNAT_Pragma --
1687 -----------------
1689 procedure GNAT_Pragma is
1690 begin
1691 Check_Restriction (No_Implementation_Pragmas, N);
1692 end GNAT_Pragma;
1694 --------------------------
1695 -- Is_Before_First_Decl --
1696 --------------------------
1698 function Is_Before_First_Decl
1699 (Pragma_Node : Node_Id;
1700 Decls : List_Id) return Boolean
1702 Item : Node_Id := First (Decls);
1704 begin
1705 -- Only other pragmas can come before this pragma
1707 loop
1708 if No (Item) or else Nkind (Item) /= N_Pragma then
1709 return False;
1711 elsif Item = Pragma_Node then
1712 return True;
1713 end if;
1715 Next (Item);
1716 end loop;
1717 end Is_Before_First_Decl;
1719 -----------------------------
1720 -- Is_Configuration_Pragma --
1721 -----------------------------
1723 -- A configuration pragma must appear in the context clause of
1724 -- a compilation unit, at the start of the list (i.e. only other
1725 -- pragmas may precede it).
1727 function Is_Configuration_Pragma return Boolean is
1728 Lis : constant List_Id := List_Containing (N);
1729 Par : constant Node_Id := Parent (N);
1730 Prg : Node_Id;
1732 begin
1733 -- If no parent, then we are in the configuration pragma file,
1734 -- so the placement is definitely appropriate.
1736 if No (Par) then
1737 return True;
1739 -- Otherwise we must be in the context clause of a compilation unit
1740 -- and the only thing allowed before us in the context list is more
1741 -- configuration pragmas.
1743 elsif Nkind (Par) = N_Compilation_Unit
1744 and then Context_Items (Par) = Lis
1745 then
1746 Prg := First (Lis);
1748 loop
1749 if Prg = N then
1750 return True;
1751 elsif Nkind (Prg) /= N_Pragma then
1752 return False;
1753 end if;
1755 Next (Prg);
1756 end loop;
1758 else
1759 return False;
1760 end if;
1761 end Is_Configuration_Pragma;
1763 ----------------------
1764 -- Pragma_Misplaced --
1765 ----------------------
1767 procedure Pragma_Misplaced is
1768 begin
1769 Error_Pragma ("incorrect placement of pragma%");
1770 end Pragma_Misplaced;
1772 ------------------------------------
1773 -- Process Atomic_Shared_Volatile --
1774 ------------------------------------
1776 procedure Process_Atomic_Shared_Volatile is
1777 E_Id : Node_Id;
1778 E : Entity_Id;
1779 D : Node_Id;
1780 K : Node_Kind;
1781 Utyp : Entity_Id;
1783 procedure Set_Atomic (E : Entity_Id);
1784 -- Set given type as atomic, and if no explicit alignment was
1785 -- given, set alignment to unknown, since back end knows what
1786 -- the alignment requirements are for atomic arrays. Note that
1787 -- this step is necessary for derived types.
1789 ----------------
1790 -- Set_Atomic --
1791 ----------------
1793 procedure Set_Atomic (E : Entity_Id) is
1794 begin
1795 Set_Is_Atomic (E);
1797 if not Has_Alignment_Clause (E) then
1798 Set_Alignment (E, Uint_0);
1799 end if;
1800 end Set_Atomic;
1802 -- Start of processing for Process_Atomic_Shared_Volatile
1804 begin
1805 Check_Ada_83_Warning;
1806 Check_No_Identifiers;
1807 Check_Arg_Count (1);
1808 Check_Arg_Is_Local_Name (Arg1);
1809 E_Id := Expression (Arg1);
1811 if Etype (E_Id) = Any_Type then
1812 return;
1813 end if;
1815 E := Entity (E_Id);
1816 D := Declaration_Node (E);
1817 K := Nkind (D);
1819 if Is_Type (E) then
1820 if Rep_Item_Too_Early (E, N)
1821 or else
1822 Rep_Item_Too_Late (E, N)
1823 then
1824 return;
1825 else
1826 Check_First_Subtype (Arg1);
1827 end if;
1829 if Prag_Id /= Pragma_Volatile then
1830 Set_Atomic (E);
1831 Set_Atomic (Underlying_Type (E));
1832 Set_Atomic (Base_Type (E));
1833 end if;
1835 -- Attribute belongs on the base type. If the
1836 -- view of the type is currently private, it also
1837 -- belongs on the underlying type.
1839 Set_Is_Volatile (Base_Type (E));
1840 Set_Is_Volatile (Underlying_Type (E));
1842 Set_Treat_As_Volatile (E);
1843 Set_Treat_As_Volatile (Underlying_Type (E));
1845 elsif K = N_Object_Declaration
1846 or else (K = N_Component_Declaration
1847 and then Original_Record_Component (E) = E)
1848 then
1849 if Rep_Item_Too_Late (E, N) then
1850 return;
1851 end if;
1853 if Prag_Id /= Pragma_Volatile then
1854 Set_Is_Atomic (E);
1856 -- If the object declaration has an explicit
1857 -- initialization, a temporary may have to be
1858 -- created to hold the expression, to insure
1859 -- that access to the object remain atomic.
1861 if Nkind (Parent (E)) = N_Object_Declaration
1862 and then Present (Expression (Parent (E)))
1863 then
1864 Set_Has_Delayed_Freeze (E);
1865 end if;
1867 -- An interesting improvement here. If an object of type X
1868 -- is declared atomic, and the type X is not atomic, that's
1869 -- a pity, since it may not have appropraite alignment etc.
1870 -- We can rescue this in the special case where the object
1871 -- and type are in the same unit by just setting the type
1872 -- as atomic, so that the back end will process it as atomic.
1874 Utyp := Underlying_Type (Etype (E));
1876 if Present (Utyp)
1877 and then Sloc (E) > No_Location
1878 and then Sloc (Utyp) > No_Location
1879 and then
1880 Get_Source_File_Index (Sloc (E)) =
1881 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
1882 then
1883 Set_Is_Atomic (Underlying_Type (Etype (E)));
1884 end if;
1885 end if;
1887 Set_Is_Volatile (E);
1888 Set_Treat_As_Volatile (E);
1890 else
1891 Error_Pragma_Arg
1892 ("inappropriate entity for pragma%", Arg1);
1893 end if;
1894 end Process_Atomic_Shared_Volatile;
1896 ------------------------
1897 -- Process_Convention --
1898 ------------------------
1900 procedure Process_Convention
1901 (C : out Convention_Id;
1902 E : out Entity_Id)
1904 Id : Node_Id;
1905 E1 : Entity_Id;
1906 Cname : Name_Id;
1907 Comp_Unit : Unit_Number_Type;
1909 procedure Set_Convention_From_Pragma (E : Entity_Id);
1910 -- Set convention in entity E, and also flag that the entity has a
1911 -- convention pragma. If entity is for a private or incomplete type,
1912 -- also set convention and flag on underlying type. This procedure
1913 -- also deals with the special case of C_Pass_By_Copy convention.
1915 --------------------------------
1916 -- Set_Convention_From_Pragma --
1917 --------------------------------
1919 procedure Set_Convention_From_Pragma (E : Entity_Id) is
1920 begin
1921 Set_Convention (E, C);
1922 Set_Has_Convention_Pragma (E);
1924 if Is_Incomplete_Or_Private_Type (E) then
1925 Set_Convention (Underlying_Type (E), C);
1926 Set_Has_Convention_Pragma (Underlying_Type (E), True);
1927 end if;
1929 -- A class-wide type should inherit the convention of
1930 -- the specific root type (although this isn't specified
1931 -- clearly by the RM).
1933 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
1934 Set_Convention (Class_Wide_Type (E), C);
1935 end if;
1937 -- If the entity is a record type, then check for special case
1938 -- of C_Pass_By_Copy, which is treated the same as C except that
1939 -- the special record flag is set. This convention is also only
1940 -- permitted on record types (see AI95-00131).
1942 if Cname = Name_C_Pass_By_Copy then
1943 if Is_Record_Type (E) then
1944 Set_C_Pass_By_Copy (Base_Type (E));
1945 elsif Is_Incomplete_Or_Private_Type (E)
1946 and then Is_Record_Type (Underlying_Type (E))
1947 then
1948 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
1949 else
1950 Error_Pragma_Arg
1951 ("C_Pass_By_Copy convention allowed only for record type",
1952 Arg2);
1953 end if;
1954 end if;
1956 -- If the entity is a derived boolean type, check for the
1957 -- special case of convention C, C++, or Fortran, where we
1958 -- consider any nonzero value to represent true.
1960 if Is_Discrete_Type (E)
1961 and then Root_Type (Etype (E)) = Standard_Boolean
1962 and then
1963 (C = Convention_C
1964 or else
1965 C = Convention_CPP
1966 or else
1967 C = Convention_Fortran)
1968 then
1969 Set_Nonzero_Is_True (Base_Type (E));
1970 end if;
1971 end Set_Convention_From_Pragma;
1973 -- Start of processing for Process_Convention
1975 begin
1976 Check_At_Least_N_Arguments (2);
1977 Check_Arg_Is_Identifier (Arg1);
1978 Check_Optional_Identifier (Arg1, Name_Convention);
1979 Cname := Chars (Expression (Arg1));
1981 -- C_Pass_By_Copy is treated as a synonym for convention C
1982 -- (this is tested again below to set the critical flag)
1984 if Cname = Name_C_Pass_By_Copy then
1985 C := Convention_C;
1987 -- Otherwise we must have something in the standard convention list
1989 elsif Is_Convention_Name (Cname) then
1990 C := Get_Convention_Id (Chars (Expression (Arg1)));
1992 -- In DEC VMS, it seems that there is an undocumented feature
1993 -- that any unrecognized convention is treated as the default,
1994 -- which for us is convention C. It does not seem so terrible
1995 -- to do this unconditionally, silently in the VMS case, and
1996 -- with a warning in the non-VMS case.
1998 else
1999 if Warn_On_Export_Import and not OpenVMS_On_Target then
2000 Error_Msg_N
2001 ("?unrecognized convention name, C assumed",
2002 Expression (Arg1));
2003 end if;
2005 C := Convention_C;
2006 end if;
2008 Check_Arg_Is_Local_Name (Arg2);
2009 Check_Optional_Identifier (Arg2, Name_Entity);
2011 Id := Expression (Arg2);
2012 Analyze (Id);
2014 if not Is_Entity_Name (Id) then
2015 Error_Pragma_Arg ("entity name required", Arg2);
2016 end if;
2018 E := Entity (Id);
2020 -- Go to renamed subprogram if present, since convention applies
2021 -- to the actual renamed entity, not to the renaming entity.
2023 if Is_Subprogram (E)
2024 and then Present (Alias (E))
2025 and then Nkind (Parent (Declaration_Node (E))) =
2026 N_Subprogram_Renaming_Declaration
2027 then
2028 E := Alias (E);
2029 end if;
2031 -- Check that we not applying this to a specless body
2033 if Is_Subprogram (E)
2034 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2035 then
2036 Error_Pragma
2037 ("pragma% requires separate spec and must come before body");
2038 end if;
2040 -- Check that we are not applying this to a named constant
2042 if Ekind (E) = E_Named_Integer
2043 or else
2044 Ekind (E) = E_Named_Real
2045 then
2046 Error_Msg_Name_1 := Chars (N);
2047 Error_Msg_N
2048 ("cannot apply pragma% to named constant!",
2049 Get_Pragma_Arg (Arg2));
2050 Error_Pragma_Arg
2051 ("\supply appropriate type for&!", Arg2);
2052 end if;
2054 if Etype (E) = Any_Type
2055 or else Rep_Item_Too_Early (E, N)
2056 then
2057 raise Pragma_Exit;
2058 else
2059 E := Underlying_Type (E);
2060 end if;
2062 if Rep_Item_Too_Late (E, N) then
2063 raise Pragma_Exit;
2064 end if;
2066 if Has_Convention_Pragma (E) then
2067 Error_Pragma_Arg
2068 ("at most one Convention/Export/Import pragma is allowed", Arg2);
2070 elsif Convention (E) = Convention_Protected
2071 or else Ekind (Scope (E)) = E_Protected_Type
2072 then
2073 Error_Pragma_Arg
2074 ("a protected operation cannot be given a different convention",
2075 Arg2);
2076 end if;
2078 -- For Intrinsic, a subprogram is required
2080 if C = Convention_Intrinsic
2081 and then not Is_Subprogram (E)
2082 and then not Is_Generic_Subprogram (E)
2083 then
2084 Error_Pragma_Arg
2085 ("second argument of pragma% must be a subprogram", Arg2);
2086 end if;
2088 -- For Stdcall, a subprogram, variable or subprogram type is required
2090 if C = Convention_Stdcall
2091 and then not Is_Subprogram (E)
2092 and then not Is_Generic_Subprogram (E)
2093 and then Ekind (E) /= E_Variable
2094 and then not
2095 (Is_Access_Type (E)
2096 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2097 then
2098 Error_Pragma_Arg
2099 ("second argument of pragma% must be subprogram (type)",
2100 Arg2);
2101 end if;
2103 if not Is_Subprogram (E)
2104 and then not Is_Generic_Subprogram (E)
2105 then
2106 Set_Convention_From_Pragma (E);
2108 if Is_Type (E) then
2110 Check_First_Subtype (Arg2);
2111 Set_Convention_From_Pragma (Base_Type (E));
2113 -- For subprograms, we must set the convention on the
2114 -- internally generated directly designated type as well.
2116 if Ekind (E) = E_Access_Subprogram_Type then
2117 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2118 end if;
2119 end if;
2121 -- For the subprogram case, set proper convention for all homonyms
2122 -- in same scope and the same declarative part, i.e. the same
2123 -- compilation unit.
2125 else
2126 Comp_Unit := Get_Source_Unit (E);
2127 Set_Convention_From_Pragma (E);
2129 -- Treat a pragma Import as an implicit body, for GPS use.
2131 if Prag_Id = Pragma_Import then
2132 Generate_Reference (E, Id, 'b');
2133 end if;
2135 E1 := E;
2136 loop
2137 E1 := Homonym (E1);
2138 exit when No (E1) or else Scope (E1) /= Current_Scope;
2140 -- Note: below we are missing a check for Rep_Item_Too_Late.
2141 -- That is deliberate, we cannot chain the rep item on more
2142 -- than one Rep_Item chain, to be fixed later ???
2144 if Comes_From_Source (E1)
2145 and then Comp_Unit = Get_Source_Unit (E1)
2146 and then Nkind (Original_Node (Parent (E1))) /=
2147 N_Full_Type_Declaration
2148 then
2149 Set_Convention_From_Pragma (E1);
2151 if Prag_Id = Pragma_Import then
2152 Generate_Reference (E, Id, 'b');
2153 end if;
2154 end if;
2155 end loop;
2156 end if;
2157 end Process_Convention;
2159 -----------------------------------------------------
2160 -- Process_Extended_Import_Export_Exception_Pragma --
2161 -----------------------------------------------------
2163 procedure Process_Extended_Import_Export_Exception_Pragma
2164 (Arg_Internal : Node_Id;
2165 Arg_External : Node_Id;
2166 Arg_Form : Node_Id;
2167 Arg_Code : Node_Id)
2169 Def_Id : Entity_Id;
2170 Code_Val : Uint;
2172 begin
2173 GNAT_Pragma;
2175 if not OpenVMS_On_Target then
2176 Error_Pragma
2177 ("?pragma% ignored (applies only to Open'V'M'S)");
2178 end if;
2180 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2181 Def_Id := Entity (Arg_Internal);
2183 if Ekind (Def_Id) /= E_Exception then
2184 Error_Pragma_Arg
2185 ("pragma% must refer to declared exception", Arg_Internal);
2186 end if;
2188 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2190 if Present (Arg_Form) then
2191 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2192 end if;
2194 if Present (Arg_Form)
2195 and then Chars (Arg_Form) = Name_Ada
2196 then
2197 null;
2198 else
2199 Set_Is_VMS_Exception (Def_Id);
2200 Set_Exception_Code (Def_Id, No_Uint);
2201 end if;
2203 if Present (Arg_Code) then
2204 if not Is_VMS_Exception (Def_Id) then
2205 Error_Pragma_Arg
2206 ("Code option for pragma% not allowed for Ada case",
2207 Arg_Code);
2208 end if;
2210 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2211 Code_Val := Expr_Value (Arg_Code);
2213 if not UI_Is_In_Int_Range (Code_Val) then
2214 Error_Pragma_Arg
2215 ("Code option for pragma% must be in 32-bit range",
2216 Arg_Code);
2218 else
2219 Set_Exception_Code (Def_Id, Code_Val);
2220 end if;
2221 end if;
2222 end Process_Extended_Import_Export_Exception_Pragma;
2224 -------------------------------------------------
2225 -- Process_Extended_Import_Export_Internal_Arg --
2226 -------------------------------------------------
2228 procedure Process_Extended_Import_Export_Internal_Arg
2229 (Arg_Internal : Node_Id := Empty)
2231 begin
2232 GNAT_Pragma;
2234 if No (Arg_Internal) then
2235 Error_Pragma ("Internal parameter required for pragma%");
2236 end if;
2238 if Nkind (Arg_Internal) = N_Identifier then
2239 null;
2241 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2242 and then (Prag_Id = Pragma_Import_Function
2243 or else
2244 Prag_Id = Pragma_Export_Function)
2245 then
2246 null;
2248 else
2249 Error_Pragma_Arg
2250 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2251 end if;
2253 Check_Arg_Is_Local_Name (Arg_Internal);
2254 end Process_Extended_Import_Export_Internal_Arg;
2256 --------------------------------------------------
2257 -- Process_Extended_Import_Export_Object_Pragma --
2258 --------------------------------------------------
2260 procedure Process_Extended_Import_Export_Object_Pragma
2261 (Arg_Internal : Node_Id;
2262 Arg_External : Node_Id;
2263 Arg_Size : Node_Id)
2265 Def_Id : Entity_Id;
2267 begin
2268 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2269 Def_Id := Entity (Arg_Internal);
2271 if Ekind (Def_Id) /= E_Constant
2272 and then Ekind (Def_Id) /= E_Variable
2273 then
2274 Error_Pragma_Arg
2275 ("pragma% must designate an object", Arg_Internal);
2276 end if;
2278 if Is_Psected (Def_Id) then
2279 Error_Pragma_Arg
2280 ("previous Psect_Object applies, pragma % not permitted",
2281 Arg_Internal);
2282 end if;
2284 if Rep_Item_Too_Late (Def_Id, N) then
2285 raise Pragma_Exit;
2286 end if;
2288 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2290 if Present (Arg_Size) then
2291 Check_Arg_Is_External_Name (Arg_Size);
2292 end if;
2294 -- Export_Object case
2296 if Prag_Id = Pragma_Export_Object then
2297 if not Is_Library_Level_Entity (Def_Id) then
2298 Error_Pragma_Arg
2299 ("argument for pragma% must be library level entity",
2300 Arg_Internal);
2301 end if;
2303 if Ekind (Current_Scope) = E_Generic_Package then
2304 Error_Pragma ("pragma& cannot appear in a generic unit");
2305 end if;
2307 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2308 Error_Pragma_Arg
2309 ("exported object must have compile time known size",
2310 Arg_Internal);
2311 end if;
2313 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2314 Error_Msg_N
2315 ("?duplicate Export_Object pragma", N);
2316 else
2317 Set_Exported (Def_Id, Arg_Internal);
2318 end if;
2320 -- Import_Object case
2322 else
2323 if Is_Concurrent_Type (Etype (Def_Id)) then
2324 Error_Pragma_Arg
2325 ("cannot use pragma% for task/protected object",
2326 Arg_Internal);
2327 end if;
2329 if Ekind (Def_Id) = E_Constant then
2330 Error_Pragma_Arg
2331 ("cannot import a constant", Arg_Internal);
2332 end if;
2334 if Warn_On_Export_Import
2335 and then Has_Discriminants (Etype (Def_Id))
2336 then
2337 Error_Msg_N
2338 ("imported value must be initialized?", Arg_Internal);
2339 end if;
2341 if Warn_On_Export_Import
2342 and then Is_Access_Type (Etype (Def_Id))
2343 then
2344 Error_Pragma_Arg
2345 ("cannot import object of an access type?", Arg_Internal);
2346 end if;
2348 if Warn_On_Export_Import
2349 and then Is_Imported (Def_Id)
2350 then
2351 Error_Msg_N
2352 ("?duplicate Import_Object pragma", N);
2354 -- Check for explicit initialization present. Note that an
2355 -- initialization that generated by the code generator, e.g.
2356 -- for an access type, does not count here.
2358 elsif Present (Expression (Parent (Def_Id)))
2359 and then
2360 Comes_From_Source
2361 (Original_Node (Expression (Parent (Def_Id))))
2362 then
2363 Error_Msg_Sloc := Sloc (Def_Id);
2364 Error_Pragma_Arg
2365 ("no initialization allowed for declaration of& #",
2366 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2367 Arg1);
2368 else
2369 Set_Imported (Def_Id);
2370 Note_Possible_Modification (Arg_Internal);
2371 end if;
2372 end if;
2373 end Process_Extended_Import_Export_Object_Pragma;
2375 ------------------------------------------------------
2376 -- Process_Extended_Import_Export_Subprogram_Pragma --
2377 ------------------------------------------------------
2379 procedure Process_Extended_Import_Export_Subprogram_Pragma
2380 (Arg_Internal : Node_Id;
2381 Arg_External : Node_Id;
2382 Arg_Parameter_Types : Node_Id;
2383 Arg_Result_Type : Node_Id := Empty;
2384 Arg_Mechanism : Node_Id;
2385 Arg_Result_Mechanism : Node_Id := Empty;
2386 Arg_First_Optional_Parameter : Node_Id := Empty)
2388 Ent : Entity_Id;
2389 Def_Id : Entity_Id;
2390 Hom_Id : Entity_Id;
2391 Formal : Entity_Id;
2392 Ambiguous : Boolean;
2393 Match : Boolean;
2394 Dval : Node_Id;
2396 function Same_Base_Type
2397 (Ptype : Node_Id;
2398 Formal : Entity_Id) return Boolean;
2399 -- Determines if Ptype references the type of Formal. Note that
2400 -- only the base types need to match according to the spec. Ptype
2401 -- here is the argument from the pragma, which is either a type
2402 -- name, or an access attribute.
2404 --------------------
2405 -- Same_Base_Type --
2406 --------------------
2408 function Same_Base_Type
2409 (Ptype : Node_Id;
2410 Formal : Entity_Id) return Boolean
2412 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2413 Pref : Node_Id;
2415 begin
2416 -- Case where pragma argument is typ'Access
2418 if Nkind (Ptype) = N_Attribute_Reference
2419 and then Attribute_Name (Ptype) = Name_Access
2420 then
2421 Pref := Prefix (Ptype);
2422 Find_Type (Pref);
2424 if not Is_Entity_Name (Pref)
2425 or else Entity (Pref) = Any_Type
2426 then
2427 raise Pragma_Exit;
2428 end if;
2430 -- We have a match if the corresponding argument is of an
2431 -- anonymous access type, and its designicated type matches
2432 -- the type of the prefix of the access attribute
2434 return Ekind (Ftyp) = E_Anonymous_Access_Type
2435 and then Base_Type (Entity (Pref)) =
2436 Base_Type (Etype (Designated_Type (Ftyp)));
2438 -- Case where pragma argument is a type name
2440 else
2441 Find_Type (Ptype);
2443 if not Is_Entity_Name (Ptype)
2444 or else Entity (Ptype) = Any_Type
2445 then
2446 raise Pragma_Exit;
2447 end if;
2449 -- We have a match if the corresponding argument is of
2450 -- the type given in the pragma (comparing base types)
2452 return Base_Type (Entity (Ptype)) = Ftyp;
2453 end if;
2454 end Same_Base_Type;
2456 -- Start of processing for
2457 -- Process_Extended_Import_Export_Subprogram_Pragma
2459 begin
2460 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2461 Hom_Id := Entity (Arg_Internal);
2462 Ent := Empty;
2463 Ambiguous := False;
2465 -- Loop through homonyms (overloadings) of Hom_Id
2467 while Present (Hom_Id) loop
2468 Def_Id := Get_Base_Subprogram (Hom_Id);
2470 -- We need a subprogram in the current scope
2472 if not Is_Subprogram (Def_Id)
2473 or else Scope (Def_Id) /= Current_Scope
2474 then
2475 null;
2477 else
2478 Match := True;
2480 -- Pragma cannot apply to subprogram body
2482 if Is_Subprogram (Def_Id)
2483 and then
2484 Nkind (Parent
2485 (Declaration_Node (Def_Id))) = N_Subprogram_Body
2486 then
2487 Error_Pragma
2488 ("pragma% requires separate spec"
2489 & " and must come before body");
2490 end if;
2492 -- Test result type if given, note that the result type
2493 -- parameter can only be present for the function cases.
2495 if Present (Arg_Result_Type)
2496 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2497 then
2498 Match := False;
2500 elsif Etype (Def_Id) /= Standard_Void_Type
2501 and then
2502 (Chars (N) = Name_Export_Procedure
2503 or else Chars (N) = Name_Import_Procedure)
2504 then
2505 Match := False;
2507 -- Test parameter types if given. Note that this parameter
2508 -- has not been analyzed (and must not be, since it is
2509 -- semantic nonsense), so we get it as the parser left it.
2511 elsif Present (Arg_Parameter_Types) then
2512 Check_Matching_Types : declare
2513 Formal : Entity_Id;
2514 Ptype : Node_Id;
2516 begin
2517 Formal := First_Formal (Def_Id);
2519 if Nkind (Arg_Parameter_Types) = N_Null then
2520 if Present (Formal) then
2521 Match := False;
2522 end if;
2524 -- A list of one type, e.g. (List) is parsed as
2525 -- a parenthesized expression.
2527 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
2528 and then Paren_Count (Arg_Parameter_Types) = 1
2529 then
2530 if No (Formal)
2531 or else Present (Next_Formal (Formal))
2532 then
2533 Match := False;
2534 else
2535 Match :=
2536 Same_Base_Type (Arg_Parameter_Types, Formal);
2537 end if;
2539 -- A list of more than one type is parsed as a aggregate
2541 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
2542 and then Paren_Count (Arg_Parameter_Types) = 0
2543 then
2544 Ptype := First (Expressions (Arg_Parameter_Types));
2545 while Present (Ptype) or else Present (Formal) loop
2546 if No (Ptype)
2547 or else No (Formal)
2548 or else not Same_Base_Type (Ptype, Formal)
2549 then
2550 Match := False;
2551 exit;
2552 else
2553 Next_Formal (Formal);
2554 Next (Ptype);
2555 end if;
2556 end loop;
2558 -- Anything else is of the wrong form
2560 else
2561 Error_Pragma_Arg
2562 ("wrong form for Parameter_Types parameter",
2563 Arg_Parameter_Types);
2564 end if;
2565 end Check_Matching_Types;
2566 end if;
2568 -- Match is now False if the entry we found did not match
2569 -- either a supplied Parameter_Types or Result_Types argument
2571 if Match then
2572 if No (Ent) then
2573 Ent := Def_Id;
2575 -- Ambiguous case, the flag Ambiguous shows if we already
2576 -- detected this and output the initial messages.
2578 else
2579 if not Ambiguous then
2580 Ambiguous := True;
2581 Error_Msg_Name_1 := Chars (N);
2582 Error_Msg_N
2583 ("pragma% does not uniquely identify subprogram!",
2585 Error_Msg_Sloc := Sloc (Ent);
2586 Error_Msg_N ("matching subprogram #!", N);
2587 Ent := Empty;
2588 end if;
2590 Error_Msg_Sloc := Sloc (Def_Id);
2591 Error_Msg_N ("matching subprogram #!", N);
2592 end if;
2593 end if;
2594 end if;
2596 Hom_Id := Homonym (Hom_Id);
2597 end loop;
2599 -- See if we found an entry
2601 if No (Ent) then
2602 if not Ambiguous then
2603 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
2604 Error_Pragma
2605 ("pragma% cannot be given for generic subprogram");
2607 else
2608 Error_Pragma
2609 ("pragma% does not identify local subprogram");
2610 end if;
2611 end if;
2613 return;
2614 end if;
2616 -- Import pragmas must be be for imported entities
2618 if Prag_Id = Pragma_Import_Function
2619 or else
2620 Prag_Id = Pragma_Import_Procedure
2621 or else
2622 Prag_Id = Pragma_Import_Valued_Procedure
2623 then
2624 if not Is_Imported (Ent) then
2625 Error_Pragma
2626 ("pragma Import or Interface must precede pragma%");
2627 end if;
2629 -- Here we have the Export case which can set the entity as exported
2631 -- But does not do so if the specified external name is null,
2632 -- since that is taken as a signal in DEC Ada 83 (with which
2633 -- we want to be compatible) to request no external name.
2635 elsif Nkind (Arg_External) = N_String_Literal
2636 and then String_Length (Strval (Arg_External)) = 0
2637 then
2638 null;
2640 -- In all other cases, set entit as exported
2642 else
2643 Set_Exported (Ent, Arg_Internal);
2644 end if;
2646 -- Special processing for Valued_Procedure cases
2648 if Prag_Id = Pragma_Import_Valued_Procedure
2649 or else
2650 Prag_Id = Pragma_Export_Valued_Procedure
2651 then
2652 Formal := First_Formal (Ent);
2654 if No (Formal) then
2655 Error_Pragma
2656 ("at least one parameter required for pragma%");
2658 elsif Ekind (Formal) /= E_Out_Parameter then
2659 Error_Pragma
2660 ("first parameter must have mode out for pragma%");
2662 else
2663 Set_Is_Valued_Procedure (Ent);
2664 end if;
2665 end if;
2667 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
2669 -- Process Result_Mechanism argument if present. We have already
2670 -- checked that this is only allowed for the function case.
2672 if Present (Arg_Result_Mechanism) then
2673 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
2674 end if;
2676 -- Process Mechanism parameter if present. Note that this parameter
2677 -- is not analyzed, and must not be analyzed since it is semantic
2678 -- nonsense, so we get it in exactly as the parser left it.
2680 if Present (Arg_Mechanism) then
2681 declare
2682 Formal : Entity_Id;
2683 Massoc : Node_Id;
2684 Mname : Node_Id;
2685 Choice : Node_Id;
2687 begin
2688 -- A single mechanism association without a formal parameter
2689 -- name is parsed as a parenthesized expression. All other
2690 -- cases are parsed as aggregates, so we rewrite the single
2691 -- parameter case as an aggregate for consistency.
2693 if Nkind (Arg_Mechanism) /= N_Aggregate
2694 and then Paren_Count (Arg_Mechanism) = 1
2695 then
2696 Rewrite (Arg_Mechanism,
2697 Make_Aggregate (Sloc (Arg_Mechanism),
2698 Expressions => New_List (
2699 Relocate_Node (Arg_Mechanism))));
2700 end if;
2702 -- Case of only mechanism name given, applies to all formals
2704 if Nkind (Arg_Mechanism) /= N_Aggregate then
2705 Formal := First_Formal (Ent);
2706 while Present (Formal) loop
2707 Set_Mechanism_Value (Formal, Arg_Mechanism);
2708 Next_Formal (Formal);
2709 end loop;
2711 -- Case of list of mechanism associations given
2713 else
2714 if Null_Record_Present (Arg_Mechanism) then
2715 Error_Pragma_Arg
2716 ("inappropriate form for Mechanism parameter",
2717 Arg_Mechanism);
2718 end if;
2720 -- Deal with positional ones first
2722 Formal := First_Formal (Ent);
2723 if Present (Expressions (Arg_Mechanism)) then
2724 Mname := First (Expressions (Arg_Mechanism));
2726 while Present (Mname) loop
2727 if No (Formal) then
2728 Error_Pragma_Arg
2729 ("too many mechanism associations", Mname);
2730 end if;
2732 Set_Mechanism_Value (Formal, Mname);
2733 Next_Formal (Formal);
2734 Next (Mname);
2735 end loop;
2736 end if;
2738 -- Deal with named entries
2740 if Present (Component_Associations (Arg_Mechanism)) then
2741 Massoc := First (Component_Associations (Arg_Mechanism));
2743 while Present (Massoc) loop
2744 Choice := First (Choices (Massoc));
2746 if Nkind (Choice) /= N_Identifier
2747 or else Present (Next (Choice))
2748 then
2749 Error_Pragma_Arg
2750 ("incorrect form for mechanism association",
2751 Massoc);
2752 end if;
2754 Formal := First_Formal (Ent);
2755 loop
2756 if No (Formal) then
2757 Error_Pragma_Arg
2758 ("parameter name & not present", Choice);
2759 end if;
2761 if Chars (Choice) = Chars (Formal) then
2762 Set_Mechanism_Value
2763 (Formal, Expression (Massoc));
2764 exit;
2765 end if;
2767 Next_Formal (Formal);
2768 end loop;
2770 Next (Massoc);
2771 end loop;
2772 end if;
2773 end if;
2774 end;
2775 end if;
2777 -- Process First_Optional_Parameter argument if present. We have
2778 -- already checked that this is only allowed for the Import case.
2780 if Present (Arg_First_Optional_Parameter) then
2781 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
2782 Error_Pragma_Arg
2783 ("first optional parameter must be formal parameter name",
2784 Arg_First_Optional_Parameter);
2785 end if;
2787 Formal := First_Formal (Ent);
2788 loop
2789 if No (Formal) then
2790 Error_Pragma_Arg
2791 ("specified formal parameter& not found",
2792 Arg_First_Optional_Parameter);
2793 end if;
2795 exit when Chars (Formal) =
2796 Chars (Arg_First_Optional_Parameter);
2798 Next_Formal (Formal);
2799 end loop;
2801 Set_First_Optional_Parameter (Ent, Formal);
2803 -- Check specified and all remaining formals have right form
2805 while Present (Formal) loop
2806 if Ekind (Formal) /= E_In_Parameter then
2807 Error_Msg_NE
2808 ("optional formal& is not of mode in!",
2809 Arg_First_Optional_Parameter, Formal);
2811 else
2812 Dval := Default_Value (Formal);
2814 if not Present (Dval) then
2815 Error_Msg_NE
2816 ("optional formal& does not have default value!",
2817 Arg_First_Optional_Parameter, Formal);
2819 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
2820 null;
2822 else
2823 Error_Msg_FE
2824 ("default value for optional formal& is non-static!",
2825 Arg_First_Optional_Parameter, Formal);
2826 end if;
2827 end if;
2829 Set_Is_Optional_Parameter (Formal);
2830 Next_Formal (Formal);
2831 end loop;
2832 end if;
2833 end Process_Extended_Import_Export_Subprogram_Pragma;
2835 --------------------------
2836 -- Process_Generic_List --
2837 --------------------------
2839 procedure Process_Generic_List is
2840 Arg : Node_Id;
2841 Exp : Node_Id;
2843 begin
2844 GNAT_Pragma;
2845 Check_No_Identifiers;
2846 Check_At_Least_N_Arguments (1);
2848 Arg := Arg1;
2849 while Present (Arg) loop
2850 Exp := Expression (Arg);
2851 Analyze (Exp);
2853 if not Is_Entity_Name (Exp)
2854 or else
2855 (not Is_Generic_Instance (Entity (Exp))
2856 and then
2857 not Is_Generic_Unit (Entity (Exp)))
2858 then
2859 Error_Pragma_Arg
2860 ("pragma% argument must be name of generic unit/instance",
2861 Arg);
2862 end if;
2864 Next (Arg);
2865 end loop;
2866 end Process_Generic_List;
2868 ---------------------------------
2869 -- Process_Import_Or_Interface --
2870 ---------------------------------
2872 procedure Process_Import_Or_Interface is
2873 C : Convention_Id;
2874 Def_Id : Entity_Id;
2875 Hom_Id : Entity_Id;
2877 begin
2878 Process_Convention (C, Def_Id);
2879 Kill_Size_Check_Code (Def_Id);
2880 Note_Possible_Modification (Expression (Arg2));
2882 if Ekind (Def_Id) = E_Variable
2883 or else
2884 Ekind (Def_Id) = E_Constant
2885 then
2886 -- User initialization is not allowed for imported object, but
2887 -- the object declaration may contain a default initialization,
2888 -- that will be discarded. Note that an explicit initialization
2889 -- only counts if it comes from source, otherwise it is simply
2890 -- the code generator making an implicit initialization explicit.
2892 if Present (Expression (Parent (Def_Id)))
2893 and then Comes_From_Source (Expression (Parent (Def_Id)))
2894 then
2895 Error_Msg_Sloc := Sloc (Def_Id);
2896 Error_Pragma_Arg
2897 ("no initialization allowed for declaration of& #",
2898 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2899 Arg2);
2901 else
2902 Set_Imported (Def_Id);
2903 Set_Is_Public (Def_Id);
2904 Process_Interface_Name (Def_Id, Arg3, Arg4);
2906 -- pragma Import completes deferred constants
2908 if Ekind (Def_Id) = E_Constant then
2909 Set_Has_Completion (Def_Id);
2910 end if;
2912 -- It is not possible to import a constant of an unconstrained
2913 -- array type (e.g. string) because there is no simple way to
2914 -- write a meaningful subtype for it.
2916 if Is_Array_Type (Etype (Def_Id))
2917 and then not Is_Constrained (Etype (Def_Id))
2918 then
2919 Error_Msg_NE
2920 ("imported constant& must have a constrained subtype",
2921 N, Def_Id);
2922 end if;
2923 end if;
2925 elsif Is_Subprogram (Def_Id)
2926 or else Is_Generic_Subprogram (Def_Id)
2927 then
2928 -- If the name is overloaded, pragma applies to all of the
2929 -- denoted entities in the same declarative part.
2931 Hom_Id := Def_Id;
2933 while Present (Hom_Id) loop
2934 Def_Id := Get_Base_Subprogram (Hom_Id);
2936 -- Ignore inherited subprograms because the pragma will
2937 -- apply to the parent operation, which is the one called.
2939 if Is_Overloadable (Def_Id)
2940 and then Present (Alias (Def_Id))
2941 then
2942 null;
2944 -- If it is not a subprogram, it must be in an outer
2945 -- scope and pragma does not apply.
2947 elsif not Is_Subprogram (Def_Id)
2948 and then not Is_Generic_Subprogram (Def_Id)
2949 then
2950 null;
2952 -- Verify that the homonym is in the same declarative
2953 -- part (not just the same scope).
2955 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
2956 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
2957 then
2958 exit;
2960 else
2961 Set_Imported (Def_Id);
2963 -- If Import intrinsic, set intrinsic flag
2964 -- and verify that it is known as such.
2966 if C = Convention_Intrinsic then
2967 Set_Is_Intrinsic_Subprogram (Def_Id);
2968 Check_Intrinsic_Subprogram
2969 (Def_Id, Expression (Arg2));
2970 end if;
2972 -- All interfaced procedures need an external
2973 -- symbol created for them since they are
2974 -- always referenced from another object file.
2976 Set_Is_Public (Def_Id);
2978 -- Verify that the subprogram does not have a completion
2979 -- through a renaming declaration. For other completions
2980 -- the pragma appears as a too late representation.
2982 declare
2983 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
2985 begin
2986 if Present (Decl)
2987 and then Nkind (Decl) = N_Subprogram_Declaration
2988 and then Present (Corresponding_Body (Decl))
2989 and then
2990 Nkind
2991 (Unit_Declaration_Node
2992 (Corresponding_Body (Decl))) =
2993 N_Subprogram_Renaming_Declaration
2994 then
2995 Error_Msg_Sloc := Sloc (Def_Id);
2996 Error_Msg_NE ("cannot import&#," &
2997 " already completed by a renaming",
2998 N, Def_Id);
2999 end if;
3000 end;
3002 Set_Has_Completion (Def_Id);
3003 Process_Interface_Name (Def_Id, Arg3, Arg4);
3004 end if;
3006 if Is_Compilation_Unit (Hom_Id) then
3008 -- Its possible homonyms are not affected by the pragma.
3009 -- Such homonyms might be present in the context of other
3010 -- units being compiled.
3012 exit;
3014 else
3015 Hom_Id := Homonym (Hom_Id);
3016 end if;
3017 end loop;
3019 -- When the convention is Java, we also allow Import to be given
3020 -- for packages, exceptions, and record components.
3022 elsif C = Convention_Java
3023 and then
3024 (Ekind (Def_Id) = E_Package
3025 or else Ekind (Def_Id) = E_Exception
3026 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3027 then
3028 Set_Imported (Def_Id);
3029 Set_Is_Public (Def_Id);
3030 Process_Interface_Name (Def_Id, Arg3, Arg4);
3032 else
3033 Error_Pragma_Arg
3034 ("second argument of pragma% must be object or subprogram",
3035 Arg2);
3036 end if;
3038 -- If this pragma applies to a compilation unit, then the unit,
3039 -- which is a subprogram, does not require (or allow) a body.
3040 -- We also do not need to elaborate imported procedures.
3042 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3043 declare
3044 Cunit : constant Node_Id := Parent (Parent (N));
3045 begin
3046 Set_Body_Required (Cunit, False);
3047 end;
3048 end if;
3049 end Process_Import_Or_Interface;
3051 --------------------
3052 -- Process_Inline --
3053 --------------------
3055 procedure Process_Inline (Active : Boolean) is
3056 Assoc : Node_Id;
3057 Decl : Node_Id;
3058 Subp_Id : Node_Id;
3059 Subp : Entity_Id;
3060 Applies : Boolean;
3061 Effective : Boolean := False;
3063 procedure Make_Inline (Subp : Entity_Id);
3064 -- Subp is the defining unit name of the subprogram
3065 -- declaration. Set the flag, as well as the flag in the
3066 -- corresponding body, if there is one present.
3068 procedure Set_Inline_Flags (Subp : Entity_Id);
3069 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp
3071 function Cannot_Inline (Subp : Entity_Id) return Boolean;
3072 -- Do not set the inline flag if body is available and contains
3073 -- exception handlers, to prevent undefined symbols at link time.
3074 -- Emit warning if front-end inlining is enabled and the pragma
3075 -- appears too late.
3077 -------------------
3078 -- Cannot_Inline --
3079 -------------------
3081 function Cannot_Inline (Subp : Entity_Id) return Boolean is
3082 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3084 begin
3085 if Nkind (Decl) = N_Subprogram_Body then
3086 return
3087 Present
3088 (Exception_Handlers (Handled_Statement_Sequence (Decl)));
3090 elsif Nkind (Decl) = N_Subprogram_Declaration
3091 and then Present (Corresponding_Body (Decl))
3092 then
3093 if Front_End_Inlining
3094 and then Analyzed (Corresponding_Body (Decl))
3095 then
3096 Error_Msg_N ("pragma appears too late, ignored?", N);
3097 return True;
3099 -- If the subprogram is a renaming as body, the body is
3100 -- just a call to the renamed subprogram, and inlining is
3101 -- trivially possible.
3103 elsif
3104 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
3105 = N_Subprogram_Renaming_Declaration
3106 then
3107 return False;
3109 else
3110 return
3111 Present (Exception_Handlers
3112 (Handled_Statement_Sequence
3113 (Unit_Declaration_Node (Corresponding_Body (Decl)))));
3114 end if;
3115 else
3116 -- If body is not available, assume the best, the check is
3117 -- performed again when compiling enclosing package bodies.
3119 return False;
3120 end if;
3121 end Cannot_Inline;
3123 -----------------
3124 -- Make_Inline --
3125 -----------------
3127 procedure Make_Inline (Subp : Entity_Id) is
3128 Kind : constant Entity_Kind := Ekind (Subp);
3129 Inner_Subp : Entity_Id := Subp;
3131 begin
3132 if Etype (Subp) = Any_Type then
3133 return;
3135 elsif Cannot_Inline (Subp) then
3136 Applies := True; -- Do not treat as an error.
3137 return;
3139 -- Here we have a candidate for inlining, but we must exclude
3140 -- derived operations. Otherwise we will end up trying to
3141 -- inline a phantom declaration, and the result would be to
3142 -- drag in a body which has no direct inlining associated with
3143 -- it. That would not only be inefficient but would also result
3144 -- in the backend doing cross-unit inlining in cases where it
3145 -- was definitely inappropriate to do so.
3147 -- However, a simple Comes_From_Source test is insufficient,
3148 -- since we do want to allow inlining of generic instances,
3149 -- which also do not come from source. Predefined operators do
3150 -- not come from source but are not inlineable either.
3152 elsif not Comes_From_Source (Subp)
3153 and then not Is_Generic_Instance (Subp)
3154 and then Scope (Subp) /= Standard_Standard
3155 then
3156 Applies := True;
3157 return;
3159 -- The referenced entity must either be the enclosing entity,
3160 -- or an entity declared within the current open scope.
3162 elsif Present (Scope (Subp))
3163 and then Scope (Subp) /= Current_Scope
3164 and then Subp /= Current_Scope
3165 then
3166 Error_Pragma_Arg
3167 ("argument of% must be entity in current scope", Assoc);
3168 return;
3169 end if;
3171 -- Processing for procedure, operator or function.
3172 -- If subprogram is aliased (as for an instance) indicate
3173 -- that the renamed entity (if declared in the same unit)
3174 -- is inlined.
3176 if Is_Subprogram (Subp) then
3177 while Present (Alias (Inner_Subp)) loop
3178 Inner_Subp := Alias (Inner_Subp);
3179 end loop;
3181 if In_Same_Source_Unit (Subp, Inner_Subp) then
3182 Set_Inline_Flags (Inner_Subp);
3184 Decl := Parent (Parent (Inner_Subp));
3186 if Nkind (Decl) = N_Subprogram_Declaration
3187 and then Present (Corresponding_Body (Decl))
3188 then
3189 Set_Inline_Flags (Corresponding_Body (Decl));
3190 end if;
3191 end if;
3193 Applies := True;
3195 -- For a generic subprogram set flag as well, for use at
3196 -- the point of instantiation, to determine whether the
3197 -- body should be generated.
3199 elsif Is_Generic_Subprogram (Subp) then
3200 Set_Inline_Flags (Subp);
3201 Applies := True;
3203 -- Literals are by definition inlined
3205 elsif Kind = E_Enumeration_Literal then
3206 null;
3208 -- Anything else is an error
3210 else
3211 Error_Pragma_Arg
3212 ("expect subprogram name for pragma%", Assoc);
3213 end if;
3214 end Make_Inline;
3216 ----------------------
3217 -- Set_Inline_Flags --
3218 ----------------------
3220 procedure Set_Inline_Flags (Subp : Entity_Id) is
3221 begin
3222 if Active then
3223 Set_Is_Inlined (Subp, True);
3224 end if;
3226 if not Has_Pragma_Inline (Subp) then
3227 Set_Has_Pragma_Inline (Subp);
3228 Set_Next_Rep_Item (N, First_Rep_Item (Subp));
3229 Set_First_Rep_Item (Subp, N);
3230 Effective := True;
3231 end if;
3232 end Set_Inline_Flags;
3234 -- Start of processing for Process_Inline
3236 begin
3237 Check_No_Identifiers;
3238 Check_At_Least_N_Arguments (1);
3240 if Active then
3241 Inline_Processing_Required := True;
3242 end if;
3244 Assoc := Arg1;
3245 while Present (Assoc) loop
3246 Subp_Id := Expression (Assoc);
3247 Analyze (Subp_Id);
3248 Applies := False;
3250 if Is_Entity_Name (Subp_Id) then
3251 Subp := Entity (Subp_Id);
3253 if Subp = Any_Id then
3254 Applies := True;
3256 else
3257 Make_Inline (Subp);
3259 while Present (Homonym (Subp))
3260 and then Scope (Homonym (Subp)) = Current_Scope
3261 loop
3262 Make_Inline (Homonym (Subp));
3263 Subp := Homonym (Subp);
3264 end loop;
3265 end if;
3266 end if;
3268 if not Applies then
3269 Error_Pragma_Arg
3270 ("inappropriate argument for pragma%", Assoc);
3272 elsif not Effective
3273 and then Warn_On_Redundant_Constructs
3274 then
3275 Error_Msg_NE ("pragma inline on& is redundant?",
3276 N, Entity (Subp_Id));
3277 end if;
3279 Next (Assoc);
3280 end loop;
3281 end Process_Inline;
3283 ----------------------------
3284 -- Process_Interface_Name --
3285 ----------------------------
3287 procedure Process_Interface_Name
3288 (Subprogram_Def : Entity_Id;
3289 Ext_Arg : Node_Id;
3290 Link_Arg : Node_Id)
3292 Ext_Nam : Node_Id;
3293 Link_Nam : Node_Id;
3294 String_Val : String_Id;
3296 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
3297 -- SN is a string literal node for an interface name. This routine
3298 -- performs some minimal checks that the name is reasonable. In
3299 -- particular that no spaces or other obviously incorrect characters
3300 -- appear. This is only a warning, since any characters are allowed.
3302 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
3303 S : constant String_Id := Strval (Expr_Value_S (SN));
3304 SL : constant Nat := String_Length (S);
3305 C : Char_Code;
3307 begin
3308 if SL = 0 then
3309 Error_Msg_N ("interface name cannot be null string", SN);
3310 end if;
3312 for J in 1 .. SL loop
3313 C := Get_String_Char (S, J);
3315 if Warn_On_Export_Import
3316 and then (not In_Character_Range (C)
3317 or else Get_Character (C) = ' '
3318 or else Get_Character (C) = ',')
3319 then
3320 Error_Msg_N
3321 ("?interface name contains illegal character", SN);
3322 end if;
3323 end loop;
3324 end Check_Form_Of_Interface_Name;
3326 -- Start of processing for Process_Interface_Name
3328 begin
3329 if No (Link_Arg) then
3330 if No (Ext_Arg) then
3331 return;
3333 elsif Chars (Ext_Arg) = Name_Link_Name then
3334 Ext_Nam := Empty;
3335 Link_Nam := Expression (Ext_Arg);
3337 else
3338 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3339 Ext_Nam := Expression (Ext_Arg);
3340 Link_Nam := Empty;
3341 end if;
3343 else
3344 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3345 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
3346 Ext_Nam := Expression (Ext_Arg);
3347 Link_Nam := Expression (Link_Arg);
3348 end if;
3350 -- Check expressions for external name and link name are static
3352 if Present (Ext_Nam) then
3353 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
3354 Check_Form_Of_Interface_Name (Ext_Nam);
3356 -- Verify that the external name is not the name of a local
3357 -- entity, which would hide the imported one and lead to
3358 -- run-time surprises. The problem can only arise for entities
3359 -- declared in a package body (otherwise the external name is
3360 -- fully qualified and won't conflict).
3362 declare
3363 Nam : Name_Id;
3364 E : Entity_Id;
3365 Par : Node_Id;
3367 begin
3368 if Prag_Id = Pragma_Import then
3369 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
3370 Nam := Name_Find;
3371 E := Entity_Id (Get_Name_Table_Info (Nam));
3373 if Nam /= Chars (Subprogram_Def)
3374 and then Present (E)
3375 and then not Is_Overloadable (E)
3376 and then Is_Immediately_Visible (E)
3377 and then not Is_Imported (E)
3378 and then Ekind (Scope (E)) = E_Package
3379 then
3380 Par := Parent (E);
3382 while Present (Par) loop
3383 if Nkind (Par) = N_Package_Body then
3384 Error_Msg_Sloc := Sloc (E);
3385 Error_Msg_NE
3386 ("imported entity is hidden by & declared#",
3387 Ext_Arg, E);
3388 exit;
3389 end if;
3391 Par := Parent (Par);
3392 end loop;
3393 end if;
3394 end if;
3395 end;
3396 end if;
3398 if Present (Link_Nam) then
3399 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
3400 Check_Form_Of_Interface_Name (Link_Nam);
3401 end if;
3403 -- If there is no link name, just set the external name
3405 if No (Link_Nam) then
3406 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
3408 -- For the Link_Name case, the given literal is preceded by an
3409 -- asterisk, which indicates to GCC that the given name should
3410 -- be taken literally, and in particular that no prepending of
3411 -- underlines should occur, even in systems where this is the
3412 -- normal default.
3414 else
3415 Start_String;
3416 Store_String_Char (Get_Char_Code ('*'));
3417 String_Val := Strval (Expr_Value_S (Link_Nam));
3419 for J in 1 .. String_Length (String_Val) loop
3420 Store_String_Char (Get_String_Char (String_Val, J));
3421 end loop;
3423 Link_Nam :=
3424 Make_String_Literal (Sloc (Link_Nam), End_String);
3425 end if;
3427 Set_Encoded_Interface_Name
3428 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
3429 Check_Duplicated_Export_Name (Link_Nam);
3430 end Process_Interface_Name;
3432 -----------------------------------------
3433 -- Process_Interrupt_Or_Attach_Handler --
3434 -----------------------------------------
3436 procedure Process_Interrupt_Or_Attach_Handler is
3437 Arg1_X : constant Node_Id := Expression (Arg1);
3438 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
3439 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
3441 begin
3442 Set_Is_Interrupt_Handler (Handler_Proc);
3444 -- If the pragma is not associated with a handler procedure
3445 -- within a protected type, then it must be for a nonprotected
3446 -- procedure for the AAMP target, in which case we don't
3447 -- associate a representation item with the procedure's scope.
3449 if Ekind (Proc_Scope) = E_Protected_Type then
3450 if Prag_Id = Pragma_Interrupt_Handler
3451 or else
3452 Prag_Id = Pragma_Attach_Handler
3453 then
3454 Record_Rep_Item (Proc_Scope, N);
3455 end if;
3456 end if;
3457 end Process_Interrupt_Or_Attach_Handler;
3459 --------------------------------------------------
3460 -- Process_Restrictions_Or_Restriction_Warnings --
3461 --------------------------------------------------
3463 procedure Process_Restrictions_Or_Restriction_Warnings is
3464 Arg : Node_Id;
3465 R_Id : Restriction_Id;
3466 Id : Name_Id;
3467 Expr : Node_Id;
3468 Val : Uint;
3470 procedure Set_Warning (R : All_Restrictions);
3471 -- If this is a Restriction_Warnings pragma, set warning flag,
3472 -- otherwise reset the flag.
3474 -----------------
3475 -- Set_Warning --
3476 -----------------
3478 procedure Set_Warning (R : All_Restrictions) is
3479 begin
3480 if Prag_Id = Pragma_Restriction_Warnings then
3481 Restriction_Warnings (R) := True;
3482 else
3483 Restriction_Warnings (R) := False;
3484 end if;
3485 end Set_Warning;
3487 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
3489 begin
3490 Check_Ada_83_Warning;
3491 Check_At_Least_N_Arguments (1);
3492 Check_Valid_Configuration_Pragma;
3494 Arg := Arg1;
3495 while Present (Arg) loop
3496 Id := Chars (Arg);
3497 Expr := Expression (Arg);
3499 -- Case of no restriction identifier present
3501 if Id = No_Name then
3502 if Nkind (Expr) /= N_Identifier then
3503 Error_Pragma_Arg
3504 ("invalid form for restriction", Arg);
3505 end if;
3507 R_Id :=
3508 Get_Restriction_Id
3509 (Process_Restriction_Synonyms (Expr));
3511 if R_Id not in All_Boolean_Restrictions then
3512 Error_Pragma_Arg
3513 ("invalid restriction identifier", Arg);
3514 end if;
3516 if Implementation_Restriction (R_Id) then
3517 Check_Restriction
3518 (No_Implementation_Restrictions, Arg);
3519 end if;
3521 Set_Restriction (R_Id, N);
3522 Set_Warning (R_Id);
3524 -- A very special case that must be processed here:
3525 -- pragma Restrictions (No_Exceptions) turns off
3526 -- all run-time checking. This is a bit dubious in
3527 -- terms of the formal language definition, but it
3528 -- is what is intended by RM H.4(12).
3530 if R_Id = No_Exceptions then
3531 Scope_Suppress := (others => True);
3532 end if;
3534 -- Case of restriction identifier present
3536 else
3537 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
3538 Analyze_And_Resolve (Expr, Any_Integer);
3540 if R_Id not in All_Parameter_Restrictions then
3541 Error_Pragma_Arg
3542 ("invalid restriction parameter identifier", Arg);
3544 elsif not Is_OK_Static_Expression (Expr) then
3545 Flag_Non_Static_Expr
3546 ("value must be static expression!", Expr);
3547 raise Pragma_Exit;
3549 elsif not Is_Integer_Type (Etype (Expr))
3550 or else Expr_Value (Expr) < 0
3551 then
3552 Error_Pragma_Arg
3553 ("value must be non-negative integer", Arg);
3555 -- Restriction pragma is active
3557 else
3558 Val := Expr_Value (Expr);
3560 if not UI_Is_In_Int_Range (Val) then
3561 Error_Pragma_Arg
3562 ("pragma ignored, value too large?", Arg);
3563 else
3564 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
3565 Set_Warning (R_Id);
3566 end if;
3567 end if;
3568 end if;
3570 Next (Arg);
3571 end loop;
3572 end Process_Restrictions_Or_Restriction_Warnings;
3574 ---------------------------------
3575 -- Process_Suppress_Unsuppress --
3576 ---------------------------------
3578 -- Note: this procedure makes entries in the check suppress data
3579 -- structures managed by Sem. See spec of package Sem for full
3580 -- details on how we handle recording of check suppression.
3582 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
3583 C : Check_Id;
3584 E_Id : Node_Id;
3585 E : Entity_Id;
3587 In_Package_Spec : constant Boolean :=
3588 (Ekind (Current_Scope) = E_Package
3589 or else
3590 Ekind (Current_Scope) = E_Generic_Package)
3591 and then not In_Package_Body (Current_Scope);
3593 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
3594 -- Used to suppress a single check on the given entity
3596 --------------------------------
3597 -- Suppress_Unsuppress_Echeck --
3598 --------------------------------
3600 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
3601 ESR : constant Entity_Check_Suppress_Record :=
3602 (Entity => E,
3603 Check => C,
3604 Suppress => Suppress_Case);
3606 begin
3607 Set_Checks_May_Be_Suppressed (E);
3609 if In_Package_Spec then
3610 Global_Entity_Suppress.Append (ESR);
3611 else
3612 Local_Entity_Suppress.Append (ESR);
3613 end if;
3615 -- If this is a first subtype, and the base type is distinct,
3616 -- then also set the suppress flags on the base type.
3618 if Is_First_Subtype (E)
3619 and then Etype (E) /= E
3620 then
3621 Suppress_Unsuppress_Echeck (Etype (E), C);
3622 end if;
3623 end Suppress_Unsuppress_Echeck;
3625 -- Start of processing for Process_Suppress_Unsuppress
3627 begin
3628 -- Suppress/Unsuppress can appear as a configuration pragma,
3629 -- or in a declarative part or a package spec (RM 11.5(5))
3631 if not Is_Configuration_Pragma then
3632 Check_Is_In_Decl_Part_Or_Package_Spec;
3633 end if;
3635 Check_At_Least_N_Arguments (1);
3636 Check_At_Most_N_Arguments (2);
3637 Check_No_Identifier (Arg1);
3638 Check_Arg_Is_Identifier (Arg1);
3640 if not Is_Check_Name (Chars (Expression (Arg1))) then
3641 Error_Pragma_Arg
3642 ("argument of pragma% is not valid check name", Arg1);
3643 else
3644 C := Get_Check_Id (Chars (Expression (Arg1)));
3645 end if;
3647 if Arg_Count = 1 then
3649 -- Make an entry in the local scope suppress table. This is the
3650 -- table that directly shows the current value of the scope
3651 -- suppress check for any check id value.
3653 if C = All_Checks then
3654 for J in Scope_Suppress'Range loop
3655 Scope_Suppress (J) := Suppress_Case;
3656 end loop;
3657 else
3658 Scope_Suppress (C) := Suppress_Case;
3659 end if;
3661 -- Also make an entry in the Local_Entity_Suppress table. See
3662 -- extended description in the package spec of Sem for details.
3664 Local_Entity_Suppress.Append
3665 ((Entity => Empty,
3666 Check => C,
3667 Suppress => Suppress_Case));
3669 -- Case of two arguments present, where the check is
3670 -- suppressed for a specified entity (given as the second
3671 -- argument of the pragma)
3673 else
3674 Check_Optional_Identifier (Arg2, Name_On);
3675 E_Id := Expression (Arg2);
3676 Analyze (E_Id);
3678 if not Is_Entity_Name (E_Id) then
3679 Error_Pragma_Arg
3680 ("second argument of pragma% must be entity name", Arg2);
3681 end if;
3683 E := Entity (E_Id);
3685 if E = Any_Id then
3686 return;
3687 end if;
3689 -- Enforce RM 11.5(7) which requires that for a pragma that
3690 -- appears within a package spec, the named entity must be
3691 -- within the package spec. We allow the package name itself
3692 -- to be mentioned since that makes sense, although it is not
3693 -- strictly allowed by 11.5(7).
3695 if In_Package_Spec
3696 and then E /= Current_Scope
3697 and then Scope (E) /= Current_Scope
3698 then
3699 Error_Pragma_Arg
3700 ("entity in pragma% is not in package spec ('R'M 11.5(7))",
3701 Arg2);
3702 end if;
3704 -- Loop through homonyms. As noted below, in the case of a package
3705 -- spec, only homonyms within the package spec are considered.
3707 loop
3708 Suppress_Unsuppress_Echeck (E, C);
3710 if Is_Generic_Instance (E)
3711 and then Is_Subprogram (E)
3712 and then Present (Alias (E))
3713 then
3714 Suppress_Unsuppress_Echeck (Alias (E), C);
3715 end if;
3717 -- Move to next homonym
3719 E := Homonym (E);
3720 exit when No (E);
3722 -- If we are within a package specification, the
3723 -- pragma only applies to homonyms in the same scope.
3725 exit when In_Package_Spec
3726 and then Scope (E) /= Current_Scope;
3727 end loop;
3728 end if;
3729 end Process_Suppress_Unsuppress;
3731 ------------------
3732 -- Set_Exported --
3733 ------------------
3735 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
3736 begin
3737 if Is_Imported (E) then
3738 Error_Pragma_Arg
3739 ("cannot export entity& that was previously imported", Arg);
3741 elsif Present (Address_Clause (E)) then
3742 Error_Pragma_Arg
3743 ("cannot export entity& that has an address clause", Arg);
3744 end if;
3746 Set_Is_Exported (E);
3748 -- Generate a reference for entity explicitly, because the
3749 -- identifier may be overloaded and name resolution will not
3750 -- generate one.
3752 Generate_Reference (E, Arg);
3754 -- Deal with exporting non-library level entity
3756 if not Is_Library_Level_Entity (E) then
3758 -- Not allowed at all for subprograms
3760 if Is_Subprogram (E) then
3761 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
3763 -- Otherwise set public and statically allocated
3765 else
3766 Set_Is_Public (E);
3767 Set_Is_Statically_Allocated (E);
3769 -- Warn if the corresponding W flag is set and the pragma
3770 -- comes from source. The latter may not be true e.g. on
3771 -- VMS where we expand export pragmas for exception codes
3772 -- associated with imported or exported exceptions. We do
3773 -- not want to generate a warning for something that the
3774 -- user did not write.
3776 if Warn_On_Export_Import
3777 and then Comes_From_Source (Arg)
3778 then
3779 Error_Msg_NE
3780 ("?& has been made static as a result of Export", Arg, E);
3781 Error_Msg_N
3782 ("\this usage is non-standard and non-portable", Arg);
3783 end if;
3784 end if;
3785 end if;
3787 if Warn_On_Export_Import and then Is_Type (E) then
3788 Error_Msg_NE
3789 ("exporting a type has no effect?", Arg, E);
3790 end if;
3792 if Warn_On_Export_Import and Inside_A_Generic then
3793 Error_Msg_NE
3794 ("all instances of& will have the same external name?", Arg, E);
3795 end if;
3796 end Set_Exported;
3798 ----------------------------------------------
3799 -- Set_Extended_Import_Export_External_Name --
3800 ----------------------------------------------
3802 procedure Set_Extended_Import_Export_External_Name
3803 (Internal_Ent : Entity_Id;
3804 Arg_External : Node_Id)
3806 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
3807 New_Name : Node_Id;
3809 begin
3810 if No (Arg_External) then
3811 return;
3812 end if;
3814 Check_Arg_Is_External_Name (Arg_External);
3816 if Nkind (Arg_External) = N_String_Literal then
3817 if String_Length (Strval (Arg_External)) = 0 then
3818 return;
3819 else
3820 New_Name := Adjust_External_Name_Case (Arg_External);
3821 end if;
3823 elsif Nkind (Arg_External) = N_Identifier then
3824 New_Name := Get_Default_External_Name (Arg_External);
3826 -- Check_Arg_Is_External_Name should let through only
3827 -- identifiers and string literals or static string
3828 -- expressions (which are folded to string literals).
3830 else
3831 raise Program_Error;
3832 end if;
3834 -- If we already have an external name set (by a prior normal
3835 -- Import or Export pragma), then the external names must match
3837 if Present (Interface_Name (Internal_Ent)) then
3838 declare
3839 S1 : constant String_Id := Strval (Old_Name);
3840 S2 : constant String_Id := Strval (New_Name);
3842 procedure Mismatch;
3843 -- Called if names do not match
3845 procedure Mismatch is
3846 begin
3847 Error_Msg_Sloc := Sloc (Old_Name);
3848 Error_Pragma_Arg
3849 ("external name does not match that given #",
3850 Arg_External);
3851 end Mismatch;
3853 begin
3854 if String_Length (S1) /= String_Length (S2) then
3855 Mismatch;
3857 else
3858 for J in 1 .. String_Length (S1) loop
3859 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
3860 Mismatch;
3861 end if;
3862 end loop;
3863 end if;
3864 end;
3866 -- Otherwise set the given name
3868 else
3869 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
3870 Check_Duplicated_Export_Name (New_Name);
3871 end if;
3872 end Set_Extended_Import_Export_External_Name;
3874 ------------------
3875 -- Set_Imported --
3876 ------------------
3878 procedure Set_Imported (E : Entity_Id) is
3879 begin
3880 Error_Msg_Sloc := Sloc (E);
3882 if Is_Exported (E) or else Is_Imported (E) then
3883 Error_Msg_NE ("import of& declared# not allowed", N, E);
3885 if Is_Exported (E) then
3886 Error_Msg_N ("\entity was previously exported", N);
3887 else
3888 Error_Msg_N ("\entity was previously imported", N);
3889 end if;
3891 Error_Pragma ("\(pragma% applies to all previous entities)");
3893 else
3894 Set_Is_Imported (E);
3896 -- If the entity is an object that is not at the library
3897 -- level, then it is statically allocated. We do not worry
3898 -- about objects with address clauses in this context since
3899 -- they are not really imported in the linker sense.
3901 if Is_Object (E)
3902 and then not Is_Library_Level_Entity (E)
3903 and then No (Address_Clause (E))
3904 then
3905 Set_Is_Statically_Allocated (E);
3906 end if;
3907 end if;
3908 end Set_Imported;
3910 -------------------------
3911 -- Set_Mechanism_Value --
3912 -------------------------
3914 -- Note: the mechanism name has not been analyzed (and cannot indeed
3915 -- be analyzed, since it is semantic nonsense), so we get it in the
3916 -- exact form created by the parser.
3918 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
3919 Class : Node_Id;
3920 Param : Node_Id;
3922 procedure Bad_Class;
3923 -- Signal bad descriptor class name
3925 procedure Bad_Mechanism;
3926 -- Signal bad mechanism name
3928 procedure Bad_Class is
3929 begin
3930 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
3931 end Bad_Class;
3933 procedure Bad_Mechanism is
3934 begin
3935 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
3936 end Bad_Mechanism;
3938 -- Start of processing for Set_Mechanism_Value
3940 begin
3941 if Mechanism (Ent) /= Default_Mechanism then
3942 Error_Msg_NE
3943 ("mechanism for & has already been set", Mech_Name, Ent);
3944 end if;
3946 -- MECHANISM_NAME ::= value | reference | descriptor
3948 if Nkind (Mech_Name) = N_Identifier then
3949 if Chars (Mech_Name) = Name_Value then
3950 Set_Mechanism (Ent, By_Copy);
3951 return;
3953 elsif Chars (Mech_Name) = Name_Reference then
3954 Set_Mechanism (Ent, By_Reference);
3955 return;
3957 elsif Chars (Mech_Name) = Name_Descriptor then
3958 Check_VMS (Mech_Name);
3959 Set_Mechanism (Ent, By_Descriptor);
3960 return;
3962 elsif Chars (Mech_Name) = Name_Copy then
3963 Error_Pragma_Arg
3964 ("bad mechanism name, Value assumed", Mech_Name);
3966 else
3967 Bad_Mechanism;
3968 end if;
3970 -- MECHANISM_NAME ::= descriptor (CLASS_NAME)
3971 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
3973 -- Note: this form is parsed as an indexed component
3975 elsif Nkind (Mech_Name) = N_Indexed_Component then
3976 Class := First (Expressions (Mech_Name));
3978 if Nkind (Prefix (Mech_Name)) /= N_Identifier
3979 or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
3980 or else Present (Next (Class))
3981 then
3982 Bad_Mechanism;
3983 end if;
3985 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
3986 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
3988 -- Note: this form is parsed as a function call
3990 elsif Nkind (Mech_Name) = N_Function_Call then
3992 Param := First (Parameter_Associations (Mech_Name));
3994 if Nkind (Name (Mech_Name)) /= N_Identifier
3995 or else Chars (Name (Mech_Name)) /= Name_Descriptor
3996 or else Present (Next (Param))
3997 or else No (Selector_Name (Param))
3998 or else Chars (Selector_Name (Param)) /= Name_Class
3999 then
4000 Bad_Mechanism;
4001 else
4002 Class := Explicit_Actual_Parameter (Param);
4003 end if;
4005 else
4006 Bad_Mechanism;
4007 end if;
4009 -- Fall through here with Class set to descriptor class name
4011 Check_VMS (Mech_Name);
4013 if Nkind (Class) /= N_Identifier then
4014 Bad_Class;
4016 elsif Chars (Class) = Name_UBS then
4017 Set_Mechanism (Ent, By_Descriptor_UBS);
4019 elsif Chars (Class) = Name_UBSB then
4020 Set_Mechanism (Ent, By_Descriptor_UBSB);
4022 elsif Chars (Class) = Name_UBA then
4023 Set_Mechanism (Ent, By_Descriptor_UBA);
4025 elsif Chars (Class) = Name_S then
4026 Set_Mechanism (Ent, By_Descriptor_S);
4028 elsif Chars (Class) = Name_SB then
4029 Set_Mechanism (Ent, By_Descriptor_SB);
4031 elsif Chars (Class) = Name_A then
4032 Set_Mechanism (Ent, By_Descriptor_A);
4034 elsif Chars (Class) = Name_NCA then
4035 Set_Mechanism (Ent, By_Descriptor_NCA);
4037 else
4038 Bad_Class;
4039 end if;
4041 end Set_Mechanism_Value;
4043 ---------------------------
4044 -- Set_Ravenscar_Profile --
4045 ---------------------------
4047 -- The tasks to be done here are
4049 -- Set required policies
4051 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4052 -- pragma Locking_Policy (Ceiling_Locking)
4054 -- Set Detect_Blocking mode
4056 -- Set required restrictions (see System.Rident for detailed list)
4058 procedure Set_Ravenscar_Profile (N : Node_Id) is
4059 begin
4060 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4062 if Task_Dispatching_Policy /= ' '
4063 and then Task_Dispatching_Policy /= 'F'
4064 then
4065 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4066 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4068 -- Set the FIFO_Within_Priorities policy, but always
4069 -- preserve System_Location since we like the error
4070 -- message with the run time name.
4072 else
4073 Task_Dispatching_Policy := 'F';
4075 if Task_Dispatching_Policy_Sloc /= System_Location then
4076 Task_Dispatching_Policy_Sloc := Loc;
4077 end if;
4078 end if;
4080 -- pragma Locking_Policy (Ceiling_Locking)
4082 if Locking_Policy /= ' '
4083 and then Locking_Policy /= 'C'
4084 then
4085 Error_Msg_Sloc := Locking_Policy_Sloc;
4086 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4088 -- Set the Ceiling_Locking policy, but always preserve
4089 -- System_Location since we like the error message with the
4090 -- run time name.
4092 else
4093 Locking_Policy := 'C';
4095 if Locking_Policy_Sloc /= System_Location then
4096 Locking_Policy_Sloc := Loc;
4097 end if;
4098 end if;
4100 -- pragma Detect_Blocking
4102 Detect_Blocking := True;
4104 -- Set the corresponding restrictions
4106 Set_Profile_Restrictions (Ravenscar, N, Warn => False);
4107 end Set_Ravenscar_Profile;
4109 -- Start of processing for Analyze_Pragma
4111 begin
4112 if not Is_Pragma_Name (Chars (N)) then
4113 if Warn_On_Unrecognized_Pragma then
4114 Error_Pragma ("unrecognized pragma%!?");
4115 else
4116 raise Pragma_Exit;
4117 end if;
4118 else
4119 Prag_Id := Get_Pragma_Id (Chars (N));
4120 end if;
4122 -- Preset arguments
4124 Arg1 := Empty;
4125 Arg2 := Empty;
4126 Arg3 := Empty;
4127 Arg4 := Empty;
4129 if Present (Pragma_Argument_Associations (N)) then
4130 Arg1 := First (Pragma_Argument_Associations (N));
4132 if Present (Arg1) then
4133 Arg2 := Next (Arg1);
4135 if Present (Arg2) then
4136 Arg3 := Next (Arg2);
4138 if Present (Arg3) then
4139 Arg4 := Next (Arg3);
4140 end if;
4141 end if;
4142 end if;
4143 end if;
4145 -- Count number of arguments
4147 declare
4148 Arg_Node : Node_Id;
4149 begin
4150 Arg_Count := 0;
4151 Arg_Node := Arg1;
4152 while Present (Arg_Node) loop
4153 Arg_Count := Arg_Count + 1;
4154 Next (Arg_Node);
4155 end loop;
4156 end;
4158 -- An enumeration type defines the pragmas that are supported by the
4159 -- implementation. Get_Pragma_Id (in package Prag) transorms a name
4160 -- into the corresponding enumeration value for the following case.
4162 case Prag_Id is
4164 -----------------
4165 -- Abort_Defer --
4166 -----------------
4168 -- pragma Abort_Defer;
4170 when Pragma_Abort_Defer =>
4171 GNAT_Pragma;
4172 Check_Arg_Count (0);
4174 -- The only required semantic processing is to check the
4175 -- placement. This pragma must appear at the start of the
4176 -- statement sequence of a handled sequence of statements.
4178 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
4179 or else N /= First (Statements (Parent (N)))
4180 then
4181 Pragma_Misplaced;
4182 end if;
4184 ------------
4185 -- Ada_83 --
4186 ------------
4188 -- pragma Ada_83;
4190 -- Note: this pragma also has some specific processing in Par.Prag
4191 -- because we want to set the Ada version mode during parsing.
4193 when Pragma_Ada_83 =>
4194 GNAT_Pragma;
4195 Ada_Version := Ada_83;
4196 Check_Arg_Count (0);
4198 ------------
4199 -- Ada_95 --
4200 ------------
4202 -- pragma Ada_95;
4204 -- Note: this pragma also has some specific processing in Par.Prag
4205 -- because we want to set the Ada 83 version mode during parsing.
4207 when Pragma_Ada_95 =>
4208 GNAT_Pragma;
4209 Ada_Version := Ada_95;
4210 Check_Arg_Count (0);
4212 ------------
4213 -- Ada_05 --
4214 ------------
4216 -- pragma Ada_05;
4218 -- Note: this pragma also has some specific processing in Par.Prag
4219 -- because we want to set the Ada 83 version mode during parsing.
4221 when Pragma_Ada_05 =>
4222 GNAT_Pragma;
4223 Ada_Version := Ada_05;
4224 Check_Arg_Count (0);
4226 ----------------------
4227 -- All_Calls_Remote --
4228 ----------------------
4230 -- pragma All_Calls_Remote [(library_package_NAME)];
4232 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
4233 Lib_Entity : Entity_Id;
4235 begin
4236 Check_Ada_83_Warning;
4237 Check_Valid_Library_Unit_Pragma;
4239 if Nkind (N) = N_Null_Statement then
4240 return;
4241 end if;
4243 Lib_Entity := Find_Lib_Unit_Name;
4245 -- This pragma should only apply to a RCI unit (RM E.2.3(23)).
4247 if Present (Lib_Entity)
4248 and then not Debug_Flag_U
4249 then
4250 if not Is_Remote_Call_Interface (Lib_Entity) then
4251 Error_Pragma ("pragma% only apply to rci unit");
4253 -- Set flag for entity of the library unit
4255 else
4256 Set_Has_All_Calls_Remote (Lib_Entity);
4257 end if;
4259 end if;
4260 end All_Calls_Remote;
4262 --------------
4263 -- Annotate --
4264 --------------
4266 -- pragma Annotate (IDENTIFIER {, ARG});
4267 -- ARG ::= NAME | EXPRESSION
4269 when Pragma_Annotate => Annotate : begin
4270 GNAT_Pragma;
4271 Check_At_Least_N_Arguments (1);
4272 Check_Arg_Is_Identifier (Arg1);
4274 declare
4275 Arg : Node_Id := Arg2;
4276 Exp : Node_Id;
4278 begin
4279 while Present (Arg) loop
4280 Exp := Expression (Arg);
4281 Analyze (Exp);
4283 if Is_Entity_Name (Exp) then
4284 null;
4286 elsif Nkind (Exp) = N_String_Literal then
4287 Resolve (Exp, Standard_String);
4289 elsif Is_Overloaded (Exp) then
4290 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
4292 else
4293 Resolve (Exp);
4294 end if;
4296 Next (Arg);
4297 end loop;
4298 end;
4299 end Annotate;
4301 ------------
4302 -- Assert --
4303 ------------
4305 -- pragma Assert (Boolean_EXPRESSION [, static_string_EXPRESSION]);
4307 when Pragma_Assert =>
4308 GNAT_Pragma;
4309 Check_No_Identifiers;
4311 if Arg_Count > 1 then
4312 Check_Arg_Count (2);
4313 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4314 end if;
4316 -- If expansion is active and assertions are inactive, then
4317 -- we rewrite the Assertion as:
4319 -- if False and then condition then
4320 -- null;
4321 -- end if;
4323 -- The reason we do this rewriting during semantic analysis
4324 -- rather than as part of normal expansion is that we cannot
4325 -- analyze and expand the code for the boolean expression
4326 -- directly, or it may cause insertion of actions that would
4327 -- escape the attempt to suppress the assertion code.
4329 if Expander_Active and not Assertions_Enabled then
4330 Rewrite (N,
4331 Make_If_Statement (Loc,
4332 Condition =>
4333 Make_And_Then (Loc,
4334 Left_Opnd => New_Occurrence_Of (Standard_False, Loc),
4335 Right_Opnd => Get_Pragma_Arg (Arg1)),
4336 Then_Statements => New_List (
4337 Make_Null_Statement (Loc))));
4339 Analyze (N);
4341 -- Otherwise (if assertions are enabled, or if we are not
4342 -- operating with expansion active), then we just analyze
4343 -- and resolve the expression.
4345 else
4346 Analyze_And_Resolve (Expression (Arg1), Any_Boolean);
4347 end if;
4349 ---------------
4350 -- AST_Entry --
4351 ---------------
4353 -- pragma AST_Entry (entry_IDENTIFIER);
4355 when Pragma_AST_Entry => AST_Entry : declare
4356 Ent : Node_Id;
4358 begin
4359 GNAT_Pragma;
4360 Check_VMS (N);
4361 Check_Arg_Count (1);
4362 Check_No_Identifiers;
4363 Check_Arg_Is_Local_Name (Arg1);
4364 Ent := Entity (Expression (Arg1));
4366 -- Note: the implementation of the AST_Entry pragma could handle
4367 -- the entry family case fine, but for now we are consistent with
4368 -- the DEC rules, and do not allow the pragma, which of course
4369 -- has the effect of also forbidding the attribute.
4371 if Ekind (Ent) /= E_Entry then
4372 Error_Pragma_Arg
4373 ("pragma% argument must be simple entry name", Arg1);
4375 elsif Is_AST_Entry (Ent) then
4376 Error_Pragma_Arg
4377 ("duplicate % pragma for entry", Arg1);
4379 elsif Has_Homonym (Ent) then
4380 Error_Pragma_Arg
4381 ("pragma% argument cannot specify overloaded entry", Arg1);
4383 else
4384 declare
4385 FF : constant Entity_Id := First_Formal (Ent);
4387 begin
4388 if Present (FF) then
4389 if Present (Next_Formal (FF)) then
4390 Error_Pragma_Arg
4391 ("entry for pragma% can have only one argument",
4392 Arg1);
4394 elsif Parameter_Mode (FF) /= E_In_Parameter then
4395 Error_Pragma_Arg
4396 ("entry parameter for pragma% must have mode IN",
4397 Arg1);
4398 end if;
4399 end if;
4400 end;
4402 Set_Is_AST_Entry (Ent);
4403 end if;
4404 end AST_Entry;
4406 ------------------
4407 -- Asynchronous --
4408 ------------------
4410 -- pragma Asynchronous (LOCAL_NAME);
4412 when Pragma_Asynchronous => Asynchronous : declare
4413 Nm : Entity_Id;
4414 C_Ent : Entity_Id;
4415 L : List_Id;
4416 S : Node_Id;
4417 N : Node_Id;
4418 Formal : Entity_Id;
4420 procedure Process_Async_Pragma;
4421 -- Common processing for procedure and access-to-procedure case
4423 --------------------------
4424 -- Process_Async_Pragma --
4425 --------------------------
4427 procedure Process_Async_Pragma is
4428 begin
4429 if not Present (L) then
4430 Set_Is_Asynchronous (Nm);
4431 return;
4432 end if;
4434 -- The formals should be of mode IN (RM E.4.1(6))
4436 S := First (L);
4437 while Present (S) loop
4438 Formal := Defining_Identifier (S);
4440 if Nkind (Formal) = N_Defining_Identifier
4441 and then Ekind (Formal) /= E_In_Parameter
4442 then
4443 Error_Pragma_Arg
4444 ("pragma% procedure can only have IN parameter",
4445 Arg1);
4446 end if;
4448 Next (S);
4449 end loop;
4451 Set_Is_Asynchronous (Nm);
4452 end Process_Async_Pragma;
4454 -- Start of processing for pragma Asynchronous
4456 begin
4457 Check_Ada_83_Warning;
4458 Check_No_Identifiers;
4459 Check_Arg_Count (1);
4460 Check_Arg_Is_Local_Name (Arg1);
4462 if Debug_Flag_U then
4463 return;
4464 end if;
4466 C_Ent := Cunit_Entity (Current_Sem_Unit);
4467 Analyze (Expression (Arg1));
4468 Nm := Entity (Expression (Arg1));
4470 if not Is_Remote_Call_Interface (C_Ent)
4471 and then not Is_Remote_Types (C_Ent)
4472 then
4473 -- This pragma should only appear in an RCI or Remote Types
4474 -- unit (RM E.4.1(4))
4476 Error_Pragma
4477 ("pragma% not in Remote_Call_Interface or " &
4478 "Remote_Types unit");
4479 end if;
4481 if Ekind (Nm) = E_Procedure
4482 and then Nkind (Parent (Nm)) = N_Procedure_Specification
4483 then
4484 if not Is_Remote_Call_Interface (Nm) then
4485 Error_Pragma_Arg
4486 ("pragma% cannot be applied on non-remote procedure",
4487 Arg1);
4488 end if;
4490 L := Parameter_Specifications (Parent (Nm));
4491 Process_Async_Pragma;
4492 return;
4494 elsif Ekind (Nm) = E_Function then
4495 Error_Pragma_Arg
4496 ("pragma% cannot be applied to function", Arg1);
4498 elsif Ekind (Nm) = E_Record_Type
4499 and then Present (Corresponding_Remote_Type (Nm))
4500 then
4501 N := Declaration_Node (Corresponding_Remote_Type (Nm));
4503 if Nkind (N) = N_Full_Type_Declaration
4504 and then Nkind (Type_Definition (N)) =
4505 N_Access_Procedure_Definition
4506 then
4507 L := Parameter_Specifications (Type_Definition (N));
4508 Process_Async_Pragma;
4510 else
4511 Error_Pragma_Arg
4512 ("pragma% cannot reference access-to-function type",
4513 Arg1);
4514 end if;
4516 -- Only other possibility is Access-to-class-wide type
4518 elsif Is_Access_Type (Nm)
4519 and then Is_Class_Wide_Type (Designated_Type (Nm))
4520 then
4521 Check_First_Subtype (Arg1);
4522 Set_Is_Asynchronous (Nm);
4523 if Expander_Active then
4524 RACW_Type_Is_Asynchronous (Nm);
4525 end if;
4527 else
4528 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
4529 end if;
4530 end Asynchronous;
4532 ------------
4533 -- Atomic --
4534 ------------
4536 -- pragma Atomic (LOCAL_NAME);
4538 when Pragma_Atomic =>
4539 Process_Atomic_Shared_Volatile;
4541 -----------------------
4542 -- Atomic_Components --
4543 -----------------------
4545 -- pragma Atomic_Components (array_LOCAL_NAME);
4547 -- This processing is shared by Volatile_Components
4549 when Pragma_Atomic_Components |
4550 Pragma_Volatile_Components =>
4552 Atomic_Components : declare
4553 E_Id : Node_Id;
4554 E : Entity_Id;
4555 D : Node_Id;
4556 K : Node_Kind;
4558 begin
4559 Check_Ada_83_Warning;
4560 Check_No_Identifiers;
4561 Check_Arg_Count (1);
4562 Check_Arg_Is_Local_Name (Arg1);
4563 E_Id := Expression (Arg1);
4565 if Etype (E_Id) = Any_Type then
4566 return;
4567 end if;
4569 E := Entity (E_Id);
4571 if Rep_Item_Too_Early (E, N)
4572 or else
4573 Rep_Item_Too_Late (E, N)
4574 then
4575 return;
4576 end if;
4578 D := Declaration_Node (E);
4579 K := Nkind (D);
4581 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
4582 or else
4583 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
4584 and then Nkind (D) = N_Object_Declaration
4585 and then Nkind (Object_Definition (D)) =
4586 N_Constrained_Array_Definition)
4587 then
4588 -- The flag is set on the object, or on the base type
4590 if Nkind (D) /= N_Object_Declaration then
4591 E := Base_Type (E);
4592 end if;
4594 Set_Has_Volatile_Components (E);
4596 if Prag_Id = Pragma_Atomic_Components then
4597 Set_Has_Atomic_Components (E);
4599 if Is_Packed (E) then
4600 Set_Is_Packed (E, False);
4602 Error_Pragma_Arg
4603 ("?Pack canceled, cannot pack atomic components",
4604 Arg1);
4605 end if;
4606 end if;
4608 else
4609 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
4610 end if;
4611 end Atomic_Components;
4613 --------------------
4614 -- Attach_Handler --
4615 --------------------
4617 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
4619 when Pragma_Attach_Handler =>
4620 Check_Ada_83_Warning;
4621 Check_No_Identifiers;
4622 Check_Arg_Count (2);
4624 if No_Run_Time_Mode then
4625 Error_Msg_CRT ("Attach_Handler pragma", N);
4626 else
4627 Check_Interrupt_Or_Attach_Handler;
4629 -- The expression that designates the attribute may
4630 -- depend on a discriminant, and is therefore a per-
4631 -- object expression, to be expanded in the init proc.
4632 -- If expansion is enabled, perform semantic checks
4633 -- on a copy only.
4635 if Expander_Active then
4636 declare
4637 Temp : constant Node_Id :=
4638 New_Copy_Tree (Expression (Arg2));
4639 begin
4640 Set_Parent (Temp, N);
4641 Pre_Analyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
4642 end;
4644 else
4645 Analyze (Expression (Arg2));
4646 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
4647 end if;
4649 Process_Interrupt_Or_Attach_Handler;
4650 end if;
4652 --------------------
4653 -- C_Pass_By_Copy --
4654 --------------------
4656 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
4658 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
4659 Arg : Node_Id;
4660 Val : Uint;
4662 begin
4663 GNAT_Pragma;
4664 Check_Valid_Configuration_Pragma;
4665 Check_Arg_Count (1);
4666 Check_Optional_Identifier (Arg1, "max_size");
4668 Arg := Expression (Arg1);
4669 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
4671 Val := Expr_Value (Arg);
4673 if Val <= 0 then
4674 Error_Pragma_Arg
4675 ("maximum size for pragma% must be positive", Arg1);
4677 elsif UI_Is_In_Int_Range (Val) then
4678 Default_C_Record_Mechanism := UI_To_Int (Val);
4680 -- If a giant value is given, Int'Last will do well enough.
4681 -- If sometime someone complains that a record larger than
4682 -- two gigabytes is not copied, we will worry about it then!
4684 else
4685 Default_C_Record_Mechanism := Mechanism_Type'Last;
4686 end if;
4687 end C_Pass_By_Copy;
4689 -------------
4690 -- Comment --
4691 -------------
4693 -- pragma Comment (static_string_EXPRESSION)
4695 -- Processing for pragma Comment shares the circuitry for
4696 -- pragma Ident. The only differences are that Ident enforces
4697 -- a limit of 31 characters on its argument, and also enforces
4698 -- limitations on placement for DEC compatibility. Pragma
4699 -- Comment shares neither of these restrictions.
4701 -------------------
4702 -- Common_Object --
4703 -------------------
4705 -- pragma Common_Object (
4706 -- [Internal =>] LOCAL_NAME,
4707 -- [, [External =>] EXTERNAL_SYMBOL]
4708 -- [, [Size =>] EXTERNAL_SYMBOL]);
4710 -- Processing for this pragma is shared with Psect_Object
4712 --------------------------
4713 -- Compile_Time_Warning --
4714 --------------------------
4716 -- pragma Compile_Time_Warning
4717 -- (boolean_EXPRESSION, static_string_EXPRESSION);
4719 when Pragma_Compile_Time_Warning => Compile_Time_Warning : declare
4720 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
4722 begin
4723 GNAT_Pragma;
4724 Check_Arg_Count (2);
4725 Check_No_Identifiers;
4726 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4727 Analyze_And_Resolve (Arg1x, Standard_Boolean);
4729 if Compile_Time_Known_Value (Arg1x) then
4730 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
4731 String_To_Name_Buffer (Strval (Get_Pragma_Arg (Arg2)));
4732 Add_Char_To_Name_Buffer ('?');
4734 declare
4735 Msg : String (1 .. Name_Len) :=
4736 Name_Buffer (1 .. Name_Len);
4738 B : Natural;
4740 begin
4741 -- This loop looks for multiple lines separated by
4742 -- ASCII.LF and breaks them into continuation error
4743 -- messages marked with the usual back slash.
4745 B := 1;
4746 for S in 2 .. Msg'Length - 1 loop
4747 if Msg (S) = ASCII.LF then
4748 Msg (S) := '?';
4749 Error_Msg_N (Msg (B .. S), Arg1);
4750 B := S;
4751 Msg (B) := '\';
4752 end if;
4753 end loop;
4755 Error_Msg_N (Msg (B .. Msg'Length), Arg1);
4756 end;
4757 end if;
4758 end if;
4759 end Compile_Time_Warning;
4761 ----------------------------
4762 -- Complex_Representation --
4763 ----------------------------
4765 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
4767 when Pragma_Complex_Representation => Complex_Representation : declare
4768 E_Id : Entity_Id;
4769 E : Entity_Id;
4770 Ent : Entity_Id;
4772 begin
4773 GNAT_Pragma;
4774 Check_Arg_Count (1);
4775 Check_Optional_Identifier (Arg1, Name_Entity);
4776 Check_Arg_Is_Local_Name (Arg1);
4777 E_Id := Expression (Arg1);
4779 if Etype (E_Id) = Any_Type then
4780 return;
4781 end if;
4783 E := Entity (E_Id);
4785 if not Is_Record_Type (E) then
4786 Error_Pragma_Arg
4787 ("argument for pragma% must be record type", Arg1);
4788 end if;
4790 Ent := First_Entity (E);
4792 if No (Ent)
4793 or else No (Next_Entity (Ent))
4794 or else Present (Next_Entity (Next_Entity (Ent)))
4795 or else not Is_Floating_Point_Type (Etype (Ent))
4796 or else Etype (Ent) /= Etype (Next_Entity (Ent))
4797 then
4798 Error_Pragma_Arg
4799 ("record for pragma% must have two fields of same fpt type",
4800 Arg1);
4802 else
4803 Set_Has_Complex_Representation (Base_Type (E));
4804 end if;
4805 end Complex_Representation;
4807 -------------------------
4808 -- Component_Alignment --
4809 -------------------------
4811 -- pragma Component_Alignment (
4812 -- [Form =>] ALIGNMENT_CHOICE
4813 -- [, [Name =>] type_LOCAL_NAME]);
4815 -- ALIGNMENT_CHOICE ::=
4816 -- Component_Size
4817 -- | Component_Size_4
4818 -- | Storage_Unit
4819 -- | Default
4821 when Pragma_Component_Alignment => Component_AlignmentP : declare
4822 Args : Args_List (1 .. 2);
4823 Names : constant Name_List (1 .. 2) := (
4824 Name_Form,
4825 Name_Name);
4827 Form : Node_Id renames Args (1);
4828 Name : Node_Id renames Args (2);
4830 Atype : Component_Alignment_Kind;
4831 Typ : Entity_Id;
4833 begin
4834 GNAT_Pragma;
4835 Gather_Associations (Names, Args);
4837 if No (Form) then
4838 Error_Pragma ("missing Form argument for pragma%");
4839 end if;
4841 Check_Arg_Is_Identifier (Form);
4843 -- Get proper alignment, note that Default = Component_Size
4844 -- on all machines we have so far, and we want to set this
4845 -- value rather than the default value to indicate that it
4846 -- has been explicitly set (and thus will not get overridden
4847 -- by the default component alignment for the current scope)
4849 if Chars (Form) = Name_Component_Size then
4850 Atype := Calign_Component_Size;
4852 elsif Chars (Form) = Name_Component_Size_4 then
4853 Atype := Calign_Component_Size_4;
4855 elsif Chars (Form) = Name_Default then
4856 Atype := Calign_Component_Size;
4858 elsif Chars (Form) = Name_Storage_Unit then
4859 Atype := Calign_Storage_Unit;
4861 else
4862 Error_Pragma_Arg
4863 ("invalid Form parameter for pragma%", Form);
4864 end if;
4866 -- Case with no name, supplied, affects scope table entry
4868 if No (Name) then
4869 Scope_Stack.Table
4870 (Scope_Stack.Last).Component_Alignment_Default := Atype;
4872 -- Case of name supplied
4874 else
4875 Check_Arg_Is_Local_Name (Name);
4876 Find_Type (Name);
4877 Typ := Entity (Name);
4879 if Typ = Any_Type
4880 or else Rep_Item_Too_Early (Typ, N)
4881 then
4882 return;
4883 else
4884 Typ := Underlying_Type (Typ);
4885 end if;
4887 if not Is_Record_Type (Typ)
4888 and then not Is_Array_Type (Typ)
4889 then
4890 Error_Pragma_Arg
4891 ("Name parameter of pragma% must identify record or " &
4892 "array type", Name);
4893 end if;
4895 -- An explicit Component_Alignment pragma overrides an
4896 -- implicit pragma Pack, but not an explicit one.
4898 if not Has_Pragma_Pack (Base_Type (Typ)) then
4899 Set_Is_Packed (Base_Type (Typ), False);
4900 Set_Component_Alignment (Base_Type (Typ), Atype);
4901 end if;
4902 end if;
4903 end Component_AlignmentP;
4905 ----------------
4906 -- Controlled --
4907 ----------------
4909 -- pragma Controlled (first_subtype_LOCAL_NAME);
4911 when Pragma_Controlled => Controlled : declare
4912 Arg : Node_Id;
4914 begin
4915 Check_No_Identifiers;
4916 Check_Arg_Count (1);
4917 Check_Arg_Is_Local_Name (Arg1);
4918 Arg := Expression (Arg1);
4920 if not Is_Entity_Name (Arg)
4921 or else not Is_Access_Type (Entity (Arg))
4922 then
4923 Error_Pragma_Arg ("pragma% requires access type", Arg1);
4924 else
4925 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
4926 end if;
4927 end Controlled;
4929 ----------------
4930 -- Convention --
4931 ----------------
4933 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
4934 -- [Entity =>] LOCAL_NAME);
4936 when Pragma_Convention => Convention : declare
4937 C : Convention_Id;
4938 E : Entity_Id;
4939 begin
4940 Check_Ada_83_Warning;
4941 Check_Arg_Count (2);
4942 Process_Convention (C, E);
4943 end Convention;
4945 ---------------------------
4946 -- Convention_Identifier --
4947 ---------------------------
4949 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
4950 -- [Convention =>] convention_IDENTIFIER);
4952 when Pragma_Convention_Identifier => Convention_Identifier : declare
4953 Idnam : Name_Id;
4954 Cname : Name_Id;
4956 begin
4957 GNAT_Pragma;
4958 Check_Arg_Count (2);
4959 Check_Optional_Identifier (Arg1, Name_Name);
4960 Check_Optional_Identifier (Arg2, Name_Convention);
4961 Check_Arg_Is_Identifier (Arg1);
4962 Check_Arg_Is_Identifier (Arg1);
4963 Idnam := Chars (Expression (Arg1));
4964 Cname := Chars (Expression (Arg2));
4966 if Is_Convention_Name (Cname) then
4967 Record_Convention_Identifier
4968 (Idnam, Get_Convention_Id (Cname));
4969 else
4970 Error_Pragma_Arg
4971 ("second arg for % pragma must be convention", Arg2);
4972 end if;
4973 end Convention_Identifier;
4975 ---------------
4976 -- CPP_Class --
4977 ---------------
4979 -- pragma CPP_Class ([Entity =>] local_NAME)
4981 when Pragma_CPP_Class => CPP_Class : declare
4982 Arg : Node_Id;
4983 Typ : Entity_Id;
4984 Default_DTC : Entity_Id := Empty;
4985 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
4986 C : Entity_Id;
4987 Tag_C : Entity_Id;
4989 begin
4990 GNAT_Pragma;
4991 Check_Arg_Count (1);
4992 Check_Optional_Identifier (Arg1, Name_Entity);
4993 Check_Arg_Is_Local_Name (Arg1);
4995 Arg := Expression (Arg1);
4996 Analyze (Arg);
4998 if Etype (Arg) = Any_Type then
4999 return;
5000 end if;
5002 if not Is_Entity_Name (Arg)
5003 or else not Is_Type (Entity (Arg))
5004 then
5005 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
5006 end if;
5008 Typ := Entity (Arg);
5010 if not Is_Record_Type (Typ) then
5011 Error_Pragma_Arg ("pragma% applicable to a record, "
5012 & "tagged record or record extension", Arg1);
5013 end if;
5015 Default_DTC := First_Component (Typ);
5016 while Present (Default_DTC)
5017 and then Etype (Default_DTC) /= VTP_Type
5018 loop
5019 Next_Component (Default_DTC);
5020 end loop;
5022 -- Case of non tagged type
5024 if not Is_Tagged_Type (Typ) then
5025 Set_Is_CPP_Class (Typ);
5027 if Present (Default_DTC) then
5028 Error_Pragma_Arg
5029 ("only tagged records can contain vtable pointers", Arg1);
5030 end if;
5032 -- Case of tagged type with no vtable ptr
5034 -- What is test for Typ = Root_Typ (Typ) about here ???
5036 elsif Is_Tagged_Type (Typ)
5037 and then Typ = Root_Type (Typ)
5038 and then No (Default_DTC)
5039 then
5040 Error_Pragma_Arg
5041 ("a cpp_class must contain a vtable pointer", Arg1);
5043 -- Tagged type that has a vtable ptr
5045 elsif Present (Default_DTC) then
5046 Set_Is_CPP_Class (Typ);
5047 Set_Is_Limited_Record (Typ);
5048 Set_Is_Tag (Default_DTC);
5049 Set_DT_Entry_Count (Default_DTC, No_Uint);
5051 -- Since a CPP type has no direct link to its associated tag
5052 -- most tags checks cannot be performed
5054 Set_Kill_Tag_Checks (Typ);
5055 Set_Kill_Tag_Checks (Class_Wide_Type (Typ));
5057 -- Get rid of the _tag component when there was one.
5058 -- It is only useful for regular tagged types
5060 if Expander_Active and then Typ = Root_Type (Typ) then
5062 Tag_C := Tag_Component (Typ);
5063 C := First_Entity (Typ);
5065 if C = Tag_C then
5066 Set_First_Entity (Typ, Next_Entity (Tag_C));
5068 else
5069 while Next_Entity (C) /= Tag_C loop
5070 Next_Entity (C);
5071 end loop;
5073 Set_Next_Entity (C, Next_Entity (Tag_C));
5074 end if;
5075 end if;
5076 end if;
5077 end CPP_Class;
5079 ---------------------
5080 -- CPP_Constructor --
5081 ---------------------
5083 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME);
5085 when Pragma_CPP_Constructor => CPP_Constructor : declare
5086 Id : Entity_Id;
5087 Def_Id : Entity_Id;
5089 begin
5090 GNAT_Pragma;
5091 Check_Arg_Count (1);
5092 Check_Optional_Identifier (Arg1, Name_Entity);
5093 Check_Arg_Is_Local_Name (Arg1);
5095 Id := Expression (Arg1);
5096 Find_Program_Unit_Name (Id);
5098 -- If we did not find the name, we are done
5100 if Etype (Id) = Any_Type then
5101 return;
5102 end if;
5104 Def_Id := Entity (Id);
5106 if Ekind (Def_Id) = E_Function
5107 and then Is_Class_Wide_Type (Etype (Def_Id))
5108 and then Is_CPP_Class (Etype (Etype (Def_Id)))
5109 then
5110 -- What the heck is this??? this pragma allows only 1 arg
5112 if Arg_Count >= 2 then
5113 Check_At_Most_N_Arguments (3);
5114 Process_Interface_Name (Def_Id, Arg2, Arg3);
5115 end if;
5117 if No (Parameter_Specifications (Parent (Def_Id))) then
5118 Set_Has_Completion (Def_Id);
5119 Set_Is_Constructor (Def_Id);
5120 else
5121 Error_Pragma_Arg
5122 ("non-default constructors not implemented", Arg1);
5123 end if;
5125 else
5126 Error_Pragma_Arg
5127 ("pragma% requires function returning a 'C'P'P_Class type",
5128 Arg1);
5129 end if;
5130 end CPP_Constructor;
5132 -----------------
5133 -- CPP_Virtual --
5134 -----------------
5136 -- pragma CPP_Virtual
5137 -- [Entity =>] LOCAL_NAME
5138 -- [ [Vtable_Ptr =>] LOCAL_NAME,
5139 -- [Position =>] static_integer_EXPRESSION]);
5141 when Pragma_CPP_Virtual => CPP_Virtual : declare
5142 Arg : Node_Id;
5143 Typ : Entity_Id;
5144 Subp : Entity_Id;
5145 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5146 DTC : Entity_Id;
5147 V : Uint;
5149 begin
5150 GNAT_Pragma;
5152 if Arg_Count = 3 then
5153 Check_Optional_Identifier (Arg2, "vtable_ptr");
5155 -- We allow Entry_Count as well as Position for the third
5156 -- parameter for back compatibility with versions of GNAT
5157 -- before version 3.12. The documentation has always said
5158 -- Position, but the code up to 3.12 said Entry_Count.
5160 if Chars (Arg3) /= Name_Position then
5161 Check_Optional_Identifier (Arg3, "entry_count");
5162 end if;
5164 else
5165 Check_Arg_Count (1);
5166 end if;
5168 Check_Optional_Identifier (Arg1, Name_Entity);
5169 Check_Arg_Is_Local_Name (Arg1);
5171 -- First argument must be a subprogram name
5173 Arg := Expression (Arg1);
5174 Find_Program_Unit_Name (Arg);
5176 if Etype (Arg) = Any_Type then
5177 return;
5178 else
5179 Subp := Entity (Arg);
5180 end if;
5182 if not (Is_Subprogram (Subp)
5183 and then Is_Dispatching_Operation (Subp))
5184 then
5185 Error_Pragma_Arg
5186 ("pragma% must reference a primitive operation", Arg1);
5187 end if;
5189 Typ := Find_Dispatching_Type (Subp);
5191 -- If only one Argument defaults are :
5192 -- . DTC_Entity is the default Vtable pointer
5193 -- . DT_Position will be set at the freezing point
5195 if Arg_Count = 1 then
5196 Set_DTC_Entity (Subp, Tag_Component (Typ));
5197 return;
5198 end if;
5200 -- Second argument is a component name of type Vtable_Ptr
5202 Arg := Expression (Arg2);
5204 if Nkind (Arg) /= N_Identifier then
5205 Error_Msg_NE ("must be a& component name", Arg, Typ);
5206 raise Pragma_Exit;
5207 end if;
5209 DTC := First_Component (Typ);
5210 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5211 Next_Component (DTC);
5212 end loop;
5214 if No (DTC) then
5215 Error_Msg_NE ("must be a& component name", Arg, Typ);
5216 raise Pragma_Exit;
5218 elsif Etype (DTC) /= VTP_Type then
5219 Wrong_Type (Arg, VTP_Type);
5220 return;
5221 end if;
5223 -- Third argument is an integer (DT_Position)
5225 Arg := Expression (Arg3);
5226 Analyze_And_Resolve (Arg, Any_Integer);
5228 if not Is_Static_Expression (Arg) then
5229 Flag_Non_Static_Expr
5230 ("third argument of pragma CPP_Virtual must be static!",
5231 Arg3);
5232 raise Pragma_Exit;
5234 else
5235 V := Expr_Value (Expression (Arg3));
5237 if V <= 0 then
5238 Error_Pragma_Arg
5239 ("third argument of pragma% must be positive",
5240 Arg3);
5242 else
5243 Set_DTC_Entity (Subp, DTC);
5244 Set_DT_Position (Subp, V);
5245 end if;
5246 end if;
5247 end CPP_Virtual;
5249 ----------------
5250 -- CPP_Vtable --
5251 ----------------
5253 -- pragma CPP_Vtable (
5254 -- [Entity =>] LOCAL_NAME
5255 -- [Vtable_Ptr =>] LOCAL_NAME,
5256 -- [Entry_Count =>] static_integer_EXPRESSION);
5258 when Pragma_CPP_Vtable => CPP_Vtable : declare
5259 Arg : Node_Id;
5260 Typ : Entity_Id;
5261 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5262 DTC : Entity_Id;
5263 V : Uint;
5264 Elmt : Elmt_Id;
5266 begin
5267 GNAT_Pragma;
5268 Check_Arg_Count (3);
5269 Check_Optional_Identifier (Arg1, Name_Entity);
5270 Check_Optional_Identifier (Arg2, "vtable_ptr");
5271 Check_Optional_Identifier (Arg3, "entry_count");
5272 Check_Arg_Is_Local_Name (Arg1);
5274 -- First argument is a record type name
5276 Arg := Expression (Arg1);
5277 Analyze (Arg);
5279 if Etype (Arg) = Any_Type then
5280 return;
5281 else
5282 Typ := Entity (Arg);
5283 end if;
5285 if not (Is_Tagged_Type (Typ) and then Is_CPP_Class (Typ)) then
5286 Error_Pragma_Arg ("'C'P'P_Class tagged type expected", Arg1);
5287 end if;
5289 -- Second argument is a component name of type Vtable_Ptr
5291 Arg := Expression (Arg2);
5293 if Nkind (Arg) /= N_Identifier then
5294 Error_Msg_NE ("must be a& component name", Arg, Typ);
5295 raise Pragma_Exit;
5296 end if;
5298 DTC := First_Component (Typ);
5299 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5300 Next_Component (DTC);
5301 end loop;
5303 if No (DTC) then
5304 Error_Msg_NE ("must be a& component name", Arg, Typ);
5305 raise Pragma_Exit;
5307 elsif Etype (DTC) /= VTP_Type then
5308 Wrong_Type (DTC, VTP_Type);
5309 return;
5311 -- If it is the first pragma Vtable, This becomes the default tag
5313 elsif (not Is_Tag (DTC))
5314 and then DT_Entry_Count (Tag_Component (Typ)) = No_Uint
5315 then
5316 Set_Is_Tag (Tag_Component (Typ), False);
5317 Set_Is_Tag (DTC, True);
5318 Set_DT_Entry_Count (DTC, No_Uint);
5319 end if;
5321 -- Those pragmas must appear before any primitive operation
5322 -- definition (except inherited ones) otherwise the default
5323 -- may be wrong
5325 Elmt := First_Elmt (Primitive_Operations (Typ));
5326 while Present (Elmt) loop
5327 if No (Alias (Node (Elmt))) then
5328 Error_Msg_Sloc := Sloc (Node (Elmt));
5329 Error_Pragma
5330 ("pragma% must appear before this primitive operation");
5331 end if;
5333 Next_Elmt (Elmt);
5334 end loop;
5336 -- Third argument is an integer (DT_Entry_Count)
5338 Arg := Expression (Arg3);
5339 Analyze_And_Resolve (Arg, Any_Integer);
5341 if not Is_Static_Expression (Arg) then
5342 Flag_Non_Static_Expr
5343 ("entry count for pragma CPP_Vtable must be a static " &
5344 "expression!", Arg3);
5345 raise Pragma_Exit;
5347 else
5348 V := Expr_Value (Expression (Arg3));
5350 if V <= 0 then
5351 Error_Pragma_Arg
5352 ("entry count for pragma% must be positive", Arg3);
5353 else
5354 Set_DT_Entry_Count (DTC, V);
5355 end if;
5356 end if;
5357 end CPP_Vtable;
5359 -----------
5360 -- Debug --
5361 -----------
5363 -- pragma Debug (PROCEDURE_CALL_STATEMENT);
5365 when Pragma_Debug => Debug : begin
5366 GNAT_Pragma;
5368 -- Rewrite into a conditional with a static condition
5370 Rewrite (N, Make_Implicit_If_Statement (N,
5371 Condition => New_Occurrence_Of (Boolean_Literals (
5372 Assertions_Enabled and Expander_Active), Loc),
5373 Then_Statements => New_List (
5374 Relocate_Node (Debug_Statement (N)))));
5375 Analyze (N);
5376 end Debug;
5378 ---------------------
5379 -- Detect_Blocking --
5380 ---------------------
5382 -- pragma Detect_Blocking;
5384 when Pragma_Detect_Blocking =>
5385 GNAT_Pragma;
5386 Check_Arg_Count (0);
5387 Check_Valid_Configuration_Pragma;
5388 Detect_Blocking := True;
5390 -------------------
5391 -- Discard_Names --
5392 -------------------
5394 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
5396 when Pragma_Discard_Names => Discard_Names : declare
5397 E_Id : Entity_Id;
5398 E : Entity_Id;
5400 begin
5401 Check_Ada_83_Warning;
5403 -- Deal with configuration pragma case
5405 if Arg_Count = 0 and then Is_Configuration_Pragma then
5406 Global_Discard_Names := True;
5407 return;
5409 -- Otherwise, check correct appropriate context
5411 else
5412 Check_Is_In_Decl_Part_Or_Package_Spec;
5414 if Arg_Count = 0 then
5416 -- If there is no parameter, then from now on this pragma
5417 -- applies to any enumeration, exception or tagged type
5418 -- defined in the current declarative part.
5420 Set_Discard_Names (Current_Scope);
5421 return;
5423 else
5424 Check_Arg_Count (1);
5425 Check_Optional_Identifier (Arg1, Name_On);
5426 Check_Arg_Is_Local_Name (Arg1);
5427 E_Id := Expression (Arg1);
5429 if Etype (E_Id) = Any_Type then
5430 return;
5431 else
5432 E := Entity (E_Id);
5433 end if;
5435 if (Is_First_Subtype (E)
5436 and then (Is_Enumeration_Type (E)
5437 or else Is_Tagged_Type (E)))
5438 or else Ekind (E) = E_Exception
5439 then
5440 Set_Discard_Names (E);
5441 else
5442 Error_Pragma_Arg
5443 ("inappropriate entity for pragma%", Arg1);
5444 end if;
5445 end if;
5446 end if;
5447 end Discard_Names;
5449 ---------------
5450 -- Elaborate --
5451 ---------------
5453 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
5455 when Pragma_Elaborate => Elaborate : declare
5456 Plist : List_Id;
5457 Parent_Node : Node_Id;
5458 Arg : Node_Id;
5459 Citem : Node_Id;
5461 begin
5462 -- Pragma must be in context items list of a compilation unit
5464 if not Is_List_Member (N) then
5465 Pragma_Misplaced;
5466 return;
5468 else
5469 Plist := List_Containing (N);
5470 Parent_Node := Parent (Plist);
5472 if Parent_Node = Empty
5473 or else Nkind (Parent_Node) /= N_Compilation_Unit
5474 or else Context_Items (Parent_Node) /= Plist
5475 then
5476 Pragma_Misplaced;
5477 return;
5478 end if;
5479 end if;
5481 -- Must be at least one argument
5483 if Arg_Count = 0 then
5484 Error_Pragma ("pragma% requires at least one argument");
5485 end if;
5487 -- In Ada 83 mode, there can be no items following it in the
5488 -- context list except other pragmas and implicit with clauses
5489 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
5490 -- placement rule does not apply.
5492 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5493 Citem := Next (N);
5495 while Present (Citem) loop
5496 if Nkind (Citem) = N_Pragma
5497 or else (Nkind (Citem) = N_With_Clause
5498 and then Implicit_With (Citem))
5499 then
5500 null;
5501 else
5502 Error_Pragma
5503 ("(Ada 83) pragma% must be at end of context clause");
5504 end if;
5506 Next (Citem);
5507 end loop;
5508 end if;
5510 -- Finally, the arguments must all be units mentioned in a with
5511 -- clause in the same context clause. Note we already checked
5512 -- (in Par.Prag) that the arguments are either identifiers or
5514 Arg := Arg1;
5515 Outer : while Present (Arg) loop
5516 Citem := First (Plist);
5518 Inner : while Citem /= N loop
5519 if Nkind (Citem) = N_With_Clause
5520 and then Same_Name (Name (Citem), Expression (Arg))
5521 then
5522 Set_Elaborate_Present (Citem, True);
5523 Set_Unit_Name (Expression (Arg), Name (Citem));
5524 Set_Suppress_Elaboration_Warnings (Entity (Name (Citem)));
5525 exit Inner;
5526 end if;
5528 Next (Citem);
5529 end loop Inner;
5531 if Citem = N then
5532 Error_Pragma_Arg
5533 ("argument of pragma% is not with'ed unit", Arg);
5534 end if;
5536 Next (Arg);
5537 end loop Outer;
5539 -- Give a warning if operating in static mode with -gnatwl
5540 -- (elaboration warnings eanbled) switch set.
5542 if Elab_Warnings and not Dynamic_Elaboration_Checks then
5543 Error_Msg_N
5544 ("?use of pragma Elaborate may not be safe", N);
5545 Error_Msg_N
5546 ("?use pragma Elaborate_All instead if possible", N);
5547 end if;
5548 end Elaborate;
5550 -------------------
5551 -- Elaborate_All --
5552 -------------------
5554 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
5556 when Pragma_Elaborate_All => Elaborate_All : declare
5557 Plist : List_Id;
5558 Parent_Node : Node_Id;
5559 Arg : Node_Id;
5560 Citem : Node_Id;
5562 begin
5563 Check_Ada_83_Warning;
5565 -- Pragma must be in context items list of a compilation unit
5567 if not Is_List_Member (N) then
5568 Pragma_Misplaced;
5569 return;
5571 else
5572 Plist := List_Containing (N);
5573 Parent_Node := Parent (Plist);
5575 if Parent_Node = Empty
5576 or else Nkind (Parent_Node) /= N_Compilation_Unit
5577 or else Context_Items (Parent_Node) /= Plist
5578 then
5579 Pragma_Misplaced;
5580 return;
5581 end if;
5582 end if;
5584 -- Must be at least one argument
5586 if Arg_Count = 0 then
5587 Error_Pragma ("pragma% requires at least one argument");
5588 end if;
5590 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
5591 -- have to appear at the end of the context clause, but may
5592 -- appear mixed in with other items, even in Ada 83 mode.
5594 -- Final check: the arguments must all be units mentioned in
5595 -- a with clause in the same context clause. Note that we
5596 -- already checked (in Par.Prag) that all the arguments are
5597 -- either identifiers or selected components.
5599 Arg := Arg1;
5600 Outr : while Present (Arg) loop
5601 Citem := First (Plist);
5603 Innr : while Citem /= N loop
5604 if Nkind (Citem) = N_With_Clause
5605 and then Same_Name (Name (Citem), Expression (Arg))
5606 then
5607 Set_Elaborate_All_Present (Citem, True);
5608 Set_Unit_Name (Expression (Arg), Name (Citem));
5609 Set_Suppress_Elaboration_Warnings (Entity (Name (Citem)));
5610 exit Innr;
5611 end if;
5613 Next (Citem);
5614 end loop Innr;
5616 if Citem = N then
5617 Set_Error_Posted (N);
5618 Error_Pragma_Arg
5619 ("argument of pragma% is not with'ed unit", Arg);
5620 end if;
5622 Next (Arg);
5623 end loop Outr;
5624 end Elaborate_All;
5626 --------------------
5627 -- Elaborate_Body --
5628 --------------------
5630 -- pragma Elaborate_Body [( library_unit_NAME )];
5632 when Pragma_Elaborate_Body => Elaborate_Body : declare
5633 Cunit_Node : Node_Id;
5634 Cunit_Ent : Entity_Id;
5636 begin
5637 Check_Ada_83_Warning;
5638 Check_Valid_Library_Unit_Pragma;
5640 if Nkind (N) = N_Null_Statement then
5641 return;
5642 end if;
5644 Cunit_Node := Cunit (Current_Sem_Unit);
5645 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
5647 if Nkind (Unit (Cunit_Node)) = N_Package_Body
5648 or else
5649 Nkind (Unit (Cunit_Node)) = N_Subprogram_Body
5650 then
5651 Error_Pragma ("pragma% must refer to a spec, not a body");
5652 else
5653 Set_Body_Required (Cunit_Node, True);
5654 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
5656 -- If we are in dynamic elaboration mode, then we suppress
5657 -- elaboration warnings for the unit, since it is definitely
5658 -- fine NOT to do dynamic checks at the first level (and such
5659 -- checks will be suppressed because no elaboration boolean
5660 -- is created for Elaborate_Body packages).
5662 -- But in the static model of elaboration, Elaborate_Body is
5663 -- definitely NOT good enough to ensure elaboration safety on
5664 -- its own, since the body may WITH other units that are not
5665 -- safe from an elaboration point of view, so a client must
5666 -- still do an Elaborate_All on such units.
5668 -- Debug flag -gnatdD restores the old behavior of 3.13,
5669 -- where Elaborate_Body always suppressed elab warnings.
5671 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
5672 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
5673 end if;
5674 end if;
5675 end Elaborate_Body;
5677 ------------------------
5678 -- Elaboration_Checks --
5679 ------------------------
5681 -- pragma Elaboration_Checks (Static | Dynamic);
5683 when Pragma_Elaboration_Checks =>
5684 GNAT_Pragma;
5685 Check_Arg_Count (1);
5686 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
5687 Dynamic_Elaboration_Checks :=
5688 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
5690 ---------------
5691 -- Eliminate --
5692 ---------------
5694 -- pragma Eliminate (
5695 -- [Unit_Name =>] IDENTIFIER |
5696 -- SELECTED_COMPONENT
5697 -- [,[Entity =>] IDENTIFIER |
5698 -- SELECTED_COMPONENT |
5699 -- STRING_LITERAL]
5700 -- [,]OVERLOADING_RESOLUTION);
5702 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
5703 -- SOURCE_LOCATION
5705 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
5706 -- FUNCTION_PROFILE
5708 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
5710 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
5711 -- Result_Type => result_SUBTYPE_NAME]
5713 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
5714 -- SUBTYPE_NAME ::= STRING_LITERAL
5716 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
5717 -- SOURCE_TRACE ::= STRING_LITERAL
5719 when Pragma_Eliminate => Eliminate : declare
5720 Args : Args_List (1 .. 5);
5721 Names : constant Name_List (1 .. 5) := (
5722 Name_Unit_Name,
5723 Name_Entity,
5724 Name_Parameter_Types,
5725 Name_Result_Type,
5726 Name_Source_Location);
5728 Unit_Name : Node_Id renames Args (1);
5729 Entity : Node_Id renames Args (2);
5730 Parameter_Types : Node_Id renames Args (3);
5731 Result_Type : Node_Id renames Args (4);
5732 Source_Location : Node_Id renames Args (5);
5734 begin
5735 GNAT_Pragma;
5736 Check_Valid_Configuration_Pragma;
5737 Gather_Associations (Names, Args);
5739 if No (Unit_Name) then
5740 Error_Pragma ("missing Unit_Name argument for pragma%");
5741 end if;
5743 if No (Entity)
5744 and then (Present (Parameter_Types)
5745 or else
5746 Present (Result_Type)
5747 or else
5748 Present (Source_Location))
5749 then
5750 Error_Pragma ("missing Entity argument for pragma%");
5751 end if;
5753 if (Present (Parameter_Types)
5754 or else
5755 Present (Result_Type))
5756 and then
5757 Present (Source_Location)
5758 then
5759 Error_Pragma
5760 ("parameter profile and source location can not " &
5761 "be used together in pragma%");
5762 end if;
5764 Process_Eliminate_Pragma
5766 Unit_Name,
5767 Entity,
5768 Parameter_Types,
5769 Result_Type,
5770 Source_Location);
5771 end Eliminate;
5773 -------------------------
5774 -- Explicit_Overriding --
5775 -------------------------
5777 when Pragma_Explicit_Overriding =>
5778 Check_Valid_Configuration_Pragma;
5779 Check_Arg_Count (0);
5780 Explicit_Overriding := True;
5782 ------------
5783 -- Export --
5784 ------------
5786 -- pragma Export (
5787 -- [ Convention =>] convention_IDENTIFIER,
5788 -- [ Entity =>] local_NAME
5789 -- [, [External_Name =>] static_string_EXPRESSION ]
5790 -- [, [Link_Name =>] static_string_EXPRESSION ]);
5792 when Pragma_Export => Export : declare
5793 C : Convention_Id;
5794 Def_Id : Entity_Id;
5796 begin
5797 Check_Ada_83_Warning;
5798 Check_At_Least_N_Arguments (2);
5799 Check_At_Most_N_Arguments (4);
5800 Process_Convention (C, Def_Id);
5802 if Ekind (Def_Id) /= E_Constant then
5803 Note_Possible_Modification (Expression (Arg2));
5804 end if;
5806 Process_Interface_Name (Def_Id, Arg3, Arg4);
5807 Set_Exported (Def_Id, Arg2);
5808 end Export;
5810 ----------------------
5811 -- Export_Exception --
5812 ----------------------
5814 -- pragma Export_Exception (
5815 -- [Internal =>] LOCAL_NAME,
5816 -- [, [External =>] EXTERNAL_SYMBOL,]
5817 -- [, [Form =>] Ada | VMS]
5818 -- [, [Code =>] static_integer_EXPRESSION]);
5820 when Pragma_Export_Exception => Export_Exception : declare
5821 Args : Args_List (1 .. 4);
5822 Names : constant Name_List (1 .. 4) := (
5823 Name_Internal,
5824 Name_External,
5825 Name_Form,
5826 Name_Code);
5828 Internal : Node_Id renames Args (1);
5829 External : Node_Id renames Args (2);
5830 Form : Node_Id renames Args (3);
5831 Code : Node_Id renames Args (4);
5833 begin
5834 if Inside_A_Generic then
5835 Error_Pragma ("pragma% cannot be used for generic entities");
5836 end if;
5838 Gather_Associations (Names, Args);
5839 Process_Extended_Import_Export_Exception_Pragma (
5840 Arg_Internal => Internal,
5841 Arg_External => External,
5842 Arg_Form => Form,
5843 Arg_Code => Code);
5845 if not Is_VMS_Exception (Entity (Internal)) then
5846 Set_Exported (Entity (Internal), Internal);
5847 end if;
5848 end Export_Exception;
5850 ---------------------
5851 -- Export_Function --
5852 ---------------------
5854 -- pragma Export_Function (
5855 -- [Internal =>] LOCAL_NAME,
5856 -- [, [External =>] EXTERNAL_SYMBOL,]
5857 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5858 -- [, [Result_Type =>] TYPE_DESIGNATOR]
5859 -- [, [Mechanism =>] MECHANISM]
5860 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
5862 -- EXTERNAL_SYMBOL ::=
5863 -- IDENTIFIER
5864 -- | static_string_EXPRESSION
5866 -- PARAMETER_TYPES ::=
5867 -- null
5868 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5870 -- TYPE_DESIGNATOR ::=
5871 -- subtype_NAME
5872 -- | subtype_Name ' Access
5874 -- MECHANISM ::=
5875 -- MECHANISM_NAME
5876 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5878 -- MECHANISM_ASSOCIATION ::=
5879 -- [formal_parameter_NAME =>] MECHANISM_NAME
5881 -- MECHANISM_NAME ::=
5882 -- Value
5883 -- | Reference
5884 -- | Descriptor [([Class =>] CLASS_NAME)]
5886 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5888 when Pragma_Export_Function => Export_Function : declare
5889 Args : Args_List (1 .. 6);
5890 Names : constant Name_List (1 .. 6) := (
5891 Name_Internal,
5892 Name_External,
5893 Name_Parameter_Types,
5894 Name_Result_Type,
5895 Name_Mechanism,
5896 Name_Result_Mechanism);
5898 Internal : Node_Id renames Args (1);
5899 External : Node_Id renames Args (2);
5900 Parameter_Types : Node_Id renames Args (3);
5901 Result_Type : Node_Id renames Args (4);
5902 Mechanism : Node_Id renames Args (5);
5903 Result_Mechanism : Node_Id renames Args (6);
5905 begin
5906 GNAT_Pragma;
5907 Gather_Associations (Names, Args);
5908 Process_Extended_Import_Export_Subprogram_Pragma (
5909 Arg_Internal => Internal,
5910 Arg_External => External,
5911 Arg_Parameter_Types => Parameter_Types,
5912 Arg_Result_Type => Result_Type,
5913 Arg_Mechanism => Mechanism,
5914 Arg_Result_Mechanism => Result_Mechanism);
5915 end Export_Function;
5917 -------------------
5918 -- Export_Object --
5919 -------------------
5921 -- pragma Export_Object (
5922 -- [Internal =>] LOCAL_NAME,
5923 -- [, [External =>] EXTERNAL_SYMBOL]
5924 -- [, [Size =>] EXTERNAL_SYMBOL]);
5926 -- EXTERNAL_SYMBOL ::=
5927 -- IDENTIFIER
5928 -- | static_string_EXPRESSION
5930 -- PARAMETER_TYPES ::=
5931 -- null
5932 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5934 -- TYPE_DESIGNATOR ::=
5935 -- subtype_NAME
5936 -- | subtype_Name ' Access
5938 -- MECHANISM ::=
5939 -- MECHANISM_NAME
5940 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5942 -- MECHANISM_ASSOCIATION ::=
5943 -- [formal_parameter_NAME =>] MECHANISM_NAME
5945 -- MECHANISM_NAME ::=
5946 -- Value
5947 -- | Reference
5948 -- | Descriptor [([Class =>] CLASS_NAME)]
5950 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5952 when Pragma_Export_Object => Export_Object : declare
5953 Args : Args_List (1 .. 3);
5954 Names : constant Name_List (1 .. 3) := (
5955 Name_Internal,
5956 Name_External,
5957 Name_Size);
5959 Internal : Node_Id renames Args (1);
5960 External : Node_Id renames Args (2);
5961 Size : Node_Id renames Args (3);
5963 begin
5964 GNAT_Pragma;
5965 Gather_Associations (Names, Args);
5966 Process_Extended_Import_Export_Object_Pragma (
5967 Arg_Internal => Internal,
5968 Arg_External => External,
5969 Arg_Size => Size);
5970 end Export_Object;
5972 ----------------------
5973 -- Export_Procedure --
5974 ----------------------
5976 -- pragma Export_Procedure (
5977 -- [Internal =>] LOCAL_NAME,
5978 -- [, [External =>] EXTERNAL_SYMBOL,]
5979 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5980 -- [, [Mechanism =>] MECHANISM]);
5982 -- EXTERNAL_SYMBOL ::=
5983 -- IDENTIFIER
5984 -- | static_string_EXPRESSION
5986 -- PARAMETER_TYPES ::=
5987 -- null
5988 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5990 -- TYPE_DESIGNATOR ::=
5991 -- subtype_NAME
5992 -- | subtype_Name ' Access
5994 -- MECHANISM ::=
5995 -- MECHANISM_NAME
5996 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5998 -- MECHANISM_ASSOCIATION ::=
5999 -- [formal_parameter_NAME =>] MECHANISM_NAME
6001 -- MECHANISM_NAME ::=
6002 -- Value
6003 -- | Reference
6004 -- | Descriptor [([Class =>] CLASS_NAME)]
6006 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6008 when Pragma_Export_Procedure => Export_Procedure : declare
6009 Args : Args_List (1 .. 4);
6010 Names : constant Name_List (1 .. 4) := (
6011 Name_Internal,
6012 Name_External,
6013 Name_Parameter_Types,
6014 Name_Mechanism);
6016 Internal : Node_Id renames Args (1);
6017 External : Node_Id renames Args (2);
6018 Parameter_Types : Node_Id renames Args (3);
6019 Mechanism : Node_Id renames Args (4);
6021 begin
6022 GNAT_Pragma;
6023 Gather_Associations (Names, Args);
6024 Process_Extended_Import_Export_Subprogram_Pragma (
6025 Arg_Internal => Internal,
6026 Arg_External => External,
6027 Arg_Parameter_Types => Parameter_Types,
6028 Arg_Mechanism => Mechanism);
6029 end Export_Procedure;
6031 ------------------
6032 -- Export_Value --
6033 ------------------
6035 -- pragma Export_Value (
6036 -- [Value =>] static_integer_EXPRESSION,
6037 -- [Link_Name =>] static_string_EXPRESSION);
6039 when Pragma_Export_Value =>
6040 GNAT_Pragma;
6041 Check_Arg_Count (2);
6043 Check_Optional_Identifier (Arg1, Name_Value);
6044 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
6046 Check_Optional_Identifier (Arg2, Name_Link_Name);
6047 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6049 -----------------------------
6050 -- Export_Valued_Procedure --
6051 -----------------------------
6053 -- pragma Export_Valued_Procedure (
6054 -- [Internal =>] LOCAL_NAME,
6055 -- [, [External =>] EXTERNAL_SYMBOL,]
6056 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6057 -- [, [Mechanism =>] MECHANISM]);
6059 -- EXTERNAL_SYMBOL ::=
6060 -- IDENTIFIER
6061 -- | static_string_EXPRESSION
6063 -- PARAMETER_TYPES ::=
6064 -- null
6065 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6067 -- TYPE_DESIGNATOR ::=
6068 -- subtype_NAME
6069 -- | subtype_Name ' Access
6071 -- MECHANISM ::=
6072 -- MECHANISM_NAME
6073 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6075 -- MECHANISM_ASSOCIATION ::=
6076 -- [formal_parameter_NAME =>] MECHANISM_NAME
6078 -- MECHANISM_NAME ::=
6079 -- Value
6080 -- | Reference
6081 -- | Descriptor [([Class =>] CLASS_NAME)]
6083 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6085 when Pragma_Export_Valued_Procedure =>
6086 Export_Valued_Procedure : declare
6087 Args : Args_List (1 .. 4);
6088 Names : constant Name_List (1 .. 4) := (
6089 Name_Internal,
6090 Name_External,
6091 Name_Parameter_Types,
6092 Name_Mechanism);
6094 Internal : Node_Id renames Args (1);
6095 External : Node_Id renames Args (2);
6096 Parameter_Types : Node_Id renames Args (3);
6097 Mechanism : Node_Id renames Args (4);
6099 begin
6100 GNAT_Pragma;
6101 Gather_Associations (Names, Args);
6102 Process_Extended_Import_Export_Subprogram_Pragma (
6103 Arg_Internal => Internal,
6104 Arg_External => External,
6105 Arg_Parameter_Types => Parameter_Types,
6106 Arg_Mechanism => Mechanism);
6107 end Export_Valued_Procedure;
6109 -------------------
6110 -- Extend_System --
6111 -------------------
6113 -- pragma Extend_System ([Name =>] Identifier);
6115 when Pragma_Extend_System => Extend_System : declare
6116 begin
6117 GNAT_Pragma;
6118 Check_Valid_Configuration_Pragma;
6119 Check_Arg_Count (1);
6120 Check_Optional_Identifier (Arg1, Name_Name);
6121 Check_Arg_Is_Identifier (Arg1);
6123 Get_Name_String (Chars (Expression (Arg1)));
6125 if Name_Len > 4
6126 and then Name_Buffer (1 .. 4) = "aux_"
6127 then
6128 if Present (System_Extend_Pragma_Arg) then
6129 if Chars (Expression (Arg1)) =
6130 Chars (Expression (System_Extend_Pragma_Arg))
6131 then
6132 null;
6133 else
6134 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
6135 Error_Pragma ("pragma% conflicts with that at#");
6136 end if;
6138 else
6139 System_Extend_Pragma_Arg := Arg1;
6141 if not GNAT_Mode then
6142 System_Extend_Unit := Arg1;
6143 end if;
6144 end if;
6145 else
6146 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
6147 end if;
6148 end Extend_System;
6150 ------------------------
6151 -- Extensions_Allowed --
6152 ------------------------
6154 -- pragma Extensions_Allowed (ON | OFF);
6156 when Pragma_Extensions_Allowed =>
6157 GNAT_Pragma;
6158 Check_Arg_Count (1);
6159 Check_No_Identifiers;
6160 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6162 if Chars (Expression (Arg1)) = Name_On then
6163 Extensions_Allowed := True;
6164 Ada_Version := Ada_Version_Type'Last;
6165 else
6166 Extensions_Allowed := False;
6167 Ada_Version := Ada_Version_Type'Min (Ada_Version, Ada_95);
6168 end if;
6170 --------------
6171 -- External --
6172 --------------
6174 -- pragma External (
6175 -- [ Convention =>] convention_IDENTIFIER,
6176 -- [ Entity =>] local_NAME
6177 -- [, [External_Name =>] static_string_EXPRESSION ]
6178 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6180 when Pragma_External => External : declare
6181 C : Convention_Id;
6182 Def_Id : Entity_Id;
6184 begin
6185 GNAT_Pragma;
6186 Check_At_Least_N_Arguments (2);
6187 Check_At_Most_N_Arguments (4);
6188 Process_Convention (C, Def_Id);
6189 Note_Possible_Modification (Expression (Arg2));
6190 Process_Interface_Name (Def_Id, Arg3, Arg4);
6191 Set_Exported (Def_Id, Arg2);
6192 end External;
6194 --------------------------
6195 -- External_Name_Casing --
6196 --------------------------
6198 -- pragma External_Name_Casing (
6199 -- UPPERCASE | LOWERCASE
6200 -- [, AS_IS | UPPERCASE | LOWERCASE]);
6202 when Pragma_External_Name_Casing =>
6204 External_Name_Casing : declare
6205 begin
6206 GNAT_Pragma;
6207 Check_No_Identifiers;
6209 if Arg_Count = 2 then
6210 Check_Arg_Is_One_Of
6211 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
6213 case Chars (Get_Pragma_Arg (Arg2)) is
6214 when Name_As_Is =>
6215 Opt.External_Name_Exp_Casing := As_Is;
6217 when Name_Uppercase =>
6218 Opt.External_Name_Exp_Casing := Uppercase;
6220 when Name_Lowercase =>
6221 Opt.External_Name_Exp_Casing := Lowercase;
6223 when others =>
6224 null;
6225 end case;
6227 else
6228 Check_Arg_Count (1);
6229 end if;
6231 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
6233 case Chars (Get_Pragma_Arg (Arg1)) is
6234 when Name_Uppercase =>
6235 Opt.External_Name_Imp_Casing := Uppercase;
6237 when Name_Lowercase =>
6238 Opt.External_Name_Imp_Casing := Lowercase;
6240 when others =>
6241 null;
6242 end case;
6243 end External_Name_Casing;
6245 ---------------------------
6246 -- Finalize_Storage_Only --
6247 ---------------------------
6249 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
6251 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
6252 Assoc : constant Node_Id := Arg1;
6253 Type_Id : constant Node_Id := Expression (Assoc);
6254 Typ : Entity_Id;
6256 begin
6257 Check_No_Identifiers;
6258 Check_Arg_Count (1);
6259 Check_Arg_Is_Local_Name (Arg1);
6261 Find_Type (Type_Id);
6262 Typ := Entity (Type_Id);
6264 if Typ = Any_Type
6265 or else Rep_Item_Too_Early (Typ, N)
6266 then
6267 return;
6268 else
6269 Typ := Underlying_Type (Typ);
6270 end if;
6272 if not Is_Controlled (Typ) then
6273 Error_Pragma ("pragma% must specify controlled type");
6274 end if;
6276 Check_First_Subtype (Arg1);
6278 if Finalize_Storage_Only (Typ) then
6279 Error_Pragma ("duplicate pragma%, only one allowed");
6281 elsif not Rep_Item_Too_Late (Typ, N) then
6282 Set_Finalize_Storage_Only (Base_Type (Typ), True);
6283 end if;
6284 end Finalize_Storage;
6286 --------------------------
6287 -- Float_Representation --
6288 --------------------------
6290 -- pragma Float_Representation (VAX_Float | IEEE_Float);
6292 when Pragma_Float_Representation => Float_Representation : declare
6293 Argx : Node_Id;
6294 Digs : Nat;
6295 Ent : Entity_Id;
6297 begin
6298 GNAT_Pragma;
6300 if Arg_Count = 1 then
6301 Check_Valid_Configuration_Pragma;
6302 else
6303 Check_Arg_Count (2);
6304 Check_Optional_Identifier (Arg2, Name_Entity);
6305 Check_Arg_Is_Local_Name (Arg2);
6306 end if;
6308 Check_No_Identifier (Arg1);
6309 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
6311 if not OpenVMS_On_Target then
6312 if Chars (Expression (Arg1)) = Name_VAX_Float then
6313 Error_Pragma
6314 ("?pragma% ignored (applies only to Open'V'M'S)");
6315 end if;
6317 return;
6318 end if;
6320 -- One argument case
6322 if Arg_Count = 1 then
6324 if Chars (Expression (Arg1)) = Name_VAX_Float then
6326 if Opt.Float_Format = 'I' then
6327 Error_Pragma ("'I'E'E'E format previously specified");
6328 end if;
6330 Opt.Float_Format := 'V';
6332 else
6333 if Opt.Float_Format = 'V' then
6334 Error_Pragma ("'V'A'X format previously specified");
6335 end if;
6337 Opt.Float_Format := 'I';
6338 end if;
6340 Set_Standard_Fpt_Formats;
6342 -- Two argument case
6344 else
6345 Argx := Get_Pragma_Arg (Arg2);
6347 if not Is_Entity_Name (Argx)
6348 or else not Is_Floating_Point_Type (Entity (Argx))
6349 then
6350 Error_Pragma_Arg
6351 ("second argument of% pragma must be floating-point type",
6352 Arg2);
6353 end if;
6355 Ent := Entity (Argx);
6356 Digs := UI_To_Int (Digits_Value (Ent));
6358 -- Two arguments, VAX_Float case
6360 if Chars (Expression (Arg1)) = Name_VAX_Float then
6362 case Digs is
6363 when 6 => Set_F_Float (Ent);
6364 when 9 => Set_D_Float (Ent);
6365 when 15 => Set_G_Float (Ent);
6367 when others =>
6368 Error_Pragma_Arg
6369 ("wrong digits value, must be 6,9 or 15", Arg2);
6370 end case;
6372 -- Two arguments, IEEE_Float case
6374 else
6375 case Digs is
6376 when 6 => Set_IEEE_Short (Ent);
6377 when 15 => Set_IEEE_Long (Ent);
6379 when others =>
6380 Error_Pragma_Arg
6381 ("wrong digits value, must be 6 or 15", Arg2);
6382 end case;
6383 end if;
6384 end if;
6385 end Float_Representation;
6387 -----------
6388 -- Ident --
6389 -----------
6391 -- pragma Ident (static_string_EXPRESSION)
6393 -- Note: pragma Comment shares this processing. Pragma Comment
6394 -- is identical to Ident, except that the restriction of the
6395 -- argument to 31 characters and the placement restrictions
6396 -- are not enforced for pragma Comment.
6398 when Pragma_Ident | Pragma_Comment => Ident : declare
6399 Str : Node_Id;
6401 begin
6402 GNAT_Pragma;
6403 Check_Arg_Count (1);
6404 Check_No_Identifiers;
6405 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
6407 -- For pragma Ident, preserve DEC compatibility by requiring
6408 -- the pragma to appear in a declarative part or package spec.
6410 if Prag_Id = Pragma_Ident then
6411 Check_Is_In_Decl_Part_Or_Package_Spec;
6412 end if;
6414 Str := Expr_Value_S (Expression (Arg1));
6416 declare
6417 CS : Node_Id;
6418 GP : Node_Id;
6420 begin
6421 GP := Parent (Parent (N));
6423 if Nkind (GP) = N_Package_Declaration
6424 or else
6425 Nkind (GP) = N_Generic_Package_Declaration
6426 then
6427 GP := Parent (GP);
6428 end if;
6430 -- If we have a compilation unit, then record the ident
6431 -- value, checking for improper duplication.
6433 if Nkind (GP) = N_Compilation_Unit then
6434 CS := Ident_String (Current_Sem_Unit);
6436 if Present (CS) then
6438 -- For Ident, we do not permit multiple instances
6440 if Prag_Id = Pragma_Ident then
6441 Error_Pragma ("duplicate% pragma not permitted");
6443 -- For Comment, we concatenate the string, unless we
6444 -- want to preserve the tree structure for ASIS.
6446 elsif not ASIS_Mode then
6447 Start_String (Strval (CS));
6448 Store_String_Char (' ');
6449 Store_String_Chars (Strval (Str));
6450 Set_Strval (CS, End_String);
6451 end if;
6453 else
6454 -- In VMS, the effect of IDENT is achieved by passing
6455 -- IDENTIFICATION=name as a --for-linker switch.
6457 if OpenVMS_On_Target then
6458 Start_String;
6459 Store_String_Chars
6460 ("--for-linker=IDENTIFICATION=");
6461 String_To_Name_Buffer (Strval (Str));
6462 Store_String_Chars (Name_Buffer (1 .. Name_Len));
6464 -- Only the last processed IDENT is saved. The main
6465 -- purpose is so an IDENT associated with a main
6466 -- procedure will be used in preference to an IDENT
6467 -- associated with a with'd package.
6469 Replace_Linker_Option_String
6470 (End_String, "--for-linker=IDENTIFICATION=");
6471 end if;
6473 Set_Ident_String (Current_Sem_Unit, Str);
6474 end if;
6476 -- For subunits, we just ignore the Ident, since in GNAT
6477 -- these are not separate object files, and hence not
6478 -- separate units in the unit table.
6480 elsif Nkind (GP) = N_Subunit then
6481 null;
6483 -- Otherwise we have a misplaced pragma Ident, but we ignore
6484 -- this if we are in an instantiation, since it comes from
6485 -- a generic, and has no relevance to the instantiation.
6487 elsif Prag_Id = Pragma_Ident then
6488 if Instantiation_Location (Loc) = No_Location then
6489 Error_Pragma ("pragma% only allowed at outer level");
6490 end if;
6491 end if;
6492 end;
6493 end Ident;
6495 ------------
6496 -- Import --
6497 ------------
6499 -- pragma Import (
6500 -- [ Convention =>] convention_IDENTIFIER,
6501 -- [ Entity =>] local_NAME
6502 -- [, [External_Name =>] static_string_EXPRESSION ]
6503 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6505 when Pragma_Import =>
6506 Check_Ada_83_Warning;
6507 Check_At_Least_N_Arguments (2);
6508 Check_At_Most_N_Arguments (4);
6509 Process_Import_Or_Interface;
6511 ----------------------
6512 -- Import_Exception --
6513 ----------------------
6515 -- pragma Import_Exception (
6516 -- [Internal =>] LOCAL_NAME,
6517 -- [, [External =>] EXTERNAL_SYMBOL,]
6518 -- [, [Form =>] Ada | VMS]
6519 -- [, [Code =>] static_integer_EXPRESSION]);
6521 when Pragma_Import_Exception => Import_Exception : declare
6522 Args : Args_List (1 .. 4);
6523 Names : constant Name_List (1 .. 4) := (
6524 Name_Internal,
6525 Name_External,
6526 Name_Form,
6527 Name_Code);
6529 Internal : Node_Id renames Args (1);
6530 External : Node_Id renames Args (2);
6531 Form : Node_Id renames Args (3);
6532 Code : Node_Id renames Args (4);
6534 begin
6535 Gather_Associations (Names, Args);
6537 if Present (External) and then Present (Code) then
6538 Error_Pragma
6539 ("cannot give both External and Code options for pragma%");
6540 end if;
6542 Process_Extended_Import_Export_Exception_Pragma (
6543 Arg_Internal => Internal,
6544 Arg_External => External,
6545 Arg_Form => Form,
6546 Arg_Code => Code);
6548 if not Is_VMS_Exception (Entity (Internal)) then
6549 Set_Imported (Entity (Internal));
6550 end if;
6551 end Import_Exception;
6553 ---------------------
6554 -- Import_Function --
6555 ---------------------
6557 -- pragma Import_Function (
6558 -- [Internal =>] LOCAL_NAME,
6559 -- [, [External =>] EXTERNAL_SYMBOL]
6560 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6561 -- [, [Result_Type =>] SUBTYPE_MARK]
6562 -- [, [Mechanism =>] MECHANISM]
6563 -- [, [Result_Mechanism =>] MECHANISM_NAME]
6564 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6566 -- EXTERNAL_SYMBOL ::=
6567 -- IDENTIFIER
6568 -- | static_string_EXPRESSION
6570 -- PARAMETER_TYPES ::=
6571 -- null
6572 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6574 -- TYPE_DESIGNATOR ::=
6575 -- subtype_NAME
6576 -- | subtype_Name ' Access
6578 -- MECHANISM ::=
6579 -- MECHANISM_NAME
6580 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6582 -- MECHANISM_ASSOCIATION ::=
6583 -- [formal_parameter_NAME =>] MECHANISM_NAME
6585 -- MECHANISM_NAME ::=
6586 -- Value
6587 -- | Reference
6588 -- | Descriptor [([Class =>] CLASS_NAME)]
6590 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6592 when Pragma_Import_Function => Import_Function : declare
6593 Args : Args_List (1 .. 7);
6594 Names : constant Name_List (1 .. 7) := (
6595 Name_Internal,
6596 Name_External,
6597 Name_Parameter_Types,
6598 Name_Result_Type,
6599 Name_Mechanism,
6600 Name_Result_Mechanism,
6601 Name_First_Optional_Parameter);
6603 Internal : Node_Id renames Args (1);
6604 External : Node_Id renames Args (2);
6605 Parameter_Types : Node_Id renames Args (3);
6606 Result_Type : Node_Id renames Args (4);
6607 Mechanism : Node_Id renames Args (5);
6608 Result_Mechanism : Node_Id renames Args (6);
6609 First_Optional_Parameter : Node_Id renames Args (7);
6611 begin
6612 GNAT_Pragma;
6613 Gather_Associations (Names, Args);
6614 Process_Extended_Import_Export_Subprogram_Pragma (
6615 Arg_Internal => Internal,
6616 Arg_External => External,
6617 Arg_Parameter_Types => Parameter_Types,
6618 Arg_Result_Type => Result_Type,
6619 Arg_Mechanism => Mechanism,
6620 Arg_Result_Mechanism => Result_Mechanism,
6621 Arg_First_Optional_Parameter => First_Optional_Parameter);
6622 end Import_Function;
6624 -------------------
6625 -- Import_Object --
6626 -------------------
6628 -- pragma Import_Object (
6629 -- [Internal =>] LOCAL_NAME,
6630 -- [, [External =>] EXTERNAL_SYMBOL]
6631 -- [, [Size =>] EXTERNAL_SYMBOL]);
6633 -- EXTERNAL_SYMBOL ::=
6634 -- IDENTIFIER
6635 -- | static_string_EXPRESSION
6637 when Pragma_Import_Object => Import_Object : declare
6638 Args : Args_List (1 .. 3);
6639 Names : constant Name_List (1 .. 3) := (
6640 Name_Internal,
6641 Name_External,
6642 Name_Size);
6644 Internal : Node_Id renames Args (1);
6645 External : Node_Id renames Args (2);
6646 Size : Node_Id renames Args (3);
6648 begin
6649 GNAT_Pragma;
6650 Gather_Associations (Names, Args);
6651 Process_Extended_Import_Export_Object_Pragma (
6652 Arg_Internal => Internal,
6653 Arg_External => External,
6654 Arg_Size => Size);
6655 end Import_Object;
6657 ----------------------
6658 -- Import_Procedure --
6659 ----------------------
6661 -- pragma Import_Procedure (
6662 -- [Internal =>] LOCAL_NAME,
6663 -- [, [External =>] EXTERNAL_SYMBOL]
6664 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6665 -- [, [Mechanism =>] MECHANISM]
6666 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6668 -- EXTERNAL_SYMBOL ::=
6669 -- IDENTIFIER
6670 -- | static_string_EXPRESSION
6672 -- PARAMETER_TYPES ::=
6673 -- null
6674 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6676 -- TYPE_DESIGNATOR ::=
6677 -- subtype_NAME
6678 -- | subtype_Name ' Access
6680 -- MECHANISM ::=
6681 -- MECHANISM_NAME
6682 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6684 -- MECHANISM_ASSOCIATION ::=
6685 -- [formal_parameter_NAME =>] MECHANISM_NAME
6687 -- MECHANISM_NAME ::=
6688 -- Value
6689 -- | Reference
6690 -- | Descriptor [([Class =>] CLASS_NAME)]
6692 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6694 when Pragma_Import_Procedure => Import_Procedure : declare
6695 Args : Args_List (1 .. 5);
6696 Names : constant Name_List (1 .. 5) := (
6697 Name_Internal,
6698 Name_External,
6699 Name_Parameter_Types,
6700 Name_Mechanism,
6701 Name_First_Optional_Parameter);
6703 Internal : Node_Id renames Args (1);
6704 External : Node_Id renames Args (2);
6705 Parameter_Types : Node_Id renames Args (3);
6706 Mechanism : Node_Id renames Args (4);
6707 First_Optional_Parameter : Node_Id renames Args (5);
6709 begin
6710 GNAT_Pragma;
6711 Gather_Associations (Names, Args);
6712 Process_Extended_Import_Export_Subprogram_Pragma (
6713 Arg_Internal => Internal,
6714 Arg_External => External,
6715 Arg_Parameter_Types => Parameter_Types,
6716 Arg_Mechanism => Mechanism,
6717 Arg_First_Optional_Parameter => First_Optional_Parameter);
6718 end Import_Procedure;
6720 -----------------------------
6721 -- Import_Valued_Procedure --
6722 -----------------------------
6724 -- pragma Import_Valued_Procedure (
6725 -- [Internal =>] LOCAL_NAME,
6726 -- [, [External =>] EXTERNAL_SYMBOL]
6727 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6728 -- [, [Mechanism =>] MECHANISM]
6729 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6731 -- EXTERNAL_SYMBOL ::=
6732 -- IDENTIFIER
6733 -- | static_string_EXPRESSION
6735 -- PARAMETER_TYPES ::=
6736 -- null
6737 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6739 -- TYPE_DESIGNATOR ::=
6740 -- subtype_NAME
6741 -- | subtype_Name ' Access
6743 -- MECHANISM ::=
6744 -- MECHANISM_NAME
6745 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6747 -- MECHANISM_ASSOCIATION ::=
6748 -- [formal_parameter_NAME =>] MECHANISM_NAME
6750 -- MECHANISM_NAME ::=
6751 -- Value
6752 -- | Reference
6753 -- | Descriptor [([Class =>] CLASS_NAME)]
6755 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6757 when Pragma_Import_Valued_Procedure =>
6758 Import_Valued_Procedure : declare
6759 Args : Args_List (1 .. 5);
6760 Names : constant Name_List (1 .. 5) := (
6761 Name_Internal,
6762 Name_External,
6763 Name_Parameter_Types,
6764 Name_Mechanism,
6765 Name_First_Optional_Parameter);
6767 Internal : Node_Id renames Args (1);
6768 External : Node_Id renames Args (2);
6769 Parameter_Types : Node_Id renames Args (3);
6770 Mechanism : Node_Id renames Args (4);
6771 First_Optional_Parameter : Node_Id renames Args (5);
6773 begin
6774 GNAT_Pragma;
6775 Gather_Associations (Names, Args);
6776 Process_Extended_Import_Export_Subprogram_Pragma (
6777 Arg_Internal => Internal,
6778 Arg_External => External,
6779 Arg_Parameter_Types => Parameter_Types,
6780 Arg_Mechanism => Mechanism,
6781 Arg_First_Optional_Parameter => First_Optional_Parameter);
6782 end Import_Valued_Procedure;
6784 ------------------------
6785 -- Initialize_Scalars --
6786 ------------------------
6788 -- pragma Initialize_Scalars;
6790 when Pragma_Initialize_Scalars =>
6791 GNAT_Pragma;
6792 Check_Arg_Count (0);
6793 Check_Valid_Configuration_Pragma;
6794 Check_Restriction (No_Initialize_Scalars, N);
6796 if not Restriction_Active (No_Initialize_Scalars) then
6797 Init_Or_Norm_Scalars := True;
6798 Initialize_Scalars := True;
6799 end if;
6801 ------------
6802 -- Inline --
6803 ------------
6805 -- pragma Inline ( NAME {, NAME} );
6807 when Pragma_Inline =>
6809 -- Pragma is active if inlining option is active
6811 if Inline_Active then
6812 Process_Inline (True);
6814 -- Pragma is active in a predefined file in config run time mode
6816 elsif Configurable_Run_Time_Mode
6817 and then
6818 Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
6819 then
6820 Process_Inline (True);
6822 -- Otherwise inlining is not active
6824 else
6825 Process_Inline (False);
6826 end if;
6828 -------------------
6829 -- Inline_Always --
6830 -------------------
6832 -- pragma Inline_Always ( NAME {, NAME} );
6834 when Pragma_Inline_Always =>
6835 Process_Inline (True);
6837 --------------------
6838 -- Inline_Generic --
6839 --------------------
6841 -- pragma Inline_Generic (NAME {, NAME});
6843 when Pragma_Inline_Generic =>
6844 Process_Generic_List;
6846 ----------------------
6847 -- Inspection_Point --
6848 ----------------------
6850 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
6852 when Pragma_Inspection_Point => Inspection_Point : declare
6853 Arg : Node_Id;
6854 Exp : Node_Id;
6856 begin
6857 if Arg_Count > 0 then
6858 Arg := Arg1;
6859 loop
6860 Exp := Expression (Arg);
6861 Analyze (Exp);
6863 if not Is_Entity_Name (Exp)
6864 or else not Is_Object (Entity (Exp))
6865 then
6866 Error_Pragma_Arg ("object name required", Arg);
6867 end if;
6869 Next (Arg);
6870 exit when No (Arg);
6871 end loop;
6872 end if;
6873 end Inspection_Point;
6875 ---------------
6876 -- Interface --
6877 ---------------
6879 -- pragma Interface (
6880 -- convention_IDENTIFIER,
6881 -- local_NAME );
6883 when Pragma_Interface =>
6884 GNAT_Pragma;
6885 Check_Arg_Count (2);
6886 Check_No_Identifiers;
6887 Process_Import_Or_Interface;
6889 --------------------
6890 -- Interface_Name --
6891 --------------------
6893 -- pragma Interface_Name (
6894 -- [ Entity =>] local_NAME
6895 -- [,[External_Name =>] static_string_EXPRESSION ]
6896 -- [,[Link_Name =>] static_string_EXPRESSION ]);
6898 when Pragma_Interface_Name => Interface_Name : declare
6899 Id : Node_Id;
6900 Def_Id : Entity_Id;
6901 Hom_Id : Entity_Id;
6902 Found : Boolean;
6904 begin
6905 GNAT_Pragma;
6906 Check_At_Least_N_Arguments (2);
6907 Check_At_Most_N_Arguments (3);
6908 Id := Expression (Arg1);
6909 Analyze (Id);
6911 if not Is_Entity_Name (Id) then
6912 Error_Pragma_Arg
6913 ("first argument for pragma% must be entity name", Arg1);
6914 elsif Etype (Id) = Any_Type then
6915 return;
6916 else
6917 Def_Id := Entity (Id);
6918 end if;
6920 -- Special DEC-compatible processing for the object case,
6921 -- forces object to be imported.
6923 if Ekind (Def_Id) = E_Variable then
6924 Kill_Size_Check_Code (Def_Id);
6925 Note_Possible_Modification (Id);
6927 -- Initialization is not allowed for imported variable
6929 if Present (Expression (Parent (Def_Id)))
6930 and then Comes_From_Source (Expression (Parent (Def_Id)))
6931 then
6932 Error_Msg_Sloc := Sloc (Def_Id);
6933 Error_Pragma_Arg
6934 ("no initialization allowed for declaration of& #",
6935 Arg2);
6937 else
6938 -- For compatibility, support VADS usage of providing both
6939 -- pragmas Interface and Interface_Name to obtain the effect
6940 -- of a single Import pragma.
6942 if Is_Imported (Def_Id)
6943 and then Present (First_Rep_Item (Def_Id))
6944 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
6945 and then Chars (First_Rep_Item (Def_Id)) = Name_Interface
6946 then
6947 null;
6948 else
6949 Set_Imported (Def_Id);
6950 end if;
6952 Set_Is_Public (Def_Id);
6953 Process_Interface_Name (Def_Id, Arg2, Arg3);
6954 end if;
6956 -- Otherwise must be subprogram
6958 elsif not Is_Subprogram (Def_Id) then
6959 Error_Pragma_Arg
6960 ("argument of pragma% is not subprogram", Arg1);
6962 else
6963 Check_At_Most_N_Arguments (3);
6964 Hom_Id := Def_Id;
6965 Found := False;
6967 -- Loop through homonyms
6969 loop
6970 Def_Id := Get_Base_Subprogram (Hom_Id);
6972 if Is_Imported (Def_Id) then
6973 Process_Interface_Name (Def_Id, Arg2, Arg3);
6974 Found := True;
6975 end if;
6977 Hom_Id := Homonym (Hom_Id);
6979 exit when No (Hom_Id)
6980 or else Scope (Hom_Id) /= Current_Scope;
6981 end loop;
6983 if not Found then
6984 Error_Pragma_Arg
6985 ("argument of pragma% is not imported subprogram",
6986 Arg1);
6987 end if;
6988 end if;
6989 end Interface_Name;
6991 -----------------------
6992 -- Interrupt_Handler --
6993 -----------------------
6995 -- pragma Interrupt_Handler (handler_NAME);
6997 when Pragma_Interrupt_Handler =>
6998 Check_Ada_83_Warning;
6999 Check_Arg_Count (1);
7000 Check_No_Identifiers;
7002 if No_Run_Time_Mode then
7003 Error_Msg_CRT ("Interrupt_Handler pragma", N);
7004 else
7005 Check_Interrupt_Or_Attach_Handler;
7006 Process_Interrupt_Or_Attach_Handler;
7007 end if;
7009 ------------------------
7010 -- Interrupt_Priority --
7011 ------------------------
7013 -- pragma Interrupt_Priority [(EXPRESSION)];
7015 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
7016 P : constant Node_Id := Parent (N);
7017 Arg : Node_Id;
7019 begin
7020 Check_Ada_83_Warning;
7022 if Arg_Count /= 0 then
7023 Arg := Expression (Arg1);
7024 Check_Arg_Count (1);
7025 Check_No_Identifiers;
7027 -- The expression must be analyzed in the special manner
7028 -- described in "Handling of Default and Per-Object
7029 -- Expressions" in sem.ads.
7031 Analyze_Per_Use_Expression (Arg, RTE (RE_Interrupt_Priority));
7032 end if;
7034 if Nkind (P) /= N_Task_Definition
7035 and then Nkind (P) /= N_Protected_Definition
7036 then
7037 Pragma_Misplaced;
7038 return;
7040 elsif Has_Priority_Pragma (P) then
7041 Error_Pragma ("duplicate pragma% not allowed");
7043 else
7044 Set_Has_Priority_Pragma (P, True);
7045 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7046 end if;
7047 end Interrupt_Priority;
7049 ---------------------
7050 -- Interrupt_State --
7051 ---------------------
7053 -- pragma Interrupt_State (
7054 -- [Name =>] INTERRUPT_ID,
7055 -- [State =>] INTERRUPT_STATE);
7057 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
7058 -- INTERRUPT_STATE => System | Runtime | User
7060 -- Note: if the interrupt id is given as an identifier, then
7061 -- it must be one of the identifiers in Ada.Interrupts.Names.
7062 -- Otherwise it is given as a static integer expression which
7063 -- must be in the range of Ada.Interrupts.Interrupt_ID.
7065 when Pragma_Interrupt_State => Interrupt_State : declare
7067 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
7068 -- This is the entity Ada.Interrupts.Interrupt_ID;
7070 State_Type : Character;
7071 -- Set to 's'/'r'/'u' for System/Runtime/User
7073 IST_Num : Pos;
7074 -- Index to entry in Interrupt_States table
7076 Int_Val : Uint;
7077 -- Value of interrupt
7079 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
7080 -- The first argument to the pragma
7082 Int_Ent : Entity_Id;
7083 -- Interrupt entity in Ada.Interrupts.Names
7085 begin
7086 GNAT_Pragma;
7087 Check_Arg_Count (2);
7089 Check_Optional_Identifier (Arg1, Name_Name);
7090 Check_Optional_Identifier (Arg2, "state");
7091 Check_Arg_Is_Identifier (Arg2);
7093 -- First argument is identifier
7095 if Nkind (Arg1X) = N_Identifier then
7097 -- Search list of names in Ada.Interrupts.Names
7099 Int_Ent := First_Entity (RTE (RE_Names));
7100 loop
7101 if No (Int_Ent) then
7102 Error_Pragma_Arg ("invalid interrupt name", Arg1);
7104 elsif Chars (Int_Ent) = Chars (Arg1X) then
7105 Int_Val := Expr_Value (Constant_Value (Int_Ent));
7106 exit;
7107 end if;
7109 Next_Entity (Int_Ent);
7110 end loop;
7112 -- First argument is not an identifier, so it must be a
7113 -- static expression of type Ada.Interrupts.Interrupt_ID.
7115 else
7116 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7117 Int_Val := Expr_Value (Arg1X);
7119 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
7120 or else
7121 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
7122 then
7123 Error_Pragma_Arg
7124 ("value not in range of type " &
7125 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
7126 end if;
7127 end if;
7129 -- Check OK state
7131 case Chars (Get_Pragma_Arg (Arg2)) is
7132 when Name_Runtime => State_Type := 'r';
7133 when Name_System => State_Type := 's';
7134 when Name_User => State_Type := 'u';
7136 when others =>
7137 Error_Pragma_Arg ("invalid interrupt state", Arg2);
7138 end case;
7140 -- Check if entry is already stored
7142 IST_Num := Interrupt_States.First;
7143 loop
7144 -- If entry not found, add it
7146 if IST_Num > Interrupt_States.Last then
7147 Interrupt_States.Append
7148 ((Interrupt_Number => UI_To_Int (Int_Val),
7149 Interrupt_State => State_Type,
7150 Pragma_Loc => Loc));
7151 exit;
7153 -- Case of entry for the same entry
7155 elsif Int_Val = Interrupt_States.Table (IST_Num).
7156 Interrupt_Number
7157 then
7158 -- If state matches, done, no need to make redundant entry
7160 exit when
7161 State_Type = Interrupt_States.Table (IST_Num).
7162 Interrupt_State;
7164 -- Otherwise if state does not match, error
7166 Error_Msg_Sloc :=
7167 Interrupt_States.Table (IST_Num).Pragma_Loc;
7168 Error_Pragma_Arg
7169 ("state conflicts with that given at #", Arg2);
7170 exit;
7171 end if;
7173 IST_Num := IST_Num + 1;
7174 end loop;
7175 end Interrupt_State;
7177 ----------------------
7178 -- Java_Constructor --
7179 ----------------------
7181 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
7183 when Pragma_Java_Constructor => Java_Constructor : declare
7184 Id : Entity_Id;
7185 Def_Id : Entity_Id;
7186 Hom_Id : Entity_Id;
7188 begin
7189 GNAT_Pragma;
7190 Check_Arg_Count (1);
7191 Check_Optional_Identifier (Arg1, Name_Entity);
7192 Check_Arg_Is_Local_Name (Arg1);
7194 Id := Expression (Arg1);
7195 Find_Program_Unit_Name (Id);
7197 -- If we did not find the name, we are done
7199 if Etype (Id) = Any_Type then
7200 return;
7201 end if;
7203 Hom_Id := Entity (Id);
7205 -- Loop through homonyms
7207 loop
7208 Def_Id := Get_Base_Subprogram (Hom_Id);
7210 -- The constructor is required to be a function returning
7211 -- an access type whose designated type has convention Java.
7213 if Ekind (Def_Id) = E_Function
7214 and then Ekind (Etype (Def_Id)) in Access_Kind
7215 and then
7216 (Atree.Convention
7217 (Designated_Type (Etype (Def_Id))) = Convention_Java
7218 or else
7219 Atree.Convention
7220 (Root_Type (Designated_Type (Etype (Def_Id))))
7221 = Convention_Java)
7222 then
7223 Set_Is_Constructor (Def_Id);
7224 Set_Convention (Def_Id, Convention_Java);
7226 else
7227 Error_Pragma_Arg
7228 ("pragma% requires function returning a 'Java access type",
7229 Arg1);
7230 end if;
7232 Hom_Id := Homonym (Hom_Id);
7234 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
7235 end loop;
7236 end Java_Constructor;
7238 ----------------------
7239 -- Java_Interface --
7240 ----------------------
7242 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
7244 when Pragma_Java_Interface => Java_Interface : declare
7245 Arg : Node_Id;
7246 Typ : Entity_Id;
7248 begin
7249 GNAT_Pragma;
7250 Check_Arg_Count (1);
7251 Check_Optional_Identifier (Arg1, Name_Entity);
7252 Check_Arg_Is_Local_Name (Arg1);
7254 Arg := Expression (Arg1);
7255 Analyze (Arg);
7257 if Etype (Arg) = Any_Type then
7258 return;
7259 end if;
7261 if not Is_Entity_Name (Arg)
7262 or else not Is_Type (Entity (Arg))
7263 then
7264 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7265 end if;
7267 Typ := Underlying_Type (Entity (Arg));
7269 -- For now we simply check some of the semantic constraints
7270 -- on the type. This currently leaves out some restrictions
7271 -- on interface types, namely that the parent type must be
7272 -- java.lang.Object.Typ and that all primitives of the type
7273 -- should be declared abstract. ???
7275 if not Is_Tagged_Type (Typ) or else not Is_Abstract (Typ) then
7276 Error_Pragma_Arg ("pragma% requires an abstract "
7277 & "tagged type", Arg1);
7279 elsif not Has_Discriminants (Typ)
7280 or else Ekind (Etype (First_Discriminant (Typ)))
7281 /= E_Anonymous_Access_Type
7282 or else
7283 not Is_Class_Wide_Type
7284 (Designated_Type (Etype (First_Discriminant (Typ))))
7285 then
7286 Error_Pragma_Arg
7287 ("type must have a class-wide access discriminant", Arg1);
7288 end if;
7289 end Java_Interface;
7291 ----------------
7292 -- Keep_Names --
7293 ----------------
7295 -- pragma Keep_Names ([On => ] local_NAME);
7297 when Pragma_Keep_Names => Keep_Names : declare
7298 Arg : Node_Id;
7300 begin
7301 GNAT_Pragma;
7302 Check_Arg_Count (1);
7303 Check_Optional_Identifier (Arg1, Name_On);
7304 Check_Arg_Is_Local_Name (Arg1);
7306 Arg := Expression (Arg1);
7307 Analyze (Arg);
7309 if Etype (Arg) = Any_Type then
7310 return;
7311 end if;
7313 if not Is_Entity_Name (Arg)
7314 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
7315 then
7316 Error_Pragma_Arg
7317 ("pragma% requires a local enumeration type", Arg1);
7318 end if;
7320 Set_Discard_Names (Entity (Arg), False);
7321 end Keep_Names;
7323 -------------
7324 -- License --
7325 -------------
7327 -- pragma License (RESTRICTED | UNRESRICTED | GPL | MODIFIED_GPL);
7329 when Pragma_License =>
7330 GNAT_Pragma;
7331 Check_Arg_Count (1);
7332 Check_No_Identifiers;
7333 Check_Valid_Configuration_Pragma;
7334 Check_Arg_Is_Identifier (Arg1);
7336 declare
7337 Sind : constant Source_File_Index :=
7338 Source_Index (Current_Sem_Unit);
7340 begin
7341 case Chars (Get_Pragma_Arg (Arg1)) is
7342 when Name_GPL =>
7343 Set_License (Sind, GPL);
7345 when Name_Modified_GPL =>
7346 Set_License (Sind, Modified_GPL);
7348 when Name_Restricted =>
7349 Set_License (Sind, Restricted);
7351 when Name_Unrestricted =>
7352 Set_License (Sind, Unrestricted);
7354 when others =>
7355 Error_Pragma_Arg ("invalid license name", Arg1);
7356 end case;
7357 end;
7359 ---------------
7360 -- Link_With --
7361 ---------------
7363 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
7365 when Pragma_Link_With => Link_With : declare
7366 Arg : Node_Id;
7368 begin
7369 GNAT_Pragma;
7371 if Operating_Mode = Generate_Code
7372 and then In_Extended_Main_Source_Unit (N)
7373 then
7374 Check_At_Least_N_Arguments (1);
7375 Check_No_Identifiers;
7376 Check_Is_In_Decl_Part_Or_Package_Spec;
7377 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7378 Start_String;
7380 Arg := Arg1;
7381 while Present (Arg) loop
7382 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7384 -- Store argument, converting sequences of spaces
7385 -- to a single null character (this is one of the
7386 -- differences in processing between Link_With
7387 -- and Linker_Options).
7389 declare
7390 C : constant Char_Code := Get_Char_Code (' ');
7391 S : constant String_Id :=
7392 Strval (Expr_Value_S (Expression (Arg)));
7393 L : constant Nat := String_Length (S);
7394 F : Nat := 1;
7396 procedure Skip_Spaces;
7397 -- Advance F past any spaces
7399 procedure Skip_Spaces is
7400 begin
7401 while F <= L and then Get_String_Char (S, F) = C loop
7402 F := F + 1;
7403 end loop;
7404 end Skip_Spaces;
7406 begin
7407 Skip_Spaces; -- skip leading spaces
7409 -- Loop through characters, changing any embedded
7410 -- sequence of spaces to a single null character
7411 -- (this is how Link_With/Linker_Options differ)
7413 while F <= L loop
7414 if Get_String_Char (S, F) = C then
7415 Skip_Spaces;
7416 exit when F > L;
7417 Store_String_Char (ASCII.NUL);
7419 else
7420 Store_String_Char (Get_String_Char (S, F));
7421 F := F + 1;
7422 end if;
7423 end loop;
7424 end;
7426 Arg := Next (Arg);
7428 if Present (Arg) then
7429 Store_String_Char (ASCII.NUL);
7430 end if;
7431 end loop;
7433 Store_Linker_Option_String (End_String);
7434 end if;
7435 end Link_With;
7437 ------------------
7438 -- Linker_Alias --
7439 ------------------
7441 -- pragma Linker_Alias (
7442 -- [Entity =>] LOCAL_NAME
7443 -- [Alias =>] static_string_EXPRESSION);
7445 when Pragma_Linker_Alias =>
7446 GNAT_Pragma;
7447 Check_Arg_Count (2);
7448 Check_Optional_Identifier (Arg1, Name_Entity);
7449 Check_Optional_Identifier (Arg2, "alias");
7450 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7451 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7453 -- The only processing required is to link this item on to the
7454 -- list of rep items for the given entity. This is accomplished
7455 -- by the call to Rep_Item_Too_Late (when no error is detected
7456 -- and False is returned).
7458 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7459 return;
7460 else
7461 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7462 end if;
7464 --------------------
7465 -- Linker_Options --
7466 --------------------
7468 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
7470 when Pragma_Linker_Options => Linker_Options : declare
7471 Arg : Node_Id;
7473 begin
7474 Check_Ada_83_Warning;
7475 Check_No_Identifiers;
7476 Check_Arg_Count (1);
7477 Check_Is_In_Decl_Part_Or_Package_Spec;
7479 if Operating_Mode = Generate_Code
7480 and then In_Extended_Main_Source_Unit (N)
7481 then
7482 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7483 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
7485 Arg := Arg2;
7486 while Present (Arg) loop
7487 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7488 Store_String_Char (ASCII.NUL);
7489 Store_String_Chars
7490 (Strval (Expr_Value_S (Expression (Arg))));
7491 Arg := Next (Arg);
7492 end loop;
7494 Store_Linker_Option_String (End_String);
7495 end if;
7496 end Linker_Options;
7498 --------------------
7499 -- Linker_Section --
7500 --------------------
7502 -- pragma Linker_Section (
7503 -- [Entity =>] LOCAL_NAME
7504 -- [Section =>] static_string_EXPRESSION);
7506 when Pragma_Linker_Section =>
7507 GNAT_Pragma;
7508 Check_Arg_Count (2);
7509 Check_Optional_Identifier (Arg1, Name_Entity);
7510 Check_Optional_Identifier (Arg2, Name_Section);
7511 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7512 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7514 -- The only processing required is to link this item on to the
7515 -- list of rep items for the given entity. This is accomplished
7516 -- by the call to Rep_Item_Too_Late (when no error is detected
7517 -- and False is returned).
7519 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7520 return;
7521 else
7522 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7523 end if;
7525 ----------
7526 -- List --
7527 ----------
7529 -- pragma List (On | Off)
7531 -- There is nothing to do here, since we did all the processing
7532 -- for this pragma in Par.Prag (so that it works properly even in
7533 -- syntax only mode)
7535 when Pragma_List =>
7536 null;
7538 --------------------
7539 -- Locking_Policy --
7540 --------------------
7542 -- pragma Locking_Policy (policy_IDENTIFIER);
7544 when Pragma_Locking_Policy => declare
7545 LP : Character;
7547 begin
7548 Check_Ada_83_Warning;
7549 Check_Arg_Count (1);
7550 Check_No_Identifiers;
7551 Check_Arg_Is_Locking_Policy (Arg1);
7552 Check_Valid_Configuration_Pragma;
7553 Get_Name_String (Chars (Expression (Arg1)));
7554 LP := Fold_Upper (Name_Buffer (1));
7556 if Locking_Policy /= ' '
7557 and then Locking_Policy /= LP
7558 then
7559 Error_Msg_Sloc := Locking_Policy_Sloc;
7560 Error_Pragma ("locking policy incompatible with policy#");
7562 -- Set new policy, but always preserve System_Location since
7563 -- we like the error message with the run time name.
7565 else
7566 Locking_Policy := LP;
7568 if Locking_Policy_Sloc /= System_Location then
7569 Locking_Policy_Sloc := Loc;
7570 end if;
7571 end if;
7572 end;
7574 ----------------
7575 -- Long_Float --
7576 ----------------
7578 -- pragma Long_Float (D_Float | G_Float);
7580 when Pragma_Long_Float =>
7581 GNAT_Pragma;
7582 Check_Valid_Configuration_Pragma;
7583 Check_Arg_Count (1);
7584 Check_No_Identifier (Arg1);
7585 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
7587 if not OpenVMS_On_Target then
7588 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
7589 end if;
7591 -- D_Float case
7593 if Chars (Expression (Arg1)) = Name_D_Float then
7594 if Opt.Float_Format_Long = 'G' then
7595 Error_Pragma ("G_Float previously specified");
7596 end if;
7598 Opt.Float_Format_Long := 'D';
7600 -- G_Float case (this is the default, does not need overriding)
7602 else
7603 if Opt.Float_Format_Long = 'D' then
7604 Error_Pragma ("D_Float previously specified");
7605 end if;
7607 Opt.Float_Format_Long := 'G';
7608 end if;
7610 Set_Standard_Fpt_Formats;
7612 -----------------------
7613 -- Machine_Attribute --
7614 -----------------------
7616 -- pragma Machine_Attribute (
7617 -- [Entity =>] LOCAL_NAME,
7618 -- [Attribute_Name =>] static_string_EXPRESSION
7619 -- [,[Info =>] static_string_EXPRESSION] );
7621 when Pragma_Machine_Attribute => Machine_Attribute : declare
7622 Def_Id : Entity_Id;
7624 begin
7625 GNAT_Pragma;
7627 if Arg_Count = 3 then
7628 Check_Optional_Identifier (Arg3, "info");
7629 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
7630 else
7631 Check_Arg_Count (2);
7632 end if;
7634 Check_Arg_Is_Local_Name (Arg1);
7635 Check_Optional_Identifier (Arg2, "attribute_name");
7636 Check_Optional_Identifier (Arg1, Name_Entity);
7637 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7638 Def_Id := Entity (Expression (Arg1));
7640 if Is_Access_Type (Def_Id) then
7641 Def_Id := Designated_Type (Def_Id);
7642 end if;
7644 if Rep_Item_Too_Early (Def_Id, N) then
7645 return;
7646 end if;
7648 Def_Id := Underlying_Type (Def_Id);
7650 -- The only processing required is to link this item on to the
7651 -- list of rep items for the given entity. This is accomplished
7652 -- by the call to Rep_Item_Too_Late (when no error is detected
7653 -- and False is returned).
7655 if Rep_Item_Too_Late (Def_Id, N) then
7656 return;
7657 else
7658 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7659 end if;
7660 end Machine_Attribute;
7662 ----------
7663 -- Main --
7664 ----------
7666 -- pragma Main_Storage
7667 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7669 -- MAIN_STORAGE_OPTION ::=
7670 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7671 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7673 when Pragma_Main => Main : declare
7674 Args : Args_List (1 .. 3);
7675 Names : constant Name_List (1 .. 3) := (
7676 Name_Stack_Size,
7677 Name_Task_Stack_Size_Default,
7678 Name_Time_Slicing_Enabled);
7680 Nod : Node_Id;
7682 begin
7683 GNAT_Pragma;
7684 Gather_Associations (Names, Args);
7686 for J in 1 .. 2 loop
7687 if Present (Args (J)) then
7688 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7689 end if;
7690 end loop;
7692 if Present (Args (3)) then
7693 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
7694 end if;
7696 Nod := Next (N);
7697 while Present (Nod) loop
7698 if Nkind (Nod) = N_Pragma
7699 and then Chars (Nod) = Name_Main
7700 then
7701 Error_Msg_Name_1 := Chars (N);
7702 Error_Msg_N ("duplicate pragma% not permitted", Nod);
7703 end if;
7705 Next (Nod);
7706 end loop;
7707 end Main;
7709 ------------------
7710 -- Main_Storage --
7711 ------------------
7713 -- pragma Main_Storage
7714 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7716 -- MAIN_STORAGE_OPTION ::=
7717 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7718 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7720 when Pragma_Main_Storage => Main_Storage : declare
7721 Args : Args_List (1 .. 2);
7722 Names : constant Name_List (1 .. 2) := (
7723 Name_Working_Storage,
7724 Name_Top_Guard);
7726 Nod : Node_Id;
7728 begin
7729 GNAT_Pragma;
7730 Gather_Associations (Names, Args);
7732 for J in 1 .. 2 loop
7733 if Present (Args (J)) then
7734 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7735 end if;
7736 end loop;
7738 Check_In_Main_Program;
7740 Nod := Next (N);
7741 while Present (Nod) loop
7742 if Nkind (Nod) = N_Pragma
7743 and then Chars (Nod) = Name_Main_Storage
7744 then
7745 Error_Msg_Name_1 := Chars (N);
7746 Error_Msg_N ("duplicate pragma% not permitted", Nod);
7747 end if;
7749 Next (Nod);
7750 end loop;
7751 end Main_Storage;
7753 -----------------
7754 -- Memory_Size --
7755 -----------------
7757 -- pragma Memory_Size (NUMERIC_LITERAL)
7759 when Pragma_Memory_Size =>
7760 GNAT_Pragma;
7762 -- Memory size is simply ignored
7764 Check_No_Identifiers;
7765 Check_Arg_Count (1);
7766 Check_Arg_Is_Integer_Literal (Arg1);
7768 ---------------
7769 -- No_Return --
7770 ---------------
7772 -- pragma No_Return (procedure_LOCAL_NAME);
7774 when Pragma_No_Return => No_Return : declare
7775 Id : Node_Id;
7776 E : Entity_Id;
7777 Found : Boolean;
7779 begin
7780 GNAT_Pragma;
7781 Check_Arg_Count (1);
7782 Check_No_Identifiers;
7783 Check_Arg_Is_Local_Name (Arg1);
7784 Id := Expression (Arg1);
7785 Analyze (Id);
7787 if not Is_Entity_Name (Id) then
7788 Error_Pragma_Arg ("entity name required", Arg1);
7789 end if;
7791 if Etype (Id) = Any_Type then
7792 raise Pragma_Exit;
7793 end if;
7795 E := Entity (Id);
7797 Found := False;
7798 while Present (E)
7799 and then Scope (E) = Current_Scope
7800 loop
7801 if Ekind (E) = E_Procedure
7802 or else Ekind (E) = E_Generic_Procedure
7803 then
7804 Set_No_Return (E);
7805 Found := True;
7806 end if;
7808 E := Homonym (E);
7809 end loop;
7811 if not Found then
7812 Error_Pragma ("no procedures found for pragma%");
7813 end if;
7814 end No_Return;
7816 ------------------------
7817 -- No_Strict_Aliasing --
7818 ------------------------
7820 when Pragma_No_Strict_Aliasing => No_Strict_Alias : declare
7821 E_Id : Entity_Id;
7823 begin
7824 GNAT_Pragma;
7825 Check_At_Most_N_Arguments (1);
7827 if Arg_Count = 0 then
7828 Check_Valid_Configuration_Pragma;
7829 Opt.No_Strict_Aliasing := True;
7831 else
7832 Check_Optional_Identifier (Arg2, Name_Entity);
7833 Check_Arg_Is_Local_Name (Arg1);
7834 E_Id := Entity (Expression (Arg1));
7836 if E_Id = Any_Type then
7837 return;
7838 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
7839 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7840 end if;
7842 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
7843 end if;
7844 end No_Strict_Alias;
7846 -----------------
7847 -- Obsolescent --
7848 -----------------
7850 -- pragma Obsolescent [(static_string_EXPRESSION)];
7852 when Pragma_Obsolescent => Obsolescent : declare
7853 begin
7854 GNAT_Pragma;
7855 Check_At_Most_N_Arguments (1);
7856 Check_No_Identifiers;
7858 if Arg_Count = 1 then
7859 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7860 end if;
7862 if No (Prev (N))
7863 or else (Nkind (Prev (N))) /= N_Subprogram_Declaration
7864 then
7865 Error_Pragma
7866 ("pragma% misplaced, must immediately " &
7867 "follow subprogram spec");
7868 end if;
7869 end Obsolescent;
7871 -----------------
7872 -- No_Run_Time --
7873 -----------------
7875 -- pragma No_Run_Time
7877 -- Note: this pragma is retained for backwards compatibiltiy.
7878 -- See body of Rtsfind for full details on its handling.
7880 when Pragma_No_Run_Time =>
7881 GNAT_Pragma;
7882 Check_Valid_Configuration_Pragma;
7883 Check_Arg_Count (0);
7885 No_Run_Time_Mode := True;
7886 Configurable_Run_Time_Mode := True;
7888 declare
7889 Word32 : constant Boolean := Ttypes.System_Word_Size = 32;
7890 begin
7891 if Word32 then
7892 Duration_32_Bits_On_Target := True;
7893 end if;
7894 end;
7896 Set_Restriction (No_Finalization, N);
7897 Set_Restriction (No_Exception_Handlers, N);
7898 Set_Restriction (Max_Tasks, N, 0);
7899 Set_Restriction (No_Tasking, N);
7901 -----------------------
7902 -- Normalize_Scalars --
7903 -----------------------
7905 -- pragma Normalize_Scalars;
7907 when Pragma_Normalize_Scalars =>
7908 Check_Ada_83_Warning;
7909 Check_Arg_Count (0);
7910 Check_Valid_Configuration_Pragma;
7911 Normalize_Scalars := True;
7912 Init_Or_Norm_Scalars := True;
7914 --------------
7915 -- Optimize --
7916 --------------
7918 -- pragma Optimize (Time | Space);
7920 -- The actual check for optimize is done in Gigi. Note that this
7921 -- pragma does not actually change the optimization setting, it
7922 -- simply checks that it is consistent with the pragma.
7924 when Pragma_Optimize =>
7925 Check_No_Identifiers;
7926 Check_Arg_Count (1);
7927 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
7929 -------------------------
7930 -- Optional_Overriding --
7931 -------------------------
7933 -- These pragmas are treated as part of the previous subprogram
7934 -- declaration, and analyzed immediately after it (see sem_ch6,
7935 -- Check_Overriding_Operation). If the pragma has not been analyzed
7936 -- yet, it appears in the wrong place.
7938 when Pragma_Optional_Overriding =>
7939 Error_Msg_N ("pragma must appear immediately after subprogram", N);
7941 ----------------
7942 -- Overriding --
7943 ----------------
7945 when Pragma_Overriding =>
7946 Error_Msg_N ("pragma must appear immediately after subprogram", N);
7948 ----------
7949 -- Pack --
7950 ----------
7952 -- pragma Pack (first_subtype_LOCAL_NAME);
7954 when Pragma_Pack => Pack : declare
7955 Assoc : constant Node_Id := Arg1;
7956 Type_Id : Node_Id;
7957 Typ : Entity_Id;
7959 begin
7960 Check_No_Identifiers;
7961 Check_Arg_Count (1);
7962 Check_Arg_Is_Local_Name (Arg1);
7964 Type_Id := Expression (Assoc);
7965 Find_Type (Type_Id);
7966 Typ := Entity (Type_Id);
7968 if Typ = Any_Type
7969 or else Rep_Item_Too_Early (Typ, N)
7970 then
7971 return;
7972 else
7973 Typ := Underlying_Type (Typ);
7974 end if;
7976 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
7977 Error_Pragma ("pragma% must specify array or record type");
7978 end if;
7980 Check_First_Subtype (Arg1);
7982 if Has_Pragma_Pack (Typ) then
7983 Error_Pragma ("duplicate pragma%, only one allowed");
7985 -- Array type. We set the Has_Pragma_Pack flag, and Is_Packed,
7986 -- but not Has_Non_Standard_Rep, because we don't actually know
7987 -- till freeze time if the array can have packed representation.
7988 -- That's because in the general case we do not know enough about
7989 -- the component type until it in turn is frozen, which certainly
7990 -- happens before the array type is frozen, but not necessarily
7991 -- till that point (i.e. right now it may be unfrozen).
7993 elsif Is_Array_Type (Typ) then
7994 if Has_Aliased_Components (Base_Type (Typ)) then
7995 Error_Pragma
7996 ("pragma% ignored, cannot pack aliased components?");
7998 elsif Has_Atomic_Components (Typ)
7999 or else Is_Atomic (Component_Type (Typ))
8000 then
8001 Error_Pragma
8002 ("?pragma% ignored, cannot pack atomic components");
8004 elsif not Rep_Item_Too_Late (Typ, N) then
8005 Set_Is_Packed (Base_Type (Typ));
8006 Set_Has_Pragma_Pack (Base_Type (Typ));
8007 Set_Has_Non_Standard_Rep (Base_Type (Typ));
8008 end if;
8010 -- Record type. For record types, the pack is always effective
8012 else pragma Assert (Is_Record_Type (Typ));
8013 if not Rep_Item_Too_Late (Typ, N) then
8014 Set_Has_Pragma_Pack (Base_Type (Typ));
8015 Set_Is_Packed (Base_Type (Typ));
8016 Set_Has_Non_Standard_Rep (Base_Type (Typ));
8017 end if;
8018 end if;
8019 end Pack;
8021 ----------
8022 -- Page --
8023 ----------
8025 -- pragma Page;
8027 -- There is nothing to do here, since we did all the processing
8028 -- for this pragma in Par.Prag (so that it works properly even in
8029 -- syntax only mode)
8031 when Pragma_Page =>
8032 null;
8034 -------------
8035 -- Passive --
8036 -------------
8038 -- pragma Passive [(PASSIVE_FORM)];
8040 -- PASSIVE_FORM ::= Semaphore | No
8042 when Pragma_Passive =>
8043 GNAT_Pragma;
8045 if Nkind (Parent (N)) /= N_Task_Definition then
8046 Error_Pragma ("pragma% must be within task definition");
8047 end if;
8049 if Arg_Count /= 0 then
8050 Check_Arg_Count (1);
8051 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
8052 end if;
8054 -------------
8055 -- Polling --
8056 -------------
8058 -- pragma Polling (ON | OFF);
8060 when Pragma_Polling =>
8061 GNAT_Pragma;
8062 Check_Arg_Count (1);
8063 Check_No_Identifiers;
8064 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8065 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
8067 ---------------------
8068 -- Persistent_Data --
8069 ---------------------
8071 when Pragma_Persistent_Data => declare
8072 Ent : Entity_Id;
8074 begin
8075 -- Register the pragma as applying to the compilation unit.
8076 -- Individual Persistent_Object pragmas for relevant objects
8077 -- are generated the end of the compilation.
8079 GNAT_Pragma;
8080 Check_Valid_Configuration_Pragma;
8081 Check_Arg_Count (0);
8082 Ent := Find_Lib_Unit_Name;
8083 Set_Is_Preelaborated (Ent);
8084 end;
8086 -----------------------
8087 -- Persistent_Object --
8088 -----------------------
8090 when Pragma_Persistent_Object => declare
8091 Decl : Node_Id;
8092 Ent : Entity_Id;
8093 MA : Node_Id;
8094 Str : String_Id;
8096 begin
8097 GNAT_Pragma;
8098 Check_Arg_Count (1);
8099 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8101 if not Is_Entity_Name (Expression (Arg1))
8102 or else
8103 (Ekind (Entity (Expression (Arg1))) /= E_Variable
8104 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
8105 then
8106 Error_Pragma_Arg ("pragma only applies to objects", Arg1);
8107 end if;
8109 Ent := Entity (Expression (Arg1));
8110 Decl := Parent (Ent);
8112 if Nkind (Decl) /= N_Object_Declaration then
8113 return;
8114 end if;
8116 -- Placement of the object depends on whether there is
8117 -- an initial value or none. If the No_Initialization flag
8118 -- is set, the initialization has been transformed into
8119 -- assignments, which is disallowed elaboration code.
8121 if No_Initialization (Decl) then
8122 Error_Msg_N
8123 ("initialization for persistent object"
8124 & "must be static expression", Decl);
8125 return;
8126 end if;
8128 if No (Expression (Decl)) then
8129 Start_String;
8130 Store_String_Chars ("section ("".persistent.bss"")");
8131 Str := End_String;
8133 else
8134 if not Is_OK_Static_Expression (Expression (Decl)) then
8135 Flag_Non_Static_Expr
8136 ("initialization for persistent object"
8137 & "must be static expression!", Expression (Decl));
8138 return;
8139 end if;
8141 Start_String;
8142 Store_String_Chars ("section ("".persistent.data"")");
8143 Str := End_String;
8144 end if;
8146 MA :=
8147 Make_Pragma
8148 (Sloc (N),
8149 Name_Machine_Attribute,
8150 New_List
8151 (Make_Pragma_Argument_Association
8152 (Sloc => Sloc (Arg1),
8153 Expression => New_Occurrence_Of (Ent, Sloc (Ent))),
8154 Make_Pragma_Argument_Association
8155 (Sloc => Sloc (Arg1),
8156 Expression =>
8157 Make_String_Literal
8158 (Sloc => Sloc (Arg1),
8159 Strval => Str))));
8161 Insert_After (N, MA);
8162 Analyze (MA);
8163 Set_Has_Gigi_Rep_Item (Ent);
8164 end;
8166 ------------------
8167 -- Preelaborate --
8168 ------------------
8170 -- pragma Preelaborate [(library_unit_NAME)];
8172 -- Set the flag Is_Preelaborated of program unit name entity
8174 when Pragma_Preelaborate => Preelaborate : declare
8175 Pa : constant Node_Id := Parent (N);
8176 Pk : constant Node_Kind := Nkind (Pa);
8177 Ent : Entity_Id;
8179 begin
8180 Check_Ada_83_Warning;
8181 Check_Valid_Library_Unit_Pragma;
8183 if Nkind (N) = N_Null_Statement then
8184 return;
8185 end if;
8187 Ent := Find_Lib_Unit_Name;
8189 -- This filters out pragmas inside generic parent then
8190 -- show up inside instantiation
8192 if Present (Ent)
8193 and then not (Pk = N_Package_Specification
8194 and then Present (Generic_Parent (Pa)))
8195 then
8196 if not Debug_Flag_U then
8197 Set_Is_Preelaborated (Ent);
8198 Set_Suppress_Elaboration_Warnings (Ent);
8199 end if;
8200 end if;
8201 end Preelaborate;
8203 --------------
8204 -- Priority --
8205 --------------
8207 -- pragma Priority (EXPRESSION);
8209 when Pragma_Priority => Priority : declare
8210 P : constant Node_Id := Parent (N);
8211 Arg : Node_Id;
8213 begin
8214 Check_No_Identifiers;
8215 Check_Arg_Count (1);
8217 -- Subprogram case
8219 if Nkind (P) = N_Subprogram_Body then
8220 Check_In_Main_Program;
8222 Arg := Expression (Arg1);
8223 Analyze_And_Resolve (Arg, Standard_Integer);
8225 -- Must be static
8227 if not Is_Static_Expression (Arg) then
8228 Flag_Non_Static_Expr
8229 ("main subprogram priority is not static!", Arg);
8230 raise Pragma_Exit;
8232 -- If constraint error, then we already signalled an error
8234 elsif Raises_Constraint_Error (Arg) then
8235 null;
8237 -- Otherwise check in range
8239 else
8240 declare
8241 Val : constant Uint := Expr_Value (Arg);
8243 begin
8244 if Val < 0
8245 or else Val > Expr_Value (Expression
8246 (Parent (RTE (RE_Max_Priority))))
8247 then
8248 Error_Pragma_Arg
8249 ("main subprogram priority is out of range", Arg1);
8250 end if;
8251 end;
8252 end if;
8254 Set_Main_Priority
8255 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8257 -- Task or Protected, must be of type Integer
8259 elsif Nkind (P) = N_Protected_Definition
8260 or else
8261 Nkind (P) = N_Task_Definition
8262 then
8263 Arg := Expression (Arg1);
8265 -- The expression must be analyzed in the special manner
8266 -- described in "Handling of Default and Per-Object
8267 -- Expressions" in sem.ads.
8269 Analyze_Per_Use_Expression (Arg, Standard_Integer);
8271 if not Is_Static_Expression (Arg) then
8272 Check_Restriction (Static_Priorities, Arg);
8273 end if;
8275 -- Anything else is incorrect
8277 else
8278 Pragma_Misplaced;
8279 end if;
8281 if Has_Priority_Pragma (P) then
8282 Error_Pragma ("duplicate pragma% not allowed");
8283 else
8284 Set_Has_Priority_Pragma (P, True);
8286 if Nkind (P) = N_Protected_Definition
8287 or else
8288 Nkind (P) = N_Task_Definition
8289 then
8290 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8291 -- exp_ch9 should use this ???
8292 end if;
8293 end if;
8294 end Priority;
8296 -------------
8297 -- Profile --
8298 -------------
8300 -- pragma Profile (profile_IDENTIFIER);
8302 -- profile_IDENTIFIER => Protected | Ravenscar
8304 when Pragma_Profile =>
8305 Check_Arg_Count (1);
8306 Check_Valid_Configuration_Pragma;
8307 Check_No_Identifiers;
8309 declare
8310 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8311 begin
8312 if Chars (Argx) = Name_Ravenscar then
8313 Set_Ravenscar_Profile (N);
8315 elsif Chars (Argx) = Name_Restricted then
8316 Set_Profile_Restrictions (Restricted, N, Warn => False);
8317 else
8318 Error_Pragma_Arg ("& is not a valid profile", Argx);
8319 end if;
8320 end;
8322 ----------------------
8323 -- Profile_Warnings --
8324 ----------------------
8326 -- pragma Profile_Warnings (profile_IDENTIFIER);
8328 -- profile_IDENTIFIER => Protected | Ravenscar
8330 when Pragma_Profile_Warnings =>
8331 GNAT_Pragma;
8332 Check_Arg_Count (1);
8333 Check_Valid_Configuration_Pragma;
8334 Check_No_Identifiers;
8336 declare
8337 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8338 begin
8339 if Chars (Argx) = Name_Ravenscar then
8340 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
8342 elsif Chars (Argx) = Name_Restricted then
8343 Set_Profile_Restrictions (Restricted, N, Warn => True);
8344 else
8345 Error_Pragma_Arg ("& is not a valid profile", Argx);
8346 end if;
8347 end;
8349 --------------------------
8350 -- Propagate_Exceptions --
8351 --------------------------
8353 -- pragma Propagate_Exceptions;
8355 when Pragma_Propagate_Exceptions =>
8356 GNAT_Pragma;
8357 Check_Arg_Count (0);
8359 if In_Extended_Main_Source_Unit (N) then
8360 Propagate_Exceptions := True;
8361 end if;
8363 ------------------
8364 -- Psect_Object --
8365 ------------------
8367 -- pragma Psect_Object (
8368 -- [Internal =>] LOCAL_NAME,
8369 -- [, [External =>] EXTERNAL_SYMBOL]
8370 -- [, [Size =>] EXTERNAL_SYMBOL]);
8372 when Pragma_Psect_Object | Pragma_Common_Object =>
8373 Psect_Object : declare
8374 Args : Args_List (1 .. 3);
8375 Names : constant Name_List (1 .. 3) := (
8376 Name_Internal,
8377 Name_External,
8378 Name_Size);
8380 Internal : Node_Id renames Args (1);
8381 External : Node_Id renames Args (2);
8382 Size : Node_Id renames Args (3);
8384 R_Internal : Node_Id;
8385 R_External : Node_Id;
8387 MA : Node_Id;
8388 Str : String_Id;
8390 Def_Id : Entity_Id;
8392 procedure Check_Too_Long (Arg : Node_Id);
8393 -- Posts message if the argument is an identifier with more
8394 -- than 31 characters, or a string literal with more than
8395 -- 31 characters, and we are operating under VMS
8397 --------------------
8398 -- Check_Too_Long --
8399 --------------------
8401 procedure Check_Too_Long (Arg : Node_Id) is
8402 X : constant Node_Id := Original_Node (Arg);
8404 begin
8405 if Nkind (X) /= N_String_Literal
8406 and then
8407 Nkind (X) /= N_Identifier
8408 then
8409 Error_Pragma_Arg
8410 ("inappropriate argument for pragma %", Arg);
8411 end if;
8413 if OpenVMS_On_Target then
8414 if (Nkind (X) = N_String_Literal
8415 and then String_Length (Strval (X)) > 31)
8416 or else
8417 (Nkind (X) = N_Identifier
8418 and then Length_Of_Name (Chars (X)) > 31)
8419 then
8420 Error_Pragma_Arg
8421 ("argument for pragma % is longer than 31 characters",
8422 Arg);
8423 end if;
8424 end if;
8425 end Check_Too_Long;
8427 -- Start of processing for Common_Object/Psect_Object
8429 begin
8430 GNAT_Pragma;
8431 Gather_Associations (Names, Args);
8432 Process_Extended_Import_Export_Internal_Arg (Internal);
8434 R_Internal := Relocate_Node (Internal);
8436 Def_Id := Entity (R_Internal);
8438 if Ekind (Def_Id) /= E_Constant
8439 and then Ekind (Def_Id) /= E_Variable
8440 then
8441 Error_Pragma_Arg
8442 ("pragma% must designate an object", Internal);
8443 end if;
8445 Check_Too_Long (R_Internal);
8447 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
8448 Error_Pragma_Arg
8449 ("cannot use pragma% for imported/exported object",
8450 R_Internal);
8451 end if;
8453 if Is_Concurrent_Type (Etype (R_Internal)) then
8454 Error_Pragma_Arg
8455 ("cannot specify pragma % for task/protected object",
8456 R_Internal);
8457 end if;
8459 if Is_Psected (Def_Id) then
8460 Error_Msg_N ("?duplicate Psect_Object pragma", N);
8461 else
8462 Set_Is_Psected (Def_Id);
8463 end if;
8465 if Ekind (Def_Id) = E_Constant then
8466 Error_Pragma_Arg
8467 ("cannot specify pragma % for a constant", R_Internal);
8468 end if;
8470 if Is_Record_Type (Etype (R_Internal)) then
8471 declare
8472 Ent : Entity_Id;
8473 Decl : Entity_Id;
8475 begin
8476 Ent := First_Entity (Etype (R_Internal));
8477 while Present (Ent) loop
8478 Decl := Declaration_Node (Ent);
8480 if Ekind (Ent) = E_Component
8481 and then Nkind (Decl) = N_Component_Declaration
8482 and then Present (Expression (Decl))
8483 and then Warn_On_Export_Import
8484 then
8485 Error_Msg_N
8486 ("?object for pragma % has defaults", R_Internal);
8487 exit;
8489 else
8490 Next_Entity (Ent);
8491 end if;
8492 end loop;
8493 end;
8494 end if;
8496 if Present (Size) then
8497 Check_Too_Long (Size);
8498 end if;
8500 -- Make Psect case-insensitive.
8502 if Present (External) then
8503 Check_Too_Long (External);
8505 if Nkind (External) = N_String_Literal then
8506 String_To_Name_Buffer (Strval (External));
8507 else
8508 Get_Name_String (Chars (External));
8509 end if;
8511 Set_All_Upper_Case;
8512 Start_String;
8513 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8514 Str := End_String;
8515 R_External := Make_String_Literal
8516 (Sloc => Sloc (External), Strval => Str);
8517 else
8518 Get_Name_String (Chars (Internal));
8519 Set_All_Upper_Case;
8520 Start_String;
8521 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8522 Str := End_String;
8523 R_External := Make_String_Literal
8524 (Sloc => Sloc (Internal), Strval => Str);
8525 end if;
8527 -- Transform into pragma Linker_Section, add attributes to
8528 -- match what DEC Ada does. Ignore size for now?
8530 Rewrite (N,
8531 Make_Pragma
8532 (Sloc (N),
8533 Name_Linker_Section,
8534 New_List
8535 (Make_Pragma_Argument_Association
8536 (Sloc => Sloc (R_Internal),
8537 Expression => R_Internal),
8538 Make_Pragma_Argument_Association
8539 (Sloc => Sloc (R_External),
8540 Expression => R_External))));
8542 Analyze (N);
8544 -- Add Machine_Attribute of "overlaid", so the section overlays
8545 -- other sections of the same name.
8547 Start_String;
8548 Store_String_Chars ("overlaid");
8549 Str := End_String;
8551 MA :=
8552 Make_Pragma
8553 (Sloc (N),
8554 Name_Machine_Attribute,
8555 New_List
8556 (Make_Pragma_Argument_Association
8557 (Sloc => Sloc (R_Internal),
8558 Expression => R_Internal),
8559 Make_Pragma_Argument_Association
8560 (Sloc => Sloc (R_External),
8561 Expression =>
8562 Make_String_Literal
8563 (Sloc => Sloc (R_External),
8564 Strval => Str))));
8565 Analyze (MA);
8567 -- Add Machine_Attribute of "global", so the section is visible
8568 -- everywhere
8570 Start_String;
8571 Store_String_Chars ("global");
8572 Str := End_String;
8574 MA :=
8575 Make_Pragma
8576 (Sloc (N),
8577 Name_Machine_Attribute,
8578 New_List
8579 (Make_Pragma_Argument_Association
8580 (Sloc => Sloc (R_Internal),
8581 Expression => R_Internal),
8583 Make_Pragma_Argument_Association
8584 (Sloc => Sloc (R_External),
8585 Expression =>
8586 Make_String_Literal
8587 (Sloc => Sloc (R_External),
8588 Strval => Str))));
8589 Analyze (MA);
8591 -- Add Machine_Attribute of "initialize", so the section is
8592 -- demand zeroed.
8594 Start_String;
8595 Store_String_Chars ("initialize");
8596 Str := End_String;
8598 MA :=
8599 Make_Pragma
8600 (Sloc (N),
8601 Name_Machine_Attribute,
8602 New_List
8603 (Make_Pragma_Argument_Association
8604 (Sloc => Sloc (R_Internal),
8605 Expression => R_Internal),
8607 Make_Pragma_Argument_Association
8608 (Sloc => Sloc (R_External),
8609 Expression =>
8610 Make_String_Literal
8611 (Sloc => Sloc (R_External),
8612 Strval => Str))));
8613 Analyze (MA);
8614 end Psect_Object;
8616 ----------
8617 -- Pure --
8618 ----------
8620 -- pragma Pure [(library_unit_NAME)];
8622 when Pragma_Pure => Pure : declare
8623 Ent : Entity_Id;
8624 begin
8625 Check_Ada_83_Warning;
8626 Check_Valid_Library_Unit_Pragma;
8628 if Nkind (N) = N_Null_Statement then
8629 return;
8630 end if;
8632 Ent := Find_Lib_Unit_Name;
8633 Set_Is_Pure (Ent);
8634 Set_Suppress_Elaboration_Warnings (Ent);
8635 end Pure;
8637 -------------------
8638 -- Pure_Function --
8639 -------------------
8641 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
8643 when Pragma_Pure_Function => Pure_Function : declare
8644 E_Id : Node_Id;
8645 E : Entity_Id;
8646 Def_Id : Entity_Id;
8647 Effective : Boolean := False;
8649 begin
8650 GNAT_Pragma;
8651 Check_Arg_Count (1);
8652 Check_Optional_Identifier (Arg1, Name_Entity);
8653 Check_Arg_Is_Local_Name (Arg1);
8654 E_Id := Expression (Arg1);
8656 if Error_Posted (E_Id) then
8657 return;
8658 end if;
8660 -- Loop through homonyms (overloadings) of referenced entity
8662 E := Entity (E_Id);
8664 if Present (E) then
8665 loop
8666 Def_Id := Get_Base_Subprogram (E);
8668 if Ekind (Def_Id) /= E_Function
8669 and then Ekind (Def_Id) /= E_Generic_Function
8670 and then Ekind (Def_Id) /= E_Operator
8671 then
8672 Error_Pragma_Arg
8673 ("pragma% requires a function name", Arg1);
8674 end if;
8676 Set_Is_Pure (Def_Id);
8678 if not Has_Pragma_Pure_Function (Def_Id) then
8679 Set_Has_Pragma_Pure_Function (Def_Id);
8680 Effective := True;
8681 end if;
8683 E := Homonym (E);
8684 exit when No (E) or else Scope (E) /= Current_Scope;
8685 end loop;
8687 if not Effective
8688 and then Warn_On_Redundant_Constructs
8689 then
8690 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
8691 N, Entity (E_Id));
8692 end if;
8693 end if;
8694 end Pure_Function;
8696 --------------------
8697 -- Queuing_Policy --
8698 --------------------
8700 -- pragma Queuing_Policy (policy_IDENTIFIER);
8702 when Pragma_Queuing_Policy => declare
8703 QP : Character;
8705 begin
8706 Check_Ada_83_Warning;
8707 Check_Arg_Count (1);
8708 Check_No_Identifiers;
8709 Check_Arg_Is_Queuing_Policy (Arg1);
8710 Check_Valid_Configuration_Pragma;
8711 Get_Name_String (Chars (Expression (Arg1)));
8712 QP := Fold_Upper (Name_Buffer (1));
8714 if Queuing_Policy /= ' '
8715 and then Queuing_Policy /= QP
8716 then
8717 Error_Msg_Sloc := Queuing_Policy_Sloc;
8718 Error_Pragma ("queuing policy incompatible with policy#");
8720 -- Set new policy, but always preserve System_Location since
8721 -- we like the error message with the run time name.
8723 else
8724 Queuing_Policy := QP;
8726 if Queuing_Policy_Sloc /= System_Location then
8727 Queuing_Policy_Sloc := Loc;
8728 end if;
8729 end if;
8730 end;
8732 ---------------------------
8733 -- Remote_Call_Interface --
8734 ---------------------------
8736 -- pragma Remote_Call_Interface [(library_unit_NAME)];
8738 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
8739 Cunit_Node : Node_Id;
8740 Cunit_Ent : Entity_Id;
8741 K : Node_Kind;
8743 begin
8744 Check_Ada_83_Warning;
8745 Check_Valid_Library_Unit_Pragma;
8747 if Nkind (N) = N_Null_Statement then
8748 return;
8749 end if;
8751 Cunit_Node := Cunit (Current_Sem_Unit);
8752 K := Nkind (Unit (Cunit_Node));
8753 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8755 if K = N_Package_Declaration
8756 or else K = N_Generic_Package_Declaration
8757 or else K = N_Subprogram_Declaration
8758 or else K = N_Generic_Subprogram_Declaration
8759 or else (K = N_Subprogram_Body
8760 and then Acts_As_Spec (Unit (Cunit_Node)))
8761 then
8762 null;
8763 else
8764 Error_Pragma (
8765 "pragma% must apply to package or subprogram declaration");
8766 end if;
8768 Set_Is_Remote_Call_Interface (Cunit_Ent);
8769 end Remote_Call_Interface;
8771 ------------------
8772 -- Remote_Types --
8773 ------------------
8775 -- pragma Remote_Types [(library_unit_NAME)];
8777 when Pragma_Remote_Types => Remote_Types : declare
8778 Cunit_Node : Node_Id;
8779 Cunit_Ent : Entity_Id;
8781 begin
8782 Check_Ada_83_Warning;
8783 Check_Valid_Library_Unit_Pragma;
8785 if Nkind (N) = N_Null_Statement then
8786 return;
8787 end if;
8789 Cunit_Node := Cunit (Current_Sem_Unit);
8790 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8792 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
8793 and then
8794 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
8795 then
8796 Error_Pragma (
8797 "pragma% can only apply to a package declaration");
8798 end if;
8800 Set_Is_Remote_Types (Cunit_Ent);
8801 end Remote_Types;
8803 ---------------
8804 -- Ravenscar --
8805 ---------------
8807 -- pragma Ravenscar;
8809 when Pragma_Ravenscar =>
8810 GNAT_Pragma;
8811 Check_Arg_Count (0);
8812 Check_Valid_Configuration_Pragma;
8813 Set_Ravenscar_Profile (N);
8815 if Warn_On_Obsolescent_Feature then
8816 Error_Msg_N
8817 ("pragma Ravenscar is an obsolescent feature?", N);
8818 Error_Msg_N
8819 ("|use pragma Profile (Ravenscar) instead", N);
8820 end if;
8822 -------------------------
8823 -- Restricted_Run_Time --
8824 -------------------------
8826 -- pragma Restricted_Run_Time;
8828 when Pragma_Restricted_Run_Time =>
8829 GNAT_Pragma;
8830 Check_Arg_Count (0);
8831 Check_Valid_Configuration_Pragma;
8832 Set_Profile_Restrictions (Restricted, N, Warn => False);
8834 if Warn_On_Obsolescent_Feature then
8835 Error_Msg_N
8836 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
8837 Error_Msg_N
8838 ("|use pragma Profile (Restricted) instead", N);
8839 end if;
8841 ------------------
8842 -- Restrictions --
8843 ------------------
8845 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
8847 -- RESTRICTION ::=
8848 -- restriction_IDENTIFIER
8849 -- | restriction_parameter_IDENTIFIER => EXPRESSION
8851 when Pragma_Restrictions =>
8852 Process_Restrictions_Or_Restriction_Warnings;
8854 --------------------------
8855 -- Restriction_Warnings --
8856 --------------------------
8858 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
8860 -- RESTRICTION ::=
8861 -- restriction_IDENTIFIER
8862 -- | restriction_parameter_IDENTIFIER => EXPRESSION
8864 when Pragma_Restriction_Warnings =>
8865 Process_Restrictions_Or_Restriction_Warnings;
8867 ----------------
8868 -- Reviewable --
8869 ----------------
8871 -- pragma Reviewable;
8873 when Pragma_Reviewable =>
8874 Check_Ada_83_Warning;
8875 Check_Arg_Count (0);
8877 -------------------
8878 -- Share_Generic --
8879 -------------------
8881 -- pragma Share_Generic (NAME {, NAME});
8883 when Pragma_Share_Generic =>
8884 GNAT_Pragma;
8885 Process_Generic_List;
8887 ------------
8888 -- Shared --
8889 ------------
8891 -- pragma Shared (LOCAL_NAME);
8893 when Pragma_Shared =>
8894 GNAT_Pragma;
8895 Process_Atomic_Shared_Volatile;
8897 --------------------
8898 -- Shared_Passive --
8899 --------------------
8901 -- pragma Shared_Passive [(library_unit_NAME)];
8903 -- Set the flag Is_Shared_Passive of program unit name entity
8905 when Pragma_Shared_Passive => Shared_Passive : declare
8906 Cunit_Node : Node_Id;
8907 Cunit_Ent : Entity_Id;
8909 begin
8910 Check_Ada_83_Warning;
8911 Check_Valid_Library_Unit_Pragma;
8913 if Nkind (N) = N_Null_Statement then
8914 return;
8915 end if;
8917 Cunit_Node := Cunit (Current_Sem_Unit);
8918 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8920 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
8921 and then
8922 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
8923 then
8924 Error_Pragma (
8925 "pragma% can only apply to a package declaration");
8926 end if;
8928 Set_Is_Shared_Passive (Cunit_Ent);
8929 end Shared_Passive;
8931 ----------------------
8932 -- Source_File_Name --
8933 ----------------------
8935 -- There are five forms for this pragma:
8937 -- pragma Source_File_Name (
8938 -- [UNIT_NAME =>] unit_NAME,
8939 -- BODY_FILE_NAME => STRING_LITERAL
8940 -- [, [INDEX =>] INTEGER_LITERAL]);
8942 -- pragma Source_File_Name (
8943 -- [UNIT_NAME =>] unit_NAME,
8944 -- SPEC_FILE_NAME => STRING_LITERAL
8945 -- [, [INDEX =>] INTEGER_LITERAL]);
8947 -- pragma Source_File_Name (
8948 -- BODY_FILE_NAME => STRING_LITERAL
8949 -- [, DOT_REPLACEMENT => STRING_LITERAL]
8950 -- [, CASING => CASING_SPEC]);
8952 -- pragma Source_File_Name (
8953 -- SPEC_FILE_NAME => STRING_LITERAL
8954 -- [, DOT_REPLACEMENT => STRING_LITERAL]
8955 -- [, CASING => CASING_SPEC]);
8957 -- pragma Source_File_Name (
8958 -- SUBUNIT_FILE_NAME => STRING_LITERAL
8959 -- [, DOT_REPLACEMENT => STRING_LITERAL]
8960 -- [, CASING => CASING_SPEC]);
8962 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
8964 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
8965 -- Source_File_Name (SFN), however their usage is exclusive:
8966 -- SFN can only be used when no project file is used, while
8967 -- SFNP can only be used when a project file is used.
8969 -- No processing here. Processing was completed during parsing,
8970 -- since we need to have file names set as early as possible.
8971 -- Units are loaded well before semantic processing starts.
8973 -- The only processing we defer to this point is the check
8974 -- for correct placement.
8976 when Pragma_Source_File_Name =>
8977 GNAT_Pragma;
8978 Check_Valid_Configuration_Pragma;
8980 ------------------------------
8981 -- Source_File_Name_Project --
8982 ------------------------------
8984 -- See Source_File_Name for syntax
8986 -- No processing here. Processing was completed during parsing,
8987 -- since we need to have file names set as early as possible.
8988 -- Units are loaded well before semantic processing starts.
8990 -- The only processing we defer to this point is the check
8991 -- for correct placement.
8993 when Pragma_Source_File_Name_Project =>
8994 GNAT_Pragma;
8995 Check_Valid_Configuration_Pragma;
8997 -- Check that a pragma Source_File_Name_Project is used only
8998 -- in a configuration pragmas file.
9000 -- Pragmas Source_File_Name_Project should only be generated
9001 -- by the Project Manager in configuration pragmas files.
9003 -- This is really an ugly test. It seems to depend on some
9004 -- accidental and undocumented property. At the very least
9005 -- it needs to be documented, but it would be better to have
9006 -- a clean way of testing if we are in a configuration file???
9008 if Present (Parent (N)) then
9009 Error_Pragma
9010 ("pragma% can only appear in a configuration pragmas file");
9011 end if;
9013 ----------------------
9014 -- Source_Reference --
9015 ----------------------
9017 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
9019 -- Nothing to do, all processing completed in Par.Prag, since we
9020 -- need the information for possible parser messages that are output
9022 when Pragma_Source_Reference =>
9023 GNAT_Pragma;
9025 ------------------
9026 -- Storage_Size --
9027 ------------------
9029 -- pragma Storage_Size (EXPRESSION);
9031 when Pragma_Storage_Size => Storage_Size : declare
9032 P : constant Node_Id := Parent (N);
9033 Arg : Node_Id;
9035 begin
9036 Check_No_Identifiers;
9037 Check_Arg_Count (1);
9039 -- The expression must be analyzed in the special manner
9040 -- described in "Handling of Default Expressions" in sem.ads.
9042 -- Set In_Default_Expression for per-object case ???
9044 Arg := Expression (Arg1);
9045 Analyze_Per_Use_Expression (Arg, Any_Integer);
9047 if not Is_Static_Expression (Arg) then
9048 Check_Restriction (Static_Storage_Size, Arg);
9049 end if;
9051 if Nkind (P) /= N_Task_Definition then
9052 Pragma_Misplaced;
9053 return;
9055 else
9056 if Has_Storage_Size_Pragma (P) then
9057 Error_Pragma ("duplicate pragma% not allowed");
9058 else
9059 Set_Has_Storage_Size_Pragma (P, True);
9060 end if;
9062 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9063 -- ??? exp_ch9 should use this!
9064 end if;
9065 end Storage_Size;
9067 ------------------
9068 -- Storage_Unit --
9069 ------------------
9071 -- pragma Storage_Unit (NUMERIC_LITERAL);
9073 -- Only permitted argument is System'Storage_Unit value
9075 when Pragma_Storage_Unit =>
9076 Check_No_Identifiers;
9077 Check_Arg_Count (1);
9078 Check_Arg_Is_Integer_Literal (Arg1);
9080 if Intval (Expression (Arg1)) /=
9081 UI_From_Int (Ttypes.System_Storage_Unit)
9082 then
9083 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
9084 Error_Pragma_Arg
9085 ("the only allowed argument for pragma% is ^", Arg1);
9086 end if;
9088 --------------------
9089 -- Stream_Convert --
9090 --------------------
9092 -- pragma Stream_Convert (
9093 -- [Entity =>] type_LOCAL_NAME,
9094 -- [Read =>] function_NAME,
9095 -- [Write =>] function NAME);
9097 when Pragma_Stream_Convert => Stream_Convert : declare
9099 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
9100 -- Check that the given argument is the name of a local
9101 -- function of one argument that is not overloaded earlier
9102 -- in the current local scope. A check is also made that the
9103 -- argument is a function with one parameter.
9105 --------------------------------------
9106 -- Check_OK_Stream_Convert_Function --
9107 --------------------------------------
9109 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
9110 Ent : Entity_Id;
9112 begin
9113 Check_Arg_Is_Local_Name (Arg);
9114 Ent := Entity (Expression (Arg));
9116 if Has_Homonym (Ent) then
9117 Error_Pragma_Arg
9118 ("argument for pragma% may not be overloaded", Arg);
9119 end if;
9121 if Ekind (Ent) /= E_Function
9122 or else No (First_Formal (Ent))
9123 or else Present (Next_Formal (First_Formal (Ent)))
9124 then
9125 Error_Pragma_Arg
9126 ("argument for pragma% must be" &
9127 " function of one argument", Arg);
9128 end if;
9129 end Check_OK_Stream_Convert_Function;
9131 -- Start of procecessing for Stream_Convert
9133 begin
9134 GNAT_Pragma;
9135 Check_Arg_Count (3);
9136 Check_Optional_Identifier (Arg1, Name_Entity);
9137 Check_Optional_Identifier (Arg2, Name_Read);
9138 Check_Optional_Identifier (Arg3, Name_Write);
9139 Check_Arg_Is_Local_Name (Arg1);
9140 Check_OK_Stream_Convert_Function (Arg2);
9141 Check_OK_Stream_Convert_Function (Arg3);
9143 declare
9144 Typ : constant Entity_Id :=
9145 Underlying_Type (Entity (Expression (Arg1)));
9146 Read : constant Entity_Id := Entity (Expression (Arg2));
9147 Write : constant Entity_Id := Entity (Expression (Arg3));
9149 begin
9150 if Etype (Typ) = Any_Type
9151 or else
9152 Etype (Read) = Any_Type
9153 or else
9154 Etype (Write) = Any_Type
9155 then
9156 return;
9157 end if;
9159 Check_First_Subtype (Arg1);
9161 if Rep_Item_Too_Early (Typ, N)
9162 or else
9163 Rep_Item_Too_Late (Typ, N)
9164 then
9165 return;
9166 end if;
9168 if Underlying_Type (Etype (Read)) /= Typ then
9169 Error_Pragma_Arg
9170 ("incorrect return type for function&", Arg2);
9171 end if;
9173 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
9174 Error_Pragma_Arg
9175 ("incorrect parameter type for function&", Arg3);
9176 end if;
9178 if Underlying_Type (Etype (First_Formal (Read))) /=
9179 Underlying_Type (Etype (Write))
9180 then
9181 Error_Pragma_Arg
9182 ("result type of & does not match Read parameter type",
9183 Arg3);
9184 end if;
9185 end;
9186 end Stream_Convert;
9188 -------------------------
9189 -- Style_Checks (GNAT) --
9190 -------------------------
9192 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
9194 -- This is processed by the parser since some of the style
9195 -- checks take place during source scanning and parsing. This
9196 -- means that we don't need to issue error messages here.
9198 when Pragma_Style_Checks => Style_Checks : declare
9199 A : constant Node_Id := Expression (Arg1);
9200 S : String_Id;
9201 C : Char_Code;
9203 begin
9204 GNAT_Pragma;
9205 Check_No_Identifiers;
9207 -- Two argument form
9209 if Arg_Count = 2 then
9210 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9212 declare
9213 E_Id : Node_Id;
9214 E : Entity_Id;
9216 begin
9217 E_Id := Expression (Arg2);
9218 Analyze (E_Id);
9220 if not Is_Entity_Name (E_Id) then
9221 Error_Pragma_Arg
9222 ("second argument of pragma% must be entity name",
9223 Arg2);
9224 end if;
9226 E := Entity (E_Id);
9228 if E = Any_Id then
9229 return;
9230 else
9231 loop
9232 Set_Suppress_Style_Checks (E,
9233 (Chars (Expression (Arg1)) = Name_Off));
9234 exit when No (Homonym (E));
9235 E := Homonym (E);
9236 end loop;
9237 end if;
9238 end;
9240 -- One argument form
9242 else
9243 Check_Arg_Count (1);
9245 if Nkind (A) = N_String_Literal then
9246 S := Strval (A);
9248 declare
9249 Slen : constant Natural := Natural (String_Length (S));
9250 Options : String (1 .. Slen);
9251 J : Natural;
9253 begin
9254 J := 1;
9255 loop
9256 C := Get_String_Char (S, Int (J));
9257 exit when not In_Character_Range (C);
9258 Options (J) := Get_Character (C);
9260 if J = Slen then
9261 Set_Style_Check_Options (Options);
9262 exit;
9263 else
9264 J := J + 1;
9265 end if;
9266 end loop;
9267 end;
9269 elsif Nkind (A) = N_Identifier then
9271 if Chars (A) = Name_All_Checks then
9272 Set_Default_Style_Check_Options;
9274 elsif Chars (A) = Name_On then
9275 Style_Check := True;
9277 elsif Chars (A) = Name_Off then
9278 Style_Check := False;
9280 end if;
9281 end if;
9282 end if;
9283 end Style_Checks;
9285 --------------
9286 -- Subtitle --
9287 --------------
9289 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
9291 when Pragma_Subtitle =>
9292 GNAT_Pragma;
9293 Check_Arg_Count (1);
9294 Check_Optional_Identifier (Arg1, Name_Subtitle);
9295 Check_Arg_Is_String_Literal (Arg1);
9297 --------------
9298 -- Suppress --
9299 --------------
9301 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
9303 when Pragma_Suppress =>
9304 Process_Suppress_Unsuppress (True);
9306 ------------------
9307 -- Suppress_All --
9308 ------------------
9310 -- pragma Suppress_All;
9312 -- The only check made here is that the pragma appears in the
9313 -- proper place, i.e. following a compilation unit. If indeed
9314 -- it appears in this context, then the parser has already
9315 -- inserted an equivalent pragma Suppress (All_Checks) to get
9316 -- the required effect.
9318 when Pragma_Suppress_All =>
9319 GNAT_Pragma;
9320 Check_Arg_Count (0);
9322 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9323 or else not Is_List_Member (N)
9324 or else List_Containing (N) /= Pragmas_After (Parent (N))
9325 then
9326 Error_Pragma
9327 ("misplaced pragma%, must follow compilation unit");
9328 end if;
9330 -------------------------
9331 -- Suppress_Debug_Info --
9332 -------------------------
9334 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
9336 when Pragma_Suppress_Debug_Info =>
9337 GNAT_Pragma;
9338 Check_Arg_Count (1);
9339 Check_Arg_Is_Local_Name (Arg1);
9340 Check_Optional_Identifier (Arg1, Name_Entity);
9341 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
9343 ----------------------------------
9344 -- Suppress_Exception_Locations --
9345 ----------------------------------
9347 -- pragma Suppress_Exception_Locations;
9349 when Pragma_Suppress_Exception_Locations =>
9350 GNAT_Pragma;
9351 Check_Arg_Count (0);
9352 Check_Valid_Configuration_Pragma;
9353 Exception_Locations_Suppressed := True;
9355 -----------------------------
9356 -- Suppress_Initialization --
9357 -----------------------------
9359 -- pragma Suppress_Initialization ([Entity =>] type_Name);
9361 when Pragma_Suppress_Initialization => Suppress_Init : declare
9362 E_Id : Node_Id;
9363 E : Entity_Id;
9365 begin
9366 GNAT_Pragma;
9367 Check_Arg_Count (1);
9368 Check_Optional_Identifier (Arg1, Name_Entity);
9369 Check_Arg_Is_Local_Name (Arg1);
9371 E_Id := Expression (Arg1);
9373 if Etype (E_Id) = Any_Type then
9374 return;
9375 end if;
9377 E := Entity (E_Id);
9379 if Is_Type (E) then
9380 if Is_Incomplete_Or_Private_Type (E) then
9381 if No (Full_View (Base_Type (E))) then
9382 Error_Pragma_Arg
9383 ("argument of pragma% cannot be an incomplete type",
9384 Arg1);
9385 else
9386 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
9387 end if;
9388 else
9389 Set_Suppress_Init_Proc (Base_Type (E));
9390 end if;
9392 else
9393 Error_Pragma_Arg
9394 ("pragma% requires argument that is a type name", Arg1);
9395 end if;
9396 end Suppress_Init;
9398 -----------------
9399 -- System_Name --
9400 -----------------
9402 -- pragma System_Name (DIRECT_NAME);
9404 -- Syntax check: one argument, which must be the identifier GNAT
9405 -- or the identifier GCC, no other identifiers are acceptable.
9407 when Pragma_System_Name =>
9408 Check_No_Identifiers;
9409 Check_Arg_Count (1);
9410 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
9412 -----------------------------
9413 -- Task_Dispatching_Policy --
9414 -----------------------------
9416 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
9418 when Pragma_Task_Dispatching_Policy => declare
9419 DP : Character;
9421 begin
9422 Check_Ada_83_Warning;
9423 Check_Arg_Count (1);
9424 Check_No_Identifiers;
9425 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9426 Check_Valid_Configuration_Pragma;
9427 Get_Name_String (Chars (Expression (Arg1)));
9428 DP := Fold_Upper (Name_Buffer (1));
9430 if Task_Dispatching_Policy /= ' '
9431 and then Task_Dispatching_Policy /= DP
9432 then
9433 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9434 Error_Pragma
9435 ("task dispatching policy incompatible with policy#");
9437 -- Set new policy, but always preserve System_Location since
9438 -- we like the error message with the run time name.
9440 else
9441 Task_Dispatching_Policy := DP;
9443 if Task_Dispatching_Policy_Sloc /= System_Location then
9444 Task_Dispatching_Policy_Sloc := Loc;
9445 end if;
9446 end if;
9447 end;
9449 --------------
9450 -- Task_Info --
9451 --------------
9453 -- pragma Task_Info (EXPRESSION);
9455 when Pragma_Task_Info => Task_Info : declare
9456 P : constant Node_Id := Parent (N);
9458 begin
9459 GNAT_Pragma;
9461 if Nkind (P) /= N_Task_Definition then
9462 Error_Pragma ("pragma% must appear in task definition");
9463 end if;
9465 Check_No_Identifiers;
9466 Check_Arg_Count (1);
9468 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
9470 if Etype (Expression (Arg1)) = Any_Type then
9471 return;
9472 end if;
9474 if Has_Task_Info_Pragma (P) then
9475 Error_Pragma ("duplicate pragma% not allowed");
9476 else
9477 Set_Has_Task_Info_Pragma (P, True);
9478 end if;
9479 end Task_Info;
9481 ---------------
9482 -- Task_Name --
9483 ---------------
9485 -- pragma Task_Name (string_EXPRESSION);
9487 when Pragma_Task_Name => Task_Name : declare
9488 -- pragma Priority (EXPRESSION);
9490 P : constant Node_Id := Parent (N);
9491 Arg : Node_Id;
9493 begin
9494 Check_No_Identifiers;
9495 Check_Arg_Count (1);
9497 Arg := Expression (Arg1);
9498 Analyze_And_Resolve (Arg, Standard_String);
9500 if Nkind (P) /= N_Task_Definition then
9501 Pragma_Misplaced;
9502 end if;
9504 if Has_Task_Name_Pragma (P) then
9505 Error_Pragma ("duplicate pragma% not allowed");
9506 else
9507 Set_Has_Task_Name_Pragma (P, True);
9508 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9509 end if;
9510 end Task_Name;
9512 ------------------
9513 -- Task_Storage --
9514 ------------------
9516 -- pragma Task_Storage (
9517 -- [Task_Type =>] LOCAL_NAME,
9518 -- [Top_Guard =>] static_integer_EXPRESSION);
9520 when Pragma_Task_Storage => Task_Storage : declare
9521 Args : Args_List (1 .. 2);
9522 Names : constant Name_List (1 .. 2) := (
9523 Name_Task_Type,
9524 Name_Top_Guard);
9526 Task_Type : Node_Id renames Args (1);
9527 Top_Guard : Node_Id renames Args (2);
9529 Ent : Entity_Id;
9531 begin
9532 GNAT_Pragma;
9533 Gather_Associations (Names, Args);
9535 if No (Task_Type) then
9536 Error_Pragma
9537 ("missing task_type argument for pragma%");
9538 end if;
9540 Check_Arg_Is_Local_Name (Task_Type);
9542 Ent := Entity (Task_Type);
9544 if not Is_Task_Type (Ent) then
9545 Error_Pragma_Arg
9546 ("argument for pragma% must be task type", Task_Type);
9547 end if;
9549 if No (Top_Guard) then
9550 Error_Pragma_Arg
9551 ("pragma% takes two arguments", Task_Type);
9552 else
9553 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
9554 end if;
9556 Check_First_Subtype (Task_Type);
9558 if Rep_Item_Too_Late (Ent, N) then
9559 raise Pragma_Exit;
9560 end if;
9561 end Task_Storage;
9563 -----------------
9564 -- Thread_Body --
9565 -----------------
9567 -- pragma Thread_Body
9568 -- ( [Entity =>] LOCAL_NAME
9569 -- [,[Secondary_Stack_Size =>] static_integer_EXPRESSION]);
9571 when Pragma_Thread_Body => Thread_Body : declare
9572 Id : Node_Id;
9573 SS : Node_Id;
9574 E : Entity_Id;
9576 begin
9577 GNAT_Pragma;
9578 Check_At_Least_N_Arguments (1);
9579 Check_At_Most_N_Arguments (2);
9580 Check_Optional_Identifier (Arg1, Name_Entity);
9581 Check_Arg_Is_Local_Name (Arg1);
9583 Id := Expression (Arg1);
9585 if not Is_Entity_Name (Id)
9586 or else not Is_Subprogram (Entity (Id))
9587 then
9588 Error_Pragma_Arg ("subprogram name required", Arg1);
9589 end if;
9591 E := Entity (Id);
9593 -- Go to renamed subprogram if present, since Thread_Body applies
9594 -- to the actual renamed entity, not to the renaming entity.
9596 if Present (Alias (E))
9597 and then Nkind (Parent (Declaration_Node (E))) =
9598 N_Subprogram_Renaming_Declaration
9599 then
9600 E := Alias (E);
9601 end if;
9603 -- Various error checks
9605 if Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body then
9606 Error_Pragma
9607 ("pragma% requires separate spec and must come before body");
9609 elsif Rep_Item_Too_Early (E, N)
9610 or else
9611 Rep_Item_Too_Late (E, N)
9612 then
9613 raise Pragma_Exit;
9615 elsif Is_Thread_Body (E) then
9616 Error_Pragma_Arg
9617 ("only one thread body pragma allowed", Arg1);
9619 elsif Present (Homonym (E))
9620 and then Scope (Homonym (E)) = Current_Scope
9621 then
9622 Error_Pragma_Arg
9623 ("thread body subprogram must not be overloaded", Arg1);
9624 end if;
9626 Set_Is_Thread_Body (E);
9628 -- Deal with secondary stack argument
9630 if Arg_Count = 2 then
9631 Check_Optional_Identifier (Arg2, Name_Secondary_Stack_Size);
9632 SS := Expression (Arg2);
9633 Analyze_And_Resolve (SS, Any_Integer);
9634 end if;
9635 end Thread_Body;
9637 ----------------
9638 -- Time_Slice --
9639 ----------------
9641 -- pragma Time_Slice (static_duration_EXPRESSION);
9643 when Pragma_Time_Slice => Time_Slice : declare
9644 Val : Ureal;
9645 Nod : Node_Id;
9647 begin
9648 GNAT_Pragma;
9649 Check_Arg_Count (1);
9650 Check_No_Identifiers;
9651 Check_In_Main_Program;
9652 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
9654 if not Error_Posted (Arg1) then
9655 Nod := Next (N);
9656 while Present (Nod) loop
9657 if Nkind (Nod) = N_Pragma
9658 and then Chars (Nod) = Name_Time_Slice
9659 then
9660 Error_Msg_Name_1 := Chars (N);
9661 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9662 end if;
9664 Next (Nod);
9665 end loop;
9666 end if;
9668 -- Process only if in main unit
9670 if Get_Source_Unit (Loc) = Main_Unit then
9671 Opt.Time_Slice_Set := True;
9672 Val := Expr_Value_R (Expression (Arg1));
9674 if Val <= Ureal_0 then
9675 Opt.Time_Slice_Value := 0;
9677 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
9678 Opt.Time_Slice_Value := 1_000_000_000;
9680 else
9681 Opt.Time_Slice_Value :=
9682 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
9683 end if;
9684 end if;
9685 end Time_Slice;
9687 -----------
9688 -- Title --
9689 -----------
9691 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
9693 -- TITLING_OPTION ::=
9694 -- [Title =>] STRING_LITERAL
9695 -- | [Subtitle =>] STRING_LITERAL
9697 when Pragma_Title => Title : declare
9698 Args : Args_List (1 .. 2);
9699 Names : constant Name_List (1 .. 2) := (
9700 Name_Title,
9701 Name_Subtitle);
9703 begin
9704 GNAT_Pragma;
9705 Gather_Associations (Names, Args);
9707 for J in 1 .. 2 loop
9708 if Present (Args (J)) then
9709 Check_Arg_Is_String_Literal (Args (J));
9710 end if;
9711 end loop;
9712 end Title;
9714 ---------------------
9715 -- Unchecked_Union --
9716 ---------------------
9718 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
9720 when Pragma_Unchecked_Union => Unchecked_Union : declare
9721 Assoc : constant Node_Id := Arg1;
9722 Type_Id : constant Node_Id := Expression (Assoc);
9723 Typ : Entity_Id;
9724 Discr : Entity_Id;
9725 Tdef : Node_Id;
9726 Clist : Node_Id;
9727 Vpart : Node_Id;
9728 Comp : Node_Id;
9729 Variant : Node_Id;
9731 begin
9732 GNAT_Pragma;
9733 Check_No_Identifiers;
9734 Check_Arg_Count (1);
9735 Check_Arg_Is_Local_Name (Arg1);
9737 Find_Type (Type_Id);
9738 Typ := Entity (Type_Id);
9740 if Typ = Any_Type
9741 or else Rep_Item_Too_Early (Typ, N)
9742 then
9743 return;
9744 else
9745 Typ := Underlying_Type (Typ);
9746 end if;
9748 if Rep_Item_Too_Late (Typ, N) then
9749 return;
9750 end if;
9752 Check_First_Subtype (Arg1);
9754 -- Note remaining cases are references to a type in the current
9755 -- declarative part. If we find an error, we post the error on
9756 -- the relevant type declaration at an appropriate point.
9758 if not Is_Record_Type (Typ) then
9759 Error_Msg_N ("Unchecked_Union must be record type", Typ);
9760 return;
9762 elsif Is_Tagged_Type (Typ) then
9763 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
9764 return;
9766 elsif Is_Limited_Type (Typ) then
9767 Error_Msg_N
9768 ("Unchecked_Union must not be limited record type", Typ);
9769 Explain_Limited_Type (Typ, Typ);
9770 return;
9772 else
9773 if not Has_Discriminants (Typ) then
9774 Error_Msg_N
9775 ("Unchecked_Union must have one discriminant", Typ);
9776 return;
9777 end if;
9779 Discr := First_Discriminant (Typ);
9781 if Present (Next_Discriminant (Discr)) then
9782 Error_Msg_N
9783 ("Unchecked_Union must have exactly one discriminant",
9784 Next_Discriminant (Discr));
9785 return;
9786 end if;
9788 if No (Discriminant_Default_Value (Discr)) then
9789 Error_Msg_N
9790 ("Unchecked_Union discriminant must have default value",
9791 Discr);
9792 end if;
9794 Tdef := Type_Definition (Declaration_Node (Typ));
9795 Clist := Component_List (Tdef);
9797 Comp := First (Component_Items (Clist));
9798 while Present (Comp) loop
9800 Check_Component (Comp);
9801 Next (Comp);
9803 end loop;
9805 if No (Clist) or else No (Variant_Part (Clist)) then
9806 Error_Msg_N
9807 ("Unchecked_Union must have variant part",
9808 Tdef);
9809 return;
9810 end if;
9812 Vpart := Variant_Part (Clist);
9813 Variant := First (Variants (Vpart));
9814 while Present (Variant) loop
9816 Check_Variant (Variant);
9817 Next (Variant);
9819 end loop;
9820 end if;
9822 Set_Is_Unchecked_Union (Typ, True);
9823 Set_Convention (Typ, Convention_C);
9825 Set_Has_Unchecked_Union (Base_Type (Typ), True);
9826 Set_Is_Unchecked_Union (Base_Type (Typ), True);
9827 end Unchecked_Union;
9829 ------------------------
9830 -- Unimplemented_Unit --
9831 ------------------------
9833 -- pragma Unimplemented_Unit;
9835 -- Note: this only gives an error if we are generating code,
9836 -- or if we are in a generic library unit (where the pragma
9837 -- appears in the body, not in the spec).
9839 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
9840 Cunitent : constant Entity_Id :=
9841 Cunit_Entity (Get_Source_Unit (Loc));
9842 Ent_Kind : constant Entity_Kind :=
9843 Ekind (Cunitent);
9845 begin
9846 GNAT_Pragma;
9847 Check_Arg_Count (0);
9849 if Operating_Mode = Generate_Code
9850 or else Ent_Kind = E_Generic_Function
9851 or else Ent_Kind = E_Generic_Procedure
9852 or else Ent_Kind = E_Generic_Package
9853 then
9854 Get_Name_String (Chars (Cunitent));
9855 Set_Casing (Mixed_Case);
9856 Write_Str (Name_Buffer (1 .. Name_Len));
9857 Write_Str (" is not implemented");
9858 Write_Eol;
9859 raise Unrecoverable_Error;
9860 end if;
9861 end Unimplemented_Unit;
9863 --------------------
9864 -- Universal_Data --
9865 --------------------
9867 -- pragma Universal_Data [(library_unit_NAME)];
9869 when Pragma_Universal_Data =>
9870 GNAT_Pragma;
9872 -- If this is a configuration pragma, then set the universal
9873 -- addressing option, otherwise confirm that the pragma
9874 -- satisfies the requirements of library unit pragma placement
9875 -- and leave it to the GNAAMP back end to detect the pragma
9876 -- (avoids transitive setting of the option due to withed units).
9878 if Is_Configuration_Pragma then
9879 Universal_Addressing_On_AAMP := True;
9880 else
9881 Check_Valid_Library_Unit_Pragma;
9882 end if;
9884 if not AAMP_On_Target then
9885 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
9886 end if;
9888 ------------------
9889 -- Unreferenced --
9890 ------------------
9892 -- pragma Unreferenced (local_Name {, local_Name});
9894 when Pragma_Unreferenced => Unreferenced : declare
9895 Arg_Node : Node_Id;
9896 Arg_Expr : Node_Id;
9897 Arg_Ent : Entity_Id;
9899 begin
9900 GNAT_Pragma;
9901 Check_At_Least_N_Arguments (1);
9903 Arg_Node := Arg1;
9905 while Present (Arg_Node) loop
9906 Check_No_Identifier (Arg_Node);
9908 -- Note that the analyze call done by Check_Arg_Is_Local_Name
9909 -- will in fact generate a reference, so that the entity will
9910 -- have a reference, which will inhibit any warnings about it
9911 -- not being referenced, and also properly show up in the ali
9912 -- file as a reference. But this reference is recorded before
9913 -- the Has_Pragma_Unreferenced flag is set, so that no warning
9914 -- is generated for this reference.
9916 Check_Arg_Is_Local_Name (Arg_Node);
9917 Arg_Expr := Get_Pragma_Arg (Arg_Node);
9919 if Is_Entity_Name (Arg_Expr) then
9920 Arg_Ent := Entity (Arg_Expr);
9922 -- If the entity is overloaded, the pragma applies to the
9923 -- most recent overloading, as documented. In this case,
9924 -- name resolution does not generate a reference, so it
9925 -- must be done here explicitly.
9927 if Is_Overloaded (Arg_Expr) then
9928 Generate_Reference (Arg_Ent, N);
9929 end if;
9931 Set_Has_Pragma_Unreferenced (Arg_Ent);
9932 end if;
9934 Next (Arg_Node);
9935 end loop;
9936 end Unreferenced;
9938 ------------------------------
9939 -- Unreserve_All_Interrupts --
9940 ------------------------------
9942 -- pragma Unreserve_All_Interrupts;
9944 when Pragma_Unreserve_All_Interrupts =>
9945 GNAT_Pragma;
9946 Check_Arg_Count (0);
9948 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
9949 Unreserve_All_Interrupts := True;
9950 end if;
9952 ----------------
9953 -- Unsuppress --
9954 ----------------
9956 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
9958 when Pragma_Unsuppress =>
9959 GNAT_Pragma;
9960 Process_Suppress_Unsuppress (False);
9962 -------------------
9963 -- Use_VADS_Size --
9964 -------------------
9966 -- pragma Use_VADS_Size;
9968 when Pragma_Use_VADS_Size =>
9969 GNAT_Pragma;
9970 Check_Arg_Count (0);
9971 Check_Valid_Configuration_Pragma;
9972 Use_VADS_Size := True;
9974 ---------------------
9975 -- Validity_Checks --
9976 ---------------------
9978 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
9980 when Pragma_Validity_Checks => Validity_Checks : declare
9981 A : constant Node_Id := Expression (Arg1);
9982 S : String_Id;
9983 C : Char_Code;
9985 begin
9986 GNAT_Pragma;
9987 Check_Arg_Count (1);
9988 Check_No_Identifiers;
9990 if Nkind (A) = N_String_Literal then
9991 S := Strval (A);
9993 declare
9994 Slen : constant Natural := Natural (String_Length (S));
9995 Options : String (1 .. Slen);
9996 J : Natural;
9998 begin
9999 J := 1;
10000 loop
10001 C := Get_String_Char (S, Int (J));
10002 exit when not In_Character_Range (C);
10003 Options (J) := Get_Character (C);
10005 if J = Slen then
10006 Set_Validity_Check_Options (Options);
10007 exit;
10008 else
10009 J := J + 1;
10010 end if;
10011 end loop;
10012 end;
10014 elsif Nkind (A) = N_Identifier then
10016 if Chars (A) = Name_All_Checks then
10017 Set_Validity_Check_Options ("a");
10019 elsif Chars (A) = Name_On then
10020 Validity_Checks_On := True;
10022 elsif Chars (A) = Name_Off then
10023 Validity_Checks_On := False;
10025 end if;
10026 end if;
10027 end Validity_Checks;
10029 --------------
10030 -- Volatile --
10031 --------------
10033 -- pragma Volatile (LOCAL_NAME);
10035 when Pragma_Volatile =>
10036 Process_Atomic_Shared_Volatile;
10038 -------------------------
10039 -- Volatile_Components --
10040 -------------------------
10042 -- pragma Volatile_Components (array_LOCAL_NAME);
10044 -- Volatile is handled by the same circuit as Atomic_Components
10046 --------------
10047 -- Warnings --
10048 --------------
10050 -- pragma Warnings (On | Off, [LOCAL_NAME])
10052 when Pragma_Warnings => Warnings : begin
10053 GNAT_Pragma;
10054 Check_At_Least_N_Arguments (1);
10055 Check_At_Most_N_Arguments (2);
10056 Check_No_Identifiers;
10058 -- One argument case was processed by parser in Par.Prag
10060 if Arg_Count /= 1 then
10061 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10062 Check_Arg_Count (2);
10064 declare
10065 E_Id : Node_Id;
10066 E : Entity_Id;
10068 begin
10069 E_Id := Expression (Arg2);
10070 Analyze (E_Id);
10072 -- In the expansion of an inlined body, a reference to
10073 -- the formal may be wrapped in a conversion if the actual
10074 -- is a conversion. Retrieve the real entity name.
10076 if (In_Instance_Body
10077 or else In_Inlined_Body)
10078 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
10079 then
10080 E_Id := Expression (E_Id);
10081 end if;
10083 if not Is_Entity_Name (E_Id) then
10084 Error_Pragma_Arg
10085 ("second argument of pragma% must be entity name",
10086 Arg2);
10087 end if;
10089 E := Entity (E_Id);
10091 if E = Any_Id then
10092 return;
10093 else
10094 loop
10095 Set_Warnings_Off (E,
10096 (Chars (Expression (Arg1)) = Name_Off));
10098 if Is_Enumeration_Type (E) then
10099 declare
10100 Lit : Entity_Id := First_Literal (E);
10102 begin
10103 while Present (Lit) loop
10104 Set_Warnings_Off (Lit);
10105 Next_Literal (Lit);
10106 end loop;
10107 end;
10108 end if;
10110 exit when No (Homonym (E));
10111 E := Homonym (E);
10112 end loop;
10113 end if;
10114 end;
10115 end if;
10116 end Warnings;
10118 -------------------
10119 -- Weak_External --
10120 -------------------
10122 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
10124 when Pragma_Weak_External => Weak_External : declare
10125 Ent : Entity_Id;
10127 begin
10128 GNAT_Pragma;
10129 Check_Arg_Count (1);
10130 Check_Optional_Identifier (Arg1, Name_Entity);
10131 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10132 Ent := Entity (Expression (Arg1));
10134 if Rep_Item_Too_Early (Ent, N) then
10135 return;
10136 else
10137 Ent := Underlying_Type (Ent);
10138 end if;
10140 -- The only processing required is to link this item on to the
10141 -- list of rep items for the given entity. This is accomplished
10142 -- by the call to Rep_Item_Too_Late (when no error is detected
10143 -- and False is returned).
10145 if Rep_Item_Too_Late (Ent, N) then
10146 return;
10147 else
10148 Set_Has_Gigi_Rep_Item (Ent);
10149 end if;
10150 end Weak_External;
10152 --------------------
10153 -- Unknown_Pragma --
10154 --------------------
10156 -- Should be impossible, since the case of an unknown pragma is
10157 -- separately processed before the case statement is entered.
10159 when Unknown_Pragma =>
10160 raise Program_Error;
10161 end case;
10163 exception
10164 when Pragma_Exit => null;
10165 end Analyze_Pragma;
10167 ---------------------------------
10168 -- Delay_Config_Pragma_Analyze --
10169 ---------------------------------
10171 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
10172 begin
10173 return Chars (N) = Name_Interrupt_State;
10174 end Delay_Config_Pragma_Analyze;
10176 -------------------------
10177 -- Get_Base_Subprogram --
10178 -------------------------
10180 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
10181 Result : Entity_Id;
10183 begin
10184 Result := Def_Id;
10186 -- Follow subprogram renaming chain
10188 while Is_Subprogram (Result)
10189 and then
10190 (Is_Generic_Instance (Result)
10191 or else Nkind (Parent (Declaration_Node (Result))) =
10192 N_Subprogram_Renaming_Declaration)
10193 and then Present (Alias (Result))
10194 loop
10195 Result := Alias (Result);
10196 end loop;
10198 return Result;
10199 end Get_Base_Subprogram;
10201 -----------------------------
10202 -- Is_Config_Static_String --
10203 -----------------------------
10205 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
10207 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
10208 -- This is an internal recursive function that is just like the
10209 -- outer function except that it adds the string to the name buffer
10210 -- rather than placing the string in the name buffer.
10212 ------------------------------
10213 -- Add_Config_Static_String --
10214 ------------------------------
10216 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
10217 N : Node_Id;
10218 C : Char_Code;
10220 begin
10221 N := Arg;
10223 if Nkind (N) = N_Op_Concat then
10224 if Add_Config_Static_String (Left_Opnd (N)) then
10225 N := Right_Opnd (N);
10226 else
10227 return False;
10228 end if;
10229 end if;
10231 if Nkind (N) /= N_String_Literal then
10232 Error_Msg_N ("string literal expected for pragma argument", N);
10233 return False;
10235 else
10236 for J in 1 .. String_Length (Strval (N)) loop
10237 C := Get_String_Char (Strval (N), J);
10239 if not In_Character_Range (C) then
10240 Error_Msg
10241 ("string literal contains invalid wide character",
10242 Sloc (N) + 1 + Source_Ptr (J));
10243 return False;
10244 end if;
10246 Add_Char_To_Name_Buffer (Get_Character (C));
10247 end loop;
10248 end if;
10250 return True;
10251 end Add_Config_Static_String;
10253 -- Start of prorcessing for Is_Config_Static_String
10255 begin
10257 Name_Len := 0;
10258 return Add_Config_Static_String (Arg);
10259 end Is_Config_Static_String;
10261 -----------------------------------------
10262 -- Is_Non_Significant_Pragma_Reference --
10263 -----------------------------------------
10265 -- This function makes use of the following static table which indicates
10266 -- whether a given pragma is significant. A value of -1 in this table
10267 -- indicates that the reference is significant. A value of zero indicates
10268 -- than appearence as any argument is insignificant, a positive value
10269 -- indicates that appearence in that parameter position is significant.
10271 Sig_Flags : constant array (Pragma_Id) of Int :=
10273 (Pragma_AST_Entry => -1,
10274 Pragma_Abort_Defer => -1,
10275 Pragma_Ada_83 => -1,
10276 Pragma_Ada_95 => -1,
10277 Pragma_Ada_05 => -1,
10278 Pragma_All_Calls_Remote => -1,
10279 Pragma_Annotate => -1,
10280 Pragma_Assert => -1,
10281 Pragma_Asynchronous => -1,
10282 Pragma_Atomic => 0,
10283 Pragma_Atomic_Components => 0,
10284 Pragma_Attach_Handler => -1,
10285 Pragma_CPP_Class => 0,
10286 Pragma_CPP_Constructor => 0,
10287 Pragma_CPP_Virtual => 0,
10288 Pragma_CPP_Vtable => 0,
10289 Pragma_C_Pass_By_Copy => 0,
10290 Pragma_Comment => 0,
10291 Pragma_Common_Object => -1,
10292 Pragma_Compile_Time_Warning => -1,
10293 Pragma_Complex_Representation => 0,
10294 Pragma_Component_Alignment => -1,
10295 Pragma_Controlled => 0,
10296 Pragma_Convention => 0,
10297 Pragma_Convention_Identifier => 0,
10298 Pragma_Debug => -1,
10299 Pragma_Detect_Blocking => -1,
10300 Pragma_Discard_Names => 0,
10301 Pragma_Elaborate => -1,
10302 Pragma_Elaborate_All => -1,
10303 Pragma_Elaborate_Body => -1,
10304 Pragma_Elaboration_Checks => -1,
10305 Pragma_Eliminate => -1,
10306 Pragma_Explicit_Overriding => -1,
10307 Pragma_Export => -1,
10308 Pragma_Export_Exception => -1,
10309 Pragma_Export_Function => -1,
10310 Pragma_Export_Object => -1,
10311 Pragma_Export_Procedure => -1,
10312 Pragma_Export_Value => -1,
10313 Pragma_Export_Valued_Procedure => -1,
10314 Pragma_Extend_System => -1,
10315 Pragma_Extensions_Allowed => -1,
10316 Pragma_External => -1,
10317 Pragma_External_Name_Casing => -1,
10318 Pragma_Finalize_Storage_Only => 0,
10319 Pragma_Float_Representation => 0,
10320 Pragma_Ident => -1,
10321 Pragma_Import => +2,
10322 Pragma_Import_Exception => 0,
10323 Pragma_Import_Function => 0,
10324 Pragma_Import_Object => 0,
10325 Pragma_Import_Procedure => 0,
10326 Pragma_Import_Valued_Procedure => 0,
10327 Pragma_Initialize_Scalars => -1,
10328 Pragma_Inline => 0,
10329 Pragma_Inline_Always => 0,
10330 Pragma_Inline_Generic => 0,
10331 Pragma_Inspection_Point => -1,
10332 Pragma_Interface => +2,
10333 Pragma_Interface_Name => +2,
10334 Pragma_Interrupt_Handler => -1,
10335 Pragma_Interrupt_Priority => -1,
10336 Pragma_Interrupt_State => -1,
10337 Pragma_Java_Constructor => -1,
10338 Pragma_Java_Interface => -1,
10339 Pragma_Keep_Names => 0,
10340 Pragma_License => -1,
10341 Pragma_Link_With => -1,
10342 Pragma_Linker_Alias => -1,
10343 Pragma_Linker_Options => -1,
10344 Pragma_Linker_Section => -1,
10345 Pragma_List => -1,
10346 Pragma_Locking_Policy => -1,
10347 Pragma_Long_Float => -1,
10348 Pragma_Machine_Attribute => -1,
10349 Pragma_Main => -1,
10350 Pragma_Main_Storage => -1,
10351 Pragma_Memory_Size => -1,
10352 Pragma_No_Return => 0,
10353 Pragma_No_Run_Time => -1,
10354 Pragma_No_Strict_Aliasing => -1,
10355 Pragma_Normalize_Scalars => -1,
10356 Pragma_Obsolescent => 0,
10357 Pragma_Optimize => -1,
10358 Pragma_Optional_Overriding => -1,
10359 Pragma_Overriding => -1,
10360 Pragma_Pack => 0,
10361 Pragma_Page => -1,
10362 Pragma_Passive => -1,
10363 Pragma_Polling => -1,
10364 Pragma_Persistent_Data => -1,
10365 Pragma_Persistent_Object => -1,
10366 Pragma_Preelaborate => -1,
10367 Pragma_Priority => -1,
10368 Pragma_Profile => 0,
10369 Pragma_Profile_Warnings => 0,
10370 Pragma_Propagate_Exceptions => -1,
10371 Pragma_Psect_Object => -1,
10372 Pragma_Pure => 0,
10373 Pragma_Pure_Function => 0,
10374 Pragma_Queuing_Policy => -1,
10375 Pragma_Ravenscar => -1,
10376 Pragma_Remote_Call_Interface => -1,
10377 Pragma_Remote_Types => -1,
10378 Pragma_Restricted_Run_Time => -1,
10379 Pragma_Restriction_Warnings => -1,
10380 Pragma_Restrictions => -1,
10381 Pragma_Reviewable => -1,
10382 Pragma_Share_Generic => -1,
10383 Pragma_Shared => -1,
10384 Pragma_Shared_Passive => -1,
10385 Pragma_Source_File_Name => -1,
10386 Pragma_Source_File_Name_Project => -1,
10387 Pragma_Source_Reference => -1,
10388 Pragma_Storage_Size => -1,
10389 Pragma_Storage_Unit => -1,
10390 Pragma_Stream_Convert => -1,
10391 Pragma_Style_Checks => -1,
10392 Pragma_Subtitle => -1,
10393 Pragma_Suppress => 0,
10394 Pragma_Suppress_Exception_Locations => 0,
10395 Pragma_Suppress_All => -1,
10396 Pragma_Suppress_Debug_Info => 0,
10397 Pragma_Suppress_Initialization => 0,
10398 Pragma_System_Name => -1,
10399 Pragma_Task_Dispatching_Policy => -1,
10400 Pragma_Task_Info => -1,
10401 Pragma_Task_Name => -1,
10402 Pragma_Task_Storage => 0,
10403 Pragma_Thread_Body => +2,
10404 Pragma_Time_Slice => -1,
10405 Pragma_Title => -1,
10406 Pragma_Unchecked_Union => 0,
10407 Pragma_Unimplemented_Unit => -1,
10408 Pragma_Universal_Data => -1,
10409 Pragma_Unreferenced => -1,
10410 Pragma_Unreserve_All_Interrupts => -1,
10411 Pragma_Unsuppress => 0,
10412 Pragma_Use_VADS_Size => -1,
10413 Pragma_Validity_Checks => -1,
10414 Pragma_Volatile => 0,
10415 Pragma_Volatile_Components => 0,
10416 Pragma_Warnings => -1,
10417 Pragma_Weak_External => 0,
10418 Unknown_Pragma => 0);
10420 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
10421 P : Node_Id;
10422 C : Int;
10423 A : Node_Id;
10425 begin
10426 P := Parent (N);
10428 if Nkind (P) /= N_Pragma_Argument_Association then
10429 return False;
10431 else
10432 C := Sig_Flags (Get_Pragma_Id (Chars (Parent (P))));
10434 case C is
10435 when -1 =>
10436 return False;
10438 when 0 =>
10439 return True;
10441 when others =>
10442 A := First (Pragma_Argument_Associations (Parent (P)));
10443 for J in 1 .. C - 1 loop
10444 if No (A) then
10445 return False;
10446 end if;
10448 Next (A);
10449 end loop;
10451 return A = P;
10452 end case;
10453 end if;
10454 end Is_Non_Significant_Pragma_Reference;
10456 ------------------------------
10457 -- Is_Pragma_String_Literal --
10458 ------------------------------
10460 -- This function returns true if the corresponding pragma argument is
10461 -- a static string expression. These are the only cases in which string
10462 -- literals can appear as pragma arguments. We also allow a string
10463 -- literal as the first argument to pragma Assert (although it will
10464 -- of course always generate a type error).
10466 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
10467 Pragn : constant Node_Id := Parent (Par);
10468 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
10469 Pname : constant Name_Id := Chars (Pragn);
10470 Argn : Natural;
10471 N : Node_Id;
10473 begin
10474 Argn := 1;
10475 N := First (Assoc);
10476 loop
10477 exit when N = Par;
10478 Argn := Argn + 1;
10479 Next (N);
10480 end loop;
10482 if Pname = Name_Assert then
10483 return True;
10485 elsif Pname = Name_Export then
10486 return Argn > 2;
10488 elsif Pname = Name_Ident then
10489 return Argn = 1;
10491 elsif Pname = Name_Import then
10492 return Argn > 2;
10494 elsif Pname = Name_Interface_Name then
10495 return Argn > 1;
10497 elsif Pname = Name_Linker_Alias then
10498 return Argn = 2;
10500 elsif Pname = Name_Linker_Section then
10501 return Argn = 2;
10503 elsif Pname = Name_Machine_Attribute then
10504 return Argn = 2;
10506 elsif Pname = Name_Source_File_Name then
10507 return True;
10509 elsif Pname = Name_Source_Reference then
10510 return Argn = 2;
10512 elsif Pname = Name_Title then
10513 return True;
10515 elsif Pname = Name_Subtitle then
10516 return True;
10518 else
10519 return False;
10520 end if;
10521 end Is_Pragma_String_Literal;
10523 --------------------------------------
10524 -- Process_Compilation_Unit_Pragmas --
10525 --------------------------------------
10527 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
10528 begin
10529 -- A special check for pragma Suppress_All. This is a strange DEC
10530 -- pragma, strange because it comes at the end of the unit. If we
10531 -- have a pragma Suppress_All in the Pragmas_After of the current
10532 -- unit, then we insert a pragma Suppress (All_Checks) at the start
10533 -- of the context clause to ensure the correct processing.
10535 declare
10536 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
10537 P : Node_Id;
10539 begin
10540 if Present (PA) then
10541 P := First (PA);
10542 while Present (P) loop
10543 if Chars (P) = Name_Suppress_All then
10544 Prepend_To (Context_Items (N),
10545 Make_Pragma (Sloc (P),
10546 Chars => Name_Suppress,
10547 Pragma_Argument_Associations => New_List (
10548 Make_Pragma_Argument_Association (Sloc (P),
10549 Expression =>
10550 Make_Identifier (Sloc (P),
10551 Chars => Name_All_Checks)))));
10552 exit;
10553 end if;
10555 Next (P);
10556 end loop;
10557 end if;
10558 end;
10559 end Process_Compilation_Unit_Pragmas;
10561 --------------------------------
10562 -- Set_Encoded_Interface_Name --
10563 --------------------------------
10565 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
10566 Str : constant String_Id := Strval (S);
10567 Len : constant Int := String_Length (Str);
10568 CC : Char_Code;
10569 C : Character;
10570 J : Int;
10572 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
10574 procedure Encode;
10575 -- Stores encoded value of character code CC. The encoding we
10576 -- use an underscore followed by four lower case hex digits.
10578 procedure Encode is
10579 begin
10580 Store_String_Char (Get_Char_Code ('_'));
10581 Store_String_Char
10582 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
10583 Store_String_Char
10584 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
10585 Store_String_Char
10586 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
10587 Store_String_Char
10588 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
10589 end Encode;
10591 -- Start of processing for Set_Encoded_Interface_Name
10593 begin
10594 -- If first character is asterisk, this is a link name, and we
10595 -- leave it completely unmodified. We also ignore null strings
10596 -- (the latter case happens only in error cases) and no encoding
10597 -- should occur for Java interface names.
10599 if Len = 0
10600 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
10601 or else Java_VM
10602 then
10603 Set_Interface_Name (E, S);
10605 else
10606 J := 1;
10607 loop
10608 CC := Get_String_Char (Str, J);
10610 exit when not In_Character_Range (CC);
10612 C := Get_Character (CC);
10614 exit when C /= '_' and then C /= '$'
10615 and then C not in '0' .. '9'
10616 and then C not in 'a' .. 'z'
10617 and then C not in 'A' .. 'Z';
10619 if J = Len then
10620 Set_Interface_Name (E, S);
10621 return;
10623 else
10624 J := J + 1;
10625 end if;
10626 end loop;
10628 -- Here we need to encode. The encoding we use as follows:
10629 -- three underscores + four hex digits (lower case)
10631 Start_String;
10633 for J in 1 .. String_Length (Str) loop
10634 CC := Get_String_Char (Str, J);
10636 if not In_Character_Range (CC) then
10637 Encode;
10638 else
10639 C := Get_Character (CC);
10641 if C = '_' or else C = '$'
10642 or else C in '0' .. '9'
10643 or else C in 'a' .. 'z'
10644 or else C in 'A' .. 'Z'
10645 then
10646 Store_String_Char (CC);
10647 else
10648 Encode;
10649 end if;
10650 end if;
10651 end loop;
10653 Set_Interface_Name (E,
10654 Make_String_Literal (Sloc (S),
10655 Strval => End_String));
10656 end if;
10657 end Set_Encoded_Interface_Name;
10659 -------------------
10660 -- Set_Unit_Name --
10661 -------------------
10663 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
10664 Pref : Node_Id;
10665 Scop : Entity_Id;
10667 begin
10668 if Nkind (N) = N_Identifier
10669 and then Nkind (With_Item) = N_Identifier
10670 then
10671 Set_Entity (N, Entity (With_Item));
10673 elsif Nkind (N) = N_Selected_Component then
10674 Change_Selected_Component_To_Expanded_Name (N);
10675 Set_Entity (N, Entity (With_Item));
10676 Set_Entity (Selector_Name (N), Entity (N));
10678 Pref := Prefix (N);
10679 Scop := Scope (Entity (N));
10681 while Nkind (Pref) = N_Selected_Component loop
10682 Change_Selected_Component_To_Expanded_Name (Pref);
10683 Set_Entity (Selector_Name (Pref), Scop);
10684 Set_Entity (Pref, Scop);
10685 Pref := Prefix (Pref);
10686 Scop := Scope (Scop);
10687 end loop;
10689 Set_Entity (Pref, Scop);
10690 end if;
10691 end Set_Unit_Name;
10693 end Sem_Prag;