* config/mips/mips.c (function_arg): Where one part of a
[official-gcc.git] / gcc / ada / sem_prag.adb
blobbec0eb5e8c0cbc83be6e32940d17aba0a8a84dba
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-2006, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 Sem_Warn; use Sem_Warn;
68 with Stand; use Stand;
69 with Sinfo; use Sinfo;
70 with Sinfo.CN; use Sinfo.CN;
71 with Sinput; use Sinput;
72 with Snames; use Snames;
73 with Stringt; use Stringt;
74 with Stylesw; use Stylesw;
75 with Table;
76 with Targparm; use Targparm;
77 with Tbuild; use Tbuild;
78 with Ttypes;
79 with Uintp; use Uintp;
80 with Urealp; use Urealp;
81 with Validsw; use Validsw;
83 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
85 package body Sem_Prag is
87 ----------------------------------------------
88 -- Common Handling of Import-Export Pragmas --
89 ----------------------------------------------
91 -- In the following section, a number of Import_xxx and Export_xxx
92 -- pragmas are defined by GNAT. These are compatible with the DEC
93 -- pragmas of the same name, and all have the following common
94 -- form and processing:
96 -- pragma Export_xxx
97 -- [Internal =>] LOCAL_NAME,
98 -- [, [External =>] EXTERNAL_SYMBOL]
99 -- [, other optional parameters ]);
101 -- pragma Import_xxx
102 -- [Internal =>] LOCAL_NAME,
103 -- [, [External =>] EXTERNAL_SYMBOL]
104 -- [, other optional parameters ]);
106 -- EXTERNAL_SYMBOL ::=
107 -- IDENTIFIER
108 -- | static_string_EXPRESSION
110 -- The internal LOCAL_NAME designates the entity that is imported or
111 -- exported, and must refer to an entity in the current declarative
112 -- part (as required by the rules for LOCAL_NAME).
114 -- The external linker name is designated by the External parameter
115 -- if given, or the Internal parameter if not (if there is no External
116 -- parameter, the External parameter is a copy of the Internal name).
118 -- If the External parameter is given as a string, then this string
119 -- is treated as an external name (exactly as though it had been given
120 -- as an External_Name parameter for a normal Import pragma).
122 -- If the External parameter is given as an identifier (or there is no
123 -- External parameter, so that the Internal identifier is used), then
124 -- the external name is the characters of the identifier, translated
125 -- to all upper case letters for OpenVMS versions of GNAT, and to all
126 -- lower case letters for all other versions
128 -- Note: the external name specified or implied by any of these special
129 -- Import_xxx or Export_xxx pragmas override an external or link name
130 -- specified in a previous Import or Export pragma.
132 -- Note: these and all other DEC-compatible GNAT pragmas allow full
133 -- use of named notation, following the standard rules for subprogram
134 -- calls, i.e. parameters can be given in any order if named notation
135 -- is used, and positional and named notation can be mixed, subject to
136 -- the rule that all positional parameters must appear first.
138 -- Note: All these pragmas are implemented exactly following the DEC
139 -- design and implementation and are intended to be fully compatible
140 -- with the use of these pragmas in the DEC Ada compiler.
142 --------------------------------------------
143 -- Checking for Duplicated External Names --
144 --------------------------------------------
146 -- It is suspicious if two separate Export pragmas use the same external
147 -- name. The following table is used to diagnose this situation so that
148 -- an appropriate warning can be issued.
150 -- The Node_Id stored is for the N_String_Literal node created to
151 -- hold the value of the external name. The Sloc of this node is
152 -- used to cross-reference the location of the duplication.
154 package Externals is new Table.Table (
155 Table_Component_Type => Node_Id,
156 Table_Index_Type => Int,
157 Table_Low_Bound => 0,
158 Table_Initial => 100,
159 Table_Increment => 100,
160 Table_Name => "Name_Externals");
162 -------------------------------------
163 -- Local Subprograms and Variables --
164 -------------------------------------
166 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
167 -- This routine is used for possible casing adjustment of an explicit
168 -- external name supplied as a string literal (the node N), according
169 -- to the casing requirement of Opt.External_Name_Casing. If this is
170 -- set to As_Is, then the string literal is returned unchanged, but if
171 -- it is set to Uppercase or Lowercase, then a new string literal with
172 -- appropriate casing is constructed.
174 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
175 -- If Def_Id refers to a renamed subprogram, then the base subprogram
176 -- (the original one, following the renaming chain) is returned.
177 -- Otherwise the entity is returned unchanged. Should be in Einfo???
179 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
180 -- Place semantic information on the argument of an Elaborate or
181 -- Elaborate_All pragma. Entity name for unit and its parents is
182 -- taken from item in previous with_clause that mentions the unit.
184 -------------------------------
185 -- Adjust_External_Name_Case --
186 -------------------------------
188 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
189 CC : Char_Code;
191 begin
192 -- Adjust case of literal if required
194 if Opt.External_Name_Exp_Casing = As_Is then
195 return N;
197 else
198 -- Copy existing string
200 Start_String;
202 -- Set proper casing
204 for J in 1 .. String_Length (Strval (N)) loop
205 CC := Get_String_Char (Strval (N), J);
207 if Opt.External_Name_Exp_Casing = Uppercase
208 and then CC >= Get_Char_Code ('a')
209 and then CC <= Get_Char_Code ('z')
210 then
211 Store_String_Char (CC - 32);
213 elsif Opt.External_Name_Exp_Casing = Lowercase
214 and then CC >= Get_Char_Code ('A')
215 and then CC <= Get_Char_Code ('Z')
216 then
217 Store_String_Char (CC + 32);
219 else
220 Store_String_Char (CC);
221 end if;
222 end loop;
224 return
225 Make_String_Literal (Sloc (N),
226 Strval => End_String);
227 end if;
228 end Adjust_External_Name_Case;
230 --------------------
231 -- Analyze_Pragma --
232 --------------------
234 procedure Analyze_Pragma (N : Node_Id) is
235 Loc : constant Source_Ptr := Sloc (N);
236 Prag_Id : Pragma_Id;
238 Pragma_Exit : exception;
239 -- This exception is used to exit pragma processing completely. It
240 -- is used when an error is detected, and no further processing is
241 -- required. It is also used if an earlier error has left the tree
242 -- in a state where the pragma should not be processed.
244 Arg_Count : Nat;
245 -- Number of pragma argument associations
247 Arg1 : Node_Id;
248 Arg2 : Node_Id;
249 Arg3 : Node_Id;
250 Arg4 : Node_Id;
251 -- First four pragma arguments (pragma argument association nodes,
252 -- or Empty if the corresponding argument does not exist).
254 type Name_List is array (Natural range <>) of Name_Id;
255 type Args_List is array (Natural range <>) of Node_Id;
256 -- Types used for arguments to Check_Arg_Order and Gather_Associations
258 procedure Check_Ada_83_Warning;
259 -- Issues a warning message for the current pragma if operating in Ada
260 -- 83 mode (used for language pragmas that are not a standard part of
261 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
262 -- of 95 pragma.
264 procedure Check_Arg_Count (Required : Nat);
265 -- Check argument count for pragma is equal to given parameter.
266 -- If not, then issue an error message and raise Pragma_Exit.
268 -- Note: all routines whose name is Check_Arg_Is_xxx take an
269 -- argument Arg which can either be a pragma argument association,
270 -- in which case the check is applied to the expression of the
271 -- association or an expression directly.
273 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
274 -- Check that an argument has the right form for an EXTERNAL_NAME
275 -- parameter of an extended import/export pragma. The rule is that
276 -- the name must be an identifier or string literal (in Ada 83 mode)
277 -- or a static string expression (in Ada 95 mode).
279 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
280 -- Check the specified argument Arg to make sure that it is an
281 -- identifier. If not give error and raise Pragma_Exit.
283 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
284 -- Check the specified argument Arg to make sure that it is an
285 -- integer literal. If not give error and raise Pragma_Exit.
287 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
288 -- Check the specified argument Arg to make sure that it has the
289 -- proper syntactic form for a local name and meets the semantic
290 -- requirements for a local name. The local name is analyzed as
291 -- part of the processing for this call. In addition, the local
292 -- name is required to represent an entity at the library level.
294 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
295 -- Check the specified argument Arg to make sure that it has the
296 -- proper syntactic form for a local name and meets the semantic
297 -- requirements for a local name. The local name is analyzed as
298 -- part of the processing for this call.
300 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
301 -- Check the specified argument Arg to make sure that it is a valid
302 -- locking policy name. If not give error and raise Pragma_Exit.
304 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
305 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
306 -- Check the specified argument Arg to make sure that it is an
307 -- identifier whose name matches either N1 or N2 (or N3 if present).
308 -- If not then give error and raise Pragma_Exit.
310 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
311 -- Check the specified argument Arg to make sure that it is a valid
312 -- queuing policy name. If not give error and raise Pragma_Exit.
314 procedure Check_Arg_Is_Static_Expression
315 (Arg : Node_Id;
316 Typ : Entity_Id);
317 -- Check the specified argument Arg to make sure that it is a static
318 -- expression of the given type (i.e. it will be analyzed and resolved
319 -- using this type, which can be any valid argument to Resolve, e.g.
320 -- Any_Integer is OK). If not, given error and raise Pragma_Exit.
322 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
323 -- Check the specified argument Arg to make sure that it is a
324 -- string literal. If not give error and raise Pragma_Exit
326 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
327 -- Check the specified argument Arg to make sure that it is a valid
328 -- valid task dispatching policy name. If not give error and raise
329 -- Pragma_Exit.
331 procedure Check_Arg_Order (Names : Name_List);
332 -- Checks for an instance of two arguments with identifiers for the
333 -- current pragma which are not in the sequence indicated by Names,
334 -- and if so, generates a fatal message about bad order of arguments.
336 procedure Check_At_Least_N_Arguments (N : Nat);
337 -- Check there are at least N arguments present
339 procedure Check_At_Most_N_Arguments (N : Nat);
340 -- Check there are no more than N arguments present
342 procedure Check_Component (Comp : Node_Id);
343 -- Examine Unchecked_Union component for correct use of per-object
344 -- constrained subtypes, and for restrictions on finalizable components.
346 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
347 -- Nam is an N_String_Literal node containing the external name set
348 -- by an Import or Export pragma (or extended Import or Export pragma).
349 -- This procedure checks for possible duplications if this is the
350 -- export case, and if found, issues an appropriate error message.
352 procedure Check_First_Subtype (Arg : Node_Id);
353 -- Checks that Arg, whose expression is an entity name referencing
354 -- a subtype, does not reference a type that is not a first subtype.
356 procedure Check_In_Main_Program;
357 -- Common checks for pragmas that appear within a main program
358 -- (Priority, Main_Storage, Time_Slice).
360 procedure Check_Interrupt_Or_Attach_Handler;
361 -- Common processing for first argument of pragma Interrupt_Handler
362 -- or pragma Attach_Handler.
364 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
365 -- Check that pragma appears in a declarative part, or in a package
366 -- specification, i.e. that it does not occur in a statement sequence
367 -- in a body.
369 procedure Check_No_Identifier (Arg : Node_Id);
370 -- Checks that the given argument does not have an identifier. If
371 -- an identifier is present, then an error message is issued, and
372 -- Pragma_Exit is raised.
374 procedure Check_No_Identifiers;
375 -- Checks that none of the arguments to the pragma has an identifier.
376 -- If any argument has an identifier, then an error message is issued,
377 -- and Pragma_Exit is raised.
379 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
380 -- Checks if the given argument has an identifier, and if so, requires
381 -- it to match the given identifier name. If there is a non-matching
382 -- identifier, then an error message is given and Error_Pragmas raised.
384 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
385 -- Checks if the given argument has an identifier, and if so, requires
386 -- it to match the given identifier name. If there is a non-matching
387 -- identifier, then an error message is given and Error_Pragmas raised.
388 -- In this version of the procedure, the identifier name is given as
389 -- a string with lower case letters.
391 procedure Check_Static_Constraint (Constr : Node_Id);
392 -- Constr is a constraint from an N_Subtype_Indication node from a
393 -- component constraint in an Unchecked_Union type. This routine checks
394 -- that the constraint is static as required by the restrictions for
395 -- Unchecked_Union.
397 procedure Check_Valid_Configuration_Pragma;
398 -- Legality checks for placement of a configuration pragma
400 procedure Check_Valid_Library_Unit_Pragma;
401 -- Legality checks for library unit pragmas. A special case arises for
402 -- pragmas in generic instances that come from copies of the original
403 -- library unit pragmas in the generic templates. In the case of other
404 -- than library level instantiations these can appear in contexts which
405 -- would normally be invalid (they only apply to the original template
406 -- and to library level instantiations), and they are simply ignored,
407 -- which is implemented by rewriting them as null statements.
409 procedure Check_Variant (Variant : Node_Id);
410 -- Check Unchecked_Union variant for lack of nested variants and
411 -- presence of at least one component.
413 procedure Error_Pragma (Msg : String);
414 pragma No_Return (Error_Pragma);
415 -- Outputs error message for current pragma. The message contains an %
416 -- that will be replaced with the pragma name, and the flag is placed
417 -- on the pragma itself. Pragma_Exit is then raised.
419 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
420 pragma No_Return (Error_Pragma_Arg);
421 -- Outputs error message for current pragma. The message may contain
422 -- a % that will be replaced with the pragma name. The parameter Arg
423 -- may either be a pragma argument association, in which case the flag
424 -- is placed on the expression of this association, or an expression,
425 -- in which case the flag is placed directly on the expression. The
426 -- message is placed using Error_Msg_N, so the message may also contain
427 -- an & insertion character which will reference the given Arg value.
428 -- After placing the message, Pragma_Exit is raised.
430 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
431 pragma No_Return (Error_Pragma_Arg);
432 -- Similar to above form of Error_Pragma_Arg except that two messages
433 -- are provided, the second is a continuation comment starting with \.
435 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
436 pragma No_Return (Error_Pragma_Arg_Ident);
437 -- Outputs error message for current pragma. The message may contain
438 -- a % that will be replaced with the pragma name. The parameter Arg
439 -- must be a pragma argument association with a non-empty identifier
440 -- (i.e. its Chars field must be set), and the error message is placed
441 -- on the identifier. The message is placed using Error_Msg_N so
442 -- the message may also contain an & insertion character which will
443 -- reference the identifier. After placing the message, Pragma_Exit
444 -- is raised.
446 function Find_Lib_Unit_Name return Entity_Id;
447 -- Used for a library unit pragma to find the entity to which the
448 -- library unit pragma applies, returns the entity found.
450 procedure Find_Program_Unit_Name (Id : Node_Id);
451 -- If the pragma is a compilation unit pragma, the id must denote the
452 -- compilation unit in the same compilation, and the pragma must appear
453 -- in the list of preceding or trailing pragmas. If it is a program
454 -- unit pragma that is not a compilation unit pragma, then the
455 -- identifier must be visible.
457 function Find_Unique_Parameterless_Procedure
458 (Name : Entity_Id;
459 Arg : Node_Id) return Entity_Id;
460 -- Used for a procedure pragma to find the unique parameterless
461 -- procedure identified by Name, returns it if it exists, otherwise
462 -- errors out and uses Arg as the pragma argument for the message.
464 procedure Gather_Associations
465 (Names : Name_List;
466 Args : out Args_List);
467 -- This procedure is used to gather the arguments for a pragma that
468 -- permits arbitrary ordering of parameters using the normal rules
469 -- for named and positional parameters. The Names argument is a list
470 -- of Name_Id values that corresponds to the allowed pragma argument
471 -- association identifiers in order. The result returned in Args is
472 -- a list of corresponding expressions that are the pragma arguments.
473 -- Note that this is a list of expressions, not of pragma argument
474 -- associations (Gather_Associations has completely checked all the
475 -- optional identifiers when it returns). An entry in Args is Empty
476 -- on return if the corresponding argument is not present.
478 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
479 -- All the routines that check pragma arguments take either a pragma
480 -- argument association (in which case the expression of the argument
481 -- association is checked), or the expression directly. The function
482 -- Get_Pragma_Arg is a utility used to deal with these two cases. If
483 -- Arg is a pragma argument association node, then its expression is
484 -- returned, otherwise Arg is returned unchanged.
486 procedure GNAT_Pragma;
487 -- Called for all GNAT defined pragmas to note the use of the feature,
488 -- and also check the relevant restriction (No_Implementation_Pragmas).
490 function Is_Before_First_Decl
491 (Pragma_Node : Node_Id;
492 Decls : List_Id) return Boolean;
493 -- Return True if Pragma_Node is before the first declarative item in
494 -- Decls where Decls is the list of declarative items.
496 function Is_Configuration_Pragma return Boolean;
497 -- Deterermines if the placement of the current pragma is appropriate
498 -- for a configuration pragma (precedes the current compilation unit)
500 procedure Pragma_Misplaced;
501 -- Issue fatal error message for misplaced pragma
503 procedure Process_Atomic_Shared_Volatile;
504 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
505 -- Shared is an obsolete Ada 83 pragma, treated as being identical
506 -- in effect to pragma Atomic.
508 procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
509 -- Common procesing for Convention, Interface, Import and Export.
510 -- Checks first two arguments of pragma, and sets the appropriate
511 -- convention value in the specified entity or entities. On return
512 -- C is the convention, E is the referenced entity.
514 procedure Process_Extended_Import_Export_Exception_Pragma
515 (Arg_Internal : Node_Id;
516 Arg_External : Node_Id;
517 Arg_Form : Node_Id;
518 Arg_Code : Node_Id);
519 -- Common processing for the pragmas Import/Export_Exception.
520 -- The three arguments correspond to the three named parameters of
521 -- the pragma. An argument is empty if the corresponding parameter
522 -- is not present in the pragma.
524 procedure Process_Extended_Import_Export_Object_Pragma
525 (Arg_Internal : Node_Id;
526 Arg_External : Node_Id;
527 Arg_Size : Node_Id);
528 -- Common processing for the pragmass Import/Export_Object.
529 -- The three arguments correspond to the three named parameters
530 -- of the pragmas. An argument is empty if the corresponding
531 -- parameter is not present in the pragma.
533 procedure Process_Extended_Import_Export_Internal_Arg
534 (Arg_Internal : Node_Id := Empty);
535 -- Common processing for all extended Import and Export pragmas. The
536 -- argument is the pragma parameter for the Internal argument. If
537 -- Arg_Internal is empty or inappropriate, an error message is posted.
538 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
539 -- set to identify the referenced entity.
541 procedure Process_Extended_Import_Export_Subprogram_Pragma
542 (Arg_Internal : Node_Id;
543 Arg_External : Node_Id;
544 Arg_Parameter_Types : Node_Id;
545 Arg_Result_Type : Node_Id := Empty;
546 Arg_Mechanism : Node_Id;
547 Arg_Result_Mechanism : Node_Id := Empty;
548 Arg_First_Optional_Parameter : Node_Id := Empty);
549 -- Common processing for all extended Import and Export pragmas
550 -- applying to subprograms. The caller omits any arguments that do
551 -- bnot apply to the pragma in question (for example, Arg_Result_Type
552 -- can be non-Empty only in the Import_Function and Export_Function
553 -- cases). The argument names correspond to the allowed pragma
554 -- association identifiers.
556 procedure Process_Generic_List;
557 -- Common processing for Share_Generic and Inline_Generic
559 procedure Process_Import_Or_Interface;
560 -- Common processing for Import of Interface
562 procedure Process_Inline (Active : Boolean);
563 -- Common processing for Inline and Inline_Always. The parameter
564 -- indicates if the inline pragma is active, i.e. if it should
565 -- actually cause inlining to occur.
567 procedure Process_Interface_Name
568 (Subprogram_Def : Entity_Id;
569 Ext_Arg : Node_Id;
570 Link_Arg : Node_Id);
571 -- Given the last two arguments of pragma Import, pragma Export, or
572 -- pragma Interface_Name, performs validity checks and sets the
573 -- Interface_Name field of the given subprogram entity to the
574 -- appropriate external or link name, depending on the arguments
575 -- given. Ext_Arg is always present, but Link_Arg may be missing.
576 -- Note that Ext_Arg may represent the Link_Name if Link_Arg is
577 -- missing, and appropriate named notation is used for Ext_Arg.
578 -- If neither Ext_Arg nor Link_Arg is present, the interface name
579 -- is set to the default from the subprogram name.
581 procedure Process_Interrupt_Or_Attach_Handler;
582 -- Common processing for Interrupt and Attach_Handler pragmas
584 procedure Process_Restrictions_Or_Restriction_Warnings;
585 -- Common processing for Restrictions and Restriction_Warnings pragmas
587 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
588 -- Common processing for Suppress and Unsuppress. The boolean parameter
589 -- Suppress_Case is True for the Suppress case, and False for the
590 -- Unsuppress case.
592 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
593 -- This procedure sets the Is_Exported flag for the given entity,
594 -- checking that the entity was not previously imported. Arg is
595 -- the argument that specified the entity. A check is also made
596 -- for exporting inappropriate entities.
598 procedure Set_Extended_Import_Export_External_Name
599 (Internal_Ent : Entity_Id;
600 Arg_External : Node_Id);
601 -- Common processing for all extended import export pragmas. The first
602 -- argument, Internal_Ent, is the internal entity, which has already
603 -- been checked for validity by the caller. Arg_External is from the
604 -- Import or Export pragma, and may be null if no External parameter
605 -- was present. If Arg_External is present and is a non-null string
606 -- (a null string is treated as the default), then the Interface_Name
607 -- field of Internal_Ent is set appropriately.
609 procedure Set_Imported (E : Entity_Id);
610 -- This procedure sets the Is_Imported flag for the given entity,
611 -- checking that it is not previously exported or imported.
613 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
614 -- Mech is a parameter passing mechanism (see Import_Function syntax
615 -- for MECHANISM_NAME). This routine checks that the mechanism argument
616 -- has the right form, and if not issues an error message. If the
617 -- argument has the right form then the Mechanism field of Ent is
618 -- set appropriately.
620 procedure Set_Ravenscar_Profile (N : Node_Id);
621 -- Activate the set of configuration pragmas and restrictions that
622 -- make up the Ravenscar Profile. N is the corresponding pragma
623 -- node, which is used for error messages on any constructs
624 -- that violate the profile.
626 --------------------------
627 -- Check_Ada_83_Warning --
628 --------------------------
630 procedure Check_Ada_83_Warning is
631 begin
632 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
633 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
634 end if;
635 end Check_Ada_83_Warning;
637 ---------------------
638 -- Check_Arg_Count --
639 ---------------------
641 procedure Check_Arg_Count (Required : Nat) is
642 begin
643 if Arg_Count /= Required then
644 Error_Pragma ("wrong number of arguments for pragma%");
645 end if;
646 end Check_Arg_Count;
648 --------------------------------
649 -- Check_Arg_Is_External_Name --
650 --------------------------------
652 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
653 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
655 begin
656 if Nkind (Argx) = N_Identifier then
657 return;
659 else
660 Analyze_And_Resolve (Argx, Standard_String);
662 if Is_OK_Static_Expression (Argx) then
663 return;
665 elsif Etype (Argx) = Any_Type then
666 raise Pragma_Exit;
668 -- An interesting special case, if we have a string literal and
669 -- we are in Ada 83 mode, then we allow it even though it will
670 -- not be flagged as static. This allows expected Ada 83 mode
671 -- use of external names which are string literals, even though
672 -- technically these are not static in Ada 83.
674 elsif Ada_Version = Ada_83
675 and then Nkind (Argx) = N_String_Literal
676 then
677 return;
679 -- Static expression that raises Constraint_Error. This has
680 -- already been flagged, so just exit from pragma processing.
682 elsif Is_Static_Expression (Argx) then
683 raise Pragma_Exit;
685 -- Here we have a real error (non-static expression)
687 else
688 Error_Msg_Name_1 := Chars (N);
689 Flag_Non_Static_Expr
690 ("argument for pragma% must be a identifier or " &
691 "static string expression!", Argx);
692 raise Pragma_Exit;
693 end if;
694 end if;
695 end Check_Arg_Is_External_Name;
697 -----------------------------
698 -- Check_Arg_Is_Identifier --
699 -----------------------------
701 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
702 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
703 begin
704 if Nkind (Argx) /= N_Identifier then
705 Error_Pragma_Arg
706 ("argument for pragma% must be identifier", Argx);
707 end if;
708 end Check_Arg_Is_Identifier;
710 ----------------------------------
711 -- Check_Arg_Is_Integer_Literal --
712 ----------------------------------
714 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
715 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
716 begin
717 if Nkind (Argx) /= N_Integer_Literal then
718 Error_Pragma_Arg
719 ("argument for pragma% must be integer literal", Argx);
720 end if;
721 end Check_Arg_Is_Integer_Literal;
723 -------------------------------------------
724 -- Check_Arg_Is_Library_Level_Local_Name --
725 -------------------------------------------
727 -- LOCAL_NAME ::=
728 -- DIRECT_NAME
729 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
730 -- | library_unit_NAME
732 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
733 begin
734 Check_Arg_Is_Local_Name (Arg);
736 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
737 and then Comes_From_Source (N)
738 then
739 Error_Pragma_Arg
740 ("argument for pragma% must be library level entity", Arg);
741 end if;
742 end Check_Arg_Is_Library_Level_Local_Name;
744 -----------------------------
745 -- Check_Arg_Is_Local_Name --
746 -----------------------------
748 -- LOCAL_NAME ::=
749 -- DIRECT_NAME
750 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
751 -- | library_unit_NAME
753 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
754 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
756 begin
757 Analyze (Argx);
759 if Nkind (Argx) not in N_Direct_Name
760 and then (Nkind (Argx) /= N_Attribute_Reference
761 or else Present (Expressions (Argx))
762 or else Nkind (Prefix (Argx)) /= N_Identifier)
763 and then (not Is_Entity_Name (Argx)
764 or else not Is_Compilation_Unit (Entity (Argx)))
765 then
766 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
767 end if;
769 if Is_Entity_Name (Argx)
770 and then Scope (Entity (Argx)) /= Current_Scope
771 then
772 Error_Pragma_Arg
773 ("pragma% argument must be in same declarative part", Arg);
774 end if;
775 end Check_Arg_Is_Local_Name;
777 ---------------------------------
778 -- Check_Arg_Is_Locking_Policy --
779 ---------------------------------
781 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
782 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
784 begin
785 Check_Arg_Is_Identifier (Argx);
787 if not Is_Locking_Policy_Name (Chars (Argx)) then
788 Error_Pragma_Arg
789 ("& is not a valid locking policy name", Argx);
790 end if;
791 end Check_Arg_Is_Locking_Policy;
793 -------------------------
794 -- Check_Arg_Is_One_Of --
795 -------------------------
797 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
798 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
800 begin
801 Check_Arg_Is_Identifier (Argx);
803 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
804 Error_Msg_Name_2 := N1;
805 Error_Msg_Name_3 := N2;
806 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
807 end if;
808 end Check_Arg_Is_One_Of;
810 procedure Check_Arg_Is_One_Of
811 (Arg : Node_Id;
812 N1, N2, N3 : Name_Id)
814 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
816 begin
817 Check_Arg_Is_Identifier (Argx);
819 if Chars (Argx) /= N1
820 and then Chars (Argx) /= N2
821 and then Chars (Argx) /= N3
822 then
823 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
824 end if;
825 end Check_Arg_Is_One_Of;
827 ---------------------------------
828 -- Check_Arg_Is_Queuing_Policy --
829 ---------------------------------
831 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
832 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
834 begin
835 Check_Arg_Is_Identifier (Argx);
837 if not Is_Queuing_Policy_Name (Chars (Argx)) then
838 Error_Pragma_Arg
839 ("& is not a valid queuing policy name", Argx);
840 end if;
841 end Check_Arg_Is_Queuing_Policy;
843 ------------------------------------
844 -- Check_Arg_Is_Static_Expression --
845 ------------------------------------
847 procedure Check_Arg_Is_Static_Expression
848 (Arg : Node_Id;
849 Typ : Entity_Id)
851 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
853 begin
854 Analyze_And_Resolve (Argx, Typ);
856 if Is_OK_Static_Expression (Argx) then
857 return;
859 elsif Etype (Argx) = Any_Type then
860 raise Pragma_Exit;
862 -- An interesting special case, if we have a string literal and
863 -- we are in Ada 83 mode, then we allow it even though it will
864 -- not be flagged as static. This allows the use of Ada 95
865 -- pragmas like Import in Ada 83 mode. They will of course be
866 -- flagged with warnings as usual, but will not cause errors.
868 elsif Ada_Version = Ada_83
869 and then Nkind (Argx) = N_String_Literal
870 then
871 return;
873 -- Static expression that raises Constraint_Error. This has
874 -- already been flagged, so just exit from pragma processing.
876 elsif Is_Static_Expression (Argx) then
877 raise Pragma_Exit;
879 -- Finally, we have a real error
881 else
882 Error_Msg_Name_1 := Chars (N);
883 Flag_Non_Static_Expr
884 ("argument for pragma% must be a static expression!", Argx);
885 raise Pragma_Exit;
886 end if;
887 end Check_Arg_Is_Static_Expression;
889 ---------------------------------
890 -- Check_Arg_Is_String_Literal --
891 ---------------------------------
893 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
894 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
895 begin
896 if Nkind (Argx) /= N_String_Literal then
897 Error_Pragma_Arg
898 ("argument for pragma% must be string literal", Argx);
899 end if;
900 end Check_Arg_Is_String_Literal;
902 ------------------------------------------
903 -- Check_Arg_Is_Task_Dispatching_Policy --
904 ------------------------------------------
906 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
907 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
909 begin
910 Check_Arg_Is_Identifier (Argx);
912 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
913 Error_Pragma_Arg
914 ("& is not a valid task dispatching policy name", Argx);
915 end if;
916 end Check_Arg_Is_Task_Dispatching_Policy;
918 ---------------------
919 -- Check_Arg_Order --
920 ---------------------
922 procedure Check_Arg_Order (Names : Name_List) is
923 Arg : Node_Id;
925 Highest_So_Far : Natural := 0;
926 -- Highest index in Names seen do far
928 begin
929 Arg := Arg1;
930 for J in 1 .. Arg_Count loop
931 if Chars (Arg) /= No_Name then
932 for K in Names'Range loop
933 if Chars (Arg) = Names (K) then
934 if K < Highest_So_Far then
935 Error_Msg_Name_1 := Chars (N);
936 Error_Msg_N
937 ("parameters out of order for pragma%", Arg);
938 Error_Msg_Name_1 := Names (K);
939 Error_Msg_Name_2 := Names (Highest_So_Far);
940 Error_Msg_N ("\% must appear before %", Arg);
941 raise Pragma_Exit;
943 else
944 Highest_So_Far := K;
945 end if;
946 end if;
947 end loop;
948 end if;
950 Arg := Next (Arg);
951 end loop;
952 end Check_Arg_Order;
954 --------------------------------
955 -- Check_At_Least_N_Arguments --
956 --------------------------------
958 procedure Check_At_Least_N_Arguments (N : Nat) is
959 begin
960 if Arg_Count < N then
961 Error_Pragma ("too few arguments for pragma%");
962 end if;
963 end Check_At_Least_N_Arguments;
965 -------------------------------
966 -- Check_At_Most_N_Arguments --
967 -------------------------------
969 procedure Check_At_Most_N_Arguments (N : Nat) is
970 Arg : Node_Id;
971 begin
972 if Arg_Count > N then
973 Arg := Arg1;
974 for J in 1 .. N loop
975 Next (Arg);
976 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
977 end loop;
978 end if;
979 end Check_At_Most_N_Arguments;
981 ---------------------
982 -- Check_Component --
983 ---------------------
985 procedure Check_Component (Comp : Node_Id) is
986 begin
987 if Nkind (Comp) = N_Component_Declaration then
988 declare
989 Sindic : constant Node_Id :=
990 Subtype_Indication (Component_Definition (Comp));
991 Typ : constant Entity_Id :=
992 Etype (Defining_Identifier (Comp));
993 begin
994 if Nkind (Sindic) = N_Subtype_Indication then
996 -- Ada 2005 (AI-216): If a component subtype is subject to
997 -- a per-object constraint, then the component type shall
998 -- be an Unchecked_Union.
1000 if Has_Per_Object_Constraint (Defining_Identifier (Comp))
1001 and then
1002 not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1003 then
1004 Error_Msg_N ("component subtype subject to per-object" &
1005 " constraint must be an Unchecked_Union", Comp);
1006 end if;
1007 end if;
1009 if Is_Controlled (Typ) then
1010 Error_Msg_N
1011 ("component of unchecked union cannot be controlled", Comp);
1013 elsif Has_Task (Typ) then
1014 Error_Msg_N
1015 ("component of unchecked union cannot have tasks", Comp);
1016 end if;
1017 end;
1018 end if;
1019 end Check_Component;
1021 ----------------------------------
1022 -- Check_Duplicated_Export_Name --
1023 ----------------------------------
1025 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1026 String_Val : constant String_Id := Strval (Nam);
1028 begin
1029 -- We are only interested in the export case, and in the case of
1030 -- generics, it is the instance, not the template, that is the
1031 -- problem (the template will generate a warning in any case).
1033 if not Inside_A_Generic
1034 and then (Prag_Id = Pragma_Export
1035 or else
1036 Prag_Id = Pragma_Export_Procedure
1037 or else
1038 Prag_Id = Pragma_Export_Valued_Procedure
1039 or else
1040 Prag_Id = Pragma_Export_Function)
1041 then
1042 for J in Externals.First .. Externals.Last loop
1043 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1044 Error_Msg_Sloc := Sloc (Externals.Table (J));
1045 Error_Msg_N ("external name duplicates name given#", Nam);
1046 exit;
1047 end if;
1048 end loop;
1050 Externals.Append (Nam);
1051 end if;
1052 end Check_Duplicated_Export_Name;
1054 -------------------------
1055 -- Check_First_Subtype --
1056 -------------------------
1058 procedure Check_First_Subtype (Arg : Node_Id) is
1059 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1060 begin
1061 if not Is_First_Subtype (Entity (Argx)) then
1062 Error_Pragma_Arg
1063 ("pragma% cannot apply to subtype", Argx);
1064 end if;
1065 end Check_First_Subtype;
1067 ---------------------------
1068 -- Check_In_Main_Program --
1069 ---------------------------
1071 procedure Check_In_Main_Program is
1072 P : constant Node_Id := Parent (N);
1074 begin
1075 -- Must be at in subprogram body
1077 if Nkind (P) /= N_Subprogram_Body then
1078 Error_Pragma ("% pragma allowed only in subprogram");
1080 -- Otherwise warn if obviously not main program
1082 elsif Present (Parameter_Specifications (Specification (P)))
1083 or else not Is_Compilation_Unit (Defining_Entity (P))
1084 then
1085 Error_Msg_Name_1 := Chars (N);
1086 Error_Msg_N
1087 ("?pragma% is only effective in main program", N);
1088 end if;
1089 end Check_In_Main_Program;
1091 ---------------------------------------
1092 -- Check_Interrupt_Or_Attach_Handler --
1093 ---------------------------------------
1095 procedure Check_Interrupt_Or_Attach_Handler is
1096 Arg1_X : constant Node_Id := Expression (Arg1);
1097 Handler_Proc, Proc_Scope : Entity_Id;
1099 begin
1100 Analyze (Arg1_X);
1102 if Prag_Id = Pragma_Interrupt_Handler then
1103 Check_Restriction (No_Dynamic_Attachment, N);
1104 end if;
1106 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1107 Proc_Scope := Scope (Handler_Proc);
1109 -- On AAMP only, a pragma Interrupt_Handler is supported for
1110 -- nonprotected parameterless procedures.
1112 if not AAMP_On_Target
1113 or else Prag_Id = Pragma_Attach_Handler
1114 then
1115 if Ekind (Proc_Scope) /= E_Protected_Type then
1116 Error_Pragma_Arg
1117 ("argument of pragma% must be protected procedure", Arg1);
1118 end if;
1120 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1121 Error_Pragma ("pragma% must be in protected definition");
1122 end if;
1123 end if;
1125 if not Is_Library_Level_Entity (Proc_Scope)
1126 or else (AAMP_On_Target
1127 and then not Is_Library_Level_Entity (Handler_Proc))
1128 then
1129 Error_Pragma_Arg
1130 ("argument for pragma% must be library level entity", Arg1);
1131 end if;
1132 end Check_Interrupt_Or_Attach_Handler;
1134 -------------------------------------------
1135 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1136 -------------------------------------------
1138 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1139 P : Node_Id;
1141 begin
1142 P := Parent (N);
1143 loop
1144 if No (P) then
1145 exit;
1147 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1148 exit;
1150 elsif Nkind (P) = N_Package_Specification then
1151 return;
1153 elsif Nkind (P) = N_Block_Statement then
1154 return;
1156 -- Note: the following tests seem a little peculiar, because
1157 -- they test for bodies, but if we were in the statement part
1158 -- of the body, we would already have hit the handled statement
1159 -- sequence, so the only way we get here is by being in the
1160 -- declarative part of the body.
1162 elsif Nkind (P) = N_Subprogram_Body
1163 or else Nkind (P) = N_Package_Body
1164 or else Nkind (P) = N_Task_Body
1165 or else Nkind (P) = N_Entry_Body
1166 then
1167 return;
1168 end if;
1170 P := Parent (P);
1171 end loop;
1173 Error_Pragma ("pragma% is not in declarative part or package spec");
1174 end Check_Is_In_Decl_Part_Or_Package_Spec;
1176 -------------------------
1177 -- Check_No_Identifier --
1178 -------------------------
1180 procedure Check_No_Identifier (Arg : Node_Id) is
1181 begin
1182 if Chars (Arg) /= No_Name then
1183 Error_Pragma_Arg_Ident
1184 ("pragma% does not permit identifier& here", Arg);
1185 end if;
1186 end Check_No_Identifier;
1188 --------------------------
1189 -- Check_No_Identifiers --
1190 --------------------------
1192 procedure Check_No_Identifiers is
1193 Arg_Node : Node_Id;
1194 begin
1195 if Arg_Count > 0 then
1196 Arg_Node := Arg1;
1197 while Present (Arg_Node) loop
1198 Check_No_Identifier (Arg_Node);
1199 Next (Arg_Node);
1200 end loop;
1201 end if;
1202 end Check_No_Identifiers;
1204 -------------------------------
1205 -- Check_Optional_Identifier --
1206 -------------------------------
1208 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1209 begin
1210 if Present (Arg) and then Chars (Arg) /= No_Name then
1211 if Chars (Arg) /= Id then
1212 Error_Msg_Name_1 := Chars (N);
1213 Error_Msg_Name_2 := Id;
1214 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1215 raise Pragma_Exit;
1216 end if;
1217 end if;
1218 end Check_Optional_Identifier;
1220 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1221 begin
1222 Name_Buffer (1 .. Id'Length) := Id;
1223 Name_Len := Id'Length;
1224 Check_Optional_Identifier (Arg, Name_Find);
1225 end Check_Optional_Identifier;
1227 -----------------------------
1228 -- Check_Static_Constraint --
1229 -----------------------------
1231 -- Note: for convenience in writing this procedure, in addition to
1232 -- the officially (i.e. by spec) allowed argument which is always
1233 -- a constraint, it also allows ranges and discriminant associations.
1234 -- Above is not clear ???
1236 procedure Check_Static_Constraint (Constr : Node_Id) is
1238 --------------------
1239 -- Require_Static --
1240 --------------------
1242 procedure Require_Static (E : Node_Id);
1243 -- Require given expression to be static expression
1245 procedure Require_Static (E : Node_Id) is
1246 begin
1247 if not Is_OK_Static_Expression (E) then
1248 Flag_Non_Static_Expr
1249 ("non-static constraint not allowed in Unchecked_Union!", E);
1250 raise Pragma_Exit;
1251 end if;
1252 end Require_Static;
1254 -- Start of processing for Check_Static_Constraint
1256 begin
1257 case Nkind (Constr) is
1258 when N_Discriminant_Association =>
1259 Require_Static (Expression (Constr));
1261 when N_Range =>
1262 Require_Static (Low_Bound (Constr));
1263 Require_Static (High_Bound (Constr));
1265 when N_Attribute_Reference =>
1266 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1267 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1269 when N_Range_Constraint =>
1270 Check_Static_Constraint (Range_Expression (Constr));
1272 when N_Index_Or_Discriminant_Constraint =>
1273 declare
1274 IDC : Entity_Id;
1275 begin
1276 IDC := First (Constraints (Constr));
1277 while Present (IDC) loop
1278 Check_Static_Constraint (IDC);
1279 Next (IDC);
1280 end loop;
1281 end;
1283 when others =>
1284 null;
1285 end case;
1286 end Check_Static_Constraint;
1288 --------------------------------------
1289 -- Check_Valid_Configuration_Pragma --
1290 --------------------------------------
1292 -- A configuration pragma must appear in the context clause of
1293 -- a compilation unit, at the start of the list (i.e. only other
1294 -- pragmas may precede it).
1296 procedure Check_Valid_Configuration_Pragma is
1297 begin
1298 if not Is_Configuration_Pragma then
1299 Error_Pragma ("incorrect placement for configuration pragma%");
1300 end if;
1301 end Check_Valid_Configuration_Pragma;
1303 -------------------------------------
1304 -- Check_Valid_Library_Unit_Pragma --
1305 -------------------------------------
1307 procedure Check_Valid_Library_Unit_Pragma is
1308 Plist : List_Id;
1309 Parent_Node : Node_Id;
1310 Unit_Name : Entity_Id;
1311 Unit_Kind : Node_Kind;
1312 Unit_Node : Node_Id;
1313 Sindex : Source_File_Index;
1315 begin
1316 if not Is_List_Member (N) then
1317 Pragma_Misplaced;
1319 else
1320 Plist := List_Containing (N);
1321 Parent_Node := Parent (Plist);
1323 if Parent_Node = Empty then
1324 Pragma_Misplaced;
1326 -- Case of pragma appearing after a compilation unit. In this
1327 -- case it must have an argument with the corresponding name
1328 -- and must be part of the following pragmas of its parent.
1330 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1331 if Plist /= Pragmas_After (Parent_Node) then
1332 Pragma_Misplaced;
1334 elsif Arg_Count = 0 then
1335 Error_Pragma
1336 ("argument required if outside compilation unit");
1338 else
1339 Check_No_Identifiers;
1340 Check_Arg_Count (1);
1341 Unit_Node := Unit (Parent (Parent_Node));
1342 Unit_Kind := Nkind (Unit_Node);
1344 Analyze (Expression (Arg1));
1346 if Unit_Kind = N_Generic_Subprogram_Declaration
1347 or else Unit_Kind = N_Subprogram_Declaration
1348 then
1349 Unit_Name := Defining_Entity (Unit_Node);
1351 elsif Unit_Kind in N_Generic_Instantiation then
1352 Unit_Name := Defining_Entity (Unit_Node);
1354 else
1355 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1356 end if;
1358 if Chars (Unit_Name) /=
1359 Chars (Entity (Expression (Arg1)))
1360 then
1361 Error_Pragma_Arg
1362 ("pragma% argument is not current unit name", Arg1);
1363 end if;
1365 if Ekind (Unit_Name) = E_Package
1366 and then Present (Renamed_Entity (Unit_Name))
1367 then
1368 Error_Pragma ("pragma% not allowed for renamed package");
1369 end if;
1370 end if;
1372 -- Pragma appears other than after a compilation unit
1374 else
1375 -- Here we check for the generic instantiation case and also
1376 -- for the case of processing a generic formal package. We
1377 -- detect these cases by noting that the Sloc on the node
1378 -- does not belong to the current compilation unit.
1380 Sindex := Source_Index (Current_Sem_Unit);
1382 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1383 Rewrite (N, Make_Null_Statement (Loc));
1384 return;
1386 -- If before first declaration, the pragma applies to the
1387 -- enclosing unit, and the name if present must be this name.
1389 elsif Is_Before_First_Decl (N, Plist) then
1390 Unit_Node := Unit_Declaration_Node (Current_Scope);
1391 Unit_Kind := Nkind (Unit_Node);
1393 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1394 Pragma_Misplaced;
1396 elsif Unit_Kind = N_Subprogram_Body
1397 and then not Acts_As_Spec (Unit_Node)
1398 then
1399 Pragma_Misplaced;
1401 elsif Nkind (Parent_Node) = N_Package_Body then
1402 Pragma_Misplaced;
1404 elsif Nkind (Parent_Node) = N_Package_Specification
1405 and then Plist = Private_Declarations (Parent_Node)
1406 then
1407 Pragma_Misplaced;
1409 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1410 or else Nkind (Parent_Node)
1411 = N_Generic_Subprogram_Declaration)
1412 and then Plist = Generic_Formal_Declarations (Parent_Node)
1413 then
1414 Pragma_Misplaced;
1416 elsif Arg_Count > 0 then
1417 Analyze (Expression (Arg1));
1419 if Entity (Expression (Arg1)) /= Current_Scope then
1420 Error_Pragma_Arg
1421 ("name in pragma% must be enclosing unit", Arg1);
1422 end if;
1424 -- It is legal to have no argument in this context
1426 else
1427 return;
1428 end if;
1430 -- Error if not before first declaration. This is because a
1431 -- library unit pragma argument must be the name of a library
1432 -- unit (RM 10.1.5(7)), but the only names permitted in this
1433 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1434 -- generic subprogram declarations or generic instantiations.
1436 else
1437 Error_Pragma
1438 ("pragma% misplaced, must be before first declaration");
1439 end if;
1440 end if;
1441 end if;
1442 end Check_Valid_Library_Unit_Pragma;
1444 -------------------
1445 -- Check_Variant --
1446 -------------------
1448 procedure Check_Variant (Variant : Node_Id) is
1449 Clist : constant Node_Id := Component_List (Variant);
1450 Comp : Node_Id;
1452 begin
1453 if not Is_Non_Empty_List (Component_Items (Clist)) then
1454 Error_Msg_N
1455 ("Unchecked_Union may not have empty component list",
1456 Variant);
1457 return;
1458 end if;
1460 Comp := First (Component_Items (Clist));
1461 while Present (Comp) loop
1462 Check_Component (Comp);
1463 Next (Comp);
1464 end loop;
1465 end Check_Variant;
1467 ------------------
1468 -- Error_Pragma --
1469 ------------------
1471 procedure Error_Pragma (Msg : String) is
1472 begin
1473 Error_Msg_Name_1 := Chars (N);
1474 Error_Msg_N (Msg, N);
1475 raise Pragma_Exit;
1476 end Error_Pragma;
1478 ----------------------
1479 -- Error_Pragma_Arg --
1480 ----------------------
1482 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1483 begin
1484 Error_Msg_Name_1 := Chars (N);
1485 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1486 raise Pragma_Exit;
1487 end Error_Pragma_Arg;
1489 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1490 begin
1491 Error_Msg_Name_1 := Chars (N);
1492 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1493 Error_Pragma_Arg (Msg2, Arg);
1494 end Error_Pragma_Arg;
1496 ----------------------------
1497 -- Error_Pragma_Arg_Ident --
1498 ----------------------------
1500 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1501 begin
1502 Error_Msg_Name_1 := Chars (N);
1503 Error_Msg_N (Msg, Arg);
1504 raise Pragma_Exit;
1505 end Error_Pragma_Arg_Ident;
1507 ------------------------
1508 -- Find_Lib_Unit_Name --
1509 ------------------------
1511 function Find_Lib_Unit_Name return Entity_Id is
1512 begin
1513 -- Return inner compilation unit entity, for case of nested
1514 -- categorization pragmas. This happens in generic unit.
1516 if Nkind (Parent (N)) = N_Package_Specification
1517 and then Defining_Entity (Parent (N)) /= Current_Scope
1518 then
1519 return Defining_Entity (Parent (N));
1520 else
1521 return Current_Scope;
1522 end if;
1523 end Find_Lib_Unit_Name;
1525 ----------------------------
1526 -- Find_Program_Unit_Name --
1527 ----------------------------
1529 procedure Find_Program_Unit_Name (Id : Node_Id) is
1530 Unit_Name : Entity_Id;
1531 Unit_Kind : Node_Kind;
1532 P : constant Node_Id := Parent (N);
1534 begin
1535 if Nkind (P) = N_Compilation_Unit then
1536 Unit_Kind := Nkind (Unit (P));
1538 if Unit_Kind = N_Subprogram_Declaration
1539 or else Unit_Kind = N_Package_Declaration
1540 or else Unit_Kind in N_Generic_Declaration
1541 then
1542 Unit_Name := Defining_Entity (Unit (P));
1544 if Chars (Id) = Chars (Unit_Name) then
1545 Set_Entity (Id, Unit_Name);
1546 Set_Etype (Id, Etype (Unit_Name));
1547 else
1548 Set_Etype (Id, Any_Type);
1549 Error_Pragma
1550 ("cannot find program unit referenced by pragma%");
1551 end if;
1553 else
1554 Set_Etype (Id, Any_Type);
1555 Error_Pragma ("pragma% inapplicable to this unit");
1556 end if;
1558 else
1559 Analyze (Id);
1560 end if;
1561 end Find_Program_Unit_Name;
1563 -----------------------------------------
1564 -- Find_Unique_Parameterless_Procedure --
1565 -----------------------------------------
1567 function Find_Unique_Parameterless_Procedure
1568 (Name : Entity_Id;
1569 Arg : Node_Id) return Entity_Id
1571 Proc : Entity_Id := Empty;
1573 begin
1574 -- The body of this procedure needs some comments ???
1576 if not Is_Entity_Name (Name) then
1577 Error_Pragma_Arg
1578 ("argument of pragma% must be entity name", Arg);
1580 elsif not Is_Overloaded (Name) then
1581 Proc := Entity (Name);
1583 if Ekind (Proc) /= E_Procedure
1584 or else Present (First_Formal (Proc)) then
1585 Error_Pragma_Arg
1586 ("argument of pragma% must be parameterless procedure", Arg);
1587 end if;
1589 else
1590 declare
1591 Found : Boolean := False;
1592 It : Interp;
1593 Index : Interp_Index;
1595 begin
1596 Get_First_Interp (Name, Index, It);
1597 while Present (It.Nam) loop
1598 Proc := It.Nam;
1600 if Ekind (Proc) = E_Procedure
1601 and then No (First_Formal (Proc))
1602 then
1603 if not Found then
1604 Found := True;
1605 Set_Entity (Name, Proc);
1606 Set_Is_Overloaded (Name, False);
1607 else
1608 Error_Pragma_Arg
1609 ("ambiguous handler name for pragma% ", Arg);
1610 end if;
1611 end if;
1613 Get_Next_Interp (Index, It);
1614 end loop;
1616 if not Found then
1617 Error_Pragma_Arg
1618 ("argument of pragma% must be parameterless procedure",
1619 Arg);
1620 else
1621 Proc := Entity (Name);
1622 end if;
1623 end;
1624 end if;
1626 return Proc;
1627 end Find_Unique_Parameterless_Procedure;
1629 -------------------------
1630 -- Gather_Associations --
1631 -------------------------
1633 procedure Gather_Associations
1634 (Names : Name_List;
1635 Args : out Args_List)
1637 Arg : Node_Id;
1639 begin
1640 -- Initialize all parameters to Empty
1642 for J in Args'Range loop
1643 Args (J) := Empty;
1644 end loop;
1646 -- That's all we have to do if there are no argument associations
1648 if No (Pragma_Argument_Associations (N)) then
1649 return;
1650 end if;
1652 -- Otherwise first deal with any positional parameters present
1654 Arg := First (Pragma_Argument_Associations (N));
1655 for Index in Args'Range loop
1656 exit when No (Arg) or else Chars (Arg) /= No_Name;
1657 Args (Index) := Expression (Arg);
1658 Next (Arg);
1659 end loop;
1661 -- Positional parameters all processed, if any left, then we
1662 -- have too many positional parameters.
1664 if Present (Arg) and then Chars (Arg) = No_Name then
1665 Error_Pragma_Arg
1666 ("too many positional associations for pragma%", Arg);
1667 end if;
1669 -- Process named parameters if any are present
1671 while Present (Arg) loop
1672 if Chars (Arg) = No_Name then
1673 Error_Pragma_Arg
1674 ("positional association cannot follow named association",
1675 Arg);
1677 else
1678 for Index in Names'Range loop
1679 if Names (Index) = Chars (Arg) then
1680 if Present (Args (Index)) then
1681 Error_Pragma_Arg
1682 ("duplicate argument association for pragma%", Arg);
1683 else
1684 Args (Index) := Expression (Arg);
1685 exit;
1686 end if;
1687 end if;
1689 if Index = Names'Last then
1690 Error_Msg_Name_1 := Chars (N);
1691 Error_Msg_N ("pragma% does not allow & argument", Arg);
1693 -- Check for possible misspelling
1695 for Index1 in Names'Range loop
1696 if Is_Bad_Spelling_Of
1697 (Get_Name_String (Chars (Arg)),
1698 Get_Name_String (Names (Index1)))
1699 then
1700 Error_Msg_Name_1 := Names (Index1);
1701 Error_Msg_N ("\possible misspelling of%", Arg);
1702 exit;
1703 end if;
1704 end loop;
1706 raise Pragma_Exit;
1707 end if;
1708 end loop;
1709 end if;
1711 Next (Arg);
1712 end loop;
1713 end Gather_Associations;
1715 --------------------
1716 -- Get_Pragma_Arg --
1717 --------------------
1719 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
1720 begin
1721 if Nkind (Arg) = N_Pragma_Argument_Association then
1722 return Expression (Arg);
1723 else
1724 return Arg;
1725 end if;
1726 end Get_Pragma_Arg;
1728 -----------------
1729 -- GNAT_Pragma --
1730 -----------------
1732 procedure GNAT_Pragma is
1733 begin
1734 Check_Restriction (No_Implementation_Pragmas, N);
1735 end GNAT_Pragma;
1737 --------------------------
1738 -- Is_Before_First_Decl --
1739 --------------------------
1741 function Is_Before_First_Decl
1742 (Pragma_Node : Node_Id;
1743 Decls : List_Id) return Boolean
1745 Item : Node_Id := First (Decls);
1747 begin
1748 -- Only other pragmas can come before this pragma
1750 loop
1751 if No (Item) or else Nkind (Item) /= N_Pragma then
1752 return False;
1754 elsif Item = Pragma_Node then
1755 return True;
1756 end if;
1758 Next (Item);
1759 end loop;
1760 end Is_Before_First_Decl;
1762 -----------------------------
1763 -- Is_Configuration_Pragma --
1764 -----------------------------
1766 -- A configuration pragma must appear in the context clause of
1767 -- a compilation unit, at the start of the list (i.e. only other
1768 -- pragmas may precede it).
1770 function Is_Configuration_Pragma return Boolean is
1771 Lis : constant List_Id := List_Containing (N);
1772 Par : constant Node_Id := Parent (N);
1773 Prg : Node_Id;
1775 begin
1776 -- If no parent, then we are in the configuration pragma file,
1777 -- so the placement is definitely appropriate.
1779 if No (Par) then
1780 return True;
1782 -- Otherwise we must be in the context clause of a compilation unit
1783 -- and the only thing allowed before us in the context list is more
1784 -- configuration pragmas.
1786 elsif Nkind (Par) = N_Compilation_Unit
1787 and then Context_Items (Par) = Lis
1788 then
1789 Prg := First (Lis);
1791 loop
1792 if Prg = N then
1793 return True;
1794 elsif Nkind (Prg) /= N_Pragma then
1795 return False;
1796 end if;
1798 Next (Prg);
1799 end loop;
1801 else
1802 return False;
1803 end if;
1804 end Is_Configuration_Pragma;
1806 ----------------------
1807 -- Pragma_Misplaced --
1808 ----------------------
1810 procedure Pragma_Misplaced is
1811 begin
1812 Error_Pragma ("incorrect placement of pragma%");
1813 end Pragma_Misplaced;
1815 ------------------------------------
1816 -- Process Atomic_Shared_Volatile --
1817 ------------------------------------
1819 procedure Process_Atomic_Shared_Volatile is
1820 E_Id : Node_Id;
1821 E : Entity_Id;
1822 D : Node_Id;
1823 K : Node_Kind;
1824 Utyp : Entity_Id;
1826 procedure Set_Atomic (E : Entity_Id);
1827 -- Set given type as atomic, and if no explicit alignment was
1828 -- given, set alignment to unknown, since back end knows what
1829 -- the alignment requirements are for atomic arrays. Note that
1830 -- this step is necessary for derived types.
1832 ----------------
1833 -- Set_Atomic --
1834 ----------------
1836 procedure Set_Atomic (E : Entity_Id) is
1837 begin
1838 Set_Is_Atomic (E);
1840 if not Has_Alignment_Clause (E) then
1841 Set_Alignment (E, Uint_0);
1842 end if;
1843 end Set_Atomic;
1845 -- Start of processing for Process_Atomic_Shared_Volatile
1847 begin
1848 Check_Ada_83_Warning;
1849 Check_No_Identifiers;
1850 Check_Arg_Count (1);
1851 Check_Arg_Is_Local_Name (Arg1);
1852 E_Id := Expression (Arg1);
1854 if Etype (E_Id) = Any_Type then
1855 return;
1856 end if;
1858 E := Entity (E_Id);
1859 D := Declaration_Node (E);
1860 K := Nkind (D);
1862 if Is_Type (E) then
1863 if Rep_Item_Too_Early (E, N)
1864 or else
1865 Rep_Item_Too_Late (E, N)
1866 then
1867 return;
1868 else
1869 Check_First_Subtype (Arg1);
1870 end if;
1872 if Prag_Id /= Pragma_Volatile then
1873 Set_Atomic (E);
1874 Set_Atomic (Underlying_Type (E));
1875 Set_Atomic (Base_Type (E));
1876 end if;
1878 -- Attribute belongs on the base type. If the
1879 -- view of the type is currently private, it also
1880 -- belongs on the underlying type.
1882 Set_Is_Volatile (Base_Type (E));
1883 Set_Is_Volatile (Underlying_Type (E));
1885 Set_Treat_As_Volatile (E);
1886 Set_Treat_As_Volatile (Underlying_Type (E));
1888 elsif K = N_Object_Declaration
1889 or else (K = N_Component_Declaration
1890 and then Original_Record_Component (E) = E)
1891 then
1892 if Rep_Item_Too_Late (E, N) then
1893 return;
1894 end if;
1896 if Prag_Id /= Pragma_Volatile then
1897 Set_Is_Atomic (E);
1899 -- If the object declaration has an explicit
1900 -- initialization, a temporary may have to be
1901 -- created to hold the expression, to insure
1902 -- that access to the object remain atomic.
1904 if Nkind (Parent (E)) = N_Object_Declaration
1905 and then Present (Expression (Parent (E)))
1906 then
1907 Set_Has_Delayed_Freeze (E);
1908 end if;
1910 -- An interesting improvement here. If an object of type X
1911 -- is declared atomic, and the type X is not atomic, that's
1912 -- a pity, since it may not have appropraite alignment etc.
1913 -- We can rescue this in the special case where the object
1914 -- and type are in the same unit by just setting the type
1915 -- as atomic, so that the back end will process it as atomic.
1917 Utyp := Underlying_Type (Etype (E));
1919 if Present (Utyp)
1920 and then Sloc (E) > No_Location
1921 and then Sloc (Utyp) > No_Location
1922 and then
1923 Get_Source_File_Index (Sloc (E)) =
1924 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
1925 then
1926 Set_Is_Atomic (Underlying_Type (Etype (E)));
1927 end if;
1928 end if;
1930 Set_Is_Volatile (E);
1931 Set_Treat_As_Volatile (E);
1933 else
1934 Error_Pragma_Arg
1935 ("inappropriate entity for pragma%", Arg1);
1936 end if;
1937 end Process_Atomic_Shared_Volatile;
1939 ------------------------
1940 -- Process_Convention --
1941 ------------------------
1943 procedure Process_Convention
1944 (C : out Convention_Id;
1945 E : out Entity_Id)
1947 Id : Node_Id;
1948 E1 : Entity_Id;
1949 Cname : Name_Id;
1950 Comp_Unit : Unit_Number_Type;
1952 procedure Set_Convention_From_Pragma (E : Entity_Id);
1953 -- Set convention in entity E, and also flag that the entity has a
1954 -- convention pragma. If entity is for a private or incomplete type,
1955 -- also set convention and flag on underlying type. This procedure
1956 -- also deals with the special case of C_Pass_By_Copy convention.
1958 --------------------------------
1959 -- Set_Convention_From_Pragma --
1960 --------------------------------
1962 procedure Set_Convention_From_Pragma (E : Entity_Id) is
1963 begin
1964 -- Check invalid attempt to change convention for an overridden
1965 -- dispatching operation. This is Ada 2005 AI 430. Technically
1966 -- this is an amendment and should only be done in Ada 2005 mode.
1967 -- However, this is clearly a mistake, since the problem that is
1968 -- addressed by this AI is that there is a clear gap in the RM!
1970 if Is_Dispatching_Operation (E)
1971 and then Present (Overridden_Operation (E))
1972 and then C /= Convention (Overridden_Operation (E))
1973 then
1974 Error_Pragma_Arg
1975 ("cannot change convention for " &
1976 "overridden dispatching operation",
1977 Arg1);
1978 end if;
1980 -- Set the convention
1982 Set_Convention (E, C);
1983 Set_Has_Convention_Pragma (E);
1985 if Is_Incomplete_Or_Private_Type (E) then
1986 Set_Convention (Underlying_Type (E), C);
1987 Set_Has_Convention_Pragma (Underlying_Type (E), True);
1988 end if;
1990 -- A class-wide type should inherit the convention of
1991 -- the specific root type (although this isn't specified
1992 -- clearly by the RM).
1994 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
1995 Set_Convention (Class_Wide_Type (E), C);
1996 end if;
1998 -- If the entity is a record type, then check for special case
1999 -- of C_Pass_By_Copy, which is treated the same as C except that
2000 -- the special record flag is set. This convention is also only
2001 -- permitted on record types (see AI95-00131).
2003 if Cname = Name_C_Pass_By_Copy then
2004 if Is_Record_Type (E) then
2005 Set_C_Pass_By_Copy (Base_Type (E));
2006 elsif Is_Incomplete_Or_Private_Type (E)
2007 and then Is_Record_Type (Underlying_Type (E))
2008 then
2009 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2010 else
2011 Error_Pragma_Arg
2012 ("C_Pass_By_Copy convention allowed only for record type",
2013 Arg2);
2014 end if;
2015 end if;
2017 -- If the entity is a derived boolean type, check for the
2018 -- special case of convention C, C++, or Fortran, where we
2019 -- consider any nonzero value to represent true.
2021 if Is_Discrete_Type (E)
2022 and then Root_Type (Etype (E)) = Standard_Boolean
2023 and then
2024 (C = Convention_C
2025 or else
2026 C = Convention_CPP
2027 or else
2028 C = Convention_Fortran)
2029 then
2030 Set_Nonzero_Is_True (Base_Type (E));
2031 end if;
2032 end Set_Convention_From_Pragma;
2034 -- Start of processing for Process_Convention
2036 begin
2037 Check_At_Least_N_Arguments (2);
2038 Check_Optional_Identifier (Arg1, Name_Convention);
2039 Check_Arg_Is_Identifier (Arg1);
2040 Cname := Chars (Expression (Arg1));
2042 -- C_Pass_By_Copy is treated as a synonym for convention C
2043 -- (this is tested again below to set the critical flag)
2045 if Cname = Name_C_Pass_By_Copy then
2046 C := Convention_C;
2048 -- Otherwise we must have something in the standard convention list
2050 elsif Is_Convention_Name (Cname) then
2051 C := Get_Convention_Id (Chars (Expression (Arg1)));
2053 -- In DEC VMS, it seems that there is an undocumented feature
2054 -- that any unrecognized convention is treated as the default,
2055 -- which for us is convention C. It does not seem so terrible
2056 -- to do this unconditionally, silently in the VMS case, and
2057 -- with a warning in the non-VMS case.
2059 else
2060 if Warn_On_Export_Import and not OpenVMS_On_Target then
2061 Error_Msg_N
2062 ("?unrecognized convention name, C assumed",
2063 Expression (Arg1));
2064 end if;
2066 C := Convention_C;
2067 end if;
2069 Check_Optional_Identifier (Arg2, Name_Entity);
2070 Check_Arg_Is_Local_Name (Arg2);
2072 Id := Expression (Arg2);
2073 Analyze (Id);
2075 if not Is_Entity_Name (Id) then
2076 Error_Pragma_Arg ("entity name required", Arg2);
2077 end if;
2079 E := Entity (Id);
2081 -- Go to renamed subprogram if present, since convention applies
2082 -- to the actual renamed entity, not to the renaming entity.
2083 -- If subprogram is inherited, go to parent subprogram.
2085 if Is_Subprogram (E)
2086 and then Present (Alias (E))
2087 then
2088 if Nkind (Parent (Declaration_Node (E)))
2089 = N_Subprogram_Renaming_Declaration
2090 then
2091 E := Alias (E);
2093 elsif Nkind (Parent (E)) = N_Full_Type_Declaration
2094 and then Scope (E) = Scope (Alias (E))
2095 then
2096 E := Alias (E);
2097 end if;
2098 end if;
2100 -- Check that we are not applying this to a specless body
2102 if Is_Subprogram (E)
2103 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2104 then
2105 Error_Pragma
2106 ("pragma% requires separate spec and must come before body");
2107 end if;
2109 -- Check that we are not applying this to a named constant
2111 if Ekind (E) = E_Named_Integer
2112 or else
2113 Ekind (E) = E_Named_Real
2114 then
2115 Error_Msg_Name_1 := Chars (N);
2116 Error_Msg_N
2117 ("cannot apply pragma% to named constant!",
2118 Get_Pragma_Arg (Arg2));
2119 Error_Pragma_Arg
2120 ("\supply appropriate type for&!", Arg2);
2121 end if;
2123 if Etype (E) = Any_Type
2124 or else Rep_Item_Too_Early (E, N)
2125 then
2126 raise Pragma_Exit;
2127 else
2128 E := Underlying_Type (E);
2129 end if;
2131 if Rep_Item_Too_Late (E, N) then
2132 raise Pragma_Exit;
2133 end if;
2135 if Has_Convention_Pragma (E) then
2136 Error_Pragma_Arg
2137 ("at most one Convention/Export/Import pragma is allowed", Arg2);
2139 elsif Convention (E) = Convention_Protected
2140 or else Ekind (Scope (E)) = E_Protected_Type
2141 then
2142 Error_Pragma_Arg
2143 ("a protected operation cannot be given a different convention",
2144 Arg2);
2145 end if;
2147 -- For Intrinsic, a subprogram is required
2149 if C = Convention_Intrinsic
2150 and then not Is_Subprogram (E)
2151 and then not Is_Generic_Subprogram (E)
2152 then
2153 Error_Pragma_Arg
2154 ("second argument of pragma% must be a subprogram", Arg2);
2155 end if;
2157 -- For Stdcall, a subprogram, variable or subprogram type is required
2159 if C = Convention_Stdcall
2160 and then not Is_Subprogram (E)
2161 and then not Is_Generic_Subprogram (E)
2162 and then Ekind (E) /= E_Variable
2163 and then not
2164 (Is_Access_Type (E)
2165 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2166 then
2167 Error_Pragma_Arg
2168 ("second argument of pragma% must be subprogram (type)",
2169 Arg2);
2170 end if;
2172 if not Is_Subprogram (E)
2173 and then not Is_Generic_Subprogram (E)
2174 then
2175 Set_Convention_From_Pragma (E);
2177 if Is_Type (E) then
2179 Check_First_Subtype (Arg2);
2180 Set_Convention_From_Pragma (Base_Type (E));
2182 -- For subprograms, we must set the convention on the
2183 -- internally generated directly designated type as well.
2185 if Ekind (E) = E_Access_Subprogram_Type then
2186 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2187 end if;
2188 end if;
2190 -- For the subprogram case, set proper convention for all homonyms
2191 -- in same scope and the same declarative part, i.e. the same
2192 -- compilation unit.
2194 else
2195 Comp_Unit := Get_Source_Unit (E);
2196 Set_Convention_From_Pragma (E);
2198 -- Treat a pragma Import as an implicit body, for GPS use
2200 if Prag_Id = Pragma_Import then
2201 Generate_Reference (E, Id, 'b');
2202 end if;
2204 E1 := E;
2205 loop
2206 E1 := Homonym (E1);
2207 exit when No (E1) or else Scope (E1) /= Current_Scope;
2209 -- Note: below we are missing a check for Rep_Item_Too_Late.
2210 -- That is deliberate, we cannot chain the rep item on more
2211 -- than one Rep_Item chain, to be fixed later ???
2213 if Comes_From_Source (E1)
2214 and then Comp_Unit = Get_Source_Unit (E1)
2215 and then Nkind (Original_Node (Parent (E1))) /=
2216 N_Full_Type_Declaration
2217 then
2218 Set_Convention_From_Pragma (E1);
2220 if Prag_Id = Pragma_Import then
2221 Generate_Reference (E, Id, 'b');
2222 end if;
2223 end if;
2224 end loop;
2225 end if;
2226 end Process_Convention;
2228 -----------------------------------------------------
2229 -- Process_Extended_Import_Export_Exception_Pragma --
2230 -----------------------------------------------------
2232 procedure Process_Extended_Import_Export_Exception_Pragma
2233 (Arg_Internal : Node_Id;
2234 Arg_External : Node_Id;
2235 Arg_Form : Node_Id;
2236 Arg_Code : Node_Id)
2238 Def_Id : Entity_Id;
2239 Code_Val : Uint;
2241 begin
2242 GNAT_Pragma;
2244 if not OpenVMS_On_Target then
2245 Error_Pragma
2246 ("?pragma% ignored (applies only to Open'V'M'S)");
2247 end if;
2249 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2250 Def_Id := Entity (Arg_Internal);
2252 if Ekind (Def_Id) /= E_Exception then
2253 Error_Pragma_Arg
2254 ("pragma% must refer to declared exception", Arg_Internal);
2255 end if;
2257 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2259 if Present (Arg_Form) then
2260 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2261 end if;
2263 if Present (Arg_Form)
2264 and then Chars (Arg_Form) = Name_Ada
2265 then
2266 null;
2267 else
2268 Set_Is_VMS_Exception (Def_Id);
2269 Set_Exception_Code (Def_Id, No_Uint);
2270 end if;
2272 if Present (Arg_Code) then
2273 if not Is_VMS_Exception (Def_Id) then
2274 Error_Pragma_Arg
2275 ("Code option for pragma% not allowed for Ada case",
2276 Arg_Code);
2277 end if;
2279 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2280 Code_Val := Expr_Value (Arg_Code);
2282 if not UI_Is_In_Int_Range (Code_Val) then
2283 Error_Pragma_Arg
2284 ("Code option for pragma% must be in 32-bit range",
2285 Arg_Code);
2287 else
2288 Set_Exception_Code (Def_Id, Code_Val);
2289 end if;
2290 end if;
2291 end Process_Extended_Import_Export_Exception_Pragma;
2293 -------------------------------------------------
2294 -- Process_Extended_Import_Export_Internal_Arg --
2295 -------------------------------------------------
2297 procedure Process_Extended_Import_Export_Internal_Arg
2298 (Arg_Internal : Node_Id := Empty)
2300 begin
2301 GNAT_Pragma;
2303 if No (Arg_Internal) then
2304 Error_Pragma ("Internal parameter required for pragma%");
2305 end if;
2307 if Nkind (Arg_Internal) = N_Identifier then
2308 null;
2310 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2311 and then (Prag_Id = Pragma_Import_Function
2312 or else
2313 Prag_Id = Pragma_Export_Function)
2314 then
2315 null;
2317 else
2318 Error_Pragma_Arg
2319 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2320 end if;
2322 Check_Arg_Is_Local_Name (Arg_Internal);
2323 end Process_Extended_Import_Export_Internal_Arg;
2325 --------------------------------------------------
2326 -- Process_Extended_Import_Export_Object_Pragma --
2327 --------------------------------------------------
2329 procedure Process_Extended_Import_Export_Object_Pragma
2330 (Arg_Internal : Node_Id;
2331 Arg_External : Node_Id;
2332 Arg_Size : Node_Id)
2334 Def_Id : Entity_Id;
2336 begin
2337 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2338 Def_Id := Entity (Arg_Internal);
2340 if Ekind (Def_Id) /= E_Constant
2341 and then Ekind (Def_Id) /= E_Variable
2342 then
2343 Error_Pragma_Arg
2344 ("pragma% must designate an object", Arg_Internal);
2345 end if;
2347 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2348 or else
2349 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2350 then
2351 Error_Pragma_Arg
2352 ("previous Common/Psect_Object applies, pragma % not permitted",
2353 Arg_Internal);
2354 end if;
2356 if Rep_Item_Too_Late (Def_Id, N) then
2357 raise Pragma_Exit;
2358 end if;
2360 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2362 if Present (Arg_Size) then
2363 Check_Arg_Is_External_Name (Arg_Size);
2364 end if;
2366 -- Export_Object case
2368 if Prag_Id = Pragma_Export_Object then
2369 if not Is_Library_Level_Entity (Def_Id) then
2370 Error_Pragma_Arg
2371 ("argument for pragma% must be library level entity",
2372 Arg_Internal);
2373 end if;
2375 if Ekind (Current_Scope) = E_Generic_Package then
2376 Error_Pragma ("pragma& cannot appear in a generic unit");
2377 end if;
2379 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2380 Error_Pragma_Arg
2381 ("exported object must have compile time known size",
2382 Arg_Internal);
2383 end if;
2385 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2386 Error_Msg_N
2387 ("?duplicate Export_Object pragma", N);
2388 else
2389 Set_Exported (Def_Id, Arg_Internal);
2390 end if;
2392 -- Import_Object case
2394 else
2395 if Is_Concurrent_Type (Etype (Def_Id)) then
2396 Error_Pragma_Arg
2397 ("cannot use pragma% for task/protected object",
2398 Arg_Internal);
2399 end if;
2401 if Ekind (Def_Id) = E_Constant then
2402 Error_Pragma_Arg
2403 ("cannot import a constant", Arg_Internal);
2404 end if;
2406 if Warn_On_Export_Import
2407 and then Has_Discriminants (Etype (Def_Id))
2408 then
2409 Error_Msg_N
2410 ("imported value must be initialized?", Arg_Internal);
2411 end if;
2413 if Warn_On_Export_Import
2414 and then Is_Access_Type (Etype (Def_Id))
2415 then
2416 Error_Pragma_Arg
2417 ("cannot import object of an access type?", Arg_Internal);
2418 end if;
2420 if Warn_On_Export_Import
2421 and then Is_Imported (Def_Id)
2422 then
2423 Error_Msg_N
2424 ("?duplicate Import_Object pragma", N);
2426 -- Check for explicit initialization present. Note that an
2427 -- initialization that generated by the code generator, e.g.
2428 -- for an access type, does not count here.
2430 elsif Present (Expression (Parent (Def_Id)))
2431 and then
2432 Comes_From_Source
2433 (Original_Node (Expression (Parent (Def_Id))))
2434 then
2435 Error_Msg_Sloc := Sloc (Def_Id);
2436 Error_Pragma_Arg
2437 ("no initialization allowed for declaration of& #",
2438 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2439 Arg1);
2440 else
2441 Set_Imported (Def_Id);
2442 Note_Possible_Modification (Arg_Internal);
2443 end if;
2444 end if;
2445 end Process_Extended_Import_Export_Object_Pragma;
2447 ------------------------------------------------------
2448 -- Process_Extended_Import_Export_Subprogram_Pragma --
2449 ------------------------------------------------------
2451 procedure Process_Extended_Import_Export_Subprogram_Pragma
2452 (Arg_Internal : Node_Id;
2453 Arg_External : Node_Id;
2454 Arg_Parameter_Types : Node_Id;
2455 Arg_Result_Type : Node_Id := Empty;
2456 Arg_Mechanism : Node_Id;
2457 Arg_Result_Mechanism : Node_Id := Empty;
2458 Arg_First_Optional_Parameter : Node_Id := Empty)
2460 Ent : Entity_Id;
2461 Def_Id : Entity_Id;
2462 Hom_Id : Entity_Id;
2463 Formal : Entity_Id;
2464 Ambiguous : Boolean;
2465 Match : Boolean;
2466 Dval : Node_Id;
2468 function Same_Base_Type
2469 (Ptype : Node_Id;
2470 Formal : Entity_Id) return Boolean;
2471 -- Determines if Ptype references the type of Formal. Note that
2472 -- only the base types need to match according to the spec. Ptype
2473 -- here is the argument from the pragma, which is either a type
2474 -- name, or an access attribute.
2476 --------------------
2477 -- Same_Base_Type --
2478 --------------------
2480 function Same_Base_Type
2481 (Ptype : Node_Id;
2482 Formal : Entity_Id) return Boolean
2484 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2485 Pref : Node_Id;
2487 begin
2488 -- Case where pragma argument is typ'Access
2490 if Nkind (Ptype) = N_Attribute_Reference
2491 and then Attribute_Name (Ptype) = Name_Access
2492 then
2493 Pref := Prefix (Ptype);
2494 Find_Type (Pref);
2496 if not Is_Entity_Name (Pref)
2497 or else Entity (Pref) = Any_Type
2498 then
2499 raise Pragma_Exit;
2500 end if;
2502 -- We have a match if the corresponding argument is of an
2503 -- anonymous access type, and its designicated type matches
2504 -- the type of the prefix of the access attribute
2506 return Ekind (Ftyp) = E_Anonymous_Access_Type
2507 and then Base_Type (Entity (Pref)) =
2508 Base_Type (Etype (Designated_Type (Ftyp)));
2510 -- Case where pragma argument is a type name
2512 else
2513 Find_Type (Ptype);
2515 if not Is_Entity_Name (Ptype)
2516 or else Entity (Ptype) = Any_Type
2517 then
2518 raise Pragma_Exit;
2519 end if;
2521 -- We have a match if the corresponding argument is of
2522 -- the type given in the pragma (comparing base types)
2524 return Base_Type (Entity (Ptype)) = Ftyp;
2525 end if;
2526 end Same_Base_Type;
2528 -- Start of processing for
2529 -- Process_Extended_Import_Export_Subprogram_Pragma
2531 begin
2532 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2533 Ent := Empty;
2534 Ambiguous := False;
2536 -- Loop through homonyms (overloadings) of the entity
2538 Hom_Id := Entity (Arg_Internal);
2539 while Present (Hom_Id) loop
2540 Def_Id := Get_Base_Subprogram (Hom_Id);
2542 -- We need a subprogram in the current scope
2544 if not Is_Subprogram (Def_Id)
2545 or else Scope (Def_Id) /= Current_Scope
2546 then
2547 null;
2549 else
2550 Match := True;
2552 -- Pragma cannot apply to subprogram body
2554 if Is_Subprogram (Def_Id)
2555 and then
2556 Nkind (Parent
2557 (Declaration_Node (Def_Id))) = N_Subprogram_Body
2558 then
2559 Error_Pragma
2560 ("pragma% requires separate spec"
2561 & " and must come before body");
2562 end if;
2564 -- Test result type if given, note that the result type
2565 -- parameter can only be present for the function cases.
2567 if Present (Arg_Result_Type)
2568 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2569 then
2570 Match := False;
2572 elsif Etype (Def_Id) /= Standard_Void_Type
2573 and then
2574 (Chars (N) = Name_Export_Procedure
2575 or else Chars (N) = Name_Import_Procedure)
2576 then
2577 Match := False;
2579 -- Test parameter types if given. Note that this parameter
2580 -- has not been analyzed (and must not be, since it is
2581 -- semantic nonsense), so we get it as the parser left it.
2583 elsif Present (Arg_Parameter_Types) then
2584 Check_Matching_Types : declare
2585 Formal : Entity_Id;
2586 Ptype : Node_Id;
2588 begin
2589 Formal := First_Formal (Def_Id);
2591 if Nkind (Arg_Parameter_Types) = N_Null then
2592 if Present (Formal) then
2593 Match := False;
2594 end if;
2596 -- A list of one type, e.g. (List) is parsed as
2597 -- a parenthesized expression.
2599 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
2600 and then Paren_Count (Arg_Parameter_Types) = 1
2601 then
2602 if No (Formal)
2603 or else Present (Next_Formal (Formal))
2604 then
2605 Match := False;
2606 else
2607 Match :=
2608 Same_Base_Type (Arg_Parameter_Types, Formal);
2609 end if;
2611 -- A list of more than one type is parsed as a aggregate
2613 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
2614 and then Paren_Count (Arg_Parameter_Types) = 0
2615 then
2616 Ptype := First (Expressions (Arg_Parameter_Types));
2617 while Present (Ptype) or else Present (Formal) loop
2618 if No (Ptype)
2619 or else No (Formal)
2620 or else not Same_Base_Type (Ptype, Formal)
2621 then
2622 Match := False;
2623 exit;
2624 else
2625 Next_Formal (Formal);
2626 Next (Ptype);
2627 end if;
2628 end loop;
2630 -- Anything else is of the wrong form
2632 else
2633 Error_Pragma_Arg
2634 ("wrong form for Parameter_Types parameter",
2635 Arg_Parameter_Types);
2636 end if;
2637 end Check_Matching_Types;
2638 end if;
2640 -- Match is now False if the entry we found did not match
2641 -- either a supplied Parameter_Types or Result_Types argument
2643 if Match then
2644 if No (Ent) then
2645 Ent := Def_Id;
2647 -- Ambiguous case, the flag Ambiguous shows if we already
2648 -- detected this and output the initial messages.
2650 else
2651 if not Ambiguous then
2652 Ambiguous := True;
2653 Error_Msg_Name_1 := Chars (N);
2654 Error_Msg_N
2655 ("pragma% does not uniquely identify subprogram!",
2657 Error_Msg_Sloc := Sloc (Ent);
2658 Error_Msg_N ("matching subprogram #!", N);
2659 Ent := Empty;
2660 end if;
2662 Error_Msg_Sloc := Sloc (Def_Id);
2663 Error_Msg_N ("matching subprogram #!", N);
2664 end if;
2665 end if;
2666 end if;
2668 Hom_Id := Homonym (Hom_Id);
2669 end loop;
2671 -- See if we found an entry
2673 if No (Ent) then
2674 if not Ambiguous then
2675 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
2676 Error_Pragma
2677 ("pragma% cannot be given for generic subprogram");
2679 else
2680 Error_Pragma
2681 ("pragma% does not identify local subprogram");
2682 end if;
2683 end if;
2685 return;
2686 end if;
2688 -- Import pragmas must be be for imported entities
2690 if Prag_Id = Pragma_Import_Function
2691 or else
2692 Prag_Id = Pragma_Import_Procedure
2693 or else
2694 Prag_Id = Pragma_Import_Valued_Procedure
2695 then
2696 if not Is_Imported (Ent) then
2697 Error_Pragma
2698 ("pragma Import or Interface must precede pragma%");
2699 end if;
2701 -- Here we have the Export case which can set the entity as exported
2703 -- But does not do so if the specified external name is null,
2704 -- since that is taken as a signal in DEC Ada 83 (with which
2705 -- we want to be compatible) to request no external name.
2707 elsif Nkind (Arg_External) = N_String_Literal
2708 and then String_Length (Strval (Arg_External)) = 0
2709 then
2710 null;
2712 -- In all other cases, set entit as exported
2714 else
2715 Set_Exported (Ent, Arg_Internal);
2716 end if;
2718 -- Special processing for Valued_Procedure cases
2720 if Prag_Id = Pragma_Import_Valued_Procedure
2721 or else
2722 Prag_Id = Pragma_Export_Valued_Procedure
2723 then
2724 Formal := First_Formal (Ent);
2726 if No (Formal) then
2727 Error_Pragma
2728 ("at least one parameter required for pragma%");
2730 elsif Ekind (Formal) /= E_Out_Parameter then
2731 Error_Pragma
2732 ("first parameter must have mode out for pragma%");
2734 else
2735 Set_Is_Valued_Procedure (Ent);
2736 end if;
2737 end if;
2739 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
2741 -- Process Result_Mechanism argument if present. We have already
2742 -- checked that this is only allowed for the function case.
2744 if Present (Arg_Result_Mechanism) then
2745 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
2746 end if;
2748 -- Process Mechanism parameter if present. Note that this parameter
2749 -- is not analyzed, and must not be analyzed since it is semantic
2750 -- nonsense, so we get it in exactly as the parser left it.
2752 if Present (Arg_Mechanism) then
2753 declare
2754 Formal : Entity_Id;
2755 Massoc : Node_Id;
2756 Mname : Node_Id;
2757 Choice : Node_Id;
2759 begin
2760 -- A single mechanism association without a formal parameter
2761 -- name is parsed as a parenthesized expression. All other
2762 -- cases are parsed as aggregates, so we rewrite the single
2763 -- parameter case as an aggregate for consistency.
2765 if Nkind (Arg_Mechanism) /= N_Aggregate
2766 and then Paren_Count (Arg_Mechanism) = 1
2767 then
2768 Rewrite (Arg_Mechanism,
2769 Make_Aggregate (Sloc (Arg_Mechanism),
2770 Expressions => New_List (
2771 Relocate_Node (Arg_Mechanism))));
2772 end if;
2774 -- Case of only mechanism name given, applies to all formals
2776 if Nkind (Arg_Mechanism) /= N_Aggregate then
2777 Formal := First_Formal (Ent);
2778 while Present (Formal) loop
2779 Set_Mechanism_Value (Formal, Arg_Mechanism);
2780 Next_Formal (Formal);
2781 end loop;
2783 -- Case of list of mechanism associations given
2785 else
2786 if Null_Record_Present (Arg_Mechanism) then
2787 Error_Pragma_Arg
2788 ("inappropriate form for Mechanism parameter",
2789 Arg_Mechanism);
2790 end if;
2792 -- Deal with positional ones first
2794 Formal := First_Formal (Ent);
2796 if Present (Expressions (Arg_Mechanism)) then
2797 Mname := First (Expressions (Arg_Mechanism));
2799 while Present (Mname) loop
2800 if No (Formal) then
2801 Error_Pragma_Arg
2802 ("too many mechanism associations", Mname);
2803 end if;
2805 Set_Mechanism_Value (Formal, Mname);
2806 Next_Formal (Formal);
2807 Next (Mname);
2808 end loop;
2809 end if;
2811 -- Deal with named entries
2813 if Present (Component_Associations (Arg_Mechanism)) then
2814 Massoc := First (Component_Associations (Arg_Mechanism));
2816 while Present (Massoc) loop
2817 Choice := First (Choices (Massoc));
2819 if Nkind (Choice) /= N_Identifier
2820 or else Present (Next (Choice))
2821 then
2822 Error_Pragma_Arg
2823 ("incorrect form for mechanism association",
2824 Massoc);
2825 end if;
2827 Formal := First_Formal (Ent);
2828 loop
2829 if No (Formal) then
2830 Error_Pragma_Arg
2831 ("parameter name & not present", Choice);
2832 end if;
2834 if Chars (Choice) = Chars (Formal) then
2835 Set_Mechanism_Value
2836 (Formal, Expression (Massoc));
2837 exit;
2838 end if;
2840 Next_Formal (Formal);
2841 end loop;
2843 Next (Massoc);
2844 end loop;
2845 end if;
2846 end if;
2847 end;
2848 end if;
2850 -- Process First_Optional_Parameter argument if present. We have
2851 -- already checked that this is only allowed for the Import case.
2853 if Present (Arg_First_Optional_Parameter) then
2854 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
2855 Error_Pragma_Arg
2856 ("first optional parameter must be formal parameter name",
2857 Arg_First_Optional_Parameter);
2858 end if;
2860 Formal := First_Formal (Ent);
2861 loop
2862 if No (Formal) then
2863 Error_Pragma_Arg
2864 ("specified formal parameter& not found",
2865 Arg_First_Optional_Parameter);
2866 end if;
2868 exit when Chars (Formal) =
2869 Chars (Arg_First_Optional_Parameter);
2871 Next_Formal (Formal);
2872 end loop;
2874 Set_First_Optional_Parameter (Ent, Formal);
2876 -- Check specified and all remaining formals have right form
2878 while Present (Formal) loop
2879 if Ekind (Formal) /= E_In_Parameter then
2880 Error_Msg_NE
2881 ("optional formal& is not of mode in!",
2882 Arg_First_Optional_Parameter, Formal);
2884 else
2885 Dval := Default_Value (Formal);
2887 if No (Dval) then
2888 Error_Msg_NE
2889 ("optional formal& does not have default value!",
2890 Arg_First_Optional_Parameter, Formal);
2892 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
2893 null;
2895 else
2896 Error_Msg_FE
2897 ("default value for optional formal& is non-static!",
2898 Arg_First_Optional_Parameter, Formal);
2899 end if;
2900 end if;
2902 Set_Is_Optional_Parameter (Formal);
2903 Next_Formal (Formal);
2904 end loop;
2905 end if;
2906 end Process_Extended_Import_Export_Subprogram_Pragma;
2908 --------------------------
2909 -- Process_Generic_List --
2910 --------------------------
2912 procedure Process_Generic_List is
2913 Arg : Node_Id;
2914 Exp : Node_Id;
2916 begin
2917 GNAT_Pragma;
2918 Check_No_Identifiers;
2919 Check_At_Least_N_Arguments (1);
2921 Arg := Arg1;
2922 while Present (Arg) loop
2923 Exp := Expression (Arg);
2924 Analyze (Exp);
2926 if not Is_Entity_Name (Exp)
2927 or else
2928 (not Is_Generic_Instance (Entity (Exp))
2929 and then
2930 not Is_Generic_Unit (Entity (Exp)))
2931 then
2932 Error_Pragma_Arg
2933 ("pragma% argument must be name of generic unit/instance",
2934 Arg);
2935 end if;
2937 Next (Arg);
2938 end loop;
2939 end Process_Generic_List;
2941 ---------------------------------
2942 -- Process_Import_Or_Interface --
2943 ---------------------------------
2945 procedure Process_Import_Or_Interface is
2946 C : Convention_Id;
2947 Def_Id : Entity_Id;
2948 Hom_Id : Entity_Id;
2950 begin
2951 Process_Convention (C, Def_Id);
2952 Kill_Size_Check_Code (Def_Id);
2953 Note_Possible_Modification (Expression (Arg2));
2955 if Ekind (Def_Id) = E_Variable
2956 or else
2957 Ekind (Def_Id) = E_Constant
2958 then
2959 -- User initialization is not allowed for imported object, but
2960 -- the object declaration may contain a default initialization,
2961 -- that will be discarded. Note that an explicit initialization
2962 -- only counts if it comes from source, otherwise it is simply
2963 -- the code generator making an implicit initialization explicit.
2965 if Present (Expression (Parent (Def_Id)))
2966 and then Comes_From_Source (Expression (Parent (Def_Id)))
2967 then
2968 Error_Msg_Sloc := Sloc (Def_Id);
2969 Error_Pragma_Arg
2970 ("no initialization allowed for declaration of& #",
2971 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2972 Arg2);
2974 else
2975 Set_Imported (Def_Id);
2976 Process_Interface_Name (Def_Id, Arg3, Arg4);
2978 -- Note that we do not set Is_Public here. That's because we
2979 -- only want to set if if there is no address clause, and we
2980 -- don't know that yet, so we delay that processing till
2981 -- freeze time.
2983 -- pragma Import completes deferred constants
2985 if Ekind (Def_Id) = E_Constant then
2986 Set_Has_Completion (Def_Id);
2987 end if;
2989 -- It is not possible to import a constant of an unconstrained
2990 -- array type (e.g. string) because there is no simple way to
2991 -- write a meaningful subtype for it.
2993 if Is_Array_Type (Etype (Def_Id))
2994 and then not Is_Constrained (Etype (Def_Id))
2995 then
2996 Error_Msg_NE
2997 ("imported constant& must have a constrained subtype",
2998 N, Def_Id);
2999 end if;
3000 end if;
3002 elsif Is_Subprogram (Def_Id)
3003 or else Is_Generic_Subprogram (Def_Id)
3004 then
3005 -- If the name is overloaded, pragma applies to all of the
3006 -- denoted entities in the same declarative part.
3008 Hom_Id := Def_Id;
3009 while Present (Hom_Id) loop
3010 Def_Id := Get_Base_Subprogram (Hom_Id);
3012 -- Ignore inherited subprograms because the pragma will
3013 -- apply to the parent operation, which is the one called.
3015 if Is_Overloadable (Def_Id)
3016 and then Present (Alias (Def_Id))
3017 then
3018 null;
3020 -- If it is not a subprogram, it must be in an outer
3021 -- scope and pragma does not apply.
3023 elsif not Is_Subprogram (Def_Id)
3024 and then not Is_Generic_Subprogram (Def_Id)
3025 then
3026 null;
3028 -- Verify that the homonym is in the same declarative
3029 -- part (not just the same scope).
3031 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3032 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3033 then
3034 exit;
3036 else
3037 Set_Imported (Def_Id);
3039 -- Special processing for Convention_Intrinsic
3041 if C = Convention_Intrinsic then
3043 -- Link_Name argument not allowed for intrinsic
3045 if Present (Arg3)
3046 and then Chars (Arg3) = Name_Link_Name
3047 then
3048 Arg4 := Arg3;
3049 end if;
3051 if Present (Arg4) then
3052 Error_Pragma_Arg
3053 ("Link_Name argument not allowed for " &
3054 "Import Intrinsic",
3055 Arg4);
3056 end if;
3058 Set_Is_Intrinsic_Subprogram (Def_Id);
3060 -- If no external name is present, then check that
3061 -- this is a valid intrinsic subprogram. If an external
3062 -- name is present, then this is handled by the back end.
3064 if No (Arg3) then
3065 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3066 end if;
3067 end if;
3069 -- All interfaced procedures need an external symbol
3070 -- created for them since they are always referenced
3071 -- from another object file.
3073 Set_Is_Public (Def_Id);
3075 -- Verify that the subprogram does not have a completion
3076 -- through a renaming declaration. For other completions
3077 -- the pragma appears as a too late representation.
3079 declare
3080 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3082 begin
3083 if Present (Decl)
3084 and then Nkind (Decl) = N_Subprogram_Declaration
3085 and then Present (Corresponding_Body (Decl))
3086 and then
3087 Nkind
3088 (Unit_Declaration_Node
3089 (Corresponding_Body (Decl))) =
3090 N_Subprogram_Renaming_Declaration
3091 then
3092 Error_Msg_Sloc := Sloc (Def_Id);
3093 Error_Msg_NE ("cannot import&#," &
3094 " already completed by a renaming",
3095 N, Def_Id);
3096 end if;
3097 end;
3099 Set_Has_Completion (Def_Id);
3100 Process_Interface_Name (Def_Id, Arg3, Arg4);
3101 end if;
3103 if Is_Compilation_Unit (Hom_Id) then
3105 -- Its possible homonyms are not affected by the pragma.
3106 -- Such homonyms might be present in the context of other
3107 -- units being compiled.
3109 exit;
3111 else
3112 Hom_Id := Homonym (Hom_Id);
3113 end if;
3114 end loop;
3116 -- When the convention is Java, we also allow Import to be given
3117 -- for packages, exceptions, and record components.
3119 elsif C = Convention_Java
3120 and then
3121 (Ekind (Def_Id) = E_Package
3122 or else Ekind (Def_Id) = E_Exception
3123 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3124 then
3125 Set_Imported (Def_Id);
3126 Set_Is_Public (Def_Id);
3127 Process_Interface_Name (Def_Id, Arg3, Arg4);
3129 else
3130 Error_Pragma_Arg
3131 ("second argument of pragma% must be object or subprogram",
3132 Arg2);
3133 end if;
3135 -- If this pragma applies to a compilation unit, then the unit,
3136 -- which is a subprogram, does not require (or allow) a body.
3137 -- We also do not need to elaborate imported procedures.
3139 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3140 declare
3141 Cunit : constant Node_Id := Parent (Parent (N));
3142 begin
3143 Set_Body_Required (Cunit, False);
3144 end;
3145 end if;
3146 end Process_Import_Or_Interface;
3148 --------------------
3149 -- Process_Inline --
3150 --------------------
3152 procedure Process_Inline (Active : Boolean) is
3153 Assoc : Node_Id;
3154 Decl : Node_Id;
3155 Subp_Id : Node_Id;
3156 Subp : Entity_Id;
3157 Applies : Boolean;
3158 Effective : Boolean := False;
3160 procedure Make_Inline (Subp : Entity_Id);
3161 -- Subp is the defining unit name of the subprogram
3162 -- declaration. Set the flag, as well as the flag in the
3163 -- corresponding body, if there is one present.
3165 procedure Set_Inline_Flags (Subp : Entity_Id);
3166 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp
3168 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3169 -- Returns True if it can be determined at this stage that inlining
3170 -- is not possible, for examle if the body is available and contains
3171 -- exception handlers, we prevent inlining, since otherwise we can
3172 -- get undefined symbols at link time. This function also emits a
3173 -- warning if front-end inlining is enabled and the pragma appears
3174 -- too late.
3175 -- ??? is business with link symbols still valid, or does it relate
3176 -- to front end ZCX which is being phased out ???
3178 ---------------------------
3179 -- Inlining_Not_Possible --
3180 ---------------------------
3182 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3183 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3184 Stats : Node_Id;
3186 begin
3187 if Nkind (Decl) = N_Subprogram_Body then
3188 Stats := Handled_Statement_Sequence (Decl);
3189 return Present (Exception_Handlers (Stats))
3190 or else Present (At_End_Proc (Stats));
3192 elsif Nkind (Decl) = N_Subprogram_Declaration
3193 and then Present (Corresponding_Body (Decl))
3194 then
3195 if Front_End_Inlining
3196 and then Analyzed (Corresponding_Body (Decl))
3197 then
3198 Error_Msg_N ("pragma appears too late, ignored?", N);
3199 return True;
3201 -- If the subprogram is a renaming as body, the body is
3202 -- just a call to the renamed subprogram, and inlining is
3203 -- trivially possible.
3205 elsif
3206 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
3207 = N_Subprogram_Renaming_Declaration
3208 then
3209 return False;
3211 else
3212 Stats :=
3213 Handled_Statement_Sequence
3214 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3216 return
3217 Present (Exception_Handlers (Stats))
3218 or else Present (At_End_Proc (Stats));
3219 end if;
3221 else
3222 -- If body is not available, assume the best, the check is
3223 -- performed again when compiling enclosing package bodies.
3225 return False;
3226 end if;
3227 end Inlining_Not_Possible;
3229 -----------------
3230 -- Make_Inline --
3231 -----------------
3233 procedure Make_Inline (Subp : Entity_Id) is
3234 Kind : constant Entity_Kind := Ekind (Subp);
3235 Inner_Subp : Entity_Id := Subp;
3237 begin
3238 if Etype (Subp) = Any_Type then
3239 return;
3241 -- If inlining is not possible, for now do not treat as an error
3243 elsif Inlining_Not_Possible (Subp) then
3244 Applies := True;
3245 return;
3247 -- Here we have a candidate for inlining, but we must exclude
3248 -- derived operations. Otherwise we will end up trying to
3249 -- inline a phantom declaration, and the result would be to
3250 -- drag in a body which has no direct inlining associated with
3251 -- it. That would not only be inefficient but would also result
3252 -- in the backend doing cross-unit inlining in cases where it
3253 -- was definitely inappropriate to do so.
3255 -- However, a simple Comes_From_Source test is insufficient,
3256 -- since we do want to allow inlining of generic instances,
3257 -- which also do not come from source. Predefined operators do
3258 -- not come from source but are not inlineable either.
3260 elsif not Comes_From_Source (Subp)
3261 and then not Is_Generic_Instance (Subp)
3262 and then Scope (Subp) /= Standard_Standard
3263 then
3264 Applies := True;
3265 return;
3267 -- The referenced entity must either be the enclosing entity,
3268 -- or an entity declared within the current open scope.
3270 elsif Present (Scope (Subp))
3271 and then Scope (Subp) /= Current_Scope
3272 and then Subp /= Current_Scope
3273 then
3274 Error_Pragma_Arg
3275 ("argument of% must be entity in current scope", Assoc);
3276 return;
3277 end if;
3279 -- Processing for procedure, operator or function.
3280 -- If subprogram is aliased (as for an instance) indicate
3281 -- that the renamed entity (if declared in the same unit)
3282 -- is inlined.
3284 if Is_Subprogram (Subp) then
3285 while Present (Alias (Inner_Subp)) loop
3286 Inner_Subp := Alias (Inner_Subp);
3287 end loop;
3289 if In_Same_Source_Unit (Subp, Inner_Subp) then
3290 Set_Inline_Flags (Inner_Subp);
3292 Decl := Parent (Parent (Inner_Subp));
3294 if Nkind (Decl) = N_Subprogram_Declaration
3295 and then Present (Corresponding_Body (Decl))
3296 then
3297 Set_Inline_Flags (Corresponding_Body (Decl));
3298 end if;
3299 end if;
3301 Applies := True;
3303 -- For a generic subprogram set flag as well, for use at
3304 -- the point of instantiation, to determine whether the
3305 -- body should be generated.
3307 elsif Is_Generic_Subprogram (Subp) then
3308 Set_Inline_Flags (Subp);
3309 Applies := True;
3311 -- Literals are by definition inlined
3313 elsif Kind = E_Enumeration_Literal then
3314 null;
3316 -- Anything else is an error
3318 else
3319 Error_Pragma_Arg
3320 ("expect subprogram name for pragma%", Assoc);
3321 end if;
3322 end Make_Inline;
3324 ----------------------
3325 -- Set_Inline_Flags --
3326 ----------------------
3328 procedure Set_Inline_Flags (Subp : Entity_Id) is
3329 begin
3330 if Active then
3331 Set_Is_Inlined (Subp, True);
3332 end if;
3334 if not Has_Pragma_Inline (Subp) then
3335 Set_Has_Pragma_Inline (Subp);
3336 Set_Next_Rep_Item (N, First_Rep_Item (Subp));
3337 Set_First_Rep_Item (Subp, N);
3338 Effective := True;
3339 end if;
3340 end Set_Inline_Flags;
3342 -- Start of processing for Process_Inline
3344 begin
3345 Check_No_Identifiers;
3346 Check_At_Least_N_Arguments (1);
3348 if Active then
3349 Inline_Processing_Required := True;
3350 end if;
3352 Assoc := Arg1;
3353 while Present (Assoc) loop
3354 Subp_Id := Expression (Assoc);
3355 Analyze (Subp_Id);
3356 Applies := False;
3358 if Is_Entity_Name (Subp_Id) then
3359 Subp := Entity (Subp_Id);
3361 if Subp = Any_Id then
3363 -- If previous error, avoid cascaded errors
3365 Applies := True;
3366 Effective := True;
3368 else
3369 Make_Inline (Subp);
3371 while Present (Homonym (Subp))
3372 and then Scope (Homonym (Subp)) = Current_Scope
3373 loop
3374 Make_Inline (Homonym (Subp));
3375 Subp := Homonym (Subp);
3376 end loop;
3377 end if;
3378 end if;
3380 if not Applies then
3381 Error_Pragma_Arg
3382 ("inappropriate argument for pragma%", Assoc);
3384 elsif not Effective
3385 and then Warn_On_Redundant_Constructs
3386 then
3387 if Inlining_Not_Possible (Subp) then
3388 Error_Msg_NE
3389 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
3390 else
3391 Error_Msg_NE
3392 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
3393 end if;
3394 end if;
3396 Next (Assoc);
3397 end loop;
3398 end Process_Inline;
3400 ----------------------------
3401 -- Process_Interface_Name --
3402 ----------------------------
3404 procedure Process_Interface_Name
3405 (Subprogram_Def : Entity_Id;
3406 Ext_Arg : Node_Id;
3407 Link_Arg : Node_Id)
3409 Ext_Nam : Node_Id;
3410 Link_Nam : Node_Id;
3411 String_Val : String_Id;
3413 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
3414 -- SN is a string literal node for an interface name. This routine
3415 -- performs some minimal checks that the name is reasonable. In
3416 -- particular that no spaces or other obviously incorrect characters
3417 -- appear. This is only a warning, since any characters are allowed.
3419 ----------------------------------
3420 -- Check_Form_Of_Interface_Name --
3421 ----------------------------------
3423 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
3424 S : constant String_Id := Strval (Expr_Value_S (SN));
3425 SL : constant Nat := String_Length (S);
3426 C : Char_Code;
3428 begin
3429 if SL = 0 then
3430 Error_Msg_N ("interface name cannot be null string", SN);
3431 end if;
3433 for J in 1 .. SL loop
3434 C := Get_String_Char (S, J);
3436 if Warn_On_Export_Import
3437 and then (not In_Character_Range (C)
3438 or else Get_Character (C) = ' '
3439 or else Get_Character (C) = ',')
3440 then
3441 Error_Msg_N
3442 ("?interface name contains illegal character", SN);
3443 end if;
3444 end loop;
3445 end Check_Form_Of_Interface_Name;
3447 -- Start of processing for Process_Interface_Name
3449 begin
3450 if No (Link_Arg) then
3451 if No (Ext_Arg) then
3452 return;
3454 elsif Chars (Ext_Arg) = Name_Link_Name then
3455 Ext_Nam := Empty;
3456 Link_Nam := Expression (Ext_Arg);
3458 else
3459 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3460 Ext_Nam := Expression (Ext_Arg);
3461 Link_Nam := Empty;
3462 end if;
3464 else
3465 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3466 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
3467 Ext_Nam := Expression (Ext_Arg);
3468 Link_Nam := Expression (Link_Arg);
3469 end if;
3471 -- Check expressions for external name and link name are static
3473 if Present (Ext_Nam) then
3474 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
3475 Check_Form_Of_Interface_Name (Ext_Nam);
3477 -- Verify that the external name is not the name of a local
3478 -- entity, which would hide the imported one and lead to
3479 -- run-time surprises. The problem can only arise for entities
3480 -- declared in a package body (otherwise the external name is
3481 -- fully qualified and won't conflict).
3483 declare
3484 Nam : Name_Id;
3485 E : Entity_Id;
3486 Par : Node_Id;
3488 begin
3489 if Prag_Id = Pragma_Import then
3490 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
3491 Nam := Name_Find;
3492 E := Entity_Id (Get_Name_Table_Info (Nam));
3494 if Nam /= Chars (Subprogram_Def)
3495 and then Present (E)
3496 and then not Is_Overloadable (E)
3497 and then Is_Immediately_Visible (E)
3498 and then not Is_Imported (E)
3499 and then Ekind (Scope (E)) = E_Package
3500 then
3501 Par := Parent (E);
3503 while Present (Par) loop
3504 if Nkind (Par) = N_Package_Body then
3505 Error_Msg_Sloc := Sloc (E);
3506 Error_Msg_NE
3507 ("imported entity is hidden by & declared#",
3508 Ext_Arg, E);
3509 exit;
3510 end if;
3512 Par := Parent (Par);
3513 end loop;
3514 end if;
3515 end if;
3516 end;
3517 end if;
3519 if Present (Link_Nam) then
3520 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
3521 Check_Form_Of_Interface_Name (Link_Nam);
3522 end if;
3524 -- If there is no link name, just set the external name
3526 if No (Link_Nam) then
3527 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
3529 -- For the Link_Name case, the given literal is preceded by an
3530 -- asterisk, which indicates to GCC that the given name should
3531 -- be taken literally, and in particular that no prepending of
3532 -- underlines should occur, even in systems where this is the
3533 -- normal default.
3535 else
3536 Start_String;
3537 Store_String_Char (Get_Char_Code ('*'));
3538 String_Val := Strval (Expr_Value_S (Link_Nam));
3540 for J in 1 .. String_Length (String_Val) loop
3541 Store_String_Char (Get_String_Char (String_Val, J));
3542 end loop;
3544 Link_Nam :=
3545 Make_String_Literal (Sloc (Link_Nam), End_String);
3546 end if;
3548 Set_Encoded_Interface_Name
3549 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
3550 Check_Duplicated_Export_Name (Link_Nam);
3551 end Process_Interface_Name;
3553 -----------------------------------------
3554 -- Process_Interrupt_Or_Attach_Handler --
3555 -----------------------------------------
3557 procedure Process_Interrupt_Or_Attach_Handler is
3558 Arg1_X : constant Node_Id := Expression (Arg1);
3559 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
3560 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
3562 begin
3563 Set_Is_Interrupt_Handler (Handler_Proc);
3565 -- If the pragma is not associated with a handler procedure
3566 -- within a protected type, then it must be for a nonprotected
3567 -- procedure for the AAMP target, in which case we don't
3568 -- associate a representation item with the procedure's scope.
3570 if Ekind (Proc_Scope) = E_Protected_Type then
3571 if Prag_Id = Pragma_Interrupt_Handler
3572 or else
3573 Prag_Id = Pragma_Attach_Handler
3574 then
3575 Record_Rep_Item (Proc_Scope, N);
3576 end if;
3577 end if;
3578 end Process_Interrupt_Or_Attach_Handler;
3580 --------------------------------------------------
3581 -- Process_Restrictions_Or_Restriction_Warnings --
3582 --------------------------------------------------
3584 -- Note: some of the simple identifier cases were handled in par-prag,
3585 -- but it is harmless (and more straightforward) to simply handle all
3586 -- cases here, even if it means we repeat a bit of work in some cases.
3588 procedure Process_Restrictions_Or_Restriction_Warnings is
3589 Arg : Node_Id;
3590 R_Id : Restriction_Id;
3591 Id : Name_Id;
3592 Expr : Node_Id;
3593 Val : Uint;
3595 procedure Check_Unit_Name (N : Node_Id);
3596 -- Checks unit name parameter for No_Dependence. Returns if it has
3597 -- an appropriate form, otherwise raises pragma argument error.
3599 procedure Set_Warning (R : All_Restrictions);
3600 -- If this is a Restriction_Warnings pragma, set warning flag,
3601 -- otherwise reset the flag.
3603 ---------------------
3604 -- Check_Unit_Name --
3605 ---------------------
3607 procedure Check_Unit_Name (N : Node_Id) is
3608 begin
3609 if Nkind (N) = N_Selected_Component then
3610 Check_Unit_Name (Prefix (N));
3611 Check_Unit_Name (Selector_Name (N));
3613 elsif Nkind (N) = N_Identifier then
3614 return;
3616 else
3617 Error_Pragma_Arg
3618 ("wrong form for unit name for No_Dependence", N);
3619 end if;
3620 end Check_Unit_Name;
3622 -----------------
3623 -- Set_Warning --
3624 -----------------
3626 procedure Set_Warning (R : All_Restrictions) is
3627 begin
3628 if Prag_Id = Pragma_Restriction_Warnings then
3629 Restriction_Warnings (R) := True;
3630 else
3631 Restriction_Warnings (R) := False;
3632 end if;
3633 end Set_Warning;
3635 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
3637 begin
3638 Check_Ada_83_Warning;
3639 Check_At_Least_N_Arguments (1);
3640 Check_Valid_Configuration_Pragma;
3642 Arg := Arg1;
3643 while Present (Arg) loop
3644 Id := Chars (Arg);
3645 Expr := Expression (Arg);
3647 -- Case of no restriction identifier present
3649 if Id = No_Name then
3650 if Nkind (Expr) /= N_Identifier then
3651 Error_Pragma_Arg
3652 ("invalid form for restriction", Arg);
3653 end if;
3655 R_Id :=
3656 Get_Restriction_Id
3657 (Process_Restriction_Synonyms (Expr));
3659 if R_Id not in All_Boolean_Restrictions then
3660 Error_Pragma_Arg
3661 ("invalid restriction identifier", Arg);
3662 end if;
3664 if Implementation_Restriction (R_Id) then
3665 Check_Restriction
3666 (No_Implementation_Restrictions, Arg);
3667 end if;
3669 Set_Restriction (R_Id, N);
3670 Set_Warning (R_Id);
3672 -- A very special case that must be processed here:
3673 -- pragma Restrictions (No_Exceptions) turns off
3674 -- all run-time checking. This is a bit dubious in
3675 -- terms of the formal language definition, but it
3676 -- is what is intended by RM H.4(12).
3678 if R_Id = No_Exceptions then
3679 Scope_Suppress := (others => True);
3680 end if;
3682 -- Case of No_Dependence => unit-name. Note that the parser
3683 -- already made the necessary entry in the No_Dependence table.
3685 elsif Id = Name_No_Dependence then
3686 Check_Unit_Name (Expr);
3688 -- All other cases of restriction identifier present
3690 else
3691 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
3692 Analyze_And_Resolve (Expr, Any_Integer);
3694 if R_Id not in All_Parameter_Restrictions then
3695 Error_Pragma_Arg
3696 ("invalid restriction parameter identifier", Arg);
3698 elsif not Is_OK_Static_Expression (Expr) then
3699 Flag_Non_Static_Expr
3700 ("value must be static expression!", Expr);
3701 raise Pragma_Exit;
3703 elsif not Is_Integer_Type (Etype (Expr))
3704 or else Expr_Value (Expr) < 0
3705 then
3706 Error_Pragma_Arg
3707 ("value must be non-negative integer", Arg);
3709 -- Restriction pragma is active
3711 else
3712 Val := Expr_Value (Expr);
3714 if not UI_Is_In_Int_Range (Val) then
3715 Error_Pragma_Arg
3716 ("pragma ignored, value too large?", Arg);
3717 else
3718 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
3719 Set_Warning (R_Id);
3720 end if;
3721 end if;
3722 end if;
3724 Next (Arg);
3725 end loop;
3726 end Process_Restrictions_Or_Restriction_Warnings;
3728 ---------------------------------
3729 -- Process_Suppress_Unsuppress --
3730 ---------------------------------
3732 -- Note: this procedure makes entries in the check suppress data
3733 -- structures managed by Sem. See spec of package Sem for full
3734 -- details on how we handle recording of check suppression.
3736 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
3737 C : Check_Id;
3738 E_Id : Node_Id;
3739 E : Entity_Id;
3741 In_Package_Spec : constant Boolean :=
3742 (Ekind (Current_Scope) = E_Package
3743 or else
3744 Ekind (Current_Scope) = E_Generic_Package)
3745 and then not In_Package_Body (Current_Scope);
3747 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
3748 -- Used to suppress a single check on the given entity
3750 --------------------------------
3751 -- Suppress_Unsuppress_Echeck --
3752 --------------------------------
3754 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
3755 ESR : constant Entity_Check_Suppress_Record :=
3756 (Entity => E,
3757 Check => C,
3758 Suppress => Suppress_Case);
3760 begin
3761 Set_Checks_May_Be_Suppressed (E);
3763 if In_Package_Spec then
3764 Global_Entity_Suppress.Append (ESR);
3765 else
3766 Local_Entity_Suppress.Append (ESR);
3767 end if;
3769 -- If this is a first subtype, and the base type is distinct,
3770 -- then also set the suppress flags on the base type.
3772 if Is_First_Subtype (E)
3773 and then Etype (E) /= E
3774 then
3775 Suppress_Unsuppress_Echeck (Etype (E), C);
3776 end if;
3777 end Suppress_Unsuppress_Echeck;
3779 -- Start of processing for Process_Suppress_Unsuppress
3781 begin
3782 -- Suppress/Unsuppress can appear as a configuration pragma,
3783 -- or in a declarative part or a package spec (RM 11.5(5))
3785 if not Is_Configuration_Pragma then
3786 Check_Is_In_Decl_Part_Or_Package_Spec;
3787 end if;
3789 Check_At_Least_N_Arguments (1);
3790 Check_At_Most_N_Arguments (2);
3791 Check_No_Identifier (Arg1);
3792 Check_Arg_Is_Identifier (Arg1);
3794 if not Is_Check_Name (Chars (Expression (Arg1))) then
3795 Error_Pragma_Arg
3796 ("argument of pragma% is not valid check name", Arg1);
3797 else
3798 C := Get_Check_Id (Chars (Expression (Arg1)));
3799 end if;
3801 if Arg_Count = 1 then
3803 -- Make an entry in the local scope suppress table. This is the
3804 -- table that directly shows the current value of the scope
3805 -- suppress check for any check id value.
3807 if C = All_Checks then
3809 -- For All_Checks, we set all specific checks with the
3810 -- exception of Elaboration_Check, which is handled specially
3811 -- because of not wanting All_Checks to have the effect of
3812 -- deactivating static elaboration order processing.
3814 for J in Scope_Suppress'Range loop
3815 if J /= Elaboration_Check then
3816 Scope_Suppress (J) := Suppress_Case;
3817 end if;
3818 end loop;
3820 -- If not All_Checks, just set appropriate entry. Note that we
3821 -- will set Elaboration_Check if this is explicitly specified.
3823 else
3824 Scope_Suppress (C) := Suppress_Case;
3825 end if;
3827 -- Also make an entry in the Local_Entity_Suppress table. See
3828 -- extended description in the package spec of Sem for details.
3830 Local_Entity_Suppress.Append
3831 ((Entity => Empty,
3832 Check => C,
3833 Suppress => Suppress_Case));
3835 -- Case of two arguments present, where the check is
3836 -- suppressed for a specified entity (given as the second
3837 -- argument of the pragma)
3839 else
3840 Check_Optional_Identifier (Arg2, Name_On);
3841 E_Id := Expression (Arg2);
3842 Analyze (E_Id);
3844 if not Is_Entity_Name (E_Id) then
3845 Error_Pragma_Arg
3846 ("second argument of pragma% must be entity name", Arg2);
3847 end if;
3849 E := Entity (E_Id);
3851 if E = Any_Id then
3852 return;
3853 end if;
3855 -- Enforce RM 11.5(7) which requires that for a pragma that
3856 -- appears within a package spec, the named entity must be
3857 -- within the package spec. We allow the package name itself
3858 -- to be mentioned since that makes sense, although it is not
3859 -- strictly allowed by 11.5(7).
3861 if In_Package_Spec
3862 and then E /= Current_Scope
3863 and then Scope (E) /= Current_Scope
3864 then
3865 Error_Pragma_Arg
3866 ("entity in pragma% is not in package spec ('R'M 11.5(7))",
3867 Arg2);
3868 end if;
3870 -- Loop through homonyms. As noted below, in the case of a package
3871 -- spec, only homonyms within the package spec are considered.
3873 loop
3874 Suppress_Unsuppress_Echeck (E, C);
3876 if Is_Generic_Instance (E)
3877 and then Is_Subprogram (E)
3878 and then Present (Alias (E))
3879 then
3880 Suppress_Unsuppress_Echeck (Alias (E), C);
3881 end if;
3883 -- Move to next homonym
3885 E := Homonym (E);
3886 exit when No (E);
3888 -- If we are within a package specification, the
3889 -- pragma only applies to homonyms in the same scope.
3891 exit when In_Package_Spec
3892 and then Scope (E) /= Current_Scope;
3893 end loop;
3894 end if;
3895 end Process_Suppress_Unsuppress;
3897 ------------------
3898 -- Set_Exported --
3899 ------------------
3901 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
3902 begin
3903 if Is_Imported (E) then
3904 Error_Pragma_Arg
3905 ("cannot export entity& that was previously imported", Arg);
3907 elsif Present (Address_Clause (E)) then
3908 Error_Pragma_Arg
3909 ("cannot export entity& that has an address clause", Arg);
3910 end if;
3912 Set_Is_Exported (E);
3914 -- Generate a reference for entity explicitly, because the
3915 -- identifier may be overloaded and name resolution will not
3916 -- generate one.
3918 Generate_Reference (E, Arg);
3920 -- Deal with exporting non-library level entity
3922 if not Is_Library_Level_Entity (E) then
3924 -- Not allowed at all for subprograms
3926 if Is_Subprogram (E) then
3927 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
3929 -- Otherwise set public and statically allocated
3931 else
3932 Set_Is_Public (E);
3933 Set_Is_Statically_Allocated (E);
3935 -- Warn if the corresponding W flag is set and the pragma
3936 -- comes from source. The latter may not be true e.g. on
3937 -- VMS where we expand export pragmas for exception codes
3938 -- associated with imported or exported exceptions. We do
3939 -- not want to generate a warning for something that the
3940 -- user did not write.
3942 if Warn_On_Export_Import
3943 and then Comes_From_Source (Arg)
3944 then
3945 Error_Msg_NE
3946 ("?& has been made static as a result of Export", Arg, E);
3947 Error_Msg_N
3948 ("\this usage is non-standard and non-portable", Arg);
3949 end if;
3950 end if;
3951 end if;
3953 if Warn_On_Export_Import and then Is_Type (E) then
3954 Error_Msg_NE
3955 ("exporting a type has no effect?", Arg, E);
3956 end if;
3958 if Warn_On_Export_Import and Inside_A_Generic then
3959 Error_Msg_NE
3960 ("all instances of& will have the same external name?", Arg, E);
3961 end if;
3962 end Set_Exported;
3964 ----------------------------------------------
3965 -- Set_Extended_Import_Export_External_Name --
3966 ----------------------------------------------
3968 procedure Set_Extended_Import_Export_External_Name
3969 (Internal_Ent : Entity_Id;
3970 Arg_External : Node_Id)
3972 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
3973 New_Name : Node_Id;
3975 begin
3976 if No (Arg_External) then
3977 return;
3978 end if;
3980 Check_Arg_Is_External_Name (Arg_External);
3982 if Nkind (Arg_External) = N_String_Literal then
3983 if String_Length (Strval (Arg_External)) = 0 then
3984 return;
3985 else
3986 New_Name := Adjust_External_Name_Case (Arg_External);
3987 end if;
3989 elsif Nkind (Arg_External) = N_Identifier then
3990 New_Name := Get_Default_External_Name (Arg_External);
3992 -- Check_Arg_Is_External_Name should let through only
3993 -- identifiers and string literals or static string
3994 -- expressions (which are folded to string literals).
3996 else
3997 raise Program_Error;
3998 end if;
4000 -- If we already have an external name set (by a prior normal
4001 -- Import or Export pragma), then the external names must match
4003 if Present (Interface_Name (Internal_Ent)) then
4004 Check_Matching_Internal_Names : declare
4005 S1 : constant String_Id := Strval (Old_Name);
4006 S2 : constant String_Id := Strval (New_Name);
4008 procedure Mismatch;
4009 -- Called if names do not match
4011 --------------
4012 -- Mismatch --
4013 --------------
4015 procedure Mismatch is
4016 begin
4017 Error_Msg_Sloc := Sloc (Old_Name);
4018 Error_Pragma_Arg
4019 ("external name does not match that given #",
4020 Arg_External);
4021 end Mismatch;
4023 -- Start of processing for Check_Matching_Internal_Names
4025 begin
4026 if String_Length (S1) /= String_Length (S2) then
4027 Mismatch;
4029 else
4030 for J in 1 .. String_Length (S1) loop
4031 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4032 Mismatch;
4033 end if;
4034 end loop;
4035 end if;
4036 end Check_Matching_Internal_Names;
4038 -- Otherwise set the given name
4040 else
4041 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4042 Check_Duplicated_Export_Name (New_Name);
4043 end if;
4044 end Set_Extended_Import_Export_External_Name;
4046 ------------------
4047 -- Set_Imported --
4048 ------------------
4050 procedure Set_Imported (E : Entity_Id) is
4051 begin
4052 Error_Msg_Sloc := Sloc (E);
4054 if Is_Exported (E) or else Is_Imported (E) then
4055 Error_Msg_NE ("import of& declared# not allowed", N, E);
4057 if Is_Exported (E) then
4058 Error_Msg_N ("\entity was previously exported", N);
4059 else
4060 Error_Msg_N ("\entity was previously imported", N);
4061 end if;
4063 Error_Pragma ("\(pragma% applies to all previous entities)");
4065 else
4066 Set_Is_Imported (E);
4068 -- If the entity is an object that is not at the library
4069 -- level, then it is statically allocated. We do not worry
4070 -- about objects with address clauses in this context since
4071 -- they are not really imported in the linker sense.
4073 if Is_Object (E)
4074 and then not Is_Library_Level_Entity (E)
4075 and then No (Address_Clause (E))
4076 then
4077 Set_Is_Statically_Allocated (E);
4078 end if;
4079 end if;
4080 end Set_Imported;
4082 -------------------------
4083 -- Set_Mechanism_Value --
4084 -------------------------
4086 -- Note: the mechanism name has not been analyzed (and cannot indeed
4087 -- be analyzed, since it is semantic nonsense), so we get it in the
4088 -- exact form created by the parser.
4090 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4091 Class : Node_Id;
4092 Param : Node_Id;
4094 procedure Bad_Class;
4095 -- Signal bad descriptor class name
4097 procedure Bad_Mechanism;
4098 -- Signal bad mechanism name
4100 ---------------
4101 -- Bad_Class --
4102 ---------------
4104 procedure Bad_Class is
4105 begin
4106 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4107 end Bad_Class;
4109 -------------------------
4110 -- Bad_Mechanism_Value --
4111 -------------------------
4113 procedure Bad_Mechanism is
4114 begin
4115 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4116 end Bad_Mechanism;
4118 -- Start of processing for Set_Mechanism_Value
4120 begin
4121 if Mechanism (Ent) /= Default_Mechanism then
4122 Error_Msg_NE
4123 ("mechanism for & has already been set", Mech_Name, Ent);
4124 end if;
4126 -- MECHANISM_NAME ::= value | reference | descriptor
4128 if Nkind (Mech_Name) = N_Identifier then
4129 if Chars (Mech_Name) = Name_Value then
4130 Set_Mechanism (Ent, By_Copy);
4131 return;
4133 elsif Chars (Mech_Name) = Name_Reference then
4134 Set_Mechanism (Ent, By_Reference);
4135 return;
4137 elsif Chars (Mech_Name) = Name_Descriptor then
4138 Check_VMS (Mech_Name);
4139 Set_Mechanism (Ent, By_Descriptor);
4140 return;
4142 elsif Chars (Mech_Name) = Name_Copy then
4143 Error_Pragma_Arg
4144 ("bad mechanism name, Value assumed", Mech_Name);
4146 else
4147 Bad_Mechanism;
4148 end if;
4150 -- MECHANISM_NAME ::= descriptor (CLASS_NAME)
4151 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4153 -- Note: this form is parsed as an indexed component
4155 elsif Nkind (Mech_Name) = N_Indexed_Component then
4156 Class := First (Expressions (Mech_Name));
4158 if Nkind (Prefix (Mech_Name)) /= N_Identifier
4159 or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
4160 or else Present (Next (Class))
4161 then
4162 Bad_Mechanism;
4163 end if;
4165 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
4166 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4168 -- Note: this form is parsed as a function call
4170 elsif Nkind (Mech_Name) = N_Function_Call then
4172 Param := First (Parameter_Associations (Mech_Name));
4174 if Nkind (Name (Mech_Name)) /= N_Identifier
4175 or else Chars (Name (Mech_Name)) /= Name_Descriptor
4176 or else Present (Next (Param))
4177 or else No (Selector_Name (Param))
4178 or else Chars (Selector_Name (Param)) /= Name_Class
4179 then
4180 Bad_Mechanism;
4181 else
4182 Class := Explicit_Actual_Parameter (Param);
4183 end if;
4185 else
4186 Bad_Mechanism;
4187 end if;
4189 -- Fall through here with Class set to descriptor class name
4191 Check_VMS (Mech_Name);
4193 if Nkind (Class) /= N_Identifier then
4194 Bad_Class;
4196 elsif Chars (Class) = Name_UBS then
4197 Set_Mechanism (Ent, By_Descriptor_UBS);
4199 elsif Chars (Class) = Name_UBSB then
4200 Set_Mechanism (Ent, By_Descriptor_UBSB);
4202 elsif Chars (Class) = Name_UBA then
4203 Set_Mechanism (Ent, By_Descriptor_UBA);
4205 elsif Chars (Class) = Name_S then
4206 Set_Mechanism (Ent, By_Descriptor_S);
4208 elsif Chars (Class) = Name_SB then
4209 Set_Mechanism (Ent, By_Descriptor_SB);
4211 elsif Chars (Class) = Name_A then
4212 Set_Mechanism (Ent, By_Descriptor_A);
4214 elsif Chars (Class) = Name_NCA then
4215 Set_Mechanism (Ent, By_Descriptor_NCA);
4217 else
4218 Bad_Class;
4219 end if;
4220 end Set_Mechanism_Value;
4222 ---------------------------
4223 -- Set_Ravenscar_Profile --
4224 ---------------------------
4226 -- The tasks to be done here are
4228 -- Set required policies
4230 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4231 -- pragma Locking_Policy (Ceiling_Locking)
4233 -- Set Detect_Blocking mode
4235 -- Set required restrictions (see System.Rident for detailed list)
4237 procedure Set_Ravenscar_Profile (N : Node_Id) is
4238 begin
4239 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4241 if Task_Dispatching_Policy /= ' '
4242 and then Task_Dispatching_Policy /= 'F'
4243 then
4244 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4245 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4247 -- Set the FIFO_Within_Priorities policy, but always preserve
4248 -- System_Location since we like the error message with the run time
4249 -- name.
4251 else
4252 Task_Dispatching_Policy := 'F';
4254 if Task_Dispatching_Policy_Sloc /= System_Location then
4255 Task_Dispatching_Policy_Sloc := Loc;
4256 end if;
4257 end if;
4259 -- pragma Locking_Policy (Ceiling_Locking)
4261 if Locking_Policy /= ' '
4262 and then Locking_Policy /= 'C'
4263 then
4264 Error_Msg_Sloc := Locking_Policy_Sloc;
4265 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4267 -- Set the Ceiling_Locking policy, but preserve System_Location since
4268 -- we like the error message with the run time name.
4270 else
4271 Locking_Policy := 'C';
4273 if Locking_Policy_Sloc /= System_Location then
4274 Locking_Policy_Sloc := Loc;
4275 end if;
4276 end if;
4278 -- pragma Detect_Blocking
4280 Detect_Blocking := True;
4282 -- Set the corresponding restrictions
4284 Set_Profile_Restrictions (Ravenscar, N, Warn => False);
4285 end Set_Ravenscar_Profile;
4287 -- Start of processing for Analyze_Pragma
4289 begin
4290 if not Is_Pragma_Name (Chars (N)) then
4291 if Warn_On_Unrecognized_Pragma then
4292 Error_Pragma ("unrecognized pragma%?");
4293 else
4294 return;
4295 end if;
4296 else
4297 Prag_Id := Get_Pragma_Id (Chars (N));
4298 end if;
4300 -- Preset arguments
4302 Arg1 := Empty;
4303 Arg2 := Empty;
4304 Arg3 := Empty;
4305 Arg4 := Empty;
4307 if Present (Pragma_Argument_Associations (N)) then
4308 Arg1 := First (Pragma_Argument_Associations (N));
4310 if Present (Arg1) then
4311 Arg2 := Next (Arg1);
4313 if Present (Arg2) then
4314 Arg3 := Next (Arg2);
4316 if Present (Arg3) then
4317 Arg4 := Next (Arg3);
4318 end if;
4319 end if;
4320 end if;
4321 end if;
4323 -- Count number of arguments
4325 declare
4326 Arg_Node : Node_Id;
4327 begin
4328 Arg_Count := 0;
4329 Arg_Node := Arg1;
4330 while Present (Arg_Node) loop
4331 Arg_Count := Arg_Count + 1;
4332 Next (Arg_Node);
4333 end loop;
4334 end;
4336 -- An enumeration type defines the pragmas that are supported by the
4337 -- implementation. Get_Pragma_Id (in package Prag) transorms a name
4338 -- into the corresponding enumeration value for the following case.
4340 case Prag_Id is
4342 -----------------
4343 -- Abort_Defer --
4344 -----------------
4346 -- pragma Abort_Defer;
4348 when Pragma_Abort_Defer =>
4349 GNAT_Pragma;
4350 Check_Arg_Count (0);
4352 -- The only required semantic processing is to check the
4353 -- placement. This pragma must appear at the start of the
4354 -- statement sequence of a handled sequence of statements.
4356 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
4357 or else N /= First (Statements (Parent (N)))
4358 then
4359 Pragma_Misplaced;
4360 end if;
4362 ------------
4363 -- Ada_83 --
4364 ------------
4366 -- pragma Ada_83;
4368 -- Note: this pragma also has some specific processing in Par.Prag
4369 -- because we want to set the Ada version mode during parsing.
4371 when Pragma_Ada_83 =>
4372 GNAT_Pragma;
4373 Ada_Version := Ada_83;
4374 Ada_Version_Explicit := Ada_Version;
4375 Check_Arg_Count (0);
4377 ------------
4378 -- Ada_95 --
4379 ------------
4381 -- pragma Ada_95;
4383 -- Note: this pragma also has some specific processing in Par.Prag
4384 -- because we want to set the Ada 83 version mode during parsing.
4386 when Pragma_Ada_95 =>
4387 GNAT_Pragma;
4388 Ada_Version := Ada_95;
4389 Ada_Version_Explicit := Ada_Version;
4390 Check_Arg_Count (0);
4392 ---------------------
4393 -- Ada_05/Ada_2005 --
4394 ---------------------
4396 -- pragma Ada_05;
4397 -- pragma Ada_05 (LOCAL_NAME);
4399 -- pragma Ada_2005;
4400 -- pragma Ada_2005 (LOCAL_NAME):
4402 -- Note: these pragma also have some specific processing in Par.Prag
4403 -- because we want to set the Ada 2005 version mode during parsing.
4405 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
4406 E_Id : Node_Id;
4408 begin
4409 GNAT_Pragma;
4411 if Arg_Count = 1 then
4412 Check_Arg_Is_Local_Name (Arg1);
4413 E_Id := Expression (Arg1);
4415 if Etype (E_Id) = Any_Type then
4416 return;
4417 end if;
4419 Set_Is_Ada_2005 (Entity (E_Id));
4421 else
4422 Check_Arg_Count (0);
4423 Ada_Version := Ada_05;
4424 Ada_Version_Explicit := Ada_05;
4425 end if;
4426 end;
4428 ----------------------
4429 -- All_Calls_Remote --
4430 ----------------------
4432 -- pragma All_Calls_Remote [(library_package_NAME)];
4434 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
4435 Lib_Entity : Entity_Id;
4437 begin
4438 Check_Ada_83_Warning;
4439 Check_Valid_Library_Unit_Pragma;
4441 if Nkind (N) = N_Null_Statement then
4442 return;
4443 end if;
4445 Lib_Entity := Find_Lib_Unit_Name;
4447 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
4449 if Present (Lib_Entity)
4450 and then not Debug_Flag_U
4451 then
4452 if not Is_Remote_Call_Interface (Lib_Entity) then
4453 Error_Pragma ("pragma% only apply to rci unit");
4455 -- Set flag for entity of the library unit
4457 else
4458 Set_Has_All_Calls_Remote (Lib_Entity);
4459 end if;
4461 end if;
4462 end All_Calls_Remote;
4464 --------------
4465 -- Annotate --
4466 --------------
4468 -- pragma Annotate (IDENTIFIER {, ARG});
4469 -- ARG ::= NAME | EXPRESSION
4471 when Pragma_Annotate => Annotate : begin
4472 GNAT_Pragma;
4473 Check_At_Least_N_Arguments (1);
4474 Check_Arg_Is_Identifier (Arg1);
4476 declare
4477 Arg : Node_Id := Arg2;
4478 Exp : Node_Id;
4480 begin
4481 while Present (Arg) loop
4482 Exp := Expression (Arg);
4483 Analyze (Exp);
4485 if Is_Entity_Name (Exp) then
4486 null;
4488 elsif Nkind (Exp) = N_String_Literal then
4489 Resolve (Exp, Standard_String);
4491 elsif Is_Overloaded (Exp) then
4492 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
4494 else
4495 Resolve (Exp);
4496 end if;
4498 Next (Arg);
4499 end loop;
4500 end;
4501 end Annotate;
4503 ------------
4504 -- Assert --
4505 ------------
4507 -- pragma Assert ([Check =>] Boolean_EXPRESSION
4508 -- [, [Message =>] Static_String_EXPRESSION]);
4510 when Pragma_Assert =>
4511 Check_At_Least_N_Arguments (1);
4512 Check_At_Most_N_Arguments (2);
4513 Check_Arg_Order ((Name_Check, Name_Message));
4514 Check_Optional_Identifier (Arg1, Name_Check);
4516 if Arg_Count > 1 then
4517 Check_Optional_Identifier (Arg2, Name_Message);
4518 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4519 end if;
4521 -- If expansion is active and assertions are inactive, then
4522 -- we rewrite the Assertion as:
4524 -- if False and then condition then
4525 -- null;
4526 -- end if;
4528 -- The reason we do this rewriting during semantic analysis
4529 -- rather than as part of normal expansion is that we cannot
4530 -- analyze and expand the code for the boolean expression
4531 -- directly, or it may cause insertion of actions that would
4532 -- escape the attempt to suppress the assertion code.
4534 if Expander_Active and not Assertions_Enabled then
4535 Rewrite (N,
4536 Make_If_Statement (Loc,
4537 Condition =>
4538 Make_And_Then (Loc,
4539 Left_Opnd => New_Occurrence_Of (Standard_False, Loc),
4540 Right_Opnd => Get_Pragma_Arg (Arg1)),
4541 Then_Statements => New_List (
4542 Make_Null_Statement (Loc))));
4544 Analyze (N);
4546 -- Otherwise (if assertions are enabled, or if we are not
4547 -- operating with expansion active), then we just analyze
4548 -- and resolve the expression.
4550 else
4551 Analyze_And_Resolve (Expression (Arg1), Any_Boolean);
4552 end if;
4554 ----------------------
4555 -- Assertion_Policy --
4556 ----------------------
4558 -- pragma Assertion_Policy (Check | Ignore)
4560 when Pragma_Assertion_Policy =>
4561 Check_Arg_Count (1);
4562 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
4563 Assertions_Enabled := Chars (Expression (Arg1)) = Name_Check;
4565 ---------------
4566 -- AST_Entry --
4567 ---------------
4569 -- pragma AST_Entry (entry_IDENTIFIER);
4571 when Pragma_AST_Entry => AST_Entry : declare
4572 Ent : Node_Id;
4574 begin
4575 GNAT_Pragma;
4576 Check_VMS (N);
4577 Check_Arg_Count (1);
4578 Check_No_Identifiers;
4579 Check_Arg_Is_Local_Name (Arg1);
4580 Ent := Entity (Expression (Arg1));
4582 -- Note: the implementation of the AST_Entry pragma could handle
4583 -- the entry family case fine, but for now we are consistent with
4584 -- the DEC rules, and do not allow the pragma, which of course
4585 -- has the effect of also forbidding the attribute.
4587 if Ekind (Ent) /= E_Entry then
4588 Error_Pragma_Arg
4589 ("pragma% argument must be simple entry name", Arg1);
4591 elsif Is_AST_Entry (Ent) then
4592 Error_Pragma_Arg
4593 ("duplicate % pragma for entry", Arg1);
4595 elsif Has_Homonym (Ent) then
4596 Error_Pragma_Arg
4597 ("pragma% argument cannot specify overloaded entry", Arg1);
4599 else
4600 declare
4601 FF : constant Entity_Id := First_Formal (Ent);
4603 begin
4604 if Present (FF) then
4605 if Present (Next_Formal (FF)) then
4606 Error_Pragma_Arg
4607 ("entry for pragma% can have only one argument",
4608 Arg1);
4610 elsif Parameter_Mode (FF) /= E_In_Parameter then
4611 Error_Pragma_Arg
4612 ("entry parameter for pragma% must have mode IN",
4613 Arg1);
4614 end if;
4615 end if;
4616 end;
4618 Set_Is_AST_Entry (Ent);
4619 end if;
4620 end AST_Entry;
4622 ------------------
4623 -- Asynchronous --
4624 ------------------
4626 -- pragma Asynchronous (LOCAL_NAME);
4628 when Pragma_Asynchronous => Asynchronous : declare
4629 Nm : Entity_Id;
4630 C_Ent : Entity_Id;
4631 L : List_Id;
4632 S : Node_Id;
4633 N : Node_Id;
4634 Formal : Entity_Id;
4636 procedure Process_Async_Pragma;
4637 -- Common processing for procedure and access-to-procedure case
4639 --------------------------
4640 -- Process_Async_Pragma --
4641 --------------------------
4643 procedure Process_Async_Pragma is
4644 begin
4645 if No (L) then
4646 Set_Is_Asynchronous (Nm);
4647 return;
4648 end if;
4650 -- The formals should be of mode IN (RM E.4.1(6))
4652 S := First (L);
4653 while Present (S) loop
4654 Formal := Defining_Identifier (S);
4656 if Nkind (Formal) = N_Defining_Identifier
4657 and then Ekind (Formal) /= E_In_Parameter
4658 then
4659 Error_Pragma_Arg
4660 ("pragma% procedure can only have IN parameter",
4661 Arg1);
4662 end if;
4664 Next (S);
4665 end loop;
4667 Set_Is_Asynchronous (Nm);
4668 end Process_Async_Pragma;
4670 -- Start of processing for pragma Asynchronous
4672 begin
4673 Check_Ada_83_Warning;
4674 Check_No_Identifiers;
4675 Check_Arg_Count (1);
4676 Check_Arg_Is_Local_Name (Arg1);
4678 if Debug_Flag_U then
4679 return;
4680 end if;
4682 C_Ent := Cunit_Entity (Current_Sem_Unit);
4683 Analyze (Expression (Arg1));
4684 Nm := Entity (Expression (Arg1));
4686 if not Is_Remote_Call_Interface (C_Ent)
4687 and then not Is_Remote_Types (C_Ent)
4688 then
4689 -- This pragma should only appear in an RCI or Remote Types
4690 -- unit (RM E.4.1(4))
4692 Error_Pragma
4693 ("pragma% not in Remote_Call_Interface or " &
4694 "Remote_Types unit");
4695 end if;
4697 if Ekind (Nm) = E_Procedure
4698 and then Nkind (Parent (Nm)) = N_Procedure_Specification
4699 then
4700 if not Is_Remote_Call_Interface (Nm) then
4701 Error_Pragma_Arg
4702 ("pragma% cannot be applied on non-remote procedure",
4703 Arg1);
4704 end if;
4706 L := Parameter_Specifications (Parent (Nm));
4707 Process_Async_Pragma;
4708 return;
4710 elsif Ekind (Nm) = E_Function then
4711 Error_Pragma_Arg
4712 ("pragma% cannot be applied to function", Arg1);
4714 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
4716 if Is_Record_Type (Nm) then
4717 -- A record type that is the Equivalent_Type for
4718 -- a remote access-to-subprogram type.
4720 N := Declaration_Node (Corresponding_Remote_Type (Nm));
4722 else
4723 -- A non-expanded RAS type (case where distribution is
4724 -- not enabled).
4726 N := Declaration_Node (Nm);
4727 end if;
4729 if Nkind (N) = N_Full_Type_Declaration
4730 and then Nkind (Type_Definition (N)) =
4731 N_Access_Procedure_Definition
4732 then
4733 L := Parameter_Specifications (Type_Definition (N));
4734 Process_Async_Pragma;
4736 if Is_Asynchronous (Nm)
4737 and then Expander_Active
4738 and then Get_PCS_Name /= Name_No_DSA
4739 then
4740 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
4741 end if;
4743 else
4744 Error_Pragma_Arg
4745 ("pragma% cannot reference access-to-function type",
4746 Arg1);
4747 end if;
4749 -- Only other possibility is Access-to-class-wide type
4751 elsif Is_Access_Type (Nm)
4752 and then Is_Class_Wide_Type (Designated_Type (Nm))
4753 then
4754 Check_First_Subtype (Arg1);
4755 Set_Is_Asynchronous (Nm);
4756 if Expander_Active then
4757 RACW_Type_Is_Asynchronous (Nm);
4758 end if;
4760 else
4761 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
4762 end if;
4763 end Asynchronous;
4765 ------------
4766 -- Atomic --
4767 ------------
4769 -- pragma Atomic (LOCAL_NAME);
4771 when Pragma_Atomic =>
4772 Process_Atomic_Shared_Volatile;
4774 -----------------------
4775 -- Atomic_Components --
4776 -----------------------
4778 -- pragma Atomic_Components (array_LOCAL_NAME);
4780 -- This processing is shared by Volatile_Components
4782 when Pragma_Atomic_Components |
4783 Pragma_Volatile_Components =>
4785 Atomic_Components : declare
4786 E_Id : Node_Id;
4787 E : Entity_Id;
4788 D : Node_Id;
4789 K : Node_Kind;
4791 begin
4792 Check_Ada_83_Warning;
4793 Check_No_Identifiers;
4794 Check_Arg_Count (1);
4795 Check_Arg_Is_Local_Name (Arg1);
4796 E_Id := Expression (Arg1);
4798 if Etype (E_Id) = Any_Type then
4799 return;
4800 end if;
4802 E := Entity (E_Id);
4804 if Rep_Item_Too_Early (E, N)
4805 or else
4806 Rep_Item_Too_Late (E, N)
4807 then
4808 return;
4809 end if;
4811 D := Declaration_Node (E);
4812 K := Nkind (D);
4814 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
4815 or else
4816 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
4817 and then Nkind (D) = N_Object_Declaration
4818 and then Nkind (Object_Definition (D)) =
4819 N_Constrained_Array_Definition)
4820 then
4821 -- The flag is set on the object, or on the base type
4823 if Nkind (D) /= N_Object_Declaration then
4824 E := Base_Type (E);
4825 end if;
4827 Set_Has_Volatile_Components (E);
4829 if Prag_Id = Pragma_Atomic_Components then
4830 Set_Has_Atomic_Components (E);
4832 if Is_Packed (E) then
4833 Set_Is_Packed (E, False);
4835 Error_Pragma_Arg
4836 ("?Pack canceled, cannot pack atomic components",
4837 Arg1);
4838 end if;
4839 end if;
4841 else
4842 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
4843 end if;
4844 end Atomic_Components;
4846 --------------------
4847 -- Attach_Handler --
4848 --------------------
4850 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
4852 when Pragma_Attach_Handler =>
4853 Check_Ada_83_Warning;
4854 Check_No_Identifiers;
4855 Check_Arg_Count (2);
4857 if No_Run_Time_Mode then
4858 Error_Msg_CRT ("Attach_Handler pragma", N);
4859 else
4860 Check_Interrupt_Or_Attach_Handler;
4862 -- The expression that designates the attribute may
4863 -- depend on a discriminant, and is therefore a per-
4864 -- object expression, to be expanded in the init proc.
4865 -- If expansion is enabled, perform semantic checks
4866 -- on a copy only.
4868 if Expander_Active then
4869 declare
4870 Temp : constant Node_Id :=
4871 New_Copy_Tree (Expression (Arg2));
4872 begin
4873 Set_Parent (Temp, N);
4874 Pre_Analyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
4875 end;
4877 else
4878 Analyze (Expression (Arg2));
4879 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
4880 end if;
4882 Process_Interrupt_Or_Attach_Handler;
4883 end if;
4885 --------------------
4886 -- C_Pass_By_Copy --
4887 --------------------
4889 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
4891 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
4892 Arg : Node_Id;
4893 Val : Uint;
4895 begin
4896 GNAT_Pragma;
4897 Check_Valid_Configuration_Pragma;
4898 Check_Arg_Count (1);
4899 Check_Optional_Identifier (Arg1, "max_size");
4901 Arg := Expression (Arg1);
4902 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
4904 Val := Expr_Value (Arg);
4906 if Val <= 0 then
4907 Error_Pragma_Arg
4908 ("maximum size for pragma% must be positive", Arg1);
4910 elsif UI_Is_In_Int_Range (Val) then
4911 Default_C_Record_Mechanism := UI_To_Int (Val);
4913 -- If a giant value is given, Int'Last will do well enough.
4914 -- If sometime someone complains that a record larger than
4915 -- two gigabytes is not copied, we will worry about it then!
4917 else
4918 Default_C_Record_Mechanism := Mechanism_Type'Last;
4919 end if;
4920 end C_Pass_By_Copy;
4922 -------------
4923 -- Comment --
4924 -------------
4926 -- pragma Comment (static_string_EXPRESSION)
4928 -- Processing for pragma Comment shares the circuitry for
4929 -- pragma Ident. The only differences are that Ident enforces
4930 -- a limit of 31 characters on its argument, and also enforces
4931 -- limitations on placement for DEC compatibility. Pragma
4932 -- Comment shares neither of these restrictions.
4934 -------------------
4935 -- Common_Object --
4936 -------------------
4938 -- pragma Common_Object (
4939 -- [Internal =>] LOCAL_NAME,
4940 -- [, [External =>] EXTERNAL_SYMBOL]
4941 -- [, [Size =>] EXTERNAL_SYMBOL]);
4943 -- Processing for this pragma is shared with Psect_Object
4945 --------------------------
4946 -- Compile_Time_Warning --
4947 --------------------------
4949 -- pragma Compile_Time_Warning
4950 -- (boolean_EXPRESSION, static_string_EXPRESSION);
4952 when Pragma_Compile_Time_Warning => Compile_Time_Warning : declare
4953 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
4955 begin
4956 GNAT_Pragma;
4957 Check_Arg_Count (2);
4958 Check_No_Identifiers;
4959 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4960 Analyze_And_Resolve (Arg1x, Standard_Boolean);
4962 if Compile_Time_Known_Value (Arg1x) then
4963 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
4964 String_To_Name_Buffer (Strval (Get_Pragma_Arg (Arg2)));
4965 Add_Char_To_Name_Buffer ('?');
4967 declare
4968 Msg : String (1 .. Name_Len) :=
4969 Name_Buffer (1 .. Name_Len);
4971 B : Natural;
4973 begin
4974 -- This loop looks for multiple lines separated by
4975 -- ASCII.LF and breaks them into continuation error
4976 -- messages marked with the usual back slash.
4978 B := 1;
4979 for S in 2 .. Msg'Length - 1 loop
4980 if Msg (S) = ASCII.LF then
4981 Msg (S) := '?';
4982 Error_Msg_N (Msg (B .. S), Arg1);
4983 B := S;
4984 Msg (B) := '\';
4985 end if;
4986 end loop;
4988 Error_Msg_N (Msg (B .. Msg'Length), Arg1);
4989 end;
4990 end if;
4991 end if;
4992 end Compile_Time_Warning;
4994 -----------------------------
4995 -- Complete_Representation --
4996 -----------------------------
4998 -- pragma Complete_Representation;
5000 when Pragma_Complete_Representation =>
5001 GNAT_Pragma;
5002 Check_Arg_Count (0);
5004 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
5005 Error_Pragma
5006 ("pragma & must appear within record representation clause");
5007 end if;
5009 ----------------------------
5010 -- Complex_Representation --
5011 ----------------------------
5013 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
5015 when Pragma_Complex_Representation => Complex_Representation : declare
5016 E_Id : Entity_Id;
5017 E : Entity_Id;
5018 Ent : Entity_Id;
5020 begin
5021 GNAT_Pragma;
5022 Check_Arg_Count (1);
5023 Check_Optional_Identifier (Arg1, Name_Entity);
5024 Check_Arg_Is_Local_Name (Arg1);
5025 E_Id := Expression (Arg1);
5027 if Etype (E_Id) = Any_Type then
5028 return;
5029 end if;
5031 E := Entity (E_Id);
5033 if not Is_Record_Type (E) then
5034 Error_Pragma_Arg
5035 ("argument for pragma% must be record type", Arg1);
5036 end if;
5038 Ent := First_Entity (E);
5040 if No (Ent)
5041 or else No (Next_Entity (Ent))
5042 or else Present (Next_Entity (Next_Entity (Ent)))
5043 or else not Is_Floating_Point_Type (Etype (Ent))
5044 or else Etype (Ent) /= Etype (Next_Entity (Ent))
5045 then
5046 Error_Pragma_Arg
5047 ("record for pragma% must have two fields of same fpt type",
5048 Arg1);
5050 else
5051 Set_Has_Complex_Representation (Base_Type (E));
5052 end if;
5053 end Complex_Representation;
5055 -------------------------
5056 -- Component_Alignment --
5057 -------------------------
5059 -- pragma Component_Alignment (
5060 -- [Form =>] ALIGNMENT_CHOICE
5061 -- [, [Name =>] type_LOCAL_NAME]);
5063 -- ALIGNMENT_CHOICE ::=
5064 -- Component_Size
5065 -- | Component_Size_4
5066 -- | Storage_Unit
5067 -- | Default
5069 when Pragma_Component_Alignment => Component_AlignmentP : declare
5070 Args : Args_List (1 .. 2);
5071 Names : constant Name_List (1 .. 2) := (
5072 Name_Form,
5073 Name_Name);
5075 Form : Node_Id renames Args (1);
5076 Name : Node_Id renames Args (2);
5078 Atype : Component_Alignment_Kind;
5079 Typ : Entity_Id;
5081 begin
5082 GNAT_Pragma;
5083 Gather_Associations (Names, Args);
5085 if No (Form) then
5086 Error_Pragma ("missing Form argument for pragma%");
5087 end if;
5089 Check_Arg_Is_Identifier (Form);
5091 -- Get proper alignment, note that Default = Component_Size
5092 -- on all machines we have so far, and we want to set this
5093 -- value rather than the default value to indicate that it
5094 -- has been explicitly set (and thus will not get overridden
5095 -- by the default component alignment for the current scope)
5097 if Chars (Form) = Name_Component_Size then
5098 Atype := Calign_Component_Size;
5100 elsif Chars (Form) = Name_Component_Size_4 then
5101 Atype := Calign_Component_Size_4;
5103 elsif Chars (Form) = Name_Default then
5104 Atype := Calign_Component_Size;
5106 elsif Chars (Form) = Name_Storage_Unit then
5107 Atype := Calign_Storage_Unit;
5109 else
5110 Error_Pragma_Arg
5111 ("invalid Form parameter for pragma%", Form);
5112 end if;
5114 -- Case with no name, supplied, affects scope table entry
5116 if No (Name) then
5117 Scope_Stack.Table
5118 (Scope_Stack.Last).Component_Alignment_Default := Atype;
5120 -- Case of name supplied
5122 else
5123 Check_Arg_Is_Local_Name (Name);
5124 Find_Type (Name);
5125 Typ := Entity (Name);
5127 if Typ = Any_Type
5128 or else Rep_Item_Too_Early (Typ, N)
5129 then
5130 return;
5131 else
5132 Typ := Underlying_Type (Typ);
5133 end if;
5135 if not Is_Record_Type (Typ)
5136 and then not Is_Array_Type (Typ)
5137 then
5138 Error_Pragma_Arg
5139 ("Name parameter of pragma% must identify record or " &
5140 "array type", Name);
5141 end if;
5143 -- An explicit Component_Alignment pragma overrides an
5144 -- implicit pragma Pack, but not an explicit one.
5146 if not Has_Pragma_Pack (Base_Type (Typ)) then
5147 Set_Is_Packed (Base_Type (Typ), False);
5148 Set_Component_Alignment (Base_Type (Typ), Atype);
5149 end if;
5150 end if;
5151 end Component_AlignmentP;
5153 ----------------
5154 -- Controlled --
5155 ----------------
5157 -- pragma Controlled (first_subtype_LOCAL_NAME);
5159 when Pragma_Controlled => Controlled : declare
5160 Arg : Node_Id;
5162 begin
5163 Check_No_Identifiers;
5164 Check_Arg_Count (1);
5165 Check_Arg_Is_Local_Name (Arg1);
5166 Arg := Expression (Arg1);
5168 if not Is_Entity_Name (Arg)
5169 or else not Is_Access_Type (Entity (Arg))
5170 then
5171 Error_Pragma_Arg ("pragma% requires access type", Arg1);
5172 else
5173 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
5174 end if;
5175 end Controlled;
5177 ----------------
5178 -- Convention --
5179 ----------------
5181 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
5182 -- [Entity =>] LOCAL_NAME);
5184 when Pragma_Convention => Convention : declare
5185 C : Convention_Id;
5186 E : Entity_Id;
5187 begin
5188 Check_Arg_Order ((Name_Convention, Name_Entity));
5189 Check_Ada_83_Warning;
5190 Check_Arg_Count (2);
5191 Process_Convention (C, E);
5192 end Convention;
5194 ---------------------------
5195 -- Convention_Identifier --
5196 ---------------------------
5198 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
5199 -- [Convention =>] convention_IDENTIFIER);
5201 when Pragma_Convention_Identifier => Convention_Identifier : declare
5202 Idnam : Name_Id;
5203 Cname : Name_Id;
5205 begin
5206 GNAT_Pragma;
5207 Check_Arg_Order ((Name_Name, Name_Convention));
5208 Check_Arg_Count (2);
5209 Check_Optional_Identifier (Arg1, Name_Name);
5210 Check_Optional_Identifier (Arg2, Name_Convention);
5211 Check_Arg_Is_Identifier (Arg1);
5212 Check_Arg_Is_Identifier (Arg1);
5213 Idnam := Chars (Expression (Arg1));
5214 Cname := Chars (Expression (Arg2));
5216 if Is_Convention_Name (Cname) then
5217 Record_Convention_Identifier
5218 (Idnam, Get_Convention_Id (Cname));
5219 else
5220 Error_Pragma_Arg
5221 ("second arg for % pragma must be convention", Arg2);
5222 end if;
5223 end Convention_Identifier;
5225 ---------------
5226 -- CPP_Class --
5227 ---------------
5229 -- pragma CPP_Class ([Entity =>] local_NAME)
5231 when Pragma_CPP_Class => CPP_Class : declare
5232 Arg : Node_Id;
5233 Typ : Entity_Id;
5234 Default_DTC : Entity_Id := Empty;
5235 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5236 C : Entity_Id;
5237 Tag_C : Entity_Id;
5239 begin
5240 GNAT_Pragma;
5241 Check_Arg_Count (1);
5242 Check_Optional_Identifier (Arg1, Name_Entity);
5243 Check_Arg_Is_Local_Name (Arg1);
5245 Arg := Expression (Arg1);
5246 Analyze (Arg);
5248 if Etype (Arg) = Any_Type then
5249 return;
5250 end if;
5252 if not Is_Entity_Name (Arg)
5253 or else not Is_Type (Entity (Arg))
5254 then
5255 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
5256 end if;
5258 Typ := Entity (Arg);
5260 if not Is_Record_Type (Typ) then
5261 Error_Pragma_Arg ("pragma% applicable to a record, "
5262 & "tagged record or record extension", Arg1);
5263 end if;
5265 Default_DTC := First_Component (Typ);
5266 while Present (Default_DTC)
5267 and then Etype (Default_DTC) /= VTP_Type
5268 loop
5269 Next_Component (Default_DTC);
5270 end loop;
5272 -- Case of non tagged type
5274 if not Is_Tagged_Type (Typ) then
5275 Set_Is_CPP_Class (Typ);
5277 if Present (Default_DTC) then
5278 Error_Pragma_Arg
5279 ("only tagged records can contain vtable pointers", Arg1);
5280 end if;
5282 -- Case of tagged type with no user-defined vtable ptr. In this
5283 -- case, because of our C++ ABI compatibility, the programmer
5284 -- does not need to specify the tag component.
5286 elsif Is_Tagged_Type (Typ)
5287 and then No (Default_DTC)
5288 then
5289 Set_Is_CPP_Class (Typ);
5290 Set_Is_Limited_Record (Typ);
5292 -- Tagged type that has a vtable ptr
5294 elsif Present (Default_DTC) then
5295 Set_Is_CPP_Class (Typ);
5296 Set_Is_Limited_Record (Typ);
5297 Set_Is_Tag (Default_DTC);
5298 Set_DT_Entry_Count (Default_DTC, No_Uint);
5300 -- Since a CPP type has no direct link to its associated tag
5301 -- most tags checks cannot be performed
5303 Set_Kill_Tag_Checks (Typ);
5304 Set_Kill_Tag_Checks (Class_Wide_Type (Typ));
5306 -- Get rid of the _tag component when there was one.
5307 -- It is only useful for regular tagged types
5309 if Expander_Active and then Typ = Root_Type (Typ) then
5311 Tag_C := First_Tag_Component (Typ);
5312 C := First_Entity (Typ);
5314 if C = Tag_C then
5315 Set_First_Entity (Typ, Next_Entity (Tag_C));
5317 else
5318 while Next_Entity (C) /= Tag_C loop
5319 Next_Entity (C);
5320 end loop;
5322 Set_Next_Entity (C, Next_Entity (Tag_C));
5323 end if;
5324 end if;
5325 end if;
5326 end CPP_Class;
5328 ---------------------
5329 -- CPP_Constructor --
5330 ---------------------
5332 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME);
5334 when Pragma_CPP_Constructor => CPP_Constructor : declare
5335 Id : Entity_Id;
5336 Def_Id : Entity_Id;
5338 begin
5339 GNAT_Pragma;
5340 Check_Arg_Count (1);
5341 Check_Optional_Identifier (Arg1, Name_Entity);
5342 Check_Arg_Is_Local_Name (Arg1);
5344 Id := Expression (Arg1);
5345 Find_Program_Unit_Name (Id);
5347 -- If we did not find the name, we are done
5349 if Etype (Id) = Any_Type then
5350 return;
5351 end if;
5353 Def_Id := Entity (Id);
5355 if Ekind (Def_Id) = E_Function
5356 and then Is_Class_Wide_Type (Etype (Def_Id))
5357 and then Is_CPP_Class (Etype (Etype (Def_Id)))
5358 then
5359 -- What the heck is this??? this pragma allows only 1 arg
5361 if Arg_Count >= 2 then
5362 Check_At_Most_N_Arguments (3);
5363 Process_Interface_Name (Def_Id, Arg2, Arg3);
5364 end if;
5366 if No (Parameter_Specifications (Parent (Def_Id))) then
5367 Set_Has_Completion (Def_Id);
5368 Set_Is_Constructor (Def_Id);
5369 else
5370 Error_Pragma_Arg
5371 ("non-default constructors not implemented", Arg1);
5372 end if;
5374 else
5375 Error_Pragma_Arg
5376 ("pragma% requires function returning a 'C'P'P_Class type",
5377 Arg1);
5378 end if;
5379 end CPP_Constructor;
5381 -----------------
5382 -- CPP_Virtual --
5383 -----------------
5385 -- pragma CPP_Virtual
5386 -- [Entity =>] LOCAL_NAME
5387 -- [ [Vtable_Ptr =>] LOCAL_NAME,
5388 -- [Position =>] static_integer_EXPRESSION]);
5390 when Pragma_CPP_Virtual => CPP_Virtual : declare
5391 Arg : Node_Id;
5392 Typ : Entity_Id;
5393 Subp : Entity_Id;
5394 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5395 DTC : Entity_Id;
5396 V : Uint;
5398 begin
5399 GNAT_Pragma;
5400 Check_Arg_Order ((Name_Entity, Name_Vtable_Ptr, Name_Position));
5402 if Arg_Count = 3 then
5403 Check_Optional_Identifier (Arg2, Name_Vtable_Ptr);
5405 -- We allow Entry_Count as well as Position for the third
5406 -- parameter for back compatibility with versions of GNAT
5407 -- before version 3.12. The documentation has always said
5408 -- Position, but the code up to 3.12 said Entry_Count.
5410 if Chars (Arg3) /= Name_Entry_Count then
5411 Check_Optional_Identifier (Arg3, Name_Position);
5412 end if;
5414 else
5415 Check_Arg_Count (1);
5416 end if;
5418 Check_Optional_Identifier (Arg1, Name_Entity);
5419 Check_Arg_Is_Local_Name (Arg1);
5421 -- First argument must be a subprogram name
5423 Arg := Expression (Arg1);
5424 Find_Program_Unit_Name (Arg);
5426 if Etype (Arg) = Any_Type then
5427 return;
5428 else
5429 Subp := Entity (Arg);
5430 end if;
5432 if not (Is_Subprogram (Subp)
5433 and then Is_Dispatching_Operation (Subp))
5434 then
5435 Error_Pragma_Arg
5436 ("pragma% must reference a primitive operation", Arg1);
5437 end if;
5439 Typ := Find_Dispatching_Type (Subp);
5441 -- If only one Argument defaults are :
5442 -- . DTC_Entity is the default Vtable pointer
5443 -- . DT_Position will be set at the freezing point
5445 if Arg_Count = 1 then
5446 Set_DTC_Entity (Subp, First_Tag_Component (Typ));
5447 return;
5448 end if;
5450 -- Second argument is a component name of type Vtable_Ptr
5452 Arg := Expression (Arg2);
5454 if Nkind (Arg) /= N_Identifier then
5455 Error_Msg_NE ("must be a& component name", Arg, Typ);
5456 raise Pragma_Exit;
5457 end if;
5459 DTC := First_Component (Typ);
5460 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5461 Next_Component (DTC);
5462 end loop;
5464 -- Case of tagged type with no user-defined vtable ptr
5466 if No (DTC) then
5467 Error_Msg_NE ("must be a& component name", Arg, Typ);
5468 raise Pragma_Exit;
5470 elsif Etype (DTC) /= VTP_Type then
5471 Wrong_Type (Arg, VTP_Type);
5472 return;
5473 end if;
5475 -- Third argument is an integer (DT_Position)
5477 Arg := Expression (Arg3);
5478 Analyze_And_Resolve (Arg, Any_Integer);
5480 if not Is_Static_Expression (Arg) then
5481 Flag_Non_Static_Expr
5482 ("third argument of pragma CPP_Virtual must be static!",
5483 Arg3);
5484 raise Pragma_Exit;
5486 else
5487 V := Expr_Value (Expression (Arg3));
5489 if V <= 0 then
5490 Error_Pragma_Arg
5491 ("third argument of pragma% must be positive",
5492 Arg3);
5494 else
5495 Set_DTC_Entity (Subp, DTC);
5496 Set_DT_Position (Subp, V);
5497 end if;
5498 end if;
5499 end CPP_Virtual;
5501 ----------------
5502 -- CPP_Vtable --
5503 ----------------
5505 -- pragma CPP_Vtable (
5506 -- [Entity =>] LOCAL_NAME
5507 -- [Vtable_Ptr =>] LOCAL_NAME,
5508 -- [Entry_Count =>] static_integer_EXPRESSION);
5510 when Pragma_CPP_Vtable => CPP_Vtable : declare
5511 Arg : Node_Id;
5512 Typ : Entity_Id;
5513 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5514 DTC : Entity_Id;
5515 V : Uint;
5516 Elmt : Elmt_Id;
5518 begin
5519 GNAT_Pragma;
5520 Check_Arg_Order ((Name_Entity, Name_Vtable_Ptr, Name_Entry_Count));
5521 Check_Arg_Count (3);
5522 Check_Optional_Identifier (Arg1, Name_Entity);
5523 Check_Optional_Identifier (Arg2, Name_Vtable_Ptr);
5524 Check_Optional_Identifier (Arg3, Name_Entry_Count);
5525 Check_Arg_Is_Local_Name (Arg1);
5527 -- First argument is a record type name
5529 Arg := Expression (Arg1);
5530 Analyze (Arg);
5532 if Etype (Arg) = Any_Type then
5533 return;
5534 else
5535 Typ := Entity (Arg);
5536 end if;
5538 if not (Is_Tagged_Type (Typ) and then Is_CPP_Class (Typ)) then
5539 Error_Pragma_Arg ("'C'P'P_Class tagged type expected", Arg1);
5540 end if;
5542 -- Second argument is a component name of type Vtable_Ptr
5544 Arg := Expression (Arg2);
5546 if Nkind (Arg) /= N_Identifier then
5547 Error_Msg_NE ("must be a& component name", Arg, Typ);
5548 raise Pragma_Exit;
5549 end if;
5551 DTC := First_Component (Typ);
5552 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5553 Next_Component (DTC);
5554 end loop;
5556 if No (DTC) then
5557 Error_Msg_NE ("must be a& component name", Arg, Typ);
5558 raise Pragma_Exit;
5560 elsif Etype (DTC) /= VTP_Type then
5561 Wrong_Type (DTC, VTP_Type);
5562 return;
5564 -- If it is the first pragma Vtable, This becomes the default tag
5566 elsif (not Is_Tag (DTC))
5567 and then DT_Entry_Count (First_Tag_Component (Typ)) = No_Uint
5568 then
5569 Set_Is_Tag (First_Tag_Component (Typ), False);
5570 Set_Is_Tag (DTC, True);
5571 Set_DT_Entry_Count (DTC, No_Uint);
5572 end if;
5574 -- Those pragmas must appear before any primitive operation
5575 -- definition (except inherited ones) otherwise the default
5576 -- may be wrong
5578 Elmt := First_Elmt (Primitive_Operations (Typ));
5579 while Present (Elmt) loop
5580 if No (Alias (Node (Elmt))) then
5581 Error_Msg_Sloc := Sloc (Node (Elmt));
5582 Error_Pragma
5583 ("pragma% must appear before this primitive operation");
5584 end if;
5586 Next_Elmt (Elmt);
5587 end loop;
5589 -- Third argument is an integer (DT_Entry_Count)
5591 Arg := Expression (Arg3);
5592 Analyze_And_Resolve (Arg, Any_Integer);
5594 if not Is_Static_Expression (Arg) then
5595 Flag_Non_Static_Expr
5596 ("entry count for pragma CPP_Vtable must be a static " &
5597 "expression!", Arg3);
5598 raise Pragma_Exit;
5600 else
5601 V := Expr_Value (Expression (Arg3));
5603 if V <= 0 then
5604 Error_Pragma_Arg
5605 ("entry count for pragma% must be positive", Arg3);
5606 else
5607 Set_DT_Entry_Count (DTC, V);
5608 end if;
5609 end if;
5610 end CPP_Vtable;
5612 -----------
5613 -- Debug --
5614 -----------
5616 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
5618 when Pragma_Debug => Debug : declare
5619 Cond : Node_Id;
5621 begin
5622 GNAT_Pragma;
5624 Cond :=
5625 New_Occurrence_Of
5626 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
5627 Loc);
5629 if Arg_Count = 2 then
5630 Cond :=
5631 Make_And_Then (Loc,
5632 Left_Opnd => Relocate_Node (Cond),
5633 Right_Opnd => Expression (Arg1));
5634 end if;
5636 -- Rewrite into a conditional with an appropriate condition. We
5637 -- wrap the procedure call in a block so that overhead from e.g.
5638 -- use of the secondary stack does not generate execution overhead
5639 -- for suppressed conditions.
5641 Rewrite (N, Make_Implicit_If_Statement (N,
5642 Condition => Cond,
5643 Then_Statements => New_List (
5644 Make_Block_Statement (Loc,
5645 Handled_Statement_Sequence =>
5646 Make_Handled_Sequence_Of_Statements (Loc,
5647 Statements => New_List (
5648 Relocate_Node (Debug_Statement (N))))))));
5649 Analyze (N);
5650 end Debug;
5652 ------------------
5653 -- Debug_Policy --
5654 ------------------
5656 -- pragma Debug_Policy (Check | Ignore)
5658 when Pragma_Debug_Policy =>
5659 GNAT_Pragma;
5660 Check_Arg_Count (1);
5661 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5662 Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
5664 ---------------------
5665 -- Detect_Blocking --
5666 ---------------------
5668 -- pragma Detect_Blocking;
5670 when Pragma_Detect_Blocking =>
5671 GNAT_Pragma;
5672 Check_Arg_Count (0);
5673 Check_Valid_Configuration_Pragma;
5674 Detect_Blocking := True;
5676 -------------------
5677 -- Discard_Names --
5678 -------------------
5680 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
5682 when Pragma_Discard_Names => Discard_Names : declare
5683 E_Id : Entity_Id;
5684 E : Entity_Id;
5686 begin
5687 Check_Ada_83_Warning;
5689 -- Deal with configuration pragma case
5691 if Arg_Count = 0 and then Is_Configuration_Pragma then
5692 Global_Discard_Names := True;
5693 return;
5695 -- Otherwise, check correct appropriate context
5697 else
5698 Check_Is_In_Decl_Part_Or_Package_Spec;
5700 if Arg_Count = 0 then
5702 -- If there is no parameter, then from now on this pragma
5703 -- applies to any enumeration, exception or tagged type
5704 -- defined in the current declarative part.
5706 Set_Discard_Names (Current_Scope);
5707 return;
5709 else
5710 Check_Arg_Count (1);
5711 Check_Optional_Identifier (Arg1, Name_On);
5712 Check_Arg_Is_Local_Name (Arg1);
5713 E_Id := Expression (Arg1);
5715 if Etype (E_Id) = Any_Type then
5716 return;
5717 else
5718 E := Entity (E_Id);
5719 end if;
5721 if (Is_First_Subtype (E)
5722 and then (Is_Enumeration_Type (E)
5723 or else Is_Tagged_Type (E)))
5724 or else Ekind (E) = E_Exception
5725 then
5726 Set_Discard_Names (E);
5727 else
5728 Error_Pragma_Arg
5729 ("inappropriate entity for pragma%", Arg1);
5730 end if;
5731 end if;
5732 end if;
5733 end Discard_Names;
5735 ---------------
5736 -- Elaborate --
5737 ---------------
5739 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
5741 when Pragma_Elaborate => Elaborate : declare
5742 Plist : List_Id;
5743 Parent_Node : Node_Id;
5744 Arg : Node_Id;
5745 Citem : Node_Id;
5747 begin
5748 -- Pragma must be in context items list of a compilation unit
5750 if not Is_List_Member (N) then
5751 Pragma_Misplaced;
5752 return;
5754 else
5755 Plist := List_Containing (N);
5756 Parent_Node := Parent (Plist);
5758 if Parent_Node = Empty
5759 or else Nkind (Parent_Node) /= N_Compilation_Unit
5760 or else Context_Items (Parent_Node) /= Plist
5761 then
5762 Pragma_Misplaced;
5763 return;
5764 end if;
5765 end if;
5767 -- Must be at least one argument
5769 if Arg_Count = 0 then
5770 Error_Pragma ("pragma% requires at least one argument");
5771 end if;
5773 -- In Ada 83 mode, there can be no items following it in the
5774 -- context list except other pragmas and implicit with clauses
5775 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
5776 -- placement rule does not apply.
5778 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5779 Citem := Next (N);
5781 while Present (Citem) loop
5782 if Nkind (Citem) = N_Pragma
5783 or else (Nkind (Citem) = N_With_Clause
5784 and then Implicit_With (Citem))
5785 then
5786 null;
5787 else
5788 Error_Pragma
5789 ("(Ada 83) pragma% must be at end of context clause");
5790 end if;
5792 Next (Citem);
5793 end loop;
5794 end if;
5796 -- Finally, the arguments must all be units mentioned in a with
5797 -- clause in the same context clause. Note we already checked
5798 -- (in Par.Prag) that the arguments are either identifiers or
5800 Arg := Arg1;
5801 Outer : while Present (Arg) loop
5802 Citem := First (Plist);
5804 Inner : while Citem /= N loop
5805 if Nkind (Citem) = N_With_Clause
5806 and then Same_Name (Name (Citem), Expression (Arg))
5807 then
5808 Set_Elaborate_Present (Citem, True);
5809 Set_Unit_Name (Expression (Arg), Name (Citem));
5811 -- With the pragma present, elaboration calls on
5812 -- subprograms from the named unit need no further
5813 -- checks, as long as the pragma appears in the current
5814 -- compilation unit. If the pragma appears in some unit
5815 -- in the context, there might still be a need for an
5816 -- Elaborate_All_Desirable from the current compilation
5817 -- to the the named unit, so we keep the check enabled.
5819 if In_Extended_Main_Source_Unit (N) then
5820 Set_Suppress_Elaboration_Warnings
5821 (Entity (Name (Citem)));
5822 end if;
5823 exit Inner;
5824 end if;
5826 Next (Citem);
5827 end loop Inner;
5829 if Citem = N then
5830 Error_Pragma_Arg
5831 ("argument of pragma% is not with'ed unit", Arg);
5832 end if;
5834 Next (Arg);
5835 end loop Outer;
5837 -- Give a warning if operating in static mode with -gnatwl
5838 -- (elaboration warnings eanbled) switch set.
5840 if Elab_Warnings and not Dynamic_Elaboration_Checks then
5841 Error_Msg_N
5842 ("?use of pragma Elaborate may not be safe", N);
5843 Error_Msg_N
5844 ("?use pragma Elaborate_All instead if possible", N);
5845 end if;
5846 end Elaborate;
5848 -------------------
5849 -- Elaborate_All --
5850 -------------------
5852 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
5854 when Pragma_Elaborate_All => Elaborate_All : declare
5855 Plist : List_Id;
5856 Parent_Node : Node_Id;
5857 Arg : Node_Id;
5858 Citem : Node_Id;
5860 begin
5861 Check_Ada_83_Warning;
5863 -- Pragma must be in context items list of a compilation unit
5865 if not Is_List_Member (N) then
5866 Pragma_Misplaced;
5867 return;
5869 else
5870 Plist := List_Containing (N);
5871 Parent_Node := Parent (Plist);
5873 if Parent_Node = Empty
5874 or else Nkind (Parent_Node) /= N_Compilation_Unit
5875 or else Context_Items (Parent_Node) /= Plist
5876 then
5877 Pragma_Misplaced;
5878 return;
5879 end if;
5880 end if;
5882 -- Must be at least one argument
5884 if Arg_Count = 0 then
5885 Error_Pragma ("pragma% requires at least one argument");
5886 end if;
5888 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
5889 -- have to appear at the end of the context clause, but may
5890 -- appear mixed in with other items, even in Ada 83 mode.
5892 -- Final check: the arguments must all be units mentioned in
5893 -- a with clause in the same context clause. Note that we
5894 -- already checked (in Par.Prag) that all the arguments are
5895 -- either identifiers or selected components.
5897 Arg := Arg1;
5898 Outr : while Present (Arg) loop
5899 Citem := First (Plist);
5901 Innr : while Citem /= N loop
5902 if Nkind (Citem) = N_With_Clause
5903 and then Same_Name (Name (Citem), Expression (Arg))
5904 then
5905 Set_Elaborate_All_Present (Citem, True);
5906 Set_Unit_Name (Expression (Arg), Name (Citem));
5908 -- Suppress warnings and elaboration checks on the named
5909 -- unit if the pragma is in the current compilation, as
5910 -- for pragma Elaborate.
5912 if In_Extended_Main_Source_Unit (N) then
5913 Set_Suppress_Elaboration_Warnings
5914 (Entity (Name (Citem)));
5915 end if;
5916 exit Innr;
5917 end if;
5919 Next (Citem);
5920 end loop Innr;
5922 if Citem = N then
5923 Set_Error_Posted (N);
5924 Error_Pragma_Arg
5925 ("argument of pragma% is not with'ed unit", Arg);
5926 end if;
5928 Next (Arg);
5929 end loop Outr;
5930 end Elaborate_All;
5932 --------------------
5933 -- Elaborate_Body --
5934 --------------------
5936 -- pragma Elaborate_Body [( library_unit_NAME )];
5938 when Pragma_Elaborate_Body => Elaborate_Body : declare
5939 Cunit_Node : Node_Id;
5940 Cunit_Ent : Entity_Id;
5942 begin
5943 Check_Ada_83_Warning;
5944 Check_Valid_Library_Unit_Pragma;
5946 if Nkind (N) = N_Null_Statement then
5947 return;
5948 end if;
5950 Cunit_Node := Cunit (Current_Sem_Unit);
5951 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
5953 if Nkind (Unit (Cunit_Node)) = N_Package_Body
5954 or else
5955 Nkind (Unit (Cunit_Node)) = N_Subprogram_Body
5956 then
5957 Error_Pragma ("pragma% must refer to a spec, not a body");
5958 else
5959 Set_Body_Required (Cunit_Node, True);
5960 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
5962 -- If we are in dynamic elaboration mode, then we suppress
5963 -- elaboration warnings for the unit, since it is definitely
5964 -- fine NOT to do dynamic checks at the first level (and such
5965 -- checks will be suppressed because no elaboration boolean
5966 -- is created for Elaborate_Body packages).
5968 -- But in the static model of elaboration, Elaborate_Body is
5969 -- definitely NOT good enough to ensure elaboration safety on
5970 -- its own, since the body may WITH other units that are not
5971 -- safe from an elaboration point of view, so a client must
5972 -- still do an Elaborate_All on such units.
5974 -- Debug flag -gnatdD restores the old behavior of 3.13,
5975 -- where Elaborate_Body always suppressed elab warnings.
5977 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
5978 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
5979 end if;
5980 end if;
5981 end Elaborate_Body;
5983 ------------------------
5984 -- Elaboration_Checks --
5985 ------------------------
5987 -- pragma Elaboration_Checks (Static | Dynamic);
5989 when Pragma_Elaboration_Checks =>
5990 GNAT_Pragma;
5991 Check_Arg_Count (1);
5992 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
5993 Dynamic_Elaboration_Checks :=
5994 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
5996 ---------------
5997 -- Eliminate --
5998 ---------------
6000 -- pragma Eliminate (
6001 -- [Unit_Name =>] IDENTIFIER |
6002 -- SELECTED_COMPONENT
6003 -- [,[Entity =>] IDENTIFIER |
6004 -- SELECTED_COMPONENT |
6005 -- STRING_LITERAL]
6006 -- [,]OVERLOADING_RESOLUTION);
6008 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
6009 -- SOURCE_LOCATION
6011 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
6012 -- FUNCTION_PROFILE
6014 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
6016 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
6017 -- Result_Type => result_SUBTYPE_NAME]
6019 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
6020 -- SUBTYPE_NAME ::= STRING_LITERAL
6022 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
6023 -- SOURCE_TRACE ::= STRING_LITERAL
6025 when Pragma_Eliminate => Eliminate : declare
6026 Args : Args_List (1 .. 5);
6027 Names : constant Name_List (1 .. 5) := (
6028 Name_Unit_Name,
6029 Name_Entity,
6030 Name_Parameter_Types,
6031 Name_Result_Type,
6032 Name_Source_Location);
6034 Unit_Name : Node_Id renames Args (1);
6035 Entity : Node_Id renames Args (2);
6036 Parameter_Types : Node_Id renames Args (3);
6037 Result_Type : Node_Id renames Args (4);
6038 Source_Location : Node_Id renames Args (5);
6040 begin
6041 GNAT_Pragma;
6042 Check_Valid_Configuration_Pragma;
6043 Gather_Associations (Names, Args);
6045 if No (Unit_Name) then
6046 Error_Pragma ("missing Unit_Name argument for pragma%");
6047 end if;
6049 if No (Entity)
6050 and then (Present (Parameter_Types)
6051 or else
6052 Present (Result_Type)
6053 or else
6054 Present (Source_Location))
6055 then
6056 Error_Pragma ("missing Entity argument for pragma%");
6057 end if;
6059 if (Present (Parameter_Types)
6060 or else
6061 Present (Result_Type))
6062 and then
6063 Present (Source_Location)
6064 then
6065 Error_Pragma
6066 ("parameter profile and source location cannot " &
6067 "be used together in pragma%");
6068 end if;
6070 Process_Eliminate_Pragma
6072 Unit_Name,
6073 Entity,
6074 Parameter_Types,
6075 Result_Type,
6076 Source_Location);
6077 end Eliminate;
6079 -------------------------
6080 -- Explicit_Overriding --
6081 -------------------------
6083 when Pragma_Explicit_Overriding =>
6084 Check_Valid_Configuration_Pragma;
6085 Check_Arg_Count (0);
6086 Explicit_Overriding := True;
6088 ------------
6089 -- Export --
6090 ------------
6092 -- pragma Export (
6093 -- [ Convention =>] convention_IDENTIFIER,
6094 -- [ Entity =>] local_NAME
6095 -- [, [External_Name =>] static_string_EXPRESSION ]
6096 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6098 when Pragma_Export => Export : declare
6099 C : Convention_Id;
6100 Def_Id : Entity_Id;
6102 begin
6103 Check_Ada_83_Warning;
6104 Check_Arg_Order
6105 ((Name_Convention,
6106 Name_Entity,
6107 Name_External_Name,
6108 Name_Link_Name));
6109 Check_At_Least_N_Arguments (2);
6110 Check_At_Most_N_Arguments (4);
6111 Process_Convention (C, Def_Id);
6113 if Ekind (Def_Id) /= E_Constant then
6114 Note_Possible_Modification (Expression (Arg2));
6115 end if;
6117 Process_Interface_Name (Def_Id, Arg3, Arg4);
6118 Set_Exported (Def_Id, Arg2);
6119 end Export;
6121 ----------------------
6122 -- Export_Exception --
6123 ----------------------
6125 -- pragma Export_Exception (
6126 -- [Internal =>] LOCAL_NAME,
6127 -- [, [External =>] EXTERNAL_SYMBOL,]
6128 -- [, [Form =>] Ada | VMS]
6129 -- [, [Code =>] static_integer_EXPRESSION]);
6131 when Pragma_Export_Exception => Export_Exception : declare
6132 Args : Args_List (1 .. 4);
6133 Names : constant Name_List (1 .. 4) := (
6134 Name_Internal,
6135 Name_External,
6136 Name_Form,
6137 Name_Code);
6139 Internal : Node_Id renames Args (1);
6140 External : Node_Id renames Args (2);
6141 Form : Node_Id renames Args (3);
6142 Code : Node_Id renames Args (4);
6144 begin
6145 if Inside_A_Generic then
6146 Error_Pragma ("pragma% cannot be used for generic entities");
6147 end if;
6149 Gather_Associations (Names, Args);
6150 Process_Extended_Import_Export_Exception_Pragma (
6151 Arg_Internal => Internal,
6152 Arg_External => External,
6153 Arg_Form => Form,
6154 Arg_Code => Code);
6156 if not Is_VMS_Exception (Entity (Internal)) then
6157 Set_Exported (Entity (Internal), Internal);
6158 end if;
6159 end Export_Exception;
6161 ---------------------
6162 -- Export_Function --
6163 ---------------------
6165 -- pragma Export_Function (
6166 -- [Internal =>] LOCAL_NAME,
6167 -- [, [External =>] EXTERNAL_SYMBOL,]
6168 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6169 -- [, [Result_Type =>] TYPE_DESIGNATOR]
6170 -- [, [Mechanism =>] MECHANISM]
6171 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
6173 -- EXTERNAL_SYMBOL ::=
6174 -- IDENTIFIER
6175 -- | static_string_EXPRESSION
6177 -- PARAMETER_TYPES ::=
6178 -- null
6179 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6181 -- TYPE_DESIGNATOR ::=
6182 -- subtype_NAME
6183 -- | subtype_Name ' Access
6185 -- MECHANISM ::=
6186 -- MECHANISM_NAME
6187 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6189 -- MECHANISM_ASSOCIATION ::=
6190 -- [formal_parameter_NAME =>] MECHANISM_NAME
6192 -- MECHANISM_NAME ::=
6193 -- Value
6194 -- | Reference
6195 -- | Descriptor [([Class =>] CLASS_NAME)]
6197 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6199 when Pragma_Export_Function => Export_Function : declare
6200 Args : Args_List (1 .. 6);
6201 Names : constant Name_List (1 .. 6) := (
6202 Name_Internal,
6203 Name_External,
6204 Name_Parameter_Types,
6205 Name_Result_Type,
6206 Name_Mechanism,
6207 Name_Result_Mechanism);
6209 Internal : Node_Id renames Args (1);
6210 External : Node_Id renames Args (2);
6211 Parameter_Types : Node_Id renames Args (3);
6212 Result_Type : Node_Id renames Args (4);
6213 Mechanism : Node_Id renames Args (5);
6214 Result_Mechanism : Node_Id renames Args (6);
6216 begin
6217 GNAT_Pragma;
6218 Gather_Associations (Names, Args);
6219 Process_Extended_Import_Export_Subprogram_Pragma (
6220 Arg_Internal => Internal,
6221 Arg_External => External,
6222 Arg_Parameter_Types => Parameter_Types,
6223 Arg_Result_Type => Result_Type,
6224 Arg_Mechanism => Mechanism,
6225 Arg_Result_Mechanism => Result_Mechanism);
6226 end Export_Function;
6228 -------------------
6229 -- Export_Object --
6230 -------------------
6232 -- pragma Export_Object (
6233 -- [Internal =>] LOCAL_NAME,
6234 -- [, [External =>] EXTERNAL_SYMBOL]
6235 -- [, [Size =>] EXTERNAL_SYMBOL]);
6237 -- EXTERNAL_SYMBOL ::=
6238 -- IDENTIFIER
6239 -- | static_string_EXPRESSION
6241 -- PARAMETER_TYPES ::=
6242 -- null
6243 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6245 -- TYPE_DESIGNATOR ::=
6246 -- subtype_NAME
6247 -- | subtype_Name ' Access
6249 -- MECHANISM ::=
6250 -- MECHANISM_NAME
6251 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6253 -- MECHANISM_ASSOCIATION ::=
6254 -- [formal_parameter_NAME =>] MECHANISM_NAME
6256 -- MECHANISM_NAME ::=
6257 -- Value
6258 -- | Reference
6259 -- | Descriptor [([Class =>] CLASS_NAME)]
6261 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6263 when Pragma_Export_Object => Export_Object : declare
6264 Args : Args_List (1 .. 3);
6265 Names : constant Name_List (1 .. 3) := (
6266 Name_Internal,
6267 Name_External,
6268 Name_Size);
6270 Internal : Node_Id renames Args (1);
6271 External : Node_Id renames Args (2);
6272 Size : Node_Id renames Args (3);
6274 begin
6275 GNAT_Pragma;
6276 Gather_Associations (Names, Args);
6277 Process_Extended_Import_Export_Object_Pragma (
6278 Arg_Internal => Internal,
6279 Arg_External => External,
6280 Arg_Size => Size);
6281 end Export_Object;
6283 ----------------------
6284 -- Export_Procedure --
6285 ----------------------
6287 -- pragma Export_Procedure (
6288 -- [Internal =>] LOCAL_NAME,
6289 -- [, [External =>] EXTERNAL_SYMBOL,]
6290 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6291 -- [, [Mechanism =>] MECHANISM]);
6293 -- EXTERNAL_SYMBOL ::=
6294 -- IDENTIFIER
6295 -- | static_string_EXPRESSION
6297 -- PARAMETER_TYPES ::=
6298 -- null
6299 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6301 -- TYPE_DESIGNATOR ::=
6302 -- subtype_NAME
6303 -- | subtype_Name ' Access
6305 -- MECHANISM ::=
6306 -- MECHANISM_NAME
6307 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6309 -- MECHANISM_ASSOCIATION ::=
6310 -- [formal_parameter_NAME =>] MECHANISM_NAME
6312 -- MECHANISM_NAME ::=
6313 -- Value
6314 -- | Reference
6315 -- | Descriptor [([Class =>] CLASS_NAME)]
6317 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6319 when Pragma_Export_Procedure => Export_Procedure : declare
6320 Args : Args_List (1 .. 4);
6321 Names : constant Name_List (1 .. 4) := (
6322 Name_Internal,
6323 Name_External,
6324 Name_Parameter_Types,
6325 Name_Mechanism);
6327 Internal : Node_Id renames Args (1);
6328 External : Node_Id renames Args (2);
6329 Parameter_Types : Node_Id renames Args (3);
6330 Mechanism : Node_Id renames Args (4);
6332 begin
6333 GNAT_Pragma;
6334 Gather_Associations (Names, Args);
6335 Process_Extended_Import_Export_Subprogram_Pragma (
6336 Arg_Internal => Internal,
6337 Arg_External => External,
6338 Arg_Parameter_Types => Parameter_Types,
6339 Arg_Mechanism => Mechanism);
6340 end Export_Procedure;
6342 ------------------
6343 -- Export_Value --
6344 ------------------
6346 -- pragma Export_Value (
6347 -- [Value =>] static_integer_EXPRESSION,
6348 -- [Link_Name =>] static_string_EXPRESSION);
6350 when Pragma_Export_Value =>
6351 GNAT_Pragma;
6352 Check_Arg_Order ((Name_Value, Name_Link_Name));
6353 Check_Arg_Count (2);
6355 Check_Optional_Identifier (Arg1, Name_Value);
6356 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
6358 Check_Optional_Identifier (Arg2, Name_Link_Name);
6359 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6361 -----------------------------
6362 -- Export_Valued_Procedure --
6363 -----------------------------
6365 -- pragma Export_Valued_Procedure (
6366 -- [Internal =>] LOCAL_NAME,
6367 -- [, [External =>] EXTERNAL_SYMBOL,]
6368 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6369 -- [, [Mechanism =>] MECHANISM]);
6371 -- EXTERNAL_SYMBOL ::=
6372 -- IDENTIFIER
6373 -- | static_string_EXPRESSION
6375 -- PARAMETER_TYPES ::=
6376 -- null
6377 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6379 -- TYPE_DESIGNATOR ::=
6380 -- subtype_NAME
6381 -- | subtype_Name ' Access
6383 -- MECHANISM ::=
6384 -- MECHANISM_NAME
6385 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6387 -- MECHANISM_ASSOCIATION ::=
6388 -- [formal_parameter_NAME =>] MECHANISM_NAME
6390 -- MECHANISM_NAME ::=
6391 -- Value
6392 -- | Reference
6393 -- | Descriptor [([Class =>] CLASS_NAME)]
6395 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6397 when Pragma_Export_Valued_Procedure =>
6398 Export_Valued_Procedure : declare
6399 Args : Args_List (1 .. 4);
6400 Names : constant Name_List (1 .. 4) := (
6401 Name_Internal,
6402 Name_External,
6403 Name_Parameter_Types,
6404 Name_Mechanism);
6406 Internal : Node_Id renames Args (1);
6407 External : Node_Id renames Args (2);
6408 Parameter_Types : Node_Id renames Args (3);
6409 Mechanism : Node_Id renames Args (4);
6411 begin
6412 GNAT_Pragma;
6413 Gather_Associations (Names, Args);
6414 Process_Extended_Import_Export_Subprogram_Pragma (
6415 Arg_Internal => Internal,
6416 Arg_External => External,
6417 Arg_Parameter_Types => Parameter_Types,
6418 Arg_Mechanism => Mechanism);
6419 end Export_Valued_Procedure;
6421 -------------------
6422 -- Extend_System --
6423 -------------------
6425 -- pragma Extend_System ([Name =>] Identifier);
6427 when Pragma_Extend_System => Extend_System : declare
6428 begin
6429 GNAT_Pragma;
6430 Check_Valid_Configuration_Pragma;
6431 Check_Arg_Count (1);
6432 Check_Optional_Identifier (Arg1, Name_Name);
6433 Check_Arg_Is_Identifier (Arg1);
6435 Get_Name_String (Chars (Expression (Arg1)));
6437 if Name_Len > 4
6438 and then Name_Buffer (1 .. 4) = "aux_"
6439 then
6440 if Present (System_Extend_Pragma_Arg) then
6441 if Chars (Expression (Arg1)) =
6442 Chars (Expression (System_Extend_Pragma_Arg))
6443 then
6444 null;
6445 else
6446 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
6447 Error_Pragma ("pragma% conflicts with that at#");
6448 end if;
6450 else
6451 System_Extend_Pragma_Arg := Arg1;
6453 if not GNAT_Mode then
6454 System_Extend_Unit := Arg1;
6455 end if;
6456 end if;
6457 else
6458 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
6459 end if;
6460 end Extend_System;
6462 ------------------------
6463 -- Extensions_Allowed --
6464 ------------------------
6466 -- pragma Extensions_Allowed (ON | OFF);
6468 when Pragma_Extensions_Allowed =>
6469 GNAT_Pragma;
6470 Check_Arg_Count (1);
6471 Check_No_Identifiers;
6472 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6474 if Chars (Expression (Arg1)) = Name_On then
6475 Extensions_Allowed := True;
6476 Ada_Version := Ada_Version_Type'Last;
6477 else
6478 Extensions_Allowed := False;
6479 Ada_Version := Ada_Version_Type'Min (Ada_Version, Ada_95);
6480 end if;
6482 Ada_Version_Explicit := Ada_Version;
6484 --------------
6485 -- External --
6486 --------------
6488 -- pragma External (
6489 -- [ Convention =>] convention_IDENTIFIER,
6490 -- [ Entity =>] local_NAME
6491 -- [, [External_Name =>] static_string_EXPRESSION ]
6492 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6494 when Pragma_External => External : declare
6495 C : Convention_Id;
6496 Def_Id : Entity_Id;
6497 begin
6498 GNAT_Pragma;
6499 Check_Arg_Order
6500 ((Name_Convention,
6501 Name_Entity,
6502 Name_External_Name,
6503 Name_Link_Name));
6504 Check_At_Least_N_Arguments (2);
6505 Check_At_Most_N_Arguments (4);
6506 Process_Convention (C, Def_Id);
6507 Note_Possible_Modification (Expression (Arg2));
6508 Process_Interface_Name (Def_Id, Arg3, Arg4);
6509 Set_Exported (Def_Id, Arg2);
6510 end External;
6512 --------------------------
6513 -- External_Name_Casing --
6514 --------------------------
6516 -- pragma External_Name_Casing (
6517 -- UPPERCASE | LOWERCASE
6518 -- [, AS_IS | UPPERCASE | LOWERCASE]);
6520 when Pragma_External_Name_Casing => External_Name_Casing : declare
6521 begin
6522 GNAT_Pragma;
6523 Check_No_Identifiers;
6525 if Arg_Count = 2 then
6526 Check_Arg_Is_One_Of
6527 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
6529 case Chars (Get_Pragma_Arg (Arg2)) is
6530 when Name_As_Is =>
6531 Opt.External_Name_Exp_Casing := As_Is;
6533 when Name_Uppercase =>
6534 Opt.External_Name_Exp_Casing := Uppercase;
6536 when Name_Lowercase =>
6537 Opt.External_Name_Exp_Casing := Lowercase;
6539 when others =>
6540 null;
6541 end case;
6543 else
6544 Check_Arg_Count (1);
6545 end if;
6547 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
6549 case Chars (Get_Pragma_Arg (Arg1)) is
6550 when Name_Uppercase =>
6551 Opt.External_Name_Imp_Casing := Uppercase;
6553 when Name_Lowercase =>
6554 Opt.External_Name_Imp_Casing := Lowercase;
6556 when others =>
6557 null;
6558 end case;
6559 end External_Name_Casing;
6561 ---------------------------
6562 -- Finalize_Storage_Only --
6563 ---------------------------
6565 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
6567 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
6568 Assoc : constant Node_Id := Arg1;
6569 Type_Id : constant Node_Id := Expression (Assoc);
6570 Typ : Entity_Id;
6572 begin
6573 Check_No_Identifiers;
6574 Check_Arg_Count (1);
6575 Check_Arg_Is_Local_Name (Arg1);
6577 Find_Type (Type_Id);
6578 Typ := Entity (Type_Id);
6580 if Typ = Any_Type
6581 or else Rep_Item_Too_Early (Typ, N)
6582 then
6583 return;
6584 else
6585 Typ := Underlying_Type (Typ);
6586 end if;
6588 if not Is_Controlled (Typ) then
6589 Error_Pragma ("pragma% must specify controlled type");
6590 end if;
6592 Check_First_Subtype (Arg1);
6594 if Finalize_Storage_Only (Typ) then
6595 Error_Pragma ("duplicate pragma%, only one allowed");
6597 elsif not Rep_Item_Too_Late (Typ, N) then
6598 Set_Finalize_Storage_Only (Base_Type (Typ), True);
6599 end if;
6600 end Finalize_Storage;
6602 --------------------------
6603 -- Float_Representation --
6604 --------------------------
6606 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
6608 -- FLOAT_REP ::= VAX_Float | IEEE_Float
6610 when Pragma_Float_Representation => Float_Representation : declare
6611 Argx : Node_Id;
6612 Digs : Nat;
6613 Ent : Entity_Id;
6615 begin
6616 GNAT_Pragma;
6618 if Arg_Count = 1 then
6619 Check_Valid_Configuration_Pragma;
6620 else
6621 Check_Arg_Count (2);
6622 Check_Optional_Identifier (Arg2, Name_Entity);
6623 Check_Arg_Is_Local_Name (Arg2);
6624 end if;
6626 Check_No_Identifier (Arg1);
6627 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
6629 if not OpenVMS_On_Target then
6630 if Chars (Expression (Arg1)) = Name_VAX_Float then
6631 Error_Pragma
6632 ("?pragma% ignored (applies only to Open'V'M'S)");
6633 end if;
6635 return;
6636 end if;
6638 -- One argument case
6640 if Arg_Count = 1 then
6641 if Chars (Expression (Arg1)) = Name_VAX_Float then
6642 if Opt.Float_Format = 'I' then
6643 Error_Pragma ("'I'E'E'E format previously specified");
6644 end if;
6646 Opt.Float_Format := 'V';
6648 else
6649 if Opt.Float_Format = 'V' then
6650 Error_Pragma ("'V'A'X format previously specified");
6651 end if;
6653 Opt.Float_Format := 'I';
6654 end if;
6656 Set_Standard_Fpt_Formats;
6658 -- Two argument case
6660 else
6661 Argx := Get_Pragma_Arg (Arg2);
6663 if not Is_Entity_Name (Argx)
6664 or else not Is_Floating_Point_Type (Entity (Argx))
6665 then
6666 Error_Pragma_Arg
6667 ("second argument of% pragma must be floating-point type",
6668 Arg2);
6669 end if;
6671 Ent := Entity (Argx);
6672 Digs := UI_To_Int (Digits_Value (Ent));
6674 -- Two arguments, VAX_Float case
6676 if Chars (Expression (Arg1)) = Name_VAX_Float then
6677 case Digs is
6678 when 6 => Set_F_Float (Ent);
6679 when 9 => Set_D_Float (Ent);
6680 when 15 => Set_G_Float (Ent);
6682 when others =>
6683 Error_Pragma_Arg
6684 ("wrong digits value, must be 6,9 or 15", Arg2);
6685 end case;
6687 -- Two arguments, IEEE_Float case
6689 else
6690 case Digs is
6691 when 6 => Set_IEEE_Short (Ent);
6692 when 15 => Set_IEEE_Long (Ent);
6694 when others =>
6695 Error_Pragma_Arg
6696 ("wrong digits value, must be 6 or 15", Arg2);
6697 end case;
6698 end if;
6699 end if;
6700 end Float_Representation;
6702 -----------
6703 -- Ident --
6704 -----------
6706 -- pragma Ident (static_string_EXPRESSION)
6708 -- Note: pragma Comment shares this processing. Pragma Comment
6709 -- is identical to Ident, except that the restriction of the
6710 -- argument to 31 characters and the placement restrictions
6711 -- are not enforced for pragma Comment.
6713 when Pragma_Ident | Pragma_Comment => Ident : declare
6714 Str : Node_Id;
6716 begin
6717 GNAT_Pragma;
6718 Check_Arg_Count (1);
6719 Check_No_Identifiers;
6720 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
6722 -- For pragma Ident, preserve DEC compatibility by requiring
6723 -- the pragma to appear in a declarative part or package spec.
6725 if Prag_Id = Pragma_Ident then
6726 Check_Is_In_Decl_Part_Or_Package_Spec;
6727 end if;
6729 Str := Expr_Value_S (Expression (Arg1));
6731 declare
6732 CS : Node_Id;
6733 GP : Node_Id;
6735 begin
6736 GP := Parent (Parent (N));
6738 if Nkind (GP) = N_Package_Declaration
6739 or else
6740 Nkind (GP) = N_Generic_Package_Declaration
6741 then
6742 GP := Parent (GP);
6743 end if;
6745 -- If we have a compilation unit, then record the ident
6746 -- value, checking for improper duplication.
6748 if Nkind (GP) = N_Compilation_Unit then
6749 CS := Ident_String (Current_Sem_Unit);
6751 if Present (CS) then
6753 -- For Ident, we do not permit multiple instances
6755 if Prag_Id = Pragma_Ident then
6756 Error_Pragma ("duplicate% pragma not permitted");
6758 -- For Comment, we concatenate the string, unless we
6759 -- want to preserve the tree structure for ASIS.
6761 elsif not ASIS_Mode then
6762 Start_String (Strval (CS));
6763 Store_String_Char (' ');
6764 Store_String_Chars (Strval (Str));
6765 Set_Strval (CS, End_String);
6766 end if;
6768 else
6769 -- In VMS, the effect of IDENT is achieved by passing
6770 -- IDENTIFICATION=name as a --for-linker switch.
6772 if OpenVMS_On_Target then
6773 Start_String;
6774 Store_String_Chars
6775 ("--for-linker=IDENTIFICATION=");
6776 String_To_Name_Buffer (Strval (Str));
6777 Store_String_Chars (Name_Buffer (1 .. Name_Len));
6779 -- Only the last processed IDENT is saved. The main
6780 -- purpose is so an IDENT associated with a main
6781 -- procedure will be used in preference to an IDENT
6782 -- associated with a with'd package.
6784 Replace_Linker_Option_String
6785 (End_String, "--for-linker=IDENTIFICATION=");
6786 end if;
6788 Set_Ident_String (Current_Sem_Unit, Str);
6789 end if;
6791 -- For subunits, we just ignore the Ident, since in GNAT
6792 -- these are not separate object files, and hence not
6793 -- separate units in the unit table.
6795 elsif Nkind (GP) = N_Subunit then
6796 null;
6798 -- Otherwise we have a misplaced pragma Ident, but we ignore
6799 -- this if we are in an instantiation, since it comes from
6800 -- a generic, and has no relevance to the instantiation.
6802 elsif Prag_Id = Pragma_Ident then
6803 if Instantiation_Location (Loc) = No_Location then
6804 Error_Pragma ("pragma% only allowed at outer level");
6805 end if;
6806 end if;
6807 end;
6808 end Ident;
6810 ------------
6811 -- Import --
6812 ------------
6814 -- pragma Import (
6815 -- [ Convention =>] convention_IDENTIFIER,
6816 -- [ Entity =>] local_NAME
6817 -- [, [External_Name =>] static_string_EXPRESSION ]
6818 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6820 when Pragma_Import =>
6821 Check_Ada_83_Warning;
6822 Check_Arg_Order
6823 ((Name_Convention,
6824 Name_Entity,
6825 Name_External_Name,
6826 Name_Link_Name));
6827 Check_At_Least_N_Arguments (2);
6828 Check_At_Most_N_Arguments (4);
6829 Process_Import_Or_Interface;
6831 ----------------------
6832 -- Import_Exception --
6833 ----------------------
6835 -- pragma Import_Exception (
6836 -- [Internal =>] LOCAL_NAME,
6837 -- [, [External =>] EXTERNAL_SYMBOL,]
6838 -- [, [Form =>] Ada | VMS]
6839 -- [, [Code =>] static_integer_EXPRESSION]);
6841 when Pragma_Import_Exception => Import_Exception : declare
6842 Args : Args_List (1 .. 4);
6843 Names : constant Name_List (1 .. 4) := (
6844 Name_Internal,
6845 Name_External,
6846 Name_Form,
6847 Name_Code);
6849 Internal : Node_Id renames Args (1);
6850 External : Node_Id renames Args (2);
6851 Form : Node_Id renames Args (3);
6852 Code : Node_Id renames Args (4);
6854 begin
6855 Gather_Associations (Names, Args);
6857 if Present (External) and then Present (Code) then
6858 Error_Pragma
6859 ("cannot give both External and Code options for pragma%");
6860 end if;
6862 Process_Extended_Import_Export_Exception_Pragma (
6863 Arg_Internal => Internal,
6864 Arg_External => External,
6865 Arg_Form => Form,
6866 Arg_Code => Code);
6868 if not Is_VMS_Exception (Entity (Internal)) then
6869 Set_Imported (Entity (Internal));
6870 end if;
6871 end Import_Exception;
6873 ---------------------
6874 -- Import_Function --
6875 ---------------------
6877 -- pragma Import_Function (
6878 -- [Internal =>] LOCAL_NAME,
6879 -- [, [External =>] EXTERNAL_SYMBOL]
6880 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6881 -- [, [Result_Type =>] SUBTYPE_MARK]
6882 -- [, [Mechanism =>] MECHANISM]
6883 -- [, [Result_Mechanism =>] MECHANISM_NAME]
6884 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6886 -- EXTERNAL_SYMBOL ::=
6887 -- IDENTIFIER
6888 -- | static_string_EXPRESSION
6890 -- PARAMETER_TYPES ::=
6891 -- null
6892 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6894 -- TYPE_DESIGNATOR ::=
6895 -- subtype_NAME
6896 -- | subtype_Name ' Access
6898 -- MECHANISM ::=
6899 -- MECHANISM_NAME
6900 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6902 -- MECHANISM_ASSOCIATION ::=
6903 -- [formal_parameter_NAME =>] MECHANISM_NAME
6905 -- MECHANISM_NAME ::=
6906 -- Value
6907 -- | Reference
6908 -- | Descriptor [([Class =>] CLASS_NAME)]
6910 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6912 when Pragma_Import_Function => Import_Function : declare
6913 Args : Args_List (1 .. 7);
6914 Names : constant Name_List (1 .. 7) := (
6915 Name_Internal,
6916 Name_External,
6917 Name_Parameter_Types,
6918 Name_Result_Type,
6919 Name_Mechanism,
6920 Name_Result_Mechanism,
6921 Name_First_Optional_Parameter);
6923 Internal : Node_Id renames Args (1);
6924 External : Node_Id renames Args (2);
6925 Parameter_Types : Node_Id renames Args (3);
6926 Result_Type : Node_Id renames Args (4);
6927 Mechanism : Node_Id renames Args (5);
6928 Result_Mechanism : Node_Id renames Args (6);
6929 First_Optional_Parameter : Node_Id renames Args (7);
6931 begin
6932 GNAT_Pragma;
6933 Gather_Associations (Names, Args);
6934 Process_Extended_Import_Export_Subprogram_Pragma (
6935 Arg_Internal => Internal,
6936 Arg_External => External,
6937 Arg_Parameter_Types => Parameter_Types,
6938 Arg_Result_Type => Result_Type,
6939 Arg_Mechanism => Mechanism,
6940 Arg_Result_Mechanism => Result_Mechanism,
6941 Arg_First_Optional_Parameter => First_Optional_Parameter);
6942 end Import_Function;
6944 -------------------
6945 -- Import_Object --
6946 -------------------
6948 -- pragma Import_Object (
6949 -- [Internal =>] LOCAL_NAME,
6950 -- [, [External =>] EXTERNAL_SYMBOL]
6951 -- [, [Size =>] EXTERNAL_SYMBOL]);
6953 -- EXTERNAL_SYMBOL ::=
6954 -- IDENTIFIER
6955 -- | static_string_EXPRESSION
6957 when Pragma_Import_Object => Import_Object : declare
6958 Args : Args_List (1 .. 3);
6959 Names : constant Name_List (1 .. 3) := (
6960 Name_Internal,
6961 Name_External,
6962 Name_Size);
6964 Internal : Node_Id renames Args (1);
6965 External : Node_Id renames Args (2);
6966 Size : Node_Id renames Args (3);
6968 begin
6969 GNAT_Pragma;
6970 Gather_Associations (Names, Args);
6971 Process_Extended_Import_Export_Object_Pragma (
6972 Arg_Internal => Internal,
6973 Arg_External => External,
6974 Arg_Size => Size);
6975 end Import_Object;
6977 ----------------------
6978 -- Import_Procedure --
6979 ----------------------
6981 -- pragma Import_Procedure (
6982 -- [Internal =>] LOCAL_NAME,
6983 -- [, [External =>] EXTERNAL_SYMBOL]
6984 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6985 -- [, [Mechanism =>] MECHANISM]
6986 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6988 -- EXTERNAL_SYMBOL ::=
6989 -- IDENTIFIER
6990 -- | static_string_EXPRESSION
6992 -- PARAMETER_TYPES ::=
6993 -- null
6994 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6996 -- TYPE_DESIGNATOR ::=
6997 -- subtype_NAME
6998 -- | subtype_Name ' Access
7000 -- MECHANISM ::=
7001 -- MECHANISM_NAME
7002 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7004 -- MECHANISM_ASSOCIATION ::=
7005 -- [formal_parameter_NAME =>] MECHANISM_NAME
7007 -- MECHANISM_NAME ::=
7008 -- Value
7009 -- | Reference
7010 -- | Descriptor [([Class =>] CLASS_NAME)]
7012 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7014 when Pragma_Import_Procedure => Import_Procedure : declare
7015 Args : Args_List (1 .. 5);
7016 Names : constant Name_List (1 .. 5) := (
7017 Name_Internal,
7018 Name_External,
7019 Name_Parameter_Types,
7020 Name_Mechanism,
7021 Name_First_Optional_Parameter);
7023 Internal : Node_Id renames Args (1);
7024 External : Node_Id renames Args (2);
7025 Parameter_Types : Node_Id renames Args (3);
7026 Mechanism : Node_Id renames Args (4);
7027 First_Optional_Parameter : Node_Id renames Args (5);
7029 begin
7030 GNAT_Pragma;
7031 Gather_Associations (Names, Args);
7032 Process_Extended_Import_Export_Subprogram_Pragma (
7033 Arg_Internal => Internal,
7034 Arg_External => External,
7035 Arg_Parameter_Types => Parameter_Types,
7036 Arg_Mechanism => Mechanism,
7037 Arg_First_Optional_Parameter => First_Optional_Parameter);
7038 end Import_Procedure;
7040 -----------------------------
7041 -- Import_Valued_Procedure --
7042 -----------------------------
7044 -- pragma Import_Valued_Procedure (
7045 -- [Internal =>] LOCAL_NAME,
7046 -- [, [External =>] EXTERNAL_SYMBOL]
7047 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7048 -- [, [Mechanism =>] MECHANISM]
7049 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7051 -- EXTERNAL_SYMBOL ::=
7052 -- IDENTIFIER
7053 -- | static_string_EXPRESSION
7055 -- PARAMETER_TYPES ::=
7056 -- null
7057 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7059 -- TYPE_DESIGNATOR ::=
7060 -- subtype_NAME
7061 -- | subtype_Name ' Access
7063 -- MECHANISM ::=
7064 -- MECHANISM_NAME
7065 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7067 -- MECHANISM_ASSOCIATION ::=
7068 -- [formal_parameter_NAME =>] MECHANISM_NAME
7070 -- MECHANISM_NAME ::=
7071 -- Value
7072 -- | Reference
7073 -- | Descriptor [([Class =>] CLASS_NAME)]
7075 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7077 when Pragma_Import_Valued_Procedure =>
7078 Import_Valued_Procedure : declare
7079 Args : Args_List (1 .. 5);
7080 Names : constant Name_List (1 .. 5) := (
7081 Name_Internal,
7082 Name_External,
7083 Name_Parameter_Types,
7084 Name_Mechanism,
7085 Name_First_Optional_Parameter);
7087 Internal : Node_Id renames Args (1);
7088 External : Node_Id renames Args (2);
7089 Parameter_Types : Node_Id renames Args (3);
7090 Mechanism : Node_Id renames Args (4);
7091 First_Optional_Parameter : Node_Id renames Args (5);
7093 begin
7094 GNAT_Pragma;
7095 Gather_Associations (Names, Args);
7096 Process_Extended_Import_Export_Subprogram_Pragma (
7097 Arg_Internal => Internal,
7098 Arg_External => External,
7099 Arg_Parameter_Types => Parameter_Types,
7100 Arg_Mechanism => Mechanism,
7101 Arg_First_Optional_Parameter => First_Optional_Parameter);
7102 end Import_Valued_Procedure;
7104 ------------------------
7105 -- Initialize_Scalars --
7106 ------------------------
7108 -- pragma Initialize_Scalars;
7110 when Pragma_Initialize_Scalars =>
7111 GNAT_Pragma;
7112 Check_Arg_Count (0);
7113 Check_Valid_Configuration_Pragma;
7114 Check_Restriction (No_Initialize_Scalars, N);
7116 if not Restriction_Active (No_Initialize_Scalars) then
7117 Init_Or_Norm_Scalars := True;
7118 Initialize_Scalars := True;
7119 end if;
7121 ------------
7122 -- Inline --
7123 ------------
7125 -- pragma Inline ( NAME {, NAME} );
7127 when Pragma_Inline =>
7129 -- Pragma is active if inlining option is active
7131 Process_Inline (Inline_Active);
7133 -------------------
7134 -- Inline_Always --
7135 -------------------
7137 -- pragma Inline_Always ( NAME {, NAME} );
7139 when Pragma_Inline_Always =>
7140 Process_Inline (True);
7142 --------------------
7143 -- Inline_Generic --
7144 --------------------
7146 -- pragma Inline_Generic (NAME {, NAME});
7148 when Pragma_Inline_Generic =>
7149 Process_Generic_List;
7151 ----------------------
7152 -- Inspection_Point --
7153 ----------------------
7155 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
7157 when Pragma_Inspection_Point => Inspection_Point : declare
7158 Arg : Node_Id;
7159 Exp : Node_Id;
7161 begin
7162 if Arg_Count > 0 then
7163 Arg := Arg1;
7164 loop
7165 Exp := Expression (Arg);
7166 Analyze (Exp);
7168 if not Is_Entity_Name (Exp)
7169 or else not Is_Object (Entity (Exp))
7170 then
7171 Error_Pragma_Arg ("object name required", Arg);
7172 end if;
7174 Next (Arg);
7175 exit when No (Arg);
7176 end loop;
7177 end if;
7178 end Inspection_Point;
7180 ---------------
7181 -- Interface --
7182 ---------------
7184 -- pragma Interface (
7185 -- convention_IDENTIFIER,
7186 -- local_NAME );
7188 when Pragma_Interface =>
7189 GNAT_Pragma;
7190 Check_Arg_Count (2);
7191 Check_No_Identifiers;
7192 Process_Import_Or_Interface;
7194 --------------------
7195 -- Interface_Name --
7196 --------------------
7198 -- pragma Interface_Name (
7199 -- [ Entity =>] local_NAME
7200 -- [,[External_Name =>] static_string_EXPRESSION ]
7201 -- [,[Link_Name =>] static_string_EXPRESSION ]);
7203 when Pragma_Interface_Name => Interface_Name : declare
7204 Id : Node_Id;
7205 Def_Id : Entity_Id;
7206 Hom_Id : Entity_Id;
7207 Found : Boolean;
7209 begin
7210 GNAT_Pragma;
7211 Check_Arg_Order
7212 ((Name_Entity, Name_External_Name, Name_Link_Name));
7213 Check_At_Least_N_Arguments (2);
7214 Check_At_Most_N_Arguments (3);
7215 Id := Expression (Arg1);
7216 Analyze (Id);
7218 if not Is_Entity_Name (Id) then
7219 Error_Pragma_Arg
7220 ("first argument for pragma% must be entity name", Arg1);
7221 elsif Etype (Id) = Any_Type then
7222 return;
7223 else
7224 Def_Id := Entity (Id);
7225 end if;
7227 -- Special DEC-compatible processing for the object case,
7228 -- forces object to be imported.
7230 if Ekind (Def_Id) = E_Variable then
7231 Kill_Size_Check_Code (Def_Id);
7232 Note_Possible_Modification (Id);
7234 -- Initialization is not allowed for imported variable
7236 if Present (Expression (Parent (Def_Id)))
7237 and then Comes_From_Source (Expression (Parent (Def_Id)))
7238 then
7239 Error_Msg_Sloc := Sloc (Def_Id);
7240 Error_Pragma_Arg
7241 ("no initialization allowed for declaration of& #",
7242 Arg2);
7244 else
7245 -- For compatibility, support VADS usage of providing both
7246 -- pragmas Interface and Interface_Name to obtain the effect
7247 -- of a single Import pragma.
7249 if Is_Imported (Def_Id)
7250 and then Present (First_Rep_Item (Def_Id))
7251 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
7252 and then Chars (First_Rep_Item (Def_Id)) = Name_Interface
7253 then
7254 null;
7255 else
7256 Set_Imported (Def_Id);
7257 end if;
7259 Set_Is_Public (Def_Id);
7260 Process_Interface_Name (Def_Id, Arg2, Arg3);
7261 end if;
7263 -- Otherwise must be subprogram
7265 elsif not Is_Subprogram (Def_Id) then
7266 Error_Pragma_Arg
7267 ("argument of pragma% is not subprogram", Arg1);
7269 else
7270 Check_At_Most_N_Arguments (3);
7271 Hom_Id := Def_Id;
7272 Found := False;
7274 -- Loop through homonyms
7276 loop
7277 Def_Id := Get_Base_Subprogram (Hom_Id);
7279 if Is_Imported (Def_Id) then
7280 Process_Interface_Name (Def_Id, Arg2, Arg3);
7281 Found := True;
7282 end if;
7284 Hom_Id := Homonym (Hom_Id);
7286 exit when No (Hom_Id)
7287 or else Scope (Hom_Id) /= Current_Scope;
7288 end loop;
7290 if not Found then
7291 Error_Pragma_Arg
7292 ("argument of pragma% is not imported subprogram",
7293 Arg1);
7294 end if;
7295 end if;
7296 end Interface_Name;
7298 -----------------------
7299 -- Interrupt_Handler --
7300 -----------------------
7302 -- pragma Interrupt_Handler (handler_NAME);
7304 when Pragma_Interrupt_Handler =>
7305 Check_Ada_83_Warning;
7306 Check_Arg_Count (1);
7307 Check_No_Identifiers;
7309 if No_Run_Time_Mode then
7310 Error_Msg_CRT ("Interrupt_Handler pragma", N);
7311 else
7312 Check_Interrupt_Or_Attach_Handler;
7313 Process_Interrupt_Or_Attach_Handler;
7314 end if;
7316 ------------------------
7317 -- Interrupt_Priority --
7318 ------------------------
7320 -- pragma Interrupt_Priority [(EXPRESSION)];
7322 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
7323 P : constant Node_Id := Parent (N);
7324 Arg : Node_Id;
7326 begin
7327 Check_Ada_83_Warning;
7329 if Arg_Count /= 0 then
7330 Arg := Expression (Arg1);
7331 Check_Arg_Count (1);
7332 Check_No_Identifiers;
7334 -- The expression must be analyzed in the special manner
7335 -- described in "Handling of Default and Per-Object
7336 -- Expressions" in sem.ads.
7338 Analyze_Per_Use_Expression (Arg, RTE (RE_Interrupt_Priority));
7339 end if;
7341 if Nkind (P) /= N_Task_Definition
7342 and then Nkind (P) /= N_Protected_Definition
7343 then
7344 Pragma_Misplaced;
7345 return;
7347 elsif Has_Priority_Pragma (P) then
7348 Error_Pragma ("duplicate pragma% not allowed");
7350 else
7351 Set_Has_Priority_Pragma (P, True);
7352 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7353 end if;
7354 end Interrupt_Priority;
7356 ---------------------
7357 -- Interrupt_State --
7358 ---------------------
7360 -- pragma Interrupt_State (
7361 -- [Name =>] INTERRUPT_ID,
7362 -- [State =>] INTERRUPT_STATE);
7364 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
7365 -- INTERRUPT_STATE => System | Runtime | User
7367 -- Note: if the interrupt id is given as an identifier, then
7368 -- it must be one of the identifiers in Ada.Interrupts.Names.
7369 -- Otherwise it is given as a static integer expression which
7370 -- must be in the range of Ada.Interrupts.Interrupt_ID.
7372 when Pragma_Interrupt_State => Interrupt_State : declare
7374 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
7375 -- This is the entity Ada.Interrupts.Interrupt_ID;
7377 State_Type : Character;
7378 -- Set to 's'/'r'/'u' for System/Runtime/User
7380 IST_Num : Pos;
7381 -- Index to entry in Interrupt_States table
7383 Int_Val : Uint;
7384 -- Value of interrupt
7386 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
7387 -- The first argument to the pragma
7389 Int_Ent : Entity_Id;
7390 -- Interrupt entity in Ada.Interrupts.Names
7392 begin
7393 GNAT_Pragma;
7394 Check_Arg_Order ((Name_Name, Name_State));
7395 Check_Arg_Count (2);
7397 Check_Optional_Identifier (Arg1, Name_Name);
7398 Check_Optional_Identifier (Arg2, Name_State);
7399 Check_Arg_Is_Identifier (Arg2);
7401 -- First argument is identifier
7403 if Nkind (Arg1X) = N_Identifier then
7405 -- Search list of names in Ada.Interrupts.Names
7407 Int_Ent := First_Entity (RTE (RE_Names));
7408 loop
7409 if No (Int_Ent) then
7410 Error_Pragma_Arg ("invalid interrupt name", Arg1);
7412 elsif Chars (Int_Ent) = Chars (Arg1X) then
7413 Int_Val := Expr_Value (Constant_Value (Int_Ent));
7414 exit;
7415 end if;
7417 Next_Entity (Int_Ent);
7418 end loop;
7420 -- First argument is not an identifier, so it must be a
7421 -- static expression of type Ada.Interrupts.Interrupt_ID.
7423 else
7424 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7425 Int_Val := Expr_Value (Arg1X);
7427 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
7428 or else
7429 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
7430 then
7431 Error_Pragma_Arg
7432 ("value not in range of type " &
7433 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
7434 end if;
7435 end if;
7437 -- Check OK state
7439 case Chars (Get_Pragma_Arg (Arg2)) is
7440 when Name_Runtime => State_Type := 'r';
7441 when Name_System => State_Type := 's';
7442 when Name_User => State_Type := 'u';
7444 when others =>
7445 Error_Pragma_Arg ("invalid interrupt state", Arg2);
7446 end case;
7448 -- Check if entry is already stored
7450 IST_Num := Interrupt_States.First;
7451 loop
7452 -- If entry not found, add it
7454 if IST_Num > Interrupt_States.Last then
7455 Interrupt_States.Append
7456 ((Interrupt_Number => UI_To_Int (Int_Val),
7457 Interrupt_State => State_Type,
7458 Pragma_Loc => Loc));
7459 exit;
7461 -- Case of entry for the same entry
7463 elsif Int_Val = Interrupt_States.Table (IST_Num).
7464 Interrupt_Number
7465 then
7466 -- If state matches, done, no need to make redundant entry
7468 exit when
7469 State_Type = Interrupt_States.Table (IST_Num).
7470 Interrupt_State;
7472 -- Otherwise if state does not match, error
7474 Error_Msg_Sloc :=
7475 Interrupt_States.Table (IST_Num).Pragma_Loc;
7476 Error_Pragma_Arg
7477 ("state conflicts with that given at #", Arg2);
7478 exit;
7479 end if;
7481 IST_Num := IST_Num + 1;
7482 end loop;
7483 end Interrupt_State;
7485 ----------------------
7486 -- Java_Constructor --
7487 ----------------------
7489 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
7491 when Pragma_Java_Constructor => Java_Constructor : declare
7492 Id : Entity_Id;
7493 Def_Id : Entity_Id;
7494 Hom_Id : Entity_Id;
7496 begin
7497 GNAT_Pragma;
7498 Check_Arg_Count (1);
7499 Check_Optional_Identifier (Arg1, Name_Entity);
7500 Check_Arg_Is_Local_Name (Arg1);
7502 Id := Expression (Arg1);
7503 Find_Program_Unit_Name (Id);
7505 -- If we did not find the name, we are done
7507 if Etype (Id) = Any_Type then
7508 return;
7509 end if;
7511 Hom_Id := Entity (Id);
7513 -- Loop through homonyms
7515 loop
7516 Def_Id := Get_Base_Subprogram (Hom_Id);
7518 -- The constructor is required to be a function returning
7519 -- an access type whose designated type has convention Java.
7521 if Ekind (Def_Id) = E_Function
7522 and then Ekind (Etype (Def_Id)) in Access_Kind
7523 and then
7524 (Atree.Convention
7525 (Designated_Type (Etype (Def_Id))) = Convention_Java
7526 or else
7527 Atree.Convention
7528 (Root_Type (Designated_Type (Etype (Def_Id))))
7529 = Convention_Java)
7530 then
7531 Set_Is_Constructor (Def_Id);
7532 Set_Convention (Def_Id, Convention_Java);
7534 else
7535 Error_Pragma_Arg
7536 ("pragma% requires function returning a 'Java access type",
7537 Arg1);
7538 end if;
7540 Hom_Id := Homonym (Hom_Id);
7542 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
7543 end loop;
7544 end Java_Constructor;
7546 ----------------------
7547 -- Java_Interface --
7548 ----------------------
7550 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
7552 when Pragma_Java_Interface => Java_Interface : declare
7553 Arg : Node_Id;
7554 Typ : Entity_Id;
7556 begin
7557 GNAT_Pragma;
7558 Check_Arg_Count (1);
7559 Check_Optional_Identifier (Arg1, Name_Entity);
7560 Check_Arg_Is_Local_Name (Arg1);
7562 Arg := Expression (Arg1);
7563 Analyze (Arg);
7565 if Etype (Arg) = Any_Type then
7566 return;
7567 end if;
7569 if not Is_Entity_Name (Arg)
7570 or else not Is_Type (Entity (Arg))
7571 then
7572 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7573 end if;
7575 Typ := Underlying_Type (Entity (Arg));
7577 -- For now we simply check some of the semantic constraints
7578 -- on the type. This currently leaves out some restrictions
7579 -- on interface types, namely that the parent type must be
7580 -- java.lang.Object.Typ and that all primitives of the type
7581 -- should be declared abstract. ???
7583 if not Is_Tagged_Type (Typ) or else not Is_Abstract (Typ) then
7584 Error_Pragma_Arg ("pragma% requires an abstract "
7585 & "tagged type", Arg1);
7587 elsif not Has_Discriminants (Typ)
7588 or else Ekind (Etype (First_Discriminant (Typ)))
7589 /= E_Anonymous_Access_Type
7590 or else
7591 not Is_Class_Wide_Type
7592 (Designated_Type (Etype (First_Discriminant (Typ))))
7593 then
7594 Error_Pragma_Arg
7595 ("type must have a class-wide access discriminant", Arg1);
7596 end if;
7597 end Java_Interface;
7599 ----------------
7600 -- Keep_Names --
7601 ----------------
7603 -- pragma Keep_Names ([On => ] local_NAME);
7605 when Pragma_Keep_Names => Keep_Names : declare
7606 Arg : Node_Id;
7608 begin
7609 GNAT_Pragma;
7610 Check_Arg_Count (1);
7611 Check_Optional_Identifier (Arg1, Name_On);
7612 Check_Arg_Is_Local_Name (Arg1);
7614 Arg := Expression (Arg1);
7615 Analyze (Arg);
7617 if Etype (Arg) = Any_Type then
7618 return;
7619 end if;
7621 if not Is_Entity_Name (Arg)
7622 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
7623 then
7624 Error_Pragma_Arg
7625 ("pragma% requires a local enumeration type", Arg1);
7626 end if;
7628 Set_Discard_Names (Entity (Arg), False);
7629 end Keep_Names;
7631 -------------
7632 -- License --
7633 -------------
7635 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
7637 when Pragma_License =>
7638 GNAT_Pragma;
7639 Check_Arg_Count (1);
7640 Check_No_Identifiers;
7641 Check_Valid_Configuration_Pragma;
7642 Check_Arg_Is_Identifier (Arg1);
7644 declare
7645 Sind : constant Source_File_Index :=
7646 Source_Index (Current_Sem_Unit);
7648 begin
7649 case Chars (Get_Pragma_Arg (Arg1)) is
7650 when Name_GPL =>
7651 Set_License (Sind, GPL);
7653 when Name_Modified_GPL =>
7654 Set_License (Sind, Modified_GPL);
7656 when Name_Restricted =>
7657 Set_License (Sind, Restricted);
7659 when Name_Unrestricted =>
7660 Set_License (Sind, Unrestricted);
7662 when others =>
7663 Error_Pragma_Arg ("invalid license name", Arg1);
7664 end case;
7665 end;
7667 ---------------
7668 -- Link_With --
7669 ---------------
7671 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
7673 when Pragma_Link_With => Link_With : declare
7674 Arg : Node_Id;
7676 begin
7677 GNAT_Pragma;
7679 if Operating_Mode = Generate_Code
7680 and then In_Extended_Main_Source_Unit (N)
7681 then
7682 Check_At_Least_N_Arguments (1);
7683 Check_No_Identifiers;
7684 Check_Is_In_Decl_Part_Or_Package_Spec;
7685 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7686 Start_String;
7688 Arg := Arg1;
7689 while Present (Arg) loop
7690 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7692 -- Store argument, converting sequences of spaces
7693 -- to a single null character (this is one of the
7694 -- differences in processing between Link_With
7695 -- and Linker_Options).
7697 declare
7698 C : constant Char_Code := Get_Char_Code (' ');
7699 S : constant String_Id :=
7700 Strval (Expr_Value_S (Expression (Arg)));
7701 L : constant Nat := String_Length (S);
7702 F : Nat := 1;
7704 procedure Skip_Spaces;
7705 -- Advance F past any spaces
7707 procedure Skip_Spaces is
7708 begin
7709 while F <= L and then Get_String_Char (S, F) = C loop
7710 F := F + 1;
7711 end loop;
7712 end Skip_Spaces;
7714 begin
7715 Skip_Spaces; -- skip leading spaces
7717 -- Loop through characters, changing any embedded
7718 -- sequence of spaces to a single null character
7719 -- (this is how Link_With/Linker_Options differ)
7721 while F <= L loop
7722 if Get_String_Char (S, F) = C then
7723 Skip_Spaces;
7724 exit when F > L;
7725 Store_String_Char (ASCII.NUL);
7727 else
7728 Store_String_Char (Get_String_Char (S, F));
7729 F := F + 1;
7730 end if;
7731 end loop;
7732 end;
7734 Arg := Next (Arg);
7736 if Present (Arg) then
7737 Store_String_Char (ASCII.NUL);
7738 end if;
7739 end loop;
7741 Store_Linker_Option_String (End_String);
7742 end if;
7743 end Link_With;
7745 ------------------
7746 -- Linker_Alias --
7747 ------------------
7749 -- pragma Linker_Alias (
7750 -- [Entity =>] LOCAL_NAME
7751 -- [Target =>] static_string_EXPRESSION);
7753 when Pragma_Linker_Alias =>
7754 GNAT_Pragma;
7755 Check_Arg_Order ((Name_Entity, Name_Target));
7756 Check_Arg_Count (2);
7757 Check_Optional_Identifier (Arg1, Name_Entity);
7758 Check_Optional_Identifier (Arg2, Name_Target);
7759 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7760 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7762 -- The only processing required is to link this item on to the
7763 -- list of rep items for the given entity. This is accomplished
7764 -- by the call to Rep_Item_Too_Late (when no error is detected
7765 -- and False is returned).
7767 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7768 return;
7769 else
7770 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7771 end if;
7773 ------------------------
7774 -- Linker_Constructor --
7775 ------------------------
7777 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
7779 -- Code is shared with Linker_Destructor
7781 -----------------------
7782 -- Linker_Destructor --
7783 -----------------------
7785 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
7787 when Pragma_Linker_Constructor |
7788 Pragma_Linker_Destructor =>
7789 Linker_Constructor : declare
7790 Arg1_X : Node_Id;
7791 Proc : Entity_Id;
7793 begin
7794 GNAT_Pragma;
7795 Check_Arg_Count (1);
7796 Check_No_Identifiers;
7797 Check_Arg_Is_Local_Name (Arg1);
7798 Arg1_X := Expression (Arg1);
7799 Analyze (Arg1_X);
7800 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
7802 if not Is_Library_Level_Entity (Proc) then
7803 Error_Pragma_Arg
7804 ("argument for pragma% must be library level entity", Arg1);
7805 end if;
7807 -- The only processing required is to link this item on to the
7808 -- list of rep items for the given entity. This is accomplished
7809 -- by the call to Rep_Item_Too_Late (when no error is detected
7810 -- and False is returned).
7812 if Rep_Item_Too_Late (Proc, N) then
7813 return;
7814 else
7815 Set_Has_Gigi_Rep_Item (Proc);
7816 end if;
7817 end Linker_Constructor;
7819 --------------------
7820 -- Linker_Options --
7821 --------------------
7823 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
7825 when Pragma_Linker_Options => Linker_Options : declare
7826 Arg : Node_Id;
7828 begin
7829 Check_Ada_83_Warning;
7830 Check_No_Identifiers;
7831 Check_Arg_Count (1);
7832 Check_Is_In_Decl_Part_Or_Package_Spec;
7834 if Operating_Mode = Generate_Code
7835 and then In_Extended_Main_Source_Unit (N)
7836 then
7837 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7838 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
7840 Arg := Arg2;
7841 while Present (Arg) loop
7842 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7843 Store_String_Char (ASCII.NUL);
7844 Store_String_Chars
7845 (Strval (Expr_Value_S (Expression (Arg))));
7846 Arg := Next (Arg);
7847 end loop;
7849 Store_Linker_Option_String (End_String);
7850 end if;
7851 end Linker_Options;
7853 --------------------
7854 -- Linker_Section --
7855 --------------------
7857 -- pragma Linker_Section (
7858 -- [Entity =>] LOCAL_NAME
7859 -- [Section =>] static_string_EXPRESSION);
7861 when Pragma_Linker_Section =>
7862 GNAT_Pragma;
7863 Check_Arg_Order ((Name_Entity, Name_Section));
7864 Check_Arg_Count (2);
7865 Check_Optional_Identifier (Arg1, Name_Entity);
7866 Check_Optional_Identifier (Arg2, Name_Section);
7867 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7868 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7870 -- The only processing required is to link this item on to the
7871 -- list of rep items for the given entity. This is accomplished
7872 -- by the call to Rep_Item_Too_Late (when no error is detected
7873 -- and False is returned).
7875 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7876 return;
7877 else
7878 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7879 end if;
7881 ----------
7882 -- List --
7883 ----------
7885 -- pragma List (On | Off)
7887 -- There is nothing to do here, since we did all the processing
7888 -- for this pragma in Par.Prag (so that it works properly even in
7889 -- syntax only mode)
7891 when Pragma_List =>
7892 null;
7894 --------------------
7895 -- Locking_Policy --
7896 --------------------
7898 -- pragma Locking_Policy (policy_IDENTIFIER);
7900 when Pragma_Locking_Policy => declare
7901 LP : Character;
7903 begin
7904 Check_Ada_83_Warning;
7905 Check_Arg_Count (1);
7906 Check_No_Identifiers;
7907 Check_Arg_Is_Locking_Policy (Arg1);
7908 Check_Valid_Configuration_Pragma;
7909 Get_Name_String (Chars (Expression (Arg1)));
7910 LP := Fold_Upper (Name_Buffer (1));
7912 if Locking_Policy /= ' '
7913 and then Locking_Policy /= LP
7914 then
7915 Error_Msg_Sloc := Locking_Policy_Sloc;
7916 Error_Pragma ("locking policy incompatible with policy#");
7918 -- Set new policy, but always preserve System_Location since
7919 -- we like the error message with the run time name.
7921 else
7922 Locking_Policy := LP;
7924 if Locking_Policy_Sloc /= System_Location then
7925 Locking_Policy_Sloc := Loc;
7926 end if;
7927 end if;
7928 end;
7930 ----------------
7931 -- Long_Float --
7932 ----------------
7934 -- pragma Long_Float (D_Float | G_Float);
7936 when Pragma_Long_Float =>
7937 GNAT_Pragma;
7938 Check_Valid_Configuration_Pragma;
7939 Check_Arg_Count (1);
7940 Check_No_Identifier (Arg1);
7941 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
7943 if not OpenVMS_On_Target then
7944 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
7945 end if;
7947 -- D_Float case
7949 if Chars (Expression (Arg1)) = Name_D_Float then
7950 if Opt.Float_Format_Long = 'G' then
7951 Error_Pragma ("G_Float previously specified");
7952 end if;
7954 Opt.Float_Format_Long := 'D';
7956 -- G_Float case (this is the default, does not need overriding)
7958 else
7959 if Opt.Float_Format_Long = 'D' then
7960 Error_Pragma ("D_Float previously specified");
7961 end if;
7963 Opt.Float_Format_Long := 'G';
7964 end if;
7966 Set_Standard_Fpt_Formats;
7968 -----------------------
7969 -- Machine_Attribute --
7970 -----------------------
7972 -- pragma Machine_Attribute (
7973 -- [Entity =>] LOCAL_NAME,
7974 -- [Attribute_Name =>] static_string_EXPRESSION
7975 -- [,[Info =>] static_string_EXPRESSION] );
7977 when Pragma_Machine_Attribute => Machine_Attribute : declare
7978 Def_Id : Entity_Id;
7980 begin
7981 GNAT_Pragma;
7982 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
7984 if Arg_Count = 3 then
7985 Check_Optional_Identifier (Arg3, Name_Info);
7986 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
7987 else
7988 Check_Arg_Count (2);
7989 end if;
7991 Check_Optional_Identifier (Arg1, Name_Entity);
7992 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
7993 Check_Arg_Is_Local_Name (Arg1);
7994 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7995 Def_Id := Entity (Expression (Arg1));
7997 if Is_Access_Type (Def_Id) then
7998 Def_Id := Designated_Type (Def_Id);
7999 end if;
8001 if Rep_Item_Too_Early (Def_Id, N) then
8002 return;
8003 end if;
8005 Def_Id := Underlying_Type (Def_Id);
8007 -- The only processing required is to link this item on to the
8008 -- list of rep items for the given entity. This is accomplished
8009 -- by the call to Rep_Item_Too_Late (when no error is detected
8010 -- and False is returned).
8012 if Rep_Item_Too_Late (Def_Id, N) then
8013 return;
8014 else
8015 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8016 end if;
8017 end Machine_Attribute;
8019 ----------
8020 -- Main --
8021 ----------
8023 -- pragma Main_Storage
8024 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
8026 -- MAIN_STORAGE_OPTION ::=
8027 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
8028 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
8030 when Pragma_Main => Main : declare
8031 Args : Args_List (1 .. 3);
8032 Names : constant Name_List (1 .. 3) := (
8033 Name_Stack_Size,
8034 Name_Task_Stack_Size_Default,
8035 Name_Time_Slicing_Enabled);
8037 Nod : Node_Id;
8039 begin
8040 GNAT_Pragma;
8041 Gather_Associations (Names, Args);
8043 for J in 1 .. 2 loop
8044 if Present (Args (J)) then
8045 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8046 end if;
8047 end loop;
8049 if Present (Args (3)) then
8050 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
8051 end if;
8053 Nod := Next (N);
8054 while Present (Nod) loop
8055 if Nkind (Nod) = N_Pragma
8056 and then Chars (Nod) = Name_Main
8057 then
8058 Error_Msg_Name_1 := Chars (N);
8059 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8060 end if;
8062 Next (Nod);
8063 end loop;
8064 end Main;
8066 ------------------
8067 -- Main_Storage --
8068 ------------------
8070 -- pragma Main_Storage
8071 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
8073 -- MAIN_STORAGE_OPTION ::=
8074 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
8075 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
8077 when Pragma_Main_Storage => Main_Storage : declare
8078 Args : Args_List (1 .. 2);
8079 Names : constant Name_List (1 .. 2) := (
8080 Name_Working_Storage,
8081 Name_Top_Guard);
8083 Nod : Node_Id;
8085 begin
8086 GNAT_Pragma;
8087 Gather_Associations (Names, Args);
8089 for J in 1 .. 2 loop
8090 if Present (Args (J)) then
8091 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8092 end if;
8093 end loop;
8095 Check_In_Main_Program;
8097 Nod := Next (N);
8098 while Present (Nod) loop
8099 if Nkind (Nod) = N_Pragma
8100 and then Chars (Nod) = Name_Main_Storage
8101 then
8102 Error_Msg_Name_1 := Chars (N);
8103 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8104 end if;
8106 Next (Nod);
8107 end loop;
8108 end Main_Storage;
8110 -----------------
8111 -- Memory_Size --
8112 -----------------
8114 -- pragma Memory_Size (NUMERIC_LITERAL)
8116 when Pragma_Memory_Size =>
8117 GNAT_Pragma;
8119 -- Memory size is simply ignored
8121 Check_No_Identifiers;
8122 Check_Arg_Count (1);
8123 Check_Arg_Is_Integer_Literal (Arg1);
8125 ---------------
8126 -- No_Return --
8127 ---------------
8129 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
8131 when Pragma_No_Return => No_Return : declare
8132 Id : Node_Id;
8133 E : Entity_Id;
8134 Found : Boolean;
8135 Arg : Node_Id;
8137 begin
8138 GNAT_Pragma;
8139 Check_At_Least_N_Arguments (1);
8141 -- Loop through arguments of pragma
8143 Arg := Arg1;
8144 while Present (Arg) loop
8145 Check_Arg_Is_Local_Name (Arg);
8146 Id := Expression (Arg);
8147 Analyze (Id);
8149 if not Is_Entity_Name (Id) then
8150 Error_Pragma_Arg ("entity name required", Arg);
8151 end if;
8153 if Etype (Id) = Any_Type then
8154 raise Pragma_Exit;
8155 end if;
8157 -- Loop to find matching procedures
8159 E := Entity (Id);
8160 Found := False;
8161 while Present (E)
8162 and then Scope (E) = Current_Scope
8163 loop
8164 if Ekind (E) = E_Procedure
8165 or else Ekind (E) = E_Generic_Procedure
8166 then
8167 Set_No_Return (E);
8168 Found := True;
8169 end if;
8171 E := Homonym (E);
8172 end loop;
8174 if not Found then
8175 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
8176 end if;
8178 Next (Arg);
8179 end loop;
8180 end No_Return;
8182 ------------------------
8183 -- No_Strict_Aliasing --
8184 ------------------------
8186 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
8188 when Pragma_No_Strict_Aliasing => No_Strict_Alias : declare
8189 E_Id : Entity_Id;
8191 begin
8192 GNAT_Pragma;
8193 Check_At_Most_N_Arguments (1);
8195 if Arg_Count = 0 then
8196 Check_Valid_Configuration_Pragma;
8197 Opt.No_Strict_Aliasing := True;
8199 else
8200 Check_Optional_Identifier (Arg2, Name_Entity);
8201 Check_Arg_Is_Local_Name (Arg1);
8202 E_Id := Entity (Expression (Arg1));
8204 if E_Id = Any_Type then
8205 return;
8206 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
8207 Error_Pragma_Arg ("pragma% requires access type", Arg1);
8208 end if;
8210 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
8211 end if;
8212 end No_Strict_Alias;
8214 -----------------
8215 -- Obsolescent --
8216 -----------------
8218 -- pragma Obsolescent [(static_string_EXPRESSION [, Ada_05])];
8220 when Pragma_Obsolescent => Obsolescent : declare
8221 Subp : Node_Or_Entity_Id;
8222 S : String_Id;
8223 Active : Boolean := True;
8225 procedure Check_Obsolete_Subprogram;
8226 -- Checks if Subp is a subprogram declaration node, and if so
8227 -- replaces Subp by the defining entity of the subprogram. If not,
8228 -- issues an error message
8230 ------------------------------
8231 -- Check_Obsolete_Subprogram--
8232 ------------------------------
8234 procedure Check_Obsolete_Subprogram is
8235 begin
8236 if Nkind (Subp) /= N_Subprogram_Declaration then
8237 Error_Pragma
8238 ("pragma% misplaced, must immediately " &
8239 "follow subprogram/package declaration");
8240 else
8241 Subp := Defining_Entity (Subp);
8242 end if;
8243 end Check_Obsolete_Subprogram;
8245 -- Start of processing for pragma Obsolescent
8247 begin
8248 GNAT_Pragma;
8249 Check_At_Most_N_Arguments (2);
8250 Check_No_Identifiers;
8252 -- Check OK placement
8254 -- First possibility is within a declarative region, where the
8255 -- pragma immediately follows a subprogram declaration.
8257 if Present (Prev (N)) then
8258 Subp := Prev (N);
8259 Check_Obsolete_Subprogram;
8261 -- Second possibility, stand alone subprogram declaration with the
8262 -- pragma immediately following the declaration.
8264 elsif No (Prev (N))
8265 and then Nkind (Parent (N)) = N_Compilation_Unit_Aux
8266 then
8267 Subp := Unit (Parent (Parent (N)));
8268 Check_Obsolete_Subprogram;
8270 -- Only other possibility is library unit placement for package
8272 else
8273 Subp := Find_Lib_Unit_Name;
8275 if Ekind (Subp) /= E_Package
8276 and then Ekind (Subp) /= E_Generic_Package
8277 then
8278 Check_Obsolete_Subprogram;
8279 end if;
8280 end if;
8282 -- If OK placement, acquire arguments
8284 if Arg_Count >= 1 then
8286 -- Deal with static string argument
8288 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8289 S := Strval (Expression (Arg1));
8291 for J in 1 .. String_Length (S) loop
8292 if not In_Character_Range (Get_String_Char (S, J)) then
8293 Error_Pragma_Arg
8294 ("pragma% argument does not allow wide characters",
8295 Arg1);
8296 end if;
8297 end loop;
8299 Set_Obsolescent_Warning (Subp, Expression (Arg1));
8301 -- Check for Ada_05 parameter
8303 if Arg_Count /= 1 then
8304 Check_Arg_Count (2);
8306 declare
8307 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
8309 begin
8310 Check_Arg_Is_Identifier (Argx);
8312 if Chars (Argx) /= Name_Ada_05 then
8313 Error_Msg_Name_2 := Name_Ada_05;
8314 Error_Pragma_Arg
8315 ("only allowed argument for pragma% is %", Argx);
8316 end if;
8318 if Ada_Version_Explicit < Ada_05
8319 or else not Warn_On_Ada_2005_Compatibility
8320 then
8321 Active := False;
8322 end if;
8323 end;
8324 end if;
8325 end if;
8327 -- Set flag if pragma active
8329 if Active then
8330 Set_Is_Obsolescent (Subp);
8331 end if;
8332 end Obsolescent;
8334 -----------------
8335 -- No_Run_Time --
8336 -----------------
8338 -- pragma No_Run_Time
8340 -- Note: this pragma is retained for backwards compatibiltiy.
8341 -- See body of Rtsfind for full details on its handling.
8343 when Pragma_No_Run_Time =>
8344 GNAT_Pragma;
8345 Check_Valid_Configuration_Pragma;
8346 Check_Arg_Count (0);
8348 No_Run_Time_Mode := True;
8349 Configurable_Run_Time_Mode := True;
8351 declare
8352 Word32 : constant Boolean := Ttypes.System_Word_Size = 32;
8353 begin
8354 if Word32 then
8355 Duration_32_Bits_On_Target := True;
8356 end if;
8357 end;
8359 Set_Restriction (No_Finalization, N);
8360 Set_Restriction (No_Exception_Handlers, N);
8361 Set_Restriction (Max_Tasks, N, 0);
8362 Set_Restriction (No_Tasking, N);
8364 -----------------------
8365 -- Normalize_Scalars --
8366 -----------------------
8368 -- pragma Normalize_Scalars;
8370 when Pragma_Normalize_Scalars =>
8371 Check_Ada_83_Warning;
8372 Check_Arg_Count (0);
8373 Check_Valid_Configuration_Pragma;
8374 Normalize_Scalars := True;
8375 Init_Or_Norm_Scalars := True;
8377 --------------
8378 -- Optimize --
8379 --------------
8381 -- pragma Optimize (Time | Space);
8383 -- The actual check for optimize is done in Gigi. Note that this
8384 -- pragma does not actually change the optimization setting, it
8385 -- simply checks that it is consistent with the pragma.
8387 when Pragma_Optimize =>
8388 Check_No_Identifiers;
8389 Check_Arg_Count (1);
8390 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
8392 -------------------------
8393 -- Optional_Overriding --
8394 -------------------------
8396 -- These pragmas are treated as part of the previous subprogram
8397 -- declaration, and analyzed immediately after it (see sem_ch6,
8398 -- Check_Overriding_Operation). If the pragma has not been analyzed
8399 -- yet, it appears in the wrong place.
8401 when Pragma_Optional_Overriding =>
8402 Error_Msg_N ("pragma must appear immediately after subprogram", N);
8404 ----------
8405 -- Pack --
8406 ----------
8408 -- pragma Pack (first_subtype_LOCAL_NAME);
8410 when Pragma_Pack => Pack : declare
8411 Assoc : constant Node_Id := Arg1;
8412 Type_Id : Node_Id;
8413 Typ : Entity_Id;
8415 begin
8416 Check_No_Identifiers;
8417 Check_Arg_Count (1);
8418 Check_Arg_Is_Local_Name (Arg1);
8420 Type_Id := Expression (Assoc);
8421 Find_Type (Type_Id);
8422 Typ := Entity (Type_Id);
8424 if Typ = Any_Type
8425 or else Rep_Item_Too_Early (Typ, N)
8426 then
8427 return;
8428 else
8429 Typ := Underlying_Type (Typ);
8430 end if;
8432 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
8433 Error_Pragma ("pragma% must specify array or record type");
8434 end if;
8436 Check_First_Subtype (Arg1);
8438 if Has_Pragma_Pack (Typ) then
8439 Error_Pragma ("duplicate pragma%, only one allowed");
8441 -- Array type
8443 elsif Is_Array_Type (Typ) then
8445 -- Pack not allowed for aliased or atomic components
8447 if Has_Aliased_Components (Base_Type (Typ)) then
8448 Error_Pragma
8449 ("pragma% ignored, cannot pack aliased components?");
8451 elsif Has_Atomic_Components (Typ)
8452 or else Is_Atomic (Component_Type (Typ))
8453 then
8454 Error_Pragma
8455 ("?pragma% ignored, cannot pack atomic components");
8456 end if;
8458 -- If we had an explicit component size given, then we do not
8459 -- let Pack override this given size. We also give a warning
8460 -- that Pack is being ignored unless we can tell for sure that
8461 -- the Pack would not have had any effect anyway.
8463 if Has_Component_Size_Clause (Typ) then
8464 if Known_Static_RM_Size (Component_Type (Typ))
8465 and then
8466 RM_Size (Component_Type (Typ)) = Component_Size (Typ)
8467 then
8468 null;
8469 else
8470 Error_Pragma
8471 ("?pragma% ignored, explicit component size given");
8472 end if;
8474 -- If no prior array component size given, Pack is effective
8476 else
8477 if not Rep_Item_Too_Late (Typ, N) then
8478 Set_Is_Packed (Base_Type (Typ));
8479 Set_Has_Pragma_Pack (Base_Type (Typ));
8480 Set_Has_Non_Standard_Rep (Base_Type (Typ));
8481 end if;
8482 end if;
8484 -- For record types, the pack is always effective
8486 else pragma Assert (Is_Record_Type (Typ));
8487 if not Rep_Item_Too_Late (Typ, N) then
8488 Set_Has_Pragma_Pack (Base_Type (Typ));
8489 Set_Is_Packed (Base_Type (Typ));
8490 Set_Has_Non_Standard_Rep (Base_Type (Typ));
8491 end if;
8492 end if;
8493 end Pack;
8495 ----------
8496 -- Page --
8497 ----------
8499 -- pragma Page;
8501 -- There is nothing to do here, since we did all the processing
8502 -- for this pragma in Par.Prag (so that it works properly even in
8503 -- syntax only mode)
8505 when Pragma_Page =>
8506 null;
8508 -------------
8509 -- Passive --
8510 -------------
8512 -- pragma Passive [(PASSIVE_FORM)];
8514 -- PASSIVE_FORM ::= Semaphore | No
8516 when Pragma_Passive =>
8517 GNAT_Pragma;
8519 if Nkind (Parent (N)) /= N_Task_Definition then
8520 Error_Pragma ("pragma% must be within task definition");
8521 end if;
8523 if Arg_Count /= 0 then
8524 Check_Arg_Count (1);
8525 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
8526 end if;
8528 -------------
8529 -- Polling --
8530 -------------
8532 -- pragma Polling (ON | OFF);
8534 when Pragma_Polling =>
8535 GNAT_Pragma;
8536 Check_Arg_Count (1);
8537 Check_No_Identifiers;
8538 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8539 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
8541 --------------------
8542 -- Persistent_BSS --
8543 --------------------
8545 when Pragma_Persistent_BSS => Persistent_BSS : declare
8546 Decl : Node_Id;
8547 Ent : Entity_Id;
8548 Prag : Node_Id;
8550 begin
8551 GNAT_Pragma;
8552 Check_At_Most_N_Arguments (1);
8554 -- Case of application to specific object (one argument)
8556 if Arg_Count = 1 then
8557 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8559 if not Is_Entity_Name (Expression (Arg1))
8560 or else
8561 (Ekind (Entity (Expression (Arg1))) /= E_Variable
8562 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
8563 then
8564 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
8565 end if;
8567 Ent := Entity (Expression (Arg1));
8568 Decl := Parent (Ent);
8570 if Rep_Item_Too_Late (Ent, N) then
8571 return;
8572 end if;
8574 if Present (Expression (Decl)) then
8575 Error_Pragma_Arg
8576 ("object for pragma% cannot have initialization", Arg1);
8577 end if;
8579 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
8580 Error_Pragma_Arg
8581 ("object type for pragma% is not potentially persistent",
8582 Arg1);
8583 end if;
8585 Prag :=
8586 Make_Linker_Section_Pragma
8587 (Ent, Sloc (N), ".persistent.bss");
8588 Insert_After (N, Prag);
8589 Analyze (Prag);
8591 -- Case of use as configuration pragma with no arguments
8593 else
8594 Check_Valid_Configuration_Pragma;
8595 Persistent_BSS_Mode := True;
8596 end if;
8597 end Persistent_BSS;
8599 ------------------
8600 -- Preelaborate --
8601 ------------------
8603 -- pragma Preelaborate [(library_unit_NAME)];
8605 -- Set the flag Is_Preelaborated of program unit name entity
8607 when Pragma_Preelaborate => Preelaborate : declare
8608 Pa : constant Node_Id := Parent (N);
8609 Pk : constant Node_Kind := Nkind (Pa);
8610 Ent : Entity_Id;
8612 begin
8613 Check_Ada_83_Warning;
8614 Check_Valid_Library_Unit_Pragma;
8616 if Nkind (N) = N_Null_Statement then
8617 return;
8618 end if;
8620 Ent := Find_Lib_Unit_Name;
8622 -- This filters out pragmas inside generic parent then
8623 -- show up inside instantiation
8625 if Present (Ent)
8626 and then not (Pk = N_Package_Specification
8627 and then Present (Generic_Parent (Pa)))
8628 then
8629 if not Debug_Flag_U then
8630 Set_Is_Preelaborated (Ent);
8631 Set_Suppress_Elaboration_Warnings (Ent);
8632 end if;
8633 end if;
8634 end Preelaborate;
8636 ---------------------
8637 -- Preelaborate_05 --
8638 ---------------------
8640 -- pragma Preelaborate_05 [(library_unit_NAME)];
8642 -- This pragma is useable only in GNAT_Mode, where it is used like
8643 -- pragma Preelaborate but it is only effective in Ada 2005 mode
8644 -- (otherwise it is ignored). This is used to implement AI-362 which
8645 -- recategorizes some run-time packages in Ada 2005 mode.
8647 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
8648 Ent : Entity_Id;
8650 begin
8651 GNAT_Pragma;
8652 Check_Valid_Library_Unit_Pragma;
8654 if not GNAT_Mode then
8655 Error_Pragma ("pragma% only available in GNAT mode");
8656 end if;
8658 if Nkind (N) = N_Null_Statement then
8659 return;
8660 end if;
8662 -- This is one of the few cases where we need to test the value of
8663 -- Ada_Version_Explicit rather than Ada_Version (which is always
8664 -- set to Ada_05 in a predefined unit), we need to know the
8665 -- explicit version set to know if this pragma is active.
8667 if Ada_Version_Explicit >= Ada_05 then
8668 Ent := Find_Lib_Unit_Name;
8669 Set_Is_Preelaborated (Ent);
8670 Set_Suppress_Elaboration_Warnings (Ent);
8671 end if;
8672 end Preelaborate_05;
8674 --------------
8675 -- Priority --
8676 --------------
8678 -- pragma Priority (EXPRESSION);
8680 when Pragma_Priority => Priority : declare
8681 P : constant Node_Id := Parent (N);
8682 Arg : Node_Id;
8684 begin
8685 Check_No_Identifiers;
8686 Check_Arg_Count (1);
8688 -- Subprogram case
8690 if Nkind (P) = N_Subprogram_Body then
8691 Check_In_Main_Program;
8693 Arg := Expression (Arg1);
8694 Analyze_And_Resolve (Arg, Standard_Integer);
8696 -- Must be static
8698 if not Is_Static_Expression (Arg) then
8699 Flag_Non_Static_Expr
8700 ("main subprogram priority is not static!", Arg);
8701 raise Pragma_Exit;
8703 -- If constraint error, then we already signalled an error
8705 elsif Raises_Constraint_Error (Arg) then
8706 null;
8708 -- Otherwise check in range
8710 else
8711 declare
8712 Val : constant Uint := Expr_Value (Arg);
8714 begin
8715 if Val < 0
8716 or else Val > Expr_Value (Expression
8717 (Parent (RTE (RE_Max_Priority))))
8718 then
8719 Error_Pragma_Arg
8720 ("main subprogram priority is out of range", Arg1);
8721 end if;
8722 end;
8723 end if;
8725 Set_Main_Priority
8726 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8728 -- Task or Protected, must be of type Integer
8730 elsif Nkind (P) = N_Protected_Definition
8731 or else
8732 Nkind (P) = N_Task_Definition
8733 then
8734 Arg := Expression (Arg1);
8736 -- The expression must be analyzed in the special manner
8737 -- described in "Handling of Default and Per-Object
8738 -- Expressions" in sem.ads.
8740 Analyze_Per_Use_Expression (Arg, Standard_Integer);
8742 if not Is_Static_Expression (Arg) then
8743 Check_Restriction (Static_Priorities, Arg);
8744 end if;
8746 -- Anything else is incorrect
8748 else
8749 Pragma_Misplaced;
8750 end if;
8752 if Has_Priority_Pragma (P) then
8753 Error_Pragma ("duplicate pragma% not allowed");
8754 else
8755 Set_Has_Priority_Pragma (P, True);
8757 if Nkind (P) = N_Protected_Definition
8758 or else
8759 Nkind (P) = N_Task_Definition
8760 then
8761 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8762 -- exp_ch9 should use this ???
8763 end if;
8764 end if;
8765 end Priority;
8767 -------------
8768 -- Profile --
8769 -------------
8771 -- pragma Profile (profile_IDENTIFIER);
8773 -- profile_IDENTIFIER => Protected | Ravenscar
8775 when Pragma_Profile =>
8776 Check_Arg_Count (1);
8777 Check_Valid_Configuration_Pragma;
8778 Check_No_Identifiers;
8780 declare
8781 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8782 begin
8783 if Chars (Argx) = Name_Ravenscar then
8784 Set_Ravenscar_Profile (N);
8786 elsif Chars (Argx) = Name_Restricted then
8787 Set_Profile_Restrictions (Restricted, N, Warn => False);
8788 else
8789 Error_Pragma_Arg ("& is not a valid profile", Argx);
8790 end if;
8791 end;
8793 ----------------------
8794 -- Profile_Warnings --
8795 ----------------------
8797 -- pragma Profile_Warnings (profile_IDENTIFIER);
8799 -- profile_IDENTIFIER => Protected | Ravenscar
8801 when Pragma_Profile_Warnings =>
8802 GNAT_Pragma;
8803 Check_Arg_Count (1);
8804 Check_Valid_Configuration_Pragma;
8805 Check_No_Identifiers;
8807 declare
8808 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8809 begin
8810 if Chars (Argx) = Name_Ravenscar then
8811 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
8813 elsif Chars (Argx) = Name_Restricted then
8814 Set_Profile_Restrictions (Restricted, N, Warn => True);
8815 else
8816 Error_Pragma_Arg ("& is not a valid profile", Argx);
8817 end if;
8818 end;
8820 --------------------------
8821 -- Propagate_Exceptions --
8822 --------------------------
8824 -- pragma Propagate_Exceptions;
8826 -- Note: this pragma is obsolete and has no effect
8828 when Pragma_Propagate_Exceptions =>
8829 GNAT_Pragma;
8830 Check_Arg_Count (0);
8832 if In_Extended_Main_Source_Unit (N) then
8833 Propagate_Exceptions := True;
8834 end if;
8836 ------------------
8837 -- Psect_Object --
8838 ------------------
8840 -- pragma Psect_Object (
8841 -- [Internal =>] LOCAL_NAME,
8842 -- [, [External =>] EXTERNAL_SYMBOL]
8843 -- [, [Size =>] EXTERNAL_SYMBOL]);
8845 when Pragma_Psect_Object | Pragma_Common_Object =>
8846 Psect_Object : declare
8847 Args : Args_List (1 .. 3);
8848 Names : constant Name_List (1 .. 3) := (
8849 Name_Internal,
8850 Name_External,
8851 Name_Size);
8853 Internal : Node_Id renames Args (1);
8854 External : Node_Id renames Args (2);
8855 Size : Node_Id renames Args (3);
8857 Def_Id : Entity_Id;
8859 procedure Check_Too_Long (Arg : Node_Id);
8860 -- Posts message if the argument is an identifier with more
8861 -- than 31 characters, or a string literal with more than
8862 -- 31 characters, and we are operating under VMS
8864 --------------------
8865 -- Check_Too_Long --
8866 --------------------
8868 procedure Check_Too_Long (Arg : Node_Id) is
8869 X : constant Node_Id := Original_Node (Arg);
8871 begin
8872 if Nkind (X) /= N_String_Literal
8873 and then
8874 Nkind (X) /= N_Identifier
8875 then
8876 Error_Pragma_Arg
8877 ("inappropriate argument for pragma %", Arg);
8878 end if;
8880 if OpenVMS_On_Target then
8881 if (Nkind (X) = N_String_Literal
8882 and then String_Length (Strval (X)) > 31)
8883 or else
8884 (Nkind (X) = N_Identifier
8885 and then Length_Of_Name (Chars (X)) > 31)
8886 then
8887 Error_Pragma_Arg
8888 ("argument for pragma % is longer than 31 characters",
8889 Arg);
8890 end if;
8891 end if;
8892 end Check_Too_Long;
8894 -- Start of processing for Common_Object/Psect_Object
8896 begin
8897 GNAT_Pragma;
8898 Gather_Associations (Names, Args);
8899 Process_Extended_Import_Export_Internal_Arg (Internal);
8901 Def_Id := Entity (Internal);
8903 if Ekind (Def_Id) /= E_Constant
8904 and then Ekind (Def_Id) /= E_Variable
8905 then
8906 Error_Pragma_Arg
8907 ("pragma% must designate an object", Internal);
8908 end if;
8910 Check_Too_Long (Internal);
8912 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
8913 Error_Pragma_Arg
8914 ("cannot use pragma% for imported/exported object",
8915 Internal);
8916 end if;
8918 if Is_Concurrent_Type (Etype (Internal)) then
8919 Error_Pragma_Arg
8920 ("cannot specify pragma % for task/protected object",
8921 Internal);
8922 end if;
8924 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
8925 or else
8926 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
8927 then
8928 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
8929 end if;
8931 if Ekind (Def_Id) = E_Constant then
8932 Error_Pragma_Arg
8933 ("cannot specify pragma % for a constant", Internal);
8934 end if;
8936 if Is_Record_Type (Etype (Internal)) then
8937 declare
8938 Ent : Entity_Id;
8939 Decl : Entity_Id;
8941 begin
8942 Ent := First_Entity (Etype (Internal));
8943 while Present (Ent) loop
8944 Decl := Declaration_Node (Ent);
8946 if Ekind (Ent) = E_Component
8947 and then Nkind (Decl) = N_Component_Declaration
8948 and then Present (Expression (Decl))
8949 and then Warn_On_Export_Import
8950 then
8951 Error_Msg_N
8952 ("?object for pragma % has defaults", Internal);
8953 exit;
8955 else
8956 Next_Entity (Ent);
8957 end if;
8958 end loop;
8959 end;
8960 end if;
8962 if Present (Size) then
8963 Check_Too_Long (Size);
8964 end if;
8966 if Present (External) then
8967 Check_Arg_Is_External_Name (External);
8968 Check_Too_Long (External);
8969 end if;
8971 -- If all error tests pass, link pragma on to the rep item chain
8973 Record_Rep_Item (Def_Id, N);
8974 end Psect_Object;
8976 ----------
8977 -- Pure --
8978 ----------
8980 -- pragma Pure [(library_unit_NAME)];
8982 when Pragma_Pure => Pure : declare
8983 Ent : Entity_Id;
8985 begin
8986 Check_Ada_83_Warning;
8987 Check_Valid_Library_Unit_Pragma;
8989 if Nkind (N) = N_Null_Statement then
8990 return;
8991 end if;
8993 Ent := Find_Lib_Unit_Name;
8994 Set_Is_Pure (Ent);
8995 Set_Has_Pragma_Pure (Ent);
8996 Set_Suppress_Elaboration_Warnings (Ent);
8997 end Pure;
8999 -------------
9000 -- Pure_05 --
9001 -------------
9003 -- pragma Pure_05 [(library_unit_NAME)];
9005 -- This pragma is useable only in GNAT_Mode, where it is used like
9006 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
9007 -- it is ignored). It may be used after a pragma Preelaborate, in
9008 -- which case it overrides the effect of the pragma Preelaborate.
9009 -- This is used to implement AI-362 which recategorizes some run-time
9010 -- packages in Ada 2005 mode.
9012 when Pragma_Pure_05 => Pure_05 : declare
9013 Ent : Entity_Id;
9015 begin
9016 GNAT_Pragma;
9017 Check_Valid_Library_Unit_Pragma;
9019 if not GNAT_Mode then
9020 Error_Pragma ("pragma% only available in GNAT mode");
9021 end if;
9022 if Nkind (N) = N_Null_Statement then
9023 return;
9024 end if;
9026 -- This is one of the few cases where we need to test the value of
9027 -- Ada_Version_Explicit rather than Ada_Version (which is always
9028 -- set to Ada_05 in a predefined unit), we need to know the
9029 -- explicit version set to know if this pragma is active.
9031 if Ada_Version_Explicit >= Ada_05 then
9032 Ent := Find_Lib_Unit_Name;
9033 Set_Is_Preelaborated (Ent, False);
9034 Set_Is_Pure (Ent);
9035 Set_Suppress_Elaboration_Warnings (Ent);
9036 end if;
9037 end Pure_05;
9039 -------------------
9040 -- Pure_Function --
9041 -------------------
9043 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
9045 when Pragma_Pure_Function => Pure_Function : declare
9046 E_Id : Node_Id;
9047 E : Entity_Id;
9048 Def_Id : Entity_Id;
9049 Effective : Boolean := False;
9051 begin
9052 GNAT_Pragma;
9053 Check_Arg_Count (1);
9054 Check_Optional_Identifier (Arg1, Name_Entity);
9055 Check_Arg_Is_Local_Name (Arg1);
9056 E_Id := Expression (Arg1);
9058 if Error_Posted (E_Id) then
9059 return;
9060 end if;
9062 -- Loop through homonyms (overloadings) of referenced entity
9064 E := Entity (E_Id);
9066 if Present (E) then
9067 loop
9068 Def_Id := Get_Base_Subprogram (E);
9070 if Ekind (Def_Id) /= E_Function
9071 and then Ekind (Def_Id) /= E_Generic_Function
9072 and then Ekind (Def_Id) /= E_Operator
9073 then
9074 Error_Pragma_Arg
9075 ("pragma% requires a function name", Arg1);
9076 end if;
9078 Set_Is_Pure (Def_Id);
9080 if not Has_Pragma_Pure_Function (Def_Id) then
9081 Set_Has_Pragma_Pure_Function (Def_Id);
9082 Effective := True;
9083 end if;
9085 E := Homonym (E);
9086 exit when No (E) or else Scope (E) /= Current_Scope;
9087 end loop;
9089 if not Effective
9090 and then Warn_On_Redundant_Constructs
9091 then
9092 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
9093 N, Entity (E_Id));
9094 end if;
9095 end if;
9096 end Pure_Function;
9098 --------------------
9099 -- Queuing_Policy --
9100 --------------------
9102 -- pragma Queuing_Policy (policy_IDENTIFIER);
9104 when Pragma_Queuing_Policy => declare
9105 QP : Character;
9107 begin
9108 Check_Ada_83_Warning;
9109 Check_Arg_Count (1);
9110 Check_No_Identifiers;
9111 Check_Arg_Is_Queuing_Policy (Arg1);
9112 Check_Valid_Configuration_Pragma;
9113 Get_Name_String (Chars (Expression (Arg1)));
9114 QP := Fold_Upper (Name_Buffer (1));
9116 if Queuing_Policy /= ' '
9117 and then Queuing_Policy /= QP
9118 then
9119 Error_Msg_Sloc := Queuing_Policy_Sloc;
9120 Error_Pragma ("queuing policy incompatible with policy#");
9122 -- Set new policy, but always preserve System_Location since
9123 -- we like the error message with the run time name.
9125 else
9126 Queuing_Policy := QP;
9128 if Queuing_Policy_Sloc /= System_Location then
9129 Queuing_Policy_Sloc := Loc;
9130 end if;
9131 end if;
9132 end;
9134 ---------------------------
9135 -- Remote_Call_Interface --
9136 ---------------------------
9138 -- pragma Remote_Call_Interface [(library_unit_NAME)];
9140 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
9141 Cunit_Node : Node_Id;
9142 Cunit_Ent : Entity_Id;
9143 K : Node_Kind;
9145 begin
9146 Check_Ada_83_Warning;
9147 Check_Valid_Library_Unit_Pragma;
9149 if Nkind (N) = N_Null_Statement then
9150 return;
9151 end if;
9153 Cunit_Node := Cunit (Current_Sem_Unit);
9154 K := Nkind (Unit (Cunit_Node));
9155 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
9157 if K = N_Package_Declaration
9158 or else K = N_Generic_Package_Declaration
9159 or else K = N_Subprogram_Declaration
9160 or else K = N_Generic_Subprogram_Declaration
9161 or else (K = N_Subprogram_Body
9162 and then Acts_As_Spec (Unit (Cunit_Node)))
9163 then
9164 null;
9165 else
9166 Error_Pragma (
9167 "pragma% must apply to package or subprogram declaration");
9168 end if;
9170 Set_Is_Remote_Call_Interface (Cunit_Ent);
9171 end Remote_Call_Interface;
9173 ------------------
9174 -- Remote_Types --
9175 ------------------
9177 -- pragma Remote_Types [(library_unit_NAME)];
9179 when Pragma_Remote_Types => Remote_Types : declare
9180 Cunit_Node : Node_Id;
9181 Cunit_Ent : Entity_Id;
9183 begin
9184 Check_Ada_83_Warning;
9185 Check_Valid_Library_Unit_Pragma;
9187 if Nkind (N) = N_Null_Statement then
9188 return;
9189 end if;
9191 Cunit_Node := Cunit (Current_Sem_Unit);
9192 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
9194 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
9195 and then
9196 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
9197 then
9198 Error_Pragma (
9199 "pragma% can only apply to a package declaration");
9200 end if;
9202 Set_Is_Remote_Types (Cunit_Ent);
9203 end Remote_Types;
9205 ---------------
9206 -- Ravenscar --
9207 ---------------
9209 -- pragma Ravenscar;
9211 when Pragma_Ravenscar =>
9212 GNAT_Pragma;
9213 Check_Arg_Count (0);
9214 Check_Valid_Configuration_Pragma;
9215 Set_Ravenscar_Profile (N);
9217 if Warn_On_Obsolescent_Feature then
9218 Error_Msg_N
9219 ("pragma Ravenscar is an obsolescent feature?", N);
9220 Error_Msg_N
9221 ("|use pragma Profile (Ravenscar) instead", N);
9222 end if;
9224 -------------------------
9225 -- Restricted_Run_Time --
9226 -------------------------
9228 -- pragma Restricted_Run_Time;
9230 when Pragma_Restricted_Run_Time =>
9231 GNAT_Pragma;
9232 Check_Arg_Count (0);
9233 Check_Valid_Configuration_Pragma;
9234 Set_Profile_Restrictions (Restricted, N, Warn => False);
9236 if Warn_On_Obsolescent_Feature then
9237 Error_Msg_N
9238 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
9239 Error_Msg_N
9240 ("|use pragma Profile (Restricted) instead", N);
9241 end if;
9243 ------------------
9244 -- Restrictions --
9245 ------------------
9247 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
9249 -- RESTRICTION ::=
9250 -- restriction_IDENTIFIER
9251 -- | restriction_parameter_IDENTIFIER => EXPRESSION
9253 when Pragma_Restrictions =>
9254 Process_Restrictions_Or_Restriction_Warnings;
9256 --------------------------
9257 -- Restriction_Warnings --
9258 --------------------------
9260 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
9262 -- RESTRICTION ::=
9263 -- restriction_IDENTIFIER
9264 -- | restriction_parameter_IDENTIFIER => EXPRESSION
9266 when Pragma_Restriction_Warnings =>
9267 Process_Restrictions_Or_Restriction_Warnings;
9269 ----------------
9270 -- Reviewable --
9271 ----------------
9273 -- pragma Reviewable;
9275 when Pragma_Reviewable =>
9276 Check_Ada_83_Warning;
9277 Check_Arg_Count (0);
9279 -------------------
9280 -- Share_Generic --
9281 -------------------
9283 -- pragma Share_Generic (NAME {, NAME});
9285 when Pragma_Share_Generic =>
9286 GNAT_Pragma;
9287 Process_Generic_List;
9289 ------------
9290 -- Shared --
9291 ------------
9293 -- pragma Shared (LOCAL_NAME);
9295 when Pragma_Shared =>
9296 GNAT_Pragma;
9297 Process_Atomic_Shared_Volatile;
9299 --------------------
9300 -- Shared_Passive --
9301 --------------------
9303 -- pragma Shared_Passive [(library_unit_NAME)];
9305 -- Set the flag Is_Shared_Passive of program unit name entity
9307 when Pragma_Shared_Passive => Shared_Passive : declare
9308 Cunit_Node : Node_Id;
9309 Cunit_Ent : Entity_Id;
9311 begin
9312 Check_Ada_83_Warning;
9313 Check_Valid_Library_Unit_Pragma;
9315 if Nkind (N) = N_Null_Statement then
9316 return;
9317 end if;
9319 Cunit_Node := Cunit (Current_Sem_Unit);
9320 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
9322 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
9323 and then
9324 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
9325 then
9326 Error_Pragma (
9327 "pragma% can only apply to a package declaration");
9328 end if;
9330 Set_Is_Shared_Passive (Cunit_Ent);
9331 end Shared_Passive;
9333 ----------------------
9334 -- Source_File_Name --
9335 ----------------------
9337 -- There are five forms for this pragma:
9339 -- pragma Source_File_Name (
9340 -- [UNIT_NAME =>] unit_NAME,
9341 -- BODY_FILE_NAME => STRING_LITERAL
9342 -- [, [INDEX =>] INTEGER_LITERAL]);
9344 -- pragma Source_File_Name (
9345 -- [UNIT_NAME =>] unit_NAME,
9346 -- SPEC_FILE_NAME => STRING_LITERAL
9347 -- [, [INDEX =>] INTEGER_LITERAL]);
9349 -- pragma Source_File_Name (
9350 -- BODY_FILE_NAME => STRING_LITERAL
9351 -- [, DOT_REPLACEMENT => STRING_LITERAL]
9352 -- [, CASING => CASING_SPEC]);
9354 -- pragma Source_File_Name (
9355 -- SPEC_FILE_NAME => STRING_LITERAL
9356 -- [, DOT_REPLACEMENT => STRING_LITERAL]
9357 -- [, CASING => CASING_SPEC]);
9359 -- pragma Source_File_Name (
9360 -- SUBUNIT_FILE_NAME => STRING_LITERAL
9361 -- [, DOT_REPLACEMENT => STRING_LITERAL]
9362 -- [, CASING => CASING_SPEC]);
9364 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
9366 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
9367 -- Source_File_Name (SFN), however their usage is exclusive:
9368 -- SFN can only be used when no project file is used, while
9369 -- SFNP can only be used when a project file is used.
9371 -- No processing here. Processing was completed during parsing,
9372 -- since we need to have file names set as early as possible.
9373 -- Units are loaded well before semantic processing starts.
9375 -- The only processing we defer to this point is the check
9376 -- for correct placement.
9378 when Pragma_Source_File_Name =>
9379 GNAT_Pragma;
9380 Check_Valid_Configuration_Pragma;
9382 ------------------------------
9383 -- Source_File_Name_Project --
9384 ------------------------------
9386 -- See Source_File_Name for syntax
9388 -- No processing here. Processing was completed during parsing,
9389 -- since we need to have file names set as early as possible.
9390 -- Units are loaded well before semantic processing starts.
9392 -- The only processing we defer to this point is the check
9393 -- for correct placement.
9395 when Pragma_Source_File_Name_Project =>
9396 GNAT_Pragma;
9397 Check_Valid_Configuration_Pragma;
9399 -- Check that a pragma Source_File_Name_Project is used only
9400 -- in a configuration pragmas file.
9402 -- Pragmas Source_File_Name_Project should only be generated
9403 -- by the Project Manager in configuration pragmas files.
9405 -- This is really an ugly test. It seems to depend on some
9406 -- accidental and undocumented property. At the very least
9407 -- it needs to be documented, but it would be better to have
9408 -- a clean way of testing if we are in a configuration file???
9410 if Present (Parent (N)) then
9411 Error_Pragma
9412 ("pragma% can only appear in a configuration pragmas file");
9413 end if;
9415 ----------------------
9416 -- Source_Reference --
9417 ----------------------
9419 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
9421 -- Nothing to do, all processing completed in Par.Prag, since we
9422 -- need the information for possible parser messages that are output
9424 when Pragma_Source_Reference =>
9425 GNAT_Pragma;
9427 ------------------
9428 -- Storage_Size --
9429 ------------------
9431 -- pragma Storage_Size (EXPRESSION);
9433 when Pragma_Storage_Size => Storage_Size : declare
9434 P : constant Node_Id := Parent (N);
9435 Arg : Node_Id;
9437 begin
9438 Check_No_Identifiers;
9439 Check_Arg_Count (1);
9441 -- The expression must be analyzed in the special manner
9442 -- described in "Handling of Default Expressions" in sem.ads.
9444 -- Set In_Default_Expression for per-object case ???
9446 Arg := Expression (Arg1);
9447 Analyze_Per_Use_Expression (Arg, Any_Integer);
9449 if not Is_Static_Expression (Arg) then
9450 Check_Restriction (Static_Storage_Size, Arg);
9451 end if;
9453 if Nkind (P) /= N_Task_Definition then
9454 Pragma_Misplaced;
9455 return;
9457 else
9458 if Has_Storage_Size_Pragma (P) then
9459 Error_Pragma ("duplicate pragma% not allowed");
9460 else
9461 Set_Has_Storage_Size_Pragma (P, True);
9462 end if;
9464 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9465 -- ??? exp_ch9 should use this!
9466 end if;
9467 end Storage_Size;
9469 ------------------
9470 -- Storage_Unit --
9471 ------------------
9473 -- pragma Storage_Unit (NUMERIC_LITERAL);
9475 -- Only permitted argument is System'Storage_Unit value
9477 when Pragma_Storage_Unit =>
9478 Check_No_Identifiers;
9479 Check_Arg_Count (1);
9480 Check_Arg_Is_Integer_Literal (Arg1);
9482 if Intval (Expression (Arg1)) /=
9483 UI_From_Int (Ttypes.System_Storage_Unit)
9484 then
9485 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
9486 Error_Pragma_Arg
9487 ("the only allowed argument for pragma% is ^", Arg1);
9488 end if;
9490 --------------------
9491 -- Stream_Convert --
9492 --------------------
9494 -- pragma Stream_Convert (
9495 -- [Entity =>] type_LOCAL_NAME,
9496 -- [Read =>] function_NAME,
9497 -- [Write =>] function NAME);
9499 when Pragma_Stream_Convert => Stream_Convert : declare
9501 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
9502 -- Check that the given argument is the name of a local
9503 -- function of one argument that is not overloaded earlier
9504 -- in the current local scope. A check is also made that the
9505 -- argument is a function with one parameter.
9507 --------------------------------------
9508 -- Check_OK_Stream_Convert_Function --
9509 --------------------------------------
9511 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
9512 Ent : Entity_Id;
9514 begin
9515 Check_Arg_Is_Local_Name (Arg);
9516 Ent := Entity (Expression (Arg));
9518 if Has_Homonym (Ent) then
9519 Error_Pragma_Arg
9520 ("argument for pragma% may not be overloaded", Arg);
9521 end if;
9523 if Ekind (Ent) /= E_Function
9524 or else No (First_Formal (Ent))
9525 or else Present (Next_Formal (First_Formal (Ent)))
9526 then
9527 Error_Pragma_Arg
9528 ("argument for pragma% must be" &
9529 " function of one argument", Arg);
9530 end if;
9531 end Check_OK_Stream_Convert_Function;
9533 -- Start of procecessing for Stream_Convert
9535 begin
9536 GNAT_Pragma;
9537 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
9538 Check_Arg_Count (3);
9539 Check_Optional_Identifier (Arg1, Name_Entity);
9540 Check_Optional_Identifier (Arg2, Name_Read);
9541 Check_Optional_Identifier (Arg3, Name_Write);
9542 Check_Arg_Is_Local_Name (Arg1);
9543 Check_OK_Stream_Convert_Function (Arg2);
9544 Check_OK_Stream_Convert_Function (Arg3);
9546 declare
9547 Typ : constant Entity_Id :=
9548 Underlying_Type (Entity (Expression (Arg1)));
9549 Read : constant Entity_Id := Entity (Expression (Arg2));
9550 Write : constant Entity_Id := Entity (Expression (Arg3));
9552 begin
9553 if Etype (Typ) = Any_Type
9554 or else
9555 Etype (Read) = Any_Type
9556 or else
9557 Etype (Write) = Any_Type
9558 then
9559 return;
9560 end if;
9562 Check_First_Subtype (Arg1);
9564 if Rep_Item_Too_Early (Typ, N)
9565 or else
9566 Rep_Item_Too_Late (Typ, N)
9567 then
9568 return;
9569 end if;
9571 if Underlying_Type (Etype (Read)) /= Typ then
9572 Error_Pragma_Arg
9573 ("incorrect return type for function&", Arg2);
9574 end if;
9576 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
9577 Error_Pragma_Arg
9578 ("incorrect parameter type for function&", Arg3);
9579 end if;
9581 if Underlying_Type (Etype (First_Formal (Read))) /=
9582 Underlying_Type (Etype (Write))
9583 then
9584 Error_Pragma_Arg
9585 ("result type of & does not match Read parameter type",
9586 Arg3);
9587 end if;
9588 end;
9589 end Stream_Convert;
9591 -------------------------
9592 -- Style_Checks (GNAT) --
9593 -------------------------
9595 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
9597 -- This is processed by the parser since some of the style
9598 -- checks take place during source scanning and parsing. This
9599 -- means that we don't need to issue error messages here.
9601 when Pragma_Style_Checks => Style_Checks : declare
9602 A : constant Node_Id := Expression (Arg1);
9603 S : String_Id;
9604 C : Char_Code;
9606 begin
9607 GNAT_Pragma;
9608 Check_No_Identifiers;
9610 -- Two argument form
9612 if Arg_Count = 2 then
9613 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9615 declare
9616 E_Id : Node_Id;
9617 E : Entity_Id;
9619 begin
9620 E_Id := Expression (Arg2);
9621 Analyze (E_Id);
9623 if not Is_Entity_Name (E_Id) then
9624 Error_Pragma_Arg
9625 ("second argument of pragma% must be entity name",
9626 Arg2);
9627 end if;
9629 E := Entity (E_Id);
9631 if E = Any_Id then
9632 return;
9633 else
9634 loop
9635 Set_Suppress_Style_Checks (E,
9636 (Chars (Expression (Arg1)) = Name_Off));
9637 exit when No (Homonym (E));
9638 E := Homonym (E);
9639 end loop;
9640 end if;
9641 end;
9643 -- One argument form
9645 else
9646 Check_Arg_Count (1);
9648 if Nkind (A) = N_String_Literal then
9649 S := Strval (A);
9651 declare
9652 Slen : constant Natural := Natural (String_Length (S));
9653 Options : String (1 .. Slen);
9654 J : Natural;
9656 begin
9657 J := 1;
9658 loop
9659 C := Get_String_Char (S, Int (J));
9660 exit when not In_Character_Range (C);
9661 Options (J) := Get_Character (C);
9663 -- If at end of string, set options. As per discussion
9664 -- above, no need to check for errors, since we issued
9665 -- them in the parser.
9667 if J = Slen then
9668 Set_Style_Check_Options (Options);
9669 exit;
9670 end if;
9672 J := J + 1;
9673 end loop;
9674 end;
9676 elsif Nkind (A) = N_Identifier then
9677 if Chars (A) = Name_All_Checks then
9678 Set_Default_Style_Check_Options;
9680 elsif Chars (A) = Name_On then
9681 Style_Check := True;
9683 elsif Chars (A) = Name_Off then
9684 Style_Check := False;
9685 end if;
9686 end if;
9687 end if;
9688 end Style_Checks;
9690 --------------
9691 -- Subtitle --
9692 --------------
9694 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
9696 when Pragma_Subtitle =>
9697 GNAT_Pragma;
9698 Check_Arg_Count (1);
9699 Check_Optional_Identifier (Arg1, Name_Subtitle);
9700 Check_Arg_Is_String_Literal (Arg1);
9702 --------------
9703 -- Suppress --
9704 --------------
9706 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
9708 when Pragma_Suppress =>
9709 Process_Suppress_Unsuppress (True);
9711 ------------------
9712 -- Suppress_All --
9713 ------------------
9715 -- pragma Suppress_All;
9717 -- The only check made here is that the pragma appears in the
9718 -- proper place, i.e. following a compilation unit. If indeed
9719 -- it appears in this context, then the parser has already
9720 -- inserted an equivalent pragma Suppress (All_Checks) to get
9721 -- the required effect.
9723 when Pragma_Suppress_All =>
9724 GNAT_Pragma;
9725 Check_Arg_Count (0);
9727 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9728 or else not Is_List_Member (N)
9729 or else List_Containing (N) /= Pragmas_After (Parent (N))
9730 then
9731 Error_Pragma
9732 ("misplaced pragma%, must follow compilation unit");
9733 end if;
9735 -------------------------
9736 -- Suppress_Debug_Info --
9737 -------------------------
9739 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
9741 when Pragma_Suppress_Debug_Info =>
9742 GNAT_Pragma;
9743 Check_Arg_Count (1);
9744 Check_Optional_Identifier (Arg1, Name_Entity);
9745 Check_Arg_Is_Local_Name (Arg1);
9746 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
9748 ----------------------------------
9749 -- Suppress_Exception_Locations --
9750 ----------------------------------
9752 -- pragma Suppress_Exception_Locations;
9754 when Pragma_Suppress_Exception_Locations =>
9755 GNAT_Pragma;
9756 Check_Arg_Count (0);
9757 Check_Valid_Configuration_Pragma;
9758 Exception_Locations_Suppressed := True;
9760 -----------------------------
9761 -- Suppress_Initialization --
9762 -----------------------------
9764 -- pragma Suppress_Initialization ([Entity =>] type_Name);
9766 when Pragma_Suppress_Initialization => Suppress_Init : declare
9767 E_Id : Node_Id;
9768 E : Entity_Id;
9770 begin
9771 GNAT_Pragma;
9772 Check_Arg_Count (1);
9773 Check_Optional_Identifier (Arg1, Name_Entity);
9774 Check_Arg_Is_Local_Name (Arg1);
9776 E_Id := Expression (Arg1);
9778 if Etype (E_Id) = Any_Type then
9779 return;
9780 end if;
9782 E := Entity (E_Id);
9784 if Is_Type (E) then
9785 if Is_Incomplete_Or_Private_Type (E) then
9786 if No (Full_View (Base_Type (E))) then
9787 Error_Pragma_Arg
9788 ("argument of pragma% cannot be an incomplete type",
9789 Arg1);
9790 else
9791 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
9792 end if;
9793 else
9794 Set_Suppress_Init_Proc (Base_Type (E));
9795 end if;
9797 else
9798 Error_Pragma_Arg
9799 ("pragma% requires argument that is a type name", Arg1);
9800 end if;
9801 end Suppress_Init;
9803 -----------------
9804 -- System_Name --
9805 -----------------
9807 -- pragma System_Name (DIRECT_NAME);
9809 -- Syntax check: one argument, which must be the identifier GNAT
9810 -- or the identifier GCC, no other identifiers are acceptable.
9812 when Pragma_System_Name =>
9813 Check_No_Identifiers;
9814 Check_Arg_Count (1);
9815 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
9817 -----------------------------
9818 -- Task_Dispatching_Policy --
9819 -----------------------------
9821 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
9823 when Pragma_Task_Dispatching_Policy => declare
9824 DP : Character;
9826 begin
9827 Check_Ada_83_Warning;
9828 Check_Arg_Count (1);
9829 Check_No_Identifiers;
9830 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9831 Check_Valid_Configuration_Pragma;
9832 Get_Name_String (Chars (Expression (Arg1)));
9833 DP := Fold_Upper (Name_Buffer (1));
9835 if Task_Dispatching_Policy /= ' '
9836 and then Task_Dispatching_Policy /= DP
9837 then
9838 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9839 Error_Pragma
9840 ("task dispatching policy incompatible with policy#");
9842 -- Set new policy, but always preserve System_Location since
9843 -- we like the error message with the run time name.
9845 else
9846 Task_Dispatching_Policy := DP;
9848 if Task_Dispatching_Policy_Sloc /= System_Location then
9849 Task_Dispatching_Policy_Sloc := Loc;
9850 end if;
9851 end if;
9852 end;
9854 --------------
9855 -- Task_Info --
9856 --------------
9858 -- pragma Task_Info (EXPRESSION);
9860 when Pragma_Task_Info => Task_Info : declare
9861 P : constant Node_Id := Parent (N);
9863 begin
9864 GNAT_Pragma;
9866 if Nkind (P) /= N_Task_Definition then
9867 Error_Pragma ("pragma% must appear in task definition");
9868 end if;
9870 Check_No_Identifiers;
9871 Check_Arg_Count (1);
9873 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
9875 if Etype (Expression (Arg1)) = Any_Type then
9876 return;
9877 end if;
9879 if Has_Task_Info_Pragma (P) then
9880 Error_Pragma ("duplicate pragma% not allowed");
9881 else
9882 Set_Has_Task_Info_Pragma (P, True);
9883 end if;
9884 end Task_Info;
9886 ---------------
9887 -- Task_Name --
9888 ---------------
9890 -- pragma Task_Name (string_EXPRESSION);
9892 when Pragma_Task_Name => Task_Name : declare
9893 -- pragma Priority (EXPRESSION);
9895 P : constant Node_Id := Parent (N);
9896 Arg : Node_Id;
9898 begin
9899 Check_No_Identifiers;
9900 Check_Arg_Count (1);
9902 Arg := Expression (Arg1);
9903 Analyze_And_Resolve (Arg, Standard_String);
9905 if Nkind (P) /= N_Task_Definition then
9906 Pragma_Misplaced;
9907 end if;
9909 if Has_Task_Name_Pragma (P) then
9910 Error_Pragma ("duplicate pragma% not allowed");
9911 else
9912 Set_Has_Task_Name_Pragma (P, True);
9913 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9914 end if;
9915 end Task_Name;
9917 ------------------
9918 -- Task_Storage --
9919 ------------------
9921 -- pragma Task_Storage (
9922 -- [Task_Type =>] LOCAL_NAME,
9923 -- [Top_Guard =>] static_integer_EXPRESSION);
9925 when Pragma_Task_Storage => Task_Storage : declare
9926 Args : Args_List (1 .. 2);
9927 Names : constant Name_List (1 .. 2) := (
9928 Name_Task_Type,
9929 Name_Top_Guard);
9931 Task_Type : Node_Id renames Args (1);
9932 Top_Guard : Node_Id renames Args (2);
9934 Ent : Entity_Id;
9936 begin
9937 GNAT_Pragma;
9938 Gather_Associations (Names, Args);
9940 if No (Task_Type) then
9941 Error_Pragma
9942 ("missing task_type argument for pragma%");
9943 end if;
9945 Check_Arg_Is_Local_Name (Task_Type);
9947 Ent := Entity (Task_Type);
9949 if not Is_Task_Type (Ent) then
9950 Error_Pragma_Arg
9951 ("argument for pragma% must be task type", Task_Type);
9952 end if;
9954 if No (Top_Guard) then
9955 Error_Pragma_Arg
9956 ("pragma% takes two arguments", Task_Type);
9957 else
9958 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
9959 end if;
9961 Check_First_Subtype (Task_Type);
9963 if Rep_Item_Too_Late (Ent, N) then
9964 raise Pragma_Exit;
9965 end if;
9966 end Task_Storage;
9968 -----------------
9969 -- Thread_Body --
9970 -----------------
9972 -- pragma Thread_Body
9973 -- ( [Entity =>] LOCAL_NAME
9974 -- [,[Secondary_Stack_Size =>] static_integer_EXPRESSION]);
9976 when Pragma_Thread_Body => Thread_Body : declare
9977 Id : Node_Id;
9978 SS : Node_Id;
9979 E : Entity_Id;
9981 begin
9982 GNAT_Pragma;
9983 Check_Arg_Order ((Name_Entity, Name_Secondary_Stack_Size));
9984 Check_At_Least_N_Arguments (1);
9985 Check_At_Most_N_Arguments (2);
9986 Check_Optional_Identifier (Arg1, Name_Entity);
9987 Check_Arg_Is_Local_Name (Arg1);
9989 Id := Expression (Arg1);
9991 if not Is_Entity_Name (Id)
9992 or else not Is_Subprogram (Entity (Id))
9993 then
9994 Error_Pragma_Arg ("subprogram name required", Arg1);
9995 end if;
9997 E := Entity (Id);
9999 -- Go to renamed subprogram if present, since Thread_Body applies
10000 -- to the actual renamed entity, not to the renaming entity.
10002 if Present (Alias (E))
10003 and then Nkind (Parent (Declaration_Node (E))) =
10004 N_Subprogram_Renaming_Declaration
10005 then
10006 E := Alias (E);
10007 end if;
10009 -- Various error checks
10011 if Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body then
10012 Error_Pragma
10013 ("pragma% requires separate spec and must come before body");
10015 elsif Rep_Item_Too_Early (E, N)
10016 or else Rep_Item_Too_Late (E, N)
10017 then
10018 raise Pragma_Exit;
10020 elsif Is_Thread_Body (E) then
10021 Error_Pragma_Arg
10022 ("only one thread body pragma allowed", Arg1);
10024 elsif Present (Homonym (E))
10025 and then Scope (Homonym (E)) = Current_Scope
10026 then
10027 Error_Pragma_Arg
10028 ("thread body subprogram must not be overloaded", Arg1);
10029 end if;
10031 Set_Is_Thread_Body (E);
10033 -- Deal with secondary stack argument
10035 if Arg_Count = 2 then
10036 Check_Optional_Identifier (Arg2, Name_Secondary_Stack_Size);
10037 SS := Expression (Arg2);
10038 Analyze_And_Resolve (SS, Any_Integer);
10039 end if;
10040 end Thread_Body;
10042 ----------------
10043 -- Time_Slice --
10044 ----------------
10046 -- pragma Time_Slice (static_duration_EXPRESSION);
10048 when Pragma_Time_Slice => Time_Slice : declare
10049 Val : Ureal;
10050 Nod : Node_Id;
10052 begin
10053 GNAT_Pragma;
10054 Check_Arg_Count (1);
10055 Check_No_Identifiers;
10056 Check_In_Main_Program;
10057 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
10059 if not Error_Posted (Arg1) then
10060 Nod := Next (N);
10061 while Present (Nod) loop
10062 if Nkind (Nod) = N_Pragma
10063 and then Chars (Nod) = Name_Time_Slice
10064 then
10065 Error_Msg_Name_1 := Chars (N);
10066 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10067 end if;
10069 Next (Nod);
10070 end loop;
10071 end if;
10073 -- Process only if in main unit
10075 if Get_Source_Unit (Loc) = Main_Unit then
10076 Opt.Time_Slice_Set := True;
10077 Val := Expr_Value_R (Expression (Arg1));
10079 if Val <= Ureal_0 then
10080 Opt.Time_Slice_Value := 0;
10082 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
10083 Opt.Time_Slice_Value := 1_000_000_000;
10085 else
10086 Opt.Time_Slice_Value :=
10087 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
10088 end if;
10089 end if;
10090 end Time_Slice;
10092 -----------
10093 -- Title --
10094 -----------
10096 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
10098 -- TITLING_OPTION ::=
10099 -- [Title =>] STRING_LITERAL
10100 -- | [Subtitle =>] STRING_LITERAL
10102 when Pragma_Title => Title : declare
10103 Args : Args_List (1 .. 2);
10104 Names : constant Name_List (1 .. 2) := (
10105 Name_Title,
10106 Name_Subtitle);
10108 begin
10109 GNAT_Pragma;
10110 Gather_Associations (Names, Args);
10112 for J in 1 .. 2 loop
10113 if Present (Args (J)) then
10114 Check_Arg_Is_String_Literal (Args (J));
10115 end if;
10116 end loop;
10117 end Title;
10119 ---------------------
10120 -- Unchecked_Union --
10121 ---------------------
10123 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
10125 when Pragma_Unchecked_Union => Unchecked_Union : declare
10126 Assoc : constant Node_Id := Arg1;
10127 Type_Id : constant Node_Id := Expression (Assoc);
10128 Typ : Entity_Id;
10129 Discr : Entity_Id;
10130 Tdef : Node_Id;
10131 Clist : Node_Id;
10132 Vpart : Node_Id;
10133 Comp : Node_Id;
10134 Variant : Node_Id;
10136 begin
10137 GNAT_Pragma;
10138 Check_No_Identifiers;
10139 Check_Arg_Count (1);
10140 Check_Arg_Is_Local_Name (Arg1);
10142 Find_Type (Type_Id);
10143 Typ := Entity (Type_Id);
10145 if Typ = Any_Type
10146 or else Rep_Item_Too_Early (Typ, N)
10147 then
10148 return;
10149 else
10150 Typ := Underlying_Type (Typ);
10151 end if;
10153 if Rep_Item_Too_Late (Typ, N) then
10154 return;
10155 end if;
10157 Check_First_Subtype (Arg1);
10159 -- Note remaining cases are references to a type in the current
10160 -- declarative part. If we find an error, we post the error on
10161 -- the relevant type declaration at an appropriate point.
10163 if not Is_Record_Type (Typ) then
10164 Error_Msg_N ("Unchecked_Union must be record type", Typ);
10165 return;
10167 elsif Is_Tagged_Type (Typ) then
10168 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
10169 return;
10171 elsif Is_Limited_Type (Typ) then
10172 Error_Msg_N
10173 ("Unchecked_Union must not be limited record type", Typ);
10174 Explain_Limited_Type (Typ, Typ);
10175 return;
10177 else
10178 if not Has_Discriminants (Typ) then
10179 Error_Msg_N
10180 ("Unchecked_Union must have one discriminant", Typ);
10181 return;
10182 end if;
10184 Discr := First_Discriminant (Typ);
10186 while Present (Discr) loop
10187 if No (Discriminant_Default_Value (Discr)) then
10188 Error_Msg_N
10189 ("Unchecked_Union discriminant must have default value",
10190 Discr);
10191 end if;
10192 Next_Discriminant (Discr);
10193 end loop;
10195 Tdef := Type_Definition (Declaration_Node (Typ));
10196 Clist := Component_List (Tdef);
10198 Comp := First (Component_Items (Clist));
10199 while Present (Comp) loop
10201 Check_Component (Comp);
10202 Next (Comp);
10204 end loop;
10206 if No (Clist) or else No (Variant_Part (Clist)) then
10207 Error_Msg_N
10208 ("Unchecked_Union must have variant part",
10209 Tdef);
10210 return;
10211 end if;
10213 Vpart := Variant_Part (Clist);
10215 Variant := First (Variants (Vpart));
10216 while Present (Variant) loop
10217 Check_Variant (Variant);
10218 Next (Variant);
10219 end loop;
10220 end if;
10222 Set_Is_Unchecked_Union (Typ, True);
10223 Set_Convention (Typ, Convention_C);
10225 Set_Has_Unchecked_Union (Base_Type (Typ), True);
10226 Set_Is_Unchecked_Union (Base_Type (Typ), True);
10227 end Unchecked_Union;
10229 ------------------------
10230 -- Unimplemented_Unit --
10231 ------------------------
10233 -- pragma Unimplemented_Unit;
10235 -- Note: this only gives an error if we are generating code,
10236 -- or if we are in a generic library unit (where the pragma
10237 -- appears in the body, not in the spec).
10239 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
10240 Cunitent : constant Entity_Id :=
10241 Cunit_Entity (Get_Source_Unit (Loc));
10242 Ent_Kind : constant Entity_Kind :=
10243 Ekind (Cunitent);
10245 begin
10246 GNAT_Pragma;
10247 Check_Arg_Count (0);
10249 if Operating_Mode = Generate_Code
10250 or else Ent_Kind = E_Generic_Function
10251 or else Ent_Kind = E_Generic_Procedure
10252 or else Ent_Kind = E_Generic_Package
10253 then
10254 Get_Name_String (Chars (Cunitent));
10255 Set_Casing (Mixed_Case);
10256 Write_Str (Name_Buffer (1 .. Name_Len));
10257 Write_Str (" is not implemented");
10258 Write_Eol;
10259 raise Unrecoverable_Error;
10260 end if;
10261 end Unimplemented_Unit;
10263 --------------------
10264 -- Universal_Data --
10265 --------------------
10267 -- pragma Universal_Data [(library_unit_NAME)];
10269 when Pragma_Universal_Data =>
10270 GNAT_Pragma;
10272 -- If this is a configuration pragma, then set the universal
10273 -- addressing option, otherwise confirm that the pragma
10274 -- satisfies the requirements of library unit pragma placement
10275 -- and leave it to the GNAAMP back end to detect the pragma
10276 -- (avoids transitive setting of the option due to withed units).
10278 if Is_Configuration_Pragma then
10279 Universal_Addressing_On_AAMP := True;
10280 else
10281 Check_Valid_Library_Unit_Pragma;
10282 end if;
10284 if not AAMP_On_Target then
10285 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
10286 end if;
10288 ------------------
10289 -- Unreferenced --
10290 ------------------
10292 -- pragma Unreferenced (local_Name {, local_Name});
10294 when Pragma_Unreferenced => Unreferenced : declare
10295 Arg_Node : Node_Id;
10296 Arg_Expr : Node_Id;
10297 Arg_Ent : Entity_Id;
10299 begin
10300 GNAT_Pragma;
10301 Check_At_Least_N_Arguments (1);
10303 Arg_Node := Arg1;
10304 while Present (Arg_Node) loop
10305 Check_No_Identifier (Arg_Node);
10307 -- Note that the analyze call done by Check_Arg_Is_Local_Name
10308 -- will in fact generate a reference, so that the entity will
10309 -- have a reference, which will inhibit any warnings about it
10310 -- not being referenced, and also properly show up in the ali
10311 -- file as a reference. But this reference is recorded before
10312 -- the Has_Pragma_Unreferenced flag is set, so that no warning
10313 -- is generated for this reference.
10315 Check_Arg_Is_Local_Name (Arg_Node);
10316 Arg_Expr := Get_Pragma_Arg (Arg_Node);
10318 if Is_Entity_Name (Arg_Expr) then
10319 Arg_Ent := Entity (Arg_Expr);
10321 -- If the entity is overloaded, the pragma applies to the
10322 -- most recent overloading, as documented. In this case,
10323 -- name resolution does not generate a reference, so it
10324 -- must be done here explicitly.
10326 if Is_Overloaded (Arg_Expr) then
10327 Generate_Reference (Arg_Ent, N);
10328 end if;
10330 Set_Has_Pragma_Unreferenced (Arg_Ent);
10331 end if;
10333 Next (Arg_Node);
10334 end loop;
10335 end Unreferenced;
10337 ------------------------------
10338 -- Unreserve_All_Interrupts --
10339 ------------------------------
10341 -- pragma Unreserve_All_Interrupts;
10343 when Pragma_Unreserve_All_Interrupts =>
10344 GNAT_Pragma;
10345 Check_Arg_Count (0);
10347 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
10348 Unreserve_All_Interrupts := True;
10349 end if;
10351 ----------------
10352 -- Unsuppress --
10353 ----------------
10355 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
10357 when Pragma_Unsuppress =>
10358 GNAT_Pragma;
10359 Process_Suppress_Unsuppress (False);
10361 -------------------
10362 -- Use_VADS_Size --
10363 -------------------
10365 -- pragma Use_VADS_Size;
10367 when Pragma_Use_VADS_Size =>
10368 GNAT_Pragma;
10369 Check_Arg_Count (0);
10370 Check_Valid_Configuration_Pragma;
10371 Use_VADS_Size := True;
10373 ---------------------
10374 -- Validity_Checks --
10375 ---------------------
10377 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
10379 when Pragma_Validity_Checks => Validity_Checks : declare
10380 A : constant Node_Id := Expression (Arg1);
10381 S : String_Id;
10382 C : Char_Code;
10384 begin
10385 GNAT_Pragma;
10386 Check_Arg_Count (1);
10387 Check_No_Identifiers;
10389 if Nkind (A) = N_String_Literal then
10390 S := Strval (A);
10392 declare
10393 Slen : constant Natural := Natural (String_Length (S));
10394 Options : String (1 .. Slen);
10395 J : Natural;
10397 begin
10398 J := 1;
10399 loop
10400 C := Get_String_Char (S, Int (J));
10401 exit when not In_Character_Range (C);
10402 Options (J) := Get_Character (C);
10404 if J = Slen then
10405 Set_Validity_Check_Options (Options);
10406 exit;
10407 else
10408 J := J + 1;
10409 end if;
10410 end loop;
10411 end;
10413 elsif Nkind (A) = N_Identifier then
10415 if Chars (A) = Name_All_Checks then
10416 Set_Validity_Check_Options ("a");
10418 elsif Chars (A) = Name_On then
10419 Validity_Checks_On := True;
10421 elsif Chars (A) = Name_Off then
10422 Validity_Checks_On := False;
10424 end if;
10425 end if;
10426 end Validity_Checks;
10428 --------------
10429 -- Volatile --
10430 --------------
10432 -- pragma Volatile (LOCAL_NAME);
10434 when Pragma_Volatile =>
10435 Process_Atomic_Shared_Volatile;
10437 -------------------------
10438 -- Volatile_Components --
10439 -------------------------
10441 -- pragma Volatile_Components (array_LOCAL_NAME);
10443 -- Volatile is handled by the same circuit as Atomic_Components
10445 --------------
10446 -- Warnings --
10447 --------------
10449 -- pragma Warnings (On | Off, [LOCAL_NAME])
10450 -- pragma Warnings (static_string_EXPRESSION);
10452 when Pragma_Warnings => Warnings : begin
10453 GNAT_Pragma;
10454 Check_At_Least_N_Arguments (1);
10455 Check_No_Identifiers;
10457 -- One argument case
10459 if Arg_Count = 1 then
10460 declare
10461 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10463 begin
10464 -- On/Off one argument case was processed by parser
10466 if Nkind (Argx) = N_Identifier
10467 and then
10468 (Chars (Argx) = Name_On
10469 or else
10470 Chars (Argx) = Name_Off)
10471 then
10472 null;
10474 else
10475 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10477 declare
10478 Lit : constant Node_Id := Expr_Value_S (Argx);
10479 Str : constant String_Id := Strval (Lit);
10480 C : Char_Code;
10482 begin
10483 for J in 1 .. String_Length (Str) loop
10484 C := Get_String_Char (Str, J);
10486 if In_Character_Range (C)
10487 and then Set_Warning_Switch (Get_Character (C))
10488 then
10489 null;
10490 else
10491 Error_Pragma_Arg
10492 ("invalid warning switch character", Arg1);
10493 end if;
10494 end loop;
10495 end;
10496 end if;
10497 end;
10499 -- Two argument case
10501 elsif Arg_Count /= 1 then
10502 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10503 Check_Arg_Count (2);
10505 declare
10506 E_Id : Node_Id;
10507 E : Entity_Id;
10509 begin
10510 E_Id := Expression (Arg2);
10511 Analyze (E_Id);
10513 -- In the expansion of an inlined body, a reference to
10514 -- the formal may be wrapped in a conversion if the actual
10515 -- is a conversion. Retrieve the real entity name.
10517 if (In_Instance_Body
10518 or else In_Inlined_Body)
10519 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
10520 then
10521 E_Id := Expression (E_Id);
10522 end if;
10524 if not Is_Entity_Name (E_Id) then
10525 Error_Pragma_Arg
10526 ("second argument of pragma% must be entity name",
10527 Arg2);
10528 end if;
10530 E := Entity (E_Id);
10532 if E = Any_Id then
10533 return;
10534 else
10535 loop
10536 Set_Warnings_Off
10537 (E, (Chars (Expression (Arg1)) = Name_Off));
10539 if Is_Enumeration_Type (E) then
10540 declare
10541 Lit : Entity_Id;
10542 begin
10543 Lit := First_Literal (E);
10544 while Present (Lit) loop
10545 Set_Warnings_Off (Lit);
10546 Next_Literal (Lit);
10547 end loop;
10548 end;
10549 end if;
10551 exit when No (Homonym (E));
10552 E := Homonym (E);
10553 end loop;
10554 end if;
10555 end;
10557 -- More than two arguments
10558 else
10559 Check_At_Most_N_Arguments (2);
10560 end if;
10561 end Warnings;
10563 -------------------
10564 -- Weak_External --
10565 -------------------
10567 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
10569 when Pragma_Weak_External => Weak_External : declare
10570 Ent : Entity_Id;
10572 begin
10573 GNAT_Pragma;
10574 Check_Arg_Count (1);
10575 Check_Optional_Identifier (Arg1, Name_Entity);
10576 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10577 Ent := Entity (Expression (Arg1));
10579 if Rep_Item_Too_Early (Ent, N) then
10580 return;
10581 else
10582 Ent := Underlying_Type (Ent);
10583 end if;
10585 -- The only processing required is to link this item on to the
10586 -- list of rep items for the given entity. This is accomplished
10587 -- by the call to Rep_Item_Too_Late (when no error is detected
10588 -- and False is returned).
10590 if Rep_Item_Too_Late (Ent, N) then
10591 return;
10592 else
10593 Set_Has_Gigi_Rep_Item (Ent);
10594 end if;
10595 end Weak_External;
10597 --------------------
10598 -- Unknown_Pragma --
10599 --------------------
10601 -- Should be impossible, since the case of an unknown pragma is
10602 -- separately processed before the case statement is entered.
10604 when Unknown_Pragma =>
10605 raise Program_Error;
10606 end case;
10608 exception
10609 when Pragma_Exit => null;
10610 end Analyze_Pragma;
10612 ---------------------------------
10613 -- Delay_Config_Pragma_Analyze --
10614 ---------------------------------
10616 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
10617 begin
10618 return Chars (N) = Name_Interrupt_State;
10619 end Delay_Config_Pragma_Analyze;
10621 -------------------------
10622 -- Get_Base_Subprogram --
10623 -------------------------
10625 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
10626 Result : Entity_Id;
10628 begin
10629 -- Follow subprogram renaming chain
10631 Result := Def_Id;
10632 while Is_Subprogram (Result)
10633 and then
10634 (Is_Generic_Instance (Result)
10635 or else Nkind (Parent (Declaration_Node (Result))) =
10636 N_Subprogram_Renaming_Declaration)
10637 and then Present (Alias (Result))
10638 loop
10639 Result := Alias (Result);
10640 end loop;
10642 return Result;
10643 end Get_Base_Subprogram;
10645 -----------------------------
10646 -- Is_Config_Static_String --
10647 -----------------------------
10649 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
10651 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
10652 -- This is an internal recursive function that is just like the
10653 -- outer function except that it adds the string to the name buffer
10654 -- rather than placing the string in the name buffer.
10656 ------------------------------
10657 -- Add_Config_Static_String --
10658 ------------------------------
10660 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
10661 N : Node_Id;
10662 C : Char_Code;
10664 begin
10665 N := Arg;
10667 if Nkind (N) = N_Op_Concat then
10668 if Add_Config_Static_String (Left_Opnd (N)) then
10669 N := Right_Opnd (N);
10670 else
10671 return False;
10672 end if;
10673 end if;
10675 if Nkind (N) /= N_String_Literal then
10676 Error_Msg_N ("string literal expected for pragma argument", N);
10677 return False;
10679 else
10680 for J in 1 .. String_Length (Strval (N)) loop
10681 C := Get_String_Char (Strval (N), J);
10683 if not In_Character_Range (C) then
10684 Error_Msg
10685 ("string literal contains invalid wide character",
10686 Sloc (N) + 1 + Source_Ptr (J));
10687 return False;
10688 end if;
10690 Add_Char_To_Name_Buffer (Get_Character (C));
10691 end loop;
10692 end if;
10694 return True;
10695 end Add_Config_Static_String;
10697 -- Start of prorcessing for Is_Config_Static_String
10699 begin
10701 Name_Len := 0;
10702 return Add_Config_Static_String (Arg);
10703 end Is_Config_Static_String;
10705 -----------------------------------------
10706 -- Is_Non_Significant_Pragma_Reference --
10707 -----------------------------------------
10709 -- This function makes use of the following static table which indicates
10710 -- whether a given pragma is significant. A value of -1 in this table
10711 -- indicates that the reference is significant. A value of zero indicates
10712 -- than appearence as any argument is insignificant, a positive value
10713 -- indicates that appearence in that parameter position is significant.
10715 Sig_Flags : constant array (Pragma_Id) of Int :=
10717 (Pragma_AST_Entry => -1,
10718 Pragma_Abort_Defer => -1,
10719 Pragma_Ada_83 => -1,
10720 Pragma_Ada_95 => -1,
10721 Pragma_Ada_05 => -1,
10722 Pragma_Ada_2005 => -1,
10723 Pragma_All_Calls_Remote => -1,
10724 Pragma_Annotate => -1,
10725 Pragma_Assert => -1,
10726 Pragma_Assertion_Policy => 0,
10727 Pragma_Asynchronous => -1,
10728 Pragma_Atomic => 0,
10729 Pragma_Atomic_Components => 0,
10730 Pragma_Attach_Handler => -1,
10731 Pragma_CPP_Class => 0,
10732 Pragma_CPP_Constructor => 0,
10733 Pragma_CPP_Virtual => 0,
10734 Pragma_CPP_Vtable => 0,
10735 Pragma_C_Pass_By_Copy => 0,
10736 Pragma_Comment => 0,
10737 Pragma_Common_Object => -1,
10738 Pragma_Compile_Time_Warning => -1,
10739 Pragma_Complete_Representation => 0,
10740 Pragma_Complex_Representation => 0,
10741 Pragma_Component_Alignment => -1,
10742 Pragma_Controlled => 0,
10743 Pragma_Convention => 0,
10744 Pragma_Convention_Identifier => 0,
10745 Pragma_Debug => -1,
10746 Pragma_Debug_Policy => 0,
10747 Pragma_Detect_Blocking => -1,
10748 Pragma_Discard_Names => 0,
10749 Pragma_Elaborate => -1,
10750 Pragma_Elaborate_All => -1,
10751 Pragma_Elaborate_Body => -1,
10752 Pragma_Elaboration_Checks => -1,
10753 Pragma_Eliminate => -1,
10754 Pragma_Explicit_Overriding => -1,
10755 Pragma_Export => -1,
10756 Pragma_Export_Exception => -1,
10757 Pragma_Export_Function => -1,
10758 Pragma_Export_Object => -1,
10759 Pragma_Export_Procedure => -1,
10760 Pragma_Export_Value => -1,
10761 Pragma_Export_Valued_Procedure => -1,
10762 Pragma_Extend_System => -1,
10763 Pragma_Extensions_Allowed => -1,
10764 Pragma_External => -1,
10765 Pragma_External_Name_Casing => -1,
10766 Pragma_Finalize_Storage_Only => 0,
10767 Pragma_Float_Representation => 0,
10768 Pragma_Ident => -1,
10769 Pragma_Import => +2,
10770 Pragma_Import_Exception => 0,
10771 Pragma_Import_Function => 0,
10772 Pragma_Import_Object => 0,
10773 Pragma_Import_Procedure => 0,
10774 Pragma_Import_Valued_Procedure => 0,
10775 Pragma_Initialize_Scalars => -1,
10776 Pragma_Inline => 0,
10777 Pragma_Inline_Always => 0,
10778 Pragma_Inline_Generic => 0,
10779 Pragma_Inspection_Point => -1,
10780 Pragma_Interface => +2,
10781 Pragma_Interface_Name => +2,
10782 Pragma_Interrupt_Handler => -1,
10783 Pragma_Interrupt_Priority => -1,
10784 Pragma_Interrupt_State => -1,
10785 Pragma_Java_Constructor => -1,
10786 Pragma_Java_Interface => -1,
10787 Pragma_Keep_Names => 0,
10788 Pragma_License => -1,
10789 Pragma_Link_With => -1,
10790 Pragma_Linker_Alias => -1,
10791 Pragma_Linker_Constructor => -1,
10792 Pragma_Linker_Destructor => -1,
10793 Pragma_Linker_Options => -1,
10794 Pragma_Linker_Section => -1,
10795 Pragma_List => -1,
10796 Pragma_Locking_Policy => -1,
10797 Pragma_Long_Float => -1,
10798 Pragma_Machine_Attribute => -1,
10799 Pragma_Main => -1,
10800 Pragma_Main_Storage => -1,
10801 Pragma_Memory_Size => -1,
10802 Pragma_No_Return => 0,
10803 Pragma_No_Run_Time => -1,
10804 Pragma_No_Strict_Aliasing => -1,
10805 Pragma_Normalize_Scalars => -1,
10806 Pragma_Obsolescent => 0,
10807 Pragma_Optimize => -1,
10808 Pragma_Optional_Overriding => -1,
10809 Pragma_Pack => 0,
10810 Pragma_Page => -1,
10811 Pragma_Passive => -1,
10812 Pragma_Polling => -1,
10813 Pragma_Persistent_BSS => 0,
10814 Pragma_Preelaborate => -1,
10815 Pragma_Preelaborate_05 => -1,
10816 Pragma_Priority => -1,
10817 Pragma_Profile => 0,
10818 Pragma_Profile_Warnings => 0,
10819 Pragma_Propagate_Exceptions => -1,
10820 Pragma_Psect_Object => -1,
10821 Pragma_Pure => -1,
10822 Pragma_Pure_05 => -1,
10823 Pragma_Pure_Function => -1,
10824 Pragma_Queuing_Policy => -1,
10825 Pragma_Ravenscar => -1,
10826 Pragma_Remote_Call_Interface => -1,
10827 Pragma_Remote_Types => -1,
10828 Pragma_Restricted_Run_Time => -1,
10829 Pragma_Restriction_Warnings => -1,
10830 Pragma_Restrictions => -1,
10831 Pragma_Reviewable => -1,
10832 Pragma_Share_Generic => -1,
10833 Pragma_Shared => -1,
10834 Pragma_Shared_Passive => -1,
10835 Pragma_Source_File_Name => -1,
10836 Pragma_Source_File_Name_Project => -1,
10837 Pragma_Source_Reference => -1,
10838 Pragma_Storage_Size => -1,
10839 Pragma_Storage_Unit => -1,
10840 Pragma_Stream_Convert => -1,
10841 Pragma_Style_Checks => -1,
10842 Pragma_Subtitle => -1,
10843 Pragma_Suppress => 0,
10844 Pragma_Suppress_Exception_Locations => 0,
10845 Pragma_Suppress_All => -1,
10846 Pragma_Suppress_Debug_Info => 0,
10847 Pragma_Suppress_Initialization => 0,
10848 Pragma_System_Name => -1,
10849 Pragma_Task_Dispatching_Policy => -1,
10850 Pragma_Task_Info => -1,
10851 Pragma_Task_Name => -1,
10852 Pragma_Task_Storage => 0,
10853 Pragma_Thread_Body => +2,
10854 Pragma_Time_Slice => -1,
10855 Pragma_Title => -1,
10856 Pragma_Unchecked_Union => 0,
10857 Pragma_Unimplemented_Unit => -1,
10858 Pragma_Universal_Data => -1,
10859 Pragma_Unreferenced => -1,
10860 Pragma_Unreserve_All_Interrupts => -1,
10861 Pragma_Unsuppress => 0,
10862 Pragma_Use_VADS_Size => -1,
10863 Pragma_Validity_Checks => -1,
10864 Pragma_Volatile => 0,
10865 Pragma_Volatile_Components => 0,
10866 Pragma_Warnings => -1,
10867 Pragma_Weak_External => 0,
10868 Unknown_Pragma => 0);
10870 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
10871 P : Node_Id;
10872 C : Int;
10873 A : Node_Id;
10875 begin
10876 P := Parent (N);
10878 if Nkind (P) /= N_Pragma_Argument_Association then
10879 return False;
10881 else
10882 C := Sig_Flags (Get_Pragma_Id (Chars (Parent (P))));
10884 case C is
10885 when -1 =>
10886 return False;
10888 when 0 =>
10889 return True;
10891 when others =>
10892 A := First (Pragma_Argument_Associations (Parent (P)));
10893 for J in 1 .. C - 1 loop
10894 if No (A) then
10895 return False;
10896 end if;
10898 Next (A);
10899 end loop;
10901 return A = P;
10902 end case;
10903 end if;
10904 end Is_Non_Significant_Pragma_Reference;
10906 ------------------------------
10907 -- Is_Pragma_String_Literal --
10908 ------------------------------
10910 -- This function returns true if the corresponding pragma argument is
10911 -- a static string expression. These are the only cases in which string
10912 -- literals can appear as pragma arguments. We also allow a string
10913 -- literal as the first argument to pragma Assert (although it will
10914 -- of course always generate a type error).
10916 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
10917 Pragn : constant Node_Id := Parent (Par);
10918 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
10919 Pname : constant Name_Id := Chars (Pragn);
10920 Argn : Natural;
10921 N : Node_Id;
10923 begin
10924 Argn := 1;
10925 N := First (Assoc);
10926 loop
10927 exit when N = Par;
10928 Argn := Argn + 1;
10929 Next (N);
10930 end loop;
10932 if Pname = Name_Assert then
10933 return True;
10935 elsif Pname = Name_Export then
10936 return Argn > 2;
10938 elsif Pname = Name_Ident then
10939 return Argn = 1;
10941 elsif Pname = Name_Import then
10942 return Argn > 2;
10944 elsif Pname = Name_Interface_Name then
10945 return Argn > 1;
10947 elsif Pname = Name_Linker_Alias then
10948 return Argn = 2;
10950 elsif Pname = Name_Linker_Section then
10951 return Argn = 2;
10953 elsif Pname = Name_Machine_Attribute then
10954 return Argn = 2;
10956 elsif Pname = Name_Source_File_Name then
10957 return True;
10959 elsif Pname = Name_Source_Reference then
10960 return Argn = 2;
10962 elsif Pname = Name_Title then
10963 return True;
10965 elsif Pname = Name_Subtitle then
10966 return True;
10968 else
10969 return False;
10970 end if;
10971 end Is_Pragma_String_Literal;
10973 --------------------------------------
10974 -- Process_Compilation_Unit_Pragmas --
10975 --------------------------------------
10977 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
10978 begin
10979 -- A special check for pragma Suppress_All. This is a strange DEC
10980 -- pragma, strange because it comes at the end of the unit. If we
10981 -- have a pragma Suppress_All in the Pragmas_After of the current
10982 -- unit, then we insert a pragma Suppress (All_Checks) at the start
10983 -- of the context clause to ensure the correct processing.
10985 declare
10986 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
10987 P : Node_Id;
10989 begin
10990 if Present (PA) then
10991 P := First (PA);
10992 while Present (P) loop
10993 if Chars (P) = Name_Suppress_All then
10994 Prepend_To (Context_Items (N),
10995 Make_Pragma (Sloc (P),
10996 Chars => Name_Suppress,
10997 Pragma_Argument_Associations => New_List (
10998 Make_Pragma_Argument_Association (Sloc (P),
10999 Expression =>
11000 Make_Identifier (Sloc (P),
11001 Chars => Name_All_Checks)))));
11002 exit;
11003 end if;
11005 Next (P);
11006 end loop;
11007 end if;
11008 end;
11009 end Process_Compilation_Unit_Pragmas;
11011 --------------------------------
11012 -- Set_Encoded_Interface_Name --
11013 --------------------------------
11015 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
11016 Str : constant String_Id := Strval (S);
11017 Len : constant Int := String_Length (Str);
11018 CC : Char_Code;
11019 C : Character;
11020 J : Int;
11022 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
11024 procedure Encode;
11025 -- Stores encoded value of character code CC. The encoding we
11026 -- use an underscore followed by four lower case hex digits.
11028 ------------
11029 -- Encode --
11030 ------------
11032 procedure Encode is
11033 begin
11034 Store_String_Char (Get_Char_Code ('_'));
11035 Store_String_Char
11036 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
11037 Store_String_Char
11038 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
11039 Store_String_Char
11040 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
11041 Store_String_Char
11042 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
11043 end Encode;
11045 -- Start of processing for Set_Encoded_Interface_Name
11047 begin
11048 -- If first character is asterisk, this is a link name, and we
11049 -- leave it completely unmodified. We also ignore null strings
11050 -- (the latter case happens only in error cases) and no encoding
11051 -- should occur for Java interface names.
11053 if Len = 0
11054 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
11055 or else Java_VM
11056 then
11057 Set_Interface_Name (E, S);
11059 else
11060 J := 1;
11061 loop
11062 CC := Get_String_Char (Str, J);
11064 exit when not In_Character_Range (CC);
11066 C := Get_Character (CC);
11068 exit when C /= '_' and then C /= '$'
11069 and then C not in '0' .. '9'
11070 and then C not in 'a' .. 'z'
11071 and then C not in 'A' .. 'Z';
11073 if J = Len then
11074 Set_Interface_Name (E, S);
11075 return;
11077 else
11078 J := J + 1;
11079 end if;
11080 end loop;
11082 -- Here we need to encode. The encoding we use as follows:
11083 -- three underscores + four hex digits (lower case)
11085 Start_String;
11087 for J in 1 .. String_Length (Str) loop
11088 CC := Get_String_Char (Str, J);
11090 if not In_Character_Range (CC) then
11091 Encode;
11092 else
11093 C := Get_Character (CC);
11095 if C = '_' or else C = '$'
11096 or else C in '0' .. '9'
11097 or else C in 'a' .. 'z'
11098 or else C in 'A' .. 'Z'
11099 then
11100 Store_String_Char (CC);
11101 else
11102 Encode;
11103 end if;
11104 end if;
11105 end loop;
11107 Set_Interface_Name (E,
11108 Make_String_Literal (Sloc (S),
11109 Strval => End_String));
11110 end if;
11111 end Set_Encoded_Interface_Name;
11113 -------------------
11114 -- Set_Unit_Name --
11115 -------------------
11117 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
11118 Pref : Node_Id;
11119 Scop : Entity_Id;
11121 begin
11122 if Nkind (N) = N_Identifier
11123 and then Nkind (With_Item) = N_Identifier
11124 then
11125 Set_Entity (N, Entity (With_Item));
11127 elsif Nkind (N) = N_Selected_Component then
11128 Change_Selected_Component_To_Expanded_Name (N);
11129 Set_Entity (N, Entity (With_Item));
11130 Set_Entity (Selector_Name (N), Entity (N));
11132 Pref := Prefix (N);
11133 Scop := Scope (Entity (N));
11134 while Nkind (Pref) = N_Selected_Component loop
11135 Change_Selected_Component_To_Expanded_Name (Pref);
11136 Set_Entity (Selector_Name (Pref), Scop);
11137 Set_Entity (Pref, Scop);
11138 Pref := Prefix (Pref);
11139 Scop := Scope (Scop);
11140 end loop;
11142 Set_Entity (Pref, Scop);
11143 end if;
11144 end Set_Unit_Name;
11145 end Sem_Prag;