]> gcc.gnu.org Git - gcc.git/blame - gcc/ada/sem_prag.adb
cstand.adb (Register_Float_Type): Print information about type to register, if the...
[gcc.git] / gcc / ada / sem_prag.adb
CommitLineData
996ae0b0
RK
1------------------------------------------------------------------------------
2-- --
3-- GNAT COMPILER COMPONENTS --
4-- --
5-- S E M _ P R A G --
6-- --
7-- B o d y --
996ae0b0 8-- --
c28408b7 9-- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
996ae0b0
RK
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- --
b5c84c3c 13-- ware Foundation; either version 3, or (at your option) any later ver- --
996ae0b0
RK
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 --
b5c84c3c
RD
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. --
996ae0b0
RK
20-- --
21-- GNAT was originally developed by the GNAT team at New York University. --
71ff80dc 22-- Extensive contributions were provided by Ada Core Technologies Inc. --
996ae0b0
RK
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
32with Atree; use Atree;
33with Casing; use Casing;
c690a2ec 34with Checks; use Checks;
996ae0b0
RK
35with Csets; use Csets;
36with Debug; use Debug;
37with Einfo; use Einfo;
7b4db06c 38with Elists; use Elists;
996ae0b0 39with Errout; use Errout;
72e9f2b9 40with Exp_Ch7; use Exp_Ch7;
996ae0b0 41with Exp_Dist; use Exp_Dist;
996ae0b0 42with Lib; use Lib;
fbf5a39b
AC
43with Lib.Writ; use Lib.Writ;
44with Lib.Xref; use Lib.Xref;
470cd9e9 45with Namet.Sp; use Namet.Sp;
996ae0b0
RK
46with Nlists; use Nlists;
47with Nmake; use Nmake;
48with Opt; use Opt;
49with Output; use Output;
b26be063 50with Par_SCO; use Par_SCO;
996ae0b0 51with Restrict; use Restrict;
6e937c1c 52with Rident; use Rident;
996ae0b0
RK
53with Rtsfind; use Rtsfind;
54with Sem; use Sem;
21d27997 55with Sem_Aux; use Sem_Aux;
fbf5a39b 56with Sem_Ch3; use Sem_Ch3;
21d27997 57with Sem_Ch6; use Sem_Ch6;
996ae0b0 58with Sem_Ch8; use Sem_Ch8;
cfb02ad1 59with Sem_Ch12; use Sem_Ch12;
996ae0b0 60with Sem_Ch13; use Sem_Ch13;
beacce02 61with Sem_Disp; use Sem_Disp;
c857f5ed 62with Sem_Dist; use Sem_Dist;
996ae0b0
RK
63with Sem_Elim; use Sem_Elim;
64with Sem_Eval; use Sem_Eval;
65with Sem_Intr; use Sem_Intr;
66with Sem_Mech; use Sem_Mech;
67with Sem_Res; use Sem_Res;
68with Sem_Type; use Sem_Type;
69with Sem_Util; use Sem_Util;
70with Sem_VFpt; use Sem_VFpt;
f02b8bb8 71with Sem_Warn; use Sem_Warn;
996ae0b0
RK
72with Stand; use Stand;
73with Sinfo; use Sinfo;
74with Sinfo.CN; use Sinfo.CN;
75with Sinput; use Sinput;
76with Snames; use Snames;
77with Stringt; use Stringt;
78with Stylesw; use Stylesw;
523456db 79with Table;
996ae0b0
RK
80with Targparm; use Targparm;
81with Tbuild; use Tbuild;
82with Ttypes;
83with Uintp; use Uintp;
1b24ada5 84with Uname; use Uname;
996ae0b0
RK
85with Urealp; use Urealp;
86with Validsw; use Validsw;
87
88package body Sem_Prag is
89
90 ----------------------------------------------
91 -- Common Handling of Import-Export Pragmas --
92 ----------------------------------------------
93
beacce02
AC
94 -- In the following section, a number of Import_xxx and Export_xxx pragmas
95 -- are defined by GNAT. These are compatible with the DEC pragmas of the
96 -- same name, and all have the following common form and processing:
996ae0b0
RK
97
98 -- pragma Export_xxx
470cd9e9 99 -- [Internal =>] LOCAL_NAME
996ae0b0
RK
100 -- [, [External =>] EXTERNAL_SYMBOL]
101 -- [, other optional parameters ]);
102
103 -- pragma Import_xxx
470cd9e9 104 -- [Internal =>] LOCAL_NAME
996ae0b0
RK
105 -- [, [External =>] EXTERNAL_SYMBOL]
106 -- [, other optional parameters ]);
107
108 -- EXTERNAL_SYMBOL ::=
109 -- IDENTIFIER
110 -- | static_string_EXPRESSION
111
112 -- The internal LOCAL_NAME designates the entity that is imported or
113 -- exported, and must refer to an entity in the current declarative
114 -- part (as required by the rules for LOCAL_NAME).
115
b3b9865d
AC
116 -- The external linker name is designated by the External parameter if
117 -- given, or the Internal parameter if not (if there is no External
996ae0b0
RK
118 -- parameter, the External parameter is a copy of the Internal name).
119
b3b9865d
AC
120 -- If the External parameter is given as a string, then this string is
121 -- treated as an external name (exactly as though it had been given as an
122 -- External_Name parameter for a normal Import pragma).
996ae0b0
RK
123
124 -- If the External parameter is given as an identifier (or there is no
125 -- External parameter, so that the Internal identifier is used), then
126 -- the external name is the characters of the identifier, translated
127 -- to all upper case letters for OpenVMS versions of GNAT, and to all
128 -- lower case letters for all other versions
129
130 -- Note: the external name specified or implied by any of these special
131 -- Import_xxx or Export_xxx pragmas override an external or link name
132 -- specified in a previous Import or Export pragma.
133
b3b9865d
AC
134 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
135 -- named notation, following the standard rules for subprogram calls, i.e.
136 -- parameters can be given in any order if named notation is used, and
137 -- positional and named notation can be mixed, subject to the rule that all
138 -- positional parameters must appear first.
996ae0b0 139
b3b9865d
AC
140 -- Note: All these pragmas are implemented exactly following the DEC design
141 -- and implementation and are intended to be fully compatible with the use
142 -- of these pragmas in the DEC Ada compiler.
996ae0b0 143
523456db
AC
144 --------------------------------------------
145 -- Checking for Duplicated External Names --
146 --------------------------------------------
147
148 -- It is suspicious if two separate Export pragmas use the same external
149 -- name. The following table is used to diagnose this situation so that
150 -- an appropriate warning can be issued.
151
b3b9865d
AC
152 -- The Node_Id stored is for the N_String_Literal node created to hold
153 -- the value of the external name. The Sloc of this node is used to
154 -- cross-reference the location of the duplication.
523456db
AC
155
156 package Externals is new Table.Table (
157 Table_Component_Type => Node_Id,
158 Table_Index_Type => Int,
159 Table_Low_Bound => 0,
160 Table_Initial => 100,
161 Table_Increment => 100,
162 Table_Name => "Name_Externals");
163
996ae0b0
RK
164 -------------------------------------
165 -- Local Subprograms and Variables --
166 -------------------------------------
167
168 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
169 -- This routine is used for possible casing adjustment of an explicit
b3b9865d
AC
170 -- external name supplied as a string literal (the node N), according to
171 -- the casing requirement of Opt.External_Name_Casing. If this is set to
172 -- As_Is, then the string literal is returned unchanged, but if it is set
173 -- to Uppercase or Lowercase, then a new string literal with appropriate
174 -- casing is constructed.
996ae0b0 175
996ae0b0 176 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
b3b9865d
AC
177 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
178 -- original one, following the renaming chain) is returned. Otherwise the
179 -- entity is returned unchanged. Should be in Einfo???
996ae0b0 180
2fa9443e
ES
181 procedure rv;
182 -- This is a dummy function called by the processing for pragma Reviewable.
183 -- It is there for assisting front end debugging. By placing a Reviewable
184 -- pragma in the source program, a breakpoint on rv catches this place in
185 -- the source, allowing convenient stepping to the point of interest.
186
996ae0b0 187 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
b3b9865d
AC
188 -- Place semantic information on the argument of an Elaborate/Elaborate_All
189 -- pragma. Entity name for unit and its parents is taken from item in
190 -- previous with_clause that mentions the unit.
996ae0b0 191
996ae0b0
RK
192 -------------------------------
193 -- Adjust_External_Name_Case --
194 -------------------------------
195
196 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
197 CC : Char_Code;
198
199 begin
200 -- Adjust case of literal if required
201
202 if Opt.External_Name_Exp_Casing = As_Is then
203 return N;
204
205 else
206 -- Copy existing string
207
208 Start_String;
209
210 -- Set proper casing
211
212 for J in 1 .. String_Length (Strval (N)) loop
213 CC := Get_String_Char (Strval (N), J);
214
215 if Opt.External_Name_Exp_Casing = Uppercase
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 elsif Opt.External_Name_Exp_Casing = Lowercase
222 and then CC >= Get_Char_Code ('A')
223 and then CC <= Get_Char_Code ('Z')
224 then
225 Store_String_Char (CC + 32);
226
227 else
228 Store_String_Char (CC);
229 end if;
230 end loop;
231
232 return
233 Make_String_Literal (Sloc (N),
234 Strval => End_String);
235 end if;
236 end Adjust_External_Name_Case;
237
21d27997
RD
238 ------------------------------
239 -- Analyze_PPC_In_Decl_Part --
240 ------------------------------
241
242 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
1fb00064 243 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
21d27997
RD
244
245 begin
b3b9865d
AC
246 -- Install formals and push subprogram spec onto scope stack so that we
247 -- can see the formals from the pragma.
21d27997
RD
248
249 Install_Formals (S);
250 Push_Scope (S);
251
b3b9865d
AC
252 -- Preanalyze the boolean expression, we treat this as a spec expression
253 -- (i.e. similar to a default expression).
21d27997
RD
254
255 Preanalyze_Spec_Expression
256 (Get_Pragma_Arg (Arg1), Standard_Boolean);
257
b3b9865d
AC
258 -- Remove the subprogram from the scope stack now that the pre-analysis
259 -- of the precondition/postcondition is done.
21d27997
RD
260
261 End_Scope;
262 end Analyze_PPC_In_Decl_Part;
263
996ae0b0
RK
264 --------------------
265 -- Analyze_Pragma --
266 --------------------
267
268 procedure Analyze_Pragma (N : Node_Id) is
269 Loc : constant Source_Ptr := Sloc (N);
1b24ada5 270 Pname : constant Name_Id := Pragma_Name (N);
996ae0b0
RK
271 Prag_Id : Pragma_Id;
272
273 Pragma_Exit : exception;
b3b9865d
AC
274 -- This exception is used to exit pragma processing completely. It is
275 -- used when an error is detected, and no further processing is
276 -- required. It is also used if an earlier error has left the tree in
277 -- a state where the pragma should not be processed.
996ae0b0
RK
278
279 Arg_Count : Nat;
280 -- Number of pragma argument associations
281
282 Arg1 : Node_Id;
283 Arg2 : Node_Id;
284 Arg3 : Node_Id;
285 Arg4 : Node_Id;
b3b9865d
AC
286 -- First four pragma arguments (pragma argument association nodes, or
287 -- Empty if the corresponding argument does not exist).
996ae0b0 288
59e5fbe0
RD
289 type Name_List is array (Natural range <>) of Name_Id;
290 type Args_List is array (Natural range <>) of Node_Id;
291 -- Types used for arguments to Check_Arg_Order and Gather_Associations
292
2fa9443e
ES
293 procedure Ada_2005_Pragma;
294 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
295 -- Ada 95 mode, these are implementation defined pragmas, so should be
bfae1846
AC
296 -- caught by the No_Implementation_Pragmas restriction.
297
298 procedure Ada_2012_Pragma;
299 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
300 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
301 -- should be caught by the No_Implementation_Pragmas restriction.
2fa9443e 302
996ae0b0
RK
303 procedure Check_Ada_83_Warning;
304 -- Issues a warning message for the current pragma if operating in Ada
305 -- 83 mode (used for language pragmas that are not a standard part of
306 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
307 -- of 95 pragma.
308
309 procedure Check_Arg_Count (Required : Nat);
b3b9865d
AC
310 -- Check argument count for pragma is equal to given parameter. If not,
311 -- then issue an error message and raise Pragma_Exit.
996ae0b0 312
b3b9865d
AC
313 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
314 -- Arg which can either be a pragma argument association, in which case
315 -- the check is applied to the expression of the association or an
316 -- expression directly.
996ae0b0 317
cc335f43
AC
318 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
319 -- Check that an argument has the right form for an EXTERNAL_NAME
b3b9865d
AC
320 -- parameter of an extended import/export pragma. The rule is that the
321 -- name must be an identifier or string literal (in Ada 83 mode) or a
322 -- static string expression (in Ada 95 mode).
cc335f43 323
996ae0b0
RK
324 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
325 -- Check the specified argument Arg to make sure that it is an
326 -- identifier. If not give error and raise Pragma_Exit.
327
328 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
b3b9865d
AC
329 -- Check the specified argument Arg to make sure that it is an integer
330 -- literal. If not give error and raise Pragma_Exit.
996ae0b0
RK
331
332 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
b3b9865d
AC
333 -- Check the specified argument Arg to make sure that it has the proper
334 -- syntactic form for a local name and meets the semantic requirements
335 -- for a local name. The local name is analyzed as part of the
336 -- processing for this call. In addition, the local name is required
337 -- to represent an entity at the library level.
996ae0b0
RK
338
339 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
b3b9865d
AC
340 -- Check the specified argument Arg to make sure that it has the proper
341 -- syntactic form for a local name and meets the semantic requirements
342 -- for a local name. The local name is analyzed as part of the
343 -- processing for this call.
996ae0b0
RK
344
345 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
346 -- Check the specified argument Arg to make sure that it is a valid
347 -- locking policy name. If not give error and raise Pragma_Exit.
348
349 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
350 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
21d27997 351 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
996ae0b0
RK
352 -- Check the specified argument Arg to make sure that it is an
353 -- identifier whose name matches either N1 or N2 (or N3 if present).
354 -- If not then give error and raise Pragma_Exit.
355
356 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
357 -- Check the specified argument Arg to make sure that it is a valid
358 -- queuing policy name. If not give error and raise Pragma_Exit.
359
360 procedure Check_Arg_Is_Static_Expression
361 (Arg : Node_Id;
d81b4c61 362 Typ : Entity_Id := Empty);
996ae0b0
RK
363 -- Check the specified argument Arg to make sure that it is a static
364 -- expression of the given type (i.e. it will be analyzed and resolved
365 -- using this type, which can be any valid argument to Resolve, e.g.
d81b4c61
RD
366 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
367 -- Typ is left Empty, then any static expression is allowed.
996ae0b0 368
996ae0b0 369 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
b3b9865d
AC
370 -- Check the specified argument Arg to make sure that it is a valid task
371 -- dispatching policy name. If not give error and raise Pragma_Exit.
996ae0b0 372
59e5fbe0
RD
373 procedure Check_Arg_Order (Names : Name_List);
374 -- Checks for an instance of two arguments with identifiers for the
375 -- current pragma which are not in the sequence indicated by Names,
376 -- and if so, generates a fatal message about bad order of arguments.
377
996ae0b0
RK
378 procedure Check_At_Least_N_Arguments (N : Nat);
379 -- Check there are at least N arguments present
380
381 procedure Check_At_Most_N_Arguments (N : Nat);
382 -- Check there are no more than N arguments present
383
72e9f2b9
AC
384 procedure Check_Component
385 (Comp : Node_Id;
386 UU_Typ : Entity_Id;
387 In_Variant_Part : Boolean := False);
388 -- Examine an Unchecked_Union component for correct use of per-object
57193e09 389 -- constrained subtypes, and for restrictions on finalizable components.
72e9f2b9
AC
390 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
391 -- should be set when Comp comes from a record variant.
5d09245e 392
af31bffb
AC
393 procedure Check_Duplicate_Pragma (E : Entity_Id);
394 -- Check if a pragma of the same name as the current pragma is already
c159409f 395 -- chained as a rep pragma to the given entity. If so give a message
0f1a6a0b 396 -- about the duplicate, and then raise Pragma_Exit so does not return.
c159409f 397 -- Also checks for delayed aspect specification node in the chain.
af31bffb 398
523456db 399 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
b3b9865d
AC
400 -- Nam is an N_String_Literal node containing the external name set by
401 -- an Import or Export pragma (or extended Import or Export pragma).
402 -- This procedure checks for possible duplications if this is the export
403 -- case, and if found, issues an appropriate error message.
523456db 404
996ae0b0 405 procedure Check_First_Subtype (Arg : Node_Id);
b4ca2d2c
AC
406 -- Checks that Arg, whose expression is an entity name, references a
407 -- first subtype.
996ae0b0
RK
408
409 procedure Check_In_Main_Program;
410 -- Common checks for pragmas that appear within a main program
8918fe18 411 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
996ae0b0
RK
412
413 procedure Check_Interrupt_Or_Attach_Handler;
b3b9865d
AC
414 -- Common processing for first argument of pragma Interrupt_Handler or
415 -- pragma Attach_Handler.
996ae0b0
RK
416
417 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
418 -- Check that pragma appears in a declarative part, or in a package
419 -- specification, i.e. that it does not occur in a statement sequence
420 -- in a body.
421
422 procedure Check_No_Identifier (Arg : Node_Id);
423 -- Checks that the given argument does not have an identifier. If
424 -- an identifier is present, then an error message is issued, and
425 -- Pragma_Exit is raised.
426
427 procedure Check_No_Identifiers;
428 -- Checks that none of the arguments to the pragma has an identifier.
429 -- If any argument has an identifier, then an error message is issued,
430 -- and Pragma_Exit is raised.
431
9eea4346
GB
432 procedure Check_No_Link_Name;
433 -- Checks that no link name is specified
434
996ae0b0
RK
435 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
436 -- Checks if the given argument has an identifier, and if so, requires
437 -- it to match the given identifier name. If there is a non-matching
438 -- identifier, then an error message is given and Error_Pragmas raised.
439
440 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
441 -- Checks if the given argument has an identifier, and if so, requires
442 -- it to match the given identifier name. If there is a non-matching
443 -- identifier, then an error message is given and Error_Pragmas raised.
444 -- In this version of the procedure, the identifier name is given as
445 -- a string with lower case letters.
446
21d27997
RD
447 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
448 -- Called to process a precondition or postcondition pragma. There are
449 -- three cases:
450 --
451 -- The pragma appears after a subprogram spec
452 --
453 -- If the corresponding check is not enabled, the pragma is analyzed
454 -- but otherwise ignored and control returns with In_Body set False.
455 --
456 -- If the check is enabled, then the first step is to analyze the
457 -- pragma, but this is skipped if the subprogram spec appears within
458 -- a package specification (because this is the case where we delay
459 -- analysis till the end of the spec). Then (whether or not it was
460 -- analyzed), the pragma is chained to the subprogram in question
461 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
462 -- caller with In_Body set False.
463 --
464 -- The pragma appears at the start of subprogram body declarations
465 --
466 -- In this case an immediate return to the caller is made with
467 -- In_Body set True, and the pragma is NOT analyzed.
468 --
469 -- In all other cases, an error message for bad placement is given
470
996ae0b0
RK
471 procedure Check_Static_Constraint (Constr : Node_Id);
472 -- Constr is a constraint from an N_Subtype_Indication node from a
473 -- component constraint in an Unchecked_Union type. This routine checks
474 -- that the constraint is static as required by the restrictions for
475 -- Unchecked_Union.
476
477 procedure Check_Valid_Configuration_Pragma;
478 -- Legality checks for placement of a configuration pragma
479
480 procedure Check_Valid_Library_Unit_Pragma;
481 -- Legality checks for library unit pragmas. A special case arises for
482 -- pragmas in generic instances that come from copies of the original
483 -- library unit pragmas in the generic templates. In the case of other
484 -- than library level instantiations these can appear in contexts which
485 -- would normally be invalid (they only apply to the original template
486 -- and to library level instantiations), and they are simply ignored,
487 -- which is implemented by rewriting them as null statements.
488
72e9f2b9
AC
489 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
490 -- Check an Unchecked_Union variant for lack of nested variants and
491 -- presence of at least one component. UU_Typ is the related Unchecked_
492 -- Union type.
5d09245e 493
996ae0b0
RK
494 procedure Error_Pragma (Msg : String);
495 pragma No_Return (Error_Pragma);
470cd9e9 496 -- Outputs error message for current pragma. The message contains a %
996ae0b0
RK
497 -- that will be replaced with the pragma name, and the flag is placed
498 -- on the pragma itself. Pragma_Exit is then raised.
499
500 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
501 pragma No_Return (Error_Pragma_Arg);
502 -- Outputs error message for current pragma. The message may contain
503 -- a % that will be replaced with the pragma name. The parameter Arg
504 -- may either be a pragma argument association, in which case the flag
505 -- is placed on the expression of this association, or an expression,
506 -- in which case the flag is placed directly on the expression. The
507 -- message is placed using Error_Msg_N, so the message may also contain
508 -- an & insertion character which will reference the given Arg value.
509 -- After placing the message, Pragma_Exit is raised.
510
511 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
512 pragma No_Return (Error_Pragma_Arg);
513 -- Similar to above form of Error_Pragma_Arg except that two messages
514 -- are provided, the second is a continuation comment starting with \.
515
516 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
517 pragma No_Return (Error_Pragma_Arg_Ident);
518 -- Outputs error message for current pragma. The message may contain
519 -- a % that will be replaced with the pragma name. The parameter Arg
520 -- must be a pragma argument association with a non-empty identifier
521 -- (i.e. its Chars field must be set), and the error message is placed
522 -- on the identifier. The message is placed using Error_Msg_N so
523 -- the message may also contain an & insertion character which will
524 -- reference the identifier. After placing the message, Pragma_Exit
525 -- is raised.
526
b039b10e
ST
527 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
528 pragma No_Return (Error_Pragma_Ref);
529 -- Outputs error message for current pragma. The message may contain
530 -- a % that will be replaced with the pragma name. The parameter Ref
531 -- must be an entity whose name can be referenced by & and sloc by #.
532 -- After placing the message, Pragma_Exit is raised.
533
996ae0b0
RK
534 function Find_Lib_Unit_Name return Entity_Id;
535 -- Used for a library unit pragma to find the entity to which the
536 -- library unit pragma applies, returns the entity found.
537
538 procedure Find_Program_Unit_Name (Id : Node_Id);
539 -- If the pragma is a compilation unit pragma, the id must denote the
540 -- compilation unit in the same compilation, and the pragma must appear
541 -- in the list of preceding or trailing pragmas. If it is a program
542 -- unit pragma that is not a compilation unit pragma, then the
543 -- identifier must be visible.
544
d9e0a587
EB
545 function Find_Unique_Parameterless_Procedure
546 (Name : Entity_Id;
547 Arg : Node_Id) return Entity_Id;
548 -- Used for a procedure pragma to find the unique parameterless
549 -- procedure identified by Name, returns it if it exists, otherwise
550 -- errors out and uses Arg as the pragma argument for the message.
551
0f1a6a0b
AC
552 procedure Fix_Error (Msg : in out String);
553 -- This is called prior to issuing an error message. Msg is a string
554 -- which typically contains the substring pragma. If the current pragma
555 -- comes from an aspect, each such "pragma" substring is replaced with
811ef5ba
RD
556 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
557 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
0f1a6a0b 558
996ae0b0
RK
559 procedure Gather_Associations
560 (Names : Name_List;
561 Args : out Args_List);
562 -- This procedure is used to gather the arguments for a pragma that
563 -- permits arbitrary ordering of parameters using the normal rules
564 -- for named and positional parameters. The Names argument is a list
565 -- of Name_Id values that corresponds to the allowed pragma argument
566 -- association identifiers in order. The result returned in Args is
567 -- a list of corresponding expressions that are the pragma arguments.
568 -- Note that this is a list of expressions, not of pragma argument
569 -- associations (Gather_Associations has completely checked all the
570 -- optional identifiers when it returns). An entry in Args is Empty
571 -- on return if the corresponding argument is not present.
572
996ae0b0 573 procedure GNAT_Pragma;
2fa9443e
ES
574 -- Called for all GNAT defined pragmas to check the relevant restriction
575 -- (No_Implementation_Pragmas).
996ae0b0
RK
576
577 function Is_Before_First_Decl
578 (Pragma_Node : Node_Id;
a9f4e3d2 579 Decls : List_Id) return Boolean;
996ae0b0
RK
580 -- Return True if Pragma_Node is before the first declarative item in
581 -- Decls where Decls is the list of declarative items.
582
583 function Is_Configuration_Pragma return Boolean;
f3d57416 584 -- Determines if the placement of the current pragma is appropriate
1b24ada5 585 -- for a configuration pragma.
ac9e9918
RD
586
587 function Is_In_Context_Clause return Boolean;
588 -- Returns True if pragma appears within the context clause of a unit,
589 -- and False for any other placement (does not generate any messages).
590
591 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
592 -- Analyzes the argument, and determines if it is a static string
593 -- expression, returns True if so, False if non-static or not String.
996ae0b0
RK
594
595 procedure Pragma_Misplaced;
3023ce42 596 pragma No_Return (Pragma_Misplaced);
996ae0b0
RK
597 -- Issue fatal error message for misplaced pragma
598
599 procedure Process_Atomic_Shared_Volatile;
600 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
601 -- Shared is an obsolete Ada 83 pragma, treated as being identical
602 -- in effect to pragma Atomic.
603
874a0341
RD
604 procedure Process_Compile_Time_Warning_Or_Error;
605 -- Common processing for Compile_Time_Error and Compile_Time_Warning
606
9fe2f33e 607 procedure Process_Convention
9cf032ef
RD
608 (C : out Convention_Id;
609 Ent : out Entity_Id);
f3d57416 610 -- Common processing for Convention, Interface, Import and Export.
996ae0b0
RK
611 -- Checks first two arguments of pragma, and sets the appropriate
612 -- convention value in the specified entity or entities. On return
9fe2f33e 613 -- C is the convention, Ent is the referenced entity.
996ae0b0
RK
614
615 procedure Process_Extended_Import_Export_Exception_Pragma
616 (Arg_Internal : Node_Id;
617 Arg_External : Node_Id;
618 Arg_Form : Node_Id;
619 Arg_Code : Node_Id);
b3b9865d
AC
620 -- Common processing for the pragmas Import/Export_Exception. The three
621 -- arguments correspond to the three named parameters of the pragma. An
622 -- argument is empty if the corresponding parameter is not present in
623 -- the pragma.
996ae0b0
RK
624
625 procedure Process_Extended_Import_Export_Object_Pragma
626 (Arg_Internal : Node_Id;
627 Arg_External : Node_Id;
628 Arg_Size : Node_Id);
b3b9865d
AC
629 -- Common processing for the pragmas Import/Export_Object. The three
630 -- arguments correspond to the three named parameters of the pragmas. An
631 -- argument is empty if the corresponding parameter is not present in
632 -- the pragma.
996ae0b0
RK
633
634 procedure Process_Extended_Import_Export_Internal_Arg
635 (Arg_Internal : Node_Id := Empty);
636 -- Common processing for all extended Import and Export pragmas. The
637 -- argument is the pragma parameter for the Internal argument. If
638 -- Arg_Internal is empty or inappropriate, an error message is posted.
639 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
640 -- set to identify the referenced entity.
641
642 procedure Process_Extended_Import_Export_Subprogram_Pragma
643 (Arg_Internal : Node_Id;
644 Arg_External : Node_Id;
645 Arg_Parameter_Types : Node_Id;
646 Arg_Result_Type : Node_Id := Empty;
647 Arg_Mechanism : Node_Id;
648 Arg_Result_Mechanism : Node_Id := Empty;
649 Arg_First_Optional_Parameter : Node_Id := Empty);
b3b9865d
AC
650 -- Common processing for all extended Import and Export pragmas applying
651 -- to subprograms. The caller omits any arguments that do not apply to
652 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
653 -- only in the Import_Function and Export_Function cases). The argument
654 -- names correspond to the allowed pragma association identifiers.
996ae0b0
RK
655
656 procedure Process_Generic_List;
657 -- Common processing for Share_Generic and Inline_Generic
658
659 procedure Process_Import_Or_Interface;
660 -- Common processing for Import of Interface
661
15b682ca
GB
662 procedure Process_Import_Predefined_Type;
663 -- Processing for completing a type with pragma Import. This is used
664 -- to declare types that match predefined C types, especially for cases
665 -- without corresponding Ada predefined type.
666
996ae0b0
RK
667 procedure Process_Inline (Active : Boolean);
668 -- Common processing for Inline and Inline_Always. The parameter
b3b9865d
AC
669 -- indicates if the inline pragma is active, i.e. if it should actually
670 -- cause inlining to occur.
996ae0b0
RK
671
672 procedure Process_Interface_Name
673 (Subprogram_Def : Entity_Id;
674 Ext_Arg : Node_Id;
675 Link_Arg : Node_Id);
676 -- Given the last two arguments of pragma Import, pragma Export, or
677 -- pragma Interface_Name, performs validity checks and sets the
678 -- Interface_Name field of the given subprogram entity to the
b3b9865d
AC
679 -- appropriate external or link name, depending on the arguments given.
680 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
681 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
682 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
683 -- nor Link_Arg is present, the interface name is set to the default
684 -- from the subprogram name.
996ae0b0
RK
685
686 procedure Process_Interrupt_Or_Attach_Handler;
6e937c1c
AC
687 -- Common processing for Interrupt and Attach_Handler pragmas
688
ac9e9918
RD
689 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
690 -- Common processing for Restrictions and Restriction_Warnings pragmas.
23e6615e
RD
691 -- Warn is True for Restriction_Warnings, or for Restrictions if the
692 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
693 -- is not set in the Restrictions case.
996ae0b0
RK
694
695 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
696 -- Common processing for Suppress and Unsuppress. The boolean parameter
697 -- Suppress_Case is True for the Suppress case, and False for the
698 -- Unsuppress case.
699
700 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
701 -- This procedure sets the Is_Exported flag for the given entity,
702 -- checking that the entity was not previously imported. Arg is
fbf5a39b
AC
703 -- the argument that specified the entity. A check is also made
704 -- for exporting inappropriate entities.
996ae0b0
RK
705
706 procedure Set_Extended_Import_Export_External_Name
707 (Internal_Ent : Entity_Id;
708 Arg_External : Node_Id);
709 -- Common processing for all extended import export pragmas. The first
710 -- argument, Internal_Ent, is the internal entity, which has already
711 -- been checked for validity by the caller. Arg_External is from the
712 -- Import or Export pragma, and may be null if no External parameter
713 -- was present. If Arg_External is present and is a non-null string
714 -- (a null string is treated as the default), then the Interface_Name
715 -- field of Internal_Ent is set appropriately.
716
717 procedure Set_Imported (E : Entity_Id);
718 -- This procedure sets the Is_Imported flag for the given entity,
719 -- checking that it is not previously exported or imported.
720
721 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
722 -- Mech is a parameter passing mechanism (see Import_Function syntax
723 -- for MECHANISM_NAME). This routine checks that the mechanism argument
724 -- has the right form, and if not issues an error message. If the
725 -- argument has the right form then the Mechanism field of Ent is
726 -- set appropriately.
727
8a36a0cc 728 procedure Set_Ravenscar_Profile (N : Node_Id);
b3b9865d
AC
729 -- Activate the set of configuration pragmas and restrictions that make
730 -- up the Ravenscar Profile. N is the corresponding pragma node, which
731 -- is used for error messages on any constructs that violate the
732 -- profile.
8a36a0cc 733
2fa9443e
ES
734 ---------------------
735 -- Ada_2005_Pragma --
736 ---------------------
737
738 procedure Ada_2005_Pragma is
739 begin
740 if Ada_Version <= Ada_95 then
741 Check_Restriction (No_Implementation_Pragmas, N);
742 end if;
743 end Ada_2005_Pragma;
744
bfae1846
AC
745 ---------------------
746 -- Ada_2012_Pragma --
747 ---------------------
748
749 procedure Ada_2012_Pragma is
750 begin
0791fbe9 751 if Ada_Version <= Ada_2005 then
bfae1846
AC
752 Check_Restriction (No_Implementation_Pragmas, N);
753 end if;
754 end Ada_2012_Pragma;
755
996ae0b0
RK
756 --------------------------
757 -- Check_Ada_83_Warning --
758 --------------------------
759
760 procedure Check_Ada_83_Warning is
761 begin
0ab80019 762 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
996ae0b0
RK
763 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
764 end if;
765 end Check_Ada_83_Warning;
766
767 ---------------------
768 -- Check_Arg_Count --
769 ---------------------
770
771 procedure Check_Arg_Count (Required : Nat) is
772 begin
773 if Arg_Count /= Required then
774 Error_Pragma ("wrong number of arguments for pragma%");
775 end if;
776 end Check_Arg_Count;
777
cc335f43
AC
778 --------------------------------
779 -- Check_Arg_Is_External_Name --
780 --------------------------------
781
782 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
783 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
784
785 begin
786 if Nkind (Argx) = N_Identifier then
787 return;
788
789 else
790 Analyze_And_Resolve (Argx, Standard_String);
791
792 if Is_OK_Static_Expression (Argx) then
793 return;
794
795 elsif Etype (Argx) = Any_Type then
796 raise Pragma_Exit;
797
798 -- An interesting special case, if we have a string literal and
799 -- we are in Ada 83 mode, then we allow it even though it will
800 -- not be flagged as static. This allows expected Ada 83 mode
801 -- use of external names which are string literals, even though
802 -- technically these are not static in Ada 83.
803
804 elsif Ada_Version = Ada_83
805 and then Nkind (Argx) = N_String_Literal
806 then
807 return;
808
809 -- Static expression that raises Constraint_Error. This has
810 -- already been flagged, so just exit from pragma processing.
811
812 elsif Is_Static_Expression (Argx) then
813 raise Pragma_Exit;
814
815 -- Here we have a real error (non-static expression)
816
817 else
1b24ada5 818 Error_Msg_Name_1 := Pname;
0f1a6a0b
AC
819
820 declare
821 Msg : String :=
822 "argument for pragma% must be a identifier or "
823 & "static string expression!";
824 begin
825 Fix_Error (Msg);
826 Flag_Non_Static_Expr (Msg, Argx);
827 raise Pragma_Exit;
828 end;
cc335f43
AC
829 end if;
830 end if;
831 end Check_Arg_Is_External_Name;
832
996ae0b0
RK
833 -----------------------------
834 -- Check_Arg_Is_Identifier --
835 -----------------------------
836
837 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
838 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
996ae0b0
RK
839 begin
840 if Nkind (Argx) /= N_Identifier then
841 Error_Pragma_Arg
842 ("argument for pragma% must be identifier", Argx);
843 end if;
844 end Check_Arg_Is_Identifier;
845
846 ----------------------------------
847 -- Check_Arg_Is_Integer_Literal --
848 ----------------------------------
849
850 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
851 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
996ae0b0
RK
852 begin
853 if Nkind (Argx) /= N_Integer_Literal then
854 Error_Pragma_Arg
855 ("argument for pragma% must be integer literal", Argx);
856 end if;
857 end Check_Arg_Is_Integer_Literal;
858
859 -------------------------------------------
860 -- Check_Arg_Is_Library_Level_Local_Name --
861 -------------------------------------------
862
863 -- LOCAL_NAME ::=
864 -- DIRECT_NAME
865 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
866 -- | library_unit_NAME
867
868 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
869 begin
870 Check_Arg_Is_Local_Name (Arg);
871
0f1a6a0b 872 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
996ae0b0
RK
873 and then Comes_From_Source (N)
874 then
875 Error_Pragma_Arg
876 ("argument for pragma% must be library level entity", Arg);
877 end if;
878 end Check_Arg_Is_Library_Level_Local_Name;
879
880 -----------------------------
881 -- Check_Arg_Is_Local_Name --
882 -----------------------------
883
884 -- LOCAL_NAME ::=
885 -- DIRECT_NAME
886 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
887 -- | library_unit_NAME
888
889 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
890 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
891
892 begin
893 Analyze (Argx);
894
895 if Nkind (Argx) not in N_Direct_Name
896 and then (Nkind (Argx) /= N_Attribute_Reference
897 or else Present (Expressions (Argx))
898 or else Nkind (Prefix (Argx)) /= N_Identifier)
899 and then (not Is_Entity_Name (Argx)
900 or else not Is_Compilation_Unit (Entity (Argx)))
901 then
902 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
903 end if;
904
c3ad80f0
TQ
905 -- No further check required if not an entity name
906
907 if not Is_Entity_Name (Argx) then
908 null;
909
910 else
911 declare
912 OK : Boolean;
913 Ent : constant Entity_Id := Entity (Argx);
914 Scop : constant Entity_Id := Scope (Ent);
915 begin
916 -- Case of a pragma applied to a compilation unit: pragma must
917 -- occur immediately after the program unit in the compilation.
918
919 if Is_Compilation_Unit (Ent) then
920 declare
921 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
922 begin
923 -- Case of pragma placed immediately after spec
924
925 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
926 OK := True;
927
928 -- Case of pragma placed immediately after body
929
930 elsif Nkind (Decl) = N_Subprogram_Declaration
931 and then Present (Corresponding_Body (Decl))
932 then
933 OK := Parent (N) =
934 Aux_Decls_Node
935 (Parent (Unit_Declaration_Node
936 (Corresponding_Body (Decl))));
937
938 -- All other cases are illegal
939
940 else
941 OK := False;
942 end if;
943 end;
944
945 -- Special restricted placement rule from 10.2.1(11.8/2)
946
947 elsif Is_Generic_Formal (Ent)
948 and then Prag_Id = Pragma_Preelaborable_Initialization
949 then
950 OK := List_Containing (N) =
951 Generic_Formal_Declarations
952 (Unit_Declaration_Node (Scop));
953
954 -- Default case, just check that the pragma occurs in the scope
955 -- of the entity denoted by the name.
956
957 else
958 OK := Current_Scope = Scop;
959 end if;
960
961 if not OK then
962 Error_Pragma_Arg
963 ("pragma% argument must be in same declarative part", Arg);
964 end if;
965 end;
996ae0b0
RK
966 end if;
967 end Check_Arg_Is_Local_Name;
968
969 ---------------------------------
970 -- Check_Arg_Is_Locking_Policy --
971 ---------------------------------
972
973 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
974 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
975
976 begin
977 Check_Arg_Is_Identifier (Argx);
978
979 if not Is_Locking_Policy_Name (Chars (Argx)) then
b4ca2d2c 980 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
996ae0b0
RK
981 end if;
982 end Check_Arg_Is_Locking_Policy;
983
984 -------------------------
985 -- Check_Arg_Is_One_Of --
986 -------------------------
987
988 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
989 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
990
991 begin
992 Check_Arg_Is_Identifier (Argx);
993
994 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
995 Error_Msg_Name_2 := N1;
996 Error_Msg_Name_3 := N2;
997 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
998 end if;
999 end Check_Arg_Is_One_Of;
1000
1001 procedure Check_Arg_Is_One_Of
1002 (Arg : Node_Id;
1003 N1, N2, N3 : Name_Id)
1004 is
1005 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1006
1007 begin
1008 Check_Arg_Is_Identifier (Argx);
1009
1010 if Chars (Argx) /= N1
1011 and then Chars (Argx) /= N2
1012 and then Chars (Argx) /= N3
1013 then
1014 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1015 end if;
1016 end Check_Arg_Is_One_Of;
1017
21d27997
RD
1018 procedure Check_Arg_Is_One_Of
1019 (Arg : Node_Id;
1020 N1, N2, N3, N4 : Name_Id)
1021 is
1022 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1023
1024 begin
1025 Check_Arg_Is_Identifier (Argx);
1026
1027 if Chars (Argx) /= N1
1028 and then Chars (Argx) /= N2
1029 and then Chars (Argx) /= N3
1030 and then Chars (Argx) /= N4
1031 then
1032 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1033 end if;
1034 end Check_Arg_Is_One_Of;
996ae0b0
RK
1035 ---------------------------------
1036 -- Check_Arg_Is_Queuing_Policy --
1037 ---------------------------------
1038
1039 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1040 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1041
1042 begin
1043 Check_Arg_Is_Identifier (Argx);
1044
1045 if not Is_Queuing_Policy_Name (Chars (Argx)) then
b4ca2d2c 1046 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
996ae0b0
RK
1047 end if;
1048 end Check_Arg_Is_Queuing_Policy;
1049
1050 ------------------------------------
1051 -- Check_Arg_Is_Static_Expression --
1052 ------------------------------------
1053
1054 procedure Check_Arg_Is_Static_Expression
1055 (Arg : Node_Id;
d81b4c61 1056 Typ : Entity_Id := Empty)
996ae0b0
RK
1057 is
1058 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1059
1060 begin
d81b4c61
RD
1061 if Present (Typ) then
1062 Analyze_And_Resolve (Argx, Typ);
1063 else
1064 Analyze_And_Resolve (Argx);
1065 end if;
996ae0b0
RK
1066
1067 if Is_OK_Static_Expression (Argx) then
1068 return;
1069
1070 elsif Etype (Argx) = Any_Type then
1071 raise Pragma_Exit;
1072
b3b9865d
AC
1073 -- An interesting special case, if we have a string literal and we
1074 -- are in Ada 83 mode, then we allow it even though it will not be
1075 -- flagged as static. This allows the use of Ada 95 pragmas like
1076 -- Import in Ada 83 mode. They will of course be flagged with
1077 -- warnings as usual, but will not cause errors.
996ae0b0 1078
0ab80019
AC
1079 elsif Ada_Version = Ada_83
1080 and then Nkind (Argx) = N_String_Literal
1081 then
996ae0b0
RK
1082 return;
1083
b3b9865d
AC
1084 -- Static expression that raises Constraint_Error. This has already
1085 -- been flagged, so just exit from pragma processing.
996ae0b0
RK
1086
1087 elsif Is_Static_Expression (Argx) then
1088 raise Pragma_Exit;
1089
1090 -- Finally, we have a real error
1091
1092 else
1b24ada5 1093 Error_Msg_Name_1 := Pname;
0f1a6a0b
AC
1094
1095 declare
1096 Msg : String :=
1097 "argument for pragma% must be a static expression!";
1098 begin
1099 Fix_Error (Msg);
1100 Flag_Non_Static_Expr (Msg, Argx);
1101 end;
1102
fbf5a39b 1103 raise Pragma_Exit;
996ae0b0 1104 end if;
996ae0b0
RK
1105 end Check_Arg_Is_Static_Expression;
1106
996ae0b0
RK
1107 ------------------------------------------
1108 -- Check_Arg_Is_Task_Dispatching_Policy --
1109 ------------------------------------------
1110
1111 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1112 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1113
1114 begin
1115 Check_Arg_Is_Identifier (Argx);
1116
1117 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1118 Error_Pragma_Arg
1119 ("& is not a valid task dispatching policy name", Argx);
1120 end if;
1121 end Check_Arg_Is_Task_Dispatching_Policy;
1122
59e5fbe0
RD
1123 ---------------------
1124 -- Check_Arg_Order --
1125 ---------------------
1126
1127 procedure Check_Arg_Order (Names : Name_List) is
1128 Arg : Node_Id;
1129
1130 Highest_So_Far : Natural := 0;
1131 -- Highest index in Names seen do far
1132
1133 begin
1134 Arg := Arg1;
1135 for J in 1 .. Arg_Count loop
1136 if Chars (Arg) /= No_Name then
1137 for K in Names'Range loop
1138 if Chars (Arg) = Names (K) then
1139 if K < Highest_So_Far then
1b24ada5 1140 Error_Msg_Name_1 := Pname;
59e5fbe0
RD
1141 Error_Msg_N
1142 ("parameters out of order for pragma%", Arg);
1143 Error_Msg_Name_1 := Names (K);
1144 Error_Msg_Name_2 := Names (Highest_So_Far);
ed2233dc 1145 Error_Msg_N ("\% must appear before %", Arg);
59e5fbe0
RD
1146 raise Pragma_Exit;
1147
1148 else
1149 Highest_So_Far := K;
1150 end if;
1151 end if;
1152 end loop;
1153 end if;
1154
1155 Arg := Next (Arg);
1156 end loop;
1157 end Check_Arg_Order;
1158
996ae0b0
RK
1159 --------------------------------
1160 -- Check_At_Least_N_Arguments --
1161 --------------------------------
1162
1163 procedure Check_At_Least_N_Arguments (N : Nat) is
1164 begin
1165 if Arg_Count < N then
1166 Error_Pragma ("too few arguments for pragma%");
1167 end if;
1168 end Check_At_Least_N_Arguments;
1169
1170 -------------------------------
1171 -- Check_At_Most_N_Arguments --
1172 -------------------------------
1173
1174 procedure Check_At_Most_N_Arguments (N : Nat) is
1175 Arg : Node_Id;
996ae0b0
RK
1176 begin
1177 if Arg_Count > N then
1178 Arg := Arg1;
996ae0b0
RK
1179 for J in 1 .. N loop
1180 Next (Arg);
1181 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1182 end loop;
1183 end if;
1184 end Check_At_Most_N_Arguments;
1185
5d09245e
AC
1186 ---------------------
1187 -- Check_Component --
1188 ---------------------
1189
72e9f2b9
AC
1190 procedure Check_Component
1191 (Comp : Node_Id;
1192 UU_Typ : Entity_Id;
1193 In_Variant_Part : Boolean := False)
1194 is
1195 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1196 Sindic : constant Node_Id :=
1197 Subtype_Indication (Component_Definition (Comp));
1198 Typ : constant Entity_Id := Etype (Comp_Id);
5d09245e 1199
72e9f2b9 1200 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
229db351
AC
1201 -- Determine whether entity Id appears inside a generic body.
1202 -- Shouldn't this be in a more general place ???
5d09245e 1203
72e9f2b9
AC
1204 -------------------------
1205 -- Inside_Generic_Body --
1206 -------------------------
57193e09 1207
72e9f2b9 1208 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
229db351 1209 S : Entity_Id;
57193e09 1210
72e9f2b9 1211 begin
229db351 1212 S := Id;
b4ca2d2c 1213 while Present (S) and then S /= Standard_Standard loop
72e9f2b9
AC
1214 if Ekind (S) = E_Generic_Package
1215 and then In_Package_Body (S)
1216 then
1217 return True;
57193e09 1218 end if;
72e9f2b9
AC
1219
1220 S := Scope (S);
1221 end loop;
1222
1223 return False;
1224 end Inside_Generic_Body;
1225
1226 -- Start of processing for Check_Component
1227
1228 begin
1229 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1230 -- object constraint, then the component type shall be an Unchecked_
1231 -- Union.
1232
1233 if Nkind (Sindic) = N_Subtype_Indication
1234 and then Has_Per_Object_Constraint (Comp_Id)
1235 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1236 then
1237 Error_Msg_N
1238 ("component subtype subject to per-object constraint " &
1239 "must be an Unchecked_Union", Comp);
1240
1241 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1242 -- the body of a generic unit, or within the body of any of its
1243 -- descendant library units, no part of the type of a component
1244 -- declared in a variant_part of the unchecked union type shall be of
1245 -- a formal private type or formal private extension declared within
1246 -- the formal part of the generic unit.
1247
1248 elsif Ada_Version >= Ada_2012
1249 and then Inside_Generic_Body (UU_Typ)
1250 and then In_Variant_Part
1251 and then Is_Private_Type (Typ)
1252 and then Is_Generic_Type (Typ)
1253 then
1254 Error_Msg_N
1255 ("component of Unchecked_Union cannot be of generic type", Comp);
1256
1257 elsif Needs_Finalization (Typ) then
1258 Error_Msg_N
1259 ("component of Unchecked_Union cannot be controlled", Comp);
1260
1261 elsif Has_Task (Typ) then
1262 Error_Msg_N
1263 ("component of Unchecked_Union cannot have tasks", Comp);
5d09245e
AC
1264 end if;
1265 end Check_Component;
1266
40f07b4b
AC
1267 ----------------------------
1268 -- Check_Duplicate_Pragma --
1269 ----------------------------
1270
af31bffb 1271 procedure Check_Duplicate_Pragma (E : Entity_Id) is
c159409f 1272 P : Node_Id;
40f07b4b 1273
af31bffb 1274 begin
0f1a6a0b
AC
1275 -- Nothing to do if this pragma comes from an aspect specification,
1276 -- since we could not be duplicating a pragma, and we dealt with the
1277 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1278
1279 if From_Aspect_Specification (N) then
1280 return;
1281 end if;
1282
1283 -- Otherwise current pragma may duplicate previous pragma or a
1284 -- previously given aspect specification for the same pragma.
1285
c159409f 1286 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
40f07b4b 1287
c159409f
AC
1288 if Present (P) then
1289 Error_Msg_Name_1 := Pragma_Name (N);
1290 Error_Msg_Sloc := Sloc (P);
40f07b4b 1291
c159409f
AC
1292 if Nkind (P) = N_Aspect_Specification
1293 or else From_Aspect_Specification (P)
40f07b4b 1294 then
beacce02 1295 Error_Msg_NE ("aspect% for & previously given#", N, E);
c159409f
AC
1296 else
1297 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
40f07b4b 1298 end if;
c159409f
AC
1299
1300 raise Pragma_Exit;
af31bffb
AC
1301 end if;
1302 end Check_Duplicate_Pragma;
1303
523456db
AC
1304 ----------------------------------
1305 -- Check_Duplicated_Export_Name --
1306 ----------------------------------
1307
1308 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1309 String_Val : constant String_Id := Strval (Nam);
1310
1311 begin
1312 -- We are only interested in the export case, and in the case of
1313 -- generics, it is the instance, not the template, that is the
1314 -- problem (the template will generate a warning in any case).
1315
1316 if not Inside_A_Generic
1317 and then (Prag_Id = Pragma_Export
1318 or else
1319 Prag_Id = Pragma_Export_Procedure
1320 or else
1321 Prag_Id = Pragma_Export_Valued_Procedure
1322 or else
1323 Prag_Id = Pragma_Export_Function)
1324 then
1325 for J in Externals.First .. Externals.Last loop
1326 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1327 Error_Msg_Sloc := Sloc (Externals.Table (J));
1328 Error_Msg_N ("external name duplicates name given#", Nam);
1329 exit;
1330 end if;
1331 end loop;
1332
1333 Externals.Append (Nam);
1334 end if;
1335 end Check_Duplicated_Export_Name;
1336
996ae0b0
RK
1337 -------------------------
1338 -- Check_First_Subtype --
1339 -------------------------
1340
1341 procedure Check_First_Subtype (Arg : Node_Id) is
1342 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
b4ca2d2c 1343 Ent : constant Entity_Id := Entity (Argx);
229db351 1344
996ae0b0 1345 begin
b4ca2d2c
AC
1346 if Is_First_Subtype (Ent) then
1347 null;
1348
1349 elsif Is_Type (Ent) then
996ae0b0
RK
1350 Error_Pragma_Arg
1351 ("pragma% cannot apply to subtype", Argx);
b4ca2d2c
AC
1352
1353 elsif Is_Object (Ent) then
1354 Error_Pragma_Arg
1355 ("pragma% cannot apply to object, requires a type", Argx);
1356
1357 else
1358 Error_Pragma_Arg
1359 ("pragma% cannot apply to&, requires a type", Argx);
996ae0b0
RK
1360 end if;
1361 end Check_First_Subtype;
1362
1363 ---------------------------
1364 -- Check_In_Main_Program --
1365 ---------------------------
1366
1367 procedure Check_In_Main_Program is
1368 P : constant Node_Id := Parent (N);
1369
1370 begin
1371 -- Must be at in subprogram body
1372
1373 if Nkind (P) /= N_Subprogram_Body then
1374 Error_Pragma ("% pragma allowed only in subprogram");
1375
1376 -- Otherwise warn if obviously not main program
1377
1378 elsif Present (Parameter_Specifications (Specification (P)))
fbf5a39b 1379 or else not Is_Compilation_Unit (Defining_Entity (P))
996ae0b0 1380 then
1b24ada5 1381 Error_Msg_Name_1 := Pname;
996ae0b0
RK
1382 Error_Msg_N
1383 ("?pragma% is only effective in main program", N);
1384 end if;
1385 end Check_In_Main_Program;
1386
1387 ---------------------------------------
1388 -- Check_Interrupt_Or_Attach_Handler --
1389 ---------------------------------------
1390
1391 procedure Check_Interrupt_Or_Attach_Handler is
0f1a6a0b 1392 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
d9e0a587 1393 Handler_Proc, Proc_Scope : Entity_Id;
996ae0b0
RK
1394
1395 begin
1396 Analyze (Arg1_X);
1397
d9e0a587 1398 if Prag_Id = Pragma_Interrupt_Handler then
9f4fd324 1399 Check_Restriction (No_Dynamic_Attachment, N);
996ae0b0
RK
1400 end if;
1401
d9e0a587
EB
1402 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1403 Proc_Scope := Scope (Handler_Proc);
fbf5a39b 1404
d9e0a587
EB
1405 -- On AAMP only, a pragma Interrupt_Handler is supported for
1406 -- nonprotected parameterless procedures.
fbf5a39b 1407
d9e0a587
EB
1408 if not AAMP_On_Target
1409 or else Prag_Id = Pragma_Attach_Handler
1410 then
1411 if Ekind (Proc_Scope) /= E_Protected_Type then
996ae0b0 1412 Error_Pragma_Arg
fbf5a39b
AC
1413 ("argument of pragma% must be protected procedure", Arg1);
1414 end if;
1415
d9e0a587
EB
1416 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1417 Error_Pragma ("pragma% must be in protected definition");
996ae0b0 1418 end if;
d9e0a587 1419 end if;
996ae0b0 1420
d9e0a587
EB
1421 if not Is_Library_Level_Entity (Proc_Scope)
1422 or else (AAMP_On_Target
1423 and then not Is_Library_Level_Entity (Handler_Proc))
1424 then
1425 Error_Pragma_Arg
1426 ("argument for pragma% must be library level entity", Arg1);
1427 end if;
6f123e48 1428
313d6f2c 1429 -- AI05-0033: A pragma cannot appear within a generic body, because
af31bffb
AC
1430 -- instance can be in a nested scope. The check that protected type
1431 -- is itself a library-level declaration is done elsewhere.
1432
313d6f2c
AC
1433 -- Note: we omit this check in Codepeer mode to properly handle code
1434 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1435
6f123e48 1436 if Inside_A_Generic then
af31bffb 1437 if Ekind (Scope (Current_Scope)) = E_Generic_Package
313d6f2c
AC
1438 and then In_Package_Body (Scope (Current_Scope))
1439 and then not CodePeer_Mode
af31bffb
AC
1440 then
1441 Error_Pragma ("pragma% cannot be used inside a generic");
1442 end if;
6f123e48 1443 end if;
996ae0b0
RK
1444 end Check_Interrupt_Or_Attach_Handler;
1445
1446 -------------------------------------------
1447 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1448 -------------------------------------------
1449
1450 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1451 P : Node_Id;
1452
1453 begin
1454 P := Parent (N);
1455 loop
1456 if No (P) then
1457 exit;
1458
1459 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1460 exit;
1461
d7ba4df4
RD
1462 elsif Nkind_In (P, N_Package_Specification,
1463 N_Block_Statement)
1464 then
996ae0b0
RK
1465 return;
1466
1467 -- Note: the following tests seem a little peculiar, because
1468 -- they test for bodies, but if we were in the statement part
1469 -- of the body, we would already have hit the handled statement
1470 -- sequence, so the only way we get here is by being in the
1471 -- declarative part of the body.
1472
f2131422
JM
1473 elsif Nkind_In (P, N_Subprogram_Body,
1474 N_Package_Body,
1475 N_Task_Body,
1476 N_Entry_Body)
996ae0b0
RK
1477 then
1478 return;
1479 end if;
1480
1481 P := Parent (P);
1482 end loop;
1483
1484 Error_Pragma ("pragma% is not in declarative part or package spec");
996ae0b0
RK
1485 end Check_Is_In_Decl_Part_Or_Package_Spec;
1486
1487 -------------------------
1488 -- Check_No_Identifier --
1489 -------------------------
1490
1491 procedure Check_No_Identifier (Arg : Node_Id) is
1492 begin
0f1a6a0b
AC
1493 if Nkind (Arg) = N_Pragma_Argument_Association
1494 and then Chars (Arg) /= No_Name
1495 then
996ae0b0
RK
1496 Error_Pragma_Arg_Ident
1497 ("pragma% does not permit identifier& here", Arg);
1498 end if;
1499 end Check_No_Identifier;
1500
1501 --------------------------
1502 -- Check_No_Identifiers --
1503 --------------------------
1504
1505 procedure Check_No_Identifiers is
1506 Arg_Node : Node_Id;
996ae0b0
RK
1507 begin
1508 if Arg_Count > 0 then
1509 Arg_Node := Arg1;
996ae0b0
RK
1510 while Present (Arg_Node) loop
1511 Check_No_Identifier (Arg_Node);
1512 Next (Arg_Node);
1513 end loop;
1514 end if;
1515 end Check_No_Identifiers;
1516
9eea4346
GB
1517 ------------------------
1518 -- Check_No_Link_Name --
1519 ------------------------
1520
1521 procedure Check_No_Link_Name is
1522 begin
1523 if Present (Arg3)
1524 and then Chars (Arg3) = Name_Link_Name
1525 then
1526 Arg4 := Arg3;
1527 end if;
1528
1529 if Present (Arg4) then
1530 Error_Pragma_Arg
1531 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1532 end if;
1533 end Check_No_Link_Name;
1534
996ae0b0
RK
1535 -------------------------------
1536 -- Check_Optional_Identifier --
1537 -------------------------------
1538
1539 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1540 begin
811ef5ba
RD
1541 if Present (Arg)
1542 and then Nkind (Arg) = N_Pragma_Argument_Association
1543 and then Chars (Arg) /= No_Name
1544 then
996ae0b0 1545 if Chars (Arg) /= Id then
1b24ada5 1546 Error_Msg_Name_1 := Pname;
996ae0b0
RK
1547 Error_Msg_Name_2 := Id;
1548 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1549 raise Pragma_Exit;
1550 end if;
1551 end if;
1552 end Check_Optional_Identifier;
1553
1554 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1555 begin
1556 Name_Buffer (1 .. Id'Length) := Id;
1557 Name_Len := Id'Length;
1558 Check_Optional_Identifier (Arg, Name_Find);
1559 end Check_Optional_Identifier;
1560
21d27997
RD
1561 --------------------------------------
1562 -- Check_Precondition_Postcondition --
1563 --------------------------------------
1564
1565 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1566 P : Node_Id;
21d27997
RD
1567 PO : Node_Id;
1568
3023ce42 1569 procedure Chain_PPC (PO : Node_Id);
393e63ce
RD
1570 -- If PO is a subprogram declaration node (or a generic subprogram
1571 -- declaration node), then the precondition/postcondition applies
1572 -- to this subprogram and the processing for the pragma is completed.
1573 -- Otherwise the pragma is misplaced.
3023ce42
ES
1574
1575 ---------------
1576 -- Chain_PPC --
1577 ---------------
1578
1579 procedure Chain_PPC (PO : Node_Id) is
811ef5ba
RD
1580 S : Entity_Id;
1581 P : Node_Id;
3023ce42
ES
1582
1583 begin
811ef5ba
RD
1584 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1585 if not From_Aspect_Specification (N) then
1586 Error_Pragma
1587 ("pragma% cannot be applied to abstract subprogram");
1588
1589 elsif Class_Present (N) then
1fb00064 1590 null;
811ef5ba
RD
1591
1592 else
1593 Error_Pragma
1594 ("aspect % requires ''Class for abstract subprogram");
1595 end if;
1596
1597 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1fb00064
AC
1598 N_Generic_Subprogram_Declaration,
1599 N_Entry_Declaration)
393e63ce
RD
1600 then
1601 Pragma_Misplaced;
1602 end if;
1603
1fb00064 1604 -- Here if we have [generic] subprogram or entry declaration
393e63ce 1605
1fb00064
AC
1606 if Nkind (PO) = N_Entry_Declaration then
1607 S := Defining_Entity (PO);
1608 else
1609 S := Defining_Unit_Name (Specification (PO));
1610 end if;
3023ce42 1611
beacce02
AC
1612 -- Make sure we do not have the case of a precondition pragma when
1613 -- the Pre'Class aspect is present.
811ef5ba
RD
1614
1615 -- We do this by looking at pragmas already chained to the entity
1616 -- since the aspect derived pragma will be put on this list first.
1617
beacce02
AC
1618 if Pragma_Name (N) = Name_Precondition then
1619 if not From_Aspect_Specification (N) then
1620 P := Spec_PPC_List (S);
1621 while Present (P) loop
1622 if Pragma_Name (P) = Name_Precondition
1623 and then From_Aspect_Specification (P)
1624 and then Class_Present (P)
1625 then
1626 Error_Msg_Sloc := Sloc (P);
1627 Error_Pragma
1628 ("pragma% not allowed, `Pre''Class` aspect given#");
811ef5ba
RD
1629 end if;
1630
beacce02
AC
1631 P := Next_Pragma (P);
1632 end loop;
1633 end if;
1634 end if;
811ef5ba 1635
beacce02
AC
1636 -- Similarly check for Pre with inherited Pre'Class. Note that
1637 -- we cover the aspect case as well here.
1638
1639 if Pragma_Name (N) = Name_Precondition
1640 and then not Class_Present (N)
1641 then
1642 declare
1643 Inherited : constant Subprogram_List :=
1644 Inherited_Subprograms (S);
1645 P : Node_Id;
1646
1647 begin
1648 for J in Inherited'Range loop
1649 P := Spec_PPC_List (Inherited (J));
1650 while Present (P) loop
1651 if Pragma_Name (P) = Name_Precondition
1652 and then Class_Present (P)
1653 then
1654 Error_Msg_Sloc := Sloc (P);
1655 Error_Pragma
1656 ("pragma% not allowed, `Pre''Class` "
1657 & "aspect inherited from#");
1658 end if;
1659
1660 P := Next_Pragma (P);
1661 end loop;
1662 end loop;
1663 end;
811ef5ba
RD
1664 end if;
1665
308e6f3a 1666 -- Note: we do not analyze the pragma at this point. Instead we
1fb00064
AC
1667 -- delay this analysis until the end of the declarative part in
1668 -- which the pragma appears. This implements the required delay
1669 -- in this analysis, allowing forward references. The analysis
1670 -- happens at the end of Analyze_Declarations.
3023ce42
ES
1671
1672 -- Chain spec PPC pragma to list for subprogram
1673
1674 Set_Next_Pragma (N, Spec_PPC_List (S));
1675 Set_Spec_PPC_List (S, N);
1676
1677 -- Return indicating spec case
1678
1679 In_Body := False;
1680 return;
1681 end Chain_PPC;
1682
1683 -- Start of processing for Check_Precondition_Postcondition
1684
21d27997
RD
1685 begin
1686 if not Is_List_Member (N) then
1687 Pragma_Misplaced;
1688 end if;
1689
1fb00064
AC
1690 -- Preanalyze message argument if present. Visibility in this
1691 -- argument is established at the point of pragma occurrence.
1692
1693 if Arg_Count = 2 then
1694 Check_Optional_Identifier (Arg2, Name_Message);
1695 Preanalyze_Spec_Expression
1696 (Get_Pragma_Arg (Arg2), Standard_String);
1697 end if;
1698
b26be063 1699 -- Record if pragma is enabled
21d27997 1700
b26be063
AC
1701 if Check_Enabled (Pname) then
1702 Set_Pragma_Enabled (N);
1703 Set_SCO_Pragma_Enabled (Loc);
1704 end if;
21d27997 1705
3023ce42
ES
1706 -- If we are within an inlined body, the legality of the pragma
1707 -- has been checked already.
1708
1709 if In_Inlined_Body then
1710 In_Body := True;
1711 return;
1712 end if;
1713
21d27997
RD
1714 -- Search prior declarations
1715
1716 P := N;
1717 while Present (Prev (P)) loop
1718 P := Prev (P);
75bee270 1719
b3b9865d
AC
1720 -- If the previous node is a generic subprogram, do not go to to
1721 -- the original node, which is the unanalyzed tree: we need to
1722 -- attach the pre/postconditions to the analyzed version at this
1723 -- point. They get propagated to the original tree when analyzing
1724 -- the corresponding body.
75bee270
ES
1725
1726 if Nkind (P) not in N_Generic_Declaration then
1727 PO := Original_Node (P);
1728 else
1729 PO := P;
1730 end if;
21d27997
RD
1731
1732 -- Skip past prior pragma
1733
1734 if Nkind (PO) = N_Pragma then
1735 null;
1736
1737 -- Skip stuff not coming from source
1738
1739 elsif not Comes_From_Source (PO) then
1740 null;
1741
393e63ce 1742 -- Only remaining possibility is subprogram declaration
21d27997 1743
393e63ce 1744 else
3023ce42 1745 Chain_PPC (PO);
21d27997 1746 return;
21d27997
RD
1747 end if;
1748 end loop;
1749
b3b9865d
AC
1750 -- If we fall through loop, pragma is at start of list, so see if it
1751 -- is at the start of declarations of a subprogram body.
21d27997
RD
1752
1753 if Nkind (Parent (N)) = N_Subprogram_Body
1754 and then List_Containing (N) = Declarations (Parent (N))
1755 then
934a3a25
AC
1756 if Operating_Mode /= Generate_Code
1757 or else Inside_A_Generic
1758 then
beacce02 1759 -- Analyze pragma expression for correctness and for ASIS use
14037bbc
ES
1760
1761 Preanalyze_Spec_Expression
1762 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1763 end if;
1764
21d27997
RD
1765 In_Body := True;
1766 return;
1767
3023ce42 1768 -- See if it is in the pragmas after a library level subprogram
21d27997 1769
3023ce42 1770 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
393e63ce
RD
1771 Chain_PPC (Unit (Parent (Parent (N))));
1772 return;
21d27997 1773 end if;
3023ce42
ES
1774
1775 -- If we fall through, pragma was misplaced
1776
1777 Pragma_Misplaced;
21d27997
RD
1778 end Check_Precondition_Postcondition;
1779
996ae0b0
RK
1780 -----------------------------
1781 -- Check_Static_Constraint --
1782 -----------------------------
1783
1784 -- Note: for convenience in writing this procedure, in addition to
b3b9865d
AC
1785 -- the officially (i.e. by spec) allowed argument which is always a
1786 -- constraint, it also allows ranges and discriminant associations.
fbf5a39b 1787 -- Above is not clear ???
996ae0b0
RK
1788
1789 procedure Check_Static_Constraint (Constr : Node_Id) is
1790
21d27997
RD
1791 procedure Require_Static (E : Node_Id);
1792 -- Require given expression to be static expression
1793
996ae0b0
RK
1794 --------------------
1795 -- Require_Static --
1796 --------------------
1797
996ae0b0
RK
1798 procedure Require_Static (E : Node_Id) is
1799 begin
1800 if not Is_OK_Static_Expression (E) then
fbf5a39b
AC
1801 Flag_Non_Static_Expr
1802 ("non-static constraint not allowed in Unchecked_Union!", E);
996ae0b0
RK
1803 raise Pragma_Exit;
1804 end if;
1805 end Require_Static;
1806
1807 -- Start of processing for Check_Static_Constraint
1808
1809 begin
1810 case Nkind (Constr) is
1811 when N_Discriminant_Association =>
1812 Require_Static (Expression (Constr));
1813
1814 when N_Range =>
1815 Require_Static (Low_Bound (Constr));
1816 Require_Static (High_Bound (Constr));
1817
1818 when N_Attribute_Reference =>
1819 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1820 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1821
1822 when N_Range_Constraint =>
1823 Check_Static_Constraint (Range_Expression (Constr));
1824
1825 when N_Index_Or_Discriminant_Constraint =>
1826 declare
1d571f3b 1827 IDC : Entity_Id;
996ae0b0 1828 begin
1d571f3b 1829 IDC := First (Constraints (Constr));
996ae0b0
RK
1830 while Present (IDC) loop
1831 Check_Static_Constraint (IDC);
1832 Next (IDC);
1833 end loop;
1834 end;
1835
1836 when others =>
1837 null;
1838 end case;
1839 end Check_Static_Constraint;
1840
1841 --------------------------------------
1842 -- Check_Valid_Configuration_Pragma --
1843 --------------------------------------
1844
1b24ada5 1845 -- A configuration pragma must appear in the context clause of a
f3d57416 1846 -- compilation unit, and only other pragmas may precede it. Note that
1b24ada5 1847 -- the test also allows use in a configuration pragma file.
996ae0b0
RK
1848
1849 procedure Check_Valid_Configuration_Pragma is
1850 begin
1851 if not Is_Configuration_Pragma then
1852 Error_Pragma ("incorrect placement for configuration pragma%");
1853 end if;
1854 end Check_Valid_Configuration_Pragma;
1855
1856 -------------------------------------
1857 -- Check_Valid_Library_Unit_Pragma --
1858 -------------------------------------
1859
1860 procedure Check_Valid_Library_Unit_Pragma is
1861 Plist : List_Id;
1862 Parent_Node : Node_Id;
1863 Unit_Name : Entity_Id;
996ae0b0
RK
1864 Unit_Kind : Node_Kind;
1865 Unit_Node : Node_Id;
1866 Sindex : Source_File_Index;
1867
1868 begin
1869 if not Is_List_Member (N) then
1870 Pragma_Misplaced;
996ae0b0
RK
1871
1872 else
1873 Plist := List_Containing (N);
1874 Parent_Node := Parent (Plist);
1875
1876 if Parent_Node = Empty then
1877 Pragma_Misplaced;
1878
b3b9865d
AC
1879 -- Case of pragma appearing after a compilation unit. In this case
1880 -- it must have an argument with the corresponding name and must
1881 -- be part of the following pragmas of its parent.
996ae0b0
RK
1882
1883 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1884 if Plist /= Pragmas_After (Parent_Node) then
1885 Pragma_Misplaced;
1886
1887 elsif Arg_Count = 0 then
1888 Error_Pragma
1889 ("argument required if outside compilation unit");
1890
1891 else
1892 Check_No_Identifiers;
1893 Check_Arg_Count (1);
1894 Unit_Node := Unit (Parent (Parent_Node));
1895 Unit_Kind := Nkind (Unit_Node);
1896
0f1a6a0b 1897 Analyze (Get_Pragma_Arg (Arg1));
996ae0b0 1898
f02b8bb8 1899 if Unit_Kind = N_Generic_Subprogram_Declaration
996ae0b0
RK
1900 or else Unit_Kind = N_Subprogram_Declaration
1901 then
1902 Unit_Name := Defining_Entity (Unit_Node);
1903
f02b8bb8 1904 elsif Unit_Kind in N_Generic_Instantiation then
996ae0b0
RK
1905 Unit_Name := Defining_Entity (Unit_Node);
1906
1907 else
1908 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1909 end if;
1910
1911 if Chars (Unit_Name) /=
0f1a6a0b 1912 Chars (Entity (Get_Pragma_Arg (Arg1)))
996ae0b0
RK
1913 then
1914 Error_Pragma_Arg
1915 ("pragma% argument is not current unit name", Arg1);
1916 end if;
1917
1918 if Ekind (Unit_Name) = E_Package
1919 and then Present (Renamed_Entity (Unit_Name))
1920 then
1921 Error_Pragma ("pragma% not allowed for renamed package");
1922 end if;
1923 end if;
1924
1925 -- Pragma appears other than after a compilation unit
1926
1927 else
1928 -- Here we check for the generic instantiation case and also
1929 -- for the case of processing a generic formal package. We
1930 -- detect these cases by noting that the Sloc on the node
1931 -- does not belong to the current compilation unit.
1932
1933 Sindex := Source_Index (Current_Sem_Unit);
1934
1935 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1936 Rewrite (N, Make_Null_Statement (Loc));
1937 return;
1938
1939 -- If before first declaration, the pragma applies to the
1940 -- enclosing unit, and the name if present must be this name.
1941
1942 elsif Is_Before_First_Decl (N, Plist) then
1943 Unit_Node := Unit_Declaration_Node (Current_Scope);
1944 Unit_Kind := Nkind (Unit_Node);
1945
1946 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1947 Pragma_Misplaced;
1948
1949 elsif Unit_Kind = N_Subprogram_Body
1950 and then not Acts_As_Spec (Unit_Node)
1951 then
1952 Pragma_Misplaced;
1953
1954 elsif Nkind (Parent_Node) = N_Package_Body then
1955 Pragma_Misplaced;
1956
1957 elsif Nkind (Parent_Node) = N_Package_Specification
1958 and then Plist = Private_Declarations (Parent_Node)
1959 then
1960 Pragma_Misplaced;
1961
1962 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2fa9443e
ES
1963 or else Nkind (Parent_Node) =
1964 N_Generic_Subprogram_Declaration)
996ae0b0
RK
1965 and then Plist = Generic_Formal_Declarations (Parent_Node)
1966 then
1967 Pragma_Misplaced;
1968
1969 elsif Arg_Count > 0 then
0f1a6a0b 1970 Analyze (Get_Pragma_Arg (Arg1));
996ae0b0 1971
0f1a6a0b 1972 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
996ae0b0
RK
1973 Error_Pragma_Arg
1974 ("name in pragma% must be enclosing unit", Arg1);
1975 end if;
1976
1977 -- It is legal to have no argument in this context
1978
1979 else
1980 return;
1981 end if;
1982
1983 -- Error if not before first declaration. This is because a
1984 -- library unit pragma argument must be the name of a library
1985 -- unit (RM 10.1.5(7)), but the only names permitted in this
1986 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1987 -- generic subprogram declarations or generic instantiations.
1988
1989 else
1990 Error_Pragma
1991 ("pragma% misplaced, must be before first declaration");
1992 end if;
1993 end if;
1994 end if;
996ae0b0
RK
1995 end Check_Valid_Library_Unit_Pragma;
1996
5d09245e
AC
1997 -------------------
1998 -- Check_Variant --
1999 -------------------
2000
72e9f2b9 2001 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
5d09245e
AC
2002 Clist : constant Node_Id := Component_List (Variant);
2003 Comp : Node_Id;
2004
2005 begin
5d09245e
AC
2006 if not Is_Non_Empty_List (Component_Items (Clist)) then
2007 Error_Msg_N
2008 ("Unchecked_Union may not have empty component list",
2009 Variant);
2010 return;
2011 end if;
2012
2013 Comp := First (Component_Items (Clist));
2014 while Present (Comp) loop
72e9f2b9 2015 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
5d09245e 2016 Next (Comp);
5d09245e
AC
2017 end loop;
2018 end Check_Variant;
2019
996ae0b0
RK
2020 ------------------
2021 -- Error_Pragma --
2022 ------------------
2023
2024 procedure Error_Pragma (Msg : String) is
0f1a6a0b 2025 MsgF : String := Msg;
996ae0b0 2026 begin
1b24ada5 2027 Error_Msg_Name_1 := Pname;
0f1a6a0b
AC
2028 Fix_Error (MsgF);
2029 Error_Msg_N (MsgF, N);
996ae0b0
RK
2030 raise Pragma_Exit;
2031 end Error_Pragma;
2032
2033 ----------------------
2034 -- Error_Pragma_Arg --
2035 ----------------------
2036
2037 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
0f1a6a0b 2038 MsgF : String := Msg;
996ae0b0 2039 begin
1b24ada5 2040 Error_Msg_Name_1 := Pname;
0f1a6a0b
AC
2041 Fix_Error (MsgF);
2042 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
996ae0b0
RK
2043 raise Pragma_Exit;
2044 end Error_Pragma_Arg;
2045
2046 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
0f1a6a0b 2047 MsgF : String := Msg1;
996ae0b0 2048 begin
1b24ada5 2049 Error_Msg_Name_1 := Pname;
0f1a6a0b
AC
2050 Fix_Error (MsgF);
2051 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
996ae0b0
RK
2052 Error_Pragma_Arg (Msg2, Arg);
2053 end Error_Pragma_Arg;
2054
2055 ----------------------------
2056 -- Error_Pragma_Arg_Ident --
2057 ----------------------------
2058
2059 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
0f1a6a0b 2060 MsgF : String := Msg;
996ae0b0 2061 begin
1b24ada5 2062 Error_Msg_Name_1 := Pname;
0f1a6a0b
AC
2063 Fix_Error (MsgF);
2064 Error_Msg_N (MsgF, Arg);
996ae0b0
RK
2065 raise Pragma_Exit;
2066 end Error_Pragma_Arg_Ident;
2067
b039b10e
ST
2068 ----------------------
2069 -- Error_Pragma_Ref --
2070 ----------------------
2071
2072 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
0f1a6a0b 2073 MsgF : String := Msg;
b039b10e
ST
2074 begin
2075 Error_Msg_Name_1 := Pname;
0f1a6a0b 2076 Fix_Error (MsgF);
b039b10e 2077 Error_Msg_Sloc := Sloc (Ref);
0f1a6a0b 2078 Error_Msg_NE (MsgF, N, Ref);
b039b10e
ST
2079 raise Pragma_Exit;
2080 end Error_Pragma_Ref;
2081
996ae0b0
RK
2082 ------------------------
2083 -- Find_Lib_Unit_Name --
2084 ------------------------
2085
2086 function Find_Lib_Unit_Name return Entity_Id is
2087 begin
2088 -- Return inner compilation unit entity, for case of nested
2089 -- categorization pragmas. This happens in generic unit.
2090
2091 if Nkind (Parent (N)) = N_Package_Specification
2092 and then Defining_Entity (Parent (N)) /= Current_Scope
2093 then
2094 return Defining_Entity (Parent (N));
996ae0b0
RK
2095 else
2096 return Current_Scope;
2097 end if;
2098 end Find_Lib_Unit_Name;
2099
2100 ----------------------------
2101 -- Find_Program_Unit_Name --
2102 ----------------------------
2103
2104 procedure Find_Program_Unit_Name (Id : Node_Id) is
2105 Unit_Name : Entity_Id;
2106 Unit_Kind : Node_Kind;
2107 P : constant Node_Id := Parent (N);
2108
2109 begin
2110 if Nkind (P) = N_Compilation_Unit then
2111 Unit_Kind := Nkind (Unit (P));
2112
2113 if Unit_Kind = N_Subprogram_Declaration
2114 or else Unit_Kind = N_Package_Declaration
2115 or else Unit_Kind in N_Generic_Declaration
2116 then
2117 Unit_Name := Defining_Entity (Unit (P));
2118
2119 if Chars (Id) = Chars (Unit_Name) then
2120 Set_Entity (Id, Unit_Name);
2121 Set_Etype (Id, Etype (Unit_Name));
2122 else
2123 Set_Etype (Id, Any_Type);
2124 Error_Pragma
2125 ("cannot find program unit referenced by pragma%");
2126 end if;
2127
2128 else
2129 Set_Etype (Id, Any_Type);
2130 Error_Pragma ("pragma% inapplicable to this unit");
2131 end if;
2132
2133 else
2134 Analyze (Id);
2135 end if;
996ae0b0
RK
2136 end Find_Program_Unit_Name;
2137
d9e0a587
EB
2138 -----------------------------------------
2139 -- Find_Unique_Parameterless_Procedure --
2140 -----------------------------------------
2141
2142 function Find_Unique_Parameterless_Procedure
2143 (Name : Entity_Id;
2144 Arg : Node_Id) return Entity_Id
2145 is
2146 Proc : Entity_Id := Empty;
2147
2148 begin
2149 -- The body of this procedure needs some comments ???
2150
2151 if not Is_Entity_Name (Name) then
2152 Error_Pragma_Arg
2153 ("argument of pragma% must be entity name", Arg);
2154
2155 elsif not Is_Overloaded (Name) then
2156 Proc := Entity (Name);
2157
2158 if Ekind (Proc) /= E_Procedure
8a95f4e8
RD
2159 or else Present (First_Formal (Proc))
2160 then
d9e0a587
EB
2161 Error_Pragma_Arg
2162 ("argument of pragma% must be parameterless procedure", Arg);
2163 end if;
2164
2165 else
2166 declare
2167 Found : Boolean := False;
2168 It : Interp;
2169 Index : Interp_Index;
2170
2171 begin
2172 Get_First_Interp (Name, Index, It);
2173 while Present (It.Nam) loop
2174 Proc := It.Nam;
2175
2176 if Ekind (Proc) = E_Procedure
2177 and then No (First_Formal (Proc))
2178 then
2179 if not Found then
2180 Found := True;
2181 Set_Entity (Name, Proc);
2182 Set_Is_Overloaded (Name, False);
2183 else
2184 Error_Pragma_Arg
2185 ("ambiguous handler name for pragma% ", Arg);
2186 end if;
2187 end if;
2188
2189 Get_Next_Interp (Index, It);
2190 end loop;
2191
2192 if not Found then
2193 Error_Pragma_Arg
2194 ("argument of pragma% must be parameterless procedure",
2195 Arg);
2196 else
2197 Proc := Entity (Name);
2198 end if;
2199 end;
2200 end if;
2201
2202 return Proc;
2203 end Find_Unique_Parameterless_Procedure;
2204
0f1a6a0b
AC
2205 ---------------
2206 -- Fix_Error --
2207 ---------------
2208
2209 procedure Fix_Error (Msg : in out String) is
2210 begin
2211 if From_Aspect_Specification (N) then
2212 for J in Msg'First .. Msg'Last - 5 loop
2213 if Msg (J .. J + 5) = "pragma" then
2214 Msg (J .. J + 5) := "aspect";
2215 end if;
2216 end loop;
0f1a6a0b 2217
811ef5ba
RD
2218 if Error_Msg_Name_1 = Name_Precondition then
2219 Error_Msg_Name_1 := Name_Pre;
2220 elsif Error_Msg_Name_1 = Name_Postcondition then
2221 Error_Msg_Name_1 := Name_Post;
2222 end if;
0f1a6a0b
AC
2223 end if;
2224 end Fix_Error;
2225
996ae0b0
RK
2226 -------------------------
2227 -- Gather_Associations --
2228 -------------------------
2229
2230 procedure Gather_Associations
2231 (Names : Name_List;
2232 Args : out Args_List)
2233 is
2234 Arg : Node_Id;
2235
2236 begin
2237 -- Initialize all parameters to Empty
2238
2239 for J in Args'Range loop
2240 Args (J) := Empty;
2241 end loop;
2242
2243 -- That's all we have to do if there are no argument associations
2244
2245 if No (Pragma_Argument_Associations (N)) then
2246 return;
2247 end if;
2248
2249 -- Otherwise first deal with any positional parameters present
2250
2251 Arg := First (Pragma_Argument_Associations (N));
996ae0b0
RK
2252 for Index in Args'Range loop
2253 exit when No (Arg) or else Chars (Arg) /= No_Name;
0f1a6a0b 2254 Args (Index) := Get_Pragma_Arg (Arg);
996ae0b0
RK
2255 Next (Arg);
2256 end loop;
2257
2258 -- Positional parameters all processed, if any left, then we
2259 -- have too many positional parameters.
2260
2261 if Present (Arg) and then Chars (Arg) = No_Name then
2262 Error_Pragma_Arg
2263 ("too many positional associations for pragma%", Arg);
2264 end if;
2265
2266 -- Process named parameters if any are present
2267
2268 while Present (Arg) loop
2269 if Chars (Arg) = No_Name then
2270 Error_Pragma_Arg
2271 ("positional association cannot follow named association",
2272 Arg);
2273
2274 else
2275 for Index in Names'Range loop
2276 if Names (Index) = Chars (Arg) then
2277 if Present (Args (Index)) then
2278 Error_Pragma_Arg
2279 ("duplicate argument association for pragma%", Arg);
2280 else
0f1a6a0b 2281 Args (Index) := Get_Pragma_Arg (Arg);
996ae0b0
RK
2282 exit;
2283 end if;
2284 end if;
2285
2286 if Index = Names'Last then
1b24ada5 2287 Error_Msg_Name_1 := Pname;
07fc65c4
GB
2288 Error_Msg_N ("pragma% does not allow & argument", Arg);
2289
2290 -- Check for possible misspelling
2291
2292 for Index1 in Names'Range loop
2293 if Is_Bad_Spelling_Of
470cd9e9 2294 (Chars (Arg), Names (Index1))
07fc65c4
GB
2295 then
2296 Error_Msg_Name_1 := Names (Index1);
0c020dde
AC
2297 Error_Msg_N -- CODEFIX
2298 ("\possible misspelling of%", Arg);
07fc65c4
GB
2299 exit;
2300 end if;
2301 end loop;
2302
2303 raise Pragma_Exit;
996ae0b0
RK
2304 end if;
2305 end loop;
2306 end if;
2307
2308 Next (Arg);
2309 end loop;
2310 end Gather_Associations;
2311
996ae0b0
RK
2312 -----------------
2313 -- GNAT_Pragma --
2314 -----------------
2315
2316 procedure GNAT_Pragma is
2317 begin
2318 Check_Restriction (No_Implementation_Pragmas, N);
2319 end GNAT_Pragma;
2320
2321 --------------------------
2322 -- Is_Before_First_Decl --
2323 --------------------------
2324
2325 function Is_Before_First_Decl
2326 (Pragma_Node : Node_Id;
a9f4e3d2 2327 Decls : List_Id) return Boolean
996ae0b0
RK
2328 is
2329 Item : Node_Id := First (Decls);
2330
2331 begin
2332 -- Only other pragmas can come before this pragma
2333
2334 loop
2335 if No (Item) or else Nkind (Item) /= N_Pragma then
2336 return False;
2337
2338 elsif Item = Pragma_Node then
2339 return True;
2340 end if;
2341
2342 Next (Item);
2343 end loop;
996ae0b0
RK
2344 end Is_Before_First_Decl;
2345
2346 -----------------------------
2347 -- Is_Configuration_Pragma --
2348 -----------------------------
2349
1b24ada5
RD
2350 -- A configuration pragma must appear in the context clause of a
2351 -- compilation unit, and only other pragmas may precede it. Note that
2352 -- the test below also permits use in a configuration pragma file.
996ae0b0
RK
2353
2354 function Is_Configuration_Pragma return Boolean is
2355 Lis : constant List_Id := List_Containing (N);
2356 Par : constant Node_Id := Parent (N);
2357 Prg : Node_Id;
2358
2359 begin
2360 -- If no parent, then we are in the configuration pragma file,
2361 -- so the placement is definitely appropriate.
2362
2363 if No (Par) then
2364 return True;
2365
2366 -- Otherwise we must be in the context clause of a compilation unit
2367 -- and the only thing allowed before us in the context list is more
2368 -- configuration pragmas.
2369
2370 elsif Nkind (Par) = N_Compilation_Unit
2371 and then Context_Items (Par) = Lis
2372 then
2373 Prg := First (Lis);
2374
2375 loop
2376 if Prg = N then
2377 return True;
2378 elsif Nkind (Prg) /= N_Pragma then
2379 return False;
2380 end if;
2381
2382 Next (Prg);
2383 end loop;
2384
2385 else
2386 return False;
2387 end if;
996ae0b0
RK
2388 end Is_Configuration_Pragma;
2389
ac9e9918
RD
2390 --------------------------
2391 -- Is_In_Context_Clause --
2392 --------------------------
2393
2394 function Is_In_Context_Clause return Boolean is
2395 Plist : List_Id;
2396 Parent_Node : Node_Id;
2397
2398 begin
2399 if not Is_List_Member (N) then
2400 return False;
2401
2402 else
2403 Plist := List_Containing (N);
2404 Parent_Node := Parent (Plist);
2405
2406 if Parent_Node = Empty
2407 or else Nkind (Parent_Node) /= N_Compilation_Unit
2408 or else Context_Items (Parent_Node) /= Plist
2409 then
2410 return False;
2411 end if;
2412 end if;
2413
2414 return True;
2415 end Is_In_Context_Clause;
2416
2417 ---------------------------------
2418 -- Is_Static_String_Expression --
2419 ---------------------------------
2420
2421 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2422 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2423
2424 begin
2425 Analyze_And_Resolve (Argx);
2426 return Is_OK_Static_Expression (Argx)
2427 and then Nkind (Argx) = N_String_Literal;
2428 end Is_Static_String_Expression;
2429
996ae0b0
RK
2430 ----------------------
2431 -- Pragma_Misplaced --
2432 ----------------------
2433
2434 procedure Pragma_Misplaced is
2435 begin
2436 Error_Pragma ("incorrect placement of pragma%");
2437 end Pragma_Misplaced;
2438
2439 ------------------------------------
2440 -- Process Atomic_Shared_Volatile --
2441 ------------------------------------
2442
2443 procedure Process_Atomic_Shared_Volatile is
2444 E_Id : Node_Id;
2445 E : Entity_Id;
2446 D : Node_Id;
2447 K : Node_Kind;
07fc65c4 2448 Utyp : Entity_Id;
996ae0b0 2449
0da2c8ac 2450 procedure Set_Atomic (E : Entity_Id);
21d27997
RD
2451 -- Set given type as atomic, and if no explicit alignment was given,
2452 -- set alignment to unknown, since back end knows what the alignment
2453 -- requirements are for atomic arrays. Note: this step is necessary
2454 -- for derived types.
0da2c8ac
AC
2455
2456 ----------------
2457 -- Set_Atomic --
2458 ----------------
2459
2460 procedure Set_Atomic (E : Entity_Id) is
2461 begin
eaba57fb 2462 Set_Is_Atomic (E);
0da2c8ac 2463
eaba57fb 2464 if not Has_Alignment_Clause (E) then
0da2c8ac
AC
2465 Set_Alignment (E, Uint_0);
2466 end if;
2467 end Set_Atomic;
2468
2469 -- Start of processing for Process_Atomic_Shared_Volatile
2470
996ae0b0 2471 begin
996ae0b0
RK
2472 Check_Ada_83_Warning;
2473 Check_No_Identifiers;
2474 Check_Arg_Count (1);
2475 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 2476 E_Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
2477
2478 if Etype (E_Id) = Any_Type then
2479 return;
2480 end if;
2481
2482 E := Entity (E_Id);
2483 D := Declaration_Node (E);
2484 K := Nkind (D);
2485
af31bffb
AC
2486 -- Check duplicate before we chain ourselves!
2487
2488 Check_Duplicate_Pragma (E);
2489
2490 -- Now check appropriateness of the entity
2491
996ae0b0
RK
2492 if Is_Type (E) then
2493 if Rep_Item_Too_Early (E, N)
2494 or else
2495 Rep_Item_Too_Late (E, N)
2496 then
2497 return;
2498 else
2499 Check_First_Subtype (Arg1);
2500 end if;
2501
2502 if Prag_Id /= Pragma_Volatile then
0da2c8ac
AC
2503 Set_Atomic (E);
2504 Set_Atomic (Underlying_Type (E));
2505 Set_Atomic (Base_Type (E));
996ae0b0
RK
2506 end if;
2507
21d27997
RD
2508 -- Attribute belongs on the base type. If the view of the type is
2509 -- currently private, it also belongs on the underlying type.
fbf5a39b 2510
eaba57fb
RD
2511 Set_Is_Volatile (Base_Type (E));
2512 Set_Is_Volatile (Underlying_Type (E));
996ae0b0 2513
eaba57fb
RD
2514 Set_Treat_As_Volatile (E);
2515 Set_Treat_As_Volatile (Underlying_Type (E));
fbf5a39b 2516
996ae0b0
RK
2517 elsif K = N_Object_Declaration
2518 or else (K = N_Component_Declaration
2519 and then Original_Record_Component (E) = E)
2520 then
2521 if Rep_Item_Too_Late (E, N) then
2522 return;
2523 end if;
2524
2525 if Prag_Id /= Pragma_Volatile then
eaba57fb 2526 Set_Is_Atomic (E);
07fc65c4 2527
21d27997
RD
2528 -- If the object declaration has an explicit initialization, a
2529 -- temporary may have to be created to hold the expression, to
2530 -- ensure that access to the object remain atomic.
fbf5a39b
AC
2531
2532 if Nkind (Parent (E)) = N_Object_Declaration
2533 and then Present (Expression (Parent (E)))
2534 then
2535 Set_Has_Delayed_Freeze (E);
2536 end if;
2537
b3b9865d
AC
2538 -- An interesting improvement here. If an object of type X is
2539 -- declared atomic, and the type X is not atomic, that's a
2540 -- pity, since it may not have appropriate alignment etc. We
2541 -- can rescue this in the special case where the object and
2542 -- type are in the same unit by just setting the type as
2543 -- atomic, so that the back end will process it as atomic.
07fc65c4
GB
2544
2545 Utyp := Underlying_Type (Etype (E));
2546
2547 if Present (Utyp)
2548 and then Sloc (E) > No_Location
2549 and then Sloc (Utyp) > No_Location
2550 and then
2551 Get_Source_File_Index (Sloc (E)) =
2552 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2553 then
eaba57fb 2554 Set_Is_Atomic (Underlying_Type (Etype (E)));
07fc65c4 2555 end if;
996ae0b0
RK
2556 end if;
2557
2558 Set_Is_Volatile (E);
fbf5a39b 2559 Set_Treat_As_Volatile (E);
996ae0b0
RK
2560
2561 else
2562 Error_Pragma_Arg
2563 ("inappropriate entity for pragma%", Arg1);
2564 end if;
2565 end Process_Atomic_Shared_Volatile;
2566
874a0341
RD
2567 -------------------------------------------
2568 -- Process_Compile_Time_Warning_Or_Error --
2569 -------------------------------------------
2570
2571 procedure Process_Compile_Time_Warning_Or_Error is
2572 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2573
2574 begin
874a0341
RD
2575 Check_Arg_Count (2);
2576 Check_No_Identifiers;
2577 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2578 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2579
2580 if Compile_Time_Known_Value (Arg1x) then
2581 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2582 declare
2583 Str : constant String_Id :=
2584 Strval (Get_Pragma_Arg (Arg2));
2585 Len : constant Int := String_Length (Str);
2586 Cont : Boolean;
2587 Ptr : Nat;
2588 CC : Char_Code;
2589 C : Character;
1b24ada5
RD
2590 Cent : constant Entity_Id :=
2591 Cunit_Entity (Current_Sem_Unit);
2592
2593 Force : constant Boolean :=
2594 Prag_Id = Pragma_Compile_Time_Warning
2595 and then
2596 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2597 and then (Ekind (Cent) /= E_Package
2598 or else not In_Private_Part (Cent));
2599 -- Set True if this is the warning case, and we are in the
2600 -- visible part of a package spec, or in a subprogram spec,
2601 -- in which case we want to force the client to see the
2602 -- warning, even though it is not in the main unit.
874a0341
RD
2603
2604 begin
b3b9865d
AC
2605 -- Loop through segments of message separated by line feeds.
2606 -- We output these segments as separate messages with
2607 -- continuation marks for all but the first.
874a0341 2608
1b24ada5
RD
2609 Cont := False;
2610 Ptr := 1;
874a0341
RD
2611 loop
2612 Error_Msg_Strlen := 0;
2613
b3b9865d
AC
2614 -- Loop to copy characters from argument to error message
2615 -- string buffer.
874a0341
RD
2616
2617 loop
2618 exit when Ptr > Len;
2619 CC := Get_String_Char (Str, Ptr);
2620 Ptr := Ptr + 1;
2621
2622 -- Ignore wide chars ??? else store character
2623
2624 if In_Character_Range (CC) then
2625 C := Get_Character (CC);
2626 exit when C = ASCII.LF;
2627 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2628 Error_Msg_String (Error_Msg_Strlen) := C;
2629 end if;
2630 end loop;
2631
2632 -- Here with one line ready to go
2633
2634 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2635
1b24ada5
RD
2636 -- If this is a warning in a spec, then we want clients
2637 -- to see the warning, so mark the message with the
2638 -- special sequence !! to force the warning. In the case
2639 -- of a package spec, we do not force this if we are in
2640 -- the private part of the spec.
2641
2642 if Force then
2643 if Cont = False then
2644 Error_Msg_N ("<~!!", Arg1);
2645 Cont := True;
2646 else
2647 Error_Msg_N ("\<~!!", Arg1);
2648 end if;
2649
2650 -- Error, rather than warning, or in a body, so we do not
2651 -- need to force visibility for client (error will be
2652 -- output in any case, and this is the situation in which
2653 -- we do not want a client to get a warning, since the
0b89eea8 2654 -- warning is in the body or the spec private part).
1b24ada5 2655
874a0341 2656 else
1b24ada5
RD
2657 if Cont = False then
2658 Error_Msg_N ("<~", Arg1);
2659 Cont := True;
2660 else
2661 Error_Msg_N ("\<~", Arg1);
2662 end if;
874a0341
RD
2663 end if;
2664
2665 exit when Ptr > Len;
2666 end loop;
2667 end;
2668 end if;
2669 end if;
2670 end Process_Compile_Time_Warning_Or_Error;
2671
996ae0b0
RK
2672 ------------------------
2673 -- Process_Convention --
2674 ------------------------
2675
2676 procedure Process_Convention
9fe2f33e
AC
2677 (C : out Convention_Id;
2678 Ent : out Entity_Id)
996ae0b0
RK
2679 is
2680 Id : Node_Id;
9fe2f33e 2681 E : Entity_Id;
996ae0b0 2682 E1 : Entity_Id;
996ae0b0 2683 Cname : Name_Id;
7324bf49 2684 Comp_Unit : Unit_Number_Type;
996ae0b0 2685
c28408b7
RD
2686 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2687 -- Called if we have more than one Export/Import/Convention pragma.
2688 -- This is generally illegal, but we have a special case of allowing
2689 -- Import and Interface to coexist if they specify the convention in
2690 -- a consistent manner. We are allowed to do this, since Interface is
2691 -- an implementation defined pragma, and we choose to do it since we
2692 -- know Rational allows this combination. S is the entity id of the
2693 -- subprogram in question. This procedure also sets the special flag
2694 -- Import_Interface_Present in both pragmas in the case where we do
2695 -- have matching Import and Interface pragmas.
2696
996ae0b0
RK
2697 procedure Set_Convention_From_Pragma (E : Entity_Id);
2698 -- Set convention in entity E, and also flag that the entity has a
2699 -- convention pragma. If entity is for a private or incomplete type,
2700 -- also set convention and flag on underlying type. This procedure
2701 -- also deals with the special case of C_Pass_By_Copy convention.
2702
c28408b7
RD
2703 -------------------------------
2704 -- Diagnose_Multiple_Pragmas --
2705 -------------------------------
2706
2707 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2708 Pdec : constant Node_Id := Declaration_Node (S);
2709 Decl : Node_Id;
2710 Err : Boolean;
2711
2712 function Same_Convention (Decl : Node_Id) return Boolean;
2713 -- Decl is a pragma node. This function returns True if this
2714 -- pragma has a first argument that is an identifier with a
2715 -- Chars field corresponding to the Convention_Id C.
2716
2717 function Same_Name (Decl : Node_Id) return Boolean;
2718 -- Decl is a pragma node. This function returns True if this
2719 -- pragma has a second argument that is an identifier with a
2720 -- Chars field that matches the Chars of the current subprogram.
2721
2722 ---------------------
2723 -- Same_Convention --
2724 ---------------------
2725
2726 function Same_Convention (Decl : Node_Id) return Boolean is
2727 Arg1 : constant Node_Id :=
2728 First (Pragma_Argument_Associations (Decl));
2729
2730 begin
2731 if Present (Arg1) then
2732 declare
2733 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2734 begin
2735 if Nkind (Arg) = N_Identifier
2736 and then Is_Convention_Name (Chars (Arg))
2737 and then Get_Convention_Id (Chars (Arg)) = C
2738 then
2739 return True;
2740 end if;
2741 end;
2742 end if;
2743
2744 return False;
2745 end Same_Convention;
2746
2747 ---------------
2748 -- Same_Name --
2749 ---------------
2750
2751 function Same_Name (Decl : Node_Id) return Boolean is
2752 Arg1 : constant Node_Id :=
2753 First (Pragma_Argument_Associations (Decl));
2754 Arg2 : Node_Id;
2755
2756 begin
2757 if No (Arg1) then
2758 return False;
2759 end if;
2760
2761 Arg2 := Next (Arg1);
2762
2763 if No (Arg2) then
2764 return False;
2765 end if;
2766
2767 declare
2768 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2769 begin
2770 if Nkind (Arg) = N_Identifier
2771 and then Chars (Arg) = Chars (S)
2772 then
2773 return True;
2774 end if;
2775 end;
2776
2777 return False;
2778 end Same_Name;
2779
2780 -- Start of processing for Diagnose_Multiple_Pragmas
2781
2782 begin
2783 Err := True;
2784
2785 -- Definitely give message if we have Convention/Export here
2786
2787 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
2788 null;
2789
2790 -- If we have an Import or Export, scan back from pragma to
2791 -- find any previous pragma applying to the same procedure.
2792 -- The scan will be terminated by the start of the list, or
2793 -- hitting the subprogram declaration. This won't allow one
2794 -- pragma to appear in the public part and one in the private
2795 -- part, but that seems very unlikely in practice.
2796
2797 else
2798 Decl := Prev (N);
2799 while Present (Decl) and then Decl /= Pdec loop
2800
2801 -- Look for pragma with same name as us
2802
2803 if Nkind (Decl) = N_Pragma
2804 and then Same_Name (Decl)
2805 then
2806 -- Give error if same as our pragma or Export/Convention
2807
2808 if Pragma_Name (Decl) = Name_Export
2809 or else
2810 Pragma_Name (Decl) = Name_Convention
2811 or else
2812 Pragma_Name (Decl) = Pragma_Name (N)
2813 then
2814 exit;
2815
2816 -- Case of Import/Interface or the other way round
2817
2818 elsif Pragma_Name (Decl) = Name_Interface
2819 or else
2820 Pragma_Name (Decl) = Name_Import
2821 then
2822 -- Here we know that we have Import and Interface. It
2823 -- doesn't matter which way round they are. See if
2824 -- they specify the same convention. If so, all OK,
2825 -- and set special flags to stop other messages
2826
2827 if Same_Convention (Decl) then
2828 Set_Import_Interface_Present (N);
2829 Set_Import_Interface_Present (Decl);
2830 Err := False;
2831
2832 -- If different conventions, special message
2833
2834 else
2835 Error_Msg_Sloc := Sloc (Decl);
2836 Error_Pragma_Arg
2837 ("convention differs from that given#", Arg1);
2838 return;
2839 end if;
2840 end if;
2841 end if;
2842
2843 Next (Decl);
2844 end loop;
2845 end if;
2846
2847 -- Give message if needed if we fall through those tests
2848
2849 if Err then
2850 Error_Pragma_Arg
2851 ("at most one Convention/Export/Import pragma is allowed",
2852 Arg2);
2853 end if;
2854 end Diagnose_Multiple_Pragmas;
2855
996ae0b0
RK
2856 --------------------------------
2857 -- Set_Convention_From_Pragma --
2858 --------------------------------
2859
2860 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2861 begin
ac9e9918
RD
2862 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2863 -- for an overridden dispatching operation. Technically this is
c690a2ec
RD
2864 -- an amendment and should only be done in Ada 2005 mode. However,
2865 -- this is clearly a mistake, since the problem that is addressed
2866 -- by this AI is that there is a clear gap in the RM!
57193e09
TQ
2867
2868 if Is_Dispatching_Operation (E)
2869 and then Present (Overridden_Operation (E))
2870 and then C /= Convention (Overridden_Operation (E))
2871 then
2872 Error_Pragma_Arg
2873 ("cannot change convention for " &
2874 "overridden dispatching operation",
2875 Arg1);
2876 end if;
2877
2878 -- Set the convention
2879
996ae0b0
RK
2880 Set_Convention (E, C);
2881 Set_Has_Convention_Pragma (E);
2882
15b682ca
GB
2883 if Is_Incomplete_Or_Private_Type (E)
2884 and then Present (Underlying_Type (E))
2885 then
996ae0b0
RK
2886 Set_Convention (Underlying_Type (E), C);
2887 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2888 end if;
2889
b3b9865d
AC
2890 -- A class-wide type should inherit the convention of the specific
2891 -- root type (although this isn't specified clearly by the RM).
996ae0b0
RK
2892
2893 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2894 Set_Convention (Class_Wide_Type (E), C);
2895 end if;
2896
c690a2ec
RD
2897 -- If the entity is a record type, then check for special case of
2898 -- C_Pass_By_Copy, which is treated the same as C except that the
2899 -- special record flag is set. This convention is only permitted
2900 -- on record types (see AI95-00131).
996ae0b0
RK
2901
2902 if Cname = Name_C_Pass_By_Copy then
2903 if Is_Record_Type (E) then
2904 Set_C_Pass_By_Copy (Base_Type (E));
2905 elsif Is_Incomplete_Or_Private_Type (E)
2906 and then Is_Record_Type (Underlying_Type (E))
2907 then
2908 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2909 else
2910 Error_Pragma_Arg
2911 ("C_Pass_By_Copy convention allowed only for record type",
2912 Arg2);
2913 end if;
2914 end if;
2915
b3b9865d
AC
2916 -- If the entity is a derived boolean type, check for the special
2917 -- case of convention C, C++, or Fortran, where we consider any
2918 -- nonzero value to represent true.
996ae0b0
RK
2919
2920 if Is_Discrete_Type (E)
2921 and then Root_Type (Etype (E)) = Standard_Boolean
2922 and then
2923 (C = Convention_C
2924 or else
2925 C = Convention_CPP
2926 or else
2927 C = Convention_Fortran)
2928 then
2929 Set_Nonzero_Is_True (Base_Type (E));
2930 end if;
2931 end Set_Convention_From_Pragma;
2932
2933 -- Start of processing for Process_Convention
2934
2935 begin
2936 Check_At_Least_N_Arguments (2);
996ae0b0 2937 Check_Optional_Identifier (Arg1, Name_Convention);
59e5fbe0 2938 Check_Arg_Is_Identifier (Arg1);
0f1a6a0b 2939 Cname := Chars (Get_Pragma_Arg (Arg1));
996ae0b0 2940
b3b9865d
AC
2941 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2942 -- tested again below to set the critical flag).
23b86353 2943
996ae0b0
RK
2944 if Cname = Name_C_Pass_By_Copy then
2945 C := Convention_C;
2946
2947 -- Otherwise we must have something in the standard convention list
2948
2949 elsif Is_Convention_Name (Cname) then
0f1a6a0b 2950 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
996ae0b0 2951
c690a2ec
RD
2952 -- In DEC VMS, it seems that there is an undocumented feature that
2953 -- any unrecognized convention is treated as the default, which for
2954 -- us is convention C. It does not seem so terrible to do this
2955 -- unconditionally, silently in the VMS case, and with a warning
2956 -- in the non-VMS case.
996ae0b0
RK
2957
2958 else
fbf5a39b 2959 if Warn_On_Export_Import and not OpenVMS_On_Target then
ed2233dc 2960 Error_Msg_N
996ae0b0 2961 ("?unrecognized convention name, C assumed",
0f1a6a0b 2962 Get_Pragma_Arg (Arg1));
996ae0b0
RK
2963 end if;
2964
2965 C := Convention_C;
2966 end if;
2967
996ae0b0 2968 Check_Optional_Identifier (Arg2, Name_Entity);
59e5fbe0 2969 Check_Arg_Is_Local_Name (Arg2);
996ae0b0 2970
0f1a6a0b 2971 Id := Get_Pragma_Arg (Arg2);
996ae0b0
RK
2972 Analyze (Id);
2973
2974 if not Is_Entity_Name (Id) then
2975 Error_Pragma_Arg ("entity name required", Arg2);
2976 end if;
2977
2978 E := Entity (Id);
2979
9fe2f33e
AC
2980 -- Set entity to return
2981
2982 Ent := E;
2983
c690a2ec
RD
2984 -- Go to renamed subprogram if present, since convention applies to
2985 -- the actual renamed entity, not to the renaming entity. If the
2986 -- subprogram is inherited, go to parent subprogram.
996ae0b0
RK
2987
2988 if Is_Subprogram (E)
2989 and then Present (Alias (E))
996ae0b0 2990 then
2fa9443e
ES
2991 if Nkind (Parent (Declaration_Node (E))) =
2992 N_Subprogram_Renaming_Declaration
c71c53a8 2993 then
b039b10e
ST
2994 if Scope (E) /= Scope (Alias (E)) then
2995 Error_Pragma_Ref
c27f2f15 2996 ("cannot apply pragma% to non-local entity&#", E);
b039b10e 2997 end if;
c27f2f15 2998
c71c53a8
ES
2999 E := Alias (E);
3000
f2131422
JM
3001 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3002 N_Private_Extension_Declaration)
c71c53a8
ES
3003 and then Scope (E) = Scope (Alias (E))
3004 then
3005 E := Alias (E);
9fe2f33e
AC
3006
3007 -- Return the parent subprogram the entity was inherited from
3008
3009 Ent := E;
c71c53a8 3010 end if;
996ae0b0
RK
3011 end if;
3012
c71c53a8 3013 -- Check that we are not applying this to a specless body
996ae0b0
RK
3014
3015 if Is_Subprogram (E)
3016 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3017 then
3018 Error_Pragma
3019 ("pragma% requires separate spec and must come before body");
3020 end if;
3021
3022 -- Check that we are not applying this to a named constant
3023
8a95f4e8 3024 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
1b24ada5 3025 Error_Msg_Name_1 := Pname;
996ae0b0
RK
3026 Error_Msg_N
3027 ("cannot apply pragma% to named constant!",
3028 Get_Pragma_Arg (Arg2));
3029 Error_Pragma_Arg
3030 ("\supply appropriate type for&!", Arg2);
3031 end if;
3032
66beb09b
ST
3033 if Ekind (E) = E_Enumeration_Literal then
3034 Error_Pragma ("enumeration literal not allowed for pragma%");
3035 end if;
3036
470cd9e9
RD
3037 -- Check for rep item appearing too early or too late
3038
996ae0b0
RK
3039 if Etype (E) = Any_Type
3040 or else Rep_Item_Too_Early (E, N)
3041 then
3042 raise Pragma_Exit;
15b682ca
GB
3043
3044 elsif Present (Underlying_Type (E)) then
996ae0b0
RK
3045 E := Underlying_Type (E);
3046 end if;
3047
3048 if Rep_Item_Too_Late (E, N) then
3049 raise Pragma_Exit;
3050 end if;
3051
3052 if Has_Convention_Pragma (E) then
c28408b7 3053 Diagnose_Multiple_Pragmas (E);
996ae0b0
RK
3054
3055 elsif Convention (E) = Convention_Protected
3056 or else Ekind (Scope (E)) = E_Protected_Type
3057 then
3058 Error_Pragma_Arg
3059 ("a protected operation cannot be given a different convention",
3060 Arg2);
3061 end if;
3062
3063 -- For Intrinsic, a subprogram is required
3064
3065 if C = Convention_Intrinsic
3066 and then not Is_Subprogram (E)
3067 and then not Is_Generic_Subprogram (E)
3068 then
3069 Error_Pragma_Arg
3070 ("second argument of pragma% must be a subprogram", Arg2);
3071 end if;
3072
3073 -- For Stdcall, a subprogram, variable or subprogram type is required
3074
3075 if C = Convention_Stdcall
3076 and then not Is_Subprogram (E)
3077 and then not Is_Generic_Subprogram (E)
3078 and then Ekind (E) /= E_Variable
3079 and then not
3080 (Is_Access_Type (E)
e074d476 3081 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
996ae0b0
RK
3082 then
3083 Error_Pragma_Arg
3084 ("second argument of pragma% must be subprogram (type)",
3085 Arg2);
3086 end if;
3087
3088 if not Is_Subprogram (E)
3089 and then not Is_Generic_Subprogram (E)
3090 then
3091 Set_Convention_From_Pragma (E);
3092
3093 if Is_Type (E) then
996ae0b0
RK
3094 Check_First_Subtype (Arg2);
3095 Set_Convention_From_Pragma (Base_Type (E));
3096
3097 -- For subprograms, we must set the convention on the
3098 -- internally generated directly designated type as well.
3099
3100 if Ekind (E) = E_Access_Subprogram_Type then
3101 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3102 end if;
3103 end if;
3104
3105 -- For the subprogram case, set proper convention for all homonyms
7324bf49
AC
3106 -- in same scope and the same declarative part, i.e. the same
3107 -- compilation unit.
996ae0b0
RK
3108
3109 else
7324bf49 3110 Comp_Unit := Get_Source_Unit (E);
996ae0b0
RK
3111 Set_Convention_From_Pragma (E);
3112
d9e0a587 3113 -- Treat a pragma Import as an implicit body, for GPS use
fbf5a39b
AC
3114
3115 if Prag_Id = Pragma_Import then
874a0341 3116 Generate_Reference (E, Id, 'b');
fbf5a39b
AC
3117 end if;
3118
9fe2f33e
AC
3119 -- Loop through the homonyms of the pragma argument's entity
3120
3121 E1 := Ent;
996ae0b0
RK
3122 loop
3123 E1 := Homonym (E1);
3124 exit when No (E1) or else Scope (E1) /= Current_Scope;
3125
b3b9865d
AC
3126 -- Do not set the pragma on inherited operations or on formal
3127 -- subprograms.
21d27997 3128
2820d220 3129 if Comes_From_Source (E1)
7324bf49 3130 and then Comp_Unit = Get_Source_Unit (E1)
21d27997 3131 and then not Is_Formal_Subprogram (E1)
2820d220 3132 and then Nkind (Original_Node (Parent (E1))) /=
f2131422 3133 N_Full_Type_Declaration
2820d220 3134 then
b039b10e
ST
3135 if Present (Alias (E1))
3136 and then Scope (E1) /= Scope (Alias (E1))
3137 then
3138 Error_Pragma_Ref
c27f2f15
RD
3139 ("cannot apply pragma% to non-local entity& declared#",
3140 E1);
b039b10e 3141 end if;
c27f2f15 3142
996ae0b0 3143 Set_Convention_From_Pragma (E1);
fbf5a39b
AC
3144
3145 if Prag_Id = Pragma_Import then
9fe2f33e 3146 Generate_Reference (E1, Id, 'b');
fbf5a39b 3147 end if;
996ae0b0 3148 end if;
0f1a6a0b
AC
3149
3150 -- For aspect case, do NOT apply to homonyms
3151
3152 exit when From_Aspect_Specification (N);
996ae0b0
RK
3153 end loop;
3154 end if;
996ae0b0
RK
3155 end Process_Convention;
3156
3157 -----------------------------------------------------
3158 -- Process_Extended_Import_Export_Exception_Pragma --
3159 -----------------------------------------------------
3160
3161 procedure Process_Extended_Import_Export_Exception_Pragma
3162 (Arg_Internal : Node_Id;
3163 Arg_External : Node_Id;
3164 Arg_Form : Node_Id;
3165 Arg_Code : Node_Id)
3166 is
3167 Def_Id : Entity_Id;
3168 Code_Val : Uint;
3169
3170 begin
fbf5a39b
AC
3171 if not OpenVMS_On_Target then
3172 Error_Pragma
3173 ("?pragma% ignored (applies only to Open'V'M'S)");
3174 end if;
3175
996ae0b0
RK
3176 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3177 Def_Id := Entity (Arg_Internal);
3178
3179 if Ekind (Def_Id) /= E_Exception then
3180 Error_Pragma_Arg
3181 ("pragma% must refer to declared exception", Arg_Internal);
3182 end if;
3183
3184 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3185
3186 if Present (Arg_Form) then
3187 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3188 end if;
3189
3190 if Present (Arg_Form)
3191 and then Chars (Arg_Form) = Name_Ada
3192 then
3193 null;
3194 else
3195 Set_Is_VMS_Exception (Def_Id);
3196 Set_Exception_Code (Def_Id, No_Uint);
3197 end if;
3198
3199 if Present (Arg_Code) then
3200 if not Is_VMS_Exception (Def_Id) then
3201 Error_Pragma_Arg
3202 ("Code option for pragma% not allowed for Ada case",
3203 Arg_Code);
3204 end if;
3205
3206 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3207 Code_Val := Expr_Value (Arg_Code);
3208
3209 if not UI_Is_In_Int_Range (Code_Val) then
3210 Error_Pragma_Arg
3211 ("Code option for pragma% must be in 32-bit range",
3212 Arg_Code);
3213
3214 else
3215 Set_Exception_Code (Def_Id, Code_Val);
3216 end if;
3217 end if;
996ae0b0
RK
3218 end Process_Extended_Import_Export_Exception_Pragma;
3219
3220 -------------------------------------------------
3221 -- Process_Extended_Import_Export_Internal_Arg --
3222 -------------------------------------------------
3223
3224 procedure Process_Extended_Import_Export_Internal_Arg
3225 (Arg_Internal : Node_Id := Empty)
3226 is
3227 begin
996ae0b0
RK
3228 if No (Arg_Internal) then
3229 Error_Pragma ("Internal parameter required for pragma%");
3230 end if;
3231
3232 if Nkind (Arg_Internal) = N_Identifier then
3233 null;
3234
3235 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3236 and then (Prag_Id = Pragma_Import_Function
3237 or else
3238 Prag_Id = Pragma_Export_Function)
3239 then
3240 null;
3241
3242 else
3243 Error_Pragma_Arg
3244 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3245 end if;
3246
3247 Check_Arg_Is_Local_Name (Arg_Internal);
996ae0b0
RK
3248 end Process_Extended_Import_Export_Internal_Arg;
3249
3250 --------------------------------------------------
3251 -- Process_Extended_Import_Export_Object_Pragma --
3252 --------------------------------------------------
3253
3254 procedure Process_Extended_Import_Export_Object_Pragma
3255 (Arg_Internal : Node_Id;
3256 Arg_External : Node_Id;
3257 Arg_Size : Node_Id)
3258 is
fbf5a39b 3259 Def_Id : Entity_Id;
996ae0b0
RK
3260
3261 begin
3262 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3263 Def_Id := Entity (Arg_Internal);
3264
8a95f4e8 3265 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
996ae0b0
RK
3266 Error_Pragma_Arg
3267 ("pragma% must designate an object", Arg_Internal);
3268 end if;
3269
1d571f3b
AC
3270 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3271 or else
3272 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3273 then
996ae0b0 3274 Error_Pragma_Arg
1d571f3b 3275 ("previous Common/Psect_Object applies, pragma % not permitted",
996ae0b0
RK
3276 Arg_Internal);
3277 end if;
3278
3279 if Rep_Item_Too_Late (Def_Id, N) then
3280 raise Pragma_Exit;
3281 end if;
3282
3283 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3284
cc335f43
AC
3285 if Present (Arg_Size) then
3286 Check_Arg_Is_External_Name (Arg_Size);
996ae0b0
RK
3287 end if;
3288
3289 -- Export_Object case
3290
3291 if Prag_Id = Pragma_Export_Object then
996ae0b0
RK
3292 if not Is_Library_Level_Entity (Def_Id) then
3293 Error_Pragma_Arg
3294 ("argument for pragma% must be library level entity",
3295 Arg_Internal);
3296 end if;
3297
3298 if Ekind (Current_Scope) = E_Generic_Package then
3299 Error_Pragma ("pragma& cannot appear in a generic unit");
3300 end if;
3301
3302 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3303 Error_Pragma_Arg
3304 ("exported object must have compile time known size",
3305 Arg_Internal);
3306 end if;
3307
fbf5a39b 3308 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
5afaf827 3309 Error_Msg_N ("?duplicate Export_Object pragma", N);
996ae0b0
RK
3310 else
3311 Set_Exported (Def_Id, Arg_Internal);
3312 end if;
3313
3314 -- Import_Object case
3315
3316 else
3317 if Is_Concurrent_Type (Etype (Def_Id)) then
3318 Error_Pragma_Arg
3319 ("cannot use pragma% for task/protected object",
3320 Arg_Internal);
3321 end if;
3322
3323 if Ekind (Def_Id) = E_Constant then
3324 Error_Pragma_Arg
3325 ("cannot import a constant", Arg_Internal);
3326 end if;
3327
fbf5a39b
AC
3328 if Warn_On_Export_Import
3329 and then Has_Discriminants (Etype (Def_Id))
3330 then
996ae0b0
RK
3331 Error_Msg_N
3332 ("imported value must be initialized?", Arg_Internal);
3333 end if;
3334
fbf5a39b
AC
3335 if Warn_On_Export_Import
3336 and then Is_Access_Type (Etype (Def_Id))
3337 then
996ae0b0
RK
3338 Error_Pragma_Arg
3339 ("cannot import object of an access type?", Arg_Internal);
3340 end if;
3341
fbf5a39b
AC
3342 if Warn_On_Export_Import
3343 and then Is_Imported (Def_Id)
3344 then
996ae0b0
RK
3345 Error_Msg_N
3346 ("?duplicate Import_Object pragma", N);
fbf5a39b
AC
3347
3348 -- Check for explicit initialization present. Note that an
5afaf827
AC
3349 -- initialization generated by the code generator, e.g. for an
3350 -- access type, does not count here.
fbf5a39b
AC
3351
3352 elsif Present (Expression (Parent (Def_Id)))
3353 and then
3354 Comes_From_Source
3355 (Original_Node (Expression (Parent (Def_Id))))
3356 then
3357 Error_Msg_Sloc := Sloc (Def_Id);
3358 Error_Pragma_Arg
c690a2ec
RD
3359 ("imported entities cannot be initialized (RM B.1(24))",
3360 "\no initialization allowed for & declared#", Arg1);
996ae0b0
RK
3361 else
3362 Set_Imported (Def_Id);
21d27997 3363 Note_Possible_Modification (Arg_Internal, Sure => False);
996ae0b0
RK
3364 end if;
3365 end if;
996ae0b0
RK
3366 end Process_Extended_Import_Export_Object_Pragma;
3367
3368 ------------------------------------------------------
3369 -- Process_Extended_Import_Export_Subprogram_Pragma --
3370 ------------------------------------------------------
3371
3372 procedure Process_Extended_Import_Export_Subprogram_Pragma
3373 (Arg_Internal : Node_Id;
3374 Arg_External : Node_Id;
3375 Arg_Parameter_Types : Node_Id;
3376 Arg_Result_Type : Node_Id := Empty;
3377 Arg_Mechanism : Node_Id;
3378 Arg_Result_Mechanism : Node_Id := Empty;
3379 Arg_First_Optional_Parameter : Node_Id := Empty)
3380 is
3381 Ent : Entity_Id;
3382 Def_Id : Entity_Id;
3383 Hom_Id : Entity_Id;
3384 Formal : Entity_Id;
3385 Ambiguous : Boolean;
3386 Match : Boolean;
3387 Dval : Node_Id;
3388
fbf5a39b
AC
3389 function Same_Base_Type
3390 (Ptype : Node_Id;
a9f4e3d2 3391 Formal : Entity_Id) return Boolean;
b3b9865d
AC
3392 -- Determines if Ptype references the type of Formal. Note that only
3393 -- the base types need to match according to the spec. Ptype here is
3394 -- the argument from the pragma, which is either a type name, or an
3395 -- access attribute.
fbf5a39b
AC
3396
3397 --------------------
3398 -- Same_Base_Type --
3399 --------------------
996ae0b0 3400
a9f4e3d2
AC
3401 function Same_Base_Type
3402 (Ptype : Node_Id;
3403 Formal : Entity_Id) return Boolean
3404 is
fbf5a39b
AC
3405 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3406 Pref : Node_Id;
3407
996ae0b0 3408 begin
fbf5a39b 3409 -- Case where pragma argument is typ'Access
996ae0b0 3410
fbf5a39b
AC
3411 if Nkind (Ptype) = N_Attribute_Reference
3412 and then Attribute_Name (Ptype) = Name_Access
996ae0b0 3413 then
fbf5a39b
AC
3414 Pref := Prefix (Ptype);
3415 Find_Type (Pref);
3416
3417 if not Is_Entity_Name (Pref)
3418 or else Entity (Pref) = Any_Type
3419 then
3420 raise Pragma_Exit;
3421 end if;
3422
3423 -- We have a match if the corresponding argument is of an
b3b9865d
AC
3424 -- anonymous access type, and its designated type matches the
3425 -- type of the prefix of the access attribute
fbf5a39b
AC
3426
3427 return Ekind (Ftyp) = E_Anonymous_Access_Type
3428 and then Base_Type (Entity (Pref)) =
3429 Base_Type (Etype (Designated_Type (Ftyp)));
3430
3431 -- Case where pragma argument is a type name
3432
3433 else
3434 Find_Type (Ptype);
3435
3436 if not Is_Entity_Name (Ptype)
3437 or else Entity (Ptype) = Any_Type
3438 then
3439 raise Pragma_Exit;
3440 end if;
996ae0b0 3441
b3b9865d
AC
3442 -- We have a match if the corresponding argument is of the type
3443 -- given in the pragma (comparing base types)
fbf5a39b
AC
3444
3445 return Base_Type (Entity (Ptype)) = Ftyp;
3446 end if;
996ae0b0
RK
3447 end Same_Base_Type;
3448
3449 -- Start of processing for
3450 -- Process_Extended_Import_Export_Subprogram_Pragma
3451
3452 begin
3453 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
996ae0b0
RK
3454 Ent := Empty;
3455 Ambiguous := False;
3456
1d571f3b 3457 -- Loop through homonyms (overloadings) of the entity
996ae0b0 3458
1d571f3b 3459 Hom_Id := Entity (Arg_Internal);
996ae0b0
RK
3460 while Present (Hom_Id) loop
3461 Def_Id := Get_Base_Subprogram (Hom_Id);
3462
3463 -- We need a subprogram in the current scope
3464
3465 if not Is_Subprogram (Def_Id)
3466 or else Scope (Def_Id) /= Current_Scope
3467 then
3468 null;
3469
3470 else
3471 Match := True;
3472
3473 -- Pragma cannot apply to subprogram body
3474
3475 if Is_Subprogram (Def_Id)
f2131422
JM
3476 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3477 N_Subprogram_Body
996ae0b0
RK
3478 then
3479 Error_Pragma
3480 ("pragma% requires separate spec"
3481 & " and must come before body");
3482 end if;
3483
3484 -- Test result type if given, note that the result type
3485 -- parameter can only be present for the function cases.
3486
3487 if Present (Arg_Result_Type)
3488 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3489 then
3490 Match := False;
3491
fbf5a39b
AC
3492 elsif Etype (Def_Id) /= Standard_Void_Type
3493 and then
1b24ada5
RD
3494 (Pname = Name_Export_Procedure
3495 or else
3496 Pname = Name_Import_Procedure)
fbf5a39b
AC
3497 then
3498 Match := False;
3499
996ae0b0
RK
3500 -- Test parameter types if given. Note that this parameter
3501 -- has not been analyzed (and must not be, since it is
3502 -- semantic nonsense), so we get it as the parser left it.
3503
3504 elsif Present (Arg_Parameter_Types) then
3505 Check_Matching_Types : declare
3506 Formal : Entity_Id;
3507 Ptype : Node_Id;
3508
3509 begin
3510 Formal := First_Formal (Def_Id);
3511
3512 if Nkind (Arg_Parameter_Types) = N_Null then
3513 if Present (Formal) then
3514 Match := False;
3515 end if;
3516
3517 -- A list of one type, e.g. (List) is parsed as
3518 -- a parenthesized expression.
3519
3520 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3521 and then Paren_Count (Arg_Parameter_Types) = 1
3522 then
3523 if No (Formal)
3524 or else Present (Next_Formal (Formal))
3525 then
3526 Match := False;
3527 else
3528 Match :=
3529 Same_Base_Type (Arg_Parameter_Types, Formal);
3530 end if;
3531
3532 -- A list of more than one type is parsed as a aggregate
3533
3534 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3535 and then Paren_Count (Arg_Parameter_Types) = 0
3536 then
3537 Ptype := First (Expressions (Arg_Parameter_Types));
996ae0b0
RK
3538 while Present (Ptype) or else Present (Formal) loop
3539 if No (Ptype)
3540 or else No (Formal)
3541 or else not Same_Base_Type (Ptype, Formal)
3542 then
3543 Match := False;
3544 exit;
3545 else
3546 Next_Formal (Formal);
3547 Next (Ptype);
3548 end if;
3549 end loop;
3550
3551 -- Anything else is of the wrong form
3552
3553 else
3554 Error_Pragma_Arg
3555 ("wrong form for Parameter_Types parameter",
3556 Arg_Parameter_Types);
3557 end if;
3558 end Check_Matching_Types;
3559 end if;
3560
3561 -- Match is now False if the entry we found did not match
3562 -- either a supplied Parameter_Types or Result_Types argument
3563
3564 if Match then
3565 if No (Ent) then
3566 Ent := Def_Id;
3567
3568 -- Ambiguous case, the flag Ambiguous shows if we already
3569 -- detected this and output the initial messages.
3570
3571 else
3572 if not Ambiguous then
3573 Ambiguous := True;
1b24ada5 3574 Error_Msg_Name_1 := Pname;
996ae0b0
RK
3575 Error_Msg_N
3576 ("pragma% does not uniquely identify subprogram!",
3577 N);
3578 Error_Msg_Sloc := Sloc (Ent);
3579 Error_Msg_N ("matching subprogram #!", N);
3580 Ent := Empty;
3581 end if;
3582
3583 Error_Msg_Sloc := Sloc (Def_Id);
3584 Error_Msg_N ("matching subprogram #!", N);
3585 end if;
3586 end if;
3587 end if;
3588
3589 Hom_Id := Homonym (Hom_Id);
3590 end loop;
3591
3592 -- See if we found an entry
3593
3594 if No (Ent) then
3595 if not Ambiguous then
3596 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3597 Error_Pragma
3598 ("pragma% cannot be given for generic subprogram");
996ae0b0
RK
3599 else
3600 Error_Pragma
3601 ("pragma% does not identify local subprogram");
3602 end if;
3603 end if;
3604
3605 return;
3606 end if;
3607
16b05213 3608 -- Import pragmas must be for imported entities
996ae0b0 3609
fbf5a39b
AC
3610 if Prag_Id = Pragma_Import_Function
3611 or else
3612 Prag_Id = Pragma_Import_Procedure
3613 or else
3614 Prag_Id = Pragma_Import_Valued_Procedure
996ae0b0
RK
3615 then
3616 if not Is_Imported (Ent) then
ed2233dc 3617 Error_Pragma
996ae0b0
RK
3618 ("pragma Import or Interface must precede pragma%");
3619 end if;
3620
fbf5a39b
AC
3621 -- Here we have the Export case which can set the entity as exported
3622
c690a2ec
RD
3623 -- But does not do so if the specified external name is null, since
3624 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3625 -- compatible) to request no external name.
fbf5a39b
AC
3626
3627 elsif Nkind (Arg_External) = N_String_Literal
3628 and then String_Length (Strval (Arg_External)) = 0
3629 then
3630 null;
3631
f3d57416 3632 -- In all other cases, set entity as exported
996ae0b0
RK
3633
3634 else
3635 Set_Exported (Ent, Arg_Internal);
3636 end if;
3637
3638 -- Special processing for Valued_Procedure cases
3639
3640 if Prag_Id = Pragma_Import_Valued_Procedure
3641 or else
3642 Prag_Id = Pragma_Export_Valued_Procedure
3643 then
3644 Formal := First_Formal (Ent);
3645
3646 if No (Formal) then
5afaf827 3647 Error_Pragma ("at least one parameter required for pragma%");
996ae0b0
RK
3648
3649 elsif Ekind (Formal) /= E_Out_Parameter then
5afaf827 3650 Error_Pragma ("first parameter must have mode out for pragma%");
996ae0b0
RK
3651
3652 else
3653 Set_Is_Valued_Procedure (Ent);
3654 end if;
3655 end if;
3656
3657 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3658
3659 -- Process Result_Mechanism argument if present. We have already
3660 -- checked that this is only allowed for the function case.
3661
3662 if Present (Arg_Result_Mechanism) then
3663 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3664 end if;
3665
3666 -- Process Mechanism parameter if present. Note that this parameter
3667 -- is not analyzed, and must not be analyzed since it is semantic
3668 -- nonsense, so we get it in exactly as the parser left it.
3669
3670 if Present (Arg_Mechanism) then
996ae0b0
RK
3671 declare
3672 Formal : Entity_Id;
3673 Massoc : Node_Id;
3674 Mname : Node_Id;
3675 Choice : Node_Id;
3676
3677 begin
3678 -- A single mechanism association without a formal parameter
3679 -- name is parsed as a parenthesized expression. All other
3680 -- cases are parsed as aggregates, so we rewrite the single
3681 -- parameter case as an aggregate for consistency.
3682
3683 if Nkind (Arg_Mechanism) /= N_Aggregate
3684 and then Paren_Count (Arg_Mechanism) = 1
3685 then
3686 Rewrite (Arg_Mechanism,
3687 Make_Aggregate (Sloc (Arg_Mechanism),
3688 Expressions => New_List (
3689 Relocate_Node (Arg_Mechanism))));
3690 end if;
3691
3692 -- Case of only mechanism name given, applies to all formals
3693
3694 if Nkind (Arg_Mechanism) /= N_Aggregate then
3695 Formal := First_Formal (Ent);
3696 while Present (Formal) loop
3697 Set_Mechanism_Value (Formal, Arg_Mechanism);
3698 Next_Formal (Formal);
3699 end loop;
3700
3701 -- Case of list of mechanism associations given
3702
3703 else
3704 if Null_Record_Present (Arg_Mechanism) then
3705 Error_Pragma_Arg
3706 ("inappropriate form for Mechanism parameter",
3707 Arg_Mechanism);
3708 end if;
3709
3710 -- Deal with positional ones first
3711
3712 Formal := First_Formal (Ent);
2c9beb8a 3713
996ae0b0
RK
3714 if Present (Expressions (Arg_Mechanism)) then
3715 Mname := First (Expressions (Arg_Mechanism));
996ae0b0
RK
3716 while Present (Mname) loop
3717 if No (Formal) then
3718 Error_Pragma_Arg
3719 ("too many mechanism associations", Mname);
3720 end if;
3721
3722 Set_Mechanism_Value (Formal, Mname);
3723 Next_Formal (Formal);
3724 Next (Mname);
3725 end loop;
3726 end if;
3727
3728 -- Deal with named entries
3729
3730 if Present (Component_Associations (Arg_Mechanism)) then
3731 Massoc := First (Component_Associations (Arg_Mechanism));
996ae0b0
RK
3732 while Present (Massoc) loop
3733 Choice := First (Choices (Massoc));
3734
3735 if Nkind (Choice) /= N_Identifier
3736 or else Present (Next (Choice))
3737 then
3738 Error_Pragma_Arg
3739 ("incorrect form for mechanism association",
3740 Massoc);
3741 end if;
3742
3743 Formal := First_Formal (Ent);
3744 loop
3745 if No (Formal) then
3746 Error_Pragma_Arg
3747 ("parameter name & not present", Choice);
3748 end if;
3749
3750 if Chars (Choice) = Chars (Formal) then
3751 Set_Mechanism_Value
3752 (Formal, Expression (Massoc));
bf8b6bfc 3753
beacce02 3754 -- Set entity on identifier (needed by ASIS)
a168f519 3755
bf8b6bfc
SR
3756 Set_Entity (Choice, Formal);
3757
996ae0b0
RK
3758 exit;
3759 end if;
3760
3761 Next_Formal (Formal);
3762 end loop;
3763
3764 Next (Massoc);
3765 end loop;
3766 end if;
3767 end if;
3768 end;
3769 end if;
3770
3771 -- Process First_Optional_Parameter argument if present. We have
3772 -- already checked that this is only allowed for the Import case.
3773
3774 if Present (Arg_First_Optional_Parameter) then
3775 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3776 Error_Pragma_Arg
3777 ("first optional parameter must be formal parameter name",
3778 Arg_First_Optional_Parameter);
3779 end if;
3780
3781 Formal := First_Formal (Ent);
3782 loop
3783 if No (Formal) then
3784 Error_Pragma_Arg
3785 ("specified formal parameter& not found",
3786 Arg_First_Optional_Parameter);
3787 end if;
3788
3789 exit when Chars (Formal) =
3790 Chars (Arg_First_Optional_Parameter);
3791
3792 Next_Formal (Formal);
3793 end loop;
3794
3795 Set_First_Optional_Parameter (Ent, Formal);
3796
3797 -- Check specified and all remaining formals have right form
3798
3799 while Present (Formal) loop
3800 if Ekind (Formal) /= E_In_Parameter then
3801 Error_Msg_NE
3802 ("optional formal& is not of mode in!",
3803 Arg_First_Optional_Parameter, Formal);
3804
3805 else
3806 Dval := Default_Value (Formal);
3807
57193e09 3808 if No (Dval) then
996ae0b0
RK
3809 Error_Msg_NE
3810 ("optional formal& does not have default value!",
3811 Arg_First_Optional_Parameter, Formal);
3812
3813 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3814 null;
3815
3816 else
fbf5a39b 3817 Error_Msg_FE
996ae0b0
RK
3818 ("default value for optional formal& is non-static!",
3819 Arg_First_Optional_Parameter, Formal);
3820 end if;
3821 end if;
3822
3823 Set_Is_Optional_Parameter (Formal);
3824 Next_Formal (Formal);
3825 end loop;
3826 end if;
996ae0b0
RK
3827 end Process_Extended_Import_Export_Subprogram_Pragma;
3828
3829 --------------------------
3830 -- Process_Generic_List --
3831 --------------------------
3832
3833 procedure Process_Generic_List is
3834 Arg : Node_Id;
3835 Exp : Node_Id;
3836
3837 begin
996ae0b0
RK
3838 Check_No_Identifiers;
3839 Check_At_Least_N_Arguments (1);
3840
3841 Arg := Arg1;
3842 while Present (Arg) loop
0f1a6a0b 3843 Exp := Get_Pragma_Arg (Arg);
996ae0b0
RK
3844 Analyze (Exp);
3845
3846 if not Is_Entity_Name (Exp)
3847 or else
3848 (not Is_Generic_Instance (Entity (Exp))
3849 and then
3850 not Is_Generic_Unit (Entity (Exp)))
3851 then
3852 Error_Pragma_Arg
3853 ("pragma% argument must be name of generic unit/instance",
3854 Arg);
3855 end if;
3856
3857 Next (Arg);
3858 end loop;
3859 end Process_Generic_List;
3860
15b682ca
GB
3861 ------------------------------------
3862 -- Process_Import_Predefined_Type --
3863 ------------------------------------
3864
3865 procedure Process_Import_Predefined_Type is
3866 Loc : constant Source_Ptr := Sloc (N);
3867 Ftyp : Node_Id := First (Predefined_Float_Types);
3868 Decl : Node_Id;
3869 Def : Node_Id;
3870 Nam : Name_Id;
3871 begin
3872 String_To_Name_Buffer (Strval (Expression (Arg3)));
3873 Nam := Name_Find;
3874
3875 while Present (Ftyp) and then Chars (Ftyp) /= Nam loop
3876 Next (Ftyp);
3877 end loop;
3878
3879 if Present (Ftyp) then
3880 -- Don't build a derived type declaration, because predefined C
3881 -- types have no declaration anywhere, so cannot really be named.
3882 -- Instead build a full type declaration, starting with an
3883 -- appropriate type definition is built
3884
3885 if Is_Floating_Point_Type (Ftyp) then
3886 Def := Make_Floating_Point_Definition (Loc,
3887 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
3888 Make_Real_Range_Specification (Loc,
3889 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
3890 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
3891
3892 else
3893 -- Should never have a predefined type we cannot handle
3894 raise Program_Error;
3895 end if;
3896
3897 -- Build and insert a Full_Type_Declaration, which will be
3898 -- analyzed as soon as this list entry has been analyzed.
3899
3900 Decl := Make_Full_Type_Declaration (Loc,
3901 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
3902 Type_Definition => Def);
3903
3904 Insert_After (N, Decl);
3905 Mark_Rewrite_Insertion (Decl);
3906
3907 else
3908 Error_Pragma_Arg ("no matching type found for pragma%",
3909 Arg2);
3910 end if;
3911 end Process_Import_Predefined_Type;
3912
996ae0b0
RK
3913 ---------------------------------
3914 -- Process_Import_Or_Interface --
3915 ---------------------------------
3916
3917 procedure Process_Import_Or_Interface is
3918 C : Convention_Id;
3919 Def_Id : Entity_Id;
3920 Hom_Id : Entity_Id;
3921
3922 begin
3923 Process_Convention (C, Def_Id);
3924 Kill_Size_Check_Code (Def_Id);
0f1a6a0b 3925 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
996ae0b0 3926
8a95f4e8
RD
3927 if Ekind_In (Def_Id, E_Variable, E_Constant) then
3928
2fa9443e
ES
3929 -- We do not permit Import to apply to a renaming declaration
3930
3931 if Present (Renamed_Object (Def_Id)) then
3932 Error_Pragma_Arg
3933 ("pragma% not allowed for object renaming", Arg2);
3934
996ae0b0
RK
3935 -- User initialization is not allowed for imported object, but
3936 -- the object declaration may contain a default initialization,
fbf5a39b
AC
3937 -- that will be discarded. Note that an explicit initialization
3938 -- only counts if it comes from source, otherwise it is simply
3939 -- the code generator making an implicit initialization explicit.
996ae0b0 3940
2fa9443e
ES
3941 elsif Present (Expression (Parent (Def_Id)))
3942 and then Comes_From_Source (Expression (Parent (Def_Id)))
996ae0b0
RK
3943 then
3944 Error_Msg_Sloc := Sloc (Def_Id);
3945 Error_Pragma_Arg
3946 ("no initialization allowed for declaration of& #",
c690a2ec 3947 "\imported entities cannot be initialized (RM B.1(24))",
996ae0b0
RK
3948 Arg2);
3949
3950 else
3951 Set_Imported (Def_Id);
996ae0b0 3952 Process_Interface_Name (Def_Id, Arg3, Arg4);
fbf5a39b 3953
2c9beb8a 3954 -- Note that we do not set Is_Public here. That's because we
16b05213 3955 -- only want to set it if there is no address clause, and we
2c9beb8a
RD
3956 -- don't know that yet, so we delay that processing till
3957 -- freeze time.
3958
5453d5bd
AC
3959 -- pragma Import completes deferred constants
3960
3961 if Ekind (Def_Id) = E_Constant then
3962 Set_Has_Completion (Def_Id);
3963 end if;
3964
fbf5a39b
AC
3965 -- It is not possible to import a constant of an unconstrained
3966 -- array type (e.g. string) because there is no simple way to
3967 -- write a meaningful subtype for it.
3968
3969 if Is_Array_Type (Etype (Def_Id))
3970 and then not Is_Constrained (Etype (Def_Id))
3971 then
3972 Error_Msg_NE
3973 ("imported constant& must have a constrained subtype",
3974 N, Def_Id);
3975 end if;
996ae0b0
RK
3976 end if;
3977
3978 elsif Is_Subprogram (Def_Id)
3979 or else Is_Generic_Subprogram (Def_Id)
3980 then
beacce02
AC
3981 -- If the name is overloaded, pragma applies to all of the denoted
3982 -- entities in the same declarative part.
996ae0b0
RK
3983
3984 Hom_Id := Def_Id;
996ae0b0
RK
3985 while Present (Hom_Id) loop
3986 Def_Id := Get_Base_Subprogram (Hom_Id);
3987
beacce02
AC
3988 -- Ignore inherited subprograms because the pragma will apply
3989 -- to the parent operation, which is the one called.
996ae0b0
RK
3990
3991 if Is_Overloadable (Def_Id)
3992 and then Present (Alias (Def_Id))
3993 then
3994 null;
3995
b3b9865d
AC
3996 -- If it is not a subprogram, it must be in an outer scope and
3997 -- pragma does not apply.
fbf5a39b
AC
3998
3999 elsif not Is_Subprogram (Def_Id)
4000 and then not Is_Generic_Subprogram (Def_Id)
4001 then
4002 null;
4003
0592046e
AC
4004 -- The pragma does not apply to primitives of interfaces
4005
4006 elsif Is_Dispatching_Operation (Def_Id)
4007 and then Present (Find_Dispatching_Type (Def_Id))
4008 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4009 then
4010 null;
4011
b3b9865d
AC
4012 -- Verify that the homonym is in the same declarative part (not
4013 -- just the same scope).
996ae0b0
RK
4014
4015 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4016 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4017 then
4018 exit;
4019
4020 else
4021 Set_Imported (Def_Id);
4022
9fe2f33e
AC
4023 -- Reject an Import applied to an abstract subprogram
4024
6fa30ef2
ST
4025 if Is_Subprogram (Def_Id)
4026 and then Is_Abstract_Subprogram (Def_Id)
4027 then
4028 Error_Msg_Sloc := Sloc (Def_Id);
4029 Error_Msg_NE
4030 ("cannot import abstract subprogram& declared#",
4031 Arg2, Def_Id);
4032 end if;
4033
98f01d53 4034 -- Special processing for Convention_Intrinsic
996ae0b0
RK
4035
4036 if C = Convention_Intrinsic then
98f01d53
AC
4037
4038 -- Link_Name argument not allowed for intrinsic
4039
9eea4346 4040 Check_No_Link_Name;
98f01d53 4041
996ae0b0 4042 Set_Is_Intrinsic_Subprogram (Def_Id);
98f01d53 4043
b3b9865d
AC
4044 -- If no external name is present, then check that this
4045 -- is a valid intrinsic subprogram. If an external name
4046 -- is present, then this is handled by the back end.
98f01d53
AC
4047
4048 if No (Arg3) then
0f1a6a0b
AC
4049 Check_Intrinsic_Subprogram
4050 (Def_Id, Get_Pragma_Arg (Arg2));
98f01d53 4051 end if;
996ae0b0
RK
4052 end if;
4053
b3b9865d
AC
4054 -- All interfaced procedures need an external symbol created
4055 -- for them since they are always referenced from another
4056 -- object file.
996ae0b0
RK
4057
4058 Set_Is_Public (Def_Id);
fbf5a39b
AC
4059
4060 -- Verify that the subprogram does not have a completion
b3b9865d
AC
4061 -- through a renaming declaration. For other completions the
4062 -- pragma appears as a too late representation.
fbf5a39b
AC
4063
4064 declare
4065 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
91b1417d 4066
fbf5a39b
AC
4067 begin
4068 if Present (Decl)
4069 and then Nkind (Decl) = N_Subprogram_Declaration
4070 and then Present (Corresponding_Body (Decl))
f2131422
JM
4071 and then Nkind (Unit_Declaration_Node
4072 (Corresponding_Body (Decl))) =
fbf5a39b
AC
4073 N_Subprogram_Renaming_Declaration
4074 then
4075 Error_Msg_Sloc := Sloc (Def_Id);
c690a2ec
RD
4076 Error_Msg_NE
4077 ("cannot import&, renaming already provided for " &
4078 "declaration #", N, Def_Id);
fbf5a39b
AC
4079 end if;
4080 end;
4081
996ae0b0
RK
4082 Set_Has_Completion (Def_Id);
4083 Process_Interface_Name (Def_Id, Arg3, Arg4);
4084 end if;
4085
4086 if Is_Compilation_Unit (Hom_Id) then
4087
4088 -- Its possible homonyms are not affected by the pragma.
4089 -- Such homonyms might be present in the context of other
4090 -- units being compiled.
4091
4092 exit;
4093
4094 else
4095 Hom_Id := Homonym (Hom_Id);
4096 end if;
4097 end loop;
4098
2fa9443e 4099 -- When the convention is Java or CIL, we also allow Import to be
7e8ed0a6
AC
4100 -- given for packages, generic packages, exceptions, record
4101 -- components, and access to subprograms.
996ae0b0 4102
2fa9443e 4103 elsif (C = Convention_Java or else C = Convention_CIL)
6e937c1c 4104 and then
b9b2405f 4105 (Is_Package_Or_Generic_Package (Def_Id)
d7ba4df4 4106 or else Ekind (Def_Id) = E_Exception
7e8ed0a6 4107 or else Ekind (Def_Id) = E_Access_Subprogram_Type
d7ba4df4 4108 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
996ae0b0
RK
4109 then
4110 Set_Imported (Def_Id);
4111 Set_Is_Public (Def_Id);
4112 Process_Interface_Name (Def_Id, Arg3, Arg4);
4113
874a0341
RD
4114 -- Import a CPP class
4115
4116 elsif Is_Record_Type (Def_Id)
4117 and then C = Convention_CPP
4118 then
7b4db06c 4119 -- Types treated as CPP classes are treated as limited, but we
0592046e
AC
4120 -- don't require them to be declared this way. A warning is issued
4121 -- to encourage the user to declare them as limited. This is not
4122 -- an error, for compatibility reasons, because these types have
4123 -- been supported this way for some time.
2fa9443e 4124
7b4db06c 4125 if not Is_Limited_Type (Def_Id) then
ed2233dc 4126 Error_Msg_N
7b4db06c
JM
4127 ("imported 'C'P'P type should be " &
4128 "explicitly declared limited?",
4129 Get_Pragma_Arg (Arg2));
ed2233dc 4130 Error_Msg_N
7b4db06c
JM
4131 ("\type will be considered limited",
4132 Get_Pragma_Arg (Arg2));
4133 end if;
2fa9443e 4134
7b4db06c
JM
4135 Set_Is_CPP_Class (Def_Id);
4136 Set_Is_Limited_Record (Def_Id);
0c020dde 4137
7b4db06c
JM
4138 -- Imported CPP types must not have discriminants (because C++
4139 -- classes do not have discriminants).
0c020dde 4140
7b4db06c
JM
4141 if Has_Discriminants (Def_Id) then
4142 Error_Msg_N
4143 ("imported 'C'P'P type cannot have discriminants",
4144 First (Discriminant_Specifications
4145 (Declaration_Node (Def_Id))));
4146 end if;
0c020dde 4147
7b4db06c 4148 -- Components of imported CPP types must not have default
3c92a2b8 4149 -- expressions because the constructor (if any) is on the
7b4db06c 4150 -- C++ side.
0c020dde 4151
7b4db06c
JM
4152 declare
4153 Tdef : constant Node_Id :=
4154 Type_Definition (Declaration_Node (Def_Id));
4155 Clist : Node_Id;
4156 Comp : Node_Id;
0c020dde 4157
7b4db06c
JM
4158 begin
4159 if Nkind (Tdef) = N_Record_Definition then
4160 Clist := Component_List (Tdef);
0c020dde 4161
7b4db06c
JM
4162 else
4163 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4164 Clist := Component_List (Record_Extension_Part (Tdef));
4165 end if;
0c020dde 4166
7b4db06c
JM
4167 if Present (Clist) then
4168 Comp := First (Component_Items (Clist));
4169 while Present (Comp) loop
4170 if Present (Expression (Comp)) then
4171 Error_Msg_N
4172 ("component of imported 'C'P'P type cannot have" &
4173 " default expression", Expression (Comp));
4174 end if;
0c020dde 4175
7b4db06c
JM
4176 Next (Comp);
4177 end loop;
4178 end if;
4179 end;
874a0341 4180
15b682ca
GB
4181 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4182 Check_No_Link_Name;
4183 Check_Arg_Count (3);
4184 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4185
4186 Process_Import_Predefined_Type;
4187
996ae0b0
RK
4188 else
4189 Error_Pragma_Arg
15b682ca
GB
4190 ("second argument of pragma% must be object, subprogram" &
4191 " or incomplete type",
996ae0b0
RK
4192 Arg2);
4193 end if;
4194
b3b9865d
AC
4195 -- If this pragma applies to a compilation unit, then the unit, which
4196 -- is a subprogram, does not require (or allow) a body. We also do
4197 -- not need to elaborate imported procedures.
996ae0b0
RK
4198
4199 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4200 declare
4201 Cunit : constant Node_Id := Parent (Parent (N));
996ae0b0 4202 begin
a9f4e3d2 4203 Set_Body_Required (Cunit, False);
996ae0b0
RK
4204 end;
4205 end if;
996ae0b0
RK
4206 end Process_Import_Or_Interface;
4207
4208 --------------------
4209 -- Process_Inline --
4210 --------------------
4211
4212 procedure Process_Inline (Active : Boolean) is
6e937c1c
AC
4213 Assoc : Node_Id;
4214 Decl : Node_Id;
4215 Subp_Id : Node_Id;
4216 Subp : Entity_Id;
4217 Applies : Boolean;
eaba57fb 4218
6e937c1c 4219 Effective : Boolean := False;
eaba57fb
RD
4220 -- Set True if inline has some effect, i.e. if there is at least one
4221 -- subprogram set as inlined as a result of the use of the pragma.
996ae0b0
RK
4222
4223 procedure Make_Inline (Subp : Entity_Id);
b3b9865d
AC
4224 -- Subp is the defining unit name of the subprogram declaration. Set
4225 -- the flag, as well as the flag in the corresponding body, if there
4226 -- is one present.
996ae0b0
RK
4227
4228 procedure Set_Inline_Flags (Subp : Entity_Id);
470cd9e9
RD
4229 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4230 -- Has_Pragma_Inline_Always for the Inline_Always case.
996ae0b0 4231
98f01d53
AC
4232 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4233 -- Returns True if it can be determined at this stage that inlining
f3d57416 4234 -- is not possible, for example if the body is available and contains
98f01d53
AC
4235 -- exception handlers, we prevent inlining, since otherwise we can
4236 -- get undefined symbols at link time. This function also emits a
4237 -- warning if front-end inlining is enabled and the pragma appears
4238 -- too late.
470cd9e9 4239 --
98f01d53
AC
4240 -- ??? is business with link symbols still valid, or does it relate
4241 -- to front end ZCX which is being phased out ???
fbf5a39b 4242
98f01d53
AC
4243 ---------------------------
4244 -- Inlining_Not_Possible --
4245 ---------------------------
fbf5a39b 4246
98f01d53
AC
4247 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4248 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4249 Stats : Node_Id;
fbf5a39b
AC
4250
4251 begin
4252 if Nkind (Decl) = N_Subprogram_Body then
98f01d53
AC
4253 Stats := Handled_Statement_Sequence (Decl);
4254 return Present (Exception_Handlers (Stats))
4255 or else Present (At_End_Proc (Stats));
fbf5a39b
AC
4256
4257 elsif Nkind (Decl) = N_Subprogram_Declaration
4258 and then Present (Corresponding_Body (Decl))
4259 then
c37bb106
AC
4260 if Front_End_Inlining
4261 and then Analyzed (Corresponding_Body (Decl))
4262 then
ed2233dc 4263 Error_Msg_N ("pragma appears too late, ignored?", N);
c37bb106
AC
4264 return True;
4265
b3b9865d
AC
4266 -- If the subprogram is a renaming as body, the body is just a
4267 -- call to the renamed subprogram, and inlining is trivially
4268 -- possible.
a9f4e3d2 4269
c37bb106 4270 elsif
2fa9443e
ES
4271 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4272 N_Subprogram_Renaming_Declaration
a9f4e3d2
AC
4273 then
4274 return False;
4275
4276 else
98f01d53
AC
4277 Stats :=
4278 Handled_Statement_Sequence
4279 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4280
a9f4e3d2 4281 return
98f01d53
AC
4282 Present (Exception_Handlers (Stats))
4283 or else Present (At_End_Proc (Stats));
a9f4e3d2 4284 end if;
98f01d53 4285
fbf5a39b
AC
4286 else
4287 -- If body is not available, assume the best, the check is
4288 -- performed again when compiling enclosing package bodies.
4289
4290 return False;
4291 end if;
98f01d53 4292 end Inlining_Not_Possible;
fbf5a39b 4293
996ae0b0
RK
4294 -----------------
4295 -- Make_Inline --
4296 -----------------
4297
4298 procedure Make_Inline (Subp : Entity_Id) is
fbf5a39b 4299 Kind : constant Entity_Kind := Ekind (Subp);
996ae0b0
RK
4300 Inner_Subp : Entity_Id := Subp;
4301
4302 begin
470cd9e9
RD
4303 -- Ignore if bad type, avoid cascaded error
4304
996ae0b0 4305 if Etype (Subp) = Any_Type then
470cd9e9
RD
4306 Applies := True;
4307 return;
4308
4309 -- Ignore if all inlining is suppressed
4310
4311 elsif Suppress_All_Inlining then
4312 Applies := True;
996ae0b0
RK
4313 return;
4314
98f01d53
AC
4315 -- If inlining is not possible, for now do not treat as an error
4316
4317 elsif Inlining_Not_Possible (Subp) then
4318 Applies := True;
fbf5a39b
AC
4319 return;
4320
996ae0b0 4321 -- Here we have a candidate for inlining, but we must exclude
21d27997
RD
4322 -- derived operations. Otherwise we would end up trying to inline
4323 -- a phantom declaration, and the result would be to drag in a
4324 -- body which has no direct inlining associated with it. That
4325 -- would not only be inefficient but would also result in the
4326 -- backend doing cross-unit inlining in cases where it was
4327 -- definitely inappropriate to do so.
4328
4329 -- However, a simple Comes_From_Source test is insufficient, since
4330 -- we do want to allow inlining of generic instances which also do
b3b9865d
AC
4331 -- not come from source. We also need to recognize specs generated
4332 -- by the front-end for bodies that carry the pragma. Finally,
4333 -- predefined operators do not come from source but are not
4334 -- inlineable either.
21d27997
RD
4335
4336 elsif Is_Generic_Instance (Subp)
4337 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4338 then
4339 null;
996ae0b0
RK
4340
4341 elsif not Comes_From_Source (Subp)
996ae0b0
RK
4342 and then Scope (Subp) /= Standard_Standard
4343 then
4344 Applies := True;
4345 return;
21d27997 4346 end if;
996ae0b0 4347
b3b9865d
AC
4348 -- The referenced entity must either be the enclosing entity, or
4349 -- an entity declared within the current open scope.
996ae0b0 4350
21d27997 4351 if Present (Scope (Subp))
996ae0b0
RK
4352 and then Scope (Subp) /= Current_Scope
4353 and then Subp /= Current_Scope
4354 then
4355 Error_Pragma_Arg
4356 ("argument of% must be entity in current scope", Assoc);
4357 return;
4358 end if;
4359
b3b9865d
AC
4360 -- Processing for procedure, operator or function. If subprogram
4361 -- is aliased (as for an instance) indicate that the renamed
4362 -- entity (if declared in the same unit) is inlined.
996ae0b0 4363
fbf5a39b 4364 if Is_Subprogram (Subp) then
b81a5940 4365 Inner_Subp := Ultimate_Alias (Inner_Subp);
996ae0b0 4366
af4b9434
AC
4367 if In_Same_Source_Unit (Subp, Inner_Subp) then
4368 Set_Inline_Flags (Inner_Subp);
996ae0b0 4369
af4b9434 4370 Decl := Parent (Parent (Inner_Subp));
996ae0b0 4371
af4b9434
AC
4372 if Nkind (Decl) = N_Subprogram_Declaration
4373 and then Present (Corresponding_Body (Decl))
4374 then
4375 Set_Inline_Flags (Corresponding_Body (Decl));
cfb02ad1
AC
4376
4377 elsif Is_Generic_Instance (Subp) then
4378
4379 -- Indicate that the body needs to be created for
b3b9865d
AC
4380 -- inlining subsequent calls. The instantiation node
4381 -- follows the declaration of the wrapper package
4382 -- created for it.
cfb02ad1
AC
4383
4384 if Scope (Subp) /= Standard_Standard
4385 and then
4386 Need_Subprogram_Instance_Body
4387 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4388 Subp)
4389 then
4390 null;
4391 end if;
af4b9434 4392 end if;
996ae0b0
RK
4393 end if;
4394
4395 Applies := True;
4396
b3b9865d
AC
4397 -- For a generic subprogram set flag as well, for use at the point
4398 -- of instantiation, to determine whether the body should be
4399 -- generated.
996ae0b0 4400
fbf5a39b 4401 elsif Is_Generic_Subprogram (Subp) then
996ae0b0
RK
4402 Set_Inline_Flags (Subp);
4403 Applies := True;
4404
fbf5a39b 4405 -- Literals are by definition inlined
996ae0b0
RK
4406
4407 elsif Kind = E_Enumeration_Literal then
4408 null;
4409
4410 -- Anything else is an error
4411
4412 else
4413 Error_Pragma_Arg
4414 ("expect subprogram name for pragma%", Assoc);
4415 end if;
4416 end Make_Inline;
4417
4418 ----------------------
4419 -- Set_Inline_Flags --
4420 ----------------------
4421
4422 procedure Set_Inline_Flags (Subp : Entity_Id) is
4423 begin
4424 if Active then
eaba57fb 4425 Set_Is_Inlined (Subp);
996ae0b0
RK
4426 end if;
4427
4428 if not Has_Pragma_Inline (Subp) then
eaba57fb 4429 Set_Has_Pragma_Inline (Subp);
6e937c1c 4430 Effective := True;
996ae0b0 4431 end if;
470cd9e9
RD
4432
4433 if Prag_Id = Pragma_Inline_Always then
eaba57fb 4434 Set_Has_Pragma_Inline_Always (Subp);
470cd9e9 4435 end if;
996ae0b0
RK
4436 end Set_Inline_Flags;
4437
4438 -- Start of processing for Process_Inline
4439
4440 begin
4441 Check_No_Identifiers;
4442 Check_At_Least_N_Arguments (1);
4443
4444 if Active then
4445 Inline_Processing_Required := True;
4446 end if;
4447
4448 Assoc := Arg1;
4449 while Present (Assoc) loop
0f1a6a0b 4450 Subp_Id := Get_Pragma_Arg (Assoc);
996ae0b0
RK
4451 Analyze (Subp_Id);
4452 Applies := False;
4453
4454 if Is_Entity_Name (Subp_Id) then
4455 Subp := Entity (Subp_Id);
4456
4457 if Subp = Any_Id then
59e5fbe0
RD
4458
4459 -- If previous error, avoid cascaded errors
4460
996ae0b0 4461 Applies := True;
59e5fbe0 4462 Effective := True;
996ae0b0
RK
4463
4464 else
4465 Make_Inline (Subp);
4466
9f90d123
AC
4467 -- For the pragma case, climb homonym chain. This is
4468 -- what implements allowing the pragma in the renaming
4469 -- case, with the result applying to the ancestors.
4470
0f1a6a0b
AC
4471 if not From_Aspect_Specification (N) then
4472 while Present (Homonym (Subp))
4473 and then Scope (Homonym (Subp)) = Current_Scope
4474 loop
4475 Make_Inline (Homonym (Subp));
4476 Subp := Homonym (Subp);
4477 end loop;
4478 end if;
996ae0b0
RK
4479 end if;
4480 end if;
4481
4482 if not Applies then
4483 Error_Pragma_Arg
4484 ("inappropriate argument for pragma%", Assoc);
6e937c1c
AC
4485
4486 elsif not Effective
4487 and then Warn_On_Redundant_Constructs
470cd9e9 4488 and then not Suppress_All_Inlining
6e937c1c 4489 then
98f01d53 4490 if Inlining_Not_Possible (Subp) then
ed2233dc 4491 Error_Msg_NE
98f01d53
AC
4492 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4493 else
ed2233dc 4494 Error_Msg_NE
98f01d53
AC
4495 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4496 end if;
996ae0b0
RK
4497 end if;
4498
4499 Next (Assoc);
4500 end loop;
996ae0b0
RK
4501 end Process_Inline;
4502
4503 ----------------------------
4504 -- Process_Interface_Name --
4505 ----------------------------
4506
4507 procedure Process_Interface_Name
4508 (Subprogram_Def : Entity_Id;
4509 Ext_Arg : Node_Id;
4510 Link_Arg : Node_Id)
4511 is
4512 Ext_Nam : Node_Id;
4513 Link_Nam : Node_Id;
4514 String_Val : String_Id;
4515
7406fc15
RD
4516 procedure Check_Form_Of_Interface_Name
4517 (SN : Node_Id;
4518 Ext_Name_Case : Boolean);
996ae0b0
RK
4519 -- SN is a string literal node for an interface name. This routine
4520 -- performs some minimal checks that the name is reasonable. In
4521 -- particular that no spaces or other obviously incorrect characters
4522 -- appear. This is only a warning, since any characters are allowed.
7406fc15 4523 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
996ae0b0 4524
2c9beb8a
RD
4525 ----------------------------------
4526 -- Check_Form_Of_Interface_Name --
4527 ----------------------------------
4528
7406fc15
RD
4529 procedure Check_Form_Of_Interface_Name
4530 (SN : Node_Id;
4531 Ext_Name_Case : Boolean)
4532 is
996ae0b0
RK
4533 S : constant String_Id := Strval (Expr_Value_S (SN));
4534 SL : constant Nat := String_Length (S);
4535 C : Char_Code;
4536
4537 begin
4538 if SL = 0 then
4539 Error_Msg_N ("interface name cannot be null string", SN);
4540 end if;
4541
4542 for J in 1 .. SL loop
4543 C := Get_String_Char (S, J);
4544
7406fc15
RD
4545 -- Look for dubious character and issue unconditional warning.
4546 -- Definitely dubious if not in character range.
4547
4548 if not In_Character_Range (C)
4549
a7a3cf5c 4550 -- For all cases except CLI target,
57eb1cf5 4551 -- commas, spaces and slashes are dubious (in CLI, we use
a7a3cf5c
AC
4552 -- commas and backslashes in external names to specify
4553 -- assembly version and public key, while slashes and spaces
4554 -- can be used in names to mark nested classes and
4555 -- valuetypes).
7406fc15 4556
57eb1cf5 4557 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
a7a3cf5c 4558 and then (Get_Character (C) = ','
57eb1cf5 4559 or else
7406fc15 4560 Get_Character (C) = '\'))
7e8ed0a6 4561 or else (VM_Target /= CLI_Target
a7a3cf5c
AC
4562 and then (Get_Character (C) = ' '
4563 or else
4564 Get_Character (C) = '/'))
996ae0b0 4565 then
ed2233dc 4566 Error_Msg
7406fc15
RD
4567 ("?interface name contains illegal character",
4568 Sloc (SN) + Source_Ptr (J));
996ae0b0
RK
4569 end if;
4570 end loop;
4571 end Check_Form_Of_Interface_Name;
4572
4573 -- Start of processing for Process_Interface_Name
4574
4575 begin
4576 if No (Link_Arg) then
4577 if No (Ext_Arg) then
2fa9443e
ES
4578 if VM_Target = CLI_Target
4579 and then Ekind (Subprogram_Def) = E_Package
4580 and then Nkind (Parent (Subprogram_Def)) =
4581 N_Package_Specification
4582 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4583 then
4584 Set_Interface_Name
4585 (Subprogram_Def,
4586 Interface_Name
4587 (Generic_Parent (Parent (Subprogram_Def))));
4588 end if;
4589
996ae0b0
RK
4590 return;
4591
4592 elsif Chars (Ext_Arg) = Name_Link_Name then
4593 Ext_Nam := Empty;
4594 Link_Nam := Expression (Ext_Arg);
4595
4596 else
4597 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4598 Ext_Nam := Expression (Ext_Arg);
4599 Link_Nam := Empty;
4600 end if;
4601
4602 else
4603 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4604 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4605 Ext_Nam := Expression (Ext_Arg);
4606 Link_Nam := Expression (Link_Arg);
4607 end if;
4608
4609 -- Check expressions for external name and link name are static
4610
4611 if Present (Ext_Nam) then
4612 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
7406fc15 4613 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
996ae0b0 4614
7406fc15
RD
4615 -- Verify that external name is not the name of a local entity,
4616 -- which would hide the imported one and could lead to run-time
4617 -- surprises. The problem can only arise for entities declared in
4618 -- a package body (otherwise the external name is fully qualified
4619 -- and will not conflict).
996ae0b0
RK
4620
4621 declare
4622 Nam : Name_Id;
4623 E : Entity_Id;
4624 Par : Node_Id;
4625
4626 begin
4627 if Prag_Id = Pragma_Import then
4628 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4629 Nam := Name_Find;
4630 E := Entity_Id (Get_Name_Table_Info (Nam));
4631
4632 if Nam /= Chars (Subprogram_Def)
4633 and then Present (E)
4634 and then not Is_Overloadable (E)
4635 and then Is_Immediately_Visible (E)
4636 and then not Is_Imported (E)
4637 and then Ekind (Scope (E)) = E_Package
4638 then
4639 Par := Parent (E);
996ae0b0
RK
4640 while Present (Par) loop
4641 if Nkind (Par) = N_Package_Body then
7406fc15 4642 Error_Msg_Sloc := Sloc (E);
996ae0b0
RK
4643 Error_Msg_NE
4644 ("imported entity is hidden by & declared#",
7406fc15 4645 Ext_Arg, E);
996ae0b0
RK
4646 exit;
4647 end if;
4648
4649 Par := Parent (Par);
4650 end loop;
4651 end if;
4652 end if;
4653 end;
4654 end if;
4655
4656 if Present (Link_Nam) then
4657 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
7406fc15 4658 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
996ae0b0
RK
4659 end if;
4660
4661 -- If there is no link name, just set the external name
4662
4663 if No (Link_Nam) then
523456db 4664 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
996ae0b0
RK
4665
4666 -- For the Link_Name case, the given literal is preceded by an
b3b9865d
AC
4667 -- asterisk, which indicates to GCC that the given name should be
4668 -- taken literally, and in particular that no prepending of
996ae0b0
RK
4669 -- underlines should occur, even in systems where this is the
4670 -- normal default.
4671
4672 else
4673 Start_String;
2fa9443e
ES
4674
4675 if VM_Target = No_VM then
4676 Store_String_Char (Get_Char_Code ('*'));
4677 end if;
4678
996ae0b0 4679 String_Val := Strval (Expr_Value_S (Link_Nam));
b54ddf5a 4680 Store_String_Chars (String_Val);
996ae0b0 4681 Link_Nam :=
b54ddf5a
BD
4682 Make_String_Literal (Sloc (Link_Nam),
4683 Strval => End_String);
996ae0b0 4684 end if;
523456db
AC
4685
4686 Set_Encoded_Interface_Name
4687 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
8255bc9d
AC
4688
4689 -- We allow duplicated export names in CIL, as they are always
4690 -- enclosed in a namespace that differentiates them, and overloaded
4691 -- entities are supported by the VM.
4692
4693 if Convention (Subprogram_Def) /= Convention_CIL then
4694 Check_Duplicated_Export_Name (Link_Nam);
4695 end if;
996ae0b0
RK
4696 end Process_Interface_Name;
4697
4698 -----------------------------------------
4699 -- Process_Interrupt_Or_Attach_Handler --
4700 -----------------------------------------
4701
4702 procedure Process_Interrupt_Or_Attach_Handler is
0f1a6a0b 4703 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
fbf5a39b
AC
4704 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4705 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
996ae0b0
RK
4706
4707 begin
fbf5a39b 4708 Set_Is_Interrupt_Handler (Handler_Proc);
996ae0b0 4709
b3b9865d
AC
4710 -- If the pragma is not associated with a handler procedure within a
4711 -- protected type, then it must be for a nonprotected procedure for
4712 -- the AAMP target, in which case we don't associate a representation
4713 -- item with the procedure's scope.
996ae0b0 4714
fbf5a39b
AC
4715 if Ekind (Proc_Scope) = E_Protected_Type then
4716 if Prag_Id = Pragma_Interrupt_Handler
6e937c1c
AC
4717 or else
4718 Prag_Id = Pragma_Attach_Handler
fbf5a39b
AC
4719 then
4720 Record_Rep_Item (Proc_Scope, N);
4721 end if;
4722 end if;
996ae0b0
RK
4723 end Process_Interrupt_Or_Attach_Handler;
4724
6e937c1c
AC
4725 --------------------------------------------------
4726 -- Process_Restrictions_Or_Restriction_Warnings --
4727 --------------------------------------------------
4728
5f3ab6fb
AC
4729 -- Note: some of the simple identifier cases were handled in par-prag,
4730 -- but it is harmless (and more straightforward) to simply handle all
4731 -- cases here, even if it means we repeat a bit of work in some cases.
4732
ac9e9918
RD
4733 procedure Process_Restrictions_Or_Restriction_Warnings
4734 (Warn : Boolean)
4735 is
6e937c1c
AC
4736 Arg : Node_Id;
4737 R_Id : Restriction_Id;
4738 Id : Name_Id;
4739 Expr : Node_Id;
4740 Val : Uint;
4741
5f3ab6fb
AC
4742 procedure Check_Unit_Name (N : Node_Id);
4743 -- Checks unit name parameter for No_Dependence. Returns if it has
4744 -- an appropriate form, otherwise raises pragma argument error.
4745
5f3ab6fb
AC
4746 ---------------------
4747 -- Check_Unit_Name --
4748 ---------------------
4749
4750 procedure Check_Unit_Name (N : Node_Id) is
4751 begin
4752 if Nkind (N) = N_Selected_Component then
4753 Check_Unit_Name (Prefix (N));
4754 Check_Unit_Name (Selector_Name (N));
4755
4756 elsif Nkind (N) = N_Identifier then
4757 return;
4758
4759 else
4760 Error_Pragma_Arg
4761 ("wrong form for unit name for No_Dependence", N);
4762 end if;
4763 end Check_Unit_Name;
4764
6e937c1c
AC
4765 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4766
4767 begin
2551782d
AC
4768 -- Ignore all Restrictions pragma in CodePeer mode
4769
4770 if CodePeer_Mode then
4771 return;
4772 end if;
4773
6e937c1c
AC
4774 Check_Ada_83_Warning;
4775 Check_At_Least_N_Arguments (1);
4776 Check_Valid_Configuration_Pragma;
4777
4778 Arg := Arg1;
4779 while Present (Arg) loop
4780 Id := Chars (Arg);
0f1a6a0b 4781 Expr := Get_Pragma_Arg (Arg);
6e937c1c 4782
b5e792e2 4783 -- Case of no restriction identifier present
6e937c1c
AC
4784
4785 if Id = No_Name then
4786 if Nkind (Expr) /= N_Identifier then
4787 Error_Pragma_Arg
4788 ("invalid form for restriction", Arg);
b5e792e2 4789 end if;
6e937c1c 4790
b5e792e2
AC
4791 R_Id :=
4792 Get_Restriction_Id
cc335f43 4793 (Process_Restriction_Synonyms (Expr));
6e937c1c 4794
b5e792e2 4795 if R_Id not in All_Boolean_Restrictions then
21d27997
RD
4796 Error_Msg_Name_1 := Pname;
4797 Error_Msg_N
4798 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4799
4800 -- Check for possible misspelling
4801
4802 for J in Restriction_Id loop
4803 declare
4804 Rnm : constant String := Restriction_Id'Image (J);
4805
4806 begin
4807 Name_Buffer (1 .. Rnm'Length) := Rnm;
4808 Name_Len := Rnm'Length;
4809 Set_Casing (All_Lower_Case);
4810
4811 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4812 Set_Casing
4813 (Identifier_Casing (Current_Source_File));
4814 Error_Msg_String (1 .. Rnm'Length) :=
4815 Name_Buffer (1 .. Name_Len);
4816 Error_Msg_Strlen := Rnm'Length;
0c020dde 4817 Error_Msg_N -- CODEFIX
21d27997
RD
4818 ("\possible misspelling of ""~""",
4819 Get_Pragma_Arg (Arg));
4820 exit;
4821 end if;
4822 end;
4823 end loop;
4824
4825 raise Pragma_Exit;
b5e792e2 4826 end if;
6e937c1c 4827
b5e792e2 4828 if Implementation_Restriction (R_Id) then
21d27997 4829 Check_Restriction (No_Implementation_Restrictions, Arg);
b5e792e2 4830 end if;
6e937c1c 4831
ac9e9918
RD
4832 -- If this is a warning, then set the warning unless we already
4833 -- have a real restriction active (we never want a warning to
4834 -- override a real restriction).
6e937c1c 4835
ac9e9918
RD
4836 if Warn then
4837 if not Restriction_Active (R_Id) then
4838 Set_Restriction (R_Id, N);
4839 Restriction_Warnings (R_Id) := True;
4840 end if;
4841
4842 -- If real restriction case, then set it and make sure that the
4843 -- restriction warning flag is off, since a real restriction
4844 -- always overrides a warning.
6e937c1c 4845
ac9e9918
RD
4846 else
4847 Set_Restriction (R_Id, N);
4848 Restriction_Warnings (R_Id) := False;
4849 end if;
4850
b5c739f9
RD
4851 -- Check for obsolescent restrictions in Ada 2005 mode
4852
4853 if not Warn
4854 and then Ada_Version >= Ada_2005
4855 and then (R_Id = No_Asynchronous_Control
4856 or else
4857 R_Id = No_Unchecked_Deallocation
4858 or else
4859 R_Id = No_Unchecked_Conversion)
4860 then
4861 Check_Restriction (No_Obsolescent_Features, N);
4862 end if;
4863
ac9e9918
RD
4864 -- A very special case that must be processed here: pragma
4865 -- Restrictions (No_Exceptions) turns off all run-time
4866 -- checking. This is a bit dubious in terms of the formal
4867 -- language definition, but it is what is intended by RM
4868 -- H.4(12). Restriction_Warnings never affects generated code
4869 -- so this is done only in the real restriction case.
4870
4871 if R_Id = No_Exceptions and then not Warn then
b5e792e2 4872 Scope_Suppress := (others => True);
6e937c1c
AC
4873 end if;
4874
5f3ab6fb
AC
4875 -- Case of No_Dependence => unit-name. Note that the parser
4876 -- already made the necessary entry in the No_Dependence table.
4877
4878 elsif Id = Name_No_Dependence then
4879 Check_Unit_Name (Expr);
4880
4881 -- All other cases of restriction identifier present
6e937c1c
AC
4882
4883 else
cc335f43 4884 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
6e937c1c
AC
4885 Analyze_And_Resolve (Expr, Any_Integer);
4886
4887 if R_Id not in All_Parameter_Restrictions then
4888 Error_Pragma_Arg
4889 ("invalid restriction parameter identifier", Arg);
4890
4891 elsif not Is_OK_Static_Expression (Expr) then
4892 Flag_Non_Static_Expr
4893 ("value must be static expression!", Expr);
4894 raise Pragma_Exit;
4895
4896 elsif not Is_Integer_Type (Etype (Expr))
4897 or else Expr_Value (Expr) < 0
4898 then
4899 Error_Pragma_Arg
4900 ("value must be non-negative integer", Arg);
ac9e9918 4901 end if;
6e937c1c 4902
ac9e9918 4903 -- Restriction pragma is active
6e937c1c 4904
ac9e9918 4905 Val := Expr_Value (Expr);
6e937c1c 4906
ac9e9918
RD
4907 if not UI_Is_In_Int_Range (Val) then
4908 Error_Pragma_Arg
4909 ("pragma ignored, value too large?", Arg);
4910 end if;
4911
4912 -- Warning case. If the real restriction is active, then we
4913 -- ignore the request, since warning never overrides a real
4914 -- restriction. Otherwise we set the proper warning. Note that
4915 -- this circuit sets the warning again if it is already set,
4916 -- which is what we want, since the constant may have changed.
4917
4918 if Warn then
4919 if not Restriction_Active (R_Id) then
4920 Set_Restriction
4921 (R_Id, N, Integer (UI_To_Int (Val)));
4922 Restriction_Warnings (R_Id) := True;
6e937c1c 4923 end if;
ac9e9918
RD
4924
4925 -- Real restriction case, set restriction and make sure warning
4926 -- flag is off since real restriction always overrides warning.
4927
4928 else
4929 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4930 Restriction_Warnings (R_Id) := False;
6e937c1c
AC
4931 end if;
4932 end if;
4933
4934 Next (Arg);
4935 end loop;
4936 end Process_Restrictions_Or_Restriction_Warnings;
4937
996ae0b0
RK
4938 ---------------------------------
4939 -- Process_Suppress_Unsuppress --
4940 ---------------------------------
4941
fbf5a39b
AC
4942 -- Note: this procedure makes entries in the check suppress data
4943 -- structures managed by Sem. See spec of package Sem for full
4944 -- details on how we handle recording of check suppression.
4945
996ae0b0 4946 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
fbf5a39b
AC
4947 C : Check_Id;
4948 E_Id : Node_Id;
4949 E : Entity_Id;
4950
4951 In_Package_Spec : constant Boolean :=
b9b2405f 4952 Is_Package_Or_Generic_Package (Current_Scope)
fbf5a39b 4953 and then not In_Package_Body (Current_Scope);
996ae0b0
RK
4954
4955 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4956 -- Used to suppress a single check on the given entity
4957
fbf5a39b
AC
4958 --------------------------------
4959 -- Suppress_Unsuppress_Echeck --
4960 --------------------------------
4961
996ae0b0 4962 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
fbf5a39b
AC
4963 begin
4964 Set_Checks_May_Be_Suppressed (E);
996ae0b0 4965
fbf5a39b 4966 if In_Package_Spec then
c690a2ec
RD
4967 Push_Global_Suppress_Stack_Entry
4968 (Entity => E,
4969 Check => C,
4970 Suppress => Suppress_Case);
4971
fbf5a39b 4972 else
c690a2ec
RD
4973 Push_Local_Suppress_Stack_Entry
4974 (Entity => E,
4975 Check => C,
4976 Suppress => Suppress_Case);
996ae0b0
RK
4977 end if;
4978
4979 -- If this is a first subtype, and the base type is distinct,
4980 -- then also set the suppress flags on the base type.
4981
4982 if Is_First_Subtype (E)
4983 and then Etype (E) /= E
4984 then
4985 Suppress_Unsuppress_Echeck (Etype (E), C);
4986 end if;
4987 end Suppress_Unsuppress_Echeck;
4988
4989 -- Start of processing for Process_Suppress_Unsuppress
4990
4991 begin
76b5b000
AC
4992 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
4993 -- we want to generate checks for analysis purposes, as set by -gnatC
ddc1515a 4994
76b5b000 4995 if CodePeer_Mode and then Comes_From_Source (N) then
ddc1515a
AC
4996 return;
4997 end if;
4998
b3b9865d
AC
4999 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5000 -- declarative part or a package spec (RM 11.5(5)).
996ae0b0
RK
5001
5002 if not Is_Configuration_Pragma then
5003 Check_Is_In_Decl_Part_Or_Package_Spec;
5004 end if;
5005
5006 Check_At_Least_N_Arguments (1);
5007 Check_At_Most_N_Arguments (2);
5008 Check_No_Identifier (Arg1);
5009 Check_Arg_Is_Identifier (Arg1);
5010
0f1a6a0b 5011 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
c690a2ec
RD
5012
5013 if C = No_Check_Id then
996ae0b0
RK
5014 Error_Pragma_Arg
5015 ("argument of pragma% is not valid check name", Arg1);
996ae0b0
RK
5016 end if;
5017
2fa9443e
ES
5018 if not Suppress_Case
5019 and then (C = All_Checks or else C = Overflow_Check)
5020 then
5021 Opt.Overflow_Checks_Unsuppressed := True;
5022 end if;
5023
996ae0b0 5024 if Arg_Count = 1 then
996ae0b0 5025
fbf5a39b
AC
5026 -- Make an entry in the local scope suppress table. This is the
5027 -- table that directly shows the current value of the scope
5028 -- suppress check for any check id value.
996ae0b0 5029
fbf5a39b 5030 if C = All_Checks then
f02b8bb8 5031
c690a2ec
RD
5032 -- For All_Checks, we set all specific predefined checks with
5033 -- the exception of Elaboration_Check, which is handled
5034 -- specially because of not wanting All_Checks to have the
5035 -- effect of deactivating static elaboration order processing.
f02b8bb8 5036
dbee7ab9 5037 for J in Scope_Suppress'Range loop
f02b8bb8
RD
5038 if J /= Elaboration_Check then
5039 Scope_Suppress (J) := Suppress_Case;
5040 end if;
dbee7ab9 5041 end loop;
f02b8bb8 5042
c690a2ec
RD
5043 -- If not All_Checks, and predefined check, then set appropriate
5044 -- scope entry. Note that we will set Elaboration_Check if this
5045 -- is explicitly specified.
f02b8bb8 5046
c690a2ec 5047 elsif C in Predefined_Check_Id then
fbf5a39b
AC
5048 Scope_Suppress (C) := Suppress_Case;
5049 end if;
996ae0b0 5050
c690a2ec 5051 -- Also make an entry in the Local_Entity_Suppress table
996ae0b0 5052
c690a2ec
RD
5053 Push_Local_Suppress_Stack_Entry
5054 (Entity => Empty,
5055 Check => C,
5056 Suppress => Suppress_Case);
996ae0b0 5057
c690a2ec
RD
5058 -- Case of two arguments present, where the check is suppressed for
5059 -- a specified entity (given as the second argument of the pragma)
996ae0b0
RK
5060
5061 else
b5c739f9
RD
5062 -- This is obsolescent in Ada 2005 mode
5063
5064 if Ada_Version >= Ada_2005 then
5065 Check_Restriction (No_Obsolescent_Features, Arg2);
5066 end if;
5067
996ae0b0 5068 Check_Optional_Identifier (Arg2, Name_On);
0f1a6a0b 5069 E_Id := Get_Pragma_Arg (Arg2);
996ae0b0
RK
5070 Analyze (E_Id);
5071
5072 if not Is_Entity_Name (E_Id) then
5073 Error_Pragma_Arg
5074 ("second argument of pragma% must be entity name", Arg2);
5075 end if;
5076
5077 E := Entity (E_Id);
5078
5079 if E = Any_Id then
5080 return;
fbf5a39b 5081 end if;
996ae0b0 5082
fbf5a39b
AC
5083 -- Enforce RM 11.5(7) which requires that for a pragma that
5084 -- appears within a package spec, the named entity must be
5085 -- within the package spec. We allow the package name itself
5086 -- to be mentioned since that makes sense, although it is not
5087 -- strictly allowed by 11.5(7).
996ae0b0 5088
fbf5a39b
AC
5089 if In_Package_Spec
5090 and then E /= Current_Scope
5091 and then Scope (E) /= Current_Scope
5092 then
5093 Error_Pragma_Arg
c690a2ec 5094 ("entity in pragma% is not in package spec (RM 11.5(7))",
fbf5a39b
AC
5095 Arg2);
5096 end if;
996ae0b0 5097
fbf5a39b
AC
5098 -- Loop through homonyms. As noted below, in the case of a package
5099 -- spec, only homonyms within the package spec are considered.
996ae0b0 5100
fbf5a39b
AC
5101 loop
5102 Suppress_Unsuppress_Echeck (E, C);
996ae0b0 5103
fbf5a39b
AC
5104 if Is_Generic_Instance (E)
5105 and then Is_Subprogram (E)
5106 and then Present (Alias (E))
5107 then
5108 Suppress_Unsuppress_Echeck (Alias (E), C);
5109 end if;
5110
0f1a6a0b 5111 -- Move to next homonym if not aspect spec case
996ae0b0 5112
0f1a6a0b 5113 exit when From_Aspect_Specification (N);
fbf5a39b
AC
5114 E := Homonym (E);
5115 exit when No (E);
5116
b3b9865d
AC
5117 -- If we are within a package specification, the pragma only
5118 -- applies to homonyms in the same scope.
fbf5a39b
AC
5119
5120 exit when In_Package_Spec
5121 and then Scope (E) /= Current_Scope;
5122 end loop;
5123 end if;
996ae0b0
RK
5124 end Process_Suppress_Unsuppress;
5125
5126 ------------------
5127 -- Set_Exported --
5128 ------------------
5129
5130 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5131 begin
5132 if Is_Imported (E) then
ed2233dc 5133 Error_Pragma_Arg
996ae0b0
RK
5134 ("cannot export entity& that was previously imported", Arg);
5135
a780db15 5136 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
ed2233dc 5137 Error_Pragma_Arg
996ae0b0
RK
5138 ("cannot export entity& that has an address clause", Arg);
5139 end if;
5140
5141 Set_Is_Exported (E);
5142
fbf5a39b
AC
5143 -- Generate a reference for entity explicitly, because the
5144 -- identifier may be overloaded and name resolution will not
5145 -- generate one.
5146
5147 Generate_Reference (E, Arg);
5148
996ae0b0
RK
5149 -- Deal with exporting non-library level entity
5150
5151 if not Is_Library_Level_Entity (E) then
5152
5153 -- Not allowed at all for subprograms
5154
5155 if Is_Subprogram (E) then
ed2233dc 5156 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
996ae0b0
RK
5157
5158 -- Otherwise set public and statically allocated
5159
5160 else
5161 Set_Is_Public (E);
5162 Set_Is_Statically_Allocated (E);
fbf5a39b 5163
b3b9865d
AC
5164 -- Warn if the corresponding W flag is set and the pragma comes
5165 -- from source. The latter may not be true e.g. on VMS where we
5166 -- expand export pragmas for exception codes associated with
5167 -- imported or exported exceptions. We do not want to generate
5168 -- a warning for something that the user did not write.
af152989
AC
5169
5170 if Warn_On_Export_Import
5171 and then Comes_From_Source (Arg)
5172 then
fbf5a39b
AC
5173 Error_Msg_NE
5174 ("?& has been made static as a result of Export", Arg, E);
5175 Error_Msg_N
5176 ("\this usage is non-standard and non-portable", Arg);
5177 end if;
996ae0b0
RK
5178 end if;
5179 end if;
5180
fbf5a39b 5181 if Warn_On_Export_Import and then Is_Type (E) then
ed2233dc 5182 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
996ae0b0
RK
5183 end if;
5184
fbf5a39b
AC
5185 if Warn_On_Export_Import and Inside_A_Generic then
5186 Error_Msg_NE
5187 ("all instances of& will have the same external name?", Arg, E);
5188 end if;
996ae0b0
RK
5189 end Set_Exported;
5190
5191 ----------------------------------------------
5192 -- Set_Extended_Import_Export_External_Name --
5193 ----------------------------------------------
5194
5195 procedure Set_Extended_Import_Export_External_Name
5196 (Internal_Ent : Entity_Id;
5197 Arg_External : Node_Id)
5198 is
5199 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5200 New_Name : Node_Id;
5201
5202 begin
5203 if No (Arg_External) then
5204 return;
cc335f43
AC
5205 end if;
5206
5207 Check_Arg_Is_External_Name (Arg_External);
996ae0b0 5208
cc335f43 5209 if Nkind (Arg_External) = N_String_Literal then
996ae0b0
RK
5210 if String_Length (Strval (Arg_External)) = 0 then
5211 return;
5212 else
5213 New_Name := Adjust_External_Name_Case (Arg_External);
5214 end if;
5215
5216 elsif Nkind (Arg_External) = N_Identifier then
5217 New_Name := Get_Default_External_Name (Arg_External);
5218
b3b9865d
AC
5219 -- Check_Arg_Is_External_Name should let through only identifiers and
5220 -- string literals or static string expressions (which are folded to
5221 -- string literals).
cc335f43 5222
996ae0b0 5223 else
cc335f43 5224 raise Program_Error;
996ae0b0
RK
5225 end if;
5226
b3b9865d
AC
5227 -- If we already have an external name set (by a prior normal Import
5228 -- or Export pragma), then the external names must match
996ae0b0
RK
5229
5230 if Present (Interface_Name (Internal_Ent)) then
2c9beb8a 5231 Check_Matching_Internal_Names : declare
996ae0b0
RK
5232 S1 : constant String_Id := Strval (Old_Name);
5233 S2 : constant String_Id := Strval (New_Name);
5234
5235 procedure Mismatch;
5236 -- Called if names do not match
5237
2c9beb8a
RD
5238 --------------
5239 -- Mismatch --
5240 --------------
5241
996ae0b0
RK
5242 procedure Mismatch is
5243 begin
5244 Error_Msg_Sloc := Sloc (Old_Name);
5245 Error_Pragma_Arg
5246 ("external name does not match that given #",
5247 Arg_External);
5248 end Mismatch;
5249
2c9beb8a
RD
5250 -- Start of processing for Check_Matching_Internal_Names
5251
996ae0b0
RK
5252 begin
5253 if String_Length (S1) /= String_Length (S2) then
5254 Mismatch;
5255
5256 else
5257 for J in 1 .. String_Length (S1) loop
5258 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5259 Mismatch;
5260 end if;
5261 end loop;
5262 end if;
2c9beb8a 5263 end Check_Matching_Internal_Names;
996ae0b0
RK
5264
5265 -- Otherwise set the given name
5266
5267 else
5268 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
523456db 5269 Check_Duplicated_Export_Name (New_Name);
996ae0b0 5270 end if;
996ae0b0
RK
5271 end Set_Extended_Import_Export_External_Name;
5272
5273 ------------------
5274 -- Set_Imported --
5275 ------------------
5276
5277 procedure Set_Imported (E : Entity_Id) is
5278 begin
c690a2ec 5279 -- Error message if already imported or exported
996ae0b0
RK
5280
5281 if Is_Exported (E) or else Is_Imported (E) then
c28408b7
RD
5282
5283 -- Error if being set Exported twice
5284
996ae0b0 5285 if Is_Exported (E) then
c690a2ec 5286 Error_Msg_NE ("entity& was previously exported", N, E);
c28408b7
RD
5287
5288 -- OK if Import/Interface case
5289
5290 elsif Import_Interface_Present (N) then
5291 goto OK;
5292
5293 -- Error if being set Imported twice
5294
996ae0b0 5295 else
c690a2ec 5296 Error_Msg_NE ("entity& was previously imported", N, E);
996ae0b0
RK
5297 end if;
5298
1b24ada5 5299 Error_Msg_Name_1 := Pname;
c690a2ec
RD
5300 Error_Msg_N
5301 ("\(pragma% applies to all previous entities)", N);
5302
5303 Error_Msg_Sloc := Sloc (E);
ed2233dc 5304 Error_Msg_NE ("\import not allowed for& declared#", N, E);
c690a2ec
RD
5305
5306 -- Here if not previously imported or exported, OK to import
996ae0b0
RK
5307
5308 else
5309 Set_Is_Imported (E);
5310
b3b9865d
AC
5311 -- If the entity is an object that is not at the library level,
5312 -- then it is statically allocated. We do not worry about objects
5313 -- with address clauses in this context since they are not really
5314 -- imported in the linker sense.
996ae0b0
RK
5315
5316 if Is_Object (E)
5317 and then not Is_Library_Level_Entity (E)
5318 and then No (Address_Clause (E))
5319 then
5320 Set_Is_Statically_Allocated (E);
5321 end if;
5322 end if;
c28408b7
RD
5323
5324 <<OK>> null;
996ae0b0
RK
5325 end Set_Imported;
5326
5327 -------------------------
5328 -- Set_Mechanism_Value --
5329 -------------------------
5330
b3b9865d
AC
5331 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5332 -- analyzed, since it is semantic nonsense), so we get it in the exact
5333 -- form created by the parser.
996ae0b0
RK
5334
5335 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
292beb8f
AC
5336 Class : Node_Id;
5337 Param : Node_Id;
d628c015 5338 Mech_Name_Id : Name_Id;
996ae0b0
RK
5339
5340 procedure Bad_Class;
5341 -- Signal bad descriptor class name
5342
5343 procedure Bad_Mechanism;
5344 -- Signal bad mechanism name
5345
2c9beb8a
RD
5346 ---------------
5347 -- Bad_Class --
5348 ---------------
5349
996ae0b0
RK
5350 procedure Bad_Class is
5351 begin
5352 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5353 end Bad_Class;
5354
2c9beb8a
RD
5355 -------------------------
5356 -- Bad_Mechanism_Value --
5357 -------------------------
5358
996ae0b0
RK
5359 procedure Bad_Mechanism is
5360 begin
5361 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5362 end Bad_Mechanism;
5363
5364 -- Start of processing for Set_Mechanism_Value
5365
5366 begin
5367 if Mechanism (Ent) /= Default_Mechanism then
5368 Error_Msg_NE
5369 ("mechanism for & has already been set", Mech_Name, Ent);
5370 end if;
5371
d628c015
DR
5372 -- MECHANISM_NAME ::= value | reference | descriptor |
5373 -- short_descriptor
996ae0b0
RK
5374
5375 if Nkind (Mech_Name) = N_Identifier then
5376 if Chars (Mech_Name) = Name_Value then
5377 Set_Mechanism (Ent, By_Copy);
5378 return;
5379
5380 elsif Chars (Mech_Name) = Name_Reference then
5381 Set_Mechanism (Ent, By_Reference);
5382 return;
5383
5384 elsif Chars (Mech_Name) = Name_Descriptor then
5385 Check_VMS (Mech_Name);
292beb8f
AC
5386
5387 -- Descriptor => Short_Descriptor if pragma was given
5388
5389 if Short_Descriptors then
5390 Set_Mechanism (Ent, By_Short_Descriptor);
5391 else
5392 Set_Mechanism (Ent, By_Descriptor);
5393 end if;
5394
996ae0b0
RK
5395 return;
5396
d628c015
DR
5397 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5398 Check_VMS (Mech_Name);
5399 Set_Mechanism (Ent, By_Short_Descriptor);
5400 return;
5401
996ae0b0
RK
5402 elsif Chars (Mech_Name) = Name_Copy then
5403 Error_Pragma_Arg
5404 ("bad mechanism name, Value assumed", Mech_Name);
5405
5406 else
5407 Bad_Mechanism;
5408 end if;
5409
d628c015
DR
5410 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5411 -- short_descriptor (CLASS_NAME)
996ae0b0
RK
5412 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5413
5414 -- Note: this form is parsed as an indexed component
5415
5416 elsif Nkind (Mech_Name) = N_Indexed_Component then
5417 Class := First (Expressions (Mech_Name));
5418
5419 if Nkind (Prefix (Mech_Name)) /= N_Identifier
d628c015
DR
5420 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5421 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5422 or else Present (Next (Class))
996ae0b0
RK
5423 then
5424 Bad_Mechanism;
d628c015
DR
5425 else
5426 Mech_Name_Id := Chars (Prefix (Mech_Name));
292beb8f
AC
5427
5428 -- Change Descriptor => Short_Descriptor if pragma was given
5429
5430 if Mech_Name_Id = Name_Descriptor
5431 and then Short_Descriptors
5432 then
5433 Mech_Name_Id := Name_Short_Descriptor;
5434 end if;
996ae0b0
RK
5435 end if;
5436
d628c015
DR
5437 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5438 -- short_descriptor (Class => CLASS_NAME)
996ae0b0
RK
5439 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5440
5441 -- Note: this form is parsed as a function call
5442
5443 elsif Nkind (Mech_Name) = N_Function_Call then
996ae0b0
RK
5444 Param := First (Parameter_Associations (Mech_Name));
5445
5446 if Nkind (Name (Mech_Name)) /= N_Identifier
d628c015
DR
5447 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5448 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
996ae0b0
RK
5449 or else Present (Next (Param))
5450 or else No (Selector_Name (Param))
5451 or else Chars (Selector_Name (Param)) /= Name_Class
5452 then
5453 Bad_Mechanism;
5454 else
5455 Class := Explicit_Actual_Parameter (Param);
d628c015 5456 Mech_Name_Id := Chars (Name (Mech_Name));
996ae0b0
RK
5457 end if;
5458
5459 else
5460 Bad_Mechanism;
5461 end if;
5462
5463 -- Fall through here with Class set to descriptor class name
5464
5465 Check_VMS (Mech_Name);
5466
5467 if Nkind (Class) /= N_Identifier then
5468 Bad_Class;
5469
d628c015 5470 elsif Mech_Name_Id = Name_Descriptor
292beb8f 5471 and then Chars (Class) = Name_UBS
d628c015 5472 then
996ae0b0
RK
5473 Set_Mechanism (Ent, By_Descriptor_UBS);
5474
d628c015 5475 elsif Mech_Name_Id = Name_Descriptor
292beb8f 5476 and then Chars (Class) = Name_UBSB
d628c015 5477 then
996ae0b0
RK
5478 Set_Mechanism (Ent, By_Descriptor_UBSB);
5479
d628c015 5480 elsif Mech_Name_Id = Name_Descriptor
292beb8f 5481 and then Chars (Class) = Name_UBA
d628c015 5482 then
996ae0b0
RK
5483 Set_Mechanism (Ent, By_Descriptor_UBA);
5484
d628c015 5485 elsif Mech_Name_Id = Name_Descriptor
292beb8f 5486 and then Chars (Class) = Name_S
d628c015 5487 then
996ae0b0
RK
5488 Set_Mechanism (Ent, By_Descriptor_S);
5489
d628c015 5490 elsif Mech_Name_Id = Name_Descriptor
292beb8f 5491 and then Chars (Class) = Name_SB
d628c015 5492 then
996ae0b0
RK
5493 Set_Mechanism (Ent, By_Descriptor_SB);
5494
d628c015 5495 elsif Mech_Name_Id = Name_Descriptor
292beb8f 5496 and then Chars (Class) = Name_A
d628c015 5497 then
996ae0b0
RK
5498 Set_Mechanism (Ent, By_Descriptor_A);
5499
d628c015 5500 elsif Mech_Name_Id = Name_Descriptor
292beb8f 5501 and then Chars (Class) = Name_NCA
d628c015 5502 then
996ae0b0
RK
5503 Set_Mechanism (Ent, By_Descriptor_NCA);
5504
d628c015 5505 elsif Mech_Name_Id = Name_Short_Descriptor
292beb8f 5506 and then Chars (Class) = Name_UBS
d628c015
DR
5507 then
5508 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5509
5510 elsif Mech_Name_Id = Name_Short_Descriptor
292beb8f 5511 and then Chars (Class) = Name_UBSB
d628c015
DR
5512 then
5513 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5514
5515 elsif Mech_Name_Id = Name_Short_Descriptor
292beb8f 5516 and then Chars (Class) = Name_UBA
d628c015
DR
5517 then
5518 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5519
5520 elsif Mech_Name_Id = Name_Short_Descriptor
292beb8f 5521 and then Chars (Class) = Name_S
d628c015
DR
5522 then
5523 Set_Mechanism (Ent, By_Short_Descriptor_S);
5524
5525 elsif Mech_Name_Id = Name_Short_Descriptor
292beb8f 5526 and then Chars (Class) = Name_SB
d628c015
DR
5527 then
5528 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5529
5530 elsif Mech_Name_Id = Name_Short_Descriptor
292beb8f 5531 and then Chars (Class) = Name_A
d628c015
DR
5532 then
5533 Set_Mechanism (Ent, By_Short_Descriptor_A);
5534
5535 elsif Mech_Name_Id = Name_Short_Descriptor
292beb8f 5536 and then Chars (Class) = Name_NCA
d628c015
DR
5537 then
5538 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5539
996ae0b0
RK
5540 else
5541 Bad_Class;
5542 end if;
996ae0b0
RK
5543 end Set_Mechanism_Value;
5544
8a36a0cc
AC
5545 ---------------------------
5546 -- Set_Ravenscar_Profile --
5547 ---------------------------
5548
5549 -- The tasks to be done here are
5550
5551 -- Set required policies
5552
5553 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5554 -- pragma Locking_Policy (Ceiling_Locking)
5555
0da2c8ac 5556 -- Set Detect_Blocking mode
8a36a0cc 5557
cc335f43 5558 -- Set required restrictions (see System.Rident for detailed list)
8a36a0cc 5559
7fc53871
AC
5560 -- Set the No_Dependence rules
5561 -- No_Dependence => Ada.Asynchronous_Task_Control
5562 -- No_Dependence => Ada.Calendar
5563 -- No_Dependence => Ada.Execution_Time.Group_Budget
5564 -- No_Dependence => Ada.Execution_Time.Timers
5565 -- No_Dependence => Ada.Task_Attributes
5566 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5567
8a36a0cc 5568 procedure Set_Ravenscar_Profile (N : Node_Id) is
7fc53871
AC
5569 Prefix_Entity : Entity_Id;
5570 Selector_Entity : Entity_Id;
5571 Prefix_Node : Node_Id;
5572 Node : Node_Id;
5573
8a36a0cc
AC
5574 begin
5575 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5576
5577 if Task_Dispatching_Policy /= ' '
5578 and then Task_Dispatching_Policy /= 'F'
5579 then
5580 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5581 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5582
57193e09
TQ
5583 -- Set the FIFO_Within_Priorities policy, but always preserve
5584 -- System_Location since we like the error message with the run time
5585 -- name.
8a36a0cc
AC
5586
5587 else
5588 Task_Dispatching_Policy := 'F';
5589
5590 if Task_Dispatching_Policy_Sloc /= System_Location then
5591 Task_Dispatching_Policy_Sloc := Loc;
5592 end if;
5593 end if;
5594
5595 -- pragma Locking_Policy (Ceiling_Locking)
5596
5597 if Locking_Policy /= ' '
5598 and then Locking_Policy /= 'C'
5599 then
5600 Error_Msg_Sloc := Locking_Policy_Sloc;
5601 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5602
57193e09
TQ
5603 -- Set the Ceiling_Locking policy, but preserve System_Location since
5604 -- we like the error message with the run time name.
8a36a0cc
AC
5605
5606 else
5607 Locking_Policy := 'C';
5608
5609 if Locking_Policy_Sloc /= System_Location then
5610 Locking_Policy_Sloc := Loc;
5611 end if;
5612 end if;
5613
0da2c8ac
AC
5614 -- pragma Detect_Blocking
5615
5616 Detect_Blocking := True;
8a36a0cc
AC
5617
5618 -- Set the corresponding restrictions
5619
23e6615e
RD
5620 Set_Profile_Restrictions
5621 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
7fc53871
AC
5622
5623 -- Set the No_Dependence restrictions
5624
5625 -- The following No_Dependence restrictions:
5626 -- No_Dependence => Ada.Asynchronous_Task_Control
5627 -- No_Dependence => Ada.Calendar
5628 -- No_Dependence => Ada.Task_Attributes
5629 -- are already set by previous call to Set_Profile_Restrictions.
5630
5631 -- Set the following restrictions which were added to Ada 2005:
5632 -- No_Dependence => Ada.Execution_Time.Group_Budget
5633 -- No_Dependence => Ada.Execution_Time.Timers
5634
5635 if Ada_Version >= Ada_2005 then
5636 Name_Buffer (1 .. 3) := "ada";
5637 Name_Len := 3;
5638
5639 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5640
5641 Name_Buffer (1 .. 14) := "execution_time";
5642 Name_Len := 14;
5643
5644 Selector_Entity := Make_Identifier (Loc, Name_Find);
5645
5646 Prefix_Node :=
5647 Make_Selected_Component
5648 (Sloc => Loc,
5649 Prefix => Prefix_Entity,
5650 Selector_Name => Selector_Entity);
5651
5652 Name_Buffer (1 .. 13) := "group_budgets";
5653 Name_Len := 13;
5654
5655 Selector_Entity := Make_Identifier (Loc, Name_Find);
5656
5657 Node :=
5658 Make_Selected_Component
5659 (Sloc => Loc,
5660 Prefix => Prefix_Node,
5661 Selector_Name => Selector_Entity);
5662
5663 Set_Restriction_No_Dependence
5664 (Unit => Node,
5665 Warn => Treat_Restrictions_As_Warnings,
5666 Profile => Ravenscar);
5667
5668 Name_Buffer (1 .. 6) := "timers";
5669 Name_Len := 6;
5670
5671 Selector_Entity := Make_Identifier (Loc, Name_Find);
5672
5673 Node :=
5674 Make_Selected_Component
5675 (Sloc => Loc,
5676 Prefix => Prefix_Node,
5677 Selector_Name => Selector_Entity);
5678
5679 Set_Restriction_No_Dependence
5680 (Unit => Node,
5681 Warn => Treat_Restrictions_As_Warnings,
5682 Profile => Ravenscar);
5683 end if;
5684
5685 -- Set the following restrictions which was added to Ada 2012 (see
5686 -- AI-0171):
5687 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5688
5689 if Ada_Version >= Ada_2012 then
5690 Name_Buffer (1 .. 6) := "system";
5691 Name_Len := 6;
5692
5693 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5694
5695 Name_Buffer (1 .. 15) := "multiprocessors";
5696 Name_Len := 15;
5697
5698 Selector_Entity := Make_Identifier (Loc, Name_Find);
5699
5700 Prefix_Node :=
5701 Make_Selected_Component
5702 (Sloc => Loc,
5703 Prefix => Prefix_Entity,
5704 Selector_Name => Selector_Entity);
5705
5706 Name_Buffer (1 .. 19) := "dispatching_domains";
5707 Name_Len := 19;
5708
5709 Selector_Entity := Make_Identifier (Loc, Name_Find);
5710
5711 Node :=
5712 Make_Selected_Component
5713 (Sloc => Loc,
5714 Prefix => Prefix_Node,
5715 Selector_Name => Selector_Entity);
5716
5717 Set_Restriction_No_Dependence
5718 (Unit => Node,
5719 Warn => Treat_Restrictions_As_Warnings,
5720 Profile => Ravenscar);
5721 end if;
8a36a0cc
AC
5722 end Set_Ravenscar_Profile;
5723
996ae0b0
RK
5724 -- Start of processing for Analyze_Pragma
5725
5726 begin
d8b962d8
AC
5727 -- The following code is a defense against recursion. Not clear that
5728 -- this can happen legitimately, but perhaps some error situations
5729 -- can cause it, and we did see this recursion during testing.
5730
5731 if Analyzed (N) then
5732 return;
5733 else
5734 Set_Analyzed (N, True);
5735 end if;
5736
c690a2ec
RD
5737 -- Deal with unrecognized pragma
5738
1b24ada5 5739 if not Is_Pragma_Name (Pname) then
fbf5a39b 5740 if Warn_On_Unrecognized_Pragma then
1b24ada5 5741 Error_Msg_Name_1 := Pname;
470cd9e9 5742 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
c690a2ec
RD
5743
5744 for PN in First_Pragma_Name .. Last_Pragma_Name loop
1b24ada5 5745 if Is_Bad_Spelling_Of (Pname, PN) then
c690a2ec 5746 Error_Msg_Name_1 := PN;
0c020dde 5747 Error_Msg_N -- CODEFIX
470cd9e9 5748 ("\?possible misspelling of %!", Pragma_Identifier (N));
c690a2ec
RD
5749 exit;
5750 end if;
5751 end loop;
fbf5a39b 5752 end if;
c690a2ec
RD
5753
5754 return;
996ae0b0
RK
5755 end if;
5756
c690a2ec
RD
5757 -- Here to start processing for recognized pragma
5758
1b24ada5 5759 Prag_Id := Get_Pragma_Id (Pname);
c690a2ec 5760
996ae0b0
RK
5761 -- Preset arguments
5762
3d6c3bd7 5763 Arg_Count := 0;
1c54829e
AC
5764 Arg1 := Empty;
5765 Arg2 := Empty;
5766 Arg3 := Empty;
5767 Arg4 := Empty;
996ae0b0
RK
5768
5769 if Present (Pragma_Argument_Associations (N)) then
3d6c3bd7 5770 Arg_Count := List_Length (Pragma_Argument_Associations (N));
996ae0b0
RK
5771 Arg1 := First (Pragma_Argument_Associations (N));
5772
5773 if Present (Arg1) then
5774 Arg2 := Next (Arg1);
5775
5776 if Present (Arg2) then
5777 Arg3 := Next (Arg2);
5778
5779 if Present (Arg3) then
5780 Arg4 := Next (Arg3);
5781 end if;
5782 end if;
5783 end if;
5784 end if;
5785
996ae0b0 5786 -- An enumeration type defines the pragmas that are supported by the
f3d57416 5787 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
996ae0b0
RK
5788 -- into the corresponding enumeration value for the following case.
5789
5790 case Prag_Id is
5791
5792 -----------------
5793 -- Abort_Defer --
5794 -----------------
5795
5796 -- pragma Abort_Defer;
5797
5798 when Pragma_Abort_Defer =>
5799 GNAT_Pragma;
5800 Check_Arg_Count (0);
5801
5802 -- The only required semantic processing is to check the
5803 -- placement. This pragma must appear at the start of the
5804 -- statement sequence of a handled sequence of statements.
5805
5806 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5807 or else N /= First (Statements (Parent (N)))
5808 then
5809 Pragma_Misplaced;
5810 end if;
5811
5812 ------------
5813 -- Ada_83 --
5814 ------------
5815
5816 -- pragma Ada_83;
5817
5818 -- Note: this pragma also has some specific processing in Par.Prag
0ab80019 5819 -- because we want to set the Ada version mode during parsing.
996ae0b0
RK
5820
5821 when Pragma_Ada_83 =>
5822 GNAT_Pragma;
c690a2ec
RD
5823 Check_Arg_Count (0);
5824
5825 -- We really should check unconditionally for proper configuration
5826 -- pragma placement, since we really don't want mixed Ada modes
5827 -- within a single unit, and the GNAT reference manual has always
5828 -- said this was a configuration pragma, but we did not check and
5829 -- are hesitant to add the check now.
5830
0eed45bb
AC
5831 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5832 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5833 -- or Ada 2012 mode.
c690a2ec 5834
0791fbe9 5835 if Ada_Version >= Ada_2005 then
c690a2ec
RD
5836 Check_Valid_Configuration_Pragma;
5837 end if;
5838
5839 -- Now set Ada 83 mode
5840
0ab80019 5841 Ada_Version := Ada_83;
59e5fbe0 5842 Ada_Version_Explicit := Ada_Version;
996ae0b0
RK
5843
5844 ------------
5845 -- Ada_95 --
5846 ------------
5847
5848 -- pragma Ada_95;
5849
5850 -- Note: this pragma also has some specific processing in Par.Prag
0ab80019 5851 -- because we want to set the Ada 83 version mode during parsing.
996ae0b0
RK
5852
5853 when Pragma_Ada_95 =>
5854 GNAT_Pragma;
c690a2ec
RD
5855 Check_Arg_Count (0);
5856
5857 -- We really should check unconditionally for proper configuration
5858 -- pragma placement, since we really don't want mixed Ada modes
5859 -- within a single unit, and the GNAT reference manual has always
5860 -- said this was a configuration pragma, but we did not check and
5861 -- are hesitant to add the check now.
5862
5863 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5864 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5865
0791fbe9 5866 if Ada_Version >= Ada_2005 then
c690a2ec
RD
5867 Check_Valid_Configuration_Pragma;
5868 end if;
5869
5870 -- Now set Ada 95 mode
5871
0ab80019 5872 Ada_Version := Ada_95;
59e5fbe0 5873 Ada_Version_Explicit := Ada_Version;
0ab80019 5874
57193e09
TQ
5875 ---------------------
5876 -- Ada_05/Ada_2005 --
5877 ---------------------
0ab80019
AC
5878
5879 -- pragma Ada_05;
82c80734 5880 -- pragma Ada_05 (LOCAL_NAME);
0ab80019 5881
57193e09
TQ
5882 -- pragma Ada_2005;
5883 -- pragma Ada_2005 (LOCAL_NAME):
5884
599a7411 5885 -- Note: these pragmas also have some specific processing in Par.Prag
82c80734
RD
5886 -- because we want to set the Ada 2005 version mode during parsing.
5887
57193e09 5888 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
82c80734 5889 E_Id : Node_Id;
0ab80019 5890
82c80734 5891 begin
0ab80019 5892 GNAT_Pragma;
82c80734
RD
5893
5894 if Arg_Count = 1 then
5895 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 5896 E_Id := Get_Pragma_Arg (Arg1);
82c80734
RD
5897
5898 if Etype (E_Id) = Any_Type then
5899 return;
5900 end if;
5901
ac9e9918 5902 Set_Is_Ada_2005_Only (Entity (E_Id));
82c80734
RD
5903
5904 else
82c80734 5905 Check_Arg_Count (0);
c690a2ec
RD
5906
5907 -- For Ada_2005 we unconditionally enforce the documented
5908 -- configuration pragma placement, since we do not want to
5909 -- tolerate mixed modes in a unit involving Ada 2005. That
5910 -- would cause real difficulties for those cases where there
5911 -- are incompatibilities between Ada 95 and Ada 2005.
5912
5913 Check_Valid_Configuration_Pragma;
5914
0f1a6a0b
AC
5915 -- Now set appropriate Ada mode
5916
eaba57fb 5917 Ada_Version := Ada_2005;
0791fbe9 5918 Ada_Version_Explicit := Ada_2005;
82c80734
RD
5919 end if;
5920 end;
996ae0b0 5921
0eed45bb
AC
5922 ---------------------
5923 -- Ada_12/Ada_2012 --
5924 ---------------------
5925
5926 -- pragma Ada_12;
599a7411
AC
5927 -- pragma Ada_12 (LOCAL_NAME);
5928
0eed45bb 5929 -- pragma Ada_2012;
599a7411 5930 -- pragma Ada_2012 (LOCAL_NAME):
0eed45bb 5931
599a7411 5932 -- Note: these pragmas also have some specific processing in Par.Prag
0eed45bb
AC
5933 -- because we want to set the Ada 2012 version mode during parsing.
5934
599a7411
AC
5935 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5936 E_Id : Node_Id;
5937
5938 begin
0eed45bb 5939 GNAT_Pragma;
0eed45bb 5940
599a7411
AC
5941 if Arg_Count = 1 then
5942 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 5943 E_Id := Get_Pragma_Arg (Arg1);
599a7411
AC
5944
5945 if Etype (E_Id) = Any_Type then
5946 return;
5947 end if;
5948
5949 Set_Is_Ada_2012_Only (Entity (E_Id));
0eed45bb 5950
599a7411
AC
5951 else
5952 Check_Arg_Count (0);
0eed45bb 5953
599a7411
AC
5954 -- For Ada_2012 we unconditionally enforce the documented
5955 -- configuration pragma placement, since we do not want to
5956 -- tolerate mixed modes in a unit involving Ada 2012. That
5957 -- would cause real difficulties for those cases where there
5958 -- are incompatibilities between Ada 95 and Ada 2012. We could
5959 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
0eed45bb 5960
599a7411
AC
5961 Check_Valid_Configuration_Pragma;
5962
0f1a6a0b
AC
5963 -- Now set appropriate Ada mode
5964
eaba57fb 5965 Ada_Version := Ada_2012;
dbe945f1 5966 Ada_Version_Explicit := Ada_2012;
599a7411
AC
5967 end if;
5968 end;
0eed45bb 5969
996ae0b0
RK
5970 ----------------------
5971 -- All_Calls_Remote --
5972 ----------------------
5973
5974 -- pragma All_Calls_Remote [(library_package_NAME)];
5975
5976 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5977 Lib_Entity : Entity_Id;
5978
5979 begin
5980 Check_Ada_83_Warning;
5981 Check_Valid_Library_Unit_Pragma;
5982
5983 if Nkind (N) = N_Null_Statement then
5984 return;
5985 end if;
5986
5987 Lib_Entity := Find_Lib_Unit_Name;
5988
d9e0a587 5989 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
996ae0b0
RK
5990
5991 if Present (Lib_Entity)
5992 and then not Debug_Flag_U
5993 then
5994 if not Is_Remote_Call_Interface (Lib_Entity) then
5995 Error_Pragma ("pragma% only apply to rci unit");
5996
5997 -- Set flag for entity of the library unit
5998
5999 else
6000 Set_Has_All_Calls_Remote (Lib_Entity);
6001 end if;
6002
6003 end if;
6004 end All_Calls_Remote;
6005
6006 --------------
6007 -- Annotate --
6008 --------------
6009
d0995fa2 6010 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
996ae0b0 6011 -- ARG ::= NAME | EXPRESSION
d0995fa2
RD
6012
6013 -- The first two arguments are by convention intended to refer to an
6014 -- external tool and a tool-specific function. These arguments are
6015 -- not analyzed.
996ae0b0
RK
6016
6017 when Pragma_Annotate => Annotate : begin
6018 GNAT_Pragma;
6019 Check_At_Least_N_Arguments (1);
6020 Check_Arg_Is_Identifier (Arg1);
7eaa7cdf
RD
6021 Check_No_Identifiers;
6022 Store_Note (N);
996ae0b0
RK
6023
6024 declare
c690a2ec 6025 Arg : Node_Id;
996ae0b0
RK
6026 Exp : Node_Id;
6027
6028 begin
d0995fa2 6029 -- Second unanalyzed parameter is optional
996ae0b0 6030
c5ff22e7
AC
6031 if No (Arg2) then
6032 null;
226e989e
AC
6033 else
6034 Arg := Next (Arg2);
6035 while Present (Arg) loop
0f1a6a0b 6036 Exp := Get_Pragma_Arg (Arg);
226e989e 6037 Analyze (Exp);
996ae0b0 6038
226e989e
AC
6039 if Is_Entity_Name (Exp) then
6040 null;
996ae0b0 6041
ebd34478
AC
6042 -- For string literals, we assume Standard_String as the
6043 -- type, unless the string contains wide or wide_wide
6044 -- characters.
3bb3f6d6 6045
226e989e 6046 elsif Nkind (Exp) = N_String_Literal then
3bb3f6d6
AC
6047 if Has_Wide_Wide_Character (Exp) then
6048 Resolve (Exp, Standard_Wide_Wide_String);
3bb3f6d6
AC
6049 elsif Has_Wide_Character (Exp) then
6050 Resolve (Exp, Standard_Wide_String);
3bb3f6d6
AC
6051 else
6052 Resolve (Exp, Standard_String);
6053 end if;
996ae0b0 6054
226e989e
AC
6055 elsif Is_Overloaded (Exp) then
6056 Error_Pragma_Arg
6057 ("ambiguous argument for pragma%", Exp);
996ae0b0 6058
226e989e
AC
6059 else
6060 Resolve (Exp);
6061 end if;
6062
6063 Next (Arg);
6064 end loop;
6065 end if;
996ae0b0
RK
6066 end;
6067 end Annotate;
6068
6069 ------------
6070 -- Assert --
6071 ------------
6072
59e5fbe0
RD
6073 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6074 -- [, [Message =>] Static_String_EXPRESSION]);
996ae0b0 6075
ac9e9918
RD
6076 when Pragma_Assert => Assert : declare
6077 Expr : Node_Id;
21d27997 6078 Newa : List_Id;
ac9e9918
RD
6079
6080 begin
2fa9443e 6081 Ada_2005_Pragma;
59e5fbe0
RD
6082 Check_At_Least_N_Arguments (1);
6083 Check_At_Most_N_Arguments (2);
6084 Check_Arg_Order ((Name_Check, Name_Message));
6085 Check_Optional_Identifier (Arg1, Name_Check);
996ae0b0 6086
21d27997 6087 -- We treat pragma Assert as equivalent to:
996ae0b0 6088
21d27997 6089 -- pragma Check (Assertion, condition [, msg]);
996ae0b0 6090
21d27997 6091 -- So rewrite pragma in this manner, and analyze the result
470cd9e9 6092
21d27997
RD
6093 Expr := Get_Pragma_Arg (Arg1);
6094 Newa := New_List (
6095 Make_Pragma_Argument_Association (Loc,
7675ad4f 6096 Expression => Make_Identifier (Loc, Name_Assertion)),
996ae0b0 6097
21d27997
RD
6098 Make_Pragma_Argument_Association (Sloc (Expr),
6099 Expression => Expr));
ac9e9918 6100
21d27997
RD
6101 if Arg_Count > 1 then
6102 Check_Optional_Identifier (Arg2, Name_Message);
6103 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6104 Append_To (Newa, Relocate_Node (Arg2));
996ae0b0
RK
6105 end if;
6106
21d27997
RD
6107 Rewrite (N,
6108 Make_Pragma (Loc,
6109 Chars => Name_Check,
6110 Pragma_Argument_Associations => Newa));
6111 Analyze (N);
ac9e9918
RD
6112 end Assert;
6113
59e5fbe0
RD
6114 ----------------------
6115 -- Assertion_Policy --
6116 ----------------------
6117
6118 -- pragma Assertion_Policy (Check | Ignore)
6119
21d27997
RD
6120 when Pragma_Assertion_Policy => Assertion_Policy : declare
6121 Policy : Node_Id;
6122
6123 begin
2fa9443e 6124 Ada_2005_Pragma;
21d27997 6125 Check_Valid_Configuration_Pragma;
59e5fbe0 6126 Check_Arg_Count (1);
21d27997 6127 Check_No_Identifiers;
59e5fbe0 6128 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
21d27997
RD
6129
6130 -- We treat pragma Assertion_Policy as equivalent to:
6131
6132 -- pragma Check_Policy (Assertion, policy)
6133
6134 -- So rewrite the pragma in that manner and link on to the chain
6135 -- of Check_Policy pragmas, marking the pragma as analyzed.
6136
6137 Policy := Get_Pragma_Arg (Arg1);
6138
6139 Rewrite (N,
6140 Make_Pragma (Loc,
6141 Chars => Name_Check_Policy,
6142
6143 Pragma_Argument_Associations => New_List (
6144 Make_Pragma_Argument_Association (Loc,
7675ad4f 6145 Expression => Make_Identifier (Loc, Name_Assertion)),
21d27997
RD
6146
6147 Make_Pragma_Argument_Association (Loc,
6148 Expression =>
7675ad4f 6149 Make_Identifier (Sloc (Policy), Chars (Policy))))));
21d27997
RD
6150
6151 Set_Analyzed (N);
6152 Set_Next_Pragma (N, Opt.Check_Policy_List);
6153 Opt.Check_Policy_List := N;
6154 end Assertion_Policy;
59e5fbe0 6155
4351c21b
AC
6156 ------------------------------
6157 -- Assume_No_Invalid_Values --
6158 ------------------------------
6159
6160 -- pragma Assume_No_Invalid_Values (On | Off);
6161
6162 when Pragma_Assume_No_Invalid_Values =>
6163 GNAT_Pragma;
6164 Check_Valid_Configuration_Pragma;
6165 Check_Arg_Count (1);
6166 Check_No_Identifiers;
6167 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6168
0f1a6a0b 6169 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
4351c21b
AC
6170 Assume_No_Invalid_Values := True;
6171 else
6172 Assume_No_Invalid_Values := False;
6173 end if;
6174
996ae0b0
RK
6175 ---------------
6176 -- AST_Entry --
6177 ---------------
6178
6179 -- pragma AST_Entry (entry_IDENTIFIER);
6180
6181 when Pragma_AST_Entry => AST_Entry : declare
6182 Ent : Node_Id;
6183
6184 begin
6185 GNAT_Pragma;
6186 Check_VMS (N);
6187 Check_Arg_Count (1);
6188 Check_No_Identifiers;
6189 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 6190 Ent := Entity (Get_Pragma_Arg (Arg1));
996ae0b0
RK
6191
6192 -- Note: the implementation of the AST_Entry pragma could handle
6193 -- the entry family case fine, but for now we are consistent with
6194 -- the DEC rules, and do not allow the pragma, which of course
6195 -- has the effect of also forbidding the attribute.
6196
6197 if Ekind (Ent) /= E_Entry then
6198 Error_Pragma_Arg
6199 ("pragma% argument must be simple entry name", Arg1);
6200
6201 elsif Is_AST_Entry (Ent) then
6202 Error_Pragma_Arg
6203 ("duplicate % pragma for entry", Arg1);
6204
6205 elsif Has_Homonym (Ent) then
6206 Error_Pragma_Arg
6207 ("pragma% argument cannot specify overloaded entry", Arg1);
6208
6209 else
6210 declare
6211 FF : constant Entity_Id := First_Formal (Ent);
6212
6213 begin
6214 if Present (FF) then
6215 if Present (Next_Formal (FF)) then
6216 Error_Pragma_Arg
6217 ("entry for pragma% can have only one argument",
6218 Arg1);
6219
6220 elsif Parameter_Mode (FF) /= E_In_Parameter then
6221 Error_Pragma_Arg
6222 ("entry parameter for pragma% must have mode IN",
6223 Arg1);
6224 end if;
6225 end if;
6226 end;
6227
6228 Set_Is_AST_Entry (Ent);
6229 end if;
6230 end AST_Entry;
6231
6232 ------------------
6233 -- Asynchronous --
6234 ------------------
6235
6236 -- pragma Asynchronous (LOCAL_NAME);
6237
6238 when Pragma_Asynchronous => Asynchronous : declare
6239 Nm : Entity_Id;
6240 C_Ent : Entity_Id;
6241 L : List_Id;
6242 S : Node_Id;
6243 N : Node_Id;
6244 Formal : Entity_Id;
6245
6246 procedure Process_Async_Pragma;
6247 -- Common processing for procedure and access-to-procedure case
6248
6249 --------------------------
6250 -- Process_Async_Pragma --
6251 --------------------------
6252
6253 procedure Process_Async_Pragma is
6254 begin
57193e09 6255 if No (L) then
996ae0b0
RK
6256 Set_Is_Asynchronous (Nm);
6257 return;
6258 end if;
6259
6260 -- The formals should be of mode IN (RM E.4.1(6))
6261
6262 S := First (L);
6263 while Present (S) loop
6264 Formal := Defining_Identifier (S);
6265
6266 if Nkind (Formal) = N_Defining_Identifier
6267 and then Ekind (Formal) /= E_In_Parameter
6268 then
6269 Error_Pragma_Arg
6270 ("pragma% procedure can only have IN parameter",
6271 Arg1);
6272 end if;
6273
6274 Next (S);
6275 end loop;
6276
6277 Set_Is_Asynchronous (Nm);
6278 end Process_Async_Pragma;
6279
6280 -- Start of processing for pragma Asynchronous
6281
6282 begin
6283 Check_Ada_83_Warning;
6284 Check_No_Identifiers;
6285 Check_Arg_Count (1);
6286 Check_Arg_Is_Local_Name (Arg1);
6287
6288 if Debug_Flag_U then
6289 return;
6290 end if;
6291
6292 C_Ent := Cunit_Entity (Current_Sem_Unit);
0f1a6a0b
AC
6293 Analyze (Get_Pragma_Arg (Arg1));
6294 Nm := Entity (Get_Pragma_Arg (Arg1));
996ae0b0
RK
6295
6296 if not Is_Remote_Call_Interface (C_Ent)
6297 and then not Is_Remote_Types (C_Ent)
6298 then
6299 -- This pragma should only appear in an RCI or Remote Types
b3b9865d 6300 -- unit (RM E.4.1(4)).
996ae0b0
RK
6301
6302 Error_Pragma
6303 ("pragma% not in Remote_Call_Interface or " &
6304 "Remote_Types unit");
6305 end if;
6306
6307 if Ekind (Nm) = E_Procedure
6308 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6309 then
6310 if not Is_Remote_Call_Interface (Nm) then
6311 Error_Pragma_Arg
6312 ("pragma% cannot be applied on non-remote procedure",
6313 Arg1);
6314 end if;
6315
6316 L := Parameter_Specifications (Parent (Nm));
6317 Process_Async_Pragma;
6318 return;
6319
6320 elsif Ekind (Nm) = E_Function then
6321 Error_Pragma_Arg
6322 ("pragma% cannot be applied to function", Arg1);
6323
c857f5ed
TQ
6324 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6325
b3b9865d 6326 if Is_Record_Type (Nm) then
c857f5ed 6327
b3b9865d
AC
6328 -- A record type that is the Equivalent_Type for a remote
6329 -- access-to-subprogram type.
c885d7a1 6330
b3b9865d 6331 N := Declaration_Node (Corresponding_Remote_Type (Nm));
c857f5ed 6332
b3b9865d
AC
6333 else
6334 -- A non-expanded RAS type (distribution is not enabled)
6335
6336 N := Declaration_Node (Nm);
6337 end if;
996ae0b0
RK
6338
6339 if Nkind (N) = N_Full_Type_Declaration
6340 and then Nkind (Type_Definition (N)) =
6341 N_Access_Procedure_Definition
6342 then
6343 L := Parameter_Specifications (Type_Definition (N));
6344 Process_Async_Pragma;
6345
c885d7a1
AC
6346 if Is_Asynchronous (Nm)
6347 and then Expander_Active
c857f5ed 6348 and then Get_PCS_Name /= Name_No_DSA
c885d7a1 6349 then
c857f5ed 6350 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
c885d7a1
AC
6351 end if;
6352
996ae0b0
RK
6353 else
6354 Error_Pragma_Arg
6355 ("pragma% cannot reference access-to-function type",
6356 Arg1);
6357 end if;
6358
6359 -- Only other possibility is Access-to-class-wide type
6360
6361 elsif Is_Access_Type (Nm)
6362 and then Is_Class_Wide_Type (Designated_Type (Nm))
6363 then
6364 Check_First_Subtype (Arg1);
6365 Set_Is_Asynchronous (Nm);
6366 if Expander_Active then
6367 RACW_Type_Is_Asynchronous (Nm);
6368 end if;
6369
6370 else
6371 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6372 end if;
996ae0b0
RK
6373 end Asynchronous;
6374
6375 ------------
6376 -- Atomic --
6377 ------------
6378
6379 -- pragma Atomic (LOCAL_NAME);
6380
6381 when Pragma_Atomic =>
6382 Process_Atomic_Shared_Volatile;
6383
6384 -----------------------
6385 -- Atomic_Components --
6386 -----------------------
6387
6388 -- pragma Atomic_Components (array_LOCAL_NAME);
6389
6390 -- This processing is shared by Volatile_Components
6391
6392 when Pragma_Atomic_Components |
6393 Pragma_Volatile_Components =>
6394
6395 Atomic_Components : declare
6396 E_Id : Node_Id;
6397 E : Entity_Id;
6398 D : Node_Id;
6399 K : Node_Kind;
6400
6401 begin
996ae0b0
RK
6402 Check_Ada_83_Warning;
6403 Check_No_Identifiers;
6404 Check_Arg_Count (1);
6405 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 6406 E_Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
6407
6408 if Etype (E_Id) = Any_Type then
6409 return;
6410 end if;
6411
6412 E := Entity (E_Id);
6413
af31bffb
AC
6414 Check_Duplicate_Pragma (E);
6415
996ae0b0
RK
6416 if Rep_Item_Too_Early (E, N)
6417 or else
6418 Rep_Item_Too_Late (E, N)
6419 then
6420 return;
6421 end if;
6422
6423 D := Declaration_Node (E);
6424 K := Nkind (D);
6425
6426 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6427 or else
6428 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6429 and then Nkind (D) = N_Object_Declaration
6430 and then Nkind (Object_Definition (D)) =
6431 N_Constrained_Array_Definition)
6432 then
6433 -- The flag is set on the object, or on the base type
6434
6435 if Nkind (D) /= N_Object_Declaration then
6436 E := Base_Type (E);
6437 end if;
6438
eaba57fb 6439 Set_Has_Volatile_Components (E);
996ae0b0
RK
6440
6441 if Prag_Id = Pragma_Atomic_Components then
eaba57fb 6442 Set_Has_Atomic_Components (E);
996ae0b0
RK
6443 end if;
6444
6445 else
6446 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6447 end if;
6448 end Atomic_Components;
6449
6450 --------------------
6451 -- Attach_Handler --
6452 --------------------
6453
6454 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6455
6456 when Pragma_Attach_Handler =>
6457 Check_Ada_83_Warning;
6458 Check_No_Identifiers;
6459 Check_Arg_Count (2);
fbf5a39b
AC
6460
6461 if No_Run_Time_Mode then
6462 Error_Msg_CRT ("Attach_Handler pragma", N);
6463 else
6464 Check_Interrupt_Or_Attach_Handler;
6465
0f1a6a0b
AC
6466 -- The expression that designates the attribute may depend on a
6467 -- discriminant, and is therefore a per- object expression, to
6468 -- be expanded in the init proc. If expansion is enabled, then
6469 -- perform semantic checks on a copy only.
fbf5a39b
AC
6470
6471 if Expander_Active then
6472 declare
91b1417d 6473 Temp : constant Node_Id :=
0f1a6a0b 6474 New_Copy_Tree (Get_Pragma_Arg (Arg2));
fbf5a39b
AC
6475 begin
6476 Set_Parent (Temp, N);
21d27997 6477 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
fbf5a39b
AC
6478 end;
6479
6480 else
0f1a6a0b
AC
6481 Analyze (Get_Pragma_Arg (Arg2));
6482 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
fbf5a39b
AC
6483 end if;
6484
6485 Process_Interrupt_Or_Attach_Handler;
6486 end if;
996ae0b0
RK
6487
6488 --------------------
6489 -- C_Pass_By_Copy --
6490 --------------------
6491
6492 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6493
6494 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6495 Arg : Node_Id;
6496 Val : Uint;
6497
6498 begin
6499 GNAT_Pragma;
6500 Check_Valid_Configuration_Pragma;
6501 Check_Arg_Count (1);
6502 Check_Optional_Identifier (Arg1, "max_size");
6503
0f1a6a0b 6504 Arg := Get_Pragma_Arg (Arg1);
996ae0b0
RK
6505 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6506
6507 Val := Expr_Value (Arg);
6508
6509 if Val <= 0 then
6510 Error_Pragma_Arg
6511 ("maximum size for pragma% must be positive", Arg1);
6512
6513 elsif UI_Is_In_Int_Range (Val) then
6514 Default_C_Record_Mechanism := UI_To_Int (Val);
6515
6516 -- If a giant value is given, Int'Last will do well enough.
6517 -- If sometime someone complains that a record larger than
6518 -- two gigabytes is not copied, we will worry about it then!
6519
6520 else
6521 Default_C_Record_Mechanism := Mechanism_Type'Last;
6522 end if;
6523 end C_Pass_By_Copy;
6524
21d27997
RD
6525 -----------
6526 -- Check --
6527 -----------
6528
6529 -- pragma Check ([Name =>] Identifier,
6530 -- [Check =>] Boolean_Expression
6531 -- [,[Message =>] String_Expression]);
6532
6533 when Pragma_Check => Check : declare
6534 Expr : Node_Id;
6535 Eloc : Source_Ptr;
6536
6537 Check_On : Boolean;
6538 -- Set True if category of assertions referenced by Name enabled
6539
6540 begin
6541 GNAT_Pragma;
6542 Check_At_Least_N_Arguments (2);
6543 Check_At_Most_N_Arguments (3);
6544 Check_Optional_Identifier (Arg1, Name_Name);
6545 Check_Optional_Identifier (Arg2, Name_Check);
6546
6547 if Arg_Count = 3 then
6548 Check_Optional_Identifier (Arg3, Name_Message);
6549 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6550 end if;
6551
6552 Check_Arg_Is_Identifier (Arg1);
51bf9bdf
AC
6553
6554 -- Indicate if pragma is enabled. The Original_Node reference here
6555 -- is to deal with pragma Assert rewritten as a Check pragma.
6556
21d27997 6557 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
b26be063
AC
6558
6559 if Check_On then
6560 Set_Pragma_Enabled (N);
6561 Set_Pragma_Enabled (Original_Node (N));
6562 Set_SCO_Pragma_Enabled (Loc);
6563 end if;
21d27997
RD
6564
6565 -- If expansion is active and the check is not enabled then we
6566 -- rewrite the Check as:
6567
6568 -- if False and then condition then
6569 -- null;
6570 -- end if;
6571
6572 -- The reason we do this rewriting during semantic analysis rather
6573 -- than as part of normal expansion is that we cannot analyze and
6574 -- expand the code for the boolean expression directly, or it may
6575 -- cause insertion of actions that would escape the attempt to
6576 -- suppress the check code.
6577
6578 -- Note that the Sloc for the if statement corresponds to the
6579 -- argument condition, not the pragma itself. The reason for this
6580 -- is that we may generate a warning if the condition is False at
6581 -- compile time, and we do not want to delete this warning when we
6582 -- delete the if statement.
6583
0f1a6a0b 6584 Expr := Get_Pragma_Arg (Arg2);
21d27997
RD
6585
6586 if Expander_Active and then not Check_On then
6587 Eloc := Sloc (Expr);
6588
6589 Rewrite (N,
6590 Make_If_Statement (Eloc,
6591 Condition =>
6592 Make_And_Then (Eloc,
6593 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6594 Right_Opnd => Expr),
6595 Then_Statements => New_List (
6596 Make_Null_Statement (Eloc))));
6597
6598 Analyze (N);
6599
6600 -- Check is active
6601
6602 else
6603 Analyze_And_Resolve (Expr, Any_Boolean);
6604 end if;
21d27997
RD
6605 end Check;
6606
c690a2ec
RD
6607 ----------------
6608 -- Check_Name --
6609 ----------------
6610
6611 -- pragma Check_Name (check_IDENTIFIER);
6612
6613 when Pragma_Check_Name =>
6614 Check_No_Identifiers;
6615 GNAT_Pragma;
6616 Check_Valid_Configuration_Pragma;
6617 Check_Arg_Count (1);
6618 Check_Arg_Is_Identifier (Arg1);
6619
6620 declare
0f1a6a0b 6621 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
c690a2ec
RD
6622
6623 begin
6624 for J in Check_Names.First .. Check_Names.Last loop
6625 if Check_Names.Table (J) = Nam then
6626 return;
6627 end if;
6628 end loop;
6629
6630 Check_Names.Append (Nam);
6631 end;
6632
21d27997
RD
6633 ------------------
6634 -- Check_Policy --
6635 ------------------
6636
ef7c5692
AC
6637 -- pragma Check_Policy (
6638 -- [Name =>] IDENTIFIER,
6639 -- [Policy =>] POLICY_IDENTIFIER);
21d27997
RD
6640
6641 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6642
b3b9865d
AC
6643 -- Note: this is a configuration pragma, but it is allowed to appear
6644 -- anywhere else.
21d27997
RD
6645
6646 when Pragma_Check_Policy =>
6647 GNAT_Pragma;
6648 Check_Arg_Count (2);
21d27997 6649 Check_Optional_Identifier (Arg1, Name_Name);
ef7c5692 6650 Check_Optional_Identifier (Arg2, Name_Policy);
21d27997
RD
6651 Check_Arg_Is_One_Of
6652 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6653
6654 -- A Check_Policy pragma can appear either as a configuration
6655 -- pragma, or in a declarative part or a package spec (see RM
6656 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6657 -- followed for Check_Policy).
6658
6659 if not Is_Configuration_Pragma then
6660 Check_Is_In_Decl_Part_Or_Package_Spec;
6661 end if;
6662
6663 Set_Next_Pragma (N, Opt.Check_Policy_List);
6664 Opt.Check_Policy_List := N;
6665
c690a2ec
RD
6666 ---------------------
6667 -- CIL_Constructor --
6668 ---------------------
6669
6670 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6671
6672 -- Processing for this pragma is shared with Java_Constructor
6673
996ae0b0
RK
6674 -------------
6675 -- Comment --
6676 -------------
6677
6678 -- pragma Comment (static_string_EXPRESSION)
6679
a30a01fe
RD
6680 -- Processing for pragma Comment shares the circuitry for pragma
6681 -- Ident. The only differences are that Ident enforces a limit of 31
6682 -- characters on its argument, and also enforces limitations on
6683 -- placement for DEC compatibility. Pragma Comment shares neither of
6684 -- these restrictions.
996ae0b0
RK
6685
6686 -------------------
6687 -- Common_Object --
6688 -------------------
6689
6690 -- pragma Common_Object (
470cd9e9 6691 -- [Internal =>] LOCAL_NAME
996ae0b0
RK
6692 -- [, [External =>] EXTERNAL_SYMBOL]
6693 -- [, [Size =>] EXTERNAL_SYMBOL]);
6694
6695 -- Processing for this pragma is shared with Psect_Object
6696
874a0341
RD
6697 ------------------------
6698 -- Compile_Time_Error --
6699 ------------------------
6700
6701 -- pragma Compile_Time_Error
6702 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6703
6704 when Pragma_Compile_Time_Error =>
a30a01fe 6705 GNAT_Pragma;
874a0341
RD
6706 Process_Compile_Time_Warning_Or_Error;
6707
fbf5a39b
AC
6708 --------------------------
6709 -- Compile_Time_Warning --
6710 --------------------------
6711
6712 -- pragma Compile_Time_Warning
6713 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6714
874a0341 6715 when Pragma_Compile_Time_Warning =>
a30a01fe 6716 GNAT_Pragma;
874a0341 6717 Process_Compile_Time_Warning_Or_Error;
fbf5a39b 6718
2d9ea47f
RD
6719 -------------------
6720 -- Compiler_Unit --
6721 -------------------
6722
6723 when Pragma_Compiler_Unit =>
6724 GNAT_Pragma;
6725 Check_Arg_Count (0);
6726 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6727
c3217dac
RD
6728 -----------------------------
6729 -- Complete_Representation --
6730 -----------------------------
6731
6732 -- pragma Complete_Representation;
6733
6734 when Pragma_Complete_Representation =>
6735 GNAT_Pragma;
6736 Check_Arg_Count (0);
6737
6738 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6739 Error_Pragma
6740 ("pragma & must appear within record representation clause");
6741 end if;
6742
996ae0b0
RK
6743 ----------------------------
6744 -- Complex_Representation --
6745 ----------------------------
6746
6747 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6748
6749 when Pragma_Complex_Representation => Complex_Representation : declare
6750 E_Id : Entity_Id;
6751 E : Entity_Id;
6752 Ent : Entity_Id;
6753
6754 begin
6755 GNAT_Pragma;
6756 Check_Arg_Count (1);
6757 Check_Optional_Identifier (Arg1, Name_Entity);
6758 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 6759 E_Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
6760
6761 if Etype (E_Id) = Any_Type then
6762 return;
6763 end if;
6764
6765 E := Entity (E_Id);
6766
6767 if not Is_Record_Type (E) then
6768 Error_Pragma_Arg
6769 ("argument for pragma% must be record type", Arg1);
6770 end if;
6771
6772 Ent := First_Entity (E);
6773
6774 if No (Ent)
6775 or else No (Next_Entity (Ent))
6776 or else Present (Next_Entity (Next_Entity (Ent)))
6777 or else not Is_Floating_Point_Type (Etype (Ent))
6778 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6779 then
6780 Error_Pragma_Arg
470cd9e9
RD
6781 ("record for pragma% must have two fields of the same "
6782 & "floating-point type", Arg1);
996ae0b0
RK
6783
6784 else
6785 Set_Has_Complex_Representation (Base_Type (E));
c690a2ec
RD
6786
6787 -- We need to treat the type has having a non-standard
6788 -- representation, for back-end purposes, even though in
6789 -- general a complex will have the default representation
6790 -- of a record with two real components.
6791
6792 Set_Has_Non_Standard_Rep (Base_Type (E));
996ae0b0
RK
6793 end if;
6794 end Complex_Representation;
6795
6796 -------------------------
6797 -- Component_Alignment --
6798 -------------------------
6799
6800 -- pragma Component_Alignment (
6801 -- [Form =>] ALIGNMENT_CHOICE
6802 -- [, [Name =>] type_LOCAL_NAME]);
6803 --
6804 -- ALIGNMENT_CHOICE ::=
6805 -- Component_Size
6806 -- | Component_Size_4
6807 -- | Storage_Unit
6808 -- | Default
6809
6810 when Pragma_Component_Alignment => Component_AlignmentP : declare
6811 Args : Args_List (1 .. 2);
fbf5a39b 6812 Names : constant Name_List (1 .. 2) := (
996ae0b0
RK
6813 Name_Form,
6814 Name_Name);
6815
6816 Form : Node_Id renames Args (1);
6817 Name : Node_Id renames Args (2);
6818
6819 Atype : Component_Alignment_Kind;
6820 Typ : Entity_Id;
6821
6822 begin
6823 GNAT_Pragma;
6824 Gather_Associations (Names, Args);
6825
6826 if No (Form) then
6827 Error_Pragma ("missing Form argument for pragma%");
6828 end if;
6829
6830 Check_Arg_Is_Identifier (Form);
6831
b3b9865d
AC
6832 -- Get proper alignment, note that Default = Component_Size on all
6833 -- machines we have so far, and we want to set this value rather
6834 -- than the default value to indicate that it has been explicitly
6835 -- set (and thus will not get overridden by the default component
6836 -- alignment for the current scope)
996ae0b0
RK
6837
6838 if Chars (Form) = Name_Component_Size then
6839 Atype := Calign_Component_Size;
6840
6841 elsif Chars (Form) = Name_Component_Size_4 then
6842 Atype := Calign_Component_Size_4;
6843
6844 elsif Chars (Form) = Name_Default then
6845 Atype := Calign_Component_Size;
6846
6847 elsif Chars (Form) = Name_Storage_Unit then
6848 Atype := Calign_Storage_Unit;
6849
6850 else
6851 Error_Pragma_Arg
6852 ("invalid Form parameter for pragma%", Form);
6853 end if;
6854
6855 -- Case with no name, supplied, affects scope table entry
6856
6857 if No (Name) then
6858 Scope_Stack.Table
6859 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6860
6861 -- Case of name supplied
6862
6863 else
6864 Check_Arg_Is_Local_Name (Name);
6865 Find_Type (Name);
6866 Typ := Entity (Name);
6867
6868 if Typ = Any_Type
6869 or else Rep_Item_Too_Early (Typ, N)
6870 then
6871 return;
6872 else
6873 Typ := Underlying_Type (Typ);
6874 end if;
6875
6876 if not Is_Record_Type (Typ)
6877 and then not Is_Array_Type (Typ)
6878 then
6879 Error_Pragma_Arg
6880 ("Name parameter of pragma% must identify record or " &
6881 "array type", Name);
6882 end if;
6883
6884 -- An explicit Component_Alignment pragma overrides an
6885 -- implicit pragma Pack, but not an explicit one.
6886
6887 if not Has_Pragma_Pack (Base_Type (Typ)) then
6888 Set_Is_Packed (Base_Type (Typ), False);
6889 Set_Component_Alignment (Base_Type (Typ), Atype);
6890 end if;
6891 end if;
996ae0b0
RK
6892 end Component_AlignmentP;
6893
6894 ----------------
6895 -- Controlled --
6896 ----------------
6897
6898 -- pragma Controlled (first_subtype_LOCAL_NAME);
6899
6900 when Pragma_Controlled => Controlled : declare
6901 Arg : Node_Id;
6902
6903 begin
6904 Check_No_Identifiers;
6905 Check_Arg_Count (1);
6906 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 6907 Arg := Get_Pragma_Arg (Arg1);
996ae0b0
RK
6908
6909 if not Is_Entity_Name (Arg)
6910 or else not Is_Access_Type (Entity (Arg))
6911 then
6912 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6913 else
6914 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6915 end if;
6916 end Controlled;
6917
6918 ----------------
6919 -- Convention --
6920 ----------------
6921
6922 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6923 -- [Entity =>] LOCAL_NAME);
6924
6925 when Pragma_Convention => Convention : declare
6926 C : Convention_Id;
6927 E : Entity_Id;
67ce0d7e
RD
6928 pragma Warnings (Off, C);
6929 pragma Warnings (Off, E);
996ae0b0 6930 begin
59e5fbe0 6931 Check_Arg_Order ((Name_Convention, Name_Entity));
996ae0b0
RK
6932 Check_Ada_83_Warning;
6933 Check_Arg_Count (2);
6934 Process_Convention (C, E);
6935 end Convention;
6936
07fc65c4
GB
6937 ---------------------------
6938 -- Convention_Identifier --
6939 ---------------------------
6940
6941 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6942 -- [Convention =>] convention_IDENTIFIER);
6943
6944 when Pragma_Convention_Identifier => Convention_Identifier : declare
6945 Idnam : Name_Id;
6946 Cname : Name_Id;
6947
6948 begin
6949 GNAT_Pragma;
59e5fbe0 6950 Check_Arg_Order ((Name_Name, Name_Convention));
07fc65c4
GB
6951 Check_Arg_Count (2);
6952 Check_Optional_Identifier (Arg1, Name_Name);
6953 Check_Optional_Identifier (Arg2, Name_Convention);
6954 Check_Arg_Is_Identifier (Arg1);
c690a2ec 6955 Check_Arg_Is_Identifier (Arg2);
0f1a6a0b
AC
6956 Idnam := Chars (Get_Pragma_Arg (Arg1));
6957 Cname := Chars (Get_Pragma_Arg (Arg2));
07fc65c4
GB
6958
6959 if Is_Convention_Name (Cname) then
6960 Record_Convention_Identifier
6961 (Idnam, Get_Convention_Id (Cname));
6962 else
6963 Error_Pragma_Arg
6964 ("second arg for % pragma must be convention", Arg2);
6965 end if;
6966 end Convention_Identifier;
6967
996ae0b0
RK
6968 ---------------
6969 -- CPP_Class --
6970 ---------------
6971
6972 -- pragma CPP_Class ([Entity =>] local_NAME)
6973
6974 when Pragma_CPP_Class => CPP_Class : declare
874a0341
RD
6975 Arg : Node_Id;
6976 Typ : Entity_Id;
996ae0b0
RK
6977
6978 begin
874a0341 6979 if Warn_On_Obsolescent_Feature then
ed2233dc 6980 Error_Msg_N
874a0341
RD
6981 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6982 " by pragma import?", N);
6983 end if;
6984
996ae0b0
RK
6985 GNAT_Pragma;
6986 Check_Arg_Count (1);
6987 Check_Optional_Identifier (Arg1, Name_Entity);
6988 Check_Arg_Is_Local_Name (Arg1);
6989
0f1a6a0b 6990 Arg := Get_Pragma_Arg (Arg1);
996ae0b0
RK
6991 Analyze (Arg);
6992
6993 if Etype (Arg) = Any_Type then
6994 return;
6995 end if;
6996
6997 if not Is_Entity_Name (Arg)
6998 or else not Is_Type (Entity (Arg))
6999 then
7000 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7001 end if;
7002
7003 Typ := Entity (Arg);
7004
996ae0b0 7005 if not Is_Tagged_Type (Typ) then
874a0341 7006 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
996ae0b0 7007 end if;
874a0341 7008
2fa9443e
ES
7009 -- Types treated as CPP classes are treated as limited, but we
7010 -- don't require them to be declared this way. A warning is issued
7011 -- to encourage the user to declare them as limited. This is not
7012 -- an error, for compatibility reasons, because these types have
7013 -- been supported this way for some time.
7014
7015 if not Is_Limited_Type (Typ) then
ed2233dc 7016 Error_Msg_N
2fa9443e
ES
7017 ("imported 'C'P'P type should be " &
7018 "explicitly declared limited?",
7019 Get_Pragma_Arg (Arg1));
7020 Error_Msg_N
7021 ("\type will be considered limited",
7022 Get_Pragma_Arg (Arg1));
7023 end if;
7024
874a0341
RD
7025 Set_Is_CPP_Class (Typ);
7026 Set_Is_Limited_Record (Typ);
7027 Set_Convention (Typ, Convention_CPP);
0c020dde
AC
7028
7029 -- Imported CPP types must not have discriminants (because C++
7030 -- classes do not have discriminants).
7031
7032 if Has_Discriminants (Typ) then
7033 Error_Msg_N
7034 ("imported 'C'P'P type cannot have discriminants",
7035 First (Discriminant_Specifications
7036 (Declaration_Node (Typ))));
7037 end if;
7038
7039 -- Components of imported CPP types must not have default
7040 -- expressions because the constructor (if any) is in the
7041 -- C++ side.
7042
7043 if Is_Incomplete_Or_Private_Type (Typ)
7044 and then No (Underlying_Type (Typ))
7045 then
7046 -- It should be an error to apply pragma CPP to a private
7047 -- type if the underlying type is not visible (as it is
7048 -- for any representation item). For now, for backward
7049 -- compatibility we do nothing but we cannot check components
7050 -- because they are not available at this stage. All this code
7051 -- will be removed when we cleanup this obsolete GNAT pragma???
7052
7053 null;
7054
7055 else
7056 declare
7057 Tdef : constant Node_Id :=
7058 Type_Definition (Declaration_Node (Typ));
7059 Clist : Node_Id;
7060 Comp : Node_Id;
7061
7062 begin
7063 if Nkind (Tdef) = N_Record_Definition then
7064 Clist := Component_List (Tdef);
7065 else
7066 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7067 Clist := Component_List (Record_Extension_Part (Tdef));
7068 end if;
7069
7070 if Present (Clist) then
7071 Comp := First (Component_Items (Clist));
7072 while Present (Comp) loop
7073 if Present (Expression (Comp)) then
7074 Error_Msg_N
7075 ("component of imported 'C'P'P type cannot have" &
7076 " default expression", Expression (Comp));
7077 end if;
7078
7079 Next (Comp);
7080 end loop;
7081 end if;
7082 end;
7083 end if;
996ae0b0
RK
7084 end CPP_Class;
7085
7086 ---------------------
7087 -- CPP_Constructor --
7088 ---------------------
7089
874a0341
RD
7090 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7091 -- [, [External_Name =>] static_string_EXPRESSION ]
7092 -- [, [Link_Name =>] static_string_EXPRESSION ]);
996ae0b0
RK
7093
7094 when Pragma_CPP_Constructor => CPP_Constructor : declare
7b4db06c
JM
7095 Elmt : Elmt_Id;
7096 Id : Entity_Id;
7097 Def_Id : Entity_Id;
7098 Tag_Typ : Entity_Id;
996ae0b0
RK
7099
7100 begin
7101 GNAT_Pragma;
874a0341
RD
7102 Check_At_Least_N_Arguments (1);
7103 Check_At_Most_N_Arguments (3);
996ae0b0
RK
7104 Check_Optional_Identifier (Arg1, Name_Entity);
7105 Check_Arg_Is_Local_Name (Arg1);
7106
0f1a6a0b 7107 Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
7108 Find_Program_Unit_Name (Id);
7109
7110 -- If we did not find the name, we are done
7111
7112 if Etype (Id) = Any_Type then
7113 return;
7114 end if;
7115
7116 Def_Id := Entity (Id);
7117
cefce34c
JM
7118 -- Check if already defined as constructor
7119
7120 if Is_Constructor (Def_Id) then
7121 Error_Msg_N
7122 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7123 return;
7124 end if;
7125
996ae0b0 7126 if Ekind (Def_Id) = E_Function
7b4db06c
JM
7127 and then (Is_CPP_Class (Etype (Def_Id))
7128 or else (Is_Class_Wide_Type (Etype (Def_Id))
7129 and then
7130 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
996ae0b0 7131 then
996ae0b0 7132 if Arg_Count >= 2 then
874a0341
RD
7133 Set_Imported (Def_Id);
7134 Set_Is_Public (Def_Id);
996ae0b0
RK
7135 Process_Interface_Name (Def_Id, Arg2, Arg3);
7136 end if;
7137
236fecbf
JM
7138 Set_Has_Completion (Def_Id);
7139 Set_Is_Constructor (Def_Id);
996ae0b0 7140
7b4db06c
JM
7141 -- Imported C++ constructors are not dispatching primitives
7142 -- because in C++ they don't have a dispatch table slot.
7143 -- However, in Ada the constructor has the profile of a
7144 -- function that returns a tagged type and therefore it has
3c92a2b8
AC
7145 -- been treated as a primitive operation during semantic
7146 -- analysis. We now remove it from the list of primitive
7147 -- operations of the type.
7b4db06c
JM
7148
7149 if Is_Tagged_Type (Etype (Def_Id))
7150 and then not Is_Class_Wide_Type (Etype (Def_Id))
7151 then
7152 pragma Assert (Is_Dispatching_Operation (Def_Id));
7153 Tag_Typ := Etype (Def_Id);
7154
7155 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
3c92a2b8 7156 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7b4db06c
JM
7157 Next_Elmt (Elmt);
7158 end loop;
7159
7160 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7161 Set_Is_Dispatching_Operation (Def_Id, False);
7162 end if;
7163
7164 -- For backward compatibility, if the constructor returns a
3c92a2b8
AC
7165 -- class wide type, and we internally change the return type to
7166 -- the corresponding root type.
7b4db06c
JM
7167
7168 if Is_Class_Wide_Type (Etype (Def_Id)) then
7169 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7170 end if;
996ae0b0
RK
7171 else
7172 Error_Pragma_Arg
7173 ("pragma% requires function returning a 'C'P'P_Class type",
7174 Arg1);
7175 end if;
7176 end CPP_Constructor;
7177
7178 -----------------
7179 -- CPP_Virtual --
7180 -----------------
7181
996ae0b0 7182 when Pragma_CPP_Virtual => CPP_Virtual : declare
996ae0b0 7183 begin
a30a01fe
RD
7184 GNAT_Pragma;
7185
874a0341 7186 if Warn_On_Obsolescent_Feature then
ed2233dc 7187 Error_Msg_N
874a0341
RD
7188 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7189 "no effect?", N);
996ae0b0
RK
7190 end if;
7191 end CPP_Virtual;
7192
7193 ----------------
7194 -- CPP_Vtable --
7195 ----------------
7196
996ae0b0 7197 when Pragma_CPP_Vtable => CPP_Vtable : declare
996ae0b0 7198 begin
a30a01fe
RD
7199 GNAT_Pragma;
7200
874a0341 7201 if Warn_On_Obsolescent_Feature then
ed2233dc 7202 Error_Msg_N
874a0341
RD
7203 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7204 "no effect?", N);
996ae0b0 7205 end if;
996ae0b0
RK
7206 end CPP_Vtable;
7207
8918fe18
AC
7208 ---------
7209 -- CPU --
7210 ---------
7211
7212 -- pragma CPU (EXPRESSION);
7213
7214 when Pragma_CPU => CPU : declare
7215 P : constant Node_Id := Parent (N);
7216 Arg : Node_Id;
7217
7218 begin
7219 Ada_2012_Pragma;
7220 Check_No_Identifiers;
7221 Check_Arg_Count (1);
7222
7223 -- Subprogram case
7224
7225 if Nkind (P) = N_Subprogram_Body then
7226 Check_In_Main_Program;
7227
7228 Arg := Get_Pragma_Arg (Arg1);
7229 Analyze_And_Resolve (Arg, Any_Integer);
7230
7231 -- Must be static
7232
7233 if not Is_Static_Expression (Arg) then
7234 Flag_Non_Static_Expr
7235 ("main subprogram affinity is not static!", Arg);
7236 raise Pragma_Exit;
7237
7238 -- If constraint error, then we already signalled an error
7239
7240 elsif Raises_Constraint_Error (Arg) then
7241 null;
7242
7243 -- Otherwise check in range
7244
7245 else
7246 declare
7247 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7248 -- This is the entity System.Multiprocessors.CPU_Range;
7249
7250 Val : constant Uint := Expr_Value (Arg);
7251
7252 begin
7253 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7254 or else
7255 Val > Expr_Value (Type_High_Bound (CPU_Id))
7256 then
7257 Error_Pragma_Arg
7258 ("main subprogram CPU is out of range", Arg1);
7259 end if;
7260 end;
7261 end if;
7262
7263 Set_Main_CPU
7264 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7265
7266 -- Task case
7267
7268 elsif Nkind (P) = N_Task_Definition then
7269 Arg := Get_Pragma_Arg (Arg1);
7270
7271 -- The expression must be analyzed in the special manner
7272 -- described in "Handling of Default and Per-Object
7273 -- Expressions" in sem.ads.
7274
7275 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7276
7277 -- Anything else is incorrect
7278
7279 else
7280 Pragma_Misplaced;
7281 end if;
7282
7283 if Has_Pragma_CPU (P) then
7284 Error_Pragma ("duplicate pragma% not allowed");
7285 else
7286 Set_Has_Pragma_CPU (P, True);
7287
7288 if Nkind (P) = N_Task_Definition then
7289 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7290 end if;
7291 end if;
7292 end CPU;
7293
996ae0b0
RK
7294 -----------
7295 -- Debug --
7296 -----------
7297
c3217dac
RD
7298 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7299
7300 when Pragma_Debug => Debug : declare
7301 Cond : Node_Id;
996ae0b0 7302
c3217dac 7303 begin
996ae0b0
RK
7304 GNAT_Pragma;
7305
c3217dac
RD
7306 Cond :=
7307 New_Occurrence_Of
7308 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7309 Loc);
7310
7311 if Arg_Count = 2 then
7312 Cond :=
7313 Make_And_Then (Loc,
7314 Left_Opnd => Relocate_Node (Cond),
0f1a6a0b 7315 Right_Opnd => Get_Pragma_Arg (Arg1));
c3217dac
RD
7316 end if;
7317
7318 -- Rewrite into a conditional with an appropriate condition. We
7319 -- wrap the procedure call in a block so that overhead from e.g.
7320 -- use of the secondary stack does not generate execution overhead
7321 -- for suppressed conditions.
996ae0b0 7322
6cdb2c6e 7323 Rewrite (N, Make_Implicit_If_Statement (N,
c3217dac
RD
7324 Condition => Cond,
7325 Then_Statements => New_List (
7326 Make_Block_Statement (Loc,
7327 Handled_Statement_Sequence =>
7328 Make_Handled_Sequence_Of_Statements (Loc,
7329 Statements => New_List (
7330 Relocate_Node (Debug_Statement (N))))))));
6cdb2c6e 7331 Analyze (N);
996ae0b0
RK
7332 end Debug;
7333
6e18b0e5
RD
7334 ------------------
7335 -- Debug_Policy --
7336 ------------------
7337
7338 -- pragma Debug_Policy (Check | Ignore)
7339
7340 when Pragma_Debug_Policy =>
7341 GNAT_Pragma;
7342 Check_Arg_Count (1);
7343 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
0f1a6a0b
AC
7344 Debug_Pragmas_Enabled :=
7345 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
6e18b0e5 7346
19fb051c
AC
7347 -----------------------------
7348 -- Default_Component_Value --
7349 -----------------------------
7350
7351 when Pragma_Default_Component_Value => declare
7352 Arg : Node_Id;
7353 E : Entity_Id;
7354
7355 begin
7356 GNAT_Pragma;
7357 Check_Arg_Count (2);
7358 Check_Arg_Is_Local_Name (Arg1);
7359
7360 Arg := Get_Pragma_Arg (Arg1);
7361 Analyze (Arg);
7362
7363 if Etype (Arg) = Any_Type then
7364 return;
7365 end if;
7366
7367 if not Is_Entity_Name (Arg)
7368 or else not Is_Array_Type (Entity (Arg))
7369 then
7370 Error_Pragma_Arg ("pragma% requires an array type", Arg1);
7371 end if;
7372
7373 Check_First_Subtype (Arg1);
7374
7375 E := Entity (Arg);
7376 Check_Duplicate_Pragma (E);
7377
7378 -- Check for rep item too early or too late, but skip this if
7379 -- the pragma comes from the corresponding aspect, since we do
7380 -- not need the checks, and more importantly, the pragma is on
7381 -- the rep item chain alreay, and must not be put there twice!
7382
7383 if not From_Aspect_Specification (N) then
7384 if Rep_Item_Too_Early (E, N)
7385 or else
7386 Rep_Item_Too_Late (E, N)
7387 then
7388 return;
7389 end if;
7390 end if;
7391
7392 -- Analyze the default value
7393
7394 Arg := Get_Pragma_Arg (Arg2);
7395 Analyze_And_Resolve (Arg, Component_Type (E));
7396
7397 if not Is_OK_Static_Expression (Arg) then
7398 Flag_Non_Static_Expr
7399 ("non-static expression not allowed for " &
7400 "Default_Component_Value",
7401 Arg2);
7402 raise Pragma_Exit;
7403 end if;
7404
7405 -- Set the flag on the root type and then check for Rep_Item too
7406 -- early or too late, the latter call chains the pragma onto the
7407 -- Rep_Item chain.
7408
7409 Set_Has_Default_Component_Value (Base_Type (E));
7410 end;
7411
7412 -------------------
7413 -- Default_Value --
7414 -------------------
7415
7416 when Pragma_Default_Value => declare
7417 Arg : Node_Id;
7418 E : Entity_Id;
7419
7420 begin
7421 -- Error checks
7422
7423 GNAT_Pragma;
7424 Check_Arg_Count (2);
7425 Check_Arg_Is_Local_Name (Arg1);
7426
7427 Arg := Get_Pragma_Arg (Arg1);
7428 Analyze (Arg);
7429
7430 if Etype (Arg) = Any_Type then
7431 return;
7432 end if;
7433
7434 if not Is_Entity_Name (Arg)
7435 or else not Is_Scalar_Type (Entity (Arg))
7436 then
7437 Error_Pragma_Arg ("pragma% requires a scalar type", Arg1);
7438 end if;
7439
7440 Check_First_Subtype (Arg1);
7441
7442 E := Entity (Arg);
7443 Check_Duplicate_Pragma (E);
7444
7445 -- Check for rep item too early or too late, but skip this if
7446 -- the pragma comes from the corresponding aspect, since we do
7447 -- not need the checks, and more importantly, the pragma is on
7448 -- the rep item chain alreay, and must not be put there twice!
7449
7450 if not From_Aspect_Specification (N) then
7451 if Rep_Item_Too_Early (E, N)
7452 or else
7453 Rep_Item_Too_Late (E, N)
7454 then
7455 return;
7456 end if;
7457 end if;
7458
7459 -- Analyze the default value. Note that we must do that after
7460 -- checking for Rep_Item_Too_Late since this resolution will
7461 -- freeze the type involved.
7462
7463 Arg := Get_Pragma_Arg (Arg2);
7464 Analyze_And_Resolve (Arg, E);
7465
7466 if not Is_OK_Static_Expression (Arg) then
7467 Flag_Non_Static_Expr
7468 ("non-static expression not allowed for Default_Value",
7469 Arg2);
7470 raise Pragma_Exit;
7471 end if;
7472
7473 -- Set the flag on the root type and then check for Rep_Item too
7474 -- early or too late, the latter call chains the pragma onto the
7475 -- Rep_Item chain.
7476
7477 Set_Has_Default_Value (Base_Type (E));
7478 end;
7479
0da2c8ac
AC
7480 ---------------------
7481 -- Detect_Blocking --
7482 ---------------------
7483
7484 -- pragma Detect_Blocking;
7485
7486 when Pragma_Detect_Blocking =>
2fa9443e 7487 Ada_2005_Pragma;
0da2c8ac
AC
7488 Check_Arg_Count (0);
7489 Check_Valid_Configuration_Pragma;
7490 Detect_Blocking := True;
7491
fab2daeb
AC
7492 --------------------------
7493 -- Default_Storage_Pool --
7494 --------------------------
7495
7496 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7497
7498 when Pragma_Default_Storage_Pool =>
7499 Ada_2012_Pragma;
7500 Check_Arg_Count (1);
7501
7502 -- Default_Storage_Pool can appear as a configuration pragma, or
7503 -- in a declarative part or a package spec.
7504
7505 if not Is_Configuration_Pragma then
7506 Check_Is_In_Decl_Part_Or_Package_Spec;
7507 end if;
7508
7509 -- Case of Default_Storage_Pool (null);
7510
7511 if Nkind (Expression (Arg1)) = N_Null then
7512 Analyze (Expression (Arg1));
e606088a
AC
7513
7514 -- This is an odd case, this is not really an expression, so
7515 -- we don't have a type for it. So just set the type to Empty.
7516
fab2daeb 7517 Set_Etype (Expression (Arg1), Empty);
fab2daeb
AC
7518
7519 -- Case of Default_Storage_Pool (storage_pool_NAME);
7520
7521 else
7522 -- If it's a configuration pragma, then the only allowed
7523 -- argument is "null".
7524
7525 if Is_Configuration_Pragma then
7526 Error_Pragma_Arg ("NULL expected", Arg1);
7527 end if;
7528
7529 -- The expected type for a non-"null" argument is
7530 -- Root_Storage_Pool'Class.
7531
7532 Analyze_And_Resolve
7533 (Get_Pragma_Arg (Arg1),
7534 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7535 end if;
7536
7537 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7538 -- for an access type will use this information to set the
7539 -- appropriate attributes of the access type.
7540
7541 Default_Pool := Expression (Arg1);
7542
95cb33a5
AC
7543 ---------------
7544 -- Dimension --
7545 ---------------
7546
7547 when Pragma_Dimension =>
7548 GNAT_Pragma;
7549 Check_Arg_Count (4);
7550 Check_No_Identifiers;
7551 Check_Arg_Is_Local_Name (Arg1);
7552
7553 if not Is_Type (Arg1) then
7554 Error_Pragma ("first argument for pragma% must be subtype");
7555 end if;
7556
7557 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7558 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7559 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7560
996ae0b0
RK
7561 -------------------
7562 -- Discard_Names --
7563 -------------------
7564
7565 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7566
7567 when Pragma_Discard_Names => Discard_Names : declare
996ae0b0 7568 E : Entity_Id;
4351c21b 7569 E_Id : Entity_Id;
996ae0b0
RK
7570
7571 begin
996ae0b0
RK
7572 Check_Ada_83_Warning;
7573
7574 -- Deal with configuration pragma case
7575
7576 if Arg_Count = 0 and then Is_Configuration_Pragma then
7577 Global_Discard_Names := True;
7578 return;
7579
7580 -- Otherwise, check correct appropriate context
7581
7582 else
7583 Check_Is_In_Decl_Part_Or_Package_Spec;
7584
7585 if Arg_Count = 0 then
7586
7587 -- If there is no parameter, then from now on this pragma
7588 -- applies to any enumeration, exception or tagged type
2fa9443e
ES
7589 -- defined in the current declarative part, and recursively
7590 -- to any nested scope.
996ae0b0 7591
eaba57fb 7592 Set_Discard_Names (Current_Scope);
996ae0b0
RK
7593 return;
7594
7595 else
7596 Check_Arg_Count (1);
7597 Check_Optional_Identifier (Arg1, Name_On);
7598 Check_Arg_Is_Local_Name (Arg1);
4351c21b 7599
0f1a6a0b 7600 E_Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
7601
7602 if Etype (E_Id) = Any_Type then
7603 return;
7604 else
7605 E := Entity (E_Id);
7606 end if;
7607
7608 if (Is_First_Subtype (E)
4351c21b
AC
7609 and then
7610 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
996ae0b0
RK
7611 or else Ekind (E) = E_Exception
7612 then
eaba57fb 7613 Set_Discard_Names (E);
996ae0b0
RK
7614 else
7615 Error_Pragma_Arg
7616 ("inappropriate entity for pragma%", Arg1);
7617 end if;
4351c21b 7618
996ae0b0
RK
7619 end if;
7620 end if;
7621 end Discard_Names;
7622
7623 ---------------
7624 -- Elaborate --
7625 ---------------
7626
7627 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7628
7629 when Pragma_Elaborate => Elaborate : declare
ac9e9918
RD
7630 Arg : Node_Id;
7631 Citem : Node_Id;
996ae0b0
RK
7632
7633 begin
7634 -- Pragma must be in context items list of a compilation unit
7635
ac9e9918 7636 if not Is_In_Context_Clause then
996ae0b0 7637 Pragma_Misplaced;
996ae0b0
RK
7638 end if;
7639
7640 -- Must be at least one argument
7641
7642 if Arg_Count = 0 then
7643 Error_Pragma ("pragma% requires at least one argument");
7644 end if;
7645
7646 -- In Ada 83 mode, there can be no items following it in the
7647 -- context list except other pragmas and implicit with clauses
7648 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7649 -- placement rule does not apply.
7650
0ab80019 7651 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
996ae0b0 7652 Citem := Next (N);
996ae0b0
RK
7653 while Present (Citem) loop
7654 if Nkind (Citem) = N_Pragma
7655 or else (Nkind (Citem) = N_With_Clause
7656 and then Implicit_With (Citem))
7657 then
7658 null;
7659 else
7660 Error_Pragma
7661 ("(Ada 83) pragma% must be at end of context clause");
7662 end if;
7663
7664 Next (Citem);
7665 end loop;
7666 end if;
7667
7668 -- Finally, the arguments must all be units mentioned in a with
ac9e9918
RD
7669 -- clause in the same context clause. Note we already checked (in
7670 -- Par.Prag) that the arguments are all identifiers or selected
7671 -- components.
996ae0b0
RK
7672
7673 Arg := Arg1;
7674 Outer : while Present (Arg) loop
ac9e9918 7675 Citem := First (List_Containing (N));
996ae0b0
RK
7676 Inner : while Citem /= N loop
7677 if Nkind (Citem) = N_With_Clause
0f1a6a0b 7678 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
996ae0b0
RK
7679 then
7680 Set_Elaborate_Present (Citem, True);
0f1a6a0b 7681 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
82c80734
RD
7682
7683 -- With the pragma present, elaboration calls on
7684 -- subprograms from the named unit need no further
7685 -- checks, as long as the pragma appears in the current
7686 -- compilation unit. If the pragma appears in some unit
7687 -- in the context, there might still be a need for an
7688 -- Elaborate_All_Desirable from the current compilation
f3d57416 7689 -- to the named unit, so we keep the check enabled.
82c80734
RD
7690
7691 if In_Extended_Main_Source_Unit (N) then
7692 Set_Suppress_Elaboration_Warnings
7693 (Entity (Name (Citem)));
7694 end if;
ac9e9918 7695
996ae0b0
RK
7696 exit Inner;
7697 end if;
7698
7699 Next (Citem);
7700 end loop Inner;
7701
7702 if Citem = N then
7703 Error_Pragma_Arg
7704 ("argument of pragma% is not with'ed unit", Arg);
7705 end if;
7706
7707 Next (Arg);
7708 end loop Outer;
fbf5a39b
AC
7709
7710 -- Give a warning if operating in static mode with -gnatwl
f3d57416 7711 -- (elaboration warnings enabled) switch set.
fbf5a39b
AC
7712
7713 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7714 Error_Msg_N
7715 ("?use of pragma Elaborate may not be safe", N);
ed2233dc 7716 Error_Msg_N
fbf5a39b
AC
7717 ("?use pragma Elaborate_All instead if possible", N);
7718 end if;
996ae0b0
RK
7719 end Elaborate;
7720
7721 -------------------
7722 -- Elaborate_All --
7723 -------------------
7724
7725 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7726
7727 when Pragma_Elaborate_All => Elaborate_All : declare
ac9e9918
RD
7728 Arg : Node_Id;
7729 Citem : Node_Id;
996ae0b0
RK
7730
7731 begin
7732 Check_Ada_83_Warning;
7733
7734 -- Pragma must be in context items list of a compilation unit
7735
ac9e9918 7736 if not Is_In_Context_Clause then
996ae0b0 7737 Pragma_Misplaced;
996ae0b0
RK
7738 end if;
7739
7740 -- Must be at least one argument
7741
7742 if Arg_Count = 0 then
7743 Error_Pragma ("pragma% requires at least one argument");
7744 end if;
7745
7746 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7747 -- have to appear at the end of the context clause, but may
7748 -- appear mixed in with other items, even in Ada 83 mode.
7749
7750 -- Final check: the arguments must all be units mentioned in
7751 -- a with clause in the same context clause. Note that we
7752 -- already checked (in Par.Prag) that all the arguments are
7753 -- either identifiers or selected components.
7754
7755 Arg := Arg1;
7756 Outr : while Present (Arg) loop
ac9e9918 7757 Citem := First (List_Containing (N));
996ae0b0
RK
7758 Innr : while Citem /= N loop
7759 if Nkind (Citem) = N_With_Clause
0f1a6a0b 7760 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
996ae0b0
RK
7761 then
7762 Set_Elaborate_All_Present (Citem, True);
0f1a6a0b 7763 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
82c80734
RD
7764
7765 -- Suppress warnings and elaboration checks on the named
7766 -- unit if the pragma is in the current compilation, as
7767 -- for pragma Elaborate.
7768
7769 if In_Extended_Main_Source_Unit (N) then
7770 Set_Suppress_Elaboration_Warnings
7771 (Entity (Name (Citem)));
7772 end if;
996ae0b0
RK
7773 exit Innr;
7774 end if;
7775
7776 Next (Citem);
7777 end loop Innr;
7778
7779 if Citem = N then
fbf5a39b 7780 Set_Error_Posted (N);
996ae0b0
RK
7781 Error_Pragma_Arg
7782 ("argument of pragma% is not with'ed unit", Arg);
7783 end if;
7784
7785 Next (Arg);
7786 end loop Outr;
7787 end Elaborate_All;
7788
7789 --------------------
7790 -- Elaborate_Body --
7791 --------------------
7792
7793 -- pragma Elaborate_Body [( library_unit_NAME )];
7794
7795 when Pragma_Elaborate_Body => Elaborate_Body : declare
7796 Cunit_Node : Node_Id;
7797 Cunit_Ent : Entity_Id;
7798
7799 begin
7800 Check_Ada_83_Warning;
7801 Check_Valid_Library_Unit_Pragma;
7802
7803 if Nkind (N) = N_Null_Statement then
7804 return;
7805 end if;
7806
7807 Cunit_Node := Cunit (Current_Sem_Unit);
7808 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7809
d7ba4df4
RD
7810 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7811 N_Subprogram_Body)
996ae0b0
RK
7812 then
7813 Error_Pragma ("pragma% must refer to a spec, not a body");
7814 else
7815 Set_Body_Required (Cunit_Node, True);
f02b8bb8 7816 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
996ae0b0
RK
7817
7818 -- If we are in dynamic elaboration mode, then we suppress
7819 -- elaboration warnings for the unit, since it is definitely
7820 -- fine NOT to do dynamic checks at the first level (and such
7821 -- checks will be suppressed because no elaboration boolean
7822 -- is created for Elaborate_Body packages).
7823
7824 -- But in the static model of elaboration, Elaborate_Body is
7825 -- definitely NOT good enough to ensure elaboration safety on
7826 -- its own, since the body may WITH other units that are not
7827 -- safe from an elaboration point of view, so a client must
7828 -- still do an Elaborate_All on such units.
7829
b3b9865d
AC
7830 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7831 -- Elaborate_Body always suppressed elab warnings.
996ae0b0
RK
7832
7833 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7834 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7835 end if;
7836 end if;
7837 end Elaborate_Body;
7838
7839 ------------------------
7840 -- Elaboration_Checks --
7841 ------------------------
7842
7843 -- pragma Elaboration_Checks (Static | Dynamic);
7844
7845 when Pragma_Elaboration_Checks =>
7846 GNAT_Pragma;
7847 Check_Arg_Count (1);
7848 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7849 Dynamic_Elaboration_Checks :=
7850 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7851
7852 ---------------
7853 -- Eliminate --
7854 ---------------
7855
7856 -- pragma Eliminate (
ef7c5692
AC
7857 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7858 -- [,[Entity =>] IDENTIFIER |
7859 -- SELECTED_COMPONENT |
7860 -- STRING_LITERAL]
7861 -- [, OVERLOADING_RESOLUTION]);
7324bf49
AC
7862
7863 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7864 -- SOURCE_LOCATION
7865
7866 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7867 -- FUNCTION_PROFILE
7868
7869 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7870
7871 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7872 -- Result_Type => result_SUBTYPE_NAME]
996ae0b0 7873
07fc65c4
GB
7874 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7875 -- SUBTYPE_NAME ::= STRING_LITERAL
996ae0b0 7876
7324bf49
AC
7877 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7878 -- SOURCE_TRACE ::= STRING_LITERAL
7879
07fc65c4
GB
7880 when Pragma_Eliminate => Eliminate : declare
7881 Args : Args_List (1 .. 5);
fbf5a39b 7882 Names : constant Name_List (1 .. 5) := (
07fc65c4
GB
7883 Name_Unit_Name,
7884 Name_Entity,
7885 Name_Parameter_Types,
7886 Name_Result_Type,
7324bf49 7887 Name_Source_Location);
07fc65c4
GB
7888
7889 Unit_Name : Node_Id renames Args (1);
7890 Entity : Node_Id renames Args (2);
7891 Parameter_Types : Node_Id renames Args (3);
7892 Result_Type : Node_Id renames Args (4);
7324bf49 7893 Source_Location : Node_Id renames Args (5);
07fc65c4
GB
7894
7895 begin
996ae0b0 7896 GNAT_Pragma;
996ae0b0 7897 Check_Valid_Configuration_Pragma;
07fc65c4 7898 Gather_Associations (Names, Args);
996ae0b0 7899
07fc65c4
GB
7900 if No (Unit_Name) then
7901 Error_Pragma ("missing Unit_Name argument for pragma%");
7902 end if;
996ae0b0 7903
07fc65c4
GB
7904 if No (Entity)
7905 and then (Present (Parameter_Types)
7906 or else
7907 Present (Result_Type)
7908 or else
7324bf49 7909 Present (Source_Location))
07fc65c4
GB
7910 then
7911 Error_Pragma ("missing Entity argument for pragma%");
996ae0b0
RK
7912 end if;
7913
7324bf49
AC
7914 if (Present (Parameter_Types)
7915 or else
7916 Present (Result_Type))
7917 and then
7918 Present (Source_Location)
7919 then
7920 Error_Pragma
f02b8bb8 7921 ("parameter profile and source location cannot " &
7324bf49
AC
7922 "be used together in pragma%");
7923 end if;
7924
07fc65c4 7925 Process_Eliminate_Pragma
91b1417d
AC
7926 (N,
7927 Unit_Name,
07fc65c4
GB
7928 Entity,
7929 Parameter_Types,
7930 Result_Type,
7324bf49 7931 Source_Location);
996ae0b0
RK
7932 end Eliminate;
7933
7934 ------------
7935 -- Export --
7936 ------------
7937
7938 -- pragma Export (
7939 -- [ Convention =>] convention_IDENTIFIER,
7940 -- [ Entity =>] local_NAME
7941 -- [, [External_Name =>] static_string_EXPRESSION ]
7942 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7943
7944 when Pragma_Export => Export : declare
7945 C : Convention_Id;
7946 Def_Id : Entity_Id;
7947
67ce0d7e
RD
7948 pragma Warnings (Off, C);
7949
996ae0b0
RK
7950 begin
7951 Check_Ada_83_Warning;
59e5fbe0
RD
7952 Check_Arg_Order
7953 ((Name_Convention,
7954 Name_Entity,
7955 Name_External_Name,
7956 Name_Link_Name));
996ae0b0
RK
7957 Check_At_Least_N_Arguments (2);
7958 Check_At_Most_N_Arguments (4);
7959 Process_Convention (C, Def_Id);
662e57b4
ES
7960
7961 if Ekind (Def_Id) /= E_Constant then
0f1a6a0b
AC
7962 Note_Possible_Modification
7963 (Get_Pragma_Arg (Arg2), Sure => False);
662e57b4
ES
7964 end if;
7965
996ae0b0
RK
7966 Process_Interface_Name (Def_Id, Arg3, Arg4);
7967 Set_Exported (Def_Id, Arg2);
21d27997 7968
b3b9865d
AC
7969 -- If the entity is a deferred constant, propagate the information
7970 -- to the full view, because gigi elaborates the full view only.
21d27997
RD
7971
7972 if Ekind (Def_Id) = E_Constant
7973 and then Present (Full_View (Def_Id))
7974 then
7975 declare
7976 Id2 : constant Entity_Id := Full_View (Def_Id);
7977 begin
7978 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7979 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7980 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7981 end;
7982 end if;
996ae0b0
RK
7983 end Export;
7984
7985 ----------------------
7986 -- Export_Exception --
7987 ----------------------
7988
7989 -- pragma Export_Exception (
470cd9e9
RD
7990 -- [Internal =>] LOCAL_NAME
7991 -- [, [External =>] EXTERNAL_SYMBOL]
996ae0b0
RK
7992 -- [, [Form =>] Ada | VMS]
7993 -- [, [Code =>] static_integer_EXPRESSION]);
7994
7995 when Pragma_Export_Exception => Export_Exception : declare
7996 Args : Args_List (1 .. 4);
fbf5a39b 7997 Names : constant Name_List (1 .. 4) := (
996ae0b0
RK
7998 Name_Internal,
7999 Name_External,
8000 Name_Form,
8001 Name_Code);
8002
8003 Internal : Node_Id renames Args (1);
8004 External : Node_Id renames Args (2);
8005 Form : Node_Id renames Args (3);
8006 Code : Node_Id renames Args (4);
8007
8008 begin
a30a01fe
RD
8009 GNAT_Pragma;
8010
996ae0b0
RK
8011 if Inside_A_Generic then
8012 Error_Pragma ("pragma% cannot be used for generic entities");
8013 end if;
8014
8015 Gather_Associations (Names, Args);
8016 Process_Extended_Import_Export_Exception_Pragma (
8017 Arg_Internal => Internal,
8018 Arg_External => External,
8019 Arg_Form => Form,
8020 Arg_Code => Code);
8021
8022 if not Is_VMS_Exception (Entity (Internal)) then
8023 Set_Exported (Entity (Internal), Internal);
8024 end if;
996ae0b0
RK
8025 end Export_Exception;
8026
8027 ---------------------
8028 -- Export_Function --
8029 ---------------------
8030
8031 -- pragma Export_Function (
470cd9e9
RD
8032 -- [Internal =>] LOCAL_NAME
8033 -- [, [External =>] EXTERNAL_SYMBOL]
996ae0b0 8034 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
fbf5a39b 8035 -- [, [Result_Type =>] TYPE_DESIGNATOR]
996ae0b0
RK
8036 -- [, [Mechanism =>] MECHANISM]
8037 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8038
fbf5a39b
AC
8039 -- EXTERNAL_SYMBOL ::=
8040 -- IDENTIFIER
8041 -- | static_string_EXPRESSION
8042
8043 -- PARAMETER_TYPES ::=
8044 -- null
8045 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8046
8047 -- TYPE_DESIGNATOR ::=
8048 -- subtype_NAME
8049 -- | subtype_Name ' Access
8050
8051 -- MECHANISM ::=
8052 -- MECHANISM_NAME
8053 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8054
8055 -- MECHANISM_ASSOCIATION ::=
8056 -- [formal_parameter_NAME =>] MECHANISM_NAME
8057
8058 -- MECHANISM_NAME ::=
8059 -- Value
8060 -- | Reference
8061 -- | Descriptor [([Class =>] CLASS_NAME)]
8062
8063 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8064
996ae0b0
RK
8065 when Pragma_Export_Function => Export_Function : declare
8066 Args : Args_List (1 .. 6);
fbf5a39b 8067 Names : constant Name_List (1 .. 6) := (
996ae0b0
RK
8068 Name_Internal,
8069 Name_External,
8070 Name_Parameter_Types,
8071 Name_Result_Type,
8072 Name_Mechanism,
8073 Name_Result_Mechanism);
8074
8075 Internal : Node_Id renames Args (1);
8076 External : Node_Id renames Args (2);
8077 Parameter_Types : Node_Id renames Args (3);
8078 Result_Type : Node_Id renames Args (4);
8079 Mechanism : Node_Id renames Args (5);
8080 Result_Mechanism : Node_Id renames Args (6);
8081
8082 begin
8083 GNAT_Pragma;
8084 Gather_Associations (Names, Args);
8085 Process_Extended_Import_Export_Subprogram_Pragma (
8086 Arg_Internal => Internal,
8087 Arg_External => External,
8088 Arg_Parameter_Types => Parameter_Types,
8089 Arg_Result_Type => Result_Type,
8090 Arg_Mechanism => Mechanism,
8091 Arg_Result_Mechanism => Result_Mechanism);
8092 end Export_Function;
8093
8094 -------------------
8095 -- Export_Object --
8096 -------------------
8097
8098 -- pragma Export_Object (
470cd9e9 8099 -- [Internal =>] LOCAL_NAME
996ae0b0
RK
8100 -- [, [External =>] EXTERNAL_SYMBOL]
8101 -- [, [Size =>] EXTERNAL_SYMBOL]);
8102
fbf5a39b
AC
8103 -- EXTERNAL_SYMBOL ::=
8104 -- IDENTIFIER
8105 -- | static_string_EXPRESSION
8106
8107 -- PARAMETER_TYPES ::=
8108 -- null
8109 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8110
8111 -- TYPE_DESIGNATOR ::=
8112 -- subtype_NAME
8113 -- | subtype_Name ' Access
8114
8115 -- MECHANISM ::=
8116 -- MECHANISM_NAME
8117 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8118
8119 -- MECHANISM_ASSOCIATION ::=
8120 -- [formal_parameter_NAME =>] MECHANISM_NAME
8121
8122 -- MECHANISM_NAME ::=
8123 -- Value
8124 -- | Reference
8125 -- | Descriptor [([Class =>] CLASS_NAME)]
8126
8127 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8128
8129 when Pragma_Export_Object => Export_Object : declare
996ae0b0 8130 Args : Args_List (1 .. 3);
fbf5a39b 8131 Names : constant Name_List (1 .. 3) := (
996ae0b0
RK
8132 Name_Internal,
8133 Name_External,
8134 Name_Size);
8135
8136 Internal : Node_Id renames Args (1);
8137 External : Node_Id renames Args (2);
8138 Size : Node_Id renames Args (3);
8139
8140 begin
8141 GNAT_Pragma;
8142 Gather_Associations (Names, Args);
8143 Process_Extended_Import_Export_Object_Pragma (
8144 Arg_Internal => Internal,
8145 Arg_External => External,
8146 Arg_Size => Size);
8147 end Export_Object;
8148
8149 ----------------------
8150 -- Export_Procedure --
8151 ----------------------
8152
8153 -- pragma Export_Procedure (
470cd9e9
RD
8154 -- [Internal =>] LOCAL_NAME
8155 -- [, [External =>] EXTERNAL_SYMBOL]
996ae0b0
RK
8156 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8157 -- [, [Mechanism =>] MECHANISM]);
8158
fbf5a39b
AC
8159 -- EXTERNAL_SYMBOL ::=
8160 -- IDENTIFIER
8161 -- | static_string_EXPRESSION
8162
8163 -- PARAMETER_TYPES ::=
8164 -- null
8165 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8166
8167 -- TYPE_DESIGNATOR ::=
8168 -- subtype_NAME
8169 -- | subtype_Name ' Access
8170
8171 -- MECHANISM ::=
8172 -- MECHANISM_NAME
8173 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8174
8175 -- MECHANISM_ASSOCIATION ::=
8176 -- [formal_parameter_NAME =>] MECHANISM_NAME
8177
8178 -- MECHANISM_NAME ::=
8179 -- Value
8180 -- | Reference
8181 -- | Descriptor [([Class =>] CLASS_NAME)]
8182
8183 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8184
996ae0b0
RK
8185 when Pragma_Export_Procedure => Export_Procedure : declare
8186 Args : Args_List (1 .. 4);
fbf5a39b 8187 Names : constant Name_List (1 .. 4) := (
996ae0b0
RK
8188 Name_Internal,
8189 Name_External,
8190 Name_Parameter_Types,
8191 Name_Mechanism);
8192
8193 Internal : Node_Id renames Args (1);
8194 External : Node_Id renames Args (2);
8195 Parameter_Types : Node_Id renames Args (3);
8196 Mechanism : Node_Id renames Args (4);
8197
8198 begin
8199 GNAT_Pragma;
8200 Gather_Associations (Names, Args);
8201 Process_Extended_Import_Export_Subprogram_Pragma (
8202 Arg_Internal => Internal,
8203 Arg_External => External,
8204 Arg_Parameter_Types => Parameter_Types,
8205 Arg_Mechanism => Mechanism);
8206 end Export_Procedure;
8207
fbf5a39b
AC
8208 ------------------
8209 -- Export_Value --
8210 ------------------
8211
8212 -- pragma Export_Value (
8213 -- [Value =>] static_integer_EXPRESSION,
8214 -- [Link_Name =>] static_string_EXPRESSION);
8215
8216 when Pragma_Export_Value =>
8217 GNAT_Pragma;
59e5fbe0 8218 Check_Arg_Order ((Name_Value, Name_Link_Name));
fbf5a39b
AC
8219 Check_Arg_Count (2);
8220
8221 Check_Optional_Identifier (Arg1, Name_Value);
8222 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8223
8224 Check_Optional_Identifier (Arg2, Name_Link_Name);
8225 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8226
996ae0b0
RK
8227 -----------------------------
8228 -- Export_Valued_Procedure --
8229 -----------------------------
8230
8231 -- pragma Export_Valued_Procedure (
470cd9e9 8232 -- [Internal =>] LOCAL_NAME
996ae0b0
RK
8233 -- [, [External =>] EXTERNAL_SYMBOL,]
8234 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8235 -- [, [Mechanism =>] MECHANISM]);
8236
fbf5a39b
AC
8237 -- EXTERNAL_SYMBOL ::=
8238 -- IDENTIFIER
8239 -- | static_string_EXPRESSION
8240
8241 -- PARAMETER_TYPES ::=
8242 -- null
8243 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8244
8245 -- TYPE_DESIGNATOR ::=
8246 -- subtype_NAME
8247 -- | subtype_Name ' Access
8248
8249 -- MECHANISM ::=
8250 -- MECHANISM_NAME
8251 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8252
8253 -- MECHANISM_ASSOCIATION ::=
8254 -- [formal_parameter_NAME =>] MECHANISM_NAME
8255
8256 -- MECHANISM_NAME ::=
8257 -- Value
8258 -- | Reference
8259 -- | Descriptor [([Class =>] CLASS_NAME)]
8260
8261 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8262
996ae0b0
RK
8263 when Pragma_Export_Valued_Procedure =>
8264 Export_Valued_Procedure : declare
8265 Args : Args_List (1 .. 4);
fbf5a39b 8266 Names : constant Name_List (1 .. 4) := (
996ae0b0
RK
8267 Name_Internal,
8268 Name_External,
8269 Name_Parameter_Types,
8270 Name_Mechanism);
8271
8272 Internal : Node_Id renames Args (1);
8273 External : Node_Id renames Args (2);
8274 Parameter_Types : Node_Id renames Args (3);
8275 Mechanism : Node_Id renames Args (4);
8276
8277 begin
8278 GNAT_Pragma;
8279 Gather_Associations (Names, Args);
8280 Process_Extended_Import_Export_Subprogram_Pragma (
8281 Arg_Internal => Internal,
8282 Arg_External => External,
8283 Arg_Parameter_Types => Parameter_Types,
8284 Arg_Mechanism => Mechanism);
8285 end Export_Valued_Procedure;
8286
8287 -------------------
8288 -- Extend_System --
8289 -------------------
8290
8291 -- pragma Extend_System ([Name =>] Identifier);
8292
8293 when Pragma_Extend_System => Extend_System : declare
8294 begin
8295 GNAT_Pragma;
8296 Check_Valid_Configuration_Pragma;
8297 Check_Arg_Count (1);
8298 Check_Optional_Identifier (Arg1, Name_Name);
8299 Check_Arg_Is_Identifier (Arg1);
8300
0f1a6a0b 8301 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
996ae0b0
RK
8302
8303 if Name_Len > 4
8304 and then Name_Buffer (1 .. 4) = "aux_"
8305 then
8306 if Present (System_Extend_Pragma_Arg) then
0f1a6a0b 8307 if Chars (Get_Pragma_Arg (Arg1)) =
996ae0b0
RK
8308 Chars (Expression (System_Extend_Pragma_Arg))
8309 then
8310 null;
8311 else
8312 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
c690a2ec 8313 Error_Pragma ("pragma% conflicts with that #");
996ae0b0
RK
8314 end if;
8315
8316 else
8317 System_Extend_Pragma_Arg := Arg1;
fbf5a39b
AC
8318
8319 if not GNAT_Mode then
8320 System_Extend_Unit := Arg1;
8321 end if;
996ae0b0
RK
8322 end if;
8323 else
8324 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8325 end if;
8326 end Extend_System;
8327
8328 ------------------------
8329 -- Extensions_Allowed --
8330 ------------------------
8331
8332 -- pragma Extensions_Allowed (ON | OFF);
8333
8334 when Pragma_Extensions_Allowed =>
8335 GNAT_Pragma;
8336 Check_Arg_Count (1);
8337 Check_No_Identifiers;
8338 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
0ab80019 8339
0f1a6a0b 8340 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
0ab80019 8341 Extensions_Allowed := True;
0eed45bb
AC
8342 Ada_Version := Ada_Version_Type'Last;
8343
0ab80019
AC
8344 else
8345 Extensions_Allowed := False;
0eed45bb 8346 Ada_Version := Ada_Version_Explicit;
0ab80019 8347 end if;
996ae0b0 8348
72e4357f
RD
8349 --------------
8350 -- External --
8351 --------------
8352
8353 -- pragma External (
8354 -- [ Convention =>] convention_IDENTIFIER,
8355 -- [ Entity =>] local_NAME
8356 -- [, [External_Name =>] static_string_EXPRESSION ]
8357 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8358
8359 when Pragma_External => External : declare
67ce0d7e
RD
8360 Def_Id : Entity_Id;
8361
8362 C : Convention_Id;
8363 pragma Warnings (Off, C);
8364
72e4357f
RD
8365 begin
8366 GNAT_Pragma;
59e5fbe0
RD
8367 Check_Arg_Order
8368 ((Name_Convention,
8369 Name_Entity,
8370 Name_External_Name,
8371 Name_Link_Name));
72e4357f
RD
8372 Check_At_Least_N_Arguments (2);
8373 Check_At_Most_N_Arguments (4);
8374 Process_Convention (C, Def_Id);
0f1a6a0b
AC
8375 Note_Possible_Modification
8376 (Get_Pragma_Arg (Arg2), Sure => False);
72e4357f
RD
8377 Process_Interface_Name (Def_Id, Arg3, Arg4);
8378 Set_Exported (Def_Id, Arg2);
8379 end External;
8380
996ae0b0
RK
8381 --------------------------
8382 -- External_Name_Casing --
8383 --------------------------
8384
8385 -- pragma External_Name_Casing (
8386 -- UPPERCASE | LOWERCASE
8387 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8388
2c9beb8a 8389 when Pragma_External_Name_Casing => External_Name_Casing : declare
996ae0b0
RK
8390 begin
8391 GNAT_Pragma;
8392 Check_No_Identifiers;
8393
8394 if Arg_Count = 2 then
8395 Check_Arg_Is_One_Of
8396 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8397
8398 case Chars (Get_Pragma_Arg (Arg2)) is
8399 when Name_As_Is =>
8400 Opt.External_Name_Exp_Casing := As_Is;
8401
8402 when Name_Uppercase =>
8403 Opt.External_Name_Exp_Casing := Uppercase;
8404
8405 when Name_Lowercase =>
8406 Opt.External_Name_Exp_Casing := Lowercase;
8407
8408 when others =>
8409 null;
8410 end case;
8411
8412 else
8413 Check_Arg_Count (1);
8414 end if;
8415
8416 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8417
8418 case Chars (Get_Pragma_Arg (Arg1)) is
8419 when Name_Uppercase =>
8420 Opt.External_Name_Imp_Casing := Uppercase;
8421
8422 when Name_Lowercase =>
8423 Opt.External_Name_Imp_Casing := Lowercase;
8424
8425 when others =>
8426 null;
8427 end case;
996ae0b0
RK
8428 end External_Name_Casing;
8429
470cd9e9
RD
8430 --------------------------
8431 -- Favor_Top_Level --
8432 --------------------------
8433
8434 -- pragma Favor_Top_Level (type_NAME);
8435
8436 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8437 Named_Entity : Entity_Id;
8438
8439 begin
8440 GNAT_Pragma;
8441 Check_No_Identifiers;
8442 Check_Arg_Count (1);
8443 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 8444 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
470cd9e9
RD
8445
8446 -- If it's an access-to-subprogram type (in particular, not a
8447 -- subtype), set the flag on that type.
8448
1b24ada5 8449 if Is_Access_Subprogram_Type (Named_Entity) then
eaba57fb 8450 Set_Can_Use_Internal_Rep (Named_Entity, False);
470cd9e9
RD
8451
8452 -- Otherwise it's an error (name denotes the wrong sort of entity)
8453
8454 else
8455 Error_Pragma_Arg
0f1a6a0b
AC
8456 ("access-to-subprogram type expected",
8457 Get_Pragma_Arg (Arg1));
470cd9e9
RD
8458 end if;
8459 end Favor_Top_Level;
8460
8461 ---------------
8462 -- Fast_Math --
8463 ---------------
8464
8465 -- pragma Fast_Math;
8466
8467 when Pragma_Fast_Math =>
8468 GNAT_Pragma;
8469 Check_No_Identifiers;
8470 Check_Valid_Configuration_Pragma;
8471 Fast_Math := True;
8472
996ae0b0
RK
8473 ---------------------------
8474 -- Finalize_Storage_Only --
8475 ---------------------------
8476
8477 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8478
8479 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
fbf5a39b 8480 Assoc : constant Node_Id := Arg1;
0f1a6a0b 8481 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
996ae0b0
RK
8482 Typ : Entity_Id;
8483
8484 begin
a30a01fe 8485 GNAT_Pragma;
996ae0b0
RK
8486 Check_No_Identifiers;
8487 Check_Arg_Count (1);
8488 Check_Arg_Is_Local_Name (Arg1);
8489
8490 Find_Type (Type_Id);
8491 Typ := Entity (Type_Id);
8492
8493 if Typ = Any_Type
8494 or else Rep_Item_Too_Early (Typ, N)
8495 then
8496 return;
8497 else
8498 Typ := Underlying_Type (Typ);
8499 end if;
8500
8501 if not Is_Controlled (Typ) then
8502 Error_Pragma ("pragma% must specify controlled type");
8503 end if;
8504
8505 Check_First_Subtype (Arg1);
8506
8507 if Finalize_Storage_Only (Typ) then
8508 Error_Pragma ("duplicate pragma%, only one allowed");
8509
8510 elsif not Rep_Item_Too_Late (Typ, N) then
07fc65c4 8511 Set_Finalize_Storage_Only (Base_Type (Typ), True);
996ae0b0
RK
8512 end if;
8513 end Finalize_Storage;
8514
8515 --------------------------
8516 -- Float_Representation --
8517 --------------------------
8518
6e18b0e5
RD
8519 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8520
8521 -- FLOAT_REP ::= VAX_Float | IEEE_Float
996ae0b0
RK
8522
8523 when Pragma_Float_Representation => Float_Representation : declare
8524 Argx : Node_Id;
8525 Digs : Nat;
8526 Ent : Entity_Id;
8527
8528 begin
8529 GNAT_Pragma;
8530
8531 if Arg_Count = 1 then
8532 Check_Valid_Configuration_Pragma;
8533 else
8534 Check_Arg_Count (2);
8535 Check_Optional_Identifier (Arg2, Name_Entity);
8536 Check_Arg_Is_Local_Name (Arg2);
8537 end if;
8538
8539 Check_No_Identifier (Arg1);
8540 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8541
8542 if not OpenVMS_On_Target then
0f1a6a0b 8543 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
996ae0b0
RK
8544 Error_Pragma
8545 ("?pragma% ignored (applies only to Open'V'M'S)");
8546 end if;
8547
8548 return;
8549 end if;
8550
8551 -- One argument case
8552
8553 if Arg_Count = 1 then
0f1a6a0b 8554 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
996ae0b0
RK
8555 if Opt.Float_Format = 'I' then
8556 Error_Pragma ("'I'E'E'E format previously specified");
8557 end if;
8558
8559 Opt.Float_Format := 'V';
8560
8561 else
8562 if Opt.Float_Format = 'V' then
8563 Error_Pragma ("'V'A'X format previously specified");
8564 end if;
8565
8566 Opt.Float_Format := 'I';
8567 end if;
8568
8569 Set_Standard_Fpt_Formats;
8570
8571 -- Two argument case
8572
8573 else
8574 Argx := Get_Pragma_Arg (Arg2);
8575
8576 if not Is_Entity_Name (Argx)
8577 or else not Is_Floating_Point_Type (Entity (Argx))
8578 then
8579 Error_Pragma_Arg
8580 ("second argument of% pragma must be floating-point type",
8581 Arg2);
8582 end if;
8583
8584 Ent := Entity (Argx);
8585 Digs := UI_To_Int (Digits_Value (Ent));
8586
8587 -- Two arguments, VAX_Float case
8588
0f1a6a0b 8589 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
996ae0b0
RK
8590 case Digs is
8591 when 6 => Set_F_Float (Ent);
8592 when 9 => Set_D_Float (Ent);
8593 when 15 => Set_G_Float (Ent);
8594
8595 when others =>
8596 Error_Pragma_Arg
8597 ("wrong digits value, must be 6,9 or 15", Arg2);
8598 end case;
8599
8600 -- Two arguments, IEEE_Float case
8601
8602 else
8603 case Digs is
8604 when 6 => Set_IEEE_Short (Ent);
8605 when 15 => Set_IEEE_Long (Ent);
8606
8607 when others =>
8608 Error_Pragma_Arg
8609 ("wrong digits value, must be 6 or 15", Arg2);
8610 end case;
8611 end if;
8612 end if;
996ae0b0
RK
8613 end Float_Representation;
8614
8615 -----------
8616 -- Ident --
8617 -----------
8618
8619 -- pragma Ident (static_string_EXPRESSION)
8620
b3b9865d
AC
8621 -- Note: pragma Comment shares this processing. Pragma Comment is
8622 -- identical to Ident, except that the restriction of the argument to
8623 -- 31 characters and the placement restrictions are not enforced for
8624 -- pragma Comment.
996ae0b0
RK
8625
8626 when Pragma_Ident | Pragma_Comment => Ident : declare
8627 Str : Node_Id;
8628
8629 begin
8630 GNAT_Pragma;
8631 Check_Arg_Count (1);
8632 Check_No_Identifiers;
8633 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7eaa7cdf 8634 Store_Note (N);
996ae0b0 8635
b3b9865d
AC
8636 -- For pragma Ident, preserve DEC compatibility by requiring the
8637 -- pragma to appear in a declarative part or package spec.
996ae0b0
RK
8638
8639 if Prag_Id = Pragma_Ident then
8640 Check_Is_In_Decl_Part_Or_Package_Spec;
8641 end if;
8642
0f1a6a0b 8643 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
996ae0b0 8644
996ae0b0
RK
8645 declare
8646 CS : Node_Id;
8647 GP : Node_Id;
8648
8649 begin
8650 GP := Parent (Parent (N));
8651
d7ba4df4
RD
8652 if Nkind_In (GP, N_Package_Declaration,
8653 N_Generic_Package_Declaration)
996ae0b0
RK
8654 then
8655 GP := Parent (GP);
8656 end if;
8657
b3b9865d
AC
8658 -- If we have a compilation unit, then record the ident value,
8659 -- checking for improper duplication.
996ae0b0
RK
8660
8661 if Nkind (GP) = N_Compilation_Unit then
8662 CS := Ident_String (Current_Sem_Unit);
8663
8664 if Present (CS) then
8665
8666 -- For Ident, we do not permit multiple instances
8667
8668 if Prag_Id = Pragma_Ident then
8669 Error_Pragma ("duplicate% pragma not permitted");
8670
b3b9865d
AC
8671 -- For Comment, we concatenate the string, unless we want
8672 -- to preserve the tree structure for ASIS.
996ae0b0 8673
fbf5a39b 8674 elsif not ASIS_Mode then
996ae0b0
RK
8675 Start_String (Strval (CS));
8676 Store_String_Char (' ');
8677 Store_String_Chars (Strval (Str));
8678 Set_Strval (CS, End_String);
8679 end if;
8680
8681 else
8682 -- In VMS, the effect of IDENT is achieved by passing
7425962b 8683 -- --identification=name as a --for-linker switch.
996ae0b0
RK
8684
8685 if OpenVMS_On_Target then
8686 Start_String;
8687 Store_String_Chars
7425962b 8688 ("--for-linker=--identification=");
996ae0b0
RK
8689 String_To_Name_Buffer (Strval (Str));
8690 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8691
8692 -- Only the last processed IDENT is saved. The main
8693 -- purpose is so an IDENT associated with a main
8694 -- procedure will be used in preference to an IDENT
8695 -- associated with a with'd package.
8696
8697 Replace_Linker_Option_String
7425962b 8698 (End_String, "--for-linker=--identification=");
996ae0b0
RK
8699 end if;
8700
8701 Set_Ident_String (Current_Sem_Unit, Str);
8702 end if;
8703
b3b9865d
AC
8704 -- For subunits, we just ignore the Ident, since in GNAT these
8705 -- are not separate object files, and hence not separate units
8706 -- in the unit table.
996ae0b0
RK
8707
8708 elsif Nkind (GP) = N_Subunit then
8709 null;
8710
8711 -- Otherwise we have a misplaced pragma Ident, but we ignore
8712 -- this if we are in an instantiation, since it comes from
8713 -- a generic, and has no relevance to the instantiation.
8714
8715 elsif Prag_Id = Pragma_Ident then
8716 if Instantiation_Location (Loc) = No_Location then
8717 Error_Pragma ("pragma% only allowed at outer level");
8718 end if;
8719 end if;
8720 end;
8721 end Ident;
8722
bfae1846
AC
8723 -----------------
8724 -- Implemented --
8725 -----------------
470cd9e9 8726
bfae1846
AC
8727 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8728 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
470cd9e9 8729
bfae1846
AC
8730 when Pragma_Implemented => Implemented : declare
8731 Proc_Id : Entity_Id;
8732 Typ : Entity_Id;
470cd9e9
RD
8733
8734 begin
bfae1846
AC
8735 Ada_2012_Pragma;
8736 Check_Arg_Count (2);
470cd9e9
RD
8737 Check_No_Identifiers;
8738 Check_Arg_Is_Identifier (Arg1);
8739 Check_Arg_Is_Local_Name (Arg1);
bfae1846
AC
8740 Check_Arg_Is_One_Of
8741 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8742
8743 -- Extract the name of the local procedure
470cd9e9 8744
0f1a6a0b 8745 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
470cd9e9 8746
bfae1846
AC
8747 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8748 -- primitive procedure of a synchronized tagged type.
8749
8750 if Ekind (Proc_Id) = E_Procedure
8751 and then Is_Primitive (Proc_Id)
8752 and then Present (First_Formal (Proc_Id))
470cd9e9 8753 then
bfae1846 8754 Typ := Etype (First_Formal (Proc_Id));
470cd9e9 8755
bfae1846
AC
8756 if Is_Tagged_Type (Typ)
8757 and then
8758
8759 -- Check for a protected, a synchronized or a task interface
8760
8761 ((Is_Interface (Typ)
8762 and then Is_Synchronized_Interface (Typ))
8763
8764 -- Check for a protected type or a task type that implements
8765 -- an interface.
8766
8767 or else
8768 (Is_Concurrent_Record_Type (Typ)
8769 and then Present (Interfaces (Typ)))
8770
8771 -- Check for a private record extension with keyword
8772 -- "synchronized".
8773
8774 or else
8775 (Ekind_In (Typ, E_Record_Type_With_Private,
8776 E_Record_Subtype_With_Private)
8777 and then Synchronized_Present (Parent (Typ))))
470cd9e9 8778 then
bfae1846 8779 null;
470cd9e9 8780 else
bfae1846
AC
8781 Error_Pragma_Arg
8782 ("controlling formal must be of synchronized " &
8783 "tagged type", Arg1);
8784 return;
470cd9e9 8785 end if;
bfae1846
AC
8786
8787 -- Procedures declared inside a protected type must be accepted
8788
8789 elsif Ekind (Proc_Id) = E_Procedure
8790 and then Is_Protected_Type (Scope (Proc_Id))
8791 then
8792 null;
8793
8794 -- The first argument is not a primitive procedure
8795
8796 else
8797 Error_Pragma_Arg
8798 ("pragma % must be applied to a primitive procedure", Arg1);
8799 return;
470cd9e9 8800 end if;
bfae1846 8801
2604ec03
AC
8802 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8803 -- By_Protected_Procedure to the primitive procedure of a task
8804 -- interface.
bfae1846
AC
8805
8806 if Chars (Arg2) = Name_By_Protected_Procedure
8807 and then Is_Interface (Typ)
8808 and then Is_Task_Interface (Typ)
8809 then
8810 Error_Pragma_Arg
8811 ("implementation kind By_Protected_Procedure cannot be " &
8812 "applied to a task interface primitive", Arg2);
8813 return;
8814 end if;
8815
8816 Record_Rep_Item (Proc_Id, N);
8817 end Implemented;
470cd9e9 8818
094cefda 8819 ----------------------
c690a2ec 8820 -- Implicit_Packing --
094cefda 8821 ----------------------
c690a2ec
RD
8822
8823 -- pragma Implicit_Packing;
8824
8825 when Pragma_Implicit_Packing =>
8826 GNAT_Pragma;
8827 Check_Arg_Count (0);
8828 Implicit_Packing := True;
8829
996ae0b0
RK
8830 ------------
8831 -- Import --
8832 ------------
8833
8834 -- pragma Import (
470cd9e9
RD
8835 -- [Convention =>] convention_IDENTIFIER,
8836 -- [Entity =>] local_NAME
996ae0b0
RK
8837 -- [, [External_Name =>] static_string_EXPRESSION ]
8838 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8839
8840 when Pragma_Import =>
8841 Check_Ada_83_Warning;
59e5fbe0
RD
8842 Check_Arg_Order
8843 ((Name_Convention,
8844 Name_Entity,
8845 Name_External_Name,
8846 Name_Link_Name));
996ae0b0
RK
8847 Check_At_Least_N_Arguments (2);
8848 Check_At_Most_N_Arguments (4);
8849 Process_Import_Or_Interface;
8850
8851 ----------------------
8852 -- Import_Exception --
8853 ----------------------
8854
8855 -- pragma Import_Exception (
470cd9e9
RD
8856 -- [Internal =>] LOCAL_NAME
8857 -- [, [External =>] EXTERNAL_SYMBOL]
996ae0b0
RK
8858 -- [, [Form =>] Ada | VMS]
8859 -- [, [Code =>] static_integer_EXPRESSION]);
8860
8861 when Pragma_Import_Exception => Import_Exception : declare
8862 Args : Args_List (1 .. 4);
fbf5a39b 8863 Names : constant Name_List (1 .. 4) := (
996ae0b0
RK
8864 Name_Internal,
8865 Name_External,
8866 Name_Form,
8867 Name_Code);
8868
8869 Internal : Node_Id renames Args (1);
8870 External : Node_Id renames Args (2);
8871 Form : Node_Id renames Args (3);
8872 Code : Node_Id renames Args (4);
8873
8874 begin
a30a01fe 8875 GNAT_Pragma;
996ae0b0
RK
8876 Gather_Associations (Names, Args);
8877
8878 if Present (External) and then Present (Code) then
8879 Error_Pragma
8880 ("cannot give both External and Code options for pragma%");
8881 end if;
8882
8883 Process_Extended_Import_Export_Exception_Pragma (
8884 Arg_Internal => Internal,
8885 Arg_External => External,
8886 Arg_Form => Form,
8887 Arg_Code => Code);
8888
8889 if not Is_VMS_Exception (Entity (Internal)) then
8890 Set_Imported (Entity (Internal));
8891 end if;
996ae0b0
RK
8892 end Import_Exception;
8893
8894 ---------------------
8895 -- Import_Function --
8896 ---------------------
8897
8898 -- pragma Import_Function (
8899 -- [Internal =>] LOCAL_NAME,
8900 -- [, [External =>] EXTERNAL_SYMBOL]
8901 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8902 -- [, [Result_Type =>] SUBTYPE_MARK]
8903 -- [, [Mechanism =>] MECHANISM]
8904 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8905 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8906
fbf5a39b
AC
8907 -- EXTERNAL_SYMBOL ::=
8908 -- IDENTIFIER
8909 -- | static_string_EXPRESSION
8910
8911 -- PARAMETER_TYPES ::=
8912 -- null
8913 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8914
8915 -- TYPE_DESIGNATOR ::=
8916 -- subtype_NAME
8917 -- | subtype_Name ' Access
8918
8919 -- MECHANISM ::=
8920 -- MECHANISM_NAME
8921 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8922
8923 -- MECHANISM_ASSOCIATION ::=
8924 -- [formal_parameter_NAME =>] MECHANISM_NAME
8925
8926 -- MECHANISM_NAME ::=
8927 -- Value
8928 -- | Reference
8929 -- | Descriptor [([Class =>] CLASS_NAME)]
8930
8931 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8932
996ae0b0
RK
8933 when Pragma_Import_Function => Import_Function : declare
8934 Args : Args_List (1 .. 7);
fbf5a39b 8935 Names : constant Name_List (1 .. 7) := (
996ae0b0
RK
8936 Name_Internal,
8937 Name_External,
8938 Name_Parameter_Types,
8939 Name_Result_Type,
8940 Name_Mechanism,
8941 Name_Result_Mechanism,
8942 Name_First_Optional_Parameter);
8943
8944 Internal : Node_Id renames Args (1);
8945 External : Node_Id renames Args (2);
8946 Parameter_Types : Node_Id renames Args (3);
8947 Result_Type : Node_Id renames Args (4);
8948 Mechanism : Node_Id renames Args (5);
8949 Result_Mechanism : Node_Id renames Args (6);
8950 First_Optional_Parameter : Node_Id renames Args (7);
8951
8952 begin
8953 GNAT_Pragma;
8954 Gather_Associations (Names, Args);
8955 Process_Extended_Import_Export_Subprogram_Pragma (
8956 Arg_Internal => Internal,
8957 Arg_External => External,
8958 Arg_Parameter_Types => Parameter_Types,
8959 Arg_Result_Type => Result_Type,
8960 Arg_Mechanism => Mechanism,
8961 Arg_Result_Mechanism => Result_Mechanism,
8962 Arg_First_Optional_Parameter => First_Optional_Parameter);
8963 end Import_Function;
8964
8965 -------------------
8966 -- Import_Object --
8967 -------------------
8968
8969 -- pragma Import_Object (
470cd9e9 8970 -- [Internal =>] LOCAL_NAME
996ae0b0
RK
8971 -- [, [External =>] EXTERNAL_SYMBOL]
8972 -- [, [Size =>] EXTERNAL_SYMBOL]);
8973
fbf5a39b
AC
8974 -- EXTERNAL_SYMBOL ::=
8975 -- IDENTIFIER
8976 -- | static_string_EXPRESSION
8977
996ae0b0
RK
8978 when Pragma_Import_Object => Import_Object : declare
8979 Args : Args_List (1 .. 3);
fbf5a39b 8980 Names : constant Name_List (1 .. 3) := (
996ae0b0
RK
8981 Name_Internal,
8982 Name_External,
8983 Name_Size);
8984
8985 Internal : Node_Id renames Args (1);
8986 External : Node_Id renames Args (2);
8987 Size : Node_Id renames Args (3);
8988
8989 begin
8990 GNAT_Pragma;
8991 Gather_Associations (Names, Args);
8992 Process_Extended_Import_Export_Object_Pragma (
8993 Arg_Internal => Internal,
8994 Arg_External => External,
8995 Arg_Size => Size);
8996 end Import_Object;
8997
8998 ----------------------
8999 -- Import_Procedure --
9000 ----------------------
9001
9002 -- pragma Import_Procedure (
470cd9e9 9003 -- [Internal =>] LOCAL_NAME
996ae0b0
RK
9004 -- [, [External =>] EXTERNAL_SYMBOL]
9005 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9006 -- [, [Mechanism =>] MECHANISM]
9007 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9008
fbf5a39b
AC
9009 -- EXTERNAL_SYMBOL ::=
9010 -- IDENTIFIER
9011 -- | static_string_EXPRESSION
9012
9013 -- PARAMETER_TYPES ::=
9014 -- null
9015 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9016
9017 -- TYPE_DESIGNATOR ::=
9018 -- subtype_NAME
9019 -- | subtype_Name ' Access
9020
9021 -- MECHANISM ::=
9022 -- MECHANISM_NAME
9023 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9024
9025 -- MECHANISM_ASSOCIATION ::=
9026 -- [formal_parameter_NAME =>] MECHANISM_NAME
9027
9028 -- MECHANISM_NAME ::=
9029 -- Value
9030 -- | Reference
9031 -- | Descriptor [([Class =>] CLASS_NAME)]
9032
9033 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9034
996ae0b0
RK
9035 when Pragma_Import_Procedure => Import_Procedure : declare
9036 Args : Args_List (1 .. 5);
fbf5a39b 9037 Names : constant Name_List (1 .. 5) := (
996ae0b0
RK
9038 Name_Internal,
9039 Name_External,
9040 Name_Parameter_Types,
9041 Name_Mechanism,
9042 Name_First_Optional_Parameter);
9043
9044 Internal : Node_Id renames Args (1);
9045 External : Node_Id renames Args (2);
9046 Parameter_Types : Node_Id renames Args (3);
9047 Mechanism : Node_Id renames Args (4);
9048 First_Optional_Parameter : Node_Id renames Args (5);
9049
9050 begin
9051 GNAT_Pragma;
9052 Gather_Associations (Names, Args);
9053 Process_Extended_Import_Export_Subprogram_Pragma (
9054 Arg_Internal => Internal,
9055 Arg_External => External,
9056 Arg_Parameter_Types => Parameter_Types,
9057 Arg_Mechanism => Mechanism,
9058 Arg_First_Optional_Parameter => First_Optional_Parameter);
9059 end Import_Procedure;
9060
9061 -----------------------------
9062 -- Import_Valued_Procedure --
9063 -----------------------------
9064
9065 -- pragma Import_Valued_Procedure (
470cd9e9 9066 -- [Internal =>] LOCAL_NAME
996ae0b0
RK
9067 -- [, [External =>] EXTERNAL_SYMBOL]
9068 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9069 -- [, [Mechanism =>] MECHANISM]
9070 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9071
fbf5a39b
AC
9072 -- EXTERNAL_SYMBOL ::=
9073 -- IDENTIFIER
9074 -- | static_string_EXPRESSION
9075
9076 -- PARAMETER_TYPES ::=
9077 -- null
9078 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9079
9080 -- TYPE_DESIGNATOR ::=
9081 -- subtype_NAME
9082 -- | subtype_Name ' Access
9083
9084 -- MECHANISM ::=
9085 -- MECHANISM_NAME
9086 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9087
9088 -- MECHANISM_ASSOCIATION ::=
9089 -- [formal_parameter_NAME =>] MECHANISM_NAME
9090
9091 -- MECHANISM_NAME ::=
9092 -- Value
9093 -- | Reference
9094 -- | Descriptor [([Class =>] CLASS_NAME)]
9095
9096 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9097
996ae0b0
RK
9098 when Pragma_Import_Valued_Procedure =>
9099 Import_Valued_Procedure : declare
9100 Args : Args_List (1 .. 5);
fbf5a39b 9101 Names : constant Name_List (1 .. 5) := (
996ae0b0
RK
9102 Name_Internal,
9103 Name_External,
9104 Name_Parameter_Types,
9105 Name_Mechanism,
9106 Name_First_Optional_Parameter);
9107
9108 Internal : Node_Id renames Args (1);
9109 External : Node_Id renames Args (2);
9110 Parameter_Types : Node_Id renames Args (3);
9111 Mechanism : Node_Id renames Args (4);
9112 First_Optional_Parameter : Node_Id renames Args (5);
9113
9114 begin
9115 GNAT_Pragma;
9116 Gather_Associations (Names, Args);
9117 Process_Extended_Import_Export_Subprogram_Pragma (
9118 Arg_Internal => Internal,
9119 Arg_External => External,
9120 Arg_Parameter_Types => Parameter_Types,
9121 Arg_Mechanism => Mechanism,
9122 Arg_First_Optional_Parameter => First_Optional_Parameter);
9123 end Import_Valued_Procedure;
9124
105b5e65
AC
9125 -----------------
9126 -- Independent --
9127 -----------------
9128
9129 -- pragma Independent (LOCAL_NAME);
9130
9131 when Pragma_Independent => Independent : declare
9132 E_Id : Node_Id;
9133 E : Entity_Id;
9134 D : Node_Id;
9135 K : Node_Kind;
9136
9137 begin
9138 Check_Ada_83_Warning;
9139 Ada_2012_Pragma;
9140 Check_No_Identifiers;
9141 Check_Arg_Count (1);
9142 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 9143 E_Id := Get_Pragma_Arg (Arg1);
105b5e65
AC
9144
9145 if Etype (E_Id) = Any_Type then
9146 return;
9147 end if;
9148
9149 E := Entity (E_Id);
9150 D := Declaration_Node (E);
9151 K := Nkind (D);
9152
af31bffb
AC
9153 -- Check duplicate before we chain ourselves!
9154
9155 Check_Duplicate_Pragma (E);
9156
9157 -- Check appropriate entity
9158
105b5e65
AC
9159 if Is_Type (E) then
9160 if Rep_Item_Too_Early (E, N)
9161 or else
9162 Rep_Item_Too_Late (E, N)
9163 then
9164 return;
9165 else
9166 Check_First_Subtype (Arg1);
9167 end if;
9168
9169 elsif K = N_Object_Declaration
9170 or else (K = N_Component_Declaration
9171 and then Original_Record_Component (E) = E)
9172 then
9173 if Rep_Item_Too_Late (E, N) then
9174 return;
9175 end if;
9176
9177 else
9178 Error_Pragma_Arg
9179 ("inappropriate entity for pragma%", Arg1);
9180 end if;
9181
9182 Independence_Checks.Append ((N, E));
9183 end Independent;
9184
9185 ----------------------------
9186 -- Independent_Components --
9187 ----------------------------
9188
9189 -- pragma Atomic_Components (array_LOCAL_NAME);
9190
9191 -- This processing is shared by Volatile_Components
9192
9193 when Pragma_Independent_Components => Independent_Components : declare
9194 E_Id : Node_Id;
9195 E : Entity_Id;
9196 D : Node_Id;
9197 K : Node_Kind;
9198
9199 begin
9200 Check_Ada_83_Warning;
9201 Ada_2012_Pragma;
9202 Check_No_Identifiers;
9203 Check_Arg_Count (1);
9204 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 9205 E_Id := Get_Pragma_Arg (Arg1);
105b5e65
AC
9206
9207 if Etype (E_Id) = Any_Type then
9208 return;
9209 end if;
9210
9211 E := Entity (E_Id);
9212
af31bffb
AC
9213 -- Check duplicate before we chain ourselves!
9214
9215 Check_Duplicate_Pragma (E);
9216
9217 -- Check appropriate entity
9218
105b5e65
AC
9219 if Rep_Item_Too_Early (E, N)
9220 or else
9221 Rep_Item_Too_Late (E, N)
9222 then
9223 return;
9224 end if;
9225
9226 D := Declaration_Node (E);
9227 K := Nkind (D);
9228
9229 if (K = N_Full_Type_Declaration
9230 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9231 or else
9232 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9233 and then Nkind (D) = N_Object_Declaration
9234 and then Nkind (Object_Definition (D)) =
9235 N_Constrained_Array_Definition)
9236 then
9237 Independence_Checks.Append ((N, E));
9238
9239 else
9240 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9241 end if;
9242 end Independent_Components;
9243
996ae0b0
RK
9244 ------------------------
9245 -- Initialize_Scalars --
9246 ------------------------
9247
9248 -- pragma Initialize_Scalars;
9249
9250 when Pragma_Initialize_Scalars =>
9251 GNAT_Pragma;
9252 Check_Arg_Count (0);
9253 Check_Valid_Configuration_Pragma;
fbf5a39b
AC
9254 Check_Restriction (No_Initialize_Scalars, N);
9255
5a989c6b
AC
9256 -- Initialize_Scalars creates false positives in CodePeer,
9257 -- so ignore this pragma in this mode.
9258
9259 if not Restriction_Active (No_Initialize_Scalars)
9260 and then not CodePeer_Mode
9261 then
fbf5a39b
AC
9262 Init_Or_Norm_Scalars := True;
9263 Initialize_Scalars := True;
9264 end if;
996ae0b0
RK
9265
9266 ------------
9267 -- Inline --
9268 ------------
9269
9270 -- pragma Inline ( NAME {, NAME} );
9271
9272 when Pragma_Inline =>
9273
9274 -- Pragma is active if inlining option is active
9275
c71c53a8 9276 Process_Inline (Inline_Active);
996ae0b0
RK
9277
9278 -------------------
9279 -- Inline_Always --
9280 -------------------
9281
9282 -- pragma Inline_Always ( NAME {, NAME} );
9283
9284 when Pragma_Inline_Always =>
a30a01fe 9285 GNAT_Pragma;
3c1ecd7e
AC
9286
9287 -- Pragma always active unless in CodePeer mode, since this causes
9288 -- walk order issues.
9289
9290 if not CodePeer_Mode then
9291 Process_Inline (True);
9292 end if;
996ae0b0
RK
9293
9294 --------------------
9295 -- Inline_Generic --
9296 --------------------
9297
9298 -- pragma Inline_Generic (NAME {, NAME});
9299
9300 when Pragma_Inline_Generic =>
a30a01fe 9301 GNAT_Pragma;
996ae0b0
RK
9302 Process_Generic_List;
9303
9304 ----------------------
9305 -- Inspection_Point --
9306 ----------------------
9307
9308 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9309
9310 when Pragma_Inspection_Point => Inspection_Point : declare
9311 Arg : Node_Id;
9312 Exp : Node_Id;
9313
9314 begin
9315 if Arg_Count > 0 then
9316 Arg := Arg1;
9317 loop
0f1a6a0b 9318 Exp := Get_Pragma_Arg (Arg);
996ae0b0
RK
9319 Analyze (Exp);
9320
9321 if not Is_Entity_Name (Exp)
9322 or else not Is_Object (Entity (Exp))
9323 then
9324 Error_Pragma_Arg ("object name required", Arg);
9325 end if;
9326
9327 Next (Arg);
9328 exit when No (Arg);
9329 end loop;
9330 end if;
9331 end Inspection_Point;
9332
9333 ---------------
9334 -- Interface --
9335 ---------------
9336
9337 -- pragma Interface (
ac9e9918
RD
9338 -- [ Convention =>] convention_IDENTIFIER,
9339 -- [ Entity =>] local_NAME
9340 -- [, [External_Name =>] static_string_EXPRESSION ]
9341 -- [, [Link_Name =>] static_string_EXPRESSION ]);
996ae0b0
RK
9342
9343 when Pragma_Interface =>
9344 GNAT_Pragma;
ac9e9918
RD
9345 Check_Arg_Order
9346 ((Name_Convention,
9347 Name_Entity,
9348 Name_External_Name,
9349 Name_Link_Name));
9350 Check_At_Least_N_Arguments (2);
9351 Check_At_Most_N_Arguments (4);
996ae0b0
RK
9352 Process_Import_Or_Interface;
9353
b5c739f9
RD
9354 -- In Ada 2005, the permission to use Interface (a reserved word)
9355 -- as a pragma name is considered an obsolescent feature.
9356
9357 if Ada_Version >= Ada_2005 then
9358 Check_Restriction
9359 (No_Obsolescent_Features, Pragma_Identifier (N));
9360 end if;
9361
996ae0b0
RK
9362 --------------------
9363 -- Interface_Name --
9364 --------------------
9365
9366 -- pragma Interface_Name (
9367 -- [ Entity =>] local_NAME
9368 -- [,[External_Name =>] static_string_EXPRESSION ]
9369 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9370
9371 when Pragma_Interface_Name => Interface_Name : declare
9372 Id : Node_Id;
9373 Def_Id : Entity_Id;
9374 Hom_Id : Entity_Id;
9375 Found : Boolean;
9376
9377 begin
9378 GNAT_Pragma;
59e5fbe0
RD
9379 Check_Arg_Order
9380 ((Name_Entity, Name_External_Name, Name_Link_Name));
996ae0b0
RK
9381 Check_At_Least_N_Arguments (2);
9382 Check_At_Most_N_Arguments (3);
0f1a6a0b 9383 Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
9384 Analyze (Id);
9385
9386 if not Is_Entity_Name (Id) then
9387 Error_Pragma_Arg
9388 ("first argument for pragma% must be entity name", Arg1);
9389 elsif Etype (Id) = Any_Type then
9390 return;
9391 else
9392 Def_Id := Entity (Id);
9393 end if;
9394
21d27997
RD
9395 -- Special DEC-compatible processing for the object case, forces
9396 -- object to be imported.
996ae0b0
RK
9397
9398 if Ekind (Def_Id) = E_Variable then
9399 Kill_Size_Check_Code (Def_Id);
21d27997 9400 Note_Possible_Modification (Id, Sure => False);
996ae0b0
RK
9401
9402 -- Initialization is not allowed for imported variable
9403
9404 if Present (Expression (Parent (Def_Id)))
9405 and then Comes_From_Source (Expression (Parent (Def_Id)))
9406 then
9407 Error_Msg_Sloc := Sloc (Def_Id);
9408 Error_Pragma_Arg
9409 ("no initialization allowed for declaration of& #",
9410 Arg2);
9411
9412 else
9413 -- For compatibility, support VADS usage of providing both
9414 -- pragmas Interface and Interface_Name to obtain the effect
9415 -- of a single Import pragma.
9416
9417 if Is_Imported (Def_Id)
9418 and then Present (First_Rep_Item (Def_Id))
9419 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
1b24ada5
RD
9420 and then
9421 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
996ae0b0
RK
9422 then
9423 null;
9424 else
9425 Set_Imported (Def_Id);
9426 end if;
9427
9428 Set_Is_Public (Def_Id);
9429 Process_Interface_Name (Def_Id, Arg2, Arg3);
9430 end if;
9431
9432 -- Otherwise must be subprogram
9433
9434 elsif not Is_Subprogram (Def_Id) then
9435 Error_Pragma_Arg
9436 ("argument of pragma% is not subprogram", Arg1);
9437
9438 else
9439 Check_At_Most_N_Arguments (3);
9440 Hom_Id := Def_Id;
9441 Found := False;
9442
9443 -- Loop through homonyms
9444
9445 loop
9446 Def_Id := Get_Base_Subprogram (Hom_Id);
9447
9448 if Is_Imported (Def_Id) then
9449 Process_Interface_Name (Def_Id, Arg2, Arg3);
9450 Found := True;
9451 end if;
9452
0f1a6a0b 9453 exit when From_Aspect_Specification (N);
996ae0b0
RK
9454 Hom_Id := Homonym (Hom_Id);
9455
9456 exit when No (Hom_Id)
9457 or else Scope (Hom_Id) /= Current_Scope;
9458 end loop;
9459
9460 if not Found then
9461 Error_Pragma_Arg
9462 ("argument of pragma% is not imported subprogram",
9463 Arg1);
9464 end if;
9465 end if;
9466 end Interface_Name;
9467
9468 -----------------------
9469 -- Interrupt_Handler --
9470 -----------------------
9471
9472 -- pragma Interrupt_Handler (handler_NAME);
9473
9474 when Pragma_Interrupt_Handler =>
9475 Check_Ada_83_Warning;
9476 Check_Arg_Count (1);
9477 Check_No_Identifiers;
fbf5a39b
AC
9478
9479 if No_Run_Time_Mode then
9480 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9481 else
9482 Check_Interrupt_Or_Attach_Handler;
9483 Process_Interrupt_Or_Attach_Handler;
9484 end if;
996ae0b0
RK
9485
9486 ------------------------
9487 -- Interrupt_Priority --
9488 ------------------------
9489
9490 -- pragma Interrupt_Priority [(EXPRESSION)];
9491
9492 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9493 P : constant Node_Id := Parent (N);
9494 Arg : Node_Id;
9495
9496 begin
9497 Check_Ada_83_Warning;
9498
9499 if Arg_Count /= 0 then
0f1a6a0b 9500 Arg := Get_Pragma_Arg (Arg1);
996ae0b0
RK
9501 Check_Arg_Count (1);
9502 Check_No_Identifiers;
9503
fbf5a39b
AC
9504 -- The expression must be analyzed in the special manner
9505 -- described in "Handling of Default and Per-Object
9506 -- Expressions" in sem.ads.
996ae0b0 9507
21d27997 9508 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
996ae0b0
RK
9509 end if;
9510
d7ba4df4 9511 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
996ae0b0
RK
9512 Pragma_Misplaced;
9513 return;
9514
c775c209 9515 elsif Has_Pragma_Priority (P) then
996ae0b0
RK
9516 Error_Pragma ("duplicate pragma% not allowed");
9517
9518 else
c775c209 9519 Set_Has_Pragma_Priority (P, True);
996ae0b0
RK
9520 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9521 end if;
9522 end Interrupt_Priority;
9523
fbf5a39b
AC
9524 ---------------------
9525 -- Interrupt_State --
9526 ---------------------
9527
9528 -- pragma Interrupt_State (
9529 -- [Name =>] INTERRUPT_ID,
9530 -- [State =>] INTERRUPT_STATE);
9531
9532 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9533 -- INTERRUPT_STATE => System | Runtime | User
9534
b3b9865d
AC
9535 -- Note: if the interrupt id is given as an identifier, then it must
9536 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9537 -- given as a static integer expression which must be in the range of
9538 -- Ada.Interrupts.Interrupt_ID.
fbf5a39b
AC
9539
9540 when Pragma_Interrupt_State => Interrupt_State : declare
9541
9542 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9543 -- This is the entity Ada.Interrupts.Interrupt_ID;
9544
9545 State_Type : Character;
9546 -- Set to 's'/'r'/'u' for System/Runtime/User
9547
9548 IST_Num : Pos;
9549 -- Index to entry in Interrupt_States table
9550
9551 Int_Val : Uint;
9552 -- Value of interrupt
9553
9554 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9555 -- The first argument to the pragma
9556
9557 Int_Ent : Entity_Id;
9558 -- Interrupt entity in Ada.Interrupts.Names
9559
9560 begin
9561 GNAT_Pragma;
59e5fbe0 9562 Check_Arg_Order ((Name_Name, Name_State));
fbf5a39b
AC
9563 Check_Arg_Count (2);
9564
9565 Check_Optional_Identifier (Arg1, Name_Name);
59e5fbe0 9566 Check_Optional_Identifier (Arg2, Name_State);
fbf5a39b
AC
9567 Check_Arg_Is_Identifier (Arg2);
9568
9569 -- First argument is identifier
9570
9571 if Nkind (Arg1X) = N_Identifier then
9572
9573 -- Search list of names in Ada.Interrupts.Names
9574
9575 Int_Ent := First_Entity (RTE (RE_Names));
9576 loop
9577 if No (Int_Ent) then
9578 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9579
9580 elsif Chars (Int_Ent) = Chars (Arg1X) then
9581 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9582 exit;
9583 end if;
9584
9585 Next_Entity (Int_Ent);
9586 end loop;
9587
b3b9865d
AC
9588 -- First argument is not an identifier, so it must be a static
9589 -- expression of type Ada.Interrupts.Interrupt_ID.
fbf5a39b
AC
9590
9591 else
9592 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9593 Int_Val := Expr_Value (Arg1X);
9594
9595 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9596 or else
9597 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9598 then
9599 Error_Pragma_Arg
9600 ("value not in range of type " &
9601 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9602 end if;
9603 end if;
9604
9605 -- Check OK state
9606
9607 case Chars (Get_Pragma_Arg (Arg2)) is
9608 when Name_Runtime => State_Type := 'r';
9609 when Name_System => State_Type := 's';
9610 when Name_User => State_Type := 'u';
9611
9612 when others =>
9613 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9614 end case;
9615
9616 -- Check if entry is already stored
9617
9618 IST_Num := Interrupt_States.First;
9619 loop
9620 -- If entry not found, add it
9621
9622 if IST_Num > Interrupt_States.Last then
9623 Interrupt_States.Append
9624 ((Interrupt_Number => UI_To_Int (Int_Val),
9625 Interrupt_State => State_Type,
9626 Pragma_Loc => Loc));
9627 exit;
9628
9629 -- Case of entry for the same entry
9630
9631 elsif Int_Val = Interrupt_States.Table (IST_Num).
9632 Interrupt_Number
9633 then
9634 -- If state matches, done, no need to make redundant entry
9635
9636 exit when
9637 State_Type = Interrupt_States.Table (IST_Num).
9638 Interrupt_State;
9639
9640 -- Otherwise if state does not match, error
9641
9642 Error_Msg_Sloc :=
9643 Interrupt_States.Table (IST_Num).Pragma_Loc;
9644 Error_Pragma_Arg
2fa9443e 9645 ("state conflicts with that given #", Arg2);
fbf5a39b
AC
9646 exit;
9647 end if;
9648
9649 IST_Num := IST_Num + 1;
9650 end loop;
9651 end Interrupt_State;
9652
e606088a
AC
9653 ---------------
9654 -- Invariant --
9655 ---------------
9656
9657 -- pragma Invariant
9658 -- ([Entity =>] type_LOCAL_NAME,
9659 -- [Check =>] EXPRESSION
9660 -- [,[Message =>] String_Expression]);
9661
9662 when Pragma_Invariant => Invariant : declare
9663 Type_Id : Node_Id;
9664 Typ : Entity_Id;
9665
9666 Discard : Boolean;
9667 pragma Unreferenced (Discard);
9668
9669 begin
9670 GNAT_Pragma;
9671 Check_At_Least_N_Arguments (2);
9672 Check_At_Most_N_Arguments (3);
9673 Check_Optional_Identifier (Arg1, Name_Entity);
9674 Check_Optional_Identifier (Arg2, Name_Check);
9675
9676 if Arg_Count = 3 then
9677 Check_Optional_Identifier (Arg3, Name_Message);
9678 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9679 end if;
9680
9681 Check_Arg_Is_Local_Name (Arg1);
9682
9683 Type_Id := Get_Pragma_Arg (Arg1);
9684 Find_Type (Type_Id);
9685 Typ := Entity (Type_Id);
9686
9687 if Typ = Any_Type then
9688 return;
9689
9690 elsif not Ekind_In (Typ, E_Private_Type,
9691 E_Record_Type_With_Private,
9692 E_Limited_Private_Type)
9693 then
9694 Error_Pragma_Arg
9695 ("pragma% only allowed for private type", Arg1);
9696 end if;
9697
9698 -- Note that the type has at least one invariant, and also that
9699 -- it has inheritable invariants if we have Invariant'Class.
9700
9701 Set_Has_Invariants (Typ);
9702
9703 if Class_Present (N) then
9704 Set_Has_Inheritable_Invariants (Typ);
9705 end if;
9706
9707 -- The remaining processing is simply to link the pragma on to
9708 -- the rep item chain, for processing when the type is frozen.
9709 -- This is accomplished by a call to Rep_Item_Too_Late.
9710
9711 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9712 end Invariant;
9713
996ae0b0
RK
9714 ----------------------
9715 -- Java_Constructor --
9716 ----------------------
9717
9718 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9719
c690a2ec
RD
9720 -- Also handles pragma CIL_Constructor
9721
2fa9443e
ES
9722 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9723 Java_Constructor : declare
0b89eea8
AC
9724 Convention : Convention_Id;
9725 Def_Id : Entity_Id;
9726 Hom_Id : Entity_Id;
9727 Id : Entity_Id;
9728 This_Formal : Entity_Id;
996ae0b0
RK
9729
9730 begin
9731 GNAT_Pragma;
9732 Check_Arg_Count (1);
9733 Check_Optional_Identifier (Arg1, Name_Entity);
9734 Check_Arg_Is_Local_Name (Arg1);
9735
0f1a6a0b 9736 Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
9737 Find_Program_Unit_Name (Id);
9738
9739 -- If we did not find the name, we are done
9740
9741 if Etype (Id) = Any_Type then
9742 return;
9743 end if;
9744
bcae2eaa
JM
9745 -- Check wrong use of pragma in wrong VM target
9746
9747 if VM_Target = No_VM then
9748 return;
9749
9750 elsif VM_Target = CLI_Target
9751 and then Prag_Id = Pragma_Java_Constructor
9752 then
9753 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9754
9755 elsif VM_Target = JVM_Target
9756 and then Prag_Id = Pragma_CIL_Constructor
9757 then
9758 Error_Pragma ("must use pragma 'Java_'Constructor");
9759 end if;
9760
2fa9443e
ES
9761 case Prag_Id is
9762 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9763 when Pragma_Java_Constructor => Convention := Convention_Java;
9764 when others => null;
9765 end case;
9766
996ae0b0
RK
9767 Hom_Id := Entity (Id);
9768
9769 -- Loop through homonyms
9770
9771 loop
9772 Def_Id := Get_Base_Subprogram (Hom_Id);
9773
bcae2eaa 9774 -- The constructor is required to be a function
996ae0b0 9775
bcae2eaa
JM
9776 if Ekind (Def_Id) /= E_Function then
9777 if VM_Target = JVM_Target then
2fa9443e
ES
9778 Error_Pragma_Arg
9779 ("pragma% requires function returning a " &
bcae2eaa 9780 "'Java access type", Def_Id);
2fa9443e 9781 else
2fa9443e
ES
9782 Error_Pragma_Arg
9783 ("pragma% requires function returning a " &
bcae2eaa 9784 "'C'I'L access type", Def_Id);
2fa9443e 9785 end if;
996ae0b0
RK
9786 end if;
9787
bcae2eaa
JM
9788 -- Check arguments: For tagged type the first formal must be
9789 -- named "this" and its type must be a named access type
9790 -- designating a class-wide tagged type that has convention
9791 -- CIL/Java. The first formal must also have a null default
9792 -- value. For example:
9793
9794 -- type Typ is tagged ...
9795 -- type Ref is access all Typ;
9796 -- pragma Convention (CIL, Typ);
9797
9798 -- function New_Typ (This : Ref) return Ref;
9799 -- function New_Typ (This : Ref; I : Integer) return Ref;
9800 -- pragma Cil_Constructor (New_Typ);
9801
9802 -- Reason: The first formal must NOT be a primitive of the
9803 -- tagged type.
9804
9805 -- This rule also applies to constructors of delegates used
9806 -- to interface with standard target libraries. For example:
9807
9808 -- type Delegate is access procedure ...
9809 -- pragma Import (CIL, Delegate, ...);
9810
9811 -- function new_Delegate
9812 -- (This : Delegate := null; ... ) return Delegate;
9813
9814 -- For value-types this rule does not apply.
9815
9816 if not Is_Value_Type (Etype (Def_Id)) then
9817 if No (First_Formal (Def_Id)) then
9818 Error_Msg_Name_1 := Pname;
0b89eea8
AC
9819 Error_Msg_N ("% function must have parameters", Def_Id);
9820 return;
9821 end if;
9822
9823 -- In the JRE library we have several occurrences in which
9824 -- the "this" parameter is not the first formal.
bcae2eaa 9825
0b89eea8
AC
9826 This_Formal := First_Formal (Def_Id);
9827
9828 -- In the JRE library we have several occurrences in which
9829 -- the "this" parameter is not the first formal. Search for
9830 -- it.
9831
9832 if VM_Target = JVM_Target then
9833 while Present (This_Formal)
9834 and then Get_Name_String (Chars (This_Formal)) /= "this"
9835 loop
9836 Next_Formal (This_Formal);
9837 end loop;
9838
9839 if No (This_Formal) then
9840 This_Formal := First_Formal (Def_Id);
9841 end if;
9842 end if;
9843
9844 -- Warning: The first parameter should be named "this".
9845 -- We temporarily allow it because we have the following
9846 -- case in the Java runtime (file s-osinte.ads) ???
9847
9848 -- function new_Thread
9849 -- (Self_Id : System.Address) return Thread_Id;
9850 -- pragma Java_Constructor (new_Thread);
9851
9852 if VM_Target = JVM_Target
9853 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9854 = "self_id"
9855 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
bcae2eaa 9856 then
0b89eea8
AC
9857 null;
9858
9859 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
bcae2eaa
JM
9860 Error_Msg_Name_1 := Pname;
9861 Error_Msg_N
9862 ("first formal of % function must be named `this`",
0b89eea8 9863 Parent (This_Formal));
bcae2eaa 9864
0b89eea8 9865 elsif not Is_Access_Type (Etype (This_Formal)) then
bd622b64
AC
9866 Error_Msg_Name_1 := Pname;
9867 Error_Msg_N
9868 ("first formal of % function must be an access type",
0b89eea8 9869 Parameter_Type (Parent (This_Formal)));
bd622b64
AC
9870
9871 -- For delegates the type of the first formal must be a
9872 -- named access-to-subprogram type (see previous example)
9873
9874 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
0b89eea8 9875 and then Ekind (Etype (This_Formal))
bd622b64
AC
9876 /= E_Access_Subprogram_Type
9877 then
9878 Error_Msg_Name_1 := Pname;
9879 Error_Msg_N
9880 ("first formal of % function must be a named access" &
9881 " to subprogram type",
0b89eea8 9882 Parameter_Type (Parent (This_Formal)));
bd622b64 9883
bcae2eaa
JM
9884 -- Warning: We should reject anonymous access types because
9885 -- the constructor must not be handled as a primitive of the
9886 -- tagged type. We temporarily allow it because this profile
9887 -- is currently generated by cil2ada???
9888
bd622b64 9889 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
0b89eea8
AC
9890 and then not Ekind_In (Etype (This_Formal),
9891 E_Access_Type,
9892 E_General_Access_Type,
9893 E_Anonymous_Access_Type)
bcae2eaa
JM
9894 then
9895 Error_Msg_Name_1 := Pname;
9896 Error_Msg_N
9897 ("first formal of % function must be a named access" &
9898 " type",
0b89eea8 9899 Parameter_Type (Parent (This_Formal)));
bcae2eaa
JM
9900
9901 elsif Atree.Convention
0b89eea8 9902 (Designated_Type (Etype (This_Formal))) /= Convention
bcae2eaa
JM
9903 then
9904 Error_Msg_Name_1 := Pname;
9905
9906 if Convention = Convention_Java then
9907 Error_Msg_N
9908 ("pragma% requires convention 'Cil in designated" &
9909 " type",
0b89eea8 9910 Parameter_Type (Parent (This_Formal)));
bcae2eaa
JM
9911 else
9912 Error_Msg_N
9913 ("pragma% requires convention 'Java in designated" &
9914 " type",
0b89eea8 9915 Parameter_Type (Parent (This_Formal)));
bcae2eaa
JM
9916 end if;
9917
0b89eea8
AC
9918 elsif No (Expression (Parent (This_Formal)))
9919 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
bcae2eaa
JM
9920 then
9921 Error_Msg_Name_1 := Pname;
9922 Error_Msg_N
9923 ("pragma% requires first formal with default `null`",
0b89eea8 9924 Parameter_Type (Parent (This_Formal)));
bcae2eaa
JM
9925 end if;
9926 end if;
9927
9928 -- Check result type: the constructor must be a function
9929 -- returning:
9930 -- * a value type (only allowed in the CIL compiler)
9931 -- * an access-to-subprogram type with convention Java/CIL
9932 -- * an access-type designating a type that has convention
9933 -- Java/CIL.
9934
9935 if Is_Value_Type (Etype (Def_Id)) then
9936 null;
9937
9938 -- Access-to-subprogram type with convention Java/CIL
9939
9940 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9941 if Atree.Convention (Etype (Def_Id)) /= Convention then
9942 if Convention = Convention_Java then
9943 Error_Pragma_Arg
9944 ("pragma% requires function returning a " &
9945 "'Java access type", Arg1);
9946 else
9947 pragma Assert (Convention = Convention_CIL);
9948 Error_Pragma_Arg
9949 ("pragma% requires function returning a " &
9950 "'C'I'L access type", Arg1);
9951 end if;
9952 end if;
9953
9954 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9955 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9956 E_General_Access_Type)
9957 or else
9958 Atree.Convention
9959 (Designated_Type (Etype (Def_Id))) /= Convention
9960 then
9961 Error_Msg_Name_1 := Pname;
9962
9963 if Convention = Convention_Java then
9964 Error_Pragma_Arg
9965 ("pragma% requires function returning a named" &
9966 "'Java access type", Arg1);
9967 else
9968 Error_Pragma_Arg
9969 ("pragma% requires function returning a named" &
9970 "'C'I'L access type", Arg1);
9971 end if;
9972 end if;
9973 end if;
9974
9975 Set_Is_Constructor (Def_Id);
9976 Set_Convention (Def_Id, Convention);
9977 Set_Is_Imported (Def_Id);
9978
0f1a6a0b 9979 exit when From_Aspect_Specification (N);
996ae0b0
RK
9980 Hom_Id := Homonym (Hom_Id);
9981
9982 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9983 end loop;
9984 end Java_Constructor;
9985
9986 ----------------------
9987 -- Java_Interface --
9988 ----------------------
9989
9990 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
9991
9992 when Pragma_Java_Interface => Java_Interface : declare
9993 Arg : Node_Id;
9994 Typ : Entity_Id;
9995
9996 begin
9997 GNAT_Pragma;
9998 Check_Arg_Count (1);
9999 Check_Optional_Identifier (Arg1, Name_Entity);
10000 Check_Arg_Is_Local_Name (Arg1);
10001
0f1a6a0b 10002 Arg := Get_Pragma_Arg (Arg1);
996ae0b0
RK
10003 Analyze (Arg);
10004
10005 if Etype (Arg) = Any_Type then
10006 return;
10007 end if;
10008
10009 if not Is_Entity_Name (Arg)
10010 or else not Is_Type (Entity (Arg))
10011 then
10012 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10013 end if;
10014
10015 Typ := Underlying_Type (Entity (Arg));
10016
b3b9865d
AC
10017 -- For now simply check some of the semantic constraints on the
10018 -- type. This currently leaves out some restrictions on interface
10019 -- types, namely that the parent type must be java.lang.Object.Typ
10020 -- and that all primitives of the type should be declared
10021 -- abstract. ???
996ae0b0 10022
874a0341 10023 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
996ae0b0
RK
10024 Error_Pragma_Arg ("pragma% requires an abstract "
10025 & "tagged type", Arg1);
10026
10027 elsif not Has_Discriminants (Typ)
10028 or else Ekind (Etype (First_Discriminant (Typ)))
10029 /= E_Anonymous_Access_Type
10030 or else
10031 not Is_Class_Wide_Type
10032 (Designated_Type (Etype (First_Discriminant (Typ))))
10033 then
10034 Error_Pragma_Arg
10035 ("type must have a class-wide access discriminant", Arg1);
10036 end if;
10037 end Java_Interface;
10038
fbf5a39b
AC
10039 ----------------
10040 -- Keep_Names --
10041 ----------------
10042
10043 -- pragma Keep_Names ([On => ] local_NAME);
10044
10045 when Pragma_Keep_Names => Keep_Names : declare
10046 Arg : Node_Id;
10047
10048 begin
10049 GNAT_Pragma;
10050 Check_Arg_Count (1);
10051 Check_Optional_Identifier (Arg1, Name_On);
10052 Check_Arg_Is_Local_Name (Arg1);
10053
0f1a6a0b 10054 Arg := Get_Pragma_Arg (Arg1);
fbf5a39b
AC
10055 Analyze (Arg);
10056
10057 if Etype (Arg) = Any_Type then
10058 return;
10059 end if;
10060
10061 if not Is_Entity_Name (Arg)
10062 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10063 then
10064 Error_Pragma_Arg
10065 ("pragma% requires a local enumeration type", Arg1);
10066 end if;
10067
10068 Set_Discard_Names (Entity (Arg), False);
10069 end Keep_Names;
10070
996ae0b0
RK
10071 -------------
10072 -- License --
10073 -------------
10074
59e5fbe0 10075 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
996ae0b0
RK
10076
10077 when Pragma_License =>
10078 GNAT_Pragma;
10079 Check_Arg_Count (1);
10080 Check_No_Identifiers;
10081 Check_Valid_Configuration_Pragma;
10082 Check_Arg_Is_Identifier (Arg1);
10083
10084 declare
10085 Sind : constant Source_File_Index :=
10086 Source_Index (Current_Sem_Unit);
10087
10088 begin
10089 case Chars (Get_Pragma_Arg (Arg1)) is
10090 when Name_GPL =>
10091 Set_License (Sind, GPL);
10092
10093 when Name_Modified_GPL =>
10094 Set_License (Sind, Modified_GPL);
10095
10096 when Name_Restricted =>
10097 Set_License (Sind, Restricted);
10098
10099 when Name_Unrestricted =>
10100 Set_License (Sind, Unrestricted);
10101
10102 when others =>
10103 Error_Pragma_Arg ("invalid license name", Arg1);
10104 end case;
10105 end;
10106
10107 ---------------
10108 -- Link_With --
10109 ---------------
10110
10111 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10112
10113 when Pragma_Link_With => Link_With : declare
10114 Arg : Node_Id;
10115
10116 begin
10117 GNAT_Pragma;
10118
10119 if Operating_Mode = Generate_Code
10120 and then In_Extended_Main_Source_Unit (N)
10121 then
10122 Check_At_Least_N_Arguments (1);
10123 Check_No_Identifiers;
10124 Check_Is_In_Decl_Part_Or_Package_Spec;
10125 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10126 Start_String;
10127
10128 Arg := Arg1;
10129 while Present (Arg) loop
10130 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10131
b3b9865d
AC
10132 -- Store argument, converting sequences of spaces to a
10133 -- single null character (this is one of the differences
10134 -- in processing between Link_With and Linker_Options).
996ae0b0 10135
c690a2ec 10136 Arg_Store : declare
996ae0b0
RK
10137 C : constant Char_Code := Get_Char_Code (' ');
10138 S : constant String_Id :=
0f1a6a0b 10139 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
fbf5a39b 10140 L : constant Nat := String_Length (S);
996ae0b0 10141 F : Nat := 1;
996ae0b0
RK
10142
10143 procedure Skip_Spaces;
10144 -- Advance F past any spaces
10145
c690a2ec
RD
10146 -----------------
10147 -- Skip_Spaces --
10148 -----------------
10149
996ae0b0
RK
10150 procedure Skip_Spaces is
10151 begin
10152 while F <= L and then Get_String_Char (S, F) = C loop
10153 F := F + 1;
10154 end loop;
10155 end Skip_Spaces;
10156
c690a2ec
RD
10157 -- Start of processing for Arg_Store
10158
996ae0b0
RK
10159 begin
10160 Skip_Spaces; -- skip leading spaces
10161
10162 -- Loop through characters, changing any embedded
b3b9865d
AC
10163 -- sequence of spaces to a single null character (this
10164 -- is how Link_With/Linker_Options differ)
996ae0b0
RK
10165
10166 while F <= L loop
10167 if Get_String_Char (S, F) = C then
10168 Skip_Spaces;
10169 exit when F > L;
10170 Store_String_Char (ASCII.NUL);
10171
10172 else
10173 Store_String_Char (Get_String_Char (S, F));
10174 F := F + 1;
10175 end if;
10176 end loop;
c690a2ec 10177 end Arg_Store;
996ae0b0
RK
10178
10179 Arg := Next (Arg);
10180
10181 if Present (Arg) then
10182 Store_String_Char (ASCII.NUL);
10183 end if;
10184 end loop;
10185
10186 Store_Linker_Option_String (End_String);
10187 end if;
10188 end Link_With;
10189
10190 ------------------
10191 -- Linker_Alias --
10192 ------------------
10193
10194 -- pragma Linker_Alias (
10195 -- [Entity =>] LOCAL_NAME
d9e0a587 10196 -- [Target =>] static_string_EXPRESSION);
996ae0b0
RK
10197
10198 when Pragma_Linker_Alias =>
10199 GNAT_Pragma;
d9e0a587 10200 Check_Arg_Order ((Name_Entity, Name_Target));
996ae0b0
RK
10201 Check_Arg_Count (2);
10202 Check_Optional_Identifier (Arg1, Name_Entity);
d9e0a587 10203 Check_Optional_Identifier (Arg2, Name_Target);
996ae0b0
RK
10204 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10205 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10206
10207 -- The only processing required is to link this item on to the
10208 -- list of rep items for the given entity. This is accomplished
10209 -- by the call to Rep_Item_Too_Late (when no error is detected
10210 -- and False is returned).
10211
0f1a6a0b 10212 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
996ae0b0
RK
10213 return;
10214 else
0f1a6a0b 10215 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
996ae0b0
RK
10216 end if;
10217
d9e0a587
EB
10218 ------------------------
10219 -- Linker_Constructor --
10220 ------------------------
10221
10222 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10223
10224 -- Code is shared with Linker_Destructor
10225
10226 -----------------------
10227 -- Linker_Destructor --
10228 -----------------------
10229
10230 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10231
10232 when Pragma_Linker_Constructor |
10233 Pragma_Linker_Destructor =>
10234 Linker_Constructor : declare
10235 Arg1_X : Node_Id;
10236 Proc : Entity_Id;
10237
10238 begin
10239 GNAT_Pragma;
10240 Check_Arg_Count (1);
10241 Check_No_Identifiers;
10242 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 10243 Arg1_X := Get_Pragma_Arg (Arg1);
d9e0a587
EB
10244 Analyze (Arg1_X);
10245 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10246
10247 if not Is_Library_Level_Entity (Proc) then
10248 Error_Pragma_Arg
10249 ("argument for pragma% must be library level entity", Arg1);
10250 end if;
10251
10252 -- The only processing required is to link this item on to the
10253 -- list of rep items for the given entity. This is accomplished
10254 -- by the call to Rep_Item_Too_Late (when no error is detected
10255 -- and False is returned).
10256
10257 if Rep_Item_Too_Late (Proc, N) then
10258 return;
10259 else
10260 Set_Has_Gigi_Rep_Item (Proc);
10261 end if;
10262 end Linker_Constructor;
10263
996ae0b0
RK
10264 --------------------
10265 -- Linker_Options --
10266 --------------------
10267
10268 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10269
996ae0b0
RK
10270 when Pragma_Linker_Options => Linker_Options : declare
10271 Arg : Node_Id;
10272
10273 begin
07fc65c4
GB
10274 Check_Ada_83_Warning;
10275 Check_No_Identifiers;
10276 Check_Arg_Count (1);
10277 Check_Is_In_Decl_Part_Or_Package_Spec;
21d27997 10278 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
0f1a6a0b 10279 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
21d27997
RD
10280
10281 Arg := Arg2;
10282 while Present (Arg) loop
10283 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10284 Store_String_Char (ASCII.NUL);
0f1a6a0b
AC
10285 Store_String_Chars
10286 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
21d27997
RD
10287 Arg := Next (Arg);
10288 end loop;
07fc65c4 10289
996ae0b0
RK
10290 if Operating_Mode = Generate_Code
10291 and then In_Extended_Main_Source_Unit (N)
10292 then
996ae0b0
RK
10293 Store_Linker_Option_String (End_String);
10294 end if;
10295 end Linker_Options;
10296
10297 --------------------
10298 -- Linker_Section --
10299 --------------------
10300
10301 -- pragma Linker_Section (
10302 -- [Entity =>] LOCAL_NAME
10303 -- [Section =>] static_string_EXPRESSION);
10304
10305 when Pragma_Linker_Section =>
10306 GNAT_Pragma;
59e5fbe0 10307 Check_Arg_Order ((Name_Entity, Name_Section));
996ae0b0
RK
10308 Check_Arg_Count (2);
10309 Check_Optional_Identifier (Arg1, Name_Entity);
10310 Check_Optional_Identifier (Arg2, Name_Section);
10311 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10312 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10313
2efcad9f 10314 -- This pragma applies only to objects
32f7efe1 10315
0f1a6a0b 10316 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
2efcad9f 10317 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
32f7efe1
ST
10318 end if;
10319
996ae0b0
RK
10320 -- The only processing required is to link this item on to the
10321 -- list of rep items for the given entity. This is accomplished
10322 -- by the call to Rep_Item_Too_Late (when no error is detected
10323 -- and False is returned).
10324
0f1a6a0b 10325 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
996ae0b0
RK
10326 return;
10327 else
0f1a6a0b 10328 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
996ae0b0
RK
10329 end if;
10330
10331 ----------
10332 -- List --
10333 ----------
10334
10335 -- pragma List (On | Off)
10336
b3b9865d
AC
10337 -- There is nothing to do here, since we did all the processing for
10338 -- this pragma in Par.Prag (so that it works properly even in syntax
10339 -- only mode).
996ae0b0
RK
10340
10341 when Pragma_List =>
10342 null;
10343
10344 --------------------
10345 -- Locking_Policy --
10346 --------------------
10347
10348 -- pragma Locking_Policy (policy_IDENTIFIER);
10349
10350 when Pragma_Locking_Policy => declare
10351 LP : Character;
10352
10353 begin
10354 Check_Ada_83_Warning;
10355 Check_Arg_Count (1);
10356 Check_No_Identifiers;
10357 Check_Arg_Is_Locking_Policy (Arg1);
10358 Check_Valid_Configuration_Pragma;
0f1a6a0b 10359 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
996ae0b0
RK
10360 LP := Fold_Upper (Name_Buffer (1));
10361
10362 if Locking_Policy /= ' '
10363 and then Locking_Policy /= LP
10364 then
10365 Error_Msg_Sloc := Locking_Policy_Sloc;
10366 Error_Pragma ("locking policy incompatible with policy#");
fbf5a39b 10367
b3b9865d
AC
10368 -- Set new policy, but always preserve System_Location since we
10369 -- like the error message with the run time name.
fbf5a39b 10370
996ae0b0
RK
10371 else
10372 Locking_Policy := LP;
fbf5a39b
AC
10373
10374 if Locking_Policy_Sloc /= System_Location then
10375 Locking_Policy_Sloc := Loc;
10376 end if;
996ae0b0
RK
10377 end if;
10378 end;
10379
10380 ----------------
10381 -- Long_Float --
10382 ----------------
10383
10384 -- pragma Long_Float (D_Float | G_Float);
10385
10386 when Pragma_Long_Float =>
10387 GNAT_Pragma;
10388 Check_Valid_Configuration_Pragma;
10389 Check_Arg_Count (1);
10390 Check_No_Identifier (Arg1);
10391 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10392
10393 if not OpenVMS_On_Target then
10394 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10395 end if;
10396
10397 -- D_Float case
10398
0f1a6a0b 10399 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
996ae0b0
RK
10400 if Opt.Float_Format_Long = 'G' then
10401 Error_Pragma ("G_Float previously specified");
10402 end if;
10403
10404 Opt.Float_Format_Long := 'D';
10405
10406 -- G_Float case (this is the default, does not need overriding)
10407
10408 else
10409 if Opt.Float_Format_Long = 'D' then
10410 Error_Pragma ("D_Float previously specified");
10411 end if;
10412
10413 Opt.Float_Format_Long := 'G';
10414 end if;
10415
10416 Set_Standard_Fpt_Formats;
10417
10418 -----------------------
10419 -- Machine_Attribute --
10420 -----------------------
10421
10422 -- pragma Machine_Attribute (
470cd9e9
RD
10423 -- [Entity =>] LOCAL_NAME,
10424 -- [Attribute_Name =>] static_string_EXPRESSION
d81b4c61 10425 -- [, [Info =>] static_EXPRESSION] );
996ae0b0
RK
10426
10427 when Pragma_Machine_Attribute => Machine_Attribute : declare
10428 Def_Id : Entity_Id;
10429
10430 begin
10431 GNAT_Pragma;
59e5fbe0 10432 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
996ae0b0
RK
10433
10434 if Arg_Count = 3 then
59e5fbe0 10435 Check_Optional_Identifier (Arg3, Name_Info);
d81b4c61 10436 Check_Arg_Is_Static_Expression (Arg3);
996ae0b0
RK
10437 else
10438 Check_Arg_Count (2);
10439 end if;
10440
996ae0b0 10441 Check_Optional_Identifier (Arg1, Name_Entity);
59e5fbe0
RD
10442 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10443 Check_Arg_Is_Local_Name (Arg1);
996ae0b0 10444 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
0f1a6a0b 10445 Def_Id := Entity (Get_Pragma_Arg (Arg1));
996ae0b0
RK
10446
10447 if Is_Access_Type (Def_Id) then
10448 Def_Id := Designated_Type (Def_Id);
10449 end if;
10450
10451 if Rep_Item_Too_Early (Def_Id, N) then
10452 return;
10453 end if;
10454
10455 Def_Id := Underlying_Type (Def_Id);
10456
10457 -- The only processing required is to link this item on to the
10458 -- list of rep items for the given entity. This is accomplished
10459 -- by the call to Rep_Item_Too_Late (when no error is detected
10460 -- and False is returned).
10461
10462 if Rep_Item_Too_Late (Def_Id, N) then
10463 return;
10464 else
0f1a6a0b 10465 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
996ae0b0
RK
10466 end if;
10467 end Machine_Attribute;
10468
10469 ----------
10470 -- Main --
10471 ----------
10472
c690a2ec
RD
10473 -- pragma Main
10474 -- (MAIN_OPTION [, MAIN_OPTION]);
996ae0b0 10475
c690a2ec
RD
10476 -- MAIN_OPTION ::=
10477 -- [STACK_SIZE =>] static_integer_EXPRESSION
10478 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10479 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
996ae0b0
RK
10480
10481 when Pragma_Main => Main : declare
10482 Args : Args_List (1 .. 3);
fbf5a39b 10483 Names : constant Name_List (1 .. 3) := (
996ae0b0
RK
10484 Name_Stack_Size,
10485 Name_Task_Stack_Size_Default,
10486 Name_Time_Slicing_Enabled);
10487
10488 Nod : Node_Id;
10489
10490 begin
10491 GNAT_Pragma;
10492 Gather_Associations (Names, Args);
10493
10494 for J in 1 .. 2 loop
10495 if Present (Args (J)) then
10496 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10497 end if;
10498 end loop;
10499
10500 if Present (Args (3)) then
10501 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10502 end if;
10503
10504 Nod := Next (N);
10505 while Present (Nod) loop
10506 if Nkind (Nod) = N_Pragma
1b24ada5 10507 and then Pragma_Name (Nod) = Name_Main
996ae0b0 10508 then
1b24ada5 10509 Error_Msg_Name_1 := Pname;
996ae0b0
RK
10510 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10511 end if;
10512
10513 Next (Nod);
10514 end loop;
10515 end Main;
10516
10517 ------------------
10518 -- Main_Storage --
10519 ------------------
10520
10521 -- pragma Main_Storage
10522 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10523
10524 -- MAIN_STORAGE_OPTION ::=
10525 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10526 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10527
10528 when Pragma_Main_Storage => Main_Storage : declare
10529 Args : Args_List (1 .. 2);
fbf5a39b 10530 Names : constant Name_List (1 .. 2) := (
996ae0b0
RK
10531 Name_Working_Storage,
10532 Name_Top_Guard);
10533
10534 Nod : Node_Id;
10535
10536 begin
10537 GNAT_Pragma;
10538 Gather_Associations (Names, Args);
10539
10540 for J in 1 .. 2 loop
10541 if Present (Args (J)) then
10542 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10543 end if;
10544 end loop;
10545
10546 Check_In_Main_Program;
10547
10548 Nod := Next (N);
10549 while Present (Nod) loop
10550 if Nkind (Nod) = N_Pragma
1b24ada5 10551 and then Pragma_Name (Nod) = Name_Main_Storage
996ae0b0 10552 then
1b24ada5 10553 Error_Msg_Name_1 := Pname;
996ae0b0
RK
10554 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10555 end if;
10556
10557 Next (Nod);
10558 end loop;
996ae0b0
RK
10559 end Main_Storage;
10560
10561 -----------------
10562 -- Memory_Size --
10563 -----------------
10564
10565 -- pragma Memory_Size (NUMERIC_LITERAL)
10566
10567 when Pragma_Memory_Size =>
10568 GNAT_Pragma;
10569
10570 -- Memory size is simply ignored
10571
10572 Check_No_Identifiers;
10573 Check_Arg_Count (1);
10574 Check_Arg_Is_Integer_Literal (Arg1);
10575
2fa9443e
ES
10576 -------------
10577 -- No_Body --
10578 -------------
10579
10580 -- pragma No_Body;
10581
10582 -- The only correct use of this pragma is on its own in a file, in
10583 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10584 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10585 -- check for a file containing nothing but a No_Body pragma). If we
10586 -- attempt to process it during normal semantics processing, it means
10587 -- it was misplaced.
10588
10589 when Pragma_No_Body =>
a30a01fe 10590 GNAT_Pragma;
21d27997 10591 Pragma_Misplaced;
2fa9443e 10592
996ae0b0
RK
10593 ---------------
10594 -- No_Return --
10595 ---------------
10596
57193e09 10597 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
996ae0b0 10598
fbf5a39b 10599 when Pragma_No_Return => No_Return : declare
996ae0b0
RK
10600 Id : Node_Id;
10601 E : Entity_Id;
10602 Found : Boolean;
57193e09 10603 Arg : Node_Id;
996ae0b0
RK
10604
10605 begin
1c5c721a 10606 Ada_2005_Pragma;
57193e09 10607 Check_At_Least_N_Arguments (1);
996ae0b0 10608
57193e09 10609 -- Loop through arguments of pragma
996ae0b0 10610
57193e09
TQ
10611 Arg := Arg1;
10612 while Present (Arg) loop
10613 Check_Arg_Is_Local_Name (Arg);
0f1a6a0b 10614 Id := Get_Pragma_Arg (Arg);
57193e09 10615 Analyze (Id);
996ae0b0 10616
57193e09
TQ
10617 if not Is_Entity_Name (Id) then
10618 Error_Pragma_Arg ("entity name required", Arg);
10619 end if;
996ae0b0 10620
57193e09
TQ
10621 if Etype (Id) = Any_Type then
10622 raise Pragma_Exit;
996ae0b0
RK
10623 end if;
10624
57193e09 10625 -- Loop to find matching procedures
996ae0b0 10626
57193e09
TQ
10627 E := Entity (Id);
10628 Found := False;
10629 while Present (E)
10630 and then Scope (E) = Current_Scope
10631 loop
8a95f4e8 10632 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
57193e09 10633 Set_No_Return (E);
470cd9e9
RD
10634
10635 -- Set flag on any alias as well
10636
10637 if Is_Overloadable (E) and then Present (Alias (E)) then
10638 Set_No_Return (Alias (E));
10639 end if;
10640
57193e09
TQ
10641 Found := True;
10642 end if;
10643
0f1a6a0b 10644 exit when From_Aspect_Specification (N);
57193e09
TQ
10645 E := Homonym (E);
10646 end loop;
10647
10648 if not Found then
10649 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10650 end if;
10651
10652 Next (Arg);
10653 end loop;
fbf5a39b
AC
10654 end No_Return;
10655
a30a01fe
RD
10656 -----------------
10657 -- No_Run_Time --
10658 -----------------
10659
10660 -- pragma No_Run_Time;
10661
b3b9865d
AC
10662 -- Note: this pragma is retained for backwards compatibility. See
10663 -- body of Rtsfind for full details on its handling.
a30a01fe
RD
10664
10665 when Pragma_No_Run_Time =>
10666 GNAT_Pragma;
10667 Check_Valid_Configuration_Pragma;
10668 Check_Arg_Count (0);
10669
10670 No_Run_Time_Mode := True;
10671 Configurable_Run_Time_Mode := True;
10672
10673 -- Set Duration to 32 bits if word size is 32
10674
10675 if Ttypes.System_Word_Size = 32 then
10676 Duration_32_Bits_On_Target := True;
10677 end if;
10678
10679 -- Set appropriate restrictions
10680
10681 Set_Restriction (No_Finalization, N);
10682 Set_Restriction (No_Exception_Handlers, N);
10683 Set_Restriction (Max_Tasks, N, 0);
10684 Set_Restriction (No_Tasking, N);
10685
8a6a52dc
AC
10686 ------------------------
10687 -- No_Strict_Aliasing --
10688 ------------------------
10689
6e18b0e5
RD
10690 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10691
a30a01fe 10692 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
8a6a52dc
AC
10693 E_Id : Entity_Id;
10694
10695 begin
10696 GNAT_Pragma;
10697 Check_At_Most_N_Arguments (1);
10698
10699 if Arg_Count = 0 then
10700 Check_Valid_Configuration_Pragma;
10701 Opt.No_Strict_Aliasing := True;
10702
10703 else
10704 Check_Optional_Identifier (Arg2, Name_Entity);
10705 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 10706 E_Id := Entity (Get_Pragma_Arg (Arg1));
8a6a52dc
AC
10707
10708 if E_Id = Any_Type then
10709 return;
10710 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10711 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10712 end if;
10713
e6f69614 10714 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
8a6a52dc 10715 end if;
a30a01fe
RD
10716 end No_Strict_Aliasing;
10717
10718 -----------------------
10719 -- Normalize_Scalars --
10720 -----------------------
10721
10722 -- pragma Normalize_Scalars;
10723
10724 when Pragma_Normalize_Scalars =>
10725 Check_Ada_83_Warning;
10726 Check_Arg_Count (0);
10727 Check_Valid_Configuration_Pragma;
5a989c6b 10728
09494c32
AC
10729 -- Normalize_Scalars creates false positives in CodePeer, so
10730 -- ignore this pragma in this mode.
5a989c6b
AC
10731
10732 if not CodePeer_Mode then
10733 Normalize_Scalars := True;
10734 Init_Or_Norm_Scalars := True;
10735 end if;
8a6a52dc 10736
fbf5a39b
AC
10737 -----------------
10738 -- Obsolescent --
10739 -----------------
10740
ed57136d
AC
10741 -- pragma Obsolescent;
10742
10743 -- pragma Obsolescent (
10744 -- [Message =>] static_string_EXPRESSION
10745 -- [,[Version =>] Ada_05]]);
10746
10747 -- pragma Obsolescent (
10748 -- [Entity =>] NAME
10749 -- [,[Message =>] static_string_EXPRESSION
10750 -- [,[Version =>] Ada_05]] );
fbf5a39b
AC
10751
10752 when Pragma_Obsolescent => Obsolescent : declare
ac9e9918
RD
10753 Ename : Node_Id;
10754 Decl : Node_Id;
10755
10756 procedure Set_Obsolescent (E : Entity_Id);
10757 -- Given an entity Ent, mark it as obsolescent if appropriate
82c80734 10758
ac9e9918
RD
10759 ---------------------
10760 -- Set_Obsolescent --
10761 ---------------------
f02b8bb8 10762
ac9e9918
RD
10763 procedure Set_Obsolescent (E : Entity_Id) is
10764 Active : Boolean;
10765 Ent : Entity_Id;
10766 S : String_Id;
f02b8bb8 10767
f02b8bb8 10768 begin
ac9e9918
RD
10769 Active := True;
10770 Ent := E;
10771
10772 -- Entity name was given
10773
10774 if Present (Ename) then
10775
b3b9865d
AC
10776 -- If entity name matches, we are fine. Save entity in
10777 -- pragma argument, for ASIS use.
ac9e9918
RD
10778
10779 if Chars (Ename) = Chars (Ent) then
bb83ec2f
ES
10780 Set_Entity (Ename, Ent);
10781 Generate_Reference (Ent, Ename);
ac9e9918
RD
10782
10783 -- If entity name does not match, only possibility is an
10784 -- enumeration literal from an enumeration type declaration.
10785
10786 elsif Ekind (Ent) /= E_Enumeration_Type then
10787 Error_Pragma
10788 ("pragma % entity name does not match declaration");
10789
10790 else
10791 Ent := First_Literal (E);
10792 loop
10793 if No (Ent) then
10794 Error_Pragma
10795 ("pragma % entity name does not match any " &
10796 "enumeration literal");
10797
10798 elsif Chars (Ent) = Chars (Ename) then
bb83ec2f
ES
10799 Set_Entity (Ename, Ent);
10800 Generate_Reference (Ent, Ename);
ac9e9918
RD
10801 exit;
10802
10803 else
10804 Ent := Next_Literal (Ent);
10805 end if;
10806 end loop;
10807 end if;
f02b8bb8 10808 end if;
ac9e9918
RD
10809
10810 -- Ent points to entity to be marked
10811
10812 if Arg_Count >= 1 then
10813
10814 -- Deal with static string argument
10815
10816 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
0f1a6a0b 10817 S := Strval (Get_Pragma_Arg (Arg1));
ac9e9918
RD
10818
10819 for J in 1 .. String_Length (S) loop
10820 if not In_Character_Range (Get_String_Char (S, J)) then
10821 Error_Pragma_Arg
10822 ("pragma% argument does not allow wide characters",
10823 Arg1);
10824 end if;
10825 end loop;
10826
21d27997 10827 Obsolescent_Warnings.Append
0f1a6a0b 10828 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
ac9e9918
RD
10829
10830 -- Check for Ada_05 parameter
10831
10832 if Arg_Count /= 1 then
10833 Check_Arg_Count (2);
10834
10835 declare
10836 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10837
10838 begin
10839 Check_Arg_Is_Identifier (Argx);
10840
10841 if Chars (Argx) /= Name_Ada_05 then
10842 Error_Msg_Name_2 := Name_Ada_05;
10843 Error_Pragma_Arg
10844 ("only allowed argument for pragma% is %", Argx);
10845 end if;
10846
0791fbe9 10847 if Ada_Version_Explicit < Ada_2005
ac9e9918
RD
10848 or else not Warn_On_Ada_2005_Compatibility
10849 then
10850 Active := False;
10851 end if;
10852 end;
10853 end if;
10854 end if;
10855
10856 -- Set flag if pragma active
10857
10858 if Active then
10859 Set_Is_Obsolescent (Ent);
10860 end if;
10861
10862 return;
10863 end Set_Obsolescent;
f02b8bb8
RD
10864
10865 -- Start of processing for pragma Obsolescent
10866
fbf5a39b
AC
10867 begin
10868 GNAT_Pragma;
fbf5a39b 10869
ac9e9918 10870 Check_At_Most_N_Arguments (3);
fbf5a39b 10871
ac9e9918 10872 -- See if first argument specifies an entity name
82c80734 10873
ac9e9918 10874 if Arg_Count >= 1
ed57136d
AC
10875 and then
10876 (Chars (Arg1) = Name_Entity
10877 or else
10878 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10879 N_Identifier,
10880 N_Operator_Symbol))
ac9e9918
RD
10881 then
10882 Ename := Get_Pragma_Arg (Arg1);
82c80734 10883
ac9e9918 10884 -- Eliminate first argument, so we can share processing
82c80734 10885
ac9e9918
RD
10886 Arg1 := Arg2;
10887 Arg2 := Arg3;
10888 Arg_Count := Arg_Count - 1;
82c80734 10889
ac9e9918 10890 -- No Entity name argument given
82c80734 10891
ac9e9918
RD
10892 else
10893 Ename := Empty;
59e5fbe0 10894 end if;
82c80734 10895
ef7c5692
AC
10896 if Arg_Count >= 1 then
10897 Check_Optional_Identifier (Arg1, Name_Message);
10898
10899 if Arg_Count = 2 then
10900 Check_Optional_Identifier (Arg2, Name_Version);
10901 end if;
10902 end if;
82c80734 10903
ac9e9918 10904 -- Get immediately preceding declaration
59e5fbe0 10905
ac9e9918
RD
10906 Decl := Prev (N);
10907 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10908 Prev (Decl);
10909 end loop;
59e5fbe0 10910
ac9e9918 10911 -- Cases where we do not follow anything other than another pragma
59e5fbe0 10912
ac9e9918 10913 if No (Decl) then
59e5fbe0 10914
ac9e9918
RD
10915 -- First case: library level compilation unit declaration with
10916 -- the pragma immediately following the declaration.
59e5fbe0 10917
ac9e9918
RD
10918 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10919 Set_Obsolescent
10920 (Defining_Entity (Unit (Parent (Parent (N)))));
10921 return;
82c80734 10922
ac9e9918 10923 -- Case 2: library unit placement for package
82c80734 10924
ac9e9918 10925 else
59e5fbe0 10926 declare
ac9e9918 10927 Ent : constant Entity_Id := Find_Lib_Unit_Name;
59e5fbe0 10928 begin
b9b2405f 10929 if Is_Package_Or_Generic_Package (Ent) then
ac9e9918
RD
10930 Set_Obsolescent (Ent);
10931 return;
59e5fbe0
RD
10932 end if;
10933 end;
82c80734 10934 end if;
59e5fbe0 10935
ac9e9918 10936 -- Cases where we must follow a declaration
59e5fbe0 10937
ac9e9918 10938 else
361effb1 10939 if Nkind (Decl) not in N_Declaration
ac9e9918
RD
10940 and then Nkind (Decl) not in N_Later_Decl_Item
10941 and then Nkind (Decl) not in N_Generic_Declaration
f7ca1d04 10942 and then Nkind (Decl) not in N_Renaming_Declaration
ac9e9918
RD
10943 then
10944 Error_Pragma
d7ba4df4
RD
10945 ("pragma% misplaced, "
10946 & "must immediately follow a declaration");
ac9e9918
RD
10947
10948 else
10949 Set_Obsolescent (Defining_Entity (Decl));
10950 return;
10951 end if;
59e5fbe0 10952 end if;
fbf5a39b 10953 end Obsolescent;
996ae0b0 10954
996ae0b0
RK
10955 --------------
10956 -- Optimize --
10957 --------------
10958
1b24ada5 10959 -- pragma Optimize (Time | Space | Off);
996ae0b0
RK
10960
10961 -- The actual check for optimize is done in Gigi. Note that this
10962 -- pragma does not actually change the optimization setting, it
10963 -- simply checks that it is consistent with the pragma.
10964
10965 when Pragma_Optimize =>
10966 Check_No_Identifiers;
10967 Check_Arg_Count (1);
10968 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10969
1b24ada5
RD
10970 ------------------------
10971 -- Optimize_Alignment --
10972 ------------------------
10973
10974 -- pragma Optimize_Alignment (Time | Space | Off);
10975
bd29d519 10976 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
1b24ada5
RD
10977 GNAT_Pragma;
10978 Check_No_Identifiers;
10979 Check_Arg_Count (1);
10980 Check_Valid_Configuration_Pragma;
10981
10982 declare
10983 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10984 begin
10985 case Nam is
10986 when Name_Time =>
10987 Opt.Optimize_Alignment := 'T';
10988 when Name_Space =>
10989 Opt.Optimize_Alignment := 'S';
10990 when Name_Off =>
10991 Opt.Optimize_Alignment := 'O';
10992 when others =>
10993 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10994 end case;
10995 end;
10996
21d27997
RD
10997 -- Set indication that mode is set locally. If we are in fact in a
10998 -- configuration pragma file, this setting is harmless since the
10999 -- switch will get reset anyway at the start of each unit.
11000
11001 Optimize_Alignment_Local := True;
bd29d519
AC
11002 end Optimize_Alignment;
11003
11004 -------------
11005 -- Ordered --
11006 -------------
11007
11008 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11009
11010 when Pragma_Ordered => Ordered : declare
11011 Assoc : constant Node_Id := Arg1;
11012 Type_Id : Node_Id;
11013 Typ : Entity_Id;
11014
11015 begin
11016 GNAT_Pragma;
11017 Check_No_Identifiers;
11018 Check_Arg_Count (1);
11019 Check_Arg_Is_Local_Name (Arg1);
11020
0f1a6a0b 11021 Type_Id := Get_Pragma_Arg (Assoc);
bd29d519
AC
11022 Find_Type (Type_Id);
11023 Typ := Entity (Type_Id);
11024
11025 if Typ = Any_Type then
11026 return;
11027 else
11028 Typ := Underlying_Type (Typ);
11029 end if;
11030
11031 if not Is_Enumeration_Type (Typ) then
11032 Error_Pragma ("pragma% must specify enumeration type");
11033 end if;
11034
11035 Check_First_Subtype (Arg1);
11036 Set_Has_Pragma_Ordered (Base_Type (Typ));
11037 end Ordered;
21d27997 11038
996ae0b0
RK
11039 ----------
11040 -- Pack --
11041 ----------
11042
11043 -- pragma Pack (first_subtype_LOCAL_NAME);
11044
11045 when Pragma_Pack => Pack : declare
fbf5a39b 11046 Assoc : constant Node_Id := Arg1;
996ae0b0
RK
11047 Type_Id : Node_Id;
11048 Typ : Entity_Id;
ffdb3d3b
AC
11049 Ctyp : Entity_Id;
11050 Ignore : Boolean := False;
996ae0b0
RK
11051
11052 begin
11053 Check_No_Identifiers;
11054 Check_Arg_Count (1);
11055 Check_Arg_Is_Local_Name (Arg1);
11056
0f1a6a0b 11057 Type_Id := Get_Pragma_Arg (Assoc);
996ae0b0
RK
11058 Find_Type (Type_Id);
11059 Typ := Entity (Type_Id);
11060
11061 if Typ = Any_Type
11062 or else Rep_Item_Too_Early (Typ, N)
11063 then
11064 return;
11065 else
11066 Typ := Underlying_Type (Typ);
11067 end if;
11068
11069 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11070 Error_Pragma ("pragma% must specify array or record type");
11071 end if;
11072
11073 Check_First_Subtype (Arg1);
0f1a6a0b 11074 Check_Duplicate_Pragma (Typ);
996ae0b0 11075
6e18b0e5 11076 -- Array type
996ae0b0 11077
0f1a6a0b 11078 if Is_Array_Type (Typ) then
ffdb3d3b 11079 Ctyp := Component_Type (Typ);
6e18b0e5 11080
ffdb3d3b 11081 -- Ignore pack that does nothing
6e18b0e5 11082
ffdb3d3b
AC
11083 if Known_Static_Esize (Ctyp)
11084 and then Known_Static_RM_Size (Ctyp)
11085 and then Esize (Ctyp) = RM_Size (Ctyp)
094cefda 11086 and then Addressable (Esize (Ctyp))
ffdb3d3b
AC
11087 then
11088 Ignore := True;
6e18b0e5 11089 end if;
996ae0b0 11090
094cefda
AC
11091 -- Process OK pragma Pack. Note that if there is a separate
11092 -- component clause present, the Pack will be cancelled. This
11093 -- processing is in Freeze.
6e18b0e5 11094
094cefda 11095 if not Rep_Item_Too_Late (Typ, N) then
6e18b0e5 11096
094cefda
AC
11097 -- In the context of static code analysis, we do not need
11098 -- complex front-end expansions related to pragma Pack,
11099 -- so disable handling of pragma Pack in this case.
6e18b0e5 11100
094cefda
AC
11101 if CodePeer_Mode then
11102 null;
d58b9515 11103
0f1a6a0b
AC
11104 -- Don't attempt any packing for VM targets. We possibly
11105 -- could deal with some cases of array bit-packing, but we
11106 -- don't bother, since this is not a typical kind of
11107 -- representation in the VM context anyway (and would not
11108 -- for example work nicely with the debugger).
11109
11110 elsif VM_Target /= No_VM then
11111 if not GNAT_Mode then
11112 Error_Pragma
11113 ("?pragma% ignored in this configuration");
11114 end if;
ce14c577 11115
0f1a6a0b
AC
11116 -- Normal case where we do the pack action
11117
11118 else
094cefda 11119 if not Ignore then
eaba57fb
RD
11120 Set_Is_Packed (Base_Type (Typ));
11121 Set_Has_Non_Standard_Rep (Base_Type (Typ));
094cefda 11122 end if;
ffdb3d3b 11123
eaba57fb 11124 Set_Has_Pragma_Pack (Base_Type (Typ));
6e18b0e5 11125 end if;
996ae0b0
RK
11126 end if;
11127
6e18b0e5 11128 -- For record types, the pack is always effective
996ae0b0 11129
fbf5a39b 11130 else pragma Assert (Is_Record_Type (Typ));
996ae0b0 11131 if not Rep_Item_Too_Late (Typ, N) then
540b5d9c 11132
0f1a6a0b
AC
11133 -- Ignore pack request with warning in VM mode (skip warning
11134 -- if we are compiling GNAT run time library).
11135
11136 if VM_Target /= No_VM then
11137 if not GNAT_Mode then
11138 Error_Pragma
11139 ("?pragma% ignored in this configuration");
11140 end if;
11141
11142 -- Normal case of pack request active
11143
11144 else
eaba57fb
RD
11145 Set_Is_Packed (Base_Type (Typ));
11146 Set_Has_Pragma_Pack (Base_Type (Typ));
11147 Set_Has_Non_Standard_Rep (Base_Type (Typ));
2fa9443e 11148 end if;
996ae0b0
RK
11149 end if;
11150 end if;
11151 end Pack;
11152
11153 ----------
11154 -- Page --
11155 ----------
11156
11157 -- pragma Page;
11158
b3b9865d
AC
11159 -- There is nothing to do here, since we did all the processing for
11160 -- this pragma in Par.Prag (so that it works properly even in syntax
11161 -- only mode).
996ae0b0
RK
11162
11163 when Pragma_Page =>
11164 null;
11165
11166 -------------
11167 -- Passive --
11168 -------------
11169
11170 -- pragma Passive [(PASSIVE_FORM)];
11171
2b3d67a5 11172 -- PASSIVE_FORM ::= Semaphore | No
996ae0b0
RK
11173
11174 when Pragma_Passive =>
11175 GNAT_Pragma;
11176
11177 if Nkind (Parent (N)) /= N_Task_Definition then
11178 Error_Pragma ("pragma% must be within task definition");
11179 end if;
11180
11181 if Arg_Count /= 0 then
11182 Check_Arg_Count (1);
11183 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11184 end if;
11185
ac9e9918
RD
11186 ----------------------------------
11187 -- Preelaborable_Initialization --
11188 ----------------------------------
11189
11190 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11191
11192 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11193 Ent : Entity_Id;
11194
11195 begin
2fa9443e 11196 Ada_2005_Pragma;
ac9e9918
RD
11197 Check_Arg_Count (1);
11198 Check_No_Identifiers;
11199 Check_Arg_Is_Identifier (Arg1);
11200 Check_Arg_Is_Local_Name (Arg1);
11201 Check_First_Subtype (Arg1);
0f1a6a0b 11202 Ent := Entity (Get_Pragma_Arg (Arg1));
ac9e9918 11203
c3ad80f0
TQ
11204 if not (Is_Private_Type (Ent)
11205 or else
11206 Is_Protected_Type (Ent)
11207 or else
11208 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
470cd9e9 11209 then
ac9e9918 11210 Error_Pragma_Arg
c3ad80f0
TQ
11211 ("pragma % can only be applied to private, formal derived or "
11212 & "protected type",
470cd9e9 11213 Arg1);
ac9e9918
RD
11214 end if;
11215
470cd9e9
RD
11216 -- Give an error if the pragma is applied to a protected type that
11217 -- does not qualify (due to having entries, or due to components
11218 -- that do not qualify).
11219
11220 if Is_Protected_Type (Ent)
11221 and then not Has_Preelaborable_Initialization (Ent)
11222 then
11223 Error_Msg_N
11224 ("protected type & does not have preelaborable " &
11225 "initialization", Ent);
11226
11227 -- Otherwise mark the type as definitely having preelaborable
11228 -- initialization.
11229
11230 else
11231 Set_Known_To_Have_Preelab_Init (Ent);
11232 end if;
c690a2ec
RD
11233
11234 if Has_Pragma_Preelab_Init (Ent)
11235 and then Warn_On_Redundant_Constructs
11236 then
11237 Error_Pragma ("?duplicate pragma%!");
11238 else
11239 Set_Has_Pragma_Preelab_Init (Ent);
11240 end if;
ac9e9918
RD
11241 end Preelab_Init;
11242
59e5fbe0
RD
11243 --------------------
11244 -- Persistent_BSS --
11245 --------------------
fbf5a39b 11246
2b3d67a5
AC
11247 -- pragma Persistent_BSS [(object_NAME)];
11248
59e5fbe0 11249 when Pragma_Persistent_BSS => Persistent_BSS : declare
fbf5a39b
AC
11250 Decl : Node_Id;
11251 Ent : Entity_Id;
59e5fbe0 11252 Prag : Node_Id;
fbf5a39b
AC
11253
11254 begin
11255 GNAT_Pragma;
59e5fbe0 11256 Check_At_Most_N_Arguments (1);
2e071734 11257
59e5fbe0 11258 -- Case of application to specific object (one argument)
fbf5a39b 11259
59e5fbe0
RD
11260 if Arg_Count = 1 then
11261 Check_Arg_Is_Library_Level_Local_Name (Arg1);
fbf5a39b 11262
0f1a6a0b
AC
11263 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11264 or else not
11265 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11266 E_Constant)
59e5fbe0
RD
11267 then
11268 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11269 end if;
fbf5a39b 11270
0f1a6a0b 11271 Ent := Entity (Get_Pragma_Arg (Arg1));
59e5fbe0 11272 Decl := Parent (Ent);
fbf5a39b 11273
59e5fbe0
RD
11274 if Rep_Item_Too_Late (Ent, N) then
11275 return;
11276 end if;
fbf5a39b 11277
59e5fbe0
RD
11278 if Present (Expression (Decl)) then
11279 Error_Pragma_Arg
11280 ("object for pragma% cannot have initialization", Arg1);
11281 end if;
fbf5a39b 11282
59e5fbe0
RD
11283 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11284 Error_Pragma_Arg
11285 ("object type for pragma% is not potentially persistent",
11286 Arg1);
fbf5a39b
AC
11287 end if;
11288
0f1a6a0b
AC
11289 Check_Duplicate_Pragma (Ent);
11290
eaba57fb
RD
11291 Prag :=
11292 Make_Linker_Section_Pragma
11293 (Ent, Sloc (N), ".persistent.bss");
11294 Insert_After (N, Prag);
11295 Analyze (Prag);
59e5fbe0
RD
11296
11297 -- Case of use as configuration pragma with no arguments
11298
11299 else
11300 Check_Valid_Configuration_Pragma;
11301 Persistent_BSS_Mode := True;
11302 end if;
11303 end Persistent_BSS;
fbf5a39b 11304
a30a01fe
RD
11305 -------------
11306 -- Polling --
11307 -------------
11308
11309 -- pragma Polling (ON | OFF);
11310
11311 when Pragma_Polling =>
11312 GNAT_Pragma;
11313 Check_Arg_Count (1);
11314 Check_No_Identifiers;
11315 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
0f1a6a0b 11316 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
a30a01fe 11317
21d27997
RD
11318 -------------------
11319 -- Postcondition --
11320 -------------------
11321
11322 -- pragma Postcondition ([Check =>] Boolean_Expression
11323 -- [,[Message =>] String_Expression]);
11324
11325 when Pragma_Postcondition => Postcondition : declare
11326 In_Body : Boolean;
11327 pragma Warnings (Off, In_Body);
11328
11329 begin
11330 GNAT_Pragma;
11331 Check_At_Least_N_Arguments (1);
11332 Check_At_Most_N_Arguments (2);
11333 Check_Optional_Identifier (Arg1, Name_Check);
11334
11335 -- All we need to do here is call the common check procedure,
11336 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11337
11338 Check_Precondition_Postcondition (In_Body);
11339 end Postcondition;
11340
11341 ------------------
11342 -- Precondition --
11343 ------------------
11344
11345 -- pragma Precondition ([Check =>] Boolean_Expression
11346 -- [,[Message =>] String_Expression]);
11347
11348 when Pragma_Precondition => Precondition : declare
11349 In_Body : Boolean;
11350
11351 begin
11352 GNAT_Pragma;
11353 Check_At_Least_N_Arguments (1);
11354 Check_At_Most_N_Arguments (2);
11355 Check_Optional_Identifier (Arg1, Name_Check);
21d27997
RD
11356 Check_Precondition_Postcondition (In_Body);
11357
fad0600d
AC
11358 -- If in spec, nothing more to do. If in body, then we convert the
11359 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11360 -- this whether or not precondition checks are enabled. That works
3f92c93b
AC
11361 -- fine since pragma Check will do this check, and will also
11362 -- analyze the condition itself in the proper context.
21d27997
RD
11363
11364 if In_Body then
21d27997
RD
11365 Rewrite (N,
11366 Make_Pragma (Loc,
11367 Chars => Name_Check,
11368 Pragma_Argument_Associations => New_List (
11369 Make_Pragma_Argument_Association (Loc,
7675ad4f 11370 Expression => Make_Identifier (Loc, Name_Precondition)),
21d27997
RD
11371
11372 Make_Pragma_Argument_Association (Sloc (Arg1),
11373 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11374
11375 if Arg_Count = 2 then
11376 Append_To (Pragma_Argument_Associations (N),
11377 Make_Pragma_Argument_Association (Sloc (Arg2),
11378 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11379 end if;
11380
11381 Analyze (N);
11382 end if;
11383 end Precondition;
11384
fd0ff1cf
RD
11385 ---------------
11386 -- Predicate --
11387 ---------------
11388
11389 -- pragma Predicate
47e11d08
AC
11390 -- ([Entity =>] type_LOCAL_NAME,
11391 -- [Check =>] EXPRESSION);
fd0ff1cf
RD
11392
11393 when Pragma_Predicate => Predicate : declare
11394 Type_Id : Node_Id;
11395 Typ : Entity_Id;
11396
11397 Discard : Boolean;
11398 pragma Unreferenced (Discard);
11399
11400 begin
11401 GNAT_Pragma;
4818e7b9 11402 Check_Arg_Count (2);
fd0ff1cf
RD
11403 Check_Optional_Identifier (Arg1, Name_Entity);
11404 Check_Optional_Identifier (Arg2, Name_Check);
11405
fd0ff1cf
RD
11406 Check_Arg_Is_Local_Name (Arg1);
11407
11408 Type_Id := Get_Pragma_Arg (Arg1);
11409 Find_Type (Type_Id);
11410 Typ := Entity (Type_Id);
11411
11412 if Typ = Any_Type then
11413 return;
11414 end if;
11415
11416 -- The remaining processing is simply to link the pragma on to
11417 -- the rep item chain, for processing when the type is frozen.
4818e7b9
RD
11418 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11419 -- mark the type as having predicates.
fd0ff1cf 11420
4818e7b9 11421 Set_Has_Predicates (Typ);
fd0ff1cf
RD
11422 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11423 end Predicate;
11424
996ae0b0
RK
11425 ------------------
11426 -- Preelaborate --
11427 ------------------
11428
11429 -- pragma Preelaborate [(library_unit_NAME)];
11430
11431 -- Set the flag Is_Preelaborated of program unit name entity
11432
11433 when Pragma_Preelaborate => Preelaborate : declare
fbf5a39b
AC
11434 Pa : constant Node_Id := Parent (N);
11435 Pk : constant Node_Kind := Nkind (Pa);
996ae0b0 11436 Ent : Entity_Id;
996ae0b0
RK
11437
11438 begin
11439 Check_Ada_83_Warning;
11440 Check_Valid_Library_Unit_Pragma;
11441
11442 if Nkind (N) = N_Null_Statement then
11443 return;
11444 end if;
11445
11446 Ent := Find_Lib_Unit_Name;
0f1a6a0b 11447 Check_Duplicate_Pragma (Ent);
996ae0b0
RK
11448
11449 -- This filters out pragmas inside generic parent then
11450 -- show up inside instantiation
11451
11452 if Present (Ent)
11453 and then not (Pk = N_Package_Specification
eaba57fb 11454 and then Present (Generic_Parent (Pa)))
996ae0b0
RK
11455 then
11456 if not Debug_Flag_U then
eaba57fb
RD
11457 Set_Is_Preelaborated (Ent);
11458 Set_Suppress_Elaboration_Warnings (Ent);
996ae0b0
RK
11459 end if;
11460 end if;
11461 end Preelaborate;
11462
59e5fbe0
RD
11463 ---------------------
11464 -- Preelaborate_05 --
11465 ---------------------
11466
11467 -- pragma Preelaborate_05 [(library_unit_NAME)];
11468
11469 -- This pragma is useable only in GNAT_Mode, where it is used like
11470 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11471 -- (otherwise it is ignored). This is used to implement AI-362 which
11472 -- recategorizes some run-time packages in Ada 2005 mode.
11473
11474 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11475 Ent : Entity_Id;
11476
11477 begin
11478 GNAT_Pragma;
11479 Check_Valid_Library_Unit_Pragma;
11480
11481 if not GNAT_Mode then
11482 Error_Pragma ("pragma% only available in GNAT mode");
11483 end if;
11484
11485 if Nkind (N) = N_Null_Statement then
11486 return;
11487 end if;
11488
11489 -- This is one of the few cases where we need to test the value of
11490 -- Ada_Version_Explicit rather than Ada_Version (which is always
dbe945f1 11491 -- set to Ada_2012 in a predefined unit), we need to know the
59e5fbe0
RD
11492 -- explicit version set to know if this pragma is active.
11493
0791fbe9 11494 if Ada_Version_Explicit >= Ada_2005 then
59e5fbe0
RD
11495 Ent := Find_Lib_Unit_Name;
11496 Set_Is_Preelaborated (Ent);
11497 Set_Suppress_Elaboration_Warnings (Ent);
11498 end if;
11499 end Preelaborate_05;
11500
996ae0b0
RK
11501 --------------
11502 -- Priority --
11503 --------------
11504
11505 -- pragma Priority (EXPRESSION);
11506
11507 when Pragma_Priority => Priority : declare
11508 P : constant Node_Id := Parent (N);
11509 Arg : Node_Id;
11510
11511 begin
11512 Check_No_Identifiers;
11513 Check_Arg_Count (1);
11514
996ae0b0
RK
11515 -- Subprogram case
11516
11517 if Nkind (P) = N_Subprogram_Body then
11518 Check_In_Main_Program;
11519
0f1a6a0b 11520 Arg := Get_Pragma_Arg (Arg1);
fbf5a39b
AC
11521 Analyze_And_Resolve (Arg, Standard_Integer);
11522
996ae0b0
RK
11523 -- Must be static
11524
11525 if not Is_Static_Expression (Arg) then
fbf5a39b
AC
11526 Flag_Non_Static_Expr
11527 ("main subprogram priority is not static!", Arg);
11528 raise Pragma_Exit;
996ae0b0
RK
11529
11530 -- If constraint error, then we already signalled an error
11531
11532 elsif Raises_Constraint_Error (Arg) then
11533 null;
11534
11535 -- Otherwise check in range
11536
11537 else
11538 declare
11539 Val : constant Uint := Expr_Value (Arg);
11540
11541 begin
11542 if Val < 0
11543 or else Val > Expr_Value (Expression
11544 (Parent (RTE (RE_Max_Priority))))
11545 then
11546 Error_Pragma_Arg
11547 ("main subprogram priority is out of range", Arg1);
11548 end if;
11549 end;
11550 end if;
11551
11552 Set_Main_Priority
874a0341
RD
11553 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11554
11555 -- Load an arbitrary entity from System.Tasking to make sure
11556 -- this package is implicitly with'ed, since we need to have
11557 -- the tasking run-time active for the pragma Priority to have
11558 -- any effect.
11559
11560 declare
11561 Discard : Entity_Id;
11562 pragma Warnings (Off, Discard);
11563 begin
11564 Discard := RTE (RE_Task_List);
11565 end;
996ae0b0
RK
11566
11567 -- Task or Protected, must be of type Integer
11568
d7ba4df4 11569 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
0f1a6a0b 11570 Arg := Get_Pragma_Arg (Arg1);
fbf5a39b
AC
11571
11572 -- The expression must be analyzed in the special manner
11573 -- described in "Handling of Default and Per-Object
11574 -- Expressions" in sem.ads.
11575
21d27997 11576 Preanalyze_Spec_Expression (Arg, Standard_Integer);
fbf5a39b
AC
11577
11578 if not Is_Static_Expression (Arg) then
11579 Check_Restriction (Static_Priorities, Arg);
996ae0b0
RK
11580 end if;
11581
11582 -- Anything else is incorrect
11583
11584 else
11585 Pragma_Misplaced;
11586 end if;
11587
c775c209 11588 if Has_Pragma_Priority (P) then
996ae0b0
RK
11589 Error_Pragma ("duplicate pragma% not allowed");
11590 else
c775c209 11591 Set_Has_Pragma_Priority (P, True);
996ae0b0 11592
d7ba4df4 11593 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
996ae0b0
RK
11594 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11595 -- exp_ch9 should use this ???
11596 end if;
11597 end if;
996ae0b0
RK
11598 end Priority;
11599
ac9e9918
RD
11600 -----------------------------------
11601 -- Priority_Specific_Dispatching --
11602 -----------------------------------
11603
11604 -- pragma Priority_Specific_Dispatching (
11605 -- policy_IDENTIFIER,
11606 -- first_priority_EXPRESSION,
11607 -- last_priority_EXPRESSION);
11608
11609 when Pragma_Priority_Specific_Dispatching =>
11610 Priority_Specific_Dispatching : declare
11611 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11612 -- This is the entity System.Any_Priority;
11613
11614 DP : Character;
11615 Lower_Bound : Node_Id;
11616 Upper_Bound : Node_Id;
11617 Lower_Val : Uint;
11618 Upper_Val : Uint;
11619
11620 begin
2fa9443e 11621 Ada_2005_Pragma;
ac9e9918
RD
11622 Check_Arg_Count (3);
11623 Check_No_Identifiers;
11624 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11625 Check_Valid_Configuration_Pragma;
0f1a6a0b 11626 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
ac9e9918
RD
11627 DP := Fold_Upper (Name_Buffer (1));
11628
0f1a6a0b 11629 Lower_Bound := Get_Pragma_Arg (Arg2);
ac9e9918
RD
11630 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11631 Lower_Val := Expr_Value (Lower_Bound);
11632
0f1a6a0b 11633 Upper_Bound := Get_Pragma_Arg (Arg3);
ac9e9918
RD
11634 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11635 Upper_Val := Expr_Value (Upper_Bound);
11636
11637 -- It is not allowed to use Task_Dispatching_Policy and
11638 -- Priority_Specific_Dispatching in the same partition.
11639
11640 if Task_Dispatching_Policy /= ' ' then
11641 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11642 Error_Pragma
11643 ("pragma% incompatible with Task_Dispatching_Policy#");
11644
11645 -- Check lower bound in range
11646
11647 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11648 or else
11649 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11650 then
11651 Error_Pragma_Arg
11652 ("first_priority is out of range", Arg2);
11653
11654 -- Check upper bound in range
11655
11656 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11657 or else
11658 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11659 then
11660 Error_Pragma_Arg
11661 ("last_priority is out of range", Arg3);
11662
11663 -- Check that the priority range is valid
11664
11665 elsif Lower_Val > Upper_Val then
11666 Error_Pragma
11667 ("last_priority_expression must be greater than" &
11668 " or equal to first_priority_expression");
11669
11670 -- Store the new policy, but always preserve System_Location since
11671 -- we like the error message with the run-time name.
11672
11673 else
11674 -- Check overlapping in the priority ranges specified in other
11675 -- Priority_Specific_Dispatching pragmas within the same
11676 -- partition. We can only check those we know about!
11677
11678 for J in
11679 Specific_Dispatching.First .. Specific_Dispatching.Last
11680 loop
11681 if Specific_Dispatching.Table (J).First_Priority in
11682 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11683 or else Specific_Dispatching.Table (J).Last_Priority in
11684 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11685 then
11686 Error_Msg_Sloc :=
11687 Specific_Dispatching.Table (J).Pragma_Loc;
c690a2ec
RD
11688 Error_Pragma
11689 ("priority range overlaps with "
11690 & "Priority_Specific_Dispatching#");
ac9e9918
RD
11691 end if;
11692 end loop;
11693
11694 -- The use of Priority_Specific_Dispatching is incompatible
11695 -- with Task_Dispatching_Policy.
11696
11697 if Task_Dispatching_Policy /= ' ' then
11698 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
c690a2ec
RD
11699 Error_Pragma
11700 ("Priority_Specific_Dispatching incompatible "
11701 & "with Task_Dispatching_Policy#");
ac9e9918
RD
11702 end if;
11703
11704 -- The use of Priority_Specific_Dispatching forces ceiling
11705 -- locking policy.
11706
11707 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11708 Error_Msg_Sloc := Locking_Policy_Sloc;
c690a2ec
RD
11709 Error_Pragma
11710 ("Priority_Specific_Dispatching incompatible "
11711 & "with Locking_Policy#");
ac9e9918
RD
11712
11713 -- Set the Ceiling_Locking policy, but preserve System_Location
11714 -- since we like the error message with the run time name.
11715
11716 else
11717 Locking_Policy := 'C';
11718
11719 if Locking_Policy_Sloc /= System_Location then
11720 Locking_Policy_Sloc := Loc;
11721 end if;
11722 end if;
11723
11724 -- Add entry in the table
11725
11726 Specific_Dispatching.Append
11727 ((Dispatching_Policy => DP,
11728 First_Priority => UI_To_Int (Lower_Val),
11729 Last_Priority => UI_To_Int (Upper_Val),
11730 Pragma_Loc => Loc));
11731 end if;
11732 end Priority_Specific_Dispatching;
11733
2e071734
AC
11734 -------------
11735 -- Profile --
11736 -------------
11737
11738 -- pragma Profile (profile_IDENTIFIER);
11739
21d27997 11740 -- profile_IDENTIFIER => Restricted | Ravenscar
2e071734
AC
11741
11742 when Pragma_Profile =>
2fa9443e 11743 Ada_2005_Pragma;
2e071734
AC
11744 Check_Arg_Count (1);
11745 Check_Valid_Configuration_Pragma;
11746 Check_No_Identifiers;
2e071734
AC
11747
11748 declare
11749 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11750 begin
11751 if Chars (Argx) = Name_Ravenscar then
8a36a0cc 11752 Set_Ravenscar_Profile (N);
cc335f43 11753 elsif Chars (Argx) = Name_Restricted then
23e6615e
RD
11754 Set_Profile_Restrictions
11755 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
cc335f43
AC
11756 else
11757 Error_Pragma_Arg ("& is not a valid profile", Argx);
11758 end if;
11759 end;
11760
11761 ----------------------
11762 -- Profile_Warnings --
11763 ----------------------
11764
11765 -- pragma Profile_Warnings (profile_IDENTIFIER);
11766
21d27997 11767 -- profile_IDENTIFIER => Restricted | Ravenscar
cc335f43
AC
11768
11769 when Pragma_Profile_Warnings =>
11770 GNAT_Pragma;
11771 Check_Arg_Count (1);
11772 Check_Valid_Configuration_Pragma;
11773 Check_No_Identifiers;
11774
11775 declare
11776 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11777 begin
11778 if Chars (Argx) = Name_Ravenscar then
11779 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
cc335f43
AC
11780 elsif Chars (Argx) = Name_Restricted then
11781 Set_Profile_Restrictions (Restricted, N, Warn => True);
2e071734
AC
11782 else
11783 Error_Pragma_Arg ("& is not a valid profile", Argx);
11784 end if;
11785 end;
11786
996ae0b0
RK
11787 --------------------------
11788 -- Propagate_Exceptions --
11789 --------------------------
11790
11791 -- pragma Propagate_Exceptions;
11792
57193e09
TQ
11793 -- Note: this pragma is obsolete and has no effect
11794
996ae0b0
RK
11795 when Pragma_Propagate_Exceptions =>
11796 GNAT_Pragma;
11797 Check_Arg_Count (0);
11798
11799 if In_Extended_Main_Source_Unit (N) then
11800 Propagate_Exceptions := True;
11801 end if;
11802
11803 ------------------
11804 -- Psect_Object --
11805 ------------------
11806
11807 -- pragma Psect_Object (
11808 -- [Internal =>] LOCAL_NAME,
11809 -- [, [External =>] EXTERNAL_SYMBOL]
11810 -- [, [Size =>] EXTERNAL_SYMBOL]);
11811
11812 when Pragma_Psect_Object | Pragma_Common_Object =>
11813 Psect_Object : declare
11814 Args : Args_List (1 .. 3);
fbf5a39b 11815 Names : constant Name_List (1 .. 3) := (
996ae0b0
RK
11816 Name_Internal,
11817 Name_External,
11818 Name_Size);
11819
11820 Internal : Node_Id renames Args (1);
11821 External : Node_Id renames Args (2);
11822 Size : Node_Id renames Args (3);
11823
1d571f3b 11824 Def_Id : Entity_Id;
996ae0b0
RK
11825
11826 procedure Check_Too_Long (Arg : Node_Id);
11827 -- Posts message if the argument is an identifier with more
11828 -- than 31 characters, or a string literal with more than
11829 -- 31 characters, and we are operating under VMS
11830
07fc65c4
GB
11831 --------------------
11832 -- Check_Too_Long --
11833 --------------------
11834
996ae0b0 11835 procedure Check_Too_Long (Arg : Node_Id) is
fbf5a39b 11836 X : constant Node_Id := Original_Node (Arg);
996ae0b0
RK
11837
11838 begin
d7ba4df4 11839 if not Nkind_In (X, N_String_Literal, N_Identifier) then
996ae0b0
RK
11840 Error_Pragma_Arg
11841 ("inappropriate argument for pragma %", Arg);
11842 end if;
11843
11844 if OpenVMS_On_Target then
11845 if (Nkind (X) = N_String_Literal
11846 and then String_Length (Strval (X)) > 31)
11847 or else
11848 (Nkind (X) = N_Identifier
11849 and then Length_Of_Name (Chars (X)) > 31)
11850 then
11851 Error_Pragma_Arg
11852 ("argument for pragma % is longer than 31 characters",
11853 Arg);
11854 end if;
11855 end if;
11856 end Check_Too_Long;
11857
11858 -- Start of processing for Common_Object/Psect_Object
11859
11860 begin
11861 GNAT_Pragma;
11862 Gather_Associations (Names, Args);
11863 Process_Extended_Import_Export_Internal_Arg (Internal);
11864
1d571f3b 11865 Def_Id := Entity (Internal);
996ae0b0 11866
8a95f4e8 11867 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
996ae0b0
RK
11868 Error_Pragma_Arg
11869 ("pragma% must designate an object", Internal);
11870 end if;
11871
1d571f3b 11872 Check_Too_Long (Internal);
996ae0b0
RK
11873
11874 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
ed2233dc 11875 Error_Pragma_Arg
996ae0b0 11876 ("cannot use pragma% for imported/exported object",
1d571f3b 11877 Internal);
996ae0b0
RK
11878 end if;
11879
1d571f3b 11880 if Is_Concurrent_Type (Etype (Internal)) then
ed2233dc 11881 Error_Pragma_Arg
996ae0b0 11882 ("cannot specify pragma % for task/protected object",
1d571f3b 11883 Internal);
996ae0b0
RK
11884 end if;
11885
1d571f3b
AC
11886 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11887 or else
11888 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11889 then
11890 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
996ae0b0
RK
11891 end if;
11892
11893 if Ekind (Def_Id) = E_Constant then
ed2233dc 11894 Error_Pragma_Arg
1d571f3b 11895 ("cannot specify pragma % for a constant", Internal);
996ae0b0
RK
11896 end if;
11897
1d571f3b 11898 if Is_Record_Type (Etype (Internal)) then
996ae0b0
RK
11899 declare
11900 Ent : Entity_Id;
11901 Decl : Entity_Id;
11902
11903 begin
1d571f3b 11904 Ent := First_Entity (Etype (Internal));
996ae0b0
RK
11905 while Present (Ent) loop
11906 Decl := Declaration_Node (Ent);
11907
11908 if Ekind (Ent) = E_Component
11909 and then Nkind (Decl) = N_Component_Declaration
11910 and then Present (Expression (Decl))
fbf5a39b 11911 and then Warn_On_Export_Import
996ae0b0
RK
11912 then
11913 Error_Msg_N
1d571f3b 11914 ("?object for pragma % has defaults", Internal);
996ae0b0
RK
11915 exit;
11916
11917 else
11918 Next_Entity (Ent);
11919 end if;
11920 end loop;
11921 end;
11922 end if;
11923
11924 if Present (Size) then
11925 Check_Too_Long (Size);
11926 end if;
11927
996ae0b0 11928 if Present (External) then
5f3ab6fb 11929 Check_Arg_Is_External_Name (External);
996ae0b0 11930 Check_Too_Long (External);
996ae0b0
RK
11931 end if;
11932
1d571f3b 11933 -- If all error tests pass, link pragma on to the rep item chain
fbf5a39b 11934
1d571f3b 11935 Record_Rep_Item (Def_Id, N);
996ae0b0
RK
11936 end Psect_Object;
11937
11938 ----------
11939 -- Pure --
11940 ----------
11941
11942 -- pragma Pure [(library_unit_NAME)];
11943
11944 when Pragma_Pure => Pure : declare
11945 Ent : Entity_Id;
59e5fbe0 11946
996ae0b0
RK
11947 begin
11948 Check_Ada_83_Warning;
11949 Check_Valid_Library_Unit_Pragma;
11950
11951 if Nkind (N) = N_Null_Statement then
11952 return;
11953 end if;
11954
11955 Ent := Find_Lib_Unit_Name;
11956 Set_Is_Pure (Ent);
57193e09 11957 Set_Has_Pragma_Pure (Ent);
996ae0b0
RK
11958 Set_Suppress_Elaboration_Warnings (Ent);
11959 end Pure;
11960
59e5fbe0
RD
11961 -------------
11962 -- Pure_05 --
11963 -------------
11964
11965 -- pragma Pure_05 [(library_unit_NAME)];
11966
11967 -- This pragma is useable only in GNAT_Mode, where it is used like
11968 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11969 -- it is ignored). It may be used after a pragma Preelaborate, in
11970 -- which case it overrides the effect of the pragma Preelaborate.
11971 -- This is used to implement AI-362 which recategorizes some run-time
11972 -- packages in Ada 2005 mode.
11973
11974 when Pragma_Pure_05 => Pure_05 : declare
11975 Ent : Entity_Id;
11976
11977 begin
11978 GNAT_Pragma;
11979 Check_Valid_Library_Unit_Pragma;
11980
11981 if not GNAT_Mode then
11982 Error_Pragma ("pragma% only available in GNAT mode");
11983 end if;
d7ba4df4 11984
59e5fbe0
RD
11985 if Nkind (N) = N_Null_Statement then
11986 return;
11987 end if;
11988
11989 -- This is one of the few cases where we need to test the value of
11990 -- Ada_Version_Explicit rather than Ada_Version (which is always
dbe945f1 11991 -- set to Ada_2012 in a predefined unit), we need to know the
59e5fbe0
RD
11992 -- explicit version set to know if this pragma is active.
11993
0791fbe9 11994 if Ada_Version_Explicit >= Ada_2005 then
59e5fbe0
RD
11995 Ent := Find_Lib_Unit_Name;
11996 Set_Is_Preelaborated (Ent, False);
11997 Set_Is_Pure (Ent);
11998 Set_Suppress_Elaboration_Warnings (Ent);
11999 end if;
12000 end Pure_05;
12001
996ae0b0
RK
12002 -------------------
12003 -- Pure_Function --
12004 -------------------
12005
12006 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12007
12008 when Pragma_Pure_Function => Pure_Function : declare
6e937c1c
AC
12009 E_Id : Node_Id;
12010 E : Entity_Id;
12011 Def_Id : Entity_Id;
12012 Effective : Boolean := False;
996ae0b0
RK
12013
12014 begin
12015 GNAT_Pragma;
12016 Check_Arg_Count (1);
12017 Check_Optional_Identifier (Arg1, Name_Entity);
12018 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 12019 E_Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
12020
12021 if Error_Posted (E_Id) then
12022 return;
12023 end if;
12024
12025 -- Loop through homonyms (overloadings) of referenced entity
12026
12027 E := Entity (E_Id);
996ae0b0 12028
fbf5a39b
AC
12029 if Present (E) then
12030 loop
12031 Def_Id := Get_Base_Subprogram (E);
996ae0b0 12032
8a95f4e8
RD
12033 if not Ekind_In (Def_Id, E_Function,
12034 E_Generic_Function,
12035 E_Operator)
fbf5a39b
AC
12036 then
12037 Error_Pragma_Arg
12038 ("pragma% requires a function name", Arg1);
12039 end if;
12040
eaba57fb 12041 Set_Is_Pure (Def_Id);
6e937c1c
AC
12042
12043 if not Has_Pragma_Pure_Function (Def_Id) then
eaba57fb
RD
12044 Set_Has_Pragma_Pure_Function (Def_Id);
12045 Effective := True;
6e937c1c 12046 end if;
fbf5a39b 12047
0f1a6a0b 12048 exit when From_Aspect_Specification (N);
fbf5a39b
AC
12049 E := Homonym (E);
12050 exit when No (E) or else Scope (E) /= Current_Scope;
12051 end loop;
6e937c1c 12052
eaba57fb 12053 if not Effective
6e937c1c
AC
12054 and then Warn_On_Redundant_Constructs
12055 then
ed2233dc 12056 Error_Msg_NE
19d846a0
RD
12057 ("pragma Pure_Function on& is redundant?",
12058 N, Entity (E_Id));
6e937c1c 12059 end if;
fbf5a39b 12060 end if;
996ae0b0
RK
12061 end Pure_Function;
12062
12063 --------------------
12064 -- Queuing_Policy --
12065 --------------------
12066
12067 -- pragma Queuing_Policy (policy_IDENTIFIER);
12068
12069 when Pragma_Queuing_Policy => declare
12070 QP : Character;
12071
12072 begin
12073 Check_Ada_83_Warning;
12074 Check_Arg_Count (1);
12075 Check_No_Identifiers;
12076 Check_Arg_Is_Queuing_Policy (Arg1);
12077 Check_Valid_Configuration_Pragma;
0f1a6a0b 12078 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
996ae0b0
RK
12079 QP := Fold_Upper (Name_Buffer (1));
12080
12081 if Queuing_Policy /= ' '
12082 and then Queuing_Policy /= QP
12083 then
12084 Error_Msg_Sloc := Queuing_Policy_Sloc;
12085 Error_Pragma ("queuing policy incompatible with policy#");
fbf5a39b 12086
b3b9865d
AC
12087 -- Set new policy, but always preserve System_Location since we
12088 -- like the error message with the run time name.
fbf5a39b 12089
996ae0b0
RK
12090 else
12091 Queuing_Policy := QP;
fbf5a39b
AC
12092
12093 if Queuing_Policy_Sloc /= System_Location then
12094 Queuing_Policy_Sloc := Loc;
12095 end if;
996ae0b0
RK
12096 end if;
12097 end;
12098
21d27997
RD
12099 -----------------------
12100 -- Relative_Deadline --
12101 -----------------------
12102
12103 -- pragma Relative_Deadline (time_span_EXPRESSION);
12104
12105 when Pragma_Relative_Deadline => Relative_Deadline : declare
12106 P : constant Node_Id := Parent (N);
12107 Arg : Node_Id;
12108
12109 begin
12110 Ada_2005_Pragma;
12111 Check_No_Identifiers;
12112 Check_Arg_Count (1);
12113
0f1a6a0b 12114 Arg := Get_Pragma_Arg (Arg1);
21d27997
RD
12115
12116 -- The expression must be analyzed in the special manner described
12117 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12118
12119 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12120
12121 -- Subprogram case
12122
12123 if Nkind (P) = N_Subprogram_Body then
12124 Check_In_Main_Program;
12125
12126 -- Tasks
12127
12128 elsif Nkind (P) = N_Task_Definition then
12129 null;
12130
12131 -- Anything else is incorrect
12132
12133 else
12134 Pragma_Misplaced;
12135 end if;
12136
12137 if Has_Relative_Deadline_Pragma (P) then
12138 Error_Pragma ("duplicate pragma% not allowed");
12139 else
12140 Set_Has_Relative_Deadline_Pragma (P, True);
12141
12142 if Nkind (P) = N_Task_Definition then
12143 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12144 end if;
12145 end if;
12146 end Relative_Deadline;
12147
996ae0b0
RK
12148 ---------------------------
12149 -- Remote_Call_Interface --
12150 ---------------------------
12151
12152 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12153
12154 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12155 Cunit_Node : Node_Id;
12156 Cunit_Ent : Entity_Id;
12157 K : Node_Kind;
12158
12159 begin
12160 Check_Ada_83_Warning;
12161 Check_Valid_Library_Unit_Pragma;
12162
12163 if Nkind (N) = N_Null_Statement then
12164 return;
12165 end if;
12166
12167 Cunit_Node := Cunit (Current_Sem_Unit);
12168 K := Nkind (Unit (Cunit_Node));
12169 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12170
12171 if K = N_Package_Declaration
12172 or else K = N_Generic_Package_Declaration
12173 or else K = N_Subprogram_Declaration
12174 or else K = N_Generic_Subprogram_Declaration
12175 or else (K = N_Subprogram_Body
12176 and then Acts_As_Spec (Unit (Cunit_Node)))
12177 then
12178 null;
12179 else
12180 Error_Pragma (
12181 "pragma% must apply to package or subprogram declaration");
12182 end if;
12183
12184 Set_Is_Remote_Call_Interface (Cunit_Ent);
12185 end Remote_Call_Interface;
12186
12187 ------------------
12188 -- Remote_Types --
12189 ------------------
12190
12191 -- pragma Remote_Types [(library_unit_NAME)];
12192
12193 when Pragma_Remote_Types => Remote_Types : declare
12194 Cunit_Node : Node_Id;
12195 Cunit_Ent : Entity_Id;
12196
12197 begin
12198 Check_Ada_83_Warning;
12199 Check_Valid_Library_Unit_Pragma;
12200
12201 if Nkind (N) = N_Null_Statement then
12202 return;
12203 end if;
12204
12205 Cunit_Node := Cunit (Current_Sem_Unit);
12206 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12207
d7ba4df4
RD
12208 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12209 N_Generic_Package_Declaration)
996ae0b0 12210 then
d7ba4df4
RD
12211 Error_Pragma
12212 ("pragma% can only apply to a package declaration");
996ae0b0
RK
12213 end if;
12214
12215 Set_Is_Remote_Types (Cunit_Ent);
12216 end Remote_Types;
12217
12218 ---------------
12219 -- Ravenscar --
12220 ---------------
12221
fbf5a39b
AC
12222 -- pragma Ravenscar;
12223
996ae0b0
RK
12224 when Pragma_Ravenscar =>
12225 GNAT_Pragma;
12226 Check_Arg_Count (0);
12227 Check_Valid_Configuration_Pragma;
8a36a0cc 12228 Set_Ravenscar_Profile (N);
996ae0b0 12229
cc335f43 12230 if Warn_On_Obsolescent_Feature then
ed2233dc
AC
12231 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12232 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
cc335f43
AC
12233 end if;
12234
996ae0b0
RK
12235 -------------------------
12236 -- Restricted_Run_Time --
12237 -------------------------
12238
fbf5a39b
AC
12239 -- pragma Restricted_Run_Time;
12240
996ae0b0
RK
12241 when Pragma_Restricted_Run_Time =>
12242 GNAT_Pragma;
12243 Check_Arg_Count (0);
12244 Check_Valid_Configuration_Pragma;
23e6615e
RD
12245 Set_Profile_Restrictions
12246 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
cc335f43
AC
12247
12248 if Warn_On_Obsolescent_Feature then
ed2233dc 12249 Error_Msg_N
cc335f43 12250 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
ed2233dc 12251 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
cc335f43 12252 end if;
996ae0b0
RK
12253
12254 ------------------
12255 -- Restrictions --
12256 ------------------
12257
12258 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12259
12260 -- RESTRICTION ::=
12261 -- restriction_IDENTIFIER
12262 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12263
6e937c1c 12264 when Pragma_Restrictions =>
23e6615e
RD
12265 Process_Restrictions_Or_Restriction_Warnings
12266 (Warn => Treat_Restrictions_As_Warnings);
996ae0b0 12267
fbf5a39b
AC
12268 --------------------------
12269 -- Restriction_Warnings --
12270 --------------------------
12271
12272 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12273
6e937c1c
AC
12274 -- RESTRICTION ::=
12275 -- restriction_IDENTIFIER
12276 -- | restriction_parameter_IDENTIFIER => EXPRESSION
fbf5a39b 12277
6e937c1c 12278 when Pragma_Restriction_Warnings =>
21d27997 12279 GNAT_Pragma;
ac9e9918 12280 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
fbf5a39b 12281
996ae0b0
RK
12282 ----------------
12283 -- Reviewable --
12284 ----------------
12285
12286 -- pragma Reviewable;
12287
12288 when Pragma_Reviewable =>
12289 Check_Ada_83_Warning;
12290 Check_Arg_Count (0);
6a2afd13
AC
12291
12292 -- Call dummy debugging function rv. This is done to assist front
12293 -- end debugging. By placing a Reviewable pragma in the source
12294 -- program, a breakpoint on rv catches this place in the source,
12295 -- allowing convenient stepping to the point of interest.
12296
2fa9443e 12297 rv;
996ae0b0 12298
6a2afd13
AC
12299 --------------------------
12300 -- Short_Circuit_And_Or --
12301 --------------------------
12302
12303 when Pragma_Short_Circuit_And_Or =>
12304 GNAT_Pragma;
12305 Check_Arg_Count (0);
12306 Check_Valid_Configuration_Pragma;
12307 Short_Circuit_And_Or := True;
12308
996ae0b0
RK
12309 -------------------
12310 -- Share_Generic --
12311 -------------------
12312
12313 -- pragma Share_Generic (NAME {, NAME});
12314
12315 when Pragma_Share_Generic =>
12316 GNAT_Pragma;
12317 Process_Generic_List;
12318
12319 ------------
12320 -- Shared --
12321 ------------
12322
12323 -- pragma Shared (LOCAL_NAME);
12324
12325 when Pragma_Shared =>
07fc65c4 12326 GNAT_Pragma;
996ae0b0
RK
12327 Process_Atomic_Shared_Volatile;
12328
12329 --------------------
12330 -- Shared_Passive --
12331 --------------------
12332
12333 -- pragma Shared_Passive [(library_unit_NAME)];
12334
12335 -- Set the flag Is_Shared_Passive of program unit name entity
12336
12337 when Pragma_Shared_Passive => Shared_Passive : declare
12338 Cunit_Node : Node_Id;
12339 Cunit_Ent : Entity_Id;
12340
12341 begin
12342 Check_Ada_83_Warning;
12343 Check_Valid_Library_Unit_Pragma;
12344
12345 if Nkind (N) = N_Null_Statement then
12346 return;
12347 end if;
12348
12349 Cunit_Node := Cunit (Current_Sem_Unit);
12350 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12351
d7ba4df4
RD
12352 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12353 N_Generic_Package_Declaration)
996ae0b0 12354 then
d7ba4df4
RD
12355 Error_Pragma
12356 ("pragma% can only apply to a package declaration");
996ae0b0
RK
12357 end if;
12358
12359 Set_Is_Shared_Passive (Cunit_Ent);
12360 end Shared_Passive;
12361
292beb8f
AC
12362 -----------------------
12363 -- Short_Descriptors --
12364 -----------------------
12365
12366 -- pragma Short_Descriptors;
12367
12368 when Pragma_Short_Descriptors =>
12369 GNAT_Pragma;
12370 Check_Arg_Count (0);
12371 Check_Valid_Configuration_Pragma;
12372 Short_Descriptors := True;
12373
996ae0b0
RK
12374 ----------------------
12375 -- Source_File_Name --
12376 ----------------------
12377
2820d220
AC
12378 -- There are five forms for this pragma:
12379
12380 -- pragma Source_File_Name (
12381 -- [UNIT_NAME =>] unit_NAME,
12382 -- BODY_FILE_NAME => STRING_LITERAL
12383 -- [, [INDEX =>] INTEGER_LITERAL]);
12384
996ae0b0 12385 -- pragma Source_File_Name (
2820d220
AC
12386 -- [UNIT_NAME =>] unit_NAME,
12387 -- SPEC_FILE_NAME => STRING_LITERAL
12388 -- [, [INDEX =>] INTEGER_LITERAL]);
12389
12390 -- pragma Source_File_Name (
12391 -- BODY_FILE_NAME => STRING_LITERAL
12392 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12393 -- [, CASING => CASING_SPEC]);
12394
12395 -- pragma Source_File_Name (
12396 -- SPEC_FILE_NAME => STRING_LITERAL
12397 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12398 -- [, CASING => CASING_SPEC]);
12399
12400 -- pragma Source_File_Name (
12401 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12402 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12403 -- [, CASING => CASING_SPEC]);
12404
12405 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12406
12407 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
b3b9865d
AC
12408 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12409 -- only be used when no project file is used, while SFNP can only be
12410 -- used when a project file is used.
996ae0b0 12411
b3b9865d
AC
12412 -- No processing here. Processing was completed during parsing, since
12413 -- we need to have file names set as early as possible. Units are
12414 -- loaded well before semantic processing starts.
996ae0b0 12415
b3b9865d
AC
12416 -- The only processing we defer to this point is the check for
12417 -- correct placement.
996ae0b0
RK
12418
12419 when Pragma_Source_File_Name =>
12420 GNAT_Pragma;
12421 Check_Valid_Configuration_Pragma;
12422
fbf5a39b
AC
12423 ------------------------------
12424 -- Source_File_Name_Project --
12425 ------------------------------
12426
2820d220 12427 -- See Source_File_Name for syntax
fbf5a39b 12428
b3b9865d
AC
12429 -- No processing here. Processing was completed during parsing, since
12430 -- we need to have file names set as early as possible. Units are
12431 -- loaded well before semantic processing starts.
fbf5a39b 12432
b3b9865d
AC
12433 -- The only processing we defer to this point is the check for
12434 -- correct placement.
fbf5a39b
AC
12435
12436 when Pragma_Source_File_Name_Project =>
12437 GNAT_Pragma;
12438 Check_Valid_Configuration_Pragma;
12439
b3b9865d
AC
12440 -- Check that a pragma Source_File_Name_Project is used only in a
12441 -- configuration pragmas file.
2820d220 12442
b3b9865d
AC
12443 -- Pragmas Source_File_Name_Project should only be generated by
12444 -- the Project Manager in configuration pragmas files.
fbf5a39b
AC
12445
12446 -- This is really an ugly test. It seems to depend on some
b3b9865d
AC
12447 -- accidental and undocumented property. At the very least it
12448 -- needs to be documented, but it would be better to have a
12449 -- clean way of testing if we are in a configuration file???
fbf5a39b
AC
12450
12451 if Present (Parent (N)) then
12452 Error_Pragma
12453 ("pragma% can only appear in a configuration pragmas file");
12454 end if;
12455
996ae0b0
RK
12456 ----------------------
12457 -- Source_Reference --
12458 ----------------------
12459
12460 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12461
b3b9865d
AC
12462 -- Nothing to do, all processing completed in Par.Prag, since we need
12463 -- the information for possible parser messages that are output.
996ae0b0
RK
12464
12465 when Pragma_Source_Reference =>
12466 GNAT_Pragma;
12467
2fa9443e
ES
12468 --------------------------------
12469 -- Static_Elaboration_Desired --
12470 --------------------------------
12471
c690a2ec 12472 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
2fa9443e
ES
12473
12474 when Pragma_Static_Elaboration_Desired =>
c690a2ec
RD
12475 GNAT_Pragma;
12476 Check_At_Most_N_Arguments (1);
2fa9443e
ES
12477
12478 if Is_Compilation_Unit (Current_Scope)
12479 and then Ekind (Current_Scope) = E_Package
12480 then
12481 Set_Static_Elaboration_Desired (Current_Scope, True);
12482 else
12483 Error_Pragma ("pragma% must apply to a library-level package");
12484 end if;
12485
996ae0b0
RK
12486 ------------------
12487 -- Storage_Size --
12488 ------------------
12489
12490 -- pragma Storage_Size (EXPRESSION);
12491
12492 when Pragma_Storage_Size => Storage_Size : declare
fbf5a39b
AC
12493 P : constant Node_Id := Parent (N);
12494 Arg : Node_Id;
996ae0b0
RK
12495
12496 begin
12497 Check_No_Identifiers;
12498 Check_Arg_Count (1);
12499
21d27997
RD
12500 -- The expression must be analyzed in the special manner described
12501 -- in "Handling of Default Expressions" in sem.ads.
996ae0b0 12502
0f1a6a0b 12503 Arg := Get_Pragma_Arg (Arg1);
21d27997 12504 Preanalyze_Spec_Expression (Arg, Any_Integer);
996ae0b0 12505
fbf5a39b
AC
12506 if not Is_Static_Expression (Arg) then
12507 Check_Restriction (Static_Storage_Size, Arg);
996ae0b0
RK
12508 end if;
12509
12510 if Nkind (P) /= N_Task_Definition then
12511 Pragma_Misplaced;
12512 return;
12513
12514 else
12515 if Has_Storage_Size_Pragma (P) then
12516 Error_Pragma ("duplicate pragma% not allowed");
12517 else
12518 Set_Has_Storage_Size_Pragma (P, True);
12519 end if;
12520
12521 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12522 -- ??? exp_ch9 should use this!
12523 end if;
12524 end Storage_Size;
12525
12526 ------------------
12527 -- Storage_Unit --
12528 ------------------
12529
12530 -- pragma Storage_Unit (NUMERIC_LITERAL);
12531
12532 -- Only permitted argument is System'Storage_Unit value
12533
12534 when Pragma_Storage_Unit =>
12535 Check_No_Identifiers;
12536 Check_Arg_Count (1);
12537 Check_Arg_Is_Integer_Literal (Arg1);
12538
0f1a6a0b 12539 if Intval (Get_Pragma_Arg (Arg1)) /=
996ae0b0
RK
12540 UI_From_Int (Ttypes.System_Storage_Unit)
12541 then
12542 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12543 Error_Pragma_Arg
12544 ("the only allowed argument for pragma% is ^", Arg1);
12545 end if;
12546
12547 --------------------
12548 -- Stream_Convert --
12549 --------------------
12550
12551 -- pragma Stream_Convert (
12552 -- [Entity =>] type_LOCAL_NAME,
12553 -- [Read =>] function_NAME,
12554 -- [Write =>] function NAME);
12555
07fc65c4
GB
12556 when Pragma_Stream_Convert => Stream_Convert : declare
12557
12558 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
b3b9865d
AC
12559 -- Check that the given argument is the name of a local function
12560 -- of one argument that is not overloaded earlier in the current
12561 -- local scope. A check is also made that the argument is a
12562 -- function with one parameter.
07fc65c4
GB
12563
12564 --------------------------------------
12565 -- Check_OK_Stream_Convert_Function --
12566 --------------------------------------
12567
12568 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12569 Ent : Entity_Id;
12570
12571 begin
12572 Check_Arg_Is_Local_Name (Arg);
0f1a6a0b 12573 Ent := Entity (Get_Pragma_Arg (Arg));
07fc65c4
GB
12574
12575 if Has_Homonym (Ent) then
12576 Error_Pragma_Arg
12577 ("argument for pragma% may not be overloaded", Arg);
12578 end if;
12579
12580 if Ekind (Ent) /= E_Function
12581 or else No (First_Formal (Ent))
12582 or else Present (Next_Formal (First_Formal (Ent)))
12583 then
12584 Error_Pragma_Arg
12585 ("argument for pragma% must be" &
12586 " function of one argument", Arg);
12587 end if;
12588 end Check_OK_Stream_Convert_Function;
12589
f3d57416 12590 -- Start of processing for Stream_Convert
07fc65c4
GB
12591
12592 begin
996ae0b0 12593 GNAT_Pragma;
59e5fbe0 12594 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
996ae0b0
RK
12595 Check_Arg_Count (3);
12596 Check_Optional_Identifier (Arg1, Name_Entity);
12597 Check_Optional_Identifier (Arg2, Name_Read);
12598 Check_Optional_Identifier (Arg3, Name_Write);
12599 Check_Arg_Is_Local_Name (Arg1);
07fc65c4
GB
12600 Check_OK_Stream_Convert_Function (Arg2);
12601 Check_OK_Stream_Convert_Function (Arg3);
996ae0b0
RK
12602
12603 declare
12604 Typ : constant Entity_Id :=
0f1a6a0b
AC
12605 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12606 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12607 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
996ae0b0
RK
12608
12609 begin
21d27997
RD
12610 Check_First_Subtype (Arg1);
12611
12612 -- Check for too early or too late. Note that we don't enforce
12613 -- the rule about primitive operations in this case, since, as
12614 -- is the case for explicit stream attributes themselves, these
12615 -- restrictions are not appropriate. Note that the chaining of
12616 -- the pragma by Rep_Item_Too_Late is actually the critical
12617 -- processing done for this pragma.
12618
12619 if Rep_Item_Too_Early (Typ, N)
996ae0b0 12620 or else
21d27997 12621 Rep_Item_Too_Late (Typ, N, FOnly => True)
996ae0b0
RK
12622 then
12623 return;
12624 end if;
12625
21d27997 12626 -- Return if previous error
996ae0b0 12627
21d27997
RD
12628 if Etype (Typ) = Any_Type
12629 or else
12630 Etype (Read) = Any_Type
996ae0b0 12631 or else
21d27997 12632 Etype (Write) = Any_Type
996ae0b0
RK
12633 then
12634 return;
12635 end if;
12636
21d27997
RD
12637 -- Error checks
12638
996ae0b0
RK
12639 if Underlying_Type (Etype (Read)) /= Typ then
12640 Error_Pragma_Arg
12641 ("incorrect return type for function&", Arg2);
12642 end if;
12643
12644 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12645 Error_Pragma_Arg
12646 ("incorrect parameter type for function&", Arg3);
12647 end if;
12648
12649 if Underlying_Type (Etype (First_Formal (Read))) /=
12650 Underlying_Type (Etype (Write))
12651 then
12652 Error_Pragma_Arg
12653 ("result type of & does not match Read parameter type",
12654 Arg3);
12655 end if;
12656 end;
12657 end Stream_Convert;
12658
12659 -------------------------
12660 -- Style_Checks (GNAT) --
12661 -------------------------
12662
12663 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12664
b3b9865d
AC
12665 -- This is processed by the parser since some of the style checks
12666 -- take place during source scanning and parsing. This means that
12667 -- we don't need to issue error messages here.
996ae0b0
RK
12668
12669 when Pragma_Style_Checks => Style_Checks : declare
0f1a6a0b 12670 A : constant Node_Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
12671 S : String_Id;
12672 C : Char_Code;
12673
12674 begin
12675 GNAT_Pragma;
12676 Check_No_Identifiers;
12677
12678 -- Two argument form
12679
12680 if Arg_Count = 2 then
12681 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12682
12683 declare
12684 E_Id : Node_Id;
12685 E : Entity_Id;
12686
12687 begin
0f1a6a0b 12688 E_Id := Get_Pragma_Arg (Arg2);
996ae0b0
RK
12689 Analyze (E_Id);
12690
12691 if not Is_Entity_Name (E_Id) then
12692 Error_Pragma_Arg
12693 ("second argument of pragma% must be entity name",
12694 Arg2);
12695 end if;
12696
12697 E := Entity (E_Id);
12698
12699 if E = Any_Id then
12700 return;
12701 else
12702 loop
12703 Set_Suppress_Style_Checks (E,
0f1a6a0b 12704 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
996ae0b0
RK
12705 exit when No (Homonym (E));
12706 E := Homonym (E);
12707 end loop;
12708 end if;
12709 end;
12710
12711 -- One argument form
12712
12713 else
12714 Check_Arg_Count (1);
12715
12716 if Nkind (A) = N_String_Literal then
12717 S := Strval (A);
12718
12719 declare
fbf5a39b 12720 Slen : constant Natural := Natural (String_Length (S));
996ae0b0
RK
12721 Options : String (1 .. Slen);
12722 J : Natural;
12723
12724 begin
12725 J := 1;
12726 loop
12727 C := Get_String_Char (S, Int (J));
12728 exit when not In_Character_Range (C);
12729 Options (J) := Get_Character (C);
12730
c3217dac
RD
12731 -- If at end of string, set options. As per discussion
12732 -- above, no need to check for errors, since we issued
12733 -- them in the parser.
12734
996ae0b0
RK
12735 if J = Slen then
12736 Set_Style_Check_Options (Options);
12737 exit;
996ae0b0 12738 end if;
c3217dac
RD
12739
12740 J := J + 1;
996ae0b0
RK
12741 end loop;
12742 end;
12743
12744 elsif Nkind (A) = N_Identifier then
996ae0b0 12745 if Chars (A) = Name_All_Checks then
19d846a0
RD
12746 if GNAT_Mode then
12747 Set_GNAT_Style_Check_Options;
12748 else
12749 Set_Default_Style_Check_Options;
12750 end if;
996ae0b0
RK
12751
12752 elsif Chars (A) = Name_On then
12753 Style_Check := True;
12754
12755 elsif Chars (A) = Name_Off then
12756 Style_Check := False;
996ae0b0
RK
12757 end if;
12758 end if;
12759 end if;
12760 end Style_Checks;
12761
12762 --------------
12763 -- Subtitle --
12764 --------------
12765
12766 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12767
12768 when Pragma_Subtitle =>
12769 GNAT_Pragma;
12770 Check_Arg_Count (1);
12771 Check_Optional_Identifier (Arg1, Name_Subtitle);
7eaa7cdf
RD
12772 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12773 Store_Note (N);
996ae0b0
RK
12774
12775 --------------
12776 -- Suppress --
12777 --------------
12778
12779 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12780
12781 when Pragma_Suppress =>
12782 Process_Suppress_Unsuppress (True);
12783
12784 ------------------
12785 -- Suppress_All --
12786 ------------------
12787
12788 -- pragma Suppress_All;
12789
c775c209
AC
12790 -- The only check made here is that the pragma has no arguments.
12791 -- There are no placement rules, and the processing required (setting
12792 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
12793 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
12794 -- then creates and inserts a pragma Suppress (All_Checks).
996ae0b0
RK
12795
12796 when Pragma_Suppress_All =>
12797 GNAT_Pragma;
12798 Check_Arg_Count (0);
12799
996ae0b0
RK
12800 -------------------------
12801 -- Suppress_Debug_Info --
12802 -------------------------
12803
12804 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12805
12806 when Pragma_Suppress_Debug_Info =>
12807 GNAT_Pragma;
12808 Check_Arg_Count (1);
996ae0b0 12809 Check_Optional_Identifier (Arg1, Name_Entity);
59e5fbe0 12810 Check_Arg_Is_Local_Name (Arg1);
eaba57fb 12811 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
996ae0b0 12812
fbf5a39b
AC
12813 ----------------------------------
12814 -- Suppress_Exception_Locations --
12815 ----------------------------------
12816
12817 -- pragma Suppress_Exception_Locations;
12818
12819 when Pragma_Suppress_Exception_Locations =>
12820 GNAT_Pragma;
12821 Check_Arg_Count (0);
12822 Check_Valid_Configuration_Pragma;
12823 Exception_Locations_Suppressed := True;
12824
996ae0b0
RK
12825 -----------------------------
12826 -- Suppress_Initialization --
12827 -----------------------------
12828
12829 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12830
12831 when Pragma_Suppress_Initialization => Suppress_Init : declare
12832 E_Id : Node_Id;
12833 E : Entity_Id;
12834
12835 begin
12836 GNAT_Pragma;
12837 Check_Arg_Count (1);
12838 Check_Optional_Identifier (Arg1, Name_Entity);
12839 Check_Arg_Is_Local_Name (Arg1);
12840
0f1a6a0b 12841 E_Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
12842
12843 if Etype (E_Id) = Any_Type then
12844 return;
12845 end if;
12846
12847 E := Entity (E_Id);
12848
12849 if Is_Type (E) then
12850 if Is_Incomplete_Or_Private_Type (E) then
12851 if No (Full_View (Base_Type (E))) then
12852 Error_Pragma_Arg
12853 ("argument of pragma% cannot be an incomplete type",
12854 Arg1);
12855 else
12856 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
12857 end if;
12858 else
12859 Set_Suppress_Init_Proc (Base_Type (E));
12860 end if;
12861
12862 else
12863 Error_Pragma_Arg
12864 ("pragma% requires argument that is a type name", Arg1);
12865 end if;
12866 end Suppress_Init;
12867
12868 -----------------
12869 -- System_Name --
12870 -----------------
12871
12872 -- pragma System_Name (DIRECT_NAME);
12873
b3b9865d
AC
12874 -- Syntax check: one argument, which must be the identifier GNAT or
12875 -- the identifier GCC, no other identifiers are acceptable.
996ae0b0
RK
12876
12877 when Pragma_System_Name =>
a30a01fe 12878 GNAT_Pragma;
996ae0b0
RK
12879 Check_No_Identifiers;
12880 Check_Arg_Count (1);
12881 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12882
12883 -----------------------------
12884 -- Task_Dispatching_Policy --
12885 -----------------------------
12886
12887 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12888
12889 when Pragma_Task_Dispatching_Policy => declare
12890 DP : Character;
12891
12892 begin
12893 Check_Ada_83_Warning;
12894 Check_Arg_Count (1);
12895 Check_No_Identifiers;
12896 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12897 Check_Valid_Configuration_Pragma;
0f1a6a0b 12898 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
996ae0b0
RK
12899 DP := Fold_Upper (Name_Buffer (1));
12900
12901 if Task_Dispatching_Policy /= ' '
12902 and then Task_Dispatching_Policy /= DP
12903 then
12904 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12905 Error_Pragma
12906 ("task dispatching policy incompatible with policy#");
fbf5a39b 12907
b3b9865d
AC
12908 -- Set new policy, but always preserve System_Location since we
12909 -- like the error message with the run time name.
fbf5a39b 12910
996ae0b0
RK
12911 else
12912 Task_Dispatching_Policy := DP;
fbf5a39b
AC
12913
12914 if Task_Dispatching_Policy_Sloc /= System_Location then
12915 Task_Dispatching_Policy_Sloc := Loc;
12916 end if;
996ae0b0
RK
12917 end if;
12918 end;
12919
12920 --------------
12921 -- Task_Info --
12922 --------------
12923
12924 -- pragma Task_Info (EXPRESSION);
12925
12926 when Pragma_Task_Info => Task_Info : declare
12927 P : constant Node_Id := Parent (N);
12928
12929 begin
12930 GNAT_Pragma;
12931
12932 if Nkind (P) /= N_Task_Definition then
12933 Error_Pragma ("pragma% must appear in task definition");
12934 end if;
12935
12936 Check_No_Identifiers;
12937 Check_Arg_Count (1);
12938
0f1a6a0b
AC
12939 Analyze_And_Resolve
12940 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
996ae0b0 12941
0f1a6a0b 12942 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
996ae0b0
RK
12943 return;
12944 end if;
12945
12946 if Has_Task_Info_Pragma (P) then
12947 Error_Pragma ("duplicate pragma% not allowed");
12948 else
12949 Set_Has_Task_Info_Pragma (P, True);
12950 end if;
996ae0b0
RK
12951 end Task_Info;
12952
12953 ---------------
12954 -- Task_Name --
12955 ---------------
12956
12957 -- pragma Task_Name (string_EXPRESSION);
12958
12959 when Pragma_Task_Name => Task_Name : declare
996ae0b0
RK
12960 P : constant Node_Id := Parent (N);
12961 Arg : Node_Id;
12962
12963 begin
12964 Check_No_Identifiers;
12965 Check_Arg_Count (1);
12966
0f1a6a0b 12967 Arg := Get_Pragma_Arg (Arg1);
4017021b 12968
b3b9865d 12969 -- The expression is used in the call to Create_Task, and must be
c5326593
ES
12970 -- expanded there, not in the context of the current spec. It must
12971 -- however be analyzed to capture global references, in case it
12972 -- appears in a generic context.
4017021b 12973
c5326593 12974 Preanalyze_And_Resolve (Arg, Standard_String);
996ae0b0
RK
12975
12976 if Nkind (P) /= N_Task_Definition then
12977 Pragma_Misplaced;
12978 end if;
12979
12980 if Has_Task_Name_Pragma (P) then
12981 Error_Pragma ("duplicate pragma% not allowed");
12982 else
12983 Set_Has_Task_Name_Pragma (P, True);
12984 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12985 end if;
996ae0b0
RK
12986 end Task_Name;
12987
12988 ------------------
12989 -- Task_Storage --
12990 ------------------
12991
12992 -- pragma Task_Storage (
12993 -- [Task_Type =>] LOCAL_NAME,
12994 -- [Top_Guard =>] static_integer_EXPRESSION);
12995
12996 when Pragma_Task_Storage => Task_Storage : declare
12997 Args : Args_List (1 .. 2);
fbf5a39b 12998 Names : constant Name_List (1 .. 2) := (
996ae0b0
RK
12999 Name_Task_Type,
13000 Name_Top_Guard);
13001
13002 Task_Type : Node_Id renames Args (1);
13003 Top_Guard : Node_Id renames Args (2);
13004
13005 Ent : Entity_Id;
13006
13007 begin
13008 GNAT_Pragma;
13009 Gather_Associations (Names, Args);
fbf5a39b
AC
13010
13011 if No (Task_Type) then
13012 Error_Pragma
13013 ("missing task_type argument for pragma%");
13014 end if;
13015
996ae0b0
RK
13016 Check_Arg_Is_Local_Name (Task_Type);
13017
13018 Ent := Entity (Task_Type);
13019
13020 if not Is_Task_Type (Ent) then
13021 Error_Pragma_Arg
13022 ("argument for pragma% must be task type", Task_Type);
13023 end if;
13024
13025 if No (Top_Guard) then
13026 Error_Pragma_Arg
13027 ("pragma% takes two arguments", Task_Type);
13028 else
13029 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13030 end if;
13031
13032 Check_First_Subtype (Task_Type);
13033
13034 if Rep_Item_Too_Late (Ent, N) then
13035 raise Pragma_Exit;
13036 end if;
996ae0b0
RK
13037 end Task_Storage;
13038
4c8a5bb8
AC
13039 --------------------------
13040 -- Thread_Local_Storage --
13041 --------------------------
13042
13043 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13044
13045 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13046 Id : Node_Id;
13047 E : Entity_Id;
13048
13049 begin
13050 GNAT_Pragma;
13051 Check_Arg_Count (1);
13052 Check_Optional_Identifier (Arg1, Name_Entity);
812f574f 13053 Check_Arg_Is_Library_Level_Local_Name (Arg1);
4c8a5bb8 13054
0f1a6a0b 13055 Id := Get_Pragma_Arg (Arg1);
4c8a5bb8
AC
13056 Analyze (Id);
13057
13058 if not Is_Entity_Name (Id)
13059 or else Ekind (Entity (Id)) /= E_Variable
13060 then
13061 Error_Pragma_Arg ("local variable name required", Arg1);
13062 end if;
13063
13064 E := Entity (Id);
13065
13066 if Rep_Item_Too_Early (E, N)
13067 or else Rep_Item_Too_Late (E, N)
13068 then
13069 raise Pragma_Exit;
13070 end if;
13071
13072 Set_Has_Pragma_Thread_Local_Storage (E);
812f574f 13073 Set_Has_Gigi_Rep_Item (E);
4c8a5bb8
AC
13074 end Thread_Local_Storage;
13075
996ae0b0
RK
13076 ----------------
13077 -- Time_Slice --
13078 ----------------
13079
13080 -- pragma Time_Slice (static_duration_EXPRESSION);
13081
13082 when Pragma_Time_Slice => Time_Slice : declare
13083 Val : Ureal;
13084 Nod : Node_Id;
13085
13086 begin
13087 GNAT_Pragma;
13088 Check_Arg_Count (1);
13089 Check_No_Identifiers;
13090 Check_In_Main_Program;
13091 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13092
13093 if not Error_Posted (Arg1) then
13094 Nod := Next (N);
13095 while Present (Nod) loop
13096 if Nkind (Nod) = N_Pragma
1b24ada5 13097 and then Pragma_Name (Nod) = Name_Time_Slice
996ae0b0 13098 then
1b24ada5 13099 Error_Msg_Name_1 := Pname;
996ae0b0
RK
13100 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13101 end if;
13102
13103 Next (Nod);
13104 end loop;
13105 end if;
13106
13107 -- Process only if in main unit
13108
13109 if Get_Source_Unit (Loc) = Main_Unit then
13110 Opt.Time_Slice_Set := True;
0f1a6a0b 13111 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
996ae0b0
RK
13112
13113 if Val <= Ureal_0 then
13114 Opt.Time_Slice_Value := 0;
13115
13116 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13117 Opt.Time_Slice_Value := 1_000_000_000;
13118
13119 else
13120 Opt.Time_Slice_Value :=
13121 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13122 end if;
13123 end if;
13124 end Time_Slice;
13125
13126 -----------
13127 -- Title --
13128 -----------
13129
13130 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13131
13132 -- TITLING_OPTION ::=
13133 -- [Title =>] STRING_LITERAL
13134 -- | [Subtitle =>] STRING_LITERAL
13135
13136 when Pragma_Title => Title : declare
13137 Args : Args_List (1 .. 2);
fbf5a39b 13138 Names : constant Name_List (1 .. 2) := (
996ae0b0
RK
13139 Name_Title,
13140 Name_Subtitle);
13141
13142 begin
13143 GNAT_Pragma;
13144 Gather_Associations (Names, Args);
7eaa7cdf 13145 Store_Note (N);
996ae0b0
RK
13146
13147 for J in 1 .. 2 loop
13148 if Present (Args (J)) then
7eaa7cdf 13149 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
996ae0b0
RK
13150 end if;
13151 end loop;
13152 end Title;
13153
13154 ---------------------
13155 -- Unchecked_Union --
13156 ---------------------
13157
13158 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13159
13160 when Pragma_Unchecked_Union => Unchecked_Union : declare
fbf5a39b 13161 Assoc : constant Node_Id := Arg1;
0f1a6a0b 13162 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
996ae0b0
RK
13163 Typ : Entity_Id;
13164 Discr : Entity_Id;
13165 Tdef : Node_Id;
13166 Clist : Node_Id;
13167 Vpart : Node_Id;
13168 Comp : Node_Id;
13169 Variant : Node_Id;
13170
13171 begin
a30a01fe 13172 Ada_2005_Pragma;
996ae0b0
RK
13173 Check_No_Identifiers;
13174 Check_Arg_Count (1);
13175 Check_Arg_Is_Local_Name (Arg1);
13176
13177 Find_Type (Type_Id);
13178 Typ := Entity (Type_Id);
13179
13180 if Typ = Any_Type
13181 or else Rep_Item_Too_Early (Typ, N)
13182 then
13183 return;
13184 else
13185 Typ := Underlying_Type (Typ);
13186 end if;
13187
13188 if Rep_Item_Too_Late (Typ, N) then
13189 return;
13190 end if;
13191
13192 Check_First_Subtype (Arg1);
13193
13194 -- Note remaining cases are references to a type in the current
13195 -- declarative part. If we find an error, we post the error on
13196 -- the relevant type declaration at an appropriate point.
13197
13198 if not Is_Record_Type (Typ) then
13199 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13200 return;
13201
13202 elsif Is_Tagged_Type (Typ) then
13203 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13204 return;
13205
13206 elsif Is_Limited_Type (Typ) then
ed2233dc 13207 Error_Msg_N
996ae0b0 13208 ("Unchecked_Union must not be limited record type", Typ);
fbf5a39b 13209 Explain_Limited_Type (Typ, Typ);
996ae0b0
RK
13210 return;
13211
13212 else
13213 if not Has_Discriminants (Typ) then
ed2233dc 13214 Error_Msg_N
996ae0b0
RK
13215 ("Unchecked_Union must have one discriminant", Typ);
13216 return;
13217 end if;
13218
13219 Discr := First_Discriminant (Typ);
57193e09
TQ
13220 while Present (Discr) loop
13221 if No (Discriminant_Default_Value (Discr)) then
13222 Error_Msg_N
13223 ("Unchecked_Union discriminant must have default value",
13224 Discr);
13225 end if;
0f1a6a0b 13226
57193e09
TQ
13227 Next_Discriminant (Discr);
13228 end loop;
996ae0b0
RK
13229
13230 Tdef := Type_Definition (Declaration_Node (Typ));
13231 Clist := Component_List (Tdef);
13232
5d09245e
AC
13233 Comp := First (Component_Items (Clist));
13234 while Present (Comp) loop
72e9f2b9 13235 Check_Component (Comp, Typ);
5d09245e 13236 Next (Comp);
5d09245e
AC
13237 end loop;
13238
996ae0b0
RK
13239 if No (Clist) or else No (Variant_Part (Clist)) then
13240 Error_Msg_N
13241 ("Unchecked_Union must have variant part",
13242 Tdef);
13243 return;
13244 end if;
13245
13246 Vpart := Variant_Part (Clist);
1d571f3b 13247
996ae0b0
RK
13248 Variant := First (Variants (Vpart));
13249 while Present (Variant) loop
72e9f2b9 13250 Check_Variant (Variant, Typ);
996ae0b0
RK
13251 Next (Variant);
13252 end loop;
13253 end if;
13254
eaba57fb
RD
13255 Set_Is_Unchecked_Union (Typ);
13256 Set_Convention (Typ, Convention_C);
13257 Set_Has_Unchecked_Union (Base_Type (Typ));
13258 Set_Is_Unchecked_Union (Base_Type (Typ));
996ae0b0
RK
13259 end Unchecked_Union;
13260
13261 ------------------------
13262 -- Unimplemented_Unit --
13263 ------------------------
13264
13265 -- pragma Unimplemented_Unit;
13266
b3b9865d
AC
13267 -- Note: this only gives an error if we are generating code, or if
13268 -- we are in a generic library unit (where the pragma appears in the
13269 -- body, not in the spec).
996ae0b0
RK
13270
13271 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
fbf5a39b
AC
13272 Cunitent : constant Entity_Id :=
13273 Cunit_Entity (Get_Source_Unit (Loc));
13274 Ent_Kind : constant Entity_Kind :=
13275 Ekind (Cunitent);
996ae0b0
RK
13276
13277 begin
13278 GNAT_Pragma;
13279 Check_Arg_Count (0);
13280
13281 if Operating_Mode = Generate_Code
13282 or else Ent_Kind = E_Generic_Function
13283 or else Ent_Kind = E_Generic_Procedure
13284 or else Ent_Kind = E_Generic_Package
13285 then
13286 Get_Name_String (Chars (Cunitent));
13287 Set_Casing (Mixed_Case);
13288 Write_Str (Name_Buffer (1 .. Name_Len));
874a0341 13289 Write_Str (" is not supported in this configuration");
996ae0b0
RK
13290 Write_Eol;
13291 raise Unrecoverable_Error;
13292 end if;
13293 end Unimplemented_Unit;
13294
2fa9443e
ES
13295 ------------------------
13296 -- Universal_Aliasing --
13297 ------------------------
13298
13299 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13300
13301 when Pragma_Universal_Aliasing => Universal_Alias : declare
13302 E_Id : Entity_Id;
13303
13304 begin
13305 GNAT_Pragma;
13306 Check_Arg_Count (1);
13307 Check_Optional_Identifier (Arg2, Name_Entity);
13308 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 13309 E_Id := Entity (Get_Pragma_Arg (Arg1));
2fa9443e
ES
13310
13311 if E_Id = Any_Type then
13312 return;
13313 elsif No (E_Id) or else not Is_Type (E_Id) then
13314 Error_Pragma_Arg ("pragma% requires type", Arg1);
13315 end if;
13316
eaba57fb 13317 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
2fa9443e
ES
13318 end Universal_Alias;
13319
07fc65c4
GB
13320 --------------------
13321 -- Universal_Data --
13322 --------------------
13323
fbf5a39b 13324 -- pragma Universal_Data [(library_unit_NAME)];
07fc65c4
GB
13325
13326 when Pragma_Universal_Data =>
13327 GNAT_Pragma;
fbf5a39b
AC
13328
13329 -- If this is a configuration pragma, then set the universal
b3b9865d
AC
13330 -- addressing option, otherwise confirm that the pragma satisfies
13331 -- the requirements of library unit pragma placement and leave it
13332 -- to the GNAAMP back end to detect the pragma (avoids transitive
13333 -- setting of the option due to withed units).
fbf5a39b
AC
13334
13335 if Is_Configuration_Pragma then
13336 Universal_Addressing_On_AAMP := True;
13337 else
13338 Check_Valid_Library_Unit_Pragma;
13339 end if;
07fc65c4
GB
13340
13341 if not AAMP_On_Target then
13342 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13343 end if;
13344
9d77af56
RD
13345 ----------------
13346 -- Unmodified --
13347 ----------------
13348
13349 -- pragma Unmodified (local_Name {, local_Name});
13350
13351 when Pragma_Unmodified => Unmodified : declare
13352 Arg_Node : Node_Id;
13353 Arg_Expr : Node_Id;
13354 Arg_Ent : Entity_Id;
13355
13356 begin
13357 GNAT_Pragma;
13358 Check_At_Least_N_Arguments (1);
13359
13360 -- Loop through arguments
13361
13362 Arg_Node := Arg1;
13363 while Present (Arg_Node) loop
13364 Check_No_Identifier (Arg_Node);
13365
b3b9865d
AC
13366 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13367 -- in fact generate reference, so that the entity will have a
13368 -- reference, which will inhibit any warnings about it not
13369 -- being referenced, and also properly show up in the ali file
13370 -- as a reference. But this reference is recorded before the
13371 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13372 -- generated for this reference.
9d77af56
RD
13373
13374 Check_Arg_Is_Local_Name (Arg_Node);
13375 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13376
13377 if Is_Entity_Name (Arg_Expr) then
13378 Arg_Ent := Entity (Arg_Expr);
13379
13380 if not Is_Assignable (Arg_Ent) then
13381 Error_Pragma_Arg
13382 ("pragma% can only be applied to a variable",
13383 Arg_Expr);
13384 else
eaba57fb 13385 Set_Has_Pragma_Unmodified (Arg_Ent);
9d77af56
RD
13386 end if;
13387 end if;
13388
13389 Next (Arg_Node);
13390 end loop;
13391 end Unmodified;
13392
07fc65c4
GB
13393 ------------------
13394 -- Unreferenced --
13395 ------------------
13396
13397 -- pragma Unreferenced (local_Name {, local_Name});
13398
ac9e9918
RD
13399 -- or when used in a context clause:
13400
13401 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13402
07fc65c4
GB
13403 when Pragma_Unreferenced => Unreferenced : declare
13404 Arg_Node : Node_Id;
13405 Arg_Expr : Node_Id;
fbf5a39b 13406 Arg_Ent : Entity_Id;
ac9e9918 13407 Citem : Node_Id;
07fc65c4
GB
13408
13409 begin
13410 GNAT_Pragma;
13411 Check_At_Least_N_Arguments (1);
13412
ac9e9918 13413 -- Check case of appearing within context clause
07fc65c4 13414
ac9e9918 13415 if Is_In_Context_Clause then
07fc65c4 13416
c690a2ec
RD
13417 -- The arguments must all be units mentioned in a with clause
13418 -- in the same context clause. Note we already checked (in
13419 -- Par.Prag) that the arguments are either identifiers or
13420 -- selected components.
07fc65c4 13421
ac9e9918
RD
13422 Arg_Node := Arg1;
13423 while Present (Arg_Node) loop
13424 Citem := First (List_Containing (N));
13425 while Citem /= N loop
13426 if Nkind (Citem) = N_With_Clause
0f1a6a0b
AC
13427 and then
13428 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
ac9e9918
RD
13429 then
13430 Set_Has_Pragma_Unreferenced
13431 (Cunit_Entity
13432 (Get_Source_Unit
13433 (Library_Unit (Citem))));
0f1a6a0b
AC
13434 Set_Unit_Name
13435 (Get_Pragma_Arg (Arg_Node), Name (Citem));
ac9e9918
RD
13436 exit;
13437 end if;
fbf5a39b 13438
ac9e9918
RD
13439 Next (Citem);
13440 end loop;
fbf5a39b 13441
ac9e9918
RD
13442 if Citem = N then
13443 Error_Pragma_Arg
13444 ("argument of pragma% is not with'ed unit", Arg_Node);
fbf5a39b
AC
13445 end if;
13446
ac9e9918
RD
13447 Next (Arg_Node);
13448 end loop;
07fc65c4 13449
ac9e9918
RD
13450 -- Case of not in list of context items
13451
13452 else
13453 Arg_Node := Arg1;
13454 while Present (Arg_Node) loop
13455 Check_No_Identifier (Arg_Node);
13456
13457 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13458 -- will in fact generate reference, so that the entity will
13459 -- have a reference, which will inhibit any warnings about
13460 -- it not being referenced, and also properly show up in the
13461 -- ali file as a reference. But this reference is recorded
13462 -- before the Has_Pragma_Unreferenced flag is set, so that
13463 -- no warning is generated for this reference.
13464
13465 Check_Arg_Is_Local_Name (Arg_Node);
13466 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13467
13468 if Is_Entity_Name (Arg_Expr) then
13469 Arg_Ent := Entity (Arg_Expr);
13470
13471 -- If the entity is overloaded, the pragma applies to the
13472 -- most recent overloading, as documented. In this case,
13473 -- name resolution does not generate a reference, so it
13474 -- must be done here explicitly.
13475
13476 if Is_Overloaded (Arg_Expr) then
13477 Generate_Reference (Arg_Ent, N);
13478 end if;
13479
eaba57fb 13480 Set_Has_Pragma_Unreferenced (Arg_Ent);
ac9e9918
RD
13481 end if;
13482
13483 Next (Arg_Node);
13484 end loop;
13485 end if;
07fc65c4
GB
13486 end Unreferenced;
13487
874a0341
RD
13488 --------------------------
13489 -- Unreferenced_Objects --
13490 --------------------------
13491
13492 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13493
13494 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13495 Arg_Node : Node_Id;
13496 Arg_Expr : Node_Id;
13497
13498 begin
13499 GNAT_Pragma;
13500 Check_At_Least_N_Arguments (1);
13501
13502 Arg_Node := Arg1;
13503 while Present (Arg_Node) loop
13504 Check_No_Identifier (Arg_Node);
13505 Check_Arg_Is_Local_Name (Arg_Node);
13506 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13507
13508 if not Is_Entity_Name (Arg_Expr)
13509 or else not Is_Type (Entity (Arg_Expr))
13510 then
13511 Error_Pragma_Arg
13512 ("argument for pragma% must be type or subtype", Arg_Node);
13513 end if;
13514
eaba57fb 13515 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
874a0341
RD
13516 Next (Arg_Node);
13517 end loop;
13518 end Unreferenced_Objects;
13519
996ae0b0
RK
13520 ------------------------------
13521 -- Unreserve_All_Interrupts --
13522 ------------------------------
13523
13524 -- pragma Unreserve_All_Interrupts;
13525
13526 when Pragma_Unreserve_All_Interrupts =>
13527 GNAT_Pragma;
13528 Check_Arg_Count (0);
13529
13530 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13531 Unreserve_All_Interrupts := True;
13532 end if;
13533
13534 ----------------
13535 -- Unsuppress --
13536 ----------------
13537
13538 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13539
13540 when Pragma_Unsuppress =>
a30a01fe 13541 Ada_2005_Pragma;
996ae0b0
RK
13542 Process_Suppress_Unsuppress (False);
13543
13544 -------------------
13545 -- Use_VADS_Size --
13546 -------------------
13547
13548 -- pragma Use_VADS_Size;
13549
13550 when Pragma_Use_VADS_Size =>
13551 GNAT_Pragma;
13552 Check_Arg_Count (0);
13553 Check_Valid_Configuration_Pragma;
13554 Use_VADS_Size := True;
13555
13556 ---------------------
13557 -- Validity_Checks --
13558 ---------------------
13559
13560 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13561
13562 when Pragma_Validity_Checks => Validity_Checks : declare
0f1a6a0b 13563 A : constant Node_Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
13564 S : String_Id;
13565 C : Char_Code;
13566
13567 begin
13568 GNAT_Pragma;
13569 Check_Arg_Count (1);
996ae0b0
RK
13570 Check_No_Identifiers;
13571
13572 if Nkind (A) = N_String_Literal then
13573 S := Strval (A);
13574
13575 declare
fbf5a39b 13576 Slen : constant Natural := Natural (String_Length (S));
996ae0b0
RK
13577 Options : String (1 .. Slen);
13578 J : Natural;
13579
13580 begin
13581 J := 1;
13582 loop
13583 C := Get_String_Char (S, Int (J));
13584 exit when not In_Character_Range (C);
13585 Options (J) := Get_Character (C);
13586
13587 if J = Slen then
13588 Set_Validity_Check_Options (Options);
13589 exit;
13590 else
13591 J := J + 1;
13592 end if;
13593 end loop;
13594 end;
13595
13596 elsif Nkind (A) = N_Identifier then
13597
13598 if Chars (A) = Name_All_Checks then
13599 Set_Validity_Check_Options ("a");
13600
13601 elsif Chars (A) = Name_On then
13602 Validity_Checks_On := True;
13603
13604 elsif Chars (A) = Name_Off then
13605 Validity_Checks_On := False;
13606
13607 end if;
13608 end if;
13609 end Validity_Checks;
13610
13611 --------------
13612 -- Volatile --
13613 --------------
13614
13615 -- pragma Volatile (LOCAL_NAME);
13616
13617 when Pragma_Volatile =>
13618 Process_Atomic_Shared_Volatile;
13619
13620 -------------------------
13621 -- Volatile_Components --
13622 -------------------------
13623
13624 -- pragma Volatile_Components (array_LOCAL_NAME);
13625
13626 -- Volatile is handled by the same circuit as Atomic_Components
13627
13628 --------------
13629 -- Warnings --
13630 --------------
13631
ac9e9918
RD
13632 -- pragma Warnings (On | Off);
13633 -- pragma Warnings (On | Off, LOCAL_NAME);
f02b8bb8 13634 -- pragma Warnings (static_string_EXPRESSION);
ac9e9918 13635 -- pragma Warnings (On | Off, STRING_LITERAL);
996ae0b0 13636
fbf5a39b 13637 when Pragma_Warnings => Warnings : begin
996ae0b0
RK
13638 GNAT_Pragma;
13639 Check_At_Least_N_Arguments (1);
996ae0b0
RK
13640 Check_No_Identifiers;
13641
cca5ded0
AC
13642 -- If debug flag -gnatd.i is set, pragma is ignored
13643
13644 if Debug_Flag_Dot_I then
13645 return;
13646 end if;
13647
13648 -- Process various forms of the pragma
13649
ac9e9918
RD
13650 declare
13651 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
996ae0b0 13652
ac9e9918
RD
13653 begin
13654 -- One argument case
13655
13656 if Arg_Count = 1 then
f02b8bb8 13657
f02b8bb8
RD
13658 -- On/Off one argument case was processed by parser
13659
13660 if Nkind (Argx) = N_Identifier
13661 and then
13662 (Chars (Argx) = Name_On
13663 or else
13664 Chars (Argx) = Name_Off)
13665 then
13666 null;
13667
ac9e9918
RD
13668 -- One argument case must be ON/OFF or static string expr
13669
13670 elsif not Is_Static_String_Expression (Arg1) then
13671 Error_Pragma_Arg
13672 ("argument of pragma% must be On/Off or " &
6e1ee5c3 13673 "static string expression", Arg1);
f02b8bb8 13674
ac9e9918
RD
13675 -- One argument string expression case
13676
13677 else
f02b8bb8
RD
13678 declare
13679 Lit : constant Node_Id := Expr_Value_S (Argx);
13680 Str : constant String_Id := Strval (Lit);
874a0341 13681 Len : constant Nat := String_Length (Str);
f02b8bb8 13682 C : Char_Code;
874a0341
RD
13683 J : Nat;
13684 OK : Boolean;
13685 Chr : Character;
f02b8bb8
RD
13686
13687 begin
874a0341
RD
13688 J := 1;
13689 while J <= Len loop
f02b8bb8 13690 C := Get_String_Char (Str, J);
874a0341 13691 OK := In_Character_Range (C);
f02b8bb8 13692
874a0341
RD
13693 if OK then
13694 Chr := Get_Character (C);
13695
13696 -- Dot case
13697
13698 if J < Len and then Chr = '.' then
13699 J := J + 1;
13700 C := Get_String_Char (Str, J);
13701 Chr := Get_Character (C);
13702
13703 if not Set_Dot_Warning_Switch (Chr) then
13704 Error_Pragma_Arg
13705 ("invalid warning switch character " &
13706 '.' & Chr, Arg1);
13707 end if;
13708
13709 -- Non-Dot case
13710
13711 else
13712 OK := Set_Warning_Switch (Chr);
13713 end if;
13714 end if;
13715
13716 if not OK then
f02b8bb8 13717 Error_Pragma_Arg
874a0341
RD
13718 ("invalid warning switch character " & Chr,
13719 Arg1);
f02b8bb8 13720 end if;
874a0341
RD
13721
13722 J := J + 1;
f02b8bb8
RD
13723 end loop;
13724 end;
13725 end if;
f02b8bb8 13726
ac9e9918 13727 -- Two or more arguments (must be two)
f02b8bb8 13728
ac9e9918
RD
13729 else
13730 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13731 Check_At_Most_N_Arguments (2);
996ae0b0 13732
ac9e9918
RD
13733 declare
13734 E_Id : Node_Id;
13735 E : Entity_Id;
13736 Err : Boolean;
996ae0b0 13737
ac9e9918 13738 begin
0f1a6a0b 13739 E_Id := Get_Pragma_Arg (Arg2);
ac9e9918 13740 Analyze (E_Id);
996ae0b0 13741
ac9e9918
RD
13742 -- In the expansion of an inlined body, a reference to
13743 -- the formal may be wrapped in a conversion if the
13744 -- actual is a conversion. Retrieve the real entity name.
5b4994bc 13745
ac9e9918
RD
13746 if (In_Instance_Body
13747 or else In_Inlined_Body)
13748 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13749 then
13750 E_Id := Expression (E_Id);
13751 end if;
efdfd311 13752
ac9e9918 13753 -- Entity name case
996ae0b0 13754
ac9e9918
RD
13755 if Is_Entity_Name (E_Id) then
13756 E := Entity (E_Id);
996ae0b0 13757
ac9e9918
RD
13758 if E = Any_Id then
13759 return;
13760 else
13761 loop
13762 Set_Warnings_Off
0f1a6a0b
AC
13763 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13764 Name_Off));
ac9e9918 13765
0f1a6a0b 13766 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
1b24ada5
RD
13767 and then Warn_On_Warnings_Off
13768 then
13769 Warnings_Off_Pragmas.Append ((N, E));
13770 end if;
13771
ac9e9918
RD
13772 if Is_Enumeration_Type (E) then
13773 declare
13774 Lit : Entity_Id;
13775 begin
13776 Lit := First_Literal (E);
13777 while Present (Lit) loop
13778 Set_Warnings_Off (Lit);
13779 Next_Literal (Lit);
13780 end loop;
13781 end;
13782 end if;
13783
13784 exit when No (Homonym (E));
13785 E := Homonym (E);
13786 end loop;
996ae0b0
RK
13787 end if;
13788
ac9e9918 13789 -- Error if not entity or static string literal case
f02b8bb8 13790
ac9e9918
RD
13791 elsif not Is_Static_String_Expression (Arg2) then
13792 Error_Pragma_Arg
13793 ("second argument of pragma% must be entity " &
13794 "name or static string expression", Arg2);
13795
13796 -- String literal case
13797
13798 else
13799 String_To_Name_Buffer
0f1a6a0b 13800 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
ac9e9918 13801
c690a2ec
RD
13802 -- Note on configuration pragma case: If this is a
13803 -- configuration pragma, then for an OFF pragma, we
13804 -- just set Config True in the call, which is all
13805 -- that needs to be done. For the case of ON, this
13806 -- is normally an error, unless it is canceling the
13807 -- effect of a previous OFF pragma in the same file.
13808 -- In any other case, an error will be signalled (ON
13809 -- with no matching OFF).
13810
13811 if Chars (Argx) = Name_Off then
13812 Set_Specific_Warning_Off
13813 (Loc, Name_Buffer (1 .. Name_Len),
13814 Config => Is_Configuration_Pragma);
13815
13816 elsif Chars (Argx) = Name_On then
13817 Set_Specific_Warning_On
13818 (Loc, Name_Buffer (1 .. Name_Len), Err);
13819
13820 if Err then
13821 Error_Msg
13822 ("?pragma Warnings On with no " &
13823 "matching Warnings Off",
13824 Loc);
ac9e9918
RD
13825 end if;
13826 end if;
13827 end if;
13828 end;
13829 end if;
13830 end;
fbf5a39b 13831 end Warnings;
996ae0b0
RK
13832
13833 -------------------
13834 -- Weak_External --
13835 -------------------
13836
13837 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13838
13839 when Pragma_Weak_External => Weak_External : declare
13840 Ent : Entity_Id;
13841
13842 begin
13843 GNAT_Pragma;
13844 Check_Arg_Count (1);
13845 Check_Optional_Identifier (Arg1, Name_Entity);
13846 Check_Arg_Is_Library_Level_Local_Name (Arg1);
0f1a6a0b 13847 Ent := Entity (Get_Pragma_Arg (Arg1));
996ae0b0
RK
13848
13849 if Rep_Item_Too_Early (Ent, N) then
13850 return;
13851 else
13852 Ent := Underlying_Type (Ent);
13853 end if;
13854
13855 -- The only processing required is to link this item on to the
13856 -- list of rep items for the given entity. This is accomplished
13857 -- by the call to Rep_Item_Too_Late (when no error is detected
13858 -- and False is returned).
13859
13860 if Rep_Item_Too_Late (Ent, N) then
13861 return;
13862 else
13863 Set_Has_Gigi_Rep_Item (Ent);
13864 end if;
13865 end Weak_External;
13866
ac9e9918
RD
13867 -----------------------------
13868 -- Wide_Character_Encoding --
13869 -----------------------------
13870
13871 -- pragma Wide_Character_Encoding (IDENTIFIER);
13872
13873 when Pragma_Wide_Character_Encoding =>
a30a01fe 13874 GNAT_Pragma;
ac9e9918
RD
13875
13876 -- Nothing to do, handled in parser. Note that we do not enforce
13877 -- configuration pragma placement, this pragma can appear at any
13878 -- place in the source, allowing mixed encodings within a single
13879 -- source program.
13880
13881 null;
13882
fbf5a39b
AC
13883 --------------------
13884 -- Unknown_Pragma --
13885 --------------------
13886
13887 -- Should be impossible, since the case of an unknown pragma is
13888 -- separately processed before the case statement is entered.
13889
13890 when Unknown_Pragma =>
13891 raise Program_Error;
996ae0b0
RK
13892 end case;
13893
6e1ee5c3
AC
13894 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13895 -- until AI is formally approved.
13896
13897 -- Check_Order_Dependence;
13898
996ae0b0
RK
13899 exception
13900 when Pragma_Exit => null;
996ae0b0
RK
13901 end Analyze_Pragma;
13902
21d27997
RD
13903 -------------------
13904 -- Check_Enabled --
13905 -------------------
13906
13907 function Check_Enabled (Nam : Name_Id) return Boolean is
13908 PP : Node_Id;
13909
13910 begin
8110ee3b
RD
13911 -- Loop through entries in check policy list
13912
21d27997
RD
13913 PP := Opt.Check_Policy_List;
13914 loop
8110ee3b
RD
13915 -- If there are no specific entries that matched, then we let the
13916 -- setting of assertions govern. Note that this provides the needed
13917 -- compatibility with the RM for the cases of assertion, invariant,
13918 -- precondition, predicate, and postcondition.
13919
21d27997
RD
13920 if No (PP) then
13921 return Assertions_Enabled;
13922
8110ee3b 13923 -- Here we have an entry see if it matches
21d27997
RD
13924
13925 else
8110ee3b
RD
13926 declare
13927 PPA : constant List_Id := Pragma_Argument_Associations (PP);
13928
13929 begin
13930 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13931 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13932 when Name_On | Name_Check =>
13933 return True;
13934 when Name_Off | Name_Ignore =>
13935 return False;
13936 when others =>
13937 raise Program_Error;
13938 end case;
13939
13940 else
13941 PP := Next_Pragma (PP);
13942 end if;
13943 end;
21d27997
RD
13944 end if;
13945 end loop;
13946 end Check_Enabled;
13947
fbf5a39b
AC
13948 ---------------------------------
13949 -- Delay_Config_Pragma_Analyze --
13950 ---------------------------------
13951
13952 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13953 begin
1b24ada5 13954 return Pragma_Name (N) = Name_Interrupt_State
ac9e9918 13955 or else
1b24ada5 13956 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
fbf5a39b
AC
13957 end Delay_Config_Pragma_Analyze;
13958
996ae0b0
RK
13959 -------------------------
13960 -- Get_Base_Subprogram --
13961 -------------------------
13962
13963 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13964 Result : Entity_Id;
13965
13966 begin
996ae0b0
RK
13967 -- Follow subprogram renaming chain
13968
1d571f3b 13969 Result := Def_Id;
996ae0b0
RK
13970 while Is_Subprogram (Result)
13971 and then
13972 (Is_Generic_Instance (Result)
13973 or else Nkind (Parent (Declaration_Node (Result))) =
d7ba4df4 13974 N_Subprogram_Renaming_Declaration)
996ae0b0
RK
13975 and then Present (Alias (Result))
13976 loop
13977 Result := Alias (Result);
13978 end loop;
13979
13980 return Result;
13981 end Get_Base_Subprogram;
13982
21d27997
RD
13983 ----------------
13984 -- Initialize --
13985 ----------------
13986
13987 procedure Initialize is
13988 begin
13989 Externals.Init;
13990 end Initialize;
13991
5950a3ac
AC
13992 -----------------------------
13993 -- Is_Config_Static_String --
13994 -----------------------------
13995
13996 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13997
13998 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
b3b9865d
AC
13999 -- This is an internal recursive function that is just like the outer
14000 -- function except that it adds the string to the name buffer rather
14001 -- than placing the string in the name buffer.
5950a3ac
AC
14002
14003 ------------------------------
14004 -- Add_Config_Static_String --
14005 ------------------------------
14006
14007 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14008 N : Node_Id;
14009 C : Char_Code;
14010
14011 begin
14012 N := Arg;
14013
14014 if Nkind (N) = N_Op_Concat then
14015 if Add_Config_Static_String (Left_Opnd (N)) then
14016 N := Right_Opnd (N);
14017 else
14018 return False;
14019 end if;
14020 end if;
14021
14022 if Nkind (N) /= N_String_Literal then
14023 Error_Msg_N ("string literal expected for pragma argument", N);
14024 return False;
14025
14026 else
14027 for J in 1 .. String_Length (Strval (N)) loop
14028 C := Get_String_Char (Strval (N), J);
14029
14030 if not In_Character_Range (C) then
14031 Error_Msg
14032 ("string literal contains invalid wide character",
14033 Sloc (N) + 1 + Source_Ptr (J));
14034 return False;
14035 end if;
14036
14037 Add_Char_To_Name_Buffer (Get_Character (C));
14038 end loop;
14039 end if;
14040
14041 return True;
14042 end Add_Config_Static_String;
14043
f3d57416 14044 -- Start of processing for Is_Config_Static_String
5950a3ac
AC
14045
14046 begin
8a36a0cc 14047
5950a3ac
AC
14048 Name_Len := 0;
14049 return Add_Config_Static_String (Arg);
14050 end Is_Config_Static_String;
14051
fbf5a39b
AC
14052 -----------------------------------------
14053 -- Is_Non_Significant_Pragma_Reference --
14054 -----------------------------------------
14055
14056 -- This function makes use of the following static table which indicates
95cb33a5 14057 -- whether a given pragma is significant.
fbf5a39b 14058
95cb33a5 14059 -- -1 indicates that references in any argument position are significant
308e6f3a
RW
14060 -- 0 indicates that appearance in any argument is not significant
14061 -- +n indicates that appearance as argument n is significant, but all
95cb33a5
AC
14062 -- other arguments are not significant
14063 -- 99 special processing required (e.g. for pragma Check)
8a36a0cc 14064
21d27997 14065 Sig_Flags : constant array (Pragma_Id) of Int :=
ac9e9918
RD
14066 (Pragma_AST_Entry => -1,
14067 Pragma_Abort_Defer => -1,
14068 Pragma_Ada_83 => -1,
14069 Pragma_Ada_95 => -1,
14070 Pragma_Ada_05 => -1,
14071 Pragma_Ada_2005 => -1,
0eed45bb
AC
14072 Pragma_Ada_12 => -1,
14073 Pragma_Ada_2012 => -1,
ac9e9918
RD
14074 Pragma_All_Calls_Remote => -1,
14075 Pragma_Annotate => -1,
14076 Pragma_Assert => -1,
14077 Pragma_Assertion_Policy => 0,
4351c21b 14078 Pragma_Assume_No_Invalid_Values => 0,
ac9e9918
RD
14079 Pragma_Asynchronous => -1,
14080 Pragma_Atomic => 0,
14081 Pragma_Atomic_Components => 0,
14082 Pragma_Attach_Handler => -1,
21d27997 14083 Pragma_Check => 99,
c690a2ec 14084 Pragma_Check_Name => 0,
21d27997 14085 Pragma_Check_Policy => 0,
2fa9443e 14086 Pragma_CIL_Constructor => -1,
ac9e9918
RD
14087 Pragma_CPP_Class => 0,
14088 Pragma_CPP_Constructor => 0,
14089 Pragma_CPP_Virtual => 0,
14090 Pragma_CPP_Vtable => 0,
8918fe18 14091 Pragma_CPU => -1,
ac9e9918
RD
14092 Pragma_C_Pass_By_Copy => 0,
14093 Pragma_Comment => 0,
14094 Pragma_Common_Object => -1,
874a0341 14095 Pragma_Compile_Time_Error => -1,
ac9e9918 14096 Pragma_Compile_Time_Warning => -1,
2d9ea47f 14097 Pragma_Compiler_Unit => 0,
ac9e9918
RD
14098 Pragma_Complete_Representation => 0,
14099 Pragma_Complex_Representation => 0,
14100 Pragma_Component_Alignment => -1,
14101 Pragma_Controlled => 0,
14102 Pragma_Convention => 0,
14103 Pragma_Convention_Identifier => 0,
14104 Pragma_Debug => -1,
14105 Pragma_Debug_Policy => 0,
19fb051c
AC
14106 Pragma_Default_Value => -1,
14107 Pragma_Default_Component_Value => -1,
ac9e9918 14108 Pragma_Detect_Blocking => -1,
fab2daeb 14109 Pragma_Default_Storage_Pool => -1,
95cb33a5 14110 Pragma_Dimension => -1,
ac9e9918
RD
14111 Pragma_Discard_Names => 0,
14112 Pragma_Elaborate => -1,
14113 Pragma_Elaborate_All => -1,
14114 Pragma_Elaborate_Body => -1,
14115 Pragma_Elaboration_Checks => -1,
14116 Pragma_Eliminate => -1,
ac9e9918
RD
14117 Pragma_Export => -1,
14118 Pragma_Export_Exception => -1,
14119 Pragma_Export_Function => -1,
14120 Pragma_Export_Object => -1,
14121 Pragma_Export_Procedure => -1,
14122 Pragma_Export_Value => -1,
14123 Pragma_Export_Valued_Procedure => -1,
14124 Pragma_Extend_System => -1,
14125 Pragma_Extensions_Allowed => -1,
14126 Pragma_External => -1,
470cd9e9 14127 Pragma_Favor_Top_Level => -1,
ac9e9918 14128 Pragma_External_Name_Casing => -1,
470cd9e9 14129 Pragma_Fast_Math => -1,
ac9e9918
RD
14130 Pragma_Finalize_Storage_Only => 0,
14131 Pragma_Float_Representation => 0,
14132 Pragma_Ident => -1,
bfae1846 14133 Pragma_Implemented => -1,
c690a2ec 14134 Pragma_Implicit_Packing => 0,
ac9e9918
RD
14135 Pragma_Import => +2,
14136 Pragma_Import_Exception => 0,
14137 Pragma_Import_Function => 0,
14138 Pragma_Import_Object => 0,
14139 Pragma_Import_Procedure => 0,
14140 Pragma_Import_Valued_Procedure => 0,
105b5e65
AC
14141 Pragma_Independent => 0,
14142 Pragma_Independent_Components => 0,
ac9e9918
RD
14143 Pragma_Initialize_Scalars => -1,
14144 Pragma_Inline => 0,
14145 Pragma_Inline_Always => 0,
14146 Pragma_Inline_Generic => 0,
14147 Pragma_Inspection_Point => -1,
14148 Pragma_Interface => +2,
14149 Pragma_Interface_Name => +2,
14150 Pragma_Interrupt_Handler => -1,
14151 Pragma_Interrupt_Priority => -1,
14152 Pragma_Interrupt_State => -1,
e606088a 14153 Pragma_Invariant => -1,
ac9e9918
RD
14154 Pragma_Java_Constructor => -1,
14155 Pragma_Java_Interface => -1,
14156 Pragma_Keep_Names => 0,
14157 Pragma_License => -1,
14158 Pragma_Link_With => -1,
14159 Pragma_Linker_Alias => -1,
14160 Pragma_Linker_Constructor => -1,
14161 Pragma_Linker_Destructor => -1,
14162 Pragma_Linker_Options => -1,
14163 Pragma_Linker_Section => -1,
14164 Pragma_List => -1,
14165 Pragma_Locking_Policy => -1,
14166 Pragma_Long_Float => -1,
14167 Pragma_Machine_Attribute => -1,
14168 Pragma_Main => -1,
14169 Pragma_Main_Storage => -1,
14170 Pragma_Memory_Size => -1,
14171 Pragma_No_Return => 0,
2fa9443e 14172 Pragma_No_Body => 0,
ac9e9918
RD
14173 Pragma_No_Run_Time => -1,
14174 Pragma_No_Strict_Aliasing => -1,
14175 Pragma_Normalize_Scalars => -1,
14176 Pragma_Obsolescent => 0,
14177 Pragma_Optimize => -1,
1b24ada5 14178 Pragma_Optimize_Alignment => -1,
bd29d519 14179 Pragma_Ordered => 0,
ac9e9918
RD
14180 Pragma_Pack => 0,
14181 Pragma_Page => -1,
14182 Pragma_Passive => -1,
14183 Pragma_Preelaborable_Initialization => -1,
14184 Pragma_Polling => -1,
14185 Pragma_Persistent_BSS => 0,
21d27997
RD
14186 Pragma_Postcondition => -1,
14187 Pragma_Precondition => -1,
fd0ff1cf 14188 Pragma_Predicate => -1,
ac9e9918
RD
14189 Pragma_Preelaborate => -1,
14190 Pragma_Preelaborate_05 => -1,
14191 Pragma_Priority => -1,
14192 Pragma_Priority_Specific_Dispatching => -1,
14193 Pragma_Profile => 0,
14194 Pragma_Profile_Warnings => 0,
14195 Pragma_Propagate_Exceptions => -1,
14196 Pragma_Psect_Object => -1,
14197 Pragma_Pure => -1,
14198 Pragma_Pure_05 => -1,
14199 Pragma_Pure_Function => -1,
14200 Pragma_Queuing_Policy => -1,
14201 Pragma_Ravenscar => -1,
21d27997 14202 Pragma_Relative_Deadline => -1,
ac9e9918
RD
14203 Pragma_Remote_Call_Interface => -1,
14204 Pragma_Remote_Types => -1,
14205 Pragma_Restricted_Run_Time => -1,
14206 Pragma_Restriction_Warnings => -1,
14207 Pragma_Restrictions => -1,
14208 Pragma_Reviewable => -1,
6a2afd13 14209 Pragma_Short_Circuit_And_Or => -1,
ac9e9918
RD
14210 Pragma_Share_Generic => -1,
14211 Pragma_Shared => -1,
14212 Pragma_Shared_Passive => -1,
292beb8f 14213 Pragma_Short_Descriptors => 0,
ac9e9918
RD
14214 Pragma_Source_File_Name => -1,
14215 Pragma_Source_File_Name_Project => -1,
14216 Pragma_Source_Reference => -1,
14217 Pragma_Storage_Size => -1,
14218 Pragma_Storage_Unit => -1,
2fa9443e 14219 Pragma_Static_Elaboration_Desired => -1,
ac9e9918
RD
14220 Pragma_Stream_Convert => -1,
14221 Pragma_Style_Checks => -1,
14222 Pragma_Subtitle => -1,
14223 Pragma_Suppress => 0,
14224 Pragma_Suppress_Exception_Locations => 0,
14225 Pragma_Suppress_All => -1,
14226 Pragma_Suppress_Debug_Info => 0,
14227 Pragma_Suppress_Initialization => 0,
14228 Pragma_System_Name => -1,
14229 Pragma_Task_Dispatching_Policy => -1,
14230 Pragma_Task_Info => -1,
14231 Pragma_Task_Name => -1,
14232 Pragma_Task_Storage => 0,
4c8a5bb8 14233 Pragma_Thread_Local_Storage => 0,
ac9e9918
RD
14234 Pragma_Time_Slice => -1,
14235 Pragma_Title => -1,
14236 Pragma_Unchecked_Union => 0,
14237 Pragma_Unimplemented_Unit => -1,
2fa9443e 14238 Pragma_Universal_Aliasing => -1,
ac9e9918 14239 Pragma_Universal_Data => -1,
9d77af56 14240 Pragma_Unmodified => -1,
ac9e9918 14241 Pragma_Unreferenced => -1,
874a0341 14242 Pragma_Unreferenced_Objects => -1,
ac9e9918
RD
14243 Pragma_Unreserve_All_Interrupts => -1,
14244 Pragma_Unsuppress => 0,
14245 Pragma_Use_VADS_Size => -1,
14246 Pragma_Validity_Checks => -1,
14247 Pragma_Volatile => 0,
14248 Pragma_Volatile_Components => 0,
14249 Pragma_Warnings => -1,
14250 Pragma_Weak_External => -1,
14251 Pragma_Wide_Character_Encoding => 0,
14252 Unknown_Pragma => 0);
fbf5a39b
AC
14253
14254 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
21d27997
RD
14255 Id : Pragma_Id;
14256 P : Node_Id;
14257 C : Int;
14258 A : Node_Id;
996ae0b0 14259
996ae0b0 14260 begin
fbf5a39b
AC
14261 P := Parent (N);
14262
14263 if Nkind (P) /= N_Pragma_Argument_Association then
14264 return False;
14265
14266 else
21d27997
RD
14267 Id := Get_Pragma_Id (Parent (P));
14268 C := Sig_Flags (Id);
fbf5a39b
AC
14269
14270 case C is
14271 when -1 =>
14272 return False;
14273
14274 when 0 =>
14275 return True;
14276
21d27997
RD
14277 when 99 =>
14278 case Id is
14279
14280 -- For pragma Check, the first argument is not significant,
14281 -- the second and the third (if present) arguments are
14282 -- significant.
14283
14284 when Pragma_Check =>
14285 return
14286 P = First (Pragma_Argument_Associations (Parent (P)));
14287
14288 when others =>
14289 raise Program_Error;
14290 end case;
14291
fbf5a39b
AC
14292 when others =>
14293 A := First (Pragma_Argument_Associations (Parent (P)));
14294 for J in 1 .. C - 1 loop
14295 if No (A) then
14296 return False;
14297 end if;
14298
14299 Next (A);
14300 end loop;
14301
21d27997 14302 return A = P; -- is this wrong way round ???
fbf5a39b
AC
14303 end case;
14304 end if;
14305 end Is_Non_Significant_Pragma_Reference;
996ae0b0
RK
14306
14307 ------------------------------
14308 -- Is_Pragma_String_Literal --
14309 ------------------------------
14310
b3b9865d
AC
14311 -- This function returns true if the corresponding pragma argument is a
14312 -- static string expression. These are the only cases in which string
14313 -- literals can appear as pragma arguments. We also allow a string literal
14314 -- as the first argument to pragma Assert (although it will of course
14315 -- always generate a type error).
996ae0b0
RK
14316
14317 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14318 Pragn : constant Node_Id := Parent (Par);
14319 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
1b24ada5 14320 Pname : constant Name_Id := Pragma_Name (Pragn);
996ae0b0
RK
14321 Argn : Natural;
14322 N : Node_Id;
14323
14324 begin
14325 Argn := 1;
14326 N := First (Assoc);
14327 loop
14328 exit when N = Par;
14329 Argn := Argn + 1;
14330 Next (N);
14331 end loop;
14332
14333 if Pname = Name_Assert then
14334 return True;
14335
14336 elsif Pname = Name_Export then
14337 return Argn > 2;
14338
14339 elsif Pname = Name_Ident then
14340 return Argn = 1;
14341
14342 elsif Pname = Name_Import then
14343 return Argn > 2;
14344
14345 elsif Pname = Name_Interface_Name then
14346 return Argn > 1;
14347
14348 elsif Pname = Name_Linker_Alias then
14349 return Argn = 2;
14350
14351 elsif Pname = Name_Linker_Section then
14352 return Argn = 2;
14353
14354 elsif Pname = Name_Machine_Attribute then
14355 return Argn = 2;
14356
14357 elsif Pname = Name_Source_File_Name then
14358 return True;
14359
14360 elsif Pname = Name_Source_Reference then
14361 return Argn = 2;
14362
14363 elsif Pname = Name_Title then
14364 return True;
14365
14366 elsif Pname = Name_Subtitle then
14367 return True;
14368
14369 else
14370 return False;
14371 end if;
996ae0b0
RK
14372 end Is_Pragma_String_Literal;
14373
14374 --------------------------------------
14375 -- Process_Compilation_Unit_Pragmas --
14376 --------------------------------------
14377
14378 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14379 begin
b3b9865d 14380 -- A special check for pragma Suppress_All, a very strange DEC pragma,
c775c209
AC
14381 -- strange because it comes at the end of the unit. Rational has the
14382 -- same name for a pragma, but treats it as a program unit pragma, In
14383 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14384 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14385 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14386 -- the context clause to ensure the correct processing.
14387
14388 if Has_Pragma_Suppress_All (N) then
14389 Prepend_To (Context_Items (N),
14390 Make_Pragma (Sloc (N),
14391 Chars => Name_Suppress,
14392 Pragma_Argument_Associations => New_List (
14393 Make_Pragma_Argument_Association (Sloc (N),
7675ad4f 14394 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
c775c209 14395 end if;
996ae0b0 14396
c775c209 14397 -- Nothing else to do at the current time!
996ae0b0 14398
996ae0b0
RK
14399 end Process_Compilation_Unit_Pragmas;
14400
2fa9443e
ES
14401 --------
14402 -- rv --
14403 --------
14404
14405 procedure rv is
14406 begin
14407 null;
14408 end rv;
14409
996ae0b0
RK
14410 --------------------------------
14411 -- Set_Encoded_Interface_Name --
14412 --------------------------------
14413
14414 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14415 Str : constant String_Id := Strval (S);
14416 Len : constant Int := String_Length (Str);
14417 CC : Char_Code;
14418 C : Character;
14419 J : Int;
14420
14421 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14422
14423 procedure Encode;
b3b9865d
AC
14424 -- Stores encoded value of character code CC. The encoding we use an
14425 -- underscore followed by four lower case hex digits.
996ae0b0 14426
2c9beb8a
RD
14427 ------------
14428 -- Encode --
14429 ------------
14430
996ae0b0
RK
14431 procedure Encode is
14432 begin
14433 Store_String_Char (Get_Char_Code ('_'));
14434 Store_String_Char
14435 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14436 Store_String_Char
14437 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14438 Store_String_Char
14439 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14440 Store_String_Char
14441 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14442 end Encode;
14443
14444 -- Start of processing for Set_Encoded_Interface_Name
14445
14446 begin
b3b9865d
AC
14447 -- If first character is asterisk, this is a link name, and we leave it
14448 -- completely unmodified. We also ignore null strings (the latter case
14449 -- happens only in error cases) and no encoding should occur for Java or
14450 -- AAMP interface names.
996ae0b0
RK
14451
14452 if Len = 0
14453 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
2fa9443e
ES
14454 or else VM_Target /= No_VM
14455 or else AAMP_On_Target
996ae0b0
RK
14456 then
14457 Set_Interface_Name (E, S);
14458
14459 else
14460 J := 1;
14461 loop
14462 CC := Get_String_Char (Str, J);
14463
14464 exit when not In_Character_Range (CC);
14465
14466 C := Get_Character (CC);
14467
14468 exit when C /= '_' and then C /= '$'
14469 and then C not in '0' .. '9'
14470 and then C not in 'a' .. 'z'
14471 and then C not in 'A' .. 'Z';
14472
14473 if J = Len then
14474 Set_Interface_Name (E, S);
14475 return;
14476
14477 else
14478 J := J + 1;
14479 end if;
14480 end loop;
14481
14482 -- Here we need to encode. The encoding we use as follows:
14483 -- three underscores + four hex digits (lower case)
14484
14485 Start_String;
14486
14487 for J in 1 .. String_Length (Str) loop
14488 CC := Get_String_Char (Str, J);
14489
14490 if not In_Character_Range (CC) then
14491 Encode;
14492 else
14493 C := Get_Character (CC);
14494
14495 if C = '_' or else C = '$'
14496 or else C in '0' .. '9'
14497 or else C in 'a' .. 'z'
14498 or else C in 'A' .. 'Z'
14499 then
14500 Store_String_Char (CC);
14501 else
14502 Encode;
14503 end if;
14504 end if;
14505 end loop;
14506
14507 Set_Interface_Name (E,
14508 Make_String_Literal (Sloc (S),
14509 Strval => End_String));
14510 end if;
14511 end Set_Encoded_Interface_Name;
14512
14513 -------------------
14514 -- Set_Unit_Name --
14515 -------------------
14516
14517 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14518 Pref : Node_Id;
14519 Scop : Entity_Id;
14520
14521 begin
14522 if Nkind (N) = N_Identifier
14523 and then Nkind (With_Item) = N_Identifier
14524 then
14525 Set_Entity (N, Entity (With_Item));
14526
14527 elsif Nkind (N) = N_Selected_Component then
14528 Change_Selected_Component_To_Expanded_Name (N);
14529 Set_Entity (N, Entity (With_Item));
14530 Set_Entity (Selector_Name (N), Entity (N));
14531
14532 Pref := Prefix (N);
14533 Scop := Scope (Entity (N));
996ae0b0
RK
14534 while Nkind (Pref) = N_Selected_Component loop
14535 Change_Selected_Component_To_Expanded_Name (Pref);
14536 Set_Entity (Selector_Name (Pref), Scop);
14537 Set_Entity (Pref, Scop);
14538 Pref := Prefix (Pref);
14539 Scop := Scope (Scop);
14540 end loop;
14541
14542 Set_Entity (Pref, Scop);
14543 end if;
14544 end Set_Unit_Name;
21d27997 14545
996ae0b0 14546end Sem_Prag;
This page took 5.231326 seconds and 5 git commands to generate.