[multiple changes]
[gcc.git] / gcc / ada / sem_prag.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ P R A G --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
31
32 with Aspects; use Aspects;
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Checks; use Checks;
36 with Csets; use Csets;
37 with Debug; use Debug;
38 with Einfo; use Einfo;
39 with Elists; use Elists;
40 with Errout; use Errout;
41 with Exp_Dist; use Exp_Dist;
42 with Exp_Util; use Exp_Util;
43 with Freeze; use Freeze;
44 with Lib; use Lib;
45 with Lib.Writ; use Lib.Writ;
46 with Lib.Xref; use Lib.Xref;
47 with Namet.Sp; use Namet.Sp;
48 with Nlists; use Nlists;
49 with Nmake; use Nmake;
50 with Opt; use Opt;
51 with Output; use Output;
52 with Par_SCO; use Par_SCO;
53 with Restrict; use Restrict;
54 with Rident; use Rident;
55 with Rtsfind; use Rtsfind;
56 with Sem; use Sem;
57 with Sem_Aux; use Sem_Aux;
58 with Sem_Ch3; use Sem_Ch3;
59 with Sem_Ch6; use Sem_Ch6;
60 with Sem_Ch8; use Sem_Ch8;
61 with Sem_Ch12; use Sem_Ch12;
62 with Sem_Ch13; use Sem_Ch13;
63 with Sem_Disp; use Sem_Disp;
64 with Sem_Dist; use Sem_Dist;
65 with Sem_Elim; use Sem_Elim;
66 with Sem_Eval; use Sem_Eval;
67 with Sem_Intr; use Sem_Intr;
68 with Sem_Mech; use Sem_Mech;
69 with Sem_Res; use Sem_Res;
70 with Sem_Type; use Sem_Type;
71 with Sem_Util; use Sem_Util;
72 with Sem_VFpt; use Sem_VFpt;
73 with Sem_Warn; use Sem_Warn;
74 with Stand; use Stand;
75 with Sinfo; use Sinfo;
76 with Sinfo.CN; use Sinfo.CN;
77 with Sinput; use Sinput;
78 with Snames; use Snames;
79 with Stringt; use Stringt;
80 with Stylesw; use Stylesw;
81 with Table;
82 with Targparm; use Targparm;
83 with Tbuild; use Tbuild;
84 with Ttypes;
85 with Uintp; use Uintp;
86 with Uname; use Uname;
87 with Urealp; use Urealp;
88 with Validsw; use Validsw;
89 with Warnsw; use Warnsw;
90
91 package body Sem_Prag is
92
93 ----------------------------------------------
94 -- Common Handling of Import-Export Pragmas --
95 ----------------------------------------------
96
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:
100
101 -- pragma Export_xxx
102 -- [Internal =>] LOCAL_NAME
103 -- [, [External =>] EXTERNAL_SYMBOL]
104 -- [, other optional parameters ]);
105
106 -- pragma Import_xxx
107 -- [Internal =>] LOCAL_NAME
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
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
121 -- parameter, the External parameter is a copy of the Internal name).
122
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).
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
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.
142
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.
146
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
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.
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
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
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.
178
179 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
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???
183
184 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id);
185 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
186 -- of a Contract_Case or Test_Case pragma if present (possibly Empty). We
187 -- treat these as spec expressions (i.e. similar to a default expression).
188
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
195 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
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.
199
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
246 ------------------------------
247 -- Analyze_CTC_In_Decl_Part --
248 ------------------------------
249
250 procedure Analyze_CTC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
251 begin
252 -- Install formals and push subprogram spec onto scope stack so that we
253 -- can see the formals from the pragma.
254
255 Install_Formals (S);
256 Push_Scope (S);
257
258 -- Preanalyze the boolean expressions, we treat these as spec
259 -- expressions (i.e. similar to a default expression).
260
261 Preanalyze_CTC_Args
262 (N,
263 Get_Requires_From_CTC_Pragma (N),
264 Get_Ensures_From_CTC_Pragma (N));
265
266 -- Remove the subprogram from the scope stack now that the pre-analysis
267 -- of the expressions in the contract case or test case is done.
268
269 End_Scope;
270 end Analyze_CTC_In_Decl_Part;
271
272 ------------------------------
273 -- Analyze_PPC_In_Decl_Part --
274 ------------------------------
275
276 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
277 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
278
279 begin
280 -- Install formals and push subprogram spec onto scope stack so that we
281 -- can see the formals from the pragma.
282
283 Install_Formals (S);
284 Push_Scope (S);
285
286 -- Preanalyze the boolean expression, we treat this as a spec expression
287 -- (i.e. similar to a default expression).
288
289 Preanalyze_Assert_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean);
290
291 -- In ASIS mode, for a pragma generated from a source aspect, also
292 -- analyze the original aspect expression.
293
294 if ASIS_Mode
295 and then Present (Corresponding_Aspect (N))
296 then
297 Preanalyze_Assert_Expression
298 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
299 end if;
300
301 -- For a class-wide condition, a reference to a controlling formal must
302 -- be interpreted as having the class-wide type (or an access to such)
303 -- so that the inherited condition can be properly applied to any
304 -- overriding operation (see ARM12 6.6.1 (7)).
305
306 if Class_Present (N) then
307 Class_Wide_Condition : declare
308 T : constant Entity_Id := Find_Dispatching_Type (S);
309
310 ACW : Entity_Id := Empty;
311 -- Access to T'class, created if there is a controlling formal
312 -- that is an access parameter.
313
314 function Get_ACW return Entity_Id;
315 -- If the expression has a reference to an controlling access
316 -- parameter, create an access to T'class for the necessary
317 -- conversions if one does not exist.
318
319 function Process (N : Node_Id) return Traverse_Result;
320 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
321 -- aspect for a primitive subprogram of a tagged type T, a name
322 -- that denotes a formal parameter of type T is interpreted as
323 -- having type T'Class. Similarly, a name that denotes a formal
324 -- accessparameter of type access-to-T is interpreted as having
325 -- type access-to-T'Class. This ensures the expression is well-
326 -- defined for a primitive subprogram of a type descended from T.
327
328 -------------
329 -- Get_ACW --
330 -------------
331
332 function Get_ACW return Entity_Id is
333 Loc : constant Source_Ptr := Sloc (N);
334 Decl : Node_Id;
335
336 begin
337 if No (ACW) then
338 Decl := Make_Full_Type_Declaration (Loc,
339 Defining_Identifier => Make_Temporary (Loc, 'T'),
340 Type_Definition =>
341 Make_Access_To_Object_Definition (Loc,
342 Subtype_Indication =>
343 New_Occurrence_Of (Class_Wide_Type (T), Loc),
344 All_Present => True));
345
346 Insert_Before (Unit_Declaration_Node (S), Decl);
347 Analyze (Decl);
348 ACW := Defining_Identifier (Decl);
349 Freeze_Before (Unit_Declaration_Node (S), ACW);
350 end if;
351
352 return ACW;
353 end Get_ACW;
354
355 -------------
356 -- Process --
357 -------------
358
359 function Process (N : Node_Id) return Traverse_Result is
360 Loc : constant Source_Ptr := Sloc (N);
361 Typ : Entity_Id;
362
363 begin
364 if Is_Entity_Name (N)
365 and then Is_Formal (Entity (N))
366 and then Nkind (Parent (N)) /= N_Type_Conversion
367 then
368 if Etype (Entity (N)) = T then
369 Typ := Class_Wide_Type (T);
370
371 elsif Is_Access_Type (Etype (Entity (N)))
372 and then Designated_Type (Etype (Entity (N))) = T
373 then
374 Typ := Get_ACW;
375 else
376 Typ := Empty;
377 end if;
378
379 if Present (Typ) then
380 Rewrite (N,
381 Make_Type_Conversion (Loc,
382 Subtype_Mark =>
383 New_Occurrence_Of (Typ, Loc),
384 Expression => New_Occurrence_Of (Entity (N), Loc)));
385 Set_Etype (N, Typ);
386 end if;
387 end if;
388
389 return OK;
390 end Process;
391
392 procedure Replace_Type is new Traverse_Proc (Process);
393
394 -- Start of processing for Class_Wide_Condition
395
396 begin
397 if not Present (T) then
398 Error_Msg_Name_1 :=
399 Chars (Identifier (Corresponding_Aspect (N)));
400
401 Error_Msg_Name_2 := Name_Class;
402
403 Error_Msg_N
404 ("aspect `%''%` can only be specified for a primitive " &
405 "operation of a tagged type",
406 Corresponding_Aspect (N));
407 end if;
408
409 Replace_Type (Get_Pragma_Arg (Arg1));
410 end Class_Wide_Condition;
411 end if;
412
413 -- Remove the subprogram from the scope stack now that the pre-analysis
414 -- of the precondition/postcondition is done.
415
416 End_Scope;
417 end Analyze_PPC_In_Decl_Part;
418
419 --------------------
420 -- Analyze_Pragma --
421 --------------------
422
423 procedure Analyze_Pragma (N : Node_Id) is
424 Loc : constant Source_Ptr := Sloc (N);
425 Prag_Id : Pragma_Id;
426
427 Pname : Name_Id;
428 -- Name of the source pragma, or name of the corresponding aspect for
429 -- pragmas which originate in a source aspect. In the latter case, the
430 -- name may be different from the pragma name.
431
432 Pragma_Exit : exception;
433 -- This exception is used to exit pragma processing completely. It is
434 -- used when an error is detected, and no further processing is
435 -- required. It is also used if an earlier error has left the tree in
436 -- a state where the pragma should not be processed.
437
438 Arg_Count : Nat;
439 -- Number of pragma argument associations
440
441 Arg1 : Node_Id;
442 Arg2 : Node_Id;
443 Arg3 : Node_Id;
444 Arg4 : Node_Id;
445 -- First four pragma arguments (pragma argument association nodes, or
446 -- Empty if the corresponding argument does not exist).
447
448 type Name_List is array (Natural range <>) of Name_Id;
449 type Args_List is array (Natural range <>) of Node_Id;
450 -- Types used for arguments to Check_Arg_Order and Gather_Associations
451
452 procedure Ada_2005_Pragma;
453 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
454 -- Ada 95 mode, these are implementation defined pragmas, so should be
455 -- caught by the No_Implementation_Pragmas restriction.
456
457 procedure Ada_2012_Pragma;
458 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
459 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
460 -- should be caught by the No_Implementation_Pragmas restriction.
461
462 procedure Check_Ada_83_Warning;
463 -- Issues a warning message for the current pragma if operating in Ada
464 -- 83 mode (used for language pragmas that are not a standard part of
465 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
466 -- of 95 pragma.
467
468 procedure Check_Arg_Count (Required : Nat);
469 -- Check argument count for pragma is equal to given parameter. If not,
470 -- then issue an error message and raise Pragma_Exit.
471
472 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
473 -- Arg which can either be a pragma argument association, in which case
474 -- the check is applied to the expression of the association or an
475 -- expression directly.
476
477 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
478 -- Check that an argument has the right form for an EXTERNAL_NAME
479 -- parameter of an extended import/export pragma. The rule is that the
480 -- name must be an identifier or string literal (in Ada 83 mode) or a
481 -- static string expression (in Ada 95 mode).
482
483 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
484 -- Check the specified argument Arg to make sure that it is an
485 -- identifier. If not give error and raise Pragma_Exit.
486
487 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
488 -- Check the specified argument Arg to make sure that it is an integer
489 -- literal. If not give error and raise Pragma_Exit.
490
491 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
492 -- Check the specified argument Arg to make sure that it has the proper
493 -- syntactic form for a local name and meets the semantic requirements
494 -- for a local name. The local name is analyzed as part of the
495 -- processing for this call. In addition, the local name is required
496 -- to represent an entity at the library level.
497
498 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
499 -- Check the specified argument Arg to make sure that it has the proper
500 -- syntactic form for a local name and meets the semantic requirements
501 -- for a local name. The local name is analyzed as part of the
502 -- processing for this call.
503
504 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
505 -- Check the specified argument Arg to make sure that it is a valid
506 -- locking policy name. If not give error and raise Pragma_Exit.
507
508 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
509 -- Check the specified argument Arg to make sure that it is a valid
510 -- elaboration policy name. If not give error and raise Pragma_Exit.
511
512 procedure Check_Arg_Is_One_Of
513 (Arg : Node_Id;
514 N1, N2 : Name_Id);
515 procedure Check_Arg_Is_One_Of
516 (Arg : Node_Id;
517 N1, N2, N3 : Name_Id);
518 procedure Check_Arg_Is_One_Of
519 (Arg : Node_Id;
520 N1, N2, N3, N4 : Name_Id);
521 procedure Check_Arg_Is_One_Of
522 (Arg : Node_Id;
523 N1, N2, N3, N4, N5 : Name_Id);
524 -- Check the specified argument Arg to make sure that it is an
525 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
526 -- present). If not then give error and raise Pragma_Exit.
527
528 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
529 -- Check the specified argument Arg to make sure that it is a valid
530 -- queuing policy name. If not give error and raise Pragma_Exit.
531
532 procedure Check_Arg_Is_Static_Expression
533 (Arg : Node_Id;
534 Typ : Entity_Id := Empty);
535 -- Check the specified argument Arg to make sure that it is a static
536 -- expression of the given type (i.e. it will be analyzed and resolved
537 -- using this type, which can be any valid argument to Resolve, e.g.
538 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
539 -- Typ is left Empty, then any static expression is allowed.
540
541 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
542 -- Check the specified argument Arg to make sure that it is a valid task
543 -- dispatching policy name. If not give error and raise Pragma_Exit.
544
545 procedure Check_Arg_Order (Names : Name_List);
546 -- Checks for an instance of two arguments with identifiers for the
547 -- current pragma which are not in the sequence indicated by Names,
548 -- and if so, generates a fatal message about bad order of arguments.
549
550 procedure Check_At_Least_N_Arguments (N : Nat);
551 -- Check there are at least N arguments present
552
553 procedure Check_At_Most_N_Arguments (N : Nat);
554 -- Check there are no more than N arguments present
555
556 procedure Check_Component
557 (Comp : Node_Id;
558 UU_Typ : Entity_Id;
559 In_Variant_Part : Boolean := False);
560 -- Examine an Unchecked_Union component for correct use of per-object
561 -- constrained subtypes, and for restrictions on finalizable components.
562 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
563 -- should be set when Comp comes from a record variant.
564
565 procedure Check_Contract_Or_Test_Case;
566 -- Called to process a contract-case or test-case pragma. It
567 -- starts with checking pragma arguments, and the rest of the
568 -- treatment is similar to the one for pre- and postcondition in
569 -- Check_Precondition_Postcondition, except the placement rules for the
570 -- contract-case and test-case pragmas are stricter. These pragmas may
571 -- only occur after a subprogram spec declared directly in a package
572 -- spec unit. In this case, the pragma is chained to the subprogram in
573 -- question (using Spec_CTC_List and Next_Pragma) and analysis of the
574 -- pragma is delayed till the end of the spec. In all other cases, an
575 -- error message for bad placement is given.
576
577 procedure Check_Duplicate_Pragma (E : Entity_Id);
578 -- Check if a rep item of the same name as the current pragma is already
579 -- chained as a rep pragma to the given entity. If so give a message
580 -- about the duplicate, and then raise Pragma_Exit so does not return.
581
582 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
583 -- Nam is an N_String_Literal node containing the external name set by
584 -- an Import or Export pragma (or extended Import or Export pragma).
585 -- This procedure checks for possible duplications if this is the export
586 -- case, and if found, issues an appropriate error message.
587
588 procedure Check_Expr_Is_Static_Expression
589 (Expr : Node_Id;
590 Typ : Entity_Id := Empty);
591 -- Check the specified expression Expr to make sure that it is a static
592 -- expression of the given type (i.e. it will be analyzed and resolved
593 -- using this type, which can be any valid argument to Resolve, e.g.
594 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
595 -- Typ is left Empty, then any static expression is allowed.
596
597 procedure Check_First_Subtype (Arg : Node_Id);
598 -- Checks that Arg, whose expression is an entity name, references a
599 -- first subtype.
600
601 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
602 -- Checks that the given argument has an identifier, and if so, requires
603 -- it to match the given identifier name. If there is no identifier, or
604 -- a non-matching identifier, then an error message is given and
605 -- Pragma_Exit is raised.
606
607 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
608 -- Checks that the given argument has an identifier, and if so, requires
609 -- it to match one of the given identifier names. If there is no
610 -- identifier, or a non-matching identifier, then an error message is
611 -- given and Pragma_Exit is raised.
612
613 procedure Check_In_Main_Program;
614 -- Common checks for pragmas that appear within a main program
615 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
616
617 procedure Check_Interrupt_Or_Attach_Handler;
618 -- Common processing for first argument of pragma Interrupt_Handler or
619 -- pragma Attach_Handler.
620
621 procedure Check_Loop_Invariant_Variant_Placement;
622 -- Verify whether pragma Loop_Invariant or pragma Loop_Variant appear
623 -- immediately within a construct restricted to loops.
624
625 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
626 -- Check that pragma appears in a declarative part, or in a package
627 -- specification, i.e. that it does not occur in a statement sequence
628 -- in a body.
629
630 procedure Check_No_Identifier (Arg : Node_Id);
631 -- Checks that the given argument does not have an identifier. If
632 -- an identifier is present, then an error message is issued, and
633 -- Pragma_Exit is raised.
634
635 procedure Check_No_Identifiers;
636 -- Checks that none of the arguments to the pragma has an identifier.
637 -- If any argument has an identifier, then an error message is issued,
638 -- and Pragma_Exit is raised.
639
640 procedure Check_No_Link_Name;
641 -- Checks that no link name is specified
642
643 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
644 -- Checks if the given argument has an identifier, and if so, requires
645 -- it to match the given identifier name. If there is a non-matching
646 -- identifier, then an error message is given and Pragma_Exit is raised.
647
648 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
649 -- Checks if the given argument has an identifier, and if so, requires
650 -- it to match the given identifier name. If there is a non-matching
651 -- identifier, then an error message is given and Pragma_Exit is raised.
652 -- In this version of the procedure, the identifier name is given as
653 -- a string with lower case letters.
654
655 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
656 -- Called to process a precondition or postcondition pragma. There are
657 -- three cases:
658 --
659 -- The pragma appears after a subprogram spec
660 --
661 -- If the corresponding check is not enabled, the pragma is analyzed
662 -- but otherwise ignored and control returns with In_Body set False.
663 --
664 -- If the check is enabled, then the first step is to analyze the
665 -- pragma, but this is skipped if the subprogram spec appears within
666 -- a package specification (because this is the case where we delay
667 -- analysis till the end of the spec). Then (whether or not it was
668 -- analyzed), the pragma is chained to the subprogram in question
669 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
670 -- caller with In_Body set False.
671 --
672 -- The pragma appears at the start of subprogram body declarations
673 --
674 -- In this case an immediate return to the caller is made with
675 -- In_Body set True, and the pragma is NOT analyzed.
676 --
677 -- In all other cases, an error message for bad placement is given
678
679 procedure Check_Static_Constraint (Constr : Node_Id);
680 -- Constr is a constraint from an N_Subtype_Indication node from a
681 -- component constraint in an Unchecked_Union type. This routine checks
682 -- that the constraint is static as required by the restrictions for
683 -- Unchecked_Union.
684
685 procedure Check_Valid_Configuration_Pragma;
686 -- Legality checks for placement of a configuration pragma
687
688 procedure Check_Valid_Library_Unit_Pragma;
689 -- Legality checks for library unit pragmas. A special case arises for
690 -- pragmas in generic instances that come from copies of the original
691 -- library unit pragmas in the generic templates. In the case of other
692 -- than library level instantiations these can appear in contexts which
693 -- would normally be invalid (they only apply to the original template
694 -- and to library level instantiations), and they are simply ignored,
695 -- which is implemented by rewriting them as null statements.
696
697 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
698 -- Check an Unchecked_Union variant for lack of nested variants and
699 -- presence of at least one component. UU_Typ is the related Unchecked_
700 -- Union type.
701
702 procedure Error_Pragma (Msg : String);
703 pragma No_Return (Error_Pragma);
704 -- Outputs error message for current pragma. The message contains a %
705 -- that will be replaced with the pragma name, and the flag is placed
706 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
707 -- calls Fix_Error (see spec of that function for details).
708
709 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
710 pragma No_Return (Error_Pragma_Arg);
711 -- Outputs error message for current pragma. The message may contain
712 -- a % that will be replaced with the pragma name. The parameter Arg
713 -- may either be a pragma argument association, in which case the flag
714 -- is placed on the expression of this association, or an expression,
715 -- in which case the flag is placed directly on the expression. The
716 -- message is placed using Error_Msg_N, so the message may also contain
717 -- an & insertion character which will reference the given Arg value.
718 -- After placing the message, Pragma_Exit is raised. Note: this routine
719 -- calls Fix_Error (see spec of that function for details).
720
721 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
722 pragma No_Return (Error_Pragma_Arg);
723 -- Similar to above form of Error_Pragma_Arg except that two messages
724 -- are provided, the second is a continuation comment starting with \.
725
726 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
727 pragma No_Return (Error_Pragma_Arg_Ident);
728 -- Outputs error message for current pragma. The message may contain
729 -- a % that will be replaced with the pragma name. The parameter Arg
730 -- must be a pragma argument association with a non-empty identifier
731 -- (i.e. its Chars field must be set), and the error message is placed
732 -- on the identifier. The message is placed using Error_Msg_N so
733 -- the message may also contain an & insertion character which will
734 -- reference the identifier. After placing the message, Pragma_Exit
735 -- is raised. Note: this routine calls Fix_Error (see spec of that
736 -- function for details).
737
738 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
739 pragma No_Return (Error_Pragma_Ref);
740 -- Outputs error message for current pragma. The message may contain
741 -- a % that will be replaced with the pragma name. The parameter Ref
742 -- must be an entity whose name can be referenced by & and sloc by #.
743 -- After placing the message, Pragma_Exit is raised. Note: this routine
744 -- calls Fix_Error (see spec of that function for details).
745
746 function Find_Lib_Unit_Name return Entity_Id;
747 -- Used for a library unit pragma to find the entity to which the
748 -- library unit pragma applies, returns the entity found.
749
750 procedure Find_Program_Unit_Name (Id : Node_Id);
751 -- If the pragma is a compilation unit pragma, the id must denote the
752 -- compilation unit in the same compilation, and the pragma must appear
753 -- in the list of preceding or trailing pragmas. If it is a program
754 -- unit pragma that is not a compilation unit pragma, then the
755 -- identifier must be visible.
756
757 function Find_Unique_Parameterless_Procedure
758 (Name : Entity_Id;
759 Arg : Node_Id) return Entity_Id;
760 -- Used for a procedure pragma to find the unique parameterless
761 -- procedure identified by Name, returns it if it exists, otherwise
762 -- errors out and uses Arg as the pragma argument for the message.
763
764 procedure Fix_Error (Msg : in out String);
765 -- This is called prior to issuing an error message. Msg is a string
766 -- that typically contains the substring "pragma". If the current pragma
767 -- comes from an aspect, each such "pragma" substring is replaced with
768 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
769 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
770
771 procedure Gather_Associations
772 (Names : Name_List;
773 Args : out Args_List);
774 -- This procedure is used to gather the arguments for a pragma that
775 -- permits arbitrary ordering of parameters using the normal rules
776 -- for named and positional parameters. The Names argument is a list
777 -- of Name_Id values that corresponds to the allowed pragma argument
778 -- association identifiers in order. The result returned in Args is
779 -- a list of corresponding expressions that are the pragma arguments.
780 -- Note that this is a list of expressions, not of pragma argument
781 -- associations (Gather_Associations has completely checked all the
782 -- optional identifiers when it returns). An entry in Args is Empty
783 -- on return if the corresponding argument is not present.
784
785 procedure GNAT_Pragma;
786 -- Called for all GNAT defined pragmas to check the relevant restriction
787 -- (No_Implementation_Pragmas).
788
789 procedure S14_Pragma;
790 -- Called for all pragmas defined for formal verification to check that
791 -- the S14_Extensions flag is set.
792 -- This name needs fixing ??? There is no such thing as an
793 -- "S14_Extensions" flag ???
794
795 function Is_Before_First_Decl
796 (Pragma_Node : Node_Id;
797 Decls : List_Id) return Boolean;
798 -- Return True if Pragma_Node is before the first declarative item in
799 -- Decls where Decls is the list of declarative items.
800
801 function Is_Configuration_Pragma return Boolean;
802 -- Determines if the placement of the current pragma is appropriate
803 -- for a configuration pragma.
804
805 function Is_In_Context_Clause return Boolean;
806 -- Returns True if pragma appears within the context clause of a unit,
807 -- and False for any other placement (does not generate any messages).
808
809 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
810 -- Analyzes the argument, and determines if it is a static string
811 -- expression, returns True if so, False if non-static or not String.
812
813 procedure Pragma_Misplaced;
814 pragma No_Return (Pragma_Misplaced);
815 -- Issue fatal error message for misplaced pragma
816
817 procedure Process_Atomic_Shared_Volatile;
818 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
819 -- Shared is an obsolete Ada 83 pragma, treated as being identical
820 -- in effect to pragma Atomic.
821
822 procedure Process_Compile_Time_Warning_Or_Error;
823 -- Common processing for Compile_Time_Error and Compile_Time_Warning
824
825 procedure Process_Convention
826 (C : out Convention_Id;
827 Ent : out Entity_Id);
828 -- Common processing for Convention, Interface, Import and Export.
829 -- Checks first two arguments of pragma, and sets the appropriate
830 -- convention value in the specified entity or entities. On return
831 -- C is the convention, Ent is the referenced entity.
832
833 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
834 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
835 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
836
837 procedure Process_Extended_Import_Export_Exception_Pragma
838 (Arg_Internal : Node_Id;
839 Arg_External : Node_Id;
840 Arg_Form : Node_Id;
841 Arg_Code : Node_Id);
842 -- Common processing for the pragmas Import/Export_Exception. The three
843 -- arguments correspond to the three named parameters of the pragma. An
844 -- argument is empty if the corresponding parameter is not present in
845 -- the pragma.
846
847 procedure Process_Extended_Import_Export_Object_Pragma
848 (Arg_Internal : Node_Id;
849 Arg_External : Node_Id;
850 Arg_Size : Node_Id);
851 -- Common processing for the pragmas Import/Export_Object. The three
852 -- arguments correspond to the three named parameters of the pragmas. An
853 -- argument is empty if the corresponding parameter is not present in
854 -- the pragma.
855
856 procedure Process_Extended_Import_Export_Internal_Arg
857 (Arg_Internal : Node_Id := Empty);
858 -- Common processing for all extended Import and Export pragmas. The
859 -- argument is the pragma parameter for the Internal argument. If
860 -- Arg_Internal is empty or inappropriate, an error message is posted.
861 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
862 -- set to identify the referenced entity.
863
864 procedure Process_Extended_Import_Export_Subprogram_Pragma
865 (Arg_Internal : Node_Id;
866 Arg_External : Node_Id;
867 Arg_Parameter_Types : Node_Id;
868 Arg_Result_Type : Node_Id := Empty;
869 Arg_Mechanism : Node_Id;
870 Arg_Result_Mechanism : Node_Id := Empty;
871 Arg_First_Optional_Parameter : Node_Id := Empty);
872 -- Common processing for all extended Import and Export pragmas applying
873 -- to subprograms. The caller omits any arguments that do not apply to
874 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
875 -- only in the Import_Function and Export_Function cases). The argument
876 -- names correspond to the allowed pragma association identifiers.
877
878 procedure Process_Generic_List;
879 -- Common processing for Share_Generic and Inline_Generic
880
881 procedure Process_Import_Or_Interface;
882 -- Common processing for Import of Interface
883
884 procedure Process_Import_Predefined_Type;
885 -- Processing for completing a type with pragma Import. This is used
886 -- to declare types that match predefined C types, especially for cases
887 -- without corresponding Ada predefined type.
888
889 procedure Process_Inline (Active : Boolean);
890 -- Common processing for Inline and Inline_Always. The parameter
891 -- indicates if the inline pragma is active, i.e. if it should actually
892 -- cause inlining to occur.
893
894 procedure Process_Interface_Name
895 (Subprogram_Def : Entity_Id;
896 Ext_Arg : Node_Id;
897 Link_Arg : Node_Id);
898 -- Given the last two arguments of pragma Import, pragma Export, or
899 -- pragma Interface_Name, performs validity checks and sets the
900 -- Interface_Name field of the given subprogram entity to the
901 -- appropriate external or link name, depending on the arguments given.
902 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
903 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
904 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
905 -- nor Link_Arg is present, the interface name is set to the default
906 -- from the subprogram name.
907
908 procedure Process_Interrupt_Or_Attach_Handler;
909 -- Common processing for Interrupt and Attach_Handler pragmas
910
911 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
912 -- Common processing for Restrictions and Restriction_Warnings pragmas.
913 -- Warn is True for Restriction_Warnings, or for Restrictions if the
914 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
915 -- is not set in the Restrictions case.
916
917 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
918 -- Common processing for Suppress and Unsuppress. The boolean parameter
919 -- Suppress_Case is True for the Suppress case, and False for the
920 -- Unsuppress case.
921
922 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
923 -- This procedure sets the Is_Exported flag for the given entity,
924 -- checking that the entity was not previously imported. Arg is
925 -- the argument that specified the entity. A check is also made
926 -- for exporting inappropriate entities.
927
928 procedure Set_Extended_Import_Export_External_Name
929 (Internal_Ent : Entity_Id;
930 Arg_External : Node_Id);
931 -- Common processing for all extended import export pragmas. The first
932 -- argument, Internal_Ent, is the internal entity, which has already
933 -- been checked for validity by the caller. Arg_External is from the
934 -- Import or Export pragma, and may be null if no External parameter
935 -- was present. If Arg_External is present and is a non-null string
936 -- (a null string is treated as the default), then the Interface_Name
937 -- field of Internal_Ent is set appropriately.
938
939 procedure Set_Imported (E : Entity_Id);
940 -- This procedure sets the Is_Imported flag for the given entity,
941 -- checking that it is not previously exported or imported.
942
943 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
944 -- Mech is a parameter passing mechanism (see Import_Function syntax
945 -- for MECHANISM_NAME). This routine checks that the mechanism argument
946 -- has the right form, and if not issues an error message. If the
947 -- argument has the right form then the Mechanism field of Ent is
948 -- set appropriately.
949
950 procedure Set_Ravenscar_Profile (N : Node_Id);
951 -- Activate the set of configuration pragmas and restrictions that make
952 -- up the Ravenscar Profile. N is the corresponding pragma node, which
953 -- is used for error messages on any constructs that violate the
954 -- profile.
955
956 ---------------------
957 -- Ada_2005_Pragma --
958 ---------------------
959
960 procedure Ada_2005_Pragma is
961 begin
962 if Ada_Version <= Ada_95 then
963 Check_Restriction (No_Implementation_Pragmas, N);
964 end if;
965 end Ada_2005_Pragma;
966
967 ---------------------
968 -- Ada_2012_Pragma --
969 ---------------------
970
971 procedure Ada_2012_Pragma is
972 begin
973 if Ada_Version <= Ada_2005 then
974 Check_Restriction (No_Implementation_Pragmas, N);
975 end if;
976 end Ada_2012_Pragma;
977
978 --------------------------
979 -- Check_Ada_83_Warning --
980 --------------------------
981
982 procedure Check_Ada_83_Warning is
983 begin
984 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
985 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
986 end if;
987 end Check_Ada_83_Warning;
988
989 ---------------------
990 -- Check_Arg_Count --
991 ---------------------
992
993 procedure Check_Arg_Count (Required : Nat) is
994 begin
995 if Arg_Count /= Required then
996 Error_Pragma ("wrong number of arguments for pragma%");
997 end if;
998 end Check_Arg_Count;
999
1000 --------------------------------
1001 -- Check_Arg_Is_External_Name --
1002 --------------------------------
1003
1004 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
1005 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1006
1007 begin
1008 if Nkind (Argx) = N_Identifier then
1009 return;
1010
1011 else
1012 Analyze_And_Resolve (Argx, Standard_String);
1013
1014 if Is_OK_Static_Expression (Argx) then
1015 return;
1016
1017 elsif Etype (Argx) = Any_Type then
1018 raise Pragma_Exit;
1019
1020 -- An interesting special case, if we have a string literal and
1021 -- we are in Ada 83 mode, then we allow it even though it will
1022 -- not be flagged as static. This allows expected Ada 83 mode
1023 -- use of external names which are string literals, even though
1024 -- technically these are not static in Ada 83.
1025
1026 elsif Ada_Version = Ada_83
1027 and then Nkind (Argx) = N_String_Literal
1028 then
1029 return;
1030
1031 -- Static expression that raises Constraint_Error. This has
1032 -- already been flagged, so just exit from pragma processing.
1033
1034 elsif Is_Static_Expression (Argx) then
1035 raise Pragma_Exit;
1036
1037 -- Here we have a real error (non-static expression)
1038
1039 else
1040 Error_Msg_Name_1 := Pname;
1041
1042 declare
1043 Msg : String :=
1044 "argument for pragma% must be a identifier or "
1045 & "static string expression!";
1046 begin
1047 Fix_Error (Msg);
1048 Flag_Non_Static_Expr (Msg, Argx);
1049 raise Pragma_Exit;
1050 end;
1051 end if;
1052 end if;
1053 end Check_Arg_Is_External_Name;
1054
1055 -----------------------------
1056 -- Check_Arg_Is_Identifier --
1057 -----------------------------
1058
1059 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
1060 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1061 begin
1062 if Nkind (Argx) /= N_Identifier then
1063 Error_Pragma_Arg
1064 ("argument for pragma% must be identifier", Argx);
1065 end if;
1066 end Check_Arg_Is_Identifier;
1067
1068 ----------------------------------
1069 -- Check_Arg_Is_Integer_Literal --
1070 ----------------------------------
1071
1072 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1073 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1074 begin
1075 if Nkind (Argx) /= N_Integer_Literal then
1076 Error_Pragma_Arg
1077 ("argument for pragma% must be integer literal", Argx);
1078 end if;
1079 end Check_Arg_Is_Integer_Literal;
1080
1081 -------------------------------------------
1082 -- Check_Arg_Is_Library_Level_Local_Name --
1083 -------------------------------------------
1084
1085 -- LOCAL_NAME ::=
1086 -- DIRECT_NAME
1087 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1088 -- | library_unit_NAME
1089
1090 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1091 begin
1092 Check_Arg_Is_Local_Name (Arg);
1093
1094 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1095 and then Comes_From_Source (N)
1096 then
1097 Error_Pragma_Arg
1098 ("argument for pragma% must be library level entity", Arg);
1099 end if;
1100 end Check_Arg_Is_Library_Level_Local_Name;
1101
1102 -----------------------------
1103 -- Check_Arg_Is_Local_Name --
1104 -----------------------------
1105
1106 -- LOCAL_NAME ::=
1107 -- DIRECT_NAME
1108 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1109 -- | library_unit_NAME
1110
1111 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1112 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1113
1114 begin
1115 Analyze (Argx);
1116
1117 if Nkind (Argx) not in N_Direct_Name
1118 and then (Nkind (Argx) /= N_Attribute_Reference
1119 or else Present (Expressions (Argx))
1120 or else Nkind (Prefix (Argx)) /= N_Identifier)
1121 and then (not Is_Entity_Name (Argx)
1122 or else not Is_Compilation_Unit (Entity (Argx)))
1123 then
1124 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1125 end if;
1126
1127 -- No further check required if not an entity name
1128
1129 if not Is_Entity_Name (Argx) then
1130 null;
1131
1132 else
1133 declare
1134 OK : Boolean;
1135 Ent : constant Entity_Id := Entity (Argx);
1136 Scop : constant Entity_Id := Scope (Ent);
1137 begin
1138 -- Case of a pragma applied to a compilation unit: pragma must
1139 -- occur immediately after the program unit in the compilation.
1140
1141 if Is_Compilation_Unit (Ent) then
1142 declare
1143 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1144
1145 begin
1146 -- Case of pragma placed immediately after spec
1147
1148 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1149 OK := True;
1150
1151 -- Case of pragma placed immediately after body
1152
1153 elsif Nkind (Decl) = N_Subprogram_Declaration
1154 and then Present (Corresponding_Body (Decl))
1155 then
1156 OK := Parent (N) =
1157 Aux_Decls_Node
1158 (Parent (Unit_Declaration_Node
1159 (Corresponding_Body (Decl))));
1160
1161 -- All other cases are illegal
1162
1163 else
1164 OK := False;
1165 end if;
1166 end;
1167
1168 -- Special restricted placement rule from 10.2.1(11.8/2)
1169
1170 elsif Is_Generic_Formal (Ent)
1171 and then Prag_Id = Pragma_Preelaborable_Initialization
1172 then
1173 OK := List_Containing (N) =
1174 Generic_Formal_Declarations
1175 (Unit_Declaration_Node (Scop));
1176
1177 -- Default case, just check that the pragma occurs in the scope
1178 -- of the entity denoted by the name.
1179
1180 else
1181 OK := Current_Scope = Scop;
1182 end if;
1183
1184 if not OK then
1185 Error_Pragma_Arg
1186 ("pragma% argument must be in same declarative part", Arg);
1187 end if;
1188 end;
1189 end if;
1190 end Check_Arg_Is_Local_Name;
1191
1192 ---------------------------------
1193 -- Check_Arg_Is_Locking_Policy --
1194 ---------------------------------
1195
1196 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1197 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1198
1199 begin
1200 Check_Arg_Is_Identifier (Argx);
1201
1202 if not Is_Locking_Policy_Name (Chars (Argx)) then
1203 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1204 end if;
1205 end Check_Arg_Is_Locking_Policy;
1206
1207 -----------------------------------------------
1208 -- Check_Arg_Is_Partition_Elaboration_Policy --
1209 -----------------------------------------------
1210
1211 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
1212 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1213
1214 begin
1215 Check_Arg_Is_Identifier (Argx);
1216
1217 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
1218 Error_Pragma_Arg
1219 ("& is not a valid partition elaboration policy name", Argx);
1220 end if;
1221 end Check_Arg_Is_Partition_Elaboration_Policy;
1222
1223 -------------------------
1224 -- Check_Arg_Is_One_Of --
1225 -------------------------
1226
1227 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1228 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1229
1230 begin
1231 Check_Arg_Is_Identifier (Argx);
1232
1233 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1234 Error_Msg_Name_2 := N1;
1235 Error_Msg_Name_3 := N2;
1236 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1237 end if;
1238 end Check_Arg_Is_One_Of;
1239
1240 procedure Check_Arg_Is_One_Of
1241 (Arg : Node_Id;
1242 N1, N2, N3 : Name_Id)
1243 is
1244 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1245
1246 begin
1247 Check_Arg_Is_Identifier (Argx);
1248
1249 if Chars (Argx) /= N1
1250 and then Chars (Argx) /= N2
1251 and then Chars (Argx) /= N3
1252 then
1253 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1254 end if;
1255 end Check_Arg_Is_One_Of;
1256
1257 procedure Check_Arg_Is_One_Of
1258 (Arg : Node_Id;
1259 N1, N2, N3, N4 : Name_Id)
1260 is
1261 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1262
1263 begin
1264 Check_Arg_Is_Identifier (Argx);
1265
1266 if Chars (Argx) /= N1
1267 and then Chars (Argx) /= N2
1268 and then Chars (Argx) /= N3
1269 and then Chars (Argx) /= N4
1270 then
1271 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1272 end if;
1273 end Check_Arg_Is_One_Of;
1274
1275 procedure Check_Arg_Is_One_Of
1276 (Arg : Node_Id;
1277 N1, N2, N3, N4, N5 : Name_Id)
1278 is
1279 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1280
1281 begin
1282 Check_Arg_Is_Identifier (Argx);
1283
1284 if Chars (Argx) /= N1
1285 and then Chars (Argx) /= N2
1286 and then Chars (Argx) /= N3
1287 and then Chars (Argx) /= N4
1288 and then Chars (Argx) /= N5
1289 then
1290 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1291 end if;
1292 end Check_Arg_Is_One_Of;
1293
1294 ---------------------------------
1295 -- Check_Arg_Is_Queuing_Policy --
1296 ---------------------------------
1297
1298 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1299 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1300
1301 begin
1302 Check_Arg_Is_Identifier (Argx);
1303
1304 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1305 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1306 end if;
1307 end Check_Arg_Is_Queuing_Policy;
1308
1309 ------------------------------------
1310 -- Check_Arg_Is_Static_Expression --
1311 ------------------------------------
1312
1313 procedure Check_Arg_Is_Static_Expression
1314 (Arg : Node_Id;
1315 Typ : Entity_Id := Empty)
1316 is
1317 begin
1318 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1319 end Check_Arg_Is_Static_Expression;
1320
1321 ------------------------------------------
1322 -- Check_Arg_Is_Task_Dispatching_Policy --
1323 ------------------------------------------
1324
1325 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1326 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1327
1328 begin
1329 Check_Arg_Is_Identifier (Argx);
1330
1331 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1332 Error_Pragma_Arg
1333 ("& is not a valid task dispatching policy name", Argx);
1334 end if;
1335 end Check_Arg_Is_Task_Dispatching_Policy;
1336
1337 ---------------------
1338 -- Check_Arg_Order --
1339 ---------------------
1340
1341 procedure Check_Arg_Order (Names : Name_List) is
1342 Arg : Node_Id;
1343
1344 Highest_So_Far : Natural := 0;
1345 -- Highest index in Names seen do far
1346
1347 begin
1348 Arg := Arg1;
1349 for J in 1 .. Arg_Count loop
1350 if Chars (Arg) /= No_Name then
1351 for K in Names'Range loop
1352 if Chars (Arg) = Names (K) then
1353 if K < Highest_So_Far then
1354 Error_Msg_Name_1 := Pname;
1355 Error_Msg_N
1356 ("parameters out of order for pragma%", Arg);
1357 Error_Msg_Name_1 := Names (K);
1358 Error_Msg_Name_2 := Names (Highest_So_Far);
1359 Error_Msg_N ("\% must appear before %", Arg);
1360 raise Pragma_Exit;
1361
1362 else
1363 Highest_So_Far := K;
1364 end if;
1365 end if;
1366 end loop;
1367 end if;
1368
1369 Arg := Next (Arg);
1370 end loop;
1371 end Check_Arg_Order;
1372
1373 --------------------------------
1374 -- Check_At_Least_N_Arguments --
1375 --------------------------------
1376
1377 procedure Check_At_Least_N_Arguments (N : Nat) is
1378 begin
1379 if Arg_Count < N then
1380 Error_Pragma ("too few arguments for pragma%");
1381 end if;
1382 end Check_At_Least_N_Arguments;
1383
1384 -------------------------------
1385 -- Check_At_Most_N_Arguments --
1386 -------------------------------
1387
1388 procedure Check_At_Most_N_Arguments (N : Nat) is
1389 Arg : Node_Id;
1390 begin
1391 if Arg_Count > N then
1392 Arg := Arg1;
1393 for J in 1 .. N loop
1394 Next (Arg);
1395 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1396 end loop;
1397 end if;
1398 end Check_At_Most_N_Arguments;
1399
1400 ---------------------
1401 -- Check_Component --
1402 ---------------------
1403
1404 procedure Check_Component
1405 (Comp : Node_Id;
1406 UU_Typ : Entity_Id;
1407 In_Variant_Part : Boolean := False)
1408 is
1409 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1410 Sindic : constant Node_Id :=
1411 Subtype_Indication (Component_Definition (Comp));
1412 Typ : constant Entity_Id := Etype (Comp_Id);
1413
1414 begin
1415 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1416 -- object constraint, then the component type shall be an Unchecked_
1417 -- Union.
1418
1419 if Nkind (Sindic) = N_Subtype_Indication
1420 and then Has_Per_Object_Constraint (Comp_Id)
1421 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1422 then
1423 Error_Msg_N
1424 ("component subtype subject to per-object constraint " &
1425 "must be an Unchecked_Union", Comp);
1426
1427 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1428 -- the body of a generic unit, or within the body of any of its
1429 -- descendant library units, no part of the type of a component
1430 -- declared in a variant_part of the unchecked union type shall be of
1431 -- a formal private type or formal private extension declared within
1432 -- the formal part of the generic unit.
1433
1434 elsif Ada_Version >= Ada_2012
1435 and then In_Generic_Body (UU_Typ)
1436 and then In_Variant_Part
1437 and then Is_Private_Type (Typ)
1438 and then Is_Generic_Type (Typ)
1439 then
1440 Error_Msg_N
1441 ("component of unchecked union cannot be of generic type", Comp);
1442
1443 elsif Needs_Finalization (Typ) then
1444 Error_Msg_N
1445 ("component of unchecked union cannot be controlled", Comp);
1446
1447 elsif Has_Task (Typ) then
1448 Error_Msg_N
1449 ("component of unchecked union cannot have tasks", Comp);
1450 end if;
1451 end Check_Component;
1452
1453 ---------------------------------
1454 -- Check_Contract_Or_Test_Case --
1455 ---------------------------------
1456
1457 procedure Check_Contract_Or_Test_Case is
1458 P : Node_Id;
1459 PO : Node_Id;
1460
1461 procedure Chain_CTC (PO : Node_Id);
1462 -- If PO is a [generic] subprogram declaration node, then the
1463 -- contract-case or test-case applies to this subprogram and the
1464 -- processing for the pragma is completed. Otherwise the pragma
1465 -- is misplaced.
1466
1467 ---------------
1468 -- Chain_CTC --
1469 ---------------
1470
1471 procedure Chain_CTC (PO : Node_Id) is
1472 S : Entity_Id;
1473
1474 begin
1475 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1476 Error_Pragma
1477 ("pragma% cannot be applied to abstract subprogram");
1478
1479 elsif Nkind (PO) = N_Entry_Declaration then
1480 Error_Pragma ("pragma% cannot be applied to entry");
1481
1482 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1483 N_Generic_Subprogram_Declaration)
1484 then
1485 Pragma_Misplaced;
1486 end if;
1487
1488 -- Here if we have [generic] subprogram declaration
1489
1490 S := Defining_Unit_Name (Specification (PO));
1491
1492 -- Note: we do not analyze the pragma at this point. Instead we
1493 -- delay this analysis until the end of the declarative part in
1494 -- which the pragma appears. This implements the required delay
1495 -- in this analysis, allowing forward references. The analysis
1496 -- happens at the end of Analyze_Declarations.
1497
1498 -- There should not be another contract-case or test-case with the
1499 -- same name associated to this subprogram.
1500
1501 declare
1502 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
1503 CTC : Node_Id;
1504
1505 begin
1506 CTC := Spec_CTC_List (Contract (S));
1507 while Present (CTC) loop
1508
1509 -- Omit pragma Contract_Cases because it does not introduce
1510 -- a unique case name and it does not follow the syntax of
1511 -- Contract_Case and Test_Case.
1512
1513 if Pragma_Name (CTC) = Name_Contract_Cases then
1514 null;
1515
1516 elsif String_Equal
1517 (Name, Get_Name_From_CTC_Pragma (CTC))
1518 then
1519 Error_Msg_Sloc := Sloc (CTC);
1520 Error_Pragma ("name for pragma% is already used#");
1521 end if;
1522
1523 CTC := Next_Pragma (CTC);
1524 end loop;
1525 end;
1526
1527 -- Chain spec CTC pragma to list for subprogram
1528
1529 Set_Next_Pragma (N, Spec_CTC_List (Contract (S)));
1530 Set_Spec_CTC_List (Contract (S), N);
1531 end Chain_CTC;
1532
1533 -- Start of processing for Check_Contract_Or_Test_Case
1534
1535 begin
1536 -- First check pragma arguments
1537
1538 GNAT_Pragma;
1539 Check_At_Least_N_Arguments (2);
1540 Check_At_Most_N_Arguments (4);
1541 Check_Arg_Order
1542 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
1543
1544 Check_Optional_Identifier (Arg1, Name_Name);
1545 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
1546
1547 -- In ASIS mode, for a pragma generated from a source aspect, also
1548 -- analyze the original aspect expression.
1549
1550 if ASIS_Mode
1551 and then Present (Corresponding_Aspect (N))
1552 then
1553 Check_Expr_Is_Static_Expression
1554 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
1555 end if;
1556
1557 Check_Optional_Identifier (Arg2, Name_Mode);
1558 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
1559
1560 if Arg_Count = 4 then
1561 Check_Identifier (Arg3, Name_Requires);
1562 Check_Identifier (Arg4, Name_Ensures);
1563
1564 elsif Arg_Count = 3 then
1565 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
1566 end if;
1567
1568 -- Check pragma placement
1569
1570 if not Is_List_Member (N) then
1571 Pragma_Misplaced;
1572 end if;
1573
1574 -- Contract-case or test-case should only appear in package spec unit
1575
1576 if Get_Source_Unit (N) = No_Unit
1577 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
1578 N_Package_Declaration,
1579 N_Generic_Package_Declaration)
1580 then
1581 Pragma_Misplaced;
1582 end if;
1583
1584 -- Search prior declarations
1585
1586 P := N;
1587 while Present (Prev (P)) loop
1588 P := Prev (P);
1589
1590 -- If the previous node is a generic subprogram, do not go to to
1591 -- the original node, which is the unanalyzed tree: we need to
1592 -- attach the contract-case or test-case to the analyzed version
1593 -- at this point. They get propagated to the original tree when
1594 -- analyzing the corresponding body.
1595
1596 if Nkind (P) not in N_Generic_Declaration then
1597 PO := Original_Node (P);
1598 else
1599 PO := P;
1600 end if;
1601
1602 -- Skip past prior pragma
1603
1604 if Nkind (PO) = N_Pragma then
1605 null;
1606
1607 -- Skip stuff not coming from source
1608
1609 elsif not Comes_From_Source (PO) then
1610 null;
1611
1612 -- Only remaining possibility is subprogram declaration. First
1613 -- check that it is declared directly in a package declaration.
1614 -- This may be either the package declaration for the current unit
1615 -- being defined or a local package declaration.
1616
1617 elsif not Present (Parent (Parent (PO)))
1618 or else not Present (Parent (Parent (Parent (PO))))
1619 or else not Nkind_In (Parent (Parent (PO)),
1620 N_Package_Declaration,
1621 N_Generic_Package_Declaration)
1622 then
1623 Pragma_Misplaced;
1624
1625 else
1626 Chain_CTC (PO);
1627 return;
1628 end if;
1629 end loop;
1630
1631 -- If we fall through, pragma was misplaced
1632
1633 Pragma_Misplaced;
1634 end Check_Contract_Or_Test_Case;
1635
1636 ----------------------------
1637 -- Check_Duplicate_Pragma --
1638 ----------------------------
1639
1640 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1641 Id : Entity_Id := E;
1642 P : Node_Id;
1643
1644 begin
1645 -- Nothing to do if this pragma comes from an aspect specification,
1646 -- since we could not be duplicating a pragma, and we dealt with the
1647 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1648
1649 if From_Aspect_Specification (N) then
1650 return;
1651 end if;
1652
1653 -- Otherwise current pragma may duplicate previous pragma or a
1654 -- previously given aspect specification or attribute definition
1655 -- clause for the same pragma.
1656
1657 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
1658
1659 if Present (P) then
1660 Error_Msg_Name_1 := Pragma_Name (N);
1661 Error_Msg_Sloc := Sloc (P);
1662
1663 -- For a single protected or a single task object, the error is
1664 -- issued on the original entity.
1665
1666 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
1667 Id := Defining_Identifier (Original_Node (Parent (Id)));
1668 end if;
1669
1670 if Nkind (P) = N_Aspect_Specification
1671 or else From_Aspect_Specification (P)
1672 then
1673 Error_Msg_NE ("aspect% for & previously given#", N, Id);
1674 else
1675 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
1676 end if;
1677
1678 raise Pragma_Exit;
1679 end if;
1680 end Check_Duplicate_Pragma;
1681
1682 ----------------------------------
1683 -- Check_Duplicated_Export_Name --
1684 ----------------------------------
1685
1686 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1687 String_Val : constant String_Id := Strval (Nam);
1688
1689 begin
1690 -- We are only interested in the export case, and in the case of
1691 -- generics, it is the instance, not the template, that is the
1692 -- problem (the template will generate a warning in any case).
1693
1694 if not Inside_A_Generic
1695 and then (Prag_Id = Pragma_Export
1696 or else
1697 Prag_Id = Pragma_Export_Procedure
1698 or else
1699 Prag_Id = Pragma_Export_Valued_Procedure
1700 or else
1701 Prag_Id = Pragma_Export_Function)
1702 then
1703 for J in Externals.First .. Externals.Last loop
1704 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1705 Error_Msg_Sloc := Sloc (Externals.Table (J));
1706 Error_Msg_N ("external name duplicates name given#", Nam);
1707 exit;
1708 end if;
1709 end loop;
1710
1711 Externals.Append (Nam);
1712 end if;
1713 end Check_Duplicated_Export_Name;
1714
1715 -------------------------------------
1716 -- Check_Expr_Is_Static_Expression --
1717 -------------------------------------
1718
1719 procedure Check_Expr_Is_Static_Expression
1720 (Expr : Node_Id;
1721 Typ : Entity_Id := Empty)
1722 is
1723 begin
1724 if Present (Typ) then
1725 Analyze_And_Resolve (Expr, Typ);
1726 else
1727 Analyze_And_Resolve (Expr);
1728 end if;
1729
1730 if Is_OK_Static_Expression (Expr) then
1731 return;
1732
1733 elsif Etype (Expr) = Any_Type then
1734 raise Pragma_Exit;
1735
1736 -- An interesting special case, if we have a string literal and we
1737 -- are in Ada 83 mode, then we allow it even though it will not be
1738 -- flagged as static. This allows the use of Ada 95 pragmas like
1739 -- Import in Ada 83 mode. They will of course be flagged with
1740 -- warnings as usual, but will not cause errors.
1741
1742 elsif Ada_Version = Ada_83
1743 and then Nkind (Expr) = N_String_Literal
1744 then
1745 return;
1746
1747 -- Static expression that raises Constraint_Error. This has already
1748 -- been flagged, so just exit from pragma processing.
1749
1750 elsif Is_Static_Expression (Expr) then
1751 raise Pragma_Exit;
1752
1753 -- Finally, we have a real error
1754
1755 else
1756 Error_Msg_Name_1 := Pname;
1757
1758 declare
1759 Msg : String :=
1760 "argument for pragma% must be a static expression!";
1761 begin
1762 Fix_Error (Msg);
1763 Flag_Non_Static_Expr (Msg, Expr);
1764 end;
1765
1766 raise Pragma_Exit;
1767 end if;
1768 end Check_Expr_Is_Static_Expression;
1769
1770 -------------------------
1771 -- Check_First_Subtype --
1772 -------------------------
1773
1774 procedure Check_First_Subtype (Arg : Node_Id) is
1775 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1776 Ent : constant Entity_Id := Entity (Argx);
1777
1778 begin
1779 if Is_First_Subtype (Ent) then
1780 null;
1781
1782 elsif Is_Type (Ent) then
1783 Error_Pragma_Arg
1784 ("pragma% cannot apply to subtype", Argx);
1785
1786 elsif Is_Object (Ent) then
1787 Error_Pragma_Arg
1788 ("pragma% cannot apply to object, requires a type", Argx);
1789
1790 else
1791 Error_Pragma_Arg
1792 ("pragma% cannot apply to&, requires a type", Argx);
1793 end if;
1794 end Check_First_Subtype;
1795
1796 ----------------------
1797 -- Check_Identifier --
1798 ----------------------
1799
1800 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1801 begin
1802 if Present (Arg)
1803 and then Nkind (Arg) = N_Pragma_Argument_Association
1804 then
1805 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1806 Error_Msg_Name_1 := Pname;
1807 Error_Msg_Name_2 := Id;
1808 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1809 raise Pragma_Exit;
1810 end if;
1811 end if;
1812 end Check_Identifier;
1813
1814 --------------------------------
1815 -- Check_Identifier_Is_One_Of --
1816 --------------------------------
1817
1818 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1819 begin
1820 if Present (Arg)
1821 and then Nkind (Arg) = N_Pragma_Argument_Association
1822 then
1823 if Chars (Arg) = No_Name then
1824 Error_Msg_Name_1 := Pname;
1825 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1826 raise Pragma_Exit;
1827
1828 elsif Chars (Arg) /= N1
1829 and then Chars (Arg) /= N2
1830 then
1831 Error_Msg_Name_1 := Pname;
1832 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1833 raise Pragma_Exit;
1834 end if;
1835 end if;
1836 end Check_Identifier_Is_One_Of;
1837
1838 ---------------------------
1839 -- Check_In_Main_Program --
1840 ---------------------------
1841
1842 procedure Check_In_Main_Program is
1843 P : constant Node_Id := Parent (N);
1844
1845 begin
1846 -- Must be at in subprogram body
1847
1848 if Nkind (P) /= N_Subprogram_Body then
1849 Error_Pragma ("% pragma allowed only in subprogram");
1850
1851 -- Otherwise warn if obviously not main program
1852
1853 elsif Present (Parameter_Specifications (Specification (P)))
1854 or else not Is_Compilation_Unit (Defining_Entity (P))
1855 then
1856 Error_Msg_Name_1 := Pname;
1857 Error_Msg_N
1858 ("??pragma% is only effective in main program", N);
1859 end if;
1860 end Check_In_Main_Program;
1861
1862 ---------------------------------------
1863 -- Check_Interrupt_Or_Attach_Handler --
1864 ---------------------------------------
1865
1866 procedure Check_Interrupt_Or_Attach_Handler is
1867 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1868 Handler_Proc, Proc_Scope : Entity_Id;
1869
1870 begin
1871 Analyze (Arg1_X);
1872
1873 if Prag_Id = Pragma_Interrupt_Handler then
1874 Check_Restriction (No_Dynamic_Attachment, N);
1875 end if;
1876
1877 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1878 Proc_Scope := Scope (Handler_Proc);
1879
1880 -- On AAMP only, a pragma Interrupt_Handler is supported for
1881 -- nonprotected parameterless procedures.
1882
1883 if not AAMP_On_Target
1884 or else Prag_Id = Pragma_Attach_Handler
1885 then
1886 if Ekind (Proc_Scope) /= E_Protected_Type then
1887 Error_Pragma_Arg
1888 ("argument of pragma% must be protected procedure", Arg1);
1889 end if;
1890
1891 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1892 Error_Pragma ("pragma% must be in protected definition");
1893 end if;
1894 end if;
1895
1896 if not Is_Library_Level_Entity (Proc_Scope)
1897 or else (AAMP_On_Target
1898 and then not Is_Library_Level_Entity (Handler_Proc))
1899 then
1900 Error_Pragma_Arg
1901 ("argument for pragma% must be library level entity", Arg1);
1902 end if;
1903
1904 -- AI05-0033: A pragma cannot appear within a generic body, because
1905 -- instance can be in a nested scope. The check that protected type
1906 -- is itself a library-level declaration is done elsewhere.
1907
1908 -- Note: we omit this check in Codepeer mode to properly handle code
1909 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1910
1911 if Inside_A_Generic then
1912 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1913 and then In_Package_Body (Scope (Current_Scope))
1914 and then not CodePeer_Mode
1915 then
1916 Error_Pragma ("pragma% cannot be used inside a generic");
1917 end if;
1918 end if;
1919 end Check_Interrupt_Or_Attach_Handler;
1920
1921 --------------------------------------------
1922 -- Check_Loop_Invariant_Variant_Placement --
1923 --------------------------------------------
1924
1925 procedure Check_Loop_Invariant_Variant_Placement is
1926 procedure Placement_Error (Constr : Node_Id);
1927 pragma No_Return (Placement_Error);
1928 -- Node Constr denotes the last loop restricted construct before we
1929 -- encountered an illegal relation between enclosing constructs. Emit
1930 -- an error depending on what Constr was.
1931
1932 ---------------------
1933 -- Placement_Error --
1934 ---------------------
1935
1936 procedure Placement_Error (Constr : Node_Id) is
1937 begin
1938 if Nkind (Constr) = N_Pragma then
1939 Error_Pragma
1940 ("pragma % must appear immediately within the statements " &
1941 "of a loop");
1942 else
1943 Error_Pragma_Arg
1944 ("block containing pragma % must appear immediately within " &
1945 "the statements of a loop", Constr);
1946 end if;
1947 end Placement_Error;
1948
1949 -- Local declarations
1950
1951 Prev : Node_Id;
1952 Stmt : Node_Id;
1953
1954 -- Start of processing for Check_Loop_Invariant_Variant_Placement
1955
1956 begin
1957 Prev := N;
1958 Stmt := Parent (N);
1959 while Present (Stmt) loop
1960
1961 -- The pragma or previous block must appear immediately within the
1962 -- current block's declarative or statement part.
1963
1964 if Nkind (Stmt) = N_Block_Statement then
1965 if (No (Declarations (Stmt))
1966 or else List_Containing (Prev) /= Declarations (Stmt))
1967 and then
1968 List_Containing (Prev) /=
1969 Statements (Handled_Statement_Sequence (Stmt))
1970 then
1971 Placement_Error (Prev);
1972 return;
1973
1974 -- Keep inspecting the parents because we are now within a
1975 -- chain of nested blocks.
1976
1977 else
1978 Prev := Stmt;
1979 Stmt := Parent (Stmt);
1980 end if;
1981
1982 -- The pragma or previous block must appear immediately within the
1983 -- statements of the loop.
1984
1985 elsif Nkind (Stmt) = N_Loop_Statement then
1986 if List_Containing (Prev) /= Statements (Stmt) then
1987 Placement_Error (Prev);
1988 end if;
1989
1990 -- Stop the traversal because we reached the innermost loop
1991 -- regardless of whether we encountered an error or not.
1992
1993 return;
1994
1995 -- Ignore a handled statement sequence. Note that this node may
1996 -- be related to a subprogram body in which case we will emit an
1997 -- error on the next iteration of the search.
1998
1999 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
2000 Stmt := Parent (Stmt);
2001
2002 -- Any other statement breaks the chain from the pragma to the
2003 -- loop.
2004
2005 else
2006 Placement_Error (Prev);
2007 return;
2008 end if;
2009 end loop;
2010 end Check_Loop_Invariant_Variant_Placement;
2011
2012 -------------------------------------------
2013 -- Check_Is_In_Decl_Part_Or_Package_Spec --
2014 -------------------------------------------
2015
2016 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
2017 P : Node_Id;
2018
2019 begin
2020 P := Parent (N);
2021 loop
2022 if No (P) then
2023 exit;
2024
2025 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
2026 exit;
2027
2028 elsif Nkind_In (P, N_Package_Specification,
2029 N_Block_Statement)
2030 then
2031 return;
2032
2033 -- Note: the following tests seem a little peculiar, because
2034 -- they test for bodies, but if we were in the statement part
2035 -- of the body, we would already have hit the handled statement
2036 -- sequence, so the only way we get here is by being in the
2037 -- declarative part of the body.
2038
2039 elsif Nkind_In (P, N_Subprogram_Body,
2040 N_Package_Body,
2041 N_Task_Body,
2042 N_Entry_Body)
2043 then
2044 return;
2045 end if;
2046
2047 P := Parent (P);
2048 end loop;
2049
2050 Error_Pragma ("pragma% is not in declarative part or package spec");
2051 end Check_Is_In_Decl_Part_Or_Package_Spec;
2052
2053 -------------------------
2054 -- Check_No_Identifier --
2055 -------------------------
2056
2057 procedure Check_No_Identifier (Arg : Node_Id) is
2058 begin
2059 if Nkind (Arg) = N_Pragma_Argument_Association
2060 and then Chars (Arg) /= No_Name
2061 then
2062 Error_Pragma_Arg_Ident
2063 ("pragma% does not permit identifier& here", Arg);
2064 end if;
2065 end Check_No_Identifier;
2066
2067 --------------------------
2068 -- Check_No_Identifiers --
2069 --------------------------
2070
2071 procedure Check_No_Identifiers is
2072 Arg_Node : Node_Id;
2073 begin
2074 if Arg_Count > 0 then
2075 Arg_Node := Arg1;
2076 while Present (Arg_Node) loop
2077 Check_No_Identifier (Arg_Node);
2078 Next (Arg_Node);
2079 end loop;
2080 end if;
2081 end Check_No_Identifiers;
2082
2083 ------------------------
2084 -- Check_No_Link_Name --
2085 ------------------------
2086
2087 procedure Check_No_Link_Name is
2088 begin
2089 if Present (Arg3)
2090 and then Chars (Arg3) = Name_Link_Name
2091 then
2092 Arg4 := Arg3;
2093 end if;
2094
2095 if Present (Arg4) then
2096 Error_Pragma_Arg
2097 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
2098 end if;
2099 end Check_No_Link_Name;
2100
2101 -------------------------------
2102 -- Check_Optional_Identifier --
2103 -------------------------------
2104
2105 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
2106 begin
2107 if Present (Arg)
2108 and then Nkind (Arg) = N_Pragma_Argument_Association
2109 and then Chars (Arg) /= No_Name
2110 then
2111 if Chars (Arg) /= Id then
2112 Error_Msg_Name_1 := Pname;
2113 Error_Msg_Name_2 := Id;
2114 Error_Msg_N ("pragma% argument expects identifier%", Arg);
2115 raise Pragma_Exit;
2116 end if;
2117 end if;
2118 end Check_Optional_Identifier;
2119
2120 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
2121 begin
2122 Name_Buffer (1 .. Id'Length) := Id;
2123 Name_Len := Id'Length;
2124 Check_Optional_Identifier (Arg, Name_Find);
2125 end Check_Optional_Identifier;
2126
2127 --------------------------------------
2128 -- Check_Precondition_Postcondition --
2129 --------------------------------------
2130
2131 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
2132 P : Node_Id;
2133 PO : Node_Id;
2134
2135 procedure Chain_PPC (PO : Node_Id);
2136 -- If PO is an entry or a [generic] subprogram declaration node, then
2137 -- the precondition/postcondition applies to this subprogram and the
2138 -- processing for the pragma is completed. Otherwise the pragma is
2139 -- misplaced.
2140
2141 ---------------
2142 -- Chain_PPC --
2143 ---------------
2144
2145 procedure Chain_PPC (PO : Node_Id) is
2146 S : Entity_Id;
2147
2148 begin
2149 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2150 if not From_Aspect_Specification (N) then
2151 Error_Pragma
2152 ("pragma% cannot be applied to abstract subprogram");
2153
2154 elsif Class_Present (N) then
2155 null;
2156
2157 else
2158 Error_Pragma
2159 ("aspect % requires ''Class for abstract subprogram");
2160 end if;
2161
2162 -- AI05-0230: The same restriction applies to null procedures. For
2163 -- compatibility with earlier uses of the Ada pragma, apply this
2164 -- rule only to aspect specifications.
2165
2166 -- The above discrpency needs documentation. Robert is dubious
2167 -- about whether it is a good idea ???
2168
2169 elsif Nkind (PO) = N_Subprogram_Declaration
2170 and then Nkind (Specification (PO)) = N_Procedure_Specification
2171 and then Null_Present (Specification (PO))
2172 and then From_Aspect_Specification (N)
2173 and then not Class_Present (N)
2174 then
2175 Error_Pragma
2176 ("aspect % requires ''Class for null procedure");
2177
2178 -- Pre/postconditions are legal on a subprogram body if it is not
2179 -- a completion of a declaration.
2180
2181 elsif Nkind (PO) = N_Subprogram_Body
2182 and then Acts_As_Spec (PO)
2183 then
2184 null;
2185
2186 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2187 N_Expression_Function,
2188 N_Generic_Subprogram_Declaration,
2189 N_Entry_Declaration)
2190 then
2191 Pragma_Misplaced;
2192 end if;
2193
2194 -- Here if we have [generic] subprogram or entry declaration
2195
2196 if Nkind (PO) = N_Entry_Declaration then
2197 S := Defining_Entity (PO);
2198 else
2199 S := Defining_Unit_Name (Specification (PO));
2200
2201 if Nkind (S) = N_Defining_Program_Unit_Name then
2202 S := Defining_Identifier (S);
2203 end if;
2204 end if;
2205
2206 -- Note: we do not analyze the pragma at this point. Instead we
2207 -- delay this analysis until the end of the declarative part in
2208 -- which the pragma appears. This implements the required delay
2209 -- in this analysis, allowing forward references. The analysis
2210 -- happens at the end of Analyze_Declarations.
2211
2212 -- Chain spec PPC pragma to list for subprogram
2213
2214 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
2215 Set_Spec_PPC_List (Contract (S), N);
2216
2217 -- Return indicating spec case
2218
2219 In_Body := False;
2220 return;
2221 end Chain_PPC;
2222
2223 -- Start of processing for Check_Precondition_Postcondition
2224
2225 begin
2226 if not Is_List_Member (N) then
2227 Pragma_Misplaced;
2228 end if;
2229
2230 -- Preanalyze message argument if present. Visibility in this
2231 -- argument is established at the point of pragma occurrence.
2232
2233 if Arg_Count = 2 then
2234 Check_Optional_Identifier (Arg2, Name_Message);
2235 Preanalyze_Spec_Expression
2236 (Get_Pragma_Arg (Arg2), Standard_String);
2237 end if;
2238
2239 -- For a pragma PPC in the extended main source unit, record enabled
2240 -- status in SCO.
2241
2242 -- This may seem redundant with the call to Check_Enabled occurring
2243 -- later on when the pragma is rewritten into a pragma Check but
2244 -- is actually required in the case of a postcondition within a
2245 -- generic.
2246
2247 if Check_Enabled (Pname) and then not Split_PPC (N) then
2248 Set_SCO_Pragma_Enabled (Loc);
2249 end if;
2250
2251 -- If we are within an inlined body, the legality of the pragma
2252 -- has been checked already.
2253
2254 if In_Inlined_Body then
2255 In_Body := True;
2256 return;
2257 end if;
2258
2259 -- Search prior declarations
2260
2261 P := N;
2262 while Present (Prev (P)) loop
2263 P := Prev (P);
2264
2265 -- If the previous node is a generic subprogram, do not go to to
2266 -- the original node, which is the unanalyzed tree: we need to
2267 -- attach the pre/postconditions to the analyzed version at this
2268 -- point. They get propagated to the original tree when analyzing
2269 -- the corresponding body.
2270
2271 if Nkind (P) not in N_Generic_Declaration then
2272 PO := Original_Node (P);
2273 else
2274 PO := P;
2275 end if;
2276
2277 -- Skip past prior pragma
2278
2279 if Nkind (PO) = N_Pragma then
2280 null;
2281
2282 -- Skip stuff not coming from source
2283
2284 elsif not Comes_From_Source (PO) then
2285
2286 -- The condition may apply to a subprogram instantiation
2287
2288 if Nkind (PO) = N_Subprogram_Declaration
2289 and then Present (Generic_Parent (Specification (PO)))
2290 then
2291 Chain_PPC (PO);
2292 return;
2293
2294 elsif Nkind (PO) = N_Subprogram_Declaration
2295 and then In_Instance
2296 then
2297 Chain_PPC (PO);
2298 return;
2299
2300 -- For all other cases of non source code, do nothing
2301
2302 else
2303 null;
2304 end if;
2305
2306 -- Only remaining possibility is subprogram declaration
2307
2308 else
2309 Chain_PPC (PO);
2310 return;
2311 end if;
2312 end loop;
2313
2314 -- If we fall through loop, pragma is at start of list, so see if it
2315 -- is at the start of declarations of a subprogram body.
2316
2317 if Nkind (Parent (N)) = N_Subprogram_Body
2318 and then List_Containing (N) = Declarations (Parent (N))
2319 then
2320 if Operating_Mode /= Generate_Code
2321 or else Inside_A_Generic
2322 then
2323 -- Analyze pragma expression for correctness and for ASIS use
2324
2325 Preanalyze_Assert_Expression
2326 (Get_Pragma_Arg (Arg1), Standard_Boolean);
2327
2328 -- In ASIS mode, for a pragma generated from a source aspect,
2329 -- also analyze the original aspect expression.
2330
2331 if ASIS_Mode
2332 and then Present (Corresponding_Aspect (N))
2333 then
2334 Preanalyze_Assert_Expression
2335 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2336 end if;
2337 end if;
2338
2339 In_Body := True;
2340 return;
2341
2342 -- See if it is in the pragmas after a library level subprogram
2343
2344 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2345
2346 -- In formal verification mode, analyze pragma expression for
2347 -- correctness, as it is not expanded later.
2348
2349 if Alfa_Mode then
2350 Analyze_PPC_In_Decl_Part
2351 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2352 end if;
2353
2354 Chain_PPC (Unit (Parent (Parent (N))));
2355 return;
2356 end if;
2357
2358 -- If we fall through, pragma was misplaced
2359
2360 Pragma_Misplaced;
2361 end Check_Precondition_Postcondition;
2362
2363 -----------------------------
2364 -- Check_Static_Constraint --
2365 -----------------------------
2366
2367 -- Note: for convenience in writing this procedure, in addition to
2368 -- the officially (i.e. by spec) allowed argument which is always a
2369 -- constraint, it also allows ranges and discriminant associations.
2370 -- Above is not clear ???
2371
2372 procedure Check_Static_Constraint (Constr : Node_Id) is
2373
2374 procedure Require_Static (E : Node_Id);
2375 -- Require given expression to be static expression
2376
2377 --------------------
2378 -- Require_Static --
2379 --------------------
2380
2381 procedure Require_Static (E : Node_Id) is
2382 begin
2383 if not Is_OK_Static_Expression (E) then
2384 Flag_Non_Static_Expr
2385 ("non-static constraint not allowed in Unchecked_Union!", E);
2386 raise Pragma_Exit;
2387 end if;
2388 end Require_Static;
2389
2390 -- Start of processing for Check_Static_Constraint
2391
2392 begin
2393 case Nkind (Constr) is
2394 when N_Discriminant_Association =>
2395 Require_Static (Expression (Constr));
2396
2397 when N_Range =>
2398 Require_Static (Low_Bound (Constr));
2399 Require_Static (High_Bound (Constr));
2400
2401 when N_Attribute_Reference =>
2402 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2403 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2404
2405 when N_Range_Constraint =>
2406 Check_Static_Constraint (Range_Expression (Constr));
2407
2408 when N_Index_Or_Discriminant_Constraint =>
2409 declare
2410 IDC : Entity_Id;
2411 begin
2412 IDC := First (Constraints (Constr));
2413 while Present (IDC) loop
2414 Check_Static_Constraint (IDC);
2415 Next (IDC);
2416 end loop;
2417 end;
2418
2419 when others =>
2420 null;
2421 end case;
2422 end Check_Static_Constraint;
2423
2424 --------------------------------------
2425 -- Check_Valid_Configuration_Pragma --
2426 --------------------------------------
2427
2428 -- A configuration pragma must appear in the context clause of a
2429 -- compilation unit, and only other pragmas may precede it. Note that
2430 -- the test also allows use in a configuration pragma file.
2431
2432 procedure Check_Valid_Configuration_Pragma is
2433 begin
2434 if not Is_Configuration_Pragma then
2435 Error_Pragma ("incorrect placement for configuration pragma%");
2436 end if;
2437 end Check_Valid_Configuration_Pragma;
2438
2439 -------------------------------------
2440 -- Check_Valid_Library_Unit_Pragma --
2441 -------------------------------------
2442
2443 procedure Check_Valid_Library_Unit_Pragma is
2444 Plist : List_Id;
2445 Parent_Node : Node_Id;
2446 Unit_Name : Entity_Id;
2447 Unit_Kind : Node_Kind;
2448 Unit_Node : Node_Id;
2449 Sindex : Source_File_Index;
2450
2451 begin
2452 if not Is_List_Member (N) then
2453 Pragma_Misplaced;
2454
2455 else
2456 Plist := List_Containing (N);
2457 Parent_Node := Parent (Plist);
2458
2459 if Parent_Node = Empty then
2460 Pragma_Misplaced;
2461
2462 -- Case of pragma appearing after a compilation unit. In this case
2463 -- it must have an argument with the corresponding name and must
2464 -- be part of the following pragmas of its parent.
2465
2466 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2467 if Plist /= Pragmas_After (Parent_Node) then
2468 Pragma_Misplaced;
2469
2470 elsif Arg_Count = 0 then
2471 Error_Pragma
2472 ("argument required if outside compilation unit");
2473
2474 else
2475 Check_No_Identifiers;
2476 Check_Arg_Count (1);
2477 Unit_Node := Unit (Parent (Parent_Node));
2478 Unit_Kind := Nkind (Unit_Node);
2479
2480 Analyze (Get_Pragma_Arg (Arg1));
2481
2482 if Unit_Kind = N_Generic_Subprogram_Declaration
2483 or else Unit_Kind = N_Subprogram_Declaration
2484 then
2485 Unit_Name := Defining_Entity (Unit_Node);
2486
2487 elsif Unit_Kind in N_Generic_Instantiation then
2488 Unit_Name := Defining_Entity (Unit_Node);
2489
2490 else
2491 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2492 end if;
2493
2494 if Chars (Unit_Name) /=
2495 Chars (Entity (Get_Pragma_Arg (Arg1)))
2496 then
2497 Error_Pragma_Arg
2498 ("pragma% argument is not current unit name", Arg1);
2499 end if;
2500
2501 if Ekind (Unit_Name) = E_Package
2502 and then Present (Renamed_Entity (Unit_Name))
2503 then
2504 Error_Pragma ("pragma% not allowed for renamed package");
2505 end if;
2506 end if;
2507
2508 -- Pragma appears other than after a compilation unit
2509
2510 else
2511 -- Here we check for the generic instantiation case and also
2512 -- for the case of processing a generic formal package. We
2513 -- detect these cases by noting that the Sloc on the node
2514 -- does not belong to the current compilation unit.
2515
2516 Sindex := Source_Index (Current_Sem_Unit);
2517
2518 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2519 Rewrite (N, Make_Null_Statement (Loc));
2520 return;
2521
2522 -- If before first declaration, the pragma applies to the
2523 -- enclosing unit, and the name if present must be this name.
2524
2525 elsif Is_Before_First_Decl (N, Plist) then
2526 Unit_Node := Unit_Declaration_Node (Current_Scope);
2527 Unit_Kind := Nkind (Unit_Node);
2528
2529 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2530 Pragma_Misplaced;
2531
2532 elsif Unit_Kind = N_Subprogram_Body
2533 and then not Acts_As_Spec (Unit_Node)
2534 then
2535 Pragma_Misplaced;
2536
2537 elsif Nkind (Parent_Node) = N_Package_Body then
2538 Pragma_Misplaced;
2539
2540 elsif Nkind (Parent_Node) = N_Package_Specification
2541 and then Plist = Private_Declarations (Parent_Node)
2542 then
2543 Pragma_Misplaced;
2544
2545 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2546 or else Nkind (Parent_Node) =
2547 N_Generic_Subprogram_Declaration)
2548 and then Plist = Generic_Formal_Declarations (Parent_Node)
2549 then
2550 Pragma_Misplaced;
2551
2552 elsif Arg_Count > 0 then
2553 Analyze (Get_Pragma_Arg (Arg1));
2554
2555 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2556 Error_Pragma_Arg
2557 ("name in pragma% must be enclosing unit", Arg1);
2558 end if;
2559
2560 -- It is legal to have no argument in this context
2561
2562 else
2563 return;
2564 end if;
2565
2566 -- Error if not before first declaration. This is because a
2567 -- library unit pragma argument must be the name of a library
2568 -- unit (RM 10.1.5(7)), but the only names permitted in this
2569 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2570 -- generic subprogram declarations or generic instantiations.
2571
2572 else
2573 Error_Pragma
2574 ("pragma% misplaced, must be before first declaration");
2575 end if;
2576 end if;
2577 end if;
2578 end Check_Valid_Library_Unit_Pragma;
2579
2580 -------------------
2581 -- Check_Variant --
2582 -------------------
2583
2584 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2585 Clist : constant Node_Id := Component_List (Variant);
2586 Comp : Node_Id;
2587
2588 begin
2589 Comp := First (Component_Items (Clist));
2590 while Present (Comp) loop
2591 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2592 Next (Comp);
2593 end loop;
2594 end Check_Variant;
2595
2596 ------------------
2597 -- Error_Pragma --
2598 ------------------
2599
2600 procedure Error_Pragma (Msg : String) is
2601 MsgF : String := Msg;
2602 begin
2603 Error_Msg_Name_1 := Pname;
2604 Fix_Error (MsgF);
2605 Error_Msg_N (MsgF, N);
2606 raise Pragma_Exit;
2607 end Error_Pragma;
2608
2609 ----------------------
2610 -- Error_Pragma_Arg --
2611 ----------------------
2612
2613 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2614 MsgF : String := Msg;
2615 begin
2616 Error_Msg_Name_1 := Pname;
2617 Fix_Error (MsgF);
2618 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2619 raise Pragma_Exit;
2620 end Error_Pragma_Arg;
2621
2622 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2623 MsgF : String := Msg1;
2624 begin
2625 Error_Msg_Name_1 := Pname;
2626 Fix_Error (MsgF);
2627 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2628 Error_Pragma_Arg (Msg2, Arg);
2629 end Error_Pragma_Arg;
2630
2631 ----------------------------
2632 -- Error_Pragma_Arg_Ident --
2633 ----------------------------
2634
2635 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2636 MsgF : String := Msg;
2637 begin
2638 Error_Msg_Name_1 := Pname;
2639 Fix_Error (MsgF);
2640 Error_Msg_N (MsgF, Arg);
2641 raise Pragma_Exit;
2642 end Error_Pragma_Arg_Ident;
2643
2644 ----------------------
2645 -- Error_Pragma_Ref --
2646 ----------------------
2647
2648 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2649 MsgF : String := Msg;
2650 begin
2651 Error_Msg_Name_1 := Pname;
2652 Fix_Error (MsgF);
2653 Error_Msg_Sloc := Sloc (Ref);
2654 Error_Msg_NE (MsgF, N, Ref);
2655 raise Pragma_Exit;
2656 end Error_Pragma_Ref;
2657
2658 ------------------------
2659 -- Find_Lib_Unit_Name --
2660 ------------------------
2661
2662 function Find_Lib_Unit_Name return Entity_Id is
2663 begin
2664 -- Return inner compilation unit entity, for case of nested
2665 -- categorization pragmas. This happens in generic unit.
2666
2667 if Nkind (Parent (N)) = N_Package_Specification
2668 and then Defining_Entity (Parent (N)) /= Current_Scope
2669 then
2670 return Defining_Entity (Parent (N));
2671 else
2672 return Current_Scope;
2673 end if;
2674 end Find_Lib_Unit_Name;
2675
2676 ----------------------------
2677 -- Find_Program_Unit_Name --
2678 ----------------------------
2679
2680 procedure Find_Program_Unit_Name (Id : Node_Id) is
2681 Unit_Name : Entity_Id;
2682 Unit_Kind : Node_Kind;
2683 P : constant Node_Id := Parent (N);
2684
2685 begin
2686 if Nkind (P) = N_Compilation_Unit then
2687 Unit_Kind := Nkind (Unit (P));
2688
2689 if Unit_Kind = N_Subprogram_Declaration
2690 or else Unit_Kind = N_Package_Declaration
2691 or else Unit_Kind in N_Generic_Declaration
2692 then
2693 Unit_Name := Defining_Entity (Unit (P));
2694
2695 if Chars (Id) = Chars (Unit_Name) then
2696 Set_Entity (Id, Unit_Name);
2697 Set_Etype (Id, Etype (Unit_Name));
2698 else
2699 Set_Etype (Id, Any_Type);
2700 Error_Pragma
2701 ("cannot find program unit referenced by pragma%");
2702 end if;
2703
2704 else
2705 Set_Etype (Id, Any_Type);
2706 Error_Pragma ("pragma% inapplicable to this unit");
2707 end if;
2708
2709 else
2710 Analyze (Id);
2711 end if;
2712 end Find_Program_Unit_Name;
2713
2714 -----------------------------------------
2715 -- Find_Unique_Parameterless_Procedure --
2716 -----------------------------------------
2717
2718 function Find_Unique_Parameterless_Procedure
2719 (Name : Entity_Id;
2720 Arg : Node_Id) return Entity_Id
2721 is
2722 Proc : Entity_Id := Empty;
2723
2724 begin
2725 -- The body of this procedure needs some comments ???
2726
2727 if not Is_Entity_Name (Name) then
2728 Error_Pragma_Arg
2729 ("argument of pragma% must be entity name", Arg);
2730
2731 elsif not Is_Overloaded (Name) then
2732 Proc := Entity (Name);
2733
2734 if Ekind (Proc) /= E_Procedure
2735 or else Present (First_Formal (Proc))
2736 then
2737 Error_Pragma_Arg
2738 ("argument of pragma% must be parameterless procedure", Arg);
2739 end if;
2740
2741 else
2742 declare
2743 Found : Boolean := False;
2744 It : Interp;
2745 Index : Interp_Index;
2746
2747 begin
2748 Get_First_Interp (Name, Index, It);
2749 while Present (It.Nam) loop
2750 Proc := It.Nam;
2751
2752 if Ekind (Proc) = E_Procedure
2753 and then No (First_Formal (Proc))
2754 then
2755 if not Found then
2756 Found := True;
2757 Set_Entity (Name, Proc);
2758 Set_Is_Overloaded (Name, False);
2759 else
2760 Error_Pragma_Arg
2761 ("ambiguous handler name for pragma% ", Arg);
2762 end if;
2763 end if;
2764
2765 Get_Next_Interp (Index, It);
2766 end loop;
2767
2768 if not Found then
2769 Error_Pragma_Arg
2770 ("argument of pragma% must be parameterless procedure",
2771 Arg);
2772 else
2773 Proc := Entity (Name);
2774 end if;
2775 end;
2776 end if;
2777
2778 return Proc;
2779 end Find_Unique_Parameterless_Procedure;
2780
2781 ---------------
2782 -- Fix_Error --
2783 ---------------
2784
2785 procedure Fix_Error (Msg : in out String) is
2786 begin
2787 if From_Aspect_Specification (N) then
2788 for J in Msg'First .. Msg'Last - 5 loop
2789 if Msg (J .. J + 5) = "pragma" then
2790 Msg (J .. J + 5) := "aspect";
2791 end if;
2792 end loop;
2793
2794 if Error_Msg_Name_1 = Name_Precondition then
2795 Error_Msg_Name_1 := Name_Pre;
2796 elsif Error_Msg_Name_1 = Name_Postcondition then
2797 Error_Msg_Name_1 := Name_Post;
2798 end if;
2799 end if;
2800 end Fix_Error;
2801
2802 -------------------------
2803 -- Gather_Associations --
2804 -------------------------
2805
2806 procedure Gather_Associations
2807 (Names : Name_List;
2808 Args : out Args_List)
2809 is
2810 Arg : Node_Id;
2811
2812 begin
2813 -- Initialize all parameters to Empty
2814
2815 for J in Args'Range loop
2816 Args (J) := Empty;
2817 end loop;
2818
2819 -- That's all we have to do if there are no argument associations
2820
2821 if No (Pragma_Argument_Associations (N)) then
2822 return;
2823 end if;
2824
2825 -- Otherwise first deal with any positional parameters present
2826
2827 Arg := First (Pragma_Argument_Associations (N));
2828 for Index in Args'Range loop
2829 exit when No (Arg) or else Chars (Arg) /= No_Name;
2830 Args (Index) := Get_Pragma_Arg (Arg);
2831 Next (Arg);
2832 end loop;
2833
2834 -- Positional parameters all processed, if any left, then we
2835 -- have too many positional parameters.
2836
2837 if Present (Arg) and then Chars (Arg) = No_Name then
2838 Error_Pragma_Arg
2839 ("too many positional associations for pragma%", Arg);
2840 end if;
2841
2842 -- Process named parameters if any are present
2843
2844 while Present (Arg) loop
2845 if Chars (Arg) = No_Name then
2846 Error_Pragma_Arg
2847 ("positional association cannot follow named association",
2848 Arg);
2849
2850 else
2851 for Index in Names'Range loop
2852 if Names (Index) = Chars (Arg) then
2853 if Present (Args (Index)) then
2854 Error_Pragma_Arg
2855 ("duplicate argument association for pragma%", Arg);
2856 else
2857 Args (Index) := Get_Pragma_Arg (Arg);
2858 exit;
2859 end if;
2860 end if;
2861
2862 if Index = Names'Last then
2863 Error_Msg_Name_1 := Pname;
2864 Error_Msg_N ("pragma% does not allow & argument", Arg);
2865
2866 -- Check for possible misspelling
2867
2868 for Index1 in Names'Range loop
2869 if Is_Bad_Spelling_Of
2870 (Chars (Arg), Names (Index1))
2871 then
2872 Error_Msg_Name_1 := Names (Index1);
2873 Error_Msg_N -- CODEFIX
2874 ("\possible misspelling of%", Arg);
2875 exit;
2876 end if;
2877 end loop;
2878
2879 raise Pragma_Exit;
2880 end if;
2881 end loop;
2882 end if;
2883
2884 Next (Arg);
2885 end loop;
2886 end Gather_Associations;
2887
2888 -----------------
2889 -- GNAT_Pragma --
2890 -----------------
2891
2892 procedure GNAT_Pragma is
2893 begin
2894 -- We need to check the No_Implementation_Pragmas restriction for
2895 -- the case of a pragma from source. Note that the case of aspects
2896 -- generating corresponding pragmas marks these pragmas as not being
2897 -- from source, so this test also catches that case.
2898
2899 if Comes_From_Source (N) then
2900 Check_Restriction (No_Implementation_Pragmas, N);
2901 end if;
2902 end GNAT_Pragma;
2903
2904 --------------------------
2905 -- Is_Before_First_Decl --
2906 --------------------------
2907
2908 function Is_Before_First_Decl
2909 (Pragma_Node : Node_Id;
2910 Decls : List_Id) return Boolean
2911 is
2912 Item : Node_Id := First (Decls);
2913
2914 begin
2915 -- Only other pragmas can come before this pragma
2916
2917 loop
2918 if No (Item) or else Nkind (Item) /= N_Pragma then
2919 return False;
2920
2921 elsif Item = Pragma_Node then
2922 return True;
2923 end if;
2924
2925 Next (Item);
2926 end loop;
2927 end Is_Before_First_Decl;
2928
2929 -----------------------------
2930 -- Is_Configuration_Pragma --
2931 -----------------------------
2932
2933 -- A configuration pragma must appear in the context clause of a
2934 -- compilation unit, and only other pragmas may precede it. Note that
2935 -- the test below also permits use in a configuration pragma file.
2936
2937 function Is_Configuration_Pragma return Boolean is
2938 Lis : constant List_Id := List_Containing (N);
2939 Par : constant Node_Id := Parent (N);
2940 Prg : Node_Id;
2941
2942 begin
2943 -- If no parent, then we are in the configuration pragma file,
2944 -- so the placement is definitely appropriate.
2945
2946 if No (Par) then
2947 return True;
2948
2949 -- Otherwise we must be in the context clause of a compilation unit
2950 -- and the only thing allowed before us in the context list is more
2951 -- configuration pragmas.
2952
2953 elsif Nkind (Par) = N_Compilation_Unit
2954 and then Context_Items (Par) = Lis
2955 then
2956 Prg := First (Lis);
2957
2958 loop
2959 if Prg = N then
2960 return True;
2961 elsif Nkind (Prg) /= N_Pragma then
2962 return False;
2963 end if;
2964
2965 Next (Prg);
2966 end loop;
2967
2968 else
2969 return False;
2970 end if;
2971 end Is_Configuration_Pragma;
2972
2973 --------------------------
2974 -- Is_In_Context_Clause --
2975 --------------------------
2976
2977 function Is_In_Context_Clause return Boolean is
2978 Plist : List_Id;
2979 Parent_Node : Node_Id;
2980
2981 begin
2982 if not Is_List_Member (N) then
2983 return False;
2984
2985 else
2986 Plist := List_Containing (N);
2987 Parent_Node := Parent (Plist);
2988
2989 if Parent_Node = Empty
2990 or else Nkind (Parent_Node) /= N_Compilation_Unit
2991 or else Context_Items (Parent_Node) /= Plist
2992 then
2993 return False;
2994 end if;
2995 end if;
2996
2997 return True;
2998 end Is_In_Context_Clause;
2999
3000 ---------------------------------
3001 -- Is_Static_String_Expression --
3002 ---------------------------------
3003
3004 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
3005 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3006
3007 begin
3008 Analyze_And_Resolve (Argx);
3009 return Is_OK_Static_Expression (Argx)
3010 and then Nkind (Argx) = N_String_Literal;
3011 end Is_Static_String_Expression;
3012
3013 ----------------------
3014 -- Pragma_Misplaced --
3015 ----------------------
3016
3017 procedure Pragma_Misplaced is
3018 begin
3019 Error_Pragma ("incorrect placement of pragma%");
3020 end Pragma_Misplaced;
3021
3022 ------------------------------------
3023 -- Process_Atomic_Shared_Volatile --
3024 ------------------------------------
3025
3026 procedure Process_Atomic_Shared_Volatile is
3027 E_Id : Node_Id;
3028 E : Entity_Id;
3029 D : Node_Id;
3030 K : Node_Kind;
3031 Utyp : Entity_Id;
3032
3033 procedure Set_Atomic (E : Entity_Id);
3034 -- Set given type as atomic, and if no explicit alignment was given,
3035 -- set alignment to unknown, since back end knows what the alignment
3036 -- requirements are for atomic arrays. Note: this step is necessary
3037 -- for derived types.
3038
3039 ----------------
3040 -- Set_Atomic --
3041 ----------------
3042
3043 procedure Set_Atomic (E : Entity_Id) is
3044 begin
3045 Set_Is_Atomic (E);
3046
3047 if not Has_Alignment_Clause (E) then
3048 Set_Alignment (E, Uint_0);
3049 end if;
3050 end Set_Atomic;
3051
3052 -- Start of processing for Process_Atomic_Shared_Volatile
3053
3054 begin
3055 Check_Ada_83_Warning;
3056 Check_No_Identifiers;
3057 Check_Arg_Count (1);
3058 Check_Arg_Is_Local_Name (Arg1);
3059 E_Id := Get_Pragma_Arg (Arg1);
3060
3061 if Etype (E_Id) = Any_Type then
3062 return;
3063 end if;
3064
3065 E := Entity (E_Id);
3066 D := Declaration_Node (E);
3067 K := Nkind (D);
3068
3069 -- Check duplicate before we chain ourselves!
3070
3071 Check_Duplicate_Pragma (E);
3072
3073 -- Now check appropriateness of the entity
3074
3075 if Is_Type (E) then
3076 if Rep_Item_Too_Early (E, N)
3077 or else
3078 Rep_Item_Too_Late (E, N)
3079 then
3080 return;
3081 else
3082 Check_First_Subtype (Arg1);
3083 end if;
3084
3085 if Prag_Id /= Pragma_Volatile then
3086 Set_Atomic (E);
3087 Set_Atomic (Underlying_Type (E));
3088 Set_Atomic (Base_Type (E));
3089 end if;
3090
3091 -- Attribute belongs on the base type. If the view of the type is
3092 -- currently private, it also belongs on the underlying type.
3093
3094 Set_Is_Volatile (Base_Type (E));
3095 Set_Is_Volatile (Underlying_Type (E));
3096
3097 Set_Treat_As_Volatile (E);
3098 Set_Treat_As_Volatile (Underlying_Type (E));
3099
3100 elsif K = N_Object_Declaration
3101 or else (K = N_Component_Declaration
3102 and then Original_Record_Component (E) = E)
3103 then
3104 if Rep_Item_Too_Late (E, N) then
3105 return;
3106 end if;
3107
3108 if Prag_Id /= Pragma_Volatile then
3109 Set_Is_Atomic (E);
3110
3111 -- If the object declaration has an explicit initialization, a
3112 -- temporary may have to be created to hold the expression, to
3113 -- ensure that access to the object remain atomic.
3114
3115 if Nkind (Parent (E)) = N_Object_Declaration
3116 and then Present (Expression (Parent (E)))
3117 then
3118 Set_Has_Delayed_Freeze (E);
3119 end if;
3120
3121 -- An interesting improvement here. If an object of composite
3122 -- type X is declared atomic, and the type X isn't, that's a
3123 -- pity, since it may not have appropriate alignment etc. We
3124 -- can rescue this in the special case where the object and
3125 -- type are in the same unit by just setting the type as
3126 -- atomic, so that the back end will process it as atomic.
3127
3128 -- Note: we used to do this for elementary types as well,
3129 -- but that turns out to be a bad idea and can have unwanted
3130 -- effects, most notably if the type is elementary, the object
3131 -- a simple component within a record, and both are in a spec:
3132 -- every object of this type in the entire program will be
3133 -- treated as atomic, thus incurring a potentially costly
3134 -- synchronization operation for every access.
3135
3136 -- Of course it would be best if the back end could just adjust
3137 -- the alignment etc for the specific object, but that's not
3138 -- something we are capable of doing at this point.
3139
3140 Utyp := Underlying_Type (Etype (E));
3141
3142 if Present (Utyp)
3143 and then Is_Composite_Type (Utyp)
3144 and then Sloc (E) > No_Location
3145 and then Sloc (Utyp) > No_Location
3146 and then
3147 Get_Source_File_Index (Sloc (E)) =
3148 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
3149 then
3150 Set_Is_Atomic (Underlying_Type (Etype (E)));
3151 end if;
3152 end if;
3153
3154 Set_Is_Volatile (E);
3155 Set_Treat_As_Volatile (E);
3156
3157 else
3158 Error_Pragma_Arg
3159 ("inappropriate entity for pragma%", Arg1);
3160 end if;
3161 end Process_Atomic_Shared_Volatile;
3162
3163 -------------------------------------------
3164 -- Process_Compile_Time_Warning_Or_Error --
3165 -------------------------------------------
3166
3167 procedure Process_Compile_Time_Warning_Or_Error is
3168 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
3169
3170 begin
3171 Check_Arg_Count (2);
3172 Check_No_Identifiers;
3173 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3174 Analyze_And_Resolve (Arg1x, Standard_Boolean);
3175
3176 if Compile_Time_Known_Value (Arg1x) then
3177 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3178 declare
3179 Str : constant String_Id :=
3180 Strval (Get_Pragma_Arg (Arg2));
3181 Len : constant Int := String_Length (Str);
3182 Cont : Boolean;
3183 Ptr : Nat;
3184 CC : Char_Code;
3185 C : Character;
3186 Cent : constant Entity_Id :=
3187 Cunit_Entity (Current_Sem_Unit);
3188
3189 Force : constant Boolean :=
3190 Prag_Id = Pragma_Compile_Time_Warning
3191 and then
3192 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3193 and then (Ekind (Cent) /= E_Package
3194 or else not In_Private_Part (Cent));
3195 -- Set True if this is the warning case, and we are in the
3196 -- visible part of a package spec, or in a subprogram spec,
3197 -- in which case we want to force the client to see the
3198 -- warning, even though it is not in the main unit.
3199
3200 begin
3201 -- Loop through segments of message separated by line feeds.
3202 -- We output these segments as separate messages with
3203 -- continuation marks for all but the first.
3204
3205 Cont := False;
3206 Ptr := 1;
3207 loop
3208 Error_Msg_Strlen := 0;
3209
3210 -- Loop to copy characters from argument to error message
3211 -- string buffer.
3212
3213 loop
3214 exit when Ptr > Len;
3215 CC := Get_String_Char (Str, Ptr);
3216 Ptr := Ptr + 1;
3217
3218 -- Ignore wide chars ??? else store character
3219
3220 if In_Character_Range (CC) then
3221 C := Get_Character (CC);
3222 exit when C = ASCII.LF;
3223 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3224 Error_Msg_String (Error_Msg_Strlen) := C;
3225 end if;
3226 end loop;
3227
3228 -- Here with one line ready to go
3229
3230 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3231
3232 -- If this is a warning in a spec, then we want clients
3233 -- to see the warning, so mark the message with the
3234 -- special sequence !! to force the warning. In the case
3235 -- of a package spec, we do not force this if we are in
3236 -- the private part of the spec.
3237
3238 if Force then
3239 if Cont = False then
3240 Error_Msg_N ("<~!!", Arg1);
3241 Cont := True;
3242 else
3243 Error_Msg_N ("\<~!!", Arg1);
3244 end if;
3245
3246 -- Error, rather than warning, or in a body, so we do not
3247 -- need to force visibility for client (error will be
3248 -- output in any case, and this is the situation in which
3249 -- we do not want a client to get a warning, since the
3250 -- warning is in the body or the spec private part).
3251
3252 else
3253 if Cont = False then
3254 Error_Msg_N ("<~", Arg1);
3255 Cont := True;
3256 else
3257 Error_Msg_N ("\<~", Arg1);
3258 end if;
3259 end if;
3260
3261 exit when Ptr > Len;
3262 end loop;
3263 end;
3264 end if;
3265 end if;
3266 end Process_Compile_Time_Warning_Or_Error;
3267
3268 ------------------------
3269 -- Process_Convention --
3270 ------------------------
3271
3272 procedure Process_Convention
3273 (C : out Convention_Id;
3274 Ent : out Entity_Id)
3275 is
3276 Id : Node_Id;
3277 E : Entity_Id;
3278 E1 : Entity_Id;
3279 Cname : Name_Id;
3280 Comp_Unit : Unit_Number_Type;
3281
3282 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3283 -- Called if we have more than one Export/Import/Convention pragma.
3284 -- This is generally illegal, but we have a special case of allowing
3285 -- Import and Interface to coexist if they specify the convention in
3286 -- a consistent manner. We are allowed to do this, since Interface is
3287 -- an implementation defined pragma, and we choose to do it since we
3288 -- know Rational allows this combination. S is the entity id of the
3289 -- subprogram in question. This procedure also sets the special flag
3290 -- Import_Interface_Present in both pragmas in the case where we do
3291 -- have matching Import and Interface pragmas.
3292
3293 procedure Set_Convention_From_Pragma (E : Entity_Id);
3294 -- Set convention in entity E, and also flag that the entity has a
3295 -- convention pragma. If entity is for a private or incomplete type,
3296 -- also set convention and flag on underlying type. This procedure
3297 -- also deals with the special case of C_Pass_By_Copy convention.
3298
3299 -------------------------------
3300 -- Diagnose_Multiple_Pragmas --
3301 -------------------------------
3302
3303 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3304 Pdec : constant Node_Id := Declaration_Node (S);
3305 Decl : Node_Id;
3306 Err : Boolean;
3307
3308 function Same_Convention (Decl : Node_Id) return Boolean;
3309 -- Decl is a pragma node. This function returns True if this
3310 -- pragma has a first argument that is an identifier with a
3311 -- Chars field corresponding to the Convention_Id C.
3312
3313 function Same_Name (Decl : Node_Id) return Boolean;
3314 -- Decl is a pragma node. This function returns True if this
3315 -- pragma has a second argument that is an identifier with a
3316 -- Chars field that matches the Chars of the current subprogram.
3317
3318 ---------------------
3319 -- Same_Convention --
3320 ---------------------
3321
3322 function Same_Convention (Decl : Node_Id) return Boolean is
3323 Arg1 : constant Node_Id :=
3324 First (Pragma_Argument_Associations (Decl));
3325
3326 begin
3327 if Present (Arg1) then
3328 declare
3329 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3330 begin
3331 if Nkind (Arg) = N_Identifier
3332 and then Is_Convention_Name (Chars (Arg))
3333 and then Get_Convention_Id (Chars (Arg)) = C
3334 then
3335 return True;
3336 end if;
3337 end;
3338 end if;
3339
3340 return False;
3341 end Same_Convention;
3342
3343 ---------------
3344 -- Same_Name --
3345 ---------------
3346
3347 function Same_Name (Decl : Node_Id) return Boolean is
3348 Arg1 : constant Node_Id :=
3349 First (Pragma_Argument_Associations (Decl));
3350 Arg2 : Node_Id;
3351
3352 begin
3353 if No (Arg1) then
3354 return False;
3355 end if;
3356
3357 Arg2 := Next (Arg1);
3358
3359 if No (Arg2) then
3360 return False;
3361 end if;
3362
3363 declare
3364 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3365 begin
3366 if Nkind (Arg) = N_Identifier
3367 and then Chars (Arg) = Chars (S)
3368 then
3369 return True;
3370 end if;
3371 end;
3372
3373 return False;
3374 end Same_Name;
3375
3376 -- Start of processing for Diagnose_Multiple_Pragmas
3377
3378 begin
3379 Err := True;
3380
3381 -- Definitely give message if we have Convention/Export here
3382
3383 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3384 null;
3385
3386 -- If we have an Import or Export, scan back from pragma to
3387 -- find any previous pragma applying to the same procedure.
3388 -- The scan will be terminated by the start of the list, or
3389 -- hitting the subprogram declaration. This won't allow one
3390 -- pragma to appear in the public part and one in the private
3391 -- part, but that seems very unlikely in practice.
3392
3393 else
3394 Decl := Prev (N);
3395 while Present (Decl) and then Decl /= Pdec loop
3396
3397 -- Look for pragma with same name as us
3398
3399 if Nkind (Decl) = N_Pragma
3400 and then Same_Name (Decl)
3401 then
3402 -- Give error if same as our pragma or Export/Convention
3403
3404 if Pragma_Name (Decl) = Name_Export
3405 or else
3406 Pragma_Name (Decl) = Name_Convention
3407 or else
3408 Pragma_Name (Decl) = Pragma_Name (N)
3409 then
3410 exit;
3411
3412 -- Case of Import/Interface or the other way round
3413
3414 elsif Pragma_Name (Decl) = Name_Interface
3415 or else
3416 Pragma_Name (Decl) = Name_Import
3417 then
3418 -- Here we know that we have Import and Interface. It
3419 -- doesn't matter which way round they are. See if
3420 -- they specify the same convention. If so, all OK,
3421 -- and set special flags to stop other messages
3422
3423 if Same_Convention (Decl) then
3424 Set_Import_Interface_Present (N);
3425 Set_Import_Interface_Present (Decl);
3426 Err := False;
3427
3428 -- If different conventions, special message
3429
3430 else
3431 Error_Msg_Sloc := Sloc (Decl);
3432 Error_Pragma_Arg
3433 ("convention differs from that given#", Arg1);
3434 return;
3435 end if;
3436 end if;
3437 end if;
3438
3439 Next (Decl);
3440 end loop;
3441 end if;
3442
3443 -- Give message if needed if we fall through those tests
3444
3445 if Err then
3446 Error_Pragma_Arg
3447 ("at most one Convention/Export/Import pragma is allowed",
3448 Arg2);
3449 end if;
3450 end Diagnose_Multiple_Pragmas;
3451
3452 --------------------------------
3453 -- Set_Convention_From_Pragma --
3454 --------------------------------
3455
3456 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3457 begin
3458 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3459 -- for an overridden dispatching operation. Technically this is
3460 -- an amendment and should only be done in Ada 2005 mode. However,
3461 -- this is clearly a mistake, since the problem that is addressed
3462 -- by this AI is that there is a clear gap in the RM!
3463
3464 if Is_Dispatching_Operation (E)
3465 and then Present (Overridden_Operation (E))
3466 and then C /= Convention (Overridden_Operation (E))
3467 then
3468 Error_Pragma_Arg
3469 ("cannot change convention for " &
3470 "overridden dispatching operation",
3471 Arg1);
3472 end if;
3473
3474 -- Set the convention
3475
3476 Set_Convention (E, C);
3477 Set_Has_Convention_Pragma (E);
3478
3479 if Is_Incomplete_Or_Private_Type (E)
3480 and then Present (Underlying_Type (E))
3481 then
3482 Set_Convention (Underlying_Type (E), C);
3483 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3484 end if;
3485
3486 -- A class-wide type should inherit the convention of the specific
3487 -- root type (although this isn't specified clearly by the RM).
3488
3489 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3490 Set_Convention (Class_Wide_Type (E), C);
3491 end if;
3492
3493 -- If the entity is a record type, then check for special case of
3494 -- C_Pass_By_Copy, which is treated the same as C except that the
3495 -- special record flag is set. This convention is only permitted
3496 -- on record types (see AI95-00131).
3497
3498 if Cname = Name_C_Pass_By_Copy then
3499 if Is_Record_Type (E) then
3500 Set_C_Pass_By_Copy (Base_Type (E));
3501 elsif Is_Incomplete_Or_Private_Type (E)
3502 and then Is_Record_Type (Underlying_Type (E))
3503 then
3504 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3505 else
3506 Error_Pragma_Arg
3507 ("C_Pass_By_Copy convention allowed only for record type",
3508 Arg2);
3509 end if;
3510 end if;
3511
3512 -- If the entity is a derived boolean type, check for the special
3513 -- case of convention C, C++, or Fortran, where we consider any
3514 -- nonzero value to represent true.
3515
3516 if Is_Discrete_Type (E)
3517 and then Root_Type (Etype (E)) = Standard_Boolean
3518 and then
3519 (C = Convention_C
3520 or else
3521 C = Convention_CPP
3522 or else
3523 C = Convention_Fortran)
3524 then
3525 Set_Nonzero_Is_True (Base_Type (E));
3526 end if;
3527 end Set_Convention_From_Pragma;
3528
3529 -- Start of processing for Process_Convention
3530
3531 begin
3532 Check_At_Least_N_Arguments (2);
3533 Check_Optional_Identifier (Arg1, Name_Convention);
3534 Check_Arg_Is_Identifier (Arg1);
3535 Cname := Chars (Get_Pragma_Arg (Arg1));
3536
3537 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3538 -- tested again below to set the critical flag).
3539
3540 if Cname = Name_C_Pass_By_Copy then
3541 C := Convention_C;
3542
3543 -- Otherwise we must have something in the standard convention list
3544
3545 elsif Is_Convention_Name (Cname) then
3546 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3547
3548 -- In DEC VMS, it seems that there is an undocumented feature that
3549 -- any unrecognized convention is treated as the default, which for
3550 -- us is convention C. It does not seem so terrible to do this
3551 -- unconditionally, silently in the VMS case, and with a warning
3552 -- in the non-VMS case.
3553
3554 else
3555 if Warn_On_Export_Import and not OpenVMS_On_Target then
3556 Error_Msg_N
3557 ("??unrecognized convention name, C assumed",
3558 Get_Pragma_Arg (Arg1));
3559 end if;
3560
3561 C := Convention_C;
3562 end if;
3563
3564 Check_Optional_Identifier (Arg2, Name_Entity);
3565 Check_Arg_Is_Local_Name (Arg2);
3566
3567 Id := Get_Pragma_Arg (Arg2);
3568 Analyze (Id);
3569
3570 if not Is_Entity_Name (Id) then
3571 Error_Pragma_Arg ("entity name required", Arg2);
3572 end if;
3573
3574 E := Entity (Id);
3575
3576 -- Set entity to return
3577
3578 Ent := E;
3579
3580 -- Ada_Pass_By_Copy special checking
3581
3582 if C = Convention_Ada_Pass_By_Copy then
3583 if not Is_First_Subtype (E) then
3584 Error_Pragma_Arg
3585 ("convention `Ada_Pass_By_Copy` only "
3586 & "allowed for types", Arg2);
3587 end if;
3588
3589 if Is_By_Reference_Type (E) then
3590 Error_Pragma_Arg
3591 ("convention `Ada_Pass_By_Copy` not allowed for "
3592 & "by-reference type", Arg1);
3593 end if;
3594 end if;
3595
3596 -- Ada_Pass_By_Reference special checking
3597
3598 if C = Convention_Ada_Pass_By_Reference then
3599 if not Is_First_Subtype (E) then
3600 Error_Pragma_Arg
3601 ("convention `Ada_Pass_By_Reference` only "
3602 & "allowed for types", Arg2);
3603 end if;
3604
3605 if Is_By_Copy_Type (E) then
3606 Error_Pragma_Arg
3607 ("convention `Ada_Pass_By_Reference` not allowed for "
3608 & "by-copy type", Arg1);
3609 end if;
3610 end if;
3611
3612 -- Go to renamed subprogram if present, since convention applies to
3613 -- the actual renamed entity, not to the renaming entity. If the
3614 -- subprogram is inherited, go to parent subprogram.
3615
3616 if Is_Subprogram (E)
3617 and then Present (Alias (E))
3618 then
3619 if Nkind (Parent (Declaration_Node (E))) =
3620 N_Subprogram_Renaming_Declaration
3621 then
3622 if Scope (E) /= Scope (Alias (E)) then
3623 Error_Pragma_Ref
3624 ("cannot apply pragma% to non-local entity&#", E);
3625 end if;
3626
3627 E := Alias (E);
3628
3629 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3630 N_Private_Extension_Declaration)
3631 and then Scope (E) = Scope (Alias (E))
3632 then
3633 E := Alias (E);
3634
3635 -- Return the parent subprogram the entity was inherited from
3636
3637 Ent := E;
3638 end if;
3639 end if;
3640
3641 -- Check that we are not applying this to a specless body
3642
3643 if Is_Subprogram (E)
3644 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3645 then
3646 Error_Pragma
3647 ("pragma% requires separate spec and must come before body");
3648 end if;
3649
3650 -- Check that we are not applying this to a named constant
3651
3652 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3653 Error_Msg_Name_1 := Pname;
3654 Error_Msg_N
3655 ("cannot apply pragma% to named constant!",
3656 Get_Pragma_Arg (Arg2));
3657 Error_Pragma_Arg
3658 ("\supply appropriate type for&!", Arg2);
3659 end if;
3660
3661 if Ekind (E) = E_Enumeration_Literal then
3662 Error_Pragma ("enumeration literal not allowed for pragma%");
3663 end if;
3664
3665 -- Check for rep item appearing too early or too late
3666
3667 if Etype (E) = Any_Type
3668 or else Rep_Item_Too_Early (E, N)
3669 then
3670 raise Pragma_Exit;
3671
3672 elsif Present (Underlying_Type (E)) then
3673 E := Underlying_Type (E);
3674 end if;
3675
3676 if Rep_Item_Too_Late (E, N) then
3677 raise Pragma_Exit;
3678 end if;
3679
3680 if Has_Convention_Pragma (E) then
3681 Diagnose_Multiple_Pragmas (E);
3682
3683 elsif Convention (E) = Convention_Protected
3684 or else Ekind (Scope (E)) = E_Protected_Type
3685 then
3686 Error_Pragma_Arg
3687 ("a protected operation cannot be given a different convention",
3688 Arg2);
3689 end if;
3690
3691 -- For Intrinsic, a subprogram is required
3692
3693 if C = Convention_Intrinsic
3694 and then not Is_Subprogram (E)
3695 and then not Is_Generic_Subprogram (E)
3696 then
3697 Error_Pragma_Arg
3698 ("second argument of pragma% must be a subprogram", Arg2);
3699 end if;
3700
3701 -- Stdcall case
3702
3703 if C = Convention_Stdcall then
3704
3705 -- A dispatching call is not allowed. A dispatching subprogram
3706 -- cannot be used to interface to the Win32 API, so in fact this
3707 -- check does not impose any effective restriction.
3708
3709 if Is_Dispatching_Operation (E) then
3710
3711 Error_Pragma
3712 ("dispatching subprograms cannot use Stdcall convention");
3713
3714 -- Subprogram is allowed, but not a generic subprogram, and not a
3715 -- dispatching operation.
3716
3717 elsif not Is_Subprogram (E)
3718 and then not Is_Generic_Subprogram (E)
3719
3720 -- A variable is OK
3721
3722 and then Ekind (E) /= E_Variable
3723
3724 -- An access to subprogram is also allowed
3725
3726 and then not
3727 (Is_Access_Type (E)
3728 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3729 then
3730 Error_Pragma_Arg
3731 ("second argument of pragma% must be subprogram (type)",
3732 Arg2);
3733 end if;
3734 end if;
3735
3736 if not Is_Subprogram (E)
3737 and then not Is_Generic_Subprogram (E)
3738 then
3739 Set_Convention_From_Pragma (E);
3740
3741 if Is_Type (E) then
3742 Check_First_Subtype (Arg2);
3743 Set_Convention_From_Pragma (Base_Type (E));
3744
3745 -- For subprograms, we must set the convention on the
3746 -- internally generated directly designated type as well.
3747
3748 if Ekind (E) = E_Access_Subprogram_Type then
3749 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3750 end if;
3751 end if;
3752
3753 -- For the subprogram case, set proper convention for all homonyms
3754 -- in same scope and the same declarative part, i.e. the same
3755 -- compilation unit.
3756
3757 else
3758 Comp_Unit := Get_Source_Unit (E);
3759 Set_Convention_From_Pragma (E);
3760
3761 -- Treat a pragma Import as an implicit body, and pragma import
3762 -- as implicit reference (for navigation in GPS).
3763
3764 if Prag_Id = Pragma_Import then
3765 Generate_Reference (E, Id, 'b');
3766
3767 -- For exported entities we restrict the generation of references
3768 -- to entities exported to foreign languages since entities
3769 -- exported to Ada do not provide further information to GPS and
3770 -- add undesired references to the output of the gnatxref tool.
3771
3772 elsif Prag_Id = Pragma_Export
3773 and then Convention (E) /= Convention_Ada
3774 then
3775 Generate_Reference (E, Id, 'i');
3776 end if;
3777
3778 -- If the pragma comes from from an aspect, it only applies
3779 -- to the given entity, not its homonyms.
3780
3781 if From_Aspect_Specification (N) then
3782 return;
3783 end if;
3784
3785 -- Otherwise Loop through the homonyms of the pragma argument's
3786 -- entity, an apply convention to those in the current scope.
3787
3788 E1 := Ent;
3789
3790 loop
3791 E1 := Homonym (E1);
3792 exit when No (E1) or else Scope (E1) /= Current_Scope;
3793
3794 -- Do not set the pragma on inherited operations or on formal
3795 -- subprograms.
3796
3797 if Comes_From_Source (E1)
3798 and then Comp_Unit = Get_Source_Unit (E1)
3799 and then not Is_Formal_Subprogram (E1)
3800 and then Nkind (Original_Node (Parent (E1))) /=
3801 N_Full_Type_Declaration
3802 then
3803 if Present (Alias (E1))
3804 and then Scope (E1) /= Scope (Alias (E1))
3805 then
3806 Error_Pragma_Ref
3807 ("cannot apply pragma% to non-local entity& declared#",
3808 E1);
3809 end if;
3810
3811 Set_Convention_From_Pragma (E1);
3812
3813 if Prag_Id = Pragma_Import then
3814 Generate_Reference (E1, Id, 'b');
3815 end if;
3816 end if;
3817 end loop;
3818 end if;
3819 end Process_Convention;
3820
3821 ----------------------------------------
3822 -- Process_Disable_Enable_Atomic_Sync --
3823 ----------------------------------------
3824
3825 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3826 begin
3827 GNAT_Pragma;
3828 Check_No_Identifiers;
3829 Check_At_Most_N_Arguments (1);
3830
3831 -- Modeled internally as
3832 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
3833
3834 Rewrite (N,
3835 Make_Pragma (Loc,
3836 Pragma_Identifier =>
3837 Make_Identifier (Loc, Nam),
3838 Pragma_Argument_Associations => New_List (
3839 Make_Pragma_Argument_Association (Loc,
3840 Expression =>
3841 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3842
3843 if Present (Arg1) then
3844 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3845 end if;
3846
3847 Analyze (N);
3848 end Process_Disable_Enable_Atomic_Sync;
3849
3850 -----------------------------------------------------
3851 -- Process_Extended_Import_Export_Exception_Pragma --
3852 -----------------------------------------------------
3853
3854 procedure Process_Extended_Import_Export_Exception_Pragma
3855 (Arg_Internal : Node_Id;
3856 Arg_External : Node_Id;
3857 Arg_Form : Node_Id;
3858 Arg_Code : Node_Id)
3859 is
3860 Def_Id : Entity_Id;
3861 Code_Val : Uint;
3862
3863 begin
3864 if not OpenVMS_On_Target then
3865 Error_Pragma
3866 ("??pragma% ignored (applies only to Open'V'M'S)");
3867 end if;
3868
3869 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3870 Def_Id := Entity (Arg_Internal);
3871
3872 if Ekind (Def_Id) /= E_Exception then
3873 Error_Pragma_Arg
3874 ("pragma% must refer to declared exception", Arg_Internal);
3875 end if;
3876
3877 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3878
3879 if Present (Arg_Form) then
3880 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3881 end if;
3882
3883 if Present (Arg_Form)
3884 and then Chars (Arg_Form) = Name_Ada
3885 then
3886 null;
3887 else
3888 Set_Is_VMS_Exception (Def_Id);
3889 Set_Exception_Code (Def_Id, No_Uint);
3890 end if;
3891
3892 if Present (Arg_Code) then
3893 if not Is_VMS_Exception (Def_Id) then
3894 Error_Pragma_Arg
3895 ("Code option for pragma% not allowed for Ada case",
3896 Arg_Code);
3897 end if;
3898
3899 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3900 Code_Val := Expr_Value (Arg_Code);
3901
3902 if not UI_Is_In_Int_Range (Code_Val) then
3903 Error_Pragma_Arg
3904 ("Code option for pragma% must be in 32-bit range",
3905 Arg_Code);
3906
3907 else
3908 Set_Exception_Code (Def_Id, Code_Val);
3909 end if;
3910 end if;
3911 end Process_Extended_Import_Export_Exception_Pragma;
3912
3913 -------------------------------------------------
3914 -- Process_Extended_Import_Export_Internal_Arg --
3915 -------------------------------------------------
3916
3917 procedure Process_Extended_Import_Export_Internal_Arg
3918 (Arg_Internal : Node_Id := Empty)
3919 is
3920 begin
3921 if No (Arg_Internal) then
3922 Error_Pragma ("Internal parameter required for pragma%");
3923 end if;
3924
3925 if Nkind (Arg_Internal) = N_Identifier then
3926 null;
3927
3928 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3929 and then (Prag_Id = Pragma_Import_Function
3930 or else
3931 Prag_Id = Pragma_Export_Function)
3932 then
3933 null;
3934
3935 else
3936 Error_Pragma_Arg
3937 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3938 end if;
3939
3940 Check_Arg_Is_Local_Name (Arg_Internal);
3941 end Process_Extended_Import_Export_Internal_Arg;
3942
3943 --------------------------------------------------
3944 -- Process_Extended_Import_Export_Object_Pragma --
3945 --------------------------------------------------
3946
3947 procedure Process_Extended_Import_Export_Object_Pragma
3948 (Arg_Internal : Node_Id;
3949 Arg_External : Node_Id;
3950 Arg_Size : Node_Id)
3951 is
3952 Def_Id : Entity_Id;
3953
3954 begin
3955 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3956 Def_Id := Entity (Arg_Internal);
3957
3958 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3959 Error_Pragma_Arg
3960 ("pragma% must designate an object", Arg_Internal);
3961 end if;
3962
3963 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3964 or else
3965 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3966 then
3967 Error_Pragma_Arg
3968 ("previous Common/Psect_Object applies, pragma % not permitted",
3969 Arg_Internal);
3970 end if;
3971
3972 if Rep_Item_Too_Late (Def_Id, N) then
3973 raise Pragma_Exit;
3974 end if;
3975
3976 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3977
3978 if Present (Arg_Size) then
3979 Check_Arg_Is_External_Name (Arg_Size);
3980 end if;
3981
3982 -- Export_Object case
3983
3984 if Prag_Id = Pragma_Export_Object then
3985 if not Is_Library_Level_Entity (Def_Id) then
3986 Error_Pragma_Arg
3987 ("argument for pragma% must be library level entity",
3988 Arg_Internal);
3989 end if;
3990
3991 if Ekind (Current_Scope) = E_Generic_Package then
3992 Error_Pragma ("pragma& cannot appear in a generic unit");
3993 end if;
3994
3995 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3996 Error_Pragma_Arg
3997 ("exported object must have compile time known size",
3998 Arg_Internal);
3999 end if;
4000
4001 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
4002 Error_Msg_N ("??duplicate Export_Object pragma", N);
4003 else
4004 Set_Exported (Def_Id, Arg_Internal);
4005 end if;
4006
4007 -- Import_Object case
4008
4009 else
4010 if Is_Concurrent_Type (Etype (Def_Id)) then
4011 Error_Pragma_Arg
4012 ("cannot use pragma% for task/protected object",
4013 Arg_Internal);
4014 end if;
4015
4016 if Ekind (Def_Id) = E_Constant then
4017 Error_Pragma_Arg
4018 ("cannot import a constant", Arg_Internal);
4019 end if;
4020
4021 if Warn_On_Export_Import
4022 and then Has_Discriminants (Etype (Def_Id))
4023 then
4024 Error_Msg_N
4025 ("imported value must be initialized??", Arg_Internal);
4026 end if;
4027
4028 if Warn_On_Export_Import
4029 and then Is_Access_Type (Etype (Def_Id))
4030 then
4031 Error_Pragma_Arg
4032 ("cannot import object of an access type??", Arg_Internal);
4033 end if;
4034
4035 if Warn_On_Export_Import
4036 and then Is_Imported (Def_Id)
4037 then
4038 Error_Msg_N ("??duplicate Import_Object pragma", N);
4039
4040 -- Check for explicit initialization present. Note that an
4041 -- initialization generated by the code generator, e.g. for an
4042 -- access type, does not count here.
4043
4044 elsif Present (Expression (Parent (Def_Id)))
4045 and then
4046 Comes_From_Source
4047 (Original_Node (Expression (Parent (Def_Id))))
4048 then
4049 Error_Msg_Sloc := Sloc (Def_Id);
4050 Error_Pragma_Arg
4051 ("imported entities cannot be initialized (RM B.1(24))",
4052 "\no initialization allowed for & declared#", Arg1);
4053 else
4054 Set_Imported (Def_Id);
4055 Note_Possible_Modification (Arg_Internal, Sure => False);
4056 end if;
4057 end if;
4058 end Process_Extended_Import_Export_Object_Pragma;
4059
4060 ------------------------------------------------------
4061 -- Process_Extended_Import_Export_Subprogram_Pragma --
4062 ------------------------------------------------------
4063
4064 procedure Process_Extended_Import_Export_Subprogram_Pragma
4065 (Arg_Internal : Node_Id;
4066 Arg_External : Node_Id;
4067 Arg_Parameter_Types : Node_Id;
4068 Arg_Result_Type : Node_Id := Empty;
4069 Arg_Mechanism : Node_Id;
4070 Arg_Result_Mechanism : Node_Id := Empty;
4071 Arg_First_Optional_Parameter : Node_Id := Empty)
4072 is
4073 Ent : Entity_Id;
4074 Def_Id : Entity_Id;
4075 Hom_Id : Entity_Id;
4076 Formal : Entity_Id;
4077 Ambiguous : Boolean;
4078 Match : Boolean;
4079 Dval : Node_Id;
4080
4081 function Same_Base_Type
4082 (Ptype : Node_Id;
4083 Formal : Entity_Id) return Boolean;
4084 -- Determines if Ptype references the type of Formal. Note that only
4085 -- the base types need to match according to the spec. Ptype here is
4086 -- the argument from the pragma, which is either a type name, or an
4087 -- access attribute.
4088
4089 --------------------
4090 -- Same_Base_Type --
4091 --------------------
4092
4093 function Same_Base_Type
4094 (Ptype : Node_Id;
4095 Formal : Entity_Id) return Boolean
4096 is
4097 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
4098 Pref : Node_Id;
4099
4100 begin
4101 -- Case where pragma argument is typ'Access
4102
4103 if Nkind (Ptype) = N_Attribute_Reference
4104 and then Attribute_Name (Ptype) = Name_Access
4105 then
4106 Pref := Prefix (Ptype);
4107 Find_Type (Pref);
4108
4109 if not Is_Entity_Name (Pref)
4110 or else Entity (Pref) = Any_Type
4111 then
4112 raise Pragma_Exit;
4113 end if;
4114
4115 -- We have a match if the corresponding argument is of an
4116 -- anonymous access type, and its designated type matches the
4117 -- type of the prefix of the access attribute
4118
4119 return Ekind (Ftyp) = E_Anonymous_Access_Type
4120 and then Base_Type (Entity (Pref)) =
4121 Base_Type (Etype (Designated_Type (Ftyp)));
4122
4123 -- Case where pragma argument is a type name
4124
4125 else
4126 Find_Type (Ptype);
4127
4128 if not Is_Entity_Name (Ptype)
4129 or else Entity (Ptype) = Any_Type
4130 then
4131 raise Pragma_Exit;
4132 end if;
4133
4134 -- We have a match if the corresponding argument is of the type
4135 -- given in the pragma (comparing base types)
4136
4137 return Base_Type (Entity (Ptype)) = Ftyp;
4138 end if;
4139 end Same_Base_Type;
4140
4141 -- Start of processing for
4142 -- Process_Extended_Import_Export_Subprogram_Pragma
4143
4144 begin
4145 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
4146 Ent := Empty;
4147 Ambiguous := False;
4148
4149 -- Loop through homonyms (overloadings) of the entity
4150
4151 Hom_Id := Entity (Arg_Internal);
4152 while Present (Hom_Id) loop
4153 Def_Id := Get_Base_Subprogram (Hom_Id);
4154
4155 -- We need a subprogram in the current scope
4156
4157 if not Is_Subprogram (Def_Id)
4158 or else Scope (Def_Id) /= Current_Scope
4159 then
4160 null;
4161
4162 else
4163 Match := True;
4164
4165 -- Pragma cannot apply to subprogram body
4166
4167 if Is_Subprogram (Def_Id)
4168 and then Nkind (Parent (Declaration_Node (Def_Id))) =
4169 N_Subprogram_Body
4170 then
4171 Error_Pragma
4172 ("pragma% requires separate spec"
4173 & " and must come before body");
4174 end if;
4175
4176 -- Test result type if given, note that the result type
4177 -- parameter can only be present for the function cases.
4178
4179 if Present (Arg_Result_Type)
4180 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
4181 then
4182 Match := False;
4183
4184 elsif Etype (Def_Id) /= Standard_Void_Type
4185 and then
4186 (Pname = Name_Export_Procedure
4187 or else
4188 Pname = Name_Import_Procedure)
4189 then
4190 Match := False;
4191
4192 -- Test parameter types if given. Note that this parameter
4193 -- has not been analyzed (and must not be, since it is
4194 -- semantic nonsense), so we get it as the parser left it.
4195
4196 elsif Present (Arg_Parameter_Types) then
4197 Check_Matching_Types : declare
4198 Formal : Entity_Id;
4199 Ptype : Node_Id;
4200
4201 begin
4202 Formal := First_Formal (Def_Id);
4203
4204 if Nkind (Arg_Parameter_Types) = N_Null then
4205 if Present (Formal) then
4206 Match := False;
4207 end if;
4208
4209 -- A list of one type, e.g. (List) is parsed as
4210 -- a parenthesized expression.
4211
4212 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4213 and then Paren_Count (Arg_Parameter_Types) = 1
4214 then
4215 if No (Formal)
4216 or else Present (Next_Formal (Formal))
4217 then
4218 Match := False;
4219 else
4220 Match :=
4221 Same_Base_Type (Arg_Parameter_Types, Formal);
4222 end if;
4223
4224 -- A list of more than one type is parsed as a aggregate
4225
4226 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4227 and then Paren_Count (Arg_Parameter_Types) = 0
4228 then
4229 Ptype := First (Expressions (Arg_Parameter_Types));
4230 while Present (Ptype) or else Present (Formal) loop
4231 if No (Ptype)
4232 or else No (Formal)
4233 or else not Same_Base_Type (Ptype, Formal)
4234 then
4235 Match := False;
4236 exit;
4237 else
4238 Next_Formal (Formal);
4239 Next (Ptype);
4240 end if;
4241 end loop;
4242
4243 -- Anything else is of the wrong form
4244
4245 else
4246 Error_Pragma_Arg
4247 ("wrong form for Parameter_Types parameter",
4248 Arg_Parameter_Types);
4249 end if;
4250 end Check_Matching_Types;
4251 end if;
4252
4253 -- Match is now False if the entry we found did not match
4254 -- either a supplied Parameter_Types or Result_Types argument
4255
4256 if Match then
4257 if No (Ent) then
4258 Ent := Def_Id;
4259
4260 -- Ambiguous case, the flag Ambiguous shows if we already
4261 -- detected this and output the initial messages.
4262
4263 else
4264 if not Ambiguous then
4265 Ambiguous := True;
4266 Error_Msg_Name_1 := Pname;
4267 Error_Msg_N
4268 ("pragma% does not uniquely identify subprogram!",
4269 N);
4270 Error_Msg_Sloc := Sloc (Ent);
4271 Error_Msg_N ("matching subprogram #!", N);
4272 Ent := Empty;
4273 end if;
4274
4275 Error_Msg_Sloc := Sloc (Def_Id);
4276 Error_Msg_N ("matching subprogram #!", N);
4277 end if;
4278 end if;
4279 end if;
4280
4281 Hom_Id := Homonym (Hom_Id);
4282 end loop;
4283
4284 -- See if we found an entry
4285
4286 if No (Ent) then
4287 if not Ambiguous then
4288 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4289 Error_Pragma
4290 ("pragma% cannot be given for generic subprogram");
4291 else
4292 Error_Pragma
4293 ("pragma% does not identify local subprogram");
4294 end if;
4295 end if;
4296
4297 return;
4298 end if;
4299
4300 -- Import pragmas must be for imported entities
4301
4302 if Prag_Id = Pragma_Import_Function
4303 or else
4304 Prag_Id = Pragma_Import_Procedure
4305 or else
4306 Prag_Id = Pragma_Import_Valued_Procedure
4307 then
4308 if not Is_Imported (Ent) then
4309 Error_Pragma
4310 ("pragma Import or Interface must precede pragma%");
4311 end if;
4312
4313 -- Here we have the Export case which can set the entity as exported
4314
4315 -- But does not do so if the specified external name is null, since
4316 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4317 -- compatible) to request no external name.
4318
4319 elsif Nkind (Arg_External) = N_String_Literal
4320 and then String_Length (Strval (Arg_External)) = 0
4321 then
4322 null;
4323
4324 -- In all other cases, set entity as exported
4325
4326 else
4327 Set_Exported (Ent, Arg_Internal);
4328 end if;
4329
4330 -- Special processing for Valued_Procedure cases
4331
4332 if Prag_Id = Pragma_Import_Valued_Procedure
4333 or else
4334 Prag_Id = Pragma_Export_Valued_Procedure
4335 then
4336 Formal := First_Formal (Ent);
4337
4338 if No (Formal) then
4339 Error_Pragma ("at least one parameter required for pragma%");
4340
4341 elsif Ekind (Formal) /= E_Out_Parameter then
4342 Error_Pragma ("first parameter must have mode out for pragma%");
4343
4344 else
4345 Set_Is_Valued_Procedure (Ent);
4346 end if;
4347 end if;
4348
4349 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4350
4351 -- Process Result_Mechanism argument if present. We have already
4352 -- checked that this is only allowed for the function case.
4353
4354 if Present (Arg_Result_Mechanism) then
4355 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4356 end if;
4357
4358 -- Process Mechanism parameter if present. Note that this parameter
4359 -- is not analyzed, and must not be analyzed since it is semantic
4360 -- nonsense, so we get it in exactly as the parser left it.
4361
4362 if Present (Arg_Mechanism) then
4363 declare
4364 Formal : Entity_Id;
4365 Massoc : Node_Id;
4366 Mname : Node_Id;
4367 Choice : Node_Id;
4368
4369 begin
4370 -- A single mechanism association without a formal parameter
4371 -- name is parsed as a parenthesized expression. All other
4372 -- cases are parsed as aggregates, so we rewrite the single
4373 -- parameter case as an aggregate for consistency.
4374
4375 if Nkind (Arg_Mechanism) /= N_Aggregate
4376 and then Paren_Count (Arg_Mechanism) = 1
4377 then
4378 Rewrite (Arg_Mechanism,
4379 Make_Aggregate (Sloc (Arg_Mechanism),
4380 Expressions => New_List (
4381 Relocate_Node (Arg_Mechanism))));
4382 end if;
4383
4384 -- Case of only mechanism name given, applies to all formals
4385
4386 if Nkind (Arg_Mechanism) /= N_Aggregate then
4387 Formal := First_Formal (Ent);
4388 while Present (Formal) loop
4389 Set_Mechanism_Value (Formal, Arg_Mechanism);
4390 Next_Formal (Formal);
4391 end loop;
4392
4393 -- Case of list of mechanism associations given
4394
4395 else
4396 if Null_Record_Present (Arg_Mechanism) then
4397 Error_Pragma_Arg
4398 ("inappropriate form for Mechanism parameter",
4399 Arg_Mechanism);
4400 end if;
4401
4402 -- Deal with positional ones first
4403
4404 Formal := First_Formal (Ent);
4405
4406 if Present (Expressions (Arg_Mechanism)) then
4407 Mname := First (Expressions (Arg_Mechanism));
4408 while Present (Mname) loop
4409 if No (Formal) then
4410 Error_Pragma_Arg
4411 ("too many mechanism associations", Mname);
4412 end if;
4413
4414 Set_Mechanism_Value (Formal, Mname);
4415 Next_Formal (Formal);
4416 Next (Mname);
4417 end loop;
4418 end if;
4419
4420 -- Deal with named entries
4421
4422 if Present (Component_Associations (Arg_Mechanism)) then
4423 Massoc := First (Component_Associations (Arg_Mechanism));
4424 while Present (Massoc) loop
4425 Choice := First (Choices (Massoc));
4426
4427 if Nkind (Choice) /= N_Identifier
4428 or else Present (Next (Choice))
4429 then
4430 Error_Pragma_Arg
4431 ("incorrect form for mechanism association",
4432 Massoc);
4433 end if;
4434
4435 Formal := First_Formal (Ent);
4436 loop
4437 if No (Formal) then
4438 Error_Pragma_Arg
4439 ("parameter name & not present", Choice);
4440 end if;
4441
4442 if Chars (Choice) = Chars (Formal) then
4443 Set_Mechanism_Value
4444 (Formal, Expression (Massoc));
4445
4446 -- Set entity on identifier (needed by ASIS)
4447
4448 Set_Entity (Choice, Formal);
4449
4450 exit;
4451 end if;
4452
4453 Next_Formal (Formal);
4454 end loop;
4455
4456 Next (Massoc);
4457 end loop;
4458 end if;
4459 end if;
4460 end;
4461 end if;
4462
4463 -- Process First_Optional_Parameter argument if present. We have
4464 -- already checked that this is only allowed for the Import case.
4465
4466 if Present (Arg_First_Optional_Parameter) then
4467 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4468 Error_Pragma_Arg
4469 ("first optional parameter must be formal parameter name",
4470 Arg_First_Optional_Parameter);
4471 end if;
4472
4473 Formal := First_Formal (Ent);
4474 loop
4475 if No (Formal) then
4476 Error_Pragma_Arg
4477 ("specified formal parameter& not found",
4478 Arg_First_Optional_Parameter);
4479 end if;
4480
4481 exit when Chars (Formal) =
4482 Chars (Arg_First_Optional_Parameter);
4483
4484 Next_Formal (Formal);
4485 end loop;
4486
4487 Set_First_Optional_Parameter (Ent, Formal);
4488
4489 -- Check specified and all remaining formals have right form
4490
4491 while Present (Formal) loop
4492 if Ekind (Formal) /= E_In_Parameter then
4493 Error_Msg_NE
4494 ("optional formal& is not of mode in!",
4495 Arg_First_Optional_Parameter, Formal);
4496
4497 else
4498 Dval := Default_Value (Formal);
4499
4500 if No (Dval) then
4501 Error_Msg_NE
4502 ("optional formal& does not have default value!",
4503 Arg_First_Optional_Parameter, Formal);
4504
4505 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4506 null;
4507
4508 else
4509 Error_Msg_FE
4510 ("default value for optional formal& is non-static!",
4511 Arg_First_Optional_Parameter, Formal);
4512 end if;
4513 end if;
4514
4515 Set_Is_Optional_Parameter (Formal);
4516 Next_Formal (Formal);
4517 end loop;
4518 end if;
4519 end Process_Extended_Import_Export_Subprogram_Pragma;
4520
4521 --------------------------
4522 -- Process_Generic_List --
4523 --------------------------
4524
4525 procedure Process_Generic_List is
4526 Arg : Node_Id;
4527 Exp : Node_Id;
4528
4529 begin
4530 Check_No_Identifiers;
4531 Check_At_Least_N_Arguments (1);
4532
4533 Arg := Arg1;
4534 while Present (Arg) loop
4535 Exp := Get_Pragma_Arg (Arg);
4536 Analyze (Exp);
4537
4538 if not Is_Entity_Name (Exp)
4539 or else
4540 (not Is_Generic_Instance (Entity (Exp))
4541 and then
4542 not Is_Generic_Unit (Entity (Exp)))
4543 then
4544 Error_Pragma_Arg
4545 ("pragma% argument must be name of generic unit/instance",
4546 Arg);
4547 end if;
4548
4549 Next (Arg);
4550 end loop;
4551 end Process_Generic_List;
4552
4553 ------------------------------------
4554 -- Process_Import_Predefined_Type --
4555 ------------------------------------
4556
4557 procedure Process_Import_Predefined_Type is
4558 Loc : constant Source_Ptr := Sloc (N);
4559 Elmt : Elmt_Id;
4560 Ftyp : Node_Id := Empty;
4561 Decl : Node_Id;
4562 Def : Node_Id;
4563 Nam : Name_Id;
4564
4565 begin
4566 String_To_Name_Buffer (Strval (Expression (Arg3)));
4567 Nam := Name_Find;
4568
4569 Elmt := First_Elmt (Predefined_Float_Types);
4570 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4571 Next_Elmt (Elmt);
4572 end loop;
4573
4574 Ftyp := Node (Elmt);
4575
4576 if Present (Ftyp) then
4577
4578 -- Don't build a derived type declaration, because predefined C
4579 -- types have no declaration anywhere, so cannot really be named.
4580 -- Instead build a full type declaration, starting with an
4581 -- appropriate type definition is built
4582
4583 if Is_Floating_Point_Type (Ftyp) then
4584 Def := Make_Floating_Point_Definition (Loc,
4585 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4586 Make_Real_Range_Specification (Loc,
4587 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4588 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4589
4590 -- Should never have a predefined type we cannot handle
4591
4592 else
4593 raise Program_Error;
4594 end if;
4595
4596 -- Build and insert a Full_Type_Declaration, which will be
4597 -- analyzed as soon as this list entry has been analyzed.
4598
4599 Decl := Make_Full_Type_Declaration (Loc,
4600 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4601 Type_Definition => Def);
4602
4603 Insert_After (N, Decl);
4604 Mark_Rewrite_Insertion (Decl);
4605
4606 else
4607 Error_Pragma_Arg ("no matching type found for pragma%",
4608 Arg2);
4609 end if;
4610 end Process_Import_Predefined_Type;
4611
4612 ---------------------------------
4613 -- Process_Import_Or_Interface --
4614 ---------------------------------
4615
4616 procedure Process_Import_Or_Interface is
4617 C : Convention_Id;
4618 Def_Id : Entity_Id;
4619 Hom_Id : Entity_Id;
4620
4621 begin
4622 Process_Convention (C, Def_Id);
4623 Kill_Size_Check_Code (Def_Id);
4624 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4625
4626 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4627
4628 -- We do not permit Import to apply to a renaming declaration
4629
4630 if Present (Renamed_Object (Def_Id)) then
4631 Error_Pragma_Arg
4632 ("pragma% not allowed for object renaming", Arg2);
4633
4634 -- User initialization is not allowed for imported object, but
4635 -- the object declaration may contain a default initialization,
4636 -- that will be discarded. Note that an explicit initialization
4637 -- only counts if it comes from source, otherwise it is simply
4638 -- the code generator making an implicit initialization explicit.
4639
4640 elsif Present (Expression (Parent (Def_Id)))
4641 and then Comes_From_Source (Expression (Parent (Def_Id)))
4642 then
4643 Error_Msg_Sloc := Sloc (Def_Id);
4644 Error_Pragma_Arg
4645 ("no initialization allowed for declaration of& #",
4646 "\imported entities cannot be initialized (RM B.1(24))",
4647 Arg2);
4648
4649 else
4650 Set_Imported (Def_Id);
4651 Process_Interface_Name (Def_Id, Arg3, Arg4);
4652
4653 -- Note that we do not set Is_Public here. That's because we
4654 -- only want to set it if there is no address clause, and we
4655 -- don't know that yet, so we delay that processing till
4656 -- freeze time.
4657
4658 -- pragma Import completes deferred constants
4659
4660 if Ekind (Def_Id) = E_Constant then
4661 Set_Has_Completion (Def_Id);
4662 end if;
4663
4664 -- It is not possible to import a constant of an unconstrained
4665 -- array type (e.g. string) because there is no simple way to
4666 -- write a meaningful subtype for it.
4667
4668 if Is_Array_Type (Etype (Def_Id))
4669 and then not Is_Constrained (Etype (Def_Id))
4670 then
4671 Error_Msg_NE
4672 ("imported constant& must have a constrained subtype",
4673 N, Def_Id);
4674 end if;
4675 end if;
4676
4677 elsif Is_Subprogram (Def_Id)
4678 or else Is_Generic_Subprogram (Def_Id)
4679 then
4680 -- If the name is overloaded, pragma applies to all of the denoted
4681 -- entities in the same declarative part, unless the pragma comes
4682 -- from an aspect specification.
4683
4684 Hom_Id := Def_Id;
4685 while Present (Hom_Id) loop
4686
4687 Def_Id := Get_Base_Subprogram (Hom_Id);
4688
4689 -- Ignore inherited subprograms because the pragma will apply
4690 -- to the parent operation, which is the one called.
4691
4692 if Is_Overloadable (Def_Id)
4693 and then Present (Alias (Def_Id))
4694 then
4695 null;
4696
4697 -- If it is not a subprogram, it must be in an outer scope and
4698 -- pragma does not apply.
4699
4700 elsif not Is_Subprogram (Def_Id)
4701 and then not Is_Generic_Subprogram (Def_Id)
4702 then
4703 null;
4704
4705 -- The pragma does not apply to primitives of interfaces
4706
4707 elsif Is_Dispatching_Operation (Def_Id)
4708 and then Present (Find_Dispatching_Type (Def_Id))
4709 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4710 then
4711 null;
4712
4713 -- Verify that the homonym is in the same declarative part (not
4714 -- just the same scope). If the pragma comes from an aspect
4715 -- specification we know that it is part of the declaration.
4716
4717 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4718 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4719 and then not From_Aspect_Specification (N)
4720 then
4721 exit;
4722
4723 else
4724 Set_Imported (Def_Id);
4725
4726 -- Reject an Import applied to an abstract subprogram
4727
4728 if Is_Subprogram (Def_Id)
4729 and then Is_Abstract_Subprogram (Def_Id)
4730 then
4731 Error_Msg_Sloc := Sloc (Def_Id);
4732 Error_Msg_NE
4733 ("cannot import abstract subprogram& declared#",
4734 Arg2, Def_Id);
4735 end if;
4736
4737 -- Special processing for Convention_Intrinsic
4738
4739 if C = Convention_Intrinsic then
4740
4741 -- Link_Name argument not allowed for intrinsic
4742
4743 Check_No_Link_Name;
4744
4745 Set_Is_Intrinsic_Subprogram (Def_Id);
4746
4747 -- If no external name is present, then check that this
4748 -- is a valid intrinsic subprogram. If an external name
4749 -- is present, then this is handled by the back end.
4750
4751 if No (Arg3) then
4752 Check_Intrinsic_Subprogram
4753 (Def_Id, Get_Pragma_Arg (Arg2));
4754 end if;
4755 end if;
4756
4757 -- All interfaced procedures need an external symbol created
4758 -- for them since they are always referenced from another
4759 -- object file.
4760
4761 Set_Is_Public (Def_Id);
4762
4763 -- Verify that the subprogram does not have a completion
4764 -- through a renaming declaration. For other completions the
4765 -- pragma appears as a too late representation.
4766
4767 declare
4768 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4769
4770 begin
4771 if Present (Decl)
4772 and then Nkind (Decl) = N_Subprogram_Declaration
4773 and then Present (Corresponding_Body (Decl))
4774 and then Nkind (Unit_Declaration_Node
4775 (Corresponding_Body (Decl))) =
4776 N_Subprogram_Renaming_Declaration
4777 then
4778 Error_Msg_Sloc := Sloc (Def_Id);
4779 Error_Msg_NE
4780 ("cannot import&, renaming already provided for " &
4781 "declaration #", N, Def_Id);
4782 end if;
4783 end;
4784
4785 Set_Has_Completion (Def_Id);
4786 Process_Interface_Name (Def_Id, Arg3, Arg4);
4787 end if;
4788
4789 if Is_Compilation_Unit (Hom_Id) then
4790
4791 -- Its possible homonyms are not affected by the pragma.
4792 -- Such homonyms might be present in the context of other
4793 -- units being compiled.
4794
4795 exit;
4796
4797 elsif From_Aspect_Specification (N) then
4798 exit;
4799
4800 else
4801 Hom_Id := Homonym (Hom_Id);
4802 end if;
4803 end loop;
4804
4805 -- When the convention is Java or CIL, we also allow Import to be
4806 -- given for packages, generic packages, exceptions, record
4807 -- components, and access to subprograms.
4808
4809 elsif (C = Convention_Java or else C = Convention_CIL)
4810 and then
4811 (Is_Package_Or_Generic_Package (Def_Id)
4812 or else Ekind (Def_Id) = E_Exception
4813 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4814 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4815 then
4816 Set_Imported (Def_Id);
4817 Set_Is_Public (Def_Id);
4818 Process_Interface_Name (Def_Id, Arg3, Arg4);
4819
4820 -- Import a CPP class
4821
4822 elsif C = Convention_CPP
4823 and then (Is_Record_Type (Def_Id)
4824 or else Ekind (Def_Id) = E_Incomplete_Type)
4825 then
4826 if Ekind (Def_Id) = E_Incomplete_Type then
4827 if Present (Full_View (Def_Id)) then
4828 Def_Id := Full_View (Def_Id);
4829
4830 else
4831 Error_Msg_N
4832 ("cannot import 'C'P'P type before full declaration seen",
4833 Get_Pragma_Arg (Arg2));
4834
4835 -- Although we have reported the error we decorate it as
4836 -- CPP_Class to avoid reporting spurious errors
4837
4838 Set_Is_CPP_Class (Def_Id);
4839 return;
4840 end if;
4841 end if;
4842
4843 -- Types treated as CPP classes must be declared limited (note:
4844 -- this used to be a warning but there is no real benefit to it
4845 -- since we did effectively intend to treat the type as limited
4846 -- anyway).
4847
4848 if not Is_Limited_Type (Def_Id) then
4849 Error_Msg_N
4850 ("imported 'C'P'P type must be limited",
4851 Get_Pragma_Arg (Arg2));
4852 end if;
4853
4854 if Etype (Def_Id) /= Def_Id
4855 and then not Is_CPP_Class (Root_Type (Def_Id))
4856 then
4857 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
4858 end if;
4859
4860 Set_Is_CPP_Class (Def_Id);
4861
4862 -- Imported CPP types must not have discriminants (because C++
4863 -- classes do not have discriminants).
4864
4865 if Has_Discriminants (Def_Id) then
4866 Error_Msg_N
4867 ("imported 'C'P'P type cannot have discriminants",
4868 First (Discriminant_Specifications
4869 (Declaration_Node (Def_Id))));
4870 end if;
4871
4872 -- Check that components of imported CPP types do not have default
4873 -- expressions. For private types this check is performed when the
4874 -- full view is analyzed (see Process_Full_View).
4875
4876 if not Is_Private_Type (Def_Id) then
4877 Check_CPP_Type_Has_No_Defaults (Def_Id);
4878 end if;
4879
4880 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4881 Check_No_Link_Name;
4882 Check_Arg_Count (3);
4883 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4884
4885 Process_Import_Predefined_Type;
4886
4887 else
4888 Error_Pragma_Arg
4889 ("second argument of pragma% must be object, subprogram "
4890 & "or incomplete type",
4891 Arg2);
4892 end if;
4893
4894 -- If this pragma applies to a compilation unit, then the unit, which
4895 -- is a subprogram, does not require (or allow) a body. We also do
4896 -- not need to elaborate imported procedures.
4897
4898 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4899 declare
4900 Cunit : constant Node_Id := Parent (Parent (N));
4901 begin
4902 Set_Body_Required (Cunit, False);
4903 end;
4904 end if;
4905 end Process_Import_Or_Interface;
4906
4907 --------------------
4908 -- Process_Inline --
4909 --------------------
4910
4911 procedure Process_Inline (Active : Boolean) is
4912 Assoc : Node_Id;
4913 Decl : Node_Id;
4914 Subp_Id : Node_Id;
4915 Subp : Entity_Id;
4916 Applies : Boolean;
4917
4918 Effective : Boolean := False;
4919 -- Set True if inline has some effect, i.e. if there is at least one
4920 -- subprogram set as inlined as a result of the use of the pragma.
4921
4922 procedure Make_Inline (Subp : Entity_Id);
4923 -- Subp is the defining unit name of the subprogram declaration. Set
4924 -- the flag, as well as the flag in the corresponding body, if there
4925 -- is one present.
4926
4927 procedure Set_Inline_Flags (Subp : Entity_Id);
4928 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4929 -- Has_Pragma_Inline_Always for the Inline_Always case.
4930
4931 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4932 -- Returns True if it can be determined at this stage that inlining
4933 -- is not possible, for example if the body is available and contains
4934 -- exception handlers, we prevent inlining, since otherwise we can
4935 -- get undefined symbols at link time. This function also emits a
4936 -- warning if front-end inlining is enabled and the pragma appears
4937 -- too late.
4938 --
4939 -- ??? is business with link symbols still valid, or does it relate
4940 -- to front end ZCX which is being phased out ???
4941
4942 ---------------------------
4943 -- Inlining_Not_Possible --
4944 ---------------------------
4945
4946 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4947 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4948 Stats : Node_Id;
4949
4950 begin
4951 if Nkind (Decl) = N_Subprogram_Body then
4952 Stats := Handled_Statement_Sequence (Decl);
4953 return Present (Exception_Handlers (Stats))
4954 or else Present (At_End_Proc (Stats));
4955
4956 elsif Nkind (Decl) = N_Subprogram_Declaration
4957 and then Present (Corresponding_Body (Decl))
4958 then
4959 if Front_End_Inlining
4960 and then Analyzed (Corresponding_Body (Decl))
4961 then
4962 Error_Msg_N ("pragma appears too late, ignored??", N);
4963 return True;
4964
4965 -- If the subprogram is a renaming as body, the body is just a
4966 -- call to the renamed subprogram, and inlining is trivially
4967 -- possible.
4968
4969 elsif
4970 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4971 N_Subprogram_Renaming_Declaration
4972 then
4973 return False;
4974
4975 else
4976 Stats :=
4977 Handled_Statement_Sequence
4978 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4979
4980 return
4981 Present (Exception_Handlers (Stats))
4982 or else Present (At_End_Proc (Stats));
4983 end if;
4984
4985 else
4986 -- If body is not available, assume the best, the check is
4987 -- performed again when compiling enclosing package bodies.
4988
4989 return False;
4990 end if;
4991 end Inlining_Not_Possible;
4992
4993 -----------------
4994 -- Make_Inline --
4995 -----------------
4996
4997 procedure Make_Inline (Subp : Entity_Id) is
4998 Kind : constant Entity_Kind := Ekind (Subp);
4999 Inner_Subp : Entity_Id := Subp;
5000
5001 begin
5002 -- Ignore if bad type, avoid cascaded error
5003
5004 if Etype (Subp) = Any_Type then
5005 Applies := True;
5006 return;
5007
5008 -- Ignore if all inlining is suppressed
5009
5010 elsif Suppress_All_Inlining then
5011 Applies := True;
5012 return;
5013
5014 -- If inlining is not possible, for now do not treat as an error
5015
5016 elsif Inlining_Not_Possible (Subp) then
5017 Applies := True;
5018 return;
5019
5020 -- Here we have a candidate for inlining, but we must exclude
5021 -- derived operations. Otherwise we would end up trying to inline
5022 -- a phantom declaration, and the result would be to drag in a
5023 -- body which has no direct inlining associated with it. That
5024 -- would not only be inefficient but would also result in the
5025 -- backend doing cross-unit inlining in cases where it was
5026 -- definitely inappropriate to do so.
5027
5028 -- However, a simple Comes_From_Source test is insufficient, since
5029 -- we do want to allow inlining of generic instances which also do
5030 -- not come from source. We also need to recognize specs generated
5031 -- by the front-end for bodies that carry the pragma. Finally,
5032 -- predefined operators do not come from source but are not
5033 -- inlineable either.
5034
5035 elsif Is_Generic_Instance (Subp)
5036 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
5037 then
5038 null;
5039
5040 elsif not Comes_From_Source (Subp)
5041 and then Scope (Subp) /= Standard_Standard
5042 then
5043 Applies := True;
5044 return;
5045 end if;
5046
5047 -- The referenced entity must either be the enclosing entity, or
5048 -- an entity declared within the current open scope.
5049
5050 if Present (Scope (Subp))
5051 and then Scope (Subp) /= Current_Scope
5052 and then Subp /= Current_Scope
5053 then
5054 Error_Pragma_Arg
5055 ("argument of% must be entity in current scope", Assoc);
5056 return;
5057 end if;
5058
5059 -- Processing for procedure, operator or function. If subprogram
5060 -- is aliased (as for an instance) indicate that the renamed
5061 -- entity (if declared in the same unit) is inlined.
5062
5063 if Is_Subprogram (Subp) then
5064 Inner_Subp := Ultimate_Alias (Inner_Subp);
5065
5066 if In_Same_Source_Unit (Subp, Inner_Subp) then
5067 Set_Inline_Flags (Inner_Subp);
5068
5069 Decl := Parent (Parent (Inner_Subp));
5070
5071 if Nkind (Decl) = N_Subprogram_Declaration
5072 and then Present (Corresponding_Body (Decl))
5073 then
5074 Set_Inline_Flags (Corresponding_Body (Decl));
5075
5076 elsif Is_Generic_Instance (Subp) then
5077
5078 -- Indicate that the body needs to be created for
5079 -- inlining subsequent calls. The instantiation node
5080 -- follows the declaration of the wrapper package
5081 -- created for it.
5082
5083 if Scope (Subp) /= Standard_Standard
5084 and then
5085 Need_Subprogram_Instance_Body
5086 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
5087 Subp)
5088 then
5089 null;
5090 end if;
5091
5092 -- Inline is a program unit pragma (RM 10.1.5) and cannot
5093 -- appear in a formal part to apply to a formal subprogram.
5094 -- Do not apply check within an instance or a formal package
5095 -- the test will have been applied to the original generic.
5096
5097 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
5098 and then List_Containing (Decl) = List_Containing (N)
5099 and then not In_Instance
5100 then
5101 Error_Msg_N
5102 ("Inline cannot apply to a formal subprogram", N);
5103
5104 -- If Subp is a renaming, it is the renamed entity that
5105 -- will appear in any call, and be inlined. However, for
5106 -- ASIS uses it is convenient to indicate that the renaming
5107 -- itself is an inlined subprogram, so that some gnatcheck
5108 -- rules can be applied in the absence of expansion.
5109
5110 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
5111 Set_Inline_Flags (Subp);
5112 end if;
5113 end if;
5114
5115 Applies := True;
5116
5117 -- For a generic subprogram set flag as well, for use at the point
5118 -- of instantiation, to determine whether the body should be
5119 -- generated.
5120
5121 elsif Is_Generic_Subprogram (Subp) then
5122 Set_Inline_Flags (Subp);
5123 Applies := True;
5124
5125 -- Literals are by definition inlined
5126
5127 elsif Kind = E_Enumeration_Literal then
5128 null;
5129
5130 -- Anything else is an error
5131
5132 else
5133 Error_Pragma_Arg
5134 ("expect subprogram name for pragma%", Assoc);
5135 end if;
5136 end Make_Inline;
5137
5138 ----------------------
5139 -- Set_Inline_Flags --
5140 ----------------------
5141
5142 procedure Set_Inline_Flags (Subp : Entity_Id) is
5143 begin
5144 if Active then
5145 Set_Is_Inlined (Subp);
5146 end if;
5147
5148 if not Has_Pragma_Inline (Subp) then
5149 Set_Has_Pragma_Inline (Subp);
5150 Effective := True;
5151 end if;
5152
5153 if Prag_Id = Pragma_Inline_Always then
5154 Set_Has_Pragma_Inline_Always (Subp);
5155 end if;
5156 end Set_Inline_Flags;
5157
5158 -- Start of processing for Process_Inline
5159
5160 begin
5161 Check_No_Identifiers;
5162 Check_At_Least_N_Arguments (1);
5163
5164 if Active then
5165 Inline_Processing_Required := True;
5166 end if;
5167
5168 Assoc := Arg1;
5169 while Present (Assoc) loop
5170 Subp_Id := Get_Pragma_Arg (Assoc);
5171 Analyze (Subp_Id);
5172 Applies := False;
5173
5174 if Is_Entity_Name (Subp_Id) then
5175 Subp := Entity (Subp_Id);
5176
5177 if Subp = Any_Id then
5178
5179 -- If previous error, avoid cascaded errors
5180
5181 Check_Error_Detected;
5182 Applies := True;
5183 Effective := True;
5184
5185 else
5186 Make_Inline (Subp);
5187
5188 -- For the pragma case, climb homonym chain. This is
5189 -- what implements allowing the pragma in the renaming
5190 -- case, with the result applying to the ancestors, and
5191 -- also allows Inline to apply to all previous homonyms.
5192
5193 if not From_Aspect_Specification (N) then
5194 while Present (Homonym (Subp))
5195 and then Scope (Homonym (Subp)) = Current_Scope
5196 loop
5197 Make_Inline (Homonym (Subp));
5198 Subp := Homonym (Subp);
5199 end loop;
5200 end if;
5201 end if;
5202 end if;
5203
5204 if not Applies then
5205 Error_Pragma_Arg
5206 ("inappropriate argument for pragma%", Assoc);
5207
5208 elsif not Effective
5209 and then Warn_On_Redundant_Constructs
5210 and then not Suppress_All_Inlining
5211 then
5212 if Inlining_Not_Possible (Subp) then
5213 Error_Msg_NE
5214 ("pragma Inline for& is ignored?r?",
5215 N, Entity (Subp_Id));
5216 else
5217 Error_Msg_NE
5218 ("pragma Inline for& is redundant?r?",
5219 N, Entity (Subp_Id));
5220 end if;
5221 end if;
5222
5223 Next (Assoc);
5224 end loop;
5225 end Process_Inline;
5226
5227 ----------------------------
5228 -- Process_Interface_Name --
5229 ----------------------------
5230
5231 procedure Process_Interface_Name
5232 (Subprogram_Def : Entity_Id;
5233 Ext_Arg : Node_Id;
5234 Link_Arg : Node_Id)
5235 is
5236 Ext_Nam : Node_Id;
5237 Link_Nam : Node_Id;
5238 String_Val : String_Id;
5239
5240 procedure Check_Form_Of_Interface_Name
5241 (SN : Node_Id;
5242 Ext_Name_Case : Boolean);
5243 -- SN is a string literal node for an interface name. This routine
5244 -- performs some minimal checks that the name is reasonable. In
5245 -- particular that no spaces or other obviously incorrect characters
5246 -- appear. This is only a warning, since any characters are allowed.
5247 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
5248
5249 ----------------------------------
5250 -- Check_Form_Of_Interface_Name --
5251 ----------------------------------
5252
5253 procedure Check_Form_Of_Interface_Name
5254 (SN : Node_Id;
5255 Ext_Name_Case : Boolean)
5256 is
5257 S : constant String_Id := Strval (Expr_Value_S (SN));
5258 SL : constant Nat := String_Length (S);
5259 C : Char_Code;
5260
5261 begin
5262 if SL = 0 then
5263 Error_Msg_N ("interface name cannot be null string", SN);
5264 end if;
5265
5266 for J in 1 .. SL loop
5267 C := Get_String_Char (S, J);
5268
5269 -- Look for dubious character and issue unconditional warning.
5270 -- Definitely dubious if not in character range.
5271
5272 if not In_Character_Range (C)
5273
5274 -- For all cases except CLI target,
5275 -- commas, spaces and slashes are dubious (in CLI, we use
5276 -- commas and backslashes in external names to specify
5277 -- assembly version and public key, while slashes and spaces
5278 -- can be used in names to mark nested classes and
5279 -- valuetypes).
5280
5281 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5282 and then (Get_Character (C) = ','
5283 or else
5284 Get_Character (C) = '\'))
5285 or else (VM_Target /= CLI_Target
5286 and then (Get_Character (C) = ' '
5287 or else
5288 Get_Character (C) = '/'))
5289 then
5290 Error_Msg
5291 ("??interface name contains illegal character",
5292 Sloc (SN) + Source_Ptr (J));
5293 end if;
5294 end loop;
5295 end Check_Form_Of_Interface_Name;
5296
5297 -- Start of processing for Process_Interface_Name
5298
5299 begin
5300 if No (Link_Arg) then
5301 if No (Ext_Arg) then
5302 if VM_Target = CLI_Target
5303 and then Ekind (Subprogram_Def) = E_Package
5304 and then Nkind (Parent (Subprogram_Def)) =
5305 N_Package_Specification
5306 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5307 then
5308 Set_Interface_Name
5309 (Subprogram_Def,
5310 Interface_Name
5311 (Generic_Parent (Parent (Subprogram_Def))));
5312 end if;
5313
5314 return;
5315
5316 elsif Chars (Ext_Arg) = Name_Link_Name then
5317 Ext_Nam := Empty;
5318 Link_Nam := Expression (Ext_Arg);
5319
5320 else
5321 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5322 Ext_Nam := Expression (Ext_Arg);
5323 Link_Nam := Empty;
5324 end if;
5325
5326 else
5327 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5328 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5329 Ext_Nam := Expression (Ext_Arg);
5330 Link_Nam := Expression (Link_Arg);
5331 end if;
5332
5333 -- Check expressions for external name and link name are static
5334
5335 if Present (Ext_Nam) then
5336 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5337 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5338
5339 -- Verify that external name is not the name of a local entity,
5340 -- which would hide the imported one and could lead to run-time
5341 -- surprises. The problem can only arise for entities declared in
5342 -- a package body (otherwise the external name is fully qualified
5343 -- and will not conflict).
5344
5345 declare
5346 Nam : Name_Id;
5347 E : Entity_Id;
5348 Par : Node_Id;
5349
5350 begin
5351 if Prag_Id = Pragma_Import then
5352 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5353 Nam := Name_Find;
5354 E := Entity_Id (Get_Name_Table_Info (Nam));
5355
5356 if Nam /= Chars (Subprogram_Def)
5357 and then Present (E)
5358 and then not Is_Overloadable (E)
5359 and then Is_Immediately_Visible (E)
5360 and then not Is_Imported (E)
5361 and then Ekind (Scope (E)) = E_Package
5362 then
5363 Par := Parent (E);
5364 while Present (Par) loop
5365 if Nkind (Par) = N_Package_Body then
5366 Error_Msg_Sloc := Sloc (E);
5367 Error_Msg_NE
5368 ("imported entity is hidden by & declared#",
5369 Ext_Arg, E);
5370 exit;
5371 end if;
5372
5373 Par := Parent (Par);
5374 end loop;
5375 end if;
5376 end if;
5377 end;
5378 end if;
5379
5380 if Present (Link_Nam) then
5381 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5382 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5383 end if;
5384
5385 -- If there is no link name, just set the external name
5386
5387 if No (Link_Nam) then
5388 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5389
5390 -- For the Link_Name case, the given literal is preceded by an
5391 -- asterisk, which indicates to GCC that the given name should be
5392 -- taken literally, and in particular that no prepending of
5393 -- underlines should occur, even in systems where this is the
5394 -- normal default.
5395
5396 else
5397 Start_String;
5398
5399 if VM_Target = No_VM then
5400 Store_String_Char (Get_Char_Code ('*'));
5401 end if;
5402
5403 String_Val := Strval (Expr_Value_S (Link_Nam));
5404 Store_String_Chars (String_Val);
5405 Link_Nam :=
5406 Make_String_Literal (Sloc (Link_Nam),
5407 Strval => End_String);
5408 end if;
5409
5410 -- Set the interface name. If the entity is a generic instance, use
5411 -- its alias, which is the callable entity.
5412
5413 if Is_Generic_Instance (Subprogram_Def) then
5414 Set_Encoded_Interface_Name
5415 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5416 else
5417 Set_Encoded_Interface_Name
5418 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5419 end if;
5420
5421 -- We allow duplicated export names in CIL/Java, as they are always
5422 -- enclosed in a namespace that differentiates them, and overloaded
5423 -- entities are supported by the VM.
5424
5425 if Convention (Subprogram_Def) /= Convention_CIL
5426 and then
5427 Convention (Subprogram_Def) /= Convention_Java
5428 then
5429 Check_Duplicated_Export_Name (Link_Nam);
5430 end if;
5431 end Process_Interface_Name;
5432
5433 -----------------------------------------
5434 -- Process_Interrupt_Or_Attach_Handler --
5435 -----------------------------------------
5436
5437 procedure Process_Interrupt_Or_Attach_Handler is
5438 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5439 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5440 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5441
5442 begin
5443 Set_Is_Interrupt_Handler (Handler_Proc);
5444
5445 -- If the pragma is not associated with a handler procedure within a
5446 -- protected type, then it must be for a nonprotected procedure for
5447 -- the AAMP target, in which case we don't associate a representation
5448 -- item with the procedure's scope.
5449
5450 if Ekind (Proc_Scope) = E_Protected_Type then
5451 if Prag_Id = Pragma_Interrupt_Handler
5452 or else
5453 Prag_Id = Pragma_Attach_Handler
5454 then
5455 Record_Rep_Item (Proc_Scope, N);
5456 end if;
5457 end if;
5458 end Process_Interrupt_Or_Attach_Handler;
5459
5460 --------------------------------------------------
5461 -- Process_Restrictions_Or_Restriction_Warnings --
5462 --------------------------------------------------
5463
5464 -- Note: some of the simple identifier cases were handled in par-prag,
5465 -- but it is harmless (and more straightforward) to simply handle all
5466 -- cases here, even if it means we repeat a bit of work in some cases.
5467
5468 procedure Process_Restrictions_Or_Restriction_Warnings
5469 (Warn : Boolean)
5470 is
5471 Arg : Node_Id;
5472 R_Id : Restriction_Id;
5473 Id : Name_Id;
5474 Expr : Node_Id;
5475 Val : Uint;
5476
5477 procedure Check_Unit_Name (N : Node_Id);
5478 -- Checks unit name parameter for No_Dependence. Returns if it has
5479 -- an appropriate form, otherwise raises pragma argument error.
5480
5481 ---------------------
5482 -- Check_Unit_Name --
5483 ---------------------
5484
5485 procedure Check_Unit_Name (N : Node_Id) is
5486 begin
5487 if Nkind (N) = N_Selected_Component then
5488 Check_Unit_Name (Prefix (N));
5489 Check_Unit_Name (Selector_Name (N));
5490
5491 elsif Nkind (N) = N_Identifier then
5492 return;
5493
5494 else
5495 Error_Pragma_Arg
5496 ("wrong form for unit name for No_Dependence", N);
5497 end if;
5498 end Check_Unit_Name;
5499
5500 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5501
5502 begin
5503 -- Ignore all Restrictions pragma in CodePeer mode
5504
5505 if CodePeer_Mode then
5506 return;
5507 end if;
5508
5509 Check_Ada_83_Warning;
5510 Check_At_Least_N_Arguments (1);
5511 Check_Valid_Configuration_Pragma;
5512
5513 Arg := Arg1;
5514 while Present (Arg) loop
5515 Id := Chars (Arg);
5516 Expr := Get_Pragma_Arg (Arg);
5517
5518 -- Case of no restriction identifier present
5519
5520 if Id = No_Name then
5521 if Nkind (Expr) /= N_Identifier then
5522 Error_Pragma_Arg
5523 ("invalid form for restriction", Arg);
5524 end if;
5525
5526 R_Id :=
5527 Get_Restriction_Id
5528 (Process_Restriction_Synonyms (Expr));
5529
5530 if R_Id not in All_Boolean_Restrictions then
5531 Error_Msg_Name_1 := Pname;
5532 Error_Msg_N
5533 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5534
5535 -- Check for possible misspelling
5536
5537 for J in Restriction_Id loop
5538 declare
5539 Rnm : constant String := Restriction_Id'Image (J);
5540
5541 begin
5542 Name_Buffer (1 .. Rnm'Length) := Rnm;
5543 Name_Len := Rnm'Length;
5544 Set_Casing (All_Lower_Case);
5545
5546 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5547 Set_Casing
5548 (Identifier_Casing (Current_Source_File));
5549 Error_Msg_String (1 .. Rnm'Length) :=
5550 Name_Buffer (1 .. Name_Len);
5551 Error_Msg_Strlen := Rnm'Length;
5552 Error_Msg_N -- CODEFIX
5553 ("\possible misspelling of ""~""",
5554 Get_Pragma_Arg (Arg));
5555 exit;
5556 end if;
5557 end;
5558 end loop;
5559
5560 raise Pragma_Exit;
5561 end if;
5562
5563 if Implementation_Restriction (R_Id) then
5564 Check_Restriction (No_Implementation_Restrictions, Arg);
5565 end if;
5566
5567 -- Special processing for No_Elaboration_Code restriction
5568
5569 if R_Id = No_Elaboration_Code then
5570
5571 -- Restriction is only recognized within a configuration
5572 -- pragma file, or within a unit of the main extended
5573 -- program. Note: the test for Main_Unit is needed to
5574 -- properly include the case of configuration pragma files.
5575
5576 if not (Current_Sem_Unit = Main_Unit
5577 or else In_Extended_Main_Source_Unit (N))
5578 then
5579 return;
5580
5581 -- Don't allow in a subunit unless already specified in
5582 -- body or spec.
5583
5584 elsif Nkind (Parent (N)) = N_Compilation_Unit
5585 and then Nkind (Unit (Parent (N))) = N_Subunit
5586 and then not Restriction_Active (No_Elaboration_Code)
5587 then
5588 Error_Msg_N
5589 ("invalid specification of ""No_Elaboration_Code""",
5590 N);
5591 Error_Msg_N
5592 ("\restriction cannot be specified in a subunit", N);
5593 Error_Msg_N
5594 ("\unless also specified in body or spec", N);
5595 return;
5596
5597 -- If we have a No_Elaboration_Code pragma that we
5598 -- accept, then it needs to be added to the configuration
5599 -- restrcition set so that we get proper application to
5600 -- other units in the main extended source as required.
5601
5602 else
5603 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
5604 end if;
5605 end if;
5606
5607 -- If this is a warning, then set the warning unless we already
5608 -- have a real restriction active (we never want a warning to
5609 -- override a real restriction).
5610
5611 if Warn then
5612 if not Restriction_Active (R_Id) then
5613 Set_Restriction (R_Id, N);
5614 Restriction_Warnings (R_Id) := True;
5615 end if;
5616
5617 -- If real restriction case, then set it and make sure that the
5618 -- restriction warning flag is off, since a real restriction
5619 -- always overrides a warning.
5620
5621 else
5622 Set_Restriction (R_Id, N);
5623 Restriction_Warnings (R_Id) := False;
5624 end if;
5625
5626 -- Check for obsolescent restrictions in Ada 2005 mode
5627
5628 if not Warn
5629 and then Ada_Version >= Ada_2005
5630 and then (R_Id = No_Asynchronous_Control
5631 or else
5632 R_Id = No_Unchecked_Deallocation
5633 or else
5634 R_Id = No_Unchecked_Conversion)
5635 then
5636 Check_Restriction (No_Obsolescent_Features, N);
5637 end if;
5638
5639 -- A very special case that must be processed here: pragma
5640 -- Restrictions (No_Exceptions) turns off all run-time
5641 -- checking. This is a bit dubious in terms of the formal
5642 -- language definition, but it is what is intended by RM
5643 -- H.4(12). Restriction_Warnings never affects generated code
5644 -- so this is done only in the real restriction case.
5645
5646 -- Atomic_Synchronization is not a real check, so it is not
5647 -- affected by this processing).
5648
5649 if R_Id = No_Exceptions and then not Warn then
5650 for J in Scope_Suppress.Suppress'Range loop
5651 if J /= Atomic_Synchronization then
5652 Scope_Suppress.Suppress (J) := True;
5653 end if;
5654 end loop;
5655 end if;
5656
5657 -- Case of No_Dependence => unit-name. Note that the parser
5658 -- already made the necessary entry in the No_Dependence table.
5659
5660 elsif Id = Name_No_Dependence then
5661 Check_Unit_Name (Expr);
5662
5663 -- Case of No_Specification_Of_Aspect => Identifier.
5664
5665 elsif Id = Name_No_Specification_Of_Aspect then
5666 declare
5667 A_Id : Aspect_Id;
5668
5669 begin
5670 if Nkind (Expr) /= N_Identifier then
5671 A_Id := No_Aspect;
5672 else
5673 A_Id := Get_Aspect_Id (Chars (Expr));
5674 end if;
5675
5676 if A_Id = No_Aspect then
5677 Error_Pragma_Arg ("invalid restriction name", Arg);
5678 else
5679 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5680 end if;
5681 end;
5682
5683 -- All other cases of restriction identifier present
5684
5685 else
5686 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5687 Analyze_And_Resolve (Expr, Any_Integer);
5688
5689 if R_Id not in All_Parameter_Restrictions then
5690 Error_Pragma_Arg
5691 ("invalid restriction parameter identifier", Arg);
5692
5693 elsif not Is_OK_Static_Expression (Expr) then
5694 Flag_Non_Static_Expr
5695 ("value must be static expression!", Expr);
5696 raise Pragma_Exit;
5697
5698 elsif not Is_Integer_Type (Etype (Expr))
5699 or else Expr_Value (Expr) < 0
5700 then
5701 Error_Pragma_Arg
5702 ("value must be non-negative integer", Arg);
5703 end if;
5704
5705 -- Restriction pragma is active
5706
5707 Val := Expr_Value (Expr);
5708
5709 if not UI_Is_In_Int_Range (Val) then
5710 Error_Pragma_Arg
5711 ("pragma ignored, value too large??", Arg);
5712 end if;
5713
5714 -- Warning case. If the real restriction is active, then we
5715 -- ignore the request, since warning never overrides a real
5716 -- restriction. Otherwise we set the proper warning. Note that
5717 -- this circuit sets the warning again if it is already set,
5718 -- which is what we want, since the constant may have changed.
5719
5720 if Warn then
5721 if not Restriction_Active (R_Id) then
5722 Set_Restriction
5723 (R_Id, N, Integer (UI_To_Int (Val)));
5724 Restriction_Warnings (R_Id) := True;
5725 end if;
5726
5727 -- Real restriction case, set restriction and make sure warning
5728 -- flag is off since real restriction always overrides warning.
5729
5730 else
5731 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5732 Restriction_Warnings (R_Id) := False;
5733 end if;
5734 end if;
5735
5736 Next (Arg);
5737 end loop;
5738 end Process_Restrictions_Or_Restriction_Warnings;
5739
5740 ---------------------------------
5741 -- Process_Suppress_Unsuppress --
5742 ---------------------------------
5743
5744 -- Note: this procedure makes entries in the check suppress data
5745 -- structures managed by Sem. See spec of package Sem for full
5746 -- details on how we handle recording of check suppression.
5747
5748 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5749 C : Check_Id;
5750 E_Id : Node_Id;
5751 E : Entity_Id;
5752
5753 In_Package_Spec : constant Boolean :=
5754 Is_Package_Or_Generic_Package (Current_Scope)
5755 and then not In_Package_Body (Current_Scope);
5756
5757 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5758 -- Used to suppress a single check on the given entity
5759
5760 --------------------------------
5761 -- Suppress_Unsuppress_Echeck --
5762 --------------------------------
5763
5764 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5765 begin
5766 -- Check for error of trying to set atomic synchronization for
5767 -- a non-atomic variable.
5768
5769 if C = Atomic_Synchronization
5770 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5771 then
5772 Error_Msg_N
5773 ("pragma & requires atomic type or variable",
5774 Pragma_Identifier (Original_Node (N)));
5775 end if;
5776
5777 Set_Checks_May_Be_Suppressed (E);
5778
5779 if In_Package_Spec then
5780 Push_Global_Suppress_Stack_Entry
5781 (Entity => E,
5782 Check => C,
5783 Suppress => Suppress_Case);
5784 else
5785 Push_Local_Suppress_Stack_Entry
5786 (Entity => E,
5787 Check => C,
5788 Suppress => Suppress_Case);
5789 end if;
5790
5791 -- If this is a first subtype, and the base type is distinct,
5792 -- then also set the suppress flags on the base type.
5793
5794 if Is_First_Subtype (E) and then Etype (E) /= E then
5795 Suppress_Unsuppress_Echeck (Etype (E), C);
5796 end if;
5797 end Suppress_Unsuppress_Echeck;
5798
5799 -- Start of processing for Process_Suppress_Unsuppress
5800
5801 begin
5802 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5803 -- user code: we want to generate checks for analysis purposes, as
5804 -- set respectively by -gnatC and -gnatd.F
5805
5806 if (CodePeer_Mode or Alfa_Mode) and then Comes_From_Source (N) then
5807 return;
5808 end if;
5809
5810 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5811 -- declarative part or a package spec (RM 11.5(5)).
5812
5813 if not Is_Configuration_Pragma then
5814 Check_Is_In_Decl_Part_Or_Package_Spec;
5815 end if;
5816
5817 Check_At_Least_N_Arguments (1);
5818 Check_At_Most_N_Arguments (2);
5819 Check_No_Identifier (Arg1);
5820 Check_Arg_Is_Identifier (Arg1);
5821
5822 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5823
5824 if C = No_Check_Id then
5825 Error_Pragma_Arg
5826 ("argument of pragma% is not valid check name", Arg1);
5827 end if;
5828
5829 if Arg_Count = 1 then
5830
5831 -- Make an entry in the local scope suppress table. This is the
5832 -- table that directly shows the current value of the scope
5833 -- suppress check for any check id value.
5834
5835 if C = All_Checks then
5836
5837 -- For All_Checks, we set all specific predefined checks with
5838 -- the exception of Elaboration_Check, which is handled
5839 -- specially because of not wanting All_Checks to have the
5840 -- effect of deactivating static elaboration order processing.
5841 -- Atomic_Synchronization is also not affected, since this is
5842 -- not a real check.
5843
5844 for J in Scope_Suppress.Suppress'Range loop
5845 if J /= Elaboration_Check
5846 and then
5847 J /= Atomic_Synchronization
5848 then
5849 Scope_Suppress.Suppress (J) := Suppress_Case;
5850 end if;
5851 end loop;
5852
5853 -- If not All_Checks, and predefined check, then set appropriate
5854 -- scope entry. Note that we will set Elaboration_Check if this
5855 -- is explicitly specified. Atomic_Synchronization is allowed
5856 -- only if internally generated and entity is atomic.
5857
5858 elsif C in Predefined_Check_Id
5859 and then (not Comes_From_Source (N)
5860 or else C /= Atomic_Synchronization)
5861 then
5862 Scope_Suppress.Suppress (C) := Suppress_Case;
5863 end if;
5864
5865 -- Also make an entry in the Local_Entity_Suppress table
5866
5867 Push_Local_Suppress_Stack_Entry
5868 (Entity => Empty,
5869 Check => C,
5870 Suppress => Suppress_Case);
5871
5872 -- Case of two arguments present, where the check is suppressed for
5873 -- a specified entity (given as the second argument of the pragma)
5874
5875 else
5876 -- This is obsolescent in Ada 2005 mode
5877
5878 if Ada_Version >= Ada_2005 then
5879 Check_Restriction (No_Obsolescent_Features, Arg2);
5880 end if;
5881
5882 Check_Optional_Identifier (Arg2, Name_On);
5883 E_Id := Get_Pragma_Arg (Arg2);
5884 Analyze (E_Id);
5885
5886 if not Is_Entity_Name (E_Id) then
5887 Error_Pragma_Arg
5888 ("second argument of pragma% must be entity name", Arg2);
5889 end if;
5890
5891 E := Entity (E_Id);
5892
5893 if E = Any_Id then
5894 return;
5895 end if;
5896
5897 -- Enforce RM 11.5(7) which requires that for a pragma that
5898 -- appears within a package spec, the named entity must be
5899 -- within the package spec. We allow the package name itself
5900 -- to be mentioned since that makes sense, although it is not
5901 -- strictly allowed by 11.5(7).
5902
5903 if In_Package_Spec
5904 and then E /= Current_Scope
5905 and then Scope (E) /= Current_Scope
5906 then
5907 Error_Pragma_Arg
5908 ("entity in pragma% is not in package spec (RM 11.5(7))",
5909 Arg2);
5910 end if;
5911
5912 -- Loop through homonyms. As noted below, in the case of a package
5913 -- spec, only homonyms within the package spec are considered.
5914
5915 loop
5916 Suppress_Unsuppress_Echeck (E, C);
5917
5918 if Is_Generic_Instance (E)
5919 and then Is_Subprogram (E)
5920 and then Present (Alias (E))
5921 then
5922 Suppress_Unsuppress_Echeck (Alias (E), C);
5923 end if;
5924
5925 -- Move to next homonym if not aspect spec case
5926
5927 exit when From_Aspect_Specification (N);
5928 E := Homonym (E);
5929 exit when No (E);
5930
5931 -- If we are within a package specification, the pragma only
5932 -- applies to homonyms in the same scope.
5933
5934 exit when In_Package_Spec
5935 and then Scope (E) /= Current_Scope;
5936 end loop;
5937 end if;
5938 end Process_Suppress_Unsuppress;
5939
5940 ------------------
5941 -- Set_Exported --
5942 ------------------
5943
5944 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5945 begin
5946 if Is_Imported (E) then
5947 Error_Pragma_Arg
5948 ("cannot export entity& that was previously imported", Arg);
5949
5950 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5951 Error_Pragma_Arg
5952 ("cannot export entity& that has an address clause", Arg);
5953 end if;
5954
5955 Set_Is_Exported (E);
5956
5957 -- Generate a reference for entity explicitly, because the
5958 -- identifier may be overloaded and name resolution will not
5959 -- generate one.
5960
5961 Generate_Reference (E, Arg);
5962
5963 -- Deal with exporting non-library level entity
5964
5965 if not Is_Library_Level_Entity (E) then
5966
5967 -- Not allowed at all for subprograms
5968
5969 if Is_Subprogram (E) then
5970 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5971
5972 -- Otherwise set public and statically allocated
5973
5974 else
5975 Set_Is_Public (E);
5976 Set_Is_Statically_Allocated (E);
5977
5978 -- Warn if the corresponding W flag is set and the pragma comes
5979 -- from source. The latter may not be true e.g. on VMS where we
5980 -- expand export pragmas for exception codes associated with
5981 -- imported or exported exceptions. We do not want to generate
5982 -- a warning for something that the user did not write.
5983
5984 if Warn_On_Export_Import
5985 and then Comes_From_Source (Arg)
5986 then
5987 Error_Msg_NE
5988 ("?x?& has been made static as a result of Export",
5989 Arg, E);
5990 Error_Msg_N
5991 ("\?x?this usage is non-standard and non-portable",
5992 Arg);
5993 end if;
5994 end if;
5995 end if;
5996
5997 if Warn_On_Export_Import and then Is_Type (E) then
5998 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
5999 end if;
6000
6001 if Warn_On_Export_Import and Inside_A_Generic then
6002 Error_Msg_NE
6003 ("all instances of& will have the same external name?x?",
6004 Arg, E);
6005 end if;
6006 end Set_Exported;
6007
6008 ----------------------------------------------
6009 -- Set_Extended_Import_Export_External_Name --
6010 ----------------------------------------------
6011
6012 procedure Set_Extended_Import_Export_External_Name
6013 (Internal_Ent : Entity_Id;
6014 Arg_External : Node_Id)
6015 is
6016 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
6017 New_Name : Node_Id;
6018
6019 begin
6020 if No (Arg_External) then
6021 return;
6022 end if;
6023
6024 Check_Arg_Is_External_Name (Arg_External);
6025
6026 if Nkind (Arg_External) = N_String_Literal then
6027 if String_Length (Strval (Arg_External)) = 0 then
6028 return;
6029 else
6030 New_Name := Adjust_External_Name_Case (Arg_External);
6031 end if;
6032
6033 elsif Nkind (Arg_External) = N_Identifier then
6034 New_Name := Get_Default_External_Name (Arg_External);
6035
6036 -- Check_Arg_Is_External_Name should let through only identifiers and
6037 -- string literals or static string expressions (which are folded to
6038 -- string literals).
6039
6040 else
6041 raise Program_Error;
6042 end if;
6043
6044 -- If we already have an external name set (by a prior normal Import
6045 -- or Export pragma), then the external names must match
6046
6047 if Present (Interface_Name (Internal_Ent)) then
6048 Check_Matching_Internal_Names : declare
6049 S1 : constant String_Id := Strval (Old_Name);
6050 S2 : constant String_Id := Strval (New_Name);
6051
6052 procedure Mismatch;
6053 pragma No_Return (Mismatch);
6054 -- Called if names do not match
6055
6056 --------------
6057 -- Mismatch --
6058 --------------
6059
6060 procedure Mismatch is
6061 begin
6062 Error_Msg_Sloc := Sloc (Old_Name);
6063 Error_Pragma_Arg
6064 ("external name does not match that given #",
6065 Arg_External);
6066 end Mismatch;
6067
6068 -- Start of processing for Check_Matching_Internal_Names
6069
6070 begin
6071 if String_Length (S1) /= String_Length (S2) then
6072 Mismatch;
6073
6074 else
6075 for J in 1 .. String_Length (S1) loop
6076 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
6077 Mismatch;
6078 end if;
6079 end loop;
6080 end if;
6081 end Check_Matching_Internal_Names;
6082
6083 -- Otherwise set the given name
6084
6085 else
6086 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
6087 Check_Duplicated_Export_Name (New_Name);
6088 end if;
6089 end Set_Extended_Import_Export_External_Name;
6090
6091 ------------------
6092 -- Set_Imported --
6093 ------------------
6094
6095 procedure Set_Imported (E : Entity_Id) is
6096 begin
6097 -- Error message if already imported or exported
6098
6099 if Is_Exported (E) or else Is_Imported (E) then
6100
6101 -- Error if being set Exported twice
6102
6103 if Is_Exported (E) then
6104 Error_Msg_NE ("entity& was previously exported", N, E);
6105
6106 -- OK if Import/Interface case
6107
6108 elsif Import_Interface_Present (N) then
6109 goto OK;
6110
6111 -- Error if being set Imported twice
6112
6113 else
6114 Error_Msg_NE ("entity& was previously imported", N, E);
6115 end if;
6116
6117 Error_Msg_Name_1 := Pname;
6118 Error_Msg_N
6119 ("\(pragma% applies to all previous entities)", N);
6120
6121 Error_Msg_Sloc := Sloc (E);
6122 Error_Msg_NE ("\import not allowed for& declared#", N, E);
6123
6124 -- Here if not previously imported or exported, OK to import
6125
6126 else
6127 Set_Is_Imported (E);
6128
6129 -- If the entity is an object that is not at the library level,
6130 -- then it is statically allocated. We do not worry about objects
6131 -- with address clauses in this context since they are not really
6132 -- imported in the linker sense.
6133
6134 if Is_Object (E)
6135 and then not Is_Library_Level_Entity (E)
6136 and then No (Address_Clause (E))
6137 then
6138 Set_Is_Statically_Allocated (E);
6139 end if;
6140 end if;
6141
6142 <<OK>> null;
6143 end Set_Imported;
6144
6145 -------------------------
6146 -- Set_Mechanism_Value --
6147 -------------------------
6148
6149 -- Note: the mechanism name has not been analyzed (and cannot indeed be
6150 -- analyzed, since it is semantic nonsense), so we get it in the exact
6151 -- form created by the parser.
6152
6153 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
6154 Class : Node_Id;
6155 Param : Node_Id;
6156 Mech_Name_Id : Name_Id;
6157
6158 procedure Bad_Class;
6159 pragma No_Return (Bad_Class);
6160 -- Signal bad descriptor class name
6161
6162 procedure Bad_Mechanism;
6163 pragma No_Return (Bad_Mechanism);
6164 -- Signal bad mechanism name
6165
6166 ---------------
6167 -- Bad_Class --
6168 ---------------
6169
6170 procedure Bad_Class is
6171 begin
6172 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
6173 end Bad_Class;
6174
6175 -------------------------
6176 -- Bad_Mechanism_Value --
6177 -------------------------
6178
6179 procedure Bad_Mechanism is
6180 begin
6181 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
6182 end Bad_Mechanism;
6183
6184 -- Start of processing for Set_Mechanism_Value
6185
6186 begin
6187 if Mechanism (Ent) /= Default_Mechanism then
6188 Error_Msg_NE
6189 ("mechanism for & has already been set", Mech_Name, Ent);
6190 end if;
6191
6192 -- MECHANISM_NAME ::= value | reference | descriptor |
6193 -- short_descriptor
6194
6195 if Nkind (Mech_Name) = N_Identifier then
6196 if Chars (Mech_Name) = Name_Value then
6197 Set_Mechanism (Ent, By_Copy);
6198 return;
6199
6200 elsif Chars (Mech_Name) = Name_Reference then
6201 Set_Mechanism (Ent, By_Reference);
6202 return;
6203
6204 elsif Chars (Mech_Name) = Name_Descriptor then
6205 Check_VMS (Mech_Name);
6206
6207 -- Descriptor => Short_Descriptor if pragma was given
6208
6209 if Short_Descriptors then
6210 Set_Mechanism (Ent, By_Short_Descriptor);
6211 else
6212 Set_Mechanism (Ent, By_Descriptor);
6213 end if;
6214
6215 return;
6216
6217 elsif Chars (Mech_Name) = Name_Short_Descriptor then
6218 Check_VMS (Mech_Name);
6219 Set_Mechanism (Ent, By_Short_Descriptor);
6220 return;
6221
6222 elsif Chars (Mech_Name) = Name_Copy then
6223 Error_Pragma_Arg
6224 ("bad mechanism name, Value assumed", Mech_Name);
6225
6226 else
6227 Bad_Mechanism;
6228 end if;
6229
6230 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
6231 -- short_descriptor (CLASS_NAME)
6232 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6233
6234 -- Note: this form is parsed as an indexed component
6235
6236 elsif Nkind (Mech_Name) = N_Indexed_Component then
6237 Class := First (Expressions (Mech_Name));
6238
6239 if Nkind (Prefix (Mech_Name)) /= N_Identifier
6240 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
6241 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
6242 or else Present (Next (Class))
6243 then
6244 Bad_Mechanism;
6245 else
6246 Mech_Name_Id := Chars (Prefix (Mech_Name));
6247
6248 -- Change Descriptor => Short_Descriptor if pragma was given
6249
6250 if Mech_Name_Id = Name_Descriptor
6251 and then Short_Descriptors
6252 then
6253 Mech_Name_Id := Name_Short_Descriptor;
6254 end if;
6255 end if;
6256
6257 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
6258 -- short_descriptor (Class => CLASS_NAME)
6259 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6260
6261 -- Note: this form is parsed as a function call
6262
6263 elsif Nkind (Mech_Name) = N_Function_Call then
6264 Param := First (Parameter_Associations (Mech_Name));
6265
6266 if Nkind (Name (Mech_Name)) /= N_Identifier
6267 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6268 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6269 or else Present (Next (Param))
6270 or else No (Selector_Name (Param))
6271 or else Chars (Selector_Name (Param)) /= Name_Class
6272 then
6273 Bad_Mechanism;
6274 else
6275 Class := Explicit_Actual_Parameter (Param);
6276 Mech_Name_Id := Chars (Name (Mech_Name));
6277 end if;
6278
6279 else
6280 Bad_Mechanism;
6281 end if;
6282
6283 -- Fall through here with Class set to descriptor class name
6284
6285 Check_VMS (Mech_Name);
6286
6287 if Nkind (Class) /= N_Identifier then
6288 Bad_Class;
6289
6290 elsif Mech_Name_Id = Name_Descriptor
6291 and then Chars (Class) = Name_UBS
6292 then
6293 Set_Mechanism (Ent, By_Descriptor_UBS);
6294
6295 elsif Mech_Name_Id = Name_Descriptor
6296 and then Chars (Class) = Name_UBSB
6297 then
6298 Set_Mechanism (Ent, By_Descriptor_UBSB);
6299
6300 elsif Mech_Name_Id = Name_Descriptor
6301 and then Chars (Class) = Name_UBA
6302 then
6303 Set_Mechanism (Ent, By_Descriptor_UBA);
6304
6305 elsif Mech_Name_Id = Name_Descriptor
6306 and then Chars (Class) = Name_S
6307 then
6308 Set_Mechanism (Ent, By_Descriptor_S);
6309
6310 elsif Mech_Name_Id = Name_Descriptor
6311 and then Chars (Class) = Name_SB
6312 then
6313 Set_Mechanism (Ent, By_Descriptor_SB);
6314
6315 elsif Mech_Name_Id = Name_Descriptor
6316 and then Chars (Class) = Name_A
6317 then
6318 Set_Mechanism (Ent, By_Descriptor_A);
6319
6320 elsif Mech_Name_Id = Name_Descriptor
6321 and then Chars (Class) = Name_NCA
6322 then
6323 Set_Mechanism (Ent, By_Descriptor_NCA);
6324
6325 elsif Mech_Name_Id = Name_Short_Descriptor
6326 and then Chars (Class) = Name_UBS
6327 then
6328 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6329
6330 elsif Mech_Name_Id = Name_Short_Descriptor
6331 and then Chars (Class) = Name_UBSB
6332 then
6333 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6334
6335 elsif Mech_Name_Id = Name_Short_Descriptor
6336 and then Chars (Class) = Name_UBA
6337 then
6338 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6339
6340 elsif Mech_Name_Id = Name_Short_Descriptor
6341 and then Chars (Class) = Name_S
6342 then
6343 Set_Mechanism (Ent, By_Short_Descriptor_S);
6344
6345 elsif Mech_Name_Id = Name_Short_Descriptor
6346 and then Chars (Class) = Name_SB
6347 then
6348 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6349
6350 elsif Mech_Name_Id = Name_Short_Descriptor
6351 and then Chars (Class) = Name_A
6352 then
6353 Set_Mechanism (Ent, By_Short_Descriptor_A);
6354
6355 elsif Mech_Name_Id = Name_Short_Descriptor
6356 and then Chars (Class) = Name_NCA
6357 then
6358 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6359
6360 else
6361 Bad_Class;
6362 end if;
6363 end Set_Mechanism_Value;
6364
6365 ---------------------------
6366 -- Set_Ravenscar_Profile --
6367 ---------------------------
6368
6369 -- The tasks to be done here are
6370
6371 -- Set required policies
6372
6373 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6374 -- pragma Locking_Policy (Ceiling_Locking)
6375
6376 -- Set Detect_Blocking mode
6377
6378 -- Set required restrictions (see System.Rident for detailed list)
6379
6380 -- Set the No_Dependence rules
6381 -- No_Dependence => Ada.Asynchronous_Task_Control
6382 -- No_Dependence => Ada.Calendar
6383 -- No_Dependence => Ada.Execution_Time.Group_Budget
6384 -- No_Dependence => Ada.Execution_Time.Timers
6385 -- No_Dependence => Ada.Task_Attributes
6386 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6387
6388 procedure Set_Ravenscar_Profile (N : Node_Id) is
6389 Prefix_Entity : Entity_Id;
6390 Selector_Entity : Entity_Id;
6391 Prefix_Node : Node_Id;
6392 Node : Node_Id;
6393
6394 begin
6395 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6396
6397 if Task_Dispatching_Policy /= ' '
6398 and then Task_Dispatching_Policy /= 'F'
6399 then
6400 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6401 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6402
6403 -- Set the FIFO_Within_Priorities policy, but always preserve
6404 -- System_Location since we like the error message with the run time
6405 -- name.
6406
6407 else
6408 Task_Dispatching_Policy := 'F';
6409
6410 if Task_Dispatching_Policy_Sloc /= System_Location then
6411 Task_Dispatching_Policy_Sloc := Loc;
6412 end if;
6413 end if;
6414
6415 -- pragma Locking_Policy (Ceiling_Locking)
6416
6417 if Locking_Policy /= ' '
6418 and then Locking_Policy /= 'C'
6419 then
6420 Error_Msg_Sloc := Locking_Policy_Sloc;
6421 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6422
6423 -- Set the Ceiling_Locking policy, but preserve System_Location since
6424 -- we like the error message with the run time name.
6425
6426 else
6427 Locking_Policy := 'C';
6428
6429 if Locking_Policy_Sloc /= System_Location then
6430 Locking_Policy_Sloc := Loc;
6431 end if;
6432 end if;
6433
6434 -- pragma Detect_Blocking
6435
6436 Detect_Blocking := True;
6437
6438 -- Set the corresponding restrictions
6439
6440 Set_Profile_Restrictions
6441 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6442
6443 -- Set the No_Dependence restrictions
6444
6445 -- The following No_Dependence restrictions:
6446 -- No_Dependence => Ada.Asynchronous_Task_Control
6447 -- No_Dependence => Ada.Calendar
6448 -- No_Dependence => Ada.Task_Attributes
6449 -- are already set by previous call to Set_Profile_Restrictions.
6450
6451 -- Set the following restrictions which were added to Ada 2005:
6452 -- No_Dependence => Ada.Execution_Time.Group_Budget
6453 -- No_Dependence => Ada.Execution_Time.Timers
6454
6455 if Ada_Version >= Ada_2005 then
6456 Name_Buffer (1 .. 3) := "ada";
6457 Name_Len := 3;
6458
6459 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6460
6461 Name_Buffer (1 .. 14) := "execution_time";
6462 Name_Len := 14;
6463
6464 Selector_Entity := Make_Identifier (Loc, Name_Find);
6465
6466 Prefix_Node :=
6467 Make_Selected_Component
6468 (Sloc => Loc,
6469 Prefix => Prefix_Entity,
6470 Selector_Name => Selector_Entity);
6471
6472 Name_Buffer (1 .. 13) := "group_budgets";
6473 Name_Len := 13;
6474
6475 Selector_Entity := Make_Identifier (Loc, Name_Find);
6476
6477 Node :=
6478 Make_Selected_Component
6479 (Sloc => Loc,
6480 Prefix => Prefix_Node,
6481 Selector_Name => Selector_Entity);
6482
6483 Set_Restriction_No_Dependence
6484 (Unit => Node,
6485 Warn => Treat_Restrictions_As_Warnings,
6486 Profile => Ravenscar);
6487
6488 Name_Buffer (1 .. 6) := "timers";
6489 Name_Len := 6;
6490
6491 Selector_Entity := Make_Identifier (Loc, Name_Find);
6492
6493 Node :=
6494 Make_Selected_Component
6495 (Sloc => Loc,
6496 Prefix => Prefix_Node,
6497 Selector_Name => Selector_Entity);
6498
6499 Set_Restriction_No_Dependence
6500 (Unit => Node,
6501 Warn => Treat_Restrictions_As_Warnings,
6502 Profile => Ravenscar);
6503 end if;
6504
6505 -- Set the following restrictions which was added to Ada 2012 (see
6506 -- AI-0171):
6507 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6508
6509 if Ada_Version >= Ada_2012 then
6510 Name_Buffer (1 .. 6) := "system";
6511 Name_Len := 6;
6512
6513 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6514
6515 Name_Buffer (1 .. 15) := "multiprocessors";
6516 Name_Len := 15;
6517
6518 Selector_Entity := Make_Identifier (Loc, Name_Find);
6519
6520 Prefix_Node :=
6521 Make_Selected_Component
6522 (Sloc => Loc,
6523 Prefix => Prefix_Entity,
6524 Selector_Name => Selector_Entity);
6525
6526 Name_Buffer (1 .. 19) := "dispatching_domains";
6527 Name_Len := 19;
6528
6529 Selector_Entity := Make_Identifier (Loc, Name_Find);
6530
6531 Node :=
6532 Make_Selected_Component
6533 (Sloc => Loc,
6534 Prefix => Prefix_Node,
6535 Selector_Name => Selector_Entity);
6536
6537 Set_Restriction_No_Dependence
6538 (Unit => Node,
6539 Warn => Treat_Restrictions_As_Warnings,
6540 Profile => Ravenscar);
6541 end if;
6542 end Set_Ravenscar_Profile;
6543
6544 ----------------
6545 -- S14_Pragma --
6546 ----------------
6547
6548 procedure S14_Pragma is
6549 begin
6550 if not Formal_Extensions then
6551 Error_Pragma ("pragma% requires the use of debug switch -gnatd.V");
6552 end if;
6553 end S14_Pragma;
6554
6555 -- Start of processing for Analyze_Pragma
6556
6557 begin
6558 -- The following code is a defense against recursion. Not clear that
6559 -- this can happen legitimately, but perhaps some error situations
6560 -- can cause it, and we did see this recursion during testing.
6561
6562 if Analyzed (N) then
6563 return;
6564 else
6565 Set_Analyzed (N, True);
6566 end if;
6567
6568 -- Deal with unrecognized pragma
6569
6570 Pname := Pragma_Name (N);
6571
6572 if not Is_Pragma_Name (Pname) then
6573 if Warn_On_Unrecognized_Pragma then
6574 Error_Msg_Name_1 := Pname;
6575 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
6576
6577 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6578 if Is_Bad_Spelling_Of (Pname, PN) then
6579 Error_Msg_Name_1 := PN;
6580 Error_Msg_N -- CODEFIX
6581 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
6582 exit;
6583 end if;
6584 end loop;
6585 end if;
6586
6587 return;
6588 end if;
6589
6590 -- Here to start processing for recognized pragma
6591
6592 Prag_Id := Get_Pragma_Id (Pname);
6593
6594 if Present (Corresponding_Aspect (N)) then
6595 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6596 end if;
6597
6598 -- Preset arguments
6599
6600 Arg_Count := 0;
6601 Arg1 := Empty;
6602 Arg2 := Empty;
6603 Arg3 := Empty;
6604 Arg4 := Empty;
6605
6606 if Present (Pragma_Argument_Associations (N)) then
6607 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6608 Arg1 := First (Pragma_Argument_Associations (N));
6609
6610 if Present (Arg1) then
6611 Arg2 := Next (Arg1);
6612
6613 if Present (Arg2) then
6614 Arg3 := Next (Arg2);
6615
6616 if Present (Arg3) then
6617 Arg4 := Next (Arg3);
6618 end if;
6619 end if;
6620 end if;
6621 end if;
6622
6623 -- An enumeration type defines the pragmas that are supported by the
6624 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6625 -- into the corresponding enumeration value for the following case.
6626
6627 case Prag_Id is
6628
6629 -----------------
6630 -- Abort_Defer --
6631 -----------------
6632
6633 -- pragma Abort_Defer;
6634
6635 when Pragma_Abort_Defer =>
6636 GNAT_Pragma;
6637 Check_Arg_Count (0);
6638
6639 -- The only required semantic processing is to check the
6640 -- placement. This pragma must appear at the start of the
6641 -- statement sequence of a handled sequence of statements.
6642
6643 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6644 or else N /= First (Statements (Parent (N)))
6645 then
6646 Pragma_Misplaced;
6647 end if;
6648
6649 --------------------
6650 -- Abstract_State --
6651 --------------------
6652
6653 -- pragma Abstract_State (ABSTRACT_STATE_LIST)
6654
6655 -- ABSTRACT_STATE_LIST ::=
6656 -- null
6657 -- | STATE_NAME_WITH_PROPERTIES {, STATE_NAME_WITH_PROPERTIES}
6658
6659 -- STATE_NAME_WITH_PROPERTIES ::=
6660 -- STATE_NAME
6661 -- | (STATE_NAME with PROPERTY_LIST)
6662
6663 -- PROPERTY_LIST ::= PROPERTY {, PROPERTY}
6664 -- PROPERTY ::= SIMPLE_PROPERTY
6665 -- | NAME_VALUE_PROPERTY
6666 -- SIMPLE_PROPERTY ::= IDENTIFIER
6667 -- NAME_VALUE_PROPERTY ::= IDENTIFIER => EXPRESSION
6668 -- STATE_NAME ::= DEFINING_IDENTIFIER
6669
6670 when Pragma_Abstract_State => Abstract_State : declare
6671 Pack_Id : Entity_Id;
6672
6673 -- Flags used to verify the consistency of states
6674
6675 Non_Null_Seen : Boolean := False;
6676 Null_Seen : Boolean := False;
6677
6678 procedure Analyze_Abstract_State (State : Node_Id);
6679 -- Verify the legality of a single state declaration. Create and
6680 -- decorate a state abstraction entity and introduce it into the
6681 -- visibility chain.
6682
6683 ----------------------------
6684 -- Analyze_Abstract_State --
6685 ----------------------------
6686
6687 procedure Analyze_Abstract_State (State : Node_Id) is
6688 procedure Check_Duplicate_Property
6689 (Prop : Node_Id;
6690 Status : in out Boolean);
6691 -- Flag Status denotes whether a particular property has been
6692 -- seen while processing a state. This routine verifies that
6693 -- Prop is not a duplicate property and sets the flag Status.
6694
6695 ------------------------------
6696 -- Check_Duplicate_Property --
6697 ------------------------------
6698
6699 procedure Check_Duplicate_Property
6700 (Prop : Node_Id;
6701 Status : in out Boolean)
6702 is
6703 begin
6704 if Status then
6705 Error_Msg_N ("duplicate state property", Prop);
6706 end if;
6707
6708 Status := True;
6709 end Check_Duplicate_Property;
6710
6711 -- Local variables
6712
6713 Errors : constant Nat := Serious_Errors_Detected;
6714 Loc : constant Source_Ptr := Sloc (State);
6715 Assoc : Node_Id;
6716 Id : Entity_Id;
6717 Is_Null : Boolean := False;
6718 Level : Uint := Uint_0;
6719 Name : Name_Id;
6720 Prop : Node_Id;
6721
6722 -- Flags used to verify the consistency of properties
6723
6724 Input_Seen : Boolean := False;
6725 Integrity_Seen : Boolean := False;
6726 Output_Seen : Boolean := False;
6727 Volatile_Seen : Boolean := False;
6728
6729 -- Start of processing for Analyze_Abstract_State
6730
6731 begin
6732 -- A package with a null abstract state is not allowed to
6733 -- declare additional states.
6734
6735 if Null_Seen then
6736 Error_Msg_Name_1 := Chars (Pack_Id);
6737 Error_Msg_N ("package % has null abstract state", State);
6738
6739 -- Null states appear as internally generated entities
6740
6741 elsif Nkind (State) = N_Null then
6742 Name := New_Internal_Name ('S');
6743 Is_Null := True;
6744 Null_Seen := True;
6745
6746 -- Catch a case where a null state appears in a list of
6747 -- non-null states.
6748
6749 if Non_Null_Seen then
6750 Error_Msg_Name_1 := Chars (Pack_Id);
6751 Error_Msg_N
6752 ("package % has non-null abstract state", State);
6753 end if;
6754
6755 -- Simple state declaration
6756
6757 elsif Nkind (State) = N_Identifier then
6758 Name := Chars (State);
6759 Non_Null_Seen := True;
6760
6761 -- State declaration with various properties. This construct
6762 -- appears as an extension aggregate in the tree.
6763
6764 elsif Nkind (State) = N_Extension_Aggregate then
6765 if Nkind (Ancestor_Part (State)) = N_Identifier then
6766 Name := Chars (Ancestor_Part (State));
6767 Non_Null_Seen := True;
6768 else
6769 Error_Msg_N
6770 ("state name must be an identifier",
6771 Ancestor_Part (State));
6772 end if;
6773
6774 -- Process properties Input, Output and Volatile. Ensure
6775 -- that none of them appear more than once.
6776
6777 Prop := First (Expressions (State));
6778 while Present (Prop) loop
6779 if Nkind (Prop) = N_Identifier then
6780 if Chars (Prop) = Name_Input then
6781 Check_Duplicate_Property (Prop, Input_Seen);
6782 elsif Chars (Prop) = Name_Output then
6783 Check_Duplicate_Property (Prop, Output_Seen);
6784 elsif Chars (Prop) = Name_Volatile then
6785 Check_Duplicate_Property (Prop, Volatile_Seen);
6786 else
6787 Error_Msg_N ("invalid state property", Prop);
6788 end if;
6789 else
6790 Error_Msg_N ("invalid state property", Prop);
6791 end if;
6792
6793 Next (Prop);
6794 end loop;
6795
6796 -- Volatile requires exactly one Input or Output
6797
6798 if Volatile_Seen
6799 and then
6800 ((Input_Seen and then Output_Seen) -- both
6801 or else
6802 (not Input_Seen and then not Output_Seen)) -- none
6803 then
6804 Error_Msg_N
6805 ("property Volatile requires exactly one Input or " &
6806 "Output", State);
6807 end if;
6808
6809 -- Either Input or Output require Volatile
6810
6811 if (Input_Seen or Output_Seen)
6812 and then not Volatile_Seen
6813 then
6814 Error_Msg_N
6815 ("properties Input and Output require Volatile", State);
6816 end if;
6817
6818 -- State property Integrity appears as a component
6819 -- association.
6820
6821 Assoc := First (Component_Associations (State));
6822 while Present (Assoc) loop
6823 Prop := First (Choices (Assoc));
6824 while Present (Prop) loop
6825 if Nkind (Prop) = N_Identifier
6826 and then Chars (Prop) = Name_Integrity
6827 then
6828 Check_Duplicate_Property (Prop, Integrity_Seen);
6829 else
6830 Error_Msg_N ("invalid state property", Prop);
6831 end if;
6832
6833 Next (Prop);
6834 end loop;
6835
6836 if Nkind (Expression (Assoc)) = N_Integer_Literal then
6837 Level := Intval (Expression (Assoc));
6838 else
6839 Error_Msg_N
6840 ("integrity level must be an integer literal",
6841 Expression (Assoc));
6842 end if;
6843
6844 Next (Assoc);
6845 end loop;
6846
6847 -- Any other attempt to declare a state is erroneous
6848
6849 else
6850 Error_Msg_N ("malformed abstract state declaration", State);
6851 end if;
6852
6853 -- Do not generate a state abstraction entity if it was not
6854 -- properly declared.
6855
6856 if Serious_Errors_Detected > Errors then
6857 return;
6858 end if;
6859
6860 -- The generated state abstraction reuses the same characters
6861 -- from the original state declaration. Decorate the entity.
6862
6863 Id := Make_Defining_Identifier (Loc, New_External_Name (Name));
6864 Set_Comes_From_Source (Id, not Is_Null);
6865 Set_Parent (Id, State);
6866 Set_Ekind (Id, E_Abstract_State);
6867 Set_Etype (Id, Standard_Void_Type);
6868 Set_Integrity_Level (Id, Level);
6869 Set_Refined_State (Id, Empty);
6870
6871 -- Every non-null state must be nameable and resolvable the
6872 -- same way a constant is.
6873
6874 if not Is_Null then
6875 Push_Scope (Pack_Id);
6876 Enter_Name (Id);
6877 Pop_Scope;
6878 end if;
6879
6880 -- Associate the state with its related package
6881
6882 if No (Abstract_States (Pack_Id)) then
6883 Set_Abstract_States (Pack_Id, New_Elmt_List);
6884 end if;
6885
6886 Append_Elmt (Id, Abstract_States (Pack_Id));
6887 end Analyze_Abstract_State;
6888
6889 -- Local variables
6890
6891 Par : Node_Id;
6892 State : Node_Id;
6893
6894 -- Start of processing for Abstract_State
6895
6896 begin
6897 GNAT_Pragma;
6898 S14_Pragma;
6899 Check_Arg_Count (1);
6900
6901 -- Ensure the proper placement of the pragma. Abstract states must
6902 -- be associated with a package declaration.
6903
6904 if From_Aspect_Specification (N) then
6905 Par := Parent (Corresponding_Aspect (N));
6906 else
6907 Par := Parent (Parent (N));
6908 end if;
6909
6910 if Nkind (Par) = N_Compilation_Unit then
6911 Par := Unit (Par);
6912 end if;
6913
6914 if Nkind (Par) /= N_Package_Declaration then
6915 Pragma_Misplaced;
6916 return;
6917 end if;
6918
6919 Pack_Id := Defining_Unit_Name (Specification (Par));
6920 State := Expression (Arg1);
6921
6922 -- Multiple abstract states appear as an aggregate
6923
6924 if Nkind (State) = N_Aggregate then
6925 State := First (Expressions (State));
6926 while Present (State) loop
6927 Analyze_Abstract_State (State);
6928
6929 Next (State);
6930 end loop;
6931
6932 -- Various forms of a single abstract state. Note that these may
6933 -- include malformed state declarations.
6934
6935 else
6936 Analyze_Abstract_State (State);
6937 end if;
6938 end Abstract_State;
6939
6940 ------------
6941 -- Ada_83 --
6942 ------------
6943
6944 -- pragma Ada_83;
6945
6946 -- Note: this pragma also has some specific processing in Par.Prag
6947 -- because we want to set the Ada version mode during parsing.
6948
6949 when Pragma_Ada_83 =>
6950 GNAT_Pragma;
6951 Check_Arg_Count (0);
6952
6953 -- We really should check unconditionally for proper configuration
6954 -- pragma placement, since we really don't want mixed Ada modes
6955 -- within a single unit, and the GNAT reference manual has always
6956 -- said this was a configuration pragma, but we did not check and
6957 -- are hesitant to add the check now.
6958
6959 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6960 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6961 -- or Ada 2012 mode.
6962
6963 if Ada_Version >= Ada_2005 then
6964 Check_Valid_Configuration_Pragma;
6965 end if;
6966
6967 -- Now set Ada 83 mode
6968
6969 Ada_Version := Ada_83;
6970 Ada_Version_Explicit := Ada_Version;
6971
6972 ------------
6973 -- Ada_95 --
6974 ------------
6975
6976 -- pragma Ada_95;
6977
6978 -- Note: this pragma also has some specific processing in Par.Prag
6979 -- because we want to set the Ada 83 version mode during parsing.
6980
6981 when Pragma_Ada_95 =>
6982 GNAT_Pragma;
6983 Check_Arg_Count (0);
6984
6985 -- We really should check unconditionally for proper configuration
6986 -- pragma placement, since we really don't want mixed Ada modes
6987 -- within a single unit, and the GNAT reference manual has always
6988 -- said this was a configuration pragma, but we did not check and
6989 -- are hesitant to add the check now.
6990
6991 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
6992 -- or Ada 95, so we must check if we are in Ada 2005 mode.
6993
6994 if Ada_Version >= Ada_2005 then
6995 Check_Valid_Configuration_Pragma;
6996 end if;
6997
6998 -- Now set Ada 95 mode
6999
7000 Ada_Version := Ada_95;
7001 Ada_Version_Explicit := Ada_Version;
7002
7003 ---------------------
7004 -- Ada_05/Ada_2005 --
7005 ---------------------
7006
7007 -- pragma Ada_05;
7008 -- pragma Ada_05 (LOCAL_NAME);
7009
7010 -- pragma Ada_2005;
7011 -- pragma Ada_2005 (LOCAL_NAME):
7012
7013 -- Note: these pragmas also have some specific processing in Par.Prag
7014 -- because we want to set the Ada 2005 version mode during parsing.
7015
7016 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
7017 E_Id : Node_Id;
7018
7019 begin
7020 GNAT_Pragma;
7021
7022 if Arg_Count = 1 then
7023 Check_Arg_Is_Local_Name (Arg1);
7024 E_Id := Get_Pragma_Arg (Arg1);
7025
7026 if Etype (E_Id) = Any_Type then
7027 return;
7028 end if;
7029
7030 Set_Is_Ada_2005_Only (Entity (E_Id));
7031 Record_Rep_Item (Entity (E_Id), N);
7032
7033 else
7034 Check_Arg_Count (0);
7035
7036 -- For Ada_2005 we unconditionally enforce the documented
7037 -- configuration pragma placement, since we do not want to
7038 -- tolerate mixed modes in a unit involving Ada 2005. That
7039 -- would cause real difficulties for those cases where there
7040 -- are incompatibilities between Ada 95 and Ada 2005.
7041
7042 Check_Valid_Configuration_Pragma;
7043
7044 -- Now set appropriate Ada mode
7045
7046 Ada_Version := Ada_2005;
7047 Ada_Version_Explicit := Ada_2005;
7048 end if;
7049 end;
7050
7051 ---------------------
7052 -- Ada_12/Ada_2012 --
7053 ---------------------
7054
7055 -- pragma Ada_12;
7056 -- pragma Ada_12 (LOCAL_NAME);
7057
7058 -- pragma Ada_2012;
7059 -- pragma Ada_2012 (LOCAL_NAME):
7060
7061 -- Note: these pragmas also have some specific processing in Par.Prag
7062 -- because we want to set the Ada 2012 version mode during parsing.
7063
7064 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
7065 E_Id : Node_Id;
7066
7067 begin
7068 GNAT_Pragma;
7069
7070 if Arg_Count = 1 then
7071 Check_Arg_Is_Local_Name (Arg1);
7072 E_Id := Get_Pragma_Arg (Arg1);
7073
7074 if Etype (E_Id) = Any_Type then
7075 return;
7076 end if;
7077
7078 Set_Is_Ada_2012_Only (Entity (E_Id));
7079 Record_Rep_Item (Entity (E_Id), N);
7080
7081 else
7082 Check_Arg_Count (0);
7083
7084 -- For Ada_2012 we unconditionally enforce the documented
7085 -- configuration pragma placement, since we do not want to
7086 -- tolerate mixed modes in a unit involving Ada 2012. That
7087 -- would cause real difficulties for those cases where there
7088 -- are incompatibilities between Ada 95 and Ada 2012. We could
7089 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
7090
7091 Check_Valid_Configuration_Pragma;
7092
7093 -- Now set appropriate Ada mode
7094
7095 Ada_Version := Ada_2012;
7096 Ada_Version_Explicit := Ada_2012;
7097 end if;
7098 end;
7099
7100 ----------------------
7101 -- All_Calls_Remote --
7102 ----------------------
7103
7104 -- pragma All_Calls_Remote [(library_package_NAME)];
7105
7106 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
7107 Lib_Entity : Entity_Id;
7108
7109 begin
7110 Check_Ada_83_Warning;
7111 Check_Valid_Library_Unit_Pragma;
7112
7113 if Nkind (N) = N_Null_Statement then
7114 return;
7115 end if;
7116
7117 Lib_Entity := Find_Lib_Unit_Name;
7118
7119 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
7120
7121 if Present (Lib_Entity)
7122 and then not Debug_Flag_U
7123 then
7124 if not Is_Remote_Call_Interface (Lib_Entity) then
7125 Error_Pragma ("pragma% only apply to rci unit");
7126
7127 -- Set flag for entity of the library unit
7128
7129 else
7130 Set_Has_All_Calls_Remote (Lib_Entity);
7131 end if;
7132
7133 end if;
7134 end All_Calls_Remote;
7135
7136 --------------
7137 -- Annotate --
7138 --------------
7139
7140 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
7141 -- ARG ::= NAME | EXPRESSION
7142
7143 -- The first two arguments are by convention intended to refer to an
7144 -- external tool and a tool-specific function. These arguments are
7145 -- not analyzed.
7146
7147 when Pragma_Annotate => Annotate : declare
7148 Arg : Node_Id;
7149 Exp : Node_Id;
7150
7151 begin
7152 GNAT_Pragma;
7153 Check_At_Least_N_Arguments (1);
7154 Check_Arg_Is_Identifier (Arg1);
7155 Check_No_Identifiers;
7156 Store_Note (N);
7157
7158 -- Second parameter is optional, it is never analyzed
7159
7160 if No (Arg2) then
7161 null;
7162
7163 -- Here if we have a second parameter
7164
7165 else
7166 -- Second parameter must be identifier
7167
7168 Check_Arg_Is_Identifier (Arg2);
7169
7170 -- Process remaining parameters if any
7171
7172 Arg := Next (Arg2);
7173 while Present (Arg) loop
7174 Exp := Get_Pragma_Arg (Arg);
7175 Analyze (Exp);
7176
7177 if Is_Entity_Name (Exp) then
7178 null;
7179
7180 -- For string literals, we assume Standard_String as the
7181 -- type, unless the string contains wide or wide_wide
7182 -- characters.
7183
7184 elsif Nkind (Exp) = N_String_Literal then
7185 if Has_Wide_Wide_Character (Exp) then
7186 Resolve (Exp, Standard_Wide_Wide_String);
7187 elsif Has_Wide_Character (Exp) then
7188 Resolve (Exp, Standard_Wide_String);
7189 else
7190 Resolve (Exp, Standard_String);
7191 end if;
7192
7193 elsif Is_Overloaded (Exp) then
7194 Error_Pragma_Arg
7195 ("ambiguous argument for pragma%", Exp);
7196
7197 else
7198 Resolve (Exp);
7199 end if;
7200
7201 Next (Arg);
7202 end loop;
7203 end if;
7204 end Annotate;
7205
7206 ---------------------------
7207 -- Assert/Assert_And_Cut --
7208 ---------------------------
7209
7210 -- pragma Assert
7211 -- ( [Check => ] Boolean_EXPRESSION
7212 -- [, [Message =>] Static_String_EXPRESSION]);
7213
7214 -- pragma Assert_And_Cut
7215 -- ( [Check => ] Boolean_EXPRESSION
7216 -- [, [Message =>] Static_String_EXPRESSION]);
7217
7218 when Pragma_Assert | Pragma_Assert_And_Cut => Assert : declare
7219 Expr : Node_Id;
7220 Newa : List_Id;
7221
7222 begin
7223 if Prag_Id = Pragma_Assert then
7224 Ada_2005_Pragma;
7225 else -- Pragma_Assert_And_Cut
7226 GNAT_Pragma;
7227 S14_Pragma;
7228 end if;
7229
7230 Check_At_Least_N_Arguments (1);
7231 Check_At_Most_N_Arguments (2);
7232 Check_Arg_Order ((Name_Check, Name_Message));
7233 Check_Optional_Identifier (Arg1, Name_Check);
7234
7235 -- We treat pragma Assert as equivalent to:
7236
7237 -- pragma Check (Assertion, condition [, msg]);
7238
7239 -- So rewrite pragma in this manner, transfer the message
7240 -- argument if present, and analyze the result
7241
7242 -- Pragma Assert_And_Cut is treated exactly like pragma Assert by
7243 -- the frontend. Formal verification tools may use it to "cut" the
7244 -- paths through the code, to make verification tractable. When
7245 -- dealing with a semantically analyzed tree, the information that
7246 -- a Check node N corresponds to a source Assert_And_Cut pragma
7247 -- can be retrieved from the pragma kind of Original_Node(N).
7248
7249 Expr := Get_Pragma_Arg (Arg1);
7250 Newa := New_List (
7251 Make_Pragma_Argument_Association (Loc,
7252 Expression => Make_Identifier (Loc, Name_Assertion)),
7253
7254 Make_Pragma_Argument_Association (Sloc (Expr),
7255 Expression => Expr));
7256
7257 if Arg_Count > 1 then
7258 Check_Optional_Identifier (Arg2, Name_Message);
7259 Append_To (Newa, New_Copy_Tree (Arg2));
7260 end if;
7261
7262 Rewrite (N,
7263 Make_Pragma (Loc,
7264 Chars => Name_Check,
7265 Pragma_Argument_Associations => Newa));
7266 Analyze (N);
7267 end Assert;
7268
7269 ----------------------
7270 -- Assertion_Policy --
7271 ----------------------
7272
7273 -- pragma Assertion_Policy (Check | Disable | Ignore)
7274
7275 when Pragma_Assertion_Policy => Assertion_Policy : declare
7276 Policy : Node_Id;
7277
7278 begin
7279 Ada_2005_Pragma;
7280 Check_Valid_Configuration_Pragma;
7281 Check_Arg_Count (1);
7282 Check_No_Identifiers;
7283 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7284
7285 -- We treat pragma Assertion_Policy as equivalent to:
7286
7287 -- pragma Check_Policy (Assertion, policy)
7288
7289 -- So rewrite the pragma in that manner and link on to the chain
7290 -- of Check_Policy pragmas, marking the pragma as analyzed.
7291
7292 Policy := Get_Pragma_Arg (Arg1);
7293
7294 Rewrite (N,
7295 Make_Pragma (Loc,
7296 Chars => Name_Check_Policy,
7297 Pragma_Argument_Associations => New_List (
7298 Make_Pragma_Argument_Association (Loc,
7299 Expression => Make_Identifier (Loc, Name_Assertion)),
7300
7301 Make_Pragma_Argument_Association (Loc,
7302 Expression =>
7303 Make_Identifier (Sloc (Policy), Chars (Policy))))));
7304
7305 Set_Analyzed (N);
7306 Set_Next_Pragma (N, Opt.Check_Policy_List);
7307 Opt.Check_Policy_List := N;
7308 end Assertion_Policy;
7309
7310 ------------
7311 -- Assume --
7312 ------------
7313
7314 -- pragma Assume (boolean_EXPRESSION);
7315
7316 when Pragma_Assume => Assume : declare
7317 begin
7318 GNAT_Pragma;
7319 S14_Pragma;
7320 Check_Arg_Count (1);
7321
7322 -- Pragma Assume is transformed into pragma Check in the following
7323 -- manner:
7324
7325 -- pragma Check (Assume, Expr);
7326
7327 Rewrite (N,
7328 Make_Pragma (Loc,
7329 Chars => Name_Check,
7330 Pragma_Argument_Associations => New_List (
7331 Make_Pragma_Argument_Association (Loc,
7332 Expression => Make_Identifier (Loc, Name_Assume)),
7333
7334 Make_Pragma_Argument_Association (Loc,
7335 Expression => Relocate_Node (Expression (Arg1))))));
7336 Analyze (N);
7337 end Assume;
7338
7339 ------------------------------
7340 -- Assume_No_Invalid_Values --
7341 ------------------------------
7342
7343 -- pragma Assume_No_Invalid_Values (On | Off);
7344
7345 when Pragma_Assume_No_Invalid_Values =>
7346 GNAT_Pragma;
7347 Check_Valid_Configuration_Pragma;
7348 Check_Arg_Count (1);
7349 Check_No_Identifiers;
7350 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7351
7352 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
7353 Assume_No_Invalid_Values := True;
7354 else
7355 Assume_No_Invalid_Values := False;
7356 end if;
7357
7358 --------------------------
7359 -- Attribute_Definition --
7360 --------------------------
7361
7362 -- pragma Attribute_Definition
7363 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
7364 -- [Entity =>] LOCAL_NAME,
7365 -- [Expression =>] EXPRESSION | NAME);
7366
7367 when Pragma_Attribute_Definition => Attribute_Definition : declare
7368 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
7369 Aname : Name_Id;
7370
7371 begin
7372 GNAT_Pragma;
7373 Check_Arg_Count (3);
7374 Check_Optional_Identifier (Arg1, "attribute");
7375 Check_Optional_Identifier (Arg2, "entity");
7376 Check_Optional_Identifier (Arg3, "expression");
7377
7378 if Nkind (Attribute_Designator) /= N_Identifier then
7379 Error_Msg_N ("attribute name expected", Attribute_Designator);
7380 return;
7381 end if;
7382
7383 Check_Arg_Is_Local_Name (Arg2);
7384
7385 -- If the attribute is not recognized, then issue a warning (not
7386 -- an error), and ignore the pragma.
7387
7388 Aname := Chars (Attribute_Designator);
7389
7390 if not Is_Attribute_Name (Aname) then
7391 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
7392 return;
7393 end if;
7394
7395 -- Otherwise, rewrite the pragma as an attribute definition clause
7396
7397 Rewrite (N,
7398 Make_Attribute_Definition_Clause (Loc,
7399 Name => Get_Pragma_Arg (Arg2),
7400 Chars => Aname,
7401 Expression => Get_Pragma_Arg (Arg3)));
7402 Analyze (N);
7403 end Attribute_Definition;
7404
7405 ---------------
7406 -- AST_Entry --
7407 ---------------
7408
7409 -- pragma AST_Entry (entry_IDENTIFIER);
7410
7411 when Pragma_AST_Entry => AST_Entry : declare
7412 Ent : Node_Id;
7413
7414 begin
7415 GNAT_Pragma;
7416 Check_VMS (N);
7417 Check_Arg_Count (1);
7418 Check_No_Identifiers;
7419 Check_Arg_Is_Local_Name (Arg1);
7420 Ent := Entity (Get_Pragma_Arg (Arg1));
7421
7422 -- Note: the implementation of the AST_Entry pragma could handle
7423 -- the entry family case fine, but for now we are consistent with
7424 -- the DEC rules, and do not allow the pragma, which of course
7425 -- has the effect of also forbidding the attribute.
7426
7427 if Ekind (Ent) /= E_Entry then
7428 Error_Pragma_Arg
7429 ("pragma% argument must be simple entry name", Arg1);
7430
7431 elsif Is_AST_Entry (Ent) then
7432 Error_Pragma_Arg
7433 ("duplicate % pragma for entry", Arg1);
7434
7435 elsif Has_Homonym (Ent) then
7436 Error_Pragma_Arg
7437 ("pragma% argument cannot specify overloaded entry", Arg1);
7438
7439 else
7440 declare
7441 FF : constant Entity_Id := First_Formal (Ent);
7442
7443 begin
7444 if Present (FF) then
7445 if Present (Next_Formal (FF)) then
7446 Error_Pragma_Arg
7447 ("entry for pragma% can have only one argument",
7448 Arg1);
7449
7450 elsif Parameter_Mode (FF) /= E_In_Parameter then
7451 Error_Pragma_Arg
7452 ("entry parameter for pragma% must have mode IN",
7453 Arg1);
7454 end if;
7455 end if;
7456 end;
7457
7458 Set_Is_AST_Entry (Ent);
7459 end if;
7460 end AST_Entry;
7461
7462 ------------------
7463 -- Asynchronous --
7464 ------------------
7465
7466 -- pragma Asynchronous (LOCAL_NAME);
7467
7468 when Pragma_Asynchronous => Asynchronous : declare
7469 Nm : Entity_Id;
7470 C_Ent : Entity_Id;
7471 L : List_Id;
7472 S : Node_Id;
7473 N : Node_Id;
7474 Formal : Entity_Id;
7475
7476 procedure Process_Async_Pragma;
7477 -- Common processing for procedure and access-to-procedure case
7478
7479 --------------------------
7480 -- Process_Async_Pragma --
7481 --------------------------
7482
7483 procedure Process_Async_Pragma is
7484 begin
7485 if No (L) then
7486 Set_Is_Asynchronous (Nm);
7487 return;
7488 end if;
7489
7490 -- The formals should be of mode IN (RM E.4.1(6))
7491
7492 S := First (L);
7493 while Present (S) loop
7494 Formal := Defining_Identifier (S);
7495
7496 if Nkind (Formal) = N_Defining_Identifier
7497 and then Ekind (Formal) /= E_In_Parameter
7498 then
7499 Error_Pragma_Arg
7500 ("pragma% procedure can only have IN parameter",
7501 Arg1);
7502 end if;
7503
7504 Next (S);
7505 end loop;
7506
7507 Set_Is_Asynchronous (Nm);
7508 end Process_Async_Pragma;
7509
7510 -- Start of processing for pragma Asynchronous
7511
7512 begin
7513 Check_Ada_83_Warning;
7514 Check_No_Identifiers;
7515 Check_Arg_Count (1);
7516 Check_Arg_Is_Local_Name (Arg1);
7517
7518 if Debug_Flag_U then
7519 return;
7520 end if;
7521
7522 C_Ent := Cunit_Entity (Current_Sem_Unit);
7523 Analyze (Get_Pragma_Arg (Arg1));
7524 Nm := Entity (Get_Pragma_Arg (Arg1));
7525
7526 if not Is_Remote_Call_Interface (C_Ent)
7527 and then not Is_Remote_Types (C_Ent)
7528 then
7529 -- This pragma should only appear in an RCI or Remote Types
7530 -- unit (RM E.4.1(4)).
7531
7532 Error_Pragma
7533 ("pragma% not in Remote_Call_Interface or " &
7534 "Remote_Types unit");
7535 end if;
7536
7537 if Ekind (Nm) = E_Procedure
7538 and then Nkind (Parent (Nm)) = N_Procedure_Specification
7539 then
7540 if not Is_Remote_Call_Interface (Nm) then
7541 Error_Pragma_Arg
7542 ("pragma% cannot be applied on non-remote procedure",
7543 Arg1);
7544 end if;
7545
7546 L := Parameter_Specifications (Parent (Nm));
7547 Process_Async_Pragma;
7548 return;
7549
7550 elsif Ekind (Nm) = E_Function then
7551 Error_Pragma_Arg
7552 ("pragma% cannot be applied to function", Arg1);
7553
7554 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
7555 if Is_Record_Type (Nm) then
7556
7557 -- A record type that is the Equivalent_Type for a remote
7558 -- access-to-subprogram type.
7559
7560 N := Declaration_Node (Corresponding_Remote_Type (Nm));
7561
7562 else
7563 -- A non-expanded RAS type (distribution is not enabled)
7564
7565 N := Declaration_Node (Nm);
7566 end if;
7567
7568 if Nkind (N) = N_Full_Type_Declaration
7569 and then Nkind (Type_Definition (N)) =
7570 N_Access_Procedure_Definition
7571 then
7572 L := Parameter_Specifications (Type_Definition (N));
7573 Process_Async_Pragma;
7574
7575 if Is_Asynchronous (Nm)
7576 and then Expander_Active
7577 and then Get_PCS_Name /= Name_No_DSA
7578 then
7579 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
7580 end if;
7581
7582 else
7583 Error_Pragma_Arg
7584 ("pragma% cannot reference access-to-function type",
7585 Arg1);
7586 end if;
7587
7588 -- Only other possibility is Access-to-class-wide type
7589
7590 elsif Is_Access_Type (Nm)
7591 and then Is_Class_Wide_Type (Designated_Type (Nm))
7592 then
7593 Check_First_Subtype (Arg1);
7594 Set_Is_Asynchronous (Nm);
7595 if Expander_Active then
7596 RACW_Type_Is_Asynchronous (Nm);
7597 end if;
7598
7599 else
7600 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
7601 end if;
7602 end Asynchronous;
7603
7604 ------------
7605 -- Atomic --
7606 ------------
7607
7608 -- pragma Atomic (LOCAL_NAME);
7609
7610 when Pragma_Atomic =>
7611 Process_Atomic_Shared_Volatile;
7612
7613 -----------------------
7614 -- Atomic_Components --
7615 -----------------------
7616
7617 -- pragma Atomic_Components (array_LOCAL_NAME);
7618
7619 -- This processing is shared by Volatile_Components
7620
7621 when Pragma_Atomic_Components |
7622 Pragma_Volatile_Components =>
7623
7624 Atomic_Components : declare
7625 E_Id : Node_Id;
7626 E : Entity_Id;
7627 D : Node_Id;
7628 K : Node_Kind;
7629
7630 begin
7631 Check_Ada_83_Warning;
7632 Check_No_Identifiers;
7633 Check_Arg_Count (1);
7634 Check_Arg_Is_Local_Name (Arg1);
7635 E_Id := Get_Pragma_Arg (Arg1);
7636
7637 if Etype (E_Id) = Any_Type then
7638 return;
7639 end if;
7640
7641 E := Entity (E_Id);
7642
7643 Check_Duplicate_Pragma (E);
7644
7645 if Rep_Item_Too_Early (E, N)
7646 or else
7647 Rep_Item_Too_Late (E, N)
7648 then
7649 return;
7650 end if;
7651
7652 D := Declaration_Node (E);
7653 K := Nkind (D);
7654
7655 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
7656 or else
7657 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7658 and then Nkind (D) = N_Object_Declaration
7659 and then Nkind (Object_Definition (D)) =
7660 N_Constrained_Array_Definition)
7661 then
7662 -- The flag is set on the object, or on the base type
7663
7664 if Nkind (D) /= N_Object_Declaration then
7665 E := Base_Type (E);
7666 end if;
7667
7668 Set_Has_Volatile_Components (E);
7669
7670 if Prag_Id = Pragma_Atomic_Components then
7671 Set_Has_Atomic_Components (E);
7672 end if;
7673
7674 else
7675 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7676 end if;
7677 end Atomic_Components;
7678
7679 --------------------
7680 -- Attach_Handler --
7681 --------------------
7682
7683 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7684
7685 when Pragma_Attach_Handler =>
7686 Check_Ada_83_Warning;
7687 Check_No_Identifiers;
7688 Check_Arg_Count (2);
7689
7690 if No_Run_Time_Mode then
7691 Error_Msg_CRT ("Attach_Handler pragma", N);
7692 else
7693 Check_Interrupt_Or_Attach_Handler;
7694
7695 -- The expression that designates the attribute may depend on a
7696 -- discriminant, and is therefore a per-object expression, to
7697 -- be expanded in the init proc. If expansion is enabled, then
7698 -- perform semantic checks on a copy only.
7699
7700 if Expander_Active then
7701 declare
7702 Temp : constant Node_Id :=
7703 New_Copy_Tree (Get_Pragma_Arg (Arg2));
7704 begin
7705 Set_Parent (Temp, N);
7706 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7707 end;
7708
7709 else
7710 Analyze (Get_Pragma_Arg (Arg2));
7711 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7712 end if;
7713
7714 Process_Interrupt_Or_Attach_Handler;
7715 end if;
7716
7717 --------------------
7718 -- C_Pass_By_Copy --
7719 --------------------
7720
7721 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7722
7723 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7724 Arg : Node_Id;
7725 Val : Uint;
7726
7727 begin
7728 GNAT_Pragma;
7729 Check_Valid_Configuration_Pragma;
7730 Check_Arg_Count (1);
7731 Check_Optional_Identifier (Arg1, "max_size");
7732
7733 Arg := Get_Pragma_Arg (Arg1);
7734 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7735
7736 Val := Expr_Value (Arg);
7737
7738 if Val <= 0 then
7739 Error_Pragma_Arg
7740 ("maximum size for pragma% must be positive", Arg1);
7741
7742 elsif UI_Is_In_Int_Range (Val) then
7743 Default_C_Record_Mechanism := UI_To_Int (Val);
7744
7745 -- If a giant value is given, Int'Last will do well enough.
7746 -- If sometime someone complains that a record larger than
7747 -- two gigabytes is not copied, we will worry about it then!
7748
7749 else
7750 Default_C_Record_Mechanism := Mechanism_Type'Last;
7751 end if;
7752 end C_Pass_By_Copy;
7753
7754 -----------
7755 -- Check --
7756 -----------
7757
7758 -- pragma Check ([Name =>] IDENTIFIER,
7759 -- [Check =>] Boolean_EXPRESSION
7760 -- [,[Message =>] String_EXPRESSION]);
7761
7762 when Pragma_Check => Check : declare
7763 Expr : Node_Id;
7764 Eloc : Source_Ptr;
7765 Cname : Name_Id;
7766
7767 Check_On : Boolean;
7768 -- Set True if category of assertions referenced by Name enabled
7769
7770 begin
7771 GNAT_Pragma;
7772 Check_At_Least_N_Arguments (2);
7773 Check_At_Most_N_Arguments (3);
7774 Check_Optional_Identifier (Arg1, Name_Name);
7775 Check_Optional_Identifier (Arg2, Name_Check);
7776
7777 if Arg_Count = 3 then
7778 Check_Optional_Identifier (Arg3, Name_Message);
7779 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
7780 end if;
7781
7782 Check_Arg_Is_Identifier (Arg1);
7783
7784 -- Completely ignore if disabled
7785
7786 if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
7787 Rewrite (N, Make_Null_Statement (Loc));
7788 Analyze (N);
7789 return;
7790 end if;
7791
7792 Cname := Chars (Get_Pragma_Arg (Arg1));
7793 Check_On := Check_Enabled (Cname);
7794
7795 case Cname is
7796 when Name_Predicate |
7797 Name_Invariant =>
7798
7799 -- Nothing to do: since checks occur in client units,
7800 -- the SCO for the aspect in the declaration unit is
7801 -- conservatively always enabled.
7802
7803 null;
7804
7805 when others =>
7806
7807 if Check_On and then not Split_PPC (N) then
7808
7809 -- Mark pragma/aspect SCO as enabled
7810
7811 Set_SCO_Pragma_Enabled (Loc);
7812 end if;
7813 end case;
7814
7815 -- If expansion is active and the check is not enabled then we
7816 -- rewrite the Check as:
7817
7818 -- if False and then condition then
7819 -- null;
7820 -- end if;
7821
7822 -- The reason we do this rewriting during semantic analysis rather
7823 -- than as part of normal expansion is that we cannot analyze and
7824 -- expand the code for the boolean expression directly, or it may
7825 -- cause insertion of actions that would escape the attempt to
7826 -- suppress the check code.
7827
7828 -- Note that the Sloc for the if statement corresponds to the
7829 -- argument condition, not the pragma itself. The reason for this
7830 -- is that we may generate a warning if the condition is False at
7831 -- compile time, and we do not want to delete this warning when we
7832 -- delete the if statement.
7833
7834 Expr := Get_Pragma_Arg (Arg2);
7835
7836 if Expander_Active and then not Check_On then
7837 Eloc := Sloc (Expr);
7838
7839 Rewrite (N,
7840 Make_If_Statement (Eloc,
7841 Condition =>
7842 Make_And_Then (Eloc,
7843 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7844 Right_Opnd => Expr),
7845 Then_Statements => New_List (
7846 Make_Null_Statement (Eloc))));
7847
7848 Analyze (N);
7849
7850 -- Check is active
7851
7852 else
7853 In_Assertion_Expr := In_Assertion_Expr + 1;
7854 Analyze_And_Resolve (Expr, Any_Boolean);
7855 In_Assertion_Expr := In_Assertion_Expr - 1;
7856 end if;
7857 end Check;
7858
7859 --------------------------
7860 -- Check_Float_Overflow --
7861 --------------------------
7862
7863 -- pragma Check_Float_Overflow;
7864
7865 when Pragma_Check_Float_Overflow =>
7866 GNAT_Pragma;
7867 Check_Valid_Configuration_Pragma;
7868 Check_Arg_Count (0);
7869 Check_Float_Overflow := True;
7870
7871 ----------------
7872 -- Check_Name --
7873 ----------------
7874
7875 -- pragma Check_Name (check_IDENTIFIER);
7876
7877 when Pragma_Check_Name =>
7878 Check_No_Identifiers;
7879 GNAT_Pragma;
7880 Check_Valid_Configuration_Pragma;
7881 Check_Arg_Count (1);
7882 Check_Arg_Is_Identifier (Arg1);
7883
7884 declare
7885 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7886
7887 begin
7888 for J in Check_Names.First .. Check_Names.Last loop
7889 if Check_Names.Table (J) = Nam then
7890 return;
7891 end if;
7892 end loop;
7893
7894 Check_Names.Append (Nam);
7895 end;
7896
7897 ------------------
7898 -- Check_Policy --
7899 ------------------
7900
7901 -- pragma Check_Policy (
7902 -- [Name =>] IDENTIFIER,
7903 -- [Policy =>] POLICY_IDENTIFIER);
7904
7905 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7906
7907 -- Note: this is a configuration pragma, but it is allowed to appear
7908 -- anywhere else.
7909
7910 when Pragma_Check_Policy =>
7911 GNAT_Pragma;
7912 Check_Arg_Count (2);
7913 Check_Optional_Identifier (Arg1, Name_Name);
7914 Check_Optional_Identifier (Arg2, Name_Policy);
7915 Check_Arg_Is_One_Of
7916 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7917
7918 -- A Check_Policy pragma can appear either as a configuration
7919 -- pragma, or in a declarative part or a package spec (see RM
7920 -- 11.5(5) for rules for Suppress/Unsuppress which are also
7921 -- followed for Check_Policy).
7922
7923 if not Is_Configuration_Pragma then
7924 Check_Is_In_Decl_Part_Or_Package_Spec;
7925 end if;
7926
7927 Set_Next_Pragma (N, Opt.Check_Policy_List);
7928 Opt.Check_Policy_List := N;
7929
7930 ---------------------
7931 -- CIL_Constructor --
7932 ---------------------
7933
7934 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7935
7936 -- Processing for this pragma is shared with Java_Constructor
7937
7938 -------------
7939 -- Comment --
7940 -------------
7941
7942 -- pragma Comment (static_string_EXPRESSION)
7943
7944 -- Processing for pragma Comment shares the circuitry for pragma
7945 -- Ident. The only differences are that Ident enforces a limit of 31
7946 -- characters on its argument, and also enforces limitations on
7947 -- placement for DEC compatibility. Pragma Comment shares neither of
7948 -- these restrictions.
7949
7950 -------------------
7951 -- Common_Object --
7952 -------------------
7953
7954 -- pragma Common_Object (
7955 -- [Internal =>] LOCAL_NAME
7956 -- [, [External =>] EXTERNAL_SYMBOL]
7957 -- [, [Size =>] EXTERNAL_SYMBOL]);
7958
7959 -- Processing for this pragma is shared with Psect_Object
7960
7961 ------------------------
7962 -- Compile_Time_Error --
7963 ------------------------
7964
7965 -- pragma Compile_Time_Error
7966 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7967
7968 when Pragma_Compile_Time_Error =>
7969 GNAT_Pragma;
7970 Process_Compile_Time_Warning_Or_Error;
7971
7972 --------------------------
7973 -- Compile_Time_Warning --
7974 --------------------------
7975
7976 -- pragma Compile_Time_Warning
7977 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7978
7979 when Pragma_Compile_Time_Warning =>
7980 GNAT_Pragma;
7981 Process_Compile_Time_Warning_Or_Error;
7982
7983 -------------------
7984 -- Compiler_Unit --
7985 -------------------
7986
7987 when Pragma_Compiler_Unit =>
7988 GNAT_Pragma;
7989 Check_Arg_Count (0);
7990 Set_Is_Compiler_Unit (Get_Source_Unit (N));
7991
7992 -----------------------------
7993 -- Complete_Representation --
7994 -----------------------------
7995
7996 -- pragma Complete_Representation;
7997
7998 when Pragma_Complete_Representation =>
7999 GNAT_Pragma;
8000 Check_Arg_Count (0);
8001
8002 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
8003 Error_Pragma
8004 ("pragma & must appear within record representation clause");
8005 end if;
8006
8007 ----------------------------
8008 -- Complex_Representation --
8009 ----------------------------
8010
8011 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
8012
8013 when Pragma_Complex_Representation => Complex_Representation : declare
8014 E_Id : Entity_Id;
8015 E : Entity_Id;
8016 Ent : Entity_Id;
8017
8018 begin
8019 GNAT_Pragma;
8020 Check_Arg_Count (1);
8021 Check_Optional_Identifier (Arg1, Name_Entity);
8022 Check_Arg_Is_Local_Name (Arg1);
8023 E_Id := Get_Pragma_Arg (Arg1);
8024
8025 if Etype (E_Id) = Any_Type then
8026 return;
8027 end if;
8028
8029 E := Entity (E_Id);
8030
8031 if not Is_Record_Type (E) then
8032 Error_Pragma_Arg
8033 ("argument for pragma% must be record type", Arg1);
8034 end if;
8035
8036 Ent := First_Entity (E);
8037
8038 if No (Ent)
8039 or else No (Next_Entity (Ent))
8040 or else Present (Next_Entity (Next_Entity (Ent)))
8041 or else not Is_Floating_Point_Type (Etype (Ent))
8042 or else Etype (Ent) /= Etype (Next_Entity (Ent))
8043 then
8044 Error_Pragma_Arg
8045 ("record for pragma% must have two fields of the same "
8046 & "floating-point type", Arg1);
8047
8048 else
8049 Set_Has_Complex_Representation (Base_Type (E));
8050
8051 -- We need to treat the type has having a non-standard
8052 -- representation, for back-end purposes, even though in
8053 -- general a complex will have the default representation
8054 -- of a record with two real components.
8055
8056 Set_Has_Non_Standard_Rep (Base_Type (E));
8057 end if;
8058 end Complex_Representation;
8059
8060 -------------------------
8061 -- Component_Alignment --
8062 -------------------------
8063
8064 -- pragma Component_Alignment (
8065 -- [Form =>] ALIGNMENT_CHOICE
8066 -- [, [Name =>] type_LOCAL_NAME]);
8067 --
8068 -- ALIGNMENT_CHOICE ::=
8069 -- Component_Size
8070 -- | Component_Size_4
8071 -- | Storage_Unit
8072 -- | Default
8073
8074 when Pragma_Component_Alignment => Component_AlignmentP : declare
8075 Args : Args_List (1 .. 2);
8076 Names : constant Name_List (1 .. 2) := (
8077 Name_Form,
8078 Name_Name);
8079
8080 Form : Node_Id renames Args (1);
8081 Name : Node_Id renames Args (2);
8082
8083 Atype : Component_Alignment_Kind;
8084 Typ : Entity_Id;
8085
8086 begin
8087 GNAT_Pragma;
8088 Gather_Associations (Names, Args);
8089
8090 if No (Form) then
8091 Error_Pragma ("missing Form argument for pragma%");
8092 end if;
8093
8094 Check_Arg_Is_Identifier (Form);
8095
8096 -- Get proper alignment, note that Default = Component_Size on all
8097 -- machines we have so far, and we want to set this value rather
8098 -- than the default value to indicate that it has been explicitly
8099 -- set (and thus will not get overridden by the default component
8100 -- alignment for the current scope)
8101
8102 if Chars (Form) = Name_Component_Size then
8103 Atype := Calign_Component_Size;
8104
8105 elsif Chars (Form) = Name_Component_Size_4 then
8106 Atype := Calign_Component_Size_4;
8107
8108 elsif Chars (Form) = Name_Default then
8109 Atype := Calign_Component_Size;
8110
8111 elsif Chars (Form) = Name_Storage_Unit then
8112 Atype := Calign_Storage_Unit;
8113
8114 else
8115 Error_Pragma_Arg
8116 ("invalid Form parameter for pragma%", Form);
8117 end if;
8118
8119 -- Case with no name, supplied, affects scope table entry
8120
8121 if No (Name) then
8122 Scope_Stack.Table
8123 (Scope_Stack.Last).Component_Alignment_Default := Atype;
8124
8125 -- Case of name supplied
8126
8127 else
8128 Check_Arg_Is_Local_Name (Name);
8129 Find_Type (Name);
8130 Typ := Entity (Name);
8131
8132 if Typ = Any_Type
8133 or else Rep_Item_Too_Early (Typ, N)
8134 then
8135 return;
8136 else
8137 Typ := Underlying_Type (Typ);
8138 end if;
8139
8140 if not Is_Record_Type (Typ)
8141 and then not Is_Array_Type (Typ)
8142 then
8143 Error_Pragma_Arg
8144 ("Name parameter of pragma% must identify record or " &
8145 "array type", Name);
8146 end if;
8147
8148 -- An explicit Component_Alignment pragma overrides an
8149 -- implicit pragma Pack, but not an explicit one.
8150
8151 if not Has_Pragma_Pack (Base_Type (Typ)) then
8152 Set_Is_Packed (Base_Type (Typ), False);
8153 Set_Component_Alignment (Base_Type (Typ), Atype);
8154 end if;
8155 end if;
8156 end Component_AlignmentP;
8157
8158 -------------------
8159 -- Contract_Case --
8160 -------------------
8161
8162 -- pragma Contract_Case
8163 -- ([Name =>] Static_String_EXPRESSION
8164 -- ,[Mode =>] MODE_TYPE
8165 -- [, Requires => Boolean_EXPRESSION]
8166 -- [, Ensures => Boolean_EXPRESSION]);
8167
8168 -- MODE_TYPE ::= Nominal | Robustness
8169
8170 when Pragma_Contract_Case =>
8171 Check_Contract_Or_Test_Case;
8172
8173 --------------------
8174 -- Contract_Cases --
8175 --------------------
8176
8177 -- pragma Contract_Cases (CONTRACT_CASE_LIST);
8178
8179 -- CONTRACT_CASE_LIST ::= CONTRACT_CASE {, CONTRACT_CASE}
8180
8181 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
8182
8183 -- CASE_GUARD ::= boolean_EXPRESSION | others
8184
8185 -- CONSEQUENCE ::= boolean_EXPRESSION
8186
8187 when Pragma_Contract_Cases => Contract_Cases : declare
8188 procedure Chain_Contract_Cases (Subp_Decl : Node_Id);
8189 -- Chain pragma Contract_Cases to the contract of a subprogram.
8190 -- Subp_Decl is the declaration of the subprogram.
8191
8192 --------------------------
8193 -- Chain_Contract_Cases --
8194 --------------------------
8195
8196 procedure Chain_Contract_Cases (Subp_Decl : Node_Id) is
8197 Subp : constant Entity_Id :=
8198 Defining_Unit_Name (Specification (Subp_Decl));
8199 CTC : Node_Id;
8200
8201 begin
8202 Check_Duplicate_Pragma (Subp);
8203 CTC := Spec_CTC_List (Contract (Subp));
8204 while Present (CTC) loop
8205 if Chars (Pragma_Identifier (CTC)) = Pname then
8206 Error_Msg_Name_1 := Pname;
8207 Error_Msg_Sloc := Sloc (CTC);
8208
8209 if From_Aspect_Specification (CTC) then
8210 Error_Msg_NE
8211 ("aspect% for & previously given#", N, Subp);
8212 else
8213 Error_Msg_NE
8214 ("pragma% for & duplicates pragma#", N, Subp);
8215 end if;
8216
8217 raise Pragma_Exit;
8218 end if;
8219
8220 CTC := Next_Pragma (CTC);
8221 end loop;
8222
8223 -- Prepend pragma Contract_Cases to the contract
8224
8225 Set_Next_Pragma (N, Spec_CTC_List (Contract (Subp)));
8226 Set_Spec_CTC_List (Contract (Subp), N);
8227 end Chain_Contract_Cases;
8228
8229 -- Local variables
8230
8231 Case_Guard : Node_Id;
8232 Decl : Node_Id;
8233 Extra : Node_Id;
8234 Others_Seen : Boolean := False;
8235 Contract_Case : Node_Id;
8236 Subp_Decl : Node_Id;
8237
8238 -- Start of processing for Contract_Cases
8239
8240 begin
8241 GNAT_Pragma;
8242 S14_Pragma;
8243 Check_Arg_Count (1);
8244
8245 -- Completely ignore if disabled
8246
8247 if Check_Disabled (Pname) then
8248 Rewrite (N, Make_Null_Statement (Loc));
8249 Analyze (N);
8250 return;
8251 end if;
8252
8253 -- Check the placement of the pragma
8254
8255 if not Is_List_Member (N) then
8256 Pragma_Misplaced;
8257 end if;
8258
8259 -- Pragma Contract_Cases must be associated with a subprogram
8260
8261 Decl := N;
8262 while Present (Prev (Decl)) loop
8263 Decl := Prev (Decl);
8264
8265 if Nkind (Decl) in N_Generic_Declaration then
8266 Subp_Decl := Decl;
8267 else
8268 Subp_Decl := Original_Node (Decl);
8269 end if;
8270
8271 -- Skip prior pragmas
8272
8273 if Nkind (Subp_Decl) = N_Pragma then
8274 null;
8275
8276 -- Skip internally generated code
8277
8278 elsif not Comes_From_Source (Subp_Decl) then
8279 null;
8280
8281 -- We have found the related subprogram
8282
8283 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
8284 N_Subprogram_Declaration)
8285 then
8286 exit;
8287
8288 else
8289 Pragma_Misplaced;
8290 end if;
8291 end loop;
8292
8293 -- All contract cases must appear as an aggregate
8294
8295 if Nkind (Expression (Arg1)) /= N_Aggregate then
8296 Error_Pragma ("wrong syntax for pragma %");
8297 return;
8298 end if;
8299
8300 -- Verify the legality of individual contract cases
8301
8302 Contract_Case :=
8303 First (Component_Associations (Expression (Arg1)));
8304 while Present (Contract_Case) loop
8305 if Nkind (Contract_Case) /= N_Component_Association then
8306 Error_Pragma_Arg
8307 ("wrong syntax in contract case", Contract_Case);
8308 return;
8309 end if;
8310
8311 Case_Guard := First (Choices (Contract_Case));
8312
8313 -- Each contract case must have exactly on case guard
8314
8315 Extra := Next (Case_Guard);
8316 if Present (Extra) then
8317 Error_Pragma_Arg
8318 ("contract case may have only one case guard", Extra);
8319 return;
8320 end if;
8321
8322 -- Check the placement of "others" (if available)
8323
8324 if Nkind (Case_Guard) = N_Others_Choice then
8325 if Others_Seen then
8326 Error_Pragma_Arg
8327 ("only one others choice allowed in pragma %",
8328 Case_Guard);
8329 return;
8330 else
8331 Others_Seen := True;
8332 end if;
8333
8334 elsif Others_Seen then
8335 Error_Pragma_Arg
8336 ("others must be the last choice in pragma %", N);
8337 return;
8338 end if;
8339
8340 Next (Contract_Case);
8341 end loop;
8342
8343 Chain_Contract_Cases (Subp_Decl);
8344 end Contract_Cases;
8345
8346 ----------------
8347 -- Controlled --
8348 ----------------
8349
8350 -- pragma Controlled (first_subtype_LOCAL_NAME);
8351
8352 when Pragma_Controlled => Controlled : declare
8353 Arg : Node_Id;
8354
8355 begin
8356 Check_No_Identifiers;
8357 Check_Arg_Count (1);
8358 Check_Arg_Is_Local_Name (Arg1);
8359 Arg := Get_Pragma_Arg (Arg1);
8360
8361 if not Is_Entity_Name (Arg)
8362 or else not Is_Access_Type (Entity (Arg))
8363 then
8364 Error_Pragma_Arg ("pragma% requires access type", Arg1);
8365 else
8366 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
8367 end if;
8368 end Controlled;
8369
8370 ----------------
8371 -- Convention --
8372 ----------------
8373
8374 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
8375 -- [Entity =>] LOCAL_NAME);
8376
8377 when Pragma_Convention => Convention : declare
8378 C : Convention_Id;
8379 E : Entity_Id;
8380 pragma Warnings (Off, C);
8381 pragma Warnings (Off, E);
8382 begin
8383 Check_Arg_Order ((Name_Convention, Name_Entity));
8384 Check_Ada_83_Warning;
8385 Check_Arg_Count (2);
8386 Process_Convention (C, E);
8387 end Convention;
8388
8389 ---------------------------
8390 -- Convention_Identifier --
8391 ---------------------------
8392
8393 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
8394 -- [Convention =>] convention_IDENTIFIER);
8395
8396 when Pragma_Convention_Identifier => Convention_Identifier : declare
8397 Idnam : Name_Id;
8398 Cname : Name_Id;
8399
8400 begin
8401 GNAT_Pragma;
8402 Check_Arg_Order ((Name_Name, Name_Convention));
8403 Check_Arg_Count (2);
8404 Check_Optional_Identifier (Arg1, Name_Name);
8405 Check_Optional_Identifier (Arg2, Name_Convention);
8406 Check_Arg_Is_Identifier (Arg1);
8407 Check_Arg_Is_Identifier (Arg2);
8408 Idnam := Chars (Get_Pragma_Arg (Arg1));
8409 Cname := Chars (Get_Pragma_Arg (Arg2));
8410
8411 if Is_Convention_Name (Cname) then
8412 Record_Convention_Identifier
8413 (Idnam, Get_Convention_Id (Cname));
8414 else
8415 Error_Pragma_Arg
8416 ("second arg for % pragma must be convention", Arg2);
8417 end if;
8418 end Convention_Identifier;
8419
8420 ---------------
8421 -- CPP_Class --
8422 ---------------
8423
8424 -- pragma CPP_Class ([Entity =>] local_NAME)
8425
8426 when Pragma_CPP_Class => CPP_Class : declare
8427 begin
8428 GNAT_Pragma;
8429
8430 if Warn_On_Obsolescent_Feature then
8431 -- Following message is obsolete ???
8432 Error_Msg_N
8433 ("'G'N'A'T pragma cpp'_class is now obsolete and has no " &
8434 "effect; replace it by pragma import?j?", N);
8435 end if;
8436
8437 Check_Arg_Count (1);
8438
8439 Rewrite (N,
8440 Make_Pragma (Loc,
8441 Chars => Name_Import,
8442 Pragma_Argument_Associations => New_List (
8443 Make_Pragma_Argument_Association (Loc,
8444 Expression => Make_Identifier (Loc, Name_CPP)),
8445 New_Copy (First (Pragma_Argument_Associations (N))))));
8446 Analyze (N);
8447 end CPP_Class;
8448
8449 ---------------------
8450 -- CPP_Constructor --
8451 ---------------------
8452
8453 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
8454 -- [, [External_Name =>] static_string_EXPRESSION ]
8455 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8456
8457 when Pragma_CPP_Constructor => CPP_Constructor : declare
8458 Elmt : Elmt_Id;
8459 Id : Entity_Id;
8460 Def_Id : Entity_Id;
8461 Tag_Typ : Entity_Id;
8462
8463 begin
8464 GNAT_Pragma;
8465 Check_At_Least_N_Arguments (1);
8466 Check_At_Most_N_Arguments (3);
8467 Check_Optional_Identifier (Arg1, Name_Entity);
8468 Check_Arg_Is_Local_Name (Arg1);
8469
8470 Id := Get_Pragma_Arg (Arg1);
8471 Find_Program_Unit_Name (Id);
8472
8473 -- If we did not find the name, we are done
8474
8475 if Etype (Id) = Any_Type then
8476 return;
8477 end if;
8478
8479 Def_Id := Entity (Id);
8480
8481 -- Check if already defined as constructor
8482
8483 if Is_Constructor (Def_Id) then
8484 Error_Msg_N
8485 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
8486 return;
8487 end if;
8488
8489 if Ekind (Def_Id) = E_Function
8490 and then (Is_CPP_Class (Etype (Def_Id))
8491 or else (Is_Class_Wide_Type (Etype (Def_Id))
8492 and then
8493 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
8494 then
8495 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
8496 Error_Msg_N
8497 ("'C'P'P constructor must be defined in the scope of " &
8498 "its returned type", Arg1);
8499 end if;
8500
8501 if Arg_Count >= 2 then
8502 Set_Imported (Def_Id);
8503 Set_Is_Public (Def_Id);
8504 Process_Interface_Name (Def_Id, Arg2, Arg3);
8505 end if;
8506
8507 Set_Has_Completion (Def_Id);
8508 Set_Is_Constructor (Def_Id);
8509 Set_Convention (Def_Id, Convention_CPP);
8510
8511 -- Imported C++ constructors are not dispatching primitives
8512 -- because in C++ they don't have a dispatch table slot.
8513 -- However, in Ada the constructor has the profile of a
8514 -- function that returns a tagged type and therefore it has
8515 -- been treated as a primitive operation during semantic
8516 -- analysis. We now remove it from the list of primitive
8517 -- operations of the type.
8518
8519 if Is_Tagged_Type (Etype (Def_Id))
8520 and then not Is_Class_Wide_Type (Etype (Def_Id))
8521 and then Is_Dispatching_Operation (Def_Id)
8522 then
8523 Tag_Typ := Etype (Def_Id);
8524
8525 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
8526 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
8527 Next_Elmt (Elmt);
8528 end loop;
8529
8530 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
8531 Set_Is_Dispatching_Operation (Def_Id, False);
8532 end if;
8533
8534 -- For backward compatibility, if the constructor returns a
8535 -- class wide type, and we internally change the return type to
8536 -- the corresponding root type.
8537
8538 if Is_Class_Wide_Type (Etype (Def_Id)) then
8539 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
8540 end if;
8541 else
8542 Error_Pragma_Arg
8543 ("pragma% requires function returning a 'C'P'P_Class type",
8544 Arg1);
8545 end if;
8546 end CPP_Constructor;
8547
8548 -----------------
8549 -- CPP_Virtual --
8550 -----------------
8551
8552 when Pragma_CPP_Virtual => CPP_Virtual : declare
8553 begin
8554 GNAT_Pragma;
8555
8556 if Warn_On_Obsolescent_Feature then
8557 Error_Msg_N
8558 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
8559 "no effect?j?", N);
8560 end if;
8561 end CPP_Virtual;
8562
8563 ----------------
8564 -- CPP_Vtable --
8565 ----------------
8566
8567 when Pragma_CPP_Vtable => CPP_Vtable : declare
8568 begin
8569 GNAT_Pragma;
8570
8571 if Warn_On_Obsolescent_Feature then
8572 Error_Msg_N
8573 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
8574 "no effect?j?", N);
8575 end if;
8576 end CPP_Vtable;
8577
8578 ---------
8579 -- CPU --
8580 ---------
8581
8582 -- pragma CPU (EXPRESSION);
8583
8584 when Pragma_CPU => CPU : declare
8585 P : constant Node_Id := Parent (N);
8586 Arg : Node_Id;
8587 Ent : Entity_Id;
8588
8589 begin
8590 Ada_2012_Pragma;
8591 Check_No_Identifiers;
8592 Check_Arg_Count (1);
8593
8594 -- Subprogram case
8595
8596 if Nkind (P) = N_Subprogram_Body then
8597 Check_In_Main_Program;
8598
8599 Arg := Get_Pragma_Arg (Arg1);
8600 Analyze_And_Resolve (Arg, Any_Integer);
8601
8602 Ent := Defining_Unit_Name (Specification (P));
8603
8604 if Nkind (Ent) = N_Defining_Program_Unit_Name then
8605 Ent := Defining_Identifier (Ent);
8606 end if;
8607
8608 -- Must be static
8609
8610 if not Is_Static_Expression (Arg) then
8611 Flag_Non_Static_Expr
8612 ("main subprogram affinity is not static!", Arg);
8613 raise Pragma_Exit;
8614
8615 -- If constraint error, then we already signalled an error
8616
8617 elsif Raises_Constraint_Error (Arg) then
8618 null;
8619
8620 -- Otherwise check in range
8621
8622 else
8623 declare
8624 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
8625 -- This is the entity System.Multiprocessors.CPU_Range;
8626
8627 Val : constant Uint := Expr_Value (Arg);
8628
8629 begin
8630 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
8631 or else
8632 Val > Expr_Value (Type_High_Bound (CPU_Id))
8633 then
8634 Error_Pragma_Arg
8635 ("main subprogram CPU is out of range", Arg1);
8636 end if;
8637 end;
8638 end if;
8639
8640 Set_Main_CPU
8641 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8642
8643 -- Task case
8644
8645 elsif Nkind (P) = N_Task_Definition then
8646 Arg := Get_Pragma_Arg (Arg1);
8647 Ent := Defining_Identifier (Parent (P));
8648
8649 -- The expression must be analyzed in the special manner
8650 -- described in "Handling of Default and Per-Object
8651 -- Expressions" in sem.ads.
8652
8653 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
8654
8655 -- Anything else is incorrect
8656
8657 else
8658 Pragma_Misplaced;
8659 end if;
8660
8661 -- Check duplicate pragma before we chain the pragma in the Rep
8662 -- Item chain of Ent.
8663
8664 Check_Duplicate_Pragma (Ent);
8665 Record_Rep_Item (Ent, N);
8666 end CPU;
8667
8668 -----------
8669 -- Debug --
8670 -----------
8671
8672 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
8673
8674 when Pragma_Debug => Debug : declare
8675 Cond : Node_Id;
8676 Call : Node_Id;
8677
8678 begin
8679 GNAT_Pragma;
8680
8681 -- Skip analysis if disabled
8682
8683 if Debug_Pragmas_Disabled then
8684 Rewrite (N, Make_Null_Statement (Loc));
8685 Analyze (N);
8686 return;
8687 end if;
8688
8689 Cond :=
8690 New_Occurrence_Of
8691 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
8692 Loc);
8693
8694 if Debug_Pragmas_Enabled then
8695 Set_SCO_Pragma_Enabled (Loc);
8696 end if;
8697
8698 if Arg_Count = 2 then
8699 Cond :=
8700 Make_And_Then (Loc,
8701 Left_Opnd => Relocate_Node (Cond),
8702 Right_Opnd => Get_Pragma_Arg (Arg1));
8703 Call := Get_Pragma_Arg (Arg2);
8704 else
8705 Call := Get_Pragma_Arg (Arg1);
8706 end if;
8707
8708 if Nkind_In (Call,
8709 N_Indexed_Component,
8710 N_Function_Call,
8711 N_Identifier,
8712 N_Expanded_Name,
8713 N_Selected_Component)
8714 then
8715 -- If this pragma Debug comes from source, its argument was
8716 -- parsed as a name form (which is syntactically identical).
8717 -- In a generic context a parameterless call will be left as
8718 -- an expanded name (if global) or selected_component if local.
8719 -- Change it to a procedure call statement now.
8720
8721 Change_Name_To_Procedure_Call_Statement (Call);
8722
8723 elsif Nkind (Call) = N_Procedure_Call_Statement then
8724
8725 -- Already in the form of a procedure call statement: nothing
8726 -- to do (could happen in case of an internally generated
8727 -- pragma Debug).
8728
8729 null;
8730
8731 else
8732 -- All other cases: diagnose error
8733
8734 Error_Msg
8735 ("argument of pragma ""Debug"" is not procedure call",
8736 Sloc (Call));
8737 return;
8738 end if;
8739
8740 -- Rewrite into a conditional with an appropriate condition. We
8741 -- wrap the procedure call in a block so that overhead from e.g.
8742 -- use of the secondary stack does not generate execution overhead
8743 -- for suppressed conditions.
8744
8745 -- Normally the analysis that follows will freeze the subprogram
8746 -- being called. However, if the call is to a null procedure,
8747 -- we want to freeze it before creating the block, because the
8748 -- analysis that follows may be done with expansion disabled, in
8749 -- which case the body will not be generated, leading to spurious
8750 -- errors.
8751
8752 if Nkind (Call) = N_Procedure_Call_Statement
8753 and then Is_Entity_Name (Name (Call))
8754 then
8755 Analyze (Name (Call));
8756 Freeze_Before (N, Entity (Name (Call)));
8757 end if;
8758
8759 Rewrite (N, Make_Implicit_If_Statement (N,
8760 Condition => Cond,
8761 Then_Statements => New_List (
8762 Make_Block_Statement (Loc,
8763 Handled_Statement_Sequence =>
8764 Make_Handled_Sequence_Of_Statements (Loc,
8765 Statements => New_List (Relocate_Node (Call)))))));
8766 Analyze (N);
8767 end Debug;
8768
8769 ------------------
8770 -- Debug_Policy --
8771 ------------------
8772
8773 -- pragma Debug_Policy (Check | Ignore)
8774
8775 when Pragma_Debug_Policy =>
8776 GNAT_Pragma;
8777 Check_Arg_Count (1);
8778 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
8779 Debug_Pragmas_Enabled :=
8780 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
8781 Debug_Pragmas_Disabled :=
8782 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
8783
8784 ---------------------
8785 -- Detect_Blocking --
8786 ---------------------
8787
8788 -- pragma Detect_Blocking;
8789
8790 when Pragma_Detect_Blocking =>
8791 Ada_2005_Pragma;
8792 Check_Arg_Count (0);
8793 Check_Valid_Configuration_Pragma;
8794 Detect_Blocking := True;
8795
8796 --------------------------
8797 -- Default_Storage_Pool --
8798 --------------------------
8799
8800 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
8801
8802 when Pragma_Default_Storage_Pool =>
8803 Ada_2012_Pragma;
8804 Check_Arg_Count (1);
8805
8806 -- Default_Storage_Pool can appear as a configuration pragma, or
8807 -- in a declarative part or a package spec.
8808
8809 if not Is_Configuration_Pragma then
8810 Check_Is_In_Decl_Part_Or_Package_Spec;
8811 end if;
8812
8813 -- Case of Default_Storage_Pool (null);
8814
8815 if Nkind (Expression (Arg1)) = N_Null then
8816 Analyze (Expression (Arg1));
8817
8818 -- This is an odd case, this is not really an expression, so
8819 -- we don't have a type for it. So just set the type to Empty.
8820
8821 Set_Etype (Expression (Arg1), Empty);
8822
8823 -- Case of Default_Storage_Pool (storage_pool_NAME);
8824
8825 else
8826 -- If it's a configuration pragma, then the only allowed
8827 -- argument is "null".
8828
8829 if Is_Configuration_Pragma then
8830 Error_Pragma_Arg ("NULL expected", Arg1);
8831 end if;
8832
8833 -- The expected type for a non-"null" argument is
8834 -- Root_Storage_Pool'Class.
8835
8836 Analyze_And_Resolve
8837 (Get_Pragma_Arg (Arg1),
8838 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8839 end if;
8840
8841 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
8842 -- for an access type will use this information to set the
8843 -- appropriate attributes of the access type.
8844
8845 Default_Pool := Expression (Arg1);
8846
8847 ------------------------------------
8848 -- Disable_Atomic_Synchronization --
8849 ------------------------------------
8850
8851 -- pragma Disable_Atomic_Synchronization [(Entity)];
8852
8853 when Pragma_Disable_Atomic_Synchronization =>
8854 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8855
8856 -------------------
8857 -- Discard_Names --
8858 -------------------
8859
8860 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
8861
8862 when Pragma_Discard_Names => Discard_Names : declare
8863 E : Entity_Id;
8864 E_Id : Entity_Id;
8865
8866 begin
8867 Check_Ada_83_Warning;
8868
8869 -- Deal with configuration pragma case
8870
8871 if Arg_Count = 0 and then Is_Configuration_Pragma then
8872 Global_Discard_Names := True;
8873 return;
8874
8875 -- Otherwise, check correct appropriate context
8876
8877 else
8878 Check_Is_In_Decl_Part_Or_Package_Spec;
8879
8880 if Arg_Count = 0 then
8881
8882 -- If there is no parameter, then from now on this pragma
8883 -- applies to any enumeration, exception or tagged type
8884 -- defined in the current declarative part, and recursively
8885 -- to any nested scope.
8886
8887 Set_Discard_Names (Current_Scope);
8888 return;
8889
8890 else
8891 Check_Arg_Count (1);
8892 Check_Optional_Identifier (Arg1, Name_On);
8893 Check_Arg_Is_Local_Name (Arg1);
8894
8895 E_Id := Get_Pragma_Arg (Arg1);
8896
8897 if Etype (E_Id) = Any_Type then
8898 return;
8899 else
8900 E := Entity (E_Id);
8901 end if;
8902
8903 if (Is_First_Subtype (E)
8904 and then
8905 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8906 or else Ekind (E) = E_Exception
8907 then
8908 Set_Discard_Names (E);
8909 Record_Rep_Item (E, N);
8910
8911 else
8912 Error_Pragma_Arg
8913 ("inappropriate entity for pragma%", Arg1);
8914 end if;
8915
8916 end if;
8917 end if;
8918 end Discard_Names;
8919
8920 ------------------------
8921 -- Dispatching_Domain --
8922 ------------------------
8923
8924 -- pragma Dispatching_Domain (EXPRESSION);
8925
8926 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
8927 P : constant Node_Id := Parent (N);
8928 Arg : Node_Id;
8929 Ent : Entity_Id;
8930
8931 begin
8932 Ada_2012_Pragma;
8933 Check_No_Identifiers;
8934 Check_Arg_Count (1);
8935
8936 -- This pragma is born obsolete, but not the aspect
8937
8938 if not From_Aspect_Specification (N) then
8939 Check_Restriction
8940 (No_Obsolescent_Features, Pragma_Identifier (N));
8941 end if;
8942
8943 if Nkind (P) = N_Task_Definition then
8944 Arg := Get_Pragma_Arg (Arg1);
8945 Ent := Defining_Identifier (Parent (P));
8946
8947 -- The expression must be analyzed in the special manner
8948 -- described in "Handling of Default and Per-Object
8949 -- Expressions" in sem.ads.
8950
8951 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8952
8953 -- Check duplicate pragma before we chain the pragma in the Rep
8954 -- Item chain of Ent.
8955
8956 Check_Duplicate_Pragma (Ent);
8957 Record_Rep_Item (Ent, N);
8958
8959 -- Anything else is incorrect
8960
8961 else
8962 Pragma_Misplaced;
8963 end if;
8964 end Dispatching_Domain;
8965
8966 ---------------
8967 -- Elaborate --
8968 ---------------
8969
8970 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8971
8972 when Pragma_Elaborate => Elaborate : declare
8973 Arg : Node_Id;
8974 Citem : Node_Id;
8975
8976 begin
8977 -- Pragma must be in context items list of a compilation unit
8978
8979 if not Is_In_Context_Clause then
8980 Pragma_Misplaced;
8981 end if;
8982
8983 -- Must be at least one argument
8984
8985 if Arg_Count = 0 then
8986 Error_Pragma ("pragma% requires at least one argument");
8987 end if;
8988
8989 -- In Ada 83 mode, there can be no items following it in the
8990 -- context list except other pragmas and implicit with clauses
8991 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8992 -- placement rule does not apply.
8993
8994 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8995 Citem := Next (N);
8996 while Present (Citem) loop
8997 if Nkind (Citem) = N_Pragma
8998 or else (Nkind (Citem) = N_With_Clause
8999 and then Implicit_With (Citem))
9000 then
9001 null;
9002 else
9003 Error_Pragma
9004 ("(Ada 83) pragma% must be at end of context clause");
9005 end if;
9006
9007 Next (Citem);
9008 end loop;
9009 end if;
9010
9011 -- Finally, the arguments must all be units mentioned in a with
9012 -- clause in the same context clause. Note we already checked (in
9013 -- Par.Prag) that the arguments are all identifiers or selected
9014 -- components.
9015
9016 Arg := Arg1;
9017 Outer : while Present (Arg) loop
9018 Citem := First (List_Containing (N));
9019 Inner : while Citem /= N loop
9020 if Nkind (Citem) = N_With_Clause
9021 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
9022 then
9023 Set_Elaborate_Present (Citem, True);
9024 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
9025 Generate_Reference (Entity (Name (Citem)), Citem);
9026
9027 -- With the pragma present, elaboration calls on
9028 -- subprograms from the named unit need no further
9029 -- checks, as long as the pragma appears in the current
9030 -- compilation unit. If the pragma appears in some unit
9031 -- in the context, there might still be a need for an
9032 -- Elaborate_All_Desirable from the current compilation
9033 -- to the named unit, so we keep the check enabled.
9034
9035 if In_Extended_Main_Source_Unit (N) then
9036 Set_Suppress_Elaboration_Warnings
9037 (Entity (Name (Citem)));
9038 end if;
9039
9040 exit Inner;
9041 end if;
9042
9043 Next (Citem);
9044 end loop Inner;
9045
9046 if Citem = N then
9047 Error_Pragma_Arg
9048 ("argument of pragma% is not withed unit", Arg);
9049 end if;
9050
9051 Next (Arg);
9052 end loop Outer;
9053
9054 -- Give a warning if operating in static mode with -gnatwl
9055 -- (elaboration warnings enabled) switch set.
9056
9057 if Elab_Warnings and not Dynamic_Elaboration_Checks then
9058 Error_Msg_N
9059 ("?l?use of pragma Elaborate may not be safe", N);
9060 Error_Msg_N
9061 ("?l?use pragma Elaborate_All instead if possible", N);
9062 end if;
9063 end Elaborate;
9064
9065 -------------------
9066 -- Elaborate_All --
9067 -------------------
9068
9069 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
9070
9071 when Pragma_Elaborate_All => Elaborate_All : declare
9072 Arg : Node_Id;
9073 Citem : Node_Id;
9074
9075 begin
9076 Check_Ada_83_Warning;
9077
9078 -- Pragma must be in context items list of a compilation unit
9079
9080 if not Is_In_Context_Clause then
9081 Pragma_Misplaced;
9082 end if;
9083
9084 -- Must be at least one argument
9085
9086 if Arg_Count = 0 then
9087 Error_Pragma ("pragma% requires at least one argument");
9088 end if;
9089
9090 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
9091 -- have to appear at the end of the context clause, but may
9092 -- appear mixed in with other items, even in Ada 83 mode.
9093
9094 -- Final check: the arguments must all be units mentioned in
9095 -- a with clause in the same context clause. Note that we
9096 -- already checked (in Par.Prag) that all the arguments are
9097 -- either identifiers or selected components.
9098
9099 Arg := Arg1;
9100 Outr : while Present (Arg) loop
9101 Citem := First (List_Containing (N));
9102 Innr : while Citem /= N loop
9103 if Nkind (Citem) = N_With_Clause
9104 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
9105 then
9106 Set_Elaborate_All_Present (Citem, True);
9107 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
9108
9109 -- Suppress warnings and elaboration checks on the named
9110 -- unit if the pragma is in the current compilation, as
9111 -- for pragma Elaborate.
9112
9113 if In_Extended_Main_Source_Unit (N) then
9114 Set_Suppress_Elaboration_Warnings
9115 (Entity (Name (Citem)));
9116 end if;
9117 exit Innr;
9118 end if;
9119
9120 Next (Citem);
9121 end loop Innr;
9122
9123 if Citem = N then
9124 Set_Error_Posted (N);
9125 Error_Pragma_Arg
9126 ("argument of pragma% is not withed unit", Arg);
9127 end if;
9128
9129 Next (Arg);
9130 end loop Outr;
9131 end Elaborate_All;
9132
9133 --------------------
9134 -- Elaborate_Body --
9135 --------------------
9136
9137 -- pragma Elaborate_Body [( library_unit_NAME )];
9138
9139 when Pragma_Elaborate_Body => Elaborate_Body : declare
9140 Cunit_Node : Node_Id;
9141 Cunit_Ent : Entity_Id;
9142
9143 begin
9144 Check_Ada_83_Warning;
9145 Check_Valid_Library_Unit_Pragma;
9146
9147 if Nkind (N) = N_Null_Statement then
9148 return;
9149 end if;
9150
9151 Cunit_Node := Cunit (Current_Sem_Unit);
9152 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
9153
9154 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
9155 N_Subprogram_Body)
9156 then
9157 Error_Pragma ("pragma% must refer to a spec, not a body");
9158 else
9159 Set_Body_Required (Cunit_Node, True);
9160 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
9161
9162 -- If we are in dynamic elaboration mode, then we suppress
9163 -- elaboration warnings for the unit, since it is definitely
9164 -- fine NOT to do dynamic checks at the first level (and such
9165 -- checks will be suppressed because no elaboration boolean
9166 -- is created for Elaborate_Body packages).
9167
9168 -- But in the static model of elaboration, Elaborate_Body is
9169 -- definitely NOT good enough to ensure elaboration safety on
9170 -- its own, since the body may WITH other units that are not
9171 -- safe from an elaboration point of view, so a client must
9172 -- still do an Elaborate_All on such units.
9173
9174 -- Debug flag -gnatdD restores the old behavior of 3.13, where
9175 -- Elaborate_Body always suppressed elab warnings.
9176
9177 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
9178 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
9179 end if;
9180 end if;
9181 end Elaborate_Body;
9182
9183 ------------------------
9184 -- Elaboration_Checks --
9185 ------------------------
9186
9187 -- pragma Elaboration_Checks (Static | Dynamic);
9188
9189 when Pragma_Elaboration_Checks =>
9190 GNAT_Pragma;
9191 Check_Arg_Count (1);
9192 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
9193 Dynamic_Elaboration_Checks :=
9194 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
9195
9196 ---------------
9197 -- Eliminate --
9198 ---------------
9199
9200 -- pragma Eliminate (
9201 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
9202 -- [,[Entity =>] IDENTIFIER |
9203 -- SELECTED_COMPONENT |
9204 -- STRING_LITERAL]
9205 -- [, OVERLOADING_RESOLUTION]);
9206
9207 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
9208 -- SOURCE_LOCATION
9209
9210 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
9211 -- FUNCTION_PROFILE
9212
9213 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
9214
9215 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
9216 -- Result_Type => result_SUBTYPE_NAME]
9217
9218 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
9219 -- SUBTYPE_NAME ::= STRING_LITERAL
9220
9221 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
9222 -- SOURCE_TRACE ::= STRING_LITERAL
9223
9224 when Pragma_Eliminate => Eliminate : declare
9225 Args : Args_List (1 .. 5);
9226 Names : constant Name_List (1 .. 5) := (
9227 Name_Unit_Name,
9228 Name_Entity,
9229 Name_Parameter_Types,
9230 Name_Result_Type,
9231 Name_Source_Location);
9232
9233 Unit_Name : Node_Id renames Args (1);
9234 Entity : Node_Id renames Args (2);
9235 Parameter_Types : Node_Id renames Args (3);
9236 Result_Type : Node_Id renames Args (4);
9237 Source_Location : Node_Id renames Args (5);
9238
9239 begin
9240 GNAT_Pragma;
9241 Check_Valid_Configuration_Pragma;
9242 Gather_Associations (Names, Args);
9243
9244 if No (Unit_Name) then
9245 Error_Pragma ("missing Unit_Name argument for pragma%");
9246 end if;
9247
9248 if No (Entity)
9249 and then (Present (Parameter_Types)
9250 or else
9251 Present (Result_Type)
9252 or else
9253 Present (Source_Location))
9254 then
9255 Error_Pragma ("missing Entity argument for pragma%");
9256 end if;
9257
9258 if (Present (Parameter_Types)
9259 or else
9260 Present (Result_Type))
9261 and then
9262 Present (Source_Location)
9263 then
9264 Error_Pragma
9265 ("parameter profile and source location cannot " &
9266 "be used together in pragma%");
9267 end if;
9268
9269 Process_Eliminate_Pragma
9270 (N,
9271 Unit_Name,
9272 Entity,
9273 Parameter_Types,
9274 Result_Type,
9275 Source_Location);
9276 end Eliminate;
9277
9278 -----------------------------------
9279 -- Enable_Atomic_Synchronization --
9280 -----------------------------------
9281
9282 -- pragma Enable_Atomic_Synchronization [(Entity)];
9283
9284 when Pragma_Enable_Atomic_Synchronization =>
9285 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
9286
9287 ------------
9288 -- Export --
9289 ------------
9290
9291 -- pragma Export (
9292 -- [ Convention =>] convention_IDENTIFIER,
9293 -- [ Entity =>] local_NAME
9294 -- [, [External_Name =>] static_string_EXPRESSION ]
9295 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9296
9297 when Pragma_Export => Export : declare
9298 C : Convention_Id;
9299 Def_Id : Entity_Id;
9300
9301 pragma Warnings (Off, C);
9302
9303 begin
9304 Check_Ada_83_Warning;
9305 Check_Arg_Order
9306 ((Name_Convention,
9307 Name_Entity,
9308 Name_External_Name,
9309 Name_Link_Name));
9310
9311 Check_At_Least_N_Arguments (2);
9312
9313 Check_At_Most_N_Arguments (4);
9314 Process_Convention (C, Def_Id);
9315
9316 if Ekind (Def_Id) /= E_Constant then
9317 Note_Possible_Modification
9318 (Get_Pragma_Arg (Arg2), Sure => False);
9319 end if;
9320
9321 Process_Interface_Name (Def_Id, Arg3, Arg4);
9322 Set_Exported (Def_Id, Arg2);
9323
9324 -- If the entity is a deferred constant, propagate the information
9325 -- to the full view, because gigi elaborates the full view only.
9326
9327 if Ekind (Def_Id) = E_Constant
9328 and then Present (Full_View (Def_Id))
9329 then
9330 declare
9331 Id2 : constant Entity_Id := Full_View (Def_Id);
9332 begin
9333 Set_Is_Exported (Id2, Is_Exported (Def_Id));
9334 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
9335 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
9336 end;
9337 end if;
9338 end Export;
9339
9340 ----------------------
9341 -- Export_Exception --
9342 ----------------------
9343
9344 -- pragma Export_Exception (
9345 -- [Internal =>] LOCAL_NAME
9346 -- [, [External =>] EXTERNAL_SYMBOL]
9347 -- [, [Form =>] Ada | VMS]
9348 -- [, [Code =>] static_integer_EXPRESSION]);
9349
9350 when Pragma_Export_Exception => Export_Exception : declare
9351 Args : Args_List (1 .. 4);
9352 Names : constant Name_List (1 .. 4) := (
9353 Name_Internal,
9354 Name_External,
9355 Name_Form,
9356 Name_Code);
9357
9358 Internal : Node_Id renames Args (1);
9359 External : Node_Id renames Args (2);
9360 Form : Node_Id renames Args (3);
9361 Code : Node_Id renames Args (4);
9362
9363 begin
9364 GNAT_Pragma;
9365
9366 if Inside_A_Generic then
9367 Error_Pragma ("pragma% cannot be used for generic entities");
9368 end if;
9369
9370 Gather_Associations (Names, Args);
9371 Process_Extended_Import_Export_Exception_Pragma (
9372 Arg_Internal => Internal,
9373 Arg_External => External,
9374 Arg_Form => Form,
9375 Arg_Code => Code);
9376
9377 if not Is_VMS_Exception (Entity (Internal)) then
9378 Set_Exported (Entity (Internal), Internal);
9379 end if;
9380 end Export_Exception;
9381
9382 ---------------------
9383 -- Export_Function --
9384 ---------------------
9385
9386 -- pragma Export_Function (
9387 -- [Internal =>] LOCAL_NAME
9388 -- [, [External =>] EXTERNAL_SYMBOL]
9389 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9390 -- [, [Result_Type =>] TYPE_DESIGNATOR]
9391 -- [, [Mechanism =>] MECHANISM]
9392 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
9393
9394 -- EXTERNAL_SYMBOL ::=
9395 -- IDENTIFIER
9396 -- | static_string_EXPRESSION
9397
9398 -- PARAMETER_TYPES ::=
9399 -- null
9400 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9401
9402 -- TYPE_DESIGNATOR ::=
9403 -- subtype_NAME
9404 -- | subtype_Name ' Access
9405
9406 -- MECHANISM ::=
9407 -- MECHANISM_NAME
9408 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9409
9410 -- MECHANISM_ASSOCIATION ::=
9411 -- [formal_parameter_NAME =>] MECHANISM_NAME
9412
9413 -- MECHANISM_NAME ::=
9414 -- Value
9415 -- | Reference
9416 -- | Descriptor [([Class =>] CLASS_NAME)]
9417
9418 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9419
9420 when Pragma_Export_Function => Export_Function : declare
9421 Args : Args_List (1 .. 6);
9422 Names : constant Name_List (1 .. 6) := (
9423 Name_Internal,
9424 Name_External,
9425 Name_Parameter_Types,
9426 Name_Result_Type,
9427 Name_Mechanism,
9428 Name_Result_Mechanism);
9429
9430 Internal : Node_Id renames Args (1);
9431 External : Node_Id renames Args (2);
9432 Parameter_Types : Node_Id renames Args (3);
9433 Result_Type : Node_Id renames Args (4);
9434 Mechanism : Node_Id renames Args (5);
9435 Result_Mechanism : Node_Id renames Args (6);
9436
9437 begin
9438 GNAT_Pragma;
9439 Gather_Associations (Names, Args);
9440 Process_Extended_Import_Export_Subprogram_Pragma (
9441 Arg_Internal => Internal,
9442 Arg_External => External,
9443 Arg_Parameter_Types => Parameter_Types,
9444 Arg_Result_Type => Result_Type,
9445 Arg_Mechanism => Mechanism,
9446 Arg_Result_Mechanism => Result_Mechanism);
9447 end Export_Function;
9448
9449 -------------------
9450 -- Export_Object --
9451 -------------------
9452
9453 -- pragma Export_Object (
9454 -- [Internal =>] LOCAL_NAME
9455 -- [, [External =>] EXTERNAL_SYMBOL]
9456 -- [, [Size =>] EXTERNAL_SYMBOL]);
9457
9458 -- EXTERNAL_SYMBOL ::=
9459 -- IDENTIFIER
9460 -- | static_string_EXPRESSION
9461
9462 -- PARAMETER_TYPES ::=
9463 -- null
9464 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9465
9466 -- TYPE_DESIGNATOR ::=
9467 -- subtype_NAME
9468 -- | subtype_Name ' Access
9469
9470 -- MECHANISM ::=
9471 -- MECHANISM_NAME
9472 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9473
9474 -- MECHANISM_ASSOCIATION ::=
9475 -- [formal_parameter_NAME =>] MECHANISM_NAME
9476
9477 -- MECHANISM_NAME ::=
9478 -- Value
9479 -- | Reference
9480 -- | Descriptor [([Class =>] CLASS_NAME)]
9481
9482 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9483
9484 when Pragma_Export_Object => Export_Object : declare
9485 Args : Args_List (1 .. 3);
9486 Names : constant Name_List (1 .. 3) := (
9487 Name_Internal,
9488 Name_External,
9489 Name_Size);
9490
9491 Internal : Node_Id renames Args (1);
9492 External : Node_Id renames Args (2);
9493 Size : Node_Id renames Args (3);
9494
9495 begin
9496 GNAT_Pragma;
9497 Gather_Associations (Names, Args);
9498 Process_Extended_Import_Export_Object_Pragma (
9499 Arg_Internal => Internal,
9500 Arg_External => External,
9501 Arg_Size => Size);
9502 end Export_Object;
9503
9504 ----------------------
9505 -- Export_Procedure --
9506 ----------------------
9507
9508 -- pragma Export_Procedure (
9509 -- [Internal =>] LOCAL_NAME
9510 -- [, [External =>] EXTERNAL_SYMBOL]
9511 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9512 -- [, [Mechanism =>] MECHANISM]);
9513
9514 -- EXTERNAL_SYMBOL ::=
9515 -- IDENTIFIER
9516 -- | static_string_EXPRESSION
9517
9518 -- PARAMETER_TYPES ::=
9519 -- null
9520 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9521
9522 -- TYPE_DESIGNATOR ::=
9523 -- subtype_NAME
9524 -- | subtype_Name ' Access
9525
9526 -- MECHANISM ::=
9527 -- MECHANISM_NAME
9528 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9529
9530 -- MECHANISM_ASSOCIATION ::=
9531 -- [formal_parameter_NAME =>] MECHANISM_NAME
9532
9533 -- MECHANISM_NAME ::=
9534 -- Value
9535 -- | Reference
9536 -- | Descriptor [([Class =>] CLASS_NAME)]
9537
9538 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9539
9540 when Pragma_Export_Procedure => Export_Procedure : declare
9541 Args : Args_List (1 .. 4);
9542 Names : constant Name_List (1 .. 4) := (
9543 Name_Internal,
9544 Name_External,
9545 Name_Parameter_Types,
9546 Name_Mechanism);
9547
9548 Internal : Node_Id renames Args (1);
9549 External : Node_Id renames Args (2);
9550 Parameter_Types : Node_Id renames Args (3);
9551 Mechanism : Node_Id renames Args (4);
9552
9553 begin
9554 GNAT_Pragma;
9555 Gather_Associations (Names, Args);
9556 Process_Extended_Import_Export_Subprogram_Pragma (
9557 Arg_Internal => Internal,
9558 Arg_External => External,
9559 Arg_Parameter_Types => Parameter_Types,
9560 Arg_Mechanism => Mechanism);
9561 end Export_Procedure;
9562
9563 ------------------
9564 -- Export_Value --
9565 ------------------
9566
9567 -- pragma Export_Value (
9568 -- [Value =>] static_integer_EXPRESSION,
9569 -- [Link_Name =>] static_string_EXPRESSION);
9570
9571 when Pragma_Export_Value =>
9572 GNAT_Pragma;
9573 Check_Arg_Order ((Name_Value, Name_Link_Name));
9574 Check_Arg_Count (2);
9575
9576 Check_Optional_Identifier (Arg1, Name_Value);
9577 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9578
9579 Check_Optional_Identifier (Arg2, Name_Link_Name);
9580 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9581
9582 -----------------------------
9583 -- Export_Valued_Procedure --
9584 -----------------------------
9585
9586 -- pragma Export_Valued_Procedure (
9587 -- [Internal =>] LOCAL_NAME
9588 -- [, [External =>] EXTERNAL_SYMBOL,]
9589 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9590 -- [, [Mechanism =>] MECHANISM]);
9591
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
9618 when Pragma_Export_Valued_Procedure =>
9619 Export_Valued_Procedure : declare
9620 Args : Args_List (1 .. 4);
9621 Names : constant Name_List (1 .. 4) := (
9622 Name_Internal,
9623 Name_External,
9624 Name_Parameter_Types,
9625 Name_Mechanism);
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
9632 begin
9633 GNAT_Pragma;
9634 Gather_Associations (Names, Args);
9635 Process_Extended_Import_Export_Subprogram_Pragma (
9636 Arg_Internal => Internal,
9637 Arg_External => External,
9638 Arg_Parameter_Types => Parameter_Types,
9639 Arg_Mechanism => Mechanism);
9640 end Export_Valued_Procedure;
9641
9642 -------------------
9643 -- Extend_System --
9644 -------------------
9645
9646 -- pragma Extend_System ([Name =>] Identifier);
9647
9648 when Pragma_Extend_System => Extend_System : declare
9649 begin
9650 GNAT_Pragma;
9651 Check_Valid_Configuration_Pragma;
9652 Check_Arg_Count (1);
9653 Check_Optional_Identifier (Arg1, Name_Name);
9654 Check_Arg_Is_Identifier (Arg1);
9655
9656 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
9657
9658 if Name_Len > 4
9659 and then Name_Buffer (1 .. 4) = "aux_"
9660 then
9661 if Present (System_Extend_Pragma_Arg) then
9662 if Chars (Get_Pragma_Arg (Arg1)) =
9663 Chars (Expression (System_Extend_Pragma_Arg))
9664 then
9665 null;
9666 else
9667 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
9668 Error_Pragma ("pragma% conflicts with that #");
9669 end if;
9670
9671 else
9672 System_Extend_Pragma_Arg := Arg1;
9673
9674 if not GNAT_Mode then
9675 System_Extend_Unit := Arg1;
9676 end if;
9677 end if;
9678 else
9679 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
9680 end if;
9681 end Extend_System;
9682
9683 ------------------------
9684 -- Extensions_Allowed --
9685 ------------------------
9686
9687 -- pragma Extensions_Allowed (ON | OFF);
9688
9689 when Pragma_Extensions_Allowed =>
9690 GNAT_Pragma;
9691 Check_Arg_Count (1);
9692 Check_No_Identifiers;
9693 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9694
9695 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
9696 Extensions_Allowed := True;
9697 Ada_Version := Ada_Version_Type'Last;
9698
9699 else
9700 Extensions_Allowed := False;
9701 Ada_Version := Ada_Version_Explicit;
9702 end if;
9703
9704 --------------
9705 -- External --
9706 --------------
9707
9708 -- pragma External (
9709 -- [ Convention =>] convention_IDENTIFIER,
9710 -- [ Entity =>] local_NAME
9711 -- [, [External_Name =>] static_string_EXPRESSION ]
9712 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9713
9714 when Pragma_External => External : declare
9715 Def_Id : Entity_Id;
9716
9717 C : Convention_Id;
9718 pragma Warnings (Off, C);
9719
9720 begin
9721 GNAT_Pragma;
9722 Check_Arg_Order
9723 ((Name_Convention,
9724 Name_Entity,
9725 Name_External_Name,
9726 Name_Link_Name));
9727 Check_At_Least_N_Arguments (2);
9728 Check_At_Most_N_Arguments (4);
9729 Process_Convention (C, Def_Id);
9730 Note_Possible_Modification
9731 (Get_Pragma_Arg (Arg2), Sure => False);
9732 Process_Interface_Name (Def_Id, Arg3, Arg4);
9733 Set_Exported (Def_Id, Arg2);
9734 end External;
9735
9736 --------------------------
9737 -- External_Name_Casing --
9738 --------------------------
9739
9740 -- pragma External_Name_Casing (
9741 -- UPPERCASE | LOWERCASE
9742 -- [, AS_IS | UPPERCASE | LOWERCASE]);
9743
9744 when Pragma_External_Name_Casing => External_Name_Casing : declare
9745 begin
9746 GNAT_Pragma;
9747 Check_No_Identifiers;
9748
9749 if Arg_Count = 2 then
9750 Check_Arg_Is_One_Of
9751 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
9752
9753 case Chars (Get_Pragma_Arg (Arg2)) is
9754 when Name_As_Is =>
9755 Opt.External_Name_Exp_Casing := As_Is;
9756
9757 when Name_Uppercase =>
9758 Opt.External_Name_Exp_Casing := Uppercase;
9759
9760 when Name_Lowercase =>
9761 Opt.External_Name_Exp_Casing := Lowercase;
9762
9763 when others =>
9764 null;
9765 end case;
9766
9767 else
9768 Check_Arg_Count (1);
9769 end if;
9770
9771 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
9772
9773 case Chars (Get_Pragma_Arg (Arg1)) is
9774 when Name_Uppercase =>
9775 Opt.External_Name_Imp_Casing := Uppercase;
9776
9777 when Name_Lowercase =>
9778 Opt.External_Name_Imp_Casing := Lowercase;
9779
9780 when others =>
9781 null;
9782 end case;
9783 end External_Name_Casing;
9784
9785 --------------------------
9786 -- Favor_Top_Level --
9787 --------------------------
9788
9789 -- pragma Favor_Top_Level (type_NAME);
9790
9791 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
9792 Named_Entity : Entity_Id;
9793
9794 begin
9795 GNAT_Pragma;
9796 Check_No_Identifiers;
9797 Check_Arg_Count (1);
9798 Check_Arg_Is_Local_Name (Arg1);
9799 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
9800
9801 -- If it's an access-to-subprogram type (in particular, not a
9802 -- subtype), set the flag on that type.
9803
9804 if Is_Access_Subprogram_Type (Named_Entity) then
9805 Set_Can_Use_Internal_Rep (Named_Entity, False);
9806
9807 -- Otherwise it's an error (name denotes the wrong sort of entity)
9808
9809 else
9810 Error_Pragma_Arg
9811 ("access-to-subprogram type expected",
9812 Get_Pragma_Arg (Arg1));
9813 end if;
9814 end Favor_Top_Level;
9815
9816 ---------------
9817 -- Fast_Math --
9818 ---------------
9819
9820 -- pragma Fast_Math;
9821
9822 when Pragma_Fast_Math =>
9823 GNAT_Pragma;
9824 Check_No_Identifiers;
9825 Check_Valid_Configuration_Pragma;
9826 Fast_Math := True;
9827
9828 ---------------------------
9829 -- Finalize_Storage_Only --
9830 ---------------------------
9831
9832 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9833
9834 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
9835 Assoc : constant Node_Id := Arg1;
9836 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
9837 Typ : Entity_Id;
9838
9839 begin
9840 GNAT_Pragma;
9841 Check_No_Identifiers;
9842 Check_Arg_Count (1);
9843 Check_Arg_Is_Local_Name (Arg1);
9844
9845 Find_Type (Type_Id);
9846 Typ := Entity (Type_Id);
9847
9848 if Typ = Any_Type
9849 or else Rep_Item_Too_Early (Typ, N)
9850 then
9851 return;
9852 else
9853 Typ := Underlying_Type (Typ);
9854 end if;
9855
9856 if not Is_Controlled (Typ) then
9857 Error_Pragma ("pragma% must specify controlled type");
9858 end if;
9859
9860 Check_First_Subtype (Arg1);
9861
9862 if Finalize_Storage_Only (Typ) then
9863 Error_Pragma ("duplicate pragma%, only one allowed");
9864
9865 elsif not Rep_Item_Too_Late (Typ, N) then
9866 Set_Finalize_Storage_Only (Base_Type (Typ), True);
9867 end if;
9868 end Finalize_Storage;
9869
9870 --------------------------
9871 -- Float_Representation --
9872 --------------------------
9873
9874 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9875
9876 -- FLOAT_REP ::= VAX_Float | IEEE_Float
9877
9878 when Pragma_Float_Representation => Float_Representation : declare
9879 Argx : Node_Id;
9880 Digs : Nat;
9881 Ent : Entity_Id;
9882
9883 begin
9884 GNAT_Pragma;
9885
9886 if Arg_Count = 1 then
9887 Check_Valid_Configuration_Pragma;
9888 else
9889 Check_Arg_Count (2);
9890 Check_Optional_Identifier (Arg2, Name_Entity);
9891 Check_Arg_Is_Local_Name (Arg2);
9892 end if;
9893
9894 Check_No_Identifier (Arg1);
9895 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9896
9897 if not OpenVMS_On_Target then
9898 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9899 Error_Pragma
9900 ("??pragma% ignored (applies only to Open'V'M'S)");
9901 end if;
9902
9903 return;
9904 end if;
9905
9906 -- One argument case
9907
9908 if Arg_Count = 1 then
9909 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9910 if Opt.Float_Format = 'I' then
9911 Error_Pragma ("'I'E'E'E format previously specified");
9912 end if;
9913
9914 Opt.Float_Format := 'V';
9915
9916 else
9917 if Opt.Float_Format = 'V' then
9918 Error_Pragma ("'V'A'X format previously specified");
9919 end if;
9920
9921 Opt.Float_Format := 'I';
9922 end if;
9923
9924 Set_Standard_Fpt_Formats;
9925
9926 -- Two argument case
9927
9928 else
9929 Argx := Get_Pragma_Arg (Arg2);
9930
9931 if not Is_Entity_Name (Argx)
9932 or else not Is_Floating_Point_Type (Entity (Argx))
9933 then
9934 Error_Pragma_Arg
9935 ("second argument of% pragma must be floating-point type",
9936 Arg2);
9937 end if;
9938
9939 Ent := Entity (Argx);
9940 Digs := UI_To_Int (Digits_Value (Ent));
9941
9942 -- Two arguments, VAX_Float case
9943
9944 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9945 case Digs is
9946 when 6 => Set_F_Float (Ent);
9947 when 9 => Set_D_Float (Ent);
9948 when 15 => Set_G_Float (Ent);
9949
9950 when others =>
9951 Error_Pragma_Arg
9952 ("wrong digits value, must be 6,9 or 15", Arg2);
9953 end case;
9954
9955 -- Two arguments, IEEE_Float case
9956
9957 else
9958 case Digs is
9959 when 6 => Set_IEEE_Short (Ent);
9960 when 15 => Set_IEEE_Long (Ent);
9961
9962 when others =>
9963 Error_Pragma_Arg
9964 ("wrong digits value, must be 6 or 15", Arg2);
9965 end case;
9966 end if;
9967 end if;
9968 end Float_Representation;
9969
9970 ------------
9971 -- Global --
9972 ------------
9973
9974 -- pragma Global (GLOBAL_SPECIFICATION)
9975
9976 -- GLOBAL_SPECIFICATION ::= MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
9977 -- | GLOBAL_LIST
9978 -- | null
9979 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
9980 -- MODE_SELECTOR ::= Input | Output | In_Out | Contract_In
9981 -- GLOBAL_LIST ::= GLOBAL_ITEM
9982 -- | (GLOBAL_ITEM {, GLOBAL_ITEM})
9983 -- GLOBAL_ITEM ::= NAME
9984
9985 when Pragma_Global => Global : declare
9986 Subp_Id : Entity_Id;
9987
9988 Seen : Elist_Id := No_Elist;
9989 -- A list containing the entities of all the items processed so
9990 -- far. It plays a role in detecting distinct entities.
9991
9992 -- Flags used to verify the consistency of modes
9993
9994 Contract_Seen : Boolean := False;
9995 In_Out_Seen : Boolean := False;
9996 Input_Seen : Boolean := False;
9997 Output_Seen : Boolean := False;
9998
9999 procedure Analyze_Global_List
10000 (List : Node_Id;
10001 Global_Mode : Name_Id := Name_Input);
10002 -- Verify the legality of a single global list declaration.
10003 -- Global_Mode denotes the current mode in effect.
10004
10005 -------------------------
10006 -- Analyze_Global_List --
10007 -------------------------
10008
10009 procedure Analyze_Global_List
10010 (List : Node_Id;
10011 Global_Mode : Name_Id := Name_Input)
10012 is
10013 procedure Analyze_Global_Item
10014 (Item : Node_Id;
10015 Global_Mode : Name_Id);
10016 -- Verify the legality of a single global item declaration.
10017 -- Global_Mode denotes the current mode in effect.
10018
10019 procedure Check_Duplicate_Mode
10020 (Mode : Node_Id;
10021 Status : in out Boolean);
10022 -- Flag Status denotes whether a particular mode has been seen
10023 -- while processing a global list. This routine verifies that
10024 -- Mode is not a duplicate mode and sets the flag Status.
10025
10026 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
10027 -- Mode denotes either In_Out or Output. Depending on the kind
10028 -- of the related subprogram, emit an error if those two modes
10029 -- apply to a function.
10030
10031 -------------------------
10032 -- Analyze_Global_Item --
10033 -------------------------
10034
10035 procedure Analyze_Global_Item
10036 (Item : Node_Id;
10037 Global_Mode : Name_Id)
10038 is
10039 function Is_Duplicate_Item (Id : Entity_Id) return Boolean;
10040 -- Determine whether Id has already been processed
10041
10042 -----------------------
10043 -- Is_Duplicate_Item --
10044 -----------------------
10045
10046 function Is_Duplicate_Item (Id : Entity_Id) return Boolean is
10047 Item_Elmt : Elmt_Id;
10048
10049 begin
10050 if Present (Seen) then
10051 Item_Elmt := First_Elmt (Seen);
10052 while Present (Item_Elmt) loop
10053 if Node (Item_Elmt) = Id then
10054 return True;
10055 end if;
10056
10057 Next_Elmt (Item_Elmt);
10058 end loop;
10059 end if;
10060
10061 return False;
10062 end Is_Duplicate_Item;
10063
10064 -- Local declarations
10065
10066 Id : Entity_Id;
10067
10068 -- Start of processing for Analyze_Global_Item
10069
10070 begin
10071 -- Detect one of the following cases
10072
10073 -- with Global => (null, Name)
10074 -- with Global => (Name_1, null, Name_2)
10075 -- with Global => (Name, null)
10076
10077 if Nkind (Item) = N_Null then
10078 Error_Msg_N
10079 ("cannot mix null and non-null global items", Item);
10080 return;
10081 end if;
10082
10083 Analyze (Item);
10084
10085 if Is_Entity_Name (Item) then
10086 Id := Entity (Item);
10087
10088 -- A global item cannot reference a formal parameter. Do
10089 -- this check first to provide a better error diagnostic.
10090
10091 if Is_Formal (Id) then
10092 Error_Msg_N
10093 ("global item cannot reference formal parameter",
10094 Item);
10095 return;
10096
10097 -- The only legal references are those to abstract states
10098 -- and variables.
10099
10100 elsif not Ekind_In (Entity (Item), E_Abstract_State,
10101 E_Variable)
10102 then
10103 Error_Msg_N
10104 ("global item must denote variable or state", Item);
10105 return;
10106 end if;
10107
10108 -- Some form of illegal construct masquerading as a name
10109
10110 else
10111 Error_Msg_N
10112 ("global item must denote variable or state", Item);
10113 return;
10114 end if;
10115
10116 -- The same entity might be referenced through various way.
10117 -- Check the entity of the item rather than the item itself.
10118
10119 if Is_Duplicate_Item (Id) then
10120 Error_Msg_N ("duplicate global item", Item);
10121
10122 -- Add the entity of the current item to the list of
10123 -- processed items.
10124
10125 else
10126 if No (Seen) then
10127 Seen := New_Elmt_List;
10128 end if;
10129
10130 Append_Elmt (Id, Seen);
10131 end if;
10132
10133 if Ekind (Id) = E_Abstract_State
10134 and then Is_Volatile_State (Id)
10135 then
10136 -- A global item of mode In_Out or Output cannot denote a
10137 -- volatile Input state.
10138
10139 if Is_Input_State (Id)
10140 and then (Global_Mode = Name_In_Out
10141 or else
10142 Global_Mode = Name_Output)
10143 then
10144 Error_Msg_N
10145 ("global item of mode In_Out or Output cannot " &
10146 "reference Volatile Input state", Item);
10147
10148 -- A global item of mode In_Out or Input cannot reference
10149 -- a volatile Output state.
10150
10151 elsif Is_Output_State (Id)
10152 and then (Global_Mode = Name_In_Out
10153 or else
10154 Global_Mode = Name_Input)
10155 then
10156 Error_Msg_N
10157 ("global item of mode In_Out or Input cannot "
10158 & "reference Volatile Output state", Item);
10159 end if;
10160 end if;
10161 end Analyze_Global_Item;
10162
10163 --------------------------
10164 -- Check_Duplicate_Mode --
10165 --------------------------
10166
10167 procedure Check_Duplicate_Mode
10168 (Mode : Node_Id;
10169 Status : in out Boolean)
10170 is
10171 begin
10172 if Status then
10173 Error_Msg_N ("duplicate global mode", Mode);
10174 end if;
10175
10176 Status := True;
10177 end Check_Duplicate_Mode;
10178
10179 ----------------------------------------
10180 -- Check_Mode_Restriction_In_Function --
10181 ----------------------------------------
10182
10183 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
10184 begin
10185 if Ekind (Subp_Id) = E_Function then
10186 Error_Msg_Name_1 := Chars (Mode);
10187 Error_Msg_N
10188 ("global mode % not applicable to functions", Mode);
10189 end if;
10190 end Check_Mode_Restriction_In_Function;
10191
10192 -- Local variables
10193
10194 Assoc : Node_Id;
10195 Item : Node_Id;
10196 Mode : Node_Id;
10197
10198 -- Start of processing for Analyze_Global_List
10199
10200 begin
10201 -- Single global item declaration
10202
10203 if Nkind_In (List, N_Identifier, N_Selected_Component) then
10204 Analyze_Global_Item (List, Global_Mode);
10205
10206 -- Simple global list or moded global list declaration
10207
10208 elsif Nkind (List) = N_Aggregate then
10209
10210 -- The declaration of a simple global list appear as a
10211 -- collection of expressions.
10212
10213 if Present (Expressions (List)) then
10214 if Present (Component_Associations (List)) then
10215 Error_Msg_N
10216 ("cannot mix moded and non-moded global lists",
10217 List);
10218 end if;
10219
10220 Item := First (Expressions (List));
10221 while Present (Item) loop
10222 Analyze_Global_Item (Item, Global_Mode);
10223
10224 Next (Item);
10225 end loop;
10226
10227 -- The declaration of a moded global list appears as a
10228 -- collection of component associations where individual
10229 -- choices denote modes.
10230
10231 elsif Present (Component_Associations (List)) then
10232 if Present (Expressions (List)) then
10233 Error_Msg_N
10234 ("cannot mix moded and non-moded global lists",
10235 List);
10236 end if;
10237
10238 Assoc := First (Component_Associations (List));
10239 while Present (Assoc) loop
10240 Mode := First (Choices (Assoc));
10241
10242 if Nkind (Mode) = N_Identifier then
10243 if Chars (Mode) = Name_Contract_In then
10244 Check_Duplicate_Mode (Mode, Contract_Seen);
10245
10246 elsif Chars (Mode) = Name_In_Out then
10247 Check_Duplicate_Mode (Mode, In_Out_Seen);
10248 Check_Mode_Restriction_In_Function (Mode);
10249
10250 elsif Chars (Mode) = Name_Input then
10251 Check_Duplicate_Mode (Mode, Input_Seen);
10252
10253 elsif Chars (Mode) = Name_Output then
10254 Check_Duplicate_Mode (Mode, Output_Seen);
10255 Check_Mode_Restriction_In_Function (Mode);
10256
10257 else
10258 Error_Msg_N ("invalid mode selector", Mode);
10259 end if;
10260
10261 else
10262 Error_Msg_N ("invalid mode selector", Mode);
10263 end if;
10264
10265 -- Items in a moded list appear as a collection of
10266 -- expressions. Reuse the existing machinery to
10267 -- analyze them.
10268
10269 Analyze_Global_List
10270 (List => Expression (Assoc),
10271 Global_Mode => Chars (Mode));
10272
10273 Next (Assoc);
10274 end loop;
10275
10276 -- Something went horribly wrong, we have a malformed tree
10277
10278 else
10279 raise Program_Error;
10280 end if;
10281
10282 -- Any other attempt to declare a global item is erroneous
10283
10284 else
10285 Error_Msg_N ("malformed global list declaration", List);
10286 end if;
10287 end Analyze_Global_List;
10288
10289 -- Local variables
10290
10291 List : Node_Id;
10292 Subp : Node_Id;
10293
10294 -- Start of processing for Global
10295
10296 begin
10297 GNAT_Pragma;
10298 S14_Pragma;
10299 Check_Arg_Count (1);
10300
10301 -- Ensure the proper placement of the pragma. Global must be
10302 -- associated with a subprogram declaration.
10303
10304 Subp := Parent (Corresponding_Aspect (N));
10305
10306 if Nkind (Subp) /= N_Subprogram_Declaration then
10307 Pragma_Misplaced;
10308 return;
10309 end if;
10310
10311 Subp_Id := Defining_Unit_Name (Specification (Subp));
10312 List := Expression (Arg1);
10313
10314 -- There is nothing to be done for a null global list
10315
10316 if Nkind (List) = N_Null then
10317 null;
10318
10319 -- Analyze the various forms of global lists and items. Note that
10320 -- some of these may be malformed in which case the analysis emits
10321 -- error messages.
10322
10323 else
10324 -- Ensure that the formal parameters are visible when
10325 -- processing an item. This falls out of the general rule of
10326 -- aspects pertaining to subprogram declarations.
10327
10328 Push_Scope (Subp_Id);
10329 Install_Formals (Subp_Id);
10330
10331 Analyze_Global_List (List);
10332
10333 Pop_Scope;
10334 end if;
10335 end Global;
10336
10337 -----------
10338 -- Ident --
10339 -----------
10340
10341 -- pragma Ident (static_string_EXPRESSION)
10342
10343 -- Note: pragma Comment shares this processing. Pragma Comment is
10344 -- identical to Ident, except that the restriction of the argument to
10345 -- 31 characters and the placement restrictions are not enforced for
10346 -- pragma Comment.
10347
10348 when Pragma_Ident | Pragma_Comment => Ident : declare
10349 Str : Node_Id;
10350
10351 begin
10352 GNAT_Pragma;
10353 Check_Arg_Count (1);
10354 Check_No_Identifiers;
10355 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10356 Store_Note (N);
10357
10358 -- For pragma Ident, preserve DEC compatibility by requiring the
10359 -- pragma to appear in a declarative part or package spec.
10360
10361 if Prag_Id = Pragma_Ident then
10362 Check_Is_In_Decl_Part_Or_Package_Spec;
10363 end if;
10364
10365 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
10366
10367 declare
10368 CS : Node_Id;
10369 GP : Node_Id;
10370
10371 begin
10372 GP := Parent (Parent (N));
10373
10374 if Nkind_In (GP, N_Package_Declaration,
10375 N_Generic_Package_Declaration)
10376 then
10377 GP := Parent (GP);
10378 end if;
10379
10380 -- If we have a compilation unit, then record the ident value,
10381 -- checking for improper duplication.
10382
10383 if Nkind (GP) = N_Compilation_Unit then
10384 CS := Ident_String (Current_Sem_Unit);
10385
10386 if Present (CS) then
10387
10388 -- For Ident, we do not permit multiple instances
10389
10390 if Prag_Id = Pragma_Ident then
10391 Error_Pragma ("duplicate% pragma not permitted");
10392
10393 -- For Comment, we concatenate the string, unless we want
10394 -- to preserve the tree structure for ASIS.
10395
10396 elsif not ASIS_Mode then
10397 Start_String (Strval (CS));
10398 Store_String_Char (' ');
10399 Store_String_Chars (Strval (Str));
10400 Set_Strval (CS, End_String);
10401 end if;
10402
10403 else
10404 -- In VMS, the effect of IDENT is achieved by passing
10405 -- --identification=name as a --for-linker switch.
10406
10407 if OpenVMS_On_Target then
10408 Start_String;
10409 Store_String_Chars
10410 ("--for-linker=--identification=");
10411 String_To_Name_Buffer (Strval (Str));
10412 Store_String_Chars (Name_Buffer (1 .. Name_Len));
10413
10414 -- Only the last processed IDENT is saved. The main
10415 -- purpose is so an IDENT associated with a main
10416 -- procedure will be used in preference to an IDENT
10417 -- associated with a with'd package.
10418
10419 Replace_Linker_Option_String
10420 (End_String, "--for-linker=--identification=");
10421 end if;
10422
10423 Set_Ident_String (Current_Sem_Unit, Str);
10424 end if;
10425
10426 -- For subunits, we just ignore the Ident, since in GNAT these
10427 -- are not separate object files, and hence not separate units
10428 -- in the unit table.
10429
10430 elsif Nkind (GP) = N_Subunit then
10431 null;
10432
10433 -- Otherwise we have a misplaced pragma Ident, but we ignore
10434 -- this if we are in an instantiation, since it comes from
10435 -- a generic, and has no relevance to the instantiation.
10436
10437 elsif Prag_Id = Pragma_Ident then
10438 if Instantiation_Location (Loc) = No_Location then
10439 Error_Pragma ("pragma% only allowed at outer level");
10440 end if;
10441 end if;
10442 end;
10443 end Ident;
10444
10445 ----------------------------
10446 -- Implementation_Defined --
10447 ----------------------------
10448
10449 -- pragma Implementation_Defined (local_NAME);
10450
10451 -- Marks previously declared entity as implementation defined. For
10452 -- an overloaded entity, applies to the most recent homonym.
10453
10454 -- pragma Implementation_Defined;
10455
10456 -- The form with no arguments appears anywhere within a scope, most
10457 -- typically a package spec, and indicates that all entities that are
10458 -- defined within the package spec are Implementation_Defined.
10459
10460 when Pragma_Implementation_Defined => Implementation_Defined : declare
10461 Ent : Entity_Id;
10462
10463 begin
10464 Check_No_Identifiers;
10465
10466 -- Form with no arguments
10467
10468 if Arg_Count = 0 then
10469 Set_Is_Implementation_Defined (Current_Scope);
10470
10471 -- Form with one argument
10472
10473 else
10474 Check_Arg_Count (1);
10475 Check_Arg_Is_Local_Name (Arg1);
10476 Ent := Entity (Get_Pragma_Arg (Arg1));
10477 Set_Is_Implementation_Defined (Ent);
10478 end if;
10479 end Implementation_Defined;
10480
10481 -----------------
10482 -- Implemented --
10483 -----------------
10484
10485 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
10486
10487 -- IMPLEMENTATION_KIND ::=
10488 -- By_Entry | By_Protected_Procedure | By_Any | Optional
10489
10490 -- "By_Any" and "Optional" are treated as synonyms in order to
10491 -- support Ada 2012 aspect Synchronization.
10492
10493 when Pragma_Implemented => Implemented : declare
10494 Proc_Id : Entity_Id;
10495 Typ : Entity_Id;
10496
10497 begin
10498 Ada_2012_Pragma;
10499 Check_Arg_Count (2);
10500 Check_No_Identifiers;
10501 Check_Arg_Is_Identifier (Arg1);
10502 Check_Arg_Is_Local_Name (Arg1);
10503 Check_Arg_Is_One_Of (Arg2,
10504 Name_By_Any,
10505 Name_By_Entry,
10506 Name_By_Protected_Procedure,
10507 Name_Optional);
10508
10509 -- Extract the name of the local procedure
10510
10511 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
10512
10513 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
10514 -- primitive procedure of a synchronized tagged type.
10515
10516 if Ekind (Proc_Id) = E_Procedure
10517 and then Is_Primitive (Proc_Id)
10518 and then Present (First_Formal (Proc_Id))
10519 then
10520 Typ := Etype (First_Formal (Proc_Id));
10521
10522 if Is_Tagged_Type (Typ)
10523 and then
10524
10525 -- Check for a protected, a synchronized or a task interface
10526
10527 ((Is_Interface (Typ)
10528 and then Is_Synchronized_Interface (Typ))
10529
10530 -- Check for a protected type or a task type that implements
10531 -- an interface.
10532
10533 or else
10534 (Is_Concurrent_Record_Type (Typ)
10535 and then Present (Interfaces (Typ)))
10536
10537 -- Check for a private record extension with keyword
10538 -- "synchronized".
10539
10540 or else
10541 (Ekind_In (Typ, E_Record_Type_With_Private,
10542 E_Record_Subtype_With_Private)
10543 and then Synchronized_Present (Parent (Typ))))
10544 then
10545 null;
10546 else
10547 Error_Pragma_Arg
10548 ("controlling formal must be of synchronized " &
10549 "tagged type", Arg1);
10550 return;
10551 end if;
10552
10553 -- Procedures declared inside a protected type must be accepted
10554
10555 elsif Ekind (Proc_Id) = E_Procedure
10556 and then Is_Protected_Type (Scope (Proc_Id))
10557 then
10558 null;
10559
10560 -- The first argument is not a primitive procedure
10561
10562 else
10563 Error_Pragma_Arg
10564 ("pragma % must be applied to a primitive procedure", Arg1);
10565 return;
10566 end if;
10567
10568 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
10569 -- By_Protected_Procedure to the primitive procedure of a task
10570 -- interface.
10571
10572 if Chars (Arg2) = Name_By_Protected_Procedure
10573 and then Is_Interface (Typ)
10574 and then Is_Task_Interface (Typ)
10575 then
10576 Error_Pragma_Arg
10577 ("implementation kind By_Protected_Procedure cannot be " &
10578 "applied to a task interface primitive", Arg2);
10579 return;
10580 end if;
10581
10582 Record_Rep_Item (Proc_Id, N);
10583 end Implemented;
10584
10585 ----------------------
10586 -- Implicit_Packing --
10587 ----------------------
10588
10589 -- pragma Implicit_Packing;
10590
10591 when Pragma_Implicit_Packing =>
10592 GNAT_Pragma;
10593 Check_Arg_Count (0);
10594 Implicit_Packing := True;
10595
10596 ------------
10597 -- Import --
10598 ------------
10599
10600 -- pragma Import (
10601 -- [Convention =>] convention_IDENTIFIER,
10602 -- [Entity =>] local_NAME
10603 -- [, [External_Name =>] static_string_EXPRESSION ]
10604 -- [, [Link_Name =>] static_string_EXPRESSION ]);
10605
10606 when Pragma_Import =>
10607 Check_Ada_83_Warning;
10608 Check_Arg_Order
10609 ((Name_Convention,
10610 Name_Entity,
10611 Name_External_Name,
10612 Name_Link_Name));
10613
10614 Check_At_Least_N_Arguments (2);
10615 Check_At_Most_N_Arguments (4);
10616 Process_Import_Or_Interface;
10617
10618 ----------------------
10619 -- Import_Exception --
10620 ----------------------
10621
10622 -- pragma Import_Exception (
10623 -- [Internal =>] LOCAL_NAME
10624 -- [, [External =>] EXTERNAL_SYMBOL]
10625 -- [, [Form =>] Ada | VMS]
10626 -- [, [Code =>] static_integer_EXPRESSION]);
10627
10628 when Pragma_Import_Exception => Import_Exception : declare
10629 Args : Args_List (1 .. 4);
10630 Names : constant Name_List (1 .. 4) := (
10631 Name_Internal,
10632 Name_External,
10633 Name_Form,
10634 Name_Code);
10635
10636 Internal : Node_Id renames Args (1);
10637 External : Node_Id renames Args (2);
10638 Form : Node_Id renames Args (3);
10639 Code : Node_Id renames Args (4);
10640
10641 begin
10642 GNAT_Pragma;
10643 Gather_Associations (Names, Args);
10644
10645 if Present (External) and then Present (Code) then
10646 Error_Pragma
10647 ("cannot give both External and Code options for pragma%");
10648 end if;
10649
10650 Process_Extended_Import_Export_Exception_Pragma (
10651 Arg_Internal => Internal,
10652 Arg_External => External,
10653 Arg_Form => Form,
10654 Arg_Code => Code);
10655
10656 if not Is_VMS_Exception (Entity (Internal)) then
10657 Set_Imported (Entity (Internal));
10658 end if;
10659 end Import_Exception;
10660
10661 ---------------------
10662 -- Import_Function --
10663 ---------------------
10664
10665 -- pragma Import_Function (
10666 -- [Internal =>] LOCAL_NAME,
10667 -- [, [External =>] EXTERNAL_SYMBOL]
10668 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10669 -- [, [Result_Type =>] SUBTYPE_MARK]
10670 -- [, [Mechanism =>] MECHANISM]
10671 -- [, [Result_Mechanism =>] MECHANISM_NAME]
10672 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
10673
10674 -- EXTERNAL_SYMBOL ::=
10675 -- IDENTIFIER
10676 -- | static_string_EXPRESSION
10677
10678 -- PARAMETER_TYPES ::=
10679 -- null
10680 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10681
10682 -- TYPE_DESIGNATOR ::=
10683 -- subtype_NAME
10684 -- | subtype_Name ' Access
10685
10686 -- MECHANISM ::=
10687 -- MECHANISM_NAME
10688 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10689
10690 -- MECHANISM_ASSOCIATION ::=
10691 -- [formal_parameter_NAME =>] MECHANISM_NAME
10692
10693 -- MECHANISM_NAME ::=
10694 -- Value
10695 -- | Reference
10696 -- | Descriptor [([Class =>] CLASS_NAME)]
10697
10698 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10699
10700 when Pragma_Import_Function => Import_Function : declare
10701 Args : Args_List (1 .. 7);
10702 Names : constant Name_List (1 .. 7) := (
10703 Name_Internal,
10704 Name_External,
10705 Name_Parameter_Types,
10706 Name_Result_Type,
10707 Name_Mechanism,
10708 Name_Result_Mechanism,
10709 Name_First_Optional_Parameter);
10710
10711 Internal : Node_Id renames Args (1);
10712 External : Node_Id renames Args (2);
10713 Parameter_Types : Node_Id renames Args (3);
10714 Result_Type : Node_Id renames Args (4);
10715 Mechanism : Node_Id renames Args (5);
10716 Result_Mechanism : Node_Id renames Args (6);
10717 First_Optional_Parameter : Node_Id renames Args (7);
10718
10719 begin
10720 GNAT_Pragma;
10721 Gather_Associations (Names, Args);
10722 Process_Extended_Import_Export_Subprogram_Pragma (
10723 Arg_Internal => Internal,
10724 Arg_External => External,
10725 Arg_Parameter_Types => Parameter_Types,
10726 Arg_Result_Type => Result_Type,
10727 Arg_Mechanism => Mechanism,
10728 Arg_Result_Mechanism => Result_Mechanism,
10729 Arg_First_Optional_Parameter => First_Optional_Parameter);
10730 end Import_Function;
10731
10732 -------------------
10733 -- Import_Object --
10734 -------------------
10735
10736 -- pragma Import_Object (
10737 -- [Internal =>] LOCAL_NAME
10738 -- [, [External =>] EXTERNAL_SYMBOL]
10739 -- [, [Size =>] EXTERNAL_SYMBOL]);
10740
10741 -- EXTERNAL_SYMBOL ::=
10742 -- IDENTIFIER
10743 -- | static_string_EXPRESSION
10744
10745 when Pragma_Import_Object => Import_Object : declare
10746 Args : Args_List (1 .. 3);
10747 Names : constant Name_List (1 .. 3) := (
10748 Name_Internal,
10749 Name_External,
10750 Name_Size);
10751
10752 Internal : Node_Id renames Args (1);
10753 External : Node_Id renames Args (2);
10754 Size : Node_Id renames Args (3);
10755
10756 begin
10757 GNAT_Pragma;
10758 Gather_Associations (Names, Args);
10759 Process_Extended_Import_Export_Object_Pragma (
10760 Arg_Internal => Internal,
10761 Arg_External => External,
10762 Arg_Size => Size);
10763 end Import_Object;
10764
10765 ----------------------
10766 -- Import_Procedure --
10767 ----------------------
10768
10769 -- pragma Import_Procedure (
10770 -- [Internal =>] LOCAL_NAME
10771 -- [, [External =>] EXTERNAL_SYMBOL]
10772 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10773 -- [, [Mechanism =>] MECHANISM]
10774 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
10775
10776 -- EXTERNAL_SYMBOL ::=
10777 -- IDENTIFIER
10778 -- | static_string_EXPRESSION
10779
10780 -- PARAMETER_TYPES ::=
10781 -- null
10782 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10783
10784 -- TYPE_DESIGNATOR ::=
10785 -- subtype_NAME
10786 -- | subtype_Name ' Access
10787
10788 -- MECHANISM ::=
10789 -- MECHANISM_NAME
10790 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10791
10792 -- MECHANISM_ASSOCIATION ::=
10793 -- [formal_parameter_NAME =>] MECHANISM_NAME
10794
10795 -- MECHANISM_NAME ::=
10796 -- Value
10797 -- | Reference
10798 -- | Descriptor [([Class =>] CLASS_NAME)]
10799
10800 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10801
10802 when Pragma_Import_Procedure => Import_Procedure : declare
10803 Args : Args_List (1 .. 5);
10804 Names : constant Name_List (1 .. 5) := (
10805 Name_Internal,
10806 Name_External,
10807 Name_Parameter_Types,
10808 Name_Mechanism,
10809 Name_First_Optional_Parameter);
10810
10811 Internal : Node_Id renames Args (1);
10812 External : Node_Id renames Args (2);
10813 Parameter_Types : Node_Id renames Args (3);
10814 Mechanism : Node_Id renames Args (4);
10815 First_Optional_Parameter : Node_Id renames Args (5);
10816
10817 begin
10818 GNAT_Pragma;
10819 Gather_Associations (Names, Args);
10820 Process_Extended_Import_Export_Subprogram_Pragma (
10821 Arg_Internal => Internal,
10822 Arg_External => External,
10823 Arg_Parameter_Types => Parameter_Types,
10824 Arg_Mechanism => Mechanism,
10825 Arg_First_Optional_Parameter => First_Optional_Parameter);
10826 end Import_Procedure;
10827
10828 -----------------------------
10829 -- Import_Valued_Procedure --
10830 -----------------------------
10831
10832 -- pragma Import_Valued_Procedure (
10833 -- [Internal =>] LOCAL_NAME
10834 -- [, [External =>] EXTERNAL_SYMBOL]
10835 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10836 -- [, [Mechanism =>] MECHANISM]
10837 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
10838
10839 -- EXTERNAL_SYMBOL ::=
10840 -- IDENTIFIER
10841 -- | static_string_EXPRESSION
10842
10843 -- PARAMETER_TYPES ::=
10844 -- null
10845 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10846
10847 -- TYPE_DESIGNATOR ::=
10848 -- subtype_NAME
10849 -- | subtype_Name ' Access
10850
10851 -- MECHANISM ::=
10852 -- MECHANISM_NAME
10853 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10854
10855 -- MECHANISM_ASSOCIATION ::=
10856 -- [formal_parameter_NAME =>] MECHANISM_NAME
10857
10858 -- MECHANISM_NAME ::=
10859 -- Value
10860 -- | Reference
10861 -- | Descriptor [([Class =>] CLASS_NAME)]
10862
10863 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10864
10865 when Pragma_Import_Valued_Procedure =>
10866 Import_Valued_Procedure : declare
10867 Args : Args_List (1 .. 5);
10868 Names : constant Name_List (1 .. 5) := (
10869 Name_Internal,
10870 Name_External,
10871 Name_Parameter_Types,
10872 Name_Mechanism,
10873 Name_First_Optional_Parameter);
10874
10875 Internal : Node_Id renames Args (1);
10876 External : Node_Id renames Args (2);
10877 Parameter_Types : Node_Id renames Args (3);
10878 Mechanism : Node_Id renames Args (4);
10879 First_Optional_Parameter : Node_Id renames Args (5);
10880
10881 begin
10882 GNAT_Pragma;
10883 Gather_Associations (Names, Args);
10884 Process_Extended_Import_Export_Subprogram_Pragma (
10885 Arg_Internal => Internal,
10886 Arg_External => External,
10887 Arg_Parameter_Types => Parameter_Types,
10888 Arg_Mechanism => Mechanism,
10889 Arg_First_Optional_Parameter => First_Optional_Parameter);
10890 end Import_Valued_Procedure;
10891
10892 -----------------
10893 -- Independent --
10894 -----------------
10895
10896 -- pragma Independent (LOCAL_NAME);
10897
10898 when Pragma_Independent => Independent : declare
10899 E_Id : Node_Id;
10900 E : Entity_Id;
10901 D : Node_Id;
10902 K : Node_Kind;
10903
10904 begin
10905 Check_Ada_83_Warning;
10906 Ada_2012_Pragma;
10907 Check_No_Identifiers;
10908 Check_Arg_Count (1);
10909 Check_Arg_Is_Local_Name (Arg1);
10910 E_Id := Get_Pragma_Arg (Arg1);
10911
10912 if Etype (E_Id) = Any_Type then
10913 return;
10914 end if;
10915
10916 E := Entity (E_Id);
10917 D := Declaration_Node (E);
10918 K := Nkind (D);
10919
10920 -- Check duplicate before we chain ourselves!
10921
10922 Check_Duplicate_Pragma (E);
10923
10924 -- Check appropriate entity
10925
10926 if Is_Type (E) then
10927 if Rep_Item_Too_Early (E, N)
10928 or else
10929 Rep_Item_Too_Late (E, N)
10930 then
10931 return;
10932 else
10933 Check_First_Subtype (Arg1);
10934 end if;
10935
10936 elsif K = N_Object_Declaration
10937 or else (K = N_Component_Declaration
10938 and then Original_Record_Component (E) = E)
10939 then
10940 if Rep_Item_Too_Late (E, N) then
10941 return;
10942 end if;
10943
10944 else
10945 Error_Pragma_Arg
10946 ("inappropriate entity for pragma%", Arg1);
10947 end if;
10948
10949 Independence_Checks.Append ((N, E));
10950 end Independent;
10951
10952 ----------------------------
10953 -- Independent_Components --
10954 ----------------------------
10955
10956 -- pragma Atomic_Components (array_LOCAL_NAME);
10957
10958 -- This processing is shared by Volatile_Components
10959
10960 when Pragma_Independent_Components => Independent_Components : declare
10961 E_Id : Node_Id;
10962 E : Entity_Id;
10963 D : Node_Id;
10964 K : Node_Kind;
10965
10966 begin
10967 Check_Ada_83_Warning;
10968 Ada_2012_Pragma;
10969 Check_No_Identifiers;
10970 Check_Arg_Count (1);
10971 Check_Arg_Is_Local_Name (Arg1);
10972 E_Id := Get_Pragma_Arg (Arg1);
10973
10974 if Etype (E_Id) = Any_Type then
10975 return;
10976 end if;
10977
10978 E := Entity (E_Id);
10979
10980 -- Check duplicate before we chain ourselves!
10981
10982 Check_Duplicate_Pragma (E);
10983
10984 -- Check appropriate entity
10985
10986 if Rep_Item_Too_Early (E, N)
10987 or else
10988 Rep_Item_Too_Late (E, N)
10989 then
10990 return;
10991 end if;
10992
10993 D := Declaration_Node (E);
10994 K := Nkind (D);
10995
10996 if K = N_Full_Type_Declaration
10997 and then (Is_Array_Type (E) or else Is_Record_Type (E))
10998 then
10999 Independence_Checks.Append ((N, E));
11000 Set_Has_Independent_Components (Base_Type (E));
11001
11002 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
11003 and then Nkind (D) = N_Object_Declaration
11004 and then Nkind (Object_Definition (D)) =
11005 N_Constrained_Array_Definition
11006 then
11007 Independence_Checks.Append ((N, E));
11008 Set_Has_Independent_Components (E);
11009
11010 else
11011 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
11012 end if;
11013 end Independent_Components;
11014
11015 ------------------------
11016 -- Initialize_Scalars --
11017 ------------------------
11018
11019 -- pragma Initialize_Scalars;
11020
11021 when Pragma_Initialize_Scalars =>
11022 GNAT_Pragma;
11023 Check_Arg_Count (0);
11024 Check_Valid_Configuration_Pragma;
11025 Check_Restriction (No_Initialize_Scalars, N);
11026
11027 -- Initialize_Scalars creates false positives in CodePeer, and
11028 -- incorrect negative results in Alfa mode, so ignore this pragma
11029 -- in these modes.
11030
11031 if not Restriction_Active (No_Initialize_Scalars)
11032 and then not (CodePeer_Mode or Alfa_Mode)
11033 then
11034 Init_Or_Norm_Scalars := True;
11035 Initialize_Scalars := True;
11036 end if;
11037
11038 ------------
11039 -- Inline --
11040 ------------
11041
11042 -- pragma Inline ( NAME {, NAME} );
11043
11044 when Pragma_Inline =>
11045
11046 -- Pragma is active if inlining option is active
11047
11048 Process_Inline (Inline_Active);
11049
11050 -------------------
11051 -- Inline_Always --
11052 -------------------
11053
11054 -- pragma Inline_Always ( NAME {, NAME} );
11055
11056 when Pragma_Inline_Always =>
11057 GNAT_Pragma;
11058
11059 -- Pragma always active unless in CodePeer or Alfa mode, since
11060 -- this causes walk order issues.
11061
11062 if not (CodePeer_Mode or Alfa_Mode) then
11063 Process_Inline (True);
11064 end if;
11065
11066 --------------------
11067 -- Inline_Generic --
11068 --------------------
11069
11070 -- pragma Inline_Generic (NAME {, NAME});
11071
11072 when Pragma_Inline_Generic =>
11073 GNAT_Pragma;
11074 Process_Generic_List;
11075
11076 ----------------------
11077 -- Inspection_Point --
11078 ----------------------
11079
11080 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
11081
11082 when Pragma_Inspection_Point => Inspection_Point : declare
11083 Arg : Node_Id;
11084 Exp : Node_Id;
11085
11086 begin
11087 if Arg_Count > 0 then
11088 Arg := Arg1;
11089 loop
11090 Exp := Get_Pragma_Arg (Arg);
11091 Analyze (Exp);
11092
11093 if not Is_Entity_Name (Exp)
11094 or else not Is_Object (Entity (Exp))
11095 then
11096 Error_Pragma_Arg ("object name required", Arg);
11097 end if;
11098
11099 Next (Arg);
11100 exit when No (Arg);
11101 end loop;
11102 end if;
11103 end Inspection_Point;
11104
11105 ---------------
11106 -- Interface --
11107 ---------------
11108
11109 -- pragma Interface (
11110 -- [ Convention =>] convention_IDENTIFIER,
11111 -- [ Entity =>] local_NAME
11112 -- [, [External_Name =>] static_string_EXPRESSION ]
11113 -- [, [Link_Name =>] static_string_EXPRESSION ]);
11114
11115 when Pragma_Interface =>
11116 GNAT_Pragma;
11117 Check_Arg_Order
11118 ((Name_Convention,
11119 Name_Entity,
11120 Name_External_Name,
11121 Name_Link_Name));
11122 Check_At_Least_N_Arguments (2);
11123 Check_At_Most_N_Arguments (4);
11124 Process_Import_Or_Interface;
11125
11126 -- In Ada 2005, the permission to use Interface (a reserved word)
11127 -- as a pragma name is considered an obsolescent feature, and this
11128 -- pragma was already obsolescent in Ada 95.
11129
11130 if Ada_Version >= Ada_95 then
11131 Check_Restriction
11132 (No_Obsolescent_Features, Pragma_Identifier (N));
11133
11134 if Warn_On_Obsolescent_Feature then
11135 Error_Msg_N
11136 ("pragma Interface is an obsolescent feature?j?", N);
11137 Error_Msg_N
11138 ("|use pragma Import instead?j?", N);
11139 end if;
11140 end if;
11141
11142 --------------------
11143 -- Interface_Name --
11144 --------------------
11145
11146 -- pragma Interface_Name (
11147 -- [ Entity =>] local_NAME
11148 -- [,[External_Name =>] static_string_EXPRESSION ]
11149 -- [,[Link_Name =>] static_string_EXPRESSION ]);
11150
11151 when Pragma_Interface_Name => Interface_Name : declare
11152 Id : Node_Id;
11153 Def_Id : Entity_Id;
11154 Hom_Id : Entity_Id;
11155 Found : Boolean;
11156
11157 begin
11158 GNAT_Pragma;
11159 Check_Arg_Order
11160 ((Name_Entity, Name_External_Name, Name_Link_Name));
11161 Check_At_Least_N_Arguments (2);
11162 Check_At_Most_N_Arguments (3);
11163 Id := Get_Pragma_Arg (Arg1);
11164 Analyze (Id);
11165
11166 -- This is obsolete from Ada 95 on, but it is an implementation
11167 -- defined pragma, so we do not consider that it violates the
11168 -- restriction (No_Obsolescent_Features).
11169
11170 if Ada_Version >= Ada_95 then
11171 if Warn_On_Obsolescent_Feature then
11172 Error_Msg_N
11173 ("pragma Interface_Name is an obsolescent feature?j?", N);
11174 Error_Msg_N
11175 ("|use pragma Import instead?j?", N);
11176 end if;
11177 end if;
11178
11179 if not Is_Entity_Name (Id) then
11180 Error_Pragma_Arg
11181 ("first argument for pragma% must be entity name", Arg1);
11182 elsif Etype (Id) = Any_Type then
11183 return;
11184 else
11185 Def_Id := Entity (Id);
11186 end if;
11187
11188 -- Special DEC-compatible processing for the object case, forces
11189 -- object to be imported.
11190
11191 if Ekind (Def_Id) = E_Variable then
11192 Kill_Size_Check_Code (Def_Id);
11193 Note_Possible_Modification (Id, Sure => False);
11194
11195 -- Initialization is not allowed for imported variable
11196
11197 if Present (Expression (Parent (Def_Id)))
11198 and then Comes_From_Source (Expression (Parent (Def_Id)))
11199 then
11200 Error_Msg_Sloc := Sloc (Def_Id);
11201 Error_Pragma_Arg
11202 ("no initialization allowed for declaration of& #",
11203 Arg2);
11204
11205 else
11206 -- For compatibility, support VADS usage of providing both
11207 -- pragmas Interface and Interface_Name to obtain the effect
11208 -- of a single Import pragma.
11209
11210 if Is_Imported (Def_Id)
11211 and then Present (First_Rep_Item (Def_Id))
11212 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
11213 and then
11214 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
11215 then
11216 null;
11217 else
11218 Set_Imported (Def_Id);
11219 end if;
11220
11221 Set_Is_Public (Def_Id);
11222 Process_Interface_Name (Def_Id, Arg2, Arg3);
11223 end if;
11224
11225 -- Otherwise must be subprogram
11226
11227 elsif not Is_Subprogram (Def_Id) then
11228 Error_Pragma_Arg
11229 ("argument of pragma% is not subprogram", Arg1);
11230
11231 else
11232 Check_At_Most_N_Arguments (3);
11233 Hom_Id := Def_Id;
11234 Found := False;
11235
11236 -- Loop through homonyms
11237
11238 loop
11239 Def_Id := Get_Base_Subprogram (Hom_Id);
11240
11241 if Is_Imported (Def_Id) then
11242 Process_Interface_Name (Def_Id, Arg2, Arg3);
11243 Found := True;
11244 end if;
11245
11246 exit when From_Aspect_Specification (N);
11247 Hom_Id := Homonym (Hom_Id);
11248
11249 exit when No (Hom_Id)
11250 or else Scope (Hom_Id) /= Current_Scope;
11251 end loop;
11252
11253 if not Found then
11254 Error_Pragma_Arg
11255 ("argument of pragma% is not imported subprogram",
11256 Arg1);
11257 end if;
11258 end if;
11259 end Interface_Name;
11260
11261 -----------------------
11262 -- Interrupt_Handler --
11263 -----------------------
11264
11265 -- pragma Interrupt_Handler (handler_NAME);
11266
11267 when Pragma_Interrupt_Handler =>
11268 Check_Ada_83_Warning;
11269 Check_Arg_Count (1);
11270 Check_No_Identifiers;
11271
11272 if No_Run_Time_Mode then
11273 Error_Msg_CRT ("Interrupt_Handler pragma", N);
11274 else
11275 Check_Interrupt_Or_Attach_Handler;
11276 Process_Interrupt_Or_Attach_Handler;
11277 end if;
11278
11279 ------------------------
11280 -- Interrupt_Priority --
11281 ------------------------
11282
11283 -- pragma Interrupt_Priority [(EXPRESSION)];
11284
11285 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
11286 P : constant Node_Id := Parent (N);
11287 Arg : Node_Id;
11288 Ent : Entity_Id;
11289
11290 begin
11291 Check_Ada_83_Warning;
11292
11293 if Arg_Count /= 0 then
11294 Arg := Get_Pragma_Arg (Arg1);
11295 Check_Arg_Count (1);
11296 Check_No_Identifiers;
11297
11298 -- The expression must be analyzed in the special manner
11299 -- described in "Handling of Default and Per-Object
11300 -- Expressions" in sem.ads.
11301
11302 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
11303 end if;
11304
11305 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
11306 Pragma_Misplaced;
11307 return;
11308
11309 else
11310 Ent := Defining_Identifier (Parent (P));
11311
11312 -- Check duplicate pragma before we chain the pragma in the Rep
11313 -- Item chain of Ent.
11314
11315 Check_Duplicate_Pragma (Ent);
11316 Record_Rep_Item (Ent, N);
11317 end if;
11318 end Interrupt_Priority;
11319
11320 ---------------------
11321 -- Interrupt_State --
11322 ---------------------
11323
11324 -- pragma Interrupt_State (
11325 -- [Name =>] INTERRUPT_ID,
11326 -- [State =>] INTERRUPT_STATE);
11327
11328 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
11329 -- INTERRUPT_STATE => System | Runtime | User
11330
11331 -- Note: if the interrupt id is given as an identifier, then it must
11332 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
11333 -- given as a static integer expression which must be in the range of
11334 -- Ada.Interrupts.Interrupt_ID.
11335
11336 when Pragma_Interrupt_State => Interrupt_State : declare
11337
11338 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
11339 -- This is the entity Ada.Interrupts.Interrupt_ID;
11340
11341 State_Type : Character;
11342 -- Set to 's'/'r'/'u' for System/Runtime/User
11343
11344 IST_Num : Pos;
11345 -- Index to entry in Interrupt_States table
11346
11347 Int_Val : Uint;
11348 -- Value of interrupt
11349
11350 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
11351 -- The first argument to the pragma
11352
11353 Int_Ent : Entity_Id;
11354 -- Interrupt entity in Ada.Interrupts.Names
11355
11356 begin
11357 GNAT_Pragma;
11358 Check_Arg_Order ((Name_Name, Name_State));
11359 Check_Arg_Count (2);
11360
11361 Check_Optional_Identifier (Arg1, Name_Name);
11362 Check_Optional_Identifier (Arg2, Name_State);
11363 Check_Arg_Is_Identifier (Arg2);
11364
11365 -- First argument is identifier
11366
11367 if Nkind (Arg1X) = N_Identifier then
11368
11369 -- Search list of names in Ada.Interrupts.Names
11370
11371 Int_Ent := First_Entity (RTE (RE_Names));
11372 loop
11373 if No (Int_Ent) then
11374 Error_Pragma_Arg ("invalid interrupt name", Arg1);
11375
11376 elsif Chars (Int_Ent) = Chars (Arg1X) then
11377 Int_Val := Expr_Value (Constant_Value (Int_Ent));
11378 exit;
11379 end if;
11380
11381 Next_Entity (Int_Ent);
11382 end loop;
11383
11384 -- First argument is not an identifier, so it must be a static
11385 -- expression of type Ada.Interrupts.Interrupt_ID.
11386
11387 else
11388 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
11389 Int_Val := Expr_Value (Arg1X);
11390
11391 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
11392 or else
11393 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
11394 then
11395 Error_Pragma_Arg
11396 ("value not in range of type " &
11397 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
11398 end if;
11399 end if;
11400
11401 -- Check OK state
11402
11403 case Chars (Get_Pragma_Arg (Arg2)) is
11404 when Name_Runtime => State_Type := 'r';
11405 when Name_System => State_Type := 's';
11406 when Name_User => State_Type := 'u';
11407
11408 when others =>
11409 Error_Pragma_Arg ("invalid interrupt state", Arg2);
11410 end case;
11411
11412 -- Check if entry is already stored
11413
11414 IST_Num := Interrupt_States.First;
11415 loop
11416 -- If entry not found, add it
11417
11418 if IST_Num > Interrupt_States.Last then
11419 Interrupt_States.Append
11420 ((Interrupt_Number => UI_To_Int (Int_Val),
11421 Interrupt_State => State_Type,
11422 Pragma_Loc => Loc));
11423 exit;
11424
11425 -- Case of entry for the same entry
11426
11427 elsif Int_Val = Interrupt_States.Table (IST_Num).
11428 Interrupt_Number
11429 then
11430 -- If state matches, done, no need to make redundant entry
11431
11432 exit when
11433 State_Type = Interrupt_States.Table (IST_Num).
11434 Interrupt_State;
11435
11436 -- Otherwise if state does not match, error
11437
11438 Error_Msg_Sloc :=
11439 Interrupt_States.Table (IST_Num).Pragma_Loc;
11440 Error_Pragma_Arg
11441 ("state conflicts with that given #", Arg2);
11442 exit;
11443 end if;
11444
11445 IST_Num := IST_Num + 1;
11446 end loop;
11447 end Interrupt_State;
11448
11449 ---------------
11450 -- Invariant --
11451 ---------------
11452
11453 -- pragma Invariant
11454 -- ([Entity =>] type_LOCAL_NAME,
11455 -- [Check =>] EXPRESSION
11456 -- [,[Message =>] String_Expression]);
11457
11458 when Pragma_Invariant => Invariant : declare
11459 Type_Id : Node_Id;
11460 Typ : Entity_Id;
11461 PDecl : Node_Id;
11462
11463 Discard : Boolean;
11464 pragma Unreferenced (Discard);
11465
11466 begin
11467 GNAT_Pragma;
11468 Check_At_Least_N_Arguments (2);
11469 Check_At_Most_N_Arguments (3);
11470 Check_Optional_Identifier (Arg1, Name_Entity);
11471 Check_Optional_Identifier (Arg2, Name_Check);
11472
11473 if Arg_Count = 3 then
11474 Check_Optional_Identifier (Arg3, Name_Message);
11475 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
11476 end if;
11477
11478 Check_Arg_Is_Local_Name (Arg1);
11479
11480 Type_Id := Get_Pragma_Arg (Arg1);
11481 Find_Type (Type_Id);
11482 Typ := Entity (Type_Id);
11483
11484 if Typ = Any_Type then
11485 return;
11486
11487 -- An invariant must apply to a private type, or appear in the
11488 -- private part of a package spec and apply to a completion.
11489
11490 elsif Ekind_In (Typ, E_Private_Type,
11491 E_Record_Type_With_Private,
11492 E_Limited_Private_Type)
11493 then
11494 null;
11495
11496 elsif In_Private_Part (Current_Scope)
11497 and then Has_Private_Declaration (Typ)
11498 then
11499 null;
11500
11501 elsif In_Private_Part (Current_Scope) then
11502 Error_Pragma_Arg
11503 ("pragma% only allowed for private type " &
11504 "declared in visible part", Arg1);
11505
11506 else
11507 Error_Pragma_Arg
11508 ("pragma% only allowed for private type", Arg1);
11509 end if;
11510
11511 -- Note that the type has at least one invariant, and also that
11512 -- it has inheritable invariants if we have Invariant'Class.
11513 -- Build the corresponding invariant procedure declaration, so
11514 -- that calls to it can be generated before the body is built
11515 -- (for example wihin an expression function).
11516
11517 PDecl := Build_Invariant_Procedure_Declaration (Typ);
11518 Insert_After (N, PDecl);
11519 Analyze (PDecl);
11520
11521 if Class_Present (N) then
11522 Set_Has_Inheritable_Invariants (Typ);
11523 end if;
11524
11525 -- The remaining processing is simply to link the pragma on to
11526 -- the rep item chain, for processing when the type is frozen.
11527 -- This is accomplished by a call to Rep_Item_Too_Late.
11528
11529 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11530 end Invariant;
11531
11532 ----------------------
11533 -- Java_Constructor --
11534 ----------------------
11535
11536 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
11537
11538 -- Also handles pragma CIL_Constructor
11539
11540 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
11541 Java_Constructor : declare
11542 Convention : Convention_Id;
11543 Def_Id : Entity_Id;
11544 Hom_Id : Entity_Id;
11545 Id : Entity_Id;
11546 This_Formal : Entity_Id;
11547
11548 begin
11549 GNAT_Pragma;
11550 Check_Arg_Count (1);
11551 Check_Optional_Identifier (Arg1, Name_Entity);
11552 Check_Arg_Is_Local_Name (Arg1);
11553
11554 Id := Get_Pragma_Arg (Arg1);
11555 Find_Program_Unit_Name (Id);
11556
11557 -- If we did not find the name, we are done
11558
11559 if Etype (Id) = Any_Type then
11560 return;
11561 end if;
11562
11563 -- Check wrong use of pragma in wrong VM target
11564
11565 if VM_Target = No_VM then
11566 return;
11567
11568 elsif VM_Target = CLI_Target
11569 and then Prag_Id = Pragma_Java_Constructor
11570 then
11571 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
11572
11573 elsif VM_Target = JVM_Target
11574 and then Prag_Id = Pragma_CIL_Constructor
11575 then
11576 Error_Pragma ("must use pragma 'Java_'Constructor");
11577 end if;
11578
11579 case Prag_Id is
11580 when Pragma_CIL_Constructor => Convention := Convention_CIL;
11581 when Pragma_Java_Constructor => Convention := Convention_Java;
11582 when others => null;
11583 end case;
11584
11585 Hom_Id := Entity (Id);
11586
11587 -- Loop through homonyms
11588
11589 loop
11590 Def_Id := Get_Base_Subprogram (Hom_Id);
11591
11592 -- The constructor is required to be a function
11593
11594 if Ekind (Def_Id) /= E_Function then
11595 if VM_Target = JVM_Target then
11596 Error_Pragma_Arg
11597 ("pragma% requires function returning a " &
11598 "'Java access type", Def_Id);
11599 else
11600 Error_Pragma_Arg
11601 ("pragma% requires function returning a " &
11602 "'C'I'L access type", Def_Id);
11603 end if;
11604 end if;
11605
11606 -- Check arguments: For tagged type the first formal must be
11607 -- named "this" and its type must be a named access type
11608 -- designating a class-wide tagged type that has convention
11609 -- CIL/Java. The first formal must also have a null default
11610 -- value. For example:
11611
11612 -- type Typ is tagged ...
11613 -- type Ref is access all Typ;
11614 -- pragma Convention (CIL, Typ);
11615
11616 -- function New_Typ (This : Ref) return Ref;
11617 -- function New_Typ (This : Ref; I : Integer) return Ref;
11618 -- pragma Cil_Constructor (New_Typ);
11619
11620 -- Reason: The first formal must NOT be a primitive of the
11621 -- tagged type.
11622
11623 -- This rule also applies to constructors of delegates used
11624 -- to interface with standard target libraries. For example:
11625
11626 -- type Delegate is access procedure ...
11627 -- pragma Import (CIL, Delegate, ...);
11628
11629 -- function new_Delegate
11630 -- (This : Delegate := null; ... ) return Delegate;
11631
11632 -- For value-types this rule does not apply.
11633
11634 if not Is_Value_Type (Etype (Def_Id)) then
11635 if No (First_Formal (Def_Id)) then
11636 Error_Msg_Name_1 := Pname;
11637 Error_Msg_N ("% function must have parameters", Def_Id);
11638 return;
11639 end if;
11640
11641 -- In the JRE library we have several occurrences in which
11642 -- the "this" parameter is not the first formal.
11643
11644 This_Formal := First_Formal (Def_Id);
11645
11646 -- In the JRE library we have several occurrences in which
11647 -- the "this" parameter is not the first formal. Search for
11648 -- it.
11649
11650 if VM_Target = JVM_Target then
11651 while Present (This_Formal)
11652 and then Get_Name_String (Chars (This_Formal)) /= "this"
11653 loop
11654 Next_Formal (This_Formal);
11655 end loop;
11656
11657 if No (This_Formal) then
11658 This_Formal := First_Formal (Def_Id);
11659 end if;
11660 end if;
11661
11662 -- Warning: The first parameter should be named "this".
11663 -- We temporarily allow it because we have the following
11664 -- case in the Java runtime (file s-osinte.ads) ???
11665
11666 -- function new_Thread
11667 -- (Self_Id : System.Address) return Thread_Id;
11668 -- pragma Java_Constructor (new_Thread);
11669
11670 if VM_Target = JVM_Target
11671 and then Get_Name_String (Chars (First_Formal (Def_Id)))
11672 = "self_id"
11673 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
11674 then
11675 null;
11676
11677 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
11678 Error_Msg_Name_1 := Pname;
11679 Error_Msg_N
11680 ("first formal of % function must be named `this`",
11681 Parent (This_Formal));
11682
11683 elsif not Is_Access_Type (Etype (This_Formal)) then
11684 Error_Msg_Name_1 := Pname;
11685 Error_Msg_N
11686 ("first formal of % function must be an access type",
11687 Parameter_Type (Parent (This_Formal)));
11688
11689 -- For delegates the type of the first formal must be a
11690 -- named access-to-subprogram type (see previous example)
11691
11692 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
11693 and then Ekind (Etype (This_Formal))
11694 /= E_Access_Subprogram_Type
11695 then
11696 Error_Msg_Name_1 := Pname;
11697 Error_Msg_N
11698 ("first formal of % function must be a named access" &
11699 " to subprogram type",
11700 Parameter_Type (Parent (This_Formal)));
11701
11702 -- Warning: We should reject anonymous access types because
11703 -- the constructor must not be handled as a primitive of the
11704 -- tagged type. We temporarily allow it because this profile
11705 -- is currently generated by cil2ada???
11706
11707 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
11708 and then not Ekind_In (Etype (This_Formal),
11709 E_Access_Type,
11710 E_General_Access_Type,
11711 E_Anonymous_Access_Type)
11712 then
11713 Error_Msg_Name_1 := Pname;
11714 Error_Msg_N
11715 ("first formal of % function must be a named access" &
11716 " type",
11717 Parameter_Type (Parent (This_Formal)));
11718
11719 elsif Atree.Convention
11720 (Designated_Type (Etype (This_Formal))) /= Convention
11721 then
11722 Error_Msg_Name_1 := Pname;
11723
11724 if Convention = Convention_Java then
11725 Error_Msg_N
11726 ("pragma% requires convention 'Cil in designated" &
11727 " type",
11728 Parameter_Type (Parent (This_Formal)));
11729 else
11730 Error_Msg_N
11731 ("pragma% requires convention 'Java in designated" &
11732 " type",
11733 Parameter_Type (Parent (This_Formal)));
11734 end if;
11735
11736 elsif No (Expression (Parent (This_Formal)))
11737 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
11738 then
11739 Error_Msg_Name_1 := Pname;
11740 Error_Msg_N
11741 ("pragma% requires first formal with default `null`",
11742 Parameter_Type (Parent (This_Formal)));
11743 end if;
11744 end if;
11745
11746 -- Check result type: the constructor must be a function
11747 -- returning:
11748 -- * a value type (only allowed in the CIL compiler)
11749 -- * an access-to-subprogram type with convention Java/CIL
11750 -- * an access-type designating a type that has convention
11751 -- Java/CIL.
11752
11753 if Is_Value_Type (Etype (Def_Id)) then
11754 null;
11755
11756 -- Access-to-subprogram type with convention Java/CIL
11757
11758 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
11759 if Atree.Convention (Etype (Def_Id)) /= Convention then
11760 if Convention = Convention_Java then
11761 Error_Pragma_Arg
11762 ("pragma% requires function returning a " &
11763 "'Java access type", Arg1);
11764 else
11765 pragma Assert (Convention = Convention_CIL);
11766 Error_Pragma_Arg
11767 ("pragma% requires function returning a " &
11768 "'C'I'L access type", Arg1);
11769 end if;
11770 end if;
11771
11772 elsif Ekind (Etype (Def_Id)) in Access_Kind then
11773 if not Ekind_In (Etype (Def_Id), E_Access_Type,
11774 E_General_Access_Type)
11775 or else
11776 Atree.Convention
11777 (Designated_Type (Etype (Def_Id))) /= Convention
11778 then
11779 Error_Msg_Name_1 := Pname;
11780
11781 if Convention = Convention_Java then
11782 Error_Pragma_Arg
11783 ("pragma% requires function returning a named" &
11784 "'Java access type", Arg1);
11785 else
11786 Error_Pragma_Arg
11787 ("pragma% requires function returning a named" &
11788 "'C'I'L access type", Arg1);
11789 end if;
11790 end if;
11791 end if;
11792
11793 Set_Is_Constructor (Def_Id);
11794 Set_Convention (Def_Id, Convention);
11795 Set_Is_Imported (Def_Id);
11796
11797 exit when From_Aspect_Specification (N);
11798 Hom_Id := Homonym (Hom_Id);
11799
11800 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
11801 end loop;
11802 end Java_Constructor;
11803
11804 ----------------------
11805 -- Java_Interface --
11806 ----------------------
11807
11808 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
11809
11810 when Pragma_Java_Interface => Java_Interface : declare
11811 Arg : Node_Id;
11812 Typ : Entity_Id;
11813
11814 begin
11815 GNAT_Pragma;
11816 Check_Arg_Count (1);
11817 Check_Optional_Identifier (Arg1, Name_Entity);
11818 Check_Arg_Is_Local_Name (Arg1);
11819
11820 Arg := Get_Pragma_Arg (Arg1);
11821 Analyze (Arg);
11822
11823 if Etype (Arg) = Any_Type then
11824 return;
11825 end if;
11826
11827 if not Is_Entity_Name (Arg)
11828 or else not Is_Type (Entity (Arg))
11829 then
11830 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
11831 end if;
11832
11833 Typ := Underlying_Type (Entity (Arg));
11834
11835 -- For now simply check some of the semantic constraints on the
11836 -- type. This currently leaves out some restrictions on interface
11837 -- types, namely that the parent type must be java.lang.Object.Typ
11838 -- and that all primitives of the type should be declared
11839 -- abstract. ???
11840
11841 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
11842 Error_Pragma_Arg ("pragma% requires an abstract "
11843 & "tagged type", Arg1);
11844
11845 elsif not Has_Discriminants (Typ)
11846 or else Ekind (Etype (First_Discriminant (Typ)))
11847 /= E_Anonymous_Access_Type
11848 or else
11849 not Is_Class_Wide_Type
11850 (Designated_Type (Etype (First_Discriminant (Typ))))
11851 then
11852 Error_Pragma_Arg
11853 ("type must have a class-wide access discriminant", Arg1);
11854 end if;
11855 end Java_Interface;
11856
11857 ----------------
11858 -- Keep_Names --
11859 ----------------
11860
11861 -- pragma Keep_Names ([On => ] local_NAME);
11862
11863 when Pragma_Keep_Names => Keep_Names : declare
11864 Arg : Node_Id;
11865
11866 begin
11867 GNAT_Pragma;
11868 Check_Arg_Count (1);
11869 Check_Optional_Identifier (Arg1, Name_On);
11870 Check_Arg_Is_Local_Name (Arg1);
11871
11872 Arg := Get_Pragma_Arg (Arg1);
11873 Analyze (Arg);
11874
11875 if Etype (Arg) = Any_Type then
11876 return;
11877 end if;
11878
11879 if not Is_Entity_Name (Arg)
11880 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
11881 then
11882 Error_Pragma_Arg
11883 ("pragma% requires a local enumeration type", Arg1);
11884 end if;
11885
11886 Set_Discard_Names (Entity (Arg), False);
11887 end Keep_Names;
11888
11889 -------------
11890 -- License --
11891 -------------
11892
11893 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
11894
11895 when Pragma_License =>
11896 GNAT_Pragma;
11897 Check_Arg_Count (1);
11898 Check_No_Identifiers;
11899 Check_Valid_Configuration_Pragma;
11900 Check_Arg_Is_Identifier (Arg1);
11901
11902 declare
11903 Sind : constant Source_File_Index :=
11904 Source_Index (Current_Sem_Unit);
11905
11906 begin
11907 case Chars (Get_Pragma_Arg (Arg1)) is
11908 when Name_GPL =>
11909 Set_License (Sind, GPL);
11910
11911 when Name_Modified_GPL =>
11912 Set_License (Sind, Modified_GPL);
11913
11914 when Name_Restricted =>
11915 Set_License (Sind, Restricted);
11916
11917 when Name_Unrestricted =>
11918 Set_License (Sind, Unrestricted);
11919
11920 when others =>
11921 Error_Pragma_Arg ("invalid license name", Arg1);
11922 end case;
11923 end;
11924
11925 ---------------
11926 -- Link_With --
11927 ---------------
11928
11929 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
11930
11931 when Pragma_Link_With => Link_With : declare
11932 Arg : Node_Id;
11933
11934 begin
11935 GNAT_Pragma;
11936
11937 if Operating_Mode = Generate_Code
11938 and then In_Extended_Main_Source_Unit (N)
11939 then
11940 Check_At_Least_N_Arguments (1);
11941 Check_No_Identifiers;
11942 Check_Is_In_Decl_Part_Or_Package_Spec;
11943 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11944 Start_String;
11945
11946 Arg := Arg1;
11947 while Present (Arg) loop
11948 Check_Arg_Is_Static_Expression (Arg, Standard_String);
11949
11950 -- Store argument, converting sequences of spaces to a
11951 -- single null character (this is one of the differences
11952 -- in processing between Link_With and Linker_Options).
11953
11954 Arg_Store : declare
11955 C : constant Char_Code := Get_Char_Code (' ');
11956 S : constant String_Id :=
11957 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
11958 L : constant Nat := String_Length (S);
11959 F : Nat := 1;
11960
11961 procedure Skip_Spaces;
11962 -- Advance F past any spaces
11963
11964 -----------------
11965 -- Skip_Spaces --
11966 -----------------
11967
11968 procedure Skip_Spaces is
11969 begin
11970 while F <= L and then Get_String_Char (S, F) = C loop
11971 F := F + 1;
11972 end loop;
11973 end Skip_Spaces;
11974
11975 -- Start of processing for Arg_Store
11976
11977 begin
11978 Skip_Spaces; -- skip leading spaces
11979
11980 -- Loop through characters, changing any embedded
11981 -- sequence of spaces to a single null character (this
11982 -- is how Link_With/Linker_Options differ)
11983
11984 while F <= L loop
11985 if Get_String_Char (S, F) = C then
11986 Skip_Spaces;
11987 exit when F > L;
11988 Store_String_Char (ASCII.NUL);
11989
11990 else
11991 Store_String_Char (Get_String_Char (S, F));
11992 F := F + 1;
11993 end if;
11994 end loop;
11995 end Arg_Store;
11996
11997 Arg := Next (Arg);
11998
11999 if Present (Arg) then
12000 Store_String_Char (ASCII.NUL);
12001 end if;
12002 end loop;
12003
12004 Store_Linker_Option_String (End_String);
12005 end if;
12006 end Link_With;
12007
12008 ------------------
12009 -- Linker_Alias --
12010 ------------------
12011
12012 -- pragma Linker_Alias (
12013 -- [Entity =>] LOCAL_NAME
12014 -- [Target =>] static_string_EXPRESSION);
12015
12016 when Pragma_Linker_Alias =>
12017 GNAT_Pragma;
12018 Check_Arg_Order ((Name_Entity, Name_Target));
12019 Check_Arg_Count (2);
12020 Check_Optional_Identifier (Arg1, Name_Entity);
12021 Check_Optional_Identifier (Arg2, Name_Target);
12022 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12023 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
12024
12025 -- The only processing required is to link this item on to the
12026 -- list of rep items for the given entity. This is accomplished
12027 -- by the call to Rep_Item_Too_Late (when no error is detected
12028 -- and False is returned).
12029
12030 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
12031 return;
12032 else
12033 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
12034 end if;
12035
12036 ------------------------
12037 -- Linker_Constructor --
12038 ------------------------
12039
12040 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
12041
12042 -- Code is shared with Linker_Destructor
12043
12044 -----------------------
12045 -- Linker_Destructor --
12046 -----------------------
12047
12048 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
12049
12050 when Pragma_Linker_Constructor |
12051 Pragma_Linker_Destructor =>
12052 Linker_Constructor : declare
12053 Arg1_X : Node_Id;
12054 Proc : Entity_Id;
12055
12056 begin
12057 GNAT_Pragma;
12058 Check_Arg_Count (1);
12059 Check_No_Identifiers;
12060 Check_Arg_Is_Local_Name (Arg1);
12061 Arg1_X := Get_Pragma_Arg (Arg1);
12062 Analyze (Arg1_X);
12063 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
12064
12065 if not Is_Library_Level_Entity (Proc) then
12066 Error_Pragma_Arg
12067 ("argument for pragma% must be library level entity", Arg1);
12068 end if;
12069
12070 -- The only processing required is to link this item on to the
12071 -- list of rep items for the given entity. This is accomplished
12072 -- by the call to Rep_Item_Too_Late (when no error is detected
12073 -- and False is returned).
12074
12075 if Rep_Item_Too_Late (Proc, N) then
12076 return;
12077 else
12078 Set_Has_Gigi_Rep_Item (Proc);
12079 end if;
12080 end Linker_Constructor;
12081
12082 --------------------
12083 -- Linker_Options --
12084 --------------------
12085
12086 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
12087
12088 when Pragma_Linker_Options => Linker_Options : declare
12089 Arg : Node_Id;
12090
12091 begin
12092 Check_Ada_83_Warning;
12093 Check_No_Identifiers;
12094 Check_Arg_Count (1);
12095 Check_Is_In_Decl_Part_Or_Package_Spec;
12096 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12097 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
12098
12099 Arg := Arg2;
12100 while Present (Arg) loop
12101 Check_Arg_Is_Static_Expression (Arg, Standard_String);
12102 Store_String_Char (ASCII.NUL);
12103 Store_String_Chars
12104 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
12105 Arg := Next (Arg);
12106 end loop;
12107
12108 if Operating_Mode = Generate_Code
12109 and then In_Extended_Main_Source_Unit (N)
12110 then
12111 Store_Linker_Option_String (End_String);
12112 end if;
12113 end Linker_Options;
12114
12115 --------------------
12116 -- Linker_Section --
12117 --------------------
12118
12119 -- pragma Linker_Section (
12120 -- [Entity =>] LOCAL_NAME
12121 -- [Section =>] static_string_EXPRESSION);
12122
12123 when Pragma_Linker_Section =>
12124 GNAT_Pragma;
12125 Check_Arg_Order ((Name_Entity, Name_Section));
12126 Check_Arg_Count (2);
12127 Check_Optional_Identifier (Arg1, Name_Entity);
12128 Check_Optional_Identifier (Arg2, Name_Section);
12129 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12130 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
12131
12132 -- This pragma applies only to objects
12133
12134 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
12135 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
12136 end if;
12137
12138 -- The only processing required is to link this item on to the
12139 -- list of rep items for the given entity. This is accomplished
12140 -- by the call to Rep_Item_Too_Late (when no error is detected
12141 -- and False is returned).
12142
12143 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
12144 return;
12145 else
12146 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
12147 end if;
12148
12149 ----------
12150 -- List --
12151 ----------
12152
12153 -- pragma List (On | Off)
12154
12155 -- There is nothing to do here, since we did all the processing for
12156 -- this pragma in Par.Prag (so that it works properly even in syntax
12157 -- only mode).
12158
12159 when Pragma_List =>
12160 null;
12161
12162 ---------------
12163 -- Lock_Free --
12164 ---------------
12165
12166 -- pragma Lock_Free [(Boolean_EXPRESSION)];
12167
12168 when Pragma_Lock_Free => Lock_Free : declare
12169 P : constant Node_Id := Parent (N);
12170 Arg : Node_Id;
12171 Ent : Entity_Id;
12172 Val : Boolean;
12173
12174 begin
12175 Check_No_Identifiers;
12176 Check_At_Most_N_Arguments (1);
12177
12178 -- Protected definition case
12179
12180 if Nkind (P) = N_Protected_Definition then
12181 Ent := Defining_Identifier (Parent (P));
12182
12183 -- One argument
12184
12185 if Arg_Count = 1 then
12186 Arg := Get_Pragma_Arg (Arg1);
12187 Val := Is_True (Static_Boolean (Arg));
12188
12189 -- No arguments (expression is considered to be True)
12190
12191 else
12192 Val := True;
12193 end if;
12194
12195 -- Check duplicate pragma before we chain the pragma in the Rep
12196 -- Item chain of Ent.
12197
12198 Check_Duplicate_Pragma (Ent);
12199 Record_Rep_Item (Ent, N);
12200 Set_Uses_Lock_Free (Ent, Val);
12201
12202 -- Anything else is incorrect placement
12203
12204 else
12205 Pragma_Misplaced;
12206 end if;
12207 end Lock_Free;
12208
12209 --------------------
12210 -- Locking_Policy --
12211 --------------------
12212
12213 -- pragma Locking_Policy (policy_IDENTIFIER);
12214
12215 when Pragma_Locking_Policy => declare
12216 subtype LP_Range is Name_Id
12217 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
12218 LP_Val : LP_Range;
12219 LP : Character;
12220
12221 begin
12222 Check_Ada_83_Warning;
12223 Check_Arg_Count (1);
12224 Check_No_Identifiers;
12225 Check_Arg_Is_Locking_Policy (Arg1);
12226 Check_Valid_Configuration_Pragma;
12227 LP_Val := Chars (Get_Pragma_Arg (Arg1));
12228
12229 case LP_Val is
12230 when Name_Ceiling_Locking =>
12231 LP := 'C';
12232 when Name_Inheritance_Locking =>
12233 LP := 'I';
12234 when Name_Concurrent_Readers_Locking =>
12235 LP := 'R';
12236 end case;
12237
12238 if Locking_Policy /= ' '
12239 and then Locking_Policy /= LP
12240 then
12241 Error_Msg_Sloc := Locking_Policy_Sloc;
12242 Error_Pragma ("locking policy incompatible with policy#");
12243
12244 -- Set new policy, but always preserve System_Location since we
12245 -- like the error message with the run time name.
12246
12247 else
12248 Locking_Policy := LP;
12249
12250 if Locking_Policy_Sloc /= System_Location then
12251 Locking_Policy_Sloc := Loc;
12252 end if;
12253 end if;
12254 end;
12255
12256 ----------------
12257 -- Long_Float --
12258 ----------------
12259
12260 -- pragma Long_Float (D_Float | G_Float);
12261
12262 when Pragma_Long_Float => Long_Float : declare
12263 begin
12264 GNAT_Pragma;
12265 Check_Valid_Configuration_Pragma;
12266 Check_Arg_Count (1);
12267 Check_No_Identifier (Arg1);
12268 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
12269
12270 if not OpenVMS_On_Target then
12271 Error_Pragma ("??pragma% ignored (applies only to Open'V'M'S)");
12272 end if;
12273
12274 -- D_Float case
12275
12276 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
12277 if Opt.Float_Format_Long = 'G' then
12278 Error_Pragma_Arg
12279 ("G_Float previously specified", Arg1);
12280
12281 elsif Current_Sem_Unit /= Main_Unit
12282 and then Opt.Float_Format_Long /= 'D'
12283 then
12284 Error_Pragma_Arg
12285 ("main unit not compiled with pragma Long_Float (D_Float)",
12286 "\pragma% must be used consistently for whole partition",
12287 Arg1);
12288
12289 else
12290 Opt.Float_Format_Long := 'D';
12291 end if;
12292
12293 -- G_Float case (this is the default, does not need overriding)
12294
12295 else
12296 if Opt.Float_Format_Long = 'D' then
12297 Error_Pragma ("D_Float previously specified");
12298
12299 elsif Current_Sem_Unit /= Main_Unit
12300 and then Opt.Float_Format_Long /= 'G'
12301 then
12302 Error_Pragma_Arg
12303 ("main unit not compiled with pragma Long_Float (G_Float)",
12304 "\pragma% must be used consistently for whole partition",
12305 Arg1);
12306
12307 else
12308 Opt.Float_Format_Long := 'G';
12309 end if;
12310 end if;
12311
12312 Set_Standard_Fpt_Formats;
12313 end Long_Float;
12314
12315 --------------------
12316 -- Loop_Invariant --
12317 --------------------
12318
12319 -- pragma Loop_Invariant ( boolean_EXPRESSION );
12320
12321 when Pragma_Loop_Invariant => Loop_Invariant : declare
12322 begin
12323 GNAT_Pragma;
12324 S14_Pragma;
12325 Check_Arg_Count (1);
12326 Check_Loop_Invariant_Variant_Placement;
12327
12328 -- Completely ignore if disabled
12329
12330 if Check_Disabled (Pname) then
12331 Rewrite (N, Make_Null_Statement (Loc));
12332 Analyze (N);
12333 return;
12334 end if;
12335
12336 Preanalyze_And_Resolve (Expression (Arg1), Any_Boolean);
12337
12338 -- Transform pragma Loop_Invariant into equivalent pragma Check
12339 -- Generate:
12340 -- pragma Check (Loop_Invaraint, Arg1);
12341
12342 -- Seems completely wrong to hijack pragma Check this way ???
12343
12344 Rewrite (N,
12345 Make_Pragma (Loc,
12346 Chars => Name_Check,
12347 Pragma_Argument_Associations => New_List (
12348 Make_Pragma_Argument_Association (Loc,
12349 Expression => Make_Identifier (Loc, Name_Loop_Invariant)),
12350 Relocate_Node (Arg1))));
12351
12352 Analyze (N);
12353 end Loop_Invariant;
12354
12355 ------------------
12356 -- Loop_Variant --
12357 ------------------
12358
12359 -- pragma Loop_Variant
12360 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
12361
12362 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
12363
12364 -- CHANGE_DIRECTION ::= Increases | Decreases
12365
12366 when Pragma_Loop_Variant => Loop_Variant : declare
12367 Variant : Node_Id;
12368
12369 begin
12370 GNAT_Pragma;
12371 S14_Pragma;
12372 Check_At_Least_N_Arguments (1);
12373 Check_Loop_Invariant_Variant_Placement;
12374
12375 -- Completely ignore if disabled
12376
12377 if Check_Disabled (Pname) then
12378 Rewrite (N, Make_Null_Statement (Loc));
12379 Analyze (N);
12380 return;
12381 end if;
12382
12383 -- Process all increasing / decreasing expressions
12384
12385 Variant := First (Pragma_Argument_Associations (N));
12386 while Present (Variant) loop
12387 if Chars (Variant) /= Name_Decreases
12388 and then Chars (Variant) /= Name_Increases
12389 then
12390 Error_Pragma_Arg ("wrong change modifier", Variant);
12391 end if;
12392
12393 Preanalyze_And_Resolve (Expression (Variant), Any_Discrete);
12394
12395 Next (Variant);
12396 end loop;
12397 end Loop_Variant;
12398
12399 -----------------------
12400 -- Machine_Attribute --
12401 -----------------------
12402
12403 -- pragma Machine_Attribute (
12404 -- [Entity =>] LOCAL_NAME,
12405 -- [Attribute_Name =>] static_string_EXPRESSION
12406 -- [, [Info =>] static_EXPRESSION] );
12407
12408 when Pragma_Machine_Attribute => Machine_Attribute : declare
12409 Def_Id : Entity_Id;
12410
12411 begin
12412 GNAT_Pragma;
12413 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
12414
12415 if Arg_Count = 3 then
12416 Check_Optional_Identifier (Arg3, Name_Info);
12417 Check_Arg_Is_Static_Expression (Arg3);
12418 else
12419 Check_Arg_Count (2);
12420 end if;
12421
12422 Check_Optional_Identifier (Arg1, Name_Entity);
12423 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
12424 Check_Arg_Is_Local_Name (Arg1);
12425 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
12426 Def_Id := Entity (Get_Pragma_Arg (Arg1));
12427
12428 if Is_Access_Type (Def_Id) then
12429 Def_Id := Designated_Type (Def_Id);
12430 end if;
12431
12432 if Rep_Item_Too_Early (Def_Id, N) then
12433 return;
12434 end if;
12435
12436 Def_Id := Underlying_Type (Def_Id);
12437
12438 -- The only processing required is to link this item on to the
12439 -- list of rep items for the given entity. This is accomplished
12440 -- by the call to Rep_Item_Too_Late (when no error is detected
12441 -- and False is returned).
12442
12443 if Rep_Item_Too_Late (Def_Id, N) then
12444 return;
12445 else
12446 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
12447 end if;
12448 end Machine_Attribute;
12449
12450 ----------
12451 -- Main --
12452 ----------
12453
12454 -- pragma Main
12455 -- (MAIN_OPTION [, MAIN_OPTION]);
12456
12457 -- MAIN_OPTION ::=
12458 -- [STACK_SIZE =>] static_integer_EXPRESSION
12459 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
12460 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
12461
12462 when Pragma_Main => Main : declare
12463 Args : Args_List (1 .. 3);
12464 Names : constant Name_List (1 .. 3) := (
12465 Name_Stack_Size,
12466 Name_Task_Stack_Size_Default,
12467 Name_Time_Slicing_Enabled);
12468
12469 Nod : Node_Id;
12470
12471 begin
12472 GNAT_Pragma;
12473 Gather_Associations (Names, Args);
12474
12475 for J in 1 .. 2 loop
12476 if Present (Args (J)) then
12477 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
12478 end if;
12479 end loop;
12480
12481 if Present (Args (3)) then
12482 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
12483 end if;
12484
12485 Nod := Next (N);
12486 while Present (Nod) loop
12487 if Nkind (Nod) = N_Pragma
12488 and then Pragma_Name (Nod) = Name_Main
12489 then
12490 Error_Msg_Name_1 := Pname;
12491 Error_Msg_N ("duplicate pragma% not permitted", Nod);
12492 end if;
12493
12494 Next (Nod);
12495 end loop;
12496 end Main;
12497
12498 ------------------
12499 -- Main_Storage --
12500 ------------------
12501
12502 -- pragma Main_Storage
12503 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
12504
12505 -- MAIN_STORAGE_OPTION ::=
12506 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
12507 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
12508
12509 when Pragma_Main_Storage => Main_Storage : declare
12510 Args : Args_List (1 .. 2);
12511 Names : constant Name_List (1 .. 2) := (
12512 Name_Working_Storage,
12513 Name_Top_Guard);
12514
12515 Nod : Node_Id;
12516
12517 begin
12518 GNAT_Pragma;
12519 Gather_Associations (Names, Args);
12520
12521 for J in 1 .. 2 loop
12522 if Present (Args (J)) then
12523 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
12524 end if;
12525 end loop;
12526
12527 Check_In_Main_Program;
12528
12529 Nod := Next (N);
12530 while Present (Nod) loop
12531 if Nkind (Nod) = N_Pragma
12532 and then Pragma_Name (Nod) = Name_Main_Storage
12533 then
12534 Error_Msg_Name_1 := Pname;
12535 Error_Msg_N ("duplicate pragma% not permitted", Nod);
12536 end if;
12537
12538 Next (Nod);
12539 end loop;
12540 end Main_Storage;
12541
12542 -----------------
12543 -- Memory_Size --
12544 -----------------
12545
12546 -- pragma Memory_Size (NUMERIC_LITERAL)
12547
12548 when Pragma_Memory_Size =>
12549 GNAT_Pragma;
12550
12551 -- Memory size is simply ignored
12552
12553 Check_No_Identifiers;
12554 Check_Arg_Count (1);
12555 Check_Arg_Is_Integer_Literal (Arg1);
12556
12557 -------------
12558 -- No_Body --
12559 -------------
12560
12561 -- pragma No_Body;
12562
12563 -- The only correct use of this pragma is on its own in a file, in
12564 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
12565 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
12566 -- check for a file containing nothing but a No_Body pragma). If we
12567 -- attempt to process it during normal semantics processing, it means
12568 -- it was misplaced.
12569
12570 when Pragma_No_Body =>
12571 GNAT_Pragma;
12572 Pragma_Misplaced;
12573
12574 ---------------
12575 -- No_Return --
12576 ---------------
12577
12578 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
12579
12580 when Pragma_No_Return => No_Return : declare
12581 Id : Node_Id;
12582 E : Entity_Id;
12583 Found : Boolean;
12584 Arg : Node_Id;
12585
12586 begin
12587 Ada_2005_Pragma;
12588 Check_At_Least_N_Arguments (1);
12589
12590 -- Loop through arguments of pragma
12591
12592 Arg := Arg1;
12593 while Present (Arg) loop
12594 Check_Arg_Is_Local_Name (Arg);
12595 Id := Get_Pragma_Arg (Arg);
12596 Analyze (Id);
12597
12598 if not Is_Entity_Name (Id) then
12599 Error_Pragma_Arg ("entity name required", Arg);
12600 end if;
12601
12602 if Etype (Id) = Any_Type then
12603 raise Pragma_Exit;
12604 end if;
12605
12606 -- Loop to find matching procedures
12607
12608 E := Entity (Id);
12609 Found := False;
12610 while Present (E)
12611 and then Scope (E) = Current_Scope
12612 loop
12613 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
12614 Set_No_Return (E);
12615
12616 -- Set flag on any alias as well
12617
12618 if Is_Overloadable (E) and then Present (Alias (E)) then
12619 Set_No_Return (Alias (E));
12620 end if;
12621
12622 Found := True;
12623 end if;
12624
12625 exit when From_Aspect_Specification (N);
12626 E := Homonym (E);
12627 end loop;
12628
12629 if not Found then
12630 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
12631 end if;
12632
12633 Next (Arg);
12634 end loop;
12635 end No_Return;
12636
12637 -----------------
12638 -- No_Run_Time --
12639 -----------------
12640
12641 -- pragma No_Run_Time;
12642
12643 -- Note: this pragma is retained for backwards compatibility. See
12644 -- body of Rtsfind for full details on its handling.
12645
12646 when Pragma_No_Run_Time =>
12647 GNAT_Pragma;
12648 Check_Valid_Configuration_Pragma;
12649 Check_Arg_Count (0);
12650
12651 No_Run_Time_Mode := True;
12652 Configurable_Run_Time_Mode := True;
12653
12654 -- Set Duration to 32 bits if word size is 32
12655
12656 if Ttypes.System_Word_Size = 32 then
12657 Duration_32_Bits_On_Target := True;
12658 end if;
12659
12660 -- Set appropriate restrictions
12661
12662 Set_Restriction (No_Finalization, N);
12663 Set_Restriction (No_Exception_Handlers, N);
12664 Set_Restriction (Max_Tasks, N, 0);
12665 Set_Restriction (No_Tasking, N);
12666
12667 ------------------------
12668 -- No_Strict_Aliasing --
12669 ------------------------
12670
12671 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
12672
12673 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
12674 E_Id : Entity_Id;
12675
12676 begin
12677 GNAT_Pragma;
12678 Check_At_Most_N_Arguments (1);
12679
12680 if Arg_Count = 0 then
12681 Check_Valid_Configuration_Pragma;
12682 Opt.No_Strict_Aliasing := True;
12683
12684 else
12685 Check_Optional_Identifier (Arg2, Name_Entity);
12686 Check_Arg_Is_Local_Name (Arg1);
12687 E_Id := Entity (Get_Pragma_Arg (Arg1));
12688
12689 if E_Id = Any_Type then
12690 return;
12691 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
12692 Error_Pragma_Arg ("pragma% requires access type", Arg1);
12693 end if;
12694
12695 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
12696 end if;
12697 end No_Strict_Aliasing;
12698
12699 -----------------------
12700 -- Normalize_Scalars --
12701 -----------------------
12702
12703 -- pragma Normalize_Scalars;
12704
12705 when Pragma_Normalize_Scalars =>
12706 Check_Ada_83_Warning;
12707 Check_Arg_Count (0);
12708 Check_Valid_Configuration_Pragma;
12709
12710 -- Normalize_Scalars creates false positives in CodePeer, and
12711 -- incorrect negative results in Alfa mode, so ignore this pragma
12712 -- in these modes.
12713
12714 if not (CodePeer_Mode or Alfa_Mode) then
12715 Normalize_Scalars := True;
12716 Init_Or_Norm_Scalars := True;
12717 end if;
12718
12719 -----------------
12720 -- Obsolescent --
12721 -----------------
12722
12723 -- pragma Obsolescent;
12724
12725 -- pragma Obsolescent (
12726 -- [Message =>] static_string_EXPRESSION
12727 -- [,[Version =>] Ada_05]]);
12728
12729 -- pragma Obsolescent (
12730 -- [Entity =>] NAME
12731 -- [,[Message =>] static_string_EXPRESSION
12732 -- [,[Version =>] Ada_05]] );
12733
12734 when Pragma_Obsolescent => Obsolescent : declare
12735 Ename : Node_Id;
12736 Decl : Node_Id;
12737
12738 procedure Set_Obsolescent (E : Entity_Id);
12739 -- Given an entity Ent, mark it as obsolescent if appropriate
12740
12741 ---------------------
12742 -- Set_Obsolescent --
12743 ---------------------
12744
12745 procedure Set_Obsolescent (E : Entity_Id) is
12746 Active : Boolean;
12747 Ent : Entity_Id;
12748 S : String_Id;
12749
12750 begin
12751 Active := True;
12752 Ent := E;
12753
12754 -- Entity name was given
12755
12756 if Present (Ename) then
12757
12758 -- If entity name matches, we are fine. Save entity in
12759 -- pragma argument, for ASIS use.
12760
12761 if Chars (Ename) = Chars (Ent) then
12762 Set_Entity (Ename, Ent);
12763 Generate_Reference (Ent, Ename);
12764
12765 -- If entity name does not match, only possibility is an
12766 -- enumeration literal from an enumeration type declaration.
12767
12768 elsif Ekind (Ent) /= E_Enumeration_Type then
12769 Error_Pragma
12770 ("pragma % entity name does not match declaration");
12771
12772 else
12773 Ent := First_Literal (E);
12774 loop
12775 if No (Ent) then
12776 Error_Pragma
12777 ("pragma % entity name does not match any " &
12778 "enumeration literal");
12779
12780 elsif Chars (Ent) = Chars (Ename) then
12781 Set_Entity (Ename, Ent);
12782 Generate_Reference (Ent, Ename);
12783 exit;
12784
12785 else
12786 Ent := Next_Literal (Ent);
12787 end if;
12788 end loop;
12789 end if;
12790 end if;
12791
12792 -- Ent points to entity to be marked
12793
12794 if Arg_Count >= 1 then
12795
12796 -- Deal with static string argument
12797
12798 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12799 S := Strval (Get_Pragma_Arg (Arg1));
12800
12801 for J in 1 .. String_Length (S) loop
12802 if not In_Character_Range (Get_String_Char (S, J)) then
12803 Error_Pragma_Arg
12804 ("pragma% argument does not allow wide characters",
12805 Arg1);
12806 end if;
12807 end loop;
12808
12809 Obsolescent_Warnings.Append
12810 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
12811
12812 -- Check for Ada_05 parameter
12813
12814 if Arg_Count /= 1 then
12815 Check_Arg_Count (2);
12816
12817 declare
12818 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
12819
12820 begin
12821 Check_Arg_Is_Identifier (Argx);
12822
12823 if Chars (Argx) /= Name_Ada_05 then
12824 Error_Msg_Name_2 := Name_Ada_05;
12825 Error_Pragma_Arg
12826 ("only allowed argument for pragma% is %", Argx);
12827 end if;
12828
12829 if Ada_Version_Explicit < Ada_2005
12830 or else not Warn_On_Ada_2005_Compatibility
12831 then
12832 Active := False;
12833 end if;
12834 end;
12835 end if;
12836 end if;
12837
12838 -- Set flag if pragma active
12839
12840 if Active then
12841 Set_Is_Obsolescent (Ent);
12842 end if;
12843
12844 return;
12845 end Set_Obsolescent;
12846
12847 -- Start of processing for pragma Obsolescent
12848
12849 begin
12850 GNAT_Pragma;
12851
12852 Check_At_Most_N_Arguments (3);
12853
12854 -- See if first argument specifies an entity name
12855
12856 if Arg_Count >= 1
12857 and then
12858 (Chars (Arg1) = Name_Entity
12859 or else
12860 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
12861 N_Identifier,
12862 N_Operator_Symbol))
12863 then
12864 Ename := Get_Pragma_Arg (Arg1);
12865
12866 -- Eliminate first argument, so we can share processing
12867
12868 Arg1 := Arg2;
12869 Arg2 := Arg3;
12870 Arg_Count := Arg_Count - 1;
12871
12872 -- No Entity name argument given
12873
12874 else
12875 Ename := Empty;
12876 end if;
12877
12878 if Arg_Count >= 1 then
12879 Check_Optional_Identifier (Arg1, Name_Message);
12880
12881 if Arg_Count = 2 then
12882 Check_Optional_Identifier (Arg2, Name_Version);
12883 end if;
12884 end if;
12885
12886 -- Get immediately preceding declaration
12887
12888 Decl := Prev (N);
12889 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
12890 Prev (Decl);
12891 end loop;
12892
12893 -- Cases where we do not follow anything other than another pragma
12894
12895 if No (Decl) then
12896
12897 -- First case: library level compilation unit declaration with
12898 -- the pragma immediately following the declaration.
12899
12900 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
12901 Set_Obsolescent
12902 (Defining_Entity (Unit (Parent (Parent (N)))));
12903 return;
12904
12905 -- Case 2: library unit placement for package
12906
12907 else
12908 declare
12909 Ent : constant Entity_Id := Find_Lib_Unit_Name;
12910 begin
12911 if Is_Package_Or_Generic_Package (Ent) then
12912 Set_Obsolescent (Ent);
12913 return;
12914 end if;
12915 end;
12916 end if;
12917
12918 -- Cases where we must follow a declaration
12919
12920 else
12921 if Nkind (Decl) not in N_Declaration
12922 and then Nkind (Decl) not in N_Later_Decl_Item
12923 and then Nkind (Decl) not in N_Generic_Declaration
12924 and then Nkind (Decl) not in N_Renaming_Declaration
12925 then
12926 Error_Pragma
12927 ("pragma% misplaced, "
12928 & "must immediately follow a declaration");
12929
12930 else
12931 Set_Obsolescent (Defining_Entity (Decl));
12932 return;
12933 end if;
12934 end if;
12935 end Obsolescent;
12936
12937 --------------
12938 -- Optimize --
12939 --------------
12940
12941 -- pragma Optimize (Time | Space | Off);
12942
12943 -- The actual check for optimize is done in Gigi. Note that this
12944 -- pragma does not actually change the optimization setting, it
12945 -- simply checks that it is consistent with the pragma.
12946
12947 when Pragma_Optimize =>
12948 Check_No_Identifiers;
12949 Check_Arg_Count (1);
12950 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
12951
12952 ------------------------
12953 -- Optimize_Alignment --
12954 ------------------------
12955
12956 -- pragma Optimize_Alignment (Time | Space | Off);
12957
12958 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
12959 GNAT_Pragma;
12960 Check_No_Identifiers;
12961 Check_Arg_Count (1);
12962 Check_Valid_Configuration_Pragma;
12963
12964 declare
12965 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
12966 begin
12967 case Nam is
12968 when Name_Time =>
12969 Opt.Optimize_Alignment := 'T';
12970 when Name_Space =>
12971 Opt.Optimize_Alignment := 'S';
12972 when Name_Off =>
12973 Opt.Optimize_Alignment := 'O';
12974 when others =>
12975 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
12976 end case;
12977 end;
12978
12979 -- Set indication that mode is set locally. If we are in fact in a
12980 -- configuration pragma file, this setting is harmless since the
12981 -- switch will get reset anyway at the start of each unit.
12982
12983 Optimize_Alignment_Local := True;
12984 end Optimize_Alignment;
12985
12986 -------------------
12987 -- Overflow_Mode --
12988 -------------------
12989
12990 -- pragma Overflow_Mode
12991 -- ([General => ] MODE [, [Assertions => ] MODE]);
12992
12993 -- MODE := STRICT | MINIMIZED | ELIMINATED
12994
12995 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
12996 -- since System.Bignums makes this assumption. This is true of nearly
12997 -- all (all?) targets.
12998
12999 when Pragma_Overflow_Mode => Overflow_Mode : declare
13000 function Get_Overflow_Mode
13001 (Name : Name_Id;
13002 Arg : Node_Id) return Overflow_Mode_Type;
13003 -- Function to process one pragma argument, Arg. If an identifier
13004 -- is present, it must be Name. Mode type is returned if a valid
13005 -- argument exists, otherwise an error is signalled.
13006
13007 -----------------------
13008 -- Get_Overflow_Mode --
13009 -----------------------
13010
13011 function Get_Overflow_Mode
13012 (Name : Name_Id;
13013 Arg : Node_Id) return Overflow_Mode_Type
13014 is
13015 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
13016
13017 begin
13018 Check_Optional_Identifier (Arg, Name);
13019 Check_Arg_Is_Identifier (Argx);
13020
13021 if Chars (Argx) = Name_Strict then
13022 return Strict;
13023
13024 elsif Chars (Argx) = Name_Minimized then
13025 return Minimized;
13026
13027 elsif Chars (Argx) = Name_Eliminated then
13028 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
13029 Error_Pragma_Arg
13030 ("Eliminated not implemented on this target", Argx);
13031 else
13032 return Eliminated;
13033 end if;
13034
13035 else
13036 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
13037 end if;
13038 end Get_Overflow_Mode;
13039
13040 -- Start of processing for Overflow_Mode
13041
13042 begin
13043 GNAT_Pragma;
13044 Check_At_Least_N_Arguments (1);
13045 Check_At_Most_N_Arguments (2);
13046
13047 -- Process first argument
13048
13049 Scope_Suppress.Overflow_Mode_General :=
13050 Get_Overflow_Mode (Name_General, Arg1);
13051
13052 -- Case of only one argument
13053
13054 if Arg_Count = 1 then
13055 Scope_Suppress.Overflow_Mode_Assertions :=
13056 Scope_Suppress.Overflow_Mode_General;
13057
13058 -- Case of two arguments present
13059
13060 else
13061 Scope_Suppress.Overflow_Mode_Assertions :=
13062 Get_Overflow_Mode (Name_Assertions, Arg2);
13063 end if;
13064 end Overflow_Mode;
13065
13066 -------------
13067 -- Ordered --
13068 -------------
13069
13070 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
13071
13072 when Pragma_Ordered => Ordered : declare
13073 Assoc : constant Node_Id := Arg1;
13074 Type_Id : Node_Id;
13075 Typ : Entity_Id;
13076
13077 begin
13078 GNAT_Pragma;
13079 Check_No_Identifiers;
13080 Check_Arg_Count (1);
13081 Check_Arg_Is_Local_Name (Arg1);
13082
13083 Type_Id := Get_Pragma_Arg (Assoc);
13084 Find_Type (Type_Id);
13085 Typ := Entity (Type_Id);
13086
13087 if Typ = Any_Type then
13088 return;
13089 else
13090 Typ := Underlying_Type (Typ);
13091 end if;
13092
13093 if not Is_Enumeration_Type (Typ) then
13094 Error_Pragma ("pragma% must specify enumeration type");
13095 end if;
13096
13097 Check_First_Subtype (Arg1);
13098 Set_Has_Pragma_Ordered (Base_Type (Typ));
13099 end Ordered;
13100
13101 ----------
13102 -- Pack --
13103 ----------
13104
13105 -- pragma Pack (first_subtype_LOCAL_NAME);
13106
13107 when Pragma_Pack => Pack : declare
13108 Assoc : constant Node_Id := Arg1;
13109 Type_Id : Node_Id;
13110 Typ : Entity_Id;
13111 Ctyp : Entity_Id;
13112 Ignore : Boolean := False;
13113
13114 begin
13115 Check_No_Identifiers;
13116 Check_Arg_Count (1);
13117 Check_Arg_Is_Local_Name (Arg1);
13118
13119 Type_Id := Get_Pragma_Arg (Assoc);
13120 Find_Type (Type_Id);
13121 Typ := Entity (Type_Id);
13122
13123 if Typ = Any_Type
13124 or else Rep_Item_Too_Early (Typ, N)
13125 then
13126 return;
13127 else
13128 Typ := Underlying_Type (Typ);
13129 end if;
13130
13131 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
13132 Error_Pragma ("pragma% must specify array or record type");
13133 end if;
13134
13135 Check_First_Subtype (Arg1);
13136 Check_Duplicate_Pragma (Typ);
13137
13138 -- Array type
13139
13140 if Is_Array_Type (Typ) then
13141 Ctyp := Component_Type (Typ);
13142
13143 -- Ignore pack that does nothing
13144
13145 if Known_Static_Esize (Ctyp)
13146 and then Known_Static_RM_Size (Ctyp)
13147 and then Esize (Ctyp) = RM_Size (Ctyp)
13148 and then Addressable (Esize (Ctyp))
13149 then
13150 Ignore := True;
13151 end if;
13152
13153 -- Process OK pragma Pack. Note that if there is a separate
13154 -- component clause present, the Pack will be cancelled. This
13155 -- processing is in Freeze.
13156
13157 if not Rep_Item_Too_Late (Typ, N) then
13158
13159 -- In the context of static code analysis, we do not need
13160 -- complex front-end expansions related to pragma Pack,
13161 -- so disable handling of pragma Pack in these cases.
13162
13163 if CodePeer_Mode or Alfa_Mode then
13164 null;
13165
13166 -- Don't attempt any packing for VM targets. We possibly
13167 -- could deal with some cases of array bit-packing, but we
13168 -- don't bother, since this is not a typical kind of
13169 -- representation in the VM context anyway (and would not
13170 -- for example work nicely with the debugger).
13171
13172 elsif VM_Target /= No_VM then
13173 if not GNAT_Mode then
13174 Error_Pragma
13175 ("??pragma% ignored in this configuration");
13176 end if;
13177
13178 -- Normal case where we do the pack action
13179
13180 else
13181 if not Ignore then
13182 Set_Is_Packed (Base_Type (Typ));
13183 Set_Has_Non_Standard_Rep (Base_Type (Typ));
13184 end if;
13185
13186 Set_Has_Pragma_Pack (Base_Type (Typ));
13187 end if;
13188 end if;
13189
13190 -- For record types, the pack is always effective
13191
13192 else pragma Assert (Is_Record_Type (Typ));
13193 if not Rep_Item_Too_Late (Typ, N) then
13194
13195 -- Ignore pack request with warning in VM mode (skip warning
13196 -- if we are compiling GNAT run time library).
13197
13198 if VM_Target /= No_VM then
13199 if not GNAT_Mode then
13200 Error_Pragma
13201 ("??pragma% ignored in this configuration");
13202 end if;
13203
13204 -- Normal case of pack request active
13205
13206 else
13207 Set_Is_Packed (Base_Type (Typ));
13208 Set_Has_Pragma_Pack (Base_Type (Typ));
13209 Set_Has_Non_Standard_Rep (Base_Type (Typ));
13210 end if;
13211 end if;
13212 end if;
13213 end Pack;
13214
13215 ----------
13216 -- Page --
13217 ----------
13218
13219 -- pragma Page;
13220
13221 -- There is nothing to do here, since we did all the processing for
13222 -- this pragma in Par.Prag (so that it works properly even in syntax
13223 -- only mode).
13224
13225 when Pragma_Page =>
13226 null;
13227
13228 ----------------------------------
13229 -- Partition_Elaboration_Policy --
13230 ----------------------------------
13231
13232 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
13233
13234 when Pragma_Partition_Elaboration_Policy => declare
13235 subtype PEP_Range is Name_Id
13236 range First_Partition_Elaboration_Policy_Name
13237 .. Last_Partition_Elaboration_Policy_Name;
13238 PEP_Val : PEP_Range;
13239 PEP : Character;
13240
13241 begin
13242 Ada_2005_Pragma;
13243 Check_Arg_Count (1);
13244 Check_No_Identifiers;
13245 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
13246 Check_Valid_Configuration_Pragma;
13247 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
13248
13249 case PEP_Val is
13250 when Name_Concurrent =>
13251 PEP := 'C';
13252 when Name_Sequential =>
13253 PEP := 'S';
13254 end case;
13255
13256 if Partition_Elaboration_Policy /= ' '
13257 and then Partition_Elaboration_Policy /= PEP
13258 then
13259 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
13260 Error_Pragma
13261 ("partition elaboration policy incompatible with policy#");
13262
13263 -- Set new policy, but always preserve System_Location since we
13264 -- like the error message with the run time name.
13265
13266 else
13267 Partition_Elaboration_Policy := PEP;
13268
13269 if Partition_Elaboration_Policy_Sloc /= System_Location then
13270 Partition_Elaboration_Policy_Sloc := Loc;
13271 end if;
13272 end if;
13273 end;
13274
13275 -------------
13276 -- Passive --
13277 -------------
13278
13279 -- pragma Passive [(PASSIVE_FORM)];
13280
13281 -- PASSIVE_FORM ::= Semaphore | No
13282
13283 when Pragma_Passive =>
13284 GNAT_Pragma;
13285
13286 if Nkind (Parent (N)) /= N_Task_Definition then
13287 Error_Pragma ("pragma% must be within task definition");
13288 end if;
13289
13290 if Arg_Count /= 0 then
13291 Check_Arg_Count (1);
13292 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
13293 end if;
13294
13295 ----------------------------------
13296 -- Preelaborable_Initialization --
13297 ----------------------------------
13298
13299 -- pragma Preelaborable_Initialization (DIRECT_NAME);
13300
13301 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
13302 Ent : Entity_Id;
13303
13304 begin
13305 Ada_2005_Pragma;
13306 Check_Arg_Count (1);
13307 Check_No_Identifiers;
13308 Check_Arg_Is_Identifier (Arg1);
13309 Check_Arg_Is_Local_Name (Arg1);
13310 Check_First_Subtype (Arg1);
13311 Ent := Entity (Get_Pragma_Arg (Arg1));
13312
13313 if not (Is_Private_Type (Ent)
13314 or else
13315 Is_Protected_Type (Ent)
13316 or else
13317 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
13318 then
13319 Error_Pragma_Arg
13320 ("pragma % can only be applied to private, formal derived or "
13321 & "protected type",
13322 Arg1);
13323 end if;
13324
13325 -- Give an error if the pragma is applied to a protected type that
13326 -- does not qualify (due to having entries, or due to components
13327 -- that do not qualify).
13328
13329 if Is_Protected_Type (Ent)
13330 and then not Has_Preelaborable_Initialization (Ent)
13331 then
13332 Error_Msg_N
13333 ("protected type & does not have preelaborable " &
13334 "initialization", Ent);
13335
13336 -- Otherwise mark the type as definitely having preelaborable
13337 -- initialization.
13338
13339 else
13340 Set_Known_To_Have_Preelab_Init (Ent);
13341 end if;
13342
13343 if Has_Pragma_Preelab_Init (Ent)
13344 and then Warn_On_Redundant_Constructs
13345 then
13346 Error_Pragma ("?r?duplicate pragma%!");
13347 else
13348 Set_Has_Pragma_Preelab_Init (Ent);
13349 end if;
13350 end Preelab_Init;
13351
13352 --------------------
13353 -- Persistent_BSS --
13354 --------------------
13355
13356 -- pragma Persistent_BSS [(object_NAME)];
13357
13358 when Pragma_Persistent_BSS => Persistent_BSS : declare
13359 Decl : Node_Id;
13360 Ent : Entity_Id;
13361 Prag : Node_Id;
13362
13363 begin
13364 GNAT_Pragma;
13365 Check_At_Most_N_Arguments (1);
13366
13367 -- Case of application to specific object (one argument)
13368
13369 if Arg_Count = 1 then
13370 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13371
13372 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
13373 or else not
13374 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
13375 E_Constant)
13376 then
13377 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
13378 end if;
13379
13380 Ent := Entity (Get_Pragma_Arg (Arg1));
13381 Decl := Parent (Ent);
13382
13383 -- Check for duplication before inserting in list of
13384 -- representation items.
13385
13386 Check_Duplicate_Pragma (Ent);
13387
13388 if Rep_Item_Too_Late (Ent, N) then
13389 return;
13390 end if;
13391
13392 if Present (Expression (Decl)) then
13393 Error_Pragma_Arg
13394 ("object for pragma% cannot have initialization", Arg1);
13395 end if;
13396
13397 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
13398 Error_Pragma_Arg
13399 ("object type for pragma% is not potentially persistent",
13400 Arg1);
13401 end if;
13402
13403 Prag :=
13404 Make_Linker_Section_Pragma
13405 (Ent, Sloc (N), ".persistent.bss");
13406 Insert_After (N, Prag);
13407 Analyze (Prag);
13408
13409 -- Case of use as configuration pragma with no arguments
13410
13411 else
13412 Check_Valid_Configuration_Pragma;
13413 Persistent_BSS_Mode := True;
13414 end if;
13415 end Persistent_BSS;
13416
13417 -------------
13418 -- Polling --
13419 -------------
13420
13421 -- pragma Polling (ON | OFF);
13422
13423 when Pragma_Polling =>
13424 GNAT_Pragma;
13425 Check_Arg_Count (1);
13426 Check_No_Identifiers;
13427 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13428 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
13429
13430 -------------------
13431 -- Postcondition --
13432 -------------------
13433
13434 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
13435 -- [,[Message =>] String_EXPRESSION]);
13436
13437 when Pragma_Postcondition => Postcondition : declare
13438 In_Body : Boolean;
13439
13440 begin
13441 GNAT_Pragma;
13442 Check_At_Least_N_Arguments (1);
13443 Check_At_Most_N_Arguments (2);
13444 Check_Optional_Identifier (Arg1, Name_Check);
13445
13446 -- Verify the proper placement of the pragma. The remainder of the
13447 -- processing is found in Sem_Ch6/Sem_Ch7.
13448
13449 Check_Precondition_Postcondition (In_Body);
13450
13451 -- When the pragma is a source contruct and appears inside a body,
13452 -- preanalyze the boolean_expression to detect illegal forward
13453 -- references:
13454
13455 -- procedure P is
13456 -- pragma Postcondition (X'Old ...);
13457 -- X : ...
13458
13459 if Comes_From_Source (N) and then In_Body then
13460 Preanalyze_Spec_Expression (Expression (Arg1), Any_Boolean);
13461 end if;
13462 end Postcondition;
13463
13464 ------------------
13465 -- Precondition --
13466 ------------------
13467
13468 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
13469 -- [,[Message =>] String_EXPRESSION]);
13470
13471 when Pragma_Precondition => Precondition : declare
13472 In_Body : Boolean;
13473
13474 begin
13475 GNAT_Pragma;
13476 Check_At_Least_N_Arguments (1);
13477 Check_At_Most_N_Arguments (2);
13478 Check_Optional_Identifier (Arg1, Name_Check);
13479 Check_Precondition_Postcondition (In_Body);
13480
13481 -- If in spec, nothing more to do. If in body, then we convert the
13482 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
13483 -- this whether or not precondition checks are enabled. That works
13484 -- fine since pragma Check will do this check, and will also
13485 -- analyze the condition itself in the proper context.
13486
13487 if In_Body then
13488 Rewrite (N,
13489 Make_Pragma (Loc,
13490 Chars => Name_Check,
13491 Pragma_Argument_Associations => New_List (
13492 Make_Pragma_Argument_Association (Loc,
13493 Expression => Make_Identifier (Loc, Name_Precondition)),
13494
13495 Make_Pragma_Argument_Association (Sloc (Arg1),
13496 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
13497
13498 if Arg_Count = 2 then
13499 Append_To (Pragma_Argument_Associations (N),
13500 Make_Pragma_Argument_Association (Sloc (Arg2),
13501 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
13502 end if;
13503
13504 Analyze (N);
13505 end if;
13506 end Precondition;
13507
13508 ---------------
13509 -- Predicate --
13510 ---------------
13511
13512 -- pragma Predicate
13513 -- ([Entity =>] type_LOCAL_NAME,
13514 -- [Check =>] EXPRESSION);
13515
13516 when Pragma_Predicate => Predicate : declare
13517 Type_Id : Node_Id;
13518 Typ : Entity_Id;
13519
13520 Discard : Boolean;
13521 pragma Unreferenced (Discard);
13522
13523 begin
13524 GNAT_Pragma;
13525 Check_Arg_Count (2);
13526 Check_Optional_Identifier (Arg1, Name_Entity);
13527 Check_Optional_Identifier (Arg2, Name_Check);
13528
13529 Check_Arg_Is_Local_Name (Arg1);
13530
13531 Type_Id := Get_Pragma_Arg (Arg1);
13532 Find_Type (Type_Id);
13533 Typ := Entity (Type_Id);
13534
13535 if Typ = Any_Type then
13536 return;
13537 end if;
13538
13539 -- The remaining processing is simply to link the pragma on to
13540 -- the rep item chain, for processing when the type is frozen.
13541 -- This is accomplished by a call to Rep_Item_Too_Late. We also
13542 -- mark the type as having predicates.
13543
13544 Set_Has_Predicates (Typ);
13545 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
13546 end Predicate;
13547
13548 ------------------
13549 -- Preelaborate --
13550 ------------------
13551
13552 -- pragma Preelaborate [(library_unit_NAME)];
13553
13554 -- Set the flag Is_Preelaborated of program unit name entity
13555
13556 when Pragma_Preelaborate => Preelaborate : declare
13557 Pa : constant Node_Id := Parent (N);
13558 Pk : constant Node_Kind := Nkind (Pa);
13559 Ent : Entity_Id;
13560
13561 begin
13562 Check_Ada_83_Warning;
13563 Check_Valid_Library_Unit_Pragma;
13564
13565 if Nkind (N) = N_Null_Statement then
13566 return;
13567 end if;
13568
13569 Ent := Find_Lib_Unit_Name;
13570 Check_Duplicate_Pragma (Ent);
13571
13572 -- This filters out pragmas inside generic parent then
13573 -- show up inside instantiation
13574
13575 if Present (Ent)
13576 and then not (Pk = N_Package_Specification
13577 and then Present (Generic_Parent (Pa)))
13578 then
13579 if not Debug_Flag_U then
13580 Set_Is_Preelaborated (Ent);
13581 Set_Suppress_Elaboration_Warnings (Ent);
13582 end if;
13583 end if;
13584 end Preelaborate;
13585
13586 ---------------------
13587 -- Preelaborate_05 --
13588 ---------------------
13589
13590 -- pragma Preelaborate_05 [(library_unit_NAME)];
13591
13592 -- This pragma is useable only in GNAT_Mode, where it is used like
13593 -- pragma Preelaborate but it is only effective in Ada 2005 mode
13594 -- (otherwise it is ignored). This is used to implement AI-362 which
13595 -- recategorizes some run-time packages in Ada 2005 mode.
13596
13597 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
13598 Ent : Entity_Id;
13599
13600 begin
13601 GNAT_Pragma;
13602 Check_Valid_Library_Unit_Pragma;
13603
13604 if not GNAT_Mode then
13605 Error_Pragma ("pragma% only available in GNAT mode");
13606 end if;
13607
13608 if Nkind (N) = N_Null_Statement then
13609 return;
13610 end if;
13611
13612 -- This is one of the few cases where we need to test the value of
13613 -- Ada_Version_Explicit rather than Ada_Version (which is always
13614 -- set to Ada_2012 in a predefined unit), we need to know the
13615 -- explicit version set to know if this pragma is active.
13616
13617 if Ada_Version_Explicit >= Ada_2005 then
13618 Ent := Find_Lib_Unit_Name;
13619 Set_Is_Preelaborated (Ent);
13620 Set_Suppress_Elaboration_Warnings (Ent);
13621 end if;
13622 end Preelaborate_05;
13623
13624 --------------
13625 -- Priority --
13626 --------------
13627
13628 -- pragma Priority (EXPRESSION);
13629
13630 when Pragma_Priority => Priority : declare
13631 P : constant Node_Id := Parent (N);
13632 Arg : Node_Id;
13633 Ent : Entity_Id;
13634
13635 begin
13636 Check_No_Identifiers;
13637 Check_Arg_Count (1);
13638
13639 -- Subprogram case
13640
13641 if Nkind (P) = N_Subprogram_Body then
13642 Check_In_Main_Program;
13643
13644 Ent := Defining_Unit_Name (Specification (P));
13645
13646 if Nkind (Ent) = N_Defining_Program_Unit_Name then
13647 Ent := Defining_Identifier (Ent);
13648 end if;
13649
13650 Arg := Get_Pragma_Arg (Arg1);
13651 Analyze_And_Resolve (Arg, Standard_Integer);
13652
13653 -- Must be static
13654
13655 if not Is_Static_Expression (Arg) then
13656 Flag_Non_Static_Expr
13657 ("main subprogram priority is not static!", Arg);
13658 raise Pragma_Exit;
13659
13660 -- If constraint error, then we already signalled an error
13661
13662 elsif Raises_Constraint_Error (Arg) then
13663 null;
13664
13665 -- Otherwise check in range
13666
13667 else
13668 declare
13669 Val : constant Uint := Expr_Value (Arg);
13670
13671 begin
13672 if Val < 0
13673 or else Val > Expr_Value (Expression
13674 (Parent (RTE (RE_Max_Priority))))
13675 then
13676 Error_Pragma_Arg
13677 ("main subprogram priority is out of range", Arg1);
13678 end if;
13679 end;
13680 end if;
13681
13682 Set_Main_Priority
13683 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
13684
13685 -- Load an arbitrary entity from System.Tasking to make sure
13686 -- this package is implicitly with'ed, since we need to have
13687 -- the tasking run-time active for the pragma Priority to have
13688 -- any effect.
13689
13690 declare
13691 Discard : Entity_Id;
13692 pragma Warnings (Off, Discard);
13693 begin
13694 Discard := RTE (RE_Task_List);
13695 end;
13696
13697 -- Task or Protected, must be of type Integer
13698
13699 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
13700 Arg := Get_Pragma_Arg (Arg1);
13701 Ent := Defining_Identifier (Parent (P));
13702
13703 -- The expression must be analyzed in the special manner
13704 -- described in "Handling of Default and Per-Object
13705 -- Expressions" in sem.ads.
13706
13707 Preanalyze_Spec_Expression (Arg, Standard_Integer);
13708
13709 if not Is_Static_Expression (Arg) then
13710 Check_Restriction (Static_Priorities, Arg);
13711 end if;
13712
13713 -- Anything else is incorrect
13714
13715 else
13716 Pragma_Misplaced;
13717 end if;
13718
13719 -- Check duplicate pragma before we chain the pragma in the Rep
13720 -- Item chain of Ent.
13721
13722 Check_Duplicate_Pragma (Ent);
13723 Record_Rep_Item (Ent, N);
13724 end Priority;
13725
13726 -----------------------------------
13727 -- Priority_Specific_Dispatching --
13728 -----------------------------------
13729
13730 -- pragma Priority_Specific_Dispatching (
13731 -- policy_IDENTIFIER,
13732 -- first_priority_EXPRESSION,
13733 -- last_priority_EXPRESSION);
13734
13735 when Pragma_Priority_Specific_Dispatching =>
13736 Priority_Specific_Dispatching : declare
13737 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
13738 -- This is the entity System.Any_Priority;
13739
13740 DP : Character;
13741 Lower_Bound : Node_Id;
13742 Upper_Bound : Node_Id;
13743 Lower_Val : Uint;
13744 Upper_Val : Uint;
13745
13746 begin
13747 Ada_2005_Pragma;
13748 Check_Arg_Count (3);
13749 Check_No_Identifiers;
13750 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13751 Check_Valid_Configuration_Pragma;
13752 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13753 DP := Fold_Upper (Name_Buffer (1));
13754
13755 Lower_Bound := Get_Pragma_Arg (Arg2);
13756 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
13757 Lower_Val := Expr_Value (Lower_Bound);
13758
13759 Upper_Bound := Get_Pragma_Arg (Arg3);
13760 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
13761 Upper_Val := Expr_Value (Upper_Bound);
13762
13763 -- It is not allowed to use Task_Dispatching_Policy and
13764 -- Priority_Specific_Dispatching in the same partition.
13765
13766 if Task_Dispatching_Policy /= ' ' then
13767 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13768 Error_Pragma
13769 ("pragma% incompatible with Task_Dispatching_Policy#");
13770
13771 -- Check lower bound in range
13772
13773 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
13774 or else
13775 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
13776 then
13777 Error_Pragma_Arg
13778 ("first_priority is out of range", Arg2);
13779
13780 -- Check upper bound in range
13781
13782 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
13783 or else
13784 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
13785 then
13786 Error_Pragma_Arg
13787 ("last_priority is out of range", Arg3);
13788
13789 -- Check that the priority range is valid
13790
13791 elsif Lower_Val > Upper_Val then
13792 Error_Pragma
13793 ("last_priority_expression must be greater than" &
13794 " or equal to first_priority_expression");
13795
13796 -- Store the new policy, but always preserve System_Location since
13797 -- we like the error message with the run-time name.
13798
13799 else
13800 -- Check overlapping in the priority ranges specified in other
13801 -- Priority_Specific_Dispatching pragmas within the same
13802 -- partition. We can only check those we know about!
13803
13804 for J in
13805 Specific_Dispatching.First .. Specific_Dispatching.Last
13806 loop
13807 if Specific_Dispatching.Table (J).First_Priority in
13808 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
13809 or else Specific_Dispatching.Table (J).Last_Priority in
13810 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
13811 then
13812 Error_Msg_Sloc :=
13813 Specific_Dispatching.Table (J).Pragma_Loc;
13814 Error_Pragma
13815 ("priority range overlaps with "
13816 & "Priority_Specific_Dispatching#");
13817 end if;
13818 end loop;
13819
13820 -- The use of Priority_Specific_Dispatching is incompatible
13821 -- with Task_Dispatching_Policy.
13822
13823 if Task_Dispatching_Policy /= ' ' then
13824 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13825 Error_Pragma
13826 ("Priority_Specific_Dispatching incompatible "
13827 & "with Task_Dispatching_Policy#");
13828 end if;
13829
13830 -- The use of Priority_Specific_Dispatching forces ceiling
13831 -- locking policy.
13832
13833 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
13834 Error_Msg_Sloc := Locking_Policy_Sloc;
13835 Error_Pragma
13836 ("Priority_Specific_Dispatching incompatible "
13837 & "with Locking_Policy#");
13838
13839 -- Set the Ceiling_Locking policy, but preserve System_Location
13840 -- since we like the error message with the run time name.
13841
13842 else
13843 Locking_Policy := 'C';
13844
13845 if Locking_Policy_Sloc /= System_Location then
13846 Locking_Policy_Sloc := Loc;
13847 end if;
13848 end if;
13849
13850 -- Add entry in the table
13851
13852 Specific_Dispatching.Append
13853 ((Dispatching_Policy => DP,
13854 First_Priority => UI_To_Int (Lower_Val),
13855 Last_Priority => UI_To_Int (Upper_Val),
13856 Pragma_Loc => Loc));
13857 end if;
13858 end Priority_Specific_Dispatching;
13859
13860 -------------
13861 -- Profile --
13862 -------------
13863
13864 -- pragma Profile (profile_IDENTIFIER);
13865
13866 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
13867
13868 when Pragma_Profile =>
13869 Ada_2005_Pragma;
13870 Check_Arg_Count (1);
13871 Check_Valid_Configuration_Pragma;
13872 Check_No_Identifiers;
13873
13874 declare
13875 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13876
13877 begin
13878 if Chars (Argx) = Name_Ravenscar then
13879 Set_Ravenscar_Profile (N);
13880
13881 elsif Chars (Argx) = Name_Restricted then
13882 Set_Profile_Restrictions
13883 (Restricted,
13884 N, Warn => Treat_Restrictions_As_Warnings);
13885
13886 elsif Chars (Argx) = Name_Rational then
13887 Rational_Profile := True;
13888
13889 elsif Chars (Argx) = Name_No_Implementation_Extensions then
13890 Set_Profile_Restrictions
13891 (No_Implementation_Extensions,
13892 N, Warn => Treat_Restrictions_As_Warnings);
13893
13894 else
13895 Error_Pragma_Arg ("& is not a valid profile", Argx);
13896 end if;
13897 end;
13898
13899 ----------------------
13900 -- Profile_Warnings --
13901 ----------------------
13902
13903 -- pragma Profile_Warnings (profile_IDENTIFIER);
13904
13905 -- profile_IDENTIFIER => Restricted | Ravenscar
13906
13907 when Pragma_Profile_Warnings =>
13908 GNAT_Pragma;
13909 Check_Arg_Count (1);
13910 Check_Valid_Configuration_Pragma;
13911 Check_No_Identifiers;
13912
13913 declare
13914 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13915
13916 begin
13917 if Chars (Argx) = Name_Ravenscar then
13918 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
13919
13920 elsif Chars (Argx) = Name_Restricted then
13921 Set_Profile_Restrictions (Restricted, N, Warn => True);
13922
13923 elsif Chars (Argx) = Name_No_Implementation_Extensions then
13924 Set_Profile_Restrictions
13925 (No_Implementation_Extensions, N, Warn => True);
13926
13927 else
13928 Error_Pragma_Arg ("& is not a valid profile", Argx);
13929 end if;
13930 end;
13931
13932 --------------------------
13933 -- Propagate_Exceptions --
13934 --------------------------
13935
13936 -- pragma Propagate_Exceptions;
13937
13938 -- Note: this pragma is obsolete and has no effect
13939
13940 when Pragma_Propagate_Exceptions =>
13941 GNAT_Pragma;
13942 Check_Arg_Count (0);
13943
13944 if In_Extended_Main_Source_Unit (N) then
13945 Propagate_Exceptions := True;
13946 end if;
13947
13948 ------------------
13949 -- Psect_Object --
13950 ------------------
13951
13952 -- pragma Psect_Object (
13953 -- [Internal =>] LOCAL_NAME,
13954 -- [, [External =>] EXTERNAL_SYMBOL]
13955 -- [, [Size =>] EXTERNAL_SYMBOL]);
13956
13957 when Pragma_Psect_Object | Pragma_Common_Object =>
13958 Psect_Object : declare
13959 Args : Args_List (1 .. 3);
13960 Names : constant Name_List (1 .. 3) := (
13961 Name_Internal,
13962 Name_External,
13963 Name_Size);
13964
13965 Internal : Node_Id renames Args (1);
13966 External : Node_Id renames Args (2);
13967 Size : Node_Id renames Args (3);
13968
13969 Def_Id : Entity_Id;
13970
13971 procedure Check_Too_Long (Arg : Node_Id);
13972 -- Posts message if the argument is an identifier with more
13973 -- than 31 characters, or a string literal with more than
13974 -- 31 characters, and we are operating under VMS
13975
13976 --------------------
13977 -- Check_Too_Long --
13978 --------------------
13979
13980 procedure Check_Too_Long (Arg : Node_Id) is
13981 X : constant Node_Id := Original_Node (Arg);
13982
13983 begin
13984 if not Nkind_In (X, N_String_Literal, N_Identifier) then
13985 Error_Pragma_Arg
13986 ("inappropriate argument for pragma %", Arg);
13987 end if;
13988
13989 if OpenVMS_On_Target then
13990 if (Nkind (X) = N_String_Literal
13991 and then String_Length (Strval (X)) > 31)
13992 or else
13993 (Nkind (X) = N_Identifier
13994 and then Length_Of_Name (Chars (X)) > 31)
13995 then
13996 Error_Pragma_Arg
13997 ("argument for pragma % is longer than 31 characters",
13998 Arg);
13999 end if;
14000 end if;
14001 end Check_Too_Long;
14002
14003 -- Start of processing for Common_Object/Psect_Object
14004
14005 begin
14006 GNAT_Pragma;
14007 Gather_Associations (Names, Args);
14008 Process_Extended_Import_Export_Internal_Arg (Internal);
14009
14010 Def_Id := Entity (Internal);
14011
14012 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
14013 Error_Pragma_Arg
14014 ("pragma% must designate an object", Internal);
14015 end if;
14016
14017 Check_Too_Long (Internal);
14018
14019 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
14020 Error_Pragma_Arg
14021 ("cannot use pragma% for imported/exported object",
14022 Internal);
14023 end if;
14024
14025 if Is_Concurrent_Type (Etype (Internal)) then
14026 Error_Pragma_Arg
14027 ("cannot specify pragma % for task/protected object",
14028 Internal);
14029 end if;
14030
14031 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
14032 or else
14033 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
14034 then
14035 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
14036 end if;
14037
14038 if Ekind (Def_Id) = E_Constant then
14039 Error_Pragma_Arg
14040 ("cannot specify pragma % for a constant", Internal);
14041 end if;
14042
14043 if Is_Record_Type (Etype (Internal)) then
14044 declare
14045 Ent : Entity_Id;
14046 Decl : Entity_Id;
14047
14048 begin
14049 Ent := First_Entity (Etype (Internal));
14050 while Present (Ent) loop
14051 Decl := Declaration_Node (Ent);
14052
14053 if Ekind (Ent) = E_Component
14054 and then Nkind (Decl) = N_Component_Declaration
14055 and then Present (Expression (Decl))
14056 and then Warn_On_Export_Import
14057 then
14058 Error_Msg_N
14059 ("?x?object for pragma % has defaults", Internal);
14060 exit;
14061
14062 else
14063 Next_Entity (Ent);
14064 end if;
14065 end loop;
14066 end;
14067 end if;
14068
14069 if Present (Size) then
14070 Check_Too_Long (Size);
14071 end if;
14072
14073 if Present (External) then
14074 Check_Arg_Is_External_Name (External);
14075 Check_Too_Long (External);
14076 end if;
14077
14078 -- If all error tests pass, link pragma on to the rep item chain
14079
14080 Record_Rep_Item (Def_Id, N);
14081 end Psect_Object;
14082
14083 ----------
14084 -- Pure --
14085 ----------
14086
14087 -- pragma Pure [(library_unit_NAME)];
14088
14089 when Pragma_Pure => Pure : declare
14090 Ent : Entity_Id;
14091
14092 begin
14093 Check_Ada_83_Warning;
14094 Check_Valid_Library_Unit_Pragma;
14095
14096 if Nkind (N) = N_Null_Statement then
14097 return;
14098 end if;
14099
14100 Ent := Find_Lib_Unit_Name;
14101 Set_Is_Pure (Ent);
14102 Set_Has_Pragma_Pure (Ent);
14103 Set_Suppress_Elaboration_Warnings (Ent);
14104 end Pure;
14105
14106 -------------
14107 -- Pure_05 --
14108 -------------
14109
14110 -- pragma Pure_05 [(library_unit_NAME)];
14111
14112 -- This pragma is useable only in GNAT_Mode, where it is used like
14113 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
14114 -- it is ignored). It may be used after a pragma Preelaborate, in
14115 -- which case it overrides the effect of the pragma Preelaborate.
14116 -- This is used to implement AI-362 which recategorizes some run-time
14117 -- packages in Ada 2005 mode.
14118
14119 when Pragma_Pure_05 => Pure_05 : declare
14120 Ent : Entity_Id;
14121
14122 begin
14123 GNAT_Pragma;
14124 Check_Valid_Library_Unit_Pragma;
14125
14126 if not GNAT_Mode then
14127 Error_Pragma ("pragma% only available in GNAT mode");
14128 end if;
14129
14130 if Nkind (N) = N_Null_Statement then
14131 return;
14132 end if;
14133
14134 -- This is one of the few cases where we need to test the value of
14135 -- Ada_Version_Explicit rather than Ada_Version (which is always
14136 -- set to Ada_2012 in a predefined unit), we need to know the
14137 -- explicit version set to know if this pragma is active.
14138
14139 if Ada_Version_Explicit >= Ada_2005 then
14140 Ent := Find_Lib_Unit_Name;
14141 Set_Is_Preelaborated (Ent, False);
14142 Set_Is_Pure (Ent);
14143 Set_Suppress_Elaboration_Warnings (Ent);
14144 end if;
14145 end Pure_05;
14146
14147 -------------
14148 -- Pure_12 --
14149 -------------
14150
14151 -- pragma Pure_12 [(library_unit_NAME)];
14152
14153 -- This pragma is useable only in GNAT_Mode, where it is used like
14154 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
14155 -- it is ignored). It may be used after a pragma Preelaborate, in
14156 -- which case it overrides the effect of the pragma Preelaborate.
14157 -- This is used to implement AI05-0212 which recategorizes some
14158 -- run-time packages in Ada 2012 mode.
14159
14160 when Pragma_Pure_12 => Pure_12 : declare
14161 Ent : Entity_Id;
14162
14163 begin
14164 GNAT_Pragma;
14165 Check_Valid_Library_Unit_Pragma;
14166
14167 if not GNAT_Mode then
14168 Error_Pragma ("pragma% only available in GNAT mode");
14169 end if;
14170
14171 if Nkind (N) = N_Null_Statement then
14172 return;
14173 end if;
14174
14175 -- This is one of the few cases where we need to test the value of
14176 -- Ada_Version_Explicit rather than Ada_Version (which is always
14177 -- set to Ada_2012 in a predefined unit), we need to know the
14178 -- explicit version set to know if this pragma is active.
14179
14180 if Ada_Version_Explicit >= Ada_2012 then
14181 Ent := Find_Lib_Unit_Name;
14182 Set_Is_Preelaborated (Ent, False);
14183 Set_Is_Pure (Ent);
14184 Set_Suppress_Elaboration_Warnings (Ent);
14185 end if;
14186 end Pure_12;
14187
14188 -------------------
14189 -- Pure_Function --
14190 -------------------
14191
14192 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
14193
14194 when Pragma_Pure_Function => Pure_Function : declare
14195 E_Id : Node_Id;
14196 E : Entity_Id;
14197 Def_Id : Entity_Id;
14198 Effective : Boolean := False;
14199
14200 begin
14201 GNAT_Pragma;
14202 Check_Arg_Count (1);
14203 Check_Optional_Identifier (Arg1, Name_Entity);
14204 Check_Arg_Is_Local_Name (Arg1);
14205 E_Id := Get_Pragma_Arg (Arg1);
14206
14207 if Error_Posted (E_Id) then
14208 return;
14209 end if;
14210
14211 -- Loop through homonyms (overloadings) of referenced entity
14212
14213 E := Entity (E_Id);
14214
14215 if Present (E) then
14216 loop
14217 Def_Id := Get_Base_Subprogram (E);
14218
14219 if not Ekind_In (Def_Id, E_Function,
14220 E_Generic_Function,
14221 E_Operator)
14222 then
14223 Error_Pragma_Arg
14224 ("pragma% requires a function name", Arg1);
14225 end if;
14226
14227 Set_Is_Pure (Def_Id);
14228
14229 if not Has_Pragma_Pure_Function (Def_Id) then
14230 Set_Has_Pragma_Pure_Function (Def_Id);
14231 Effective := True;
14232 end if;
14233
14234 exit when From_Aspect_Specification (N);
14235 E := Homonym (E);
14236 exit when No (E) or else Scope (E) /= Current_Scope;
14237 end loop;
14238
14239 if not Effective
14240 and then Warn_On_Redundant_Constructs
14241 then
14242 Error_Msg_NE
14243 ("pragma Pure_Function on& is redundant?r?",
14244 N, Entity (E_Id));
14245 end if;
14246 end if;
14247 end Pure_Function;
14248
14249 --------------------
14250 -- Queuing_Policy --
14251 --------------------
14252
14253 -- pragma Queuing_Policy (policy_IDENTIFIER);
14254
14255 when Pragma_Queuing_Policy => declare
14256 QP : Character;
14257
14258 begin
14259 Check_Ada_83_Warning;
14260 Check_Arg_Count (1);
14261 Check_No_Identifiers;
14262 Check_Arg_Is_Queuing_Policy (Arg1);
14263 Check_Valid_Configuration_Pragma;
14264 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
14265 QP := Fold_Upper (Name_Buffer (1));
14266
14267 if Queuing_Policy /= ' '
14268 and then Queuing_Policy /= QP
14269 then
14270 Error_Msg_Sloc := Queuing_Policy_Sloc;
14271 Error_Pragma ("queuing policy incompatible with policy#");
14272
14273 -- Set new policy, but always preserve System_Location since we
14274 -- like the error message with the run time name.
14275
14276 else
14277 Queuing_Policy := QP;
14278
14279 if Queuing_Policy_Sloc /= System_Location then
14280 Queuing_Policy_Sloc := Loc;
14281 end if;
14282 end if;
14283 end;
14284
14285 --------------
14286 -- Rational --
14287 --------------
14288
14289 -- pragma Rational, for compatibility with foreign compiler
14290
14291 when Pragma_Rational =>
14292 Rational_Profile := True;
14293
14294 -----------------------
14295 -- Relative_Deadline --
14296 -----------------------
14297
14298 -- pragma Relative_Deadline (time_span_EXPRESSION);
14299
14300 when Pragma_Relative_Deadline => Relative_Deadline : declare
14301 P : constant Node_Id := Parent (N);
14302 Arg : Node_Id;
14303
14304 begin
14305 Ada_2005_Pragma;
14306 Check_No_Identifiers;
14307 Check_Arg_Count (1);
14308
14309 Arg := Get_Pragma_Arg (Arg1);
14310
14311 -- The expression must be analyzed in the special manner described
14312 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
14313
14314 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
14315
14316 -- Subprogram case
14317
14318 if Nkind (P) = N_Subprogram_Body then
14319 Check_In_Main_Program;
14320
14321 -- Only Task and subprogram cases allowed
14322
14323 elsif Nkind (P) /= N_Task_Definition then
14324 Pragma_Misplaced;
14325 end if;
14326
14327 -- Check duplicate pragma before we set the corresponding flag
14328
14329 if Has_Relative_Deadline_Pragma (P) then
14330 Error_Pragma ("duplicate pragma% not allowed");
14331 end if;
14332
14333 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
14334 -- Relative_Deadline pragma node cannot be inserted in the Rep
14335 -- Item chain of Ent since it is rewritten by the expander as a
14336 -- procedure call statement that will break the chain.
14337
14338 Set_Has_Relative_Deadline_Pragma (P, True);
14339 end Relative_Deadline;
14340
14341 ------------------------
14342 -- Remote_Access_Type --
14343 ------------------------
14344
14345 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
14346
14347 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
14348 E : Entity_Id;
14349
14350 begin
14351 GNAT_Pragma;
14352 Check_Arg_Count (1);
14353 Check_Optional_Identifier (Arg1, Name_Entity);
14354 Check_Arg_Is_Local_Name (Arg1);
14355
14356 E := Entity (Get_Pragma_Arg (Arg1));
14357
14358 if Nkind (Parent (E)) = N_Formal_Type_Declaration
14359 and then Ekind (E) = E_General_Access_Type
14360 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
14361 and then Scope (Root_Type (Directly_Designated_Type (E)))
14362 = Scope (E)
14363 and then Is_Valid_Remote_Object_Type
14364 (Root_Type (Directly_Designated_Type (E)))
14365 then
14366 Set_Is_Remote_Types (E);
14367
14368 else
14369 Error_Pragma_Arg
14370 ("pragma% applies only to formal access to classwide types",
14371 Arg1);
14372 end if;
14373 end Remote_Access_Type;
14374
14375 ---------------------------
14376 -- Remote_Call_Interface --
14377 ---------------------------
14378
14379 -- pragma Remote_Call_Interface [(library_unit_NAME)];
14380
14381 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
14382 Cunit_Node : Node_Id;
14383 Cunit_Ent : Entity_Id;
14384 K : Node_Kind;
14385
14386 begin
14387 Check_Ada_83_Warning;
14388 Check_Valid_Library_Unit_Pragma;
14389
14390 if Nkind (N) = N_Null_Statement then
14391 return;
14392 end if;
14393
14394 Cunit_Node := Cunit (Current_Sem_Unit);
14395 K := Nkind (Unit (Cunit_Node));
14396 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
14397
14398 if K = N_Package_Declaration
14399 or else K = N_Generic_Package_Declaration
14400 or else K = N_Subprogram_Declaration
14401 or else K = N_Generic_Subprogram_Declaration
14402 or else (K = N_Subprogram_Body
14403 and then Acts_As_Spec (Unit (Cunit_Node)))
14404 then
14405 null;
14406 else
14407 Error_Pragma (
14408 "pragma% must apply to package or subprogram declaration");
14409 end if;
14410
14411 Set_Is_Remote_Call_Interface (Cunit_Ent);
14412 end Remote_Call_Interface;
14413
14414 ------------------
14415 -- Remote_Types --
14416 ------------------
14417
14418 -- pragma Remote_Types [(library_unit_NAME)];
14419
14420 when Pragma_Remote_Types => Remote_Types : declare
14421 Cunit_Node : Node_Id;
14422 Cunit_Ent : Entity_Id;
14423
14424 begin
14425 Check_Ada_83_Warning;
14426 Check_Valid_Library_Unit_Pragma;
14427
14428 if Nkind (N) = N_Null_Statement then
14429 return;
14430 end if;
14431
14432 Cunit_Node := Cunit (Current_Sem_Unit);
14433 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
14434
14435 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
14436 N_Generic_Package_Declaration)
14437 then
14438 Error_Pragma
14439 ("pragma% can only apply to a package declaration");
14440 end if;
14441
14442 Set_Is_Remote_Types (Cunit_Ent);
14443 end Remote_Types;
14444
14445 ---------------
14446 -- Ravenscar --
14447 ---------------
14448
14449 -- pragma Ravenscar;
14450
14451 when Pragma_Ravenscar =>
14452 GNAT_Pragma;
14453 Check_Arg_Count (0);
14454 Check_Valid_Configuration_Pragma;
14455 Set_Ravenscar_Profile (N);
14456
14457 if Warn_On_Obsolescent_Feature then
14458 Error_Msg_N
14459 ("pragma Ravenscar is an obsolescent feature?j?", N);
14460 Error_Msg_N
14461 ("|use pragma Profile (Ravenscar) instead?j?", N);
14462 end if;
14463
14464 -------------------------
14465 -- Restricted_Run_Time --
14466 -------------------------
14467
14468 -- pragma Restricted_Run_Time;
14469
14470 when Pragma_Restricted_Run_Time =>
14471 GNAT_Pragma;
14472 Check_Arg_Count (0);
14473 Check_Valid_Configuration_Pragma;
14474 Set_Profile_Restrictions
14475 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
14476
14477 if Warn_On_Obsolescent_Feature then
14478 Error_Msg_N
14479 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
14480 N);
14481 Error_Msg_N
14482 ("|use pragma Profile (Restricted) instead?j?", N);
14483 end if;
14484
14485 ------------------
14486 -- Restrictions --
14487 ------------------
14488
14489 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
14490
14491 -- RESTRICTION ::=
14492 -- restriction_IDENTIFIER
14493 -- | restriction_parameter_IDENTIFIER => EXPRESSION
14494
14495 when Pragma_Restrictions =>
14496 Process_Restrictions_Or_Restriction_Warnings
14497 (Warn => Treat_Restrictions_As_Warnings);
14498
14499 --------------------------
14500 -- Restriction_Warnings --
14501 --------------------------
14502
14503 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
14504
14505 -- RESTRICTION ::=
14506 -- restriction_IDENTIFIER
14507 -- | restriction_parameter_IDENTIFIER => EXPRESSION
14508
14509 when Pragma_Restriction_Warnings =>
14510 GNAT_Pragma;
14511 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
14512
14513 ----------------
14514 -- Reviewable --
14515 ----------------
14516
14517 -- pragma Reviewable;
14518
14519 when Pragma_Reviewable =>
14520 Check_Ada_83_Warning;
14521 Check_Arg_Count (0);
14522
14523 -- Call dummy debugging function rv. This is done to assist front
14524 -- end debugging. By placing a Reviewable pragma in the source
14525 -- program, a breakpoint on rv catches this place in the source,
14526 -- allowing convenient stepping to the point of interest.
14527
14528 rv;
14529
14530 --------------------------
14531 -- Short_Circuit_And_Or --
14532 --------------------------
14533
14534 when Pragma_Short_Circuit_And_Or =>
14535 GNAT_Pragma;
14536 Check_Arg_Count (0);
14537 Check_Valid_Configuration_Pragma;
14538 Short_Circuit_And_Or := True;
14539
14540 -------------------
14541 -- Share_Generic --
14542 -------------------
14543
14544 -- pragma Share_Generic (NAME {, NAME});
14545
14546 when Pragma_Share_Generic =>
14547 GNAT_Pragma;
14548 Process_Generic_List;
14549
14550 ------------
14551 -- Shared --
14552 ------------
14553
14554 -- pragma Shared (LOCAL_NAME);
14555
14556 when Pragma_Shared =>
14557 GNAT_Pragma;
14558 Process_Atomic_Shared_Volatile;
14559
14560 --------------------
14561 -- Shared_Passive --
14562 --------------------
14563
14564 -- pragma Shared_Passive [(library_unit_NAME)];
14565
14566 -- Set the flag Is_Shared_Passive of program unit name entity
14567
14568 when Pragma_Shared_Passive => Shared_Passive : declare
14569 Cunit_Node : Node_Id;
14570 Cunit_Ent : Entity_Id;
14571
14572 begin
14573 Check_Ada_83_Warning;
14574 Check_Valid_Library_Unit_Pragma;
14575
14576 if Nkind (N) = N_Null_Statement then
14577 return;
14578 end if;
14579
14580 Cunit_Node := Cunit (Current_Sem_Unit);
14581 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
14582
14583 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
14584 N_Generic_Package_Declaration)
14585 then
14586 Error_Pragma
14587 ("pragma% can only apply to a package declaration");
14588 end if;
14589
14590 Set_Is_Shared_Passive (Cunit_Ent);
14591 end Shared_Passive;
14592
14593 -----------------------
14594 -- Short_Descriptors --
14595 -----------------------
14596
14597 -- pragma Short_Descriptors;
14598
14599 when Pragma_Short_Descriptors =>
14600 GNAT_Pragma;
14601 Check_Arg_Count (0);
14602 Check_Valid_Configuration_Pragma;
14603 Short_Descriptors := True;
14604
14605 ------------------------------
14606 -- Simple_Storage_Pool_Type --
14607 ------------------------------
14608
14609 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
14610
14611 when Pragma_Simple_Storage_Pool_Type =>
14612 Simple_Storage_Pool_Type : declare
14613 Type_Id : Node_Id;
14614 Typ : Entity_Id;
14615
14616 begin
14617 GNAT_Pragma;
14618 Check_Arg_Count (1);
14619 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14620
14621 Type_Id := Get_Pragma_Arg (Arg1);
14622 Find_Type (Type_Id);
14623 Typ := Entity (Type_Id);
14624
14625 if Typ = Any_Type then
14626 return;
14627 end if;
14628
14629 -- We require the pragma to apply to a type declared in a package
14630 -- declaration, but not (immediately) within a package body.
14631
14632 if Ekind (Current_Scope) /= E_Package
14633 or else In_Package_Body (Current_Scope)
14634 then
14635 Error_Pragma
14636 ("pragma% can only apply to type declared immediately " &
14637 "within a package declaration");
14638 end if;
14639
14640 -- A simple storage pool type must be an immutably limited record
14641 -- or private type. If the pragma is given for a private type,
14642 -- the full type is similarly restricted (which is checked later
14643 -- in Freeze_Entity).
14644
14645 if Is_Record_Type (Typ)
14646 and then not Is_Immutably_Limited_Type (Typ)
14647 then
14648 Error_Pragma
14649 ("pragma% can only apply to explicitly limited record type");
14650
14651 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
14652 Error_Pragma
14653 ("pragma% can only apply to a private type that is limited");
14654
14655 elsif not Is_Record_Type (Typ)
14656 and then not Is_Private_Type (Typ)
14657 then
14658 Error_Pragma
14659 ("pragma% can only apply to limited record or private type");
14660 end if;
14661
14662 Record_Rep_Item (Typ, N);
14663 end Simple_Storage_Pool_Type;
14664
14665 ----------------------
14666 -- Source_File_Name --
14667 ----------------------
14668
14669 -- There are five forms for this pragma:
14670
14671 -- pragma Source_File_Name (
14672 -- [UNIT_NAME =>] unit_NAME,
14673 -- BODY_FILE_NAME => STRING_LITERAL
14674 -- [, [INDEX =>] INTEGER_LITERAL]);
14675
14676 -- pragma Source_File_Name (
14677 -- [UNIT_NAME =>] unit_NAME,
14678 -- SPEC_FILE_NAME => STRING_LITERAL
14679 -- [, [INDEX =>] INTEGER_LITERAL]);
14680
14681 -- pragma Source_File_Name (
14682 -- BODY_FILE_NAME => STRING_LITERAL
14683 -- [, DOT_REPLACEMENT => STRING_LITERAL]
14684 -- [, CASING => CASING_SPEC]);
14685
14686 -- pragma Source_File_Name (
14687 -- SPEC_FILE_NAME => STRING_LITERAL
14688 -- [, DOT_REPLACEMENT => STRING_LITERAL]
14689 -- [, CASING => CASING_SPEC]);
14690
14691 -- pragma Source_File_Name (
14692 -- SUBUNIT_FILE_NAME => STRING_LITERAL
14693 -- [, DOT_REPLACEMENT => STRING_LITERAL]
14694 -- [, CASING => CASING_SPEC]);
14695
14696 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
14697
14698 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
14699 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
14700 -- only be used when no project file is used, while SFNP can only be
14701 -- used when a project file is used.
14702
14703 -- No processing here. Processing was completed during parsing, since
14704 -- we need to have file names set as early as possible. Units are
14705 -- loaded well before semantic processing starts.
14706
14707 -- The only processing we defer to this point is the check for
14708 -- correct placement.
14709
14710 when Pragma_Source_File_Name =>
14711 GNAT_Pragma;
14712 Check_Valid_Configuration_Pragma;
14713
14714 ------------------------------
14715 -- Source_File_Name_Project --
14716 ------------------------------
14717
14718 -- See Source_File_Name for syntax
14719
14720 -- No processing here. Processing was completed during parsing, since
14721 -- we need to have file names set as early as possible. Units are
14722 -- loaded well before semantic processing starts.
14723
14724 -- The only processing we defer to this point is the check for
14725 -- correct placement.
14726
14727 when Pragma_Source_File_Name_Project =>
14728 GNAT_Pragma;
14729 Check_Valid_Configuration_Pragma;
14730
14731 -- Check that a pragma Source_File_Name_Project is used only in a
14732 -- configuration pragmas file.
14733
14734 -- Pragmas Source_File_Name_Project should only be generated by
14735 -- the Project Manager in configuration pragmas files.
14736
14737 -- This is really an ugly test. It seems to depend on some
14738 -- accidental and undocumented property. At the very least it
14739 -- needs to be documented, but it would be better to have a
14740 -- clean way of testing if we are in a configuration file???
14741
14742 if Present (Parent (N)) then
14743 Error_Pragma
14744 ("pragma% can only appear in a configuration pragmas file");
14745 end if;
14746
14747 ----------------------
14748 -- Source_Reference --
14749 ----------------------
14750
14751 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
14752
14753 -- Nothing to do, all processing completed in Par.Prag, since we need
14754 -- the information for possible parser messages that are output.
14755
14756 when Pragma_Source_Reference =>
14757 GNAT_Pragma;
14758
14759 --------------------------------
14760 -- Static_Elaboration_Desired --
14761 --------------------------------
14762
14763 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
14764
14765 when Pragma_Static_Elaboration_Desired =>
14766 GNAT_Pragma;
14767 Check_At_Most_N_Arguments (1);
14768
14769 if Is_Compilation_Unit (Current_Scope)
14770 and then Ekind (Current_Scope) = E_Package
14771 then
14772 Set_Static_Elaboration_Desired (Current_Scope, True);
14773 else
14774 Error_Pragma ("pragma% must apply to a library-level package");
14775 end if;
14776
14777 ------------------
14778 -- Storage_Size --
14779 ------------------
14780
14781 -- pragma Storage_Size (EXPRESSION);
14782
14783 when Pragma_Storage_Size => Storage_Size : declare
14784 P : constant Node_Id := Parent (N);
14785 Arg : Node_Id;
14786
14787 begin
14788 Check_No_Identifiers;
14789 Check_Arg_Count (1);
14790
14791 -- The expression must be analyzed in the special manner described
14792 -- in "Handling of Default Expressions" in sem.ads.
14793
14794 Arg := Get_Pragma_Arg (Arg1);
14795 Preanalyze_Spec_Expression (Arg, Any_Integer);
14796
14797 if not Is_Static_Expression (Arg) then
14798 Check_Restriction (Static_Storage_Size, Arg);
14799 end if;
14800
14801 if Nkind (P) /= N_Task_Definition then
14802 Pragma_Misplaced;
14803 return;
14804
14805 else
14806 if Has_Storage_Size_Pragma (P) then
14807 Error_Pragma ("duplicate pragma% not allowed");
14808 else
14809 Set_Has_Storage_Size_Pragma (P, True);
14810 end if;
14811
14812 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
14813 end if;
14814 end Storage_Size;
14815
14816 ------------------
14817 -- Storage_Unit --
14818 ------------------
14819
14820 -- pragma Storage_Unit (NUMERIC_LITERAL);
14821
14822 -- Only permitted argument is System'Storage_Unit value
14823
14824 when Pragma_Storage_Unit =>
14825 Check_No_Identifiers;
14826 Check_Arg_Count (1);
14827 Check_Arg_Is_Integer_Literal (Arg1);
14828
14829 if Intval (Get_Pragma_Arg (Arg1)) /=
14830 UI_From_Int (Ttypes.System_Storage_Unit)
14831 then
14832 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
14833 Error_Pragma_Arg
14834 ("the only allowed argument for pragma% is ^", Arg1);
14835 end if;
14836
14837 --------------------
14838 -- Stream_Convert --
14839 --------------------
14840
14841 -- pragma Stream_Convert (
14842 -- [Entity =>] type_LOCAL_NAME,
14843 -- [Read =>] function_NAME,
14844 -- [Write =>] function NAME);
14845
14846 when Pragma_Stream_Convert => Stream_Convert : declare
14847
14848 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
14849 -- Check that the given argument is the name of a local function
14850 -- of one argument that is not overloaded earlier in the current
14851 -- local scope. A check is also made that the argument is a
14852 -- function with one parameter.
14853
14854 --------------------------------------
14855 -- Check_OK_Stream_Convert_Function --
14856 --------------------------------------
14857
14858 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
14859 Ent : Entity_Id;
14860
14861 begin
14862 Check_Arg_Is_Local_Name (Arg);
14863 Ent := Entity (Get_Pragma_Arg (Arg));
14864
14865 if Has_Homonym (Ent) then
14866 Error_Pragma_Arg
14867 ("argument for pragma% may not be overloaded", Arg);
14868 end if;
14869
14870 if Ekind (Ent) /= E_Function
14871 or else No (First_Formal (Ent))
14872 or else Present (Next_Formal (First_Formal (Ent)))
14873 then
14874 Error_Pragma_Arg
14875 ("argument for pragma% must be" &
14876 " function of one argument", Arg);
14877 end if;
14878 end Check_OK_Stream_Convert_Function;
14879
14880 -- Start of processing for Stream_Convert
14881
14882 begin
14883 GNAT_Pragma;
14884 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
14885 Check_Arg_Count (3);
14886 Check_Optional_Identifier (Arg1, Name_Entity);
14887 Check_Optional_Identifier (Arg2, Name_Read);
14888 Check_Optional_Identifier (Arg3, Name_Write);
14889 Check_Arg_Is_Local_Name (Arg1);
14890 Check_OK_Stream_Convert_Function (Arg2);
14891 Check_OK_Stream_Convert_Function (Arg3);
14892
14893 declare
14894 Typ : constant Entity_Id :=
14895 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
14896 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
14897 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
14898
14899 begin
14900 Check_First_Subtype (Arg1);
14901
14902 -- Check for too early or too late. Note that we don't enforce
14903 -- the rule about primitive operations in this case, since, as
14904 -- is the case for explicit stream attributes themselves, these
14905 -- restrictions are not appropriate. Note that the chaining of
14906 -- the pragma by Rep_Item_Too_Late is actually the critical
14907 -- processing done for this pragma.
14908
14909 if Rep_Item_Too_Early (Typ, N)
14910 or else
14911 Rep_Item_Too_Late (Typ, N, FOnly => True)
14912 then
14913 return;
14914 end if;
14915
14916 -- Return if previous error
14917
14918 if Etype (Typ) = Any_Type
14919 or else
14920 Etype (Read) = Any_Type
14921 or else
14922 Etype (Write) = Any_Type
14923 then
14924 return;
14925 end if;
14926
14927 -- Error checks
14928
14929 if Underlying_Type (Etype (Read)) /= Typ then
14930 Error_Pragma_Arg
14931 ("incorrect return type for function&", Arg2);
14932 end if;
14933
14934 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
14935 Error_Pragma_Arg
14936 ("incorrect parameter type for function&", Arg3);
14937 end if;
14938
14939 if Underlying_Type (Etype (First_Formal (Read))) /=
14940 Underlying_Type (Etype (Write))
14941 then
14942 Error_Pragma_Arg
14943 ("result type of & does not match Read parameter type",
14944 Arg3);
14945 end if;
14946 end;
14947 end Stream_Convert;
14948
14949 ------------------
14950 -- Style_Checks --
14951 ------------------
14952
14953 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14954
14955 -- This is processed by the parser since some of the style checks
14956 -- take place during source scanning and parsing. This means that
14957 -- we don't need to issue error messages here.
14958
14959 when Pragma_Style_Checks => Style_Checks : declare
14960 A : constant Node_Id := Get_Pragma_Arg (Arg1);
14961 S : String_Id;
14962 C : Char_Code;
14963
14964 begin
14965 GNAT_Pragma;
14966 Check_No_Identifiers;
14967
14968 -- Two argument form
14969
14970 if Arg_Count = 2 then
14971 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14972
14973 declare
14974 E_Id : Node_Id;
14975 E : Entity_Id;
14976
14977 begin
14978 E_Id := Get_Pragma_Arg (Arg2);
14979 Analyze (E_Id);
14980
14981 if not Is_Entity_Name (E_Id) then
14982 Error_Pragma_Arg
14983 ("second argument of pragma% must be entity name",
14984 Arg2);
14985 end if;
14986
14987 E := Entity (E_Id);
14988
14989 if not Ignore_Style_Checks_Pragmas then
14990 if E = Any_Id then
14991 return;
14992 else
14993 loop
14994 Set_Suppress_Style_Checks
14995 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
14996 exit when No (Homonym (E));
14997 E := Homonym (E);
14998 end loop;
14999 end if;
15000 end if;
15001 end;
15002
15003 -- One argument form
15004
15005 else
15006 Check_Arg_Count (1);
15007
15008 if Nkind (A) = N_String_Literal then
15009 S := Strval (A);
15010
15011 declare
15012 Slen : constant Natural := Natural (String_Length (S));
15013 Options : String (1 .. Slen);
15014 J : Natural;
15015
15016 begin
15017 J := 1;
15018 loop
15019 C := Get_String_Char (S, Int (J));
15020 exit when not In_Character_Range (C);
15021 Options (J) := Get_Character (C);
15022
15023 -- If at end of string, set options. As per discussion
15024 -- above, no need to check for errors, since we issued
15025 -- them in the parser.
15026
15027 if J = Slen then
15028 if not Ignore_Style_Checks_Pragmas then
15029 Set_Style_Check_Options (Options);
15030 end if;
15031
15032 exit;
15033 end if;
15034
15035 J := J + 1;
15036 end loop;
15037 end;
15038
15039 elsif Nkind (A) = N_Identifier then
15040 if Chars (A) = Name_All_Checks then
15041 if not Ignore_Style_Checks_Pragmas then
15042 if GNAT_Mode then
15043 Set_GNAT_Style_Check_Options;
15044 else
15045 Set_Default_Style_Check_Options;
15046 end if;
15047 end if;
15048
15049 elsif Chars (A) = Name_On then
15050 if not Ignore_Style_Checks_Pragmas then
15051 Style_Check := True;
15052 end if;
15053
15054 elsif Chars (A) = Name_Off then
15055 if not Ignore_Style_Checks_Pragmas then
15056 Style_Check := False;
15057 end if;
15058 end if;
15059 end if;
15060 end if;
15061 end Style_Checks;
15062
15063 --------------
15064 -- Subtitle --
15065 --------------
15066
15067 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
15068
15069 when Pragma_Subtitle =>
15070 GNAT_Pragma;
15071 Check_Arg_Count (1);
15072 Check_Optional_Identifier (Arg1, Name_Subtitle);
15073 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
15074 Store_Note (N);
15075
15076 --------------
15077 -- Suppress --
15078 --------------
15079
15080 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
15081
15082 when Pragma_Suppress =>
15083 Process_Suppress_Unsuppress (True);
15084
15085 ------------------
15086 -- Suppress_All --
15087 ------------------
15088
15089 -- pragma Suppress_All;
15090
15091 -- The only check made here is that the pragma has no arguments.
15092 -- There are no placement rules, and the processing required (setting
15093 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
15094 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
15095 -- then creates and inserts a pragma Suppress (All_Checks).
15096
15097 when Pragma_Suppress_All =>
15098 GNAT_Pragma;
15099 Check_Arg_Count (0);
15100
15101 -------------------------
15102 -- Suppress_Debug_Info --
15103 -------------------------
15104
15105 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
15106
15107 when Pragma_Suppress_Debug_Info =>
15108 GNAT_Pragma;
15109 Check_Arg_Count (1);
15110 Check_Optional_Identifier (Arg1, Name_Entity);
15111 Check_Arg_Is_Local_Name (Arg1);
15112 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
15113
15114 ----------------------------------
15115 -- Suppress_Exception_Locations --
15116 ----------------------------------
15117
15118 -- pragma Suppress_Exception_Locations;
15119
15120 when Pragma_Suppress_Exception_Locations =>
15121 GNAT_Pragma;
15122 Check_Arg_Count (0);
15123 Check_Valid_Configuration_Pragma;
15124 Exception_Locations_Suppressed := True;
15125
15126 -----------------------------
15127 -- Suppress_Initialization --
15128 -----------------------------
15129
15130 -- pragma Suppress_Initialization ([Entity =>] type_Name);
15131
15132 when Pragma_Suppress_Initialization => Suppress_Init : declare
15133 E_Id : Node_Id;
15134 E : Entity_Id;
15135
15136 begin
15137 GNAT_Pragma;
15138 Check_Arg_Count (1);
15139 Check_Optional_Identifier (Arg1, Name_Entity);
15140 Check_Arg_Is_Local_Name (Arg1);
15141
15142 E_Id := Get_Pragma_Arg (Arg1);
15143
15144 if Etype (E_Id) = Any_Type then
15145 return;
15146 end if;
15147
15148 E := Entity (E_Id);
15149
15150 if not Is_Type (E) then
15151 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
15152 end if;
15153
15154 if Rep_Item_Too_Early (E, N)
15155 or else
15156 Rep_Item_Too_Late (E, N, FOnly => True)
15157 then
15158 return;
15159 end if;
15160
15161 -- For incomplete/private type, set flag on full view
15162
15163 if Is_Incomplete_Or_Private_Type (E) then
15164 if No (Full_View (Base_Type (E))) then
15165 Error_Pragma_Arg
15166 ("argument of pragma% cannot be an incomplete type", Arg1);
15167 else
15168 Set_Suppress_Initialization (Full_View (Base_Type (E)));
15169 end if;
15170
15171 -- For first subtype, set flag on base type
15172
15173 elsif Is_First_Subtype (E) then
15174 Set_Suppress_Initialization (Base_Type (E));
15175
15176 -- For other than first subtype, set flag on subtype itself
15177
15178 else
15179 Set_Suppress_Initialization (E);
15180 end if;
15181 end Suppress_Init;
15182
15183 -----------------
15184 -- System_Name --
15185 -----------------
15186
15187 -- pragma System_Name (DIRECT_NAME);
15188
15189 -- Syntax check: one argument, which must be the identifier GNAT or
15190 -- the identifier GCC, no other identifiers are acceptable.
15191
15192 when Pragma_System_Name =>
15193 GNAT_Pragma;
15194 Check_No_Identifiers;
15195 Check_Arg_Count (1);
15196 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
15197
15198 -----------------------------
15199 -- Task_Dispatching_Policy --
15200 -----------------------------
15201
15202 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
15203
15204 when Pragma_Task_Dispatching_Policy => declare
15205 DP : Character;
15206
15207 begin
15208 Check_Ada_83_Warning;
15209 Check_Arg_Count (1);
15210 Check_No_Identifiers;
15211 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
15212 Check_Valid_Configuration_Pragma;
15213 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15214 DP := Fold_Upper (Name_Buffer (1));
15215
15216 if Task_Dispatching_Policy /= ' '
15217 and then Task_Dispatching_Policy /= DP
15218 then
15219 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
15220 Error_Pragma
15221 ("task dispatching policy incompatible with policy#");
15222
15223 -- Set new policy, but always preserve System_Location since we
15224 -- like the error message with the run time name.
15225
15226 else
15227 Task_Dispatching_Policy := DP;
15228
15229 if Task_Dispatching_Policy_Sloc /= System_Location then
15230 Task_Dispatching_Policy_Sloc := Loc;
15231 end if;
15232 end if;
15233 end;
15234
15235 ---------------
15236 -- Task_Info --
15237 ---------------
15238
15239 -- pragma Task_Info (EXPRESSION);
15240
15241 when Pragma_Task_Info => Task_Info : declare
15242 P : constant Node_Id := Parent (N);
15243 Ent : Entity_Id;
15244
15245 begin
15246 GNAT_Pragma;
15247
15248 if Nkind (P) /= N_Task_Definition then
15249 Error_Pragma ("pragma% must appear in task definition");
15250 end if;
15251
15252 Check_No_Identifiers;
15253 Check_Arg_Count (1);
15254
15255 Analyze_And_Resolve
15256 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
15257
15258 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
15259 return;
15260 end if;
15261
15262 Ent := Defining_Identifier (Parent (P));
15263
15264 -- Check duplicate pragma before we chain the pragma in the Rep
15265 -- Item chain of Ent.
15266
15267 if Has_Rep_Pragma
15268 (Ent, Name_Task_Info, Check_Parents => False)
15269 then
15270 Error_Pragma ("duplicate pragma% not allowed");
15271 end if;
15272
15273 Record_Rep_Item (Ent, N);
15274 end Task_Info;
15275
15276 ---------------
15277 -- Task_Name --
15278 ---------------
15279
15280 -- pragma Task_Name (string_EXPRESSION);
15281
15282 when Pragma_Task_Name => Task_Name : declare
15283 P : constant Node_Id := Parent (N);
15284 Arg : Node_Id;
15285 Ent : Entity_Id;
15286
15287 begin
15288 Check_No_Identifiers;
15289 Check_Arg_Count (1);
15290
15291 Arg := Get_Pragma_Arg (Arg1);
15292
15293 -- The expression is used in the call to Create_Task, and must be
15294 -- expanded there, not in the context of the current spec. It must
15295 -- however be analyzed to capture global references, in case it
15296 -- appears in a generic context.
15297
15298 Preanalyze_And_Resolve (Arg, Standard_String);
15299
15300 if Nkind (P) /= N_Task_Definition then
15301 Pragma_Misplaced;
15302 end if;
15303
15304 Ent := Defining_Identifier (Parent (P));
15305
15306 -- Check duplicate pragma before we chain the pragma in the Rep
15307 -- Item chain of Ent.
15308
15309 if Has_Rep_Pragma
15310 (Ent, Name_Task_Name, Check_Parents => False)
15311 then
15312 Error_Pragma ("duplicate pragma% not allowed");
15313 end if;
15314
15315 Record_Rep_Item (Ent, N);
15316 end Task_Name;
15317
15318 ------------------
15319 -- Task_Storage --
15320 ------------------
15321
15322 -- pragma Task_Storage (
15323 -- [Task_Type =>] LOCAL_NAME,
15324 -- [Top_Guard =>] static_integer_EXPRESSION);
15325
15326 when Pragma_Task_Storage => Task_Storage : declare
15327 Args : Args_List (1 .. 2);
15328 Names : constant Name_List (1 .. 2) := (
15329 Name_Task_Type,
15330 Name_Top_Guard);
15331
15332 Task_Type : Node_Id renames Args (1);
15333 Top_Guard : Node_Id renames Args (2);
15334
15335 Ent : Entity_Id;
15336
15337 begin
15338 GNAT_Pragma;
15339 Gather_Associations (Names, Args);
15340
15341 if No (Task_Type) then
15342 Error_Pragma
15343 ("missing task_type argument for pragma%");
15344 end if;
15345
15346 Check_Arg_Is_Local_Name (Task_Type);
15347
15348 Ent := Entity (Task_Type);
15349
15350 if not Is_Task_Type (Ent) then
15351 Error_Pragma_Arg
15352 ("argument for pragma% must be task type", Task_Type);
15353 end if;
15354
15355 if No (Top_Guard) then
15356 Error_Pragma_Arg
15357 ("pragma% takes two arguments", Task_Type);
15358 else
15359 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
15360 end if;
15361
15362 Check_First_Subtype (Task_Type);
15363
15364 if Rep_Item_Too_Late (Ent, N) then
15365 raise Pragma_Exit;
15366 end if;
15367 end Task_Storage;
15368
15369 ---------------
15370 -- Test_Case --
15371 ---------------
15372
15373 -- pragma Test_Case
15374 -- ([Name =>] Static_String_EXPRESSION
15375 -- ,[Mode =>] MODE_TYPE
15376 -- [, Requires => Boolean_EXPRESSION]
15377 -- [, Ensures => Boolean_EXPRESSION]);
15378
15379 -- MODE_TYPE ::= Nominal | Robustness
15380
15381 when Pragma_Test_Case =>
15382 Check_Contract_Or_Test_Case;
15383
15384 --------------------------
15385 -- Thread_Local_Storage --
15386 --------------------------
15387
15388 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
15389
15390 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
15391 Id : Node_Id;
15392 E : Entity_Id;
15393
15394 begin
15395 GNAT_Pragma;
15396 Check_Arg_Count (1);
15397 Check_Optional_Identifier (Arg1, Name_Entity);
15398 Check_Arg_Is_Library_Level_Local_Name (Arg1);
15399
15400 Id := Get_Pragma_Arg (Arg1);
15401 Analyze (Id);
15402
15403 if not Is_Entity_Name (Id)
15404 or else Ekind (Entity (Id)) /= E_Variable
15405 then
15406 Error_Pragma_Arg ("local variable name required", Arg1);
15407 end if;
15408
15409 E := Entity (Id);
15410
15411 if Rep_Item_Too_Early (E, N)
15412 or else Rep_Item_Too_Late (E, N)
15413 then
15414 raise Pragma_Exit;
15415 end if;
15416
15417 Set_Has_Pragma_Thread_Local_Storage (E);
15418 Set_Has_Gigi_Rep_Item (E);
15419 end Thread_Local_Storage;
15420
15421 ----------------
15422 -- Time_Slice --
15423 ----------------
15424
15425 -- pragma Time_Slice (static_duration_EXPRESSION);
15426
15427 when Pragma_Time_Slice => Time_Slice : declare
15428 Val : Ureal;
15429 Nod : Node_Id;
15430
15431 begin
15432 GNAT_Pragma;
15433 Check_Arg_Count (1);
15434 Check_No_Identifiers;
15435 Check_In_Main_Program;
15436 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
15437
15438 if not Error_Posted (Arg1) then
15439 Nod := Next (N);
15440 while Present (Nod) loop
15441 if Nkind (Nod) = N_Pragma
15442 and then Pragma_Name (Nod) = Name_Time_Slice
15443 then
15444 Error_Msg_Name_1 := Pname;
15445 Error_Msg_N ("duplicate pragma% not permitted", Nod);
15446 end if;
15447
15448 Next (Nod);
15449 end loop;
15450 end if;
15451
15452 -- Process only if in main unit
15453
15454 if Get_Source_Unit (Loc) = Main_Unit then
15455 Opt.Time_Slice_Set := True;
15456 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
15457
15458 if Val <= Ureal_0 then
15459 Opt.Time_Slice_Value := 0;
15460
15461 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
15462 Opt.Time_Slice_Value := 1_000_000_000;
15463
15464 else
15465 Opt.Time_Slice_Value :=
15466 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
15467 end if;
15468 end if;
15469 end Time_Slice;
15470
15471 -----------
15472 -- Title --
15473 -----------
15474
15475 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
15476
15477 -- TITLING_OPTION ::=
15478 -- [Title =>] STRING_LITERAL
15479 -- | [Subtitle =>] STRING_LITERAL
15480
15481 when Pragma_Title => Title : declare
15482 Args : Args_List (1 .. 2);
15483 Names : constant Name_List (1 .. 2) := (
15484 Name_Title,
15485 Name_Subtitle);
15486
15487 begin
15488 GNAT_Pragma;
15489 Gather_Associations (Names, Args);
15490 Store_Note (N);
15491
15492 for J in 1 .. 2 loop
15493 if Present (Args (J)) then
15494 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
15495 end if;
15496 end loop;
15497 end Title;
15498
15499 ---------------------
15500 -- Unchecked_Union --
15501 ---------------------
15502
15503 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
15504
15505 when Pragma_Unchecked_Union => Unchecked_Union : declare
15506 Assoc : constant Node_Id := Arg1;
15507 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
15508 Typ : Entity_Id;
15509 Tdef : Node_Id;
15510 Clist : Node_Id;
15511 Vpart : Node_Id;
15512 Comp : Node_Id;
15513 Variant : Node_Id;
15514
15515 begin
15516 Ada_2005_Pragma;
15517 Check_No_Identifiers;
15518 Check_Arg_Count (1);
15519 Check_Arg_Is_Local_Name (Arg1);
15520
15521 Find_Type (Type_Id);
15522
15523 Typ := Entity (Type_Id);
15524
15525 if Typ = Any_Type
15526 or else Rep_Item_Too_Early (Typ, N)
15527 then
15528 return;
15529 else
15530 Typ := Underlying_Type (Typ);
15531 end if;
15532
15533 if Rep_Item_Too_Late (Typ, N) then
15534 return;
15535 end if;
15536
15537 Check_First_Subtype (Arg1);
15538
15539 -- Note remaining cases are references to a type in the current
15540 -- declarative part. If we find an error, we post the error on
15541 -- the relevant type declaration at an appropriate point.
15542
15543 if not Is_Record_Type (Typ) then
15544 Error_Msg_N ("unchecked union must be record type", Typ);
15545 return;
15546
15547 elsif Is_Tagged_Type (Typ) then
15548 Error_Msg_N ("unchecked union must not be tagged", Typ);
15549 return;
15550
15551 elsif not Has_Discriminants (Typ) then
15552 Error_Msg_N
15553 ("unchecked union must have one discriminant", Typ);
15554 return;
15555
15556 -- Note: in previous versions of GNAT we used to check for limited
15557 -- types and give an error, but in fact the standard does allow
15558 -- Unchecked_Union on limited types, so this check was removed.
15559
15560 -- Similarly, GNAT used to require that all discriminants have
15561 -- default values, but this is not mandated by the RM.
15562
15563 -- Proceed with basic error checks completed
15564
15565 else
15566 Tdef := Type_Definition (Declaration_Node (Typ));
15567 Clist := Component_List (Tdef);
15568
15569 -- Check presence of component list and variant part
15570
15571 if No (Clist) or else No (Variant_Part (Clist)) then
15572 Error_Msg_N
15573 ("unchecked union must have variant part", Tdef);
15574 return;
15575 end if;
15576
15577 -- Check components
15578
15579 Comp := First (Component_Items (Clist));
15580 while Present (Comp) loop
15581 Check_Component (Comp, Typ);
15582 Next (Comp);
15583 end loop;
15584
15585 -- Check variant part
15586
15587 Vpart := Variant_Part (Clist);
15588
15589 Variant := First (Variants (Vpart));
15590 while Present (Variant) loop
15591 Check_Variant (Variant, Typ);
15592 Next (Variant);
15593 end loop;
15594 end if;
15595
15596 Set_Is_Unchecked_Union (Typ);
15597 Set_Convention (Typ, Convention_C);
15598 Set_Has_Unchecked_Union (Base_Type (Typ));
15599 Set_Is_Unchecked_Union (Base_Type (Typ));
15600 end Unchecked_Union;
15601
15602 ------------------------
15603 -- Unimplemented_Unit --
15604 ------------------------
15605
15606 -- pragma Unimplemented_Unit;
15607
15608 -- Note: this only gives an error if we are generating code, or if
15609 -- we are in a generic library unit (where the pragma appears in the
15610 -- body, not in the spec).
15611
15612 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
15613 Cunitent : constant Entity_Id :=
15614 Cunit_Entity (Get_Source_Unit (Loc));
15615 Ent_Kind : constant Entity_Kind :=
15616 Ekind (Cunitent);
15617
15618 begin
15619 GNAT_Pragma;
15620 Check_Arg_Count (0);
15621
15622 if Operating_Mode = Generate_Code
15623 or else Ent_Kind = E_Generic_Function
15624 or else Ent_Kind = E_Generic_Procedure
15625 or else Ent_Kind = E_Generic_Package
15626 then
15627 Get_Name_String (Chars (Cunitent));
15628 Set_Casing (Mixed_Case);
15629 Write_Str (Name_Buffer (1 .. Name_Len));
15630 Write_Str (" is not supported in this configuration");
15631 Write_Eol;
15632 raise Unrecoverable_Error;
15633 end if;
15634 end Unimplemented_Unit;
15635
15636 ------------------------
15637 -- Universal_Aliasing --
15638 ------------------------
15639
15640 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
15641
15642 when Pragma_Universal_Aliasing => Universal_Alias : declare
15643 E_Id : Entity_Id;
15644
15645 begin
15646 GNAT_Pragma;
15647 Check_Arg_Count (1);
15648 Check_Optional_Identifier (Arg2, Name_Entity);
15649 Check_Arg_Is_Local_Name (Arg1);
15650 E_Id := Entity (Get_Pragma_Arg (Arg1));
15651
15652 if E_Id = Any_Type then
15653 return;
15654 elsif No (E_Id) or else not Is_Type (E_Id) then
15655 Error_Pragma_Arg ("pragma% requires type", Arg1);
15656 end if;
15657
15658 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
15659 Record_Rep_Item (E_Id, N);
15660 end Universal_Alias;
15661
15662 --------------------
15663 -- Universal_Data --
15664 --------------------
15665
15666 -- pragma Universal_Data [(library_unit_NAME)];
15667
15668 when Pragma_Universal_Data =>
15669 GNAT_Pragma;
15670
15671 -- If this is a configuration pragma, then set the universal
15672 -- addressing option, otherwise confirm that the pragma satisfies
15673 -- the requirements of library unit pragma placement and leave it
15674 -- to the GNAAMP back end to detect the pragma (avoids transitive
15675 -- setting of the option due to withed units).
15676
15677 if Is_Configuration_Pragma then
15678 Universal_Addressing_On_AAMP := True;
15679 else
15680 Check_Valid_Library_Unit_Pragma;
15681 end if;
15682
15683 if not AAMP_On_Target then
15684 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
15685 end if;
15686
15687 ----------------
15688 -- Unmodified --
15689 ----------------
15690
15691 -- pragma Unmodified (local_Name {, local_Name});
15692
15693 when Pragma_Unmodified => Unmodified : declare
15694 Arg_Node : Node_Id;
15695 Arg_Expr : Node_Id;
15696 Arg_Ent : Entity_Id;
15697
15698 begin
15699 GNAT_Pragma;
15700 Check_At_Least_N_Arguments (1);
15701
15702 -- Loop through arguments
15703
15704 Arg_Node := Arg1;
15705 while Present (Arg_Node) loop
15706 Check_No_Identifier (Arg_Node);
15707
15708 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
15709 -- in fact generate reference, so that the entity will have a
15710 -- reference, which will inhibit any warnings about it not
15711 -- being referenced, and also properly show up in the ali file
15712 -- as a reference. But this reference is recorded before the
15713 -- Has_Pragma_Unreferenced flag is set, so that no warning is
15714 -- generated for this reference.
15715
15716 Check_Arg_Is_Local_Name (Arg_Node);
15717 Arg_Expr := Get_Pragma_Arg (Arg_Node);
15718
15719 if Is_Entity_Name (Arg_Expr) then
15720 Arg_Ent := Entity (Arg_Expr);
15721
15722 if not Is_Assignable (Arg_Ent) then
15723 Error_Pragma_Arg
15724 ("pragma% can only be applied to a variable",
15725 Arg_Expr);
15726 else
15727 Set_Has_Pragma_Unmodified (Arg_Ent);
15728 end if;
15729 end if;
15730
15731 Next (Arg_Node);
15732 end loop;
15733 end Unmodified;
15734
15735 ------------------
15736 -- Unreferenced --
15737 ------------------
15738
15739 -- pragma Unreferenced (local_Name {, local_Name});
15740
15741 -- or when used in a context clause:
15742
15743 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
15744
15745 when Pragma_Unreferenced => Unreferenced : declare
15746 Arg_Node : Node_Id;
15747 Arg_Expr : Node_Id;
15748 Arg_Ent : Entity_Id;
15749 Citem : Node_Id;
15750
15751 begin
15752 GNAT_Pragma;
15753 Check_At_Least_N_Arguments (1);
15754
15755 -- Check case of appearing within context clause
15756
15757 if Is_In_Context_Clause then
15758
15759 -- The arguments must all be units mentioned in a with clause
15760 -- in the same context clause. Note we already checked (in
15761 -- Par.Prag) that the arguments are either identifiers or
15762 -- selected components.
15763
15764 Arg_Node := Arg1;
15765 while Present (Arg_Node) loop
15766 Citem := First (List_Containing (N));
15767 while Citem /= N loop
15768 if Nkind (Citem) = N_With_Clause
15769 and then
15770 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
15771 then
15772 Set_Has_Pragma_Unreferenced
15773 (Cunit_Entity
15774 (Get_Source_Unit
15775 (Library_Unit (Citem))));
15776 Set_Unit_Name
15777 (Get_Pragma_Arg (Arg_Node), Name (Citem));
15778 exit;
15779 end if;
15780
15781 Next (Citem);
15782 end loop;
15783
15784 if Citem = N then
15785 Error_Pragma_Arg
15786 ("argument of pragma% is not withed unit", Arg_Node);
15787 end if;
15788
15789 Next (Arg_Node);
15790 end loop;
15791
15792 -- Case of not in list of context items
15793
15794 else
15795 Arg_Node := Arg1;
15796 while Present (Arg_Node) loop
15797 Check_No_Identifier (Arg_Node);
15798
15799 -- Note: the analyze call done by Check_Arg_Is_Local_Name
15800 -- will in fact generate reference, so that the entity will
15801 -- have a reference, which will inhibit any warnings about
15802 -- it not being referenced, and also properly show up in the
15803 -- ali file as a reference. But this reference is recorded
15804 -- before the Has_Pragma_Unreferenced flag is set, so that
15805 -- no warning is generated for this reference.
15806
15807 Check_Arg_Is_Local_Name (Arg_Node);
15808 Arg_Expr := Get_Pragma_Arg (Arg_Node);
15809
15810 if Is_Entity_Name (Arg_Expr) then
15811 Arg_Ent := Entity (Arg_Expr);
15812
15813 -- If the entity is overloaded, the pragma applies to the
15814 -- most recent overloading, as documented. In this case,
15815 -- name resolution does not generate a reference, so it
15816 -- must be done here explicitly.
15817
15818 if Is_Overloaded (Arg_Expr) then
15819 Generate_Reference (Arg_Ent, N);
15820 end if;
15821
15822 Set_Has_Pragma_Unreferenced (Arg_Ent);
15823 end if;
15824
15825 Next (Arg_Node);
15826 end loop;
15827 end if;
15828 end Unreferenced;
15829
15830 --------------------------
15831 -- Unreferenced_Objects --
15832 --------------------------
15833
15834 -- pragma Unreferenced_Objects (local_Name {, local_Name});
15835
15836 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
15837 Arg_Node : Node_Id;
15838 Arg_Expr : Node_Id;
15839
15840 begin
15841 GNAT_Pragma;
15842 Check_At_Least_N_Arguments (1);
15843
15844 Arg_Node := Arg1;
15845 while Present (Arg_Node) loop
15846 Check_No_Identifier (Arg_Node);
15847 Check_Arg_Is_Local_Name (Arg_Node);
15848 Arg_Expr := Get_Pragma_Arg (Arg_Node);
15849
15850 if not Is_Entity_Name (Arg_Expr)
15851 or else not Is_Type (Entity (Arg_Expr))
15852 then
15853 Error_Pragma_Arg
15854 ("argument for pragma% must be type or subtype", Arg_Node);
15855 end if;
15856
15857 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
15858 Next (Arg_Node);
15859 end loop;
15860 end Unreferenced_Objects;
15861
15862 ------------------------------
15863 -- Unreserve_All_Interrupts --
15864 ------------------------------
15865
15866 -- pragma Unreserve_All_Interrupts;
15867
15868 when Pragma_Unreserve_All_Interrupts =>
15869 GNAT_Pragma;
15870 Check_Arg_Count (0);
15871
15872 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
15873 Unreserve_All_Interrupts := True;
15874 end if;
15875
15876 ----------------
15877 -- Unsuppress --
15878 ----------------
15879
15880 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
15881
15882 when Pragma_Unsuppress =>
15883 Ada_2005_Pragma;
15884 Process_Suppress_Unsuppress (False);
15885
15886 -------------------
15887 -- Use_VADS_Size --
15888 -------------------
15889
15890 -- pragma Use_VADS_Size;
15891
15892 when Pragma_Use_VADS_Size =>
15893 GNAT_Pragma;
15894 Check_Arg_Count (0);
15895 Check_Valid_Configuration_Pragma;
15896 Use_VADS_Size := True;
15897
15898 ---------------------
15899 -- Validity_Checks --
15900 ---------------------
15901
15902 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
15903
15904 when Pragma_Validity_Checks => Validity_Checks : declare
15905 A : constant Node_Id := Get_Pragma_Arg (Arg1);
15906 S : String_Id;
15907 C : Char_Code;
15908
15909 begin
15910 GNAT_Pragma;
15911 Check_Arg_Count (1);
15912 Check_No_Identifiers;
15913
15914 if Nkind (A) = N_String_Literal then
15915 S := Strval (A);
15916
15917 declare
15918 Slen : constant Natural := Natural (String_Length (S));
15919 Options : String (1 .. Slen);
15920 J : Natural;
15921
15922 begin
15923 J := 1;
15924 loop
15925 C := Get_String_Char (S, Int (J));
15926 exit when not In_Character_Range (C);
15927 Options (J) := Get_Character (C);
15928
15929 if J = Slen then
15930 Set_Validity_Check_Options (Options);
15931 exit;
15932 else
15933 J := J + 1;
15934 end if;
15935 end loop;
15936 end;
15937
15938 elsif Nkind (A) = N_Identifier then
15939 if Chars (A) = Name_All_Checks then
15940 Set_Validity_Check_Options ("a");
15941 elsif Chars (A) = Name_On then
15942 Validity_Checks_On := True;
15943 elsif Chars (A) = Name_Off then
15944 Validity_Checks_On := False;
15945 end if;
15946 end if;
15947 end Validity_Checks;
15948
15949 --------------
15950 -- Volatile --
15951 --------------
15952
15953 -- pragma Volatile (LOCAL_NAME);
15954
15955 when Pragma_Volatile =>
15956 Process_Atomic_Shared_Volatile;
15957
15958 -------------------------
15959 -- Volatile_Components --
15960 -------------------------
15961
15962 -- pragma Volatile_Components (array_LOCAL_NAME);
15963
15964 -- Volatile is handled by the same circuit as Atomic_Components
15965
15966 --------------
15967 -- Warnings --
15968 --------------
15969
15970 -- pragma Warnings (On | Off);
15971 -- pragma Warnings (On | Off, LOCAL_NAME);
15972 -- pragma Warnings (static_string_EXPRESSION);
15973 -- pragma Warnings (On | Off, STRING_LITERAL);
15974
15975 when Pragma_Warnings => Warnings : begin
15976 GNAT_Pragma;
15977 Check_At_Least_N_Arguments (1);
15978 Check_No_Identifiers;
15979
15980 -- If debug flag -gnatd.i is set, pragma is ignored
15981
15982 if Debug_Flag_Dot_I then
15983 return;
15984 end if;
15985
15986 -- Process various forms of the pragma
15987
15988 declare
15989 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
15990
15991 begin
15992 -- One argument case
15993
15994 if Arg_Count = 1 then
15995
15996 -- On/Off one argument case was processed by parser
15997
15998 if Nkind (Argx) = N_Identifier
15999 and then
16000 (Chars (Argx) = Name_On
16001 or else
16002 Chars (Argx) = Name_Off)
16003 then
16004 null;
16005
16006 -- One argument case must be ON/OFF or static string expr
16007
16008 elsif not Is_Static_String_Expression (Arg1) then
16009 Error_Pragma_Arg
16010 ("argument of pragma% must be On/Off or " &
16011 "static string expression", Arg1);
16012
16013 -- One argument string expression case
16014
16015 else
16016 declare
16017 Lit : constant Node_Id := Expr_Value_S (Argx);
16018 Str : constant String_Id := Strval (Lit);
16019 Len : constant Nat := String_Length (Str);
16020 C : Char_Code;
16021 J : Nat;
16022 OK : Boolean;
16023 Chr : Character;
16024
16025 begin
16026 J := 1;
16027 while J <= Len loop
16028 C := Get_String_Char (Str, J);
16029 OK := In_Character_Range (C);
16030
16031 if OK then
16032 Chr := Get_Character (C);
16033
16034 -- Dash case: only -Wxxx is accepted
16035
16036 if J = 1
16037 and then J < Len
16038 and then Chr = '-'
16039 then
16040 J := J + 1;
16041 C := Get_String_Char (Str, J);
16042 Chr := Get_Character (C);
16043 exit when Chr = 'W';
16044 OK := False;
16045
16046 -- Dot case
16047
16048 elsif J < Len and then Chr = '.' then
16049 J := J + 1;
16050 C := Get_String_Char (Str, J);
16051 Chr := Get_Character (C);
16052
16053 if not Set_Dot_Warning_Switch (Chr) then
16054 Error_Pragma_Arg
16055 ("invalid warning switch character " &
16056 '.' & Chr, Arg1);
16057 end if;
16058
16059 -- Non-Dot case
16060
16061 else
16062 OK := Set_Warning_Switch (Chr);
16063 end if;
16064 end if;
16065
16066 if not OK then
16067 Error_Pragma_Arg
16068 ("invalid warning switch character " & Chr,
16069 Arg1);
16070 end if;
16071
16072 J := J + 1;
16073 end loop;
16074 end;
16075 end if;
16076
16077 -- Two or more arguments (must be two)
16078
16079 else
16080 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
16081 Check_At_Most_N_Arguments (2);
16082
16083 declare
16084 E_Id : Node_Id;
16085 E : Entity_Id;
16086 Err : Boolean;
16087
16088 begin
16089 E_Id := Get_Pragma_Arg (Arg2);
16090 Analyze (E_Id);
16091
16092 -- In the expansion of an inlined body, a reference to
16093 -- the formal may be wrapped in a conversion if the
16094 -- actual is a conversion. Retrieve the real entity name.
16095
16096 if (In_Instance_Body or In_Inlined_Body)
16097 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
16098 then
16099 E_Id := Expression (E_Id);
16100 end if;
16101
16102 -- Entity name case
16103
16104 if Is_Entity_Name (E_Id) then
16105 E := Entity (E_Id);
16106
16107 if E = Any_Id then
16108 return;
16109 else
16110 loop
16111 Set_Warnings_Off
16112 (E, (Chars (Get_Pragma_Arg (Arg1)) =
16113 Name_Off));
16114
16115 -- For OFF case, make entry in warnings off
16116 -- pragma table for later processing. But we do
16117 -- not do that within an instance, since these
16118 -- warnings are about what is needed in the
16119 -- template, not an instance of it.
16120
16121 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
16122 and then Warn_On_Warnings_Off
16123 and then not In_Instance
16124 then
16125 Warnings_Off_Pragmas.Append ((N, E));
16126 end if;
16127
16128 if Is_Enumeration_Type (E) then
16129 declare
16130 Lit : Entity_Id;
16131 begin
16132 Lit := First_Literal (E);
16133 while Present (Lit) loop
16134 Set_Warnings_Off (Lit);
16135 Next_Literal (Lit);
16136 end loop;
16137 end;
16138 end if;
16139
16140 exit when No (Homonym (E));
16141 E := Homonym (E);
16142 end loop;
16143 end if;
16144
16145 -- Error if not entity or static string literal case
16146
16147 elsif not Is_Static_String_Expression (Arg2) then
16148 Error_Pragma_Arg
16149 ("second argument of pragma% must be entity " &
16150 "name or static string expression", Arg2);
16151
16152 -- String literal case
16153
16154 else
16155 String_To_Name_Buffer
16156 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
16157
16158 -- Note on configuration pragma case: If this is a
16159 -- configuration pragma, then for an OFF pragma, we
16160 -- just set Config True in the call, which is all
16161 -- that needs to be done. For the case of ON, this
16162 -- is normally an error, unless it is canceling the
16163 -- effect of a previous OFF pragma in the same file.
16164 -- In any other case, an error will be signalled (ON
16165 -- with no matching OFF).
16166
16167 -- Note: We set Used if we are inside a generic to
16168 -- disable the test that the non-config case actually
16169 -- cancels a warning. That's because we can't be sure
16170 -- there isn't an instantiation in some other unit
16171 -- where a warning is suppressed.
16172
16173 -- We could do a little better here by checking if the
16174 -- generic unit we are inside is public, but for now
16175 -- we don't bother with that refinement.
16176
16177 if Chars (Argx) = Name_Off then
16178 Set_Specific_Warning_Off
16179 (Loc, Name_Buffer (1 .. Name_Len),
16180 Config => Is_Configuration_Pragma,
16181 Used => Inside_A_Generic or else In_Instance);
16182
16183 elsif Chars (Argx) = Name_On then
16184 Set_Specific_Warning_On
16185 (Loc, Name_Buffer (1 .. Name_Len), Err);
16186
16187 if Err then
16188 Error_Msg
16189 ("??pragma Warnings On with no " &
16190 "matching Warnings Off",
16191 Loc);
16192 end if;
16193 end if;
16194 end if;
16195 end;
16196 end if;
16197 end;
16198 end Warnings;
16199
16200 -------------------
16201 -- Weak_External --
16202 -------------------
16203
16204 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
16205
16206 when Pragma_Weak_External => Weak_External : declare
16207 Ent : Entity_Id;
16208
16209 begin
16210 GNAT_Pragma;
16211 Check_Arg_Count (1);
16212 Check_Optional_Identifier (Arg1, Name_Entity);
16213 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16214 Ent := Entity (Get_Pragma_Arg (Arg1));
16215
16216 if Rep_Item_Too_Early (Ent, N) then
16217 return;
16218 else
16219 Ent := Underlying_Type (Ent);
16220 end if;
16221
16222 -- The only processing required is to link this item on to the
16223 -- list of rep items for the given entity. This is accomplished
16224 -- by the call to Rep_Item_Too_Late (when no error is detected
16225 -- and False is returned).
16226
16227 if Rep_Item_Too_Late (Ent, N) then
16228 return;
16229 else
16230 Set_Has_Gigi_Rep_Item (Ent);
16231 end if;
16232 end Weak_External;
16233
16234 -----------------------------
16235 -- Wide_Character_Encoding --
16236 -----------------------------
16237
16238 -- pragma Wide_Character_Encoding (IDENTIFIER);
16239
16240 when Pragma_Wide_Character_Encoding =>
16241 GNAT_Pragma;
16242
16243 -- Nothing to do, handled in parser. Note that we do not enforce
16244 -- configuration pragma placement, this pragma can appear at any
16245 -- place in the source, allowing mixed encodings within a single
16246 -- source program.
16247
16248 null;
16249
16250 --------------------
16251 -- Unknown_Pragma --
16252 --------------------
16253
16254 -- Should be impossible, since the case of an unknown pragma is
16255 -- separately processed before the case statement is entered.
16256
16257 when Unknown_Pragma =>
16258 raise Program_Error;
16259 end case;
16260
16261 -- AI05-0144: detect dangerous order dependence. Disabled for now,
16262 -- until AI is formally approved.
16263
16264 -- Check_Order_Dependence;
16265
16266 exception
16267 when Pragma_Exit => null;
16268 end Analyze_Pragma;
16269
16270 --------------------
16271 -- Check_Disabled --
16272 --------------------
16273
16274 function Check_Disabled (Nam : Name_Id) return Boolean is
16275 PP : Node_Id;
16276
16277 begin
16278 -- Loop through entries in check policy list
16279
16280 PP := Opt.Check_Policy_List;
16281 loop
16282 -- If there are no specific entries that matched, then nothing is
16283 -- disabled, so return False.
16284
16285 if No (PP) then
16286 return False;
16287
16288 -- Here we have an entry see if it matches
16289
16290 else
16291 declare
16292 PPA : constant List_Id := Pragma_Argument_Associations (PP);
16293 begin
16294 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
16295 return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
16296 else
16297 PP := Next_Pragma (PP);
16298 end if;
16299 end;
16300 end if;
16301 end loop;
16302 end Check_Disabled;
16303
16304 -------------------
16305 -- Check_Enabled --
16306 -------------------
16307
16308 function Check_Enabled (Nam : Name_Id) return Boolean is
16309 PP : Node_Id;
16310
16311 begin
16312 -- Loop through entries in check policy list
16313
16314 PP := Opt.Check_Policy_List;
16315 loop
16316 -- If there are no specific entries that matched, then we let the
16317 -- setting of assertions govern. Note that this provides the needed
16318 -- compatibility with the RM for the cases of assertion, invariant,
16319 -- precondition, predicate, and postcondition.
16320
16321 if No (PP) then
16322 return Assertions_Enabled;
16323
16324 -- Here we have an entry see if it matches
16325
16326 else
16327 declare
16328 PPA : constant List_Id := Pragma_Argument_Associations (PP);
16329
16330 begin
16331 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
16332 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
16333 when Name_On | Name_Check =>
16334 return True;
16335 when Name_Off | Name_Ignore =>
16336 return False;
16337 when others =>
16338 raise Program_Error;
16339 end case;
16340
16341 else
16342 PP := Next_Pragma (PP);
16343 end if;
16344 end;
16345 end if;
16346 end loop;
16347 end Check_Enabled;
16348
16349 ---------------------------------
16350 -- Delay_Config_Pragma_Analyze --
16351 ---------------------------------
16352
16353 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
16354 begin
16355 return Pragma_Name (N) = Name_Interrupt_State
16356 or else
16357 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
16358 end Delay_Config_Pragma_Analyze;
16359
16360 -------------------------
16361 -- Get_Base_Subprogram --
16362 -------------------------
16363
16364 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
16365 Result : Entity_Id;
16366
16367 begin
16368 -- Follow subprogram renaming chain
16369
16370 Result := Def_Id;
16371
16372 if Is_Subprogram (Result)
16373 and then
16374 Nkind (Parent (Declaration_Node (Result))) =
16375 N_Subprogram_Renaming_Declaration
16376 and then Present (Alias (Result))
16377 then
16378 Result := Alias (Result);
16379 end if;
16380
16381 return Result;
16382 end Get_Base_Subprogram;
16383
16384 ----------------
16385 -- Initialize --
16386 ----------------
16387
16388 procedure Initialize is
16389 begin
16390 Externals.Init;
16391 end Initialize;
16392
16393 -----------------------------
16394 -- Is_Config_Static_String --
16395 -----------------------------
16396
16397 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
16398
16399 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
16400 -- This is an internal recursive function that is just like the outer
16401 -- function except that it adds the string to the name buffer rather
16402 -- than placing the string in the name buffer.
16403
16404 ------------------------------
16405 -- Add_Config_Static_String --
16406 ------------------------------
16407
16408 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
16409 N : Node_Id;
16410 C : Char_Code;
16411
16412 begin
16413 N := Arg;
16414
16415 if Nkind (N) = N_Op_Concat then
16416 if Add_Config_Static_String (Left_Opnd (N)) then
16417 N := Right_Opnd (N);
16418 else
16419 return False;
16420 end if;
16421 end if;
16422
16423 if Nkind (N) /= N_String_Literal then
16424 Error_Msg_N ("string literal expected for pragma argument", N);
16425 return False;
16426
16427 else
16428 for J in 1 .. String_Length (Strval (N)) loop
16429 C := Get_String_Char (Strval (N), J);
16430
16431 if not In_Character_Range (C) then
16432 Error_Msg
16433 ("string literal contains invalid wide character",
16434 Sloc (N) + 1 + Source_Ptr (J));
16435 return False;
16436 end if;
16437
16438 Add_Char_To_Name_Buffer (Get_Character (C));
16439 end loop;
16440 end if;
16441
16442 return True;
16443 end Add_Config_Static_String;
16444
16445 -- Start of processing for Is_Config_Static_String
16446
16447 begin
16448
16449 Name_Len := 0;
16450 return Add_Config_Static_String (Arg);
16451 end Is_Config_Static_String;
16452
16453 -----------------------------------------
16454 -- Is_Non_Significant_Pragma_Reference --
16455 -----------------------------------------
16456
16457 -- This function makes use of the following static table which indicates
16458 -- whether appearance of some name in a given pragma is to be considered
16459 -- as a reference for the purposes of warnings about unreferenced objects.
16460
16461 -- -1 indicates that references in any argument position are significant
16462 -- 0 indicates that appearance in any argument is not significant
16463 -- +n indicates that appearance as argument n is significant, but all
16464 -- other arguments are not significant
16465 -- 99 special processing required (e.g. for pragma Check)
16466
16467 Sig_Flags : constant array (Pragma_Id) of Int :=
16468 (Pragma_AST_Entry => -1,
16469 Pragma_Abort_Defer => -1,
16470 Pragma_Abstract_State => -1,
16471 Pragma_Ada_83 => -1,
16472 Pragma_Ada_95 => -1,
16473 Pragma_Ada_05 => -1,
16474 Pragma_Ada_2005 => -1,
16475 Pragma_Ada_12 => -1,
16476 Pragma_Ada_2012 => -1,
16477 Pragma_All_Calls_Remote => -1,
16478 Pragma_Annotate => -1,
16479 Pragma_Assert => -1,
16480 Pragma_Assert_And_Cut => -1,
16481 Pragma_Assertion_Policy => 0,
16482 Pragma_Assume => 0,
16483 Pragma_Assume_No_Invalid_Values => 0,
16484 Pragma_Attribute_Definition => +3,
16485 Pragma_Asynchronous => -1,
16486 Pragma_Atomic => 0,
16487 Pragma_Atomic_Components => 0,
16488 Pragma_Attach_Handler => -1,
16489 Pragma_Check => 99,
16490 Pragma_Check_Float_Overflow => 0,
16491 Pragma_Check_Name => 0,
16492 Pragma_Check_Policy => 0,
16493 Pragma_CIL_Constructor => -1,
16494 Pragma_CPP_Class => 0,
16495 Pragma_CPP_Constructor => 0,
16496 Pragma_CPP_Virtual => 0,
16497 Pragma_CPP_Vtable => 0,
16498 Pragma_CPU => -1,
16499 Pragma_C_Pass_By_Copy => 0,
16500 Pragma_Comment => 0,
16501 Pragma_Common_Object => -1,
16502 Pragma_Compile_Time_Error => -1,
16503 Pragma_Compile_Time_Warning => -1,
16504 Pragma_Compiler_Unit => 0,
16505 Pragma_Complete_Representation => 0,
16506 Pragma_Complex_Representation => 0,
16507 Pragma_Component_Alignment => -1,
16508 Pragma_Contract_Case => -1,
16509 Pragma_Contract_Cases => -1,
16510 Pragma_Controlled => 0,
16511 Pragma_Convention => 0,
16512 Pragma_Convention_Identifier => 0,
16513 Pragma_Debug => -1,
16514 Pragma_Debug_Policy => 0,
16515 Pragma_Detect_Blocking => -1,
16516 Pragma_Default_Storage_Pool => -1,
16517 Pragma_Disable_Atomic_Synchronization => -1,
16518 Pragma_Discard_Names => 0,
16519 Pragma_Dispatching_Domain => -1,
16520 Pragma_Elaborate => -1,
16521 Pragma_Elaborate_All => -1,
16522 Pragma_Elaborate_Body => -1,
16523 Pragma_Elaboration_Checks => -1,
16524 Pragma_Eliminate => -1,
16525 Pragma_Enable_Atomic_Synchronization => -1,
16526 Pragma_Export => -1,
16527 Pragma_Export_Exception => -1,
16528 Pragma_Export_Function => -1,
16529 Pragma_Export_Object => -1,
16530 Pragma_Export_Procedure => -1,
16531 Pragma_Export_Value => -1,
16532 Pragma_Export_Valued_Procedure => -1,
16533 Pragma_Extend_System => -1,
16534 Pragma_Extensions_Allowed => -1,
16535 Pragma_External => -1,
16536 Pragma_Favor_Top_Level => -1,
16537 Pragma_External_Name_Casing => -1,
16538 Pragma_Fast_Math => -1,
16539 Pragma_Finalize_Storage_Only => 0,
16540 Pragma_Float_Representation => 0,
16541 Pragma_Global => -1,
16542 Pragma_Ident => -1,
16543 Pragma_Implementation_Defined => -1,
16544 Pragma_Implemented => -1,
16545 Pragma_Implicit_Packing => 0,
16546 Pragma_Import => +2,
16547 Pragma_Import_Exception => 0,
16548 Pragma_Import_Function => 0,
16549 Pragma_Import_Object => 0,
16550 Pragma_Import_Procedure => 0,
16551 Pragma_Import_Valued_Procedure => 0,
16552 Pragma_Independent => 0,
16553 Pragma_Independent_Components => 0,
16554 Pragma_Initialize_Scalars => -1,
16555 Pragma_Inline => 0,
16556 Pragma_Inline_Always => 0,
16557 Pragma_Inline_Generic => 0,
16558 Pragma_Inspection_Point => -1,
16559 Pragma_Interface => +2,
16560 Pragma_Interface_Name => +2,
16561 Pragma_Interrupt_Handler => -1,
16562 Pragma_Interrupt_Priority => -1,
16563 Pragma_Interrupt_State => -1,
16564 Pragma_Invariant => -1,
16565 Pragma_Java_Constructor => -1,
16566 Pragma_Java_Interface => -1,
16567 Pragma_Keep_Names => 0,
16568 Pragma_License => -1,
16569 Pragma_Link_With => -1,
16570 Pragma_Linker_Alias => -1,
16571 Pragma_Linker_Constructor => -1,
16572 Pragma_Linker_Destructor => -1,
16573 Pragma_Linker_Options => -1,
16574 Pragma_Linker_Section => -1,
16575 Pragma_List => -1,
16576 Pragma_Lock_Free => -1,
16577 Pragma_Locking_Policy => -1,
16578 Pragma_Long_Float => -1,
16579 Pragma_Loop_Invariant => -1,
16580 Pragma_Loop_Variant => -1,
16581 Pragma_Machine_Attribute => -1,
16582 Pragma_Main => -1,
16583 Pragma_Main_Storage => -1,
16584 Pragma_Memory_Size => -1,
16585 Pragma_No_Return => 0,
16586 Pragma_No_Body => 0,
16587 Pragma_No_Run_Time => -1,
16588 Pragma_No_Strict_Aliasing => -1,
16589 Pragma_Normalize_Scalars => -1,
16590 Pragma_Obsolescent => 0,
16591 Pragma_Optimize => -1,
16592 Pragma_Optimize_Alignment => -1,
16593 Pragma_Overflow_Mode => 0,
16594 Pragma_Ordered => 0,
16595 Pragma_Pack => 0,
16596 Pragma_Page => -1,
16597 Pragma_Partition_Elaboration_Policy => -1,
16598 Pragma_Passive => -1,
16599 Pragma_Preelaborable_Initialization => -1,
16600 Pragma_Polling => -1,
16601 Pragma_Persistent_BSS => 0,
16602 Pragma_Postcondition => -1,
16603 Pragma_Precondition => -1,
16604 Pragma_Predicate => -1,
16605 Pragma_Preelaborate => -1,
16606 Pragma_Preelaborate_05 => -1,
16607 Pragma_Priority => -1,
16608 Pragma_Priority_Specific_Dispatching => -1,
16609 Pragma_Profile => 0,
16610 Pragma_Profile_Warnings => 0,
16611 Pragma_Propagate_Exceptions => -1,
16612 Pragma_Psect_Object => -1,
16613 Pragma_Pure => -1,
16614 Pragma_Pure_05 => -1,
16615 Pragma_Pure_12 => -1,
16616 Pragma_Pure_Function => -1,
16617 Pragma_Queuing_Policy => -1,
16618 Pragma_Rational => -1,
16619 Pragma_Ravenscar => -1,
16620 Pragma_Relative_Deadline => -1,
16621 Pragma_Remote_Access_Type => -1,
16622 Pragma_Remote_Call_Interface => -1,
16623 Pragma_Remote_Types => -1,
16624 Pragma_Restricted_Run_Time => -1,
16625 Pragma_Restriction_Warnings => -1,
16626 Pragma_Restrictions => -1,
16627 Pragma_Reviewable => -1,
16628 Pragma_Short_Circuit_And_Or => -1,
16629 Pragma_Share_Generic => -1,
16630 Pragma_Shared => -1,
16631 Pragma_Shared_Passive => -1,
16632 Pragma_Short_Descriptors => 0,
16633 Pragma_Simple_Storage_Pool_Type => 0,
16634 Pragma_Source_File_Name => -1,
16635 Pragma_Source_File_Name_Project => -1,
16636 Pragma_Source_Reference => -1,
16637 Pragma_Storage_Size => -1,
16638 Pragma_Storage_Unit => -1,
16639 Pragma_Static_Elaboration_Desired => -1,
16640 Pragma_Stream_Convert => -1,
16641 Pragma_Style_Checks => -1,
16642 Pragma_Subtitle => -1,
16643 Pragma_Suppress => 0,
16644 Pragma_Suppress_Exception_Locations => 0,
16645 Pragma_Suppress_All => -1,
16646 Pragma_Suppress_Debug_Info => 0,
16647 Pragma_Suppress_Initialization => 0,
16648 Pragma_System_Name => -1,
16649 Pragma_Task_Dispatching_Policy => -1,
16650 Pragma_Task_Info => -1,
16651 Pragma_Task_Name => -1,
16652 Pragma_Task_Storage => 0,
16653 Pragma_Test_Case => -1,
16654 Pragma_Thread_Local_Storage => 0,
16655 Pragma_Time_Slice => -1,
16656 Pragma_Title => -1,
16657 Pragma_Unchecked_Union => 0,
16658 Pragma_Unimplemented_Unit => -1,
16659 Pragma_Universal_Aliasing => -1,
16660 Pragma_Universal_Data => -1,
16661 Pragma_Unmodified => -1,
16662 Pragma_Unreferenced => -1,
16663 Pragma_Unreferenced_Objects => -1,
16664 Pragma_Unreserve_All_Interrupts => -1,
16665 Pragma_Unsuppress => 0,
16666 Pragma_Use_VADS_Size => -1,
16667 Pragma_Validity_Checks => -1,
16668 Pragma_Volatile => 0,
16669 Pragma_Volatile_Components => 0,
16670 Pragma_Warnings => -1,
16671 Pragma_Weak_External => -1,
16672 Pragma_Wide_Character_Encoding => 0,
16673 Unknown_Pragma => 0);
16674
16675 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
16676 Id : Pragma_Id;
16677 P : Node_Id;
16678 C : Int;
16679 A : Node_Id;
16680
16681 begin
16682 P := Parent (N);
16683
16684 if Nkind (P) /= N_Pragma_Argument_Association then
16685 return False;
16686
16687 else
16688 Id := Get_Pragma_Id (Parent (P));
16689 C := Sig_Flags (Id);
16690
16691 case C is
16692 when -1 =>
16693 return False;
16694
16695 when 0 =>
16696 return True;
16697
16698 when 99 =>
16699 case Id is
16700
16701 -- For pragma Check, the first argument is not significant,
16702 -- the second and the third (if present) arguments are
16703 -- significant.
16704
16705 when Pragma_Check =>
16706 return
16707 P = First (Pragma_Argument_Associations (Parent (P)));
16708
16709 when others =>
16710 raise Program_Error;
16711 end case;
16712
16713 when others =>
16714 A := First (Pragma_Argument_Associations (Parent (P)));
16715 for J in 1 .. C - 1 loop
16716 if No (A) then
16717 return False;
16718 end if;
16719
16720 Next (A);
16721 end loop;
16722
16723 return A = P; -- is this wrong way round ???
16724 end case;
16725 end if;
16726 end Is_Non_Significant_Pragma_Reference;
16727
16728 ------------------------------
16729 -- Is_Pragma_String_Literal --
16730 ------------------------------
16731
16732 -- This function returns true if the corresponding pragma argument is a
16733 -- static string expression. These are the only cases in which string
16734 -- literals can appear as pragma arguments. We also allow a string literal
16735 -- as the first argument to pragma Assert (although it will of course
16736 -- always generate a type error).
16737
16738 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
16739 Pragn : constant Node_Id := Parent (Par);
16740 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
16741 Pname : constant Name_Id := Pragma_Name (Pragn);
16742 Argn : Natural;
16743 N : Node_Id;
16744
16745 begin
16746 Argn := 1;
16747 N := First (Assoc);
16748 loop
16749 exit when N = Par;
16750 Argn := Argn + 1;
16751 Next (N);
16752 end loop;
16753
16754 if Pname = Name_Assert then
16755 return True;
16756
16757 elsif Pname = Name_Export then
16758 return Argn > 2;
16759
16760 elsif Pname = Name_Ident then
16761 return Argn = 1;
16762
16763 elsif Pname = Name_Import then
16764 return Argn > 2;
16765
16766 elsif Pname = Name_Interface_Name then
16767 return Argn > 1;
16768
16769 elsif Pname = Name_Linker_Alias then
16770 return Argn = 2;
16771
16772 elsif Pname = Name_Linker_Section then
16773 return Argn = 2;
16774
16775 elsif Pname = Name_Machine_Attribute then
16776 return Argn = 2;
16777
16778 elsif Pname = Name_Source_File_Name then
16779 return True;
16780
16781 elsif Pname = Name_Source_Reference then
16782 return Argn = 2;
16783
16784 elsif Pname = Name_Title then
16785 return True;
16786
16787 elsif Pname = Name_Subtitle then
16788 return True;
16789
16790 else
16791 return False;
16792 end if;
16793 end Is_Pragma_String_Literal;
16794
16795 -----------------------------------------
16796 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
16797 -----------------------------------------
16798
16799 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
16800 Aspects : constant List_Id := New_List;
16801 Loc : constant Source_Ptr := Sloc (Decl);
16802 Or_Decl : constant Node_Id := Original_Node (Decl);
16803
16804 Original_Aspects : List_Id;
16805 -- To capture global references, a copy of the created aspects must be
16806 -- inserted in the original tree.
16807
16808 Prag : Node_Id;
16809 Prag_Arg_Ass : Node_Id;
16810 Prag_Id : Pragma_Id;
16811
16812 begin
16813 -- Check for any PPC pragmas that appear within Decl
16814
16815 Prag := Next (Decl);
16816 while Nkind (Prag) = N_Pragma loop
16817 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
16818
16819 case Prag_Id is
16820 when Pragma_Postcondition | Pragma_Precondition =>
16821 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
16822
16823 -- Make an aspect from any PPC pragma
16824
16825 Append_To (Aspects,
16826 Make_Aspect_Specification (Loc,
16827 Identifier =>
16828 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
16829 Expression =>
16830 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
16831
16832 -- Generate the analysis information in the pragma expression
16833 -- and then set the pragma node analyzed to avoid any further
16834 -- analysis.
16835
16836 Analyze (Expression (Prag_Arg_Ass));
16837 Set_Analyzed (Prag, True);
16838
16839 when others => null;
16840 end case;
16841
16842 Next (Prag);
16843 end loop;
16844
16845 -- Set all new aspects into the generic declaration node
16846
16847 if Is_Non_Empty_List (Aspects) then
16848
16849 -- Create the list of aspects to be inserted in the original tree
16850
16851 Original_Aspects := Copy_Separate_List (Aspects);
16852
16853 -- Check if Decl already has aspects
16854
16855 -- Attach the new lists of aspects to both the generic copy and the
16856 -- original tree.
16857
16858 if Has_Aspects (Decl) then
16859 Append_List (Aspects, Aspect_Specifications (Decl));
16860 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
16861
16862 else
16863 Set_Parent (Aspects, Decl);
16864 Set_Aspect_Specifications (Decl, Aspects);
16865 Set_Parent (Original_Aspects, Or_Decl);
16866 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
16867 end if;
16868 end if;
16869 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
16870
16871 -------------------------
16872 -- Preanalyze_CTC_Args --
16873 -------------------------
16874
16875 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
16876 begin
16877 -- Preanalyze the boolean expressions, we treat these as spec
16878 -- expressions (i.e. similar to a default expression).
16879
16880 if Present (Arg_Req) then
16881 Preanalyze_Assert_Expression
16882 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
16883
16884 -- In ASIS mode, for a pragma generated from a source aspect, also
16885 -- analyze the original aspect expression.
16886
16887 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
16888 Preanalyze_Assert_Expression
16889 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
16890 end if;
16891 end if;
16892
16893 if Present (Arg_Ens) then
16894 Preanalyze_Assert_Expression
16895 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
16896
16897 -- In ASIS mode, for a pragma generated from a source aspect, also
16898 -- analyze the original aspect expression.
16899
16900 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
16901 Preanalyze_Assert_Expression
16902 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
16903 end if;
16904 end if;
16905 end Preanalyze_CTC_Args;
16906
16907 --------------------------------------
16908 -- Process_Compilation_Unit_Pragmas --
16909 --------------------------------------
16910
16911 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
16912 begin
16913 -- A special check for pragma Suppress_All, a very strange DEC pragma,
16914 -- strange because it comes at the end of the unit. Rational has the
16915 -- same name for a pragma, but treats it as a program unit pragma, In
16916 -- GNAT we just decide to allow it anywhere at all. If it appeared then
16917 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
16918 -- node, and we insert a pragma Suppress (All_Checks) at the start of
16919 -- the context clause to ensure the correct processing.
16920
16921 if Has_Pragma_Suppress_All (N) then
16922 Prepend_To (Context_Items (N),
16923 Make_Pragma (Sloc (N),
16924 Chars => Name_Suppress,
16925 Pragma_Argument_Associations => New_List (
16926 Make_Pragma_Argument_Association (Sloc (N),
16927 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
16928 end if;
16929
16930 -- Nothing else to do at the current time!
16931
16932 end Process_Compilation_Unit_Pragmas;
16933
16934 --------
16935 -- rv --
16936 --------
16937
16938 procedure rv is
16939 begin
16940 null;
16941 end rv;
16942
16943 --------------------------------
16944 -- Set_Encoded_Interface_Name --
16945 --------------------------------
16946
16947 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
16948 Str : constant String_Id := Strval (S);
16949 Len : constant Int := String_Length (Str);
16950 CC : Char_Code;
16951 C : Character;
16952 J : Int;
16953
16954 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
16955
16956 procedure Encode;
16957 -- Stores encoded value of character code CC. The encoding we use an
16958 -- underscore followed by four lower case hex digits.
16959
16960 ------------
16961 -- Encode --
16962 ------------
16963
16964 procedure Encode is
16965 begin
16966 Store_String_Char (Get_Char_Code ('_'));
16967 Store_String_Char
16968 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
16969 Store_String_Char
16970 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
16971 Store_String_Char
16972 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
16973 Store_String_Char
16974 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
16975 end Encode;
16976
16977 -- Start of processing for Set_Encoded_Interface_Name
16978
16979 begin
16980 -- If first character is asterisk, this is a link name, and we leave it
16981 -- completely unmodified. We also ignore null strings (the latter case
16982 -- happens only in error cases) and no encoding should occur for Java or
16983 -- AAMP interface names.
16984
16985 if Len = 0
16986 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
16987 or else VM_Target /= No_VM
16988 or else AAMP_On_Target
16989 then
16990 Set_Interface_Name (E, S);
16991
16992 else
16993 J := 1;
16994 loop
16995 CC := Get_String_Char (Str, J);
16996
16997 exit when not In_Character_Range (CC);
16998
16999 C := Get_Character (CC);
17000
17001 exit when C /= '_' and then C /= '$'
17002 and then C not in '0' .. '9'
17003 and then C not in 'a' .. 'z'
17004 and then C not in 'A' .. 'Z';
17005
17006 if J = Len then
17007 Set_Interface_Name (E, S);
17008 return;
17009
17010 else
17011 J := J + 1;
17012 end if;
17013 end loop;
17014
17015 -- Here we need to encode. The encoding we use as follows:
17016 -- three underscores + four hex digits (lower case)
17017
17018 Start_String;
17019
17020 for J in 1 .. String_Length (Str) loop
17021 CC := Get_String_Char (Str, J);
17022
17023 if not In_Character_Range (CC) then
17024 Encode;
17025 else
17026 C := Get_Character (CC);
17027
17028 if C = '_' or else C = '$'
17029 or else C in '0' .. '9'
17030 or else C in 'a' .. 'z'
17031 or else C in 'A' .. 'Z'
17032 then
17033 Store_String_Char (CC);
17034 else
17035 Encode;
17036 end if;
17037 end if;
17038 end loop;
17039
17040 Set_Interface_Name (E,
17041 Make_String_Literal (Sloc (S),
17042 Strval => End_String));
17043 end if;
17044 end Set_Encoded_Interface_Name;
17045
17046 -------------------
17047 -- Set_Unit_Name --
17048 -------------------
17049
17050 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
17051 Pref : Node_Id;
17052 Scop : Entity_Id;
17053
17054 begin
17055 if Nkind (N) = N_Identifier
17056 and then Nkind (With_Item) = N_Identifier
17057 then
17058 Set_Entity (N, Entity (With_Item));
17059
17060 elsif Nkind (N) = N_Selected_Component then
17061 Change_Selected_Component_To_Expanded_Name (N);
17062 Set_Entity (N, Entity (With_Item));
17063 Set_Entity (Selector_Name (N), Entity (N));
17064
17065 Pref := Prefix (N);
17066 Scop := Scope (Entity (N));
17067 while Nkind (Pref) = N_Selected_Component loop
17068 Change_Selected_Component_To_Expanded_Name (Pref);
17069 Set_Entity (Selector_Name (Pref), Scop);
17070 Set_Entity (Pref, Scop);
17071 Pref := Prefix (Pref);
17072 Scop := Scope (Scop);
17073 end loop;
17074
17075 Set_Entity (Pref, Scop);
17076 end if;
17077 end Set_Unit_Name;
17078
17079 end Sem_Prag;