OSDN Git Service

2007-10-15 Hristian Kirtchev <kirtchev@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_prag.adb
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-2007, 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 3,  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 COPYING3.  If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license.          --
20 --                                                                          --
21 -- GNAT was originally developed  by the GNAT team at  New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 --  This unit contains the semantic processing for all pragmas, both language
27 --  and implementation defined. For most pragmas, the parser only does the
28 --  most basic job of checking the syntax, so Sem_Prag also contains the code
29 --  to complete the syntax checks. Certain pragmas are handled partially or
30 --  completely by the parser (see Par.Prag for further details).
31
32 with Atree;    use Atree;
33 with Casing;   use Casing;
34 with Checks;   use Checks;
35 with Csets;    use Csets;
36 with Debug;    use Debug;
37 with Einfo;    use Einfo;
38 with Errout;   use Errout;
39 with Exp_Dist; use Exp_Dist;
40 with Lib;      use Lib;
41 with Lib.Writ; use Lib.Writ;
42 with Lib.Xref; use Lib.Xref;
43 with Namet;    use Namet;
44 with Nlists;   use Nlists;
45 with Nmake;    use Nmake;
46 with Opt;      use Opt;
47 with Output;   use Output;
48 with Restrict; use Restrict;
49 with Rident;   use Rident;
50 with Rtsfind;  use Rtsfind;
51 with Sem;      use Sem;
52 with Sem_Ch3;  use Sem_Ch3;
53 with Sem_Ch8;  use Sem_Ch8;
54 with Sem_Ch13; use Sem_Ch13;
55 with Sem_Dist; use Sem_Dist;
56 with Sem_Elim; use Sem_Elim;
57 with Sem_Eval; use Sem_Eval;
58 with Sem_Intr; use Sem_Intr;
59 with Sem_Mech; use Sem_Mech;
60 with Sem_Res;  use Sem_Res;
61 with Sem_Type; use Sem_Type;
62 with Sem_Util; use Sem_Util;
63 with Sem_VFpt; use Sem_VFpt;
64 with Sem_Warn; use Sem_Warn;
65 with Stand;    use Stand;
66 with Sinfo;    use Sinfo;
67 with Sinfo.CN; use Sinfo.CN;
68 with Sinput;   use Sinput;
69 with Snames;   use Snames;
70 with Stringt;  use Stringt;
71 with Stylesw;  use Stylesw;
72 with Table;
73 with Targparm; use Targparm;
74 with Tbuild;   use Tbuild;
75 with Ttypes;
76 with Uintp;    use Uintp;
77 with Urealp;   use Urealp;
78 with Validsw;  use Validsw;
79
80 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
81
82 package body Sem_Prag is
83
84    ----------------------------------------------
85    -- Common Handling of Import-Export Pragmas --
86    ----------------------------------------------
87
88    --  In the following section, a number of Import_xxx and Export_xxx
89    --  pragmas are defined by GNAT. These are compatible with the DEC
90    --  pragmas of the same name, and all have the following common
91    --  form and processing:
92
93    --  pragma Export_xxx
94    --        [Internal                 =>] LOCAL_NAME,
95    --     [, [External                 =>] EXTERNAL_SYMBOL]
96    --     [, other optional parameters   ]);
97
98    --  pragma Import_xxx
99    --        [Internal                 =>] LOCAL_NAME,
100    --     [, [External                 =>] EXTERNAL_SYMBOL]
101    --     [, other optional parameters   ]);
102
103    --   EXTERNAL_SYMBOL ::=
104    --     IDENTIFIER
105    --   | static_string_EXPRESSION
106
107    --  The internal LOCAL_NAME designates the entity that is imported or
108    --  exported, and must refer to an entity in the current declarative
109    --  part (as required by the rules for LOCAL_NAME).
110
111    --  The external linker name is designated by the External parameter
112    --  if given, or the Internal parameter if not (if there is no External
113    --  parameter, the External parameter is a copy of the Internal name).
114
115    --  If the External parameter is given as a string, then this string
116    --  is treated as an external name (exactly as though it had been given
117    --  as an External_Name parameter for a normal Import pragma).
118
119    --  If the External parameter is given as an identifier (or there is no
120    --  External parameter, so that the Internal identifier is used), then
121    --  the external name is the characters of the identifier, translated
122    --  to all upper case letters for OpenVMS versions of GNAT, and to all
123    --  lower case letters for all other versions
124
125    --  Note: the external name specified or implied by any of these special
126    --  Import_xxx or Export_xxx pragmas override an external or link name
127    --  specified in a previous Import or Export pragma.
128
129    --  Note: these and all other DEC-compatible GNAT pragmas allow full
130    --  use of named notation, following the standard rules for subprogram
131    --  calls, i.e. parameters can be given in any order if named notation
132    --  is used, and positional and named notation can be mixed, subject to
133    --  the rule that all positional parameters must appear first.
134
135    --  Note: All these pragmas are implemented exactly following the DEC
136    --  design and implementation and are intended to be fully compatible
137    --  with the use of these pragmas in the DEC Ada compiler.
138
139    --------------------------------------------
140    -- Checking for Duplicated External Names --
141    --------------------------------------------
142
143    --  It is suspicious if two separate Export pragmas use the same external
144    --  name. The following table is used to diagnose this situation so that
145    --  an appropriate warning can be issued.
146
147    --  The Node_Id stored is for the N_String_Literal node created to
148    --  hold the value of the external name. The Sloc of this node is
149    --  used to cross-reference the location of the duplication.
150
151    package Externals is new Table.Table (
152      Table_Component_Type => Node_Id,
153      Table_Index_Type     => Int,
154      Table_Low_Bound      => 0,
155      Table_Initial        => 100,
156      Table_Increment      => 100,
157      Table_Name           => "Name_Externals");
158
159    -------------------------------------
160    -- Local Subprograms and Variables --
161    -------------------------------------
162
163    function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
164    --  This routine is used for possible casing adjustment of an explicit
165    --  external name supplied as a string literal (the node N), according
166    --  to the casing requirement of Opt.External_Name_Casing. If this is
167    --  set to As_Is, then the string literal is returned unchanged, but if
168    --  it is set to Uppercase or Lowercase, then a new string literal with
169    --  appropriate casing is constructed.
170
171    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
172    --  If Def_Id refers to a renamed subprogram, then the base subprogram
173    --  (the original one, following the renaming chain) is returned.
174    --  Otherwise the entity is returned unchanged. Should be in Einfo???
175
176    procedure rv;
177    --  This is a dummy function called by the processing for pragma Reviewable.
178    --  It is there for assisting front end debugging. By placing a Reviewable
179    --  pragma in the source program, a breakpoint on rv catches this place in
180    --  the source, allowing convenient stepping to the point of interest.
181
182    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
183    --  Place semantic information on the argument of an Elaborate or
184    --  Elaborate_All pragma. Entity name for unit and its parents is
185    --  taken from item in previous with_clause that mentions the unit.
186
187    -------------------------------
188    -- Adjust_External_Name_Case --
189    -------------------------------
190
191    function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
192       CC : Char_Code;
193
194    begin
195       --  Adjust case of literal if required
196
197       if Opt.External_Name_Exp_Casing = As_Is then
198          return N;
199
200       else
201          --  Copy existing string
202
203          Start_String;
204
205          --  Set proper casing
206
207          for J in 1 .. String_Length (Strval (N)) loop
208             CC := Get_String_Char (Strval (N), J);
209
210             if Opt.External_Name_Exp_Casing = Uppercase
211               and then CC >= Get_Char_Code ('a')
212               and then CC <= Get_Char_Code ('z')
213             then
214                Store_String_Char (CC - 32);
215
216             elsif Opt.External_Name_Exp_Casing = Lowercase
217               and then CC >= Get_Char_Code ('A')
218               and then CC <= Get_Char_Code ('Z')
219             then
220                Store_String_Char (CC + 32);
221
222             else
223                Store_String_Char (CC);
224             end if;
225          end loop;
226
227          return
228            Make_String_Literal (Sloc (N),
229              Strval => End_String);
230       end if;
231    end Adjust_External_Name_Case;
232
233    --------------------
234    -- Analyze_Pragma --
235    --------------------
236
237    procedure Analyze_Pragma (N : Node_Id) is
238       Loc     : constant Source_Ptr := Sloc (N);
239       Prag_Id : Pragma_Id;
240
241       Pragma_Exit : exception;
242       --  This exception is used to exit pragma processing completely. It
243       --  is used when an error is detected, and no further processing is
244       --  required. It is also used if an earlier error has left the tree
245       --  in a state where the pragma should not be processed.
246
247       Arg_Count : Nat;
248       --  Number of pragma argument associations
249
250       Arg1 : Node_Id;
251       Arg2 : Node_Id;
252       Arg3 : Node_Id;
253       Arg4 : Node_Id;
254       --  First four pragma arguments (pragma argument association nodes,
255       --  or Empty if the corresponding argument does not exist).
256
257       type Name_List is array (Natural range <>) of Name_Id;
258       type Args_List is array (Natural range <>) of Node_Id;
259       --  Types used for arguments to Check_Arg_Order and Gather_Associations
260
261       procedure Ada_2005_Pragma;
262       --  Called for pragmas defined in Ada 2005, that are not in Ada 95. In
263       --  Ada 95 mode, these are implementation defined pragmas, so should be
264       --  caught by the No_Implementation_Pragmas restriction
265
266       procedure Check_Ada_83_Warning;
267       --  Issues a warning message for the current pragma if operating in Ada
268       --  83 mode (used for language pragmas that are not a standard part of
269       --  Ada 83). This procedure does not raise Error_Pragma. Also notes use
270       --  of 95 pragma.
271
272       procedure Check_Arg_Count (Required : Nat);
273       --  Check argument count for pragma is equal to given parameter.
274       --  If not, then issue an error message and raise Pragma_Exit.
275
276       --  Note: all routines whose name is Check_Arg_Is_xxx take an
277       --  argument Arg which can either be a pragma argument association,
278       --  in which case the check is applied to the expression of the
279       --  association or an expression directly.
280
281       procedure Check_Arg_Is_External_Name (Arg : Node_Id);
282       --  Check that an argument has the right form for an EXTERNAL_NAME
283       --  parameter of an extended import/export pragma. The rule is that
284       --  the name must be an identifier or string literal (in Ada 83 mode)
285       --  or a static string expression (in Ada 95 mode).
286
287       procedure Check_Arg_Is_Identifier (Arg : Node_Id);
288       --  Check the specified argument Arg to make sure that it is an
289       --  identifier. If not give error and raise Pragma_Exit.
290
291       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
292       --  Check the specified argument Arg to make sure that it is an
293       --  integer literal. If not give error and raise Pragma_Exit.
294
295       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
296       --  Check the specified argument Arg to make sure that it has the
297       --  proper syntactic form for a local name and meets the semantic
298       --  requirements for a local name. The local name is analyzed as
299       --  part of the processing for this call. In addition, the local
300       --  name is required to represent an entity at the library level.
301
302       procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
303       --  Check the specified argument Arg to make sure that it has the
304       --  proper syntactic form for a local name and meets the semantic
305       --  requirements for a local name. The local name is analyzed as
306       --  part of the processing for this call.
307
308       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
309       --  Check the specified argument Arg to make sure that it is a valid
310       --  locking policy name. If not give error and raise Pragma_Exit.
311
312       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
313       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
314       --  Check the specified argument Arg to make sure that it is an
315       --  identifier whose name matches either N1 or N2 (or N3 if present).
316       --  If not then give error and raise Pragma_Exit.
317
318       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
319       --  Check the specified argument Arg to make sure that it is a valid
320       --  queuing policy name. If not give error and raise Pragma_Exit.
321
322       procedure Check_Arg_Is_Static_Expression
323         (Arg : Node_Id;
324          Typ : Entity_Id);
325       --  Check the specified argument Arg to make sure that it is a static
326       --  expression of the given type (i.e. it will be analyzed and resolved
327       --  using this type, which can be any valid argument to Resolve, e.g.
328       --  Any_Integer is OK). If not, given error and raise Pragma_Exit.
329
330       procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
331       --  Check the specified argument Arg to make sure that it is a
332       --  string literal. If not give error and raise Pragma_Exit
333
334       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
335       --  Check the specified argument Arg to make sure that it is a valid
336       --  valid task dispatching policy name. If not give error and raise
337       --  Pragma_Exit.
338
339       procedure Check_Arg_Order (Names : Name_List);
340       --  Checks for an instance of two arguments with identifiers for the
341       --  current pragma which are not in the sequence indicated by Names,
342       --  and if so, generates a fatal message about bad order of arguments.
343
344       procedure Check_At_Least_N_Arguments (N : Nat);
345       --  Check there are at least N arguments present
346
347       procedure Check_At_Most_N_Arguments (N : Nat);
348       --  Check there are no more than N arguments present
349
350       procedure Check_Component (Comp : Node_Id);
351       --  Examine Unchecked_Union component for correct use of per-object
352       --  constrained subtypes, and for restrictions on finalizable components.
353
354       procedure Check_Duplicated_Export_Name (Nam : Node_Id);
355       --  Nam is an N_String_Literal node containing the external name set
356       --  by an Import or Export pragma (or extended Import or Export pragma).
357       --  This procedure checks for possible duplications if this is the
358       --  export case, and if found, issues an appropriate error message.
359
360       procedure Check_First_Subtype (Arg : Node_Id);
361       --  Checks that Arg, whose expression is an entity name referencing
362       --  a subtype, does not reference a type that is not a first subtype.
363
364       procedure Check_In_Main_Program;
365       --  Common checks for pragmas that appear within a main program
366       --  (Priority, Main_Storage, Time_Slice).
367
368       procedure Check_Interrupt_Or_Attach_Handler;
369       --  Common processing for first argument of pragma Interrupt_Handler
370       --  or pragma Attach_Handler.
371
372       procedure Check_Is_In_Decl_Part_Or_Package_Spec;
373       --  Check that pragma appears in a declarative part, or in a package
374       --  specification, i.e. that it does not occur in a statement sequence
375       --  in a body.
376
377       procedure Check_No_Identifier (Arg : Node_Id);
378       --  Checks that the given argument does not have an identifier. If
379       --  an identifier is present, then an error message is issued, and
380       --  Pragma_Exit is raised.
381
382       procedure Check_No_Identifiers;
383       --  Checks that none of the arguments to the pragma has an identifier.
384       --  If any argument has an identifier, then an error message is issued,
385       --  and Pragma_Exit is raised.
386
387       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
388       --  Checks if the given argument has an identifier, and if so, requires
389       --  it to match the given identifier name. If there is a non-matching
390       --  identifier, then an error message is given and Error_Pragmas raised.
391
392       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
393       --  Checks if the given argument has an identifier, and if so, requires
394       --  it to match the given identifier name. If there is a non-matching
395       --  identifier, then an error message is given and Error_Pragmas raised.
396       --  In this version of the procedure, the identifier name is given as
397       --  a string with lower case letters.
398
399       procedure Check_Static_Constraint (Constr : Node_Id);
400       --  Constr is a constraint from an N_Subtype_Indication node from a
401       --  component constraint in an Unchecked_Union type. This routine checks
402       --  that the constraint is static as required by the restrictions for
403       --  Unchecked_Union.
404
405       procedure Check_Valid_Configuration_Pragma;
406       --  Legality checks for placement of a configuration pragma
407
408       procedure Check_Valid_Library_Unit_Pragma;
409       --  Legality checks for library unit pragmas. A special case arises for
410       --  pragmas in generic instances that come from copies of the original
411       --  library unit pragmas in the generic templates. In the case of other
412       --  than library level instantiations these can appear in contexts which
413       --  would normally be invalid (they only apply to the original template
414       --  and to library level instantiations), and they are simply ignored,
415       --  which is implemented by rewriting them as null statements.
416
417       procedure Check_Variant (Variant : Node_Id);
418       --  Check Unchecked_Union variant for lack of nested variants and
419       --  presence of at least one component.
420
421       procedure Error_Pragma (Msg : String);
422       pragma No_Return (Error_Pragma);
423       --  Outputs error message for current pragma. The message contains an %
424       --  that will be replaced with the pragma name, and the flag is placed
425       --  on the pragma itself. Pragma_Exit is then raised.
426
427       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
428       pragma No_Return (Error_Pragma_Arg);
429       --  Outputs error message for current pragma. The message may contain
430       --  a % that will be replaced with the pragma name. The parameter Arg
431       --  may either be a pragma argument association, in which case the flag
432       --  is placed on the expression of this association, or an expression,
433       --  in which case the flag is placed directly on the expression. The
434       --  message is placed using Error_Msg_N, so the message may also contain
435       --  an & insertion character which will reference the given Arg value.
436       --  After placing the message, Pragma_Exit is raised.
437
438       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
439       pragma No_Return (Error_Pragma_Arg);
440       --  Similar to above form of Error_Pragma_Arg except that two messages
441       --  are provided, the second is a continuation comment starting with \.
442
443       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
444       pragma No_Return (Error_Pragma_Arg_Ident);
445       --  Outputs error message for current pragma. The message may contain
446       --  a % that will be replaced with the pragma name. The parameter Arg
447       --  must be a pragma argument association with a non-empty identifier
448       --  (i.e. its Chars field must be set), and the error message is placed
449       --  on the identifier. The message is placed using Error_Msg_N so
450       --  the message may also contain an & insertion character which will
451       --  reference the identifier. After placing the message, Pragma_Exit
452       --  is raised.
453
454       function Find_Lib_Unit_Name return Entity_Id;
455       --  Used for a library unit pragma to find the entity to which the
456       --  library unit pragma applies, returns the entity found.
457
458       procedure Find_Program_Unit_Name (Id : Node_Id);
459       --  If the pragma is a compilation unit pragma, the id must denote the
460       --  compilation unit in the same compilation, and the pragma must appear
461       --  in the list of preceding or trailing pragmas. If it is a program
462       --  unit pragma that is not a compilation unit pragma, then the
463       --  identifier must be visible.
464
465       function Find_Unique_Parameterless_Procedure
466         (Name : Entity_Id;
467          Arg  : Node_Id) return Entity_Id;
468       --  Used for a procedure pragma to find the unique parameterless
469       --  procedure identified by Name, returns it if it exists, otherwise
470       --  errors out and uses Arg as the pragma argument for the message.
471
472       procedure Gather_Associations
473         (Names : Name_List;
474          Args  : out Args_List);
475       --  This procedure is used to gather the arguments for a pragma that
476       --  permits arbitrary ordering of parameters using the normal rules
477       --  for named and positional parameters. The Names argument is a list
478       --  of Name_Id values that corresponds to the allowed pragma argument
479       --  association identifiers in order. The result returned in Args is
480       --  a list of corresponding expressions that are the pragma arguments.
481       --  Note that this is a list of expressions, not of pragma argument
482       --  associations (Gather_Associations has completely checked all the
483       --  optional identifiers when it returns). An entry in Args is Empty
484       --  on return if the corresponding argument is not present.
485
486       function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
487       --  All the routines that check pragma arguments take either a pragma
488       --  argument association (in which case the expression of the argument
489       --  association is checked), or the expression directly. The function
490       --  Get_Pragma_Arg is a utility used to deal with these two cases. If
491       --  Arg is a pragma argument association node, then its expression is
492       --  returned, otherwise Arg is returned unchanged.
493
494       procedure GNAT_Pragma;
495       --  Called for all GNAT defined pragmas to check the relevant restriction
496       --  (No_Implementation_Pragmas).
497
498       function Is_Before_First_Decl
499         (Pragma_Node : Node_Id;
500          Decls       : List_Id) return Boolean;
501       --  Return True if Pragma_Node is before the first declarative item in
502       --  Decls where Decls is the list of declarative items.
503
504       function Is_Configuration_Pragma return Boolean;
505       --  Deterermines if the placement of the current pragma is appropriate
506       --  for a configuration pragma (precedes the current compilation unit).
507
508       function Is_In_Context_Clause return Boolean;
509       --  Returns True if pragma appears within the context clause of a unit,
510       --  and False for any other placement (does not generate any messages).
511
512       function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
513       --  Analyzes the argument, and determines if it is a static string
514       --  expression, returns True if so, False if non-static or not String.
515
516       procedure Pragma_Misplaced;
517       --  Issue fatal error message for misplaced pragma
518
519       procedure Process_Atomic_Shared_Volatile;
520       --  Common processing for pragmas Atomic, Shared, Volatile. Note that
521       --  Shared is an obsolete Ada 83 pragma, treated as being identical
522       --  in effect to pragma Atomic.
523
524       procedure Process_Compile_Time_Warning_Or_Error;
525       --  Common processing for Compile_Time_Error and Compile_Time_Warning
526
527       procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
528       --  Common procesing for Convention, Interface, Import and Export.
529       --  Checks first two arguments of pragma, and sets the appropriate
530       --  convention value in the specified entity or entities. On return
531       --  C is the convention, E is the referenced entity.
532
533       procedure Process_Extended_Import_Export_Exception_Pragma
534         (Arg_Internal : Node_Id;
535          Arg_External : Node_Id;
536          Arg_Form     : Node_Id;
537          Arg_Code     : Node_Id);
538       --  Common processing for the pragmas Import/Export_Exception.
539       --  The three arguments correspond to the three named parameters of
540       --  the pragma. An argument is empty if the corresponding parameter
541       --  is not present in the pragma.
542
543       procedure Process_Extended_Import_Export_Object_Pragma
544         (Arg_Internal : Node_Id;
545          Arg_External : Node_Id;
546          Arg_Size     : Node_Id);
547       --  Common processing for the pragmass Import/Export_Object.
548       --  The three arguments correspond to the three named parameters
549       --  of the pragmas. An argument is empty if the corresponding
550       --  parameter is not present in the pragma.
551
552       procedure Process_Extended_Import_Export_Internal_Arg
553         (Arg_Internal : Node_Id := Empty);
554       --  Common processing for all extended Import and Export pragmas. The
555       --  argument is the pragma parameter for the Internal argument. If
556       --  Arg_Internal is empty or inappropriate, an error message is posted.
557       --  Otherwise, on normal return, the Entity_Field of Arg_Internal is
558       --  set to identify the referenced entity.
559
560       procedure Process_Extended_Import_Export_Subprogram_Pragma
561         (Arg_Internal                 : Node_Id;
562          Arg_External                 : Node_Id;
563          Arg_Parameter_Types          : Node_Id;
564          Arg_Result_Type              : Node_Id := Empty;
565          Arg_Mechanism                : Node_Id;
566          Arg_Result_Mechanism         : Node_Id := Empty;
567          Arg_First_Optional_Parameter : Node_Id := Empty);
568       --  Common processing for all extended Import and Export pragmas
569       --  applying to subprograms. The caller omits any arguments that do
570       --  bnot apply to the pragma in question (for example, Arg_Result_Type
571       --  can be non-Empty only in the Import_Function and Export_Function
572       --  cases). The argument names correspond to the allowed pragma
573       --  association identifiers.
574
575       procedure Process_Generic_List;
576       --  Common processing for Share_Generic and Inline_Generic
577
578       procedure Process_Import_Or_Interface;
579       --  Common processing for Import of Interface
580
581       procedure Process_Inline (Active : Boolean);
582       --  Common processing for Inline and Inline_Always. The parameter
583       --  indicates if the inline pragma is active, i.e. if it should
584       --  actually cause inlining to occur.
585
586       procedure Process_Interface_Name
587         (Subprogram_Def : Entity_Id;
588          Ext_Arg        : Node_Id;
589          Link_Arg       : Node_Id);
590       --  Given the last two arguments of pragma Import, pragma Export, or
591       --  pragma Interface_Name, performs validity checks and sets the
592       --  Interface_Name field of the given subprogram entity to the
593       --  appropriate external or link name, depending on the arguments
594       --  given. Ext_Arg is always present, but Link_Arg may be missing.
595       --  Note that Ext_Arg may represent the Link_Name if Link_Arg is
596       --  missing, and appropriate named notation is used for Ext_Arg.
597       --  If neither Ext_Arg nor Link_Arg is present, the interface name
598       --  is set to the default from the subprogram name.
599
600       procedure Process_Interrupt_Or_Attach_Handler;
601       --  Common processing for Interrupt and Attach_Handler pragmas
602
603       procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
604       --  Common processing for Restrictions and Restriction_Warnings pragmas.
605       --  Warn is False for Restrictions, True for Restriction_Warnings.
606
607       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
608       --  Common processing for Suppress and Unsuppress. The boolean parameter
609       --  Suppress_Case is True for the Suppress case, and False for the
610       --  Unsuppress case.
611
612       procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
613       --  This procedure sets the Is_Exported flag for the given entity,
614       --  checking that the entity was not previously imported. Arg is
615       --  the argument that specified the entity. A check is also made
616       --  for exporting inappropriate entities.
617
618       procedure Set_Extended_Import_Export_External_Name
619         (Internal_Ent : Entity_Id;
620          Arg_External : Node_Id);
621       --  Common processing for all extended import export pragmas. The first
622       --  argument, Internal_Ent, is the internal entity, which has already
623       --  been checked for validity by the caller. Arg_External is from the
624       --  Import or Export pragma, and may be null if no External parameter
625       --  was present. If Arg_External is present and is a non-null string
626       --  (a null string is treated as the default), then the Interface_Name
627       --  field of Internal_Ent is set appropriately.
628
629       procedure Set_Imported (E : Entity_Id);
630       --  This procedure sets the Is_Imported flag for the given entity,
631       --  checking that it is not previously exported or imported.
632
633       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
634       --  Mech is a parameter passing mechanism (see Import_Function syntax
635       --  for MECHANISM_NAME). This routine checks that the mechanism argument
636       --  has the right form, and if not issues an error message. If the
637       --  argument has the right form then the Mechanism field of Ent is
638       --  set appropriately.
639
640       procedure Set_Ravenscar_Profile (N : Node_Id);
641       --  Activate the set of configuration pragmas and restrictions that
642       --  make up the Ravenscar Profile. N is the corresponding pragma
643       --  node, which is used for error messages on any constructs
644       --  that violate the profile.
645
646       ---------------------
647       -- Ada_2005_Pragma --
648       ---------------------
649
650       procedure Ada_2005_Pragma is
651       begin
652          if Ada_Version <= Ada_95 then
653             Check_Restriction (No_Implementation_Pragmas, N);
654          end if;
655       end Ada_2005_Pragma;
656
657       --------------------------
658       -- Check_Ada_83_Warning --
659       --------------------------
660
661       procedure Check_Ada_83_Warning is
662       begin
663          if Ada_Version = Ada_83 and then Comes_From_Source (N) then
664             Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
665          end if;
666       end Check_Ada_83_Warning;
667
668       ---------------------
669       -- Check_Arg_Count --
670       ---------------------
671
672       procedure Check_Arg_Count (Required : Nat) is
673       begin
674          if Arg_Count /= Required then
675             Error_Pragma ("wrong number of arguments for pragma%");
676          end if;
677       end Check_Arg_Count;
678
679       --------------------------------
680       -- Check_Arg_Is_External_Name --
681       --------------------------------
682
683       procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
684          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
685
686       begin
687          if Nkind (Argx) = N_Identifier then
688             return;
689
690          else
691             Analyze_And_Resolve (Argx, Standard_String);
692
693             if Is_OK_Static_Expression (Argx) then
694                return;
695
696             elsif Etype (Argx) = Any_Type then
697                raise Pragma_Exit;
698
699             --  An interesting special case, if we have a string literal and
700             --  we are in Ada 83 mode, then we allow it even though it will
701             --  not be flagged as static. This allows expected Ada 83 mode
702             --  use of external names which are string literals, even though
703             --  technically these are not static in Ada 83.
704
705             elsif Ada_Version = Ada_83
706               and then Nkind (Argx) = N_String_Literal
707             then
708                return;
709
710             --  Static expression that raises Constraint_Error. This has
711             --  already been flagged, so just exit from pragma processing.
712
713             elsif Is_Static_Expression (Argx) then
714                raise Pragma_Exit;
715
716             --  Here we have a real error (non-static expression)
717
718             else
719                Error_Msg_Name_1 := Chars (N);
720                Flag_Non_Static_Expr
721                  ("argument for pragma% must be a identifier or " &
722                   "static string expression!", Argx);
723                raise Pragma_Exit;
724             end if;
725          end if;
726       end Check_Arg_Is_External_Name;
727
728       -----------------------------
729       -- Check_Arg_Is_Identifier --
730       -----------------------------
731
732       procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
733          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
734       begin
735          if Nkind (Argx) /= N_Identifier then
736             Error_Pragma_Arg
737               ("argument for pragma% must be identifier", Argx);
738          end if;
739       end Check_Arg_Is_Identifier;
740
741       ----------------------------------
742       -- Check_Arg_Is_Integer_Literal --
743       ----------------------------------
744
745       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
746          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
747       begin
748          if Nkind (Argx) /= N_Integer_Literal then
749             Error_Pragma_Arg
750               ("argument for pragma% must be integer literal", Argx);
751          end if;
752       end Check_Arg_Is_Integer_Literal;
753
754       -------------------------------------------
755       -- Check_Arg_Is_Library_Level_Local_Name --
756       -------------------------------------------
757
758       --  LOCAL_NAME ::=
759       --    DIRECT_NAME
760       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
761       --  | library_unit_NAME
762
763       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
764       begin
765          Check_Arg_Is_Local_Name (Arg);
766
767          if not Is_Library_Level_Entity (Entity (Expression (Arg)))
768            and then Comes_From_Source (N)
769          then
770             Error_Pragma_Arg
771               ("argument for pragma% must be library level entity", Arg);
772          end if;
773       end Check_Arg_Is_Library_Level_Local_Name;
774
775       -----------------------------
776       -- Check_Arg_Is_Local_Name --
777       -----------------------------
778
779       --  LOCAL_NAME ::=
780       --    DIRECT_NAME
781       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
782       --  | library_unit_NAME
783
784       procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
785          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
786
787       begin
788          Analyze (Argx);
789
790          if Nkind (Argx) not in N_Direct_Name
791            and then (Nkind (Argx) /= N_Attribute_Reference
792                       or else Present (Expressions (Argx))
793                       or else Nkind (Prefix (Argx)) /= N_Identifier)
794            and then (not Is_Entity_Name (Argx)
795                       or else not Is_Compilation_Unit (Entity (Argx)))
796          then
797             Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
798          end if;
799
800          if Is_Entity_Name (Argx)
801            and then Scope (Entity (Argx)) /= Current_Scope
802          then
803             Error_Pragma_Arg
804               ("pragma% argument must be in same declarative part", Arg);
805          end if;
806       end Check_Arg_Is_Local_Name;
807
808       ---------------------------------
809       -- Check_Arg_Is_Locking_Policy --
810       ---------------------------------
811
812       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
813          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
814
815       begin
816          Check_Arg_Is_Identifier (Argx);
817
818          if not Is_Locking_Policy_Name (Chars (Argx)) then
819             Error_Pragma_Arg
820               ("& is not a valid locking policy name", Argx);
821          end if;
822       end Check_Arg_Is_Locking_Policy;
823
824       -------------------------
825       -- Check_Arg_Is_One_Of --
826       -------------------------
827
828       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
829          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
830
831       begin
832          Check_Arg_Is_Identifier (Argx);
833
834          if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
835             Error_Msg_Name_2 := N1;
836             Error_Msg_Name_3 := N2;
837             Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
838          end if;
839       end Check_Arg_Is_One_Of;
840
841       procedure Check_Arg_Is_One_Of
842         (Arg        : Node_Id;
843          N1, N2, N3 : Name_Id)
844       is
845          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
846
847       begin
848          Check_Arg_Is_Identifier (Argx);
849
850          if Chars (Argx) /= N1
851            and then Chars (Argx) /= N2
852            and then Chars (Argx) /= N3
853          then
854             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
855          end if;
856       end Check_Arg_Is_One_Of;
857
858       ---------------------------------
859       -- Check_Arg_Is_Queuing_Policy --
860       ---------------------------------
861
862       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
863          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
864
865       begin
866          Check_Arg_Is_Identifier (Argx);
867
868          if not Is_Queuing_Policy_Name (Chars (Argx)) then
869             Error_Pragma_Arg
870               ("& is not a valid queuing policy name", Argx);
871          end if;
872       end Check_Arg_Is_Queuing_Policy;
873
874       ------------------------------------
875       -- Check_Arg_Is_Static_Expression --
876       ------------------------------------
877
878       procedure Check_Arg_Is_Static_Expression
879         (Arg : Node_Id;
880          Typ : Entity_Id)
881       is
882          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
883
884       begin
885          Analyze_And_Resolve (Argx, Typ);
886
887          if Is_OK_Static_Expression (Argx) then
888             return;
889
890          elsif Etype (Argx) = Any_Type then
891             raise Pragma_Exit;
892
893          --  An interesting special case, if we have a string literal and
894          --  we are in Ada 83 mode, then we allow it even though it will
895          --  not be flagged as static. This allows the use of Ada 95
896          --  pragmas like Import in Ada 83 mode. They will of course be
897          --  flagged with warnings as usual, but will not cause errors.
898
899          elsif Ada_Version = Ada_83
900            and then Nkind (Argx) = N_String_Literal
901          then
902             return;
903
904          --  Static expression that raises Constraint_Error. This has
905          --  already been flagged, so just exit from pragma processing.
906
907          elsif Is_Static_Expression (Argx) then
908             raise Pragma_Exit;
909
910          --  Finally, we have a real error
911
912          else
913             Error_Msg_Name_1 := Chars (N);
914             Flag_Non_Static_Expr
915               ("argument for pragma% must be a static expression!", Argx);
916             raise Pragma_Exit;
917          end if;
918       end Check_Arg_Is_Static_Expression;
919
920       ---------------------------------
921       -- Check_Arg_Is_String_Literal --
922       ---------------------------------
923
924       procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
925          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
926       begin
927          if Nkind (Argx) /= N_String_Literal then
928             Error_Pragma_Arg
929               ("argument for pragma% must be string literal", Argx);
930          end if;
931       end Check_Arg_Is_String_Literal;
932
933       ------------------------------------------
934       -- Check_Arg_Is_Task_Dispatching_Policy --
935       ------------------------------------------
936
937       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
938          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
939
940       begin
941          Check_Arg_Is_Identifier (Argx);
942
943          if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
944             Error_Pragma_Arg
945               ("& is not a valid task dispatching policy name", Argx);
946          end if;
947       end Check_Arg_Is_Task_Dispatching_Policy;
948
949       ---------------------
950       -- Check_Arg_Order --
951       ---------------------
952
953       procedure Check_Arg_Order (Names : Name_List) is
954          Arg : Node_Id;
955
956          Highest_So_Far : Natural := 0;
957          --  Highest index in Names seen do far
958
959       begin
960          Arg := Arg1;
961          for J in 1 .. Arg_Count loop
962             if Chars (Arg) /= No_Name then
963                for K in Names'Range loop
964                   if Chars (Arg) = Names (K) then
965                      if K < Highest_So_Far then
966                         Error_Msg_Name_1 := Chars (N);
967                         Error_Msg_N
968                           ("parameters out of order for pragma%", Arg);
969                         Error_Msg_Name_1 := Names (K);
970                         Error_Msg_Name_2 := Names (Highest_So_Far);
971                         Error_Msg_N ("\% must appear before %", Arg);
972                         raise Pragma_Exit;
973
974                      else
975                         Highest_So_Far := K;
976                      end if;
977                   end if;
978                end loop;
979             end if;
980
981             Arg := Next (Arg);
982          end loop;
983       end Check_Arg_Order;
984
985       --------------------------------
986       -- Check_At_Least_N_Arguments --
987       --------------------------------
988
989       procedure Check_At_Least_N_Arguments (N : Nat) is
990       begin
991          if Arg_Count < N then
992             Error_Pragma ("too few arguments for pragma%");
993          end if;
994       end Check_At_Least_N_Arguments;
995
996       -------------------------------
997       -- Check_At_Most_N_Arguments --
998       -------------------------------
999
1000       procedure Check_At_Most_N_Arguments (N : Nat) is
1001          Arg : Node_Id;
1002       begin
1003          if Arg_Count > N then
1004             Arg := Arg1;
1005             for J in 1 .. N loop
1006                Next (Arg);
1007                Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1008             end loop;
1009          end if;
1010       end Check_At_Most_N_Arguments;
1011
1012       ---------------------
1013       -- Check_Component --
1014       ---------------------
1015
1016       procedure Check_Component (Comp : Node_Id) is
1017       begin
1018          if Nkind (Comp) = N_Component_Declaration then
1019             declare
1020                Sindic : constant Node_Id :=
1021                           Subtype_Indication (Component_Definition (Comp));
1022                Typ    : constant Entity_Id :=
1023                           Etype (Defining_Identifier (Comp));
1024             begin
1025                if Nkind (Sindic) = N_Subtype_Indication then
1026
1027                   --  Ada 2005 (AI-216): If a component subtype is subject to
1028                   --  a per-object constraint, then the component type shall
1029                   --  be an Unchecked_Union.
1030
1031                   if Has_Per_Object_Constraint (Defining_Identifier (Comp))
1032                     and then
1033                       not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1034                   then
1035                      Error_Msg_N ("component subtype subject to per-object" &
1036                        " constraint must be an Unchecked_Union", Comp);
1037                   end if;
1038                end if;
1039
1040                if Is_Controlled (Typ) then
1041                   Error_Msg_N
1042                    ("component of unchecked union cannot be controlled", Comp);
1043
1044                elsif Has_Task (Typ) then
1045                   Error_Msg_N
1046                    ("component of unchecked union cannot have tasks", Comp);
1047                end if;
1048             end;
1049          end if;
1050       end Check_Component;
1051
1052       ----------------------------------
1053       -- Check_Duplicated_Export_Name --
1054       ----------------------------------
1055
1056       procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1057          String_Val : constant String_Id := Strval (Nam);
1058
1059       begin
1060          --  We are only interested in the export case, and in the case of
1061          --  generics, it is the instance, not the template, that is the
1062          --  problem (the template will generate a warning in any case).
1063
1064          if not Inside_A_Generic
1065            and then (Prag_Id = Pragma_Export
1066                        or else
1067                      Prag_Id = Pragma_Export_Procedure
1068                        or else
1069                      Prag_Id = Pragma_Export_Valued_Procedure
1070                        or else
1071                      Prag_Id = Pragma_Export_Function)
1072          then
1073             for J in Externals.First .. Externals.Last loop
1074                if String_Equal (String_Val, Strval (Externals.Table (J))) then
1075                   Error_Msg_Sloc := Sloc (Externals.Table (J));
1076                   Error_Msg_N ("external name duplicates name given#", Nam);
1077                   exit;
1078                end if;
1079             end loop;
1080
1081             Externals.Append (Nam);
1082          end if;
1083       end Check_Duplicated_Export_Name;
1084
1085       -------------------------
1086       -- Check_First_Subtype --
1087       -------------------------
1088
1089       procedure Check_First_Subtype (Arg : Node_Id) is
1090          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1091       begin
1092          if not Is_First_Subtype (Entity (Argx)) then
1093             Error_Pragma_Arg
1094               ("pragma% cannot apply to subtype", Argx);
1095          end if;
1096       end Check_First_Subtype;
1097
1098       ---------------------------
1099       -- Check_In_Main_Program --
1100       ---------------------------
1101
1102       procedure Check_In_Main_Program is
1103          P : constant Node_Id := Parent (N);
1104
1105       begin
1106          --  Must be at in subprogram body
1107
1108          if Nkind (P) /= N_Subprogram_Body then
1109             Error_Pragma ("% pragma allowed only in subprogram");
1110
1111          --  Otherwise warn if obviously not main program
1112
1113          elsif Present (Parameter_Specifications (Specification (P)))
1114            or else not Is_Compilation_Unit (Defining_Entity (P))
1115          then
1116             Error_Msg_Name_1 := Chars (N);
1117             Error_Msg_N
1118               ("?pragma% is only effective in main program", N);
1119          end if;
1120       end Check_In_Main_Program;
1121
1122       ---------------------------------------
1123       -- Check_Interrupt_Or_Attach_Handler --
1124       ---------------------------------------
1125
1126       procedure Check_Interrupt_Or_Attach_Handler is
1127          Arg1_X : constant Node_Id := Expression (Arg1);
1128          Handler_Proc, Proc_Scope : Entity_Id;
1129
1130       begin
1131          Analyze (Arg1_X);
1132
1133          if Prag_Id = Pragma_Interrupt_Handler then
1134             Check_Restriction (No_Dynamic_Attachment, N);
1135          end if;
1136
1137          Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1138          Proc_Scope := Scope (Handler_Proc);
1139
1140          --  On AAMP only, a pragma Interrupt_Handler is supported for
1141          --  nonprotected parameterless procedures.
1142
1143          if not AAMP_On_Target
1144            or else Prag_Id = Pragma_Attach_Handler
1145          then
1146             if Ekind (Proc_Scope) /= E_Protected_Type then
1147                Error_Pragma_Arg
1148                  ("argument of pragma% must be protected procedure", Arg1);
1149             end if;
1150
1151             if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1152                Error_Pragma ("pragma% must be in protected definition");
1153             end if;
1154          end if;
1155
1156          if not Is_Library_Level_Entity (Proc_Scope)
1157            or else (AAMP_On_Target
1158                      and then not Is_Library_Level_Entity (Handler_Proc))
1159          then
1160             Error_Pragma_Arg
1161               ("argument for pragma% must be library level entity", Arg1);
1162          end if;
1163       end Check_Interrupt_Or_Attach_Handler;
1164
1165       -------------------------------------------
1166       -- Check_Is_In_Decl_Part_Or_Package_Spec --
1167       -------------------------------------------
1168
1169       procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1170          P : Node_Id;
1171
1172       begin
1173          P := Parent (N);
1174          loop
1175             if No (P) then
1176                exit;
1177
1178             elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1179                exit;
1180
1181             elsif Nkind (P) = N_Package_Specification then
1182                return;
1183
1184             elsif Nkind (P) = N_Block_Statement then
1185                return;
1186
1187             --  Note: the following tests seem a little peculiar, because
1188             --  they test for bodies, but if we were in the statement part
1189             --  of the body, we would already have hit the handled statement
1190             --  sequence, so the only way we get here is by being in the
1191             --  declarative part of the body.
1192
1193             elsif Nkind (P) = N_Subprogram_Body
1194               or else Nkind (P) = N_Package_Body
1195               or else Nkind (P) = N_Task_Body
1196               or else Nkind (P) = N_Entry_Body
1197             then
1198                return;
1199             end if;
1200
1201             P := Parent (P);
1202          end loop;
1203
1204          Error_Pragma ("pragma% is not in declarative part or package spec");
1205       end Check_Is_In_Decl_Part_Or_Package_Spec;
1206
1207       -------------------------
1208       -- Check_No_Identifier --
1209       -------------------------
1210
1211       procedure Check_No_Identifier (Arg : Node_Id) is
1212       begin
1213          if Chars (Arg) /= No_Name then
1214             Error_Pragma_Arg_Ident
1215               ("pragma% does not permit identifier& here", Arg);
1216          end if;
1217       end Check_No_Identifier;
1218
1219       --------------------------
1220       -- Check_No_Identifiers --
1221       --------------------------
1222
1223       procedure Check_No_Identifiers is
1224          Arg_Node : Node_Id;
1225       begin
1226          if Arg_Count > 0 then
1227             Arg_Node := Arg1;
1228             while Present (Arg_Node) loop
1229                Check_No_Identifier (Arg_Node);
1230                Next (Arg_Node);
1231             end loop;
1232          end if;
1233       end Check_No_Identifiers;
1234
1235       -------------------------------
1236       -- Check_Optional_Identifier --
1237       -------------------------------
1238
1239       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1240       begin
1241          if Present (Arg) and then Chars (Arg) /= No_Name then
1242             if Chars (Arg) /= Id then
1243                Error_Msg_Name_1 := Chars (N);
1244                Error_Msg_Name_2 := Id;
1245                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1246                raise Pragma_Exit;
1247             end if;
1248          end if;
1249       end Check_Optional_Identifier;
1250
1251       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1252       begin
1253          Name_Buffer (1 .. Id'Length) := Id;
1254          Name_Len := Id'Length;
1255          Check_Optional_Identifier (Arg, Name_Find);
1256       end Check_Optional_Identifier;
1257
1258       -----------------------------
1259       -- Check_Static_Constraint --
1260       -----------------------------
1261
1262       --  Note: for convenience in writing this procedure, in addition to
1263       --  the officially (i.e. by spec) allowed argument which is always
1264       --  a constraint, it also allows ranges and discriminant associations.
1265       --  Above is not clear ???
1266
1267       procedure Check_Static_Constraint (Constr : Node_Id) is
1268
1269          --------------------
1270          -- Require_Static --
1271          --------------------
1272
1273          procedure Require_Static (E : Node_Id);
1274          --  Require given expression to be static expression
1275
1276          procedure Require_Static (E : Node_Id) is
1277          begin
1278             if not Is_OK_Static_Expression (E) then
1279                Flag_Non_Static_Expr
1280                  ("non-static constraint not allowed in Unchecked_Union!", E);
1281                raise Pragma_Exit;
1282             end if;
1283          end Require_Static;
1284
1285       --  Start of processing for Check_Static_Constraint
1286
1287       begin
1288          case Nkind (Constr) is
1289             when N_Discriminant_Association =>
1290                Require_Static (Expression (Constr));
1291
1292             when N_Range =>
1293                Require_Static (Low_Bound (Constr));
1294                Require_Static (High_Bound (Constr));
1295
1296             when N_Attribute_Reference =>
1297                Require_Static (Type_Low_Bound  (Etype (Prefix (Constr))));
1298                Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1299
1300             when N_Range_Constraint =>
1301                Check_Static_Constraint (Range_Expression (Constr));
1302
1303             when N_Index_Or_Discriminant_Constraint =>
1304                declare
1305                   IDC : Entity_Id;
1306                begin
1307                   IDC := First (Constraints (Constr));
1308                   while Present (IDC) loop
1309                      Check_Static_Constraint (IDC);
1310                      Next (IDC);
1311                   end loop;
1312                end;
1313
1314             when others =>
1315                null;
1316          end case;
1317       end Check_Static_Constraint;
1318
1319       --------------------------------------
1320       -- Check_Valid_Configuration_Pragma --
1321       --------------------------------------
1322
1323       --  A configuration pragma must appear in the context clause of
1324       --  a compilation unit, at the start of the list (i.e. only other
1325       --  pragmas may precede it).
1326
1327       procedure Check_Valid_Configuration_Pragma is
1328       begin
1329          if not Is_Configuration_Pragma then
1330             Error_Pragma ("incorrect placement for configuration pragma%");
1331          end if;
1332       end Check_Valid_Configuration_Pragma;
1333
1334       -------------------------------------
1335       -- Check_Valid_Library_Unit_Pragma --
1336       -------------------------------------
1337
1338       procedure Check_Valid_Library_Unit_Pragma is
1339          Plist       : List_Id;
1340          Parent_Node : Node_Id;
1341          Unit_Name   : Entity_Id;
1342          Unit_Kind   : Node_Kind;
1343          Unit_Node   : Node_Id;
1344          Sindex      : Source_File_Index;
1345
1346       begin
1347          if not Is_List_Member (N) then
1348             Pragma_Misplaced;
1349
1350          else
1351             Plist := List_Containing (N);
1352             Parent_Node := Parent (Plist);
1353
1354             if Parent_Node = Empty then
1355                Pragma_Misplaced;
1356
1357             --  Case of pragma appearing after a compilation unit. In this
1358             --  case it must have an argument with the corresponding name
1359             --  and must be part of the following pragmas of its parent.
1360
1361             elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1362                if Plist /= Pragmas_After (Parent_Node) then
1363                   Pragma_Misplaced;
1364
1365                elsif Arg_Count = 0 then
1366                   Error_Pragma
1367                     ("argument required if outside compilation unit");
1368
1369                else
1370                   Check_No_Identifiers;
1371                   Check_Arg_Count (1);
1372                   Unit_Node := Unit (Parent (Parent_Node));
1373                   Unit_Kind := Nkind (Unit_Node);
1374
1375                   Analyze (Expression (Arg1));
1376
1377                   if Unit_Kind = N_Generic_Subprogram_Declaration
1378                     or else Unit_Kind = N_Subprogram_Declaration
1379                   then
1380                      Unit_Name := Defining_Entity (Unit_Node);
1381
1382                   elsif Unit_Kind in N_Generic_Instantiation then
1383                      Unit_Name := Defining_Entity (Unit_Node);
1384
1385                   else
1386                      Unit_Name := Cunit_Entity (Current_Sem_Unit);
1387                   end if;
1388
1389                   if Chars (Unit_Name) /=
1390                      Chars (Entity (Expression (Arg1)))
1391                   then
1392                      Error_Pragma_Arg
1393                        ("pragma% argument is not current unit name", Arg1);
1394                   end if;
1395
1396                   if Ekind (Unit_Name) = E_Package
1397                     and then Present (Renamed_Entity (Unit_Name))
1398                   then
1399                      Error_Pragma ("pragma% not allowed for renamed package");
1400                   end if;
1401                end if;
1402
1403             --  Pragma appears other than after a compilation unit
1404
1405             else
1406                --  Here we check for the generic instantiation case and also
1407                --  for the case of processing a generic formal package. We
1408                --  detect these cases by noting that the Sloc on the node
1409                --  does not belong to the current compilation unit.
1410
1411                Sindex := Source_Index (Current_Sem_Unit);
1412
1413                if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1414                   Rewrite (N, Make_Null_Statement (Loc));
1415                   return;
1416
1417                --  If before first declaration, the pragma applies to the
1418                --  enclosing unit, and the name if present must be this name.
1419
1420                elsif Is_Before_First_Decl (N, Plist) then
1421                   Unit_Node := Unit_Declaration_Node (Current_Scope);
1422                   Unit_Kind := Nkind (Unit_Node);
1423
1424                   if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1425                      Pragma_Misplaced;
1426
1427                   elsif Unit_Kind = N_Subprogram_Body
1428                     and then not Acts_As_Spec (Unit_Node)
1429                   then
1430                      Pragma_Misplaced;
1431
1432                   elsif Nkind (Parent_Node) = N_Package_Body then
1433                      Pragma_Misplaced;
1434
1435                   elsif Nkind (Parent_Node) = N_Package_Specification
1436                     and then Plist = Private_Declarations (Parent_Node)
1437                   then
1438                      Pragma_Misplaced;
1439
1440                   elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1441                            or else Nkind (Parent_Node) =
1442                                              N_Generic_Subprogram_Declaration)
1443                     and then Plist = Generic_Formal_Declarations (Parent_Node)
1444                   then
1445                      Pragma_Misplaced;
1446
1447                   elsif Arg_Count > 0 then
1448                      Analyze (Expression (Arg1));
1449
1450                      if Entity (Expression (Arg1)) /= Current_Scope then
1451                         Error_Pragma_Arg
1452                           ("name in pragma% must be enclosing unit", Arg1);
1453                      end if;
1454
1455                   --  It is legal to have no argument in this context
1456
1457                   else
1458                      return;
1459                   end if;
1460
1461                --  Error if not before first declaration. This is because a
1462                --  library unit pragma argument must be the name of a library
1463                --  unit (RM 10.1.5(7)), but the only names permitted in this
1464                --  context are (RM 10.1.5(6)) names of subprogram declarations,
1465                --  generic subprogram declarations or generic instantiations.
1466
1467                else
1468                   Error_Pragma
1469                     ("pragma% misplaced, must be before first declaration");
1470                end if;
1471             end if;
1472          end if;
1473       end Check_Valid_Library_Unit_Pragma;
1474
1475       -------------------
1476       -- Check_Variant --
1477       -------------------
1478
1479       procedure Check_Variant (Variant : Node_Id) is
1480          Clist : constant Node_Id := Component_List (Variant);
1481          Comp  : Node_Id;
1482
1483       begin
1484          if not Is_Non_Empty_List (Component_Items (Clist)) then
1485             Error_Msg_N
1486               ("Unchecked_Union may not have empty component list",
1487                Variant);
1488             return;
1489          end if;
1490
1491          Comp := First (Component_Items (Clist));
1492          while Present (Comp) loop
1493             Check_Component (Comp);
1494             Next (Comp);
1495          end loop;
1496       end Check_Variant;
1497
1498       ------------------
1499       -- Error_Pragma --
1500       ------------------
1501
1502       procedure Error_Pragma (Msg : String) is
1503       begin
1504          Error_Msg_Name_1 := Chars (N);
1505          Error_Msg_N (Msg, N);
1506          raise Pragma_Exit;
1507       end Error_Pragma;
1508
1509       ----------------------
1510       -- Error_Pragma_Arg --
1511       ----------------------
1512
1513       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1514       begin
1515          Error_Msg_Name_1 := Chars (N);
1516          Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1517          raise Pragma_Exit;
1518       end Error_Pragma_Arg;
1519
1520       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1521       begin
1522          Error_Msg_Name_1 := Chars (N);
1523          Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1524          Error_Pragma_Arg (Msg2, Arg);
1525       end Error_Pragma_Arg;
1526
1527       ----------------------------
1528       -- Error_Pragma_Arg_Ident --
1529       ----------------------------
1530
1531       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1532       begin
1533          Error_Msg_Name_1 := Chars (N);
1534          Error_Msg_N (Msg, Arg);
1535          raise Pragma_Exit;
1536       end Error_Pragma_Arg_Ident;
1537
1538       ------------------------
1539       -- Find_Lib_Unit_Name --
1540       ------------------------
1541
1542       function Find_Lib_Unit_Name return Entity_Id is
1543       begin
1544          --  Return inner compilation unit entity, for case of nested
1545          --  categorization pragmas. This happens in generic unit.
1546
1547          if Nkind (Parent (N)) = N_Package_Specification
1548            and then Defining_Entity (Parent (N)) /= Current_Scope
1549          then
1550             return Defining_Entity (Parent (N));
1551          else
1552             return Current_Scope;
1553          end if;
1554       end Find_Lib_Unit_Name;
1555
1556       ----------------------------
1557       -- Find_Program_Unit_Name --
1558       ----------------------------
1559
1560       procedure Find_Program_Unit_Name (Id : Node_Id) is
1561          Unit_Name : Entity_Id;
1562          Unit_Kind : Node_Kind;
1563          P         : constant Node_Id := Parent (N);
1564
1565       begin
1566          if Nkind (P) = N_Compilation_Unit then
1567             Unit_Kind := Nkind (Unit (P));
1568
1569             if Unit_Kind = N_Subprogram_Declaration
1570               or else Unit_Kind = N_Package_Declaration
1571               or else Unit_Kind in N_Generic_Declaration
1572             then
1573                Unit_Name := Defining_Entity (Unit (P));
1574
1575                if Chars (Id) = Chars (Unit_Name) then
1576                   Set_Entity (Id, Unit_Name);
1577                   Set_Etype (Id, Etype (Unit_Name));
1578                else
1579                   Set_Etype (Id, Any_Type);
1580                   Error_Pragma
1581                     ("cannot find program unit referenced by pragma%");
1582                end if;
1583
1584             else
1585                Set_Etype (Id, Any_Type);
1586                Error_Pragma ("pragma% inapplicable to this unit");
1587             end if;
1588
1589          else
1590             Analyze (Id);
1591          end if;
1592       end Find_Program_Unit_Name;
1593
1594       -----------------------------------------
1595       -- Find_Unique_Parameterless_Procedure --
1596       -----------------------------------------
1597
1598       function Find_Unique_Parameterless_Procedure
1599         (Name : Entity_Id;
1600          Arg  : Node_Id) return Entity_Id
1601       is
1602          Proc : Entity_Id := Empty;
1603
1604       begin
1605          --  The body of this procedure needs some comments ???
1606
1607          if not Is_Entity_Name (Name) then
1608             Error_Pragma_Arg
1609               ("argument of pragma% must be entity name", Arg);
1610
1611          elsif not Is_Overloaded (Name) then
1612             Proc := Entity (Name);
1613
1614             if Ekind (Proc) /= E_Procedure
1615                  or else Present (First_Formal (Proc)) then
1616                Error_Pragma_Arg
1617                  ("argument of pragma% must be parameterless procedure", Arg);
1618             end if;
1619
1620          else
1621             declare
1622                Found : Boolean := False;
1623                It    : Interp;
1624                Index : Interp_Index;
1625
1626             begin
1627                Get_First_Interp (Name, Index, It);
1628                while Present (It.Nam) loop
1629                   Proc := It.Nam;
1630
1631                   if Ekind (Proc) = E_Procedure
1632                     and then No (First_Formal (Proc))
1633                   then
1634                      if not Found then
1635                         Found := True;
1636                         Set_Entity (Name, Proc);
1637                         Set_Is_Overloaded (Name, False);
1638                      else
1639                         Error_Pragma_Arg
1640                           ("ambiguous handler name for pragma% ", Arg);
1641                      end if;
1642                   end if;
1643
1644                   Get_Next_Interp (Index, It);
1645                end loop;
1646
1647                if not Found then
1648                   Error_Pragma_Arg
1649                     ("argument of pragma% must be parameterless procedure",
1650                      Arg);
1651                else
1652                   Proc := Entity (Name);
1653                end if;
1654             end;
1655          end if;
1656
1657          return Proc;
1658       end Find_Unique_Parameterless_Procedure;
1659
1660       -------------------------
1661       -- Gather_Associations --
1662       -------------------------
1663
1664       procedure Gather_Associations
1665         (Names : Name_List;
1666          Args  : out Args_List)
1667       is
1668          Arg : Node_Id;
1669
1670       begin
1671          --  Initialize all parameters to Empty
1672
1673          for J in Args'Range loop
1674             Args (J) := Empty;
1675          end loop;
1676
1677          --  That's all we have to do if there are no argument associations
1678
1679          if No (Pragma_Argument_Associations (N)) then
1680             return;
1681          end if;
1682
1683          --  Otherwise first deal with any positional parameters present
1684
1685          Arg := First (Pragma_Argument_Associations (N));
1686          for Index in Args'Range loop
1687             exit when No (Arg) or else Chars (Arg) /= No_Name;
1688             Args (Index) := Expression (Arg);
1689             Next (Arg);
1690          end loop;
1691
1692          --  Positional parameters all processed, if any left, then we
1693          --  have too many positional parameters.
1694
1695          if Present (Arg) and then Chars (Arg) = No_Name then
1696             Error_Pragma_Arg
1697               ("too many positional associations for pragma%", Arg);
1698          end if;
1699
1700          --  Process named parameters if any are present
1701
1702          while Present (Arg) loop
1703             if Chars (Arg) = No_Name then
1704                Error_Pragma_Arg
1705                  ("positional association cannot follow named association",
1706                   Arg);
1707
1708             else
1709                for Index in Names'Range loop
1710                   if Names (Index) = Chars (Arg) then
1711                      if Present (Args (Index)) then
1712                         Error_Pragma_Arg
1713                           ("duplicate argument association for pragma%", Arg);
1714                      else
1715                         Args (Index) := Expression (Arg);
1716                         exit;
1717                      end if;
1718                   end if;
1719
1720                   if Index = Names'Last then
1721                      Error_Msg_Name_1 := Chars (N);
1722                      Error_Msg_N ("pragma% does not allow & argument", Arg);
1723
1724                      --  Check for possible misspelling
1725
1726                      for Index1 in Names'Range loop
1727                         if Is_Bad_Spelling_Of
1728                              (Get_Name_String (Chars (Arg)),
1729                               Get_Name_String (Names (Index1)))
1730                         then
1731                            Error_Msg_Name_1 := Names (Index1);
1732                            Error_Msg_N ("\possible misspelling of%", Arg);
1733                            exit;
1734                         end if;
1735                      end loop;
1736
1737                      raise Pragma_Exit;
1738                   end if;
1739                end loop;
1740             end if;
1741
1742             Next (Arg);
1743          end loop;
1744       end Gather_Associations;
1745
1746       --------------------
1747       -- Get_Pragma_Arg --
1748       --------------------
1749
1750       function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
1751       begin
1752          if Nkind (Arg) = N_Pragma_Argument_Association then
1753             return Expression (Arg);
1754          else
1755             return Arg;
1756          end if;
1757       end Get_Pragma_Arg;
1758
1759       -----------------
1760       -- GNAT_Pragma --
1761       -----------------
1762
1763       procedure GNAT_Pragma is
1764       begin
1765          Check_Restriction (No_Implementation_Pragmas, N);
1766       end GNAT_Pragma;
1767
1768       --------------------------
1769       -- Is_Before_First_Decl --
1770       --------------------------
1771
1772       function Is_Before_First_Decl
1773         (Pragma_Node : Node_Id;
1774          Decls       : List_Id) return Boolean
1775       is
1776          Item : Node_Id := First (Decls);
1777
1778       begin
1779          --  Only other pragmas can come before this pragma
1780
1781          loop
1782             if No (Item) or else Nkind (Item) /= N_Pragma then
1783                return False;
1784
1785             elsif Item = Pragma_Node then
1786                return True;
1787             end if;
1788
1789             Next (Item);
1790          end loop;
1791       end Is_Before_First_Decl;
1792
1793       -----------------------------
1794       -- Is_Configuration_Pragma --
1795       -----------------------------
1796
1797       --  A configuration pragma must appear in the context clause of
1798       --  a compilation unit, at the start of the list (i.e. only other
1799       --  pragmas may precede it).
1800
1801       function Is_Configuration_Pragma return Boolean is
1802          Lis : constant List_Id := List_Containing (N);
1803          Par : constant Node_Id := Parent (N);
1804          Prg : Node_Id;
1805
1806       begin
1807          --  If no parent, then we are in the configuration pragma file,
1808          --  so the placement is definitely appropriate.
1809
1810          if No (Par) then
1811             return True;
1812
1813          --  Otherwise we must be in the context clause of a compilation unit
1814          --  and the only thing allowed before us in the context list is more
1815          --  configuration pragmas.
1816
1817          elsif Nkind (Par) = N_Compilation_Unit
1818            and then Context_Items (Par) = Lis
1819          then
1820             Prg := First (Lis);
1821
1822             loop
1823                if Prg = N then
1824                   return True;
1825                elsif Nkind (Prg) /= N_Pragma then
1826                   return False;
1827                end if;
1828
1829                Next (Prg);
1830             end loop;
1831
1832          else
1833             return False;
1834          end if;
1835       end Is_Configuration_Pragma;
1836
1837       --------------------------
1838       -- Is_In_Context_Clause --
1839       --------------------------
1840
1841       function Is_In_Context_Clause return Boolean is
1842          Plist       : List_Id;
1843          Parent_Node : Node_Id;
1844
1845       begin
1846          if not Is_List_Member (N) then
1847             return False;
1848
1849          else
1850             Plist := List_Containing (N);
1851             Parent_Node := Parent (Plist);
1852
1853             if Parent_Node = Empty
1854               or else Nkind (Parent_Node) /= N_Compilation_Unit
1855               or else Context_Items (Parent_Node) /= Plist
1856             then
1857                return False;
1858             end if;
1859          end if;
1860
1861          return True;
1862       end Is_In_Context_Clause;
1863
1864       ---------------------------------
1865       -- Is_Static_String_Expression --
1866       ---------------------------------
1867
1868       function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
1869          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1870
1871       begin
1872          Analyze_And_Resolve (Argx);
1873          return Is_OK_Static_Expression (Argx)
1874            and then Nkind (Argx) = N_String_Literal;
1875       end Is_Static_String_Expression;
1876
1877       ----------------------
1878       -- Pragma_Misplaced --
1879       ----------------------
1880
1881       procedure Pragma_Misplaced is
1882       begin
1883          Error_Pragma ("incorrect placement of pragma%");
1884       end Pragma_Misplaced;
1885
1886       ------------------------------------
1887       -- Process Atomic_Shared_Volatile --
1888       ------------------------------------
1889
1890       procedure Process_Atomic_Shared_Volatile is
1891          E_Id : Node_Id;
1892          E    : Entity_Id;
1893          D    : Node_Id;
1894          K    : Node_Kind;
1895          Utyp : Entity_Id;
1896
1897          procedure Set_Atomic (E : Entity_Id);
1898          --  Set given type as atomic, and if no explicit alignment was
1899          --  given, set alignment to unknown, since back end knows what
1900          --  the alignment requirements are for atomic arrays. Note that
1901          --  this step is necessary for derived types.
1902
1903          ----------------
1904          -- Set_Atomic --
1905          ----------------
1906
1907          procedure Set_Atomic (E : Entity_Id) is
1908          begin
1909             Set_Is_Atomic (E);
1910
1911             if not Has_Alignment_Clause (E) then
1912                Set_Alignment (E, Uint_0);
1913             end if;
1914          end Set_Atomic;
1915
1916       --  Start of processing for Process_Atomic_Shared_Volatile
1917
1918       begin
1919          Check_Ada_83_Warning;
1920          Check_No_Identifiers;
1921          Check_Arg_Count (1);
1922          Check_Arg_Is_Local_Name (Arg1);
1923          E_Id := Expression (Arg1);
1924
1925          if Etype (E_Id) = Any_Type then
1926             return;
1927          end if;
1928
1929          E := Entity (E_Id);
1930          D := Declaration_Node (E);
1931          K := Nkind (D);
1932
1933          if Is_Type (E) then
1934             if Rep_Item_Too_Early (E, N)
1935                  or else
1936                Rep_Item_Too_Late (E, N)
1937             then
1938                return;
1939             else
1940                Check_First_Subtype (Arg1);
1941             end if;
1942
1943             if Prag_Id /= Pragma_Volatile then
1944                Set_Atomic (E);
1945                Set_Atomic (Underlying_Type (E));
1946                Set_Atomic (Base_Type (E));
1947             end if;
1948
1949             --  Attribute belongs on the base type. If the
1950             --  view of the type is currently private, it also
1951             --  belongs on the underlying type.
1952
1953             Set_Is_Volatile (Base_Type (E));
1954             Set_Is_Volatile (Underlying_Type (E));
1955
1956             Set_Treat_As_Volatile (E);
1957             Set_Treat_As_Volatile (Underlying_Type (E));
1958
1959          elsif K = N_Object_Declaration
1960            or else (K = N_Component_Declaration
1961                      and then Original_Record_Component (E) = E)
1962          then
1963             if Rep_Item_Too_Late (E, N) then
1964                return;
1965             end if;
1966
1967             if Prag_Id /= Pragma_Volatile then
1968                Set_Is_Atomic (E);
1969
1970                --  If the object declaration has an explicit
1971                --  initialization, a temporary may have to be
1972                --  created to hold the expression, to insure
1973                --  that access to the object remain atomic.
1974
1975                if Nkind (Parent (E)) = N_Object_Declaration
1976                  and then Present (Expression (Parent (E)))
1977                then
1978                   Set_Has_Delayed_Freeze (E);
1979                end if;
1980
1981                --  An interesting improvement here. If an object of type X
1982                --  is declared atomic, and the type X is not atomic, that's
1983                --  a pity, since it may not have appropraite alignment etc.
1984                --  We can rescue this in the special case where the object
1985                --  and type are in the same unit by just setting the type
1986                --  as atomic, so that the back end will process it as atomic.
1987
1988                Utyp := Underlying_Type (Etype (E));
1989
1990                if Present (Utyp)
1991                  and then Sloc (E) > No_Location
1992                  and then Sloc (Utyp) > No_Location
1993                  and then
1994                    Get_Source_File_Index (Sloc (E)) =
1995                    Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
1996                then
1997                   Set_Is_Atomic (Underlying_Type (Etype (E)));
1998                end if;
1999             end if;
2000
2001             Set_Is_Volatile (E);
2002             Set_Treat_As_Volatile (E);
2003
2004          else
2005             Error_Pragma_Arg
2006               ("inappropriate entity for pragma%", Arg1);
2007          end if;
2008       end Process_Atomic_Shared_Volatile;
2009
2010       -------------------------------------------
2011       -- Process_Compile_Time_Warning_Or_Error --
2012       -------------------------------------------
2013
2014       procedure Process_Compile_Time_Warning_Or_Error is
2015          Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2016
2017       begin
2018          GNAT_Pragma;
2019          Check_Arg_Count (2);
2020          Check_No_Identifiers;
2021          Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2022          Analyze_And_Resolve (Arg1x, Standard_Boolean);
2023
2024          if Compile_Time_Known_Value (Arg1x) then
2025             if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2026                declare
2027                   Str   : constant String_Id :=
2028                             Strval (Get_Pragma_Arg (Arg2));
2029                   Len   : constant Int := String_Length (Str);
2030                   Cont  : Boolean;
2031                   Ptr   : Nat;
2032                   CC    : Char_Code;
2033                   C     : Character;
2034
2035                begin
2036                   Cont := False;
2037                   Ptr := 1;
2038
2039                   --  Loop through segments of message separated by line
2040                   --  feeds. We output these segments as separate messages
2041                   --  with continuation marks for all but the first.
2042
2043                   loop
2044                      Error_Msg_Strlen := 0;
2045
2046                      --  Loop to copy characters from argument to error
2047                      --  message string buffer.
2048
2049                      loop
2050                         exit when Ptr > Len;
2051                         CC := Get_String_Char (Str, Ptr);
2052                         Ptr := Ptr + 1;
2053
2054                         --  Ignore wide chars ??? else store character
2055
2056                         if In_Character_Range (CC) then
2057                            C := Get_Character (CC);
2058                            exit when C = ASCII.LF;
2059                            Error_Msg_Strlen := Error_Msg_Strlen + 1;
2060                            Error_Msg_String (Error_Msg_Strlen) := C;
2061                         end if;
2062                      end loop;
2063
2064                      --  Here with one line ready to go
2065
2066                      Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2067
2068                      if Cont = False then
2069                         Error_Msg_N ("<~", Arg1);
2070                         Cont := True;
2071                      else
2072                         Error_Msg_N ("\<~", Arg1);
2073                      end if;
2074
2075                      exit when Ptr > Len;
2076                   end loop;
2077                end;
2078             end if;
2079          end if;
2080       end Process_Compile_Time_Warning_Or_Error;
2081
2082       ------------------------
2083       -- Process_Convention --
2084       ------------------------
2085
2086       procedure Process_Convention
2087         (C : out Convention_Id;
2088          E : out Entity_Id)
2089       is
2090          Id        : Node_Id;
2091          E1        : Entity_Id;
2092          Cname     : Name_Id;
2093          Comp_Unit : Unit_Number_Type;
2094
2095          procedure Set_Convention_From_Pragma (E : Entity_Id);
2096          --  Set convention in entity E, and also flag that the entity has a
2097          --  convention pragma. If entity is for a private or incomplete type,
2098          --  also set convention and flag on underlying type. This procedure
2099          --  also deals with the special case of C_Pass_By_Copy convention.
2100
2101          --------------------------------
2102          -- Set_Convention_From_Pragma --
2103          --------------------------------
2104
2105          procedure Set_Convention_From_Pragma (E : Entity_Id) is
2106          begin
2107             --  Ada 2005 (AI-430): Check invalid attempt to change convention
2108             --  for an overridden dispatching operation. Technically this is
2109             --  an amendment and should only be done in Ada 2005 mode. However,
2110             --  this is clearly a mistake, since the problem that is addressed
2111             --  by this AI is that there is a clear gap in the RM!
2112
2113             if Is_Dispatching_Operation (E)
2114               and then Present (Overridden_Operation (E))
2115               and then C /= Convention (Overridden_Operation (E))
2116             then
2117                Error_Pragma_Arg
2118                  ("cannot change convention for " &
2119                   "overridden dispatching operation",
2120                   Arg1);
2121             end if;
2122
2123             --  Set the convention
2124
2125             Set_Convention (E, C);
2126             Set_Has_Convention_Pragma (E);
2127
2128             if Is_Incomplete_Or_Private_Type (E) then
2129                Set_Convention            (Underlying_Type (E), C);
2130                Set_Has_Convention_Pragma (Underlying_Type (E), True);
2131             end if;
2132
2133             --  A class-wide type should inherit the convention of
2134             --  the specific root type (although this isn't specified
2135             --  clearly by the RM).
2136
2137             if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2138                Set_Convention (Class_Wide_Type (E), C);
2139             end if;
2140
2141             --  If the entity is a record type, then check for special case of
2142             --  C_Pass_By_Copy, which is treated the same as C except that the
2143             --  special record flag is set. This convention is only permitted
2144             --  on record types (see AI95-00131).
2145
2146             if Cname = Name_C_Pass_By_Copy then
2147                if Is_Record_Type (E) then
2148                   Set_C_Pass_By_Copy (Base_Type (E));
2149                elsif Is_Incomplete_Or_Private_Type (E)
2150                  and then Is_Record_Type (Underlying_Type (E))
2151                then
2152                   Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2153                else
2154                   Error_Pragma_Arg
2155                     ("C_Pass_By_Copy convention allowed only for record type",
2156                      Arg2);
2157                end if;
2158             end if;
2159
2160             --  If the entity is a derived boolean type, check for the
2161             --  special case of convention C, C++, or Fortran, where we
2162             --  consider any nonzero value to represent true.
2163
2164             if Is_Discrete_Type (E)
2165               and then Root_Type (Etype (E)) = Standard_Boolean
2166               and then
2167                 (C = Convention_C
2168                    or else
2169                  C = Convention_CPP
2170                    or else
2171                  C = Convention_Fortran)
2172             then
2173                Set_Nonzero_Is_True (Base_Type (E));
2174             end if;
2175          end Set_Convention_From_Pragma;
2176
2177       --  Start of processing for Process_Convention
2178
2179       begin
2180          Check_At_Least_N_Arguments (2);
2181          Check_Optional_Identifier (Arg1, Name_Convention);
2182          Check_Arg_Is_Identifier (Arg1);
2183          Cname := Chars (Expression (Arg1));
2184
2185          --  C_Pass_By_Copy is treated as a synonym for convention C
2186          --  (this is tested again below to set the critical flag)
2187
2188          if Cname = Name_C_Pass_By_Copy then
2189             C := Convention_C;
2190
2191          --  Otherwise we must have something in the standard convention list
2192
2193          elsif Is_Convention_Name (Cname) then
2194             C := Get_Convention_Id (Chars (Expression (Arg1)));
2195
2196          --  In DEC VMS, it seems that there is an undocumented feature that
2197          --  any unrecognized convention is treated as the default, which for
2198          --  us is convention C. It does not seem so terrible to do this
2199          --  unconditionally, silently in the VMS case, and with a warning
2200          --  in the non-VMS case.
2201
2202          else
2203             if Warn_On_Export_Import and not OpenVMS_On_Target then
2204                Error_Msg_N
2205                  ("?unrecognized convention name, C assumed",
2206                   Expression (Arg1));
2207             end if;
2208
2209             C := Convention_C;
2210          end if;
2211
2212          Check_Optional_Identifier (Arg2, Name_Entity);
2213          Check_Arg_Is_Local_Name (Arg2);
2214
2215          Id := Expression (Arg2);
2216          Analyze (Id);
2217
2218          if not Is_Entity_Name (Id) then
2219             Error_Pragma_Arg ("entity name required", Arg2);
2220          end if;
2221
2222          if Ekind (Entity (Id)) = E_Enumeration_Literal then
2223             Error_Pragma ("enumeration literal not allowed for pragma%");
2224          end if;
2225
2226          E := Entity (Id);
2227
2228          --  Go to renamed subprogram if present, since convention applies to
2229          --  the actual renamed entity, not to the renaming entity. If the
2230          --  subprogram is inherited, go to parent subprogram.
2231
2232          if Is_Subprogram (E)
2233            and then Present (Alias (E))
2234          then
2235             if Nkind (Parent (Declaration_Node (E))) =
2236                                        N_Subprogram_Renaming_Declaration
2237             then
2238                E := Alias (E);
2239
2240             elsif Nkind (Parent (E)) = N_Full_Type_Declaration
2241               and then Scope (E) = Scope (Alias (E))
2242             then
2243                E := Alias (E);
2244             end if;
2245          end if;
2246
2247          --  Check that we are not applying this to a specless body
2248
2249          if Is_Subprogram (E)
2250            and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2251          then
2252             Error_Pragma
2253               ("pragma% requires separate spec and must come before body");
2254          end if;
2255
2256          --  Check that we are not applying this to a named constant
2257
2258          if Ekind (E) = E_Named_Integer
2259               or else
2260             Ekind (E) = E_Named_Real
2261          then
2262             Error_Msg_Name_1 := Chars (N);
2263             Error_Msg_N
2264               ("cannot apply pragma% to named constant!",
2265                Get_Pragma_Arg (Arg2));
2266             Error_Pragma_Arg
2267               ("\supply appropriate type for&!", Arg2);
2268          end if;
2269
2270          if Etype (E) = Any_Type
2271            or else Rep_Item_Too_Early (E, N)
2272          then
2273             raise Pragma_Exit;
2274          else
2275             E := Underlying_Type (E);
2276          end if;
2277
2278          if Rep_Item_Too_Late (E, N) then
2279             raise Pragma_Exit;
2280          end if;
2281
2282          if Has_Convention_Pragma (E) then
2283             Error_Pragma_Arg
2284               ("at most one Convention/Export/Import pragma is allowed", Arg2);
2285
2286          elsif Convention (E) = Convention_Protected
2287            or else Ekind (Scope (E)) = E_Protected_Type
2288          then
2289             Error_Pragma_Arg
2290               ("a protected operation cannot be given a different convention",
2291                 Arg2);
2292          end if;
2293
2294          --  For Intrinsic, a subprogram is required
2295
2296          if C = Convention_Intrinsic
2297            and then not Is_Subprogram (E)
2298            and then not Is_Generic_Subprogram (E)
2299          then
2300             Error_Pragma_Arg
2301               ("second argument of pragma% must be a subprogram", Arg2);
2302          end if;
2303
2304          --  For Stdcall, a subprogram, variable or subprogram type is required
2305
2306          if C = Convention_Stdcall
2307            and then not Is_Subprogram (E)
2308            and then not Is_Generic_Subprogram (E)
2309            and then Ekind (E) /= E_Variable
2310            and then not
2311              (Is_Access_Type (E)
2312                 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2313          then
2314             Error_Pragma_Arg
2315               ("second argument of pragma% must be subprogram (type)",
2316                Arg2);
2317          end if;
2318
2319          if not Is_Subprogram (E)
2320            and then not Is_Generic_Subprogram (E)
2321          then
2322             Set_Convention_From_Pragma (E);
2323
2324             if Is_Type (E) then
2325
2326                Check_First_Subtype (Arg2);
2327                Set_Convention_From_Pragma (Base_Type (E));
2328
2329                --  For subprograms, we must set the convention on the
2330                --  internally generated directly designated type as well.
2331
2332                if Ekind (E) = E_Access_Subprogram_Type then
2333                   Set_Convention_From_Pragma (Directly_Designated_Type (E));
2334                end if;
2335             end if;
2336
2337          --  For the subprogram case, set proper convention for all homonyms
2338          --  in same scope and the same declarative part, i.e. the same
2339          --  compilation unit.
2340
2341          else
2342             Comp_Unit := Get_Source_Unit (E);
2343             Set_Convention_From_Pragma (E);
2344
2345             --  Treat a pragma Import as an implicit body, for GPS use
2346
2347             if Prag_Id = Pragma_Import then
2348                Generate_Reference (E, Id, 'b');
2349             end if;
2350
2351             E1 := E;
2352             loop
2353                E1 := Homonym (E1);
2354                exit when No (E1) or else Scope (E1) /= Current_Scope;
2355
2356                --  Note: below we are missing a check for Rep_Item_Too_Late.
2357                --  That is deliberate, we cannot chain the rep item on more
2358                --  than one Rep_Item chain, to be fixed later ???
2359
2360                if Comes_From_Source (E1)
2361                  and then Comp_Unit = Get_Source_Unit (E1)
2362                  and then Nkind (Original_Node (Parent (E1))) /=
2363                    N_Full_Type_Declaration
2364                then
2365                   Set_Convention_From_Pragma (E1);
2366
2367                   if Prag_Id = Pragma_Import then
2368                      Generate_Reference (E, Id, 'b');
2369                   end if;
2370                end if;
2371             end loop;
2372          end if;
2373       end Process_Convention;
2374
2375       -----------------------------------------------------
2376       -- Process_Extended_Import_Export_Exception_Pragma --
2377       -----------------------------------------------------
2378
2379       procedure Process_Extended_Import_Export_Exception_Pragma
2380         (Arg_Internal : Node_Id;
2381          Arg_External : Node_Id;
2382          Arg_Form     : Node_Id;
2383          Arg_Code     : Node_Id)
2384       is
2385          Def_Id   : Entity_Id;
2386          Code_Val : Uint;
2387
2388       begin
2389          GNAT_Pragma;
2390
2391          if not OpenVMS_On_Target then
2392             Error_Pragma
2393               ("?pragma% ignored (applies only to Open'V'M'S)");
2394          end if;
2395
2396          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2397          Def_Id := Entity (Arg_Internal);
2398
2399          if Ekind (Def_Id) /= E_Exception then
2400             Error_Pragma_Arg
2401               ("pragma% must refer to declared exception", Arg_Internal);
2402          end if;
2403
2404          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2405
2406          if Present (Arg_Form) then
2407             Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2408          end if;
2409
2410          if Present (Arg_Form)
2411            and then Chars (Arg_Form) = Name_Ada
2412          then
2413             null;
2414          else
2415             Set_Is_VMS_Exception (Def_Id);
2416             Set_Exception_Code (Def_Id, No_Uint);
2417          end if;
2418
2419          if Present (Arg_Code) then
2420             if not Is_VMS_Exception (Def_Id) then
2421                Error_Pragma_Arg
2422                  ("Code option for pragma% not allowed for Ada case",
2423                   Arg_Code);
2424             end if;
2425
2426             Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2427             Code_Val := Expr_Value (Arg_Code);
2428
2429             if not UI_Is_In_Int_Range (Code_Val) then
2430                Error_Pragma_Arg
2431                  ("Code option for pragma% must be in 32-bit range",
2432                   Arg_Code);
2433
2434             else
2435                Set_Exception_Code (Def_Id, Code_Val);
2436             end if;
2437          end if;
2438       end Process_Extended_Import_Export_Exception_Pragma;
2439
2440       -------------------------------------------------
2441       -- Process_Extended_Import_Export_Internal_Arg --
2442       -------------------------------------------------
2443
2444       procedure Process_Extended_Import_Export_Internal_Arg
2445         (Arg_Internal : Node_Id := Empty)
2446       is
2447       begin
2448          GNAT_Pragma;
2449
2450          if No (Arg_Internal) then
2451             Error_Pragma ("Internal parameter required for pragma%");
2452          end if;
2453
2454          if Nkind (Arg_Internal) = N_Identifier then
2455             null;
2456
2457          elsif Nkind (Arg_Internal) = N_Operator_Symbol
2458            and then (Prag_Id = Pragma_Import_Function
2459                        or else
2460                      Prag_Id = Pragma_Export_Function)
2461          then
2462             null;
2463
2464          else
2465             Error_Pragma_Arg
2466               ("wrong form for Internal parameter for pragma%", Arg_Internal);
2467          end if;
2468
2469          Check_Arg_Is_Local_Name (Arg_Internal);
2470       end Process_Extended_Import_Export_Internal_Arg;
2471
2472       --------------------------------------------------
2473       -- Process_Extended_Import_Export_Object_Pragma --
2474       --------------------------------------------------
2475
2476       procedure Process_Extended_Import_Export_Object_Pragma
2477         (Arg_Internal : Node_Id;
2478          Arg_External : Node_Id;
2479          Arg_Size     : Node_Id)
2480       is
2481          Def_Id : Entity_Id;
2482
2483       begin
2484          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2485          Def_Id := Entity (Arg_Internal);
2486
2487          if Ekind (Def_Id) /= E_Constant
2488            and then Ekind (Def_Id) /= E_Variable
2489          then
2490             Error_Pragma_Arg
2491               ("pragma% must designate an object", Arg_Internal);
2492          end if;
2493
2494          if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2495               or else
2496             Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2497          then
2498             Error_Pragma_Arg
2499               ("previous Common/Psect_Object applies, pragma % not permitted",
2500                Arg_Internal);
2501          end if;
2502
2503          if Rep_Item_Too_Late (Def_Id, N) then
2504             raise Pragma_Exit;
2505          end if;
2506
2507          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2508
2509          if Present (Arg_Size) then
2510             Check_Arg_Is_External_Name (Arg_Size);
2511          end if;
2512
2513          --  Export_Object case
2514
2515          if Prag_Id = Pragma_Export_Object then
2516             if not Is_Library_Level_Entity (Def_Id) then
2517                Error_Pragma_Arg
2518                  ("argument for pragma% must be library level entity",
2519                   Arg_Internal);
2520             end if;
2521
2522             if Ekind (Current_Scope) = E_Generic_Package then
2523                Error_Pragma ("pragma& cannot appear in a generic unit");
2524             end if;
2525
2526             if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2527                Error_Pragma_Arg
2528                  ("exported object must have compile time known size",
2529                   Arg_Internal);
2530             end if;
2531
2532             if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2533                Error_Msg_N
2534                  ("?duplicate Export_Object pragma", N);
2535             else
2536                Set_Exported (Def_Id, Arg_Internal);
2537             end if;
2538
2539          --  Import_Object case
2540
2541          else
2542             if Is_Concurrent_Type (Etype (Def_Id)) then
2543                Error_Pragma_Arg
2544                  ("cannot use pragma% for task/protected object",
2545                   Arg_Internal);
2546             end if;
2547
2548             if Ekind (Def_Id) = E_Constant then
2549                Error_Pragma_Arg
2550                  ("cannot import a constant", Arg_Internal);
2551             end if;
2552
2553             if Warn_On_Export_Import
2554               and then Has_Discriminants (Etype (Def_Id))
2555             then
2556                Error_Msg_N
2557                  ("imported value must be initialized?", Arg_Internal);
2558             end if;
2559
2560             if Warn_On_Export_Import
2561               and then Is_Access_Type (Etype (Def_Id))
2562             then
2563                Error_Pragma_Arg
2564                  ("cannot import object of an access type?", Arg_Internal);
2565             end if;
2566
2567             if Warn_On_Export_Import
2568               and then Is_Imported (Def_Id)
2569             then
2570                Error_Msg_N
2571                  ("?duplicate Import_Object pragma", N);
2572
2573             --  Check for explicit initialization present. Note that an
2574             --  initialization that generated by the code generator, e.g.
2575             --  for an access type, does not count here.
2576
2577             elsif Present (Expression (Parent (Def_Id)))
2578                and then
2579                  Comes_From_Source
2580                    (Original_Node (Expression (Parent (Def_Id))))
2581             then
2582                Error_Msg_Sloc := Sloc (Def_Id);
2583                Error_Pragma_Arg
2584                  ("imported entities cannot be initialized (RM B.1(24))",
2585                   "\no initialization allowed for & declared#", Arg1);
2586             else
2587                Set_Imported (Def_Id);
2588                Note_Possible_Modification (Arg_Internal);
2589             end if;
2590          end if;
2591       end Process_Extended_Import_Export_Object_Pragma;
2592
2593       ------------------------------------------------------
2594       -- Process_Extended_Import_Export_Subprogram_Pragma --
2595       ------------------------------------------------------
2596
2597       procedure Process_Extended_Import_Export_Subprogram_Pragma
2598         (Arg_Internal                 : Node_Id;
2599          Arg_External                 : Node_Id;
2600          Arg_Parameter_Types          : Node_Id;
2601          Arg_Result_Type              : Node_Id := Empty;
2602          Arg_Mechanism                : Node_Id;
2603          Arg_Result_Mechanism         : Node_Id := Empty;
2604          Arg_First_Optional_Parameter : Node_Id := Empty)
2605       is
2606          Ent       : Entity_Id;
2607          Def_Id    : Entity_Id;
2608          Hom_Id    : Entity_Id;
2609          Formal    : Entity_Id;
2610          Ambiguous : Boolean;
2611          Match     : Boolean;
2612          Dval      : Node_Id;
2613
2614          function Same_Base_Type
2615           (Ptype  : Node_Id;
2616            Formal : Entity_Id) return Boolean;
2617          --  Determines if Ptype references the type of Formal. Note that
2618          --  only the base types need to match according to the spec. Ptype
2619          --  here is the argument from the pragma, which is either a type
2620          --  name, or an access attribute.
2621
2622          --------------------
2623          -- Same_Base_Type --
2624          --------------------
2625
2626          function Same_Base_Type
2627            (Ptype  : Node_Id;
2628             Formal : Entity_Id) return Boolean
2629          is
2630             Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2631             Pref : Node_Id;
2632
2633          begin
2634             --  Case where pragma argument is typ'Access
2635
2636             if Nkind (Ptype) = N_Attribute_Reference
2637               and then Attribute_Name (Ptype) = Name_Access
2638             then
2639                Pref := Prefix (Ptype);
2640                Find_Type (Pref);
2641
2642                if not Is_Entity_Name (Pref)
2643                  or else Entity (Pref) = Any_Type
2644                then
2645                   raise Pragma_Exit;
2646                end if;
2647
2648                --  We have a match if the corresponding argument is of an
2649                --  anonymous access type, and its designicated type matches
2650                --  the type of the prefix of the access attribute
2651
2652                return Ekind (Ftyp) = E_Anonymous_Access_Type
2653                  and then Base_Type (Entity (Pref)) =
2654                             Base_Type (Etype (Designated_Type (Ftyp)));
2655
2656             --  Case where pragma argument is a type name
2657
2658             else
2659                Find_Type (Ptype);
2660
2661                if not Is_Entity_Name (Ptype)
2662                  or else Entity (Ptype) = Any_Type
2663                then
2664                   raise Pragma_Exit;
2665                end if;
2666
2667                --  We have a match if the corresponding argument is of
2668                --  the type given in the pragma (comparing base types)
2669
2670                return Base_Type (Entity (Ptype)) = Ftyp;
2671             end if;
2672          end Same_Base_Type;
2673
2674       --  Start of processing for
2675       --  Process_Extended_Import_Export_Subprogram_Pragma
2676
2677       begin
2678          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2679          Ent := Empty;
2680          Ambiguous := False;
2681
2682          --  Loop through homonyms (overloadings) of the entity
2683
2684          Hom_Id := Entity (Arg_Internal);
2685          while Present (Hom_Id) loop
2686             Def_Id := Get_Base_Subprogram (Hom_Id);
2687
2688             --  We need a subprogram in the current scope
2689
2690             if not Is_Subprogram (Def_Id)
2691               or else Scope (Def_Id) /= Current_Scope
2692             then
2693                null;
2694
2695             else
2696                Match := True;
2697
2698                --  Pragma cannot apply to subprogram body
2699
2700                if Is_Subprogram (Def_Id)
2701                  and then
2702                    Nkind (Parent
2703                      (Declaration_Node (Def_Id))) = N_Subprogram_Body
2704                then
2705                   Error_Pragma
2706                     ("pragma% requires separate spec"
2707                       & " and must come before body");
2708                end if;
2709
2710                --  Test result type if given, note that the result type
2711                --  parameter can only be present for the function cases.
2712
2713                if Present (Arg_Result_Type)
2714                  and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2715                then
2716                   Match := False;
2717
2718                elsif Etype (Def_Id) /= Standard_Void_Type
2719                  and then
2720                    (Chars (N) = Name_Export_Procedure
2721                       or else Chars (N) = Name_Import_Procedure)
2722                then
2723                   Match := False;
2724
2725                --  Test parameter types if given. Note that this parameter
2726                --  has not been analyzed (and must not be, since it is
2727                --  semantic nonsense), so we get it as the parser left it.
2728
2729                elsif Present (Arg_Parameter_Types) then
2730                   Check_Matching_Types : declare
2731                      Formal : Entity_Id;
2732                      Ptype  : Node_Id;
2733
2734                   begin
2735                      Formal := First_Formal (Def_Id);
2736
2737                      if Nkind (Arg_Parameter_Types) = N_Null then
2738                         if Present (Formal) then
2739                            Match := False;
2740                         end if;
2741
2742                      --  A list of one type, e.g. (List) is parsed as
2743                      --  a parenthesized expression.
2744
2745                      elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
2746                        and then Paren_Count (Arg_Parameter_Types) = 1
2747                      then
2748                         if No (Formal)
2749                           or else Present (Next_Formal (Formal))
2750                         then
2751                            Match := False;
2752                         else
2753                            Match :=
2754                              Same_Base_Type (Arg_Parameter_Types, Formal);
2755                         end if;
2756
2757                      --  A list of more than one type is parsed as a aggregate
2758
2759                      elsif Nkind (Arg_Parameter_Types) = N_Aggregate
2760                        and then Paren_Count (Arg_Parameter_Types) = 0
2761                      then
2762                         Ptype := First (Expressions (Arg_Parameter_Types));
2763                         while Present (Ptype) or else Present (Formal) loop
2764                            if No (Ptype)
2765                              or else No (Formal)
2766                              or else not Same_Base_Type (Ptype, Formal)
2767                            then
2768                               Match := False;
2769                               exit;
2770                            else
2771                               Next_Formal (Formal);
2772                               Next (Ptype);
2773                            end if;
2774                         end loop;
2775
2776                      --  Anything else is of the wrong form
2777
2778                      else
2779                         Error_Pragma_Arg
2780                           ("wrong form for Parameter_Types parameter",
2781                            Arg_Parameter_Types);
2782                      end if;
2783                   end Check_Matching_Types;
2784                end if;
2785
2786                --  Match is now False if the entry we found did not match
2787                --  either a supplied Parameter_Types or Result_Types argument
2788
2789                if Match then
2790                   if No (Ent) then
2791                      Ent := Def_Id;
2792
2793                   --  Ambiguous case, the flag Ambiguous shows if we already
2794                   --  detected this and output the initial messages.
2795
2796                   else
2797                      if not Ambiguous then
2798                         Ambiguous := True;
2799                         Error_Msg_Name_1 := Chars (N);
2800                         Error_Msg_N
2801                           ("pragma% does not uniquely identify subprogram!",
2802                            N);
2803                         Error_Msg_Sloc := Sloc (Ent);
2804                         Error_Msg_N ("matching subprogram #!", N);
2805                         Ent := Empty;
2806                      end if;
2807
2808                      Error_Msg_Sloc := Sloc (Def_Id);
2809                      Error_Msg_N ("matching subprogram #!", N);
2810                   end if;
2811                end if;
2812             end if;
2813
2814             Hom_Id := Homonym (Hom_Id);
2815          end loop;
2816
2817          --  See if we found an entry
2818
2819          if No (Ent) then
2820             if not Ambiguous then
2821                if Is_Generic_Subprogram (Entity (Arg_Internal)) then
2822                   Error_Pragma
2823                     ("pragma% cannot be given for generic subprogram");
2824
2825                else
2826                   Error_Pragma
2827                     ("pragma% does not identify local subprogram");
2828                end if;
2829             end if;
2830
2831             return;
2832          end if;
2833
2834          --  Import pragmas must be be for imported entities
2835
2836          if Prag_Id = Pragma_Import_Function
2837               or else
2838             Prag_Id = Pragma_Import_Procedure
2839               or else
2840             Prag_Id = Pragma_Import_Valued_Procedure
2841          then
2842             if not Is_Imported (Ent) then
2843                Error_Pragma
2844                  ("pragma Import or Interface must precede pragma%");
2845             end if;
2846
2847          --  Here we have the Export case which can set the entity as exported
2848
2849          --  But does not do so if the specified external name is null, since
2850          --  that is taken as a signal in DEC Ada 83 (with which we want to be
2851          --  compatible) to request no external name.
2852
2853          elsif Nkind (Arg_External) = N_String_Literal
2854            and then String_Length (Strval (Arg_External)) = 0
2855          then
2856             null;
2857
2858          --  In all other cases, set entit as exported
2859
2860          else
2861             Set_Exported (Ent, Arg_Internal);
2862          end if;
2863
2864          --  Special processing for Valued_Procedure cases
2865
2866          if Prag_Id = Pragma_Import_Valued_Procedure
2867            or else
2868             Prag_Id = Pragma_Export_Valued_Procedure
2869          then
2870             Formal := First_Formal (Ent);
2871
2872             if No (Formal) then
2873                Error_Pragma
2874                  ("at least one parameter required for pragma%");
2875
2876             elsif Ekind (Formal) /= E_Out_Parameter then
2877                Error_Pragma
2878                  ("first parameter must have mode out for pragma%");
2879
2880             else
2881                Set_Is_Valued_Procedure (Ent);
2882             end if;
2883          end if;
2884
2885          Set_Extended_Import_Export_External_Name (Ent, Arg_External);
2886
2887          --  Process Result_Mechanism argument if present. We have already
2888          --  checked that this is only allowed for the function case.
2889
2890          if Present (Arg_Result_Mechanism) then
2891             Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
2892          end if;
2893
2894          --  Process Mechanism parameter if present. Note that this parameter
2895          --  is not analyzed, and must not be analyzed since it is semantic
2896          --  nonsense, so we get it in exactly as the parser left it.
2897
2898          if Present (Arg_Mechanism) then
2899             declare
2900                Formal : Entity_Id;
2901                Massoc : Node_Id;
2902                Mname  : Node_Id;
2903                Choice : Node_Id;
2904
2905             begin
2906                --  A single mechanism association without a formal parameter
2907                --  name is parsed as a parenthesized expression. All other
2908                --  cases are parsed as aggregates, so we rewrite the single
2909                --  parameter case as an aggregate for consistency.
2910
2911                if Nkind (Arg_Mechanism) /= N_Aggregate
2912                  and then Paren_Count (Arg_Mechanism) = 1
2913                then
2914                   Rewrite (Arg_Mechanism,
2915                     Make_Aggregate (Sloc (Arg_Mechanism),
2916                       Expressions => New_List (
2917                         Relocate_Node (Arg_Mechanism))));
2918                end if;
2919
2920                --  Case of only mechanism name given, applies to all formals
2921
2922                if Nkind (Arg_Mechanism) /= N_Aggregate then
2923                   Formal := First_Formal (Ent);
2924                   while Present (Formal) loop
2925                      Set_Mechanism_Value (Formal, Arg_Mechanism);
2926                      Next_Formal (Formal);
2927                   end loop;
2928
2929                --  Case of list of mechanism associations given
2930
2931                else
2932                   if Null_Record_Present (Arg_Mechanism) then
2933                      Error_Pragma_Arg
2934                        ("inappropriate form for Mechanism parameter",
2935                         Arg_Mechanism);
2936                   end if;
2937
2938                   --  Deal with positional ones first
2939
2940                   Formal := First_Formal (Ent);
2941
2942                   if Present (Expressions (Arg_Mechanism)) then
2943                      Mname := First (Expressions (Arg_Mechanism));
2944                      while Present (Mname) loop
2945                         if No (Formal) then
2946                            Error_Pragma_Arg
2947                              ("too many mechanism associations", Mname);
2948                         end if;
2949
2950                         Set_Mechanism_Value (Formal, Mname);
2951                         Next_Formal (Formal);
2952                         Next (Mname);
2953                      end loop;
2954                   end if;
2955
2956                   --  Deal with named entries
2957
2958                   if Present (Component_Associations (Arg_Mechanism)) then
2959                      Massoc := First (Component_Associations (Arg_Mechanism));
2960                      while Present (Massoc) loop
2961                         Choice := First (Choices (Massoc));
2962
2963                         if Nkind (Choice) /= N_Identifier
2964                           or else Present (Next (Choice))
2965                         then
2966                            Error_Pragma_Arg
2967                              ("incorrect form for mechanism association",
2968                               Massoc);
2969                         end if;
2970
2971                         Formal := First_Formal (Ent);
2972                         loop
2973                            if No (Formal) then
2974                               Error_Pragma_Arg
2975                                 ("parameter name & not present", Choice);
2976                            end if;
2977
2978                            if Chars (Choice) = Chars (Formal) then
2979                               Set_Mechanism_Value
2980                                 (Formal, Expression (Massoc));
2981                               exit;
2982                            end if;
2983
2984                            Next_Formal (Formal);
2985                         end loop;
2986
2987                         Next (Massoc);
2988                      end loop;
2989                   end if;
2990                end if;
2991             end;
2992          end if;
2993
2994          --  Process First_Optional_Parameter argument if present. We have
2995          --  already checked that this is only allowed for the Import case.
2996
2997          if Present (Arg_First_Optional_Parameter) then
2998             if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
2999                Error_Pragma_Arg
3000                  ("first optional parameter must be formal parameter name",
3001                   Arg_First_Optional_Parameter);
3002             end if;
3003
3004             Formal := First_Formal (Ent);
3005             loop
3006                if No (Formal) then
3007                   Error_Pragma_Arg
3008                     ("specified formal parameter& not found",
3009                      Arg_First_Optional_Parameter);
3010                end if;
3011
3012                exit when Chars (Formal) =
3013                          Chars (Arg_First_Optional_Parameter);
3014
3015                Next_Formal (Formal);
3016             end loop;
3017
3018             Set_First_Optional_Parameter (Ent, Formal);
3019
3020             --  Check specified and all remaining formals have right form
3021
3022             while Present (Formal) loop
3023                if Ekind (Formal) /= E_In_Parameter then
3024                   Error_Msg_NE
3025                     ("optional formal& is not of mode in!",
3026                      Arg_First_Optional_Parameter, Formal);
3027
3028                else
3029                   Dval := Default_Value (Formal);
3030
3031                   if No (Dval) then
3032                      Error_Msg_NE
3033                        ("optional formal& does not have default value!",
3034                         Arg_First_Optional_Parameter, Formal);
3035
3036                   elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3037                      null;
3038
3039                   else
3040                      Error_Msg_FE
3041                        ("default value for optional formal& is non-static!",
3042                         Arg_First_Optional_Parameter, Formal);
3043                   end if;
3044                end if;
3045
3046                Set_Is_Optional_Parameter (Formal);
3047                Next_Formal (Formal);
3048             end loop;
3049          end if;
3050       end Process_Extended_Import_Export_Subprogram_Pragma;
3051
3052       --------------------------
3053       -- Process_Generic_List --
3054       --------------------------
3055
3056       procedure Process_Generic_List is
3057          Arg : Node_Id;
3058          Exp : Node_Id;
3059
3060       begin
3061          GNAT_Pragma;
3062          Check_No_Identifiers;
3063          Check_At_Least_N_Arguments (1);
3064
3065          Arg := Arg1;
3066          while Present (Arg) loop
3067             Exp := Expression (Arg);
3068             Analyze (Exp);
3069
3070             if not Is_Entity_Name (Exp)
3071               or else
3072                 (not Is_Generic_Instance (Entity (Exp))
3073                   and then
3074                  not Is_Generic_Unit (Entity (Exp)))
3075             then
3076                Error_Pragma_Arg
3077                  ("pragma% argument must be name of generic unit/instance",
3078                   Arg);
3079             end if;
3080
3081             Next (Arg);
3082          end loop;
3083       end Process_Generic_List;
3084
3085       ---------------------------------
3086       -- Process_Import_Or_Interface --
3087       ---------------------------------
3088
3089       procedure Process_Import_Or_Interface is
3090          C      : Convention_Id;
3091          Def_Id : Entity_Id;
3092          Hom_Id : Entity_Id;
3093
3094       begin
3095          Process_Convention (C, Def_Id);
3096          Kill_Size_Check_Code (Def_Id);
3097          Note_Possible_Modification (Expression (Arg2));
3098
3099          if Ekind (Def_Id) = E_Variable
3100               or else
3101             Ekind (Def_Id) = E_Constant
3102          then
3103             --  We do not permit Import to apply to a renaming declaration
3104
3105             if Present (Renamed_Object (Def_Id)) then
3106                Error_Pragma_Arg
3107                  ("pragma% not allowed for object renaming", Arg2);
3108
3109             --  User initialization is not allowed for imported object, but
3110             --  the object declaration may contain a default initialization,
3111             --  that will be discarded. Note that an explicit initialization
3112             --  only counts if it comes from source, otherwise it is simply
3113             --  the code generator making an implicit initialization explicit.
3114
3115             elsif Present (Expression (Parent (Def_Id)))
3116               and then Comes_From_Source (Expression (Parent (Def_Id)))
3117             then
3118                Error_Msg_Sloc := Sloc (Def_Id);
3119                Error_Pragma_Arg
3120                  ("no initialization allowed for declaration of& #",
3121                   "\imported entities cannot be initialized (RM B.1(24))",
3122                   Arg2);
3123
3124             else
3125                Set_Imported (Def_Id);
3126                Process_Interface_Name (Def_Id, Arg3, Arg4);
3127
3128                --  Note that we do not set Is_Public here. That's because we
3129                --  only want to set if if there is no address clause, and we
3130                --  don't know that yet, so we delay that processing till
3131                --  freeze time.
3132
3133                --  pragma Import completes deferred constants
3134
3135                if Ekind (Def_Id) = E_Constant then
3136                   Set_Has_Completion (Def_Id);
3137                end if;
3138
3139                --  It is not possible to import a constant of an unconstrained
3140                --  array type (e.g. string) because there is no simple way to
3141                --  write a meaningful subtype for it.
3142
3143                if Is_Array_Type (Etype (Def_Id))
3144                  and then not Is_Constrained (Etype (Def_Id))
3145                then
3146                   Error_Msg_NE
3147                     ("imported constant& must have a constrained subtype",
3148                       N, Def_Id);
3149                end if;
3150             end if;
3151
3152          elsif Is_Subprogram (Def_Id)
3153            or else Is_Generic_Subprogram (Def_Id)
3154          then
3155             --  If the name is overloaded, pragma applies to all of the
3156             --  denoted entities in the same declarative part.
3157
3158             Hom_Id := Def_Id;
3159             while Present (Hom_Id) loop
3160                Def_Id := Get_Base_Subprogram (Hom_Id);
3161
3162                --  Ignore inherited subprograms because the pragma will
3163                --  apply to the parent operation, which is the one called.
3164
3165                if Is_Overloadable (Def_Id)
3166                  and then Present (Alias (Def_Id))
3167                then
3168                   null;
3169
3170                --  If it is not a subprogram, it must be in an outer
3171                --  scope and pragma does not apply.
3172
3173                elsif not Is_Subprogram (Def_Id)
3174                  and then not Is_Generic_Subprogram (Def_Id)
3175                then
3176                   null;
3177
3178                --  Verify that the homonym is in the same declarative
3179                --  part (not just the same scope).
3180
3181                elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3182                  and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3183                then
3184                   exit;
3185
3186                else
3187                   Set_Imported (Def_Id);
3188
3189                   --  Special processing for Convention_Intrinsic
3190
3191                   if C = Convention_Intrinsic then
3192
3193                      --  Link_Name argument not allowed for intrinsic
3194
3195                      if Present (Arg3)
3196                        and then Chars (Arg3) = Name_Link_Name
3197                      then
3198                         Arg4 := Arg3;
3199                      end if;
3200
3201                      if Present (Arg4) then
3202                         Error_Pragma_Arg
3203                           ("Link_Name argument not allowed for " &
3204                            "Import Intrinsic",
3205                            Arg4);
3206                      end if;
3207
3208                      Set_Is_Intrinsic_Subprogram (Def_Id);
3209
3210                      --  If no external name is present, then check that
3211                      --  this is a valid intrinsic subprogram. If an external
3212                      --  name is present, then this is handled by the back end.
3213
3214                      if No (Arg3) then
3215                         Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3216                      end if;
3217                   end if;
3218
3219                   --  All interfaced procedures need an external symbol
3220                   --  created for them since they are always referenced
3221                   --  from another object file.
3222
3223                   Set_Is_Public (Def_Id);
3224
3225                   --  Verify that the subprogram does not have a completion
3226                   --  through a renaming declaration. For other completions
3227                   --  the pragma appears as a too late representation.
3228
3229                   declare
3230                      Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3231
3232                   begin
3233                      if Present (Decl)
3234                        and then Nkind (Decl) = N_Subprogram_Declaration
3235                        and then Present (Corresponding_Body (Decl))
3236                        and then
3237                          Nkind
3238                            (Unit_Declaration_Node
3239                              (Corresponding_Body (Decl))) =
3240                                              N_Subprogram_Renaming_Declaration
3241                      then
3242                         Error_Msg_Sloc := Sloc (Def_Id);
3243                         Error_Msg_NE
3244                           ("cannot import&, renaming already provided for " &
3245                            "declaration #", N, Def_Id);
3246                      end if;
3247                   end;
3248
3249                   Set_Has_Completion (Def_Id);
3250                   Process_Interface_Name (Def_Id, Arg3, Arg4);
3251                end if;
3252
3253                if Is_Compilation_Unit (Hom_Id) then
3254
3255                   --  Its possible homonyms are not affected by the pragma.
3256                   --  Such homonyms might be present in the context of other
3257                   --  units being compiled.
3258
3259                   exit;
3260
3261                else
3262                   Hom_Id := Homonym (Hom_Id);
3263                end if;
3264             end loop;
3265
3266          --  When the convention is Java or CIL, we also allow Import to be
3267          --  given for packages, generic packages, exceptions, and record
3268          --  components.
3269
3270          elsif (C = Convention_Java or else C = Convention_CIL)
3271            and then
3272              (Ekind (Def_Id) = E_Package
3273                 or else Ekind (Def_Id) = E_Generic_Package
3274                 or else Ekind (Def_Id) = E_Exception
3275                 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3276          then
3277             Set_Imported (Def_Id);
3278             Set_Is_Public (Def_Id);
3279             Process_Interface_Name (Def_Id, Arg3, Arg4);
3280
3281          --  Import a CPP class
3282
3283          elsif Is_Record_Type (Def_Id)
3284            and then C = Convention_CPP
3285          then
3286             if not Is_Tagged_Type (Def_Id) then
3287                Error_Msg_Sloc := Sloc (Def_Id);
3288                Error_Pragma_Arg ("imported 'C'P'P type must be tagged", Arg2);
3289
3290             else
3291                --  Types treated as CPP classes are treated as limited, but we
3292                --  don't require them to be declared this way. A warning is
3293                --  issued to encourage the user to declare them as limited.
3294                --  This is not an error, for compatibility reasons, because
3295                --  these types have been supported this way for some time.
3296
3297                if not Is_Limited_Type (Def_Id) then
3298                   Error_Msg_N
3299                     ("imported 'C'P'P type should be " &
3300                        "explicitly declared limited?",
3301                      Get_Pragma_Arg (Arg2));
3302                   Error_Msg_N
3303                     ("\type will be considered limited",
3304                      Get_Pragma_Arg (Arg2));
3305                end if;
3306
3307                Set_Is_CPP_Class (Def_Id);
3308                Set_Is_Limited_Record (Def_Id);
3309             end if;
3310
3311          else
3312             Error_Pragma_Arg
3313               ("second argument of pragma% must be object or subprogram",
3314                Arg2);
3315          end if;
3316
3317          --  If this pragma applies to a compilation unit, then the unit,
3318          --  which is a subprogram, does not require (or allow) a body.
3319          --  We also do not need to elaborate imported procedures.
3320
3321          if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3322             declare
3323                Cunit : constant Node_Id := Parent (Parent (N));
3324             begin
3325                Set_Body_Required (Cunit, False);
3326             end;
3327          end if;
3328       end Process_Import_Or_Interface;
3329
3330       --------------------
3331       -- Process_Inline --
3332       --------------------
3333
3334       procedure Process_Inline (Active : Boolean) is
3335          Assoc     : Node_Id;
3336          Decl      : Node_Id;
3337          Subp_Id   : Node_Id;
3338          Subp      : Entity_Id;
3339          Applies   : Boolean;
3340          Effective : Boolean := False;
3341
3342          procedure Make_Inline (Subp : Entity_Id);
3343          --  Subp is the defining unit name of the subprogram
3344          --  declaration. Set the flag, as well as the flag in the
3345          --  corresponding body, if there is one present.
3346
3347          procedure Set_Inline_Flags (Subp : Entity_Id);
3348          --  Sets Is_Inlined and Has_Pragma_Inline flags for Subp
3349
3350          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3351          --  Returns True if it can be determined at this stage that inlining
3352          --  is not possible, for examle if the body is available and contains
3353          --  exception handlers, we prevent inlining, since otherwise we can
3354          --  get undefined symbols at link time. This function also emits a
3355          --  warning if front-end inlining is enabled and the pragma appears
3356          --  too late.
3357          --  ??? is business with link symbols still valid, or does it relate
3358          --  to front end ZCX which is being phased out ???
3359
3360          ---------------------------
3361          -- Inlining_Not_Possible --
3362          ---------------------------
3363
3364          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3365             Decl  : constant Node_Id := Unit_Declaration_Node (Subp);
3366             Stats : Node_Id;
3367
3368          begin
3369             if Nkind (Decl) = N_Subprogram_Body then
3370                Stats := Handled_Statement_Sequence (Decl);
3371                return Present (Exception_Handlers (Stats))
3372                  or else Present (At_End_Proc (Stats));
3373
3374             elsif Nkind (Decl) = N_Subprogram_Declaration
3375               and then Present (Corresponding_Body (Decl))
3376             then
3377                if Front_End_Inlining
3378                  and then Analyzed (Corresponding_Body (Decl))
3379                then
3380                   Error_Msg_N ("pragma appears too late, ignored?", N);
3381                   return True;
3382
3383                --  If the subprogram is a renaming as body, the body is
3384                --  just a call to the renamed subprogram, and inlining is
3385                --  trivially possible.
3386
3387                elsif
3388                  Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
3389                                              N_Subprogram_Renaming_Declaration
3390                then
3391                   return False;
3392
3393                else
3394                   Stats :=
3395                     Handled_Statement_Sequence
3396                         (Unit_Declaration_Node (Corresponding_Body (Decl)));
3397
3398                   return
3399                     Present (Exception_Handlers (Stats))
3400                       or else Present (At_End_Proc (Stats));
3401                end if;
3402
3403             else
3404                --  If body is not available, assume the best, the check is
3405                --  performed again when compiling enclosing package bodies.
3406
3407                return False;
3408             end if;
3409          end Inlining_Not_Possible;
3410
3411          -----------------
3412          -- Make_Inline --
3413          -----------------
3414
3415          procedure Make_Inline (Subp : Entity_Id) is
3416             Kind       : constant Entity_Kind := Ekind (Subp);
3417             Inner_Subp : Entity_Id   := Subp;
3418
3419          begin
3420             if Etype (Subp) = Any_Type then
3421                return;
3422
3423             --  If inlining is not possible, for now do not treat as an error
3424
3425             elsif Inlining_Not_Possible (Subp) then
3426                Applies := True;
3427                return;
3428
3429             --  Here we have a candidate for inlining, but we must exclude
3430             --  derived operations. Otherwise we will end up trying to
3431             --  inline a phantom declaration, and the result would be to
3432             --  drag in a body which has no direct inlining associated with
3433             --  it. That would not only be inefficient but would also result
3434             --  in the backend doing cross-unit inlining in cases where it
3435             --  was definitely inappropriate to do so.
3436
3437             --  However, a simple Comes_From_Source test is insufficient,
3438             --  since we do want to allow inlining of generic instances,
3439             --  which also do not come from source. Predefined operators do
3440             --  not come from source but are not inlineable either.
3441
3442             elsif not Comes_From_Source (Subp)
3443               and then not Is_Generic_Instance (Subp)
3444               and then Scope (Subp) /= Standard_Standard
3445             then
3446                Applies := True;
3447                return;
3448
3449             --  The referenced entity must either be the enclosing entity,
3450             --  or an entity declared within the current open scope.
3451
3452             elsif Present (Scope (Subp))
3453               and then Scope (Subp) /= Current_Scope
3454               and then Subp /= Current_Scope
3455             then
3456                Error_Pragma_Arg
3457                  ("argument of% must be entity in current scope", Assoc);
3458                return;
3459             end if;
3460
3461             --  Processing for procedure, operator or function.
3462             --  If subprogram is aliased (as for an instance) indicate
3463             --  that the renamed entity (if declared in the same unit)
3464             --  is inlined.
3465
3466             if Is_Subprogram (Subp) then
3467                while Present (Alias (Inner_Subp)) loop
3468                   Inner_Subp := Alias (Inner_Subp);
3469                end loop;
3470
3471                if In_Same_Source_Unit (Subp, Inner_Subp) then
3472                   Set_Inline_Flags (Inner_Subp);
3473
3474                   Decl := Parent (Parent (Inner_Subp));
3475
3476                   if Nkind (Decl) = N_Subprogram_Declaration
3477                     and then Present (Corresponding_Body (Decl))
3478                   then
3479                      Set_Inline_Flags (Corresponding_Body (Decl));
3480                   end if;
3481                end if;
3482
3483                Applies := True;
3484
3485             --  For a generic subprogram set flag as well, for use at
3486             --  the point of instantiation, to determine whether the
3487             --  body should be generated.
3488
3489             elsif Is_Generic_Subprogram (Subp) then
3490                Set_Inline_Flags (Subp);
3491                Applies := True;
3492
3493             --  Literals are by definition inlined
3494
3495             elsif Kind = E_Enumeration_Literal then
3496                null;
3497
3498             --  Anything else is an error
3499
3500             else
3501                Error_Pragma_Arg
3502                  ("expect subprogram name for pragma%", Assoc);
3503             end if;
3504          end Make_Inline;
3505
3506          ----------------------
3507          -- Set_Inline_Flags --
3508          ----------------------
3509
3510          procedure Set_Inline_Flags (Subp : Entity_Id) is
3511          begin
3512             if Active then
3513                Set_Is_Inlined (Subp, True);
3514             end if;
3515
3516             if not Has_Pragma_Inline (Subp) then
3517                Set_Has_Pragma_Inline (Subp);
3518                Set_Next_Rep_Item (N, First_Rep_Item (Subp));
3519                Set_First_Rep_Item (Subp, N);
3520                Effective := True;
3521             end if;
3522          end Set_Inline_Flags;
3523
3524       --  Start of processing for Process_Inline
3525
3526       begin
3527          Check_No_Identifiers;
3528          Check_At_Least_N_Arguments (1);
3529
3530          if Active then
3531             Inline_Processing_Required := True;
3532          end if;
3533
3534          Assoc := Arg1;
3535          while Present (Assoc) loop
3536             Subp_Id := Expression (Assoc);
3537             Analyze (Subp_Id);
3538             Applies := False;
3539
3540             if Is_Entity_Name (Subp_Id) then
3541                Subp := Entity (Subp_Id);
3542
3543                if Subp = Any_Id then
3544
3545                   --  If previous error, avoid cascaded errors
3546
3547                   Applies := True;
3548                   Effective := True;
3549
3550                else
3551                   Make_Inline (Subp);
3552
3553                   while Present (Homonym (Subp))
3554                     and then Scope (Homonym (Subp)) = Current_Scope
3555                   loop
3556                      Make_Inline (Homonym (Subp));
3557                      Subp := Homonym (Subp);
3558                   end loop;
3559                end if;
3560             end if;
3561
3562             if not Applies then
3563                Error_Pragma_Arg
3564                  ("inappropriate argument for pragma%", Assoc);
3565
3566             elsif not Effective
3567               and then Warn_On_Redundant_Constructs
3568             then
3569                if Inlining_Not_Possible (Subp) then
3570                   Error_Msg_NE
3571                     ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
3572                else
3573                   Error_Msg_NE
3574                     ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
3575                end if;
3576             end if;
3577
3578             Next (Assoc);
3579          end loop;
3580       end Process_Inline;
3581
3582       ----------------------------
3583       -- Process_Interface_Name --
3584       ----------------------------
3585
3586       procedure Process_Interface_Name
3587         (Subprogram_Def : Entity_Id;
3588          Ext_Arg        : Node_Id;
3589          Link_Arg       : Node_Id)
3590       is
3591          Ext_Nam    : Node_Id;
3592          Link_Nam   : Node_Id;
3593          String_Val : String_Id;
3594
3595          procedure Check_Form_Of_Interface_Name (SN : Node_Id);
3596          --  SN is a string literal node for an interface name. This routine
3597          --  performs some minimal checks that the name is reasonable. In
3598          --  particular that no spaces or other obviously incorrect characters
3599          --  appear. This is only a warning, since any characters are allowed.
3600
3601          ----------------------------------
3602          -- Check_Form_Of_Interface_Name --
3603          ----------------------------------
3604
3605          procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
3606             S  : constant String_Id := Strval (Expr_Value_S (SN));
3607             SL : constant Nat       := String_Length (S);
3608             C  : Char_Code;
3609
3610          begin
3611             if SL = 0 then
3612                Error_Msg_N ("interface name cannot be null string", SN);
3613             end if;
3614
3615             for J in 1 .. SL loop
3616                C := Get_String_Char (S, J);
3617
3618                if Warn_On_Export_Import
3619                  and then
3620                    (not In_Character_Range (C)
3621                      or else (Get_Character (C) = ' '
3622                                and then VM_Target /= CLI_Target)
3623                      or else Get_Character (C) = ',')
3624                then
3625                   Error_Msg_N
3626                     ("?interface name contains illegal character", SN);
3627                end if;
3628             end loop;
3629          end Check_Form_Of_Interface_Name;
3630
3631       --  Start of processing for Process_Interface_Name
3632
3633       begin
3634          if No (Link_Arg) then
3635             if No (Ext_Arg) then
3636                if VM_Target = CLI_Target
3637                  and then Ekind (Subprogram_Def) = E_Package
3638                  and then Nkind (Parent (Subprogram_Def)) =
3639                                                  N_Package_Specification
3640                  and then Present (Generic_Parent (Parent (Subprogram_Def)))
3641                then
3642                   Set_Interface_Name
3643                      (Subprogram_Def,
3644                       Interface_Name
3645                         (Generic_Parent (Parent (Subprogram_Def))));
3646                end if;
3647
3648                return;
3649
3650             elsif Chars (Ext_Arg) = Name_Link_Name then
3651                Ext_Nam  := Empty;
3652                Link_Nam := Expression (Ext_Arg);
3653
3654             else
3655                Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3656                Ext_Nam  := Expression (Ext_Arg);
3657                Link_Nam := Empty;
3658             end if;
3659
3660          else
3661             Check_Optional_Identifier (Ext_Arg,  Name_External_Name);
3662             Check_Optional_Identifier (Link_Arg, Name_Link_Name);
3663             Ext_Nam  := Expression (Ext_Arg);
3664             Link_Nam := Expression (Link_Arg);
3665          end if;
3666
3667          --  Check expressions for external name and link name are static
3668
3669          if Present (Ext_Nam) then
3670             Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
3671             Check_Form_Of_Interface_Name (Ext_Nam);
3672
3673             --  Verify that the external name is not the name of a local
3674             --  entity, which would hide the imported one and lead to
3675             --  run-time surprises. The problem can only arise for entities
3676             --  declared in a package body (otherwise the external name is
3677             --  fully qualified and won't conflict).
3678
3679             declare
3680                Nam : Name_Id;
3681                E   : Entity_Id;
3682                Par : Node_Id;
3683
3684             begin
3685                if Prag_Id = Pragma_Import then
3686                   String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
3687                   Nam := Name_Find;
3688                   E   := Entity_Id (Get_Name_Table_Info (Nam));
3689
3690                   if Nam /= Chars (Subprogram_Def)
3691                     and then Present (E)
3692                     and then not Is_Overloadable (E)
3693                     and then Is_Immediately_Visible (E)
3694                     and then not Is_Imported (E)
3695                     and then Ekind (Scope (E)) = E_Package
3696                   then
3697                      Par := Parent (E);
3698                      while Present (Par) loop
3699                         if Nkind (Par) = N_Package_Body then
3700                            Error_Msg_Sloc  := Sloc (E);
3701                            Error_Msg_NE
3702                              ("imported entity is hidden by & declared#",
3703                                  Ext_Arg, E);
3704                            exit;
3705                         end if;
3706
3707                         Par := Parent (Par);
3708                      end loop;
3709                   end if;
3710                end if;
3711             end;
3712          end if;
3713
3714          if Present (Link_Nam) then
3715             Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
3716             Check_Form_Of_Interface_Name (Link_Nam);
3717          end if;
3718
3719          --  If there is no link name, just set the external name
3720
3721          if No (Link_Nam) then
3722             Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
3723
3724          --  For the Link_Name case, the given literal is preceded by an
3725          --  asterisk, which indicates to GCC that the given name should
3726          --  be taken literally, and in particular that no prepending of
3727          --  underlines should occur, even in systems where this is the
3728          --  normal default.
3729
3730          else
3731             Start_String;
3732
3733             if VM_Target = No_VM then
3734                Store_String_Char (Get_Char_Code ('*'));
3735             end if;
3736
3737             String_Val := Strval (Expr_Value_S (Link_Nam));
3738             Store_String_Chars (String_Val);
3739             Link_Nam :=
3740               Make_String_Literal (Sloc (Link_Nam),
3741                 Strval => End_String);
3742          end if;
3743
3744          Set_Encoded_Interface_Name
3745            (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
3746          Check_Duplicated_Export_Name (Link_Nam);
3747       end Process_Interface_Name;
3748
3749       -----------------------------------------
3750       -- Process_Interrupt_Or_Attach_Handler --
3751       -----------------------------------------
3752
3753       procedure Process_Interrupt_Or_Attach_Handler is
3754          Arg1_X       : constant Node_Id   := Expression (Arg1);
3755          Handler_Proc : constant Entity_Id := Entity (Arg1_X);
3756          Proc_Scope   : constant Entity_Id := Scope (Handler_Proc);
3757
3758       begin
3759          Set_Is_Interrupt_Handler (Handler_Proc);
3760
3761          --  If the pragma is not associated with a handler procedure
3762          --  within a protected type, then it must be for a nonprotected
3763          --  procedure for the AAMP target, in which case we don't
3764          --  associate a representation item with the procedure's scope.
3765
3766          if Ekind (Proc_Scope) = E_Protected_Type then
3767             if Prag_Id = Pragma_Interrupt_Handler
3768                  or else
3769                Prag_Id = Pragma_Attach_Handler
3770             then
3771                Record_Rep_Item (Proc_Scope, N);
3772             end if;
3773          end if;
3774       end Process_Interrupt_Or_Attach_Handler;
3775
3776       --------------------------------------------------
3777       -- Process_Restrictions_Or_Restriction_Warnings --
3778       --------------------------------------------------
3779
3780       --  Note: some of the simple identifier cases were handled in par-prag,
3781       --  but it is harmless (and more straightforward) to simply handle all
3782       --  cases here, even if it means we repeat a bit of work in some cases.
3783
3784       procedure Process_Restrictions_Or_Restriction_Warnings
3785         (Warn : Boolean)
3786       is
3787          Arg   : Node_Id;
3788          R_Id  : Restriction_Id;
3789          Id    : Name_Id;
3790          Expr  : Node_Id;
3791          Val   : Uint;
3792
3793          procedure Check_Unit_Name (N : Node_Id);
3794          --  Checks unit name parameter for No_Dependence. Returns if it has
3795          --  an appropriate form, otherwise raises pragma argument error.
3796
3797          ---------------------
3798          -- Check_Unit_Name --
3799          ---------------------
3800
3801          procedure Check_Unit_Name (N : Node_Id) is
3802          begin
3803             if Nkind (N) = N_Selected_Component then
3804                Check_Unit_Name (Prefix (N));
3805                Check_Unit_Name (Selector_Name (N));
3806
3807             elsif Nkind (N) = N_Identifier then
3808                return;
3809
3810             else
3811                Error_Pragma_Arg
3812                  ("wrong form for unit name for No_Dependence", N);
3813             end if;
3814          end Check_Unit_Name;
3815
3816       --  Start of processing for Process_Restrictions_Or_Restriction_Warnings
3817
3818       begin
3819          Check_Ada_83_Warning;
3820          Check_At_Least_N_Arguments (1);
3821          Check_Valid_Configuration_Pragma;
3822
3823          Arg := Arg1;
3824          while Present (Arg) loop
3825             Id := Chars (Arg);
3826             Expr := Expression (Arg);
3827
3828             --  Case of no restriction identifier present
3829
3830             if Id = No_Name then
3831                if Nkind (Expr) /= N_Identifier then
3832                   Error_Pragma_Arg
3833                     ("invalid form for restriction", Arg);
3834                end if;
3835
3836                R_Id :=
3837                  Get_Restriction_Id
3838                    (Process_Restriction_Synonyms (Expr));
3839
3840                if R_Id not in All_Boolean_Restrictions then
3841                   Error_Pragma_Arg
3842                     ("invalid restriction identifier", Arg);
3843                end if;
3844
3845                if Implementation_Restriction (R_Id) then
3846                   Check_Restriction
3847                     (No_Implementation_Restrictions, Arg);
3848                end if;
3849
3850                --  If this is a warning, then set the warning unless we already
3851                --  have a real restriction active (we never want a warning to
3852                --  override a real restriction).
3853
3854                if Warn then
3855                   if not Restriction_Active (R_Id) then
3856                      Set_Restriction (R_Id, N);
3857                      Restriction_Warnings (R_Id) := True;
3858                   end if;
3859
3860                --  If real restriction case, then set it and make sure that the
3861                --  restriction warning flag is off, since a real restriction
3862                --  always overrides a warning.
3863
3864                else
3865                   Set_Restriction (R_Id, N);
3866                   Restriction_Warnings (R_Id) := False;
3867                end if;
3868
3869                --  A very special case that must be processed here: pragma
3870                --  Restrictions (No_Exceptions) turns off all run-time
3871                --  checking. This is a bit dubious in terms of the formal
3872                --  language definition, but it is what is intended by RM
3873                --  H.4(12). Restriction_Warnings never affects generated code
3874                --  so this is done only in the real restriction case.
3875
3876                if R_Id = No_Exceptions and then not Warn then
3877                   Scope_Suppress := (others => True);
3878                end if;
3879
3880             --  Case of No_Dependence => unit-name. Note that the parser
3881             --  already made the necessary entry in the No_Dependence table.
3882
3883             elsif Id = Name_No_Dependence then
3884                Check_Unit_Name (Expr);
3885
3886             --  All other cases of restriction identifier present
3887
3888             else
3889                R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
3890                Analyze_And_Resolve (Expr, Any_Integer);
3891
3892                if R_Id not in All_Parameter_Restrictions then
3893                   Error_Pragma_Arg
3894                     ("invalid restriction parameter identifier", Arg);
3895
3896                elsif not Is_OK_Static_Expression (Expr) then
3897                   Flag_Non_Static_Expr
3898                     ("value must be static expression!", Expr);
3899                   raise Pragma_Exit;
3900
3901                elsif not Is_Integer_Type (Etype (Expr))
3902                  or else Expr_Value (Expr) < 0
3903                then
3904                   Error_Pragma_Arg
3905                     ("value must be non-negative integer", Arg);
3906                end if;
3907
3908                --  Restriction pragma is active
3909
3910                Val := Expr_Value (Expr);
3911
3912                if not UI_Is_In_Int_Range (Val) then
3913                   Error_Pragma_Arg
3914                     ("pragma ignored, value too large?", Arg);
3915                end if;
3916
3917                --  Warning case. If the real restriction is active, then we
3918                --  ignore the request, since warning never overrides a real
3919                --  restriction. Otherwise we set the proper warning. Note that
3920                --  this circuit sets the warning again if it is already set,
3921                --  which is what we want, since the constant may have changed.
3922
3923                if Warn then
3924                   if not Restriction_Active (R_Id) then
3925                      Set_Restriction
3926                        (R_Id, N, Integer (UI_To_Int (Val)));
3927                      Restriction_Warnings (R_Id) := True;
3928                   end if;
3929
3930                --  Real restriction case, set restriction and make sure warning
3931                --  flag is off since real restriction always overrides warning.
3932
3933                else
3934                   Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
3935                   Restriction_Warnings (R_Id) := False;
3936                end if;
3937             end if;
3938
3939             Next (Arg);
3940          end loop;
3941       end Process_Restrictions_Or_Restriction_Warnings;
3942
3943       ---------------------------------
3944       -- Process_Suppress_Unsuppress --
3945       ---------------------------------
3946
3947       --  Note: this procedure makes entries in the check suppress data
3948       --  structures managed by Sem. See spec of package Sem for full
3949       --  details on how we handle recording of check suppression.
3950
3951       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
3952          C    : Check_Id;
3953          E_Id : Node_Id;
3954          E    : Entity_Id;
3955
3956          In_Package_Spec : constant Boolean :=
3957                              (Ekind (Current_Scope) = E_Package
3958                                 or else
3959                               Ekind (Current_Scope) = E_Generic_Package)
3960                                and then not In_Package_Body (Current_Scope);
3961
3962          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
3963          --  Used to suppress a single check on the given entity
3964
3965          --------------------------------
3966          -- Suppress_Unsuppress_Echeck --
3967          --------------------------------
3968
3969          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
3970          begin
3971             Set_Checks_May_Be_Suppressed (E);
3972
3973             if In_Package_Spec then
3974                Push_Global_Suppress_Stack_Entry
3975                  (Entity   => E,
3976                   Check    => C,
3977                   Suppress => Suppress_Case);
3978
3979             else
3980                Push_Local_Suppress_Stack_Entry
3981                  (Entity   => E,
3982                   Check    => C,
3983                   Suppress => Suppress_Case);
3984             end if;
3985
3986             --  If this is a first subtype, and the base type is distinct,
3987             --  then also set the suppress flags on the base type.
3988
3989             if Is_First_Subtype (E)
3990               and then Etype (E) /= E
3991             then
3992                Suppress_Unsuppress_Echeck (Etype (E), C);
3993             end if;
3994          end Suppress_Unsuppress_Echeck;
3995
3996       --  Start of processing for Process_Suppress_Unsuppress
3997
3998       begin
3999          --  Suppress/Unsuppress can appear as a configuration pragma,
4000          --  or in a declarative part or a package spec (RM 11.5(5))
4001
4002          if not Is_Configuration_Pragma then
4003             Check_Is_In_Decl_Part_Or_Package_Spec;
4004          end if;
4005
4006          Check_At_Least_N_Arguments (1);
4007          Check_At_Most_N_Arguments (2);
4008          Check_No_Identifier (Arg1);
4009          Check_Arg_Is_Identifier (Arg1);
4010
4011          C := Get_Check_Id (Chars (Expression (Arg1)));
4012
4013          if C = No_Check_Id then
4014             Error_Pragma_Arg
4015               ("argument of pragma% is not valid check name", Arg1);
4016          end if;
4017
4018          if not Suppress_Case
4019            and then (C = All_Checks or else C = Overflow_Check)
4020          then
4021             Opt.Overflow_Checks_Unsuppressed := True;
4022          end if;
4023
4024          if Arg_Count = 1 then
4025
4026             --  Make an entry in the local scope suppress table. This is the
4027             --  table that directly shows the current value of the scope
4028             --  suppress check for any check id value.
4029
4030             if C = All_Checks then
4031
4032                --  For All_Checks, we set all specific predefined checks with
4033                --  the exception of Elaboration_Check, which is handled
4034                --  specially because of not wanting All_Checks to have the
4035                --  effect of deactivating static elaboration order processing.
4036
4037                for J in Scope_Suppress'Range loop
4038                   if J /= Elaboration_Check then
4039                      Scope_Suppress (J) := Suppress_Case;
4040                   end if;
4041                end loop;
4042
4043             --  If not All_Checks, and predefined check, then set appropriate
4044             --  scope entry. Note that we will set Elaboration_Check if this
4045             --  is explicitly specified.
4046
4047             elsif C in Predefined_Check_Id then
4048                Scope_Suppress (C) := Suppress_Case;
4049             end if;
4050
4051             --  Also make an entry in the Local_Entity_Suppress table
4052
4053             Push_Local_Suppress_Stack_Entry
4054               (Entity   => Empty,
4055                Check    => C,
4056                Suppress => Suppress_Case);
4057
4058          --  Case of two arguments present, where the check is suppressed for
4059          --  a specified entity (given as the second argument of the pragma)
4060
4061          else
4062             Check_Optional_Identifier (Arg2, Name_On);
4063             E_Id := Expression (Arg2);
4064             Analyze (E_Id);
4065
4066             if not Is_Entity_Name (E_Id) then
4067                Error_Pragma_Arg
4068                  ("second argument of pragma% must be entity name", Arg2);
4069             end if;
4070
4071             E := Entity (E_Id);
4072
4073             if E = Any_Id then
4074                return;
4075             end if;
4076
4077             --  Enforce RM 11.5(7) which requires that for a pragma that
4078             --  appears within a package spec, the named entity must be
4079             --  within the package spec. We allow the package name itself
4080             --  to be mentioned since that makes sense, although it is not
4081             --  strictly allowed by 11.5(7).
4082
4083             if In_Package_Spec
4084               and then E /= Current_Scope
4085               and then Scope (E) /= Current_Scope
4086             then
4087                Error_Pragma_Arg
4088                  ("entity in pragma% is not in package spec (RM 11.5(7))",
4089                   Arg2);
4090             end if;
4091
4092             --  Loop through homonyms. As noted below, in the case of a package
4093             --  spec, only homonyms within the package spec are considered.
4094
4095             loop
4096                Suppress_Unsuppress_Echeck (E, C);
4097
4098                if Is_Generic_Instance (E)
4099                  and then Is_Subprogram (E)
4100                  and then Present (Alias (E))
4101                then
4102                   Suppress_Unsuppress_Echeck (Alias (E), C);
4103                end if;
4104
4105                --  Move to next homonym
4106
4107                E := Homonym (E);
4108                exit when No (E);
4109
4110                --  If we are within a package specification, the
4111                --  pragma only applies to homonyms in the same scope.
4112
4113                exit when In_Package_Spec
4114                  and then Scope (E) /= Current_Scope;
4115             end loop;
4116          end if;
4117       end Process_Suppress_Unsuppress;
4118
4119       ------------------
4120       -- Set_Exported --
4121       ------------------
4122
4123       procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
4124       begin
4125          if Is_Imported (E) then
4126             Error_Pragma_Arg
4127               ("cannot export entity& that was previously imported", Arg);
4128
4129          elsif Present (Address_Clause (E)) then
4130             Error_Pragma_Arg
4131               ("cannot export entity& that has an address clause", Arg);
4132          end if;
4133
4134          Set_Is_Exported (E);
4135
4136          --  Generate a reference for entity explicitly, because the
4137          --  identifier may be overloaded and name resolution will not
4138          --  generate one.
4139
4140          Generate_Reference (E, Arg);
4141
4142          --  Deal with exporting non-library level entity
4143
4144          if not Is_Library_Level_Entity (E) then
4145
4146             --  Not allowed at all for subprograms
4147
4148             if Is_Subprogram (E) then
4149                Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
4150
4151             --  Otherwise set public and statically allocated
4152
4153             else
4154                Set_Is_Public (E);
4155                Set_Is_Statically_Allocated (E);
4156
4157                --  Warn if the corresponding W flag is set and the pragma
4158                --  comes from source. The latter may not be true e.g. on
4159                --  VMS where we expand export pragmas for exception codes
4160                --  associated with imported or exported exceptions. We do
4161                --  not want to generate a warning for something that the
4162                --  user did not write.
4163
4164                if Warn_On_Export_Import
4165                  and then Comes_From_Source (Arg)
4166                then
4167                   Error_Msg_NE
4168                     ("?& has been made static as a result of Export", Arg, E);
4169                   Error_Msg_N
4170                     ("\this usage is non-standard and non-portable", Arg);
4171                end if;
4172             end if;
4173          end if;
4174
4175          if Warn_On_Export_Import and then Is_Type (E) then
4176             Error_Msg_NE
4177               ("exporting a type has no effect?", Arg, E);
4178          end if;
4179
4180          if Warn_On_Export_Import and Inside_A_Generic then
4181             Error_Msg_NE
4182               ("all instances of& will have the same external name?", Arg, E);
4183          end if;
4184       end Set_Exported;
4185
4186       ----------------------------------------------
4187       -- Set_Extended_Import_Export_External_Name --
4188       ----------------------------------------------
4189
4190       procedure Set_Extended_Import_Export_External_Name
4191         (Internal_Ent : Entity_Id;
4192          Arg_External : Node_Id)
4193       is
4194          Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
4195          New_Name : Node_Id;
4196
4197       begin
4198          if No (Arg_External) then
4199             return;
4200          end if;
4201
4202          Check_Arg_Is_External_Name (Arg_External);
4203
4204          if Nkind (Arg_External) = N_String_Literal then
4205             if String_Length (Strval (Arg_External)) = 0 then
4206                return;
4207             else
4208                New_Name := Adjust_External_Name_Case (Arg_External);
4209             end if;
4210
4211          elsif Nkind (Arg_External) = N_Identifier then
4212             New_Name := Get_Default_External_Name (Arg_External);
4213
4214          --  Check_Arg_Is_External_Name should let through only
4215          --  identifiers and string literals or static string
4216          --  expressions (which are folded to string literals).
4217
4218          else
4219             raise Program_Error;
4220          end if;
4221
4222          --  If we already have an external name set (by a prior normal
4223          --  Import or Export pragma), then the external names must match
4224
4225          if Present (Interface_Name (Internal_Ent)) then
4226             Check_Matching_Internal_Names : declare
4227                S1 : constant String_Id := Strval (Old_Name);
4228                S2 : constant String_Id := Strval (New_Name);
4229
4230                procedure Mismatch;
4231                --  Called if names do not match
4232
4233                --------------
4234                -- Mismatch --
4235                --------------
4236
4237                procedure Mismatch is
4238                begin
4239                   Error_Msg_Sloc := Sloc (Old_Name);
4240                   Error_Pragma_Arg
4241                     ("external name does not match that given #",
4242                      Arg_External);
4243                end Mismatch;
4244
4245             --  Start of processing for Check_Matching_Internal_Names
4246
4247             begin
4248                if String_Length (S1) /= String_Length (S2) then
4249                   Mismatch;
4250
4251                else
4252                   for J in 1 .. String_Length (S1) loop
4253                      if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4254                         Mismatch;
4255                      end if;
4256                   end loop;
4257                end if;
4258             end Check_Matching_Internal_Names;
4259
4260          --  Otherwise set the given name
4261
4262          else
4263             Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4264             Check_Duplicated_Export_Name (New_Name);
4265          end if;
4266       end Set_Extended_Import_Export_External_Name;
4267
4268       ------------------
4269       -- Set_Imported --
4270       ------------------
4271
4272       procedure Set_Imported (E : Entity_Id) is
4273       begin
4274          --  Error message if already imported or exported
4275
4276          if Is_Exported (E) or else Is_Imported (E) then
4277             if Is_Exported (E) then
4278                Error_Msg_NE ("entity& was previously exported", N, E);
4279             else
4280                Error_Msg_NE ("entity& was previously imported", N, E);
4281             end if;
4282
4283             Error_Msg_Name_1 := Chars (N);
4284             Error_Msg_N
4285               ("\(pragma% applies to all previous entities)", N);
4286
4287             Error_Msg_Sloc  := Sloc (E);
4288             Error_Msg_NE ("\import not allowed for& declared#", N, E);
4289
4290          --  Here if not previously imported or exported, OK to import
4291
4292          else
4293             Set_Is_Imported (E);
4294
4295             --  If the entity is an object that is not at the library
4296             --  level, then it is statically allocated. We do not worry
4297             --  about objects with address clauses in this context since
4298             --  they are not really imported in the linker sense.
4299
4300             if Is_Object (E)
4301               and then not Is_Library_Level_Entity (E)
4302               and then No (Address_Clause (E))
4303             then
4304                Set_Is_Statically_Allocated (E);
4305             end if;
4306          end if;
4307       end Set_Imported;
4308
4309       -------------------------
4310       -- Set_Mechanism_Value --
4311       -------------------------
4312
4313       --  Note: the mechanism name has not been analyzed (and cannot indeed
4314       --  be analyzed, since it is semantic nonsense), so we get it in the
4315       --  exact form created by the parser.
4316
4317       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4318          Class : Node_Id;
4319          Param : Node_Id;
4320
4321          procedure Bad_Class;
4322          --  Signal bad descriptor class name
4323
4324          procedure Bad_Mechanism;
4325          --  Signal bad mechanism name
4326
4327          ---------------
4328          -- Bad_Class --
4329          ---------------
4330
4331          procedure Bad_Class is
4332          begin
4333             Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4334          end Bad_Class;
4335
4336          -------------------------
4337          -- Bad_Mechanism_Value --
4338          -------------------------
4339
4340          procedure Bad_Mechanism is
4341          begin
4342             Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4343          end Bad_Mechanism;
4344
4345       --  Start of processing for Set_Mechanism_Value
4346
4347       begin
4348          if Mechanism (Ent) /= Default_Mechanism then
4349             Error_Msg_NE
4350               ("mechanism for & has already been set", Mech_Name, Ent);
4351          end if;
4352
4353          --  MECHANISM_NAME ::= value | reference | descriptor
4354
4355          if Nkind (Mech_Name) = N_Identifier then
4356             if Chars (Mech_Name) = Name_Value then
4357                Set_Mechanism (Ent, By_Copy);
4358                return;
4359
4360             elsif Chars (Mech_Name) = Name_Reference then
4361                Set_Mechanism (Ent, By_Reference);
4362                return;
4363
4364             elsif Chars (Mech_Name) = Name_Descriptor then
4365                Check_VMS (Mech_Name);
4366                Set_Mechanism (Ent, By_Descriptor);
4367                return;
4368
4369             elsif Chars (Mech_Name) = Name_Copy then
4370                Error_Pragma_Arg
4371                  ("bad mechanism name, Value assumed", Mech_Name);
4372
4373             else
4374                Bad_Mechanism;
4375             end if;
4376
4377          --  MECHANISM_NAME ::= descriptor (CLASS_NAME)
4378          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
4379
4380          --  Note: this form is parsed as an indexed component
4381
4382          elsif Nkind (Mech_Name) = N_Indexed_Component then
4383             Class := First (Expressions (Mech_Name));
4384
4385             if Nkind (Prefix (Mech_Name)) /= N_Identifier
4386               or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
4387               or else Present (Next (Class))
4388             then
4389                Bad_Mechanism;
4390             end if;
4391
4392          --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
4393          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
4394
4395          --  Note: this form is parsed as a function call
4396
4397          elsif Nkind (Mech_Name) = N_Function_Call then
4398
4399             Param := First (Parameter_Associations (Mech_Name));
4400
4401             if Nkind (Name (Mech_Name)) /= N_Identifier
4402               or else Chars (Name (Mech_Name)) /= Name_Descriptor
4403               or else Present (Next (Param))
4404               or else No (Selector_Name (Param))
4405               or else Chars (Selector_Name (Param)) /= Name_Class
4406             then
4407                Bad_Mechanism;
4408             else
4409                Class := Explicit_Actual_Parameter (Param);
4410             end if;
4411
4412          else
4413             Bad_Mechanism;
4414          end if;
4415
4416          --  Fall through here with Class set to descriptor class name
4417
4418          Check_VMS (Mech_Name);
4419
4420          if Nkind (Class) /= N_Identifier then
4421             Bad_Class;
4422
4423          elsif Chars (Class) = Name_UBS then
4424             Set_Mechanism (Ent, By_Descriptor_UBS);
4425
4426          elsif Chars (Class) = Name_UBSB then
4427             Set_Mechanism (Ent, By_Descriptor_UBSB);
4428
4429          elsif Chars (Class) = Name_UBA then
4430             Set_Mechanism (Ent, By_Descriptor_UBA);
4431
4432          elsif Chars (Class) = Name_S then
4433             Set_Mechanism (Ent, By_Descriptor_S);
4434
4435          elsif Chars (Class) = Name_SB then
4436             Set_Mechanism (Ent, By_Descriptor_SB);
4437
4438          elsif Chars (Class) = Name_A then
4439             Set_Mechanism (Ent, By_Descriptor_A);
4440
4441          elsif Chars (Class) = Name_NCA then
4442             Set_Mechanism (Ent, By_Descriptor_NCA);
4443
4444          else
4445             Bad_Class;
4446          end if;
4447       end Set_Mechanism_Value;
4448
4449       ---------------------------
4450       -- Set_Ravenscar_Profile --
4451       ---------------------------
4452
4453       --  The tasks to be done here are
4454
4455       --    Set required policies
4456
4457       --      pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4458       --      pragma Locking_Policy (Ceiling_Locking)
4459
4460       --    Set Detect_Blocking mode
4461
4462       --    Set required restrictions (see System.Rident for detailed list)
4463
4464       procedure Set_Ravenscar_Profile (N : Node_Id) is
4465       begin
4466          --  pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4467
4468          if Task_Dispatching_Policy /= ' '
4469            and then Task_Dispatching_Policy /= 'F'
4470          then
4471             Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4472             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4473
4474          --  Set the FIFO_Within_Priorities policy, but always preserve
4475          --  System_Location since we like the error message with the run time
4476          --  name.
4477
4478          else
4479             Task_Dispatching_Policy := 'F';
4480
4481             if Task_Dispatching_Policy_Sloc /= System_Location then
4482                Task_Dispatching_Policy_Sloc := Loc;
4483             end if;
4484          end if;
4485
4486          --  pragma Locking_Policy (Ceiling_Locking)
4487
4488          if Locking_Policy /= ' '
4489            and then Locking_Policy /= 'C'
4490          then
4491             Error_Msg_Sloc := Locking_Policy_Sloc;
4492             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4493
4494          --  Set the Ceiling_Locking policy, but preserve System_Location since
4495          --  we like the error message with the run time name.
4496
4497          else
4498             Locking_Policy := 'C';
4499
4500             if Locking_Policy_Sloc /= System_Location then
4501                Locking_Policy_Sloc := Loc;
4502             end if;
4503          end if;
4504
4505          --  pragma Detect_Blocking
4506
4507          Detect_Blocking := True;
4508
4509          --  Set the corresponding restrictions
4510
4511          Set_Profile_Restrictions (Ravenscar, N, Warn => False);
4512       end Set_Ravenscar_Profile;
4513
4514    --  Start of processing for Analyze_Pragma
4515
4516    begin
4517       --  Deal with unrecognized pragma
4518
4519       if not Is_Pragma_Name (Chars (N)) then
4520          if Warn_On_Unrecognized_Pragma then
4521             Error_Msg_Name_1 := Chars (N);
4522             Error_Msg_N ("?unrecognized pragma%!", N);
4523
4524             for PN in First_Pragma_Name .. Last_Pragma_Name loop
4525                if Is_Bad_Spelling_Of
4526                  (Get_Name_String (Chars (N)),
4527                   Get_Name_String (PN))
4528                then
4529                   Error_Msg_Name_1 := PN;
4530                   Error_Msg_N ("\?possible misspelling of %!", N);
4531                   exit;
4532                end if;
4533             end loop;
4534          end if;
4535
4536          return;
4537       end if;
4538
4539       --  Here to start processing for recognized pragma
4540
4541       Prag_Id := Get_Pragma_Id (Chars (N));
4542
4543       --  Preset arguments
4544
4545       Arg1 := Empty;
4546       Arg2 := Empty;
4547       Arg3 := Empty;
4548       Arg4 := Empty;
4549
4550       if Present (Pragma_Argument_Associations (N)) then
4551          Arg1 := First (Pragma_Argument_Associations (N));
4552
4553          if Present (Arg1) then
4554             Arg2 := Next (Arg1);
4555
4556             if Present (Arg2) then
4557                Arg3 := Next (Arg2);
4558
4559                if Present (Arg3) then
4560                   Arg4 := Next (Arg3);
4561                end if;
4562             end if;
4563          end if;
4564       end if;
4565
4566       --  Count number of arguments
4567
4568       declare
4569          Arg_Node : Node_Id;
4570       begin
4571          Arg_Count := 0;
4572          Arg_Node := Arg1;
4573          while Present (Arg_Node) loop
4574             Arg_Count := Arg_Count + 1;
4575             Next (Arg_Node);
4576          end loop;
4577       end;
4578
4579       --  An enumeration type defines the pragmas that are supported by the
4580       --  implementation. Get_Pragma_Id (in package Prag) transorms a name
4581       --  into the corresponding enumeration value for the following case.
4582
4583       case Prag_Id is
4584
4585          -----------------
4586          -- Abort_Defer --
4587          -----------------
4588
4589          --  pragma Abort_Defer;
4590
4591          when Pragma_Abort_Defer =>
4592             GNAT_Pragma;
4593             Check_Arg_Count (0);
4594
4595             --  The only required semantic processing is to check the
4596             --  placement. This pragma must appear at the start of the
4597             --  statement sequence of a handled sequence of statements.
4598
4599             if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
4600               or else N /= First (Statements (Parent (N)))
4601             then
4602                Pragma_Misplaced;
4603             end if;
4604
4605          ------------
4606          -- Ada_83 --
4607          ------------
4608
4609          --  pragma Ada_83;
4610
4611          --  Note: this pragma also has some specific processing in Par.Prag
4612          --  because we want to set the Ada version mode during parsing.
4613
4614          when Pragma_Ada_83 =>
4615             GNAT_Pragma;
4616             Check_Arg_Count (0);
4617
4618             --  We really should check unconditionally for proper configuration
4619             --  pragma placement, since we really don't want mixed Ada modes
4620             --  within a single unit, and the GNAT reference manual has always
4621             --  said this was a configuration pragma, but we did not check and
4622             --  are hesitant to add the check now.
4623
4624             --  However, we really cannot tolerate mixing Ada 2005 with Ada 83
4625             --  or Ada 95, so we must check if we are in Ada 2005 mode.
4626
4627             if Ada_Version >= Ada_05 then
4628                Check_Valid_Configuration_Pragma;
4629             end if;
4630
4631             --  Now set Ada 83 mode
4632
4633             Ada_Version := Ada_83;
4634             Ada_Version_Explicit := Ada_Version;
4635
4636          ------------
4637          -- Ada_95 --
4638          ------------
4639
4640          --  pragma Ada_95;
4641
4642          --  Note: this pragma also has some specific processing in Par.Prag
4643          --  because we want to set the Ada 83 version mode during parsing.
4644
4645          when Pragma_Ada_95 =>
4646             GNAT_Pragma;
4647             Check_Arg_Count (0);
4648
4649             --  We really should check unconditionally for proper configuration
4650             --  pragma placement, since we really don't want mixed Ada modes
4651             --  within a single unit, and the GNAT reference manual has always
4652             --  said this was a configuration pragma, but we did not check and
4653             --  are hesitant to add the check now.
4654
4655             --  However, we really cannot tolerate mixing Ada 2005 with Ada 83
4656             --  or Ada 95, so we must check if we are in Ada 2005 mode.
4657
4658             if Ada_Version >= Ada_05 then
4659                Check_Valid_Configuration_Pragma;
4660             end if;
4661
4662             --  Now set Ada 95 mode
4663
4664             Ada_Version := Ada_95;
4665             Ada_Version_Explicit := Ada_Version;
4666
4667          ---------------------
4668          -- Ada_05/Ada_2005 --
4669          ---------------------
4670
4671          --  pragma Ada_05;
4672          --  pragma Ada_05 (LOCAL_NAME);
4673
4674          --  pragma Ada_2005;
4675          --  pragma Ada_2005 (LOCAL_NAME):
4676
4677          --  Note: these pragma also have some specific processing in Par.Prag
4678          --  because we want to set the Ada 2005 version mode during parsing.
4679
4680          when Pragma_Ada_05 | Pragma_Ada_2005 => declare
4681             E_Id : Node_Id;
4682
4683          begin
4684             GNAT_Pragma;
4685
4686             if Arg_Count = 1 then
4687                Check_Arg_Is_Local_Name (Arg1);
4688                E_Id := Expression (Arg1);
4689
4690                if Etype (E_Id) = Any_Type then
4691                   return;
4692                end if;
4693
4694                Set_Is_Ada_2005_Only (Entity (E_Id));
4695
4696             else
4697                Check_Arg_Count (0);
4698
4699                --  For Ada_2005 we unconditionally enforce the documented
4700                --  configuration pragma placement, since we do not want to
4701                --  tolerate mixed modes in a unit involving Ada 2005. That
4702                --  would cause real difficulties for those cases where there
4703                --  are incompatibilities between Ada 95 and Ada 2005.
4704
4705                Check_Valid_Configuration_Pragma;
4706
4707                --  Now set Ada 2005 mode
4708
4709                Ada_Version := Ada_05;
4710                Ada_Version_Explicit := Ada_05;
4711             end if;
4712          end;
4713
4714          ----------------------
4715          -- All_Calls_Remote --
4716          ----------------------
4717
4718          --  pragma All_Calls_Remote [(library_package_NAME)];
4719
4720          when Pragma_All_Calls_Remote => All_Calls_Remote : declare
4721             Lib_Entity : Entity_Id;
4722
4723          begin
4724             Check_Ada_83_Warning;
4725             Check_Valid_Library_Unit_Pragma;
4726
4727             if Nkind (N) = N_Null_Statement then
4728                return;
4729             end if;
4730
4731             Lib_Entity := Find_Lib_Unit_Name;
4732
4733             --  This pragma should only apply to a RCI unit (RM E.2.3(23))
4734
4735             if Present (Lib_Entity)
4736               and then not Debug_Flag_U
4737             then
4738                if not Is_Remote_Call_Interface (Lib_Entity) then
4739                   Error_Pragma ("pragma% only apply to rci unit");
4740
4741                --  Set flag for entity of the library unit
4742
4743                else
4744                   Set_Has_All_Calls_Remote (Lib_Entity);
4745                end if;
4746
4747             end if;
4748          end All_Calls_Remote;
4749
4750          --------------
4751          -- Annotate --
4752          --------------
4753
4754          --  pragma Annotate (IDENTIFIER {, ARG});
4755          --  ARG ::= NAME | EXPRESSION
4756
4757          when Pragma_Annotate => Annotate : begin
4758             GNAT_Pragma;
4759             Check_At_Least_N_Arguments (1);
4760             Check_Arg_Is_Identifier (Arg1);
4761
4762             declare
4763                Arg : Node_Id;
4764                Exp : Node_Id;
4765
4766             begin
4767                Arg := Arg2;
4768                while Present (Arg) loop
4769                   Exp := Expression (Arg);
4770                   Analyze (Exp);
4771
4772                   if Is_Entity_Name (Exp) then
4773                      null;
4774
4775                   elsif Nkind (Exp) = N_String_Literal then
4776                      Resolve (Exp, Standard_String);
4777
4778                   elsif Is_Overloaded (Exp) then
4779                      Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
4780
4781                   else
4782                      Resolve (Exp);
4783                   end if;
4784
4785                   Next (Arg);
4786                end loop;
4787             end;
4788          end Annotate;
4789
4790          ------------
4791          -- Assert --
4792          ------------
4793
4794          --  pragma Assert ([Check =>] Boolean_EXPRESSION
4795          --                 [, [Message =>] Static_String_EXPRESSION]);
4796
4797          when Pragma_Assert => Assert : declare
4798             Expr : Node_Id;
4799
4800          begin
4801             Ada_2005_Pragma;
4802             Check_At_Least_N_Arguments (1);
4803             Check_At_Most_N_Arguments (2);
4804             Check_Arg_Order ((Name_Check, Name_Message));
4805             Check_Optional_Identifier (Arg1, Name_Check);
4806
4807             if Arg_Count > 1 then
4808                Check_Optional_Identifier (Arg2, Name_Message);
4809                Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4810             end if;
4811
4812             --  If expansion is active and assertions are inactive, then
4813             --  we rewrite the Assertion as:
4814
4815             --    if False and then condition then
4816             --       null;
4817             --    end if;
4818
4819             --  The reason we do this rewriting during semantic analysis
4820             --  rather than as part of normal expansion is that we cannot
4821             --  analyze and expand the code for the boolean expression
4822             --  directly, or it may cause insertion of actions that would
4823             --  escape the attempt to suppress the assertion code.
4824
4825             Expr := Expression (Arg1);
4826
4827             if Expander_Active and not Assertions_Enabled then
4828                Rewrite (N,
4829                  Make_If_Statement (Loc,
4830                    Condition =>
4831                      Make_And_Then (Loc,
4832                        Left_Opnd  => New_Occurrence_Of (Standard_False, Loc),
4833                        Right_Opnd => Expr),
4834                    Then_Statements => New_List (
4835                      Make_Null_Statement (Loc))));
4836
4837                Analyze (N);
4838
4839             --  Otherwise (if assertions are enabled, or if we are not
4840             --  operating with expansion active), then we just analyze
4841             --  and resolve the expression.
4842
4843             else
4844                Analyze_And_Resolve (Expr, Any_Boolean);
4845             end if;
4846
4847             --  If assertion is of the form (X'First = literal), where X is
4848             --  formal parameter, then set Low_Bound_Known flag on this formal.
4849
4850             if Nkind (Expr) = N_Op_Eq then
4851                declare
4852                   Right : constant Node_Id := Right_Opnd (Expr);
4853                   Left  : constant Node_Id := Left_Opnd  (Expr);
4854                begin
4855                   if Nkind (Left) = N_Attribute_Reference
4856                     and then Attribute_Name (Left) = Name_First
4857                     and then Is_Entity_Name (Prefix (Left))
4858                     and then Is_Formal (Entity (Prefix (Left)))
4859                     and then Nkind (Right) = N_Integer_Literal
4860                   then
4861                      Set_Low_Bound_Known (Entity (Prefix (Left)));
4862                   end if;
4863                end;
4864             end if;
4865          end Assert;
4866
4867          ----------------------
4868          -- Assertion_Policy --
4869          ----------------------
4870
4871          --  pragma Assertion_Policy (Check | Ignore)
4872
4873          when Pragma_Assertion_Policy =>
4874             Ada_2005_Pragma;
4875             Check_Arg_Count (1);
4876             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
4877             Assertions_Enabled := Chars (Expression (Arg1)) = Name_Check;
4878
4879          ---------------
4880          -- AST_Entry --
4881          ---------------
4882
4883          --  pragma AST_Entry (entry_IDENTIFIER);
4884
4885          when Pragma_AST_Entry => AST_Entry : declare
4886             Ent : Node_Id;
4887
4888          begin
4889             GNAT_Pragma;
4890             Check_VMS (N);
4891             Check_Arg_Count (1);
4892             Check_No_Identifiers;
4893             Check_Arg_Is_Local_Name (Arg1);
4894             Ent := Entity (Expression (Arg1));
4895
4896             --  Note: the implementation of the AST_Entry pragma could handle
4897             --  the entry family case fine, but for now we are consistent with
4898             --  the DEC rules, and do not allow the pragma, which of course
4899             --  has the effect of also forbidding the attribute.
4900
4901             if Ekind (Ent) /= E_Entry then
4902                Error_Pragma_Arg
4903                  ("pragma% argument must be simple entry name", Arg1);
4904
4905             elsif Is_AST_Entry (Ent) then
4906                Error_Pragma_Arg
4907                  ("duplicate % pragma for entry", Arg1);
4908
4909             elsif Has_Homonym (Ent) then
4910                Error_Pragma_Arg
4911                  ("pragma% argument cannot specify overloaded entry", Arg1);
4912
4913             else
4914                declare
4915                   FF : constant Entity_Id := First_Formal (Ent);
4916
4917                begin
4918                   if Present (FF) then
4919                      if Present (Next_Formal (FF)) then
4920                         Error_Pragma_Arg
4921                           ("entry for pragma% can have only one argument",
4922                            Arg1);
4923
4924                      elsif Parameter_Mode (FF) /= E_In_Parameter then
4925                         Error_Pragma_Arg
4926                           ("entry parameter for pragma% must have mode IN",
4927                            Arg1);
4928                      end if;
4929                   end if;
4930                end;
4931
4932                Set_Is_AST_Entry (Ent);
4933             end if;
4934          end AST_Entry;
4935
4936          ------------------
4937          -- Asynchronous --
4938          ------------------
4939
4940          --  pragma Asynchronous (LOCAL_NAME);
4941
4942          when Pragma_Asynchronous => Asynchronous : declare
4943             Nm     : Entity_Id;
4944             C_Ent  : Entity_Id;
4945             L      : List_Id;
4946             S      : Node_Id;
4947             N      : Node_Id;
4948             Formal : Entity_Id;
4949
4950             procedure Process_Async_Pragma;
4951             --  Common processing for procedure and access-to-procedure case
4952
4953             --------------------------
4954             -- Process_Async_Pragma --
4955             --------------------------
4956
4957             procedure Process_Async_Pragma is
4958             begin
4959                if No (L) then
4960                   Set_Is_Asynchronous (Nm);
4961                   return;
4962                end if;
4963
4964                --  The formals should be of mode IN (RM E.4.1(6))
4965
4966                S := First (L);
4967                while Present (S) loop
4968                   Formal := Defining_Identifier (S);
4969
4970                   if Nkind (Formal) = N_Defining_Identifier
4971                     and then Ekind (Formal) /= E_In_Parameter
4972                   then
4973                      Error_Pragma_Arg
4974                        ("pragma% procedure can only have IN parameter",
4975                         Arg1);
4976                   end if;
4977
4978                   Next (S);
4979                end loop;
4980
4981                Set_Is_Asynchronous (Nm);
4982             end Process_Async_Pragma;
4983
4984          --  Start of processing for pragma Asynchronous
4985
4986          begin
4987             Check_Ada_83_Warning;
4988             Check_No_Identifiers;
4989             Check_Arg_Count (1);
4990             Check_Arg_Is_Local_Name (Arg1);
4991
4992             if Debug_Flag_U then
4993                return;
4994             end if;
4995
4996             C_Ent := Cunit_Entity (Current_Sem_Unit);
4997             Analyze (Expression (Arg1));
4998             Nm := Entity (Expression (Arg1));
4999
5000             if not Is_Remote_Call_Interface (C_Ent)
5001               and then not Is_Remote_Types (C_Ent)
5002             then
5003                --  This pragma should only appear in an RCI or Remote Types
5004                --  unit (RM E.4.1(4))
5005
5006                Error_Pragma
5007                  ("pragma% not in Remote_Call_Interface or " &
5008                   "Remote_Types unit");
5009             end if;
5010
5011             if Ekind (Nm) = E_Procedure
5012               and then Nkind (Parent (Nm)) = N_Procedure_Specification
5013             then
5014                if not Is_Remote_Call_Interface (Nm) then
5015                   Error_Pragma_Arg
5016                     ("pragma% cannot be applied on non-remote procedure",
5017                      Arg1);
5018                end if;
5019
5020                L := Parameter_Specifications (Parent (Nm));
5021                Process_Async_Pragma;
5022                return;
5023
5024             elsif Ekind (Nm) = E_Function then
5025                Error_Pragma_Arg
5026                  ("pragma% cannot be applied to function", Arg1);
5027
5028             elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
5029
5030                if Is_Record_Type (Nm) then
5031                   --  A record type that is the Equivalent_Type for
5032                   --  a remote access-to-subprogram type.
5033
5034                   N := Declaration_Node (Corresponding_Remote_Type (Nm));
5035
5036                else
5037                   --  A non-expanded RAS type (case where distribution is
5038                   --  not enabled).
5039
5040                   N := Declaration_Node (Nm);
5041                end if;
5042
5043                if Nkind (N) = N_Full_Type_Declaration
5044                  and then Nkind (Type_Definition (N)) =
5045                                      N_Access_Procedure_Definition
5046                then
5047                   L := Parameter_Specifications (Type_Definition (N));
5048                   Process_Async_Pragma;
5049
5050                   if Is_Asynchronous (Nm)
5051                     and then Expander_Active
5052                     and then Get_PCS_Name /= Name_No_DSA
5053                   then
5054                      RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
5055                   end if;
5056
5057                else
5058                   Error_Pragma_Arg
5059                     ("pragma% cannot reference access-to-function type",
5060                     Arg1);
5061                end if;
5062
5063             --  Only other possibility is Access-to-class-wide type
5064
5065             elsif Is_Access_Type (Nm)
5066               and then Is_Class_Wide_Type (Designated_Type (Nm))
5067             then
5068                Check_First_Subtype (Arg1);
5069                Set_Is_Asynchronous (Nm);
5070                if Expander_Active then
5071                   RACW_Type_Is_Asynchronous (Nm);
5072                end if;
5073
5074             else
5075                Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
5076             end if;
5077          end Asynchronous;
5078
5079          ------------
5080          -- Atomic --
5081          ------------
5082
5083          --  pragma Atomic (LOCAL_NAME);
5084
5085          when Pragma_Atomic =>
5086             Process_Atomic_Shared_Volatile;
5087
5088          -----------------------
5089          -- Atomic_Components --
5090          -----------------------
5091
5092          --  pragma Atomic_Components (array_LOCAL_NAME);
5093
5094          --  This processing is shared by Volatile_Components
5095
5096          when Pragma_Atomic_Components   |
5097               Pragma_Volatile_Components =>
5098
5099          Atomic_Components : declare
5100             E_Id : Node_Id;
5101             E    : Entity_Id;
5102             D    : Node_Id;
5103             K    : Node_Kind;
5104
5105          begin
5106             Check_Ada_83_Warning;
5107             Check_No_Identifiers;
5108             Check_Arg_Count (1);
5109             Check_Arg_Is_Local_Name (Arg1);
5110             E_Id := Expression (Arg1);
5111
5112             if Etype (E_Id) = Any_Type then
5113                return;
5114             end if;
5115
5116             E := Entity (E_Id);
5117
5118             if Rep_Item_Too_Early (E, N)
5119                  or else
5120                Rep_Item_Too_Late (E, N)
5121             then
5122                return;
5123             end if;
5124
5125             D := Declaration_Node (E);
5126             K := Nkind (D);
5127
5128             if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
5129               or else
5130                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
5131                    and then Nkind (D) = N_Object_Declaration
5132                    and then Nkind (Object_Definition (D)) =
5133                                        N_Constrained_Array_Definition)
5134             then
5135                --  The flag is set on the object, or on the base type
5136
5137                if Nkind (D) /= N_Object_Declaration then
5138                   E := Base_Type (E);
5139                end if;
5140
5141                Set_Has_Volatile_Components (E);
5142
5143                if Prag_Id = Pragma_Atomic_Components then
5144                   Set_Has_Atomic_Components (E);
5145
5146                   if Is_Packed (E) then
5147                      Set_Is_Packed (E, False);
5148
5149                      Error_Pragma_Arg
5150                        ("?Pack canceled, cannot pack atomic components",
5151                         Arg1);
5152                   end if;
5153                end if;
5154
5155             else
5156                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
5157             end if;
5158          end Atomic_Components;
5159
5160          --------------------
5161          -- Attach_Handler --
5162          --------------------
5163
5164          --  pragma Attach_Handler (handler_NAME, EXPRESSION);
5165
5166          when Pragma_Attach_Handler =>
5167             Check_Ada_83_Warning;
5168             Check_No_Identifiers;
5169             Check_Arg_Count (2);
5170
5171             if No_Run_Time_Mode then
5172                Error_Msg_CRT ("Attach_Handler pragma", N);
5173             else
5174                Check_Interrupt_Or_Attach_Handler;
5175
5176                --  The expression that designates the attribute may
5177                --  depend on a discriminant, and is therefore a per-
5178                --  object expression, to be expanded in the init proc.
5179                --  If expansion is enabled, perform semantic checks
5180                --  on a copy only.
5181
5182                if Expander_Active then
5183                   declare
5184                      Temp : constant Node_Id :=
5185                               New_Copy_Tree (Expression (Arg2));
5186                   begin
5187                      Set_Parent (Temp, N);
5188                      Pre_Analyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
5189                   end;
5190
5191                else
5192                   Analyze (Expression (Arg2));
5193                   Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
5194                end if;
5195
5196                Process_Interrupt_Or_Attach_Handler;
5197             end if;
5198
5199          --------------------
5200          -- C_Pass_By_Copy --
5201          --------------------
5202
5203          --  pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
5204
5205          when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
5206             Arg : Node_Id;
5207             Val : Uint;
5208
5209          begin
5210             GNAT_Pragma;
5211             Check_Valid_Configuration_Pragma;
5212             Check_Arg_Count (1);
5213             Check_Optional_Identifier (Arg1, "max_size");
5214
5215             Arg := Expression (Arg1);
5216             Check_Arg_Is_Static_Expression (Arg, Any_Integer);
5217
5218             Val := Expr_Value (Arg);
5219
5220             if Val <= 0 then
5221                Error_Pragma_Arg
5222                  ("maximum size for pragma% must be positive", Arg1);
5223
5224             elsif UI_Is_In_Int_Range (Val) then
5225                Default_C_Record_Mechanism := UI_To_Int (Val);
5226
5227             --  If a giant value is given, Int'Last will do well enough.
5228             --  If sometime someone complains that a record larger than
5229             --  two gigabytes is not copied, we will worry about it then!
5230
5231             else
5232                Default_C_Record_Mechanism := Mechanism_Type'Last;
5233             end if;
5234          end C_Pass_By_Copy;
5235
5236          ----------------
5237          -- Check_Name --
5238          ----------------
5239
5240          --  pragma Check_Name (check_IDENTIFIER);
5241
5242          when Pragma_Check_Name =>
5243             Check_No_Identifiers;
5244             GNAT_Pragma;
5245             Check_Valid_Configuration_Pragma;
5246             Check_Arg_Count (1);
5247             Check_Arg_Is_Identifier (Arg1);
5248
5249             declare
5250                Nam : constant Name_Id := Chars (Expression (Arg1));
5251
5252             begin
5253                for J in Check_Names.First .. Check_Names.Last loop
5254                   if Check_Names.Table (J) = Nam then
5255                      return;
5256                   end if;
5257                end loop;
5258
5259                Check_Names.Append (Nam);
5260             end;
5261
5262          ---------------------
5263          -- CIL_Constructor --
5264          ---------------------
5265
5266          --  pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
5267
5268          --  Processing for this pragma is shared with Java_Constructor
5269
5270          -------------
5271          -- Comment --
5272          -------------
5273
5274          --  pragma Comment (static_string_EXPRESSION)
5275
5276          --  Processing for pragma Comment shares the circuitry for
5277          --  pragma Ident. The only differences are that Ident enforces
5278          --  a limit of 31 characters on its argument, and also enforces
5279          --  limitations on placement for DEC compatibility. Pragma
5280          --  Comment shares neither of these restrictions.
5281
5282          -------------------
5283          -- Common_Object --
5284          -------------------
5285
5286          --  pragma Common_Object (
5287          --        [Internal =>] LOCAL_NAME,
5288          --     [, [External =>] EXTERNAL_SYMBOL]
5289          --     [, [Size     =>] EXTERNAL_SYMBOL]);
5290
5291          --  Processing for this pragma is shared with Psect_Object
5292
5293          ------------------------
5294          -- Compile_Time_Error --
5295          ------------------------
5296
5297          --  pragma Compile_Time_Error
5298          --    (boolean_EXPRESSION, static_string_EXPRESSION);
5299
5300          when Pragma_Compile_Time_Error =>
5301             Process_Compile_Time_Warning_Or_Error;
5302
5303          --------------------------
5304          -- Compile_Time_Warning --
5305          --------------------------
5306
5307          --  pragma Compile_Time_Warning
5308          --    (boolean_EXPRESSION, static_string_EXPRESSION);
5309
5310          when Pragma_Compile_Time_Warning =>
5311             Process_Compile_Time_Warning_Or_Error;
5312
5313          -------------------
5314          -- Compiler_Unit --
5315          -------------------
5316
5317          when Pragma_Compiler_Unit =>
5318             GNAT_Pragma;
5319             Check_Arg_Count (0);
5320             Set_Is_Compiler_Unit (Get_Source_Unit (N));
5321
5322          -----------------------------
5323          -- Complete_Representation --
5324          -----------------------------
5325
5326          --  pragma Complete_Representation;
5327
5328          when Pragma_Complete_Representation =>
5329             GNAT_Pragma;
5330             Check_Arg_Count (0);
5331
5332             if Nkind (Parent (N)) /= N_Record_Representation_Clause then
5333                Error_Pragma
5334                  ("pragma & must appear within record representation clause");
5335             end if;
5336
5337          ----------------------------
5338          -- Complex_Representation --
5339          ----------------------------
5340
5341          --  pragma Complex_Representation ([Entity =>] LOCAL_NAME);
5342
5343          when Pragma_Complex_Representation => Complex_Representation : declare
5344             E_Id : Entity_Id;
5345             E    : Entity_Id;
5346             Ent  : Entity_Id;
5347
5348          begin
5349             GNAT_Pragma;
5350             Check_Arg_Count (1);
5351             Check_Optional_Identifier (Arg1, Name_Entity);
5352             Check_Arg_Is_Local_Name (Arg1);
5353             E_Id := Expression (Arg1);
5354
5355             if Etype (E_Id) = Any_Type then
5356                return;
5357             end if;
5358
5359             E := Entity (E_Id);
5360
5361             if not Is_Record_Type (E) then
5362                Error_Pragma_Arg
5363                  ("argument for pragma% must be record type", Arg1);
5364             end if;
5365
5366             Ent := First_Entity (E);
5367
5368             if No (Ent)
5369               or else No (Next_Entity (Ent))
5370               or else Present (Next_Entity (Next_Entity (Ent)))
5371               or else not Is_Floating_Point_Type (Etype (Ent))
5372               or else Etype (Ent) /= Etype (Next_Entity (Ent))
5373             then
5374                Error_Pragma_Arg
5375                  ("record for pragma% must have two fields of same fpt type",
5376                   Arg1);
5377
5378             else
5379                Set_Has_Complex_Representation (Base_Type (E));
5380
5381                --  We need to treat the type has having a non-standard
5382                --  representation, for back-end purposes, even though in
5383                --  general a complex will have the default representation
5384                --  of a record with two real components.
5385
5386                Set_Has_Non_Standard_Rep (Base_Type (E));
5387             end if;
5388          end Complex_Representation;
5389
5390          -------------------------
5391          -- Component_Alignment --
5392          -------------------------
5393
5394          --  pragma Component_Alignment (
5395          --        [Form =>] ALIGNMENT_CHOICE
5396          --     [, [Name =>] type_LOCAL_NAME]);
5397          --
5398          --   ALIGNMENT_CHOICE ::=
5399          --     Component_Size
5400          --   | Component_Size_4
5401          --   | Storage_Unit
5402          --   | Default
5403
5404          when Pragma_Component_Alignment => Component_AlignmentP : declare
5405             Args  : Args_List (1 .. 2);
5406             Names : constant Name_List (1 .. 2) := (
5407                       Name_Form,
5408                       Name_Name);
5409
5410             Form  : Node_Id renames Args (1);
5411             Name  : Node_Id renames Args (2);
5412
5413             Atype : Component_Alignment_Kind;
5414             Typ   : Entity_Id;
5415
5416          begin
5417             GNAT_Pragma;
5418             Gather_Associations (Names, Args);
5419
5420             if No (Form) then
5421                Error_Pragma ("missing Form argument for pragma%");
5422             end if;
5423
5424             Check_Arg_Is_Identifier (Form);
5425
5426             --  Get proper alignment, note that Default = Component_Size
5427             --  on all machines we have so far, and we want to set this
5428             --  value rather than the default value to indicate that it
5429             --  has been explicitly set (and thus will not get overridden
5430             --  by the default component alignment for the current scope)
5431
5432             if Chars (Form) = Name_Component_Size then
5433                Atype := Calign_Component_Size;
5434
5435             elsif Chars (Form) = Name_Component_Size_4 then
5436                Atype := Calign_Component_Size_4;
5437
5438             elsif Chars (Form) = Name_Default then
5439                Atype := Calign_Component_Size;
5440
5441             elsif Chars (Form) = Name_Storage_Unit then
5442                Atype := Calign_Storage_Unit;
5443
5444             else
5445                Error_Pragma_Arg
5446                  ("invalid Form parameter for pragma%", Form);
5447             end if;
5448
5449             --  Case with no name, supplied, affects scope table entry
5450
5451             if No (Name) then
5452                Scope_Stack.Table
5453                  (Scope_Stack.Last).Component_Alignment_Default := Atype;
5454
5455             --  Case of name supplied
5456
5457             else
5458                Check_Arg_Is_Local_Name (Name);
5459                Find_Type (Name);
5460                Typ := Entity (Name);
5461
5462                if Typ = Any_Type
5463                  or else Rep_Item_Too_Early (Typ, N)
5464                then
5465                   return;
5466                else
5467                   Typ := Underlying_Type (Typ);
5468                end if;
5469
5470                if not Is_Record_Type (Typ)
5471                  and then not Is_Array_Type (Typ)
5472                then
5473                   Error_Pragma_Arg
5474                     ("Name parameter of pragma% must identify record or " &
5475                      "array type", Name);
5476                end if;
5477
5478                --  An explicit Component_Alignment pragma overrides an
5479                --  implicit pragma Pack, but not an explicit one.
5480
5481                if not Has_Pragma_Pack (Base_Type (Typ)) then
5482                   Set_Is_Packed (Base_Type (Typ), False);
5483                   Set_Component_Alignment (Base_Type (Typ), Atype);
5484                end if;
5485             end if;
5486          end Component_AlignmentP;
5487
5488          ----------------
5489          -- Controlled --
5490          ----------------
5491
5492          --  pragma Controlled (first_subtype_LOCAL_NAME);
5493
5494          when Pragma_Controlled => Controlled : declare
5495             Arg : Node_Id;
5496
5497          begin
5498             Check_No_Identifiers;
5499             Check_Arg_Count (1);
5500             Check_Arg_Is_Local_Name (Arg1);
5501             Arg := Expression (Arg1);
5502
5503             if not Is_Entity_Name (Arg)
5504               or else not Is_Access_Type (Entity (Arg))
5505             then
5506                Error_Pragma_Arg ("pragma% requires access type", Arg1);
5507             else
5508                Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
5509             end if;
5510          end Controlled;
5511
5512          ----------------
5513          -- Convention --
5514          ----------------
5515
5516          --  pragma Convention ([Convention =>] convention_IDENTIFIER,
5517          --    [Entity =>] LOCAL_NAME);
5518
5519          when Pragma_Convention => Convention : declare
5520             C : Convention_Id;
5521             E : Entity_Id;
5522             pragma Warnings (Off, C);
5523             pragma Warnings (Off, E);
5524          begin
5525             Check_Arg_Order ((Name_Convention, Name_Entity));
5526             Check_Ada_83_Warning;
5527             Check_Arg_Count (2);
5528             Process_Convention (C, E);
5529          end Convention;
5530
5531          ---------------------------
5532          -- Convention_Identifier --
5533          ---------------------------
5534
5535          --  pragma Convention_Identifier ([Name =>] IDENTIFIER,
5536          --    [Convention =>] convention_IDENTIFIER);
5537
5538          when Pragma_Convention_Identifier => Convention_Identifier : declare
5539             Idnam : Name_Id;
5540             Cname : Name_Id;
5541
5542          begin
5543             GNAT_Pragma;
5544             Check_Arg_Order ((Name_Name, Name_Convention));
5545             Check_Arg_Count (2);
5546             Check_Optional_Identifier (Arg1, Name_Name);
5547             Check_Optional_Identifier (Arg2, Name_Convention);
5548             Check_Arg_Is_Identifier (Arg1);
5549             Check_Arg_Is_Identifier (Arg2);
5550             Idnam := Chars (Expression (Arg1));
5551             Cname := Chars (Expression (Arg2));
5552
5553             if Is_Convention_Name (Cname) then
5554                Record_Convention_Identifier
5555                  (Idnam, Get_Convention_Id (Cname));
5556             else
5557                Error_Pragma_Arg
5558                  ("second arg for % pragma must be convention", Arg2);
5559             end if;
5560          end Convention_Identifier;
5561
5562          ---------------
5563          -- CPP_Class --
5564          ---------------
5565
5566          --  pragma CPP_Class ([Entity =>] local_NAME)
5567
5568          when Pragma_CPP_Class => CPP_Class : declare
5569             Arg : Node_Id;
5570             Typ : Entity_Id;
5571
5572          begin
5573             if Warn_On_Obsolescent_Feature then
5574                Error_Msg_N
5575                  ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
5576                   " by pragma import?", N);
5577             end if;
5578
5579             GNAT_Pragma;
5580             Check_Arg_Count (1);
5581             Check_Optional_Identifier (Arg1, Name_Entity);
5582             Check_Arg_Is_Local_Name (Arg1);
5583
5584             Arg := Expression (Arg1);
5585             Analyze (Arg);
5586
5587             if Etype (Arg) = Any_Type then
5588                return;
5589             end if;
5590
5591             if not Is_Entity_Name (Arg)
5592               or else not Is_Type (Entity (Arg))
5593             then
5594                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
5595             end if;
5596
5597             Typ := Entity (Arg);
5598
5599             if not Is_Tagged_Type (Typ) then
5600                Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
5601             end if;
5602
5603             --  Types treated as CPP classes are treated as limited, but we
5604             --  don't require them to be declared this way. A warning is issued
5605             --  to encourage the user to declare them as limited. This is not
5606             --  an error, for compatibility reasons, because these types have
5607             --  been supported this way for some time.
5608
5609             if not Is_Limited_Type (Typ) then
5610                Error_Msg_N
5611                  ("imported 'C'P'P type should be " &
5612                     "explicitly declared limited?",
5613                   Get_Pragma_Arg (Arg1));
5614                Error_Msg_N
5615                  ("\type will be considered limited",
5616                   Get_Pragma_Arg (Arg1));
5617             end if;
5618
5619             Set_Is_CPP_Class      (Typ);
5620             Set_Is_Limited_Record (Typ);
5621             Set_Convention        (Typ, Convention_CPP);
5622          end CPP_Class;
5623
5624          ---------------------
5625          -- CPP_Constructor --
5626          ---------------------
5627
5628          --  pragma CPP_Constructor ([Entity =>] LOCAL_NAME
5629          --    [, [External_Name =>] static_string_EXPRESSION ]
5630          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
5631
5632          when Pragma_CPP_Constructor => CPP_Constructor : declare
5633             Id     : Entity_Id;
5634             Def_Id : Entity_Id;
5635
5636          begin
5637             GNAT_Pragma;
5638             Check_At_Least_N_Arguments (1);
5639             Check_At_Most_N_Arguments (3);
5640             Check_Optional_Identifier (Arg1, Name_Entity);
5641             Check_Arg_Is_Local_Name (Arg1);
5642
5643             Id := Expression (Arg1);
5644             Find_Program_Unit_Name (Id);
5645
5646             --  If we did not find the name, we are done
5647
5648             if Etype (Id) = Any_Type then
5649                return;
5650             end if;
5651
5652             Def_Id := Entity (Id);
5653
5654             if Ekind (Def_Id) = E_Function
5655               and then Is_Class_Wide_Type (Etype (Def_Id))
5656               and then Is_CPP_Class (Etype (Etype (Def_Id)))
5657             then
5658                if Arg_Count >= 2 then
5659                   Set_Imported (Def_Id);
5660                   Set_Is_Public (Def_Id);
5661                   Process_Interface_Name (Def_Id, Arg2, Arg3);
5662                end if;
5663
5664                if No (Parameter_Specifications (Parent (Def_Id))) then
5665                   Set_Has_Completion (Def_Id);
5666                   Set_Is_Constructor (Def_Id);
5667                else
5668                   Error_Pragma_Arg
5669                     ("non-default constructors not implemented", Arg1);
5670                end if;
5671
5672             else
5673                Error_Pragma_Arg
5674                  ("pragma% requires function returning a 'C'P'P_Class type",
5675                    Arg1);
5676             end if;
5677          end CPP_Constructor;
5678
5679          -----------------
5680          -- CPP_Virtual --
5681          -----------------
5682
5683          when Pragma_CPP_Virtual => CPP_Virtual : declare
5684          begin
5685             if Warn_On_Obsolescent_Feature then
5686                Error_Msg_N
5687                  ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
5688                   "no effect?", N);
5689             end if;
5690          end CPP_Virtual;
5691
5692          ----------------
5693          -- CPP_Vtable --
5694          ----------------
5695
5696          when Pragma_CPP_Vtable => CPP_Vtable : declare
5697          begin
5698             if Warn_On_Obsolescent_Feature then
5699                Error_Msg_N
5700                  ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
5701                   "no effect?", N);
5702             end if;
5703          end CPP_Vtable;
5704
5705          -----------
5706          -- Debug --
5707          -----------
5708
5709          --  pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
5710
5711          when Pragma_Debug => Debug : declare
5712                Cond : Node_Id;
5713
5714          begin
5715             GNAT_Pragma;
5716
5717             Cond :=
5718               New_Occurrence_Of
5719                 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
5720                  Loc);
5721
5722             if Arg_Count = 2 then
5723                Cond :=
5724                  Make_And_Then (Loc,
5725                    Left_Opnd   => Relocate_Node (Cond),
5726                    Right_Opnd  => Expression (Arg1));
5727             end if;
5728
5729             --  Rewrite into a conditional with an appropriate condition. We
5730             --  wrap the procedure call in a block so that overhead from e.g.
5731             --  use of the secondary stack does not generate execution overhead
5732             --  for suppressed conditions.
5733
5734             Rewrite (N, Make_Implicit_If_Statement (N,
5735               Condition => Cond,
5736                  Then_Statements => New_List (
5737                    Make_Block_Statement (Loc,
5738                      Handled_Statement_Sequence =>
5739                        Make_Handled_Sequence_Of_Statements (Loc,
5740                          Statements => New_List (
5741                            Relocate_Node (Debug_Statement (N))))))));
5742             Analyze (N);
5743          end Debug;
5744
5745          ------------------
5746          -- Debug_Policy --
5747          ------------------
5748
5749          --  pragma Debug_Policy (Check | Ignore)
5750
5751          when Pragma_Debug_Policy =>
5752             GNAT_Pragma;
5753             Check_Arg_Count (1);
5754             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5755             Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
5756
5757          ---------------------
5758          -- Detect_Blocking --
5759          ---------------------
5760
5761          --  pragma Detect_Blocking;
5762
5763          when Pragma_Detect_Blocking =>
5764             Ada_2005_Pragma;
5765             Check_Arg_Count (0);
5766             Check_Valid_Configuration_Pragma;
5767             Detect_Blocking := True;
5768
5769          -------------------
5770          -- Discard_Names --
5771          -------------------
5772
5773          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
5774
5775          when Pragma_Discard_Names => Discard_Names : declare
5776             E_Id : Entity_Id;
5777             E    : Entity_Id;
5778
5779          begin
5780             Check_Ada_83_Warning;
5781
5782             --  Deal with configuration pragma case
5783
5784             if Arg_Count = 0 and then Is_Configuration_Pragma then
5785                Global_Discard_Names := True;
5786                return;
5787
5788             --  Otherwise, check correct appropriate context
5789
5790             else
5791                Check_Is_In_Decl_Part_Or_Package_Spec;
5792
5793                if Arg_Count = 0 then
5794
5795                   --  If there is no parameter, then from now on this pragma
5796                   --  applies to any enumeration, exception or tagged type
5797                   --  defined in the current declarative part, and recursively
5798                   --  to any nested scope.
5799
5800                   Set_Discard_Names (Current_Scope);
5801                   return;
5802
5803                else
5804                   Check_Arg_Count (1);
5805                   Check_Optional_Identifier (Arg1, Name_On);
5806                   Check_Arg_Is_Local_Name (Arg1);
5807                   E_Id := Expression (Arg1);
5808
5809                   if Etype (E_Id) = Any_Type then
5810                      return;
5811                   else
5812                      E := Entity (E_Id);
5813                   end if;
5814
5815                   if (Is_First_Subtype (E)
5816                        and then (Is_Enumeration_Type (E)
5817                                   or else Is_Tagged_Type (E)))
5818                     or else Ekind (E) = E_Exception
5819                   then
5820                      Set_Discard_Names (E);
5821                   else
5822                      Error_Pragma_Arg
5823                        ("inappropriate entity for pragma%", Arg1);
5824                   end if;
5825                end if;
5826             end if;
5827          end Discard_Names;
5828
5829          ---------------
5830          -- Elaborate --
5831          ---------------
5832
5833          --  pragma Elaborate (library_unit_NAME {, library_unit_NAME});
5834
5835          when Pragma_Elaborate => Elaborate : declare
5836             Arg   : Node_Id;
5837             Citem : Node_Id;
5838
5839          begin
5840             --  Pragma must be in context items list of a compilation unit
5841
5842             if not Is_In_Context_Clause then
5843                Pragma_Misplaced;
5844             end if;
5845
5846             --  Must be at least one argument
5847
5848             if Arg_Count = 0 then
5849                Error_Pragma ("pragma% requires at least one argument");
5850             end if;
5851
5852             --  In Ada 83 mode, there can be no items following it in the
5853             --  context list except other pragmas and implicit with clauses
5854             --  (e.g. those added by use of Rtsfind). In Ada 95 mode, this
5855             --  placement rule does not apply.
5856
5857             if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5858                Citem := Next (N);
5859                while Present (Citem) loop
5860                   if Nkind (Citem) = N_Pragma
5861                     or else (Nkind (Citem) = N_With_Clause
5862                               and then Implicit_With (Citem))
5863                   then
5864                      null;
5865                   else
5866                      Error_Pragma
5867                        ("(Ada 83) pragma% must be at end of context clause");
5868                   end if;
5869
5870                   Next (Citem);
5871                end loop;
5872             end if;
5873
5874             --  Finally, the arguments must all be units mentioned in a with
5875             --  clause in the same context clause. Note we already checked (in
5876             --  Par.Prag) that the arguments are all identifiers or selected
5877             --  components.
5878
5879             Arg := Arg1;
5880             Outer : while Present (Arg) loop
5881                Citem := First (List_Containing (N));
5882                Inner : while Citem /= N loop
5883                   if Nkind (Citem) = N_With_Clause
5884                     and then Same_Name (Name (Citem), Expression (Arg))
5885                   then
5886                      Set_Elaborate_Present (Citem, True);
5887                      Set_Unit_Name (Expression (Arg), Name (Citem));
5888
5889                      --  With the pragma present, elaboration calls on
5890                      --  subprograms from the named unit need no further
5891                      --  checks, as long as the pragma appears in the current
5892                      --  compilation unit. If the pragma appears in some unit
5893                      --  in the context, there might still be a need for an
5894                      --  Elaborate_All_Desirable from the current compilation
5895                      --  to the the named unit, so we keep the check enabled.
5896
5897                      if In_Extended_Main_Source_Unit (N) then
5898                         Set_Suppress_Elaboration_Warnings
5899                           (Entity (Name (Citem)));
5900                      end if;
5901
5902                      exit Inner;
5903                   end if;
5904
5905                   Next (Citem);
5906                end loop Inner;
5907
5908                if Citem = N then
5909                   Error_Pragma_Arg
5910                     ("argument of pragma% is not with'ed unit", Arg);
5911                end if;
5912
5913                Next (Arg);
5914             end loop Outer;
5915
5916             --  Give a warning if operating in static mode with -gnatwl
5917             --  (elaboration warnings eanbled) switch set.
5918
5919             if Elab_Warnings and not Dynamic_Elaboration_Checks then
5920                Error_Msg_N
5921                  ("?use of pragma Elaborate may not be safe", N);
5922                Error_Msg_N
5923                  ("?use pragma Elaborate_All instead if possible", N);
5924             end if;
5925          end Elaborate;
5926
5927          -------------------
5928          -- Elaborate_All --
5929          -------------------
5930
5931          --  pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
5932
5933          when Pragma_Elaborate_All => Elaborate_All : declare
5934             Arg   : Node_Id;
5935             Citem : Node_Id;
5936
5937          begin
5938             Check_Ada_83_Warning;
5939
5940             --  Pragma must be in context items list of a compilation unit
5941
5942             if not Is_In_Context_Clause then
5943                Pragma_Misplaced;
5944             end if;
5945
5946             --  Must be at least one argument
5947
5948             if Arg_Count = 0 then
5949                Error_Pragma ("pragma% requires at least one argument");
5950             end if;
5951
5952             --  Note: unlike pragma Elaborate, pragma Elaborate_All does not
5953             --  have to appear at the end of the context clause, but may
5954             --  appear mixed in with other items, even in Ada 83 mode.
5955
5956             --  Final check: the arguments must all be units mentioned in
5957             --  a with clause in the same context clause. Note that we
5958             --  already checked (in Par.Prag) that all the arguments are
5959             --  either identifiers or selected components.
5960
5961             Arg := Arg1;
5962             Outr : while Present (Arg) loop
5963                Citem := First (List_Containing (N));
5964                Innr : while Citem /= N loop
5965                   if Nkind (Citem) = N_With_Clause
5966                     and then Same_Name (Name (Citem), Expression (Arg))
5967                   then
5968                      Set_Elaborate_All_Present (Citem, True);
5969                      Set_Unit_Name (Expression (Arg), Name (Citem));
5970
5971                      --  Suppress warnings and elaboration checks on the named
5972                      --  unit if the pragma is in the current compilation, as
5973                      --  for pragma Elaborate.
5974
5975                      if In_Extended_Main_Source_Unit (N) then
5976                         Set_Suppress_Elaboration_Warnings
5977                           (Entity (Name (Citem)));
5978                      end if;
5979                      exit Innr;
5980                   end if;
5981
5982                   Next (Citem);
5983                end loop Innr;
5984
5985                if Citem = N then
5986                   Set_Error_Posted (N);
5987                   Error_Pragma_Arg
5988                     ("argument of pragma% is not with'ed unit", Arg);
5989                end if;
5990
5991                Next (Arg);
5992             end loop Outr;
5993          end Elaborate_All;
5994
5995          --------------------
5996          -- Elaborate_Body --
5997          --------------------
5998
5999          --  pragma Elaborate_Body [( library_unit_NAME )];
6000
6001          when Pragma_Elaborate_Body => Elaborate_Body : declare
6002             Cunit_Node : Node_Id;
6003             Cunit_Ent  : Entity_Id;
6004
6005          begin
6006             Check_Ada_83_Warning;
6007             Check_Valid_Library_Unit_Pragma;
6008
6009             if Nkind (N) = N_Null_Statement then
6010                return;
6011             end if;
6012
6013             Cunit_Node := Cunit (Current_Sem_Unit);
6014             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
6015
6016             if Nkind (Unit (Cunit_Node)) = N_Package_Body
6017                  or else
6018                Nkind (Unit (Cunit_Node)) = N_Subprogram_Body
6019             then
6020                Error_Pragma ("pragma% must refer to a spec, not a body");
6021             else
6022                Set_Body_Required (Cunit_Node, True);
6023                Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
6024
6025                --  If we are in dynamic elaboration mode, then we suppress
6026                --  elaboration warnings for the unit, since it is definitely
6027                --  fine NOT to do dynamic checks at the first level (and such
6028                --  checks will be suppressed because no elaboration boolean
6029                --  is created for Elaborate_Body packages).
6030
6031                --  But in the static model of elaboration, Elaborate_Body is
6032                --  definitely NOT good enough to ensure elaboration safety on
6033                --  its own, since the body may WITH other units that are not
6034                --  safe from an elaboration point of view, so a client must
6035                --  still do an Elaborate_All on such units.
6036
6037                --  Debug flag -gnatdD restores the old behavior of 3.13,
6038                --  where Elaborate_Body always suppressed elab warnings.
6039
6040                if Dynamic_Elaboration_Checks or Debug_Flag_DD then
6041                   Set_Suppress_Elaboration_Warnings (Cunit_Ent);
6042                end if;
6043             end if;
6044          end Elaborate_Body;
6045
6046          ------------------------
6047          -- Elaboration_Checks --
6048          ------------------------
6049
6050          --  pragma Elaboration_Checks (Static | Dynamic);
6051
6052          when Pragma_Elaboration_Checks =>
6053             GNAT_Pragma;
6054             Check_Arg_Count (1);
6055             Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
6056             Dynamic_Elaboration_Checks :=
6057               (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
6058
6059          ---------------
6060          -- Eliminate --
6061          ---------------
6062
6063          --  pragma Eliminate (
6064          --      [Unit_Name       =>]  IDENTIFIER |
6065          --                            SELECTED_COMPONENT
6066          --    [,[Entity          =>]  IDENTIFIER |
6067          --                            SELECTED_COMPONENT |
6068          --                            STRING_LITERAL]
6069          --    [,]OVERLOADING_RESOLUTION);
6070
6071          --  OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
6072          --                             SOURCE_LOCATION
6073
6074          --  PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
6075          --                                        FUNCTION_PROFILE
6076
6077          --  PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
6078
6079          --  FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
6080          --                       Result_Type => result_SUBTYPE_NAME]
6081
6082          --  PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
6083          --  SUBTYPE_NAME    ::= STRING_LITERAL
6084
6085          --  SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
6086          --  SOURCE_TRACE    ::= STRING_LITERAL
6087
6088          when Pragma_Eliminate => Eliminate : declare
6089             Args  : Args_List (1 .. 5);
6090             Names : constant Name_List (1 .. 5) := (
6091                       Name_Unit_Name,
6092                       Name_Entity,
6093                       Name_Parameter_Types,
6094                       Name_Result_Type,
6095                       Name_Source_Location);
6096
6097             Unit_Name       : Node_Id renames Args (1);
6098             Entity          : Node_Id renames Args (2);
6099             Parameter_Types : Node_Id renames Args (3);
6100             Result_Type     : Node_Id renames Args (4);
6101             Source_Location : Node_Id renames Args (5);
6102
6103          begin
6104             GNAT_Pragma;
6105             Check_Valid_Configuration_Pragma;
6106             Gather_Associations (Names, Args);
6107
6108             if No (Unit_Name) then
6109                Error_Pragma ("missing Unit_Name argument for pragma%");
6110             end if;
6111
6112             if No (Entity)
6113               and then (Present (Parameter_Types)
6114                           or else
6115                         Present (Result_Type)
6116                           or else
6117                         Present (Source_Location))
6118             then
6119                Error_Pragma ("missing Entity argument for pragma%");
6120             end if;
6121
6122             if (Present (Parameter_Types)
6123                        or else
6124                 Present (Result_Type))
6125               and then
6126                 Present (Source_Location)
6127             then
6128                Error_Pragma
6129                  ("parameter profile and source location cannot " &
6130                   "be used together in pragma%");
6131             end if;
6132
6133             Process_Eliminate_Pragma
6134               (N,
6135                Unit_Name,
6136                Entity,
6137                Parameter_Types,
6138                Result_Type,
6139                Source_Location);
6140          end Eliminate;
6141
6142          ------------
6143          -- Export --
6144          ------------
6145
6146          --  pragma Export (
6147          --    [   Convention    =>] convention_IDENTIFIER,
6148          --    [   Entity        =>] local_NAME
6149          --    [, [External_Name =>] static_string_EXPRESSION ]
6150          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
6151
6152          when Pragma_Export => Export : declare
6153             C      : Convention_Id;
6154             Def_Id : Entity_Id;
6155
6156             pragma Warnings (Off, C);
6157
6158          begin
6159             Check_Ada_83_Warning;
6160             Check_Arg_Order
6161               ((Name_Convention,
6162                 Name_Entity,
6163                 Name_External_Name,
6164                 Name_Link_Name));
6165             Check_At_Least_N_Arguments (2);
6166             Check_At_Most_N_Arguments  (4);
6167             Process_Convention (C, Def_Id);
6168
6169             if Ekind (Def_Id) /= E_Constant then
6170                Note_Possible_Modification (Expression (Arg2));
6171             end if;
6172
6173             Process_Interface_Name (Def_Id, Arg3, Arg4);
6174             Set_Exported (Def_Id, Arg2);
6175          end Export;
6176
6177          ----------------------
6178          -- Export_Exception --
6179          ----------------------
6180
6181          --  pragma Export_Exception (
6182          --        [Internal         =>] LOCAL_NAME,
6183          --     [, [External         =>] EXTERNAL_SYMBOL,]
6184          --     [, [Form     =>] Ada | VMS]
6185          --     [, [Code     =>] static_integer_EXPRESSION]);
6186
6187          when Pragma_Export_Exception => Export_Exception : declare
6188             Args  : Args_List (1 .. 4);
6189             Names : constant Name_List (1 .. 4) := (
6190                       Name_Internal,
6191                       Name_External,
6192                       Name_Form,
6193                       Name_Code);
6194
6195             Internal : Node_Id renames Args (1);
6196             External : Node_Id renames Args (2);
6197             Form     : Node_Id renames Args (3);
6198             Code     : Node_Id renames Args (4);
6199
6200          begin
6201             if Inside_A_Generic then
6202                Error_Pragma ("pragma% cannot be used for generic entities");
6203             end if;
6204
6205             Gather_Associations (Names, Args);
6206             Process_Extended_Import_Export_Exception_Pragma (
6207               Arg_Internal => Internal,
6208               Arg_External => External,
6209               Arg_Form     => Form,
6210               Arg_Code     => Code);
6211
6212             if not Is_VMS_Exception (Entity (Internal)) then
6213                Set_Exported (Entity (Internal), Internal);
6214             end if;
6215          end Export_Exception;
6216
6217          ---------------------
6218          -- Export_Function --
6219          ---------------------
6220
6221          --  pragma Export_Function (
6222          --        [Internal         =>] LOCAL_NAME,
6223          --     [, [External         =>] EXTERNAL_SYMBOL,]
6224          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
6225          --     [, [Result_Type      =>] TYPE_DESIGNATOR]
6226          --     [, [Mechanism        =>] MECHANISM]
6227          --     [, [Result_Mechanism =>] MECHANISM_NAME]);
6228
6229          --  EXTERNAL_SYMBOL ::=
6230          --    IDENTIFIER
6231          --  | static_string_EXPRESSION
6232
6233          --  PARAMETER_TYPES ::=
6234          --    null
6235          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6236
6237          --  TYPE_DESIGNATOR ::=
6238          --    subtype_NAME
6239          --  | subtype_Name ' Access
6240
6241          --  MECHANISM ::=
6242          --    MECHANISM_NAME
6243          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6244
6245          --  MECHANISM_ASSOCIATION ::=
6246          --    [formal_parameter_NAME =>] MECHANISM_NAME
6247
6248          --  MECHANISM_NAME ::=
6249          --    Value
6250          --  | Reference
6251          --  | Descriptor [([Class =>] CLASS_NAME)]
6252
6253          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6254
6255          when Pragma_Export_Function => Export_Function : declare
6256             Args  : Args_List (1 .. 6);
6257             Names : constant Name_List (1 .. 6) := (
6258                       Name_Internal,
6259                       Name_External,
6260                       Name_Parameter_Types,
6261                       Name_Result_Type,
6262                       Name_Mechanism,
6263                       Name_Result_Mechanism);
6264
6265             Internal         : Node_Id renames Args (1);
6266             External         : Node_Id renames Args (2);
6267             Parameter_Types  : Node_Id renames Args (3);
6268             Result_Type      : Node_Id renames Args (4);
6269             Mechanism        : Node_Id renames Args (5);
6270             Result_Mechanism : Node_Id renames Args (6);
6271
6272          begin
6273             GNAT_Pragma;
6274             Gather_Associations (Names, Args);
6275             Process_Extended_Import_Export_Subprogram_Pragma (
6276               Arg_Internal         => Internal,
6277               Arg_External         => External,
6278               Arg_Parameter_Types  => Parameter_Types,
6279               Arg_Result_Type      => Result_Type,
6280               Arg_Mechanism        => Mechanism,
6281               Arg_Result_Mechanism => Result_Mechanism);
6282          end Export_Function;
6283
6284          -------------------
6285          -- Export_Object --
6286          -------------------
6287
6288          --  pragma Export_Object (
6289          --        [Internal =>] LOCAL_NAME,
6290          --     [, [External =>] EXTERNAL_SYMBOL]
6291          --     [, [Size     =>] EXTERNAL_SYMBOL]);
6292
6293          --  EXTERNAL_SYMBOL ::=
6294          --    IDENTIFIER
6295          --  | static_string_EXPRESSION
6296
6297          --  PARAMETER_TYPES ::=
6298          --    null
6299          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6300
6301          --  TYPE_DESIGNATOR ::=
6302          --    subtype_NAME
6303          --  | subtype_Name ' Access
6304
6305          --  MECHANISM ::=
6306          --    MECHANISM_NAME
6307          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6308
6309          --  MECHANISM_ASSOCIATION ::=
6310          --    [formal_parameter_NAME =>] MECHANISM_NAME
6311
6312          --  MECHANISM_NAME ::=
6313          --    Value
6314          --  | Reference
6315          --  | Descriptor [([Class =>] CLASS_NAME)]
6316
6317          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6318
6319          when Pragma_Export_Object => Export_Object : declare
6320             Args  : Args_List (1 .. 3);
6321             Names : constant Name_List (1 .. 3) := (
6322                       Name_Internal,
6323                       Name_External,
6324                       Name_Size);
6325
6326             Internal : Node_Id renames Args (1);
6327             External : Node_Id renames Args (2);
6328             Size     : Node_Id renames Args (3);
6329
6330          begin
6331             GNAT_Pragma;
6332             Gather_Associations (Names, Args);
6333             Process_Extended_Import_Export_Object_Pragma (
6334               Arg_Internal => Internal,
6335               Arg_External => External,
6336               Arg_Size     => Size);
6337          end Export_Object;
6338
6339          ----------------------
6340          -- Export_Procedure --
6341          ----------------------
6342
6343          --  pragma Export_Procedure (
6344          --        [Internal         =>] LOCAL_NAME,
6345          --     [, [External         =>] EXTERNAL_SYMBOL,]
6346          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
6347          --     [, [Mechanism        =>] MECHANISM]);
6348
6349          --  EXTERNAL_SYMBOL ::=
6350          --    IDENTIFIER
6351          --  | static_string_EXPRESSION
6352
6353          --  PARAMETER_TYPES ::=
6354          --    null
6355          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6356
6357          --  TYPE_DESIGNATOR ::=
6358          --    subtype_NAME
6359          --  | subtype_Name ' Access
6360
6361          --  MECHANISM ::=
6362          --    MECHANISM_NAME
6363          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6364
6365          --  MECHANISM_ASSOCIATION ::=
6366          --    [formal_parameter_NAME =>] MECHANISM_NAME
6367
6368          --  MECHANISM_NAME ::=
6369          --    Value
6370          --  | Reference
6371          --  | Descriptor [([Class =>] CLASS_NAME)]
6372
6373          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6374
6375          when Pragma_Export_Procedure => Export_Procedure : declare
6376             Args  : Args_List (1 .. 4);
6377             Names : constant Name_List (1 .. 4) := (
6378                       Name_Internal,
6379                       Name_External,
6380                       Name_Parameter_Types,
6381                       Name_Mechanism);
6382
6383             Internal        : Node_Id renames Args (1);
6384             External        : Node_Id renames Args (2);
6385             Parameter_Types : Node_Id renames Args (3);
6386             Mechanism       : Node_Id renames Args (4);
6387
6388          begin
6389             GNAT_Pragma;
6390             Gather_Associations (Names, Args);
6391             Process_Extended_Import_Export_Subprogram_Pragma (
6392               Arg_Internal        => Internal,
6393               Arg_External        => External,
6394               Arg_Parameter_Types => Parameter_Types,
6395               Arg_Mechanism       => Mechanism);
6396          end Export_Procedure;
6397
6398          ------------------
6399          -- Export_Value --
6400          ------------------
6401
6402          --  pragma Export_Value (
6403          --     [Value     =>] static_integer_EXPRESSION,
6404          --     [Link_Name =>] static_string_EXPRESSION);
6405
6406          when Pragma_Export_Value =>
6407             GNAT_Pragma;
6408             Check_Arg_Order ((Name_Value, Name_Link_Name));
6409             Check_Arg_Count (2);
6410
6411             Check_Optional_Identifier (Arg1, Name_Value);
6412             Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
6413
6414             Check_Optional_Identifier (Arg2, Name_Link_Name);
6415             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6416
6417          -----------------------------
6418          -- Export_Valued_Procedure --
6419          -----------------------------
6420
6421          --  pragma Export_Valued_Procedure (
6422          --        [Internal         =>] LOCAL_NAME,
6423          --     [, [External         =>] EXTERNAL_SYMBOL,]
6424          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
6425          --     [, [Mechanism        =>] MECHANISM]);
6426
6427          --  EXTERNAL_SYMBOL ::=
6428          --    IDENTIFIER
6429          --  | static_string_EXPRESSION
6430
6431          --  PARAMETER_TYPES ::=
6432          --    null
6433          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6434
6435          --  TYPE_DESIGNATOR ::=
6436          --    subtype_NAME
6437          --  | subtype_Name ' Access
6438
6439          --  MECHANISM ::=
6440          --    MECHANISM_NAME
6441          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6442
6443          --  MECHANISM_ASSOCIATION ::=
6444          --    [formal_parameter_NAME =>] MECHANISM_NAME
6445
6446          --  MECHANISM_NAME ::=
6447          --    Value
6448          --  | Reference
6449          --  | Descriptor [([Class =>] CLASS_NAME)]
6450
6451          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6452
6453          when Pragma_Export_Valued_Procedure =>
6454          Export_Valued_Procedure : declare
6455             Args  : Args_List (1 .. 4);
6456             Names : constant Name_List (1 .. 4) := (
6457                       Name_Internal,
6458                       Name_External,
6459                       Name_Parameter_Types,
6460                       Name_Mechanism);
6461
6462             Internal        : Node_Id renames Args (1);
6463             External        : Node_Id renames Args (2);
6464             Parameter_Types : Node_Id renames Args (3);
6465             Mechanism       : Node_Id renames Args (4);
6466
6467          begin
6468             GNAT_Pragma;
6469             Gather_Associations (Names, Args);
6470             Process_Extended_Import_Export_Subprogram_Pragma (
6471               Arg_Internal        => Internal,
6472               Arg_External        => External,
6473               Arg_Parameter_Types => Parameter_Types,
6474               Arg_Mechanism       => Mechanism);
6475          end Export_Valued_Procedure;
6476
6477          -------------------
6478          -- Extend_System --
6479          -------------------
6480
6481          --  pragma Extend_System ([Name =>] Identifier);
6482
6483          when Pragma_Extend_System => Extend_System : declare
6484          begin
6485             GNAT_Pragma;
6486             Check_Valid_Configuration_Pragma;
6487             Check_Arg_Count (1);
6488             Check_Optional_Identifier (Arg1, Name_Name);
6489             Check_Arg_Is_Identifier (Arg1);
6490
6491             Get_Name_String (Chars (Expression (Arg1)));
6492
6493             if Name_Len > 4
6494               and then Name_Buffer (1 .. 4) = "aux_"
6495             then
6496                if Present (System_Extend_Pragma_Arg) then
6497                   if Chars (Expression (Arg1)) =
6498                      Chars (Expression (System_Extend_Pragma_Arg))
6499                   then
6500                      null;
6501                   else
6502                      Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
6503                      Error_Pragma ("pragma% conflicts with that #");
6504                   end if;
6505
6506                else
6507                   System_Extend_Pragma_Arg := Arg1;
6508
6509                   if not GNAT_Mode then
6510                      System_Extend_Unit := Arg1;
6511                   end if;
6512                end if;
6513             else
6514                Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
6515             end if;
6516          end Extend_System;
6517
6518          ------------------------
6519          -- Extensions_Allowed --
6520          ------------------------
6521
6522          --  pragma Extensions_Allowed (ON | OFF);
6523
6524          when Pragma_Extensions_Allowed =>
6525             GNAT_Pragma;
6526             Check_Arg_Count (1);
6527             Check_No_Identifiers;
6528             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6529
6530             if Chars (Expression (Arg1)) = Name_On then
6531                Extensions_Allowed := True;
6532             else
6533                Extensions_Allowed := False;
6534             end if;
6535
6536          --------------
6537          -- External --
6538          --------------
6539
6540          --  pragma External (
6541          --    [   Convention    =>] convention_IDENTIFIER,
6542          --    [   Entity        =>] local_NAME
6543          --    [, [External_Name =>] static_string_EXPRESSION ]
6544          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
6545
6546          when Pragma_External => External : declare
6547                Def_Id : Entity_Id;
6548
6549                C : Convention_Id;
6550                pragma Warnings (Off, C);
6551
6552          begin
6553             GNAT_Pragma;
6554             Check_Arg_Order
6555               ((Name_Convention,
6556                 Name_Entity,
6557                 Name_External_Name,
6558                 Name_Link_Name));
6559             Check_At_Least_N_Arguments (2);
6560             Check_At_Most_N_Arguments  (4);
6561             Process_Convention (C, Def_Id);
6562             Note_Possible_Modification (Expression (Arg2));
6563             Process_Interface_Name (Def_Id, Arg3, Arg4);
6564             Set_Exported (Def_Id, Arg2);
6565          end External;
6566
6567          --------------------------
6568          -- External_Name_Casing --
6569          --------------------------
6570
6571          --  pragma External_Name_Casing (
6572          --    UPPERCASE | LOWERCASE
6573          --    [, AS_IS | UPPERCASE | LOWERCASE]);
6574
6575          when Pragma_External_Name_Casing => External_Name_Casing : declare
6576          begin
6577             GNAT_Pragma;
6578             Check_No_Identifiers;
6579
6580             if Arg_Count = 2 then
6581                Check_Arg_Is_One_Of
6582                  (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
6583
6584                case Chars (Get_Pragma_Arg (Arg2)) is
6585                   when Name_As_Is     =>
6586                      Opt.External_Name_Exp_Casing := As_Is;
6587
6588                   when Name_Uppercase =>
6589                      Opt.External_Name_Exp_Casing := Uppercase;
6590
6591                   when Name_Lowercase =>
6592                      Opt.External_Name_Exp_Casing := Lowercase;
6593
6594                   when others =>
6595                      null;
6596                end case;
6597
6598             else
6599                Check_Arg_Count (1);
6600             end if;
6601
6602             Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
6603
6604             case Chars (Get_Pragma_Arg (Arg1)) is
6605                when Name_Uppercase =>
6606                   Opt.External_Name_Imp_Casing := Uppercase;
6607
6608                when Name_Lowercase =>
6609                   Opt.External_Name_Imp_Casing := Lowercase;
6610
6611                when others =>
6612                   null;
6613             end case;
6614          end External_Name_Casing;
6615
6616          ---------------------------
6617          -- Finalize_Storage_Only --
6618          ---------------------------
6619
6620          --  pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
6621
6622          when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
6623             Assoc   : constant Node_Id := Arg1;
6624             Type_Id : constant Node_Id := Expression (Assoc);
6625             Typ     : Entity_Id;
6626
6627          begin
6628             Check_No_Identifiers;
6629             Check_Arg_Count (1);
6630             Check_Arg_Is_Local_Name (Arg1);
6631
6632             Find_Type (Type_Id);
6633             Typ := Entity (Type_Id);
6634
6635             if Typ = Any_Type
6636               or else Rep_Item_Too_Early (Typ, N)
6637             then
6638                return;
6639             else
6640                Typ := Underlying_Type (Typ);
6641             end if;
6642
6643             if not Is_Controlled (Typ) then
6644                Error_Pragma ("pragma% must specify controlled type");
6645             end if;
6646
6647             Check_First_Subtype (Arg1);
6648
6649             if Finalize_Storage_Only (Typ) then
6650                Error_Pragma ("duplicate pragma%, only one allowed");
6651
6652             elsif not Rep_Item_Too_Late (Typ, N) then
6653                Set_Finalize_Storage_Only (Base_Type (Typ), True);
6654             end if;
6655          end Finalize_Storage;
6656
6657          --------------------------
6658          -- Float_Representation --
6659          --------------------------
6660
6661          --  pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
6662
6663          --  FLOAT_REP ::= VAX_Float | IEEE_Float
6664
6665          when Pragma_Float_Representation => Float_Representation : declare
6666             Argx : Node_Id;
6667             Digs : Nat;
6668             Ent  : Entity_Id;
6669
6670          begin
6671             GNAT_Pragma;
6672
6673             if Arg_Count = 1 then
6674                Check_Valid_Configuration_Pragma;
6675             else
6676                Check_Arg_Count (2);
6677                Check_Optional_Identifier (Arg2, Name_Entity);
6678                Check_Arg_Is_Local_Name (Arg2);
6679             end if;
6680
6681             Check_No_Identifier (Arg1);
6682             Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
6683
6684             if not OpenVMS_On_Target then
6685                if Chars (Expression (Arg1)) = Name_VAX_Float then
6686                   Error_Pragma
6687                     ("?pragma% ignored (applies only to Open'V'M'S)");
6688                end if;
6689
6690                return;
6691             end if;
6692
6693             --  One argument case
6694
6695             if Arg_Count = 1 then
6696                if Chars (Expression (Arg1)) = Name_VAX_Float then
6697                   if Opt.Float_Format = 'I' then
6698                      Error_Pragma ("'I'E'E'E format previously specified");
6699                   end if;
6700
6701                   Opt.Float_Format := 'V';
6702
6703                else
6704                   if Opt.Float_Format = 'V' then
6705                      Error_Pragma ("'V'A'X format previously specified");
6706                   end if;
6707
6708                   Opt.Float_Format := 'I';
6709                end if;
6710
6711                Set_Standard_Fpt_Formats;
6712
6713             --  Two argument case
6714
6715             else
6716                Argx := Get_Pragma_Arg (Arg2);
6717
6718                if not Is_Entity_Name (Argx)
6719                  or else not Is_Floating_Point_Type (Entity (Argx))
6720                then
6721                   Error_Pragma_Arg
6722                     ("second argument of% pragma must be floating-point type",
6723                      Arg2);
6724                end if;
6725
6726                Ent  := Entity (Argx);
6727                Digs := UI_To_Int (Digits_Value (Ent));
6728
6729                --  Two arguments, VAX_Float case
6730
6731                if Chars (Expression (Arg1)) = Name_VAX_Float then
6732                   case Digs is
6733                      when  6 => Set_F_Float (Ent);
6734                      when  9 => Set_D_Float (Ent);
6735                      when 15 => Set_G_Float (Ent);
6736
6737                      when others =>
6738                         Error_Pragma_Arg
6739                           ("wrong digits value, must be 6,9 or 15", Arg2);
6740                   end case;
6741
6742                --  Two arguments, IEEE_Float case
6743
6744                else
6745                   case Digs is
6746                      when  6 => Set_IEEE_Short (Ent);
6747                      when 15 => Set_IEEE_Long  (Ent);
6748
6749                      when others =>
6750                         Error_Pragma_Arg
6751                           ("wrong digits value, must be 6 or 15", Arg2);
6752                   end case;
6753                end if;
6754             end if;
6755          end Float_Representation;
6756
6757          -----------
6758          -- Ident --
6759          -----------
6760
6761          --  pragma Ident (static_string_EXPRESSION)
6762
6763          --  Note: pragma Comment shares this processing. Pragma Comment
6764          --  is identical to Ident, except that the restriction of the
6765          --  argument to 31 characters and the placement restrictions
6766          --  are not enforced for pragma Comment.
6767
6768          when Pragma_Ident | Pragma_Comment => Ident : declare
6769             Str : Node_Id;
6770
6771          begin
6772             GNAT_Pragma;
6773             Check_Arg_Count (1);
6774             Check_No_Identifiers;
6775             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
6776
6777             --  For pragma Ident, preserve DEC compatibility by requiring
6778             --  the pragma to appear in a declarative part or package spec.
6779
6780             if Prag_Id = Pragma_Ident then
6781                Check_Is_In_Decl_Part_Or_Package_Spec;
6782             end if;
6783
6784             Str := Expr_Value_S (Expression (Arg1));
6785
6786             declare
6787                CS : Node_Id;
6788                GP : Node_Id;
6789
6790             begin
6791                GP := Parent (Parent (N));
6792
6793                if Nkind (GP) = N_Package_Declaration
6794                     or else
6795                   Nkind (GP) = N_Generic_Package_Declaration
6796                then
6797                   GP := Parent (GP);
6798                end if;
6799
6800                --  If we have a compilation unit, then record the ident
6801                --  value, checking for improper duplication.
6802
6803                if Nkind (GP) = N_Compilation_Unit then
6804                   CS := Ident_String (Current_Sem_Unit);
6805
6806                   if Present (CS) then
6807
6808                      --  For Ident, we do not permit multiple instances
6809
6810                      if Prag_Id = Pragma_Ident then
6811                         Error_Pragma ("duplicate% pragma not permitted");
6812
6813                      --  For Comment, we concatenate the string, unless we
6814                      --  want to preserve the tree structure for ASIS.
6815
6816                      elsif not ASIS_Mode then
6817                         Start_String (Strval (CS));
6818                         Store_String_Char (' ');
6819                         Store_String_Chars (Strval (Str));
6820                         Set_Strval (CS, End_String);
6821                      end if;
6822
6823                   else
6824                      --  In VMS, the effect of IDENT is achieved by passing
6825                      --  IDENTIFICATION=name as a --for-linker switch.
6826
6827                      if OpenVMS_On_Target then
6828                         Start_String;
6829                         Store_String_Chars
6830                           ("--for-linker=IDENTIFICATION=");
6831                         String_To_Name_Buffer (Strval (Str));
6832                         Store_String_Chars (Name_Buffer (1 .. Name_Len));
6833
6834                         --  Only the last processed IDENT is saved. The main
6835                         --  purpose is so an IDENT associated with a main
6836                         --  procedure will be used in preference to an IDENT
6837                         --  associated with a with'd package.
6838
6839                         Replace_Linker_Option_String
6840                           (End_String, "--for-linker=IDENTIFICATION=");
6841                      end if;
6842
6843                      Set_Ident_String (Current_Sem_Unit, Str);
6844                   end if;
6845
6846                --  For subunits, we just ignore the Ident, since in GNAT
6847                --  these are not separate object files, and hence not
6848                --  separate units in the unit table.
6849
6850                elsif Nkind (GP) = N_Subunit then
6851                   null;
6852
6853                --  Otherwise we have a misplaced pragma Ident, but we ignore
6854                --  this if we are in an instantiation, since it comes from
6855                --  a generic, and has no relevance to the instantiation.
6856
6857                elsif Prag_Id = Pragma_Ident then
6858                   if Instantiation_Location (Loc) = No_Location then
6859                      Error_Pragma ("pragma% only allowed at outer level");
6860                   end if;
6861                end if;
6862             end;
6863          end Ident;
6864
6865          -----------------------
6866          -- Implicit_Packing --
6867          -----------------------
6868
6869          --  pragma Implicit_Packing;
6870
6871          when Pragma_Implicit_Packing =>
6872             GNAT_Pragma;
6873             Check_Arg_Count (0);
6874             Implicit_Packing := True;
6875
6876          ------------
6877          -- Import --
6878          ------------
6879
6880          --  pragma Import (
6881          --    [   Convention    =>] convention_IDENTIFIER,
6882          --    [   Entity        =>] local_NAME
6883          --    [, [External_Name =>] static_string_EXPRESSION ]
6884          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
6885
6886          when Pragma_Import =>
6887             Check_Ada_83_Warning;
6888             Check_Arg_Order
6889               ((Name_Convention,
6890                 Name_Entity,
6891                 Name_External_Name,
6892                 Name_Link_Name));
6893             Check_At_Least_N_Arguments (2);
6894             Check_At_Most_N_Arguments  (4);
6895             Process_Import_Or_Interface;
6896
6897          ----------------------
6898          -- Import_Exception --
6899          ----------------------
6900
6901          --  pragma Import_Exception (
6902          --        [Internal         =>] LOCAL_NAME,
6903          --     [, [External         =>] EXTERNAL_SYMBOL,]
6904          --     [, [Form     =>] Ada | VMS]
6905          --     [, [Code     =>] static_integer_EXPRESSION]);
6906
6907          when Pragma_Import_Exception => Import_Exception : declare
6908             Args  : Args_List (1 .. 4);
6909             Names : constant Name_List (1 .. 4) := (
6910                       Name_Internal,
6911                       Name_External,
6912                       Name_Form,
6913                       Name_Code);
6914
6915             Internal : Node_Id renames Args (1);
6916             External : Node_Id renames Args (2);
6917             Form     : Node_Id renames Args (3);
6918             Code     : Node_Id renames Args (4);
6919
6920          begin
6921             Gather_Associations (Names, Args);
6922
6923             if Present (External) and then Present (Code) then
6924                Error_Pragma
6925                  ("cannot give both External and Code options for pragma%");
6926             end if;
6927
6928             Process_Extended_Import_Export_Exception_Pragma (
6929               Arg_Internal => Internal,
6930               Arg_External => External,
6931               Arg_Form     => Form,
6932               Arg_Code     => Code);
6933
6934             if not Is_VMS_Exception (Entity (Internal)) then
6935                Set_Imported (Entity (Internal));
6936             end if;
6937          end Import_Exception;
6938
6939          ---------------------
6940          -- Import_Function --
6941          ---------------------
6942
6943          --  pragma Import_Function (
6944          --        [Internal                 =>] LOCAL_NAME,
6945          --     [, [External                 =>] EXTERNAL_SYMBOL]
6946          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
6947          --     [, [Result_Type              =>] SUBTYPE_MARK]
6948          --     [, [Mechanism                =>] MECHANISM]
6949          --     [, [Result_Mechanism         =>] MECHANISM_NAME]
6950          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
6951
6952          --  EXTERNAL_SYMBOL ::=
6953          --    IDENTIFIER
6954          --  | static_string_EXPRESSION
6955
6956          --  PARAMETER_TYPES ::=
6957          --    null
6958          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6959
6960          --  TYPE_DESIGNATOR ::=
6961          --    subtype_NAME
6962          --  | subtype_Name ' Access
6963
6964          --  MECHANISM ::=
6965          --    MECHANISM_NAME
6966          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6967
6968          --  MECHANISM_ASSOCIATION ::=
6969          --    [formal_parameter_NAME =>] MECHANISM_NAME
6970
6971          --  MECHANISM_NAME ::=
6972          --    Value
6973          --  | Reference
6974          --  | Descriptor [([Class =>] CLASS_NAME)]
6975
6976          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6977
6978          when Pragma_Import_Function => Import_Function : declare
6979             Args  : Args_List (1 .. 7);
6980             Names : constant Name_List (1 .. 7) := (
6981                       Name_Internal,
6982                       Name_External,
6983                       Name_Parameter_Types,
6984                       Name_Result_Type,
6985                       Name_Mechanism,
6986                       Name_Result_Mechanism,
6987                       Name_First_Optional_Parameter);
6988
6989             Internal                 : Node_Id renames Args (1);
6990             External                 : Node_Id renames Args (2);
6991             Parameter_Types          : Node_Id renames Args (3);
6992             Result_Type              : Node_Id renames Args (4);
6993             Mechanism                : Node_Id renames Args (5);
6994             Result_Mechanism         : Node_Id renames Args (6);
6995             First_Optional_Parameter : Node_Id renames Args (7);
6996
6997          begin
6998             GNAT_Pragma;
6999             Gather_Associations (Names, Args);
7000             Process_Extended_Import_Export_Subprogram_Pragma (
7001               Arg_Internal                 => Internal,
7002               Arg_External                 => External,
7003               Arg_Parameter_Types          => Parameter_Types,
7004               Arg_Result_Type              => Result_Type,
7005               Arg_Mechanism                => Mechanism,
7006               Arg_Result_Mechanism         => Result_Mechanism,
7007               Arg_First_Optional_Parameter => First_Optional_Parameter);
7008          end Import_Function;
7009
7010          -------------------
7011          -- Import_Object --
7012          -------------------
7013
7014          --  pragma Import_Object (
7015          --        [Internal =>] LOCAL_NAME,
7016          --     [, [External =>] EXTERNAL_SYMBOL]
7017          --     [, [Size     =>] EXTERNAL_SYMBOL]);
7018
7019          --  EXTERNAL_SYMBOL ::=
7020          --    IDENTIFIER
7021          --  | static_string_EXPRESSION
7022
7023          when Pragma_Import_Object => Import_Object : declare
7024             Args  : Args_List (1 .. 3);
7025             Names : constant Name_List (1 .. 3) := (
7026                       Name_Internal,
7027                       Name_External,
7028                       Name_Size);
7029
7030             Internal : Node_Id renames Args (1);
7031             External : Node_Id renames Args (2);
7032             Size     : Node_Id renames Args (3);
7033
7034          begin
7035             GNAT_Pragma;
7036             Gather_Associations (Names, Args);
7037             Process_Extended_Import_Export_Object_Pragma (
7038               Arg_Internal => Internal,
7039               Arg_External => External,
7040               Arg_Size     => Size);
7041          end Import_Object;
7042
7043          ----------------------
7044          -- Import_Procedure --
7045          ----------------------
7046
7047          --  pragma Import_Procedure (
7048          --        [Internal                 =>] LOCAL_NAME,
7049          --     [, [External                 =>] EXTERNAL_SYMBOL]
7050          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
7051          --     [, [Mechanism                =>] MECHANISM]
7052          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
7053
7054          --  EXTERNAL_SYMBOL ::=
7055          --    IDENTIFIER
7056          --  | static_string_EXPRESSION
7057
7058          --  PARAMETER_TYPES ::=
7059          --    null
7060          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7061
7062          --  TYPE_DESIGNATOR ::=
7063          --    subtype_NAME
7064          --  | subtype_Name ' Access
7065
7066          --  MECHANISM ::=
7067          --    MECHANISM_NAME
7068          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7069
7070          --  MECHANISM_ASSOCIATION ::=
7071          --    [formal_parameter_NAME =>] MECHANISM_NAME
7072
7073          --  MECHANISM_NAME ::=
7074          --    Value
7075          --  | Reference
7076          --  | Descriptor [([Class =>] CLASS_NAME)]
7077
7078          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7079
7080          when Pragma_Import_Procedure => Import_Procedure : declare
7081             Args  : Args_List (1 .. 5);
7082             Names : constant Name_List (1 .. 5) := (
7083                       Name_Internal,
7084                       Name_External,
7085                       Name_Parameter_Types,
7086                       Name_Mechanism,
7087                       Name_First_Optional_Parameter);
7088
7089             Internal                 : Node_Id renames Args (1);
7090             External                 : Node_Id renames Args (2);
7091             Parameter_Types          : Node_Id renames Args (3);
7092             Mechanism                : Node_Id renames Args (4);
7093             First_Optional_Parameter : Node_Id renames Args (5);
7094
7095          begin
7096             GNAT_Pragma;
7097             Gather_Associations (Names, Args);
7098             Process_Extended_Import_Export_Subprogram_Pragma (
7099               Arg_Internal                 => Internal,
7100               Arg_External                 => External,
7101               Arg_Parameter_Types          => Parameter_Types,
7102               Arg_Mechanism                => Mechanism,
7103               Arg_First_Optional_Parameter => First_Optional_Parameter);
7104          end Import_Procedure;
7105
7106          -----------------------------
7107          -- Import_Valued_Procedure --
7108          -----------------------------
7109
7110          --  pragma Import_Valued_Procedure (
7111          --        [Internal                 =>] LOCAL_NAME,
7112          --     [, [External                 =>] EXTERNAL_SYMBOL]
7113          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
7114          --     [, [Mechanism                =>] MECHANISM]
7115          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
7116
7117          --  EXTERNAL_SYMBOL ::=
7118          --    IDENTIFIER
7119          --  | static_string_EXPRESSION
7120
7121          --  PARAMETER_TYPES ::=
7122          --    null
7123          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7124
7125          --  TYPE_DESIGNATOR ::=
7126          --    subtype_NAME
7127          --  | subtype_Name ' Access
7128
7129          --  MECHANISM ::=
7130          --    MECHANISM_NAME
7131          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7132
7133          --  MECHANISM_ASSOCIATION ::=
7134          --    [formal_parameter_NAME =>] MECHANISM_NAME
7135
7136          --  MECHANISM_NAME ::=
7137          --    Value
7138          --  | Reference
7139          --  | Descriptor [([Class =>] CLASS_NAME)]
7140
7141          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7142
7143          when Pragma_Import_Valued_Procedure =>
7144          Import_Valued_Procedure : declare
7145             Args  : Args_List (1 .. 5);
7146             Names : constant Name_List (1 .. 5) := (
7147                       Name_Internal,
7148                       Name_External,
7149                       Name_Parameter_Types,
7150                       Name_Mechanism,
7151                       Name_First_Optional_Parameter);
7152
7153             Internal                 : Node_Id renames Args (1);
7154             External                 : Node_Id renames Args (2);
7155             Parameter_Types          : Node_Id renames Args (3);
7156             Mechanism                : Node_Id renames Args (4);
7157             First_Optional_Parameter : Node_Id renames Args (5);
7158
7159          begin
7160             GNAT_Pragma;
7161             Gather_Associations (Names, Args);
7162             Process_Extended_Import_Export_Subprogram_Pragma (
7163               Arg_Internal                 => Internal,
7164               Arg_External                 => External,
7165               Arg_Parameter_Types          => Parameter_Types,
7166               Arg_Mechanism                => Mechanism,
7167               Arg_First_Optional_Parameter => First_Optional_Parameter);
7168          end Import_Valued_Procedure;
7169
7170          ------------------------
7171          -- Initialize_Scalars --
7172          ------------------------
7173
7174          --  pragma Initialize_Scalars;
7175
7176          when Pragma_Initialize_Scalars =>
7177             GNAT_Pragma;
7178             Check_Arg_Count (0);
7179             Check_Valid_Configuration_Pragma;
7180             Check_Restriction (No_Initialize_Scalars, N);
7181
7182             if not Restriction_Active (No_Initialize_Scalars) then
7183                Init_Or_Norm_Scalars := True;
7184                Initialize_Scalars := True;
7185             end if;
7186
7187          ------------
7188          -- Inline --
7189          ------------
7190
7191          --  pragma Inline ( NAME {, NAME} );
7192
7193          when Pragma_Inline =>
7194
7195             --  Pragma is active if inlining option is active
7196
7197             Process_Inline (Inline_Active);
7198
7199          -------------------
7200          -- Inline_Always --
7201          -------------------
7202
7203          --  pragma Inline_Always ( NAME {, NAME} );
7204
7205          when Pragma_Inline_Always =>
7206             Process_Inline (True);
7207
7208          --------------------
7209          -- Inline_Generic --
7210          --------------------
7211
7212          --  pragma Inline_Generic (NAME {, NAME});
7213
7214          when Pragma_Inline_Generic =>
7215             Process_Generic_List;
7216
7217          ----------------------
7218          -- Inspection_Point --
7219          ----------------------
7220
7221          --  pragma Inspection_Point [(object_NAME {, object_NAME})];
7222
7223          when Pragma_Inspection_Point => Inspection_Point : declare
7224             Arg : Node_Id;
7225             Exp : Node_Id;
7226
7227          begin
7228             if Arg_Count > 0 then
7229                Arg := Arg1;
7230                loop
7231                   Exp := Expression (Arg);
7232                   Analyze (Exp);
7233
7234                   if not Is_Entity_Name (Exp)
7235                     or else not Is_Object (Entity (Exp))
7236                   then
7237                      Error_Pragma_Arg ("object name required", Arg);
7238                   end if;
7239
7240                   Next (Arg);
7241                   exit when No (Arg);
7242                end loop;
7243             end if;
7244          end Inspection_Point;
7245
7246          ---------------
7247          -- Interface --
7248          ---------------
7249
7250          --  pragma Interface (
7251          --    [   Convention    =>] convention_IDENTIFIER,
7252          --    [   Entity        =>] local_NAME
7253          --    [, [External_Name =>] static_string_EXPRESSION ]
7254          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7255
7256          when Pragma_Interface =>
7257             GNAT_Pragma;
7258             Check_Arg_Order
7259               ((Name_Convention,
7260                 Name_Entity,
7261                 Name_External_Name,
7262                 Name_Link_Name));
7263             Check_At_Least_N_Arguments (2);
7264             Check_At_Most_N_Arguments  (4);
7265             Process_Import_Or_Interface;
7266
7267          --------------------
7268          -- Interface_Name --
7269          --------------------
7270
7271          --  pragma Interface_Name (
7272          --    [  Entity        =>] local_NAME
7273          --    [,[External_Name =>] static_string_EXPRESSION ]
7274          --    [,[Link_Name     =>] static_string_EXPRESSION ]);
7275
7276          when Pragma_Interface_Name => Interface_Name : declare
7277             Id     : Node_Id;
7278             Def_Id : Entity_Id;
7279             Hom_Id : Entity_Id;
7280             Found  : Boolean;
7281
7282          begin
7283             GNAT_Pragma;
7284             Check_Arg_Order
7285               ((Name_Entity, Name_External_Name, Name_Link_Name));
7286             Check_At_Least_N_Arguments (2);
7287             Check_At_Most_N_Arguments  (3);
7288             Id := Expression (Arg1);
7289             Analyze (Id);
7290
7291             if not Is_Entity_Name (Id) then
7292                Error_Pragma_Arg
7293                  ("first argument for pragma% must be entity name", Arg1);
7294             elsif Etype (Id) = Any_Type then
7295                return;
7296             else
7297                Def_Id := Entity (Id);
7298             end if;
7299
7300             --  Special DEC-compatible processing for the object case,
7301             --  forces object to be imported.
7302
7303             if Ekind (Def_Id) = E_Variable then
7304                Kill_Size_Check_Code (Def_Id);
7305                Note_Possible_Modification (Id);
7306
7307                --  Initialization is not allowed for imported variable
7308
7309                if Present (Expression (Parent (Def_Id)))
7310                  and then Comes_From_Source (Expression (Parent (Def_Id)))
7311                then
7312                   Error_Msg_Sloc := Sloc (Def_Id);
7313                   Error_Pragma_Arg
7314                     ("no initialization allowed for declaration of& #",
7315                      Arg2);
7316
7317                else
7318                   --  For compatibility, support VADS usage of providing both
7319                   --  pragmas Interface and Interface_Name to obtain the effect
7320                   --  of a single Import pragma.
7321
7322                   if Is_Imported (Def_Id)
7323                     and then Present (First_Rep_Item (Def_Id))
7324                     and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
7325                     and then Chars (First_Rep_Item (Def_Id)) = Name_Interface
7326                   then
7327                      null;
7328                   else
7329                      Set_Imported (Def_Id);
7330                   end if;
7331
7332                   Set_Is_Public (Def_Id);
7333                   Process_Interface_Name (Def_Id, Arg2, Arg3);
7334                end if;
7335
7336             --  Otherwise must be subprogram
7337
7338             elsif not Is_Subprogram (Def_Id) then
7339                Error_Pragma_Arg
7340                  ("argument of pragma% is not subprogram", Arg1);
7341
7342             else
7343                Check_At_Most_N_Arguments (3);
7344                Hom_Id := Def_Id;
7345                Found := False;
7346
7347                --  Loop through homonyms
7348
7349                loop
7350                   Def_Id := Get_Base_Subprogram (Hom_Id);
7351
7352                   if Is_Imported (Def_Id) then
7353                      Process_Interface_Name (Def_Id, Arg2, Arg3);
7354                      Found := True;
7355                   end if;
7356
7357                   Hom_Id := Homonym (Hom_Id);
7358
7359                   exit when No (Hom_Id)
7360                     or else Scope (Hom_Id) /= Current_Scope;
7361                end loop;
7362
7363                if not Found then
7364                   Error_Pragma_Arg
7365                     ("argument of pragma% is not imported subprogram",
7366                      Arg1);
7367                end if;
7368             end if;
7369          end Interface_Name;
7370
7371          -----------------------
7372          -- Interrupt_Handler --
7373          -----------------------
7374
7375          --  pragma Interrupt_Handler (handler_NAME);
7376
7377          when Pragma_Interrupt_Handler =>
7378             Check_Ada_83_Warning;
7379             Check_Arg_Count (1);
7380             Check_No_Identifiers;
7381
7382             if No_Run_Time_Mode then
7383                Error_Msg_CRT ("Interrupt_Handler pragma", N);
7384             else
7385                Check_Interrupt_Or_Attach_Handler;
7386                Process_Interrupt_Or_Attach_Handler;
7387             end if;
7388
7389          ------------------------
7390          -- Interrupt_Priority --
7391          ------------------------
7392
7393          --  pragma Interrupt_Priority [(EXPRESSION)];
7394
7395          when Pragma_Interrupt_Priority => Interrupt_Priority : declare
7396             P   : constant Node_Id := Parent (N);
7397             Arg : Node_Id;
7398
7399          begin
7400             Check_Ada_83_Warning;
7401
7402             if Arg_Count /= 0 then
7403                Arg := Expression (Arg1);
7404                Check_Arg_Count (1);
7405                Check_No_Identifiers;
7406
7407                --  The expression must be analyzed in the special manner
7408                --  described in "Handling of Default and Per-Object
7409                --  Expressions" in sem.ads.
7410
7411                Analyze_Per_Use_Expression (Arg, RTE (RE_Interrupt_Priority));
7412             end if;
7413
7414             if Nkind (P) /= N_Task_Definition
7415               and then Nkind (P) /= N_Protected_Definition
7416             then
7417                Pragma_Misplaced;
7418                return;
7419
7420             elsif Has_Priority_Pragma (P) then
7421                Error_Pragma ("duplicate pragma% not allowed");
7422
7423             else
7424                Set_Has_Priority_Pragma (P, True);
7425                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7426             end if;
7427          end Interrupt_Priority;
7428
7429          ---------------------
7430          -- Interrupt_State --
7431          ---------------------
7432
7433          --  pragma Interrupt_State (
7434          --    [Name  =>] INTERRUPT_ID,
7435          --    [State =>] INTERRUPT_STATE);
7436
7437          --  INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
7438          --  INTERRUPT_STATE => System | Runtime | User
7439
7440          --  Note: if the interrupt id is given as an identifier, then
7441          --  it must be one of the identifiers in Ada.Interrupts.Names.
7442          --  Otherwise it is given as a static integer expression which
7443          --  must be in the range of Ada.Interrupts.Interrupt_ID.
7444
7445          when Pragma_Interrupt_State => Interrupt_State : declare
7446
7447             Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
7448             --  This is the entity Ada.Interrupts.Interrupt_ID;
7449
7450             State_Type : Character;
7451             --  Set to 's'/'r'/'u' for System/Runtime/User
7452
7453             IST_Num : Pos;
7454             --  Index to entry in Interrupt_States table
7455
7456             Int_Val : Uint;
7457             --  Value of interrupt
7458
7459             Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
7460             --  The first argument to the pragma
7461
7462             Int_Ent : Entity_Id;
7463             --  Interrupt entity in Ada.Interrupts.Names
7464
7465          begin
7466             GNAT_Pragma;
7467             Check_Arg_Order ((Name_Name, Name_State));
7468             Check_Arg_Count (2);
7469
7470             Check_Optional_Identifier (Arg1, Name_Name);
7471             Check_Optional_Identifier (Arg2, Name_State);
7472             Check_Arg_Is_Identifier (Arg2);
7473
7474             --  First argument is identifier
7475
7476             if Nkind (Arg1X) = N_Identifier then
7477
7478                --  Search list of names in Ada.Interrupts.Names
7479
7480                Int_Ent := First_Entity (RTE (RE_Names));
7481                loop
7482                   if No (Int_Ent) then
7483                      Error_Pragma_Arg ("invalid interrupt name", Arg1);
7484
7485                   elsif Chars (Int_Ent) = Chars (Arg1X) then
7486                      Int_Val := Expr_Value (Constant_Value (Int_Ent));
7487                      exit;
7488                   end if;
7489
7490                   Next_Entity (Int_Ent);
7491                end loop;
7492
7493             --  First argument is not an identifier, so it must be a
7494             --  static expression of type Ada.Interrupts.Interrupt_ID.
7495
7496             else
7497                Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7498                Int_Val := Expr_Value (Arg1X);
7499
7500                if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
7501                     or else
7502                   Int_Val > Expr_Value (Type_High_Bound (Int_Id))
7503                then
7504                   Error_Pragma_Arg
7505                     ("value not in range of type " &
7506                      """Ada.Interrupts.Interrupt_'I'D""", Arg1);
7507                end if;
7508             end if;
7509
7510             --  Check OK state
7511
7512             case Chars (Get_Pragma_Arg (Arg2)) is
7513                when Name_Runtime => State_Type := 'r';
7514                when Name_System  => State_Type := 's';
7515                when Name_User    => State_Type := 'u';
7516
7517                when others =>
7518                   Error_Pragma_Arg ("invalid interrupt state", Arg2);
7519             end case;
7520
7521             --  Check if entry is already stored
7522
7523             IST_Num := Interrupt_States.First;
7524             loop
7525                --  If entry not found, add it
7526
7527                if IST_Num > Interrupt_States.Last then
7528                   Interrupt_States.Append
7529                     ((Interrupt_Number => UI_To_Int (Int_Val),
7530                       Interrupt_State  => State_Type,
7531                       Pragma_Loc       => Loc));
7532                   exit;
7533
7534                --  Case of entry for the same entry
7535
7536                elsif Int_Val = Interrupt_States.Table (IST_Num).
7537                                                            Interrupt_Number
7538                then
7539                   --  If state matches, done, no need to make redundant entry
7540
7541                   exit when
7542                     State_Type = Interrupt_States.Table (IST_Num).
7543                                                            Interrupt_State;
7544
7545                   --  Otherwise if state does not match, error
7546
7547                   Error_Msg_Sloc :=
7548                     Interrupt_States.Table (IST_Num).Pragma_Loc;
7549                   Error_Pragma_Arg
7550                     ("state conflicts with that given #", Arg2);
7551                   exit;
7552                end if;
7553
7554                IST_Num := IST_Num + 1;
7555             end loop;
7556          end Interrupt_State;
7557
7558          ----------------------
7559          -- Java_Constructor --
7560          ----------------------
7561
7562          --  pragma Java_Constructor ([Entity =>] LOCAL_NAME);
7563
7564          --  Also handles pragma CIL_Constructor
7565
7566          when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
7567          Java_Constructor : declare
7568             Id         : Entity_Id;
7569             Def_Id     : Entity_Id;
7570             Hom_Id     : Entity_Id;
7571             Convention : Convention_Id;
7572
7573          begin
7574             GNAT_Pragma;
7575             Check_Arg_Count (1);
7576             Check_Optional_Identifier (Arg1, Name_Entity);
7577             Check_Arg_Is_Local_Name (Arg1);
7578
7579             Id := Expression (Arg1);
7580             Find_Program_Unit_Name (Id);
7581
7582             --  If we did not find the name, we are done
7583
7584             if Etype (Id) = Any_Type then
7585                return;
7586             end if;
7587
7588             case Prag_Id is
7589                when Pragma_CIL_Constructor  => Convention := Convention_CIL;
7590                when Pragma_Java_Constructor => Convention := Convention_Java;
7591                when others                  => null;
7592             end case;
7593
7594             Hom_Id := Entity (Id);
7595
7596             --  Loop through homonyms
7597
7598             loop
7599                Def_Id := Get_Base_Subprogram (Hom_Id);
7600
7601                --  The constructor is required to be a function returning an
7602                --  access type whose designated type has convention Java/CIL.
7603
7604                if Ekind (Def_Id) = E_Function
7605                  and then
7606                    (Is_Value_Type (Etype (Def_Id))
7607                      or else
7608                        (Ekind (Etype (Def_Id)) in Access_Kind
7609                          and then
7610                           (Atree.Convention
7611                              (Designated_Type (Etype (Def_Id))) = Convention
7612                             or else
7613                               Atree.Convention
7614                                (Root_Type (Designated_Type (Etype (Def_Id)))) =
7615                                                                  Convention)))
7616                then
7617                   Set_Is_Constructor (Def_Id);
7618                   Set_Convention     (Def_Id, Convention);
7619                   Set_Is_Imported    (Def_Id);
7620
7621                else
7622                   if Convention = Convention_Java then
7623                      Error_Pragma_Arg
7624                        ("pragma% requires function returning a " &
7625                         "'Java access type", Arg1);
7626                   else
7627                      pragma Assert (Convention = Convention_CIL);
7628                      Error_Pragma_Arg
7629                        ("pragma% requires function returning a " &
7630                         "'CIL access type", Arg1);
7631                   end if;
7632                end if;
7633
7634                Hom_Id := Homonym (Hom_Id);
7635
7636                exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
7637             end loop;
7638          end Java_Constructor;
7639
7640          ----------------------
7641          -- Java_Interface --
7642          ----------------------
7643
7644          --  pragma Java_Interface ([Entity =>] LOCAL_NAME);
7645
7646          when Pragma_Java_Interface => Java_Interface : declare
7647             Arg : Node_Id;
7648             Typ : Entity_Id;
7649
7650          begin
7651             GNAT_Pragma;
7652             Check_Arg_Count (1);
7653             Check_Optional_Identifier (Arg1, Name_Entity);
7654             Check_Arg_Is_Local_Name (Arg1);
7655
7656             Arg := Expression (Arg1);
7657             Analyze (Arg);
7658
7659             if Etype (Arg) = Any_Type then
7660                return;
7661             end if;
7662
7663             if not Is_Entity_Name (Arg)
7664               or else not Is_Type (Entity (Arg))
7665             then
7666                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7667             end if;
7668
7669             Typ := Underlying_Type (Entity (Arg));
7670
7671             --  For now we simply check some of the semantic constraints
7672             --  on the type. This currently leaves out some restrictions
7673             --  on interface types, namely that the parent type must be
7674             --  java.lang.Object.Typ and that all primitives of the type
7675             --  should be declared abstract. ???
7676
7677             if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
7678                Error_Pragma_Arg ("pragma% requires an abstract "
7679                  & "tagged type", Arg1);
7680
7681             elsif not Has_Discriminants (Typ)
7682               or else Ekind (Etype (First_Discriminant (Typ)))
7683                         /= E_Anonymous_Access_Type
7684               or else
7685                 not Is_Class_Wide_Type
7686                       (Designated_Type (Etype (First_Discriminant (Typ))))
7687             then
7688                Error_Pragma_Arg
7689                  ("type must have a class-wide access discriminant", Arg1);
7690             end if;
7691          end Java_Interface;
7692
7693          ----------------
7694          -- Keep_Names --
7695          ----------------
7696
7697          --  pragma Keep_Names ([On => ] local_NAME);
7698
7699          when Pragma_Keep_Names => Keep_Names : declare
7700             Arg : Node_Id;
7701
7702          begin
7703             GNAT_Pragma;
7704             Check_Arg_Count (1);
7705             Check_Optional_Identifier (Arg1, Name_On);
7706             Check_Arg_Is_Local_Name (Arg1);
7707
7708             Arg := Expression (Arg1);
7709             Analyze (Arg);
7710
7711             if Etype (Arg) = Any_Type then
7712                return;
7713             end if;
7714
7715             if not Is_Entity_Name (Arg)
7716               or else Ekind (Entity (Arg)) /= E_Enumeration_Type
7717             then
7718                Error_Pragma_Arg
7719                  ("pragma% requires a local enumeration type", Arg1);
7720             end if;
7721
7722             Set_Discard_Names (Entity (Arg), False);
7723          end Keep_Names;
7724
7725          -------------
7726          -- License --
7727          -------------
7728
7729          --  pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
7730
7731          when Pragma_License =>
7732             GNAT_Pragma;
7733             Check_Arg_Count (1);
7734             Check_No_Identifiers;
7735             Check_Valid_Configuration_Pragma;
7736             Check_Arg_Is_Identifier (Arg1);
7737
7738             declare
7739                Sind : constant Source_File_Index :=
7740                         Source_Index (Current_Sem_Unit);
7741
7742             begin
7743                case Chars (Get_Pragma_Arg (Arg1)) is
7744                   when Name_GPL =>
7745                      Set_License (Sind, GPL);
7746
7747                   when Name_Modified_GPL =>
7748                      Set_License (Sind, Modified_GPL);
7749
7750                   when Name_Restricted =>
7751                      Set_License (Sind, Restricted);
7752
7753                   when Name_Unrestricted =>
7754                      Set_License (Sind, Unrestricted);
7755
7756                   when others =>
7757                      Error_Pragma_Arg ("invalid license name", Arg1);
7758                end case;
7759             end;
7760
7761          ---------------
7762          -- Link_With --
7763          ---------------
7764
7765          --  pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
7766
7767          when Pragma_Link_With => Link_With : declare
7768             Arg : Node_Id;
7769
7770          begin
7771             GNAT_Pragma;
7772
7773             if Operating_Mode = Generate_Code
7774               and then In_Extended_Main_Source_Unit (N)
7775             then
7776                Check_At_Least_N_Arguments (1);
7777                Check_No_Identifiers;
7778                Check_Is_In_Decl_Part_Or_Package_Spec;
7779                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7780                Start_String;
7781
7782                Arg := Arg1;
7783                while Present (Arg) loop
7784                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
7785
7786                   --  Store argument, converting sequences of spaces
7787                   --  to a single null character (this is one of the
7788                   --  differences in processing between Link_With
7789                   --  and Linker_Options).
7790
7791                   Arg_Store : declare
7792                      C : constant Char_Code := Get_Char_Code (' ');
7793                      S : constant String_Id :=
7794                            Strval (Expr_Value_S (Expression (Arg)));
7795                      L : constant Nat := String_Length (S);
7796                      F : Nat := 1;
7797
7798                      procedure Skip_Spaces;
7799                      --  Advance F past any spaces
7800
7801                      -----------------
7802                      -- Skip_Spaces --
7803                      -----------------
7804
7805                      procedure Skip_Spaces is
7806                      begin
7807                         while F <= L and then Get_String_Char (S, F) = C loop
7808                            F := F + 1;
7809                         end loop;
7810                      end Skip_Spaces;
7811
7812                   --  Start of processing for Arg_Store
7813
7814                   begin
7815                      Skip_Spaces; -- skip leading spaces
7816
7817                      --  Loop through characters, changing any embedded
7818                      --  sequence of spaces to a single null character
7819                      --  (this is how Link_With/Linker_Options differ)
7820
7821                      while F <= L loop
7822                         if Get_String_Char (S, F) = C then
7823                            Skip_Spaces;
7824                            exit when F > L;
7825                            Store_String_Char (ASCII.NUL);
7826
7827                         else
7828                            Store_String_Char (Get_String_Char (S, F));
7829                            F := F + 1;
7830                         end if;
7831                      end loop;
7832                   end Arg_Store;
7833
7834                   Arg := Next (Arg);
7835
7836                   if Present (Arg) then
7837                      Store_String_Char (ASCII.NUL);
7838                   end if;
7839                end loop;
7840
7841                Store_Linker_Option_String (End_String);
7842             end if;
7843          end Link_With;
7844
7845          ------------------
7846          -- Linker_Alias --
7847          ------------------
7848
7849          --  pragma Linker_Alias (
7850          --      [Entity =>]  LOCAL_NAME
7851          --      [Target =>]  static_string_EXPRESSION);
7852
7853          when Pragma_Linker_Alias =>
7854             GNAT_Pragma;
7855             Check_Arg_Order ((Name_Entity, Name_Target));
7856             Check_Arg_Count (2);
7857             Check_Optional_Identifier (Arg1, Name_Entity);
7858             Check_Optional_Identifier (Arg2, Name_Target);
7859             Check_Arg_Is_Library_Level_Local_Name (Arg1);
7860             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7861
7862             --  The only processing required is to link this item on to the
7863             --  list of rep items for the given entity. This is accomplished
7864             --  by the call to Rep_Item_Too_Late (when no error is detected
7865             --  and False is returned).
7866
7867             if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7868                return;
7869             else
7870                Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7871             end if;
7872
7873          ------------------------
7874          -- Linker_Constructor --
7875          ------------------------
7876
7877          --  pragma Linker_Constructor (procedure_LOCAL_NAME);
7878
7879          --  Code is shared with Linker_Destructor
7880
7881          -----------------------
7882          -- Linker_Destructor --
7883          -----------------------
7884
7885          --  pragma Linker_Destructor (procedure_LOCAL_NAME);
7886
7887          when Pragma_Linker_Constructor |
7888               Pragma_Linker_Destructor =>
7889          Linker_Constructor : declare
7890             Arg1_X : Node_Id;
7891             Proc   : Entity_Id;
7892
7893          begin
7894             GNAT_Pragma;
7895             Check_Arg_Count (1);
7896             Check_No_Identifiers;
7897             Check_Arg_Is_Local_Name (Arg1);
7898             Arg1_X := Expression (Arg1);
7899             Analyze (Arg1_X);
7900             Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
7901
7902             if not Is_Library_Level_Entity (Proc) then
7903                Error_Pragma_Arg
7904                 ("argument for pragma% must be library level entity", Arg1);
7905             end if;
7906
7907             --  The only processing required is to link this item on to the
7908             --  list of rep items for the given entity. This is accomplished
7909             --  by the call to Rep_Item_Too_Late (when no error is detected
7910             --  and False is returned).
7911
7912             if Rep_Item_Too_Late (Proc, N) then
7913                return;
7914             else
7915                Set_Has_Gigi_Rep_Item (Proc);
7916             end if;
7917          end Linker_Constructor;
7918
7919          --------------------
7920          -- Linker_Options --
7921          --------------------
7922
7923          --  pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
7924
7925          when Pragma_Linker_Options => Linker_Options : declare
7926             Arg : Node_Id;
7927
7928          begin
7929             Check_Ada_83_Warning;
7930             Check_No_Identifiers;
7931             Check_Arg_Count (1);
7932             Check_Is_In_Decl_Part_Or_Package_Spec;
7933
7934             if Operating_Mode = Generate_Code
7935               and then In_Extended_Main_Source_Unit (N)
7936             then
7937                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7938                Start_String (Strval (Expr_Value_S (Expression (Arg1))));
7939
7940                Arg := Arg2;
7941                while Present (Arg) loop
7942                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
7943                   Store_String_Char (ASCII.NUL);
7944                   Store_String_Chars
7945                     (Strval (Expr_Value_S (Expression (Arg))));
7946                   Arg := Next (Arg);
7947                end loop;
7948
7949                Store_Linker_Option_String (End_String);
7950             end if;
7951          end Linker_Options;
7952
7953          --------------------
7954          -- Linker_Section --
7955          --------------------
7956
7957          --  pragma Linker_Section (
7958          --      [Entity  =>]  LOCAL_NAME
7959          --      [Section =>]  static_string_EXPRESSION);
7960
7961          when Pragma_Linker_Section =>
7962             GNAT_Pragma;
7963             Check_Arg_Order ((Name_Entity, Name_Section));
7964             Check_Arg_Count (2);
7965             Check_Optional_Identifier (Arg1, Name_Entity);
7966             Check_Optional_Identifier (Arg2, Name_Section);
7967             Check_Arg_Is_Library_Level_Local_Name (Arg1);
7968             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7969
7970             --  The only processing required is to link this item on to the
7971             --  list of rep items for the given entity. This is accomplished
7972             --  by the call to Rep_Item_Too_Late (when no error is detected
7973             --  and False is returned).
7974
7975             if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7976                return;
7977             else
7978                Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7979             end if;
7980
7981          ----------
7982          -- List --
7983          ----------
7984
7985          --  pragma List (On | Off)
7986
7987          --  There is nothing to do here, since we did all the processing
7988          --  for this pragma in Par.Prag (so that it works properly even in
7989          --  syntax only mode)
7990
7991          when Pragma_List =>
7992             null;
7993
7994          --------------------
7995          -- Locking_Policy --
7996          --------------------
7997
7998          --  pragma Locking_Policy (policy_IDENTIFIER);
7999
8000          when Pragma_Locking_Policy => declare
8001             LP : Character;
8002
8003          begin
8004             Check_Ada_83_Warning;
8005             Check_Arg_Count (1);
8006             Check_No_Identifiers;
8007             Check_Arg_Is_Locking_Policy (Arg1);
8008             Check_Valid_Configuration_Pragma;
8009             Get_Name_String (Chars (Expression (Arg1)));
8010             LP := Fold_Upper (Name_Buffer (1));
8011
8012             if Locking_Policy /= ' '
8013               and then Locking_Policy /= LP
8014             then
8015                Error_Msg_Sloc := Locking_Policy_Sloc;
8016                Error_Pragma ("locking policy incompatible with policy#");
8017
8018             --  Set new policy, but always preserve System_Location since
8019             --  we like the error message with the run time name.
8020
8021             else
8022                Locking_Policy := LP;
8023
8024                if Locking_Policy_Sloc /= System_Location then
8025                   Locking_Policy_Sloc := Loc;
8026                end if;
8027             end if;
8028          end;
8029
8030          ----------------
8031          -- Long_Float --
8032          ----------------
8033
8034          --  pragma Long_Float (D_Float | G_Float);
8035
8036          when Pragma_Long_Float =>
8037             GNAT_Pragma;
8038             Check_Valid_Configuration_Pragma;
8039             Check_Arg_Count (1);
8040             Check_No_Identifier (Arg1);
8041             Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
8042
8043             if not OpenVMS_On_Target then
8044                Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
8045             end if;
8046
8047             --  D_Float case
8048
8049             if Chars (Expression (Arg1)) = Name_D_Float then
8050                if Opt.Float_Format_Long = 'G' then
8051                   Error_Pragma ("G_Float previously specified");
8052                end if;
8053
8054                Opt.Float_Format_Long := 'D';
8055
8056             --  G_Float case (this is the default, does not need overriding)
8057
8058             else
8059                if Opt.Float_Format_Long = 'D' then
8060                   Error_Pragma ("D_Float previously specified");
8061                end if;
8062
8063                Opt.Float_Format_Long := 'G';
8064             end if;
8065
8066             Set_Standard_Fpt_Formats;
8067
8068          -----------------------
8069          -- Machine_Attribute --
8070          -----------------------
8071
8072          --  pragma Machine_Attribute (
8073          --    [Entity         =>] LOCAL_NAME,
8074          --    [Attribute_Name =>] static_string_EXPRESSION
8075          --  [,[Info           =>] static_string_EXPRESSION] );
8076
8077          when Pragma_Machine_Attribute => Machine_Attribute : declare
8078             Def_Id : Entity_Id;
8079
8080          begin
8081             GNAT_Pragma;
8082             Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
8083
8084             if Arg_Count = 3 then
8085                Check_Optional_Identifier (Arg3, Name_Info);
8086                Check_Arg_Is_Static_Expression (Arg3, Standard_String);
8087             else
8088                Check_Arg_Count (2);
8089             end if;
8090
8091             Check_Optional_Identifier (Arg1, Name_Entity);
8092             Check_Optional_Identifier (Arg2, Name_Attribute_Name);
8093             Check_Arg_Is_Local_Name (Arg1);
8094             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8095             Def_Id := Entity (Expression (Arg1));
8096
8097             if Is_Access_Type (Def_Id) then
8098                Def_Id := Designated_Type (Def_Id);
8099             end if;
8100
8101             if Rep_Item_Too_Early (Def_Id, N) then
8102                return;
8103             end if;
8104
8105             Def_Id := Underlying_Type (Def_Id);
8106
8107             --  The only processing required is to link this item on to the
8108             --  list of rep items for the given entity. This is accomplished
8109             --  by the call to Rep_Item_Too_Late (when no error is detected
8110             --  and False is returned).
8111
8112             if Rep_Item_Too_Late (Def_Id, N) then
8113                return;
8114             else
8115                Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8116             end if;
8117          end Machine_Attribute;
8118
8119          ----------
8120          -- Main --
8121          ----------
8122
8123          --  pragma Main
8124          --   (MAIN_OPTION [, MAIN_OPTION]);
8125
8126          --  MAIN_OPTION ::=
8127          --    [STACK_SIZE              =>] static_integer_EXPRESSION
8128          --  | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
8129          --  | [TIME_SLICING_ENABLED    =>] static_boolean_EXPRESSION
8130
8131          when Pragma_Main => Main : declare
8132             Args  : Args_List (1 .. 3);
8133             Names : constant Name_List (1 .. 3) := (
8134                       Name_Stack_Size,
8135                       Name_Task_Stack_Size_Default,
8136                       Name_Time_Slicing_Enabled);
8137
8138             Nod : Node_Id;
8139
8140          begin
8141             GNAT_Pragma;
8142             Gather_Associations (Names, Args);
8143
8144             for J in 1 .. 2 loop
8145                if Present (Args (J)) then
8146                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8147                end if;
8148             end loop;
8149
8150             if Present (Args (3)) then
8151                Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
8152             end if;
8153
8154             Nod := Next (N);
8155             while Present (Nod) loop
8156                if Nkind (Nod) = N_Pragma
8157                  and then Chars (Nod) = Name_Main
8158                then
8159                   Error_Msg_Name_1 := Chars (N);
8160                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
8161                end if;
8162
8163                Next (Nod);
8164             end loop;
8165          end Main;
8166
8167          ------------------
8168          -- Main_Storage --
8169          ------------------
8170
8171          --  pragma Main_Storage
8172          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
8173
8174          --  MAIN_STORAGE_OPTION ::=
8175          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
8176          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
8177
8178          when Pragma_Main_Storage => Main_Storage : declare
8179             Args  : Args_List (1 .. 2);
8180             Names : constant Name_List (1 .. 2) := (
8181                       Name_Working_Storage,
8182                       Name_Top_Guard);
8183
8184             Nod : Node_Id;
8185
8186          begin
8187             GNAT_Pragma;
8188             Gather_Associations (Names, Args);
8189
8190             for J in 1 .. 2 loop
8191                if Present (Args (J)) then
8192                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8193                end if;
8194             end loop;
8195
8196             Check_In_Main_Program;
8197
8198             Nod := Next (N);
8199             while Present (Nod) loop
8200                if Nkind (Nod) = N_Pragma
8201                  and then Chars (Nod) = Name_Main_Storage
8202                then
8203                   Error_Msg_Name_1 := Chars (N);
8204                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
8205                end if;
8206
8207                Next (Nod);
8208             end loop;
8209          end Main_Storage;
8210
8211          -----------------
8212          -- Memory_Size --
8213          -----------------
8214
8215          --  pragma Memory_Size (NUMERIC_LITERAL)
8216
8217          when Pragma_Memory_Size =>
8218             GNAT_Pragma;
8219
8220             --  Memory size is simply ignored
8221
8222             Check_No_Identifiers;
8223             Check_Arg_Count (1);
8224             Check_Arg_Is_Integer_Literal (Arg1);
8225
8226          -------------
8227          -- No_Body --
8228          -------------
8229
8230          --  pragma No_Body;
8231
8232          --  The only correct use of this pragma is on its own in a file, in
8233          --  which case it is specially processed (see Gnat1drv.Check_Bad_Body
8234          --  and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
8235          --  check for a file containing nothing but a No_Body pragma). If we
8236          --  attempt to process it during normal semantics processing, it means
8237          --  it was misplaced.
8238
8239          when Pragma_No_Body =>
8240             Error_Pragma ("misplaced pragma %");
8241
8242          ---------------
8243          -- No_Return --
8244          ---------------
8245
8246          --  pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
8247
8248          when Pragma_No_Return => No_Return : declare
8249             Id    : Node_Id;
8250             E     : Entity_Id;
8251             Found : Boolean;
8252             Arg   : Node_Id;
8253
8254          begin
8255             GNAT_Pragma;
8256             Check_At_Least_N_Arguments (1);
8257
8258             --  Loop through arguments of pragma
8259
8260             Arg := Arg1;
8261             while Present (Arg) loop
8262                Check_Arg_Is_Local_Name (Arg);
8263                Id := Expression (Arg);
8264                Analyze (Id);
8265
8266                if not Is_Entity_Name (Id) then
8267                   Error_Pragma_Arg ("entity name required", Arg);
8268                end if;
8269
8270                if Etype (Id) = Any_Type then
8271                   raise Pragma_Exit;
8272                end if;
8273
8274                --  Loop to find matching procedures
8275
8276                E := Entity (Id);
8277                Found := False;
8278                while Present (E)
8279                  and then Scope (E) = Current_Scope
8280                loop
8281                   if Ekind (E) = E_Procedure
8282                     or else Ekind (E) = E_Generic_Procedure
8283                   then
8284                      Set_No_Return (E);
8285                      Found := True;
8286                   end if;
8287
8288                   E := Homonym (E);
8289                end loop;
8290
8291                if not Found then
8292                   Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
8293                end if;
8294
8295                Next (Arg);
8296             end loop;
8297          end No_Return;
8298
8299          ------------------------
8300          -- No_Strict_Aliasing --
8301          ------------------------
8302
8303          --  pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
8304
8305          when Pragma_No_Strict_Aliasing => No_Strict_Alias : declare
8306             E_Id : Entity_Id;
8307
8308          begin
8309             GNAT_Pragma;
8310             Check_At_Most_N_Arguments (1);
8311
8312             if Arg_Count = 0 then
8313                Check_Valid_Configuration_Pragma;
8314                Opt.No_Strict_Aliasing := True;
8315
8316             else
8317                Check_Optional_Identifier (Arg2, Name_Entity);
8318                Check_Arg_Is_Local_Name (Arg1);
8319                E_Id := Entity (Expression (Arg1));
8320
8321                if E_Id = Any_Type then
8322                   return;
8323                elsif No (E_Id) or else not Is_Access_Type (E_Id) then
8324                   Error_Pragma_Arg ("pragma% requires access type", Arg1);
8325                end if;
8326
8327                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
8328             end if;
8329          end No_Strict_Alias;
8330
8331          -----------------
8332          -- Obsolescent --
8333          -----------------
8334
8335          --  pragma Obsolescent [(
8336          --    [Entity => NAME,]
8337          --    [(static_string_EXPRESSION [, Ada_05])];
8338
8339          when Pragma_Obsolescent => Obsolescent : declare
8340             Ename : Node_Id;
8341             Decl  : Node_Id;
8342
8343             procedure Set_Obsolescent (E : Entity_Id);
8344             --  Given an entity Ent, mark it as obsolescent if appropriate
8345
8346             ---------------------
8347             -- Set_Obsolescent --
8348             ---------------------
8349
8350             procedure Set_Obsolescent (E : Entity_Id) is
8351                Active : Boolean;
8352                Ent    : Entity_Id;
8353                S      : String_Id;
8354
8355             begin
8356                Active := True;
8357                Ent    := E;
8358
8359                --  Entity name was given
8360
8361                if Present (Ename) then
8362
8363                   --  If entity name matches, we are fine
8364
8365                   if Chars (Ename) = Chars (Ent) then
8366                      null;
8367
8368                   --  If entity name does not match, only possibility is an
8369                   --  enumeration literal from an enumeration type declaration.
8370
8371                   elsif Ekind (Ent) /= E_Enumeration_Type then
8372                      Error_Pragma
8373                        ("pragma % entity name does not match declaration");
8374
8375                   else
8376                      Ent := First_Literal (E);
8377                      loop
8378                         if No (Ent) then
8379                            Error_Pragma
8380                              ("pragma % entity name does not match any " &
8381                               "enumeration literal");
8382
8383                         elsif Chars (Ent) = Chars (Ename) then
8384                            exit;
8385
8386                         else
8387                            Ent := Next_Literal (Ent);
8388                         end if;
8389                      end loop;
8390                   end if;
8391                end if;
8392
8393                --  Ent points to entity to be marked
8394
8395                if Arg_Count >= 1 then
8396
8397                   --  Deal with static string argument
8398
8399                   Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8400                   S := Strval (Expression (Arg1));
8401
8402                   for J in 1 .. String_Length (S) loop
8403                      if not In_Character_Range (Get_String_Char (S, J)) then
8404                         Error_Pragma_Arg
8405                           ("pragma% argument does not allow wide characters",
8406                            Arg1);
8407                      end if;
8408                   end loop;
8409
8410                   Set_Obsolescent_Warning (Ent, Expression (Arg1));
8411
8412                   --  Check for Ada_05 parameter
8413
8414                   if Arg_Count /= 1 then
8415                      Check_Arg_Count (2);
8416
8417                      declare
8418                         Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
8419
8420                      begin
8421                         Check_Arg_Is_Identifier (Argx);
8422
8423                         if Chars (Argx) /= Name_Ada_05 then
8424                            Error_Msg_Name_2 := Name_Ada_05;
8425                            Error_Pragma_Arg
8426                              ("only allowed argument for pragma% is %", Argx);
8427                         end if;
8428
8429                         if Ada_Version_Explicit < Ada_05
8430                           or else not Warn_On_Ada_2005_Compatibility
8431                         then
8432                            Active := False;
8433                         end if;
8434                      end;
8435                   end if;
8436                end if;
8437
8438                --  Set flag if pragma active
8439
8440                if Active then
8441                   Set_Is_Obsolescent (Ent);
8442                end if;
8443
8444                return;
8445             end Set_Obsolescent;
8446
8447          --  Start of processing for pragma Obsolescent
8448
8449          begin
8450             GNAT_Pragma;
8451
8452             Check_At_Most_N_Arguments (3);
8453
8454             --  See if first argument specifies an entity name
8455
8456             if Arg_Count >= 1
8457               and then Chars (Arg1) = Name_Entity
8458             then
8459                Ename := Get_Pragma_Arg (Arg1);
8460
8461                if Nkind (Ename) /= N_Character_Literal
8462                     and then
8463                   Nkind (Ename) /= N_Identifier
8464                     and then
8465                   Nkind (Ename) /= N_Operator_Symbol
8466                then
8467                   Error_Pragma_Arg ("entity name expected for pragma%", Arg1);
8468                end if;
8469
8470                --  Eliminate first argument, so we can share processing
8471
8472                Arg1 := Arg2;
8473                Arg2 := Arg3;
8474                Arg_Count := Arg_Count - 1;
8475
8476             --  No Entity name argument given
8477
8478             else
8479                Ename := Empty;
8480             end if;
8481
8482             Check_No_Identifiers;
8483
8484             --  Get immediately preceding declaration
8485
8486             Decl := Prev (N);
8487             while Present (Decl) and then Nkind (Decl) = N_Pragma loop
8488                Prev (Decl);
8489             end loop;
8490
8491             --  Cases where we do not follow anything other than another pragma
8492
8493             if No (Decl) then
8494
8495                --  First case: library level compilation unit declaration with
8496                --  the pragma immediately following the declaration.
8497
8498                if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
8499                   Set_Obsolescent
8500                     (Defining_Entity (Unit (Parent (Parent (N)))));
8501                   return;
8502
8503                --  Case 2: library unit placement for package
8504
8505                else
8506                   declare
8507                      Ent : constant Entity_Id := Find_Lib_Unit_Name;
8508                   begin
8509                      if Ekind (Ent) = E_Package
8510                        or else Ekind (Ent) = E_Generic_Package
8511                      then
8512                         Set_Obsolescent (Ent);
8513                         return;
8514                      end if;
8515                   end;
8516                end if;
8517
8518             --  Cases where we must follow a declaration
8519
8520             else
8521                if Nkind (Decl) not in N_Declaration
8522                  and then Nkind (Decl) not in N_Later_Decl_Item
8523                  and then Nkind (Decl) not in N_Generic_Declaration
8524                then
8525                   Error_Pragma
8526                     ("pragma% misplaced, " &
8527                      "must immediately follow a declaration");
8528
8529                else
8530                   Set_Obsolescent (Defining_Entity (Decl));
8531                   return;
8532                end if;
8533             end if;
8534          end Obsolescent;
8535
8536          -----------------
8537          -- No_Run_Time --
8538          -----------------
8539
8540          --  pragma No_Run_Time
8541
8542          --  Note: this pragma is retained for backwards compatibiltiy.
8543          --  See body of Rtsfind for full details on its handling.
8544
8545          when Pragma_No_Run_Time =>
8546             GNAT_Pragma;
8547             Check_Valid_Configuration_Pragma;
8548             Check_Arg_Count (0);
8549
8550             No_Run_Time_Mode           := True;
8551             Configurable_Run_Time_Mode := True;
8552
8553             declare
8554                Word32 : constant Boolean := Ttypes.System_Word_Size = 32;
8555             begin
8556                if Word32 then
8557                   Duration_32_Bits_On_Target := True;
8558                end if;
8559             end;
8560
8561             Set_Restriction (No_Finalization, N);
8562             Set_Restriction (No_Exception_Handlers, N);
8563             Set_Restriction (Max_Tasks, N, 0);
8564             Set_Restriction (No_Tasking, N);
8565
8566          -----------------------
8567          -- Normalize_Scalars --
8568          -----------------------
8569
8570          --  pragma Normalize_Scalars;
8571
8572          when Pragma_Normalize_Scalars =>
8573             Check_Ada_83_Warning;
8574             Check_Arg_Count (0);
8575             Check_Valid_Configuration_Pragma;
8576             Normalize_Scalars := True;
8577             Init_Or_Norm_Scalars := True;
8578
8579          --------------
8580          -- Optimize --
8581          --------------
8582
8583          --  pragma Optimize (Time | Space);
8584
8585          --  The actual check for optimize is done in Gigi. Note that this
8586          --  pragma does not actually change the optimization setting, it
8587          --  simply checks that it is consistent with the pragma.
8588
8589          when Pragma_Optimize =>
8590             Check_No_Identifiers;
8591             Check_Arg_Count (1);
8592             Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
8593
8594          ----------
8595          -- Pack --
8596          ----------
8597
8598          --  pragma Pack (first_subtype_LOCAL_NAME);
8599
8600          when Pragma_Pack => Pack : declare
8601             Assoc   : constant Node_Id := Arg1;
8602             Type_Id : Node_Id;
8603             Typ     : Entity_Id;
8604
8605          begin
8606             Check_No_Identifiers;
8607             Check_Arg_Count (1);
8608             Check_Arg_Is_Local_Name (Arg1);
8609
8610             Type_Id := Expression (Assoc);
8611             Find_Type (Type_Id);
8612             Typ := Entity (Type_Id);
8613
8614             if Typ = Any_Type
8615               or else Rep_Item_Too_Early (Typ, N)
8616             then
8617                return;
8618             else
8619                Typ := Underlying_Type (Typ);
8620             end if;
8621
8622             if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
8623                Error_Pragma ("pragma% must specify array or record type");
8624             end if;
8625
8626             Check_First_Subtype (Arg1);
8627
8628             if Has_Pragma_Pack (Typ) then
8629                Error_Pragma ("duplicate pragma%, only one allowed");
8630
8631             --  Array type
8632
8633             elsif Is_Array_Type (Typ) then
8634
8635                --  Pack not allowed for aliased or atomic components
8636
8637                if Has_Aliased_Components (Base_Type (Typ)) then
8638                   Error_Pragma
8639                     ("pragma% ignored, cannot pack aliased components?");
8640
8641                elsif Has_Atomic_Components (Typ)
8642                  or else Is_Atomic (Component_Type (Typ))
8643                then
8644                   Error_Pragma
8645                     ("?pragma% ignored, cannot pack atomic components");
8646                end if;
8647
8648                --  If we had an explicit component size given, then we do not
8649                --  let Pack override this given size. We also give a warning
8650                --  that Pack is being ignored unless we can tell for sure that
8651                --  the Pack would not have had any effect anyway.
8652
8653                if Has_Component_Size_Clause (Typ) then
8654                   if Known_Static_RM_Size (Component_Type (Typ))
8655                     and then
8656                       RM_Size (Component_Type (Typ)) = Component_Size (Typ)
8657                   then
8658                      null;
8659                   else
8660                      Error_Pragma
8661                        ("?pragma% ignored, explicit component size given");
8662                   end if;
8663
8664                --  If no prior array component size given, Pack is effective
8665
8666                else
8667                   if not Rep_Item_Too_Late (Typ, N) then
8668                      if VM_Target = No_VM then
8669                         Set_Is_Packed (Base_Type (Typ));
8670                      elsif not GNAT_Mode then
8671                         Error_Pragma
8672                           ("?pragma% ignored in this configuration");
8673                      end if;
8674
8675                      Set_Has_Pragma_Pack      (Base_Type (Typ));
8676                      Set_Has_Non_Standard_Rep (Base_Type (Typ));
8677                   end if;
8678                end if;
8679
8680             --  For record types, the pack is always effective
8681
8682             else pragma Assert (Is_Record_Type (Typ));
8683                if not Rep_Item_Too_Late (Typ, N) then
8684                   if VM_Target = No_VM then
8685                      Set_Is_Packed (Base_Type (Typ));
8686                   elsif not GNAT_Mode then
8687                      Error_Pragma ("?pragma% ignored in this configuration");
8688                   end if;
8689
8690                   Set_Has_Pragma_Pack      (Base_Type (Typ));
8691                   Set_Has_Non_Standard_Rep (Base_Type (Typ));
8692                end if;
8693             end if;
8694          end Pack;
8695
8696          ----------
8697          -- Page --
8698          ----------
8699
8700          --  pragma Page;
8701
8702          --  There is nothing to do here, since we did all the processing
8703          --  for this pragma in Par.Prag (so that it works properly even in
8704          --  syntax only mode)
8705
8706          when Pragma_Page =>
8707             null;
8708
8709          -------------
8710          -- Passive --
8711          -------------
8712
8713          --  pragma Passive [(PASSIVE_FORM)];
8714
8715          --   PASSIVE_FORM ::= Semaphore | No
8716
8717          when Pragma_Passive =>
8718             GNAT_Pragma;
8719
8720             if Nkind (Parent (N)) /= N_Task_Definition then
8721                Error_Pragma ("pragma% must be within task definition");
8722             end if;
8723
8724             if Arg_Count /= 0 then
8725                Check_Arg_Count (1);
8726                Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
8727             end if;
8728
8729          ----------------------------------
8730          -- Preelaborable_Initialization --
8731          ----------------------------------
8732
8733          --  pragma Preelaborable_Initialization (DIRECT_NAME);
8734
8735          when Pragma_Preelaborable_Initialization => Preelab_Init : declare
8736             Ent : Entity_Id;
8737
8738          begin
8739             Ada_2005_Pragma;
8740             Check_Arg_Count (1);
8741             Check_No_Identifiers;
8742             Check_Arg_Is_Identifier (Arg1);
8743             Check_Arg_Is_Local_Name (Arg1);
8744             Check_First_Subtype (Arg1);
8745             Ent := Entity (Expression (Arg1));
8746
8747             if not Is_Private_Type (Ent) then
8748                Error_Pragma_Arg
8749                  ("pragma % can only be applied to private type", Arg1);
8750             end if;
8751
8752             Set_Known_To_Have_Preelab_Init (Ent);
8753
8754             if Has_Pragma_Preelab_Init (Ent)
8755               and then Warn_On_Redundant_Constructs
8756             then
8757                Error_Pragma ("?duplicate pragma%!");
8758             else
8759                Set_Has_Pragma_Preelab_Init (Ent);
8760             end if;
8761          end Preelab_Init;
8762
8763          -------------
8764          -- Polling --
8765          -------------
8766
8767          --  pragma Polling (ON | OFF);
8768
8769          when Pragma_Polling =>
8770             GNAT_Pragma;
8771             Check_Arg_Count (1);
8772             Check_No_Identifiers;
8773             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8774             Polling_Required := (Chars (Expression (Arg1)) = Name_On);
8775
8776          --------------------
8777          -- Persistent_BSS --
8778          --------------------
8779
8780          when Pragma_Persistent_BSS => Persistent_BSS :  declare
8781             Decl : Node_Id;
8782             Ent  : Entity_Id;
8783             Prag : Node_Id;
8784
8785          begin
8786             GNAT_Pragma;
8787             Check_At_Most_N_Arguments (1);
8788
8789             --  Case of application to specific object (one argument)
8790
8791             if Arg_Count = 1 then
8792                Check_Arg_Is_Library_Level_Local_Name (Arg1);
8793
8794                if not Is_Entity_Name (Expression (Arg1))
8795                  or else
8796                   (Ekind (Entity (Expression (Arg1))) /= E_Variable
8797                     and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
8798                then
8799                   Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
8800                end if;
8801
8802                Ent := Entity (Expression (Arg1));
8803                Decl := Parent (Ent);
8804
8805                if Rep_Item_Too_Late (Ent, N) then
8806                   return;
8807                end if;
8808
8809                if Present (Expression (Decl)) then
8810                   Error_Pragma_Arg
8811                     ("object for pragma% cannot have initialization", Arg1);
8812                end if;
8813
8814                if not Is_Potentially_Persistent_Type (Etype (Ent)) then
8815                   Error_Pragma_Arg
8816                     ("object type for pragma% is not potentially persistent",
8817                      Arg1);
8818                end if;
8819
8820                Prag :=
8821                  Make_Linker_Section_Pragma
8822                    (Ent, Sloc (N), ".persistent.bss");
8823                Insert_After (N, Prag);
8824                Analyze (Prag);
8825
8826             --  Case of use as configuration pragma with no arguments
8827
8828             else
8829                Check_Valid_Configuration_Pragma;
8830                Persistent_BSS_Mode := True;
8831             end if;
8832          end Persistent_BSS;
8833
8834          ------------------
8835          -- Preelaborate --
8836          ------------------
8837
8838          --  pragma Preelaborate [(library_unit_NAME)];
8839
8840          --  Set the flag Is_Preelaborated of program unit name entity
8841
8842          when Pragma_Preelaborate => Preelaborate : declare
8843             Pa  : constant Node_Id   := Parent (N);
8844             Pk  : constant Node_Kind := Nkind (Pa);
8845             Ent : Entity_Id;
8846
8847          begin
8848             Check_Ada_83_Warning;
8849             Check_Valid_Library_Unit_Pragma;
8850
8851             if Nkind (N) = N_Null_Statement then
8852                return;
8853             end if;
8854
8855             Ent := Find_Lib_Unit_Name;
8856
8857             --  This filters out pragmas inside generic parent then
8858             --  show up inside instantiation
8859
8860             if Present (Ent)
8861               and then not (Pk = N_Package_Specification
8862                               and then Present (Generic_Parent (Pa)))
8863             then
8864                if not Debug_Flag_U then
8865                   Set_Is_Preelaborated (Ent);
8866                   Set_Suppress_Elaboration_Warnings (Ent);
8867                end if;
8868             end if;
8869          end Preelaborate;
8870
8871          ---------------------
8872          -- Preelaborate_05 --
8873          ---------------------
8874
8875          --  pragma Preelaborate_05 [(library_unit_NAME)];
8876
8877          --  This pragma is useable only in GNAT_Mode, where it is used like
8878          --  pragma Preelaborate but it is only effective in Ada 2005 mode
8879          --  (otherwise it is ignored). This is used to implement AI-362 which
8880          --  recategorizes some run-time packages in Ada 2005 mode.
8881
8882          when Pragma_Preelaborate_05 => Preelaborate_05 : declare
8883             Ent : Entity_Id;
8884
8885          begin
8886             GNAT_Pragma;
8887             Check_Valid_Library_Unit_Pragma;
8888
8889             if not GNAT_Mode then
8890                Error_Pragma ("pragma% only available in GNAT mode");
8891             end if;
8892
8893             if Nkind (N) = N_Null_Statement then
8894                return;
8895             end if;
8896
8897             --  This is one of the few cases where we need to test the value of
8898             --  Ada_Version_Explicit rather than Ada_Version (which is always
8899             --  set to Ada_05 in a predefined unit), we need to know the
8900             --  explicit version set to know if this pragma is active.
8901
8902             if Ada_Version_Explicit >= Ada_05 then
8903                Ent := Find_Lib_Unit_Name;
8904                Set_Is_Preelaborated (Ent);
8905                Set_Suppress_Elaboration_Warnings (Ent);
8906             end if;
8907          end Preelaborate_05;
8908
8909          --------------
8910          -- Priority --
8911          --------------
8912
8913          --  pragma Priority (EXPRESSION);
8914
8915          when Pragma_Priority => Priority : declare
8916             P   : constant Node_Id := Parent (N);
8917             Arg : Node_Id;
8918
8919          begin
8920             Check_No_Identifiers;
8921             Check_Arg_Count (1);
8922
8923             --  Subprogram case
8924
8925             if Nkind (P) = N_Subprogram_Body then
8926                Check_In_Main_Program;
8927
8928                Arg := Expression (Arg1);
8929                Analyze_And_Resolve (Arg, Standard_Integer);
8930
8931                --  Must be static
8932
8933                if not Is_Static_Expression (Arg) then
8934                   Flag_Non_Static_Expr
8935                     ("main subprogram priority is not static!", Arg);
8936                   raise Pragma_Exit;
8937
8938                --  If constraint error, then we already signalled an error
8939
8940                elsif Raises_Constraint_Error (Arg) then
8941                   null;
8942
8943                --  Otherwise check in range
8944
8945                else
8946                   declare
8947                      Val : constant Uint := Expr_Value (Arg);
8948
8949                   begin
8950                      if Val < 0
8951                        or else Val > Expr_Value (Expression
8952                                        (Parent (RTE (RE_Max_Priority))))
8953                      then
8954                         Error_Pragma_Arg
8955                           ("main subprogram priority is out of range", Arg1);
8956                      end if;
8957                   end;
8958                end if;
8959
8960                Set_Main_Priority
8961                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8962
8963                --  Load an arbitrary entity from System.Tasking to make sure
8964                --  this package is implicitly with'ed, since we need to have
8965                --  the tasking run-time active for the pragma Priority to have
8966                --  any effect.
8967
8968                declare
8969                   Discard : Entity_Id;
8970                   pragma Warnings (Off, Discard);
8971                begin
8972                   Discard := RTE (RE_Task_List);
8973                end;
8974
8975             --  Task or Protected, must be of type Integer
8976
8977             elsif Nkind (P) = N_Protected_Definition
8978                     or else
8979                   Nkind (P) = N_Task_Definition
8980             then
8981                Arg := Expression (Arg1);
8982
8983                --  The expression must be analyzed in the special manner
8984                --  described in "Handling of Default and Per-Object
8985                --  Expressions" in sem.ads.
8986
8987                Analyze_Per_Use_Expression (Arg, Standard_Integer);
8988
8989                if not Is_Static_Expression (Arg) then
8990                   Check_Restriction (Static_Priorities, Arg);
8991                end if;
8992
8993             --  Anything else is incorrect
8994
8995             else
8996                Pragma_Misplaced;
8997             end if;
8998
8999             if Has_Priority_Pragma (P) then
9000                Error_Pragma ("duplicate pragma% not allowed");
9001             else
9002                Set_Has_Priority_Pragma (P, True);
9003
9004                if Nkind (P) = N_Protected_Definition
9005                     or else
9006                   Nkind (P) = N_Task_Definition
9007                then
9008                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9009                   --  exp_ch9 should use this ???
9010                end if;
9011             end if;
9012          end Priority;
9013
9014          -----------------------------------
9015          -- Priority_Specific_Dispatching --
9016          -----------------------------------
9017
9018          --  pragma Priority_Specific_Dispatching (
9019          --    policy_IDENTIFIER,
9020          --    first_priority_EXPRESSION,
9021          --    last_priority_EXPRESSION);
9022
9023          when Pragma_Priority_Specific_Dispatching =>
9024          Priority_Specific_Dispatching : declare
9025             Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
9026             --  This is the entity System.Any_Priority;
9027
9028             DP          : Character;
9029             Lower_Bound : Node_Id;
9030             Upper_Bound : Node_Id;
9031             Lower_Val   : Uint;
9032             Upper_Val   : Uint;
9033
9034          begin
9035             Ada_2005_Pragma;
9036             Check_Arg_Count (3);
9037             Check_No_Identifiers;
9038             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9039             Check_Valid_Configuration_Pragma;
9040             Get_Name_String (Chars (Expression (Arg1)));
9041             DP := Fold_Upper (Name_Buffer (1));
9042
9043             Lower_Bound := Expression (Arg2);
9044             Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
9045             Lower_Val := Expr_Value (Lower_Bound);
9046
9047             Upper_Bound := Expression (Arg3);
9048             Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
9049             Upper_Val := Expr_Value (Upper_Bound);
9050
9051             --  It is not allowed to use Task_Dispatching_Policy and
9052             --  Priority_Specific_Dispatching in the same partition.
9053
9054             if Task_Dispatching_Policy /= ' ' then
9055                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9056                Error_Pragma
9057                  ("pragma% incompatible with Task_Dispatching_Policy#");
9058
9059             --  Check lower bound in range
9060
9061             elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
9062                     or else
9063                   Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
9064             then
9065                Error_Pragma_Arg
9066                  ("first_priority is out of range", Arg2);
9067
9068             --  Check upper bound in range
9069
9070             elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
9071                     or else
9072                   Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
9073             then
9074                Error_Pragma_Arg
9075                  ("last_priority is out of range", Arg3);
9076
9077             --  Check that the priority range is valid
9078
9079             elsif Lower_Val > Upper_Val then
9080                Error_Pragma
9081                  ("last_priority_expression must be greater than" &
9082                   " or equal to first_priority_expression");
9083
9084             --  Store the new policy, but always preserve System_Location since
9085             --  we like the error message with the run-time name.
9086
9087             else
9088                --  Check overlapping in the priority ranges specified in other
9089                --  Priority_Specific_Dispatching pragmas within the same
9090                --  partition. We can only check those we know about!
9091
9092                for J in
9093                   Specific_Dispatching.First .. Specific_Dispatching.Last
9094                loop
9095                   if Specific_Dispatching.Table (J).First_Priority in
9096                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
9097                   or else Specific_Dispatching.Table (J).Last_Priority in
9098                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
9099                   then
9100                      Error_Msg_Sloc :=
9101                        Specific_Dispatching.Table (J).Pragma_Loc;
9102                         Error_Pragma
9103                           ("priority range overlaps with "
9104                            & "Priority_Specific_Dispatching#");
9105                   end if;
9106                end loop;
9107
9108                --  The use of Priority_Specific_Dispatching is incompatible
9109                --  with Task_Dispatching_Policy.
9110
9111                if Task_Dispatching_Policy /= ' ' then
9112                   Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9113                      Error_Pragma
9114                        ("Priority_Specific_Dispatching incompatible "
9115                         & "with Task_Dispatching_Policy#");
9116                end if;
9117
9118                --  The use of Priority_Specific_Dispatching forces ceiling
9119                --  locking policy.
9120
9121                if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
9122                   Error_Msg_Sloc := Locking_Policy_Sloc;
9123                      Error_Pragma
9124                        ("Priority_Specific_Dispatching incompatible "
9125                         & "with Locking_Policy#");
9126
9127                --  Set the Ceiling_Locking policy, but preserve System_Location
9128                --  since we like the error message with the run time name.
9129
9130                else
9131                   Locking_Policy := 'C';
9132
9133                   if Locking_Policy_Sloc /= System_Location then
9134                      Locking_Policy_Sloc := Loc;
9135                   end if;
9136                end if;
9137
9138                --  Add entry in the table
9139
9140                Specific_Dispatching.Append
9141                     ((Dispatching_Policy => DP,
9142                       First_Priority     => UI_To_Int (Lower_Val),
9143                       Last_Priority      => UI_To_Int (Upper_Val),
9144                       Pragma_Loc         => Loc));
9145             end if;
9146          end Priority_Specific_Dispatching;
9147
9148          -------------
9149          -- Profile --
9150          -------------
9151
9152          --  pragma Profile (profile_IDENTIFIER);
9153
9154          --  profile_IDENTIFIER => Protected | Ravenscar
9155
9156          when Pragma_Profile =>
9157             Ada_2005_Pragma;
9158             Check_Arg_Count (1);
9159             Check_Valid_Configuration_Pragma;
9160             Check_No_Identifiers;
9161
9162             declare
9163                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
9164             begin
9165                if Chars (Argx) = Name_Ravenscar then
9166                   Set_Ravenscar_Profile (N);
9167                elsif Chars (Argx) = Name_Restricted then
9168                   Set_Profile_Restrictions (Restricted, N, Warn => False);
9169                else
9170                   Error_Pragma_Arg ("& is not a valid profile", Argx);
9171                end if;
9172             end;
9173
9174          ----------------------
9175          -- Profile_Warnings --
9176          ----------------------
9177
9178          --  pragma Profile_Warnings (profile_IDENTIFIER);
9179
9180          --  profile_IDENTIFIER => Protected | Ravenscar
9181
9182          when Pragma_Profile_Warnings =>
9183             GNAT_Pragma;
9184             Check_Arg_Count (1);
9185             Check_Valid_Configuration_Pragma;
9186             Check_No_Identifiers;
9187
9188             declare
9189                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
9190             begin
9191                if Chars (Argx) = Name_Ravenscar then
9192                   Set_Profile_Restrictions (Ravenscar, N, Warn => True);
9193                elsif Chars (Argx) = Name_Restricted then
9194                   Set_Profile_Restrictions (Restricted, N, Warn => True);
9195                else
9196                   Error_Pragma_Arg ("& is not a valid profile", Argx);
9197                end if;
9198             end;
9199
9200          --------------------------
9201          -- Propagate_Exceptions --
9202          --------------------------
9203
9204          --  pragma Propagate_Exceptions;
9205
9206          --  Note: this pragma is obsolete and has no effect
9207
9208          when Pragma_Propagate_Exceptions =>
9209             GNAT_Pragma;
9210             Check_Arg_Count (0);
9211
9212             if In_Extended_Main_Source_Unit (N) then
9213                Propagate_Exceptions := True;
9214             end if;
9215
9216          ------------------
9217          -- Psect_Object --
9218          ------------------
9219
9220          --  pragma Psect_Object (
9221          --        [Internal =>] LOCAL_NAME,
9222          --     [, [External =>] EXTERNAL_SYMBOL]
9223          --     [, [Size     =>] EXTERNAL_SYMBOL]);
9224
9225          when Pragma_Psect_Object | Pragma_Common_Object =>
9226          Psect_Object : declare
9227             Args  : Args_List (1 .. 3);
9228             Names : constant Name_List (1 .. 3) := (
9229                       Name_Internal,
9230                       Name_External,
9231                       Name_Size);
9232
9233             Internal : Node_Id renames Args (1);
9234             External : Node_Id renames Args (2);
9235             Size     : Node_Id renames Args (3);
9236
9237             Def_Id : Entity_Id;
9238
9239             procedure Check_Too_Long (Arg : Node_Id);
9240             --  Posts message if the argument is an identifier with more
9241             --  than 31 characters, or a string literal with more than
9242             --  31 characters, and we are operating under VMS
9243
9244             --------------------
9245             -- Check_Too_Long --
9246             --------------------
9247
9248             procedure Check_Too_Long (Arg : Node_Id) is
9249                X : constant Node_Id := Original_Node (Arg);
9250
9251             begin
9252                if Nkind (X) /= N_String_Literal
9253                     and then
9254                   Nkind (X) /= N_Identifier
9255                then
9256                   Error_Pragma_Arg
9257                     ("inappropriate argument for pragma %", Arg);
9258                end if;
9259
9260                if OpenVMS_On_Target then
9261                   if (Nkind (X) = N_String_Literal
9262                        and then String_Length (Strval (X)) > 31)
9263                     or else
9264                      (Nkind (X) = N_Identifier
9265                        and then Length_Of_Name (Chars (X)) > 31)
9266                   then
9267                      Error_Pragma_Arg
9268                        ("argument for pragma % is longer than 31 characters",
9269                         Arg);
9270                   end if;
9271                end if;
9272             end Check_Too_Long;
9273
9274          --  Start of processing for Common_Object/Psect_Object
9275
9276          begin
9277             GNAT_Pragma;
9278             Gather_Associations (Names, Args);
9279             Process_Extended_Import_Export_Internal_Arg (Internal);
9280
9281             Def_Id := Entity (Internal);
9282
9283             if Ekind (Def_Id) /= E_Constant
9284               and then Ekind (Def_Id) /= E_Variable
9285             then
9286                Error_Pragma_Arg
9287                  ("pragma% must designate an object", Internal);
9288             end if;
9289
9290             Check_Too_Long (Internal);
9291
9292             if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
9293                Error_Pragma_Arg
9294                  ("cannot use pragma% for imported/exported object",
9295                   Internal);
9296             end if;
9297
9298             if Is_Concurrent_Type (Etype (Internal)) then
9299                Error_Pragma_Arg
9300                  ("cannot specify pragma % for task/protected object",
9301                   Internal);
9302             end if;
9303
9304             if Has_Rep_Pragma (Def_Id, Name_Common_Object)
9305                  or else
9306                Has_Rep_Pragma (Def_Id, Name_Psect_Object)
9307             then
9308                Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
9309             end if;
9310
9311             if Ekind (Def_Id) = E_Constant then
9312                Error_Pragma_Arg
9313                  ("cannot specify pragma % for a constant", Internal);
9314             end if;
9315
9316             if Is_Record_Type (Etype (Internal)) then
9317                declare
9318                   Ent  : Entity_Id;
9319                   Decl : Entity_Id;
9320
9321                begin
9322                   Ent := First_Entity (Etype (Internal));
9323                   while Present (Ent) loop
9324                      Decl := Declaration_Node (Ent);
9325
9326                      if Ekind (Ent) = E_Component
9327                        and then Nkind (Decl) = N_Component_Declaration
9328                        and then Present (Expression (Decl))
9329                        and then Warn_On_Export_Import
9330                      then
9331                         Error_Msg_N
9332                           ("?object for pragma % has defaults", Internal);
9333                         exit;
9334
9335                      else
9336                         Next_Entity (Ent);
9337                      end if;
9338                   end loop;
9339                end;
9340             end if;
9341
9342             if Present (Size) then
9343                Check_Too_Long (Size);
9344             end if;
9345
9346             if Present (External) then
9347                Check_Arg_Is_External_Name (External);
9348                Check_Too_Long (External);
9349             end if;
9350
9351             --  If all error tests pass, link pragma on to the rep item chain
9352
9353             Record_Rep_Item (Def_Id, N);
9354          end Psect_Object;
9355
9356          ----------
9357          -- Pure --
9358          ----------
9359
9360          --  pragma Pure [(library_unit_NAME)];
9361
9362          when Pragma_Pure => Pure : declare
9363             Ent : Entity_Id;
9364
9365          begin
9366             Check_Ada_83_Warning;
9367             Check_Valid_Library_Unit_Pragma;
9368
9369             if Nkind (N) = N_Null_Statement then
9370                return;
9371             end if;
9372
9373             Ent := Find_Lib_Unit_Name;
9374             Set_Is_Pure (Ent);
9375             Set_Has_Pragma_Pure (Ent);
9376             Set_Suppress_Elaboration_Warnings (Ent);
9377          end Pure;
9378
9379          -------------
9380          -- Pure_05 --
9381          -------------
9382
9383          --  pragma Pure_05 [(library_unit_NAME)];
9384
9385          --  This pragma is useable only in GNAT_Mode, where it is used like
9386          --  pragma Pure but it is only effective in Ada 2005 mode (otherwise
9387          --  it is ignored). It may be used after a pragma Preelaborate, in
9388          --  which case it overrides the effect of the pragma Preelaborate.
9389          --  This is used to implement AI-362 which recategorizes some run-time
9390          --  packages in Ada 2005 mode.
9391
9392          when Pragma_Pure_05 => Pure_05 : declare
9393             Ent : Entity_Id;
9394
9395          begin
9396             GNAT_Pragma;
9397             Check_Valid_Library_Unit_Pragma;
9398
9399             if not GNAT_Mode then
9400                Error_Pragma ("pragma% only available in GNAT mode");
9401             end if;
9402             if Nkind (N) = N_Null_Statement then
9403                return;
9404             end if;
9405
9406             --  This is one of the few cases where we need to test the value of
9407             --  Ada_Version_Explicit rather than Ada_Version (which is always
9408             --  set to Ada_05 in a predefined unit), we need to know the
9409             --  explicit version set to know if this pragma is active.
9410
9411             if Ada_Version_Explicit >= Ada_05 then
9412                Ent := Find_Lib_Unit_Name;
9413                Set_Is_Preelaborated (Ent, False);
9414                Set_Is_Pure (Ent);
9415                Set_Suppress_Elaboration_Warnings (Ent);
9416             end if;
9417          end Pure_05;
9418
9419          -------------------
9420          -- Pure_Function --
9421          -------------------
9422
9423          --  pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
9424
9425          when Pragma_Pure_Function => Pure_Function : declare
9426             E_Id      : Node_Id;
9427             E         : Entity_Id;
9428             Def_Id    : Entity_Id;
9429             Effective : Boolean := False;
9430
9431          begin
9432             GNAT_Pragma;
9433             Check_Arg_Count (1);
9434             Check_Optional_Identifier (Arg1, Name_Entity);
9435             Check_Arg_Is_Local_Name (Arg1);
9436             E_Id := Expression (Arg1);
9437
9438             if Error_Posted (E_Id) then
9439                return;
9440             end if;
9441
9442             --  Loop through homonyms (overloadings) of referenced entity
9443
9444             E := Entity (E_Id);
9445
9446             if Present (E) then
9447                loop
9448                   Def_Id := Get_Base_Subprogram (E);
9449
9450                   if Ekind (Def_Id) /= E_Function
9451                     and then Ekind (Def_Id) /= E_Generic_Function
9452                     and then Ekind (Def_Id) /= E_Operator
9453                   then
9454                      Error_Pragma_Arg
9455                        ("pragma% requires a function name", Arg1);
9456                   end if;
9457
9458                   Set_Is_Pure (Def_Id);
9459
9460                   if not Has_Pragma_Pure_Function (Def_Id) then
9461                      Set_Has_Pragma_Pure_Function (Def_Id);
9462                      Effective := True;
9463                   end if;
9464
9465                   E := Homonym (E);
9466                   exit when No (E) or else Scope (E) /= Current_Scope;
9467                end loop;
9468
9469                if not Effective
9470                  and then Warn_On_Redundant_Constructs
9471                then
9472                   Error_Msg_NE ("pragma Pure_Function on& is redundant?",
9473                     N, Entity (E_Id));
9474                end if;
9475             end if;
9476          end Pure_Function;
9477
9478          --------------------
9479          -- Queuing_Policy --
9480          --------------------
9481
9482          --  pragma Queuing_Policy (policy_IDENTIFIER);
9483
9484          when Pragma_Queuing_Policy => declare
9485             QP : Character;
9486
9487          begin
9488             Check_Ada_83_Warning;
9489             Check_Arg_Count (1);
9490             Check_No_Identifiers;
9491             Check_Arg_Is_Queuing_Policy (Arg1);
9492             Check_Valid_Configuration_Pragma;
9493             Get_Name_String (Chars (Expression (Arg1)));
9494             QP := Fold_Upper (Name_Buffer (1));
9495
9496             if Queuing_Policy /= ' '
9497               and then Queuing_Policy /= QP
9498             then
9499                Error_Msg_Sloc := Queuing_Policy_Sloc;
9500                Error_Pragma ("queuing policy incompatible with policy#");
9501
9502             --  Set new policy, but always preserve System_Location since
9503             --  we like the error message with the run time name.
9504
9505             else
9506                Queuing_Policy := QP;
9507
9508                if Queuing_Policy_Sloc /= System_Location then
9509                   Queuing_Policy_Sloc := Loc;
9510                end if;
9511             end if;
9512          end;
9513
9514          ---------------------------
9515          -- Remote_Call_Interface --
9516          ---------------------------
9517
9518          --  pragma Remote_Call_Interface [(library_unit_NAME)];
9519
9520          when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
9521             Cunit_Node : Node_Id;
9522             Cunit_Ent  : Entity_Id;
9523             K          : Node_Kind;
9524
9525          begin
9526             Check_Ada_83_Warning;
9527             Check_Valid_Library_Unit_Pragma;
9528
9529             if Nkind (N) = N_Null_Statement then
9530                return;
9531             end if;
9532
9533             Cunit_Node := Cunit (Current_Sem_Unit);
9534             K          := Nkind (Unit (Cunit_Node));
9535             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
9536
9537             if K = N_Package_Declaration
9538               or else K = N_Generic_Package_Declaration
9539               or else K = N_Subprogram_Declaration
9540               or else K = N_Generic_Subprogram_Declaration
9541               or else (K = N_Subprogram_Body
9542                          and then Acts_As_Spec (Unit (Cunit_Node)))
9543             then
9544                null;
9545             else
9546                Error_Pragma (
9547                  "pragma% must apply to package or subprogram declaration");
9548             end if;
9549
9550             Set_Is_Remote_Call_Interface (Cunit_Ent);
9551          end Remote_Call_Interface;
9552
9553          ------------------
9554          -- Remote_Types --
9555          ------------------
9556
9557          --  pragma Remote_Types [(library_unit_NAME)];
9558
9559          when Pragma_Remote_Types => Remote_Types : declare
9560             Cunit_Node : Node_Id;
9561             Cunit_Ent  : Entity_Id;
9562
9563          begin
9564             Check_Ada_83_Warning;
9565             Check_Valid_Library_Unit_Pragma;
9566
9567             if Nkind (N) = N_Null_Statement then
9568                return;
9569             end if;
9570
9571             Cunit_Node := Cunit (Current_Sem_Unit);
9572             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
9573
9574             if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
9575               and then
9576               Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
9577             then
9578                Error_Pragma (
9579                  "pragma% can only apply to a package declaration");
9580             end if;
9581
9582             Set_Is_Remote_Types (Cunit_Ent);
9583          end Remote_Types;
9584
9585          ---------------
9586          -- Ravenscar --
9587          ---------------
9588
9589          --  pragma Ravenscar;
9590
9591          when Pragma_Ravenscar =>
9592             GNAT_Pragma;
9593             Check_Arg_Count (0);
9594             Check_Valid_Configuration_Pragma;
9595             Set_Ravenscar_Profile (N);
9596
9597             if Warn_On_Obsolescent_Feature then
9598                Error_Msg_N
9599                  ("pragma Ravenscar is an obsolescent feature?", N);
9600                Error_Msg_N
9601                  ("|use pragma Profile (Ravenscar) instead", N);
9602             end if;
9603
9604          -------------------------
9605          -- Restricted_Run_Time --
9606          -------------------------
9607
9608          --  pragma Restricted_Run_Time;
9609
9610          when Pragma_Restricted_Run_Time =>
9611             GNAT_Pragma;
9612             Check_Arg_Count (0);
9613             Check_Valid_Configuration_Pragma;
9614             Set_Profile_Restrictions (Restricted, N, Warn => False);
9615
9616             if Warn_On_Obsolescent_Feature then
9617                Error_Msg_N
9618                  ("pragma Restricted_Run_Time is an obsolescent feature?", N);
9619                Error_Msg_N
9620                  ("|use pragma Profile (Restricted) instead", N);
9621             end if;
9622
9623          ------------------
9624          -- Restrictions --
9625          ------------------
9626
9627          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
9628
9629          --  RESTRICTION ::=
9630          --    restriction_IDENTIFIER
9631          --  | restriction_parameter_IDENTIFIER => EXPRESSION
9632
9633          when Pragma_Restrictions =>
9634             Process_Restrictions_Or_Restriction_Warnings (Warn => False);
9635
9636          --------------------------
9637          -- Restriction_Warnings --
9638          --------------------------
9639
9640          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
9641
9642          --  RESTRICTION ::=
9643          --    restriction_IDENTIFIER
9644          --  | restriction_parameter_IDENTIFIER => EXPRESSION
9645
9646          when Pragma_Restriction_Warnings =>
9647             Process_Restrictions_Or_Restriction_Warnings (Warn => True);
9648
9649          ----------------
9650          -- Reviewable --
9651          ----------------
9652
9653          --  pragma Reviewable;
9654
9655          when Pragma_Reviewable =>
9656             Check_Ada_83_Warning;
9657             Check_Arg_Count (0);
9658             rv;
9659
9660          -------------------
9661          -- Share_Generic --
9662          -------------------
9663
9664          --  pragma Share_Generic (NAME {, NAME});
9665
9666          when Pragma_Share_Generic =>
9667             GNAT_Pragma;
9668             Process_Generic_List;
9669
9670          ------------
9671          -- Shared --
9672          ------------
9673
9674          --  pragma Shared (LOCAL_NAME);
9675
9676          when Pragma_Shared =>
9677             GNAT_Pragma;
9678             Process_Atomic_Shared_Volatile;
9679
9680          --------------------
9681          -- Shared_Passive --
9682          --------------------
9683
9684          --  pragma Shared_Passive [(library_unit_NAME)];
9685
9686          --  Set the flag Is_Shared_Passive of program unit name entity
9687
9688          when Pragma_Shared_Passive => Shared_Passive : declare
9689             Cunit_Node : Node_Id;
9690             Cunit_Ent  : Entity_Id;
9691
9692          begin
9693             Check_Ada_83_Warning;
9694             Check_Valid_Library_Unit_Pragma;
9695
9696             if Nkind (N) = N_Null_Statement then
9697                return;
9698             end if;
9699
9700             Cunit_Node := Cunit (Current_Sem_Unit);
9701             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
9702
9703             if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
9704               and then
9705               Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
9706             then
9707                Error_Pragma (
9708                  "pragma% can only apply to a package declaration");
9709             end if;
9710
9711             Set_Is_Shared_Passive (Cunit_Ent);
9712          end Shared_Passive;
9713
9714          ----------------------
9715          -- Source_File_Name --
9716          ----------------------
9717
9718          --  There are five forms for this pragma:
9719
9720          --  pragma Source_File_Name (
9721          --    [UNIT_NAME      =>] unit_NAME,
9722          --     BODY_FILE_NAME =>  STRING_LITERAL
9723          --    [, [INDEX =>] INTEGER_LITERAL]);
9724
9725          --  pragma Source_File_Name (
9726          --    [UNIT_NAME      =>] unit_NAME,
9727          --     SPEC_FILE_NAME =>  STRING_LITERAL
9728          --    [, [INDEX =>] INTEGER_LITERAL]);
9729
9730          --  pragma Source_File_Name (
9731          --     BODY_FILE_NAME  => STRING_LITERAL
9732          --  [, DOT_REPLACEMENT => STRING_LITERAL]
9733          --  [, CASING          => CASING_SPEC]);
9734
9735          --  pragma Source_File_Name (
9736          --     SPEC_FILE_NAME  => STRING_LITERAL
9737          --  [, DOT_REPLACEMENT => STRING_LITERAL]
9738          --  [, CASING          => CASING_SPEC]);
9739
9740          --  pragma Source_File_Name (
9741          --     SUBUNIT_FILE_NAME  => STRING_LITERAL
9742          --  [, DOT_REPLACEMENT    => STRING_LITERAL]
9743          --  [, CASING             => CASING_SPEC]);
9744
9745          --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
9746
9747          --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
9748          --  Source_File_Name (SFN), however their usage is exclusive:
9749          --  SFN can only be used when no project file is used, while
9750          --  SFNP can only be used when a project file is used.
9751
9752          --  No processing here. Processing was completed during parsing,
9753          --  since we need to have file names set as early as possible.
9754          --  Units are loaded well before semantic processing starts.
9755
9756          --  The only processing we defer to this point is the check
9757          --  for correct placement.
9758
9759          when Pragma_Source_File_Name =>
9760             GNAT_Pragma;
9761             Check_Valid_Configuration_Pragma;
9762
9763          ------------------------------
9764          -- Source_File_Name_Project --
9765          ------------------------------
9766
9767          --  See Source_File_Name for syntax
9768
9769          --  No processing here. Processing was completed during parsing,
9770          --  since we need to have file names set as early as possible.
9771          --  Units are loaded well before semantic processing starts.
9772
9773          --  The only processing we defer to this point is the check
9774          --  for correct placement.
9775
9776          when Pragma_Source_File_Name_Project =>
9777             GNAT_Pragma;
9778             Check_Valid_Configuration_Pragma;
9779
9780             --  Check that a pragma Source_File_Name_Project is used only
9781             --  in a configuration pragmas file.
9782
9783             --  Pragmas Source_File_Name_Project should only be generated
9784             --  by the Project Manager in configuration pragmas files.
9785
9786             --  This is really an ugly test. It seems to depend on some
9787             --  accidental and undocumented property. At the very least
9788             --  it needs to be documented, but it would be better to have
9789             --  a clean way of testing if we are in a configuration file???
9790
9791             if Present (Parent (N)) then
9792                Error_Pragma
9793                  ("pragma% can only appear in a configuration pragmas file");
9794             end if;
9795
9796          ----------------------
9797          -- Source_Reference --
9798          ----------------------
9799
9800          --  pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
9801
9802          --  Nothing to do, all processing completed in Par.Prag, since we
9803          --  need the information for possible parser messages that are output
9804
9805          when Pragma_Source_Reference =>
9806             GNAT_Pragma;
9807
9808          --------------------------------
9809          -- Static_Elaboration_Desired --
9810          --------------------------------
9811
9812          --  pragma Static_Elaboration_Desired (DIRECT_NAME);
9813
9814          when Pragma_Static_Elaboration_Desired =>
9815             GNAT_Pragma;
9816             Check_At_Most_N_Arguments (1);
9817
9818             if Is_Compilation_Unit (Current_Scope)
9819               and then Ekind (Current_Scope) = E_Package
9820             then
9821                Set_Static_Elaboration_Desired (Current_Scope, True);
9822             else
9823                Error_Pragma ("pragma% must apply to a library-level package");
9824             end if;
9825
9826          ------------------
9827          -- Storage_Size --
9828          ------------------
9829
9830          --  pragma Storage_Size (EXPRESSION);
9831
9832          when Pragma_Storage_Size => Storage_Size : declare
9833             P   : constant Node_Id := Parent (N);
9834             Arg : Node_Id;
9835
9836          begin
9837             Check_No_Identifiers;
9838             Check_Arg_Count (1);
9839
9840             --  The expression must be analyzed in the special manner
9841             --  described in "Handling of Default Expressions" in sem.ads.
9842
9843             --  Set In_Default_Expression for per-object case ???
9844
9845             Arg := Expression (Arg1);
9846             Analyze_Per_Use_Expression (Arg, Any_Integer);
9847
9848             if not Is_Static_Expression (Arg) then
9849                Check_Restriction (Static_Storage_Size, Arg);
9850             end if;
9851
9852             if Nkind (P) /= N_Task_Definition then
9853                Pragma_Misplaced;
9854                return;
9855
9856             else
9857                if Has_Storage_Size_Pragma (P) then
9858                   Error_Pragma ("duplicate pragma% not allowed");
9859                else
9860                   Set_Has_Storage_Size_Pragma (P, True);
9861                end if;
9862
9863                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9864                --  ???  exp_ch9 should use this!
9865             end if;
9866          end Storage_Size;
9867
9868          ------------------
9869          -- Storage_Unit --
9870          ------------------
9871
9872          --  pragma Storage_Unit (NUMERIC_LITERAL);
9873
9874          --  Only permitted argument is System'Storage_Unit value
9875
9876          when Pragma_Storage_Unit =>
9877             Check_No_Identifiers;
9878             Check_Arg_Count (1);
9879             Check_Arg_Is_Integer_Literal (Arg1);
9880
9881             if Intval (Expression (Arg1)) /=
9882               UI_From_Int (Ttypes.System_Storage_Unit)
9883             then
9884                Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
9885                Error_Pragma_Arg
9886                  ("the only allowed argument for pragma% is ^", Arg1);
9887             end if;
9888
9889          --------------------
9890          -- Stream_Convert --
9891          --------------------
9892
9893          --  pragma Stream_Convert (
9894          --    [Entity =>] type_LOCAL_NAME,
9895          --    [Read   =>] function_NAME,
9896          --    [Write  =>] function NAME);
9897
9898          when Pragma_Stream_Convert => Stream_Convert : declare
9899
9900             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
9901             --  Check that the given argument is the name of a local
9902             --  function of one argument that is not overloaded earlier
9903             --  in the current local scope. A check is also made that the
9904             --  argument is a function with one parameter.
9905
9906             --------------------------------------
9907             -- Check_OK_Stream_Convert_Function --
9908             --------------------------------------
9909
9910             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
9911                Ent : Entity_Id;
9912
9913             begin
9914                Check_Arg_Is_Local_Name (Arg);
9915                Ent := Entity (Expression (Arg));
9916
9917                if Has_Homonym (Ent) then
9918                   Error_Pragma_Arg
9919                     ("argument for pragma% may not be overloaded", Arg);
9920                end if;
9921
9922                if Ekind (Ent) /= E_Function
9923                  or else No (First_Formal (Ent))
9924                  or else Present (Next_Formal (First_Formal (Ent)))
9925                then
9926                   Error_Pragma_Arg
9927                     ("argument for pragma% must be" &
9928                      " function of one argument", Arg);
9929                end if;
9930             end Check_OK_Stream_Convert_Function;
9931
9932          --  Start of procecessing for Stream_Convert
9933
9934          begin
9935             GNAT_Pragma;
9936             Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
9937             Check_Arg_Count (3);
9938             Check_Optional_Identifier (Arg1, Name_Entity);
9939             Check_Optional_Identifier (Arg2, Name_Read);
9940             Check_Optional_Identifier (Arg3, Name_Write);
9941             Check_Arg_Is_Local_Name (Arg1);
9942             Check_OK_Stream_Convert_Function (Arg2);
9943             Check_OK_Stream_Convert_Function (Arg3);
9944
9945             declare
9946                Typ   : constant Entity_Id :=
9947                          Underlying_Type (Entity (Expression (Arg1)));
9948                Read  : constant Entity_Id := Entity (Expression (Arg2));
9949                Write : constant Entity_Id := Entity (Expression (Arg3));
9950
9951             begin
9952                if Etype (Typ) = Any_Type
9953                     or else
9954                   Etype (Read) = Any_Type
9955                     or else
9956                   Etype (Write) = Any_Type
9957                then
9958                   return;
9959                end if;
9960
9961                Check_First_Subtype (Arg1);
9962
9963                if Rep_Item_Too_Early (Typ, N)
9964                     or else
9965                   Rep_Item_Too_Late (Typ, N)
9966                then
9967                   return;
9968                end if;
9969
9970                if Underlying_Type (Etype (Read)) /= Typ then
9971                   Error_Pragma_Arg
9972                     ("incorrect return type for function&", Arg2);
9973                end if;
9974
9975                if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
9976                   Error_Pragma_Arg
9977                     ("incorrect parameter type for function&", Arg3);
9978                end if;
9979
9980                if Underlying_Type (Etype (First_Formal (Read))) /=
9981                   Underlying_Type (Etype (Write))
9982                then
9983                   Error_Pragma_Arg
9984                     ("result type of & does not match Read parameter type",
9985                      Arg3);
9986                end if;
9987             end;
9988          end Stream_Convert;
9989
9990          -------------------------
9991          -- Style_Checks (GNAT) --
9992          -------------------------
9993
9994          --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
9995
9996          --  This is processed by the parser since some of the style
9997          --  checks take place during source scanning and parsing. This
9998          --  means that we don't need to issue error messages here.
9999
10000          when Pragma_Style_Checks => Style_Checks : declare
10001             A  : constant Node_Id   := Expression (Arg1);
10002             S  : String_Id;
10003             C  : Char_Code;
10004
10005          begin
10006             GNAT_Pragma;
10007             Check_No_Identifiers;
10008
10009             --  Two argument form
10010
10011             if Arg_Count = 2 then
10012                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10013
10014                declare
10015                   E_Id : Node_Id;
10016                   E    : Entity_Id;
10017
10018                begin
10019                   E_Id := Expression (Arg2);
10020                   Analyze (E_Id);
10021
10022                   if not Is_Entity_Name (E_Id) then
10023                      Error_Pragma_Arg
10024                        ("second argument of pragma% must be entity name",
10025                         Arg2);
10026                   end if;
10027
10028                   E := Entity (E_Id);
10029
10030                   if E = Any_Id then
10031                      return;
10032                   else
10033                      loop
10034                         Set_Suppress_Style_Checks (E,
10035                           (Chars (Expression (Arg1)) = Name_Off));
10036                         exit when No (Homonym (E));
10037                         E := Homonym (E);
10038                      end loop;
10039                   end if;
10040                end;
10041
10042             --  One argument form
10043
10044             else
10045                Check_Arg_Count (1);
10046
10047                if Nkind (A) = N_String_Literal then
10048                   S   := Strval (A);
10049
10050                   declare
10051                      Slen    : constant Natural := Natural (String_Length (S));
10052                      Options : String (1 .. Slen);
10053                      J       : Natural;
10054
10055                   begin
10056                      J := 1;
10057                      loop
10058                         C := Get_String_Char (S, Int (J));
10059                         exit when not In_Character_Range (C);
10060                         Options (J) := Get_Character (C);
10061
10062                         --  If at end of string, set options. As per discussion
10063                         --  above, no need to check for errors, since we issued
10064                         --  them in the parser.
10065
10066                         if J = Slen then
10067                            Set_Style_Check_Options (Options);
10068                            exit;
10069                         end if;
10070
10071                         J := J + 1;
10072                      end loop;
10073                   end;
10074
10075                elsif Nkind (A) = N_Identifier then
10076                   if Chars (A) = Name_All_Checks then
10077                      Set_Default_Style_Check_Options;
10078
10079                   elsif Chars (A) = Name_On then
10080                      Style_Check := True;
10081
10082                   elsif Chars (A) = Name_Off then
10083                      Style_Check := False;
10084                   end if;
10085                end if;
10086             end if;
10087          end Style_Checks;
10088
10089          --------------
10090          -- Subtitle --
10091          --------------
10092
10093          --  pragma Subtitle ([Subtitle =>] STRING_LITERAL);
10094
10095          when Pragma_Subtitle =>
10096             GNAT_Pragma;
10097             Check_Arg_Count (1);
10098             Check_Optional_Identifier (Arg1, Name_Subtitle);
10099             Check_Arg_Is_String_Literal (Arg1);
10100
10101          --------------
10102          -- Suppress --
10103          --------------
10104
10105          --  pragma Suppress (IDENTIFIER [, [On =>] NAME]);
10106
10107          when Pragma_Suppress =>
10108             Process_Suppress_Unsuppress (True);
10109
10110          ------------------
10111          -- Suppress_All --
10112          ------------------
10113
10114          --  pragma Suppress_All;
10115
10116          --  The only check made here is that the pragma appears in the
10117          --  proper place, i.e. following a compilation unit. If indeed
10118          --  it appears in this context, then the parser has already
10119          --  inserted an equivalent pragma Suppress (All_Checks) to get
10120          --  the required effect.
10121
10122          when Pragma_Suppress_All =>
10123             GNAT_Pragma;
10124             Check_Arg_Count (0);
10125
10126             if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
10127               or else not Is_List_Member (N)
10128               or else List_Containing (N) /= Pragmas_After (Parent (N))
10129             then
10130                Error_Pragma
10131                  ("misplaced pragma%, must follow compilation unit");
10132             end if;
10133
10134          -------------------------
10135          -- Suppress_Debug_Info --
10136          -------------------------
10137
10138          --  pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
10139
10140          when Pragma_Suppress_Debug_Info =>
10141             GNAT_Pragma;
10142             Check_Arg_Count (1);
10143             Check_Optional_Identifier (Arg1, Name_Entity);
10144             Check_Arg_Is_Local_Name (Arg1);
10145             Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
10146
10147          ----------------------------------
10148          -- Suppress_Exception_Locations --
10149          ----------------------------------
10150
10151          --  pragma Suppress_Exception_Locations;
10152
10153          when Pragma_Suppress_Exception_Locations =>
10154             GNAT_Pragma;
10155             Check_Arg_Count (0);
10156             Check_Valid_Configuration_Pragma;
10157             Exception_Locations_Suppressed := True;
10158
10159          -----------------------------
10160          -- Suppress_Initialization --
10161          -----------------------------
10162
10163          --  pragma Suppress_Initialization ([Entity =>] type_Name);
10164
10165          when Pragma_Suppress_Initialization => Suppress_Init : declare
10166             E_Id : Node_Id;
10167             E    : Entity_Id;
10168
10169          begin
10170             GNAT_Pragma;
10171             Check_Arg_Count (1);
10172             Check_Optional_Identifier (Arg1, Name_Entity);
10173             Check_Arg_Is_Local_Name (Arg1);
10174
10175             E_Id := Expression (Arg1);
10176
10177             if Etype (E_Id) = Any_Type then
10178                return;
10179             end if;
10180
10181             E := Entity (E_Id);
10182
10183             if Is_Type (E) then
10184                if Is_Incomplete_Or_Private_Type (E) then
10185                   if No (Full_View (Base_Type (E))) then
10186                      Error_Pragma_Arg
10187                        ("argument of pragma% cannot be an incomplete type",
10188                          Arg1);
10189                   else
10190                      Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
10191                   end if;
10192                else
10193                   Set_Suppress_Init_Proc (Base_Type (E));
10194                end if;
10195
10196             else
10197                Error_Pragma_Arg
10198                  ("pragma% requires argument that is a type name", Arg1);
10199             end if;
10200          end Suppress_Init;
10201
10202          -----------------
10203          -- System_Name --
10204          -----------------
10205
10206          --  pragma System_Name (DIRECT_NAME);
10207
10208          --  Syntax check: one argument, which must be the identifier GNAT
10209          --  or the identifier GCC, no other identifiers are acceptable.
10210
10211          when Pragma_System_Name =>
10212             Check_No_Identifiers;
10213             Check_Arg_Count (1);
10214             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
10215
10216          -----------------------------
10217          -- Task_Dispatching_Policy --
10218          -----------------------------
10219
10220          --  pragma Task_Dispatching_Policy (policy_IDENTIFIER);
10221
10222          when Pragma_Task_Dispatching_Policy => declare
10223             DP : Character;
10224
10225          begin
10226             Check_Ada_83_Warning;
10227             Check_Arg_Count (1);
10228             Check_No_Identifiers;
10229             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
10230             Check_Valid_Configuration_Pragma;
10231             Get_Name_String (Chars (Expression (Arg1)));
10232             DP := Fold_Upper (Name_Buffer (1));
10233
10234             if Task_Dispatching_Policy /= ' '
10235               and then Task_Dispatching_Policy /= DP
10236             then
10237                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10238                Error_Pragma
10239                  ("task dispatching policy incompatible with policy#");
10240
10241             --  Set new policy, but always preserve System_Location since
10242             --  we like the error message with the run time name.
10243
10244             else
10245                Task_Dispatching_Policy := DP;
10246
10247                if Task_Dispatching_Policy_Sloc /= System_Location then
10248                   Task_Dispatching_Policy_Sloc := Loc;
10249                end if;
10250             end if;
10251          end;
10252
10253          --------------
10254          -- Task_Info --
10255          --------------
10256
10257          --  pragma Task_Info (EXPRESSION);
10258
10259          when Pragma_Task_Info => Task_Info : declare
10260             P : constant Node_Id := Parent (N);
10261
10262          begin
10263             GNAT_Pragma;
10264
10265             if Nkind (P) /= N_Task_Definition then
10266                Error_Pragma ("pragma% must appear in task definition");
10267             end if;
10268
10269             Check_No_Identifiers;
10270             Check_Arg_Count (1);
10271
10272             Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
10273
10274             if Etype (Expression (Arg1)) = Any_Type then
10275                return;
10276             end if;
10277
10278             if Has_Task_Info_Pragma (P) then
10279                Error_Pragma ("duplicate pragma% not allowed");
10280             else
10281                Set_Has_Task_Info_Pragma (P, True);
10282             end if;
10283          end Task_Info;
10284
10285          ---------------
10286          -- Task_Name --
10287          ---------------
10288
10289          --  pragma Task_Name (string_EXPRESSION);
10290
10291          when Pragma_Task_Name => Task_Name : declare
10292          --  pragma Priority (EXPRESSION);
10293
10294             P   : constant Node_Id := Parent (N);
10295             Arg : Node_Id;
10296
10297          begin
10298             Check_No_Identifiers;
10299             Check_Arg_Count (1);
10300
10301             Arg := Expression (Arg1);
10302             Analyze_And_Resolve (Arg, Standard_String);
10303
10304             if Nkind (P) /= N_Task_Definition then
10305                Pragma_Misplaced;
10306             end if;
10307
10308             if Has_Task_Name_Pragma (P) then
10309                Error_Pragma ("duplicate pragma% not allowed");
10310             else
10311                Set_Has_Task_Name_Pragma (P, True);
10312                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10313             end if;
10314          end Task_Name;
10315
10316          ------------------
10317          -- Task_Storage --
10318          ------------------
10319
10320          --  pragma Task_Storage (
10321          --     [Task_Type =>] LOCAL_NAME,
10322          --     [Top_Guard =>] static_integer_EXPRESSION);
10323
10324          when Pragma_Task_Storage => Task_Storage : declare
10325             Args  : Args_List (1 .. 2);
10326             Names : constant Name_List (1 .. 2) := (
10327                       Name_Task_Type,
10328                       Name_Top_Guard);
10329
10330             Task_Type : Node_Id renames Args (1);
10331             Top_Guard : Node_Id renames Args (2);
10332
10333             Ent : Entity_Id;
10334
10335          begin
10336             GNAT_Pragma;
10337             Gather_Associations (Names, Args);
10338
10339             if No (Task_Type) then
10340                Error_Pragma
10341                  ("missing task_type argument for pragma%");
10342             end if;
10343
10344             Check_Arg_Is_Local_Name (Task_Type);
10345
10346             Ent := Entity (Task_Type);
10347
10348             if not Is_Task_Type (Ent) then
10349                Error_Pragma_Arg
10350                  ("argument for pragma% must be task type", Task_Type);
10351             end if;
10352
10353             if No (Top_Guard) then
10354                Error_Pragma_Arg
10355                  ("pragma% takes two arguments", Task_Type);
10356             else
10357                Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
10358             end if;
10359
10360             Check_First_Subtype (Task_Type);
10361
10362             if Rep_Item_Too_Late (Ent, N) then
10363                raise Pragma_Exit;
10364             end if;
10365          end Task_Storage;
10366
10367          ----------------
10368          -- Time_Slice --
10369          ----------------
10370
10371          --  pragma Time_Slice (static_duration_EXPRESSION);
10372
10373          when Pragma_Time_Slice => Time_Slice : declare
10374             Val : Ureal;
10375             Nod : Node_Id;
10376
10377          begin
10378             GNAT_Pragma;
10379             Check_Arg_Count (1);
10380             Check_No_Identifiers;
10381             Check_In_Main_Program;
10382             Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
10383
10384             if not Error_Posted (Arg1) then
10385                Nod := Next (N);
10386                while Present (Nod) loop
10387                   if Nkind (Nod) = N_Pragma
10388                     and then Chars (Nod) = Name_Time_Slice
10389                   then
10390                      Error_Msg_Name_1 := Chars (N);
10391                      Error_Msg_N ("duplicate pragma% not permitted", Nod);
10392                   end if;
10393
10394                   Next (Nod);
10395                end loop;
10396             end if;
10397
10398             --  Process only if in main unit
10399
10400             if Get_Source_Unit (Loc) = Main_Unit then
10401                Opt.Time_Slice_Set := True;
10402                Val := Expr_Value_R (Expression (Arg1));
10403
10404                if Val <= Ureal_0 then
10405                   Opt.Time_Slice_Value := 0;
10406
10407                elsif Val > UR_From_Uint (UI_From_Int (1000)) then
10408                   Opt.Time_Slice_Value := 1_000_000_000;
10409
10410                else
10411                   Opt.Time_Slice_Value :=
10412                     UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
10413                end if;
10414             end if;
10415          end Time_Slice;
10416
10417          -----------
10418          -- Title --
10419          -----------
10420
10421          --  pragma Title (TITLING_OPTION [, TITLING OPTION]);
10422
10423          --   TITLING_OPTION ::=
10424          --     [Title =>] STRING_LITERAL
10425          --   | [Subtitle =>] STRING_LITERAL
10426
10427          when Pragma_Title => Title : declare
10428             Args  : Args_List (1 .. 2);
10429             Names : constant Name_List (1 .. 2) := (
10430                       Name_Title,
10431                       Name_Subtitle);
10432
10433          begin
10434             GNAT_Pragma;
10435             Gather_Associations (Names, Args);
10436
10437             for J in 1 .. 2 loop
10438                if Present (Args (J)) then
10439                   Check_Arg_Is_String_Literal (Args (J));
10440                end if;
10441             end loop;
10442          end Title;
10443
10444          ---------------------
10445          -- Unchecked_Union --
10446          ---------------------
10447
10448          --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
10449
10450          when Pragma_Unchecked_Union => Unchecked_Union : declare
10451             Assoc   : constant Node_Id := Arg1;
10452             Type_Id : constant Node_Id := Expression (Assoc);
10453             Typ     : Entity_Id;
10454             Discr   : Entity_Id;
10455             Tdef    : Node_Id;
10456             Clist   : Node_Id;
10457             Vpart   : Node_Id;
10458             Comp    : Node_Id;
10459             Variant : Node_Id;
10460
10461          begin
10462             GNAT_Pragma;
10463             Check_No_Identifiers;
10464             Check_Arg_Count (1);
10465             Check_Arg_Is_Local_Name (Arg1);
10466
10467             Find_Type (Type_Id);
10468             Typ := Entity (Type_Id);
10469
10470             if Typ = Any_Type
10471               or else Rep_Item_Too_Early (Typ, N)
10472             then
10473                return;
10474             else
10475                Typ := Underlying_Type (Typ);
10476             end if;
10477
10478             if Rep_Item_Too_Late (Typ, N) then
10479                return;
10480             end if;
10481
10482             Check_First_Subtype (Arg1);
10483
10484             --  Note remaining cases are references to a type in the current
10485             --  declarative part. If we find an error, we post the error on
10486             --  the relevant type declaration at an appropriate point.
10487
10488             if not Is_Record_Type (Typ) then
10489                Error_Msg_N ("Unchecked_Union must be record type", Typ);
10490                return;
10491
10492             elsif Is_Tagged_Type (Typ) then
10493                Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
10494                return;
10495
10496             elsif Is_Limited_Type (Typ) then
10497                Error_Msg_N
10498                  ("Unchecked_Union must not be limited record type", Typ);
10499                Explain_Limited_Type (Typ, Typ);
10500                return;
10501
10502             else
10503                if not Has_Discriminants (Typ) then
10504                   Error_Msg_N
10505                     ("Unchecked_Union must have one discriminant", Typ);
10506                   return;
10507                end if;
10508
10509                Discr := First_Discriminant (Typ);
10510                while Present (Discr) loop
10511                   if No (Discriminant_Default_Value (Discr)) then
10512                      Error_Msg_N
10513                        ("Unchecked_Union discriminant must have default value",
10514                         Discr);
10515                   end if;
10516                   Next_Discriminant (Discr);
10517                end loop;
10518
10519                Tdef  := Type_Definition (Declaration_Node (Typ));
10520                Clist := Component_List (Tdef);
10521
10522                Comp := First (Component_Items (Clist));
10523                while Present (Comp) loop
10524                   Check_Component (Comp);
10525                   Next (Comp);
10526                end loop;
10527
10528                if No (Clist) or else No (Variant_Part (Clist)) then
10529                   Error_Msg_N
10530                     ("Unchecked_Union must have variant part",
10531                      Tdef);
10532                   return;
10533                end if;
10534
10535                Vpart := Variant_Part (Clist);
10536
10537                Variant := First (Variants (Vpart));
10538                while Present (Variant) loop
10539                   Check_Variant (Variant);
10540                   Next (Variant);
10541                end loop;
10542             end if;
10543
10544             Set_Is_Unchecked_Union  (Typ, True);
10545             Set_Convention          (Typ, Convention_C);
10546
10547             Set_Has_Unchecked_Union (Base_Type (Typ), True);
10548             Set_Is_Unchecked_Union  (Base_Type (Typ), True);
10549          end Unchecked_Union;
10550
10551          ------------------------
10552          -- Unimplemented_Unit --
10553          ------------------------
10554
10555          --  pragma Unimplemented_Unit;
10556
10557          --  Note: this only gives an error if we are generating code,
10558          --  or if we are in a generic library unit (where the pragma
10559          --  appears in the body, not in the spec).
10560
10561          when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
10562             Cunitent : constant Entity_Id :=
10563                          Cunit_Entity (Get_Source_Unit (Loc));
10564             Ent_Kind : constant Entity_Kind :=
10565                          Ekind (Cunitent);
10566
10567          begin
10568             GNAT_Pragma;
10569             Check_Arg_Count (0);
10570
10571             if Operating_Mode = Generate_Code
10572               or else Ent_Kind = E_Generic_Function
10573               or else Ent_Kind = E_Generic_Procedure
10574               or else Ent_Kind = E_Generic_Package
10575             then
10576                Get_Name_String (Chars (Cunitent));
10577                Set_Casing (Mixed_Case);
10578                Write_Str (Name_Buffer (1 .. Name_Len));
10579                Write_Str (" is not supported in this configuration");
10580                Write_Eol;
10581                raise Unrecoverable_Error;
10582             end if;
10583          end Unimplemented_Unit;
10584
10585          ------------------------
10586          -- Universal_Aliasing --
10587          ------------------------
10588
10589          --  pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
10590
10591          when Pragma_Universal_Aliasing => Universal_Alias : declare
10592             E_Id : Entity_Id;
10593
10594          begin
10595             GNAT_Pragma;
10596             Check_Arg_Count (1);
10597             Check_Optional_Identifier (Arg2, Name_Entity);
10598             Check_Arg_Is_Local_Name (Arg1);
10599             E_Id := Entity (Expression (Arg1));
10600
10601             if E_Id = Any_Type then
10602                return;
10603             elsif No (E_Id) or else not Is_Type (E_Id) then
10604                Error_Pragma_Arg ("pragma% requires type", Arg1);
10605             end if;
10606
10607             Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
10608          end Universal_Alias;
10609
10610          --------------------
10611          -- Universal_Data --
10612          --------------------
10613
10614          --  pragma Universal_Data [(library_unit_NAME)];
10615
10616          when Pragma_Universal_Data =>
10617             GNAT_Pragma;
10618
10619             --  If this is a configuration pragma, then set the universal
10620             --  addressing option, otherwise confirm that the pragma
10621             --  satisfies the requirements of library unit pragma placement
10622             --  and leave it to the GNAAMP back end to detect the pragma
10623             --  (avoids transitive setting of the option due to withed units).
10624
10625             if Is_Configuration_Pragma then
10626                Universal_Addressing_On_AAMP := True;
10627             else
10628                Check_Valid_Library_Unit_Pragma;
10629             end if;
10630
10631             if not AAMP_On_Target then
10632                Error_Pragma ("?pragma% ignored (applies only to AAMP)");
10633             end if;
10634
10635          ------------------
10636          -- Unreferenced --
10637          ------------------
10638
10639          --  pragma Unreferenced (local_Name {, local_Name});
10640
10641          --    or when used in a context clause:
10642
10643          --  pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
10644
10645          when Pragma_Unreferenced => Unreferenced : declare
10646             Arg_Node : Node_Id;
10647             Arg_Expr : Node_Id;
10648             Arg_Ent  : Entity_Id;
10649             Citem    : Node_Id;
10650
10651          begin
10652             GNAT_Pragma;
10653             Check_At_Least_N_Arguments (1);
10654
10655             --  Check case of appearing within context clause
10656
10657             if Is_In_Context_Clause then
10658
10659                --  The arguments must all be units mentioned in a with clause
10660                --  in the same context clause. Note we already checked (in
10661                --  Par.Prag) that the arguments are either identifiers or
10662                --  selected components.
10663
10664                Arg_Node := Arg1;
10665                while Present (Arg_Node) loop
10666                   Citem := First (List_Containing (N));
10667                   while Citem /= N loop
10668                      if Nkind (Citem) = N_With_Clause
10669                        and then Same_Name (Name (Citem), Expression (Arg_Node))
10670                      then
10671                         Set_Has_Pragma_Unreferenced
10672                           (Cunit_Entity
10673                              (Get_Source_Unit
10674                                 (Library_Unit (Citem))));
10675                         Set_Unit_Name (Expression (Arg_Node), Name (Citem));
10676                         exit;
10677                      end if;
10678
10679                      Next (Citem);
10680                   end loop;
10681
10682                   if Citem = N then
10683                      Error_Pragma_Arg
10684                        ("argument of pragma% is not with'ed unit", Arg_Node);
10685                   end if;
10686
10687                   Next (Arg_Node);
10688                end loop;
10689
10690             --  Case of not in list of context items
10691
10692             else
10693                Arg_Node := Arg1;
10694                while Present (Arg_Node) loop
10695                   Check_No_Identifier (Arg_Node);
10696
10697                   --  Note: the analyze call done by Check_Arg_Is_Local_Name
10698                   --  will in fact generate reference, so that the entity will
10699                   --  have a reference, which will inhibit any warnings about
10700                   --  it not being referenced, and also properly show up in the
10701                   --  ali file as a reference. But this reference is recorded
10702                   --  before the Has_Pragma_Unreferenced flag is set, so that
10703                   --  no warning is generated for this reference.
10704
10705                   Check_Arg_Is_Local_Name (Arg_Node);
10706                   Arg_Expr := Get_Pragma_Arg (Arg_Node);
10707
10708                   if Is_Entity_Name (Arg_Expr) then
10709                      Arg_Ent := Entity (Arg_Expr);
10710
10711                      --  If the entity is overloaded, the pragma applies to the
10712                      --  most recent overloading, as documented. In this case,
10713                      --  name resolution does not generate a reference, so it
10714                      --  must be done here explicitly.
10715
10716                      if Is_Overloaded (Arg_Expr) then
10717                         Generate_Reference (Arg_Ent, N);
10718                      end if;
10719
10720                      Set_Has_Pragma_Unreferenced (Arg_Ent);
10721                   end if;
10722
10723                   Next (Arg_Node);
10724                end loop;
10725             end if;
10726          end Unreferenced;
10727
10728          --------------------------
10729          -- Unreferenced_Objects --
10730          --------------------------
10731
10732          --  pragma Unreferenced_Objects (local_Name {, local_Name});
10733
10734          when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
10735             Arg_Node : Node_Id;
10736             Arg_Expr : Node_Id;
10737
10738          begin
10739             GNAT_Pragma;
10740             Check_At_Least_N_Arguments (1);
10741
10742             Arg_Node := Arg1;
10743             while Present (Arg_Node) loop
10744                Check_No_Identifier (Arg_Node);
10745                Check_Arg_Is_Local_Name (Arg_Node);
10746                Arg_Expr := Get_Pragma_Arg (Arg_Node);
10747
10748                if not Is_Entity_Name (Arg_Expr)
10749                  or else not Is_Type (Entity (Arg_Expr))
10750                then
10751                   Error_Pragma_Arg
10752                     ("argument for pragma% must be type or subtype", Arg_Node);
10753                end if;
10754
10755                Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
10756                Next (Arg_Node);
10757             end loop;
10758          end Unreferenced_Objects;
10759
10760          ------------------------------
10761          -- Unreserve_All_Interrupts --
10762          ------------------------------
10763
10764          --  pragma Unreserve_All_Interrupts;
10765
10766          when Pragma_Unreserve_All_Interrupts =>
10767             GNAT_Pragma;
10768             Check_Arg_Count (0);
10769
10770             if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
10771                Unreserve_All_Interrupts := True;
10772             end if;
10773
10774          ----------------
10775          -- Unsuppress --
10776          ----------------
10777
10778          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
10779
10780          when Pragma_Unsuppress =>
10781             GNAT_Pragma;
10782             Process_Suppress_Unsuppress (False);
10783
10784          -------------------
10785          -- Use_VADS_Size --
10786          -------------------
10787
10788          --  pragma Use_VADS_Size;
10789
10790          when Pragma_Use_VADS_Size =>
10791             GNAT_Pragma;
10792             Check_Arg_Count (0);
10793             Check_Valid_Configuration_Pragma;
10794             Use_VADS_Size := True;
10795
10796          ---------------------
10797          -- Validity_Checks --
10798          ---------------------
10799
10800          --  pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
10801
10802          when Pragma_Validity_Checks => Validity_Checks : declare
10803             A  : constant Node_Id   := Expression (Arg1);
10804             S  : String_Id;
10805             C  : Char_Code;
10806
10807          begin
10808             GNAT_Pragma;
10809             Check_Arg_Count (1);
10810             Check_No_Identifiers;
10811
10812             if Nkind (A) = N_String_Literal then
10813                S   := Strval (A);
10814
10815                declare
10816                   Slen    : constant Natural := Natural (String_Length (S));
10817                   Options : String (1 .. Slen);
10818                   J       : Natural;
10819
10820                begin
10821                   J := 1;
10822                   loop
10823                      C := Get_String_Char (S, Int (J));
10824                      exit when not In_Character_Range (C);
10825                      Options (J) := Get_Character (C);
10826
10827                      if J = Slen then
10828                         Set_Validity_Check_Options (Options);
10829                         exit;
10830                      else
10831                         J := J + 1;
10832                      end if;
10833                   end loop;
10834                end;
10835
10836             elsif Nkind (A) = N_Identifier then
10837
10838                if Chars (A) = Name_All_Checks then
10839                   Set_Validity_Check_Options ("a");
10840
10841                elsif Chars (A) = Name_On then
10842                   Validity_Checks_On := True;
10843
10844                elsif Chars (A) = Name_Off then
10845                   Validity_Checks_On := False;
10846
10847                end if;
10848             end if;
10849          end Validity_Checks;
10850
10851          --------------
10852          -- Volatile --
10853          --------------
10854
10855          --  pragma Volatile (LOCAL_NAME);
10856
10857          when Pragma_Volatile =>
10858             Process_Atomic_Shared_Volatile;
10859
10860          -------------------------
10861          -- Volatile_Components --
10862          -------------------------
10863
10864          --  pragma Volatile_Components (array_LOCAL_NAME);
10865
10866          --  Volatile is handled by the same circuit as Atomic_Components
10867
10868          --------------
10869          -- Warnings --
10870          --------------
10871
10872          --  pragma Warnings (On | Off);
10873          --  pragma Warnings (On | Off, LOCAL_NAME);
10874          --  pragma Warnings (static_string_EXPRESSION);
10875          --  pragma Warnings (On | Off, STRING_LITERAL);
10876
10877          when Pragma_Warnings => Warnings : begin
10878             GNAT_Pragma;
10879             Check_At_Least_N_Arguments (1);
10880             Check_No_Identifiers;
10881
10882             declare
10883                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10884
10885             begin
10886                --  One argument case
10887
10888                if Arg_Count = 1 then
10889
10890                   --  On/Off one argument case was processed by parser
10891
10892                   if Nkind (Argx) = N_Identifier
10893                     and then
10894                       (Chars (Argx) = Name_On
10895                          or else
10896                        Chars (Argx) = Name_Off)
10897                   then
10898                      null;
10899
10900                   --  One argument case must be ON/OFF or static string expr
10901
10902                   elsif not Is_Static_String_Expression (Arg1) then
10903                      Error_Pragma_Arg
10904                        ("argument of pragma% must be On/Off or " &
10905                         "static string expression", Arg2);
10906
10907                   --  One argument string expression case
10908
10909                   else
10910                      declare
10911                         Lit : constant Node_Id   := Expr_Value_S (Argx);
10912                         Str : constant String_Id := Strval (Lit);
10913                         Len : constant Nat       := String_Length (Str);
10914                         C   : Char_Code;
10915                         J   : Nat;
10916                         OK  : Boolean;
10917                         Chr : Character;
10918
10919                      begin
10920                         J := 1;
10921                         while J <= Len loop
10922                            C := Get_String_Char (Str, J);
10923                            OK := In_Character_Range (C);
10924
10925                            if OK then
10926                               Chr := Get_Character (C);
10927
10928                               --  Dot case
10929
10930                               if J < Len and then Chr = '.' then
10931                                  J := J + 1;
10932                                  C := Get_String_Char (Str, J);
10933                                  Chr := Get_Character (C);
10934
10935                                  if not Set_Dot_Warning_Switch (Chr) then
10936                                     Error_Pragma_Arg
10937                                       ("invalid warning switch character " &
10938                                        '.' & Chr, Arg1);
10939                                  end if;
10940
10941                               --  Non-Dot case
10942
10943                               else
10944                                  OK := Set_Warning_Switch (Chr);
10945                               end if;
10946                            end if;
10947
10948                            if not OK then
10949                               Error_Pragma_Arg
10950                                 ("invalid warning switch character " & Chr,
10951                                  Arg1);
10952                            end if;
10953
10954                            J := J + 1;
10955                         end loop;
10956                      end;
10957                   end if;
10958
10959                   --  Two or more arguments (must be two)
10960
10961                else
10962                   Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10963                   Check_At_Most_N_Arguments (2);
10964
10965                   declare
10966                      E_Id : Node_Id;
10967                      E    : Entity_Id;
10968                      Err  : Boolean;
10969
10970                   begin
10971                      E_Id := Expression (Arg2);
10972                      Analyze (E_Id);
10973
10974                      --  In the expansion of an inlined body, a reference to
10975                      --  the formal may be wrapped in a conversion if the
10976                      --  actual is a conversion. Retrieve the real entity name.
10977
10978                      if (In_Instance_Body
10979                          or else In_Inlined_Body)
10980                        and then Nkind (E_Id) = N_Unchecked_Type_Conversion
10981                      then
10982                         E_Id := Expression (E_Id);
10983                      end if;
10984
10985                      --  Entity name case
10986
10987                      if Is_Entity_Name (E_Id) then
10988                         E := Entity (E_Id);
10989
10990                         if E = Any_Id then
10991                            return;
10992                         else
10993                            loop
10994                               Set_Warnings_Off
10995                                 (E, (Chars (Expression (Arg1)) = Name_Off));
10996
10997                               if Is_Enumeration_Type (E) then
10998                                  declare
10999                                     Lit : Entity_Id;
11000                                  begin
11001                                     Lit := First_Literal (E);
11002                                     while Present (Lit) loop
11003                                        Set_Warnings_Off (Lit);
11004                                        Next_Literal (Lit);
11005                                     end loop;
11006                                  end;
11007                               end if;
11008
11009                               exit when No (Homonym (E));
11010                               E := Homonym (E);
11011                            end loop;
11012                         end if;
11013
11014                      --  Error if not entity or static string literal case
11015
11016                      elsif not Is_Static_String_Expression (Arg2) then
11017                         Error_Pragma_Arg
11018                           ("second argument of pragma% must be entity " &
11019                            "name or static string expression", Arg2);
11020
11021                      --  String literal case
11022
11023                      else
11024                         String_To_Name_Buffer
11025                           (Strval (Expr_Value_S (Expression (Arg2))));
11026
11027                         --  Note on configuration pragma case: If this is a
11028                         --  configuration pragma, then for an OFF pragma, we
11029                         --  just set Config True in the call, which is all
11030                         --  that needs to be done. For the case of ON, this
11031                         --  is normally an error, unless it is canceling the
11032                         --  effect of a previous OFF pragma in the same file.
11033                         --  In any other case, an error will be signalled (ON
11034                         --  with no matching OFF).
11035
11036                         if Chars (Argx) = Name_Off then
11037                            Set_Specific_Warning_Off
11038                              (Loc, Name_Buffer (1 .. Name_Len),
11039                               Config => Is_Configuration_Pragma);
11040
11041                         elsif Chars (Argx) = Name_On then
11042                            Set_Specific_Warning_On
11043                              (Loc, Name_Buffer (1 .. Name_Len), Err);
11044
11045                            if Err then
11046                               Error_Msg
11047                                 ("?pragma Warnings On with no " &
11048                                  "matching Warnings Off",
11049                                  Loc);
11050                            end if;
11051                         end if;
11052                      end if;
11053                   end;
11054                end if;
11055             end;
11056          end Warnings;
11057
11058          -------------------
11059          -- Weak_External --
11060          -------------------
11061
11062          --  pragma Weak_External ([Entity =>] LOCAL_NAME);
11063
11064          when Pragma_Weak_External => Weak_External : declare
11065             Ent : Entity_Id;
11066
11067          begin
11068             GNAT_Pragma;
11069             Check_Arg_Count (1);
11070             Check_Optional_Identifier (Arg1, Name_Entity);
11071             Check_Arg_Is_Library_Level_Local_Name (Arg1);
11072             Ent := Entity (Expression (Arg1));
11073
11074             if Rep_Item_Too_Early (Ent, N) then
11075                return;
11076             else
11077                Ent := Underlying_Type (Ent);
11078             end if;
11079
11080             --  The only processing required is to link this item on to the
11081             --  list of rep items for the given entity. This is accomplished
11082             --  by the call to Rep_Item_Too_Late (when no error is detected
11083             --  and False is returned).
11084
11085             if Rep_Item_Too_Late (Ent, N) then
11086                return;
11087             else
11088                Set_Has_Gigi_Rep_Item (Ent);
11089             end if;
11090          end Weak_External;
11091
11092          -----------------------------
11093          -- Wide_Character_Encoding --
11094          -----------------------------
11095
11096          --  pragma Wide_Character_Encoding (IDENTIFIER);
11097
11098          when Pragma_Wide_Character_Encoding =>
11099
11100             --  Nothing to do, handled in parser. Note that we do not enforce
11101             --  configuration pragma placement, this pragma can appear at any
11102             --  place in the source, allowing mixed encodings within a single
11103             --  source program.
11104
11105             null;
11106
11107          --------------------
11108          -- Unknown_Pragma --
11109          --------------------
11110
11111          --  Should be impossible, since the case of an unknown pragma is
11112          --  separately processed before the case statement is entered.
11113
11114          when Unknown_Pragma =>
11115             raise Program_Error;
11116       end case;
11117
11118    exception
11119       when Pragma_Exit => null;
11120    end Analyze_Pragma;
11121
11122    ---------------------------------
11123    -- Delay_Config_Pragma_Analyze --
11124    ---------------------------------
11125
11126    function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
11127    begin
11128       return Chars (N) = Name_Interrupt_State
11129                or else
11130              Chars (N) = Name_Priority_Specific_Dispatching;
11131    end Delay_Config_Pragma_Analyze;
11132
11133    -------------------------
11134    -- Get_Base_Subprogram --
11135    -------------------------
11136
11137    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
11138       Result : Entity_Id;
11139
11140    begin
11141       --  Follow subprogram renaming chain
11142
11143       Result := Def_Id;
11144       while Is_Subprogram (Result)
11145         and then
11146           (Is_Generic_Instance (Result)
11147             or else Nkind (Parent (Declaration_Node (Result))) =
11148                     N_Subprogram_Renaming_Declaration)
11149         and then Present (Alias (Result))
11150       loop
11151          Result := Alias (Result);
11152       end loop;
11153
11154       return Result;
11155    end Get_Base_Subprogram;
11156
11157    -----------------------------
11158    -- Is_Config_Static_String --
11159    -----------------------------
11160
11161    function Is_Config_Static_String (Arg : Node_Id) return Boolean is
11162
11163       function Add_Config_Static_String (Arg : Node_Id) return Boolean;
11164       --  This is an internal recursive function that is just like the
11165       --  outer function except that it adds the string to the name buffer
11166       --  rather than placing the string in the name buffer.
11167
11168       ------------------------------
11169       -- Add_Config_Static_String --
11170       ------------------------------
11171
11172       function Add_Config_Static_String (Arg : Node_Id) return Boolean is
11173          N : Node_Id;
11174          C : Char_Code;
11175
11176       begin
11177          N := Arg;
11178
11179          if Nkind (N) = N_Op_Concat then
11180             if Add_Config_Static_String (Left_Opnd (N)) then
11181                N := Right_Opnd (N);
11182             else
11183                return False;
11184             end if;
11185          end if;
11186
11187          if Nkind (N) /= N_String_Literal then
11188             Error_Msg_N ("string literal expected for pragma argument", N);
11189             return False;
11190
11191          else
11192             for J in 1 .. String_Length (Strval (N)) loop
11193                C := Get_String_Char (Strval (N), J);
11194
11195                if not In_Character_Range (C) then
11196                   Error_Msg
11197                     ("string literal contains invalid wide character",
11198                      Sloc (N) + 1 + Source_Ptr (J));
11199                   return False;
11200                end if;
11201
11202                Add_Char_To_Name_Buffer (Get_Character (C));
11203             end loop;
11204          end if;
11205
11206          return True;
11207       end Add_Config_Static_String;
11208
11209    --  Start of prorcessing for Is_Config_Static_String
11210
11211    begin
11212
11213       Name_Len := 0;
11214       return Add_Config_Static_String (Arg);
11215    end Is_Config_Static_String;
11216
11217    -----------------------------------------
11218    -- Is_Non_Significant_Pragma_Reference --
11219    -----------------------------------------
11220
11221    --  This function makes use of the following static table which indicates
11222    --  whether a given pragma is significant. A value of -1 in this table
11223    --  indicates that the reference is significant. A value of zero indicates
11224    --  than appearence as any argument is insignificant, a positive value
11225    --  indicates that appearence in that parameter position is significant.
11226
11227    Sig_Flags : constant array (Pragma_Id) of Int :=
11228
11229      (Pragma_AST_Entry                     => -1,
11230       Pragma_Abort_Defer                   => -1,
11231       Pragma_Ada_83                        => -1,
11232       Pragma_Ada_95                        => -1,
11233       Pragma_Ada_05                        => -1,
11234       Pragma_Ada_2005                      => -1,
11235       Pragma_All_Calls_Remote              => -1,
11236       Pragma_Annotate                      => -1,
11237       Pragma_Assert                        => -1,
11238       Pragma_Assertion_Policy              =>  0,
11239       Pragma_Asynchronous                  => -1,
11240       Pragma_Atomic                        =>  0,
11241       Pragma_Atomic_Components             =>  0,
11242       Pragma_Attach_Handler                => -1,
11243       Pragma_Check_Name                    =>  0,
11244       Pragma_CIL_Constructor               => -1,
11245       Pragma_CPP_Class                     =>  0,
11246       Pragma_CPP_Constructor               =>  0,
11247       Pragma_CPP_Virtual                   =>  0,
11248       Pragma_CPP_Vtable                    =>  0,
11249       Pragma_C_Pass_By_Copy                =>  0,
11250       Pragma_Comment                       =>  0,
11251       Pragma_Common_Object                 => -1,
11252       Pragma_Compile_Time_Error            => -1,
11253       Pragma_Compile_Time_Warning          => -1,
11254       Pragma_Compiler_Unit                 =>  0,
11255       Pragma_Complete_Representation       =>  0,
11256       Pragma_Complex_Representation        =>  0,
11257       Pragma_Component_Alignment           => -1,
11258       Pragma_Controlled                    =>  0,
11259       Pragma_Convention                    =>  0,
11260       Pragma_Convention_Identifier         =>  0,
11261       Pragma_Debug                         => -1,
11262       Pragma_Debug_Policy                  =>  0,
11263       Pragma_Detect_Blocking               => -1,
11264       Pragma_Discard_Names                 =>  0,
11265       Pragma_Elaborate                     => -1,
11266       Pragma_Elaborate_All                 => -1,
11267       Pragma_Elaborate_Body                => -1,
11268       Pragma_Elaboration_Checks            => -1,
11269       Pragma_Eliminate                     => -1,
11270       Pragma_Export                        => -1,
11271       Pragma_Export_Exception              => -1,
11272       Pragma_Export_Function               => -1,
11273       Pragma_Export_Object                 => -1,
11274       Pragma_Export_Procedure              => -1,
11275       Pragma_Export_Value                  => -1,
11276       Pragma_Export_Valued_Procedure       => -1,
11277       Pragma_Extend_System                 => -1,
11278       Pragma_Extensions_Allowed            => -1,
11279       Pragma_External                      => -1,
11280       Pragma_External_Name_Casing          => -1,
11281       Pragma_Finalize_Storage_Only         =>  0,
11282       Pragma_Float_Representation          =>  0,
11283       Pragma_Ident                         => -1,
11284       Pragma_Implicit_Packing              =>  0,
11285       Pragma_Import                        => +2,
11286       Pragma_Import_Exception              =>  0,
11287       Pragma_Import_Function               =>  0,
11288       Pragma_Import_Object                 =>  0,
11289       Pragma_Import_Procedure              =>  0,
11290       Pragma_Import_Valued_Procedure       =>  0,
11291       Pragma_Initialize_Scalars            => -1,
11292       Pragma_Inline                        =>  0,
11293       Pragma_Inline_Always                 =>  0,
11294       Pragma_Inline_Generic                =>  0,
11295       Pragma_Inspection_Point              => -1,
11296       Pragma_Interface                     => +2,
11297       Pragma_Interface_Name                => +2,
11298       Pragma_Interrupt_Handler             => -1,
11299       Pragma_Interrupt_Priority            => -1,
11300       Pragma_Interrupt_State               => -1,
11301       Pragma_Java_Constructor              => -1,
11302       Pragma_Java_Interface                => -1,
11303       Pragma_Keep_Names                    =>  0,
11304       Pragma_License                       => -1,
11305       Pragma_Link_With                     => -1,
11306       Pragma_Linker_Alias                  => -1,
11307       Pragma_Linker_Constructor            => -1,
11308       Pragma_Linker_Destructor             => -1,
11309       Pragma_Linker_Options                => -1,
11310       Pragma_Linker_Section                => -1,
11311       Pragma_List                          => -1,
11312       Pragma_Locking_Policy                => -1,
11313       Pragma_Long_Float                    => -1,
11314       Pragma_Machine_Attribute             => -1,
11315       Pragma_Main                          => -1,
11316       Pragma_Main_Storage                  => -1,
11317       Pragma_Memory_Size                   => -1,
11318       Pragma_No_Return                     =>  0,
11319       Pragma_No_Body                       =>  0,
11320       Pragma_No_Run_Time                   => -1,
11321       Pragma_No_Strict_Aliasing            => -1,
11322       Pragma_Normalize_Scalars             => -1,
11323       Pragma_Obsolescent                   =>  0,
11324       Pragma_Optimize                      => -1,
11325       Pragma_Pack                          =>  0,
11326       Pragma_Page                          => -1,
11327       Pragma_Passive                       => -1,
11328       Pragma_Preelaborable_Initialization  => -1,
11329       Pragma_Polling                       => -1,
11330       Pragma_Persistent_BSS                =>  0,
11331       Pragma_Preelaborate                  => -1,
11332       Pragma_Preelaborate_05               => -1,
11333       Pragma_Priority                      => -1,
11334       Pragma_Priority_Specific_Dispatching => -1,
11335       Pragma_Profile                       =>  0,
11336       Pragma_Profile_Warnings              =>  0,
11337       Pragma_Propagate_Exceptions          => -1,
11338       Pragma_Psect_Object                  => -1,
11339       Pragma_Pure                          => -1,
11340       Pragma_Pure_05                       => -1,
11341       Pragma_Pure_Function                 => -1,
11342       Pragma_Queuing_Policy                => -1,
11343       Pragma_Ravenscar                     => -1,
11344       Pragma_Remote_Call_Interface         => -1,
11345       Pragma_Remote_Types                  => -1,
11346       Pragma_Restricted_Run_Time           => -1,
11347       Pragma_Restriction_Warnings          => -1,
11348       Pragma_Restrictions                  => -1,
11349       Pragma_Reviewable                    => -1,
11350       Pragma_Share_Generic                 => -1,
11351       Pragma_Shared                        => -1,
11352       Pragma_Shared_Passive                => -1,
11353       Pragma_Source_File_Name              => -1,
11354       Pragma_Source_File_Name_Project      => -1,
11355       Pragma_Source_Reference              => -1,
11356       Pragma_Storage_Size                  => -1,
11357       Pragma_Storage_Unit                  => -1,
11358       Pragma_Static_Elaboration_Desired    => -1,
11359       Pragma_Stream_Convert                => -1,
11360       Pragma_Style_Checks                  => -1,
11361       Pragma_Subtitle                      => -1,
11362       Pragma_Suppress                      =>  0,
11363       Pragma_Suppress_Exception_Locations  =>  0,
11364       Pragma_Suppress_All                  => -1,
11365       Pragma_Suppress_Debug_Info           =>  0,
11366       Pragma_Suppress_Initialization       =>  0,
11367       Pragma_System_Name                   => -1,
11368       Pragma_Task_Dispatching_Policy       => -1,
11369       Pragma_Task_Info                     => -1,
11370       Pragma_Task_Name                     => -1,
11371       Pragma_Task_Storage                  =>  0,
11372       Pragma_Time_Slice                    => -1,
11373       Pragma_Title                         => -1,
11374       Pragma_Unchecked_Union               =>  0,
11375       Pragma_Unimplemented_Unit            => -1,
11376       Pragma_Universal_Aliasing            => -1,
11377       Pragma_Universal_Data                => -1,
11378       Pragma_Unreferenced                  => -1,
11379       Pragma_Unreferenced_Objects          => -1,
11380       Pragma_Unreserve_All_Interrupts      => -1,
11381       Pragma_Unsuppress                    =>  0,
11382       Pragma_Use_VADS_Size                 => -1,
11383       Pragma_Validity_Checks               => -1,
11384       Pragma_Volatile                      =>  0,
11385       Pragma_Volatile_Components           =>  0,
11386       Pragma_Warnings                      => -1,
11387       Pragma_Weak_External                 => -1,
11388       Pragma_Wide_Character_Encoding       =>  0,
11389       Unknown_Pragma                       =>  0);
11390
11391    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
11392       P : Node_Id;
11393       C : Int;
11394       A : Node_Id;
11395
11396    begin
11397       P := Parent (N);
11398
11399       if Nkind (P) /= N_Pragma_Argument_Association then
11400          return False;
11401
11402       else
11403          C := Sig_Flags (Get_Pragma_Id (Chars (Parent (P))));
11404
11405          case C is
11406             when -1 =>
11407                return False;
11408
11409             when 0 =>
11410                return True;
11411
11412             when others =>
11413                A := First (Pragma_Argument_Associations (Parent (P)));
11414                for J in 1 .. C - 1 loop
11415                   if No (A) then
11416                      return False;
11417                   end if;
11418
11419                   Next (A);
11420                end loop;
11421
11422                return A = P;
11423          end case;
11424       end if;
11425    end Is_Non_Significant_Pragma_Reference;
11426
11427    ------------------------------
11428    -- Is_Pragma_String_Literal --
11429    ------------------------------
11430
11431    --  This function returns true if the corresponding pragma argument is
11432    --  a static string expression. These are the only cases in which string
11433    --  literals can appear as pragma arguments. We also allow a string
11434    --  literal as the first argument to pragma Assert (although it will
11435    --  of course always generate a type error).
11436
11437    function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
11438       Pragn : constant Node_Id := Parent (Par);
11439       Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
11440       Pname : constant Name_Id := Chars (Pragn);
11441       Argn  : Natural;
11442       N     : Node_Id;
11443
11444    begin
11445       Argn := 1;
11446       N := First (Assoc);
11447       loop
11448          exit when N = Par;
11449          Argn := Argn + 1;
11450          Next (N);
11451       end loop;
11452
11453       if Pname = Name_Assert then
11454          return True;
11455
11456       elsif Pname = Name_Export then
11457          return Argn > 2;
11458
11459       elsif Pname = Name_Ident then
11460          return Argn = 1;
11461
11462       elsif Pname = Name_Import then
11463          return Argn > 2;
11464
11465       elsif Pname = Name_Interface_Name then
11466          return Argn > 1;
11467
11468       elsif Pname = Name_Linker_Alias then
11469          return Argn = 2;
11470
11471       elsif Pname = Name_Linker_Section then
11472          return Argn = 2;
11473
11474       elsif Pname = Name_Machine_Attribute then
11475          return Argn = 2;
11476
11477       elsif Pname = Name_Source_File_Name then
11478          return True;
11479
11480       elsif Pname = Name_Source_Reference then
11481          return Argn = 2;
11482
11483       elsif Pname = Name_Title then
11484          return True;
11485
11486       elsif Pname = Name_Subtitle then
11487          return True;
11488
11489       else
11490          return False;
11491       end if;
11492    end Is_Pragma_String_Literal;
11493
11494    --------------------------------------
11495    -- Process_Compilation_Unit_Pragmas --
11496    --------------------------------------
11497
11498    procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
11499    begin
11500       --  A special check for pragma Suppress_All. This is a strange DEC
11501       --  pragma, strange because it comes at the end of the unit. If we
11502       --  have a pragma Suppress_All in the Pragmas_After of the current
11503       --  unit, then we insert a pragma Suppress (All_Checks) at the start
11504       --  of the context clause to ensure the correct processing.
11505
11506       declare
11507          PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
11508          P  : Node_Id;
11509
11510       begin
11511          if Present (PA) then
11512             P := First (PA);
11513             while Present (P) loop
11514                if Chars (P) = Name_Suppress_All then
11515                   Prepend_To (Context_Items (N),
11516                     Make_Pragma (Sloc (P),
11517                       Chars => Name_Suppress,
11518                       Pragma_Argument_Associations => New_List (
11519                         Make_Pragma_Argument_Association (Sloc (P),
11520                           Expression =>
11521                             Make_Identifier (Sloc (P),
11522                               Chars => Name_All_Checks)))));
11523                   exit;
11524                end if;
11525
11526                Next (P);
11527             end loop;
11528          end if;
11529       end;
11530    end Process_Compilation_Unit_Pragmas;
11531
11532    --------
11533    -- rv --
11534    --------
11535
11536    procedure rv is
11537    begin
11538       null;
11539    end rv;
11540
11541    --------------------------------
11542    -- Set_Encoded_Interface_Name --
11543    --------------------------------
11544
11545    procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
11546       Str : constant String_Id := Strval (S);
11547       Len : constant Int       := String_Length (Str);
11548       CC  : Char_Code;
11549       C   : Character;
11550       J   : Int;
11551
11552       Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
11553
11554       procedure Encode;
11555       --  Stores encoded value of character code CC. The encoding we
11556       --  use an underscore followed by four lower case hex digits.
11557
11558       ------------
11559       -- Encode --
11560       ------------
11561
11562       procedure Encode is
11563       begin
11564          Store_String_Char (Get_Char_Code ('_'));
11565          Store_String_Char
11566            (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
11567          Store_String_Char
11568            (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
11569          Store_String_Char
11570            (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
11571          Store_String_Char
11572            (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
11573       end Encode;
11574
11575    --  Start of processing for Set_Encoded_Interface_Name
11576
11577    begin
11578       --  If first character is asterisk, this is a link name, and we
11579       --  leave it completely unmodified. We also ignore null strings
11580       --  (the latter case happens only in error cases) and no encoding
11581       --  should occur for Java or AAMP interface names.
11582
11583       if Len = 0
11584         or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
11585         or else VM_Target /= No_VM
11586         or else AAMP_On_Target
11587       then
11588          Set_Interface_Name (E, S);
11589
11590       else
11591          J := 1;
11592          loop
11593             CC := Get_String_Char (Str, J);
11594
11595             exit when not In_Character_Range (CC);
11596
11597             C := Get_Character (CC);
11598
11599             exit when C /= '_' and then C /= '$'
11600               and then C not in '0' .. '9'
11601               and then C not in 'a' .. 'z'
11602               and then C not in 'A' .. 'Z';
11603
11604             if J = Len then
11605                Set_Interface_Name (E, S);
11606                return;
11607
11608             else
11609                J := J + 1;
11610             end if;
11611          end loop;
11612
11613          --  Here we need to encode. The encoding we use as follows:
11614          --     three underscores  + four hex digits (lower case)
11615
11616          Start_String;
11617
11618          for J in 1 .. String_Length (Str) loop
11619             CC := Get_String_Char (Str, J);
11620
11621             if not In_Character_Range (CC) then
11622                Encode;
11623             else
11624                C := Get_Character (CC);
11625
11626                if C = '_' or else C = '$'
11627                  or else C in '0' .. '9'
11628                  or else C in 'a' .. 'z'
11629                  or else C in 'A' .. 'Z'
11630                then
11631                   Store_String_Char (CC);
11632                else
11633                   Encode;
11634                end if;
11635             end if;
11636          end loop;
11637
11638          Set_Interface_Name (E,
11639            Make_String_Literal (Sloc (S),
11640              Strval => End_String));
11641       end if;
11642    end Set_Encoded_Interface_Name;
11643
11644    -------------------
11645    -- Set_Unit_Name --
11646    -------------------
11647
11648    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
11649       Pref : Node_Id;
11650       Scop : Entity_Id;
11651
11652    begin
11653       if Nkind (N) = N_Identifier
11654         and then Nkind (With_Item) = N_Identifier
11655       then
11656          Set_Entity (N, Entity (With_Item));
11657
11658       elsif Nkind (N) = N_Selected_Component then
11659          Change_Selected_Component_To_Expanded_Name (N);
11660          Set_Entity (N, Entity (With_Item));
11661          Set_Entity (Selector_Name (N), Entity (N));
11662
11663          Pref := Prefix (N);
11664          Scop := Scope (Entity (N));
11665          while Nkind (Pref) = N_Selected_Component loop
11666             Change_Selected_Component_To_Expanded_Name (Pref);
11667             Set_Entity (Selector_Name (Pref), Scop);
11668             Set_Entity (Pref, Scop);
11669             Pref := Prefix (Pref);
11670             Scop := Scope (Scop);
11671          end loop;
11672
11673          Set_Entity (Pref, Scop);
11674       end if;
11675    end Set_Unit_Name;
11676 end Sem_Prag;