* arm.c (FL_WBUF): Define.
[official-gcc.git] / gcc / ada / sem_prag.adb
bloba65c9ca70022ad1f5cff16671b741de6447dfda8
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_Dist; use Sem_Dist;
59 with Sem_Elim; use Sem_Elim;
60 with Sem_Eval; use Sem_Eval;
61 with Sem_Intr; use Sem_Intr;
62 with Sem_Mech; use Sem_Mech;
63 with Sem_Res; use Sem_Res;
64 with Sem_Type; use Sem_Type;
65 with Sem_Util; use Sem_Util;
66 with Sem_VFpt; use Sem_VFpt;
67 with Stand; use Stand;
68 with Sinfo; use Sinfo;
69 with Sinfo.CN; use Sinfo.CN;
70 with Sinput; use Sinput;
71 with Snames; use Snames;
72 with Stringt; use Stringt;
73 with Stylesw; use Stylesw;
74 with Table;
75 with Targparm; use Targparm;
76 with Tbuild; use Tbuild;
77 with Ttypes;
78 with Uintp; use Uintp;
79 with Urealp; use Urealp;
80 with Validsw; use Validsw;
82 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
84 package body Sem_Prag is
86 ----------------------------------------------
87 -- Common Handling of Import-Export Pragmas --
88 ----------------------------------------------
90 -- In the following section, a number of Import_xxx and Export_xxx
91 -- pragmas are defined by GNAT. These are compatible with the DEC
92 -- pragmas of the same name, and all have the following common
93 -- form and processing:
95 -- pragma Export_xxx
96 -- [Internal =>] LOCAL_NAME,
97 -- [, [External =>] EXTERNAL_SYMBOL]
98 -- [, other optional parameters ]);
100 -- pragma Import_xxx
101 -- [Internal =>] LOCAL_NAME,
102 -- [, [External =>] EXTERNAL_SYMBOL]
103 -- [, other optional parameters ]);
105 -- EXTERNAL_SYMBOL ::=
106 -- IDENTIFIER
107 -- | static_string_EXPRESSION
109 -- The internal LOCAL_NAME designates the entity that is imported or
110 -- exported, and must refer to an entity in the current declarative
111 -- part (as required by the rules for LOCAL_NAME).
113 -- The external linker name is designated by the External parameter
114 -- if given, or the Internal parameter if not (if there is no External
115 -- parameter, the External parameter is a copy of the Internal name).
117 -- If the External parameter is given as a string, then this string
118 -- is treated as an external name (exactly as though it had been given
119 -- as an External_Name parameter for a normal Import pragma).
121 -- If the External parameter is given as an identifier (or there is no
122 -- External parameter, so that the Internal identifier is used), then
123 -- the external name is the characters of the identifier, translated
124 -- to all upper case letters for OpenVMS versions of GNAT, and to all
125 -- lower case letters for all other versions
127 -- Note: the external name specified or implied by any of these special
128 -- Import_xxx or Export_xxx pragmas override an external or link name
129 -- specified in a previous Import or Export pragma.
131 -- Note: these and all other DEC-compatible GNAT pragmas allow full
132 -- use of named notation, following the standard rules for subprogram
133 -- calls, i.e. parameters can be given in any order if named notation
134 -- is used, and positional and named notation can be mixed, subject to
135 -- the rule that all positional parameters must appear first.
137 -- Note: All these pragmas are implemented exactly following the DEC
138 -- design and implementation and are intended to be fully compatible
139 -- with the use of these pragmas in the DEC Ada compiler.
141 --------------------------------------------
142 -- Checking for Duplicated External Names --
143 --------------------------------------------
145 -- It is suspicious if two separate Export pragmas use the same external
146 -- name. The following table is used to diagnose this situation so that
147 -- an appropriate warning can be issued.
149 -- The Node_Id stored is for the N_String_Literal node created to
150 -- hold the value of the external name. The Sloc of this node is
151 -- used to cross-reference the location of the duplication.
153 package Externals is new Table.Table (
154 Table_Component_Type => Node_Id,
155 Table_Index_Type => Int,
156 Table_Low_Bound => 0,
157 Table_Initial => 100,
158 Table_Increment => 100,
159 Table_Name => "Name_Externals");
161 -------------------------------------
162 -- Local Subprograms and Variables --
163 -------------------------------------
165 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
166 -- This routine is used for possible casing adjustment of an explicit
167 -- external name supplied as a string literal (the node N), according
168 -- to the casing requirement of Opt.External_Name_Casing. If this is
169 -- set to As_Is, then the string literal is returned unchanged, but if
170 -- it is set to Uppercase or Lowercase, then a new string literal with
171 -- appropriate casing is constructed.
173 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
174 -- If Def_Id refers to a renamed subprogram, then the base subprogram
175 -- (the original one, following the renaming chain) is returned.
176 -- Otherwise the entity is returned unchanged. Should be in Einfo???
178 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
179 -- Place semantic information on the argument of an Elaborate or
180 -- Elaborate_All pragma. Entity name for unit and its parents is
181 -- taken from item in previous with_clause that mentions the unit.
183 -------------------------------
184 -- Adjust_External_Name_Case --
185 -------------------------------
187 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
188 CC : Char_Code;
190 begin
191 -- Adjust case of literal if required
193 if Opt.External_Name_Exp_Casing = As_Is then
194 return N;
196 else
197 -- Copy existing string
199 Start_String;
201 -- Set proper casing
203 for J in 1 .. String_Length (Strval (N)) loop
204 CC := Get_String_Char (Strval (N), J);
206 if Opt.External_Name_Exp_Casing = Uppercase
207 and then CC >= Get_Char_Code ('a')
208 and then CC <= Get_Char_Code ('z')
209 then
210 Store_String_Char (CC - 32);
212 elsif Opt.External_Name_Exp_Casing = Lowercase
213 and then CC >= Get_Char_Code ('A')
214 and then CC <= Get_Char_Code ('Z')
215 then
216 Store_String_Char (CC + 32);
218 else
219 Store_String_Char (CC);
220 end if;
221 end loop;
223 return
224 Make_String_Literal (Sloc (N),
225 Strval => End_String);
226 end if;
227 end Adjust_External_Name_Case;
229 --------------------
230 -- Analyze_Pragma --
231 --------------------
233 procedure Analyze_Pragma (N : Node_Id) is
234 Loc : constant Source_Ptr := Sloc (N);
235 Prag_Id : Pragma_Id;
237 Pragma_Exit : exception;
238 -- This exception is used to exit pragma processing completely. It
239 -- is used when an error is detected, and in other situations where
240 -- it is known that no further processing is required.
242 Arg_Count : Nat;
243 -- Number of pragma argument associations
245 Arg1 : Node_Id;
246 Arg2 : Node_Id;
247 Arg3 : Node_Id;
248 Arg4 : Node_Id;
249 -- First four pragma arguments (pragma argument association nodes,
250 -- or Empty if the corresponding argument does not exist).
252 procedure Check_Ada_83_Warning;
253 -- Issues a warning message for the current pragma if operating in Ada
254 -- 83 mode (used for language pragmas that are not a standard part of
255 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
256 -- of 95 pragma.
258 procedure Check_Arg_Count (Required : Nat);
259 -- Check argument count for pragma is equal to given parameter.
260 -- If not, then issue an error message and raise Pragma_Exit.
262 -- Note: all routines whose name is Check_Arg_Is_xxx take an
263 -- argument Arg which can either be a pragma argument association,
264 -- in which case the check is applied to the expression of the
265 -- association or an expression directly.
267 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
268 -- Check that an argument has the right form for an EXTERNAL_NAME
269 -- parameter of an extended import/export pragma. The rule is that
270 -- the name must be an identifier or string literal (in Ada 83 mode)
271 -- or a static string expression (in Ada 95 mode).
273 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
274 -- Check the specified argument Arg to make sure that it is an
275 -- identifier. If not give error and raise Pragma_Exit.
277 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
278 -- Check the specified argument Arg to make sure that it is an
279 -- integer literal. If not give error and raise Pragma_Exit.
281 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
282 -- Check the specified argument Arg to make sure that it has the
283 -- proper syntactic form for a local name and meets the semantic
284 -- requirements for a local name. The local name is analyzed as
285 -- part of the processing for this call. In addition, the local
286 -- name is required to represent an entity at the library level.
288 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
289 -- Check the specified argument Arg to make sure that it has the
290 -- proper syntactic form for a local name and meets the semantic
291 -- requirements for a local name. The local name is analyzed as
292 -- part of the processing for this call.
294 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
295 -- Check the specified argument Arg to make sure that it is a valid
296 -- locking policy name. If not give error and raise Pragma_Exit.
298 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
299 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
300 -- Check the specified argument Arg to make sure that it is an
301 -- identifier whose name matches either N1 or N2 (or N3 if present).
302 -- If not then give error and raise Pragma_Exit.
304 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
305 -- Check the specified argument Arg to make sure that it is a valid
306 -- queuing policy name. If not give error and raise Pragma_Exit.
308 procedure Check_Arg_Is_Static_Expression
309 (Arg : Node_Id;
310 Typ : Entity_Id);
311 -- Check the specified argument Arg to make sure that it is a static
312 -- expression of the given type (i.e. it will be analyzed and resolved
313 -- using this type, which can be any valid argument to Resolve, e.g.
314 -- Any_Integer is OK). If not, given error and raise Pragma_Exit.
316 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
317 -- Check the specified argument Arg to make sure that it is a
318 -- string literal. If not give error and raise Pragma_Exit
320 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
321 -- Check the specified argument Arg to make sure that it is a valid
322 -- valid task dispatching policy name. If not give error and raise
323 -- Pragma_Exit.
325 procedure Check_At_Least_N_Arguments (N : Nat);
326 -- Check there are at least N arguments present
328 procedure Check_At_Most_N_Arguments (N : Nat);
329 -- Check there are no more than N arguments present
331 procedure Check_Component (Comp : Node_Id);
332 -- Examine Unchecked_Union component for correct use of per-object
333 -- constrained subtypes.
335 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
336 -- Nam is an N_String_Literal node containing the external name set
337 -- by an Import or Export pragma (or extended Import or Export pragma).
338 -- This procedure checks for possible duplications if this is the
339 -- export case, and if found, issues an appropriate error message.
341 procedure Check_First_Subtype (Arg : Node_Id);
342 -- Checks that Arg, whose expression is an entity name referencing
343 -- a subtype, does not reference a type that is not a first subtype.
345 procedure Check_In_Main_Program;
346 -- Common checks for pragmas that appear within a main program
347 -- (Priority, Main_Storage, Time_Slice).
349 procedure Check_Interrupt_Or_Attach_Handler;
350 -- Common processing for first argument of pragma Interrupt_Handler
351 -- or pragma Attach_Handler.
353 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
354 -- Check that pragma appears in a declarative part, or in a package
355 -- specification, i.e. that it does not occur in a statement sequence
356 -- in a body.
358 procedure Check_No_Identifier (Arg : Node_Id);
359 -- Checks that the given argument does not have an identifier. If
360 -- an identifier is present, then an error message is issued, and
361 -- Pragma_Exit is raised.
363 procedure Check_No_Identifiers;
364 -- Checks that none of the arguments to the pragma has an identifier.
365 -- If any argument has an identifier, then an error message is issued,
366 -- and Pragma_Exit is raised.
368 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
369 -- Checks if the given argument has an identifier, and if so, requires
370 -- it to match the given identifier name. If there is a non-matching
371 -- identifier, then an error message is given and Error_Pragmas raised.
373 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
374 -- Checks if the given argument has an identifier, and if so, requires
375 -- it to match the given identifier name. If there is a non-matching
376 -- identifier, then an error message is given and Error_Pragmas raised.
377 -- In this version of the procedure, the identifier name is given as
378 -- a string with lower case letters.
380 procedure Check_Static_Constraint (Constr : Node_Id);
381 -- Constr is a constraint from an N_Subtype_Indication node from a
382 -- component constraint in an Unchecked_Union type. This routine checks
383 -- that the constraint is static as required by the restrictions for
384 -- Unchecked_Union.
386 procedure Check_Valid_Configuration_Pragma;
387 -- Legality checks for placement of a configuration pragma
389 procedure Check_Valid_Library_Unit_Pragma;
390 -- Legality checks for library unit pragmas. A special case arises for
391 -- pragmas in generic instances that come from copies of the original
392 -- library unit pragmas in the generic templates. In the case of other
393 -- than library level instantiations these can appear in contexts which
394 -- would normally be invalid (they only apply to the original template
395 -- and to library level instantiations), and they are simply ignored,
396 -- which is implemented by rewriting them as null statements.
398 procedure Check_Variant (Variant : Node_Id);
399 -- Check Unchecked_Union variant for lack of nested variants and
400 -- presence of at least one component.
402 procedure Error_Pragma (Msg : String);
403 pragma No_Return (Error_Pragma);
404 -- Outputs error message for current pragma. The message contains an %
405 -- that will be replaced with the pragma name, and the flag is placed
406 -- on the pragma itself. Pragma_Exit is then raised.
408 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
409 pragma No_Return (Error_Pragma_Arg);
410 -- Outputs error message for current pragma. The message may contain
411 -- a % that will be replaced with the pragma name. The parameter Arg
412 -- may either be a pragma argument association, in which case the flag
413 -- is placed on the expression of this association, or an expression,
414 -- in which case the flag is placed directly on the expression. The
415 -- message is placed using Error_Msg_N, so the message may also contain
416 -- an & insertion character which will reference the given Arg value.
417 -- After placing the message, Pragma_Exit is raised.
419 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
420 pragma No_Return (Error_Pragma_Arg);
421 -- Similar to above form of Error_Pragma_Arg except that two messages
422 -- are provided, the second is a continuation comment starting with \.
424 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
425 pragma No_Return (Error_Pragma_Arg_Ident);
426 -- Outputs error message for current pragma. The message may contain
427 -- a % that will be replaced with the pragma name. The parameter Arg
428 -- must be a pragma argument association with a non-empty identifier
429 -- (i.e. its Chars field must be set), and the error message is placed
430 -- on the identifier. The message is placed using Error_Msg_N so
431 -- the message may also contain an & insertion character which will
432 -- reference the identifier. After placing the message, Pragma_Exit
433 -- is raised.
435 function Find_Lib_Unit_Name return Entity_Id;
436 -- Used for a library unit pragma to find the entity to which the
437 -- library unit pragma applies, returns the entity found.
439 procedure Find_Program_Unit_Name (Id : Node_Id);
440 -- If the pragma is a compilation unit pragma, the id must denote the
441 -- compilation unit in the same compilation, and the pragma must appear
442 -- in the list of preceding or trailing pragmas. If it is a program
443 -- unit pragma that is not a compilation unit pragma, then the
444 -- identifier must be visible.
446 type Name_List is array (Natural range <>) of Name_Id;
447 type Args_List is array (Natural range <>) of Node_Id;
448 procedure Gather_Associations
449 (Names : Name_List;
450 Args : out Args_List);
451 -- This procedure is used to gather the arguments for a pragma that
452 -- permits arbitrary ordering of parameters using the normal rules
453 -- for named and positional parameters. The Names argument is a list
454 -- of Name_Id values that corresponds to the allowed pragma argument
455 -- association identifiers in order. The result returned in Args is
456 -- a list of corresponding expressions that are the pragma arguments.
457 -- Note that this is a list of expressions, not of pragma argument
458 -- associations (Gather_Associations has completely checked all the
459 -- optional identifiers when it returns). An entry in Args is Empty
460 -- on return if the corresponding argument is not present.
462 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
463 -- All the routines that check pragma arguments take either a pragma
464 -- argument association (in which case the expression of the argument
465 -- association is checked), or the expression directly. The function
466 -- Get_Pragma_Arg is a utility used to deal with these two cases. If
467 -- Arg is a pragma argument association node, then its expression is
468 -- returned, otherwise Arg is returned unchanged.
470 procedure GNAT_Pragma;
471 -- Called for all GNAT defined pragmas to note the use of the feature,
472 -- and also check the relevant restriction (No_Implementation_Pragmas).
474 function Is_Before_First_Decl
475 (Pragma_Node : Node_Id;
476 Decls : List_Id) return Boolean;
477 -- Return True if Pragma_Node is before the first declarative item in
478 -- Decls where Decls is the list of declarative items.
480 function Is_Configuration_Pragma return Boolean;
481 -- Deterermines if the placement of the current pragma is appropriate
482 -- for a configuration pragma (precedes the current compilation unit)
484 procedure Pragma_Misplaced;
485 -- Issue fatal error message for misplaced pragma
487 procedure Process_Atomic_Shared_Volatile;
488 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
489 -- Shared is an obsolete Ada 83 pragma, treated as being identical
490 -- in effect to pragma Atomic.
492 procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
493 -- Common procesing for Convention, Interface, Import and Export.
494 -- Checks first two arguments of pragma, and sets the appropriate
495 -- convention value in the specified entity or entities. On return
496 -- C is the convention, E is the referenced entity.
498 procedure Process_Extended_Import_Export_Exception_Pragma
499 (Arg_Internal : Node_Id;
500 Arg_External : Node_Id;
501 Arg_Form : Node_Id;
502 Arg_Code : Node_Id);
503 -- Common processing for the pragmas Import/Export_Exception.
504 -- The three arguments correspond to the three named parameters of
505 -- the pragma. An argument is empty if the corresponding parameter
506 -- is not present in the pragma.
508 procedure Process_Extended_Import_Export_Object_Pragma
509 (Arg_Internal : Node_Id;
510 Arg_External : Node_Id;
511 Arg_Size : Node_Id);
512 -- Common processing for the pragmass Import/Export_Object.
513 -- The three arguments correspond to the three named parameters
514 -- of the pragmas. An argument is empty if the corresponding
515 -- parameter is not present in the pragma.
517 procedure Process_Extended_Import_Export_Internal_Arg
518 (Arg_Internal : Node_Id := Empty);
519 -- Common processing for all extended Import and Export pragmas. The
520 -- argument is the pragma parameter for the Internal argument. If
521 -- Arg_Internal is empty or inappropriate, an error message is posted.
522 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
523 -- set to identify the referenced entity.
525 procedure Process_Extended_Import_Export_Subprogram_Pragma
526 (Arg_Internal : Node_Id;
527 Arg_External : Node_Id;
528 Arg_Parameter_Types : Node_Id;
529 Arg_Result_Type : Node_Id := Empty;
530 Arg_Mechanism : Node_Id;
531 Arg_Result_Mechanism : Node_Id := Empty;
532 Arg_First_Optional_Parameter : Node_Id := Empty);
533 -- Common processing for all extended Import and Export pragmas
534 -- applying to subprograms. The caller omits any arguments that do
535 -- bnot apply to the pragma in question (for example, Arg_Result_Type
536 -- can be non-Empty only in the Import_Function and Export_Function
537 -- cases). The argument names correspond to the allowed pragma
538 -- association identifiers.
540 procedure Process_Generic_List;
541 -- Common processing for Share_Generic and Inline_Generic
543 procedure Process_Import_Or_Interface;
544 -- Common processing for Import of Interface
546 procedure Process_Inline (Active : Boolean);
547 -- Common processing for Inline and Inline_Always. The parameter
548 -- indicates if the inline pragma is active, i.e. if it should
549 -- actually cause inlining to occur.
551 procedure Process_Interface_Name
552 (Subprogram_Def : Entity_Id;
553 Ext_Arg : Node_Id;
554 Link_Arg : Node_Id);
555 -- Given the last two arguments of pragma Import, pragma Export, or
556 -- pragma Interface_Name, performs validity checks and sets the
557 -- Interface_Name field of the given subprogram entity to the
558 -- appropriate external or link name, depending on the arguments
559 -- given. Ext_Arg is always present, but Link_Arg may be missing.
560 -- Note that Ext_Arg may represent the Link_Name if Link_Arg is
561 -- missing, and appropriate named notation is used for Ext_Arg.
562 -- If neither Ext_Arg nor Link_Arg is present, the interface name
563 -- is set to the default from the subprogram name.
565 procedure Process_Interrupt_Or_Attach_Handler;
566 -- Common processing for Interrupt and Attach_Handler pragmas
568 procedure Process_Restrictions_Or_Restriction_Warnings;
569 -- Common processing for Restrictions and Restriction_Warnings pragmas
571 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
572 -- Common processing for Suppress and Unsuppress. The boolean parameter
573 -- Suppress_Case is True for the Suppress case, and False for the
574 -- Unsuppress case.
576 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
577 -- This procedure sets the Is_Exported flag for the given entity,
578 -- checking that the entity was not previously imported. Arg is
579 -- the argument that specified the entity. A check is also made
580 -- for exporting inappropriate entities.
582 procedure Set_Extended_Import_Export_External_Name
583 (Internal_Ent : Entity_Id;
584 Arg_External : Node_Id);
585 -- Common processing for all extended import export pragmas. The first
586 -- argument, Internal_Ent, is the internal entity, which has already
587 -- been checked for validity by the caller. Arg_External is from the
588 -- Import or Export pragma, and may be null if no External parameter
589 -- was present. If Arg_External is present and is a non-null string
590 -- (a null string is treated as the default), then the Interface_Name
591 -- field of Internal_Ent is set appropriately.
593 procedure Set_Imported (E : Entity_Id);
594 -- This procedure sets the Is_Imported flag for the given entity,
595 -- checking that it is not previously exported or imported.
597 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
598 -- Mech is a parameter passing mechanism (see Import_Function syntax
599 -- for MECHANISM_NAME). This routine checks that the mechanism argument
600 -- has the right form, and if not issues an error message. If the
601 -- argument has the right form then the Mechanism field of Ent is
602 -- set appropriately.
604 procedure Set_Ravenscar_Profile (N : Node_Id);
605 -- Activate the set of configuration pragmas and restrictions that
606 -- make up the Ravenscar Profile. N is the corresponding pragma
607 -- node, which is used for error messages on any constructs
608 -- that violate the profile.
610 --------------------------
611 -- Check_Ada_83_Warning --
612 --------------------------
614 procedure Check_Ada_83_Warning is
615 begin
616 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
617 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
618 end if;
619 end Check_Ada_83_Warning;
621 ---------------------
622 -- Check_Arg_Count --
623 ---------------------
625 procedure Check_Arg_Count (Required : Nat) is
626 begin
627 if Arg_Count /= Required then
628 Error_Pragma ("wrong number of arguments for pragma%");
629 end if;
630 end Check_Arg_Count;
632 --------------------------------
633 -- Check_Arg_Is_External_Name --
634 --------------------------------
636 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
637 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
639 begin
640 if Nkind (Argx) = N_Identifier then
641 return;
643 else
644 Analyze_And_Resolve (Argx, Standard_String);
646 if Is_OK_Static_Expression (Argx) then
647 return;
649 elsif Etype (Argx) = Any_Type then
650 raise Pragma_Exit;
652 -- An interesting special case, if we have a string literal and
653 -- we are in Ada 83 mode, then we allow it even though it will
654 -- not be flagged as static. This allows expected Ada 83 mode
655 -- use of external names which are string literals, even though
656 -- technically these are not static in Ada 83.
658 elsif Ada_Version = Ada_83
659 and then Nkind (Argx) = N_String_Literal
660 then
661 return;
663 -- Static expression that raises Constraint_Error. This has
664 -- already been flagged, so just exit from pragma processing.
666 elsif Is_Static_Expression (Argx) then
667 raise Pragma_Exit;
669 -- Here we have a real error (non-static expression)
671 else
672 Error_Msg_Name_1 := Chars (N);
673 Flag_Non_Static_Expr
674 ("argument for pragma% must be a identifier or " &
675 "static string expression!", Argx);
676 raise Pragma_Exit;
677 end if;
678 end if;
679 end Check_Arg_Is_External_Name;
681 -----------------------------
682 -- Check_Arg_Is_Identifier --
683 -----------------------------
685 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
686 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
687 begin
688 if Nkind (Argx) /= N_Identifier then
689 Error_Pragma_Arg
690 ("argument for pragma% must be identifier", Argx);
691 end if;
692 end Check_Arg_Is_Identifier;
694 ----------------------------------
695 -- Check_Arg_Is_Integer_Literal --
696 ----------------------------------
698 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
699 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
700 begin
701 if Nkind (Argx) /= N_Integer_Literal then
702 Error_Pragma_Arg
703 ("argument for pragma% must be integer literal", Argx);
704 end if;
705 end Check_Arg_Is_Integer_Literal;
707 -------------------------------------------
708 -- Check_Arg_Is_Library_Level_Local_Name --
709 -------------------------------------------
711 -- LOCAL_NAME ::=
712 -- DIRECT_NAME
713 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
714 -- | library_unit_NAME
716 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
717 begin
718 Check_Arg_Is_Local_Name (Arg);
720 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
721 and then Comes_From_Source (N)
722 then
723 Error_Pragma_Arg
724 ("argument for pragma% must be library level entity", Arg);
725 end if;
726 end Check_Arg_Is_Library_Level_Local_Name;
728 -----------------------------
729 -- Check_Arg_Is_Local_Name --
730 -----------------------------
732 -- LOCAL_NAME ::=
733 -- DIRECT_NAME
734 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
735 -- | library_unit_NAME
737 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
738 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
740 begin
741 Analyze (Argx);
743 if Nkind (Argx) not in N_Direct_Name
744 and then (Nkind (Argx) /= N_Attribute_Reference
745 or else Present (Expressions (Argx))
746 or else Nkind (Prefix (Argx)) /= N_Identifier)
747 and then (not Is_Entity_Name (Argx)
748 or else not Is_Compilation_Unit (Entity (Argx)))
749 then
750 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
751 end if;
753 if Is_Entity_Name (Argx)
754 and then Scope (Entity (Argx)) /= Current_Scope
755 then
756 Error_Pragma_Arg
757 ("pragma% argument must be in same declarative part", Arg);
758 end if;
759 end Check_Arg_Is_Local_Name;
761 ---------------------------------
762 -- Check_Arg_Is_Locking_Policy --
763 ---------------------------------
765 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
766 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
768 begin
769 Check_Arg_Is_Identifier (Argx);
771 if not Is_Locking_Policy_Name (Chars (Argx)) then
772 Error_Pragma_Arg
773 ("& is not a valid locking policy name", Argx);
774 end if;
775 end Check_Arg_Is_Locking_Policy;
777 -------------------------
778 -- Check_Arg_Is_One_Of --
779 -------------------------
781 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
782 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
784 begin
785 Check_Arg_Is_Identifier (Argx);
787 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
788 Error_Msg_Name_2 := N1;
789 Error_Msg_Name_3 := N2;
790 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
791 end if;
792 end Check_Arg_Is_One_Of;
794 procedure Check_Arg_Is_One_Of
795 (Arg : Node_Id;
796 N1, N2, N3 : Name_Id)
798 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
800 begin
801 Check_Arg_Is_Identifier (Argx);
803 if Chars (Argx) /= N1
804 and then Chars (Argx) /= N2
805 and then Chars (Argx) /= N3
806 then
807 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
808 end if;
809 end Check_Arg_Is_One_Of;
811 ---------------------------------
812 -- Check_Arg_Is_Queuing_Policy --
813 ---------------------------------
815 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
816 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
818 begin
819 Check_Arg_Is_Identifier (Argx);
821 if not Is_Queuing_Policy_Name (Chars (Argx)) then
822 Error_Pragma_Arg
823 ("& is not a valid queuing policy name", Argx);
824 end if;
825 end Check_Arg_Is_Queuing_Policy;
827 ------------------------------------
828 -- Check_Arg_Is_Static_Expression --
829 ------------------------------------
831 procedure Check_Arg_Is_Static_Expression
832 (Arg : Node_Id;
833 Typ : Entity_Id)
835 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
837 begin
838 Analyze_And_Resolve (Argx, Typ);
840 if Is_OK_Static_Expression (Argx) then
841 return;
843 elsif Etype (Argx) = Any_Type then
844 raise Pragma_Exit;
846 -- An interesting special case, if we have a string literal and
847 -- we are in Ada 83 mode, then we allow it even though it will
848 -- not be flagged as static. This allows the use of Ada 95
849 -- pragmas like Import in Ada 83 mode. They will of course be
850 -- flagged with warnings as usual, but will not cause errors.
852 elsif Ada_Version = Ada_83
853 and then Nkind (Argx) = N_String_Literal
854 then
855 return;
857 -- Static expression that raises Constraint_Error. This has
858 -- already been flagged, so just exit from pragma processing.
860 elsif Is_Static_Expression (Argx) then
861 raise Pragma_Exit;
863 -- Finally, we have a real error
865 else
866 Error_Msg_Name_1 := Chars (N);
867 Flag_Non_Static_Expr
868 ("argument for pragma% must be a static expression!", Argx);
869 raise Pragma_Exit;
870 end if;
871 end Check_Arg_Is_Static_Expression;
873 ---------------------------------
874 -- Check_Arg_Is_String_Literal --
875 ---------------------------------
877 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
878 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
879 begin
880 if Nkind (Argx) /= N_String_Literal then
881 Error_Pragma_Arg
882 ("argument for pragma% must be string literal", Argx);
883 end if;
884 end Check_Arg_Is_String_Literal;
886 ------------------------------------------
887 -- Check_Arg_Is_Task_Dispatching_Policy --
888 ------------------------------------------
890 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
891 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
893 begin
894 Check_Arg_Is_Identifier (Argx);
896 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
897 Error_Pragma_Arg
898 ("& is not a valid task dispatching policy name", Argx);
899 end if;
900 end Check_Arg_Is_Task_Dispatching_Policy;
902 --------------------------------
903 -- Check_At_Least_N_Arguments --
904 --------------------------------
906 procedure Check_At_Least_N_Arguments (N : Nat) is
907 begin
908 if Arg_Count < N then
909 Error_Pragma ("too few arguments for pragma%");
910 end if;
911 end Check_At_Least_N_Arguments;
913 -------------------------------
914 -- Check_At_Most_N_Arguments --
915 -------------------------------
917 procedure Check_At_Most_N_Arguments (N : Nat) is
918 Arg : Node_Id;
919 begin
920 if Arg_Count > N then
921 Arg := Arg1;
922 for J in 1 .. N loop
923 Next (Arg);
924 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
925 end loop;
926 end if;
927 end Check_At_Most_N_Arguments;
929 ---------------------
930 -- Check_Component --
931 ---------------------
933 procedure Check_Component (Comp : Node_Id) is
934 begin
935 if Nkind (Comp) = N_Component_Declaration then
936 declare
937 Sindic : constant Node_Id :=
938 Subtype_Indication (Component_Definition (Comp));
940 begin
941 if Nkind (Sindic) = N_Subtype_Indication then
943 -- Ada 2005 (AI-216): If a component subtype is subject to
944 -- a per-object constraint, then the component type shall
945 -- be an Unchecked_Union.
947 if Has_Per_Object_Constraint (Defining_Identifier (Comp))
948 and then
949 not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
950 then
951 Error_Msg_N ("component subtype subject to per-object" &
952 " constraint must be an Unchecked_Union", Comp);
953 end if;
954 end if;
955 end;
956 end if;
957 end Check_Component;
959 ----------------------------------
960 -- Check_Duplicated_Export_Name --
961 ----------------------------------
963 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
964 String_Val : constant String_Id := Strval (Nam);
966 begin
967 -- We are only interested in the export case, and in the case of
968 -- generics, it is the instance, not the template, that is the
969 -- problem (the template will generate a warning in any case).
971 if not Inside_A_Generic
972 and then (Prag_Id = Pragma_Export
973 or else
974 Prag_Id = Pragma_Export_Procedure
975 or else
976 Prag_Id = Pragma_Export_Valued_Procedure
977 or else
978 Prag_Id = Pragma_Export_Function)
979 then
980 for J in Externals.First .. Externals.Last loop
981 if String_Equal (String_Val, Strval (Externals.Table (J))) then
982 Error_Msg_Sloc := Sloc (Externals.Table (J));
983 Error_Msg_N ("external name duplicates name given#", Nam);
984 exit;
985 end if;
986 end loop;
988 Externals.Append (Nam);
989 end if;
990 end Check_Duplicated_Export_Name;
992 -------------------------
993 -- Check_First_Subtype --
994 -------------------------
996 procedure Check_First_Subtype (Arg : Node_Id) is
997 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
998 begin
999 if not Is_First_Subtype (Entity (Argx)) then
1000 Error_Pragma_Arg
1001 ("pragma% cannot apply to subtype", Argx);
1002 end if;
1003 end Check_First_Subtype;
1005 ---------------------------
1006 -- Check_In_Main_Program --
1007 ---------------------------
1009 procedure Check_In_Main_Program is
1010 P : constant Node_Id := Parent (N);
1012 begin
1013 -- Must be at in subprogram body
1015 if Nkind (P) /= N_Subprogram_Body then
1016 Error_Pragma ("% pragma allowed only in subprogram");
1018 -- Otherwise warn if obviously not main program
1020 elsif Present (Parameter_Specifications (Specification (P)))
1021 or else not Is_Compilation_Unit (Defining_Entity (P))
1022 then
1023 Error_Msg_Name_1 := Chars (N);
1024 Error_Msg_N
1025 ("?pragma% is only effective in main program", N);
1026 end if;
1027 end Check_In_Main_Program;
1029 ---------------------------------------
1030 -- Check_Interrupt_Or_Attach_Handler --
1031 ---------------------------------------
1033 procedure Check_Interrupt_Or_Attach_Handler is
1034 Arg1_X : constant Node_Id := Expression (Arg1);
1036 begin
1037 Analyze (Arg1_X);
1039 if not Is_Entity_Name (Arg1_X) then
1040 Error_Pragma_Arg
1041 ("argument of pragma% must be entity name", Arg1);
1043 elsif Prag_Id = Pragma_Interrupt_Handler then
1044 Check_Restriction (No_Dynamic_Attachment, N);
1045 end if;
1047 declare
1048 Handler_Proc : Entity_Id := Empty;
1049 Proc_Scope : Entity_Id;
1050 Found : Boolean := False;
1052 begin
1053 if not Is_Overloaded (Arg1_X) then
1054 Handler_Proc := Entity (Arg1_X);
1056 else
1057 declare
1058 It : Interp;
1059 Index : Interp_Index;
1061 begin
1062 Get_First_Interp (Arg1_X, Index, It);
1063 while Present (It.Nam) loop
1064 Handler_Proc := It.Nam;
1066 if Ekind (Handler_Proc) = E_Procedure
1067 and then No (First_Formal (Handler_Proc))
1068 then
1069 if not Found then
1070 Found := True;
1071 Set_Entity (Arg1_X, Handler_Proc);
1072 Set_Is_Overloaded (Arg1_X, False);
1073 else
1074 Error_Pragma_Arg
1075 ("ambiguous handler name for pragma% ", Arg1);
1076 end if;
1077 end if;
1079 Get_Next_Interp (Index, It);
1080 end loop;
1082 if not Found then
1083 Error_Pragma_Arg
1084 ("argument of pragma% must be parameterless procedure",
1085 Arg1);
1086 else
1087 Handler_Proc := Entity (Arg1_X);
1088 end if;
1089 end;
1090 end if;
1092 Proc_Scope := Scope (Handler_Proc);
1094 -- On AAMP only, a pragma Interrupt_Handler is supported for
1095 -- nonprotected parameterless procedures.
1097 if AAMP_On_Target
1098 and then Prag_Id = Pragma_Interrupt_Handler
1099 then
1100 if Ekind (Handler_Proc) /= E_Procedure then
1101 Error_Pragma_Arg
1102 ("argument of pragma% must be a procedure", Arg1);
1103 end if;
1105 elsif Ekind (Handler_Proc) /= E_Procedure
1106 or else Ekind (Proc_Scope) /= E_Protected_Type
1107 then
1108 Error_Pragma_Arg
1109 ("argument of pragma% must be protected procedure", Arg1);
1110 end if;
1112 if (not AAMP_On_Target or else Prag_Id = Pragma_Attach_Handler)
1113 and then Ekind (Proc_Scope) = E_Protected_Type
1114 then
1115 if Parent (N) /=
1116 Protected_Definition (Parent (Proc_Scope))
1117 then
1118 Error_Pragma ("pragma% must be in protected definition");
1119 end if;
1120 end if;
1122 if not Is_Library_Level_Entity (Proc_Scope)
1123 or else (AAMP_On_Target
1124 and then not Is_Library_Level_Entity (Handler_Proc))
1125 then
1126 Error_Pragma_Arg
1127 ("pragma% requires library-level entity", Arg1);
1128 end if;
1130 if Present (First_Formal (Handler_Proc)) then
1131 Error_Pragma_Arg
1132 ("argument of pragma% must be parameterless procedure",
1133 Arg1);
1134 end if;
1135 end;
1136 end Check_Interrupt_Or_Attach_Handler;
1138 -------------------------------------------
1139 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1140 -------------------------------------------
1142 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1143 P : Node_Id;
1145 begin
1146 P := Parent (N);
1147 loop
1148 if No (P) then
1149 exit;
1151 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1152 exit;
1154 elsif Nkind (P) = N_Package_Specification then
1155 return;
1157 elsif Nkind (P) = N_Block_Statement then
1158 return;
1160 -- Note: the following tests seem a little peculiar, because
1161 -- they test for bodies, but if we were in the statement part
1162 -- of the body, we would already have hit the handled statement
1163 -- sequence, so the only way we get here is by being in the
1164 -- declarative part of the body.
1166 elsif Nkind (P) = N_Subprogram_Body
1167 or else Nkind (P) = N_Package_Body
1168 or else Nkind (P) = N_Task_Body
1169 or else Nkind (P) = N_Entry_Body
1170 then
1171 return;
1172 end if;
1174 P := Parent (P);
1175 end loop;
1177 Error_Pragma ("pragma% is not in declarative part or package spec");
1178 end Check_Is_In_Decl_Part_Or_Package_Spec;
1180 -------------------------
1181 -- Check_No_Identifier --
1182 -------------------------
1184 procedure Check_No_Identifier (Arg : Node_Id) is
1185 begin
1186 if Chars (Arg) /= No_Name then
1187 Error_Pragma_Arg_Ident
1188 ("pragma% does not permit identifier& here", Arg);
1189 end if;
1190 end Check_No_Identifier;
1192 --------------------------
1193 -- Check_No_Identifiers --
1194 --------------------------
1196 procedure Check_No_Identifiers is
1197 Arg_Node : Node_Id;
1198 begin
1199 if Arg_Count > 0 then
1200 Arg_Node := Arg1;
1201 while Present (Arg_Node) loop
1202 Check_No_Identifier (Arg_Node);
1203 Next (Arg_Node);
1204 end loop;
1205 end if;
1206 end Check_No_Identifiers;
1208 -------------------------------
1209 -- Check_Optional_Identifier --
1210 -------------------------------
1212 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1213 begin
1214 if Present (Arg) and then Chars (Arg) /= No_Name then
1215 if Chars (Arg) /= Id then
1216 Error_Msg_Name_1 := Chars (N);
1217 Error_Msg_Name_2 := Id;
1218 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1219 raise Pragma_Exit;
1220 end if;
1221 end if;
1222 end Check_Optional_Identifier;
1224 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1225 begin
1226 Name_Buffer (1 .. Id'Length) := Id;
1227 Name_Len := Id'Length;
1228 Check_Optional_Identifier (Arg, Name_Find);
1229 end Check_Optional_Identifier;
1231 -----------------------------
1232 -- Check_Static_Constraint --
1233 -----------------------------
1235 -- Note: for convenience in writing this procedure, in addition to
1236 -- the officially (i.e. by spec) allowed argument which is always
1237 -- a constraint, it also allows ranges and discriminant associations.
1238 -- Above is not clear ???
1240 procedure Check_Static_Constraint (Constr : Node_Id) is
1242 --------------------
1243 -- Require_Static --
1244 --------------------
1246 procedure Require_Static (E : Node_Id);
1247 -- Require given expression to be static expression
1249 procedure Require_Static (E : Node_Id) is
1250 begin
1251 if not Is_OK_Static_Expression (E) then
1252 Flag_Non_Static_Expr
1253 ("non-static constraint not allowed in Unchecked_Union!", E);
1254 raise Pragma_Exit;
1255 end if;
1256 end Require_Static;
1258 -- Start of processing for Check_Static_Constraint
1260 begin
1261 case Nkind (Constr) is
1262 when N_Discriminant_Association =>
1263 Require_Static (Expression (Constr));
1265 when N_Range =>
1266 Require_Static (Low_Bound (Constr));
1267 Require_Static (High_Bound (Constr));
1269 when N_Attribute_Reference =>
1270 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1271 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1273 when N_Range_Constraint =>
1274 Check_Static_Constraint (Range_Expression (Constr));
1276 when N_Index_Or_Discriminant_Constraint =>
1277 declare
1278 IDC : Entity_Id;
1279 begin
1280 IDC := First (Constraints (Constr));
1281 while Present (IDC) loop
1282 Check_Static_Constraint (IDC);
1283 Next (IDC);
1284 end loop;
1285 end;
1287 when others =>
1288 null;
1289 end case;
1290 end Check_Static_Constraint;
1292 --------------------------------------
1293 -- Check_Valid_Configuration_Pragma --
1294 --------------------------------------
1296 -- A configuration pragma must appear in the context clause of
1297 -- a compilation unit, at the start of the list (i.e. only other
1298 -- pragmas may precede it).
1300 procedure Check_Valid_Configuration_Pragma is
1301 begin
1302 if not Is_Configuration_Pragma then
1303 Error_Pragma ("incorrect placement for configuration pragma%");
1304 end if;
1305 end Check_Valid_Configuration_Pragma;
1307 -------------------------------------
1308 -- Check_Valid_Library_Unit_Pragma --
1309 -------------------------------------
1311 procedure Check_Valid_Library_Unit_Pragma is
1312 Plist : List_Id;
1313 Parent_Node : Node_Id;
1314 Unit_Name : Entity_Id;
1315 Unit_Kind : Node_Kind;
1316 Unit_Node : Node_Id;
1317 Sindex : Source_File_Index;
1319 begin
1320 if not Is_List_Member (N) then
1321 Pragma_Misplaced;
1323 else
1324 Plist := List_Containing (N);
1325 Parent_Node := Parent (Plist);
1327 if Parent_Node = Empty then
1328 Pragma_Misplaced;
1330 -- Case of pragma appearing after a compilation unit. In this
1331 -- case it must have an argument with the corresponding name
1332 -- and must be part of the following pragmas of its parent.
1334 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1335 if Plist /= Pragmas_After (Parent_Node) then
1336 Pragma_Misplaced;
1338 elsif Arg_Count = 0 then
1339 Error_Pragma
1340 ("argument required if outside compilation unit");
1342 else
1343 Check_No_Identifiers;
1344 Check_Arg_Count (1);
1345 Unit_Node := Unit (Parent (Parent_Node));
1346 Unit_Kind := Nkind (Unit_Node);
1348 Analyze (Expression (Arg1));
1350 if Unit_Kind = N_Generic_Subprogram_Declaration
1351 or else Unit_Kind = N_Subprogram_Declaration
1352 then
1353 Unit_Name := Defining_Entity (Unit_Node);
1355 elsif Unit_Kind = N_Function_Instantiation
1356 or else Unit_Kind = N_Package_Instantiation
1357 or else Unit_Kind = N_Procedure_Instantiation
1358 then
1359 Unit_Name := Defining_Entity (Unit_Node);
1361 else
1362 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1363 end if;
1365 if Chars (Unit_Name) /=
1366 Chars (Entity (Expression (Arg1)))
1367 then
1368 Error_Pragma_Arg
1369 ("pragma% argument is not current unit name", Arg1);
1370 end if;
1372 if Ekind (Unit_Name) = E_Package
1373 and then Present (Renamed_Entity (Unit_Name))
1374 then
1375 Error_Pragma ("pragma% not allowed for renamed package");
1376 end if;
1377 end if;
1379 -- Pragma appears other than after a compilation unit
1381 else
1382 -- Here we check for the generic instantiation case and also
1383 -- for the case of processing a generic formal package. We
1384 -- detect these cases by noting that the Sloc on the node
1385 -- does not belong to the current compilation unit.
1387 Sindex := Source_Index (Current_Sem_Unit);
1389 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1390 Rewrite (N, Make_Null_Statement (Loc));
1391 return;
1393 -- If before first declaration, the pragma applies to the
1394 -- enclosing unit, and the name if present must be this name.
1396 elsif Is_Before_First_Decl (N, Plist) then
1397 Unit_Node := Unit_Declaration_Node (Current_Scope);
1398 Unit_Kind := Nkind (Unit_Node);
1400 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1401 Pragma_Misplaced;
1403 elsif Unit_Kind = N_Subprogram_Body
1404 and then not Acts_As_Spec (Unit_Node)
1405 then
1406 Pragma_Misplaced;
1408 elsif Nkind (Parent_Node) = N_Package_Body then
1409 Pragma_Misplaced;
1411 elsif Nkind (Parent_Node) = N_Package_Specification
1412 and then Plist = Private_Declarations (Parent_Node)
1413 then
1414 Pragma_Misplaced;
1416 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1417 or else Nkind (Parent_Node)
1418 = N_Generic_Subprogram_Declaration)
1419 and then Plist = Generic_Formal_Declarations (Parent_Node)
1420 then
1421 Pragma_Misplaced;
1423 elsif Arg_Count > 0 then
1424 Analyze (Expression (Arg1));
1426 if Entity (Expression (Arg1)) /= Current_Scope then
1427 Error_Pragma_Arg
1428 ("name in pragma% must be enclosing unit", Arg1);
1429 end if;
1431 -- It is legal to have no argument in this context
1433 else
1434 return;
1435 end if;
1437 -- Error if not before first declaration. This is because a
1438 -- library unit pragma argument must be the name of a library
1439 -- unit (RM 10.1.5(7)), but the only names permitted in this
1440 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1441 -- generic subprogram declarations or generic instantiations.
1443 else
1444 Error_Pragma
1445 ("pragma% misplaced, must be before first declaration");
1446 end if;
1447 end if;
1448 end if;
1449 end Check_Valid_Library_Unit_Pragma;
1451 -------------------
1452 -- Check_Variant --
1453 -------------------
1455 procedure Check_Variant (Variant : Node_Id) is
1456 Clist : constant Node_Id := Component_List (Variant);
1457 Comp : Node_Id;
1459 begin
1460 if Present (Variant_Part (Clist)) then
1461 Error_Msg_N
1462 ("Unchecked_Union may not have nested variants",
1463 Variant_Part (Clist));
1464 end if;
1466 if not Is_Non_Empty_List (Component_Items (Clist)) then
1467 Error_Msg_N
1468 ("Unchecked_Union may not have empty component list",
1469 Variant);
1470 return;
1471 end if;
1473 Comp := First (Component_Items (Clist));
1474 while Present (Comp) loop
1475 Check_Component (Comp);
1476 Next (Comp);
1477 end loop;
1478 end Check_Variant;
1480 ------------------
1481 -- Error_Pragma --
1482 ------------------
1484 procedure Error_Pragma (Msg : String) is
1485 begin
1486 Error_Msg_Name_1 := Chars (N);
1487 Error_Msg_N (Msg, N);
1488 raise Pragma_Exit;
1489 end Error_Pragma;
1491 ----------------------
1492 -- Error_Pragma_Arg --
1493 ----------------------
1495 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1496 begin
1497 Error_Msg_Name_1 := Chars (N);
1498 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1499 raise Pragma_Exit;
1500 end Error_Pragma_Arg;
1502 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1503 begin
1504 Error_Msg_Name_1 := Chars (N);
1505 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1506 Error_Pragma_Arg (Msg2, Arg);
1507 end Error_Pragma_Arg;
1509 ----------------------------
1510 -- Error_Pragma_Arg_Ident --
1511 ----------------------------
1513 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1514 begin
1515 Error_Msg_Name_1 := Chars (N);
1516 Error_Msg_N (Msg, Arg);
1517 raise Pragma_Exit;
1518 end Error_Pragma_Arg_Ident;
1520 ------------------------
1521 -- Find_Lib_Unit_Name --
1522 ------------------------
1524 function Find_Lib_Unit_Name return Entity_Id is
1525 begin
1526 -- Return inner compilation unit entity, for case of nested
1527 -- categorization pragmas. This happens in generic unit.
1529 if Nkind (Parent (N)) = N_Package_Specification
1530 and then Defining_Entity (Parent (N)) /= Current_Scope
1531 then
1532 return Defining_Entity (Parent (N));
1533 else
1534 return Current_Scope;
1535 end if;
1536 end Find_Lib_Unit_Name;
1538 ----------------------------
1539 -- Find_Program_Unit_Name --
1540 ----------------------------
1542 procedure Find_Program_Unit_Name (Id : Node_Id) is
1543 Unit_Name : Entity_Id;
1544 Unit_Kind : Node_Kind;
1545 P : constant Node_Id := Parent (N);
1547 begin
1548 if Nkind (P) = N_Compilation_Unit then
1549 Unit_Kind := Nkind (Unit (P));
1551 if Unit_Kind = N_Subprogram_Declaration
1552 or else Unit_Kind = N_Package_Declaration
1553 or else Unit_Kind in N_Generic_Declaration
1554 then
1555 Unit_Name := Defining_Entity (Unit (P));
1557 if Chars (Id) = Chars (Unit_Name) then
1558 Set_Entity (Id, Unit_Name);
1559 Set_Etype (Id, Etype (Unit_Name));
1560 else
1561 Set_Etype (Id, Any_Type);
1562 Error_Pragma
1563 ("cannot find program unit referenced by pragma%");
1564 end if;
1566 else
1567 Set_Etype (Id, Any_Type);
1568 Error_Pragma ("pragma% inapplicable to this unit");
1569 end if;
1571 else
1572 Analyze (Id);
1573 end if;
1575 end Find_Program_Unit_Name;
1577 -------------------------
1578 -- Gather_Associations --
1579 -------------------------
1581 procedure Gather_Associations
1582 (Names : Name_List;
1583 Args : out Args_List)
1585 Arg : Node_Id;
1587 begin
1588 -- Initialize all parameters to Empty
1590 for J in Args'Range loop
1591 Args (J) := Empty;
1592 end loop;
1594 -- That's all we have to do if there are no argument associations
1596 if No (Pragma_Argument_Associations (N)) then
1597 return;
1598 end if;
1600 -- Otherwise first deal with any positional parameters present
1602 Arg := First (Pragma_Argument_Associations (N));
1603 for Index in Args'Range loop
1604 exit when No (Arg) or else Chars (Arg) /= No_Name;
1605 Args (Index) := Expression (Arg);
1606 Next (Arg);
1607 end loop;
1609 -- Positional parameters all processed, if any left, then we
1610 -- have too many positional parameters.
1612 if Present (Arg) and then Chars (Arg) = No_Name then
1613 Error_Pragma_Arg
1614 ("too many positional associations for pragma%", Arg);
1615 end if;
1617 -- Process named parameters if any are present
1619 while Present (Arg) loop
1620 if Chars (Arg) = No_Name then
1621 Error_Pragma_Arg
1622 ("positional association cannot follow named association",
1623 Arg);
1625 else
1626 for Index in Names'Range loop
1627 if Names (Index) = Chars (Arg) then
1628 if Present (Args (Index)) then
1629 Error_Pragma_Arg
1630 ("duplicate argument association for pragma%", Arg);
1631 else
1632 Args (Index) := Expression (Arg);
1633 exit;
1634 end if;
1635 end if;
1637 if Index = Names'Last then
1638 Error_Msg_Name_1 := Chars (N);
1639 Error_Msg_N ("pragma% does not allow & argument", Arg);
1641 -- Check for possible misspelling
1643 for Index1 in Names'Range loop
1644 if Is_Bad_Spelling_Of
1645 (Get_Name_String (Chars (Arg)),
1646 Get_Name_String (Names (Index1)))
1647 then
1648 Error_Msg_Name_1 := Names (Index1);
1649 Error_Msg_N ("\possible misspelling of%", Arg);
1650 exit;
1651 end if;
1652 end loop;
1654 raise Pragma_Exit;
1655 end if;
1656 end loop;
1657 end if;
1659 Next (Arg);
1660 end loop;
1661 end Gather_Associations;
1663 --------------------
1664 -- Get_Pragma_Arg --
1665 --------------------
1667 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
1668 begin
1669 if Nkind (Arg) = N_Pragma_Argument_Association then
1670 return Expression (Arg);
1671 else
1672 return Arg;
1673 end if;
1674 end Get_Pragma_Arg;
1676 -----------------
1677 -- GNAT_Pragma --
1678 -----------------
1680 procedure GNAT_Pragma is
1681 begin
1682 Check_Restriction (No_Implementation_Pragmas, N);
1683 end GNAT_Pragma;
1685 --------------------------
1686 -- Is_Before_First_Decl --
1687 --------------------------
1689 function Is_Before_First_Decl
1690 (Pragma_Node : Node_Id;
1691 Decls : List_Id) return Boolean
1693 Item : Node_Id := First (Decls);
1695 begin
1696 -- Only other pragmas can come before this pragma
1698 loop
1699 if No (Item) or else Nkind (Item) /= N_Pragma then
1700 return False;
1702 elsif Item = Pragma_Node then
1703 return True;
1704 end if;
1706 Next (Item);
1707 end loop;
1708 end Is_Before_First_Decl;
1710 -----------------------------
1711 -- Is_Configuration_Pragma --
1712 -----------------------------
1714 -- A configuration pragma must appear in the context clause of
1715 -- a compilation unit, at the start of the list (i.e. only other
1716 -- pragmas may precede it).
1718 function Is_Configuration_Pragma return Boolean is
1719 Lis : constant List_Id := List_Containing (N);
1720 Par : constant Node_Id := Parent (N);
1721 Prg : Node_Id;
1723 begin
1724 -- If no parent, then we are in the configuration pragma file,
1725 -- so the placement is definitely appropriate.
1727 if No (Par) then
1728 return True;
1730 -- Otherwise we must be in the context clause of a compilation unit
1731 -- and the only thing allowed before us in the context list is more
1732 -- configuration pragmas.
1734 elsif Nkind (Par) = N_Compilation_Unit
1735 and then Context_Items (Par) = Lis
1736 then
1737 Prg := First (Lis);
1739 loop
1740 if Prg = N then
1741 return True;
1742 elsif Nkind (Prg) /= N_Pragma then
1743 return False;
1744 end if;
1746 Next (Prg);
1747 end loop;
1749 else
1750 return False;
1751 end if;
1752 end Is_Configuration_Pragma;
1754 ----------------------
1755 -- Pragma_Misplaced --
1756 ----------------------
1758 procedure Pragma_Misplaced is
1759 begin
1760 Error_Pragma ("incorrect placement of pragma%");
1761 end Pragma_Misplaced;
1763 ------------------------------------
1764 -- Process Atomic_Shared_Volatile --
1765 ------------------------------------
1767 procedure Process_Atomic_Shared_Volatile is
1768 E_Id : Node_Id;
1769 E : Entity_Id;
1770 D : Node_Id;
1771 K : Node_Kind;
1772 Utyp : Entity_Id;
1774 procedure Set_Atomic (E : Entity_Id);
1775 -- Set given type as atomic, and if no explicit alignment was
1776 -- given, set alignment to unknown, since back end knows what
1777 -- the alignment requirements are for atomic arrays. Note that
1778 -- this step is necessary for derived types.
1780 ----------------
1781 -- Set_Atomic --
1782 ----------------
1784 procedure Set_Atomic (E : Entity_Id) is
1785 begin
1786 Set_Is_Atomic (E);
1788 if not Has_Alignment_Clause (E) then
1789 Set_Alignment (E, Uint_0);
1790 end if;
1791 end Set_Atomic;
1793 -- Start of processing for Process_Atomic_Shared_Volatile
1795 begin
1796 Check_Ada_83_Warning;
1797 Check_No_Identifiers;
1798 Check_Arg_Count (1);
1799 Check_Arg_Is_Local_Name (Arg1);
1800 E_Id := Expression (Arg1);
1802 if Etype (E_Id) = Any_Type then
1803 return;
1804 end if;
1806 E := Entity (E_Id);
1807 D := Declaration_Node (E);
1808 K := Nkind (D);
1810 if Is_Type (E) then
1811 if Rep_Item_Too_Early (E, N)
1812 or else
1813 Rep_Item_Too_Late (E, N)
1814 then
1815 return;
1816 else
1817 Check_First_Subtype (Arg1);
1818 end if;
1820 if Prag_Id /= Pragma_Volatile then
1821 Set_Atomic (E);
1822 Set_Atomic (Underlying_Type (E));
1823 Set_Atomic (Base_Type (E));
1824 end if;
1826 -- Attribute belongs on the base type. If the
1827 -- view of the type is currently private, it also
1828 -- belongs on the underlying type.
1830 Set_Is_Volatile (Base_Type (E));
1831 Set_Is_Volatile (Underlying_Type (E));
1833 Set_Treat_As_Volatile (E);
1834 Set_Treat_As_Volatile (Underlying_Type (E));
1836 elsif K = N_Object_Declaration
1837 or else (K = N_Component_Declaration
1838 and then Original_Record_Component (E) = E)
1839 then
1840 if Rep_Item_Too_Late (E, N) then
1841 return;
1842 end if;
1844 if Prag_Id /= Pragma_Volatile then
1845 Set_Is_Atomic (E);
1847 -- If the object declaration has an explicit
1848 -- initialization, a temporary may have to be
1849 -- created to hold the expression, to insure
1850 -- that access to the object remain atomic.
1852 if Nkind (Parent (E)) = N_Object_Declaration
1853 and then Present (Expression (Parent (E)))
1854 then
1855 Set_Has_Delayed_Freeze (E);
1856 end if;
1858 -- An interesting improvement here. If an object of type X
1859 -- is declared atomic, and the type X is not atomic, that's
1860 -- a pity, since it may not have appropraite alignment etc.
1861 -- We can rescue this in the special case where the object
1862 -- and type are in the same unit by just setting the type
1863 -- as atomic, so that the back end will process it as atomic.
1865 Utyp := Underlying_Type (Etype (E));
1867 if Present (Utyp)
1868 and then Sloc (E) > No_Location
1869 and then Sloc (Utyp) > No_Location
1870 and then
1871 Get_Source_File_Index (Sloc (E)) =
1872 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
1873 then
1874 Set_Is_Atomic (Underlying_Type (Etype (E)));
1875 end if;
1876 end if;
1878 Set_Is_Volatile (E);
1879 Set_Treat_As_Volatile (E);
1881 else
1882 Error_Pragma_Arg
1883 ("inappropriate entity for pragma%", Arg1);
1884 end if;
1885 end Process_Atomic_Shared_Volatile;
1887 ------------------------
1888 -- Process_Convention --
1889 ------------------------
1891 procedure Process_Convention
1892 (C : out Convention_Id;
1893 E : out Entity_Id)
1895 Id : Node_Id;
1896 E1 : Entity_Id;
1897 Cname : Name_Id;
1898 Comp_Unit : Unit_Number_Type;
1900 procedure Set_Convention_From_Pragma (E : Entity_Id);
1901 -- Set convention in entity E, and also flag that the entity has a
1902 -- convention pragma. If entity is for a private or incomplete type,
1903 -- also set convention and flag on underlying type. This procedure
1904 -- also deals with the special case of C_Pass_By_Copy convention.
1906 --------------------------------
1907 -- Set_Convention_From_Pragma --
1908 --------------------------------
1910 procedure Set_Convention_From_Pragma (E : Entity_Id) is
1911 begin
1912 Set_Convention (E, C);
1913 Set_Has_Convention_Pragma (E);
1915 if Is_Incomplete_Or_Private_Type (E) then
1916 Set_Convention (Underlying_Type (E), C);
1917 Set_Has_Convention_Pragma (Underlying_Type (E), True);
1918 end if;
1920 -- A class-wide type should inherit the convention of
1921 -- the specific root type (although this isn't specified
1922 -- clearly by the RM).
1924 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
1925 Set_Convention (Class_Wide_Type (E), C);
1926 end if;
1928 -- If the entity is a record type, then check for special case
1929 -- of C_Pass_By_Copy, which is treated the same as C except that
1930 -- the special record flag is set. This convention is also only
1931 -- permitted on record types (see AI95-00131).
1933 if Cname = Name_C_Pass_By_Copy then
1934 if Is_Record_Type (E) then
1935 Set_C_Pass_By_Copy (Base_Type (E));
1936 elsif Is_Incomplete_Or_Private_Type (E)
1937 and then Is_Record_Type (Underlying_Type (E))
1938 then
1939 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
1940 else
1941 Error_Pragma_Arg
1942 ("C_Pass_By_Copy convention allowed only for record type",
1943 Arg2);
1944 end if;
1945 end if;
1947 -- If the entity is a derived boolean type, check for the
1948 -- special case of convention C, C++, or Fortran, where we
1949 -- consider any nonzero value to represent true.
1951 if Is_Discrete_Type (E)
1952 and then Root_Type (Etype (E)) = Standard_Boolean
1953 and then
1954 (C = Convention_C
1955 or else
1956 C = Convention_CPP
1957 or else
1958 C = Convention_Fortran)
1959 then
1960 Set_Nonzero_Is_True (Base_Type (E));
1961 end if;
1962 end Set_Convention_From_Pragma;
1964 -- Start of processing for Process_Convention
1966 begin
1967 Check_At_Least_N_Arguments (2);
1968 Check_Arg_Is_Identifier (Arg1);
1969 Check_Optional_Identifier (Arg1, Name_Convention);
1970 Cname := Chars (Expression (Arg1));
1972 -- C_Pass_By_Copy is treated as a synonym for convention C
1973 -- (this is tested again below to set the critical flag)
1975 if Cname = Name_C_Pass_By_Copy then
1976 C := Convention_C;
1978 -- Otherwise we must have something in the standard convention list
1980 elsif Is_Convention_Name (Cname) then
1981 C := Get_Convention_Id (Chars (Expression (Arg1)));
1983 -- In DEC VMS, it seems that there is an undocumented feature
1984 -- that any unrecognized convention is treated as the default,
1985 -- which for us is convention C. It does not seem so terrible
1986 -- to do this unconditionally, silently in the VMS case, and
1987 -- with a warning in the non-VMS case.
1989 else
1990 if Warn_On_Export_Import and not OpenVMS_On_Target then
1991 Error_Msg_N
1992 ("?unrecognized convention name, C assumed",
1993 Expression (Arg1));
1994 end if;
1996 C := Convention_C;
1997 end if;
1999 Check_Arg_Is_Local_Name (Arg2);
2000 Check_Optional_Identifier (Arg2, Name_Entity);
2002 Id := Expression (Arg2);
2003 Analyze (Id);
2005 if not Is_Entity_Name (Id) then
2006 Error_Pragma_Arg ("entity name required", Arg2);
2007 end if;
2009 E := Entity (Id);
2011 -- Go to renamed subprogram if present, since convention applies
2012 -- to the actual renamed entity, not to the renaming entity.
2013 -- If subprogram is inherited, go to parent subprogram.
2015 if Is_Subprogram (E)
2016 and then Present (Alias (E))
2017 then
2018 if Nkind (Parent (Declaration_Node (E)))
2019 = N_Subprogram_Renaming_Declaration
2020 then
2021 E := Alias (E);
2023 elsif Nkind (Parent (E)) = N_Full_Type_Declaration
2024 and then Scope (E) = Scope (Alias (E))
2025 then
2026 E := Alias (E);
2027 end if;
2028 end if;
2030 -- Check that we are not applying this to a specless body
2032 if Is_Subprogram (E)
2033 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2034 then
2035 Error_Pragma
2036 ("pragma% requires separate spec and must come before body");
2037 end if;
2039 -- Check that we are not applying this to a named constant
2041 if Ekind (E) = E_Named_Integer
2042 or else
2043 Ekind (E) = E_Named_Real
2044 then
2045 Error_Msg_Name_1 := Chars (N);
2046 Error_Msg_N
2047 ("cannot apply pragma% to named constant!",
2048 Get_Pragma_Arg (Arg2));
2049 Error_Pragma_Arg
2050 ("\supply appropriate type for&!", Arg2);
2051 end if;
2053 if Etype (E) = Any_Type
2054 or else Rep_Item_Too_Early (E, N)
2055 then
2056 raise Pragma_Exit;
2057 else
2058 E := Underlying_Type (E);
2059 end if;
2061 if Rep_Item_Too_Late (E, N) then
2062 raise Pragma_Exit;
2063 end if;
2065 if Has_Convention_Pragma (E) then
2066 Error_Pragma_Arg
2067 ("at most one Convention/Export/Import pragma is allowed", Arg2);
2069 elsif Convention (E) = Convention_Protected
2070 or else Ekind (Scope (E)) = E_Protected_Type
2071 then
2072 Error_Pragma_Arg
2073 ("a protected operation cannot be given a different convention",
2074 Arg2);
2075 end if;
2077 -- For Intrinsic, a subprogram is required
2079 if C = Convention_Intrinsic
2080 and then not Is_Subprogram (E)
2081 and then not Is_Generic_Subprogram (E)
2082 then
2083 Error_Pragma_Arg
2084 ("second argument of pragma% must be a subprogram", Arg2);
2085 end if;
2087 -- For Stdcall, a subprogram, variable or subprogram type is required
2089 if C = Convention_Stdcall
2090 and then not Is_Subprogram (E)
2091 and then not Is_Generic_Subprogram (E)
2092 and then Ekind (E) /= E_Variable
2093 and then not
2094 (Is_Access_Type (E)
2095 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2096 then
2097 Error_Pragma_Arg
2098 ("second argument of pragma% must be subprogram (type)",
2099 Arg2);
2100 end if;
2102 if not Is_Subprogram (E)
2103 and then not Is_Generic_Subprogram (E)
2104 then
2105 Set_Convention_From_Pragma (E);
2107 if Is_Type (E) then
2109 Check_First_Subtype (Arg2);
2110 Set_Convention_From_Pragma (Base_Type (E));
2112 -- For subprograms, we must set the convention on the
2113 -- internally generated directly designated type as well.
2115 if Ekind (E) = E_Access_Subprogram_Type then
2116 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2117 end if;
2118 end if;
2120 -- For the subprogram case, set proper convention for all homonyms
2121 -- in same scope and the same declarative part, i.e. the same
2122 -- compilation unit.
2124 else
2125 Comp_Unit := Get_Source_Unit (E);
2126 Set_Convention_From_Pragma (E);
2128 -- Treat a pragma Import as an implicit body, for GPS use.
2130 if Prag_Id = Pragma_Import then
2131 Generate_Reference (E, Id, 'b');
2132 end if;
2134 E1 := E;
2135 loop
2136 E1 := Homonym (E1);
2137 exit when No (E1) or else Scope (E1) /= Current_Scope;
2139 -- Note: below we are missing a check for Rep_Item_Too_Late.
2140 -- That is deliberate, we cannot chain the rep item on more
2141 -- than one Rep_Item chain, to be fixed later ???
2143 if Comes_From_Source (E1)
2144 and then Comp_Unit = Get_Source_Unit (E1)
2145 and then Nkind (Original_Node (Parent (E1))) /=
2146 N_Full_Type_Declaration
2147 then
2148 Set_Convention_From_Pragma (E1);
2150 if Prag_Id = Pragma_Import then
2151 Generate_Reference (E, Id, 'b');
2152 end if;
2153 end if;
2154 end loop;
2155 end if;
2156 end Process_Convention;
2158 -----------------------------------------------------
2159 -- Process_Extended_Import_Export_Exception_Pragma --
2160 -----------------------------------------------------
2162 procedure Process_Extended_Import_Export_Exception_Pragma
2163 (Arg_Internal : Node_Id;
2164 Arg_External : Node_Id;
2165 Arg_Form : Node_Id;
2166 Arg_Code : Node_Id)
2168 Def_Id : Entity_Id;
2169 Code_Val : Uint;
2171 begin
2172 GNAT_Pragma;
2174 if not OpenVMS_On_Target then
2175 Error_Pragma
2176 ("?pragma% ignored (applies only to Open'V'M'S)");
2177 end if;
2179 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2180 Def_Id := Entity (Arg_Internal);
2182 if Ekind (Def_Id) /= E_Exception then
2183 Error_Pragma_Arg
2184 ("pragma% must refer to declared exception", Arg_Internal);
2185 end if;
2187 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2189 if Present (Arg_Form) then
2190 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2191 end if;
2193 if Present (Arg_Form)
2194 and then Chars (Arg_Form) = Name_Ada
2195 then
2196 null;
2197 else
2198 Set_Is_VMS_Exception (Def_Id);
2199 Set_Exception_Code (Def_Id, No_Uint);
2200 end if;
2202 if Present (Arg_Code) then
2203 if not Is_VMS_Exception (Def_Id) then
2204 Error_Pragma_Arg
2205 ("Code option for pragma% not allowed for Ada case",
2206 Arg_Code);
2207 end if;
2209 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2210 Code_Val := Expr_Value (Arg_Code);
2212 if not UI_Is_In_Int_Range (Code_Val) then
2213 Error_Pragma_Arg
2214 ("Code option for pragma% must be in 32-bit range",
2215 Arg_Code);
2217 else
2218 Set_Exception_Code (Def_Id, Code_Val);
2219 end if;
2220 end if;
2221 end Process_Extended_Import_Export_Exception_Pragma;
2223 -------------------------------------------------
2224 -- Process_Extended_Import_Export_Internal_Arg --
2225 -------------------------------------------------
2227 procedure Process_Extended_Import_Export_Internal_Arg
2228 (Arg_Internal : Node_Id := Empty)
2230 begin
2231 GNAT_Pragma;
2233 if No (Arg_Internal) then
2234 Error_Pragma ("Internal parameter required for pragma%");
2235 end if;
2237 if Nkind (Arg_Internal) = N_Identifier then
2238 null;
2240 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2241 and then (Prag_Id = Pragma_Import_Function
2242 or else
2243 Prag_Id = Pragma_Export_Function)
2244 then
2245 null;
2247 else
2248 Error_Pragma_Arg
2249 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2250 end if;
2252 Check_Arg_Is_Local_Name (Arg_Internal);
2253 end Process_Extended_Import_Export_Internal_Arg;
2255 --------------------------------------------------
2256 -- Process_Extended_Import_Export_Object_Pragma --
2257 --------------------------------------------------
2259 procedure Process_Extended_Import_Export_Object_Pragma
2260 (Arg_Internal : Node_Id;
2261 Arg_External : Node_Id;
2262 Arg_Size : Node_Id)
2264 Def_Id : Entity_Id;
2266 begin
2267 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2268 Def_Id := Entity (Arg_Internal);
2270 if Ekind (Def_Id) /= E_Constant
2271 and then Ekind (Def_Id) /= E_Variable
2272 then
2273 Error_Pragma_Arg
2274 ("pragma% must designate an object", Arg_Internal);
2275 end if;
2277 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2278 or else
2279 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2280 then
2281 Error_Pragma_Arg
2282 ("previous Common/Psect_Object applies, pragma % not permitted",
2283 Arg_Internal);
2284 end if;
2286 if Rep_Item_Too_Late (Def_Id, N) then
2287 raise Pragma_Exit;
2288 end if;
2290 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2292 if Present (Arg_Size) then
2293 Check_Arg_Is_External_Name (Arg_Size);
2294 end if;
2296 -- Export_Object case
2298 if Prag_Id = Pragma_Export_Object then
2299 if not Is_Library_Level_Entity (Def_Id) then
2300 Error_Pragma_Arg
2301 ("argument for pragma% must be library level entity",
2302 Arg_Internal);
2303 end if;
2305 if Ekind (Current_Scope) = E_Generic_Package then
2306 Error_Pragma ("pragma& cannot appear in a generic unit");
2307 end if;
2309 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2310 Error_Pragma_Arg
2311 ("exported object must have compile time known size",
2312 Arg_Internal);
2313 end if;
2315 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2316 Error_Msg_N
2317 ("?duplicate Export_Object pragma", N);
2318 else
2319 Set_Exported (Def_Id, Arg_Internal);
2320 end if;
2322 -- Import_Object case
2324 else
2325 if Is_Concurrent_Type (Etype (Def_Id)) then
2326 Error_Pragma_Arg
2327 ("cannot use pragma% for task/protected object",
2328 Arg_Internal);
2329 end if;
2331 if Ekind (Def_Id) = E_Constant then
2332 Error_Pragma_Arg
2333 ("cannot import a constant", Arg_Internal);
2334 end if;
2336 if Warn_On_Export_Import
2337 and then Has_Discriminants (Etype (Def_Id))
2338 then
2339 Error_Msg_N
2340 ("imported value must be initialized?", Arg_Internal);
2341 end if;
2343 if Warn_On_Export_Import
2344 and then Is_Access_Type (Etype (Def_Id))
2345 then
2346 Error_Pragma_Arg
2347 ("cannot import object of an access type?", Arg_Internal);
2348 end if;
2350 if Warn_On_Export_Import
2351 and then Is_Imported (Def_Id)
2352 then
2353 Error_Msg_N
2354 ("?duplicate Import_Object pragma", N);
2356 -- Check for explicit initialization present. Note that an
2357 -- initialization that generated by the code generator, e.g.
2358 -- for an access type, does not count here.
2360 elsif Present (Expression (Parent (Def_Id)))
2361 and then
2362 Comes_From_Source
2363 (Original_Node (Expression (Parent (Def_Id))))
2364 then
2365 Error_Msg_Sloc := Sloc (Def_Id);
2366 Error_Pragma_Arg
2367 ("no initialization allowed for declaration of& #",
2368 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2369 Arg1);
2370 else
2371 Set_Imported (Def_Id);
2372 Note_Possible_Modification (Arg_Internal);
2373 end if;
2374 end if;
2375 end Process_Extended_Import_Export_Object_Pragma;
2377 ------------------------------------------------------
2378 -- Process_Extended_Import_Export_Subprogram_Pragma --
2379 ------------------------------------------------------
2381 procedure Process_Extended_Import_Export_Subprogram_Pragma
2382 (Arg_Internal : Node_Id;
2383 Arg_External : Node_Id;
2384 Arg_Parameter_Types : Node_Id;
2385 Arg_Result_Type : Node_Id := Empty;
2386 Arg_Mechanism : Node_Id;
2387 Arg_Result_Mechanism : Node_Id := Empty;
2388 Arg_First_Optional_Parameter : Node_Id := Empty)
2390 Ent : Entity_Id;
2391 Def_Id : Entity_Id;
2392 Hom_Id : Entity_Id;
2393 Formal : Entity_Id;
2394 Ambiguous : Boolean;
2395 Match : Boolean;
2396 Dval : Node_Id;
2398 function Same_Base_Type
2399 (Ptype : Node_Id;
2400 Formal : Entity_Id) return Boolean;
2401 -- Determines if Ptype references the type of Formal. Note that
2402 -- only the base types need to match according to the spec. Ptype
2403 -- here is the argument from the pragma, which is either a type
2404 -- name, or an access attribute.
2406 --------------------
2407 -- Same_Base_Type --
2408 --------------------
2410 function Same_Base_Type
2411 (Ptype : Node_Id;
2412 Formal : Entity_Id) return Boolean
2414 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2415 Pref : Node_Id;
2417 begin
2418 -- Case where pragma argument is typ'Access
2420 if Nkind (Ptype) = N_Attribute_Reference
2421 and then Attribute_Name (Ptype) = Name_Access
2422 then
2423 Pref := Prefix (Ptype);
2424 Find_Type (Pref);
2426 if not Is_Entity_Name (Pref)
2427 or else Entity (Pref) = Any_Type
2428 then
2429 raise Pragma_Exit;
2430 end if;
2432 -- We have a match if the corresponding argument is of an
2433 -- anonymous access type, and its designicated type matches
2434 -- the type of the prefix of the access attribute
2436 return Ekind (Ftyp) = E_Anonymous_Access_Type
2437 and then Base_Type (Entity (Pref)) =
2438 Base_Type (Etype (Designated_Type (Ftyp)));
2440 -- Case where pragma argument is a type name
2442 else
2443 Find_Type (Ptype);
2445 if not Is_Entity_Name (Ptype)
2446 or else Entity (Ptype) = Any_Type
2447 then
2448 raise Pragma_Exit;
2449 end if;
2451 -- We have a match if the corresponding argument is of
2452 -- the type given in the pragma (comparing base types)
2454 return Base_Type (Entity (Ptype)) = Ftyp;
2455 end if;
2456 end Same_Base_Type;
2458 -- Start of processing for
2459 -- Process_Extended_Import_Export_Subprogram_Pragma
2461 begin
2462 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2463 Ent := Empty;
2464 Ambiguous := False;
2466 -- Loop through homonyms (overloadings) of the entity
2468 Hom_Id := Entity (Arg_Internal);
2469 while Present (Hom_Id) loop
2470 Def_Id := Get_Base_Subprogram (Hom_Id);
2472 -- We need a subprogram in the current scope
2474 if not Is_Subprogram (Def_Id)
2475 or else Scope (Def_Id) /= Current_Scope
2476 then
2477 null;
2479 else
2480 Match := True;
2482 -- Pragma cannot apply to subprogram body
2484 if Is_Subprogram (Def_Id)
2485 and then
2486 Nkind (Parent
2487 (Declaration_Node (Def_Id))) = N_Subprogram_Body
2488 then
2489 Error_Pragma
2490 ("pragma% requires separate spec"
2491 & " and must come before body");
2492 end if;
2494 -- Test result type if given, note that the result type
2495 -- parameter can only be present for the function cases.
2497 if Present (Arg_Result_Type)
2498 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2499 then
2500 Match := False;
2502 elsif Etype (Def_Id) /= Standard_Void_Type
2503 and then
2504 (Chars (N) = Name_Export_Procedure
2505 or else Chars (N) = Name_Import_Procedure)
2506 then
2507 Match := False;
2509 -- Test parameter types if given. Note that this parameter
2510 -- has not been analyzed (and must not be, since it is
2511 -- semantic nonsense), so we get it as the parser left it.
2513 elsif Present (Arg_Parameter_Types) then
2514 Check_Matching_Types : declare
2515 Formal : Entity_Id;
2516 Ptype : Node_Id;
2518 begin
2519 Formal := First_Formal (Def_Id);
2521 if Nkind (Arg_Parameter_Types) = N_Null then
2522 if Present (Formal) then
2523 Match := False;
2524 end if;
2526 -- A list of one type, e.g. (List) is parsed as
2527 -- a parenthesized expression.
2529 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
2530 and then Paren_Count (Arg_Parameter_Types) = 1
2531 then
2532 if No (Formal)
2533 or else Present (Next_Formal (Formal))
2534 then
2535 Match := False;
2536 else
2537 Match :=
2538 Same_Base_Type (Arg_Parameter_Types, Formal);
2539 end if;
2541 -- A list of more than one type is parsed as a aggregate
2543 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
2544 and then Paren_Count (Arg_Parameter_Types) = 0
2545 then
2546 Ptype := First (Expressions (Arg_Parameter_Types));
2547 while Present (Ptype) or else Present (Formal) loop
2548 if No (Ptype)
2549 or else No (Formal)
2550 or else not Same_Base_Type (Ptype, Formal)
2551 then
2552 Match := False;
2553 exit;
2554 else
2555 Next_Formal (Formal);
2556 Next (Ptype);
2557 end if;
2558 end loop;
2560 -- Anything else is of the wrong form
2562 else
2563 Error_Pragma_Arg
2564 ("wrong form for Parameter_Types parameter",
2565 Arg_Parameter_Types);
2566 end if;
2567 end Check_Matching_Types;
2568 end if;
2570 -- Match is now False if the entry we found did not match
2571 -- either a supplied Parameter_Types or Result_Types argument
2573 if Match then
2574 if No (Ent) then
2575 Ent := Def_Id;
2577 -- Ambiguous case, the flag Ambiguous shows if we already
2578 -- detected this and output the initial messages.
2580 else
2581 if not Ambiguous then
2582 Ambiguous := True;
2583 Error_Msg_Name_1 := Chars (N);
2584 Error_Msg_N
2585 ("pragma% does not uniquely identify subprogram!",
2587 Error_Msg_Sloc := Sloc (Ent);
2588 Error_Msg_N ("matching subprogram #!", N);
2589 Ent := Empty;
2590 end if;
2592 Error_Msg_Sloc := Sloc (Def_Id);
2593 Error_Msg_N ("matching subprogram #!", N);
2594 end if;
2595 end if;
2596 end if;
2598 Hom_Id := Homonym (Hom_Id);
2599 end loop;
2601 -- See if we found an entry
2603 if No (Ent) then
2604 if not Ambiguous then
2605 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
2606 Error_Pragma
2607 ("pragma% cannot be given for generic subprogram");
2609 else
2610 Error_Pragma
2611 ("pragma% does not identify local subprogram");
2612 end if;
2613 end if;
2615 return;
2616 end if;
2618 -- Import pragmas must be be for imported entities
2620 if Prag_Id = Pragma_Import_Function
2621 or else
2622 Prag_Id = Pragma_Import_Procedure
2623 or else
2624 Prag_Id = Pragma_Import_Valued_Procedure
2625 then
2626 if not Is_Imported (Ent) then
2627 Error_Pragma
2628 ("pragma Import or Interface must precede pragma%");
2629 end if;
2631 -- Here we have the Export case which can set the entity as exported
2633 -- But does not do so if the specified external name is null,
2634 -- since that is taken as a signal in DEC Ada 83 (with which
2635 -- we want to be compatible) to request no external name.
2637 elsif Nkind (Arg_External) = N_String_Literal
2638 and then String_Length (Strval (Arg_External)) = 0
2639 then
2640 null;
2642 -- In all other cases, set entit as exported
2644 else
2645 Set_Exported (Ent, Arg_Internal);
2646 end if;
2648 -- Special processing for Valued_Procedure cases
2650 if Prag_Id = Pragma_Import_Valued_Procedure
2651 or else
2652 Prag_Id = Pragma_Export_Valued_Procedure
2653 then
2654 Formal := First_Formal (Ent);
2656 if No (Formal) then
2657 Error_Pragma
2658 ("at least one parameter required for pragma%");
2660 elsif Ekind (Formal) /= E_Out_Parameter then
2661 Error_Pragma
2662 ("first parameter must have mode out for pragma%");
2664 else
2665 Set_Is_Valued_Procedure (Ent);
2666 end if;
2667 end if;
2669 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
2671 -- Process Result_Mechanism argument if present. We have already
2672 -- checked that this is only allowed for the function case.
2674 if Present (Arg_Result_Mechanism) then
2675 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
2676 end if;
2678 -- Process Mechanism parameter if present. Note that this parameter
2679 -- is not analyzed, and must not be analyzed since it is semantic
2680 -- nonsense, so we get it in exactly as the parser left it.
2682 if Present (Arg_Mechanism) then
2683 declare
2684 Formal : Entity_Id;
2685 Massoc : Node_Id;
2686 Mname : Node_Id;
2687 Choice : Node_Id;
2689 begin
2690 -- A single mechanism association without a formal parameter
2691 -- name is parsed as a parenthesized expression. All other
2692 -- cases are parsed as aggregates, so we rewrite the single
2693 -- parameter case as an aggregate for consistency.
2695 if Nkind (Arg_Mechanism) /= N_Aggregate
2696 and then Paren_Count (Arg_Mechanism) = 1
2697 then
2698 Rewrite (Arg_Mechanism,
2699 Make_Aggregate (Sloc (Arg_Mechanism),
2700 Expressions => New_List (
2701 Relocate_Node (Arg_Mechanism))));
2702 end if;
2704 -- Case of only mechanism name given, applies to all formals
2706 if Nkind (Arg_Mechanism) /= N_Aggregate then
2707 Formal := First_Formal (Ent);
2708 while Present (Formal) loop
2709 Set_Mechanism_Value (Formal, Arg_Mechanism);
2710 Next_Formal (Formal);
2711 end loop;
2713 -- Case of list of mechanism associations given
2715 else
2716 if Null_Record_Present (Arg_Mechanism) then
2717 Error_Pragma_Arg
2718 ("inappropriate form for Mechanism parameter",
2719 Arg_Mechanism);
2720 end if;
2722 -- Deal with positional ones first
2724 Formal := First_Formal (Ent);
2726 if Present (Expressions (Arg_Mechanism)) then
2727 Mname := First (Expressions (Arg_Mechanism));
2729 while Present (Mname) loop
2730 if No (Formal) then
2731 Error_Pragma_Arg
2732 ("too many mechanism associations", Mname);
2733 end if;
2735 Set_Mechanism_Value (Formal, Mname);
2736 Next_Formal (Formal);
2737 Next (Mname);
2738 end loop;
2739 end if;
2741 -- Deal with named entries
2743 if Present (Component_Associations (Arg_Mechanism)) then
2744 Massoc := First (Component_Associations (Arg_Mechanism));
2746 while Present (Massoc) loop
2747 Choice := First (Choices (Massoc));
2749 if Nkind (Choice) /= N_Identifier
2750 or else Present (Next (Choice))
2751 then
2752 Error_Pragma_Arg
2753 ("incorrect form for mechanism association",
2754 Massoc);
2755 end if;
2757 Formal := First_Formal (Ent);
2758 loop
2759 if No (Formal) then
2760 Error_Pragma_Arg
2761 ("parameter name & not present", Choice);
2762 end if;
2764 if Chars (Choice) = Chars (Formal) then
2765 Set_Mechanism_Value
2766 (Formal, Expression (Massoc));
2767 exit;
2768 end if;
2770 Next_Formal (Formal);
2771 end loop;
2773 Next (Massoc);
2774 end loop;
2775 end if;
2776 end if;
2777 end;
2778 end if;
2780 -- Process First_Optional_Parameter argument if present. We have
2781 -- already checked that this is only allowed for the Import case.
2783 if Present (Arg_First_Optional_Parameter) then
2784 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
2785 Error_Pragma_Arg
2786 ("first optional parameter must be formal parameter name",
2787 Arg_First_Optional_Parameter);
2788 end if;
2790 Formal := First_Formal (Ent);
2791 loop
2792 if No (Formal) then
2793 Error_Pragma_Arg
2794 ("specified formal parameter& not found",
2795 Arg_First_Optional_Parameter);
2796 end if;
2798 exit when Chars (Formal) =
2799 Chars (Arg_First_Optional_Parameter);
2801 Next_Formal (Formal);
2802 end loop;
2804 Set_First_Optional_Parameter (Ent, Formal);
2806 -- Check specified and all remaining formals have right form
2808 while Present (Formal) loop
2809 if Ekind (Formal) /= E_In_Parameter then
2810 Error_Msg_NE
2811 ("optional formal& is not of mode in!",
2812 Arg_First_Optional_Parameter, Formal);
2814 else
2815 Dval := Default_Value (Formal);
2817 if not Present (Dval) then
2818 Error_Msg_NE
2819 ("optional formal& does not have default value!",
2820 Arg_First_Optional_Parameter, Formal);
2822 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
2823 null;
2825 else
2826 Error_Msg_FE
2827 ("default value for optional formal& is non-static!",
2828 Arg_First_Optional_Parameter, Formal);
2829 end if;
2830 end if;
2832 Set_Is_Optional_Parameter (Formal);
2833 Next_Formal (Formal);
2834 end loop;
2835 end if;
2836 end Process_Extended_Import_Export_Subprogram_Pragma;
2838 --------------------------
2839 -- Process_Generic_List --
2840 --------------------------
2842 procedure Process_Generic_List is
2843 Arg : Node_Id;
2844 Exp : Node_Id;
2846 begin
2847 GNAT_Pragma;
2848 Check_No_Identifiers;
2849 Check_At_Least_N_Arguments (1);
2851 Arg := Arg1;
2852 while Present (Arg) loop
2853 Exp := Expression (Arg);
2854 Analyze (Exp);
2856 if not Is_Entity_Name (Exp)
2857 or else
2858 (not Is_Generic_Instance (Entity (Exp))
2859 and then
2860 not Is_Generic_Unit (Entity (Exp)))
2861 then
2862 Error_Pragma_Arg
2863 ("pragma% argument must be name of generic unit/instance",
2864 Arg);
2865 end if;
2867 Next (Arg);
2868 end loop;
2869 end Process_Generic_List;
2871 ---------------------------------
2872 -- Process_Import_Or_Interface --
2873 ---------------------------------
2875 procedure Process_Import_Or_Interface is
2876 C : Convention_Id;
2877 Def_Id : Entity_Id;
2878 Hom_Id : Entity_Id;
2880 begin
2881 Process_Convention (C, Def_Id);
2882 Kill_Size_Check_Code (Def_Id);
2883 Note_Possible_Modification (Expression (Arg2));
2885 if Ekind (Def_Id) = E_Variable
2886 or else
2887 Ekind (Def_Id) = E_Constant
2888 then
2889 -- User initialization is not allowed for imported object, but
2890 -- the object declaration may contain a default initialization,
2891 -- that will be discarded. Note that an explicit initialization
2892 -- only counts if it comes from source, otherwise it is simply
2893 -- the code generator making an implicit initialization explicit.
2895 if Present (Expression (Parent (Def_Id)))
2896 and then Comes_From_Source (Expression (Parent (Def_Id)))
2897 then
2898 Error_Msg_Sloc := Sloc (Def_Id);
2899 Error_Pragma_Arg
2900 ("no initialization allowed for declaration of& #",
2901 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2902 Arg2);
2904 else
2905 Set_Imported (Def_Id);
2906 Process_Interface_Name (Def_Id, Arg3, Arg4);
2908 -- Note that we do not set Is_Public here. That's because we
2909 -- only want to set if if there is no address clause, and we
2910 -- don't know that yet, so we delay that processing till
2911 -- freeze time.
2913 -- pragma Import completes deferred constants
2915 if Ekind (Def_Id) = E_Constant then
2916 Set_Has_Completion (Def_Id);
2917 end if;
2919 -- It is not possible to import a constant of an unconstrained
2920 -- array type (e.g. string) because there is no simple way to
2921 -- write a meaningful subtype for it.
2923 if Is_Array_Type (Etype (Def_Id))
2924 and then not Is_Constrained (Etype (Def_Id))
2925 then
2926 Error_Msg_NE
2927 ("imported constant& must have a constrained subtype",
2928 N, Def_Id);
2929 end if;
2930 end if;
2932 elsif Is_Subprogram (Def_Id)
2933 or else Is_Generic_Subprogram (Def_Id)
2934 then
2935 -- If the name is overloaded, pragma applies to all of the
2936 -- denoted entities in the same declarative part.
2938 Hom_Id := Def_Id;
2939 while Present (Hom_Id) loop
2940 Def_Id := Get_Base_Subprogram (Hom_Id);
2942 -- Ignore inherited subprograms because the pragma will
2943 -- apply to the parent operation, which is the one called.
2945 if Is_Overloadable (Def_Id)
2946 and then Present (Alias (Def_Id))
2947 then
2948 null;
2950 -- If it is not a subprogram, it must be in an outer
2951 -- scope and pragma does not apply.
2953 elsif not Is_Subprogram (Def_Id)
2954 and then not Is_Generic_Subprogram (Def_Id)
2955 then
2956 null;
2958 -- Verify that the homonym is in the same declarative
2959 -- part (not just the same scope).
2961 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
2962 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
2963 then
2964 exit;
2966 else
2967 Set_Imported (Def_Id);
2969 -- Special processing for Convention_Intrinsic
2971 if C = Convention_Intrinsic then
2973 -- Link_Name argument not allowed for intrinsic
2975 if Present (Arg3)
2976 and then Chars (Arg3) = Name_Link_Name
2977 then
2978 Arg4 := Arg3;
2979 end if;
2981 if Present (Arg4) then
2982 Error_Pragma_Arg
2983 ("Link_Name argument not allowed for " &
2984 "Import Intrinsic",
2985 Arg4);
2986 end if;
2988 Set_Is_Intrinsic_Subprogram (Def_Id);
2990 -- If no external name is present, then check that
2991 -- this is a valid intrinsic subprogram. If an external
2992 -- name is present, then this is handled by the back end.
2994 if No (Arg3) then
2995 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
2996 end if;
2997 end if;
2999 -- All interfaced procedures need an external symbol
3000 -- created for them since they are always referenced
3001 -- from another object file.
3003 Set_Is_Public (Def_Id);
3005 -- Verify that the subprogram does not have a completion
3006 -- through a renaming declaration. For other completions
3007 -- the pragma appears as a too late representation.
3009 declare
3010 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3012 begin
3013 if Present (Decl)
3014 and then Nkind (Decl) = N_Subprogram_Declaration
3015 and then Present (Corresponding_Body (Decl))
3016 and then
3017 Nkind
3018 (Unit_Declaration_Node
3019 (Corresponding_Body (Decl))) =
3020 N_Subprogram_Renaming_Declaration
3021 then
3022 Error_Msg_Sloc := Sloc (Def_Id);
3023 Error_Msg_NE ("cannot import&#," &
3024 " already completed by a renaming",
3025 N, Def_Id);
3026 end if;
3027 end;
3029 Set_Has_Completion (Def_Id);
3030 Process_Interface_Name (Def_Id, Arg3, Arg4);
3031 end if;
3033 if Is_Compilation_Unit (Hom_Id) then
3035 -- Its possible homonyms are not affected by the pragma.
3036 -- Such homonyms might be present in the context of other
3037 -- units being compiled.
3039 exit;
3041 else
3042 Hom_Id := Homonym (Hom_Id);
3043 end if;
3044 end loop;
3046 -- When the convention is Java, we also allow Import to be given
3047 -- for packages, exceptions, and record components.
3049 elsif C = Convention_Java
3050 and then
3051 (Ekind (Def_Id) = E_Package
3052 or else Ekind (Def_Id) = E_Exception
3053 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3054 then
3055 Set_Imported (Def_Id);
3056 Set_Is_Public (Def_Id);
3057 Process_Interface_Name (Def_Id, Arg3, Arg4);
3059 else
3060 Error_Pragma_Arg
3061 ("second argument of pragma% must be object or subprogram",
3062 Arg2);
3063 end if;
3065 -- If this pragma applies to a compilation unit, then the unit,
3066 -- which is a subprogram, does not require (or allow) a body.
3067 -- We also do not need to elaborate imported procedures.
3069 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3070 declare
3071 Cunit : constant Node_Id := Parent (Parent (N));
3072 begin
3073 Set_Body_Required (Cunit, False);
3074 end;
3075 end if;
3076 end Process_Import_Or_Interface;
3078 --------------------
3079 -- Process_Inline --
3080 --------------------
3082 procedure Process_Inline (Active : Boolean) is
3083 Assoc : Node_Id;
3084 Decl : Node_Id;
3085 Subp_Id : Node_Id;
3086 Subp : Entity_Id;
3087 Applies : Boolean;
3088 Effective : Boolean := False;
3090 procedure Make_Inline (Subp : Entity_Id);
3091 -- Subp is the defining unit name of the subprogram
3092 -- declaration. Set the flag, as well as the flag in the
3093 -- corresponding body, if there is one present.
3095 procedure Set_Inline_Flags (Subp : Entity_Id);
3096 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp
3098 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3099 -- Returns True if it can be determined at this stage that inlining
3100 -- is not possible, for examle if the body is available and contains
3101 -- exception handlers, we prevent inlining, since otherwise we can
3102 -- get undefined symbols at link time. This function also emits a
3103 -- warning if front-end inlining is enabled and the pragma appears
3104 -- too late.
3105 -- ??? is business with link symbols still valid, or does it relate
3106 -- to front end ZCX which is being phased out ???
3108 ---------------------------
3109 -- Inlining_Not_Possible --
3110 ---------------------------
3112 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3113 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3114 Stats : Node_Id;
3116 begin
3117 if Nkind (Decl) = N_Subprogram_Body then
3118 Stats := Handled_Statement_Sequence (Decl);
3119 return Present (Exception_Handlers (Stats))
3120 or else Present (At_End_Proc (Stats));
3122 elsif Nkind (Decl) = N_Subprogram_Declaration
3123 and then Present (Corresponding_Body (Decl))
3124 then
3125 if Front_End_Inlining
3126 and then Analyzed (Corresponding_Body (Decl))
3127 then
3128 Error_Msg_N ("pragma appears too late, ignored?", N);
3129 return True;
3131 -- If the subprogram is a renaming as body, the body is
3132 -- just a call to the renamed subprogram, and inlining is
3133 -- trivially possible.
3135 elsif
3136 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
3137 = N_Subprogram_Renaming_Declaration
3138 then
3139 return False;
3141 else
3142 Stats :=
3143 Handled_Statement_Sequence
3144 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3146 return
3147 Present (Exception_Handlers (Stats))
3148 or else Present (At_End_Proc (Stats));
3149 end if;
3151 else
3152 -- If body is not available, assume the best, the check is
3153 -- performed again when compiling enclosing package bodies.
3155 return False;
3156 end if;
3157 end Inlining_Not_Possible;
3159 -----------------
3160 -- Make_Inline --
3161 -----------------
3163 procedure Make_Inline (Subp : Entity_Id) is
3164 Kind : constant Entity_Kind := Ekind (Subp);
3165 Inner_Subp : Entity_Id := Subp;
3167 begin
3168 if Etype (Subp) = Any_Type then
3169 return;
3171 -- If inlining is not possible, for now do not treat as an error
3173 elsif Inlining_Not_Possible (Subp) then
3174 Applies := True;
3175 return;
3177 -- Here we have a candidate for inlining, but we must exclude
3178 -- derived operations. Otherwise we will end up trying to
3179 -- inline a phantom declaration, and the result would be to
3180 -- drag in a body which has no direct inlining associated with
3181 -- it. That would not only be inefficient but would also result
3182 -- in the backend doing cross-unit inlining in cases where it
3183 -- was definitely inappropriate to do so.
3185 -- However, a simple Comes_From_Source test is insufficient,
3186 -- since we do want to allow inlining of generic instances,
3187 -- which also do not come from source. Predefined operators do
3188 -- not come from source but are not inlineable either.
3190 elsif not Comes_From_Source (Subp)
3191 and then not Is_Generic_Instance (Subp)
3192 and then Scope (Subp) /= Standard_Standard
3193 then
3194 Applies := True;
3195 return;
3197 -- The referenced entity must either be the enclosing entity,
3198 -- or an entity declared within the current open scope.
3200 elsif Present (Scope (Subp))
3201 and then Scope (Subp) /= Current_Scope
3202 and then Subp /= Current_Scope
3203 then
3204 Error_Pragma_Arg
3205 ("argument of% must be entity in current scope", Assoc);
3206 return;
3207 end if;
3209 -- Processing for procedure, operator or function.
3210 -- If subprogram is aliased (as for an instance) indicate
3211 -- that the renamed entity (if declared in the same unit)
3212 -- is inlined.
3214 if Is_Subprogram (Subp) then
3215 while Present (Alias (Inner_Subp)) loop
3216 Inner_Subp := Alias (Inner_Subp);
3217 end loop;
3219 if In_Same_Source_Unit (Subp, Inner_Subp) then
3220 Set_Inline_Flags (Inner_Subp);
3222 Decl := Parent (Parent (Inner_Subp));
3224 if Nkind (Decl) = N_Subprogram_Declaration
3225 and then Present (Corresponding_Body (Decl))
3226 then
3227 Set_Inline_Flags (Corresponding_Body (Decl));
3228 end if;
3229 end if;
3231 Applies := True;
3233 -- For a generic subprogram set flag as well, for use at
3234 -- the point of instantiation, to determine whether the
3235 -- body should be generated.
3237 elsif Is_Generic_Subprogram (Subp) then
3238 Set_Inline_Flags (Subp);
3239 Applies := True;
3241 -- Literals are by definition inlined
3243 elsif Kind = E_Enumeration_Literal then
3244 null;
3246 -- Anything else is an error
3248 else
3249 Error_Pragma_Arg
3250 ("expect subprogram name for pragma%", Assoc);
3251 end if;
3252 end Make_Inline;
3254 ----------------------
3255 -- Set_Inline_Flags --
3256 ----------------------
3258 procedure Set_Inline_Flags (Subp : Entity_Id) is
3259 begin
3260 if Active then
3261 Set_Is_Inlined (Subp, True);
3262 end if;
3264 if not Has_Pragma_Inline (Subp) then
3265 Set_Has_Pragma_Inline (Subp);
3266 Set_Next_Rep_Item (N, First_Rep_Item (Subp));
3267 Set_First_Rep_Item (Subp, N);
3268 Effective := True;
3269 end if;
3270 end Set_Inline_Flags;
3272 -- Start of processing for Process_Inline
3274 begin
3275 Check_No_Identifiers;
3276 Check_At_Least_N_Arguments (1);
3278 if Active then
3279 Inline_Processing_Required := True;
3280 end if;
3282 Assoc := Arg1;
3283 while Present (Assoc) loop
3284 Subp_Id := Expression (Assoc);
3285 Analyze (Subp_Id);
3286 Applies := False;
3288 if Is_Entity_Name (Subp_Id) then
3289 Subp := Entity (Subp_Id);
3291 if Subp = Any_Id then
3292 Applies := True;
3294 else
3295 Make_Inline (Subp);
3297 while Present (Homonym (Subp))
3298 and then Scope (Homonym (Subp)) = Current_Scope
3299 loop
3300 Make_Inline (Homonym (Subp));
3301 Subp := Homonym (Subp);
3302 end loop;
3303 end if;
3304 end if;
3306 if not Applies then
3307 Error_Pragma_Arg
3308 ("inappropriate argument for pragma%", Assoc);
3310 elsif not Effective
3311 and then Warn_On_Redundant_Constructs
3312 then
3313 if Inlining_Not_Possible (Subp) then
3314 Error_Msg_NE
3315 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
3316 else
3317 Error_Msg_NE
3318 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
3319 end if;
3320 end if;
3322 Next (Assoc);
3323 end loop;
3324 end Process_Inline;
3326 ----------------------------
3327 -- Process_Interface_Name --
3328 ----------------------------
3330 procedure Process_Interface_Name
3331 (Subprogram_Def : Entity_Id;
3332 Ext_Arg : Node_Id;
3333 Link_Arg : Node_Id)
3335 Ext_Nam : Node_Id;
3336 Link_Nam : Node_Id;
3337 String_Val : String_Id;
3339 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
3340 -- SN is a string literal node for an interface name. This routine
3341 -- performs some minimal checks that the name is reasonable. In
3342 -- particular that no spaces or other obviously incorrect characters
3343 -- appear. This is only a warning, since any characters are allowed.
3345 ----------------------------------
3346 -- Check_Form_Of_Interface_Name --
3347 ----------------------------------
3349 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
3350 S : constant String_Id := Strval (Expr_Value_S (SN));
3351 SL : constant Nat := String_Length (S);
3352 C : Char_Code;
3354 begin
3355 if SL = 0 then
3356 Error_Msg_N ("interface name cannot be null string", SN);
3357 end if;
3359 for J in 1 .. SL loop
3360 C := Get_String_Char (S, J);
3362 if Warn_On_Export_Import
3363 and then (not In_Character_Range (C)
3364 or else Get_Character (C) = ' '
3365 or else Get_Character (C) = ',')
3366 then
3367 Error_Msg_N
3368 ("?interface name contains illegal character", SN);
3369 end if;
3370 end loop;
3371 end Check_Form_Of_Interface_Name;
3373 -- Start of processing for Process_Interface_Name
3375 begin
3376 if No (Link_Arg) then
3377 if No (Ext_Arg) then
3378 return;
3380 elsif Chars (Ext_Arg) = Name_Link_Name then
3381 Ext_Nam := Empty;
3382 Link_Nam := Expression (Ext_Arg);
3384 else
3385 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3386 Ext_Nam := Expression (Ext_Arg);
3387 Link_Nam := Empty;
3388 end if;
3390 else
3391 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3392 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
3393 Ext_Nam := Expression (Ext_Arg);
3394 Link_Nam := Expression (Link_Arg);
3395 end if;
3397 -- Check expressions for external name and link name are static
3399 if Present (Ext_Nam) then
3400 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
3401 Check_Form_Of_Interface_Name (Ext_Nam);
3403 -- Verify that the external name is not the name of a local
3404 -- entity, which would hide the imported one and lead to
3405 -- run-time surprises. The problem can only arise for entities
3406 -- declared in a package body (otherwise the external name is
3407 -- fully qualified and won't conflict).
3409 declare
3410 Nam : Name_Id;
3411 E : Entity_Id;
3412 Par : Node_Id;
3414 begin
3415 if Prag_Id = Pragma_Import then
3416 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
3417 Nam := Name_Find;
3418 E := Entity_Id (Get_Name_Table_Info (Nam));
3420 if Nam /= Chars (Subprogram_Def)
3421 and then Present (E)
3422 and then not Is_Overloadable (E)
3423 and then Is_Immediately_Visible (E)
3424 and then not Is_Imported (E)
3425 and then Ekind (Scope (E)) = E_Package
3426 then
3427 Par := Parent (E);
3429 while Present (Par) loop
3430 if Nkind (Par) = N_Package_Body then
3431 Error_Msg_Sloc := Sloc (E);
3432 Error_Msg_NE
3433 ("imported entity is hidden by & declared#",
3434 Ext_Arg, E);
3435 exit;
3436 end if;
3438 Par := Parent (Par);
3439 end loop;
3440 end if;
3441 end if;
3442 end;
3443 end if;
3445 if Present (Link_Nam) then
3446 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
3447 Check_Form_Of_Interface_Name (Link_Nam);
3448 end if;
3450 -- If there is no link name, just set the external name
3452 if No (Link_Nam) then
3453 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
3455 -- For the Link_Name case, the given literal is preceded by an
3456 -- asterisk, which indicates to GCC that the given name should
3457 -- be taken literally, and in particular that no prepending of
3458 -- underlines should occur, even in systems where this is the
3459 -- normal default.
3461 else
3462 Start_String;
3463 Store_String_Char (Get_Char_Code ('*'));
3464 String_Val := Strval (Expr_Value_S (Link_Nam));
3466 for J in 1 .. String_Length (String_Val) loop
3467 Store_String_Char (Get_String_Char (String_Val, J));
3468 end loop;
3470 Link_Nam :=
3471 Make_String_Literal (Sloc (Link_Nam), End_String);
3472 end if;
3474 Set_Encoded_Interface_Name
3475 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
3476 Check_Duplicated_Export_Name (Link_Nam);
3477 end Process_Interface_Name;
3479 -----------------------------------------
3480 -- Process_Interrupt_Or_Attach_Handler --
3481 -----------------------------------------
3483 procedure Process_Interrupt_Or_Attach_Handler is
3484 Arg1_X : constant Node_Id := Expression (Arg1);
3485 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
3486 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
3488 begin
3489 Set_Is_Interrupt_Handler (Handler_Proc);
3491 -- If the pragma is not associated with a handler procedure
3492 -- within a protected type, then it must be for a nonprotected
3493 -- procedure for the AAMP target, in which case we don't
3494 -- associate a representation item with the procedure's scope.
3496 if Ekind (Proc_Scope) = E_Protected_Type then
3497 if Prag_Id = Pragma_Interrupt_Handler
3498 or else
3499 Prag_Id = Pragma_Attach_Handler
3500 then
3501 Record_Rep_Item (Proc_Scope, N);
3502 end if;
3503 end if;
3504 end Process_Interrupt_Or_Attach_Handler;
3506 --------------------------------------------------
3507 -- Process_Restrictions_Or_Restriction_Warnings --
3508 --------------------------------------------------
3510 -- Note: some of the simple identifier cases were handled in par-prag,
3511 -- but it is harmless (and more straightforward) to simply handle all
3512 -- cases here, even if it means we repeat a bit of work in some cases.
3514 procedure Process_Restrictions_Or_Restriction_Warnings is
3515 Arg : Node_Id;
3516 R_Id : Restriction_Id;
3517 Id : Name_Id;
3518 Expr : Node_Id;
3519 Val : Uint;
3521 procedure Check_Unit_Name (N : Node_Id);
3522 -- Checks unit name parameter for No_Dependence. Returns if it has
3523 -- an appropriate form, otherwise raises pragma argument error.
3525 procedure Set_Warning (R : All_Restrictions);
3526 -- If this is a Restriction_Warnings pragma, set warning flag,
3527 -- otherwise reset the flag.
3529 ---------------------
3530 -- Check_Unit_Name --
3531 ---------------------
3533 procedure Check_Unit_Name (N : Node_Id) is
3534 begin
3535 if Nkind (N) = N_Selected_Component then
3536 Check_Unit_Name (Prefix (N));
3537 Check_Unit_Name (Selector_Name (N));
3539 elsif Nkind (N) = N_Identifier then
3540 return;
3542 else
3543 Error_Pragma_Arg
3544 ("wrong form for unit name for No_Dependence", N);
3545 end if;
3546 end Check_Unit_Name;
3548 -----------------
3549 -- Set_Warning --
3550 -----------------
3552 procedure Set_Warning (R : All_Restrictions) is
3553 begin
3554 if Prag_Id = Pragma_Restriction_Warnings then
3555 Restriction_Warnings (R) := True;
3556 else
3557 Restriction_Warnings (R) := False;
3558 end if;
3559 end Set_Warning;
3561 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
3563 begin
3564 Check_Ada_83_Warning;
3565 Check_At_Least_N_Arguments (1);
3566 Check_Valid_Configuration_Pragma;
3568 Arg := Arg1;
3569 while Present (Arg) loop
3570 Id := Chars (Arg);
3571 Expr := Expression (Arg);
3573 -- Case of no restriction identifier present
3575 if Id = No_Name then
3576 if Nkind (Expr) /= N_Identifier then
3577 Error_Pragma_Arg
3578 ("invalid form for restriction", Arg);
3579 end if;
3581 R_Id :=
3582 Get_Restriction_Id
3583 (Process_Restriction_Synonyms (Expr));
3585 if R_Id not in All_Boolean_Restrictions then
3586 Error_Pragma_Arg
3587 ("invalid restriction identifier", Arg);
3588 end if;
3590 if Implementation_Restriction (R_Id) then
3591 Check_Restriction
3592 (No_Implementation_Restrictions, Arg);
3593 end if;
3595 Set_Restriction (R_Id, N);
3596 Set_Warning (R_Id);
3598 -- A very special case that must be processed here:
3599 -- pragma Restrictions (No_Exceptions) turns off
3600 -- all run-time checking. This is a bit dubious in
3601 -- terms of the formal language definition, but it
3602 -- is what is intended by RM H.4(12).
3604 if R_Id = No_Exceptions then
3605 Scope_Suppress := (others => True);
3606 end if;
3608 -- Case of No_Dependence => unit-name. Note that the parser
3609 -- already made the necessary entry in the No_Dependence table.
3611 elsif Id = Name_No_Dependence then
3612 Check_Unit_Name (Expr);
3614 -- All other cases of restriction identifier present
3616 else
3617 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
3618 Analyze_And_Resolve (Expr, Any_Integer);
3620 if R_Id not in All_Parameter_Restrictions then
3621 Error_Pragma_Arg
3622 ("invalid restriction parameter identifier", Arg);
3624 elsif not Is_OK_Static_Expression (Expr) then
3625 Flag_Non_Static_Expr
3626 ("value must be static expression!", Expr);
3627 raise Pragma_Exit;
3629 elsif not Is_Integer_Type (Etype (Expr))
3630 or else Expr_Value (Expr) < 0
3631 then
3632 Error_Pragma_Arg
3633 ("value must be non-negative integer", Arg);
3635 -- Restriction pragma is active
3637 else
3638 Val := Expr_Value (Expr);
3640 if not UI_Is_In_Int_Range (Val) then
3641 Error_Pragma_Arg
3642 ("pragma ignored, value too large?", Arg);
3643 else
3644 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
3645 Set_Warning (R_Id);
3646 end if;
3647 end if;
3648 end if;
3650 Next (Arg);
3651 end loop;
3652 end Process_Restrictions_Or_Restriction_Warnings;
3654 ---------------------------------
3655 -- Process_Suppress_Unsuppress --
3656 ---------------------------------
3658 -- Note: this procedure makes entries in the check suppress data
3659 -- structures managed by Sem. See spec of package Sem for full
3660 -- details on how we handle recording of check suppression.
3662 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
3663 C : Check_Id;
3664 E_Id : Node_Id;
3665 E : Entity_Id;
3667 In_Package_Spec : constant Boolean :=
3668 (Ekind (Current_Scope) = E_Package
3669 or else
3670 Ekind (Current_Scope) = E_Generic_Package)
3671 and then not In_Package_Body (Current_Scope);
3673 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
3674 -- Used to suppress a single check on the given entity
3676 --------------------------------
3677 -- Suppress_Unsuppress_Echeck --
3678 --------------------------------
3680 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
3681 ESR : constant Entity_Check_Suppress_Record :=
3682 (Entity => E,
3683 Check => C,
3684 Suppress => Suppress_Case);
3686 begin
3687 Set_Checks_May_Be_Suppressed (E);
3689 if In_Package_Spec then
3690 Global_Entity_Suppress.Append (ESR);
3691 else
3692 Local_Entity_Suppress.Append (ESR);
3693 end if;
3695 -- If this is a first subtype, and the base type is distinct,
3696 -- then also set the suppress flags on the base type.
3698 if Is_First_Subtype (E)
3699 and then Etype (E) /= E
3700 then
3701 Suppress_Unsuppress_Echeck (Etype (E), C);
3702 end if;
3703 end Suppress_Unsuppress_Echeck;
3705 -- Start of processing for Process_Suppress_Unsuppress
3707 begin
3708 -- Suppress/Unsuppress can appear as a configuration pragma,
3709 -- or in a declarative part or a package spec (RM 11.5(5))
3711 if not Is_Configuration_Pragma then
3712 Check_Is_In_Decl_Part_Or_Package_Spec;
3713 end if;
3715 Check_At_Least_N_Arguments (1);
3716 Check_At_Most_N_Arguments (2);
3717 Check_No_Identifier (Arg1);
3718 Check_Arg_Is_Identifier (Arg1);
3720 if not Is_Check_Name (Chars (Expression (Arg1))) then
3721 Error_Pragma_Arg
3722 ("argument of pragma% is not valid check name", Arg1);
3723 else
3724 C := Get_Check_Id (Chars (Expression (Arg1)));
3725 end if;
3727 if Arg_Count = 1 then
3729 -- Make an entry in the local scope suppress table. This is the
3730 -- table that directly shows the current value of the scope
3731 -- suppress check for any check id value.
3733 if C = All_Checks then
3734 for J in Scope_Suppress'Range loop
3735 Scope_Suppress (J) := Suppress_Case;
3736 end loop;
3737 else
3738 Scope_Suppress (C) := Suppress_Case;
3739 end if;
3741 -- Also make an entry in the Local_Entity_Suppress table. See
3742 -- extended description in the package spec of Sem for details.
3744 Local_Entity_Suppress.Append
3745 ((Entity => Empty,
3746 Check => C,
3747 Suppress => Suppress_Case));
3749 -- Case of two arguments present, where the check is
3750 -- suppressed for a specified entity (given as the second
3751 -- argument of the pragma)
3753 else
3754 Check_Optional_Identifier (Arg2, Name_On);
3755 E_Id := Expression (Arg2);
3756 Analyze (E_Id);
3758 if not Is_Entity_Name (E_Id) then
3759 Error_Pragma_Arg
3760 ("second argument of pragma% must be entity name", Arg2);
3761 end if;
3763 E := Entity (E_Id);
3765 if E = Any_Id then
3766 return;
3767 end if;
3769 -- Enforce RM 11.5(7) which requires that for a pragma that
3770 -- appears within a package spec, the named entity must be
3771 -- within the package spec. We allow the package name itself
3772 -- to be mentioned since that makes sense, although it is not
3773 -- strictly allowed by 11.5(7).
3775 if In_Package_Spec
3776 and then E /= Current_Scope
3777 and then Scope (E) /= Current_Scope
3778 then
3779 Error_Pragma_Arg
3780 ("entity in pragma% is not in package spec ('R'M 11.5(7))",
3781 Arg2);
3782 end if;
3784 -- Loop through homonyms. As noted below, in the case of a package
3785 -- spec, only homonyms within the package spec are considered.
3787 loop
3788 Suppress_Unsuppress_Echeck (E, C);
3790 if Is_Generic_Instance (E)
3791 and then Is_Subprogram (E)
3792 and then Present (Alias (E))
3793 then
3794 Suppress_Unsuppress_Echeck (Alias (E), C);
3795 end if;
3797 -- Move to next homonym
3799 E := Homonym (E);
3800 exit when No (E);
3802 -- If we are within a package specification, the
3803 -- pragma only applies to homonyms in the same scope.
3805 exit when In_Package_Spec
3806 and then Scope (E) /= Current_Scope;
3807 end loop;
3808 end if;
3809 end Process_Suppress_Unsuppress;
3811 ------------------
3812 -- Set_Exported --
3813 ------------------
3815 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
3816 begin
3817 if Is_Imported (E) then
3818 Error_Pragma_Arg
3819 ("cannot export entity& that was previously imported", Arg);
3821 elsif Present (Address_Clause (E)) then
3822 Error_Pragma_Arg
3823 ("cannot export entity& that has an address clause", Arg);
3824 end if;
3826 Set_Is_Exported (E);
3828 -- Generate a reference for entity explicitly, because the
3829 -- identifier may be overloaded and name resolution will not
3830 -- generate one.
3832 Generate_Reference (E, Arg);
3834 -- Deal with exporting non-library level entity
3836 if not Is_Library_Level_Entity (E) then
3838 -- Not allowed at all for subprograms
3840 if Is_Subprogram (E) then
3841 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
3843 -- Otherwise set public and statically allocated
3845 else
3846 Set_Is_Public (E);
3847 Set_Is_Statically_Allocated (E);
3849 -- Warn if the corresponding W flag is set and the pragma
3850 -- comes from source. The latter may not be true e.g. on
3851 -- VMS where we expand export pragmas for exception codes
3852 -- associated with imported or exported exceptions. We do
3853 -- not want to generate a warning for something that the
3854 -- user did not write.
3856 if Warn_On_Export_Import
3857 and then Comes_From_Source (Arg)
3858 then
3859 Error_Msg_NE
3860 ("?& has been made static as a result of Export", Arg, E);
3861 Error_Msg_N
3862 ("\this usage is non-standard and non-portable", Arg);
3863 end if;
3864 end if;
3865 end if;
3867 if Warn_On_Export_Import and then Is_Type (E) then
3868 Error_Msg_NE
3869 ("exporting a type has no effect?", Arg, E);
3870 end if;
3872 if Warn_On_Export_Import and Inside_A_Generic then
3873 Error_Msg_NE
3874 ("all instances of& will have the same external name?", Arg, E);
3875 end if;
3876 end Set_Exported;
3878 ----------------------------------------------
3879 -- Set_Extended_Import_Export_External_Name --
3880 ----------------------------------------------
3882 procedure Set_Extended_Import_Export_External_Name
3883 (Internal_Ent : Entity_Id;
3884 Arg_External : Node_Id)
3886 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
3887 New_Name : Node_Id;
3889 begin
3890 if No (Arg_External) then
3891 return;
3892 end if;
3894 Check_Arg_Is_External_Name (Arg_External);
3896 if Nkind (Arg_External) = N_String_Literal then
3897 if String_Length (Strval (Arg_External)) = 0 then
3898 return;
3899 else
3900 New_Name := Adjust_External_Name_Case (Arg_External);
3901 end if;
3903 elsif Nkind (Arg_External) = N_Identifier then
3904 New_Name := Get_Default_External_Name (Arg_External);
3906 -- Check_Arg_Is_External_Name should let through only
3907 -- identifiers and string literals or static string
3908 -- expressions (which are folded to string literals).
3910 else
3911 raise Program_Error;
3912 end if;
3914 -- If we already have an external name set (by a prior normal
3915 -- Import or Export pragma), then the external names must match
3917 if Present (Interface_Name (Internal_Ent)) then
3918 Check_Matching_Internal_Names : declare
3919 S1 : constant String_Id := Strval (Old_Name);
3920 S2 : constant String_Id := Strval (New_Name);
3922 procedure Mismatch;
3923 -- Called if names do not match
3925 --------------
3926 -- Mismatch --
3927 --------------
3929 procedure Mismatch is
3930 begin
3931 Error_Msg_Sloc := Sloc (Old_Name);
3932 Error_Pragma_Arg
3933 ("external name does not match that given #",
3934 Arg_External);
3935 end Mismatch;
3937 -- Start of processing for Check_Matching_Internal_Names
3939 begin
3940 if String_Length (S1) /= String_Length (S2) then
3941 Mismatch;
3943 else
3944 for J in 1 .. String_Length (S1) loop
3945 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
3946 Mismatch;
3947 end if;
3948 end loop;
3949 end if;
3950 end Check_Matching_Internal_Names;
3952 -- Otherwise set the given name
3954 else
3955 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
3956 Check_Duplicated_Export_Name (New_Name);
3957 end if;
3958 end Set_Extended_Import_Export_External_Name;
3960 ------------------
3961 -- Set_Imported --
3962 ------------------
3964 procedure Set_Imported (E : Entity_Id) is
3965 begin
3966 Error_Msg_Sloc := Sloc (E);
3968 if Is_Exported (E) or else Is_Imported (E) then
3969 Error_Msg_NE ("import of& declared# not allowed", N, E);
3971 if Is_Exported (E) then
3972 Error_Msg_N ("\entity was previously exported", N);
3973 else
3974 Error_Msg_N ("\entity was previously imported", N);
3975 end if;
3977 Error_Pragma ("\(pragma% applies to all previous entities)");
3979 else
3980 Set_Is_Imported (E);
3982 -- If the entity is an object that is not at the library
3983 -- level, then it is statically allocated. We do not worry
3984 -- about objects with address clauses in this context since
3985 -- they are not really imported in the linker sense.
3987 if Is_Object (E)
3988 and then not Is_Library_Level_Entity (E)
3989 and then No (Address_Clause (E))
3990 then
3991 Set_Is_Statically_Allocated (E);
3992 end if;
3993 end if;
3994 end Set_Imported;
3996 -------------------------
3997 -- Set_Mechanism_Value --
3998 -------------------------
4000 -- Note: the mechanism name has not been analyzed (and cannot indeed
4001 -- be analyzed, since it is semantic nonsense), so we get it in the
4002 -- exact form created by the parser.
4004 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4005 Class : Node_Id;
4006 Param : Node_Id;
4008 procedure Bad_Class;
4009 -- Signal bad descriptor class name
4011 procedure Bad_Mechanism;
4012 -- Signal bad mechanism name
4014 ---------------
4015 -- Bad_Class --
4016 ---------------
4018 procedure Bad_Class is
4019 begin
4020 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4021 end Bad_Class;
4023 -------------------------
4024 -- Bad_Mechanism_Value --
4025 -------------------------
4027 procedure Bad_Mechanism is
4028 begin
4029 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4030 end Bad_Mechanism;
4032 -- Start of processing for Set_Mechanism_Value
4034 begin
4035 if Mechanism (Ent) /= Default_Mechanism then
4036 Error_Msg_NE
4037 ("mechanism for & has already been set", Mech_Name, Ent);
4038 end if;
4040 -- MECHANISM_NAME ::= value | reference | descriptor
4042 if Nkind (Mech_Name) = N_Identifier then
4043 if Chars (Mech_Name) = Name_Value then
4044 Set_Mechanism (Ent, By_Copy);
4045 return;
4047 elsif Chars (Mech_Name) = Name_Reference then
4048 Set_Mechanism (Ent, By_Reference);
4049 return;
4051 elsif Chars (Mech_Name) = Name_Descriptor then
4052 Check_VMS (Mech_Name);
4053 Set_Mechanism (Ent, By_Descriptor);
4054 return;
4056 elsif Chars (Mech_Name) = Name_Copy then
4057 Error_Pragma_Arg
4058 ("bad mechanism name, Value assumed", Mech_Name);
4060 else
4061 Bad_Mechanism;
4062 end if;
4064 -- MECHANISM_NAME ::= descriptor (CLASS_NAME)
4065 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4067 -- Note: this form is parsed as an indexed component
4069 elsif Nkind (Mech_Name) = N_Indexed_Component then
4070 Class := First (Expressions (Mech_Name));
4072 if Nkind (Prefix (Mech_Name)) /= N_Identifier
4073 or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
4074 or else Present (Next (Class))
4075 then
4076 Bad_Mechanism;
4077 end if;
4079 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
4080 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4082 -- Note: this form is parsed as a function call
4084 elsif Nkind (Mech_Name) = N_Function_Call then
4086 Param := First (Parameter_Associations (Mech_Name));
4088 if Nkind (Name (Mech_Name)) /= N_Identifier
4089 or else Chars (Name (Mech_Name)) /= Name_Descriptor
4090 or else Present (Next (Param))
4091 or else No (Selector_Name (Param))
4092 or else Chars (Selector_Name (Param)) /= Name_Class
4093 then
4094 Bad_Mechanism;
4095 else
4096 Class := Explicit_Actual_Parameter (Param);
4097 end if;
4099 else
4100 Bad_Mechanism;
4101 end if;
4103 -- Fall through here with Class set to descriptor class name
4105 Check_VMS (Mech_Name);
4107 if Nkind (Class) /= N_Identifier then
4108 Bad_Class;
4110 elsif Chars (Class) = Name_UBS then
4111 Set_Mechanism (Ent, By_Descriptor_UBS);
4113 elsif Chars (Class) = Name_UBSB then
4114 Set_Mechanism (Ent, By_Descriptor_UBSB);
4116 elsif Chars (Class) = Name_UBA then
4117 Set_Mechanism (Ent, By_Descriptor_UBA);
4119 elsif Chars (Class) = Name_S then
4120 Set_Mechanism (Ent, By_Descriptor_S);
4122 elsif Chars (Class) = Name_SB then
4123 Set_Mechanism (Ent, By_Descriptor_SB);
4125 elsif Chars (Class) = Name_A then
4126 Set_Mechanism (Ent, By_Descriptor_A);
4128 elsif Chars (Class) = Name_NCA then
4129 Set_Mechanism (Ent, By_Descriptor_NCA);
4131 else
4132 Bad_Class;
4133 end if;
4134 end Set_Mechanism_Value;
4136 ---------------------------
4137 -- Set_Ravenscar_Profile --
4138 ---------------------------
4140 -- The tasks to be done here are
4142 -- Set required policies
4144 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4145 -- pragma Locking_Policy (Ceiling_Locking)
4147 -- Set Detect_Blocking mode
4149 -- Set required restrictions (see System.Rident for detailed list)
4151 procedure Set_Ravenscar_Profile (N : Node_Id) is
4152 begin
4153 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4155 if Task_Dispatching_Policy /= ' '
4156 and then Task_Dispatching_Policy /= 'F'
4157 then
4158 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4159 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4161 -- Set the FIFO_Within_Priorities policy, but always
4162 -- preserve System_Location since we like the error
4163 -- message with the run time name.
4165 else
4166 Task_Dispatching_Policy := 'F';
4168 if Task_Dispatching_Policy_Sloc /= System_Location then
4169 Task_Dispatching_Policy_Sloc := Loc;
4170 end if;
4171 end if;
4173 -- pragma Locking_Policy (Ceiling_Locking)
4175 if Locking_Policy /= ' '
4176 and then Locking_Policy /= 'C'
4177 then
4178 Error_Msg_Sloc := Locking_Policy_Sloc;
4179 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4181 -- Set the Ceiling_Locking policy, but always preserve
4182 -- System_Location since we like the error message with the
4183 -- run time name.
4185 else
4186 Locking_Policy := 'C';
4188 if Locking_Policy_Sloc /= System_Location then
4189 Locking_Policy_Sloc := Loc;
4190 end if;
4191 end if;
4193 -- pragma Detect_Blocking
4195 Detect_Blocking := True;
4197 -- Set the corresponding restrictions
4199 Set_Profile_Restrictions (Ravenscar, N, Warn => False);
4200 end Set_Ravenscar_Profile;
4202 -- Start of processing for Analyze_Pragma
4204 begin
4205 if not Is_Pragma_Name (Chars (N)) then
4206 if Warn_On_Unrecognized_Pragma then
4207 Error_Pragma ("unrecognized pragma%!?");
4208 else
4209 raise Pragma_Exit;
4210 end if;
4211 else
4212 Prag_Id := Get_Pragma_Id (Chars (N));
4213 end if;
4215 -- Preset arguments
4217 Arg1 := Empty;
4218 Arg2 := Empty;
4219 Arg3 := Empty;
4220 Arg4 := Empty;
4222 if Present (Pragma_Argument_Associations (N)) then
4223 Arg1 := First (Pragma_Argument_Associations (N));
4225 if Present (Arg1) then
4226 Arg2 := Next (Arg1);
4228 if Present (Arg2) then
4229 Arg3 := Next (Arg2);
4231 if Present (Arg3) then
4232 Arg4 := Next (Arg3);
4233 end if;
4234 end if;
4235 end if;
4236 end if;
4238 -- Count number of arguments
4240 declare
4241 Arg_Node : Node_Id;
4242 begin
4243 Arg_Count := 0;
4244 Arg_Node := Arg1;
4245 while Present (Arg_Node) loop
4246 Arg_Count := Arg_Count + 1;
4247 Next (Arg_Node);
4248 end loop;
4249 end;
4251 -- An enumeration type defines the pragmas that are supported by the
4252 -- implementation. Get_Pragma_Id (in package Prag) transorms a name
4253 -- into the corresponding enumeration value for the following case.
4255 case Prag_Id is
4257 -----------------
4258 -- Abort_Defer --
4259 -----------------
4261 -- pragma Abort_Defer;
4263 when Pragma_Abort_Defer =>
4264 GNAT_Pragma;
4265 Check_Arg_Count (0);
4267 -- The only required semantic processing is to check the
4268 -- placement. This pragma must appear at the start of the
4269 -- statement sequence of a handled sequence of statements.
4271 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
4272 or else N /= First (Statements (Parent (N)))
4273 then
4274 Pragma_Misplaced;
4275 end if;
4277 ------------
4278 -- Ada_83 --
4279 ------------
4281 -- pragma Ada_83;
4283 -- Note: this pragma also has some specific processing in Par.Prag
4284 -- because we want to set the Ada version mode during parsing.
4286 when Pragma_Ada_83 =>
4287 GNAT_Pragma;
4288 Ada_Version := Ada_83;
4289 Check_Arg_Count (0);
4291 ------------
4292 -- Ada_95 --
4293 ------------
4295 -- pragma Ada_95;
4297 -- Note: this pragma also has some specific processing in Par.Prag
4298 -- because we want to set the Ada 83 version mode during parsing.
4300 when Pragma_Ada_95 =>
4301 GNAT_Pragma;
4302 Ada_Version := Ada_95;
4303 Check_Arg_Count (0);
4305 ------------
4306 -- Ada_05 --
4307 ------------
4309 -- pragma Ada_05;
4310 -- pragma Ada_05 (LOCAL_NAME);
4312 -- Note: this pragma also has some specific processing in Par.Prag
4313 -- because we want to set the Ada 2005 version mode during parsing.
4315 when Pragma_Ada_05 => declare
4316 E_Id : Node_Id;
4318 begin
4319 GNAT_Pragma;
4321 if Arg_Count = 1 then
4322 Check_Arg_Is_Local_Name (Arg1);
4323 E_Id := Expression (Arg1);
4325 if Etype (E_Id) = Any_Type then
4326 return;
4327 end if;
4329 Set_Is_Ada_2005 (Entity (E_Id));
4331 else
4332 Ada_Version := Ada_05;
4333 Check_Arg_Count (0);
4334 end if;
4335 end;
4337 ----------------------
4338 -- All_Calls_Remote --
4339 ----------------------
4341 -- pragma All_Calls_Remote [(library_package_NAME)];
4343 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
4344 Lib_Entity : Entity_Id;
4346 begin
4347 Check_Ada_83_Warning;
4348 Check_Valid_Library_Unit_Pragma;
4350 if Nkind (N) = N_Null_Statement then
4351 return;
4352 end if;
4354 Lib_Entity := Find_Lib_Unit_Name;
4356 -- This pragma should only apply to a RCI unit (RM E.2.3(23)).
4358 if Present (Lib_Entity)
4359 and then not Debug_Flag_U
4360 then
4361 if not Is_Remote_Call_Interface (Lib_Entity) then
4362 Error_Pragma ("pragma% only apply to rci unit");
4364 -- Set flag for entity of the library unit
4366 else
4367 Set_Has_All_Calls_Remote (Lib_Entity);
4368 end if;
4370 end if;
4371 end All_Calls_Remote;
4373 --------------
4374 -- Annotate --
4375 --------------
4377 -- pragma Annotate (IDENTIFIER {, ARG});
4378 -- ARG ::= NAME | EXPRESSION
4380 when Pragma_Annotate => Annotate : begin
4381 GNAT_Pragma;
4382 Check_At_Least_N_Arguments (1);
4383 Check_Arg_Is_Identifier (Arg1);
4385 declare
4386 Arg : Node_Id := Arg2;
4387 Exp : Node_Id;
4389 begin
4390 while Present (Arg) loop
4391 Exp := Expression (Arg);
4392 Analyze (Exp);
4394 if Is_Entity_Name (Exp) then
4395 null;
4397 elsif Nkind (Exp) = N_String_Literal then
4398 Resolve (Exp, Standard_String);
4400 elsif Is_Overloaded (Exp) then
4401 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
4403 else
4404 Resolve (Exp);
4405 end if;
4407 Next (Arg);
4408 end loop;
4409 end;
4410 end Annotate;
4412 ------------
4413 -- Assert --
4414 ------------
4416 -- pragma Assert (Boolean_EXPRESSION [, static_string_EXPRESSION]);
4418 when Pragma_Assert =>
4419 GNAT_Pragma;
4420 Check_No_Identifiers;
4422 if Arg_Count > 1 then
4423 Check_Arg_Count (2);
4424 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4425 end if;
4427 -- If expansion is active and assertions are inactive, then
4428 -- we rewrite the Assertion as:
4430 -- if False and then condition then
4431 -- null;
4432 -- end if;
4434 -- The reason we do this rewriting during semantic analysis
4435 -- rather than as part of normal expansion is that we cannot
4436 -- analyze and expand the code for the boolean expression
4437 -- directly, or it may cause insertion of actions that would
4438 -- escape the attempt to suppress the assertion code.
4440 if Expander_Active and not Assertions_Enabled then
4441 Rewrite (N,
4442 Make_If_Statement (Loc,
4443 Condition =>
4444 Make_And_Then (Loc,
4445 Left_Opnd => New_Occurrence_Of (Standard_False, Loc),
4446 Right_Opnd => Get_Pragma_Arg (Arg1)),
4447 Then_Statements => New_List (
4448 Make_Null_Statement (Loc))));
4450 Analyze (N);
4452 -- Otherwise (if assertions are enabled, or if we are not
4453 -- operating with expansion active), then we just analyze
4454 -- and resolve the expression.
4456 else
4457 Analyze_And_Resolve (Expression (Arg1), Any_Boolean);
4458 end if;
4460 ---------------
4461 -- AST_Entry --
4462 ---------------
4464 -- pragma AST_Entry (entry_IDENTIFIER);
4466 when Pragma_AST_Entry => AST_Entry : declare
4467 Ent : Node_Id;
4469 begin
4470 GNAT_Pragma;
4471 Check_VMS (N);
4472 Check_Arg_Count (1);
4473 Check_No_Identifiers;
4474 Check_Arg_Is_Local_Name (Arg1);
4475 Ent := Entity (Expression (Arg1));
4477 -- Note: the implementation of the AST_Entry pragma could handle
4478 -- the entry family case fine, but for now we are consistent with
4479 -- the DEC rules, and do not allow the pragma, which of course
4480 -- has the effect of also forbidding the attribute.
4482 if Ekind (Ent) /= E_Entry then
4483 Error_Pragma_Arg
4484 ("pragma% argument must be simple entry name", Arg1);
4486 elsif Is_AST_Entry (Ent) then
4487 Error_Pragma_Arg
4488 ("duplicate % pragma for entry", Arg1);
4490 elsif Has_Homonym (Ent) then
4491 Error_Pragma_Arg
4492 ("pragma% argument cannot specify overloaded entry", Arg1);
4494 else
4495 declare
4496 FF : constant Entity_Id := First_Formal (Ent);
4498 begin
4499 if Present (FF) then
4500 if Present (Next_Formal (FF)) then
4501 Error_Pragma_Arg
4502 ("entry for pragma% can have only one argument",
4503 Arg1);
4505 elsif Parameter_Mode (FF) /= E_In_Parameter then
4506 Error_Pragma_Arg
4507 ("entry parameter for pragma% must have mode IN",
4508 Arg1);
4509 end if;
4510 end if;
4511 end;
4513 Set_Is_AST_Entry (Ent);
4514 end if;
4515 end AST_Entry;
4517 ------------------
4518 -- Asynchronous --
4519 ------------------
4521 -- pragma Asynchronous (LOCAL_NAME);
4523 when Pragma_Asynchronous => Asynchronous : declare
4524 Nm : Entity_Id;
4525 C_Ent : Entity_Id;
4526 L : List_Id;
4527 S : Node_Id;
4528 N : Node_Id;
4529 Formal : Entity_Id;
4531 procedure Process_Async_Pragma;
4532 -- Common processing for procedure and access-to-procedure case
4534 --------------------------
4535 -- Process_Async_Pragma --
4536 --------------------------
4538 procedure Process_Async_Pragma is
4539 begin
4540 if not Present (L) then
4541 Set_Is_Asynchronous (Nm);
4542 return;
4543 end if;
4545 -- The formals should be of mode IN (RM E.4.1(6))
4547 S := First (L);
4548 while Present (S) loop
4549 Formal := Defining_Identifier (S);
4551 if Nkind (Formal) = N_Defining_Identifier
4552 and then Ekind (Formal) /= E_In_Parameter
4553 then
4554 Error_Pragma_Arg
4555 ("pragma% procedure can only have IN parameter",
4556 Arg1);
4557 end if;
4559 Next (S);
4560 end loop;
4562 Set_Is_Asynchronous (Nm);
4563 end Process_Async_Pragma;
4565 -- Start of processing for pragma Asynchronous
4567 begin
4568 Check_Ada_83_Warning;
4569 Check_No_Identifiers;
4570 Check_Arg_Count (1);
4571 Check_Arg_Is_Local_Name (Arg1);
4573 if Debug_Flag_U then
4574 return;
4575 end if;
4577 C_Ent := Cunit_Entity (Current_Sem_Unit);
4578 Analyze (Expression (Arg1));
4579 Nm := Entity (Expression (Arg1));
4581 if not Is_Remote_Call_Interface (C_Ent)
4582 and then not Is_Remote_Types (C_Ent)
4583 then
4584 -- This pragma should only appear in an RCI or Remote Types
4585 -- unit (RM E.4.1(4))
4587 Error_Pragma
4588 ("pragma% not in Remote_Call_Interface or " &
4589 "Remote_Types unit");
4590 end if;
4592 if Ekind (Nm) = E_Procedure
4593 and then Nkind (Parent (Nm)) = N_Procedure_Specification
4594 then
4595 if not Is_Remote_Call_Interface (Nm) then
4596 Error_Pragma_Arg
4597 ("pragma% cannot be applied on non-remote procedure",
4598 Arg1);
4599 end if;
4601 L := Parameter_Specifications (Parent (Nm));
4602 Process_Async_Pragma;
4603 return;
4605 elsif Ekind (Nm) = E_Function then
4606 Error_Pragma_Arg
4607 ("pragma% cannot be applied to function", Arg1);
4609 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
4611 if Is_Record_Type (Nm) then
4612 -- A record type that is the Equivalent_Type for
4613 -- a remote access-to-subprogram type.
4615 N := Declaration_Node (Corresponding_Remote_Type (Nm));
4617 else
4618 -- A non-expanded RAS type (case where distribution is
4619 -- not enabled).
4621 N := Declaration_Node (Nm);
4622 end if;
4624 if Nkind (N) = N_Full_Type_Declaration
4625 and then Nkind (Type_Definition (N)) =
4626 N_Access_Procedure_Definition
4627 then
4628 L := Parameter_Specifications (Type_Definition (N));
4629 Process_Async_Pragma;
4631 if Is_Asynchronous (Nm)
4632 and then Expander_Active
4633 and then Get_PCS_Name /= Name_No_DSA
4634 then
4635 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
4636 end if;
4638 else
4639 Error_Pragma_Arg
4640 ("pragma% cannot reference access-to-function type",
4641 Arg1);
4642 end if;
4644 -- Only other possibility is Access-to-class-wide type
4646 elsif Is_Access_Type (Nm)
4647 and then Is_Class_Wide_Type (Designated_Type (Nm))
4648 then
4649 Check_First_Subtype (Arg1);
4650 Set_Is_Asynchronous (Nm);
4651 if Expander_Active then
4652 RACW_Type_Is_Asynchronous (Nm);
4653 end if;
4655 else
4656 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
4657 end if;
4658 end Asynchronous;
4660 ------------
4661 -- Atomic --
4662 ------------
4664 -- pragma Atomic (LOCAL_NAME);
4666 when Pragma_Atomic =>
4667 Process_Atomic_Shared_Volatile;
4669 -----------------------
4670 -- Atomic_Components --
4671 -----------------------
4673 -- pragma Atomic_Components (array_LOCAL_NAME);
4675 -- This processing is shared by Volatile_Components
4677 when Pragma_Atomic_Components |
4678 Pragma_Volatile_Components =>
4680 Atomic_Components : declare
4681 E_Id : Node_Id;
4682 E : Entity_Id;
4683 D : Node_Id;
4684 K : Node_Kind;
4686 begin
4687 Check_Ada_83_Warning;
4688 Check_No_Identifiers;
4689 Check_Arg_Count (1);
4690 Check_Arg_Is_Local_Name (Arg1);
4691 E_Id := Expression (Arg1);
4693 if Etype (E_Id) = Any_Type then
4694 return;
4695 end if;
4697 E := Entity (E_Id);
4699 if Rep_Item_Too_Early (E, N)
4700 or else
4701 Rep_Item_Too_Late (E, N)
4702 then
4703 return;
4704 end if;
4706 D := Declaration_Node (E);
4707 K := Nkind (D);
4709 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
4710 or else
4711 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
4712 and then Nkind (D) = N_Object_Declaration
4713 and then Nkind (Object_Definition (D)) =
4714 N_Constrained_Array_Definition)
4715 then
4716 -- The flag is set on the object, or on the base type
4718 if Nkind (D) /= N_Object_Declaration then
4719 E := Base_Type (E);
4720 end if;
4722 Set_Has_Volatile_Components (E);
4724 if Prag_Id = Pragma_Atomic_Components then
4725 Set_Has_Atomic_Components (E);
4727 if Is_Packed (E) then
4728 Set_Is_Packed (E, False);
4730 Error_Pragma_Arg
4731 ("?Pack canceled, cannot pack atomic components",
4732 Arg1);
4733 end if;
4734 end if;
4736 else
4737 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
4738 end if;
4739 end Atomic_Components;
4741 --------------------
4742 -- Attach_Handler --
4743 --------------------
4745 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
4747 when Pragma_Attach_Handler =>
4748 Check_Ada_83_Warning;
4749 Check_No_Identifiers;
4750 Check_Arg_Count (2);
4752 if No_Run_Time_Mode then
4753 Error_Msg_CRT ("Attach_Handler pragma", N);
4754 else
4755 Check_Interrupt_Or_Attach_Handler;
4757 -- The expression that designates the attribute may
4758 -- depend on a discriminant, and is therefore a per-
4759 -- object expression, to be expanded in the init proc.
4760 -- If expansion is enabled, perform semantic checks
4761 -- on a copy only.
4763 if Expander_Active then
4764 declare
4765 Temp : constant Node_Id :=
4766 New_Copy_Tree (Expression (Arg2));
4767 begin
4768 Set_Parent (Temp, N);
4769 Pre_Analyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
4770 end;
4772 else
4773 Analyze (Expression (Arg2));
4774 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
4775 end if;
4777 Process_Interrupt_Or_Attach_Handler;
4778 end if;
4780 --------------------
4781 -- C_Pass_By_Copy --
4782 --------------------
4784 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
4786 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
4787 Arg : Node_Id;
4788 Val : Uint;
4790 begin
4791 GNAT_Pragma;
4792 Check_Valid_Configuration_Pragma;
4793 Check_Arg_Count (1);
4794 Check_Optional_Identifier (Arg1, "max_size");
4796 Arg := Expression (Arg1);
4797 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
4799 Val := Expr_Value (Arg);
4801 if Val <= 0 then
4802 Error_Pragma_Arg
4803 ("maximum size for pragma% must be positive", Arg1);
4805 elsif UI_Is_In_Int_Range (Val) then
4806 Default_C_Record_Mechanism := UI_To_Int (Val);
4808 -- If a giant value is given, Int'Last will do well enough.
4809 -- If sometime someone complains that a record larger than
4810 -- two gigabytes is not copied, we will worry about it then!
4812 else
4813 Default_C_Record_Mechanism := Mechanism_Type'Last;
4814 end if;
4815 end C_Pass_By_Copy;
4817 -------------
4818 -- Comment --
4819 -------------
4821 -- pragma Comment (static_string_EXPRESSION)
4823 -- Processing for pragma Comment shares the circuitry for
4824 -- pragma Ident. The only differences are that Ident enforces
4825 -- a limit of 31 characters on its argument, and also enforces
4826 -- limitations on placement for DEC compatibility. Pragma
4827 -- Comment shares neither of these restrictions.
4829 -------------------
4830 -- Common_Object --
4831 -------------------
4833 -- pragma Common_Object (
4834 -- [Internal =>] LOCAL_NAME,
4835 -- [, [External =>] EXTERNAL_SYMBOL]
4836 -- [, [Size =>] EXTERNAL_SYMBOL]);
4838 -- Processing for this pragma is shared with Psect_Object
4840 --------------------------
4841 -- Compile_Time_Warning --
4842 --------------------------
4844 -- pragma Compile_Time_Warning
4845 -- (boolean_EXPRESSION, static_string_EXPRESSION);
4847 when Pragma_Compile_Time_Warning => Compile_Time_Warning : declare
4848 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
4850 begin
4851 GNAT_Pragma;
4852 Check_Arg_Count (2);
4853 Check_No_Identifiers;
4854 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4855 Analyze_And_Resolve (Arg1x, Standard_Boolean);
4857 if Compile_Time_Known_Value (Arg1x) then
4858 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
4859 String_To_Name_Buffer (Strval (Get_Pragma_Arg (Arg2)));
4860 Add_Char_To_Name_Buffer ('?');
4862 declare
4863 Msg : String (1 .. Name_Len) :=
4864 Name_Buffer (1 .. Name_Len);
4866 B : Natural;
4868 begin
4869 -- This loop looks for multiple lines separated by
4870 -- ASCII.LF and breaks them into continuation error
4871 -- messages marked with the usual back slash.
4873 B := 1;
4874 for S in 2 .. Msg'Length - 1 loop
4875 if Msg (S) = ASCII.LF then
4876 Msg (S) := '?';
4877 Error_Msg_N (Msg (B .. S), Arg1);
4878 B := S;
4879 Msg (B) := '\';
4880 end if;
4881 end loop;
4883 Error_Msg_N (Msg (B .. Msg'Length), Arg1);
4884 end;
4885 end if;
4886 end if;
4887 end Compile_Time_Warning;
4889 ----------------------------
4890 -- Complex_Representation --
4891 ----------------------------
4893 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
4895 when Pragma_Complex_Representation => Complex_Representation : declare
4896 E_Id : Entity_Id;
4897 E : Entity_Id;
4898 Ent : Entity_Id;
4900 begin
4901 GNAT_Pragma;
4902 Check_Arg_Count (1);
4903 Check_Optional_Identifier (Arg1, Name_Entity);
4904 Check_Arg_Is_Local_Name (Arg1);
4905 E_Id := Expression (Arg1);
4907 if Etype (E_Id) = Any_Type then
4908 return;
4909 end if;
4911 E := Entity (E_Id);
4913 if not Is_Record_Type (E) then
4914 Error_Pragma_Arg
4915 ("argument for pragma% must be record type", Arg1);
4916 end if;
4918 Ent := First_Entity (E);
4920 if No (Ent)
4921 or else No (Next_Entity (Ent))
4922 or else Present (Next_Entity (Next_Entity (Ent)))
4923 or else not Is_Floating_Point_Type (Etype (Ent))
4924 or else Etype (Ent) /= Etype (Next_Entity (Ent))
4925 then
4926 Error_Pragma_Arg
4927 ("record for pragma% must have two fields of same fpt type",
4928 Arg1);
4930 else
4931 Set_Has_Complex_Representation (Base_Type (E));
4932 end if;
4933 end Complex_Representation;
4935 -------------------------
4936 -- Component_Alignment --
4937 -------------------------
4939 -- pragma Component_Alignment (
4940 -- [Form =>] ALIGNMENT_CHOICE
4941 -- [, [Name =>] type_LOCAL_NAME]);
4943 -- ALIGNMENT_CHOICE ::=
4944 -- Component_Size
4945 -- | Component_Size_4
4946 -- | Storage_Unit
4947 -- | Default
4949 when Pragma_Component_Alignment => Component_AlignmentP : declare
4950 Args : Args_List (1 .. 2);
4951 Names : constant Name_List (1 .. 2) := (
4952 Name_Form,
4953 Name_Name);
4955 Form : Node_Id renames Args (1);
4956 Name : Node_Id renames Args (2);
4958 Atype : Component_Alignment_Kind;
4959 Typ : Entity_Id;
4961 begin
4962 GNAT_Pragma;
4963 Gather_Associations (Names, Args);
4965 if No (Form) then
4966 Error_Pragma ("missing Form argument for pragma%");
4967 end if;
4969 Check_Arg_Is_Identifier (Form);
4971 -- Get proper alignment, note that Default = Component_Size
4972 -- on all machines we have so far, and we want to set this
4973 -- value rather than the default value to indicate that it
4974 -- has been explicitly set (and thus will not get overridden
4975 -- by the default component alignment for the current scope)
4977 if Chars (Form) = Name_Component_Size then
4978 Atype := Calign_Component_Size;
4980 elsif Chars (Form) = Name_Component_Size_4 then
4981 Atype := Calign_Component_Size_4;
4983 elsif Chars (Form) = Name_Default then
4984 Atype := Calign_Component_Size;
4986 elsif Chars (Form) = Name_Storage_Unit then
4987 Atype := Calign_Storage_Unit;
4989 else
4990 Error_Pragma_Arg
4991 ("invalid Form parameter for pragma%", Form);
4992 end if;
4994 -- Case with no name, supplied, affects scope table entry
4996 if No (Name) then
4997 Scope_Stack.Table
4998 (Scope_Stack.Last).Component_Alignment_Default := Atype;
5000 -- Case of name supplied
5002 else
5003 Check_Arg_Is_Local_Name (Name);
5004 Find_Type (Name);
5005 Typ := Entity (Name);
5007 if Typ = Any_Type
5008 or else Rep_Item_Too_Early (Typ, N)
5009 then
5010 return;
5011 else
5012 Typ := Underlying_Type (Typ);
5013 end if;
5015 if not Is_Record_Type (Typ)
5016 and then not Is_Array_Type (Typ)
5017 then
5018 Error_Pragma_Arg
5019 ("Name parameter of pragma% must identify record or " &
5020 "array type", Name);
5021 end if;
5023 -- An explicit Component_Alignment pragma overrides an
5024 -- implicit pragma Pack, but not an explicit one.
5026 if not Has_Pragma_Pack (Base_Type (Typ)) then
5027 Set_Is_Packed (Base_Type (Typ), False);
5028 Set_Component_Alignment (Base_Type (Typ), Atype);
5029 end if;
5030 end if;
5031 end Component_AlignmentP;
5033 ----------------
5034 -- Controlled --
5035 ----------------
5037 -- pragma Controlled (first_subtype_LOCAL_NAME);
5039 when Pragma_Controlled => Controlled : declare
5040 Arg : Node_Id;
5042 begin
5043 Check_No_Identifiers;
5044 Check_Arg_Count (1);
5045 Check_Arg_Is_Local_Name (Arg1);
5046 Arg := Expression (Arg1);
5048 if not Is_Entity_Name (Arg)
5049 or else not Is_Access_Type (Entity (Arg))
5050 then
5051 Error_Pragma_Arg ("pragma% requires access type", Arg1);
5052 else
5053 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
5054 end if;
5055 end Controlled;
5057 ----------------
5058 -- Convention --
5059 ----------------
5061 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
5062 -- [Entity =>] LOCAL_NAME);
5064 when Pragma_Convention => Convention : declare
5065 C : Convention_Id;
5066 E : Entity_Id;
5067 begin
5068 Check_Ada_83_Warning;
5069 Check_Arg_Count (2);
5070 Process_Convention (C, E);
5071 end Convention;
5073 ---------------------------
5074 -- Convention_Identifier --
5075 ---------------------------
5077 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
5078 -- [Convention =>] convention_IDENTIFIER);
5080 when Pragma_Convention_Identifier => Convention_Identifier : declare
5081 Idnam : Name_Id;
5082 Cname : Name_Id;
5084 begin
5085 GNAT_Pragma;
5086 Check_Arg_Count (2);
5087 Check_Optional_Identifier (Arg1, Name_Name);
5088 Check_Optional_Identifier (Arg2, Name_Convention);
5089 Check_Arg_Is_Identifier (Arg1);
5090 Check_Arg_Is_Identifier (Arg1);
5091 Idnam := Chars (Expression (Arg1));
5092 Cname := Chars (Expression (Arg2));
5094 if Is_Convention_Name (Cname) then
5095 Record_Convention_Identifier
5096 (Idnam, Get_Convention_Id (Cname));
5097 else
5098 Error_Pragma_Arg
5099 ("second arg for % pragma must be convention", Arg2);
5100 end if;
5101 end Convention_Identifier;
5103 ---------------
5104 -- CPP_Class --
5105 ---------------
5107 -- pragma CPP_Class ([Entity =>] local_NAME)
5109 when Pragma_CPP_Class => CPP_Class : declare
5110 Arg : Node_Id;
5111 Typ : Entity_Id;
5112 Default_DTC : Entity_Id := Empty;
5113 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5114 C : Entity_Id;
5115 Tag_C : Entity_Id;
5117 begin
5118 GNAT_Pragma;
5119 Check_Arg_Count (1);
5120 Check_Optional_Identifier (Arg1, Name_Entity);
5121 Check_Arg_Is_Local_Name (Arg1);
5123 Arg := Expression (Arg1);
5124 Analyze (Arg);
5126 if Etype (Arg) = Any_Type then
5127 return;
5128 end if;
5130 if not Is_Entity_Name (Arg)
5131 or else not Is_Type (Entity (Arg))
5132 then
5133 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
5134 end if;
5136 Typ := Entity (Arg);
5138 if not Is_Record_Type (Typ) then
5139 Error_Pragma_Arg ("pragma% applicable to a record, "
5140 & "tagged record or record extension", Arg1);
5141 end if;
5143 Default_DTC := First_Component (Typ);
5144 while Present (Default_DTC)
5145 and then Etype (Default_DTC) /= VTP_Type
5146 loop
5147 Next_Component (Default_DTC);
5148 end loop;
5150 -- Case of non tagged type
5152 if not Is_Tagged_Type (Typ) then
5153 Set_Is_CPP_Class (Typ);
5155 if Present (Default_DTC) then
5156 Error_Pragma_Arg
5157 ("only tagged records can contain vtable pointers", Arg1);
5158 end if;
5160 -- Case of tagged type with no vtable ptr
5162 -- What is test for Typ = Root_Typ (Typ) about here ???
5164 elsif Is_Tagged_Type (Typ)
5165 and then Typ = Root_Type (Typ)
5166 and then No (Default_DTC)
5167 then
5168 Error_Pragma_Arg
5169 ("a cpp_class must contain a vtable pointer", Arg1);
5171 -- Tagged type that has a vtable ptr
5173 elsif Present (Default_DTC) then
5174 Set_Is_CPP_Class (Typ);
5175 Set_Is_Limited_Record (Typ);
5176 Set_Is_Tag (Default_DTC);
5177 Set_DT_Entry_Count (Default_DTC, No_Uint);
5179 -- Since a CPP type has no direct link to its associated tag
5180 -- most tags checks cannot be performed
5182 Set_Kill_Tag_Checks (Typ);
5183 Set_Kill_Tag_Checks (Class_Wide_Type (Typ));
5185 -- Get rid of the _tag component when there was one.
5186 -- It is only useful for regular tagged types
5188 if Expander_Active and then Typ = Root_Type (Typ) then
5190 Tag_C := First_Tag_Component (Typ);
5191 C := First_Entity (Typ);
5193 if C = Tag_C then
5194 Set_First_Entity (Typ, Next_Entity (Tag_C));
5196 else
5197 while Next_Entity (C) /= Tag_C loop
5198 Next_Entity (C);
5199 end loop;
5201 Set_Next_Entity (C, Next_Entity (Tag_C));
5202 end if;
5203 end if;
5204 end if;
5205 end CPP_Class;
5207 ---------------------
5208 -- CPP_Constructor --
5209 ---------------------
5211 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME);
5213 when Pragma_CPP_Constructor => CPP_Constructor : declare
5214 Id : Entity_Id;
5215 Def_Id : Entity_Id;
5217 begin
5218 GNAT_Pragma;
5219 Check_Arg_Count (1);
5220 Check_Optional_Identifier (Arg1, Name_Entity);
5221 Check_Arg_Is_Local_Name (Arg1);
5223 Id := Expression (Arg1);
5224 Find_Program_Unit_Name (Id);
5226 -- If we did not find the name, we are done
5228 if Etype (Id) = Any_Type then
5229 return;
5230 end if;
5232 Def_Id := Entity (Id);
5234 if Ekind (Def_Id) = E_Function
5235 and then Is_Class_Wide_Type (Etype (Def_Id))
5236 and then Is_CPP_Class (Etype (Etype (Def_Id)))
5237 then
5238 -- What the heck is this??? this pragma allows only 1 arg
5240 if Arg_Count >= 2 then
5241 Check_At_Most_N_Arguments (3);
5242 Process_Interface_Name (Def_Id, Arg2, Arg3);
5243 end if;
5245 if No (Parameter_Specifications (Parent (Def_Id))) then
5246 Set_Has_Completion (Def_Id);
5247 Set_Is_Constructor (Def_Id);
5248 else
5249 Error_Pragma_Arg
5250 ("non-default constructors not implemented", Arg1);
5251 end if;
5253 else
5254 Error_Pragma_Arg
5255 ("pragma% requires function returning a 'C'P'P_Class type",
5256 Arg1);
5257 end if;
5258 end CPP_Constructor;
5260 -----------------
5261 -- CPP_Virtual --
5262 -----------------
5264 -- pragma CPP_Virtual
5265 -- [Entity =>] LOCAL_NAME
5266 -- [ [Vtable_Ptr =>] LOCAL_NAME,
5267 -- [Position =>] static_integer_EXPRESSION]);
5269 when Pragma_CPP_Virtual => CPP_Virtual : declare
5270 Arg : Node_Id;
5271 Typ : Entity_Id;
5272 Subp : Entity_Id;
5273 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5274 DTC : Entity_Id;
5275 V : Uint;
5277 begin
5278 GNAT_Pragma;
5280 if Arg_Count = 3 then
5281 Check_Optional_Identifier (Arg2, "vtable_ptr");
5283 -- We allow Entry_Count as well as Position for the third
5284 -- parameter for back compatibility with versions of GNAT
5285 -- before version 3.12. The documentation has always said
5286 -- Position, but the code up to 3.12 said Entry_Count.
5288 if Chars (Arg3) /= Name_Position then
5289 Check_Optional_Identifier (Arg3, "entry_count");
5290 end if;
5292 else
5293 Check_Arg_Count (1);
5294 end if;
5296 Check_Optional_Identifier (Arg1, Name_Entity);
5297 Check_Arg_Is_Local_Name (Arg1);
5299 -- First argument must be a subprogram name
5301 Arg := Expression (Arg1);
5302 Find_Program_Unit_Name (Arg);
5304 if Etype (Arg) = Any_Type then
5305 return;
5306 else
5307 Subp := Entity (Arg);
5308 end if;
5310 if not (Is_Subprogram (Subp)
5311 and then Is_Dispatching_Operation (Subp))
5312 then
5313 Error_Pragma_Arg
5314 ("pragma% must reference a primitive operation", Arg1);
5315 end if;
5317 Typ := Find_Dispatching_Type (Subp);
5319 -- If only one Argument defaults are :
5320 -- . DTC_Entity is the default Vtable pointer
5321 -- . DT_Position will be set at the freezing point
5323 if Arg_Count = 1 then
5324 Set_DTC_Entity (Subp, First_Tag_Component (Typ));
5325 return;
5326 end if;
5328 -- Second argument is a component name of type Vtable_Ptr
5330 Arg := Expression (Arg2);
5332 if Nkind (Arg) /= N_Identifier then
5333 Error_Msg_NE ("must be a& component name", Arg, Typ);
5334 raise Pragma_Exit;
5335 end if;
5337 DTC := First_Component (Typ);
5338 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5339 Next_Component (DTC);
5340 end loop;
5342 if No (DTC) then
5343 Error_Msg_NE ("must be a& component name", Arg, Typ);
5344 raise Pragma_Exit;
5346 elsif Etype (DTC) /= VTP_Type then
5347 Wrong_Type (Arg, VTP_Type);
5348 return;
5349 end if;
5351 -- Third argument is an integer (DT_Position)
5353 Arg := Expression (Arg3);
5354 Analyze_And_Resolve (Arg, Any_Integer);
5356 if not Is_Static_Expression (Arg) then
5357 Flag_Non_Static_Expr
5358 ("third argument of pragma CPP_Virtual must be static!",
5359 Arg3);
5360 raise Pragma_Exit;
5362 else
5363 V := Expr_Value (Expression (Arg3));
5365 if V <= 0 then
5366 Error_Pragma_Arg
5367 ("third argument of pragma% must be positive",
5368 Arg3);
5370 else
5371 Set_DTC_Entity (Subp, DTC);
5372 Set_DT_Position (Subp, V);
5373 end if;
5374 end if;
5375 end CPP_Virtual;
5377 ----------------
5378 -- CPP_Vtable --
5379 ----------------
5381 -- pragma CPP_Vtable (
5382 -- [Entity =>] LOCAL_NAME
5383 -- [Vtable_Ptr =>] LOCAL_NAME,
5384 -- [Entry_Count =>] static_integer_EXPRESSION);
5386 when Pragma_CPP_Vtable => CPP_Vtable : declare
5387 Arg : Node_Id;
5388 Typ : Entity_Id;
5389 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5390 DTC : Entity_Id;
5391 V : Uint;
5392 Elmt : Elmt_Id;
5394 begin
5395 GNAT_Pragma;
5396 Check_Arg_Count (3);
5397 Check_Optional_Identifier (Arg1, Name_Entity);
5398 Check_Optional_Identifier (Arg2, "vtable_ptr");
5399 Check_Optional_Identifier (Arg3, "entry_count");
5400 Check_Arg_Is_Local_Name (Arg1);
5402 -- First argument is a record type name
5404 Arg := Expression (Arg1);
5405 Analyze (Arg);
5407 if Etype (Arg) = Any_Type then
5408 return;
5409 else
5410 Typ := Entity (Arg);
5411 end if;
5413 if not (Is_Tagged_Type (Typ) and then Is_CPP_Class (Typ)) then
5414 Error_Pragma_Arg ("'C'P'P_Class tagged type expected", Arg1);
5415 end if;
5417 -- Second argument is a component name of type Vtable_Ptr
5419 Arg := Expression (Arg2);
5421 if Nkind (Arg) /= N_Identifier then
5422 Error_Msg_NE ("must be a& component name", Arg, Typ);
5423 raise Pragma_Exit;
5424 end if;
5426 DTC := First_Component (Typ);
5427 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5428 Next_Component (DTC);
5429 end loop;
5431 if No (DTC) then
5432 Error_Msg_NE ("must be a& component name", Arg, Typ);
5433 raise Pragma_Exit;
5435 elsif Etype (DTC) /= VTP_Type then
5436 Wrong_Type (DTC, VTP_Type);
5437 return;
5439 -- If it is the first pragma Vtable, This becomes the default tag
5441 elsif (not Is_Tag (DTC))
5442 and then DT_Entry_Count (First_Tag_Component (Typ)) = No_Uint
5443 then
5444 Set_Is_Tag (First_Tag_Component (Typ), False);
5445 Set_Is_Tag (DTC, True);
5446 Set_DT_Entry_Count (DTC, No_Uint);
5447 end if;
5449 -- Those pragmas must appear before any primitive operation
5450 -- definition (except inherited ones) otherwise the default
5451 -- may be wrong
5453 Elmt := First_Elmt (Primitive_Operations (Typ));
5454 while Present (Elmt) loop
5455 if No (Alias (Node (Elmt))) then
5456 Error_Msg_Sloc := Sloc (Node (Elmt));
5457 Error_Pragma
5458 ("pragma% must appear before this primitive operation");
5459 end if;
5461 Next_Elmt (Elmt);
5462 end loop;
5464 -- Third argument is an integer (DT_Entry_Count)
5466 Arg := Expression (Arg3);
5467 Analyze_And_Resolve (Arg, Any_Integer);
5469 if not Is_Static_Expression (Arg) then
5470 Flag_Non_Static_Expr
5471 ("entry count for pragma CPP_Vtable must be a static " &
5472 "expression!", Arg3);
5473 raise Pragma_Exit;
5475 else
5476 V := Expr_Value (Expression (Arg3));
5478 if V <= 0 then
5479 Error_Pragma_Arg
5480 ("entry count for pragma% must be positive", Arg3);
5481 else
5482 Set_DT_Entry_Count (DTC, V);
5483 end if;
5484 end if;
5485 end CPP_Vtable;
5487 -----------
5488 -- Debug --
5489 -----------
5491 -- pragma Debug (PROCEDURE_CALL_STATEMENT);
5493 when Pragma_Debug => Debug : begin
5494 GNAT_Pragma;
5496 -- Rewrite into a conditional with a static condition
5498 Rewrite (N, Make_Implicit_If_Statement (N,
5499 Condition => New_Occurrence_Of (Boolean_Literals (
5500 Assertions_Enabled and Expander_Active), Loc),
5501 Then_Statements => New_List (
5502 Relocate_Node (Debug_Statement (N)))));
5503 Analyze (N);
5504 end Debug;
5506 ---------------------
5507 -- Detect_Blocking --
5508 ---------------------
5510 -- pragma Detect_Blocking;
5512 when Pragma_Detect_Blocking =>
5513 GNAT_Pragma;
5514 Check_Arg_Count (0);
5515 Check_Valid_Configuration_Pragma;
5516 Detect_Blocking := True;
5518 -------------------
5519 -- Discard_Names --
5520 -------------------
5522 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
5524 when Pragma_Discard_Names => Discard_Names : declare
5525 E_Id : Entity_Id;
5526 E : Entity_Id;
5528 begin
5529 Check_Ada_83_Warning;
5531 -- Deal with configuration pragma case
5533 if Arg_Count = 0 and then Is_Configuration_Pragma then
5534 Global_Discard_Names := True;
5535 return;
5537 -- Otherwise, check correct appropriate context
5539 else
5540 Check_Is_In_Decl_Part_Or_Package_Spec;
5542 if Arg_Count = 0 then
5544 -- If there is no parameter, then from now on this pragma
5545 -- applies to any enumeration, exception or tagged type
5546 -- defined in the current declarative part.
5548 Set_Discard_Names (Current_Scope);
5549 return;
5551 else
5552 Check_Arg_Count (1);
5553 Check_Optional_Identifier (Arg1, Name_On);
5554 Check_Arg_Is_Local_Name (Arg1);
5555 E_Id := Expression (Arg1);
5557 if Etype (E_Id) = Any_Type then
5558 return;
5559 else
5560 E := Entity (E_Id);
5561 end if;
5563 if (Is_First_Subtype (E)
5564 and then (Is_Enumeration_Type (E)
5565 or else Is_Tagged_Type (E)))
5566 or else Ekind (E) = E_Exception
5567 then
5568 Set_Discard_Names (E);
5569 else
5570 Error_Pragma_Arg
5571 ("inappropriate entity for pragma%", Arg1);
5572 end if;
5573 end if;
5574 end if;
5575 end Discard_Names;
5577 ---------------
5578 -- Elaborate --
5579 ---------------
5581 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
5583 when Pragma_Elaborate => Elaborate : declare
5584 Plist : List_Id;
5585 Parent_Node : Node_Id;
5586 Arg : Node_Id;
5587 Citem : Node_Id;
5589 begin
5590 -- Pragma must be in context items list of a compilation unit
5592 if not Is_List_Member (N) then
5593 Pragma_Misplaced;
5594 return;
5596 else
5597 Plist := List_Containing (N);
5598 Parent_Node := Parent (Plist);
5600 if Parent_Node = Empty
5601 or else Nkind (Parent_Node) /= N_Compilation_Unit
5602 or else Context_Items (Parent_Node) /= Plist
5603 then
5604 Pragma_Misplaced;
5605 return;
5606 end if;
5607 end if;
5609 -- Must be at least one argument
5611 if Arg_Count = 0 then
5612 Error_Pragma ("pragma% requires at least one argument");
5613 end if;
5615 -- In Ada 83 mode, there can be no items following it in the
5616 -- context list except other pragmas and implicit with clauses
5617 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
5618 -- placement rule does not apply.
5620 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5621 Citem := Next (N);
5623 while Present (Citem) loop
5624 if Nkind (Citem) = N_Pragma
5625 or else (Nkind (Citem) = N_With_Clause
5626 and then Implicit_With (Citem))
5627 then
5628 null;
5629 else
5630 Error_Pragma
5631 ("(Ada 83) pragma% must be at end of context clause");
5632 end if;
5634 Next (Citem);
5635 end loop;
5636 end if;
5638 -- Finally, the arguments must all be units mentioned in a with
5639 -- clause in the same context clause. Note we already checked
5640 -- (in Par.Prag) that the arguments are either identifiers or
5642 Arg := Arg1;
5643 Outer : while Present (Arg) loop
5644 Citem := First (Plist);
5646 Inner : while Citem /= N loop
5647 if Nkind (Citem) = N_With_Clause
5648 and then Same_Name (Name (Citem), Expression (Arg))
5649 then
5650 Set_Elaborate_Present (Citem, True);
5651 Set_Unit_Name (Expression (Arg), Name (Citem));
5653 -- With the pragma present, elaboration calls on
5654 -- subprograms from the named unit need no further
5655 -- checks, as long as the pragma appears in the current
5656 -- compilation unit. If the pragma appears in some unit
5657 -- in the context, there might still be a need for an
5658 -- Elaborate_All_Desirable from the current compilation
5659 -- to the the named unit, so we keep the check enabled.
5661 if In_Extended_Main_Source_Unit (N) then
5662 Set_Suppress_Elaboration_Warnings
5663 (Entity (Name (Citem)));
5664 end if;
5665 exit Inner;
5666 end if;
5668 Next (Citem);
5669 end loop Inner;
5671 if Citem = N then
5672 Error_Pragma_Arg
5673 ("argument of pragma% is not with'ed unit", Arg);
5674 end if;
5676 Next (Arg);
5677 end loop Outer;
5679 -- Give a warning if operating in static mode with -gnatwl
5680 -- (elaboration warnings eanbled) switch set.
5682 if Elab_Warnings and not Dynamic_Elaboration_Checks then
5683 Error_Msg_N
5684 ("?use of pragma Elaborate may not be safe", N);
5685 Error_Msg_N
5686 ("?use pragma Elaborate_All instead if possible", N);
5687 end if;
5688 end Elaborate;
5690 -------------------
5691 -- Elaborate_All --
5692 -------------------
5694 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
5696 when Pragma_Elaborate_All => Elaborate_All : declare
5697 Plist : List_Id;
5698 Parent_Node : Node_Id;
5699 Arg : Node_Id;
5700 Citem : Node_Id;
5702 begin
5703 Check_Ada_83_Warning;
5705 -- Pragma must be in context items list of a compilation unit
5707 if not Is_List_Member (N) then
5708 Pragma_Misplaced;
5709 return;
5711 else
5712 Plist := List_Containing (N);
5713 Parent_Node := Parent (Plist);
5715 if Parent_Node = Empty
5716 or else Nkind (Parent_Node) /= N_Compilation_Unit
5717 or else Context_Items (Parent_Node) /= Plist
5718 then
5719 Pragma_Misplaced;
5720 return;
5721 end if;
5722 end if;
5724 -- Must be at least one argument
5726 if Arg_Count = 0 then
5727 Error_Pragma ("pragma% requires at least one argument");
5728 end if;
5730 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
5731 -- have to appear at the end of the context clause, but may
5732 -- appear mixed in with other items, even in Ada 83 mode.
5734 -- Final check: the arguments must all be units mentioned in
5735 -- a with clause in the same context clause. Note that we
5736 -- already checked (in Par.Prag) that all the arguments are
5737 -- either identifiers or selected components.
5739 Arg := Arg1;
5740 Outr : while Present (Arg) loop
5741 Citem := First (Plist);
5743 Innr : while Citem /= N loop
5744 if Nkind (Citem) = N_With_Clause
5745 and then Same_Name (Name (Citem), Expression (Arg))
5746 then
5747 Set_Elaborate_All_Present (Citem, True);
5748 Set_Unit_Name (Expression (Arg), Name (Citem));
5750 -- Suppress warnings and elaboration checks on the named
5751 -- unit if the pragma is in the current compilation, as
5752 -- for pragma Elaborate.
5754 if In_Extended_Main_Source_Unit (N) then
5755 Set_Suppress_Elaboration_Warnings
5756 (Entity (Name (Citem)));
5757 end if;
5758 exit Innr;
5759 end if;
5761 Next (Citem);
5762 end loop Innr;
5764 if Citem = N then
5765 Set_Error_Posted (N);
5766 Error_Pragma_Arg
5767 ("argument of pragma% is not with'ed unit", Arg);
5768 end if;
5770 Next (Arg);
5771 end loop Outr;
5772 end Elaborate_All;
5774 --------------------
5775 -- Elaborate_Body --
5776 --------------------
5778 -- pragma Elaborate_Body [( library_unit_NAME )];
5780 when Pragma_Elaborate_Body => Elaborate_Body : declare
5781 Cunit_Node : Node_Id;
5782 Cunit_Ent : Entity_Id;
5784 begin
5785 Check_Ada_83_Warning;
5786 Check_Valid_Library_Unit_Pragma;
5788 if Nkind (N) = N_Null_Statement then
5789 return;
5790 end if;
5792 Cunit_Node := Cunit (Current_Sem_Unit);
5793 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
5795 if Nkind (Unit (Cunit_Node)) = N_Package_Body
5796 or else
5797 Nkind (Unit (Cunit_Node)) = N_Subprogram_Body
5798 then
5799 Error_Pragma ("pragma% must refer to a spec, not a body");
5800 else
5801 Set_Body_Required (Cunit_Node, True);
5802 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
5804 -- If we are in dynamic elaboration mode, then we suppress
5805 -- elaboration warnings for the unit, since it is definitely
5806 -- fine NOT to do dynamic checks at the first level (and such
5807 -- checks will be suppressed because no elaboration boolean
5808 -- is created for Elaborate_Body packages).
5810 -- But in the static model of elaboration, Elaborate_Body is
5811 -- definitely NOT good enough to ensure elaboration safety on
5812 -- its own, since the body may WITH other units that are not
5813 -- safe from an elaboration point of view, so a client must
5814 -- still do an Elaborate_All on such units.
5816 -- Debug flag -gnatdD restores the old behavior of 3.13,
5817 -- where Elaborate_Body always suppressed elab warnings.
5819 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
5820 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
5821 end if;
5822 end if;
5823 end Elaborate_Body;
5825 ------------------------
5826 -- Elaboration_Checks --
5827 ------------------------
5829 -- pragma Elaboration_Checks (Static | Dynamic);
5831 when Pragma_Elaboration_Checks =>
5832 GNAT_Pragma;
5833 Check_Arg_Count (1);
5834 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
5835 Dynamic_Elaboration_Checks :=
5836 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
5838 ---------------
5839 -- Eliminate --
5840 ---------------
5842 -- pragma Eliminate (
5843 -- [Unit_Name =>] IDENTIFIER |
5844 -- SELECTED_COMPONENT
5845 -- [,[Entity =>] IDENTIFIER |
5846 -- SELECTED_COMPONENT |
5847 -- STRING_LITERAL]
5848 -- [,]OVERLOADING_RESOLUTION);
5850 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
5851 -- SOURCE_LOCATION
5853 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
5854 -- FUNCTION_PROFILE
5856 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
5858 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
5859 -- Result_Type => result_SUBTYPE_NAME]
5861 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
5862 -- SUBTYPE_NAME ::= STRING_LITERAL
5864 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
5865 -- SOURCE_TRACE ::= STRING_LITERAL
5867 when Pragma_Eliminate => Eliminate : declare
5868 Args : Args_List (1 .. 5);
5869 Names : constant Name_List (1 .. 5) := (
5870 Name_Unit_Name,
5871 Name_Entity,
5872 Name_Parameter_Types,
5873 Name_Result_Type,
5874 Name_Source_Location);
5876 Unit_Name : Node_Id renames Args (1);
5877 Entity : Node_Id renames Args (2);
5878 Parameter_Types : Node_Id renames Args (3);
5879 Result_Type : Node_Id renames Args (4);
5880 Source_Location : Node_Id renames Args (5);
5882 begin
5883 GNAT_Pragma;
5884 Check_Valid_Configuration_Pragma;
5885 Gather_Associations (Names, Args);
5887 if No (Unit_Name) then
5888 Error_Pragma ("missing Unit_Name argument for pragma%");
5889 end if;
5891 if No (Entity)
5892 and then (Present (Parameter_Types)
5893 or else
5894 Present (Result_Type)
5895 or else
5896 Present (Source_Location))
5897 then
5898 Error_Pragma ("missing Entity argument for pragma%");
5899 end if;
5901 if (Present (Parameter_Types)
5902 or else
5903 Present (Result_Type))
5904 and then
5905 Present (Source_Location)
5906 then
5907 Error_Pragma
5908 ("parameter profile and source location can not " &
5909 "be used together in pragma%");
5910 end if;
5912 Process_Eliminate_Pragma
5914 Unit_Name,
5915 Entity,
5916 Parameter_Types,
5917 Result_Type,
5918 Source_Location);
5919 end Eliminate;
5921 -------------------------
5922 -- Explicit_Overriding --
5923 -------------------------
5925 when Pragma_Explicit_Overriding =>
5926 Check_Valid_Configuration_Pragma;
5927 Check_Arg_Count (0);
5928 Explicit_Overriding := True;
5930 ------------
5931 -- Export --
5932 ------------
5934 -- pragma Export (
5935 -- [ Convention =>] convention_IDENTIFIER,
5936 -- [ Entity =>] local_NAME
5937 -- [, [External_Name =>] static_string_EXPRESSION ]
5938 -- [, [Link_Name =>] static_string_EXPRESSION ]);
5940 when Pragma_Export => Export : declare
5941 C : Convention_Id;
5942 Def_Id : Entity_Id;
5944 begin
5945 Check_Ada_83_Warning;
5946 Check_At_Least_N_Arguments (2);
5947 Check_At_Most_N_Arguments (4);
5948 Process_Convention (C, Def_Id);
5950 if Ekind (Def_Id) /= E_Constant then
5951 Note_Possible_Modification (Expression (Arg2));
5952 end if;
5954 Process_Interface_Name (Def_Id, Arg3, Arg4);
5955 Set_Exported (Def_Id, Arg2);
5956 end Export;
5958 ----------------------
5959 -- Export_Exception --
5960 ----------------------
5962 -- pragma Export_Exception (
5963 -- [Internal =>] LOCAL_NAME,
5964 -- [, [External =>] EXTERNAL_SYMBOL,]
5965 -- [, [Form =>] Ada | VMS]
5966 -- [, [Code =>] static_integer_EXPRESSION]);
5968 when Pragma_Export_Exception => Export_Exception : declare
5969 Args : Args_List (1 .. 4);
5970 Names : constant Name_List (1 .. 4) := (
5971 Name_Internal,
5972 Name_External,
5973 Name_Form,
5974 Name_Code);
5976 Internal : Node_Id renames Args (1);
5977 External : Node_Id renames Args (2);
5978 Form : Node_Id renames Args (3);
5979 Code : Node_Id renames Args (4);
5981 begin
5982 if Inside_A_Generic then
5983 Error_Pragma ("pragma% cannot be used for generic entities");
5984 end if;
5986 Gather_Associations (Names, Args);
5987 Process_Extended_Import_Export_Exception_Pragma (
5988 Arg_Internal => Internal,
5989 Arg_External => External,
5990 Arg_Form => Form,
5991 Arg_Code => Code);
5993 if not Is_VMS_Exception (Entity (Internal)) then
5994 Set_Exported (Entity (Internal), Internal);
5995 end if;
5996 end Export_Exception;
5998 ---------------------
5999 -- Export_Function --
6000 ---------------------
6002 -- pragma Export_Function (
6003 -- [Internal =>] LOCAL_NAME,
6004 -- [, [External =>] EXTERNAL_SYMBOL,]
6005 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6006 -- [, [Result_Type =>] TYPE_DESIGNATOR]
6007 -- [, [Mechanism =>] MECHANISM]
6008 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
6010 -- EXTERNAL_SYMBOL ::=
6011 -- IDENTIFIER
6012 -- | static_string_EXPRESSION
6014 -- PARAMETER_TYPES ::=
6015 -- null
6016 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6018 -- TYPE_DESIGNATOR ::=
6019 -- subtype_NAME
6020 -- | subtype_Name ' Access
6022 -- MECHANISM ::=
6023 -- MECHANISM_NAME
6024 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6026 -- MECHANISM_ASSOCIATION ::=
6027 -- [formal_parameter_NAME =>] MECHANISM_NAME
6029 -- MECHANISM_NAME ::=
6030 -- Value
6031 -- | Reference
6032 -- | Descriptor [([Class =>] CLASS_NAME)]
6034 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6036 when Pragma_Export_Function => Export_Function : declare
6037 Args : Args_List (1 .. 6);
6038 Names : constant Name_List (1 .. 6) := (
6039 Name_Internal,
6040 Name_External,
6041 Name_Parameter_Types,
6042 Name_Result_Type,
6043 Name_Mechanism,
6044 Name_Result_Mechanism);
6046 Internal : Node_Id renames Args (1);
6047 External : Node_Id renames Args (2);
6048 Parameter_Types : Node_Id renames Args (3);
6049 Result_Type : Node_Id renames Args (4);
6050 Mechanism : Node_Id renames Args (5);
6051 Result_Mechanism : Node_Id renames Args (6);
6053 begin
6054 GNAT_Pragma;
6055 Gather_Associations (Names, Args);
6056 Process_Extended_Import_Export_Subprogram_Pragma (
6057 Arg_Internal => Internal,
6058 Arg_External => External,
6059 Arg_Parameter_Types => Parameter_Types,
6060 Arg_Result_Type => Result_Type,
6061 Arg_Mechanism => Mechanism,
6062 Arg_Result_Mechanism => Result_Mechanism);
6063 end Export_Function;
6065 -------------------
6066 -- Export_Object --
6067 -------------------
6069 -- pragma Export_Object (
6070 -- [Internal =>] LOCAL_NAME,
6071 -- [, [External =>] EXTERNAL_SYMBOL]
6072 -- [, [Size =>] EXTERNAL_SYMBOL]);
6074 -- EXTERNAL_SYMBOL ::=
6075 -- IDENTIFIER
6076 -- | static_string_EXPRESSION
6078 -- PARAMETER_TYPES ::=
6079 -- null
6080 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6082 -- TYPE_DESIGNATOR ::=
6083 -- subtype_NAME
6084 -- | subtype_Name ' Access
6086 -- MECHANISM ::=
6087 -- MECHANISM_NAME
6088 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6090 -- MECHANISM_ASSOCIATION ::=
6091 -- [formal_parameter_NAME =>] MECHANISM_NAME
6093 -- MECHANISM_NAME ::=
6094 -- Value
6095 -- | Reference
6096 -- | Descriptor [([Class =>] CLASS_NAME)]
6098 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6100 when Pragma_Export_Object => Export_Object : declare
6101 Args : Args_List (1 .. 3);
6102 Names : constant Name_List (1 .. 3) := (
6103 Name_Internal,
6104 Name_External,
6105 Name_Size);
6107 Internal : Node_Id renames Args (1);
6108 External : Node_Id renames Args (2);
6109 Size : Node_Id renames Args (3);
6111 begin
6112 GNAT_Pragma;
6113 Gather_Associations (Names, Args);
6114 Process_Extended_Import_Export_Object_Pragma (
6115 Arg_Internal => Internal,
6116 Arg_External => External,
6117 Arg_Size => Size);
6118 end Export_Object;
6120 ----------------------
6121 -- Export_Procedure --
6122 ----------------------
6124 -- pragma Export_Procedure (
6125 -- [Internal =>] LOCAL_NAME,
6126 -- [, [External =>] EXTERNAL_SYMBOL,]
6127 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6128 -- [, [Mechanism =>] MECHANISM]);
6130 -- EXTERNAL_SYMBOL ::=
6131 -- IDENTIFIER
6132 -- | static_string_EXPRESSION
6134 -- PARAMETER_TYPES ::=
6135 -- null
6136 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6138 -- TYPE_DESIGNATOR ::=
6139 -- subtype_NAME
6140 -- | subtype_Name ' Access
6142 -- MECHANISM ::=
6143 -- MECHANISM_NAME
6144 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6146 -- MECHANISM_ASSOCIATION ::=
6147 -- [formal_parameter_NAME =>] MECHANISM_NAME
6149 -- MECHANISM_NAME ::=
6150 -- Value
6151 -- | Reference
6152 -- | Descriptor [([Class =>] CLASS_NAME)]
6154 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6156 when Pragma_Export_Procedure => Export_Procedure : declare
6157 Args : Args_List (1 .. 4);
6158 Names : constant Name_List (1 .. 4) := (
6159 Name_Internal,
6160 Name_External,
6161 Name_Parameter_Types,
6162 Name_Mechanism);
6164 Internal : Node_Id renames Args (1);
6165 External : Node_Id renames Args (2);
6166 Parameter_Types : Node_Id renames Args (3);
6167 Mechanism : Node_Id renames Args (4);
6169 begin
6170 GNAT_Pragma;
6171 Gather_Associations (Names, Args);
6172 Process_Extended_Import_Export_Subprogram_Pragma (
6173 Arg_Internal => Internal,
6174 Arg_External => External,
6175 Arg_Parameter_Types => Parameter_Types,
6176 Arg_Mechanism => Mechanism);
6177 end Export_Procedure;
6179 ------------------
6180 -- Export_Value --
6181 ------------------
6183 -- pragma Export_Value (
6184 -- [Value =>] static_integer_EXPRESSION,
6185 -- [Link_Name =>] static_string_EXPRESSION);
6187 when Pragma_Export_Value =>
6188 GNAT_Pragma;
6189 Check_Arg_Count (2);
6191 Check_Optional_Identifier (Arg1, Name_Value);
6192 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
6194 Check_Optional_Identifier (Arg2, Name_Link_Name);
6195 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6197 -----------------------------
6198 -- Export_Valued_Procedure --
6199 -----------------------------
6201 -- pragma Export_Valued_Procedure (
6202 -- [Internal =>] LOCAL_NAME,
6203 -- [, [External =>] EXTERNAL_SYMBOL,]
6204 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6205 -- [, [Mechanism =>] MECHANISM]);
6207 -- EXTERNAL_SYMBOL ::=
6208 -- IDENTIFIER
6209 -- | static_string_EXPRESSION
6211 -- PARAMETER_TYPES ::=
6212 -- null
6213 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6215 -- TYPE_DESIGNATOR ::=
6216 -- subtype_NAME
6217 -- | subtype_Name ' Access
6219 -- MECHANISM ::=
6220 -- MECHANISM_NAME
6221 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6223 -- MECHANISM_ASSOCIATION ::=
6224 -- [formal_parameter_NAME =>] MECHANISM_NAME
6226 -- MECHANISM_NAME ::=
6227 -- Value
6228 -- | Reference
6229 -- | Descriptor [([Class =>] CLASS_NAME)]
6231 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6233 when Pragma_Export_Valued_Procedure =>
6234 Export_Valued_Procedure : declare
6235 Args : Args_List (1 .. 4);
6236 Names : constant Name_List (1 .. 4) := (
6237 Name_Internal,
6238 Name_External,
6239 Name_Parameter_Types,
6240 Name_Mechanism);
6242 Internal : Node_Id renames Args (1);
6243 External : Node_Id renames Args (2);
6244 Parameter_Types : Node_Id renames Args (3);
6245 Mechanism : Node_Id renames Args (4);
6247 begin
6248 GNAT_Pragma;
6249 Gather_Associations (Names, Args);
6250 Process_Extended_Import_Export_Subprogram_Pragma (
6251 Arg_Internal => Internal,
6252 Arg_External => External,
6253 Arg_Parameter_Types => Parameter_Types,
6254 Arg_Mechanism => Mechanism);
6255 end Export_Valued_Procedure;
6257 -------------------
6258 -- Extend_System --
6259 -------------------
6261 -- pragma Extend_System ([Name =>] Identifier);
6263 when Pragma_Extend_System => Extend_System : declare
6264 begin
6265 GNAT_Pragma;
6266 Check_Valid_Configuration_Pragma;
6267 Check_Arg_Count (1);
6268 Check_Optional_Identifier (Arg1, Name_Name);
6269 Check_Arg_Is_Identifier (Arg1);
6271 Get_Name_String (Chars (Expression (Arg1)));
6273 if Name_Len > 4
6274 and then Name_Buffer (1 .. 4) = "aux_"
6275 then
6276 if Present (System_Extend_Pragma_Arg) then
6277 if Chars (Expression (Arg1)) =
6278 Chars (Expression (System_Extend_Pragma_Arg))
6279 then
6280 null;
6281 else
6282 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
6283 Error_Pragma ("pragma% conflicts with that at#");
6284 end if;
6286 else
6287 System_Extend_Pragma_Arg := Arg1;
6289 if not GNAT_Mode then
6290 System_Extend_Unit := Arg1;
6291 end if;
6292 end if;
6293 else
6294 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
6295 end if;
6296 end Extend_System;
6298 ------------------------
6299 -- Extensions_Allowed --
6300 ------------------------
6302 -- pragma Extensions_Allowed (ON | OFF);
6304 when Pragma_Extensions_Allowed =>
6305 GNAT_Pragma;
6306 Check_Arg_Count (1);
6307 Check_No_Identifiers;
6308 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6310 if Chars (Expression (Arg1)) = Name_On then
6311 Extensions_Allowed := True;
6312 Ada_Version := Ada_Version_Type'Last;
6313 else
6314 Extensions_Allowed := False;
6315 Ada_Version := Ada_Version_Type'Min (Ada_Version, Ada_95);
6316 end if;
6318 --------------
6319 -- External --
6320 --------------
6322 -- pragma External (
6323 -- [ Convention =>] convention_IDENTIFIER,
6324 -- [ Entity =>] local_NAME
6325 -- [, [External_Name =>] static_string_EXPRESSION ]
6326 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6328 when Pragma_External => External : declare
6329 C : Convention_Id;
6330 Def_Id : Entity_Id;
6332 begin
6333 GNAT_Pragma;
6334 Check_At_Least_N_Arguments (2);
6335 Check_At_Most_N_Arguments (4);
6336 Process_Convention (C, Def_Id);
6337 Note_Possible_Modification (Expression (Arg2));
6338 Process_Interface_Name (Def_Id, Arg3, Arg4);
6339 Set_Exported (Def_Id, Arg2);
6340 end External;
6342 --------------------------
6343 -- External_Name_Casing --
6344 --------------------------
6346 -- pragma External_Name_Casing (
6347 -- UPPERCASE | LOWERCASE
6348 -- [, AS_IS | UPPERCASE | LOWERCASE]);
6350 when Pragma_External_Name_Casing => External_Name_Casing : declare
6351 begin
6352 GNAT_Pragma;
6353 Check_No_Identifiers;
6355 if Arg_Count = 2 then
6356 Check_Arg_Is_One_Of
6357 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
6359 case Chars (Get_Pragma_Arg (Arg2)) is
6360 when Name_As_Is =>
6361 Opt.External_Name_Exp_Casing := As_Is;
6363 when Name_Uppercase =>
6364 Opt.External_Name_Exp_Casing := Uppercase;
6366 when Name_Lowercase =>
6367 Opt.External_Name_Exp_Casing := Lowercase;
6369 when others =>
6370 null;
6371 end case;
6373 else
6374 Check_Arg_Count (1);
6375 end if;
6377 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
6379 case Chars (Get_Pragma_Arg (Arg1)) is
6380 when Name_Uppercase =>
6381 Opt.External_Name_Imp_Casing := Uppercase;
6383 when Name_Lowercase =>
6384 Opt.External_Name_Imp_Casing := Lowercase;
6386 when others =>
6387 null;
6388 end case;
6389 end External_Name_Casing;
6391 ---------------------------
6392 -- Finalize_Storage_Only --
6393 ---------------------------
6395 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
6397 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
6398 Assoc : constant Node_Id := Arg1;
6399 Type_Id : constant Node_Id := Expression (Assoc);
6400 Typ : Entity_Id;
6402 begin
6403 Check_No_Identifiers;
6404 Check_Arg_Count (1);
6405 Check_Arg_Is_Local_Name (Arg1);
6407 Find_Type (Type_Id);
6408 Typ := Entity (Type_Id);
6410 if Typ = Any_Type
6411 or else Rep_Item_Too_Early (Typ, N)
6412 then
6413 return;
6414 else
6415 Typ := Underlying_Type (Typ);
6416 end if;
6418 if not Is_Controlled (Typ) then
6419 Error_Pragma ("pragma% must specify controlled type");
6420 end if;
6422 Check_First_Subtype (Arg1);
6424 if Finalize_Storage_Only (Typ) then
6425 Error_Pragma ("duplicate pragma%, only one allowed");
6427 elsif not Rep_Item_Too_Late (Typ, N) then
6428 Set_Finalize_Storage_Only (Base_Type (Typ), True);
6429 end if;
6430 end Finalize_Storage;
6432 --------------------------
6433 -- Float_Representation --
6434 --------------------------
6436 -- pragma Float_Representation (VAX_Float | IEEE_Float);
6438 when Pragma_Float_Representation => Float_Representation : declare
6439 Argx : Node_Id;
6440 Digs : Nat;
6441 Ent : Entity_Id;
6443 begin
6444 GNAT_Pragma;
6446 if Arg_Count = 1 then
6447 Check_Valid_Configuration_Pragma;
6448 else
6449 Check_Arg_Count (2);
6450 Check_Optional_Identifier (Arg2, Name_Entity);
6451 Check_Arg_Is_Local_Name (Arg2);
6452 end if;
6454 Check_No_Identifier (Arg1);
6455 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
6457 if not OpenVMS_On_Target then
6458 if Chars (Expression (Arg1)) = Name_VAX_Float then
6459 Error_Pragma
6460 ("?pragma% ignored (applies only to Open'V'M'S)");
6461 end if;
6463 return;
6464 end if;
6466 -- One argument case
6468 if Arg_Count = 1 then
6470 if Chars (Expression (Arg1)) = Name_VAX_Float then
6472 if Opt.Float_Format = 'I' then
6473 Error_Pragma ("'I'E'E'E format previously specified");
6474 end if;
6476 Opt.Float_Format := 'V';
6478 else
6479 if Opt.Float_Format = 'V' then
6480 Error_Pragma ("'V'A'X format previously specified");
6481 end if;
6483 Opt.Float_Format := 'I';
6484 end if;
6486 Set_Standard_Fpt_Formats;
6488 -- Two argument case
6490 else
6491 Argx := Get_Pragma_Arg (Arg2);
6493 if not Is_Entity_Name (Argx)
6494 or else not Is_Floating_Point_Type (Entity (Argx))
6495 then
6496 Error_Pragma_Arg
6497 ("second argument of% pragma must be floating-point type",
6498 Arg2);
6499 end if;
6501 Ent := Entity (Argx);
6502 Digs := UI_To_Int (Digits_Value (Ent));
6504 -- Two arguments, VAX_Float case
6506 if Chars (Expression (Arg1)) = Name_VAX_Float then
6508 case Digs is
6509 when 6 => Set_F_Float (Ent);
6510 when 9 => Set_D_Float (Ent);
6511 when 15 => Set_G_Float (Ent);
6513 when others =>
6514 Error_Pragma_Arg
6515 ("wrong digits value, must be 6,9 or 15", Arg2);
6516 end case;
6518 -- Two arguments, IEEE_Float case
6520 else
6521 case Digs is
6522 when 6 => Set_IEEE_Short (Ent);
6523 when 15 => Set_IEEE_Long (Ent);
6525 when others =>
6526 Error_Pragma_Arg
6527 ("wrong digits value, must be 6 or 15", Arg2);
6528 end case;
6529 end if;
6530 end if;
6531 end Float_Representation;
6533 -----------
6534 -- Ident --
6535 -----------
6537 -- pragma Ident (static_string_EXPRESSION)
6539 -- Note: pragma Comment shares this processing. Pragma Comment
6540 -- is identical to Ident, except that the restriction of the
6541 -- argument to 31 characters and the placement restrictions
6542 -- are not enforced for pragma Comment.
6544 when Pragma_Ident | Pragma_Comment => Ident : declare
6545 Str : Node_Id;
6547 begin
6548 GNAT_Pragma;
6549 Check_Arg_Count (1);
6550 Check_No_Identifiers;
6551 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
6553 -- For pragma Ident, preserve DEC compatibility by requiring
6554 -- the pragma to appear in a declarative part or package spec.
6556 if Prag_Id = Pragma_Ident then
6557 Check_Is_In_Decl_Part_Or_Package_Spec;
6558 end if;
6560 Str := Expr_Value_S (Expression (Arg1));
6562 declare
6563 CS : Node_Id;
6564 GP : Node_Id;
6566 begin
6567 GP := Parent (Parent (N));
6569 if Nkind (GP) = N_Package_Declaration
6570 or else
6571 Nkind (GP) = N_Generic_Package_Declaration
6572 then
6573 GP := Parent (GP);
6574 end if;
6576 -- If we have a compilation unit, then record the ident
6577 -- value, checking for improper duplication.
6579 if Nkind (GP) = N_Compilation_Unit then
6580 CS := Ident_String (Current_Sem_Unit);
6582 if Present (CS) then
6584 -- For Ident, we do not permit multiple instances
6586 if Prag_Id = Pragma_Ident then
6587 Error_Pragma ("duplicate% pragma not permitted");
6589 -- For Comment, we concatenate the string, unless we
6590 -- want to preserve the tree structure for ASIS.
6592 elsif not ASIS_Mode then
6593 Start_String (Strval (CS));
6594 Store_String_Char (' ');
6595 Store_String_Chars (Strval (Str));
6596 Set_Strval (CS, End_String);
6597 end if;
6599 else
6600 -- In VMS, the effect of IDENT is achieved by passing
6601 -- IDENTIFICATION=name as a --for-linker switch.
6603 if OpenVMS_On_Target then
6604 Start_String;
6605 Store_String_Chars
6606 ("--for-linker=IDENTIFICATION=");
6607 String_To_Name_Buffer (Strval (Str));
6608 Store_String_Chars (Name_Buffer (1 .. Name_Len));
6610 -- Only the last processed IDENT is saved. The main
6611 -- purpose is so an IDENT associated with a main
6612 -- procedure will be used in preference to an IDENT
6613 -- associated with a with'd package.
6615 Replace_Linker_Option_String
6616 (End_String, "--for-linker=IDENTIFICATION=");
6617 end if;
6619 Set_Ident_String (Current_Sem_Unit, Str);
6620 end if;
6622 -- For subunits, we just ignore the Ident, since in GNAT
6623 -- these are not separate object files, and hence not
6624 -- separate units in the unit table.
6626 elsif Nkind (GP) = N_Subunit then
6627 null;
6629 -- Otherwise we have a misplaced pragma Ident, but we ignore
6630 -- this if we are in an instantiation, since it comes from
6631 -- a generic, and has no relevance to the instantiation.
6633 elsif Prag_Id = Pragma_Ident then
6634 if Instantiation_Location (Loc) = No_Location then
6635 Error_Pragma ("pragma% only allowed at outer level");
6636 end if;
6637 end if;
6638 end;
6639 end Ident;
6641 ------------
6642 -- Import --
6643 ------------
6645 -- pragma Import (
6646 -- [ Convention =>] convention_IDENTIFIER,
6647 -- [ Entity =>] local_NAME
6648 -- [, [External_Name =>] static_string_EXPRESSION ]
6649 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6651 when Pragma_Import =>
6652 Check_Ada_83_Warning;
6653 Check_At_Least_N_Arguments (2);
6654 Check_At_Most_N_Arguments (4);
6655 Process_Import_Or_Interface;
6657 ----------------------
6658 -- Import_Exception --
6659 ----------------------
6661 -- pragma Import_Exception (
6662 -- [Internal =>] LOCAL_NAME,
6663 -- [, [External =>] EXTERNAL_SYMBOL,]
6664 -- [, [Form =>] Ada | VMS]
6665 -- [, [Code =>] static_integer_EXPRESSION]);
6667 when Pragma_Import_Exception => Import_Exception : declare
6668 Args : Args_List (1 .. 4);
6669 Names : constant Name_List (1 .. 4) := (
6670 Name_Internal,
6671 Name_External,
6672 Name_Form,
6673 Name_Code);
6675 Internal : Node_Id renames Args (1);
6676 External : Node_Id renames Args (2);
6677 Form : Node_Id renames Args (3);
6678 Code : Node_Id renames Args (4);
6680 begin
6681 Gather_Associations (Names, Args);
6683 if Present (External) and then Present (Code) then
6684 Error_Pragma
6685 ("cannot give both External and Code options for pragma%");
6686 end if;
6688 Process_Extended_Import_Export_Exception_Pragma (
6689 Arg_Internal => Internal,
6690 Arg_External => External,
6691 Arg_Form => Form,
6692 Arg_Code => Code);
6694 if not Is_VMS_Exception (Entity (Internal)) then
6695 Set_Imported (Entity (Internal));
6696 end if;
6697 end Import_Exception;
6699 ---------------------
6700 -- Import_Function --
6701 ---------------------
6703 -- pragma Import_Function (
6704 -- [Internal =>] LOCAL_NAME,
6705 -- [, [External =>] EXTERNAL_SYMBOL]
6706 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6707 -- [, [Result_Type =>] SUBTYPE_MARK]
6708 -- [, [Mechanism =>] MECHANISM]
6709 -- [, [Result_Mechanism =>] MECHANISM_NAME]
6710 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6712 -- EXTERNAL_SYMBOL ::=
6713 -- IDENTIFIER
6714 -- | static_string_EXPRESSION
6716 -- PARAMETER_TYPES ::=
6717 -- null
6718 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6720 -- TYPE_DESIGNATOR ::=
6721 -- subtype_NAME
6722 -- | subtype_Name ' Access
6724 -- MECHANISM ::=
6725 -- MECHANISM_NAME
6726 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6728 -- MECHANISM_ASSOCIATION ::=
6729 -- [formal_parameter_NAME =>] MECHANISM_NAME
6731 -- MECHANISM_NAME ::=
6732 -- Value
6733 -- | Reference
6734 -- | Descriptor [([Class =>] CLASS_NAME)]
6736 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6738 when Pragma_Import_Function => Import_Function : declare
6739 Args : Args_List (1 .. 7);
6740 Names : constant Name_List (1 .. 7) := (
6741 Name_Internal,
6742 Name_External,
6743 Name_Parameter_Types,
6744 Name_Result_Type,
6745 Name_Mechanism,
6746 Name_Result_Mechanism,
6747 Name_First_Optional_Parameter);
6749 Internal : Node_Id renames Args (1);
6750 External : Node_Id renames Args (2);
6751 Parameter_Types : Node_Id renames Args (3);
6752 Result_Type : Node_Id renames Args (4);
6753 Mechanism : Node_Id renames Args (5);
6754 Result_Mechanism : Node_Id renames Args (6);
6755 First_Optional_Parameter : Node_Id renames Args (7);
6757 begin
6758 GNAT_Pragma;
6759 Gather_Associations (Names, Args);
6760 Process_Extended_Import_Export_Subprogram_Pragma (
6761 Arg_Internal => Internal,
6762 Arg_External => External,
6763 Arg_Parameter_Types => Parameter_Types,
6764 Arg_Result_Type => Result_Type,
6765 Arg_Mechanism => Mechanism,
6766 Arg_Result_Mechanism => Result_Mechanism,
6767 Arg_First_Optional_Parameter => First_Optional_Parameter);
6768 end Import_Function;
6770 -------------------
6771 -- Import_Object --
6772 -------------------
6774 -- pragma Import_Object (
6775 -- [Internal =>] LOCAL_NAME,
6776 -- [, [External =>] EXTERNAL_SYMBOL]
6777 -- [, [Size =>] EXTERNAL_SYMBOL]);
6779 -- EXTERNAL_SYMBOL ::=
6780 -- IDENTIFIER
6781 -- | static_string_EXPRESSION
6783 when Pragma_Import_Object => Import_Object : declare
6784 Args : Args_List (1 .. 3);
6785 Names : constant Name_List (1 .. 3) := (
6786 Name_Internal,
6787 Name_External,
6788 Name_Size);
6790 Internal : Node_Id renames Args (1);
6791 External : Node_Id renames Args (2);
6792 Size : Node_Id renames Args (3);
6794 begin
6795 GNAT_Pragma;
6796 Gather_Associations (Names, Args);
6797 Process_Extended_Import_Export_Object_Pragma (
6798 Arg_Internal => Internal,
6799 Arg_External => External,
6800 Arg_Size => Size);
6801 end Import_Object;
6803 ----------------------
6804 -- Import_Procedure --
6805 ----------------------
6807 -- pragma Import_Procedure (
6808 -- [Internal =>] LOCAL_NAME,
6809 -- [, [External =>] EXTERNAL_SYMBOL]
6810 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6811 -- [, [Mechanism =>] MECHANISM]
6812 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6814 -- EXTERNAL_SYMBOL ::=
6815 -- IDENTIFIER
6816 -- | static_string_EXPRESSION
6818 -- PARAMETER_TYPES ::=
6819 -- null
6820 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6822 -- TYPE_DESIGNATOR ::=
6823 -- subtype_NAME
6824 -- | subtype_Name ' Access
6826 -- MECHANISM ::=
6827 -- MECHANISM_NAME
6828 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6830 -- MECHANISM_ASSOCIATION ::=
6831 -- [formal_parameter_NAME =>] MECHANISM_NAME
6833 -- MECHANISM_NAME ::=
6834 -- Value
6835 -- | Reference
6836 -- | Descriptor [([Class =>] CLASS_NAME)]
6838 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6840 when Pragma_Import_Procedure => Import_Procedure : declare
6841 Args : Args_List (1 .. 5);
6842 Names : constant Name_List (1 .. 5) := (
6843 Name_Internal,
6844 Name_External,
6845 Name_Parameter_Types,
6846 Name_Mechanism,
6847 Name_First_Optional_Parameter);
6849 Internal : Node_Id renames Args (1);
6850 External : Node_Id renames Args (2);
6851 Parameter_Types : Node_Id renames Args (3);
6852 Mechanism : Node_Id renames Args (4);
6853 First_Optional_Parameter : Node_Id renames Args (5);
6855 begin
6856 GNAT_Pragma;
6857 Gather_Associations (Names, Args);
6858 Process_Extended_Import_Export_Subprogram_Pragma (
6859 Arg_Internal => Internal,
6860 Arg_External => External,
6861 Arg_Parameter_Types => Parameter_Types,
6862 Arg_Mechanism => Mechanism,
6863 Arg_First_Optional_Parameter => First_Optional_Parameter);
6864 end Import_Procedure;
6866 -----------------------------
6867 -- Import_Valued_Procedure --
6868 -----------------------------
6870 -- pragma Import_Valued_Procedure (
6871 -- [Internal =>] LOCAL_NAME,
6872 -- [, [External =>] EXTERNAL_SYMBOL]
6873 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6874 -- [, [Mechanism =>] MECHANISM]
6875 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6877 -- EXTERNAL_SYMBOL ::=
6878 -- IDENTIFIER
6879 -- | static_string_EXPRESSION
6881 -- PARAMETER_TYPES ::=
6882 -- null
6883 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6885 -- TYPE_DESIGNATOR ::=
6886 -- subtype_NAME
6887 -- | subtype_Name ' Access
6889 -- MECHANISM ::=
6890 -- MECHANISM_NAME
6891 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6893 -- MECHANISM_ASSOCIATION ::=
6894 -- [formal_parameter_NAME =>] MECHANISM_NAME
6896 -- MECHANISM_NAME ::=
6897 -- Value
6898 -- | Reference
6899 -- | Descriptor [([Class =>] CLASS_NAME)]
6901 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6903 when Pragma_Import_Valued_Procedure =>
6904 Import_Valued_Procedure : declare
6905 Args : Args_List (1 .. 5);
6906 Names : constant Name_List (1 .. 5) := (
6907 Name_Internal,
6908 Name_External,
6909 Name_Parameter_Types,
6910 Name_Mechanism,
6911 Name_First_Optional_Parameter);
6913 Internal : Node_Id renames Args (1);
6914 External : Node_Id renames Args (2);
6915 Parameter_Types : Node_Id renames Args (3);
6916 Mechanism : Node_Id renames Args (4);
6917 First_Optional_Parameter : Node_Id renames Args (5);
6919 begin
6920 GNAT_Pragma;
6921 Gather_Associations (Names, Args);
6922 Process_Extended_Import_Export_Subprogram_Pragma (
6923 Arg_Internal => Internal,
6924 Arg_External => External,
6925 Arg_Parameter_Types => Parameter_Types,
6926 Arg_Mechanism => Mechanism,
6927 Arg_First_Optional_Parameter => First_Optional_Parameter);
6928 end Import_Valued_Procedure;
6930 ------------------------
6931 -- Initialize_Scalars --
6932 ------------------------
6934 -- pragma Initialize_Scalars;
6936 when Pragma_Initialize_Scalars =>
6937 GNAT_Pragma;
6938 Check_Arg_Count (0);
6939 Check_Valid_Configuration_Pragma;
6940 Check_Restriction (No_Initialize_Scalars, N);
6942 if not Restriction_Active (No_Initialize_Scalars) then
6943 Init_Or_Norm_Scalars := True;
6944 Initialize_Scalars := True;
6945 end if;
6947 ------------
6948 -- Inline --
6949 ------------
6951 -- pragma Inline ( NAME {, NAME} );
6953 when Pragma_Inline =>
6955 -- Pragma is active if inlining option is active
6957 Process_Inline (Inline_Active);
6959 -------------------
6960 -- Inline_Always --
6961 -------------------
6963 -- pragma Inline_Always ( NAME {, NAME} );
6965 when Pragma_Inline_Always =>
6966 Process_Inline (True);
6968 --------------------
6969 -- Inline_Generic --
6970 --------------------
6972 -- pragma Inline_Generic (NAME {, NAME});
6974 when Pragma_Inline_Generic =>
6975 Process_Generic_List;
6977 ----------------------
6978 -- Inspection_Point --
6979 ----------------------
6981 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
6983 when Pragma_Inspection_Point => Inspection_Point : declare
6984 Arg : Node_Id;
6985 Exp : Node_Id;
6987 begin
6988 if Arg_Count > 0 then
6989 Arg := Arg1;
6990 loop
6991 Exp := Expression (Arg);
6992 Analyze (Exp);
6994 if not Is_Entity_Name (Exp)
6995 or else not Is_Object (Entity (Exp))
6996 then
6997 Error_Pragma_Arg ("object name required", Arg);
6998 end if;
7000 Next (Arg);
7001 exit when No (Arg);
7002 end loop;
7003 end if;
7004 end Inspection_Point;
7006 ---------------
7007 -- Interface --
7008 ---------------
7010 -- pragma Interface (
7011 -- convention_IDENTIFIER,
7012 -- local_NAME );
7014 when Pragma_Interface =>
7015 GNAT_Pragma;
7016 Check_Arg_Count (2);
7017 Check_No_Identifiers;
7018 Process_Import_Or_Interface;
7020 --------------------
7021 -- Interface_Name --
7022 --------------------
7024 -- pragma Interface_Name (
7025 -- [ Entity =>] local_NAME
7026 -- [,[External_Name =>] static_string_EXPRESSION ]
7027 -- [,[Link_Name =>] static_string_EXPRESSION ]);
7029 when Pragma_Interface_Name => Interface_Name : declare
7030 Id : Node_Id;
7031 Def_Id : Entity_Id;
7032 Hom_Id : Entity_Id;
7033 Found : Boolean;
7035 begin
7036 GNAT_Pragma;
7037 Check_At_Least_N_Arguments (2);
7038 Check_At_Most_N_Arguments (3);
7039 Id := Expression (Arg1);
7040 Analyze (Id);
7042 if not Is_Entity_Name (Id) then
7043 Error_Pragma_Arg
7044 ("first argument for pragma% must be entity name", Arg1);
7045 elsif Etype (Id) = Any_Type then
7046 return;
7047 else
7048 Def_Id := Entity (Id);
7049 end if;
7051 -- Special DEC-compatible processing for the object case,
7052 -- forces object to be imported.
7054 if Ekind (Def_Id) = E_Variable then
7055 Kill_Size_Check_Code (Def_Id);
7056 Note_Possible_Modification (Id);
7058 -- Initialization is not allowed for imported variable
7060 if Present (Expression (Parent (Def_Id)))
7061 and then Comes_From_Source (Expression (Parent (Def_Id)))
7062 then
7063 Error_Msg_Sloc := Sloc (Def_Id);
7064 Error_Pragma_Arg
7065 ("no initialization allowed for declaration of& #",
7066 Arg2);
7068 else
7069 -- For compatibility, support VADS usage of providing both
7070 -- pragmas Interface and Interface_Name to obtain the effect
7071 -- of a single Import pragma.
7073 if Is_Imported (Def_Id)
7074 and then Present (First_Rep_Item (Def_Id))
7075 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
7076 and then Chars (First_Rep_Item (Def_Id)) = Name_Interface
7077 then
7078 null;
7079 else
7080 Set_Imported (Def_Id);
7081 end if;
7083 Set_Is_Public (Def_Id);
7084 Process_Interface_Name (Def_Id, Arg2, Arg3);
7085 end if;
7087 -- Otherwise must be subprogram
7089 elsif not Is_Subprogram (Def_Id) then
7090 Error_Pragma_Arg
7091 ("argument of pragma% is not subprogram", Arg1);
7093 else
7094 Check_At_Most_N_Arguments (3);
7095 Hom_Id := Def_Id;
7096 Found := False;
7098 -- Loop through homonyms
7100 loop
7101 Def_Id := Get_Base_Subprogram (Hom_Id);
7103 if Is_Imported (Def_Id) then
7104 Process_Interface_Name (Def_Id, Arg2, Arg3);
7105 Found := True;
7106 end if;
7108 Hom_Id := Homonym (Hom_Id);
7110 exit when No (Hom_Id)
7111 or else Scope (Hom_Id) /= Current_Scope;
7112 end loop;
7114 if not Found then
7115 Error_Pragma_Arg
7116 ("argument of pragma% is not imported subprogram",
7117 Arg1);
7118 end if;
7119 end if;
7120 end Interface_Name;
7122 -----------------------
7123 -- Interrupt_Handler --
7124 -----------------------
7126 -- pragma Interrupt_Handler (handler_NAME);
7128 when Pragma_Interrupt_Handler =>
7129 Check_Ada_83_Warning;
7130 Check_Arg_Count (1);
7131 Check_No_Identifiers;
7133 if No_Run_Time_Mode then
7134 Error_Msg_CRT ("Interrupt_Handler pragma", N);
7135 else
7136 Check_Interrupt_Or_Attach_Handler;
7137 Process_Interrupt_Or_Attach_Handler;
7138 end if;
7140 ------------------------
7141 -- Interrupt_Priority --
7142 ------------------------
7144 -- pragma Interrupt_Priority [(EXPRESSION)];
7146 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
7147 P : constant Node_Id := Parent (N);
7148 Arg : Node_Id;
7150 begin
7151 Check_Ada_83_Warning;
7153 if Arg_Count /= 0 then
7154 Arg := Expression (Arg1);
7155 Check_Arg_Count (1);
7156 Check_No_Identifiers;
7158 -- The expression must be analyzed in the special manner
7159 -- described in "Handling of Default and Per-Object
7160 -- Expressions" in sem.ads.
7162 Analyze_Per_Use_Expression (Arg, RTE (RE_Interrupt_Priority));
7163 end if;
7165 if Nkind (P) /= N_Task_Definition
7166 and then Nkind (P) /= N_Protected_Definition
7167 then
7168 Pragma_Misplaced;
7169 return;
7171 elsif Has_Priority_Pragma (P) then
7172 Error_Pragma ("duplicate pragma% not allowed");
7174 else
7175 Set_Has_Priority_Pragma (P, True);
7176 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7177 end if;
7178 end Interrupt_Priority;
7180 ---------------------
7181 -- Interrupt_State --
7182 ---------------------
7184 -- pragma Interrupt_State (
7185 -- [Name =>] INTERRUPT_ID,
7186 -- [State =>] INTERRUPT_STATE);
7188 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
7189 -- INTERRUPT_STATE => System | Runtime | User
7191 -- Note: if the interrupt id is given as an identifier, then
7192 -- it must be one of the identifiers in Ada.Interrupts.Names.
7193 -- Otherwise it is given as a static integer expression which
7194 -- must be in the range of Ada.Interrupts.Interrupt_ID.
7196 when Pragma_Interrupt_State => Interrupt_State : declare
7198 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
7199 -- This is the entity Ada.Interrupts.Interrupt_ID;
7201 State_Type : Character;
7202 -- Set to 's'/'r'/'u' for System/Runtime/User
7204 IST_Num : Pos;
7205 -- Index to entry in Interrupt_States table
7207 Int_Val : Uint;
7208 -- Value of interrupt
7210 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
7211 -- The first argument to the pragma
7213 Int_Ent : Entity_Id;
7214 -- Interrupt entity in Ada.Interrupts.Names
7216 begin
7217 GNAT_Pragma;
7218 Check_Arg_Count (2);
7220 Check_Optional_Identifier (Arg1, Name_Name);
7221 Check_Optional_Identifier (Arg2, "state");
7222 Check_Arg_Is_Identifier (Arg2);
7224 -- First argument is identifier
7226 if Nkind (Arg1X) = N_Identifier then
7228 -- Search list of names in Ada.Interrupts.Names
7230 Int_Ent := First_Entity (RTE (RE_Names));
7231 loop
7232 if No (Int_Ent) then
7233 Error_Pragma_Arg ("invalid interrupt name", Arg1);
7235 elsif Chars (Int_Ent) = Chars (Arg1X) then
7236 Int_Val := Expr_Value (Constant_Value (Int_Ent));
7237 exit;
7238 end if;
7240 Next_Entity (Int_Ent);
7241 end loop;
7243 -- First argument is not an identifier, so it must be a
7244 -- static expression of type Ada.Interrupts.Interrupt_ID.
7246 else
7247 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7248 Int_Val := Expr_Value (Arg1X);
7250 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
7251 or else
7252 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
7253 then
7254 Error_Pragma_Arg
7255 ("value not in range of type " &
7256 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
7257 end if;
7258 end if;
7260 -- Check OK state
7262 case Chars (Get_Pragma_Arg (Arg2)) is
7263 when Name_Runtime => State_Type := 'r';
7264 when Name_System => State_Type := 's';
7265 when Name_User => State_Type := 'u';
7267 when others =>
7268 Error_Pragma_Arg ("invalid interrupt state", Arg2);
7269 end case;
7271 -- Check if entry is already stored
7273 IST_Num := Interrupt_States.First;
7274 loop
7275 -- If entry not found, add it
7277 if IST_Num > Interrupt_States.Last then
7278 Interrupt_States.Append
7279 ((Interrupt_Number => UI_To_Int (Int_Val),
7280 Interrupt_State => State_Type,
7281 Pragma_Loc => Loc));
7282 exit;
7284 -- Case of entry for the same entry
7286 elsif Int_Val = Interrupt_States.Table (IST_Num).
7287 Interrupt_Number
7288 then
7289 -- If state matches, done, no need to make redundant entry
7291 exit when
7292 State_Type = Interrupt_States.Table (IST_Num).
7293 Interrupt_State;
7295 -- Otherwise if state does not match, error
7297 Error_Msg_Sloc :=
7298 Interrupt_States.Table (IST_Num).Pragma_Loc;
7299 Error_Pragma_Arg
7300 ("state conflicts with that given at #", Arg2);
7301 exit;
7302 end if;
7304 IST_Num := IST_Num + 1;
7305 end loop;
7306 end Interrupt_State;
7308 ----------------------
7309 -- Java_Constructor --
7310 ----------------------
7312 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
7314 when Pragma_Java_Constructor => Java_Constructor : declare
7315 Id : Entity_Id;
7316 Def_Id : Entity_Id;
7317 Hom_Id : Entity_Id;
7319 begin
7320 GNAT_Pragma;
7321 Check_Arg_Count (1);
7322 Check_Optional_Identifier (Arg1, Name_Entity);
7323 Check_Arg_Is_Local_Name (Arg1);
7325 Id := Expression (Arg1);
7326 Find_Program_Unit_Name (Id);
7328 -- If we did not find the name, we are done
7330 if Etype (Id) = Any_Type then
7331 return;
7332 end if;
7334 Hom_Id := Entity (Id);
7336 -- Loop through homonyms
7338 loop
7339 Def_Id := Get_Base_Subprogram (Hom_Id);
7341 -- The constructor is required to be a function returning
7342 -- an access type whose designated type has convention Java.
7344 if Ekind (Def_Id) = E_Function
7345 and then Ekind (Etype (Def_Id)) in Access_Kind
7346 and then
7347 (Atree.Convention
7348 (Designated_Type (Etype (Def_Id))) = Convention_Java
7349 or else
7350 Atree.Convention
7351 (Root_Type (Designated_Type (Etype (Def_Id))))
7352 = Convention_Java)
7353 then
7354 Set_Is_Constructor (Def_Id);
7355 Set_Convention (Def_Id, Convention_Java);
7357 else
7358 Error_Pragma_Arg
7359 ("pragma% requires function returning a 'Java access type",
7360 Arg1);
7361 end if;
7363 Hom_Id := Homonym (Hom_Id);
7365 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
7366 end loop;
7367 end Java_Constructor;
7369 ----------------------
7370 -- Java_Interface --
7371 ----------------------
7373 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
7375 when Pragma_Java_Interface => Java_Interface : declare
7376 Arg : Node_Id;
7377 Typ : Entity_Id;
7379 begin
7380 GNAT_Pragma;
7381 Check_Arg_Count (1);
7382 Check_Optional_Identifier (Arg1, Name_Entity);
7383 Check_Arg_Is_Local_Name (Arg1);
7385 Arg := Expression (Arg1);
7386 Analyze (Arg);
7388 if Etype (Arg) = Any_Type then
7389 return;
7390 end if;
7392 if not Is_Entity_Name (Arg)
7393 or else not Is_Type (Entity (Arg))
7394 then
7395 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7396 end if;
7398 Typ := Underlying_Type (Entity (Arg));
7400 -- For now we simply check some of the semantic constraints
7401 -- on the type. This currently leaves out some restrictions
7402 -- on interface types, namely that the parent type must be
7403 -- java.lang.Object.Typ and that all primitives of the type
7404 -- should be declared abstract. ???
7406 if not Is_Tagged_Type (Typ) or else not Is_Abstract (Typ) then
7407 Error_Pragma_Arg ("pragma% requires an abstract "
7408 & "tagged type", Arg1);
7410 elsif not Has_Discriminants (Typ)
7411 or else Ekind (Etype (First_Discriminant (Typ)))
7412 /= E_Anonymous_Access_Type
7413 or else
7414 not Is_Class_Wide_Type
7415 (Designated_Type (Etype (First_Discriminant (Typ))))
7416 then
7417 Error_Pragma_Arg
7418 ("type must have a class-wide access discriminant", Arg1);
7419 end if;
7420 end Java_Interface;
7422 ----------------
7423 -- Keep_Names --
7424 ----------------
7426 -- pragma Keep_Names ([On => ] local_NAME);
7428 when Pragma_Keep_Names => Keep_Names : declare
7429 Arg : Node_Id;
7431 begin
7432 GNAT_Pragma;
7433 Check_Arg_Count (1);
7434 Check_Optional_Identifier (Arg1, Name_On);
7435 Check_Arg_Is_Local_Name (Arg1);
7437 Arg := Expression (Arg1);
7438 Analyze (Arg);
7440 if Etype (Arg) = Any_Type then
7441 return;
7442 end if;
7444 if not Is_Entity_Name (Arg)
7445 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
7446 then
7447 Error_Pragma_Arg
7448 ("pragma% requires a local enumeration type", Arg1);
7449 end if;
7451 Set_Discard_Names (Entity (Arg), False);
7452 end Keep_Names;
7454 -------------
7455 -- License --
7456 -------------
7458 -- pragma License (RESTRICTED | UNRESRICTED | GPL | MODIFIED_GPL);
7460 when Pragma_License =>
7461 GNAT_Pragma;
7462 Check_Arg_Count (1);
7463 Check_No_Identifiers;
7464 Check_Valid_Configuration_Pragma;
7465 Check_Arg_Is_Identifier (Arg1);
7467 declare
7468 Sind : constant Source_File_Index :=
7469 Source_Index (Current_Sem_Unit);
7471 begin
7472 case Chars (Get_Pragma_Arg (Arg1)) is
7473 when Name_GPL =>
7474 Set_License (Sind, GPL);
7476 when Name_Modified_GPL =>
7477 Set_License (Sind, Modified_GPL);
7479 when Name_Restricted =>
7480 Set_License (Sind, Restricted);
7482 when Name_Unrestricted =>
7483 Set_License (Sind, Unrestricted);
7485 when others =>
7486 Error_Pragma_Arg ("invalid license name", Arg1);
7487 end case;
7488 end;
7490 ---------------
7491 -- Link_With --
7492 ---------------
7494 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
7496 when Pragma_Link_With => Link_With : declare
7497 Arg : Node_Id;
7499 begin
7500 GNAT_Pragma;
7502 if Operating_Mode = Generate_Code
7503 and then In_Extended_Main_Source_Unit (N)
7504 then
7505 Check_At_Least_N_Arguments (1);
7506 Check_No_Identifiers;
7507 Check_Is_In_Decl_Part_Or_Package_Spec;
7508 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7509 Start_String;
7511 Arg := Arg1;
7512 while Present (Arg) loop
7513 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7515 -- Store argument, converting sequences of spaces
7516 -- to a single null character (this is one of the
7517 -- differences in processing between Link_With
7518 -- and Linker_Options).
7520 declare
7521 C : constant Char_Code := Get_Char_Code (' ');
7522 S : constant String_Id :=
7523 Strval (Expr_Value_S (Expression (Arg)));
7524 L : constant Nat := String_Length (S);
7525 F : Nat := 1;
7527 procedure Skip_Spaces;
7528 -- Advance F past any spaces
7530 procedure Skip_Spaces is
7531 begin
7532 while F <= L and then Get_String_Char (S, F) = C loop
7533 F := F + 1;
7534 end loop;
7535 end Skip_Spaces;
7537 begin
7538 Skip_Spaces; -- skip leading spaces
7540 -- Loop through characters, changing any embedded
7541 -- sequence of spaces to a single null character
7542 -- (this is how Link_With/Linker_Options differ)
7544 while F <= L loop
7545 if Get_String_Char (S, F) = C then
7546 Skip_Spaces;
7547 exit when F > L;
7548 Store_String_Char (ASCII.NUL);
7550 else
7551 Store_String_Char (Get_String_Char (S, F));
7552 F := F + 1;
7553 end if;
7554 end loop;
7555 end;
7557 Arg := Next (Arg);
7559 if Present (Arg) then
7560 Store_String_Char (ASCII.NUL);
7561 end if;
7562 end loop;
7564 Store_Linker_Option_String (End_String);
7565 end if;
7566 end Link_With;
7568 ------------------
7569 -- Linker_Alias --
7570 ------------------
7572 -- pragma Linker_Alias (
7573 -- [Entity =>] LOCAL_NAME
7574 -- [Alias =>] static_string_EXPRESSION);
7576 when Pragma_Linker_Alias =>
7577 GNAT_Pragma;
7578 Check_Arg_Count (2);
7579 Check_Optional_Identifier (Arg1, Name_Entity);
7580 Check_Optional_Identifier (Arg2, "alias");
7581 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7582 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7584 -- The only processing required is to link this item on to the
7585 -- list of rep items for the given entity. This is accomplished
7586 -- by the call to Rep_Item_Too_Late (when no error is detected
7587 -- and False is returned).
7589 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7590 return;
7591 else
7592 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7593 end if;
7595 --------------------
7596 -- Linker_Options --
7597 --------------------
7599 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
7601 when Pragma_Linker_Options => Linker_Options : declare
7602 Arg : Node_Id;
7604 begin
7605 Check_Ada_83_Warning;
7606 Check_No_Identifiers;
7607 Check_Arg_Count (1);
7608 Check_Is_In_Decl_Part_Or_Package_Spec;
7610 if Operating_Mode = Generate_Code
7611 and then In_Extended_Main_Source_Unit (N)
7612 then
7613 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7614 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
7616 Arg := Arg2;
7617 while Present (Arg) loop
7618 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7619 Store_String_Char (ASCII.NUL);
7620 Store_String_Chars
7621 (Strval (Expr_Value_S (Expression (Arg))));
7622 Arg := Next (Arg);
7623 end loop;
7625 Store_Linker_Option_String (End_String);
7626 end if;
7627 end Linker_Options;
7629 --------------------
7630 -- Linker_Section --
7631 --------------------
7633 -- pragma Linker_Section (
7634 -- [Entity =>] LOCAL_NAME
7635 -- [Section =>] static_string_EXPRESSION);
7637 when Pragma_Linker_Section =>
7638 GNAT_Pragma;
7639 Check_Arg_Count (2);
7640 Check_Optional_Identifier (Arg1, Name_Entity);
7641 Check_Optional_Identifier (Arg2, Name_Section);
7642 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7643 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7645 -- The only processing required is to link this item on to the
7646 -- list of rep items for the given entity. This is accomplished
7647 -- by the call to Rep_Item_Too_Late (when no error is detected
7648 -- and False is returned).
7650 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7651 return;
7652 else
7653 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7654 end if;
7656 ----------
7657 -- List --
7658 ----------
7660 -- pragma List (On | Off)
7662 -- There is nothing to do here, since we did all the processing
7663 -- for this pragma in Par.Prag (so that it works properly even in
7664 -- syntax only mode)
7666 when Pragma_List =>
7667 null;
7669 --------------------
7670 -- Locking_Policy --
7671 --------------------
7673 -- pragma Locking_Policy (policy_IDENTIFIER);
7675 when Pragma_Locking_Policy => declare
7676 LP : Character;
7678 begin
7679 Check_Ada_83_Warning;
7680 Check_Arg_Count (1);
7681 Check_No_Identifiers;
7682 Check_Arg_Is_Locking_Policy (Arg1);
7683 Check_Valid_Configuration_Pragma;
7684 Get_Name_String (Chars (Expression (Arg1)));
7685 LP := Fold_Upper (Name_Buffer (1));
7687 if Locking_Policy /= ' '
7688 and then Locking_Policy /= LP
7689 then
7690 Error_Msg_Sloc := Locking_Policy_Sloc;
7691 Error_Pragma ("locking policy incompatible with policy#");
7693 -- Set new policy, but always preserve System_Location since
7694 -- we like the error message with the run time name.
7696 else
7697 Locking_Policy := LP;
7699 if Locking_Policy_Sloc /= System_Location then
7700 Locking_Policy_Sloc := Loc;
7701 end if;
7702 end if;
7703 end;
7705 ----------------
7706 -- Long_Float --
7707 ----------------
7709 -- pragma Long_Float (D_Float | G_Float);
7711 when Pragma_Long_Float =>
7712 GNAT_Pragma;
7713 Check_Valid_Configuration_Pragma;
7714 Check_Arg_Count (1);
7715 Check_No_Identifier (Arg1);
7716 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
7718 if not OpenVMS_On_Target then
7719 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
7720 end if;
7722 -- D_Float case
7724 if Chars (Expression (Arg1)) = Name_D_Float then
7725 if Opt.Float_Format_Long = 'G' then
7726 Error_Pragma ("G_Float previously specified");
7727 end if;
7729 Opt.Float_Format_Long := 'D';
7731 -- G_Float case (this is the default, does not need overriding)
7733 else
7734 if Opt.Float_Format_Long = 'D' then
7735 Error_Pragma ("D_Float previously specified");
7736 end if;
7738 Opt.Float_Format_Long := 'G';
7739 end if;
7741 Set_Standard_Fpt_Formats;
7743 -----------------------
7744 -- Machine_Attribute --
7745 -----------------------
7747 -- pragma Machine_Attribute (
7748 -- [Entity =>] LOCAL_NAME,
7749 -- [Attribute_Name =>] static_string_EXPRESSION
7750 -- [,[Info =>] static_string_EXPRESSION] );
7752 when Pragma_Machine_Attribute => Machine_Attribute : declare
7753 Def_Id : Entity_Id;
7755 begin
7756 GNAT_Pragma;
7758 if Arg_Count = 3 then
7759 Check_Optional_Identifier (Arg3, "info");
7760 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
7761 else
7762 Check_Arg_Count (2);
7763 end if;
7765 Check_Arg_Is_Local_Name (Arg1);
7766 Check_Optional_Identifier (Arg2, "attribute_name");
7767 Check_Optional_Identifier (Arg1, Name_Entity);
7768 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7769 Def_Id := Entity (Expression (Arg1));
7771 if Is_Access_Type (Def_Id) then
7772 Def_Id := Designated_Type (Def_Id);
7773 end if;
7775 if Rep_Item_Too_Early (Def_Id, N) then
7776 return;
7777 end if;
7779 Def_Id := Underlying_Type (Def_Id);
7781 -- The only processing required is to link this item on to the
7782 -- list of rep items for the given entity. This is accomplished
7783 -- by the call to Rep_Item_Too_Late (when no error is detected
7784 -- and False is returned).
7786 if Rep_Item_Too_Late (Def_Id, N) then
7787 return;
7788 else
7789 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7790 end if;
7791 end Machine_Attribute;
7793 ----------
7794 -- Main --
7795 ----------
7797 -- pragma Main_Storage
7798 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7800 -- MAIN_STORAGE_OPTION ::=
7801 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7802 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7804 when Pragma_Main => Main : declare
7805 Args : Args_List (1 .. 3);
7806 Names : constant Name_List (1 .. 3) := (
7807 Name_Stack_Size,
7808 Name_Task_Stack_Size_Default,
7809 Name_Time_Slicing_Enabled);
7811 Nod : Node_Id;
7813 begin
7814 GNAT_Pragma;
7815 Gather_Associations (Names, Args);
7817 for J in 1 .. 2 loop
7818 if Present (Args (J)) then
7819 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7820 end if;
7821 end loop;
7823 if Present (Args (3)) then
7824 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
7825 end if;
7827 Nod := Next (N);
7828 while Present (Nod) loop
7829 if Nkind (Nod) = N_Pragma
7830 and then Chars (Nod) = Name_Main
7831 then
7832 Error_Msg_Name_1 := Chars (N);
7833 Error_Msg_N ("duplicate pragma% not permitted", Nod);
7834 end if;
7836 Next (Nod);
7837 end loop;
7838 end Main;
7840 ------------------
7841 -- Main_Storage --
7842 ------------------
7844 -- pragma Main_Storage
7845 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7847 -- MAIN_STORAGE_OPTION ::=
7848 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7849 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7851 when Pragma_Main_Storage => Main_Storage : declare
7852 Args : Args_List (1 .. 2);
7853 Names : constant Name_List (1 .. 2) := (
7854 Name_Working_Storage,
7855 Name_Top_Guard);
7857 Nod : Node_Id;
7859 begin
7860 GNAT_Pragma;
7861 Gather_Associations (Names, Args);
7863 for J in 1 .. 2 loop
7864 if Present (Args (J)) then
7865 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7866 end if;
7867 end loop;
7869 Check_In_Main_Program;
7871 Nod := Next (N);
7872 while Present (Nod) loop
7873 if Nkind (Nod) = N_Pragma
7874 and then Chars (Nod) = Name_Main_Storage
7875 then
7876 Error_Msg_Name_1 := Chars (N);
7877 Error_Msg_N ("duplicate pragma% not permitted", Nod);
7878 end if;
7880 Next (Nod);
7881 end loop;
7882 end Main_Storage;
7884 -----------------
7885 -- Memory_Size --
7886 -----------------
7888 -- pragma Memory_Size (NUMERIC_LITERAL)
7890 when Pragma_Memory_Size =>
7891 GNAT_Pragma;
7893 -- Memory size is simply ignored
7895 Check_No_Identifiers;
7896 Check_Arg_Count (1);
7897 Check_Arg_Is_Integer_Literal (Arg1);
7899 ---------------
7900 -- No_Return --
7901 ---------------
7903 -- pragma No_Return (procedure_LOCAL_NAME);
7905 when Pragma_No_Return => No_Return : declare
7906 Id : Node_Id;
7907 E : Entity_Id;
7908 Found : Boolean;
7910 begin
7911 GNAT_Pragma;
7912 Check_Arg_Count (1);
7913 Check_No_Identifiers;
7914 Check_Arg_Is_Local_Name (Arg1);
7915 Id := Expression (Arg1);
7916 Analyze (Id);
7918 if not Is_Entity_Name (Id) then
7919 Error_Pragma_Arg ("entity name required", Arg1);
7920 end if;
7922 if Etype (Id) = Any_Type then
7923 raise Pragma_Exit;
7924 end if;
7926 E := Entity (Id);
7928 Found := False;
7929 while Present (E)
7930 and then Scope (E) = Current_Scope
7931 loop
7932 if Ekind (E) = E_Procedure
7933 or else Ekind (E) = E_Generic_Procedure
7934 then
7935 Set_No_Return (E);
7936 Found := True;
7937 end if;
7939 E := Homonym (E);
7940 end loop;
7942 if not Found then
7943 Error_Pragma ("no procedures found for pragma%");
7944 end if;
7945 end No_Return;
7947 ------------------------
7948 -- No_Strict_Aliasing --
7949 ------------------------
7951 when Pragma_No_Strict_Aliasing => No_Strict_Alias : declare
7952 E_Id : Entity_Id;
7954 begin
7955 GNAT_Pragma;
7956 Check_At_Most_N_Arguments (1);
7958 if Arg_Count = 0 then
7959 Check_Valid_Configuration_Pragma;
7960 Opt.No_Strict_Aliasing := True;
7962 else
7963 Check_Optional_Identifier (Arg2, Name_Entity);
7964 Check_Arg_Is_Local_Name (Arg1);
7965 E_Id := Entity (Expression (Arg1));
7967 if E_Id = Any_Type then
7968 return;
7969 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
7970 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7971 end if;
7973 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
7974 end if;
7975 end No_Strict_Alias;
7977 -----------------
7978 -- Obsolescent --
7979 -----------------
7981 -- pragma Obsolescent [(static_string_EXPRESSION)];
7983 when Pragma_Obsolescent => Obsolescent : declare
7984 Subp : Node_Or_Entity_Id;
7985 S : String_Id;
7987 begin
7988 GNAT_Pragma;
7989 Check_At_Most_N_Arguments (1);
7990 Check_No_Identifiers;
7992 -- Check OK placement
7994 -- First possibility is within a declarative region, where the
7995 -- pragma immediately follows a subprogram declaration.
7997 if Present (Prev (N)) then
7998 Subp := Prev (N);
8000 -- Second possibility, stand alone subprogram declaration with the
8001 -- pragma immediately following the declaration.
8003 elsif No (Prev (N))
8004 and then Nkind (Parent (N)) = N_Compilation_Unit_Aux
8005 then
8006 Subp := Unit (Parent (Parent (N)));
8008 -- Any other possibility is a misplacement
8010 else
8011 Subp := Empty;
8012 end if;
8014 -- Check correct placement
8016 if Nkind (Subp) /= N_Subprogram_Declaration then
8017 Error_Pragma
8018 ("pragma% misplaced, must immediately " &
8019 "follow subprogram spec");
8021 -- If OK placement, set flag and acquire argument
8023 else
8024 Subp := Defining_Entity (Subp);
8025 Set_Is_Obsolescent (Subp);
8027 if Arg_Count = 1 then
8028 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8029 S := Strval (Expression (Arg1));
8031 for J in 1 .. String_Length (S) loop
8032 if not In_Character_Range (Get_String_Char (S, J)) then
8033 Error_Pragma_Arg
8034 ("pragma% argument does not allow wide characters",
8035 Arg1);
8036 end if;
8037 end loop;
8039 Set_Obsolescent_Warning (Subp, Expression (Arg1));
8040 end if;
8041 end if;
8042 end Obsolescent;
8044 -----------------
8045 -- No_Run_Time --
8046 -----------------
8048 -- pragma No_Run_Time
8050 -- Note: this pragma is retained for backwards compatibiltiy.
8051 -- See body of Rtsfind for full details on its handling.
8053 when Pragma_No_Run_Time =>
8054 GNAT_Pragma;
8055 Check_Valid_Configuration_Pragma;
8056 Check_Arg_Count (0);
8058 No_Run_Time_Mode := True;
8059 Configurable_Run_Time_Mode := True;
8061 declare
8062 Word32 : constant Boolean := Ttypes.System_Word_Size = 32;
8063 begin
8064 if Word32 then
8065 Duration_32_Bits_On_Target := True;
8066 end if;
8067 end;
8069 Set_Restriction (No_Finalization, N);
8070 Set_Restriction (No_Exception_Handlers, N);
8071 Set_Restriction (Max_Tasks, N, 0);
8072 Set_Restriction (No_Tasking, N);
8074 -----------------------
8075 -- Normalize_Scalars --
8076 -----------------------
8078 -- pragma Normalize_Scalars;
8080 when Pragma_Normalize_Scalars =>
8081 Check_Ada_83_Warning;
8082 Check_Arg_Count (0);
8083 Check_Valid_Configuration_Pragma;
8084 Normalize_Scalars := True;
8085 Init_Or_Norm_Scalars := True;
8087 --------------
8088 -- Optimize --
8089 --------------
8091 -- pragma Optimize (Time | Space);
8093 -- The actual check for optimize is done in Gigi. Note that this
8094 -- pragma does not actually change the optimization setting, it
8095 -- simply checks that it is consistent with the pragma.
8097 when Pragma_Optimize =>
8098 Check_No_Identifiers;
8099 Check_Arg_Count (1);
8100 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
8102 -------------------------
8103 -- Optional_Overriding --
8104 -------------------------
8106 -- These pragmas are treated as part of the previous subprogram
8107 -- declaration, and analyzed immediately after it (see sem_ch6,
8108 -- Check_Overriding_Operation). If the pragma has not been analyzed
8109 -- yet, it appears in the wrong place.
8111 when Pragma_Optional_Overriding =>
8112 Error_Msg_N ("pragma must appear immediately after subprogram", N);
8114 ----------
8115 -- Pack --
8116 ----------
8118 -- pragma Pack (first_subtype_LOCAL_NAME);
8120 when Pragma_Pack => Pack : declare
8121 Assoc : constant Node_Id := Arg1;
8122 Type_Id : Node_Id;
8123 Typ : Entity_Id;
8125 begin
8126 Check_No_Identifiers;
8127 Check_Arg_Count (1);
8128 Check_Arg_Is_Local_Name (Arg1);
8130 Type_Id := Expression (Assoc);
8131 Find_Type (Type_Id);
8132 Typ := Entity (Type_Id);
8134 if Typ = Any_Type
8135 or else Rep_Item_Too_Early (Typ, N)
8136 then
8137 return;
8138 else
8139 Typ := Underlying_Type (Typ);
8140 end if;
8142 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
8143 Error_Pragma ("pragma% must specify array or record type");
8144 end if;
8146 Check_First_Subtype (Arg1);
8148 if Has_Pragma_Pack (Typ) then
8149 Error_Pragma ("duplicate pragma%, only one allowed");
8151 -- Array type. We set the Has_Pragma_Pack flag, and Is_Packed,
8152 -- but not Has_Non_Standard_Rep, because we don't actually know
8153 -- till freeze time if the array can have packed representation.
8154 -- That's because in the general case we do not know enough about
8155 -- the component type until it in turn is frozen, which certainly
8156 -- happens before the array type is frozen, but not necessarily
8157 -- till that point (i.e. right now it may be unfrozen).
8159 elsif Is_Array_Type (Typ) then
8160 if Has_Aliased_Components (Base_Type (Typ)) then
8161 Error_Pragma
8162 ("pragma% ignored, cannot pack aliased components?");
8164 elsif Has_Atomic_Components (Typ)
8165 or else Is_Atomic (Component_Type (Typ))
8166 then
8167 Error_Pragma
8168 ("?pragma% ignored, cannot pack atomic components");
8170 elsif not Rep_Item_Too_Late (Typ, N) then
8171 Set_Is_Packed (Base_Type (Typ));
8172 Set_Has_Pragma_Pack (Base_Type (Typ));
8173 Set_Has_Non_Standard_Rep (Base_Type (Typ));
8174 end if;
8176 -- Record type. For record types, the pack is always effective
8178 else pragma Assert (Is_Record_Type (Typ));
8179 if not Rep_Item_Too_Late (Typ, N) then
8180 Set_Has_Pragma_Pack (Base_Type (Typ));
8181 Set_Is_Packed (Base_Type (Typ));
8182 Set_Has_Non_Standard_Rep (Base_Type (Typ));
8183 end if;
8184 end if;
8185 end Pack;
8187 ----------
8188 -- Page --
8189 ----------
8191 -- pragma Page;
8193 -- There is nothing to do here, since we did all the processing
8194 -- for this pragma in Par.Prag (so that it works properly even in
8195 -- syntax only mode)
8197 when Pragma_Page =>
8198 null;
8200 -------------
8201 -- Passive --
8202 -------------
8204 -- pragma Passive [(PASSIVE_FORM)];
8206 -- PASSIVE_FORM ::= Semaphore | No
8208 when Pragma_Passive =>
8209 GNAT_Pragma;
8211 if Nkind (Parent (N)) /= N_Task_Definition then
8212 Error_Pragma ("pragma% must be within task definition");
8213 end if;
8215 if Arg_Count /= 0 then
8216 Check_Arg_Count (1);
8217 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
8218 end if;
8220 -------------
8221 -- Polling --
8222 -------------
8224 -- pragma Polling (ON | OFF);
8226 when Pragma_Polling =>
8227 GNAT_Pragma;
8228 Check_Arg_Count (1);
8229 Check_No_Identifiers;
8230 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8231 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
8233 ---------------------
8234 -- Persistent_Data --
8235 ---------------------
8237 when Pragma_Persistent_Data => declare
8238 Ent : Entity_Id;
8240 begin
8241 -- Register the pragma as applying to the compilation unit.
8242 -- Individual Persistent_Object pragmas for relevant objects
8243 -- are generated the end of the compilation.
8245 GNAT_Pragma;
8246 Check_Valid_Configuration_Pragma;
8247 Check_Arg_Count (0);
8248 Ent := Find_Lib_Unit_Name;
8249 Set_Is_Preelaborated (Ent);
8250 end;
8252 -----------------------
8253 -- Persistent_Object --
8254 -----------------------
8256 when Pragma_Persistent_Object => declare
8257 Decl : Node_Id;
8258 Ent : Entity_Id;
8259 MA : Node_Id;
8260 Str : String_Id;
8262 begin
8263 GNAT_Pragma;
8264 Check_Arg_Count (1);
8265 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8267 if not Is_Entity_Name (Expression (Arg1))
8268 or else
8269 (Ekind (Entity (Expression (Arg1))) /= E_Variable
8270 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
8271 then
8272 Error_Pragma_Arg ("pragma only applies to objects", Arg1);
8273 end if;
8275 Ent := Entity (Expression (Arg1));
8276 Decl := Parent (Ent);
8278 if Nkind (Decl) /= N_Object_Declaration then
8279 return;
8280 end if;
8282 -- Placement of the object depends on whether there is
8283 -- an initial value or none. If the No_Initialization flag
8284 -- is set, the initialization has been transformed into
8285 -- assignments, which is disallowed elaboration code.
8287 if No_Initialization (Decl) then
8288 Error_Msg_N
8289 ("initialization for persistent object"
8290 & "must be static expression", Decl);
8291 return;
8292 end if;
8294 if No (Expression (Decl)) then
8295 Start_String;
8296 Store_String_Chars ("section ("".persistent.bss"")");
8297 Str := End_String;
8299 else
8300 if not Is_OK_Static_Expression (Expression (Decl)) then
8301 Flag_Non_Static_Expr
8302 ("initialization for persistent object"
8303 & "must be static expression!", Expression (Decl));
8304 return;
8305 end if;
8307 Start_String;
8308 Store_String_Chars ("section ("".persistent.data"")");
8309 Str := End_String;
8310 end if;
8312 MA :=
8313 Make_Pragma
8314 (Sloc (N),
8315 Name_Machine_Attribute,
8316 New_List
8317 (Make_Pragma_Argument_Association
8318 (Sloc => Sloc (Arg1),
8319 Expression => New_Occurrence_Of (Ent, Sloc (Ent))),
8320 Make_Pragma_Argument_Association
8321 (Sloc => Sloc (Arg1),
8322 Expression =>
8323 Make_String_Literal
8324 (Sloc => Sloc (Arg1),
8325 Strval => Str))));
8327 Insert_After (N, MA);
8328 Analyze (MA);
8329 Set_Has_Gigi_Rep_Item (Ent);
8330 end;
8332 ------------------
8333 -- Preelaborate --
8334 ------------------
8336 -- pragma Preelaborate [(library_unit_NAME)];
8338 -- Set the flag Is_Preelaborated of program unit name entity
8340 when Pragma_Preelaborate => Preelaborate : declare
8341 Pa : constant Node_Id := Parent (N);
8342 Pk : constant Node_Kind := Nkind (Pa);
8343 Ent : Entity_Id;
8345 begin
8346 Check_Ada_83_Warning;
8347 Check_Valid_Library_Unit_Pragma;
8349 if Nkind (N) = N_Null_Statement then
8350 return;
8351 end if;
8353 Ent := Find_Lib_Unit_Name;
8355 -- This filters out pragmas inside generic parent then
8356 -- show up inside instantiation
8358 if Present (Ent)
8359 and then not (Pk = N_Package_Specification
8360 and then Present (Generic_Parent (Pa)))
8361 then
8362 if not Debug_Flag_U then
8363 Set_Is_Preelaborated (Ent);
8364 Set_Suppress_Elaboration_Warnings (Ent);
8365 end if;
8366 end if;
8367 end Preelaborate;
8369 --------------
8370 -- Priority --
8371 --------------
8373 -- pragma Priority (EXPRESSION);
8375 when Pragma_Priority => Priority : declare
8376 P : constant Node_Id := Parent (N);
8377 Arg : Node_Id;
8379 begin
8380 Check_No_Identifiers;
8381 Check_Arg_Count (1);
8383 -- Subprogram case
8385 if Nkind (P) = N_Subprogram_Body then
8386 Check_In_Main_Program;
8388 Arg := Expression (Arg1);
8389 Analyze_And_Resolve (Arg, Standard_Integer);
8391 -- Must be static
8393 if not Is_Static_Expression (Arg) then
8394 Flag_Non_Static_Expr
8395 ("main subprogram priority is not static!", Arg);
8396 raise Pragma_Exit;
8398 -- If constraint error, then we already signalled an error
8400 elsif Raises_Constraint_Error (Arg) then
8401 null;
8403 -- Otherwise check in range
8405 else
8406 declare
8407 Val : constant Uint := Expr_Value (Arg);
8409 begin
8410 if Val < 0
8411 or else Val > Expr_Value (Expression
8412 (Parent (RTE (RE_Max_Priority))))
8413 then
8414 Error_Pragma_Arg
8415 ("main subprogram priority is out of range", Arg1);
8416 end if;
8417 end;
8418 end if;
8420 Set_Main_Priority
8421 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8423 -- Task or Protected, must be of type Integer
8425 elsif Nkind (P) = N_Protected_Definition
8426 or else
8427 Nkind (P) = N_Task_Definition
8428 then
8429 Arg := Expression (Arg1);
8431 -- The expression must be analyzed in the special manner
8432 -- described in "Handling of Default and Per-Object
8433 -- Expressions" in sem.ads.
8435 Analyze_Per_Use_Expression (Arg, Standard_Integer);
8437 if not Is_Static_Expression (Arg) then
8438 Check_Restriction (Static_Priorities, Arg);
8439 end if;
8441 -- Anything else is incorrect
8443 else
8444 Pragma_Misplaced;
8445 end if;
8447 if Has_Priority_Pragma (P) then
8448 Error_Pragma ("duplicate pragma% not allowed");
8449 else
8450 Set_Has_Priority_Pragma (P, True);
8452 if Nkind (P) = N_Protected_Definition
8453 or else
8454 Nkind (P) = N_Task_Definition
8455 then
8456 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8457 -- exp_ch9 should use this ???
8458 end if;
8459 end if;
8460 end Priority;
8462 -------------
8463 -- Profile --
8464 -------------
8466 -- pragma Profile (profile_IDENTIFIER);
8468 -- profile_IDENTIFIER => Protected | Ravenscar
8470 when Pragma_Profile =>
8471 Check_Arg_Count (1);
8472 Check_Valid_Configuration_Pragma;
8473 Check_No_Identifiers;
8475 declare
8476 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8477 begin
8478 if Chars (Argx) = Name_Ravenscar then
8479 Set_Ravenscar_Profile (N);
8481 elsif Chars (Argx) = Name_Restricted then
8482 Set_Profile_Restrictions (Restricted, N, Warn => False);
8483 else
8484 Error_Pragma_Arg ("& is not a valid profile", Argx);
8485 end if;
8486 end;
8488 ----------------------
8489 -- Profile_Warnings --
8490 ----------------------
8492 -- pragma Profile_Warnings (profile_IDENTIFIER);
8494 -- profile_IDENTIFIER => Protected | Ravenscar
8496 when Pragma_Profile_Warnings =>
8497 GNAT_Pragma;
8498 Check_Arg_Count (1);
8499 Check_Valid_Configuration_Pragma;
8500 Check_No_Identifiers;
8502 declare
8503 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8504 begin
8505 if Chars (Argx) = Name_Ravenscar then
8506 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
8508 elsif Chars (Argx) = Name_Restricted then
8509 Set_Profile_Restrictions (Restricted, N, Warn => True);
8510 else
8511 Error_Pragma_Arg ("& is not a valid profile", Argx);
8512 end if;
8513 end;
8515 --------------------------
8516 -- Propagate_Exceptions --
8517 --------------------------
8519 -- pragma Propagate_Exceptions;
8521 when Pragma_Propagate_Exceptions =>
8522 GNAT_Pragma;
8523 Check_Arg_Count (0);
8525 if In_Extended_Main_Source_Unit (N) then
8526 Propagate_Exceptions := True;
8527 end if;
8529 ------------------
8530 -- Psect_Object --
8531 ------------------
8533 -- pragma Psect_Object (
8534 -- [Internal =>] LOCAL_NAME,
8535 -- [, [External =>] EXTERNAL_SYMBOL]
8536 -- [, [Size =>] EXTERNAL_SYMBOL]);
8538 when Pragma_Psect_Object | Pragma_Common_Object =>
8539 Psect_Object : declare
8540 Args : Args_List (1 .. 3);
8541 Names : constant Name_List (1 .. 3) := (
8542 Name_Internal,
8543 Name_External,
8544 Name_Size);
8546 Internal : Node_Id renames Args (1);
8547 External : Node_Id renames Args (2);
8548 Size : Node_Id renames Args (3);
8550 Def_Id : Entity_Id;
8552 procedure Check_Too_Long (Arg : Node_Id);
8553 -- Posts message if the argument is an identifier with more
8554 -- than 31 characters, or a string literal with more than
8555 -- 31 characters, and we are operating under VMS
8557 --------------------
8558 -- Check_Too_Long --
8559 --------------------
8561 procedure Check_Too_Long (Arg : Node_Id) is
8562 X : constant Node_Id := Original_Node (Arg);
8564 begin
8565 if Nkind (X) /= N_String_Literal
8566 and then
8567 Nkind (X) /= N_Identifier
8568 then
8569 Error_Pragma_Arg
8570 ("inappropriate argument for pragma %", Arg);
8571 end if;
8573 if OpenVMS_On_Target then
8574 if (Nkind (X) = N_String_Literal
8575 and then String_Length (Strval (X)) > 31)
8576 or else
8577 (Nkind (X) = N_Identifier
8578 and then Length_Of_Name (Chars (X)) > 31)
8579 then
8580 Error_Pragma_Arg
8581 ("argument for pragma % is longer than 31 characters",
8582 Arg);
8583 end if;
8584 end if;
8585 end Check_Too_Long;
8587 -- Start of processing for Common_Object/Psect_Object
8589 begin
8590 GNAT_Pragma;
8591 Gather_Associations (Names, Args);
8592 Process_Extended_Import_Export_Internal_Arg (Internal);
8594 Def_Id := Entity (Internal);
8596 if Ekind (Def_Id) /= E_Constant
8597 and then Ekind (Def_Id) /= E_Variable
8598 then
8599 Error_Pragma_Arg
8600 ("pragma% must designate an object", Internal);
8601 end if;
8603 Check_Too_Long (Internal);
8605 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
8606 Error_Pragma_Arg
8607 ("cannot use pragma% for imported/exported object",
8608 Internal);
8609 end if;
8611 if Is_Concurrent_Type (Etype (Internal)) then
8612 Error_Pragma_Arg
8613 ("cannot specify pragma % for task/protected object",
8614 Internal);
8615 end if;
8617 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
8618 or else
8619 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
8620 then
8621 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
8622 end if;
8624 if Ekind (Def_Id) = E_Constant then
8625 Error_Pragma_Arg
8626 ("cannot specify pragma % for a constant", Internal);
8627 end if;
8629 if Is_Record_Type (Etype (Internal)) then
8630 declare
8631 Ent : Entity_Id;
8632 Decl : Entity_Id;
8634 begin
8635 Ent := First_Entity (Etype (Internal));
8636 while Present (Ent) loop
8637 Decl := Declaration_Node (Ent);
8639 if Ekind (Ent) = E_Component
8640 and then Nkind (Decl) = N_Component_Declaration
8641 and then Present (Expression (Decl))
8642 and then Warn_On_Export_Import
8643 then
8644 Error_Msg_N
8645 ("?object for pragma % has defaults", Internal);
8646 exit;
8648 else
8649 Next_Entity (Ent);
8650 end if;
8651 end loop;
8652 end;
8653 end if;
8655 if Present (Size) then
8656 Check_Too_Long (Size);
8657 end if;
8659 if Present (External) then
8660 Check_Arg_Is_External_Name (External);
8661 Check_Too_Long (External);
8662 end if;
8664 -- If all error tests pass, link pragma on to the rep item chain
8666 Record_Rep_Item (Def_Id, N);
8667 end Psect_Object;
8669 ----------
8670 -- Pure --
8671 ----------
8673 -- pragma Pure [(library_unit_NAME)];
8675 when Pragma_Pure => Pure : declare
8676 Ent : Entity_Id;
8677 begin
8678 Check_Ada_83_Warning;
8679 Check_Valid_Library_Unit_Pragma;
8681 if Nkind (N) = N_Null_Statement then
8682 return;
8683 end if;
8685 Ent := Find_Lib_Unit_Name;
8686 Set_Is_Pure (Ent);
8687 Set_Suppress_Elaboration_Warnings (Ent);
8688 end Pure;
8690 -------------------
8691 -- Pure_Function --
8692 -------------------
8694 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
8696 when Pragma_Pure_Function => Pure_Function : declare
8697 E_Id : Node_Id;
8698 E : Entity_Id;
8699 Def_Id : Entity_Id;
8700 Effective : Boolean := False;
8702 begin
8703 GNAT_Pragma;
8704 Check_Arg_Count (1);
8705 Check_Optional_Identifier (Arg1, Name_Entity);
8706 Check_Arg_Is_Local_Name (Arg1);
8707 E_Id := Expression (Arg1);
8709 if Error_Posted (E_Id) then
8710 return;
8711 end if;
8713 -- Loop through homonyms (overloadings) of referenced entity
8715 E := Entity (E_Id);
8717 if Present (E) then
8718 loop
8719 Def_Id := Get_Base_Subprogram (E);
8721 if Ekind (Def_Id) /= E_Function
8722 and then Ekind (Def_Id) /= E_Generic_Function
8723 and then Ekind (Def_Id) /= E_Operator
8724 then
8725 Error_Pragma_Arg
8726 ("pragma% requires a function name", Arg1);
8727 end if;
8729 Set_Is_Pure (Def_Id);
8731 if not Has_Pragma_Pure_Function (Def_Id) then
8732 Set_Has_Pragma_Pure_Function (Def_Id);
8733 Effective := True;
8734 end if;
8736 E := Homonym (E);
8737 exit when No (E) or else Scope (E) /= Current_Scope;
8738 end loop;
8740 if not Effective
8741 and then Warn_On_Redundant_Constructs
8742 then
8743 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
8744 N, Entity (E_Id));
8745 end if;
8746 end if;
8747 end Pure_Function;
8749 --------------------
8750 -- Queuing_Policy --
8751 --------------------
8753 -- pragma Queuing_Policy (policy_IDENTIFIER);
8755 when Pragma_Queuing_Policy => declare
8756 QP : Character;
8758 begin
8759 Check_Ada_83_Warning;
8760 Check_Arg_Count (1);
8761 Check_No_Identifiers;
8762 Check_Arg_Is_Queuing_Policy (Arg1);
8763 Check_Valid_Configuration_Pragma;
8764 Get_Name_String (Chars (Expression (Arg1)));
8765 QP := Fold_Upper (Name_Buffer (1));
8767 if Queuing_Policy /= ' '
8768 and then Queuing_Policy /= QP
8769 then
8770 Error_Msg_Sloc := Queuing_Policy_Sloc;
8771 Error_Pragma ("queuing policy incompatible with policy#");
8773 -- Set new policy, but always preserve System_Location since
8774 -- we like the error message with the run time name.
8776 else
8777 Queuing_Policy := QP;
8779 if Queuing_Policy_Sloc /= System_Location then
8780 Queuing_Policy_Sloc := Loc;
8781 end if;
8782 end if;
8783 end;
8785 ---------------------------
8786 -- Remote_Call_Interface --
8787 ---------------------------
8789 -- pragma Remote_Call_Interface [(library_unit_NAME)];
8791 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
8792 Cunit_Node : Node_Id;
8793 Cunit_Ent : Entity_Id;
8794 K : Node_Kind;
8796 begin
8797 Check_Ada_83_Warning;
8798 Check_Valid_Library_Unit_Pragma;
8800 if Nkind (N) = N_Null_Statement then
8801 return;
8802 end if;
8804 Cunit_Node := Cunit (Current_Sem_Unit);
8805 K := Nkind (Unit (Cunit_Node));
8806 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8808 if K = N_Package_Declaration
8809 or else K = N_Generic_Package_Declaration
8810 or else K = N_Subprogram_Declaration
8811 or else K = N_Generic_Subprogram_Declaration
8812 or else (K = N_Subprogram_Body
8813 and then Acts_As_Spec (Unit (Cunit_Node)))
8814 then
8815 null;
8816 else
8817 Error_Pragma (
8818 "pragma% must apply to package or subprogram declaration");
8819 end if;
8821 Set_Is_Remote_Call_Interface (Cunit_Ent);
8822 end Remote_Call_Interface;
8824 ------------------
8825 -- Remote_Types --
8826 ------------------
8828 -- pragma Remote_Types [(library_unit_NAME)];
8830 when Pragma_Remote_Types => Remote_Types : declare
8831 Cunit_Node : Node_Id;
8832 Cunit_Ent : Entity_Id;
8834 begin
8835 Check_Ada_83_Warning;
8836 Check_Valid_Library_Unit_Pragma;
8838 if Nkind (N) = N_Null_Statement then
8839 return;
8840 end if;
8842 Cunit_Node := Cunit (Current_Sem_Unit);
8843 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8845 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
8846 and then
8847 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
8848 then
8849 Error_Pragma (
8850 "pragma% can only apply to a package declaration");
8851 end if;
8853 Set_Is_Remote_Types (Cunit_Ent);
8854 end Remote_Types;
8856 ---------------
8857 -- Ravenscar --
8858 ---------------
8860 -- pragma Ravenscar;
8862 when Pragma_Ravenscar =>
8863 GNAT_Pragma;
8864 Check_Arg_Count (0);
8865 Check_Valid_Configuration_Pragma;
8866 Set_Ravenscar_Profile (N);
8868 if Warn_On_Obsolescent_Feature then
8869 Error_Msg_N
8870 ("pragma Ravenscar is an obsolescent feature?", N);
8871 Error_Msg_N
8872 ("|use pragma Profile (Ravenscar) instead", N);
8873 end if;
8875 -------------------------
8876 -- Restricted_Run_Time --
8877 -------------------------
8879 -- pragma Restricted_Run_Time;
8881 when Pragma_Restricted_Run_Time =>
8882 GNAT_Pragma;
8883 Check_Arg_Count (0);
8884 Check_Valid_Configuration_Pragma;
8885 Set_Profile_Restrictions (Restricted, N, Warn => False);
8887 if Warn_On_Obsolescent_Feature then
8888 Error_Msg_N
8889 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
8890 Error_Msg_N
8891 ("|use pragma Profile (Restricted) instead", N);
8892 end if;
8894 ------------------
8895 -- Restrictions --
8896 ------------------
8898 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
8900 -- RESTRICTION ::=
8901 -- restriction_IDENTIFIER
8902 -- | restriction_parameter_IDENTIFIER => EXPRESSION
8904 when Pragma_Restrictions =>
8905 Process_Restrictions_Or_Restriction_Warnings;
8907 --------------------------
8908 -- Restriction_Warnings --
8909 --------------------------
8911 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
8913 -- RESTRICTION ::=
8914 -- restriction_IDENTIFIER
8915 -- | restriction_parameter_IDENTIFIER => EXPRESSION
8917 when Pragma_Restriction_Warnings =>
8918 Process_Restrictions_Or_Restriction_Warnings;
8920 ----------------
8921 -- Reviewable --
8922 ----------------
8924 -- pragma Reviewable;
8926 when Pragma_Reviewable =>
8927 Check_Ada_83_Warning;
8928 Check_Arg_Count (0);
8930 -------------------
8931 -- Share_Generic --
8932 -------------------
8934 -- pragma Share_Generic (NAME {, NAME});
8936 when Pragma_Share_Generic =>
8937 GNAT_Pragma;
8938 Process_Generic_List;
8940 ------------
8941 -- Shared --
8942 ------------
8944 -- pragma Shared (LOCAL_NAME);
8946 when Pragma_Shared =>
8947 GNAT_Pragma;
8948 Process_Atomic_Shared_Volatile;
8950 --------------------
8951 -- Shared_Passive --
8952 --------------------
8954 -- pragma Shared_Passive [(library_unit_NAME)];
8956 -- Set the flag Is_Shared_Passive of program unit name entity
8958 when Pragma_Shared_Passive => Shared_Passive : declare
8959 Cunit_Node : Node_Id;
8960 Cunit_Ent : Entity_Id;
8962 begin
8963 Check_Ada_83_Warning;
8964 Check_Valid_Library_Unit_Pragma;
8966 if Nkind (N) = N_Null_Statement then
8967 return;
8968 end if;
8970 Cunit_Node := Cunit (Current_Sem_Unit);
8971 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8973 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
8974 and then
8975 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
8976 then
8977 Error_Pragma (
8978 "pragma% can only apply to a package declaration");
8979 end if;
8981 Set_Is_Shared_Passive (Cunit_Ent);
8982 end Shared_Passive;
8984 ----------------------
8985 -- Source_File_Name --
8986 ----------------------
8988 -- There are five forms for this pragma:
8990 -- pragma Source_File_Name (
8991 -- [UNIT_NAME =>] unit_NAME,
8992 -- BODY_FILE_NAME => STRING_LITERAL
8993 -- [, [INDEX =>] INTEGER_LITERAL]);
8995 -- pragma Source_File_Name (
8996 -- [UNIT_NAME =>] unit_NAME,
8997 -- SPEC_FILE_NAME => STRING_LITERAL
8998 -- [, [INDEX =>] INTEGER_LITERAL]);
9000 -- pragma Source_File_Name (
9001 -- BODY_FILE_NAME => STRING_LITERAL
9002 -- [, DOT_REPLACEMENT => STRING_LITERAL]
9003 -- [, CASING => CASING_SPEC]);
9005 -- pragma Source_File_Name (
9006 -- SPEC_FILE_NAME => STRING_LITERAL
9007 -- [, DOT_REPLACEMENT => STRING_LITERAL]
9008 -- [, CASING => CASING_SPEC]);
9010 -- pragma Source_File_Name (
9011 -- SUBUNIT_FILE_NAME => STRING_LITERAL
9012 -- [, DOT_REPLACEMENT => STRING_LITERAL]
9013 -- [, CASING => CASING_SPEC]);
9015 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
9017 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
9018 -- Source_File_Name (SFN), however their usage is exclusive:
9019 -- SFN can only be used when no project file is used, while
9020 -- SFNP can only be used when a project file is used.
9022 -- No processing here. Processing was completed during parsing,
9023 -- since we need to have file names set as early as possible.
9024 -- Units are loaded well before semantic processing starts.
9026 -- The only processing we defer to this point is the check
9027 -- for correct placement.
9029 when Pragma_Source_File_Name =>
9030 GNAT_Pragma;
9031 Check_Valid_Configuration_Pragma;
9033 ------------------------------
9034 -- Source_File_Name_Project --
9035 ------------------------------
9037 -- See Source_File_Name for syntax
9039 -- No processing here. Processing was completed during parsing,
9040 -- since we need to have file names set as early as possible.
9041 -- Units are loaded well before semantic processing starts.
9043 -- The only processing we defer to this point is the check
9044 -- for correct placement.
9046 when Pragma_Source_File_Name_Project =>
9047 GNAT_Pragma;
9048 Check_Valid_Configuration_Pragma;
9050 -- Check that a pragma Source_File_Name_Project is used only
9051 -- in a configuration pragmas file.
9053 -- Pragmas Source_File_Name_Project should only be generated
9054 -- by the Project Manager in configuration pragmas files.
9056 -- This is really an ugly test. It seems to depend on some
9057 -- accidental and undocumented property. At the very least
9058 -- it needs to be documented, but it would be better to have
9059 -- a clean way of testing if we are in a configuration file???
9061 if Present (Parent (N)) then
9062 Error_Pragma
9063 ("pragma% can only appear in a configuration pragmas file");
9064 end if;
9066 ----------------------
9067 -- Source_Reference --
9068 ----------------------
9070 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
9072 -- Nothing to do, all processing completed in Par.Prag, since we
9073 -- need the information for possible parser messages that are output
9075 when Pragma_Source_Reference =>
9076 GNAT_Pragma;
9078 ------------------
9079 -- Storage_Size --
9080 ------------------
9082 -- pragma Storage_Size (EXPRESSION);
9084 when Pragma_Storage_Size => Storage_Size : declare
9085 P : constant Node_Id := Parent (N);
9086 Arg : Node_Id;
9088 begin
9089 Check_No_Identifiers;
9090 Check_Arg_Count (1);
9092 -- The expression must be analyzed in the special manner
9093 -- described in "Handling of Default Expressions" in sem.ads.
9095 -- Set In_Default_Expression for per-object case ???
9097 Arg := Expression (Arg1);
9098 Analyze_Per_Use_Expression (Arg, Any_Integer);
9100 if not Is_Static_Expression (Arg) then
9101 Check_Restriction (Static_Storage_Size, Arg);
9102 end if;
9104 if Nkind (P) /= N_Task_Definition then
9105 Pragma_Misplaced;
9106 return;
9108 else
9109 if Has_Storage_Size_Pragma (P) then
9110 Error_Pragma ("duplicate pragma% not allowed");
9111 else
9112 Set_Has_Storage_Size_Pragma (P, True);
9113 end if;
9115 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9116 -- ??? exp_ch9 should use this!
9117 end if;
9118 end Storage_Size;
9120 ------------------
9121 -- Storage_Unit --
9122 ------------------
9124 -- pragma Storage_Unit (NUMERIC_LITERAL);
9126 -- Only permitted argument is System'Storage_Unit value
9128 when Pragma_Storage_Unit =>
9129 Check_No_Identifiers;
9130 Check_Arg_Count (1);
9131 Check_Arg_Is_Integer_Literal (Arg1);
9133 if Intval (Expression (Arg1)) /=
9134 UI_From_Int (Ttypes.System_Storage_Unit)
9135 then
9136 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
9137 Error_Pragma_Arg
9138 ("the only allowed argument for pragma% is ^", Arg1);
9139 end if;
9141 --------------------
9142 -- Stream_Convert --
9143 --------------------
9145 -- pragma Stream_Convert (
9146 -- [Entity =>] type_LOCAL_NAME,
9147 -- [Read =>] function_NAME,
9148 -- [Write =>] function NAME);
9150 when Pragma_Stream_Convert => Stream_Convert : declare
9152 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
9153 -- Check that the given argument is the name of a local
9154 -- function of one argument that is not overloaded earlier
9155 -- in the current local scope. A check is also made that the
9156 -- argument is a function with one parameter.
9158 --------------------------------------
9159 -- Check_OK_Stream_Convert_Function --
9160 --------------------------------------
9162 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
9163 Ent : Entity_Id;
9165 begin
9166 Check_Arg_Is_Local_Name (Arg);
9167 Ent := Entity (Expression (Arg));
9169 if Has_Homonym (Ent) then
9170 Error_Pragma_Arg
9171 ("argument for pragma% may not be overloaded", Arg);
9172 end if;
9174 if Ekind (Ent) /= E_Function
9175 or else No (First_Formal (Ent))
9176 or else Present (Next_Formal (First_Formal (Ent)))
9177 then
9178 Error_Pragma_Arg
9179 ("argument for pragma% must be" &
9180 " function of one argument", Arg);
9181 end if;
9182 end Check_OK_Stream_Convert_Function;
9184 -- Start of procecessing for Stream_Convert
9186 begin
9187 GNAT_Pragma;
9188 Check_Arg_Count (3);
9189 Check_Optional_Identifier (Arg1, Name_Entity);
9190 Check_Optional_Identifier (Arg2, Name_Read);
9191 Check_Optional_Identifier (Arg3, Name_Write);
9192 Check_Arg_Is_Local_Name (Arg1);
9193 Check_OK_Stream_Convert_Function (Arg2);
9194 Check_OK_Stream_Convert_Function (Arg3);
9196 declare
9197 Typ : constant Entity_Id :=
9198 Underlying_Type (Entity (Expression (Arg1)));
9199 Read : constant Entity_Id := Entity (Expression (Arg2));
9200 Write : constant Entity_Id := Entity (Expression (Arg3));
9202 begin
9203 if Etype (Typ) = Any_Type
9204 or else
9205 Etype (Read) = Any_Type
9206 or else
9207 Etype (Write) = Any_Type
9208 then
9209 return;
9210 end if;
9212 Check_First_Subtype (Arg1);
9214 if Rep_Item_Too_Early (Typ, N)
9215 or else
9216 Rep_Item_Too_Late (Typ, N)
9217 then
9218 return;
9219 end if;
9221 if Underlying_Type (Etype (Read)) /= Typ then
9222 Error_Pragma_Arg
9223 ("incorrect return type for function&", Arg2);
9224 end if;
9226 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
9227 Error_Pragma_Arg
9228 ("incorrect parameter type for function&", Arg3);
9229 end if;
9231 if Underlying_Type (Etype (First_Formal (Read))) /=
9232 Underlying_Type (Etype (Write))
9233 then
9234 Error_Pragma_Arg
9235 ("result type of & does not match Read parameter type",
9236 Arg3);
9237 end if;
9238 end;
9239 end Stream_Convert;
9241 -------------------------
9242 -- Style_Checks (GNAT) --
9243 -------------------------
9245 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
9247 -- This is processed by the parser since some of the style
9248 -- checks take place during source scanning and parsing. This
9249 -- means that we don't need to issue error messages here.
9251 when Pragma_Style_Checks => Style_Checks : declare
9252 A : constant Node_Id := Expression (Arg1);
9253 S : String_Id;
9254 C : Char_Code;
9256 begin
9257 GNAT_Pragma;
9258 Check_No_Identifiers;
9260 -- Two argument form
9262 if Arg_Count = 2 then
9263 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9265 declare
9266 E_Id : Node_Id;
9267 E : Entity_Id;
9269 begin
9270 E_Id := Expression (Arg2);
9271 Analyze (E_Id);
9273 if not Is_Entity_Name (E_Id) then
9274 Error_Pragma_Arg
9275 ("second argument of pragma% must be entity name",
9276 Arg2);
9277 end if;
9279 E := Entity (E_Id);
9281 if E = Any_Id then
9282 return;
9283 else
9284 loop
9285 Set_Suppress_Style_Checks (E,
9286 (Chars (Expression (Arg1)) = Name_Off));
9287 exit when No (Homonym (E));
9288 E := Homonym (E);
9289 end loop;
9290 end if;
9291 end;
9293 -- One argument form
9295 else
9296 Check_Arg_Count (1);
9298 if Nkind (A) = N_String_Literal then
9299 S := Strval (A);
9301 declare
9302 Slen : constant Natural := Natural (String_Length (S));
9303 Options : String (1 .. Slen);
9304 J : Natural;
9306 begin
9307 J := 1;
9308 loop
9309 C := Get_String_Char (S, Int (J));
9310 exit when not In_Character_Range (C);
9311 Options (J) := Get_Character (C);
9313 if J = Slen then
9314 Set_Style_Check_Options (Options);
9315 exit;
9316 else
9317 J := J + 1;
9318 end if;
9319 end loop;
9320 end;
9322 elsif Nkind (A) = N_Identifier then
9324 if Chars (A) = Name_All_Checks then
9325 Set_Default_Style_Check_Options;
9327 elsif Chars (A) = Name_On then
9328 Style_Check := True;
9330 elsif Chars (A) = Name_Off then
9331 Style_Check := False;
9333 end if;
9334 end if;
9335 end if;
9336 end Style_Checks;
9338 --------------
9339 -- Subtitle --
9340 --------------
9342 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
9344 when Pragma_Subtitle =>
9345 GNAT_Pragma;
9346 Check_Arg_Count (1);
9347 Check_Optional_Identifier (Arg1, Name_Subtitle);
9348 Check_Arg_Is_String_Literal (Arg1);
9350 --------------
9351 -- Suppress --
9352 --------------
9354 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
9356 when Pragma_Suppress =>
9357 Process_Suppress_Unsuppress (True);
9359 ------------------
9360 -- Suppress_All --
9361 ------------------
9363 -- pragma Suppress_All;
9365 -- The only check made here is that the pragma appears in the
9366 -- proper place, i.e. following a compilation unit. If indeed
9367 -- it appears in this context, then the parser has already
9368 -- inserted an equivalent pragma Suppress (All_Checks) to get
9369 -- the required effect.
9371 when Pragma_Suppress_All =>
9372 GNAT_Pragma;
9373 Check_Arg_Count (0);
9375 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9376 or else not Is_List_Member (N)
9377 or else List_Containing (N) /= Pragmas_After (Parent (N))
9378 then
9379 Error_Pragma
9380 ("misplaced pragma%, must follow compilation unit");
9381 end if;
9383 -------------------------
9384 -- Suppress_Debug_Info --
9385 -------------------------
9387 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
9389 when Pragma_Suppress_Debug_Info =>
9390 GNAT_Pragma;
9391 Check_Arg_Count (1);
9392 Check_Arg_Is_Local_Name (Arg1);
9393 Check_Optional_Identifier (Arg1, Name_Entity);
9394 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
9396 ----------------------------------
9397 -- Suppress_Exception_Locations --
9398 ----------------------------------
9400 -- pragma Suppress_Exception_Locations;
9402 when Pragma_Suppress_Exception_Locations =>
9403 GNAT_Pragma;
9404 Check_Arg_Count (0);
9405 Check_Valid_Configuration_Pragma;
9406 Exception_Locations_Suppressed := True;
9408 -----------------------------
9409 -- Suppress_Initialization --
9410 -----------------------------
9412 -- pragma Suppress_Initialization ([Entity =>] type_Name);
9414 when Pragma_Suppress_Initialization => Suppress_Init : declare
9415 E_Id : Node_Id;
9416 E : Entity_Id;
9418 begin
9419 GNAT_Pragma;
9420 Check_Arg_Count (1);
9421 Check_Optional_Identifier (Arg1, Name_Entity);
9422 Check_Arg_Is_Local_Name (Arg1);
9424 E_Id := Expression (Arg1);
9426 if Etype (E_Id) = Any_Type then
9427 return;
9428 end if;
9430 E := Entity (E_Id);
9432 if Is_Type (E) then
9433 if Is_Incomplete_Or_Private_Type (E) then
9434 if No (Full_View (Base_Type (E))) then
9435 Error_Pragma_Arg
9436 ("argument of pragma% cannot be an incomplete type",
9437 Arg1);
9438 else
9439 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
9440 end if;
9441 else
9442 Set_Suppress_Init_Proc (Base_Type (E));
9443 end if;
9445 else
9446 Error_Pragma_Arg
9447 ("pragma% requires argument that is a type name", Arg1);
9448 end if;
9449 end Suppress_Init;
9451 -----------------
9452 -- System_Name --
9453 -----------------
9455 -- pragma System_Name (DIRECT_NAME);
9457 -- Syntax check: one argument, which must be the identifier GNAT
9458 -- or the identifier GCC, no other identifiers are acceptable.
9460 when Pragma_System_Name =>
9461 Check_No_Identifiers;
9462 Check_Arg_Count (1);
9463 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
9465 -----------------------------
9466 -- Task_Dispatching_Policy --
9467 -----------------------------
9469 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
9471 when Pragma_Task_Dispatching_Policy => declare
9472 DP : Character;
9474 begin
9475 Check_Ada_83_Warning;
9476 Check_Arg_Count (1);
9477 Check_No_Identifiers;
9478 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9479 Check_Valid_Configuration_Pragma;
9480 Get_Name_String (Chars (Expression (Arg1)));
9481 DP := Fold_Upper (Name_Buffer (1));
9483 if Task_Dispatching_Policy /= ' '
9484 and then Task_Dispatching_Policy /= DP
9485 then
9486 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9487 Error_Pragma
9488 ("task dispatching policy incompatible with policy#");
9490 -- Set new policy, but always preserve System_Location since
9491 -- we like the error message with the run time name.
9493 else
9494 Task_Dispatching_Policy := DP;
9496 if Task_Dispatching_Policy_Sloc /= System_Location then
9497 Task_Dispatching_Policy_Sloc := Loc;
9498 end if;
9499 end if;
9500 end;
9502 --------------
9503 -- Task_Info --
9504 --------------
9506 -- pragma Task_Info (EXPRESSION);
9508 when Pragma_Task_Info => Task_Info : declare
9509 P : constant Node_Id := Parent (N);
9511 begin
9512 GNAT_Pragma;
9514 if Nkind (P) /= N_Task_Definition then
9515 Error_Pragma ("pragma% must appear in task definition");
9516 end if;
9518 Check_No_Identifiers;
9519 Check_Arg_Count (1);
9521 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
9523 if Etype (Expression (Arg1)) = Any_Type then
9524 return;
9525 end if;
9527 if Has_Task_Info_Pragma (P) then
9528 Error_Pragma ("duplicate pragma% not allowed");
9529 else
9530 Set_Has_Task_Info_Pragma (P, True);
9531 end if;
9532 end Task_Info;
9534 ---------------
9535 -- Task_Name --
9536 ---------------
9538 -- pragma Task_Name (string_EXPRESSION);
9540 when Pragma_Task_Name => Task_Name : declare
9541 -- pragma Priority (EXPRESSION);
9543 P : constant Node_Id := Parent (N);
9544 Arg : Node_Id;
9546 begin
9547 Check_No_Identifiers;
9548 Check_Arg_Count (1);
9550 Arg := Expression (Arg1);
9551 Analyze_And_Resolve (Arg, Standard_String);
9553 if Nkind (P) /= N_Task_Definition then
9554 Pragma_Misplaced;
9555 end if;
9557 if Has_Task_Name_Pragma (P) then
9558 Error_Pragma ("duplicate pragma% not allowed");
9559 else
9560 Set_Has_Task_Name_Pragma (P, True);
9561 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9562 end if;
9563 end Task_Name;
9565 ------------------
9566 -- Task_Storage --
9567 ------------------
9569 -- pragma Task_Storage (
9570 -- [Task_Type =>] LOCAL_NAME,
9571 -- [Top_Guard =>] static_integer_EXPRESSION);
9573 when Pragma_Task_Storage => Task_Storage : declare
9574 Args : Args_List (1 .. 2);
9575 Names : constant Name_List (1 .. 2) := (
9576 Name_Task_Type,
9577 Name_Top_Guard);
9579 Task_Type : Node_Id renames Args (1);
9580 Top_Guard : Node_Id renames Args (2);
9582 Ent : Entity_Id;
9584 begin
9585 GNAT_Pragma;
9586 Gather_Associations (Names, Args);
9588 if No (Task_Type) then
9589 Error_Pragma
9590 ("missing task_type argument for pragma%");
9591 end if;
9593 Check_Arg_Is_Local_Name (Task_Type);
9595 Ent := Entity (Task_Type);
9597 if not Is_Task_Type (Ent) then
9598 Error_Pragma_Arg
9599 ("argument for pragma% must be task type", Task_Type);
9600 end if;
9602 if No (Top_Guard) then
9603 Error_Pragma_Arg
9604 ("pragma% takes two arguments", Task_Type);
9605 else
9606 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
9607 end if;
9609 Check_First_Subtype (Task_Type);
9611 if Rep_Item_Too_Late (Ent, N) then
9612 raise Pragma_Exit;
9613 end if;
9614 end Task_Storage;
9616 -----------------
9617 -- Thread_Body --
9618 -----------------
9620 -- pragma Thread_Body
9621 -- ( [Entity =>] LOCAL_NAME
9622 -- [,[Secondary_Stack_Size =>] static_integer_EXPRESSION]);
9624 when Pragma_Thread_Body => Thread_Body : declare
9625 Id : Node_Id;
9626 SS : Node_Id;
9627 E : Entity_Id;
9629 begin
9630 GNAT_Pragma;
9631 Check_At_Least_N_Arguments (1);
9632 Check_At_Most_N_Arguments (2);
9633 Check_Optional_Identifier (Arg1, Name_Entity);
9634 Check_Arg_Is_Local_Name (Arg1);
9636 Id := Expression (Arg1);
9638 if not Is_Entity_Name (Id)
9639 or else not Is_Subprogram (Entity (Id))
9640 then
9641 Error_Pragma_Arg ("subprogram name required", Arg1);
9642 end if;
9644 E := Entity (Id);
9646 -- Go to renamed subprogram if present, since Thread_Body applies
9647 -- to the actual renamed entity, not to the renaming entity.
9649 if Present (Alias (E))
9650 and then Nkind (Parent (Declaration_Node (E))) =
9651 N_Subprogram_Renaming_Declaration
9652 then
9653 E := Alias (E);
9654 end if;
9656 -- Various error checks
9658 if Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body then
9659 Error_Pragma
9660 ("pragma% requires separate spec and must come before body");
9662 elsif Rep_Item_Too_Early (E, N)
9663 or else
9664 Rep_Item_Too_Late (E, N)
9665 then
9666 raise Pragma_Exit;
9668 elsif Is_Thread_Body (E) then
9669 Error_Pragma_Arg
9670 ("only one thread body pragma allowed", Arg1);
9672 elsif Present (Homonym (E))
9673 and then Scope (Homonym (E)) = Current_Scope
9674 then
9675 Error_Pragma_Arg
9676 ("thread body subprogram must not be overloaded", Arg1);
9677 end if;
9679 Set_Is_Thread_Body (E);
9681 -- Deal with secondary stack argument
9683 if Arg_Count = 2 then
9684 Check_Optional_Identifier (Arg2, Name_Secondary_Stack_Size);
9685 SS := Expression (Arg2);
9686 Analyze_And_Resolve (SS, Any_Integer);
9687 end if;
9688 end Thread_Body;
9690 ----------------
9691 -- Time_Slice --
9692 ----------------
9694 -- pragma Time_Slice (static_duration_EXPRESSION);
9696 when Pragma_Time_Slice => Time_Slice : declare
9697 Val : Ureal;
9698 Nod : Node_Id;
9700 begin
9701 GNAT_Pragma;
9702 Check_Arg_Count (1);
9703 Check_No_Identifiers;
9704 Check_In_Main_Program;
9705 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
9707 if not Error_Posted (Arg1) then
9708 Nod := Next (N);
9709 while Present (Nod) loop
9710 if Nkind (Nod) = N_Pragma
9711 and then Chars (Nod) = Name_Time_Slice
9712 then
9713 Error_Msg_Name_1 := Chars (N);
9714 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9715 end if;
9717 Next (Nod);
9718 end loop;
9719 end if;
9721 -- Process only if in main unit
9723 if Get_Source_Unit (Loc) = Main_Unit then
9724 Opt.Time_Slice_Set := True;
9725 Val := Expr_Value_R (Expression (Arg1));
9727 if Val <= Ureal_0 then
9728 Opt.Time_Slice_Value := 0;
9730 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
9731 Opt.Time_Slice_Value := 1_000_000_000;
9733 else
9734 Opt.Time_Slice_Value :=
9735 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
9736 end if;
9737 end if;
9738 end Time_Slice;
9740 -----------
9741 -- Title --
9742 -----------
9744 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
9746 -- TITLING_OPTION ::=
9747 -- [Title =>] STRING_LITERAL
9748 -- | [Subtitle =>] STRING_LITERAL
9750 when Pragma_Title => Title : declare
9751 Args : Args_List (1 .. 2);
9752 Names : constant Name_List (1 .. 2) := (
9753 Name_Title,
9754 Name_Subtitle);
9756 begin
9757 GNAT_Pragma;
9758 Gather_Associations (Names, Args);
9760 for J in 1 .. 2 loop
9761 if Present (Args (J)) then
9762 Check_Arg_Is_String_Literal (Args (J));
9763 end if;
9764 end loop;
9765 end Title;
9767 ---------------------
9768 -- Unchecked_Union --
9769 ---------------------
9771 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
9773 when Pragma_Unchecked_Union => Unchecked_Union : declare
9774 Assoc : constant Node_Id := Arg1;
9775 Type_Id : constant Node_Id := Expression (Assoc);
9776 Typ : Entity_Id;
9777 Discr : Entity_Id;
9778 Tdef : Node_Id;
9779 Clist : Node_Id;
9780 Vpart : Node_Id;
9781 Comp : Node_Id;
9782 Variant : Node_Id;
9784 begin
9785 GNAT_Pragma;
9786 Check_No_Identifiers;
9787 Check_Arg_Count (1);
9788 Check_Arg_Is_Local_Name (Arg1);
9790 Find_Type (Type_Id);
9791 Typ := Entity (Type_Id);
9793 if Typ = Any_Type
9794 or else Rep_Item_Too_Early (Typ, N)
9795 then
9796 return;
9797 else
9798 Typ := Underlying_Type (Typ);
9799 end if;
9801 if Rep_Item_Too_Late (Typ, N) then
9802 return;
9803 end if;
9805 Check_First_Subtype (Arg1);
9807 -- Note remaining cases are references to a type in the current
9808 -- declarative part. If we find an error, we post the error on
9809 -- the relevant type declaration at an appropriate point.
9811 if not Is_Record_Type (Typ) then
9812 Error_Msg_N ("Unchecked_Union must be record type", Typ);
9813 return;
9815 elsif Is_Tagged_Type (Typ) then
9816 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
9817 return;
9819 elsif Is_Limited_Type (Typ) then
9820 Error_Msg_N
9821 ("Unchecked_Union must not be limited record type", Typ);
9822 Explain_Limited_Type (Typ, Typ);
9823 return;
9825 else
9826 if not Has_Discriminants (Typ) then
9827 Error_Msg_N
9828 ("Unchecked_Union must have one discriminant", Typ);
9829 return;
9830 end if;
9832 Discr := First_Discriminant (Typ);
9834 if Present (Next_Discriminant (Discr)) then
9835 Error_Msg_N
9836 ("Unchecked_Union must have exactly one discriminant",
9837 Next_Discriminant (Discr));
9838 return;
9839 end if;
9841 if No (Discriminant_Default_Value (Discr)) then
9842 Error_Msg_N
9843 ("Unchecked_Union discriminant must have default value",
9844 Discr);
9845 end if;
9847 Tdef := Type_Definition (Declaration_Node (Typ));
9848 Clist := Component_List (Tdef);
9850 Comp := First (Component_Items (Clist));
9851 while Present (Comp) loop
9853 Check_Component (Comp);
9854 Next (Comp);
9856 end loop;
9858 if No (Clist) or else No (Variant_Part (Clist)) then
9859 Error_Msg_N
9860 ("Unchecked_Union must have variant part",
9861 Tdef);
9862 return;
9863 end if;
9865 Vpart := Variant_Part (Clist);
9867 Variant := First (Variants (Vpart));
9868 while Present (Variant) loop
9869 Check_Variant (Variant);
9870 Next (Variant);
9871 end loop;
9872 end if;
9874 Set_Is_Unchecked_Union (Typ, True);
9875 Set_Convention (Typ, Convention_C);
9877 Set_Has_Unchecked_Union (Base_Type (Typ), True);
9878 Set_Is_Unchecked_Union (Base_Type (Typ), True);
9879 end Unchecked_Union;
9881 ------------------------
9882 -- Unimplemented_Unit --
9883 ------------------------
9885 -- pragma Unimplemented_Unit;
9887 -- Note: this only gives an error if we are generating code,
9888 -- or if we are in a generic library unit (where the pragma
9889 -- appears in the body, not in the spec).
9891 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
9892 Cunitent : constant Entity_Id :=
9893 Cunit_Entity (Get_Source_Unit (Loc));
9894 Ent_Kind : constant Entity_Kind :=
9895 Ekind (Cunitent);
9897 begin
9898 GNAT_Pragma;
9899 Check_Arg_Count (0);
9901 if Operating_Mode = Generate_Code
9902 or else Ent_Kind = E_Generic_Function
9903 or else Ent_Kind = E_Generic_Procedure
9904 or else Ent_Kind = E_Generic_Package
9905 then
9906 Get_Name_String (Chars (Cunitent));
9907 Set_Casing (Mixed_Case);
9908 Write_Str (Name_Buffer (1 .. Name_Len));
9909 Write_Str (" is not implemented");
9910 Write_Eol;
9911 raise Unrecoverable_Error;
9912 end if;
9913 end Unimplemented_Unit;
9915 --------------------
9916 -- Universal_Data --
9917 --------------------
9919 -- pragma Universal_Data [(library_unit_NAME)];
9921 when Pragma_Universal_Data =>
9922 GNAT_Pragma;
9924 -- If this is a configuration pragma, then set the universal
9925 -- addressing option, otherwise confirm that the pragma
9926 -- satisfies the requirements of library unit pragma placement
9927 -- and leave it to the GNAAMP back end to detect the pragma
9928 -- (avoids transitive setting of the option due to withed units).
9930 if Is_Configuration_Pragma then
9931 Universal_Addressing_On_AAMP := True;
9932 else
9933 Check_Valid_Library_Unit_Pragma;
9934 end if;
9936 if not AAMP_On_Target then
9937 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
9938 end if;
9940 ------------------
9941 -- Unreferenced --
9942 ------------------
9944 -- pragma Unreferenced (local_Name {, local_Name});
9946 when Pragma_Unreferenced => Unreferenced : declare
9947 Arg_Node : Node_Id;
9948 Arg_Expr : Node_Id;
9949 Arg_Ent : Entity_Id;
9951 begin
9952 GNAT_Pragma;
9953 Check_At_Least_N_Arguments (1);
9955 Arg_Node := Arg1;
9956 while Present (Arg_Node) loop
9957 Check_No_Identifier (Arg_Node);
9959 -- Note that the analyze call done by Check_Arg_Is_Local_Name
9960 -- will in fact generate a reference, so that the entity will
9961 -- have a reference, which will inhibit any warnings about it
9962 -- not being referenced, and also properly show up in the ali
9963 -- file as a reference. But this reference is recorded before
9964 -- the Has_Pragma_Unreferenced flag is set, so that no warning
9965 -- is generated for this reference.
9967 Check_Arg_Is_Local_Name (Arg_Node);
9968 Arg_Expr := Get_Pragma_Arg (Arg_Node);
9970 if Is_Entity_Name (Arg_Expr) then
9971 Arg_Ent := Entity (Arg_Expr);
9973 -- If the entity is overloaded, the pragma applies to the
9974 -- most recent overloading, as documented. In this case,
9975 -- name resolution does not generate a reference, so it
9976 -- must be done here explicitly.
9978 if Is_Overloaded (Arg_Expr) then
9979 Generate_Reference (Arg_Ent, N);
9980 end if;
9982 Set_Has_Pragma_Unreferenced (Arg_Ent);
9983 end if;
9985 Next (Arg_Node);
9986 end loop;
9987 end Unreferenced;
9989 ------------------------------
9990 -- Unreserve_All_Interrupts --
9991 ------------------------------
9993 -- pragma Unreserve_All_Interrupts;
9995 when Pragma_Unreserve_All_Interrupts =>
9996 GNAT_Pragma;
9997 Check_Arg_Count (0);
9999 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
10000 Unreserve_All_Interrupts := True;
10001 end if;
10003 ----------------
10004 -- Unsuppress --
10005 ----------------
10007 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
10009 when Pragma_Unsuppress =>
10010 GNAT_Pragma;
10011 Process_Suppress_Unsuppress (False);
10013 -------------------
10014 -- Use_VADS_Size --
10015 -------------------
10017 -- pragma Use_VADS_Size;
10019 when Pragma_Use_VADS_Size =>
10020 GNAT_Pragma;
10021 Check_Arg_Count (0);
10022 Check_Valid_Configuration_Pragma;
10023 Use_VADS_Size := True;
10025 ---------------------
10026 -- Validity_Checks --
10027 ---------------------
10029 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
10031 when Pragma_Validity_Checks => Validity_Checks : declare
10032 A : constant Node_Id := Expression (Arg1);
10033 S : String_Id;
10034 C : Char_Code;
10036 begin
10037 GNAT_Pragma;
10038 Check_Arg_Count (1);
10039 Check_No_Identifiers;
10041 if Nkind (A) = N_String_Literal then
10042 S := Strval (A);
10044 declare
10045 Slen : constant Natural := Natural (String_Length (S));
10046 Options : String (1 .. Slen);
10047 J : Natural;
10049 begin
10050 J := 1;
10051 loop
10052 C := Get_String_Char (S, Int (J));
10053 exit when not In_Character_Range (C);
10054 Options (J) := Get_Character (C);
10056 if J = Slen then
10057 Set_Validity_Check_Options (Options);
10058 exit;
10059 else
10060 J := J + 1;
10061 end if;
10062 end loop;
10063 end;
10065 elsif Nkind (A) = N_Identifier then
10067 if Chars (A) = Name_All_Checks then
10068 Set_Validity_Check_Options ("a");
10070 elsif Chars (A) = Name_On then
10071 Validity_Checks_On := True;
10073 elsif Chars (A) = Name_Off then
10074 Validity_Checks_On := False;
10076 end if;
10077 end if;
10078 end Validity_Checks;
10080 --------------
10081 -- Volatile --
10082 --------------
10084 -- pragma Volatile (LOCAL_NAME);
10086 when Pragma_Volatile =>
10087 Process_Atomic_Shared_Volatile;
10089 -------------------------
10090 -- Volatile_Components --
10091 -------------------------
10093 -- pragma Volatile_Components (array_LOCAL_NAME);
10095 -- Volatile is handled by the same circuit as Atomic_Components
10097 --------------
10098 -- Warnings --
10099 --------------
10101 -- pragma Warnings (On | Off, [LOCAL_NAME])
10103 when Pragma_Warnings => Warnings : begin
10104 GNAT_Pragma;
10105 Check_At_Least_N_Arguments (1);
10106 Check_At_Most_N_Arguments (2);
10107 Check_No_Identifiers;
10109 -- One argument case was processed by parser in Par.Prag
10111 if Arg_Count /= 1 then
10112 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10113 Check_Arg_Count (2);
10115 declare
10116 E_Id : Node_Id;
10117 E : Entity_Id;
10119 begin
10120 E_Id := Expression (Arg2);
10121 Analyze (E_Id);
10123 -- In the expansion of an inlined body, a reference to
10124 -- the formal may be wrapped in a conversion if the actual
10125 -- is a conversion. Retrieve the real entity name.
10127 if (In_Instance_Body
10128 or else In_Inlined_Body)
10129 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
10130 then
10131 E_Id := Expression (E_Id);
10132 end if;
10134 if not Is_Entity_Name (E_Id) then
10135 Error_Pragma_Arg
10136 ("second argument of pragma% must be entity name",
10137 Arg2);
10138 end if;
10140 E := Entity (E_Id);
10142 if E = Any_Id then
10143 return;
10144 else
10145 loop
10146 Set_Warnings_Off (E,
10147 (Chars (Expression (Arg1)) = Name_Off));
10149 if Is_Enumeration_Type (E) then
10150 declare
10151 Lit : Entity_Id;
10152 begin
10153 Lit := First_Literal (E);
10154 while Present (Lit) loop
10155 Set_Warnings_Off (Lit);
10156 Next_Literal (Lit);
10157 end loop;
10158 end;
10159 end if;
10161 exit when No (Homonym (E));
10162 E := Homonym (E);
10163 end loop;
10164 end if;
10165 end;
10166 end if;
10167 end Warnings;
10169 -------------------
10170 -- Weak_External --
10171 -------------------
10173 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
10175 when Pragma_Weak_External => Weak_External : declare
10176 Ent : Entity_Id;
10178 begin
10179 GNAT_Pragma;
10180 Check_Arg_Count (1);
10181 Check_Optional_Identifier (Arg1, Name_Entity);
10182 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10183 Ent := Entity (Expression (Arg1));
10185 if Rep_Item_Too_Early (Ent, N) then
10186 return;
10187 else
10188 Ent := Underlying_Type (Ent);
10189 end if;
10191 -- The only processing required is to link this item on to the
10192 -- list of rep items for the given entity. This is accomplished
10193 -- by the call to Rep_Item_Too_Late (when no error is detected
10194 -- and False is returned).
10196 if Rep_Item_Too_Late (Ent, N) then
10197 return;
10198 else
10199 Set_Has_Gigi_Rep_Item (Ent);
10200 end if;
10201 end Weak_External;
10203 --------------------
10204 -- Unknown_Pragma --
10205 --------------------
10207 -- Should be impossible, since the case of an unknown pragma is
10208 -- separately processed before the case statement is entered.
10210 when Unknown_Pragma =>
10211 raise Program_Error;
10212 end case;
10214 exception
10215 when Pragma_Exit => null;
10216 end Analyze_Pragma;
10218 ---------------------------------
10219 -- Delay_Config_Pragma_Analyze --
10220 ---------------------------------
10222 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
10223 begin
10224 return Chars (N) = Name_Interrupt_State;
10225 end Delay_Config_Pragma_Analyze;
10227 -------------------------
10228 -- Get_Base_Subprogram --
10229 -------------------------
10231 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
10232 Result : Entity_Id;
10234 begin
10235 -- Follow subprogram renaming chain
10237 Result := Def_Id;
10238 while Is_Subprogram (Result)
10239 and then
10240 (Is_Generic_Instance (Result)
10241 or else Nkind (Parent (Declaration_Node (Result))) =
10242 N_Subprogram_Renaming_Declaration)
10243 and then Present (Alias (Result))
10244 loop
10245 Result := Alias (Result);
10246 end loop;
10248 return Result;
10249 end Get_Base_Subprogram;
10251 -----------------------------
10252 -- Is_Config_Static_String --
10253 -----------------------------
10255 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
10257 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
10258 -- This is an internal recursive function that is just like the
10259 -- outer function except that it adds the string to the name buffer
10260 -- rather than placing the string in the name buffer.
10262 ------------------------------
10263 -- Add_Config_Static_String --
10264 ------------------------------
10266 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
10267 N : Node_Id;
10268 C : Char_Code;
10270 begin
10271 N := Arg;
10273 if Nkind (N) = N_Op_Concat then
10274 if Add_Config_Static_String (Left_Opnd (N)) then
10275 N := Right_Opnd (N);
10276 else
10277 return False;
10278 end if;
10279 end if;
10281 if Nkind (N) /= N_String_Literal then
10282 Error_Msg_N ("string literal expected for pragma argument", N);
10283 return False;
10285 else
10286 for J in 1 .. String_Length (Strval (N)) loop
10287 C := Get_String_Char (Strval (N), J);
10289 if not In_Character_Range (C) then
10290 Error_Msg
10291 ("string literal contains invalid wide character",
10292 Sloc (N) + 1 + Source_Ptr (J));
10293 return False;
10294 end if;
10296 Add_Char_To_Name_Buffer (Get_Character (C));
10297 end loop;
10298 end if;
10300 return True;
10301 end Add_Config_Static_String;
10303 -- Start of prorcessing for Is_Config_Static_String
10305 begin
10307 Name_Len := 0;
10308 return Add_Config_Static_String (Arg);
10309 end Is_Config_Static_String;
10311 -----------------------------------------
10312 -- Is_Non_Significant_Pragma_Reference --
10313 -----------------------------------------
10315 -- This function makes use of the following static table which indicates
10316 -- whether a given pragma is significant. A value of -1 in this table
10317 -- indicates that the reference is significant. A value of zero indicates
10318 -- than appearence as any argument is insignificant, a positive value
10319 -- indicates that appearence in that parameter position is significant.
10321 Sig_Flags : constant array (Pragma_Id) of Int :=
10323 (Pragma_AST_Entry => -1,
10324 Pragma_Abort_Defer => -1,
10325 Pragma_Ada_83 => -1,
10326 Pragma_Ada_95 => -1,
10327 Pragma_Ada_05 => -1,
10328 Pragma_All_Calls_Remote => -1,
10329 Pragma_Annotate => -1,
10330 Pragma_Assert => -1,
10331 Pragma_Asynchronous => -1,
10332 Pragma_Atomic => 0,
10333 Pragma_Atomic_Components => 0,
10334 Pragma_Attach_Handler => -1,
10335 Pragma_CPP_Class => 0,
10336 Pragma_CPP_Constructor => 0,
10337 Pragma_CPP_Virtual => 0,
10338 Pragma_CPP_Vtable => 0,
10339 Pragma_C_Pass_By_Copy => 0,
10340 Pragma_Comment => 0,
10341 Pragma_Common_Object => -1,
10342 Pragma_Compile_Time_Warning => -1,
10343 Pragma_Complex_Representation => 0,
10344 Pragma_Component_Alignment => -1,
10345 Pragma_Controlled => 0,
10346 Pragma_Convention => 0,
10347 Pragma_Convention_Identifier => 0,
10348 Pragma_Debug => -1,
10349 Pragma_Detect_Blocking => -1,
10350 Pragma_Discard_Names => 0,
10351 Pragma_Elaborate => -1,
10352 Pragma_Elaborate_All => -1,
10353 Pragma_Elaborate_Body => -1,
10354 Pragma_Elaboration_Checks => -1,
10355 Pragma_Eliminate => -1,
10356 Pragma_Explicit_Overriding => -1,
10357 Pragma_Export => -1,
10358 Pragma_Export_Exception => -1,
10359 Pragma_Export_Function => -1,
10360 Pragma_Export_Object => -1,
10361 Pragma_Export_Procedure => -1,
10362 Pragma_Export_Value => -1,
10363 Pragma_Export_Valued_Procedure => -1,
10364 Pragma_Extend_System => -1,
10365 Pragma_Extensions_Allowed => -1,
10366 Pragma_External => -1,
10367 Pragma_External_Name_Casing => -1,
10368 Pragma_Finalize_Storage_Only => 0,
10369 Pragma_Float_Representation => 0,
10370 Pragma_Ident => -1,
10371 Pragma_Import => +2,
10372 Pragma_Import_Exception => 0,
10373 Pragma_Import_Function => 0,
10374 Pragma_Import_Object => 0,
10375 Pragma_Import_Procedure => 0,
10376 Pragma_Import_Valued_Procedure => 0,
10377 Pragma_Initialize_Scalars => -1,
10378 Pragma_Inline => 0,
10379 Pragma_Inline_Always => 0,
10380 Pragma_Inline_Generic => 0,
10381 Pragma_Inspection_Point => -1,
10382 Pragma_Interface => +2,
10383 Pragma_Interface_Name => +2,
10384 Pragma_Interrupt_Handler => -1,
10385 Pragma_Interrupt_Priority => -1,
10386 Pragma_Interrupt_State => -1,
10387 Pragma_Java_Constructor => -1,
10388 Pragma_Java_Interface => -1,
10389 Pragma_Keep_Names => 0,
10390 Pragma_License => -1,
10391 Pragma_Link_With => -1,
10392 Pragma_Linker_Alias => -1,
10393 Pragma_Linker_Options => -1,
10394 Pragma_Linker_Section => -1,
10395 Pragma_List => -1,
10396 Pragma_Locking_Policy => -1,
10397 Pragma_Long_Float => -1,
10398 Pragma_Machine_Attribute => -1,
10399 Pragma_Main => -1,
10400 Pragma_Main_Storage => -1,
10401 Pragma_Memory_Size => -1,
10402 Pragma_No_Return => 0,
10403 Pragma_No_Run_Time => -1,
10404 Pragma_No_Strict_Aliasing => -1,
10405 Pragma_Normalize_Scalars => -1,
10406 Pragma_Obsolescent => 0,
10407 Pragma_Optimize => -1,
10408 Pragma_Optional_Overriding => -1,
10409 Pragma_Pack => 0,
10410 Pragma_Page => -1,
10411 Pragma_Passive => -1,
10412 Pragma_Polling => -1,
10413 Pragma_Persistent_Data => -1,
10414 Pragma_Persistent_Object => -1,
10415 Pragma_Preelaborate => -1,
10416 Pragma_Priority => -1,
10417 Pragma_Profile => 0,
10418 Pragma_Profile_Warnings => 0,
10419 Pragma_Propagate_Exceptions => -1,
10420 Pragma_Psect_Object => -1,
10421 Pragma_Pure => 0,
10422 Pragma_Pure_Function => 0,
10423 Pragma_Queuing_Policy => -1,
10424 Pragma_Ravenscar => -1,
10425 Pragma_Remote_Call_Interface => -1,
10426 Pragma_Remote_Types => -1,
10427 Pragma_Restricted_Run_Time => -1,
10428 Pragma_Restriction_Warnings => -1,
10429 Pragma_Restrictions => -1,
10430 Pragma_Reviewable => -1,
10431 Pragma_Share_Generic => -1,
10432 Pragma_Shared => -1,
10433 Pragma_Shared_Passive => -1,
10434 Pragma_Source_File_Name => -1,
10435 Pragma_Source_File_Name_Project => -1,
10436 Pragma_Source_Reference => -1,
10437 Pragma_Storage_Size => -1,
10438 Pragma_Storage_Unit => -1,
10439 Pragma_Stream_Convert => -1,
10440 Pragma_Style_Checks => -1,
10441 Pragma_Subtitle => -1,
10442 Pragma_Suppress => 0,
10443 Pragma_Suppress_Exception_Locations => 0,
10444 Pragma_Suppress_All => -1,
10445 Pragma_Suppress_Debug_Info => 0,
10446 Pragma_Suppress_Initialization => 0,
10447 Pragma_System_Name => -1,
10448 Pragma_Task_Dispatching_Policy => -1,
10449 Pragma_Task_Info => -1,
10450 Pragma_Task_Name => -1,
10451 Pragma_Task_Storage => 0,
10452 Pragma_Thread_Body => +2,
10453 Pragma_Time_Slice => -1,
10454 Pragma_Title => -1,
10455 Pragma_Unchecked_Union => 0,
10456 Pragma_Unimplemented_Unit => -1,
10457 Pragma_Universal_Data => -1,
10458 Pragma_Unreferenced => -1,
10459 Pragma_Unreserve_All_Interrupts => -1,
10460 Pragma_Unsuppress => 0,
10461 Pragma_Use_VADS_Size => -1,
10462 Pragma_Validity_Checks => -1,
10463 Pragma_Volatile => 0,
10464 Pragma_Volatile_Components => 0,
10465 Pragma_Warnings => -1,
10466 Pragma_Weak_External => 0,
10467 Unknown_Pragma => 0);
10469 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
10470 P : Node_Id;
10471 C : Int;
10472 A : Node_Id;
10474 begin
10475 P := Parent (N);
10477 if Nkind (P) /= N_Pragma_Argument_Association then
10478 return False;
10480 else
10481 C := Sig_Flags (Get_Pragma_Id (Chars (Parent (P))));
10483 case C is
10484 when -1 =>
10485 return False;
10487 when 0 =>
10488 return True;
10490 when others =>
10491 A := First (Pragma_Argument_Associations (Parent (P)));
10492 for J in 1 .. C - 1 loop
10493 if No (A) then
10494 return False;
10495 end if;
10497 Next (A);
10498 end loop;
10500 return A = P;
10501 end case;
10502 end if;
10503 end Is_Non_Significant_Pragma_Reference;
10505 ------------------------------
10506 -- Is_Pragma_String_Literal --
10507 ------------------------------
10509 -- This function returns true if the corresponding pragma argument is
10510 -- a static string expression. These are the only cases in which string
10511 -- literals can appear as pragma arguments. We also allow a string
10512 -- literal as the first argument to pragma Assert (although it will
10513 -- of course always generate a type error).
10515 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
10516 Pragn : constant Node_Id := Parent (Par);
10517 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
10518 Pname : constant Name_Id := Chars (Pragn);
10519 Argn : Natural;
10520 N : Node_Id;
10522 begin
10523 Argn := 1;
10524 N := First (Assoc);
10525 loop
10526 exit when N = Par;
10527 Argn := Argn + 1;
10528 Next (N);
10529 end loop;
10531 if Pname = Name_Assert then
10532 return True;
10534 elsif Pname = Name_Export then
10535 return Argn > 2;
10537 elsif Pname = Name_Ident then
10538 return Argn = 1;
10540 elsif Pname = Name_Import then
10541 return Argn > 2;
10543 elsif Pname = Name_Interface_Name then
10544 return Argn > 1;
10546 elsif Pname = Name_Linker_Alias then
10547 return Argn = 2;
10549 elsif Pname = Name_Linker_Section then
10550 return Argn = 2;
10552 elsif Pname = Name_Machine_Attribute then
10553 return Argn = 2;
10555 elsif Pname = Name_Source_File_Name then
10556 return True;
10558 elsif Pname = Name_Source_Reference then
10559 return Argn = 2;
10561 elsif Pname = Name_Title then
10562 return True;
10564 elsif Pname = Name_Subtitle then
10565 return True;
10567 else
10568 return False;
10569 end if;
10570 end Is_Pragma_String_Literal;
10572 --------------------------------------
10573 -- Process_Compilation_Unit_Pragmas --
10574 --------------------------------------
10576 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
10577 begin
10578 -- A special check for pragma Suppress_All. This is a strange DEC
10579 -- pragma, strange because it comes at the end of the unit. If we
10580 -- have a pragma Suppress_All in the Pragmas_After of the current
10581 -- unit, then we insert a pragma Suppress (All_Checks) at the start
10582 -- of the context clause to ensure the correct processing.
10584 declare
10585 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
10586 P : Node_Id;
10588 begin
10589 if Present (PA) then
10590 P := First (PA);
10591 while Present (P) loop
10592 if Chars (P) = Name_Suppress_All then
10593 Prepend_To (Context_Items (N),
10594 Make_Pragma (Sloc (P),
10595 Chars => Name_Suppress,
10596 Pragma_Argument_Associations => New_List (
10597 Make_Pragma_Argument_Association (Sloc (P),
10598 Expression =>
10599 Make_Identifier (Sloc (P),
10600 Chars => Name_All_Checks)))));
10601 exit;
10602 end if;
10604 Next (P);
10605 end loop;
10606 end if;
10607 end;
10608 end Process_Compilation_Unit_Pragmas;
10610 --------------------------------
10611 -- Set_Encoded_Interface_Name --
10612 --------------------------------
10614 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
10615 Str : constant String_Id := Strval (S);
10616 Len : constant Int := String_Length (Str);
10617 CC : Char_Code;
10618 C : Character;
10619 J : Int;
10621 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
10623 procedure Encode;
10624 -- Stores encoded value of character code CC. The encoding we
10625 -- use an underscore followed by four lower case hex digits.
10627 ------------
10628 -- Encode --
10629 ------------
10631 procedure Encode is
10632 begin
10633 Store_String_Char (Get_Char_Code ('_'));
10634 Store_String_Char
10635 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
10636 Store_String_Char
10637 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
10638 Store_String_Char
10639 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
10640 Store_String_Char
10641 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
10642 end Encode;
10644 -- Start of processing for Set_Encoded_Interface_Name
10646 begin
10647 -- If first character is asterisk, this is a link name, and we
10648 -- leave it completely unmodified. We also ignore null strings
10649 -- (the latter case happens only in error cases) and no encoding
10650 -- should occur for Java interface names.
10652 if Len = 0
10653 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
10654 or else Java_VM
10655 then
10656 Set_Interface_Name (E, S);
10658 else
10659 J := 1;
10660 loop
10661 CC := Get_String_Char (Str, J);
10663 exit when not In_Character_Range (CC);
10665 C := Get_Character (CC);
10667 exit when C /= '_' and then C /= '$'
10668 and then C not in '0' .. '9'
10669 and then C not in 'a' .. 'z'
10670 and then C not in 'A' .. 'Z';
10672 if J = Len then
10673 Set_Interface_Name (E, S);
10674 return;
10676 else
10677 J := J + 1;
10678 end if;
10679 end loop;
10681 -- Here we need to encode. The encoding we use as follows:
10682 -- three underscores + four hex digits (lower case)
10684 Start_String;
10686 for J in 1 .. String_Length (Str) loop
10687 CC := Get_String_Char (Str, J);
10689 if not In_Character_Range (CC) then
10690 Encode;
10691 else
10692 C := Get_Character (CC);
10694 if C = '_' or else C = '$'
10695 or else C in '0' .. '9'
10696 or else C in 'a' .. 'z'
10697 or else C in 'A' .. 'Z'
10698 then
10699 Store_String_Char (CC);
10700 else
10701 Encode;
10702 end if;
10703 end if;
10704 end loop;
10706 Set_Interface_Name (E,
10707 Make_String_Literal (Sloc (S),
10708 Strval => End_String));
10709 end if;
10710 end Set_Encoded_Interface_Name;
10712 -------------------
10713 -- Set_Unit_Name --
10714 -------------------
10716 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
10717 Pref : Node_Id;
10718 Scop : Entity_Id;
10720 begin
10721 if Nkind (N) = N_Identifier
10722 and then Nkind (With_Item) = N_Identifier
10723 then
10724 Set_Entity (N, Entity (With_Item));
10726 elsif Nkind (N) = N_Selected_Component then
10727 Change_Selected_Component_To_Expanded_Name (N);
10728 Set_Entity (N, Entity (With_Item));
10729 Set_Entity (Selector_Name (N), Entity (N));
10731 Pref := Prefix (N);
10732 Scop := Scope (Entity (N));
10733 while Nkind (Pref) = N_Selected_Component loop
10734 Change_Selected_Component_To_Expanded_Name (Pref);
10735 Set_Entity (Selector_Name (Pref), Scop);
10736 Set_Entity (Pref, Scop);
10737 Pref := Prefix (Pref);
10738 Scop := Scope (Scop);
10739 end loop;
10741 Set_Entity (Pref, Scop);
10742 end if;
10743 end Set_Unit_Name;
10744 end Sem_Prag;