]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ada/sem_prag.adb
[multiple changes]
[thirdparty/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-- --
e8374e7a 9-- Copyright (C) 1992-2011, 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
e7fceebc 32with Aspects; use Aspects;
ba759acd
AC
33with Atree; use Atree;
34with Casing; use Casing;
35with Checks; use Checks;
36with Csets; use Csets;
37with Debug; use Debug;
38with Einfo; use Einfo;
39with Elists; use Elists;
40with Errout; use Errout;
41with Exp_Dist; use Exp_Dist;
42with Exp_Util; use Exp_Util;
43with Freeze; use Freeze;
44with Lib; use Lib;
45with Lib.Writ; use Lib.Writ;
46with Lib.Xref; use Lib.Xref;
47with Namet.Sp; use Namet.Sp;
48with Nlists; use Nlists;
49with Nmake; use Nmake;
50with Opt; use Opt;
51with Output; use Output;
52with Par_SCO; use Par_SCO;
53with Restrict; use Restrict;
54with Rident; use Rident;
55with Rtsfind; use Rtsfind;
56with Sem; use Sem;
57with Sem_Aux; use Sem_Aux;
58with Sem_Ch3; use Sem_Ch3;
59with Sem_Ch6; use Sem_Ch6;
60with Sem_Ch8; use Sem_Ch8;
61with Sem_Ch12; use Sem_Ch12;
62with Sem_Ch13; use Sem_Ch13;
63with Sem_Disp; use Sem_Disp;
64with Sem_Dist; use Sem_Dist;
65with Sem_Elim; use Sem_Elim;
66with Sem_Eval; use Sem_Eval;
67with Sem_Intr; use Sem_Intr;
68with Sem_Mech; use Sem_Mech;
69with Sem_Res; use Sem_Res;
70with Sem_Type; use Sem_Type;
71with Sem_Util; use Sem_Util;
72with Sem_VFpt; use Sem_VFpt;
73with Sem_Warn; use Sem_Warn;
74with Stand; use Stand;
75with Sinfo; use Sinfo;
76with Sinfo.CN; use Sinfo.CN;
77with Sinput; use Sinput;
78with Snames; use Snames;
79with Stringt; use Stringt;
80with Stylesw; use Stylesw;
523456db 81with Table;
ba759acd
AC
82with Targparm; use Targparm;
83with Tbuild; use Tbuild;
996ae0b0 84with Ttypes;
ba759acd
AC
85with Uintp; use Uintp;
86with Uname; use Uname;
87with Urealp; use Urealp;
88with Validsw; use Validsw;
89with Warnsw; use Warnsw;
996ae0b0
RK
90
91package body Sem_Prag is
92
93 ----------------------------------------------
94 -- Common Handling of Import-Export Pragmas --
95 ----------------------------------------------
96
beacce02
AC
97 -- In the following section, a number of Import_xxx and Export_xxx pragmas
98 -- are defined by GNAT. These are compatible with the DEC pragmas of the
99 -- same name, and all have the following common form and processing:
996ae0b0
RK
100
101 -- pragma Export_xxx
470cd9e9 102 -- [Internal =>] LOCAL_NAME
996ae0b0
RK
103 -- [, [External =>] EXTERNAL_SYMBOL]
104 -- [, other optional parameters ]);
105
106 -- pragma Import_xxx
470cd9e9 107 -- [Internal =>] LOCAL_NAME
996ae0b0
RK
108 -- [, [External =>] EXTERNAL_SYMBOL]
109 -- [, other optional parameters ]);
110
111 -- EXTERNAL_SYMBOL ::=
112 -- IDENTIFIER
113 -- | static_string_EXPRESSION
114
115 -- The internal LOCAL_NAME designates the entity that is imported or
116 -- exported, and must refer to an entity in the current declarative
117 -- part (as required by the rules for LOCAL_NAME).
118
b3b9865d
AC
119 -- The external linker name is designated by the External parameter if
120 -- given, or the Internal parameter if not (if there is no External
996ae0b0
RK
121 -- parameter, the External parameter is a copy of the Internal name).
122
b3b9865d
AC
123 -- If the External parameter is given as a string, then this string is
124 -- treated as an external name (exactly as though it had been given as an
125 -- External_Name parameter for a normal Import pragma).
996ae0b0
RK
126
127 -- If the External parameter is given as an identifier (or there is no
128 -- External parameter, so that the Internal identifier is used), then
129 -- the external name is the characters of the identifier, translated
130 -- to all upper case letters for OpenVMS versions of GNAT, and to all
131 -- lower case letters for all other versions
132
133 -- Note: the external name specified or implied by any of these special
134 -- Import_xxx or Export_xxx pragmas override an external or link name
135 -- specified in a previous Import or Export pragma.
136
b3b9865d
AC
137 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
138 -- named notation, following the standard rules for subprogram calls, i.e.
139 -- parameters can be given in any order if named notation is used, and
140 -- positional and named notation can be mixed, subject to the rule that all
141 -- positional parameters must appear first.
996ae0b0 142
b3b9865d
AC
143 -- Note: All these pragmas are implemented exactly following the DEC design
144 -- and implementation and are intended to be fully compatible with the use
145 -- of these pragmas in the DEC Ada compiler.
996ae0b0 146
523456db
AC
147 --------------------------------------------
148 -- Checking for Duplicated External Names --
149 --------------------------------------------
150
151 -- It is suspicious if two separate Export pragmas use the same external
152 -- name. The following table is used to diagnose this situation so that
153 -- an appropriate warning can be issued.
154
b3b9865d
AC
155 -- The Node_Id stored is for the N_String_Literal node created to hold
156 -- the value of the external name. The Sloc of this node is used to
157 -- cross-reference the location of the duplication.
523456db
AC
158
159 package Externals is new Table.Table (
160 Table_Component_Type => Node_Id,
161 Table_Index_Type => Int,
162 Table_Low_Bound => 0,
163 Table_Initial => 100,
164 Table_Increment => 100,
165 Table_Name => "Name_Externals");
166
996ae0b0
RK
167 -------------------------------------
168 -- Local Subprograms and Variables --
169 -------------------------------------
170
171 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
172 -- This routine is used for possible casing adjustment of an explicit
b3b9865d
AC
173 -- external name supplied as a string literal (the node N), according to
174 -- the casing requirement of Opt.External_Name_Casing. If this is set to
175 -- As_Is, then the string literal is returned unchanged, but if it is set
176 -- to Uppercase or Lowercase, then a new string literal with appropriate
177 -- casing is constructed.
996ae0b0 178
996ae0b0 179 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
b3b9865d
AC
180 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
181 -- original one, following the renaming chain) is returned. Otherwise the
182 -- entity is returned unchanged. Should be in Einfo???
996ae0b0 183
8c18a165 184 procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id);
dac3bede
YM
185 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
186 -- of a Test_Case pragma if present (possibly Empty). We treat these as
187 -- spec expressions (i.e. similar to a default expression).
188
2fa9443e
ES
189 procedure rv;
190 -- This is a dummy function called by the processing for pragma Reviewable.
191 -- It is there for assisting front end debugging. By placing a Reviewable
192 -- pragma in the source program, a breakpoint on rv catches this place in
193 -- the source, allowing convenient stepping to the point of interest.
194
996ae0b0 195 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
b3b9865d
AC
196 -- Place semantic information on the argument of an Elaborate/Elaborate_All
197 -- pragma. Entity name for unit and its parents is taken from item in
198 -- previous with_clause that mentions the unit.
996ae0b0 199
996ae0b0
RK
200 -------------------------------
201 -- Adjust_External_Name_Case --
202 -------------------------------
203
204 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
205 CC : Char_Code;
206
207 begin
208 -- Adjust case of literal if required
209
210 if Opt.External_Name_Exp_Casing = As_Is then
211 return N;
212
213 else
214 -- Copy existing string
215
216 Start_String;
217
218 -- Set proper casing
219
220 for J in 1 .. String_Length (Strval (N)) loop
221 CC := Get_String_Char (Strval (N), J);
222
223 if Opt.External_Name_Exp_Casing = Uppercase
224 and then CC >= Get_Char_Code ('a')
225 and then CC <= Get_Char_Code ('z')
226 then
227 Store_String_Char (CC - 32);
228
229 elsif Opt.External_Name_Exp_Casing = Lowercase
230 and then CC >= Get_Char_Code ('A')
231 and then CC <= Get_Char_Code ('Z')
232 then
233 Store_String_Char (CC + 32);
234
235 else
236 Store_String_Char (CC);
237 end if;
238 end loop;
239
240 return
241 Make_String_Literal (Sloc (N),
242 Strval => End_String);
243 end if;
244 end Adjust_External_Name_Case;
245
21d27997
RD
246 ------------------------------
247 -- Analyze_PPC_In_Decl_Part --
248 ------------------------------
249
250 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
1fb00064 251 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
21d27997
RD
252
253 begin
b3b9865d
AC
254 -- Install formals and push subprogram spec onto scope stack so that we
255 -- can see the formals from the pragma.
21d27997
RD
256
257 Install_Formals (S);
258 Push_Scope (S);
259
b3b9865d
AC
260 -- Preanalyze the boolean expression, we treat this as a spec expression
261 -- (i.e. similar to a default expression).
21d27997 262
8c18a165
AC
263 Preanalyze_Spec_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean);
264
265 -- In ASIS mode, for a pragma generated from a source aspect, also
266 -- analyze the original aspect expression.
267
268 if ASIS_Mode
269 and then Present (Corresponding_Aspect (N))
270 then
271 Preanalyze_Spec_Expression
272 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
273 end if;
21d27997 274
bd603506
RD
275 -- For a class-wide condition, a reference to a controlling formal must
276 -- be interpreted as having the class-wide type (or an access to such)
277 -- so that the inherited condition can be properly applied to any
278 -- overriding operation (see ARM12 6.6.1 (7)).
279
24a120ac
AC
280 if Class_Present (N) then
281 declare
282 T : constant Entity_Id := Find_Dispatching_Type (S);
283
284 ACW : Entity_Id := Empty;
285 -- Access to T'class, created if there is a controlling formal
286 -- that is an access parameter.
287
288 function Get_ACW return Entity_Id;
289 -- If the expression has a reference to an controlling access
290 -- parameter, create an access to T'class for the necessary
291 -- conversions if one does not exist.
292
293 function Process (N : Node_Id) return Traverse_Result;
294 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
295 -- aspect for a primitive subprogram of a tagged type T, a name
296 -- that denotes a formal parameter of type T is interpreted as
297 -- having type T'Class. Similarly, a name that denotes a formal
298 -- accessparameter of type access-to-T is interpreted as having
299 -- type access-to-T'Class. This ensures the expression is well-
300 -- defined for a primitive subprogram of a type descended from T.
301
302 -------------
303 -- Get_ACW --
304 -------------
305
306 function Get_ACW return Entity_Id is
307 Loc : constant Source_Ptr := Sloc (N);
308 Decl : Node_Id;
309
310 begin
311 if No (ACW) then
312 Decl := Make_Full_Type_Declaration (Loc,
313 Defining_Identifier => Make_Temporary (Loc, 'T'),
314 Type_Definition =>
315 Make_Access_To_Object_Definition (Loc,
316 Subtype_Indication =>
317 New_Occurrence_Of (Class_Wide_Type (T), Loc),
318 All_Present => True));
319
320 Insert_Before (Unit_Declaration_Node (S), Decl);
321 Analyze (Decl);
322 ACW := Defining_Identifier (Decl);
323 Freeze_Before (Unit_Declaration_Node (S), ACW);
324 end if;
325
326 return ACW;
327 end Get_ACW;
328
329 -------------
330 -- Process --
331 -------------
332
333 function Process (N : Node_Id) return Traverse_Result is
334 Loc : constant Source_Ptr := Sloc (N);
335 Typ : Entity_Id;
336
337 begin
338 if Is_Entity_Name (N)
339 and then Is_Formal (Entity (N))
340 and then Nkind (Parent (N)) /= N_Type_Conversion
341 then
342 if Etype (Entity (N)) = T then
343 Typ := Class_Wide_Type (T);
344
345 elsif Is_Access_Type (Etype (Entity (N)))
346 and then Designated_Type (Etype (Entity (N))) = T
347 then
348 Typ := Get_ACW;
349 else
350 Typ := Empty;
351 end if;
352
353 if Present (Typ) then
354 Rewrite (N,
355 Make_Type_Conversion (Loc,
356 Subtype_Mark =>
357 New_Occurrence_Of (Typ, Loc),
358 Expression => New_Occurrence_Of (Entity (N), Loc)));
359 Set_Etype (N, Typ);
360 end if;
361 end if;
362
363 return OK;
364 end Process;
365
366 procedure Replace_Type is new Traverse_Proc (Process);
367
368 begin
369 Replace_Type (Get_Pragma_Arg (Arg1));
370 end;
371 end if;
372
b3b9865d
AC
373 -- Remove the subprogram from the scope stack now that the pre-analysis
374 -- of the precondition/postcondition is done.
21d27997
RD
375
376 End_Scope;
377 end Analyze_PPC_In_Decl_Part;
378
996ae0b0
RK
379 --------------------
380 -- Analyze_Pragma --
381 --------------------
382
383 procedure Analyze_Pragma (N : Node_Id) is
384 Loc : constant Source_Ptr := Sloc (N);
385 Prag_Id : Pragma_Id;
386
ba759acd
AC
387 Pname : Name_Id;
388 -- Name of the source pragma, or name of the corresponding aspect for
389 -- pragmas which originate in a source aspect. In the latter case, the
390 -- name may be different from the pragma name.
391
996ae0b0 392 Pragma_Exit : exception;
b3b9865d
AC
393 -- This exception is used to exit pragma processing completely. It is
394 -- used when an error is detected, and no further processing is
395 -- required. It is also used if an earlier error has left the tree in
396 -- a state where the pragma should not be processed.
996ae0b0
RK
397
398 Arg_Count : Nat;
399 -- Number of pragma argument associations
400
401 Arg1 : Node_Id;
402 Arg2 : Node_Id;
403 Arg3 : Node_Id;
404 Arg4 : Node_Id;
b3b9865d
AC
405 -- First four pragma arguments (pragma argument association nodes, or
406 -- Empty if the corresponding argument does not exist).
996ae0b0 407
59e5fbe0
RD
408 type Name_List is array (Natural range <>) of Name_Id;
409 type Args_List is array (Natural range <>) of Node_Id;
410 -- Types used for arguments to Check_Arg_Order and Gather_Associations
411
2fa9443e
ES
412 procedure Ada_2005_Pragma;
413 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
414 -- Ada 95 mode, these are implementation defined pragmas, so should be
bfae1846
AC
415 -- caught by the No_Implementation_Pragmas restriction.
416
417 procedure Ada_2012_Pragma;
418 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
419 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
420 -- should be caught by the No_Implementation_Pragmas restriction.
2fa9443e 421
996ae0b0
RK
422 procedure Check_Ada_83_Warning;
423 -- Issues a warning message for the current pragma if operating in Ada
424 -- 83 mode (used for language pragmas that are not a standard part of
425 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
426 -- of 95 pragma.
427
428 procedure Check_Arg_Count (Required : Nat);
b3b9865d
AC
429 -- Check argument count for pragma is equal to given parameter. If not,
430 -- then issue an error message and raise Pragma_Exit.
996ae0b0 431
b3b9865d
AC
432 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
433 -- Arg which can either be a pragma argument association, in which case
434 -- the check is applied to the expression of the association or an
435 -- expression directly.
996ae0b0 436
cc335f43
AC
437 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
438 -- Check that an argument has the right form for an EXTERNAL_NAME
b3b9865d
AC
439 -- parameter of an extended import/export pragma. The rule is that the
440 -- name must be an identifier or string literal (in Ada 83 mode) or a
441 -- static string expression (in Ada 95 mode).
cc335f43 442
996ae0b0
RK
443 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
444 -- Check the specified argument Arg to make sure that it is an
445 -- identifier. If not give error and raise Pragma_Exit.
446
447 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
b3b9865d
AC
448 -- Check the specified argument Arg to make sure that it is an integer
449 -- literal. If not give error and raise Pragma_Exit.
996ae0b0
RK
450
451 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
b3b9865d
AC
452 -- Check the specified argument Arg to make sure that it has the proper
453 -- syntactic form for a local name and meets the semantic requirements
454 -- for a local name. The local name is analyzed as part of the
455 -- processing for this call. In addition, the local name is required
456 -- to represent an entity at the library level.
996ae0b0
RK
457
458 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
b3b9865d
AC
459 -- Check the specified argument Arg to make sure that it has the proper
460 -- syntactic form for a local name and meets the semantic requirements
461 -- for a local name. The local name is analyzed as part of the
462 -- processing for this call.
996ae0b0
RK
463
464 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
465 -- Check the specified argument Arg to make sure that it is a valid
466 -- locking policy name. If not give error and raise Pragma_Exit.
467
9b3956dd
RD
468 procedure Check_Arg_Is_One_Of
469 (Arg : Node_Id;
470 N1, N2 : Name_Id);
471 procedure Check_Arg_Is_One_Of
472 (Arg : Node_Id;
473 N1, N2, N3 : Name_Id);
474 procedure Check_Arg_Is_One_Of
475 (Arg : Node_Id;
476 N1, N2, N3, N4, N5 : Name_Id);
996ae0b0 477 -- Check the specified argument Arg to make sure that it is an
9b3956dd
RD
478 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
479 -- present). If not then give error and raise Pragma_Exit.
996ae0b0
RK
480
481 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
482 -- Check the specified argument Arg to make sure that it is a valid
483 -- queuing policy name. If not give error and raise Pragma_Exit.
484
485 procedure Check_Arg_Is_Static_Expression
486 (Arg : Node_Id;
d81b4c61 487 Typ : Entity_Id := Empty);
996ae0b0
RK
488 -- Check the specified argument Arg to make sure that it is a static
489 -- expression of the given type (i.e. it will be analyzed and resolved
490 -- using this type, which can be any valid argument to Resolve, e.g.
d81b4c61
RD
491 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
492 -- Typ is left Empty, then any static expression is allowed.
996ae0b0 493
996ae0b0 494 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
b3b9865d
AC
495 -- Check the specified argument Arg to make sure that it is a valid task
496 -- dispatching policy name. If not give error and raise Pragma_Exit.
996ae0b0 497
59e5fbe0
RD
498 procedure Check_Arg_Order (Names : Name_List);
499 -- Checks for an instance of two arguments with identifiers for the
500 -- current pragma which are not in the sequence indicated by Names,
501 -- and if so, generates a fatal message about bad order of arguments.
502
996ae0b0
RK
503 procedure Check_At_Least_N_Arguments (N : Nat);
504 -- Check there are at least N arguments present
505
506 procedure Check_At_Most_N_Arguments (N : Nat);
507 -- Check there are no more than N arguments present
508
72e9f2b9
AC
509 procedure Check_Component
510 (Comp : Node_Id;
511 UU_Typ : Entity_Id;
512 In_Variant_Part : Boolean := False);
513 -- Examine an Unchecked_Union component for correct use of per-object
57193e09 514 -- constrained subtypes, and for restrictions on finalizable components.
72e9f2b9
AC
515 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
516 -- should be set when Comp comes from a record variant.
5d09245e 517
af31bffb
AC
518 procedure Check_Duplicate_Pragma (E : Entity_Id);
519 -- Check if a pragma of the same name as the current pragma is already
c159409f 520 -- chained as a rep pragma to the given entity. If so give a message
0f1a6a0b 521 -- about the duplicate, and then raise Pragma_Exit so does not return.
c159409f 522 -- Also checks for delayed aspect specification node in the chain.
af31bffb 523
523456db 524 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
b3b9865d
AC
525 -- Nam is an N_String_Literal node containing the external name set by
526 -- an Import or Export pragma (or extended Import or Export pragma).
527 -- This procedure checks for possible duplications if this is the export
528 -- case, and if found, issues an appropriate error message.
523456db 529
8c18a165 530 procedure Check_Expr_Is_Static_Expression
4c318253 531 (Expr : Node_Id;
8c18a165 532 Typ : Entity_Id := Empty);
4c318253 533 -- Check the specified expression Expr to make sure that it is a static
8c18a165
AC
534 -- expression of the given type (i.e. it will be analyzed and resolved
535 -- using this type, which can be any valid argument to Resolve, e.g.
536 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
537 -- Typ is left Empty, then any static expression is allowed.
538
996ae0b0 539 procedure Check_First_Subtype (Arg : Node_Id);
b4ca2d2c
AC
540 -- Checks that Arg, whose expression is an entity name, references a
541 -- first subtype.
996ae0b0 542
dac3bede
YM
543 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
544 -- Checks that the given argument has an identifier, and if so, requires
545 -- it to match the given identifier name. If there is no identifier, or
546 -- a non-matching identifier, then an error message is given and
1bf773bb
AC
547 -- Pragma_Exit is raised.
548
549 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
550 -- Checks that the given argument has an identifier, and if so, requires
551 -- it to match one of the given identifier names. If there is no
552 -- identifier, or a non-matching identifier, then an error message is
a54d0eb4 553 -- given and Pragma_Exit is raised.
dac3bede 554
996ae0b0
RK
555 procedure Check_In_Main_Program;
556 -- Common checks for pragmas that appear within a main program
8918fe18 557 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
996ae0b0
RK
558
559 procedure Check_Interrupt_Or_Attach_Handler;
b3b9865d
AC
560 -- Common processing for first argument of pragma Interrupt_Handler or
561 -- pragma Attach_Handler.
996ae0b0
RK
562
563 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
564 -- Check that pragma appears in a declarative part, or in a package
565 -- specification, i.e. that it does not occur in a statement sequence
566 -- in a body.
567
568 procedure Check_No_Identifier (Arg : Node_Id);
569 -- Checks that the given argument does not have an identifier. If
570 -- an identifier is present, then an error message is issued, and
571 -- Pragma_Exit is raised.
572
573 procedure Check_No_Identifiers;
574 -- Checks that none of the arguments to the pragma has an identifier.
575 -- If any argument has an identifier, then an error message is issued,
576 -- and Pragma_Exit is raised.
577
9eea4346
GB
578 procedure Check_No_Link_Name;
579 -- Checks that no link name is specified
580
996ae0b0
RK
581 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
582 -- Checks if the given argument has an identifier, and if so, requires
583 -- it to match the given identifier name. If there is a non-matching
1bf773bb 584 -- identifier, then an error message is given and Pragma_Exit is raised.
996ae0b0
RK
585
586 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
587 -- Checks if the given argument has an identifier, and if so, requires
588 -- it to match the given identifier name. If there is a non-matching
1bf773bb 589 -- identifier, then an error message is given and Pragma_Exit is raised.
996ae0b0
RK
590 -- In this version of the procedure, the identifier name is given as
591 -- a string with lower case letters.
592
21d27997
RD
593 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
594 -- Called to process a precondition or postcondition pragma. There are
595 -- three cases:
596 --
597 -- The pragma appears after a subprogram spec
598 --
599 -- If the corresponding check is not enabled, the pragma is analyzed
600 -- but otherwise ignored and control returns with In_Body set False.
601 --
602 -- If the check is enabled, then the first step is to analyze the
603 -- pragma, but this is skipped if the subprogram spec appears within
604 -- a package specification (because this is the case where we delay
605 -- analysis till the end of the spec). Then (whether or not it was
606 -- analyzed), the pragma is chained to the subprogram in question
607 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
608 -- caller with In_Body set False.
609 --
610 -- The pragma appears at the start of subprogram body declarations
611 --
612 -- In this case an immediate return to the caller is made with
613 -- In_Body set True, and the pragma is NOT analyzed.
614 --
615 -- In all other cases, an error message for bad placement is given
616
996ae0b0
RK
617 procedure Check_Static_Constraint (Constr : Node_Id);
618 -- Constr is a constraint from an N_Subtype_Indication node from a
619 -- component constraint in an Unchecked_Union type. This routine checks
620 -- that the constraint is static as required by the restrictions for
621 -- Unchecked_Union.
622
dac3bede
YM
623 procedure Check_Test_Case;
624 -- Called to process a test-case pragma. The treatment is similar to the
5accd7b6
AC
625 -- one for pre- and postcondition in Check_Precondition_Postcondition,
626 -- except the placement rules for the test-case pragma are stricter.
627 -- This pragma may only occur after a subprogram spec declared directly
628 -- in a package spec unit. In this case, the pragma is chained to the
629 -- subprogram in question (using Spec_TC_List and Next_Pragma) and
630 -- analysis of the pragma is delayed till the end of the spec. In
631 -- all other cases, an error message for bad placement is given.
dac3bede 632
996ae0b0
RK
633 procedure Check_Valid_Configuration_Pragma;
634 -- Legality checks for placement of a configuration pragma
635
636 procedure Check_Valid_Library_Unit_Pragma;
637 -- Legality checks for library unit pragmas. A special case arises for
638 -- pragmas in generic instances that come from copies of the original
639 -- library unit pragmas in the generic templates. In the case of other
640 -- than library level instantiations these can appear in contexts which
641 -- would normally be invalid (they only apply to the original template
642 -- and to library level instantiations), and they are simply ignored,
643 -- which is implemented by rewriting them as null statements.
644
72e9f2b9
AC
645 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
646 -- Check an Unchecked_Union variant for lack of nested variants and
647 -- presence of at least one component. UU_Typ is the related Unchecked_
648 -- Union type.
5d09245e 649
996ae0b0
RK
650 procedure Error_Pragma (Msg : String);
651 pragma No_Return (Error_Pragma);
470cd9e9 652 -- Outputs error message for current pragma. The message contains a %
996ae0b0
RK
653 -- that will be replaced with the pragma name, and the flag is placed
654 -- on the pragma itself. Pragma_Exit is then raised.
655
656 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
657 pragma No_Return (Error_Pragma_Arg);
658 -- Outputs error message for current pragma. The message may contain
659 -- a % that will be replaced with the pragma name. The parameter Arg
660 -- may either be a pragma argument association, in which case the flag
661 -- is placed on the expression of this association, or an expression,
662 -- in which case the flag is placed directly on the expression. The
663 -- message is placed using Error_Msg_N, so the message may also contain
664 -- an & insertion character which will reference the given Arg value.
665 -- After placing the message, Pragma_Exit is raised.
666
667 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
668 pragma No_Return (Error_Pragma_Arg);
669 -- Similar to above form of Error_Pragma_Arg except that two messages
670 -- are provided, the second is a continuation comment starting with \.
671
672 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
673 pragma No_Return (Error_Pragma_Arg_Ident);
674 -- Outputs error message for current pragma. The message may contain
675 -- a % that will be replaced with the pragma name. The parameter Arg
676 -- must be a pragma argument association with a non-empty identifier
677 -- (i.e. its Chars field must be set), and the error message is placed
678 -- on the identifier. The message is placed using Error_Msg_N so
679 -- the message may also contain an & insertion character which will
680 -- reference the identifier. After placing the message, Pragma_Exit
681 -- is raised.
682
b039b10e
ST
683 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
684 pragma No_Return (Error_Pragma_Ref);
685 -- Outputs error message for current pragma. The message may contain
686 -- a % that will be replaced with the pragma name. The parameter Ref
687 -- must be an entity whose name can be referenced by & and sloc by #.
688 -- After placing the message, Pragma_Exit is raised.
689
996ae0b0
RK
690 function Find_Lib_Unit_Name return Entity_Id;
691 -- Used for a library unit pragma to find the entity to which the
692 -- library unit pragma applies, returns the entity found.
693
694 procedure Find_Program_Unit_Name (Id : Node_Id);
695 -- If the pragma is a compilation unit pragma, the id must denote the
696 -- compilation unit in the same compilation, and the pragma must appear
697 -- in the list of preceding or trailing pragmas. If it is a program
698 -- unit pragma that is not a compilation unit pragma, then the
699 -- identifier must be visible.
700
d9e0a587
EB
701 function Find_Unique_Parameterless_Procedure
702 (Name : Entity_Id;
703 Arg : Node_Id) return Entity_Id;
704 -- Used for a procedure pragma to find the unique parameterless
705 -- procedure identified by Name, returns it if it exists, otherwise
706 -- errors out and uses Arg as the pragma argument for the message.
707
0f1a6a0b
AC
708 procedure Fix_Error (Msg : in out String);
709 -- This is called prior to issuing an error message. Msg is a string
710 -- which typically contains the substring pragma. If the current pragma
711 -- comes from an aspect, each such "pragma" substring is replaced with
811ef5ba
RD
712 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
713 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
0f1a6a0b 714
996ae0b0
RK
715 procedure Gather_Associations
716 (Names : Name_List;
717 Args : out Args_List);
718 -- This procedure is used to gather the arguments for a pragma that
719 -- permits arbitrary ordering of parameters using the normal rules
720 -- for named and positional parameters. The Names argument is a list
721 -- of Name_Id values that corresponds to the allowed pragma argument
722 -- association identifiers in order. The result returned in Args is
723 -- a list of corresponding expressions that are the pragma arguments.
724 -- Note that this is a list of expressions, not of pragma argument
725 -- associations (Gather_Associations has completely checked all the
726 -- optional identifiers when it returns). An entry in Args is Empty
727 -- on return if the corresponding argument is not present.
728
996ae0b0 729 procedure GNAT_Pragma;
2fa9443e
ES
730 -- Called for all GNAT defined pragmas to check the relevant restriction
731 -- (No_Implementation_Pragmas).
996ae0b0
RK
732
733 function Is_Before_First_Decl
734 (Pragma_Node : Node_Id;
a9f4e3d2 735 Decls : List_Id) return Boolean;
996ae0b0
RK
736 -- Return True if Pragma_Node is before the first declarative item in
737 -- Decls where Decls is the list of declarative items.
738
739 function Is_Configuration_Pragma return Boolean;
f3d57416 740 -- Determines if the placement of the current pragma is appropriate
1b24ada5 741 -- for a configuration pragma.
ac9e9918
RD
742
743 function Is_In_Context_Clause return Boolean;
744 -- Returns True if pragma appears within the context clause of a unit,
745 -- and False for any other placement (does not generate any messages).
746
747 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
748 -- Analyzes the argument, and determines if it is a static string
749 -- expression, returns True if so, False if non-static or not String.
996ae0b0
RK
750
751 procedure Pragma_Misplaced;
3023ce42 752 pragma No_Return (Pragma_Misplaced);
996ae0b0
RK
753 -- Issue fatal error message for misplaced pragma
754
755 procedure Process_Atomic_Shared_Volatile;
756 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
757 -- Shared is an obsolete Ada 83 pragma, treated as being identical
758 -- in effect to pragma Atomic.
759
874a0341
RD
760 procedure Process_Compile_Time_Warning_Or_Error;
761 -- Common processing for Compile_Time_Error and Compile_Time_Warning
762
9fe2f33e 763 procedure Process_Convention
9cf032ef
RD
764 (C : out Convention_Id;
765 Ent : out Entity_Id);
f3d57416 766 -- Common processing for Convention, Interface, Import and Export.
996ae0b0
RK
767 -- Checks first two arguments of pragma, and sets the appropriate
768 -- convention value in the specified entity or entities. On return
9fe2f33e 769 -- C is the convention, Ent is the referenced entity.
996ae0b0 770
12b4d338
AC
771 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
772 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
773 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
774
996ae0b0
RK
775 procedure Process_Extended_Import_Export_Exception_Pragma
776 (Arg_Internal : Node_Id;
777 Arg_External : Node_Id;
778 Arg_Form : Node_Id;
779 Arg_Code : Node_Id);
b3b9865d
AC
780 -- Common processing for the pragmas Import/Export_Exception. The three
781 -- arguments correspond to the three named parameters of the pragma. An
782 -- argument is empty if the corresponding parameter is not present in
783 -- the pragma.
996ae0b0
RK
784
785 procedure Process_Extended_Import_Export_Object_Pragma
786 (Arg_Internal : Node_Id;
787 Arg_External : Node_Id;
788 Arg_Size : Node_Id);
b3b9865d
AC
789 -- Common processing for the pragmas Import/Export_Object. The three
790 -- arguments correspond to the three named parameters of the pragmas. An
791 -- argument is empty if the corresponding parameter is not present in
792 -- the pragma.
996ae0b0
RK
793
794 procedure Process_Extended_Import_Export_Internal_Arg
795 (Arg_Internal : Node_Id := Empty);
796 -- Common processing for all extended Import and Export pragmas. The
797 -- argument is the pragma parameter for the Internal argument. If
798 -- Arg_Internal is empty or inappropriate, an error message is posted.
799 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
800 -- set to identify the referenced entity.
801
802 procedure Process_Extended_Import_Export_Subprogram_Pragma
803 (Arg_Internal : Node_Id;
804 Arg_External : Node_Id;
805 Arg_Parameter_Types : Node_Id;
806 Arg_Result_Type : Node_Id := Empty;
807 Arg_Mechanism : Node_Id;
808 Arg_Result_Mechanism : Node_Id := Empty;
809 Arg_First_Optional_Parameter : Node_Id := Empty);
b3b9865d
AC
810 -- Common processing for all extended Import and Export pragmas applying
811 -- to subprograms. The caller omits any arguments that do not apply to
812 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
813 -- only in the Import_Function and Export_Function cases). The argument
814 -- names correspond to the allowed pragma association identifiers.
996ae0b0
RK
815
816 procedure Process_Generic_List;
817 -- Common processing for Share_Generic and Inline_Generic
818
819 procedure Process_Import_Or_Interface;
820 -- Common processing for Import of Interface
821
15b682ca
GB
822 procedure Process_Import_Predefined_Type;
823 -- Processing for completing a type with pragma Import. This is used
824 -- to declare types that match predefined C types, especially for cases
825 -- without corresponding Ada predefined type.
826
996ae0b0
RK
827 procedure Process_Inline (Active : Boolean);
828 -- Common processing for Inline and Inline_Always. The parameter
b3b9865d
AC
829 -- indicates if the inline pragma is active, i.e. if it should actually
830 -- cause inlining to occur.
996ae0b0
RK
831
832 procedure Process_Interface_Name
833 (Subprogram_Def : Entity_Id;
834 Ext_Arg : Node_Id;
835 Link_Arg : Node_Id);
836 -- Given the last two arguments of pragma Import, pragma Export, or
837 -- pragma Interface_Name, performs validity checks and sets the
838 -- Interface_Name field of the given subprogram entity to the
b3b9865d
AC
839 -- appropriate external or link name, depending on the arguments given.
840 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
841 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
842 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
843 -- nor Link_Arg is present, the interface name is set to the default
844 -- from the subprogram name.
996ae0b0
RK
845
846 procedure Process_Interrupt_Or_Attach_Handler;
6e937c1c
AC
847 -- Common processing for Interrupt and Attach_Handler pragmas
848
ac9e9918
RD
849 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
850 -- Common processing for Restrictions and Restriction_Warnings pragmas.
23e6615e
RD
851 -- Warn is True for Restriction_Warnings, or for Restrictions if the
852 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
853 -- is not set in the Restrictions case.
996ae0b0
RK
854
855 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
856 -- Common processing for Suppress and Unsuppress. The boolean parameter
857 -- Suppress_Case is True for the Suppress case, and False for the
858 -- Unsuppress case.
859
860 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
861 -- This procedure sets the Is_Exported flag for the given entity,
862 -- checking that the entity was not previously imported. Arg is
fbf5a39b
AC
863 -- the argument that specified the entity. A check is also made
864 -- for exporting inappropriate entities.
996ae0b0
RK
865
866 procedure Set_Extended_Import_Export_External_Name
867 (Internal_Ent : Entity_Id;
868 Arg_External : Node_Id);
869 -- Common processing for all extended import export pragmas. The first
870 -- argument, Internal_Ent, is the internal entity, which has already
871 -- been checked for validity by the caller. Arg_External is from the
872 -- Import or Export pragma, and may be null if no External parameter
873 -- was present. If Arg_External is present and is a non-null string
874 -- (a null string is treated as the default), then the Interface_Name
875 -- field of Internal_Ent is set appropriately.
876
877 procedure Set_Imported (E : Entity_Id);
878 -- This procedure sets the Is_Imported flag for the given entity,
879 -- checking that it is not previously exported or imported.
880
881 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
882 -- Mech is a parameter passing mechanism (see Import_Function syntax
883 -- for MECHANISM_NAME). This routine checks that the mechanism argument
884 -- has the right form, and if not issues an error message. If the
885 -- argument has the right form then the Mechanism field of Ent is
886 -- set appropriately.
887
8a36a0cc 888 procedure Set_Ravenscar_Profile (N : Node_Id);
b3b9865d
AC
889 -- Activate the set of configuration pragmas and restrictions that make
890 -- up the Ravenscar Profile. N is the corresponding pragma node, which
891 -- is used for error messages on any constructs that violate the
892 -- profile.
8a36a0cc 893
2fa9443e
ES
894 ---------------------
895 -- Ada_2005_Pragma --
896 ---------------------
897
898 procedure Ada_2005_Pragma is
899 begin
900 if Ada_Version <= Ada_95 then
901 Check_Restriction (No_Implementation_Pragmas, N);
902 end if;
903 end Ada_2005_Pragma;
904
bfae1846
AC
905 ---------------------
906 -- Ada_2012_Pragma --
907 ---------------------
908
909 procedure Ada_2012_Pragma is
910 begin
0791fbe9 911 if Ada_Version <= Ada_2005 then
bfae1846
AC
912 Check_Restriction (No_Implementation_Pragmas, N);
913 end if;
914 end Ada_2012_Pragma;
915
996ae0b0
RK
916 --------------------------
917 -- Check_Ada_83_Warning --
918 --------------------------
919
920 procedure Check_Ada_83_Warning is
921 begin
0ab80019 922 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
996ae0b0
RK
923 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
924 end if;
925 end Check_Ada_83_Warning;
926
927 ---------------------
928 -- Check_Arg_Count --
929 ---------------------
930
931 procedure Check_Arg_Count (Required : Nat) is
932 begin
933 if Arg_Count /= Required then
934 Error_Pragma ("wrong number of arguments for pragma%");
935 end if;
936 end Check_Arg_Count;
937
cc335f43
AC
938 --------------------------------
939 -- Check_Arg_Is_External_Name --
940 --------------------------------
941
942 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
943 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
944
945 begin
946 if Nkind (Argx) = N_Identifier then
947 return;
948
949 else
950 Analyze_And_Resolve (Argx, Standard_String);
951
952 if Is_OK_Static_Expression (Argx) then
953 return;
954
955 elsif Etype (Argx) = Any_Type then
956 raise Pragma_Exit;
957
958 -- An interesting special case, if we have a string literal and
959 -- we are in Ada 83 mode, then we allow it even though it will
960 -- not be flagged as static. This allows expected Ada 83 mode
961 -- use of external names which are string literals, even though
962 -- technically these are not static in Ada 83.
963
964 elsif Ada_Version = Ada_83
965 and then Nkind (Argx) = N_String_Literal
966 then
967 return;
968
969 -- Static expression that raises Constraint_Error. This has
970 -- already been flagged, so just exit from pragma processing.
971
972 elsif Is_Static_Expression (Argx) then
973 raise Pragma_Exit;
974
975 -- Here we have a real error (non-static expression)
976
977 else
1b24ada5 978 Error_Msg_Name_1 := Pname;
0f1a6a0b
AC
979
980 declare
981 Msg : String :=
982 "argument for pragma% must be a identifier or "
983 & "static string expression!";
984 begin
985 Fix_Error (Msg);
986 Flag_Non_Static_Expr (Msg, Argx);
987 raise Pragma_Exit;
988 end;
cc335f43
AC
989 end if;
990 end if;
991 end Check_Arg_Is_External_Name;
992
996ae0b0
RK
993 -----------------------------
994 -- Check_Arg_Is_Identifier --
995 -----------------------------
996
997 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
998 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
996ae0b0
RK
999 begin
1000 if Nkind (Argx) /= N_Identifier then
1001 Error_Pragma_Arg
1002 ("argument for pragma% must be identifier", Argx);
1003 end if;
1004 end Check_Arg_Is_Identifier;
1005
1006 ----------------------------------
1007 -- Check_Arg_Is_Integer_Literal --
1008 ----------------------------------
1009
1010 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1011 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
996ae0b0
RK
1012 begin
1013 if Nkind (Argx) /= N_Integer_Literal then
1014 Error_Pragma_Arg
1015 ("argument for pragma% must be integer literal", Argx);
1016 end if;
1017 end Check_Arg_Is_Integer_Literal;
1018
1019 -------------------------------------------
1020 -- Check_Arg_Is_Library_Level_Local_Name --
1021 -------------------------------------------
1022
1023 -- LOCAL_NAME ::=
1024 -- DIRECT_NAME
1025 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1026 -- | library_unit_NAME
1027
1028 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1029 begin
1030 Check_Arg_Is_Local_Name (Arg);
1031
0f1a6a0b 1032 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
996ae0b0
RK
1033 and then Comes_From_Source (N)
1034 then
1035 Error_Pragma_Arg
1036 ("argument for pragma% must be library level entity", Arg);
1037 end if;
1038 end Check_Arg_Is_Library_Level_Local_Name;
1039
1040 -----------------------------
1041 -- Check_Arg_Is_Local_Name --
1042 -----------------------------
1043
1044 -- LOCAL_NAME ::=
1045 -- DIRECT_NAME
1046 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1047 -- | library_unit_NAME
1048
1049 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1050 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1051
1052 begin
1053 Analyze (Argx);
1054
1055 if Nkind (Argx) not in N_Direct_Name
1056 and then (Nkind (Argx) /= N_Attribute_Reference
1057 or else Present (Expressions (Argx))
1058 or else Nkind (Prefix (Argx)) /= N_Identifier)
1059 and then (not Is_Entity_Name (Argx)
1060 or else not Is_Compilation_Unit (Entity (Argx)))
1061 then
1062 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1063 end if;
1064
c3ad80f0
TQ
1065 -- No further check required if not an entity name
1066
1067 if not Is_Entity_Name (Argx) then
1068 null;
1069
1070 else
1071 declare
1072 OK : Boolean;
1073 Ent : constant Entity_Id := Entity (Argx);
1074 Scop : constant Entity_Id := Scope (Ent);
1075 begin
1076 -- Case of a pragma applied to a compilation unit: pragma must
1077 -- occur immediately after the program unit in the compilation.
1078
1079 if Is_Compilation_Unit (Ent) then
1080 declare
1081 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
df177175 1082
c3ad80f0
TQ
1083 begin
1084 -- Case of pragma placed immediately after spec
1085
1086 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1087 OK := True;
1088
1089 -- Case of pragma placed immediately after body
1090
1091 elsif Nkind (Decl) = N_Subprogram_Declaration
1092 and then Present (Corresponding_Body (Decl))
1093 then
1094 OK := Parent (N) =
1095 Aux_Decls_Node
1096 (Parent (Unit_Declaration_Node
1097 (Corresponding_Body (Decl))));
1098
1099 -- All other cases are illegal
1100
1101 else
1102 OK := False;
1103 end if;
1104 end;
1105
1106 -- Special restricted placement rule from 10.2.1(11.8/2)
1107
1108 elsif Is_Generic_Formal (Ent)
1109 and then Prag_Id = Pragma_Preelaborable_Initialization
1110 then
1111 OK := List_Containing (N) =
1112 Generic_Formal_Declarations
1113 (Unit_Declaration_Node (Scop));
1114
1115 -- Default case, just check that the pragma occurs in the scope
1116 -- of the entity denoted by the name.
1117
1118 else
1119 OK := Current_Scope = Scop;
1120 end if;
1121
1122 if not OK then
1123 Error_Pragma_Arg
1124 ("pragma% argument must be in same declarative part", Arg);
1125 end if;
1126 end;
996ae0b0
RK
1127 end if;
1128 end Check_Arg_Is_Local_Name;
1129
1130 ---------------------------------
1131 -- Check_Arg_Is_Locking_Policy --
1132 ---------------------------------
1133
1134 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1135 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1136
1137 begin
1138 Check_Arg_Is_Identifier (Argx);
1139
1140 if not Is_Locking_Policy_Name (Chars (Argx)) then
b4ca2d2c 1141 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
996ae0b0
RK
1142 end if;
1143 end Check_Arg_Is_Locking_Policy;
1144
1145 -------------------------
1146 -- Check_Arg_Is_One_Of --
1147 -------------------------
1148
1149 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1150 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1151
1152 begin
1153 Check_Arg_Is_Identifier (Argx);
1154
1155 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1156 Error_Msg_Name_2 := N1;
1157 Error_Msg_Name_3 := N2;
1158 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1159 end if;
1160 end Check_Arg_Is_One_Of;
1161
1162 procedure Check_Arg_Is_One_Of
1163 (Arg : Node_Id;
1164 N1, N2, N3 : Name_Id)
1165 is
1166 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1167
1168 begin
1169 Check_Arg_Is_Identifier (Argx);
1170
1171 if Chars (Argx) /= N1
1172 and then Chars (Argx) /= N2
1173 and then Chars (Argx) /= N3
1174 then
1175 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1176 end if;
1177 end Check_Arg_Is_One_Of;
1178
21d27997 1179 procedure Check_Arg_Is_One_Of
9b3956dd
RD
1180 (Arg : Node_Id;
1181 N1, N2, N3, N4, N5 : Name_Id)
21d27997
RD
1182 is
1183 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1184
1185 begin
1186 Check_Arg_Is_Identifier (Argx);
1187
1188 if Chars (Argx) /= N1
1189 and then Chars (Argx) /= N2
1190 and then Chars (Argx) /= N3
1191 and then Chars (Argx) /= N4
9b3956dd 1192 and then Chars (Argx) /= N5
21d27997
RD
1193 then
1194 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1195 end if;
1196 end Check_Arg_Is_One_Of;
996ae0b0
RK
1197 ---------------------------------
1198 -- Check_Arg_Is_Queuing_Policy --
1199 ---------------------------------
1200
1201 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1202 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1203
1204 begin
1205 Check_Arg_Is_Identifier (Argx);
1206
1207 if not Is_Queuing_Policy_Name (Chars (Argx)) then
b4ca2d2c 1208 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
996ae0b0
RK
1209 end if;
1210 end Check_Arg_Is_Queuing_Policy;
1211
1212 ------------------------------------
1213 -- Check_Arg_Is_Static_Expression --
1214 ------------------------------------
1215
1216 procedure Check_Arg_Is_Static_Expression
1217 (Arg : Node_Id;
37765e95
RD
1218 Typ : Entity_Id := Empty)
1219 is
996ae0b0 1220 begin
8c18a165 1221 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
996ae0b0
RK
1222 end Check_Arg_Is_Static_Expression;
1223
996ae0b0
RK
1224 ------------------------------------------
1225 -- Check_Arg_Is_Task_Dispatching_Policy --
1226 ------------------------------------------
1227
1228 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1229 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1230
1231 begin
1232 Check_Arg_Is_Identifier (Argx);
1233
1234 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1235 Error_Pragma_Arg
1236 ("& is not a valid task dispatching policy name", Argx);
1237 end if;
1238 end Check_Arg_Is_Task_Dispatching_Policy;
1239
59e5fbe0
RD
1240 ---------------------
1241 -- Check_Arg_Order --
1242 ---------------------
1243
1244 procedure Check_Arg_Order (Names : Name_List) is
1245 Arg : Node_Id;
1246
1247 Highest_So_Far : Natural := 0;
1248 -- Highest index in Names seen do far
1249
1250 begin
1251 Arg := Arg1;
1252 for J in 1 .. Arg_Count loop
1253 if Chars (Arg) /= No_Name then
1254 for K in Names'Range loop
1255 if Chars (Arg) = Names (K) then
1256 if K < Highest_So_Far then
1b24ada5 1257 Error_Msg_Name_1 := Pname;
59e5fbe0
RD
1258 Error_Msg_N
1259 ("parameters out of order for pragma%", Arg);
1260 Error_Msg_Name_1 := Names (K);
1261 Error_Msg_Name_2 := Names (Highest_So_Far);
ed2233dc 1262 Error_Msg_N ("\% must appear before %", Arg);
59e5fbe0
RD
1263 raise Pragma_Exit;
1264
1265 else
1266 Highest_So_Far := K;
1267 end if;
1268 end if;
1269 end loop;
1270 end if;
1271
1272 Arg := Next (Arg);
1273 end loop;
1274 end Check_Arg_Order;
1275
996ae0b0
RK
1276 --------------------------------
1277 -- Check_At_Least_N_Arguments --
1278 --------------------------------
1279
1280 procedure Check_At_Least_N_Arguments (N : Nat) is
1281 begin
1282 if Arg_Count < N then
1283 Error_Pragma ("too few arguments for pragma%");
1284 end if;
1285 end Check_At_Least_N_Arguments;
1286
1287 -------------------------------
1288 -- Check_At_Most_N_Arguments --
1289 -------------------------------
1290
1291 procedure Check_At_Most_N_Arguments (N : Nat) is
1292 Arg : Node_Id;
996ae0b0
RK
1293 begin
1294 if Arg_Count > N then
1295 Arg := Arg1;
996ae0b0
RK
1296 for J in 1 .. N loop
1297 Next (Arg);
1298 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1299 end loop;
1300 end if;
1301 end Check_At_Most_N_Arguments;
1302
5d09245e
AC
1303 ---------------------
1304 -- Check_Component --
1305 ---------------------
1306
72e9f2b9
AC
1307 procedure Check_Component
1308 (Comp : Node_Id;
1309 UU_Typ : Entity_Id;
1310 In_Variant_Part : Boolean := False)
1311 is
1312 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1313 Sindic : constant Node_Id :=
1314 Subtype_Indication (Component_Definition (Comp));
1315 Typ : constant Entity_Id := Etype (Comp_Id);
5d09245e 1316
72e9f2b9 1317 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
229db351
AC
1318 -- Determine whether entity Id appears inside a generic body.
1319 -- Shouldn't this be in a more general place ???
5d09245e 1320
72e9f2b9
AC
1321 -------------------------
1322 -- Inside_Generic_Body --
1323 -------------------------
57193e09 1324
72e9f2b9 1325 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
229db351 1326 S : Entity_Id;
57193e09 1327
72e9f2b9 1328 begin
229db351 1329 S := Id;
b4ca2d2c 1330 while Present (S) and then S /= Standard_Standard loop
72e9f2b9
AC
1331 if Ekind (S) = E_Generic_Package
1332 and then In_Package_Body (S)
1333 then
1334 return True;
57193e09 1335 end if;
72e9f2b9
AC
1336
1337 S := Scope (S);
1338 end loop;
1339
1340 return False;
1341 end Inside_Generic_Body;
1342
1343 -- Start of processing for Check_Component
1344
1345 begin
1346 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1347 -- object constraint, then the component type shall be an Unchecked_
1348 -- Union.
1349
1350 if Nkind (Sindic) = N_Subtype_Indication
1351 and then Has_Per_Object_Constraint (Comp_Id)
1352 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1353 then
1354 Error_Msg_N
1355 ("component subtype subject to per-object constraint " &
1356 "must be an Unchecked_Union", Comp);
1357
1358 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1359 -- the body of a generic unit, or within the body of any of its
1360 -- descendant library units, no part of the type of a component
1361 -- declared in a variant_part of the unchecked union type shall be of
1362 -- a formal private type or formal private extension declared within
1363 -- the formal part of the generic unit.
1364
1365 elsif Ada_Version >= Ada_2012
1366 and then Inside_Generic_Body (UU_Typ)
1367 and then In_Variant_Part
1368 and then Is_Private_Type (Typ)
1369 and then Is_Generic_Type (Typ)
1370 then
1371 Error_Msg_N
1372 ("component of Unchecked_Union cannot be of generic type", Comp);
1373
1374 elsif Needs_Finalization (Typ) then
1375 Error_Msg_N
1376 ("component of Unchecked_Union cannot be controlled", Comp);
1377
1378 elsif Has_Task (Typ) then
1379 Error_Msg_N
1380 ("component of Unchecked_Union cannot have tasks", Comp);
5d09245e
AC
1381 end if;
1382 end Check_Component;
1383
40f07b4b
AC
1384 ----------------------------
1385 -- Check_Duplicate_Pragma --
1386 ----------------------------
1387
af31bffb 1388 procedure Check_Duplicate_Pragma (E : Entity_Id) is
c159409f 1389 P : Node_Id;
40f07b4b 1390
af31bffb 1391 begin
0f1a6a0b
AC
1392 -- Nothing to do if this pragma comes from an aspect specification,
1393 -- since we could not be duplicating a pragma, and we dealt with the
1394 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1395
1396 if From_Aspect_Specification (N) then
1397 return;
1398 end if;
1399
1400 -- Otherwise current pragma may duplicate previous pragma or a
1401 -- previously given aspect specification for the same pragma.
1402
c159409f 1403 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
40f07b4b 1404
c159409f
AC
1405 if Present (P) then
1406 Error_Msg_Name_1 := Pragma_Name (N);
1407 Error_Msg_Sloc := Sloc (P);
40f07b4b 1408
c159409f
AC
1409 if Nkind (P) = N_Aspect_Specification
1410 or else From_Aspect_Specification (P)
40f07b4b 1411 then
beacce02 1412 Error_Msg_NE ("aspect% for & previously given#", N, E);
c159409f
AC
1413 else
1414 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
40f07b4b 1415 end if;
c159409f
AC
1416
1417 raise Pragma_Exit;
af31bffb
AC
1418 end if;
1419 end Check_Duplicate_Pragma;
1420
523456db
AC
1421 ----------------------------------
1422 -- Check_Duplicated_Export_Name --
1423 ----------------------------------
1424
1425 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1426 String_Val : constant String_Id := Strval (Nam);
1427
1428 begin
1429 -- We are only interested in the export case, and in the case of
1430 -- generics, it is the instance, not the template, that is the
1431 -- problem (the template will generate a warning in any case).
1432
1433 if not Inside_A_Generic
1434 and then (Prag_Id = Pragma_Export
1435 or else
1436 Prag_Id = Pragma_Export_Procedure
1437 or else
1438 Prag_Id = Pragma_Export_Valued_Procedure
1439 or else
1440 Prag_Id = Pragma_Export_Function)
1441 then
1442 for J in Externals.First .. Externals.Last loop
1443 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1444 Error_Msg_Sloc := Sloc (Externals.Table (J));
1445 Error_Msg_N ("external name duplicates name given#", Nam);
1446 exit;
1447 end if;
1448 end loop;
1449
1450 Externals.Append (Nam);
1451 end if;
1452 end Check_Duplicated_Export_Name;
1453
8c18a165
AC
1454 -------------------------------------
1455 -- Check_Expr_Is_Static_Expression --
1456 -------------------------------------
1457
1458 procedure Check_Expr_Is_Static_Expression
4c318253 1459 (Expr : Node_Id;
37765e95
RD
1460 Typ : Entity_Id := Empty)
1461 is
8c18a165
AC
1462 begin
1463 if Present (Typ) then
4c318253 1464 Analyze_And_Resolve (Expr, Typ);
8c18a165 1465 else
4c318253 1466 Analyze_And_Resolve (Expr);
8c18a165
AC
1467 end if;
1468
4c318253 1469 if Is_OK_Static_Expression (Expr) then
8c18a165
AC
1470 return;
1471
4c318253 1472 elsif Etype (Expr) = Any_Type then
8c18a165
AC
1473 raise Pragma_Exit;
1474
1475 -- An interesting special case, if we have a string literal and we
1476 -- are in Ada 83 mode, then we allow it even though it will not be
1477 -- flagged as static. This allows the use of Ada 95 pragmas like
1478 -- Import in Ada 83 mode. They will of course be flagged with
1479 -- warnings as usual, but will not cause errors.
1480
1481 elsif Ada_Version = Ada_83
4c318253 1482 and then Nkind (Expr) = N_String_Literal
8c18a165
AC
1483 then
1484 return;
1485
1486 -- Static expression that raises Constraint_Error. This has already
1487 -- been flagged, so just exit from pragma processing.
1488
4c318253 1489 elsif Is_Static_Expression (Expr) then
8c18a165
AC
1490 raise Pragma_Exit;
1491
1492 -- Finally, we have a real error
1493
1494 else
1495 Error_Msg_Name_1 := Pname;
1496
1497 declare
1498 Msg : String :=
1499 "argument for pragma% must be a static expression!";
1500 begin
1501 Fix_Error (Msg);
4c318253 1502 Flag_Non_Static_Expr (Msg, Expr);
8c18a165
AC
1503 end;
1504
1505 raise Pragma_Exit;
1506 end if;
1507 end Check_Expr_Is_Static_Expression;
1508
996ae0b0
RK
1509 -------------------------
1510 -- Check_First_Subtype --
1511 -------------------------
1512
1513 procedure Check_First_Subtype (Arg : Node_Id) is
1514 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
b4ca2d2c 1515 Ent : constant Entity_Id := Entity (Argx);
229db351 1516
996ae0b0 1517 begin
b4ca2d2c
AC
1518 if Is_First_Subtype (Ent) then
1519 null;
1520
1521 elsif Is_Type (Ent) then
996ae0b0
RK
1522 Error_Pragma_Arg
1523 ("pragma% cannot apply to subtype", Argx);
b4ca2d2c
AC
1524
1525 elsif Is_Object (Ent) then
1526 Error_Pragma_Arg
1527 ("pragma% cannot apply to object, requires a type", Argx);
1528
1529 else
1530 Error_Pragma_Arg
1531 ("pragma% cannot apply to&, requires a type", Argx);
996ae0b0
RK
1532 end if;
1533 end Check_First_Subtype;
1534
dac3bede
YM
1535 ----------------------
1536 -- Check_Identifier --
1537 ----------------------
1538
1539 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1540 begin
1541 if Present (Arg)
1542 and then Nkind (Arg) = N_Pragma_Argument_Association
1543 then
1544 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1545 Error_Msg_Name_1 := Pname;
1546 Error_Msg_Name_2 := Id;
1547 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1548 raise Pragma_Exit;
1549 end if;
1550 end if;
1551 end Check_Identifier;
1552
1bf773bb
AC
1553 --------------------------------
1554 -- Check_Identifier_Is_One_Of --
1555 --------------------------------
1556
1557 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1558 begin
1559 if Present (Arg)
1560 and then Nkind (Arg) = N_Pragma_Argument_Association
1561 then
1562 if Chars (Arg) = No_Name then
1563 Error_Msg_Name_1 := Pname;
1564 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1565 raise Pragma_Exit;
1566
1567 elsif Chars (Arg) /= N1
1568 and then Chars (Arg) /= N2
1569 then
1570 Error_Msg_Name_1 := Pname;
1571 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1572 raise Pragma_Exit;
1573 end if;
1574 end if;
1575 end Check_Identifier_Is_One_Of;
1576
996ae0b0
RK
1577 ---------------------------
1578 -- Check_In_Main_Program --
1579 ---------------------------
1580
1581 procedure Check_In_Main_Program is
1582 P : constant Node_Id := Parent (N);
1583
1584 begin
1585 -- Must be at in subprogram body
1586
1587 if Nkind (P) /= N_Subprogram_Body then
1588 Error_Pragma ("% pragma allowed only in subprogram");
1589
1590 -- Otherwise warn if obviously not main program
1591
1592 elsif Present (Parameter_Specifications (Specification (P)))
fbf5a39b 1593 or else not Is_Compilation_Unit (Defining_Entity (P))
996ae0b0 1594 then
1b24ada5 1595 Error_Msg_Name_1 := Pname;
996ae0b0
RK
1596 Error_Msg_N
1597 ("?pragma% is only effective in main program", N);
1598 end if;
1599 end Check_In_Main_Program;
1600
1601 ---------------------------------------
1602 -- Check_Interrupt_Or_Attach_Handler --
1603 ---------------------------------------
1604
1605 procedure Check_Interrupt_Or_Attach_Handler is
0f1a6a0b 1606 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
d9e0a587 1607 Handler_Proc, Proc_Scope : Entity_Id;
996ae0b0
RK
1608
1609 begin
1610 Analyze (Arg1_X);
1611
d9e0a587 1612 if Prag_Id = Pragma_Interrupt_Handler then
9f4fd324 1613 Check_Restriction (No_Dynamic_Attachment, N);
996ae0b0
RK
1614 end if;
1615
d9e0a587
EB
1616 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1617 Proc_Scope := Scope (Handler_Proc);
fbf5a39b 1618
d9e0a587
EB
1619 -- On AAMP only, a pragma Interrupt_Handler is supported for
1620 -- nonprotected parameterless procedures.
fbf5a39b 1621
d9e0a587
EB
1622 if not AAMP_On_Target
1623 or else Prag_Id = Pragma_Attach_Handler
1624 then
1625 if Ekind (Proc_Scope) /= E_Protected_Type then
996ae0b0 1626 Error_Pragma_Arg
fbf5a39b
AC
1627 ("argument of pragma% must be protected procedure", Arg1);
1628 end if;
1629
d9e0a587
EB
1630 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1631 Error_Pragma ("pragma% must be in protected definition");
996ae0b0 1632 end if;
d9e0a587 1633 end if;
996ae0b0 1634
d9e0a587
EB
1635 if not Is_Library_Level_Entity (Proc_Scope)
1636 or else (AAMP_On_Target
1637 and then not Is_Library_Level_Entity (Handler_Proc))
1638 then
1639 Error_Pragma_Arg
1640 ("argument for pragma% must be library level entity", Arg1);
1641 end if;
6f123e48 1642
313d6f2c 1643 -- AI05-0033: A pragma cannot appear within a generic body, because
af31bffb
AC
1644 -- instance can be in a nested scope. The check that protected type
1645 -- is itself a library-level declaration is done elsewhere.
1646
313d6f2c
AC
1647 -- Note: we omit this check in Codepeer mode to properly handle code
1648 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1649
6f123e48 1650 if Inside_A_Generic then
af31bffb 1651 if Ekind (Scope (Current_Scope)) = E_Generic_Package
313d6f2c
AC
1652 and then In_Package_Body (Scope (Current_Scope))
1653 and then not CodePeer_Mode
af31bffb
AC
1654 then
1655 Error_Pragma ("pragma% cannot be used inside a generic");
1656 end if;
6f123e48 1657 end if;
996ae0b0
RK
1658 end Check_Interrupt_Or_Attach_Handler;
1659
1660 -------------------------------------------
1661 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1662 -------------------------------------------
1663
1664 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1665 P : Node_Id;
1666
1667 begin
1668 P := Parent (N);
1669 loop
1670 if No (P) then
1671 exit;
1672
1673 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1674 exit;
1675
d7ba4df4
RD
1676 elsif Nkind_In (P, N_Package_Specification,
1677 N_Block_Statement)
1678 then
996ae0b0
RK
1679 return;
1680
1681 -- Note: the following tests seem a little peculiar, because
1682 -- they test for bodies, but if we were in the statement part
1683 -- of the body, we would already have hit the handled statement
1684 -- sequence, so the only way we get here is by being in the
1685 -- declarative part of the body.
1686
f2131422
JM
1687 elsif Nkind_In (P, N_Subprogram_Body,
1688 N_Package_Body,
1689 N_Task_Body,
1690 N_Entry_Body)
996ae0b0
RK
1691 then
1692 return;
1693 end if;
1694
1695 P := Parent (P);
1696 end loop;
1697
1698 Error_Pragma ("pragma% is not in declarative part or package spec");
996ae0b0
RK
1699 end Check_Is_In_Decl_Part_Or_Package_Spec;
1700
1701 -------------------------
1702 -- Check_No_Identifier --
1703 -------------------------
1704
1705 procedure Check_No_Identifier (Arg : Node_Id) is
1706 begin
0f1a6a0b
AC
1707 if Nkind (Arg) = N_Pragma_Argument_Association
1708 and then Chars (Arg) /= No_Name
1709 then
996ae0b0
RK
1710 Error_Pragma_Arg_Ident
1711 ("pragma% does not permit identifier& here", Arg);
1712 end if;
1713 end Check_No_Identifier;
1714
1715 --------------------------
1716 -- Check_No_Identifiers --
1717 --------------------------
1718
1719 procedure Check_No_Identifiers is
1720 Arg_Node : Node_Id;
996ae0b0
RK
1721 begin
1722 if Arg_Count > 0 then
1723 Arg_Node := Arg1;
996ae0b0
RK
1724 while Present (Arg_Node) loop
1725 Check_No_Identifier (Arg_Node);
1726 Next (Arg_Node);
1727 end loop;
1728 end if;
1729 end Check_No_Identifiers;
1730
9eea4346
GB
1731 ------------------------
1732 -- Check_No_Link_Name --
1733 ------------------------
1734
1735 procedure Check_No_Link_Name is
1736 begin
1737 if Present (Arg3)
1738 and then Chars (Arg3) = Name_Link_Name
1739 then
1740 Arg4 := Arg3;
1741 end if;
1742
1743 if Present (Arg4) then
1744 Error_Pragma_Arg
1745 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1746 end if;
1747 end Check_No_Link_Name;
1748
996ae0b0
RK
1749 -------------------------------
1750 -- Check_Optional_Identifier --
1751 -------------------------------
1752
1753 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1754 begin
811ef5ba
RD
1755 if Present (Arg)
1756 and then Nkind (Arg) = N_Pragma_Argument_Association
1757 and then Chars (Arg) /= No_Name
1758 then
996ae0b0 1759 if Chars (Arg) /= Id then
1b24ada5 1760 Error_Msg_Name_1 := Pname;
996ae0b0
RK
1761 Error_Msg_Name_2 := Id;
1762 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1763 raise Pragma_Exit;
1764 end if;
1765 end if;
1766 end Check_Optional_Identifier;
1767
1768 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1769 begin
1770 Name_Buffer (1 .. Id'Length) := Id;
1771 Name_Len := Id'Length;
1772 Check_Optional_Identifier (Arg, Name_Find);
1773 end Check_Optional_Identifier;
1774
21d27997
RD
1775 --------------------------------------
1776 -- Check_Precondition_Postcondition --
1777 --------------------------------------
1778
1779 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1780 P : Node_Id;
21d27997
RD
1781 PO : Node_Id;
1782
3023ce42 1783 procedure Chain_PPC (PO : Node_Id);
dac3bede
YM
1784 -- If PO is an entry or a [generic] subprogram declaration node, then
1785 -- the precondition/postcondition applies to this subprogram and the
1786 -- processing for the pragma is completed. Otherwise the pragma is
1787 -- misplaced.
3023ce42
ES
1788
1789 ---------------
1790 -- Chain_PPC --
1791 ---------------
1792
1793 procedure Chain_PPC (PO : Node_Id) is
811ef5ba
RD
1794 S : Entity_Id;
1795 P : Node_Id;
3023ce42
ES
1796
1797 begin
811ef5ba
RD
1798 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1799 if not From_Aspect_Specification (N) then
1800 Error_Pragma
1801 ("pragma% cannot be applied to abstract subprogram");
1802
1803 elsif Class_Present (N) then
1fb00064 1804 null;
811ef5ba
RD
1805
1806 else
1807 Error_Pragma
1808 ("aspect % requires ''Class for abstract subprogram");
1809 end if;
1810
5ad4969d
RD
1811 -- AI05-0230: The same restriction applies to null procedures. For
1812 -- compatibility with earlier uses of the Ada pragma, apply this
1813 -- rule only to aspect specifications.
1814
1815 -- The above discrpency needs documentation. Robert is dubious
1816 -- about whether it is a good idea ???
8c4ee6f5
AC
1817
1818 elsif Nkind (PO) = N_Subprogram_Declaration
1819 and then Nkind (Specification (PO)) = N_Procedure_Specification
1820 and then Null_Present (Specification (PO))
1821 and then From_Aspect_Specification (N)
1822 and then not Class_Present (N)
1823 then
1824 Error_Pragma
1825 ("aspect % requires ''Class for null procedure");
1826
811ef5ba 1827 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1fb00064
AC
1828 N_Generic_Subprogram_Declaration,
1829 N_Entry_Declaration)
393e63ce
RD
1830 then
1831 Pragma_Misplaced;
1832 end if;
1833
1fb00064 1834 -- Here if we have [generic] subprogram or entry declaration
393e63ce 1835
1fb00064
AC
1836 if Nkind (PO) = N_Entry_Declaration then
1837 S := Defining_Entity (PO);
1838 else
1839 S := Defining_Unit_Name (Specification (PO));
1840 end if;
3023ce42 1841
beacce02
AC
1842 -- Make sure we do not have the case of a precondition pragma when
1843 -- the Pre'Class aspect is present.
811ef5ba
RD
1844
1845 -- We do this by looking at pragmas already chained to the entity
1846 -- since the aspect derived pragma will be put on this list first.
1847
beacce02
AC
1848 if Pragma_Name (N) = Name_Precondition then
1849 if not From_Aspect_Specification (N) then
dac3bede 1850 P := Spec_PPC_List (Contract (S));
beacce02
AC
1851 while Present (P) loop
1852 if Pragma_Name (P) = Name_Precondition
1853 and then From_Aspect_Specification (P)
1854 and then Class_Present (P)
1855 then
1856 Error_Msg_Sloc := Sloc (P);
1857 Error_Pragma
1858 ("pragma% not allowed, `Pre''Class` aspect given#");
811ef5ba
RD
1859 end if;
1860
beacce02
AC
1861 P := Next_Pragma (P);
1862 end loop;
1863 end if;
1864 end if;
811ef5ba 1865
beacce02
AC
1866 -- Similarly check for Pre with inherited Pre'Class. Note that
1867 -- we cover the aspect case as well here.
1868
1869 if Pragma_Name (N) = Name_Precondition
1870 and then not Class_Present (N)
1871 then
1872 declare
1873 Inherited : constant Subprogram_List :=
1874 Inherited_Subprograms (S);
1875 P : Node_Id;
1876
1877 begin
1878 for J in Inherited'Range loop
dac3bede 1879 P := Spec_PPC_List (Contract (Inherited (J)));
beacce02
AC
1880 while Present (P) loop
1881 if Pragma_Name (P) = Name_Precondition
1882 and then Class_Present (P)
1883 then
1884 Error_Msg_Sloc := Sloc (P);
1885 Error_Pragma
1886 ("pragma% not allowed, `Pre''Class` "
1887 & "aspect inherited from#");
1888 end if;
1889
1890 P := Next_Pragma (P);
1891 end loop;
1892 end loop;
1893 end;
811ef5ba
RD
1894 end if;
1895
308e6f3a 1896 -- Note: we do not analyze the pragma at this point. Instead we
1fb00064
AC
1897 -- delay this analysis until the end of the declarative part in
1898 -- which the pragma appears. This implements the required delay
1899 -- in this analysis, allowing forward references. The analysis
1900 -- happens at the end of Analyze_Declarations.
3023ce42
ES
1901
1902 -- Chain spec PPC pragma to list for subprogram
1903
dac3bede
YM
1904 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1905 Set_Spec_PPC_List (Contract (S), N);
3023ce42
ES
1906
1907 -- Return indicating spec case
1908
1909 In_Body := False;
1910 return;
1911 end Chain_PPC;
1912
c2873f74 1913 -- Start of processing for Check_Precondition_Postcondition
3023ce42 1914
21d27997
RD
1915 begin
1916 if not Is_List_Member (N) then
1917 Pragma_Misplaced;
1918 end if;
1919
1fb00064
AC
1920 -- Preanalyze message argument if present. Visibility in this
1921 -- argument is established at the point of pragma occurrence.
1922
1923 if Arg_Count = 2 then
1924 Check_Optional_Identifier (Arg2, Name_Message);
1925 Preanalyze_Spec_Expression
1926 (Get_Pragma_Arg (Arg2), Standard_String);
1927 end if;
1928
44a10091 1929 -- Record if pragma is disabled
21d27997 1930
b26be063 1931 if Check_Enabled (Pname) then
b26be063
AC
1932 Set_SCO_Pragma_Enabled (Loc);
1933 end if;
21d27997 1934
3023ce42
ES
1935 -- If we are within an inlined body, the legality of the pragma
1936 -- has been checked already.
1937
1938 if In_Inlined_Body then
1939 In_Body := True;
1940 return;
1941 end if;
1942
21d27997
RD
1943 -- Search prior declarations
1944
1945 P := N;
1946 while Present (Prev (P)) loop
1947 P := Prev (P);
75bee270 1948
b3b9865d
AC
1949 -- If the previous node is a generic subprogram, do not go to to
1950 -- the original node, which is the unanalyzed tree: we need to
1951 -- attach the pre/postconditions to the analyzed version at this
1952 -- point. They get propagated to the original tree when analyzing
1953 -- the corresponding body.
75bee270
ES
1954
1955 if Nkind (P) not in N_Generic_Declaration then
1956 PO := Original_Node (P);
1957 else
1958 PO := P;
1959 end if;
21d27997
RD
1960
1961 -- Skip past prior pragma
1962
1963 if Nkind (PO) = N_Pragma then
1964 null;
1965
1966 -- Skip stuff not coming from source
1967
1968 elsif not Comes_From_Source (PO) then
0b3d16c0 1969
5ad4969d 1970 -- The condition may apply to a subprogram instantiation
0b3d16c0
AC
1971
1972 if Nkind (PO) = N_Subprogram_Declaration
1973 and then Present (Generic_Parent (Specification (PO)))
1974 then
1975 Chain_PPC (PO);
1976 return;
1977
24a120ac
AC
1978 elsif Nkind (PO) = N_Subprogram_Declaration
1979 and then In_Instance
1980 then
1981 Chain_PPC (PO);
1982 return;
1983
5ad4969d
RD
1984 -- For all other cases of non source code, do nothing
1985
0b3d16c0
AC
1986 else
1987 null;
1988 end if;
21d27997 1989
393e63ce 1990 -- Only remaining possibility is subprogram declaration
21d27997 1991
393e63ce 1992 else
3023ce42 1993 Chain_PPC (PO);
21d27997 1994 return;
21d27997
RD
1995 end if;
1996 end loop;
1997
b3b9865d
AC
1998 -- If we fall through loop, pragma is at start of list, so see if it
1999 -- is at the start of declarations of a subprogram body.
21d27997
RD
2000
2001 if Nkind (Parent (N)) = N_Subprogram_Body
2002 and then List_Containing (N) = Declarations (Parent (N))
2003 then
934a3a25
AC
2004 if Operating_Mode /= Generate_Code
2005 or else Inside_A_Generic
2006 then
beacce02 2007 -- Analyze pragma expression for correctness and for ASIS use
14037bbc
ES
2008
2009 Preanalyze_Spec_Expression
2010 (Get_Pragma_Arg (Arg1), Standard_Boolean);
8c18a165
AC
2011
2012 -- In ASIS mode, for a pragma generated from a source aspect,
2013 -- also analyze the original aspect expression.
2014
2015 if ASIS_Mode
2016 and then Present (Corresponding_Aspect (N))
2017 then
2018 Preanalyze_Spec_Expression
2019 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2020 end if;
14037bbc
ES
2021 end if;
2022
21d27997
RD
2023 In_Body := True;
2024 return;
2025
3023ce42 2026 -- See if it is in the pragmas after a library level subprogram
21d27997 2027
3023ce42 2028 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9b20e59b
AC
2029
2030 -- In formal verification mode, analyze pragma expression for
2031 -- correctness, as it is not expanded later.
2032
56812278 2033 if Alfa_Mode then
9b20e59b
AC
2034 Analyze_PPC_In_Decl_Part
2035 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2036 end if;
2037
393e63ce
RD
2038 Chain_PPC (Unit (Parent (Parent (N))));
2039 return;
21d27997 2040 end if;
3023ce42
ES
2041
2042 -- If we fall through, pragma was misplaced
2043
2044 Pragma_Misplaced;
21d27997
RD
2045 end Check_Precondition_Postcondition;
2046
996ae0b0
RK
2047 -----------------------------
2048 -- Check_Static_Constraint --
2049 -----------------------------
2050
2051 -- Note: for convenience in writing this procedure, in addition to
b3b9865d
AC
2052 -- the officially (i.e. by spec) allowed argument which is always a
2053 -- constraint, it also allows ranges and discriminant associations.
fbf5a39b 2054 -- Above is not clear ???
996ae0b0
RK
2055
2056 procedure Check_Static_Constraint (Constr : Node_Id) is
2057
21d27997
RD
2058 procedure Require_Static (E : Node_Id);
2059 -- Require given expression to be static expression
2060
996ae0b0
RK
2061 --------------------
2062 -- Require_Static --
2063 --------------------
2064
996ae0b0
RK
2065 procedure Require_Static (E : Node_Id) is
2066 begin
2067 if not Is_OK_Static_Expression (E) then
fbf5a39b
AC
2068 Flag_Non_Static_Expr
2069 ("non-static constraint not allowed in Unchecked_Union!", E);
996ae0b0
RK
2070 raise Pragma_Exit;
2071 end if;
2072 end Require_Static;
2073
2074 -- Start of processing for Check_Static_Constraint
2075
2076 begin
2077 case Nkind (Constr) is
2078 when N_Discriminant_Association =>
2079 Require_Static (Expression (Constr));
2080
2081 when N_Range =>
2082 Require_Static (Low_Bound (Constr));
2083 Require_Static (High_Bound (Constr));
2084
2085 when N_Attribute_Reference =>
2086 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2087 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2088
2089 when N_Range_Constraint =>
2090 Check_Static_Constraint (Range_Expression (Constr));
2091
2092 when N_Index_Or_Discriminant_Constraint =>
2093 declare
1d571f3b 2094 IDC : Entity_Id;
996ae0b0 2095 begin
1d571f3b 2096 IDC := First (Constraints (Constr));
996ae0b0
RK
2097 while Present (IDC) loop
2098 Check_Static_Constraint (IDC);
2099 Next (IDC);
2100 end loop;
2101 end;
2102
2103 when others =>
2104 null;
2105 end case;
2106 end Check_Static_Constraint;
2107
dac3bede
YM
2108 ---------------------
2109 -- Check_Test_Case --
2110 ---------------------
2111
2112 procedure Check_Test_Case is
2113 P : Node_Id;
2114 PO : Node_Id;
2115
2116 procedure Chain_TC (PO : Node_Id);
5accd7b6
AC
2117 -- If PO is a [generic] subprogram declaration node, then the
2118 -- test-case applies to this subprogram and the processing for the
2119 -- pragma is completed. Otherwise the pragma is misplaced.
dac3bede
YM
2120
2121 --------------
2122 -- Chain_TC --
2123 --------------
2124
2125 procedure Chain_TC (PO : Node_Id) is
2126 S : Entity_Id;
2127
2128 begin
2129 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2130 if From_Aspect_Specification (N) then
2131 Error_Pragma
2132 ("aspect% cannot be applied to abstract subprogram");
2133 else
2134 Error_Pragma
2135 ("pragma% cannot be applied to abstract subprogram");
2136 end if;
2137
5accd7b6
AC
2138 elsif Nkind (PO) = N_Entry_Declaration then
2139 if From_Aspect_Specification (N) then
2140 Error_Pragma ("aspect% cannot be applied to entry");
2141 else
2142 Error_Pragma ("pragma% cannot be applied to entry");
2143 end if;
2144
dac3bede 2145 elsif not Nkind_In (PO, N_Subprogram_Declaration,
5accd7b6 2146 N_Generic_Subprogram_Declaration)
dac3bede
YM
2147 then
2148 Pragma_Misplaced;
2149 end if;
2150
5accd7b6 2151 -- Here if we have [generic] subprogram declaration
dac3bede 2152
5accd7b6 2153 S := Defining_Unit_Name (Specification (PO));
dac3bede
YM
2154
2155 -- Note: we do not analyze the pragma at this point. Instead we
2156 -- delay this analysis until the end of the declarative part in
2157 -- which the pragma appears. This implements the required delay
2158 -- in this analysis, allowing forward references. The analysis
2159 -- happens at the end of Analyze_Declarations.
2160
1bf773bb
AC
2161 -- There should not be another test case with the same name
2162 -- associated to this subprogram.
2163
2164 declare
2165 Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2166 TC : Node_Id;
2167
2168 begin
2169 TC := Spec_TC_List (Contract (S));
2170 while Present (TC) loop
2171
2172 if String_Equal
2173 (Name, Get_Name_From_Test_Case_Pragma (TC))
2174 then
2175 Error_Msg_Sloc := Sloc (TC);
2176
2177 if From_Aspect_Specification (N) then
2178 Error_Pragma ("name for aspect% is already used#");
2179 else
2180 Error_Pragma ("name for pragma% is already used#");
2181 end if;
2182 end if;
2183
2184 TC := Next_Pragma (TC);
2185 end loop;
2186 end;
2187
dac3bede
YM
2188 -- Chain spec TC pragma to list for subprogram
2189
2190 Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2191 Set_Spec_TC_List (Contract (S), N);
2192 end Chain_TC;
2193
2194 -- Start of processing for Check_Test_Case
2195
2196 begin
2197 if not Is_List_Member (N) then
2198 Pragma_Misplaced;
2199 end if;
2200
5accd7b6
AC
2201 -- Test cases should only appear in package spec unit
2202
2203 if Get_Source_Unit (N) = No_Unit
2204 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
2205 N_Package_Declaration,
2206 N_Generic_Package_Declaration)
2207 then
2208 Pragma_Misplaced;
2209 end if;
2210
dac3bede
YM
2211 -- Search prior declarations
2212
2213 P := N;
2214 while Present (Prev (P)) loop
2215 P := Prev (P);
2216
2217 -- If the previous node is a generic subprogram, do not go to to
2218 -- the original node, which is the unanalyzed tree: we need to
2219 -- attach the test-case to the analyzed version at this point.
2220 -- They get propagated to the original tree when analyzing the
2221 -- corresponding body.
2222
2223 if Nkind (P) not in N_Generic_Declaration then
2224 PO := Original_Node (P);
2225 else
2226 PO := P;
2227 end if;
2228
2229 -- Skip past prior pragma
2230
2231 if Nkind (PO) = N_Pragma then
2232 null;
2233
2234 -- Skip stuff not coming from source
2235
2236 elsif not Comes_From_Source (PO) then
2237 null;
2238
5accd7b6
AC
2239 -- Only remaining possibility is subprogram declaration. First
2240 -- check that it is declared directly in a package declaration.
2241 -- This may be either the package declaration for the current unit
2242 -- being defined or a local package declaration.
2243
2244 elsif not Present (Parent (Parent (PO)))
2245 or else not Present (Parent (Parent (Parent (PO))))
2246 or else not Nkind_In (Parent (Parent (PO)),
2247 N_Package_Declaration,
2248 N_Generic_Package_Declaration)
2249 then
2250 Pragma_Misplaced;
dac3bede
YM
2251
2252 else
2253 Chain_TC (PO);
2254 return;
2255 end if;
2256 end loop;
2257
dac3bede
YM
2258 -- If we fall through, pragma was misplaced
2259
2260 Pragma_Misplaced;
2261 end Check_Test_Case;
2262
996ae0b0
RK
2263 --------------------------------------
2264 -- Check_Valid_Configuration_Pragma --
2265 --------------------------------------
2266
1b24ada5 2267 -- A configuration pragma must appear in the context clause of a
f3d57416 2268 -- compilation unit, and only other pragmas may precede it. Note that
1b24ada5 2269 -- the test also allows use in a configuration pragma file.
996ae0b0
RK
2270
2271 procedure Check_Valid_Configuration_Pragma is
2272 begin
2273 if not Is_Configuration_Pragma then
2274 Error_Pragma ("incorrect placement for configuration pragma%");
2275 end if;
2276 end Check_Valid_Configuration_Pragma;
2277
2278 -------------------------------------
2279 -- Check_Valid_Library_Unit_Pragma --
2280 -------------------------------------
2281
2282 procedure Check_Valid_Library_Unit_Pragma is
2283 Plist : List_Id;
2284 Parent_Node : Node_Id;
2285 Unit_Name : Entity_Id;
996ae0b0
RK
2286 Unit_Kind : Node_Kind;
2287 Unit_Node : Node_Id;
2288 Sindex : Source_File_Index;
2289
2290 begin
2291 if not Is_List_Member (N) then
2292 Pragma_Misplaced;
996ae0b0
RK
2293
2294 else
2295 Plist := List_Containing (N);
2296 Parent_Node := Parent (Plist);
2297
2298 if Parent_Node = Empty then
2299 Pragma_Misplaced;
2300
b3b9865d
AC
2301 -- Case of pragma appearing after a compilation unit. In this case
2302 -- it must have an argument with the corresponding name and must
2303 -- be part of the following pragmas of its parent.
996ae0b0
RK
2304
2305 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2306 if Plist /= Pragmas_After (Parent_Node) then
2307 Pragma_Misplaced;
2308
2309 elsif Arg_Count = 0 then
2310 Error_Pragma
2311 ("argument required if outside compilation unit");
2312
2313 else
2314 Check_No_Identifiers;
2315 Check_Arg_Count (1);
2316 Unit_Node := Unit (Parent (Parent_Node));
2317 Unit_Kind := Nkind (Unit_Node);
2318
0f1a6a0b 2319 Analyze (Get_Pragma_Arg (Arg1));
996ae0b0 2320
f02b8bb8 2321 if Unit_Kind = N_Generic_Subprogram_Declaration
996ae0b0
RK
2322 or else Unit_Kind = N_Subprogram_Declaration
2323 then
2324 Unit_Name := Defining_Entity (Unit_Node);
2325
f02b8bb8 2326 elsif Unit_Kind in N_Generic_Instantiation then
996ae0b0
RK
2327 Unit_Name := Defining_Entity (Unit_Node);
2328
2329 else
2330 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2331 end if;
2332
2333 if Chars (Unit_Name) /=
0f1a6a0b 2334 Chars (Entity (Get_Pragma_Arg (Arg1)))
996ae0b0
RK
2335 then
2336 Error_Pragma_Arg
2337 ("pragma% argument is not current unit name", Arg1);
2338 end if;
2339
2340 if Ekind (Unit_Name) = E_Package
2341 and then Present (Renamed_Entity (Unit_Name))
2342 then
2343 Error_Pragma ("pragma% not allowed for renamed package");
2344 end if;
2345 end if;
2346
2347 -- Pragma appears other than after a compilation unit
2348
2349 else
2350 -- Here we check for the generic instantiation case and also
2351 -- for the case of processing a generic formal package. We
2352 -- detect these cases by noting that the Sloc on the node
2353 -- does not belong to the current compilation unit.
2354
2355 Sindex := Source_Index (Current_Sem_Unit);
2356
2357 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2358 Rewrite (N, Make_Null_Statement (Loc));
2359 return;
2360
2361 -- If before first declaration, the pragma applies to the
2362 -- enclosing unit, and the name if present must be this name.
2363
2364 elsif Is_Before_First_Decl (N, Plist) then
2365 Unit_Node := Unit_Declaration_Node (Current_Scope);
2366 Unit_Kind := Nkind (Unit_Node);
2367
2368 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2369 Pragma_Misplaced;
2370
2371 elsif Unit_Kind = N_Subprogram_Body
2372 and then not Acts_As_Spec (Unit_Node)
2373 then
2374 Pragma_Misplaced;
2375
2376 elsif Nkind (Parent_Node) = N_Package_Body then
2377 Pragma_Misplaced;
2378
2379 elsif Nkind (Parent_Node) = N_Package_Specification
2380 and then Plist = Private_Declarations (Parent_Node)
2381 then
2382 Pragma_Misplaced;
2383
2384 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2fa9443e
ES
2385 or else Nkind (Parent_Node) =
2386 N_Generic_Subprogram_Declaration)
996ae0b0
RK
2387 and then Plist = Generic_Formal_Declarations (Parent_Node)
2388 then
2389 Pragma_Misplaced;
2390
2391 elsif Arg_Count > 0 then
0f1a6a0b 2392 Analyze (Get_Pragma_Arg (Arg1));
996ae0b0 2393
0f1a6a0b 2394 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
996ae0b0
RK
2395 Error_Pragma_Arg
2396 ("name in pragma% must be enclosing unit", Arg1);
2397 end if;
2398
2399 -- It is legal to have no argument in this context
2400
2401 else
2402 return;
2403 end if;
2404
2405 -- Error if not before first declaration. This is because a
2406 -- library unit pragma argument must be the name of a library
2407 -- unit (RM 10.1.5(7)), but the only names permitted in this
2408 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2409 -- generic subprogram declarations or generic instantiations.
2410
2411 else
2412 Error_Pragma
2413 ("pragma% misplaced, must be before first declaration");
2414 end if;
2415 end if;
2416 end if;
996ae0b0
RK
2417 end Check_Valid_Library_Unit_Pragma;
2418
5d09245e
AC
2419 -------------------
2420 -- Check_Variant --
2421 -------------------
2422
72e9f2b9 2423 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
5d09245e
AC
2424 Clist : constant Node_Id := Component_List (Variant);
2425 Comp : Node_Id;
2426
2427 begin
5d09245e
AC
2428 if not Is_Non_Empty_List (Component_Items (Clist)) then
2429 Error_Msg_N
2430 ("Unchecked_Union may not have empty component list",
2431 Variant);
2432 return;
2433 end if;
2434
2435 Comp := First (Component_Items (Clist));
2436 while Present (Comp) loop
72e9f2b9 2437 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
5d09245e 2438 Next (Comp);
5d09245e
AC
2439 end loop;
2440 end Check_Variant;
2441
996ae0b0
RK
2442 ------------------
2443 -- Error_Pragma --
2444 ------------------
2445
2446 procedure Error_Pragma (Msg : String) is
0f1a6a0b 2447 MsgF : String := Msg;
996ae0b0 2448 begin
1b24ada5 2449 Error_Msg_Name_1 := Pname;
0f1a6a0b
AC
2450 Fix_Error (MsgF);
2451 Error_Msg_N (MsgF, N);
996ae0b0
RK
2452 raise Pragma_Exit;
2453 end Error_Pragma;
2454
2455 ----------------------
2456 -- Error_Pragma_Arg --
2457 ----------------------
2458
2459 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
0f1a6a0b 2460 MsgF : String := Msg;
996ae0b0 2461 begin
1b24ada5 2462 Error_Msg_Name_1 := Pname;
0f1a6a0b
AC
2463 Fix_Error (MsgF);
2464 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
996ae0b0
RK
2465 raise Pragma_Exit;
2466 end Error_Pragma_Arg;
2467
2468 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
0f1a6a0b 2469 MsgF : String := Msg1;
996ae0b0 2470 begin
1b24ada5 2471 Error_Msg_Name_1 := Pname;
0f1a6a0b
AC
2472 Fix_Error (MsgF);
2473 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
996ae0b0
RK
2474 Error_Pragma_Arg (Msg2, Arg);
2475 end Error_Pragma_Arg;
2476
2477 ----------------------------
2478 -- Error_Pragma_Arg_Ident --
2479 ----------------------------
2480
2481 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
0f1a6a0b 2482 MsgF : String := Msg;
996ae0b0 2483 begin
1b24ada5 2484 Error_Msg_Name_1 := Pname;
0f1a6a0b
AC
2485 Fix_Error (MsgF);
2486 Error_Msg_N (MsgF, Arg);
996ae0b0
RK
2487 raise Pragma_Exit;
2488 end Error_Pragma_Arg_Ident;
2489
b039b10e
ST
2490 ----------------------
2491 -- Error_Pragma_Ref --
2492 ----------------------
2493
2494 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
0f1a6a0b 2495 MsgF : String := Msg;
b039b10e
ST
2496 begin
2497 Error_Msg_Name_1 := Pname;
0f1a6a0b 2498 Fix_Error (MsgF);
b039b10e 2499 Error_Msg_Sloc := Sloc (Ref);
0f1a6a0b 2500 Error_Msg_NE (MsgF, N, Ref);
b039b10e
ST
2501 raise Pragma_Exit;
2502 end Error_Pragma_Ref;
2503
996ae0b0
RK
2504 ------------------------
2505 -- Find_Lib_Unit_Name --
2506 ------------------------
2507
2508 function Find_Lib_Unit_Name return Entity_Id is
2509 begin
2510 -- Return inner compilation unit entity, for case of nested
2511 -- categorization pragmas. This happens in generic unit.
2512
2513 if Nkind (Parent (N)) = N_Package_Specification
2514 and then Defining_Entity (Parent (N)) /= Current_Scope
2515 then
2516 return Defining_Entity (Parent (N));
996ae0b0
RK
2517 else
2518 return Current_Scope;
2519 end if;
2520 end Find_Lib_Unit_Name;
2521
2522 ----------------------------
2523 -- Find_Program_Unit_Name --
2524 ----------------------------
2525
2526 procedure Find_Program_Unit_Name (Id : Node_Id) is
2527 Unit_Name : Entity_Id;
2528 Unit_Kind : Node_Kind;
2529 P : constant Node_Id := Parent (N);
2530
2531 begin
2532 if Nkind (P) = N_Compilation_Unit then
2533 Unit_Kind := Nkind (Unit (P));
2534
2535 if Unit_Kind = N_Subprogram_Declaration
2536 or else Unit_Kind = N_Package_Declaration
2537 or else Unit_Kind in N_Generic_Declaration
2538 then
2539 Unit_Name := Defining_Entity (Unit (P));
2540
2541 if Chars (Id) = Chars (Unit_Name) then
2542 Set_Entity (Id, Unit_Name);
2543 Set_Etype (Id, Etype (Unit_Name));
2544 else
2545 Set_Etype (Id, Any_Type);
2546 Error_Pragma
2547 ("cannot find program unit referenced by pragma%");
2548 end if;
2549
2550 else
2551 Set_Etype (Id, Any_Type);
2552 Error_Pragma ("pragma% inapplicable to this unit");
2553 end if;
2554
2555 else
2556 Analyze (Id);
2557 end if;
996ae0b0
RK
2558 end Find_Program_Unit_Name;
2559
d9e0a587
EB
2560 -----------------------------------------
2561 -- Find_Unique_Parameterless_Procedure --
2562 -----------------------------------------
2563
2564 function Find_Unique_Parameterless_Procedure
2565 (Name : Entity_Id;
2566 Arg : Node_Id) return Entity_Id
2567 is
2568 Proc : Entity_Id := Empty;
2569
2570 begin
2571 -- The body of this procedure needs some comments ???
2572
2573 if not Is_Entity_Name (Name) then
2574 Error_Pragma_Arg
2575 ("argument of pragma% must be entity name", Arg);
2576
2577 elsif not Is_Overloaded (Name) then
2578 Proc := Entity (Name);
2579
2580 if Ekind (Proc) /= E_Procedure
8a95f4e8
RD
2581 or else Present (First_Formal (Proc))
2582 then
d9e0a587
EB
2583 Error_Pragma_Arg
2584 ("argument of pragma% must be parameterless procedure", Arg);
2585 end if;
2586
2587 else
2588 declare
2589 Found : Boolean := False;
2590 It : Interp;
2591 Index : Interp_Index;
2592
2593 begin
2594 Get_First_Interp (Name, Index, It);
2595 while Present (It.Nam) loop
2596 Proc := It.Nam;
2597
2598 if Ekind (Proc) = E_Procedure
2599 and then No (First_Formal (Proc))
2600 then
2601 if not Found then
2602 Found := True;
2603 Set_Entity (Name, Proc);
2604 Set_Is_Overloaded (Name, False);
2605 else
2606 Error_Pragma_Arg
2607 ("ambiguous handler name for pragma% ", Arg);
2608 end if;
2609 end if;
2610
2611 Get_Next_Interp (Index, It);
2612 end loop;
2613
2614 if not Found then
2615 Error_Pragma_Arg
2616 ("argument of pragma% must be parameterless procedure",
2617 Arg);
2618 else
2619 Proc := Entity (Name);
2620 end if;
2621 end;
2622 end if;
2623
2624 return Proc;
2625 end Find_Unique_Parameterless_Procedure;
2626
0f1a6a0b
AC
2627 ---------------
2628 -- Fix_Error --
2629 ---------------
2630
2631 procedure Fix_Error (Msg : in out String) is
2632 begin
2633 if From_Aspect_Specification (N) then
2634 for J in Msg'First .. Msg'Last - 5 loop
2635 if Msg (J .. J + 5) = "pragma" then
2636 Msg (J .. J + 5) := "aspect";
2637 end if;
2638 end loop;
0f1a6a0b 2639
811ef5ba
RD
2640 if Error_Msg_Name_1 = Name_Precondition then
2641 Error_Msg_Name_1 := Name_Pre;
2642 elsif Error_Msg_Name_1 = Name_Postcondition then
2643 Error_Msg_Name_1 := Name_Post;
2644 end if;
0f1a6a0b
AC
2645 end if;
2646 end Fix_Error;
2647
996ae0b0
RK
2648 -------------------------
2649 -- Gather_Associations --
2650 -------------------------
2651
2652 procedure Gather_Associations
2653 (Names : Name_List;
2654 Args : out Args_List)
2655 is
2656 Arg : Node_Id;
2657
2658 begin
2659 -- Initialize all parameters to Empty
2660
2661 for J in Args'Range loop
2662 Args (J) := Empty;
2663 end loop;
2664
2665 -- That's all we have to do if there are no argument associations
2666
2667 if No (Pragma_Argument_Associations (N)) then
2668 return;
2669 end if;
2670
2671 -- Otherwise first deal with any positional parameters present
2672
2673 Arg := First (Pragma_Argument_Associations (N));
996ae0b0
RK
2674 for Index in Args'Range loop
2675 exit when No (Arg) or else Chars (Arg) /= No_Name;
0f1a6a0b 2676 Args (Index) := Get_Pragma_Arg (Arg);
996ae0b0
RK
2677 Next (Arg);
2678 end loop;
2679
2680 -- Positional parameters all processed, if any left, then we
2681 -- have too many positional parameters.
2682
2683 if Present (Arg) and then Chars (Arg) = No_Name then
2684 Error_Pragma_Arg
2685 ("too many positional associations for pragma%", Arg);
2686 end if;
2687
2688 -- Process named parameters if any are present
2689
2690 while Present (Arg) loop
2691 if Chars (Arg) = No_Name then
2692 Error_Pragma_Arg
2693 ("positional association cannot follow named association",
2694 Arg);
2695
2696 else
2697 for Index in Names'Range loop
2698 if Names (Index) = Chars (Arg) then
2699 if Present (Args (Index)) then
2700 Error_Pragma_Arg
2701 ("duplicate argument association for pragma%", Arg);
2702 else
0f1a6a0b 2703 Args (Index) := Get_Pragma_Arg (Arg);
996ae0b0
RK
2704 exit;
2705 end if;
2706 end if;
2707
2708 if Index = Names'Last then
1b24ada5 2709 Error_Msg_Name_1 := Pname;
07fc65c4
GB
2710 Error_Msg_N ("pragma% does not allow & argument", Arg);
2711
2712 -- Check for possible misspelling
2713
2714 for Index1 in Names'Range loop
2715 if Is_Bad_Spelling_Of
470cd9e9 2716 (Chars (Arg), Names (Index1))
07fc65c4
GB
2717 then
2718 Error_Msg_Name_1 := Names (Index1);
0c020dde
AC
2719 Error_Msg_N -- CODEFIX
2720 ("\possible misspelling of%", Arg);
07fc65c4
GB
2721 exit;
2722 end if;
2723 end loop;
2724
2725 raise Pragma_Exit;
996ae0b0
RK
2726 end if;
2727 end loop;
2728 end if;
2729
2730 Next (Arg);
2731 end loop;
2732 end Gather_Associations;
2733
996ae0b0
RK
2734 -----------------
2735 -- GNAT_Pragma --
2736 -----------------
2737
2738 procedure GNAT_Pragma is
2739 begin
2740 Check_Restriction (No_Implementation_Pragmas, N);
2741 end GNAT_Pragma;
2742
2743 --------------------------
2744 -- Is_Before_First_Decl --
2745 --------------------------
2746
2747 function Is_Before_First_Decl
2748 (Pragma_Node : Node_Id;
a9f4e3d2 2749 Decls : List_Id) return Boolean
996ae0b0
RK
2750 is
2751 Item : Node_Id := First (Decls);
2752
2753 begin
2754 -- Only other pragmas can come before this pragma
2755
2756 loop
2757 if No (Item) or else Nkind (Item) /= N_Pragma then
2758 return False;
2759
2760 elsif Item = Pragma_Node then
2761 return True;
2762 end if;
2763
2764 Next (Item);
2765 end loop;
996ae0b0
RK
2766 end Is_Before_First_Decl;
2767
2768 -----------------------------
2769 -- Is_Configuration_Pragma --
2770 -----------------------------
2771
1b24ada5
RD
2772 -- A configuration pragma must appear in the context clause of a
2773 -- compilation unit, and only other pragmas may precede it. Note that
2774 -- the test below also permits use in a configuration pragma file.
996ae0b0
RK
2775
2776 function Is_Configuration_Pragma return Boolean is
2777 Lis : constant List_Id := List_Containing (N);
2778 Par : constant Node_Id := Parent (N);
2779 Prg : Node_Id;
2780
2781 begin
2782 -- If no parent, then we are in the configuration pragma file,
2783 -- so the placement is definitely appropriate.
2784
2785 if No (Par) then
2786 return True;
2787
2788 -- Otherwise we must be in the context clause of a compilation unit
2789 -- and the only thing allowed before us in the context list is more
2790 -- configuration pragmas.
2791
2792 elsif Nkind (Par) = N_Compilation_Unit
2793 and then Context_Items (Par) = Lis
2794 then
2795 Prg := First (Lis);
2796
2797 loop
2798 if Prg = N then
2799 return True;
2800 elsif Nkind (Prg) /= N_Pragma then
2801 return False;
2802 end if;
2803
2804 Next (Prg);
2805 end loop;
2806
2807 else
2808 return False;
2809 end if;
996ae0b0
RK
2810 end Is_Configuration_Pragma;
2811
ac9e9918
RD
2812 --------------------------
2813 -- Is_In_Context_Clause --
2814 --------------------------
2815
2816 function Is_In_Context_Clause return Boolean is
2817 Plist : List_Id;
2818 Parent_Node : Node_Id;
2819
2820 begin
2821 if not Is_List_Member (N) then
2822 return False;
2823
2824 else
2825 Plist := List_Containing (N);
2826 Parent_Node := Parent (Plist);
2827
2828 if Parent_Node = Empty
2829 or else Nkind (Parent_Node) /= N_Compilation_Unit
2830 or else Context_Items (Parent_Node) /= Plist
2831 then
2832 return False;
2833 end if;
2834 end if;
2835
2836 return True;
2837 end Is_In_Context_Clause;
2838
2839 ---------------------------------
2840 -- Is_Static_String_Expression --
2841 ---------------------------------
2842
2843 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2844 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2845
2846 begin
2847 Analyze_And_Resolve (Argx);
2848 return Is_OK_Static_Expression (Argx)
2849 and then Nkind (Argx) = N_String_Literal;
2850 end Is_Static_String_Expression;
2851
996ae0b0
RK
2852 ----------------------
2853 -- Pragma_Misplaced --
2854 ----------------------
2855
2856 procedure Pragma_Misplaced is
2857 begin
2858 Error_Pragma ("incorrect placement of pragma%");
2859 end Pragma_Misplaced;
2860
2861 ------------------------------------
2862 -- Process Atomic_Shared_Volatile --
2863 ------------------------------------
2864
2865 procedure Process_Atomic_Shared_Volatile is
2866 E_Id : Node_Id;
2867 E : Entity_Id;
2868 D : Node_Id;
2869 K : Node_Kind;
07fc65c4 2870 Utyp : Entity_Id;
996ae0b0 2871
0da2c8ac 2872 procedure Set_Atomic (E : Entity_Id);
21d27997
RD
2873 -- Set given type as atomic, and if no explicit alignment was given,
2874 -- set alignment to unknown, since back end knows what the alignment
2875 -- requirements are for atomic arrays. Note: this step is necessary
2876 -- for derived types.
0da2c8ac
AC
2877
2878 ----------------
2879 -- Set_Atomic --
2880 ----------------
2881
2882 procedure Set_Atomic (E : Entity_Id) is
2883 begin
eaba57fb 2884 Set_Is_Atomic (E);
0da2c8ac 2885
eaba57fb 2886 if not Has_Alignment_Clause (E) then
0da2c8ac
AC
2887 Set_Alignment (E, Uint_0);
2888 end if;
2889 end Set_Atomic;
2890
2891 -- Start of processing for Process_Atomic_Shared_Volatile
2892
996ae0b0 2893 begin
996ae0b0
RK
2894 Check_Ada_83_Warning;
2895 Check_No_Identifiers;
2896 Check_Arg_Count (1);
2897 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 2898 E_Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
2899
2900 if Etype (E_Id) = Any_Type then
2901 return;
2902 end if;
2903
2904 E := Entity (E_Id);
2905 D := Declaration_Node (E);
2906 K := Nkind (D);
2907
af31bffb
AC
2908 -- Check duplicate before we chain ourselves!
2909
2910 Check_Duplicate_Pragma (E);
2911
2912 -- Now check appropriateness of the entity
2913
996ae0b0
RK
2914 if Is_Type (E) then
2915 if Rep_Item_Too_Early (E, N)
2916 or else
2917 Rep_Item_Too_Late (E, N)
2918 then
2919 return;
2920 else
2921 Check_First_Subtype (Arg1);
2922 end if;
2923
2924 if Prag_Id /= Pragma_Volatile then
0da2c8ac
AC
2925 Set_Atomic (E);
2926 Set_Atomic (Underlying_Type (E));
2927 Set_Atomic (Base_Type (E));
996ae0b0
RK
2928 end if;
2929
21d27997
RD
2930 -- Attribute belongs on the base type. If the view of the type is
2931 -- currently private, it also belongs on the underlying type.
fbf5a39b 2932
eaba57fb
RD
2933 Set_Is_Volatile (Base_Type (E));
2934 Set_Is_Volatile (Underlying_Type (E));
996ae0b0 2935
eaba57fb
RD
2936 Set_Treat_As_Volatile (E);
2937 Set_Treat_As_Volatile (Underlying_Type (E));
fbf5a39b 2938
996ae0b0
RK
2939 elsif K = N_Object_Declaration
2940 or else (K = N_Component_Declaration
2941 and then Original_Record_Component (E) = E)
2942 then
2943 if Rep_Item_Too_Late (E, N) then
2944 return;
2945 end if;
2946
2947 if Prag_Id /= Pragma_Volatile then
eaba57fb 2948 Set_Is_Atomic (E);
07fc65c4 2949
21d27997
RD
2950 -- If the object declaration has an explicit initialization, a
2951 -- temporary may have to be created to hold the expression, to
2952 -- ensure that access to the object remain atomic.
fbf5a39b
AC
2953
2954 if Nkind (Parent (E)) = N_Object_Declaration
2955 and then Present (Expression (Parent (E)))
2956 then
2957 Set_Has_Delayed_Freeze (E);
2958 end if;
2959
b3b9865d
AC
2960 -- An interesting improvement here. If an object of type X is
2961 -- declared atomic, and the type X is not atomic, that's a
2962 -- pity, since it may not have appropriate alignment etc. We
2963 -- can rescue this in the special case where the object and
2964 -- type are in the same unit by just setting the type as
2965 -- atomic, so that the back end will process it as atomic.
07fc65c4
GB
2966
2967 Utyp := Underlying_Type (Etype (E));
2968
2969 if Present (Utyp)
2970 and then Sloc (E) > No_Location
2971 and then Sloc (Utyp) > No_Location
2972 and then
2973 Get_Source_File_Index (Sloc (E)) =
2974 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2975 then
eaba57fb 2976 Set_Is_Atomic (Underlying_Type (Etype (E)));
07fc65c4 2977 end if;
996ae0b0
RK
2978 end if;
2979
2980 Set_Is_Volatile (E);
fbf5a39b 2981 Set_Treat_As_Volatile (E);
996ae0b0
RK
2982
2983 else
2984 Error_Pragma_Arg
2985 ("inappropriate entity for pragma%", Arg1);
2986 end if;
2987 end Process_Atomic_Shared_Volatile;
2988
874a0341
RD
2989 -------------------------------------------
2990 -- Process_Compile_Time_Warning_Or_Error --
2991 -------------------------------------------
2992
2993 procedure Process_Compile_Time_Warning_Or_Error is
2994 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2995
2996 begin
874a0341
RD
2997 Check_Arg_Count (2);
2998 Check_No_Identifiers;
2999 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3000 Analyze_And_Resolve (Arg1x, Standard_Boolean);
3001
3002 if Compile_Time_Known_Value (Arg1x) then
3003 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3004 declare
3005 Str : constant String_Id :=
3006 Strval (Get_Pragma_Arg (Arg2));
3007 Len : constant Int := String_Length (Str);
3008 Cont : Boolean;
3009 Ptr : Nat;
3010 CC : Char_Code;
3011 C : Character;
1b24ada5
RD
3012 Cent : constant Entity_Id :=
3013 Cunit_Entity (Current_Sem_Unit);
3014
3015 Force : constant Boolean :=
3016 Prag_Id = Pragma_Compile_Time_Warning
3017 and then
3018 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3019 and then (Ekind (Cent) /= E_Package
3020 or else not In_Private_Part (Cent));
3021 -- Set True if this is the warning case, and we are in the
3022 -- visible part of a package spec, or in a subprogram spec,
3023 -- in which case we want to force the client to see the
3024 -- warning, even though it is not in the main unit.
874a0341
RD
3025
3026 begin
b3b9865d
AC
3027 -- Loop through segments of message separated by line feeds.
3028 -- We output these segments as separate messages with
3029 -- continuation marks for all but the first.
874a0341 3030
1b24ada5
RD
3031 Cont := False;
3032 Ptr := 1;
874a0341
RD
3033 loop
3034 Error_Msg_Strlen := 0;
3035
b3b9865d
AC
3036 -- Loop to copy characters from argument to error message
3037 -- string buffer.
874a0341
RD
3038
3039 loop
3040 exit when Ptr > Len;
3041 CC := Get_String_Char (Str, Ptr);
3042 Ptr := Ptr + 1;
3043
3044 -- Ignore wide chars ??? else store character
3045
3046 if In_Character_Range (CC) then
3047 C := Get_Character (CC);
3048 exit when C = ASCII.LF;
3049 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3050 Error_Msg_String (Error_Msg_Strlen) := C;
3051 end if;
3052 end loop;
3053
3054 -- Here with one line ready to go
3055
3056 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3057
1b24ada5
RD
3058 -- If this is a warning in a spec, then we want clients
3059 -- to see the warning, so mark the message with the
3060 -- special sequence !! to force the warning. In the case
3061 -- of a package spec, we do not force this if we are in
3062 -- the private part of the spec.
3063
3064 if Force then
3065 if Cont = False then
3066 Error_Msg_N ("<~!!", Arg1);
3067 Cont := True;
3068 else
3069 Error_Msg_N ("\<~!!", Arg1);
3070 end if;
3071
3072 -- Error, rather than warning, or in a body, so we do not
3073 -- need to force visibility for client (error will be
3074 -- output in any case, and this is the situation in which
3075 -- we do not want a client to get a warning, since the
0b89eea8 3076 -- warning is in the body or the spec private part).
1b24ada5 3077
874a0341 3078 else
1b24ada5
RD
3079 if Cont = False then
3080 Error_Msg_N ("<~", Arg1);
3081 Cont := True;
3082 else
3083 Error_Msg_N ("\<~", Arg1);
3084 end if;
874a0341
RD
3085 end if;
3086
3087 exit when Ptr > Len;
3088 end loop;
3089 end;
3090 end if;
3091 end if;
3092 end Process_Compile_Time_Warning_Or_Error;
3093
996ae0b0
RK
3094 ------------------------
3095 -- Process_Convention --
3096 ------------------------
3097
3098 procedure Process_Convention
9fe2f33e
AC
3099 (C : out Convention_Id;
3100 Ent : out Entity_Id)
996ae0b0
RK
3101 is
3102 Id : Node_Id;
9fe2f33e 3103 E : Entity_Id;
996ae0b0 3104 E1 : Entity_Id;
996ae0b0 3105 Cname : Name_Id;
7324bf49 3106 Comp_Unit : Unit_Number_Type;
996ae0b0 3107
c28408b7
RD
3108 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3109 -- Called if we have more than one Export/Import/Convention pragma.
3110 -- This is generally illegal, but we have a special case of allowing
3111 -- Import and Interface to coexist if they specify the convention in
3112 -- a consistent manner. We are allowed to do this, since Interface is
3113 -- an implementation defined pragma, and we choose to do it since we
3114 -- know Rational allows this combination. S is the entity id of the
3115 -- subprogram in question. This procedure also sets the special flag
3116 -- Import_Interface_Present in both pragmas in the case where we do
3117 -- have matching Import and Interface pragmas.
3118
996ae0b0
RK
3119 procedure Set_Convention_From_Pragma (E : Entity_Id);
3120 -- Set convention in entity E, and also flag that the entity has a
3121 -- convention pragma. If entity is for a private or incomplete type,
3122 -- also set convention and flag on underlying type. This procedure
3123 -- also deals with the special case of C_Pass_By_Copy convention.
3124
c28408b7
RD
3125 -------------------------------
3126 -- Diagnose_Multiple_Pragmas --
3127 -------------------------------
3128
3129 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3130 Pdec : constant Node_Id := Declaration_Node (S);
3131 Decl : Node_Id;
3132 Err : Boolean;
3133
3134 function Same_Convention (Decl : Node_Id) return Boolean;
3135 -- Decl is a pragma node. This function returns True if this
3136 -- pragma has a first argument that is an identifier with a
3137 -- Chars field corresponding to the Convention_Id C.
3138
3139 function Same_Name (Decl : Node_Id) return Boolean;
3140 -- Decl is a pragma node. This function returns True if this
3141 -- pragma has a second argument that is an identifier with a
3142 -- Chars field that matches the Chars of the current subprogram.
3143
3144 ---------------------
3145 -- Same_Convention --
3146 ---------------------
3147
3148 function Same_Convention (Decl : Node_Id) return Boolean is
3149 Arg1 : constant Node_Id :=
3150 First (Pragma_Argument_Associations (Decl));
3151
3152 begin
3153 if Present (Arg1) then
3154 declare
3155 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3156 begin
3157 if Nkind (Arg) = N_Identifier
3158 and then Is_Convention_Name (Chars (Arg))
3159 and then Get_Convention_Id (Chars (Arg)) = C
3160 then
3161 return True;
3162 end if;
3163 end;
3164 end if;
3165
3166 return False;
3167 end Same_Convention;
3168
3169 ---------------
3170 -- Same_Name --
3171 ---------------
3172
3173 function Same_Name (Decl : Node_Id) return Boolean is
3174 Arg1 : constant Node_Id :=
3175 First (Pragma_Argument_Associations (Decl));
3176 Arg2 : Node_Id;
3177
3178 begin
3179 if No (Arg1) then
3180 return False;
3181 end if;
3182
3183 Arg2 := Next (Arg1);
3184
3185 if No (Arg2) then
3186 return False;
3187 end if;
3188
3189 declare
3190 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3191 begin
3192 if Nkind (Arg) = N_Identifier
3193 and then Chars (Arg) = Chars (S)
3194 then
3195 return True;
3196 end if;
3197 end;
3198
3199 return False;
3200 end Same_Name;
3201
3202 -- Start of processing for Diagnose_Multiple_Pragmas
3203
3204 begin
3205 Err := True;
3206
3207 -- Definitely give message if we have Convention/Export here
3208
3209 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3210 null;
3211
3212 -- If we have an Import or Export, scan back from pragma to
3213 -- find any previous pragma applying to the same procedure.
3214 -- The scan will be terminated by the start of the list, or
3215 -- hitting the subprogram declaration. This won't allow one
3216 -- pragma to appear in the public part and one in the private
3217 -- part, but that seems very unlikely in practice.
3218
3219 else
3220 Decl := Prev (N);
3221 while Present (Decl) and then Decl /= Pdec loop
3222
3223 -- Look for pragma with same name as us
3224
3225 if Nkind (Decl) = N_Pragma
3226 and then Same_Name (Decl)
3227 then
3228 -- Give error if same as our pragma or Export/Convention
3229
3230 if Pragma_Name (Decl) = Name_Export
3231 or else
3232 Pragma_Name (Decl) = Name_Convention
3233 or else
3234 Pragma_Name (Decl) = Pragma_Name (N)
3235 then
3236 exit;
3237
3238 -- Case of Import/Interface or the other way round
3239
3240 elsif Pragma_Name (Decl) = Name_Interface
3241 or else
3242 Pragma_Name (Decl) = Name_Import
3243 then
3244 -- Here we know that we have Import and Interface. It
3245 -- doesn't matter which way round they are. See if
3246 -- they specify the same convention. If so, all OK,
3247 -- and set special flags to stop other messages
3248
3249 if Same_Convention (Decl) then
3250 Set_Import_Interface_Present (N);
3251 Set_Import_Interface_Present (Decl);
3252 Err := False;
3253
3254 -- If different conventions, special message
3255
3256 else
3257 Error_Msg_Sloc := Sloc (Decl);
3258 Error_Pragma_Arg
3259 ("convention differs from that given#", Arg1);
3260 return;
3261 end if;
3262 end if;
3263 end if;
3264
3265 Next (Decl);
3266 end loop;
3267 end if;
3268
3269 -- Give message if needed if we fall through those tests
3270
3271 if Err then
3272 Error_Pragma_Arg
3273 ("at most one Convention/Export/Import pragma is allowed",
3274 Arg2);
3275 end if;
3276 end Diagnose_Multiple_Pragmas;
3277
996ae0b0
RK
3278 --------------------------------
3279 -- Set_Convention_From_Pragma --
3280 --------------------------------
3281
3282 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3283 begin
ac9e9918
RD
3284 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3285 -- for an overridden dispatching operation. Technically this is
c690a2ec
RD
3286 -- an amendment and should only be done in Ada 2005 mode. However,
3287 -- this is clearly a mistake, since the problem that is addressed
3288 -- by this AI is that there is a clear gap in the RM!
57193e09
TQ
3289
3290 if Is_Dispatching_Operation (E)
3291 and then Present (Overridden_Operation (E))
3292 and then C /= Convention (Overridden_Operation (E))
3293 then
3294 Error_Pragma_Arg
3295 ("cannot change convention for " &
3296 "overridden dispatching operation",
3297 Arg1);
3298 end if;
3299
3300 -- Set the convention
3301
996ae0b0
RK
3302 Set_Convention (E, C);
3303 Set_Has_Convention_Pragma (E);
3304
15b682ca
GB
3305 if Is_Incomplete_Or_Private_Type (E)
3306 and then Present (Underlying_Type (E))
3307 then
996ae0b0
RK
3308 Set_Convention (Underlying_Type (E), C);
3309 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3310 end if;
3311
b3b9865d
AC
3312 -- A class-wide type should inherit the convention of the specific
3313 -- root type (although this isn't specified clearly by the RM).
996ae0b0
RK
3314
3315 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3316 Set_Convention (Class_Wide_Type (E), C);
3317 end if;
3318
c690a2ec
RD
3319 -- If the entity is a record type, then check for special case of
3320 -- C_Pass_By_Copy, which is treated the same as C except that the
3321 -- special record flag is set. This convention is only permitted
3322 -- on record types (see AI95-00131).
996ae0b0
RK
3323
3324 if Cname = Name_C_Pass_By_Copy then
3325 if Is_Record_Type (E) then
3326 Set_C_Pass_By_Copy (Base_Type (E));
3327 elsif Is_Incomplete_Or_Private_Type (E)
3328 and then Is_Record_Type (Underlying_Type (E))
3329 then
3330 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3331 else
3332 Error_Pragma_Arg
3333 ("C_Pass_By_Copy convention allowed only for record type",
3334 Arg2);
3335 end if;
3336 end if;
3337
b3b9865d
AC
3338 -- If the entity is a derived boolean type, check for the special
3339 -- case of convention C, C++, or Fortran, where we consider any
3340 -- nonzero value to represent true.
996ae0b0
RK
3341
3342 if Is_Discrete_Type (E)
3343 and then Root_Type (Etype (E)) = Standard_Boolean
3344 and then
3345 (C = Convention_C
3346 or else
3347 C = Convention_CPP
3348 or else
3349 C = Convention_Fortran)
3350 then
3351 Set_Nonzero_Is_True (Base_Type (E));
3352 end if;
3353 end Set_Convention_From_Pragma;
3354
3355 -- Start of processing for Process_Convention
3356
3357 begin
3358 Check_At_Least_N_Arguments (2);
996ae0b0 3359 Check_Optional_Identifier (Arg1, Name_Convention);
59e5fbe0 3360 Check_Arg_Is_Identifier (Arg1);
0f1a6a0b 3361 Cname := Chars (Get_Pragma_Arg (Arg1));
996ae0b0 3362
b3b9865d
AC
3363 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3364 -- tested again below to set the critical flag).
23b86353 3365
996ae0b0
RK
3366 if Cname = Name_C_Pass_By_Copy then
3367 C := Convention_C;
3368
3369 -- Otherwise we must have something in the standard convention list
3370
3371 elsif Is_Convention_Name (Cname) then
0f1a6a0b 3372 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
996ae0b0 3373
c690a2ec
RD
3374 -- In DEC VMS, it seems that there is an undocumented feature that
3375 -- any unrecognized convention is treated as the default, which for
3376 -- us is convention C. It does not seem so terrible to do this
3377 -- unconditionally, silently in the VMS case, and with a warning
3378 -- in the non-VMS case.
996ae0b0
RK
3379
3380 else
fbf5a39b 3381 if Warn_On_Export_Import and not OpenVMS_On_Target then
ed2233dc 3382 Error_Msg_N
996ae0b0 3383 ("?unrecognized convention name, C assumed",
0f1a6a0b 3384 Get_Pragma_Arg (Arg1));
996ae0b0
RK
3385 end if;
3386
3387 C := Convention_C;
3388 end if;
3389
996ae0b0 3390 Check_Optional_Identifier (Arg2, Name_Entity);
59e5fbe0 3391 Check_Arg_Is_Local_Name (Arg2);
996ae0b0 3392
0f1a6a0b 3393 Id := Get_Pragma_Arg (Arg2);
996ae0b0
RK
3394 Analyze (Id);
3395
3396 if not Is_Entity_Name (Id) then
3397 Error_Pragma_Arg ("entity name required", Arg2);
3398 end if;
3399
3400 E := Entity (Id);
3401
9fe2f33e
AC
3402 -- Set entity to return
3403
3404 Ent := E;
3405
e917aec2
RD
3406 -- Ada_Pass_By_Copy special checking
3407
3408 if C = Convention_Ada_Pass_By_Copy then
3409 if not Is_First_Subtype (E) then
3410 Error_Pragma_Arg
3411 ("convention `Ada_Pass_By_Copy` only "
3412 & "allowed for types", Arg2);
3413 end if;
3414
3415 if Is_By_Reference_Type (E) then
3416 Error_Pragma_Arg
3417 ("convention `Ada_Pass_By_Copy` not allowed for "
3418 & "by-reference type", Arg1);
3419 end if;
3420 end if;
3421
3422 -- Ada_Pass_By_Reference special checking
3423
3424 if C = Convention_Ada_Pass_By_Reference then
3425 if not Is_First_Subtype (E) then
3426 Error_Pragma_Arg
3427 ("convention `Ada_Pass_By_Reference` only "
3428 & "allowed for types", Arg2);
3429 end if;
3430
3431 if Is_By_Copy_Type (E) then
3432 Error_Pragma_Arg
3433 ("convention `Ada_Pass_By_Reference` not allowed for "
3434 & "by-copy type", Arg1);
3435 end if;
3436 end if;
3437
c690a2ec
RD
3438 -- Go to renamed subprogram if present, since convention applies to
3439 -- the actual renamed entity, not to the renaming entity. If the
3440 -- subprogram is inherited, go to parent subprogram.
996ae0b0
RK
3441
3442 if Is_Subprogram (E)
3443 and then Present (Alias (E))
996ae0b0 3444 then
2fa9443e
ES
3445 if Nkind (Parent (Declaration_Node (E))) =
3446 N_Subprogram_Renaming_Declaration
c71c53a8 3447 then
b039b10e
ST
3448 if Scope (E) /= Scope (Alias (E)) then
3449 Error_Pragma_Ref
c27f2f15 3450 ("cannot apply pragma% to non-local entity&#", E);
b039b10e 3451 end if;
c27f2f15 3452
c71c53a8
ES
3453 E := Alias (E);
3454
f2131422
JM
3455 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3456 N_Private_Extension_Declaration)
c71c53a8
ES
3457 and then Scope (E) = Scope (Alias (E))
3458 then
3459 E := Alias (E);
9fe2f33e
AC
3460
3461 -- Return the parent subprogram the entity was inherited from
3462
3463 Ent := E;
c71c53a8 3464 end if;
996ae0b0
RK
3465 end if;
3466
c71c53a8 3467 -- Check that we are not applying this to a specless body
996ae0b0
RK
3468
3469 if Is_Subprogram (E)
3470 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3471 then
3472 Error_Pragma
3473 ("pragma% requires separate spec and must come before body");
3474 end if;
3475
3476 -- Check that we are not applying this to a named constant
3477
8a95f4e8 3478 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
1b24ada5 3479 Error_Msg_Name_1 := Pname;
996ae0b0
RK
3480 Error_Msg_N
3481 ("cannot apply pragma% to named constant!",
3482 Get_Pragma_Arg (Arg2));
3483 Error_Pragma_Arg
3484 ("\supply appropriate type for&!", Arg2);
3485 end if;
3486
66beb09b
ST
3487 if Ekind (E) = E_Enumeration_Literal then
3488 Error_Pragma ("enumeration literal not allowed for pragma%");
3489 end if;
3490
470cd9e9
RD
3491 -- Check for rep item appearing too early or too late
3492
996ae0b0
RK
3493 if Etype (E) = Any_Type
3494 or else Rep_Item_Too_Early (E, N)
3495 then
3496 raise Pragma_Exit;
15b682ca
GB
3497
3498 elsif Present (Underlying_Type (E)) then
996ae0b0
RK
3499 E := Underlying_Type (E);
3500 end if;
3501
3502 if Rep_Item_Too_Late (E, N) then
3503 raise Pragma_Exit;
3504 end if;
3505
3506 if Has_Convention_Pragma (E) then
c28408b7 3507 Diagnose_Multiple_Pragmas (E);
996ae0b0
RK
3508
3509 elsif Convention (E) = Convention_Protected
3510 or else Ekind (Scope (E)) = E_Protected_Type
3511 then
3512 Error_Pragma_Arg
3513 ("a protected operation cannot be given a different convention",
3514 Arg2);
3515 end if;
3516
3517 -- For Intrinsic, a subprogram is required
3518
3519 if C = Convention_Intrinsic
3520 and then not Is_Subprogram (E)
3521 and then not Is_Generic_Subprogram (E)
3522 then
3523 Error_Pragma_Arg
3524 ("second argument of pragma% must be a subprogram", Arg2);
3525 end if;
3526
3527 -- For Stdcall, a subprogram, variable or subprogram type is required
3528
3529 if C = Convention_Stdcall
3530 and then not Is_Subprogram (E)
3531 and then not Is_Generic_Subprogram (E)
3532 and then Ekind (E) /= E_Variable
3533 and then not
3534 (Is_Access_Type (E)
e074d476 3535 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
996ae0b0
RK
3536 then
3537 Error_Pragma_Arg
3538 ("second argument of pragma% must be subprogram (type)",
3539 Arg2);
3540 end if;
3541
3542 if not Is_Subprogram (E)
3543 and then not Is_Generic_Subprogram (E)
3544 then
3545 Set_Convention_From_Pragma (E);
3546
3547 if Is_Type (E) then
996ae0b0
RK
3548 Check_First_Subtype (Arg2);
3549 Set_Convention_From_Pragma (Base_Type (E));
3550
3551 -- For subprograms, we must set the convention on the
3552 -- internally generated directly designated type as well.
3553
3554 if Ekind (E) = E_Access_Subprogram_Type then
3555 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3556 end if;
3557 end if;
3558
3559 -- For the subprogram case, set proper convention for all homonyms
7324bf49
AC
3560 -- in same scope and the same declarative part, i.e. the same
3561 -- compilation unit.
996ae0b0
RK
3562
3563 else
7324bf49 3564 Comp_Unit := Get_Source_Unit (E);
996ae0b0
RK
3565 Set_Convention_From_Pragma (E);
3566
d9e0a587 3567 -- Treat a pragma Import as an implicit body, for GPS use
fbf5a39b
AC
3568
3569 if Prag_Id = Pragma_Import then
874a0341 3570 Generate_Reference (E, Id, 'b');
fbf5a39b
AC
3571 end if;
3572
9fe2f33e
AC
3573 -- Loop through the homonyms of the pragma argument's entity
3574
3575 E1 := Ent;
996ae0b0
RK
3576 loop
3577 E1 := Homonym (E1);
3578 exit when No (E1) or else Scope (E1) /= Current_Scope;
3579
b3b9865d
AC
3580 -- Do not set the pragma on inherited operations or on formal
3581 -- subprograms.
21d27997 3582
2820d220 3583 if Comes_From_Source (E1)
7324bf49 3584 and then Comp_Unit = Get_Source_Unit (E1)
21d27997 3585 and then not Is_Formal_Subprogram (E1)
2820d220 3586 and then Nkind (Original_Node (Parent (E1))) /=
f2131422 3587 N_Full_Type_Declaration
2820d220 3588 then
b039b10e
ST
3589 if Present (Alias (E1))
3590 and then Scope (E1) /= Scope (Alias (E1))
3591 then
3592 Error_Pragma_Ref
c27f2f15
RD
3593 ("cannot apply pragma% to non-local entity& declared#",
3594 E1);
b039b10e 3595 end if;
c27f2f15 3596
996ae0b0 3597 Set_Convention_From_Pragma (E1);
fbf5a39b
AC
3598
3599 if Prag_Id = Pragma_Import then
9fe2f33e 3600 Generate_Reference (E1, Id, 'b');
fbf5a39b 3601 end if;
996ae0b0 3602 end if;
0f1a6a0b
AC
3603
3604 -- For aspect case, do NOT apply to homonyms
3605
3606 exit when From_Aspect_Specification (N);
996ae0b0
RK
3607 end loop;
3608 end if;
996ae0b0
RK
3609 end Process_Convention;
3610
12b4d338
AC
3611 ----------------------------------------
3612 -- Process_Disable_Enable_Atomic_Sync --
3613 ----------------------------------------
3614
3615 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3616 begin
3617 GNAT_Pragma;
3618 Check_No_Identifiers;
3619 Check_At_Most_N_Arguments (1);
3620
3621 -- Modeled internally as
3622 -- pragma Unsuppress (Atomic_Synchronization [,Entity])
3623
3624 Rewrite (N,
3625 Make_Pragma (Loc,
3626 Pragma_Identifier =>
3627 Make_Identifier (Loc, Nam),
3628 Pragma_Argument_Associations => New_List (
3629 Make_Pragma_Argument_Association (Loc,
3630 Expression =>
3631 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3632
3633 if Present (Arg1) then
3634 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3635 end if;
3636
3637 Analyze (N);
3638 end Process_Disable_Enable_Atomic_Sync;
3639
996ae0b0
RK
3640 -----------------------------------------------------
3641 -- Process_Extended_Import_Export_Exception_Pragma --
3642 -----------------------------------------------------
3643
3644 procedure Process_Extended_Import_Export_Exception_Pragma
3645 (Arg_Internal : Node_Id;
3646 Arg_External : Node_Id;
3647 Arg_Form : Node_Id;
3648 Arg_Code : Node_Id)
3649 is
3650 Def_Id : Entity_Id;
3651 Code_Val : Uint;
3652
3653 begin
fbf5a39b
AC
3654 if not OpenVMS_On_Target then
3655 Error_Pragma
3656 ("?pragma% ignored (applies only to Open'V'M'S)");
3657 end if;
3658
996ae0b0
RK
3659 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3660 Def_Id := Entity (Arg_Internal);
3661
3662 if Ekind (Def_Id) /= E_Exception then
3663 Error_Pragma_Arg
3664 ("pragma% must refer to declared exception", Arg_Internal);
3665 end if;
3666
3667 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3668
3669 if Present (Arg_Form) then
3670 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3671 end if;
3672
3673 if Present (Arg_Form)
3674 and then Chars (Arg_Form) = Name_Ada
3675 then
3676 null;
3677 else
3678 Set_Is_VMS_Exception (Def_Id);
3679 Set_Exception_Code (Def_Id, No_Uint);
3680 end if;
3681
3682 if Present (Arg_Code) then
3683 if not Is_VMS_Exception (Def_Id) then
3684 Error_Pragma_Arg
3685 ("Code option for pragma% not allowed for Ada case",
3686 Arg_Code);
3687 end if;
3688
3689 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3690 Code_Val := Expr_Value (Arg_Code);
3691
3692 if not UI_Is_In_Int_Range (Code_Val) then
3693 Error_Pragma_Arg
3694 ("Code option for pragma% must be in 32-bit range",
3695 Arg_Code);
3696
3697 else
3698 Set_Exception_Code (Def_Id, Code_Val);
3699 end if;
3700 end if;
996ae0b0
RK
3701 end Process_Extended_Import_Export_Exception_Pragma;
3702
3703 -------------------------------------------------
3704 -- Process_Extended_Import_Export_Internal_Arg --
3705 -------------------------------------------------
3706
3707 procedure Process_Extended_Import_Export_Internal_Arg
3708 (Arg_Internal : Node_Id := Empty)
3709 is
3710 begin
996ae0b0
RK
3711 if No (Arg_Internal) then
3712 Error_Pragma ("Internal parameter required for pragma%");
3713 end if;
3714
3715 if Nkind (Arg_Internal) = N_Identifier then
3716 null;
3717
3718 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3719 and then (Prag_Id = Pragma_Import_Function
3720 or else
3721 Prag_Id = Pragma_Export_Function)
3722 then
3723 null;
3724
3725 else
3726 Error_Pragma_Arg
3727 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3728 end if;
3729
3730 Check_Arg_Is_Local_Name (Arg_Internal);
996ae0b0
RK
3731 end Process_Extended_Import_Export_Internal_Arg;
3732
3733 --------------------------------------------------
3734 -- Process_Extended_Import_Export_Object_Pragma --
3735 --------------------------------------------------
3736
3737 procedure Process_Extended_Import_Export_Object_Pragma
3738 (Arg_Internal : Node_Id;
3739 Arg_External : Node_Id;
3740 Arg_Size : Node_Id)
3741 is
fbf5a39b 3742 Def_Id : Entity_Id;
996ae0b0
RK
3743
3744 begin
3745 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3746 Def_Id := Entity (Arg_Internal);
3747
8a95f4e8 3748 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
996ae0b0
RK
3749 Error_Pragma_Arg
3750 ("pragma% must designate an object", Arg_Internal);
3751 end if;
3752
1d571f3b
AC
3753 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3754 or else
3755 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3756 then
996ae0b0 3757 Error_Pragma_Arg
1d571f3b 3758 ("previous Common/Psect_Object applies, pragma % not permitted",
996ae0b0
RK
3759 Arg_Internal);
3760 end if;
3761
3762 if Rep_Item_Too_Late (Def_Id, N) then
3763 raise Pragma_Exit;
3764 end if;
3765
3766 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3767
cc335f43
AC
3768 if Present (Arg_Size) then
3769 Check_Arg_Is_External_Name (Arg_Size);
996ae0b0
RK
3770 end if;
3771
3772 -- Export_Object case
3773
3774 if Prag_Id = Pragma_Export_Object then
996ae0b0
RK
3775 if not Is_Library_Level_Entity (Def_Id) then
3776 Error_Pragma_Arg
3777 ("argument for pragma% must be library level entity",
3778 Arg_Internal);
3779 end if;
3780
3781 if Ekind (Current_Scope) = E_Generic_Package then
3782 Error_Pragma ("pragma& cannot appear in a generic unit");
3783 end if;
3784
3785 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3786 Error_Pragma_Arg
3787 ("exported object must have compile time known size",
3788 Arg_Internal);
3789 end if;
3790
fbf5a39b 3791 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
5afaf827 3792 Error_Msg_N ("?duplicate Export_Object pragma", N);
996ae0b0
RK
3793 else
3794 Set_Exported (Def_Id, Arg_Internal);
3795 end if;
3796
3797 -- Import_Object case
3798
3799 else
3800 if Is_Concurrent_Type (Etype (Def_Id)) then
3801 Error_Pragma_Arg
3802 ("cannot use pragma% for task/protected object",
3803 Arg_Internal);
3804 end if;
3805
3806 if Ekind (Def_Id) = E_Constant then
3807 Error_Pragma_Arg
3808 ("cannot import a constant", Arg_Internal);
3809 end if;
3810
fbf5a39b
AC
3811 if Warn_On_Export_Import
3812 and then Has_Discriminants (Etype (Def_Id))
3813 then
996ae0b0
RK
3814 Error_Msg_N
3815 ("imported value must be initialized?", Arg_Internal);
3816 end if;
3817
fbf5a39b
AC
3818 if Warn_On_Export_Import
3819 and then Is_Access_Type (Etype (Def_Id))
3820 then
996ae0b0
RK
3821 Error_Pragma_Arg
3822 ("cannot import object of an access type?", Arg_Internal);
3823 end if;
3824
fbf5a39b
AC
3825 if Warn_On_Export_Import
3826 and then Is_Imported (Def_Id)
3827 then
996ae0b0
RK
3828 Error_Msg_N
3829 ("?duplicate Import_Object pragma", N);
fbf5a39b
AC
3830
3831 -- Check for explicit initialization present. Note that an
5afaf827
AC
3832 -- initialization generated by the code generator, e.g. for an
3833 -- access type, does not count here.
fbf5a39b
AC
3834
3835 elsif Present (Expression (Parent (Def_Id)))
3836 and then
3837 Comes_From_Source
3838 (Original_Node (Expression (Parent (Def_Id))))
3839 then
3840 Error_Msg_Sloc := Sloc (Def_Id);
3841 Error_Pragma_Arg
c690a2ec
RD
3842 ("imported entities cannot be initialized (RM B.1(24))",
3843 "\no initialization allowed for & declared#", Arg1);
996ae0b0
RK
3844 else
3845 Set_Imported (Def_Id);
21d27997 3846 Note_Possible_Modification (Arg_Internal, Sure => False);
996ae0b0
RK
3847 end if;
3848 end if;
996ae0b0
RK
3849 end Process_Extended_Import_Export_Object_Pragma;
3850
3851 ------------------------------------------------------
3852 -- Process_Extended_Import_Export_Subprogram_Pragma --
3853 ------------------------------------------------------
3854
3855 procedure Process_Extended_Import_Export_Subprogram_Pragma
3856 (Arg_Internal : Node_Id;
3857 Arg_External : Node_Id;
3858 Arg_Parameter_Types : Node_Id;
3859 Arg_Result_Type : Node_Id := Empty;
3860 Arg_Mechanism : Node_Id;
3861 Arg_Result_Mechanism : Node_Id := Empty;
3862 Arg_First_Optional_Parameter : Node_Id := Empty)
3863 is
3864 Ent : Entity_Id;
3865 Def_Id : Entity_Id;
3866 Hom_Id : Entity_Id;
3867 Formal : Entity_Id;
3868 Ambiguous : Boolean;
3869 Match : Boolean;
3870 Dval : Node_Id;
3871
fbf5a39b
AC
3872 function Same_Base_Type
3873 (Ptype : Node_Id;
a9f4e3d2 3874 Formal : Entity_Id) return Boolean;
b3b9865d
AC
3875 -- Determines if Ptype references the type of Formal. Note that only
3876 -- the base types need to match according to the spec. Ptype here is
3877 -- the argument from the pragma, which is either a type name, or an
3878 -- access attribute.
fbf5a39b
AC
3879
3880 --------------------
3881 -- Same_Base_Type --
3882 --------------------
996ae0b0 3883
a9f4e3d2
AC
3884 function Same_Base_Type
3885 (Ptype : Node_Id;
3886 Formal : Entity_Id) return Boolean
3887 is
fbf5a39b
AC
3888 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3889 Pref : Node_Id;
3890
996ae0b0 3891 begin
fbf5a39b 3892 -- Case where pragma argument is typ'Access
996ae0b0 3893
fbf5a39b
AC
3894 if Nkind (Ptype) = N_Attribute_Reference
3895 and then Attribute_Name (Ptype) = Name_Access
996ae0b0 3896 then
fbf5a39b
AC
3897 Pref := Prefix (Ptype);
3898 Find_Type (Pref);
3899
3900 if not Is_Entity_Name (Pref)
3901 or else Entity (Pref) = Any_Type
3902 then
3903 raise Pragma_Exit;
3904 end if;
3905
3906 -- We have a match if the corresponding argument is of an
b3b9865d
AC
3907 -- anonymous access type, and its designated type matches the
3908 -- type of the prefix of the access attribute
fbf5a39b
AC
3909
3910 return Ekind (Ftyp) = E_Anonymous_Access_Type
3911 and then Base_Type (Entity (Pref)) =
3912 Base_Type (Etype (Designated_Type (Ftyp)));
3913
3914 -- Case where pragma argument is a type name
3915
3916 else
3917 Find_Type (Ptype);
3918
3919 if not Is_Entity_Name (Ptype)
3920 or else Entity (Ptype) = Any_Type
3921 then
3922 raise Pragma_Exit;
3923 end if;
996ae0b0 3924
b3b9865d
AC
3925 -- We have a match if the corresponding argument is of the type
3926 -- given in the pragma (comparing base types)
fbf5a39b
AC
3927
3928 return Base_Type (Entity (Ptype)) = Ftyp;
3929 end if;
996ae0b0
RK
3930 end Same_Base_Type;
3931
3932 -- Start of processing for
3933 -- Process_Extended_Import_Export_Subprogram_Pragma
3934
3935 begin
3936 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
996ae0b0
RK
3937 Ent := Empty;
3938 Ambiguous := False;
3939
1d571f3b 3940 -- Loop through homonyms (overloadings) of the entity
996ae0b0 3941
1d571f3b 3942 Hom_Id := Entity (Arg_Internal);
996ae0b0
RK
3943 while Present (Hom_Id) loop
3944 Def_Id := Get_Base_Subprogram (Hom_Id);
3945
3946 -- We need a subprogram in the current scope
3947
3948 if not Is_Subprogram (Def_Id)
3949 or else Scope (Def_Id) /= Current_Scope
3950 then
3951 null;
3952
3953 else
3954 Match := True;
3955
3956 -- Pragma cannot apply to subprogram body
3957
3958 if Is_Subprogram (Def_Id)
f2131422
JM
3959 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3960 N_Subprogram_Body
996ae0b0
RK
3961 then
3962 Error_Pragma
3963 ("pragma% requires separate spec"
3964 & " and must come before body");
3965 end if;
3966
3967 -- Test result type if given, note that the result type
3968 -- parameter can only be present for the function cases.
3969
3970 if Present (Arg_Result_Type)
3971 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3972 then
3973 Match := False;
3974
fbf5a39b
AC
3975 elsif Etype (Def_Id) /= Standard_Void_Type
3976 and then
1b24ada5
RD
3977 (Pname = Name_Export_Procedure
3978 or else
3979 Pname = Name_Import_Procedure)
fbf5a39b
AC
3980 then
3981 Match := False;
3982
996ae0b0
RK
3983 -- Test parameter types if given. Note that this parameter
3984 -- has not been analyzed (and must not be, since it is
3985 -- semantic nonsense), so we get it as the parser left it.
3986
3987 elsif Present (Arg_Parameter_Types) then
3988 Check_Matching_Types : declare
3989 Formal : Entity_Id;
3990 Ptype : Node_Id;
3991
3992 begin
3993 Formal := First_Formal (Def_Id);
3994
3995 if Nkind (Arg_Parameter_Types) = N_Null then
3996 if Present (Formal) then
3997 Match := False;
3998 end if;
3999
4000 -- A list of one type, e.g. (List) is parsed as
4001 -- a parenthesized expression.
4002
4003 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4004 and then Paren_Count (Arg_Parameter_Types) = 1
4005 then
4006 if No (Formal)
4007 or else Present (Next_Formal (Formal))
4008 then
4009 Match := False;
4010 else
4011 Match :=
4012 Same_Base_Type (Arg_Parameter_Types, Formal);
4013 end if;
4014
4015 -- A list of more than one type is parsed as a aggregate
4016
4017 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4018 and then Paren_Count (Arg_Parameter_Types) = 0
4019 then
4020 Ptype := First (Expressions (Arg_Parameter_Types));
996ae0b0
RK
4021 while Present (Ptype) or else Present (Formal) loop
4022 if No (Ptype)
4023 or else No (Formal)
4024 or else not Same_Base_Type (Ptype, Formal)
4025 then
4026 Match := False;
4027 exit;
4028 else
4029 Next_Formal (Formal);
4030 Next (Ptype);
4031 end if;
4032 end loop;
4033
4034 -- Anything else is of the wrong form
4035
4036 else
4037 Error_Pragma_Arg
4038 ("wrong form for Parameter_Types parameter",
4039 Arg_Parameter_Types);
4040 end if;
4041 end Check_Matching_Types;
4042 end if;
4043
4044 -- Match is now False if the entry we found did not match
4045 -- either a supplied Parameter_Types or Result_Types argument
4046
4047 if Match then
4048 if No (Ent) then
4049 Ent := Def_Id;
4050
4051 -- Ambiguous case, the flag Ambiguous shows if we already
4052 -- detected this and output the initial messages.
4053
4054 else
4055 if not Ambiguous then
4056 Ambiguous := True;
1b24ada5 4057 Error_Msg_Name_1 := Pname;
996ae0b0
RK
4058 Error_Msg_N
4059 ("pragma% does not uniquely identify subprogram!",
4060 N);
4061 Error_Msg_Sloc := Sloc (Ent);
4062 Error_Msg_N ("matching subprogram #!", N);
4063 Ent := Empty;
4064 end if;
4065
4066 Error_Msg_Sloc := Sloc (Def_Id);
4067 Error_Msg_N ("matching subprogram #!", N);
4068 end if;
4069 end if;
4070 end if;
4071
4072 Hom_Id := Homonym (Hom_Id);
4073 end loop;
4074
4075 -- See if we found an entry
4076
4077 if No (Ent) then
4078 if not Ambiguous then
4079 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4080 Error_Pragma
4081 ("pragma% cannot be given for generic subprogram");
996ae0b0
RK
4082 else
4083 Error_Pragma
4084 ("pragma% does not identify local subprogram");
4085 end if;
4086 end if;
4087
4088 return;
4089 end if;
4090
16b05213 4091 -- Import pragmas must be for imported entities
996ae0b0 4092
fbf5a39b
AC
4093 if Prag_Id = Pragma_Import_Function
4094 or else
4095 Prag_Id = Pragma_Import_Procedure
4096 or else
4097 Prag_Id = Pragma_Import_Valued_Procedure
996ae0b0
RK
4098 then
4099 if not Is_Imported (Ent) then
ed2233dc 4100 Error_Pragma
996ae0b0
RK
4101 ("pragma Import or Interface must precede pragma%");
4102 end if;
4103
fbf5a39b
AC
4104 -- Here we have the Export case which can set the entity as exported
4105
c690a2ec
RD
4106 -- But does not do so if the specified external name is null, since
4107 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4108 -- compatible) to request no external name.
fbf5a39b
AC
4109
4110 elsif Nkind (Arg_External) = N_String_Literal
4111 and then String_Length (Strval (Arg_External)) = 0
4112 then
4113 null;
4114
f3d57416 4115 -- In all other cases, set entity as exported
996ae0b0
RK
4116
4117 else
4118 Set_Exported (Ent, Arg_Internal);
4119 end if;
4120
4121 -- Special processing for Valued_Procedure cases
4122
4123 if Prag_Id = Pragma_Import_Valued_Procedure
4124 or else
4125 Prag_Id = Pragma_Export_Valued_Procedure
4126 then
4127 Formal := First_Formal (Ent);
4128
4129 if No (Formal) then
5afaf827 4130 Error_Pragma ("at least one parameter required for pragma%");
996ae0b0
RK
4131
4132 elsif Ekind (Formal) /= E_Out_Parameter then
5afaf827 4133 Error_Pragma ("first parameter must have mode out for pragma%");
996ae0b0
RK
4134
4135 else
4136 Set_Is_Valued_Procedure (Ent);
4137 end if;
4138 end if;
4139
4140 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4141
4142 -- Process Result_Mechanism argument if present. We have already
4143 -- checked that this is only allowed for the function case.
4144
4145 if Present (Arg_Result_Mechanism) then
4146 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4147 end if;
4148
4149 -- Process Mechanism parameter if present. Note that this parameter
4150 -- is not analyzed, and must not be analyzed since it is semantic
4151 -- nonsense, so we get it in exactly as the parser left it.
4152
4153 if Present (Arg_Mechanism) then
996ae0b0
RK
4154 declare
4155 Formal : Entity_Id;
4156 Massoc : Node_Id;
4157 Mname : Node_Id;
4158 Choice : Node_Id;
4159
4160 begin
4161 -- A single mechanism association without a formal parameter
4162 -- name is parsed as a parenthesized expression. All other
4163 -- cases are parsed as aggregates, so we rewrite the single
4164 -- parameter case as an aggregate for consistency.
4165
4166 if Nkind (Arg_Mechanism) /= N_Aggregate
4167 and then Paren_Count (Arg_Mechanism) = 1
4168 then
4169 Rewrite (Arg_Mechanism,
4170 Make_Aggregate (Sloc (Arg_Mechanism),
4171 Expressions => New_List (
4172 Relocate_Node (Arg_Mechanism))));
4173 end if;
4174
4175 -- Case of only mechanism name given, applies to all formals
4176
4177 if Nkind (Arg_Mechanism) /= N_Aggregate then
4178 Formal := First_Formal (Ent);
4179 while Present (Formal) loop
4180 Set_Mechanism_Value (Formal, Arg_Mechanism);
4181 Next_Formal (Formal);
4182 end loop;
4183
4184 -- Case of list of mechanism associations given
4185
4186 else
4187 if Null_Record_Present (Arg_Mechanism) then
4188 Error_Pragma_Arg
4189 ("inappropriate form for Mechanism parameter",
4190 Arg_Mechanism);
4191 end if;
4192
4193 -- Deal with positional ones first
4194
4195 Formal := First_Formal (Ent);
2c9beb8a 4196
996ae0b0
RK
4197 if Present (Expressions (Arg_Mechanism)) then
4198 Mname := First (Expressions (Arg_Mechanism));
996ae0b0
RK
4199 while Present (Mname) loop
4200 if No (Formal) then
4201 Error_Pragma_Arg
4202 ("too many mechanism associations", Mname);
4203 end if;
4204
4205 Set_Mechanism_Value (Formal, Mname);
4206 Next_Formal (Formal);
4207 Next (Mname);
4208 end loop;
4209 end if;
4210
4211 -- Deal with named entries
4212
4213 if Present (Component_Associations (Arg_Mechanism)) then
4214 Massoc := First (Component_Associations (Arg_Mechanism));
996ae0b0
RK
4215 while Present (Massoc) loop
4216 Choice := First (Choices (Massoc));
4217
4218 if Nkind (Choice) /= N_Identifier
4219 or else Present (Next (Choice))
4220 then
4221 Error_Pragma_Arg
4222 ("incorrect form for mechanism association",
4223 Massoc);
4224 end if;
4225
4226 Formal := First_Formal (Ent);
4227 loop
4228 if No (Formal) then
4229 Error_Pragma_Arg
4230 ("parameter name & not present", Choice);
4231 end if;
4232
4233 if Chars (Choice) = Chars (Formal) then
4234 Set_Mechanism_Value
4235 (Formal, Expression (Massoc));
bf8b6bfc 4236
beacce02 4237 -- Set entity on identifier (needed by ASIS)
a168f519 4238
bf8b6bfc
SR
4239 Set_Entity (Choice, Formal);
4240
996ae0b0
RK
4241 exit;
4242 end if;
4243
4244 Next_Formal (Formal);
4245 end loop;
4246
4247 Next (Massoc);
4248 end loop;
4249 end if;
4250 end if;
4251 end;
4252 end if;
4253
4254 -- Process First_Optional_Parameter argument if present. We have
4255 -- already checked that this is only allowed for the Import case.
4256
4257 if Present (Arg_First_Optional_Parameter) then
4258 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4259 Error_Pragma_Arg
4260 ("first optional parameter must be formal parameter name",
4261 Arg_First_Optional_Parameter);
4262 end if;
4263
4264 Formal := First_Formal (Ent);
4265 loop
4266 if No (Formal) then
4267 Error_Pragma_Arg
4268 ("specified formal parameter& not found",
4269 Arg_First_Optional_Parameter);
4270 end if;
4271
4272 exit when Chars (Formal) =
4273 Chars (Arg_First_Optional_Parameter);
4274
4275 Next_Formal (Formal);
4276 end loop;
4277
4278 Set_First_Optional_Parameter (Ent, Formal);
4279
4280 -- Check specified and all remaining formals have right form
4281
4282 while Present (Formal) loop
4283 if Ekind (Formal) /= E_In_Parameter then
4284 Error_Msg_NE
4285 ("optional formal& is not of mode in!",
4286 Arg_First_Optional_Parameter, Formal);
4287
4288 else
4289 Dval := Default_Value (Formal);
4290
57193e09 4291 if No (Dval) then
996ae0b0
RK
4292 Error_Msg_NE
4293 ("optional formal& does not have default value!",
4294 Arg_First_Optional_Parameter, Formal);
4295
4296 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4297 null;
4298
4299 else
fbf5a39b 4300 Error_Msg_FE
996ae0b0
RK
4301 ("default value for optional formal& is non-static!",
4302 Arg_First_Optional_Parameter, Formal);
4303 end if;
4304 end if;
4305
4306 Set_Is_Optional_Parameter (Formal);
4307 Next_Formal (Formal);
4308 end loop;
4309 end if;
996ae0b0
RK
4310 end Process_Extended_Import_Export_Subprogram_Pragma;
4311
4312 --------------------------
4313 -- Process_Generic_List --
4314 --------------------------
4315
4316 procedure Process_Generic_List is
4317 Arg : Node_Id;
4318 Exp : Node_Id;
4319
4320 begin
996ae0b0
RK
4321 Check_No_Identifiers;
4322 Check_At_Least_N_Arguments (1);
4323
4324 Arg := Arg1;
4325 while Present (Arg) loop
0f1a6a0b 4326 Exp := Get_Pragma_Arg (Arg);
996ae0b0
RK
4327 Analyze (Exp);
4328
4329 if not Is_Entity_Name (Exp)
4330 or else
4331 (not Is_Generic_Instance (Entity (Exp))
4332 and then
4333 not Is_Generic_Unit (Entity (Exp)))
4334 then
4335 Error_Pragma_Arg
4336 ("pragma% argument must be name of generic unit/instance",
4337 Arg);
4338 end if;
4339
4340 Next (Arg);
4341 end loop;
4342 end Process_Generic_List;
4343
15b682ca
GB
4344 ------------------------------------
4345 -- Process_Import_Predefined_Type --
4346 ------------------------------------
4347
4348 procedure Process_Import_Predefined_Type is
4349 Loc : constant Source_Ptr := Sloc (N);
ded8909b 4350 Elmt : Elmt_Id;
70c34e1c 4351 Ftyp : Node_Id := Empty;
15b682ca
GB
4352 Decl : Node_Id;
4353 Def : Node_Id;
4354 Nam : Name_Id;
ded8909b 4355
15b682ca
GB
4356 begin
4357 String_To_Name_Buffer (Strval (Expression (Arg3)));
4358 Nam := Name_Find;
4359
ded8909b 4360 Elmt := First_Elmt (Predefined_Float_Types);
70c34e1c
AC
4361 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4362 Next_Elmt (Elmt);
15b682ca
GB
4363 end loop;
4364
70c34e1c
AC
4365 Ftyp := Node (Elmt);
4366
15b682ca 4367 if Present (Ftyp) then
ded8909b 4368
15b682ca
GB
4369 -- Don't build a derived type declaration, because predefined C
4370 -- types have no declaration anywhere, so cannot really be named.
4371 -- Instead build a full type declaration, starting with an
4372 -- appropriate type definition is built
4373
4374 if Is_Floating_Point_Type (Ftyp) then
4375 Def := Make_Floating_Point_Definition (Loc,
4376 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4377 Make_Real_Range_Specification (Loc,
4378 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4379 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4380
ded8909b
AC
4381 -- Should never have a predefined type we cannot handle
4382
15b682ca 4383 else
15b682ca
GB
4384 raise Program_Error;
4385 end if;
4386
4387 -- Build and insert a Full_Type_Declaration, which will be
4388 -- analyzed as soon as this list entry has been analyzed.
4389
4390 Decl := Make_Full_Type_Declaration (Loc,
4391 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4392 Type_Definition => Def);
4393
4394 Insert_After (N, Decl);
4395 Mark_Rewrite_Insertion (Decl);
4396
4397 else
4398 Error_Pragma_Arg ("no matching type found for pragma%",
4399 Arg2);
4400 end if;
4401 end Process_Import_Predefined_Type;
4402
996ae0b0
RK
4403 ---------------------------------
4404 -- Process_Import_Or_Interface --
4405 ---------------------------------
4406
4407 procedure Process_Import_Or_Interface is
4408 C : Convention_Id;
4409 Def_Id : Entity_Id;
4410 Hom_Id : Entity_Id;
4411
4412 begin
4413 Process_Convention (C, Def_Id);
4414 Kill_Size_Check_Code (Def_Id);
0f1a6a0b 4415 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
996ae0b0 4416
8a95f4e8
RD
4417 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4418
2fa9443e
ES
4419 -- We do not permit Import to apply to a renaming declaration
4420
4421 if Present (Renamed_Object (Def_Id)) then
4422 Error_Pragma_Arg
4423 ("pragma% not allowed for object renaming", Arg2);
4424
996ae0b0
RK
4425 -- User initialization is not allowed for imported object, but
4426 -- the object declaration may contain a default initialization,
fbf5a39b
AC
4427 -- that will be discarded. Note that an explicit initialization
4428 -- only counts if it comes from source, otherwise it is simply
4429 -- the code generator making an implicit initialization explicit.
996ae0b0 4430
2fa9443e
ES
4431 elsif Present (Expression (Parent (Def_Id)))
4432 and then Comes_From_Source (Expression (Parent (Def_Id)))
996ae0b0
RK
4433 then
4434 Error_Msg_Sloc := Sloc (Def_Id);
4435 Error_Pragma_Arg
4436 ("no initialization allowed for declaration of& #",
c690a2ec 4437 "\imported entities cannot be initialized (RM B.1(24))",
996ae0b0
RK
4438 Arg2);
4439
4440 else
4441 Set_Imported (Def_Id);
996ae0b0 4442 Process_Interface_Name (Def_Id, Arg3, Arg4);
fbf5a39b 4443
2c9beb8a 4444 -- Note that we do not set Is_Public here. That's because we
16b05213 4445 -- only want to set it if there is no address clause, and we
2c9beb8a
RD
4446 -- don't know that yet, so we delay that processing till
4447 -- freeze time.
4448
5453d5bd
AC
4449 -- pragma Import completes deferred constants
4450
4451 if Ekind (Def_Id) = E_Constant then
4452 Set_Has_Completion (Def_Id);
4453 end if;
4454
fbf5a39b
AC
4455 -- It is not possible to import a constant of an unconstrained
4456 -- array type (e.g. string) because there is no simple way to
4457 -- write a meaningful subtype for it.
4458
4459 if Is_Array_Type (Etype (Def_Id))
4460 and then not Is_Constrained (Etype (Def_Id))
4461 then
4462 Error_Msg_NE
4463 ("imported constant& must have a constrained subtype",
4464 N, Def_Id);
4465 end if;
996ae0b0
RK
4466 end if;
4467
4468 elsif Is_Subprogram (Def_Id)
4469 or else Is_Generic_Subprogram (Def_Id)
4470 then
beacce02
AC
4471 -- If the name is overloaded, pragma applies to all of the denoted
4472 -- entities in the same declarative part.
996ae0b0
RK
4473
4474 Hom_Id := Def_Id;
996ae0b0
RK
4475 while Present (Hom_Id) loop
4476 Def_Id := Get_Base_Subprogram (Hom_Id);
4477
beacce02
AC
4478 -- Ignore inherited subprograms because the pragma will apply
4479 -- to the parent operation, which is the one called.
996ae0b0
RK
4480
4481 if Is_Overloadable (Def_Id)
4482 and then Present (Alias (Def_Id))
4483 then
4484 null;
4485
b3b9865d
AC
4486 -- If it is not a subprogram, it must be in an outer scope and
4487 -- pragma does not apply.
fbf5a39b
AC
4488
4489 elsif not Is_Subprogram (Def_Id)
4490 and then not Is_Generic_Subprogram (Def_Id)
4491 then
4492 null;
4493
0592046e
AC
4494 -- The pragma does not apply to primitives of interfaces
4495
4496 elsif Is_Dispatching_Operation (Def_Id)
4497 and then Present (Find_Dispatching_Type (Def_Id))
4498 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4499 then
4500 null;
4501
b3b9865d
AC
4502 -- Verify that the homonym is in the same declarative part (not
4503 -- just the same scope).
996ae0b0
RK
4504
4505 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4506 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4507 then
4508 exit;
4509
4510 else
4511 Set_Imported (Def_Id);
4512
9fe2f33e
AC
4513 -- Reject an Import applied to an abstract subprogram
4514
6fa30ef2
ST
4515 if Is_Subprogram (Def_Id)
4516 and then Is_Abstract_Subprogram (Def_Id)
4517 then
4518 Error_Msg_Sloc := Sloc (Def_Id);
4519 Error_Msg_NE
4520 ("cannot import abstract subprogram& declared#",
4521 Arg2, Def_Id);
4522 end if;
4523
98f01d53 4524 -- Special processing for Convention_Intrinsic
996ae0b0
RK
4525
4526 if C = Convention_Intrinsic then
98f01d53
AC
4527
4528 -- Link_Name argument not allowed for intrinsic
4529
9eea4346 4530 Check_No_Link_Name;
98f01d53 4531
996ae0b0 4532 Set_Is_Intrinsic_Subprogram (Def_Id);
98f01d53 4533
b3b9865d
AC
4534 -- If no external name is present, then check that this
4535 -- is a valid intrinsic subprogram. If an external name
4536 -- is present, then this is handled by the back end.
98f01d53
AC
4537
4538 if No (Arg3) then
0f1a6a0b
AC
4539 Check_Intrinsic_Subprogram
4540 (Def_Id, Get_Pragma_Arg (Arg2));
98f01d53 4541 end if;
996ae0b0
RK
4542 end if;
4543
b3b9865d
AC
4544 -- All interfaced procedures need an external symbol created
4545 -- for them since they are always referenced from another
4546 -- object file.
996ae0b0
RK
4547
4548 Set_Is_Public (Def_Id);
fbf5a39b
AC
4549
4550 -- Verify that the subprogram does not have a completion
b3b9865d
AC
4551 -- through a renaming declaration. For other completions the
4552 -- pragma appears as a too late representation.
fbf5a39b
AC
4553
4554 declare
4555 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
91b1417d 4556
fbf5a39b
AC
4557 begin
4558 if Present (Decl)
4559 and then Nkind (Decl) = N_Subprogram_Declaration
4560 and then Present (Corresponding_Body (Decl))
f2131422
JM
4561 and then Nkind (Unit_Declaration_Node
4562 (Corresponding_Body (Decl))) =
fbf5a39b
AC
4563 N_Subprogram_Renaming_Declaration
4564 then
4565 Error_Msg_Sloc := Sloc (Def_Id);
c690a2ec
RD
4566 Error_Msg_NE
4567 ("cannot import&, renaming already provided for " &
4568 "declaration #", N, Def_Id);
fbf5a39b
AC
4569 end if;
4570 end;
4571
996ae0b0
RK
4572 Set_Has_Completion (Def_Id);
4573 Process_Interface_Name (Def_Id, Arg3, Arg4);
4574 end if;
4575
4576 if Is_Compilation_Unit (Hom_Id) then
4577
4578 -- Its possible homonyms are not affected by the pragma.
4579 -- Such homonyms might be present in the context of other
4580 -- units being compiled.
4581
4582 exit;
4583
4584 else
4585 Hom_Id := Homonym (Hom_Id);
4586 end if;
4587 end loop;
4588
2fa9443e 4589 -- When the convention is Java or CIL, we also allow Import to be
7e8ed0a6
AC
4590 -- given for packages, generic packages, exceptions, record
4591 -- components, and access to subprograms.
996ae0b0 4592
2fa9443e 4593 elsif (C = Convention_Java or else C = Convention_CIL)
6e937c1c 4594 and then
b9b2405f 4595 (Is_Package_Or_Generic_Package (Def_Id)
d7ba4df4 4596 or else Ekind (Def_Id) = E_Exception
7e8ed0a6 4597 or else Ekind (Def_Id) = E_Access_Subprogram_Type
d7ba4df4 4598 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
996ae0b0
RK
4599 then
4600 Set_Imported (Def_Id);
4601 Set_Is_Public (Def_Id);
4602 Process_Interface_Name (Def_Id, Arg3, Arg4);
4603
874a0341
RD
4604 -- Import a CPP class
4605
4606 elsif Is_Record_Type (Def_Id)
4607 and then C = Convention_CPP
4608 then
56e94186
AC
4609 -- Types treated as CPP classes must be declared limited (note:
4610 -- this used to be a warning but there is no real benefit to it
4611 -- since we did effectively intend to treat the type as limited
4612 -- anyway).
2fa9443e 4613
7b4db06c 4614 if not Is_Limited_Type (Def_Id) then
ed2233dc 4615 Error_Msg_N
56e94186 4616 ("imported 'C'P'P type must be limited",
7b4db06c
JM
4617 Get_Pragma_Arg (Arg2));
4618 end if;
2fa9443e 4619
7b4db06c 4620 Set_Is_CPP_Class (Def_Id);
0c020dde 4621
7b4db06c
JM
4622 -- Imported CPP types must not have discriminants (because C++
4623 -- classes do not have discriminants).
0c020dde 4624
7b4db06c
JM
4625 if Has_Discriminants (Def_Id) then
4626 Error_Msg_N
4627 ("imported 'C'P'P type cannot have discriminants",
4628 First (Discriminant_Specifications
4629 (Declaration_Node (Def_Id))));
4630 end if;
0c020dde 4631
7b4db06c 4632 -- Components of imported CPP types must not have default
3c92a2b8 4633 -- expressions because the constructor (if any) is on the
7b4db06c 4634 -- C++ side.
0c020dde 4635
7b4db06c
JM
4636 declare
4637 Tdef : constant Node_Id :=
4638 Type_Definition (Declaration_Node (Def_Id));
4639 Clist : Node_Id;
4640 Comp : Node_Id;
0c020dde 4641
7b4db06c
JM
4642 begin
4643 if Nkind (Tdef) = N_Record_Definition then
4644 Clist := Component_List (Tdef);
0c020dde 4645
7b4db06c
JM
4646 else
4647 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4648 Clist := Component_List (Record_Extension_Part (Tdef));
4649 end if;
0c020dde 4650
7b4db06c
JM
4651 if Present (Clist) then
4652 Comp := First (Component_Items (Clist));
4653 while Present (Comp) loop
4654 if Present (Expression (Comp)) then
4655 Error_Msg_N
4656 ("component of imported 'C'P'P type cannot have" &
4657 " default expression", Expression (Comp));
4658 end if;
0c020dde 4659
7b4db06c
JM
4660 Next (Comp);
4661 end loop;
4662 end if;
4663 end;
874a0341 4664
15b682ca
GB
4665 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4666 Check_No_Link_Name;
4667 Check_Arg_Count (3);
4668 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4669
4670 Process_Import_Predefined_Type;
4671
996ae0b0
RK
4672 else
4673 Error_Pragma_Arg
15b682ca
GB
4674 ("second argument of pragma% must be object, subprogram" &
4675 " or incomplete type",
996ae0b0
RK
4676 Arg2);
4677 end if;
4678
b3b9865d
AC
4679 -- If this pragma applies to a compilation unit, then the unit, which
4680 -- is a subprogram, does not require (or allow) a body. We also do
4681 -- not need to elaborate imported procedures.
996ae0b0
RK
4682
4683 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4684 declare
4685 Cunit : constant Node_Id := Parent (Parent (N));
996ae0b0 4686 begin
a9f4e3d2 4687 Set_Body_Required (Cunit, False);
996ae0b0
RK
4688 end;
4689 end if;
996ae0b0
RK
4690 end Process_Import_Or_Interface;
4691
4692 --------------------
4693 -- Process_Inline --
4694 --------------------
4695
4696 procedure Process_Inline (Active : Boolean) is
6e937c1c
AC
4697 Assoc : Node_Id;
4698 Decl : Node_Id;
4699 Subp_Id : Node_Id;
4700 Subp : Entity_Id;
4701 Applies : Boolean;
eaba57fb 4702
6e937c1c 4703 Effective : Boolean := False;
eaba57fb
RD
4704 -- Set True if inline has some effect, i.e. if there is at least one
4705 -- subprogram set as inlined as a result of the use of the pragma.
996ae0b0
RK
4706
4707 procedure Make_Inline (Subp : Entity_Id);
b3b9865d
AC
4708 -- Subp is the defining unit name of the subprogram declaration. Set
4709 -- the flag, as well as the flag in the corresponding body, if there
4710 -- is one present.
996ae0b0
RK
4711
4712 procedure Set_Inline_Flags (Subp : Entity_Id);
470cd9e9
RD
4713 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4714 -- Has_Pragma_Inline_Always for the Inline_Always case.
996ae0b0 4715
98f01d53
AC
4716 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4717 -- Returns True if it can be determined at this stage that inlining
f3d57416 4718 -- is not possible, for example if the body is available and contains
98f01d53
AC
4719 -- exception handlers, we prevent inlining, since otherwise we can
4720 -- get undefined symbols at link time. This function also emits a
4721 -- warning if front-end inlining is enabled and the pragma appears
4722 -- too late.
470cd9e9 4723 --
98f01d53
AC
4724 -- ??? is business with link symbols still valid, or does it relate
4725 -- to front end ZCX which is being phased out ???
fbf5a39b 4726
98f01d53
AC
4727 ---------------------------
4728 -- Inlining_Not_Possible --
4729 ---------------------------
fbf5a39b 4730
98f01d53
AC
4731 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4732 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4733 Stats : Node_Id;
fbf5a39b
AC
4734
4735 begin
4736 if Nkind (Decl) = N_Subprogram_Body then
98f01d53
AC
4737 Stats := Handled_Statement_Sequence (Decl);
4738 return Present (Exception_Handlers (Stats))
4739 or else Present (At_End_Proc (Stats));
fbf5a39b
AC
4740
4741 elsif Nkind (Decl) = N_Subprogram_Declaration
4742 and then Present (Corresponding_Body (Decl))
4743 then
c37bb106
AC
4744 if Front_End_Inlining
4745 and then Analyzed (Corresponding_Body (Decl))
4746 then
ed2233dc 4747 Error_Msg_N ("pragma appears too late, ignored?", N);
c37bb106
AC
4748 return True;
4749
b3b9865d
AC
4750 -- If the subprogram is a renaming as body, the body is just a
4751 -- call to the renamed subprogram, and inlining is trivially
4752 -- possible.
a9f4e3d2 4753
c37bb106 4754 elsif
2fa9443e
ES
4755 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4756 N_Subprogram_Renaming_Declaration
a9f4e3d2
AC
4757 then
4758 return False;
4759
4760 else
98f01d53
AC
4761 Stats :=
4762 Handled_Statement_Sequence
4763 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4764
a9f4e3d2 4765 return
98f01d53
AC
4766 Present (Exception_Handlers (Stats))
4767 or else Present (At_End_Proc (Stats));
a9f4e3d2 4768 end if;
98f01d53 4769
fbf5a39b
AC
4770 else
4771 -- If body is not available, assume the best, the check is
4772 -- performed again when compiling enclosing package bodies.
4773
4774 return False;
4775 end if;
98f01d53 4776 end Inlining_Not_Possible;
fbf5a39b 4777
996ae0b0
RK
4778 -----------------
4779 -- Make_Inline --
4780 -----------------
4781
4782 procedure Make_Inline (Subp : Entity_Id) is
fbf5a39b 4783 Kind : constant Entity_Kind := Ekind (Subp);
996ae0b0
RK
4784 Inner_Subp : Entity_Id := Subp;
4785
4786 begin
470cd9e9
RD
4787 -- Ignore if bad type, avoid cascaded error
4788
996ae0b0 4789 if Etype (Subp) = Any_Type then
470cd9e9
RD
4790 Applies := True;
4791 return;
4792
4793 -- Ignore if all inlining is suppressed
4794
4795 elsif Suppress_All_Inlining then
4796 Applies := True;
996ae0b0
RK
4797 return;
4798
98f01d53
AC
4799 -- If inlining is not possible, for now do not treat as an error
4800
4801 elsif Inlining_Not_Possible (Subp) then
4802 Applies := True;
fbf5a39b
AC
4803 return;
4804
996ae0b0 4805 -- Here we have a candidate for inlining, but we must exclude
21d27997
RD
4806 -- derived operations. Otherwise we would end up trying to inline
4807 -- a phantom declaration, and the result would be to drag in a
4808 -- body which has no direct inlining associated with it. That
4809 -- would not only be inefficient but would also result in the
4810 -- backend doing cross-unit inlining in cases where it was
4811 -- definitely inappropriate to do so.
4812
4813 -- However, a simple Comes_From_Source test is insufficient, since
4814 -- we do want to allow inlining of generic instances which also do
b3b9865d
AC
4815 -- not come from source. We also need to recognize specs generated
4816 -- by the front-end for bodies that carry the pragma. Finally,
4817 -- predefined operators do not come from source but are not
4818 -- inlineable either.
21d27997
RD
4819
4820 elsif Is_Generic_Instance (Subp)
4821 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4822 then
4823 null;
996ae0b0
RK
4824
4825 elsif not Comes_From_Source (Subp)
996ae0b0
RK
4826 and then Scope (Subp) /= Standard_Standard
4827 then
4828 Applies := True;
4829 return;
21d27997 4830 end if;
996ae0b0 4831
b3b9865d
AC
4832 -- The referenced entity must either be the enclosing entity, or
4833 -- an entity declared within the current open scope.
996ae0b0 4834
21d27997 4835 if Present (Scope (Subp))
996ae0b0
RK
4836 and then Scope (Subp) /= Current_Scope
4837 and then Subp /= Current_Scope
4838 then
4839 Error_Pragma_Arg
4840 ("argument of% must be entity in current scope", Assoc);
4841 return;
4842 end if;
4843
b3b9865d
AC
4844 -- Processing for procedure, operator or function. If subprogram
4845 -- is aliased (as for an instance) indicate that the renamed
4846 -- entity (if declared in the same unit) is inlined.
996ae0b0 4847
fbf5a39b 4848 if Is_Subprogram (Subp) then
b81a5940 4849 Inner_Subp := Ultimate_Alias (Inner_Subp);
996ae0b0 4850
af4b9434
AC
4851 if In_Same_Source_Unit (Subp, Inner_Subp) then
4852 Set_Inline_Flags (Inner_Subp);
996ae0b0 4853
af4b9434 4854 Decl := Parent (Parent (Inner_Subp));
996ae0b0 4855
af4b9434
AC
4856 if Nkind (Decl) = N_Subprogram_Declaration
4857 and then Present (Corresponding_Body (Decl))
4858 then
4859 Set_Inline_Flags (Corresponding_Body (Decl));
cfb02ad1
AC
4860
4861 elsif Is_Generic_Instance (Subp) then
4862
4863 -- Indicate that the body needs to be created for
b3b9865d
AC
4864 -- inlining subsequent calls. The instantiation node
4865 -- follows the declaration of the wrapper package
4866 -- created for it.
cfb02ad1
AC
4867
4868 if Scope (Subp) /= Standard_Standard
4869 and then
4870 Need_Subprogram_Instance_Body
4871 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4872 Subp)
4873 then
4874 null;
4875 end if;
79e705d6
AC
4876
4877 -- Inline is a program unit pragma (RM 10.1.5) and cannot
4878 -- appear in a formal part to apply to a formal subprogram.
25ebc085
AC
4879 -- Do not apply check within an instance or a formal package
4880 -- the test will have been applied to the original generic.
79e705d6
AC
4881
4882 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4883 and then List_Containing (Decl) = List_Containing (N)
25ebc085 4884 and then not In_Instance
79e705d6
AC
4885 then
4886 Error_Msg_N
4887 ("Inline cannot apply to a formal subprogram", N);
af4b9434 4888 end if;
996ae0b0
RK
4889 end if;
4890
4891 Applies := True;
4892
b3b9865d
AC
4893 -- For a generic subprogram set flag as well, for use at the point
4894 -- of instantiation, to determine whether the body should be
4895 -- generated.
996ae0b0 4896
fbf5a39b 4897 elsif Is_Generic_Subprogram (Subp) then
996ae0b0
RK
4898 Set_Inline_Flags (Subp);
4899 Applies := True;
4900
fbf5a39b 4901 -- Literals are by definition inlined
996ae0b0
RK
4902
4903 elsif Kind = E_Enumeration_Literal then
4904 null;
4905
4906 -- Anything else is an error
4907
4908 else
4909 Error_Pragma_Arg
4910 ("expect subprogram name for pragma%", Assoc);
4911 end if;
4912 end Make_Inline;
4913
4914 ----------------------
4915 -- Set_Inline_Flags --
4916 ----------------------
4917
4918 procedure Set_Inline_Flags (Subp : Entity_Id) is
4919 begin
4920 if Active then
eaba57fb 4921 Set_Is_Inlined (Subp);
996ae0b0
RK
4922 end if;
4923
4924 if not Has_Pragma_Inline (Subp) then
eaba57fb 4925 Set_Has_Pragma_Inline (Subp);
6e937c1c 4926 Effective := True;
996ae0b0 4927 end if;
470cd9e9
RD
4928
4929 if Prag_Id = Pragma_Inline_Always then
eaba57fb 4930 Set_Has_Pragma_Inline_Always (Subp);
470cd9e9 4931 end if;
996ae0b0
RK
4932 end Set_Inline_Flags;
4933
4934 -- Start of processing for Process_Inline
4935
4936 begin
4937 Check_No_Identifiers;
4938 Check_At_Least_N_Arguments (1);
4939
4940 if Active then
4941 Inline_Processing_Required := True;
4942 end if;
4943
4944 Assoc := Arg1;
4945 while Present (Assoc) loop
0f1a6a0b 4946 Subp_Id := Get_Pragma_Arg (Assoc);
996ae0b0
RK
4947 Analyze (Subp_Id);
4948 Applies := False;
4949
4950 if Is_Entity_Name (Subp_Id) then
4951 Subp := Entity (Subp_Id);
4952
4953 if Subp = Any_Id then
59e5fbe0
RD
4954
4955 -- If previous error, avoid cascaded errors
4956
996ae0b0 4957 Applies := True;
59e5fbe0 4958 Effective := True;
996ae0b0
RK
4959
4960 else
4961 Make_Inline (Subp);
4962
9f90d123
AC
4963 -- For the pragma case, climb homonym chain. This is
4964 -- what implements allowing the pragma in the renaming
df177175
RD
4965 -- case, with the result applying to the ancestors, and
4966 -- also allows Inline to apply to all previous homonyms.
9f90d123 4967
0f1a6a0b
AC
4968 if not From_Aspect_Specification (N) then
4969 while Present (Homonym (Subp))
4970 and then Scope (Homonym (Subp)) = Current_Scope
4971 loop
4972 Make_Inline (Homonym (Subp));
4973 Subp := Homonym (Subp);
4974 end loop;
4975 end if;
996ae0b0
RK
4976 end if;
4977 end if;
4978
4979 if not Applies then
4980 Error_Pragma_Arg
4981 ("inappropriate argument for pragma%", Assoc);
6e937c1c
AC
4982
4983 elsif not Effective
4984 and then Warn_On_Redundant_Constructs
470cd9e9 4985 and then not Suppress_All_Inlining
6e937c1c 4986 then
98f01d53 4987 if Inlining_Not_Possible (Subp) then
ed2233dc 4988 Error_Msg_NE
98f01d53
AC
4989 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4990 else
ed2233dc 4991 Error_Msg_NE
98f01d53
AC
4992 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4993 end if;
996ae0b0
RK
4994 end if;
4995
4996 Next (Assoc);
4997 end loop;
996ae0b0
RK
4998 end Process_Inline;
4999
5000 ----------------------------
5001 -- Process_Interface_Name --
5002 ----------------------------
5003
5004 procedure Process_Interface_Name
5005 (Subprogram_Def : Entity_Id;
5006 Ext_Arg : Node_Id;
5007 Link_Arg : Node_Id)
5008 is
5009 Ext_Nam : Node_Id;
5010 Link_Nam : Node_Id;
5011 String_Val : String_Id;
5012
7406fc15
RD
5013 procedure Check_Form_Of_Interface_Name
5014 (SN : Node_Id;
5015 Ext_Name_Case : Boolean);
996ae0b0
RK
5016 -- SN is a string literal node for an interface name. This routine
5017 -- performs some minimal checks that the name is reasonable. In
5018 -- particular that no spaces or other obviously incorrect characters
5019 -- appear. This is only a warning, since any characters are allowed.
7406fc15 5020 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
996ae0b0 5021
2c9beb8a
RD
5022 ----------------------------------
5023 -- Check_Form_Of_Interface_Name --
5024 ----------------------------------
5025
7406fc15
RD
5026 procedure Check_Form_Of_Interface_Name
5027 (SN : Node_Id;
5028 Ext_Name_Case : Boolean)
5029 is
996ae0b0
RK
5030 S : constant String_Id := Strval (Expr_Value_S (SN));
5031 SL : constant Nat := String_Length (S);
5032 C : Char_Code;
5033
5034 begin
5035 if SL = 0 then
5036 Error_Msg_N ("interface name cannot be null string", SN);
5037 end if;
5038
5039 for J in 1 .. SL loop
5040 C := Get_String_Char (S, J);
5041
7406fc15
RD
5042 -- Look for dubious character and issue unconditional warning.
5043 -- Definitely dubious if not in character range.
5044
5045 if not In_Character_Range (C)
5046
a7a3cf5c 5047 -- For all cases except CLI target,
57eb1cf5 5048 -- commas, spaces and slashes are dubious (in CLI, we use
a7a3cf5c
AC
5049 -- commas and backslashes in external names to specify
5050 -- assembly version and public key, while slashes and spaces
5051 -- can be used in names to mark nested classes and
5052 -- valuetypes).
7406fc15 5053
57eb1cf5 5054 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
a7a3cf5c 5055 and then (Get_Character (C) = ','
57eb1cf5 5056 or else
7406fc15 5057 Get_Character (C) = '\'))
7e8ed0a6 5058 or else (VM_Target /= CLI_Target
a7a3cf5c
AC
5059 and then (Get_Character (C) = ' '
5060 or else
5061 Get_Character (C) = '/'))
996ae0b0 5062 then
ed2233dc 5063 Error_Msg
7406fc15
RD
5064 ("?interface name contains illegal character",
5065 Sloc (SN) + Source_Ptr (J));
996ae0b0
RK
5066 end if;
5067 end loop;
5068 end Check_Form_Of_Interface_Name;
5069
5070 -- Start of processing for Process_Interface_Name
5071
5072 begin
5073 if No (Link_Arg) then
5074 if No (Ext_Arg) then
2fa9443e
ES
5075 if VM_Target = CLI_Target
5076 and then Ekind (Subprogram_Def) = E_Package
5077 and then Nkind (Parent (Subprogram_Def)) =
5078 N_Package_Specification
5079 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5080 then
5081 Set_Interface_Name
5082 (Subprogram_Def,
5083 Interface_Name
5084 (Generic_Parent (Parent (Subprogram_Def))));
5085 end if;
5086
996ae0b0
RK
5087 return;
5088
5089 elsif Chars (Ext_Arg) = Name_Link_Name then
5090 Ext_Nam := Empty;
5091 Link_Nam := Expression (Ext_Arg);
5092
5093 else
5094 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5095 Ext_Nam := Expression (Ext_Arg);
5096 Link_Nam := Empty;
5097 end if;
5098
5099 else
5100 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5101 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5102 Ext_Nam := Expression (Ext_Arg);
5103 Link_Nam := Expression (Link_Arg);
5104 end if;
5105
5106 -- Check expressions for external name and link name are static
5107
5108 if Present (Ext_Nam) then
5109 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
7406fc15 5110 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
996ae0b0 5111
7406fc15
RD
5112 -- Verify that external name is not the name of a local entity,
5113 -- which would hide the imported one and could lead to run-time
5114 -- surprises. The problem can only arise for entities declared in
5115 -- a package body (otherwise the external name is fully qualified
5116 -- and will not conflict).
996ae0b0
RK
5117
5118 declare
5119 Nam : Name_Id;
5120 E : Entity_Id;
5121 Par : Node_Id;
5122
5123 begin
5124 if Prag_Id = Pragma_Import then
5125 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5126 Nam := Name_Find;
5127 E := Entity_Id (Get_Name_Table_Info (Nam));
5128
5129 if Nam /= Chars (Subprogram_Def)
5130 and then Present (E)
5131 and then not Is_Overloadable (E)
5132 and then Is_Immediately_Visible (E)
5133 and then not Is_Imported (E)
5134 and then Ekind (Scope (E)) = E_Package
5135 then
5136 Par := Parent (E);
996ae0b0
RK
5137 while Present (Par) loop
5138 if Nkind (Par) = N_Package_Body then
7406fc15 5139 Error_Msg_Sloc := Sloc (E);
996ae0b0
RK
5140 Error_Msg_NE
5141 ("imported entity is hidden by & declared#",
7406fc15 5142 Ext_Arg, E);
996ae0b0
RK
5143 exit;
5144 end if;
5145
5146 Par := Parent (Par);
5147 end loop;
5148 end if;
5149 end if;
5150 end;
5151 end if;
5152
5153 if Present (Link_Nam) then
5154 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
7406fc15 5155 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
996ae0b0
RK
5156 end if;
5157
5158 -- If there is no link name, just set the external name
5159
5160 if No (Link_Nam) then
523456db 5161 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
996ae0b0
RK
5162
5163 -- For the Link_Name case, the given literal is preceded by an
b3b9865d
AC
5164 -- asterisk, which indicates to GCC that the given name should be
5165 -- taken literally, and in particular that no prepending of
996ae0b0
RK
5166 -- underlines should occur, even in systems where this is the
5167 -- normal default.
5168
5169 else
5170 Start_String;
2fa9443e
ES
5171
5172 if VM_Target = No_VM then
5173 Store_String_Char (Get_Char_Code ('*'));
5174 end if;
5175
996ae0b0 5176 String_Val := Strval (Expr_Value_S (Link_Nam));
b54ddf5a 5177 Store_String_Chars (String_Val);
996ae0b0 5178 Link_Nam :=
b54ddf5a
BD
5179 Make_String_Literal (Sloc (Link_Nam),
5180 Strval => End_String);
996ae0b0 5181 end if;
523456db 5182
53f29d4f
AC
5183 -- Set the interface name. If the entity is a generic instance, use
5184 -- its alias, which is the callable entity.
5185
5186 if Is_Generic_Instance (Subprogram_Def) then
5187 Set_Encoded_Interface_Name
5188 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
53f29d4f
AC
5189 else
5190 Set_Encoded_Interface_Name
5191 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5192 end if;
8255bc9d 5193
f9ad6b62 5194 -- We allow duplicated export names in CIL/Java, as they are always
8255bc9d
AC
5195 -- enclosed in a namespace that differentiates them, and overloaded
5196 -- entities are supported by the VM.
5197
f9ad6b62 5198 if Convention (Subprogram_Def) /= Convention_CIL
2c1b72d7
AC
5199 and then
5200 Convention (Subprogram_Def) /= Convention_Java
f9ad6b62 5201 then
8255bc9d
AC
5202 Check_Duplicated_Export_Name (Link_Nam);
5203 end if;
996ae0b0
RK
5204 end Process_Interface_Name;
5205
5206 -----------------------------------------
5207 -- Process_Interrupt_Or_Attach_Handler --
5208 -----------------------------------------
5209
5210 procedure Process_Interrupt_Or_Attach_Handler is
0f1a6a0b 5211 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
fbf5a39b
AC
5212 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5213 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
996ae0b0
RK
5214
5215 begin
fbf5a39b 5216 Set_Is_Interrupt_Handler (Handler_Proc);
996ae0b0 5217
b3b9865d
AC
5218 -- If the pragma is not associated with a handler procedure within a
5219 -- protected type, then it must be for a nonprotected procedure for
5220 -- the AAMP target, in which case we don't associate a representation
5221 -- item with the procedure's scope.
996ae0b0 5222
fbf5a39b
AC
5223 if Ekind (Proc_Scope) = E_Protected_Type then
5224 if Prag_Id = Pragma_Interrupt_Handler
6e937c1c
AC
5225 or else
5226 Prag_Id = Pragma_Attach_Handler
fbf5a39b
AC
5227 then
5228 Record_Rep_Item (Proc_Scope, N);
5229 end if;
5230 end if;
996ae0b0
RK
5231 end Process_Interrupt_Or_Attach_Handler;
5232
6e937c1c
AC
5233 --------------------------------------------------
5234 -- Process_Restrictions_Or_Restriction_Warnings --
5235 --------------------------------------------------
5236
5f3ab6fb
AC
5237 -- Note: some of the simple identifier cases were handled in par-prag,
5238 -- but it is harmless (and more straightforward) to simply handle all
5239 -- cases here, even if it means we repeat a bit of work in some cases.
5240
ac9e9918
RD
5241 procedure Process_Restrictions_Or_Restriction_Warnings
5242 (Warn : Boolean)
5243 is
6e937c1c
AC
5244 Arg : Node_Id;
5245 R_Id : Restriction_Id;
5246 Id : Name_Id;
5247 Expr : Node_Id;
5248 Val : Uint;
5249
5f3ab6fb
AC
5250 procedure Check_Unit_Name (N : Node_Id);
5251 -- Checks unit name parameter for No_Dependence. Returns if it has
5252 -- an appropriate form, otherwise raises pragma argument error.
5253
5f3ab6fb
AC
5254 ---------------------
5255 -- Check_Unit_Name --
5256 ---------------------
5257
5258 procedure Check_Unit_Name (N : Node_Id) is
5259 begin
5260 if Nkind (N) = N_Selected_Component then
5261 Check_Unit_Name (Prefix (N));
5262 Check_Unit_Name (Selector_Name (N));
5263
5264 elsif Nkind (N) = N_Identifier then
5265 return;
5266
5267 else
5268 Error_Pragma_Arg
5269 ("wrong form for unit name for No_Dependence", N);
5270 end if;
5271 end Check_Unit_Name;
5272
6e937c1c
AC
5273 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5274
5275 begin
36b8f95f 5276 -- Ignore all Restrictions pragma in CodePeer mode
2551782d 5277
36b8f95f 5278 if CodePeer_Mode then
2551782d
AC
5279 return;
5280 end if;
5281
6e937c1c
AC
5282 Check_Ada_83_Warning;
5283 Check_At_Least_N_Arguments (1);
5284 Check_Valid_Configuration_Pragma;
5285
5286 Arg := Arg1;
5287 while Present (Arg) loop
5288 Id := Chars (Arg);
0f1a6a0b 5289 Expr := Get_Pragma_Arg (Arg);
6e937c1c 5290
b5e792e2 5291 -- Case of no restriction identifier present
6e937c1c
AC
5292
5293 if Id = No_Name then
5294 if Nkind (Expr) /= N_Identifier then
5295 Error_Pragma_Arg
5296 ("invalid form for restriction", Arg);
b5e792e2 5297 end if;
6e937c1c 5298
b5e792e2
AC
5299 R_Id :=
5300 Get_Restriction_Id
cc335f43 5301 (Process_Restriction_Synonyms (Expr));
6e937c1c 5302
b5e792e2 5303 if R_Id not in All_Boolean_Restrictions then
21d27997
RD
5304 Error_Msg_Name_1 := Pname;
5305 Error_Msg_N
5306 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5307
5308 -- Check for possible misspelling
5309
5310 for J in Restriction_Id loop
5311 declare
5312 Rnm : constant String := Restriction_Id'Image (J);
5313
5314 begin
5315 Name_Buffer (1 .. Rnm'Length) := Rnm;
5316 Name_Len := Rnm'Length;
5317 Set_Casing (All_Lower_Case);
5318
5319 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5320 Set_Casing
5321 (Identifier_Casing (Current_Source_File));
5322 Error_Msg_String (1 .. Rnm'Length) :=
5323 Name_Buffer (1 .. Name_Len);
5324 Error_Msg_Strlen := Rnm'Length;
0c020dde 5325 Error_Msg_N -- CODEFIX
21d27997
RD
5326 ("\possible misspelling of ""~""",
5327 Get_Pragma_Arg (Arg));
5328 exit;
5329 end if;
5330 end;
5331 end loop;
5332
5333 raise Pragma_Exit;
b5e792e2 5334 end if;
6e937c1c 5335
b5e792e2 5336 if Implementation_Restriction (R_Id) then
21d27997 5337 Check_Restriction (No_Implementation_Restrictions, Arg);
b5e792e2 5338 end if;
6e937c1c 5339
ac9e9918
RD
5340 -- If this is a warning, then set the warning unless we already
5341 -- have a real restriction active (we never want a warning to
5342 -- override a real restriction).
6e937c1c 5343
ac9e9918
RD
5344 if Warn then
5345 if not Restriction_Active (R_Id) then
5346 Set_Restriction (R_Id, N);
5347 Restriction_Warnings (R_Id) := True;
5348 end if;
5349
5350 -- If real restriction case, then set it and make sure that the
5351 -- restriction warning flag is off, since a real restriction
5352 -- always overrides a warning.
6e937c1c 5353
ac9e9918
RD
5354 else
5355 Set_Restriction (R_Id, N);
5356 Restriction_Warnings (R_Id) := False;
5357 end if;
5358
b5c739f9
RD
5359 -- Check for obsolescent restrictions in Ada 2005 mode
5360
5361 if not Warn
5362 and then Ada_Version >= Ada_2005
5363 and then (R_Id = No_Asynchronous_Control
5364 or else
5365 R_Id = No_Unchecked_Deallocation
5366 or else
5367 R_Id = No_Unchecked_Conversion)
5368 then
5369 Check_Restriction (No_Obsolescent_Features, N);
5370 end if;
5371
ac9e9918
RD
5372 -- A very special case that must be processed here: pragma
5373 -- Restrictions (No_Exceptions) turns off all run-time
5374 -- checking. This is a bit dubious in terms of the formal
5375 -- language definition, but it is what is intended by RM
5376 -- H.4(12). Restriction_Warnings never affects generated code
5377 -- so this is done only in the real restriction case.
5378
12b4d338
AC
5379 -- Atomic_Synchronization is not a real check, so it is not
5380 -- affected by this processing).
5381
ac9e9918 5382 if R_Id = No_Exceptions and then not Warn then
12b4d338
AC
5383 for J in Scope_Suppress'Range loop
5384 if J /= Atomic_Synchronization then
5385 Scope_Suppress (J) := True;
5386 end if;
5387 end loop;
6e937c1c
AC
5388 end if;
5389
5f3ab6fb
AC
5390 -- Case of No_Dependence => unit-name. Note that the parser
5391 -- already made the necessary entry in the No_Dependence table.
5392
5393 elsif Id = Name_No_Dependence then
5394 Check_Unit_Name (Expr);
5395
e7fceebc
AC
5396 -- Case of No_Specification_Of_Aspect => Identifier.
5397
5398 elsif Id = Name_No_Specification_Of_Aspect then
5399 declare
5400 A_Id : Aspect_Id;
5401
5402 begin
5403 if Nkind (Expr) /= N_Identifier then
5404 A_Id := No_Aspect;
5405 else
5406 A_Id := Get_Aspect_Id (Chars (Expr));
5407 end if;
5408
5409 if A_Id = No_Aspect then
5410 Error_Pragma_Arg ("invalid restriction name", Arg);
5411 else
5412 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5413 end if;
5414 end;
5415
5f3ab6fb 5416 -- All other cases of restriction identifier present
6e937c1c
AC
5417
5418 else
cc335f43 5419 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
6e937c1c
AC
5420 Analyze_And_Resolve (Expr, Any_Integer);
5421
5422 if R_Id not in All_Parameter_Restrictions then
5423 Error_Pragma_Arg
5424 ("invalid restriction parameter identifier", Arg);
5425
5426 elsif not Is_OK_Static_Expression (Expr) then
5427 Flag_Non_Static_Expr
5428 ("value must be static expression!", Expr);
5429 raise Pragma_Exit;
5430
5431 elsif not Is_Integer_Type (Etype (Expr))
5432 or else Expr_Value (Expr) < 0
5433 then
5434 Error_Pragma_Arg
5435 ("value must be non-negative integer", Arg);
ac9e9918 5436 end if;
6e937c1c 5437
ac9e9918 5438 -- Restriction pragma is active
6e937c1c 5439
ac9e9918 5440 Val := Expr_Value (Expr);
6e937c1c 5441
ac9e9918
RD
5442 if not UI_Is_In_Int_Range (Val) then
5443 Error_Pragma_Arg
5444 ("pragma ignored, value too large?", Arg);
5445 end if;
5446
5447 -- Warning case. If the real restriction is active, then we
5448 -- ignore the request, since warning never overrides a real
5449 -- restriction. Otherwise we set the proper warning. Note that
5450 -- this circuit sets the warning again if it is already set,
5451 -- which is what we want, since the constant may have changed.
5452
5453 if Warn then
5454 if not Restriction_Active (R_Id) then
5455 Set_Restriction
5456 (R_Id, N, Integer (UI_To_Int (Val)));
5457 Restriction_Warnings (R_Id) := True;
6e937c1c 5458 end if;
ac9e9918
RD
5459
5460 -- Real restriction case, set restriction and make sure warning
5461 -- flag is off since real restriction always overrides warning.
5462
5463 else
5464 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5465 Restriction_Warnings (R_Id) := False;
6e937c1c
AC
5466 end if;
5467 end if;
5468
5469 Next (Arg);
5470 end loop;
5471 end Process_Restrictions_Or_Restriction_Warnings;
5472
996ae0b0
RK
5473 ---------------------------------
5474 -- Process_Suppress_Unsuppress --
5475 ---------------------------------
5476
fbf5a39b
AC
5477 -- Note: this procedure makes entries in the check suppress data
5478 -- structures managed by Sem. See spec of package Sem for full
5479 -- details on how we handle recording of check suppression.
5480
996ae0b0 5481 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
fbf5a39b
AC
5482 C : Check_Id;
5483 E_Id : Node_Id;
5484 E : Entity_Id;
5485
5486 In_Package_Spec : constant Boolean :=
b9b2405f 5487 Is_Package_Or_Generic_Package (Current_Scope)
fbf5a39b 5488 and then not In_Package_Body (Current_Scope);
996ae0b0
RK
5489
5490 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5491 -- Used to suppress a single check on the given entity
5492
fbf5a39b
AC
5493 --------------------------------
5494 -- Suppress_Unsuppress_Echeck --
5495 --------------------------------
5496
996ae0b0 5497 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
fbf5a39b 5498 begin
12b4d338
AC
5499 -- Check for error of trying to set atomic synchronization for
5500 -- a non-atomic variable.
5501
5502 if C = Atomic_Synchronization
5972791c 5503 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
12b4d338
AC
5504 then
5505 Error_Msg_N
fb5d63c6 5506 ("pragma & requires atomic type or variable",
12b4d338
AC
5507 Pragma_Identifier (Original_Node (N)));
5508 end if;
5509
fbf5a39b 5510 Set_Checks_May_Be_Suppressed (E);
996ae0b0 5511
fbf5a39b 5512 if In_Package_Spec then
c690a2ec
RD
5513 Push_Global_Suppress_Stack_Entry
5514 (Entity => E,
5515 Check => C,
5516 Suppress => Suppress_Case);
fbf5a39b 5517 else
c690a2ec
RD
5518 Push_Local_Suppress_Stack_Entry
5519 (Entity => E,
5520 Check => C,
5521 Suppress => Suppress_Case);
996ae0b0
RK
5522 end if;
5523
5524 -- If this is a first subtype, and the base type is distinct,
5525 -- then also set the suppress flags on the base type.
5526
5527 if Is_First_Subtype (E)
5528 and then Etype (E) /= E
5529 then
5530 Suppress_Unsuppress_Echeck (Etype (E), C);
5531 end if;
5532 end Suppress_Unsuppress_Echeck;
5533
5534 -- Start of processing for Process_Suppress_Unsuppress
5535
5536 begin
56812278 5537 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
406935b6
AC
5538 -- user code: we want to generate checks for analysis purposes, as
5539 -- set respectively by -gnatC and -gnatd.F
ddc1515a 5540
56812278 5541 if (CodePeer_Mode or Alfa_Mode)
406935b6
AC
5542 and then Comes_From_Source (N)
5543 then
ddc1515a
AC
5544 return;
5545 end if;
5546
b3b9865d
AC
5547 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5548 -- declarative part or a package spec (RM 11.5(5)).
996ae0b0
RK
5549
5550 if not Is_Configuration_Pragma then
5551 Check_Is_In_Decl_Part_Or_Package_Spec;
5552 end if;
5553
5554 Check_At_Least_N_Arguments (1);
5555 Check_At_Most_N_Arguments (2);
5556 Check_No_Identifier (Arg1);
5557 Check_Arg_Is_Identifier (Arg1);
5558
0f1a6a0b 5559 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
c690a2ec
RD
5560
5561 if C = No_Check_Id then
996ae0b0
RK
5562 Error_Pragma_Arg
5563 ("argument of pragma% is not valid check name", Arg1);
996ae0b0
RK
5564 end if;
5565
2fa9443e
ES
5566 if not Suppress_Case
5567 and then (C = All_Checks or else C = Overflow_Check)
5568 then
5569 Opt.Overflow_Checks_Unsuppressed := True;
5570 end if;
5571
996ae0b0 5572 if Arg_Count = 1 then
996ae0b0 5573
fbf5a39b
AC
5574 -- Make an entry in the local scope suppress table. This is the
5575 -- table that directly shows the current value of the scope
5576 -- suppress check for any check id value.
996ae0b0 5577
fbf5a39b 5578 if C = All_Checks then
f02b8bb8 5579
c690a2ec
RD
5580 -- For All_Checks, we set all specific predefined checks with
5581 -- the exception of Elaboration_Check, which is handled
5582 -- specially because of not wanting All_Checks to have the
5583 -- effect of deactivating static elaboration order processing.
12b4d338
AC
5584 -- Atomic_Synchronization is also not affected, since this is
5585 -- not a real check.
f02b8bb8 5586
dbee7ab9 5587 for J in Scope_Suppress'Range loop
12b4d338
AC
5588 if J /= Elaboration_Check
5589 and then J /= Atomic_Synchronization
5590 then
f02b8bb8
RD
5591 Scope_Suppress (J) := Suppress_Case;
5592 end if;
dbee7ab9 5593 end loop;
f02b8bb8 5594
c690a2ec
RD
5595 -- If not All_Checks, and predefined check, then set appropriate
5596 -- scope entry. Note that we will set Elaboration_Check if this
12b4d338
AC
5597 -- is explicitly specified. Atomic_Synchronization is allowed
5598 -- only if internally generated and entity is atomic.
f02b8bb8 5599
12b4d338
AC
5600 elsif C in Predefined_Check_Id
5601 and then (not Comes_From_Source (N)
5602 or else C /= Atomic_Synchronization)
5603 then
fbf5a39b
AC
5604 Scope_Suppress (C) := Suppress_Case;
5605 end if;
996ae0b0 5606
c690a2ec 5607 -- Also make an entry in the Local_Entity_Suppress table
996ae0b0 5608
c690a2ec
RD
5609 Push_Local_Suppress_Stack_Entry
5610 (Entity => Empty,
5611 Check => C,
5612 Suppress => Suppress_Case);
996ae0b0 5613
c690a2ec
RD
5614 -- Case of two arguments present, where the check is suppressed for
5615 -- a specified entity (given as the second argument of the pragma)
996ae0b0
RK
5616
5617 else
b5c739f9
RD
5618 -- This is obsolescent in Ada 2005 mode
5619
5620 if Ada_Version >= Ada_2005 then
5621 Check_Restriction (No_Obsolescent_Features, Arg2);
5622 end if;
5623
996ae0b0 5624 Check_Optional_Identifier (Arg2, Name_On);
0f1a6a0b 5625 E_Id := Get_Pragma_Arg (Arg2);
996ae0b0
RK
5626 Analyze (E_Id);
5627
5628 if not Is_Entity_Name (E_Id) then
5629 Error_Pragma_Arg
5630 ("second argument of pragma% must be entity name", Arg2);
5631 end if;
5632
5633 E := Entity (E_Id);
5634
5635 if E = Any_Id then
5636 return;
fbf5a39b 5637 end if;
996ae0b0 5638
fbf5a39b
AC
5639 -- Enforce RM 11.5(7) which requires that for a pragma that
5640 -- appears within a package spec, the named entity must be
5641 -- within the package spec. We allow the package name itself
5642 -- to be mentioned since that makes sense, although it is not
5643 -- strictly allowed by 11.5(7).
996ae0b0 5644
fbf5a39b
AC
5645 if In_Package_Spec
5646 and then E /= Current_Scope
5647 and then Scope (E) /= Current_Scope
5648 then
5649 Error_Pragma_Arg
c690a2ec 5650 ("entity in pragma% is not in package spec (RM 11.5(7))",
fbf5a39b
AC
5651 Arg2);
5652 end if;
996ae0b0 5653
fbf5a39b
AC
5654 -- Loop through homonyms. As noted below, in the case of a package
5655 -- spec, only homonyms within the package spec are considered.
996ae0b0 5656
fbf5a39b
AC
5657 loop
5658 Suppress_Unsuppress_Echeck (E, C);
996ae0b0 5659
fbf5a39b
AC
5660 if Is_Generic_Instance (E)
5661 and then Is_Subprogram (E)
5662 and then Present (Alias (E))
5663 then
5664 Suppress_Unsuppress_Echeck (Alias (E), C);
5665 end if;
5666
0f1a6a0b 5667 -- Move to next homonym if not aspect spec case
996ae0b0 5668
0f1a6a0b 5669 exit when From_Aspect_Specification (N);
fbf5a39b
AC
5670 E := Homonym (E);
5671 exit when No (E);
5672
b3b9865d
AC
5673 -- If we are within a package specification, the pragma only
5674 -- applies to homonyms in the same scope.
fbf5a39b
AC
5675
5676 exit when In_Package_Spec
5677 and then Scope (E) /= Current_Scope;
5678 end loop;
5679 end if;
996ae0b0
RK
5680 end Process_Suppress_Unsuppress;
5681
5682 ------------------
5683 -- Set_Exported --
5684 ------------------
5685
5686 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5687 begin
5688 if Is_Imported (E) then
ed2233dc 5689 Error_Pragma_Arg
996ae0b0
RK
5690 ("cannot export entity& that was previously imported", Arg);
5691
a780db15 5692 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
ed2233dc 5693 Error_Pragma_Arg
996ae0b0
RK
5694 ("cannot export entity& that has an address clause", Arg);
5695 end if;
5696
5697 Set_Is_Exported (E);
5698
fbf5a39b
AC
5699 -- Generate a reference for entity explicitly, because the
5700 -- identifier may be overloaded and name resolution will not
5701 -- generate one.
5702
5703 Generate_Reference (E, Arg);
5704
996ae0b0
RK
5705 -- Deal with exporting non-library level entity
5706
5707 if not Is_Library_Level_Entity (E) then
5708
5709 -- Not allowed at all for subprograms
5710
5711 if Is_Subprogram (E) then
ed2233dc 5712 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
996ae0b0
RK
5713
5714 -- Otherwise set public and statically allocated
5715
5716 else
5717 Set_Is_Public (E);
5718 Set_Is_Statically_Allocated (E);
fbf5a39b 5719
b3b9865d
AC
5720 -- Warn if the corresponding W flag is set and the pragma comes
5721 -- from source. The latter may not be true e.g. on VMS where we
5722 -- expand export pragmas for exception codes associated with
5723 -- imported or exported exceptions. We do not want to generate
5724 -- a warning for something that the user did not write.
af152989
AC
5725
5726 if Warn_On_Export_Import
5727 and then Comes_From_Source (Arg)
5728 then
fbf5a39b
AC
5729 Error_Msg_NE
5730 ("?& has been made static as a result of Export", Arg, E);
5731 Error_Msg_N
5732 ("\this usage is non-standard and non-portable", Arg);
5733 end if;
996ae0b0
RK
5734 end if;
5735 end if;
5736
fbf5a39b 5737 if Warn_On_Export_Import and then Is_Type (E) then
ed2233dc 5738 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
996ae0b0
RK
5739 end if;
5740
fbf5a39b
AC
5741 if Warn_On_Export_Import and Inside_A_Generic then
5742 Error_Msg_NE
5743 ("all instances of& will have the same external name?", Arg, E);
5744 end if;
996ae0b0
RK
5745 end Set_Exported;
5746
5747 ----------------------------------------------
5748 -- Set_Extended_Import_Export_External_Name --
5749 ----------------------------------------------
5750
5751 procedure Set_Extended_Import_Export_External_Name
5752 (Internal_Ent : Entity_Id;
5753 Arg_External : Node_Id)
5754 is
5755 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5756 New_Name : Node_Id;
5757
5758 begin
5759 if No (Arg_External) then
5760 return;
cc335f43
AC
5761 end if;
5762
5763 Check_Arg_Is_External_Name (Arg_External);
996ae0b0 5764
cc335f43 5765 if Nkind (Arg_External) = N_String_Literal then
996ae0b0
RK
5766 if String_Length (Strval (Arg_External)) = 0 then
5767 return;
5768 else
5769 New_Name := Adjust_External_Name_Case (Arg_External);
5770 end if;
5771
5772 elsif Nkind (Arg_External) = N_Identifier then
5773 New_Name := Get_Default_External_Name (Arg_External);
5774
b3b9865d
AC
5775 -- Check_Arg_Is_External_Name should let through only identifiers and
5776 -- string literals or static string expressions (which are folded to
5777 -- string literals).
cc335f43 5778
996ae0b0 5779 else
cc335f43 5780 raise Program_Error;
996ae0b0
RK
5781 end if;
5782
b3b9865d
AC
5783 -- If we already have an external name set (by a prior normal Import
5784 -- or Export pragma), then the external names must match
996ae0b0
RK
5785
5786 if Present (Interface_Name (Internal_Ent)) then
2c9beb8a 5787 Check_Matching_Internal_Names : declare
996ae0b0
RK
5788 S1 : constant String_Id := Strval (Old_Name);
5789 S2 : constant String_Id := Strval (New_Name);
5790
5791 procedure Mismatch;
5792 -- Called if names do not match
5793
2c9beb8a
RD
5794 --------------
5795 -- Mismatch --
5796 --------------
5797
996ae0b0
RK
5798 procedure Mismatch is
5799 begin
5800 Error_Msg_Sloc := Sloc (Old_Name);
5801 Error_Pragma_Arg
5802 ("external name does not match that given #",
5803 Arg_External);
5804 end Mismatch;
5805
2c9beb8a
RD
5806 -- Start of processing for Check_Matching_Internal_Names
5807
996ae0b0
RK
5808 begin
5809 if String_Length (S1) /= String_Length (S2) then
5810 Mismatch;
5811
5812 else
5813 for J in 1 .. String_Length (S1) loop
5814 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5815 Mismatch;
5816 end if;
5817 end loop;
5818 end if;
2c9beb8a 5819 end Check_Matching_Internal_Names;
996ae0b0
RK
5820
5821 -- Otherwise set the given name
5822
5823 else
5824 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
523456db 5825 Check_Duplicated_Export_Name (New_Name);
996ae0b0 5826 end if;
996ae0b0
RK
5827 end Set_Extended_Import_Export_External_Name;
5828
5829 ------------------
5830 -- Set_Imported --
5831 ------------------
5832
5833 procedure Set_Imported (E : Entity_Id) is
5834 begin
c690a2ec 5835 -- Error message if already imported or exported
996ae0b0
RK
5836
5837 if Is_Exported (E) or else Is_Imported (E) then
c28408b7
RD
5838
5839 -- Error if being set Exported twice
5840
996ae0b0 5841 if Is_Exported (E) then
c690a2ec 5842 Error_Msg_NE ("entity& was previously exported", N, E);
c28408b7
RD
5843
5844 -- OK if Import/Interface case
5845
5846 elsif Import_Interface_Present (N) then
5847 goto OK;
5848
5849 -- Error if being set Imported twice
5850
996ae0b0 5851 else
c690a2ec 5852 Error_Msg_NE ("entity& was previously imported", N, E);
996ae0b0
RK
5853 end if;
5854
1b24ada5 5855 Error_Msg_Name_1 := Pname;
c690a2ec
RD
5856 Error_Msg_N
5857 ("\(pragma% applies to all previous entities)", N);
5858
5859 Error_Msg_Sloc := Sloc (E);
ed2233dc 5860 Error_Msg_NE ("\import not allowed for& declared#", N, E);
c690a2ec
RD
5861
5862 -- Here if not previously imported or exported, OK to import
996ae0b0
RK
5863
5864 else
5865 Set_Is_Imported (E);
5866
b3b9865d
AC
5867 -- If the entity is an object that is not at the library level,
5868 -- then it is statically allocated. We do not worry about objects
5869 -- with address clauses in this context since they are not really
5870 -- imported in the linker sense.
996ae0b0
RK
5871
5872 if Is_Object (E)
5873 and then not Is_Library_Level_Entity (E)
5874 and then No (Address_Clause (E))
5875 then
5876 Set_Is_Statically_Allocated (E);
5877 end if;
5878 end if;
c28408b7
RD
5879
5880 <<OK>> null;
996ae0b0
RK
5881 end Set_Imported;
5882
5883 -------------------------
5884 -- Set_Mechanism_Value --
5885 -------------------------
5886
b3b9865d
AC
5887 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5888 -- analyzed, since it is semantic nonsense), so we get it in the exact
5889 -- form created by the parser.
996ae0b0
RK
5890
5891 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
292beb8f
AC
5892 Class : Node_Id;
5893 Param : Node_Id;
d628c015 5894 Mech_Name_Id : Name_Id;
996ae0b0
RK
5895
5896 procedure Bad_Class;
5897 -- Signal bad descriptor class name
5898
5899 procedure Bad_Mechanism;
5900 -- Signal bad mechanism name
5901
2c9beb8a
RD
5902 ---------------
5903 -- Bad_Class --
5904 ---------------
5905
996ae0b0
RK
5906 procedure Bad_Class is
5907 begin
5908 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5909 end Bad_Class;
5910
2c9beb8a
RD
5911 -------------------------
5912 -- Bad_Mechanism_Value --
5913 -------------------------
5914
996ae0b0
RK
5915 procedure Bad_Mechanism is
5916 begin
5917 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5918 end Bad_Mechanism;
5919
5920 -- Start of processing for Set_Mechanism_Value
5921
5922 begin
5923 if Mechanism (Ent) /= Default_Mechanism then
5924 Error_Msg_NE
5925 ("mechanism for & has already been set", Mech_Name, Ent);
5926 end if;
5927
d628c015
DR
5928 -- MECHANISM_NAME ::= value | reference | descriptor |
5929 -- short_descriptor
996ae0b0
RK
5930
5931 if Nkind (Mech_Name) = N_Identifier then
5932 if Chars (Mech_Name) = Name_Value then
5933 Set_Mechanism (Ent, By_Copy);
5934 return;
5935
5936 elsif Chars (Mech_Name) = Name_Reference then
5937 Set_Mechanism (Ent, By_Reference);
5938 return;
5939
5940 elsif Chars (Mech_Name) = Name_Descriptor then
5941 Check_VMS (Mech_Name);
292beb8f
AC
5942
5943 -- Descriptor => Short_Descriptor if pragma was given
5944
5945 if Short_Descriptors then
5946 Set_Mechanism (Ent, By_Short_Descriptor);
5947 else
5948 Set_Mechanism (Ent, By_Descriptor);
5949 end if;
5950
996ae0b0
RK
5951 return;
5952
d628c015
DR
5953 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5954 Check_VMS (Mech_Name);
5955 Set_Mechanism (Ent, By_Short_Descriptor);
5956 return;
5957
996ae0b0
RK
5958 elsif Chars (Mech_Name) = Name_Copy then
5959 Error_Pragma_Arg
5960 ("bad mechanism name, Value assumed", Mech_Name);
5961
5962 else
5963 Bad_Mechanism;
5964 end if;
5965
d628c015
DR
5966 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5967 -- short_descriptor (CLASS_NAME)
996ae0b0
RK
5968 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5969
5970 -- Note: this form is parsed as an indexed component
5971
5972 elsif Nkind (Mech_Name) = N_Indexed_Component then
5973 Class := First (Expressions (Mech_Name));
5974
5975 if Nkind (Prefix (Mech_Name)) /= N_Identifier
d628c015
DR
5976 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5977 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5978 or else Present (Next (Class))
996ae0b0
RK
5979 then
5980 Bad_Mechanism;
d628c015
DR
5981 else
5982 Mech_Name_Id := Chars (Prefix (Mech_Name));
292beb8f
AC
5983
5984 -- Change Descriptor => Short_Descriptor if pragma was given
5985
5986 if Mech_Name_Id = Name_Descriptor
5987 and then Short_Descriptors
5988 then
5989 Mech_Name_Id := Name_Short_Descriptor;
5990 end if;
996ae0b0
RK
5991 end if;
5992
d628c015
DR
5993 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5994 -- short_descriptor (Class => CLASS_NAME)
996ae0b0
RK
5995 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5996
5997 -- Note: this form is parsed as a function call
5998
5999 elsif Nkind (Mech_Name) = N_Function_Call then
996ae0b0
RK
6000 Param := First (Parameter_Associations (Mech_Name));
6001
6002 if Nkind (Name (Mech_Name)) /= N_Identifier
d628c015
DR
6003 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6004 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
996ae0b0
RK
6005 or else Present (Next (Param))
6006 or else No (Selector_Name (Param))
6007 or else Chars (Selector_Name (Param)) /= Name_Class
6008 then
6009 Bad_Mechanism;
6010 else
6011 Class := Explicit_Actual_Parameter (Param);
d628c015 6012 Mech_Name_Id := Chars (Name (Mech_Name));
996ae0b0
RK
6013 end if;
6014
6015 else
6016 Bad_Mechanism;
6017 end if;
6018
6019 -- Fall through here with Class set to descriptor class name
6020
6021 Check_VMS (Mech_Name);
6022
6023 if Nkind (Class) /= N_Identifier then
6024 Bad_Class;
6025
d628c015 6026 elsif Mech_Name_Id = Name_Descriptor
292beb8f 6027 and then Chars (Class) = Name_UBS
d628c015 6028 then
996ae0b0
RK
6029 Set_Mechanism (Ent, By_Descriptor_UBS);
6030
d628c015 6031 elsif Mech_Name_Id = Name_Descriptor
292beb8f 6032 and then Chars (Class) = Name_UBSB
d628c015 6033 then
996ae0b0
RK
6034 Set_Mechanism (Ent, By_Descriptor_UBSB);
6035
d628c015 6036 elsif Mech_Name_Id = Name_Descriptor
292beb8f 6037 and then Chars (Class) = Name_UBA
d628c015 6038 then
996ae0b0
RK
6039 Set_Mechanism (Ent, By_Descriptor_UBA);
6040
d628c015 6041 elsif Mech_Name_Id = Name_Descriptor
292beb8f 6042 and then Chars (Class) = Name_S
d628c015 6043 then
996ae0b0
RK
6044 Set_Mechanism (Ent, By_Descriptor_S);
6045
d628c015 6046 elsif Mech_Name_Id = Name_Descriptor
292beb8f 6047 and then Chars (Class) = Name_SB
d628c015 6048 then
996ae0b0
RK
6049 Set_Mechanism (Ent, By_Descriptor_SB);
6050
d628c015 6051 elsif Mech_Name_Id = Name_Descriptor
292beb8f 6052 and then Chars (Class) = Name_A
d628c015 6053 then
996ae0b0
RK
6054 Set_Mechanism (Ent, By_Descriptor_A);
6055
d628c015 6056 elsif Mech_Name_Id = Name_Descriptor
292beb8f 6057 and then Chars (Class) = Name_NCA
d628c015 6058 then
996ae0b0
RK
6059 Set_Mechanism (Ent, By_Descriptor_NCA);
6060
d628c015 6061 elsif Mech_Name_Id = Name_Short_Descriptor
292beb8f 6062 and then Chars (Class) = Name_UBS
d628c015
DR
6063 then
6064 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6065
6066 elsif Mech_Name_Id = Name_Short_Descriptor
292beb8f 6067 and then Chars (Class) = Name_UBSB
d628c015
DR
6068 then
6069 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6070
6071 elsif Mech_Name_Id = Name_Short_Descriptor
292beb8f 6072 and then Chars (Class) = Name_UBA
d628c015
DR
6073 then
6074 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6075
6076 elsif Mech_Name_Id = Name_Short_Descriptor
292beb8f 6077 and then Chars (Class) = Name_S
d628c015
DR
6078 then
6079 Set_Mechanism (Ent, By_Short_Descriptor_S);
6080
6081 elsif Mech_Name_Id = Name_Short_Descriptor
292beb8f 6082 and then Chars (Class) = Name_SB
d628c015
DR
6083 then
6084 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6085
6086 elsif Mech_Name_Id = Name_Short_Descriptor
292beb8f 6087 and then Chars (Class) = Name_A
d628c015
DR
6088 then
6089 Set_Mechanism (Ent, By_Short_Descriptor_A);
6090
6091 elsif Mech_Name_Id = Name_Short_Descriptor
292beb8f 6092 and then Chars (Class) = Name_NCA
d628c015
DR
6093 then
6094 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6095
996ae0b0
RK
6096 else
6097 Bad_Class;
6098 end if;
996ae0b0
RK
6099 end Set_Mechanism_Value;
6100
8a36a0cc
AC
6101 ---------------------------
6102 -- Set_Ravenscar_Profile --
6103 ---------------------------
6104
6105 -- The tasks to be done here are
6106
6107 -- Set required policies
6108
6109 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6110 -- pragma Locking_Policy (Ceiling_Locking)
6111
0da2c8ac 6112 -- Set Detect_Blocking mode
8a36a0cc 6113
cc335f43 6114 -- Set required restrictions (see System.Rident for detailed list)
8a36a0cc 6115
7fc53871
AC
6116 -- Set the No_Dependence rules
6117 -- No_Dependence => Ada.Asynchronous_Task_Control
6118 -- No_Dependence => Ada.Calendar
6119 -- No_Dependence => Ada.Execution_Time.Group_Budget
6120 -- No_Dependence => Ada.Execution_Time.Timers
6121 -- No_Dependence => Ada.Task_Attributes
6122 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6123
8a36a0cc 6124 procedure Set_Ravenscar_Profile (N : Node_Id) is
7fc53871
AC
6125 Prefix_Entity : Entity_Id;
6126 Selector_Entity : Entity_Id;
6127 Prefix_Node : Node_Id;
6128 Node : Node_Id;
6129
8a36a0cc
AC
6130 begin
6131 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6132
6133 if Task_Dispatching_Policy /= ' '
6134 and then Task_Dispatching_Policy /= 'F'
6135 then
6136 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6137 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6138
57193e09
TQ
6139 -- Set the FIFO_Within_Priorities policy, but always preserve
6140 -- System_Location since we like the error message with the run time
6141 -- name.
8a36a0cc
AC
6142
6143 else
6144 Task_Dispatching_Policy := 'F';
6145
6146 if Task_Dispatching_Policy_Sloc /= System_Location then
6147 Task_Dispatching_Policy_Sloc := Loc;
6148 end if;
6149 end if;
6150
6151 -- pragma Locking_Policy (Ceiling_Locking)
6152
6153 if Locking_Policy /= ' '
6154 and then Locking_Policy /= 'C'
6155 then
6156 Error_Msg_Sloc := Locking_Policy_Sloc;
6157 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6158
57193e09
TQ
6159 -- Set the Ceiling_Locking policy, but preserve System_Location since
6160 -- we like the error message with the run time name.
8a36a0cc
AC
6161
6162 else
6163 Locking_Policy := 'C';
6164
6165 if Locking_Policy_Sloc /= System_Location then
6166 Locking_Policy_Sloc := Loc;
6167 end if;
6168 end if;
6169
0da2c8ac
AC
6170 -- pragma Detect_Blocking
6171
6172 Detect_Blocking := True;
8a36a0cc
AC
6173
6174 -- Set the corresponding restrictions
6175
23e6615e
RD
6176 Set_Profile_Restrictions
6177 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
7fc53871
AC
6178
6179 -- Set the No_Dependence restrictions
6180
6181 -- The following No_Dependence restrictions:
6182 -- No_Dependence => Ada.Asynchronous_Task_Control
6183 -- No_Dependence => Ada.Calendar
6184 -- No_Dependence => Ada.Task_Attributes
6185 -- are already set by previous call to Set_Profile_Restrictions.
6186
6187 -- Set the following restrictions which were added to Ada 2005:
6188 -- No_Dependence => Ada.Execution_Time.Group_Budget
6189 -- No_Dependence => Ada.Execution_Time.Timers
6190
6191 if Ada_Version >= Ada_2005 then
6192 Name_Buffer (1 .. 3) := "ada";
6193 Name_Len := 3;
6194
6195 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6196
6197 Name_Buffer (1 .. 14) := "execution_time";
6198 Name_Len := 14;
6199
6200 Selector_Entity := Make_Identifier (Loc, Name_Find);
6201
6202 Prefix_Node :=
6203 Make_Selected_Component
6204 (Sloc => Loc,
6205 Prefix => Prefix_Entity,
6206 Selector_Name => Selector_Entity);
6207
6208 Name_Buffer (1 .. 13) := "group_budgets";
6209 Name_Len := 13;
6210
6211 Selector_Entity := Make_Identifier (Loc, Name_Find);
6212
6213 Node :=
6214 Make_Selected_Component
6215 (Sloc => Loc,
6216 Prefix => Prefix_Node,
6217 Selector_Name => Selector_Entity);
6218
6219 Set_Restriction_No_Dependence
6220 (Unit => Node,
6221 Warn => Treat_Restrictions_As_Warnings,
6222 Profile => Ravenscar);
6223
6224 Name_Buffer (1 .. 6) := "timers";
6225 Name_Len := 6;
6226
6227 Selector_Entity := Make_Identifier (Loc, Name_Find);
6228
6229 Node :=
6230 Make_Selected_Component
6231 (Sloc => Loc,
6232 Prefix => Prefix_Node,
6233 Selector_Name => Selector_Entity);
6234
6235 Set_Restriction_No_Dependence
6236 (Unit => Node,
6237 Warn => Treat_Restrictions_As_Warnings,
6238 Profile => Ravenscar);
6239 end if;
6240
6241 -- Set the following restrictions which was added to Ada 2012 (see
6242 -- AI-0171):
6243 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6244
6245 if Ada_Version >= Ada_2012 then
6246 Name_Buffer (1 .. 6) := "system";
6247 Name_Len := 6;
6248
6249 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6250
6251 Name_Buffer (1 .. 15) := "multiprocessors";
6252 Name_Len := 15;
6253
6254 Selector_Entity := Make_Identifier (Loc, Name_Find);
6255
6256 Prefix_Node :=
6257 Make_Selected_Component
6258 (Sloc => Loc,
6259 Prefix => Prefix_Entity,
6260 Selector_Name => Selector_Entity);
6261
6262 Name_Buffer (1 .. 19) := "dispatching_domains";
6263 Name_Len := 19;
6264
6265 Selector_Entity := Make_Identifier (Loc, Name_Find);
6266
6267 Node :=
6268 Make_Selected_Component
6269 (Sloc => Loc,
6270 Prefix => Prefix_Node,
6271 Selector_Name => Selector_Entity);
6272
6273 Set_Restriction_No_Dependence
6274 (Unit => Node,
6275 Warn => Treat_Restrictions_As_Warnings,
6276 Profile => Ravenscar);
6277 end if;
8a36a0cc
AC
6278 end Set_Ravenscar_Profile;
6279
996ae0b0
RK
6280 -- Start of processing for Analyze_Pragma
6281
6282 begin
d8b962d8
AC
6283 -- The following code is a defense against recursion. Not clear that
6284 -- this can happen legitimately, but perhaps some error situations
6285 -- can cause it, and we did see this recursion during testing.
6286
6287 if Analyzed (N) then
6288 return;
6289 else
6290 Set_Analyzed (N, True);
6291 end if;
6292
c690a2ec
RD
6293 -- Deal with unrecognized pragma
6294
ba759acd
AC
6295 Pname := Pragma_Name (N);
6296
1b24ada5 6297 if not Is_Pragma_Name (Pname) then
fbf5a39b 6298 if Warn_On_Unrecognized_Pragma then
1b24ada5 6299 Error_Msg_Name_1 := Pname;
470cd9e9 6300 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
c690a2ec
RD
6301
6302 for PN in First_Pragma_Name .. Last_Pragma_Name loop
1b24ada5 6303 if Is_Bad_Spelling_Of (Pname, PN) then
c690a2ec 6304 Error_Msg_Name_1 := PN;
0c020dde 6305 Error_Msg_N -- CODEFIX
470cd9e9 6306 ("\?possible misspelling of %!", Pragma_Identifier (N));
c690a2ec
RD
6307 exit;
6308 end if;
6309 end loop;
fbf5a39b 6310 end if;
c690a2ec
RD
6311
6312 return;
996ae0b0
RK
6313 end if;
6314
c690a2ec
RD
6315 -- Here to start processing for recognized pragma
6316
1b24ada5 6317 Prag_Id := Get_Pragma_Id (Pname);
c690a2ec 6318
ba759acd
AC
6319 if Present (Corresponding_Aspect (N)) then
6320 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6321 end if;
6322
996ae0b0
RK
6323 -- Preset arguments
6324
3d6c3bd7 6325 Arg_Count := 0;
1c54829e
AC
6326 Arg1 := Empty;
6327 Arg2 := Empty;
6328 Arg3 := Empty;
6329 Arg4 := Empty;
996ae0b0
RK
6330
6331 if Present (Pragma_Argument_Associations (N)) then
3d6c3bd7 6332 Arg_Count := List_Length (Pragma_Argument_Associations (N));
996ae0b0
RK
6333 Arg1 := First (Pragma_Argument_Associations (N));
6334
6335 if Present (Arg1) then
6336 Arg2 := Next (Arg1);
6337
6338 if Present (Arg2) then
6339 Arg3 := Next (Arg2);
6340
6341 if Present (Arg3) then
6342 Arg4 := Next (Arg3);
6343 end if;
6344 end if;
6345 end if;
6346 end if;
6347
996ae0b0 6348 -- An enumeration type defines the pragmas that are supported by the
f3d57416 6349 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
996ae0b0
RK
6350 -- into the corresponding enumeration value for the following case.
6351
6352 case Prag_Id is
6353
6354 -----------------
6355 -- Abort_Defer --
6356 -----------------
6357
6358 -- pragma Abort_Defer;
6359
6360 when Pragma_Abort_Defer =>
6361 GNAT_Pragma;
6362 Check_Arg_Count (0);
6363
6364 -- The only required semantic processing is to check the
6365 -- placement. This pragma must appear at the start of the
6366 -- statement sequence of a handled sequence of statements.
6367
6368 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6369 or else N /= First (Statements (Parent (N)))
6370 then
6371 Pragma_Misplaced;
6372 end if;
6373
6374 ------------
6375 -- Ada_83 --
6376 ------------
6377
6378 -- pragma Ada_83;
6379
6380 -- Note: this pragma also has some specific processing in Par.Prag
0ab80019 6381 -- because we want to set the Ada version mode during parsing.
996ae0b0
RK
6382
6383 when Pragma_Ada_83 =>
6384 GNAT_Pragma;
c690a2ec
RD
6385 Check_Arg_Count (0);
6386
6387 -- We really should check unconditionally for proper configuration
6388 -- pragma placement, since we really don't want mixed Ada modes
6389 -- within a single unit, and the GNAT reference manual has always
6390 -- said this was a configuration pragma, but we did not check and
6391 -- are hesitant to add the check now.
6392
0eed45bb
AC
6393 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6394 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6395 -- or Ada 2012 mode.
c690a2ec 6396
0791fbe9 6397 if Ada_Version >= Ada_2005 then
c690a2ec
RD
6398 Check_Valid_Configuration_Pragma;
6399 end if;
6400
6401 -- Now set Ada 83 mode
6402
0ab80019 6403 Ada_Version := Ada_83;
59e5fbe0 6404 Ada_Version_Explicit := Ada_Version;
996ae0b0
RK
6405
6406 ------------
6407 -- Ada_95 --
6408 ------------
6409
6410 -- pragma Ada_95;
6411
6412 -- Note: this pragma also has some specific processing in Par.Prag
0ab80019 6413 -- because we want to set the Ada 83 version mode during parsing.
996ae0b0
RK
6414
6415 when Pragma_Ada_95 =>
6416 GNAT_Pragma;
c690a2ec
RD
6417 Check_Arg_Count (0);
6418
6419 -- We really should check unconditionally for proper configuration
6420 -- pragma placement, since we really don't want mixed Ada modes
6421 -- within a single unit, and the GNAT reference manual has always
6422 -- said this was a configuration pragma, but we did not check and
6423 -- are hesitant to add the check now.
6424
6425 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
6426 -- or Ada 95, so we must check if we are in Ada 2005 mode.
6427
0791fbe9 6428 if Ada_Version >= Ada_2005 then
c690a2ec
RD
6429 Check_Valid_Configuration_Pragma;
6430 end if;
6431
6432 -- Now set Ada 95 mode
6433
0ab80019 6434 Ada_Version := Ada_95;
59e5fbe0 6435 Ada_Version_Explicit := Ada_Version;
0ab80019 6436
57193e09
TQ
6437 ---------------------
6438 -- Ada_05/Ada_2005 --
6439 ---------------------
0ab80019
AC
6440
6441 -- pragma Ada_05;
82c80734 6442 -- pragma Ada_05 (LOCAL_NAME);
0ab80019 6443
57193e09
TQ
6444 -- pragma Ada_2005;
6445 -- pragma Ada_2005 (LOCAL_NAME):
6446
599a7411 6447 -- Note: these pragmas also have some specific processing in Par.Prag
82c80734
RD
6448 -- because we want to set the Ada 2005 version mode during parsing.
6449
57193e09 6450 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
82c80734 6451 E_Id : Node_Id;
0ab80019 6452
82c80734 6453 begin
0ab80019 6454 GNAT_Pragma;
82c80734
RD
6455
6456 if Arg_Count = 1 then
6457 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 6458 E_Id := Get_Pragma_Arg (Arg1);
82c80734
RD
6459
6460 if Etype (E_Id) = Any_Type then
6461 return;
6462 end if;
6463
ac9e9918 6464 Set_Is_Ada_2005_Only (Entity (E_Id));
82c80734
RD
6465
6466 else
82c80734 6467 Check_Arg_Count (0);
c690a2ec
RD
6468
6469 -- For Ada_2005 we unconditionally enforce the documented
6470 -- configuration pragma placement, since we do not want to
6471 -- tolerate mixed modes in a unit involving Ada 2005. That
6472 -- would cause real difficulties for those cases where there
6473 -- are incompatibilities between Ada 95 and Ada 2005.
6474
6475 Check_Valid_Configuration_Pragma;
6476
0f1a6a0b
AC
6477 -- Now set appropriate Ada mode
6478
eaba57fb 6479 Ada_Version := Ada_2005;
0791fbe9 6480 Ada_Version_Explicit := Ada_2005;
82c80734
RD
6481 end if;
6482 end;
996ae0b0 6483
0eed45bb
AC
6484 ---------------------
6485 -- Ada_12/Ada_2012 --
6486 ---------------------
6487
6488 -- pragma Ada_12;
599a7411
AC
6489 -- pragma Ada_12 (LOCAL_NAME);
6490
0eed45bb 6491 -- pragma Ada_2012;
599a7411 6492 -- pragma Ada_2012 (LOCAL_NAME):
0eed45bb 6493
599a7411 6494 -- Note: these pragmas also have some specific processing in Par.Prag
0eed45bb
AC
6495 -- because we want to set the Ada 2012 version mode during parsing.
6496
599a7411
AC
6497 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6498 E_Id : Node_Id;
6499
6500 begin
0eed45bb 6501 GNAT_Pragma;
0eed45bb 6502
599a7411
AC
6503 if Arg_Count = 1 then
6504 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 6505 E_Id := Get_Pragma_Arg (Arg1);
599a7411
AC
6506
6507 if Etype (E_Id) = Any_Type then
6508 return;
6509 end if;
6510
6511 Set_Is_Ada_2012_Only (Entity (E_Id));
0eed45bb 6512
599a7411
AC
6513 else
6514 Check_Arg_Count (0);
0eed45bb 6515
599a7411
AC
6516 -- For Ada_2012 we unconditionally enforce the documented
6517 -- configuration pragma placement, since we do not want to
6518 -- tolerate mixed modes in a unit involving Ada 2012. That
6519 -- would cause real difficulties for those cases where there
6520 -- are incompatibilities between Ada 95 and Ada 2012. We could
6521 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
0eed45bb 6522
599a7411
AC
6523 Check_Valid_Configuration_Pragma;
6524
0f1a6a0b
AC
6525 -- Now set appropriate Ada mode
6526
eaba57fb 6527 Ada_Version := Ada_2012;
dbe945f1 6528 Ada_Version_Explicit := Ada_2012;
599a7411
AC
6529 end if;
6530 end;
0eed45bb 6531
996ae0b0
RK
6532 ----------------------
6533 -- All_Calls_Remote --
6534 ----------------------
6535
6536 -- pragma All_Calls_Remote [(library_package_NAME)];
6537
6538 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6539 Lib_Entity : Entity_Id;
6540
6541 begin
6542 Check_Ada_83_Warning;
6543 Check_Valid_Library_Unit_Pragma;
6544
6545 if Nkind (N) = N_Null_Statement then
6546 return;
6547 end if;
6548
6549 Lib_Entity := Find_Lib_Unit_Name;
6550
d9e0a587 6551 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
996ae0b0
RK
6552
6553 if Present (Lib_Entity)
6554 and then not Debug_Flag_U
6555 then
6556 if not Is_Remote_Call_Interface (Lib_Entity) then
6557 Error_Pragma ("pragma% only apply to rci unit");
6558
6559 -- Set flag for entity of the library unit
6560
6561 else
6562 Set_Has_All_Calls_Remote (Lib_Entity);
6563 end if;
6564
6565 end if;
6566 end All_Calls_Remote;
6567
6568 --------------
6569 -- Annotate --
6570 --------------
6571
d0995fa2 6572 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
996ae0b0 6573 -- ARG ::= NAME | EXPRESSION
d0995fa2
RD
6574
6575 -- The first two arguments are by convention intended to refer to an
6576 -- external tool and a tool-specific function. These arguments are
6577 -- not analyzed.
996ae0b0 6578
a4640a39
AC
6579 when Pragma_Annotate => Annotate : declare
6580 Arg : Node_Id;
6581 Exp : Node_Id;
6582
6583 begin
996ae0b0
RK
6584 GNAT_Pragma;
6585 Check_At_Least_N_Arguments (1);
6586 Check_Arg_Is_Identifier (Arg1);
7eaa7cdf
RD
6587 Check_No_Identifiers;
6588 Store_Note (N);
996ae0b0 6589
a4640a39 6590 -- Second parameter is optional, it is never analyzed
9534ab17 6591
ad05f2e9 6592 if No (Arg2) then
a4640a39 6593 null;
9534ab17 6594
a4640a39 6595 -- Here if we have a second parameter
996ae0b0 6596
a4640a39
AC
6597 else
6598 -- Second parameter must be identifier
996ae0b0 6599
a4640a39 6600 Check_Arg_Is_Identifier (Arg2);
996ae0b0 6601
a4640a39 6602 -- Process remaining parameters if any
3bb3f6d6 6603
a4640a39
AC
6604 Arg := Next (Arg2);
6605 while Present (Arg) loop
6606 Exp := Get_Pragma_Arg (Arg);
6607 Analyze (Exp);
996ae0b0 6608
a4640a39
AC
6609 if Is_Entity_Name (Exp) then
6610 null;
996ae0b0 6611
a4640a39
AC
6612 -- For string literals, we assume Standard_String as the
6613 -- type, unless the string contains wide or wide_wide
6614 -- characters.
6615
6616 elsif Nkind (Exp) = N_String_Literal then
6617 if Has_Wide_Wide_Character (Exp) then
6618 Resolve (Exp, Standard_Wide_Wide_String);
6619 elsif Has_Wide_Character (Exp) then
6620 Resolve (Exp, Standard_Wide_String);
226e989e 6621 else
a4640a39 6622 Resolve (Exp, Standard_String);
226e989e
AC
6623 end if;
6624
a4640a39
AC
6625 elsif Is_Overloaded (Exp) then
6626 Error_Pragma_Arg
6627 ("ambiguous argument for pragma%", Exp);
6628
6629 else
6630 Resolve (Exp);
6631 end if;
6632
6633 Next (Arg);
6634 end loop;
6635 end if;
996ae0b0
RK
6636 end Annotate;
6637
6638 ------------
6639 -- Assert --
6640 ------------
6641
59e5fbe0
RD
6642 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6643 -- [, [Message =>] Static_String_EXPRESSION]);
996ae0b0 6644
ac9e9918
RD
6645 when Pragma_Assert => Assert : declare
6646 Expr : Node_Id;
21d27997 6647 Newa : List_Id;
ac9e9918
RD
6648
6649 begin
2fa9443e 6650 Ada_2005_Pragma;
59e5fbe0
RD
6651 Check_At_Least_N_Arguments (1);
6652 Check_At_Most_N_Arguments (2);
6653 Check_Arg_Order ((Name_Check, Name_Message));
6654 Check_Optional_Identifier (Arg1, Name_Check);
996ae0b0 6655
21d27997 6656 -- We treat pragma Assert as equivalent to:
996ae0b0 6657
21d27997 6658 -- pragma Check (Assertion, condition [, msg]);
996ae0b0 6659
21d27997 6660 -- So rewrite pragma in this manner, and analyze the result
470cd9e9 6661
21d27997
RD
6662 Expr := Get_Pragma_Arg (Arg1);
6663 Newa := New_List (
6664 Make_Pragma_Argument_Association (Loc,
7675ad4f 6665 Expression => Make_Identifier (Loc, Name_Assertion)),
996ae0b0 6666
21d27997
RD
6667 Make_Pragma_Argument_Association (Sloc (Expr),
6668 Expression => Expr));
ac9e9918 6669
21d27997
RD
6670 if Arg_Count > 1 then
6671 Check_Optional_Identifier (Arg2, Name_Message);
6672 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6673 Append_To (Newa, Relocate_Node (Arg2));
996ae0b0
RK
6674 end if;
6675
21d27997
RD
6676 Rewrite (N,
6677 Make_Pragma (Loc,
9b3956dd 6678 Chars => Name_Check,
21d27997
RD
6679 Pragma_Argument_Associations => Newa));
6680 Analyze (N);
ac9e9918
RD
6681 end Assert;
6682
59e5fbe0
RD
6683 ----------------------
6684 -- Assertion_Policy --
6685 ----------------------
6686
9b3956dd 6687 -- pragma Assertion_Policy (Check | Disable |Ignore)
59e5fbe0 6688
21d27997
RD
6689 when Pragma_Assertion_Policy => Assertion_Policy : declare
6690 Policy : Node_Id;
6691
6692 begin
2fa9443e 6693 Ada_2005_Pragma;
21d27997 6694 Check_Valid_Configuration_Pragma;
59e5fbe0 6695 Check_Arg_Count (1);
21d27997 6696 Check_No_Identifiers;
9b3956dd 6697 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
21d27997
RD
6698
6699 -- We treat pragma Assertion_Policy as equivalent to:
6700
6701 -- pragma Check_Policy (Assertion, policy)
6702
6703 -- So rewrite the pragma in that manner and link on to the chain
6704 -- of Check_Policy pragmas, marking the pragma as analyzed.
6705
6706 Policy := Get_Pragma_Arg (Arg1);
6707
6708 Rewrite (N,
6709 Make_Pragma (Loc,
6710 Chars => Name_Check_Policy,
6711
6712 Pragma_Argument_Associations => New_List (
6713 Make_Pragma_Argument_Association (Loc,
7675ad4f 6714 Expression => Make_Identifier (Loc, Name_Assertion)),
21d27997
RD
6715
6716 Make_Pragma_Argument_Association (Loc,
6717 Expression =>
7675ad4f 6718 Make_Identifier (Sloc (Policy), Chars (Policy))))));
21d27997
RD
6719
6720 Set_Analyzed (N);
6721 Set_Next_Pragma (N, Opt.Check_Policy_List);
6722 Opt.Check_Policy_List := N;
6723 end Assertion_Policy;
59e5fbe0 6724
4351c21b
AC
6725 ------------------------------
6726 -- Assume_No_Invalid_Values --
6727 ------------------------------
6728
6729 -- pragma Assume_No_Invalid_Values (On | Off);
6730
6731 when Pragma_Assume_No_Invalid_Values =>
6732 GNAT_Pragma;
6733 Check_Valid_Configuration_Pragma;
6734 Check_Arg_Count (1);
6735 Check_No_Identifiers;
6736 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6737
0f1a6a0b 6738 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
4351c21b
AC
6739 Assume_No_Invalid_Values := True;
6740 else
6741 Assume_No_Invalid_Values := False;
6742 end if;
6743
996ae0b0
RK
6744 ---------------
6745 -- AST_Entry --
6746 ---------------
6747
6748 -- pragma AST_Entry (entry_IDENTIFIER);
6749
6750 when Pragma_AST_Entry => AST_Entry : declare
6751 Ent : Node_Id;
6752
6753 begin
6754 GNAT_Pragma;
6755 Check_VMS (N);
6756 Check_Arg_Count (1);
6757 Check_No_Identifiers;
6758 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 6759 Ent := Entity (Get_Pragma_Arg (Arg1));
996ae0b0
RK
6760
6761 -- Note: the implementation of the AST_Entry pragma could handle
6762 -- the entry family case fine, but for now we are consistent with
6763 -- the DEC rules, and do not allow the pragma, which of course
6764 -- has the effect of also forbidding the attribute.
6765
6766 if Ekind (Ent) /= E_Entry then
6767 Error_Pragma_Arg
6768 ("pragma% argument must be simple entry name", Arg1);
6769
6770 elsif Is_AST_Entry (Ent) then
6771 Error_Pragma_Arg
6772 ("duplicate % pragma for entry", Arg1);
6773
6774 elsif Has_Homonym (Ent) then
6775 Error_Pragma_Arg
6776 ("pragma% argument cannot specify overloaded entry", Arg1);
6777
6778 else
6779 declare
6780 FF : constant Entity_Id := First_Formal (Ent);
6781
6782 begin
6783 if Present (FF) then
6784 if Present (Next_Formal (FF)) then
6785 Error_Pragma_Arg
6786 ("entry for pragma% can have only one argument",
6787 Arg1);
6788
6789 elsif Parameter_Mode (FF) /= E_In_Parameter then
6790 Error_Pragma_Arg
6791 ("entry parameter for pragma% must have mode IN",
6792 Arg1);
6793 end if;
6794 end if;
6795 end;
6796
6797 Set_Is_AST_Entry (Ent);
6798 end if;
6799 end AST_Entry;
6800
6801 ------------------
6802 -- Asynchronous --
6803 ------------------
6804
6805 -- pragma Asynchronous (LOCAL_NAME);
6806
6807 when Pragma_Asynchronous => Asynchronous : declare
6808 Nm : Entity_Id;
6809 C_Ent : Entity_Id;
6810 L : List_Id;
6811 S : Node_Id;
6812 N : Node_Id;
6813 Formal : Entity_Id;
6814
6815 procedure Process_Async_Pragma;
6816 -- Common processing for procedure and access-to-procedure case
6817
6818 --------------------------
6819 -- Process_Async_Pragma --
6820 --------------------------
6821
6822 procedure Process_Async_Pragma is
6823 begin
57193e09 6824 if No (L) then
996ae0b0
RK
6825 Set_Is_Asynchronous (Nm);
6826 return;
6827 end if;
6828
6829 -- The formals should be of mode IN (RM E.4.1(6))
6830
6831 S := First (L);
6832 while Present (S) loop
6833 Formal := Defining_Identifier (S);
6834
6835 if Nkind (Formal) = N_Defining_Identifier
6836 and then Ekind (Formal) /= E_In_Parameter
6837 then
6838 Error_Pragma_Arg
6839 ("pragma% procedure can only have IN parameter",
6840 Arg1);
6841 end if;
6842
6843 Next (S);
6844 end loop;
6845
6846 Set_Is_Asynchronous (Nm);
6847 end Process_Async_Pragma;
6848
6849 -- Start of processing for pragma Asynchronous
6850
6851 begin
6852 Check_Ada_83_Warning;
6853 Check_No_Identifiers;
6854 Check_Arg_Count (1);
6855 Check_Arg_Is_Local_Name (Arg1);
6856
6857 if Debug_Flag_U then
6858 return;
6859 end if;
6860
6861 C_Ent := Cunit_Entity (Current_Sem_Unit);
0f1a6a0b
AC
6862 Analyze (Get_Pragma_Arg (Arg1));
6863 Nm := Entity (Get_Pragma_Arg (Arg1));
996ae0b0
RK
6864
6865 if not Is_Remote_Call_Interface (C_Ent)
6866 and then not Is_Remote_Types (C_Ent)
6867 then
6868 -- This pragma should only appear in an RCI or Remote Types
b3b9865d 6869 -- unit (RM E.4.1(4)).
996ae0b0
RK
6870
6871 Error_Pragma
6872 ("pragma% not in Remote_Call_Interface or " &
6873 "Remote_Types unit");
6874 end if;
6875
6876 if Ekind (Nm) = E_Procedure
6877 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6878 then
6879 if not Is_Remote_Call_Interface (Nm) then
6880 Error_Pragma_Arg
6881 ("pragma% cannot be applied on non-remote procedure",
6882 Arg1);
6883 end if;
6884
6885 L := Parameter_Specifications (Parent (Nm));
6886 Process_Async_Pragma;
6887 return;
6888
6889 elsif Ekind (Nm) = E_Function then
6890 Error_Pragma_Arg
6891 ("pragma% cannot be applied to function", Arg1);
6892
c857f5ed 6893 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
b3b9865d 6894 if Is_Record_Type (Nm) then
c857f5ed 6895
b3b9865d
AC
6896 -- A record type that is the Equivalent_Type for a remote
6897 -- access-to-subprogram type.
c885d7a1 6898
b3b9865d 6899 N := Declaration_Node (Corresponding_Remote_Type (Nm));
c857f5ed 6900
b3b9865d
AC
6901 else
6902 -- A non-expanded RAS type (distribution is not enabled)
6903
6904 N := Declaration_Node (Nm);
6905 end if;
996ae0b0
RK
6906
6907 if Nkind (N) = N_Full_Type_Declaration
6908 and then Nkind (Type_Definition (N)) =
6909 N_Access_Procedure_Definition
6910 then
6911 L := Parameter_Specifications (Type_Definition (N));
6912 Process_Async_Pragma;
6913
c885d7a1
AC
6914 if Is_Asynchronous (Nm)
6915 and then Expander_Active
c857f5ed 6916 and then Get_PCS_Name /= Name_No_DSA
c885d7a1 6917 then
c857f5ed 6918 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
c885d7a1
AC
6919 end if;
6920
996ae0b0
RK
6921 else
6922 Error_Pragma_Arg
6923 ("pragma% cannot reference access-to-function type",
6924 Arg1);
6925 end if;
6926
6927 -- Only other possibility is Access-to-class-wide type
6928
6929 elsif Is_Access_Type (Nm)
6930 and then Is_Class_Wide_Type (Designated_Type (Nm))
6931 then
6932 Check_First_Subtype (Arg1);
6933 Set_Is_Asynchronous (Nm);
6934 if Expander_Active then
6935 RACW_Type_Is_Asynchronous (Nm);
6936 end if;
6937
6938 else
6939 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6940 end if;
996ae0b0
RK
6941 end Asynchronous;
6942
6943 ------------
6944 -- Atomic --
6945 ------------
6946
6947 -- pragma Atomic (LOCAL_NAME);
6948
6949 when Pragma_Atomic =>
6950 Process_Atomic_Shared_Volatile;
6951
6952 -----------------------
6953 -- Atomic_Components --
6954 -----------------------
6955
6956 -- pragma Atomic_Components (array_LOCAL_NAME);
6957
6958 -- This processing is shared by Volatile_Components
6959
6960 when Pragma_Atomic_Components |
6961 Pragma_Volatile_Components =>
6962
6963 Atomic_Components : declare
6964 E_Id : Node_Id;
6965 E : Entity_Id;
6966 D : Node_Id;
6967 K : Node_Kind;
6968
6969 begin
996ae0b0
RK
6970 Check_Ada_83_Warning;
6971 Check_No_Identifiers;
6972 Check_Arg_Count (1);
6973 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 6974 E_Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
6975
6976 if Etype (E_Id) = Any_Type then
6977 return;
6978 end if;
6979
6980 E := Entity (E_Id);
6981
af31bffb
AC
6982 Check_Duplicate_Pragma (E);
6983
996ae0b0
RK
6984 if Rep_Item_Too_Early (E, N)
6985 or else
6986 Rep_Item_Too_Late (E, N)
6987 then
6988 return;
6989 end if;
6990
6991 D := Declaration_Node (E);
6992 K := Nkind (D);
6993
6994 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6995 or else
6996 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6997 and then Nkind (D) = N_Object_Declaration
6998 and then Nkind (Object_Definition (D)) =
6999 N_Constrained_Array_Definition)
7000 then
7001 -- The flag is set on the object, or on the base type
7002
7003 if Nkind (D) /= N_Object_Declaration then
7004 E := Base_Type (E);
7005 end if;
7006
eaba57fb 7007 Set_Has_Volatile_Components (E);
996ae0b0
RK
7008
7009 if Prag_Id = Pragma_Atomic_Components then
eaba57fb 7010 Set_Has_Atomic_Components (E);
996ae0b0
RK
7011 end if;
7012
7013 else
7014 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7015 end if;
7016 end Atomic_Components;
996ae0b0
RK
7017 --------------------
7018 -- Attach_Handler --
7019 --------------------
7020
7021 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7022
7023 when Pragma_Attach_Handler =>
7024 Check_Ada_83_Warning;
7025 Check_No_Identifiers;
7026 Check_Arg_Count (2);
fbf5a39b
AC
7027
7028 if No_Run_Time_Mode then
7029 Error_Msg_CRT ("Attach_Handler pragma", N);
7030 else
7031 Check_Interrupt_Or_Attach_Handler;
7032
0f1a6a0b
AC
7033 -- The expression that designates the attribute may depend on a
7034 -- discriminant, and is therefore a per- object expression, to
7035 -- be expanded in the init proc. If expansion is enabled, then
7036 -- perform semantic checks on a copy only.
fbf5a39b
AC
7037
7038 if Expander_Active then
7039 declare
91b1417d 7040 Temp : constant Node_Id :=
0f1a6a0b 7041 New_Copy_Tree (Get_Pragma_Arg (Arg2));
fbf5a39b
AC
7042 begin
7043 Set_Parent (Temp, N);
21d27997 7044 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
fbf5a39b
AC
7045 end;
7046
7047 else
0f1a6a0b
AC
7048 Analyze (Get_Pragma_Arg (Arg2));
7049 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
fbf5a39b
AC
7050 end if;
7051
7052 Process_Interrupt_Or_Attach_Handler;
7053 end if;
996ae0b0
RK
7054
7055 --------------------
7056 -- C_Pass_By_Copy --
7057 --------------------
7058
7059 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7060
7061 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7062 Arg : Node_Id;
7063 Val : Uint;
7064
7065 begin
7066 GNAT_Pragma;
7067 Check_Valid_Configuration_Pragma;
7068 Check_Arg_Count (1);
7069 Check_Optional_Identifier (Arg1, "max_size");
7070
0f1a6a0b 7071 Arg := Get_Pragma_Arg (Arg1);
996ae0b0
RK
7072 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7073
7074 Val := Expr_Value (Arg);
7075
7076 if Val <= 0 then
7077 Error_Pragma_Arg
7078 ("maximum size for pragma% must be positive", Arg1);
7079
7080 elsif UI_Is_In_Int_Range (Val) then
7081 Default_C_Record_Mechanism := UI_To_Int (Val);
7082
7083 -- If a giant value is given, Int'Last will do well enough.
7084 -- If sometime someone complains that a record larger than
7085 -- two gigabytes is not copied, we will worry about it then!
7086
7087 else
7088 Default_C_Record_Mechanism := Mechanism_Type'Last;
7089 end if;
7090 end C_Pass_By_Copy;
7091
21d27997
RD
7092 -----------
7093 -- Check --
7094 -----------
7095
15d8a51d
AC
7096 -- pragma Check ([Name =>] IDENTIFIER,
7097 -- [Check =>] Boolean_EXPRESSION
7098 -- [,[Message =>] String_EXPRESSION]);
21d27997
RD
7099
7100 when Pragma_Check => Check : declare
7101 Expr : Node_Id;
7102 Eloc : Source_Ptr;
7103
7104 Check_On : Boolean;
7105 -- Set True if category of assertions referenced by Name enabled
7106
7107 begin
7108 GNAT_Pragma;
7109 Check_At_Least_N_Arguments (2);
7110 Check_At_Most_N_Arguments (3);
7111 Check_Optional_Identifier (Arg1, Name_Name);
7112 Check_Optional_Identifier (Arg2, Name_Check);
7113
7114 if Arg_Count = 3 then
7115 Check_Optional_Identifier (Arg3, Name_Message);
7116 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
7117 end if;
7118
7119 Check_Arg_Is_Identifier (Arg1);
51bf9bdf 7120
9b3956dd
RD
7121 -- Completely ignore if disabled
7122
7123 if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
7124 Rewrite (N, Make_Null_Statement (Loc));
7125 Analyze (N);
7126 return;
7127 end if;
7128
51bf9bdf
AC
7129 -- Indicate if pragma is enabled. The Original_Node reference here
7130 -- is to deal with pragma Assert rewritten as a Check pragma.
7131
21d27997 7132 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
b26be063
AC
7133
7134 if Check_On then
b26be063
AC
7135 Set_SCO_Pragma_Enabled (Loc);
7136 end if;
21d27997
RD
7137
7138 -- If expansion is active and the check is not enabled then we
7139 -- rewrite the Check as:
7140
7141 -- if False and then condition then
7142 -- null;
7143 -- end if;
7144
7145 -- The reason we do this rewriting during semantic analysis rather
7146 -- than as part of normal expansion is that we cannot analyze and
7147 -- expand the code for the boolean expression directly, or it may
7148 -- cause insertion of actions that would escape the attempt to
7149 -- suppress the check code.
7150
4fdebd93 7151 -- Note that the Sloc for the if statement corresponds to the
21d27997
RD
7152 -- argument condition, not the pragma itself. The reason for this
7153 -- is that we may generate a warning if the condition is False at
7154 -- compile time, and we do not want to delete this warning when we
4fdebd93 7155 -- delete the if statement.
21d27997 7156
0f1a6a0b 7157 Expr := Get_Pragma_Arg (Arg2);
21d27997
RD
7158
7159 if Expander_Active and then not Check_On then
7160 Eloc := Sloc (Expr);
7161
7162 Rewrite (N,
7163 Make_If_Statement (Eloc,
7164 Condition =>
7165 Make_And_Then (Eloc,
7166 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7167 Right_Opnd => Expr),
7168 Then_Statements => New_List (
7169 Make_Null_Statement (Eloc))));
7170
7171 Analyze (N);
7172
7173 -- Check is active
7174
7175 else
7176 Analyze_And_Resolve (Expr, Any_Boolean);
7177 end if;
21d27997
RD
7178 end Check;
7179
c690a2ec
RD
7180 ----------------
7181 -- Check_Name --
7182 ----------------
7183
7184 -- pragma Check_Name (check_IDENTIFIER);
7185
7186 when Pragma_Check_Name =>
7187 Check_No_Identifiers;
7188 GNAT_Pragma;
7189 Check_Valid_Configuration_Pragma;
7190 Check_Arg_Count (1);
7191 Check_Arg_Is_Identifier (Arg1);
7192
7193 declare
0f1a6a0b 7194 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
c690a2ec
RD
7195
7196 begin
7197 for J in Check_Names.First .. Check_Names.Last loop
7198 if Check_Names.Table (J) = Nam then
7199 return;
7200 end if;
7201 end loop;
7202
7203 Check_Names.Append (Nam);
7204 end;
7205
21d27997
RD
7206 ------------------
7207 -- Check_Policy --
7208 ------------------
7209
ef7c5692
AC
7210 -- pragma Check_Policy (
7211 -- [Name =>] IDENTIFIER,
7212 -- [Policy =>] POLICY_IDENTIFIER);
21d27997 7213
9b3956dd 7214 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
21d27997 7215
b3b9865d
AC
7216 -- Note: this is a configuration pragma, but it is allowed to appear
7217 -- anywhere else.
21d27997
RD
7218
7219 when Pragma_Check_Policy =>
7220 GNAT_Pragma;
7221 Check_Arg_Count (2);
21d27997 7222 Check_Optional_Identifier (Arg1, Name_Name);
ef7c5692 7223 Check_Optional_Identifier (Arg2, Name_Policy);
21d27997 7224 Check_Arg_Is_One_Of
9b3956dd 7225 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
21d27997
RD
7226
7227 -- A Check_Policy pragma can appear either as a configuration
7228 -- pragma, or in a declarative part or a package spec (see RM
7229 -- 11.5(5) for rules for Suppress/Unsuppress which are also
7230 -- followed for Check_Policy).
7231
7232 if not Is_Configuration_Pragma then
7233 Check_Is_In_Decl_Part_Or_Package_Spec;
7234 end if;
7235
7236 Set_Next_Pragma (N, Opt.Check_Policy_List);
7237 Opt.Check_Policy_List := N;
7238
c690a2ec
RD
7239 ---------------------
7240 -- CIL_Constructor --
7241 ---------------------
7242
7243 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7244
7245 -- Processing for this pragma is shared with Java_Constructor
7246
996ae0b0
RK
7247 -------------
7248 -- Comment --
7249 -------------
7250
7251 -- pragma Comment (static_string_EXPRESSION)
7252
a30a01fe
RD
7253 -- Processing for pragma Comment shares the circuitry for pragma
7254 -- Ident. The only differences are that Ident enforces a limit of 31
7255 -- characters on its argument, and also enforces limitations on
7256 -- placement for DEC compatibility. Pragma Comment shares neither of
7257 -- these restrictions.
996ae0b0
RK
7258
7259 -------------------
7260 -- Common_Object --
7261 -------------------
7262
7263 -- pragma Common_Object (
470cd9e9 7264 -- [Internal =>] LOCAL_NAME
996ae0b0
RK
7265 -- [, [External =>] EXTERNAL_SYMBOL]
7266 -- [, [Size =>] EXTERNAL_SYMBOL]);
7267
7268 -- Processing for this pragma is shared with Psect_Object
7269
874a0341
RD
7270 ------------------------
7271 -- Compile_Time_Error --
7272 ------------------------
7273
7274 -- pragma Compile_Time_Error
7275 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7276
7277 when Pragma_Compile_Time_Error =>
a30a01fe 7278 GNAT_Pragma;
874a0341
RD
7279 Process_Compile_Time_Warning_Or_Error;
7280
fbf5a39b
AC
7281 --------------------------
7282 -- Compile_Time_Warning --
7283 --------------------------
7284
7285 -- pragma Compile_Time_Warning
7286 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7287
874a0341 7288 when Pragma_Compile_Time_Warning =>
a30a01fe 7289 GNAT_Pragma;
874a0341 7290 Process_Compile_Time_Warning_Or_Error;
fbf5a39b 7291
2d9ea47f
RD
7292 -------------------
7293 -- Compiler_Unit --
7294 -------------------
7295
7296 when Pragma_Compiler_Unit =>
7297 GNAT_Pragma;
7298 Check_Arg_Count (0);
7299 Set_Is_Compiler_Unit (Get_Source_Unit (N));
7300
c3217dac
RD
7301 -----------------------------
7302 -- Complete_Representation --
7303 -----------------------------
7304
7305 -- pragma Complete_Representation;
7306
7307 when Pragma_Complete_Representation =>
7308 GNAT_Pragma;
7309 Check_Arg_Count (0);
7310
7311 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7312 Error_Pragma
7313 ("pragma & must appear within record representation clause");
7314 end if;
7315
996ae0b0
RK
7316 ----------------------------
7317 -- Complex_Representation --
7318 ----------------------------
7319
7320 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7321
7322 when Pragma_Complex_Representation => Complex_Representation : declare
7323 E_Id : Entity_Id;
7324 E : Entity_Id;
7325 Ent : Entity_Id;
7326
7327 begin
7328 GNAT_Pragma;
7329 Check_Arg_Count (1);
7330 Check_Optional_Identifier (Arg1, Name_Entity);
7331 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 7332 E_Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
7333
7334 if Etype (E_Id) = Any_Type then
7335 return;
7336 end if;
7337
7338 E := Entity (E_Id);
7339
7340 if not Is_Record_Type (E) then
7341 Error_Pragma_Arg
7342 ("argument for pragma% must be record type", Arg1);
7343 end if;
7344
7345 Ent := First_Entity (E);
7346
7347 if No (Ent)
7348 or else No (Next_Entity (Ent))
7349 or else Present (Next_Entity (Next_Entity (Ent)))
7350 or else not Is_Floating_Point_Type (Etype (Ent))
7351 or else Etype (Ent) /= Etype (Next_Entity (Ent))
7352 then
7353 Error_Pragma_Arg
470cd9e9
RD
7354 ("record for pragma% must have two fields of the same "
7355 & "floating-point type", Arg1);
996ae0b0
RK
7356
7357 else
7358 Set_Has_Complex_Representation (Base_Type (E));
c690a2ec
RD
7359
7360 -- We need to treat the type has having a non-standard
7361 -- representation, for back-end purposes, even though in
7362 -- general a complex will have the default representation
7363 -- of a record with two real components.
7364
7365 Set_Has_Non_Standard_Rep (Base_Type (E));
996ae0b0
RK
7366 end if;
7367 end Complex_Representation;
7368
7369 -------------------------
7370 -- Component_Alignment --
7371 -------------------------
7372
7373 -- pragma Component_Alignment (
7374 -- [Form =>] ALIGNMENT_CHOICE
7375 -- [, [Name =>] type_LOCAL_NAME]);
7376 --
7377 -- ALIGNMENT_CHOICE ::=
7378 -- Component_Size
7379 -- | Component_Size_4
7380 -- | Storage_Unit
7381 -- | Default
7382
7383 when Pragma_Component_Alignment => Component_AlignmentP : declare
7384 Args : Args_List (1 .. 2);
fbf5a39b 7385 Names : constant Name_List (1 .. 2) := (
996ae0b0
RK
7386 Name_Form,
7387 Name_Name);
7388
7389 Form : Node_Id renames Args (1);
7390 Name : Node_Id renames Args (2);
7391
7392 Atype : Component_Alignment_Kind;
7393 Typ : Entity_Id;
7394
7395 begin
7396 GNAT_Pragma;
7397 Gather_Associations (Names, Args);
7398
7399 if No (Form) then
7400 Error_Pragma ("missing Form argument for pragma%");
7401 end if;
7402
7403 Check_Arg_Is_Identifier (Form);
7404
b3b9865d
AC
7405 -- Get proper alignment, note that Default = Component_Size on all
7406 -- machines we have so far, and we want to set this value rather
7407 -- than the default value to indicate that it has been explicitly
7408 -- set (and thus will not get overridden by the default component
7409 -- alignment for the current scope)
996ae0b0
RK
7410
7411 if Chars (Form) = Name_Component_Size then
7412 Atype := Calign_Component_Size;
7413
7414 elsif Chars (Form) = Name_Component_Size_4 then
7415 Atype := Calign_Component_Size_4;
7416
7417 elsif Chars (Form) = Name_Default then
7418 Atype := Calign_Component_Size;
7419
7420 elsif Chars (Form) = Name_Storage_Unit then
7421 Atype := Calign_Storage_Unit;
7422
7423 else
7424 Error_Pragma_Arg
7425 ("invalid Form parameter for pragma%", Form);
7426 end if;
7427
7428 -- Case with no name, supplied, affects scope table entry
7429
7430 if No (Name) then
7431 Scope_Stack.Table
7432 (Scope_Stack.Last).Component_Alignment_Default := Atype;
7433
7434 -- Case of name supplied
7435
7436 else
7437 Check_Arg_Is_Local_Name (Name);
7438 Find_Type (Name);
7439 Typ := Entity (Name);
7440
7441 if Typ = Any_Type
7442 or else Rep_Item_Too_Early (Typ, N)
7443 then
7444 return;
7445 else
7446 Typ := Underlying_Type (Typ);
7447 end if;
7448
7449 if not Is_Record_Type (Typ)
7450 and then not Is_Array_Type (Typ)
7451 then
7452 Error_Pragma_Arg
7453 ("Name parameter of pragma% must identify record or " &
7454 "array type", Name);
7455 end if;
7456
7457 -- An explicit Component_Alignment pragma overrides an
7458 -- implicit pragma Pack, but not an explicit one.
7459
7460 if not Has_Pragma_Pack (Base_Type (Typ)) then
7461 Set_Is_Packed (Base_Type (Typ), False);
7462 Set_Component_Alignment (Base_Type (Typ), Atype);
7463 end if;
7464 end if;
996ae0b0
RK
7465 end Component_AlignmentP;
7466
7467 ----------------
7468 -- Controlled --
7469 ----------------
7470
7471 -- pragma Controlled (first_subtype_LOCAL_NAME);
7472
7473 when Pragma_Controlled => Controlled : declare
7474 Arg : Node_Id;
7475
7476 begin
7477 Check_No_Identifiers;
7478 Check_Arg_Count (1);
7479 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 7480 Arg := Get_Pragma_Arg (Arg1);
996ae0b0
RK
7481
7482 if not Is_Entity_Name (Arg)
7483 or else not Is_Access_Type (Entity (Arg))
7484 then
7485 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7486 else
7487 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7488 end if;
7489 end Controlled;
7490
7491 ----------------
7492 -- Convention --
7493 ----------------
7494
7495 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
7496 -- [Entity =>] LOCAL_NAME);
7497
7498 when Pragma_Convention => Convention : declare
7499 C : Convention_Id;
7500 E : Entity_Id;
67ce0d7e
RD
7501 pragma Warnings (Off, C);
7502 pragma Warnings (Off, E);
996ae0b0 7503 begin
59e5fbe0 7504 Check_Arg_Order ((Name_Convention, Name_Entity));
996ae0b0
RK
7505 Check_Ada_83_Warning;
7506 Check_Arg_Count (2);
7507 Process_Convention (C, E);
7508 end Convention;
7509
07fc65c4
GB
7510 ---------------------------
7511 -- Convention_Identifier --
7512 ---------------------------
7513
7514 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
7515 -- [Convention =>] convention_IDENTIFIER);
7516
7517 when Pragma_Convention_Identifier => Convention_Identifier : declare
7518 Idnam : Name_Id;
7519 Cname : Name_Id;
7520
7521 begin
7522 GNAT_Pragma;
59e5fbe0 7523 Check_Arg_Order ((Name_Name, Name_Convention));
07fc65c4
GB
7524 Check_Arg_Count (2);
7525 Check_Optional_Identifier (Arg1, Name_Name);
7526 Check_Optional_Identifier (Arg2, Name_Convention);
7527 Check_Arg_Is_Identifier (Arg1);
c690a2ec 7528 Check_Arg_Is_Identifier (Arg2);
0f1a6a0b
AC
7529 Idnam := Chars (Get_Pragma_Arg (Arg1));
7530 Cname := Chars (Get_Pragma_Arg (Arg2));
07fc65c4
GB
7531
7532 if Is_Convention_Name (Cname) then
7533 Record_Convention_Identifier
7534 (Idnam, Get_Convention_Id (Cname));
7535 else
7536 Error_Pragma_Arg
7537 ("second arg for % pragma must be convention", Arg2);
7538 end if;
7539 end Convention_Identifier;
7540
996ae0b0
RK
7541 ---------------
7542 -- CPP_Class --
7543 ---------------
7544
7545 -- pragma CPP_Class ([Entity =>] local_NAME)
7546
7547 when Pragma_CPP_Class => CPP_Class : declare
874a0341
RD
7548 Arg : Node_Id;
7549 Typ : Entity_Id;
996ae0b0
RK
7550
7551 begin
874a0341 7552 if Warn_On_Obsolescent_Feature then
ed2233dc 7553 Error_Msg_N
874a0341
RD
7554 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7555 " by pragma import?", N);
7556 end if;
7557
996ae0b0
RK
7558 GNAT_Pragma;
7559 Check_Arg_Count (1);
7560 Check_Optional_Identifier (Arg1, Name_Entity);
7561 Check_Arg_Is_Local_Name (Arg1);
7562
0f1a6a0b 7563 Arg := Get_Pragma_Arg (Arg1);
996ae0b0
RK
7564 Analyze (Arg);
7565
7566 if Etype (Arg) = Any_Type then
7567 return;
7568 end if;
7569
7570 if not Is_Entity_Name (Arg)
7571 or else not Is_Type (Entity (Arg))
7572 then
7573 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7574 end if;
7575
7576 Typ := Entity (Arg);
7577
996ae0b0 7578 if not Is_Tagged_Type (Typ) then
874a0341 7579 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
996ae0b0 7580 end if;
874a0341 7581
56e94186
AC
7582 -- Types treated as CPP classes must be declared limited (note:
7583 -- this used to be a warning but there is no real benefit to it
7584 -- since we did effectively intend to treat the type as limited
7585 -- anyway).
2fa9443e
ES
7586
7587 if not Is_Limited_Type (Typ) then
ed2233dc 7588 Error_Msg_N
56e94186 7589 ("imported 'C'P'P type must be limited",
2fa9443e
ES
7590 Get_Pragma_Arg (Arg1));
7591 end if;
7592
874a0341 7593 Set_Is_CPP_Class (Typ);
874a0341 7594 Set_Convention (Typ, Convention_CPP);
0c020dde
AC
7595
7596 -- Imported CPP types must not have discriminants (because C++
7597 -- classes do not have discriminants).
7598
7599 if Has_Discriminants (Typ) then
7600 Error_Msg_N
7601 ("imported 'C'P'P type cannot have discriminants",
7602 First (Discriminant_Specifications
7603 (Declaration_Node (Typ))));
7604 end if;
7605
7606 -- Components of imported CPP types must not have default
7607 -- expressions because the constructor (if any) is in the
7608 -- C++ side.
7609
7610 if Is_Incomplete_Or_Private_Type (Typ)
7611 and then No (Underlying_Type (Typ))
7612 then
7613 -- It should be an error to apply pragma CPP to a private
7614 -- type if the underlying type is not visible (as it is
7615 -- for any representation item). For now, for backward
7616 -- compatibility we do nothing but we cannot check components
7617 -- because they are not available at this stage. All this code
7618 -- will be removed when we cleanup this obsolete GNAT pragma???
7619
7620 null;
7621
7622 else
7623 declare
7624 Tdef : constant Node_Id :=
7625 Type_Definition (Declaration_Node (Typ));
7626 Clist : Node_Id;
7627 Comp : Node_Id;
7628
7629 begin
7630 if Nkind (Tdef) = N_Record_Definition then
7631 Clist := Component_List (Tdef);
7632 else
7633 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7634 Clist := Component_List (Record_Extension_Part (Tdef));
7635 end if;
7636
7637 if Present (Clist) then
7638 Comp := First (Component_Items (Clist));
7639 while Present (Comp) loop
7640 if Present (Expression (Comp)) then
7641 Error_Msg_N
7642 ("component of imported 'C'P'P type cannot have" &
7643 " default expression", Expression (Comp));
7644 end if;
7645
7646 Next (Comp);
7647 end loop;
7648 end if;
7649 end;
7650 end if;
996ae0b0
RK
7651 end CPP_Class;
7652
7653 ---------------------
7654 -- CPP_Constructor --
7655 ---------------------
7656
874a0341
RD
7657 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7658 -- [, [External_Name =>] static_string_EXPRESSION ]
7659 -- [, [Link_Name =>] static_string_EXPRESSION ]);
996ae0b0
RK
7660
7661 when Pragma_CPP_Constructor => CPP_Constructor : declare
7b4db06c
JM
7662 Elmt : Elmt_Id;
7663 Id : Entity_Id;
7664 Def_Id : Entity_Id;
7665 Tag_Typ : Entity_Id;
996ae0b0
RK
7666
7667 begin
7668 GNAT_Pragma;
874a0341
RD
7669 Check_At_Least_N_Arguments (1);
7670 Check_At_Most_N_Arguments (3);
996ae0b0
RK
7671 Check_Optional_Identifier (Arg1, Name_Entity);
7672 Check_Arg_Is_Local_Name (Arg1);
7673
0f1a6a0b 7674 Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
7675 Find_Program_Unit_Name (Id);
7676
7677 -- If we did not find the name, we are done
7678
7679 if Etype (Id) = Any_Type then
7680 return;
7681 end if;
7682
7683 Def_Id := Entity (Id);
7684
cefce34c
JM
7685 -- Check if already defined as constructor
7686
7687 if Is_Constructor (Def_Id) then
7688 Error_Msg_N
7689 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7690 return;
7691 end if;
7692
996ae0b0 7693 if Ekind (Def_Id) = E_Function
7b4db06c
JM
7694 and then (Is_CPP_Class (Etype (Def_Id))
7695 or else (Is_Class_Wide_Type (Etype (Def_Id))
7696 and then
7697 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
996ae0b0 7698 then
996ae0b0 7699 if Arg_Count >= 2 then
874a0341
RD
7700 Set_Imported (Def_Id);
7701 Set_Is_Public (Def_Id);
996ae0b0
RK
7702 Process_Interface_Name (Def_Id, Arg2, Arg3);
7703 end if;
7704
236fecbf
JM
7705 Set_Has_Completion (Def_Id);
7706 Set_Is_Constructor (Def_Id);
996ae0b0 7707
7b4db06c
JM
7708 -- Imported C++ constructors are not dispatching primitives
7709 -- because in C++ they don't have a dispatch table slot.
7710 -- However, in Ada the constructor has the profile of a
7711 -- function that returns a tagged type and therefore it has
3c92a2b8
AC
7712 -- been treated as a primitive operation during semantic
7713 -- analysis. We now remove it from the list of primitive
7714 -- operations of the type.
7b4db06c
JM
7715
7716 if Is_Tagged_Type (Etype (Def_Id))
7717 and then not Is_Class_Wide_Type (Etype (Def_Id))
7718 then
7719 pragma Assert (Is_Dispatching_Operation (Def_Id));
7720 Tag_Typ := Etype (Def_Id);
7721
7722 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
3c92a2b8 7723 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7b4db06c
JM
7724 Next_Elmt (Elmt);
7725 end loop;
7726
7727 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7728 Set_Is_Dispatching_Operation (Def_Id, False);
7729 end if;
7730
7731 -- For backward compatibility, if the constructor returns a
3c92a2b8
AC
7732 -- class wide type, and we internally change the return type to
7733 -- the corresponding root type.
7b4db06c
JM
7734
7735 if Is_Class_Wide_Type (Etype (Def_Id)) then
7736 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7737 end if;
996ae0b0
RK
7738 else
7739 Error_Pragma_Arg
7740 ("pragma% requires function returning a 'C'P'P_Class type",
7741 Arg1);
7742 end if;
7743 end CPP_Constructor;
7744
7745 -----------------
7746 -- CPP_Virtual --
7747 -----------------
7748
996ae0b0 7749 when Pragma_CPP_Virtual => CPP_Virtual : declare
996ae0b0 7750 begin
a30a01fe
RD
7751 GNAT_Pragma;
7752
874a0341 7753 if Warn_On_Obsolescent_Feature then
ed2233dc 7754 Error_Msg_N
874a0341
RD
7755 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7756 "no effect?", N);
996ae0b0
RK
7757 end if;
7758 end CPP_Virtual;
7759
7760 ----------------
7761 -- CPP_Vtable --
7762 ----------------
7763
996ae0b0 7764 when Pragma_CPP_Vtable => CPP_Vtable : declare
996ae0b0 7765 begin
a30a01fe
RD
7766 GNAT_Pragma;
7767
874a0341 7768 if Warn_On_Obsolescent_Feature then
ed2233dc 7769 Error_Msg_N
874a0341
RD
7770 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7771 "no effect?", N);
996ae0b0 7772 end if;
996ae0b0
RK
7773 end CPP_Vtable;
7774
8918fe18
AC
7775 ---------
7776 -- CPU --
7777 ---------
7778
7779 -- pragma CPU (EXPRESSION);
7780
7781 when Pragma_CPU => CPU : declare
7782 P : constant Node_Id := Parent (N);
7783 Arg : Node_Id;
7784
7785 begin
7786 Ada_2012_Pragma;
7787 Check_No_Identifiers;
7788 Check_Arg_Count (1);
7789
7790 -- Subprogram case
7791
7792 if Nkind (P) = N_Subprogram_Body then
7793 Check_In_Main_Program;
7794
7795 Arg := Get_Pragma_Arg (Arg1);
7796 Analyze_And_Resolve (Arg, Any_Integer);
7797
7798 -- Must be static
7799
7800 if not Is_Static_Expression (Arg) then
7801 Flag_Non_Static_Expr
7802 ("main subprogram affinity is not static!", Arg);
7803 raise Pragma_Exit;
7804
7805 -- If constraint error, then we already signalled an error
7806
7807 elsif Raises_Constraint_Error (Arg) then
7808 null;
7809
7810 -- Otherwise check in range
7811
7812 else
7813 declare
7814 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7815 -- This is the entity System.Multiprocessors.CPU_Range;
7816
7817 Val : constant Uint := Expr_Value (Arg);
7818
7819 begin
7820 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7821 or else
7822 Val > Expr_Value (Type_High_Bound (CPU_Id))
7823 then
7824 Error_Pragma_Arg
7825 ("main subprogram CPU is out of range", Arg1);
7826 end if;
7827 end;
7828 end if;
7829
7830 Set_Main_CPU
7831 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7832
7833 -- Task case
7834
7835 elsif Nkind (P) = N_Task_Definition then
7836 Arg := Get_Pragma_Arg (Arg1);
7837
7838 -- The expression must be analyzed in the special manner
7839 -- described in "Handling of Default and Per-Object
7840 -- Expressions" in sem.ads.
7841
7842 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7843
7844 -- Anything else is incorrect
7845
7846 else
7847 Pragma_Misplaced;
7848 end if;
7849
7850 if Has_Pragma_CPU (P) then
7851 Error_Pragma ("duplicate pragma% not allowed");
7852 else
7853 Set_Has_Pragma_CPU (P, True);
7854
7855 if Nkind (P) = N_Task_Definition then
7856 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7857 end if;
7858 end if;
7859 end CPU;
7860
996ae0b0
RK
7861 -----------
7862 -- Debug --
7863 -----------
7864
c3217dac
RD
7865 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7866
7867 when Pragma_Debug => Debug : declare
7ab4d95a
AC
7868 Cond : Node_Id;
7869 Call : Node_Id;
996ae0b0 7870
c3217dac 7871 begin
996ae0b0
RK
7872 GNAT_Pragma;
7873
9b3956dd
RD
7874 -- Skip analysis if disabled
7875
7876 if Debug_Pragmas_Disabled then
7877 Rewrite (N, Make_Null_Statement (Loc));
7878 Analyze (N);
7879 return;
7880 end if;
7881
c3217dac
RD
7882 Cond :=
7883 New_Occurrence_Of
7884 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7885 Loc);
7886
44a10091
AC
7887 if Debug_Pragmas_Enabled then
7888 Set_SCO_Pragma_Enabled (Loc);
7889 end if;
7890
c3217dac
RD
7891 if Arg_Count = 2 then
7892 Cond :=
7893 Make_And_Then (Loc,
7ab4d95a
AC
7894 Left_Opnd => Relocate_Node (Cond),
7895 Right_Opnd => Get_Pragma_Arg (Arg1));
7896 Call := Get_Pragma_Arg (Arg2);
7897 else
7898 Call := Get_Pragma_Arg (Arg1);
7899 end if;
7900
7901 if Nkind_In (Call,
7902 N_Indexed_Component,
7903 N_Function_Call,
7904 N_Identifier,
7905 N_Selected_Component)
7906 then
7907 -- If this pragma Debug comes from source, its argument was
7908 -- parsed as a name form (which is syntactically identical).
7909 -- Change it to a procedure call statement now.
7910
7911 Change_Name_To_Procedure_Call_Statement (Call);
7912
7913 elsif Nkind (Call) = N_Procedure_Call_Statement then
7914
7915 -- Already in the form of a procedure call statement: nothing
7916 -- to do (could happen in case of an internally generated
7917 -- pragma Debug).
7918
7919 null;
7920
7921 else
7922 -- All other cases: diagnose error
7923
7924 Error_Msg
b3c33641
AC
7925 ("argument of pragma ""Debug"" is not procedure call",
7926 Sloc (Call));
7ab4d95a 7927 return;
c3217dac
RD
7928 end if;
7929
7930 -- Rewrite into a conditional with an appropriate condition. We
7931 -- wrap the procedure call in a block so that overhead from e.g.
7932 -- use of the secondary stack does not generate execution overhead
7933 -- for suppressed conditions.
996ae0b0 7934
6cdb2c6e 7935 Rewrite (N, Make_Implicit_If_Statement (N,
c3217dac
RD
7936 Condition => Cond,
7937 Then_Statements => New_List (
7938 Make_Block_Statement (Loc,
7939 Handled_Statement_Sequence =>
7940 Make_Handled_Sequence_Of_Statements (Loc,
7ab4d95a 7941 Statements => New_List (Relocate_Node (Call)))))));
6cdb2c6e 7942 Analyze (N);
996ae0b0
RK
7943 end Debug;
7944
6e18b0e5
RD
7945 ------------------
7946 -- Debug_Policy --
7947 ------------------
7948
7949 -- pragma Debug_Policy (Check | Ignore)
7950
7951 when Pragma_Debug_Policy =>
7952 GNAT_Pragma;
7953 Check_Arg_Count (1);
9b3956dd 7954 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
0f1a6a0b
AC
7955 Debug_Pragmas_Enabled :=
7956 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
9b3956dd
RD
7957 Debug_Pragmas_Disabled :=
7958 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
6e18b0e5 7959
0da2c8ac
AC
7960 ---------------------
7961 -- Detect_Blocking --
7962 ---------------------
7963
7964 -- pragma Detect_Blocking;
7965
7966 when Pragma_Detect_Blocking =>
2fa9443e 7967 Ada_2005_Pragma;
0da2c8ac
AC
7968 Check_Arg_Count (0);
7969 Check_Valid_Configuration_Pragma;
7970 Detect_Blocking := True;
7971
fab2daeb
AC
7972 --------------------------
7973 -- Default_Storage_Pool --
7974 --------------------------
7975
7976 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7977
7978 when Pragma_Default_Storage_Pool =>
7979 Ada_2012_Pragma;
7980 Check_Arg_Count (1);
7981
7982 -- Default_Storage_Pool can appear as a configuration pragma, or
7983 -- in a declarative part or a package spec.
7984
7985 if not Is_Configuration_Pragma then
7986 Check_Is_In_Decl_Part_Or_Package_Spec;
7987 end if;
7988
7989 -- Case of Default_Storage_Pool (null);
7990
7991 if Nkind (Expression (Arg1)) = N_Null then
7992 Analyze (Expression (Arg1));
e606088a
AC
7993
7994 -- This is an odd case, this is not really an expression, so
7995 -- we don't have a type for it. So just set the type to Empty.
7996
fab2daeb 7997 Set_Etype (Expression (Arg1), Empty);
fab2daeb
AC
7998
7999 -- Case of Default_Storage_Pool (storage_pool_NAME);
8000
8001 else
8002 -- If it's a configuration pragma, then the only allowed
8003 -- argument is "null".
8004
8005 if Is_Configuration_Pragma then
8006 Error_Pragma_Arg ("NULL expected", Arg1);
8007 end if;
8008
8009 -- The expected type for a non-"null" argument is
8010 -- Root_Storage_Pool'Class.
8011
8012 Analyze_And_Resolve
8013 (Get_Pragma_Arg (Arg1),
8014 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8015 end if;
8016
8017 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
8018 -- for an access type will use this information to set the
8019 -- appropriate attributes of the access type.
8020
8021 Default_Pool := Expression (Arg1);
8022
95cb33a5
AC
8023 ---------------
8024 -- Dimension --
8025 ---------------
8026
8027 when Pragma_Dimension =>
8028 GNAT_Pragma;
8029 Check_Arg_Count (4);
8030 Check_No_Identifiers;
8031 Check_Arg_Is_Local_Name (Arg1);
8032
8033 if not Is_Type (Arg1) then
8034 Error_Pragma ("first argument for pragma% must be subtype");
8035 end if;
8036
8037 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
8038 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
8039 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
8040
12b4d338
AC
8041 ------------------------------------
8042 -- Disable_Atomic_Synchronization --
8043 ------------------------------------
8044
8045 -- pragma Disable_Atomic_Synchronization [(Entity)];
8046
8047 when Pragma_Disable_Atomic_Synchronization =>
8048 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8049
996ae0b0
RK
8050 -------------------
8051 -- Discard_Names --
8052 -------------------
8053
8054 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
8055
8056 when Pragma_Discard_Names => Discard_Names : declare
996ae0b0 8057 E : Entity_Id;
4351c21b 8058 E_Id : Entity_Id;
996ae0b0
RK
8059
8060 begin
996ae0b0
RK
8061 Check_Ada_83_Warning;
8062
8063 -- Deal with configuration pragma case
8064
8065 if Arg_Count = 0 and then Is_Configuration_Pragma then
8066 Global_Discard_Names := True;
8067 return;
8068
8069 -- Otherwise, check correct appropriate context
8070
8071 else
8072 Check_Is_In_Decl_Part_Or_Package_Spec;
8073
8074 if Arg_Count = 0 then
8075
8076 -- If there is no parameter, then from now on this pragma
8077 -- applies to any enumeration, exception or tagged type
2fa9443e
ES
8078 -- defined in the current declarative part, and recursively
8079 -- to any nested scope.
996ae0b0 8080
eaba57fb 8081 Set_Discard_Names (Current_Scope);
996ae0b0
RK
8082 return;
8083
8084 else
8085 Check_Arg_Count (1);
8086 Check_Optional_Identifier (Arg1, Name_On);
8087 Check_Arg_Is_Local_Name (Arg1);
4351c21b 8088
0f1a6a0b 8089 E_Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
8090
8091 if Etype (E_Id) = Any_Type then
8092 return;
8093 else
8094 E := Entity (E_Id);
8095 end if;
8096
8097 if (Is_First_Subtype (E)
4351c21b
AC
8098 and then
8099 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
996ae0b0
RK
8100 or else Ekind (E) = E_Exception
8101 then
eaba57fb 8102 Set_Discard_Names (E);
996ae0b0
RK
8103 else
8104 Error_Pragma_Arg
8105 ("inappropriate entity for pragma%", Arg1);
8106 end if;
4351c21b 8107
996ae0b0
RK
8108 end if;
8109 end if;
8110 end Discard_Names;
8111
67645bde
AC
8112 ------------------------
8113 -- Dispatching_Domain --
8114 ------------------------
8115
8116 -- pragma Dispatching_Domain (EXPRESSION);
8117
8118 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
8119 P : constant Node_Id := Parent (N);
8120 Arg : Node_Id;
8121
8122 begin
8123 Ada_2012_Pragma;
8124 Check_No_Identifiers;
8125 Check_Arg_Count (1);
8126
8127 -- This pragma is born obsolete, but not the aspect
8128
8129 if not From_Aspect_Specification (N) then
8130 Check_Restriction
8131 (No_Obsolescent_Features, Pragma_Identifier (N));
8132 end if;
8133
8134 if Nkind (P) = N_Task_Definition then
8135 Arg := Get_Pragma_Arg (Arg1);
8136
8137 -- The expression must be analyzed in the special manner
8138 -- described in "Handling of Default and Per-Object
8139 -- Expressions" in sem.ads.
8140
8141 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8142
8143 -- Anything else is incorrect
8144
8145 else
8146 Pragma_Misplaced;
8147 end if;
8148
8149 if Has_Pragma_Dispatching_Domain (P) then
8150 Error_Pragma ("duplicate pragma% not allowed");
8151 else
8152 Set_Has_Pragma_Dispatching_Domain (P, True);
8153
8154 if Nkind (P) = N_Task_Definition then
8155 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8156 end if;
8157 end if;
8158 end Dispatching_Domain;
8159
996ae0b0
RK
8160 ---------------
8161 -- Elaborate --
8162 ---------------
8163
8164 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8165
8166 when Pragma_Elaborate => Elaborate : declare
ac9e9918
RD
8167 Arg : Node_Id;
8168 Citem : Node_Id;
996ae0b0
RK
8169
8170 begin
8171 -- Pragma must be in context items list of a compilation unit
8172
ac9e9918 8173 if not Is_In_Context_Clause then
996ae0b0 8174 Pragma_Misplaced;
996ae0b0
RK
8175 end if;
8176
8177 -- Must be at least one argument
8178
8179 if Arg_Count = 0 then
8180 Error_Pragma ("pragma% requires at least one argument");
8181 end if;
8182
8183 -- In Ada 83 mode, there can be no items following it in the
8184 -- context list except other pragmas and implicit with clauses
8185 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8186 -- placement rule does not apply.
8187
0ab80019 8188 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
996ae0b0 8189 Citem := Next (N);
996ae0b0
RK
8190 while Present (Citem) loop
8191 if Nkind (Citem) = N_Pragma
8192 or else (Nkind (Citem) = N_With_Clause
8193 and then Implicit_With (Citem))
8194 then
8195 null;
8196 else
8197 Error_Pragma
8198 ("(Ada 83) pragma% must be at end of context clause");
8199 end if;
8200
8201 Next (Citem);
8202 end loop;
8203 end if;
8204
8205 -- Finally, the arguments must all be units mentioned in a with
ac9e9918
RD
8206 -- clause in the same context clause. Note we already checked (in
8207 -- Par.Prag) that the arguments are all identifiers or selected
8208 -- components.
996ae0b0
RK
8209
8210 Arg := Arg1;
8211 Outer : while Present (Arg) loop
ac9e9918 8212 Citem := First (List_Containing (N));
996ae0b0
RK
8213 Inner : while Citem /= N loop
8214 if Nkind (Citem) = N_With_Clause
0f1a6a0b 8215 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
996ae0b0
RK
8216 then
8217 Set_Elaborate_Present (Citem, True);
0f1a6a0b 8218 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
0b3d16c0 8219 Generate_Reference (Entity (Name (Citem)), Citem);
82c80734
RD
8220
8221 -- With the pragma present, elaboration calls on
8222 -- subprograms from the named unit need no further
8223 -- checks, as long as the pragma appears in the current
8224 -- compilation unit. If the pragma appears in some unit
8225 -- in the context, there might still be a need for an
8226 -- Elaborate_All_Desirable from the current compilation
f3d57416 8227 -- to the named unit, so we keep the check enabled.
82c80734
RD
8228
8229 if In_Extended_Main_Source_Unit (N) then
8230 Set_Suppress_Elaboration_Warnings
8231 (Entity (Name (Citem)));
8232 end if;
ac9e9918 8233
996ae0b0
RK
8234 exit Inner;
8235 end if;
8236
8237 Next (Citem);
8238 end loop Inner;
8239
8240 if Citem = N then
8241 Error_Pragma_Arg
8242 ("argument of pragma% is not with'ed unit", Arg);
8243 end if;
8244
8245 Next (Arg);
8246 end loop Outer;
fbf5a39b
AC
8247
8248 -- Give a warning if operating in static mode with -gnatwl
f3d57416 8249 -- (elaboration warnings enabled) switch set.
fbf5a39b
AC
8250
8251 if Elab_Warnings and not Dynamic_Elaboration_Checks then
8252 Error_Msg_N
8253 ("?use of pragma Elaborate may not be safe", N);
ed2233dc 8254 Error_Msg_N
fbf5a39b
AC
8255 ("?use pragma Elaborate_All instead if possible", N);
8256 end if;
996ae0b0
RK
8257 end Elaborate;
8258
8259 -------------------
8260 -- Elaborate_All --
8261 -------------------
8262
8263 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8264
8265 when Pragma_Elaborate_All => Elaborate_All : declare
ac9e9918
RD
8266 Arg : Node_Id;
8267 Citem : Node_Id;
996ae0b0
RK
8268
8269 begin
8270 Check_Ada_83_Warning;
8271
8272 -- Pragma must be in context items list of a compilation unit
8273
ac9e9918 8274 if not Is_In_Context_Clause then
996ae0b0 8275 Pragma_Misplaced;
996ae0b0
RK
8276 end if;
8277
8278 -- Must be at least one argument
8279
8280 if Arg_Count = 0 then
8281 Error_Pragma ("pragma% requires at least one argument");
8282 end if;
8283
8284 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
8285 -- have to appear at the end of the context clause, but may
8286 -- appear mixed in with other items, even in Ada 83 mode.
8287
8288 -- Final check: the arguments must all be units mentioned in
8289 -- a with clause in the same context clause. Note that we
8290 -- already checked (in Par.Prag) that all the arguments are
8291 -- either identifiers or selected components.
8292
8293 Arg := Arg1;
8294 Outr : while Present (Arg) loop
ac9e9918 8295 Citem := First (List_Containing (N));
996ae0b0
RK
8296 Innr : while Citem /= N loop
8297 if Nkind (Citem) = N_With_Clause
0f1a6a0b 8298 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
996ae0b0
RK
8299 then
8300 Set_Elaborate_All_Present (Citem, True);
0f1a6a0b 8301 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
82c80734
RD
8302
8303 -- Suppress warnings and elaboration checks on the named
8304 -- unit if the pragma is in the current compilation, as
8305 -- for pragma Elaborate.
8306
8307 if In_Extended_Main_Source_Unit (N) then
8308 Set_Suppress_Elaboration_Warnings
8309 (Entity (Name (Citem)));
8310 end if;
996ae0b0
RK
8311 exit Innr;
8312 end if;
8313
8314 Next (Citem);
8315 end loop Innr;
8316
8317 if Citem = N then
fbf5a39b 8318 Set_Error_Posted (N);
996ae0b0
RK
8319 Error_Pragma_Arg
8320 ("argument of pragma% is not with'ed unit", Arg);
8321 end if;
8322
8323 Next (Arg);
8324 end loop Outr;
8325 end Elaborate_All;
8326
8327 --------------------
8328 -- Elaborate_Body --
8329 --------------------
8330
8331 -- pragma Elaborate_Body [( library_unit_NAME )];
8332
8333 when Pragma_Elaborate_Body => Elaborate_Body : declare
8334 Cunit_Node : Node_Id;
8335 Cunit_Ent : Entity_Id;
8336
8337 begin
8338 Check_Ada_83_Warning;
8339 Check_Valid_Library_Unit_Pragma;
8340
8341 if Nkind (N) = N_Null_Statement then
8342 return;
8343 end if;
8344
8345 Cunit_Node := Cunit (Current_Sem_Unit);
8346 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8347
d7ba4df4
RD
8348 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8349 N_Subprogram_Body)
996ae0b0
RK
8350 then
8351 Error_Pragma ("pragma% must refer to a spec, not a body");
8352 else
8353 Set_Body_Required (Cunit_Node, True);
f02b8bb8 8354 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
996ae0b0
RK
8355
8356 -- If we are in dynamic elaboration mode, then we suppress
8357 -- elaboration warnings for the unit, since it is definitely
8358 -- fine NOT to do dynamic checks at the first level (and such
8359 -- checks will be suppressed because no elaboration boolean
8360 -- is created for Elaborate_Body packages).
8361
8362 -- But in the static model of elaboration, Elaborate_Body is
8363 -- definitely NOT good enough to ensure elaboration safety on
8364 -- its own, since the body may WITH other units that are not
8365 -- safe from an elaboration point of view, so a client must
8366 -- still do an Elaborate_All on such units.
8367
b3b9865d
AC
8368 -- Debug flag -gnatdD restores the old behavior of 3.13, where
8369 -- Elaborate_Body always suppressed elab warnings.
996ae0b0
RK
8370
8371 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8372 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8373 end if;
8374 end if;
8375 end Elaborate_Body;
8376
8377 ------------------------
8378 -- Elaboration_Checks --
8379 ------------------------
8380
8381 -- pragma Elaboration_Checks (Static | Dynamic);
8382
8383 when Pragma_Elaboration_Checks =>
8384 GNAT_Pragma;
8385 Check_Arg_Count (1);
8386 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8387 Dynamic_Elaboration_Checks :=
8388 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8389
8390 ---------------
8391 -- Eliminate --
8392 ---------------
8393
8394 -- pragma Eliminate (
ef7c5692
AC
8395 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
8396 -- [,[Entity =>] IDENTIFIER |
8397 -- SELECTED_COMPONENT |
8398 -- STRING_LITERAL]
8399 -- [, OVERLOADING_RESOLUTION]);
7324bf49
AC
8400
8401 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8402 -- SOURCE_LOCATION
8403
8404 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8405 -- FUNCTION_PROFILE
8406
8407 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8408
8409 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8410 -- Result_Type => result_SUBTYPE_NAME]
996ae0b0 8411
07fc65c4
GB
8412 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8413 -- SUBTYPE_NAME ::= STRING_LITERAL
996ae0b0 8414
7324bf49
AC
8415 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8416 -- SOURCE_TRACE ::= STRING_LITERAL
8417
07fc65c4
GB
8418 when Pragma_Eliminate => Eliminate : declare
8419 Args : Args_List (1 .. 5);
fbf5a39b 8420 Names : constant Name_List (1 .. 5) := (
07fc65c4
GB
8421 Name_Unit_Name,
8422 Name_Entity,
8423 Name_Parameter_Types,
8424 Name_Result_Type,
7324bf49 8425 Name_Source_Location);
07fc65c4
GB
8426
8427 Unit_Name : Node_Id renames Args (1);
8428 Entity : Node_Id renames Args (2);
8429 Parameter_Types : Node_Id renames Args (3);
8430 Result_Type : Node_Id renames Args (4);
7324bf49 8431 Source_Location : Node_Id renames Args (5);
07fc65c4
GB
8432
8433 begin
996ae0b0 8434 GNAT_Pragma;
996ae0b0 8435 Check_Valid_Configuration_Pragma;
07fc65c4 8436 Gather_Associations (Names, Args);
996ae0b0 8437
07fc65c4
GB
8438 if No (Unit_Name) then
8439 Error_Pragma ("missing Unit_Name argument for pragma%");
8440 end if;
996ae0b0 8441
07fc65c4
GB
8442 if No (Entity)
8443 and then (Present (Parameter_Types)
8444 or else
8445 Present (Result_Type)
8446 or else
7324bf49 8447 Present (Source_Location))
07fc65c4
GB
8448 then
8449 Error_Pragma ("missing Entity argument for pragma%");
996ae0b0
RK
8450 end if;
8451
7324bf49 8452 if (Present (Parameter_Types)
e8374e7a 8453 or else
7324bf49
AC
8454 Present (Result_Type))
8455 and then
8456 Present (Source_Location)
8457 then
8458 Error_Pragma
f02b8bb8 8459 ("parameter profile and source location cannot " &
7324bf49
AC
8460 "be used together in pragma%");
8461 end if;
8462
07fc65c4 8463 Process_Eliminate_Pragma
91b1417d
AC
8464 (N,
8465 Unit_Name,
07fc65c4
GB
8466 Entity,
8467 Parameter_Types,
8468 Result_Type,
7324bf49 8469 Source_Location);
996ae0b0
RK
8470 end Eliminate;
8471
12b4d338
AC
8472 -----------------------------------
8473 -- Enable_Atomic_Synchronization --
8474 -----------------------------------
8475
8476 -- pragma Enable_Atomic_Synchronization [(Entity)];
8477
8478 when Pragma_Enable_Atomic_Synchronization =>
8479 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
8480
996ae0b0
RK
8481 ------------
8482 -- Export --
8483 ------------
8484
8485 -- pragma Export (
8486 -- [ Convention =>] convention_IDENTIFIER,
8487 -- [ Entity =>] local_NAME
8488 -- [, [External_Name =>] static_string_EXPRESSION ]
8489 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8490
8491 when Pragma_Export => Export : declare
8492 C : Convention_Id;
8493 Def_Id : Entity_Id;
8494
67ce0d7e
RD
8495 pragma Warnings (Off, C);
8496
996ae0b0
RK
8497 begin
8498 Check_Ada_83_Warning;
59e5fbe0
RD
8499 Check_Arg_Order
8500 ((Name_Convention,
8501 Name_Entity,
8502 Name_External_Name,
8503 Name_Link_Name));
996ae0b0
RK
8504 Check_At_Least_N_Arguments (2);
8505 Check_At_Most_N_Arguments (4);
8506 Process_Convention (C, Def_Id);
662e57b4
ES
8507
8508 if Ekind (Def_Id) /= E_Constant then
0f1a6a0b
AC
8509 Note_Possible_Modification
8510 (Get_Pragma_Arg (Arg2), Sure => False);
662e57b4
ES
8511 end if;
8512
996ae0b0
RK
8513 Process_Interface_Name (Def_Id, Arg3, Arg4);
8514 Set_Exported (Def_Id, Arg2);
21d27997 8515
b3b9865d
AC
8516 -- If the entity is a deferred constant, propagate the information
8517 -- to the full view, because gigi elaborates the full view only.
21d27997
RD
8518
8519 if Ekind (Def_Id) = E_Constant
8520 and then Present (Full_View (Def_Id))
8521 then
8522 declare
8523 Id2 : constant Entity_Id := Full_View (Def_Id);
8524 begin
8525 Set_Is_Exported (Id2, Is_Exported (Def_Id));
8526 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
8527 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8528 end;
8529 end if;
996ae0b0
RK
8530 end Export;
8531
8532 ----------------------
8533 -- Export_Exception --
8534 ----------------------
8535
8536 -- pragma Export_Exception (
470cd9e9
RD
8537 -- [Internal =>] LOCAL_NAME
8538 -- [, [External =>] EXTERNAL_SYMBOL]
996ae0b0
RK
8539 -- [, [Form =>] Ada | VMS]
8540 -- [, [Code =>] static_integer_EXPRESSION]);
8541
8542 when Pragma_Export_Exception => Export_Exception : declare
8543 Args : Args_List (1 .. 4);
fbf5a39b 8544 Names : constant Name_List (1 .. 4) := (
996ae0b0
RK
8545 Name_Internal,
8546 Name_External,
8547 Name_Form,
8548 Name_Code);
8549
8550 Internal : Node_Id renames Args (1);
8551 External : Node_Id renames Args (2);
8552 Form : Node_Id renames Args (3);
8553 Code : Node_Id renames Args (4);
8554
8555 begin
a30a01fe
RD
8556 GNAT_Pragma;
8557
996ae0b0
RK
8558 if Inside_A_Generic then
8559 Error_Pragma ("pragma% cannot be used for generic entities");
8560 end if;
8561
8562 Gather_Associations (Names, Args);
8563 Process_Extended_Import_Export_Exception_Pragma (
8564 Arg_Internal => Internal,
8565 Arg_External => External,
8566 Arg_Form => Form,
8567 Arg_Code => Code);
8568
8569 if not Is_VMS_Exception (Entity (Internal)) then
8570 Set_Exported (Entity (Internal), Internal);
8571 end if;
996ae0b0
RK
8572 end Export_Exception;
8573
8574 ---------------------
8575 -- Export_Function --
8576 ---------------------
8577
8578 -- pragma Export_Function (
470cd9e9
RD
8579 -- [Internal =>] LOCAL_NAME
8580 -- [, [External =>] EXTERNAL_SYMBOL]
996ae0b0 8581 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
fbf5a39b 8582 -- [, [Result_Type =>] TYPE_DESIGNATOR]
996ae0b0
RK
8583 -- [, [Mechanism =>] MECHANISM]
8584 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8585
fbf5a39b
AC
8586 -- EXTERNAL_SYMBOL ::=
8587 -- IDENTIFIER
8588 -- | static_string_EXPRESSION
8589
8590 -- PARAMETER_TYPES ::=
8591 -- null
8592 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8593
8594 -- TYPE_DESIGNATOR ::=
8595 -- subtype_NAME
8596 -- | subtype_Name ' Access
8597
8598 -- MECHANISM ::=
8599 -- MECHANISM_NAME
8600 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8601
8602 -- MECHANISM_ASSOCIATION ::=
8603 -- [formal_parameter_NAME =>] MECHANISM_NAME
8604
8605 -- MECHANISM_NAME ::=
8606 -- Value
8607 -- | Reference
8608 -- | Descriptor [([Class =>] CLASS_NAME)]
8609
8610 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8611
996ae0b0
RK
8612 when Pragma_Export_Function => Export_Function : declare
8613 Args : Args_List (1 .. 6);
fbf5a39b 8614 Names : constant Name_List (1 .. 6) := (
996ae0b0
RK
8615 Name_Internal,
8616 Name_External,
8617 Name_Parameter_Types,
8618 Name_Result_Type,
8619 Name_Mechanism,
8620 Name_Result_Mechanism);
8621
8622 Internal : Node_Id renames Args (1);
8623 External : Node_Id renames Args (2);
8624 Parameter_Types : Node_Id renames Args (3);
8625 Result_Type : Node_Id renames Args (4);
8626 Mechanism : Node_Id renames Args (5);
8627 Result_Mechanism : Node_Id renames Args (6);
8628
8629 begin
8630 GNAT_Pragma;
8631 Gather_Associations (Names, Args);
8632 Process_Extended_Import_Export_Subprogram_Pragma (
8633 Arg_Internal => Internal,
8634 Arg_External => External,
8635 Arg_Parameter_Types => Parameter_Types,
8636 Arg_Result_Type => Result_Type,
8637 Arg_Mechanism => Mechanism,
8638 Arg_Result_Mechanism => Result_Mechanism);
8639 end Export_Function;
8640
8641 -------------------
8642 -- Export_Object --
8643 -------------------
8644
8645 -- pragma Export_Object (
470cd9e9 8646 -- [Internal =>] LOCAL_NAME
996ae0b0
RK
8647 -- [, [External =>] EXTERNAL_SYMBOL]
8648 -- [, [Size =>] EXTERNAL_SYMBOL]);
8649
fbf5a39b
AC
8650 -- EXTERNAL_SYMBOL ::=
8651 -- IDENTIFIER
8652 -- | static_string_EXPRESSION
8653
8654 -- PARAMETER_TYPES ::=
8655 -- null
8656 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8657
8658 -- TYPE_DESIGNATOR ::=
8659 -- subtype_NAME
8660 -- | subtype_Name ' Access
8661
8662 -- MECHANISM ::=
8663 -- MECHANISM_NAME
8664 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8665
8666 -- MECHANISM_ASSOCIATION ::=
8667 -- [formal_parameter_NAME =>] MECHANISM_NAME
8668
8669 -- MECHANISM_NAME ::=
8670 -- Value
8671 -- | Reference
8672 -- | Descriptor [([Class =>] CLASS_NAME)]
8673
8674 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8675
8676 when Pragma_Export_Object => Export_Object : declare
996ae0b0 8677 Args : Args_List (1 .. 3);
fbf5a39b 8678 Names : constant Name_List (1 .. 3) := (
996ae0b0
RK
8679 Name_Internal,
8680 Name_External,
8681 Name_Size);
8682
8683 Internal : Node_Id renames Args (1);
8684 External : Node_Id renames Args (2);
8685 Size : Node_Id renames Args (3);
8686
8687 begin
8688 GNAT_Pragma;
8689 Gather_Associations (Names, Args);
8690 Process_Extended_Import_Export_Object_Pragma (
8691 Arg_Internal => Internal,
8692 Arg_External => External,
8693 Arg_Size => Size);
8694 end Export_Object;
8695
8696 ----------------------
8697 -- Export_Procedure --
8698 ----------------------
8699
8700 -- pragma Export_Procedure (
470cd9e9
RD
8701 -- [Internal =>] LOCAL_NAME
8702 -- [, [External =>] EXTERNAL_SYMBOL]
996ae0b0
RK
8703 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8704 -- [, [Mechanism =>] MECHANISM]);
8705
fbf5a39b
AC
8706 -- EXTERNAL_SYMBOL ::=
8707 -- IDENTIFIER
8708 -- | static_string_EXPRESSION
8709
8710 -- PARAMETER_TYPES ::=
8711 -- null
8712 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8713
8714 -- TYPE_DESIGNATOR ::=
8715 -- subtype_NAME
8716 -- | subtype_Name ' Access
8717
8718 -- MECHANISM ::=
8719 -- MECHANISM_NAME
8720 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8721
8722 -- MECHANISM_ASSOCIATION ::=
8723 -- [formal_parameter_NAME =>] MECHANISM_NAME
8724
8725 -- MECHANISM_NAME ::=
8726 -- Value
8727 -- | Reference
8728 -- | Descriptor [([Class =>] CLASS_NAME)]
8729
8730 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8731
996ae0b0
RK
8732 when Pragma_Export_Procedure => Export_Procedure : declare
8733 Args : Args_List (1 .. 4);
fbf5a39b 8734 Names : constant Name_List (1 .. 4) := (
996ae0b0
RK
8735 Name_Internal,
8736 Name_External,
8737 Name_Parameter_Types,
8738 Name_Mechanism);
8739
8740 Internal : Node_Id renames Args (1);
8741 External : Node_Id renames Args (2);
8742 Parameter_Types : Node_Id renames Args (3);
8743 Mechanism : Node_Id renames Args (4);
8744
8745 begin
8746 GNAT_Pragma;
8747 Gather_Associations (Names, Args);
8748 Process_Extended_Import_Export_Subprogram_Pragma (
8749 Arg_Internal => Internal,
8750 Arg_External => External,
8751 Arg_Parameter_Types => Parameter_Types,
8752 Arg_Mechanism => Mechanism);
8753 end Export_Procedure;
8754
fbf5a39b
AC
8755 ------------------
8756 -- Export_Value --
8757 ------------------
8758
8759 -- pragma Export_Value (
8760 -- [Value =>] static_integer_EXPRESSION,
8761 -- [Link_Name =>] static_string_EXPRESSION);
8762
8763 when Pragma_Export_Value =>
8764 GNAT_Pragma;
59e5fbe0 8765 Check_Arg_Order ((Name_Value, Name_Link_Name));
fbf5a39b
AC
8766 Check_Arg_Count (2);
8767
8768 Check_Optional_Identifier (Arg1, Name_Value);
8769 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8770
8771 Check_Optional_Identifier (Arg2, Name_Link_Name);
8772 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8773
996ae0b0
RK
8774 -----------------------------
8775 -- Export_Valued_Procedure --
8776 -----------------------------
8777
8778 -- pragma Export_Valued_Procedure (
470cd9e9 8779 -- [Internal =>] LOCAL_NAME
996ae0b0
RK
8780 -- [, [External =>] EXTERNAL_SYMBOL,]
8781 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8782 -- [, [Mechanism =>] MECHANISM]);
8783
fbf5a39b
AC
8784 -- EXTERNAL_SYMBOL ::=
8785 -- IDENTIFIER
8786 -- | static_string_EXPRESSION
8787
8788 -- PARAMETER_TYPES ::=
8789 -- null
8790 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8791
8792 -- TYPE_DESIGNATOR ::=
8793 -- subtype_NAME
8794 -- | subtype_Name ' Access
8795
8796 -- MECHANISM ::=
8797 -- MECHANISM_NAME
8798 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8799
8800 -- MECHANISM_ASSOCIATION ::=
8801 -- [formal_parameter_NAME =>] MECHANISM_NAME
8802
8803 -- MECHANISM_NAME ::=
8804 -- Value
8805 -- | Reference
8806 -- | Descriptor [([Class =>] CLASS_NAME)]
8807
8808 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8809
996ae0b0
RK
8810 when Pragma_Export_Valued_Procedure =>
8811 Export_Valued_Procedure : declare
8812 Args : Args_List (1 .. 4);
fbf5a39b 8813 Names : constant Name_List (1 .. 4) := (
996ae0b0
RK
8814 Name_Internal,
8815 Name_External,
8816 Name_Parameter_Types,
8817 Name_Mechanism);
8818
8819 Internal : Node_Id renames Args (1);
8820 External : Node_Id renames Args (2);
8821 Parameter_Types : Node_Id renames Args (3);
8822 Mechanism : Node_Id renames Args (4);
8823
8824 begin
8825 GNAT_Pragma;
8826 Gather_Associations (Names, Args);
8827 Process_Extended_Import_Export_Subprogram_Pragma (
8828 Arg_Internal => Internal,
8829 Arg_External => External,
8830 Arg_Parameter_Types => Parameter_Types,
8831 Arg_Mechanism => Mechanism);
8832 end Export_Valued_Procedure;
8833
8834 -------------------
8835 -- Extend_System --
8836 -------------------
8837
8838 -- pragma Extend_System ([Name =>] Identifier);
8839
8840 when Pragma_Extend_System => Extend_System : declare
8841 begin
8842 GNAT_Pragma;
8843 Check_Valid_Configuration_Pragma;
8844 Check_Arg_Count (1);
8845 Check_Optional_Identifier (Arg1, Name_Name);
8846 Check_Arg_Is_Identifier (Arg1);
8847
0f1a6a0b 8848 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
996ae0b0
RK
8849
8850 if Name_Len > 4
8851 and then Name_Buffer (1 .. 4) = "aux_"
8852 then
8853 if Present (System_Extend_Pragma_Arg) then
0f1a6a0b 8854 if Chars (Get_Pragma_Arg (Arg1)) =
996ae0b0
RK
8855 Chars (Expression (System_Extend_Pragma_Arg))
8856 then
8857 null;
8858 else
8859 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
c690a2ec 8860 Error_Pragma ("pragma% conflicts with that #");
996ae0b0
RK
8861 end if;
8862
8863 else
8864 System_Extend_Pragma_Arg := Arg1;
fbf5a39b
AC
8865
8866 if not GNAT_Mode then
8867 System_Extend_Unit := Arg1;
8868 end if;
996ae0b0
RK
8869 end if;
8870 else
8871 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8872 end if;
8873 end Extend_System;
8874
8875 ------------------------
8876 -- Extensions_Allowed --
8877 ------------------------
8878
8879 -- pragma Extensions_Allowed (ON | OFF);
8880
8881 when Pragma_Extensions_Allowed =>
8882 GNAT_Pragma;
8883 Check_Arg_Count (1);
8884 Check_No_Identifiers;
8885 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
0ab80019 8886
0f1a6a0b 8887 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
0ab80019 8888 Extensions_Allowed := True;
0eed45bb
AC
8889 Ada_Version := Ada_Version_Type'Last;
8890
0ab80019
AC
8891 else
8892 Extensions_Allowed := False;
0eed45bb 8893 Ada_Version := Ada_Version_Explicit;
0ab80019 8894 end if;
996ae0b0 8895
72e4357f
RD
8896 --------------
8897 -- External --
8898 --------------
8899
8900 -- pragma External (
8901 -- [ Convention =>] convention_IDENTIFIER,
8902 -- [ Entity =>] local_NAME
8903 -- [, [External_Name =>] static_string_EXPRESSION ]
8904 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8905
8906 when Pragma_External => External : declare
67ce0d7e
RD
8907 Def_Id : Entity_Id;
8908
8909 C : Convention_Id;
8910 pragma Warnings (Off, C);
8911
72e4357f
RD
8912 begin
8913 GNAT_Pragma;
59e5fbe0
RD
8914 Check_Arg_Order
8915 ((Name_Convention,
8916 Name_Entity,
8917 Name_External_Name,
8918 Name_Link_Name));
72e4357f
RD
8919 Check_At_Least_N_Arguments (2);
8920 Check_At_Most_N_Arguments (4);
8921 Process_Convention (C, Def_Id);
0f1a6a0b
AC
8922 Note_Possible_Modification
8923 (Get_Pragma_Arg (Arg2), Sure => False);
72e4357f
RD
8924 Process_Interface_Name (Def_Id, Arg3, Arg4);
8925 Set_Exported (Def_Id, Arg2);
8926 end External;
8927
996ae0b0
RK
8928 --------------------------
8929 -- External_Name_Casing --
8930 --------------------------
8931
8932 -- pragma External_Name_Casing (
8933 -- UPPERCASE | LOWERCASE
8934 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8935
2c9beb8a 8936 when Pragma_External_Name_Casing => External_Name_Casing : declare
996ae0b0
RK
8937 begin
8938 GNAT_Pragma;
8939 Check_No_Identifiers;
8940
8941 if Arg_Count = 2 then
8942 Check_Arg_Is_One_Of
8943 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8944
8945 case Chars (Get_Pragma_Arg (Arg2)) is
8946 when Name_As_Is =>
8947 Opt.External_Name_Exp_Casing := As_Is;
8948
8949 when Name_Uppercase =>
8950 Opt.External_Name_Exp_Casing := Uppercase;
8951
8952 when Name_Lowercase =>
8953 Opt.External_Name_Exp_Casing := Lowercase;
8954
8955 when others =>
8956 null;
8957 end case;
8958
8959 else
8960 Check_Arg_Count (1);
8961 end if;
8962
8963 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8964
8965 case Chars (Get_Pragma_Arg (Arg1)) is
8966 when Name_Uppercase =>
8967 Opt.External_Name_Imp_Casing := Uppercase;
8968
8969 when Name_Lowercase =>
8970 Opt.External_Name_Imp_Casing := Lowercase;
8971
8972 when others =>
8973 null;
8974 end case;
996ae0b0
RK
8975 end External_Name_Casing;
8976
470cd9e9
RD
8977 --------------------------
8978 -- Favor_Top_Level --
8979 --------------------------
8980
8981 -- pragma Favor_Top_Level (type_NAME);
8982
8983 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8984 Named_Entity : Entity_Id;
8985
8986 begin
8987 GNAT_Pragma;
8988 Check_No_Identifiers;
8989 Check_Arg_Count (1);
8990 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 8991 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
470cd9e9
RD
8992
8993 -- If it's an access-to-subprogram type (in particular, not a
8994 -- subtype), set the flag on that type.
8995
1b24ada5 8996 if Is_Access_Subprogram_Type (Named_Entity) then
eaba57fb 8997 Set_Can_Use_Internal_Rep (Named_Entity, False);
470cd9e9
RD
8998
8999 -- Otherwise it's an error (name denotes the wrong sort of entity)
9000
9001 else
9002 Error_Pragma_Arg
0f1a6a0b
AC
9003 ("access-to-subprogram type expected",
9004 Get_Pragma_Arg (Arg1));
470cd9e9
RD
9005 end if;
9006 end Favor_Top_Level;
9007
9008 ---------------
9009 -- Fast_Math --
9010 ---------------
9011
9012 -- pragma Fast_Math;
9013
9014 when Pragma_Fast_Math =>
9015 GNAT_Pragma;
9016 Check_No_Identifiers;
9017 Check_Valid_Configuration_Pragma;
9018 Fast_Math := True;
9019
996ae0b0
RK
9020 ---------------------------
9021 -- Finalize_Storage_Only --
9022 ---------------------------
9023
9024 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9025
9026 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
fbf5a39b 9027 Assoc : constant Node_Id := Arg1;
0f1a6a0b 9028 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
996ae0b0
RK
9029 Typ : Entity_Id;
9030
9031 begin
a30a01fe 9032 GNAT_Pragma;
996ae0b0
RK
9033 Check_No_Identifiers;
9034 Check_Arg_Count (1);
9035 Check_Arg_Is_Local_Name (Arg1);
9036
9037 Find_Type (Type_Id);
9038 Typ := Entity (Type_Id);
9039
9040 if Typ = Any_Type
9041 or else Rep_Item_Too_Early (Typ, N)
9042 then
9043 return;
9044 else
9045 Typ := Underlying_Type (Typ);
9046 end if;
9047
9048 if not Is_Controlled (Typ) then
9049 Error_Pragma ("pragma% must specify controlled type");
9050 end if;
9051
9052 Check_First_Subtype (Arg1);
9053
9054 if Finalize_Storage_Only (Typ) then
9055 Error_Pragma ("duplicate pragma%, only one allowed");
9056
9057 elsif not Rep_Item_Too_Late (Typ, N) then
07fc65c4 9058 Set_Finalize_Storage_Only (Base_Type (Typ), True);
996ae0b0
RK
9059 end if;
9060 end Finalize_Storage;
9061
9062 --------------------------
9063 -- Float_Representation --
9064 --------------------------
9065
6e18b0e5
RD
9066 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9067
9068 -- FLOAT_REP ::= VAX_Float | IEEE_Float
996ae0b0
RK
9069
9070 when Pragma_Float_Representation => Float_Representation : declare
9071 Argx : Node_Id;
9072 Digs : Nat;
9073 Ent : Entity_Id;
9074
9075 begin
9076 GNAT_Pragma;
9077
9078 if Arg_Count = 1 then
9079 Check_Valid_Configuration_Pragma;
9080 else
9081 Check_Arg_Count (2);
9082 Check_Optional_Identifier (Arg2, Name_Entity);
9083 Check_Arg_Is_Local_Name (Arg2);
9084 end if;
9085
9086 Check_No_Identifier (Arg1);
9087 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9088
9089 if not OpenVMS_On_Target then
0f1a6a0b 9090 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
996ae0b0
RK
9091 Error_Pragma
9092 ("?pragma% ignored (applies only to Open'V'M'S)");
9093 end if;
9094
9095 return;
9096 end if;
9097
9098 -- One argument case
9099
9100 if Arg_Count = 1 then
0f1a6a0b 9101 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
996ae0b0
RK
9102 if Opt.Float_Format = 'I' then
9103 Error_Pragma ("'I'E'E'E format previously specified");
9104 end if;
9105
9106 Opt.Float_Format := 'V';
9107
9108 else
9109 if Opt.Float_Format = 'V' then
9110 Error_Pragma ("'V'A'X format previously specified");
9111 end if;
9112
9113 Opt.Float_Format := 'I';
9114 end if;
9115
9116 Set_Standard_Fpt_Formats;
9117
9118 -- Two argument case
9119
9120 else
9121 Argx := Get_Pragma_Arg (Arg2);
9122
9123 if not Is_Entity_Name (Argx)
9124 or else not Is_Floating_Point_Type (Entity (Argx))
9125 then
9126 Error_Pragma_Arg
9127 ("second argument of% pragma must be floating-point type",
9128 Arg2);
9129 end if;
9130
9131 Ent := Entity (Argx);
9132 Digs := UI_To_Int (Digits_Value (Ent));
9133
9134 -- Two arguments, VAX_Float case
9135
0f1a6a0b 9136 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
996ae0b0
RK
9137 case Digs is
9138 when 6 => Set_F_Float (Ent);
9139 when 9 => Set_D_Float (Ent);
9140 when 15 => Set_G_Float (Ent);
9141
9142 when others =>
9143 Error_Pragma_Arg
9144 ("wrong digits value, must be 6,9 or 15", Arg2);
9145 end case;
9146
9147 -- Two arguments, IEEE_Float case
9148
9149 else
9150 case Digs is
9151 when 6 => Set_IEEE_Short (Ent);
9152 when 15 => Set_IEEE_Long (Ent);
9153
9154 when others =>
9155 Error_Pragma_Arg
9156 ("wrong digits value, must be 6 or 15", Arg2);
9157 end case;
9158 end if;
9159 end if;
996ae0b0
RK
9160 end Float_Representation;
9161
9162 -----------
9163 -- Ident --
9164 -----------
9165
9166 -- pragma Ident (static_string_EXPRESSION)
9167
b3b9865d
AC
9168 -- Note: pragma Comment shares this processing. Pragma Comment is
9169 -- identical to Ident, except that the restriction of the argument to
9170 -- 31 characters and the placement restrictions are not enforced for
9171 -- pragma Comment.
996ae0b0
RK
9172
9173 when Pragma_Ident | Pragma_Comment => Ident : declare
9174 Str : Node_Id;
9175
9176 begin
9177 GNAT_Pragma;
9178 Check_Arg_Count (1);
9179 Check_No_Identifiers;
9180 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7eaa7cdf 9181 Store_Note (N);
996ae0b0 9182
b3b9865d
AC
9183 -- For pragma Ident, preserve DEC compatibility by requiring the
9184 -- pragma to appear in a declarative part or package spec.
996ae0b0
RK
9185
9186 if Prag_Id = Pragma_Ident then
9187 Check_Is_In_Decl_Part_Or_Package_Spec;
9188 end if;
9189
0f1a6a0b 9190 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
996ae0b0 9191
996ae0b0
RK
9192 declare
9193 CS : Node_Id;
9194 GP : Node_Id;
9195
9196 begin
9197 GP := Parent (Parent (N));
9198
d7ba4df4
RD
9199 if Nkind_In (GP, N_Package_Declaration,
9200 N_Generic_Package_Declaration)
996ae0b0
RK
9201 then
9202 GP := Parent (GP);
9203 end if;
9204
b3b9865d
AC
9205 -- If we have a compilation unit, then record the ident value,
9206 -- checking for improper duplication.
996ae0b0
RK
9207
9208 if Nkind (GP) = N_Compilation_Unit then
9209 CS := Ident_String (Current_Sem_Unit);
9210
9211 if Present (CS) then
9212
9213 -- For Ident, we do not permit multiple instances
9214
9215 if Prag_Id = Pragma_Ident then
9216 Error_Pragma ("duplicate% pragma not permitted");
9217
b3b9865d
AC
9218 -- For Comment, we concatenate the string, unless we want
9219 -- to preserve the tree structure for ASIS.
996ae0b0 9220
fbf5a39b 9221 elsif not ASIS_Mode then
996ae0b0
RK
9222 Start_String (Strval (CS));
9223 Store_String_Char (' ');
9224 Store_String_Chars (Strval (Str));
9225 Set_Strval (CS, End_String);
9226 end if;
9227
9228 else
9229 -- In VMS, the effect of IDENT is achieved by passing
7425962b 9230 -- --identification=name as a --for-linker switch.
996ae0b0
RK
9231
9232 if OpenVMS_On_Target then
9233 Start_String;
9234 Store_String_Chars
7425962b 9235 ("--for-linker=--identification=");
996ae0b0
RK
9236 String_To_Name_Buffer (Strval (Str));
9237 Store_String_Chars (Name_Buffer (1 .. Name_Len));
9238
9239 -- Only the last processed IDENT is saved. The main
9240 -- purpose is so an IDENT associated with a main
9241 -- procedure will be used in preference to an IDENT
9242 -- associated with a with'd package.
9243
9244 Replace_Linker_Option_String
7425962b 9245 (End_String, "--for-linker=--identification=");
996ae0b0
RK
9246 end if;
9247
9248 Set_Ident_String (Current_Sem_Unit, Str);
9249 end if;
9250
b3b9865d
AC
9251 -- For subunits, we just ignore the Ident, since in GNAT these
9252 -- are not separate object files, and hence not separate units
9253 -- in the unit table.
996ae0b0
RK
9254
9255 elsif Nkind (GP) = N_Subunit then
9256 null;
9257
9258 -- Otherwise we have a misplaced pragma Ident, but we ignore
9259 -- this if we are in an instantiation, since it comes from
9260 -- a generic, and has no relevance to the instantiation.
9261
9262 elsif Prag_Id = Pragma_Ident then
9263 if Instantiation_Location (Loc) = No_Location then
9264 Error_Pragma ("pragma% only allowed at outer level");
9265 end if;
9266 end if;
9267 end;
9268 end Ident;
9269
df177175
RD
9270 ----------------------------
9271 -- Implementation_Defined --
9272 ----------------------------
9273
9274 -- pragma Implementation_Defined (local_NAME);
9275
9276 -- Marks previously declared entity as implementation defined. For
9277 -- an overloaded entity, applies to the most recent homonym.
9278
9279 -- pragma Implementation_Defined;
9280
9281 -- The form with no arguments appears anywhere within a scope, most
9282 -- typically a package spec, and indicates that all entities that are
9283 -- defined within the package spec are Implementation_Defined.
9284
9285 when Pragma_Implementation_Defined => Implementation_Defined : declare
9286 Ent : Entity_Id;
9287
9288 begin
9289 Check_No_Identifiers;
9290
9291 -- Form with no arguments
9292
9293 if Arg_Count = 0 then
9294 Set_Is_Implementation_Defined (Current_Scope);
9295
9296 -- Form with one argument
9297
9298 else
9299 Check_Arg_Count (1);
9300 Check_Arg_Is_Local_Name (Arg1);
9301 Ent := Entity (Get_Pragma_Arg (Arg1));
9302 Set_Is_Implementation_Defined (Ent);
9303 end if;
9304 end Implementation_Defined;
9305
bfae1846
AC
9306 -----------------
9307 -- Implemented --
9308 -----------------
470cd9e9 9309
bfae1846
AC
9310 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9311 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
470cd9e9 9312
bfae1846
AC
9313 when Pragma_Implemented => Implemented : declare
9314 Proc_Id : Entity_Id;
9315 Typ : Entity_Id;
470cd9e9
RD
9316
9317 begin
bfae1846
AC
9318 Ada_2012_Pragma;
9319 Check_Arg_Count (2);
470cd9e9
RD
9320 Check_No_Identifiers;
9321 Check_Arg_Is_Identifier (Arg1);
9322 Check_Arg_Is_Local_Name (Arg1);
bfae1846
AC
9323 Check_Arg_Is_One_Of
9324 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
9325
9326 -- Extract the name of the local procedure
470cd9e9 9327
0f1a6a0b 9328 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
470cd9e9 9329
bfae1846
AC
9330 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9331 -- primitive procedure of a synchronized tagged type.
9332
9333 if Ekind (Proc_Id) = E_Procedure
9334 and then Is_Primitive (Proc_Id)
9335 and then Present (First_Formal (Proc_Id))
470cd9e9 9336 then
bfae1846 9337 Typ := Etype (First_Formal (Proc_Id));
470cd9e9 9338
bfae1846
AC
9339 if Is_Tagged_Type (Typ)
9340 and then
9341
9342 -- Check for a protected, a synchronized or a task interface
9343
9344 ((Is_Interface (Typ)
9345 and then Is_Synchronized_Interface (Typ))
9346
9347 -- Check for a protected type or a task type that implements
9348 -- an interface.
9349
9350 or else
9351 (Is_Concurrent_Record_Type (Typ)
9352 and then Present (Interfaces (Typ)))
9353
9354 -- Check for a private record extension with keyword
9355 -- "synchronized".
9356
9357 or else
9358 (Ekind_In (Typ, E_Record_Type_With_Private,
9359 E_Record_Subtype_With_Private)
9360 and then Synchronized_Present (Parent (Typ))))
470cd9e9 9361 then
bfae1846 9362 null;
470cd9e9 9363 else
bfae1846
AC
9364 Error_Pragma_Arg
9365 ("controlling formal must be of synchronized " &
9366 "tagged type", Arg1);
9367 return;
470cd9e9 9368 end if;
bfae1846
AC
9369
9370 -- Procedures declared inside a protected type must be accepted
9371
9372 elsif Ekind (Proc_Id) = E_Procedure
9373 and then Is_Protected_Type (Scope (Proc_Id))
9374 then
9375 null;
9376
9377 -- The first argument is not a primitive procedure
9378
9379 else
9380 Error_Pragma_Arg
9381 ("pragma % must be applied to a primitive procedure", Arg1);
9382 return;
470cd9e9 9383 end if;
bfae1846 9384
2604ec03
AC
9385 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9386 -- By_Protected_Procedure to the primitive procedure of a task
9387 -- interface.
bfae1846
AC
9388
9389 if Chars (Arg2) = Name_By_Protected_Procedure
9390 and then Is_Interface (Typ)
9391 and then Is_Task_Interface (Typ)
9392 then
9393 Error_Pragma_Arg
9394 ("implementation kind By_Protected_Procedure cannot be " &
9395 "applied to a task interface primitive", Arg2);
9396 return;
9397 end if;
9398
9399 Record_Rep_Item (Proc_Id, N);
9400 end Implemented;
470cd9e9 9401
094cefda 9402 ----------------------
c690a2ec 9403 -- Implicit_Packing --
094cefda 9404 ----------------------
c690a2ec
RD
9405
9406 -- pragma Implicit_Packing;
9407
9408 when Pragma_Implicit_Packing =>
9409 GNAT_Pragma;
9410 Check_Arg_Count (0);
9411 Implicit_Packing := True;
9412
996ae0b0
RK
9413 ------------
9414 -- Import --
9415 ------------
9416
9417 -- pragma Import (
470cd9e9
RD
9418 -- [Convention =>] convention_IDENTIFIER,
9419 -- [Entity =>] local_NAME
996ae0b0
RK
9420 -- [, [External_Name =>] static_string_EXPRESSION ]
9421 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9422
9423 when Pragma_Import =>
9424 Check_Ada_83_Warning;
59e5fbe0
RD
9425 Check_Arg_Order
9426 ((Name_Convention,
9427 Name_Entity,
9428 Name_External_Name,
9429 Name_Link_Name));
996ae0b0
RK
9430 Check_At_Least_N_Arguments (2);
9431 Check_At_Most_N_Arguments (4);
9432 Process_Import_Or_Interface;
9433
9434 ----------------------
9435 -- Import_Exception --
9436 ----------------------
9437
9438 -- pragma Import_Exception (
470cd9e9
RD
9439 -- [Internal =>] LOCAL_NAME
9440 -- [, [External =>] EXTERNAL_SYMBOL]
996ae0b0
RK
9441 -- [, [Form =>] Ada | VMS]
9442 -- [, [Code =>] static_integer_EXPRESSION]);
9443
9444 when Pragma_Import_Exception => Import_Exception : declare
9445 Args : Args_List (1 .. 4);
fbf5a39b 9446 Names : constant Name_List (1 .. 4) := (
996ae0b0
RK
9447 Name_Internal,
9448 Name_External,
9449 Name_Form,
9450 Name_Code);
9451
9452 Internal : Node_Id renames Args (1);
9453 External : Node_Id renames Args (2);
9454 Form : Node_Id renames Args (3);
9455 Code : Node_Id renames Args (4);
9456
9457 begin
a30a01fe 9458 GNAT_Pragma;
996ae0b0
RK
9459 Gather_Associations (Names, Args);
9460
9461 if Present (External) and then Present (Code) then
9462 Error_Pragma
9463 ("cannot give both External and Code options for pragma%");
9464 end if;
9465
9466 Process_Extended_Import_Export_Exception_Pragma (
9467 Arg_Internal => Internal,
9468 Arg_External => External,
9469 Arg_Form => Form,
9470 Arg_Code => Code);
9471
9472 if not Is_VMS_Exception (Entity (Internal)) then
9473 Set_Imported (Entity (Internal));
9474 end if;
996ae0b0
RK
9475 end Import_Exception;
9476
9477 ---------------------
9478 -- Import_Function --
9479 ---------------------
9480
9481 -- pragma Import_Function (
9482 -- [Internal =>] LOCAL_NAME,
9483 -- [, [External =>] EXTERNAL_SYMBOL]
9484 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9485 -- [, [Result_Type =>] SUBTYPE_MARK]
9486 -- [, [Mechanism =>] MECHANISM]
9487 -- [, [Result_Mechanism =>] MECHANISM_NAME]
9488 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9489
fbf5a39b
AC
9490 -- EXTERNAL_SYMBOL ::=
9491 -- IDENTIFIER
9492 -- | static_string_EXPRESSION
9493
9494 -- PARAMETER_TYPES ::=
9495 -- null
9496 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9497
9498 -- TYPE_DESIGNATOR ::=
9499 -- subtype_NAME
9500 -- | subtype_Name ' Access
9501
9502 -- MECHANISM ::=
9503 -- MECHANISM_NAME
9504 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9505
9506 -- MECHANISM_ASSOCIATION ::=
9507 -- [formal_parameter_NAME =>] MECHANISM_NAME
9508
9509 -- MECHANISM_NAME ::=
9510 -- Value
9511 -- | Reference
9512 -- | Descriptor [([Class =>] CLASS_NAME)]
9513
9514 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9515
996ae0b0
RK
9516 when Pragma_Import_Function => Import_Function : declare
9517 Args : Args_List (1 .. 7);
fbf5a39b 9518 Names : constant Name_List (1 .. 7) := (
996ae0b0
RK
9519 Name_Internal,
9520 Name_External,
9521 Name_Parameter_Types,
9522 Name_Result_Type,
9523 Name_Mechanism,
9524 Name_Result_Mechanism,
9525 Name_First_Optional_Parameter);
9526
9527 Internal : Node_Id renames Args (1);
9528 External : Node_Id renames Args (2);
9529 Parameter_Types : Node_Id renames Args (3);
9530 Result_Type : Node_Id renames Args (4);
9531 Mechanism : Node_Id renames Args (5);
9532 Result_Mechanism : Node_Id renames Args (6);
9533 First_Optional_Parameter : Node_Id renames Args (7);
9534
9535 begin
9536 GNAT_Pragma;
9537 Gather_Associations (Names, Args);
9538 Process_Extended_Import_Export_Subprogram_Pragma (
9539 Arg_Internal => Internal,
9540 Arg_External => External,
9541 Arg_Parameter_Types => Parameter_Types,
9542 Arg_Result_Type => Result_Type,
9543 Arg_Mechanism => Mechanism,
9544 Arg_Result_Mechanism => Result_Mechanism,
9545 Arg_First_Optional_Parameter => First_Optional_Parameter);
9546 end Import_Function;
9547
9548 -------------------
9549 -- Import_Object --
9550 -------------------
9551
9552 -- pragma Import_Object (
470cd9e9 9553 -- [Internal =>] LOCAL_NAME
996ae0b0
RK
9554 -- [, [External =>] EXTERNAL_SYMBOL]
9555 -- [, [Size =>] EXTERNAL_SYMBOL]);
9556
fbf5a39b
AC
9557 -- EXTERNAL_SYMBOL ::=
9558 -- IDENTIFIER
9559 -- | static_string_EXPRESSION
9560
996ae0b0
RK
9561 when Pragma_Import_Object => Import_Object : declare
9562 Args : Args_List (1 .. 3);
fbf5a39b 9563 Names : constant Name_List (1 .. 3) := (
996ae0b0
RK
9564 Name_Internal,
9565 Name_External,
9566 Name_Size);
9567
9568 Internal : Node_Id renames Args (1);
9569 External : Node_Id renames Args (2);
9570 Size : Node_Id renames Args (3);
9571
9572 begin
9573 GNAT_Pragma;
9574 Gather_Associations (Names, Args);
9575 Process_Extended_Import_Export_Object_Pragma (
9576 Arg_Internal => Internal,
9577 Arg_External => External,
9578 Arg_Size => Size);
9579 end Import_Object;
9580
9581 ----------------------
9582 -- Import_Procedure --
9583 ----------------------
9584
9585 -- pragma Import_Procedure (
470cd9e9 9586 -- [Internal =>] LOCAL_NAME
996ae0b0
RK
9587 -- [, [External =>] EXTERNAL_SYMBOL]
9588 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9589 -- [, [Mechanism =>] MECHANISM]
9590 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9591
fbf5a39b
AC
9592 -- EXTERNAL_SYMBOL ::=
9593 -- IDENTIFIER
9594 -- | static_string_EXPRESSION
9595
9596 -- PARAMETER_TYPES ::=
9597 -- null
9598 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9599
9600 -- TYPE_DESIGNATOR ::=
9601 -- subtype_NAME
9602 -- | subtype_Name ' Access
9603
9604 -- MECHANISM ::=
9605 -- MECHANISM_NAME
9606 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9607
9608 -- MECHANISM_ASSOCIATION ::=
9609 -- [formal_parameter_NAME =>] MECHANISM_NAME
9610
9611 -- MECHANISM_NAME ::=
9612 -- Value
9613 -- | Reference
9614 -- | Descriptor [([Class =>] CLASS_NAME)]
9615
9616 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9617
996ae0b0
RK
9618 when Pragma_Import_Procedure => Import_Procedure : declare
9619 Args : Args_List (1 .. 5);
fbf5a39b 9620 Names : constant Name_List (1 .. 5) := (
996ae0b0
RK
9621 Name_Internal,
9622 Name_External,
9623 Name_Parameter_Types,
9624 Name_Mechanism,
9625 Name_First_Optional_Parameter);
9626
9627 Internal : Node_Id renames Args (1);
9628 External : Node_Id renames Args (2);
9629 Parameter_Types : Node_Id renames Args (3);
9630 Mechanism : Node_Id renames Args (4);
9631 First_Optional_Parameter : Node_Id renames Args (5);
9632
9633 begin
9634 GNAT_Pragma;
9635 Gather_Associations (Names, Args);
9636 Process_Extended_Import_Export_Subprogram_Pragma (
9637 Arg_Internal => Internal,
9638 Arg_External => External,
9639 Arg_Parameter_Types => Parameter_Types,
9640 Arg_Mechanism => Mechanism,
9641 Arg_First_Optional_Parameter => First_Optional_Parameter);
9642 end Import_Procedure;
9643
9644 -----------------------------
9645 -- Import_Valued_Procedure --
9646 -----------------------------
9647
9648 -- pragma Import_Valued_Procedure (
470cd9e9 9649 -- [Internal =>] LOCAL_NAME
996ae0b0
RK
9650 -- [, [External =>] EXTERNAL_SYMBOL]
9651 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9652 -- [, [Mechanism =>] MECHANISM]
9653 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9654
fbf5a39b
AC
9655 -- EXTERNAL_SYMBOL ::=
9656 -- IDENTIFIER
9657 -- | static_string_EXPRESSION
9658
9659 -- PARAMETER_TYPES ::=
9660 -- null
9661 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9662
9663 -- TYPE_DESIGNATOR ::=
9664 -- subtype_NAME
9665 -- | subtype_Name ' Access
9666
9667 -- MECHANISM ::=
9668 -- MECHANISM_NAME
9669 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9670
9671 -- MECHANISM_ASSOCIATION ::=
9672 -- [formal_parameter_NAME =>] MECHANISM_NAME
9673
9674 -- MECHANISM_NAME ::=
9675 -- Value
9676 -- | Reference
9677 -- | Descriptor [([Class =>] CLASS_NAME)]
9678
9679 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9680
996ae0b0
RK
9681 when Pragma_Import_Valued_Procedure =>
9682 Import_Valued_Procedure : declare
9683 Args : Args_List (1 .. 5);
fbf5a39b 9684 Names : constant Name_List (1 .. 5) := (
996ae0b0
RK
9685 Name_Internal,
9686 Name_External,
9687 Name_Parameter_Types,
9688 Name_Mechanism,
9689 Name_First_Optional_Parameter);
9690
9691 Internal : Node_Id renames Args (1);
9692 External : Node_Id renames Args (2);
9693 Parameter_Types : Node_Id renames Args (3);
9694 Mechanism : Node_Id renames Args (4);
9695 First_Optional_Parameter : Node_Id renames Args (5);
9696
9697 begin
9698 GNAT_Pragma;
9699 Gather_Associations (Names, Args);
9700 Process_Extended_Import_Export_Subprogram_Pragma (
9701 Arg_Internal => Internal,
9702 Arg_External => External,
9703 Arg_Parameter_Types => Parameter_Types,
9704 Arg_Mechanism => Mechanism,
9705 Arg_First_Optional_Parameter => First_Optional_Parameter);
9706 end Import_Valued_Procedure;
9707
105b5e65
AC
9708 -----------------
9709 -- Independent --
9710 -----------------
9711
9712 -- pragma Independent (LOCAL_NAME);
9713
9714 when Pragma_Independent => Independent : declare
9715 E_Id : Node_Id;
9716 E : Entity_Id;
9717 D : Node_Id;
9718 K : Node_Kind;
9719
9720 begin
9721 Check_Ada_83_Warning;
9722 Ada_2012_Pragma;
9723 Check_No_Identifiers;
9724 Check_Arg_Count (1);
9725 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 9726 E_Id := Get_Pragma_Arg (Arg1);
105b5e65
AC
9727
9728 if Etype (E_Id) = Any_Type then
9729 return;
9730 end if;
9731
9732 E := Entity (E_Id);
9733 D := Declaration_Node (E);
9734 K := Nkind (D);
9735
af31bffb
AC
9736 -- Check duplicate before we chain ourselves!
9737
9738 Check_Duplicate_Pragma (E);
9739
9740 -- Check appropriate entity
9741
105b5e65
AC
9742 if Is_Type (E) then
9743 if Rep_Item_Too_Early (E, N)
9744 or else
9745 Rep_Item_Too_Late (E, N)
9746 then
9747 return;
9748 else
9749 Check_First_Subtype (Arg1);
9750 end if;
9751
9752 elsif K = N_Object_Declaration
9753 or else (K = N_Component_Declaration
9754 and then Original_Record_Component (E) = E)
9755 then
9756 if Rep_Item_Too_Late (E, N) then
9757 return;
9758 end if;
9759
9760 else
9761 Error_Pragma_Arg
9762 ("inappropriate entity for pragma%", Arg1);
9763 end if;
9764
9765 Independence_Checks.Append ((N, E));
9766 end Independent;
9767
9768 ----------------------------
9769 -- Independent_Components --
9770 ----------------------------
9771
9772 -- pragma Atomic_Components (array_LOCAL_NAME);
9773
9774 -- This processing is shared by Volatile_Components
9775
9776 when Pragma_Independent_Components => Independent_Components : declare
9777 E_Id : Node_Id;
9778 E : Entity_Id;
9779 D : Node_Id;
9780 K : Node_Kind;
9781
9782 begin
9783 Check_Ada_83_Warning;
9784 Ada_2012_Pragma;
9785 Check_No_Identifiers;
9786 Check_Arg_Count (1);
9787 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 9788 E_Id := Get_Pragma_Arg (Arg1);
105b5e65
AC
9789
9790 if Etype (E_Id) = Any_Type then
9791 return;
9792 end if;
9793
9794 E := Entity (E_Id);
9795
af31bffb
AC
9796 -- Check duplicate before we chain ourselves!
9797
9798 Check_Duplicate_Pragma (E);
9799
9800 -- Check appropriate entity
9801
105b5e65
AC
9802 if Rep_Item_Too_Early (E, N)
9803 or else
9804 Rep_Item_Too_Late (E, N)
9805 then
9806 return;
9807 end if;
9808
9809 D := Declaration_Node (E);
9810 K := Nkind (D);
9811
9812 if (K = N_Full_Type_Declaration
9813 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9814 or else
9815 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9816 and then Nkind (D) = N_Object_Declaration
9817 and then Nkind (Object_Definition (D)) =
9818 N_Constrained_Array_Definition)
9819 then
9820 Independence_Checks.Append ((N, E));
9821
9822 else
9823 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9824 end if;
9825 end Independent_Components;
9826
996ae0b0
RK
9827 ------------------------
9828 -- Initialize_Scalars --
9829 ------------------------
9830
9831 -- pragma Initialize_Scalars;
9832
9833 when Pragma_Initialize_Scalars =>
9834 GNAT_Pragma;
9835 Check_Arg_Count (0);
9836 Check_Valid_Configuration_Pragma;
fbf5a39b
AC
9837 Check_Restriction (No_Initialize_Scalars, N);
9838
406935b6 9839 -- Initialize_Scalars creates false positives in CodePeer, and
56812278 9840 -- incorrect negative results in Alfa mode, so ignore this pragma
406935b6 9841 -- in these modes.
5a989c6b
AC
9842
9843 if not Restriction_Active (No_Initialize_Scalars)
56812278 9844 and then not (CodePeer_Mode or Alfa_Mode)
5a989c6b 9845 then
fbf5a39b
AC
9846 Init_Or_Norm_Scalars := True;
9847 Initialize_Scalars := True;
9848 end if;
996ae0b0
RK
9849
9850 ------------
9851 -- Inline --
9852 ------------
9853
9854 -- pragma Inline ( NAME {, NAME} );
9855
9856 when Pragma_Inline =>
9857
9858 -- Pragma is active if inlining option is active
9859
c71c53a8 9860 Process_Inline (Inline_Active);
996ae0b0
RK
9861
9862 -------------------
9863 -- Inline_Always --
9864 -------------------
9865
9866 -- pragma Inline_Always ( NAME {, NAME} );
9867
9868 when Pragma_Inline_Always =>
a30a01fe 9869 GNAT_Pragma;
3c1ecd7e 9870
56812278 9871 -- Pragma always active unless in CodePeer or Alfa mode, since
406935b6 9872 -- this causes walk order issues.
3c1ecd7e 9873
56812278 9874 if not (CodePeer_Mode or Alfa_Mode) then
3c1ecd7e
AC
9875 Process_Inline (True);
9876 end if;
996ae0b0
RK
9877
9878 --------------------
9879 -- Inline_Generic --
9880 --------------------
9881
9882 -- pragma Inline_Generic (NAME {, NAME});
9883
9884 when Pragma_Inline_Generic =>
a30a01fe 9885 GNAT_Pragma;
996ae0b0
RK
9886 Process_Generic_List;
9887
9888 ----------------------
9889 -- Inspection_Point --
9890 ----------------------
9891
9892 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9893
9894 when Pragma_Inspection_Point => Inspection_Point : declare
9895 Arg : Node_Id;
9896 Exp : Node_Id;
9897
9898 begin
9899 if Arg_Count > 0 then
9900 Arg := Arg1;
9901 loop
0f1a6a0b 9902 Exp := Get_Pragma_Arg (Arg);
996ae0b0
RK
9903 Analyze (Exp);
9904
9905 if not Is_Entity_Name (Exp)
9906 or else not Is_Object (Entity (Exp))
9907 then
9908 Error_Pragma_Arg ("object name required", Arg);
9909 end if;
9910
9911 Next (Arg);
9912 exit when No (Arg);
9913 end loop;
9914 end if;
9915 end Inspection_Point;
9916
9917 ---------------
9918 -- Interface --
9919 ---------------
9920
9921 -- pragma Interface (
ac9e9918
RD
9922 -- [ Convention =>] convention_IDENTIFIER,
9923 -- [ Entity =>] local_NAME
9924 -- [, [External_Name =>] static_string_EXPRESSION ]
9925 -- [, [Link_Name =>] static_string_EXPRESSION ]);
996ae0b0
RK
9926
9927 when Pragma_Interface =>
9928 GNAT_Pragma;
ac9e9918
RD
9929 Check_Arg_Order
9930 ((Name_Convention,
9931 Name_Entity,
9932 Name_External_Name,
9933 Name_Link_Name));
9934 Check_At_Least_N_Arguments (2);
9935 Check_At_Most_N_Arguments (4);
996ae0b0
RK
9936 Process_Import_Or_Interface;
9937
b5c739f9
RD
9938 -- In Ada 2005, the permission to use Interface (a reserved word)
9939 -- as a pragma name is considered an obsolescent feature.
9940
9941 if Ada_Version >= Ada_2005 then
9942 Check_Restriction
9943 (No_Obsolescent_Features, Pragma_Identifier (N));
9944 end if;
9945
996ae0b0
RK
9946 --------------------
9947 -- Interface_Name --
9948 --------------------
9949
9950 -- pragma Interface_Name (
9951 -- [ Entity =>] local_NAME
9952 -- [,[External_Name =>] static_string_EXPRESSION ]
9953 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9954
9955 when Pragma_Interface_Name => Interface_Name : declare
9956 Id : Node_Id;
9957 Def_Id : Entity_Id;
9958 Hom_Id : Entity_Id;
9959 Found : Boolean;
9960
9961 begin
9962 GNAT_Pragma;
59e5fbe0
RD
9963 Check_Arg_Order
9964 ((Name_Entity, Name_External_Name, Name_Link_Name));
996ae0b0
RK
9965 Check_At_Least_N_Arguments (2);
9966 Check_At_Most_N_Arguments (3);
0f1a6a0b 9967 Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
9968 Analyze (Id);
9969
9970 if not Is_Entity_Name (Id) then
9971 Error_Pragma_Arg
9972 ("first argument for pragma% must be entity name", Arg1);
9973 elsif Etype (Id) = Any_Type then
9974 return;
9975 else
9976 Def_Id := Entity (Id);
9977 end if;
9978
21d27997
RD
9979 -- Special DEC-compatible processing for the object case, forces
9980 -- object to be imported.
996ae0b0
RK
9981
9982 if Ekind (Def_Id) = E_Variable then
9983 Kill_Size_Check_Code (Def_Id);
21d27997 9984 Note_Possible_Modification (Id, Sure => False);
996ae0b0
RK
9985
9986 -- Initialization is not allowed for imported variable
9987
9988 if Present (Expression (Parent (Def_Id)))
9989 and then Comes_From_Source (Expression (Parent (Def_Id)))
9990 then
9991 Error_Msg_Sloc := Sloc (Def_Id);
9992 Error_Pragma_Arg
9993 ("no initialization allowed for declaration of& #",
9994 Arg2);
9995
9996 else
9997 -- For compatibility, support VADS usage of providing both
9998 -- pragmas Interface and Interface_Name to obtain the effect
9999 -- of a single Import pragma.
10000
10001 if Is_Imported (Def_Id)
10002 and then Present (First_Rep_Item (Def_Id))
10003 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
1b24ada5
RD
10004 and then
10005 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
996ae0b0
RK
10006 then
10007 null;
10008 else
10009 Set_Imported (Def_Id);
10010 end if;
10011
10012 Set_Is_Public (Def_Id);
10013 Process_Interface_Name (Def_Id, Arg2, Arg3);
10014 end if;
10015
10016 -- Otherwise must be subprogram
10017
10018 elsif not Is_Subprogram (Def_Id) then
10019 Error_Pragma_Arg
10020 ("argument of pragma% is not subprogram", Arg1);
10021
10022 else
10023 Check_At_Most_N_Arguments (3);
10024 Hom_Id := Def_Id;
10025 Found := False;
10026
10027 -- Loop through homonyms
10028
10029 loop
10030 Def_Id := Get_Base_Subprogram (Hom_Id);
10031
10032 if Is_Imported (Def_Id) then
10033 Process_Interface_Name (Def_Id, Arg2, Arg3);
10034 Found := True;
10035 end if;
10036
0f1a6a0b 10037 exit when From_Aspect_Specification (N);
996ae0b0
RK
10038 Hom_Id := Homonym (Hom_Id);
10039
10040 exit when No (Hom_Id)
10041 or else Scope (Hom_Id) /= Current_Scope;
10042 end loop;
10043
10044 if not Found then
10045 Error_Pragma_Arg
10046 ("argument of pragma% is not imported subprogram",
10047 Arg1);
10048 end if;
10049 end if;
10050 end Interface_Name;
10051
10052 -----------------------
10053 -- Interrupt_Handler --
10054 -----------------------
10055
10056 -- pragma Interrupt_Handler (handler_NAME);
10057
10058 when Pragma_Interrupt_Handler =>
10059 Check_Ada_83_Warning;
10060 Check_Arg_Count (1);
10061 Check_No_Identifiers;
fbf5a39b
AC
10062
10063 if No_Run_Time_Mode then
10064 Error_Msg_CRT ("Interrupt_Handler pragma", N);
10065 else
10066 Check_Interrupt_Or_Attach_Handler;
10067 Process_Interrupt_Or_Attach_Handler;
10068 end if;
996ae0b0
RK
10069
10070 ------------------------
10071 -- Interrupt_Priority --
10072 ------------------------
10073
10074 -- pragma Interrupt_Priority [(EXPRESSION)];
10075
10076 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
10077 P : constant Node_Id := Parent (N);
10078 Arg : Node_Id;
10079
10080 begin
10081 Check_Ada_83_Warning;
10082
10083 if Arg_Count /= 0 then
0f1a6a0b 10084 Arg := Get_Pragma_Arg (Arg1);
996ae0b0
RK
10085 Check_Arg_Count (1);
10086 Check_No_Identifiers;
10087
fbf5a39b
AC
10088 -- The expression must be analyzed in the special manner
10089 -- described in "Handling of Default and Per-Object
10090 -- Expressions" in sem.ads.
996ae0b0 10091
21d27997 10092 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
996ae0b0
RK
10093 end if;
10094
d7ba4df4 10095 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
996ae0b0
RK
10096 Pragma_Misplaced;
10097 return;
10098
c775c209 10099 elsif Has_Pragma_Priority (P) then
996ae0b0
RK
10100 Error_Pragma ("duplicate pragma% not allowed");
10101
10102 else
c775c209 10103 Set_Has_Pragma_Priority (P, True);
996ae0b0
RK
10104 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10105 end if;
10106 end Interrupt_Priority;
10107
fbf5a39b
AC
10108 ---------------------
10109 -- Interrupt_State --
10110 ---------------------
10111
10112 -- pragma Interrupt_State (
10113 -- [Name =>] INTERRUPT_ID,
10114 -- [State =>] INTERRUPT_STATE);
10115
10116 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
10117 -- INTERRUPT_STATE => System | Runtime | User
10118
b3b9865d
AC
10119 -- Note: if the interrupt id is given as an identifier, then it must
10120 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
10121 -- given as a static integer expression which must be in the range of
10122 -- Ada.Interrupts.Interrupt_ID.
fbf5a39b
AC
10123
10124 when Pragma_Interrupt_State => Interrupt_State : declare
10125
10126 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
10127 -- This is the entity Ada.Interrupts.Interrupt_ID;
10128
10129 State_Type : Character;
10130 -- Set to 's'/'r'/'u' for System/Runtime/User
10131
10132 IST_Num : Pos;
10133 -- Index to entry in Interrupt_States table
10134
10135 Int_Val : Uint;
10136 -- Value of interrupt
10137
10138 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
10139 -- The first argument to the pragma
10140
10141 Int_Ent : Entity_Id;
10142 -- Interrupt entity in Ada.Interrupts.Names
10143
10144 begin
10145 GNAT_Pragma;
59e5fbe0 10146 Check_Arg_Order ((Name_Name, Name_State));
fbf5a39b
AC
10147 Check_Arg_Count (2);
10148
10149 Check_Optional_Identifier (Arg1, Name_Name);
59e5fbe0 10150 Check_Optional_Identifier (Arg2, Name_State);
fbf5a39b
AC
10151 Check_Arg_Is_Identifier (Arg2);
10152
10153 -- First argument is identifier
10154
10155 if Nkind (Arg1X) = N_Identifier then
10156
10157 -- Search list of names in Ada.Interrupts.Names
10158
10159 Int_Ent := First_Entity (RTE (RE_Names));
10160 loop
10161 if No (Int_Ent) then
10162 Error_Pragma_Arg ("invalid interrupt name", Arg1);
10163
10164 elsif Chars (Int_Ent) = Chars (Arg1X) then
10165 Int_Val := Expr_Value (Constant_Value (Int_Ent));
10166 exit;
10167 end if;
10168
10169 Next_Entity (Int_Ent);
10170 end loop;
10171
b3b9865d
AC
10172 -- First argument is not an identifier, so it must be a static
10173 -- expression of type Ada.Interrupts.Interrupt_ID.
fbf5a39b
AC
10174
10175 else
10176 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10177 Int_Val := Expr_Value (Arg1X);
10178
10179 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
10180 or else
10181 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
10182 then
10183 Error_Pragma_Arg
10184 ("value not in range of type " &
10185 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
10186 end if;
10187 end if;
10188
10189 -- Check OK state
10190
10191 case Chars (Get_Pragma_Arg (Arg2)) is
10192 when Name_Runtime => State_Type := 'r';
10193 when Name_System => State_Type := 's';
10194 when Name_User => State_Type := 'u';
10195
10196 when others =>
10197 Error_Pragma_Arg ("invalid interrupt state", Arg2);
10198 end case;
10199
10200 -- Check if entry is already stored
10201
10202 IST_Num := Interrupt_States.First;
10203 loop
10204 -- If entry not found, add it
10205
10206 if IST_Num > Interrupt_States.Last then
10207 Interrupt_States.Append
10208 ((Interrupt_Number => UI_To_Int (Int_Val),
10209 Interrupt_State => State_Type,
10210 Pragma_Loc => Loc));
10211 exit;
10212
10213 -- Case of entry for the same entry
10214
10215 elsif Int_Val = Interrupt_States.Table (IST_Num).
10216 Interrupt_Number
10217 then
10218 -- If state matches, done, no need to make redundant entry
10219
10220 exit when
10221 State_Type = Interrupt_States.Table (IST_Num).
10222 Interrupt_State;
10223
10224 -- Otherwise if state does not match, error
10225
10226 Error_Msg_Sloc :=
10227 Interrupt_States.Table (IST_Num).Pragma_Loc;
10228 Error_Pragma_Arg
2fa9443e 10229 ("state conflicts with that given #", Arg2);
fbf5a39b
AC
10230 exit;
10231 end if;
10232
10233 IST_Num := IST_Num + 1;
10234 end loop;
10235 end Interrupt_State;
10236
e606088a
AC
10237 ---------------
10238 -- Invariant --
10239 ---------------
10240
10241 -- pragma Invariant
10242 -- ([Entity =>] type_LOCAL_NAME,
10243 -- [Check =>] EXPRESSION
10244 -- [,[Message =>] String_Expression]);
10245
10246 when Pragma_Invariant => Invariant : declare
10247 Type_Id : Node_Id;
10248 Typ : Entity_Id;
10249
10250 Discard : Boolean;
10251 pragma Unreferenced (Discard);
10252
10253 begin
10254 GNAT_Pragma;
10255 Check_At_Least_N_Arguments (2);
10256 Check_At_Most_N_Arguments (3);
10257 Check_Optional_Identifier (Arg1, Name_Entity);
10258 Check_Optional_Identifier (Arg2, Name_Check);
10259
10260 if Arg_Count = 3 then
10261 Check_Optional_Identifier (Arg3, Name_Message);
10262 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10263 end if;
10264
10265 Check_Arg_Is_Local_Name (Arg1);
10266
10267 Type_Id := Get_Pragma_Arg (Arg1);
10268 Find_Type (Type_Id);
10269 Typ := Entity (Type_Id);
10270
10271 if Typ = Any_Type then
10272 return;
10273
516785cc
AC
10274 -- An invariant must apply to a private type, or appear in the
10275 -- private part of a package spec and apply to a completion.
10276
10277 elsif Ekind_In (Typ, E_Private_Type,
df177175
RD
10278 E_Record_Type_With_Private,
10279 E_Limited_Private_Type)
e606088a 10280 then
516785cc
AC
10281 null;
10282
10283 elsif In_Private_Part (Current_Scope)
10284 and then Has_Private_Declaration (Typ)
10285 then
10286 null;
10287
f4f92d9d 10288 elsif In_Private_Part (Current_Scope) then
ba759acd 10289 Error_Pragma_Arg
f4f92d9d 10290 ("pragma% only allowed for private type " &
ba759acd 10291 "declared in visible part", Arg1);
f4f92d9d 10292
516785cc 10293 else
ba759acd
AC
10294 Error_Pragma_Arg
10295 ("pragma% only allowed for private type", Arg1);
e606088a
AC
10296 end if;
10297
10298 -- Note that the type has at least one invariant, and also that
10299 -- it has inheritable invariants if we have Invariant'Class.
10300
10301 Set_Has_Invariants (Typ);
10302
10303 if Class_Present (N) then
10304 Set_Has_Inheritable_Invariants (Typ);
10305 end if;
10306
10307 -- The remaining processing is simply to link the pragma on to
10308 -- the rep item chain, for processing when the type is frozen.
10309 -- This is accomplished by a call to Rep_Item_Too_Late.
10310
10311 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10312 end Invariant;
10313
996ae0b0
RK
10314 ----------------------
10315 -- Java_Constructor --
10316 ----------------------
10317
10318 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10319
c690a2ec
RD
10320 -- Also handles pragma CIL_Constructor
10321
2fa9443e
ES
10322 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10323 Java_Constructor : declare
0b89eea8
AC
10324 Convention : Convention_Id;
10325 Def_Id : Entity_Id;
10326 Hom_Id : Entity_Id;
10327 Id : Entity_Id;
10328 This_Formal : Entity_Id;
996ae0b0
RK
10329
10330 begin
10331 GNAT_Pragma;
10332 Check_Arg_Count (1);
10333 Check_Optional_Identifier (Arg1, Name_Entity);
10334 Check_Arg_Is_Local_Name (Arg1);
10335
0f1a6a0b 10336 Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
10337 Find_Program_Unit_Name (Id);
10338
10339 -- If we did not find the name, we are done
10340
10341 if Etype (Id) = Any_Type then
10342 return;
10343 end if;
10344
bcae2eaa
JM
10345 -- Check wrong use of pragma in wrong VM target
10346
10347 if VM_Target = No_VM then
10348 return;
10349
10350 elsif VM_Target = CLI_Target
10351 and then Prag_Id = Pragma_Java_Constructor
10352 then
10353 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10354
10355 elsif VM_Target = JVM_Target
10356 and then Prag_Id = Pragma_CIL_Constructor
10357 then
10358 Error_Pragma ("must use pragma 'Java_'Constructor");
10359 end if;
10360
2fa9443e
ES
10361 case Prag_Id is
10362 when Pragma_CIL_Constructor => Convention := Convention_CIL;
10363 when Pragma_Java_Constructor => Convention := Convention_Java;
10364 when others => null;
10365 end case;
10366
996ae0b0
RK
10367 Hom_Id := Entity (Id);
10368
10369 -- Loop through homonyms
10370
10371 loop
10372 Def_Id := Get_Base_Subprogram (Hom_Id);
10373
bcae2eaa 10374 -- The constructor is required to be a function
996ae0b0 10375
bcae2eaa
JM
10376 if Ekind (Def_Id) /= E_Function then
10377 if VM_Target = JVM_Target then
2fa9443e
ES
10378 Error_Pragma_Arg
10379 ("pragma% requires function returning a " &
bcae2eaa 10380 "'Java access type", Def_Id);
2fa9443e 10381 else
2fa9443e
ES
10382 Error_Pragma_Arg
10383 ("pragma% requires function returning a " &
bcae2eaa 10384 "'C'I'L access type", Def_Id);
2fa9443e 10385 end if;
996ae0b0
RK
10386 end if;
10387
bcae2eaa
JM
10388 -- Check arguments: For tagged type the first formal must be
10389 -- named "this" and its type must be a named access type
10390 -- designating a class-wide tagged type that has convention
10391 -- CIL/Java. The first formal must also have a null default
10392 -- value. For example:
10393
10394 -- type Typ is tagged ...
10395 -- type Ref is access all Typ;
10396 -- pragma Convention (CIL, Typ);
10397
10398 -- function New_Typ (This : Ref) return Ref;
10399 -- function New_Typ (This : Ref; I : Integer) return Ref;
10400 -- pragma Cil_Constructor (New_Typ);
10401
10402 -- Reason: The first formal must NOT be a primitive of the
10403 -- tagged type.
10404
10405 -- This rule also applies to constructors of delegates used
10406 -- to interface with standard target libraries. For example:
10407
10408 -- type Delegate is access procedure ...
10409 -- pragma Import (CIL, Delegate, ...);
10410
10411 -- function new_Delegate
10412 -- (This : Delegate := null; ... ) return Delegate;
10413
10414 -- For value-types this rule does not apply.
10415
10416 if not Is_Value_Type (Etype (Def_Id)) then
10417 if No (First_Formal (Def_Id)) then
10418 Error_Msg_Name_1 := Pname;
0b89eea8
AC
10419 Error_Msg_N ("% function must have parameters", Def_Id);
10420 return;
10421 end if;
10422
10423 -- In the JRE library we have several occurrences in which
10424 -- the "this" parameter is not the first formal.
bcae2eaa 10425
0b89eea8
AC
10426 This_Formal := First_Formal (Def_Id);
10427
10428 -- In the JRE library we have several occurrences in which
10429 -- the "this" parameter is not the first formal. Search for
10430 -- it.
10431
10432 if VM_Target = JVM_Target then
10433 while Present (This_Formal)
10434 and then Get_Name_String (Chars (This_Formal)) /= "this"
10435 loop
10436 Next_Formal (This_Formal);
10437 end loop;
10438
10439 if No (This_Formal) then
10440 This_Formal := First_Formal (Def_Id);
10441 end if;
10442 end if;
10443
10444 -- Warning: The first parameter should be named "this".
10445 -- We temporarily allow it because we have the following
10446 -- case in the Java runtime (file s-osinte.ads) ???
10447
10448 -- function new_Thread
10449 -- (Self_Id : System.Address) return Thread_Id;
10450 -- pragma Java_Constructor (new_Thread);
10451
10452 if VM_Target = JVM_Target
10453 and then Get_Name_String (Chars (First_Formal (Def_Id)))
10454 = "self_id"
10455 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
bcae2eaa 10456 then
0b89eea8
AC
10457 null;
10458
10459 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
bcae2eaa
JM
10460 Error_Msg_Name_1 := Pname;
10461 Error_Msg_N
10462 ("first formal of % function must be named `this`",
0b89eea8 10463 Parent (This_Formal));
bcae2eaa 10464
0b89eea8 10465 elsif not Is_Access_Type (Etype (This_Formal)) then
bd622b64
AC
10466 Error_Msg_Name_1 := Pname;
10467 Error_Msg_N
10468 ("first formal of % function must be an access type",
0b89eea8 10469 Parameter_Type (Parent (This_Formal)));
bd622b64
AC
10470
10471 -- For delegates the type of the first formal must be a
10472 -- named access-to-subprogram type (see previous example)
10473
10474 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
0b89eea8 10475 and then Ekind (Etype (This_Formal))
bd622b64
AC
10476 /= E_Access_Subprogram_Type
10477 then
10478 Error_Msg_Name_1 := Pname;
10479 Error_Msg_N
10480 ("first formal of % function must be a named access" &
10481 " to subprogram type",
0b89eea8 10482 Parameter_Type (Parent (This_Formal)));
bd622b64 10483
bcae2eaa
JM
10484 -- Warning: We should reject anonymous access types because
10485 -- the constructor must not be handled as a primitive of the
10486 -- tagged type. We temporarily allow it because this profile
10487 -- is currently generated by cil2ada???
10488
bd622b64 10489 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
0b89eea8
AC
10490 and then not Ekind_In (Etype (This_Formal),
10491 E_Access_Type,
10492 E_General_Access_Type,
10493 E_Anonymous_Access_Type)
bcae2eaa
JM
10494 then
10495 Error_Msg_Name_1 := Pname;
10496 Error_Msg_N
10497 ("first formal of % function must be a named access" &
10498 " type",
0b89eea8 10499 Parameter_Type (Parent (This_Formal)));
bcae2eaa
JM
10500
10501 elsif Atree.Convention
0b89eea8 10502 (Designated_Type (Etype (This_Formal))) /= Convention
bcae2eaa
JM
10503 then
10504 Error_Msg_Name_1 := Pname;
10505
10506 if Convention = Convention_Java then
10507 Error_Msg_N
10508 ("pragma% requires convention 'Cil in designated" &
10509 " type",
0b89eea8 10510 Parameter_Type (Parent (This_Formal)));
bcae2eaa
JM
10511 else
10512 Error_Msg_N
10513 ("pragma% requires convention 'Java in designated" &
10514 " type",
0b89eea8 10515 Parameter_Type (Parent (This_Formal)));
bcae2eaa
JM
10516 end if;
10517
0b89eea8
AC
10518 elsif No (Expression (Parent (This_Formal)))
10519 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
bcae2eaa
JM
10520 then
10521 Error_Msg_Name_1 := Pname;
10522 Error_Msg_N
10523 ("pragma% requires first formal with default `null`",
0b89eea8 10524 Parameter_Type (Parent (This_Formal)));
bcae2eaa
JM
10525 end if;
10526 end if;
10527
10528 -- Check result type: the constructor must be a function
10529 -- returning:
10530 -- * a value type (only allowed in the CIL compiler)
10531 -- * an access-to-subprogram type with convention Java/CIL
10532 -- * an access-type designating a type that has convention
10533 -- Java/CIL.
10534
10535 if Is_Value_Type (Etype (Def_Id)) then
10536 null;
10537
10538 -- Access-to-subprogram type with convention Java/CIL
10539
10540 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10541 if Atree.Convention (Etype (Def_Id)) /= Convention then
10542 if Convention = Convention_Java then
10543 Error_Pragma_Arg
10544 ("pragma% requires function returning a " &
10545 "'Java access type", Arg1);
10546 else
10547 pragma Assert (Convention = Convention_CIL);
10548 Error_Pragma_Arg
10549 ("pragma% requires function returning a " &
10550 "'C'I'L access type", Arg1);
10551 end if;
10552 end if;
10553
10554 elsif Ekind (Etype (Def_Id)) in Access_Kind then
10555 if not Ekind_In (Etype (Def_Id), E_Access_Type,
10556 E_General_Access_Type)
10557 or else
10558 Atree.Convention
10559 (Designated_Type (Etype (Def_Id))) /= Convention
10560 then
10561 Error_Msg_Name_1 := Pname;
10562
10563 if Convention = Convention_Java then
10564 Error_Pragma_Arg
10565 ("pragma% requires function returning a named" &
10566 "'Java access type", Arg1);
10567 else
10568 Error_Pragma_Arg
10569 ("pragma% requires function returning a named" &
10570 "'C'I'L access type", Arg1);
10571 end if;
10572 end if;
10573 end if;
10574
10575 Set_Is_Constructor (Def_Id);
10576 Set_Convention (Def_Id, Convention);
10577 Set_Is_Imported (Def_Id);
10578
0f1a6a0b 10579 exit when From_Aspect_Specification (N);
996ae0b0
RK
10580 Hom_Id := Homonym (Hom_Id);
10581
10582 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10583 end loop;
10584 end Java_Constructor;
10585
10586 ----------------------
10587 -- Java_Interface --
10588 ----------------------
10589
10590 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
10591
10592 when Pragma_Java_Interface => Java_Interface : declare
10593 Arg : Node_Id;
10594 Typ : Entity_Id;
10595
10596 begin
10597 GNAT_Pragma;
10598 Check_Arg_Count (1);
10599 Check_Optional_Identifier (Arg1, Name_Entity);
10600 Check_Arg_Is_Local_Name (Arg1);
10601
0f1a6a0b 10602 Arg := Get_Pragma_Arg (Arg1);
996ae0b0
RK
10603 Analyze (Arg);
10604
10605 if Etype (Arg) = Any_Type then
10606 return;
10607 end if;
10608
10609 if not Is_Entity_Name (Arg)
10610 or else not Is_Type (Entity (Arg))
10611 then
10612 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10613 end if;
10614
10615 Typ := Underlying_Type (Entity (Arg));
10616
b3b9865d
AC
10617 -- For now simply check some of the semantic constraints on the
10618 -- type. This currently leaves out some restrictions on interface
10619 -- types, namely that the parent type must be java.lang.Object.Typ
10620 -- and that all primitives of the type should be declared
10621 -- abstract. ???
996ae0b0 10622
874a0341 10623 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
996ae0b0
RK
10624 Error_Pragma_Arg ("pragma% requires an abstract "
10625 & "tagged type", Arg1);
10626
10627 elsif not Has_Discriminants (Typ)
10628 or else Ekind (Etype (First_Discriminant (Typ)))
10629 /= E_Anonymous_Access_Type
10630 or else
10631 not Is_Class_Wide_Type
10632 (Designated_Type (Etype (First_Discriminant (Typ))))
10633 then
10634 Error_Pragma_Arg
10635 ("type must have a class-wide access discriminant", Arg1);
10636 end if;
10637 end Java_Interface;
10638
fbf5a39b
AC
10639 ----------------
10640 -- Keep_Names --
10641 ----------------
10642
10643 -- pragma Keep_Names ([On => ] local_NAME);
10644
10645 when Pragma_Keep_Names => Keep_Names : declare
10646 Arg : Node_Id;
10647
10648 begin
10649 GNAT_Pragma;
10650 Check_Arg_Count (1);
10651 Check_Optional_Identifier (Arg1, Name_On);
10652 Check_Arg_Is_Local_Name (Arg1);
10653
0f1a6a0b 10654 Arg := Get_Pragma_Arg (Arg1);
fbf5a39b
AC
10655 Analyze (Arg);
10656
10657 if Etype (Arg) = Any_Type then
10658 return;
10659 end if;
10660
10661 if not Is_Entity_Name (Arg)
10662 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10663 then
10664 Error_Pragma_Arg
10665 ("pragma% requires a local enumeration type", Arg1);
10666 end if;
10667
10668 Set_Discard_Names (Entity (Arg), False);
10669 end Keep_Names;
10670
996ae0b0
RK
10671 -------------
10672 -- License --
10673 -------------
10674
59e5fbe0 10675 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
996ae0b0
RK
10676
10677 when Pragma_License =>
10678 GNAT_Pragma;
10679 Check_Arg_Count (1);
10680 Check_No_Identifiers;
10681 Check_Valid_Configuration_Pragma;
10682 Check_Arg_Is_Identifier (Arg1);
10683
10684 declare
10685 Sind : constant Source_File_Index :=
10686 Source_Index (Current_Sem_Unit);
10687
10688 begin
10689 case Chars (Get_Pragma_Arg (Arg1)) is
10690 when Name_GPL =>
10691 Set_License (Sind, GPL);
10692
10693 when Name_Modified_GPL =>
10694 Set_License (Sind, Modified_GPL);
10695
10696 when Name_Restricted =>
10697 Set_License (Sind, Restricted);
10698
10699 when Name_Unrestricted =>
10700 Set_License (Sind, Unrestricted);
10701
10702 when others =>
10703 Error_Pragma_Arg ("invalid license name", Arg1);
10704 end case;
10705 end;
10706
10707 ---------------
10708 -- Link_With --
10709 ---------------
10710
10711 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10712
10713 when Pragma_Link_With => Link_With : declare
10714 Arg : Node_Id;
10715
10716 begin
10717 GNAT_Pragma;
10718
10719 if Operating_Mode = Generate_Code
10720 and then In_Extended_Main_Source_Unit (N)
10721 then
10722 Check_At_Least_N_Arguments (1);
10723 Check_No_Identifiers;
10724 Check_Is_In_Decl_Part_Or_Package_Spec;
10725 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10726 Start_String;
10727
10728 Arg := Arg1;
10729 while Present (Arg) loop
10730 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10731
b3b9865d
AC
10732 -- Store argument, converting sequences of spaces to a
10733 -- single null character (this is one of the differences
10734 -- in processing between Link_With and Linker_Options).
996ae0b0 10735
c690a2ec 10736 Arg_Store : declare
996ae0b0
RK
10737 C : constant Char_Code := Get_Char_Code (' ');
10738 S : constant String_Id :=
0f1a6a0b 10739 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
fbf5a39b 10740 L : constant Nat := String_Length (S);
996ae0b0 10741 F : Nat := 1;
996ae0b0
RK
10742
10743 procedure Skip_Spaces;
10744 -- Advance F past any spaces
10745
c690a2ec
RD
10746 -----------------
10747 -- Skip_Spaces --
10748 -----------------
10749
996ae0b0
RK
10750 procedure Skip_Spaces is
10751 begin
10752 while F <= L and then Get_String_Char (S, F) = C loop
10753 F := F + 1;
10754 end loop;
10755 end Skip_Spaces;
10756
c690a2ec
RD
10757 -- Start of processing for Arg_Store
10758
996ae0b0
RK
10759 begin
10760 Skip_Spaces; -- skip leading spaces
10761
10762 -- Loop through characters, changing any embedded
b3b9865d
AC
10763 -- sequence of spaces to a single null character (this
10764 -- is how Link_With/Linker_Options differ)
996ae0b0
RK
10765
10766 while F <= L loop
10767 if Get_String_Char (S, F) = C then
10768 Skip_Spaces;
10769 exit when F > L;
10770 Store_String_Char (ASCII.NUL);
10771
10772 else
10773 Store_String_Char (Get_String_Char (S, F));
10774 F := F + 1;
10775 end if;
10776 end loop;
c690a2ec 10777 end Arg_Store;
996ae0b0
RK
10778
10779 Arg := Next (Arg);
10780
10781 if Present (Arg) then
10782 Store_String_Char (ASCII.NUL);
10783 end if;
10784 end loop;
10785
10786 Store_Linker_Option_String (End_String);
10787 end if;
10788 end Link_With;
10789
10790 ------------------
10791 -- Linker_Alias --
10792 ------------------
10793
10794 -- pragma Linker_Alias (
10795 -- [Entity =>] LOCAL_NAME
d9e0a587 10796 -- [Target =>] static_string_EXPRESSION);
996ae0b0
RK
10797
10798 when Pragma_Linker_Alias =>
10799 GNAT_Pragma;
d9e0a587 10800 Check_Arg_Order ((Name_Entity, Name_Target));
996ae0b0
RK
10801 Check_Arg_Count (2);
10802 Check_Optional_Identifier (Arg1, Name_Entity);
d9e0a587 10803 Check_Optional_Identifier (Arg2, Name_Target);
996ae0b0
RK
10804 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10805 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10806
10807 -- The only processing required is to link this item on to the
10808 -- list of rep items for the given entity. This is accomplished
10809 -- by the call to Rep_Item_Too_Late (when no error is detected
10810 -- and False is returned).
10811
0f1a6a0b 10812 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
996ae0b0
RK
10813 return;
10814 else
0f1a6a0b 10815 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
996ae0b0
RK
10816 end if;
10817
d9e0a587
EB
10818 ------------------------
10819 -- Linker_Constructor --
10820 ------------------------
10821
10822 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10823
10824 -- Code is shared with Linker_Destructor
10825
10826 -----------------------
10827 -- Linker_Destructor --
10828 -----------------------
10829
10830 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10831
10832 when Pragma_Linker_Constructor |
10833 Pragma_Linker_Destructor =>
10834 Linker_Constructor : declare
10835 Arg1_X : Node_Id;
10836 Proc : Entity_Id;
10837
10838 begin
10839 GNAT_Pragma;
10840 Check_Arg_Count (1);
10841 Check_No_Identifiers;
10842 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 10843 Arg1_X := Get_Pragma_Arg (Arg1);
d9e0a587
EB
10844 Analyze (Arg1_X);
10845 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10846
10847 if not Is_Library_Level_Entity (Proc) then
10848 Error_Pragma_Arg
10849 ("argument for pragma% must be library level entity", Arg1);
10850 end if;
10851
10852 -- The only processing required is to link this item on to the
10853 -- list of rep items for the given entity. This is accomplished
10854 -- by the call to Rep_Item_Too_Late (when no error is detected
10855 -- and False is returned).
10856
10857 if Rep_Item_Too_Late (Proc, N) then
10858 return;
10859 else
10860 Set_Has_Gigi_Rep_Item (Proc);
10861 end if;
10862 end Linker_Constructor;
10863
996ae0b0
RK
10864 --------------------
10865 -- Linker_Options --
10866 --------------------
10867
10868 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10869
996ae0b0
RK
10870 when Pragma_Linker_Options => Linker_Options : declare
10871 Arg : Node_Id;
10872
10873 begin
07fc65c4
GB
10874 Check_Ada_83_Warning;
10875 Check_No_Identifiers;
10876 Check_Arg_Count (1);
10877 Check_Is_In_Decl_Part_Or_Package_Spec;
21d27997 10878 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
0f1a6a0b 10879 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
21d27997
RD
10880
10881 Arg := Arg2;
10882 while Present (Arg) loop
10883 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10884 Store_String_Char (ASCII.NUL);
0f1a6a0b
AC
10885 Store_String_Chars
10886 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
21d27997
RD
10887 Arg := Next (Arg);
10888 end loop;
07fc65c4 10889
996ae0b0
RK
10890 if Operating_Mode = Generate_Code
10891 and then In_Extended_Main_Source_Unit (N)
10892 then
996ae0b0
RK
10893 Store_Linker_Option_String (End_String);
10894 end if;
10895 end Linker_Options;
10896
10897 --------------------
10898 -- Linker_Section --
10899 --------------------
10900
10901 -- pragma Linker_Section (
10902 -- [Entity =>] LOCAL_NAME
10903 -- [Section =>] static_string_EXPRESSION);
10904
10905 when Pragma_Linker_Section =>
10906 GNAT_Pragma;
59e5fbe0 10907 Check_Arg_Order ((Name_Entity, Name_Section));
996ae0b0
RK
10908 Check_Arg_Count (2);
10909 Check_Optional_Identifier (Arg1, Name_Entity);
10910 Check_Optional_Identifier (Arg2, Name_Section);
10911 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10912 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10913
2efcad9f 10914 -- This pragma applies only to objects
32f7efe1 10915
0f1a6a0b 10916 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
2efcad9f 10917 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
32f7efe1
ST
10918 end if;
10919
996ae0b0
RK
10920 -- The only processing required is to link this item on to the
10921 -- list of rep items for the given entity. This is accomplished
10922 -- by the call to Rep_Item_Too_Late (when no error is detected
10923 -- and False is returned).
10924
0f1a6a0b 10925 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
996ae0b0
RK
10926 return;
10927 else
0f1a6a0b 10928 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
996ae0b0
RK
10929 end if;
10930
10931 ----------
10932 -- List --
10933 ----------
10934
10935 -- pragma List (On | Off)
10936
b3b9865d
AC
10937 -- There is nothing to do here, since we did all the processing for
10938 -- this pragma in Par.Prag (so that it works properly even in syntax
10939 -- only mode).
996ae0b0
RK
10940
10941 when Pragma_List =>
10942 null;
10943
10944 --------------------
10945 -- Locking_Policy --
10946 --------------------
10947
10948 -- pragma Locking_Policy (policy_IDENTIFIER);
10949
10950 when Pragma_Locking_Policy => declare
343250a6
PO
10951 subtype LP_Range is Name_Id
10952 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
10953 LP_Val : LP_Range;
10954 LP : Character;
996ae0b0
RK
10955 begin
10956 Check_Ada_83_Warning;
10957 Check_Arg_Count (1);
10958 Check_No_Identifiers;
10959 Check_Arg_Is_Locking_Policy (Arg1);
10960 Check_Valid_Configuration_Pragma;
343250a6
PO
10961 LP_Val := Chars (Get_Pragma_Arg (Arg1));
10962
10963 case LP_Val is
10964 when Name_Ceiling_Locking => LP := 'C';
10965 when Name_Inheritance_Locking => LP := 'I';
10966 when Name_Concurrent_Readers_Locking => LP := 'R';
10967 end case;
996ae0b0
RK
10968
10969 if Locking_Policy /= ' '
10970 and then Locking_Policy /= LP
10971 then
10972 Error_Msg_Sloc := Locking_Policy_Sloc;
10973 Error_Pragma ("locking policy incompatible with policy#");
fbf5a39b 10974
b3b9865d
AC
10975 -- Set new policy, but always preserve System_Location since we
10976 -- like the error message with the run time name.
fbf5a39b 10977
996ae0b0
RK
10978 else
10979 Locking_Policy := LP;
fbf5a39b
AC
10980
10981 if Locking_Policy_Sloc /= System_Location then
10982 Locking_Policy_Sloc := Loc;
10983 end if;
996ae0b0
RK
10984 end if;
10985 end;
10986
10987 ----------------
10988 -- Long_Float --
10989 ----------------
10990
10991 -- pragma Long_Float (D_Float | G_Float);
10992
a51cd0ec
AC
10993 when Pragma_Long_Float => Long_Float : declare
10994 begin
996ae0b0
RK
10995 GNAT_Pragma;
10996 Check_Valid_Configuration_Pragma;
10997 Check_Arg_Count (1);
10998 Check_No_Identifier (Arg1);
10999 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
11000
11001 if not OpenVMS_On_Target then
11002 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
11003 end if;
11004
11005 -- D_Float case
11006
0f1a6a0b 11007 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
996ae0b0 11008 if Opt.Float_Format_Long = 'G' then
a51cd0ec
AC
11009 Error_Pragma_Arg
11010 ("G_Float previously specified", Arg1);
11011
11012 elsif Current_Sem_Unit /= Main_Unit
11013 and then Opt.Float_Format_Long /= 'D'
11014 then
11015 Error_Pragma_Arg
11016 ("main unit not compiled with pragma Long_Float (D_Float)",
11017 "\pragma% must be used consistently for whole partition",
11018 Arg1);
996ae0b0 11019
a51cd0ec
AC
11020 else
11021 Opt.Float_Format_Long := 'D';
11022 end if;
996ae0b0
RK
11023
11024 -- G_Float case (this is the default, does not need overriding)
11025
11026 else
11027 if Opt.Float_Format_Long = 'D' then
11028 Error_Pragma ("D_Float previously specified");
996ae0b0 11029
a51cd0ec
AC
11030 elsif Current_Sem_Unit /= Main_Unit
11031 and then Opt.Float_Format_Long /= 'G'
11032 then
11033 Error_Pragma_Arg
11034 ("main unit not compiled with pragma Long_Float (G_Float)",
11035 "\pragma% must be used consistently for whole partition",
11036 Arg1);
11037
11038 else
11039 Opt.Float_Format_Long := 'G';
11040 end if;
996ae0b0
RK
11041 end if;
11042
11043 Set_Standard_Fpt_Formats;
a51cd0ec 11044 end Long_Float;
996ae0b0
RK
11045
11046 -----------------------
11047 -- Machine_Attribute --
11048 -----------------------
11049
11050 -- pragma Machine_Attribute (
470cd9e9
RD
11051 -- [Entity =>] LOCAL_NAME,
11052 -- [Attribute_Name =>] static_string_EXPRESSION
d81b4c61 11053 -- [, [Info =>] static_EXPRESSION] );
996ae0b0
RK
11054
11055 when Pragma_Machine_Attribute => Machine_Attribute : declare
11056 Def_Id : Entity_Id;
11057
11058 begin
11059 GNAT_Pragma;
59e5fbe0 11060 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
996ae0b0
RK
11061
11062 if Arg_Count = 3 then
59e5fbe0 11063 Check_Optional_Identifier (Arg3, Name_Info);
d81b4c61 11064 Check_Arg_Is_Static_Expression (Arg3);
996ae0b0
RK
11065 else
11066 Check_Arg_Count (2);
11067 end if;
11068
996ae0b0 11069 Check_Optional_Identifier (Arg1, Name_Entity);
59e5fbe0
RD
11070 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
11071 Check_Arg_Is_Local_Name (Arg1);
996ae0b0 11072 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
0f1a6a0b 11073 Def_Id := Entity (Get_Pragma_Arg (Arg1));
996ae0b0
RK
11074
11075 if Is_Access_Type (Def_Id) then
11076 Def_Id := Designated_Type (Def_Id);
11077 end if;
11078
11079 if Rep_Item_Too_Early (Def_Id, N) then
11080 return;
11081 end if;
11082
11083 Def_Id := Underlying_Type (Def_Id);
11084
11085 -- The only processing required is to link this item on to the
11086 -- list of rep items for the given entity. This is accomplished
11087 -- by the call to Rep_Item_Too_Late (when no error is detected
11088 -- and False is returned).
11089
11090 if Rep_Item_Too_Late (Def_Id, N) then
11091 return;
11092 else
0f1a6a0b 11093 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
996ae0b0
RK
11094 end if;
11095 end Machine_Attribute;
11096
11097 ----------
11098 -- Main --
11099 ----------
11100
c690a2ec
RD
11101 -- pragma Main
11102 -- (MAIN_OPTION [, MAIN_OPTION]);
996ae0b0 11103
c690a2ec
RD
11104 -- MAIN_OPTION ::=
11105 -- [STACK_SIZE =>] static_integer_EXPRESSION
11106 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
11107 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
996ae0b0
RK
11108
11109 when Pragma_Main => Main : declare
11110 Args : Args_List (1 .. 3);
fbf5a39b 11111 Names : constant Name_List (1 .. 3) := (
996ae0b0
RK
11112 Name_Stack_Size,
11113 Name_Task_Stack_Size_Default,
11114 Name_Time_Slicing_Enabled);
11115
11116 Nod : Node_Id;
11117
11118 begin
11119 GNAT_Pragma;
11120 Gather_Associations (Names, Args);
11121
11122 for J in 1 .. 2 loop
11123 if Present (Args (J)) then
11124 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11125 end if;
11126 end loop;
11127
11128 if Present (Args (3)) then
11129 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
11130 end if;
11131
11132 Nod := Next (N);
11133 while Present (Nod) loop
11134 if Nkind (Nod) = N_Pragma
1b24ada5 11135 and then Pragma_Name (Nod) = Name_Main
996ae0b0 11136 then
1b24ada5 11137 Error_Msg_Name_1 := Pname;
996ae0b0
RK
11138 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11139 end if;
11140
11141 Next (Nod);
11142 end loop;
11143 end Main;
11144
11145 ------------------
11146 -- Main_Storage --
11147 ------------------
11148
11149 -- pragma Main_Storage
11150 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
11151
11152 -- MAIN_STORAGE_OPTION ::=
11153 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
11154 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
11155
11156 when Pragma_Main_Storage => Main_Storage : declare
11157 Args : Args_List (1 .. 2);
fbf5a39b 11158 Names : constant Name_List (1 .. 2) := (
996ae0b0
RK
11159 Name_Working_Storage,
11160 Name_Top_Guard);
11161
11162 Nod : Node_Id;
11163
11164 begin
11165 GNAT_Pragma;
11166 Gather_Associations (Names, Args);
11167
11168 for J in 1 .. 2 loop
11169 if Present (Args (J)) then
11170 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11171 end if;
11172 end loop;
11173
11174 Check_In_Main_Program;
11175
11176 Nod := Next (N);
11177 while Present (Nod) loop
11178 if Nkind (Nod) = N_Pragma
1b24ada5 11179 and then Pragma_Name (Nod) = Name_Main_Storage
996ae0b0 11180 then
1b24ada5 11181 Error_Msg_Name_1 := Pname;
996ae0b0
RK
11182 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11183 end if;
11184
11185 Next (Nod);
11186 end loop;
996ae0b0
RK
11187 end Main_Storage;
11188
11189 -----------------
11190 -- Memory_Size --
11191 -----------------
11192
11193 -- pragma Memory_Size (NUMERIC_LITERAL)
11194
11195 when Pragma_Memory_Size =>
11196 GNAT_Pragma;
11197
11198 -- Memory size is simply ignored
11199
11200 Check_No_Identifiers;
11201 Check_Arg_Count (1);
11202 Check_Arg_Is_Integer_Literal (Arg1);
11203
2fa9443e
ES
11204 -------------
11205 -- No_Body --
11206 -------------
11207
11208 -- pragma No_Body;
11209
11210 -- The only correct use of this pragma is on its own in a file, in
11211 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
11212 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
11213 -- check for a file containing nothing but a No_Body pragma). If we
11214 -- attempt to process it during normal semantics processing, it means
11215 -- it was misplaced.
11216
11217 when Pragma_No_Body =>
a30a01fe 11218 GNAT_Pragma;
21d27997 11219 Pragma_Misplaced;
2fa9443e 11220
996ae0b0
RK
11221 ---------------
11222 -- No_Return --
11223 ---------------
11224
57193e09 11225 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
996ae0b0 11226
fbf5a39b 11227 when Pragma_No_Return => No_Return : declare
996ae0b0
RK
11228 Id : Node_Id;
11229 E : Entity_Id;
11230 Found : Boolean;
57193e09 11231 Arg : Node_Id;
996ae0b0
RK
11232
11233 begin
1c5c721a 11234 Ada_2005_Pragma;
57193e09 11235 Check_At_Least_N_Arguments (1);
996ae0b0 11236
57193e09 11237 -- Loop through arguments of pragma
996ae0b0 11238
57193e09
TQ
11239 Arg := Arg1;
11240 while Present (Arg) loop
11241 Check_Arg_Is_Local_Name (Arg);
0f1a6a0b 11242 Id := Get_Pragma_Arg (Arg);
57193e09 11243 Analyze (Id);
996ae0b0 11244
57193e09
TQ
11245 if not Is_Entity_Name (Id) then
11246 Error_Pragma_Arg ("entity name required", Arg);
11247 end if;
996ae0b0 11248
57193e09
TQ
11249 if Etype (Id) = Any_Type then
11250 raise Pragma_Exit;
996ae0b0
RK
11251 end if;
11252
57193e09 11253 -- Loop to find matching procedures
996ae0b0 11254
57193e09
TQ
11255 E := Entity (Id);
11256 Found := False;
11257 while Present (E)
11258 and then Scope (E) = Current_Scope
11259 loop
8a95f4e8 11260 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
57193e09 11261 Set_No_Return (E);
470cd9e9
RD
11262
11263 -- Set flag on any alias as well
11264
11265 if Is_Overloadable (E) and then Present (Alias (E)) then
11266 Set_No_Return (Alias (E));
11267 end if;
11268
57193e09
TQ
11269 Found := True;
11270 end if;
11271
0f1a6a0b 11272 exit when From_Aspect_Specification (N);
57193e09
TQ
11273 E := Homonym (E);
11274 end loop;
11275
11276 if not Found then
11277 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11278 end if;
11279
11280 Next (Arg);
11281 end loop;
fbf5a39b
AC
11282 end No_Return;
11283
a30a01fe
RD
11284 -----------------
11285 -- No_Run_Time --
11286 -----------------
11287
11288 -- pragma No_Run_Time;
11289
b3b9865d
AC
11290 -- Note: this pragma is retained for backwards compatibility. See
11291 -- body of Rtsfind for full details on its handling.
a30a01fe
RD
11292
11293 when Pragma_No_Run_Time =>
11294 GNAT_Pragma;
11295 Check_Valid_Configuration_Pragma;
11296 Check_Arg_Count (0);
11297
11298 No_Run_Time_Mode := True;
11299 Configurable_Run_Time_Mode := True;
11300
11301 -- Set Duration to 32 bits if word size is 32
11302
11303 if Ttypes.System_Word_Size = 32 then
11304 Duration_32_Bits_On_Target := True;
11305 end if;
11306
11307 -- Set appropriate restrictions
11308
11309 Set_Restriction (No_Finalization, N);
11310 Set_Restriction (No_Exception_Handlers, N);
11311 Set_Restriction (Max_Tasks, N, 0);
11312 Set_Restriction (No_Tasking, N);
11313
8a6a52dc
AC
11314 ------------------------
11315 -- No_Strict_Aliasing --
11316 ------------------------
11317
6e18b0e5
RD
11318 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11319
a30a01fe 11320 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
8a6a52dc
AC
11321 E_Id : Entity_Id;
11322
11323 begin
11324 GNAT_Pragma;
11325 Check_At_Most_N_Arguments (1);
11326
11327 if Arg_Count = 0 then
11328 Check_Valid_Configuration_Pragma;
11329 Opt.No_Strict_Aliasing := True;
11330
11331 else
11332 Check_Optional_Identifier (Arg2, Name_Entity);
11333 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 11334 E_Id := Entity (Get_Pragma_Arg (Arg1));
8a6a52dc
AC
11335
11336 if E_Id = Any_Type then
11337 return;
11338 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11339 Error_Pragma_Arg ("pragma% requires access type", Arg1);
11340 end if;
11341
e6f69614 11342 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
8a6a52dc 11343 end if;
a30a01fe
RD
11344 end No_Strict_Aliasing;
11345
11346 -----------------------
11347 -- Normalize_Scalars --
11348 -----------------------
11349
11350 -- pragma Normalize_Scalars;
11351
11352 when Pragma_Normalize_Scalars =>
11353 Check_Ada_83_Warning;
11354 Check_Arg_Count (0);
11355 Check_Valid_Configuration_Pragma;
5a989c6b 11356
406935b6 11357 -- Normalize_Scalars creates false positives in CodePeer, and
56812278 11358 -- incorrect negative results in Alfa mode, so ignore this pragma
406935b6 11359 -- in these modes.
5a989c6b 11360
56812278 11361 if not (CodePeer_Mode or Alfa_Mode) then
5a989c6b
AC
11362 Normalize_Scalars := True;
11363 Init_Or_Norm_Scalars := True;
11364 end if;
8a6a52dc 11365
fbf5a39b
AC
11366 -----------------
11367 -- Obsolescent --
11368 -----------------
11369
ed57136d
AC
11370 -- pragma Obsolescent;
11371
11372 -- pragma Obsolescent (
11373 -- [Message =>] static_string_EXPRESSION
11374 -- [,[Version =>] Ada_05]]);
11375
11376 -- pragma Obsolescent (
11377 -- [Entity =>] NAME
11378 -- [,[Message =>] static_string_EXPRESSION
11379 -- [,[Version =>] Ada_05]] );
fbf5a39b
AC
11380
11381 when Pragma_Obsolescent => Obsolescent : declare
ac9e9918
RD
11382 Ename : Node_Id;
11383 Decl : Node_Id;
11384
11385 procedure Set_Obsolescent (E : Entity_Id);
11386 -- Given an entity Ent, mark it as obsolescent if appropriate
82c80734 11387
ac9e9918
RD
11388 ---------------------
11389 -- Set_Obsolescent --
11390 ---------------------
f02b8bb8 11391
ac9e9918
RD
11392 procedure Set_Obsolescent (E : Entity_Id) is
11393 Active : Boolean;
11394 Ent : Entity_Id;
11395 S : String_Id;
f02b8bb8 11396
f02b8bb8 11397 begin
ac9e9918
RD
11398 Active := True;
11399 Ent := E;
11400
11401 -- Entity name was given
11402
11403 if Present (Ename) then
11404
b3b9865d
AC
11405 -- If entity name matches, we are fine. Save entity in
11406 -- pragma argument, for ASIS use.
ac9e9918
RD
11407
11408 if Chars (Ename) = Chars (Ent) then
bb83ec2f
ES
11409 Set_Entity (Ename, Ent);
11410 Generate_Reference (Ent, Ename);
ac9e9918
RD
11411
11412 -- If entity name does not match, only possibility is an
11413 -- enumeration literal from an enumeration type declaration.
11414
11415 elsif Ekind (Ent) /= E_Enumeration_Type then
11416 Error_Pragma
11417 ("pragma % entity name does not match declaration");
11418
11419 else
11420 Ent := First_Literal (E);
11421 loop
11422 if No (Ent) then
11423 Error_Pragma
11424 ("pragma % entity name does not match any " &
11425 "enumeration literal");
11426
11427 elsif Chars (Ent) = Chars (Ename) then
bb83ec2f
ES
11428 Set_Entity (Ename, Ent);
11429 Generate_Reference (Ent, Ename);
ac9e9918
RD
11430 exit;
11431
11432 else
11433 Ent := Next_Literal (Ent);
11434 end if;
11435 end loop;
11436 end if;
f02b8bb8 11437 end if;
ac9e9918
RD
11438
11439 -- Ent points to entity to be marked
11440
11441 if Arg_Count >= 1 then
11442
11443 -- Deal with static string argument
11444
11445 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
0f1a6a0b 11446 S := Strval (Get_Pragma_Arg (Arg1));
ac9e9918
RD
11447
11448 for J in 1 .. String_Length (S) loop
11449 if not In_Character_Range (Get_String_Char (S, J)) then
11450 Error_Pragma_Arg
11451 ("pragma% argument does not allow wide characters",
11452 Arg1);
11453 end if;
11454 end loop;
11455
21d27997 11456 Obsolescent_Warnings.Append
0f1a6a0b 11457 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
ac9e9918
RD
11458
11459 -- Check for Ada_05 parameter
11460
11461 if Arg_Count /= 1 then
11462 Check_Arg_Count (2);
11463
11464 declare
11465 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11466
11467 begin
11468 Check_Arg_Is_Identifier (Argx);
11469
11470 if Chars (Argx) /= Name_Ada_05 then
11471 Error_Msg_Name_2 := Name_Ada_05;
11472 Error_Pragma_Arg
11473 ("only allowed argument for pragma% is %", Argx);
11474 end if;
11475
0791fbe9 11476 if Ada_Version_Explicit < Ada_2005
ac9e9918
RD
11477 or else not Warn_On_Ada_2005_Compatibility
11478 then
11479 Active := False;
11480 end if;
11481 end;
11482 end if;
11483 end if;
11484
11485 -- Set flag if pragma active
11486
11487 if Active then
11488 Set_Is_Obsolescent (Ent);
11489 end if;
11490
11491 return;
11492 end Set_Obsolescent;
f02b8bb8
RD
11493
11494 -- Start of processing for pragma Obsolescent
11495
fbf5a39b
AC
11496 begin
11497 GNAT_Pragma;
fbf5a39b 11498
ac9e9918 11499 Check_At_Most_N_Arguments (3);
fbf5a39b 11500
ac9e9918 11501 -- See if first argument specifies an entity name
82c80734 11502
ac9e9918 11503 if Arg_Count >= 1
ed57136d
AC
11504 and then
11505 (Chars (Arg1) = Name_Entity
11506 or else
11507 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11508 N_Identifier,
11509 N_Operator_Symbol))
ac9e9918
RD
11510 then
11511 Ename := Get_Pragma_Arg (Arg1);
82c80734 11512
ac9e9918 11513 -- Eliminate first argument, so we can share processing
82c80734 11514
ac9e9918
RD
11515 Arg1 := Arg2;
11516 Arg2 := Arg3;
11517 Arg_Count := Arg_Count - 1;
82c80734 11518
ac9e9918 11519 -- No Entity name argument given
82c80734 11520
ac9e9918
RD
11521 else
11522 Ename := Empty;
59e5fbe0 11523 end if;
82c80734 11524
ef7c5692
AC
11525 if Arg_Count >= 1 then
11526 Check_Optional_Identifier (Arg1, Name_Message);
11527
11528 if Arg_Count = 2 then
11529 Check_Optional_Identifier (Arg2, Name_Version);
11530 end if;
11531 end if;
82c80734 11532
ac9e9918 11533 -- Get immediately preceding declaration
59e5fbe0 11534
ac9e9918
RD
11535 Decl := Prev (N);
11536 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11537 Prev (Decl);
11538 end loop;
59e5fbe0 11539
ac9e9918 11540 -- Cases where we do not follow anything other than another pragma
59e5fbe0 11541
ac9e9918 11542 if No (Decl) then
59e5fbe0 11543
ac9e9918
RD
11544 -- First case: library level compilation unit declaration with
11545 -- the pragma immediately following the declaration.
59e5fbe0 11546
ac9e9918
RD
11547 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11548 Set_Obsolescent
11549 (Defining_Entity (Unit (Parent (Parent (N)))));
11550 return;
82c80734 11551
ac9e9918 11552 -- Case 2: library unit placement for package
82c80734 11553
ac9e9918 11554 else
59e5fbe0 11555 declare
ac9e9918 11556 Ent : constant Entity_Id := Find_Lib_Unit_Name;
59e5fbe0 11557 begin
b9b2405f 11558 if Is_Package_Or_Generic_Package (Ent) then
ac9e9918
RD
11559 Set_Obsolescent (Ent);
11560 return;
59e5fbe0
RD
11561 end if;
11562 end;
82c80734 11563 end if;
59e5fbe0 11564
ac9e9918 11565 -- Cases where we must follow a declaration
59e5fbe0 11566
ac9e9918 11567 else
361effb1 11568 if Nkind (Decl) not in N_Declaration
ac9e9918
RD
11569 and then Nkind (Decl) not in N_Later_Decl_Item
11570 and then Nkind (Decl) not in N_Generic_Declaration
f7ca1d04 11571 and then Nkind (Decl) not in N_Renaming_Declaration
ac9e9918
RD
11572 then
11573 Error_Pragma
d7ba4df4
RD
11574 ("pragma% misplaced, "
11575 & "must immediately follow a declaration");
ac9e9918
RD
11576
11577 else
11578 Set_Obsolescent (Defining_Entity (Decl));
11579 return;
11580 end if;
59e5fbe0 11581 end if;
fbf5a39b 11582 end Obsolescent;
996ae0b0 11583
996ae0b0
RK
11584 --------------
11585 -- Optimize --
11586 --------------
11587
1b24ada5 11588 -- pragma Optimize (Time | Space | Off);
996ae0b0
RK
11589
11590 -- The actual check for optimize is done in Gigi. Note that this
11591 -- pragma does not actually change the optimization setting, it
11592 -- simply checks that it is consistent with the pragma.
11593
11594 when Pragma_Optimize =>
11595 Check_No_Identifiers;
11596 Check_Arg_Count (1);
11597 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11598
1b24ada5
RD
11599 ------------------------
11600 -- Optimize_Alignment --
11601 ------------------------
11602
11603 -- pragma Optimize_Alignment (Time | Space | Off);
11604
bd29d519 11605 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
1b24ada5
RD
11606 GNAT_Pragma;
11607 Check_No_Identifiers;
11608 Check_Arg_Count (1);
11609 Check_Valid_Configuration_Pragma;
11610
11611 declare
11612 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11613 begin
11614 case Nam is
11615 when Name_Time =>
11616 Opt.Optimize_Alignment := 'T';
11617 when Name_Space =>
11618 Opt.Optimize_Alignment := 'S';
11619 when Name_Off =>
11620 Opt.Optimize_Alignment := 'O';
11621 when others =>
11622 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11623 end case;
11624 end;
11625
21d27997
RD
11626 -- Set indication that mode is set locally. If we are in fact in a
11627 -- configuration pragma file, this setting is harmless since the
11628 -- switch will get reset anyway at the start of each unit.
11629
11630 Optimize_Alignment_Local := True;
bd29d519
AC
11631 end Optimize_Alignment;
11632
11633 -------------
11634 -- Ordered --
11635 -------------
11636
11637 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11638
11639 when Pragma_Ordered => Ordered : declare
11640 Assoc : constant Node_Id := Arg1;
11641 Type_Id : Node_Id;
11642 Typ : Entity_Id;
11643
11644 begin
11645 GNAT_Pragma;
11646 Check_No_Identifiers;
11647 Check_Arg_Count (1);
11648 Check_Arg_Is_Local_Name (Arg1);
11649
0f1a6a0b 11650 Type_Id := Get_Pragma_Arg (Assoc);
bd29d519
AC
11651 Find_Type (Type_Id);
11652 Typ := Entity (Type_Id);
11653
11654 if Typ = Any_Type then
11655 return;
11656 else
11657 Typ := Underlying_Type (Typ);
11658 end if;
11659
11660 if not Is_Enumeration_Type (Typ) then
11661 Error_Pragma ("pragma% must specify enumeration type");
11662 end if;
11663
11664 Check_First_Subtype (Arg1);
11665 Set_Has_Pragma_Ordered (Base_Type (Typ));
11666 end Ordered;
21d27997 11667
996ae0b0
RK
11668 ----------
11669 -- Pack --
11670 ----------
11671
11672 -- pragma Pack (first_subtype_LOCAL_NAME);
11673
11674 when Pragma_Pack => Pack : declare
fbf5a39b 11675 Assoc : constant Node_Id := Arg1;
996ae0b0
RK
11676 Type_Id : Node_Id;
11677 Typ : Entity_Id;
ffdb3d3b
AC
11678 Ctyp : Entity_Id;
11679 Ignore : Boolean := False;
996ae0b0
RK
11680
11681 begin
11682 Check_No_Identifiers;
11683 Check_Arg_Count (1);
11684 Check_Arg_Is_Local_Name (Arg1);
11685
0f1a6a0b 11686 Type_Id := Get_Pragma_Arg (Assoc);
996ae0b0
RK
11687 Find_Type (Type_Id);
11688 Typ := Entity (Type_Id);
11689
11690 if Typ = Any_Type
11691 or else Rep_Item_Too_Early (Typ, N)
11692 then
11693 return;
11694 else
11695 Typ := Underlying_Type (Typ);
11696 end if;
11697
11698 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11699 Error_Pragma ("pragma% must specify array or record type");
11700 end if;
11701
11702 Check_First_Subtype (Arg1);
0f1a6a0b 11703 Check_Duplicate_Pragma (Typ);
996ae0b0 11704
6e18b0e5 11705 -- Array type
996ae0b0 11706
0f1a6a0b 11707 if Is_Array_Type (Typ) then
ffdb3d3b 11708 Ctyp := Component_Type (Typ);
6e18b0e5 11709
ffdb3d3b 11710 -- Ignore pack that does nothing
6e18b0e5 11711
ffdb3d3b
AC
11712 if Known_Static_Esize (Ctyp)
11713 and then Known_Static_RM_Size (Ctyp)
11714 and then Esize (Ctyp) = RM_Size (Ctyp)
094cefda 11715 and then Addressable (Esize (Ctyp))
ffdb3d3b
AC
11716 then
11717 Ignore := True;
6e18b0e5 11718 end if;
996ae0b0 11719
094cefda
AC
11720 -- Process OK pragma Pack. Note that if there is a separate
11721 -- component clause present, the Pack will be cancelled. This
11722 -- processing is in Freeze.
6e18b0e5 11723
094cefda 11724 if not Rep_Item_Too_Late (Typ, N) then
6e18b0e5 11725
094cefda
AC
11726 -- In the context of static code analysis, we do not need
11727 -- complex front-end expansions related to pragma Pack,
406935b6 11728 -- so disable handling of pragma Pack in these cases.
6e18b0e5 11729
56812278 11730 if CodePeer_Mode or Alfa_Mode then
094cefda 11731 null;
d58b9515 11732
0f1a6a0b
AC
11733 -- Don't attempt any packing for VM targets. We possibly
11734 -- could deal with some cases of array bit-packing, but we
11735 -- don't bother, since this is not a typical kind of
11736 -- representation in the VM context anyway (and would not
11737 -- for example work nicely with the debugger).
11738
11739 elsif VM_Target /= No_VM then
11740 if not GNAT_Mode then
11741 Error_Pragma
11742 ("?pragma% ignored in this configuration");
11743 end if;
ce14c577 11744
0f1a6a0b
AC
11745 -- Normal case where we do the pack action
11746
11747 else
094cefda 11748 if not Ignore then
eaba57fb
RD
11749 Set_Is_Packed (Base_Type (Typ));
11750 Set_Has_Non_Standard_Rep (Base_Type (Typ));
094cefda 11751 end if;
ffdb3d3b 11752
eaba57fb 11753 Set_Has_Pragma_Pack (Base_Type (Typ));
6e18b0e5 11754 end if;
996ae0b0
RK
11755 end if;
11756
6e18b0e5 11757 -- For record types, the pack is always effective
996ae0b0 11758
fbf5a39b 11759 else pragma Assert (Is_Record_Type (Typ));
996ae0b0 11760 if not Rep_Item_Too_Late (Typ, N) then
540b5d9c 11761
0f1a6a0b
AC
11762 -- Ignore pack request with warning in VM mode (skip warning
11763 -- if we are compiling GNAT run time library).
11764
11765 if VM_Target /= No_VM then
11766 if not GNAT_Mode then
11767 Error_Pragma
11768 ("?pragma% ignored in this configuration");
11769 end if;
11770
11771 -- Normal case of pack request active
11772
11773 else
eaba57fb
RD
11774 Set_Is_Packed (Base_Type (Typ));
11775 Set_Has_Pragma_Pack (Base_Type (Typ));
11776 Set_Has_Non_Standard_Rep (Base_Type (Typ));
2fa9443e 11777 end if;
996ae0b0
RK
11778 end if;
11779 end if;
11780 end Pack;
11781
11782 ----------
11783 -- Page --
11784 ----------
11785
11786 -- pragma Page;
11787
b3b9865d
AC
11788 -- There is nothing to do here, since we did all the processing for
11789 -- this pragma in Par.Prag (so that it works properly even in syntax
11790 -- only mode).
996ae0b0
RK
11791
11792 when Pragma_Page =>
11793 null;
11794
11795 -------------
11796 -- Passive --
11797 -------------
11798
11799 -- pragma Passive [(PASSIVE_FORM)];
11800
2b3d67a5 11801 -- PASSIVE_FORM ::= Semaphore | No
996ae0b0
RK
11802
11803 when Pragma_Passive =>
11804 GNAT_Pragma;
11805
11806 if Nkind (Parent (N)) /= N_Task_Definition then
11807 Error_Pragma ("pragma% must be within task definition");
11808 end if;
11809
11810 if Arg_Count /= 0 then
11811 Check_Arg_Count (1);
11812 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11813 end if;
11814
ac9e9918
RD
11815 ----------------------------------
11816 -- Preelaborable_Initialization --
11817 ----------------------------------
11818
11819 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11820
11821 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11822 Ent : Entity_Id;
11823
11824 begin
2fa9443e 11825 Ada_2005_Pragma;
ac9e9918
RD
11826 Check_Arg_Count (1);
11827 Check_No_Identifiers;
11828 Check_Arg_Is_Identifier (Arg1);
11829 Check_Arg_Is_Local_Name (Arg1);
11830 Check_First_Subtype (Arg1);
0f1a6a0b 11831 Ent := Entity (Get_Pragma_Arg (Arg1));
ac9e9918 11832
c3ad80f0
TQ
11833 if not (Is_Private_Type (Ent)
11834 or else
11835 Is_Protected_Type (Ent)
11836 or else
11837 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
470cd9e9 11838 then
ac9e9918 11839 Error_Pragma_Arg
c3ad80f0
TQ
11840 ("pragma % can only be applied to private, formal derived or "
11841 & "protected type",
470cd9e9 11842 Arg1);
ac9e9918
RD
11843 end if;
11844
470cd9e9
RD
11845 -- Give an error if the pragma is applied to a protected type that
11846 -- does not qualify (due to having entries, or due to components
11847 -- that do not qualify).
11848
11849 if Is_Protected_Type (Ent)
11850 and then not Has_Preelaborable_Initialization (Ent)
11851 then
11852 Error_Msg_N
11853 ("protected type & does not have preelaborable " &
11854 "initialization", Ent);
11855
11856 -- Otherwise mark the type as definitely having preelaborable
11857 -- initialization.
11858
11859 else
11860 Set_Known_To_Have_Preelab_Init (Ent);
11861 end if;
c690a2ec
RD
11862
11863 if Has_Pragma_Preelab_Init (Ent)
11864 and then Warn_On_Redundant_Constructs
11865 then
11866 Error_Pragma ("?duplicate pragma%!");
11867 else
11868 Set_Has_Pragma_Preelab_Init (Ent);
11869 end if;
ac9e9918
RD
11870 end Preelab_Init;
11871
59e5fbe0
RD
11872 --------------------
11873 -- Persistent_BSS --
11874 --------------------
fbf5a39b 11875
2b3d67a5
AC
11876 -- pragma Persistent_BSS [(object_NAME)];
11877
59e5fbe0 11878 when Pragma_Persistent_BSS => Persistent_BSS : declare
fbf5a39b
AC
11879 Decl : Node_Id;
11880 Ent : Entity_Id;
59e5fbe0 11881 Prag : Node_Id;
fbf5a39b
AC
11882
11883 begin
11884 GNAT_Pragma;
59e5fbe0 11885 Check_At_Most_N_Arguments (1);
2e071734 11886
59e5fbe0 11887 -- Case of application to specific object (one argument)
fbf5a39b 11888
59e5fbe0
RD
11889 if Arg_Count = 1 then
11890 Check_Arg_Is_Library_Level_Local_Name (Arg1);
fbf5a39b 11891
0f1a6a0b
AC
11892 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11893 or else not
11894 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11895 E_Constant)
59e5fbe0
RD
11896 then
11897 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11898 end if;
fbf5a39b 11899
0f1a6a0b 11900 Ent := Entity (Get_Pragma_Arg (Arg1));
59e5fbe0 11901 Decl := Parent (Ent);
fbf5a39b 11902
59e5fbe0
RD
11903 if Rep_Item_Too_Late (Ent, N) then
11904 return;
11905 end if;
fbf5a39b 11906
59e5fbe0
RD
11907 if Present (Expression (Decl)) then
11908 Error_Pragma_Arg
11909 ("object for pragma% cannot have initialization", Arg1);
11910 end if;
fbf5a39b 11911
59e5fbe0
RD
11912 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11913 Error_Pragma_Arg
11914 ("object type for pragma% is not potentially persistent",
11915 Arg1);
fbf5a39b
AC
11916 end if;
11917
0f1a6a0b
AC
11918 Check_Duplicate_Pragma (Ent);
11919
eaba57fb
RD
11920 Prag :=
11921 Make_Linker_Section_Pragma
11922 (Ent, Sloc (N), ".persistent.bss");
11923 Insert_After (N, Prag);
11924 Analyze (Prag);
59e5fbe0
RD
11925
11926 -- Case of use as configuration pragma with no arguments
11927
11928 else
11929 Check_Valid_Configuration_Pragma;
11930 Persistent_BSS_Mode := True;
11931 end if;
11932 end Persistent_BSS;
fbf5a39b 11933
a30a01fe
RD
11934 -------------
11935 -- Polling --
11936 -------------
11937
11938 -- pragma Polling (ON | OFF);
11939
11940 when Pragma_Polling =>
11941 GNAT_Pragma;
11942 Check_Arg_Count (1);
11943 Check_No_Identifiers;
11944 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
0f1a6a0b 11945 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
a30a01fe 11946
21d27997
RD
11947 -------------------
11948 -- Postcondition --
11949 -------------------
11950
15d8a51d
AC
11951 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
11952 -- [,[Message =>] String_EXPRESSION]);
21d27997
RD
11953
11954 when Pragma_Postcondition => Postcondition : declare
11955 In_Body : Boolean;
11956 pragma Warnings (Off, In_Body);
11957
11958 begin
11959 GNAT_Pragma;
11960 Check_At_Least_N_Arguments (1);
11961 Check_At_Most_N_Arguments (2);
11962 Check_Optional_Identifier (Arg1, Name_Check);
11963
11964 -- All we need to do here is call the common check procedure,
11965 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11966
11967 Check_Precondition_Postcondition (In_Body);
11968 end Postcondition;
11969
11970 ------------------
11971 -- Precondition --
11972 ------------------
11973
15d8a51d
AC
11974 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
11975 -- [,[Message =>] String_EXPRESSION]);
21d27997
RD
11976
11977 when Pragma_Precondition => Precondition : declare
11978 In_Body : Boolean;
11979
11980 begin
11981 GNAT_Pragma;
11982 Check_At_Least_N_Arguments (1);
11983 Check_At_Most_N_Arguments (2);
11984 Check_Optional_Identifier (Arg1, Name_Check);
21d27997
RD
11985 Check_Precondition_Postcondition (In_Body);
11986
fad0600d
AC
11987 -- If in spec, nothing more to do. If in body, then we convert the
11988 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11989 -- this whether or not precondition checks are enabled. That works
3f92c93b
AC
11990 -- fine since pragma Check will do this check, and will also
11991 -- analyze the condition itself in the proper context.
21d27997
RD
11992
11993 if In_Body then
21d27997
RD
11994 Rewrite (N,
11995 Make_Pragma (Loc,
11996 Chars => Name_Check,
11997 Pragma_Argument_Associations => New_List (
11998 Make_Pragma_Argument_Association (Loc,
7675ad4f 11999 Expression => Make_Identifier (Loc, Name_Precondition)),
21d27997
RD
12000
12001 Make_Pragma_Argument_Association (Sloc (Arg1),
12002 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
12003
12004 if Arg_Count = 2 then
12005 Append_To (Pragma_Argument_Associations (N),
12006 Make_Pragma_Argument_Association (Sloc (Arg2),
12007 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
12008 end if;
12009
12010 Analyze (N);
12011 end if;
12012 end Precondition;
12013
fd0ff1cf
RD
12014 ---------------
12015 -- Predicate --
12016 ---------------
12017
12018 -- pragma Predicate
47e11d08
AC
12019 -- ([Entity =>] type_LOCAL_NAME,
12020 -- [Check =>] EXPRESSION);
fd0ff1cf
RD
12021
12022 when Pragma_Predicate => Predicate : declare
12023 Type_Id : Node_Id;
12024 Typ : Entity_Id;
12025
12026 Discard : Boolean;
12027 pragma Unreferenced (Discard);
12028
12029 begin
12030 GNAT_Pragma;
4818e7b9 12031 Check_Arg_Count (2);
fd0ff1cf
RD
12032 Check_Optional_Identifier (Arg1, Name_Entity);
12033 Check_Optional_Identifier (Arg2, Name_Check);
12034
fd0ff1cf
RD
12035 Check_Arg_Is_Local_Name (Arg1);
12036
12037 Type_Id := Get_Pragma_Arg (Arg1);
12038 Find_Type (Type_Id);
12039 Typ := Entity (Type_Id);
12040
12041 if Typ = Any_Type then
12042 return;
12043 end if;
12044
12045 -- The remaining processing is simply to link the pragma on to
12046 -- the rep item chain, for processing when the type is frozen.
4818e7b9
RD
12047 -- This is accomplished by a call to Rep_Item_Too_Late. We also
12048 -- mark the type as having predicates.
fd0ff1cf 12049
4818e7b9 12050 Set_Has_Predicates (Typ);
fd0ff1cf
RD
12051 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12052 end Predicate;
12053
996ae0b0
RK
12054 ------------------
12055 -- Preelaborate --
12056 ------------------
12057
12058 -- pragma Preelaborate [(library_unit_NAME)];
12059
12060 -- Set the flag Is_Preelaborated of program unit name entity
12061
12062 when Pragma_Preelaborate => Preelaborate : declare
fbf5a39b
AC
12063 Pa : constant Node_Id := Parent (N);
12064 Pk : constant Node_Kind := Nkind (Pa);
996ae0b0 12065 Ent : Entity_Id;
996ae0b0
RK
12066
12067 begin
12068 Check_Ada_83_Warning;
12069 Check_Valid_Library_Unit_Pragma;
12070
12071 if Nkind (N) = N_Null_Statement then
12072 return;
12073 end if;
12074
12075 Ent := Find_Lib_Unit_Name;
0f1a6a0b 12076 Check_Duplicate_Pragma (Ent);
996ae0b0
RK
12077
12078 -- This filters out pragmas inside generic parent then
12079 -- show up inside instantiation
12080
12081 if Present (Ent)
12082 and then not (Pk = N_Package_Specification
eaba57fb 12083 and then Present (Generic_Parent (Pa)))
996ae0b0
RK
12084 then
12085 if not Debug_Flag_U then
eaba57fb
RD
12086 Set_Is_Preelaborated (Ent);
12087 Set_Suppress_Elaboration_Warnings (Ent);
996ae0b0
RK
12088 end if;
12089 end if;
12090 end Preelaborate;
12091
59e5fbe0
RD
12092 ---------------------
12093 -- Preelaborate_05 --
12094 ---------------------
12095
12096 -- pragma Preelaborate_05 [(library_unit_NAME)];
12097
12098 -- This pragma is useable only in GNAT_Mode, where it is used like
12099 -- pragma Preelaborate but it is only effective in Ada 2005 mode
12100 -- (otherwise it is ignored). This is used to implement AI-362 which
12101 -- recategorizes some run-time packages in Ada 2005 mode.
12102
12103 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
12104 Ent : Entity_Id;
12105
12106 begin
12107 GNAT_Pragma;
12108 Check_Valid_Library_Unit_Pragma;
12109
12110 if not GNAT_Mode then
12111 Error_Pragma ("pragma% only available in GNAT mode");
12112 end if;
12113
12114 if Nkind (N) = N_Null_Statement then
12115 return;
12116 end if;
12117
12118 -- This is one of the few cases where we need to test the value of
12119 -- Ada_Version_Explicit rather than Ada_Version (which is always
dbe945f1 12120 -- set to Ada_2012 in a predefined unit), we need to know the
59e5fbe0
RD
12121 -- explicit version set to know if this pragma is active.
12122
0791fbe9 12123 if Ada_Version_Explicit >= Ada_2005 then
59e5fbe0
RD
12124 Ent := Find_Lib_Unit_Name;
12125 Set_Is_Preelaborated (Ent);
12126 Set_Suppress_Elaboration_Warnings (Ent);
12127 end if;
12128 end Preelaborate_05;
12129
996ae0b0
RK
12130 --------------
12131 -- Priority --
12132 --------------
12133
12134 -- pragma Priority (EXPRESSION);
12135
12136 when Pragma_Priority => Priority : declare
12137 P : constant Node_Id := Parent (N);
12138 Arg : Node_Id;
12139
12140 begin
12141 Check_No_Identifiers;
12142 Check_Arg_Count (1);
12143
996ae0b0
RK
12144 -- Subprogram case
12145
12146 if Nkind (P) = N_Subprogram_Body then
12147 Check_In_Main_Program;
12148
0f1a6a0b 12149 Arg := Get_Pragma_Arg (Arg1);
fbf5a39b
AC
12150 Analyze_And_Resolve (Arg, Standard_Integer);
12151
996ae0b0
RK
12152 -- Must be static
12153
12154 if not Is_Static_Expression (Arg) then
fbf5a39b
AC
12155 Flag_Non_Static_Expr
12156 ("main subprogram priority is not static!", Arg);
12157 raise Pragma_Exit;
996ae0b0
RK
12158
12159 -- If constraint error, then we already signalled an error
12160
12161 elsif Raises_Constraint_Error (Arg) then
12162 null;
12163
12164 -- Otherwise check in range
12165
12166 else
12167 declare
12168 Val : constant Uint := Expr_Value (Arg);
12169
12170 begin
12171 if Val < 0
12172 or else Val > Expr_Value (Expression
12173 (Parent (RTE (RE_Max_Priority))))
12174 then
12175 Error_Pragma_Arg
12176 ("main subprogram priority is out of range", Arg1);
12177 end if;
12178 end;
12179 end if;
12180
12181 Set_Main_Priority
874a0341
RD
12182 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12183
12184 -- Load an arbitrary entity from System.Tasking to make sure
12185 -- this package is implicitly with'ed, since we need to have
12186 -- the tasking run-time active for the pragma Priority to have
12187 -- any effect.
12188
12189 declare
12190 Discard : Entity_Id;
12191 pragma Warnings (Off, Discard);
12192 begin
12193 Discard := RTE (RE_Task_List);
12194 end;
996ae0b0
RK
12195
12196 -- Task or Protected, must be of type Integer
12197
d7ba4df4 12198 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
0f1a6a0b 12199 Arg := Get_Pragma_Arg (Arg1);
fbf5a39b
AC
12200
12201 -- The expression must be analyzed in the special manner
12202 -- described in "Handling of Default and Per-Object
12203 -- Expressions" in sem.ads.
12204
21d27997 12205 Preanalyze_Spec_Expression (Arg, Standard_Integer);
fbf5a39b
AC
12206
12207 if not Is_Static_Expression (Arg) then
12208 Check_Restriction (Static_Priorities, Arg);
996ae0b0
RK
12209 end if;
12210
12211 -- Anything else is incorrect
12212
12213 else
12214 Pragma_Misplaced;
12215 end if;
12216
c775c209 12217 if Has_Pragma_Priority (P) then
996ae0b0
RK
12218 Error_Pragma ("duplicate pragma% not allowed");
12219 else
c775c209 12220 Set_Has_Pragma_Priority (P, True);
996ae0b0 12221
d7ba4df4 12222 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
996ae0b0
RK
12223 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12224 -- exp_ch9 should use this ???
12225 end if;
12226 end if;
996ae0b0
RK
12227 end Priority;
12228
ac9e9918
RD
12229 -----------------------------------
12230 -- Priority_Specific_Dispatching --
12231 -----------------------------------
12232
12233 -- pragma Priority_Specific_Dispatching (
12234 -- policy_IDENTIFIER,
12235 -- first_priority_EXPRESSION,
12236 -- last_priority_EXPRESSION);
12237
12238 when Pragma_Priority_Specific_Dispatching =>
12239 Priority_Specific_Dispatching : declare
12240 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
12241 -- This is the entity System.Any_Priority;
12242
12243 DP : Character;
12244 Lower_Bound : Node_Id;
12245 Upper_Bound : Node_Id;
12246 Lower_Val : Uint;
12247 Upper_Val : Uint;
12248
12249 begin
2fa9443e 12250 Ada_2005_Pragma;
ac9e9918
RD
12251 Check_Arg_Count (3);
12252 Check_No_Identifiers;
12253 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12254 Check_Valid_Configuration_Pragma;
0f1a6a0b 12255 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
ac9e9918
RD
12256 DP := Fold_Upper (Name_Buffer (1));
12257
0f1a6a0b 12258 Lower_Bound := Get_Pragma_Arg (Arg2);
ac9e9918
RD
12259 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
12260 Lower_Val := Expr_Value (Lower_Bound);
12261
0f1a6a0b 12262 Upper_Bound := Get_Pragma_Arg (Arg3);
ac9e9918
RD
12263 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
12264 Upper_Val := Expr_Value (Upper_Bound);
12265
12266 -- It is not allowed to use Task_Dispatching_Policy and
12267 -- Priority_Specific_Dispatching in the same partition.
12268
12269 if Task_Dispatching_Policy /= ' ' then
12270 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12271 Error_Pragma
12272 ("pragma% incompatible with Task_Dispatching_Policy#");
12273
12274 -- Check lower bound in range
12275
12276 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12277 or else
12278 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
12279 then
12280 Error_Pragma_Arg
12281 ("first_priority is out of range", Arg2);
12282
12283 -- Check upper bound in range
12284
12285 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12286 or else
12287 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
12288 then
12289 Error_Pragma_Arg
12290 ("last_priority is out of range", Arg3);
12291
12292 -- Check that the priority range is valid
12293
12294 elsif Lower_Val > Upper_Val then
12295 Error_Pragma
12296 ("last_priority_expression must be greater than" &
12297 " or equal to first_priority_expression");
12298
12299 -- Store the new policy, but always preserve System_Location since
12300 -- we like the error message with the run-time name.
12301
12302 else
12303 -- Check overlapping in the priority ranges specified in other
12304 -- Priority_Specific_Dispatching pragmas within the same
12305 -- partition. We can only check those we know about!
12306
12307 for J in
12308 Specific_Dispatching.First .. Specific_Dispatching.Last
12309 loop
12310 if Specific_Dispatching.Table (J).First_Priority in
12311 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12312 or else Specific_Dispatching.Table (J).Last_Priority in
12313 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12314 then
12315 Error_Msg_Sloc :=
12316 Specific_Dispatching.Table (J).Pragma_Loc;
c690a2ec
RD
12317 Error_Pragma
12318 ("priority range overlaps with "
12319 & "Priority_Specific_Dispatching#");
ac9e9918
RD
12320 end if;
12321 end loop;
12322
12323 -- The use of Priority_Specific_Dispatching is incompatible
12324 -- with Task_Dispatching_Policy.
12325
12326 if Task_Dispatching_Policy /= ' ' then
12327 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
c690a2ec
RD
12328 Error_Pragma
12329 ("Priority_Specific_Dispatching incompatible "
12330 & "with Task_Dispatching_Policy#");
ac9e9918
RD
12331 end if;
12332
12333 -- The use of Priority_Specific_Dispatching forces ceiling
12334 -- locking policy.
12335
12336 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
12337 Error_Msg_Sloc := Locking_Policy_Sloc;
c690a2ec
RD
12338 Error_Pragma
12339 ("Priority_Specific_Dispatching incompatible "
12340 & "with Locking_Policy#");
ac9e9918
RD
12341
12342 -- Set the Ceiling_Locking policy, but preserve System_Location
12343 -- since we like the error message with the run time name.
12344
12345 else
12346 Locking_Policy := 'C';
12347
12348 if Locking_Policy_Sloc /= System_Location then
12349 Locking_Policy_Sloc := Loc;
12350 end if;
12351 end if;
12352
12353 -- Add entry in the table
12354
12355 Specific_Dispatching.Append
12356 ((Dispatching_Policy => DP,
12357 First_Priority => UI_To_Int (Lower_Val),
12358 Last_Priority => UI_To_Int (Upper_Val),
12359 Pragma_Loc => Loc));
12360 end if;
12361 end Priority_Specific_Dispatching;
12362
2e071734
AC
12363 -------------
12364 -- Profile --
12365 -------------
12366
12367 -- pragma Profile (profile_IDENTIFIER);
12368
21d27997 12369 -- profile_IDENTIFIER => Restricted | Ravenscar
2e071734
AC
12370
12371 when Pragma_Profile =>
2fa9443e 12372 Ada_2005_Pragma;
2e071734
AC
12373 Check_Arg_Count (1);
12374 Check_Valid_Configuration_Pragma;
12375 Check_No_Identifiers;
2e071734
AC
12376
12377 declare
12378 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
df177175 12379
2e071734
AC
12380 begin
12381 if Chars (Argx) = Name_Ravenscar then
8a36a0cc 12382 Set_Ravenscar_Profile (N);
df177175 12383
cc335f43 12384 elsif Chars (Argx) = Name_Restricted then
23e6615e 12385 Set_Profile_Restrictions
df177175
RD
12386 (Restricted,
12387 N, Warn => Treat_Restrictions_As_Warnings);
12388
12389 elsif Chars (Argx) = Name_No_Implementation_Extensions then
12390 Set_Profile_Restrictions
12391 (No_Implementation_Extensions,
12392 N, Warn => Treat_Restrictions_As_Warnings);
12393
cc335f43
AC
12394 else
12395 Error_Pragma_Arg ("& is not a valid profile", Argx);
12396 end if;
12397 end;
12398
12399 ----------------------
12400 -- Profile_Warnings --
12401 ----------------------
12402
12403 -- pragma Profile_Warnings (profile_IDENTIFIER);
12404
21d27997 12405 -- profile_IDENTIFIER => Restricted | Ravenscar
cc335f43
AC
12406
12407 when Pragma_Profile_Warnings =>
12408 GNAT_Pragma;
12409 Check_Arg_Count (1);
12410 Check_Valid_Configuration_Pragma;
12411 Check_No_Identifiers;
12412
12413 declare
12414 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
df177175 12415
cc335f43
AC
12416 begin
12417 if Chars (Argx) = Name_Ravenscar then
12418 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
df177175 12419
cc335f43
AC
12420 elsif Chars (Argx) = Name_Restricted then
12421 Set_Profile_Restrictions (Restricted, N, Warn => True);
df177175
RD
12422
12423 elsif Chars (Argx) = Name_No_Implementation_Extensions then
12424 Set_Profile_Restrictions
12425 (No_Implementation_Extensions, N, Warn => True);
12426
2e071734
AC
12427 else
12428 Error_Pragma_Arg ("& is not a valid profile", Argx);
12429 end if;
12430 end;
12431
996ae0b0
RK
12432 --------------------------
12433 -- Propagate_Exceptions --
12434 --------------------------
12435
12436 -- pragma Propagate_Exceptions;
12437
57193e09
TQ
12438 -- Note: this pragma is obsolete and has no effect
12439
996ae0b0
RK
12440 when Pragma_Propagate_Exceptions =>
12441 GNAT_Pragma;
12442 Check_Arg_Count (0);
12443
12444 if In_Extended_Main_Source_Unit (N) then
12445 Propagate_Exceptions := True;
12446 end if;
12447
12448 ------------------
12449 -- Psect_Object --
12450 ------------------
12451
12452 -- pragma Psect_Object (
12453 -- [Internal =>] LOCAL_NAME,
12454 -- [, [External =>] EXTERNAL_SYMBOL]
12455 -- [, [Size =>] EXTERNAL_SYMBOL]);
12456
12457 when Pragma_Psect_Object | Pragma_Common_Object =>
12458 Psect_Object : declare
12459 Args : Args_List (1 .. 3);
fbf5a39b 12460 Names : constant Name_List (1 .. 3) := (
996ae0b0
RK
12461 Name_Internal,
12462 Name_External,
12463 Name_Size);
12464
12465 Internal : Node_Id renames Args (1);
12466 External : Node_Id renames Args (2);
12467 Size : Node_Id renames Args (3);
12468
1d571f3b 12469 Def_Id : Entity_Id;
996ae0b0
RK
12470
12471 procedure Check_Too_Long (Arg : Node_Id);
12472 -- Posts message if the argument is an identifier with more
12473 -- than 31 characters, or a string literal with more than
12474 -- 31 characters, and we are operating under VMS
12475
07fc65c4
GB
12476 --------------------
12477 -- Check_Too_Long --
12478 --------------------
12479
996ae0b0 12480 procedure Check_Too_Long (Arg : Node_Id) is
fbf5a39b 12481 X : constant Node_Id := Original_Node (Arg);
996ae0b0
RK
12482
12483 begin
d7ba4df4 12484 if not Nkind_In (X, N_String_Literal, N_Identifier) then
996ae0b0
RK
12485 Error_Pragma_Arg
12486 ("inappropriate argument for pragma %", Arg);
12487 end if;
12488
12489 if OpenVMS_On_Target then
12490 if (Nkind (X) = N_String_Literal
12491 and then String_Length (Strval (X)) > 31)
12492 or else
12493 (Nkind (X) = N_Identifier
12494 and then Length_Of_Name (Chars (X)) > 31)
12495 then
12496 Error_Pragma_Arg
12497 ("argument for pragma % is longer than 31 characters",
12498 Arg);
12499 end if;
12500 end if;
12501 end Check_Too_Long;
12502
12503 -- Start of processing for Common_Object/Psect_Object
12504
12505 begin
12506 GNAT_Pragma;
12507 Gather_Associations (Names, Args);
12508 Process_Extended_Import_Export_Internal_Arg (Internal);
12509
1d571f3b 12510 Def_Id := Entity (Internal);
996ae0b0 12511
8a95f4e8 12512 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
996ae0b0
RK
12513 Error_Pragma_Arg
12514 ("pragma% must designate an object", Internal);
12515 end if;
12516
1d571f3b 12517 Check_Too_Long (Internal);
996ae0b0
RK
12518
12519 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
ed2233dc 12520 Error_Pragma_Arg
996ae0b0 12521 ("cannot use pragma% for imported/exported object",
1d571f3b 12522 Internal);
996ae0b0
RK
12523 end if;
12524
1d571f3b 12525 if Is_Concurrent_Type (Etype (Internal)) then
ed2233dc 12526 Error_Pragma_Arg
996ae0b0 12527 ("cannot specify pragma % for task/protected object",
1d571f3b 12528 Internal);
996ae0b0
RK
12529 end if;
12530
1d571f3b
AC
12531 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12532 or else
12533 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12534 then
12535 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
996ae0b0
RK
12536 end if;
12537
12538 if Ekind (Def_Id) = E_Constant then
ed2233dc 12539 Error_Pragma_Arg
1d571f3b 12540 ("cannot specify pragma % for a constant", Internal);
996ae0b0
RK
12541 end if;
12542
1d571f3b 12543 if Is_Record_Type (Etype (Internal)) then
996ae0b0
RK
12544 declare
12545 Ent : Entity_Id;
12546 Decl : Entity_Id;
12547
12548 begin
1d571f3b 12549 Ent := First_Entity (Etype (Internal));
996ae0b0
RK
12550 while Present (Ent) loop
12551 Decl := Declaration_Node (Ent);
12552
12553 if Ekind (Ent) = E_Component
12554 and then Nkind (Decl) = N_Component_Declaration
12555 and then Present (Expression (Decl))
fbf5a39b 12556 and then Warn_On_Export_Import
996ae0b0
RK
12557 then
12558 Error_Msg_N
1d571f3b 12559 ("?object for pragma % has defaults", Internal);
996ae0b0
RK
12560 exit;
12561
12562 else
12563 Next_Entity (Ent);
12564 end if;
12565 end loop;
12566 end;
12567 end if;
12568
12569 if Present (Size) then
12570 Check_Too_Long (Size);
12571 end if;
12572
996ae0b0 12573 if Present (External) then
5f3ab6fb 12574 Check_Arg_Is_External_Name (External);
996ae0b0 12575 Check_Too_Long (External);
996ae0b0
RK
12576 end if;
12577
1d571f3b 12578 -- If all error tests pass, link pragma on to the rep item chain
fbf5a39b 12579
1d571f3b 12580 Record_Rep_Item (Def_Id, N);
996ae0b0
RK
12581 end Psect_Object;
12582
12583 ----------
12584 -- Pure --
12585 ----------
12586
12587 -- pragma Pure [(library_unit_NAME)];
12588
12589 when Pragma_Pure => Pure : declare
12590 Ent : Entity_Id;
59e5fbe0 12591
996ae0b0
RK
12592 begin
12593 Check_Ada_83_Warning;
12594 Check_Valid_Library_Unit_Pragma;
12595
12596 if Nkind (N) = N_Null_Statement then
12597 return;
12598 end if;
12599
12600 Ent := Find_Lib_Unit_Name;
12601 Set_Is_Pure (Ent);
57193e09 12602 Set_Has_Pragma_Pure (Ent);
996ae0b0
RK
12603 Set_Suppress_Elaboration_Warnings (Ent);
12604 end Pure;
12605
59e5fbe0
RD
12606 -------------
12607 -- Pure_05 --
12608 -------------
12609
12610 -- pragma Pure_05 [(library_unit_NAME)];
12611
12612 -- This pragma is useable only in GNAT_Mode, where it is used like
12613 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
12614 -- it is ignored). It may be used after a pragma Preelaborate, in
12615 -- which case it overrides the effect of the pragma Preelaborate.
12616 -- This is used to implement AI-362 which recategorizes some run-time
12617 -- packages in Ada 2005 mode.
12618
12619 when Pragma_Pure_05 => Pure_05 : declare
12620 Ent : Entity_Id;
12621
12622 begin
12623 GNAT_Pragma;
12624 Check_Valid_Library_Unit_Pragma;
12625
12626 if not GNAT_Mode then
12627 Error_Pragma ("pragma% only available in GNAT mode");
12628 end if;
d7ba4df4 12629
59e5fbe0
RD
12630 if Nkind (N) = N_Null_Statement then
12631 return;
12632 end if;
12633
12634 -- This is one of the few cases where we need to test the value of
12635 -- Ada_Version_Explicit rather than Ada_Version (which is always
dbe945f1 12636 -- set to Ada_2012 in a predefined unit), we need to know the
59e5fbe0
RD
12637 -- explicit version set to know if this pragma is active.
12638
0791fbe9 12639 if Ada_Version_Explicit >= Ada_2005 then
59e5fbe0
RD
12640 Ent := Find_Lib_Unit_Name;
12641 Set_Is_Preelaborated (Ent, False);
12642 Set_Is_Pure (Ent);
12643 Set_Suppress_Elaboration_Warnings (Ent);
12644 end if;
12645 end Pure_05;
12646
996ae0b0
RK
12647 -------------------
12648 -- Pure_Function --
12649 -------------------
12650
12651 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12652
12653 when Pragma_Pure_Function => Pure_Function : declare
6e937c1c
AC
12654 E_Id : Node_Id;
12655 E : Entity_Id;
12656 Def_Id : Entity_Id;
12657 Effective : Boolean := False;
996ae0b0
RK
12658
12659 begin
12660 GNAT_Pragma;
12661 Check_Arg_Count (1);
12662 Check_Optional_Identifier (Arg1, Name_Entity);
12663 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 12664 E_Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
12665
12666 if Error_Posted (E_Id) then
12667 return;
12668 end if;
12669
12670 -- Loop through homonyms (overloadings) of referenced entity
12671
12672 E := Entity (E_Id);
996ae0b0 12673
fbf5a39b
AC
12674 if Present (E) then
12675 loop
12676 Def_Id := Get_Base_Subprogram (E);
996ae0b0 12677
8a95f4e8
RD
12678 if not Ekind_In (Def_Id, E_Function,
12679 E_Generic_Function,
12680 E_Operator)
fbf5a39b
AC
12681 then
12682 Error_Pragma_Arg
12683 ("pragma% requires a function name", Arg1);
12684 end if;
12685
eaba57fb 12686 Set_Is_Pure (Def_Id);
6e937c1c
AC
12687
12688 if not Has_Pragma_Pure_Function (Def_Id) then
eaba57fb
RD
12689 Set_Has_Pragma_Pure_Function (Def_Id);
12690 Effective := True;
6e937c1c 12691 end if;
fbf5a39b 12692
0f1a6a0b 12693 exit when From_Aspect_Specification (N);
fbf5a39b
AC
12694 E := Homonym (E);
12695 exit when No (E) or else Scope (E) /= Current_Scope;
12696 end loop;
6e937c1c 12697
eaba57fb 12698 if not Effective
6e937c1c
AC
12699 and then Warn_On_Redundant_Constructs
12700 then
ed2233dc 12701 Error_Msg_NE
19d846a0
RD
12702 ("pragma Pure_Function on& is redundant?",
12703 N, Entity (E_Id));
6e937c1c 12704 end if;
fbf5a39b 12705 end if;
996ae0b0
RK
12706 end Pure_Function;
12707
12708 --------------------
12709 -- Queuing_Policy --
12710 --------------------
12711
12712 -- pragma Queuing_Policy (policy_IDENTIFIER);
12713
12714 when Pragma_Queuing_Policy => declare
12715 QP : Character;
12716
12717 begin
12718 Check_Ada_83_Warning;
12719 Check_Arg_Count (1);
12720 Check_No_Identifiers;
12721 Check_Arg_Is_Queuing_Policy (Arg1);
12722 Check_Valid_Configuration_Pragma;
0f1a6a0b 12723 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
996ae0b0
RK
12724 QP := Fold_Upper (Name_Buffer (1));
12725
12726 if Queuing_Policy /= ' '
12727 and then Queuing_Policy /= QP
12728 then
12729 Error_Msg_Sloc := Queuing_Policy_Sloc;
12730 Error_Pragma ("queuing policy incompatible with policy#");
fbf5a39b 12731
b3b9865d
AC
12732 -- Set new policy, but always preserve System_Location since we
12733 -- like the error message with the run time name.
fbf5a39b 12734
996ae0b0
RK
12735 else
12736 Queuing_Policy := QP;
fbf5a39b
AC
12737
12738 if Queuing_Policy_Sloc /= System_Location then
12739 Queuing_Policy_Sloc := Loc;
12740 end if;
996ae0b0
RK
12741 end if;
12742 end;
12743
21d27997
RD
12744 -----------------------
12745 -- Relative_Deadline --
12746 -----------------------
12747
12748 -- pragma Relative_Deadline (time_span_EXPRESSION);
12749
12750 when Pragma_Relative_Deadline => Relative_Deadline : declare
12751 P : constant Node_Id := Parent (N);
12752 Arg : Node_Id;
12753
12754 begin
12755 Ada_2005_Pragma;
12756 Check_No_Identifiers;
12757 Check_Arg_Count (1);
12758
0f1a6a0b 12759 Arg := Get_Pragma_Arg (Arg1);
21d27997
RD
12760
12761 -- The expression must be analyzed in the special manner described
12762 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12763
12764 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12765
12766 -- Subprogram case
12767
12768 if Nkind (P) = N_Subprogram_Body then
12769 Check_In_Main_Program;
12770
12771 -- Tasks
12772
12773 elsif Nkind (P) = N_Task_Definition then
12774 null;
12775
12776 -- Anything else is incorrect
12777
12778 else
12779 Pragma_Misplaced;
12780 end if;
12781
12782 if Has_Relative_Deadline_Pragma (P) then
12783 Error_Pragma ("duplicate pragma% not allowed");
12784 else
12785 Set_Has_Relative_Deadline_Pragma (P, True);
12786
12787 if Nkind (P) = N_Task_Definition then
12788 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12789 end if;
12790 end if;
12791 end Relative_Deadline;
12792
996ae0b0
RK
12793 ---------------------------
12794 -- Remote_Call_Interface --
12795 ---------------------------
12796
12797 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12798
12799 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12800 Cunit_Node : Node_Id;
12801 Cunit_Ent : Entity_Id;
12802 K : Node_Kind;
12803
12804 begin
12805 Check_Ada_83_Warning;
12806 Check_Valid_Library_Unit_Pragma;
12807
12808 if Nkind (N) = N_Null_Statement then
12809 return;
12810 end if;
12811
12812 Cunit_Node := Cunit (Current_Sem_Unit);
12813 K := Nkind (Unit (Cunit_Node));
12814 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12815
12816 if K = N_Package_Declaration
12817 or else K = N_Generic_Package_Declaration
12818 or else K = N_Subprogram_Declaration
12819 or else K = N_Generic_Subprogram_Declaration
12820 or else (K = N_Subprogram_Body
12821 and then Acts_As_Spec (Unit (Cunit_Node)))
12822 then
12823 null;
12824 else
12825 Error_Pragma (
12826 "pragma% must apply to package or subprogram declaration");
12827 end if;
12828
12829 Set_Is_Remote_Call_Interface (Cunit_Ent);
12830 end Remote_Call_Interface;
12831
12832 ------------------
12833 -- Remote_Types --
12834 ------------------
12835
12836 -- pragma Remote_Types [(library_unit_NAME)];
12837
12838 when Pragma_Remote_Types => Remote_Types : declare
12839 Cunit_Node : Node_Id;
12840 Cunit_Ent : Entity_Id;
12841
12842 begin
12843 Check_Ada_83_Warning;
12844 Check_Valid_Library_Unit_Pragma;
12845
12846 if Nkind (N) = N_Null_Statement then
12847 return;
12848 end if;
12849
12850 Cunit_Node := Cunit (Current_Sem_Unit);
12851 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12852
d7ba4df4
RD
12853 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12854 N_Generic_Package_Declaration)
996ae0b0 12855 then
d7ba4df4
RD
12856 Error_Pragma
12857 ("pragma% can only apply to a package declaration");
996ae0b0
RK
12858 end if;
12859
12860 Set_Is_Remote_Types (Cunit_Ent);
12861 end Remote_Types;
12862
12863 ---------------
12864 -- Ravenscar --
12865 ---------------
12866
fbf5a39b
AC
12867 -- pragma Ravenscar;
12868
996ae0b0
RK
12869 when Pragma_Ravenscar =>
12870 GNAT_Pragma;
12871 Check_Arg_Count (0);
12872 Check_Valid_Configuration_Pragma;
8a36a0cc 12873 Set_Ravenscar_Profile (N);
996ae0b0 12874
cc335f43 12875 if Warn_On_Obsolescent_Feature then
ed2233dc
AC
12876 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12877 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
cc335f43
AC
12878 end if;
12879
996ae0b0
RK
12880 -------------------------
12881 -- Restricted_Run_Time --
12882 -------------------------
12883
fbf5a39b
AC
12884 -- pragma Restricted_Run_Time;
12885
996ae0b0
RK
12886 when Pragma_Restricted_Run_Time =>
12887 GNAT_Pragma;
12888 Check_Arg_Count (0);
12889 Check_Valid_Configuration_Pragma;
23e6615e
RD
12890 Set_Profile_Restrictions
12891 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
cc335f43
AC
12892
12893 if Warn_On_Obsolescent_Feature then
ed2233dc 12894 Error_Msg_N
cc335f43 12895 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
ed2233dc 12896 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
cc335f43 12897 end if;
996ae0b0
RK
12898
12899 ------------------
12900 -- Restrictions --
12901 ------------------
12902
12903 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12904
12905 -- RESTRICTION ::=
12906 -- restriction_IDENTIFIER
12907 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12908
6e937c1c 12909 when Pragma_Restrictions =>
23e6615e
RD
12910 Process_Restrictions_Or_Restriction_Warnings
12911 (Warn => Treat_Restrictions_As_Warnings);
996ae0b0 12912
fbf5a39b
AC
12913 --------------------------
12914 -- Restriction_Warnings --
12915 --------------------------
12916
12917 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12918
6e937c1c
AC
12919 -- RESTRICTION ::=
12920 -- restriction_IDENTIFIER
12921 -- | restriction_parameter_IDENTIFIER => EXPRESSION
fbf5a39b 12922
6e937c1c 12923 when Pragma_Restriction_Warnings =>
21d27997 12924 GNAT_Pragma;
ac9e9918 12925 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
fbf5a39b 12926
996ae0b0
RK
12927 ----------------
12928 -- Reviewable --
12929 ----------------
12930
12931 -- pragma Reviewable;
12932
12933 when Pragma_Reviewable =>
12934 Check_Ada_83_Warning;
12935 Check_Arg_Count (0);
6a2afd13
AC
12936
12937 -- Call dummy debugging function rv. This is done to assist front
12938 -- end debugging. By placing a Reviewable pragma in the source
12939 -- program, a breakpoint on rv catches this place in the source,
12940 -- allowing convenient stepping to the point of interest.
12941
2fa9443e 12942 rv;
996ae0b0 12943
6a2afd13
AC
12944 --------------------------
12945 -- Short_Circuit_And_Or --
12946 --------------------------
12947
12948 when Pragma_Short_Circuit_And_Or =>
12949 GNAT_Pragma;
12950 Check_Arg_Count (0);
12951 Check_Valid_Configuration_Pragma;
12952 Short_Circuit_And_Or := True;
12953
996ae0b0
RK
12954 -------------------
12955 -- Share_Generic --
12956 -------------------
12957
12958 -- pragma Share_Generic (NAME {, NAME});
12959
12960 when Pragma_Share_Generic =>
12961 GNAT_Pragma;
12962 Process_Generic_List;
12963
12964 ------------
12965 -- Shared --
12966 ------------
12967
12968 -- pragma Shared (LOCAL_NAME);
12969
12970 when Pragma_Shared =>
07fc65c4 12971 GNAT_Pragma;
996ae0b0
RK
12972 Process_Atomic_Shared_Volatile;
12973
12974 --------------------
12975 -- Shared_Passive --
12976 --------------------
12977
12978 -- pragma Shared_Passive [(library_unit_NAME)];
12979
12980 -- Set the flag Is_Shared_Passive of program unit name entity
12981
12982 when Pragma_Shared_Passive => Shared_Passive : declare
12983 Cunit_Node : Node_Id;
12984 Cunit_Ent : Entity_Id;
12985
12986 begin
12987 Check_Ada_83_Warning;
12988 Check_Valid_Library_Unit_Pragma;
12989
12990 if Nkind (N) = N_Null_Statement then
12991 return;
12992 end if;
12993
12994 Cunit_Node := Cunit (Current_Sem_Unit);
12995 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12996
d7ba4df4
RD
12997 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12998 N_Generic_Package_Declaration)
996ae0b0 12999 then
d7ba4df4
RD
13000 Error_Pragma
13001 ("pragma% can only apply to a package declaration");
996ae0b0
RK
13002 end if;
13003
13004 Set_Is_Shared_Passive (Cunit_Ent);
13005 end Shared_Passive;
13006
292beb8f
AC
13007 -----------------------
13008 -- Short_Descriptors --
13009 -----------------------
13010
13011 -- pragma Short_Descriptors;
13012
13013 when Pragma_Short_Descriptors =>
13014 GNAT_Pragma;
13015 Check_Arg_Count (0);
13016 Check_Valid_Configuration_Pragma;
13017 Short_Descriptors := True;
13018
996ae0b0
RK
13019 ----------------------
13020 -- Source_File_Name --
13021 ----------------------
13022
2820d220
AC
13023 -- There are five forms for this pragma:
13024
13025 -- pragma Source_File_Name (
13026 -- [UNIT_NAME =>] unit_NAME,
13027 -- BODY_FILE_NAME => STRING_LITERAL
13028 -- [, [INDEX =>] INTEGER_LITERAL]);
13029
996ae0b0 13030 -- pragma Source_File_Name (
2820d220
AC
13031 -- [UNIT_NAME =>] unit_NAME,
13032 -- SPEC_FILE_NAME => STRING_LITERAL
13033 -- [, [INDEX =>] INTEGER_LITERAL]);
13034
13035 -- pragma Source_File_Name (
13036 -- BODY_FILE_NAME => STRING_LITERAL
13037 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13038 -- [, CASING => CASING_SPEC]);
13039
13040 -- pragma Source_File_Name (
13041 -- SPEC_FILE_NAME => STRING_LITERAL
13042 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13043 -- [, CASING => CASING_SPEC]);
13044
13045 -- pragma Source_File_Name (
13046 -- SUBUNIT_FILE_NAME => STRING_LITERAL
13047 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13048 -- [, CASING => CASING_SPEC]);
13049
13050 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
13051
13052 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
b3b9865d
AC
13053 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
13054 -- only be used when no project file is used, while SFNP can only be
13055 -- used when a project file is used.
996ae0b0 13056
b3b9865d
AC
13057 -- No processing here. Processing was completed during parsing, since
13058 -- we need to have file names set as early as possible. Units are
13059 -- loaded well before semantic processing starts.
996ae0b0 13060
b3b9865d
AC
13061 -- The only processing we defer to this point is the check for
13062 -- correct placement.
996ae0b0
RK
13063
13064 when Pragma_Source_File_Name =>
13065 GNAT_Pragma;
13066 Check_Valid_Configuration_Pragma;
13067
fbf5a39b
AC
13068 ------------------------------
13069 -- Source_File_Name_Project --
13070 ------------------------------
13071
2820d220 13072 -- See Source_File_Name for syntax
fbf5a39b 13073
b3b9865d
AC
13074 -- No processing here. Processing was completed during parsing, since
13075 -- we need to have file names set as early as possible. Units are
13076 -- loaded well before semantic processing starts.
fbf5a39b 13077
b3b9865d
AC
13078 -- The only processing we defer to this point is the check for
13079 -- correct placement.
fbf5a39b
AC
13080
13081 when Pragma_Source_File_Name_Project =>
13082 GNAT_Pragma;
13083 Check_Valid_Configuration_Pragma;
13084
b3b9865d
AC
13085 -- Check that a pragma Source_File_Name_Project is used only in a
13086 -- configuration pragmas file.
2820d220 13087
b3b9865d
AC
13088 -- Pragmas Source_File_Name_Project should only be generated by
13089 -- the Project Manager in configuration pragmas files.
fbf5a39b
AC
13090
13091 -- This is really an ugly test. It seems to depend on some
b3b9865d
AC
13092 -- accidental and undocumented property. At the very least it
13093 -- needs to be documented, but it would be better to have a
13094 -- clean way of testing if we are in a configuration file???
fbf5a39b
AC
13095
13096 if Present (Parent (N)) then
13097 Error_Pragma
13098 ("pragma% can only appear in a configuration pragmas file");
13099 end if;
13100
996ae0b0
RK
13101 ----------------------
13102 -- Source_Reference --
13103 ----------------------
13104
13105 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
13106
b3b9865d
AC
13107 -- Nothing to do, all processing completed in Par.Prag, since we need
13108 -- the information for possible parser messages that are output.
996ae0b0
RK
13109
13110 when Pragma_Source_Reference =>
13111 GNAT_Pragma;
13112
2fa9443e
ES
13113 --------------------------------
13114 -- Static_Elaboration_Desired --
13115 --------------------------------
13116
c690a2ec 13117 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
2fa9443e
ES
13118
13119 when Pragma_Static_Elaboration_Desired =>
c690a2ec
RD
13120 GNAT_Pragma;
13121 Check_At_Most_N_Arguments (1);
2fa9443e
ES
13122
13123 if Is_Compilation_Unit (Current_Scope)
13124 and then Ekind (Current_Scope) = E_Package
13125 then
13126 Set_Static_Elaboration_Desired (Current_Scope, True);
13127 else
13128 Error_Pragma ("pragma% must apply to a library-level package");
13129 end if;
13130
996ae0b0
RK
13131 ------------------
13132 -- Storage_Size --
13133 ------------------
13134
13135 -- pragma Storage_Size (EXPRESSION);
13136
13137 when Pragma_Storage_Size => Storage_Size : declare
fbf5a39b
AC
13138 P : constant Node_Id := Parent (N);
13139 Arg : Node_Id;
996ae0b0
RK
13140
13141 begin
13142 Check_No_Identifiers;
13143 Check_Arg_Count (1);
13144
21d27997
RD
13145 -- The expression must be analyzed in the special manner described
13146 -- in "Handling of Default Expressions" in sem.ads.
996ae0b0 13147
0f1a6a0b 13148 Arg := Get_Pragma_Arg (Arg1);
21d27997 13149 Preanalyze_Spec_Expression (Arg, Any_Integer);
996ae0b0 13150
fbf5a39b
AC
13151 if not Is_Static_Expression (Arg) then
13152 Check_Restriction (Static_Storage_Size, Arg);
996ae0b0
RK
13153 end if;
13154
13155 if Nkind (P) /= N_Task_Definition then
13156 Pragma_Misplaced;
13157 return;
13158
13159 else
13160 if Has_Storage_Size_Pragma (P) then
13161 Error_Pragma ("duplicate pragma% not allowed");
13162 else
13163 Set_Has_Storage_Size_Pragma (P, True);
13164 end if;
13165
13166 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13167 -- ??? exp_ch9 should use this!
13168 end if;
13169 end Storage_Size;
13170
13171 ------------------
13172 -- Storage_Unit --
13173 ------------------
13174
13175 -- pragma Storage_Unit (NUMERIC_LITERAL);
13176
13177 -- Only permitted argument is System'Storage_Unit value
13178
13179 when Pragma_Storage_Unit =>
13180 Check_No_Identifiers;
13181 Check_Arg_Count (1);
13182 Check_Arg_Is_Integer_Literal (Arg1);
13183
0f1a6a0b 13184 if Intval (Get_Pragma_Arg (Arg1)) /=
996ae0b0
RK
13185 UI_From_Int (Ttypes.System_Storage_Unit)
13186 then
13187 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
13188 Error_Pragma_Arg
13189 ("the only allowed argument for pragma% is ^", Arg1);
13190 end if;
13191
13192 --------------------
13193 -- Stream_Convert --
13194 --------------------
13195
13196 -- pragma Stream_Convert (
13197 -- [Entity =>] type_LOCAL_NAME,
13198 -- [Read =>] function_NAME,
13199 -- [Write =>] function NAME);
13200
07fc65c4
GB
13201 when Pragma_Stream_Convert => Stream_Convert : declare
13202
13203 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
b3b9865d
AC
13204 -- Check that the given argument is the name of a local function
13205 -- of one argument that is not overloaded earlier in the current
13206 -- local scope. A check is also made that the argument is a
13207 -- function with one parameter.
07fc65c4
GB
13208
13209 --------------------------------------
13210 -- Check_OK_Stream_Convert_Function --
13211 --------------------------------------
13212
13213 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
13214 Ent : Entity_Id;
13215
13216 begin
13217 Check_Arg_Is_Local_Name (Arg);
0f1a6a0b 13218 Ent := Entity (Get_Pragma_Arg (Arg));
07fc65c4
GB
13219
13220 if Has_Homonym (Ent) then
13221 Error_Pragma_Arg
13222 ("argument for pragma% may not be overloaded", Arg);
13223 end if;
13224
13225 if Ekind (Ent) /= E_Function
13226 or else No (First_Formal (Ent))
13227 or else Present (Next_Formal (First_Formal (Ent)))
13228 then
13229 Error_Pragma_Arg
13230 ("argument for pragma% must be" &
13231 " function of one argument", Arg);
13232 end if;
13233 end Check_OK_Stream_Convert_Function;
13234
f3d57416 13235 -- Start of processing for Stream_Convert
07fc65c4
GB
13236
13237 begin
996ae0b0 13238 GNAT_Pragma;
59e5fbe0 13239 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
996ae0b0
RK
13240 Check_Arg_Count (3);
13241 Check_Optional_Identifier (Arg1, Name_Entity);
13242 Check_Optional_Identifier (Arg2, Name_Read);
13243 Check_Optional_Identifier (Arg3, Name_Write);
13244 Check_Arg_Is_Local_Name (Arg1);
07fc65c4
GB
13245 Check_OK_Stream_Convert_Function (Arg2);
13246 Check_OK_Stream_Convert_Function (Arg3);
996ae0b0
RK
13247
13248 declare
13249 Typ : constant Entity_Id :=
0f1a6a0b
AC
13250 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
13251 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
13252 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
996ae0b0
RK
13253
13254 begin
21d27997
RD
13255 Check_First_Subtype (Arg1);
13256
13257 -- Check for too early or too late. Note that we don't enforce
13258 -- the rule about primitive operations in this case, since, as
13259 -- is the case for explicit stream attributes themselves, these
13260 -- restrictions are not appropriate. Note that the chaining of
13261 -- the pragma by Rep_Item_Too_Late is actually the critical
13262 -- processing done for this pragma.
13263
13264 if Rep_Item_Too_Early (Typ, N)
996ae0b0 13265 or else
21d27997 13266 Rep_Item_Too_Late (Typ, N, FOnly => True)
996ae0b0
RK
13267 then
13268 return;
13269 end if;
13270
21d27997 13271 -- Return if previous error
996ae0b0 13272
21d27997
RD
13273 if Etype (Typ) = Any_Type
13274 or else
13275 Etype (Read) = Any_Type
996ae0b0 13276 or else
21d27997 13277 Etype (Write) = Any_Type
996ae0b0
RK
13278 then
13279 return;
13280 end if;
13281
21d27997
RD
13282 -- Error checks
13283
996ae0b0
RK
13284 if Underlying_Type (Etype (Read)) /= Typ then
13285 Error_Pragma_Arg
13286 ("incorrect return type for function&", Arg2);
13287 end if;
13288
13289 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
13290 Error_Pragma_Arg
13291 ("incorrect parameter type for function&", Arg3);
13292 end if;
13293
13294 if Underlying_Type (Etype (First_Formal (Read))) /=
13295 Underlying_Type (Etype (Write))
13296 then
13297 Error_Pragma_Arg
13298 ("result type of & does not match Read parameter type",
13299 Arg3);
13300 end if;
13301 end;
13302 end Stream_Convert;
13303
13304 -------------------------
13305 -- Style_Checks (GNAT) --
13306 -------------------------
13307
13308 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13309
b3b9865d
AC
13310 -- This is processed by the parser since some of the style checks
13311 -- take place during source scanning and parsing. This means that
13312 -- we don't need to issue error messages here.
996ae0b0
RK
13313
13314 when Pragma_Style_Checks => Style_Checks : declare
0f1a6a0b 13315 A : constant Node_Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
13316 S : String_Id;
13317 C : Char_Code;
13318
13319 begin
13320 GNAT_Pragma;
13321 Check_No_Identifiers;
13322
13323 -- Two argument form
13324
13325 if Arg_Count = 2 then
13326 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13327
13328 declare
13329 E_Id : Node_Id;
13330 E : Entity_Id;
13331
13332 begin
0f1a6a0b 13333 E_Id := Get_Pragma_Arg (Arg2);
996ae0b0
RK
13334 Analyze (E_Id);
13335
13336 if not Is_Entity_Name (E_Id) then
13337 Error_Pragma_Arg
13338 ("second argument of pragma% must be entity name",
13339 Arg2);
13340 end if;
13341
13342 E := Entity (E_Id);
13343
13344 if E = Any_Id then
13345 return;
13346 else
13347 loop
13348 Set_Suppress_Style_Checks (E,
0f1a6a0b 13349 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
996ae0b0
RK
13350 exit when No (Homonym (E));
13351 E := Homonym (E);
13352 end loop;
13353 end if;
13354 end;
13355
13356 -- One argument form
13357
13358 else
13359 Check_Arg_Count (1);
13360
13361 if Nkind (A) = N_String_Literal then
13362 S := Strval (A);
13363
13364 declare
fbf5a39b 13365 Slen : constant Natural := Natural (String_Length (S));
996ae0b0
RK
13366 Options : String (1 .. Slen);
13367 J : Natural;
13368
13369 begin
13370 J := 1;
13371 loop
13372 C := Get_String_Char (S, Int (J));
13373 exit when not In_Character_Range (C);
13374 Options (J) := Get_Character (C);
13375
c3217dac
RD
13376 -- If at end of string, set options. As per discussion
13377 -- above, no need to check for errors, since we issued
13378 -- them in the parser.
13379
996ae0b0
RK
13380 if J = Slen then
13381 Set_Style_Check_Options (Options);
13382 exit;
996ae0b0 13383 end if;
c3217dac
RD
13384
13385 J := J + 1;
996ae0b0
RK
13386 end loop;
13387 end;
13388
13389 elsif Nkind (A) = N_Identifier then
996ae0b0 13390 if Chars (A) = Name_All_Checks then
19d846a0
RD
13391 if GNAT_Mode then
13392 Set_GNAT_Style_Check_Options;
13393 else
13394 Set_Default_Style_Check_Options;
13395 end if;
996ae0b0
RK
13396
13397 elsif Chars (A) = Name_On then
13398 Style_Check := True;
13399
13400 elsif Chars (A) = Name_Off then
13401 Style_Check := False;
996ae0b0
RK
13402 end if;
13403 end if;
13404 end if;
13405 end Style_Checks;
13406
13407 --------------
13408 -- Subtitle --
13409 --------------
13410
13411 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13412
13413 when Pragma_Subtitle =>
13414 GNAT_Pragma;
13415 Check_Arg_Count (1);
13416 Check_Optional_Identifier (Arg1, Name_Subtitle);
7eaa7cdf
RD
13417 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13418 Store_Note (N);
996ae0b0
RK
13419
13420 --------------
13421 -- Suppress --
13422 --------------
13423
13424 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13425
13426 when Pragma_Suppress =>
13427 Process_Suppress_Unsuppress (True);
13428
13429 ------------------
13430 -- Suppress_All --
13431 ------------------
13432
13433 -- pragma Suppress_All;
13434
c775c209
AC
13435 -- The only check made here is that the pragma has no arguments.
13436 -- There are no placement rules, and the processing required (setting
13437 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
13438 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
13439 -- then creates and inserts a pragma Suppress (All_Checks).
996ae0b0
RK
13440
13441 when Pragma_Suppress_All =>
13442 GNAT_Pragma;
13443 Check_Arg_Count (0);
13444
996ae0b0
RK
13445 -------------------------
13446 -- Suppress_Debug_Info --
13447 -------------------------
13448
13449 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13450
13451 when Pragma_Suppress_Debug_Info =>
13452 GNAT_Pragma;
13453 Check_Arg_Count (1);
996ae0b0 13454 Check_Optional_Identifier (Arg1, Name_Entity);
59e5fbe0 13455 Check_Arg_Is_Local_Name (Arg1);
eaba57fb 13456 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
996ae0b0 13457
fbf5a39b
AC
13458 ----------------------------------
13459 -- Suppress_Exception_Locations --
13460 ----------------------------------
13461
13462 -- pragma Suppress_Exception_Locations;
13463
13464 when Pragma_Suppress_Exception_Locations =>
13465 GNAT_Pragma;
13466 Check_Arg_Count (0);
13467 Check_Valid_Configuration_Pragma;
13468 Exception_Locations_Suppressed := True;
13469
996ae0b0
RK
13470 -----------------------------
13471 -- Suppress_Initialization --
13472 -----------------------------
13473
13474 -- pragma Suppress_Initialization ([Entity =>] type_Name);
13475
13476 when Pragma_Suppress_Initialization => Suppress_Init : declare
13477 E_Id : Node_Id;
13478 E : Entity_Id;
13479
13480 begin
13481 GNAT_Pragma;
13482 Check_Arg_Count (1);
13483 Check_Optional_Identifier (Arg1, Name_Entity);
13484 Check_Arg_Is_Local_Name (Arg1);
13485
0f1a6a0b 13486 E_Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
13487
13488 if Etype (E_Id) = Any_Type then
13489 return;
13490 end if;
13491
13492 E := Entity (E_Id);
13493
5b1e6aca
RD
13494 if not Is_Type (E) then
13495 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13496 end if;
13497
13498 if Rep_Item_Too_Early (E, N)
13499 or else
13500 Rep_Item_Too_Late (E, N, FOnly => True)
13501 then
13502 return;
13503 end if;
13504
13505 -- For incomplete/private type, set flag on full view
13506
13507 if Is_Incomplete_Or_Private_Type (E) then
13508 if No (Full_View (Base_Type (E))) then
13509 Error_Pragma_Arg
13510 ("argument of pragma% cannot be an incomplete type", Arg1);
996ae0b0 13511 else
5b1e6aca 13512 Set_Suppress_Initialization (Full_View (Base_Type (E)));
996ae0b0
RK
13513 end if;
13514
5b1e6aca
RD
13515 -- For first subtype, set flag on base type
13516
13517 elsif Is_First_Subtype (E) then
13518 Set_Suppress_Initialization (Base_Type (E));
13519
13520 -- For other than first subtype, set flag on subtype itself
13521
996ae0b0 13522 else
5b1e6aca 13523 Set_Suppress_Initialization (E);
996ae0b0
RK
13524 end if;
13525 end Suppress_Init;
13526
13527 -----------------
13528 -- System_Name --
13529 -----------------
13530
13531 -- pragma System_Name (DIRECT_NAME);
13532
b3b9865d
AC
13533 -- Syntax check: one argument, which must be the identifier GNAT or
13534 -- the identifier GCC, no other identifiers are acceptable.
996ae0b0
RK
13535
13536 when Pragma_System_Name =>
a30a01fe 13537 GNAT_Pragma;
996ae0b0
RK
13538 Check_No_Identifiers;
13539 Check_Arg_Count (1);
13540 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13541
13542 -----------------------------
13543 -- Task_Dispatching_Policy --
13544 -----------------------------
13545
13546 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13547
13548 when Pragma_Task_Dispatching_Policy => declare
13549 DP : Character;
13550
13551 begin
13552 Check_Ada_83_Warning;
13553 Check_Arg_Count (1);
13554 Check_No_Identifiers;
13555 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13556 Check_Valid_Configuration_Pragma;
0f1a6a0b 13557 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
996ae0b0
RK
13558 DP := Fold_Upper (Name_Buffer (1));
13559
13560 if Task_Dispatching_Policy /= ' '
13561 and then Task_Dispatching_Policy /= DP
13562 then
13563 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13564 Error_Pragma
13565 ("task dispatching policy incompatible with policy#");
fbf5a39b 13566
b3b9865d
AC
13567 -- Set new policy, but always preserve System_Location since we
13568 -- like the error message with the run time name.
fbf5a39b 13569
996ae0b0
RK
13570 else
13571 Task_Dispatching_Policy := DP;
fbf5a39b
AC
13572
13573 if Task_Dispatching_Policy_Sloc /= System_Location then
13574 Task_Dispatching_Policy_Sloc := Loc;
13575 end if;
996ae0b0
RK
13576 end if;
13577 end;
13578
dac3bede 13579 ---------------
996ae0b0 13580 -- Task_Info --
dac3bede 13581 ---------------
996ae0b0
RK
13582
13583 -- pragma Task_Info (EXPRESSION);
13584
13585 when Pragma_Task_Info => Task_Info : declare
13586 P : constant Node_Id := Parent (N);
13587
13588 begin
13589 GNAT_Pragma;
13590
13591 if Nkind (P) /= N_Task_Definition then
13592 Error_Pragma ("pragma% must appear in task definition");
13593 end if;
13594
13595 Check_No_Identifiers;
13596 Check_Arg_Count (1);
13597
0f1a6a0b
AC
13598 Analyze_And_Resolve
13599 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
996ae0b0 13600
0f1a6a0b 13601 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
996ae0b0
RK
13602 return;
13603 end if;
13604
13605 if Has_Task_Info_Pragma (P) then
13606 Error_Pragma ("duplicate pragma% not allowed");
13607 else
13608 Set_Has_Task_Info_Pragma (P, True);
13609 end if;
996ae0b0
RK
13610 end Task_Info;
13611
13612 ---------------
13613 -- Task_Name --
13614 ---------------
13615
13616 -- pragma Task_Name (string_EXPRESSION);
13617
13618 when Pragma_Task_Name => Task_Name : declare
996ae0b0
RK
13619 P : constant Node_Id := Parent (N);
13620 Arg : Node_Id;
13621
13622 begin
13623 Check_No_Identifiers;
13624 Check_Arg_Count (1);
13625
0f1a6a0b 13626 Arg := Get_Pragma_Arg (Arg1);
4017021b 13627
b3b9865d 13628 -- The expression is used in the call to Create_Task, and must be
c5326593
ES
13629 -- expanded there, not in the context of the current spec. It must
13630 -- however be analyzed to capture global references, in case it
13631 -- appears in a generic context.
4017021b 13632
c5326593 13633 Preanalyze_And_Resolve (Arg, Standard_String);
996ae0b0
RK
13634
13635 if Nkind (P) /= N_Task_Definition then
13636 Pragma_Misplaced;
13637 end if;
13638
13639 if Has_Task_Name_Pragma (P) then
13640 Error_Pragma ("duplicate pragma% not allowed");
13641 else
13642 Set_Has_Task_Name_Pragma (P, True);
13643 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13644 end if;
996ae0b0
RK
13645 end Task_Name;
13646
13647 ------------------
13648 -- Task_Storage --
13649 ------------------
13650
13651 -- pragma Task_Storage (
13652 -- [Task_Type =>] LOCAL_NAME,
13653 -- [Top_Guard =>] static_integer_EXPRESSION);
13654
13655 when Pragma_Task_Storage => Task_Storage : declare
13656 Args : Args_List (1 .. 2);
fbf5a39b 13657 Names : constant Name_List (1 .. 2) := (
996ae0b0
RK
13658 Name_Task_Type,
13659 Name_Top_Guard);
13660
13661 Task_Type : Node_Id renames Args (1);
13662 Top_Guard : Node_Id renames Args (2);
13663
13664 Ent : Entity_Id;
13665
13666 begin
13667 GNAT_Pragma;
13668 Gather_Associations (Names, Args);
fbf5a39b
AC
13669
13670 if No (Task_Type) then
13671 Error_Pragma
13672 ("missing task_type argument for pragma%");
13673 end if;
13674
996ae0b0
RK
13675 Check_Arg_Is_Local_Name (Task_Type);
13676
13677 Ent := Entity (Task_Type);
13678
13679 if not Is_Task_Type (Ent) then
13680 Error_Pragma_Arg
13681 ("argument for pragma% must be task type", Task_Type);
13682 end if;
13683
13684 if No (Top_Guard) then
13685 Error_Pragma_Arg
13686 ("pragma% takes two arguments", Task_Type);
13687 else
13688 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13689 end if;
13690
13691 Check_First_Subtype (Task_Type);
13692
13693 if Rep_Item_Too_Late (Ent, N) then
13694 raise Pragma_Exit;
13695 end if;
996ae0b0
RK
13696 end Task_Storage;
13697
dac3bede
YM
13698 ---------------
13699 -- Test_Case --
13700 ---------------
13701
a54d0eb4
AC
13702 -- pragma Test_Case ([Name =>] Static_String_EXPRESSION
13703 -- ,[Mode =>] MODE_TYPE
15d8a51d
AC
13704 -- [, Requires => Boolean_EXPRESSION]
13705 -- [, Ensures => Boolean_EXPRESSION]);
13706
5accd7b6 13707 -- MODE_TYPE ::= Nominal | Robustness
a54d0eb4 13708
dac3bede 13709 when Pragma_Test_Case => Test_Case : declare
dac3bede
YM
13710 begin
13711 GNAT_Pragma;
e0296583 13712 Check_At_Least_N_Arguments (2);
dac3bede
YM
13713 Check_At_Most_N_Arguments (4);
13714 Check_Arg_Order
a54d0eb4 13715 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
dac3bede
YM
13716
13717 Check_Optional_Identifier (Arg1, Name_Name);
1f9939b5 13718 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8c18a165
AC
13719
13720 -- In ASIS mode, for a pragma generated from a source aspect, also
13721 -- analyze the original aspect expression.
13722
13723 if ASIS_Mode
13724 and then Present (Corresponding_Aspect (N))
13725 then
13726 Check_Expr_Is_Static_Expression
13727 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
13728 end if;
13729
dac3bede 13730 Check_Optional_Identifier (Arg2, Name_Mode);
5accd7b6 13731 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
15d8a51d 13732
dac3bede
YM
13733 if Arg_Count = 4 then
13734 Check_Identifier (Arg3, Name_Requires);
13735 Check_Identifier (Arg4, Name_Ensures);
3ddd922e 13736
e0296583 13737 elsif Arg_Count = 3 then
1bf773bb 13738 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
dac3bede
YM
13739 end if;
13740
13741 Check_Test_Case;
13742 end Test_Case;
13743
4c8a5bb8
AC
13744 --------------------------
13745 -- Thread_Local_Storage --
13746 --------------------------
13747
13748 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13749
13750 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13751 Id : Node_Id;
13752 E : Entity_Id;
13753
13754 begin
13755 GNAT_Pragma;
13756 Check_Arg_Count (1);
13757 Check_Optional_Identifier (Arg1, Name_Entity);
812f574f 13758 Check_Arg_Is_Library_Level_Local_Name (Arg1);
4c8a5bb8 13759
0f1a6a0b 13760 Id := Get_Pragma_Arg (Arg1);
4c8a5bb8
AC
13761 Analyze (Id);
13762
13763 if not Is_Entity_Name (Id)
13764 or else Ekind (Entity (Id)) /= E_Variable
13765 then
13766 Error_Pragma_Arg ("local variable name required", Arg1);
13767 end if;
13768
13769 E := Entity (Id);
13770
13771 if Rep_Item_Too_Early (E, N)
13772 or else Rep_Item_Too_Late (E, N)
13773 then
13774 raise Pragma_Exit;
13775 end if;
13776
13777 Set_Has_Pragma_Thread_Local_Storage (E);
812f574f 13778 Set_Has_Gigi_Rep_Item (E);
4c8a5bb8
AC
13779 end Thread_Local_Storage;
13780
996ae0b0
RK
13781 ----------------
13782 -- Time_Slice --
13783 ----------------
13784
13785 -- pragma Time_Slice (static_duration_EXPRESSION);
13786
13787 when Pragma_Time_Slice => Time_Slice : declare
13788 Val : Ureal;
13789 Nod : Node_Id;
13790
13791 begin
13792 GNAT_Pragma;
13793 Check_Arg_Count (1);
13794 Check_No_Identifiers;
13795 Check_In_Main_Program;
13796 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13797
13798 if not Error_Posted (Arg1) then
13799 Nod := Next (N);
13800 while Present (Nod) loop
13801 if Nkind (Nod) = N_Pragma
1b24ada5 13802 and then Pragma_Name (Nod) = Name_Time_Slice
996ae0b0 13803 then
1b24ada5 13804 Error_Msg_Name_1 := Pname;
996ae0b0
RK
13805 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13806 end if;
13807
13808 Next (Nod);
13809 end loop;
13810 end if;
13811
13812 -- Process only if in main unit
13813
13814 if Get_Source_Unit (Loc) = Main_Unit then
13815 Opt.Time_Slice_Set := True;
0f1a6a0b 13816 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
996ae0b0
RK
13817
13818 if Val <= Ureal_0 then
13819 Opt.Time_Slice_Value := 0;
13820
13821 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13822 Opt.Time_Slice_Value := 1_000_000_000;
13823
13824 else
13825 Opt.Time_Slice_Value :=
13826 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13827 end if;
13828 end if;
13829 end Time_Slice;
13830
13831 -----------
13832 -- Title --
13833 -----------
13834
13835 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13836
13837 -- TITLING_OPTION ::=
13838 -- [Title =>] STRING_LITERAL
13839 -- | [Subtitle =>] STRING_LITERAL
13840
13841 when Pragma_Title => Title : declare
13842 Args : Args_List (1 .. 2);
fbf5a39b 13843 Names : constant Name_List (1 .. 2) := (
996ae0b0
RK
13844 Name_Title,
13845 Name_Subtitle);
13846
13847 begin
13848 GNAT_Pragma;
13849 Gather_Associations (Names, Args);
7eaa7cdf 13850 Store_Note (N);
996ae0b0
RK
13851
13852 for J in 1 .. 2 loop
13853 if Present (Args (J)) then
7eaa7cdf 13854 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
996ae0b0
RK
13855 end if;
13856 end loop;
13857 end Title;
13858
13859 ---------------------
13860 -- Unchecked_Union --
13861 ---------------------
13862
13863 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13864
13865 when Pragma_Unchecked_Union => Unchecked_Union : declare
fbf5a39b 13866 Assoc : constant Node_Id := Arg1;
0f1a6a0b 13867 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
996ae0b0
RK
13868 Typ : Entity_Id;
13869 Discr : Entity_Id;
13870 Tdef : Node_Id;
13871 Clist : Node_Id;
13872 Vpart : Node_Id;
13873 Comp : Node_Id;
13874 Variant : Node_Id;
13875
13876 begin
a30a01fe 13877 Ada_2005_Pragma;
996ae0b0
RK
13878 Check_No_Identifiers;
13879 Check_Arg_Count (1);
13880 Check_Arg_Is_Local_Name (Arg1);
13881
13882 Find_Type (Type_Id);
13883 Typ := Entity (Type_Id);
13884
13885 if Typ = Any_Type
13886 or else Rep_Item_Too_Early (Typ, N)
13887 then
13888 return;
13889 else
13890 Typ := Underlying_Type (Typ);
13891 end if;
13892
13893 if Rep_Item_Too_Late (Typ, N) then
13894 return;
13895 end if;
13896
13897 Check_First_Subtype (Arg1);
13898
13899 -- Note remaining cases are references to a type in the current
13900 -- declarative part. If we find an error, we post the error on
13901 -- the relevant type declaration at an appropriate point.
13902
13903 if not Is_Record_Type (Typ) then
13904 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13905 return;
13906
13907 elsif Is_Tagged_Type (Typ) then
13908 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13909 return;
13910
3e7302c3
AC
13911 elsif not Has_Discriminants (Typ) then
13912 Error_Msg_N
13913 ("Unchecked_Union must have one discriminant", Typ);
13914 return;
13915
13916 -- Note: in previous versions of GNAT we used to check for limited
13917 -- types and give an error, but in fact the standard does allow
13918 -- Unchecked_Union on limited types, so this check was removed.
996ae0b0 13919
3e7302c3
AC
13920 -- Proceed with basic error checks completed
13921
13922 else
996ae0b0 13923 Discr := First_Discriminant (Typ);
57193e09
TQ
13924 while Present (Discr) loop
13925 if No (Discriminant_Default_Value (Discr)) then
13926 Error_Msg_N
13927 ("Unchecked_Union discriminant must have default value",
13928 Discr);
13929 end if;
0f1a6a0b 13930
57193e09
TQ
13931 Next_Discriminant (Discr);
13932 end loop;
996ae0b0
RK
13933
13934 Tdef := Type_Definition (Declaration_Node (Typ));
13935 Clist := Component_List (Tdef);
13936
5d09245e
AC
13937 Comp := First (Component_Items (Clist));
13938 while Present (Comp) loop
72e9f2b9 13939 Check_Component (Comp, Typ);
5d09245e 13940 Next (Comp);
5d09245e
AC
13941 end loop;
13942
996ae0b0
RK
13943 if No (Clist) or else No (Variant_Part (Clist)) then
13944 Error_Msg_N
13945 ("Unchecked_Union must have variant part",
13946 Tdef);
13947 return;
13948 end if;
13949
13950 Vpart := Variant_Part (Clist);
1d571f3b 13951
996ae0b0
RK
13952 Variant := First (Variants (Vpart));
13953 while Present (Variant) loop
72e9f2b9 13954 Check_Variant (Variant, Typ);
996ae0b0
RK
13955 Next (Variant);
13956 end loop;
13957 end if;
13958
eaba57fb
RD
13959 Set_Is_Unchecked_Union (Typ);
13960 Set_Convention (Typ, Convention_C);
13961 Set_Has_Unchecked_Union (Base_Type (Typ));
13962 Set_Is_Unchecked_Union (Base_Type (Typ));
996ae0b0
RK
13963 end Unchecked_Union;
13964
13965 ------------------------
13966 -- Unimplemented_Unit --
13967 ------------------------
13968
13969 -- pragma Unimplemented_Unit;
13970
b3b9865d
AC
13971 -- Note: this only gives an error if we are generating code, or if
13972 -- we are in a generic library unit (where the pragma appears in the
13973 -- body, not in the spec).
996ae0b0
RK
13974
13975 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
fbf5a39b
AC
13976 Cunitent : constant Entity_Id :=
13977 Cunit_Entity (Get_Source_Unit (Loc));
13978 Ent_Kind : constant Entity_Kind :=
13979 Ekind (Cunitent);
996ae0b0
RK
13980
13981 begin
13982 GNAT_Pragma;
13983 Check_Arg_Count (0);
13984
13985 if Operating_Mode = Generate_Code
13986 or else Ent_Kind = E_Generic_Function
13987 or else Ent_Kind = E_Generic_Procedure
13988 or else Ent_Kind = E_Generic_Package
13989 then
13990 Get_Name_String (Chars (Cunitent));
13991 Set_Casing (Mixed_Case);
13992 Write_Str (Name_Buffer (1 .. Name_Len));
874a0341 13993 Write_Str (" is not supported in this configuration");
996ae0b0
RK
13994 Write_Eol;
13995 raise Unrecoverable_Error;
13996 end if;
13997 end Unimplemented_Unit;
13998
2fa9443e
ES
13999 ------------------------
14000 -- Universal_Aliasing --
14001 ------------------------
14002
14003 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
14004
14005 when Pragma_Universal_Aliasing => Universal_Alias : declare
14006 E_Id : Entity_Id;
14007
14008 begin
14009 GNAT_Pragma;
14010 Check_Arg_Count (1);
14011 Check_Optional_Identifier (Arg2, Name_Entity);
14012 Check_Arg_Is_Local_Name (Arg1);
0f1a6a0b 14013 E_Id := Entity (Get_Pragma_Arg (Arg1));
2fa9443e
ES
14014
14015 if E_Id = Any_Type then
14016 return;
14017 elsif No (E_Id) or else not Is_Type (E_Id) then
14018 Error_Pragma_Arg ("pragma% requires type", Arg1);
14019 end if;
14020
eaba57fb 14021 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
2fa9443e
ES
14022 end Universal_Alias;
14023
07fc65c4
GB
14024 --------------------
14025 -- Universal_Data --
14026 --------------------
14027
fbf5a39b 14028 -- pragma Universal_Data [(library_unit_NAME)];
07fc65c4
GB
14029
14030 when Pragma_Universal_Data =>
14031 GNAT_Pragma;
fbf5a39b
AC
14032
14033 -- If this is a configuration pragma, then set the universal
b3b9865d
AC
14034 -- addressing option, otherwise confirm that the pragma satisfies
14035 -- the requirements of library unit pragma placement and leave it
14036 -- to the GNAAMP back end to detect the pragma (avoids transitive
14037 -- setting of the option due to withed units).
fbf5a39b
AC
14038
14039 if Is_Configuration_Pragma then
14040 Universal_Addressing_On_AAMP := True;
14041 else
14042 Check_Valid_Library_Unit_Pragma;
14043 end if;
07fc65c4
GB
14044
14045 if not AAMP_On_Target then
14046 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
14047 end if;
14048
9d77af56
RD
14049 ----------------
14050 -- Unmodified --
14051 ----------------
14052
14053 -- pragma Unmodified (local_Name {, local_Name});
14054
14055 when Pragma_Unmodified => Unmodified : declare
14056 Arg_Node : Node_Id;
14057 Arg_Expr : Node_Id;
14058 Arg_Ent : Entity_Id;
14059
14060 begin
14061 GNAT_Pragma;
14062 Check_At_Least_N_Arguments (1);
14063
14064 -- Loop through arguments
14065
14066 Arg_Node := Arg1;
14067 while Present (Arg_Node) loop
14068 Check_No_Identifier (Arg_Node);
14069
b3b9865d
AC
14070 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
14071 -- in fact generate reference, so that the entity will have a
14072 -- reference, which will inhibit any warnings about it not
14073 -- being referenced, and also properly show up in the ali file
14074 -- as a reference. But this reference is recorded before the
14075 -- Has_Pragma_Unreferenced flag is set, so that no warning is
14076 -- generated for this reference.
9d77af56
RD
14077
14078 Check_Arg_Is_Local_Name (Arg_Node);
14079 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14080
14081 if Is_Entity_Name (Arg_Expr) then
14082 Arg_Ent := Entity (Arg_Expr);
14083
14084 if not Is_Assignable (Arg_Ent) then
14085 Error_Pragma_Arg
14086 ("pragma% can only be applied to a variable",
14087 Arg_Expr);
14088 else
eaba57fb 14089 Set_Has_Pragma_Unmodified (Arg_Ent);
9d77af56
RD
14090 end if;
14091 end if;
14092
14093 Next (Arg_Node);
14094 end loop;
14095 end Unmodified;
14096
07fc65c4
GB
14097 ------------------
14098 -- Unreferenced --
14099 ------------------
14100
14101 -- pragma Unreferenced (local_Name {, local_Name});
14102
ac9e9918
RD
14103 -- or when used in a context clause:
14104
14105 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
14106
07fc65c4
GB
14107 when Pragma_Unreferenced => Unreferenced : declare
14108 Arg_Node : Node_Id;
14109 Arg_Expr : Node_Id;
fbf5a39b 14110 Arg_Ent : Entity_Id;
ac9e9918 14111 Citem : Node_Id;
07fc65c4
GB
14112
14113 begin
14114 GNAT_Pragma;
14115 Check_At_Least_N_Arguments (1);
14116
ac9e9918 14117 -- Check case of appearing within context clause
07fc65c4 14118
ac9e9918 14119 if Is_In_Context_Clause then
07fc65c4 14120
c690a2ec
RD
14121 -- The arguments must all be units mentioned in a with clause
14122 -- in the same context clause. Note we already checked (in
14123 -- Par.Prag) that the arguments are either identifiers or
14124 -- selected components.
07fc65c4 14125
ac9e9918
RD
14126 Arg_Node := Arg1;
14127 while Present (Arg_Node) loop
14128 Citem := First (List_Containing (N));
14129 while Citem /= N loop
14130 if Nkind (Citem) = N_With_Clause
0f1a6a0b
AC
14131 and then
14132 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
ac9e9918
RD
14133 then
14134 Set_Has_Pragma_Unreferenced
14135 (Cunit_Entity
14136 (Get_Source_Unit
14137 (Library_Unit (Citem))));
0f1a6a0b
AC
14138 Set_Unit_Name
14139 (Get_Pragma_Arg (Arg_Node), Name (Citem));
ac9e9918
RD
14140 exit;
14141 end if;
fbf5a39b 14142
ac9e9918
RD
14143 Next (Citem);
14144 end loop;
fbf5a39b 14145
ac9e9918
RD
14146 if Citem = N then
14147 Error_Pragma_Arg
14148 ("argument of pragma% is not with'ed unit", Arg_Node);
fbf5a39b
AC
14149 end if;
14150
ac9e9918
RD
14151 Next (Arg_Node);
14152 end loop;
07fc65c4 14153
ac9e9918
RD
14154 -- Case of not in list of context items
14155
14156 else
14157 Arg_Node := Arg1;
14158 while Present (Arg_Node) loop
14159 Check_No_Identifier (Arg_Node);
14160
14161 -- Note: the analyze call done by Check_Arg_Is_Local_Name
14162 -- will in fact generate reference, so that the entity will
14163 -- have a reference, which will inhibit any warnings about
14164 -- it not being referenced, and also properly show up in the
14165 -- ali file as a reference. But this reference is recorded
14166 -- before the Has_Pragma_Unreferenced flag is set, so that
14167 -- no warning is generated for this reference.
14168
14169 Check_Arg_Is_Local_Name (Arg_Node);
14170 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14171
14172 if Is_Entity_Name (Arg_Expr) then
14173 Arg_Ent := Entity (Arg_Expr);
14174
14175 -- If the entity is overloaded, the pragma applies to the
14176 -- most recent overloading, as documented. In this case,
14177 -- name resolution does not generate a reference, so it
14178 -- must be done here explicitly.
14179
14180 if Is_Overloaded (Arg_Expr) then
14181 Generate_Reference (Arg_Ent, N);
14182 end if;
14183
eaba57fb 14184 Set_Has_Pragma_Unreferenced (Arg_Ent);
ac9e9918
RD
14185 end if;
14186
14187 Next (Arg_Node);
14188 end loop;
14189 end if;
07fc65c4
GB
14190 end Unreferenced;
14191
874a0341
RD
14192 --------------------------
14193 -- Unreferenced_Objects --
14194 --------------------------
14195
14196 -- pragma Unreferenced_Objects (local_Name {, local_Name});
14197
14198 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
14199 Arg_Node : Node_Id;
14200 Arg_Expr : Node_Id;
14201
14202 begin
14203 GNAT_Pragma;
14204 Check_At_Least_N_Arguments (1);
14205
14206 Arg_Node := Arg1;
14207 while Present (Arg_Node) loop
14208 Check_No_Identifier (Arg_Node);
14209 Check_Arg_Is_Local_Name (Arg_Node);
14210 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14211
14212 if not Is_Entity_Name (Arg_Expr)
14213 or else not Is_Type (Entity (Arg_Expr))
14214 then
14215 Error_Pragma_Arg
14216 ("argument for pragma% must be type or subtype", Arg_Node);
14217 end if;
14218
eaba57fb 14219 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
874a0341
RD
14220 Next (Arg_Node);
14221 end loop;
14222 end Unreferenced_Objects;
14223
996ae0b0
RK
14224 ------------------------------
14225 -- Unreserve_All_Interrupts --
14226 ------------------------------
14227
14228 -- pragma Unreserve_All_Interrupts;
14229
14230 when Pragma_Unreserve_All_Interrupts =>
14231 GNAT_Pragma;
14232 Check_Arg_Count (0);
14233
14234 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
14235 Unreserve_All_Interrupts := True;
14236 end if;
14237
14238 ----------------
14239 -- Unsuppress --
14240 ----------------
14241
14242 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
14243
14244 when Pragma_Unsuppress =>
a30a01fe 14245 Ada_2005_Pragma;
996ae0b0
RK
14246 Process_Suppress_Unsuppress (False);
14247
14248 -------------------
14249 -- Use_VADS_Size --
14250 -------------------
14251
14252 -- pragma Use_VADS_Size;
14253
14254 when Pragma_Use_VADS_Size =>
14255 GNAT_Pragma;
14256 Check_Arg_Count (0);
14257 Check_Valid_Configuration_Pragma;
14258 Use_VADS_Size := True;
14259
14260 ---------------------
14261 -- Validity_Checks --
14262 ---------------------
14263
14264 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14265
14266 when Pragma_Validity_Checks => Validity_Checks : declare
0f1a6a0b 14267 A : constant Node_Id := Get_Pragma_Arg (Arg1);
996ae0b0
RK
14268 S : String_Id;
14269 C : Char_Code;
14270
14271 begin
14272 GNAT_Pragma;
14273 Check_Arg_Count (1);
996ae0b0
RK
14274 Check_No_Identifiers;
14275
14276 if Nkind (A) = N_String_Literal then
14277 S := Strval (A);
14278
14279 declare
fbf5a39b 14280 Slen : constant Natural := Natural (String_Length (S));
996ae0b0
RK
14281 Options : String (1 .. Slen);
14282 J : Natural;
14283
14284 begin
14285 J := 1;
14286 loop
14287 C := Get_String_Char (S, Int (J));
14288 exit when not In_Character_Range (C);
14289 Options (J) := Get_Character (C);
14290
14291 if J = Slen then
14292 Set_Validity_Check_Options (Options);
14293 exit;
14294 else
14295 J := J + 1;
14296 end if;
14297 end loop;
14298 end;
14299
14300 elsif Nkind (A) = N_Identifier then
996ae0b0
RK
14301 if Chars (A) = Name_All_Checks then
14302 Set_Validity_Check_Options ("a");
996ae0b0
RK
14303 elsif Chars (A) = Name_On then
14304 Validity_Checks_On := True;
996ae0b0
RK
14305 elsif Chars (A) = Name_Off then
14306 Validity_Checks_On := False;
996ae0b0
RK
14307 end if;
14308 end if;
14309 end Validity_Checks;
14310
14311 --------------
14312 -- Volatile --
14313 --------------
14314
14315 -- pragma Volatile (LOCAL_NAME);
14316
14317 when Pragma_Volatile =>
14318 Process_Atomic_Shared_Volatile;
14319
14320 -------------------------
14321 -- Volatile_Components --
14322 -------------------------
14323
14324 -- pragma Volatile_Components (array_LOCAL_NAME);
14325
14326 -- Volatile is handled by the same circuit as Atomic_Components
14327
14328 --------------
14329 -- Warnings --
14330 --------------
14331
ac9e9918
RD
14332 -- pragma Warnings (On | Off);
14333 -- pragma Warnings (On | Off, LOCAL_NAME);
f02b8bb8 14334 -- pragma Warnings (static_string_EXPRESSION);
ac9e9918 14335 -- pragma Warnings (On | Off, STRING_LITERAL);
996ae0b0 14336
fbf5a39b 14337 when Pragma_Warnings => Warnings : begin
996ae0b0
RK
14338 GNAT_Pragma;
14339 Check_At_Least_N_Arguments (1);
996ae0b0
RK
14340 Check_No_Identifiers;
14341
cca5ded0
AC
14342 -- If debug flag -gnatd.i is set, pragma is ignored
14343
14344 if Debug_Flag_Dot_I then
14345 return;
14346 end if;
14347
14348 -- Process various forms of the pragma
14349
ac9e9918
RD
14350 declare
14351 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
996ae0b0 14352
ac9e9918
RD
14353 begin
14354 -- One argument case
14355
14356 if Arg_Count = 1 then
f02b8bb8 14357
f02b8bb8
RD
14358 -- On/Off one argument case was processed by parser
14359
14360 if Nkind (Argx) = N_Identifier
14361 and then
14362 (Chars (Argx) = Name_On
14363 or else
14364 Chars (Argx) = Name_Off)
14365 then
14366 null;
14367
ac9e9918
RD
14368 -- One argument case must be ON/OFF or static string expr
14369
14370 elsif not Is_Static_String_Expression (Arg1) then
14371 Error_Pragma_Arg
14372 ("argument of pragma% must be On/Off or " &
6e1ee5c3 14373 "static string expression", Arg1);
f02b8bb8 14374
ac9e9918
RD
14375 -- One argument string expression case
14376
14377 else
f02b8bb8
RD
14378 declare
14379 Lit : constant Node_Id := Expr_Value_S (Argx);
14380 Str : constant String_Id := Strval (Lit);
874a0341 14381 Len : constant Nat := String_Length (Str);
f02b8bb8 14382 C : Char_Code;
874a0341
RD
14383 J : Nat;
14384 OK : Boolean;
14385 Chr : Character;
f02b8bb8
RD
14386
14387 begin
874a0341
RD
14388 J := 1;
14389 while J <= Len loop
f02b8bb8 14390 C := Get_String_Char (Str, J);
874a0341 14391 OK := In_Character_Range (C);
f02b8bb8 14392
874a0341
RD
14393 if OK then
14394 Chr := Get_Character (C);
14395
14396 -- Dot case
14397
14398 if J < Len and then Chr = '.' then
14399 J := J + 1;
14400 C := Get_String_Char (Str, J);
14401 Chr := Get_Character (C);
14402
14403 if not Set_Dot_Warning_Switch (Chr) then
14404 Error_Pragma_Arg
14405 ("invalid warning switch character " &
14406 '.' & Chr, Arg1);
14407 end if;
14408
14409 -- Non-Dot case
14410
14411 else
14412 OK := Set_Warning_Switch (Chr);
14413 end if;
14414 end if;
14415
14416 if not OK then
f02b8bb8 14417 Error_Pragma_Arg
874a0341
RD
14418 ("invalid warning switch character " & Chr,
14419 Arg1);
f02b8bb8 14420 end if;
874a0341
RD
14421
14422 J := J + 1;
f02b8bb8
RD
14423 end loop;
14424 end;
14425 end if;
f02b8bb8 14426
ac9e9918 14427 -- Two or more arguments (must be two)
f02b8bb8 14428
ac9e9918
RD
14429 else
14430 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14431 Check_At_Most_N_Arguments (2);
996ae0b0 14432
ac9e9918
RD
14433 declare
14434 E_Id : Node_Id;
14435 E : Entity_Id;
14436 Err : Boolean;
996ae0b0 14437
ac9e9918 14438 begin
0f1a6a0b 14439 E_Id := Get_Pragma_Arg (Arg2);
ac9e9918 14440 Analyze (E_Id);
996ae0b0 14441
ac9e9918
RD
14442 -- In the expansion of an inlined body, a reference to
14443 -- the formal may be wrapped in a conversion if the
14444 -- actual is a conversion. Retrieve the real entity name.
5b4994bc 14445
ac9e9918 14446 if (In_Instance_Body
8751a35c 14447 or else In_Inlined_Body)
ac9e9918
RD
14448 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14449 then
14450 E_Id := Expression (E_Id);
14451 end if;
efdfd311 14452
ac9e9918 14453 -- Entity name case
996ae0b0 14454
ac9e9918
RD
14455 if Is_Entity_Name (E_Id) then
14456 E := Entity (E_Id);
996ae0b0 14457
ac9e9918
RD
14458 if E = Any_Id then
14459 return;
14460 else
14461 loop
14462 Set_Warnings_Off
0f1a6a0b
AC
14463 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14464 Name_Off));
ac9e9918 14465
0f1a6a0b 14466 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
1b24ada5
RD
14467 and then Warn_On_Warnings_Off
14468 then
14469 Warnings_Off_Pragmas.Append ((N, E));
14470 end if;
14471
ac9e9918
RD
14472 if Is_Enumeration_Type (E) then
14473 declare
14474 Lit : Entity_Id;
14475 begin
14476 Lit := First_Literal (E);
14477 while Present (Lit) loop
14478 Set_Warnings_Off (Lit);
14479 Next_Literal (Lit);
14480 end loop;
14481 end;
14482 end if;
14483
14484 exit when No (Homonym (E));
14485 E := Homonym (E);
14486 end loop;
996ae0b0
RK
14487 end if;
14488
ac9e9918 14489 -- Error if not entity or static string literal case
f02b8bb8 14490
ac9e9918
RD
14491 elsif not Is_Static_String_Expression (Arg2) then
14492 Error_Pragma_Arg
14493 ("second argument of pragma% must be entity " &
14494 "name or static string expression", Arg2);
14495
14496 -- String literal case
14497
14498 else
14499 String_To_Name_Buffer
0f1a6a0b 14500 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
ac9e9918 14501
c690a2ec
RD
14502 -- Note on configuration pragma case: If this is a
14503 -- configuration pragma, then for an OFF pragma, we
14504 -- just set Config True in the call, which is all
14505 -- that needs to be done. For the case of ON, this
14506 -- is normally an error, unless it is canceling the
14507 -- effect of a previous OFF pragma in the same file.
14508 -- In any other case, an error will be signalled (ON
14509 -- with no matching OFF).
14510
14511 if Chars (Argx) = Name_Off then
14512 Set_Specific_Warning_Off
14513 (Loc, Name_Buffer (1 .. Name_Len),
14514 Config => Is_Configuration_Pragma);
14515
14516 elsif Chars (Argx) = Name_On then
14517 Set_Specific_Warning_On
14518 (Loc, Name_Buffer (1 .. Name_Len), Err);
14519
14520 if Err then
14521 Error_Msg
14522 ("?pragma Warnings On with no " &
14523 "matching Warnings Off",
14524 Loc);
ac9e9918
RD
14525 end if;
14526 end if;
14527 end if;
14528 end;
14529 end if;
14530 end;
fbf5a39b 14531 end Warnings;
996ae0b0
RK
14532
14533 -------------------
14534 -- Weak_External --
14535 -------------------
14536
14537 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
14538
14539 when Pragma_Weak_External => Weak_External : declare
14540 Ent : Entity_Id;
14541
14542 begin
14543 GNAT_Pragma;
14544 Check_Arg_Count (1);
14545 Check_Optional_Identifier (Arg1, Name_Entity);
14546 Check_Arg_Is_Library_Level_Local_Name (Arg1);
0f1a6a0b 14547 Ent := Entity (Get_Pragma_Arg (Arg1));
996ae0b0
RK
14548
14549 if Rep_Item_Too_Early (Ent, N) then
14550 return;
14551 else
14552 Ent := Underlying_Type (Ent);
14553 end if;
14554
14555 -- The only processing required is to link this item on to the
14556 -- list of rep items for the given entity. This is accomplished
14557 -- by the call to Rep_Item_Too_Late (when no error is detected
14558 -- and False is returned).
14559
14560 if Rep_Item_Too_Late (Ent, N) then
14561 return;
14562 else
14563 Set_Has_Gigi_Rep_Item (Ent);
14564 end if;
14565 end Weak_External;
14566
ac9e9918
RD
14567 -----------------------------
14568 -- Wide_Character_Encoding --
14569 -----------------------------
14570
14571 -- pragma Wide_Character_Encoding (IDENTIFIER);
14572
14573 when Pragma_Wide_Character_Encoding =>
a30a01fe 14574 GNAT_Pragma;
ac9e9918
RD
14575
14576 -- Nothing to do, handled in parser. Note that we do not enforce
14577 -- configuration pragma placement, this pragma can appear at any
14578 -- place in the source, allowing mixed encodings within a single
14579 -- source program.
14580
14581 null;
14582
fbf5a39b
AC
14583 --------------------
14584 -- Unknown_Pragma --
14585 --------------------
14586
14587 -- Should be impossible, since the case of an unknown pragma is
14588 -- separately processed before the case statement is entered.
14589
14590 when Unknown_Pragma =>
14591 raise Program_Error;
996ae0b0
RK
14592 end case;
14593
6e1ee5c3
AC
14594 -- AI05-0144: detect dangerous order dependence. Disabled for now,
14595 -- until AI is formally approved.
14596
14597 -- Check_Order_Dependence;
14598
996ae0b0
RK
14599 exception
14600 when Pragma_Exit => null;
996ae0b0
RK
14601 end Analyze_Pragma;
14602
dac3bede
YM
14603 -----------------------------
14604 -- Analyze_TC_In_Decl_Part --
14605 -----------------------------
14606
14607 procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14608 begin
14609 -- Install formals and push subprogram spec onto scope stack so that we
14610 -- can see the formals from the pragma.
14611
14612 Install_Formals (S);
14613 Push_Scope (S);
14614
14615 -- Preanalyze the boolean expressions, we treat these as spec
14616 -- expressions (i.e. similar to a default expression).
14617
8c18a165
AC
14618 Preanalyze_TC_Args (N,
14619 Get_Requires_From_Test_Case_Pragma (N),
dac3bede
YM
14620 Get_Ensures_From_Test_Case_Pragma (N));
14621
14622 -- Remove the subprogram from the scope stack now that the pre-analysis
14623 -- of the expressions in the test-case is done.
14624
14625 End_Scope;
14626 end Analyze_TC_In_Decl_Part;
14627
9b3956dd
RD
14628 --------------------
14629 -- Check_Disabled --
14630 --------------------
14631
14632 function Check_Disabled (Nam : Name_Id) return Boolean is
14633 PP : Node_Id;
14634
14635 begin
14636 -- Loop through entries in check policy list
14637
14638 PP := Opt.Check_Policy_List;
14639 loop
14640 -- If there are no specific entries that matched, then nothing is
14641 -- disabled, so return False.
14642
14643 if No (PP) then
14644 return False;
14645
14646 -- Here we have an entry see if it matches
14647
14648 else
14649 declare
14650 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14651 begin
14652 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14653 return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14654 else
14655 PP := Next_Pragma (PP);
14656 end if;
14657 end;
14658 end if;
14659 end loop;
14660 end Check_Disabled;
14661
21d27997
RD
14662 -------------------
14663 -- Check_Enabled --
14664 -------------------
14665
14666 function Check_Enabled (Nam : Name_Id) return Boolean is
14667 PP : Node_Id;
14668
14669 begin
8110ee3b
RD
14670 -- Loop through entries in check policy list
14671
21d27997
RD
14672 PP := Opt.Check_Policy_List;
14673 loop
8110ee3b
RD
14674 -- If there are no specific entries that matched, then we let the
14675 -- setting of assertions govern. Note that this provides the needed
14676 -- compatibility with the RM for the cases of assertion, invariant,
14677 -- precondition, predicate, and postcondition.
14678
21d27997
RD
14679 if No (PP) then
14680 return Assertions_Enabled;
14681
8110ee3b 14682 -- Here we have an entry see if it matches
21d27997
RD
14683
14684 else
8110ee3b
RD
14685 declare
14686 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14687
14688 begin
14689 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14690 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14691 when Name_On | Name_Check =>
14692 return True;
14693 when Name_Off | Name_Ignore =>
14694 return False;
14695 when others =>
14696 raise Program_Error;
14697 end case;
14698
14699 else
14700 PP := Next_Pragma (PP);
14701 end if;
14702 end;
21d27997
RD
14703 end if;
14704 end loop;
14705 end Check_Enabled;
14706
fbf5a39b
AC
14707 ---------------------------------
14708 -- Delay_Config_Pragma_Analyze --
14709 ---------------------------------
14710
14711 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14712 begin
1b24ada5 14713 return Pragma_Name (N) = Name_Interrupt_State
ac9e9918 14714 or else
1b24ada5 14715 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
fbf5a39b
AC
14716 end Delay_Config_Pragma_Analyze;
14717
996ae0b0
RK
14718 -------------------------
14719 -- Get_Base_Subprogram --
14720 -------------------------
14721
14722 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14723 Result : Entity_Id;
14724
14725 begin
996ae0b0
RK
14726 -- Follow subprogram renaming chain
14727
1d571f3b 14728 Result := Def_Id;
996ae0b0
RK
14729 while Is_Subprogram (Result)
14730 and then
53f29d4f
AC
14731 Nkind (Parent (Declaration_Node (Result))) =
14732 N_Subprogram_Renaming_Declaration
996ae0b0
RK
14733 and then Present (Alias (Result))
14734 loop
14735 Result := Alias (Result);
14736 end loop;
14737
14738 return Result;
14739 end Get_Base_Subprogram;
14740
21d27997
RD
14741 ----------------
14742 -- Initialize --
14743 ----------------
14744
14745 procedure Initialize is
14746 begin
14747 Externals.Init;
14748 end Initialize;
14749
5950a3ac
AC
14750 -----------------------------
14751 -- Is_Config_Static_String --
14752 -----------------------------
14753
14754 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14755
14756 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
b3b9865d
AC
14757 -- This is an internal recursive function that is just like the outer
14758 -- function except that it adds the string to the name buffer rather
14759 -- than placing the string in the name buffer.
5950a3ac
AC
14760
14761 ------------------------------
14762 -- Add_Config_Static_String --
14763 ------------------------------
14764
14765 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14766 N : Node_Id;
14767 C : Char_Code;
14768
14769 begin
14770 N := Arg;
14771
14772 if Nkind (N) = N_Op_Concat then
14773 if Add_Config_Static_String (Left_Opnd (N)) then
14774 N := Right_Opnd (N);
14775 else
14776 return False;
14777 end if;
14778 end if;
14779
14780 if Nkind (N) /= N_String_Literal then
14781 Error_Msg_N ("string literal expected for pragma argument", N);
14782 return False;
14783
14784 else
14785 for J in 1 .. String_Length (Strval (N)) loop
14786 C := Get_String_Char (Strval (N), J);
14787
14788 if not In_Character_Range (C) then
14789 Error_Msg
14790 ("string literal contains invalid wide character",
14791 Sloc (N) + 1 + Source_Ptr (J));
14792 return False;
14793 end if;
14794
14795 Add_Char_To_Name_Buffer (Get_Character (C));
14796 end loop;
14797 end if;
14798
14799 return True;
14800 end Add_Config_Static_String;
14801
f3d57416 14802 -- Start of processing for Is_Config_Static_String
5950a3ac
AC
14803
14804 begin
8a36a0cc 14805
5950a3ac
AC
14806 Name_Len := 0;
14807 return Add_Config_Static_String (Arg);
14808 end Is_Config_Static_String;
14809
fbf5a39b
AC
14810 -----------------------------------------
14811 -- Is_Non_Significant_Pragma_Reference --
14812 -----------------------------------------
14813
14814 -- This function makes use of the following static table which indicates
95cb33a5 14815 -- whether a given pragma is significant.
fbf5a39b 14816
95cb33a5 14817 -- -1 indicates that references in any argument position are significant
308e6f3a
RW
14818 -- 0 indicates that appearance in any argument is not significant
14819 -- +n indicates that appearance as argument n is significant, but all
95cb33a5
AC
14820 -- other arguments are not significant
14821 -- 99 special processing required (e.g. for pragma Check)
8a36a0cc 14822
21d27997 14823 Sig_Flags : constant array (Pragma_Id) of Int :=
12b4d338
AC
14824 (Pragma_AST_Entry => -1,
14825 Pragma_Abort_Defer => -1,
14826 Pragma_Ada_83 => -1,
14827 Pragma_Ada_95 => -1,
14828 Pragma_Ada_05 => -1,
14829 Pragma_Ada_2005 => -1,
14830 Pragma_Ada_12 => -1,
14831 Pragma_Ada_2012 => -1,
14832 Pragma_All_Calls_Remote => -1,
14833 Pragma_Annotate => -1,
14834 Pragma_Assert => -1,
14835 Pragma_Assertion_Policy => 0,
14836 Pragma_Assume_No_Invalid_Values => 0,
14837 Pragma_Asynchronous => -1,
14838 Pragma_Atomic => 0,
14839 Pragma_Atomic_Components => 0,
14840 Pragma_Attach_Handler => -1,
14841 Pragma_Check => 99,
14842 Pragma_Check_Name => 0,
14843 Pragma_Check_Policy => 0,
14844 Pragma_CIL_Constructor => -1,
14845 Pragma_CPP_Class => 0,
14846 Pragma_CPP_Constructor => 0,
14847 Pragma_CPP_Virtual => 0,
14848 Pragma_CPP_Vtable => 0,
14849 Pragma_CPU => -1,
14850 Pragma_C_Pass_By_Copy => 0,
14851 Pragma_Comment => 0,
14852 Pragma_Common_Object => -1,
14853 Pragma_Compile_Time_Error => -1,
14854 Pragma_Compile_Time_Warning => -1,
14855 Pragma_Compiler_Unit => 0,
14856 Pragma_Complete_Representation => 0,
14857 Pragma_Complex_Representation => 0,
14858 Pragma_Component_Alignment => -1,
14859 Pragma_Controlled => 0,
14860 Pragma_Convention => 0,
14861 Pragma_Convention_Identifier => 0,
14862 Pragma_Debug => -1,
14863 Pragma_Debug_Policy => 0,
14864 Pragma_Detect_Blocking => -1,
14865 Pragma_Default_Storage_Pool => -1,
14866 Pragma_Dimension => -1,
14867 Pragma_Disable_Atomic_Synchronization => -1,
14868 Pragma_Discard_Names => 0,
14869 Pragma_Dispatching_Domain => -1,
14870 Pragma_Elaborate => -1,
14871 Pragma_Elaborate_All => -1,
14872 Pragma_Elaborate_Body => -1,
14873 Pragma_Elaboration_Checks => -1,
14874 Pragma_Eliminate => -1,
14875 Pragma_Enable_Atomic_Synchronization => -1,
14876 Pragma_Export => -1,
14877 Pragma_Export_Exception => -1,
14878 Pragma_Export_Function => -1,
14879 Pragma_Export_Object => -1,
14880 Pragma_Export_Procedure => -1,
14881 Pragma_Export_Value => -1,
14882 Pragma_Export_Valued_Procedure => -1,
14883 Pragma_Extend_System => -1,
14884 Pragma_Extensions_Allowed => -1,
14885 Pragma_External => -1,
14886 Pragma_Favor_Top_Level => -1,
14887 Pragma_External_Name_Casing => -1,
14888 Pragma_Fast_Math => -1,
14889 Pragma_Finalize_Storage_Only => 0,
14890 Pragma_Float_Representation => 0,
14891 Pragma_Ident => -1,
14892 Pragma_Implementation_Defined => -1,
14893 Pragma_Implemented => -1,
14894 Pragma_Implicit_Packing => 0,
14895 Pragma_Import => +2,
14896 Pragma_Import_Exception => 0,
14897 Pragma_Import_Function => 0,
14898 Pragma_Import_Object => 0,
14899 Pragma_Import_Procedure => 0,
14900 Pragma_Import_Valued_Procedure => 0,
14901 Pragma_Independent => 0,
14902 Pragma_Independent_Components => 0,
14903 Pragma_Initialize_Scalars => -1,
14904 Pragma_Inline => 0,
14905 Pragma_Inline_Always => 0,
14906 Pragma_Inline_Generic => 0,
14907 Pragma_Inspection_Point => -1,
14908 Pragma_Interface => +2,
14909 Pragma_Interface_Name => +2,
14910 Pragma_Interrupt_Handler => -1,
14911 Pragma_Interrupt_Priority => -1,
14912 Pragma_Interrupt_State => -1,
14913 Pragma_Invariant => -1,
14914 Pragma_Java_Constructor => -1,
14915 Pragma_Java_Interface => -1,
14916 Pragma_Keep_Names => 0,
14917 Pragma_License => -1,
14918 Pragma_Link_With => -1,
14919 Pragma_Linker_Alias => -1,
14920 Pragma_Linker_Constructor => -1,
14921 Pragma_Linker_Destructor => -1,
14922 Pragma_Linker_Options => -1,
14923 Pragma_Linker_Section => -1,
14924 Pragma_List => -1,
14925 Pragma_Locking_Policy => -1,
14926 Pragma_Long_Float => -1,
14927 Pragma_Machine_Attribute => -1,
14928 Pragma_Main => -1,
14929 Pragma_Main_Storage => -1,
14930 Pragma_Memory_Size => -1,
14931 Pragma_No_Return => 0,
14932 Pragma_No_Body => 0,
14933 Pragma_No_Run_Time => -1,
14934 Pragma_No_Strict_Aliasing => -1,
14935 Pragma_Normalize_Scalars => -1,
14936 Pragma_Obsolescent => 0,
14937 Pragma_Optimize => -1,
14938 Pragma_Optimize_Alignment => -1,
14939 Pragma_Ordered => 0,
14940 Pragma_Pack => 0,
14941 Pragma_Page => -1,
14942 Pragma_Passive => -1,
14943 Pragma_Preelaborable_Initialization => -1,
14944 Pragma_Polling => -1,
14945 Pragma_Persistent_BSS => 0,
14946 Pragma_Postcondition => -1,
14947 Pragma_Precondition => -1,
14948 Pragma_Predicate => -1,
14949 Pragma_Preelaborate => -1,
14950 Pragma_Preelaborate_05 => -1,
14951 Pragma_Priority => -1,
14952 Pragma_Priority_Specific_Dispatching => -1,
14953 Pragma_Profile => 0,
14954 Pragma_Profile_Warnings => 0,
14955 Pragma_Propagate_Exceptions => -1,
14956 Pragma_Psect_Object => -1,
14957 Pragma_Pure => -1,
14958 Pragma_Pure_05 => -1,
14959 Pragma_Pure_Function => -1,
14960 Pragma_Queuing_Policy => -1,
14961 Pragma_Ravenscar => -1,
14962 Pragma_Relative_Deadline => -1,
14963 Pragma_Remote_Call_Interface => -1,
14964 Pragma_Remote_Types => -1,
14965 Pragma_Restricted_Run_Time => -1,
14966 Pragma_Restriction_Warnings => -1,
14967 Pragma_Restrictions => -1,
14968 Pragma_Reviewable => -1,
14969 Pragma_Short_Circuit_And_Or => -1,
14970 Pragma_Share_Generic => -1,
14971 Pragma_Shared => -1,
14972 Pragma_Shared_Passive => -1,
14973 Pragma_Short_Descriptors => 0,
14974 Pragma_Source_File_Name => -1,
14975 Pragma_Source_File_Name_Project => -1,
14976 Pragma_Source_Reference => -1,
14977 Pragma_Storage_Size => -1,
14978 Pragma_Storage_Unit => -1,
14979 Pragma_Static_Elaboration_Desired => -1,
14980 Pragma_Stream_Convert => -1,
14981 Pragma_Style_Checks => -1,
14982 Pragma_Subtitle => -1,
14983 Pragma_Suppress => 0,
14984 Pragma_Suppress_Exception_Locations => 0,
14985 Pragma_Suppress_All => -1,
14986 Pragma_Suppress_Debug_Info => 0,
14987 Pragma_Suppress_Initialization => 0,
14988 Pragma_System_Name => -1,
14989 Pragma_Task_Dispatching_Policy => -1,
14990 Pragma_Task_Info => -1,
14991 Pragma_Task_Name => -1,
14992 Pragma_Task_Storage => 0,
14993 Pragma_Test_Case => -1,
14994 Pragma_Thread_Local_Storage => 0,
14995 Pragma_Time_Slice => -1,
14996 Pragma_Title => -1,
14997 Pragma_Unchecked_Union => 0,
14998 Pragma_Unimplemented_Unit => -1,
14999 Pragma_Universal_Aliasing => -1,
15000 Pragma_Universal_Data => -1,
15001 Pragma_Unmodified => -1,
15002 Pragma_Unreferenced => -1,
15003 Pragma_Unreferenced_Objects => -1,
15004 Pragma_Unreserve_All_Interrupts => -1,
15005 Pragma_Unsuppress => 0,
15006 Pragma_Use_VADS_Size => -1,
15007 Pragma_Validity_Checks => -1,
15008 Pragma_Volatile => 0,
15009 Pragma_Volatile_Components => 0,
15010 Pragma_Warnings => -1,
15011 Pragma_Weak_External => -1,
15012 Pragma_Wide_Character_Encoding => 0,
15013 Unknown_Pragma => 0);
fbf5a39b
AC
15014
15015 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
21d27997
RD
15016 Id : Pragma_Id;
15017 P : Node_Id;
15018 C : Int;
15019 A : Node_Id;
996ae0b0 15020
996ae0b0 15021 begin
fbf5a39b
AC
15022 P := Parent (N);
15023
15024 if Nkind (P) /= N_Pragma_Argument_Association then
15025 return False;
15026
15027 else
21d27997
RD
15028 Id := Get_Pragma_Id (Parent (P));
15029 C := Sig_Flags (Id);
fbf5a39b
AC
15030
15031 case C is
15032 when -1 =>
15033 return False;
15034
15035 when 0 =>
15036 return True;
15037
21d27997
RD
15038 when 99 =>
15039 case Id is
15040
15041 -- For pragma Check, the first argument is not significant,
15042 -- the second and the third (if present) arguments are
15043 -- significant.
15044
15045 when Pragma_Check =>
15046 return
15047 P = First (Pragma_Argument_Associations (Parent (P)));
15048
15049 when others =>
15050 raise Program_Error;
15051 end case;
15052
fbf5a39b
AC
15053 when others =>
15054 A := First (Pragma_Argument_Associations (Parent (P)));
15055 for J in 1 .. C - 1 loop
15056 if No (A) then
15057 return False;
15058 end if;
15059
15060 Next (A);
15061 end loop;
15062
21d27997 15063 return A = P; -- is this wrong way round ???
fbf5a39b
AC
15064 end case;
15065 end if;
15066 end Is_Non_Significant_Pragma_Reference;
996ae0b0
RK
15067
15068 ------------------------------
15069 -- Is_Pragma_String_Literal --
15070 ------------------------------
15071
b3b9865d
AC
15072 -- This function returns true if the corresponding pragma argument is a
15073 -- static string expression. These are the only cases in which string
15074 -- literals can appear as pragma arguments. We also allow a string literal
15075 -- as the first argument to pragma Assert (although it will of course
15076 -- always generate a type error).
996ae0b0
RK
15077
15078 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
15079 Pragn : constant Node_Id := Parent (Par);
15080 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
1b24ada5 15081 Pname : constant Name_Id := Pragma_Name (Pragn);
996ae0b0
RK
15082 Argn : Natural;
15083 N : Node_Id;
15084
15085 begin
15086 Argn := 1;
15087 N := First (Assoc);
15088 loop
15089 exit when N = Par;
15090 Argn := Argn + 1;
15091 Next (N);
15092 end loop;
15093
15094 if Pname = Name_Assert then
15095 return True;
15096
15097 elsif Pname = Name_Export then
15098 return Argn > 2;
15099
15100 elsif Pname = Name_Ident then
15101 return Argn = 1;
15102
15103 elsif Pname = Name_Import then
15104 return Argn > 2;
15105
15106 elsif Pname = Name_Interface_Name then
15107 return Argn > 1;
15108
15109 elsif Pname = Name_Linker_Alias then
15110 return Argn = 2;
15111
15112 elsif Pname = Name_Linker_Section then
15113 return Argn = 2;
15114
15115 elsif Pname = Name_Machine_Attribute then
15116 return Argn = 2;
15117
15118 elsif Pname = Name_Source_File_Name then
15119 return True;
15120
15121 elsif Pname = Name_Source_Reference then
15122 return Argn = 2;
15123
15124 elsif Pname = Name_Title then
15125 return True;
15126
15127 elsif Pname = Name_Subtitle then
15128 return True;
15129
15130 else
15131 return False;
15132 end if;
996ae0b0
RK
15133 end Is_Pragma_String_Literal;
15134
dac3bede
YM
15135 ------------------------
15136 -- Preanalyze_TC_Args --
15137 ------------------------
15138
8c18a165 15139 procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
dac3bede
YM
15140 begin
15141 -- Preanalyze the boolean expressions, we treat these as spec
15142 -- expressions (i.e. similar to a default expression).
15143
15144 if Present (Arg_Req) then
15145 Preanalyze_Spec_Expression
15146 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
8c18a165
AC
15147
15148 -- In ASIS mode, for a pragma generated from a source aspect, also
15149 -- analyze the original aspect expression.
15150
15151 if ASIS_Mode
15152 and then Present (Corresponding_Aspect (N))
15153 then
15154 Preanalyze_Spec_Expression
15155 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
15156 end if;
dac3bede
YM
15157 end if;
15158
15159 if Present (Arg_Ens) then
15160 Preanalyze_Spec_Expression
15161 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
8c18a165
AC
15162
15163 -- In ASIS mode, for a pragma generated from a source aspect, also
15164 -- analyze the original aspect expression.
15165
15166 if ASIS_Mode
15167 and then Present (Corresponding_Aspect (N))
15168 then
15169 Preanalyze_Spec_Expression
15170 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
15171 end if;
dac3bede
YM
15172 end if;
15173 end Preanalyze_TC_Args;
15174
996ae0b0
RK
15175 --------------------------------------
15176 -- Process_Compilation_Unit_Pragmas --
15177 --------------------------------------
15178
15179 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
15180 begin
b3b9865d 15181 -- A special check for pragma Suppress_All, a very strange DEC pragma,
c775c209
AC
15182 -- strange because it comes at the end of the unit. Rational has the
15183 -- same name for a pragma, but treats it as a program unit pragma, In
15184 -- GNAT we just decide to allow it anywhere at all. If it appeared then
15185 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
15186 -- node, and we insert a pragma Suppress (All_Checks) at the start of
15187 -- the context clause to ensure the correct processing.
15188
15189 if Has_Pragma_Suppress_All (N) then
15190 Prepend_To (Context_Items (N),
15191 Make_Pragma (Sloc (N),
15192 Chars => Name_Suppress,
15193 Pragma_Argument_Associations => New_List (
15194 Make_Pragma_Argument_Association (Sloc (N),
7675ad4f 15195 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
c775c209 15196 end if;
996ae0b0 15197
c775c209 15198 -- Nothing else to do at the current time!
996ae0b0 15199
996ae0b0
RK
15200 end Process_Compilation_Unit_Pragmas;
15201
2fa9443e
ES
15202 --------
15203 -- rv --
15204 --------
15205
15206 procedure rv is
15207 begin
15208 null;
15209 end rv;
15210
996ae0b0
RK
15211 --------------------------------
15212 -- Set_Encoded_Interface_Name --
15213 --------------------------------
15214
15215 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
15216 Str : constant String_Id := Strval (S);
15217 Len : constant Int := String_Length (Str);
15218 CC : Char_Code;
15219 C : Character;
15220 J : Int;
15221
15222 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
15223
15224 procedure Encode;
b3b9865d
AC
15225 -- Stores encoded value of character code CC. The encoding we use an
15226 -- underscore followed by four lower case hex digits.
996ae0b0 15227
2c9beb8a
RD
15228 ------------
15229 -- Encode --
15230 ------------
15231
996ae0b0
RK
15232 procedure Encode is
15233 begin
15234 Store_String_Char (Get_Char_Code ('_'));
15235 Store_String_Char
15236 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
15237 Store_String_Char
15238 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
15239 Store_String_Char
15240 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
15241 Store_String_Char
15242 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
15243 end Encode;
15244
15245 -- Start of processing for Set_Encoded_Interface_Name
15246
15247 begin
b3b9865d
AC
15248 -- If first character is asterisk, this is a link name, and we leave it
15249 -- completely unmodified. We also ignore null strings (the latter case
15250 -- happens only in error cases) and no encoding should occur for Java or
15251 -- AAMP interface names.
996ae0b0
RK
15252
15253 if Len = 0
15254 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
2fa9443e
ES
15255 or else VM_Target /= No_VM
15256 or else AAMP_On_Target
996ae0b0
RK
15257 then
15258 Set_Interface_Name (E, S);
15259
15260 else
15261 J := 1;
15262 loop
15263 CC := Get_String_Char (Str, J);
15264
15265 exit when not In_Character_Range (CC);
15266
15267 C := Get_Character (CC);
15268
15269 exit when C /= '_' and then C /= '$'
15270 and then C not in '0' .. '9'
15271 and then C not in 'a' .. 'z'
15272 and then C not in 'A' .. 'Z';
15273
15274 if J = Len then
15275 Set_Interface_Name (E, S);
15276 return;
15277
15278 else
15279 J := J + 1;
15280 end if;
15281 end loop;
15282
15283 -- Here we need to encode. The encoding we use as follows:
15284 -- three underscores + four hex digits (lower case)
15285
15286 Start_String;
15287
15288 for J in 1 .. String_Length (Str) loop
15289 CC := Get_String_Char (Str, J);
15290
15291 if not In_Character_Range (CC) then
15292 Encode;
15293 else
15294 C := Get_Character (CC);
15295
15296 if C = '_' or else C = '$'
15297 or else C in '0' .. '9'
15298 or else C in 'a' .. 'z'
15299 or else C in 'A' .. 'Z'
15300 then
15301 Store_String_Char (CC);
15302 else
15303 Encode;
15304 end if;
15305 end if;
15306 end loop;
15307
15308 Set_Interface_Name (E,
15309 Make_String_Literal (Sloc (S),
15310 Strval => End_String));
15311 end if;
15312 end Set_Encoded_Interface_Name;
15313
15314 -------------------
15315 -- Set_Unit_Name --
15316 -------------------
15317
15318 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
15319 Pref : Node_Id;
15320 Scop : Entity_Id;
15321
15322 begin
15323 if Nkind (N) = N_Identifier
15324 and then Nkind (With_Item) = N_Identifier
15325 then
15326 Set_Entity (N, Entity (With_Item));
15327
15328 elsif Nkind (N) = N_Selected_Component then
15329 Change_Selected_Component_To_Expanded_Name (N);
15330 Set_Entity (N, Entity (With_Item));
15331 Set_Entity (Selector_Name (N), Entity (N));
15332
15333 Pref := Prefix (N);
15334 Scop := Scope (Entity (N));
996ae0b0
RK
15335 while Nkind (Pref) = N_Selected_Component loop
15336 Change_Selected_Component_To_Expanded_Name (Pref);
15337 Set_Entity (Selector_Name (Pref), Scop);
15338 Set_Entity (Pref, Scop);
15339 Pref := Prefix (Pref);
15340 Scop := Scope (Scop);
15341 end loop;
15342
15343 Set_Entity (Pref, Scop);
15344 end if;
15345 end Set_Unit_Name;
21d27997 15346
996ae0b0 15347end Sem_Prag;