OSDN Git Service

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