Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / gcc / ada / sem_prag.adb
blob408024b3715df940f31b416c335327c3008f2c9f
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-2005, 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 Hostparm; use Hostparm;
42 with Lib; use Lib;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref; use Lib.Xref;
45 with Namet; use Namet;
46 with Nlists; use Nlists;
47 with Nmake; use Nmake;
48 with Opt; use Opt;
49 with Output; use Output;
50 with Restrict; use Restrict;
51 with Rident; use Rident;
52 with Rtsfind; use Rtsfind;
53 with Sem; use Sem;
54 with Sem_Ch3; use Sem_Ch3;
55 with Sem_Ch8; use Sem_Ch8;
56 with Sem_Ch13; use Sem_Ch13;
57 with Sem_Disp; use Sem_Disp;
58 with Sem_Elim; use Sem_Elim;
59 with Sem_Eval; use Sem_Eval;
60 with Sem_Intr; use Sem_Intr;
61 with Sem_Mech; use Sem_Mech;
62 with Sem_Res; use Sem_Res;
63 with Sem_Type; use Sem_Type;
64 with Sem_Util; use Sem_Util;
65 with Sem_VFpt; use Sem_VFpt;
66 with Stand; use Stand;
67 with Sinfo; use Sinfo;
68 with Sinfo.CN; use Sinfo.CN;
69 with Sinput; use Sinput;
70 with Snames; use Snames;
71 with Stringt; use Stringt;
72 with Stylesw; use Stylesw;
73 with Table;
74 with Targparm; use Targparm;
75 with Tbuild; use Tbuild;
76 with Ttypes;
77 with Uintp; use Uintp;
78 with Urealp; use Urealp;
79 with Validsw; use Validsw;
81 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
83 package body Sem_Prag is
85 ----------------------------------------------
86 -- Common Handling of Import-Export Pragmas --
87 ----------------------------------------------
89 -- In the following section, a number of Import_xxx and Export_xxx
90 -- pragmas are defined by GNAT. These are compatible with the DEC
91 -- pragmas of the same name, and all have the following common
92 -- form and processing:
94 -- pragma Export_xxx
95 -- [Internal =>] LOCAL_NAME,
96 -- [, [External =>] EXTERNAL_SYMBOL]
97 -- [, other optional parameters ]);
99 -- pragma Import_xxx
100 -- [Internal =>] LOCAL_NAME,
101 -- [, [External =>] EXTERNAL_SYMBOL]
102 -- [, other optional parameters ]);
104 -- EXTERNAL_SYMBOL ::=
105 -- IDENTIFIER
106 -- | static_string_EXPRESSION
108 -- The internal LOCAL_NAME designates the entity that is imported or
109 -- exported, and must refer to an entity in the current declarative
110 -- part (as required by the rules for LOCAL_NAME).
112 -- The external linker name is designated by the External parameter
113 -- if given, or the Internal parameter if not (if there is no External
114 -- parameter, the External parameter is a copy of the Internal name).
116 -- If the External parameter is given as a string, then this string
117 -- is treated as an external name (exactly as though it had been given
118 -- as an External_Name parameter for a normal Import pragma).
120 -- If the External parameter is given as an identifier (or there is no
121 -- External parameter, so that the Internal identifier is used), then
122 -- the external name is the characters of the identifier, translated
123 -- to all upper case letters for OpenVMS versions of GNAT, and to all
124 -- lower case letters for all other versions
126 -- Note: the external name specified or implied by any of these special
127 -- Import_xxx or Export_xxx pragmas override an external or link name
128 -- specified in a previous Import or Export pragma.
130 -- Note: these and all other DEC-compatible GNAT pragmas allow full
131 -- use of named notation, following the standard rules for subprogram
132 -- calls, i.e. parameters can be given in any order if named notation
133 -- is used, and positional and named notation can be mixed, subject to
134 -- the rule that all positional parameters must appear first.
136 -- Note: All these pragmas are implemented exactly following the DEC
137 -- design and implementation and are intended to be fully compatible
138 -- with the use of these pragmas in the DEC Ada compiler.
140 --------------------------------------------
141 -- Checking for Duplicated External Names --
142 --------------------------------------------
144 -- It is suspicious if two separate Export pragmas use the same external
145 -- name. The following table is used to diagnose this situation so that
146 -- an appropriate warning can be issued.
148 -- The Node_Id stored is for the N_String_Literal node created to
149 -- hold the value of the external name. The Sloc of this node is
150 -- used to cross-reference the location of the duplication.
152 package Externals is new Table.Table (
153 Table_Component_Type => Node_Id,
154 Table_Index_Type => Int,
155 Table_Low_Bound => 0,
156 Table_Initial => 100,
157 Table_Increment => 100,
158 Table_Name => "Name_Externals");
160 -------------------------------------
161 -- Local Subprograms and Variables --
162 -------------------------------------
164 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
165 -- This routine is used for possible casing adjustment of an explicit
166 -- external name supplied as a string literal (the node N), according
167 -- to the casing requirement of Opt.External_Name_Casing. If this is
168 -- set to As_Is, then the string literal is returned unchanged, but if
169 -- it is set to Uppercase or Lowercase, then a new string literal with
170 -- appropriate casing is constructed.
172 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
173 -- If Def_Id refers to a renamed subprogram, then the base subprogram
174 -- (the original one, following the renaming chain) is returned.
175 -- Otherwise the entity is returned unchanged. Should be in Einfo???
177 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
178 -- Place semantic information on the argument of an Elaborate or
179 -- Elaborate_All pragma. Entity name for unit and its parents is
180 -- taken from item in previous with_clause that mentions the unit.
182 -------------------------------
183 -- Adjust_External_Name_Case --
184 -------------------------------
186 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
187 CC : Char_Code;
189 begin
190 -- Adjust case of literal if required
192 if Opt.External_Name_Exp_Casing = As_Is then
193 return N;
195 else
196 -- Copy existing string
198 Start_String;
200 -- Set proper casing
202 for J in 1 .. String_Length (Strval (N)) loop
203 CC := Get_String_Char (Strval (N), J);
205 if Opt.External_Name_Exp_Casing = Uppercase
206 and then CC >= Get_Char_Code ('a')
207 and then CC <= Get_Char_Code ('z')
208 then
209 Store_String_Char (CC - 32);
211 elsif Opt.External_Name_Exp_Casing = Lowercase
212 and then CC >= Get_Char_Code ('A')
213 and then CC <= Get_Char_Code ('Z')
214 then
215 Store_String_Char (CC + 32);
217 else
218 Store_String_Char (CC);
219 end if;
220 end loop;
222 return
223 Make_String_Literal (Sloc (N),
224 Strval => End_String);
225 end if;
226 end Adjust_External_Name_Case;
228 --------------------
229 -- Analyze_Pragma --
230 --------------------
232 procedure Analyze_Pragma (N : Node_Id) is
233 Loc : constant Source_Ptr := Sloc (N);
234 Prag_Id : Pragma_Id;
236 Pragma_Exit : exception;
237 -- This exception is used to exit pragma processing completely. It
238 -- is used when an error is detected, and in other situations where
239 -- it is known that no further processing is required.
241 Arg_Count : Nat;
242 -- Number of pragma argument associations
244 Arg1 : Node_Id;
245 Arg2 : Node_Id;
246 Arg3 : Node_Id;
247 Arg4 : Node_Id;
248 -- First four pragma arguments (pragma argument association nodes,
249 -- or Empty if the corresponding argument does not exist).
251 procedure Check_Ada_83_Warning;
252 -- Issues a warning message for the current pragma if operating in Ada
253 -- 83 mode (used for language pragmas that are not a standard part of
254 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
255 -- of 95 pragma.
257 procedure Check_Arg_Count (Required : Nat);
258 -- Check argument count for pragma is equal to given parameter.
259 -- If not, then issue an error message and raise Pragma_Exit.
261 -- Note: all routines whose name is Check_Arg_Is_xxx take an
262 -- argument Arg which can either be a pragma argument association,
263 -- in which case the check is applied to the expression of the
264 -- association or an expression directly.
266 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
267 -- Check that an argument has the right form for an EXTERNAL_NAME
268 -- parameter of an extended import/export pragma. The rule is that
269 -- the name must be an identifier or string literal (in Ada 83 mode)
270 -- or a static string expression (in Ada 95 mode).
272 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
273 -- Check the specified argument Arg to make sure that it is an
274 -- identifier. If not give error and raise Pragma_Exit.
276 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
277 -- Check the specified argument Arg to make sure that it is an
278 -- integer literal. If not give error and raise Pragma_Exit.
280 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
281 -- Check the specified argument Arg to make sure that it has the
282 -- proper syntactic form for a local name and meets the semantic
283 -- requirements for a local name. The local name is analyzed as
284 -- part of the processing for this call. In addition, the local
285 -- name is required to represent an entity at the library level.
287 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
288 -- Check the specified argument Arg to make sure that it has the
289 -- proper syntactic form for a local name and meets the semantic
290 -- requirements for a local name. The local name is analyzed as
291 -- part of the processing for this call.
293 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
294 -- Check the specified argument Arg to make sure that it is a valid
295 -- locking policy name. If not give error and raise Pragma_Exit.
297 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
298 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
299 -- Check the specified argument Arg to make sure that it is an
300 -- identifier whose name matches either N1 or N2 (or N3 if present).
301 -- If not then give error and raise Pragma_Exit.
303 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
304 -- Check the specified argument Arg to make sure that it is a valid
305 -- queuing policy name. If not give error and raise Pragma_Exit.
307 procedure Check_Arg_Is_Static_Expression
308 (Arg : Node_Id;
309 Typ : Entity_Id);
310 -- Check the specified argument Arg to make sure that it is a static
311 -- expression of the given type (i.e. it will be analyzed and resolved
312 -- using this type, which can be any valid argument to Resolve, e.g.
313 -- Any_Integer is OK). If not, given error and raise Pragma_Exit.
315 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
316 -- Check the specified argument Arg to make sure that it is a
317 -- string literal. If not give error and raise Pragma_Exit
319 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
320 -- Check the specified argument Arg to make sure that it is a valid
321 -- valid task dispatching policy name. If not give error and raise
322 -- Pragma_Exit.
324 procedure Check_At_Least_N_Arguments (N : Nat);
325 -- Check there are at least N arguments present
327 procedure Check_At_Most_N_Arguments (N : Nat);
328 -- Check there are no more than N arguments present
330 procedure Check_Component (Comp : Node_Id);
331 -- Examine Unchecked_Union component for correct use of per-object
332 -- constrained subtypes.
334 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
335 -- Nam is an N_String_Literal node containing the external name set
336 -- by an Import or Export pragma (or extended Import or Export pragma).
337 -- This procedure checks for possible duplications if this is the
338 -- export case, and if found, issues an appropriate error message.
340 procedure Check_First_Subtype (Arg : Node_Id);
341 -- Checks that Arg, whose expression is an entity name referencing
342 -- a subtype, does not reference a type that is not a first subtype.
344 procedure Check_In_Main_Program;
345 -- Common checks for pragmas that appear within a main program
346 -- (Priority, Main_Storage, Time_Slice).
348 procedure Check_Interrupt_Or_Attach_Handler;
349 -- Common processing for first argument of pragma Interrupt_Handler
350 -- or pragma Attach_Handler.
352 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
353 -- Check that pragma appears in a declarative part, or in a package
354 -- specification, i.e. that it does not occur in a statement sequence
355 -- in a body.
357 procedure Check_No_Identifier (Arg : Node_Id);
358 -- Checks that the given argument does not have an identifier. If
359 -- an identifier is present, then an error message is issued, and
360 -- Pragma_Exit is raised.
362 procedure Check_No_Identifiers;
363 -- Checks that none of the arguments to the pragma has an identifier.
364 -- If any argument has an identifier, then an error message is issued,
365 -- and Pragma_Exit is raised.
367 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
368 -- Checks if the given argument has an identifier, and if so, requires
369 -- it to match the given identifier name. If there is a non-matching
370 -- identifier, then an error message is given and Error_Pragmas raised.
372 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
373 -- Checks if the given argument has an identifier, and if so, requires
374 -- it to match the given identifier name. If there is a non-matching
375 -- identifier, then an error message is given and Error_Pragmas raised.
376 -- In this version of the procedure, the identifier name is given as
377 -- a string with lower case letters.
379 procedure Check_Static_Constraint (Constr : Node_Id);
380 -- Constr is a constraint from an N_Subtype_Indication node from a
381 -- component constraint in an Unchecked_Union type. This routine checks
382 -- that the constraint is static as required by the restrictions for
383 -- Unchecked_Union.
385 procedure Check_Valid_Configuration_Pragma;
386 -- Legality checks for placement of a configuration pragma
388 procedure Check_Valid_Library_Unit_Pragma;
389 -- Legality checks for library unit pragmas. A special case arises for
390 -- pragmas in generic instances that come from copies of the original
391 -- library unit pragmas in the generic templates. In the case of other
392 -- than library level instantiations these can appear in contexts which
393 -- would normally be invalid (they only apply to the original template
394 -- and to library level instantiations), and they are simply ignored,
395 -- which is implemented by rewriting them as null statements.
397 procedure Check_Variant (Variant : Node_Id);
398 -- Check Unchecked_Union variant for lack of nested variants and
399 -- presence of at least one component.
401 procedure Error_Pragma (Msg : String);
402 pragma No_Return (Error_Pragma);
403 -- Outputs error message for current pragma. The message contains an %
404 -- that will be replaced with the pragma name, and the flag is placed
405 -- on the pragma itself. Pragma_Exit is then raised.
407 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
408 pragma No_Return (Error_Pragma_Arg);
409 -- Outputs error message for current pragma. The message may contain
410 -- a % that will be replaced with the pragma name. The parameter Arg
411 -- may either be a pragma argument association, in which case the flag
412 -- is placed on the expression of this association, or an expression,
413 -- in which case the flag is placed directly on the expression. The
414 -- message is placed using Error_Msg_N, so the message may also contain
415 -- an & insertion character which will reference the given Arg value.
416 -- After placing the message, Pragma_Exit is raised.
418 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
419 pragma No_Return (Error_Pragma_Arg);
420 -- Similar to above form of Error_Pragma_Arg except that two messages
421 -- are provided, the second is a continuation comment starting with \.
423 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
424 pragma No_Return (Error_Pragma_Arg_Ident);
425 -- Outputs error message for current pragma. The message may contain
426 -- a % that will be replaced with the pragma name. The parameter Arg
427 -- must be a pragma argument association with a non-empty identifier
428 -- (i.e. its Chars field must be set), and the error message is placed
429 -- on the identifier. The message is placed using Error_Msg_N so
430 -- the message may also contain an & insertion character which will
431 -- reference the identifier. After placing the message, Pragma_Exit
432 -- is raised.
434 function Find_Lib_Unit_Name return Entity_Id;
435 -- Used for a library unit pragma to find the entity to which the
436 -- library unit pragma applies, returns the entity found.
438 procedure Find_Program_Unit_Name (Id : Node_Id);
439 -- If the pragma is a compilation unit pragma, the id must denote the
440 -- compilation unit in the same compilation, and the pragma must appear
441 -- in the list of preceding or trailing pragmas. If it is a program
442 -- unit pragma that is not a compilation unit pragma, then the
443 -- identifier must be visible.
445 type Name_List is array (Natural range <>) of Name_Id;
446 type Args_List is array (Natural range <>) of Node_Id;
447 procedure Gather_Associations
448 (Names : Name_List;
449 Args : out Args_List);
450 -- This procedure is used to gather the arguments for a pragma that
451 -- permits arbitrary ordering of parameters using the normal rules
452 -- for named and positional parameters. The Names argument is a list
453 -- of Name_Id values that corresponds to the allowed pragma argument
454 -- association identifiers in order. The result returned in Args is
455 -- a list of corresponding expressions that are the pragma arguments.
456 -- Note that this is a list of expressions, not of pragma argument
457 -- associations (Gather_Associations has completely checked all the
458 -- optional identifiers when it returns). An entry in Args is Empty
459 -- on return if the corresponding argument is not present.
461 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
462 -- All the routines that check pragma arguments take either a pragma
463 -- argument association (in which case the expression of the argument
464 -- association is checked), or the expression directly. The function
465 -- Get_Pragma_Arg is a utility used to deal with these two cases. If
466 -- Arg is a pragma argument association node, then its expression is
467 -- returned, otherwise Arg is returned unchanged.
469 procedure GNAT_Pragma;
470 -- Called for all GNAT defined pragmas to note the use of the feature,
471 -- and also check the relevant restriction (No_Implementation_Pragmas).
473 function Is_Before_First_Decl
474 (Pragma_Node : Node_Id;
475 Decls : List_Id) return Boolean;
476 -- Return True if Pragma_Node is before the first declarative item in
477 -- Decls where Decls is the list of declarative items.
479 function Is_Configuration_Pragma return Boolean;
480 -- Deterermines if the placement of the current pragma is appropriate
481 -- for a configuration pragma (precedes the current compilation unit)
483 procedure Pragma_Misplaced;
484 -- Issue fatal error message for misplaced pragma
486 procedure Process_Atomic_Shared_Volatile;
487 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
488 -- Shared is an obsolete Ada 83 pragma, treated as being identical
489 -- in effect to pragma Atomic.
491 procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
492 -- Common procesing for Convention, Interface, Import and Export.
493 -- Checks first two arguments of pragma, and sets the appropriate
494 -- convention value in the specified entity or entities. On return
495 -- C is the convention, E is the referenced entity.
497 procedure Process_Extended_Import_Export_Exception_Pragma
498 (Arg_Internal : Node_Id;
499 Arg_External : Node_Id;
500 Arg_Form : Node_Id;
501 Arg_Code : Node_Id);
502 -- Common processing for the pragmas Import/Export_Exception.
503 -- The three arguments correspond to the three named parameters of
504 -- the pragma. An argument is empty if the corresponding parameter
505 -- is not present in the pragma.
507 procedure Process_Extended_Import_Export_Object_Pragma
508 (Arg_Internal : Node_Id;
509 Arg_External : Node_Id;
510 Arg_Size : Node_Id);
511 -- Common processing for the pragmass Import/Export_Object.
512 -- The three arguments correspond to the three named parameters
513 -- of the pragmas. An argument is empty if the corresponding
514 -- parameter is not present in the pragma.
516 procedure Process_Extended_Import_Export_Internal_Arg
517 (Arg_Internal : Node_Id := Empty);
518 -- Common processing for all extended Import and Export pragmas. The
519 -- argument is the pragma parameter for the Internal argument. If
520 -- Arg_Internal is empty or inappropriate, an error message is posted.
521 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
522 -- set to identify the referenced entity.
524 procedure Process_Extended_Import_Export_Subprogram_Pragma
525 (Arg_Internal : Node_Id;
526 Arg_External : Node_Id;
527 Arg_Parameter_Types : Node_Id;
528 Arg_Result_Type : Node_Id := Empty;
529 Arg_Mechanism : Node_Id;
530 Arg_Result_Mechanism : Node_Id := Empty;
531 Arg_First_Optional_Parameter : Node_Id := Empty);
532 -- Common processing for all extended Import and Export pragmas
533 -- applying to subprograms. The caller omits any arguments that do
534 -- bnot apply to the pragma in question (for example, Arg_Result_Type
535 -- can be non-Empty only in the Import_Function and Export_Function
536 -- cases). The argument names correspond to the allowed pragma
537 -- association identifiers.
539 procedure Process_Generic_List;
540 -- Common processing for Share_Generic and Inline_Generic
542 procedure Process_Import_Or_Interface;
543 -- Common processing for Import of Interface
545 procedure Process_Inline (Active : Boolean);
546 -- Common processing for Inline and Inline_Always. The parameter
547 -- indicates if the inline pragma is active, i.e. if it should
548 -- actually cause inlining to occur.
550 procedure Process_Interface_Name
551 (Subprogram_Def : Entity_Id;
552 Ext_Arg : Node_Id;
553 Link_Arg : Node_Id);
554 -- Given the last two arguments of pragma Import, pragma Export, or
555 -- pragma Interface_Name, performs validity checks and sets the
556 -- Interface_Name field of the given subprogram entity to the
557 -- appropriate external or link name, depending on the arguments
558 -- given. Ext_Arg is always present, but Link_Arg may be missing.
559 -- Note that Ext_Arg may represent the Link_Name if Link_Arg is
560 -- missing, and appropriate named notation is used for Ext_Arg.
561 -- If neither Ext_Arg nor Link_Arg is present, the interface name
562 -- is set to the default from the subprogram name.
564 procedure Process_Interrupt_Or_Attach_Handler;
565 -- Common processing for Interrupt and Attach_Handler pragmas
567 procedure Process_Restrictions_Or_Restriction_Warnings;
568 -- Common processing for Restrictions and Restriction_Warnings pragmas
570 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
571 -- Common processing for Suppress and Unsuppress. The boolean parameter
572 -- Suppress_Case is True for the Suppress case, and False for the
573 -- Unsuppress case.
575 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
576 -- This procedure sets the Is_Exported flag for the given entity,
577 -- checking that the entity was not previously imported. Arg is
578 -- the argument that specified the entity. A check is also made
579 -- for exporting inappropriate entities.
581 procedure Set_Extended_Import_Export_External_Name
582 (Internal_Ent : Entity_Id;
583 Arg_External : Node_Id);
584 -- Common processing for all extended import export pragmas. The first
585 -- argument, Internal_Ent, is the internal entity, which has already
586 -- been checked for validity by the caller. Arg_External is from the
587 -- Import or Export pragma, and may be null if no External parameter
588 -- was present. If Arg_External is present and is a non-null string
589 -- (a null string is treated as the default), then the Interface_Name
590 -- field of Internal_Ent is set appropriately.
592 procedure Set_Imported (E : Entity_Id);
593 -- This procedure sets the Is_Imported flag for the given entity,
594 -- checking that it is not previously exported or imported.
596 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
597 -- Mech is a parameter passing mechanism (see Import_Function syntax
598 -- for MECHANISM_NAME). This routine checks that the mechanism argument
599 -- has the right form, and if not issues an error message. If the
600 -- argument has the right form then the Mechanism field of Ent is
601 -- set appropriately.
603 procedure Set_Ravenscar_Profile (N : Node_Id);
604 -- Activate the set of configuration pragmas and restrictions that
605 -- make up the Ravenscar Profile. N is the corresponding pragma
606 -- node, which is used for error messages on any constructs
607 -- that violate the profile.
609 --------------------------
610 -- Check_Ada_83_Warning --
611 --------------------------
613 procedure Check_Ada_83_Warning is
614 begin
615 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
616 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
617 end if;
618 end Check_Ada_83_Warning;
620 ---------------------
621 -- Check_Arg_Count --
622 ---------------------
624 procedure Check_Arg_Count (Required : Nat) is
625 begin
626 if Arg_Count /= Required then
627 Error_Pragma ("wrong number of arguments for pragma%");
628 end if;
629 end Check_Arg_Count;
631 --------------------------------
632 -- Check_Arg_Is_External_Name --
633 --------------------------------
635 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
636 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
638 begin
639 if Nkind (Argx) = N_Identifier then
640 return;
642 else
643 Analyze_And_Resolve (Argx, Standard_String);
645 if Is_OK_Static_Expression (Argx) then
646 return;
648 elsif Etype (Argx) = Any_Type then
649 raise Pragma_Exit;
651 -- An interesting special case, if we have a string literal and
652 -- we are in Ada 83 mode, then we allow it even though it will
653 -- not be flagged as static. This allows expected Ada 83 mode
654 -- use of external names which are string literals, even though
655 -- technically these are not static in Ada 83.
657 elsif Ada_Version = Ada_83
658 and then Nkind (Argx) = N_String_Literal
659 then
660 return;
662 -- Static expression that raises Constraint_Error. This has
663 -- already been flagged, so just exit from pragma processing.
665 elsif Is_Static_Expression (Argx) then
666 raise Pragma_Exit;
668 -- Here we have a real error (non-static expression)
670 else
671 Error_Msg_Name_1 := Chars (N);
672 Flag_Non_Static_Expr
673 ("argument for pragma% must be a identifier or " &
674 "static string expression!", Argx);
675 raise Pragma_Exit;
676 end if;
677 end if;
678 end Check_Arg_Is_External_Name;
680 -----------------------------
681 -- Check_Arg_Is_Identifier --
682 -----------------------------
684 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
685 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
686 begin
687 if Nkind (Argx) /= N_Identifier then
688 Error_Pragma_Arg
689 ("argument for pragma% must be identifier", Argx);
690 end if;
691 end Check_Arg_Is_Identifier;
693 ----------------------------------
694 -- Check_Arg_Is_Integer_Literal --
695 ----------------------------------
697 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
698 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
699 begin
700 if Nkind (Argx) /= N_Integer_Literal then
701 Error_Pragma_Arg
702 ("argument for pragma% must be integer literal", Argx);
703 end if;
704 end Check_Arg_Is_Integer_Literal;
706 -------------------------------------------
707 -- Check_Arg_Is_Library_Level_Local_Name --
708 -------------------------------------------
710 -- LOCAL_NAME ::=
711 -- DIRECT_NAME
712 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
713 -- | library_unit_NAME
715 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
716 begin
717 Check_Arg_Is_Local_Name (Arg);
719 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
720 and then Comes_From_Source (N)
721 then
722 Error_Pragma_Arg
723 ("argument for pragma% must be library level entity", Arg);
724 end if;
725 end Check_Arg_Is_Library_Level_Local_Name;
727 -----------------------------
728 -- Check_Arg_Is_Local_Name --
729 -----------------------------
731 -- LOCAL_NAME ::=
732 -- DIRECT_NAME
733 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
734 -- | library_unit_NAME
736 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
737 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
739 begin
740 Analyze (Argx);
742 if Nkind (Argx) not in N_Direct_Name
743 and then (Nkind (Argx) /= N_Attribute_Reference
744 or else Present (Expressions (Argx))
745 or else Nkind (Prefix (Argx)) /= N_Identifier)
746 and then (not Is_Entity_Name (Argx)
747 or else not Is_Compilation_Unit (Entity (Argx)))
748 then
749 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
750 end if;
752 if Is_Entity_Name (Argx)
753 and then Scope (Entity (Argx)) /= Current_Scope
754 then
755 Error_Pragma_Arg
756 ("pragma% argument must be in same declarative part", Arg);
757 end if;
758 end Check_Arg_Is_Local_Name;
760 ---------------------------------
761 -- Check_Arg_Is_Locking_Policy --
762 ---------------------------------
764 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
765 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
767 begin
768 Check_Arg_Is_Identifier (Argx);
770 if not Is_Locking_Policy_Name (Chars (Argx)) then
771 Error_Pragma_Arg
772 ("& is not a valid locking policy name", Argx);
773 end if;
774 end Check_Arg_Is_Locking_Policy;
776 -------------------------
777 -- Check_Arg_Is_One_Of --
778 -------------------------
780 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
781 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
783 begin
784 Check_Arg_Is_Identifier (Argx);
786 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
787 Error_Msg_Name_2 := N1;
788 Error_Msg_Name_3 := N2;
789 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
790 end if;
791 end Check_Arg_Is_One_Of;
793 procedure Check_Arg_Is_One_Of
794 (Arg : Node_Id;
795 N1, N2, N3 : Name_Id)
797 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
799 begin
800 Check_Arg_Is_Identifier (Argx);
802 if Chars (Argx) /= N1
803 and then Chars (Argx) /= N2
804 and then Chars (Argx) /= N3
805 then
806 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
807 end if;
808 end Check_Arg_Is_One_Of;
810 ---------------------------------
811 -- Check_Arg_Is_Queuing_Policy --
812 ---------------------------------
814 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
815 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
817 begin
818 Check_Arg_Is_Identifier (Argx);
820 if not Is_Queuing_Policy_Name (Chars (Argx)) then
821 Error_Pragma_Arg
822 ("& is not a valid queuing policy name", Argx);
823 end if;
824 end Check_Arg_Is_Queuing_Policy;
826 ------------------------------------
827 -- Check_Arg_Is_Static_Expression --
828 ------------------------------------
830 procedure Check_Arg_Is_Static_Expression
831 (Arg : Node_Id;
832 Typ : Entity_Id)
834 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
836 begin
837 Analyze_And_Resolve (Argx, Typ);
839 if Is_OK_Static_Expression (Argx) then
840 return;
842 elsif Etype (Argx) = Any_Type then
843 raise Pragma_Exit;
845 -- An interesting special case, if we have a string literal and
846 -- we are in Ada 83 mode, then we allow it even though it will
847 -- not be flagged as static. This allows the use of Ada 95
848 -- pragmas like Import in Ada 83 mode. They will of course be
849 -- flagged with warnings as usual, but will not cause errors.
851 elsif Ada_Version = Ada_83
852 and then Nkind (Argx) = N_String_Literal
853 then
854 return;
856 -- Static expression that raises Constraint_Error. This has
857 -- already been flagged, so just exit from pragma processing.
859 elsif Is_Static_Expression (Argx) then
860 raise Pragma_Exit;
862 -- Finally, we have a real error
864 else
865 Error_Msg_Name_1 := Chars (N);
866 Flag_Non_Static_Expr
867 ("argument for pragma% must be a static expression!", Argx);
868 raise Pragma_Exit;
869 end if;
870 end Check_Arg_Is_Static_Expression;
872 ---------------------------------
873 -- Check_Arg_Is_String_Literal --
874 ---------------------------------
876 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
877 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
878 begin
879 if Nkind (Argx) /= N_String_Literal then
880 Error_Pragma_Arg
881 ("argument for pragma% must be string literal", Argx);
882 end if;
883 end Check_Arg_Is_String_Literal;
885 ------------------------------------------
886 -- Check_Arg_Is_Task_Dispatching_Policy --
887 ------------------------------------------
889 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
890 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
892 begin
893 Check_Arg_Is_Identifier (Argx);
895 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
896 Error_Pragma_Arg
897 ("& is not a valid task dispatching policy name", Argx);
898 end if;
899 end Check_Arg_Is_Task_Dispatching_Policy;
901 --------------------------------
902 -- Check_At_Least_N_Arguments --
903 --------------------------------
905 procedure Check_At_Least_N_Arguments (N : Nat) is
906 begin
907 if Arg_Count < N then
908 Error_Pragma ("too few arguments for pragma%");
909 end if;
910 end Check_At_Least_N_Arguments;
912 -------------------------------
913 -- Check_At_Most_N_Arguments --
914 -------------------------------
916 procedure Check_At_Most_N_Arguments (N : Nat) is
917 Arg : Node_Id;
918 begin
919 if Arg_Count > N then
920 Arg := Arg1;
921 for J in 1 .. N loop
922 Next (Arg);
923 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
924 end loop;
925 end if;
926 end Check_At_Most_N_Arguments;
928 ---------------------
929 -- Check_Component --
930 ---------------------
932 procedure Check_Component (Comp : Node_Id) is
933 begin
934 if Nkind (Comp) = N_Component_Declaration then
935 declare
936 Sindic : constant Node_Id :=
937 Subtype_Indication (Component_Definition (Comp));
939 begin
940 if Nkind (Sindic) = N_Subtype_Indication then
942 -- Ada 2005 (AI-216): If a component subtype is subject to
943 -- a per-object constraint, then the component type shall
944 -- be an Unchecked_Union.
946 if Has_Per_Object_Constraint (Defining_Identifier (Comp))
947 and then
948 not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
949 then
950 Error_Msg_N ("component subtype subject to per-object" &
951 " constraint must be an Unchecked_Union", Comp);
952 end if;
953 end if;
954 end;
955 end if;
956 end Check_Component;
958 ----------------------------------
959 -- Check_Duplicated_Export_Name --
960 ----------------------------------
962 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
963 String_Val : constant String_Id := Strval (Nam);
965 begin
966 -- We are only interested in the export case, and in the case of
967 -- generics, it is the instance, not the template, that is the
968 -- problem (the template will generate a warning in any case).
970 if not Inside_A_Generic
971 and then (Prag_Id = Pragma_Export
972 or else
973 Prag_Id = Pragma_Export_Procedure
974 or else
975 Prag_Id = Pragma_Export_Valued_Procedure
976 or else
977 Prag_Id = Pragma_Export_Function)
978 then
979 for J in Externals.First .. Externals.Last loop
980 if String_Equal (String_Val, Strval (Externals.Table (J))) then
981 Error_Msg_Sloc := Sloc (Externals.Table (J));
982 Error_Msg_N ("external name duplicates name given#", Nam);
983 exit;
984 end if;
985 end loop;
987 Externals.Append (Nam);
988 end if;
989 end Check_Duplicated_Export_Name;
991 -------------------------
992 -- Check_First_Subtype --
993 -------------------------
995 procedure Check_First_Subtype (Arg : Node_Id) is
996 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
997 begin
998 if not Is_First_Subtype (Entity (Argx)) then
999 Error_Pragma_Arg
1000 ("pragma% cannot apply to subtype", Argx);
1001 end if;
1002 end Check_First_Subtype;
1004 ---------------------------
1005 -- Check_In_Main_Program --
1006 ---------------------------
1008 procedure Check_In_Main_Program is
1009 P : constant Node_Id := Parent (N);
1011 begin
1012 -- Must be at in subprogram body
1014 if Nkind (P) /= N_Subprogram_Body then
1015 Error_Pragma ("% pragma allowed only in subprogram");
1017 -- Otherwise warn if obviously not main program
1019 elsif Present (Parameter_Specifications (Specification (P)))
1020 or else not Is_Compilation_Unit (Defining_Entity (P))
1021 then
1022 Error_Msg_Name_1 := Chars (N);
1023 Error_Msg_N
1024 ("?pragma% is only effective in main program", N);
1025 end if;
1026 end Check_In_Main_Program;
1028 ---------------------------------------
1029 -- Check_Interrupt_Or_Attach_Handler --
1030 ---------------------------------------
1032 procedure Check_Interrupt_Or_Attach_Handler is
1033 Arg1_X : constant Node_Id := Expression (Arg1);
1035 begin
1036 Analyze (Arg1_X);
1038 if not Is_Entity_Name (Arg1_X) then
1039 Error_Pragma_Arg
1040 ("argument of pragma% must be entity name", Arg1);
1042 elsif Prag_Id = Pragma_Interrupt_Handler then
1043 Check_Restriction (No_Dynamic_Attachment, N);
1044 end if;
1046 declare
1047 Handler_Proc : Entity_Id := Empty;
1048 Proc_Scope : Entity_Id;
1049 Found : Boolean := False;
1051 begin
1052 if not Is_Overloaded (Arg1_X) then
1053 Handler_Proc := Entity (Arg1_X);
1055 else
1056 declare
1057 It : Interp;
1058 Index : Interp_Index;
1060 begin
1061 Get_First_Interp (Arg1_X, Index, It);
1062 while Present (It.Nam) loop
1063 Handler_Proc := It.Nam;
1065 if Ekind (Handler_Proc) = E_Procedure
1066 and then No (First_Formal (Handler_Proc))
1067 then
1068 if not Found then
1069 Found := True;
1070 Set_Entity (Arg1_X, Handler_Proc);
1071 Set_Is_Overloaded (Arg1_X, False);
1072 else
1073 Error_Pragma_Arg
1074 ("ambiguous handler name for pragma% ", Arg1);
1075 end if;
1076 end if;
1078 Get_Next_Interp (Index, It);
1079 end loop;
1081 if not Found then
1082 Error_Pragma_Arg
1083 ("argument of pragma% must be parameterless procedure",
1084 Arg1);
1085 else
1086 Handler_Proc := Entity (Arg1_X);
1087 end if;
1088 end;
1089 end if;
1091 Proc_Scope := Scope (Handler_Proc);
1093 -- On AAMP only, a pragma Interrupt_Handler is supported for
1094 -- nonprotected parameterless procedures.
1096 if AAMP_On_Target
1097 and then Prag_Id = Pragma_Interrupt_Handler
1098 then
1099 if Ekind (Handler_Proc) /= E_Procedure then
1100 Error_Pragma_Arg
1101 ("argument of pragma% must be a procedure", Arg1);
1102 end if;
1104 elsif Ekind (Handler_Proc) /= E_Procedure
1105 or else Ekind (Proc_Scope) /= E_Protected_Type
1106 then
1107 Error_Pragma_Arg
1108 ("argument of pragma% must be protected procedure", Arg1);
1109 end if;
1111 if (not AAMP_On_Target or else Prag_Id = Pragma_Attach_Handler)
1112 and then Ekind (Proc_Scope) = E_Protected_Type
1113 then
1114 if Parent (N) /=
1115 Protected_Definition (Parent (Proc_Scope))
1116 then
1117 Error_Pragma ("pragma% must be in protected definition");
1118 end if;
1119 end if;
1121 if not Is_Library_Level_Entity (Proc_Scope)
1122 or else (AAMP_On_Target
1123 and then not Is_Library_Level_Entity (Handler_Proc))
1124 then
1125 Error_Pragma_Arg
1126 ("pragma% requires library-level entity", Arg1);
1127 end if;
1129 if Present (First_Formal (Handler_Proc)) then
1130 Error_Pragma_Arg
1131 ("argument of pragma% must be parameterless procedure",
1132 Arg1);
1133 end if;
1134 end;
1135 end Check_Interrupt_Or_Attach_Handler;
1137 -------------------------------------------
1138 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1139 -------------------------------------------
1141 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1142 P : Node_Id;
1144 begin
1145 P := Parent (N);
1146 loop
1147 if No (P) then
1148 exit;
1150 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1151 exit;
1153 elsif Nkind (P) = N_Package_Specification then
1154 return;
1156 elsif Nkind (P) = N_Block_Statement then
1157 return;
1159 -- Note: the following tests seem a little peculiar, because
1160 -- they test for bodies, but if we were in the statement part
1161 -- of the body, we would already have hit the handled statement
1162 -- sequence, so the only way we get here is by being in the
1163 -- declarative part of the body.
1165 elsif Nkind (P) = N_Subprogram_Body
1166 or else Nkind (P) = N_Package_Body
1167 or else Nkind (P) = N_Task_Body
1168 or else Nkind (P) = N_Entry_Body
1169 then
1170 return;
1171 end if;
1173 P := Parent (P);
1174 end loop;
1176 Error_Pragma ("pragma% is not in declarative part or package spec");
1177 end Check_Is_In_Decl_Part_Or_Package_Spec;
1179 -------------------------
1180 -- Check_No_Identifier --
1181 -------------------------
1183 procedure Check_No_Identifier (Arg : Node_Id) is
1184 begin
1185 if Chars (Arg) /= No_Name then
1186 Error_Pragma_Arg_Ident
1187 ("pragma% does not permit identifier& here", Arg);
1188 end if;
1189 end Check_No_Identifier;
1191 --------------------------
1192 -- Check_No_Identifiers --
1193 --------------------------
1195 procedure Check_No_Identifiers is
1196 Arg_Node : Node_Id;
1197 begin
1198 if Arg_Count > 0 then
1199 Arg_Node := Arg1;
1200 while Present (Arg_Node) loop
1201 Check_No_Identifier (Arg_Node);
1202 Next (Arg_Node);
1203 end loop;
1204 end if;
1205 end Check_No_Identifiers;
1207 -------------------------------
1208 -- Check_Optional_Identifier --
1209 -------------------------------
1211 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1212 begin
1213 if Present (Arg) and then Chars (Arg) /= No_Name then
1214 if Chars (Arg) /= Id then
1215 Error_Msg_Name_1 := Chars (N);
1216 Error_Msg_Name_2 := Id;
1217 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1218 raise Pragma_Exit;
1219 end if;
1220 end if;
1221 end Check_Optional_Identifier;
1223 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1224 begin
1225 Name_Buffer (1 .. Id'Length) := Id;
1226 Name_Len := Id'Length;
1227 Check_Optional_Identifier (Arg, Name_Find);
1228 end Check_Optional_Identifier;
1230 -----------------------------
1231 -- Check_Static_Constraint --
1232 -----------------------------
1234 -- Note: for convenience in writing this procedure, in addition to
1235 -- the officially (i.e. by spec) allowed argument which is always
1236 -- a constraint, it also allows ranges and discriminant associations.
1237 -- Above is not clear ???
1239 procedure Check_Static_Constraint (Constr : Node_Id) is
1241 --------------------
1242 -- Require_Static --
1243 --------------------
1245 procedure Require_Static (E : Node_Id);
1246 -- Require given expression to be static expression
1248 procedure Require_Static (E : Node_Id) is
1249 begin
1250 if not Is_OK_Static_Expression (E) then
1251 Flag_Non_Static_Expr
1252 ("non-static constraint not allowed in Unchecked_Union!", E);
1253 raise Pragma_Exit;
1254 end if;
1255 end Require_Static;
1257 -- Start of processing for Check_Static_Constraint
1259 begin
1260 case Nkind (Constr) is
1261 when N_Discriminant_Association =>
1262 Require_Static (Expression (Constr));
1264 when N_Range =>
1265 Require_Static (Low_Bound (Constr));
1266 Require_Static (High_Bound (Constr));
1268 when N_Attribute_Reference =>
1269 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1270 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1272 when N_Range_Constraint =>
1273 Check_Static_Constraint (Range_Expression (Constr));
1275 when N_Index_Or_Discriminant_Constraint =>
1276 declare
1277 IDC : Entity_Id;
1278 begin
1279 IDC := First (Constraints (Constr));
1280 while Present (IDC) loop
1281 Check_Static_Constraint (IDC);
1282 Next (IDC);
1283 end loop;
1284 end;
1286 when others =>
1287 null;
1288 end case;
1289 end Check_Static_Constraint;
1291 --------------------------------------
1292 -- Check_Valid_Configuration_Pragma --
1293 --------------------------------------
1295 -- A configuration pragma must appear in the context clause of
1296 -- a compilation unit, at the start of the list (i.e. only other
1297 -- pragmas may precede it).
1299 procedure Check_Valid_Configuration_Pragma is
1300 begin
1301 if not Is_Configuration_Pragma then
1302 Error_Pragma ("incorrect placement for configuration pragma%");
1303 end if;
1304 end Check_Valid_Configuration_Pragma;
1306 -------------------------------------
1307 -- Check_Valid_Library_Unit_Pragma --
1308 -------------------------------------
1310 procedure Check_Valid_Library_Unit_Pragma is
1311 Plist : List_Id;
1312 Parent_Node : Node_Id;
1313 Unit_Name : Entity_Id;
1314 Unit_Kind : Node_Kind;
1315 Unit_Node : Node_Id;
1316 Sindex : Source_File_Index;
1318 begin
1319 if not Is_List_Member (N) then
1320 Pragma_Misplaced;
1322 else
1323 Plist := List_Containing (N);
1324 Parent_Node := Parent (Plist);
1326 if Parent_Node = Empty then
1327 Pragma_Misplaced;
1329 -- Case of pragma appearing after a compilation unit. In this
1330 -- case it must have an argument with the corresponding name
1331 -- and must be part of the following pragmas of its parent.
1333 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1334 if Plist /= Pragmas_After (Parent_Node) then
1335 Pragma_Misplaced;
1337 elsif Arg_Count = 0 then
1338 Error_Pragma
1339 ("argument required if outside compilation unit");
1341 else
1342 Check_No_Identifiers;
1343 Check_Arg_Count (1);
1344 Unit_Node := Unit (Parent (Parent_Node));
1345 Unit_Kind := Nkind (Unit_Node);
1347 Analyze (Expression (Arg1));
1349 if Unit_Kind = N_Generic_Subprogram_Declaration
1350 or else Unit_Kind = N_Subprogram_Declaration
1351 then
1352 Unit_Name := Defining_Entity (Unit_Node);
1354 elsif Unit_Kind = N_Function_Instantiation
1355 or else Unit_Kind = N_Package_Instantiation
1356 or else Unit_Kind = N_Procedure_Instantiation
1357 then
1358 Unit_Name := Defining_Entity (Unit_Node);
1360 else
1361 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1362 end if;
1364 if Chars (Unit_Name) /=
1365 Chars (Entity (Expression (Arg1)))
1366 then
1367 Error_Pragma_Arg
1368 ("pragma% argument is not current unit name", Arg1);
1369 end if;
1371 if Ekind (Unit_Name) = E_Package
1372 and then Present (Renamed_Entity (Unit_Name))
1373 then
1374 Error_Pragma ("pragma% not allowed for renamed package");
1375 end if;
1376 end if;
1378 -- Pragma appears other than after a compilation unit
1380 else
1381 -- Here we check for the generic instantiation case and also
1382 -- for the case of processing a generic formal package. We
1383 -- detect these cases by noting that the Sloc on the node
1384 -- does not belong to the current compilation unit.
1386 Sindex := Source_Index (Current_Sem_Unit);
1388 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1389 Rewrite (N, Make_Null_Statement (Loc));
1390 return;
1392 -- If before first declaration, the pragma applies to the
1393 -- enclosing unit, and the name if present must be this name.
1395 elsif Is_Before_First_Decl (N, Plist) then
1396 Unit_Node := Unit_Declaration_Node (Current_Scope);
1397 Unit_Kind := Nkind (Unit_Node);
1399 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1400 Pragma_Misplaced;
1402 elsif Unit_Kind = N_Subprogram_Body
1403 and then not Acts_As_Spec (Unit_Node)
1404 then
1405 Pragma_Misplaced;
1407 elsif Nkind (Parent_Node) = N_Package_Body then
1408 Pragma_Misplaced;
1410 elsif Nkind (Parent_Node) = N_Package_Specification
1411 and then Plist = Private_Declarations (Parent_Node)
1412 then
1413 Pragma_Misplaced;
1415 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1416 or else Nkind (Parent_Node)
1417 = N_Generic_Subprogram_Declaration)
1418 and then Plist = Generic_Formal_Declarations (Parent_Node)
1419 then
1420 Pragma_Misplaced;
1422 elsif Arg_Count > 0 then
1423 Analyze (Expression (Arg1));
1425 if Entity (Expression (Arg1)) /= Current_Scope then
1426 Error_Pragma_Arg
1427 ("name in pragma% must be enclosing unit", Arg1);
1428 end if;
1430 -- It is legal to have no argument in this context
1432 else
1433 return;
1434 end if;
1436 -- Error if not before first declaration. This is because a
1437 -- library unit pragma argument must be the name of a library
1438 -- unit (RM 10.1.5(7)), but the only names permitted in this
1439 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1440 -- generic subprogram declarations or generic instantiations.
1442 else
1443 Error_Pragma
1444 ("pragma% misplaced, must be before first declaration");
1445 end if;
1446 end if;
1447 end if;
1448 end Check_Valid_Library_Unit_Pragma;
1450 -------------------
1451 -- Check_Variant --
1452 -------------------
1454 procedure Check_Variant (Variant : Node_Id) is
1455 Clist : constant Node_Id := Component_List (Variant);
1456 Comp : Node_Id;
1458 begin
1459 if Present (Variant_Part (Clist)) then
1460 Error_Msg_N
1461 ("Unchecked_Union may not have nested variants",
1462 Variant_Part (Clist));
1463 end if;
1465 if not Is_Non_Empty_List (Component_Items (Clist)) then
1466 Error_Msg_N
1467 ("Unchecked_Union may not have empty component list",
1468 Variant);
1469 return;
1470 end if;
1472 Comp := First (Component_Items (Clist));
1473 while Present (Comp) loop
1474 Check_Component (Comp);
1475 Next (Comp);
1476 end loop;
1477 end Check_Variant;
1479 ------------------
1480 -- Error_Pragma --
1481 ------------------
1483 procedure Error_Pragma (Msg : String) is
1484 begin
1485 Error_Msg_Name_1 := Chars (N);
1486 Error_Msg_N (Msg, N);
1487 raise Pragma_Exit;
1488 end Error_Pragma;
1490 ----------------------
1491 -- Error_Pragma_Arg --
1492 ----------------------
1494 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1495 begin
1496 Error_Msg_Name_1 := Chars (N);
1497 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1498 raise Pragma_Exit;
1499 end Error_Pragma_Arg;
1501 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1502 begin
1503 Error_Msg_Name_1 := Chars (N);
1504 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1505 Error_Pragma_Arg (Msg2, Arg);
1506 end Error_Pragma_Arg;
1508 ----------------------------
1509 -- Error_Pragma_Arg_Ident --
1510 ----------------------------
1512 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1513 begin
1514 Error_Msg_Name_1 := Chars (N);
1515 Error_Msg_N (Msg, Arg);
1516 raise Pragma_Exit;
1517 end Error_Pragma_Arg_Ident;
1519 ------------------------
1520 -- Find_Lib_Unit_Name --
1521 ------------------------
1523 function Find_Lib_Unit_Name return Entity_Id is
1524 begin
1525 -- Return inner compilation unit entity, for case of nested
1526 -- categorization pragmas. This happens in generic unit.
1528 if Nkind (Parent (N)) = N_Package_Specification
1529 and then Defining_Entity (Parent (N)) /= Current_Scope
1530 then
1531 return Defining_Entity (Parent (N));
1532 else
1533 return Current_Scope;
1534 end if;
1535 end Find_Lib_Unit_Name;
1537 ----------------------------
1538 -- Find_Program_Unit_Name --
1539 ----------------------------
1541 procedure Find_Program_Unit_Name (Id : Node_Id) is
1542 Unit_Name : Entity_Id;
1543 Unit_Kind : Node_Kind;
1544 P : constant Node_Id := Parent (N);
1546 begin
1547 if Nkind (P) = N_Compilation_Unit then
1548 Unit_Kind := Nkind (Unit (P));
1550 if Unit_Kind = N_Subprogram_Declaration
1551 or else Unit_Kind = N_Package_Declaration
1552 or else Unit_Kind in N_Generic_Declaration
1553 then
1554 Unit_Name := Defining_Entity (Unit (P));
1556 if Chars (Id) = Chars (Unit_Name) then
1557 Set_Entity (Id, Unit_Name);
1558 Set_Etype (Id, Etype (Unit_Name));
1559 else
1560 Set_Etype (Id, Any_Type);
1561 Error_Pragma
1562 ("cannot find program unit referenced by pragma%");
1563 end if;
1565 else
1566 Set_Etype (Id, Any_Type);
1567 Error_Pragma ("pragma% inapplicable to this unit");
1568 end if;
1570 else
1571 Analyze (Id);
1572 end if;
1574 end Find_Program_Unit_Name;
1576 -------------------------
1577 -- Gather_Associations --
1578 -------------------------
1580 procedure Gather_Associations
1581 (Names : Name_List;
1582 Args : out Args_List)
1584 Arg : Node_Id;
1586 begin
1587 -- Initialize all parameters to Empty
1589 for J in Args'Range loop
1590 Args (J) := Empty;
1591 end loop;
1593 -- That's all we have to do if there are no argument associations
1595 if No (Pragma_Argument_Associations (N)) then
1596 return;
1597 end if;
1599 -- Otherwise first deal with any positional parameters present
1601 Arg := First (Pragma_Argument_Associations (N));
1602 for Index in Args'Range loop
1603 exit when No (Arg) or else Chars (Arg) /= No_Name;
1604 Args (Index) := Expression (Arg);
1605 Next (Arg);
1606 end loop;
1608 -- Positional parameters all processed, if any left, then we
1609 -- have too many positional parameters.
1611 if Present (Arg) and then Chars (Arg) = No_Name then
1612 Error_Pragma_Arg
1613 ("too many positional associations for pragma%", Arg);
1614 end if;
1616 -- Process named parameters if any are present
1618 while Present (Arg) loop
1619 if Chars (Arg) = No_Name then
1620 Error_Pragma_Arg
1621 ("positional association cannot follow named association",
1622 Arg);
1624 else
1625 for Index in Names'Range loop
1626 if Names (Index) = Chars (Arg) then
1627 if Present (Args (Index)) then
1628 Error_Pragma_Arg
1629 ("duplicate argument association for pragma%", Arg);
1630 else
1631 Args (Index) := Expression (Arg);
1632 exit;
1633 end if;
1634 end if;
1636 if Index = Names'Last then
1637 Error_Msg_Name_1 := Chars (N);
1638 Error_Msg_N ("pragma% does not allow & argument", Arg);
1640 -- Check for possible misspelling
1642 for Index1 in Names'Range loop
1643 if Is_Bad_Spelling_Of
1644 (Get_Name_String (Chars (Arg)),
1645 Get_Name_String (Names (Index1)))
1646 then
1647 Error_Msg_Name_1 := Names (Index1);
1648 Error_Msg_N ("\possible misspelling of%", Arg);
1649 exit;
1650 end if;
1651 end loop;
1653 raise Pragma_Exit;
1654 end if;
1655 end loop;
1656 end if;
1658 Next (Arg);
1659 end loop;
1660 end Gather_Associations;
1662 --------------------
1663 -- Get_Pragma_Arg --
1664 --------------------
1666 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
1667 begin
1668 if Nkind (Arg) = N_Pragma_Argument_Association then
1669 return Expression (Arg);
1670 else
1671 return Arg;
1672 end if;
1673 end Get_Pragma_Arg;
1675 -----------------
1676 -- GNAT_Pragma --
1677 -----------------
1679 procedure GNAT_Pragma is
1680 begin
1681 Check_Restriction (No_Implementation_Pragmas, N);
1682 end GNAT_Pragma;
1684 --------------------------
1685 -- Is_Before_First_Decl --
1686 --------------------------
1688 function Is_Before_First_Decl
1689 (Pragma_Node : Node_Id;
1690 Decls : List_Id) return Boolean
1692 Item : Node_Id := First (Decls);
1694 begin
1695 -- Only other pragmas can come before this pragma
1697 loop
1698 if No (Item) or else Nkind (Item) /= N_Pragma then
1699 return False;
1701 elsif Item = Pragma_Node then
1702 return True;
1703 end if;
1705 Next (Item);
1706 end loop;
1707 end Is_Before_First_Decl;
1709 -----------------------------
1710 -- Is_Configuration_Pragma --
1711 -----------------------------
1713 -- A configuration pragma must appear in the context clause of
1714 -- a compilation unit, at the start of the list (i.e. only other
1715 -- pragmas may precede it).
1717 function Is_Configuration_Pragma return Boolean is
1718 Lis : constant List_Id := List_Containing (N);
1719 Par : constant Node_Id := Parent (N);
1720 Prg : Node_Id;
1722 begin
1723 -- If no parent, then we are in the configuration pragma file,
1724 -- so the placement is definitely appropriate.
1726 if No (Par) then
1727 return True;
1729 -- Otherwise we must be in the context clause of a compilation unit
1730 -- and the only thing allowed before us in the context list is more
1731 -- configuration pragmas.
1733 elsif Nkind (Par) = N_Compilation_Unit
1734 and then Context_Items (Par) = Lis
1735 then
1736 Prg := First (Lis);
1738 loop
1739 if Prg = N then
1740 return True;
1741 elsif Nkind (Prg) /= N_Pragma then
1742 return False;
1743 end if;
1745 Next (Prg);
1746 end loop;
1748 else
1749 return False;
1750 end if;
1751 end Is_Configuration_Pragma;
1753 ----------------------
1754 -- Pragma_Misplaced --
1755 ----------------------
1757 procedure Pragma_Misplaced is
1758 begin
1759 Error_Pragma ("incorrect placement of pragma%");
1760 end Pragma_Misplaced;
1762 ------------------------------------
1763 -- Process Atomic_Shared_Volatile --
1764 ------------------------------------
1766 procedure Process_Atomic_Shared_Volatile is
1767 E_Id : Node_Id;
1768 E : Entity_Id;
1769 D : Node_Id;
1770 K : Node_Kind;
1771 Utyp : Entity_Id;
1773 procedure Set_Atomic (E : Entity_Id);
1774 -- Set given type as atomic, and if no explicit alignment was
1775 -- given, set alignment to unknown, since back end knows what
1776 -- the alignment requirements are for atomic arrays. Note that
1777 -- this step is necessary for derived types.
1779 ----------------
1780 -- Set_Atomic --
1781 ----------------
1783 procedure Set_Atomic (E : Entity_Id) is
1784 begin
1785 Set_Is_Atomic (E);
1787 if not Has_Alignment_Clause (E) then
1788 Set_Alignment (E, Uint_0);
1789 end if;
1790 end Set_Atomic;
1792 -- Start of processing for Process_Atomic_Shared_Volatile
1794 begin
1795 Check_Ada_83_Warning;
1796 Check_No_Identifiers;
1797 Check_Arg_Count (1);
1798 Check_Arg_Is_Local_Name (Arg1);
1799 E_Id := Expression (Arg1);
1801 if Etype (E_Id) = Any_Type then
1802 return;
1803 end if;
1805 E := Entity (E_Id);
1806 D := Declaration_Node (E);
1807 K := Nkind (D);
1809 if Is_Type (E) then
1810 if Rep_Item_Too_Early (E, N)
1811 or else
1812 Rep_Item_Too_Late (E, N)
1813 then
1814 return;
1815 else
1816 Check_First_Subtype (Arg1);
1817 end if;
1819 if Prag_Id /= Pragma_Volatile then
1820 Set_Atomic (E);
1821 Set_Atomic (Underlying_Type (E));
1822 Set_Atomic (Base_Type (E));
1823 end if;
1825 -- Attribute belongs on the base type. If the
1826 -- view of the type is currently private, it also
1827 -- belongs on the underlying type.
1829 Set_Is_Volatile (Base_Type (E));
1830 Set_Is_Volatile (Underlying_Type (E));
1832 Set_Treat_As_Volatile (E);
1833 Set_Treat_As_Volatile (Underlying_Type (E));
1835 elsif K = N_Object_Declaration
1836 or else (K = N_Component_Declaration
1837 and then Original_Record_Component (E) = E)
1838 then
1839 if Rep_Item_Too_Late (E, N) then
1840 return;
1841 end if;
1843 if Prag_Id /= Pragma_Volatile then
1844 Set_Is_Atomic (E);
1846 -- If the object declaration has an explicit
1847 -- initialization, a temporary may have to be
1848 -- created to hold the expression, to insure
1849 -- that access to the object remain atomic.
1851 if Nkind (Parent (E)) = N_Object_Declaration
1852 and then Present (Expression (Parent (E)))
1853 then
1854 Set_Has_Delayed_Freeze (E);
1855 end if;
1857 -- An interesting improvement here. If an object of type X
1858 -- is declared atomic, and the type X is not atomic, that's
1859 -- a pity, since it may not have appropraite alignment etc.
1860 -- We can rescue this in the special case where the object
1861 -- and type are in the same unit by just setting the type
1862 -- as atomic, so that the back end will process it as atomic.
1864 Utyp := Underlying_Type (Etype (E));
1866 if Present (Utyp)
1867 and then Sloc (E) > No_Location
1868 and then Sloc (Utyp) > No_Location
1869 and then
1870 Get_Source_File_Index (Sloc (E)) =
1871 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
1872 then
1873 Set_Is_Atomic (Underlying_Type (Etype (E)));
1874 end if;
1875 end if;
1877 Set_Is_Volatile (E);
1878 Set_Treat_As_Volatile (E);
1880 else
1881 Error_Pragma_Arg
1882 ("inappropriate entity for pragma%", Arg1);
1883 end if;
1884 end Process_Atomic_Shared_Volatile;
1886 ------------------------
1887 -- Process_Convention --
1888 ------------------------
1890 procedure Process_Convention
1891 (C : out Convention_Id;
1892 E : out Entity_Id)
1894 Id : Node_Id;
1895 E1 : Entity_Id;
1896 Cname : Name_Id;
1897 Comp_Unit : Unit_Number_Type;
1899 procedure Set_Convention_From_Pragma (E : Entity_Id);
1900 -- Set convention in entity E, and also flag that the entity has a
1901 -- convention pragma. If entity is for a private or incomplete type,
1902 -- also set convention and flag on underlying type. This procedure
1903 -- also deals with the special case of C_Pass_By_Copy convention.
1905 --------------------------------
1906 -- Set_Convention_From_Pragma --
1907 --------------------------------
1909 procedure Set_Convention_From_Pragma (E : Entity_Id) is
1910 begin
1911 Set_Convention (E, C);
1912 Set_Has_Convention_Pragma (E);
1914 if Is_Incomplete_Or_Private_Type (E) then
1915 Set_Convention (Underlying_Type (E), C);
1916 Set_Has_Convention_Pragma (Underlying_Type (E), True);
1917 end if;
1919 -- A class-wide type should inherit the convention of
1920 -- the specific root type (although this isn't specified
1921 -- clearly by the RM).
1923 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
1924 Set_Convention (Class_Wide_Type (E), C);
1925 end if;
1927 -- If the entity is a record type, then check for special case
1928 -- of C_Pass_By_Copy, which is treated the same as C except that
1929 -- the special record flag is set. This convention is also only
1930 -- permitted on record types (see AI95-00131).
1932 if Cname = Name_C_Pass_By_Copy then
1933 if Is_Record_Type (E) then
1934 Set_C_Pass_By_Copy (Base_Type (E));
1935 elsif Is_Incomplete_Or_Private_Type (E)
1936 and then Is_Record_Type (Underlying_Type (E))
1937 then
1938 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
1939 else
1940 Error_Pragma_Arg
1941 ("C_Pass_By_Copy convention allowed only for record type",
1942 Arg2);
1943 end if;
1944 end if;
1946 -- If the entity is a derived boolean type, check for the
1947 -- special case of convention C, C++, or Fortran, where we
1948 -- consider any nonzero value to represent true.
1950 if Is_Discrete_Type (E)
1951 and then Root_Type (Etype (E)) = Standard_Boolean
1952 and then
1953 (C = Convention_C
1954 or else
1955 C = Convention_CPP
1956 or else
1957 C = Convention_Fortran)
1958 then
1959 Set_Nonzero_Is_True (Base_Type (E));
1960 end if;
1961 end Set_Convention_From_Pragma;
1963 -- Start of processing for Process_Convention
1965 begin
1966 Check_At_Least_N_Arguments (2);
1967 Check_Arg_Is_Identifier (Arg1);
1968 Check_Optional_Identifier (Arg1, Name_Convention);
1969 Cname := Chars (Expression (Arg1));
1971 -- C_Pass_By_Copy is treated as a synonym for convention C
1972 -- (this is tested again below to set the critical flag)
1974 if Cname = Name_C_Pass_By_Copy then
1975 C := Convention_C;
1977 -- Otherwise we must have something in the standard convention list
1979 elsif Is_Convention_Name (Cname) then
1980 C := Get_Convention_Id (Chars (Expression (Arg1)));
1982 -- In DEC VMS, it seems that there is an undocumented feature
1983 -- that any unrecognized convention is treated as the default,
1984 -- which for us is convention C. It does not seem so terrible
1985 -- to do this unconditionally, silently in the VMS case, and
1986 -- with a warning in the non-VMS case.
1988 else
1989 if Warn_On_Export_Import and not OpenVMS_On_Target then
1990 Error_Msg_N
1991 ("?unrecognized convention name, C assumed",
1992 Expression (Arg1));
1993 end if;
1995 C := Convention_C;
1996 end if;
1998 Check_Arg_Is_Local_Name (Arg2);
1999 Check_Optional_Identifier (Arg2, Name_Entity);
2001 Id := Expression (Arg2);
2002 Analyze (Id);
2004 if not Is_Entity_Name (Id) then
2005 Error_Pragma_Arg ("entity name required", Arg2);
2006 end if;
2008 E := Entity (Id);
2010 -- Go to renamed subprogram if present, since convention applies
2011 -- to the actual renamed entity, not to the renaming entity.
2012 -- If subprogram is inherited, go to parent subprogram.
2014 if Is_Subprogram (E)
2015 and then Present (Alias (E))
2016 then
2017 if Nkind (Parent (Declaration_Node (E)))
2018 = N_Subprogram_Renaming_Declaration
2019 then
2020 E := Alias (E);
2022 elsif Nkind (Parent (E)) = N_Full_Type_Declaration
2023 and then Scope (E) = Scope (Alias (E))
2024 then
2025 E := Alias (E);
2026 end if;
2027 end if;
2029 -- Check that we are not applying this to a specless body
2031 if Is_Subprogram (E)
2032 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2033 then
2034 Error_Pragma
2035 ("pragma% requires separate spec and must come before body");
2036 end if;
2038 -- Check that we are not applying this to a named constant
2040 if Ekind (E) = E_Named_Integer
2041 or else
2042 Ekind (E) = E_Named_Real
2043 then
2044 Error_Msg_Name_1 := Chars (N);
2045 Error_Msg_N
2046 ("cannot apply pragma% to named constant!",
2047 Get_Pragma_Arg (Arg2));
2048 Error_Pragma_Arg
2049 ("\supply appropriate type for&!", Arg2);
2050 end if;
2052 if Etype (E) = Any_Type
2053 or else Rep_Item_Too_Early (E, N)
2054 then
2055 raise Pragma_Exit;
2056 else
2057 E := Underlying_Type (E);
2058 end if;
2060 if Rep_Item_Too_Late (E, N) then
2061 raise Pragma_Exit;
2062 end if;
2064 if Has_Convention_Pragma (E) then
2065 Error_Pragma_Arg
2066 ("at most one Convention/Export/Import pragma is allowed", Arg2);
2068 elsif Convention (E) = Convention_Protected
2069 or else Ekind (Scope (E)) = E_Protected_Type
2070 then
2071 Error_Pragma_Arg
2072 ("a protected operation cannot be given a different convention",
2073 Arg2);
2074 end if;
2076 -- For Intrinsic, a subprogram is required
2078 if C = Convention_Intrinsic
2079 and then not Is_Subprogram (E)
2080 and then not Is_Generic_Subprogram (E)
2081 then
2082 Error_Pragma_Arg
2083 ("second argument of pragma% must be a subprogram", Arg2);
2084 end if;
2086 -- For Stdcall, a subprogram, variable or subprogram type is required
2088 if C = Convention_Stdcall
2089 and then not Is_Subprogram (E)
2090 and then not Is_Generic_Subprogram (E)
2091 and then Ekind (E) /= E_Variable
2092 and then not
2093 (Is_Access_Type (E)
2094 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2095 then
2096 Error_Pragma_Arg
2097 ("second argument of pragma% must be subprogram (type)",
2098 Arg2);
2099 end if;
2101 if not Is_Subprogram (E)
2102 and then not Is_Generic_Subprogram (E)
2103 then
2104 Set_Convention_From_Pragma (E);
2106 if Is_Type (E) then
2108 Check_First_Subtype (Arg2);
2109 Set_Convention_From_Pragma (Base_Type (E));
2111 -- For subprograms, we must set the convention on the
2112 -- internally generated directly designated type as well.
2114 if Ekind (E) = E_Access_Subprogram_Type then
2115 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2116 end if;
2117 end if;
2119 -- For the subprogram case, set proper convention for all homonyms
2120 -- in same scope and the same declarative part, i.e. the same
2121 -- compilation unit.
2123 else
2124 Comp_Unit := Get_Source_Unit (E);
2125 Set_Convention_From_Pragma (E);
2127 -- Treat a pragma Import as an implicit body, for GPS use.
2129 if Prag_Id = Pragma_Import then
2130 Generate_Reference (E, Id, 'b');
2131 end if;
2133 E1 := E;
2134 loop
2135 E1 := Homonym (E1);
2136 exit when No (E1) or else Scope (E1) /= Current_Scope;
2138 -- Note: below we are missing a check for Rep_Item_Too_Late.
2139 -- That is deliberate, we cannot chain the rep item on more
2140 -- than one Rep_Item chain, to be fixed later ???
2142 if Comes_From_Source (E1)
2143 and then Comp_Unit = Get_Source_Unit (E1)
2144 and then Nkind (Original_Node (Parent (E1))) /=
2145 N_Full_Type_Declaration
2146 then
2147 Set_Convention_From_Pragma (E1);
2149 if Prag_Id = Pragma_Import then
2150 Generate_Reference (E, Id, 'b');
2151 end if;
2152 end if;
2153 end loop;
2154 end if;
2155 end Process_Convention;
2157 -----------------------------------------------------
2158 -- Process_Extended_Import_Export_Exception_Pragma --
2159 -----------------------------------------------------
2161 procedure Process_Extended_Import_Export_Exception_Pragma
2162 (Arg_Internal : Node_Id;
2163 Arg_External : Node_Id;
2164 Arg_Form : Node_Id;
2165 Arg_Code : Node_Id)
2167 Def_Id : Entity_Id;
2168 Code_Val : Uint;
2170 begin
2171 GNAT_Pragma;
2173 if not OpenVMS_On_Target then
2174 Error_Pragma
2175 ("?pragma% ignored (applies only to Open'V'M'S)");
2176 end if;
2178 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2179 Def_Id := Entity (Arg_Internal);
2181 if Ekind (Def_Id) /= E_Exception then
2182 Error_Pragma_Arg
2183 ("pragma% must refer to declared exception", Arg_Internal);
2184 end if;
2186 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2188 if Present (Arg_Form) then
2189 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2190 end if;
2192 if Present (Arg_Form)
2193 and then Chars (Arg_Form) = Name_Ada
2194 then
2195 null;
2196 else
2197 Set_Is_VMS_Exception (Def_Id);
2198 Set_Exception_Code (Def_Id, No_Uint);
2199 end if;
2201 if Present (Arg_Code) then
2202 if not Is_VMS_Exception (Def_Id) then
2203 Error_Pragma_Arg
2204 ("Code option for pragma% not allowed for Ada case",
2205 Arg_Code);
2206 end if;
2208 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2209 Code_Val := Expr_Value (Arg_Code);
2211 if not UI_Is_In_Int_Range (Code_Val) then
2212 Error_Pragma_Arg
2213 ("Code option for pragma% must be in 32-bit range",
2214 Arg_Code);
2216 else
2217 Set_Exception_Code (Def_Id, Code_Val);
2218 end if;
2219 end if;
2220 end Process_Extended_Import_Export_Exception_Pragma;
2222 -------------------------------------------------
2223 -- Process_Extended_Import_Export_Internal_Arg --
2224 -------------------------------------------------
2226 procedure Process_Extended_Import_Export_Internal_Arg
2227 (Arg_Internal : Node_Id := Empty)
2229 begin
2230 GNAT_Pragma;
2232 if No (Arg_Internal) then
2233 Error_Pragma ("Internal parameter required for pragma%");
2234 end if;
2236 if Nkind (Arg_Internal) = N_Identifier then
2237 null;
2239 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2240 and then (Prag_Id = Pragma_Import_Function
2241 or else
2242 Prag_Id = Pragma_Export_Function)
2243 then
2244 null;
2246 else
2247 Error_Pragma_Arg
2248 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2249 end if;
2251 Check_Arg_Is_Local_Name (Arg_Internal);
2252 end Process_Extended_Import_Export_Internal_Arg;
2254 --------------------------------------------------
2255 -- Process_Extended_Import_Export_Object_Pragma --
2256 --------------------------------------------------
2258 procedure Process_Extended_Import_Export_Object_Pragma
2259 (Arg_Internal : Node_Id;
2260 Arg_External : Node_Id;
2261 Arg_Size : Node_Id)
2263 Def_Id : Entity_Id;
2265 begin
2266 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2267 Def_Id := Entity (Arg_Internal);
2269 if Ekind (Def_Id) /= E_Constant
2270 and then Ekind (Def_Id) /= E_Variable
2271 then
2272 Error_Pragma_Arg
2273 ("pragma% must designate an object", Arg_Internal);
2274 end if;
2276 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2277 or else
2278 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2279 then
2280 Error_Pragma_Arg
2281 ("previous Common/Psect_Object applies, pragma % not permitted",
2282 Arg_Internal);
2283 end if;
2285 if Rep_Item_Too_Late (Def_Id, N) then
2286 raise Pragma_Exit;
2287 end if;
2289 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2291 if Present (Arg_Size) then
2292 Check_Arg_Is_External_Name (Arg_Size);
2293 end if;
2295 -- Export_Object case
2297 if Prag_Id = Pragma_Export_Object then
2298 if not Is_Library_Level_Entity (Def_Id) then
2299 Error_Pragma_Arg
2300 ("argument for pragma% must be library level entity",
2301 Arg_Internal);
2302 end if;
2304 if Ekind (Current_Scope) = E_Generic_Package then
2305 Error_Pragma ("pragma& cannot appear in a generic unit");
2306 end if;
2308 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2309 Error_Pragma_Arg
2310 ("exported object must have compile time known size",
2311 Arg_Internal);
2312 end if;
2314 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2315 Error_Msg_N
2316 ("?duplicate Export_Object pragma", N);
2317 else
2318 Set_Exported (Def_Id, Arg_Internal);
2319 end if;
2321 -- Import_Object case
2323 else
2324 if Is_Concurrent_Type (Etype (Def_Id)) then
2325 Error_Pragma_Arg
2326 ("cannot use pragma% for task/protected object",
2327 Arg_Internal);
2328 end if;
2330 if Ekind (Def_Id) = E_Constant then
2331 Error_Pragma_Arg
2332 ("cannot import a constant", Arg_Internal);
2333 end if;
2335 if Warn_On_Export_Import
2336 and then Has_Discriminants (Etype (Def_Id))
2337 then
2338 Error_Msg_N
2339 ("imported value must be initialized?", Arg_Internal);
2340 end if;
2342 if Warn_On_Export_Import
2343 and then Is_Access_Type (Etype (Def_Id))
2344 then
2345 Error_Pragma_Arg
2346 ("cannot import object of an access type?", Arg_Internal);
2347 end if;
2349 if Warn_On_Export_Import
2350 and then Is_Imported (Def_Id)
2351 then
2352 Error_Msg_N
2353 ("?duplicate Import_Object pragma", N);
2355 -- Check for explicit initialization present. Note that an
2356 -- initialization that generated by the code generator, e.g.
2357 -- for an access type, does not count here.
2359 elsif Present (Expression (Parent (Def_Id)))
2360 and then
2361 Comes_From_Source
2362 (Original_Node (Expression (Parent (Def_Id))))
2363 then
2364 Error_Msg_Sloc := Sloc (Def_Id);
2365 Error_Pragma_Arg
2366 ("no initialization allowed for declaration of& #",
2367 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2368 Arg1);
2369 else
2370 Set_Imported (Def_Id);
2371 Note_Possible_Modification (Arg_Internal);
2372 end if;
2373 end if;
2374 end Process_Extended_Import_Export_Object_Pragma;
2376 ------------------------------------------------------
2377 -- Process_Extended_Import_Export_Subprogram_Pragma --
2378 ------------------------------------------------------
2380 procedure Process_Extended_Import_Export_Subprogram_Pragma
2381 (Arg_Internal : Node_Id;
2382 Arg_External : Node_Id;
2383 Arg_Parameter_Types : Node_Id;
2384 Arg_Result_Type : Node_Id := Empty;
2385 Arg_Mechanism : Node_Id;
2386 Arg_Result_Mechanism : Node_Id := Empty;
2387 Arg_First_Optional_Parameter : Node_Id := Empty)
2389 Ent : Entity_Id;
2390 Def_Id : Entity_Id;
2391 Hom_Id : Entity_Id;
2392 Formal : Entity_Id;
2393 Ambiguous : Boolean;
2394 Match : Boolean;
2395 Dval : Node_Id;
2397 function Same_Base_Type
2398 (Ptype : Node_Id;
2399 Formal : Entity_Id) return Boolean;
2400 -- Determines if Ptype references the type of Formal. Note that
2401 -- only the base types need to match according to the spec. Ptype
2402 -- here is the argument from the pragma, which is either a type
2403 -- name, or an access attribute.
2405 --------------------
2406 -- Same_Base_Type --
2407 --------------------
2409 function Same_Base_Type
2410 (Ptype : Node_Id;
2411 Formal : Entity_Id) return Boolean
2413 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2414 Pref : Node_Id;
2416 begin
2417 -- Case where pragma argument is typ'Access
2419 if Nkind (Ptype) = N_Attribute_Reference
2420 and then Attribute_Name (Ptype) = Name_Access
2421 then
2422 Pref := Prefix (Ptype);
2423 Find_Type (Pref);
2425 if not Is_Entity_Name (Pref)
2426 or else Entity (Pref) = Any_Type
2427 then
2428 raise Pragma_Exit;
2429 end if;
2431 -- We have a match if the corresponding argument is of an
2432 -- anonymous access type, and its designicated type matches
2433 -- the type of the prefix of the access attribute
2435 return Ekind (Ftyp) = E_Anonymous_Access_Type
2436 and then Base_Type (Entity (Pref)) =
2437 Base_Type (Etype (Designated_Type (Ftyp)));
2439 -- Case where pragma argument is a type name
2441 else
2442 Find_Type (Ptype);
2444 if not Is_Entity_Name (Ptype)
2445 or else Entity (Ptype) = Any_Type
2446 then
2447 raise Pragma_Exit;
2448 end if;
2450 -- We have a match if the corresponding argument is of
2451 -- the type given in the pragma (comparing base types)
2453 return Base_Type (Entity (Ptype)) = Ftyp;
2454 end if;
2455 end Same_Base_Type;
2457 -- Start of processing for
2458 -- Process_Extended_Import_Export_Subprogram_Pragma
2460 begin
2461 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2462 Ent := Empty;
2463 Ambiguous := False;
2465 -- Loop through homonyms (overloadings) of the entity
2467 Hom_Id := Entity (Arg_Internal);
2468 while Present (Hom_Id) loop
2469 Def_Id := Get_Base_Subprogram (Hom_Id);
2471 -- We need a subprogram in the current scope
2473 if not Is_Subprogram (Def_Id)
2474 or else Scope (Def_Id) /= Current_Scope
2475 then
2476 null;
2478 else
2479 Match := True;
2481 -- Pragma cannot apply to subprogram body
2483 if Is_Subprogram (Def_Id)
2484 and then
2485 Nkind (Parent
2486 (Declaration_Node (Def_Id))) = N_Subprogram_Body
2487 then
2488 Error_Pragma
2489 ("pragma% requires separate spec"
2490 & " and must come before body");
2491 end if;
2493 -- Test result type if given, note that the result type
2494 -- parameter can only be present for the function cases.
2496 if Present (Arg_Result_Type)
2497 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2498 then
2499 Match := False;
2501 elsif Etype (Def_Id) /= Standard_Void_Type
2502 and then
2503 (Chars (N) = Name_Export_Procedure
2504 or else Chars (N) = Name_Import_Procedure)
2505 then
2506 Match := False;
2508 -- Test parameter types if given. Note that this parameter
2509 -- has not been analyzed (and must not be, since it is
2510 -- semantic nonsense), so we get it as the parser left it.
2512 elsif Present (Arg_Parameter_Types) then
2513 Check_Matching_Types : declare
2514 Formal : Entity_Id;
2515 Ptype : Node_Id;
2517 begin
2518 Formal := First_Formal (Def_Id);
2520 if Nkind (Arg_Parameter_Types) = N_Null then
2521 if Present (Formal) then
2522 Match := False;
2523 end if;
2525 -- A list of one type, e.g. (List) is parsed as
2526 -- a parenthesized expression.
2528 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
2529 and then Paren_Count (Arg_Parameter_Types) = 1
2530 then
2531 if No (Formal)
2532 or else Present (Next_Formal (Formal))
2533 then
2534 Match := False;
2535 else
2536 Match :=
2537 Same_Base_Type (Arg_Parameter_Types, Formal);
2538 end if;
2540 -- A list of more than one type is parsed as a aggregate
2542 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
2543 and then Paren_Count (Arg_Parameter_Types) = 0
2544 then
2545 Ptype := First (Expressions (Arg_Parameter_Types));
2546 while Present (Ptype) or else Present (Formal) loop
2547 if No (Ptype)
2548 or else No (Formal)
2549 or else not Same_Base_Type (Ptype, Formal)
2550 then
2551 Match := False;
2552 exit;
2553 else
2554 Next_Formal (Formal);
2555 Next (Ptype);
2556 end if;
2557 end loop;
2559 -- Anything else is of the wrong form
2561 else
2562 Error_Pragma_Arg
2563 ("wrong form for Parameter_Types parameter",
2564 Arg_Parameter_Types);
2565 end if;
2566 end Check_Matching_Types;
2567 end if;
2569 -- Match is now False if the entry we found did not match
2570 -- either a supplied Parameter_Types or Result_Types argument
2572 if Match then
2573 if No (Ent) then
2574 Ent := Def_Id;
2576 -- Ambiguous case, the flag Ambiguous shows if we already
2577 -- detected this and output the initial messages.
2579 else
2580 if not Ambiguous then
2581 Ambiguous := True;
2582 Error_Msg_Name_1 := Chars (N);
2583 Error_Msg_N
2584 ("pragma% does not uniquely identify subprogram!",
2586 Error_Msg_Sloc := Sloc (Ent);
2587 Error_Msg_N ("matching subprogram #!", N);
2588 Ent := Empty;
2589 end if;
2591 Error_Msg_Sloc := Sloc (Def_Id);
2592 Error_Msg_N ("matching subprogram #!", N);
2593 end if;
2594 end if;
2595 end if;
2597 Hom_Id := Homonym (Hom_Id);
2598 end loop;
2600 -- See if we found an entry
2602 if No (Ent) then
2603 if not Ambiguous then
2604 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
2605 Error_Pragma
2606 ("pragma% cannot be given for generic subprogram");
2608 else
2609 Error_Pragma
2610 ("pragma% does not identify local subprogram");
2611 end if;
2612 end if;
2614 return;
2615 end if;
2617 -- Import pragmas must be be for imported entities
2619 if Prag_Id = Pragma_Import_Function
2620 or else
2621 Prag_Id = Pragma_Import_Procedure
2622 or else
2623 Prag_Id = Pragma_Import_Valued_Procedure
2624 then
2625 if not Is_Imported (Ent) then
2626 Error_Pragma
2627 ("pragma Import or Interface must precede pragma%");
2628 end if;
2630 -- Here we have the Export case which can set the entity as exported
2632 -- But does not do so if the specified external name is null,
2633 -- since that is taken as a signal in DEC Ada 83 (with which
2634 -- we want to be compatible) to request no external name.
2636 elsif Nkind (Arg_External) = N_String_Literal
2637 and then String_Length (Strval (Arg_External)) = 0
2638 then
2639 null;
2641 -- In all other cases, set entit as exported
2643 else
2644 Set_Exported (Ent, Arg_Internal);
2645 end if;
2647 -- Special processing for Valued_Procedure cases
2649 if Prag_Id = Pragma_Import_Valued_Procedure
2650 or else
2651 Prag_Id = Pragma_Export_Valued_Procedure
2652 then
2653 Formal := First_Formal (Ent);
2655 if No (Formal) then
2656 Error_Pragma
2657 ("at least one parameter required for pragma%");
2659 elsif Ekind (Formal) /= E_Out_Parameter then
2660 Error_Pragma
2661 ("first parameter must have mode out for pragma%");
2663 else
2664 Set_Is_Valued_Procedure (Ent);
2665 end if;
2666 end if;
2668 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
2670 -- Process Result_Mechanism argument if present. We have already
2671 -- checked that this is only allowed for the function case.
2673 if Present (Arg_Result_Mechanism) then
2674 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
2675 end if;
2677 -- Process Mechanism parameter if present. Note that this parameter
2678 -- is not analyzed, and must not be analyzed since it is semantic
2679 -- nonsense, so we get it in exactly as the parser left it.
2681 if Present (Arg_Mechanism) then
2682 declare
2683 Formal : Entity_Id;
2684 Massoc : Node_Id;
2685 Mname : Node_Id;
2686 Choice : Node_Id;
2688 begin
2689 -- A single mechanism association without a formal parameter
2690 -- name is parsed as a parenthesized expression. All other
2691 -- cases are parsed as aggregates, so we rewrite the single
2692 -- parameter case as an aggregate for consistency.
2694 if Nkind (Arg_Mechanism) /= N_Aggregate
2695 and then Paren_Count (Arg_Mechanism) = 1
2696 then
2697 Rewrite (Arg_Mechanism,
2698 Make_Aggregate (Sloc (Arg_Mechanism),
2699 Expressions => New_List (
2700 Relocate_Node (Arg_Mechanism))));
2701 end if;
2703 -- Case of only mechanism name given, applies to all formals
2705 if Nkind (Arg_Mechanism) /= N_Aggregate then
2706 Formal := First_Formal (Ent);
2707 while Present (Formal) loop
2708 Set_Mechanism_Value (Formal, Arg_Mechanism);
2709 Next_Formal (Formal);
2710 end loop;
2712 -- Case of list of mechanism associations given
2714 else
2715 if Null_Record_Present (Arg_Mechanism) then
2716 Error_Pragma_Arg
2717 ("inappropriate form for Mechanism parameter",
2718 Arg_Mechanism);
2719 end if;
2721 -- Deal with positional ones first
2723 Formal := First_Formal (Ent);
2725 if Present (Expressions (Arg_Mechanism)) then
2726 Mname := First (Expressions (Arg_Mechanism));
2728 while Present (Mname) loop
2729 if No (Formal) then
2730 Error_Pragma_Arg
2731 ("too many mechanism associations", Mname);
2732 end if;
2734 Set_Mechanism_Value (Formal, Mname);
2735 Next_Formal (Formal);
2736 Next (Mname);
2737 end loop;
2738 end if;
2740 -- Deal with named entries
2742 if Present (Component_Associations (Arg_Mechanism)) then
2743 Massoc := First (Component_Associations (Arg_Mechanism));
2745 while Present (Massoc) loop
2746 Choice := First (Choices (Massoc));
2748 if Nkind (Choice) /= N_Identifier
2749 or else Present (Next (Choice))
2750 then
2751 Error_Pragma_Arg
2752 ("incorrect form for mechanism association",
2753 Massoc);
2754 end if;
2756 Formal := First_Formal (Ent);
2757 loop
2758 if No (Formal) then
2759 Error_Pragma_Arg
2760 ("parameter name & not present", Choice);
2761 end if;
2763 if Chars (Choice) = Chars (Formal) then
2764 Set_Mechanism_Value
2765 (Formal, Expression (Massoc));
2766 exit;
2767 end if;
2769 Next_Formal (Formal);
2770 end loop;
2772 Next (Massoc);
2773 end loop;
2774 end if;
2775 end if;
2776 end;
2777 end if;
2779 -- Process First_Optional_Parameter argument if present. We have
2780 -- already checked that this is only allowed for the Import case.
2782 if Present (Arg_First_Optional_Parameter) then
2783 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
2784 Error_Pragma_Arg
2785 ("first optional parameter must be formal parameter name",
2786 Arg_First_Optional_Parameter);
2787 end if;
2789 Formal := First_Formal (Ent);
2790 loop
2791 if No (Formal) then
2792 Error_Pragma_Arg
2793 ("specified formal parameter& not found",
2794 Arg_First_Optional_Parameter);
2795 end if;
2797 exit when Chars (Formal) =
2798 Chars (Arg_First_Optional_Parameter);
2800 Next_Formal (Formal);
2801 end loop;
2803 Set_First_Optional_Parameter (Ent, Formal);
2805 -- Check specified and all remaining formals have right form
2807 while Present (Formal) loop
2808 if Ekind (Formal) /= E_In_Parameter then
2809 Error_Msg_NE
2810 ("optional formal& is not of mode in!",
2811 Arg_First_Optional_Parameter, Formal);
2813 else
2814 Dval := Default_Value (Formal);
2816 if not Present (Dval) then
2817 Error_Msg_NE
2818 ("optional formal& does not have default value!",
2819 Arg_First_Optional_Parameter, Formal);
2821 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
2822 null;
2824 else
2825 Error_Msg_FE
2826 ("default value for optional formal& is non-static!",
2827 Arg_First_Optional_Parameter, Formal);
2828 end if;
2829 end if;
2831 Set_Is_Optional_Parameter (Formal);
2832 Next_Formal (Formal);
2833 end loop;
2834 end if;
2835 end Process_Extended_Import_Export_Subprogram_Pragma;
2837 --------------------------
2838 -- Process_Generic_List --
2839 --------------------------
2841 procedure Process_Generic_List is
2842 Arg : Node_Id;
2843 Exp : Node_Id;
2845 begin
2846 GNAT_Pragma;
2847 Check_No_Identifiers;
2848 Check_At_Least_N_Arguments (1);
2850 Arg := Arg1;
2851 while Present (Arg) loop
2852 Exp := Expression (Arg);
2853 Analyze (Exp);
2855 if not Is_Entity_Name (Exp)
2856 or else
2857 (not Is_Generic_Instance (Entity (Exp))
2858 and then
2859 not Is_Generic_Unit (Entity (Exp)))
2860 then
2861 Error_Pragma_Arg
2862 ("pragma% argument must be name of generic unit/instance",
2863 Arg);
2864 end if;
2866 Next (Arg);
2867 end loop;
2868 end Process_Generic_List;
2870 ---------------------------------
2871 -- Process_Import_Or_Interface --
2872 ---------------------------------
2874 procedure Process_Import_Or_Interface is
2875 C : Convention_Id;
2876 Def_Id : Entity_Id;
2877 Hom_Id : Entity_Id;
2879 begin
2880 Process_Convention (C, Def_Id);
2881 Kill_Size_Check_Code (Def_Id);
2882 Note_Possible_Modification (Expression (Arg2));
2884 if Ekind (Def_Id) = E_Variable
2885 or else
2886 Ekind (Def_Id) = E_Constant
2887 then
2888 -- User initialization is not allowed for imported object, but
2889 -- the object declaration may contain a default initialization,
2890 -- that will be discarded. Note that an explicit initialization
2891 -- only counts if it comes from source, otherwise it is simply
2892 -- the code generator making an implicit initialization explicit.
2894 if Present (Expression (Parent (Def_Id)))
2895 and then Comes_From_Source (Expression (Parent (Def_Id)))
2896 then
2897 Error_Msg_Sloc := Sloc (Def_Id);
2898 Error_Pragma_Arg
2899 ("no initialization allowed for declaration of& #",
2900 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2901 Arg2);
2903 else
2904 Set_Imported (Def_Id);
2905 Process_Interface_Name (Def_Id, Arg3, Arg4);
2907 -- Note that we do not set Is_Public here. That's because we
2908 -- only want to set if if there is no address clause, and we
2909 -- don't know that yet, so we delay that processing till
2910 -- freeze time.
2912 -- pragma Import completes deferred constants
2914 if Ekind (Def_Id) = E_Constant then
2915 Set_Has_Completion (Def_Id);
2916 end if;
2918 -- It is not possible to import a constant of an unconstrained
2919 -- array type (e.g. string) because there is no simple way to
2920 -- write a meaningful subtype for it.
2922 if Is_Array_Type (Etype (Def_Id))
2923 and then not Is_Constrained (Etype (Def_Id))
2924 then
2925 Error_Msg_NE
2926 ("imported constant& must have a constrained subtype",
2927 N, Def_Id);
2928 end if;
2929 end if;
2931 elsif Is_Subprogram (Def_Id)
2932 or else Is_Generic_Subprogram (Def_Id)
2933 then
2934 -- If the name is overloaded, pragma applies to all of the
2935 -- denoted entities in the same declarative part.
2937 Hom_Id := Def_Id;
2938 while Present (Hom_Id) loop
2939 Def_Id := Get_Base_Subprogram (Hom_Id);
2941 -- Ignore inherited subprograms because the pragma will
2942 -- apply to the parent operation, which is the one called.
2944 if Is_Overloadable (Def_Id)
2945 and then Present (Alias (Def_Id))
2946 then
2947 null;
2949 -- If it is not a subprogram, it must be in an outer
2950 -- scope and pragma does not apply.
2952 elsif not Is_Subprogram (Def_Id)
2953 and then not Is_Generic_Subprogram (Def_Id)
2954 then
2955 null;
2957 -- Verify that the homonym is in the same declarative
2958 -- part (not just the same scope).
2960 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
2961 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
2962 then
2963 exit;
2965 else
2966 Set_Imported (Def_Id);
2968 -- Special processing for Convention_Intrinsic
2970 if C = Convention_Intrinsic then
2972 -- Link_Name argument not allowed for intrinsic
2974 if Present (Arg3)
2975 and then Chars (Arg3) = Name_Link_Name
2976 then
2977 Arg4 := Arg3;
2978 end if;
2980 if Present (Arg4) then
2981 Error_Pragma_Arg
2982 ("Link_Name argument not allowed for " &
2983 "Import Intrinsic",
2984 Arg4);
2985 end if;
2987 Set_Is_Intrinsic_Subprogram (Def_Id);
2989 -- If no external name is present, then check that
2990 -- this is a valid intrinsic subprogram. If an external
2991 -- name is present, then this is handled by the back end.
2993 if No (Arg3) then
2994 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
2995 end if;
2996 end if;
2998 -- All interfaced procedures need an external symbol
2999 -- created for them since they are always referenced
3000 -- from another object file.
3002 Set_Is_Public (Def_Id);
3004 -- Verify that the subprogram does not have a completion
3005 -- through a renaming declaration. For other completions
3006 -- the pragma appears as a too late representation.
3008 declare
3009 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3011 begin
3012 if Present (Decl)
3013 and then Nkind (Decl) = N_Subprogram_Declaration
3014 and then Present (Corresponding_Body (Decl))
3015 and then
3016 Nkind
3017 (Unit_Declaration_Node
3018 (Corresponding_Body (Decl))) =
3019 N_Subprogram_Renaming_Declaration
3020 then
3021 Error_Msg_Sloc := Sloc (Def_Id);
3022 Error_Msg_NE ("cannot import&#," &
3023 " already completed by a renaming",
3024 N, Def_Id);
3025 end if;
3026 end;
3028 Set_Has_Completion (Def_Id);
3029 Process_Interface_Name (Def_Id, Arg3, Arg4);
3030 end if;
3032 if Is_Compilation_Unit (Hom_Id) then
3034 -- Its possible homonyms are not affected by the pragma.
3035 -- Such homonyms might be present in the context of other
3036 -- units being compiled.
3038 exit;
3040 else
3041 Hom_Id := Homonym (Hom_Id);
3042 end if;
3043 end loop;
3045 -- When the convention is Java, we also allow Import to be given
3046 -- for packages, exceptions, and record components.
3048 elsif C = Convention_Java
3049 and then
3050 (Ekind (Def_Id) = E_Package
3051 or else Ekind (Def_Id) = E_Exception
3052 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3053 then
3054 Set_Imported (Def_Id);
3055 Set_Is_Public (Def_Id);
3056 Process_Interface_Name (Def_Id, Arg3, Arg4);
3058 else
3059 Error_Pragma_Arg
3060 ("second argument of pragma% must be object or subprogram",
3061 Arg2);
3062 end if;
3064 -- If this pragma applies to a compilation unit, then the unit,
3065 -- which is a subprogram, does not require (or allow) a body.
3066 -- We also do not need to elaborate imported procedures.
3068 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3069 declare
3070 Cunit : constant Node_Id := Parent (Parent (N));
3071 begin
3072 Set_Body_Required (Cunit, False);
3073 end;
3074 end if;
3075 end Process_Import_Or_Interface;
3077 --------------------
3078 -- Process_Inline --
3079 --------------------
3081 procedure Process_Inline (Active : Boolean) is
3082 Assoc : Node_Id;
3083 Decl : Node_Id;
3084 Subp_Id : Node_Id;
3085 Subp : Entity_Id;
3086 Applies : Boolean;
3087 Effective : Boolean := False;
3089 procedure Make_Inline (Subp : Entity_Id);
3090 -- Subp is the defining unit name of the subprogram
3091 -- declaration. Set the flag, as well as the flag in the
3092 -- corresponding body, if there is one present.
3094 procedure Set_Inline_Flags (Subp : Entity_Id);
3095 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp
3097 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3098 -- Returns True if it can be determined at this stage that inlining
3099 -- is not possible, for examle if the body is available and contains
3100 -- exception handlers, we prevent inlining, since otherwise we can
3101 -- get undefined symbols at link time. This function also emits a
3102 -- warning if front-end inlining is enabled and the pragma appears
3103 -- too late.
3104 -- ??? is business with link symbols still valid, or does it relate
3105 -- to front end ZCX which is being phased out ???
3107 ---------------------------
3108 -- Inlining_Not_Possible --
3109 ---------------------------
3111 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3112 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3113 Stats : Node_Id;
3115 begin
3116 if Nkind (Decl) = N_Subprogram_Body then
3117 Stats := Handled_Statement_Sequence (Decl);
3118 return Present (Exception_Handlers (Stats))
3119 or else Present (At_End_Proc (Stats));
3121 elsif Nkind (Decl) = N_Subprogram_Declaration
3122 and then Present (Corresponding_Body (Decl))
3123 then
3124 if Front_End_Inlining
3125 and then Analyzed (Corresponding_Body (Decl))
3126 then
3127 Error_Msg_N ("pragma appears too late, ignored?", N);
3128 return True;
3130 -- If the subprogram is a renaming as body, the body is
3131 -- just a call to the renamed subprogram, and inlining is
3132 -- trivially possible.
3134 elsif
3135 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
3136 = N_Subprogram_Renaming_Declaration
3137 then
3138 return False;
3140 else
3141 Stats :=
3142 Handled_Statement_Sequence
3143 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3145 return
3146 Present (Exception_Handlers (Stats))
3147 or else Present (At_End_Proc (Stats));
3148 end if;
3150 else
3151 -- If body is not available, assume the best, the check is
3152 -- performed again when compiling enclosing package bodies.
3154 return False;
3155 end if;
3156 end Inlining_Not_Possible;
3158 -----------------
3159 -- Make_Inline --
3160 -----------------
3162 procedure Make_Inline (Subp : Entity_Id) is
3163 Kind : constant Entity_Kind := Ekind (Subp);
3164 Inner_Subp : Entity_Id := Subp;
3166 begin
3167 if Etype (Subp) = Any_Type then
3168 return;
3170 -- If inlining is not possible, for now do not treat as an error
3172 elsif Inlining_Not_Possible (Subp) then
3173 Applies := True;
3174 return;
3176 -- Here we have a candidate for inlining, but we must exclude
3177 -- derived operations. Otherwise we will end up trying to
3178 -- inline a phantom declaration, and the result would be to
3179 -- drag in a body which has no direct inlining associated with
3180 -- it. That would not only be inefficient but would also result
3181 -- in the backend doing cross-unit inlining in cases where it
3182 -- was definitely inappropriate to do so.
3184 -- However, a simple Comes_From_Source test is insufficient,
3185 -- since we do want to allow inlining of generic instances,
3186 -- which also do not come from source. Predefined operators do
3187 -- not come from source but are not inlineable either.
3189 elsif not Comes_From_Source (Subp)
3190 and then not Is_Generic_Instance (Subp)
3191 and then Scope (Subp) /= Standard_Standard
3192 then
3193 Applies := True;
3194 return;
3196 -- The referenced entity must either be the enclosing entity,
3197 -- or an entity declared within the current open scope.
3199 elsif Present (Scope (Subp))
3200 and then Scope (Subp) /= Current_Scope
3201 and then Subp /= Current_Scope
3202 then
3203 Error_Pragma_Arg
3204 ("argument of% must be entity in current scope", Assoc);
3205 return;
3206 end if;
3208 -- Processing for procedure, operator or function.
3209 -- If subprogram is aliased (as for an instance) indicate
3210 -- that the renamed entity (if declared in the same unit)
3211 -- is inlined.
3213 if Is_Subprogram (Subp) then
3214 while Present (Alias (Inner_Subp)) loop
3215 Inner_Subp := Alias (Inner_Subp);
3216 end loop;
3218 if In_Same_Source_Unit (Subp, Inner_Subp) then
3219 Set_Inline_Flags (Inner_Subp);
3221 Decl := Parent (Parent (Inner_Subp));
3223 if Nkind (Decl) = N_Subprogram_Declaration
3224 and then Present (Corresponding_Body (Decl))
3225 then
3226 Set_Inline_Flags (Corresponding_Body (Decl));
3227 end if;
3228 end if;
3230 Applies := True;
3232 -- For a generic subprogram set flag as well, for use at
3233 -- the point of instantiation, to determine whether the
3234 -- body should be generated.
3236 elsif Is_Generic_Subprogram (Subp) then
3237 Set_Inline_Flags (Subp);
3238 Applies := True;
3240 -- Literals are by definition inlined
3242 elsif Kind = E_Enumeration_Literal then
3243 null;
3245 -- Anything else is an error
3247 else
3248 Error_Pragma_Arg
3249 ("expect subprogram name for pragma%", Assoc);
3250 end if;
3251 end Make_Inline;
3253 ----------------------
3254 -- Set_Inline_Flags --
3255 ----------------------
3257 procedure Set_Inline_Flags (Subp : Entity_Id) is
3258 begin
3259 if Active then
3260 Set_Is_Inlined (Subp, True);
3261 end if;
3263 if not Has_Pragma_Inline (Subp) then
3264 Set_Has_Pragma_Inline (Subp);
3265 Set_Next_Rep_Item (N, First_Rep_Item (Subp));
3266 Set_First_Rep_Item (Subp, N);
3267 Effective := True;
3268 end if;
3269 end Set_Inline_Flags;
3271 -- Start of processing for Process_Inline
3273 begin
3274 Check_No_Identifiers;
3275 Check_At_Least_N_Arguments (1);
3277 if Active then
3278 Inline_Processing_Required := True;
3279 end if;
3281 Assoc := Arg1;
3282 while Present (Assoc) loop
3283 Subp_Id := Expression (Assoc);
3284 Analyze (Subp_Id);
3285 Applies := False;
3287 if Is_Entity_Name (Subp_Id) then
3288 Subp := Entity (Subp_Id);
3290 if Subp = Any_Id then
3291 Applies := True;
3293 else
3294 Make_Inline (Subp);
3296 while Present (Homonym (Subp))
3297 and then Scope (Homonym (Subp)) = Current_Scope
3298 loop
3299 Make_Inline (Homonym (Subp));
3300 Subp := Homonym (Subp);
3301 end loop;
3302 end if;
3303 end if;
3305 if not Applies then
3306 Error_Pragma_Arg
3307 ("inappropriate argument for pragma%", Assoc);
3309 elsif not Effective
3310 and then Warn_On_Redundant_Constructs
3311 then
3312 if Inlining_Not_Possible (Subp) then
3313 Error_Msg_NE
3314 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
3315 else
3316 Error_Msg_NE
3317 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
3318 end if;
3319 end if;
3321 Next (Assoc);
3322 end loop;
3323 end Process_Inline;
3325 ----------------------------
3326 -- Process_Interface_Name --
3327 ----------------------------
3329 procedure Process_Interface_Name
3330 (Subprogram_Def : Entity_Id;
3331 Ext_Arg : Node_Id;
3332 Link_Arg : Node_Id)
3334 Ext_Nam : Node_Id;
3335 Link_Nam : Node_Id;
3336 String_Val : String_Id;
3338 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
3339 -- SN is a string literal node for an interface name. This routine
3340 -- performs some minimal checks that the name is reasonable. In
3341 -- particular that no spaces or other obviously incorrect characters
3342 -- appear. This is only a warning, since any characters are allowed.
3344 ----------------------------------
3345 -- Check_Form_Of_Interface_Name --
3346 ----------------------------------
3348 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
3349 S : constant String_Id := Strval (Expr_Value_S (SN));
3350 SL : constant Nat := String_Length (S);
3351 C : Char_Code;
3353 begin
3354 if SL = 0 then
3355 Error_Msg_N ("interface name cannot be null string", SN);
3356 end if;
3358 for J in 1 .. SL loop
3359 C := Get_String_Char (S, J);
3361 if Warn_On_Export_Import
3362 and then (not In_Character_Range (C)
3363 or else Get_Character (C) = ' '
3364 or else Get_Character (C) = ',')
3365 then
3366 Error_Msg_N
3367 ("?interface name contains illegal character", SN);
3368 end if;
3369 end loop;
3370 end Check_Form_Of_Interface_Name;
3372 -- Start of processing for Process_Interface_Name
3374 begin
3375 if No (Link_Arg) then
3376 if No (Ext_Arg) then
3377 return;
3379 elsif Chars (Ext_Arg) = Name_Link_Name then
3380 Ext_Nam := Empty;
3381 Link_Nam := Expression (Ext_Arg);
3383 else
3384 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3385 Ext_Nam := Expression (Ext_Arg);
3386 Link_Nam := Empty;
3387 end if;
3389 else
3390 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3391 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
3392 Ext_Nam := Expression (Ext_Arg);
3393 Link_Nam := Expression (Link_Arg);
3394 end if;
3396 -- Check expressions for external name and link name are static
3398 if Present (Ext_Nam) then
3399 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
3400 Check_Form_Of_Interface_Name (Ext_Nam);
3402 -- Verify that the external name is not the name of a local
3403 -- entity, which would hide the imported one and lead to
3404 -- run-time surprises. The problem can only arise for entities
3405 -- declared in a package body (otherwise the external name is
3406 -- fully qualified and won't conflict).
3408 declare
3409 Nam : Name_Id;
3410 E : Entity_Id;
3411 Par : Node_Id;
3413 begin
3414 if Prag_Id = Pragma_Import then
3415 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
3416 Nam := Name_Find;
3417 E := Entity_Id (Get_Name_Table_Info (Nam));
3419 if Nam /= Chars (Subprogram_Def)
3420 and then Present (E)
3421 and then not Is_Overloadable (E)
3422 and then Is_Immediately_Visible (E)
3423 and then not Is_Imported (E)
3424 and then Ekind (Scope (E)) = E_Package
3425 then
3426 Par := Parent (E);
3428 while Present (Par) loop
3429 if Nkind (Par) = N_Package_Body then
3430 Error_Msg_Sloc := Sloc (E);
3431 Error_Msg_NE
3432 ("imported entity is hidden by & declared#",
3433 Ext_Arg, E);
3434 exit;
3435 end if;
3437 Par := Parent (Par);
3438 end loop;
3439 end if;
3440 end if;
3441 end;
3442 end if;
3444 if Present (Link_Nam) then
3445 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
3446 Check_Form_Of_Interface_Name (Link_Nam);
3447 end if;
3449 -- If there is no link name, just set the external name
3451 if No (Link_Nam) then
3452 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
3454 -- For the Link_Name case, the given literal is preceded by an
3455 -- asterisk, which indicates to GCC that the given name should
3456 -- be taken literally, and in particular that no prepending of
3457 -- underlines should occur, even in systems where this is the
3458 -- normal default.
3460 else
3461 Start_String;
3462 Store_String_Char (Get_Char_Code ('*'));
3463 String_Val := Strval (Expr_Value_S (Link_Nam));
3465 for J in 1 .. String_Length (String_Val) loop
3466 Store_String_Char (Get_String_Char (String_Val, J));
3467 end loop;
3469 Link_Nam :=
3470 Make_String_Literal (Sloc (Link_Nam), End_String);
3471 end if;
3473 Set_Encoded_Interface_Name
3474 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
3475 Check_Duplicated_Export_Name (Link_Nam);
3476 end Process_Interface_Name;
3478 -----------------------------------------
3479 -- Process_Interrupt_Or_Attach_Handler --
3480 -----------------------------------------
3482 procedure Process_Interrupt_Or_Attach_Handler is
3483 Arg1_X : constant Node_Id := Expression (Arg1);
3484 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
3485 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
3487 begin
3488 Set_Is_Interrupt_Handler (Handler_Proc);
3490 -- If the pragma is not associated with a handler procedure
3491 -- within a protected type, then it must be for a nonprotected
3492 -- procedure for the AAMP target, in which case we don't
3493 -- associate a representation item with the procedure's scope.
3495 if Ekind (Proc_Scope) = E_Protected_Type then
3496 if Prag_Id = Pragma_Interrupt_Handler
3497 or else
3498 Prag_Id = Pragma_Attach_Handler
3499 then
3500 Record_Rep_Item (Proc_Scope, N);
3501 end if;
3502 end if;
3503 end Process_Interrupt_Or_Attach_Handler;
3505 --------------------------------------------------
3506 -- Process_Restrictions_Or_Restriction_Warnings --
3507 --------------------------------------------------
3509 -- Note: some of the simple identifier cases were handled in par-prag,
3510 -- but it is harmless (and more straightforward) to simply handle all
3511 -- cases here, even if it means we repeat a bit of work in some cases.
3513 procedure Process_Restrictions_Or_Restriction_Warnings is
3514 Arg : Node_Id;
3515 R_Id : Restriction_Id;
3516 Id : Name_Id;
3517 Expr : Node_Id;
3518 Val : Uint;
3520 procedure Check_Unit_Name (N : Node_Id);
3521 -- Checks unit name parameter for No_Dependence. Returns if it has
3522 -- an appropriate form, otherwise raises pragma argument error.
3524 procedure Set_Warning (R : All_Restrictions);
3525 -- If this is a Restriction_Warnings pragma, set warning flag,
3526 -- otherwise reset the flag.
3528 ---------------------
3529 -- Check_Unit_Name --
3530 ---------------------
3532 procedure Check_Unit_Name (N : Node_Id) is
3533 begin
3534 if Nkind (N) = N_Selected_Component then
3535 Check_Unit_Name (Prefix (N));
3536 Check_Unit_Name (Selector_Name (N));
3538 elsif Nkind (N) = N_Identifier then
3539 return;
3541 else
3542 Error_Pragma_Arg
3543 ("wrong form for unit name for No_Dependence", N);
3544 end if;
3545 end Check_Unit_Name;
3547 -----------------
3548 -- Set_Warning --
3549 -----------------
3551 procedure Set_Warning (R : All_Restrictions) is
3552 begin
3553 if Prag_Id = Pragma_Restriction_Warnings then
3554 Restriction_Warnings (R) := True;
3555 else
3556 Restriction_Warnings (R) := False;
3557 end if;
3558 end Set_Warning;
3560 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
3562 begin
3563 Check_Ada_83_Warning;
3564 Check_At_Least_N_Arguments (1);
3565 Check_Valid_Configuration_Pragma;
3567 Arg := Arg1;
3568 while Present (Arg) loop
3569 Id := Chars (Arg);
3570 Expr := Expression (Arg);
3572 -- Case of no restriction identifier present
3574 if Id = No_Name then
3575 if Nkind (Expr) /= N_Identifier then
3576 Error_Pragma_Arg
3577 ("invalid form for restriction", Arg);
3578 end if;
3580 R_Id :=
3581 Get_Restriction_Id
3582 (Process_Restriction_Synonyms (Expr));
3584 if R_Id not in All_Boolean_Restrictions then
3585 Error_Pragma_Arg
3586 ("invalid restriction identifier", Arg);
3587 end if;
3589 if Implementation_Restriction (R_Id) then
3590 Check_Restriction
3591 (No_Implementation_Restrictions, Arg);
3592 end if;
3594 Set_Restriction (R_Id, N);
3595 Set_Warning (R_Id);
3597 -- A very special case that must be processed here:
3598 -- pragma Restrictions (No_Exceptions) turns off
3599 -- all run-time checking. This is a bit dubious in
3600 -- terms of the formal language definition, but it
3601 -- is what is intended by RM H.4(12).
3603 if R_Id = No_Exceptions then
3604 Scope_Suppress := (others => True);
3605 end if;
3607 -- Case of No_Dependence => unit-name. Note that the parser
3608 -- already made the necessary entry in the No_Dependence table.
3610 elsif Id = Name_No_Dependence then
3611 Check_Unit_Name (Expr);
3613 -- All other cases of restriction identifier present
3615 else
3616 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
3617 Analyze_And_Resolve (Expr, Any_Integer);
3619 if R_Id not in All_Parameter_Restrictions then
3620 Error_Pragma_Arg
3621 ("invalid restriction parameter identifier", Arg);
3623 elsif not Is_OK_Static_Expression (Expr) then
3624 Flag_Non_Static_Expr
3625 ("value must be static expression!", Expr);
3626 raise Pragma_Exit;
3628 elsif not Is_Integer_Type (Etype (Expr))
3629 or else Expr_Value (Expr) < 0
3630 then
3631 Error_Pragma_Arg
3632 ("value must be non-negative integer", Arg);
3634 -- Restriction pragma is active
3636 else
3637 Val := Expr_Value (Expr);
3639 if not UI_Is_In_Int_Range (Val) then
3640 Error_Pragma_Arg
3641 ("pragma ignored, value too large?", Arg);
3642 else
3643 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
3644 Set_Warning (R_Id);
3645 end if;
3646 end if;
3647 end if;
3649 Next (Arg);
3650 end loop;
3651 end Process_Restrictions_Or_Restriction_Warnings;
3653 ---------------------------------
3654 -- Process_Suppress_Unsuppress --
3655 ---------------------------------
3657 -- Note: this procedure makes entries in the check suppress data
3658 -- structures managed by Sem. See spec of package Sem for full
3659 -- details on how we handle recording of check suppression.
3661 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
3662 C : Check_Id;
3663 E_Id : Node_Id;
3664 E : Entity_Id;
3666 In_Package_Spec : constant Boolean :=
3667 (Ekind (Current_Scope) = E_Package
3668 or else
3669 Ekind (Current_Scope) = E_Generic_Package)
3670 and then not In_Package_Body (Current_Scope);
3672 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
3673 -- Used to suppress a single check on the given entity
3675 --------------------------------
3676 -- Suppress_Unsuppress_Echeck --
3677 --------------------------------
3679 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
3680 ESR : constant Entity_Check_Suppress_Record :=
3681 (Entity => E,
3682 Check => C,
3683 Suppress => Suppress_Case);
3685 begin
3686 Set_Checks_May_Be_Suppressed (E);
3688 if In_Package_Spec then
3689 Global_Entity_Suppress.Append (ESR);
3690 else
3691 Local_Entity_Suppress.Append (ESR);
3692 end if;
3694 -- If this is a first subtype, and the base type is distinct,
3695 -- then also set the suppress flags on the base type.
3697 if Is_First_Subtype (E)
3698 and then Etype (E) /= E
3699 then
3700 Suppress_Unsuppress_Echeck (Etype (E), C);
3701 end if;
3702 end Suppress_Unsuppress_Echeck;
3704 -- Start of processing for Process_Suppress_Unsuppress
3706 begin
3707 -- Suppress/Unsuppress can appear as a configuration pragma,
3708 -- or in a declarative part or a package spec (RM 11.5(5))
3710 if not Is_Configuration_Pragma then
3711 Check_Is_In_Decl_Part_Or_Package_Spec;
3712 end if;
3714 Check_At_Least_N_Arguments (1);
3715 Check_At_Most_N_Arguments (2);
3716 Check_No_Identifier (Arg1);
3717 Check_Arg_Is_Identifier (Arg1);
3719 if not Is_Check_Name (Chars (Expression (Arg1))) then
3720 Error_Pragma_Arg
3721 ("argument of pragma% is not valid check name", Arg1);
3722 else
3723 C := Get_Check_Id (Chars (Expression (Arg1)));
3724 end if;
3726 if Arg_Count = 1 then
3728 -- Make an entry in the local scope suppress table. This is the
3729 -- table that directly shows the current value of the scope
3730 -- suppress check for any check id value.
3732 if C = All_Checks then
3733 for J in Scope_Suppress'Range loop
3734 Scope_Suppress (J) := Suppress_Case;
3735 end loop;
3736 else
3737 Scope_Suppress (C) := Suppress_Case;
3738 end if;
3740 -- Also make an entry in the Local_Entity_Suppress table. See
3741 -- extended description in the package spec of Sem for details.
3743 Local_Entity_Suppress.Append
3744 ((Entity => Empty,
3745 Check => C,
3746 Suppress => Suppress_Case));
3748 -- Case of two arguments present, where the check is
3749 -- suppressed for a specified entity (given as the second
3750 -- argument of the pragma)
3752 else
3753 Check_Optional_Identifier (Arg2, Name_On);
3754 E_Id := Expression (Arg2);
3755 Analyze (E_Id);
3757 if not Is_Entity_Name (E_Id) then
3758 Error_Pragma_Arg
3759 ("second argument of pragma% must be entity name", Arg2);
3760 end if;
3762 E := Entity (E_Id);
3764 if E = Any_Id then
3765 return;
3766 end if;
3768 -- Enforce RM 11.5(7) which requires that for a pragma that
3769 -- appears within a package spec, the named entity must be
3770 -- within the package spec. We allow the package name itself
3771 -- to be mentioned since that makes sense, although it is not
3772 -- strictly allowed by 11.5(7).
3774 if In_Package_Spec
3775 and then E /= Current_Scope
3776 and then Scope (E) /= Current_Scope
3777 then
3778 Error_Pragma_Arg
3779 ("entity in pragma% is not in package spec ('R'M 11.5(7))",
3780 Arg2);
3781 end if;
3783 -- Loop through homonyms. As noted below, in the case of a package
3784 -- spec, only homonyms within the package spec are considered.
3786 loop
3787 Suppress_Unsuppress_Echeck (E, C);
3789 if Is_Generic_Instance (E)
3790 and then Is_Subprogram (E)
3791 and then Present (Alias (E))
3792 then
3793 Suppress_Unsuppress_Echeck (Alias (E), C);
3794 end if;
3796 -- Move to next homonym
3798 E := Homonym (E);
3799 exit when No (E);
3801 -- If we are within a package specification, the
3802 -- pragma only applies to homonyms in the same scope.
3804 exit when In_Package_Spec
3805 and then Scope (E) /= Current_Scope;
3806 end loop;
3807 end if;
3808 end Process_Suppress_Unsuppress;
3810 ------------------
3811 -- Set_Exported --
3812 ------------------
3814 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
3815 begin
3816 if Is_Imported (E) then
3817 Error_Pragma_Arg
3818 ("cannot export entity& that was previously imported", Arg);
3820 elsif Present (Address_Clause (E)) then
3821 Error_Pragma_Arg
3822 ("cannot export entity& that has an address clause", Arg);
3823 end if;
3825 Set_Is_Exported (E);
3827 -- Generate a reference for entity explicitly, because the
3828 -- identifier may be overloaded and name resolution will not
3829 -- generate one.
3831 Generate_Reference (E, Arg);
3833 -- Deal with exporting non-library level entity
3835 if not Is_Library_Level_Entity (E) then
3837 -- Not allowed at all for subprograms
3839 if Is_Subprogram (E) then
3840 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
3842 -- Otherwise set public and statically allocated
3844 else
3845 Set_Is_Public (E);
3846 Set_Is_Statically_Allocated (E);
3848 -- Warn if the corresponding W flag is set and the pragma
3849 -- comes from source. The latter may not be true e.g. on
3850 -- VMS where we expand export pragmas for exception codes
3851 -- associated with imported or exported exceptions. We do
3852 -- not want to generate a warning for something that the
3853 -- user did not write.
3855 if Warn_On_Export_Import
3856 and then Comes_From_Source (Arg)
3857 then
3858 Error_Msg_NE
3859 ("?& has been made static as a result of Export", Arg, E);
3860 Error_Msg_N
3861 ("\this usage is non-standard and non-portable", Arg);
3862 end if;
3863 end if;
3864 end if;
3866 if Warn_On_Export_Import and then Is_Type (E) then
3867 Error_Msg_NE
3868 ("exporting a type has no effect?", Arg, E);
3869 end if;
3871 if Warn_On_Export_Import and Inside_A_Generic then
3872 Error_Msg_NE
3873 ("all instances of& will have the same external name?", Arg, E);
3874 end if;
3875 end Set_Exported;
3877 ----------------------------------------------
3878 -- Set_Extended_Import_Export_External_Name --
3879 ----------------------------------------------
3881 procedure Set_Extended_Import_Export_External_Name
3882 (Internal_Ent : Entity_Id;
3883 Arg_External : Node_Id)
3885 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
3886 New_Name : Node_Id;
3888 begin
3889 if No (Arg_External) then
3890 return;
3891 end if;
3893 Check_Arg_Is_External_Name (Arg_External);
3895 if Nkind (Arg_External) = N_String_Literal then
3896 if String_Length (Strval (Arg_External)) = 0 then
3897 return;
3898 else
3899 New_Name := Adjust_External_Name_Case (Arg_External);
3900 end if;
3902 elsif Nkind (Arg_External) = N_Identifier then
3903 New_Name := Get_Default_External_Name (Arg_External);
3905 -- Check_Arg_Is_External_Name should let through only
3906 -- identifiers and string literals or static string
3907 -- expressions (which are folded to string literals).
3909 else
3910 raise Program_Error;
3911 end if;
3913 -- If we already have an external name set (by a prior normal
3914 -- Import or Export pragma), then the external names must match
3916 if Present (Interface_Name (Internal_Ent)) then
3917 Check_Matching_Internal_Names : declare
3918 S1 : constant String_Id := Strval (Old_Name);
3919 S2 : constant String_Id := Strval (New_Name);
3921 procedure Mismatch;
3922 -- Called if names do not match
3924 --------------
3925 -- Mismatch --
3926 --------------
3928 procedure Mismatch is
3929 begin
3930 Error_Msg_Sloc := Sloc (Old_Name);
3931 Error_Pragma_Arg
3932 ("external name does not match that given #",
3933 Arg_External);
3934 end Mismatch;
3936 -- Start of processing for Check_Matching_Internal_Names
3938 begin
3939 if String_Length (S1) /= String_Length (S2) then
3940 Mismatch;
3942 else
3943 for J in 1 .. String_Length (S1) loop
3944 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
3945 Mismatch;
3946 end if;
3947 end loop;
3948 end if;
3949 end Check_Matching_Internal_Names;
3951 -- Otherwise set the given name
3953 else
3954 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
3955 Check_Duplicated_Export_Name (New_Name);
3956 end if;
3957 end Set_Extended_Import_Export_External_Name;
3959 ------------------
3960 -- Set_Imported --
3961 ------------------
3963 procedure Set_Imported (E : Entity_Id) is
3964 begin
3965 Error_Msg_Sloc := Sloc (E);
3967 if Is_Exported (E) or else Is_Imported (E) then
3968 Error_Msg_NE ("import of& declared# not allowed", N, E);
3970 if Is_Exported (E) then
3971 Error_Msg_N ("\entity was previously exported", N);
3972 else
3973 Error_Msg_N ("\entity was previously imported", N);
3974 end if;
3976 Error_Pragma ("\(pragma% applies to all previous entities)");
3978 else
3979 Set_Is_Imported (E);
3981 -- If the entity is an object that is not at the library
3982 -- level, then it is statically allocated. We do not worry
3983 -- about objects with address clauses in this context since
3984 -- they are not really imported in the linker sense.
3986 if Is_Object (E)
3987 and then not Is_Library_Level_Entity (E)
3988 and then No (Address_Clause (E))
3989 then
3990 Set_Is_Statically_Allocated (E);
3991 end if;
3992 end if;
3993 end Set_Imported;
3995 -------------------------
3996 -- Set_Mechanism_Value --
3997 -------------------------
3999 -- Note: the mechanism name has not been analyzed (and cannot indeed
4000 -- be analyzed, since it is semantic nonsense), so we get it in the
4001 -- exact form created by the parser.
4003 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4004 Class : Node_Id;
4005 Param : Node_Id;
4007 procedure Bad_Class;
4008 -- Signal bad descriptor class name
4010 procedure Bad_Mechanism;
4011 -- Signal bad mechanism name
4013 ---------------
4014 -- Bad_Class --
4015 ---------------
4017 procedure Bad_Class is
4018 begin
4019 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4020 end Bad_Class;
4022 -------------------------
4023 -- Bad_Mechanism_Value --
4024 -------------------------
4026 procedure Bad_Mechanism is
4027 begin
4028 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4029 end Bad_Mechanism;
4031 -- Start of processing for Set_Mechanism_Value
4033 begin
4034 if Mechanism (Ent) /= Default_Mechanism then
4035 Error_Msg_NE
4036 ("mechanism for & has already been set", Mech_Name, Ent);
4037 end if;
4039 -- MECHANISM_NAME ::= value | reference | descriptor
4041 if Nkind (Mech_Name) = N_Identifier then
4042 if Chars (Mech_Name) = Name_Value then
4043 Set_Mechanism (Ent, By_Copy);
4044 return;
4046 elsif Chars (Mech_Name) = Name_Reference then
4047 Set_Mechanism (Ent, By_Reference);
4048 return;
4050 elsif Chars (Mech_Name) = Name_Descriptor then
4051 Check_VMS (Mech_Name);
4052 Set_Mechanism (Ent, By_Descriptor);
4053 return;
4055 elsif Chars (Mech_Name) = Name_Copy then
4056 Error_Pragma_Arg
4057 ("bad mechanism name, Value assumed", Mech_Name);
4059 else
4060 Bad_Mechanism;
4061 end if;
4063 -- MECHANISM_NAME ::= descriptor (CLASS_NAME)
4064 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4066 -- Note: this form is parsed as an indexed component
4068 elsif Nkind (Mech_Name) = N_Indexed_Component then
4069 Class := First (Expressions (Mech_Name));
4071 if Nkind (Prefix (Mech_Name)) /= N_Identifier
4072 or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
4073 or else Present (Next (Class))
4074 then
4075 Bad_Mechanism;
4076 end if;
4078 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
4079 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4081 -- Note: this form is parsed as a function call
4083 elsif Nkind (Mech_Name) = N_Function_Call then
4085 Param := First (Parameter_Associations (Mech_Name));
4087 if Nkind (Name (Mech_Name)) /= N_Identifier
4088 or else Chars (Name (Mech_Name)) /= Name_Descriptor
4089 or else Present (Next (Param))
4090 or else No (Selector_Name (Param))
4091 or else Chars (Selector_Name (Param)) /= Name_Class
4092 then
4093 Bad_Mechanism;
4094 else
4095 Class := Explicit_Actual_Parameter (Param);
4096 end if;
4098 else
4099 Bad_Mechanism;
4100 end if;
4102 -- Fall through here with Class set to descriptor class name
4104 Check_VMS (Mech_Name);
4106 if Nkind (Class) /= N_Identifier then
4107 Bad_Class;
4109 elsif Chars (Class) = Name_UBS then
4110 Set_Mechanism (Ent, By_Descriptor_UBS);
4112 elsif Chars (Class) = Name_UBSB then
4113 Set_Mechanism (Ent, By_Descriptor_UBSB);
4115 elsif Chars (Class) = Name_UBA then
4116 Set_Mechanism (Ent, By_Descriptor_UBA);
4118 elsif Chars (Class) = Name_S then
4119 Set_Mechanism (Ent, By_Descriptor_S);
4121 elsif Chars (Class) = Name_SB then
4122 Set_Mechanism (Ent, By_Descriptor_SB);
4124 elsif Chars (Class) = Name_A then
4125 Set_Mechanism (Ent, By_Descriptor_A);
4127 elsif Chars (Class) = Name_NCA then
4128 Set_Mechanism (Ent, By_Descriptor_NCA);
4130 else
4131 Bad_Class;
4132 end if;
4133 end Set_Mechanism_Value;
4135 ---------------------------
4136 -- Set_Ravenscar_Profile --
4137 ---------------------------
4139 -- The tasks to be done here are
4141 -- Set required policies
4143 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4144 -- pragma Locking_Policy (Ceiling_Locking)
4146 -- Set Detect_Blocking mode
4148 -- Set required restrictions (see System.Rident for detailed list)
4150 procedure Set_Ravenscar_Profile (N : Node_Id) is
4151 begin
4152 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4154 if Task_Dispatching_Policy /= ' '
4155 and then Task_Dispatching_Policy /= 'F'
4156 then
4157 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4158 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4160 -- Set the FIFO_Within_Priorities policy, but always
4161 -- preserve System_Location since we like the error
4162 -- message with the run time name.
4164 else
4165 Task_Dispatching_Policy := 'F';
4167 if Task_Dispatching_Policy_Sloc /= System_Location then
4168 Task_Dispatching_Policy_Sloc := Loc;
4169 end if;
4170 end if;
4172 -- pragma Locking_Policy (Ceiling_Locking)
4174 if Locking_Policy /= ' '
4175 and then Locking_Policy /= 'C'
4176 then
4177 Error_Msg_Sloc := Locking_Policy_Sloc;
4178 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4180 -- Set the Ceiling_Locking policy, but always preserve
4181 -- System_Location since we like the error message with the
4182 -- run time name.
4184 else
4185 Locking_Policy := 'C';
4187 if Locking_Policy_Sloc /= System_Location then
4188 Locking_Policy_Sloc := Loc;
4189 end if;
4190 end if;
4192 -- pragma Detect_Blocking
4194 Detect_Blocking := True;
4196 -- Set the corresponding restrictions
4198 Set_Profile_Restrictions (Ravenscar, N, Warn => False);
4199 end Set_Ravenscar_Profile;
4201 -- Start of processing for Analyze_Pragma
4203 begin
4204 if not Is_Pragma_Name (Chars (N)) then
4205 if Warn_On_Unrecognized_Pragma then
4206 Error_Pragma ("unrecognized pragma%!?");
4207 else
4208 raise Pragma_Exit;
4209 end if;
4210 else
4211 Prag_Id := Get_Pragma_Id (Chars (N));
4212 end if;
4214 -- Preset arguments
4216 Arg1 := Empty;
4217 Arg2 := Empty;
4218 Arg3 := Empty;
4219 Arg4 := Empty;
4221 if Present (Pragma_Argument_Associations (N)) then
4222 Arg1 := First (Pragma_Argument_Associations (N));
4224 if Present (Arg1) then
4225 Arg2 := Next (Arg1);
4227 if Present (Arg2) then
4228 Arg3 := Next (Arg2);
4230 if Present (Arg3) then
4231 Arg4 := Next (Arg3);
4232 end if;
4233 end if;
4234 end if;
4235 end if;
4237 -- Count number of arguments
4239 declare
4240 Arg_Node : Node_Id;
4241 begin
4242 Arg_Count := 0;
4243 Arg_Node := Arg1;
4244 while Present (Arg_Node) loop
4245 Arg_Count := Arg_Count + 1;
4246 Next (Arg_Node);
4247 end loop;
4248 end;
4250 -- An enumeration type defines the pragmas that are supported by the
4251 -- implementation. Get_Pragma_Id (in package Prag) transorms a name
4252 -- into the corresponding enumeration value for the following case.
4254 case Prag_Id is
4256 -----------------
4257 -- Abort_Defer --
4258 -----------------
4260 -- pragma Abort_Defer;
4262 when Pragma_Abort_Defer =>
4263 GNAT_Pragma;
4264 Check_Arg_Count (0);
4266 -- The only required semantic processing is to check the
4267 -- placement. This pragma must appear at the start of the
4268 -- statement sequence of a handled sequence of statements.
4270 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
4271 or else N /= First (Statements (Parent (N)))
4272 then
4273 Pragma_Misplaced;
4274 end if;
4276 ------------
4277 -- Ada_83 --
4278 ------------
4280 -- pragma Ada_83;
4282 -- Note: this pragma also has some specific processing in Par.Prag
4283 -- because we want to set the Ada version mode during parsing.
4285 when Pragma_Ada_83 =>
4286 GNAT_Pragma;
4287 Ada_Version := Ada_83;
4288 Check_Arg_Count (0);
4290 ------------
4291 -- Ada_95 --
4292 ------------
4294 -- pragma Ada_95;
4296 -- Note: this pragma also has some specific processing in Par.Prag
4297 -- because we want to set the Ada 83 version mode during parsing.
4299 when Pragma_Ada_95 =>
4300 GNAT_Pragma;
4301 Ada_Version := Ada_95;
4302 Check_Arg_Count (0);
4304 ------------
4305 -- Ada_05 --
4306 ------------
4308 -- pragma Ada_05;
4309 -- pragma Ada_05 (LOCAL_NAME);
4311 -- Note: this pragma also has some specific processing in Par.Prag
4312 -- because we want to set the Ada 2005 version mode during parsing.
4314 when Pragma_Ada_05 => declare
4315 E_Id : Node_Id;
4317 begin
4318 GNAT_Pragma;
4320 if Arg_Count = 1 then
4321 Check_Arg_Is_Local_Name (Arg1);
4322 E_Id := Expression (Arg1);
4324 if Etype (E_Id) = Any_Type then
4325 return;
4326 end if;
4328 Set_Is_Ada_2005 (Entity (E_Id));
4330 else
4331 Ada_Version := Ada_05;
4332 Check_Arg_Count (0);
4333 end if;
4334 end;
4336 ----------------------
4337 -- All_Calls_Remote --
4338 ----------------------
4340 -- pragma All_Calls_Remote [(library_package_NAME)];
4342 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
4343 Lib_Entity : Entity_Id;
4345 begin
4346 Check_Ada_83_Warning;
4347 Check_Valid_Library_Unit_Pragma;
4349 if Nkind (N) = N_Null_Statement then
4350 return;
4351 end if;
4353 Lib_Entity := Find_Lib_Unit_Name;
4355 -- This pragma should only apply to a RCI unit (RM E.2.3(23)).
4357 if Present (Lib_Entity)
4358 and then not Debug_Flag_U
4359 then
4360 if not Is_Remote_Call_Interface (Lib_Entity) then
4361 Error_Pragma ("pragma% only apply to rci unit");
4363 -- Set flag for entity of the library unit
4365 else
4366 Set_Has_All_Calls_Remote (Lib_Entity);
4367 end if;
4369 end if;
4370 end All_Calls_Remote;
4372 --------------
4373 -- Annotate --
4374 --------------
4376 -- pragma Annotate (IDENTIFIER {, ARG});
4377 -- ARG ::= NAME | EXPRESSION
4379 when Pragma_Annotate => Annotate : begin
4380 GNAT_Pragma;
4381 Check_At_Least_N_Arguments (1);
4382 Check_Arg_Is_Identifier (Arg1);
4384 declare
4385 Arg : Node_Id := Arg2;
4386 Exp : Node_Id;
4388 begin
4389 while Present (Arg) loop
4390 Exp := Expression (Arg);
4391 Analyze (Exp);
4393 if Is_Entity_Name (Exp) then
4394 null;
4396 elsif Nkind (Exp) = N_String_Literal then
4397 Resolve (Exp, Standard_String);
4399 elsif Is_Overloaded (Exp) then
4400 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
4402 else
4403 Resolve (Exp);
4404 end if;
4406 Next (Arg);
4407 end loop;
4408 end;
4409 end Annotate;
4411 ------------
4412 -- Assert --
4413 ------------
4415 -- pragma Assert (Boolean_EXPRESSION [, static_string_EXPRESSION]);
4417 when Pragma_Assert =>
4418 GNAT_Pragma;
4419 Check_No_Identifiers;
4421 if Arg_Count > 1 then
4422 Check_Arg_Count (2);
4423 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4424 end if;
4426 -- If expansion is active and assertions are inactive, then
4427 -- we rewrite the Assertion as:
4429 -- if False and then condition then
4430 -- null;
4431 -- end if;
4433 -- The reason we do this rewriting during semantic analysis
4434 -- rather than as part of normal expansion is that we cannot
4435 -- analyze and expand the code for the boolean expression
4436 -- directly, or it may cause insertion of actions that would
4437 -- escape the attempt to suppress the assertion code.
4439 if Expander_Active and not Assertions_Enabled then
4440 Rewrite (N,
4441 Make_If_Statement (Loc,
4442 Condition =>
4443 Make_And_Then (Loc,
4444 Left_Opnd => New_Occurrence_Of (Standard_False, Loc),
4445 Right_Opnd => Get_Pragma_Arg (Arg1)),
4446 Then_Statements => New_List (
4447 Make_Null_Statement (Loc))));
4449 Analyze (N);
4451 -- Otherwise (if assertions are enabled, or if we are not
4452 -- operating with expansion active), then we just analyze
4453 -- and resolve the expression.
4455 else
4456 Analyze_And_Resolve (Expression (Arg1), Any_Boolean);
4457 end if;
4459 ---------------
4460 -- AST_Entry --
4461 ---------------
4463 -- pragma AST_Entry (entry_IDENTIFIER);
4465 when Pragma_AST_Entry => AST_Entry : declare
4466 Ent : Node_Id;
4468 begin
4469 GNAT_Pragma;
4470 Check_VMS (N);
4471 Check_Arg_Count (1);
4472 Check_No_Identifiers;
4473 Check_Arg_Is_Local_Name (Arg1);
4474 Ent := Entity (Expression (Arg1));
4476 -- Note: the implementation of the AST_Entry pragma could handle
4477 -- the entry family case fine, but for now we are consistent with
4478 -- the DEC rules, and do not allow the pragma, which of course
4479 -- has the effect of also forbidding the attribute.
4481 if Ekind (Ent) /= E_Entry then
4482 Error_Pragma_Arg
4483 ("pragma% argument must be simple entry name", Arg1);
4485 elsif Is_AST_Entry (Ent) then
4486 Error_Pragma_Arg
4487 ("duplicate % pragma for entry", Arg1);
4489 elsif Has_Homonym (Ent) then
4490 Error_Pragma_Arg
4491 ("pragma% argument cannot specify overloaded entry", Arg1);
4493 else
4494 declare
4495 FF : constant Entity_Id := First_Formal (Ent);
4497 begin
4498 if Present (FF) then
4499 if Present (Next_Formal (FF)) then
4500 Error_Pragma_Arg
4501 ("entry for pragma% can have only one argument",
4502 Arg1);
4504 elsif Parameter_Mode (FF) /= E_In_Parameter then
4505 Error_Pragma_Arg
4506 ("entry parameter for pragma% must have mode IN",
4507 Arg1);
4508 end if;
4509 end if;
4510 end;
4512 Set_Is_AST_Entry (Ent);
4513 end if;
4514 end AST_Entry;
4516 ------------------
4517 -- Asynchronous --
4518 ------------------
4520 -- pragma Asynchronous (LOCAL_NAME);
4522 when Pragma_Asynchronous => Asynchronous : declare
4523 Nm : Entity_Id;
4524 C_Ent : Entity_Id;
4525 L : List_Id;
4526 S : Node_Id;
4527 N : Node_Id;
4528 Formal : Entity_Id;
4530 procedure Process_Async_Pragma;
4531 -- Common processing for procedure and access-to-procedure case
4533 --------------------------
4534 -- Process_Async_Pragma --
4535 --------------------------
4537 procedure Process_Async_Pragma is
4538 begin
4539 if not Present (L) then
4540 Set_Is_Asynchronous (Nm);
4541 return;
4542 end if;
4544 -- The formals should be of mode IN (RM E.4.1(6))
4546 S := First (L);
4547 while Present (S) loop
4548 Formal := Defining_Identifier (S);
4550 if Nkind (Formal) = N_Defining_Identifier
4551 and then Ekind (Formal) /= E_In_Parameter
4552 then
4553 Error_Pragma_Arg
4554 ("pragma% procedure can only have IN parameter",
4555 Arg1);
4556 end if;
4558 Next (S);
4559 end loop;
4561 Set_Is_Asynchronous (Nm);
4562 end Process_Async_Pragma;
4564 -- Start of processing for pragma Asynchronous
4566 begin
4567 Check_Ada_83_Warning;
4568 Check_No_Identifiers;
4569 Check_Arg_Count (1);
4570 Check_Arg_Is_Local_Name (Arg1);
4572 if Debug_Flag_U then
4573 return;
4574 end if;
4576 C_Ent := Cunit_Entity (Current_Sem_Unit);
4577 Analyze (Expression (Arg1));
4578 Nm := Entity (Expression (Arg1));
4580 if not Is_Remote_Call_Interface (C_Ent)
4581 and then not Is_Remote_Types (C_Ent)
4582 then
4583 -- This pragma should only appear in an RCI or Remote Types
4584 -- unit (RM E.4.1(4))
4586 Error_Pragma
4587 ("pragma% not in Remote_Call_Interface or " &
4588 "Remote_Types unit");
4589 end if;
4591 if Ekind (Nm) = E_Procedure
4592 and then Nkind (Parent (Nm)) = N_Procedure_Specification
4593 then
4594 if not Is_Remote_Call_Interface (Nm) then
4595 Error_Pragma_Arg
4596 ("pragma% cannot be applied on non-remote procedure",
4597 Arg1);
4598 end if;
4600 L := Parameter_Specifications (Parent (Nm));
4601 Process_Async_Pragma;
4602 return;
4604 elsif Ekind (Nm) = E_Function then
4605 Error_Pragma_Arg
4606 ("pragma% cannot be applied to function", Arg1);
4608 elsif Ekind (Nm) = E_Record_Type
4609 and then Present (Corresponding_Remote_Type (Nm))
4610 then
4611 -- A record type that is the Equivalent_Type for
4612 -- a remote access-to-subprogram type.
4614 N := Declaration_Node (Corresponding_Remote_Type (Nm));
4616 if Nkind (N) = N_Full_Type_Declaration
4617 and then Nkind (Type_Definition (N)) =
4618 N_Access_Procedure_Definition
4619 then
4620 L := Parameter_Specifications (Type_Definition (N));
4621 Process_Async_Pragma;
4623 if Is_Asynchronous (Nm)
4624 and then Expander_Active
4625 then
4626 RACW_Type_Is_Asynchronous (
4627 Underlying_RACW_Type (Nm));
4628 end if;
4630 else
4631 Error_Pragma_Arg
4632 ("pragma% cannot reference access-to-function type",
4633 Arg1);
4634 end if;
4636 -- Only other possibility is Access-to-class-wide type
4638 elsif Is_Access_Type (Nm)
4639 and then Is_Class_Wide_Type (Designated_Type (Nm))
4640 then
4641 Check_First_Subtype (Arg1);
4642 Set_Is_Asynchronous (Nm);
4643 if Expander_Active then
4644 RACW_Type_Is_Asynchronous (Nm);
4645 end if;
4647 else
4648 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
4649 end if;
4650 end Asynchronous;
4652 ------------
4653 -- Atomic --
4654 ------------
4656 -- pragma Atomic (LOCAL_NAME);
4658 when Pragma_Atomic =>
4659 Process_Atomic_Shared_Volatile;
4661 -----------------------
4662 -- Atomic_Components --
4663 -----------------------
4665 -- pragma Atomic_Components (array_LOCAL_NAME);
4667 -- This processing is shared by Volatile_Components
4669 when Pragma_Atomic_Components |
4670 Pragma_Volatile_Components =>
4672 Atomic_Components : declare
4673 E_Id : Node_Id;
4674 E : Entity_Id;
4675 D : Node_Id;
4676 K : Node_Kind;
4678 begin
4679 Check_Ada_83_Warning;
4680 Check_No_Identifiers;
4681 Check_Arg_Count (1);
4682 Check_Arg_Is_Local_Name (Arg1);
4683 E_Id := Expression (Arg1);
4685 if Etype (E_Id) = Any_Type then
4686 return;
4687 end if;
4689 E := Entity (E_Id);
4691 if Rep_Item_Too_Early (E, N)
4692 or else
4693 Rep_Item_Too_Late (E, N)
4694 then
4695 return;
4696 end if;
4698 D := Declaration_Node (E);
4699 K := Nkind (D);
4701 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
4702 or else
4703 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
4704 and then Nkind (D) = N_Object_Declaration
4705 and then Nkind (Object_Definition (D)) =
4706 N_Constrained_Array_Definition)
4707 then
4708 -- The flag is set on the object, or on the base type
4710 if Nkind (D) /= N_Object_Declaration then
4711 E := Base_Type (E);
4712 end if;
4714 Set_Has_Volatile_Components (E);
4716 if Prag_Id = Pragma_Atomic_Components then
4717 Set_Has_Atomic_Components (E);
4719 if Is_Packed (E) then
4720 Set_Is_Packed (E, False);
4722 Error_Pragma_Arg
4723 ("?Pack canceled, cannot pack atomic components",
4724 Arg1);
4725 end if;
4726 end if;
4728 else
4729 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
4730 end if;
4731 end Atomic_Components;
4733 --------------------
4734 -- Attach_Handler --
4735 --------------------
4737 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
4739 when Pragma_Attach_Handler =>
4740 Check_Ada_83_Warning;
4741 Check_No_Identifiers;
4742 Check_Arg_Count (2);
4744 if No_Run_Time_Mode then
4745 Error_Msg_CRT ("Attach_Handler pragma", N);
4746 else
4747 Check_Interrupt_Or_Attach_Handler;
4749 -- The expression that designates the attribute may
4750 -- depend on a discriminant, and is therefore a per-
4751 -- object expression, to be expanded in the init proc.
4752 -- If expansion is enabled, perform semantic checks
4753 -- on a copy only.
4755 if Expander_Active then
4756 declare
4757 Temp : constant Node_Id :=
4758 New_Copy_Tree (Expression (Arg2));
4759 begin
4760 Set_Parent (Temp, N);
4761 Pre_Analyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
4762 end;
4764 else
4765 Analyze (Expression (Arg2));
4766 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
4767 end if;
4769 Process_Interrupt_Or_Attach_Handler;
4770 end if;
4772 --------------------
4773 -- C_Pass_By_Copy --
4774 --------------------
4776 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
4778 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
4779 Arg : Node_Id;
4780 Val : Uint;
4782 begin
4783 GNAT_Pragma;
4784 Check_Valid_Configuration_Pragma;
4785 Check_Arg_Count (1);
4786 Check_Optional_Identifier (Arg1, "max_size");
4788 Arg := Expression (Arg1);
4789 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
4791 Val := Expr_Value (Arg);
4793 if Val <= 0 then
4794 Error_Pragma_Arg
4795 ("maximum size for pragma% must be positive", Arg1);
4797 elsif UI_Is_In_Int_Range (Val) then
4798 Default_C_Record_Mechanism := UI_To_Int (Val);
4800 -- If a giant value is given, Int'Last will do well enough.
4801 -- If sometime someone complains that a record larger than
4802 -- two gigabytes is not copied, we will worry about it then!
4804 else
4805 Default_C_Record_Mechanism := Mechanism_Type'Last;
4806 end if;
4807 end C_Pass_By_Copy;
4809 -------------
4810 -- Comment --
4811 -------------
4813 -- pragma Comment (static_string_EXPRESSION)
4815 -- Processing for pragma Comment shares the circuitry for
4816 -- pragma Ident. The only differences are that Ident enforces
4817 -- a limit of 31 characters on its argument, and also enforces
4818 -- limitations on placement for DEC compatibility. Pragma
4819 -- Comment shares neither of these restrictions.
4821 -------------------
4822 -- Common_Object --
4823 -------------------
4825 -- pragma Common_Object (
4826 -- [Internal =>] LOCAL_NAME,
4827 -- [, [External =>] EXTERNAL_SYMBOL]
4828 -- [, [Size =>] EXTERNAL_SYMBOL]);
4830 -- Processing for this pragma is shared with Psect_Object
4832 --------------------------
4833 -- Compile_Time_Warning --
4834 --------------------------
4836 -- pragma Compile_Time_Warning
4837 -- (boolean_EXPRESSION, static_string_EXPRESSION);
4839 when Pragma_Compile_Time_Warning => Compile_Time_Warning : declare
4840 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
4842 begin
4843 GNAT_Pragma;
4844 Check_Arg_Count (2);
4845 Check_No_Identifiers;
4846 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4847 Analyze_And_Resolve (Arg1x, Standard_Boolean);
4849 if Compile_Time_Known_Value (Arg1x) then
4850 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
4851 String_To_Name_Buffer (Strval (Get_Pragma_Arg (Arg2)));
4852 Add_Char_To_Name_Buffer ('?');
4854 declare
4855 Msg : String (1 .. Name_Len) :=
4856 Name_Buffer (1 .. Name_Len);
4858 B : Natural;
4860 begin
4861 -- This loop looks for multiple lines separated by
4862 -- ASCII.LF and breaks them into continuation error
4863 -- messages marked with the usual back slash.
4865 B := 1;
4866 for S in 2 .. Msg'Length - 1 loop
4867 if Msg (S) = ASCII.LF then
4868 Msg (S) := '?';
4869 Error_Msg_N (Msg (B .. S), Arg1);
4870 B := S;
4871 Msg (B) := '\';
4872 end if;
4873 end loop;
4875 Error_Msg_N (Msg (B .. Msg'Length), Arg1);
4876 end;
4877 end if;
4878 end if;
4879 end Compile_Time_Warning;
4881 ----------------------------
4882 -- Complex_Representation --
4883 ----------------------------
4885 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
4887 when Pragma_Complex_Representation => Complex_Representation : declare
4888 E_Id : Entity_Id;
4889 E : Entity_Id;
4890 Ent : Entity_Id;
4892 begin
4893 GNAT_Pragma;
4894 Check_Arg_Count (1);
4895 Check_Optional_Identifier (Arg1, Name_Entity);
4896 Check_Arg_Is_Local_Name (Arg1);
4897 E_Id := Expression (Arg1);
4899 if Etype (E_Id) = Any_Type then
4900 return;
4901 end if;
4903 E := Entity (E_Id);
4905 if not Is_Record_Type (E) then
4906 Error_Pragma_Arg
4907 ("argument for pragma% must be record type", Arg1);
4908 end if;
4910 Ent := First_Entity (E);
4912 if No (Ent)
4913 or else No (Next_Entity (Ent))
4914 or else Present (Next_Entity (Next_Entity (Ent)))
4915 or else not Is_Floating_Point_Type (Etype (Ent))
4916 or else Etype (Ent) /= Etype (Next_Entity (Ent))
4917 then
4918 Error_Pragma_Arg
4919 ("record for pragma% must have two fields of same fpt type",
4920 Arg1);
4922 else
4923 Set_Has_Complex_Representation (Base_Type (E));
4924 end if;
4925 end Complex_Representation;
4927 -------------------------
4928 -- Component_Alignment --
4929 -------------------------
4931 -- pragma Component_Alignment (
4932 -- [Form =>] ALIGNMENT_CHOICE
4933 -- [, [Name =>] type_LOCAL_NAME]);
4935 -- ALIGNMENT_CHOICE ::=
4936 -- Component_Size
4937 -- | Component_Size_4
4938 -- | Storage_Unit
4939 -- | Default
4941 when Pragma_Component_Alignment => Component_AlignmentP : declare
4942 Args : Args_List (1 .. 2);
4943 Names : constant Name_List (1 .. 2) := (
4944 Name_Form,
4945 Name_Name);
4947 Form : Node_Id renames Args (1);
4948 Name : Node_Id renames Args (2);
4950 Atype : Component_Alignment_Kind;
4951 Typ : Entity_Id;
4953 begin
4954 GNAT_Pragma;
4955 Gather_Associations (Names, Args);
4957 if No (Form) then
4958 Error_Pragma ("missing Form argument for pragma%");
4959 end if;
4961 Check_Arg_Is_Identifier (Form);
4963 -- Get proper alignment, note that Default = Component_Size
4964 -- on all machines we have so far, and we want to set this
4965 -- value rather than the default value to indicate that it
4966 -- has been explicitly set (and thus will not get overridden
4967 -- by the default component alignment for the current scope)
4969 if Chars (Form) = Name_Component_Size then
4970 Atype := Calign_Component_Size;
4972 elsif Chars (Form) = Name_Component_Size_4 then
4973 Atype := Calign_Component_Size_4;
4975 elsif Chars (Form) = Name_Default then
4976 Atype := Calign_Component_Size;
4978 elsif Chars (Form) = Name_Storage_Unit then
4979 Atype := Calign_Storage_Unit;
4981 else
4982 Error_Pragma_Arg
4983 ("invalid Form parameter for pragma%", Form);
4984 end if;
4986 -- Case with no name, supplied, affects scope table entry
4988 if No (Name) then
4989 Scope_Stack.Table
4990 (Scope_Stack.Last).Component_Alignment_Default := Atype;
4992 -- Case of name supplied
4994 else
4995 Check_Arg_Is_Local_Name (Name);
4996 Find_Type (Name);
4997 Typ := Entity (Name);
4999 if Typ = Any_Type
5000 or else Rep_Item_Too_Early (Typ, N)
5001 then
5002 return;
5003 else
5004 Typ := Underlying_Type (Typ);
5005 end if;
5007 if not Is_Record_Type (Typ)
5008 and then not Is_Array_Type (Typ)
5009 then
5010 Error_Pragma_Arg
5011 ("Name parameter of pragma% must identify record or " &
5012 "array type", Name);
5013 end if;
5015 -- An explicit Component_Alignment pragma overrides an
5016 -- implicit pragma Pack, but not an explicit one.
5018 if not Has_Pragma_Pack (Base_Type (Typ)) then
5019 Set_Is_Packed (Base_Type (Typ), False);
5020 Set_Component_Alignment (Base_Type (Typ), Atype);
5021 end if;
5022 end if;
5023 end Component_AlignmentP;
5025 ----------------
5026 -- Controlled --
5027 ----------------
5029 -- pragma Controlled (first_subtype_LOCAL_NAME);
5031 when Pragma_Controlled => Controlled : declare
5032 Arg : Node_Id;
5034 begin
5035 Check_No_Identifiers;
5036 Check_Arg_Count (1);
5037 Check_Arg_Is_Local_Name (Arg1);
5038 Arg := Expression (Arg1);
5040 if not Is_Entity_Name (Arg)
5041 or else not Is_Access_Type (Entity (Arg))
5042 then
5043 Error_Pragma_Arg ("pragma% requires access type", Arg1);
5044 else
5045 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
5046 end if;
5047 end Controlled;
5049 ----------------
5050 -- Convention --
5051 ----------------
5053 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
5054 -- [Entity =>] LOCAL_NAME);
5056 when Pragma_Convention => Convention : declare
5057 C : Convention_Id;
5058 E : Entity_Id;
5059 begin
5060 Check_Ada_83_Warning;
5061 Check_Arg_Count (2);
5062 Process_Convention (C, E);
5063 end Convention;
5065 ---------------------------
5066 -- Convention_Identifier --
5067 ---------------------------
5069 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
5070 -- [Convention =>] convention_IDENTIFIER);
5072 when Pragma_Convention_Identifier => Convention_Identifier : declare
5073 Idnam : Name_Id;
5074 Cname : Name_Id;
5076 begin
5077 GNAT_Pragma;
5078 Check_Arg_Count (2);
5079 Check_Optional_Identifier (Arg1, Name_Name);
5080 Check_Optional_Identifier (Arg2, Name_Convention);
5081 Check_Arg_Is_Identifier (Arg1);
5082 Check_Arg_Is_Identifier (Arg1);
5083 Idnam := Chars (Expression (Arg1));
5084 Cname := Chars (Expression (Arg2));
5086 if Is_Convention_Name (Cname) then
5087 Record_Convention_Identifier
5088 (Idnam, Get_Convention_Id (Cname));
5089 else
5090 Error_Pragma_Arg
5091 ("second arg for % pragma must be convention", Arg2);
5092 end if;
5093 end Convention_Identifier;
5095 ---------------
5096 -- CPP_Class --
5097 ---------------
5099 -- pragma CPP_Class ([Entity =>] local_NAME)
5101 when Pragma_CPP_Class => CPP_Class : declare
5102 Arg : Node_Id;
5103 Typ : Entity_Id;
5104 Default_DTC : Entity_Id := Empty;
5105 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5106 C : Entity_Id;
5107 Tag_C : Entity_Id;
5109 begin
5110 GNAT_Pragma;
5111 Check_Arg_Count (1);
5112 Check_Optional_Identifier (Arg1, Name_Entity);
5113 Check_Arg_Is_Local_Name (Arg1);
5115 Arg := Expression (Arg1);
5116 Analyze (Arg);
5118 if Etype (Arg) = Any_Type then
5119 return;
5120 end if;
5122 if not Is_Entity_Name (Arg)
5123 or else not Is_Type (Entity (Arg))
5124 then
5125 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
5126 end if;
5128 Typ := Entity (Arg);
5130 if not Is_Record_Type (Typ) then
5131 Error_Pragma_Arg ("pragma% applicable to a record, "
5132 & "tagged record or record extension", Arg1);
5133 end if;
5135 Default_DTC := First_Component (Typ);
5136 while Present (Default_DTC)
5137 and then Etype (Default_DTC) /= VTP_Type
5138 loop
5139 Next_Component (Default_DTC);
5140 end loop;
5142 -- Case of non tagged type
5144 if not Is_Tagged_Type (Typ) then
5145 Set_Is_CPP_Class (Typ);
5147 if Present (Default_DTC) then
5148 Error_Pragma_Arg
5149 ("only tagged records can contain vtable pointers", Arg1);
5150 end if;
5152 -- Case of tagged type with no vtable ptr
5154 -- What is test for Typ = Root_Typ (Typ) about here ???
5156 elsif Is_Tagged_Type (Typ)
5157 and then Typ = Root_Type (Typ)
5158 and then No (Default_DTC)
5159 then
5160 Error_Pragma_Arg
5161 ("a cpp_class must contain a vtable pointer", Arg1);
5163 -- Tagged type that has a vtable ptr
5165 elsif Present (Default_DTC) then
5166 Set_Is_CPP_Class (Typ);
5167 Set_Is_Limited_Record (Typ);
5168 Set_Is_Tag (Default_DTC);
5169 Set_DT_Entry_Count (Default_DTC, No_Uint);
5171 -- Since a CPP type has no direct link to its associated tag
5172 -- most tags checks cannot be performed
5174 Set_Kill_Tag_Checks (Typ);
5175 Set_Kill_Tag_Checks (Class_Wide_Type (Typ));
5177 -- Get rid of the _tag component when there was one.
5178 -- It is only useful for regular tagged types
5180 if Expander_Active and then Typ = Root_Type (Typ) then
5182 Tag_C := Tag_Component (Typ);
5183 C := First_Entity (Typ);
5185 if C = Tag_C then
5186 Set_First_Entity (Typ, Next_Entity (Tag_C));
5188 else
5189 while Next_Entity (C) /= Tag_C loop
5190 Next_Entity (C);
5191 end loop;
5193 Set_Next_Entity (C, Next_Entity (Tag_C));
5194 end if;
5195 end if;
5196 end if;
5197 end CPP_Class;
5199 ---------------------
5200 -- CPP_Constructor --
5201 ---------------------
5203 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME);
5205 when Pragma_CPP_Constructor => CPP_Constructor : declare
5206 Id : Entity_Id;
5207 Def_Id : Entity_Id;
5209 begin
5210 GNAT_Pragma;
5211 Check_Arg_Count (1);
5212 Check_Optional_Identifier (Arg1, Name_Entity);
5213 Check_Arg_Is_Local_Name (Arg1);
5215 Id := Expression (Arg1);
5216 Find_Program_Unit_Name (Id);
5218 -- If we did not find the name, we are done
5220 if Etype (Id) = Any_Type then
5221 return;
5222 end if;
5224 Def_Id := Entity (Id);
5226 if Ekind (Def_Id) = E_Function
5227 and then Is_Class_Wide_Type (Etype (Def_Id))
5228 and then Is_CPP_Class (Etype (Etype (Def_Id)))
5229 then
5230 -- What the heck is this??? this pragma allows only 1 arg
5232 if Arg_Count >= 2 then
5233 Check_At_Most_N_Arguments (3);
5234 Process_Interface_Name (Def_Id, Arg2, Arg3);
5235 end if;
5237 if No (Parameter_Specifications (Parent (Def_Id))) then
5238 Set_Has_Completion (Def_Id);
5239 Set_Is_Constructor (Def_Id);
5240 else
5241 Error_Pragma_Arg
5242 ("non-default constructors not implemented", Arg1);
5243 end if;
5245 else
5246 Error_Pragma_Arg
5247 ("pragma% requires function returning a 'C'P'P_Class type",
5248 Arg1);
5249 end if;
5250 end CPP_Constructor;
5252 -----------------
5253 -- CPP_Virtual --
5254 -----------------
5256 -- pragma CPP_Virtual
5257 -- [Entity =>] LOCAL_NAME
5258 -- [ [Vtable_Ptr =>] LOCAL_NAME,
5259 -- [Position =>] static_integer_EXPRESSION]);
5261 when Pragma_CPP_Virtual => CPP_Virtual : declare
5262 Arg : Node_Id;
5263 Typ : Entity_Id;
5264 Subp : Entity_Id;
5265 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5266 DTC : Entity_Id;
5267 V : Uint;
5269 begin
5270 GNAT_Pragma;
5272 if Arg_Count = 3 then
5273 Check_Optional_Identifier (Arg2, "vtable_ptr");
5275 -- We allow Entry_Count as well as Position for the third
5276 -- parameter for back compatibility with versions of GNAT
5277 -- before version 3.12. The documentation has always said
5278 -- Position, but the code up to 3.12 said Entry_Count.
5280 if Chars (Arg3) /= Name_Position then
5281 Check_Optional_Identifier (Arg3, "entry_count");
5282 end if;
5284 else
5285 Check_Arg_Count (1);
5286 end if;
5288 Check_Optional_Identifier (Arg1, Name_Entity);
5289 Check_Arg_Is_Local_Name (Arg1);
5291 -- First argument must be a subprogram name
5293 Arg := Expression (Arg1);
5294 Find_Program_Unit_Name (Arg);
5296 if Etype (Arg) = Any_Type then
5297 return;
5298 else
5299 Subp := Entity (Arg);
5300 end if;
5302 if not (Is_Subprogram (Subp)
5303 and then Is_Dispatching_Operation (Subp))
5304 then
5305 Error_Pragma_Arg
5306 ("pragma% must reference a primitive operation", Arg1);
5307 end if;
5309 Typ := Find_Dispatching_Type (Subp);
5311 -- If only one Argument defaults are :
5312 -- . DTC_Entity is the default Vtable pointer
5313 -- . DT_Position will be set at the freezing point
5315 if Arg_Count = 1 then
5316 Set_DTC_Entity (Subp, Tag_Component (Typ));
5317 return;
5318 end if;
5320 -- Second argument is a component name of type Vtable_Ptr
5322 Arg := Expression (Arg2);
5324 if Nkind (Arg) /= N_Identifier then
5325 Error_Msg_NE ("must be a& component name", Arg, Typ);
5326 raise Pragma_Exit;
5327 end if;
5329 DTC := First_Component (Typ);
5330 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5331 Next_Component (DTC);
5332 end loop;
5334 if No (DTC) then
5335 Error_Msg_NE ("must be a& component name", Arg, Typ);
5336 raise Pragma_Exit;
5338 elsif Etype (DTC) /= VTP_Type then
5339 Wrong_Type (Arg, VTP_Type);
5340 return;
5341 end if;
5343 -- Third argument is an integer (DT_Position)
5345 Arg := Expression (Arg3);
5346 Analyze_And_Resolve (Arg, Any_Integer);
5348 if not Is_Static_Expression (Arg) then
5349 Flag_Non_Static_Expr
5350 ("third argument of pragma CPP_Virtual must be static!",
5351 Arg3);
5352 raise Pragma_Exit;
5354 else
5355 V := Expr_Value (Expression (Arg3));
5357 if V <= 0 then
5358 Error_Pragma_Arg
5359 ("third argument of pragma% must be positive",
5360 Arg3);
5362 else
5363 Set_DTC_Entity (Subp, DTC);
5364 Set_DT_Position (Subp, V);
5365 end if;
5366 end if;
5367 end CPP_Virtual;
5369 ----------------
5370 -- CPP_Vtable --
5371 ----------------
5373 -- pragma CPP_Vtable (
5374 -- [Entity =>] LOCAL_NAME
5375 -- [Vtable_Ptr =>] LOCAL_NAME,
5376 -- [Entry_Count =>] static_integer_EXPRESSION);
5378 when Pragma_CPP_Vtable => CPP_Vtable : declare
5379 Arg : Node_Id;
5380 Typ : Entity_Id;
5381 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5382 DTC : Entity_Id;
5383 V : Uint;
5384 Elmt : Elmt_Id;
5386 begin
5387 GNAT_Pragma;
5388 Check_Arg_Count (3);
5389 Check_Optional_Identifier (Arg1, Name_Entity);
5390 Check_Optional_Identifier (Arg2, "vtable_ptr");
5391 Check_Optional_Identifier (Arg3, "entry_count");
5392 Check_Arg_Is_Local_Name (Arg1);
5394 -- First argument is a record type name
5396 Arg := Expression (Arg1);
5397 Analyze (Arg);
5399 if Etype (Arg) = Any_Type then
5400 return;
5401 else
5402 Typ := Entity (Arg);
5403 end if;
5405 if not (Is_Tagged_Type (Typ) and then Is_CPP_Class (Typ)) then
5406 Error_Pragma_Arg ("'C'P'P_Class tagged type expected", Arg1);
5407 end if;
5409 -- Second argument is a component name of type Vtable_Ptr
5411 Arg := Expression (Arg2);
5413 if Nkind (Arg) /= N_Identifier then
5414 Error_Msg_NE ("must be a& component name", Arg, Typ);
5415 raise Pragma_Exit;
5416 end if;
5418 DTC := First_Component (Typ);
5419 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5420 Next_Component (DTC);
5421 end loop;
5423 if No (DTC) then
5424 Error_Msg_NE ("must be a& component name", Arg, Typ);
5425 raise Pragma_Exit;
5427 elsif Etype (DTC) /= VTP_Type then
5428 Wrong_Type (DTC, VTP_Type);
5429 return;
5431 -- If it is the first pragma Vtable, This becomes the default tag
5433 elsif (not Is_Tag (DTC))
5434 and then DT_Entry_Count (Tag_Component (Typ)) = No_Uint
5435 then
5436 Set_Is_Tag (Tag_Component (Typ), False);
5437 Set_Is_Tag (DTC, True);
5438 Set_DT_Entry_Count (DTC, No_Uint);
5439 end if;
5441 -- Those pragmas must appear before any primitive operation
5442 -- definition (except inherited ones) otherwise the default
5443 -- may be wrong
5445 Elmt := First_Elmt (Primitive_Operations (Typ));
5446 while Present (Elmt) loop
5447 if No (Alias (Node (Elmt))) then
5448 Error_Msg_Sloc := Sloc (Node (Elmt));
5449 Error_Pragma
5450 ("pragma% must appear before this primitive operation");
5451 end if;
5453 Next_Elmt (Elmt);
5454 end loop;
5456 -- Third argument is an integer (DT_Entry_Count)
5458 Arg := Expression (Arg3);
5459 Analyze_And_Resolve (Arg, Any_Integer);
5461 if not Is_Static_Expression (Arg) then
5462 Flag_Non_Static_Expr
5463 ("entry count for pragma CPP_Vtable must be a static " &
5464 "expression!", Arg3);
5465 raise Pragma_Exit;
5467 else
5468 V := Expr_Value (Expression (Arg3));
5470 if V <= 0 then
5471 Error_Pragma_Arg
5472 ("entry count for pragma% must be positive", Arg3);
5473 else
5474 Set_DT_Entry_Count (DTC, V);
5475 end if;
5476 end if;
5477 end CPP_Vtable;
5479 -----------
5480 -- Debug --
5481 -----------
5483 -- pragma Debug (PROCEDURE_CALL_STATEMENT);
5485 when Pragma_Debug => Debug : begin
5486 GNAT_Pragma;
5488 -- Rewrite into a conditional with a static condition
5490 Rewrite (N, Make_Implicit_If_Statement (N,
5491 Condition => New_Occurrence_Of (Boolean_Literals (
5492 Assertions_Enabled and Expander_Active), Loc),
5493 Then_Statements => New_List (
5494 Relocate_Node (Debug_Statement (N)))));
5495 Analyze (N);
5496 end Debug;
5498 ---------------------
5499 -- Detect_Blocking --
5500 ---------------------
5502 -- pragma Detect_Blocking;
5504 when Pragma_Detect_Blocking =>
5505 GNAT_Pragma;
5506 Check_Arg_Count (0);
5507 Check_Valid_Configuration_Pragma;
5508 Detect_Blocking := True;
5510 -------------------
5511 -- Discard_Names --
5512 -------------------
5514 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
5516 when Pragma_Discard_Names => Discard_Names : declare
5517 E_Id : Entity_Id;
5518 E : Entity_Id;
5520 begin
5521 Check_Ada_83_Warning;
5523 -- Deal with configuration pragma case
5525 if Arg_Count = 0 and then Is_Configuration_Pragma then
5526 Global_Discard_Names := True;
5527 return;
5529 -- Otherwise, check correct appropriate context
5531 else
5532 Check_Is_In_Decl_Part_Or_Package_Spec;
5534 if Arg_Count = 0 then
5536 -- If there is no parameter, then from now on this pragma
5537 -- applies to any enumeration, exception or tagged type
5538 -- defined in the current declarative part.
5540 Set_Discard_Names (Current_Scope);
5541 return;
5543 else
5544 Check_Arg_Count (1);
5545 Check_Optional_Identifier (Arg1, Name_On);
5546 Check_Arg_Is_Local_Name (Arg1);
5547 E_Id := Expression (Arg1);
5549 if Etype (E_Id) = Any_Type then
5550 return;
5551 else
5552 E := Entity (E_Id);
5553 end if;
5555 if (Is_First_Subtype (E)
5556 and then (Is_Enumeration_Type (E)
5557 or else Is_Tagged_Type (E)))
5558 or else Ekind (E) = E_Exception
5559 then
5560 Set_Discard_Names (E);
5561 else
5562 Error_Pragma_Arg
5563 ("inappropriate entity for pragma%", Arg1);
5564 end if;
5565 end if;
5566 end if;
5567 end Discard_Names;
5569 ---------------
5570 -- Elaborate --
5571 ---------------
5573 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
5575 when Pragma_Elaborate => Elaborate : declare
5576 Plist : List_Id;
5577 Parent_Node : Node_Id;
5578 Arg : Node_Id;
5579 Citem : Node_Id;
5581 begin
5582 -- Pragma must be in context items list of a compilation unit
5584 if not Is_List_Member (N) then
5585 Pragma_Misplaced;
5586 return;
5588 else
5589 Plist := List_Containing (N);
5590 Parent_Node := Parent (Plist);
5592 if Parent_Node = Empty
5593 or else Nkind (Parent_Node) /= N_Compilation_Unit
5594 or else Context_Items (Parent_Node) /= Plist
5595 then
5596 Pragma_Misplaced;
5597 return;
5598 end if;
5599 end if;
5601 -- Must be at least one argument
5603 if Arg_Count = 0 then
5604 Error_Pragma ("pragma% requires at least one argument");
5605 end if;
5607 -- In Ada 83 mode, there can be no items following it in the
5608 -- context list except other pragmas and implicit with clauses
5609 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
5610 -- placement rule does not apply.
5612 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5613 Citem := Next (N);
5615 while Present (Citem) loop
5616 if Nkind (Citem) = N_Pragma
5617 or else (Nkind (Citem) = N_With_Clause
5618 and then Implicit_With (Citem))
5619 then
5620 null;
5621 else
5622 Error_Pragma
5623 ("(Ada 83) pragma% must be at end of context clause");
5624 end if;
5626 Next (Citem);
5627 end loop;
5628 end if;
5630 -- Finally, the arguments must all be units mentioned in a with
5631 -- clause in the same context clause. Note we already checked
5632 -- (in Par.Prag) that the arguments are either identifiers or
5634 Arg := Arg1;
5635 Outer : while Present (Arg) loop
5636 Citem := First (Plist);
5638 Inner : while Citem /= N loop
5639 if Nkind (Citem) = N_With_Clause
5640 and then Same_Name (Name (Citem), Expression (Arg))
5641 then
5642 Set_Elaborate_Present (Citem, True);
5643 Set_Unit_Name (Expression (Arg), Name (Citem));
5645 -- With the pragma present, elaboration calls on
5646 -- subprograms from the named unit need no further
5647 -- checks, as long as the pragma appears in the current
5648 -- compilation unit. If the pragma appears in some unit
5649 -- in the context, there might still be a need for an
5650 -- Elaborate_All_Desirable from the current compilation
5651 -- to the the named unit, so we keep the check enabled.
5653 if In_Extended_Main_Source_Unit (N) then
5654 Set_Suppress_Elaboration_Warnings
5655 (Entity (Name (Citem)));
5656 end if;
5657 exit Inner;
5658 end if;
5660 Next (Citem);
5661 end loop Inner;
5663 if Citem = N then
5664 Error_Pragma_Arg
5665 ("argument of pragma% is not with'ed unit", Arg);
5666 end if;
5668 Next (Arg);
5669 end loop Outer;
5671 -- Give a warning if operating in static mode with -gnatwl
5672 -- (elaboration warnings eanbled) switch set.
5674 if Elab_Warnings and not Dynamic_Elaboration_Checks then
5675 Error_Msg_N
5676 ("?use of pragma Elaborate may not be safe", N);
5677 Error_Msg_N
5678 ("?use pragma Elaborate_All instead if possible", N);
5679 end if;
5680 end Elaborate;
5682 -------------------
5683 -- Elaborate_All --
5684 -------------------
5686 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
5688 when Pragma_Elaborate_All => Elaborate_All : declare
5689 Plist : List_Id;
5690 Parent_Node : Node_Id;
5691 Arg : Node_Id;
5692 Citem : Node_Id;
5694 begin
5695 Check_Ada_83_Warning;
5697 -- Pragma must be in context items list of a compilation unit
5699 if not Is_List_Member (N) then
5700 Pragma_Misplaced;
5701 return;
5703 else
5704 Plist := List_Containing (N);
5705 Parent_Node := Parent (Plist);
5707 if Parent_Node = Empty
5708 or else Nkind (Parent_Node) /= N_Compilation_Unit
5709 or else Context_Items (Parent_Node) /= Plist
5710 then
5711 Pragma_Misplaced;
5712 return;
5713 end if;
5714 end if;
5716 -- Must be at least one argument
5718 if Arg_Count = 0 then
5719 Error_Pragma ("pragma% requires at least one argument");
5720 end if;
5722 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
5723 -- have to appear at the end of the context clause, but may
5724 -- appear mixed in with other items, even in Ada 83 mode.
5726 -- Final check: the arguments must all be units mentioned in
5727 -- a with clause in the same context clause. Note that we
5728 -- already checked (in Par.Prag) that all the arguments are
5729 -- either identifiers or selected components.
5731 Arg := Arg1;
5732 Outr : while Present (Arg) loop
5733 Citem := First (Plist);
5735 Innr : while Citem /= N loop
5736 if Nkind (Citem) = N_With_Clause
5737 and then Same_Name (Name (Citem), Expression (Arg))
5738 then
5739 Set_Elaborate_All_Present (Citem, True);
5740 Set_Unit_Name (Expression (Arg), Name (Citem));
5742 -- Suppress warnings and elaboration checks on the named
5743 -- unit if the pragma is in the current compilation, as
5744 -- for pragma Elaborate.
5746 if In_Extended_Main_Source_Unit (N) then
5747 Set_Suppress_Elaboration_Warnings
5748 (Entity (Name (Citem)));
5749 end if;
5750 exit Innr;
5751 end if;
5753 Next (Citem);
5754 end loop Innr;
5756 if Citem = N then
5757 Set_Error_Posted (N);
5758 Error_Pragma_Arg
5759 ("argument of pragma% is not with'ed unit", Arg);
5760 end if;
5762 Next (Arg);
5763 end loop Outr;
5764 end Elaborate_All;
5766 --------------------
5767 -- Elaborate_Body --
5768 --------------------
5770 -- pragma Elaborate_Body [( library_unit_NAME )];
5772 when Pragma_Elaborate_Body => Elaborate_Body : declare
5773 Cunit_Node : Node_Id;
5774 Cunit_Ent : Entity_Id;
5776 begin
5777 Check_Ada_83_Warning;
5778 Check_Valid_Library_Unit_Pragma;
5780 if Nkind (N) = N_Null_Statement then
5781 return;
5782 end if;
5784 Cunit_Node := Cunit (Current_Sem_Unit);
5785 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
5787 if Nkind (Unit (Cunit_Node)) = N_Package_Body
5788 or else
5789 Nkind (Unit (Cunit_Node)) = N_Subprogram_Body
5790 then
5791 Error_Pragma ("pragma% must refer to a spec, not a body");
5792 else
5793 Set_Body_Required (Cunit_Node, True);
5794 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
5796 -- If we are in dynamic elaboration mode, then we suppress
5797 -- elaboration warnings for the unit, since it is definitely
5798 -- fine NOT to do dynamic checks at the first level (and such
5799 -- checks will be suppressed because no elaboration boolean
5800 -- is created for Elaborate_Body packages).
5802 -- But in the static model of elaboration, Elaborate_Body is
5803 -- definitely NOT good enough to ensure elaboration safety on
5804 -- its own, since the body may WITH other units that are not
5805 -- safe from an elaboration point of view, so a client must
5806 -- still do an Elaborate_All on such units.
5808 -- Debug flag -gnatdD restores the old behavior of 3.13,
5809 -- where Elaborate_Body always suppressed elab warnings.
5811 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
5812 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
5813 end if;
5814 end if;
5815 end Elaborate_Body;
5817 ------------------------
5818 -- Elaboration_Checks --
5819 ------------------------
5821 -- pragma Elaboration_Checks (Static | Dynamic);
5823 when Pragma_Elaboration_Checks =>
5824 GNAT_Pragma;
5825 Check_Arg_Count (1);
5826 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
5827 Dynamic_Elaboration_Checks :=
5828 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
5830 ---------------
5831 -- Eliminate --
5832 ---------------
5834 -- pragma Eliminate (
5835 -- [Unit_Name =>] IDENTIFIER |
5836 -- SELECTED_COMPONENT
5837 -- [,[Entity =>] IDENTIFIER |
5838 -- SELECTED_COMPONENT |
5839 -- STRING_LITERAL]
5840 -- [,]OVERLOADING_RESOLUTION);
5842 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
5843 -- SOURCE_LOCATION
5845 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
5846 -- FUNCTION_PROFILE
5848 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
5850 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
5851 -- Result_Type => result_SUBTYPE_NAME]
5853 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
5854 -- SUBTYPE_NAME ::= STRING_LITERAL
5856 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
5857 -- SOURCE_TRACE ::= STRING_LITERAL
5859 when Pragma_Eliminate => Eliminate : declare
5860 Args : Args_List (1 .. 5);
5861 Names : constant Name_List (1 .. 5) := (
5862 Name_Unit_Name,
5863 Name_Entity,
5864 Name_Parameter_Types,
5865 Name_Result_Type,
5866 Name_Source_Location);
5868 Unit_Name : Node_Id renames Args (1);
5869 Entity : Node_Id renames Args (2);
5870 Parameter_Types : Node_Id renames Args (3);
5871 Result_Type : Node_Id renames Args (4);
5872 Source_Location : Node_Id renames Args (5);
5874 begin
5875 GNAT_Pragma;
5876 Check_Valid_Configuration_Pragma;
5877 Gather_Associations (Names, Args);
5879 if No (Unit_Name) then
5880 Error_Pragma ("missing Unit_Name argument for pragma%");
5881 end if;
5883 if No (Entity)
5884 and then (Present (Parameter_Types)
5885 or else
5886 Present (Result_Type)
5887 or else
5888 Present (Source_Location))
5889 then
5890 Error_Pragma ("missing Entity argument for pragma%");
5891 end if;
5893 if (Present (Parameter_Types)
5894 or else
5895 Present (Result_Type))
5896 and then
5897 Present (Source_Location)
5898 then
5899 Error_Pragma
5900 ("parameter profile and source location can not " &
5901 "be used together in pragma%");
5902 end if;
5904 Process_Eliminate_Pragma
5906 Unit_Name,
5907 Entity,
5908 Parameter_Types,
5909 Result_Type,
5910 Source_Location);
5911 end Eliminate;
5913 -------------------------
5914 -- Explicit_Overriding --
5915 -------------------------
5917 when Pragma_Explicit_Overriding =>
5918 Check_Valid_Configuration_Pragma;
5919 Check_Arg_Count (0);
5920 Explicit_Overriding := True;
5922 ------------
5923 -- Export --
5924 ------------
5926 -- pragma Export (
5927 -- [ Convention =>] convention_IDENTIFIER,
5928 -- [ Entity =>] local_NAME
5929 -- [, [External_Name =>] static_string_EXPRESSION ]
5930 -- [, [Link_Name =>] static_string_EXPRESSION ]);
5932 when Pragma_Export => Export : declare
5933 C : Convention_Id;
5934 Def_Id : Entity_Id;
5936 begin
5937 Check_Ada_83_Warning;
5938 Check_At_Least_N_Arguments (2);
5939 Check_At_Most_N_Arguments (4);
5940 Process_Convention (C, Def_Id);
5942 if Ekind (Def_Id) /= E_Constant then
5943 Note_Possible_Modification (Expression (Arg2));
5944 end if;
5946 Process_Interface_Name (Def_Id, Arg3, Arg4);
5947 Set_Exported (Def_Id, Arg2);
5948 end Export;
5950 ----------------------
5951 -- Export_Exception --
5952 ----------------------
5954 -- pragma Export_Exception (
5955 -- [Internal =>] LOCAL_NAME,
5956 -- [, [External =>] EXTERNAL_SYMBOL,]
5957 -- [, [Form =>] Ada | VMS]
5958 -- [, [Code =>] static_integer_EXPRESSION]);
5960 when Pragma_Export_Exception => Export_Exception : declare
5961 Args : Args_List (1 .. 4);
5962 Names : constant Name_List (1 .. 4) := (
5963 Name_Internal,
5964 Name_External,
5965 Name_Form,
5966 Name_Code);
5968 Internal : Node_Id renames Args (1);
5969 External : Node_Id renames Args (2);
5970 Form : Node_Id renames Args (3);
5971 Code : Node_Id renames Args (4);
5973 begin
5974 if Inside_A_Generic then
5975 Error_Pragma ("pragma% cannot be used for generic entities");
5976 end if;
5978 Gather_Associations (Names, Args);
5979 Process_Extended_Import_Export_Exception_Pragma (
5980 Arg_Internal => Internal,
5981 Arg_External => External,
5982 Arg_Form => Form,
5983 Arg_Code => Code);
5985 if not Is_VMS_Exception (Entity (Internal)) then
5986 Set_Exported (Entity (Internal), Internal);
5987 end if;
5988 end Export_Exception;
5990 ---------------------
5991 -- Export_Function --
5992 ---------------------
5994 -- pragma Export_Function (
5995 -- [Internal =>] LOCAL_NAME,
5996 -- [, [External =>] EXTERNAL_SYMBOL,]
5997 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5998 -- [, [Result_Type =>] TYPE_DESIGNATOR]
5999 -- [, [Mechanism =>] MECHANISM]
6000 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
6002 -- EXTERNAL_SYMBOL ::=
6003 -- IDENTIFIER
6004 -- | static_string_EXPRESSION
6006 -- PARAMETER_TYPES ::=
6007 -- null
6008 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6010 -- TYPE_DESIGNATOR ::=
6011 -- subtype_NAME
6012 -- | subtype_Name ' Access
6014 -- MECHANISM ::=
6015 -- MECHANISM_NAME
6016 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6018 -- MECHANISM_ASSOCIATION ::=
6019 -- [formal_parameter_NAME =>] MECHANISM_NAME
6021 -- MECHANISM_NAME ::=
6022 -- Value
6023 -- | Reference
6024 -- | Descriptor [([Class =>] CLASS_NAME)]
6026 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6028 when Pragma_Export_Function => Export_Function : declare
6029 Args : Args_List (1 .. 6);
6030 Names : constant Name_List (1 .. 6) := (
6031 Name_Internal,
6032 Name_External,
6033 Name_Parameter_Types,
6034 Name_Result_Type,
6035 Name_Mechanism,
6036 Name_Result_Mechanism);
6038 Internal : Node_Id renames Args (1);
6039 External : Node_Id renames Args (2);
6040 Parameter_Types : Node_Id renames Args (3);
6041 Result_Type : Node_Id renames Args (4);
6042 Mechanism : Node_Id renames Args (5);
6043 Result_Mechanism : Node_Id renames Args (6);
6045 begin
6046 GNAT_Pragma;
6047 Gather_Associations (Names, Args);
6048 Process_Extended_Import_Export_Subprogram_Pragma (
6049 Arg_Internal => Internal,
6050 Arg_External => External,
6051 Arg_Parameter_Types => Parameter_Types,
6052 Arg_Result_Type => Result_Type,
6053 Arg_Mechanism => Mechanism,
6054 Arg_Result_Mechanism => Result_Mechanism);
6055 end Export_Function;
6057 -------------------
6058 -- Export_Object --
6059 -------------------
6061 -- pragma Export_Object (
6062 -- [Internal =>] LOCAL_NAME,
6063 -- [, [External =>] EXTERNAL_SYMBOL]
6064 -- [, [Size =>] EXTERNAL_SYMBOL]);
6066 -- EXTERNAL_SYMBOL ::=
6067 -- IDENTIFIER
6068 -- | static_string_EXPRESSION
6070 -- PARAMETER_TYPES ::=
6071 -- null
6072 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6074 -- TYPE_DESIGNATOR ::=
6075 -- subtype_NAME
6076 -- | subtype_Name ' Access
6078 -- MECHANISM ::=
6079 -- MECHANISM_NAME
6080 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6082 -- MECHANISM_ASSOCIATION ::=
6083 -- [formal_parameter_NAME =>] MECHANISM_NAME
6085 -- MECHANISM_NAME ::=
6086 -- Value
6087 -- | Reference
6088 -- | Descriptor [([Class =>] CLASS_NAME)]
6090 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6092 when Pragma_Export_Object => Export_Object : declare
6093 Args : Args_List (1 .. 3);
6094 Names : constant Name_List (1 .. 3) := (
6095 Name_Internal,
6096 Name_External,
6097 Name_Size);
6099 Internal : Node_Id renames Args (1);
6100 External : Node_Id renames Args (2);
6101 Size : Node_Id renames Args (3);
6103 begin
6104 GNAT_Pragma;
6105 Gather_Associations (Names, Args);
6106 Process_Extended_Import_Export_Object_Pragma (
6107 Arg_Internal => Internal,
6108 Arg_External => External,
6109 Arg_Size => Size);
6110 end Export_Object;
6112 ----------------------
6113 -- Export_Procedure --
6114 ----------------------
6116 -- pragma Export_Procedure (
6117 -- [Internal =>] LOCAL_NAME,
6118 -- [, [External =>] EXTERNAL_SYMBOL,]
6119 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6120 -- [, [Mechanism =>] MECHANISM]);
6122 -- EXTERNAL_SYMBOL ::=
6123 -- IDENTIFIER
6124 -- | static_string_EXPRESSION
6126 -- PARAMETER_TYPES ::=
6127 -- null
6128 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6130 -- TYPE_DESIGNATOR ::=
6131 -- subtype_NAME
6132 -- | subtype_Name ' Access
6134 -- MECHANISM ::=
6135 -- MECHANISM_NAME
6136 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6138 -- MECHANISM_ASSOCIATION ::=
6139 -- [formal_parameter_NAME =>] MECHANISM_NAME
6141 -- MECHANISM_NAME ::=
6142 -- Value
6143 -- | Reference
6144 -- | Descriptor [([Class =>] CLASS_NAME)]
6146 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6148 when Pragma_Export_Procedure => Export_Procedure : declare
6149 Args : Args_List (1 .. 4);
6150 Names : constant Name_List (1 .. 4) := (
6151 Name_Internal,
6152 Name_External,
6153 Name_Parameter_Types,
6154 Name_Mechanism);
6156 Internal : Node_Id renames Args (1);
6157 External : Node_Id renames Args (2);
6158 Parameter_Types : Node_Id renames Args (3);
6159 Mechanism : Node_Id renames Args (4);
6161 begin
6162 GNAT_Pragma;
6163 Gather_Associations (Names, Args);
6164 Process_Extended_Import_Export_Subprogram_Pragma (
6165 Arg_Internal => Internal,
6166 Arg_External => External,
6167 Arg_Parameter_Types => Parameter_Types,
6168 Arg_Mechanism => Mechanism);
6169 end Export_Procedure;
6171 ------------------
6172 -- Export_Value --
6173 ------------------
6175 -- pragma Export_Value (
6176 -- [Value =>] static_integer_EXPRESSION,
6177 -- [Link_Name =>] static_string_EXPRESSION);
6179 when Pragma_Export_Value =>
6180 GNAT_Pragma;
6181 Check_Arg_Count (2);
6183 Check_Optional_Identifier (Arg1, Name_Value);
6184 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
6186 Check_Optional_Identifier (Arg2, Name_Link_Name);
6187 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6189 -----------------------------
6190 -- Export_Valued_Procedure --
6191 -----------------------------
6193 -- pragma Export_Valued_Procedure (
6194 -- [Internal =>] LOCAL_NAME,
6195 -- [, [External =>] EXTERNAL_SYMBOL,]
6196 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6197 -- [, [Mechanism =>] MECHANISM]);
6199 -- EXTERNAL_SYMBOL ::=
6200 -- IDENTIFIER
6201 -- | static_string_EXPRESSION
6203 -- PARAMETER_TYPES ::=
6204 -- null
6205 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6207 -- TYPE_DESIGNATOR ::=
6208 -- subtype_NAME
6209 -- | subtype_Name ' Access
6211 -- MECHANISM ::=
6212 -- MECHANISM_NAME
6213 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6215 -- MECHANISM_ASSOCIATION ::=
6216 -- [formal_parameter_NAME =>] MECHANISM_NAME
6218 -- MECHANISM_NAME ::=
6219 -- Value
6220 -- | Reference
6221 -- | Descriptor [([Class =>] CLASS_NAME)]
6223 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6225 when Pragma_Export_Valued_Procedure =>
6226 Export_Valued_Procedure : declare
6227 Args : Args_List (1 .. 4);
6228 Names : constant Name_List (1 .. 4) := (
6229 Name_Internal,
6230 Name_External,
6231 Name_Parameter_Types,
6232 Name_Mechanism);
6234 Internal : Node_Id renames Args (1);
6235 External : Node_Id renames Args (2);
6236 Parameter_Types : Node_Id renames Args (3);
6237 Mechanism : Node_Id renames Args (4);
6239 begin
6240 GNAT_Pragma;
6241 Gather_Associations (Names, Args);
6242 Process_Extended_Import_Export_Subprogram_Pragma (
6243 Arg_Internal => Internal,
6244 Arg_External => External,
6245 Arg_Parameter_Types => Parameter_Types,
6246 Arg_Mechanism => Mechanism);
6247 end Export_Valued_Procedure;
6249 -------------------
6250 -- Extend_System --
6251 -------------------
6253 -- pragma Extend_System ([Name =>] Identifier);
6255 when Pragma_Extend_System => Extend_System : declare
6256 begin
6257 GNAT_Pragma;
6258 Check_Valid_Configuration_Pragma;
6259 Check_Arg_Count (1);
6260 Check_Optional_Identifier (Arg1, Name_Name);
6261 Check_Arg_Is_Identifier (Arg1);
6263 Get_Name_String (Chars (Expression (Arg1)));
6265 if Name_Len > 4
6266 and then Name_Buffer (1 .. 4) = "aux_"
6267 then
6268 if Present (System_Extend_Pragma_Arg) then
6269 if Chars (Expression (Arg1)) =
6270 Chars (Expression (System_Extend_Pragma_Arg))
6271 then
6272 null;
6273 else
6274 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
6275 Error_Pragma ("pragma% conflicts with that at#");
6276 end if;
6278 else
6279 System_Extend_Pragma_Arg := Arg1;
6281 if not GNAT_Mode then
6282 System_Extend_Unit := Arg1;
6283 end if;
6284 end if;
6285 else
6286 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
6287 end if;
6288 end Extend_System;
6290 ------------------------
6291 -- Extensions_Allowed --
6292 ------------------------
6294 -- pragma Extensions_Allowed (ON | OFF);
6296 when Pragma_Extensions_Allowed =>
6297 GNAT_Pragma;
6298 Check_Arg_Count (1);
6299 Check_No_Identifiers;
6300 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6302 if Chars (Expression (Arg1)) = Name_On then
6303 Extensions_Allowed := True;
6304 Ada_Version := Ada_Version_Type'Last;
6305 else
6306 Extensions_Allowed := False;
6307 Ada_Version := Ada_Version_Type'Min (Ada_Version, Ada_95);
6308 end if;
6310 --------------
6311 -- External --
6312 --------------
6314 -- pragma External (
6315 -- [ Convention =>] convention_IDENTIFIER,
6316 -- [ Entity =>] local_NAME
6317 -- [, [External_Name =>] static_string_EXPRESSION ]
6318 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6320 when Pragma_External => External : declare
6321 C : Convention_Id;
6322 Def_Id : Entity_Id;
6324 begin
6325 GNAT_Pragma;
6326 Check_At_Least_N_Arguments (2);
6327 Check_At_Most_N_Arguments (4);
6328 Process_Convention (C, Def_Id);
6329 Note_Possible_Modification (Expression (Arg2));
6330 Process_Interface_Name (Def_Id, Arg3, Arg4);
6331 Set_Exported (Def_Id, Arg2);
6332 end External;
6334 --------------------------
6335 -- External_Name_Casing --
6336 --------------------------
6338 -- pragma External_Name_Casing (
6339 -- UPPERCASE | LOWERCASE
6340 -- [, AS_IS | UPPERCASE | LOWERCASE]);
6342 when Pragma_External_Name_Casing => External_Name_Casing : declare
6343 begin
6344 GNAT_Pragma;
6345 Check_No_Identifiers;
6347 if Arg_Count = 2 then
6348 Check_Arg_Is_One_Of
6349 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
6351 case Chars (Get_Pragma_Arg (Arg2)) is
6352 when Name_As_Is =>
6353 Opt.External_Name_Exp_Casing := As_Is;
6355 when Name_Uppercase =>
6356 Opt.External_Name_Exp_Casing := Uppercase;
6358 when Name_Lowercase =>
6359 Opt.External_Name_Exp_Casing := Lowercase;
6361 when others =>
6362 null;
6363 end case;
6365 else
6366 Check_Arg_Count (1);
6367 end if;
6369 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
6371 case Chars (Get_Pragma_Arg (Arg1)) is
6372 when Name_Uppercase =>
6373 Opt.External_Name_Imp_Casing := Uppercase;
6375 when Name_Lowercase =>
6376 Opt.External_Name_Imp_Casing := Lowercase;
6378 when others =>
6379 null;
6380 end case;
6381 end External_Name_Casing;
6383 ---------------------------
6384 -- Finalize_Storage_Only --
6385 ---------------------------
6387 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
6389 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
6390 Assoc : constant Node_Id := Arg1;
6391 Type_Id : constant Node_Id := Expression (Assoc);
6392 Typ : Entity_Id;
6394 begin
6395 Check_No_Identifiers;
6396 Check_Arg_Count (1);
6397 Check_Arg_Is_Local_Name (Arg1);
6399 Find_Type (Type_Id);
6400 Typ := Entity (Type_Id);
6402 if Typ = Any_Type
6403 or else Rep_Item_Too_Early (Typ, N)
6404 then
6405 return;
6406 else
6407 Typ := Underlying_Type (Typ);
6408 end if;
6410 if not Is_Controlled (Typ) then
6411 Error_Pragma ("pragma% must specify controlled type");
6412 end if;
6414 Check_First_Subtype (Arg1);
6416 if Finalize_Storage_Only (Typ) then
6417 Error_Pragma ("duplicate pragma%, only one allowed");
6419 elsif not Rep_Item_Too_Late (Typ, N) then
6420 Set_Finalize_Storage_Only (Base_Type (Typ), True);
6421 end if;
6422 end Finalize_Storage;
6424 --------------------------
6425 -- Float_Representation --
6426 --------------------------
6428 -- pragma Float_Representation (VAX_Float | IEEE_Float);
6430 when Pragma_Float_Representation => Float_Representation : declare
6431 Argx : Node_Id;
6432 Digs : Nat;
6433 Ent : Entity_Id;
6435 begin
6436 GNAT_Pragma;
6438 if Arg_Count = 1 then
6439 Check_Valid_Configuration_Pragma;
6440 else
6441 Check_Arg_Count (2);
6442 Check_Optional_Identifier (Arg2, Name_Entity);
6443 Check_Arg_Is_Local_Name (Arg2);
6444 end if;
6446 Check_No_Identifier (Arg1);
6447 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
6449 if not OpenVMS_On_Target then
6450 if Chars (Expression (Arg1)) = Name_VAX_Float then
6451 Error_Pragma
6452 ("?pragma% ignored (applies only to Open'V'M'S)");
6453 end if;
6455 return;
6456 end if;
6458 -- One argument case
6460 if Arg_Count = 1 then
6462 if Chars (Expression (Arg1)) = Name_VAX_Float then
6464 if Opt.Float_Format = 'I' then
6465 Error_Pragma ("'I'E'E'E format previously specified");
6466 end if;
6468 Opt.Float_Format := 'V';
6470 else
6471 if Opt.Float_Format = 'V' then
6472 Error_Pragma ("'V'A'X format previously specified");
6473 end if;
6475 Opt.Float_Format := 'I';
6476 end if;
6478 Set_Standard_Fpt_Formats;
6480 -- Two argument case
6482 else
6483 Argx := Get_Pragma_Arg (Arg2);
6485 if not Is_Entity_Name (Argx)
6486 or else not Is_Floating_Point_Type (Entity (Argx))
6487 then
6488 Error_Pragma_Arg
6489 ("second argument of% pragma must be floating-point type",
6490 Arg2);
6491 end if;
6493 Ent := Entity (Argx);
6494 Digs := UI_To_Int (Digits_Value (Ent));
6496 -- Two arguments, VAX_Float case
6498 if Chars (Expression (Arg1)) = Name_VAX_Float then
6500 case Digs is
6501 when 6 => Set_F_Float (Ent);
6502 when 9 => Set_D_Float (Ent);
6503 when 15 => Set_G_Float (Ent);
6505 when others =>
6506 Error_Pragma_Arg
6507 ("wrong digits value, must be 6,9 or 15", Arg2);
6508 end case;
6510 -- Two arguments, IEEE_Float case
6512 else
6513 case Digs is
6514 when 6 => Set_IEEE_Short (Ent);
6515 when 15 => Set_IEEE_Long (Ent);
6517 when others =>
6518 Error_Pragma_Arg
6519 ("wrong digits value, must be 6 or 15", Arg2);
6520 end case;
6521 end if;
6522 end if;
6523 end Float_Representation;
6525 -----------
6526 -- Ident --
6527 -----------
6529 -- pragma Ident (static_string_EXPRESSION)
6531 -- Note: pragma Comment shares this processing. Pragma Comment
6532 -- is identical to Ident, except that the restriction of the
6533 -- argument to 31 characters and the placement restrictions
6534 -- are not enforced for pragma Comment.
6536 when Pragma_Ident | Pragma_Comment => Ident : declare
6537 Str : Node_Id;
6539 begin
6540 GNAT_Pragma;
6541 Check_Arg_Count (1);
6542 Check_No_Identifiers;
6543 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
6545 -- For pragma Ident, preserve DEC compatibility by requiring
6546 -- the pragma to appear in a declarative part or package spec.
6548 if Prag_Id = Pragma_Ident then
6549 Check_Is_In_Decl_Part_Or_Package_Spec;
6550 end if;
6552 Str := Expr_Value_S (Expression (Arg1));
6554 declare
6555 CS : Node_Id;
6556 GP : Node_Id;
6558 begin
6559 GP := Parent (Parent (N));
6561 if Nkind (GP) = N_Package_Declaration
6562 or else
6563 Nkind (GP) = N_Generic_Package_Declaration
6564 then
6565 GP := Parent (GP);
6566 end if;
6568 -- If we have a compilation unit, then record the ident
6569 -- value, checking for improper duplication.
6571 if Nkind (GP) = N_Compilation_Unit then
6572 CS := Ident_String (Current_Sem_Unit);
6574 if Present (CS) then
6576 -- For Ident, we do not permit multiple instances
6578 if Prag_Id = Pragma_Ident then
6579 Error_Pragma ("duplicate% pragma not permitted");
6581 -- For Comment, we concatenate the string, unless we
6582 -- want to preserve the tree structure for ASIS.
6584 elsif not ASIS_Mode then
6585 Start_String (Strval (CS));
6586 Store_String_Char (' ');
6587 Store_String_Chars (Strval (Str));
6588 Set_Strval (CS, End_String);
6589 end if;
6591 else
6592 -- In VMS, the effect of IDENT is achieved by passing
6593 -- IDENTIFICATION=name as a --for-linker switch.
6595 if OpenVMS_On_Target then
6596 Start_String;
6597 Store_String_Chars
6598 ("--for-linker=IDENTIFICATION=");
6599 String_To_Name_Buffer (Strval (Str));
6600 Store_String_Chars (Name_Buffer (1 .. Name_Len));
6602 -- Only the last processed IDENT is saved. The main
6603 -- purpose is so an IDENT associated with a main
6604 -- procedure will be used in preference to an IDENT
6605 -- associated with a with'd package.
6607 Replace_Linker_Option_String
6608 (End_String, "--for-linker=IDENTIFICATION=");
6609 end if;
6611 Set_Ident_String (Current_Sem_Unit, Str);
6612 end if;
6614 -- For subunits, we just ignore the Ident, since in GNAT
6615 -- these are not separate object files, and hence not
6616 -- separate units in the unit table.
6618 elsif Nkind (GP) = N_Subunit then
6619 null;
6621 -- Otherwise we have a misplaced pragma Ident, but we ignore
6622 -- this if we are in an instantiation, since it comes from
6623 -- a generic, and has no relevance to the instantiation.
6625 elsif Prag_Id = Pragma_Ident then
6626 if Instantiation_Location (Loc) = No_Location then
6627 Error_Pragma ("pragma% only allowed at outer level");
6628 end if;
6629 end if;
6630 end;
6631 end Ident;
6633 ------------
6634 -- Import --
6635 ------------
6637 -- pragma Import (
6638 -- [ Convention =>] convention_IDENTIFIER,
6639 -- [ Entity =>] local_NAME
6640 -- [, [External_Name =>] static_string_EXPRESSION ]
6641 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6643 when Pragma_Import =>
6644 Check_Ada_83_Warning;
6645 Check_At_Least_N_Arguments (2);
6646 Check_At_Most_N_Arguments (4);
6647 Process_Import_Or_Interface;
6649 ----------------------
6650 -- Import_Exception --
6651 ----------------------
6653 -- pragma Import_Exception (
6654 -- [Internal =>] LOCAL_NAME,
6655 -- [, [External =>] EXTERNAL_SYMBOL,]
6656 -- [, [Form =>] Ada | VMS]
6657 -- [, [Code =>] static_integer_EXPRESSION]);
6659 when Pragma_Import_Exception => Import_Exception : declare
6660 Args : Args_List (1 .. 4);
6661 Names : constant Name_List (1 .. 4) := (
6662 Name_Internal,
6663 Name_External,
6664 Name_Form,
6665 Name_Code);
6667 Internal : Node_Id renames Args (1);
6668 External : Node_Id renames Args (2);
6669 Form : Node_Id renames Args (3);
6670 Code : Node_Id renames Args (4);
6672 begin
6673 Gather_Associations (Names, Args);
6675 if Present (External) and then Present (Code) then
6676 Error_Pragma
6677 ("cannot give both External and Code options for pragma%");
6678 end if;
6680 Process_Extended_Import_Export_Exception_Pragma (
6681 Arg_Internal => Internal,
6682 Arg_External => External,
6683 Arg_Form => Form,
6684 Arg_Code => Code);
6686 if not Is_VMS_Exception (Entity (Internal)) then
6687 Set_Imported (Entity (Internal));
6688 end if;
6689 end Import_Exception;
6691 ---------------------
6692 -- Import_Function --
6693 ---------------------
6695 -- pragma Import_Function (
6696 -- [Internal =>] LOCAL_NAME,
6697 -- [, [External =>] EXTERNAL_SYMBOL]
6698 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6699 -- [, [Result_Type =>] SUBTYPE_MARK]
6700 -- [, [Mechanism =>] MECHANISM]
6701 -- [, [Result_Mechanism =>] MECHANISM_NAME]
6702 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6704 -- EXTERNAL_SYMBOL ::=
6705 -- IDENTIFIER
6706 -- | static_string_EXPRESSION
6708 -- PARAMETER_TYPES ::=
6709 -- null
6710 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6712 -- TYPE_DESIGNATOR ::=
6713 -- subtype_NAME
6714 -- | subtype_Name ' Access
6716 -- MECHANISM ::=
6717 -- MECHANISM_NAME
6718 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6720 -- MECHANISM_ASSOCIATION ::=
6721 -- [formal_parameter_NAME =>] MECHANISM_NAME
6723 -- MECHANISM_NAME ::=
6724 -- Value
6725 -- | Reference
6726 -- | Descriptor [([Class =>] CLASS_NAME)]
6728 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6730 when Pragma_Import_Function => Import_Function : declare
6731 Args : Args_List (1 .. 7);
6732 Names : constant Name_List (1 .. 7) := (
6733 Name_Internal,
6734 Name_External,
6735 Name_Parameter_Types,
6736 Name_Result_Type,
6737 Name_Mechanism,
6738 Name_Result_Mechanism,
6739 Name_First_Optional_Parameter);
6741 Internal : Node_Id renames Args (1);
6742 External : Node_Id renames Args (2);
6743 Parameter_Types : Node_Id renames Args (3);
6744 Result_Type : Node_Id renames Args (4);
6745 Mechanism : Node_Id renames Args (5);
6746 Result_Mechanism : Node_Id renames Args (6);
6747 First_Optional_Parameter : Node_Id renames Args (7);
6749 begin
6750 GNAT_Pragma;
6751 Gather_Associations (Names, Args);
6752 Process_Extended_Import_Export_Subprogram_Pragma (
6753 Arg_Internal => Internal,
6754 Arg_External => External,
6755 Arg_Parameter_Types => Parameter_Types,
6756 Arg_Result_Type => Result_Type,
6757 Arg_Mechanism => Mechanism,
6758 Arg_Result_Mechanism => Result_Mechanism,
6759 Arg_First_Optional_Parameter => First_Optional_Parameter);
6760 end Import_Function;
6762 -------------------
6763 -- Import_Object --
6764 -------------------
6766 -- pragma Import_Object (
6767 -- [Internal =>] LOCAL_NAME,
6768 -- [, [External =>] EXTERNAL_SYMBOL]
6769 -- [, [Size =>] EXTERNAL_SYMBOL]);
6771 -- EXTERNAL_SYMBOL ::=
6772 -- IDENTIFIER
6773 -- | static_string_EXPRESSION
6775 when Pragma_Import_Object => Import_Object : declare
6776 Args : Args_List (1 .. 3);
6777 Names : constant Name_List (1 .. 3) := (
6778 Name_Internal,
6779 Name_External,
6780 Name_Size);
6782 Internal : Node_Id renames Args (1);
6783 External : Node_Id renames Args (2);
6784 Size : Node_Id renames Args (3);
6786 begin
6787 GNAT_Pragma;
6788 Gather_Associations (Names, Args);
6789 Process_Extended_Import_Export_Object_Pragma (
6790 Arg_Internal => Internal,
6791 Arg_External => External,
6792 Arg_Size => Size);
6793 end Import_Object;
6795 ----------------------
6796 -- Import_Procedure --
6797 ----------------------
6799 -- pragma Import_Procedure (
6800 -- [Internal =>] LOCAL_NAME,
6801 -- [, [External =>] EXTERNAL_SYMBOL]
6802 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6803 -- [, [Mechanism =>] MECHANISM]
6804 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6806 -- EXTERNAL_SYMBOL ::=
6807 -- IDENTIFIER
6808 -- | static_string_EXPRESSION
6810 -- PARAMETER_TYPES ::=
6811 -- null
6812 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6814 -- TYPE_DESIGNATOR ::=
6815 -- subtype_NAME
6816 -- | subtype_Name ' Access
6818 -- MECHANISM ::=
6819 -- MECHANISM_NAME
6820 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6822 -- MECHANISM_ASSOCIATION ::=
6823 -- [formal_parameter_NAME =>] MECHANISM_NAME
6825 -- MECHANISM_NAME ::=
6826 -- Value
6827 -- | Reference
6828 -- | Descriptor [([Class =>] CLASS_NAME)]
6830 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6832 when Pragma_Import_Procedure => Import_Procedure : declare
6833 Args : Args_List (1 .. 5);
6834 Names : constant Name_List (1 .. 5) := (
6835 Name_Internal,
6836 Name_External,
6837 Name_Parameter_Types,
6838 Name_Mechanism,
6839 Name_First_Optional_Parameter);
6841 Internal : Node_Id renames Args (1);
6842 External : Node_Id renames Args (2);
6843 Parameter_Types : Node_Id renames Args (3);
6844 Mechanism : Node_Id renames Args (4);
6845 First_Optional_Parameter : Node_Id renames Args (5);
6847 begin
6848 GNAT_Pragma;
6849 Gather_Associations (Names, Args);
6850 Process_Extended_Import_Export_Subprogram_Pragma (
6851 Arg_Internal => Internal,
6852 Arg_External => External,
6853 Arg_Parameter_Types => Parameter_Types,
6854 Arg_Mechanism => Mechanism,
6855 Arg_First_Optional_Parameter => First_Optional_Parameter);
6856 end Import_Procedure;
6858 -----------------------------
6859 -- Import_Valued_Procedure --
6860 -----------------------------
6862 -- pragma Import_Valued_Procedure (
6863 -- [Internal =>] LOCAL_NAME,
6864 -- [, [External =>] EXTERNAL_SYMBOL]
6865 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6866 -- [, [Mechanism =>] MECHANISM]
6867 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6869 -- EXTERNAL_SYMBOL ::=
6870 -- IDENTIFIER
6871 -- | static_string_EXPRESSION
6873 -- PARAMETER_TYPES ::=
6874 -- null
6875 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6877 -- TYPE_DESIGNATOR ::=
6878 -- subtype_NAME
6879 -- | subtype_Name ' Access
6881 -- MECHANISM ::=
6882 -- MECHANISM_NAME
6883 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6885 -- MECHANISM_ASSOCIATION ::=
6886 -- [formal_parameter_NAME =>] MECHANISM_NAME
6888 -- MECHANISM_NAME ::=
6889 -- Value
6890 -- | Reference
6891 -- | Descriptor [([Class =>] CLASS_NAME)]
6893 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6895 when Pragma_Import_Valued_Procedure =>
6896 Import_Valued_Procedure : declare
6897 Args : Args_List (1 .. 5);
6898 Names : constant Name_List (1 .. 5) := (
6899 Name_Internal,
6900 Name_External,
6901 Name_Parameter_Types,
6902 Name_Mechanism,
6903 Name_First_Optional_Parameter);
6905 Internal : Node_Id renames Args (1);
6906 External : Node_Id renames Args (2);
6907 Parameter_Types : Node_Id renames Args (3);
6908 Mechanism : Node_Id renames Args (4);
6909 First_Optional_Parameter : Node_Id renames Args (5);
6911 begin
6912 GNAT_Pragma;
6913 Gather_Associations (Names, Args);
6914 Process_Extended_Import_Export_Subprogram_Pragma (
6915 Arg_Internal => Internal,
6916 Arg_External => External,
6917 Arg_Parameter_Types => Parameter_Types,
6918 Arg_Mechanism => Mechanism,
6919 Arg_First_Optional_Parameter => First_Optional_Parameter);
6920 end Import_Valued_Procedure;
6922 ------------------------
6923 -- Initialize_Scalars --
6924 ------------------------
6926 -- pragma Initialize_Scalars;
6928 when Pragma_Initialize_Scalars =>
6929 GNAT_Pragma;
6930 Check_Arg_Count (0);
6931 Check_Valid_Configuration_Pragma;
6932 Check_Restriction (No_Initialize_Scalars, N);
6934 if not Restriction_Active (No_Initialize_Scalars) then
6935 Init_Or_Norm_Scalars := True;
6936 Initialize_Scalars := True;
6937 end if;
6939 ------------
6940 -- Inline --
6941 ------------
6943 -- pragma Inline ( NAME {, NAME} );
6945 when Pragma_Inline =>
6947 -- Pragma is active if inlining option is active
6949 Process_Inline (Inline_Active);
6951 -------------------
6952 -- Inline_Always --
6953 -------------------
6955 -- pragma Inline_Always ( NAME {, NAME} );
6957 when Pragma_Inline_Always =>
6958 Process_Inline (True);
6960 --------------------
6961 -- Inline_Generic --
6962 --------------------
6964 -- pragma Inline_Generic (NAME {, NAME});
6966 when Pragma_Inline_Generic =>
6967 Process_Generic_List;
6969 ----------------------
6970 -- Inspection_Point --
6971 ----------------------
6973 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
6975 when Pragma_Inspection_Point => Inspection_Point : declare
6976 Arg : Node_Id;
6977 Exp : Node_Id;
6979 begin
6980 if Arg_Count > 0 then
6981 Arg := Arg1;
6982 loop
6983 Exp := Expression (Arg);
6984 Analyze (Exp);
6986 if not Is_Entity_Name (Exp)
6987 or else not Is_Object (Entity (Exp))
6988 then
6989 Error_Pragma_Arg ("object name required", Arg);
6990 end if;
6992 Next (Arg);
6993 exit when No (Arg);
6994 end loop;
6995 end if;
6996 end Inspection_Point;
6998 ---------------
6999 -- Interface --
7000 ---------------
7002 -- pragma Interface (
7003 -- convention_IDENTIFIER,
7004 -- local_NAME );
7006 when Pragma_Interface =>
7007 GNAT_Pragma;
7008 Check_Arg_Count (2);
7009 Check_No_Identifiers;
7010 Process_Import_Or_Interface;
7012 --------------------
7013 -- Interface_Name --
7014 --------------------
7016 -- pragma Interface_Name (
7017 -- [ Entity =>] local_NAME
7018 -- [,[External_Name =>] static_string_EXPRESSION ]
7019 -- [,[Link_Name =>] static_string_EXPRESSION ]);
7021 when Pragma_Interface_Name => Interface_Name : declare
7022 Id : Node_Id;
7023 Def_Id : Entity_Id;
7024 Hom_Id : Entity_Id;
7025 Found : Boolean;
7027 begin
7028 GNAT_Pragma;
7029 Check_At_Least_N_Arguments (2);
7030 Check_At_Most_N_Arguments (3);
7031 Id := Expression (Arg1);
7032 Analyze (Id);
7034 if not Is_Entity_Name (Id) then
7035 Error_Pragma_Arg
7036 ("first argument for pragma% must be entity name", Arg1);
7037 elsif Etype (Id) = Any_Type then
7038 return;
7039 else
7040 Def_Id := Entity (Id);
7041 end if;
7043 -- Special DEC-compatible processing for the object case,
7044 -- forces object to be imported.
7046 if Ekind (Def_Id) = E_Variable then
7047 Kill_Size_Check_Code (Def_Id);
7048 Note_Possible_Modification (Id);
7050 -- Initialization is not allowed for imported variable
7052 if Present (Expression (Parent (Def_Id)))
7053 and then Comes_From_Source (Expression (Parent (Def_Id)))
7054 then
7055 Error_Msg_Sloc := Sloc (Def_Id);
7056 Error_Pragma_Arg
7057 ("no initialization allowed for declaration of& #",
7058 Arg2);
7060 else
7061 -- For compatibility, support VADS usage of providing both
7062 -- pragmas Interface and Interface_Name to obtain the effect
7063 -- of a single Import pragma.
7065 if Is_Imported (Def_Id)
7066 and then Present (First_Rep_Item (Def_Id))
7067 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
7068 and then Chars (First_Rep_Item (Def_Id)) = Name_Interface
7069 then
7070 null;
7071 else
7072 Set_Imported (Def_Id);
7073 end if;
7075 Set_Is_Public (Def_Id);
7076 Process_Interface_Name (Def_Id, Arg2, Arg3);
7077 end if;
7079 -- Otherwise must be subprogram
7081 elsif not Is_Subprogram (Def_Id) then
7082 Error_Pragma_Arg
7083 ("argument of pragma% is not subprogram", Arg1);
7085 else
7086 Check_At_Most_N_Arguments (3);
7087 Hom_Id := Def_Id;
7088 Found := False;
7090 -- Loop through homonyms
7092 loop
7093 Def_Id := Get_Base_Subprogram (Hom_Id);
7095 if Is_Imported (Def_Id) then
7096 Process_Interface_Name (Def_Id, Arg2, Arg3);
7097 Found := True;
7098 end if;
7100 Hom_Id := Homonym (Hom_Id);
7102 exit when No (Hom_Id)
7103 or else Scope (Hom_Id) /= Current_Scope;
7104 end loop;
7106 if not Found then
7107 Error_Pragma_Arg
7108 ("argument of pragma% is not imported subprogram",
7109 Arg1);
7110 end if;
7111 end if;
7112 end Interface_Name;
7114 -----------------------
7115 -- Interrupt_Handler --
7116 -----------------------
7118 -- pragma Interrupt_Handler (handler_NAME);
7120 when Pragma_Interrupt_Handler =>
7121 Check_Ada_83_Warning;
7122 Check_Arg_Count (1);
7123 Check_No_Identifiers;
7125 if No_Run_Time_Mode then
7126 Error_Msg_CRT ("Interrupt_Handler pragma", N);
7127 else
7128 Check_Interrupt_Or_Attach_Handler;
7129 Process_Interrupt_Or_Attach_Handler;
7130 end if;
7132 ------------------------
7133 -- Interrupt_Priority --
7134 ------------------------
7136 -- pragma Interrupt_Priority [(EXPRESSION)];
7138 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
7139 P : constant Node_Id := Parent (N);
7140 Arg : Node_Id;
7142 begin
7143 Check_Ada_83_Warning;
7145 if Arg_Count /= 0 then
7146 Arg := Expression (Arg1);
7147 Check_Arg_Count (1);
7148 Check_No_Identifiers;
7150 -- The expression must be analyzed in the special manner
7151 -- described in "Handling of Default and Per-Object
7152 -- Expressions" in sem.ads.
7154 Analyze_Per_Use_Expression (Arg, RTE (RE_Interrupt_Priority));
7155 end if;
7157 if Nkind (P) /= N_Task_Definition
7158 and then Nkind (P) /= N_Protected_Definition
7159 then
7160 Pragma_Misplaced;
7161 return;
7163 elsif Has_Priority_Pragma (P) then
7164 Error_Pragma ("duplicate pragma% not allowed");
7166 else
7167 Set_Has_Priority_Pragma (P, True);
7168 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7169 end if;
7170 end Interrupt_Priority;
7172 ---------------------
7173 -- Interrupt_State --
7174 ---------------------
7176 -- pragma Interrupt_State (
7177 -- [Name =>] INTERRUPT_ID,
7178 -- [State =>] INTERRUPT_STATE);
7180 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
7181 -- INTERRUPT_STATE => System | Runtime | User
7183 -- Note: if the interrupt id is given as an identifier, then
7184 -- it must be one of the identifiers in Ada.Interrupts.Names.
7185 -- Otherwise it is given as a static integer expression which
7186 -- must be in the range of Ada.Interrupts.Interrupt_ID.
7188 when Pragma_Interrupt_State => Interrupt_State : declare
7190 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
7191 -- This is the entity Ada.Interrupts.Interrupt_ID;
7193 State_Type : Character;
7194 -- Set to 's'/'r'/'u' for System/Runtime/User
7196 IST_Num : Pos;
7197 -- Index to entry in Interrupt_States table
7199 Int_Val : Uint;
7200 -- Value of interrupt
7202 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
7203 -- The first argument to the pragma
7205 Int_Ent : Entity_Id;
7206 -- Interrupt entity in Ada.Interrupts.Names
7208 begin
7209 GNAT_Pragma;
7210 Check_Arg_Count (2);
7212 Check_Optional_Identifier (Arg1, Name_Name);
7213 Check_Optional_Identifier (Arg2, "state");
7214 Check_Arg_Is_Identifier (Arg2);
7216 -- First argument is identifier
7218 if Nkind (Arg1X) = N_Identifier then
7220 -- Search list of names in Ada.Interrupts.Names
7222 Int_Ent := First_Entity (RTE (RE_Names));
7223 loop
7224 if No (Int_Ent) then
7225 Error_Pragma_Arg ("invalid interrupt name", Arg1);
7227 elsif Chars (Int_Ent) = Chars (Arg1X) then
7228 Int_Val := Expr_Value (Constant_Value (Int_Ent));
7229 exit;
7230 end if;
7232 Next_Entity (Int_Ent);
7233 end loop;
7235 -- First argument is not an identifier, so it must be a
7236 -- static expression of type Ada.Interrupts.Interrupt_ID.
7238 else
7239 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7240 Int_Val := Expr_Value (Arg1X);
7242 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
7243 or else
7244 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
7245 then
7246 Error_Pragma_Arg
7247 ("value not in range of type " &
7248 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
7249 end if;
7250 end if;
7252 -- Check OK state
7254 case Chars (Get_Pragma_Arg (Arg2)) is
7255 when Name_Runtime => State_Type := 'r';
7256 when Name_System => State_Type := 's';
7257 when Name_User => State_Type := 'u';
7259 when others =>
7260 Error_Pragma_Arg ("invalid interrupt state", Arg2);
7261 end case;
7263 -- Check if entry is already stored
7265 IST_Num := Interrupt_States.First;
7266 loop
7267 -- If entry not found, add it
7269 if IST_Num > Interrupt_States.Last then
7270 Interrupt_States.Append
7271 ((Interrupt_Number => UI_To_Int (Int_Val),
7272 Interrupt_State => State_Type,
7273 Pragma_Loc => Loc));
7274 exit;
7276 -- Case of entry for the same entry
7278 elsif Int_Val = Interrupt_States.Table (IST_Num).
7279 Interrupt_Number
7280 then
7281 -- If state matches, done, no need to make redundant entry
7283 exit when
7284 State_Type = Interrupt_States.Table (IST_Num).
7285 Interrupt_State;
7287 -- Otherwise if state does not match, error
7289 Error_Msg_Sloc :=
7290 Interrupt_States.Table (IST_Num).Pragma_Loc;
7291 Error_Pragma_Arg
7292 ("state conflicts with that given at #", Arg2);
7293 exit;
7294 end if;
7296 IST_Num := IST_Num + 1;
7297 end loop;
7298 end Interrupt_State;
7300 ----------------------
7301 -- Java_Constructor --
7302 ----------------------
7304 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
7306 when Pragma_Java_Constructor => Java_Constructor : declare
7307 Id : Entity_Id;
7308 Def_Id : Entity_Id;
7309 Hom_Id : Entity_Id;
7311 begin
7312 GNAT_Pragma;
7313 Check_Arg_Count (1);
7314 Check_Optional_Identifier (Arg1, Name_Entity);
7315 Check_Arg_Is_Local_Name (Arg1);
7317 Id := Expression (Arg1);
7318 Find_Program_Unit_Name (Id);
7320 -- If we did not find the name, we are done
7322 if Etype (Id) = Any_Type then
7323 return;
7324 end if;
7326 Hom_Id := Entity (Id);
7328 -- Loop through homonyms
7330 loop
7331 Def_Id := Get_Base_Subprogram (Hom_Id);
7333 -- The constructor is required to be a function returning
7334 -- an access type whose designated type has convention Java.
7336 if Ekind (Def_Id) = E_Function
7337 and then Ekind (Etype (Def_Id)) in Access_Kind
7338 and then
7339 (Atree.Convention
7340 (Designated_Type (Etype (Def_Id))) = Convention_Java
7341 or else
7342 Atree.Convention
7343 (Root_Type (Designated_Type (Etype (Def_Id))))
7344 = Convention_Java)
7345 then
7346 Set_Is_Constructor (Def_Id);
7347 Set_Convention (Def_Id, Convention_Java);
7349 else
7350 Error_Pragma_Arg
7351 ("pragma% requires function returning a 'Java access type",
7352 Arg1);
7353 end if;
7355 Hom_Id := Homonym (Hom_Id);
7357 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
7358 end loop;
7359 end Java_Constructor;
7361 ----------------------
7362 -- Java_Interface --
7363 ----------------------
7365 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
7367 when Pragma_Java_Interface => Java_Interface : declare
7368 Arg : Node_Id;
7369 Typ : Entity_Id;
7371 begin
7372 GNAT_Pragma;
7373 Check_Arg_Count (1);
7374 Check_Optional_Identifier (Arg1, Name_Entity);
7375 Check_Arg_Is_Local_Name (Arg1);
7377 Arg := Expression (Arg1);
7378 Analyze (Arg);
7380 if Etype (Arg) = Any_Type then
7381 return;
7382 end if;
7384 if not Is_Entity_Name (Arg)
7385 or else not Is_Type (Entity (Arg))
7386 then
7387 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7388 end if;
7390 Typ := Underlying_Type (Entity (Arg));
7392 -- For now we simply check some of the semantic constraints
7393 -- on the type. This currently leaves out some restrictions
7394 -- on interface types, namely that the parent type must be
7395 -- java.lang.Object.Typ and that all primitives of the type
7396 -- should be declared abstract. ???
7398 if not Is_Tagged_Type (Typ) or else not Is_Abstract (Typ) then
7399 Error_Pragma_Arg ("pragma% requires an abstract "
7400 & "tagged type", Arg1);
7402 elsif not Has_Discriminants (Typ)
7403 or else Ekind (Etype (First_Discriminant (Typ)))
7404 /= E_Anonymous_Access_Type
7405 or else
7406 not Is_Class_Wide_Type
7407 (Designated_Type (Etype (First_Discriminant (Typ))))
7408 then
7409 Error_Pragma_Arg
7410 ("type must have a class-wide access discriminant", Arg1);
7411 end if;
7412 end Java_Interface;
7414 ----------------
7415 -- Keep_Names --
7416 ----------------
7418 -- pragma Keep_Names ([On => ] local_NAME);
7420 when Pragma_Keep_Names => Keep_Names : declare
7421 Arg : Node_Id;
7423 begin
7424 GNAT_Pragma;
7425 Check_Arg_Count (1);
7426 Check_Optional_Identifier (Arg1, Name_On);
7427 Check_Arg_Is_Local_Name (Arg1);
7429 Arg := Expression (Arg1);
7430 Analyze (Arg);
7432 if Etype (Arg) = Any_Type then
7433 return;
7434 end if;
7436 if not Is_Entity_Name (Arg)
7437 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
7438 then
7439 Error_Pragma_Arg
7440 ("pragma% requires a local enumeration type", Arg1);
7441 end if;
7443 Set_Discard_Names (Entity (Arg), False);
7444 end Keep_Names;
7446 -------------
7447 -- License --
7448 -------------
7450 -- pragma License (RESTRICTED | UNRESRICTED | GPL | MODIFIED_GPL);
7452 when Pragma_License =>
7453 GNAT_Pragma;
7454 Check_Arg_Count (1);
7455 Check_No_Identifiers;
7456 Check_Valid_Configuration_Pragma;
7457 Check_Arg_Is_Identifier (Arg1);
7459 declare
7460 Sind : constant Source_File_Index :=
7461 Source_Index (Current_Sem_Unit);
7463 begin
7464 case Chars (Get_Pragma_Arg (Arg1)) is
7465 when Name_GPL =>
7466 Set_License (Sind, GPL);
7468 when Name_Modified_GPL =>
7469 Set_License (Sind, Modified_GPL);
7471 when Name_Restricted =>
7472 Set_License (Sind, Restricted);
7474 when Name_Unrestricted =>
7475 Set_License (Sind, Unrestricted);
7477 when others =>
7478 Error_Pragma_Arg ("invalid license name", Arg1);
7479 end case;
7480 end;
7482 ---------------
7483 -- Link_With --
7484 ---------------
7486 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
7488 when Pragma_Link_With => Link_With : declare
7489 Arg : Node_Id;
7491 begin
7492 GNAT_Pragma;
7494 if Operating_Mode = Generate_Code
7495 and then In_Extended_Main_Source_Unit (N)
7496 then
7497 Check_At_Least_N_Arguments (1);
7498 Check_No_Identifiers;
7499 Check_Is_In_Decl_Part_Or_Package_Spec;
7500 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7501 Start_String;
7503 Arg := Arg1;
7504 while Present (Arg) loop
7505 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7507 -- Store argument, converting sequences of spaces
7508 -- to a single null character (this is one of the
7509 -- differences in processing between Link_With
7510 -- and Linker_Options).
7512 declare
7513 C : constant Char_Code := Get_Char_Code (' ');
7514 S : constant String_Id :=
7515 Strval (Expr_Value_S (Expression (Arg)));
7516 L : constant Nat := String_Length (S);
7517 F : Nat := 1;
7519 procedure Skip_Spaces;
7520 -- Advance F past any spaces
7522 procedure Skip_Spaces is
7523 begin
7524 while F <= L and then Get_String_Char (S, F) = C loop
7525 F := F + 1;
7526 end loop;
7527 end Skip_Spaces;
7529 begin
7530 Skip_Spaces; -- skip leading spaces
7532 -- Loop through characters, changing any embedded
7533 -- sequence of spaces to a single null character
7534 -- (this is how Link_With/Linker_Options differ)
7536 while F <= L loop
7537 if Get_String_Char (S, F) = C then
7538 Skip_Spaces;
7539 exit when F > L;
7540 Store_String_Char (ASCII.NUL);
7542 else
7543 Store_String_Char (Get_String_Char (S, F));
7544 F := F + 1;
7545 end if;
7546 end loop;
7547 end;
7549 Arg := Next (Arg);
7551 if Present (Arg) then
7552 Store_String_Char (ASCII.NUL);
7553 end if;
7554 end loop;
7556 Store_Linker_Option_String (End_String);
7557 end if;
7558 end Link_With;
7560 ------------------
7561 -- Linker_Alias --
7562 ------------------
7564 -- pragma Linker_Alias (
7565 -- [Entity =>] LOCAL_NAME
7566 -- [Alias =>] static_string_EXPRESSION);
7568 when Pragma_Linker_Alias =>
7569 GNAT_Pragma;
7570 Check_Arg_Count (2);
7571 Check_Optional_Identifier (Arg1, Name_Entity);
7572 Check_Optional_Identifier (Arg2, "alias");
7573 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7574 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7576 -- The only processing required is to link this item on to the
7577 -- list of rep items for the given entity. This is accomplished
7578 -- by the call to Rep_Item_Too_Late (when no error is detected
7579 -- and False is returned).
7581 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7582 return;
7583 else
7584 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7585 end if;
7587 --------------------
7588 -- Linker_Options --
7589 --------------------
7591 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
7593 when Pragma_Linker_Options => Linker_Options : declare
7594 Arg : Node_Id;
7596 begin
7597 Check_Ada_83_Warning;
7598 Check_No_Identifiers;
7599 Check_Arg_Count (1);
7600 Check_Is_In_Decl_Part_Or_Package_Spec;
7602 if Operating_Mode = Generate_Code
7603 and then In_Extended_Main_Source_Unit (N)
7604 then
7605 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7606 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
7608 Arg := Arg2;
7609 while Present (Arg) loop
7610 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7611 Store_String_Char (ASCII.NUL);
7612 Store_String_Chars
7613 (Strval (Expr_Value_S (Expression (Arg))));
7614 Arg := Next (Arg);
7615 end loop;
7617 Store_Linker_Option_String (End_String);
7618 end if;
7619 end Linker_Options;
7621 --------------------
7622 -- Linker_Section --
7623 --------------------
7625 -- pragma Linker_Section (
7626 -- [Entity =>] LOCAL_NAME
7627 -- [Section =>] static_string_EXPRESSION);
7629 when Pragma_Linker_Section =>
7630 GNAT_Pragma;
7631 Check_Arg_Count (2);
7632 Check_Optional_Identifier (Arg1, Name_Entity);
7633 Check_Optional_Identifier (Arg2, Name_Section);
7634 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7635 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7637 -- The only processing required is to link this item on to the
7638 -- list of rep items for the given entity. This is accomplished
7639 -- by the call to Rep_Item_Too_Late (when no error is detected
7640 -- and False is returned).
7642 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7643 return;
7644 else
7645 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7646 end if;
7648 ----------
7649 -- List --
7650 ----------
7652 -- pragma List (On | Off)
7654 -- There is nothing to do here, since we did all the processing
7655 -- for this pragma in Par.Prag (so that it works properly even in
7656 -- syntax only mode)
7658 when Pragma_List =>
7659 null;
7661 --------------------
7662 -- Locking_Policy --
7663 --------------------
7665 -- pragma Locking_Policy (policy_IDENTIFIER);
7667 when Pragma_Locking_Policy => declare
7668 LP : Character;
7670 begin
7671 Check_Ada_83_Warning;
7672 Check_Arg_Count (1);
7673 Check_No_Identifiers;
7674 Check_Arg_Is_Locking_Policy (Arg1);
7675 Check_Valid_Configuration_Pragma;
7676 Get_Name_String (Chars (Expression (Arg1)));
7677 LP := Fold_Upper (Name_Buffer (1));
7679 if Locking_Policy /= ' '
7680 and then Locking_Policy /= LP
7681 then
7682 Error_Msg_Sloc := Locking_Policy_Sloc;
7683 Error_Pragma ("locking policy incompatible with policy#");
7685 -- Set new policy, but always preserve System_Location since
7686 -- we like the error message with the run time name.
7688 else
7689 Locking_Policy := LP;
7691 if Locking_Policy_Sloc /= System_Location then
7692 Locking_Policy_Sloc := Loc;
7693 end if;
7694 end if;
7695 end;
7697 ----------------
7698 -- Long_Float --
7699 ----------------
7701 -- pragma Long_Float (D_Float | G_Float);
7703 when Pragma_Long_Float =>
7704 GNAT_Pragma;
7705 Check_Valid_Configuration_Pragma;
7706 Check_Arg_Count (1);
7707 Check_No_Identifier (Arg1);
7708 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
7710 if not OpenVMS_On_Target then
7711 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
7712 end if;
7714 -- D_Float case
7716 if Chars (Expression (Arg1)) = Name_D_Float then
7717 if Opt.Float_Format_Long = 'G' then
7718 Error_Pragma ("G_Float previously specified");
7719 end if;
7721 Opt.Float_Format_Long := 'D';
7723 -- G_Float case (this is the default, does not need overriding)
7725 else
7726 if Opt.Float_Format_Long = 'D' then
7727 Error_Pragma ("D_Float previously specified");
7728 end if;
7730 Opt.Float_Format_Long := 'G';
7731 end if;
7733 Set_Standard_Fpt_Formats;
7735 -----------------------
7736 -- Machine_Attribute --
7737 -----------------------
7739 -- pragma Machine_Attribute (
7740 -- [Entity =>] LOCAL_NAME,
7741 -- [Attribute_Name =>] static_string_EXPRESSION
7742 -- [,[Info =>] static_string_EXPRESSION] );
7744 when Pragma_Machine_Attribute => Machine_Attribute : declare
7745 Def_Id : Entity_Id;
7747 begin
7748 GNAT_Pragma;
7750 if Arg_Count = 3 then
7751 Check_Optional_Identifier (Arg3, "info");
7752 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
7753 else
7754 Check_Arg_Count (2);
7755 end if;
7757 Check_Arg_Is_Local_Name (Arg1);
7758 Check_Optional_Identifier (Arg2, "attribute_name");
7759 Check_Optional_Identifier (Arg1, Name_Entity);
7760 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7761 Def_Id := Entity (Expression (Arg1));
7763 if Is_Access_Type (Def_Id) then
7764 Def_Id := Designated_Type (Def_Id);
7765 end if;
7767 if Rep_Item_Too_Early (Def_Id, N) then
7768 return;
7769 end if;
7771 Def_Id := Underlying_Type (Def_Id);
7773 -- The only processing required is to link this item on to the
7774 -- list of rep items for the given entity. This is accomplished
7775 -- by the call to Rep_Item_Too_Late (when no error is detected
7776 -- and False is returned).
7778 if Rep_Item_Too_Late (Def_Id, N) then
7779 return;
7780 else
7781 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7782 end if;
7783 end Machine_Attribute;
7785 ----------
7786 -- Main --
7787 ----------
7789 -- pragma Main_Storage
7790 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7792 -- MAIN_STORAGE_OPTION ::=
7793 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7794 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7796 when Pragma_Main => Main : declare
7797 Args : Args_List (1 .. 3);
7798 Names : constant Name_List (1 .. 3) := (
7799 Name_Stack_Size,
7800 Name_Task_Stack_Size_Default,
7801 Name_Time_Slicing_Enabled);
7803 Nod : Node_Id;
7805 begin
7806 GNAT_Pragma;
7807 Gather_Associations (Names, Args);
7809 for J in 1 .. 2 loop
7810 if Present (Args (J)) then
7811 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7812 end if;
7813 end loop;
7815 if Present (Args (3)) then
7816 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
7817 end if;
7819 Nod := Next (N);
7820 while Present (Nod) loop
7821 if Nkind (Nod) = N_Pragma
7822 and then Chars (Nod) = Name_Main
7823 then
7824 Error_Msg_Name_1 := Chars (N);
7825 Error_Msg_N ("duplicate pragma% not permitted", Nod);
7826 end if;
7828 Next (Nod);
7829 end loop;
7830 end Main;
7832 ------------------
7833 -- Main_Storage --
7834 ------------------
7836 -- pragma Main_Storage
7837 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7839 -- MAIN_STORAGE_OPTION ::=
7840 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7841 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7843 when Pragma_Main_Storage => Main_Storage : declare
7844 Args : Args_List (1 .. 2);
7845 Names : constant Name_List (1 .. 2) := (
7846 Name_Working_Storage,
7847 Name_Top_Guard);
7849 Nod : Node_Id;
7851 begin
7852 GNAT_Pragma;
7853 Gather_Associations (Names, Args);
7855 for J in 1 .. 2 loop
7856 if Present (Args (J)) then
7857 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7858 end if;
7859 end loop;
7861 Check_In_Main_Program;
7863 Nod := Next (N);
7864 while Present (Nod) loop
7865 if Nkind (Nod) = N_Pragma
7866 and then Chars (Nod) = Name_Main_Storage
7867 then
7868 Error_Msg_Name_1 := Chars (N);
7869 Error_Msg_N ("duplicate pragma% not permitted", Nod);
7870 end if;
7872 Next (Nod);
7873 end loop;
7874 end Main_Storage;
7876 -----------------
7877 -- Memory_Size --
7878 -----------------
7880 -- pragma Memory_Size (NUMERIC_LITERAL)
7882 when Pragma_Memory_Size =>
7883 GNAT_Pragma;
7885 -- Memory size is simply ignored
7887 Check_No_Identifiers;
7888 Check_Arg_Count (1);
7889 Check_Arg_Is_Integer_Literal (Arg1);
7891 ---------------
7892 -- No_Return --
7893 ---------------
7895 -- pragma No_Return (procedure_LOCAL_NAME);
7897 when Pragma_No_Return => No_Return : declare
7898 Id : Node_Id;
7899 E : Entity_Id;
7900 Found : Boolean;
7902 begin
7903 GNAT_Pragma;
7904 Check_Arg_Count (1);
7905 Check_No_Identifiers;
7906 Check_Arg_Is_Local_Name (Arg1);
7907 Id := Expression (Arg1);
7908 Analyze (Id);
7910 if not Is_Entity_Name (Id) then
7911 Error_Pragma_Arg ("entity name required", Arg1);
7912 end if;
7914 if Etype (Id) = Any_Type then
7915 raise Pragma_Exit;
7916 end if;
7918 E := Entity (Id);
7920 Found := False;
7921 while Present (E)
7922 and then Scope (E) = Current_Scope
7923 loop
7924 if Ekind (E) = E_Procedure
7925 or else Ekind (E) = E_Generic_Procedure
7926 then
7927 Set_No_Return (E);
7928 Found := True;
7929 end if;
7931 E := Homonym (E);
7932 end loop;
7934 if not Found then
7935 Error_Pragma ("no procedures found for pragma%");
7936 end if;
7937 end No_Return;
7939 ------------------------
7940 -- No_Strict_Aliasing --
7941 ------------------------
7943 when Pragma_No_Strict_Aliasing => No_Strict_Alias : declare
7944 E_Id : Entity_Id;
7946 begin
7947 GNAT_Pragma;
7948 Check_At_Most_N_Arguments (1);
7950 if Arg_Count = 0 then
7951 Check_Valid_Configuration_Pragma;
7952 Opt.No_Strict_Aliasing := True;
7954 else
7955 Check_Optional_Identifier (Arg2, Name_Entity);
7956 Check_Arg_Is_Local_Name (Arg1);
7957 E_Id := Entity (Expression (Arg1));
7959 if E_Id = Any_Type then
7960 return;
7961 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
7962 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7963 end if;
7965 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
7966 end if;
7967 end No_Strict_Alias;
7969 -----------------
7970 -- Obsolescent --
7971 -----------------
7973 -- pragma Obsolescent [(static_string_EXPRESSION)];
7975 when Pragma_Obsolescent => Obsolescent : declare
7976 Subp : Node_Or_Entity_Id;
7977 S : String_Id;
7979 begin
7980 GNAT_Pragma;
7981 Check_At_Most_N_Arguments (1);
7982 Check_No_Identifiers;
7984 -- Check OK placement
7986 -- First possibility is within a declarative region, where the
7987 -- pragma immediately follows a subprogram declaration.
7989 if Present (Prev (N)) then
7990 Subp := Prev (N);
7992 -- Second possibility, stand alone subprogram declaration with the
7993 -- pragma immediately following the declaration.
7995 elsif No (Prev (N))
7996 and then Nkind (Parent (N)) = N_Compilation_Unit_Aux
7997 then
7998 Subp := Unit (Parent (Parent (N)));
8000 -- Any other possibility is a misplacement
8002 else
8003 Subp := Empty;
8004 end if;
8006 -- Check correct placement
8008 if Nkind (Subp) /= N_Subprogram_Declaration then
8009 Error_Pragma
8010 ("pragma% misplaced, must immediately " &
8011 "follow subprogram spec");
8013 -- If OK placement, set flag and acquire argument
8015 else
8016 Subp := Defining_Entity (Subp);
8017 Set_Is_Obsolescent (Subp);
8019 if Arg_Count = 1 then
8020 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8021 S := Strval (Expression (Arg1));
8023 for J in 1 .. String_Length (S) loop
8024 if not In_Character_Range (Get_String_Char (S, J)) then
8025 Error_Pragma_Arg
8026 ("pragma% argument does not allow wide characters",
8027 Arg1);
8028 end if;
8029 end loop;
8031 Set_Obsolescent_Warning (Subp, Expression (Arg1));
8032 end if;
8033 end if;
8034 end Obsolescent;
8036 -----------------
8037 -- No_Run_Time --
8038 -----------------
8040 -- pragma No_Run_Time
8042 -- Note: this pragma is retained for backwards compatibiltiy.
8043 -- See body of Rtsfind for full details on its handling.
8045 when Pragma_No_Run_Time =>
8046 GNAT_Pragma;
8047 Check_Valid_Configuration_Pragma;
8048 Check_Arg_Count (0);
8050 No_Run_Time_Mode := True;
8051 Configurable_Run_Time_Mode := True;
8053 declare
8054 Word32 : constant Boolean := Ttypes.System_Word_Size = 32;
8055 begin
8056 if Word32 then
8057 Duration_32_Bits_On_Target := True;
8058 end if;
8059 end;
8061 Set_Restriction (No_Finalization, N);
8062 Set_Restriction (No_Exception_Handlers, N);
8063 Set_Restriction (Max_Tasks, N, 0);
8064 Set_Restriction (No_Tasking, N);
8066 -----------------------
8067 -- Normalize_Scalars --
8068 -----------------------
8070 -- pragma Normalize_Scalars;
8072 when Pragma_Normalize_Scalars =>
8073 Check_Ada_83_Warning;
8074 Check_Arg_Count (0);
8075 Check_Valid_Configuration_Pragma;
8076 Normalize_Scalars := True;
8077 Init_Or_Norm_Scalars := True;
8079 --------------
8080 -- Optimize --
8081 --------------
8083 -- pragma Optimize (Time | Space);
8085 -- The actual check for optimize is done in Gigi. Note that this
8086 -- pragma does not actually change the optimization setting, it
8087 -- simply checks that it is consistent with the pragma.
8089 when Pragma_Optimize =>
8090 Check_No_Identifiers;
8091 Check_Arg_Count (1);
8092 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
8094 -------------------------
8095 -- Optional_Overriding --
8096 -------------------------
8098 -- These pragmas are treated as part of the previous subprogram
8099 -- declaration, and analyzed immediately after it (see sem_ch6,
8100 -- Check_Overriding_Operation). If the pragma has not been analyzed
8101 -- yet, it appears in the wrong place.
8103 when Pragma_Optional_Overriding =>
8104 Error_Msg_N ("pragma must appear immediately after subprogram", N);
8106 ----------
8107 -- Pack --
8108 ----------
8110 -- pragma Pack (first_subtype_LOCAL_NAME);
8112 when Pragma_Pack => Pack : declare
8113 Assoc : constant Node_Id := Arg1;
8114 Type_Id : Node_Id;
8115 Typ : Entity_Id;
8117 begin
8118 Check_No_Identifiers;
8119 Check_Arg_Count (1);
8120 Check_Arg_Is_Local_Name (Arg1);
8122 Type_Id := Expression (Assoc);
8123 Find_Type (Type_Id);
8124 Typ := Entity (Type_Id);
8126 if Typ = Any_Type
8127 or else Rep_Item_Too_Early (Typ, N)
8128 then
8129 return;
8130 else
8131 Typ := Underlying_Type (Typ);
8132 end if;
8134 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
8135 Error_Pragma ("pragma% must specify array or record type");
8136 end if;
8138 Check_First_Subtype (Arg1);
8140 if Has_Pragma_Pack (Typ) then
8141 Error_Pragma ("duplicate pragma%, only one allowed");
8143 -- Array type. We set the Has_Pragma_Pack flag, and Is_Packed,
8144 -- but not Has_Non_Standard_Rep, because we don't actually know
8145 -- till freeze time if the array can have packed representation.
8146 -- That's because in the general case we do not know enough about
8147 -- the component type until it in turn is frozen, which certainly
8148 -- happens before the array type is frozen, but not necessarily
8149 -- till that point (i.e. right now it may be unfrozen).
8151 elsif Is_Array_Type (Typ) then
8152 if Has_Aliased_Components (Base_Type (Typ)) then
8153 Error_Pragma
8154 ("pragma% ignored, cannot pack aliased components?");
8156 elsif Has_Atomic_Components (Typ)
8157 or else Is_Atomic (Component_Type (Typ))
8158 then
8159 Error_Pragma
8160 ("?pragma% ignored, cannot pack atomic components");
8162 elsif not Rep_Item_Too_Late (Typ, N) then
8163 Set_Is_Packed (Base_Type (Typ));
8164 Set_Has_Pragma_Pack (Base_Type (Typ));
8165 Set_Has_Non_Standard_Rep (Base_Type (Typ));
8166 end if;
8168 -- Record type. For record types, the pack is always effective
8170 else pragma Assert (Is_Record_Type (Typ));
8171 if not Rep_Item_Too_Late (Typ, N) then
8172 Set_Has_Pragma_Pack (Base_Type (Typ));
8173 Set_Is_Packed (Base_Type (Typ));
8174 Set_Has_Non_Standard_Rep (Base_Type (Typ));
8175 end if;
8176 end if;
8177 end Pack;
8179 ----------
8180 -- Page --
8181 ----------
8183 -- pragma Page;
8185 -- There is nothing to do here, since we did all the processing
8186 -- for this pragma in Par.Prag (so that it works properly even in
8187 -- syntax only mode)
8189 when Pragma_Page =>
8190 null;
8192 -------------
8193 -- Passive --
8194 -------------
8196 -- pragma Passive [(PASSIVE_FORM)];
8198 -- PASSIVE_FORM ::= Semaphore | No
8200 when Pragma_Passive =>
8201 GNAT_Pragma;
8203 if Nkind (Parent (N)) /= N_Task_Definition then
8204 Error_Pragma ("pragma% must be within task definition");
8205 end if;
8207 if Arg_Count /= 0 then
8208 Check_Arg_Count (1);
8209 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
8210 end if;
8212 -------------
8213 -- Polling --
8214 -------------
8216 -- pragma Polling (ON | OFF);
8218 when Pragma_Polling =>
8219 GNAT_Pragma;
8220 Check_Arg_Count (1);
8221 Check_No_Identifiers;
8222 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8223 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
8225 ---------------------
8226 -- Persistent_Data --
8227 ---------------------
8229 when Pragma_Persistent_Data => declare
8230 Ent : Entity_Id;
8232 begin
8233 -- Register the pragma as applying to the compilation unit.
8234 -- Individual Persistent_Object pragmas for relevant objects
8235 -- are generated the end of the compilation.
8237 GNAT_Pragma;
8238 Check_Valid_Configuration_Pragma;
8239 Check_Arg_Count (0);
8240 Ent := Find_Lib_Unit_Name;
8241 Set_Is_Preelaborated (Ent);
8242 end;
8244 -----------------------
8245 -- Persistent_Object --
8246 -----------------------
8248 when Pragma_Persistent_Object => declare
8249 Decl : Node_Id;
8250 Ent : Entity_Id;
8251 MA : Node_Id;
8252 Str : String_Id;
8254 begin
8255 GNAT_Pragma;
8256 Check_Arg_Count (1);
8257 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8259 if not Is_Entity_Name (Expression (Arg1))
8260 or else
8261 (Ekind (Entity (Expression (Arg1))) /= E_Variable
8262 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
8263 then
8264 Error_Pragma_Arg ("pragma only applies to objects", Arg1);
8265 end if;
8267 Ent := Entity (Expression (Arg1));
8268 Decl := Parent (Ent);
8270 if Nkind (Decl) /= N_Object_Declaration then
8271 return;
8272 end if;
8274 -- Placement of the object depends on whether there is
8275 -- an initial value or none. If the No_Initialization flag
8276 -- is set, the initialization has been transformed into
8277 -- assignments, which is disallowed elaboration code.
8279 if No_Initialization (Decl) then
8280 Error_Msg_N
8281 ("initialization for persistent object"
8282 & "must be static expression", Decl);
8283 return;
8284 end if;
8286 if No (Expression (Decl)) then
8287 Start_String;
8288 Store_String_Chars ("section ("".persistent.bss"")");
8289 Str := End_String;
8291 else
8292 if not Is_OK_Static_Expression (Expression (Decl)) then
8293 Flag_Non_Static_Expr
8294 ("initialization for persistent object"
8295 & "must be static expression!", Expression (Decl));
8296 return;
8297 end if;
8299 Start_String;
8300 Store_String_Chars ("section ("".persistent.data"")");
8301 Str := End_String;
8302 end if;
8304 MA :=
8305 Make_Pragma
8306 (Sloc (N),
8307 Name_Machine_Attribute,
8308 New_List
8309 (Make_Pragma_Argument_Association
8310 (Sloc => Sloc (Arg1),
8311 Expression => New_Occurrence_Of (Ent, Sloc (Ent))),
8312 Make_Pragma_Argument_Association
8313 (Sloc => Sloc (Arg1),
8314 Expression =>
8315 Make_String_Literal
8316 (Sloc => Sloc (Arg1),
8317 Strval => Str))));
8319 Insert_After (N, MA);
8320 Analyze (MA);
8321 Set_Has_Gigi_Rep_Item (Ent);
8322 end;
8324 ------------------
8325 -- Preelaborate --
8326 ------------------
8328 -- pragma Preelaborate [(library_unit_NAME)];
8330 -- Set the flag Is_Preelaborated of program unit name entity
8332 when Pragma_Preelaborate => Preelaborate : declare
8333 Pa : constant Node_Id := Parent (N);
8334 Pk : constant Node_Kind := Nkind (Pa);
8335 Ent : Entity_Id;
8337 begin
8338 Check_Ada_83_Warning;
8339 Check_Valid_Library_Unit_Pragma;
8341 if Nkind (N) = N_Null_Statement then
8342 return;
8343 end if;
8345 Ent := Find_Lib_Unit_Name;
8347 -- This filters out pragmas inside generic parent then
8348 -- show up inside instantiation
8350 if Present (Ent)
8351 and then not (Pk = N_Package_Specification
8352 and then Present (Generic_Parent (Pa)))
8353 then
8354 if not Debug_Flag_U then
8355 Set_Is_Preelaborated (Ent);
8356 Set_Suppress_Elaboration_Warnings (Ent);
8357 end if;
8358 end if;
8359 end Preelaborate;
8361 --------------
8362 -- Priority --
8363 --------------
8365 -- pragma Priority (EXPRESSION);
8367 when Pragma_Priority => Priority : declare
8368 P : constant Node_Id := Parent (N);
8369 Arg : Node_Id;
8371 begin
8372 Check_No_Identifiers;
8373 Check_Arg_Count (1);
8375 -- Subprogram case
8377 if Nkind (P) = N_Subprogram_Body then
8378 Check_In_Main_Program;
8380 Arg := Expression (Arg1);
8381 Analyze_And_Resolve (Arg, Standard_Integer);
8383 -- Must be static
8385 if not Is_Static_Expression (Arg) then
8386 Flag_Non_Static_Expr
8387 ("main subprogram priority is not static!", Arg);
8388 raise Pragma_Exit;
8390 -- If constraint error, then we already signalled an error
8392 elsif Raises_Constraint_Error (Arg) then
8393 null;
8395 -- Otherwise check in range
8397 else
8398 declare
8399 Val : constant Uint := Expr_Value (Arg);
8401 begin
8402 if Val < 0
8403 or else Val > Expr_Value (Expression
8404 (Parent (RTE (RE_Max_Priority))))
8405 then
8406 Error_Pragma_Arg
8407 ("main subprogram priority is out of range", Arg1);
8408 end if;
8409 end;
8410 end if;
8412 Set_Main_Priority
8413 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8415 -- Task or Protected, must be of type Integer
8417 elsif Nkind (P) = N_Protected_Definition
8418 or else
8419 Nkind (P) = N_Task_Definition
8420 then
8421 Arg := Expression (Arg1);
8423 -- The expression must be analyzed in the special manner
8424 -- described in "Handling of Default and Per-Object
8425 -- Expressions" in sem.ads.
8427 Analyze_Per_Use_Expression (Arg, Standard_Integer);
8429 if not Is_Static_Expression (Arg) then
8430 Check_Restriction (Static_Priorities, Arg);
8431 end if;
8433 -- Anything else is incorrect
8435 else
8436 Pragma_Misplaced;
8437 end if;
8439 if Has_Priority_Pragma (P) then
8440 Error_Pragma ("duplicate pragma% not allowed");
8441 else
8442 Set_Has_Priority_Pragma (P, True);
8444 if Nkind (P) = N_Protected_Definition
8445 or else
8446 Nkind (P) = N_Task_Definition
8447 then
8448 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8449 -- exp_ch9 should use this ???
8450 end if;
8451 end if;
8452 end Priority;
8454 -------------
8455 -- Profile --
8456 -------------
8458 -- pragma Profile (profile_IDENTIFIER);
8460 -- profile_IDENTIFIER => Protected | Ravenscar
8462 when Pragma_Profile =>
8463 Check_Arg_Count (1);
8464 Check_Valid_Configuration_Pragma;
8465 Check_No_Identifiers;
8467 declare
8468 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8469 begin
8470 if Chars (Argx) = Name_Ravenscar then
8471 Set_Ravenscar_Profile (N);
8473 elsif Chars (Argx) = Name_Restricted then
8474 Set_Profile_Restrictions (Restricted, N, Warn => False);
8475 else
8476 Error_Pragma_Arg ("& is not a valid profile", Argx);
8477 end if;
8478 end;
8480 ----------------------
8481 -- Profile_Warnings --
8482 ----------------------
8484 -- pragma Profile_Warnings (profile_IDENTIFIER);
8486 -- profile_IDENTIFIER => Protected | Ravenscar
8488 when Pragma_Profile_Warnings =>
8489 GNAT_Pragma;
8490 Check_Arg_Count (1);
8491 Check_Valid_Configuration_Pragma;
8492 Check_No_Identifiers;
8494 declare
8495 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8496 begin
8497 if Chars (Argx) = Name_Ravenscar then
8498 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
8500 elsif Chars (Argx) = Name_Restricted then
8501 Set_Profile_Restrictions (Restricted, N, Warn => True);
8502 else
8503 Error_Pragma_Arg ("& is not a valid profile", Argx);
8504 end if;
8505 end;
8507 --------------------------
8508 -- Propagate_Exceptions --
8509 --------------------------
8511 -- pragma Propagate_Exceptions;
8513 when Pragma_Propagate_Exceptions =>
8514 GNAT_Pragma;
8515 Check_Arg_Count (0);
8517 if In_Extended_Main_Source_Unit (N) then
8518 Propagate_Exceptions := True;
8519 end if;
8521 ------------------
8522 -- Psect_Object --
8523 ------------------
8525 -- pragma Psect_Object (
8526 -- [Internal =>] LOCAL_NAME,
8527 -- [, [External =>] EXTERNAL_SYMBOL]
8528 -- [, [Size =>] EXTERNAL_SYMBOL]);
8530 when Pragma_Psect_Object | Pragma_Common_Object =>
8531 Psect_Object : declare
8532 Args : Args_List (1 .. 3);
8533 Names : constant Name_List (1 .. 3) := (
8534 Name_Internal,
8535 Name_External,
8536 Name_Size);
8538 Internal : Node_Id renames Args (1);
8539 External : Node_Id renames Args (2);
8540 Size : Node_Id renames Args (3);
8542 Def_Id : Entity_Id;
8544 procedure Check_Too_Long (Arg : Node_Id);
8545 -- Posts message if the argument is an identifier with more
8546 -- than 31 characters, or a string literal with more than
8547 -- 31 characters, and we are operating under VMS
8549 --------------------
8550 -- Check_Too_Long --
8551 --------------------
8553 procedure Check_Too_Long (Arg : Node_Id) is
8554 X : constant Node_Id := Original_Node (Arg);
8556 begin
8557 if Nkind (X) /= N_String_Literal
8558 and then
8559 Nkind (X) /= N_Identifier
8560 then
8561 Error_Pragma_Arg
8562 ("inappropriate argument for pragma %", Arg);
8563 end if;
8565 if OpenVMS_On_Target then
8566 if (Nkind (X) = N_String_Literal
8567 and then String_Length (Strval (X)) > 31)
8568 or else
8569 (Nkind (X) = N_Identifier
8570 and then Length_Of_Name (Chars (X)) > 31)
8571 then
8572 Error_Pragma_Arg
8573 ("argument for pragma % is longer than 31 characters",
8574 Arg);
8575 end if;
8576 end if;
8577 end Check_Too_Long;
8579 -- Start of processing for Common_Object/Psect_Object
8581 begin
8582 GNAT_Pragma;
8583 Gather_Associations (Names, Args);
8584 Process_Extended_Import_Export_Internal_Arg (Internal);
8586 Def_Id := Entity (Internal);
8588 if Ekind (Def_Id) /= E_Constant
8589 and then Ekind (Def_Id) /= E_Variable
8590 then
8591 Error_Pragma_Arg
8592 ("pragma% must designate an object", Internal);
8593 end if;
8595 Check_Too_Long (Internal);
8597 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
8598 Error_Pragma_Arg
8599 ("cannot use pragma% for imported/exported object",
8600 Internal);
8601 end if;
8603 if Is_Concurrent_Type (Etype (Internal)) then
8604 Error_Pragma_Arg
8605 ("cannot specify pragma % for task/protected object",
8606 Internal);
8607 end if;
8609 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
8610 or else
8611 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
8612 then
8613 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
8614 end if;
8616 if Ekind (Def_Id) = E_Constant then
8617 Error_Pragma_Arg
8618 ("cannot specify pragma % for a constant", Internal);
8619 end if;
8621 if Is_Record_Type (Etype (Internal)) then
8622 declare
8623 Ent : Entity_Id;
8624 Decl : Entity_Id;
8626 begin
8627 Ent := First_Entity (Etype (Internal));
8628 while Present (Ent) loop
8629 Decl := Declaration_Node (Ent);
8631 if Ekind (Ent) = E_Component
8632 and then Nkind (Decl) = N_Component_Declaration
8633 and then Present (Expression (Decl))
8634 and then Warn_On_Export_Import
8635 then
8636 Error_Msg_N
8637 ("?object for pragma % has defaults", Internal);
8638 exit;
8640 else
8641 Next_Entity (Ent);
8642 end if;
8643 end loop;
8644 end;
8645 end if;
8647 if Present (Size) then
8648 Check_Too_Long (Size);
8649 end if;
8651 if Present (External) then
8652 Check_Arg_Is_External_Name (External);
8653 Check_Too_Long (External);
8654 end if;
8656 -- If all error tests pass, link pragma on to the rep item chain
8658 Record_Rep_Item (Def_Id, N);
8659 end Psect_Object;
8661 ----------
8662 -- Pure --
8663 ----------
8665 -- pragma Pure [(library_unit_NAME)];
8667 when Pragma_Pure => Pure : declare
8668 Ent : Entity_Id;
8669 begin
8670 Check_Ada_83_Warning;
8671 Check_Valid_Library_Unit_Pragma;
8673 if Nkind (N) = N_Null_Statement then
8674 return;
8675 end if;
8677 Ent := Find_Lib_Unit_Name;
8678 Set_Is_Pure (Ent);
8679 Set_Suppress_Elaboration_Warnings (Ent);
8680 end Pure;
8682 -------------------
8683 -- Pure_Function --
8684 -------------------
8686 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
8688 when Pragma_Pure_Function => Pure_Function : declare
8689 E_Id : Node_Id;
8690 E : Entity_Id;
8691 Def_Id : Entity_Id;
8692 Effective : Boolean := False;
8694 begin
8695 GNAT_Pragma;
8696 Check_Arg_Count (1);
8697 Check_Optional_Identifier (Arg1, Name_Entity);
8698 Check_Arg_Is_Local_Name (Arg1);
8699 E_Id := Expression (Arg1);
8701 if Error_Posted (E_Id) then
8702 return;
8703 end if;
8705 -- Loop through homonyms (overloadings) of referenced entity
8707 E := Entity (E_Id);
8709 if Present (E) then
8710 loop
8711 Def_Id := Get_Base_Subprogram (E);
8713 if Ekind (Def_Id) /= E_Function
8714 and then Ekind (Def_Id) /= E_Generic_Function
8715 and then Ekind (Def_Id) /= E_Operator
8716 then
8717 Error_Pragma_Arg
8718 ("pragma% requires a function name", Arg1);
8719 end if;
8721 Set_Is_Pure (Def_Id);
8723 if not Has_Pragma_Pure_Function (Def_Id) then
8724 Set_Has_Pragma_Pure_Function (Def_Id);
8725 Effective := True;
8726 end if;
8728 E := Homonym (E);
8729 exit when No (E) or else Scope (E) /= Current_Scope;
8730 end loop;
8732 if not Effective
8733 and then Warn_On_Redundant_Constructs
8734 then
8735 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
8736 N, Entity (E_Id));
8737 end if;
8738 end if;
8739 end Pure_Function;
8741 --------------------
8742 -- Queuing_Policy --
8743 --------------------
8745 -- pragma Queuing_Policy (policy_IDENTIFIER);
8747 when Pragma_Queuing_Policy => declare
8748 QP : Character;
8750 begin
8751 Check_Ada_83_Warning;
8752 Check_Arg_Count (1);
8753 Check_No_Identifiers;
8754 Check_Arg_Is_Queuing_Policy (Arg1);
8755 Check_Valid_Configuration_Pragma;
8756 Get_Name_String (Chars (Expression (Arg1)));
8757 QP := Fold_Upper (Name_Buffer (1));
8759 if Queuing_Policy /= ' '
8760 and then Queuing_Policy /= QP
8761 then
8762 Error_Msg_Sloc := Queuing_Policy_Sloc;
8763 Error_Pragma ("queuing policy incompatible with policy#");
8765 -- Set new policy, but always preserve System_Location since
8766 -- we like the error message with the run time name.
8768 else
8769 Queuing_Policy := QP;
8771 if Queuing_Policy_Sloc /= System_Location then
8772 Queuing_Policy_Sloc := Loc;
8773 end if;
8774 end if;
8775 end;
8777 ---------------------------
8778 -- Remote_Call_Interface --
8779 ---------------------------
8781 -- pragma Remote_Call_Interface [(library_unit_NAME)];
8783 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
8784 Cunit_Node : Node_Id;
8785 Cunit_Ent : Entity_Id;
8786 K : Node_Kind;
8788 begin
8789 Check_Ada_83_Warning;
8790 Check_Valid_Library_Unit_Pragma;
8792 if Nkind (N) = N_Null_Statement then
8793 return;
8794 end if;
8796 Cunit_Node := Cunit (Current_Sem_Unit);
8797 K := Nkind (Unit (Cunit_Node));
8798 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8800 if K = N_Package_Declaration
8801 or else K = N_Generic_Package_Declaration
8802 or else K = N_Subprogram_Declaration
8803 or else K = N_Generic_Subprogram_Declaration
8804 or else (K = N_Subprogram_Body
8805 and then Acts_As_Spec (Unit (Cunit_Node)))
8806 then
8807 null;
8808 else
8809 Error_Pragma (
8810 "pragma% must apply to package or subprogram declaration");
8811 end if;
8813 Set_Is_Remote_Call_Interface (Cunit_Ent);
8814 end Remote_Call_Interface;
8816 ------------------
8817 -- Remote_Types --
8818 ------------------
8820 -- pragma Remote_Types [(library_unit_NAME)];
8822 when Pragma_Remote_Types => Remote_Types : declare
8823 Cunit_Node : Node_Id;
8824 Cunit_Ent : Entity_Id;
8826 begin
8827 Check_Ada_83_Warning;
8828 Check_Valid_Library_Unit_Pragma;
8830 if Nkind (N) = N_Null_Statement then
8831 return;
8832 end if;
8834 Cunit_Node := Cunit (Current_Sem_Unit);
8835 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8837 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
8838 and then
8839 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
8840 then
8841 Error_Pragma (
8842 "pragma% can only apply to a package declaration");
8843 end if;
8845 Set_Is_Remote_Types (Cunit_Ent);
8846 end Remote_Types;
8848 ---------------
8849 -- Ravenscar --
8850 ---------------
8852 -- pragma Ravenscar;
8854 when Pragma_Ravenscar =>
8855 GNAT_Pragma;
8856 Check_Arg_Count (0);
8857 Check_Valid_Configuration_Pragma;
8858 Set_Ravenscar_Profile (N);
8860 if Warn_On_Obsolescent_Feature then
8861 Error_Msg_N
8862 ("pragma Ravenscar is an obsolescent feature?", N);
8863 Error_Msg_N
8864 ("|use pragma Profile (Ravenscar) instead", N);
8865 end if;
8867 -------------------------
8868 -- Restricted_Run_Time --
8869 -------------------------
8871 -- pragma Restricted_Run_Time;
8873 when Pragma_Restricted_Run_Time =>
8874 GNAT_Pragma;
8875 Check_Arg_Count (0);
8876 Check_Valid_Configuration_Pragma;
8877 Set_Profile_Restrictions (Restricted, N, Warn => False);
8879 if Warn_On_Obsolescent_Feature then
8880 Error_Msg_N
8881 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
8882 Error_Msg_N
8883 ("|use pragma Profile (Restricted) instead", N);
8884 end if;
8886 ------------------
8887 -- Restrictions --
8888 ------------------
8890 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
8892 -- RESTRICTION ::=
8893 -- restriction_IDENTIFIER
8894 -- | restriction_parameter_IDENTIFIER => EXPRESSION
8896 when Pragma_Restrictions =>
8897 Process_Restrictions_Or_Restriction_Warnings;
8899 --------------------------
8900 -- Restriction_Warnings --
8901 --------------------------
8903 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
8905 -- RESTRICTION ::=
8906 -- restriction_IDENTIFIER
8907 -- | restriction_parameter_IDENTIFIER => EXPRESSION
8909 when Pragma_Restriction_Warnings =>
8910 Process_Restrictions_Or_Restriction_Warnings;
8912 ----------------
8913 -- Reviewable --
8914 ----------------
8916 -- pragma Reviewable;
8918 when Pragma_Reviewable =>
8919 Check_Ada_83_Warning;
8920 Check_Arg_Count (0);
8922 -------------------
8923 -- Share_Generic --
8924 -------------------
8926 -- pragma Share_Generic (NAME {, NAME});
8928 when Pragma_Share_Generic =>
8929 GNAT_Pragma;
8930 Process_Generic_List;
8932 ------------
8933 -- Shared --
8934 ------------
8936 -- pragma Shared (LOCAL_NAME);
8938 when Pragma_Shared =>
8939 GNAT_Pragma;
8940 Process_Atomic_Shared_Volatile;
8942 --------------------
8943 -- Shared_Passive --
8944 --------------------
8946 -- pragma Shared_Passive [(library_unit_NAME)];
8948 -- Set the flag Is_Shared_Passive of program unit name entity
8950 when Pragma_Shared_Passive => Shared_Passive : declare
8951 Cunit_Node : Node_Id;
8952 Cunit_Ent : Entity_Id;
8954 begin
8955 Check_Ada_83_Warning;
8956 Check_Valid_Library_Unit_Pragma;
8958 if Nkind (N) = N_Null_Statement then
8959 return;
8960 end if;
8962 Cunit_Node := Cunit (Current_Sem_Unit);
8963 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8965 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
8966 and then
8967 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
8968 then
8969 Error_Pragma (
8970 "pragma% can only apply to a package declaration");
8971 end if;
8973 Set_Is_Shared_Passive (Cunit_Ent);
8974 end Shared_Passive;
8976 ----------------------
8977 -- Source_File_Name --
8978 ----------------------
8980 -- There are five forms for this pragma:
8982 -- pragma Source_File_Name (
8983 -- [UNIT_NAME =>] unit_NAME,
8984 -- BODY_FILE_NAME => STRING_LITERAL
8985 -- [, [INDEX =>] INTEGER_LITERAL]);
8987 -- pragma Source_File_Name (
8988 -- [UNIT_NAME =>] unit_NAME,
8989 -- SPEC_FILE_NAME => STRING_LITERAL
8990 -- [, [INDEX =>] INTEGER_LITERAL]);
8992 -- pragma Source_File_Name (
8993 -- BODY_FILE_NAME => STRING_LITERAL
8994 -- [, DOT_REPLACEMENT => STRING_LITERAL]
8995 -- [, CASING => CASING_SPEC]);
8997 -- pragma Source_File_Name (
8998 -- SPEC_FILE_NAME => STRING_LITERAL
8999 -- [, DOT_REPLACEMENT => STRING_LITERAL]
9000 -- [, CASING => CASING_SPEC]);
9002 -- pragma Source_File_Name (
9003 -- SUBUNIT_FILE_NAME => STRING_LITERAL
9004 -- [, DOT_REPLACEMENT => STRING_LITERAL]
9005 -- [, CASING => CASING_SPEC]);
9007 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
9009 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
9010 -- Source_File_Name (SFN), however their usage is exclusive:
9011 -- SFN can only be used when no project file is used, while
9012 -- SFNP can only be used when a project file is used.
9014 -- No processing here. Processing was completed during parsing,
9015 -- since we need to have file names set as early as possible.
9016 -- Units are loaded well before semantic processing starts.
9018 -- The only processing we defer to this point is the check
9019 -- for correct placement.
9021 when Pragma_Source_File_Name =>
9022 GNAT_Pragma;
9023 Check_Valid_Configuration_Pragma;
9025 ------------------------------
9026 -- Source_File_Name_Project --
9027 ------------------------------
9029 -- See Source_File_Name for syntax
9031 -- No processing here. Processing was completed during parsing,
9032 -- since we need to have file names set as early as possible.
9033 -- Units are loaded well before semantic processing starts.
9035 -- The only processing we defer to this point is the check
9036 -- for correct placement.
9038 when Pragma_Source_File_Name_Project =>
9039 GNAT_Pragma;
9040 Check_Valid_Configuration_Pragma;
9042 -- Check that a pragma Source_File_Name_Project is used only
9043 -- in a configuration pragmas file.
9045 -- Pragmas Source_File_Name_Project should only be generated
9046 -- by the Project Manager in configuration pragmas files.
9048 -- This is really an ugly test. It seems to depend on some
9049 -- accidental and undocumented property. At the very least
9050 -- it needs to be documented, but it would be better to have
9051 -- a clean way of testing if we are in a configuration file???
9053 if Present (Parent (N)) then
9054 Error_Pragma
9055 ("pragma% can only appear in a configuration pragmas file");
9056 end if;
9058 ----------------------
9059 -- Source_Reference --
9060 ----------------------
9062 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
9064 -- Nothing to do, all processing completed in Par.Prag, since we
9065 -- need the information for possible parser messages that are output
9067 when Pragma_Source_Reference =>
9068 GNAT_Pragma;
9070 ------------------
9071 -- Storage_Size --
9072 ------------------
9074 -- pragma Storage_Size (EXPRESSION);
9076 when Pragma_Storage_Size => Storage_Size : declare
9077 P : constant Node_Id := Parent (N);
9078 Arg : Node_Id;
9080 begin
9081 Check_No_Identifiers;
9082 Check_Arg_Count (1);
9084 -- The expression must be analyzed in the special manner
9085 -- described in "Handling of Default Expressions" in sem.ads.
9087 -- Set In_Default_Expression for per-object case ???
9089 Arg := Expression (Arg1);
9090 Analyze_Per_Use_Expression (Arg, Any_Integer);
9092 if not Is_Static_Expression (Arg) then
9093 Check_Restriction (Static_Storage_Size, Arg);
9094 end if;
9096 if Nkind (P) /= N_Task_Definition then
9097 Pragma_Misplaced;
9098 return;
9100 else
9101 if Has_Storage_Size_Pragma (P) then
9102 Error_Pragma ("duplicate pragma% not allowed");
9103 else
9104 Set_Has_Storage_Size_Pragma (P, True);
9105 end if;
9107 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9108 -- ??? exp_ch9 should use this!
9109 end if;
9110 end Storage_Size;
9112 ------------------
9113 -- Storage_Unit --
9114 ------------------
9116 -- pragma Storage_Unit (NUMERIC_LITERAL);
9118 -- Only permitted argument is System'Storage_Unit value
9120 when Pragma_Storage_Unit =>
9121 Check_No_Identifiers;
9122 Check_Arg_Count (1);
9123 Check_Arg_Is_Integer_Literal (Arg1);
9125 if Intval (Expression (Arg1)) /=
9126 UI_From_Int (Ttypes.System_Storage_Unit)
9127 then
9128 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
9129 Error_Pragma_Arg
9130 ("the only allowed argument for pragma% is ^", Arg1);
9131 end if;
9133 --------------------
9134 -- Stream_Convert --
9135 --------------------
9137 -- pragma Stream_Convert (
9138 -- [Entity =>] type_LOCAL_NAME,
9139 -- [Read =>] function_NAME,
9140 -- [Write =>] function NAME);
9142 when Pragma_Stream_Convert => Stream_Convert : declare
9144 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
9145 -- Check that the given argument is the name of a local
9146 -- function of one argument that is not overloaded earlier
9147 -- in the current local scope. A check is also made that the
9148 -- argument is a function with one parameter.
9150 --------------------------------------
9151 -- Check_OK_Stream_Convert_Function --
9152 --------------------------------------
9154 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
9155 Ent : Entity_Id;
9157 begin
9158 Check_Arg_Is_Local_Name (Arg);
9159 Ent := Entity (Expression (Arg));
9161 if Has_Homonym (Ent) then
9162 Error_Pragma_Arg
9163 ("argument for pragma% may not be overloaded", Arg);
9164 end if;
9166 if Ekind (Ent) /= E_Function
9167 or else No (First_Formal (Ent))
9168 or else Present (Next_Formal (First_Formal (Ent)))
9169 then
9170 Error_Pragma_Arg
9171 ("argument for pragma% must be" &
9172 " function of one argument", Arg);
9173 end if;
9174 end Check_OK_Stream_Convert_Function;
9176 -- Start of procecessing for Stream_Convert
9178 begin
9179 GNAT_Pragma;
9180 Check_Arg_Count (3);
9181 Check_Optional_Identifier (Arg1, Name_Entity);
9182 Check_Optional_Identifier (Arg2, Name_Read);
9183 Check_Optional_Identifier (Arg3, Name_Write);
9184 Check_Arg_Is_Local_Name (Arg1);
9185 Check_OK_Stream_Convert_Function (Arg2);
9186 Check_OK_Stream_Convert_Function (Arg3);
9188 declare
9189 Typ : constant Entity_Id :=
9190 Underlying_Type (Entity (Expression (Arg1)));
9191 Read : constant Entity_Id := Entity (Expression (Arg2));
9192 Write : constant Entity_Id := Entity (Expression (Arg3));
9194 begin
9195 if Etype (Typ) = Any_Type
9196 or else
9197 Etype (Read) = Any_Type
9198 or else
9199 Etype (Write) = Any_Type
9200 then
9201 return;
9202 end if;
9204 Check_First_Subtype (Arg1);
9206 if Rep_Item_Too_Early (Typ, N)
9207 or else
9208 Rep_Item_Too_Late (Typ, N)
9209 then
9210 return;
9211 end if;
9213 if Underlying_Type (Etype (Read)) /= Typ then
9214 Error_Pragma_Arg
9215 ("incorrect return type for function&", Arg2);
9216 end if;
9218 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
9219 Error_Pragma_Arg
9220 ("incorrect parameter type for function&", Arg3);
9221 end if;
9223 if Underlying_Type (Etype (First_Formal (Read))) /=
9224 Underlying_Type (Etype (Write))
9225 then
9226 Error_Pragma_Arg
9227 ("result type of & does not match Read parameter type",
9228 Arg3);
9229 end if;
9230 end;
9231 end Stream_Convert;
9233 -------------------------
9234 -- Style_Checks (GNAT) --
9235 -------------------------
9237 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
9239 -- This is processed by the parser since some of the style
9240 -- checks take place during source scanning and parsing. This
9241 -- means that we don't need to issue error messages here.
9243 when Pragma_Style_Checks => Style_Checks : declare
9244 A : constant Node_Id := Expression (Arg1);
9245 S : String_Id;
9246 C : Char_Code;
9248 begin
9249 GNAT_Pragma;
9250 Check_No_Identifiers;
9252 -- Two argument form
9254 if Arg_Count = 2 then
9255 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9257 declare
9258 E_Id : Node_Id;
9259 E : Entity_Id;
9261 begin
9262 E_Id := Expression (Arg2);
9263 Analyze (E_Id);
9265 if not Is_Entity_Name (E_Id) then
9266 Error_Pragma_Arg
9267 ("second argument of pragma% must be entity name",
9268 Arg2);
9269 end if;
9271 E := Entity (E_Id);
9273 if E = Any_Id then
9274 return;
9275 else
9276 loop
9277 Set_Suppress_Style_Checks (E,
9278 (Chars (Expression (Arg1)) = Name_Off));
9279 exit when No (Homonym (E));
9280 E := Homonym (E);
9281 end loop;
9282 end if;
9283 end;
9285 -- One argument form
9287 else
9288 Check_Arg_Count (1);
9290 if Nkind (A) = N_String_Literal then
9291 S := Strval (A);
9293 declare
9294 Slen : constant Natural := Natural (String_Length (S));
9295 Options : String (1 .. Slen);
9296 J : Natural;
9298 begin
9299 J := 1;
9300 loop
9301 C := Get_String_Char (S, Int (J));
9302 exit when not In_Character_Range (C);
9303 Options (J) := Get_Character (C);
9305 if J = Slen then
9306 Set_Style_Check_Options (Options);
9307 exit;
9308 else
9309 J := J + 1;
9310 end if;
9311 end loop;
9312 end;
9314 elsif Nkind (A) = N_Identifier then
9316 if Chars (A) = Name_All_Checks then
9317 Set_Default_Style_Check_Options;
9319 elsif Chars (A) = Name_On then
9320 Style_Check := True;
9322 elsif Chars (A) = Name_Off then
9323 Style_Check := False;
9325 end if;
9326 end if;
9327 end if;
9328 end Style_Checks;
9330 --------------
9331 -- Subtitle --
9332 --------------
9334 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
9336 when Pragma_Subtitle =>
9337 GNAT_Pragma;
9338 Check_Arg_Count (1);
9339 Check_Optional_Identifier (Arg1, Name_Subtitle);
9340 Check_Arg_Is_String_Literal (Arg1);
9342 --------------
9343 -- Suppress --
9344 --------------
9346 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
9348 when Pragma_Suppress =>
9349 Process_Suppress_Unsuppress (True);
9351 ------------------
9352 -- Suppress_All --
9353 ------------------
9355 -- pragma Suppress_All;
9357 -- The only check made here is that the pragma appears in the
9358 -- proper place, i.e. following a compilation unit. If indeed
9359 -- it appears in this context, then the parser has already
9360 -- inserted an equivalent pragma Suppress (All_Checks) to get
9361 -- the required effect.
9363 when Pragma_Suppress_All =>
9364 GNAT_Pragma;
9365 Check_Arg_Count (0);
9367 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9368 or else not Is_List_Member (N)
9369 or else List_Containing (N) /= Pragmas_After (Parent (N))
9370 then
9371 Error_Pragma
9372 ("misplaced pragma%, must follow compilation unit");
9373 end if;
9375 -------------------------
9376 -- Suppress_Debug_Info --
9377 -------------------------
9379 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
9381 when Pragma_Suppress_Debug_Info =>
9382 GNAT_Pragma;
9383 Check_Arg_Count (1);
9384 Check_Arg_Is_Local_Name (Arg1);
9385 Check_Optional_Identifier (Arg1, Name_Entity);
9386 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
9388 ----------------------------------
9389 -- Suppress_Exception_Locations --
9390 ----------------------------------
9392 -- pragma Suppress_Exception_Locations;
9394 when Pragma_Suppress_Exception_Locations =>
9395 GNAT_Pragma;
9396 Check_Arg_Count (0);
9397 Check_Valid_Configuration_Pragma;
9398 Exception_Locations_Suppressed := True;
9400 -----------------------------
9401 -- Suppress_Initialization --
9402 -----------------------------
9404 -- pragma Suppress_Initialization ([Entity =>] type_Name);
9406 when Pragma_Suppress_Initialization => Suppress_Init : declare
9407 E_Id : Node_Id;
9408 E : Entity_Id;
9410 begin
9411 GNAT_Pragma;
9412 Check_Arg_Count (1);
9413 Check_Optional_Identifier (Arg1, Name_Entity);
9414 Check_Arg_Is_Local_Name (Arg1);
9416 E_Id := Expression (Arg1);
9418 if Etype (E_Id) = Any_Type then
9419 return;
9420 end if;
9422 E := Entity (E_Id);
9424 if Is_Type (E) then
9425 if Is_Incomplete_Or_Private_Type (E) then
9426 if No (Full_View (Base_Type (E))) then
9427 Error_Pragma_Arg
9428 ("argument of pragma% cannot be an incomplete type",
9429 Arg1);
9430 else
9431 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
9432 end if;
9433 else
9434 Set_Suppress_Init_Proc (Base_Type (E));
9435 end if;
9437 else
9438 Error_Pragma_Arg
9439 ("pragma% requires argument that is a type name", Arg1);
9440 end if;
9441 end Suppress_Init;
9443 -----------------
9444 -- System_Name --
9445 -----------------
9447 -- pragma System_Name (DIRECT_NAME);
9449 -- Syntax check: one argument, which must be the identifier GNAT
9450 -- or the identifier GCC, no other identifiers are acceptable.
9452 when Pragma_System_Name =>
9453 Check_No_Identifiers;
9454 Check_Arg_Count (1);
9455 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
9457 -----------------------------
9458 -- Task_Dispatching_Policy --
9459 -----------------------------
9461 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
9463 when Pragma_Task_Dispatching_Policy => declare
9464 DP : Character;
9466 begin
9467 Check_Ada_83_Warning;
9468 Check_Arg_Count (1);
9469 Check_No_Identifiers;
9470 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9471 Check_Valid_Configuration_Pragma;
9472 Get_Name_String (Chars (Expression (Arg1)));
9473 DP := Fold_Upper (Name_Buffer (1));
9475 if Task_Dispatching_Policy /= ' '
9476 and then Task_Dispatching_Policy /= DP
9477 then
9478 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9479 Error_Pragma
9480 ("task dispatching policy incompatible with policy#");
9482 -- Set new policy, but always preserve System_Location since
9483 -- we like the error message with the run time name.
9485 else
9486 Task_Dispatching_Policy := DP;
9488 if Task_Dispatching_Policy_Sloc /= System_Location then
9489 Task_Dispatching_Policy_Sloc := Loc;
9490 end if;
9491 end if;
9492 end;
9494 --------------
9495 -- Task_Info --
9496 --------------
9498 -- pragma Task_Info (EXPRESSION);
9500 when Pragma_Task_Info => Task_Info : declare
9501 P : constant Node_Id := Parent (N);
9503 begin
9504 GNAT_Pragma;
9506 if Nkind (P) /= N_Task_Definition then
9507 Error_Pragma ("pragma% must appear in task definition");
9508 end if;
9510 Check_No_Identifiers;
9511 Check_Arg_Count (1);
9513 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
9515 if Etype (Expression (Arg1)) = Any_Type then
9516 return;
9517 end if;
9519 if Has_Task_Info_Pragma (P) then
9520 Error_Pragma ("duplicate pragma% not allowed");
9521 else
9522 Set_Has_Task_Info_Pragma (P, True);
9523 end if;
9524 end Task_Info;
9526 ---------------
9527 -- Task_Name --
9528 ---------------
9530 -- pragma Task_Name (string_EXPRESSION);
9532 when Pragma_Task_Name => Task_Name : declare
9533 -- pragma Priority (EXPRESSION);
9535 P : constant Node_Id := Parent (N);
9536 Arg : Node_Id;
9538 begin
9539 Check_No_Identifiers;
9540 Check_Arg_Count (1);
9542 Arg := Expression (Arg1);
9543 Analyze_And_Resolve (Arg, Standard_String);
9545 if Nkind (P) /= N_Task_Definition then
9546 Pragma_Misplaced;
9547 end if;
9549 if Has_Task_Name_Pragma (P) then
9550 Error_Pragma ("duplicate pragma% not allowed");
9551 else
9552 Set_Has_Task_Name_Pragma (P, True);
9553 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9554 end if;
9555 end Task_Name;
9557 ------------------
9558 -- Task_Storage --
9559 ------------------
9561 -- pragma Task_Storage (
9562 -- [Task_Type =>] LOCAL_NAME,
9563 -- [Top_Guard =>] static_integer_EXPRESSION);
9565 when Pragma_Task_Storage => Task_Storage : declare
9566 Args : Args_List (1 .. 2);
9567 Names : constant Name_List (1 .. 2) := (
9568 Name_Task_Type,
9569 Name_Top_Guard);
9571 Task_Type : Node_Id renames Args (1);
9572 Top_Guard : Node_Id renames Args (2);
9574 Ent : Entity_Id;
9576 begin
9577 GNAT_Pragma;
9578 Gather_Associations (Names, Args);
9580 if No (Task_Type) then
9581 Error_Pragma
9582 ("missing task_type argument for pragma%");
9583 end if;
9585 Check_Arg_Is_Local_Name (Task_Type);
9587 Ent := Entity (Task_Type);
9589 if not Is_Task_Type (Ent) then
9590 Error_Pragma_Arg
9591 ("argument for pragma% must be task type", Task_Type);
9592 end if;
9594 if No (Top_Guard) then
9595 Error_Pragma_Arg
9596 ("pragma% takes two arguments", Task_Type);
9597 else
9598 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
9599 end if;
9601 Check_First_Subtype (Task_Type);
9603 if Rep_Item_Too_Late (Ent, N) then
9604 raise Pragma_Exit;
9605 end if;
9606 end Task_Storage;
9608 -----------------
9609 -- Thread_Body --
9610 -----------------
9612 -- pragma Thread_Body
9613 -- ( [Entity =>] LOCAL_NAME
9614 -- [,[Secondary_Stack_Size =>] static_integer_EXPRESSION]);
9616 when Pragma_Thread_Body => Thread_Body : declare
9617 Id : Node_Id;
9618 SS : Node_Id;
9619 E : Entity_Id;
9621 begin
9622 GNAT_Pragma;
9623 Check_At_Least_N_Arguments (1);
9624 Check_At_Most_N_Arguments (2);
9625 Check_Optional_Identifier (Arg1, Name_Entity);
9626 Check_Arg_Is_Local_Name (Arg1);
9628 Id := Expression (Arg1);
9630 if not Is_Entity_Name (Id)
9631 or else not Is_Subprogram (Entity (Id))
9632 then
9633 Error_Pragma_Arg ("subprogram name required", Arg1);
9634 end if;
9636 E := Entity (Id);
9638 -- Go to renamed subprogram if present, since Thread_Body applies
9639 -- to the actual renamed entity, not to the renaming entity.
9641 if Present (Alias (E))
9642 and then Nkind (Parent (Declaration_Node (E))) =
9643 N_Subprogram_Renaming_Declaration
9644 then
9645 E := Alias (E);
9646 end if;
9648 -- Various error checks
9650 if Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body then
9651 Error_Pragma
9652 ("pragma% requires separate spec and must come before body");
9654 elsif Rep_Item_Too_Early (E, N)
9655 or else
9656 Rep_Item_Too_Late (E, N)
9657 then
9658 raise Pragma_Exit;
9660 elsif Is_Thread_Body (E) then
9661 Error_Pragma_Arg
9662 ("only one thread body pragma allowed", Arg1);
9664 elsif Present (Homonym (E))
9665 and then Scope (Homonym (E)) = Current_Scope
9666 then
9667 Error_Pragma_Arg
9668 ("thread body subprogram must not be overloaded", Arg1);
9669 end if;
9671 Set_Is_Thread_Body (E);
9673 -- Deal with secondary stack argument
9675 if Arg_Count = 2 then
9676 Check_Optional_Identifier (Arg2, Name_Secondary_Stack_Size);
9677 SS := Expression (Arg2);
9678 Analyze_And_Resolve (SS, Any_Integer);
9679 end if;
9680 end Thread_Body;
9682 ----------------
9683 -- Time_Slice --
9684 ----------------
9686 -- pragma Time_Slice (static_duration_EXPRESSION);
9688 when Pragma_Time_Slice => Time_Slice : declare
9689 Val : Ureal;
9690 Nod : Node_Id;
9692 begin
9693 GNAT_Pragma;
9694 Check_Arg_Count (1);
9695 Check_No_Identifiers;
9696 Check_In_Main_Program;
9697 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
9699 if not Error_Posted (Arg1) then
9700 Nod := Next (N);
9701 while Present (Nod) loop
9702 if Nkind (Nod) = N_Pragma
9703 and then Chars (Nod) = Name_Time_Slice
9704 then
9705 Error_Msg_Name_1 := Chars (N);
9706 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9707 end if;
9709 Next (Nod);
9710 end loop;
9711 end if;
9713 -- Process only if in main unit
9715 if Get_Source_Unit (Loc) = Main_Unit then
9716 Opt.Time_Slice_Set := True;
9717 Val := Expr_Value_R (Expression (Arg1));
9719 if Val <= Ureal_0 then
9720 Opt.Time_Slice_Value := 0;
9722 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
9723 Opt.Time_Slice_Value := 1_000_000_000;
9725 else
9726 Opt.Time_Slice_Value :=
9727 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
9728 end if;
9729 end if;
9730 end Time_Slice;
9732 -----------
9733 -- Title --
9734 -----------
9736 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
9738 -- TITLING_OPTION ::=
9739 -- [Title =>] STRING_LITERAL
9740 -- | [Subtitle =>] STRING_LITERAL
9742 when Pragma_Title => Title : declare
9743 Args : Args_List (1 .. 2);
9744 Names : constant Name_List (1 .. 2) := (
9745 Name_Title,
9746 Name_Subtitle);
9748 begin
9749 GNAT_Pragma;
9750 Gather_Associations (Names, Args);
9752 for J in 1 .. 2 loop
9753 if Present (Args (J)) then
9754 Check_Arg_Is_String_Literal (Args (J));
9755 end if;
9756 end loop;
9757 end Title;
9759 ---------------------
9760 -- Unchecked_Union --
9761 ---------------------
9763 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
9765 when Pragma_Unchecked_Union => Unchecked_Union : declare
9766 Assoc : constant Node_Id := Arg1;
9767 Type_Id : constant Node_Id := Expression (Assoc);
9768 Typ : Entity_Id;
9769 Discr : Entity_Id;
9770 Tdef : Node_Id;
9771 Clist : Node_Id;
9772 Vpart : Node_Id;
9773 Comp : Node_Id;
9774 Variant : Node_Id;
9776 begin
9777 GNAT_Pragma;
9778 Check_No_Identifiers;
9779 Check_Arg_Count (1);
9780 Check_Arg_Is_Local_Name (Arg1);
9782 Find_Type (Type_Id);
9783 Typ := Entity (Type_Id);
9785 if Typ = Any_Type
9786 or else Rep_Item_Too_Early (Typ, N)
9787 then
9788 return;
9789 else
9790 Typ := Underlying_Type (Typ);
9791 end if;
9793 if Rep_Item_Too_Late (Typ, N) then
9794 return;
9795 end if;
9797 Check_First_Subtype (Arg1);
9799 -- Note remaining cases are references to a type in the current
9800 -- declarative part. If we find an error, we post the error on
9801 -- the relevant type declaration at an appropriate point.
9803 if not Is_Record_Type (Typ) then
9804 Error_Msg_N ("Unchecked_Union must be record type", Typ);
9805 return;
9807 elsif Is_Tagged_Type (Typ) then
9808 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
9809 return;
9811 elsif Is_Limited_Type (Typ) then
9812 Error_Msg_N
9813 ("Unchecked_Union must not be limited record type", Typ);
9814 Explain_Limited_Type (Typ, Typ);
9815 return;
9817 else
9818 if not Has_Discriminants (Typ) then
9819 Error_Msg_N
9820 ("Unchecked_Union must have one discriminant", Typ);
9821 return;
9822 end if;
9824 Discr := First_Discriminant (Typ);
9826 if Present (Next_Discriminant (Discr)) then
9827 Error_Msg_N
9828 ("Unchecked_Union must have exactly one discriminant",
9829 Next_Discriminant (Discr));
9830 return;
9831 end if;
9833 if No (Discriminant_Default_Value (Discr)) then
9834 Error_Msg_N
9835 ("Unchecked_Union discriminant must have default value",
9836 Discr);
9837 end if;
9839 Tdef := Type_Definition (Declaration_Node (Typ));
9840 Clist := Component_List (Tdef);
9842 Comp := First (Component_Items (Clist));
9843 while Present (Comp) loop
9845 Check_Component (Comp);
9846 Next (Comp);
9848 end loop;
9850 if No (Clist) or else No (Variant_Part (Clist)) then
9851 Error_Msg_N
9852 ("Unchecked_Union must have variant part",
9853 Tdef);
9854 return;
9855 end if;
9857 Vpart := Variant_Part (Clist);
9859 Variant := First (Variants (Vpart));
9860 while Present (Variant) loop
9861 Check_Variant (Variant);
9862 Next (Variant);
9863 end loop;
9864 end if;
9866 Set_Is_Unchecked_Union (Typ, True);
9867 Set_Convention (Typ, Convention_C);
9869 Set_Has_Unchecked_Union (Base_Type (Typ), True);
9870 Set_Is_Unchecked_Union (Base_Type (Typ), True);
9871 end Unchecked_Union;
9873 ------------------------
9874 -- Unimplemented_Unit --
9875 ------------------------
9877 -- pragma Unimplemented_Unit;
9879 -- Note: this only gives an error if we are generating code,
9880 -- or if we are in a generic library unit (where the pragma
9881 -- appears in the body, not in the spec).
9883 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
9884 Cunitent : constant Entity_Id :=
9885 Cunit_Entity (Get_Source_Unit (Loc));
9886 Ent_Kind : constant Entity_Kind :=
9887 Ekind (Cunitent);
9889 begin
9890 GNAT_Pragma;
9891 Check_Arg_Count (0);
9893 if Operating_Mode = Generate_Code
9894 or else Ent_Kind = E_Generic_Function
9895 or else Ent_Kind = E_Generic_Procedure
9896 or else Ent_Kind = E_Generic_Package
9897 then
9898 Get_Name_String (Chars (Cunitent));
9899 Set_Casing (Mixed_Case);
9900 Write_Str (Name_Buffer (1 .. Name_Len));
9901 Write_Str (" is not implemented");
9902 Write_Eol;
9903 raise Unrecoverable_Error;
9904 end if;
9905 end Unimplemented_Unit;
9907 --------------------
9908 -- Universal_Data --
9909 --------------------
9911 -- pragma Universal_Data [(library_unit_NAME)];
9913 when Pragma_Universal_Data =>
9914 GNAT_Pragma;
9916 -- If this is a configuration pragma, then set the universal
9917 -- addressing option, otherwise confirm that the pragma
9918 -- satisfies the requirements of library unit pragma placement
9919 -- and leave it to the GNAAMP back end to detect the pragma
9920 -- (avoids transitive setting of the option due to withed units).
9922 if Is_Configuration_Pragma then
9923 Universal_Addressing_On_AAMP := True;
9924 else
9925 Check_Valid_Library_Unit_Pragma;
9926 end if;
9928 if not AAMP_On_Target then
9929 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
9930 end if;
9932 ------------------
9933 -- Unreferenced --
9934 ------------------
9936 -- pragma Unreferenced (local_Name {, local_Name});
9938 when Pragma_Unreferenced => Unreferenced : declare
9939 Arg_Node : Node_Id;
9940 Arg_Expr : Node_Id;
9941 Arg_Ent : Entity_Id;
9943 begin
9944 GNAT_Pragma;
9945 Check_At_Least_N_Arguments (1);
9947 Arg_Node := Arg1;
9948 while Present (Arg_Node) loop
9949 Check_No_Identifier (Arg_Node);
9951 -- Note that the analyze call done by Check_Arg_Is_Local_Name
9952 -- will in fact generate a reference, so that the entity will
9953 -- have a reference, which will inhibit any warnings about it
9954 -- not being referenced, and also properly show up in the ali
9955 -- file as a reference. But this reference is recorded before
9956 -- the Has_Pragma_Unreferenced flag is set, so that no warning
9957 -- is generated for this reference.
9959 Check_Arg_Is_Local_Name (Arg_Node);
9960 Arg_Expr := Get_Pragma_Arg (Arg_Node);
9962 if Is_Entity_Name (Arg_Expr) then
9963 Arg_Ent := Entity (Arg_Expr);
9965 -- If the entity is overloaded, the pragma applies to the
9966 -- most recent overloading, as documented. In this case,
9967 -- name resolution does not generate a reference, so it
9968 -- must be done here explicitly.
9970 if Is_Overloaded (Arg_Expr) then
9971 Generate_Reference (Arg_Ent, N);
9972 end if;
9974 Set_Has_Pragma_Unreferenced (Arg_Ent);
9975 end if;
9977 Next (Arg_Node);
9978 end loop;
9979 end Unreferenced;
9981 ------------------------------
9982 -- Unreserve_All_Interrupts --
9983 ------------------------------
9985 -- pragma Unreserve_All_Interrupts;
9987 when Pragma_Unreserve_All_Interrupts =>
9988 GNAT_Pragma;
9989 Check_Arg_Count (0);
9991 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
9992 Unreserve_All_Interrupts := True;
9993 end if;
9995 ----------------
9996 -- Unsuppress --
9997 ----------------
9999 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
10001 when Pragma_Unsuppress =>
10002 GNAT_Pragma;
10003 Process_Suppress_Unsuppress (False);
10005 -------------------
10006 -- Use_VADS_Size --
10007 -------------------
10009 -- pragma Use_VADS_Size;
10011 when Pragma_Use_VADS_Size =>
10012 GNAT_Pragma;
10013 Check_Arg_Count (0);
10014 Check_Valid_Configuration_Pragma;
10015 Use_VADS_Size := True;
10017 ---------------------
10018 -- Validity_Checks --
10019 ---------------------
10021 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
10023 when Pragma_Validity_Checks => Validity_Checks : declare
10024 A : constant Node_Id := Expression (Arg1);
10025 S : String_Id;
10026 C : Char_Code;
10028 begin
10029 GNAT_Pragma;
10030 Check_Arg_Count (1);
10031 Check_No_Identifiers;
10033 if Nkind (A) = N_String_Literal then
10034 S := Strval (A);
10036 declare
10037 Slen : constant Natural := Natural (String_Length (S));
10038 Options : String (1 .. Slen);
10039 J : Natural;
10041 begin
10042 J := 1;
10043 loop
10044 C := Get_String_Char (S, Int (J));
10045 exit when not In_Character_Range (C);
10046 Options (J) := Get_Character (C);
10048 if J = Slen then
10049 Set_Validity_Check_Options (Options);
10050 exit;
10051 else
10052 J := J + 1;
10053 end if;
10054 end loop;
10055 end;
10057 elsif Nkind (A) = N_Identifier then
10059 if Chars (A) = Name_All_Checks then
10060 Set_Validity_Check_Options ("a");
10062 elsif Chars (A) = Name_On then
10063 Validity_Checks_On := True;
10065 elsif Chars (A) = Name_Off then
10066 Validity_Checks_On := False;
10068 end if;
10069 end if;
10070 end Validity_Checks;
10072 --------------
10073 -- Volatile --
10074 --------------
10076 -- pragma Volatile (LOCAL_NAME);
10078 when Pragma_Volatile =>
10079 Process_Atomic_Shared_Volatile;
10081 -------------------------
10082 -- Volatile_Components --
10083 -------------------------
10085 -- pragma Volatile_Components (array_LOCAL_NAME);
10087 -- Volatile is handled by the same circuit as Atomic_Components
10089 --------------
10090 -- Warnings --
10091 --------------
10093 -- pragma Warnings (On | Off, [LOCAL_NAME])
10095 when Pragma_Warnings => Warnings : begin
10096 GNAT_Pragma;
10097 Check_At_Least_N_Arguments (1);
10098 Check_At_Most_N_Arguments (2);
10099 Check_No_Identifiers;
10101 -- One argument case was processed by parser in Par.Prag
10103 if Arg_Count /= 1 then
10104 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10105 Check_Arg_Count (2);
10107 declare
10108 E_Id : Node_Id;
10109 E : Entity_Id;
10111 begin
10112 E_Id := Expression (Arg2);
10113 Analyze (E_Id);
10115 -- In the expansion of an inlined body, a reference to
10116 -- the formal may be wrapped in a conversion if the actual
10117 -- is a conversion. Retrieve the real entity name.
10119 if (In_Instance_Body
10120 or else In_Inlined_Body)
10121 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
10122 then
10123 E_Id := Expression (E_Id);
10124 end if;
10126 if not Is_Entity_Name (E_Id) then
10127 Error_Pragma_Arg
10128 ("second argument of pragma% must be entity name",
10129 Arg2);
10130 end if;
10132 E := Entity (E_Id);
10134 if E = Any_Id then
10135 return;
10136 else
10137 loop
10138 Set_Warnings_Off (E,
10139 (Chars (Expression (Arg1)) = Name_Off));
10141 if Is_Enumeration_Type (E) then
10142 declare
10143 Lit : Entity_Id;
10144 begin
10145 Lit := First_Literal (E);
10146 while Present (Lit) loop
10147 Set_Warnings_Off (Lit);
10148 Next_Literal (Lit);
10149 end loop;
10150 end;
10151 end if;
10153 exit when No (Homonym (E));
10154 E := Homonym (E);
10155 end loop;
10156 end if;
10157 end;
10158 end if;
10159 end Warnings;
10161 -------------------
10162 -- Weak_External --
10163 -------------------
10165 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
10167 when Pragma_Weak_External => Weak_External : declare
10168 Ent : Entity_Id;
10170 begin
10171 GNAT_Pragma;
10172 Check_Arg_Count (1);
10173 Check_Optional_Identifier (Arg1, Name_Entity);
10174 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10175 Ent := Entity (Expression (Arg1));
10177 if Rep_Item_Too_Early (Ent, N) then
10178 return;
10179 else
10180 Ent := Underlying_Type (Ent);
10181 end if;
10183 -- The only processing required is to link this item on to the
10184 -- list of rep items for the given entity. This is accomplished
10185 -- by the call to Rep_Item_Too_Late (when no error is detected
10186 -- and False is returned).
10188 if Rep_Item_Too_Late (Ent, N) then
10189 return;
10190 else
10191 Set_Has_Gigi_Rep_Item (Ent);
10192 end if;
10193 end Weak_External;
10195 --------------------
10196 -- Unknown_Pragma --
10197 --------------------
10199 -- Should be impossible, since the case of an unknown pragma is
10200 -- separately processed before the case statement is entered.
10202 when Unknown_Pragma =>
10203 raise Program_Error;
10204 end case;
10206 exception
10207 when Pragma_Exit => null;
10208 end Analyze_Pragma;
10210 ---------------------------------
10211 -- Delay_Config_Pragma_Analyze --
10212 ---------------------------------
10214 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
10215 begin
10216 return Chars (N) = Name_Interrupt_State;
10217 end Delay_Config_Pragma_Analyze;
10219 -------------------------
10220 -- Get_Base_Subprogram --
10221 -------------------------
10223 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
10224 Result : Entity_Id;
10226 begin
10227 -- Follow subprogram renaming chain
10229 Result := Def_Id;
10230 while Is_Subprogram (Result)
10231 and then
10232 (Is_Generic_Instance (Result)
10233 or else Nkind (Parent (Declaration_Node (Result))) =
10234 N_Subprogram_Renaming_Declaration)
10235 and then Present (Alias (Result))
10236 loop
10237 Result := Alias (Result);
10238 end loop;
10240 return Result;
10241 end Get_Base_Subprogram;
10243 -----------------------------
10244 -- Is_Config_Static_String --
10245 -----------------------------
10247 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
10249 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
10250 -- This is an internal recursive function that is just like the
10251 -- outer function except that it adds the string to the name buffer
10252 -- rather than placing the string in the name buffer.
10254 ------------------------------
10255 -- Add_Config_Static_String --
10256 ------------------------------
10258 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
10259 N : Node_Id;
10260 C : Char_Code;
10262 begin
10263 N := Arg;
10265 if Nkind (N) = N_Op_Concat then
10266 if Add_Config_Static_String (Left_Opnd (N)) then
10267 N := Right_Opnd (N);
10268 else
10269 return False;
10270 end if;
10271 end if;
10273 if Nkind (N) /= N_String_Literal then
10274 Error_Msg_N ("string literal expected for pragma argument", N);
10275 return False;
10277 else
10278 for J in 1 .. String_Length (Strval (N)) loop
10279 C := Get_String_Char (Strval (N), J);
10281 if not In_Character_Range (C) then
10282 Error_Msg
10283 ("string literal contains invalid wide character",
10284 Sloc (N) + 1 + Source_Ptr (J));
10285 return False;
10286 end if;
10288 Add_Char_To_Name_Buffer (Get_Character (C));
10289 end loop;
10290 end if;
10292 return True;
10293 end Add_Config_Static_String;
10295 -- Start of prorcessing for Is_Config_Static_String
10297 begin
10299 Name_Len := 0;
10300 return Add_Config_Static_String (Arg);
10301 end Is_Config_Static_String;
10303 -----------------------------------------
10304 -- Is_Non_Significant_Pragma_Reference --
10305 -----------------------------------------
10307 -- This function makes use of the following static table which indicates
10308 -- whether a given pragma is significant. A value of -1 in this table
10309 -- indicates that the reference is significant. A value of zero indicates
10310 -- than appearence as any argument is insignificant, a positive value
10311 -- indicates that appearence in that parameter position is significant.
10313 Sig_Flags : constant array (Pragma_Id) of Int :=
10315 (Pragma_AST_Entry => -1,
10316 Pragma_Abort_Defer => -1,
10317 Pragma_Ada_83 => -1,
10318 Pragma_Ada_95 => -1,
10319 Pragma_Ada_05 => -1,
10320 Pragma_All_Calls_Remote => -1,
10321 Pragma_Annotate => -1,
10322 Pragma_Assert => -1,
10323 Pragma_Asynchronous => -1,
10324 Pragma_Atomic => 0,
10325 Pragma_Atomic_Components => 0,
10326 Pragma_Attach_Handler => -1,
10327 Pragma_CPP_Class => 0,
10328 Pragma_CPP_Constructor => 0,
10329 Pragma_CPP_Virtual => 0,
10330 Pragma_CPP_Vtable => 0,
10331 Pragma_C_Pass_By_Copy => 0,
10332 Pragma_Comment => 0,
10333 Pragma_Common_Object => -1,
10334 Pragma_Compile_Time_Warning => -1,
10335 Pragma_Complex_Representation => 0,
10336 Pragma_Component_Alignment => -1,
10337 Pragma_Controlled => 0,
10338 Pragma_Convention => 0,
10339 Pragma_Convention_Identifier => 0,
10340 Pragma_Debug => -1,
10341 Pragma_Detect_Blocking => -1,
10342 Pragma_Discard_Names => 0,
10343 Pragma_Elaborate => -1,
10344 Pragma_Elaborate_All => -1,
10345 Pragma_Elaborate_Body => -1,
10346 Pragma_Elaboration_Checks => -1,
10347 Pragma_Eliminate => -1,
10348 Pragma_Explicit_Overriding => -1,
10349 Pragma_Export => -1,
10350 Pragma_Export_Exception => -1,
10351 Pragma_Export_Function => -1,
10352 Pragma_Export_Object => -1,
10353 Pragma_Export_Procedure => -1,
10354 Pragma_Export_Value => -1,
10355 Pragma_Export_Valued_Procedure => -1,
10356 Pragma_Extend_System => -1,
10357 Pragma_Extensions_Allowed => -1,
10358 Pragma_External => -1,
10359 Pragma_External_Name_Casing => -1,
10360 Pragma_Finalize_Storage_Only => 0,
10361 Pragma_Float_Representation => 0,
10362 Pragma_Ident => -1,
10363 Pragma_Import => +2,
10364 Pragma_Import_Exception => 0,
10365 Pragma_Import_Function => 0,
10366 Pragma_Import_Object => 0,
10367 Pragma_Import_Procedure => 0,
10368 Pragma_Import_Valued_Procedure => 0,
10369 Pragma_Initialize_Scalars => -1,
10370 Pragma_Inline => 0,
10371 Pragma_Inline_Always => 0,
10372 Pragma_Inline_Generic => 0,
10373 Pragma_Inspection_Point => -1,
10374 Pragma_Interface => +2,
10375 Pragma_Interface_Name => +2,
10376 Pragma_Interrupt_Handler => -1,
10377 Pragma_Interrupt_Priority => -1,
10378 Pragma_Interrupt_State => -1,
10379 Pragma_Java_Constructor => -1,
10380 Pragma_Java_Interface => -1,
10381 Pragma_Keep_Names => 0,
10382 Pragma_License => -1,
10383 Pragma_Link_With => -1,
10384 Pragma_Linker_Alias => -1,
10385 Pragma_Linker_Options => -1,
10386 Pragma_Linker_Section => -1,
10387 Pragma_List => -1,
10388 Pragma_Locking_Policy => -1,
10389 Pragma_Long_Float => -1,
10390 Pragma_Machine_Attribute => -1,
10391 Pragma_Main => -1,
10392 Pragma_Main_Storage => -1,
10393 Pragma_Memory_Size => -1,
10394 Pragma_No_Return => 0,
10395 Pragma_No_Run_Time => -1,
10396 Pragma_No_Strict_Aliasing => -1,
10397 Pragma_Normalize_Scalars => -1,
10398 Pragma_Obsolescent => 0,
10399 Pragma_Optimize => -1,
10400 Pragma_Optional_Overriding => -1,
10401 Pragma_Pack => 0,
10402 Pragma_Page => -1,
10403 Pragma_Passive => -1,
10404 Pragma_Polling => -1,
10405 Pragma_Persistent_Data => -1,
10406 Pragma_Persistent_Object => -1,
10407 Pragma_Preelaborate => -1,
10408 Pragma_Priority => -1,
10409 Pragma_Profile => 0,
10410 Pragma_Profile_Warnings => 0,
10411 Pragma_Propagate_Exceptions => -1,
10412 Pragma_Psect_Object => -1,
10413 Pragma_Pure => 0,
10414 Pragma_Pure_Function => 0,
10415 Pragma_Queuing_Policy => -1,
10416 Pragma_Ravenscar => -1,
10417 Pragma_Remote_Call_Interface => -1,
10418 Pragma_Remote_Types => -1,
10419 Pragma_Restricted_Run_Time => -1,
10420 Pragma_Restriction_Warnings => -1,
10421 Pragma_Restrictions => -1,
10422 Pragma_Reviewable => -1,
10423 Pragma_Share_Generic => -1,
10424 Pragma_Shared => -1,
10425 Pragma_Shared_Passive => -1,
10426 Pragma_Source_File_Name => -1,
10427 Pragma_Source_File_Name_Project => -1,
10428 Pragma_Source_Reference => -1,
10429 Pragma_Storage_Size => -1,
10430 Pragma_Storage_Unit => -1,
10431 Pragma_Stream_Convert => -1,
10432 Pragma_Style_Checks => -1,
10433 Pragma_Subtitle => -1,
10434 Pragma_Suppress => 0,
10435 Pragma_Suppress_Exception_Locations => 0,
10436 Pragma_Suppress_All => -1,
10437 Pragma_Suppress_Debug_Info => 0,
10438 Pragma_Suppress_Initialization => 0,
10439 Pragma_System_Name => -1,
10440 Pragma_Task_Dispatching_Policy => -1,
10441 Pragma_Task_Info => -1,
10442 Pragma_Task_Name => -1,
10443 Pragma_Task_Storage => 0,
10444 Pragma_Thread_Body => +2,
10445 Pragma_Time_Slice => -1,
10446 Pragma_Title => -1,
10447 Pragma_Unchecked_Union => 0,
10448 Pragma_Unimplemented_Unit => -1,
10449 Pragma_Universal_Data => -1,
10450 Pragma_Unreferenced => -1,
10451 Pragma_Unreserve_All_Interrupts => -1,
10452 Pragma_Unsuppress => 0,
10453 Pragma_Use_VADS_Size => -1,
10454 Pragma_Validity_Checks => -1,
10455 Pragma_Volatile => 0,
10456 Pragma_Volatile_Components => 0,
10457 Pragma_Warnings => -1,
10458 Pragma_Weak_External => 0,
10459 Unknown_Pragma => 0);
10461 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
10462 P : Node_Id;
10463 C : Int;
10464 A : Node_Id;
10466 begin
10467 P := Parent (N);
10469 if Nkind (P) /= N_Pragma_Argument_Association then
10470 return False;
10472 else
10473 C := Sig_Flags (Get_Pragma_Id (Chars (Parent (P))));
10475 case C is
10476 when -1 =>
10477 return False;
10479 when 0 =>
10480 return True;
10482 when others =>
10483 A := First (Pragma_Argument_Associations (Parent (P)));
10484 for J in 1 .. C - 1 loop
10485 if No (A) then
10486 return False;
10487 end if;
10489 Next (A);
10490 end loop;
10492 return A = P;
10493 end case;
10494 end if;
10495 end Is_Non_Significant_Pragma_Reference;
10497 ------------------------------
10498 -- Is_Pragma_String_Literal --
10499 ------------------------------
10501 -- This function returns true if the corresponding pragma argument is
10502 -- a static string expression. These are the only cases in which string
10503 -- literals can appear as pragma arguments. We also allow a string
10504 -- literal as the first argument to pragma Assert (although it will
10505 -- of course always generate a type error).
10507 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
10508 Pragn : constant Node_Id := Parent (Par);
10509 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
10510 Pname : constant Name_Id := Chars (Pragn);
10511 Argn : Natural;
10512 N : Node_Id;
10514 begin
10515 Argn := 1;
10516 N := First (Assoc);
10517 loop
10518 exit when N = Par;
10519 Argn := Argn + 1;
10520 Next (N);
10521 end loop;
10523 if Pname = Name_Assert then
10524 return True;
10526 elsif Pname = Name_Export then
10527 return Argn > 2;
10529 elsif Pname = Name_Ident then
10530 return Argn = 1;
10532 elsif Pname = Name_Import then
10533 return Argn > 2;
10535 elsif Pname = Name_Interface_Name then
10536 return Argn > 1;
10538 elsif Pname = Name_Linker_Alias then
10539 return Argn = 2;
10541 elsif Pname = Name_Linker_Section then
10542 return Argn = 2;
10544 elsif Pname = Name_Machine_Attribute then
10545 return Argn = 2;
10547 elsif Pname = Name_Source_File_Name then
10548 return True;
10550 elsif Pname = Name_Source_Reference then
10551 return Argn = 2;
10553 elsif Pname = Name_Title then
10554 return True;
10556 elsif Pname = Name_Subtitle then
10557 return True;
10559 else
10560 return False;
10561 end if;
10562 end Is_Pragma_String_Literal;
10564 --------------------------------------
10565 -- Process_Compilation_Unit_Pragmas --
10566 --------------------------------------
10568 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
10569 begin
10570 -- A special check for pragma Suppress_All. This is a strange DEC
10571 -- pragma, strange because it comes at the end of the unit. If we
10572 -- have a pragma Suppress_All in the Pragmas_After of the current
10573 -- unit, then we insert a pragma Suppress (All_Checks) at the start
10574 -- of the context clause to ensure the correct processing.
10576 declare
10577 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
10578 P : Node_Id;
10580 begin
10581 if Present (PA) then
10582 P := First (PA);
10583 while Present (P) loop
10584 if Chars (P) = Name_Suppress_All then
10585 Prepend_To (Context_Items (N),
10586 Make_Pragma (Sloc (P),
10587 Chars => Name_Suppress,
10588 Pragma_Argument_Associations => New_List (
10589 Make_Pragma_Argument_Association (Sloc (P),
10590 Expression =>
10591 Make_Identifier (Sloc (P),
10592 Chars => Name_All_Checks)))));
10593 exit;
10594 end if;
10596 Next (P);
10597 end loop;
10598 end if;
10599 end;
10600 end Process_Compilation_Unit_Pragmas;
10602 --------------------------------
10603 -- Set_Encoded_Interface_Name --
10604 --------------------------------
10606 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
10607 Str : constant String_Id := Strval (S);
10608 Len : constant Int := String_Length (Str);
10609 CC : Char_Code;
10610 C : Character;
10611 J : Int;
10613 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
10615 procedure Encode;
10616 -- Stores encoded value of character code CC. The encoding we
10617 -- use an underscore followed by four lower case hex digits.
10619 ------------
10620 -- Encode --
10621 ------------
10623 procedure Encode is
10624 begin
10625 Store_String_Char (Get_Char_Code ('_'));
10626 Store_String_Char
10627 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
10628 Store_String_Char
10629 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
10630 Store_String_Char
10631 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
10632 Store_String_Char
10633 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
10634 end Encode;
10636 -- Start of processing for Set_Encoded_Interface_Name
10638 begin
10639 -- If first character is asterisk, this is a link name, and we
10640 -- leave it completely unmodified. We also ignore null strings
10641 -- (the latter case happens only in error cases) and no encoding
10642 -- should occur for Java interface names.
10644 if Len = 0
10645 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
10646 or else Java_VM
10647 then
10648 Set_Interface_Name (E, S);
10650 else
10651 J := 1;
10652 loop
10653 CC := Get_String_Char (Str, J);
10655 exit when not In_Character_Range (CC);
10657 C := Get_Character (CC);
10659 exit when C /= '_' and then C /= '$'
10660 and then C not in '0' .. '9'
10661 and then C not in 'a' .. 'z'
10662 and then C not in 'A' .. 'Z';
10664 if J = Len then
10665 Set_Interface_Name (E, S);
10666 return;
10668 else
10669 J := J + 1;
10670 end if;
10671 end loop;
10673 -- Here we need to encode. The encoding we use as follows:
10674 -- three underscores + four hex digits (lower case)
10676 Start_String;
10678 for J in 1 .. String_Length (Str) loop
10679 CC := Get_String_Char (Str, J);
10681 if not In_Character_Range (CC) then
10682 Encode;
10683 else
10684 C := Get_Character (CC);
10686 if C = '_' or else C = '$'
10687 or else C in '0' .. '9'
10688 or else C in 'a' .. 'z'
10689 or else C in 'A' .. 'Z'
10690 then
10691 Store_String_Char (CC);
10692 else
10693 Encode;
10694 end if;
10695 end if;
10696 end loop;
10698 Set_Interface_Name (E,
10699 Make_String_Literal (Sloc (S),
10700 Strval => End_String));
10701 end if;
10702 end Set_Encoded_Interface_Name;
10704 -------------------
10705 -- Set_Unit_Name --
10706 -------------------
10708 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
10709 Pref : Node_Id;
10710 Scop : Entity_Id;
10712 begin
10713 if Nkind (N) = N_Identifier
10714 and then Nkind (With_Item) = N_Identifier
10715 then
10716 Set_Entity (N, Entity (With_Item));
10718 elsif Nkind (N) = N_Selected_Component then
10719 Change_Selected_Component_To_Expanded_Name (N);
10720 Set_Entity (N, Entity (With_Item));
10721 Set_Entity (Selector_Name (N), Entity (N));
10723 Pref := Prefix (N);
10724 Scop := Scope (Entity (N));
10725 while Nkind (Pref) = N_Selected_Component loop
10726 Change_Selected_Component_To_Expanded_Name (Pref);
10727 Set_Entity (Selector_Name (Pref), Scop);
10728 Set_Entity (Pref, Scop);
10729 Pref := Prefix (Pref);
10730 Scop := Scope (Scop);
10731 end loop;
10733 Set_Entity (Pref, Scop);
10734 end if;
10735 end Set_Unit_Name;
10736 end Sem_Prag;