* varasm.c (default_assemble_integer): Return false for values wider
[official-gcc.git] / gcc / ada / sem_prag.adb
blob6fd97d8a269462e659fb5e1abaa1bf0351fc558f
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;
2932 while Present (Hom_Id) loop
2933 Def_Id := Get_Base_Subprogram (Hom_Id);
2935 -- Ignore inherited subprograms because the pragma will
2936 -- apply to the parent operation, which is the one called.
2938 if Is_Overloadable (Def_Id)
2939 and then Present (Alias (Def_Id))
2940 then
2941 null;
2943 -- If it is not a subprogram, it must be in an outer
2944 -- scope and pragma does not apply.
2946 elsif not Is_Subprogram (Def_Id)
2947 and then not Is_Generic_Subprogram (Def_Id)
2948 then
2949 null;
2951 -- Verify that the homonym is in the same declarative
2952 -- part (not just the same scope).
2954 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
2955 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
2956 then
2957 exit;
2959 else
2960 Set_Imported (Def_Id);
2962 -- If Import intrinsic, set intrinsic flag
2963 -- and verify that it is known as such.
2965 if C = Convention_Intrinsic then
2966 Set_Is_Intrinsic_Subprogram (Def_Id);
2967 Check_Intrinsic_Subprogram
2968 (Def_Id, Expression (Arg2));
2969 end if;
2971 -- All interfaced procedures need an external
2972 -- symbol created for them since they are
2973 -- always referenced from another object file.
2975 Set_Is_Public (Def_Id);
2977 -- Verify that the subprogram does not have a completion
2978 -- through a renaming declaration. For other completions
2979 -- the pragma appears as a too late representation.
2981 declare
2982 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
2984 begin
2985 if Present (Decl)
2986 and then Nkind (Decl) = N_Subprogram_Declaration
2987 and then Present (Corresponding_Body (Decl))
2988 and then
2989 Nkind
2990 (Unit_Declaration_Node
2991 (Corresponding_Body (Decl))) =
2992 N_Subprogram_Renaming_Declaration
2993 then
2994 Error_Msg_Sloc := Sloc (Def_Id);
2995 Error_Msg_NE ("cannot import&#," &
2996 " already completed by a renaming",
2997 N, Def_Id);
2998 end if;
2999 end;
3001 Set_Has_Completion (Def_Id);
3002 Process_Interface_Name (Def_Id, Arg3, Arg4);
3003 end if;
3005 if Is_Compilation_Unit (Hom_Id) then
3007 -- Its possible homonyms are not affected by the pragma.
3008 -- Such homonyms might be present in the context of other
3009 -- units being compiled.
3011 exit;
3013 else
3014 Hom_Id := Homonym (Hom_Id);
3015 end if;
3016 end loop;
3018 -- When the convention is Java, we also allow Import to be given
3019 -- for packages, exceptions, and record components.
3021 elsif C = Convention_Java
3022 and then
3023 (Ekind (Def_Id) = E_Package
3024 or else Ekind (Def_Id) = E_Exception
3025 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3026 then
3027 Set_Imported (Def_Id);
3028 Set_Is_Public (Def_Id);
3029 Process_Interface_Name (Def_Id, Arg3, Arg4);
3031 else
3032 Error_Pragma_Arg
3033 ("second argument of pragma% must be object or subprogram",
3034 Arg2);
3035 end if;
3037 -- If this pragma applies to a compilation unit, then the unit,
3038 -- which is a subprogram, does not require (or allow) a body.
3039 -- We also do not need to elaborate imported procedures.
3041 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3042 declare
3043 Cunit : constant Node_Id := Parent (Parent (N));
3044 begin
3045 Set_Body_Required (Cunit, False);
3046 end;
3047 end if;
3048 end Process_Import_Or_Interface;
3050 --------------------
3051 -- Process_Inline --
3052 --------------------
3054 procedure Process_Inline (Active : Boolean) is
3055 Assoc : Node_Id;
3056 Decl : Node_Id;
3057 Subp_Id : Node_Id;
3058 Subp : Entity_Id;
3059 Applies : Boolean;
3060 Effective : Boolean := False;
3062 procedure Make_Inline (Subp : Entity_Id);
3063 -- Subp is the defining unit name of the subprogram
3064 -- declaration. Set the flag, as well as the flag in the
3065 -- corresponding body, if there is one present.
3067 procedure Set_Inline_Flags (Subp : Entity_Id);
3068 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp
3070 function Cannot_Inline (Subp : Entity_Id) return Boolean;
3071 -- Do not set the inline flag if body is available and contains
3072 -- exception handlers, to prevent undefined symbols at link time.
3073 -- Emit warning if front-end inlining is enabled and the pragma
3074 -- appears too late.
3076 -------------------
3077 -- Cannot_Inline --
3078 -------------------
3080 function Cannot_Inline (Subp : Entity_Id) return Boolean is
3081 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3083 begin
3084 if Nkind (Decl) = N_Subprogram_Body then
3085 return
3086 Present
3087 (Exception_Handlers (Handled_Statement_Sequence (Decl)));
3089 elsif Nkind (Decl) = N_Subprogram_Declaration
3090 and then Present (Corresponding_Body (Decl))
3091 then
3092 if Front_End_Inlining
3093 and then Analyzed (Corresponding_Body (Decl))
3094 then
3095 Error_Msg_N ("pragma appears too late, ignored?", N);
3096 return True;
3098 -- If the subprogram is a renaming as body, the body is
3099 -- just a call to the renamed subprogram, and inlining is
3100 -- trivially possible.
3102 elsif
3103 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
3104 = N_Subprogram_Renaming_Declaration
3105 then
3106 return False;
3108 else
3109 return
3110 Present (Exception_Handlers
3111 (Handled_Statement_Sequence
3112 (Unit_Declaration_Node (Corresponding_Body (Decl)))));
3113 end if;
3114 else
3115 -- If body is not available, assume the best, the check is
3116 -- performed again when compiling enclosing package bodies.
3118 return False;
3119 end if;
3120 end Cannot_Inline;
3122 -----------------
3123 -- Make_Inline --
3124 -----------------
3126 procedure Make_Inline (Subp : Entity_Id) is
3127 Kind : constant Entity_Kind := Ekind (Subp);
3128 Inner_Subp : Entity_Id := Subp;
3130 begin
3131 if Etype (Subp) = Any_Type then
3132 return;
3134 elsif Cannot_Inline (Subp) then
3135 Applies := True; -- Do not treat as an error.
3136 return;
3138 -- Here we have a candidate for inlining, but we must exclude
3139 -- derived operations. Otherwise we will end up trying to
3140 -- inline a phantom declaration, and the result would be to
3141 -- drag in a body which has no direct inlining associated with
3142 -- it. That would not only be inefficient but would also result
3143 -- in the backend doing cross-unit inlining in cases where it
3144 -- was definitely inappropriate to do so.
3146 -- However, a simple Comes_From_Source test is insufficient,
3147 -- since we do want to allow inlining of generic instances,
3148 -- which also do not come from source. Predefined operators do
3149 -- not come from source but are not inlineable either.
3151 elsif not Comes_From_Source (Subp)
3152 and then not Is_Generic_Instance (Subp)
3153 and then Scope (Subp) /= Standard_Standard
3154 then
3155 Applies := True;
3156 return;
3158 -- The referenced entity must either be the enclosing entity,
3159 -- or an entity declared within the current open scope.
3161 elsif Present (Scope (Subp))
3162 and then Scope (Subp) /= Current_Scope
3163 and then Subp /= Current_Scope
3164 then
3165 Error_Pragma_Arg
3166 ("argument of% must be entity in current scope", Assoc);
3167 return;
3168 end if;
3170 -- Processing for procedure, operator or function.
3171 -- If subprogram is aliased (as for an instance) indicate
3172 -- that the renamed entity (if declared in the same unit)
3173 -- is inlined.
3175 if Is_Subprogram (Subp) then
3176 while Present (Alias (Inner_Subp)) loop
3177 Inner_Subp := Alias (Inner_Subp);
3178 end loop;
3180 if In_Same_Source_Unit (Subp, Inner_Subp) then
3181 Set_Inline_Flags (Inner_Subp);
3183 Decl := Parent (Parent (Inner_Subp));
3185 if Nkind (Decl) = N_Subprogram_Declaration
3186 and then Present (Corresponding_Body (Decl))
3187 then
3188 Set_Inline_Flags (Corresponding_Body (Decl));
3189 end if;
3190 end if;
3192 Applies := True;
3194 -- For a generic subprogram set flag as well, for use at
3195 -- the point of instantiation, to determine whether the
3196 -- body should be generated.
3198 elsif Is_Generic_Subprogram (Subp) then
3199 Set_Inline_Flags (Subp);
3200 Applies := True;
3202 -- Literals are by definition inlined
3204 elsif Kind = E_Enumeration_Literal then
3205 null;
3207 -- Anything else is an error
3209 else
3210 Error_Pragma_Arg
3211 ("expect subprogram name for pragma%", Assoc);
3212 end if;
3213 end Make_Inline;
3215 ----------------------
3216 -- Set_Inline_Flags --
3217 ----------------------
3219 procedure Set_Inline_Flags (Subp : Entity_Id) is
3220 begin
3221 if Active then
3222 Set_Is_Inlined (Subp, True);
3223 end if;
3225 if not Has_Pragma_Inline (Subp) then
3226 Set_Has_Pragma_Inline (Subp);
3227 Set_Next_Rep_Item (N, First_Rep_Item (Subp));
3228 Set_First_Rep_Item (Subp, N);
3229 Effective := True;
3230 end if;
3231 end Set_Inline_Flags;
3233 -- Start of processing for Process_Inline
3235 begin
3236 Check_No_Identifiers;
3237 Check_At_Least_N_Arguments (1);
3239 if Active then
3240 Inline_Processing_Required := True;
3241 end if;
3243 Assoc := Arg1;
3244 while Present (Assoc) loop
3245 Subp_Id := Expression (Assoc);
3246 Analyze (Subp_Id);
3247 Applies := False;
3249 if Is_Entity_Name (Subp_Id) then
3250 Subp := Entity (Subp_Id);
3252 if Subp = Any_Id then
3253 Applies := True;
3255 else
3256 Make_Inline (Subp);
3258 while Present (Homonym (Subp))
3259 and then Scope (Homonym (Subp)) = Current_Scope
3260 loop
3261 Make_Inline (Homonym (Subp));
3262 Subp := Homonym (Subp);
3263 end loop;
3264 end if;
3265 end if;
3267 if not Applies then
3268 Error_Pragma_Arg
3269 ("inappropriate argument for pragma%", Assoc);
3271 elsif not Effective
3272 and then Warn_On_Redundant_Constructs
3273 then
3274 Error_Msg_NE ("pragma inline on& is redundant?",
3275 N, Entity (Subp_Id));
3276 end if;
3278 Next (Assoc);
3279 end loop;
3280 end Process_Inline;
3282 ----------------------------
3283 -- Process_Interface_Name --
3284 ----------------------------
3286 procedure Process_Interface_Name
3287 (Subprogram_Def : Entity_Id;
3288 Ext_Arg : Node_Id;
3289 Link_Arg : Node_Id)
3291 Ext_Nam : Node_Id;
3292 Link_Nam : Node_Id;
3293 String_Val : String_Id;
3295 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
3296 -- SN is a string literal node for an interface name. This routine
3297 -- performs some minimal checks that the name is reasonable. In
3298 -- particular that no spaces or other obviously incorrect characters
3299 -- appear. This is only a warning, since any characters are allowed.
3301 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
3302 S : constant String_Id := Strval (Expr_Value_S (SN));
3303 SL : constant Nat := String_Length (S);
3304 C : Char_Code;
3306 begin
3307 if SL = 0 then
3308 Error_Msg_N ("interface name cannot be null string", SN);
3309 end if;
3311 for J in 1 .. SL loop
3312 C := Get_String_Char (S, J);
3314 if Warn_On_Export_Import
3315 and then (not In_Character_Range (C)
3316 or else Get_Character (C) = ' '
3317 or else Get_Character (C) = ',')
3318 then
3319 Error_Msg_N
3320 ("?interface name contains illegal character", SN);
3321 end if;
3322 end loop;
3323 end Check_Form_Of_Interface_Name;
3325 -- Start of processing for Process_Interface_Name
3327 begin
3328 if No (Link_Arg) then
3329 if No (Ext_Arg) then
3330 return;
3332 elsif Chars (Ext_Arg) = Name_Link_Name then
3333 Ext_Nam := Empty;
3334 Link_Nam := Expression (Ext_Arg);
3336 else
3337 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3338 Ext_Nam := Expression (Ext_Arg);
3339 Link_Nam := Empty;
3340 end if;
3342 else
3343 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3344 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
3345 Ext_Nam := Expression (Ext_Arg);
3346 Link_Nam := Expression (Link_Arg);
3347 end if;
3349 -- Check expressions for external name and link name are static
3351 if Present (Ext_Nam) then
3352 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
3353 Check_Form_Of_Interface_Name (Ext_Nam);
3355 -- Verify that the external name is not the name of a local
3356 -- entity, which would hide the imported one and lead to
3357 -- run-time surprises. The problem can only arise for entities
3358 -- declared in a package body (otherwise the external name is
3359 -- fully qualified and won't conflict).
3361 declare
3362 Nam : Name_Id;
3363 E : Entity_Id;
3364 Par : Node_Id;
3366 begin
3367 if Prag_Id = Pragma_Import then
3368 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
3369 Nam := Name_Find;
3370 E := Entity_Id (Get_Name_Table_Info (Nam));
3372 if Nam /= Chars (Subprogram_Def)
3373 and then Present (E)
3374 and then not Is_Overloadable (E)
3375 and then Is_Immediately_Visible (E)
3376 and then not Is_Imported (E)
3377 and then Ekind (Scope (E)) = E_Package
3378 then
3379 Par := Parent (E);
3381 while Present (Par) loop
3382 if Nkind (Par) = N_Package_Body then
3383 Error_Msg_Sloc := Sloc (E);
3384 Error_Msg_NE
3385 ("imported entity is hidden by & declared#",
3386 Ext_Arg, E);
3387 exit;
3388 end if;
3390 Par := Parent (Par);
3391 end loop;
3392 end if;
3393 end if;
3394 end;
3395 end if;
3397 if Present (Link_Nam) then
3398 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
3399 Check_Form_Of_Interface_Name (Link_Nam);
3400 end if;
3402 -- If there is no link name, just set the external name
3404 if No (Link_Nam) then
3405 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
3407 -- For the Link_Name case, the given literal is preceded by an
3408 -- asterisk, which indicates to GCC that the given name should
3409 -- be taken literally, and in particular that no prepending of
3410 -- underlines should occur, even in systems where this is the
3411 -- normal default.
3413 else
3414 Start_String;
3415 Store_String_Char (Get_Char_Code ('*'));
3416 String_Val := Strval (Expr_Value_S (Link_Nam));
3418 for J in 1 .. String_Length (String_Val) loop
3419 Store_String_Char (Get_String_Char (String_Val, J));
3420 end loop;
3422 Link_Nam :=
3423 Make_String_Literal (Sloc (Link_Nam), End_String);
3424 end if;
3426 Set_Encoded_Interface_Name
3427 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
3428 Check_Duplicated_Export_Name (Link_Nam);
3429 end Process_Interface_Name;
3431 -----------------------------------------
3432 -- Process_Interrupt_Or_Attach_Handler --
3433 -----------------------------------------
3435 procedure Process_Interrupt_Or_Attach_Handler is
3436 Arg1_X : constant Node_Id := Expression (Arg1);
3437 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
3438 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
3440 begin
3441 Set_Is_Interrupt_Handler (Handler_Proc);
3443 -- If the pragma is not associated with a handler procedure
3444 -- within a protected type, then it must be for a nonprotected
3445 -- procedure for the AAMP target, in which case we don't
3446 -- associate a representation item with the procedure's scope.
3448 if Ekind (Proc_Scope) = E_Protected_Type then
3449 if Prag_Id = Pragma_Interrupt_Handler
3450 or else
3451 Prag_Id = Pragma_Attach_Handler
3452 then
3453 Record_Rep_Item (Proc_Scope, N);
3454 end if;
3455 end if;
3456 end Process_Interrupt_Or_Attach_Handler;
3458 --------------------------------------------------
3459 -- Process_Restrictions_Or_Restriction_Warnings --
3460 --------------------------------------------------
3462 procedure Process_Restrictions_Or_Restriction_Warnings is
3463 Arg : Node_Id;
3464 R_Id : Restriction_Id;
3465 Id : Name_Id;
3466 Expr : Node_Id;
3467 Val : Uint;
3469 procedure Set_Warning (R : All_Restrictions);
3470 -- If this is a Restriction_Warnings pragma, set warning flag,
3471 -- otherwise reset the flag.
3473 -----------------
3474 -- Set_Warning --
3475 -----------------
3477 procedure Set_Warning (R : All_Restrictions) is
3478 begin
3479 if Prag_Id = Pragma_Restriction_Warnings then
3480 Restriction_Warnings (R) := True;
3481 else
3482 Restriction_Warnings (R) := False;
3483 end if;
3484 end Set_Warning;
3486 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
3488 begin
3489 Check_Ada_83_Warning;
3490 Check_At_Least_N_Arguments (1);
3491 Check_Valid_Configuration_Pragma;
3493 Arg := Arg1;
3494 while Present (Arg) loop
3495 Id := Chars (Arg);
3496 Expr := Expression (Arg);
3498 -- Case of no restriction identifier present
3500 if Id = No_Name then
3501 if Nkind (Expr) /= N_Identifier then
3502 Error_Pragma_Arg
3503 ("invalid form for restriction", Arg);
3504 end if;
3506 R_Id :=
3507 Get_Restriction_Id
3508 (Process_Restriction_Synonyms (Expr));
3510 if R_Id not in All_Boolean_Restrictions then
3511 Error_Pragma_Arg
3512 ("invalid restriction identifier", Arg);
3513 end if;
3515 if Implementation_Restriction (R_Id) then
3516 Check_Restriction
3517 (No_Implementation_Restrictions, Arg);
3518 end if;
3520 Set_Restriction (R_Id, N);
3521 Set_Warning (R_Id);
3523 -- A very special case that must be processed here:
3524 -- pragma Restrictions (No_Exceptions) turns off
3525 -- all run-time checking. This is a bit dubious in
3526 -- terms of the formal language definition, but it
3527 -- is what is intended by RM H.4(12).
3529 if R_Id = No_Exceptions then
3530 Scope_Suppress := (others => True);
3531 end if;
3533 -- Case of restriction identifier present
3535 else
3536 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
3537 Analyze_And_Resolve (Expr, Any_Integer);
3539 if R_Id not in All_Parameter_Restrictions then
3540 Error_Pragma_Arg
3541 ("invalid restriction parameter identifier", Arg);
3543 elsif not Is_OK_Static_Expression (Expr) then
3544 Flag_Non_Static_Expr
3545 ("value must be static expression!", Expr);
3546 raise Pragma_Exit;
3548 elsif not Is_Integer_Type (Etype (Expr))
3549 or else Expr_Value (Expr) < 0
3550 then
3551 Error_Pragma_Arg
3552 ("value must be non-negative integer", Arg);
3554 -- Restriction pragma is active
3556 else
3557 Val := Expr_Value (Expr);
3559 if not UI_Is_In_Int_Range (Val) then
3560 Error_Pragma_Arg
3561 ("pragma ignored, value too large?", Arg);
3562 else
3563 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
3564 Set_Warning (R_Id);
3565 end if;
3566 end if;
3567 end if;
3569 Next (Arg);
3570 end loop;
3571 end Process_Restrictions_Or_Restriction_Warnings;
3573 ---------------------------------
3574 -- Process_Suppress_Unsuppress --
3575 ---------------------------------
3577 -- Note: this procedure makes entries in the check suppress data
3578 -- structures managed by Sem. See spec of package Sem for full
3579 -- details on how we handle recording of check suppression.
3581 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
3582 C : Check_Id;
3583 E_Id : Node_Id;
3584 E : Entity_Id;
3586 In_Package_Spec : constant Boolean :=
3587 (Ekind (Current_Scope) = E_Package
3588 or else
3589 Ekind (Current_Scope) = E_Generic_Package)
3590 and then not In_Package_Body (Current_Scope);
3592 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
3593 -- Used to suppress a single check on the given entity
3595 --------------------------------
3596 -- Suppress_Unsuppress_Echeck --
3597 --------------------------------
3599 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
3600 ESR : constant Entity_Check_Suppress_Record :=
3601 (Entity => E,
3602 Check => C,
3603 Suppress => Suppress_Case);
3605 begin
3606 Set_Checks_May_Be_Suppressed (E);
3608 if In_Package_Spec then
3609 Global_Entity_Suppress.Append (ESR);
3610 else
3611 Local_Entity_Suppress.Append (ESR);
3612 end if;
3614 -- If this is a first subtype, and the base type is distinct,
3615 -- then also set the suppress flags on the base type.
3617 if Is_First_Subtype (E)
3618 and then Etype (E) /= E
3619 then
3620 Suppress_Unsuppress_Echeck (Etype (E), C);
3621 end if;
3622 end Suppress_Unsuppress_Echeck;
3624 -- Start of processing for Process_Suppress_Unsuppress
3626 begin
3627 -- Suppress/Unsuppress can appear as a configuration pragma,
3628 -- or in a declarative part or a package spec (RM 11.5(5))
3630 if not Is_Configuration_Pragma then
3631 Check_Is_In_Decl_Part_Or_Package_Spec;
3632 end if;
3634 Check_At_Least_N_Arguments (1);
3635 Check_At_Most_N_Arguments (2);
3636 Check_No_Identifier (Arg1);
3637 Check_Arg_Is_Identifier (Arg1);
3639 if not Is_Check_Name (Chars (Expression (Arg1))) then
3640 Error_Pragma_Arg
3641 ("argument of pragma% is not valid check name", Arg1);
3642 else
3643 C := Get_Check_Id (Chars (Expression (Arg1)));
3644 end if;
3646 if Arg_Count = 1 then
3648 -- Make an entry in the local scope suppress table. This is the
3649 -- table that directly shows the current value of the scope
3650 -- suppress check for any check id value.
3652 if C = All_Checks then
3653 for J in Scope_Suppress'Range loop
3654 Scope_Suppress (J) := Suppress_Case;
3655 end loop;
3656 else
3657 Scope_Suppress (C) := Suppress_Case;
3658 end if;
3660 -- Also make an entry in the Local_Entity_Suppress table. See
3661 -- extended description in the package spec of Sem for details.
3663 Local_Entity_Suppress.Append
3664 ((Entity => Empty,
3665 Check => C,
3666 Suppress => Suppress_Case));
3668 -- Case of two arguments present, where the check is
3669 -- suppressed for a specified entity (given as the second
3670 -- argument of the pragma)
3672 else
3673 Check_Optional_Identifier (Arg2, Name_On);
3674 E_Id := Expression (Arg2);
3675 Analyze (E_Id);
3677 if not Is_Entity_Name (E_Id) then
3678 Error_Pragma_Arg
3679 ("second argument of pragma% must be entity name", Arg2);
3680 end if;
3682 E := Entity (E_Id);
3684 if E = Any_Id then
3685 return;
3686 end if;
3688 -- Enforce RM 11.5(7) which requires that for a pragma that
3689 -- appears within a package spec, the named entity must be
3690 -- within the package spec. We allow the package name itself
3691 -- to be mentioned since that makes sense, although it is not
3692 -- strictly allowed by 11.5(7).
3694 if In_Package_Spec
3695 and then E /= Current_Scope
3696 and then Scope (E) /= Current_Scope
3697 then
3698 Error_Pragma_Arg
3699 ("entity in pragma% is not in package spec ('R'M 11.5(7))",
3700 Arg2);
3701 end if;
3703 -- Loop through homonyms. As noted below, in the case of a package
3704 -- spec, only homonyms within the package spec are considered.
3706 loop
3707 Suppress_Unsuppress_Echeck (E, C);
3709 if Is_Generic_Instance (E)
3710 and then Is_Subprogram (E)
3711 and then Present (Alias (E))
3712 then
3713 Suppress_Unsuppress_Echeck (Alias (E), C);
3714 end if;
3716 -- Move to next homonym
3718 E := Homonym (E);
3719 exit when No (E);
3721 -- If we are within a package specification, the
3722 -- pragma only applies to homonyms in the same scope.
3724 exit when In_Package_Spec
3725 and then Scope (E) /= Current_Scope;
3726 end loop;
3727 end if;
3728 end Process_Suppress_Unsuppress;
3730 ------------------
3731 -- Set_Exported --
3732 ------------------
3734 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
3735 begin
3736 if Is_Imported (E) then
3737 Error_Pragma_Arg
3738 ("cannot export entity& that was previously imported", Arg);
3740 elsif Present (Address_Clause (E)) then
3741 Error_Pragma_Arg
3742 ("cannot export entity& that has an address clause", Arg);
3743 end if;
3745 Set_Is_Exported (E);
3747 -- Generate a reference for entity explicitly, because the
3748 -- identifier may be overloaded and name resolution will not
3749 -- generate one.
3751 Generate_Reference (E, Arg);
3753 -- Deal with exporting non-library level entity
3755 if not Is_Library_Level_Entity (E) then
3757 -- Not allowed at all for subprograms
3759 if Is_Subprogram (E) then
3760 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
3762 -- Otherwise set public and statically allocated
3764 else
3765 Set_Is_Public (E);
3766 Set_Is_Statically_Allocated (E);
3768 -- Warn if the corresponding W flag is set and the pragma
3769 -- comes from source. The latter may not be true e.g. on
3770 -- VMS where we expand export pragmas for exception codes
3771 -- associated with imported or exported exceptions. We do
3772 -- not want to generate a warning for something that the
3773 -- user did not write.
3775 if Warn_On_Export_Import
3776 and then Comes_From_Source (Arg)
3777 then
3778 Error_Msg_NE
3779 ("?& has been made static as a result of Export", Arg, E);
3780 Error_Msg_N
3781 ("\this usage is non-standard and non-portable", Arg);
3782 end if;
3783 end if;
3784 end if;
3786 if Warn_On_Export_Import and then Is_Type (E) then
3787 Error_Msg_NE
3788 ("exporting a type has no effect?", Arg, E);
3789 end if;
3791 if Warn_On_Export_Import and Inside_A_Generic then
3792 Error_Msg_NE
3793 ("all instances of& will have the same external name?", Arg, E);
3794 end if;
3795 end Set_Exported;
3797 ----------------------------------------------
3798 -- Set_Extended_Import_Export_External_Name --
3799 ----------------------------------------------
3801 procedure Set_Extended_Import_Export_External_Name
3802 (Internal_Ent : Entity_Id;
3803 Arg_External : Node_Id)
3805 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
3806 New_Name : Node_Id;
3808 begin
3809 if No (Arg_External) then
3810 return;
3811 end if;
3813 Check_Arg_Is_External_Name (Arg_External);
3815 if Nkind (Arg_External) = N_String_Literal then
3816 if String_Length (Strval (Arg_External)) = 0 then
3817 return;
3818 else
3819 New_Name := Adjust_External_Name_Case (Arg_External);
3820 end if;
3822 elsif Nkind (Arg_External) = N_Identifier then
3823 New_Name := Get_Default_External_Name (Arg_External);
3825 -- Check_Arg_Is_External_Name should let through only
3826 -- identifiers and string literals or static string
3827 -- expressions (which are folded to string literals).
3829 else
3830 raise Program_Error;
3831 end if;
3833 -- If we already have an external name set (by a prior normal
3834 -- Import or Export pragma), then the external names must match
3836 if Present (Interface_Name (Internal_Ent)) then
3837 declare
3838 S1 : constant String_Id := Strval (Old_Name);
3839 S2 : constant String_Id := Strval (New_Name);
3841 procedure Mismatch;
3842 -- Called if names do not match
3844 procedure Mismatch is
3845 begin
3846 Error_Msg_Sloc := Sloc (Old_Name);
3847 Error_Pragma_Arg
3848 ("external name does not match that given #",
3849 Arg_External);
3850 end Mismatch;
3852 begin
3853 if String_Length (S1) /= String_Length (S2) then
3854 Mismatch;
3856 else
3857 for J in 1 .. String_Length (S1) loop
3858 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
3859 Mismatch;
3860 end if;
3861 end loop;
3862 end if;
3863 end;
3865 -- Otherwise set the given name
3867 else
3868 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
3869 Check_Duplicated_Export_Name (New_Name);
3870 end if;
3871 end Set_Extended_Import_Export_External_Name;
3873 ------------------
3874 -- Set_Imported --
3875 ------------------
3877 procedure Set_Imported (E : Entity_Id) is
3878 begin
3879 Error_Msg_Sloc := Sloc (E);
3881 if Is_Exported (E) or else Is_Imported (E) then
3882 Error_Msg_NE ("import of& declared# not allowed", N, E);
3884 if Is_Exported (E) then
3885 Error_Msg_N ("\entity was previously exported", N);
3886 else
3887 Error_Msg_N ("\entity was previously imported", N);
3888 end if;
3890 Error_Pragma ("\(pragma% applies to all previous entities)");
3892 else
3893 Set_Is_Imported (E);
3895 -- If the entity is an object that is not at the library
3896 -- level, then it is statically allocated. We do not worry
3897 -- about objects with address clauses in this context since
3898 -- they are not really imported in the linker sense.
3900 if Is_Object (E)
3901 and then not Is_Library_Level_Entity (E)
3902 and then No (Address_Clause (E))
3903 then
3904 Set_Is_Statically_Allocated (E);
3905 end if;
3906 end if;
3907 end Set_Imported;
3909 -------------------------
3910 -- Set_Mechanism_Value --
3911 -------------------------
3913 -- Note: the mechanism name has not been analyzed (and cannot indeed
3914 -- be analyzed, since it is semantic nonsense), so we get it in the
3915 -- exact form created by the parser.
3917 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
3918 Class : Node_Id;
3919 Param : Node_Id;
3921 procedure Bad_Class;
3922 -- Signal bad descriptor class name
3924 procedure Bad_Mechanism;
3925 -- Signal bad mechanism name
3927 procedure Bad_Class is
3928 begin
3929 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
3930 end Bad_Class;
3932 procedure Bad_Mechanism is
3933 begin
3934 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
3935 end Bad_Mechanism;
3937 -- Start of processing for Set_Mechanism_Value
3939 begin
3940 if Mechanism (Ent) /= Default_Mechanism then
3941 Error_Msg_NE
3942 ("mechanism for & has already been set", Mech_Name, Ent);
3943 end if;
3945 -- MECHANISM_NAME ::= value | reference | descriptor
3947 if Nkind (Mech_Name) = N_Identifier then
3948 if Chars (Mech_Name) = Name_Value then
3949 Set_Mechanism (Ent, By_Copy);
3950 return;
3952 elsif Chars (Mech_Name) = Name_Reference then
3953 Set_Mechanism (Ent, By_Reference);
3954 return;
3956 elsif Chars (Mech_Name) = Name_Descriptor then
3957 Check_VMS (Mech_Name);
3958 Set_Mechanism (Ent, By_Descriptor);
3959 return;
3961 elsif Chars (Mech_Name) = Name_Copy then
3962 Error_Pragma_Arg
3963 ("bad mechanism name, Value assumed", Mech_Name);
3965 else
3966 Bad_Mechanism;
3967 end if;
3969 -- MECHANISM_NAME ::= descriptor (CLASS_NAME)
3970 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
3972 -- Note: this form is parsed as an indexed component
3974 elsif Nkind (Mech_Name) = N_Indexed_Component then
3975 Class := First (Expressions (Mech_Name));
3977 if Nkind (Prefix (Mech_Name)) /= N_Identifier
3978 or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
3979 or else Present (Next (Class))
3980 then
3981 Bad_Mechanism;
3982 end if;
3984 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
3985 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
3987 -- Note: this form is parsed as a function call
3989 elsif Nkind (Mech_Name) = N_Function_Call then
3991 Param := First (Parameter_Associations (Mech_Name));
3993 if Nkind (Name (Mech_Name)) /= N_Identifier
3994 or else Chars (Name (Mech_Name)) /= Name_Descriptor
3995 or else Present (Next (Param))
3996 or else No (Selector_Name (Param))
3997 or else Chars (Selector_Name (Param)) /= Name_Class
3998 then
3999 Bad_Mechanism;
4000 else
4001 Class := Explicit_Actual_Parameter (Param);
4002 end if;
4004 else
4005 Bad_Mechanism;
4006 end if;
4008 -- Fall through here with Class set to descriptor class name
4010 Check_VMS (Mech_Name);
4012 if Nkind (Class) /= N_Identifier then
4013 Bad_Class;
4015 elsif Chars (Class) = Name_UBS then
4016 Set_Mechanism (Ent, By_Descriptor_UBS);
4018 elsif Chars (Class) = Name_UBSB then
4019 Set_Mechanism (Ent, By_Descriptor_UBSB);
4021 elsif Chars (Class) = Name_UBA then
4022 Set_Mechanism (Ent, By_Descriptor_UBA);
4024 elsif Chars (Class) = Name_S then
4025 Set_Mechanism (Ent, By_Descriptor_S);
4027 elsif Chars (Class) = Name_SB then
4028 Set_Mechanism (Ent, By_Descriptor_SB);
4030 elsif Chars (Class) = Name_A then
4031 Set_Mechanism (Ent, By_Descriptor_A);
4033 elsif Chars (Class) = Name_NCA then
4034 Set_Mechanism (Ent, By_Descriptor_NCA);
4036 else
4037 Bad_Class;
4038 end if;
4040 end Set_Mechanism_Value;
4042 ---------------------------
4043 -- Set_Ravenscar_Profile --
4044 ---------------------------
4046 -- The tasks to be done here are
4048 -- Set required policies
4050 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4051 -- pragma Locking_Policy (Ceiling_Locking)
4053 -- Set Detect_Blocking mode
4055 -- Set required restrictions (see System.Rident for detailed list)
4057 procedure Set_Ravenscar_Profile (N : Node_Id) is
4058 begin
4059 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4061 if Task_Dispatching_Policy /= ' '
4062 and then Task_Dispatching_Policy /= 'F'
4063 then
4064 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4065 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4067 -- Set the FIFO_Within_Priorities policy, but always
4068 -- preserve System_Location since we like the error
4069 -- message with the run time name.
4071 else
4072 Task_Dispatching_Policy := 'F';
4074 if Task_Dispatching_Policy_Sloc /= System_Location then
4075 Task_Dispatching_Policy_Sloc := Loc;
4076 end if;
4077 end if;
4079 -- pragma Locking_Policy (Ceiling_Locking)
4081 if Locking_Policy /= ' '
4082 and then Locking_Policy /= 'C'
4083 then
4084 Error_Msg_Sloc := Locking_Policy_Sloc;
4085 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4087 -- Set the Ceiling_Locking policy, but always preserve
4088 -- System_Location since we like the error message with the
4089 -- run time name.
4091 else
4092 Locking_Policy := 'C';
4094 if Locking_Policy_Sloc /= System_Location then
4095 Locking_Policy_Sloc := Loc;
4096 end if;
4097 end if;
4099 -- pragma Detect_Blocking
4101 Detect_Blocking := True;
4103 -- Set the corresponding restrictions
4105 Set_Profile_Restrictions (Ravenscar, N, Warn => False);
4106 end Set_Ravenscar_Profile;
4108 -- Start of processing for Analyze_Pragma
4110 begin
4111 if not Is_Pragma_Name (Chars (N)) then
4112 if Warn_On_Unrecognized_Pragma then
4113 Error_Pragma ("unrecognized pragma%!?");
4114 else
4115 raise Pragma_Exit;
4116 end if;
4117 else
4118 Prag_Id := Get_Pragma_Id (Chars (N));
4119 end if;
4121 -- Preset arguments
4123 Arg1 := Empty;
4124 Arg2 := Empty;
4125 Arg3 := Empty;
4126 Arg4 := Empty;
4128 if Present (Pragma_Argument_Associations (N)) then
4129 Arg1 := First (Pragma_Argument_Associations (N));
4131 if Present (Arg1) then
4132 Arg2 := Next (Arg1);
4134 if Present (Arg2) then
4135 Arg3 := Next (Arg2);
4137 if Present (Arg3) then
4138 Arg4 := Next (Arg3);
4139 end if;
4140 end if;
4141 end if;
4142 end if;
4144 -- Count number of arguments
4146 declare
4147 Arg_Node : Node_Id;
4148 begin
4149 Arg_Count := 0;
4150 Arg_Node := Arg1;
4151 while Present (Arg_Node) loop
4152 Arg_Count := Arg_Count + 1;
4153 Next (Arg_Node);
4154 end loop;
4155 end;
4157 -- An enumeration type defines the pragmas that are supported by the
4158 -- implementation. Get_Pragma_Id (in package Prag) transorms a name
4159 -- into the corresponding enumeration value for the following case.
4161 case Prag_Id is
4163 -----------------
4164 -- Abort_Defer --
4165 -----------------
4167 -- pragma Abort_Defer;
4169 when Pragma_Abort_Defer =>
4170 GNAT_Pragma;
4171 Check_Arg_Count (0);
4173 -- The only required semantic processing is to check the
4174 -- placement. This pragma must appear at the start of the
4175 -- statement sequence of a handled sequence of statements.
4177 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
4178 or else N /= First (Statements (Parent (N)))
4179 then
4180 Pragma_Misplaced;
4181 end if;
4183 ------------
4184 -- Ada_83 --
4185 ------------
4187 -- pragma Ada_83;
4189 -- Note: this pragma also has some specific processing in Par.Prag
4190 -- because we want to set the Ada version mode during parsing.
4192 when Pragma_Ada_83 =>
4193 GNAT_Pragma;
4194 Ada_Version := Ada_83;
4195 Check_Arg_Count (0);
4197 ------------
4198 -- Ada_95 --
4199 ------------
4201 -- pragma Ada_95;
4203 -- Note: this pragma also has some specific processing in Par.Prag
4204 -- because we want to set the Ada 83 version mode during parsing.
4206 when Pragma_Ada_95 =>
4207 GNAT_Pragma;
4208 Ada_Version := Ada_95;
4209 Check_Arg_Count (0);
4211 ------------
4212 -- Ada_05 --
4213 ------------
4215 -- pragma Ada_05;
4217 -- Note: this pragma also has some specific processing in Par.Prag
4218 -- because we want to set the Ada 83 version mode during parsing.
4220 when Pragma_Ada_05 =>
4221 GNAT_Pragma;
4222 Ada_Version := Ada_05;
4223 Check_Arg_Count (0);
4225 ----------------------
4226 -- All_Calls_Remote --
4227 ----------------------
4229 -- pragma All_Calls_Remote [(library_package_NAME)];
4231 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
4232 Lib_Entity : Entity_Id;
4234 begin
4235 Check_Ada_83_Warning;
4236 Check_Valid_Library_Unit_Pragma;
4238 if Nkind (N) = N_Null_Statement then
4239 return;
4240 end if;
4242 Lib_Entity := Find_Lib_Unit_Name;
4244 -- This pragma should only apply to a RCI unit (RM E.2.3(23)).
4246 if Present (Lib_Entity)
4247 and then not Debug_Flag_U
4248 then
4249 if not Is_Remote_Call_Interface (Lib_Entity) then
4250 Error_Pragma ("pragma% only apply to rci unit");
4252 -- Set flag for entity of the library unit
4254 else
4255 Set_Has_All_Calls_Remote (Lib_Entity);
4256 end if;
4258 end if;
4259 end All_Calls_Remote;
4261 --------------
4262 -- Annotate --
4263 --------------
4265 -- pragma Annotate (IDENTIFIER {, ARG});
4266 -- ARG ::= NAME | EXPRESSION
4268 when Pragma_Annotate => Annotate : begin
4269 GNAT_Pragma;
4270 Check_At_Least_N_Arguments (1);
4271 Check_Arg_Is_Identifier (Arg1);
4273 declare
4274 Arg : Node_Id := Arg2;
4275 Exp : Node_Id;
4277 begin
4278 while Present (Arg) loop
4279 Exp := Expression (Arg);
4280 Analyze (Exp);
4282 if Is_Entity_Name (Exp) then
4283 null;
4285 elsif Nkind (Exp) = N_String_Literal then
4286 Resolve (Exp, Standard_String);
4288 elsif Is_Overloaded (Exp) then
4289 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
4291 else
4292 Resolve (Exp);
4293 end if;
4295 Next (Arg);
4296 end loop;
4297 end;
4298 end Annotate;
4300 ------------
4301 -- Assert --
4302 ------------
4304 -- pragma Assert (Boolean_EXPRESSION [, static_string_EXPRESSION]);
4306 when Pragma_Assert =>
4307 GNAT_Pragma;
4308 Check_No_Identifiers;
4310 if Arg_Count > 1 then
4311 Check_Arg_Count (2);
4312 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4313 end if;
4315 -- If expansion is active and assertions are inactive, then
4316 -- we rewrite the Assertion as:
4318 -- if False and then condition then
4319 -- null;
4320 -- end if;
4322 -- The reason we do this rewriting during semantic analysis
4323 -- rather than as part of normal expansion is that we cannot
4324 -- analyze and expand the code for the boolean expression
4325 -- directly, or it may cause insertion of actions that would
4326 -- escape the attempt to suppress the assertion code.
4328 if Expander_Active and not Assertions_Enabled then
4329 Rewrite (N,
4330 Make_If_Statement (Loc,
4331 Condition =>
4332 Make_And_Then (Loc,
4333 Left_Opnd => New_Occurrence_Of (Standard_False, Loc),
4334 Right_Opnd => Get_Pragma_Arg (Arg1)),
4335 Then_Statements => New_List (
4336 Make_Null_Statement (Loc))));
4338 Analyze (N);
4340 -- Otherwise (if assertions are enabled, or if we are not
4341 -- operating with expansion active), then we just analyze
4342 -- and resolve the expression.
4344 else
4345 Analyze_And_Resolve (Expression (Arg1), Any_Boolean);
4346 end if;
4348 ---------------
4349 -- AST_Entry --
4350 ---------------
4352 -- pragma AST_Entry (entry_IDENTIFIER);
4354 when Pragma_AST_Entry => AST_Entry : declare
4355 Ent : Node_Id;
4357 begin
4358 GNAT_Pragma;
4359 Check_VMS (N);
4360 Check_Arg_Count (1);
4361 Check_No_Identifiers;
4362 Check_Arg_Is_Local_Name (Arg1);
4363 Ent := Entity (Expression (Arg1));
4365 -- Note: the implementation of the AST_Entry pragma could handle
4366 -- the entry family case fine, but for now we are consistent with
4367 -- the DEC rules, and do not allow the pragma, which of course
4368 -- has the effect of also forbidding the attribute.
4370 if Ekind (Ent) /= E_Entry then
4371 Error_Pragma_Arg
4372 ("pragma% argument must be simple entry name", Arg1);
4374 elsif Is_AST_Entry (Ent) then
4375 Error_Pragma_Arg
4376 ("duplicate % pragma for entry", Arg1);
4378 elsif Has_Homonym (Ent) then
4379 Error_Pragma_Arg
4380 ("pragma% argument cannot specify overloaded entry", Arg1);
4382 else
4383 declare
4384 FF : constant Entity_Id := First_Formal (Ent);
4386 begin
4387 if Present (FF) then
4388 if Present (Next_Formal (FF)) then
4389 Error_Pragma_Arg
4390 ("entry for pragma% can have only one argument",
4391 Arg1);
4393 elsif Parameter_Mode (FF) /= E_In_Parameter then
4394 Error_Pragma_Arg
4395 ("entry parameter for pragma% must have mode IN",
4396 Arg1);
4397 end if;
4398 end if;
4399 end;
4401 Set_Is_AST_Entry (Ent);
4402 end if;
4403 end AST_Entry;
4405 ------------------
4406 -- Asynchronous --
4407 ------------------
4409 -- pragma Asynchronous (LOCAL_NAME);
4411 when Pragma_Asynchronous => Asynchronous : declare
4412 Nm : Entity_Id;
4413 C_Ent : Entity_Id;
4414 L : List_Id;
4415 S : Node_Id;
4416 N : Node_Id;
4417 Formal : Entity_Id;
4419 procedure Process_Async_Pragma;
4420 -- Common processing for procedure and access-to-procedure case
4422 --------------------------
4423 -- Process_Async_Pragma --
4424 --------------------------
4426 procedure Process_Async_Pragma is
4427 begin
4428 if not Present (L) then
4429 Set_Is_Asynchronous (Nm);
4430 return;
4431 end if;
4433 -- The formals should be of mode IN (RM E.4.1(6))
4435 S := First (L);
4436 while Present (S) loop
4437 Formal := Defining_Identifier (S);
4439 if Nkind (Formal) = N_Defining_Identifier
4440 and then Ekind (Formal) /= E_In_Parameter
4441 then
4442 Error_Pragma_Arg
4443 ("pragma% procedure can only have IN parameter",
4444 Arg1);
4445 end if;
4447 Next (S);
4448 end loop;
4450 Set_Is_Asynchronous (Nm);
4451 end Process_Async_Pragma;
4453 -- Start of processing for pragma Asynchronous
4455 begin
4456 Check_Ada_83_Warning;
4457 Check_No_Identifiers;
4458 Check_Arg_Count (1);
4459 Check_Arg_Is_Local_Name (Arg1);
4461 if Debug_Flag_U then
4462 return;
4463 end if;
4465 C_Ent := Cunit_Entity (Current_Sem_Unit);
4466 Analyze (Expression (Arg1));
4467 Nm := Entity (Expression (Arg1));
4469 if not Is_Remote_Call_Interface (C_Ent)
4470 and then not Is_Remote_Types (C_Ent)
4471 then
4472 -- This pragma should only appear in an RCI or Remote Types
4473 -- unit (RM E.4.1(4))
4475 Error_Pragma
4476 ("pragma% not in Remote_Call_Interface or " &
4477 "Remote_Types unit");
4478 end if;
4480 if Ekind (Nm) = E_Procedure
4481 and then Nkind (Parent (Nm)) = N_Procedure_Specification
4482 then
4483 if not Is_Remote_Call_Interface (Nm) then
4484 Error_Pragma_Arg
4485 ("pragma% cannot be applied on non-remote procedure",
4486 Arg1);
4487 end if;
4489 L := Parameter_Specifications (Parent (Nm));
4490 Process_Async_Pragma;
4491 return;
4493 elsif Ekind (Nm) = E_Function then
4494 Error_Pragma_Arg
4495 ("pragma% cannot be applied to function", Arg1);
4497 elsif Ekind (Nm) = E_Record_Type
4498 and then Present (Corresponding_Remote_Type (Nm))
4499 then
4500 -- A record type that is the Equivalent_Type for
4501 -- a remote access-to-subprogram type.
4503 N := Declaration_Node (Corresponding_Remote_Type (Nm));
4505 if Nkind (N) = N_Full_Type_Declaration
4506 and then Nkind (Type_Definition (N)) =
4507 N_Access_Procedure_Definition
4508 then
4509 L := Parameter_Specifications (Type_Definition (N));
4510 Process_Async_Pragma;
4512 if Is_Asynchronous (Nm)
4513 and then Expander_Active
4514 then
4515 RACW_Type_Is_Asynchronous (
4516 Underlying_RACW_Type (Nm));
4517 end if;
4519 else
4520 Error_Pragma_Arg
4521 ("pragma% cannot reference access-to-function type",
4522 Arg1);
4523 end if;
4525 -- Only other possibility is Access-to-class-wide type
4527 elsif Is_Access_Type (Nm)
4528 and then Is_Class_Wide_Type (Designated_Type (Nm))
4529 then
4530 Check_First_Subtype (Arg1);
4531 Set_Is_Asynchronous (Nm);
4532 if Expander_Active then
4533 RACW_Type_Is_Asynchronous (Nm);
4534 end if;
4536 else
4537 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
4538 end if;
4539 end Asynchronous;
4541 ------------
4542 -- Atomic --
4543 ------------
4545 -- pragma Atomic (LOCAL_NAME);
4547 when Pragma_Atomic =>
4548 Process_Atomic_Shared_Volatile;
4550 -----------------------
4551 -- Atomic_Components --
4552 -----------------------
4554 -- pragma Atomic_Components (array_LOCAL_NAME);
4556 -- This processing is shared by Volatile_Components
4558 when Pragma_Atomic_Components |
4559 Pragma_Volatile_Components =>
4561 Atomic_Components : declare
4562 E_Id : Node_Id;
4563 E : Entity_Id;
4564 D : Node_Id;
4565 K : Node_Kind;
4567 begin
4568 Check_Ada_83_Warning;
4569 Check_No_Identifiers;
4570 Check_Arg_Count (1);
4571 Check_Arg_Is_Local_Name (Arg1);
4572 E_Id := Expression (Arg1);
4574 if Etype (E_Id) = Any_Type then
4575 return;
4576 end if;
4578 E := Entity (E_Id);
4580 if Rep_Item_Too_Early (E, N)
4581 or else
4582 Rep_Item_Too_Late (E, N)
4583 then
4584 return;
4585 end if;
4587 D := Declaration_Node (E);
4588 K := Nkind (D);
4590 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
4591 or else
4592 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
4593 and then Nkind (D) = N_Object_Declaration
4594 and then Nkind (Object_Definition (D)) =
4595 N_Constrained_Array_Definition)
4596 then
4597 -- The flag is set on the object, or on the base type
4599 if Nkind (D) /= N_Object_Declaration then
4600 E := Base_Type (E);
4601 end if;
4603 Set_Has_Volatile_Components (E);
4605 if Prag_Id = Pragma_Atomic_Components then
4606 Set_Has_Atomic_Components (E);
4608 if Is_Packed (E) then
4609 Set_Is_Packed (E, False);
4611 Error_Pragma_Arg
4612 ("?Pack canceled, cannot pack atomic components",
4613 Arg1);
4614 end if;
4615 end if;
4617 else
4618 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
4619 end if;
4620 end Atomic_Components;
4622 --------------------
4623 -- Attach_Handler --
4624 --------------------
4626 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
4628 when Pragma_Attach_Handler =>
4629 Check_Ada_83_Warning;
4630 Check_No_Identifiers;
4631 Check_Arg_Count (2);
4633 if No_Run_Time_Mode then
4634 Error_Msg_CRT ("Attach_Handler pragma", N);
4635 else
4636 Check_Interrupt_Or_Attach_Handler;
4638 -- The expression that designates the attribute may
4639 -- depend on a discriminant, and is therefore a per-
4640 -- object expression, to be expanded in the init proc.
4641 -- If expansion is enabled, perform semantic checks
4642 -- on a copy only.
4644 if Expander_Active then
4645 declare
4646 Temp : constant Node_Id :=
4647 New_Copy_Tree (Expression (Arg2));
4648 begin
4649 Set_Parent (Temp, N);
4650 Pre_Analyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
4651 end;
4653 else
4654 Analyze (Expression (Arg2));
4655 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
4656 end if;
4658 Process_Interrupt_Or_Attach_Handler;
4659 end if;
4661 --------------------
4662 -- C_Pass_By_Copy --
4663 --------------------
4665 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
4667 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
4668 Arg : Node_Id;
4669 Val : Uint;
4671 begin
4672 GNAT_Pragma;
4673 Check_Valid_Configuration_Pragma;
4674 Check_Arg_Count (1);
4675 Check_Optional_Identifier (Arg1, "max_size");
4677 Arg := Expression (Arg1);
4678 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
4680 Val := Expr_Value (Arg);
4682 if Val <= 0 then
4683 Error_Pragma_Arg
4684 ("maximum size for pragma% must be positive", Arg1);
4686 elsif UI_Is_In_Int_Range (Val) then
4687 Default_C_Record_Mechanism := UI_To_Int (Val);
4689 -- If a giant value is given, Int'Last will do well enough.
4690 -- If sometime someone complains that a record larger than
4691 -- two gigabytes is not copied, we will worry about it then!
4693 else
4694 Default_C_Record_Mechanism := Mechanism_Type'Last;
4695 end if;
4696 end C_Pass_By_Copy;
4698 -------------
4699 -- Comment --
4700 -------------
4702 -- pragma Comment (static_string_EXPRESSION)
4704 -- Processing for pragma Comment shares the circuitry for
4705 -- pragma Ident. The only differences are that Ident enforces
4706 -- a limit of 31 characters on its argument, and also enforces
4707 -- limitations on placement for DEC compatibility. Pragma
4708 -- Comment shares neither of these restrictions.
4710 -------------------
4711 -- Common_Object --
4712 -------------------
4714 -- pragma Common_Object (
4715 -- [Internal =>] LOCAL_NAME,
4716 -- [, [External =>] EXTERNAL_SYMBOL]
4717 -- [, [Size =>] EXTERNAL_SYMBOL]);
4719 -- Processing for this pragma is shared with Psect_Object
4721 --------------------------
4722 -- Compile_Time_Warning --
4723 --------------------------
4725 -- pragma Compile_Time_Warning
4726 -- (boolean_EXPRESSION, static_string_EXPRESSION);
4728 when Pragma_Compile_Time_Warning => Compile_Time_Warning : declare
4729 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
4731 begin
4732 GNAT_Pragma;
4733 Check_Arg_Count (2);
4734 Check_No_Identifiers;
4735 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4736 Analyze_And_Resolve (Arg1x, Standard_Boolean);
4738 if Compile_Time_Known_Value (Arg1x) then
4739 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
4740 String_To_Name_Buffer (Strval (Get_Pragma_Arg (Arg2)));
4741 Add_Char_To_Name_Buffer ('?');
4743 declare
4744 Msg : String (1 .. Name_Len) :=
4745 Name_Buffer (1 .. Name_Len);
4747 B : Natural;
4749 begin
4750 -- This loop looks for multiple lines separated by
4751 -- ASCII.LF and breaks them into continuation error
4752 -- messages marked with the usual back slash.
4754 B := 1;
4755 for S in 2 .. Msg'Length - 1 loop
4756 if Msg (S) = ASCII.LF then
4757 Msg (S) := '?';
4758 Error_Msg_N (Msg (B .. S), Arg1);
4759 B := S;
4760 Msg (B) := '\';
4761 end if;
4762 end loop;
4764 Error_Msg_N (Msg (B .. Msg'Length), Arg1);
4765 end;
4766 end if;
4767 end if;
4768 end Compile_Time_Warning;
4770 ----------------------------
4771 -- Complex_Representation --
4772 ----------------------------
4774 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
4776 when Pragma_Complex_Representation => Complex_Representation : declare
4777 E_Id : Entity_Id;
4778 E : Entity_Id;
4779 Ent : Entity_Id;
4781 begin
4782 GNAT_Pragma;
4783 Check_Arg_Count (1);
4784 Check_Optional_Identifier (Arg1, Name_Entity);
4785 Check_Arg_Is_Local_Name (Arg1);
4786 E_Id := Expression (Arg1);
4788 if Etype (E_Id) = Any_Type then
4789 return;
4790 end if;
4792 E := Entity (E_Id);
4794 if not Is_Record_Type (E) then
4795 Error_Pragma_Arg
4796 ("argument for pragma% must be record type", Arg1);
4797 end if;
4799 Ent := First_Entity (E);
4801 if No (Ent)
4802 or else No (Next_Entity (Ent))
4803 or else Present (Next_Entity (Next_Entity (Ent)))
4804 or else not Is_Floating_Point_Type (Etype (Ent))
4805 or else Etype (Ent) /= Etype (Next_Entity (Ent))
4806 then
4807 Error_Pragma_Arg
4808 ("record for pragma% must have two fields of same fpt type",
4809 Arg1);
4811 else
4812 Set_Has_Complex_Representation (Base_Type (E));
4813 end if;
4814 end Complex_Representation;
4816 -------------------------
4817 -- Component_Alignment --
4818 -------------------------
4820 -- pragma Component_Alignment (
4821 -- [Form =>] ALIGNMENT_CHOICE
4822 -- [, [Name =>] type_LOCAL_NAME]);
4824 -- ALIGNMENT_CHOICE ::=
4825 -- Component_Size
4826 -- | Component_Size_4
4827 -- | Storage_Unit
4828 -- | Default
4830 when Pragma_Component_Alignment => Component_AlignmentP : declare
4831 Args : Args_List (1 .. 2);
4832 Names : constant Name_List (1 .. 2) := (
4833 Name_Form,
4834 Name_Name);
4836 Form : Node_Id renames Args (1);
4837 Name : Node_Id renames Args (2);
4839 Atype : Component_Alignment_Kind;
4840 Typ : Entity_Id;
4842 begin
4843 GNAT_Pragma;
4844 Gather_Associations (Names, Args);
4846 if No (Form) then
4847 Error_Pragma ("missing Form argument for pragma%");
4848 end if;
4850 Check_Arg_Is_Identifier (Form);
4852 -- Get proper alignment, note that Default = Component_Size
4853 -- on all machines we have so far, and we want to set this
4854 -- value rather than the default value to indicate that it
4855 -- has been explicitly set (and thus will not get overridden
4856 -- by the default component alignment for the current scope)
4858 if Chars (Form) = Name_Component_Size then
4859 Atype := Calign_Component_Size;
4861 elsif Chars (Form) = Name_Component_Size_4 then
4862 Atype := Calign_Component_Size_4;
4864 elsif Chars (Form) = Name_Default then
4865 Atype := Calign_Component_Size;
4867 elsif Chars (Form) = Name_Storage_Unit then
4868 Atype := Calign_Storage_Unit;
4870 else
4871 Error_Pragma_Arg
4872 ("invalid Form parameter for pragma%", Form);
4873 end if;
4875 -- Case with no name, supplied, affects scope table entry
4877 if No (Name) then
4878 Scope_Stack.Table
4879 (Scope_Stack.Last).Component_Alignment_Default := Atype;
4881 -- Case of name supplied
4883 else
4884 Check_Arg_Is_Local_Name (Name);
4885 Find_Type (Name);
4886 Typ := Entity (Name);
4888 if Typ = Any_Type
4889 or else Rep_Item_Too_Early (Typ, N)
4890 then
4891 return;
4892 else
4893 Typ := Underlying_Type (Typ);
4894 end if;
4896 if not Is_Record_Type (Typ)
4897 and then not Is_Array_Type (Typ)
4898 then
4899 Error_Pragma_Arg
4900 ("Name parameter of pragma% must identify record or " &
4901 "array type", Name);
4902 end if;
4904 -- An explicit Component_Alignment pragma overrides an
4905 -- implicit pragma Pack, but not an explicit one.
4907 if not Has_Pragma_Pack (Base_Type (Typ)) then
4908 Set_Is_Packed (Base_Type (Typ), False);
4909 Set_Component_Alignment (Base_Type (Typ), Atype);
4910 end if;
4911 end if;
4912 end Component_AlignmentP;
4914 ----------------
4915 -- Controlled --
4916 ----------------
4918 -- pragma Controlled (first_subtype_LOCAL_NAME);
4920 when Pragma_Controlled => Controlled : declare
4921 Arg : Node_Id;
4923 begin
4924 Check_No_Identifiers;
4925 Check_Arg_Count (1);
4926 Check_Arg_Is_Local_Name (Arg1);
4927 Arg := Expression (Arg1);
4929 if not Is_Entity_Name (Arg)
4930 or else not Is_Access_Type (Entity (Arg))
4931 then
4932 Error_Pragma_Arg ("pragma% requires access type", Arg1);
4933 else
4934 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
4935 end if;
4936 end Controlled;
4938 ----------------
4939 -- Convention --
4940 ----------------
4942 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
4943 -- [Entity =>] LOCAL_NAME);
4945 when Pragma_Convention => Convention : declare
4946 C : Convention_Id;
4947 E : Entity_Id;
4948 begin
4949 Check_Ada_83_Warning;
4950 Check_Arg_Count (2);
4951 Process_Convention (C, E);
4952 end Convention;
4954 ---------------------------
4955 -- Convention_Identifier --
4956 ---------------------------
4958 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
4959 -- [Convention =>] convention_IDENTIFIER);
4961 when Pragma_Convention_Identifier => Convention_Identifier : declare
4962 Idnam : Name_Id;
4963 Cname : Name_Id;
4965 begin
4966 GNAT_Pragma;
4967 Check_Arg_Count (2);
4968 Check_Optional_Identifier (Arg1, Name_Name);
4969 Check_Optional_Identifier (Arg2, Name_Convention);
4970 Check_Arg_Is_Identifier (Arg1);
4971 Check_Arg_Is_Identifier (Arg1);
4972 Idnam := Chars (Expression (Arg1));
4973 Cname := Chars (Expression (Arg2));
4975 if Is_Convention_Name (Cname) then
4976 Record_Convention_Identifier
4977 (Idnam, Get_Convention_Id (Cname));
4978 else
4979 Error_Pragma_Arg
4980 ("second arg for % pragma must be convention", Arg2);
4981 end if;
4982 end Convention_Identifier;
4984 ---------------
4985 -- CPP_Class --
4986 ---------------
4988 -- pragma CPP_Class ([Entity =>] local_NAME)
4990 when Pragma_CPP_Class => CPP_Class : declare
4991 Arg : Node_Id;
4992 Typ : Entity_Id;
4993 Default_DTC : Entity_Id := Empty;
4994 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
4995 C : Entity_Id;
4996 Tag_C : Entity_Id;
4998 begin
4999 GNAT_Pragma;
5000 Check_Arg_Count (1);
5001 Check_Optional_Identifier (Arg1, Name_Entity);
5002 Check_Arg_Is_Local_Name (Arg1);
5004 Arg := Expression (Arg1);
5005 Analyze (Arg);
5007 if Etype (Arg) = Any_Type then
5008 return;
5009 end if;
5011 if not Is_Entity_Name (Arg)
5012 or else not Is_Type (Entity (Arg))
5013 then
5014 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
5015 end if;
5017 Typ := Entity (Arg);
5019 if not Is_Record_Type (Typ) then
5020 Error_Pragma_Arg ("pragma% applicable to a record, "
5021 & "tagged record or record extension", Arg1);
5022 end if;
5024 Default_DTC := First_Component (Typ);
5025 while Present (Default_DTC)
5026 and then Etype (Default_DTC) /= VTP_Type
5027 loop
5028 Next_Component (Default_DTC);
5029 end loop;
5031 -- Case of non tagged type
5033 if not Is_Tagged_Type (Typ) then
5034 Set_Is_CPP_Class (Typ);
5036 if Present (Default_DTC) then
5037 Error_Pragma_Arg
5038 ("only tagged records can contain vtable pointers", Arg1);
5039 end if;
5041 -- Case of tagged type with no vtable ptr
5043 -- What is test for Typ = Root_Typ (Typ) about here ???
5045 elsif Is_Tagged_Type (Typ)
5046 and then Typ = Root_Type (Typ)
5047 and then No (Default_DTC)
5048 then
5049 Error_Pragma_Arg
5050 ("a cpp_class must contain a vtable pointer", Arg1);
5052 -- Tagged type that has a vtable ptr
5054 elsif Present (Default_DTC) then
5055 Set_Is_CPP_Class (Typ);
5056 Set_Is_Limited_Record (Typ);
5057 Set_Is_Tag (Default_DTC);
5058 Set_DT_Entry_Count (Default_DTC, No_Uint);
5060 -- Since a CPP type has no direct link to its associated tag
5061 -- most tags checks cannot be performed
5063 Set_Kill_Tag_Checks (Typ);
5064 Set_Kill_Tag_Checks (Class_Wide_Type (Typ));
5066 -- Get rid of the _tag component when there was one.
5067 -- It is only useful for regular tagged types
5069 if Expander_Active and then Typ = Root_Type (Typ) then
5071 Tag_C := Tag_Component (Typ);
5072 C := First_Entity (Typ);
5074 if C = Tag_C then
5075 Set_First_Entity (Typ, Next_Entity (Tag_C));
5077 else
5078 while Next_Entity (C) /= Tag_C loop
5079 Next_Entity (C);
5080 end loop;
5082 Set_Next_Entity (C, Next_Entity (Tag_C));
5083 end if;
5084 end if;
5085 end if;
5086 end CPP_Class;
5088 ---------------------
5089 -- CPP_Constructor --
5090 ---------------------
5092 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME);
5094 when Pragma_CPP_Constructor => CPP_Constructor : declare
5095 Id : Entity_Id;
5096 Def_Id : Entity_Id;
5098 begin
5099 GNAT_Pragma;
5100 Check_Arg_Count (1);
5101 Check_Optional_Identifier (Arg1, Name_Entity);
5102 Check_Arg_Is_Local_Name (Arg1);
5104 Id := Expression (Arg1);
5105 Find_Program_Unit_Name (Id);
5107 -- If we did not find the name, we are done
5109 if Etype (Id) = Any_Type then
5110 return;
5111 end if;
5113 Def_Id := Entity (Id);
5115 if Ekind (Def_Id) = E_Function
5116 and then Is_Class_Wide_Type (Etype (Def_Id))
5117 and then Is_CPP_Class (Etype (Etype (Def_Id)))
5118 then
5119 -- What the heck is this??? this pragma allows only 1 arg
5121 if Arg_Count >= 2 then
5122 Check_At_Most_N_Arguments (3);
5123 Process_Interface_Name (Def_Id, Arg2, Arg3);
5124 end if;
5126 if No (Parameter_Specifications (Parent (Def_Id))) then
5127 Set_Has_Completion (Def_Id);
5128 Set_Is_Constructor (Def_Id);
5129 else
5130 Error_Pragma_Arg
5131 ("non-default constructors not implemented", Arg1);
5132 end if;
5134 else
5135 Error_Pragma_Arg
5136 ("pragma% requires function returning a 'C'P'P_Class type",
5137 Arg1);
5138 end if;
5139 end CPP_Constructor;
5141 -----------------
5142 -- CPP_Virtual --
5143 -----------------
5145 -- pragma CPP_Virtual
5146 -- [Entity =>] LOCAL_NAME
5147 -- [ [Vtable_Ptr =>] LOCAL_NAME,
5148 -- [Position =>] static_integer_EXPRESSION]);
5150 when Pragma_CPP_Virtual => CPP_Virtual : declare
5151 Arg : Node_Id;
5152 Typ : Entity_Id;
5153 Subp : Entity_Id;
5154 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5155 DTC : Entity_Id;
5156 V : Uint;
5158 begin
5159 GNAT_Pragma;
5161 if Arg_Count = 3 then
5162 Check_Optional_Identifier (Arg2, "vtable_ptr");
5164 -- We allow Entry_Count as well as Position for the third
5165 -- parameter for back compatibility with versions of GNAT
5166 -- before version 3.12. The documentation has always said
5167 -- Position, but the code up to 3.12 said Entry_Count.
5169 if Chars (Arg3) /= Name_Position then
5170 Check_Optional_Identifier (Arg3, "entry_count");
5171 end if;
5173 else
5174 Check_Arg_Count (1);
5175 end if;
5177 Check_Optional_Identifier (Arg1, Name_Entity);
5178 Check_Arg_Is_Local_Name (Arg1);
5180 -- First argument must be a subprogram name
5182 Arg := Expression (Arg1);
5183 Find_Program_Unit_Name (Arg);
5185 if Etype (Arg) = Any_Type then
5186 return;
5187 else
5188 Subp := Entity (Arg);
5189 end if;
5191 if not (Is_Subprogram (Subp)
5192 and then Is_Dispatching_Operation (Subp))
5193 then
5194 Error_Pragma_Arg
5195 ("pragma% must reference a primitive operation", Arg1);
5196 end if;
5198 Typ := Find_Dispatching_Type (Subp);
5200 -- If only one Argument defaults are :
5201 -- . DTC_Entity is the default Vtable pointer
5202 -- . DT_Position will be set at the freezing point
5204 if Arg_Count = 1 then
5205 Set_DTC_Entity (Subp, Tag_Component (Typ));
5206 return;
5207 end if;
5209 -- Second argument is a component name of type Vtable_Ptr
5211 Arg := Expression (Arg2);
5213 if Nkind (Arg) /= N_Identifier then
5214 Error_Msg_NE ("must be a& component name", Arg, Typ);
5215 raise Pragma_Exit;
5216 end if;
5218 DTC := First_Component (Typ);
5219 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5220 Next_Component (DTC);
5221 end loop;
5223 if No (DTC) then
5224 Error_Msg_NE ("must be a& component name", Arg, Typ);
5225 raise Pragma_Exit;
5227 elsif Etype (DTC) /= VTP_Type then
5228 Wrong_Type (Arg, VTP_Type);
5229 return;
5230 end if;
5232 -- Third argument is an integer (DT_Position)
5234 Arg := Expression (Arg3);
5235 Analyze_And_Resolve (Arg, Any_Integer);
5237 if not Is_Static_Expression (Arg) then
5238 Flag_Non_Static_Expr
5239 ("third argument of pragma CPP_Virtual must be static!",
5240 Arg3);
5241 raise Pragma_Exit;
5243 else
5244 V := Expr_Value (Expression (Arg3));
5246 if V <= 0 then
5247 Error_Pragma_Arg
5248 ("third argument of pragma% must be positive",
5249 Arg3);
5251 else
5252 Set_DTC_Entity (Subp, DTC);
5253 Set_DT_Position (Subp, V);
5254 end if;
5255 end if;
5256 end CPP_Virtual;
5258 ----------------
5259 -- CPP_Vtable --
5260 ----------------
5262 -- pragma CPP_Vtable (
5263 -- [Entity =>] LOCAL_NAME
5264 -- [Vtable_Ptr =>] LOCAL_NAME,
5265 -- [Entry_Count =>] static_integer_EXPRESSION);
5267 when Pragma_CPP_Vtable => CPP_Vtable : declare
5268 Arg : Node_Id;
5269 Typ : Entity_Id;
5270 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5271 DTC : Entity_Id;
5272 V : Uint;
5273 Elmt : Elmt_Id;
5275 begin
5276 GNAT_Pragma;
5277 Check_Arg_Count (3);
5278 Check_Optional_Identifier (Arg1, Name_Entity);
5279 Check_Optional_Identifier (Arg2, "vtable_ptr");
5280 Check_Optional_Identifier (Arg3, "entry_count");
5281 Check_Arg_Is_Local_Name (Arg1);
5283 -- First argument is a record type name
5285 Arg := Expression (Arg1);
5286 Analyze (Arg);
5288 if Etype (Arg) = Any_Type then
5289 return;
5290 else
5291 Typ := Entity (Arg);
5292 end if;
5294 if not (Is_Tagged_Type (Typ) and then Is_CPP_Class (Typ)) then
5295 Error_Pragma_Arg ("'C'P'P_Class tagged type expected", Arg1);
5296 end if;
5298 -- Second argument is a component name of type Vtable_Ptr
5300 Arg := Expression (Arg2);
5302 if Nkind (Arg) /= N_Identifier then
5303 Error_Msg_NE ("must be a& component name", Arg, Typ);
5304 raise Pragma_Exit;
5305 end if;
5307 DTC := First_Component (Typ);
5308 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5309 Next_Component (DTC);
5310 end loop;
5312 if No (DTC) then
5313 Error_Msg_NE ("must be a& component name", Arg, Typ);
5314 raise Pragma_Exit;
5316 elsif Etype (DTC) /= VTP_Type then
5317 Wrong_Type (DTC, VTP_Type);
5318 return;
5320 -- If it is the first pragma Vtable, This becomes the default tag
5322 elsif (not Is_Tag (DTC))
5323 and then DT_Entry_Count (Tag_Component (Typ)) = No_Uint
5324 then
5325 Set_Is_Tag (Tag_Component (Typ), False);
5326 Set_Is_Tag (DTC, True);
5327 Set_DT_Entry_Count (DTC, No_Uint);
5328 end if;
5330 -- Those pragmas must appear before any primitive operation
5331 -- definition (except inherited ones) otherwise the default
5332 -- may be wrong
5334 Elmt := First_Elmt (Primitive_Operations (Typ));
5335 while Present (Elmt) loop
5336 if No (Alias (Node (Elmt))) then
5337 Error_Msg_Sloc := Sloc (Node (Elmt));
5338 Error_Pragma
5339 ("pragma% must appear before this primitive operation");
5340 end if;
5342 Next_Elmt (Elmt);
5343 end loop;
5345 -- Third argument is an integer (DT_Entry_Count)
5347 Arg := Expression (Arg3);
5348 Analyze_And_Resolve (Arg, Any_Integer);
5350 if not Is_Static_Expression (Arg) then
5351 Flag_Non_Static_Expr
5352 ("entry count for pragma CPP_Vtable must be a static " &
5353 "expression!", Arg3);
5354 raise Pragma_Exit;
5356 else
5357 V := Expr_Value (Expression (Arg3));
5359 if V <= 0 then
5360 Error_Pragma_Arg
5361 ("entry count for pragma% must be positive", Arg3);
5362 else
5363 Set_DT_Entry_Count (DTC, V);
5364 end if;
5365 end if;
5366 end CPP_Vtable;
5368 -----------
5369 -- Debug --
5370 -----------
5372 -- pragma Debug (PROCEDURE_CALL_STATEMENT);
5374 when Pragma_Debug => Debug : begin
5375 GNAT_Pragma;
5377 -- Rewrite into a conditional with a static condition
5379 Rewrite (N, Make_Implicit_If_Statement (N,
5380 Condition => New_Occurrence_Of (Boolean_Literals (
5381 Assertions_Enabled and Expander_Active), Loc),
5382 Then_Statements => New_List (
5383 Relocate_Node (Debug_Statement (N)))));
5384 Analyze (N);
5385 end Debug;
5387 ---------------------
5388 -- Detect_Blocking --
5389 ---------------------
5391 -- pragma Detect_Blocking;
5393 when Pragma_Detect_Blocking =>
5394 GNAT_Pragma;
5395 Check_Arg_Count (0);
5396 Check_Valid_Configuration_Pragma;
5397 Detect_Blocking := True;
5399 -------------------
5400 -- Discard_Names --
5401 -------------------
5403 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
5405 when Pragma_Discard_Names => Discard_Names : declare
5406 E_Id : Entity_Id;
5407 E : Entity_Id;
5409 begin
5410 Check_Ada_83_Warning;
5412 -- Deal with configuration pragma case
5414 if Arg_Count = 0 and then Is_Configuration_Pragma then
5415 Global_Discard_Names := True;
5416 return;
5418 -- Otherwise, check correct appropriate context
5420 else
5421 Check_Is_In_Decl_Part_Or_Package_Spec;
5423 if Arg_Count = 0 then
5425 -- If there is no parameter, then from now on this pragma
5426 -- applies to any enumeration, exception or tagged type
5427 -- defined in the current declarative part.
5429 Set_Discard_Names (Current_Scope);
5430 return;
5432 else
5433 Check_Arg_Count (1);
5434 Check_Optional_Identifier (Arg1, Name_On);
5435 Check_Arg_Is_Local_Name (Arg1);
5436 E_Id := Expression (Arg1);
5438 if Etype (E_Id) = Any_Type then
5439 return;
5440 else
5441 E := Entity (E_Id);
5442 end if;
5444 if (Is_First_Subtype (E)
5445 and then (Is_Enumeration_Type (E)
5446 or else Is_Tagged_Type (E)))
5447 or else Ekind (E) = E_Exception
5448 then
5449 Set_Discard_Names (E);
5450 else
5451 Error_Pragma_Arg
5452 ("inappropriate entity for pragma%", Arg1);
5453 end if;
5454 end if;
5455 end if;
5456 end Discard_Names;
5458 ---------------
5459 -- Elaborate --
5460 ---------------
5462 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
5464 when Pragma_Elaborate => Elaborate : declare
5465 Plist : List_Id;
5466 Parent_Node : Node_Id;
5467 Arg : Node_Id;
5468 Citem : Node_Id;
5470 begin
5471 -- Pragma must be in context items list of a compilation unit
5473 if not Is_List_Member (N) then
5474 Pragma_Misplaced;
5475 return;
5477 else
5478 Plist := List_Containing (N);
5479 Parent_Node := Parent (Plist);
5481 if Parent_Node = Empty
5482 or else Nkind (Parent_Node) /= N_Compilation_Unit
5483 or else Context_Items (Parent_Node) /= Plist
5484 then
5485 Pragma_Misplaced;
5486 return;
5487 end if;
5488 end if;
5490 -- Must be at least one argument
5492 if Arg_Count = 0 then
5493 Error_Pragma ("pragma% requires at least one argument");
5494 end if;
5496 -- In Ada 83 mode, there can be no items following it in the
5497 -- context list except other pragmas and implicit with clauses
5498 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
5499 -- placement rule does not apply.
5501 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5502 Citem := Next (N);
5504 while Present (Citem) loop
5505 if Nkind (Citem) = N_Pragma
5506 or else (Nkind (Citem) = N_With_Clause
5507 and then Implicit_With (Citem))
5508 then
5509 null;
5510 else
5511 Error_Pragma
5512 ("(Ada 83) pragma% must be at end of context clause");
5513 end if;
5515 Next (Citem);
5516 end loop;
5517 end if;
5519 -- Finally, the arguments must all be units mentioned in a with
5520 -- clause in the same context clause. Note we already checked
5521 -- (in Par.Prag) that the arguments are either identifiers or
5523 Arg := Arg1;
5524 Outer : while Present (Arg) loop
5525 Citem := First (Plist);
5527 Inner : while Citem /= N loop
5528 if Nkind (Citem) = N_With_Clause
5529 and then Same_Name (Name (Citem), Expression (Arg))
5530 then
5531 Set_Elaborate_Present (Citem, True);
5532 Set_Unit_Name (Expression (Arg), Name (Citem));
5533 Set_Suppress_Elaboration_Warnings (Entity (Name (Citem)));
5534 exit Inner;
5535 end if;
5537 Next (Citem);
5538 end loop Inner;
5540 if Citem = N then
5541 Error_Pragma_Arg
5542 ("argument of pragma% is not with'ed unit", Arg);
5543 end if;
5545 Next (Arg);
5546 end loop Outer;
5548 -- Give a warning if operating in static mode with -gnatwl
5549 -- (elaboration warnings eanbled) switch set.
5551 if Elab_Warnings and not Dynamic_Elaboration_Checks then
5552 Error_Msg_N
5553 ("?use of pragma Elaborate may not be safe", N);
5554 Error_Msg_N
5555 ("?use pragma Elaborate_All instead if possible", N);
5556 end if;
5557 end Elaborate;
5559 -------------------
5560 -- Elaborate_All --
5561 -------------------
5563 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
5565 when Pragma_Elaborate_All => Elaborate_All : declare
5566 Plist : List_Id;
5567 Parent_Node : Node_Id;
5568 Arg : Node_Id;
5569 Citem : Node_Id;
5571 begin
5572 Check_Ada_83_Warning;
5574 -- Pragma must be in context items list of a compilation unit
5576 if not Is_List_Member (N) then
5577 Pragma_Misplaced;
5578 return;
5580 else
5581 Plist := List_Containing (N);
5582 Parent_Node := Parent (Plist);
5584 if Parent_Node = Empty
5585 or else Nkind (Parent_Node) /= N_Compilation_Unit
5586 or else Context_Items (Parent_Node) /= Plist
5587 then
5588 Pragma_Misplaced;
5589 return;
5590 end if;
5591 end if;
5593 -- Must be at least one argument
5595 if Arg_Count = 0 then
5596 Error_Pragma ("pragma% requires at least one argument");
5597 end if;
5599 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
5600 -- have to appear at the end of the context clause, but may
5601 -- appear mixed in with other items, even in Ada 83 mode.
5603 -- Final check: the arguments must all be units mentioned in
5604 -- a with clause in the same context clause. Note that we
5605 -- already checked (in Par.Prag) that all the arguments are
5606 -- either identifiers or selected components.
5608 Arg := Arg1;
5609 Outr : while Present (Arg) loop
5610 Citem := First (Plist);
5612 Innr : while Citem /= N loop
5613 if Nkind (Citem) = N_With_Clause
5614 and then Same_Name (Name (Citem), Expression (Arg))
5615 then
5616 Set_Elaborate_All_Present (Citem, True);
5617 Set_Unit_Name (Expression (Arg), Name (Citem));
5618 Set_Suppress_Elaboration_Warnings (Entity (Name (Citem)));
5619 exit Innr;
5620 end if;
5622 Next (Citem);
5623 end loop Innr;
5625 if Citem = N then
5626 Set_Error_Posted (N);
5627 Error_Pragma_Arg
5628 ("argument of pragma% is not with'ed unit", Arg);
5629 end if;
5631 Next (Arg);
5632 end loop Outr;
5633 end Elaborate_All;
5635 --------------------
5636 -- Elaborate_Body --
5637 --------------------
5639 -- pragma Elaborate_Body [( library_unit_NAME )];
5641 when Pragma_Elaborate_Body => Elaborate_Body : declare
5642 Cunit_Node : Node_Id;
5643 Cunit_Ent : Entity_Id;
5645 begin
5646 Check_Ada_83_Warning;
5647 Check_Valid_Library_Unit_Pragma;
5649 if Nkind (N) = N_Null_Statement then
5650 return;
5651 end if;
5653 Cunit_Node := Cunit (Current_Sem_Unit);
5654 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
5656 if Nkind (Unit (Cunit_Node)) = N_Package_Body
5657 or else
5658 Nkind (Unit (Cunit_Node)) = N_Subprogram_Body
5659 then
5660 Error_Pragma ("pragma% must refer to a spec, not a body");
5661 else
5662 Set_Body_Required (Cunit_Node, True);
5663 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
5665 -- If we are in dynamic elaboration mode, then we suppress
5666 -- elaboration warnings for the unit, since it is definitely
5667 -- fine NOT to do dynamic checks at the first level (and such
5668 -- checks will be suppressed because no elaboration boolean
5669 -- is created for Elaborate_Body packages).
5671 -- But in the static model of elaboration, Elaborate_Body is
5672 -- definitely NOT good enough to ensure elaboration safety on
5673 -- its own, since the body may WITH other units that are not
5674 -- safe from an elaboration point of view, so a client must
5675 -- still do an Elaborate_All on such units.
5677 -- Debug flag -gnatdD restores the old behavior of 3.13,
5678 -- where Elaborate_Body always suppressed elab warnings.
5680 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
5681 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
5682 end if;
5683 end if;
5684 end Elaborate_Body;
5686 ------------------------
5687 -- Elaboration_Checks --
5688 ------------------------
5690 -- pragma Elaboration_Checks (Static | Dynamic);
5692 when Pragma_Elaboration_Checks =>
5693 GNAT_Pragma;
5694 Check_Arg_Count (1);
5695 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
5696 Dynamic_Elaboration_Checks :=
5697 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
5699 ---------------
5700 -- Eliminate --
5701 ---------------
5703 -- pragma Eliminate (
5704 -- [Unit_Name =>] IDENTIFIER |
5705 -- SELECTED_COMPONENT
5706 -- [,[Entity =>] IDENTIFIER |
5707 -- SELECTED_COMPONENT |
5708 -- STRING_LITERAL]
5709 -- [,]OVERLOADING_RESOLUTION);
5711 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
5712 -- SOURCE_LOCATION
5714 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
5715 -- FUNCTION_PROFILE
5717 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
5719 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
5720 -- Result_Type => result_SUBTYPE_NAME]
5722 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
5723 -- SUBTYPE_NAME ::= STRING_LITERAL
5725 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
5726 -- SOURCE_TRACE ::= STRING_LITERAL
5728 when Pragma_Eliminate => Eliminate : declare
5729 Args : Args_List (1 .. 5);
5730 Names : constant Name_List (1 .. 5) := (
5731 Name_Unit_Name,
5732 Name_Entity,
5733 Name_Parameter_Types,
5734 Name_Result_Type,
5735 Name_Source_Location);
5737 Unit_Name : Node_Id renames Args (1);
5738 Entity : Node_Id renames Args (2);
5739 Parameter_Types : Node_Id renames Args (3);
5740 Result_Type : Node_Id renames Args (4);
5741 Source_Location : Node_Id renames Args (5);
5743 begin
5744 GNAT_Pragma;
5745 Check_Valid_Configuration_Pragma;
5746 Gather_Associations (Names, Args);
5748 if No (Unit_Name) then
5749 Error_Pragma ("missing Unit_Name argument for pragma%");
5750 end if;
5752 if No (Entity)
5753 and then (Present (Parameter_Types)
5754 or else
5755 Present (Result_Type)
5756 or else
5757 Present (Source_Location))
5758 then
5759 Error_Pragma ("missing Entity argument for pragma%");
5760 end if;
5762 if (Present (Parameter_Types)
5763 or else
5764 Present (Result_Type))
5765 and then
5766 Present (Source_Location)
5767 then
5768 Error_Pragma
5769 ("parameter profile and source location can not " &
5770 "be used together in pragma%");
5771 end if;
5773 Process_Eliminate_Pragma
5775 Unit_Name,
5776 Entity,
5777 Parameter_Types,
5778 Result_Type,
5779 Source_Location);
5780 end Eliminate;
5782 -------------------------
5783 -- Explicit_Overriding --
5784 -------------------------
5786 when Pragma_Explicit_Overriding =>
5787 Check_Valid_Configuration_Pragma;
5788 Check_Arg_Count (0);
5789 Explicit_Overriding := True;
5791 ------------
5792 -- Export --
5793 ------------
5795 -- pragma Export (
5796 -- [ Convention =>] convention_IDENTIFIER,
5797 -- [ Entity =>] local_NAME
5798 -- [, [External_Name =>] static_string_EXPRESSION ]
5799 -- [, [Link_Name =>] static_string_EXPRESSION ]);
5801 when Pragma_Export => Export : declare
5802 C : Convention_Id;
5803 Def_Id : Entity_Id;
5805 begin
5806 Check_Ada_83_Warning;
5807 Check_At_Least_N_Arguments (2);
5808 Check_At_Most_N_Arguments (4);
5809 Process_Convention (C, Def_Id);
5811 if Ekind (Def_Id) /= E_Constant then
5812 Note_Possible_Modification (Expression (Arg2));
5813 end if;
5815 Process_Interface_Name (Def_Id, Arg3, Arg4);
5816 Set_Exported (Def_Id, Arg2);
5817 end Export;
5819 ----------------------
5820 -- Export_Exception --
5821 ----------------------
5823 -- pragma Export_Exception (
5824 -- [Internal =>] LOCAL_NAME,
5825 -- [, [External =>] EXTERNAL_SYMBOL,]
5826 -- [, [Form =>] Ada | VMS]
5827 -- [, [Code =>] static_integer_EXPRESSION]);
5829 when Pragma_Export_Exception => Export_Exception : declare
5830 Args : Args_List (1 .. 4);
5831 Names : constant Name_List (1 .. 4) := (
5832 Name_Internal,
5833 Name_External,
5834 Name_Form,
5835 Name_Code);
5837 Internal : Node_Id renames Args (1);
5838 External : Node_Id renames Args (2);
5839 Form : Node_Id renames Args (3);
5840 Code : Node_Id renames Args (4);
5842 begin
5843 if Inside_A_Generic then
5844 Error_Pragma ("pragma% cannot be used for generic entities");
5845 end if;
5847 Gather_Associations (Names, Args);
5848 Process_Extended_Import_Export_Exception_Pragma (
5849 Arg_Internal => Internal,
5850 Arg_External => External,
5851 Arg_Form => Form,
5852 Arg_Code => Code);
5854 if not Is_VMS_Exception (Entity (Internal)) then
5855 Set_Exported (Entity (Internal), Internal);
5856 end if;
5857 end Export_Exception;
5859 ---------------------
5860 -- Export_Function --
5861 ---------------------
5863 -- pragma Export_Function (
5864 -- [Internal =>] LOCAL_NAME,
5865 -- [, [External =>] EXTERNAL_SYMBOL,]
5866 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5867 -- [, [Result_Type =>] TYPE_DESIGNATOR]
5868 -- [, [Mechanism =>] MECHANISM]
5869 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
5871 -- EXTERNAL_SYMBOL ::=
5872 -- IDENTIFIER
5873 -- | static_string_EXPRESSION
5875 -- PARAMETER_TYPES ::=
5876 -- null
5877 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5879 -- TYPE_DESIGNATOR ::=
5880 -- subtype_NAME
5881 -- | subtype_Name ' Access
5883 -- MECHANISM ::=
5884 -- MECHANISM_NAME
5885 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5887 -- MECHANISM_ASSOCIATION ::=
5888 -- [formal_parameter_NAME =>] MECHANISM_NAME
5890 -- MECHANISM_NAME ::=
5891 -- Value
5892 -- | Reference
5893 -- | Descriptor [([Class =>] CLASS_NAME)]
5895 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5897 when Pragma_Export_Function => Export_Function : declare
5898 Args : Args_List (1 .. 6);
5899 Names : constant Name_List (1 .. 6) := (
5900 Name_Internal,
5901 Name_External,
5902 Name_Parameter_Types,
5903 Name_Result_Type,
5904 Name_Mechanism,
5905 Name_Result_Mechanism);
5907 Internal : Node_Id renames Args (1);
5908 External : Node_Id renames Args (2);
5909 Parameter_Types : Node_Id renames Args (3);
5910 Result_Type : Node_Id renames Args (4);
5911 Mechanism : Node_Id renames Args (5);
5912 Result_Mechanism : Node_Id renames Args (6);
5914 begin
5915 GNAT_Pragma;
5916 Gather_Associations (Names, Args);
5917 Process_Extended_Import_Export_Subprogram_Pragma (
5918 Arg_Internal => Internal,
5919 Arg_External => External,
5920 Arg_Parameter_Types => Parameter_Types,
5921 Arg_Result_Type => Result_Type,
5922 Arg_Mechanism => Mechanism,
5923 Arg_Result_Mechanism => Result_Mechanism);
5924 end Export_Function;
5926 -------------------
5927 -- Export_Object --
5928 -------------------
5930 -- pragma Export_Object (
5931 -- [Internal =>] LOCAL_NAME,
5932 -- [, [External =>] EXTERNAL_SYMBOL]
5933 -- [, [Size =>] EXTERNAL_SYMBOL]);
5935 -- EXTERNAL_SYMBOL ::=
5936 -- IDENTIFIER
5937 -- | static_string_EXPRESSION
5939 -- PARAMETER_TYPES ::=
5940 -- null
5941 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5943 -- TYPE_DESIGNATOR ::=
5944 -- subtype_NAME
5945 -- | subtype_Name ' Access
5947 -- MECHANISM ::=
5948 -- MECHANISM_NAME
5949 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5951 -- MECHANISM_ASSOCIATION ::=
5952 -- [formal_parameter_NAME =>] MECHANISM_NAME
5954 -- MECHANISM_NAME ::=
5955 -- Value
5956 -- | Reference
5957 -- | Descriptor [([Class =>] CLASS_NAME)]
5959 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5961 when Pragma_Export_Object => Export_Object : declare
5962 Args : Args_List (1 .. 3);
5963 Names : constant Name_List (1 .. 3) := (
5964 Name_Internal,
5965 Name_External,
5966 Name_Size);
5968 Internal : Node_Id renames Args (1);
5969 External : Node_Id renames Args (2);
5970 Size : Node_Id renames Args (3);
5972 begin
5973 GNAT_Pragma;
5974 Gather_Associations (Names, Args);
5975 Process_Extended_Import_Export_Object_Pragma (
5976 Arg_Internal => Internal,
5977 Arg_External => External,
5978 Arg_Size => Size);
5979 end Export_Object;
5981 ----------------------
5982 -- Export_Procedure --
5983 ----------------------
5985 -- pragma Export_Procedure (
5986 -- [Internal =>] LOCAL_NAME,
5987 -- [, [External =>] EXTERNAL_SYMBOL,]
5988 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5989 -- [, [Mechanism =>] MECHANISM]);
5991 -- EXTERNAL_SYMBOL ::=
5992 -- IDENTIFIER
5993 -- | static_string_EXPRESSION
5995 -- PARAMETER_TYPES ::=
5996 -- null
5997 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5999 -- TYPE_DESIGNATOR ::=
6000 -- subtype_NAME
6001 -- | subtype_Name ' Access
6003 -- MECHANISM ::=
6004 -- MECHANISM_NAME
6005 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6007 -- MECHANISM_ASSOCIATION ::=
6008 -- [formal_parameter_NAME =>] MECHANISM_NAME
6010 -- MECHANISM_NAME ::=
6011 -- Value
6012 -- | Reference
6013 -- | Descriptor [([Class =>] CLASS_NAME)]
6015 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6017 when Pragma_Export_Procedure => Export_Procedure : declare
6018 Args : Args_List (1 .. 4);
6019 Names : constant Name_List (1 .. 4) := (
6020 Name_Internal,
6021 Name_External,
6022 Name_Parameter_Types,
6023 Name_Mechanism);
6025 Internal : Node_Id renames Args (1);
6026 External : Node_Id renames Args (2);
6027 Parameter_Types : Node_Id renames Args (3);
6028 Mechanism : Node_Id renames Args (4);
6030 begin
6031 GNAT_Pragma;
6032 Gather_Associations (Names, Args);
6033 Process_Extended_Import_Export_Subprogram_Pragma (
6034 Arg_Internal => Internal,
6035 Arg_External => External,
6036 Arg_Parameter_Types => Parameter_Types,
6037 Arg_Mechanism => Mechanism);
6038 end Export_Procedure;
6040 ------------------
6041 -- Export_Value --
6042 ------------------
6044 -- pragma Export_Value (
6045 -- [Value =>] static_integer_EXPRESSION,
6046 -- [Link_Name =>] static_string_EXPRESSION);
6048 when Pragma_Export_Value =>
6049 GNAT_Pragma;
6050 Check_Arg_Count (2);
6052 Check_Optional_Identifier (Arg1, Name_Value);
6053 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
6055 Check_Optional_Identifier (Arg2, Name_Link_Name);
6056 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6058 -----------------------------
6059 -- Export_Valued_Procedure --
6060 -----------------------------
6062 -- pragma Export_Valued_Procedure (
6063 -- [Internal =>] LOCAL_NAME,
6064 -- [, [External =>] EXTERNAL_SYMBOL,]
6065 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6066 -- [, [Mechanism =>] MECHANISM]);
6068 -- EXTERNAL_SYMBOL ::=
6069 -- IDENTIFIER
6070 -- | static_string_EXPRESSION
6072 -- PARAMETER_TYPES ::=
6073 -- null
6074 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6076 -- TYPE_DESIGNATOR ::=
6077 -- subtype_NAME
6078 -- | subtype_Name ' Access
6080 -- MECHANISM ::=
6081 -- MECHANISM_NAME
6082 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6084 -- MECHANISM_ASSOCIATION ::=
6085 -- [formal_parameter_NAME =>] MECHANISM_NAME
6087 -- MECHANISM_NAME ::=
6088 -- Value
6089 -- | Reference
6090 -- | Descriptor [([Class =>] CLASS_NAME)]
6092 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6094 when Pragma_Export_Valued_Procedure =>
6095 Export_Valued_Procedure : declare
6096 Args : Args_List (1 .. 4);
6097 Names : constant Name_List (1 .. 4) := (
6098 Name_Internal,
6099 Name_External,
6100 Name_Parameter_Types,
6101 Name_Mechanism);
6103 Internal : Node_Id renames Args (1);
6104 External : Node_Id renames Args (2);
6105 Parameter_Types : Node_Id renames Args (3);
6106 Mechanism : Node_Id renames Args (4);
6108 begin
6109 GNAT_Pragma;
6110 Gather_Associations (Names, Args);
6111 Process_Extended_Import_Export_Subprogram_Pragma (
6112 Arg_Internal => Internal,
6113 Arg_External => External,
6114 Arg_Parameter_Types => Parameter_Types,
6115 Arg_Mechanism => Mechanism);
6116 end Export_Valued_Procedure;
6118 -------------------
6119 -- Extend_System --
6120 -------------------
6122 -- pragma Extend_System ([Name =>] Identifier);
6124 when Pragma_Extend_System => Extend_System : declare
6125 begin
6126 GNAT_Pragma;
6127 Check_Valid_Configuration_Pragma;
6128 Check_Arg_Count (1);
6129 Check_Optional_Identifier (Arg1, Name_Name);
6130 Check_Arg_Is_Identifier (Arg1);
6132 Get_Name_String (Chars (Expression (Arg1)));
6134 if Name_Len > 4
6135 and then Name_Buffer (1 .. 4) = "aux_"
6136 then
6137 if Present (System_Extend_Pragma_Arg) then
6138 if Chars (Expression (Arg1)) =
6139 Chars (Expression (System_Extend_Pragma_Arg))
6140 then
6141 null;
6142 else
6143 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
6144 Error_Pragma ("pragma% conflicts with that at#");
6145 end if;
6147 else
6148 System_Extend_Pragma_Arg := Arg1;
6150 if not GNAT_Mode then
6151 System_Extend_Unit := Arg1;
6152 end if;
6153 end if;
6154 else
6155 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
6156 end if;
6157 end Extend_System;
6159 ------------------------
6160 -- Extensions_Allowed --
6161 ------------------------
6163 -- pragma Extensions_Allowed (ON | OFF);
6165 when Pragma_Extensions_Allowed =>
6166 GNAT_Pragma;
6167 Check_Arg_Count (1);
6168 Check_No_Identifiers;
6169 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6171 if Chars (Expression (Arg1)) = Name_On then
6172 Extensions_Allowed := True;
6173 Ada_Version := Ada_Version_Type'Last;
6174 else
6175 Extensions_Allowed := False;
6176 Ada_Version := Ada_Version_Type'Min (Ada_Version, Ada_95);
6177 end if;
6179 --------------
6180 -- External --
6181 --------------
6183 -- pragma External (
6184 -- [ Convention =>] convention_IDENTIFIER,
6185 -- [ Entity =>] local_NAME
6186 -- [, [External_Name =>] static_string_EXPRESSION ]
6187 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6189 when Pragma_External => External : declare
6190 C : Convention_Id;
6191 Def_Id : Entity_Id;
6193 begin
6194 GNAT_Pragma;
6195 Check_At_Least_N_Arguments (2);
6196 Check_At_Most_N_Arguments (4);
6197 Process_Convention (C, Def_Id);
6198 Note_Possible_Modification (Expression (Arg2));
6199 Process_Interface_Name (Def_Id, Arg3, Arg4);
6200 Set_Exported (Def_Id, Arg2);
6201 end External;
6203 --------------------------
6204 -- External_Name_Casing --
6205 --------------------------
6207 -- pragma External_Name_Casing (
6208 -- UPPERCASE | LOWERCASE
6209 -- [, AS_IS | UPPERCASE | LOWERCASE]);
6211 when Pragma_External_Name_Casing =>
6213 External_Name_Casing : declare
6214 begin
6215 GNAT_Pragma;
6216 Check_No_Identifiers;
6218 if Arg_Count = 2 then
6219 Check_Arg_Is_One_Of
6220 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
6222 case Chars (Get_Pragma_Arg (Arg2)) is
6223 when Name_As_Is =>
6224 Opt.External_Name_Exp_Casing := As_Is;
6226 when Name_Uppercase =>
6227 Opt.External_Name_Exp_Casing := Uppercase;
6229 when Name_Lowercase =>
6230 Opt.External_Name_Exp_Casing := Lowercase;
6232 when others =>
6233 null;
6234 end case;
6236 else
6237 Check_Arg_Count (1);
6238 end if;
6240 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
6242 case Chars (Get_Pragma_Arg (Arg1)) is
6243 when Name_Uppercase =>
6244 Opt.External_Name_Imp_Casing := Uppercase;
6246 when Name_Lowercase =>
6247 Opt.External_Name_Imp_Casing := Lowercase;
6249 when others =>
6250 null;
6251 end case;
6252 end External_Name_Casing;
6254 ---------------------------
6255 -- Finalize_Storage_Only --
6256 ---------------------------
6258 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
6260 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
6261 Assoc : constant Node_Id := Arg1;
6262 Type_Id : constant Node_Id := Expression (Assoc);
6263 Typ : Entity_Id;
6265 begin
6266 Check_No_Identifiers;
6267 Check_Arg_Count (1);
6268 Check_Arg_Is_Local_Name (Arg1);
6270 Find_Type (Type_Id);
6271 Typ := Entity (Type_Id);
6273 if Typ = Any_Type
6274 or else Rep_Item_Too_Early (Typ, N)
6275 then
6276 return;
6277 else
6278 Typ := Underlying_Type (Typ);
6279 end if;
6281 if not Is_Controlled (Typ) then
6282 Error_Pragma ("pragma% must specify controlled type");
6283 end if;
6285 Check_First_Subtype (Arg1);
6287 if Finalize_Storage_Only (Typ) then
6288 Error_Pragma ("duplicate pragma%, only one allowed");
6290 elsif not Rep_Item_Too_Late (Typ, N) then
6291 Set_Finalize_Storage_Only (Base_Type (Typ), True);
6292 end if;
6293 end Finalize_Storage;
6295 --------------------------
6296 -- Float_Representation --
6297 --------------------------
6299 -- pragma Float_Representation (VAX_Float | IEEE_Float);
6301 when Pragma_Float_Representation => Float_Representation : declare
6302 Argx : Node_Id;
6303 Digs : Nat;
6304 Ent : Entity_Id;
6306 begin
6307 GNAT_Pragma;
6309 if Arg_Count = 1 then
6310 Check_Valid_Configuration_Pragma;
6311 else
6312 Check_Arg_Count (2);
6313 Check_Optional_Identifier (Arg2, Name_Entity);
6314 Check_Arg_Is_Local_Name (Arg2);
6315 end if;
6317 Check_No_Identifier (Arg1);
6318 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
6320 if not OpenVMS_On_Target then
6321 if Chars (Expression (Arg1)) = Name_VAX_Float then
6322 Error_Pragma
6323 ("?pragma% ignored (applies only to Open'V'M'S)");
6324 end if;
6326 return;
6327 end if;
6329 -- One argument case
6331 if Arg_Count = 1 then
6333 if Chars (Expression (Arg1)) = Name_VAX_Float then
6335 if Opt.Float_Format = 'I' then
6336 Error_Pragma ("'I'E'E'E format previously specified");
6337 end if;
6339 Opt.Float_Format := 'V';
6341 else
6342 if Opt.Float_Format = 'V' then
6343 Error_Pragma ("'V'A'X format previously specified");
6344 end if;
6346 Opt.Float_Format := 'I';
6347 end if;
6349 Set_Standard_Fpt_Formats;
6351 -- Two argument case
6353 else
6354 Argx := Get_Pragma_Arg (Arg2);
6356 if not Is_Entity_Name (Argx)
6357 or else not Is_Floating_Point_Type (Entity (Argx))
6358 then
6359 Error_Pragma_Arg
6360 ("second argument of% pragma must be floating-point type",
6361 Arg2);
6362 end if;
6364 Ent := Entity (Argx);
6365 Digs := UI_To_Int (Digits_Value (Ent));
6367 -- Two arguments, VAX_Float case
6369 if Chars (Expression (Arg1)) = Name_VAX_Float then
6371 case Digs is
6372 when 6 => Set_F_Float (Ent);
6373 when 9 => Set_D_Float (Ent);
6374 when 15 => Set_G_Float (Ent);
6376 when others =>
6377 Error_Pragma_Arg
6378 ("wrong digits value, must be 6,9 or 15", Arg2);
6379 end case;
6381 -- Two arguments, IEEE_Float case
6383 else
6384 case Digs is
6385 when 6 => Set_IEEE_Short (Ent);
6386 when 15 => Set_IEEE_Long (Ent);
6388 when others =>
6389 Error_Pragma_Arg
6390 ("wrong digits value, must be 6 or 15", Arg2);
6391 end case;
6392 end if;
6393 end if;
6394 end Float_Representation;
6396 -----------
6397 -- Ident --
6398 -----------
6400 -- pragma Ident (static_string_EXPRESSION)
6402 -- Note: pragma Comment shares this processing. Pragma Comment
6403 -- is identical to Ident, except that the restriction of the
6404 -- argument to 31 characters and the placement restrictions
6405 -- are not enforced for pragma Comment.
6407 when Pragma_Ident | Pragma_Comment => Ident : declare
6408 Str : Node_Id;
6410 begin
6411 GNAT_Pragma;
6412 Check_Arg_Count (1);
6413 Check_No_Identifiers;
6414 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
6416 -- For pragma Ident, preserve DEC compatibility by requiring
6417 -- the pragma to appear in a declarative part or package spec.
6419 if Prag_Id = Pragma_Ident then
6420 Check_Is_In_Decl_Part_Or_Package_Spec;
6421 end if;
6423 Str := Expr_Value_S (Expression (Arg1));
6425 declare
6426 CS : Node_Id;
6427 GP : Node_Id;
6429 begin
6430 GP := Parent (Parent (N));
6432 if Nkind (GP) = N_Package_Declaration
6433 or else
6434 Nkind (GP) = N_Generic_Package_Declaration
6435 then
6436 GP := Parent (GP);
6437 end if;
6439 -- If we have a compilation unit, then record the ident
6440 -- value, checking for improper duplication.
6442 if Nkind (GP) = N_Compilation_Unit then
6443 CS := Ident_String (Current_Sem_Unit);
6445 if Present (CS) then
6447 -- For Ident, we do not permit multiple instances
6449 if Prag_Id = Pragma_Ident then
6450 Error_Pragma ("duplicate% pragma not permitted");
6452 -- For Comment, we concatenate the string, unless we
6453 -- want to preserve the tree structure for ASIS.
6455 elsif not ASIS_Mode then
6456 Start_String (Strval (CS));
6457 Store_String_Char (' ');
6458 Store_String_Chars (Strval (Str));
6459 Set_Strval (CS, End_String);
6460 end if;
6462 else
6463 -- In VMS, the effect of IDENT is achieved by passing
6464 -- IDENTIFICATION=name as a --for-linker switch.
6466 if OpenVMS_On_Target then
6467 Start_String;
6468 Store_String_Chars
6469 ("--for-linker=IDENTIFICATION=");
6470 String_To_Name_Buffer (Strval (Str));
6471 Store_String_Chars (Name_Buffer (1 .. Name_Len));
6473 -- Only the last processed IDENT is saved. The main
6474 -- purpose is so an IDENT associated with a main
6475 -- procedure will be used in preference to an IDENT
6476 -- associated with a with'd package.
6478 Replace_Linker_Option_String
6479 (End_String, "--for-linker=IDENTIFICATION=");
6480 end if;
6482 Set_Ident_String (Current_Sem_Unit, Str);
6483 end if;
6485 -- For subunits, we just ignore the Ident, since in GNAT
6486 -- these are not separate object files, and hence not
6487 -- separate units in the unit table.
6489 elsif Nkind (GP) = N_Subunit then
6490 null;
6492 -- Otherwise we have a misplaced pragma Ident, but we ignore
6493 -- this if we are in an instantiation, since it comes from
6494 -- a generic, and has no relevance to the instantiation.
6496 elsif Prag_Id = Pragma_Ident then
6497 if Instantiation_Location (Loc) = No_Location then
6498 Error_Pragma ("pragma% only allowed at outer level");
6499 end if;
6500 end if;
6501 end;
6502 end Ident;
6504 ------------
6505 -- Import --
6506 ------------
6508 -- pragma Import (
6509 -- [ Convention =>] convention_IDENTIFIER,
6510 -- [ Entity =>] local_NAME
6511 -- [, [External_Name =>] static_string_EXPRESSION ]
6512 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6514 when Pragma_Import =>
6515 Check_Ada_83_Warning;
6516 Check_At_Least_N_Arguments (2);
6517 Check_At_Most_N_Arguments (4);
6518 Process_Import_Or_Interface;
6520 ----------------------
6521 -- Import_Exception --
6522 ----------------------
6524 -- pragma Import_Exception (
6525 -- [Internal =>] LOCAL_NAME,
6526 -- [, [External =>] EXTERNAL_SYMBOL,]
6527 -- [, [Form =>] Ada | VMS]
6528 -- [, [Code =>] static_integer_EXPRESSION]);
6530 when Pragma_Import_Exception => Import_Exception : declare
6531 Args : Args_List (1 .. 4);
6532 Names : constant Name_List (1 .. 4) := (
6533 Name_Internal,
6534 Name_External,
6535 Name_Form,
6536 Name_Code);
6538 Internal : Node_Id renames Args (1);
6539 External : Node_Id renames Args (2);
6540 Form : Node_Id renames Args (3);
6541 Code : Node_Id renames Args (4);
6543 begin
6544 Gather_Associations (Names, Args);
6546 if Present (External) and then Present (Code) then
6547 Error_Pragma
6548 ("cannot give both External and Code options for pragma%");
6549 end if;
6551 Process_Extended_Import_Export_Exception_Pragma (
6552 Arg_Internal => Internal,
6553 Arg_External => External,
6554 Arg_Form => Form,
6555 Arg_Code => Code);
6557 if not Is_VMS_Exception (Entity (Internal)) then
6558 Set_Imported (Entity (Internal));
6559 end if;
6560 end Import_Exception;
6562 ---------------------
6563 -- Import_Function --
6564 ---------------------
6566 -- pragma Import_Function (
6567 -- [Internal =>] LOCAL_NAME,
6568 -- [, [External =>] EXTERNAL_SYMBOL]
6569 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6570 -- [, [Result_Type =>] SUBTYPE_MARK]
6571 -- [, [Mechanism =>] MECHANISM]
6572 -- [, [Result_Mechanism =>] MECHANISM_NAME]
6573 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6575 -- EXTERNAL_SYMBOL ::=
6576 -- IDENTIFIER
6577 -- | static_string_EXPRESSION
6579 -- PARAMETER_TYPES ::=
6580 -- null
6581 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6583 -- TYPE_DESIGNATOR ::=
6584 -- subtype_NAME
6585 -- | subtype_Name ' Access
6587 -- MECHANISM ::=
6588 -- MECHANISM_NAME
6589 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6591 -- MECHANISM_ASSOCIATION ::=
6592 -- [formal_parameter_NAME =>] MECHANISM_NAME
6594 -- MECHANISM_NAME ::=
6595 -- Value
6596 -- | Reference
6597 -- | Descriptor [([Class =>] CLASS_NAME)]
6599 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6601 when Pragma_Import_Function => Import_Function : declare
6602 Args : Args_List (1 .. 7);
6603 Names : constant Name_List (1 .. 7) := (
6604 Name_Internal,
6605 Name_External,
6606 Name_Parameter_Types,
6607 Name_Result_Type,
6608 Name_Mechanism,
6609 Name_Result_Mechanism,
6610 Name_First_Optional_Parameter);
6612 Internal : Node_Id renames Args (1);
6613 External : Node_Id renames Args (2);
6614 Parameter_Types : Node_Id renames Args (3);
6615 Result_Type : Node_Id renames Args (4);
6616 Mechanism : Node_Id renames Args (5);
6617 Result_Mechanism : Node_Id renames Args (6);
6618 First_Optional_Parameter : Node_Id renames Args (7);
6620 begin
6621 GNAT_Pragma;
6622 Gather_Associations (Names, Args);
6623 Process_Extended_Import_Export_Subprogram_Pragma (
6624 Arg_Internal => Internal,
6625 Arg_External => External,
6626 Arg_Parameter_Types => Parameter_Types,
6627 Arg_Result_Type => Result_Type,
6628 Arg_Mechanism => Mechanism,
6629 Arg_Result_Mechanism => Result_Mechanism,
6630 Arg_First_Optional_Parameter => First_Optional_Parameter);
6631 end Import_Function;
6633 -------------------
6634 -- Import_Object --
6635 -------------------
6637 -- pragma Import_Object (
6638 -- [Internal =>] LOCAL_NAME,
6639 -- [, [External =>] EXTERNAL_SYMBOL]
6640 -- [, [Size =>] EXTERNAL_SYMBOL]);
6642 -- EXTERNAL_SYMBOL ::=
6643 -- IDENTIFIER
6644 -- | static_string_EXPRESSION
6646 when Pragma_Import_Object => Import_Object : declare
6647 Args : Args_List (1 .. 3);
6648 Names : constant Name_List (1 .. 3) := (
6649 Name_Internal,
6650 Name_External,
6651 Name_Size);
6653 Internal : Node_Id renames Args (1);
6654 External : Node_Id renames Args (2);
6655 Size : Node_Id renames Args (3);
6657 begin
6658 GNAT_Pragma;
6659 Gather_Associations (Names, Args);
6660 Process_Extended_Import_Export_Object_Pragma (
6661 Arg_Internal => Internal,
6662 Arg_External => External,
6663 Arg_Size => Size);
6664 end Import_Object;
6666 ----------------------
6667 -- Import_Procedure --
6668 ----------------------
6670 -- pragma Import_Procedure (
6671 -- [Internal =>] LOCAL_NAME,
6672 -- [, [External =>] EXTERNAL_SYMBOL]
6673 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6674 -- [, [Mechanism =>] MECHANISM]
6675 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6677 -- EXTERNAL_SYMBOL ::=
6678 -- IDENTIFIER
6679 -- | static_string_EXPRESSION
6681 -- PARAMETER_TYPES ::=
6682 -- null
6683 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6685 -- TYPE_DESIGNATOR ::=
6686 -- subtype_NAME
6687 -- | subtype_Name ' Access
6689 -- MECHANISM ::=
6690 -- MECHANISM_NAME
6691 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6693 -- MECHANISM_ASSOCIATION ::=
6694 -- [formal_parameter_NAME =>] MECHANISM_NAME
6696 -- MECHANISM_NAME ::=
6697 -- Value
6698 -- | Reference
6699 -- | Descriptor [([Class =>] CLASS_NAME)]
6701 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6703 when Pragma_Import_Procedure => Import_Procedure : declare
6704 Args : Args_List (1 .. 5);
6705 Names : constant Name_List (1 .. 5) := (
6706 Name_Internal,
6707 Name_External,
6708 Name_Parameter_Types,
6709 Name_Mechanism,
6710 Name_First_Optional_Parameter);
6712 Internal : Node_Id renames Args (1);
6713 External : Node_Id renames Args (2);
6714 Parameter_Types : Node_Id renames Args (3);
6715 Mechanism : Node_Id renames Args (4);
6716 First_Optional_Parameter : Node_Id renames Args (5);
6718 begin
6719 GNAT_Pragma;
6720 Gather_Associations (Names, Args);
6721 Process_Extended_Import_Export_Subprogram_Pragma (
6722 Arg_Internal => Internal,
6723 Arg_External => External,
6724 Arg_Parameter_Types => Parameter_Types,
6725 Arg_Mechanism => Mechanism,
6726 Arg_First_Optional_Parameter => First_Optional_Parameter);
6727 end Import_Procedure;
6729 -----------------------------
6730 -- Import_Valued_Procedure --
6731 -----------------------------
6733 -- pragma Import_Valued_Procedure (
6734 -- [Internal =>] LOCAL_NAME,
6735 -- [, [External =>] EXTERNAL_SYMBOL]
6736 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6737 -- [, [Mechanism =>] MECHANISM]
6738 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6740 -- EXTERNAL_SYMBOL ::=
6741 -- IDENTIFIER
6742 -- | static_string_EXPRESSION
6744 -- PARAMETER_TYPES ::=
6745 -- null
6746 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6748 -- TYPE_DESIGNATOR ::=
6749 -- subtype_NAME
6750 -- | subtype_Name ' Access
6752 -- MECHANISM ::=
6753 -- MECHANISM_NAME
6754 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6756 -- MECHANISM_ASSOCIATION ::=
6757 -- [formal_parameter_NAME =>] MECHANISM_NAME
6759 -- MECHANISM_NAME ::=
6760 -- Value
6761 -- | Reference
6762 -- | Descriptor [([Class =>] CLASS_NAME)]
6764 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6766 when Pragma_Import_Valued_Procedure =>
6767 Import_Valued_Procedure : declare
6768 Args : Args_List (1 .. 5);
6769 Names : constant Name_List (1 .. 5) := (
6770 Name_Internal,
6771 Name_External,
6772 Name_Parameter_Types,
6773 Name_Mechanism,
6774 Name_First_Optional_Parameter);
6776 Internal : Node_Id renames Args (1);
6777 External : Node_Id renames Args (2);
6778 Parameter_Types : Node_Id renames Args (3);
6779 Mechanism : Node_Id renames Args (4);
6780 First_Optional_Parameter : Node_Id renames Args (5);
6782 begin
6783 GNAT_Pragma;
6784 Gather_Associations (Names, Args);
6785 Process_Extended_Import_Export_Subprogram_Pragma (
6786 Arg_Internal => Internal,
6787 Arg_External => External,
6788 Arg_Parameter_Types => Parameter_Types,
6789 Arg_Mechanism => Mechanism,
6790 Arg_First_Optional_Parameter => First_Optional_Parameter);
6791 end Import_Valued_Procedure;
6793 ------------------------
6794 -- Initialize_Scalars --
6795 ------------------------
6797 -- pragma Initialize_Scalars;
6799 when Pragma_Initialize_Scalars =>
6800 GNAT_Pragma;
6801 Check_Arg_Count (0);
6802 Check_Valid_Configuration_Pragma;
6803 Check_Restriction (No_Initialize_Scalars, N);
6805 if not Restriction_Active (No_Initialize_Scalars) then
6806 Init_Or_Norm_Scalars := True;
6807 Initialize_Scalars := True;
6808 end if;
6810 ------------
6811 -- Inline --
6812 ------------
6814 -- pragma Inline ( NAME {, NAME} );
6816 when Pragma_Inline =>
6818 -- Pragma is active if inlining option is active
6820 if Inline_Active then
6821 Process_Inline (True);
6823 -- Pragma is active in a predefined file in config run time mode
6825 elsif Configurable_Run_Time_Mode
6826 and then
6827 Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
6828 then
6829 Process_Inline (True);
6831 -- Otherwise inlining is not active
6833 else
6834 Process_Inline (False);
6835 end if;
6837 -------------------
6838 -- Inline_Always --
6839 -------------------
6841 -- pragma Inline_Always ( NAME {, NAME} );
6843 when Pragma_Inline_Always =>
6844 Process_Inline (True);
6846 --------------------
6847 -- Inline_Generic --
6848 --------------------
6850 -- pragma Inline_Generic (NAME {, NAME});
6852 when Pragma_Inline_Generic =>
6853 Process_Generic_List;
6855 ----------------------
6856 -- Inspection_Point --
6857 ----------------------
6859 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
6861 when Pragma_Inspection_Point => Inspection_Point : declare
6862 Arg : Node_Id;
6863 Exp : Node_Id;
6865 begin
6866 if Arg_Count > 0 then
6867 Arg := Arg1;
6868 loop
6869 Exp := Expression (Arg);
6870 Analyze (Exp);
6872 if not Is_Entity_Name (Exp)
6873 or else not Is_Object (Entity (Exp))
6874 then
6875 Error_Pragma_Arg ("object name required", Arg);
6876 end if;
6878 Next (Arg);
6879 exit when No (Arg);
6880 end loop;
6881 end if;
6882 end Inspection_Point;
6884 ---------------
6885 -- Interface --
6886 ---------------
6888 -- pragma Interface (
6889 -- convention_IDENTIFIER,
6890 -- local_NAME );
6892 when Pragma_Interface =>
6893 GNAT_Pragma;
6894 Check_Arg_Count (2);
6895 Check_No_Identifiers;
6896 Process_Import_Or_Interface;
6898 --------------------
6899 -- Interface_Name --
6900 --------------------
6902 -- pragma Interface_Name (
6903 -- [ Entity =>] local_NAME
6904 -- [,[External_Name =>] static_string_EXPRESSION ]
6905 -- [,[Link_Name =>] static_string_EXPRESSION ]);
6907 when Pragma_Interface_Name => Interface_Name : declare
6908 Id : Node_Id;
6909 Def_Id : Entity_Id;
6910 Hom_Id : Entity_Id;
6911 Found : Boolean;
6913 begin
6914 GNAT_Pragma;
6915 Check_At_Least_N_Arguments (2);
6916 Check_At_Most_N_Arguments (3);
6917 Id := Expression (Arg1);
6918 Analyze (Id);
6920 if not Is_Entity_Name (Id) then
6921 Error_Pragma_Arg
6922 ("first argument for pragma% must be entity name", Arg1);
6923 elsif Etype (Id) = Any_Type then
6924 return;
6925 else
6926 Def_Id := Entity (Id);
6927 end if;
6929 -- Special DEC-compatible processing for the object case,
6930 -- forces object to be imported.
6932 if Ekind (Def_Id) = E_Variable then
6933 Kill_Size_Check_Code (Def_Id);
6934 Note_Possible_Modification (Id);
6936 -- Initialization is not allowed for imported variable
6938 if Present (Expression (Parent (Def_Id)))
6939 and then Comes_From_Source (Expression (Parent (Def_Id)))
6940 then
6941 Error_Msg_Sloc := Sloc (Def_Id);
6942 Error_Pragma_Arg
6943 ("no initialization allowed for declaration of& #",
6944 Arg2);
6946 else
6947 -- For compatibility, support VADS usage of providing both
6948 -- pragmas Interface and Interface_Name to obtain the effect
6949 -- of a single Import pragma.
6951 if Is_Imported (Def_Id)
6952 and then Present (First_Rep_Item (Def_Id))
6953 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
6954 and then Chars (First_Rep_Item (Def_Id)) = Name_Interface
6955 then
6956 null;
6957 else
6958 Set_Imported (Def_Id);
6959 end if;
6961 Set_Is_Public (Def_Id);
6962 Process_Interface_Name (Def_Id, Arg2, Arg3);
6963 end if;
6965 -- Otherwise must be subprogram
6967 elsif not Is_Subprogram (Def_Id) then
6968 Error_Pragma_Arg
6969 ("argument of pragma% is not subprogram", Arg1);
6971 else
6972 Check_At_Most_N_Arguments (3);
6973 Hom_Id := Def_Id;
6974 Found := False;
6976 -- Loop through homonyms
6978 loop
6979 Def_Id := Get_Base_Subprogram (Hom_Id);
6981 if Is_Imported (Def_Id) then
6982 Process_Interface_Name (Def_Id, Arg2, Arg3);
6983 Found := True;
6984 end if;
6986 Hom_Id := Homonym (Hom_Id);
6988 exit when No (Hom_Id)
6989 or else Scope (Hom_Id) /= Current_Scope;
6990 end loop;
6992 if not Found then
6993 Error_Pragma_Arg
6994 ("argument of pragma% is not imported subprogram",
6995 Arg1);
6996 end if;
6997 end if;
6998 end Interface_Name;
7000 -----------------------
7001 -- Interrupt_Handler --
7002 -----------------------
7004 -- pragma Interrupt_Handler (handler_NAME);
7006 when Pragma_Interrupt_Handler =>
7007 Check_Ada_83_Warning;
7008 Check_Arg_Count (1);
7009 Check_No_Identifiers;
7011 if No_Run_Time_Mode then
7012 Error_Msg_CRT ("Interrupt_Handler pragma", N);
7013 else
7014 Check_Interrupt_Or_Attach_Handler;
7015 Process_Interrupt_Or_Attach_Handler;
7016 end if;
7018 ------------------------
7019 -- Interrupt_Priority --
7020 ------------------------
7022 -- pragma Interrupt_Priority [(EXPRESSION)];
7024 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
7025 P : constant Node_Id := Parent (N);
7026 Arg : Node_Id;
7028 begin
7029 Check_Ada_83_Warning;
7031 if Arg_Count /= 0 then
7032 Arg := Expression (Arg1);
7033 Check_Arg_Count (1);
7034 Check_No_Identifiers;
7036 -- The expression must be analyzed in the special manner
7037 -- described in "Handling of Default and Per-Object
7038 -- Expressions" in sem.ads.
7040 Analyze_Per_Use_Expression (Arg, RTE (RE_Interrupt_Priority));
7041 end if;
7043 if Nkind (P) /= N_Task_Definition
7044 and then Nkind (P) /= N_Protected_Definition
7045 then
7046 Pragma_Misplaced;
7047 return;
7049 elsif Has_Priority_Pragma (P) then
7050 Error_Pragma ("duplicate pragma% not allowed");
7052 else
7053 Set_Has_Priority_Pragma (P, True);
7054 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7055 end if;
7056 end Interrupt_Priority;
7058 ---------------------
7059 -- Interrupt_State --
7060 ---------------------
7062 -- pragma Interrupt_State (
7063 -- [Name =>] INTERRUPT_ID,
7064 -- [State =>] INTERRUPT_STATE);
7066 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
7067 -- INTERRUPT_STATE => System | Runtime | User
7069 -- Note: if the interrupt id is given as an identifier, then
7070 -- it must be one of the identifiers in Ada.Interrupts.Names.
7071 -- Otherwise it is given as a static integer expression which
7072 -- must be in the range of Ada.Interrupts.Interrupt_ID.
7074 when Pragma_Interrupt_State => Interrupt_State : declare
7076 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
7077 -- This is the entity Ada.Interrupts.Interrupt_ID;
7079 State_Type : Character;
7080 -- Set to 's'/'r'/'u' for System/Runtime/User
7082 IST_Num : Pos;
7083 -- Index to entry in Interrupt_States table
7085 Int_Val : Uint;
7086 -- Value of interrupt
7088 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
7089 -- The first argument to the pragma
7091 Int_Ent : Entity_Id;
7092 -- Interrupt entity in Ada.Interrupts.Names
7094 begin
7095 GNAT_Pragma;
7096 Check_Arg_Count (2);
7098 Check_Optional_Identifier (Arg1, Name_Name);
7099 Check_Optional_Identifier (Arg2, "state");
7100 Check_Arg_Is_Identifier (Arg2);
7102 -- First argument is identifier
7104 if Nkind (Arg1X) = N_Identifier then
7106 -- Search list of names in Ada.Interrupts.Names
7108 Int_Ent := First_Entity (RTE (RE_Names));
7109 loop
7110 if No (Int_Ent) then
7111 Error_Pragma_Arg ("invalid interrupt name", Arg1);
7113 elsif Chars (Int_Ent) = Chars (Arg1X) then
7114 Int_Val := Expr_Value (Constant_Value (Int_Ent));
7115 exit;
7116 end if;
7118 Next_Entity (Int_Ent);
7119 end loop;
7121 -- First argument is not an identifier, so it must be a
7122 -- static expression of type Ada.Interrupts.Interrupt_ID.
7124 else
7125 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7126 Int_Val := Expr_Value (Arg1X);
7128 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
7129 or else
7130 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
7131 then
7132 Error_Pragma_Arg
7133 ("value not in range of type " &
7134 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
7135 end if;
7136 end if;
7138 -- Check OK state
7140 case Chars (Get_Pragma_Arg (Arg2)) is
7141 when Name_Runtime => State_Type := 'r';
7142 when Name_System => State_Type := 's';
7143 when Name_User => State_Type := 'u';
7145 when others =>
7146 Error_Pragma_Arg ("invalid interrupt state", Arg2);
7147 end case;
7149 -- Check if entry is already stored
7151 IST_Num := Interrupt_States.First;
7152 loop
7153 -- If entry not found, add it
7155 if IST_Num > Interrupt_States.Last then
7156 Interrupt_States.Append
7157 ((Interrupt_Number => UI_To_Int (Int_Val),
7158 Interrupt_State => State_Type,
7159 Pragma_Loc => Loc));
7160 exit;
7162 -- Case of entry for the same entry
7164 elsif Int_Val = Interrupt_States.Table (IST_Num).
7165 Interrupt_Number
7166 then
7167 -- If state matches, done, no need to make redundant entry
7169 exit when
7170 State_Type = Interrupt_States.Table (IST_Num).
7171 Interrupt_State;
7173 -- Otherwise if state does not match, error
7175 Error_Msg_Sloc :=
7176 Interrupt_States.Table (IST_Num).Pragma_Loc;
7177 Error_Pragma_Arg
7178 ("state conflicts with that given at #", Arg2);
7179 exit;
7180 end if;
7182 IST_Num := IST_Num + 1;
7183 end loop;
7184 end Interrupt_State;
7186 ----------------------
7187 -- Java_Constructor --
7188 ----------------------
7190 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
7192 when Pragma_Java_Constructor => Java_Constructor : declare
7193 Id : Entity_Id;
7194 Def_Id : Entity_Id;
7195 Hom_Id : Entity_Id;
7197 begin
7198 GNAT_Pragma;
7199 Check_Arg_Count (1);
7200 Check_Optional_Identifier (Arg1, Name_Entity);
7201 Check_Arg_Is_Local_Name (Arg1);
7203 Id := Expression (Arg1);
7204 Find_Program_Unit_Name (Id);
7206 -- If we did not find the name, we are done
7208 if Etype (Id) = Any_Type then
7209 return;
7210 end if;
7212 Hom_Id := Entity (Id);
7214 -- Loop through homonyms
7216 loop
7217 Def_Id := Get_Base_Subprogram (Hom_Id);
7219 -- The constructor is required to be a function returning
7220 -- an access type whose designated type has convention Java.
7222 if Ekind (Def_Id) = E_Function
7223 and then Ekind (Etype (Def_Id)) in Access_Kind
7224 and then
7225 (Atree.Convention
7226 (Designated_Type (Etype (Def_Id))) = Convention_Java
7227 or else
7228 Atree.Convention
7229 (Root_Type (Designated_Type (Etype (Def_Id))))
7230 = Convention_Java)
7231 then
7232 Set_Is_Constructor (Def_Id);
7233 Set_Convention (Def_Id, Convention_Java);
7235 else
7236 Error_Pragma_Arg
7237 ("pragma% requires function returning a 'Java access type",
7238 Arg1);
7239 end if;
7241 Hom_Id := Homonym (Hom_Id);
7243 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
7244 end loop;
7245 end Java_Constructor;
7247 ----------------------
7248 -- Java_Interface --
7249 ----------------------
7251 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
7253 when Pragma_Java_Interface => Java_Interface : declare
7254 Arg : Node_Id;
7255 Typ : Entity_Id;
7257 begin
7258 GNAT_Pragma;
7259 Check_Arg_Count (1);
7260 Check_Optional_Identifier (Arg1, Name_Entity);
7261 Check_Arg_Is_Local_Name (Arg1);
7263 Arg := Expression (Arg1);
7264 Analyze (Arg);
7266 if Etype (Arg) = Any_Type then
7267 return;
7268 end if;
7270 if not Is_Entity_Name (Arg)
7271 or else not Is_Type (Entity (Arg))
7272 then
7273 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7274 end if;
7276 Typ := Underlying_Type (Entity (Arg));
7278 -- For now we simply check some of the semantic constraints
7279 -- on the type. This currently leaves out some restrictions
7280 -- on interface types, namely that the parent type must be
7281 -- java.lang.Object.Typ and that all primitives of the type
7282 -- should be declared abstract. ???
7284 if not Is_Tagged_Type (Typ) or else not Is_Abstract (Typ) then
7285 Error_Pragma_Arg ("pragma% requires an abstract "
7286 & "tagged type", Arg1);
7288 elsif not Has_Discriminants (Typ)
7289 or else Ekind (Etype (First_Discriminant (Typ)))
7290 /= E_Anonymous_Access_Type
7291 or else
7292 not Is_Class_Wide_Type
7293 (Designated_Type (Etype (First_Discriminant (Typ))))
7294 then
7295 Error_Pragma_Arg
7296 ("type must have a class-wide access discriminant", Arg1);
7297 end if;
7298 end Java_Interface;
7300 ----------------
7301 -- Keep_Names --
7302 ----------------
7304 -- pragma Keep_Names ([On => ] local_NAME);
7306 when Pragma_Keep_Names => Keep_Names : declare
7307 Arg : Node_Id;
7309 begin
7310 GNAT_Pragma;
7311 Check_Arg_Count (1);
7312 Check_Optional_Identifier (Arg1, Name_On);
7313 Check_Arg_Is_Local_Name (Arg1);
7315 Arg := Expression (Arg1);
7316 Analyze (Arg);
7318 if Etype (Arg) = Any_Type then
7319 return;
7320 end if;
7322 if not Is_Entity_Name (Arg)
7323 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
7324 then
7325 Error_Pragma_Arg
7326 ("pragma% requires a local enumeration type", Arg1);
7327 end if;
7329 Set_Discard_Names (Entity (Arg), False);
7330 end Keep_Names;
7332 -------------
7333 -- License --
7334 -------------
7336 -- pragma License (RESTRICTED | UNRESRICTED | GPL | MODIFIED_GPL);
7338 when Pragma_License =>
7339 GNAT_Pragma;
7340 Check_Arg_Count (1);
7341 Check_No_Identifiers;
7342 Check_Valid_Configuration_Pragma;
7343 Check_Arg_Is_Identifier (Arg1);
7345 declare
7346 Sind : constant Source_File_Index :=
7347 Source_Index (Current_Sem_Unit);
7349 begin
7350 case Chars (Get_Pragma_Arg (Arg1)) is
7351 when Name_GPL =>
7352 Set_License (Sind, GPL);
7354 when Name_Modified_GPL =>
7355 Set_License (Sind, Modified_GPL);
7357 when Name_Restricted =>
7358 Set_License (Sind, Restricted);
7360 when Name_Unrestricted =>
7361 Set_License (Sind, Unrestricted);
7363 when others =>
7364 Error_Pragma_Arg ("invalid license name", Arg1);
7365 end case;
7366 end;
7368 ---------------
7369 -- Link_With --
7370 ---------------
7372 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
7374 when Pragma_Link_With => Link_With : declare
7375 Arg : Node_Id;
7377 begin
7378 GNAT_Pragma;
7380 if Operating_Mode = Generate_Code
7381 and then In_Extended_Main_Source_Unit (N)
7382 then
7383 Check_At_Least_N_Arguments (1);
7384 Check_No_Identifiers;
7385 Check_Is_In_Decl_Part_Or_Package_Spec;
7386 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7387 Start_String;
7389 Arg := Arg1;
7390 while Present (Arg) loop
7391 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7393 -- Store argument, converting sequences of spaces
7394 -- to a single null character (this is one of the
7395 -- differences in processing between Link_With
7396 -- and Linker_Options).
7398 declare
7399 C : constant Char_Code := Get_Char_Code (' ');
7400 S : constant String_Id :=
7401 Strval (Expr_Value_S (Expression (Arg)));
7402 L : constant Nat := String_Length (S);
7403 F : Nat := 1;
7405 procedure Skip_Spaces;
7406 -- Advance F past any spaces
7408 procedure Skip_Spaces is
7409 begin
7410 while F <= L and then Get_String_Char (S, F) = C loop
7411 F := F + 1;
7412 end loop;
7413 end Skip_Spaces;
7415 begin
7416 Skip_Spaces; -- skip leading spaces
7418 -- Loop through characters, changing any embedded
7419 -- sequence of spaces to a single null character
7420 -- (this is how Link_With/Linker_Options differ)
7422 while F <= L loop
7423 if Get_String_Char (S, F) = C then
7424 Skip_Spaces;
7425 exit when F > L;
7426 Store_String_Char (ASCII.NUL);
7428 else
7429 Store_String_Char (Get_String_Char (S, F));
7430 F := F + 1;
7431 end if;
7432 end loop;
7433 end;
7435 Arg := Next (Arg);
7437 if Present (Arg) then
7438 Store_String_Char (ASCII.NUL);
7439 end if;
7440 end loop;
7442 Store_Linker_Option_String (End_String);
7443 end if;
7444 end Link_With;
7446 ------------------
7447 -- Linker_Alias --
7448 ------------------
7450 -- pragma Linker_Alias (
7451 -- [Entity =>] LOCAL_NAME
7452 -- [Alias =>] static_string_EXPRESSION);
7454 when Pragma_Linker_Alias =>
7455 GNAT_Pragma;
7456 Check_Arg_Count (2);
7457 Check_Optional_Identifier (Arg1, Name_Entity);
7458 Check_Optional_Identifier (Arg2, "alias");
7459 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7460 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7462 -- The only processing required is to link this item on to the
7463 -- list of rep items for the given entity. This is accomplished
7464 -- by the call to Rep_Item_Too_Late (when no error is detected
7465 -- and False is returned).
7467 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7468 return;
7469 else
7470 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7471 end if;
7473 --------------------
7474 -- Linker_Options --
7475 --------------------
7477 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
7479 when Pragma_Linker_Options => Linker_Options : declare
7480 Arg : Node_Id;
7482 begin
7483 Check_Ada_83_Warning;
7484 Check_No_Identifiers;
7485 Check_Arg_Count (1);
7486 Check_Is_In_Decl_Part_Or_Package_Spec;
7488 if Operating_Mode = Generate_Code
7489 and then In_Extended_Main_Source_Unit (N)
7490 then
7491 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7492 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
7494 Arg := Arg2;
7495 while Present (Arg) loop
7496 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7497 Store_String_Char (ASCII.NUL);
7498 Store_String_Chars
7499 (Strval (Expr_Value_S (Expression (Arg))));
7500 Arg := Next (Arg);
7501 end loop;
7503 Store_Linker_Option_String (End_String);
7504 end if;
7505 end Linker_Options;
7507 --------------------
7508 -- Linker_Section --
7509 --------------------
7511 -- pragma Linker_Section (
7512 -- [Entity =>] LOCAL_NAME
7513 -- [Section =>] static_string_EXPRESSION);
7515 when Pragma_Linker_Section =>
7516 GNAT_Pragma;
7517 Check_Arg_Count (2);
7518 Check_Optional_Identifier (Arg1, Name_Entity);
7519 Check_Optional_Identifier (Arg2, Name_Section);
7520 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7521 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7523 -- The only processing required is to link this item on to the
7524 -- list of rep items for the given entity. This is accomplished
7525 -- by the call to Rep_Item_Too_Late (when no error is detected
7526 -- and False is returned).
7528 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7529 return;
7530 else
7531 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7532 end if;
7534 ----------
7535 -- List --
7536 ----------
7538 -- pragma List (On | Off)
7540 -- There is nothing to do here, since we did all the processing
7541 -- for this pragma in Par.Prag (so that it works properly even in
7542 -- syntax only mode)
7544 when Pragma_List =>
7545 null;
7547 --------------------
7548 -- Locking_Policy --
7549 --------------------
7551 -- pragma Locking_Policy (policy_IDENTIFIER);
7553 when Pragma_Locking_Policy => declare
7554 LP : Character;
7556 begin
7557 Check_Ada_83_Warning;
7558 Check_Arg_Count (1);
7559 Check_No_Identifiers;
7560 Check_Arg_Is_Locking_Policy (Arg1);
7561 Check_Valid_Configuration_Pragma;
7562 Get_Name_String (Chars (Expression (Arg1)));
7563 LP := Fold_Upper (Name_Buffer (1));
7565 if Locking_Policy /= ' '
7566 and then Locking_Policy /= LP
7567 then
7568 Error_Msg_Sloc := Locking_Policy_Sloc;
7569 Error_Pragma ("locking policy incompatible with policy#");
7571 -- Set new policy, but always preserve System_Location since
7572 -- we like the error message with the run time name.
7574 else
7575 Locking_Policy := LP;
7577 if Locking_Policy_Sloc /= System_Location then
7578 Locking_Policy_Sloc := Loc;
7579 end if;
7580 end if;
7581 end;
7583 ----------------
7584 -- Long_Float --
7585 ----------------
7587 -- pragma Long_Float (D_Float | G_Float);
7589 when Pragma_Long_Float =>
7590 GNAT_Pragma;
7591 Check_Valid_Configuration_Pragma;
7592 Check_Arg_Count (1);
7593 Check_No_Identifier (Arg1);
7594 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
7596 if not OpenVMS_On_Target then
7597 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
7598 end if;
7600 -- D_Float case
7602 if Chars (Expression (Arg1)) = Name_D_Float then
7603 if Opt.Float_Format_Long = 'G' then
7604 Error_Pragma ("G_Float previously specified");
7605 end if;
7607 Opt.Float_Format_Long := 'D';
7609 -- G_Float case (this is the default, does not need overriding)
7611 else
7612 if Opt.Float_Format_Long = 'D' then
7613 Error_Pragma ("D_Float previously specified");
7614 end if;
7616 Opt.Float_Format_Long := 'G';
7617 end if;
7619 Set_Standard_Fpt_Formats;
7621 -----------------------
7622 -- Machine_Attribute --
7623 -----------------------
7625 -- pragma Machine_Attribute (
7626 -- [Entity =>] LOCAL_NAME,
7627 -- [Attribute_Name =>] static_string_EXPRESSION
7628 -- [,[Info =>] static_string_EXPRESSION] );
7630 when Pragma_Machine_Attribute => Machine_Attribute : declare
7631 Def_Id : Entity_Id;
7633 begin
7634 GNAT_Pragma;
7636 if Arg_Count = 3 then
7637 Check_Optional_Identifier (Arg3, "info");
7638 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
7639 else
7640 Check_Arg_Count (2);
7641 end if;
7643 Check_Arg_Is_Local_Name (Arg1);
7644 Check_Optional_Identifier (Arg2, "attribute_name");
7645 Check_Optional_Identifier (Arg1, Name_Entity);
7646 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7647 Def_Id := Entity (Expression (Arg1));
7649 if Is_Access_Type (Def_Id) then
7650 Def_Id := Designated_Type (Def_Id);
7651 end if;
7653 if Rep_Item_Too_Early (Def_Id, N) then
7654 return;
7655 end if;
7657 Def_Id := Underlying_Type (Def_Id);
7659 -- The only processing required is to link this item on to the
7660 -- list of rep items for the given entity. This is accomplished
7661 -- by the call to Rep_Item_Too_Late (when no error is detected
7662 -- and False is returned).
7664 if Rep_Item_Too_Late (Def_Id, N) then
7665 return;
7666 else
7667 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7668 end if;
7669 end Machine_Attribute;
7671 ----------
7672 -- Main --
7673 ----------
7675 -- pragma Main_Storage
7676 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7678 -- MAIN_STORAGE_OPTION ::=
7679 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7680 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7682 when Pragma_Main => Main : declare
7683 Args : Args_List (1 .. 3);
7684 Names : constant Name_List (1 .. 3) := (
7685 Name_Stack_Size,
7686 Name_Task_Stack_Size_Default,
7687 Name_Time_Slicing_Enabled);
7689 Nod : Node_Id;
7691 begin
7692 GNAT_Pragma;
7693 Gather_Associations (Names, Args);
7695 for J in 1 .. 2 loop
7696 if Present (Args (J)) then
7697 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7698 end if;
7699 end loop;
7701 if Present (Args (3)) then
7702 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
7703 end if;
7705 Nod := Next (N);
7706 while Present (Nod) loop
7707 if Nkind (Nod) = N_Pragma
7708 and then Chars (Nod) = Name_Main
7709 then
7710 Error_Msg_Name_1 := Chars (N);
7711 Error_Msg_N ("duplicate pragma% not permitted", Nod);
7712 end if;
7714 Next (Nod);
7715 end loop;
7716 end Main;
7718 ------------------
7719 -- Main_Storage --
7720 ------------------
7722 -- pragma Main_Storage
7723 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7725 -- MAIN_STORAGE_OPTION ::=
7726 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7727 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7729 when Pragma_Main_Storage => Main_Storage : declare
7730 Args : Args_List (1 .. 2);
7731 Names : constant Name_List (1 .. 2) := (
7732 Name_Working_Storage,
7733 Name_Top_Guard);
7735 Nod : Node_Id;
7737 begin
7738 GNAT_Pragma;
7739 Gather_Associations (Names, Args);
7741 for J in 1 .. 2 loop
7742 if Present (Args (J)) then
7743 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7744 end if;
7745 end loop;
7747 Check_In_Main_Program;
7749 Nod := Next (N);
7750 while Present (Nod) loop
7751 if Nkind (Nod) = N_Pragma
7752 and then Chars (Nod) = Name_Main_Storage
7753 then
7754 Error_Msg_Name_1 := Chars (N);
7755 Error_Msg_N ("duplicate pragma% not permitted", Nod);
7756 end if;
7758 Next (Nod);
7759 end loop;
7760 end Main_Storage;
7762 -----------------
7763 -- Memory_Size --
7764 -----------------
7766 -- pragma Memory_Size (NUMERIC_LITERAL)
7768 when Pragma_Memory_Size =>
7769 GNAT_Pragma;
7771 -- Memory size is simply ignored
7773 Check_No_Identifiers;
7774 Check_Arg_Count (1);
7775 Check_Arg_Is_Integer_Literal (Arg1);
7777 ---------------
7778 -- No_Return --
7779 ---------------
7781 -- pragma No_Return (procedure_LOCAL_NAME);
7783 when Pragma_No_Return => No_Return : declare
7784 Id : Node_Id;
7785 E : Entity_Id;
7786 Found : Boolean;
7788 begin
7789 GNAT_Pragma;
7790 Check_Arg_Count (1);
7791 Check_No_Identifiers;
7792 Check_Arg_Is_Local_Name (Arg1);
7793 Id := Expression (Arg1);
7794 Analyze (Id);
7796 if not Is_Entity_Name (Id) then
7797 Error_Pragma_Arg ("entity name required", Arg1);
7798 end if;
7800 if Etype (Id) = Any_Type then
7801 raise Pragma_Exit;
7802 end if;
7804 E := Entity (Id);
7806 Found := False;
7807 while Present (E)
7808 and then Scope (E) = Current_Scope
7809 loop
7810 if Ekind (E) = E_Procedure
7811 or else Ekind (E) = E_Generic_Procedure
7812 then
7813 Set_No_Return (E);
7814 Found := True;
7815 end if;
7817 E := Homonym (E);
7818 end loop;
7820 if not Found then
7821 Error_Pragma ("no procedures found for pragma%");
7822 end if;
7823 end No_Return;
7825 ------------------------
7826 -- No_Strict_Aliasing --
7827 ------------------------
7829 when Pragma_No_Strict_Aliasing => No_Strict_Alias : declare
7830 E_Id : Entity_Id;
7832 begin
7833 GNAT_Pragma;
7834 Check_At_Most_N_Arguments (1);
7836 if Arg_Count = 0 then
7837 Check_Valid_Configuration_Pragma;
7838 Opt.No_Strict_Aliasing := True;
7840 else
7841 Check_Optional_Identifier (Arg2, Name_Entity);
7842 Check_Arg_Is_Local_Name (Arg1);
7843 E_Id := Entity (Expression (Arg1));
7845 if E_Id = Any_Type then
7846 return;
7847 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
7848 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7849 end if;
7851 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
7852 end if;
7853 end No_Strict_Alias;
7855 -----------------
7856 -- Obsolescent --
7857 -----------------
7859 -- pragma Obsolescent [(static_string_EXPRESSION)];
7861 when Pragma_Obsolescent => Obsolescent : declare
7862 begin
7863 GNAT_Pragma;
7864 Check_At_Most_N_Arguments (1);
7865 Check_No_Identifiers;
7867 if Arg_Count = 1 then
7868 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7869 end if;
7871 if No (Prev (N))
7872 or else (Nkind (Prev (N))) /= N_Subprogram_Declaration
7873 then
7874 Error_Pragma
7875 ("pragma% misplaced, must immediately " &
7876 "follow subprogram spec");
7877 end if;
7878 end Obsolescent;
7880 -----------------
7881 -- No_Run_Time --
7882 -----------------
7884 -- pragma No_Run_Time
7886 -- Note: this pragma is retained for backwards compatibiltiy.
7887 -- See body of Rtsfind for full details on its handling.
7889 when Pragma_No_Run_Time =>
7890 GNAT_Pragma;
7891 Check_Valid_Configuration_Pragma;
7892 Check_Arg_Count (0);
7894 No_Run_Time_Mode := True;
7895 Configurable_Run_Time_Mode := True;
7897 declare
7898 Word32 : constant Boolean := Ttypes.System_Word_Size = 32;
7899 begin
7900 if Word32 then
7901 Duration_32_Bits_On_Target := True;
7902 end if;
7903 end;
7905 Set_Restriction (No_Finalization, N);
7906 Set_Restriction (No_Exception_Handlers, N);
7907 Set_Restriction (Max_Tasks, N, 0);
7908 Set_Restriction (No_Tasking, N);
7910 -----------------------
7911 -- Normalize_Scalars --
7912 -----------------------
7914 -- pragma Normalize_Scalars;
7916 when Pragma_Normalize_Scalars =>
7917 Check_Ada_83_Warning;
7918 Check_Arg_Count (0);
7919 Check_Valid_Configuration_Pragma;
7920 Normalize_Scalars := True;
7921 Init_Or_Norm_Scalars := True;
7923 --------------
7924 -- Optimize --
7925 --------------
7927 -- pragma Optimize (Time | Space);
7929 -- The actual check for optimize is done in Gigi. Note that this
7930 -- pragma does not actually change the optimization setting, it
7931 -- simply checks that it is consistent with the pragma.
7933 when Pragma_Optimize =>
7934 Check_No_Identifiers;
7935 Check_Arg_Count (1);
7936 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
7938 -------------------------
7939 -- Optional_Overriding --
7940 -------------------------
7942 -- These pragmas are treated as part of the previous subprogram
7943 -- declaration, and analyzed immediately after it (see sem_ch6,
7944 -- Check_Overriding_Operation). If the pragma has not been analyzed
7945 -- yet, it appears in the wrong place.
7947 when Pragma_Optional_Overriding =>
7948 Error_Msg_N ("pragma must appear immediately after subprogram", N);
7950 ----------------
7951 -- Overriding --
7952 ----------------
7954 when Pragma_Overriding =>
7955 Error_Msg_N ("pragma must appear immediately after subprogram", N);
7957 ----------
7958 -- Pack --
7959 ----------
7961 -- pragma Pack (first_subtype_LOCAL_NAME);
7963 when Pragma_Pack => Pack : declare
7964 Assoc : constant Node_Id := Arg1;
7965 Type_Id : Node_Id;
7966 Typ : Entity_Id;
7968 begin
7969 Check_No_Identifiers;
7970 Check_Arg_Count (1);
7971 Check_Arg_Is_Local_Name (Arg1);
7973 Type_Id := Expression (Assoc);
7974 Find_Type (Type_Id);
7975 Typ := Entity (Type_Id);
7977 if Typ = Any_Type
7978 or else Rep_Item_Too_Early (Typ, N)
7979 then
7980 return;
7981 else
7982 Typ := Underlying_Type (Typ);
7983 end if;
7985 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
7986 Error_Pragma ("pragma% must specify array or record type");
7987 end if;
7989 Check_First_Subtype (Arg1);
7991 if Has_Pragma_Pack (Typ) then
7992 Error_Pragma ("duplicate pragma%, only one allowed");
7994 -- Array type. We set the Has_Pragma_Pack flag, and Is_Packed,
7995 -- but not Has_Non_Standard_Rep, because we don't actually know
7996 -- till freeze time if the array can have packed representation.
7997 -- That's because in the general case we do not know enough about
7998 -- the component type until it in turn is frozen, which certainly
7999 -- happens before the array type is frozen, but not necessarily
8000 -- till that point (i.e. right now it may be unfrozen).
8002 elsif Is_Array_Type (Typ) then
8003 if Has_Aliased_Components (Base_Type (Typ)) then
8004 Error_Pragma
8005 ("pragma% ignored, cannot pack aliased components?");
8007 elsif Has_Atomic_Components (Typ)
8008 or else Is_Atomic (Component_Type (Typ))
8009 then
8010 Error_Pragma
8011 ("?pragma% ignored, cannot pack atomic components");
8013 elsif not Rep_Item_Too_Late (Typ, N) then
8014 Set_Is_Packed (Base_Type (Typ));
8015 Set_Has_Pragma_Pack (Base_Type (Typ));
8016 Set_Has_Non_Standard_Rep (Base_Type (Typ));
8017 end if;
8019 -- Record type. For record types, the pack is always effective
8021 else pragma Assert (Is_Record_Type (Typ));
8022 if not Rep_Item_Too_Late (Typ, N) then
8023 Set_Has_Pragma_Pack (Base_Type (Typ));
8024 Set_Is_Packed (Base_Type (Typ));
8025 Set_Has_Non_Standard_Rep (Base_Type (Typ));
8026 end if;
8027 end if;
8028 end Pack;
8030 ----------
8031 -- Page --
8032 ----------
8034 -- pragma Page;
8036 -- There is nothing to do here, since we did all the processing
8037 -- for this pragma in Par.Prag (so that it works properly even in
8038 -- syntax only mode)
8040 when Pragma_Page =>
8041 null;
8043 -------------
8044 -- Passive --
8045 -------------
8047 -- pragma Passive [(PASSIVE_FORM)];
8049 -- PASSIVE_FORM ::= Semaphore | No
8051 when Pragma_Passive =>
8052 GNAT_Pragma;
8054 if Nkind (Parent (N)) /= N_Task_Definition then
8055 Error_Pragma ("pragma% must be within task definition");
8056 end if;
8058 if Arg_Count /= 0 then
8059 Check_Arg_Count (1);
8060 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
8061 end if;
8063 -------------
8064 -- Polling --
8065 -------------
8067 -- pragma Polling (ON | OFF);
8069 when Pragma_Polling =>
8070 GNAT_Pragma;
8071 Check_Arg_Count (1);
8072 Check_No_Identifiers;
8073 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8074 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
8076 ---------------------
8077 -- Persistent_Data --
8078 ---------------------
8080 when Pragma_Persistent_Data => declare
8081 Ent : Entity_Id;
8083 begin
8084 -- Register the pragma as applying to the compilation unit.
8085 -- Individual Persistent_Object pragmas for relevant objects
8086 -- are generated the end of the compilation.
8088 GNAT_Pragma;
8089 Check_Valid_Configuration_Pragma;
8090 Check_Arg_Count (0);
8091 Ent := Find_Lib_Unit_Name;
8092 Set_Is_Preelaborated (Ent);
8093 end;
8095 -----------------------
8096 -- Persistent_Object --
8097 -----------------------
8099 when Pragma_Persistent_Object => declare
8100 Decl : Node_Id;
8101 Ent : Entity_Id;
8102 MA : Node_Id;
8103 Str : String_Id;
8105 begin
8106 GNAT_Pragma;
8107 Check_Arg_Count (1);
8108 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8110 if not Is_Entity_Name (Expression (Arg1))
8111 or else
8112 (Ekind (Entity (Expression (Arg1))) /= E_Variable
8113 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
8114 then
8115 Error_Pragma_Arg ("pragma only applies to objects", Arg1);
8116 end if;
8118 Ent := Entity (Expression (Arg1));
8119 Decl := Parent (Ent);
8121 if Nkind (Decl) /= N_Object_Declaration then
8122 return;
8123 end if;
8125 -- Placement of the object depends on whether there is
8126 -- an initial value or none. If the No_Initialization flag
8127 -- is set, the initialization has been transformed into
8128 -- assignments, which is disallowed elaboration code.
8130 if No_Initialization (Decl) then
8131 Error_Msg_N
8132 ("initialization for persistent object"
8133 & "must be static expression", Decl);
8134 return;
8135 end if;
8137 if No (Expression (Decl)) then
8138 Start_String;
8139 Store_String_Chars ("section ("".persistent.bss"")");
8140 Str := End_String;
8142 else
8143 if not Is_OK_Static_Expression (Expression (Decl)) then
8144 Flag_Non_Static_Expr
8145 ("initialization for persistent object"
8146 & "must be static expression!", Expression (Decl));
8147 return;
8148 end if;
8150 Start_String;
8151 Store_String_Chars ("section ("".persistent.data"")");
8152 Str := End_String;
8153 end if;
8155 MA :=
8156 Make_Pragma
8157 (Sloc (N),
8158 Name_Machine_Attribute,
8159 New_List
8160 (Make_Pragma_Argument_Association
8161 (Sloc => Sloc (Arg1),
8162 Expression => New_Occurrence_Of (Ent, Sloc (Ent))),
8163 Make_Pragma_Argument_Association
8164 (Sloc => Sloc (Arg1),
8165 Expression =>
8166 Make_String_Literal
8167 (Sloc => Sloc (Arg1),
8168 Strval => Str))));
8170 Insert_After (N, MA);
8171 Analyze (MA);
8172 Set_Has_Gigi_Rep_Item (Ent);
8173 end;
8175 ------------------
8176 -- Preelaborate --
8177 ------------------
8179 -- pragma Preelaborate [(library_unit_NAME)];
8181 -- Set the flag Is_Preelaborated of program unit name entity
8183 when Pragma_Preelaborate => Preelaborate : declare
8184 Pa : constant Node_Id := Parent (N);
8185 Pk : constant Node_Kind := Nkind (Pa);
8186 Ent : Entity_Id;
8188 begin
8189 Check_Ada_83_Warning;
8190 Check_Valid_Library_Unit_Pragma;
8192 if Nkind (N) = N_Null_Statement then
8193 return;
8194 end if;
8196 Ent := Find_Lib_Unit_Name;
8198 -- This filters out pragmas inside generic parent then
8199 -- show up inside instantiation
8201 if Present (Ent)
8202 and then not (Pk = N_Package_Specification
8203 and then Present (Generic_Parent (Pa)))
8204 then
8205 if not Debug_Flag_U then
8206 Set_Is_Preelaborated (Ent);
8207 Set_Suppress_Elaboration_Warnings (Ent);
8208 end if;
8209 end if;
8210 end Preelaborate;
8212 --------------
8213 -- Priority --
8214 --------------
8216 -- pragma Priority (EXPRESSION);
8218 when Pragma_Priority => Priority : declare
8219 P : constant Node_Id := Parent (N);
8220 Arg : Node_Id;
8222 begin
8223 Check_No_Identifiers;
8224 Check_Arg_Count (1);
8226 -- Subprogram case
8228 if Nkind (P) = N_Subprogram_Body then
8229 Check_In_Main_Program;
8231 Arg := Expression (Arg1);
8232 Analyze_And_Resolve (Arg, Standard_Integer);
8234 -- Must be static
8236 if not Is_Static_Expression (Arg) then
8237 Flag_Non_Static_Expr
8238 ("main subprogram priority is not static!", Arg);
8239 raise Pragma_Exit;
8241 -- If constraint error, then we already signalled an error
8243 elsif Raises_Constraint_Error (Arg) then
8244 null;
8246 -- Otherwise check in range
8248 else
8249 declare
8250 Val : constant Uint := Expr_Value (Arg);
8252 begin
8253 if Val < 0
8254 or else Val > Expr_Value (Expression
8255 (Parent (RTE (RE_Max_Priority))))
8256 then
8257 Error_Pragma_Arg
8258 ("main subprogram priority is out of range", Arg1);
8259 end if;
8260 end;
8261 end if;
8263 Set_Main_Priority
8264 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8266 -- Task or Protected, must be of type Integer
8268 elsif Nkind (P) = N_Protected_Definition
8269 or else
8270 Nkind (P) = N_Task_Definition
8271 then
8272 Arg := Expression (Arg1);
8274 -- The expression must be analyzed in the special manner
8275 -- described in "Handling of Default and Per-Object
8276 -- Expressions" in sem.ads.
8278 Analyze_Per_Use_Expression (Arg, Standard_Integer);
8280 if not Is_Static_Expression (Arg) then
8281 Check_Restriction (Static_Priorities, Arg);
8282 end if;
8284 -- Anything else is incorrect
8286 else
8287 Pragma_Misplaced;
8288 end if;
8290 if Has_Priority_Pragma (P) then
8291 Error_Pragma ("duplicate pragma% not allowed");
8292 else
8293 Set_Has_Priority_Pragma (P, True);
8295 if Nkind (P) = N_Protected_Definition
8296 or else
8297 Nkind (P) = N_Task_Definition
8298 then
8299 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8300 -- exp_ch9 should use this ???
8301 end if;
8302 end if;
8303 end Priority;
8305 -------------
8306 -- Profile --
8307 -------------
8309 -- pragma Profile (profile_IDENTIFIER);
8311 -- profile_IDENTIFIER => Protected | Ravenscar
8313 when Pragma_Profile =>
8314 Check_Arg_Count (1);
8315 Check_Valid_Configuration_Pragma;
8316 Check_No_Identifiers;
8318 declare
8319 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8320 begin
8321 if Chars (Argx) = Name_Ravenscar then
8322 Set_Ravenscar_Profile (N);
8324 elsif Chars (Argx) = Name_Restricted then
8325 Set_Profile_Restrictions (Restricted, N, Warn => False);
8326 else
8327 Error_Pragma_Arg ("& is not a valid profile", Argx);
8328 end if;
8329 end;
8331 ----------------------
8332 -- Profile_Warnings --
8333 ----------------------
8335 -- pragma Profile_Warnings (profile_IDENTIFIER);
8337 -- profile_IDENTIFIER => Protected | Ravenscar
8339 when Pragma_Profile_Warnings =>
8340 GNAT_Pragma;
8341 Check_Arg_Count (1);
8342 Check_Valid_Configuration_Pragma;
8343 Check_No_Identifiers;
8345 declare
8346 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8347 begin
8348 if Chars (Argx) = Name_Ravenscar then
8349 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
8351 elsif Chars (Argx) = Name_Restricted then
8352 Set_Profile_Restrictions (Restricted, N, Warn => True);
8353 else
8354 Error_Pragma_Arg ("& is not a valid profile", Argx);
8355 end if;
8356 end;
8358 --------------------------
8359 -- Propagate_Exceptions --
8360 --------------------------
8362 -- pragma Propagate_Exceptions;
8364 when Pragma_Propagate_Exceptions =>
8365 GNAT_Pragma;
8366 Check_Arg_Count (0);
8368 if In_Extended_Main_Source_Unit (N) then
8369 Propagate_Exceptions := True;
8370 end if;
8372 ------------------
8373 -- Psect_Object --
8374 ------------------
8376 -- pragma Psect_Object (
8377 -- [Internal =>] LOCAL_NAME,
8378 -- [, [External =>] EXTERNAL_SYMBOL]
8379 -- [, [Size =>] EXTERNAL_SYMBOL]);
8381 when Pragma_Psect_Object | Pragma_Common_Object =>
8382 Psect_Object : declare
8383 Args : Args_List (1 .. 3);
8384 Names : constant Name_List (1 .. 3) := (
8385 Name_Internal,
8386 Name_External,
8387 Name_Size);
8389 Internal : Node_Id renames Args (1);
8390 External : Node_Id renames Args (2);
8391 Size : Node_Id renames Args (3);
8393 R_Internal : Node_Id;
8394 R_External : Node_Id;
8396 MA : Node_Id;
8397 Str : String_Id;
8399 Def_Id : Entity_Id;
8401 procedure Check_Too_Long (Arg : Node_Id);
8402 -- Posts message if the argument is an identifier with more
8403 -- than 31 characters, or a string literal with more than
8404 -- 31 characters, and we are operating under VMS
8406 --------------------
8407 -- Check_Too_Long --
8408 --------------------
8410 procedure Check_Too_Long (Arg : Node_Id) is
8411 X : constant Node_Id := Original_Node (Arg);
8413 begin
8414 if Nkind (X) /= N_String_Literal
8415 and then
8416 Nkind (X) /= N_Identifier
8417 then
8418 Error_Pragma_Arg
8419 ("inappropriate argument for pragma %", Arg);
8420 end if;
8422 if OpenVMS_On_Target then
8423 if (Nkind (X) = N_String_Literal
8424 and then String_Length (Strval (X)) > 31)
8425 or else
8426 (Nkind (X) = N_Identifier
8427 and then Length_Of_Name (Chars (X)) > 31)
8428 then
8429 Error_Pragma_Arg
8430 ("argument for pragma % is longer than 31 characters",
8431 Arg);
8432 end if;
8433 end if;
8434 end Check_Too_Long;
8436 -- Start of processing for Common_Object/Psect_Object
8438 begin
8439 GNAT_Pragma;
8440 Gather_Associations (Names, Args);
8441 Process_Extended_Import_Export_Internal_Arg (Internal);
8443 R_Internal := Relocate_Node (Internal);
8445 Def_Id := Entity (R_Internal);
8447 if Ekind (Def_Id) /= E_Constant
8448 and then Ekind (Def_Id) /= E_Variable
8449 then
8450 Error_Pragma_Arg
8451 ("pragma% must designate an object", Internal);
8452 end if;
8454 Check_Too_Long (R_Internal);
8456 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
8457 Error_Pragma_Arg
8458 ("cannot use pragma% for imported/exported object",
8459 R_Internal);
8460 end if;
8462 if Is_Concurrent_Type (Etype (R_Internal)) then
8463 Error_Pragma_Arg
8464 ("cannot specify pragma % for task/protected object",
8465 R_Internal);
8466 end if;
8468 if Is_Psected (Def_Id) then
8469 Error_Msg_N ("?duplicate Psect_Object pragma", N);
8470 else
8471 Set_Is_Psected (Def_Id);
8472 end if;
8474 if Ekind (Def_Id) = E_Constant then
8475 Error_Pragma_Arg
8476 ("cannot specify pragma % for a constant", R_Internal);
8477 end if;
8479 if Is_Record_Type (Etype (R_Internal)) then
8480 declare
8481 Ent : Entity_Id;
8482 Decl : Entity_Id;
8484 begin
8485 Ent := First_Entity (Etype (R_Internal));
8486 while Present (Ent) loop
8487 Decl := Declaration_Node (Ent);
8489 if Ekind (Ent) = E_Component
8490 and then Nkind (Decl) = N_Component_Declaration
8491 and then Present (Expression (Decl))
8492 and then Warn_On_Export_Import
8493 then
8494 Error_Msg_N
8495 ("?object for pragma % has defaults", R_Internal);
8496 exit;
8498 else
8499 Next_Entity (Ent);
8500 end if;
8501 end loop;
8502 end;
8503 end if;
8505 if Present (Size) then
8506 Check_Too_Long (Size);
8507 end if;
8509 -- Make Psect case-insensitive.
8511 if Present (External) then
8512 Check_Too_Long (External);
8514 if Nkind (External) = N_String_Literal then
8515 String_To_Name_Buffer (Strval (External));
8516 else
8517 Get_Name_String (Chars (External));
8518 end if;
8520 Set_All_Upper_Case;
8521 Start_String;
8522 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8523 Str := End_String;
8524 R_External := Make_String_Literal
8525 (Sloc => Sloc (External), Strval => Str);
8526 else
8527 Get_Name_String (Chars (Internal));
8528 Set_All_Upper_Case;
8529 Start_String;
8530 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8531 Str := End_String;
8532 R_External := Make_String_Literal
8533 (Sloc => Sloc (Internal), Strval => Str);
8534 end if;
8536 -- Transform into pragma Linker_Section, add attributes to
8537 -- match what DEC Ada does. Ignore size for now?
8539 Rewrite (N,
8540 Make_Pragma
8541 (Sloc (N),
8542 Name_Linker_Section,
8543 New_List
8544 (Make_Pragma_Argument_Association
8545 (Sloc => Sloc (R_Internal),
8546 Expression => R_Internal),
8547 Make_Pragma_Argument_Association
8548 (Sloc => Sloc (R_External),
8549 Expression => R_External))));
8551 Analyze (N);
8553 -- Add Machine_Attribute of "overlaid", so the section overlays
8554 -- other sections of the same name.
8556 Start_String;
8557 Store_String_Chars ("overlaid");
8558 Str := End_String;
8560 MA :=
8561 Make_Pragma
8562 (Sloc (N),
8563 Name_Machine_Attribute,
8564 New_List
8565 (Make_Pragma_Argument_Association
8566 (Sloc => Sloc (R_Internal),
8567 Expression => R_Internal),
8568 Make_Pragma_Argument_Association
8569 (Sloc => Sloc (R_External),
8570 Expression =>
8571 Make_String_Literal
8572 (Sloc => Sloc (R_External),
8573 Strval => Str))));
8574 Analyze (MA);
8576 -- Add Machine_Attribute of "global", so the section is visible
8577 -- everywhere
8579 Start_String;
8580 Store_String_Chars ("global");
8581 Str := End_String;
8583 MA :=
8584 Make_Pragma
8585 (Sloc (N),
8586 Name_Machine_Attribute,
8587 New_List
8588 (Make_Pragma_Argument_Association
8589 (Sloc => Sloc (R_Internal),
8590 Expression => R_Internal),
8592 Make_Pragma_Argument_Association
8593 (Sloc => Sloc (R_External),
8594 Expression =>
8595 Make_String_Literal
8596 (Sloc => Sloc (R_External),
8597 Strval => Str))));
8598 Analyze (MA);
8600 -- Add Machine_Attribute of "initialize", so the section is
8601 -- demand zeroed.
8603 Start_String;
8604 Store_String_Chars ("initialize");
8605 Str := End_String;
8607 MA :=
8608 Make_Pragma
8609 (Sloc (N),
8610 Name_Machine_Attribute,
8611 New_List
8612 (Make_Pragma_Argument_Association
8613 (Sloc => Sloc (R_Internal),
8614 Expression => R_Internal),
8616 Make_Pragma_Argument_Association
8617 (Sloc => Sloc (R_External),
8618 Expression =>
8619 Make_String_Literal
8620 (Sloc => Sloc (R_External),
8621 Strval => Str))));
8622 Analyze (MA);
8623 end Psect_Object;
8625 ----------
8626 -- Pure --
8627 ----------
8629 -- pragma Pure [(library_unit_NAME)];
8631 when Pragma_Pure => Pure : declare
8632 Ent : Entity_Id;
8633 begin
8634 Check_Ada_83_Warning;
8635 Check_Valid_Library_Unit_Pragma;
8637 if Nkind (N) = N_Null_Statement then
8638 return;
8639 end if;
8641 Ent := Find_Lib_Unit_Name;
8642 Set_Is_Pure (Ent);
8643 Set_Suppress_Elaboration_Warnings (Ent);
8644 end Pure;
8646 -------------------
8647 -- Pure_Function --
8648 -------------------
8650 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
8652 when Pragma_Pure_Function => Pure_Function : declare
8653 E_Id : Node_Id;
8654 E : Entity_Id;
8655 Def_Id : Entity_Id;
8656 Effective : Boolean := False;
8658 begin
8659 GNAT_Pragma;
8660 Check_Arg_Count (1);
8661 Check_Optional_Identifier (Arg1, Name_Entity);
8662 Check_Arg_Is_Local_Name (Arg1);
8663 E_Id := Expression (Arg1);
8665 if Error_Posted (E_Id) then
8666 return;
8667 end if;
8669 -- Loop through homonyms (overloadings) of referenced entity
8671 E := Entity (E_Id);
8673 if Present (E) then
8674 loop
8675 Def_Id := Get_Base_Subprogram (E);
8677 if Ekind (Def_Id) /= E_Function
8678 and then Ekind (Def_Id) /= E_Generic_Function
8679 and then Ekind (Def_Id) /= E_Operator
8680 then
8681 Error_Pragma_Arg
8682 ("pragma% requires a function name", Arg1);
8683 end if;
8685 Set_Is_Pure (Def_Id);
8687 if not Has_Pragma_Pure_Function (Def_Id) then
8688 Set_Has_Pragma_Pure_Function (Def_Id);
8689 Effective := True;
8690 end if;
8692 E := Homonym (E);
8693 exit when No (E) or else Scope (E) /= Current_Scope;
8694 end loop;
8696 if not Effective
8697 and then Warn_On_Redundant_Constructs
8698 then
8699 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
8700 N, Entity (E_Id));
8701 end if;
8702 end if;
8703 end Pure_Function;
8705 --------------------
8706 -- Queuing_Policy --
8707 --------------------
8709 -- pragma Queuing_Policy (policy_IDENTIFIER);
8711 when Pragma_Queuing_Policy => declare
8712 QP : Character;
8714 begin
8715 Check_Ada_83_Warning;
8716 Check_Arg_Count (1);
8717 Check_No_Identifiers;
8718 Check_Arg_Is_Queuing_Policy (Arg1);
8719 Check_Valid_Configuration_Pragma;
8720 Get_Name_String (Chars (Expression (Arg1)));
8721 QP := Fold_Upper (Name_Buffer (1));
8723 if Queuing_Policy /= ' '
8724 and then Queuing_Policy /= QP
8725 then
8726 Error_Msg_Sloc := Queuing_Policy_Sloc;
8727 Error_Pragma ("queuing policy incompatible with policy#");
8729 -- Set new policy, but always preserve System_Location since
8730 -- we like the error message with the run time name.
8732 else
8733 Queuing_Policy := QP;
8735 if Queuing_Policy_Sloc /= System_Location then
8736 Queuing_Policy_Sloc := Loc;
8737 end if;
8738 end if;
8739 end;
8741 ---------------------------
8742 -- Remote_Call_Interface --
8743 ---------------------------
8745 -- pragma Remote_Call_Interface [(library_unit_NAME)];
8747 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
8748 Cunit_Node : Node_Id;
8749 Cunit_Ent : Entity_Id;
8750 K : Node_Kind;
8752 begin
8753 Check_Ada_83_Warning;
8754 Check_Valid_Library_Unit_Pragma;
8756 if Nkind (N) = N_Null_Statement then
8757 return;
8758 end if;
8760 Cunit_Node := Cunit (Current_Sem_Unit);
8761 K := Nkind (Unit (Cunit_Node));
8762 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8764 if K = N_Package_Declaration
8765 or else K = N_Generic_Package_Declaration
8766 or else K = N_Subprogram_Declaration
8767 or else K = N_Generic_Subprogram_Declaration
8768 or else (K = N_Subprogram_Body
8769 and then Acts_As_Spec (Unit (Cunit_Node)))
8770 then
8771 null;
8772 else
8773 Error_Pragma (
8774 "pragma% must apply to package or subprogram declaration");
8775 end if;
8777 Set_Is_Remote_Call_Interface (Cunit_Ent);
8778 end Remote_Call_Interface;
8780 ------------------
8781 -- Remote_Types --
8782 ------------------
8784 -- pragma Remote_Types [(library_unit_NAME)];
8786 when Pragma_Remote_Types => Remote_Types : declare
8787 Cunit_Node : Node_Id;
8788 Cunit_Ent : Entity_Id;
8790 begin
8791 Check_Ada_83_Warning;
8792 Check_Valid_Library_Unit_Pragma;
8794 if Nkind (N) = N_Null_Statement then
8795 return;
8796 end if;
8798 Cunit_Node := Cunit (Current_Sem_Unit);
8799 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8801 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
8802 and then
8803 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
8804 then
8805 Error_Pragma (
8806 "pragma% can only apply to a package declaration");
8807 end if;
8809 Set_Is_Remote_Types (Cunit_Ent);
8810 end Remote_Types;
8812 ---------------
8813 -- Ravenscar --
8814 ---------------
8816 -- pragma Ravenscar;
8818 when Pragma_Ravenscar =>
8819 GNAT_Pragma;
8820 Check_Arg_Count (0);
8821 Check_Valid_Configuration_Pragma;
8822 Set_Ravenscar_Profile (N);
8824 if Warn_On_Obsolescent_Feature then
8825 Error_Msg_N
8826 ("pragma Ravenscar is an obsolescent feature?", N);
8827 Error_Msg_N
8828 ("|use pragma Profile (Ravenscar) instead", N);
8829 end if;
8831 -------------------------
8832 -- Restricted_Run_Time --
8833 -------------------------
8835 -- pragma Restricted_Run_Time;
8837 when Pragma_Restricted_Run_Time =>
8838 GNAT_Pragma;
8839 Check_Arg_Count (0);
8840 Check_Valid_Configuration_Pragma;
8841 Set_Profile_Restrictions (Restricted, N, Warn => False);
8843 if Warn_On_Obsolescent_Feature then
8844 Error_Msg_N
8845 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
8846 Error_Msg_N
8847 ("|use pragma Profile (Restricted) instead", N);
8848 end if;
8850 ------------------
8851 -- Restrictions --
8852 ------------------
8854 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
8856 -- RESTRICTION ::=
8857 -- restriction_IDENTIFIER
8858 -- | restriction_parameter_IDENTIFIER => EXPRESSION
8860 when Pragma_Restrictions =>
8861 Process_Restrictions_Or_Restriction_Warnings;
8863 --------------------------
8864 -- Restriction_Warnings --
8865 --------------------------
8867 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
8869 -- RESTRICTION ::=
8870 -- restriction_IDENTIFIER
8871 -- | restriction_parameter_IDENTIFIER => EXPRESSION
8873 when Pragma_Restriction_Warnings =>
8874 Process_Restrictions_Or_Restriction_Warnings;
8876 ----------------
8877 -- Reviewable --
8878 ----------------
8880 -- pragma Reviewable;
8882 when Pragma_Reviewable =>
8883 Check_Ada_83_Warning;
8884 Check_Arg_Count (0);
8886 -------------------
8887 -- Share_Generic --
8888 -------------------
8890 -- pragma Share_Generic (NAME {, NAME});
8892 when Pragma_Share_Generic =>
8893 GNAT_Pragma;
8894 Process_Generic_List;
8896 ------------
8897 -- Shared --
8898 ------------
8900 -- pragma Shared (LOCAL_NAME);
8902 when Pragma_Shared =>
8903 GNAT_Pragma;
8904 Process_Atomic_Shared_Volatile;
8906 --------------------
8907 -- Shared_Passive --
8908 --------------------
8910 -- pragma Shared_Passive [(library_unit_NAME)];
8912 -- Set the flag Is_Shared_Passive of program unit name entity
8914 when Pragma_Shared_Passive => Shared_Passive : declare
8915 Cunit_Node : Node_Id;
8916 Cunit_Ent : Entity_Id;
8918 begin
8919 Check_Ada_83_Warning;
8920 Check_Valid_Library_Unit_Pragma;
8922 if Nkind (N) = N_Null_Statement then
8923 return;
8924 end if;
8926 Cunit_Node := Cunit (Current_Sem_Unit);
8927 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8929 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
8930 and then
8931 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
8932 then
8933 Error_Pragma (
8934 "pragma% can only apply to a package declaration");
8935 end if;
8937 Set_Is_Shared_Passive (Cunit_Ent);
8938 end Shared_Passive;
8940 ----------------------
8941 -- Source_File_Name --
8942 ----------------------
8944 -- There are five forms for this pragma:
8946 -- pragma Source_File_Name (
8947 -- [UNIT_NAME =>] unit_NAME,
8948 -- BODY_FILE_NAME => STRING_LITERAL
8949 -- [, [INDEX =>] INTEGER_LITERAL]);
8951 -- pragma Source_File_Name (
8952 -- [UNIT_NAME =>] unit_NAME,
8953 -- SPEC_FILE_NAME => STRING_LITERAL
8954 -- [, [INDEX =>] INTEGER_LITERAL]);
8956 -- pragma Source_File_Name (
8957 -- BODY_FILE_NAME => STRING_LITERAL
8958 -- [, DOT_REPLACEMENT => STRING_LITERAL]
8959 -- [, CASING => CASING_SPEC]);
8961 -- pragma Source_File_Name (
8962 -- SPEC_FILE_NAME => STRING_LITERAL
8963 -- [, DOT_REPLACEMENT => STRING_LITERAL]
8964 -- [, CASING => CASING_SPEC]);
8966 -- pragma Source_File_Name (
8967 -- SUBUNIT_FILE_NAME => STRING_LITERAL
8968 -- [, DOT_REPLACEMENT => STRING_LITERAL]
8969 -- [, CASING => CASING_SPEC]);
8971 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
8973 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
8974 -- Source_File_Name (SFN), however their usage is exclusive:
8975 -- SFN can only be used when no project file is used, while
8976 -- SFNP can only be used when a project file is used.
8978 -- No processing here. Processing was completed during parsing,
8979 -- since we need to have file names set as early as possible.
8980 -- Units are loaded well before semantic processing starts.
8982 -- The only processing we defer to this point is the check
8983 -- for correct placement.
8985 when Pragma_Source_File_Name =>
8986 GNAT_Pragma;
8987 Check_Valid_Configuration_Pragma;
8989 ------------------------------
8990 -- Source_File_Name_Project --
8991 ------------------------------
8993 -- See Source_File_Name for syntax
8995 -- No processing here. Processing was completed during parsing,
8996 -- since we need to have file names set as early as possible.
8997 -- Units are loaded well before semantic processing starts.
8999 -- The only processing we defer to this point is the check
9000 -- for correct placement.
9002 when Pragma_Source_File_Name_Project =>
9003 GNAT_Pragma;
9004 Check_Valid_Configuration_Pragma;
9006 -- Check that a pragma Source_File_Name_Project is used only
9007 -- in a configuration pragmas file.
9009 -- Pragmas Source_File_Name_Project should only be generated
9010 -- by the Project Manager in configuration pragmas files.
9012 -- This is really an ugly test. It seems to depend on some
9013 -- accidental and undocumented property. At the very least
9014 -- it needs to be documented, but it would be better to have
9015 -- a clean way of testing if we are in a configuration file???
9017 if Present (Parent (N)) then
9018 Error_Pragma
9019 ("pragma% can only appear in a configuration pragmas file");
9020 end if;
9022 ----------------------
9023 -- Source_Reference --
9024 ----------------------
9026 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
9028 -- Nothing to do, all processing completed in Par.Prag, since we
9029 -- need the information for possible parser messages that are output
9031 when Pragma_Source_Reference =>
9032 GNAT_Pragma;
9034 ------------------
9035 -- Storage_Size --
9036 ------------------
9038 -- pragma Storage_Size (EXPRESSION);
9040 when Pragma_Storage_Size => Storage_Size : declare
9041 P : constant Node_Id := Parent (N);
9042 Arg : Node_Id;
9044 begin
9045 Check_No_Identifiers;
9046 Check_Arg_Count (1);
9048 -- The expression must be analyzed in the special manner
9049 -- described in "Handling of Default Expressions" in sem.ads.
9051 -- Set In_Default_Expression for per-object case ???
9053 Arg := Expression (Arg1);
9054 Analyze_Per_Use_Expression (Arg, Any_Integer);
9056 if not Is_Static_Expression (Arg) then
9057 Check_Restriction (Static_Storage_Size, Arg);
9058 end if;
9060 if Nkind (P) /= N_Task_Definition then
9061 Pragma_Misplaced;
9062 return;
9064 else
9065 if Has_Storage_Size_Pragma (P) then
9066 Error_Pragma ("duplicate pragma% not allowed");
9067 else
9068 Set_Has_Storage_Size_Pragma (P, True);
9069 end if;
9071 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9072 -- ??? exp_ch9 should use this!
9073 end if;
9074 end Storage_Size;
9076 ------------------
9077 -- Storage_Unit --
9078 ------------------
9080 -- pragma Storage_Unit (NUMERIC_LITERAL);
9082 -- Only permitted argument is System'Storage_Unit value
9084 when Pragma_Storage_Unit =>
9085 Check_No_Identifiers;
9086 Check_Arg_Count (1);
9087 Check_Arg_Is_Integer_Literal (Arg1);
9089 if Intval (Expression (Arg1)) /=
9090 UI_From_Int (Ttypes.System_Storage_Unit)
9091 then
9092 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
9093 Error_Pragma_Arg
9094 ("the only allowed argument for pragma% is ^", Arg1);
9095 end if;
9097 --------------------
9098 -- Stream_Convert --
9099 --------------------
9101 -- pragma Stream_Convert (
9102 -- [Entity =>] type_LOCAL_NAME,
9103 -- [Read =>] function_NAME,
9104 -- [Write =>] function NAME);
9106 when Pragma_Stream_Convert => Stream_Convert : declare
9108 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
9109 -- Check that the given argument is the name of a local
9110 -- function of one argument that is not overloaded earlier
9111 -- in the current local scope. A check is also made that the
9112 -- argument is a function with one parameter.
9114 --------------------------------------
9115 -- Check_OK_Stream_Convert_Function --
9116 --------------------------------------
9118 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
9119 Ent : Entity_Id;
9121 begin
9122 Check_Arg_Is_Local_Name (Arg);
9123 Ent := Entity (Expression (Arg));
9125 if Has_Homonym (Ent) then
9126 Error_Pragma_Arg
9127 ("argument for pragma% may not be overloaded", Arg);
9128 end if;
9130 if Ekind (Ent) /= E_Function
9131 or else No (First_Formal (Ent))
9132 or else Present (Next_Formal (First_Formal (Ent)))
9133 then
9134 Error_Pragma_Arg
9135 ("argument for pragma% must be" &
9136 " function of one argument", Arg);
9137 end if;
9138 end Check_OK_Stream_Convert_Function;
9140 -- Start of procecessing for Stream_Convert
9142 begin
9143 GNAT_Pragma;
9144 Check_Arg_Count (3);
9145 Check_Optional_Identifier (Arg1, Name_Entity);
9146 Check_Optional_Identifier (Arg2, Name_Read);
9147 Check_Optional_Identifier (Arg3, Name_Write);
9148 Check_Arg_Is_Local_Name (Arg1);
9149 Check_OK_Stream_Convert_Function (Arg2);
9150 Check_OK_Stream_Convert_Function (Arg3);
9152 declare
9153 Typ : constant Entity_Id :=
9154 Underlying_Type (Entity (Expression (Arg1)));
9155 Read : constant Entity_Id := Entity (Expression (Arg2));
9156 Write : constant Entity_Id := Entity (Expression (Arg3));
9158 begin
9159 if Etype (Typ) = Any_Type
9160 or else
9161 Etype (Read) = Any_Type
9162 or else
9163 Etype (Write) = Any_Type
9164 then
9165 return;
9166 end if;
9168 Check_First_Subtype (Arg1);
9170 if Rep_Item_Too_Early (Typ, N)
9171 or else
9172 Rep_Item_Too_Late (Typ, N)
9173 then
9174 return;
9175 end if;
9177 if Underlying_Type (Etype (Read)) /= Typ then
9178 Error_Pragma_Arg
9179 ("incorrect return type for function&", Arg2);
9180 end if;
9182 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
9183 Error_Pragma_Arg
9184 ("incorrect parameter type for function&", Arg3);
9185 end if;
9187 if Underlying_Type (Etype (First_Formal (Read))) /=
9188 Underlying_Type (Etype (Write))
9189 then
9190 Error_Pragma_Arg
9191 ("result type of & does not match Read parameter type",
9192 Arg3);
9193 end if;
9194 end;
9195 end Stream_Convert;
9197 -------------------------
9198 -- Style_Checks (GNAT) --
9199 -------------------------
9201 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
9203 -- This is processed by the parser since some of the style
9204 -- checks take place during source scanning and parsing. This
9205 -- means that we don't need to issue error messages here.
9207 when Pragma_Style_Checks => Style_Checks : declare
9208 A : constant Node_Id := Expression (Arg1);
9209 S : String_Id;
9210 C : Char_Code;
9212 begin
9213 GNAT_Pragma;
9214 Check_No_Identifiers;
9216 -- Two argument form
9218 if Arg_Count = 2 then
9219 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9221 declare
9222 E_Id : Node_Id;
9223 E : Entity_Id;
9225 begin
9226 E_Id := Expression (Arg2);
9227 Analyze (E_Id);
9229 if not Is_Entity_Name (E_Id) then
9230 Error_Pragma_Arg
9231 ("second argument of pragma% must be entity name",
9232 Arg2);
9233 end if;
9235 E := Entity (E_Id);
9237 if E = Any_Id then
9238 return;
9239 else
9240 loop
9241 Set_Suppress_Style_Checks (E,
9242 (Chars (Expression (Arg1)) = Name_Off));
9243 exit when No (Homonym (E));
9244 E := Homonym (E);
9245 end loop;
9246 end if;
9247 end;
9249 -- One argument form
9251 else
9252 Check_Arg_Count (1);
9254 if Nkind (A) = N_String_Literal then
9255 S := Strval (A);
9257 declare
9258 Slen : constant Natural := Natural (String_Length (S));
9259 Options : String (1 .. Slen);
9260 J : Natural;
9262 begin
9263 J := 1;
9264 loop
9265 C := Get_String_Char (S, Int (J));
9266 exit when not In_Character_Range (C);
9267 Options (J) := Get_Character (C);
9269 if J = Slen then
9270 Set_Style_Check_Options (Options);
9271 exit;
9272 else
9273 J := J + 1;
9274 end if;
9275 end loop;
9276 end;
9278 elsif Nkind (A) = N_Identifier then
9280 if Chars (A) = Name_All_Checks then
9281 Set_Default_Style_Check_Options;
9283 elsif Chars (A) = Name_On then
9284 Style_Check := True;
9286 elsif Chars (A) = Name_Off then
9287 Style_Check := False;
9289 end if;
9290 end if;
9291 end if;
9292 end Style_Checks;
9294 --------------
9295 -- Subtitle --
9296 --------------
9298 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
9300 when Pragma_Subtitle =>
9301 GNAT_Pragma;
9302 Check_Arg_Count (1);
9303 Check_Optional_Identifier (Arg1, Name_Subtitle);
9304 Check_Arg_Is_String_Literal (Arg1);
9306 --------------
9307 -- Suppress --
9308 --------------
9310 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
9312 when Pragma_Suppress =>
9313 Process_Suppress_Unsuppress (True);
9315 ------------------
9316 -- Suppress_All --
9317 ------------------
9319 -- pragma Suppress_All;
9321 -- The only check made here is that the pragma appears in the
9322 -- proper place, i.e. following a compilation unit. If indeed
9323 -- it appears in this context, then the parser has already
9324 -- inserted an equivalent pragma Suppress (All_Checks) to get
9325 -- the required effect.
9327 when Pragma_Suppress_All =>
9328 GNAT_Pragma;
9329 Check_Arg_Count (0);
9331 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9332 or else not Is_List_Member (N)
9333 or else List_Containing (N) /= Pragmas_After (Parent (N))
9334 then
9335 Error_Pragma
9336 ("misplaced pragma%, must follow compilation unit");
9337 end if;
9339 -------------------------
9340 -- Suppress_Debug_Info --
9341 -------------------------
9343 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
9345 when Pragma_Suppress_Debug_Info =>
9346 GNAT_Pragma;
9347 Check_Arg_Count (1);
9348 Check_Arg_Is_Local_Name (Arg1);
9349 Check_Optional_Identifier (Arg1, Name_Entity);
9350 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
9352 ----------------------------------
9353 -- Suppress_Exception_Locations --
9354 ----------------------------------
9356 -- pragma Suppress_Exception_Locations;
9358 when Pragma_Suppress_Exception_Locations =>
9359 GNAT_Pragma;
9360 Check_Arg_Count (0);
9361 Check_Valid_Configuration_Pragma;
9362 Exception_Locations_Suppressed := True;
9364 -----------------------------
9365 -- Suppress_Initialization --
9366 -----------------------------
9368 -- pragma Suppress_Initialization ([Entity =>] type_Name);
9370 when Pragma_Suppress_Initialization => Suppress_Init : declare
9371 E_Id : Node_Id;
9372 E : Entity_Id;
9374 begin
9375 GNAT_Pragma;
9376 Check_Arg_Count (1);
9377 Check_Optional_Identifier (Arg1, Name_Entity);
9378 Check_Arg_Is_Local_Name (Arg1);
9380 E_Id := Expression (Arg1);
9382 if Etype (E_Id) = Any_Type then
9383 return;
9384 end if;
9386 E := Entity (E_Id);
9388 if Is_Type (E) then
9389 if Is_Incomplete_Or_Private_Type (E) then
9390 if No (Full_View (Base_Type (E))) then
9391 Error_Pragma_Arg
9392 ("argument of pragma% cannot be an incomplete type",
9393 Arg1);
9394 else
9395 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
9396 end if;
9397 else
9398 Set_Suppress_Init_Proc (Base_Type (E));
9399 end if;
9401 else
9402 Error_Pragma_Arg
9403 ("pragma% requires argument that is a type name", Arg1);
9404 end if;
9405 end Suppress_Init;
9407 -----------------
9408 -- System_Name --
9409 -----------------
9411 -- pragma System_Name (DIRECT_NAME);
9413 -- Syntax check: one argument, which must be the identifier GNAT
9414 -- or the identifier GCC, no other identifiers are acceptable.
9416 when Pragma_System_Name =>
9417 Check_No_Identifiers;
9418 Check_Arg_Count (1);
9419 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
9421 -----------------------------
9422 -- Task_Dispatching_Policy --
9423 -----------------------------
9425 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
9427 when Pragma_Task_Dispatching_Policy => declare
9428 DP : Character;
9430 begin
9431 Check_Ada_83_Warning;
9432 Check_Arg_Count (1);
9433 Check_No_Identifiers;
9434 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9435 Check_Valid_Configuration_Pragma;
9436 Get_Name_String (Chars (Expression (Arg1)));
9437 DP := Fold_Upper (Name_Buffer (1));
9439 if Task_Dispatching_Policy /= ' '
9440 and then Task_Dispatching_Policy /= DP
9441 then
9442 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9443 Error_Pragma
9444 ("task dispatching policy incompatible with policy#");
9446 -- Set new policy, but always preserve System_Location since
9447 -- we like the error message with the run time name.
9449 else
9450 Task_Dispatching_Policy := DP;
9452 if Task_Dispatching_Policy_Sloc /= System_Location then
9453 Task_Dispatching_Policy_Sloc := Loc;
9454 end if;
9455 end if;
9456 end;
9458 --------------
9459 -- Task_Info --
9460 --------------
9462 -- pragma Task_Info (EXPRESSION);
9464 when Pragma_Task_Info => Task_Info : declare
9465 P : constant Node_Id := Parent (N);
9467 begin
9468 GNAT_Pragma;
9470 if Nkind (P) /= N_Task_Definition then
9471 Error_Pragma ("pragma% must appear in task definition");
9472 end if;
9474 Check_No_Identifiers;
9475 Check_Arg_Count (1);
9477 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
9479 if Etype (Expression (Arg1)) = Any_Type then
9480 return;
9481 end if;
9483 if Has_Task_Info_Pragma (P) then
9484 Error_Pragma ("duplicate pragma% not allowed");
9485 else
9486 Set_Has_Task_Info_Pragma (P, True);
9487 end if;
9488 end Task_Info;
9490 ---------------
9491 -- Task_Name --
9492 ---------------
9494 -- pragma Task_Name (string_EXPRESSION);
9496 when Pragma_Task_Name => Task_Name : declare
9497 -- pragma Priority (EXPRESSION);
9499 P : constant Node_Id := Parent (N);
9500 Arg : Node_Id;
9502 begin
9503 Check_No_Identifiers;
9504 Check_Arg_Count (1);
9506 Arg := Expression (Arg1);
9507 Analyze_And_Resolve (Arg, Standard_String);
9509 if Nkind (P) /= N_Task_Definition then
9510 Pragma_Misplaced;
9511 end if;
9513 if Has_Task_Name_Pragma (P) then
9514 Error_Pragma ("duplicate pragma% not allowed");
9515 else
9516 Set_Has_Task_Name_Pragma (P, True);
9517 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9518 end if;
9519 end Task_Name;
9521 ------------------
9522 -- Task_Storage --
9523 ------------------
9525 -- pragma Task_Storage (
9526 -- [Task_Type =>] LOCAL_NAME,
9527 -- [Top_Guard =>] static_integer_EXPRESSION);
9529 when Pragma_Task_Storage => Task_Storage : declare
9530 Args : Args_List (1 .. 2);
9531 Names : constant Name_List (1 .. 2) := (
9532 Name_Task_Type,
9533 Name_Top_Guard);
9535 Task_Type : Node_Id renames Args (1);
9536 Top_Guard : Node_Id renames Args (2);
9538 Ent : Entity_Id;
9540 begin
9541 GNAT_Pragma;
9542 Gather_Associations (Names, Args);
9544 if No (Task_Type) then
9545 Error_Pragma
9546 ("missing task_type argument for pragma%");
9547 end if;
9549 Check_Arg_Is_Local_Name (Task_Type);
9551 Ent := Entity (Task_Type);
9553 if not Is_Task_Type (Ent) then
9554 Error_Pragma_Arg
9555 ("argument for pragma% must be task type", Task_Type);
9556 end if;
9558 if No (Top_Guard) then
9559 Error_Pragma_Arg
9560 ("pragma% takes two arguments", Task_Type);
9561 else
9562 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
9563 end if;
9565 Check_First_Subtype (Task_Type);
9567 if Rep_Item_Too_Late (Ent, N) then
9568 raise Pragma_Exit;
9569 end if;
9570 end Task_Storage;
9572 -----------------
9573 -- Thread_Body --
9574 -----------------
9576 -- pragma Thread_Body
9577 -- ( [Entity =>] LOCAL_NAME
9578 -- [,[Secondary_Stack_Size =>] static_integer_EXPRESSION]);
9580 when Pragma_Thread_Body => Thread_Body : declare
9581 Id : Node_Id;
9582 SS : Node_Id;
9583 E : Entity_Id;
9585 begin
9586 GNAT_Pragma;
9587 Check_At_Least_N_Arguments (1);
9588 Check_At_Most_N_Arguments (2);
9589 Check_Optional_Identifier (Arg1, Name_Entity);
9590 Check_Arg_Is_Local_Name (Arg1);
9592 Id := Expression (Arg1);
9594 if not Is_Entity_Name (Id)
9595 or else not Is_Subprogram (Entity (Id))
9596 then
9597 Error_Pragma_Arg ("subprogram name required", Arg1);
9598 end if;
9600 E := Entity (Id);
9602 -- Go to renamed subprogram if present, since Thread_Body applies
9603 -- to the actual renamed entity, not to the renaming entity.
9605 if Present (Alias (E))
9606 and then Nkind (Parent (Declaration_Node (E))) =
9607 N_Subprogram_Renaming_Declaration
9608 then
9609 E := Alias (E);
9610 end if;
9612 -- Various error checks
9614 if Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body then
9615 Error_Pragma
9616 ("pragma% requires separate spec and must come before body");
9618 elsif Rep_Item_Too_Early (E, N)
9619 or else
9620 Rep_Item_Too_Late (E, N)
9621 then
9622 raise Pragma_Exit;
9624 elsif Is_Thread_Body (E) then
9625 Error_Pragma_Arg
9626 ("only one thread body pragma allowed", Arg1);
9628 elsif Present (Homonym (E))
9629 and then Scope (Homonym (E)) = Current_Scope
9630 then
9631 Error_Pragma_Arg
9632 ("thread body subprogram must not be overloaded", Arg1);
9633 end if;
9635 Set_Is_Thread_Body (E);
9637 -- Deal with secondary stack argument
9639 if Arg_Count = 2 then
9640 Check_Optional_Identifier (Arg2, Name_Secondary_Stack_Size);
9641 SS := Expression (Arg2);
9642 Analyze_And_Resolve (SS, Any_Integer);
9643 end if;
9644 end Thread_Body;
9646 ----------------
9647 -- Time_Slice --
9648 ----------------
9650 -- pragma Time_Slice (static_duration_EXPRESSION);
9652 when Pragma_Time_Slice => Time_Slice : declare
9653 Val : Ureal;
9654 Nod : Node_Id;
9656 begin
9657 GNAT_Pragma;
9658 Check_Arg_Count (1);
9659 Check_No_Identifiers;
9660 Check_In_Main_Program;
9661 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
9663 if not Error_Posted (Arg1) then
9664 Nod := Next (N);
9665 while Present (Nod) loop
9666 if Nkind (Nod) = N_Pragma
9667 and then Chars (Nod) = Name_Time_Slice
9668 then
9669 Error_Msg_Name_1 := Chars (N);
9670 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9671 end if;
9673 Next (Nod);
9674 end loop;
9675 end if;
9677 -- Process only if in main unit
9679 if Get_Source_Unit (Loc) = Main_Unit then
9680 Opt.Time_Slice_Set := True;
9681 Val := Expr_Value_R (Expression (Arg1));
9683 if Val <= Ureal_0 then
9684 Opt.Time_Slice_Value := 0;
9686 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
9687 Opt.Time_Slice_Value := 1_000_000_000;
9689 else
9690 Opt.Time_Slice_Value :=
9691 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
9692 end if;
9693 end if;
9694 end Time_Slice;
9696 -----------
9697 -- Title --
9698 -----------
9700 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
9702 -- TITLING_OPTION ::=
9703 -- [Title =>] STRING_LITERAL
9704 -- | [Subtitle =>] STRING_LITERAL
9706 when Pragma_Title => Title : declare
9707 Args : Args_List (1 .. 2);
9708 Names : constant Name_List (1 .. 2) := (
9709 Name_Title,
9710 Name_Subtitle);
9712 begin
9713 GNAT_Pragma;
9714 Gather_Associations (Names, Args);
9716 for J in 1 .. 2 loop
9717 if Present (Args (J)) then
9718 Check_Arg_Is_String_Literal (Args (J));
9719 end if;
9720 end loop;
9721 end Title;
9723 ---------------------
9724 -- Unchecked_Union --
9725 ---------------------
9727 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
9729 when Pragma_Unchecked_Union => Unchecked_Union : declare
9730 Assoc : constant Node_Id := Arg1;
9731 Type_Id : constant Node_Id := Expression (Assoc);
9732 Typ : Entity_Id;
9733 Discr : Entity_Id;
9734 Tdef : Node_Id;
9735 Clist : Node_Id;
9736 Vpart : Node_Id;
9737 Comp : Node_Id;
9738 Variant : Node_Id;
9740 begin
9741 GNAT_Pragma;
9742 Check_No_Identifiers;
9743 Check_Arg_Count (1);
9744 Check_Arg_Is_Local_Name (Arg1);
9746 Find_Type (Type_Id);
9747 Typ := Entity (Type_Id);
9749 if Typ = Any_Type
9750 or else Rep_Item_Too_Early (Typ, N)
9751 then
9752 return;
9753 else
9754 Typ := Underlying_Type (Typ);
9755 end if;
9757 if Rep_Item_Too_Late (Typ, N) then
9758 return;
9759 end if;
9761 Check_First_Subtype (Arg1);
9763 -- Note remaining cases are references to a type in the current
9764 -- declarative part. If we find an error, we post the error on
9765 -- the relevant type declaration at an appropriate point.
9767 if not Is_Record_Type (Typ) then
9768 Error_Msg_N ("Unchecked_Union must be record type", Typ);
9769 return;
9771 elsif Is_Tagged_Type (Typ) then
9772 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
9773 return;
9775 elsif Is_Limited_Type (Typ) then
9776 Error_Msg_N
9777 ("Unchecked_Union must not be limited record type", Typ);
9778 Explain_Limited_Type (Typ, Typ);
9779 return;
9781 else
9782 if not Has_Discriminants (Typ) then
9783 Error_Msg_N
9784 ("Unchecked_Union must have one discriminant", Typ);
9785 return;
9786 end if;
9788 Discr := First_Discriminant (Typ);
9790 if Present (Next_Discriminant (Discr)) then
9791 Error_Msg_N
9792 ("Unchecked_Union must have exactly one discriminant",
9793 Next_Discriminant (Discr));
9794 return;
9795 end if;
9797 if No (Discriminant_Default_Value (Discr)) then
9798 Error_Msg_N
9799 ("Unchecked_Union discriminant must have default value",
9800 Discr);
9801 end if;
9803 Tdef := Type_Definition (Declaration_Node (Typ));
9804 Clist := Component_List (Tdef);
9806 Comp := First (Component_Items (Clist));
9807 while Present (Comp) loop
9809 Check_Component (Comp);
9810 Next (Comp);
9812 end loop;
9814 if No (Clist) or else No (Variant_Part (Clist)) then
9815 Error_Msg_N
9816 ("Unchecked_Union must have variant part",
9817 Tdef);
9818 return;
9819 end if;
9821 Vpart := Variant_Part (Clist);
9822 Variant := First (Variants (Vpart));
9823 while Present (Variant) loop
9825 Check_Variant (Variant);
9826 Next (Variant);
9828 end loop;
9829 end if;
9831 Set_Is_Unchecked_Union (Typ, True);
9832 Set_Convention (Typ, Convention_C);
9834 Set_Has_Unchecked_Union (Base_Type (Typ), True);
9835 Set_Is_Unchecked_Union (Base_Type (Typ), True);
9836 end Unchecked_Union;
9838 ------------------------
9839 -- Unimplemented_Unit --
9840 ------------------------
9842 -- pragma Unimplemented_Unit;
9844 -- Note: this only gives an error if we are generating code,
9845 -- or if we are in a generic library unit (where the pragma
9846 -- appears in the body, not in the spec).
9848 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
9849 Cunitent : constant Entity_Id :=
9850 Cunit_Entity (Get_Source_Unit (Loc));
9851 Ent_Kind : constant Entity_Kind :=
9852 Ekind (Cunitent);
9854 begin
9855 GNAT_Pragma;
9856 Check_Arg_Count (0);
9858 if Operating_Mode = Generate_Code
9859 or else Ent_Kind = E_Generic_Function
9860 or else Ent_Kind = E_Generic_Procedure
9861 or else Ent_Kind = E_Generic_Package
9862 then
9863 Get_Name_String (Chars (Cunitent));
9864 Set_Casing (Mixed_Case);
9865 Write_Str (Name_Buffer (1 .. Name_Len));
9866 Write_Str (" is not implemented");
9867 Write_Eol;
9868 raise Unrecoverable_Error;
9869 end if;
9870 end Unimplemented_Unit;
9872 --------------------
9873 -- Universal_Data --
9874 --------------------
9876 -- pragma Universal_Data [(library_unit_NAME)];
9878 when Pragma_Universal_Data =>
9879 GNAT_Pragma;
9881 -- If this is a configuration pragma, then set the universal
9882 -- addressing option, otherwise confirm that the pragma
9883 -- satisfies the requirements of library unit pragma placement
9884 -- and leave it to the GNAAMP back end to detect the pragma
9885 -- (avoids transitive setting of the option due to withed units).
9887 if Is_Configuration_Pragma then
9888 Universal_Addressing_On_AAMP := True;
9889 else
9890 Check_Valid_Library_Unit_Pragma;
9891 end if;
9893 if not AAMP_On_Target then
9894 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
9895 end if;
9897 ------------------
9898 -- Unreferenced --
9899 ------------------
9901 -- pragma Unreferenced (local_Name {, local_Name});
9903 when Pragma_Unreferenced => Unreferenced : declare
9904 Arg_Node : Node_Id;
9905 Arg_Expr : Node_Id;
9906 Arg_Ent : Entity_Id;
9908 begin
9909 GNAT_Pragma;
9910 Check_At_Least_N_Arguments (1);
9912 Arg_Node := Arg1;
9914 while Present (Arg_Node) loop
9915 Check_No_Identifier (Arg_Node);
9917 -- Note that the analyze call done by Check_Arg_Is_Local_Name
9918 -- will in fact generate a reference, so that the entity will
9919 -- have a reference, which will inhibit any warnings about it
9920 -- not being referenced, and also properly show up in the ali
9921 -- file as a reference. But this reference is recorded before
9922 -- the Has_Pragma_Unreferenced flag is set, so that no warning
9923 -- is generated for this reference.
9925 Check_Arg_Is_Local_Name (Arg_Node);
9926 Arg_Expr := Get_Pragma_Arg (Arg_Node);
9928 if Is_Entity_Name (Arg_Expr) then
9929 Arg_Ent := Entity (Arg_Expr);
9931 -- If the entity is overloaded, the pragma applies to the
9932 -- most recent overloading, as documented. In this case,
9933 -- name resolution does not generate a reference, so it
9934 -- must be done here explicitly.
9936 if Is_Overloaded (Arg_Expr) then
9937 Generate_Reference (Arg_Ent, N);
9938 end if;
9940 Set_Has_Pragma_Unreferenced (Arg_Ent);
9941 end if;
9943 Next (Arg_Node);
9944 end loop;
9945 end Unreferenced;
9947 ------------------------------
9948 -- Unreserve_All_Interrupts --
9949 ------------------------------
9951 -- pragma Unreserve_All_Interrupts;
9953 when Pragma_Unreserve_All_Interrupts =>
9954 GNAT_Pragma;
9955 Check_Arg_Count (0);
9957 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
9958 Unreserve_All_Interrupts := True;
9959 end if;
9961 ----------------
9962 -- Unsuppress --
9963 ----------------
9965 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
9967 when Pragma_Unsuppress =>
9968 GNAT_Pragma;
9969 Process_Suppress_Unsuppress (False);
9971 -------------------
9972 -- Use_VADS_Size --
9973 -------------------
9975 -- pragma Use_VADS_Size;
9977 when Pragma_Use_VADS_Size =>
9978 GNAT_Pragma;
9979 Check_Arg_Count (0);
9980 Check_Valid_Configuration_Pragma;
9981 Use_VADS_Size := True;
9983 ---------------------
9984 -- Validity_Checks --
9985 ---------------------
9987 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
9989 when Pragma_Validity_Checks => Validity_Checks : declare
9990 A : constant Node_Id := Expression (Arg1);
9991 S : String_Id;
9992 C : Char_Code;
9994 begin
9995 GNAT_Pragma;
9996 Check_Arg_Count (1);
9997 Check_No_Identifiers;
9999 if Nkind (A) = N_String_Literal then
10000 S := Strval (A);
10002 declare
10003 Slen : constant Natural := Natural (String_Length (S));
10004 Options : String (1 .. Slen);
10005 J : Natural;
10007 begin
10008 J := 1;
10009 loop
10010 C := Get_String_Char (S, Int (J));
10011 exit when not In_Character_Range (C);
10012 Options (J) := Get_Character (C);
10014 if J = Slen then
10015 Set_Validity_Check_Options (Options);
10016 exit;
10017 else
10018 J := J + 1;
10019 end if;
10020 end loop;
10021 end;
10023 elsif Nkind (A) = N_Identifier then
10025 if Chars (A) = Name_All_Checks then
10026 Set_Validity_Check_Options ("a");
10028 elsif Chars (A) = Name_On then
10029 Validity_Checks_On := True;
10031 elsif Chars (A) = Name_Off then
10032 Validity_Checks_On := False;
10034 end if;
10035 end if;
10036 end Validity_Checks;
10038 --------------
10039 -- Volatile --
10040 --------------
10042 -- pragma Volatile (LOCAL_NAME);
10044 when Pragma_Volatile =>
10045 Process_Atomic_Shared_Volatile;
10047 -------------------------
10048 -- Volatile_Components --
10049 -------------------------
10051 -- pragma Volatile_Components (array_LOCAL_NAME);
10053 -- Volatile is handled by the same circuit as Atomic_Components
10055 --------------
10056 -- Warnings --
10057 --------------
10059 -- pragma Warnings (On | Off, [LOCAL_NAME])
10061 when Pragma_Warnings => Warnings : begin
10062 GNAT_Pragma;
10063 Check_At_Least_N_Arguments (1);
10064 Check_At_Most_N_Arguments (2);
10065 Check_No_Identifiers;
10067 -- One argument case was processed by parser in Par.Prag
10069 if Arg_Count /= 1 then
10070 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10071 Check_Arg_Count (2);
10073 declare
10074 E_Id : Node_Id;
10075 E : Entity_Id;
10077 begin
10078 E_Id := Expression (Arg2);
10079 Analyze (E_Id);
10081 -- In the expansion of an inlined body, a reference to
10082 -- the formal may be wrapped in a conversion if the actual
10083 -- is a conversion. Retrieve the real entity name.
10085 if (In_Instance_Body
10086 or else In_Inlined_Body)
10087 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
10088 then
10089 E_Id := Expression (E_Id);
10090 end if;
10092 if not Is_Entity_Name (E_Id) then
10093 Error_Pragma_Arg
10094 ("second argument of pragma% must be entity name",
10095 Arg2);
10096 end if;
10098 E := Entity (E_Id);
10100 if E = Any_Id then
10101 return;
10102 else
10103 loop
10104 Set_Warnings_Off (E,
10105 (Chars (Expression (Arg1)) = Name_Off));
10107 if Is_Enumeration_Type (E) then
10108 declare
10109 Lit : Entity_Id := First_Literal (E);
10111 begin
10112 while Present (Lit) loop
10113 Set_Warnings_Off (Lit);
10114 Next_Literal (Lit);
10115 end loop;
10116 end;
10117 end if;
10119 exit when No (Homonym (E));
10120 E := Homonym (E);
10121 end loop;
10122 end if;
10123 end;
10124 end if;
10125 end Warnings;
10127 -------------------
10128 -- Weak_External --
10129 -------------------
10131 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
10133 when Pragma_Weak_External => Weak_External : declare
10134 Ent : Entity_Id;
10136 begin
10137 GNAT_Pragma;
10138 Check_Arg_Count (1);
10139 Check_Optional_Identifier (Arg1, Name_Entity);
10140 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10141 Ent := Entity (Expression (Arg1));
10143 if Rep_Item_Too_Early (Ent, N) then
10144 return;
10145 else
10146 Ent := Underlying_Type (Ent);
10147 end if;
10149 -- The only processing required is to link this item on to the
10150 -- list of rep items for the given entity. This is accomplished
10151 -- by the call to Rep_Item_Too_Late (when no error is detected
10152 -- and False is returned).
10154 if Rep_Item_Too_Late (Ent, N) then
10155 return;
10156 else
10157 Set_Has_Gigi_Rep_Item (Ent);
10158 end if;
10159 end Weak_External;
10161 --------------------
10162 -- Unknown_Pragma --
10163 --------------------
10165 -- Should be impossible, since the case of an unknown pragma is
10166 -- separately processed before the case statement is entered.
10168 when Unknown_Pragma =>
10169 raise Program_Error;
10170 end case;
10172 exception
10173 when Pragma_Exit => null;
10174 end Analyze_Pragma;
10176 ---------------------------------
10177 -- Delay_Config_Pragma_Analyze --
10178 ---------------------------------
10180 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
10181 begin
10182 return Chars (N) = Name_Interrupt_State;
10183 end Delay_Config_Pragma_Analyze;
10185 -------------------------
10186 -- Get_Base_Subprogram --
10187 -------------------------
10189 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
10190 Result : Entity_Id;
10192 begin
10193 Result := Def_Id;
10195 -- Follow subprogram renaming chain
10197 while Is_Subprogram (Result)
10198 and then
10199 (Is_Generic_Instance (Result)
10200 or else Nkind (Parent (Declaration_Node (Result))) =
10201 N_Subprogram_Renaming_Declaration)
10202 and then Present (Alias (Result))
10203 loop
10204 Result := Alias (Result);
10205 end loop;
10207 return Result;
10208 end Get_Base_Subprogram;
10210 -----------------------------
10211 -- Is_Config_Static_String --
10212 -----------------------------
10214 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
10216 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
10217 -- This is an internal recursive function that is just like the
10218 -- outer function except that it adds the string to the name buffer
10219 -- rather than placing the string in the name buffer.
10221 ------------------------------
10222 -- Add_Config_Static_String --
10223 ------------------------------
10225 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
10226 N : Node_Id;
10227 C : Char_Code;
10229 begin
10230 N := Arg;
10232 if Nkind (N) = N_Op_Concat then
10233 if Add_Config_Static_String (Left_Opnd (N)) then
10234 N := Right_Opnd (N);
10235 else
10236 return False;
10237 end if;
10238 end if;
10240 if Nkind (N) /= N_String_Literal then
10241 Error_Msg_N ("string literal expected for pragma argument", N);
10242 return False;
10244 else
10245 for J in 1 .. String_Length (Strval (N)) loop
10246 C := Get_String_Char (Strval (N), J);
10248 if not In_Character_Range (C) then
10249 Error_Msg
10250 ("string literal contains invalid wide character",
10251 Sloc (N) + 1 + Source_Ptr (J));
10252 return False;
10253 end if;
10255 Add_Char_To_Name_Buffer (Get_Character (C));
10256 end loop;
10257 end if;
10259 return True;
10260 end Add_Config_Static_String;
10262 -- Start of prorcessing for Is_Config_Static_String
10264 begin
10266 Name_Len := 0;
10267 return Add_Config_Static_String (Arg);
10268 end Is_Config_Static_String;
10270 -----------------------------------------
10271 -- Is_Non_Significant_Pragma_Reference --
10272 -----------------------------------------
10274 -- This function makes use of the following static table which indicates
10275 -- whether a given pragma is significant. A value of -1 in this table
10276 -- indicates that the reference is significant. A value of zero indicates
10277 -- than appearence as any argument is insignificant, a positive value
10278 -- indicates that appearence in that parameter position is significant.
10280 Sig_Flags : constant array (Pragma_Id) of Int :=
10282 (Pragma_AST_Entry => -1,
10283 Pragma_Abort_Defer => -1,
10284 Pragma_Ada_83 => -1,
10285 Pragma_Ada_95 => -1,
10286 Pragma_Ada_05 => -1,
10287 Pragma_All_Calls_Remote => -1,
10288 Pragma_Annotate => -1,
10289 Pragma_Assert => -1,
10290 Pragma_Asynchronous => -1,
10291 Pragma_Atomic => 0,
10292 Pragma_Atomic_Components => 0,
10293 Pragma_Attach_Handler => -1,
10294 Pragma_CPP_Class => 0,
10295 Pragma_CPP_Constructor => 0,
10296 Pragma_CPP_Virtual => 0,
10297 Pragma_CPP_Vtable => 0,
10298 Pragma_C_Pass_By_Copy => 0,
10299 Pragma_Comment => 0,
10300 Pragma_Common_Object => -1,
10301 Pragma_Compile_Time_Warning => -1,
10302 Pragma_Complex_Representation => 0,
10303 Pragma_Component_Alignment => -1,
10304 Pragma_Controlled => 0,
10305 Pragma_Convention => 0,
10306 Pragma_Convention_Identifier => 0,
10307 Pragma_Debug => -1,
10308 Pragma_Detect_Blocking => -1,
10309 Pragma_Discard_Names => 0,
10310 Pragma_Elaborate => -1,
10311 Pragma_Elaborate_All => -1,
10312 Pragma_Elaborate_Body => -1,
10313 Pragma_Elaboration_Checks => -1,
10314 Pragma_Eliminate => -1,
10315 Pragma_Explicit_Overriding => -1,
10316 Pragma_Export => -1,
10317 Pragma_Export_Exception => -1,
10318 Pragma_Export_Function => -1,
10319 Pragma_Export_Object => -1,
10320 Pragma_Export_Procedure => -1,
10321 Pragma_Export_Value => -1,
10322 Pragma_Export_Valued_Procedure => -1,
10323 Pragma_Extend_System => -1,
10324 Pragma_Extensions_Allowed => -1,
10325 Pragma_External => -1,
10326 Pragma_External_Name_Casing => -1,
10327 Pragma_Finalize_Storage_Only => 0,
10328 Pragma_Float_Representation => 0,
10329 Pragma_Ident => -1,
10330 Pragma_Import => +2,
10331 Pragma_Import_Exception => 0,
10332 Pragma_Import_Function => 0,
10333 Pragma_Import_Object => 0,
10334 Pragma_Import_Procedure => 0,
10335 Pragma_Import_Valued_Procedure => 0,
10336 Pragma_Initialize_Scalars => -1,
10337 Pragma_Inline => 0,
10338 Pragma_Inline_Always => 0,
10339 Pragma_Inline_Generic => 0,
10340 Pragma_Inspection_Point => -1,
10341 Pragma_Interface => +2,
10342 Pragma_Interface_Name => +2,
10343 Pragma_Interrupt_Handler => -1,
10344 Pragma_Interrupt_Priority => -1,
10345 Pragma_Interrupt_State => -1,
10346 Pragma_Java_Constructor => -1,
10347 Pragma_Java_Interface => -1,
10348 Pragma_Keep_Names => 0,
10349 Pragma_License => -1,
10350 Pragma_Link_With => -1,
10351 Pragma_Linker_Alias => -1,
10352 Pragma_Linker_Options => -1,
10353 Pragma_Linker_Section => -1,
10354 Pragma_List => -1,
10355 Pragma_Locking_Policy => -1,
10356 Pragma_Long_Float => -1,
10357 Pragma_Machine_Attribute => -1,
10358 Pragma_Main => -1,
10359 Pragma_Main_Storage => -1,
10360 Pragma_Memory_Size => -1,
10361 Pragma_No_Return => 0,
10362 Pragma_No_Run_Time => -1,
10363 Pragma_No_Strict_Aliasing => -1,
10364 Pragma_Normalize_Scalars => -1,
10365 Pragma_Obsolescent => 0,
10366 Pragma_Optimize => -1,
10367 Pragma_Optional_Overriding => -1,
10368 Pragma_Overriding => -1,
10369 Pragma_Pack => 0,
10370 Pragma_Page => -1,
10371 Pragma_Passive => -1,
10372 Pragma_Polling => -1,
10373 Pragma_Persistent_Data => -1,
10374 Pragma_Persistent_Object => -1,
10375 Pragma_Preelaborate => -1,
10376 Pragma_Priority => -1,
10377 Pragma_Profile => 0,
10378 Pragma_Profile_Warnings => 0,
10379 Pragma_Propagate_Exceptions => -1,
10380 Pragma_Psect_Object => -1,
10381 Pragma_Pure => 0,
10382 Pragma_Pure_Function => 0,
10383 Pragma_Queuing_Policy => -1,
10384 Pragma_Ravenscar => -1,
10385 Pragma_Remote_Call_Interface => -1,
10386 Pragma_Remote_Types => -1,
10387 Pragma_Restricted_Run_Time => -1,
10388 Pragma_Restriction_Warnings => -1,
10389 Pragma_Restrictions => -1,
10390 Pragma_Reviewable => -1,
10391 Pragma_Share_Generic => -1,
10392 Pragma_Shared => -1,
10393 Pragma_Shared_Passive => -1,
10394 Pragma_Source_File_Name => -1,
10395 Pragma_Source_File_Name_Project => -1,
10396 Pragma_Source_Reference => -1,
10397 Pragma_Storage_Size => -1,
10398 Pragma_Storage_Unit => -1,
10399 Pragma_Stream_Convert => -1,
10400 Pragma_Style_Checks => -1,
10401 Pragma_Subtitle => -1,
10402 Pragma_Suppress => 0,
10403 Pragma_Suppress_Exception_Locations => 0,
10404 Pragma_Suppress_All => -1,
10405 Pragma_Suppress_Debug_Info => 0,
10406 Pragma_Suppress_Initialization => 0,
10407 Pragma_System_Name => -1,
10408 Pragma_Task_Dispatching_Policy => -1,
10409 Pragma_Task_Info => -1,
10410 Pragma_Task_Name => -1,
10411 Pragma_Task_Storage => 0,
10412 Pragma_Thread_Body => +2,
10413 Pragma_Time_Slice => -1,
10414 Pragma_Title => -1,
10415 Pragma_Unchecked_Union => 0,
10416 Pragma_Unimplemented_Unit => -1,
10417 Pragma_Universal_Data => -1,
10418 Pragma_Unreferenced => -1,
10419 Pragma_Unreserve_All_Interrupts => -1,
10420 Pragma_Unsuppress => 0,
10421 Pragma_Use_VADS_Size => -1,
10422 Pragma_Validity_Checks => -1,
10423 Pragma_Volatile => 0,
10424 Pragma_Volatile_Components => 0,
10425 Pragma_Warnings => -1,
10426 Pragma_Weak_External => 0,
10427 Unknown_Pragma => 0);
10429 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
10430 P : Node_Id;
10431 C : Int;
10432 A : Node_Id;
10434 begin
10435 P := Parent (N);
10437 if Nkind (P) /= N_Pragma_Argument_Association then
10438 return False;
10440 else
10441 C := Sig_Flags (Get_Pragma_Id (Chars (Parent (P))));
10443 case C is
10444 when -1 =>
10445 return False;
10447 when 0 =>
10448 return True;
10450 when others =>
10451 A := First (Pragma_Argument_Associations (Parent (P)));
10452 for J in 1 .. C - 1 loop
10453 if No (A) then
10454 return False;
10455 end if;
10457 Next (A);
10458 end loop;
10460 return A = P;
10461 end case;
10462 end if;
10463 end Is_Non_Significant_Pragma_Reference;
10465 ------------------------------
10466 -- Is_Pragma_String_Literal --
10467 ------------------------------
10469 -- This function returns true if the corresponding pragma argument is
10470 -- a static string expression. These are the only cases in which string
10471 -- literals can appear as pragma arguments. We also allow a string
10472 -- literal as the first argument to pragma Assert (although it will
10473 -- of course always generate a type error).
10475 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
10476 Pragn : constant Node_Id := Parent (Par);
10477 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
10478 Pname : constant Name_Id := Chars (Pragn);
10479 Argn : Natural;
10480 N : Node_Id;
10482 begin
10483 Argn := 1;
10484 N := First (Assoc);
10485 loop
10486 exit when N = Par;
10487 Argn := Argn + 1;
10488 Next (N);
10489 end loop;
10491 if Pname = Name_Assert then
10492 return True;
10494 elsif Pname = Name_Export then
10495 return Argn > 2;
10497 elsif Pname = Name_Ident then
10498 return Argn = 1;
10500 elsif Pname = Name_Import then
10501 return Argn > 2;
10503 elsif Pname = Name_Interface_Name then
10504 return Argn > 1;
10506 elsif Pname = Name_Linker_Alias then
10507 return Argn = 2;
10509 elsif Pname = Name_Linker_Section then
10510 return Argn = 2;
10512 elsif Pname = Name_Machine_Attribute then
10513 return Argn = 2;
10515 elsif Pname = Name_Source_File_Name then
10516 return True;
10518 elsif Pname = Name_Source_Reference then
10519 return Argn = 2;
10521 elsif Pname = Name_Title then
10522 return True;
10524 elsif Pname = Name_Subtitle then
10525 return True;
10527 else
10528 return False;
10529 end if;
10530 end Is_Pragma_String_Literal;
10532 --------------------------------------
10533 -- Process_Compilation_Unit_Pragmas --
10534 --------------------------------------
10536 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
10537 begin
10538 -- A special check for pragma Suppress_All. This is a strange DEC
10539 -- pragma, strange because it comes at the end of the unit. If we
10540 -- have a pragma Suppress_All in the Pragmas_After of the current
10541 -- unit, then we insert a pragma Suppress (All_Checks) at the start
10542 -- of the context clause to ensure the correct processing.
10544 declare
10545 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
10546 P : Node_Id;
10548 begin
10549 if Present (PA) then
10550 P := First (PA);
10551 while Present (P) loop
10552 if Chars (P) = Name_Suppress_All then
10553 Prepend_To (Context_Items (N),
10554 Make_Pragma (Sloc (P),
10555 Chars => Name_Suppress,
10556 Pragma_Argument_Associations => New_List (
10557 Make_Pragma_Argument_Association (Sloc (P),
10558 Expression =>
10559 Make_Identifier (Sloc (P),
10560 Chars => Name_All_Checks)))));
10561 exit;
10562 end if;
10564 Next (P);
10565 end loop;
10566 end if;
10567 end;
10568 end Process_Compilation_Unit_Pragmas;
10570 --------------------------------
10571 -- Set_Encoded_Interface_Name --
10572 --------------------------------
10574 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
10575 Str : constant String_Id := Strval (S);
10576 Len : constant Int := String_Length (Str);
10577 CC : Char_Code;
10578 C : Character;
10579 J : Int;
10581 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
10583 procedure Encode;
10584 -- Stores encoded value of character code CC. The encoding we
10585 -- use an underscore followed by four lower case hex digits.
10587 procedure Encode is
10588 begin
10589 Store_String_Char (Get_Char_Code ('_'));
10590 Store_String_Char
10591 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
10592 Store_String_Char
10593 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
10594 Store_String_Char
10595 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
10596 Store_String_Char
10597 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
10598 end Encode;
10600 -- Start of processing for Set_Encoded_Interface_Name
10602 begin
10603 -- If first character is asterisk, this is a link name, and we
10604 -- leave it completely unmodified. We also ignore null strings
10605 -- (the latter case happens only in error cases) and no encoding
10606 -- should occur for Java interface names.
10608 if Len = 0
10609 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
10610 or else Java_VM
10611 then
10612 Set_Interface_Name (E, S);
10614 else
10615 J := 1;
10616 loop
10617 CC := Get_String_Char (Str, J);
10619 exit when not In_Character_Range (CC);
10621 C := Get_Character (CC);
10623 exit when C /= '_' and then C /= '$'
10624 and then C not in '0' .. '9'
10625 and then C not in 'a' .. 'z'
10626 and then C not in 'A' .. 'Z';
10628 if J = Len then
10629 Set_Interface_Name (E, S);
10630 return;
10632 else
10633 J := J + 1;
10634 end if;
10635 end loop;
10637 -- Here we need to encode. The encoding we use as follows:
10638 -- three underscores + four hex digits (lower case)
10640 Start_String;
10642 for J in 1 .. String_Length (Str) loop
10643 CC := Get_String_Char (Str, J);
10645 if not In_Character_Range (CC) then
10646 Encode;
10647 else
10648 C := Get_Character (CC);
10650 if C = '_' or else C = '$'
10651 or else C in '0' .. '9'
10652 or else C in 'a' .. 'z'
10653 or else C in 'A' .. 'Z'
10654 then
10655 Store_String_Char (CC);
10656 else
10657 Encode;
10658 end if;
10659 end if;
10660 end loop;
10662 Set_Interface_Name (E,
10663 Make_String_Literal (Sloc (S),
10664 Strval => End_String));
10665 end if;
10666 end Set_Encoded_Interface_Name;
10668 -------------------
10669 -- Set_Unit_Name --
10670 -------------------
10672 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
10673 Pref : Node_Id;
10674 Scop : Entity_Id;
10676 begin
10677 if Nkind (N) = N_Identifier
10678 and then Nkind (With_Item) = N_Identifier
10679 then
10680 Set_Entity (N, Entity (With_Item));
10682 elsif Nkind (N) = N_Selected_Component then
10683 Change_Selected_Component_To_Expanded_Name (N);
10684 Set_Entity (N, Entity (With_Item));
10685 Set_Entity (Selector_Name (N), Entity (N));
10687 Pref := Prefix (N);
10688 Scop := Scope (Entity (N));
10690 while Nkind (Pref) = N_Selected_Component loop
10691 Change_Selected_Component_To_Expanded_Name (Pref);
10692 Set_Entity (Selector_Name (Pref), Scop);
10693 Set_Entity (Pref, Scop);
10694 Pref := Prefix (Pref);
10695 Scop := Scope (Scop);
10696 end loop;
10698 Set_Entity (Pref, Scop);
10699 end if;
10700 end Set_Unit_Name;
10702 end Sem_Prag;