[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", Corresponding_Aspect (N));
406 end if;
407
408 Replace_Type (Get_Pragma_Arg (Arg1));
409 end Class_Wide_Condition;
410 end if;
411
412 -- Remove the subprogram from the scope stack now that the pre-analysis
413 -- of the precondition/postcondition is done.
414
415 End_Scope;
416 end Analyze_PPC_In_Decl_Part;
417
418 --------------------
419 -- Analyze_Pragma --
420 --------------------
421
422 procedure Analyze_Pragma (N : Node_Id) is
423 Loc : constant Source_Ptr := Sloc (N);
424 Prag_Id : Pragma_Id;
425
426 Pname : Name_Id;
427 -- Name of the source pragma, or name of the corresponding aspect for
428 -- pragmas which originate in a source aspect. In the latter case, the
429 -- name may be different from the pragma name.
430
431 Pragma_Exit : exception;
432 -- This exception is used to exit pragma processing completely. It is
433 -- used when an error is detected, and no further processing is
434 -- required. It is also used if an earlier error has left the tree in
435 -- a state where the pragma should not be processed.
436
437 Arg_Count : Nat;
438 -- Number of pragma argument associations
439
440 Arg1 : Node_Id;
441 Arg2 : Node_Id;
442 Arg3 : Node_Id;
443 Arg4 : Node_Id;
444 -- First four pragma arguments (pragma argument association nodes, or
445 -- Empty if the corresponding argument does not exist).
446
447 type Name_List is array (Natural range <>) of Name_Id;
448 type Args_List is array (Natural range <>) of Node_Id;
449 -- Types used for arguments to Check_Arg_Order and Gather_Associations
450
451 procedure Ada_2005_Pragma;
452 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
453 -- Ada 95 mode, these are implementation defined pragmas, so should be
454 -- caught by the No_Implementation_Pragmas restriction.
455
456 procedure Ada_2012_Pragma;
457 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
458 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
459 -- should be caught by the No_Implementation_Pragmas restriction.
460
461 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id);
462 -- Subsidiary routine to the analysis of pragmas Depends and Global.
463 -- Append an input or output item to a list. If the list is empty, a
464 -- new one is created.
465
466 procedure Check_Ada_83_Warning;
467 -- Issues a warning message for the current pragma if operating in Ada
468 -- 83 mode (used for language pragmas that are not a standard part of
469 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
470 -- of 95 pragma.
471
472 procedure Check_Arg_Count (Required : Nat);
473 -- Check argument count for pragma is equal to given parameter. If not,
474 -- then issue an error message and raise Pragma_Exit.
475
476 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
477 -- Arg which can either be a pragma argument association, in which case
478 -- the check is applied to the expression of the association or an
479 -- expression directly.
480
481 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
482 -- Check that an argument has the right form for an EXTERNAL_NAME
483 -- parameter of an extended import/export pragma. The rule is that the
484 -- name must be an identifier or string literal (in Ada 83 mode) or a
485 -- static string expression (in Ada 95 mode).
486
487 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
488 -- Check the specified argument Arg to make sure that it is an
489 -- identifier. If not give error and raise Pragma_Exit.
490
491 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
492 -- Check the specified argument Arg to make sure that it is an integer
493 -- literal. If not give error and raise Pragma_Exit.
494
495 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
496 -- Check the specified argument Arg to make sure that it has the proper
497 -- syntactic form for a local name and meets the semantic requirements
498 -- for a local name. The local name is analyzed as part of the
499 -- processing for this call. In addition, the local name is required
500 -- to represent an entity at the library level.
501
502 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
503 -- Check the specified argument Arg to make sure that it has the proper
504 -- syntactic form for a local name and meets the semantic requirements
505 -- for a local name. The local name is analyzed as part of the
506 -- processing for this call.
507
508 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
509 -- Check the specified argument Arg to make sure that it is a valid
510 -- locking policy name. If not give error and raise Pragma_Exit.
511
512 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
513 -- Check the specified argument Arg to make sure that it is a valid
514 -- elaboration policy name. If not give error and raise Pragma_Exit.
515
516 procedure Check_Arg_Is_One_Of
517 (Arg : Node_Id;
518 N1, N2 : Name_Id);
519 procedure Check_Arg_Is_One_Of
520 (Arg : Node_Id;
521 N1, N2, N3 : Name_Id);
522 procedure Check_Arg_Is_One_Of
523 (Arg : Node_Id;
524 N1, N2, N3, N4 : Name_Id);
525 procedure Check_Arg_Is_One_Of
526 (Arg : Node_Id;
527 N1, N2, N3, N4, N5 : Name_Id);
528 -- Check the specified argument Arg to make sure that it is an
529 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
530 -- present). If not then give error and raise Pragma_Exit.
531
532 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
533 -- Check the specified argument Arg to make sure that it is a valid
534 -- queuing policy name. If not give error and raise Pragma_Exit.
535
536 procedure Check_Arg_Is_Static_Expression
537 (Arg : Node_Id;
538 Typ : Entity_Id := Empty);
539 -- Check the specified argument Arg to make sure that it is a static
540 -- expression of the given type (i.e. it will be analyzed and resolved
541 -- using this type, which can be any valid argument to Resolve, e.g.
542 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
543 -- Typ is left Empty, then any static expression is allowed.
544
545 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
546 -- Check the specified argument Arg to make sure that it is a valid task
547 -- dispatching policy name. If not give error and raise Pragma_Exit.
548
549 procedure Check_Arg_Order (Names : Name_List);
550 -- Checks for an instance of two arguments with identifiers for the
551 -- current pragma which are not in the sequence indicated by Names,
552 -- and if so, generates a fatal message about bad order of arguments.
553
554 procedure Check_At_Least_N_Arguments (N : Nat);
555 -- Check there are at least N arguments present
556
557 procedure Check_At_Most_N_Arguments (N : Nat);
558 -- Check there are no more than N arguments present
559
560 procedure Check_Component
561 (Comp : Node_Id;
562 UU_Typ : Entity_Id;
563 In_Variant_Part : Boolean := False);
564 -- Examine an Unchecked_Union component for correct use of per-object
565 -- constrained subtypes, and for restrictions on finalizable components.
566 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
567 -- should be set when Comp comes from a record variant.
568
569 procedure Check_Contract_Or_Test_Case;
570 -- Called to process a contract-case or test-case pragma. It
571 -- starts with checking pragma arguments, and the rest of the
572 -- treatment is similar to the one for pre- and postcondition in
573 -- Check_Precondition_Postcondition, except the placement rules for the
574 -- contract-case and test-case pragmas are stricter. These pragmas may
575 -- only occur after a subprogram spec declared directly in a package
576 -- spec unit. In this case, the pragma is chained to the subprogram in
577 -- question (using Spec_CTC_List and Next_Pragma) and analysis of the
578 -- pragma is delayed till the end of the spec. In all other cases, an
579 -- error message for bad placement is given.
580
581 procedure Check_Duplicate_Pragma (E : Entity_Id);
582 -- Check if a rep item of the same name as the current pragma is already
583 -- chained as a rep pragma to the given entity. If so give a message
584 -- about the duplicate, and then raise Pragma_Exit so does not return.
585
586 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
587 -- Nam is an N_String_Literal node containing the external name set by
588 -- an Import or Export pragma (or extended Import or Export pragma).
589 -- This procedure checks for possible duplications if this is the export
590 -- case, and if found, issues an appropriate error message.
591
592 procedure Check_Expr_Is_Static_Expression
593 (Expr : Node_Id;
594 Typ : Entity_Id := Empty);
595 -- Check the specified expression Expr to make sure that it is a static
596 -- expression of the given type (i.e. it will be analyzed and resolved
597 -- using this type, which can be any valid argument to Resolve, e.g.
598 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
599 -- Typ is left Empty, then any static expression is allowed.
600
601 procedure Check_First_Subtype (Arg : Node_Id);
602 -- Checks that Arg, whose expression is an entity name, references a
603 -- first subtype.
604
605 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
606 -- Checks that the given argument has an identifier, and if so, requires
607 -- it to match the given identifier name. If there is no identifier, or
608 -- a non-matching identifier, then an error message is given and
609 -- Pragma_Exit is raised.
610
611 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
612 -- Checks that the given argument has an identifier, and if so, requires
613 -- it to match one of the given identifier names. If there is no
614 -- identifier, or a non-matching identifier, then an error message is
615 -- given and Pragma_Exit is raised.
616
617 procedure Check_In_Main_Program;
618 -- Common checks for pragmas that appear within a main program
619 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
620
621 procedure Check_Interrupt_Or_Attach_Handler;
622 -- Common processing for first argument of pragma Interrupt_Handler or
623 -- pragma Attach_Handler.
624
625 procedure Check_Loop_Pragma_Placement;
626 -- Verify whether pragma Loop_Invariant or Loop_Optimize or Loop_Variant
627 -- appear immediately within a construct restricted to loops.
628
629 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
630 -- Check that pragma appears in a declarative part, or in a package
631 -- specification, i.e. that it does not occur in a statement sequence
632 -- in a body.
633
634 procedure Check_No_Identifier (Arg : Node_Id);
635 -- Checks that the given argument does not have an identifier. If
636 -- an identifier is present, then an error message is issued, and
637 -- Pragma_Exit is raised.
638
639 procedure Check_No_Identifiers;
640 -- Checks that none of the arguments to the pragma has an identifier.
641 -- If any argument has an identifier, then an error message is issued,
642 -- and Pragma_Exit is raised.
643
644 procedure Check_No_Link_Name;
645 -- Checks that no link name is specified
646
647 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
648 -- Checks if the given argument has an identifier, and if so, requires
649 -- it to match the given identifier name. If there is a non-matching
650 -- identifier, then an error message is given and Pragma_Exit is raised.
651
652 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
653 -- Checks if the given argument has an identifier, and if so, requires
654 -- it to match the given identifier name. If there is a non-matching
655 -- identifier, then an error message is given and Pragma_Exit is raised.
656 -- In this version of the procedure, the identifier name is given as
657 -- a string with lower case letters.
658
659 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
660 -- Called to process a precondition or postcondition pragma. There are
661 -- three cases:
662 --
663 -- The pragma appears after a subprogram spec
664 --
665 -- If the corresponding check is not enabled, the pragma is analyzed
666 -- but otherwise ignored and control returns with In_Body set False.
667 --
668 -- If the check is enabled, then the first step is to analyze the
669 -- pragma, but this is skipped if the subprogram spec appears within
670 -- a package specification (because this is the case where we delay
671 -- analysis till the end of the spec). Then (whether or not it was
672 -- analyzed), the pragma is chained to the subprogram in question
673 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
674 -- caller with In_Body set False.
675 --
676 -- The pragma appears at the start of subprogram body declarations
677 --
678 -- In this case an immediate return to the caller is made with
679 -- In_Body set True, and the pragma is NOT analyzed.
680 --
681 -- In all other cases, an error message for bad placement is given
682
683 procedure Check_Static_Constraint (Constr : Node_Id);
684 -- Constr is a constraint from an N_Subtype_Indication node from a
685 -- component constraint in an Unchecked_Union type. This routine checks
686 -- that the constraint is static as required by the restrictions for
687 -- Unchecked_Union.
688
689 procedure Check_Valid_Configuration_Pragma;
690 -- Legality checks for placement of a configuration pragma
691
692 procedure Check_Valid_Library_Unit_Pragma;
693 -- Legality checks for library unit pragmas. A special case arises for
694 -- pragmas in generic instances that come from copies of the original
695 -- library unit pragmas in the generic templates. In the case of other
696 -- than library level instantiations these can appear in contexts which
697 -- would normally be invalid (they only apply to the original template
698 -- and to library level instantiations), and they are simply ignored,
699 -- which is implemented by rewriting them as null statements.
700
701 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
702 -- Check an Unchecked_Union variant for lack of nested variants and
703 -- presence of at least one component. UU_Typ is the related Unchecked_
704 -- Union type.
705
706 procedure Error_Pragma (Msg : String);
707 pragma No_Return (Error_Pragma);
708 -- Outputs error message for current pragma. The message contains a %
709 -- that will be replaced with the pragma name, and the flag is placed
710 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
711 -- calls Fix_Error (see spec of that function for details).
712
713 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
714 pragma No_Return (Error_Pragma_Arg);
715 -- Outputs error message for current pragma. The message may contain
716 -- a % that will be replaced with the pragma name. The parameter Arg
717 -- may either be a pragma argument association, in which case the flag
718 -- is placed on the expression of this association, or an expression,
719 -- in which case the flag is placed directly on the expression. The
720 -- message is placed using Error_Msg_N, so the message may also contain
721 -- an & insertion character which will reference the given Arg value.
722 -- After placing the message, Pragma_Exit is raised. Note: this routine
723 -- calls Fix_Error (see spec of that function for details).
724
725 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
726 pragma No_Return (Error_Pragma_Arg);
727 -- Similar to above form of Error_Pragma_Arg except that two messages
728 -- are provided, the second is a continuation comment starting with \.
729
730 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
731 pragma No_Return (Error_Pragma_Arg_Ident);
732 -- Outputs error message for current pragma. The message may contain
733 -- a % that will be replaced with the pragma name. The parameter Arg
734 -- must be a pragma argument association with a non-empty identifier
735 -- (i.e. its Chars field must be set), and the error message is placed
736 -- on the identifier. The message is placed using Error_Msg_N so
737 -- the message may also contain an & insertion character which will
738 -- reference the identifier. After placing the message, Pragma_Exit
739 -- is raised. Note: this routine calls Fix_Error (see spec of that
740 -- function for details).
741
742 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
743 pragma No_Return (Error_Pragma_Ref);
744 -- Outputs error message for current pragma. The message may contain
745 -- a % that will be replaced with the pragma name. The parameter Ref
746 -- must be an entity whose name can be referenced by & and sloc by #.
747 -- After placing the message, Pragma_Exit is raised. Note: this routine
748 -- calls Fix_Error (see spec of that function for details).
749
750 function Find_Lib_Unit_Name return Entity_Id;
751 -- Used for a library unit pragma to find the entity to which the
752 -- library unit pragma applies, returns the entity found.
753
754 procedure Find_Program_Unit_Name (Id : Node_Id);
755 -- If the pragma is a compilation unit pragma, the id must denote the
756 -- compilation unit in the same compilation, and the pragma must appear
757 -- in the list of preceding or trailing pragmas. If it is a program
758 -- unit pragma that is not a compilation unit pragma, then the
759 -- identifier must be visible.
760
761 function Find_Unique_Parameterless_Procedure
762 (Name : Entity_Id;
763 Arg : Node_Id) return Entity_Id;
764 -- Used for a procedure pragma to find the unique parameterless
765 -- procedure identified by Name, returns it if it exists, otherwise
766 -- errors out and uses Arg as the pragma argument for the message.
767
768 procedure Fix_Error (Msg : in out String);
769 -- This is called prior to issuing an error message. Msg is a string
770 -- that typically contains the substring "pragma". If the current pragma
771 -- comes from an aspect, each such "pragma" substring is replaced with
772 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
773 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
774
775 procedure Gather_Associations
776 (Names : Name_List;
777 Args : out Args_List);
778 -- This procedure is used to gather the arguments for a pragma that
779 -- permits arbitrary ordering of parameters using the normal rules
780 -- for named and positional parameters. The Names argument is a list
781 -- of Name_Id values that corresponds to the allowed pragma argument
782 -- association identifiers in order. The result returned in Args is
783 -- a list of corresponding expressions that are the pragma arguments.
784 -- Note that this is a list of expressions, not of pragma argument
785 -- associations (Gather_Associations has completely checked all the
786 -- optional identifiers when it returns). An entry in Args is Empty
787 -- on return if the corresponding argument is not present.
788
789 procedure GNAT_Pragma;
790 -- Called for all GNAT defined pragmas to check the relevant restriction
791 -- (No_Implementation_Pragmas).
792
793 procedure S14_Pragma;
794 -- Called for all pragmas defined for formal verification to check that
795 -- the S14_Extensions flag is set.
796 -- This name needs fixing ??? There is no such thing as an
797 -- "S14_Extensions" flag ???
798
799 function Is_Before_First_Decl
800 (Pragma_Node : Node_Id;
801 Decls : List_Id) return Boolean;
802 -- Return True if Pragma_Node is before the first declarative item in
803 -- Decls where Decls is the list of declarative items.
804
805 function Is_Configuration_Pragma return Boolean;
806 -- Determines if the placement of the current pragma is appropriate
807 -- for a configuration pragma.
808
809 function Is_In_Context_Clause return Boolean;
810 -- Returns True if pragma appears within the context clause of a unit,
811 -- and False for any other placement (does not generate any messages).
812
813 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
814 -- Analyzes the argument, and determines if it is a static string
815 -- expression, returns True if so, False if non-static or not String.
816
817 procedure Pragma_Misplaced;
818 pragma No_Return (Pragma_Misplaced);
819 -- Issue fatal error message for misplaced pragma
820
821 procedure Process_Atomic_Shared_Volatile;
822 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
823 -- Shared is an obsolete Ada 83 pragma, treated as being identical
824 -- in effect to pragma Atomic.
825
826 procedure Process_Compile_Time_Warning_Or_Error;
827 -- Common processing for Compile_Time_Error and Compile_Time_Warning
828
829 procedure Process_Convention
830 (C : out Convention_Id;
831 Ent : out Entity_Id);
832 -- Common processing for Convention, Interface, Import and Export.
833 -- Checks first two arguments of pragma, and sets the appropriate
834 -- convention value in the specified entity or entities. On return
835 -- C is the convention, Ent is the referenced entity.
836
837 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
838 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
839 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
840
841 procedure Process_Extended_Import_Export_Exception_Pragma
842 (Arg_Internal : Node_Id;
843 Arg_External : Node_Id;
844 Arg_Form : Node_Id;
845 Arg_Code : Node_Id);
846 -- Common processing for the pragmas Import/Export_Exception. The three
847 -- arguments correspond to the three named parameters of the pragma. An
848 -- argument is empty if the corresponding parameter is not present in
849 -- the pragma.
850
851 procedure Process_Extended_Import_Export_Object_Pragma
852 (Arg_Internal : Node_Id;
853 Arg_External : Node_Id;
854 Arg_Size : Node_Id);
855 -- Common processing for the pragmas Import/Export_Object. The three
856 -- arguments correspond to the three named parameters of the pragmas. An
857 -- argument is empty if the corresponding parameter is not present in
858 -- the pragma.
859
860 procedure Process_Extended_Import_Export_Internal_Arg
861 (Arg_Internal : Node_Id := Empty);
862 -- Common processing for all extended Import and Export pragmas. The
863 -- argument is the pragma parameter for the Internal argument. If
864 -- Arg_Internal is empty or inappropriate, an error message is posted.
865 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
866 -- set to identify the referenced entity.
867
868 procedure Process_Extended_Import_Export_Subprogram_Pragma
869 (Arg_Internal : Node_Id;
870 Arg_External : Node_Id;
871 Arg_Parameter_Types : Node_Id;
872 Arg_Result_Type : Node_Id := Empty;
873 Arg_Mechanism : Node_Id;
874 Arg_Result_Mechanism : Node_Id := Empty;
875 Arg_First_Optional_Parameter : Node_Id := Empty);
876 -- Common processing for all extended Import and Export pragmas applying
877 -- to subprograms. The caller omits any arguments that do not apply to
878 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
879 -- only in the Import_Function and Export_Function cases). The argument
880 -- names correspond to the allowed pragma association identifiers.
881
882 procedure Process_Generic_List;
883 -- Common processing for Share_Generic and Inline_Generic
884
885 procedure Process_Import_Or_Interface;
886 -- Common processing for Import of Interface
887
888 procedure Process_Import_Predefined_Type;
889 -- Processing for completing a type with pragma Import. This is used
890 -- to declare types that match predefined C types, especially for cases
891 -- without corresponding Ada predefined type.
892
893 type Inline_Status is (Suppressed, Disabled, Enabled);
894 -- Inline status of a subprogram, indicated as follows:
895 -- Suppressed: inlining is suppressed for the subprogram
896 -- Disabled: no inlining is requested for the subprogram
897 -- Enabled: inlining is requested/required for the subprogram
898
899 procedure Process_Inline (Status : Inline_Status);
900 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
901 -- indicates the inline status specified by the pragma.
902
903 procedure Process_Interface_Name
904 (Subprogram_Def : Entity_Id;
905 Ext_Arg : Node_Id;
906 Link_Arg : Node_Id);
907 -- Given the last two arguments of pragma Import, pragma Export, or
908 -- pragma Interface_Name, performs validity checks and sets the
909 -- Interface_Name field of the given subprogram entity to the
910 -- appropriate external or link name, depending on the arguments given.
911 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
912 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
913 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
914 -- nor Link_Arg is present, the interface name is set to the default
915 -- from the subprogram name.
916
917 procedure Process_Interrupt_Or_Attach_Handler;
918 -- Common processing for Interrupt and Attach_Handler pragmas
919
920 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
921 -- Common processing for Restrictions and Restriction_Warnings pragmas.
922 -- Warn is True for Restriction_Warnings, or for Restrictions if the
923 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
924 -- is not set in the Restrictions case.
925
926 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
927 -- Common processing for Suppress and Unsuppress. The boolean parameter
928 -- Suppress_Case is True for the Suppress case, and False for the
929 -- Unsuppress case.
930
931 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
932 -- This procedure sets the Is_Exported flag for the given entity,
933 -- checking that the entity was not previously imported. Arg is
934 -- the argument that specified the entity. A check is also made
935 -- for exporting inappropriate entities.
936
937 procedure Set_Extended_Import_Export_External_Name
938 (Internal_Ent : Entity_Id;
939 Arg_External : Node_Id);
940 -- Common processing for all extended import export pragmas. The first
941 -- argument, Internal_Ent, is the internal entity, which has already
942 -- been checked for validity by the caller. Arg_External is from the
943 -- Import or Export pragma, and may be null if no External parameter
944 -- was present. If Arg_External is present and is a non-null string
945 -- (a null string is treated as the default), then the Interface_Name
946 -- field of Internal_Ent is set appropriately.
947
948 procedure Set_Imported (E : Entity_Id);
949 -- This procedure sets the Is_Imported flag for the given entity,
950 -- checking that it is not previously exported or imported.
951
952 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
953 -- Mech is a parameter passing mechanism (see Import_Function syntax
954 -- for MECHANISM_NAME). This routine checks that the mechanism argument
955 -- has the right form, and if not issues an error message. If the
956 -- argument has the right form then the Mechanism field of Ent is
957 -- set appropriately.
958
959 procedure Set_Rational_Profile;
960 -- Activate the set of configuration pragmas and permissions that make
961 -- up the Rational profile.
962
963 procedure Set_Ravenscar_Profile (N : Node_Id);
964 -- Activate the set of configuration pragmas and restrictions that make
965 -- up the Ravenscar Profile. N is the corresponding pragma node, which
966 -- is used for error messages on any constructs that violate the
967 -- profile.
968
969 ---------------------
970 -- Ada_2005_Pragma --
971 ---------------------
972
973 procedure Ada_2005_Pragma is
974 begin
975 if Ada_Version <= Ada_95 then
976 Check_Restriction (No_Implementation_Pragmas, N);
977 end if;
978 end Ada_2005_Pragma;
979
980 ---------------------
981 -- Ada_2012_Pragma --
982 ---------------------
983
984 procedure Ada_2012_Pragma is
985 begin
986 if Ada_Version <= Ada_2005 then
987 Check_Restriction (No_Implementation_Pragmas, N);
988 end if;
989 end Ada_2012_Pragma;
990
991 --------------
992 -- Add_Item --
993 --------------
994
995 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id) is
996 begin
997 if No (To_List) then
998 To_List := New_Elmt_List;
999 end if;
1000
1001 Append_Unique_Elmt (Item, To_List);
1002 end Add_Item;
1003
1004 --------------------------
1005 -- Check_Ada_83_Warning --
1006 --------------------------
1007
1008 procedure Check_Ada_83_Warning is
1009 begin
1010 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
1011 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
1012 end if;
1013 end Check_Ada_83_Warning;
1014
1015 ---------------------
1016 -- Check_Arg_Count --
1017 ---------------------
1018
1019 procedure Check_Arg_Count (Required : Nat) is
1020 begin
1021 if Arg_Count /= Required then
1022 Error_Pragma ("wrong number of arguments for pragma%");
1023 end if;
1024 end Check_Arg_Count;
1025
1026 --------------------------------
1027 -- Check_Arg_Is_External_Name --
1028 --------------------------------
1029
1030 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
1031 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1032
1033 begin
1034 if Nkind (Argx) = N_Identifier then
1035 return;
1036
1037 else
1038 Analyze_And_Resolve (Argx, Standard_String);
1039
1040 if Is_OK_Static_Expression (Argx) then
1041 return;
1042
1043 elsif Etype (Argx) = Any_Type then
1044 raise Pragma_Exit;
1045
1046 -- An interesting special case, if we have a string literal and
1047 -- we are in Ada 83 mode, then we allow it even though it will
1048 -- not be flagged as static. This allows expected Ada 83 mode
1049 -- use of external names which are string literals, even though
1050 -- technically these are not static in Ada 83.
1051
1052 elsif Ada_Version = Ada_83
1053 and then Nkind (Argx) = N_String_Literal
1054 then
1055 return;
1056
1057 -- Static expression that raises Constraint_Error. This has
1058 -- already been flagged, so just exit from pragma processing.
1059
1060 elsif Is_Static_Expression (Argx) then
1061 raise Pragma_Exit;
1062
1063 -- Here we have a real error (non-static expression)
1064
1065 else
1066 Error_Msg_Name_1 := Pname;
1067
1068 declare
1069 Msg : String :=
1070 "argument for pragma% must be a identifier or "
1071 & "static string expression!";
1072 begin
1073 Fix_Error (Msg);
1074 Flag_Non_Static_Expr (Msg, Argx);
1075 raise Pragma_Exit;
1076 end;
1077 end if;
1078 end if;
1079 end Check_Arg_Is_External_Name;
1080
1081 -----------------------------
1082 -- Check_Arg_Is_Identifier --
1083 -----------------------------
1084
1085 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
1086 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1087 begin
1088 if Nkind (Argx) /= N_Identifier then
1089 Error_Pragma_Arg
1090 ("argument for pragma% must be identifier", Argx);
1091 end if;
1092 end Check_Arg_Is_Identifier;
1093
1094 ----------------------------------
1095 -- Check_Arg_Is_Integer_Literal --
1096 ----------------------------------
1097
1098 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1099 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1100 begin
1101 if Nkind (Argx) /= N_Integer_Literal then
1102 Error_Pragma_Arg
1103 ("argument for pragma% must be integer literal", Argx);
1104 end if;
1105 end Check_Arg_Is_Integer_Literal;
1106
1107 -------------------------------------------
1108 -- Check_Arg_Is_Library_Level_Local_Name --
1109 -------------------------------------------
1110
1111 -- LOCAL_NAME ::=
1112 -- DIRECT_NAME
1113 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1114 -- | library_unit_NAME
1115
1116 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1117 begin
1118 Check_Arg_Is_Local_Name (Arg);
1119
1120 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1121 and then Comes_From_Source (N)
1122 then
1123 Error_Pragma_Arg
1124 ("argument for pragma% must be library level entity", Arg);
1125 end if;
1126 end Check_Arg_Is_Library_Level_Local_Name;
1127
1128 -----------------------------
1129 -- Check_Arg_Is_Local_Name --
1130 -----------------------------
1131
1132 -- LOCAL_NAME ::=
1133 -- DIRECT_NAME
1134 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1135 -- | library_unit_NAME
1136
1137 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1138 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1139
1140 begin
1141 Analyze (Argx);
1142
1143 if Nkind (Argx) not in N_Direct_Name
1144 and then (Nkind (Argx) /= N_Attribute_Reference
1145 or else Present (Expressions (Argx))
1146 or else Nkind (Prefix (Argx)) /= N_Identifier)
1147 and then (not Is_Entity_Name (Argx)
1148 or else not Is_Compilation_Unit (Entity (Argx)))
1149 then
1150 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1151 end if;
1152
1153 -- No further check required if not an entity name
1154
1155 if not Is_Entity_Name (Argx) then
1156 null;
1157
1158 else
1159 declare
1160 OK : Boolean;
1161 Ent : constant Entity_Id := Entity (Argx);
1162 Scop : constant Entity_Id := Scope (Ent);
1163 begin
1164 -- Case of a pragma applied to a compilation unit: pragma must
1165 -- occur immediately after the program unit in the compilation.
1166
1167 if Is_Compilation_Unit (Ent) then
1168 declare
1169 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1170
1171 begin
1172 -- Case of pragma placed immediately after spec
1173
1174 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1175 OK := True;
1176
1177 -- Case of pragma placed immediately after body
1178
1179 elsif Nkind (Decl) = N_Subprogram_Declaration
1180 and then Present (Corresponding_Body (Decl))
1181 then
1182 OK := Parent (N) =
1183 Aux_Decls_Node
1184 (Parent (Unit_Declaration_Node
1185 (Corresponding_Body (Decl))));
1186
1187 -- All other cases are illegal
1188
1189 else
1190 OK := False;
1191 end if;
1192 end;
1193
1194 -- Special restricted placement rule from 10.2.1(11.8/2)
1195
1196 elsif Is_Generic_Formal (Ent)
1197 and then Prag_Id = Pragma_Preelaborable_Initialization
1198 then
1199 OK := List_Containing (N) =
1200 Generic_Formal_Declarations
1201 (Unit_Declaration_Node (Scop));
1202
1203 -- Default case, just check that the pragma occurs in the scope
1204 -- of the entity denoted by the name.
1205
1206 else
1207 OK := Current_Scope = Scop;
1208 end if;
1209
1210 if not OK then
1211 Error_Pragma_Arg
1212 ("pragma% argument must be in same declarative part", Arg);
1213 end if;
1214 end;
1215 end if;
1216 end Check_Arg_Is_Local_Name;
1217
1218 ---------------------------------
1219 -- Check_Arg_Is_Locking_Policy --
1220 ---------------------------------
1221
1222 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1223 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1224
1225 begin
1226 Check_Arg_Is_Identifier (Argx);
1227
1228 if not Is_Locking_Policy_Name (Chars (Argx)) then
1229 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1230 end if;
1231 end Check_Arg_Is_Locking_Policy;
1232
1233 -----------------------------------------------
1234 -- Check_Arg_Is_Partition_Elaboration_Policy --
1235 -----------------------------------------------
1236
1237 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
1238 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1239
1240 begin
1241 Check_Arg_Is_Identifier (Argx);
1242
1243 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
1244 Error_Pragma_Arg
1245 ("& is not a valid partition elaboration policy name", Argx);
1246 end if;
1247 end Check_Arg_Is_Partition_Elaboration_Policy;
1248
1249 -------------------------
1250 -- Check_Arg_Is_One_Of --
1251 -------------------------
1252
1253 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1254 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1255
1256 begin
1257 Check_Arg_Is_Identifier (Argx);
1258
1259 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1260 Error_Msg_Name_2 := N1;
1261 Error_Msg_Name_3 := N2;
1262 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1263 end if;
1264 end Check_Arg_Is_One_Of;
1265
1266 procedure Check_Arg_Is_One_Of
1267 (Arg : Node_Id;
1268 N1, N2, N3 : Name_Id)
1269 is
1270 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1271
1272 begin
1273 Check_Arg_Is_Identifier (Argx);
1274
1275 if Chars (Argx) /= N1
1276 and then Chars (Argx) /= N2
1277 and then Chars (Argx) /= N3
1278 then
1279 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1280 end if;
1281 end Check_Arg_Is_One_Of;
1282
1283 procedure Check_Arg_Is_One_Of
1284 (Arg : Node_Id;
1285 N1, N2, N3, N4 : Name_Id)
1286 is
1287 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1288
1289 begin
1290 Check_Arg_Is_Identifier (Argx);
1291
1292 if Chars (Argx) /= N1
1293 and then Chars (Argx) /= N2
1294 and then Chars (Argx) /= N3
1295 and then Chars (Argx) /= N4
1296 then
1297 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1298 end if;
1299 end Check_Arg_Is_One_Of;
1300
1301 procedure Check_Arg_Is_One_Of
1302 (Arg : Node_Id;
1303 N1, N2, N3, N4, N5 : Name_Id)
1304 is
1305 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1306
1307 begin
1308 Check_Arg_Is_Identifier (Argx);
1309
1310 if Chars (Argx) /= N1
1311 and then Chars (Argx) /= N2
1312 and then Chars (Argx) /= N3
1313 and then Chars (Argx) /= N4
1314 and then Chars (Argx) /= N5
1315 then
1316 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1317 end if;
1318 end Check_Arg_Is_One_Of;
1319
1320 ---------------------------------
1321 -- Check_Arg_Is_Queuing_Policy --
1322 ---------------------------------
1323
1324 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1325 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1326
1327 begin
1328 Check_Arg_Is_Identifier (Argx);
1329
1330 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1331 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1332 end if;
1333 end Check_Arg_Is_Queuing_Policy;
1334
1335 ------------------------------------
1336 -- Check_Arg_Is_Static_Expression --
1337 ------------------------------------
1338
1339 procedure Check_Arg_Is_Static_Expression
1340 (Arg : Node_Id;
1341 Typ : Entity_Id := Empty)
1342 is
1343 begin
1344 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1345 end Check_Arg_Is_Static_Expression;
1346
1347 ------------------------------------------
1348 -- Check_Arg_Is_Task_Dispatching_Policy --
1349 ------------------------------------------
1350
1351 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1352 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1353
1354 begin
1355 Check_Arg_Is_Identifier (Argx);
1356
1357 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1358 Error_Pragma_Arg
1359 ("& is not a valid task dispatching policy name", Argx);
1360 end if;
1361 end Check_Arg_Is_Task_Dispatching_Policy;
1362
1363 ---------------------
1364 -- Check_Arg_Order --
1365 ---------------------
1366
1367 procedure Check_Arg_Order (Names : Name_List) is
1368 Arg : Node_Id;
1369
1370 Highest_So_Far : Natural := 0;
1371 -- Highest index in Names seen do far
1372
1373 begin
1374 Arg := Arg1;
1375 for J in 1 .. Arg_Count loop
1376 if Chars (Arg) /= No_Name then
1377 for K in Names'Range loop
1378 if Chars (Arg) = Names (K) then
1379 if K < Highest_So_Far then
1380 Error_Msg_Name_1 := Pname;
1381 Error_Msg_N
1382 ("parameters out of order for pragma%", Arg);
1383 Error_Msg_Name_1 := Names (K);
1384 Error_Msg_Name_2 := Names (Highest_So_Far);
1385 Error_Msg_N ("\% must appear before %", Arg);
1386 raise Pragma_Exit;
1387
1388 else
1389 Highest_So_Far := K;
1390 end if;
1391 end if;
1392 end loop;
1393 end if;
1394
1395 Arg := Next (Arg);
1396 end loop;
1397 end Check_Arg_Order;
1398
1399 --------------------------------
1400 -- Check_At_Least_N_Arguments --
1401 --------------------------------
1402
1403 procedure Check_At_Least_N_Arguments (N : Nat) is
1404 begin
1405 if Arg_Count < N then
1406 Error_Pragma ("too few arguments for pragma%");
1407 end if;
1408 end Check_At_Least_N_Arguments;
1409
1410 -------------------------------
1411 -- Check_At_Most_N_Arguments --
1412 -------------------------------
1413
1414 procedure Check_At_Most_N_Arguments (N : Nat) is
1415 Arg : Node_Id;
1416 begin
1417 if Arg_Count > N then
1418 Arg := Arg1;
1419 for J in 1 .. N loop
1420 Next (Arg);
1421 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1422 end loop;
1423 end if;
1424 end Check_At_Most_N_Arguments;
1425
1426 ---------------------
1427 -- Check_Component --
1428 ---------------------
1429
1430 procedure Check_Component
1431 (Comp : Node_Id;
1432 UU_Typ : Entity_Id;
1433 In_Variant_Part : Boolean := False)
1434 is
1435 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1436 Sindic : constant Node_Id :=
1437 Subtype_Indication (Component_Definition (Comp));
1438 Typ : constant Entity_Id := Etype (Comp_Id);
1439
1440 begin
1441 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1442 -- object constraint, then the component type shall be an Unchecked_
1443 -- Union.
1444
1445 if Nkind (Sindic) = N_Subtype_Indication
1446 and then Has_Per_Object_Constraint (Comp_Id)
1447 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1448 then
1449 Error_Msg_N
1450 ("component subtype subject to per-object constraint "
1451 & "must be an Unchecked_Union", Comp);
1452
1453 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1454 -- the body of a generic unit, or within the body of any of its
1455 -- descendant library units, no part of the type of a component
1456 -- declared in a variant_part of the unchecked union type shall be of
1457 -- a formal private type or formal private extension declared within
1458 -- the formal part of the generic unit.
1459
1460 elsif Ada_Version >= Ada_2012
1461 and then In_Generic_Body (UU_Typ)
1462 and then In_Variant_Part
1463 and then Is_Private_Type (Typ)
1464 and then Is_Generic_Type (Typ)
1465 then
1466 Error_Msg_N
1467 ("component of unchecked union cannot be of generic type", Comp);
1468
1469 elsif Needs_Finalization (Typ) then
1470 Error_Msg_N
1471 ("component of unchecked union cannot be controlled", Comp);
1472
1473 elsif Has_Task (Typ) then
1474 Error_Msg_N
1475 ("component of unchecked union cannot have tasks", Comp);
1476 end if;
1477 end Check_Component;
1478
1479 ---------------------------------
1480 -- Check_Contract_Or_Test_Case --
1481 ---------------------------------
1482
1483 procedure Check_Contract_Or_Test_Case is
1484 P : Node_Id;
1485 PO : Node_Id;
1486
1487 procedure Chain_CTC (PO : Node_Id);
1488 -- If PO is a [generic] subprogram declaration node, then the
1489 -- contract-case or test-case applies to this subprogram and the
1490 -- processing for the pragma is completed. Otherwise the pragma
1491 -- is misplaced.
1492
1493 ---------------
1494 -- Chain_CTC --
1495 ---------------
1496
1497 procedure Chain_CTC (PO : Node_Id) is
1498 S : Entity_Id;
1499
1500 begin
1501 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1502 Error_Pragma
1503 ("pragma% cannot be applied to abstract subprogram");
1504
1505 elsif Nkind (PO) = N_Entry_Declaration then
1506 Error_Pragma ("pragma% cannot be applied to entry");
1507
1508 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1509 N_Generic_Subprogram_Declaration)
1510 then
1511 Pragma_Misplaced;
1512 end if;
1513
1514 -- Here if we have [generic] subprogram declaration
1515
1516 S := Defining_Unit_Name (Specification (PO));
1517
1518 -- Note: we do not analyze the pragma at this point. Instead we
1519 -- delay this analysis until the end of the declarative part in
1520 -- which the pragma appears. This implements the required delay
1521 -- in this analysis, allowing forward references. The analysis
1522 -- happens at the end of Analyze_Declarations.
1523
1524 -- There should not be another contract-case or test-case with the
1525 -- same name associated to this subprogram.
1526
1527 declare
1528 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
1529 CTC : Node_Id;
1530
1531 begin
1532 CTC := Spec_CTC_List (Contract (S));
1533 while Present (CTC) loop
1534
1535 -- Omit pragma Contract_Cases because it does not introduce
1536 -- a unique case name and it does not follow the syntax of
1537 -- Contract_Case and Test_Case.
1538
1539 if Pragma_Name (CTC) = Name_Contract_Cases then
1540 null;
1541
1542 elsif String_Equal
1543 (Name, Get_Name_From_CTC_Pragma (CTC))
1544 then
1545 Error_Msg_Sloc := Sloc (CTC);
1546 Error_Pragma ("name for pragma% is already used#");
1547 end if;
1548
1549 CTC := Next_Pragma (CTC);
1550 end loop;
1551 end;
1552
1553 -- Chain spec CTC pragma to list for subprogram
1554
1555 Set_Next_Pragma (N, Spec_CTC_List (Contract (S)));
1556 Set_Spec_CTC_List (Contract (S), N);
1557 end Chain_CTC;
1558
1559 -- Start of processing for Check_Contract_Or_Test_Case
1560
1561 begin
1562 -- First check pragma arguments
1563
1564 GNAT_Pragma;
1565 Check_At_Least_N_Arguments (2);
1566 Check_At_Most_N_Arguments (4);
1567 Check_Arg_Order
1568 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
1569
1570 Check_Optional_Identifier (Arg1, Name_Name);
1571 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
1572
1573 -- In ASIS mode, for a pragma generated from a source aspect, also
1574 -- analyze the original aspect expression.
1575
1576 if ASIS_Mode
1577 and then Present (Corresponding_Aspect (N))
1578 then
1579 Check_Expr_Is_Static_Expression
1580 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
1581 end if;
1582
1583 Check_Optional_Identifier (Arg2, Name_Mode);
1584 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
1585
1586 if Arg_Count = 4 then
1587 Check_Identifier (Arg3, Name_Requires);
1588 Check_Identifier (Arg4, Name_Ensures);
1589
1590 elsif Arg_Count = 3 then
1591 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
1592 end if;
1593
1594 -- Check pragma placement
1595
1596 if not Is_List_Member (N) then
1597 Pragma_Misplaced;
1598 end if;
1599
1600 -- Contract-case or test-case should only appear in package spec unit
1601
1602 if Get_Source_Unit (N) = No_Unit
1603 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
1604 N_Package_Declaration,
1605 N_Generic_Package_Declaration)
1606 then
1607 Pragma_Misplaced;
1608 end if;
1609
1610 -- Search prior declarations
1611
1612 P := N;
1613 while Present (Prev (P)) loop
1614 P := Prev (P);
1615
1616 -- If the previous node is a generic subprogram, do not go to to
1617 -- the original node, which is the unanalyzed tree: we need to
1618 -- attach the contract-case or test-case to the analyzed version
1619 -- at this point. They get propagated to the original tree when
1620 -- analyzing the corresponding body.
1621
1622 if Nkind (P) not in N_Generic_Declaration then
1623 PO := Original_Node (P);
1624 else
1625 PO := P;
1626 end if;
1627
1628 -- Skip past prior pragma
1629
1630 if Nkind (PO) = N_Pragma then
1631 null;
1632
1633 -- Skip stuff not coming from source
1634
1635 elsif not Comes_From_Source (PO) then
1636 null;
1637
1638 -- Only remaining possibility is subprogram declaration. First
1639 -- check that it is declared directly in a package declaration.
1640 -- This may be either the package declaration for the current unit
1641 -- being defined or a local package declaration.
1642
1643 elsif not Present (Parent (Parent (PO)))
1644 or else not Present (Parent (Parent (Parent (PO))))
1645 or else not Nkind_In (Parent (Parent (PO)),
1646 N_Package_Declaration,
1647 N_Generic_Package_Declaration)
1648 then
1649 Pragma_Misplaced;
1650
1651 else
1652 Chain_CTC (PO);
1653 return;
1654 end if;
1655 end loop;
1656
1657 -- If we fall through, pragma was misplaced
1658
1659 Pragma_Misplaced;
1660 end Check_Contract_Or_Test_Case;
1661
1662 ----------------------------
1663 -- Check_Duplicate_Pragma --
1664 ----------------------------
1665
1666 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1667 Id : Entity_Id := E;
1668 P : Node_Id;
1669
1670 begin
1671 -- Nothing to do if this pragma comes from an aspect specification,
1672 -- since we could not be duplicating a pragma, and we dealt with the
1673 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1674
1675 if From_Aspect_Specification (N) then
1676 return;
1677 end if;
1678
1679 -- Otherwise current pragma may duplicate previous pragma or a
1680 -- previously given aspect specification or attribute definition
1681 -- clause for the same pragma.
1682
1683 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
1684
1685 if Present (P) then
1686 Error_Msg_Name_1 := Pragma_Name (N);
1687 Error_Msg_Sloc := Sloc (P);
1688
1689 -- For a single protected or a single task object, the error is
1690 -- issued on the original entity.
1691
1692 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
1693 Id := Defining_Identifier (Original_Node (Parent (Id)));
1694 end if;
1695
1696 if Nkind (P) = N_Aspect_Specification
1697 or else From_Aspect_Specification (P)
1698 then
1699 Error_Msg_NE ("aspect% for & previously given#", N, Id);
1700 else
1701 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
1702 end if;
1703
1704 raise Pragma_Exit;
1705 end if;
1706 end Check_Duplicate_Pragma;
1707
1708 ----------------------------------
1709 -- Check_Duplicated_Export_Name --
1710 ----------------------------------
1711
1712 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1713 String_Val : constant String_Id := Strval (Nam);
1714
1715 begin
1716 -- We are only interested in the export case, and in the case of
1717 -- generics, it is the instance, not the template, that is the
1718 -- problem (the template will generate a warning in any case).
1719
1720 if not Inside_A_Generic
1721 and then (Prag_Id = Pragma_Export
1722 or else
1723 Prag_Id = Pragma_Export_Procedure
1724 or else
1725 Prag_Id = Pragma_Export_Valued_Procedure
1726 or else
1727 Prag_Id = Pragma_Export_Function)
1728 then
1729 for J in Externals.First .. Externals.Last loop
1730 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1731 Error_Msg_Sloc := Sloc (Externals.Table (J));
1732 Error_Msg_N ("external name duplicates name given#", Nam);
1733 exit;
1734 end if;
1735 end loop;
1736
1737 Externals.Append (Nam);
1738 end if;
1739 end Check_Duplicated_Export_Name;
1740
1741 -------------------------------------
1742 -- Check_Expr_Is_Static_Expression --
1743 -------------------------------------
1744
1745 procedure Check_Expr_Is_Static_Expression
1746 (Expr : Node_Id;
1747 Typ : Entity_Id := Empty)
1748 is
1749 begin
1750 if Present (Typ) then
1751 Analyze_And_Resolve (Expr, Typ);
1752 else
1753 Analyze_And_Resolve (Expr);
1754 end if;
1755
1756 if Is_OK_Static_Expression (Expr) then
1757 return;
1758
1759 elsif Etype (Expr) = Any_Type then
1760 raise Pragma_Exit;
1761
1762 -- An interesting special case, if we have a string literal and we
1763 -- are in Ada 83 mode, then we allow it even though it will not be
1764 -- flagged as static. This allows the use of Ada 95 pragmas like
1765 -- Import in Ada 83 mode. They will of course be flagged with
1766 -- warnings as usual, but will not cause errors.
1767
1768 elsif Ada_Version = Ada_83
1769 and then Nkind (Expr) = N_String_Literal
1770 then
1771 return;
1772
1773 -- Static expression that raises Constraint_Error. This has already
1774 -- been flagged, so just exit from pragma processing.
1775
1776 elsif Is_Static_Expression (Expr) then
1777 raise Pragma_Exit;
1778
1779 -- Finally, we have a real error
1780
1781 else
1782 Error_Msg_Name_1 := Pname;
1783
1784 declare
1785 Msg : String :=
1786 "argument for pragma% must be a static expression!";
1787 begin
1788 Fix_Error (Msg);
1789 Flag_Non_Static_Expr (Msg, Expr);
1790 end;
1791
1792 raise Pragma_Exit;
1793 end if;
1794 end Check_Expr_Is_Static_Expression;
1795
1796 -------------------------
1797 -- Check_First_Subtype --
1798 -------------------------
1799
1800 procedure Check_First_Subtype (Arg : Node_Id) is
1801 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1802 Ent : constant Entity_Id := Entity (Argx);
1803
1804 begin
1805 if Is_First_Subtype (Ent) then
1806 null;
1807
1808 elsif Is_Type (Ent) then
1809 Error_Pragma_Arg
1810 ("pragma% cannot apply to subtype", Argx);
1811
1812 elsif Is_Object (Ent) then
1813 Error_Pragma_Arg
1814 ("pragma% cannot apply to object, requires a type", Argx);
1815
1816 else
1817 Error_Pragma_Arg
1818 ("pragma% cannot apply to&, requires a type", Argx);
1819 end if;
1820 end Check_First_Subtype;
1821
1822 ----------------------
1823 -- Check_Identifier --
1824 ----------------------
1825
1826 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1827 begin
1828 if Present (Arg)
1829 and then Nkind (Arg) = N_Pragma_Argument_Association
1830 then
1831 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1832 Error_Msg_Name_1 := Pname;
1833 Error_Msg_Name_2 := Id;
1834 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1835 raise Pragma_Exit;
1836 end if;
1837 end if;
1838 end Check_Identifier;
1839
1840 --------------------------------
1841 -- Check_Identifier_Is_One_Of --
1842 --------------------------------
1843
1844 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1845 begin
1846 if Present (Arg)
1847 and then Nkind (Arg) = N_Pragma_Argument_Association
1848 then
1849 if Chars (Arg) = No_Name then
1850 Error_Msg_Name_1 := Pname;
1851 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1852 raise Pragma_Exit;
1853
1854 elsif Chars (Arg) /= N1
1855 and then Chars (Arg) /= N2
1856 then
1857 Error_Msg_Name_1 := Pname;
1858 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1859 raise Pragma_Exit;
1860 end if;
1861 end if;
1862 end Check_Identifier_Is_One_Of;
1863
1864 ---------------------------
1865 -- Check_In_Main_Program --
1866 ---------------------------
1867
1868 procedure Check_In_Main_Program is
1869 P : constant Node_Id := Parent (N);
1870
1871 begin
1872 -- Must be at in subprogram body
1873
1874 if Nkind (P) /= N_Subprogram_Body then
1875 Error_Pragma ("% pragma allowed only in subprogram");
1876
1877 -- Otherwise warn if obviously not main program
1878
1879 elsif Present (Parameter_Specifications (Specification (P)))
1880 or else not Is_Compilation_Unit (Defining_Entity (P))
1881 then
1882 Error_Msg_Name_1 := Pname;
1883 Error_Msg_N
1884 ("??pragma% is only effective in main program", N);
1885 end if;
1886 end Check_In_Main_Program;
1887
1888 ---------------------------------------
1889 -- Check_Interrupt_Or_Attach_Handler --
1890 ---------------------------------------
1891
1892 procedure Check_Interrupt_Or_Attach_Handler is
1893 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1894 Handler_Proc, Proc_Scope : Entity_Id;
1895
1896 begin
1897 Analyze (Arg1_X);
1898
1899 if Prag_Id = Pragma_Interrupt_Handler then
1900 Check_Restriction (No_Dynamic_Attachment, N);
1901 end if;
1902
1903 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1904 Proc_Scope := Scope (Handler_Proc);
1905
1906 -- On AAMP only, a pragma Interrupt_Handler is supported for
1907 -- nonprotected parameterless procedures.
1908
1909 if not AAMP_On_Target
1910 or else Prag_Id = Pragma_Attach_Handler
1911 then
1912 if Ekind (Proc_Scope) /= E_Protected_Type then
1913 Error_Pragma_Arg
1914 ("argument of pragma% must be protected procedure", Arg1);
1915 end if;
1916
1917 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1918 Error_Pragma ("pragma% must be in protected definition");
1919 end if;
1920 end if;
1921
1922 if not Is_Library_Level_Entity (Proc_Scope)
1923 or else (AAMP_On_Target
1924 and then not Is_Library_Level_Entity (Handler_Proc))
1925 then
1926 Error_Pragma_Arg
1927 ("argument for pragma% must be library level entity", Arg1);
1928 end if;
1929
1930 -- AI05-0033: A pragma cannot appear within a generic body, because
1931 -- instance can be in a nested scope. The check that protected type
1932 -- is itself a library-level declaration is done elsewhere.
1933
1934 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
1935 -- handle code prior to AI-0033. Analysis tools typically are not
1936 -- interested in this pragma in any case, so no need to worry too
1937 -- much about its placement.
1938
1939 if Inside_A_Generic then
1940 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1941 and then In_Package_Body (Scope (Current_Scope))
1942 and then not Relaxed_RM_Semantics
1943 then
1944 Error_Pragma ("pragma% cannot be used inside a generic");
1945 end if;
1946 end if;
1947 end Check_Interrupt_Or_Attach_Handler;
1948
1949 ---------------------------------
1950 -- Check_Loop_Pragma_Placement --
1951 ---------------------------------
1952
1953 procedure Check_Loop_Pragma_Placement is
1954 procedure Placement_Error (Constr : Node_Id);
1955 pragma No_Return (Placement_Error);
1956 -- Node Constr denotes the last loop restricted construct before we
1957 -- encountered an illegal relation between enclosing constructs. Emit
1958 -- an error depending on what Constr was.
1959
1960 ---------------------
1961 -- Placement_Error --
1962 ---------------------
1963
1964 procedure Placement_Error (Constr : Node_Id) is
1965 begin
1966 if Nkind (Constr) = N_Pragma then
1967 Error_Pragma
1968 ("pragma % must appear immediately within the statements "
1969 & "of a loop");
1970 else
1971 Error_Pragma_Arg
1972 ("block containing pragma % must appear immediately within "
1973 & "the statements of a loop", Constr);
1974 end if;
1975 end Placement_Error;
1976
1977 -- Local declarations
1978
1979 Prev : Node_Id;
1980 Stmt : Node_Id;
1981
1982 -- Start of processing for Check_Loop_Pragma_Placement
1983
1984 begin
1985 Prev := N;
1986 Stmt := Parent (N);
1987 while Present (Stmt) loop
1988
1989 -- The pragma or previous block must appear immediately within the
1990 -- current block's declarative or statement part.
1991
1992 if Nkind (Stmt) = N_Block_Statement then
1993 if (No (Declarations (Stmt))
1994 or else List_Containing (Prev) /= Declarations (Stmt))
1995 and then
1996 List_Containing (Prev) /=
1997 Statements (Handled_Statement_Sequence (Stmt))
1998 then
1999 Placement_Error (Prev);
2000 return;
2001
2002 -- Keep inspecting the parents because we are now within a
2003 -- chain of nested blocks.
2004
2005 else
2006 Prev := Stmt;
2007 Stmt := Parent (Stmt);
2008 end if;
2009
2010 -- The pragma or previous block must appear immediately within the
2011 -- statements of the loop.
2012
2013 elsif Nkind (Stmt) = N_Loop_Statement then
2014 if List_Containing (Prev) /= Statements (Stmt) then
2015 Placement_Error (Prev);
2016 end if;
2017
2018 -- Stop the traversal because we reached the innermost loop
2019 -- regardless of whether we encountered an error or not.
2020
2021 return;
2022
2023 -- Ignore a handled statement sequence. Note that this node may
2024 -- be related to a subprogram body in which case we will emit an
2025 -- error on the next iteration of the search.
2026
2027 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
2028 Stmt := Parent (Stmt);
2029
2030 -- Any other statement breaks the chain from the pragma to the
2031 -- loop.
2032
2033 else
2034 Placement_Error (Prev);
2035 return;
2036 end if;
2037 end loop;
2038 end Check_Loop_Pragma_Placement;
2039
2040 -------------------------------------------
2041 -- Check_Is_In_Decl_Part_Or_Package_Spec --
2042 -------------------------------------------
2043
2044 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
2045 P : Node_Id;
2046
2047 begin
2048 P := Parent (N);
2049 loop
2050 if No (P) then
2051 exit;
2052
2053 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
2054 exit;
2055
2056 elsif Nkind_In (P, N_Package_Specification,
2057 N_Block_Statement)
2058 then
2059 return;
2060
2061 -- Note: the following tests seem a little peculiar, because
2062 -- they test for bodies, but if we were in the statement part
2063 -- of the body, we would already have hit the handled statement
2064 -- sequence, so the only way we get here is by being in the
2065 -- declarative part of the body.
2066
2067 elsif Nkind_In (P, N_Subprogram_Body,
2068 N_Package_Body,
2069 N_Task_Body,
2070 N_Entry_Body)
2071 then
2072 return;
2073 end if;
2074
2075 P := Parent (P);
2076 end loop;
2077
2078 Error_Pragma ("pragma% is not in declarative part or package spec");
2079 end Check_Is_In_Decl_Part_Or_Package_Spec;
2080
2081 -------------------------
2082 -- Check_No_Identifier --
2083 -------------------------
2084
2085 procedure Check_No_Identifier (Arg : Node_Id) is
2086 begin
2087 if Nkind (Arg) = N_Pragma_Argument_Association
2088 and then Chars (Arg) /= No_Name
2089 then
2090 Error_Pragma_Arg_Ident
2091 ("pragma% does not permit identifier& here", Arg);
2092 end if;
2093 end Check_No_Identifier;
2094
2095 --------------------------
2096 -- Check_No_Identifiers --
2097 --------------------------
2098
2099 procedure Check_No_Identifiers is
2100 Arg_Node : Node_Id;
2101 begin
2102 if Arg_Count > 0 then
2103 Arg_Node := Arg1;
2104 while Present (Arg_Node) loop
2105 Check_No_Identifier (Arg_Node);
2106 Next (Arg_Node);
2107 end loop;
2108 end if;
2109 end Check_No_Identifiers;
2110
2111 ------------------------
2112 -- Check_No_Link_Name --
2113 ------------------------
2114
2115 procedure Check_No_Link_Name is
2116 begin
2117 if Present (Arg3)
2118 and then Chars (Arg3) = Name_Link_Name
2119 then
2120 Arg4 := Arg3;
2121 end if;
2122
2123 if Present (Arg4) then
2124 Error_Pragma_Arg
2125 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
2126 end if;
2127 end Check_No_Link_Name;
2128
2129 -------------------------------
2130 -- Check_Optional_Identifier --
2131 -------------------------------
2132
2133 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
2134 begin
2135 if Present (Arg)
2136 and then Nkind (Arg) = N_Pragma_Argument_Association
2137 and then Chars (Arg) /= No_Name
2138 then
2139 if Chars (Arg) /= Id then
2140 Error_Msg_Name_1 := Pname;
2141 Error_Msg_Name_2 := Id;
2142 Error_Msg_N ("pragma% argument expects identifier%", Arg);
2143 raise Pragma_Exit;
2144 end if;
2145 end if;
2146 end Check_Optional_Identifier;
2147
2148 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
2149 begin
2150 Name_Buffer (1 .. Id'Length) := Id;
2151 Name_Len := Id'Length;
2152 Check_Optional_Identifier (Arg, Name_Find);
2153 end Check_Optional_Identifier;
2154
2155 --------------------------------------
2156 -- Check_Precondition_Postcondition --
2157 --------------------------------------
2158
2159 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
2160 P : Node_Id;
2161 PO : Node_Id;
2162
2163 procedure Chain_PPC (PO : Node_Id);
2164 -- If PO is an entry or a [generic] subprogram declaration node, then
2165 -- the precondition/postcondition applies to this subprogram and the
2166 -- processing for the pragma is completed. Otherwise the pragma is
2167 -- misplaced.
2168
2169 ---------------
2170 -- Chain_PPC --
2171 ---------------
2172
2173 procedure Chain_PPC (PO : Node_Id) is
2174 S : Entity_Id;
2175
2176 begin
2177 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2178 if not From_Aspect_Specification (N) then
2179 Error_Pragma
2180 ("pragma% cannot be applied to abstract subprogram");
2181
2182 elsif Class_Present (N) then
2183 null;
2184
2185 else
2186 Error_Pragma
2187 ("aspect % requires ''Class for abstract subprogram");
2188 end if;
2189
2190 -- AI05-0230: The same restriction applies to null procedures. For
2191 -- compatibility with earlier uses of the Ada pragma, apply this
2192 -- rule only to aspect specifications.
2193
2194 -- The above discrpency needs documentation. Robert is dubious
2195 -- about whether it is a good idea ???
2196
2197 elsif Nkind (PO) = N_Subprogram_Declaration
2198 and then Nkind (Specification (PO)) = N_Procedure_Specification
2199 and then Null_Present (Specification (PO))
2200 and then From_Aspect_Specification (N)
2201 and then not Class_Present (N)
2202 then
2203 Error_Pragma
2204 ("aspect % requires ''Class for null procedure");
2205
2206 -- Pre/postconditions are legal on a subprogram body if it is not
2207 -- a completion of a declaration. They are also legal on a stub
2208 -- with no previous declarations (this is checked when processing
2209 -- the corresponding aspects).
2210
2211 elsif Nkind (PO) = N_Subprogram_Body
2212 and then Acts_As_Spec (PO)
2213 then
2214 null;
2215
2216 elsif Nkind (PO) = N_Subprogram_Body_Stub then
2217 null;
2218
2219 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2220 N_Expression_Function,
2221 N_Generic_Subprogram_Declaration,
2222 N_Entry_Declaration)
2223 then
2224 Pragma_Misplaced;
2225 end if;
2226
2227 -- Here if we have [generic] subprogram or entry declaration
2228
2229 if Nkind (PO) = N_Entry_Declaration then
2230 S := Defining_Entity (PO);
2231 else
2232 S := Defining_Unit_Name (Specification (PO));
2233
2234 if Nkind (S) = N_Defining_Program_Unit_Name then
2235 S := Defining_Identifier (S);
2236 end if;
2237 end if;
2238
2239 -- Note: we do not analyze the pragma at this point. Instead we
2240 -- delay this analysis until the end of the declarative part in
2241 -- which the pragma appears. This implements the required delay
2242 -- in this analysis, allowing forward references. The analysis
2243 -- happens at the end of Analyze_Declarations.
2244
2245 -- Chain spec PPC pragma to list for subprogram
2246
2247 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
2248 Set_Spec_PPC_List (Contract (S), N);
2249
2250 -- Return indicating spec case
2251
2252 In_Body := False;
2253 return;
2254 end Chain_PPC;
2255
2256 -- Start of processing for Check_Precondition_Postcondition
2257
2258 begin
2259 if not Is_List_Member (N) then
2260 Pragma_Misplaced;
2261 end if;
2262
2263 -- Preanalyze message argument if present. Visibility in this
2264 -- argument is established at the point of pragma occurrence.
2265
2266 if Arg_Count = 2 then
2267 Check_Optional_Identifier (Arg2, Name_Message);
2268 Preanalyze_Spec_Expression
2269 (Get_Pragma_Arg (Arg2), Standard_String);
2270 end if;
2271
2272 -- For a pragma PPC in the extended main source unit, record enabled
2273 -- status in SCO.
2274
2275 -- This may seem redundant with the call to Check_Enabled occurring
2276 -- later on when the pragma is rewritten into a pragma Check but
2277 -- is actually required in the case of a postcondition within a
2278 -- generic.
2279
2280 if Check_Enabled (Pname) and then not Split_PPC (N) then
2281 Set_SCO_Pragma_Enabled (Loc);
2282 end if;
2283
2284 -- If we are within an inlined body, the legality of the pragma
2285 -- has been checked already.
2286
2287 if In_Inlined_Body then
2288 In_Body := True;
2289 return;
2290 end if;
2291
2292 -- Search prior declarations
2293
2294 P := N;
2295 while Present (Prev (P)) loop
2296 P := Prev (P);
2297
2298 -- If the previous node is a generic subprogram, do not go to to
2299 -- the original node, which is the unanalyzed tree: we need to
2300 -- attach the pre/postconditions to the analyzed version at this
2301 -- point. They get propagated to the original tree when analyzing
2302 -- the corresponding body.
2303
2304 if Nkind (P) not in N_Generic_Declaration then
2305 PO := Original_Node (P);
2306 else
2307 PO := P;
2308 end if;
2309
2310 -- Skip past prior pragma
2311
2312 if Nkind (PO) = N_Pragma then
2313 null;
2314
2315 -- Skip stuff not coming from source
2316
2317 elsif not Comes_From_Source (PO) then
2318
2319 -- The condition may apply to a subprogram instantiation
2320
2321 if Nkind (PO) = N_Subprogram_Declaration
2322 and then Present (Generic_Parent (Specification (PO)))
2323 then
2324 Chain_PPC (PO);
2325 return;
2326
2327 elsif Nkind (PO) = N_Subprogram_Declaration
2328 and then In_Instance
2329 then
2330 Chain_PPC (PO);
2331 return;
2332
2333 -- For all other cases of non source code, do nothing
2334
2335 else
2336 null;
2337 end if;
2338
2339 -- Only remaining possibility is subprogram declaration
2340
2341 else
2342 Chain_PPC (PO);
2343 return;
2344 end if;
2345 end loop;
2346
2347 -- If we fall through loop, pragma is at start of list, so see if it
2348 -- is at the start of declarations of a subprogram body.
2349
2350 if Nkind (Parent (N)) = N_Subprogram_Body
2351 and then List_Containing (N) = Declarations (Parent (N))
2352 then
2353 if Operating_Mode /= Generate_Code
2354 or else Inside_A_Generic
2355 then
2356 -- Analyze pragma expression for correctness and for ASIS use
2357
2358 Preanalyze_Assert_Expression
2359 (Get_Pragma_Arg (Arg1), Standard_Boolean);
2360
2361 -- In ASIS mode, for a pragma generated from a source aspect,
2362 -- also analyze the original aspect expression.
2363
2364 if ASIS_Mode
2365 and then Present (Corresponding_Aspect (N))
2366 then
2367 Preanalyze_Assert_Expression
2368 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2369 end if;
2370 end if;
2371
2372 In_Body := True;
2373 return;
2374
2375 -- See if it is in the pragmas after a library level subprogram
2376
2377 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2378
2379 -- In formal verification mode, analyze pragma expression for
2380 -- correctness, as it is not expanded later.
2381
2382 if Alfa_Mode then
2383 Analyze_PPC_In_Decl_Part
2384 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2385 end if;
2386
2387 Chain_PPC (Unit (Parent (Parent (N))));
2388 return;
2389 end if;
2390
2391 -- If we fall through, pragma was misplaced
2392
2393 Pragma_Misplaced;
2394 end Check_Precondition_Postcondition;
2395
2396 -----------------------------
2397 -- Check_Static_Constraint --
2398 -----------------------------
2399
2400 -- Note: for convenience in writing this procedure, in addition to
2401 -- the officially (i.e. by spec) allowed argument which is always a
2402 -- constraint, it also allows ranges and discriminant associations.
2403 -- Above is not clear ???
2404
2405 procedure Check_Static_Constraint (Constr : Node_Id) is
2406
2407 procedure Require_Static (E : Node_Id);
2408 -- Require given expression to be static expression
2409
2410 --------------------
2411 -- Require_Static --
2412 --------------------
2413
2414 procedure Require_Static (E : Node_Id) is
2415 begin
2416 if not Is_OK_Static_Expression (E) then
2417 Flag_Non_Static_Expr
2418 ("non-static constraint not allowed in Unchecked_Union!", E);
2419 raise Pragma_Exit;
2420 end if;
2421 end Require_Static;
2422
2423 -- Start of processing for Check_Static_Constraint
2424
2425 begin
2426 case Nkind (Constr) is
2427 when N_Discriminant_Association =>
2428 Require_Static (Expression (Constr));
2429
2430 when N_Range =>
2431 Require_Static (Low_Bound (Constr));
2432 Require_Static (High_Bound (Constr));
2433
2434 when N_Attribute_Reference =>
2435 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2436 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2437
2438 when N_Range_Constraint =>
2439 Check_Static_Constraint (Range_Expression (Constr));
2440
2441 when N_Index_Or_Discriminant_Constraint =>
2442 declare
2443 IDC : Entity_Id;
2444 begin
2445 IDC := First (Constraints (Constr));
2446 while Present (IDC) loop
2447 Check_Static_Constraint (IDC);
2448 Next (IDC);
2449 end loop;
2450 end;
2451
2452 when others =>
2453 null;
2454 end case;
2455 end Check_Static_Constraint;
2456
2457 --------------------------------------
2458 -- Check_Valid_Configuration_Pragma --
2459 --------------------------------------
2460
2461 -- A configuration pragma must appear in the context clause of a
2462 -- compilation unit, and only other pragmas may precede it. Note that
2463 -- the test also allows use in a configuration pragma file.
2464
2465 procedure Check_Valid_Configuration_Pragma is
2466 begin
2467 if not Is_Configuration_Pragma then
2468 Error_Pragma ("incorrect placement for configuration pragma%");
2469 end if;
2470 end Check_Valid_Configuration_Pragma;
2471
2472 -------------------------------------
2473 -- Check_Valid_Library_Unit_Pragma --
2474 -------------------------------------
2475
2476 procedure Check_Valid_Library_Unit_Pragma is
2477 Plist : List_Id;
2478 Parent_Node : Node_Id;
2479 Unit_Name : Entity_Id;
2480 Unit_Kind : Node_Kind;
2481 Unit_Node : Node_Id;
2482 Sindex : Source_File_Index;
2483
2484 begin
2485 if not Is_List_Member (N) then
2486 Pragma_Misplaced;
2487
2488 else
2489 Plist := List_Containing (N);
2490 Parent_Node := Parent (Plist);
2491
2492 if Parent_Node = Empty then
2493 Pragma_Misplaced;
2494
2495 -- Case of pragma appearing after a compilation unit. In this case
2496 -- it must have an argument with the corresponding name and must
2497 -- be part of the following pragmas of its parent.
2498
2499 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2500 if Plist /= Pragmas_After (Parent_Node) then
2501 Pragma_Misplaced;
2502
2503 elsif Arg_Count = 0 then
2504 Error_Pragma
2505 ("argument required if outside compilation unit");
2506
2507 else
2508 Check_No_Identifiers;
2509 Check_Arg_Count (1);
2510 Unit_Node := Unit (Parent (Parent_Node));
2511 Unit_Kind := Nkind (Unit_Node);
2512
2513 Analyze (Get_Pragma_Arg (Arg1));
2514
2515 if Unit_Kind = N_Generic_Subprogram_Declaration
2516 or else Unit_Kind = N_Subprogram_Declaration
2517 then
2518 Unit_Name := Defining_Entity (Unit_Node);
2519
2520 elsif Unit_Kind in N_Generic_Instantiation then
2521 Unit_Name := Defining_Entity (Unit_Node);
2522
2523 else
2524 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2525 end if;
2526
2527 if Chars (Unit_Name) /=
2528 Chars (Entity (Get_Pragma_Arg (Arg1)))
2529 then
2530 Error_Pragma_Arg
2531 ("pragma% argument is not current unit name", Arg1);
2532 end if;
2533
2534 if Ekind (Unit_Name) = E_Package
2535 and then Present (Renamed_Entity (Unit_Name))
2536 then
2537 Error_Pragma ("pragma% not allowed for renamed package");
2538 end if;
2539 end if;
2540
2541 -- Pragma appears other than after a compilation unit
2542
2543 else
2544 -- Here we check for the generic instantiation case and also
2545 -- for the case of processing a generic formal package. We
2546 -- detect these cases by noting that the Sloc on the node
2547 -- does not belong to the current compilation unit.
2548
2549 Sindex := Source_Index (Current_Sem_Unit);
2550
2551 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2552 Rewrite (N, Make_Null_Statement (Loc));
2553 return;
2554
2555 -- If before first declaration, the pragma applies to the
2556 -- enclosing unit, and the name if present must be this name.
2557
2558 elsif Is_Before_First_Decl (N, Plist) then
2559 Unit_Node := Unit_Declaration_Node (Current_Scope);
2560 Unit_Kind := Nkind (Unit_Node);
2561
2562 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2563 Pragma_Misplaced;
2564
2565 elsif Unit_Kind = N_Subprogram_Body
2566 and then not Acts_As_Spec (Unit_Node)
2567 then
2568 Pragma_Misplaced;
2569
2570 elsif Nkind (Parent_Node) = N_Package_Body then
2571 Pragma_Misplaced;
2572
2573 elsif Nkind (Parent_Node) = N_Package_Specification
2574 and then Plist = Private_Declarations (Parent_Node)
2575 then
2576 Pragma_Misplaced;
2577
2578 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2579 or else Nkind (Parent_Node) =
2580 N_Generic_Subprogram_Declaration)
2581 and then Plist = Generic_Formal_Declarations (Parent_Node)
2582 then
2583 Pragma_Misplaced;
2584
2585 elsif Arg_Count > 0 then
2586 Analyze (Get_Pragma_Arg (Arg1));
2587
2588 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2589 Error_Pragma_Arg
2590 ("name in pragma% must be enclosing unit", Arg1);
2591 end if;
2592
2593 -- It is legal to have no argument in this context
2594
2595 else
2596 return;
2597 end if;
2598
2599 -- Error if not before first declaration. This is because a
2600 -- library unit pragma argument must be the name of a library
2601 -- unit (RM 10.1.5(7)), but the only names permitted in this
2602 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2603 -- generic subprogram declarations or generic instantiations.
2604
2605 else
2606 Error_Pragma
2607 ("pragma% misplaced, must be before first declaration");
2608 end if;
2609 end if;
2610 end if;
2611 end Check_Valid_Library_Unit_Pragma;
2612
2613 -------------------
2614 -- Check_Variant --
2615 -------------------
2616
2617 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2618 Clist : constant Node_Id := Component_List (Variant);
2619 Comp : Node_Id;
2620
2621 begin
2622 Comp := First (Component_Items (Clist));
2623 while Present (Comp) loop
2624 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2625 Next (Comp);
2626 end loop;
2627 end Check_Variant;
2628
2629 ------------------
2630 -- Error_Pragma --
2631 ------------------
2632
2633 procedure Error_Pragma (Msg : String) is
2634 MsgF : String := Msg;
2635 begin
2636 Error_Msg_Name_1 := Pname;
2637 Fix_Error (MsgF);
2638 Error_Msg_N (MsgF, N);
2639 raise Pragma_Exit;
2640 end Error_Pragma;
2641
2642 ----------------------
2643 -- Error_Pragma_Arg --
2644 ----------------------
2645
2646 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2647 MsgF : String := Msg;
2648 begin
2649 Error_Msg_Name_1 := Pname;
2650 Fix_Error (MsgF);
2651 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2652 raise Pragma_Exit;
2653 end Error_Pragma_Arg;
2654
2655 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2656 MsgF : String := Msg1;
2657 begin
2658 Error_Msg_Name_1 := Pname;
2659 Fix_Error (MsgF);
2660 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2661 Error_Pragma_Arg (Msg2, Arg);
2662 end Error_Pragma_Arg;
2663
2664 ----------------------------
2665 -- Error_Pragma_Arg_Ident --
2666 ----------------------------
2667
2668 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2669 MsgF : String := Msg;
2670 begin
2671 Error_Msg_Name_1 := Pname;
2672 Fix_Error (MsgF);
2673 Error_Msg_N (MsgF, Arg);
2674 raise Pragma_Exit;
2675 end Error_Pragma_Arg_Ident;
2676
2677 ----------------------
2678 -- Error_Pragma_Ref --
2679 ----------------------
2680
2681 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2682 MsgF : String := Msg;
2683 begin
2684 Error_Msg_Name_1 := Pname;
2685 Fix_Error (MsgF);
2686 Error_Msg_Sloc := Sloc (Ref);
2687 Error_Msg_NE (MsgF, N, Ref);
2688 raise Pragma_Exit;
2689 end Error_Pragma_Ref;
2690
2691 ------------------------
2692 -- Find_Lib_Unit_Name --
2693 ------------------------
2694
2695 function Find_Lib_Unit_Name return Entity_Id is
2696 begin
2697 -- Return inner compilation unit entity, for case of nested
2698 -- categorization pragmas. This happens in generic unit.
2699
2700 if Nkind (Parent (N)) = N_Package_Specification
2701 and then Defining_Entity (Parent (N)) /= Current_Scope
2702 then
2703 return Defining_Entity (Parent (N));
2704 else
2705 return Current_Scope;
2706 end if;
2707 end Find_Lib_Unit_Name;
2708
2709 ----------------------------
2710 -- Find_Program_Unit_Name --
2711 ----------------------------
2712
2713 procedure Find_Program_Unit_Name (Id : Node_Id) is
2714 Unit_Name : Entity_Id;
2715 Unit_Kind : Node_Kind;
2716 P : constant Node_Id := Parent (N);
2717
2718 begin
2719 if Nkind (P) = N_Compilation_Unit then
2720 Unit_Kind := Nkind (Unit (P));
2721
2722 if Unit_Kind = N_Subprogram_Declaration
2723 or else Unit_Kind = N_Package_Declaration
2724 or else Unit_Kind in N_Generic_Declaration
2725 then
2726 Unit_Name := Defining_Entity (Unit (P));
2727
2728 if Chars (Id) = Chars (Unit_Name) then
2729 Set_Entity (Id, Unit_Name);
2730 Set_Etype (Id, Etype (Unit_Name));
2731 else
2732 Set_Etype (Id, Any_Type);
2733 Error_Pragma
2734 ("cannot find program unit referenced by pragma%");
2735 end if;
2736
2737 else
2738 Set_Etype (Id, Any_Type);
2739 Error_Pragma ("pragma% inapplicable to this unit");
2740 end if;
2741
2742 else
2743 Analyze (Id);
2744 end if;
2745 end Find_Program_Unit_Name;
2746
2747 -----------------------------------------
2748 -- Find_Unique_Parameterless_Procedure --
2749 -----------------------------------------
2750
2751 function Find_Unique_Parameterless_Procedure
2752 (Name : Entity_Id;
2753 Arg : Node_Id) return Entity_Id
2754 is
2755 Proc : Entity_Id := Empty;
2756
2757 begin
2758 -- The body of this procedure needs some comments ???
2759
2760 if not Is_Entity_Name (Name) then
2761 Error_Pragma_Arg
2762 ("argument of pragma% must be entity name", Arg);
2763
2764 elsif not Is_Overloaded (Name) then
2765 Proc := Entity (Name);
2766
2767 if Ekind (Proc) /= E_Procedure
2768 or else Present (First_Formal (Proc))
2769 then
2770 Error_Pragma_Arg
2771 ("argument of pragma% must be parameterless procedure", Arg);
2772 end if;
2773
2774 else
2775 declare
2776 Found : Boolean := False;
2777 It : Interp;
2778 Index : Interp_Index;
2779
2780 begin
2781 Get_First_Interp (Name, Index, It);
2782 while Present (It.Nam) loop
2783 Proc := It.Nam;
2784
2785 if Ekind (Proc) = E_Procedure
2786 and then No (First_Formal (Proc))
2787 then
2788 if not Found then
2789 Found := True;
2790 Set_Entity (Name, Proc);
2791 Set_Is_Overloaded (Name, False);
2792 else
2793 Error_Pragma_Arg
2794 ("ambiguous handler name for pragma% ", Arg);
2795 end if;
2796 end if;
2797
2798 Get_Next_Interp (Index, It);
2799 end loop;
2800
2801 if not Found then
2802 Error_Pragma_Arg
2803 ("argument of pragma% must be parameterless procedure",
2804 Arg);
2805 else
2806 Proc := Entity (Name);
2807 end if;
2808 end;
2809 end if;
2810
2811 return Proc;
2812 end Find_Unique_Parameterless_Procedure;
2813
2814 ---------------
2815 -- Fix_Error --
2816 ---------------
2817
2818 procedure Fix_Error (Msg : in out String) is
2819 begin
2820 if From_Aspect_Specification (N) then
2821 for J in Msg'First .. Msg'Last - 5 loop
2822 if Msg (J .. J + 5) = "pragma" then
2823 Msg (J .. J + 5) := "aspect";
2824 end if;
2825 end loop;
2826
2827 if Error_Msg_Name_1 = Name_Precondition then
2828 Error_Msg_Name_1 := Name_Pre;
2829 elsif Error_Msg_Name_1 = Name_Postcondition then
2830 Error_Msg_Name_1 := Name_Post;
2831 end if;
2832 end if;
2833 end Fix_Error;
2834
2835 -------------------------
2836 -- Gather_Associations --
2837 -------------------------
2838
2839 procedure Gather_Associations
2840 (Names : Name_List;
2841 Args : out Args_List)
2842 is
2843 Arg : Node_Id;
2844
2845 begin
2846 -- Initialize all parameters to Empty
2847
2848 for J in Args'Range loop
2849 Args (J) := Empty;
2850 end loop;
2851
2852 -- That's all we have to do if there are no argument associations
2853
2854 if No (Pragma_Argument_Associations (N)) then
2855 return;
2856 end if;
2857
2858 -- Otherwise first deal with any positional parameters present
2859
2860 Arg := First (Pragma_Argument_Associations (N));
2861 for Index in Args'Range loop
2862 exit when No (Arg) or else Chars (Arg) /= No_Name;
2863 Args (Index) := Get_Pragma_Arg (Arg);
2864 Next (Arg);
2865 end loop;
2866
2867 -- Positional parameters all processed, if any left, then we
2868 -- have too many positional parameters.
2869
2870 if Present (Arg) and then Chars (Arg) = No_Name then
2871 Error_Pragma_Arg
2872 ("too many positional associations for pragma%", Arg);
2873 end if;
2874
2875 -- Process named parameters if any are present
2876
2877 while Present (Arg) loop
2878 if Chars (Arg) = No_Name then
2879 Error_Pragma_Arg
2880 ("positional association cannot follow named association",
2881 Arg);
2882
2883 else
2884 for Index in Names'Range loop
2885 if Names (Index) = Chars (Arg) then
2886 if Present (Args (Index)) then
2887 Error_Pragma_Arg
2888 ("duplicate argument association for pragma%", Arg);
2889 else
2890 Args (Index) := Get_Pragma_Arg (Arg);
2891 exit;
2892 end if;
2893 end if;
2894
2895 if Index = Names'Last then
2896 Error_Msg_Name_1 := Pname;
2897 Error_Msg_N ("pragma% does not allow & argument", Arg);
2898
2899 -- Check for possible misspelling
2900
2901 for Index1 in Names'Range loop
2902 if Is_Bad_Spelling_Of
2903 (Chars (Arg), Names (Index1))
2904 then
2905 Error_Msg_Name_1 := Names (Index1);
2906 Error_Msg_N -- CODEFIX
2907 ("\possible misspelling of%", Arg);
2908 exit;
2909 end if;
2910 end loop;
2911
2912 raise Pragma_Exit;
2913 end if;
2914 end loop;
2915 end if;
2916
2917 Next (Arg);
2918 end loop;
2919 end Gather_Associations;
2920
2921 -----------------
2922 -- GNAT_Pragma --
2923 -----------------
2924
2925 procedure GNAT_Pragma is
2926 begin
2927 -- We need to check the No_Implementation_Pragmas restriction for
2928 -- the case of a pragma from source. Note that the case of aspects
2929 -- generating corresponding pragmas marks these pragmas as not being
2930 -- from source, so this test also catches that case.
2931
2932 if Comes_From_Source (N) then
2933 Check_Restriction (No_Implementation_Pragmas, N);
2934 end if;
2935 end GNAT_Pragma;
2936
2937 --------------------------
2938 -- Is_Before_First_Decl --
2939 --------------------------
2940
2941 function Is_Before_First_Decl
2942 (Pragma_Node : Node_Id;
2943 Decls : List_Id) return Boolean
2944 is
2945 Item : Node_Id := First (Decls);
2946
2947 begin
2948 -- Only other pragmas can come before this pragma
2949
2950 loop
2951 if No (Item) or else Nkind (Item) /= N_Pragma then
2952 return False;
2953
2954 elsif Item = Pragma_Node then
2955 return True;
2956 end if;
2957
2958 Next (Item);
2959 end loop;
2960 end Is_Before_First_Decl;
2961
2962 -----------------------------
2963 -- Is_Configuration_Pragma --
2964 -----------------------------
2965
2966 -- A configuration pragma must appear in the context clause of a
2967 -- compilation unit, and only other pragmas may precede it. Note that
2968 -- the test below also permits use in a configuration pragma file.
2969
2970 function Is_Configuration_Pragma return Boolean is
2971 Lis : constant List_Id := List_Containing (N);
2972 Par : constant Node_Id := Parent (N);
2973 Prg : Node_Id;
2974
2975 begin
2976 -- If no parent, then we are in the configuration pragma file,
2977 -- so the placement is definitely appropriate.
2978
2979 if No (Par) then
2980 return True;
2981
2982 -- Otherwise we must be in the context clause of a compilation unit
2983 -- and the only thing allowed before us in the context list is more
2984 -- configuration pragmas.
2985
2986 elsif Nkind (Par) = N_Compilation_Unit
2987 and then Context_Items (Par) = Lis
2988 then
2989 Prg := First (Lis);
2990
2991 loop
2992 if Prg = N then
2993 return True;
2994 elsif Nkind (Prg) /= N_Pragma then
2995 return False;
2996 end if;
2997
2998 Next (Prg);
2999 end loop;
3000
3001 else
3002 return False;
3003 end if;
3004 end Is_Configuration_Pragma;
3005
3006 --------------------------
3007 -- Is_In_Context_Clause --
3008 --------------------------
3009
3010 function Is_In_Context_Clause return Boolean is
3011 Plist : List_Id;
3012 Parent_Node : Node_Id;
3013
3014 begin
3015 if not Is_List_Member (N) then
3016 return False;
3017
3018 else
3019 Plist := List_Containing (N);
3020 Parent_Node := Parent (Plist);
3021
3022 if Parent_Node = Empty
3023 or else Nkind (Parent_Node) /= N_Compilation_Unit
3024 or else Context_Items (Parent_Node) /= Plist
3025 then
3026 return False;
3027 end if;
3028 end if;
3029
3030 return True;
3031 end Is_In_Context_Clause;
3032
3033 ---------------------------------
3034 -- Is_Static_String_Expression --
3035 ---------------------------------
3036
3037 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
3038 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3039
3040 begin
3041 Analyze_And_Resolve (Argx);
3042 return Is_OK_Static_Expression (Argx)
3043 and then Nkind (Argx) = N_String_Literal;
3044 end Is_Static_String_Expression;
3045
3046 ----------------------
3047 -- Pragma_Misplaced --
3048 ----------------------
3049
3050 procedure Pragma_Misplaced is
3051 begin
3052 Error_Pragma ("incorrect placement of pragma%");
3053 end Pragma_Misplaced;
3054
3055 ------------------------------------
3056 -- Process_Atomic_Shared_Volatile --
3057 ------------------------------------
3058
3059 procedure Process_Atomic_Shared_Volatile is
3060 E_Id : Node_Id;
3061 E : Entity_Id;
3062 D : Node_Id;
3063 K : Node_Kind;
3064 Utyp : Entity_Id;
3065
3066 procedure Set_Atomic (E : Entity_Id);
3067 -- Set given type as atomic, and if no explicit alignment was given,
3068 -- set alignment to unknown, since back end knows what the alignment
3069 -- requirements are for atomic arrays. Note: this step is necessary
3070 -- for derived types.
3071
3072 ----------------
3073 -- Set_Atomic --
3074 ----------------
3075
3076 procedure Set_Atomic (E : Entity_Id) is
3077 begin
3078 Set_Is_Atomic (E);
3079
3080 if not Has_Alignment_Clause (E) then
3081 Set_Alignment (E, Uint_0);
3082 end if;
3083 end Set_Atomic;
3084
3085 -- Start of processing for Process_Atomic_Shared_Volatile
3086
3087 begin
3088 Check_Ada_83_Warning;
3089 Check_No_Identifiers;
3090 Check_Arg_Count (1);
3091 Check_Arg_Is_Local_Name (Arg1);
3092 E_Id := Get_Pragma_Arg (Arg1);
3093
3094 if Etype (E_Id) = Any_Type then
3095 return;
3096 end if;
3097
3098 E := Entity (E_Id);
3099 D := Declaration_Node (E);
3100 K := Nkind (D);
3101
3102 -- Check duplicate before we chain ourselves!
3103
3104 Check_Duplicate_Pragma (E);
3105
3106 -- Now check appropriateness of the entity
3107
3108 if Is_Type (E) then
3109 if Rep_Item_Too_Early (E, N)
3110 or else
3111 Rep_Item_Too_Late (E, N)
3112 then
3113 return;
3114 else
3115 Check_First_Subtype (Arg1);
3116 end if;
3117
3118 if Prag_Id /= Pragma_Volatile then
3119 Set_Atomic (E);
3120 Set_Atomic (Underlying_Type (E));
3121 Set_Atomic (Base_Type (E));
3122 end if;
3123
3124 -- Attribute belongs on the base type. If the view of the type is
3125 -- currently private, it also belongs on the underlying type.
3126
3127 Set_Is_Volatile (Base_Type (E));
3128 Set_Is_Volatile (Underlying_Type (E));
3129
3130 Set_Treat_As_Volatile (E);
3131 Set_Treat_As_Volatile (Underlying_Type (E));
3132
3133 elsif K = N_Object_Declaration
3134 or else (K = N_Component_Declaration
3135 and then Original_Record_Component (E) = E)
3136 then
3137 if Rep_Item_Too_Late (E, N) then
3138 return;
3139 end if;
3140
3141 if Prag_Id /= Pragma_Volatile then
3142 Set_Is_Atomic (E);
3143
3144 -- If the object declaration has an explicit initialization, a
3145 -- temporary may have to be created to hold the expression, to
3146 -- ensure that access to the object remain atomic.
3147
3148 if Nkind (Parent (E)) = N_Object_Declaration
3149 and then Present (Expression (Parent (E)))
3150 then
3151 Set_Has_Delayed_Freeze (E);
3152 end if;
3153
3154 -- An interesting improvement here. If an object of composite
3155 -- type X is declared atomic, and the type X isn't, that's a
3156 -- pity, since it may not have appropriate alignment etc. We
3157 -- can rescue this in the special case where the object and
3158 -- type are in the same unit by just setting the type as
3159 -- atomic, so that the back end will process it as atomic.
3160
3161 -- Note: we used to do this for elementary types as well,
3162 -- but that turns out to be a bad idea and can have unwanted
3163 -- effects, most notably if the type is elementary, the object
3164 -- a simple component within a record, and both are in a spec:
3165 -- every object of this type in the entire program will be
3166 -- treated as atomic, thus incurring a potentially costly
3167 -- synchronization operation for every access.
3168
3169 -- Of course it would be best if the back end could just adjust
3170 -- the alignment etc for the specific object, but that's not
3171 -- something we are capable of doing at this point.
3172
3173 Utyp := Underlying_Type (Etype (E));
3174
3175 if Present (Utyp)
3176 and then Is_Composite_Type (Utyp)
3177 and then Sloc (E) > No_Location
3178 and then Sloc (Utyp) > No_Location
3179 and then
3180 Get_Source_File_Index (Sloc (E)) =
3181 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
3182 then
3183 Set_Is_Atomic (Underlying_Type (Etype (E)));
3184 end if;
3185 end if;
3186
3187 Set_Is_Volatile (E);
3188 Set_Treat_As_Volatile (E);
3189
3190 else
3191 Error_Pragma_Arg
3192 ("inappropriate entity for pragma%", Arg1);
3193 end if;
3194 end Process_Atomic_Shared_Volatile;
3195
3196 -------------------------------------------
3197 -- Process_Compile_Time_Warning_Or_Error --
3198 -------------------------------------------
3199
3200 procedure Process_Compile_Time_Warning_Or_Error is
3201 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
3202
3203 begin
3204 Check_Arg_Count (2);
3205 Check_No_Identifiers;
3206 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3207 Analyze_And_Resolve (Arg1x, Standard_Boolean);
3208
3209 if Compile_Time_Known_Value (Arg1x) then
3210 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3211 declare
3212 Str : constant String_Id :=
3213 Strval (Get_Pragma_Arg (Arg2));
3214 Len : constant Int := String_Length (Str);
3215 Cont : Boolean;
3216 Ptr : Nat;
3217 CC : Char_Code;
3218 C : Character;
3219 Cent : constant Entity_Id :=
3220 Cunit_Entity (Current_Sem_Unit);
3221
3222 Force : constant Boolean :=
3223 Prag_Id = Pragma_Compile_Time_Warning
3224 and then
3225 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3226 and then (Ekind (Cent) /= E_Package
3227 or else not In_Private_Part (Cent));
3228 -- Set True if this is the warning case, and we are in the
3229 -- visible part of a package spec, or in a subprogram spec,
3230 -- in which case we want to force the client to see the
3231 -- warning, even though it is not in the main unit.
3232
3233 begin
3234 -- Loop through segments of message separated by line feeds.
3235 -- We output these segments as separate messages with
3236 -- continuation marks for all but the first.
3237
3238 Cont := False;
3239 Ptr := 1;
3240 loop
3241 Error_Msg_Strlen := 0;
3242
3243 -- Loop to copy characters from argument to error message
3244 -- string buffer.
3245
3246 loop
3247 exit when Ptr > Len;
3248 CC := Get_String_Char (Str, Ptr);
3249 Ptr := Ptr + 1;
3250
3251 -- Ignore wide chars ??? else store character
3252
3253 if In_Character_Range (CC) then
3254 C := Get_Character (CC);
3255 exit when C = ASCII.LF;
3256 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3257 Error_Msg_String (Error_Msg_Strlen) := C;
3258 end if;
3259 end loop;
3260
3261 -- Here with one line ready to go
3262
3263 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3264
3265 -- If this is a warning in a spec, then we want clients
3266 -- to see the warning, so mark the message with the
3267 -- special sequence !! to force the warning. In the case
3268 -- of a package spec, we do not force this if we are in
3269 -- the private part of the spec.
3270
3271 if Force then
3272 if Cont = False then
3273 Error_Msg_N ("<~!!", Arg1);
3274 Cont := True;
3275 else
3276 Error_Msg_N ("\<~!!", Arg1);
3277 end if;
3278
3279 -- Error, rather than warning, or in a body, so we do not
3280 -- need to force visibility for client (error will be
3281 -- output in any case, and this is the situation in which
3282 -- we do not want a client to get a warning, since the
3283 -- warning is in the body or the spec private part).
3284
3285 else
3286 if Cont = False then
3287 Error_Msg_N ("<~", Arg1);
3288 Cont := True;
3289 else
3290 Error_Msg_N ("\<~", Arg1);
3291 end if;
3292 end if;
3293
3294 exit when Ptr > Len;
3295 end loop;
3296 end;
3297 end if;
3298 end if;
3299 end Process_Compile_Time_Warning_Or_Error;
3300
3301 ------------------------
3302 -- Process_Convention --
3303 ------------------------
3304
3305 procedure Process_Convention
3306 (C : out Convention_Id;
3307 Ent : out Entity_Id)
3308 is
3309 Id : Node_Id;
3310 E : Entity_Id;
3311 E1 : Entity_Id;
3312 Cname : Name_Id;
3313 Comp_Unit : Unit_Number_Type;
3314
3315 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3316 -- Called if we have more than one Export/Import/Convention pragma.
3317 -- This is generally illegal, but we have a special case of allowing
3318 -- Import and Interface to coexist if they specify the convention in
3319 -- a consistent manner. We are allowed to do this, since Interface is
3320 -- an implementation defined pragma, and we choose to do it since we
3321 -- know Rational allows this combination. S is the entity id of the
3322 -- subprogram in question. This procedure also sets the special flag
3323 -- Import_Interface_Present in both pragmas in the case where we do
3324 -- have matching Import and Interface pragmas.
3325
3326 procedure Set_Convention_From_Pragma (E : Entity_Id);
3327 -- Set convention in entity E, and also flag that the entity has a
3328 -- convention pragma. If entity is for a private or incomplete type,
3329 -- also set convention and flag on underlying type. This procedure
3330 -- also deals with the special case of C_Pass_By_Copy convention.
3331
3332 -------------------------------
3333 -- Diagnose_Multiple_Pragmas --
3334 -------------------------------
3335
3336 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3337 Pdec : constant Node_Id := Declaration_Node (S);
3338 Decl : Node_Id;
3339 Err : Boolean;
3340
3341 function Same_Convention (Decl : Node_Id) return Boolean;
3342 -- Decl is a pragma node. This function returns True if this
3343 -- pragma has a first argument that is an identifier with a
3344 -- Chars field corresponding to the Convention_Id C.
3345
3346 function Same_Name (Decl : Node_Id) return Boolean;
3347 -- Decl is a pragma node. This function returns True if this
3348 -- pragma has a second argument that is an identifier with a
3349 -- Chars field that matches the Chars of the current subprogram.
3350
3351 ---------------------
3352 -- Same_Convention --
3353 ---------------------
3354
3355 function Same_Convention (Decl : Node_Id) return Boolean is
3356 Arg1 : constant Node_Id :=
3357 First (Pragma_Argument_Associations (Decl));
3358
3359 begin
3360 if Present (Arg1) then
3361 declare
3362 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3363 begin
3364 if Nkind (Arg) = N_Identifier
3365 and then Is_Convention_Name (Chars (Arg))
3366 and then Get_Convention_Id (Chars (Arg)) = C
3367 then
3368 return True;
3369 end if;
3370 end;
3371 end if;
3372
3373 return False;
3374 end Same_Convention;
3375
3376 ---------------
3377 -- Same_Name --
3378 ---------------
3379
3380 function Same_Name (Decl : Node_Id) return Boolean is
3381 Arg1 : constant Node_Id :=
3382 First (Pragma_Argument_Associations (Decl));
3383 Arg2 : Node_Id;
3384
3385 begin
3386 if No (Arg1) then
3387 return False;
3388 end if;
3389
3390 Arg2 := Next (Arg1);
3391
3392 if No (Arg2) then
3393 return False;
3394 end if;
3395
3396 declare
3397 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3398 begin
3399 if Nkind (Arg) = N_Identifier
3400 and then Chars (Arg) = Chars (S)
3401 then
3402 return True;
3403 end if;
3404 end;
3405
3406 return False;
3407 end Same_Name;
3408
3409 -- Start of processing for Diagnose_Multiple_Pragmas
3410
3411 begin
3412 Err := True;
3413
3414 -- Definitely give message if we have Convention/Export here
3415
3416 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3417 null;
3418
3419 -- If we have an Import or Export, scan back from pragma to
3420 -- find any previous pragma applying to the same procedure.
3421 -- The scan will be terminated by the start of the list, or
3422 -- hitting the subprogram declaration. This won't allow one
3423 -- pragma to appear in the public part and one in the private
3424 -- part, but that seems very unlikely in practice.
3425
3426 else
3427 Decl := Prev (N);
3428 while Present (Decl) and then Decl /= Pdec loop
3429
3430 -- Look for pragma with same name as us
3431
3432 if Nkind (Decl) = N_Pragma
3433 and then Same_Name (Decl)
3434 then
3435 -- Give error if same as our pragma or Export/Convention
3436
3437 if Pragma_Name (Decl) = Name_Export
3438 or else
3439 Pragma_Name (Decl) = Name_Convention
3440 or else
3441 Pragma_Name (Decl) = Pragma_Name (N)
3442 then
3443 exit;
3444
3445 -- Case of Import/Interface or the other way round
3446
3447 elsif Pragma_Name (Decl) = Name_Interface
3448 or else
3449 Pragma_Name (Decl) = Name_Import
3450 then
3451 -- Here we know that we have Import and Interface. It
3452 -- doesn't matter which way round they are. See if
3453 -- they specify the same convention. If so, all OK,
3454 -- and set special flags to stop other messages
3455
3456 if Same_Convention (Decl) then
3457 Set_Import_Interface_Present (N);
3458 Set_Import_Interface_Present (Decl);
3459 Err := False;
3460
3461 -- If different conventions, special message
3462
3463 else
3464 Error_Msg_Sloc := Sloc (Decl);
3465 Error_Pragma_Arg
3466 ("convention differs from that given#", Arg1);
3467 return;
3468 end if;
3469 end if;
3470 end if;
3471
3472 Next (Decl);
3473 end loop;
3474 end if;
3475
3476 -- Give message if needed if we fall through those tests
3477 -- except on Relaxed_RM_Semantics where we let go: either this
3478 -- is a case accepted/ignored by other Ada compilers (e.g.
3479 -- a mix of Convention and Import), or another error will be
3480 -- generated later (e.g. using both Import and Export).
3481
3482 if Err and not Relaxed_RM_Semantics then
3483 Error_Pragma_Arg
3484 ("at most one Convention/Export/Import pragma is allowed",
3485 Arg2);
3486 end if;
3487 end Diagnose_Multiple_Pragmas;
3488
3489 --------------------------------
3490 -- Set_Convention_From_Pragma --
3491 --------------------------------
3492
3493 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3494 begin
3495 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3496 -- for an overridden dispatching operation. Technically this is
3497 -- an amendment and should only be done in Ada 2005 mode. However,
3498 -- this is clearly a mistake, since the problem that is addressed
3499 -- by this AI is that there is a clear gap in the RM!
3500
3501 if Is_Dispatching_Operation (E)
3502 and then Present (Overridden_Operation (E))
3503 and then C /= Convention (Overridden_Operation (E))
3504 then
3505 Error_Pragma_Arg
3506 ("cannot change convention for overridden dispatching "
3507 & "operation", Arg1);
3508 end if;
3509
3510 -- Set the convention
3511
3512 Set_Convention (E, C);
3513 Set_Has_Convention_Pragma (E);
3514
3515 if Is_Incomplete_Or_Private_Type (E)
3516 and then Present (Underlying_Type (E))
3517 then
3518 Set_Convention (Underlying_Type (E), C);
3519 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3520 end if;
3521
3522 -- A class-wide type should inherit the convention of the specific
3523 -- root type (although this isn't specified clearly by the RM).
3524
3525 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3526 Set_Convention (Class_Wide_Type (E), C);
3527 end if;
3528
3529 -- If the entity is a record type, then check for special case of
3530 -- C_Pass_By_Copy, which is treated the same as C except that the
3531 -- special record flag is set. This convention is only permitted
3532 -- on record types (see AI95-00131).
3533
3534 if Cname = Name_C_Pass_By_Copy then
3535 if Is_Record_Type (E) then
3536 Set_C_Pass_By_Copy (Base_Type (E));
3537 elsif Is_Incomplete_Or_Private_Type (E)
3538 and then Is_Record_Type (Underlying_Type (E))
3539 then
3540 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3541 else
3542 Error_Pragma_Arg
3543 ("C_Pass_By_Copy convention allowed only for record type",
3544 Arg2);
3545 end if;
3546 end if;
3547
3548 -- If the entity is a derived boolean type, check for the special
3549 -- case of convention C, C++, or Fortran, where we consider any
3550 -- nonzero value to represent true.
3551
3552 if Is_Discrete_Type (E)
3553 and then Root_Type (Etype (E)) = Standard_Boolean
3554 and then
3555 (C = Convention_C
3556 or else
3557 C = Convention_CPP
3558 or else
3559 C = Convention_Fortran)
3560 then
3561 Set_Nonzero_Is_True (Base_Type (E));
3562 end if;
3563 end Set_Convention_From_Pragma;
3564
3565 -- Start of processing for Process_Convention
3566
3567 begin
3568 Check_At_Least_N_Arguments (2);
3569 Check_Optional_Identifier (Arg1, Name_Convention);
3570 Check_Arg_Is_Identifier (Arg1);
3571 Cname := Chars (Get_Pragma_Arg (Arg1));
3572
3573 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3574 -- tested again below to set the critical flag).
3575
3576 if Cname = Name_C_Pass_By_Copy then
3577 C := Convention_C;
3578
3579 -- Otherwise we must have something in the standard convention list
3580
3581 elsif Is_Convention_Name (Cname) then
3582 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3583
3584 -- In DEC VMS, it seems that there is an undocumented feature that
3585 -- any unrecognized convention is treated as the default, which for
3586 -- us is convention C. It does not seem so terrible to do this
3587 -- unconditionally, silently in the VMS case, and with a warning
3588 -- in the non-VMS case.
3589
3590 else
3591 if Warn_On_Export_Import and not OpenVMS_On_Target then
3592 Error_Msg_N
3593 ("??unrecognized convention name, C assumed",
3594 Get_Pragma_Arg (Arg1));
3595 end if;
3596
3597 C := Convention_C;
3598 end if;
3599
3600 Check_Optional_Identifier (Arg2, Name_Entity);
3601 Check_Arg_Is_Local_Name (Arg2);
3602
3603 Id := Get_Pragma_Arg (Arg2);
3604 Analyze (Id);
3605
3606 if not Is_Entity_Name (Id) then
3607 Error_Pragma_Arg ("entity name required", Arg2);
3608 end if;
3609
3610 E := Entity (Id);
3611
3612 -- Set entity to return
3613
3614 Ent := E;
3615
3616 -- Ada_Pass_By_Copy special checking
3617
3618 if C = Convention_Ada_Pass_By_Copy then
3619 if not Is_First_Subtype (E) then
3620 Error_Pragma_Arg
3621 ("convention `Ada_Pass_By_Copy` only "
3622 & "allowed for types", Arg2);
3623 end if;
3624
3625 if Is_By_Reference_Type (E) then
3626 Error_Pragma_Arg
3627 ("convention `Ada_Pass_By_Copy` not allowed for "
3628 & "by-reference type", Arg1);
3629 end if;
3630 end if;
3631
3632 -- Ada_Pass_By_Reference special checking
3633
3634 if C = Convention_Ada_Pass_By_Reference then
3635 if not Is_First_Subtype (E) then
3636 Error_Pragma_Arg
3637 ("convention `Ada_Pass_By_Reference` only "
3638 & "allowed for types", Arg2);
3639 end if;
3640
3641 if Is_By_Copy_Type (E) then
3642 Error_Pragma_Arg
3643 ("convention `Ada_Pass_By_Reference` not allowed for "
3644 & "by-copy type", Arg1);
3645 end if;
3646 end if;
3647
3648 -- Go to renamed subprogram if present, since convention applies to
3649 -- the actual renamed entity, not to the renaming entity. If the
3650 -- subprogram is inherited, go to parent subprogram.
3651
3652 if Is_Subprogram (E)
3653 and then Present (Alias (E))
3654 then
3655 if Nkind (Parent (Declaration_Node (E))) =
3656 N_Subprogram_Renaming_Declaration
3657 then
3658 if Scope (E) /= Scope (Alias (E)) then
3659 Error_Pragma_Ref
3660 ("cannot apply pragma% to non-local entity&#", E);
3661 end if;
3662
3663 E := Alias (E);
3664
3665 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3666 N_Private_Extension_Declaration)
3667 and then Scope (E) = Scope (Alias (E))
3668 then
3669 E := Alias (E);
3670
3671 -- Return the parent subprogram the entity was inherited from
3672
3673 Ent := E;
3674 end if;
3675 end if;
3676
3677 -- Check that we are not applying this to a specless body
3678 -- Relax this check if Relaxed_RM_Semantics to accomodate other Ada
3679 -- compilers.
3680
3681 if Is_Subprogram (E)
3682 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3683 and then not Relaxed_RM_Semantics
3684 then
3685 Error_Pragma
3686 ("pragma% requires separate spec and must come before body");
3687 end if;
3688
3689 -- Check that we are not applying this to a named constant
3690
3691 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3692 Error_Msg_Name_1 := Pname;
3693 Error_Msg_N
3694 ("cannot apply pragma% to named constant!",
3695 Get_Pragma_Arg (Arg2));
3696 Error_Pragma_Arg
3697 ("\supply appropriate type for&!", Arg2);
3698 end if;
3699
3700 if Ekind (E) = E_Enumeration_Literal then
3701 Error_Pragma ("enumeration literal not allowed for pragma%");
3702 end if;
3703
3704 -- Check for rep item appearing too early or too late
3705
3706 if Etype (E) = Any_Type
3707 or else Rep_Item_Too_Early (E, N)
3708 then
3709 raise Pragma_Exit;
3710
3711 elsif Present (Underlying_Type (E)) then
3712 E := Underlying_Type (E);
3713 end if;
3714
3715 if Rep_Item_Too_Late (E, N) then
3716 raise Pragma_Exit;
3717 end if;
3718
3719 if Has_Convention_Pragma (E) then
3720 Diagnose_Multiple_Pragmas (E);
3721
3722 elsif Convention (E) = Convention_Protected
3723 or else Ekind (Scope (E)) = E_Protected_Type
3724 then
3725 Error_Pragma_Arg
3726 ("a protected operation cannot be given a different convention",
3727 Arg2);
3728 end if;
3729
3730 -- For Intrinsic, a subprogram is required
3731
3732 if C = Convention_Intrinsic
3733 and then not Is_Subprogram (E)
3734 and then not Is_Generic_Subprogram (E)
3735 then
3736 Error_Pragma_Arg
3737 ("second argument of pragma% must be a subprogram", Arg2);
3738 end if;
3739
3740 -- Stdcall case
3741
3742 if C = Convention_Stdcall then
3743
3744 -- A dispatching call is not allowed. A dispatching subprogram
3745 -- cannot be used to interface to the Win32 API, so in fact this
3746 -- check does not impose any effective restriction.
3747
3748 if Is_Dispatching_Operation (E) then
3749
3750 Error_Pragma
3751 ("dispatching subprograms cannot use Stdcall convention");
3752
3753 -- Subprogram is allowed, but not a generic subprogram, and not a
3754 -- dispatching operation.
3755
3756 elsif not Is_Subprogram (E)
3757 and then not Is_Generic_Subprogram (E)
3758
3759 -- A variable is OK
3760
3761 and then Ekind (E) /= E_Variable
3762
3763 -- An access to subprogram is also allowed
3764
3765 and then not
3766 (Is_Access_Type (E)
3767 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3768 then
3769 Error_Pragma_Arg
3770 ("second argument of pragma% must be subprogram (type)",
3771 Arg2);
3772 end if;
3773 end if;
3774
3775 if not Is_Subprogram (E)
3776 and then not Is_Generic_Subprogram (E)
3777 then
3778 Set_Convention_From_Pragma (E);
3779
3780 if Is_Type (E) then
3781 Check_First_Subtype (Arg2);
3782 Set_Convention_From_Pragma (Base_Type (E));
3783
3784 -- For subprograms, we must set the convention on the
3785 -- internally generated directly designated type as well.
3786
3787 if Ekind (E) = E_Access_Subprogram_Type then
3788 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3789 end if;
3790 end if;
3791
3792 -- For the subprogram case, set proper convention for all homonyms
3793 -- in same scope and the same declarative part, i.e. the same
3794 -- compilation unit.
3795
3796 else
3797 Comp_Unit := Get_Source_Unit (E);
3798 Set_Convention_From_Pragma (E);
3799
3800 -- Treat a pragma Import as an implicit body, and pragma import
3801 -- as implicit reference (for navigation in GPS).
3802
3803 if Prag_Id = Pragma_Import then
3804 Generate_Reference (E, Id, 'b');
3805
3806 -- For exported entities we restrict the generation of references
3807 -- to entities exported to foreign languages since entities
3808 -- exported to Ada do not provide further information to GPS and
3809 -- add undesired references to the output of the gnatxref tool.
3810
3811 elsif Prag_Id = Pragma_Export
3812 and then Convention (E) /= Convention_Ada
3813 then
3814 Generate_Reference (E, Id, 'i');
3815 end if;
3816
3817 -- If the pragma comes from from an aspect, it only applies
3818 -- to the given entity, not its homonyms.
3819
3820 if From_Aspect_Specification (N) then
3821 return;
3822 end if;
3823
3824 -- Otherwise Loop through the homonyms of the pragma argument's
3825 -- entity, an apply convention to those in the current scope.
3826
3827 E1 := Ent;
3828
3829 loop
3830 E1 := Homonym (E1);
3831 exit when No (E1) or else Scope (E1) /= Current_Scope;
3832
3833 -- Do not set the pragma on inherited operations or on formal
3834 -- subprograms.
3835
3836 if Comes_From_Source (E1)
3837 and then Comp_Unit = Get_Source_Unit (E1)
3838 and then not Is_Formal_Subprogram (E1)
3839 and then Nkind (Original_Node (Parent (E1))) /=
3840 N_Full_Type_Declaration
3841 then
3842 if Present (Alias (E1))
3843 and then Scope (E1) /= Scope (Alias (E1))
3844 then
3845 Error_Pragma_Ref
3846 ("cannot apply pragma% to non-local entity& declared#",
3847 E1);
3848 end if;
3849
3850 Set_Convention_From_Pragma (E1);
3851
3852 if Prag_Id = Pragma_Import then
3853 Generate_Reference (E1, Id, 'b');
3854 end if;
3855 end if;
3856 end loop;
3857 end if;
3858 end Process_Convention;
3859
3860 ----------------------------------------
3861 -- Process_Disable_Enable_Atomic_Sync --
3862 ----------------------------------------
3863
3864 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3865 begin
3866 GNAT_Pragma;
3867 Check_No_Identifiers;
3868 Check_At_Most_N_Arguments (1);
3869
3870 -- Modeled internally as
3871 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
3872
3873 Rewrite (N,
3874 Make_Pragma (Loc,
3875 Pragma_Identifier =>
3876 Make_Identifier (Loc, Nam),
3877 Pragma_Argument_Associations => New_List (
3878 Make_Pragma_Argument_Association (Loc,
3879 Expression =>
3880 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3881
3882 if Present (Arg1) then
3883 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3884 end if;
3885
3886 Analyze (N);
3887 end Process_Disable_Enable_Atomic_Sync;
3888
3889 -----------------------------------------------------
3890 -- Process_Extended_Import_Export_Exception_Pragma --
3891 -----------------------------------------------------
3892
3893 procedure Process_Extended_Import_Export_Exception_Pragma
3894 (Arg_Internal : Node_Id;
3895 Arg_External : Node_Id;
3896 Arg_Form : Node_Id;
3897 Arg_Code : Node_Id)
3898 is
3899 Def_Id : Entity_Id;
3900 Code_Val : Uint;
3901
3902 begin
3903 if not OpenVMS_On_Target then
3904 Error_Pragma
3905 ("??pragma% ignored (applies only to Open'V'M'S)");
3906 end if;
3907
3908 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3909 Def_Id := Entity (Arg_Internal);
3910
3911 if Ekind (Def_Id) /= E_Exception then
3912 Error_Pragma_Arg
3913 ("pragma% must refer to declared exception", Arg_Internal);
3914 end if;
3915
3916 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3917
3918 if Present (Arg_Form) then
3919 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3920 end if;
3921
3922 if Present (Arg_Form)
3923 and then Chars (Arg_Form) = Name_Ada
3924 then
3925 null;
3926 else
3927 Set_Is_VMS_Exception (Def_Id);
3928 Set_Exception_Code (Def_Id, No_Uint);
3929 end if;
3930
3931 if Present (Arg_Code) then
3932 if not Is_VMS_Exception (Def_Id) then
3933 Error_Pragma_Arg
3934 ("Code option for pragma% not allowed for Ada case",
3935 Arg_Code);
3936 end if;
3937
3938 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3939 Code_Val := Expr_Value (Arg_Code);
3940
3941 if not UI_Is_In_Int_Range (Code_Val) then
3942 Error_Pragma_Arg
3943 ("Code option for pragma% must be in 32-bit range",
3944 Arg_Code);
3945
3946 else
3947 Set_Exception_Code (Def_Id, Code_Val);
3948 end if;
3949 end if;
3950 end Process_Extended_Import_Export_Exception_Pragma;
3951
3952 -------------------------------------------------
3953 -- Process_Extended_Import_Export_Internal_Arg --
3954 -------------------------------------------------
3955
3956 procedure Process_Extended_Import_Export_Internal_Arg
3957 (Arg_Internal : Node_Id := Empty)
3958 is
3959 begin
3960 if No (Arg_Internal) then
3961 Error_Pragma ("Internal parameter required for pragma%");
3962 end if;
3963
3964 if Nkind (Arg_Internal) = N_Identifier then
3965 null;
3966
3967 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3968 and then (Prag_Id = Pragma_Import_Function
3969 or else
3970 Prag_Id = Pragma_Export_Function)
3971 then
3972 null;
3973
3974 else
3975 Error_Pragma_Arg
3976 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3977 end if;
3978
3979 Check_Arg_Is_Local_Name (Arg_Internal);
3980 end Process_Extended_Import_Export_Internal_Arg;
3981
3982 --------------------------------------------------
3983 -- Process_Extended_Import_Export_Object_Pragma --
3984 --------------------------------------------------
3985
3986 procedure Process_Extended_Import_Export_Object_Pragma
3987 (Arg_Internal : Node_Id;
3988 Arg_External : Node_Id;
3989 Arg_Size : Node_Id)
3990 is
3991 Def_Id : Entity_Id;
3992
3993 begin
3994 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3995 Def_Id := Entity (Arg_Internal);
3996
3997 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3998 Error_Pragma_Arg
3999 ("pragma% must designate an object", Arg_Internal);
4000 end if;
4001
4002 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
4003 or else
4004 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
4005 then
4006 Error_Pragma_Arg
4007 ("previous Common/Psect_Object applies, pragma % not permitted",
4008 Arg_Internal);
4009 end if;
4010
4011 if Rep_Item_Too_Late (Def_Id, N) then
4012 raise Pragma_Exit;
4013 end if;
4014
4015 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
4016
4017 if Present (Arg_Size) then
4018 Check_Arg_Is_External_Name (Arg_Size);
4019 end if;
4020
4021 -- Export_Object case
4022
4023 if Prag_Id = Pragma_Export_Object then
4024 if not Is_Library_Level_Entity (Def_Id) then
4025 Error_Pragma_Arg
4026 ("argument for pragma% must be library level entity",
4027 Arg_Internal);
4028 end if;
4029
4030 if Ekind (Current_Scope) = E_Generic_Package then
4031 Error_Pragma ("pragma& cannot appear in a generic unit");
4032 end if;
4033
4034 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
4035 Error_Pragma_Arg
4036 ("exported object must have compile time known size",
4037 Arg_Internal);
4038 end if;
4039
4040 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
4041 Error_Msg_N ("??duplicate Export_Object pragma", N);
4042 else
4043 Set_Exported (Def_Id, Arg_Internal);
4044 end if;
4045
4046 -- Import_Object case
4047
4048 else
4049 if Is_Concurrent_Type (Etype (Def_Id)) then
4050 Error_Pragma_Arg
4051 ("cannot use pragma% for task/protected object",
4052 Arg_Internal);
4053 end if;
4054
4055 if Ekind (Def_Id) = E_Constant then
4056 Error_Pragma_Arg
4057 ("cannot import a constant", Arg_Internal);
4058 end if;
4059
4060 if Warn_On_Export_Import
4061 and then Has_Discriminants (Etype (Def_Id))
4062 then
4063 Error_Msg_N
4064 ("imported value must be initialized??", Arg_Internal);
4065 end if;
4066
4067 if Warn_On_Export_Import
4068 and then Is_Access_Type (Etype (Def_Id))
4069 then
4070 Error_Pragma_Arg
4071 ("cannot import object of an access type??", Arg_Internal);
4072 end if;
4073
4074 if Warn_On_Export_Import
4075 and then Is_Imported (Def_Id)
4076 then
4077 Error_Msg_N ("??duplicate Import_Object pragma", N);
4078
4079 -- Check for explicit initialization present. Note that an
4080 -- initialization generated by the code generator, e.g. for an
4081 -- access type, does not count here.
4082
4083 elsif Present (Expression (Parent (Def_Id)))
4084 and then
4085 Comes_From_Source
4086 (Original_Node (Expression (Parent (Def_Id))))
4087 then
4088 Error_Msg_Sloc := Sloc (Def_Id);
4089 Error_Pragma_Arg
4090 ("imported entities cannot be initialized (RM B.1(24))",
4091 "\no initialization allowed for & declared#", Arg1);
4092 else
4093 Set_Imported (Def_Id);
4094 Note_Possible_Modification (Arg_Internal, Sure => False);
4095 end if;
4096 end if;
4097 end Process_Extended_Import_Export_Object_Pragma;
4098
4099 ------------------------------------------------------
4100 -- Process_Extended_Import_Export_Subprogram_Pragma --
4101 ------------------------------------------------------
4102
4103 procedure Process_Extended_Import_Export_Subprogram_Pragma
4104 (Arg_Internal : Node_Id;
4105 Arg_External : Node_Id;
4106 Arg_Parameter_Types : Node_Id;
4107 Arg_Result_Type : Node_Id := Empty;
4108 Arg_Mechanism : Node_Id;
4109 Arg_Result_Mechanism : Node_Id := Empty;
4110 Arg_First_Optional_Parameter : Node_Id := Empty)
4111 is
4112 Ent : Entity_Id;
4113 Def_Id : Entity_Id;
4114 Hom_Id : Entity_Id;
4115 Formal : Entity_Id;
4116 Ambiguous : Boolean;
4117 Match : Boolean;
4118 Dval : Node_Id;
4119
4120 function Same_Base_Type
4121 (Ptype : Node_Id;
4122 Formal : Entity_Id) return Boolean;
4123 -- Determines if Ptype references the type of Formal. Note that only
4124 -- the base types need to match according to the spec. Ptype here is
4125 -- the argument from the pragma, which is either a type name, or an
4126 -- access attribute.
4127
4128 --------------------
4129 -- Same_Base_Type --
4130 --------------------
4131
4132 function Same_Base_Type
4133 (Ptype : Node_Id;
4134 Formal : Entity_Id) return Boolean
4135 is
4136 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
4137 Pref : Node_Id;
4138
4139 begin
4140 -- Case where pragma argument is typ'Access
4141
4142 if Nkind (Ptype) = N_Attribute_Reference
4143 and then Attribute_Name (Ptype) = Name_Access
4144 then
4145 Pref := Prefix (Ptype);
4146 Find_Type (Pref);
4147
4148 if not Is_Entity_Name (Pref)
4149 or else Entity (Pref) = Any_Type
4150 then
4151 raise Pragma_Exit;
4152 end if;
4153
4154 -- We have a match if the corresponding argument is of an
4155 -- anonymous access type, and its designated type matches the
4156 -- type of the prefix of the access attribute
4157
4158 return Ekind (Ftyp) = E_Anonymous_Access_Type
4159 and then Base_Type (Entity (Pref)) =
4160 Base_Type (Etype (Designated_Type (Ftyp)));
4161
4162 -- Case where pragma argument is a type name
4163
4164 else
4165 Find_Type (Ptype);
4166
4167 if not Is_Entity_Name (Ptype)
4168 or else Entity (Ptype) = Any_Type
4169 then
4170 raise Pragma_Exit;
4171 end if;
4172
4173 -- We have a match if the corresponding argument is of the type
4174 -- given in the pragma (comparing base types)
4175
4176 return Base_Type (Entity (Ptype)) = Ftyp;
4177 end if;
4178 end Same_Base_Type;
4179
4180 -- Start of processing for
4181 -- Process_Extended_Import_Export_Subprogram_Pragma
4182
4183 begin
4184 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
4185 Ent := Empty;
4186 Ambiguous := False;
4187
4188 -- Loop through homonyms (overloadings) of the entity
4189
4190 Hom_Id := Entity (Arg_Internal);
4191 while Present (Hom_Id) loop
4192 Def_Id := Get_Base_Subprogram (Hom_Id);
4193
4194 -- We need a subprogram in the current scope
4195
4196 if not Is_Subprogram (Def_Id)
4197 or else Scope (Def_Id) /= Current_Scope
4198 then
4199 null;
4200
4201 else
4202 Match := True;
4203
4204 -- Pragma cannot apply to subprogram body
4205
4206 if Is_Subprogram (Def_Id)
4207 and then Nkind (Parent (Declaration_Node (Def_Id))) =
4208 N_Subprogram_Body
4209 then
4210 Error_Pragma
4211 ("pragma% requires separate spec"
4212 & " and must come before body");
4213 end if;
4214
4215 -- Test result type if given, note that the result type
4216 -- parameter can only be present for the function cases.
4217
4218 if Present (Arg_Result_Type)
4219 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
4220 then
4221 Match := False;
4222
4223 elsif Etype (Def_Id) /= Standard_Void_Type
4224 and then
4225 (Pname = Name_Export_Procedure
4226 or else
4227 Pname = Name_Import_Procedure)
4228 then
4229 Match := False;
4230
4231 -- Test parameter types if given. Note that this parameter
4232 -- has not been analyzed (and must not be, since it is
4233 -- semantic nonsense), so we get it as the parser left it.
4234
4235 elsif Present (Arg_Parameter_Types) then
4236 Check_Matching_Types : declare
4237 Formal : Entity_Id;
4238 Ptype : Node_Id;
4239
4240 begin
4241 Formal := First_Formal (Def_Id);
4242
4243 if Nkind (Arg_Parameter_Types) = N_Null then
4244 if Present (Formal) then
4245 Match := False;
4246 end if;
4247
4248 -- A list of one type, e.g. (List) is parsed as
4249 -- a parenthesized expression.
4250
4251 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4252 and then Paren_Count (Arg_Parameter_Types) = 1
4253 then
4254 if No (Formal)
4255 or else Present (Next_Formal (Formal))
4256 then
4257 Match := False;
4258 else
4259 Match :=
4260 Same_Base_Type (Arg_Parameter_Types, Formal);
4261 end if;
4262
4263 -- A list of more than one type is parsed as a aggregate
4264
4265 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4266 and then Paren_Count (Arg_Parameter_Types) = 0
4267 then
4268 Ptype := First (Expressions (Arg_Parameter_Types));
4269 while Present (Ptype) or else Present (Formal) loop
4270 if No (Ptype)
4271 or else No (Formal)
4272 or else not Same_Base_Type (Ptype, Formal)
4273 then
4274 Match := False;
4275 exit;
4276 else
4277 Next_Formal (Formal);
4278 Next (Ptype);
4279 end if;
4280 end loop;
4281
4282 -- Anything else is of the wrong form
4283
4284 else
4285 Error_Pragma_Arg
4286 ("wrong form for Parameter_Types parameter",
4287 Arg_Parameter_Types);
4288 end if;
4289 end Check_Matching_Types;
4290 end if;
4291
4292 -- Match is now False if the entry we found did not match
4293 -- either a supplied Parameter_Types or Result_Types argument
4294
4295 if Match then
4296 if No (Ent) then
4297 Ent := Def_Id;
4298
4299 -- Ambiguous case, the flag Ambiguous shows if we already
4300 -- detected this and output the initial messages.
4301
4302 else
4303 if not Ambiguous then
4304 Ambiguous := True;
4305 Error_Msg_Name_1 := Pname;
4306 Error_Msg_N
4307 ("pragma% does not uniquely identify subprogram!",
4308 N);
4309 Error_Msg_Sloc := Sloc (Ent);
4310 Error_Msg_N ("matching subprogram #!", N);
4311 Ent := Empty;
4312 end if;
4313
4314 Error_Msg_Sloc := Sloc (Def_Id);
4315 Error_Msg_N ("matching subprogram #!", N);
4316 end if;
4317 end if;
4318 end if;
4319
4320 Hom_Id := Homonym (Hom_Id);
4321 end loop;
4322
4323 -- See if we found an entry
4324
4325 if No (Ent) then
4326 if not Ambiguous then
4327 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4328 Error_Pragma
4329 ("pragma% cannot be given for generic subprogram");
4330 else
4331 Error_Pragma
4332 ("pragma% does not identify local subprogram");
4333 end if;
4334 end if;
4335
4336 return;
4337 end if;
4338
4339 -- Import pragmas must be for imported entities
4340
4341 if Prag_Id = Pragma_Import_Function
4342 or else
4343 Prag_Id = Pragma_Import_Procedure
4344 or else
4345 Prag_Id = Pragma_Import_Valued_Procedure
4346 then
4347 if not Is_Imported (Ent) then
4348 Error_Pragma
4349 ("pragma Import or Interface must precede pragma%");
4350 end if;
4351
4352 -- Here we have the Export case which can set the entity as exported
4353
4354 -- But does not do so if the specified external name is null, since
4355 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4356 -- compatible) to request no external name.
4357
4358 elsif Nkind (Arg_External) = N_String_Literal
4359 and then String_Length (Strval (Arg_External)) = 0
4360 then
4361 null;
4362
4363 -- In all other cases, set entity as exported
4364
4365 else
4366 Set_Exported (Ent, Arg_Internal);
4367 end if;
4368
4369 -- Special processing for Valued_Procedure cases
4370
4371 if Prag_Id = Pragma_Import_Valued_Procedure
4372 or else
4373 Prag_Id = Pragma_Export_Valued_Procedure
4374 then
4375 Formal := First_Formal (Ent);
4376
4377 if No (Formal) then
4378 Error_Pragma ("at least one parameter required for pragma%");
4379
4380 elsif Ekind (Formal) /= E_Out_Parameter then
4381 Error_Pragma ("first parameter must have mode out for pragma%");
4382
4383 else
4384 Set_Is_Valued_Procedure (Ent);
4385 end if;
4386 end if;
4387
4388 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4389
4390 -- Process Result_Mechanism argument if present. We have already
4391 -- checked that this is only allowed for the function case.
4392
4393 if Present (Arg_Result_Mechanism) then
4394 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4395 end if;
4396
4397 -- Process Mechanism parameter if present. Note that this parameter
4398 -- is not analyzed, and must not be analyzed since it is semantic
4399 -- nonsense, so we get it in exactly as the parser left it.
4400
4401 if Present (Arg_Mechanism) then
4402 declare
4403 Formal : Entity_Id;
4404 Massoc : Node_Id;
4405 Mname : Node_Id;
4406 Choice : Node_Id;
4407
4408 begin
4409 -- A single mechanism association without a formal parameter
4410 -- name is parsed as a parenthesized expression. All other
4411 -- cases are parsed as aggregates, so we rewrite the single
4412 -- parameter case as an aggregate for consistency.
4413
4414 if Nkind (Arg_Mechanism) /= N_Aggregate
4415 and then Paren_Count (Arg_Mechanism) = 1
4416 then
4417 Rewrite (Arg_Mechanism,
4418 Make_Aggregate (Sloc (Arg_Mechanism),
4419 Expressions => New_List (
4420 Relocate_Node (Arg_Mechanism))));
4421 end if;
4422
4423 -- Case of only mechanism name given, applies to all formals
4424
4425 if Nkind (Arg_Mechanism) /= N_Aggregate then
4426 Formal := First_Formal (Ent);
4427 while Present (Formal) loop
4428 Set_Mechanism_Value (Formal, Arg_Mechanism);
4429 Next_Formal (Formal);
4430 end loop;
4431
4432 -- Case of list of mechanism associations given
4433
4434 else
4435 if Null_Record_Present (Arg_Mechanism) then
4436 Error_Pragma_Arg
4437 ("inappropriate form for Mechanism parameter",
4438 Arg_Mechanism);
4439 end if;
4440
4441 -- Deal with positional ones first
4442
4443 Formal := First_Formal (Ent);
4444
4445 if Present (Expressions (Arg_Mechanism)) then
4446 Mname := First (Expressions (Arg_Mechanism));
4447 while Present (Mname) loop
4448 if No (Formal) then
4449 Error_Pragma_Arg
4450 ("too many mechanism associations", Mname);
4451 end if;
4452
4453 Set_Mechanism_Value (Formal, Mname);
4454 Next_Formal (Formal);
4455 Next (Mname);
4456 end loop;
4457 end if;
4458
4459 -- Deal with named entries
4460
4461 if Present (Component_Associations (Arg_Mechanism)) then
4462 Massoc := First (Component_Associations (Arg_Mechanism));
4463 while Present (Massoc) loop
4464 Choice := First (Choices (Massoc));
4465
4466 if Nkind (Choice) /= N_Identifier
4467 or else Present (Next (Choice))
4468 then
4469 Error_Pragma_Arg
4470 ("incorrect form for mechanism association",
4471 Massoc);
4472 end if;
4473
4474 Formal := First_Formal (Ent);
4475 loop
4476 if No (Formal) then
4477 Error_Pragma_Arg
4478 ("parameter name & not present", Choice);
4479 end if;
4480
4481 if Chars (Choice) = Chars (Formal) then
4482 Set_Mechanism_Value
4483 (Formal, Expression (Massoc));
4484
4485 -- Set entity on identifier (needed by ASIS)
4486
4487 Set_Entity (Choice, Formal);
4488
4489 exit;
4490 end if;
4491
4492 Next_Formal (Formal);
4493 end loop;
4494
4495 Next (Massoc);
4496 end loop;
4497 end if;
4498 end if;
4499 end;
4500 end if;
4501
4502 -- Process First_Optional_Parameter argument if present. We have
4503 -- already checked that this is only allowed for the Import case.
4504
4505 if Present (Arg_First_Optional_Parameter) then
4506 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4507 Error_Pragma_Arg
4508 ("first optional parameter must be formal parameter name",
4509 Arg_First_Optional_Parameter);
4510 end if;
4511
4512 Formal := First_Formal (Ent);
4513 loop
4514 if No (Formal) then
4515 Error_Pragma_Arg
4516 ("specified formal parameter& not found",
4517 Arg_First_Optional_Parameter);
4518 end if;
4519
4520 exit when Chars (Formal) =
4521 Chars (Arg_First_Optional_Parameter);
4522
4523 Next_Formal (Formal);
4524 end loop;
4525
4526 Set_First_Optional_Parameter (Ent, Formal);
4527
4528 -- Check specified and all remaining formals have right form
4529
4530 while Present (Formal) loop
4531 if Ekind (Formal) /= E_In_Parameter then
4532 Error_Msg_NE
4533 ("optional formal& is not of mode in!",
4534 Arg_First_Optional_Parameter, Formal);
4535
4536 else
4537 Dval := Default_Value (Formal);
4538
4539 if No (Dval) then
4540 Error_Msg_NE
4541 ("optional formal& does not have default value!",
4542 Arg_First_Optional_Parameter, Formal);
4543
4544 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4545 null;
4546
4547 else
4548 Error_Msg_FE
4549 ("default value for optional formal& is non-static!",
4550 Arg_First_Optional_Parameter, Formal);
4551 end if;
4552 end if;
4553
4554 Set_Is_Optional_Parameter (Formal);
4555 Next_Formal (Formal);
4556 end loop;
4557 end if;
4558 end Process_Extended_Import_Export_Subprogram_Pragma;
4559
4560 --------------------------
4561 -- Process_Generic_List --
4562 --------------------------
4563
4564 procedure Process_Generic_List is
4565 Arg : Node_Id;
4566 Exp : Node_Id;
4567
4568 begin
4569 Check_No_Identifiers;
4570 Check_At_Least_N_Arguments (1);
4571
4572 Arg := Arg1;
4573 while Present (Arg) loop
4574 Exp := Get_Pragma_Arg (Arg);
4575 Analyze (Exp);
4576
4577 if not Is_Entity_Name (Exp)
4578 or else
4579 (not Is_Generic_Instance (Entity (Exp))
4580 and then
4581 not Is_Generic_Unit (Entity (Exp)))
4582 then
4583 Error_Pragma_Arg
4584 ("pragma% argument must be name of generic unit/instance",
4585 Arg);
4586 end if;
4587
4588 Next (Arg);
4589 end loop;
4590 end Process_Generic_List;
4591
4592 ------------------------------------
4593 -- Process_Import_Predefined_Type --
4594 ------------------------------------
4595
4596 procedure Process_Import_Predefined_Type is
4597 Loc : constant Source_Ptr := Sloc (N);
4598 Elmt : Elmt_Id;
4599 Ftyp : Node_Id := Empty;
4600 Decl : Node_Id;
4601 Def : Node_Id;
4602 Nam : Name_Id;
4603
4604 begin
4605 String_To_Name_Buffer (Strval (Expression (Arg3)));
4606 Nam := Name_Find;
4607
4608 Elmt := First_Elmt (Predefined_Float_Types);
4609 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4610 Next_Elmt (Elmt);
4611 end loop;
4612
4613 Ftyp := Node (Elmt);
4614
4615 if Present (Ftyp) then
4616
4617 -- Don't build a derived type declaration, because predefined C
4618 -- types have no declaration anywhere, so cannot really be named.
4619 -- Instead build a full type declaration, starting with an
4620 -- appropriate type definition is built
4621
4622 if Is_Floating_Point_Type (Ftyp) then
4623 Def := Make_Floating_Point_Definition (Loc,
4624 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4625 Make_Real_Range_Specification (Loc,
4626 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4627 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4628
4629 -- Should never have a predefined type we cannot handle
4630
4631 else
4632 raise Program_Error;
4633 end if;
4634
4635 -- Build and insert a Full_Type_Declaration, which will be
4636 -- analyzed as soon as this list entry has been analyzed.
4637
4638 Decl := Make_Full_Type_Declaration (Loc,
4639 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4640 Type_Definition => Def);
4641
4642 Insert_After (N, Decl);
4643 Mark_Rewrite_Insertion (Decl);
4644
4645 else
4646 Error_Pragma_Arg ("no matching type found for pragma%",
4647 Arg2);
4648 end if;
4649 end Process_Import_Predefined_Type;
4650
4651 ---------------------------------
4652 -- Process_Import_Or_Interface --
4653 ---------------------------------
4654
4655 procedure Process_Import_Or_Interface is
4656 C : Convention_Id;
4657 Def_Id : Entity_Id;
4658 Hom_Id : Entity_Id;
4659
4660 begin
4661 Process_Convention (C, Def_Id);
4662 Kill_Size_Check_Code (Def_Id);
4663 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4664
4665 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4666
4667 -- We do not permit Import to apply to a renaming declaration
4668
4669 if Present (Renamed_Object (Def_Id)) then
4670 Error_Pragma_Arg
4671 ("pragma% not allowed for object renaming", Arg2);
4672
4673 -- User initialization is not allowed for imported object, but
4674 -- the object declaration may contain a default initialization,
4675 -- that will be discarded. Note that an explicit initialization
4676 -- only counts if it comes from source, otherwise it is simply
4677 -- the code generator making an implicit initialization explicit.
4678
4679 elsif Present (Expression (Parent (Def_Id)))
4680 and then Comes_From_Source (Expression (Parent (Def_Id)))
4681 then
4682 Error_Msg_Sloc := Sloc (Def_Id);
4683 Error_Pragma_Arg
4684 ("no initialization allowed for declaration of& #",
4685 "\imported entities cannot be initialized (RM B.1(24))",
4686 Arg2);
4687
4688 else
4689 Set_Imported (Def_Id);
4690 Process_Interface_Name (Def_Id, Arg3, Arg4);
4691
4692 -- Note that we do not set Is_Public here. That's because we
4693 -- only want to set it if there is no address clause, and we
4694 -- don't know that yet, so we delay that processing till
4695 -- freeze time.
4696
4697 -- pragma Import completes deferred constants
4698
4699 if Ekind (Def_Id) = E_Constant then
4700 Set_Has_Completion (Def_Id);
4701 end if;
4702
4703 -- It is not possible to import a constant of an unconstrained
4704 -- array type (e.g. string) because there is no simple way to
4705 -- write a meaningful subtype for it.
4706
4707 if Is_Array_Type (Etype (Def_Id))
4708 and then not Is_Constrained (Etype (Def_Id))
4709 then
4710 Error_Msg_NE
4711 ("imported constant& must have a constrained subtype",
4712 N, Def_Id);
4713 end if;
4714 end if;
4715
4716 elsif Is_Subprogram (Def_Id)
4717 or else Is_Generic_Subprogram (Def_Id)
4718 then
4719 -- If the name is overloaded, pragma applies to all of the denoted
4720 -- entities in the same declarative part, unless the pragma comes
4721 -- from an aspect specification.
4722
4723 Hom_Id := Def_Id;
4724 while Present (Hom_Id) loop
4725
4726 Def_Id := Get_Base_Subprogram (Hom_Id);
4727
4728 -- Ignore inherited subprograms because the pragma will apply
4729 -- to the parent operation, which is the one called.
4730
4731 if Is_Overloadable (Def_Id)
4732 and then Present (Alias (Def_Id))
4733 then
4734 null;
4735
4736 -- If it is not a subprogram, it must be in an outer scope and
4737 -- pragma does not apply.
4738
4739 elsif not Is_Subprogram (Def_Id)
4740 and then not Is_Generic_Subprogram (Def_Id)
4741 then
4742 null;
4743
4744 -- The pragma does not apply to primitives of interfaces
4745
4746 elsif Is_Dispatching_Operation (Def_Id)
4747 and then Present (Find_Dispatching_Type (Def_Id))
4748 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4749 then
4750 null;
4751
4752 -- Verify that the homonym is in the same declarative part (not
4753 -- just the same scope). If the pragma comes from an aspect
4754 -- specification we know that it is part of the declaration.
4755
4756 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4757 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4758 and then not From_Aspect_Specification (N)
4759 then
4760 exit;
4761
4762 else
4763 Set_Imported (Def_Id);
4764
4765 -- Reject an Import applied to an abstract subprogram
4766
4767 if Is_Subprogram (Def_Id)
4768 and then Is_Abstract_Subprogram (Def_Id)
4769 then
4770 Error_Msg_Sloc := Sloc (Def_Id);
4771 Error_Msg_NE
4772 ("cannot import abstract subprogram& declared#",
4773 Arg2, Def_Id);
4774 end if;
4775
4776 -- Special processing for Convention_Intrinsic
4777
4778 if C = Convention_Intrinsic then
4779
4780 -- Link_Name argument not allowed for intrinsic
4781
4782 Check_No_Link_Name;
4783
4784 Set_Is_Intrinsic_Subprogram (Def_Id);
4785
4786 -- If no external name is present, then check that this
4787 -- is a valid intrinsic subprogram. If an external name
4788 -- is present, then this is handled by the back end.
4789
4790 if No (Arg3) then
4791 Check_Intrinsic_Subprogram
4792 (Def_Id, Get_Pragma_Arg (Arg2));
4793 end if;
4794 end if;
4795
4796 -- All interfaced procedures need an external symbol created
4797 -- for them since they are always referenced from another
4798 -- object file.
4799
4800 Set_Is_Public (Def_Id);
4801
4802 -- Verify that the subprogram does not have a completion
4803 -- through a renaming declaration. For other completions the
4804 -- pragma appears as a too late representation.
4805
4806 declare
4807 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4808
4809 begin
4810 if Present (Decl)
4811 and then Nkind (Decl) = N_Subprogram_Declaration
4812 and then Present (Corresponding_Body (Decl))
4813 and then Nkind (Unit_Declaration_Node
4814 (Corresponding_Body (Decl))) =
4815 N_Subprogram_Renaming_Declaration
4816 then
4817 Error_Msg_Sloc := Sloc (Def_Id);
4818 Error_Msg_NE
4819 ("cannot import&, renaming already provided for "
4820 & "declaration #", N, Def_Id);
4821 end if;
4822 end;
4823
4824 Set_Has_Completion (Def_Id);
4825 Process_Interface_Name (Def_Id, Arg3, Arg4);
4826 end if;
4827
4828 if Is_Compilation_Unit (Hom_Id) then
4829
4830 -- Its possible homonyms are not affected by the pragma.
4831 -- Such homonyms might be present in the context of other
4832 -- units being compiled.
4833
4834 exit;
4835
4836 elsif From_Aspect_Specification (N) then
4837 exit;
4838
4839 else
4840 Hom_Id := Homonym (Hom_Id);
4841 end if;
4842 end loop;
4843
4844 -- When the convention is Java or CIL, we also allow Import to be
4845 -- given for packages, generic packages, exceptions, record
4846 -- components, and access to subprograms.
4847
4848 elsif (C = Convention_Java or else C = Convention_CIL)
4849 and then
4850 (Is_Package_Or_Generic_Package (Def_Id)
4851 or else Ekind (Def_Id) = E_Exception
4852 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4853 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4854 then
4855 Set_Imported (Def_Id);
4856 Set_Is_Public (Def_Id);
4857 Process_Interface_Name (Def_Id, Arg3, Arg4);
4858
4859 -- Import a CPP class
4860
4861 elsif C = Convention_CPP
4862 and then (Is_Record_Type (Def_Id)
4863 or else Ekind (Def_Id) = E_Incomplete_Type)
4864 then
4865 if Ekind (Def_Id) = E_Incomplete_Type then
4866 if Present (Full_View (Def_Id)) then
4867 Def_Id := Full_View (Def_Id);
4868
4869 else
4870 Error_Msg_N
4871 ("cannot import 'C'P'P type before full declaration seen",
4872 Get_Pragma_Arg (Arg2));
4873
4874 -- Although we have reported the error we decorate it as
4875 -- CPP_Class to avoid reporting spurious errors
4876
4877 Set_Is_CPP_Class (Def_Id);
4878 return;
4879 end if;
4880 end if;
4881
4882 -- Types treated as CPP classes must be declared limited (note:
4883 -- this used to be a warning but there is no real benefit to it
4884 -- since we did effectively intend to treat the type as limited
4885 -- anyway).
4886
4887 if not Is_Limited_Type (Def_Id) then
4888 Error_Msg_N
4889 ("imported 'C'P'P type must be limited",
4890 Get_Pragma_Arg (Arg2));
4891 end if;
4892
4893 if Etype (Def_Id) /= Def_Id
4894 and then not Is_CPP_Class (Root_Type (Def_Id))
4895 then
4896 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
4897 end if;
4898
4899 Set_Is_CPP_Class (Def_Id);
4900
4901 -- Imported CPP types must not have discriminants (because C++
4902 -- classes do not have discriminants).
4903
4904 if Has_Discriminants (Def_Id) then
4905 Error_Msg_N
4906 ("imported 'C'P'P type cannot have discriminants",
4907 First (Discriminant_Specifications
4908 (Declaration_Node (Def_Id))));
4909 end if;
4910
4911 -- Check that components of imported CPP types do not have default
4912 -- expressions. For private types this check is performed when the
4913 -- full view is analyzed (see Process_Full_View).
4914
4915 if not Is_Private_Type (Def_Id) then
4916 Check_CPP_Type_Has_No_Defaults (Def_Id);
4917 end if;
4918
4919 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4920 Check_No_Link_Name;
4921 Check_Arg_Count (3);
4922 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4923
4924 Process_Import_Predefined_Type;
4925
4926 else
4927 Error_Pragma_Arg
4928 ("second argument of pragma% must be object, subprogram "
4929 & "or incomplete type",
4930 Arg2);
4931 end if;
4932
4933 -- If this pragma applies to a compilation unit, then the unit, which
4934 -- is a subprogram, does not require (or allow) a body. We also do
4935 -- not need to elaborate imported procedures.
4936
4937 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4938 declare
4939 Cunit : constant Node_Id := Parent (Parent (N));
4940 begin
4941 Set_Body_Required (Cunit, False);
4942 end;
4943 end if;
4944 end Process_Import_Or_Interface;
4945
4946 --------------------
4947 -- Process_Inline --
4948 --------------------
4949
4950 procedure Process_Inline (Status : Inline_Status) is
4951 Assoc : Node_Id;
4952 Decl : Node_Id;
4953 Subp_Id : Node_Id;
4954 Subp : Entity_Id;
4955 Applies : Boolean;
4956
4957 Effective : Boolean := False;
4958 -- Set True if inline has some effect, i.e. if there is at least one
4959 -- subprogram set as inlined as a result of the use of the pragma.
4960
4961 procedure Make_Inline (Subp : Entity_Id);
4962 -- Subp is the defining unit name of the subprogram declaration. Set
4963 -- the flag, as well as the flag in the corresponding body, if there
4964 -- is one present.
4965
4966 procedure Set_Inline_Flags (Subp : Entity_Id);
4967 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4968 -- Has_Pragma_Inline_Always for the Inline_Always case.
4969
4970 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4971 -- Returns True if it can be determined at this stage that inlining
4972 -- is not possible, for example if the body is available and contains
4973 -- exception handlers, we prevent inlining, since otherwise we can
4974 -- get undefined symbols at link time. This function also emits a
4975 -- warning if front-end inlining is enabled and the pragma appears
4976 -- too late.
4977 --
4978 -- ??? is business with link symbols still valid, or does it relate
4979 -- to front end ZCX which is being phased out ???
4980
4981 ---------------------------
4982 -- Inlining_Not_Possible --
4983 ---------------------------
4984
4985 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4986 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4987 Stats : Node_Id;
4988
4989 begin
4990 if Nkind (Decl) = N_Subprogram_Body then
4991 Stats := Handled_Statement_Sequence (Decl);
4992 return Present (Exception_Handlers (Stats))
4993 or else Present (At_End_Proc (Stats));
4994
4995 elsif Nkind (Decl) = N_Subprogram_Declaration
4996 and then Present (Corresponding_Body (Decl))
4997 then
4998 if Front_End_Inlining
4999 and then Analyzed (Corresponding_Body (Decl))
5000 then
5001 Error_Msg_N ("pragma appears too late, ignored??", N);
5002 return True;
5003
5004 -- If the subprogram is a renaming as body, the body is just a
5005 -- call to the renamed subprogram, and inlining is trivially
5006 -- possible.
5007
5008 elsif
5009 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
5010 N_Subprogram_Renaming_Declaration
5011 then
5012 return False;
5013
5014 else
5015 Stats :=
5016 Handled_Statement_Sequence
5017 (Unit_Declaration_Node (Corresponding_Body (Decl)));
5018
5019 return
5020 Present (Exception_Handlers (Stats))
5021 or else Present (At_End_Proc (Stats));
5022 end if;
5023
5024 else
5025 -- If body is not available, assume the best, the check is
5026 -- performed again when compiling enclosing package bodies.
5027
5028 return False;
5029 end if;
5030 end Inlining_Not_Possible;
5031
5032 -----------------
5033 -- Make_Inline --
5034 -----------------
5035
5036 procedure Make_Inline (Subp : Entity_Id) is
5037 Kind : constant Entity_Kind := Ekind (Subp);
5038 Inner_Subp : Entity_Id := Subp;
5039
5040 begin
5041 -- Ignore if bad type, avoid cascaded error
5042
5043 if Etype (Subp) = Any_Type then
5044 Applies := True;
5045 return;
5046
5047 -- Ignore if all inlining is suppressed
5048
5049 elsif Suppress_All_Inlining then
5050 Applies := True;
5051 return;
5052
5053 -- If inlining is not possible, for now do not treat as an error
5054
5055 elsif Status /= Suppressed
5056 and then Inlining_Not_Possible (Subp)
5057 then
5058 Applies := True;
5059 return;
5060
5061 -- Here we have a candidate for inlining, but we must exclude
5062 -- derived operations. Otherwise we would end up trying to inline
5063 -- a phantom declaration, and the result would be to drag in a
5064 -- body which has no direct inlining associated with it. That
5065 -- would not only be inefficient but would also result in the
5066 -- backend doing cross-unit inlining in cases where it was
5067 -- definitely inappropriate to do so.
5068
5069 -- However, a simple Comes_From_Source test is insufficient, since
5070 -- we do want to allow inlining of generic instances which also do
5071 -- not come from source. We also need to recognize specs generated
5072 -- by the front-end for bodies that carry the pragma. Finally,
5073 -- predefined operators do not come from source but are not
5074 -- inlineable either.
5075
5076 elsif Is_Generic_Instance (Subp)
5077 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
5078 then
5079 null;
5080
5081 elsif not Comes_From_Source (Subp)
5082 and then Scope (Subp) /= Standard_Standard
5083 then
5084 Applies := True;
5085 return;
5086 end if;
5087
5088 -- The referenced entity must either be the enclosing entity, or
5089 -- an entity declared within the current open scope.
5090
5091 if Present (Scope (Subp))
5092 and then Scope (Subp) /= Current_Scope
5093 and then Subp /= Current_Scope
5094 then
5095 Error_Pragma_Arg
5096 ("argument of% must be entity in current scope", Assoc);
5097 return;
5098 end if;
5099
5100 -- Processing for procedure, operator or function. If subprogram
5101 -- is aliased (as for an instance) indicate that the renamed
5102 -- entity (if declared in the same unit) is inlined.
5103
5104 if Is_Subprogram (Subp) then
5105 Inner_Subp := Ultimate_Alias (Inner_Subp);
5106
5107 if In_Same_Source_Unit (Subp, Inner_Subp) then
5108 Set_Inline_Flags (Inner_Subp);
5109
5110 Decl := Parent (Parent (Inner_Subp));
5111
5112 if Nkind (Decl) = N_Subprogram_Declaration
5113 and then Present (Corresponding_Body (Decl))
5114 then
5115 Set_Inline_Flags (Corresponding_Body (Decl));
5116
5117 elsif Is_Generic_Instance (Subp) then
5118
5119 -- Indicate that the body needs to be created for
5120 -- inlining subsequent calls. The instantiation node
5121 -- follows the declaration of the wrapper package
5122 -- created for it.
5123
5124 if Scope (Subp) /= Standard_Standard
5125 and then
5126 Need_Subprogram_Instance_Body
5127 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
5128 Subp)
5129 then
5130 null;
5131 end if;
5132
5133 -- Inline is a program unit pragma (RM 10.1.5) and cannot
5134 -- appear in a formal part to apply to a formal subprogram.
5135 -- Do not apply check within an instance or a formal package
5136 -- the test will have been applied to the original generic.
5137
5138 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
5139 and then List_Containing (Decl) = List_Containing (N)
5140 and then not In_Instance
5141 then
5142 Error_Msg_N
5143 ("Inline cannot apply to a formal subprogram", N);
5144
5145 -- If Subp is a renaming, it is the renamed entity that
5146 -- will appear in any call, and be inlined. However, for
5147 -- ASIS uses it is convenient to indicate that the renaming
5148 -- itself is an inlined subprogram, so that some gnatcheck
5149 -- rules can be applied in the absence of expansion.
5150
5151 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
5152 Set_Inline_Flags (Subp);
5153 end if;
5154 end if;
5155
5156 Applies := True;
5157
5158 -- For a generic subprogram set flag as well, for use at the point
5159 -- of instantiation, to determine whether the body should be
5160 -- generated.
5161
5162 elsif Is_Generic_Subprogram (Subp) then
5163 Set_Inline_Flags (Subp);
5164 Applies := True;
5165
5166 -- Literals are by definition inlined
5167
5168 elsif Kind = E_Enumeration_Literal then
5169 null;
5170
5171 -- Anything else is an error
5172
5173 else
5174 Error_Pragma_Arg
5175 ("expect subprogram name for pragma%", Assoc);
5176 end if;
5177 end Make_Inline;
5178
5179 ----------------------
5180 -- Set_Inline_Flags --
5181 ----------------------
5182
5183 procedure Set_Inline_Flags (Subp : Entity_Id) is
5184 begin
5185 -- First set the Has_Pragma_XXX flags and issue the appropriate
5186 -- errors and warnings for suspicious combinations.
5187
5188 if Prag_Id = Pragma_No_Inline then
5189 if Has_Pragma_Inline_Always (Subp) then
5190 Error_Msg_N
5191 ("Inline_Always and No_Inline are mutually exclusive", N);
5192 elsif Has_Pragma_Inline (Subp) then
5193 Error_Msg_NE
5194 ("Inline and No_Inline both specified for& ??",
5195 N, Entity (Subp_Id));
5196 end if;
5197
5198 Set_Has_Pragma_No_Inline (Subp);
5199 else
5200 if Prag_Id = Pragma_Inline_Always then
5201 if Has_Pragma_No_Inline (Subp) then
5202 Error_Msg_N
5203 ("Inline_Always and No_Inline are mutually exclusive",
5204 N);
5205 end if;
5206
5207 Set_Has_Pragma_Inline_Always (Subp);
5208 else
5209 if Has_Pragma_No_Inline (Subp) then
5210 Error_Msg_NE
5211 ("Inline and No_Inline both specified for& ??",
5212 N, Entity (Subp_Id));
5213 end if;
5214 end if;
5215
5216 if not Has_Pragma_Inline (Subp) then
5217 Set_Has_Pragma_Inline (Subp);
5218 Effective := True;
5219 end if;
5220 end if;
5221
5222 -- Then adjust the Is_Inlined flag. It can never be set if the
5223 -- subprogram is subject to pragma No_Inline.
5224
5225 case Status is
5226 when Suppressed =>
5227 Set_Is_Inlined (Subp, False);
5228 when Disabled =>
5229 null;
5230 when Enabled =>
5231 if not Has_Pragma_No_Inline (Subp) then
5232 Set_Is_Inlined (Subp, True);
5233 end if;
5234 end case;
5235 end Set_Inline_Flags;
5236
5237 -- Start of processing for Process_Inline
5238
5239 begin
5240 Check_No_Identifiers;
5241 Check_At_Least_N_Arguments (1);
5242
5243 if Status = Enabled then
5244 Inline_Processing_Required := True;
5245 end if;
5246
5247 Assoc := Arg1;
5248 while Present (Assoc) loop
5249 Subp_Id := Get_Pragma_Arg (Assoc);
5250 Analyze (Subp_Id);
5251 Applies := False;
5252
5253 if Is_Entity_Name (Subp_Id) then
5254 Subp := Entity (Subp_Id);
5255
5256 if Subp = Any_Id then
5257
5258 -- If previous error, avoid cascaded errors
5259
5260 Check_Error_Detected;
5261 Applies := True;
5262 Effective := True;
5263
5264 else
5265 Make_Inline (Subp);
5266
5267 -- For the pragma case, climb homonym chain. This is
5268 -- what implements allowing the pragma in the renaming
5269 -- case, with the result applying to the ancestors, and
5270 -- also allows Inline to apply to all previous homonyms.
5271
5272 if not From_Aspect_Specification (N) then
5273 while Present (Homonym (Subp))
5274 and then Scope (Homonym (Subp)) = Current_Scope
5275 loop
5276 Make_Inline (Homonym (Subp));
5277 Subp := Homonym (Subp);
5278 end loop;
5279 end if;
5280 end if;
5281 end if;
5282
5283 if not Applies then
5284 Error_Pragma_Arg
5285 ("inappropriate argument for pragma%", Assoc);
5286
5287 elsif not Effective
5288 and then Warn_On_Redundant_Constructs
5289 and then not (Status = Suppressed or else Suppress_All_Inlining)
5290 then
5291 if Inlining_Not_Possible (Subp) then
5292 Error_Msg_NE
5293 ("pragma Inline for& is ignored?r?",
5294 N, Entity (Subp_Id));
5295 else
5296 Error_Msg_NE
5297 ("pragma Inline for& is redundant?r?",
5298 N, Entity (Subp_Id));
5299 end if;
5300 end if;
5301
5302 Next (Assoc);
5303 end loop;
5304 end Process_Inline;
5305
5306 ----------------------------
5307 -- Process_Interface_Name --
5308 ----------------------------
5309
5310 procedure Process_Interface_Name
5311 (Subprogram_Def : Entity_Id;
5312 Ext_Arg : Node_Id;
5313 Link_Arg : Node_Id)
5314 is
5315 Ext_Nam : Node_Id;
5316 Link_Nam : Node_Id;
5317 String_Val : String_Id;
5318
5319 procedure Check_Form_Of_Interface_Name
5320 (SN : Node_Id;
5321 Ext_Name_Case : Boolean);
5322 -- SN is a string literal node for an interface name. This routine
5323 -- performs some minimal checks that the name is reasonable. In
5324 -- particular that no spaces or other obviously incorrect characters
5325 -- appear. This is only a warning, since any characters are allowed.
5326 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
5327
5328 ----------------------------------
5329 -- Check_Form_Of_Interface_Name --
5330 ----------------------------------
5331
5332 procedure Check_Form_Of_Interface_Name
5333 (SN : Node_Id;
5334 Ext_Name_Case : Boolean)
5335 is
5336 S : constant String_Id := Strval (Expr_Value_S (SN));
5337 SL : constant Nat := String_Length (S);
5338 C : Char_Code;
5339
5340 begin
5341 if SL = 0 then
5342 Error_Msg_N ("interface name cannot be null string", SN);
5343 end if;
5344
5345 for J in 1 .. SL loop
5346 C := Get_String_Char (S, J);
5347
5348 -- Look for dubious character and issue unconditional warning.
5349 -- Definitely dubious if not in character range.
5350
5351 if not In_Character_Range (C)
5352
5353 -- For all cases except CLI target,
5354 -- commas, spaces and slashes are dubious (in CLI, we use
5355 -- commas and backslashes in external names to specify
5356 -- assembly version and public key, while slashes and spaces
5357 -- can be used in names to mark nested classes and
5358 -- valuetypes).
5359
5360 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5361 and then (Get_Character (C) = ','
5362 or else
5363 Get_Character (C) = '\'))
5364 or else (VM_Target /= CLI_Target
5365 and then (Get_Character (C) = ' '
5366 or else
5367 Get_Character (C) = '/'))
5368 then
5369 Error_Msg
5370 ("??interface name contains illegal character",
5371 Sloc (SN) + Source_Ptr (J));
5372 end if;
5373 end loop;
5374 end Check_Form_Of_Interface_Name;
5375
5376 -- Start of processing for Process_Interface_Name
5377
5378 begin
5379 if No (Link_Arg) then
5380 if No (Ext_Arg) then
5381 if VM_Target = CLI_Target
5382 and then Ekind (Subprogram_Def) = E_Package
5383 and then Nkind (Parent (Subprogram_Def)) =
5384 N_Package_Specification
5385 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5386 then
5387 Set_Interface_Name
5388 (Subprogram_Def,
5389 Interface_Name
5390 (Generic_Parent (Parent (Subprogram_Def))));
5391 end if;
5392
5393 return;
5394
5395 elsif Chars (Ext_Arg) = Name_Link_Name then
5396 Ext_Nam := Empty;
5397 Link_Nam := Expression (Ext_Arg);
5398
5399 else
5400 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5401 Ext_Nam := Expression (Ext_Arg);
5402 Link_Nam := Empty;
5403 end if;
5404
5405 else
5406 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5407 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5408 Ext_Nam := Expression (Ext_Arg);
5409 Link_Nam := Expression (Link_Arg);
5410 end if;
5411
5412 -- Check expressions for external name and link name are static
5413
5414 if Present (Ext_Nam) then
5415 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5416 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5417
5418 -- Verify that external name is not the name of a local entity,
5419 -- which would hide the imported one and could lead to run-time
5420 -- surprises. The problem can only arise for entities declared in
5421 -- a package body (otherwise the external name is fully qualified
5422 -- and will not conflict).
5423
5424 declare
5425 Nam : Name_Id;
5426 E : Entity_Id;
5427 Par : Node_Id;
5428
5429 begin
5430 if Prag_Id = Pragma_Import then
5431 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5432 Nam := Name_Find;
5433 E := Entity_Id (Get_Name_Table_Info (Nam));
5434
5435 if Nam /= Chars (Subprogram_Def)
5436 and then Present (E)
5437 and then not Is_Overloadable (E)
5438 and then Is_Immediately_Visible (E)
5439 and then not Is_Imported (E)
5440 and then Ekind (Scope (E)) = E_Package
5441 then
5442 Par := Parent (E);
5443 while Present (Par) loop
5444 if Nkind (Par) = N_Package_Body then
5445 Error_Msg_Sloc := Sloc (E);
5446 Error_Msg_NE
5447 ("imported entity is hidden by & declared#",
5448 Ext_Arg, E);
5449 exit;
5450 end if;
5451
5452 Par := Parent (Par);
5453 end loop;
5454 end if;
5455 end if;
5456 end;
5457 end if;
5458
5459 if Present (Link_Nam) then
5460 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5461 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5462 end if;
5463
5464 -- If there is no link name, just set the external name
5465
5466 if No (Link_Nam) then
5467 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5468
5469 -- For the Link_Name case, the given literal is preceded by an
5470 -- asterisk, which indicates to GCC that the given name should be
5471 -- taken literally, and in particular that no prepending of
5472 -- underlines should occur, even in systems where this is the
5473 -- normal default.
5474
5475 else
5476 Start_String;
5477
5478 if VM_Target = No_VM then
5479 Store_String_Char (Get_Char_Code ('*'));
5480 end if;
5481
5482 String_Val := Strval (Expr_Value_S (Link_Nam));
5483 Store_String_Chars (String_Val);
5484 Link_Nam :=
5485 Make_String_Literal (Sloc (Link_Nam),
5486 Strval => End_String);
5487 end if;
5488
5489 -- Set the interface name. If the entity is a generic instance, use
5490 -- its alias, which is the callable entity.
5491
5492 if Is_Generic_Instance (Subprogram_Def) then
5493 Set_Encoded_Interface_Name
5494 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5495 else
5496 Set_Encoded_Interface_Name
5497 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5498 end if;
5499
5500 -- We allow duplicated export names in CIL/Java, as they are always
5501 -- enclosed in a namespace that differentiates them, and overloaded
5502 -- entities are supported by the VM.
5503
5504 if Convention (Subprogram_Def) /= Convention_CIL
5505 and then
5506 Convention (Subprogram_Def) /= Convention_Java
5507 then
5508 Check_Duplicated_Export_Name (Link_Nam);
5509 end if;
5510 end Process_Interface_Name;
5511
5512 -----------------------------------------
5513 -- Process_Interrupt_Or_Attach_Handler --
5514 -----------------------------------------
5515
5516 procedure Process_Interrupt_Or_Attach_Handler is
5517 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5518 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5519 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5520
5521 begin
5522 Set_Is_Interrupt_Handler (Handler_Proc);
5523
5524 -- If the pragma is not associated with a handler procedure within a
5525 -- protected type, then it must be for a nonprotected procedure for
5526 -- the AAMP target, in which case we don't associate a representation
5527 -- item with the procedure's scope.
5528
5529 if Ekind (Proc_Scope) = E_Protected_Type then
5530 if Prag_Id = Pragma_Interrupt_Handler
5531 or else
5532 Prag_Id = Pragma_Attach_Handler
5533 then
5534 Record_Rep_Item (Proc_Scope, N);
5535 end if;
5536 end if;
5537 end Process_Interrupt_Or_Attach_Handler;
5538
5539 --------------------------------------------------
5540 -- Process_Restrictions_Or_Restriction_Warnings --
5541 --------------------------------------------------
5542
5543 -- Note: some of the simple identifier cases were handled in par-prag,
5544 -- but it is harmless (and more straightforward) to simply handle all
5545 -- cases here, even if it means we repeat a bit of work in some cases.
5546
5547 procedure Process_Restrictions_Or_Restriction_Warnings
5548 (Warn : Boolean)
5549 is
5550 Arg : Node_Id;
5551 R_Id : Restriction_Id;
5552 Id : Name_Id;
5553 Expr : Node_Id;
5554 Val : Uint;
5555
5556 procedure Check_Unit_Name (N : Node_Id);
5557 -- Checks unit name parameter for No_Dependence. Returns if it has
5558 -- an appropriate form, otherwise raises pragma argument error.
5559
5560 ---------------------
5561 -- Check_Unit_Name --
5562 ---------------------
5563
5564 procedure Check_Unit_Name (N : Node_Id) is
5565 begin
5566 if Nkind (N) = N_Selected_Component then
5567 Check_Unit_Name (Prefix (N));
5568 Check_Unit_Name (Selector_Name (N));
5569
5570 elsif Nkind (N) = N_Identifier then
5571 return;
5572
5573 else
5574 Error_Pragma_Arg
5575 ("wrong form for unit name for No_Dependence", N);
5576 end if;
5577 end Check_Unit_Name;
5578
5579 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5580
5581 begin
5582 -- Ignore all Restrictions pragma in CodePeer mode
5583
5584 if CodePeer_Mode then
5585 return;
5586 end if;
5587
5588 Check_Ada_83_Warning;
5589 Check_At_Least_N_Arguments (1);
5590 Check_Valid_Configuration_Pragma;
5591
5592 Arg := Arg1;
5593 while Present (Arg) loop
5594 Id := Chars (Arg);
5595 Expr := Get_Pragma_Arg (Arg);
5596
5597 -- Case of no restriction identifier present
5598
5599 if Id = No_Name then
5600 if Nkind (Expr) /= N_Identifier then
5601 Error_Pragma_Arg
5602 ("invalid form for restriction", Arg);
5603 end if;
5604
5605 R_Id :=
5606 Get_Restriction_Id
5607 (Process_Restriction_Synonyms (Expr));
5608
5609 if R_Id not in All_Boolean_Restrictions then
5610 Error_Msg_Name_1 := Pname;
5611 Error_Msg_N
5612 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5613
5614 -- Check for possible misspelling
5615
5616 for J in Restriction_Id loop
5617 declare
5618 Rnm : constant String := Restriction_Id'Image (J);
5619
5620 begin
5621 Name_Buffer (1 .. Rnm'Length) := Rnm;
5622 Name_Len := Rnm'Length;
5623 Set_Casing (All_Lower_Case);
5624
5625 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5626 Set_Casing
5627 (Identifier_Casing (Current_Source_File));
5628 Error_Msg_String (1 .. Rnm'Length) :=
5629 Name_Buffer (1 .. Name_Len);
5630 Error_Msg_Strlen := Rnm'Length;
5631 Error_Msg_N -- CODEFIX
5632 ("\possible misspelling of ""~""",
5633 Get_Pragma_Arg (Arg));
5634 exit;
5635 end if;
5636 end;
5637 end loop;
5638
5639 raise Pragma_Exit;
5640 end if;
5641
5642 if Implementation_Restriction (R_Id) then
5643 Check_Restriction (No_Implementation_Restrictions, Arg);
5644 end if;
5645
5646 -- Special processing for No_Elaboration_Code restriction
5647
5648 if R_Id = No_Elaboration_Code then
5649
5650 -- Restriction is only recognized within a configuration
5651 -- pragma file, or within a unit of the main extended
5652 -- program. Note: the test for Main_Unit is needed to
5653 -- properly include the case of configuration pragma files.
5654
5655 if not (Current_Sem_Unit = Main_Unit
5656 or else In_Extended_Main_Source_Unit (N))
5657 then
5658 return;
5659
5660 -- Don't allow in a subunit unless already specified in
5661 -- body or spec.
5662
5663 elsif Nkind (Parent (N)) = N_Compilation_Unit
5664 and then Nkind (Unit (Parent (N))) = N_Subunit
5665 and then not Restriction_Active (No_Elaboration_Code)
5666 then
5667 Error_Msg_N
5668 ("invalid specification of ""No_Elaboration_Code""",
5669 N);
5670 Error_Msg_N
5671 ("\restriction cannot be specified in a subunit", N);
5672 Error_Msg_N
5673 ("\unless also specified in body or spec", N);
5674 return;
5675
5676 -- If we have a No_Elaboration_Code pragma that we
5677 -- accept, then it needs to be added to the configuration
5678 -- restrcition set so that we get proper application to
5679 -- other units in the main extended source as required.
5680
5681 else
5682 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
5683 end if;
5684 end if;
5685
5686 -- If this is a warning, then set the warning unless we already
5687 -- have a real restriction active (we never want a warning to
5688 -- override a real restriction).
5689
5690 if Warn then
5691 if not Restriction_Active (R_Id) then
5692 Set_Restriction (R_Id, N);
5693 Restriction_Warnings (R_Id) := True;
5694 end if;
5695
5696 -- If real restriction case, then set it and make sure that the
5697 -- restriction warning flag is off, since a real restriction
5698 -- always overrides a warning.
5699
5700 else
5701 Set_Restriction (R_Id, N);
5702 Restriction_Warnings (R_Id) := False;
5703 end if;
5704
5705 -- Check for obsolescent restrictions in Ada 2005 mode
5706
5707 if not Warn
5708 and then Ada_Version >= Ada_2005
5709 and then (R_Id = No_Asynchronous_Control
5710 or else
5711 R_Id = No_Unchecked_Deallocation
5712 or else
5713 R_Id = No_Unchecked_Conversion)
5714 then
5715 Check_Restriction (No_Obsolescent_Features, N);
5716 end if;
5717
5718 -- A very special case that must be processed here: pragma
5719 -- Restrictions (No_Exceptions) turns off all run-time
5720 -- checking. This is a bit dubious in terms of the formal
5721 -- language definition, but it is what is intended by RM
5722 -- H.4(12). Restriction_Warnings never affects generated code
5723 -- so this is done only in the real restriction case.
5724
5725 -- Atomic_Synchronization is not a real check, so it is not
5726 -- affected by this processing).
5727
5728 if R_Id = No_Exceptions and then not Warn then
5729 for J in Scope_Suppress.Suppress'Range loop
5730 if J /= Atomic_Synchronization then
5731 Scope_Suppress.Suppress (J) := True;
5732 end if;
5733 end loop;
5734 end if;
5735
5736 -- Case of No_Dependence => unit-name. Note that the parser
5737 -- already made the necessary entry in the No_Dependence table.
5738
5739 elsif Id = Name_No_Dependence then
5740 Check_Unit_Name (Expr);
5741
5742 -- Case of No_Specification_Of_Aspect => Identifier.
5743
5744 elsif Id = Name_No_Specification_Of_Aspect then
5745 declare
5746 A_Id : Aspect_Id;
5747
5748 begin
5749 if Nkind (Expr) /= N_Identifier then
5750 A_Id := No_Aspect;
5751 else
5752 A_Id := Get_Aspect_Id (Chars (Expr));
5753 end if;
5754
5755 if A_Id = No_Aspect then
5756 Error_Pragma_Arg ("invalid restriction name", Arg);
5757 else
5758 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5759 end if;
5760 end;
5761
5762 -- All other cases of restriction identifier present
5763
5764 else
5765 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5766 Analyze_And_Resolve (Expr, Any_Integer);
5767
5768 if R_Id not in All_Parameter_Restrictions then
5769 Error_Pragma_Arg
5770 ("invalid restriction parameter identifier", Arg);
5771
5772 elsif not Is_OK_Static_Expression (Expr) then
5773 Flag_Non_Static_Expr
5774 ("value must be static expression!", Expr);
5775 raise Pragma_Exit;
5776
5777 elsif not Is_Integer_Type (Etype (Expr))
5778 or else Expr_Value (Expr) < 0
5779 then
5780 Error_Pragma_Arg
5781 ("value must be non-negative integer", Arg);
5782 end if;
5783
5784 -- Restriction pragma is active
5785
5786 Val := Expr_Value (Expr);
5787
5788 if not UI_Is_In_Int_Range (Val) then
5789 Error_Pragma_Arg
5790 ("pragma ignored, value too large??", Arg);
5791 end if;
5792
5793 -- Warning case. If the real restriction is active, then we
5794 -- ignore the request, since warning never overrides a real
5795 -- restriction. Otherwise we set the proper warning. Note that
5796 -- this circuit sets the warning again if it is already set,
5797 -- which is what we want, since the constant may have changed.
5798
5799 if Warn then
5800 if not Restriction_Active (R_Id) then
5801 Set_Restriction
5802 (R_Id, N, Integer (UI_To_Int (Val)));
5803 Restriction_Warnings (R_Id) := True;
5804 end if;
5805
5806 -- Real restriction case, set restriction and make sure warning
5807 -- flag is off since real restriction always overrides warning.
5808
5809 else
5810 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5811 Restriction_Warnings (R_Id) := False;
5812 end if;
5813 end if;
5814
5815 Next (Arg);
5816 end loop;
5817 end Process_Restrictions_Or_Restriction_Warnings;
5818
5819 ---------------------------------
5820 -- Process_Suppress_Unsuppress --
5821 ---------------------------------
5822
5823 -- Note: this procedure makes entries in the check suppress data
5824 -- structures managed by Sem. See spec of package Sem for full
5825 -- details on how we handle recording of check suppression.
5826
5827 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5828 C : Check_Id;
5829 E_Id : Node_Id;
5830 E : Entity_Id;
5831
5832 In_Package_Spec : constant Boolean :=
5833 Is_Package_Or_Generic_Package (Current_Scope)
5834 and then not In_Package_Body (Current_Scope);
5835
5836 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5837 -- Used to suppress a single check on the given entity
5838
5839 --------------------------------
5840 -- Suppress_Unsuppress_Echeck --
5841 --------------------------------
5842
5843 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5844 begin
5845 -- Check for error of trying to set atomic synchronization for
5846 -- a non-atomic variable.
5847
5848 if C = Atomic_Synchronization
5849 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5850 then
5851 Error_Msg_N
5852 ("pragma & requires atomic type or variable",
5853 Pragma_Identifier (Original_Node (N)));
5854 end if;
5855
5856 Set_Checks_May_Be_Suppressed (E);
5857
5858 if In_Package_Spec then
5859 Push_Global_Suppress_Stack_Entry
5860 (Entity => E,
5861 Check => C,
5862 Suppress => Suppress_Case);
5863 else
5864 Push_Local_Suppress_Stack_Entry
5865 (Entity => E,
5866 Check => C,
5867 Suppress => Suppress_Case);
5868 end if;
5869
5870 -- If this is a first subtype, and the base type is distinct,
5871 -- then also set the suppress flags on the base type.
5872
5873 if Is_First_Subtype (E) and then Etype (E) /= E then
5874 Suppress_Unsuppress_Echeck (Etype (E), C);
5875 end if;
5876 end Suppress_Unsuppress_Echeck;
5877
5878 -- Start of processing for Process_Suppress_Unsuppress
5879
5880 begin
5881 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5882 -- user code: we want to generate checks for analysis purposes, as
5883 -- set respectively by -gnatC and -gnatd.F
5884
5885 if (CodePeer_Mode or Alfa_Mode) and then Comes_From_Source (N) then
5886 return;
5887 end if;
5888
5889 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5890 -- declarative part or a package spec (RM 11.5(5)).
5891
5892 if not Is_Configuration_Pragma then
5893 Check_Is_In_Decl_Part_Or_Package_Spec;
5894 end if;
5895
5896 Check_At_Least_N_Arguments (1);
5897 Check_At_Most_N_Arguments (2);
5898 Check_No_Identifier (Arg1);
5899 Check_Arg_Is_Identifier (Arg1);
5900
5901 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5902
5903 if C = No_Check_Id then
5904 Error_Pragma_Arg
5905 ("argument of pragma% is not valid check name", Arg1);
5906 end if;
5907
5908 if Arg_Count = 1 then
5909
5910 -- Make an entry in the local scope suppress table. This is the
5911 -- table that directly shows the current value of the scope
5912 -- suppress check for any check id value.
5913
5914 if C = All_Checks then
5915
5916 -- For All_Checks, we set all specific predefined checks with
5917 -- the exception of Elaboration_Check, which is handled
5918 -- specially because of not wanting All_Checks to have the
5919 -- effect of deactivating static elaboration order processing.
5920 -- Atomic_Synchronization is also not affected, since this is
5921 -- not a real check.
5922
5923 for J in Scope_Suppress.Suppress'Range loop
5924 if J /= Elaboration_Check
5925 and then
5926 J /= Atomic_Synchronization
5927 then
5928 Scope_Suppress.Suppress (J) := Suppress_Case;
5929 end if;
5930 end loop;
5931
5932 -- If not All_Checks, and predefined check, then set appropriate
5933 -- scope entry. Note that we will set Elaboration_Check if this
5934 -- is explicitly specified. Atomic_Synchronization is allowed
5935 -- only if internally generated and entity is atomic.
5936
5937 elsif C in Predefined_Check_Id
5938 and then (not Comes_From_Source (N)
5939 or else C /= Atomic_Synchronization)
5940 then
5941 Scope_Suppress.Suppress (C) := Suppress_Case;
5942 end if;
5943
5944 -- Also make an entry in the Local_Entity_Suppress table
5945
5946 Push_Local_Suppress_Stack_Entry
5947 (Entity => Empty,
5948 Check => C,
5949 Suppress => Suppress_Case);
5950
5951 -- Case of two arguments present, where the check is suppressed for
5952 -- a specified entity (given as the second argument of the pragma)
5953
5954 else
5955 -- This is obsolescent in Ada 2005 mode
5956
5957 if Ada_Version >= Ada_2005 then
5958 Check_Restriction (No_Obsolescent_Features, Arg2);
5959 end if;
5960
5961 Check_Optional_Identifier (Arg2, Name_On);
5962 E_Id := Get_Pragma_Arg (Arg2);
5963 Analyze (E_Id);
5964
5965 if not Is_Entity_Name (E_Id) then
5966 Error_Pragma_Arg
5967 ("second argument of pragma% must be entity name", Arg2);
5968 end if;
5969
5970 E := Entity (E_Id);
5971
5972 if E = Any_Id then
5973 return;
5974 end if;
5975
5976 -- Enforce RM 11.5(7) which requires that for a pragma that
5977 -- appears within a package spec, the named entity must be
5978 -- within the package spec. We allow the package name itself
5979 -- to be mentioned since that makes sense, although it is not
5980 -- strictly allowed by 11.5(7).
5981
5982 if In_Package_Spec
5983 and then E /= Current_Scope
5984 and then Scope (E) /= Current_Scope
5985 then
5986 Error_Pragma_Arg
5987 ("entity in pragma% is not in package spec (RM 11.5(7))",
5988 Arg2);
5989 end if;
5990
5991 -- Loop through homonyms. As noted below, in the case of a package
5992 -- spec, only homonyms within the package spec are considered.
5993
5994 loop
5995 Suppress_Unsuppress_Echeck (E, C);
5996
5997 if Is_Generic_Instance (E)
5998 and then Is_Subprogram (E)
5999 and then Present (Alias (E))
6000 then
6001 Suppress_Unsuppress_Echeck (Alias (E), C);
6002 end if;
6003
6004 -- Move to next homonym if not aspect spec case
6005
6006 exit when From_Aspect_Specification (N);
6007 E := Homonym (E);
6008 exit when No (E);
6009
6010 -- If we are within a package specification, the pragma only
6011 -- applies to homonyms in the same scope.
6012
6013 exit when In_Package_Spec
6014 and then Scope (E) /= Current_Scope;
6015 end loop;
6016 end if;
6017 end Process_Suppress_Unsuppress;
6018
6019 ------------------
6020 -- Set_Exported --
6021 ------------------
6022
6023 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
6024 begin
6025 if Is_Imported (E) then
6026 Error_Pragma_Arg
6027 ("cannot export entity& that was previously imported", Arg);
6028
6029 elsif Present (Address_Clause (E))
6030 and then not Relaxed_RM_Semantics
6031 then
6032 Error_Pragma_Arg
6033 ("cannot export entity& that has an address clause", Arg);
6034 end if;
6035
6036 Set_Is_Exported (E);
6037
6038 -- Generate a reference for entity explicitly, because the
6039 -- identifier may be overloaded and name resolution will not
6040 -- generate one.
6041
6042 Generate_Reference (E, Arg);
6043
6044 -- Deal with exporting non-library level entity
6045
6046 if not Is_Library_Level_Entity (E) then
6047
6048 -- Not allowed at all for subprograms
6049
6050 if Is_Subprogram (E) then
6051 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
6052
6053 -- Otherwise set public and statically allocated
6054
6055 else
6056 Set_Is_Public (E);
6057 Set_Is_Statically_Allocated (E);
6058
6059 -- Warn if the corresponding W flag is set and the pragma comes
6060 -- from source. The latter may not be true e.g. on VMS where we
6061 -- expand export pragmas for exception codes associated with
6062 -- imported or exported exceptions. We do not want to generate
6063 -- a warning for something that the user did not write.
6064
6065 if Warn_On_Export_Import
6066 and then Comes_From_Source (Arg)
6067 then
6068 Error_Msg_NE
6069 ("?x?& has been made static as a result of Export",
6070 Arg, E);
6071 Error_Msg_N
6072 ("\?x?this usage is non-standard and non-portable",
6073 Arg);
6074 end if;
6075 end if;
6076 end if;
6077
6078 if Warn_On_Export_Import and then Is_Type (E) then
6079 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
6080 end if;
6081
6082 if Warn_On_Export_Import and Inside_A_Generic then
6083 Error_Msg_NE
6084 ("all instances of& will have the same external name?x?",
6085 Arg, E);
6086 end if;
6087 end Set_Exported;
6088
6089 ----------------------------------------------
6090 -- Set_Extended_Import_Export_External_Name --
6091 ----------------------------------------------
6092
6093 procedure Set_Extended_Import_Export_External_Name
6094 (Internal_Ent : Entity_Id;
6095 Arg_External : Node_Id)
6096 is
6097 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
6098 New_Name : Node_Id;
6099
6100 begin
6101 if No (Arg_External) then
6102 return;
6103 end if;
6104
6105 Check_Arg_Is_External_Name (Arg_External);
6106
6107 if Nkind (Arg_External) = N_String_Literal then
6108 if String_Length (Strval (Arg_External)) = 0 then
6109 return;
6110 else
6111 New_Name := Adjust_External_Name_Case (Arg_External);
6112 end if;
6113
6114 elsif Nkind (Arg_External) = N_Identifier then
6115 New_Name := Get_Default_External_Name (Arg_External);
6116
6117 -- Check_Arg_Is_External_Name should let through only identifiers and
6118 -- string literals or static string expressions (which are folded to
6119 -- string literals).
6120
6121 else
6122 raise Program_Error;
6123 end if;
6124
6125 -- If we already have an external name set (by a prior normal Import
6126 -- or Export pragma), then the external names must match
6127
6128 if Present (Interface_Name (Internal_Ent)) then
6129 Check_Matching_Internal_Names : declare
6130 S1 : constant String_Id := Strval (Old_Name);
6131 S2 : constant String_Id := Strval (New_Name);
6132
6133 procedure Mismatch;
6134 pragma No_Return (Mismatch);
6135 -- Called if names do not match
6136
6137 --------------
6138 -- Mismatch --
6139 --------------
6140
6141 procedure Mismatch is
6142 begin
6143 Error_Msg_Sloc := Sloc (Old_Name);
6144 Error_Pragma_Arg
6145 ("external name does not match that given #",
6146 Arg_External);
6147 end Mismatch;
6148
6149 -- Start of processing for Check_Matching_Internal_Names
6150
6151 begin
6152 if String_Length (S1) /= String_Length (S2) then
6153 Mismatch;
6154
6155 else
6156 for J in 1 .. String_Length (S1) loop
6157 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
6158 Mismatch;
6159 end if;
6160 end loop;
6161 end if;
6162 end Check_Matching_Internal_Names;
6163
6164 -- Otherwise set the given name
6165
6166 else
6167 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
6168 Check_Duplicated_Export_Name (New_Name);
6169 end if;
6170 end Set_Extended_Import_Export_External_Name;
6171
6172 ------------------
6173 -- Set_Imported --
6174 ------------------
6175
6176 procedure Set_Imported (E : Entity_Id) is
6177 begin
6178 -- Error message if already imported or exported
6179
6180 if Is_Exported (E) or else Is_Imported (E) then
6181
6182 -- Error if being set Exported twice
6183
6184 if Is_Exported (E) then
6185 Error_Msg_NE ("entity& was previously exported", N, E);
6186
6187 -- OK if Import/Interface case
6188
6189 elsif Import_Interface_Present (N) then
6190 goto OK;
6191
6192 -- Error if being set Imported twice
6193
6194 else
6195 Error_Msg_NE ("entity& was previously imported", N, E);
6196 end if;
6197
6198 Error_Msg_Name_1 := Pname;
6199 Error_Msg_N
6200 ("\(pragma% applies to all previous entities)", N);
6201
6202 Error_Msg_Sloc := Sloc (E);
6203 Error_Msg_NE ("\import not allowed for& declared#", N, E);
6204
6205 -- Here if not previously imported or exported, OK to import
6206
6207 else
6208 Set_Is_Imported (E);
6209
6210 -- If the entity is an object that is not at the library level,
6211 -- then it is statically allocated. We do not worry about objects
6212 -- with address clauses in this context since they are not really
6213 -- imported in the linker sense.
6214
6215 if Is_Object (E)
6216 and then not Is_Library_Level_Entity (E)
6217 and then No (Address_Clause (E))
6218 then
6219 Set_Is_Statically_Allocated (E);
6220 end if;
6221 end if;
6222
6223 <<OK>> null;
6224 end Set_Imported;
6225
6226 -------------------------
6227 -- Set_Mechanism_Value --
6228 -------------------------
6229
6230 -- Note: the mechanism name has not been analyzed (and cannot indeed be
6231 -- analyzed, since it is semantic nonsense), so we get it in the exact
6232 -- form created by the parser.
6233
6234 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
6235 Class : Node_Id;
6236 Param : Node_Id;
6237 Mech_Name_Id : Name_Id;
6238
6239 procedure Bad_Class;
6240 pragma No_Return (Bad_Class);
6241 -- Signal bad descriptor class name
6242
6243 procedure Bad_Mechanism;
6244 pragma No_Return (Bad_Mechanism);
6245 -- Signal bad mechanism name
6246
6247 ---------------
6248 -- Bad_Class --
6249 ---------------
6250
6251 procedure Bad_Class is
6252 begin
6253 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
6254 end Bad_Class;
6255
6256 -------------------------
6257 -- Bad_Mechanism_Value --
6258 -------------------------
6259
6260 procedure Bad_Mechanism is
6261 begin
6262 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
6263 end Bad_Mechanism;
6264
6265 -- Start of processing for Set_Mechanism_Value
6266
6267 begin
6268 if Mechanism (Ent) /= Default_Mechanism then
6269 Error_Msg_NE
6270 ("mechanism for & has already been set", Mech_Name, Ent);
6271 end if;
6272
6273 -- MECHANISM_NAME ::= value | reference | descriptor |
6274 -- short_descriptor
6275
6276 if Nkind (Mech_Name) = N_Identifier then
6277 if Chars (Mech_Name) = Name_Value then
6278 Set_Mechanism (Ent, By_Copy);
6279 return;
6280
6281 elsif Chars (Mech_Name) = Name_Reference then
6282 Set_Mechanism (Ent, By_Reference);
6283 return;
6284
6285 elsif Chars (Mech_Name) = Name_Descriptor then
6286 Check_VMS (Mech_Name);
6287
6288 -- Descriptor => Short_Descriptor if pragma was given
6289
6290 if Short_Descriptors then
6291 Set_Mechanism (Ent, By_Short_Descriptor);
6292 else
6293 Set_Mechanism (Ent, By_Descriptor);
6294 end if;
6295
6296 return;
6297
6298 elsif Chars (Mech_Name) = Name_Short_Descriptor then
6299 Check_VMS (Mech_Name);
6300 Set_Mechanism (Ent, By_Short_Descriptor);
6301 return;
6302
6303 elsif Chars (Mech_Name) = Name_Copy then
6304 Error_Pragma_Arg
6305 ("bad mechanism name, Value assumed", Mech_Name);
6306
6307 else
6308 Bad_Mechanism;
6309 end if;
6310
6311 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
6312 -- short_descriptor (CLASS_NAME)
6313 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6314
6315 -- Note: this form is parsed as an indexed component
6316
6317 elsif Nkind (Mech_Name) = N_Indexed_Component then
6318 Class := First (Expressions (Mech_Name));
6319
6320 if Nkind (Prefix (Mech_Name)) /= N_Identifier
6321 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
6322 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
6323 or else Present (Next (Class))
6324 then
6325 Bad_Mechanism;
6326 else
6327 Mech_Name_Id := Chars (Prefix (Mech_Name));
6328
6329 -- Change Descriptor => Short_Descriptor if pragma was given
6330
6331 if Mech_Name_Id = Name_Descriptor
6332 and then Short_Descriptors
6333 then
6334 Mech_Name_Id := Name_Short_Descriptor;
6335 end if;
6336 end if;
6337
6338 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
6339 -- short_descriptor (Class => CLASS_NAME)
6340 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6341
6342 -- Note: this form is parsed as a function call
6343
6344 elsif Nkind (Mech_Name) = N_Function_Call then
6345 Param := First (Parameter_Associations (Mech_Name));
6346
6347 if Nkind (Name (Mech_Name)) /= N_Identifier
6348 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6349 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6350 or else Present (Next (Param))
6351 or else No (Selector_Name (Param))
6352 or else Chars (Selector_Name (Param)) /= Name_Class
6353 then
6354 Bad_Mechanism;
6355 else
6356 Class := Explicit_Actual_Parameter (Param);
6357 Mech_Name_Id := Chars (Name (Mech_Name));
6358 end if;
6359
6360 else
6361 Bad_Mechanism;
6362 end if;
6363
6364 -- Fall through here with Class set to descriptor class name
6365
6366 Check_VMS (Mech_Name);
6367
6368 if Nkind (Class) /= N_Identifier then
6369 Bad_Class;
6370
6371 elsif Mech_Name_Id = Name_Descriptor
6372 and then Chars (Class) = Name_UBS
6373 then
6374 Set_Mechanism (Ent, By_Descriptor_UBS);
6375
6376 elsif Mech_Name_Id = Name_Descriptor
6377 and then Chars (Class) = Name_UBSB
6378 then
6379 Set_Mechanism (Ent, By_Descriptor_UBSB);
6380
6381 elsif Mech_Name_Id = Name_Descriptor
6382 and then Chars (Class) = Name_UBA
6383 then
6384 Set_Mechanism (Ent, By_Descriptor_UBA);
6385
6386 elsif Mech_Name_Id = Name_Descriptor
6387 and then Chars (Class) = Name_S
6388 then
6389 Set_Mechanism (Ent, By_Descriptor_S);
6390
6391 elsif Mech_Name_Id = Name_Descriptor
6392 and then Chars (Class) = Name_SB
6393 then
6394 Set_Mechanism (Ent, By_Descriptor_SB);
6395
6396 elsif Mech_Name_Id = Name_Descriptor
6397 and then Chars (Class) = Name_A
6398 then
6399 Set_Mechanism (Ent, By_Descriptor_A);
6400
6401 elsif Mech_Name_Id = Name_Descriptor
6402 and then Chars (Class) = Name_NCA
6403 then
6404 Set_Mechanism (Ent, By_Descriptor_NCA);
6405
6406 elsif Mech_Name_Id = Name_Short_Descriptor
6407 and then Chars (Class) = Name_UBS
6408 then
6409 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6410
6411 elsif Mech_Name_Id = Name_Short_Descriptor
6412 and then Chars (Class) = Name_UBSB
6413 then
6414 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6415
6416 elsif Mech_Name_Id = Name_Short_Descriptor
6417 and then Chars (Class) = Name_UBA
6418 then
6419 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6420
6421 elsif Mech_Name_Id = Name_Short_Descriptor
6422 and then Chars (Class) = Name_S
6423 then
6424 Set_Mechanism (Ent, By_Short_Descriptor_S);
6425
6426 elsif Mech_Name_Id = Name_Short_Descriptor
6427 and then Chars (Class) = Name_SB
6428 then
6429 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6430
6431 elsif Mech_Name_Id = Name_Short_Descriptor
6432 and then Chars (Class) = Name_A
6433 then
6434 Set_Mechanism (Ent, By_Short_Descriptor_A);
6435
6436 elsif Mech_Name_Id = Name_Short_Descriptor
6437 and then Chars (Class) = Name_NCA
6438 then
6439 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6440
6441 else
6442 Bad_Class;
6443 end if;
6444 end Set_Mechanism_Value;
6445
6446 --------------------------
6447 -- Set_Rational_Profile --
6448 --------------------------
6449
6450 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
6451 -- and extension to the semantics of renaming declarations.
6452
6453 procedure Set_Rational_Profile is
6454 begin
6455 Implicit_Packing := True;
6456 Overriding_Renamings := True;
6457 Use_VADS_Size := True;
6458 end Set_Rational_Profile;
6459
6460 ---------------------------
6461 -- Set_Ravenscar_Profile --
6462 ---------------------------
6463
6464 -- The tasks to be done here are
6465
6466 -- Set required policies
6467
6468 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6469 -- pragma Locking_Policy (Ceiling_Locking)
6470
6471 -- Set Detect_Blocking mode
6472
6473 -- Set required restrictions (see System.Rident for detailed list)
6474
6475 -- Set the No_Dependence rules
6476 -- No_Dependence => Ada.Asynchronous_Task_Control
6477 -- No_Dependence => Ada.Calendar
6478 -- No_Dependence => Ada.Execution_Time.Group_Budget
6479 -- No_Dependence => Ada.Execution_Time.Timers
6480 -- No_Dependence => Ada.Task_Attributes
6481 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6482
6483 procedure Set_Ravenscar_Profile (N : Node_Id) is
6484 Prefix_Entity : Entity_Id;
6485 Selector_Entity : Entity_Id;
6486 Prefix_Node : Node_Id;
6487 Node : Node_Id;
6488
6489 begin
6490 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6491
6492 if Task_Dispatching_Policy /= ' '
6493 and then Task_Dispatching_Policy /= 'F'
6494 then
6495 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6496 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6497
6498 -- Set the FIFO_Within_Priorities policy, but always preserve
6499 -- System_Location since we like the error message with the run time
6500 -- name.
6501
6502 else
6503 Task_Dispatching_Policy := 'F';
6504
6505 if Task_Dispatching_Policy_Sloc /= System_Location then
6506 Task_Dispatching_Policy_Sloc := Loc;
6507 end if;
6508 end if;
6509
6510 -- pragma Locking_Policy (Ceiling_Locking)
6511
6512 if Locking_Policy /= ' '
6513 and then Locking_Policy /= 'C'
6514 then
6515 Error_Msg_Sloc := Locking_Policy_Sloc;
6516 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6517
6518 -- Set the Ceiling_Locking policy, but preserve System_Location since
6519 -- we like the error message with the run time name.
6520
6521 else
6522 Locking_Policy := 'C';
6523
6524 if Locking_Policy_Sloc /= System_Location then
6525 Locking_Policy_Sloc := Loc;
6526 end if;
6527 end if;
6528
6529 -- pragma Detect_Blocking
6530
6531 Detect_Blocking := True;
6532
6533 -- Set the corresponding restrictions
6534
6535 Set_Profile_Restrictions
6536 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6537
6538 -- Set the No_Dependence restrictions
6539
6540 -- The following No_Dependence restrictions:
6541 -- No_Dependence => Ada.Asynchronous_Task_Control
6542 -- No_Dependence => Ada.Calendar
6543 -- No_Dependence => Ada.Task_Attributes
6544 -- are already set by previous call to Set_Profile_Restrictions.
6545
6546 -- Set the following restrictions which were added to Ada 2005:
6547 -- No_Dependence => Ada.Execution_Time.Group_Budget
6548 -- No_Dependence => Ada.Execution_Time.Timers
6549
6550 if Ada_Version >= Ada_2005 then
6551 Name_Buffer (1 .. 3) := "ada";
6552 Name_Len := 3;
6553
6554 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6555
6556 Name_Buffer (1 .. 14) := "execution_time";
6557 Name_Len := 14;
6558
6559 Selector_Entity := Make_Identifier (Loc, Name_Find);
6560
6561 Prefix_Node :=
6562 Make_Selected_Component
6563 (Sloc => Loc,
6564 Prefix => Prefix_Entity,
6565 Selector_Name => Selector_Entity);
6566
6567 Name_Buffer (1 .. 13) := "group_budgets";
6568 Name_Len := 13;
6569
6570 Selector_Entity := Make_Identifier (Loc, Name_Find);
6571
6572 Node :=
6573 Make_Selected_Component
6574 (Sloc => Loc,
6575 Prefix => Prefix_Node,
6576 Selector_Name => Selector_Entity);
6577
6578 Set_Restriction_No_Dependence
6579 (Unit => Node,
6580 Warn => Treat_Restrictions_As_Warnings,
6581 Profile => Ravenscar);
6582
6583 Name_Buffer (1 .. 6) := "timers";
6584 Name_Len := 6;
6585
6586 Selector_Entity := Make_Identifier (Loc, Name_Find);
6587
6588 Node :=
6589 Make_Selected_Component
6590 (Sloc => Loc,
6591 Prefix => Prefix_Node,
6592 Selector_Name => Selector_Entity);
6593
6594 Set_Restriction_No_Dependence
6595 (Unit => Node,
6596 Warn => Treat_Restrictions_As_Warnings,
6597 Profile => Ravenscar);
6598 end if;
6599
6600 -- Set the following restrictions which was added to Ada 2012 (see
6601 -- AI-0171):
6602 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6603
6604 if Ada_Version >= Ada_2012 then
6605 Name_Buffer (1 .. 6) := "system";
6606 Name_Len := 6;
6607
6608 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6609
6610 Name_Buffer (1 .. 15) := "multiprocessors";
6611 Name_Len := 15;
6612
6613 Selector_Entity := Make_Identifier (Loc, Name_Find);
6614
6615 Prefix_Node :=
6616 Make_Selected_Component
6617 (Sloc => Loc,
6618 Prefix => Prefix_Entity,
6619 Selector_Name => Selector_Entity);
6620
6621 Name_Buffer (1 .. 19) := "dispatching_domains";
6622 Name_Len := 19;
6623
6624 Selector_Entity := Make_Identifier (Loc, Name_Find);
6625
6626 Node :=
6627 Make_Selected_Component
6628 (Sloc => Loc,
6629 Prefix => Prefix_Node,
6630 Selector_Name => Selector_Entity);
6631
6632 Set_Restriction_No_Dependence
6633 (Unit => Node,
6634 Warn => Treat_Restrictions_As_Warnings,
6635 Profile => Ravenscar);
6636 end if;
6637 end Set_Ravenscar_Profile;
6638
6639 ----------------
6640 -- S14_Pragma --
6641 ----------------
6642
6643 procedure S14_Pragma is
6644 begin
6645 if not Formal_Extensions then
6646 Error_Pragma ("pragma% requires the use of debug switch -gnatd.V");
6647 end if;
6648 end S14_Pragma;
6649
6650 -- Start of processing for Analyze_Pragma
6651
6652 begin
6653 -- The following code is a defense against recursion. Not clear that
6654 -- this can happen legitimately, but perhaps some error situations
6655 -- can cause it, and we did see this recursion during testing.
6656
6657 if Analyzed (N) then
6658 return;
6659 else
6660 Set_Analyzed (N, True);
6661 end if;
6662
6663 -- Deal with unrecognized pragma
6664
6665 Pname := Pragma_Name (N);
6666
6667 if not Is_Pragma_Name (Pname) then
6668 if Warn_On_Unrecognized_Pragma then
6669 Error_Msg_Name_1 := Pname;
6670 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
6671
6672 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6673 if Is_Bad_Spelling_Of (Pname, PN) then
6674 Error_Msg_Name_1 := PN;
6675 Error_Msg_N -- CODEFIX
6676 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
6677 exit;
6678 end if;
6679 end loop;
6680 end if;
6681
6682 return;
6683 end if;
6684
6685 -- Here to start processing for recognized pragma
6686
6687 Prag_Id := Get_Pragma_Id (Pname);
6688
6689 if Present (Corresponding_Aspect (N)) then
6690 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6691 end if;
6692
6693 -- Preset arguments
6694
6695 Arg_Count := 0;
6696 Arg1 := Empty;
6697 Arg2 := Empty;
6698 Arg3 := Empty;
6699 Arg4 := Empty;
6700
6701 if Present (Pragma_Argument_Associations (N)) then
6702 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6703 Arg1 := First (Pragma_Argument_Associations (N));
6704
6705 if Present (Arg1) then
6706 Arg2 := Next (Arg1);
6707
6708 if Present (Arg2) then
6709 Arg3 := Next (Arg2);
6710
6711 if Present (Arg3) then
6712 Arg4 := Next (Arg3);
6713 end if;
6714 end if;
6715 end if;
6716 end if;
6717
6718 -- An enumeration type defines the pragmas that are supported by the
6719 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6720 -- into the corresponding enumeration value for the following case.
6721
6722 case Prag_Id is
6723
6724 -----------------
6725 -- Abort_Defer --
6726 -----------------
6727
6728 -- pragma Abort_Defer;
6729
6730 when Pragma_Abort_Defer =>
6731 GNAT_Pragma;
6732 Check_Arg_Count (0);
6733
6734 -- The only required semantic processing is to check the
6735 -- placement. This pragma must appear at the start of the
6736 -- statement sequence of a handled sequence of statements.
6737
6738 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6739 or else N /= First (Statements (Parent (N)))
6740 then
6741 Pragma_Misplaced;
6742 end if;
6743
6744 --------------------
6745 -- Abstract_State --
6746 --------------------
6747
6748 -- pragma Abstract_State (ABSTRACT_STATE_LIST)
6749
6750 -- ABSTRACT_STATE_LIST ::=
6751 -- null
6752 -- | STATE_NAME_WITH_PROPERTIES {, STATE_NAME_WITH_PROPERTIES}
6753
6754 -- STATE_NAME_WITH_PROPERTIES ::=
6755 -- STATE_NAME
6756 -- | (STATE_NAME with PROPERTY_LIST)
6757
6758 -- PROPERTY_LIST ::= PROPERTY {, PROPERTY}
6759 -- PROPERTY ::= SIMPLE_PROPERTY | NAME_VALUE_PROPERTY
6760
6761 -- SIMPLE_PROPERTY ::= IDENTIFIER
6762 -- NAME_VALUE_PROPERTY ::= IDENTIFIER => EXPRESSION
6763
6764 -- STATE_NAME ::= DEFINING_IDENTIFIER
6765
6766 when Pragma_Abstract_State => Abstract_State : declare
6767 Pack_Id : Entity_Id;
6768
6769 -- Flags used to verify the consistency of states
6770
6771 Non_Null_Seen : Boolean := False;
6772 Null_Seen : Boolean := False;
6773
6774 procedure Analyze_Abstract_State (State : Node_Id);
6775 -- Verify the legality of a single state declaration. Create and
6776 -- decorate a state abstraction entity and introduce it into the
6777 -- visibility chain.
6778
6779 ----------------------------
6780 -- Analyze_Abstract_State --
6781 ----------------------------
6782
6783 procedure Analyze_Abstract_State (State : Node_Id) is
6784 procedure Check_Duplicate_Property
6785 (Prop : Node_Id;
6786 Status : in out Boolean);
6787 -- Flag Status denotes whether a particular property has been
6788 -- seen while processing a state. This routine verifies that
6789 -- Prop is not a duplicate property and sets the flag Status.
6790
6791 ------------------------------
6792 -- Check_Duplicate_Property --
6793 ------------------------------
6794
6795 procedure Check_Duplicate_Property
6796 (Prop : Node_Id;
6797 Status : in out Boolean)
6798 is
6799 begin
6800 if Status then
6801 Error_Msg_N ("duplicate state property", Prop);
6802 end if;
6803
6804 Status := True;
6805 end Check_Duplicate_Property;
6806
6807 -- Local variables
6808
6809 Errors : constant Nat := Serious_Errors_Detected;
6810 Loc : constant Source_Ptr := Sloc (State);
6811 Assoc : Node_Id;
6812 Id : Entity_Id;
6813 Is_Null : Boolean := False;
6814 Level : Uint := Uint_0;
6815 Name : Name_Id;
6816 Prop : Node_Id;
6817
6818 -- Flags used to verify the consistency of properties
6819
6820 Input_Seen : Boolean := False;
6821 Integrity_Seen : Boolean := False;
6822 Output_Seen : Boolean := False;
6823 Volatile_Seen : Boolean := False;
6824
6825 -- Start of processing for Analyze_Abstract_State
6826
6827 begin
6828 -- A package with a null abstract state is not allowed to
6829 -- declare additional states.
6830
6831 if Null_Seen then
6832 Error_Msg_Name_1 := Chars (Pack_Id);
6833 Error_Msg_N ("package % has null abstract state", State);
6834
6835 -- Null states appear as internally generated entities
6836
6837 elsif Nkind (State) = N_Null then
6838 Name := New_Internal_Name ('S');
6839 Is_Null := True;
6840 Null_Seen := True;
6841
6842 -- Catch a case where a null state appears in a list of
6843 -- non-null states.
6844
6845 if Non_Null_Seen then
6846 Error_Msg_Name_1 := Chars (Pack_Id);
6847 Error_Msg_N
6848 ("package % has non-null abstract state", State);
6849 end if;
6850
6851 -- Simple state declaration
6852
6853 elsif Nkind (State) = N_Identifier then
6854 Name := Chars (State);
6855 Non_Null_Seen := True;
6856
6857 -- State declaration with various properties. This construct
6858 -- appears as an extension aggregate in the tree.
6859
6860 elsif Nkind (State) = N_Extension_Aggregate then
6861 if Nkind (Ancestor_Part (State)) = N_Identifier then
6862 Name := Chars (Ancestor_Part (State));
6863 Non_Null_Seen := True;
6864 else
6865 Error_Msg_N
6866 ("state name must be an identifier",
6867 Ancestor_Part (State));
6868 end if;
6869
6870 -- Process properties Input, Output and Volatile. Ensure
6871 -- that none of them appear more than once.
6872
6873 Prop := First (Expressions (State));
6874 while Present (Prop) loop
6875 if Nkind (Prop) = N_Identifier then
6876 if Chars (Prop) = Name_Input then
6877 Check_Duplicate_Property (Prop, Input_Seen);
6878 elsif Chars (Prop) = Name_Output then
6879 Check_Duplicate_Property (Prop, Output_Seen);
6880 elsif Chars (Prop) = Name_Volatile then
6881 Check_Duplicate_Property (Prop, Volatile_Seen);
6882 else
6883 Error_Msg_N ("invalid state property", Prop);
6884 end if;
6885 else
6886 Error_Msg_N ("invalid state property", Prop);
6887 end if;
6888
6889 Next (Prop);
6890 end loop;
6891
6892 -- Volatile requires exactly one Input or Output
6893
6894 if Volatile_Seen
6895 and then
6896 ((Input_Seen and then Output_Seen) -- both
6897 or else
6898 (not Input_Seen and then not Output_Seen)) -- none
6899 then
6900 Error_Msg_N
6901 ("property Volatile requires exactly one Input or "
6902 & "Output", State);
6903 end if;
6904
6905 -- Either Input or Output require Volatile
6906
6907 if (Input_Seen or Output_Seen)
6908 and then not Volatile_Seen
6909 then
6910 Error_Msg_N
6911 ("properties Input and Output require Volatile", State);
6912 end if;
6913
6914 -- State property Integrity appears as a component
6915 -- association.
6916
6917 Assoc := First (Component_Associations (State));
6918 while Present (Assoc) loop
6919 Prop := First (Choices (Assoc));
6920 while Present (Prop) loop
6921 if Nkind (Prop) = N_Identifier
6922 and then Chars (Prop) = Name_Integrity
6923 then
6924 Check_Duplicate_Property (Prop, Integrity_Seen);
6925 else
6926 Error_Msg_N ("invalid state property", Prop);
6927 end if;
6928
6929 Next (Prop);
6930 end loop;
6931
6932 if Nkind (Expression (Assoc)) = N_Integer_Literal then
6933 Level := Intval (Expression (Assoc));
6934 else
6935 Error_Msg_N
6936 ("integrity level must be an integer literal",
6937 Expression (Assoc));
6938 end if;
6939
6940 Next (Assoc);
6941 end loop;
6942
6943 -- Any other attempt to declare a state is erroneous
6944
6945 else
6946 Error_Msg_N ("malformed abstract state declaration", State);
6947 end if;
6948
6949 -- Do not generate a state abstraction entity if it was not
6950 -- properly declared.
6951
6952 if Serious_Errors_Detected > Errors then
6953 return;
6954 end if;
6955
6956 -- The generated state abstraction reuses the same characters
6957 -- from the original state declaration. Decorate the entity.
6958
6959 Id := Make_Defining_Identifier (Loc, New_External_Name (Name));
6960 Set_Comes_From_Source (Id, not Is_Null);
6961 Set_Parent (Id, State);
6962 Set_Ekind (Id, E_Abstract_State);
6963 Set_Etype (Id, Standard_Void_Type);
6964 Set_Integrity_Level (Id, Level);
6965 Set_Refined_State (Id, Empty);
6966
6967 -- Every non-null state must be nameable and resolvable the
6968 -- same way a constant is.
6969
6970 if not Is_Null then
6971 Push_Scope (Pack_Id);
6972 Enter_Name (Id);
6973 Pop_Scope;
6974 end if;
6975
6976 -- Associate the state with its related package
6977
6978 if No (Abstract_States (Pack_Id)) then
6979 Set_Abstract_States (Pack_Id, New_Elmt_List);
6980 end if;
6981
6982 Append_Elmt (Id, Abstract_States (Pack_Id));
6983 end Analyze_Abstract_State;
6984
6985 -- Local variables
6986
6987 Par : Node_Id;
6988 State : Node_Id;
6989
6990 -- Start of processing for Abstract_State
6991
6992 begin
6993 GNAT_Pragma;
6994 S14_Pragma;
6995 Check_Arg_Count (1);
6996
6997 -- Ensure the proper placement of the pragma. Abstract states must
6998 -- be associated with a package declaration.
6999
7000 if From_Aspect_Specification (N) then
7001 Par := Parent (Corresponding_Aspect (N));
7002 else
7003 Par := Parent (Parent (N));
7004 end if;
7005
7006 if Nkind (Par) = N_Compilation_Unit then
7007 Par := Unit (Par);
7008 end if;
7009
7010 if Nkind (Par) /= N_Package_Declaration then
7011 Pragma_Misplaced;
7012 return;
7013 end if;
7014
7015 Pack_Id := Defining_Unit_Name (Specification (Par));
7016 State := Expression (Arg1);
7017
7018 -- Multiple abstract states appear as an aggregate
7019
7020 if Nkind (State) = N_Aggregate then
7021 State := First (Expressions (State));
7022 while Present (State) loop
7023 Analyze_Abstract_State (State);
7024
7025 Next (State);
7026 end loop;
7027
7028 -- Various forms of a single abstract state. Note that these may
7029 -- include malformed state declarations.
7030
7031 else
7032 Analyze_Abstract_State (State);
7033 end if;
7034 end Abstract_State;
7035
7036 ------------
7037 -- Ada_83 --
7038 ------------
7039
7040 -- pragma Ada_83;
7041
7042 -- Note: this pragma also has some specific processing in Par.Prag
7043 -- because we want to set the Ada version mode during parsing.
7044
7045 when Pragma_Ada_83 =>
7046 GNAT_Pragma;
7047 Check_Arg_Count (0);
7048
7049 -- We really should check unconditionally for proper configuration
7050 -- pragma placement, since we really don't want mixed Ada modes
7051 -- within a single unit, and the GNAT reference manual has always
7052 -- said this was a configuration pragma, but we did not check and
7053 -- are hesitant to add the check now.
7054
7055 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
7056 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
7057 -- or Ada 2012 mode.
7058
7059 if Ada_Version >= Ada_2005 then
7060 Check_Valid_Configuration_Pragma;
7061 end if;
7062
7063 -- Now set Ada 83 mode
7064
7065 Ada_Version := Ada_83;
7066 Ada_Version_Explicit := Ada_Version;
7067
7068 ------------
7069 -- Ada_95 --
7070 ------------
7071
7072 -- pragma Ada_95;
7073
7074 -- Note: this pragma also has some specific processing in Par.Prag
7075 -- because we want to set the Ada 83 version mode during parsing.
7076
7077 when Pragma_Ada_95 =>
7078 GNAT_Pragma;
7079 Check_Arg_Count (0);
7080
7081 -- We really should check unconditionally for proper configuration
7082 -- pragma placement, since we really don't want mixed Ada modes
7083 -- within a single unit, and the GNAT reference manual has always
7084 -- said this was a configuration pragma, but we did not check and
7085 -- are hesitant to add the check now.
7086
7087 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
7088 -- or Ada 95, so we must check if we are in Ada 2005 mode.
7089
7090 if Ada_Version >= Ada_2005 then
7091 Check_Valid_Configuration_Pragma;
7092 end if;
7093
7094 -- Now set Ada 95 mode
7095
7096 Ada_Version := Ada_95;
7097 Ada_Version_Explicit := Ada_Version;
7098
7099 ---------------------
7100 -- Ada_05/Ada_2005 --
7101 ---------------------
7102
7103 -- pragma Ada_05;
7104 -- pragma Ada_05 (LOCAL_NAME);
7105
7106 -- pragma Ada_2005;
7107 -- pragma Ada_2005 (LOCAL_NAME):
7108
7109 -- Note: these pragmas also have some specific processing in Par.Prag
7110 -- because we want to set the Ada 2005 version mode during parsing.
7111
7112 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
7113 E_Id : Node_Id;
7114
7115 begin
7116 GNAT_Pragma;
7117
7118 if Arg_Count = 1 then
7119 Check_Arg_Is_Local_Name (Arg1);
7120 E_Id := Get_Pragma_Arg (Arg1);
7121
7122 if Etype (E_Id) = Any_Type then
7123 return;
7124 end if;
7125
7126 Set_Is_Ada_2005_Only (Entity (E_Id));
7127 Record_Rep_Item (Entity (E_Id), N);
7128
7129 else
7130 Check_Arg_Count (0);
7131
7132 -- For Ada_2005 we unconditionally enforce the documented
7133 -- configuration pragma placement, since we do not want to
7134 -- tolerate mixed modes in a unit involving Ada 2005. That
7135 -- would cause real difficulties for those cases where there
7136 -- are incompatibilities between Ada 95 and Ada 2005.
7137
7138 Check_Valid_Configuration_Pragma;
7139
7140 -- Now set appropriate Ada mode
7141
7142 Ada_Version := Ada_2005;
7143 Ada_Version_Explicit := Ada_2005;
7144 end if;
7145 end;
7146
7147 ---------------------
7148 -- Ada_12/Ada_2012 --
7149 ---------------------
7150
7151 -- pragma Ada_12;
7152 -- pragma Ada_12 (LOCAL_NAME);
7153
7154 -- pragma Ada_2012;
7155 -- pragma Ada_2012 (LOCAL_NAME):
7156
7157 -- Note: these pragmas also have some specific processing in Par.Prag
7158 -- because we want to set the Ada 2012 version mode during parsing.
7159
7160 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
7161 E_Id : Node_Id;
7162
7163 begin
7164 GNAT_Pragma;
7165
7166 if Arg_Count = 1 then
7167 Check_Arg_Is_Local_Name (Arg1);
7168 E_Id := Get_Pragma_Arg (Arg1);
7169
7170 if Etype (E_Id) = Any_Type then
7171 return;
7172 end if;
7173
7174 Set_Is_Ada_2012_Only (Entity (E_Id));
7175 Record_Rep_Item (Entity (E_Id), N);
7176
7177 else
7178 Check_Arg_Count (0);
7179
7180 -- For Ada_2012 we unconditionally enforce the documented
7181 -- configuration pragma placement, since we do not want to
7182 -- tolerate mixed modes in a unit involving Ada 2012. That
7183 -- would cause real difficulties for those cases where there
7184 -- are incompatibilities between Ada 95 and Ada 2012. We could
7185 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
7186
7187 Check_Valid_Configuration_Pragma;
7188
7189 -- Now set appropriate Ada mode
7190
7191 Ada_Version := Ada_2012;
7192 Ada_Version_Explicit := Ada_2012;
7193 end if;
7194 end;
7195
7196 ----------------------
7197 -- All_Calls_Remote --
7198 ----------------------
7199
7200 -- pragma All_Calls_Remote [(library_package_NAME)];
7201
7202 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
7203 Lib_Entity : Entity_Id;
7204
7205 begin
7206 Check_Ada_83_Warning;
7207 Check_Valid_Library_Unit_Pragma;
7208
7209 if Nkind (N) = N_Null_Statement then
7210 return;
7211 end if;
7212
7213 Lib_Entity := Find_Lib_Unit_Name;
7214
7215 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
7216
7217 if Present (Lib_Entity)
7218 and then not Debug_Flag_U
7219 then
7220 if not Is_Remote_Call_Interface (Lib_Entity) then
7221 Error_Pragma ("pragma% only apply to rci unit");
7222
7223 -- Set flag for entity of the library unit
7224
7225 else
7226 Set_Has_All_Calls_Remote (Lib_Entity);
7227 end if;
7228
7229 end if;
7230 end All_Calls_Remote;
7231
7232 --------------
7233 -- Annotate --
7234 --------------
7235
7236 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
7237 -- ARG ::= NAME | EXPRESSION
7238
7239 -- The first two arguments are by convention intended to refer to an
7240 -- external tool and a tool-specific function. These arguments are
7241 -- not analyzed.
7242
7243 when Pragma_Annotate => Annotate : declare
7244 Arg : Node_Id;
7245 Exp : Node_Id;
7246
7247 begin
7248 GNAT_Pragma;
7249 Check_At_Least_N_Arguments (1);
7250 Check_Arg_Is_Identifier (Arg1);
7251 Check_No_Identifiers;
7252 Store_Note (N);
7253
7254 -- Second parameter is optional, it is never analyzed
7255
7256 if No (Arg2) then
7257 null;
7258
7259 -- Here if we have a second parameter
7260
7261 else
7262 -- Second parameter must be identifier
7263
7264 Check_Arg_Is_Identifier (Arg2);
7265
7266 -- Process remaining parameters if any
7267
7268 Arg := Next (Arg2);
7269 while Present (Arg) loop
7270 Exp := Get_Pragma_Arg (Arg);
7271 Analyze (Exp);
7272
7273 if Is_Entity_Name (Exp) then
7274 null;
7275
7276 -- For string literals, we assume Standard_String as the
7277 -- type, unless the string contains wide or wide_wide
7278 -- characters.
7279
7280 elsif Nkind (Exp) = N_String_Literal then
7281 if Has_Wide_Wide_Character (Exp) then
7282 Resolve (Exp, Standard_Wide_Wide_String);
7283 elsif Has_Wide_Character (Exp) then
7284 Resolve (Exp, Standard_Wide_String);
7285 else
7286 Resolve (Exp, Standard_String);
7287 end if;
7288
7289 elsif Is_Overloaded (Exp) then
7290 Error_Pragma_Arg
7291 ("ambiguous argument for pragma%", Exp);
7292
7293 else
7294 Resolve (Exp);
7295 end if;
7296
7297 Next (Arg);
7298 end loop;
7299 end if;
7300 end Annotate;
7301
7302 ---------------------------
7303 -- Assert/Assert_And_Cut --
7304 ---------------------------
7305
7306 -- pragma Assert
7307 -- ( [Check => ] Boolean_EXPRESSION
7308 -- [, [Message =>] Static_String_EXPRESSION]);
7309
7310 -- pragma Assert_And_Cut
7311 -- ( [Check => ] Boolean_EXPRESSION
7312 -- [, [Message =>] Static_String_EXPRESSION]);
7313
7314 when Pragma_Assert | Pragma_Assert_And_Cut => Assert : declare
7315 Expr : Node_Id;
7316 Newa : List_Id;
7317
7318 begin
7319 if Prag_Id = Pragma_Assert then
7320 Ada_2005_Pragma;
7321 else -- Pragma_Assert_And_Cut
7322 GNAT_Pragma;
7323 S14_Pragma;
7324 end if;
7325
7326 Check_At_Least_N_Arguments (1);
7327 Check_At_Most_N_Arguments (2);
7328 Check_Arg_Order ((Name_Check, Name_Message));
7329 Check_Optional_Identifier (Arg1, Name_Check);
7330
7331 -- We treat pragma Assert as equivalent to:
7332
7333 -- pragma Check (Assertion, condition [, msg]);
7334
7335 -- So rewrite pragma in this manner, transfer the message
7336 -- argument if present, and analyze the result
7337
7338 -- Pragma Assert_And_Cut is treated exactly like pragma Assert by
7339 -- the frontend. Formal verification tools may use it to "cut" the
7340 -- paths through the code, to make verification tractable. When
7341 -- dealing with a semantically analyzed tree, the information that
7342 -- a Check node N corresponds to a source Assert_And_Cut pragma
7343 -- can be retrieved from the pragma kind of Original_Node(N).
7344
7345 Expr := Get_Pragma_Arg (Arg1);
7346 Newa := New_List (
7347 Make_Pragma_Argument_Association (Loc,
7348 Expression => Make_Identifier (Loc, Name_Assertion)),
7349
7350 Make_Pragma_Argument_Association (Sloc (Expr),
7351 Expression => Expr));
7352
7353 if Arg_Count > 1 then
7354 Check_Optional_Identifier (Arg2, Name_Message);
7355 Append_To (Newa, New_Copy_Tree (Arg2));
7356 end if;
7357
7358 Rewrite (N,
7359 Make_Pragma (Loc,
7360 Chars => Name_Check,
7361 Pragma_Argument_Associations => Newa));
7362 Analyze (N);
7363 end Assert;
7364
7365 ----------------------
7366 -- Assertion_Policy --
7367 ----------------------
7368
7369 -- pragma Assertion_Policy (Check | Disable | Ignore)
7370
7371 when Pragma_Assertion_Policy => Assertion_Policy : declare
7372 Policy : Node_Id;
7373
7374 begin
7375 Ada_2005_Pragma;
7376 Check_Valid_Configuration_Pragma;
7377 Check_Arg_Count (1);
7378 Check_No_Identifiers;
7379 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7380
7381 -- We treat pragma Assertion_Policy as equivalent to:
7382
7383 -- pragma Check_Policy (Assertion, policy)
7384
7385 -- So rewrite the pragma in that manner and link on to the chain
7386 -- of Check_Policy pragmas, marking the pragma as analyzed.
7387
7388 Policy := Get_Pragma_Arg (Arg1);
7389
7390 Rewrite (N,
7391 Make_Pragma (Loc,
7392 Chars => Name_Check_Policy,
7393 Pragma_Argument_Associations => New_List (
7394 Make_Pragma_Argument_Association (Loc,
7395 Expression => Make_Identifier (Loc, Name_Assertion)),
7396
7397 Make_Pragma_Argument_Association (Loc,
7398 Expression =>
7399 Make_Identifier (Sloc (Policy), Chars (Policy))))));
7400
7401 Set_Analyzed (N);
7402 Set_Next_Pragma (N, Opt.Check_Policy_List);
7403 Opt.Check_Policy_List := N;
7404 end Assertion_Policy;
7405
7406 ------------
7407 -- Assume --
7408 ------------
7409
7410 -- pragma Assume (boolean_EXPRESSION);
7411
7412 when Pragma_Assume => Assume : declare
7413 begin
7414 GNAT_Pragma;
7415 S14_Pragma;
7416 Check_Arg_Count (1);
7417
7418 -- Pragma Assume is transformed into pragma Check in the following
7419 -- manner:
7420
7421 -- pragma Check (Assume, Expr);
7422
7423 Rewrite (N,
7424 Make_Pragma (Loc,
7425 Chars => Name_Check,
7426 Pragma_Argument_Associations => New_List (
7427 Make_Pragma_Argument_Association (Loc,
7428 Expression => Make_Identifier (Loc, Name_Assume)),
7429
7430 Make_Pragma_Argument_Association (Loc,
7431 Expression => Relocate_Node (Expression (Arg1))))));
7432 Analyze (N);
7433 end Assume;
7434
7435 ------------------------------
7436 -- Assume_No_Invalid_Values --
7437 ------------------------------
7438
7439 -- pragma Assume_No_Invalid_Values (On | Off);
7440
7441 when Pragma_Assume_No_Invalid_Values =>
7442 GNAT_Pragma;
7443 Check_Valid_Configuration_Pragma;
7444 Check_Arg_Count (1);
7445 Check_No_Identifiers;
7446 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7447
7448 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
7449 Assume_No_Invalid_Values := True;
7450 else
7451 Assume_No_Invalid_Values := False;
7452 end if;
7453
7454 --------------------------
7455 -- Attribute_Definition --
7456 --------------------------
7457
7458 -- pragma Attribute_Definition
7459 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
7460 -- [Entity =>] LOCAL_NAME,
7461 -- [Expression =>] EXPRESSION | NAME);
7462
7463 when Pragma_Attribute_Definition => Attribute_Definition : declare
7464 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
7465 Aname : Name_Id;
7466
7467 begin
7468 GNAT_Pragma;
7469 Check_Arg_Count (3);
7470 Check_Optional_Identifier (Arg1, "attribute");
7471 Check_Optional_Identifier (Arg2, "entity");
7472 Check_Optional_Identifier (Arg3, "expression");
7473
7474 if Nkind (Attribute_Designator) /= N_Identifier then
7475 Error_Msg_N ("attribute name expected", Attribute_Designator);
7476 return;
7477 end if;
7478
7479 Check_Arg_Is_Local_Name (Arg2);
7480
7481 -- If the attribute is not recognized, then issue a warning (not
7482 -- an error), and ignore the pragma.
7483
7484 Aname := Chars (Attribute_Designator);
7485
7486 if not Is_Attribute_Name (Aname) then
7487 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
7488 return;
7489 end if;
7490
7491 -- Otherwise, rewrite the pragma as an attribute definition clause
7492
7493 Rewrite (N,
7494 Make_Attribute_Definition_Clause (Loc,
7495 Name => Get_Pragma_Arg (Arg2),
7496 Chars => Aname,
7497 Expression => Get_Pragma_Arg (Arg3)));
7498 Analyze (N);
7499 end Attribute_Definition;
7500
7501 ---------------
7502 -- AST_Entry --
7503 ---------------
7504
7505 -- pragma AST_Entry (entry_IDENTIFIER);
7506
7507 when Pragma_AST_Entry => AST_Entry : declare
7508 Ent : Node_Id;
7509
7510 begin
7511 GNAT_Pragma;
7512 Check_VMS (N);
7513 Check_Arg_Count (1);
7514 Check_No_Identifiers;
7515 Check_Arg_Is_Local_Name (Arg1);
7516 Ent := Entity (Get_Pragma_Arg (Arg1));
7517
7518 -- Note: the implementation of the AST_Entry pragma could handle
7519 -- the entry family case fine, but for now we are consistent with
7520 -- the DEC rules, and do not allow the pragma, which of course
7521 -- has the effect of also forbidding the attribute.
7522
7523 if Ekind (Ent) /= E_Entry then
7524 Error_Pragma_Arg
7525 ("pragma% argument must be simple entry name", Arg1);
7526
7527 elsif Is_AST_Entry (Ent) then
7528 Error_Pragma_Arg
7529 ("duplicate % pragma for entry", Arg1);
7530
7531 elsif Has_Homonym (Ent) then
7532 Error_Pragma_Arg
7533 ("pragma% argument cannot specify overloaded entry", Arg1);
7534
7535 else
7536 declare
7537 FF : constant Entity_Id := First_Formal (Ent);
7538
7539 begin
7540 if Present (FF) then
7541 if Present (Next_Formal (FF)) then
7542 Error_Pragma_Arg
7543 ("entry for pragma% can have only one argument",
7544 Arg1);
7545
7546 elsif Parameter_Mode (FF) /= E_In_Parameter then
7547 Error_Pragma_Arg
7548 ("entry parameter for pragma% must have mode IN",
7549 Arg1);
7550 end if;
7551 end if;
7552 end;
7553
7554 Set_Is_AST_Entry (Ent);
7555 end if;
7556 end AST_Entry;
7557
7558 ------------------
7559 -- Asynchronous --
7560 ------------------
7561
7562 -- pragma Asynchronous (LOCAL_NAME);
7563
7564 when Pragma_Asynchronous => Asynchronous : declare
7565 Nm : Entity_Id;
7566 C_Ent : Entity_Id;
7567 L : List_Id;
7568 S : Node_Id;
7569 N : Node_Id;
7570 Formal : Entity_Id;
7571
7572 procedure Process_Async_Pragma;
7573 -- Common processing for procedure and access-to-procedure case
7574
7575 --------------------------
7576 -- Process_Async_Pragma --
7577 --------------------------
7578
7579 procedure Process_Async_Pragma is
7580 begin
7581 if No (L) then
7582 Set_Is_Asynchronous (Nm);
7583 return;
7584 end if;
7585
7586 -- The formals should be of mode IN (RM E.4.1(6))
7587
7588 S := First (L);
7589 while Present (S) loop
7590 Formal := Defining_Identifier (S);
7591
7592 if Nkind (Formal) = N_Defining_Identifier
7593 and then Ekind (Formal) /= E_In_Parameter
7594 then
7595 Error_Pragma_Arg
7596 ("pragma% procedure can only have IN parameter",
7597 Arg1);
7598 end if;
7599
7600 Next (S);
7601 end loop;
7602
7603 Set_Is_Asynchronous (Nm);
7604 end Process_Async_Pragma;
7605
7606 -- Start of processing for pragma Asynchronous
7607
7608 begin
7609 Check_Ada_83_Warning;
7610 Check_No_Identifiers;
7611 Check_Arg_Count (1);
7612 Check_Arg_Is_Local_Name (Arg1);
7613
7614 if Debug_Flag_U then
7615 return;
7616 end if;
7617
7618 C_Ent := Cunit_Entity (Current_Sem_Unit);
7619 Analyze (Get_Pragma_Arg (Arg1));
7620 Nm := Entity (Get_Pragma_Arg (Arg1));
7621
7622 if not Is_Remote_Call_Interface (C_Ent)
7623 and then not Is_Remote_Types (C_Ent)
7624 then
7625 -- This pragma should only appear in an RCI or Remote Types
7626 -- unit (RM E.4.1(4)).
7627
7628 Error_Pragma
7629 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
7630 end if;
7631
7632 if Ekind (Nm) = E_Procedure
7633 and then Nkind (Parent (Nm)) = N_Procedure_Specification
7634 then
7635 if not Is_Remote_Call_Interface (Nm) then
7636 Error_Pragma_Arg
7637 ("pragma% cannot be applied on non-remote procedure",
7638 Arg1);
7639 end if;
7640
7641 L := Parameter_Specifications (Parent (Nm));
7642 Process_Async_Pragma;
7643 return;
7644
7645 elsif Ekind (Nm) = E_Function then
7646 Error_Pragma_Arg
7647 ("pragma% cannot be applied to function", Arg1);
7648
7649 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
7650 if Is_Record_Type (Nm) then
7651
7652 -- A record type that is the Equivalent_Type for a remote
7653 -- access-to-subprogram type.
7654
7655 N := Declaration_Node (Corresponding_Remote_Type (Nm));
7656
7657 else
7658 -- A non-expanded RAS type (distribution is not enabled)
7659
7660 N := Declaration_Node (Nm);
7661 end if;
7662
7663 if Nkind (N) = N_Full_Type_Declaration
7664 and then Nkind (Type_Definition (N)) =
7665 N_Access_Procedure_Definition
7666 then
7667 L := Parameter_Specifications (Type_Definition (N));
7668 Process_Async_Pragma;
7669
7670 if Is_Asynchronous (Nm)
7671 and then Expander_Active
7672 and then Get_PCS_Name /= Name_No_DSA
7673 then
7674 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
7675 end if;
7676
7677 else
7678 Error_Pragma_Arg
7679 ("pragma% cannot reference access-to-function type",
7680 Arg1);
7681 end if;
7682
7683 -- Only other possibility is Access-to-class-wide type
7684
7685 elsif Is_Access_Type (Nm)
7686 and then Is_Class_Wide_Type (Designated_Type (Nm))
7687 then
7688 Check_First_Subtype (Arg1);
7689 Set_Is_Asynchronous (Nm);
7690 if Expander_Active then
7691 RACW_Type_Is_Asynchronous (Nm);
7692 end if;
7693
7694 else
7695 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
7696 end if;
7697 end Asynchronous;
7698
7699 ------------
7700 -- Atomic --
7701 ------------
7702
7703 -- pragma Atomic (LOCAL_NAME);
7704
7705 when Pragma_Atomic =>
7706 Process_Atomic_Shared_Volatile;
7707
7708 -----------------------
7709 -- Atomic_Components --
7710 -----------------------
7711
7712 -- pragma Atomic_Components (array_LOCAL_NAME);
7713
7714 -- This processing is shared by Volatile_Components
7715
7716 when Pragma_Atomic_Components |
7717 Pragma_Volatile_Components =>
7718
7719 Atomic_Components : declare
7720 E_Id : Node_Id;
7721 E : Entity_Id;
7722 D : Node_Id;
7723 K : Node_Kind;
7724
7725 begin
7726 Check_Ada_83_Warning;
7727 Check_No_Identifiers;
7728 Check_Arg_Count (1);
7729 Check_Arg_Is_Local_Name (Arg1);
7730 E_Id := Get_Pragma_Arg (Arg1);
7731
7732 if Etype (E_Id) = Any_Type then
7733 return;
7734 end if;
7735
7736 E := Entity (E_Id);
7737
7738 Check_Duplicate_Pragma (E);
7739
7740 if Rep_Item_Too_Early (E, N)
7741 or else
7742 Rep_Item_Too_Late (E, N)
7743 then
7744 return;
7745 end if;
7746
7747 D := Declaration_Node (E);
7748 K := Nkind (D);
7749
7750 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
7751 or else
7752 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7753 and then Nkind (D) = N_Object_Declaration
7754 and then Nkind (Object_Definition (D)) =
7755 N_Constrained_Array_Definition)
7756 then
7757 -- The flag is set on the object, or on the base type
7758
7759 if Nkind (D) /= N_Object_Declaration then
7760 E := Base_Type (E);
7761 end if;
7762
7763 Set_Has_Volatile_Components (E);
7764
7765 if Prag_Id = Pragma_Atomic_Components then
7766 Set_Has_Atomic_Components (E);
7767 end if;
7768
7769 else
7770 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7771 end if;
7772 end Atomic_Components;
7773
7774 --------------------
7775 -- Attach_Handler --
7776 --------------------
7777
7778 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7779
7780 when Pragma_Attach_Handler =>
7781 Check_Ada_83_Warning;
7782 Check_No_Identifiers;
7783 Check_Arg_Count (2);
7784
7785 if No_Run_Time_Mode then
7786 Error_Msg_CRT ("Attach_Handler pragma", N);
7787 else
7788 Check_Interrupt_Or_Attach_Handler;
7789
7790 -- The expression that designates the attribute may depend on a
7791 -- discriminant, and is therefore a per-object expression, to
7792 -- be expanded in the init proc. If expansion is enabled, then
7793 -- perform semantic checks on a copy only.
7794
7795 if Expander_Active then
7796 declare
7797 Temp : constant Node_Id :=
7798 New_Copy_Tree (Get_Pragma_Arg (Arg2));
7799 begin
7800 Set_Parent (Temp, N);
7801 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7802 end;
7803
7804 else
7805 Analyze (Get_Pragma_Arg (Arg2));
7806 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7807 end if;
7808
7809 Process_Interrupt_Or_Attach_Handler;
7810 end if;
7811
7812 --------------------
7813 -- C_Pass_By_Copy --
7814 --------------------
7815
7816 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7817
7818 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7819 Arg : Node_Id;
7820 Val : Uint;
7821
7822 begin
7823 GNAT_Pragma;
7824 Check_Valid_Configuration_Pragma;
7825 Check_Arg_Count (1);
7826 Check_Optional_Identifier (Arg1, "max_size");
7827
7828 Arg := Get_Pragma_Arg (Arg1);
7829 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7830
7831 Val := Expr_Value (Arg);
7832
7833 if Val <= 0 then
7834 Error_Pragma_Arg
7835 ("maximum size for pragma% must be positive", Arg1);
7836
7837 elsif UI_Is_In_Int_Range (Val) then
7838 Default_C_Record_Mechanism := UI_To_Int (Val);
7839
7840 -- If a giant value is given, Int'Last will do well enough.
7841 -- If sometime someone complains that a record larger than
7842 -- two gigabytes is not copied, we will worry about it then!
7843
7844 else
7845 Default_C_Record_Mechanism := Mechanism_Type'Last;
7846 end if;
7847 end C_Pass_By_Copy;
7848
7849 -----------
7850 -- Check --
7851 -----------
7852
7853 -- pragma Check ([Name =>] IDENTIFIER,
7854 -- [Check =>] Boolean_EXPRESSION
7855 -- [,[Message =>] String_EXPRESSION]);
7856
7857 when Pragma_Check => Check : declare
7858 Expr : Node_Id;
7859 Eloc : Source_Ptr;
7860 Cname : Name_Id;
7861 Str : Node_Id;
7862
7863 Check_On : Boolean;
7864 -- Set True if category of assertions referenced by Name enabled
7865
7866 begin
7867 GNAT_Pragma;
7868 Check_At_Least_N_Arguments (2);
7869 Check_At_Most_N_Arguments (3);
7870 Check_Optional_Identifier (Arg1, Name_Name);
7871 Check_Optional_Identifier (Arg2, Name_Check);
7872
7873 if Arg_Count = 3 then
7874 Check_Optional_Identifier (Arg3, Name_Message);
7875 Str := Get_Pragma_Arg (Arg3);
7876 end if;
7877
7878 Check_Arg_Is_Identifier (Arg1);
7879 Cname := Chars (Get_Pragma_Arg (Arg1));
7880 Check_On := Check_Enabled (Cname);
7881 Expr := Get_Pragma_Arg (Arg2);
7882
7883 -- Deal with SCO generation
7884
7885 case Cname is
7886 when Name_Predicate |
7887 Name_Invariant =>
7888
7889 -- Nothing to do: since checks occur in client units,
7890 -- the SCO for the aspect in the declaration unit is
7891 -- conservatively always enabled.
7892
7893 null;
7894
7895 when others =>
7896
7897 if Check_On and then not Split_PPC (N) then
7898
7899 -- Mark pragma/aspect SCO as enabled
7900
7901 Set_SCO_Pragma_Enabled (Loc);
7902 end if;
7903 end case;
7904
7905 -- Deal with analyzing the string argument.
7906
7907 if Arg_Count = 3 then
7908
7909 -- If checks are not on we don't want any expansion (since
7910 -- such expansion would not get properly deleted) but
7911 -- we do want to analyze (to get proper references).
7912 -- The Preanalyze_And_Resolve routine does just what we want
7913
7914 if not Check_On then
7915 Preanalyze_And_Resolve (Str, Standard_String);
7916
7917 -- Otherwise we need a proper analysis and expansion
7918
7919 else
7920 Analyze_And_Resolve (Str, Standard_String);
7921 end if;
7922 end if;
7923
7924 -- Now you might think we could just do the same with the Boolean
7925 -- expression if checks are off (and expansion is on) and then
7926 -- rewrite the check as a null statement. This would work but we
7927 -- would lose the useful warnings about an assertion being bound
7928 -- to fail even if assertions are turned off.
7929
7930 -- So instead we wrap the boolean expression in an if statement
7931 -- that looks like:
7932
7933 -- if False and then condition then
7934 -- null;
7935 -- end if;
7936
7937 -- The reason we do this rewriting during semantic analysis
7938 -- rather than as part of normal expansion is that we cannot
7939 -- analyze and expand the code for the boolean expression
7940 -- directly, or it may cause insertion of actions that would
7941 -- escape the attempt to suppress the check code.
7942
7943 -- Note that the Sloc for the if statement corresponds to the
7944 -- argument condition, not the pragma itself. The reason for
7945 -- this is that we may generate a warning if the condition is
7946 -- False at compile time, and we do not want to delete this
7947 -- warning when we delete the if statement.
7948
7949 if Expander_Active and not Check_On then
7950 Eloc := Sloc (Expr);
7951
7952 Rewrite (N,
7953 Make_If_Statement (Eloc,
7954 Condition =>
7955 Make_And_Then (Eloc,
7956 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7957 Right_Opnd => Expr),
7958 Then_Statements => New_List (
7959 Make_Null_Statement (Eloc))));
7960
7961 In_Assertion_Expr := In_Assertion_Expr + 1;
7962 Analyze (N);
7963 In_Assertion_Expr := In_Assertion_Expr - 1;
7964
7965 -- Check is active or expansion not active. In these cases we can
7966 -- just go ahead and analyze the boolean with no worries.
7967
7968 else
7969 In_Assertion_Expr := In_Assertion_Expr + 1;
7970 Analyze_And_Resolve (Expr, Any_Boolean);
7971 In_Assertion_Expr := In_Assertion_Expr - 1;
7972 end if;
7973 end Check;
7974
7975 --------------------------
7976 -- Check_Float_Overflow --
7977 --------------------------
7978
7979 -- pragma Check_Float_Overflow;
7980
7981 when Pragma_Check_Float_Overflow =>
7982 GNAT_Pragma;
7983 Check_Valid_Configuration_Pragma;
7984 Check_Arg_Count (0);
7985 Check_Float_Overflow := True;
7986
7987 ----------------
7988 -- Check_Name --
7989 ----------------
7990
7991 -- pragma Check_Name (check_IDENTIFIER);
7992
7993 when Pragma_Check_Name =>
7994 Check_No_Identifiers;
7995 GNAT_Pragma;
7996 Check_Valid_Configuration_Pragma;
7997 Check_Arg_Count (1);
7998 Check_Arg_Is_Identifier (Arg1);
7999
8000 declare
8001 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
8002
8003 begin
8004 for J in Check_Names.First .. Check_Names.Last loop
8005 if Check_Names.Table (J) = Nam then
8006 return;
8007 end if;
8008 end loop;
8009
8010 Check_Names.Append (Nam);
8011 end;
8012
8013 ------------------
8014 -- Check_Policy --
8015 ------------------
8016
8017 -- pragma Check_Policy (
8018 -- [Name =>] IDENTIFIER,
8019 -- [Policy =>] POLICY_IDENTIFIER);
8020
8021 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
8022
8023 -- Note: this is a configuration pragma, but it is allowed to appear
8024 -- anywhere else.
8025
8026 when Pragma_Check_Policy =>
8027 GNAT_Pragma;
8028 Check_Arg_Count (2);
8029 Check_Optional_Identifier (Arg1, Name_Name);
8030 Check_Optional_Identifier (Arg2, Name_Policy);
8031 Check_Arg_Is_One_Of
8032 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
8033
8034 -- A Check_Policy pragma can appear either as a configuration
8035 -- pragma, or in a declarative part or a package spec (see RM
8036 -- 11.5(5) for rules for Suppress/Unsuppress which are also
8037 -- followed for Check_Policy).
8038
8039 if not Is_Configuration_Pragma then
8040 Check_Is_In_Decl_Part_Or_Package_Spec;
8041 end if;
8042
8043 Set_Next_Pragma (N, Opt.Check_Policy_List);
8044 Opt.Check_Policy_List := N;
8045
8046 ---------------------
8047 -- CIL_Constructor --
8048 ---------------------
8049
8050 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
8051
8052 -- Processing for this pragma is shared with Java_Constructor
8053
8054 -------------
8055 -- Comment --
8056 -------------
8057
8058 -- pragma Comment (static_string_EXPRESSION)
8059
8060 -- Processing for pragma Comment shares the circuitry for pragma
8061 -- Ident. The only differences are that Ident enforces a limit of 31
8062 -- characters on its argument, and also enforces limitations on
8063 -- placement for DEC compatibility. Pragma Comment shares neither of
8064 -- these restrictions.
8065
8066 -------------------
8067 -- Common_Object --
8068 -------------------
8069
8070 -- pragma Common_Object (
8071 -- [Internal =>] LOCAL_NAME
8072 -- [, [External =>] EXTERNAL_SYMBOL]
8073 -- [, [Size =>] EXTERNAL_SYMBOL]);
8074
8075 -- Processing for this pragma is shared with Psect_Object
8076
8077 ------------------------
8078 -- Compile_Time_Error --
8079 ------------------------
8080
8081 -- pragma Compile_Time_Error
8082 -- (boolean_EXPRESSION, static_string_EXPRESSION);
8083
8084 when Pragma_Compile_Time_Error =>
8085 GNAT_Pragma;
8086 Process_Compile_Time_Warning_Or_Error;
8087
8088 --------------------------
8089 -- Compile_Time_Warning --
8090 --------------------------
8091
8092 -- pragma Compile_Time_Warning
8093 -- (boolean_EXPRESSION, static_string_EXPRESSION);
8094
8095 when Pragma_Compile_Time_Warning =>
8096 GNAT_Pragma;
8097 Process_Compile_Time_Warning_Or_Error;
8098
8099 -------------------
8100 -- Compiler_Unit --
8101 -------------------
8102
8103 when Pragma_Compiler_Unit =>
8104 GNAT_Pragma;
8105 Check_Arg_Count (0);
8106 Set_Is_Compiler_Unit (Get_Source_Unit (N));
8107
8108 -----------------------------
8109 -- Complete_Representation --
8110 -----------------------------
8111
8112 -- pragma Complete_Representation;
8113
8114 when Pragma_Complete_Representation =>
8115 GNAT_Pragma;
8116 Check_Arg_Count (0);
8117
8118 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
8119 Error_Pragma
8120 ("pragma & must appear within record representation clause");
8121 end if;
8122
8123 ----------------------------
8124 -- Complex_Representation --
8125 ----------------------------
8126
8127 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
8128
8129 when Pragma_Complex_Representation => Complex_Representation : declare
8130 E_Id : Entity_Id;
8131 E : Entity_Id;
8132 Ent : Entity_Id;
8133
8134 begin
8135 GNAT_Pragma;
8136 Check_Arg_Count (1);
8137 Check_Optional_Identifier (Arg1, Name_Entity);
8138 Check_Arg_Is_Local_Name (Arg1);
8139 E_Id := Get_Pragma_Arg (Arg1);
8140
8141 if Etype (E_Id) = Any_Type then
8142 return;
8143 end if;
8144
8145 E := Entity (E_Id);
8146
8147 if not Is_Record_Type (E) then
8148 Error_Pragma_Arg
8149 ("argument for pragma% must be record type", Arg1);
8150 end if;
8151
8152 Ent := First_Entity (E);
8153
8154 if No (Ent)
8155 or else No (Next_Entity (Ent))
8156 or else Present (Next_Entity (Next_Entity (Ent)))
8157 or else not Is_Floating_Point_Type (Etype (Ent))
8158 or else Etype (Ent) /= Etype (Next_Entity (Ent))
8159 then
8160 Error_Pragma_Arg
8161 ("record for pragma% must have two fields of the same "
8162 & "floating-point type", Arg1);
8163
8164 else
8165 Set_Has_Complex_Representation (Base_Type (E));
8166
8167 -- We need to treat the type has having a non-standard
8168 -- representation, for back-end purposes, even though in
8169 -- general a complex will have the default representation
8170 -- of a record with two real components.
8171
8172 Set_Has_Non_Standard_Rep (Base_Type (E));
8173 end if;
8174 end Complex_Representation;
8175
8176 -------------------------
8177 -- Component_Alignment --
8178 -------------------------
8179
8180 -- pragma Component_Alignment (
8181 -- [Form =>] ALIGNMENT_CHOICE
8182 -- [, [Name =>] type_LOCAL_NAME]);
8183 --
8184 -- ALIGNMENT_CHOICE ::=
8185 -- Component_Size
8186 -- | Component_Size_4
8187 -- | Storage_Unit
8188 -- | Default
8189
8190 when Pragma_Component_Alignment => Component_AlignmentP : declare
8191 Args : Args_List (1 .. 2);
8192 Names : constant Name_List (1 .. 2) := (
8193 Name_Form,
8194 Name_Name);
8195
8196 Form : Node_Id renames Args (1);
8197 Name : Node_Id renames Args (2);
8198
8199 Atype : Component_Alignment_Kind;
8200 Typ : Entity_Id;
8201
8202 begin
8203 GNAT_Pragma;
8204 Gather_Associations (Names, Args);
8205
8206 if No (Form) then
8207 Error_Pragma ("missing Form argument for pragma%");
8208 end if;
8209
8210 Check_Arg_Is_Identifier (Form);
8211
8212 -- Get proper alignment, note that Default = Component_Size on all
8213 -- machines we have so far, and we want to set this value rather
8214 -- than the default value to indicate that it has been explicitly
8215 -- set (and thus will not get overridden by the default component
8216 -- alignment for the current scope)
8217
8218 if Chars (Form) = Name_Component_Size then
8219 Atype := Calign_Component_Size;
8220
8221 elsif Chars (Form) = Name_Component_Size_4 then
8222 Atype := Calign_Component_Size_4;
8223
8224 elsif Chars (Form) = Name_Default then
8225 Atype := Calign_Component_Size;
8226
8227 elsif Chars (Form) = Name_Storage_Unit then
8228 Atype := Calign_Storage_Unit;
8229
8230 else
8231 Error_Pragma_Arg
8232 ("invalid Form parameter for pragma%", Form);
8233 end if;
8234
8235 -- Case with no name, supplied, affects scope table entry
8236
8237 if No (Name) then
8238 Scope_Stack.Table
8239 (Scope_Stack.Last).Component_Alignment_Default := Atype;
8240
8241 -- Case of name supplied
8242
8243 else
8244 Check_Arg_Is_Local_Name (Name);
8245 Find_Type (Name);
8246 Typ := Entity (Name);
8247
8248 if Typ = Any_Type
8249 or else Rep_Item_Too_Early (Typ, N)
8250 then
8251 return;
8252 else
8253 Typ := Underlying_Type (Typ);
8254 end if;
8255
8256 if not Is_Record_Type (Typ)
8257 and then not Is_Array_Type (Typ)
8258 then
8259 Error_Pragma_Arg
8260 ("Name parameter of pragma% must identify record or "
8261 & "array type", Name);
8262 end if;
8263
8264 -- An explicit Component_Alignment pragma overrides an
8265 -- implicit pragma Pack, but not an explicit one.
8266
8267 if not Has_Pragma_Pack (Base_Type (Typ)) then
8268 Set_Is_Packed (Base_Type (Typ), False);
8269 Set_Component_Alignment (Base_Type (Typ), Atype);
8270 end if;
8271 end if;
8272 end Component_AlignmentP;
8273
8274 -------------------
8275 -- Contract_Case --
8276 -------------------
8277
8278 -- pragma Contract_Case
8279 -- ([Name =>] Static_String_EXPRESSION
8280 -- ,[Mode =>] MODE_TYPE
8281 -- [, Requires => Boolean_EXPRESSION]
8282 -- [, Ensures => Boolean_EXPRESSION]);
8283
8284 -- MODE_TYPE ::= Nominal | Robustness
8285
8286 when Pragma_Contract_Case =>
8287 Check_Contract_Or_Test_Case;
8288
8289 --------------------
8290 -- Contract_Cases --
8291 --------------------
8292
8293 -- pragma Contract_Cases (CONTRACT_CASE_LIST);
8294
8295 -- CONTRACT_CASE_LIST ::= CONTRACT_CASE {, CONTRACT_CASE}
8296
8297 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
8298
8299 -- CASE_GUARD ::= boolean_EXPRESSION | others
8300
8301 -- CONSEQUENCE ::= boolean_EXPRESSION
8302
8303 when Pragma_Contract_Cases => Contract_Cases : declare
8304 procedure Chain_Contract_Cases (Subp_Decl : Node_Id);
8305 -- Chain pragma Contract_Cases to the contract of a subprogram.
8306 -- Subp_Decl is the declaration of the subprogram.
8307
8308 --------------------------
8309 -- Chain_Contract_Cases --
8310 --------------------------
8311
8312 procedure Chain_Contract_Cases (Subp_Decl : Node_Id) is
8313 Subp : constant Entity_Id :=
8314 Defining_Unit_Name (Specification (Subp_Decl));
8315 CTC : Node_Id;
8316
8317 begin
8318 Check_Duplicate_Pragma (Subp);
8319 CTC := Spec_CTC_List (Contract (Subp));
8320 while Present (CTC) loop
8321 if Chars (Pragma_Identifier (CTC)) = Pname then
8322 Error_Msg_Name_1 := Pname;
8323 Error_Msg_Sloc := Sloc (CTC);
8324
8325 if From_Aspect_Specification (CTC) then
8326 Error_Msg_NE
8327 ("aspect% for & previously given#", N, Subp);
8328 else
8329 Error_Msg_NE
8330 ("pragma% for & duplicates pragma#", N, Subp);
8331 end if;
8332
8333 raise Pragma_Exit;
8334 end if;
8335
8336 CTC := Next_Pragma (CTC);
8337 end loop;
8338
8339 -- Prepend pragma Contract_Cases to the contract
8340
8341 Set_Next_Pragma (N, Spec_CTC_List (Contract (Subp)));
8342 Set_Spec_CTC_List (Contract (Subp), N);
8343 end Chain_Contract_Cases;
8344
8345 -- Local variables
8346
8347 Case_Guard : Node_Id;
8348 Decl : Node_Id;
8349 Extra : Node_Id;
8350 Others_Seen : Boolean := False;
8351 Contract_Case : Node_Id;
8352 Subp_Decl : Node_Id;
8353
8354 -- Start of processing for Contract_Cases
8355
8356 begin
8357 GNAT_Pragma;
8358 S14_Pragma;
8359 Check_Arg_Count (1);
8360
8361 -- Completely ignore if disabled
8362
8363 if not Check_Enabled (Pname) then
8364 Rewrite (N, Make_Null_Statement (Loc));
8365 Analyze (N);
8366 return;
8367 end if;
8368
8369 -- Check the placement of the pragma
8370
8371 if not Is_List_Member (N) then
8372 Pragma_Misplaced;
8373 end if;
8374
8375 -- Pragma Contract_Cases must be associated with a subprogram
8376
8377 Decl := N;
8378 while Present (Prev (Decl)) loop
8379 Decl := Prev (Decl);
8380
8381 if Nkind (Decl) in N_Generic_Declaration then
8382 Subp_Decl := Decl;
8383 else
8384 Subp_Decl := Original_Node (Decl);
8385 end if;
8386
8387 -- Skip prior pragmas
8388
8389 if Nkind (Subp_Decl) = N_Pragma then
8390 null;
8391
8392 -- Skip internally generated code
8393
8394 elsif not Comes_From_Source (Subp_Decl) then
8395 null;
8396
8397 -- We have found the related subprogram
8398
8399 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
8400 N_Subprogram_Declaration)
8401 then
8402 exit;
8403
8404 else
8405 Pragma_Misplaced;
8406 end if;
8407 end loop;
8408
8409 -- All contract cases must appear as an aggregate
8410
8411 if Nkind (Expression (Arg1)) /= N_Aggregate then
8412 Error_Pragma ("wrong syntax for pragma %");
8413 return;
8414 end if;
8415
8416 -- Verify the legality of individual contract cases
8417
8418 Contract_Case :=
8419 First (Component_Associations (Expression (Arg1)));
8420 while Present (Contract_Case) loop
8421 if Nkind (Contract_Case) /= N_Component_Association then
8422 Error_Pragma_Arg
8423 ("wrong syntax in contract case", Contract_Case);
8424 return;
8425 end if;
8426
8427 Case_Guard := First (Choices (Contract_Case));
8428
8429 -- Each contract case must have exactly on case guard
8430
8431 Extra := Next (Case_Guard);
8432 if Present (Extra) then
8433 Error_Pragma_Arg
8434 ("contract case may have only one case guard", Extra);
8435 return;
8436 end if;
8437
8438 -- Check the placement of "others" (if available)
8439
8440 if Nkind (Case_Guard) = N_Others_Choice then
8441 if Others_Seen then
8442 Error_Pragma_Arg
8443 ("only one others choice allowed in pragma %",
8444 Case_Guard);
8445 return;
8446 else
8447 Others_Seen := True;
8448 end if;
8449
8450 elsif Others_Seen then
8451 Error_Pragma_Arg
8452 ("others must be the last choice in pragma %", N);
8453 return;
8454 end if;
8455
8456 Next (Contract_Case);
8457 end loop;
8458
8459 Chain_Contract_Cases (Subp_Decl);
8460 end Contract_Cases;
8461
8462 ----------------
8463 -- Controlled --
8464 ----------------
8465
8466 -- pragma Controlled (first_subtype_LOCAL_NAME);
8467
8468 when Pragma_Controlled => Controlled : declare
8469 Arg : Node_Id;
8470
8471 begin
8472 Check_No_Identifiers;
8473 Check_Arg_Count (1);
8474 Check_Arg_Is_Local_Name (Arg1);
8475 Arg := Get_Pragma_Arg (Arg1);
8476
8477 if not Is_Entity_Name (Arg)
8478 or else not Is_Access_Type (Entity (Arg))
8479 then
8480 Error_Pragma_Arg ("pragma% requires access type", Arg1);
8481 else
8482 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
8483 end if;
8484 end Controlled;
8485
8486 ----------------
8487 -- Convention --
8488 ----------------
8489
8490 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
8491 -- [Entity =>] LOCAL_NAME);
8492
8493 when Pragma_Convention => Convention : declare
8494 C : Convention_Id;
8495 E : Entity_Id;
8496 pragma Warnings (Off, C);
8497 pragma Warnings (Off, E);
8498 begin
8499 Check_Arg_Order ((Name_Convention, Name_Entity));
8500 Check_Ada_83_Warning;
8501 Check_Arg_Count (2);
8502 Process_Convention (C, E);
8503 end Convention;
8504
8505 ---------------------------
8506 -- Convention_Identifier --
8507 ---------------------------
8508
8509 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
8510 -- [Convention =>] convention_IDENTIFIER);
8511
8512 when Pragma_Convention_Identifier => Convention_Identifier : declare
8513 Idnam : Name_Id;
8514 Cname : Name_Id;
8515
8516 begin
8517 GNAT_Pragma;
8518 Check_Arg_Order ((Name_Name, Name_Convention));
8519 Check_Arg_Count (2);
8520 Check_Optional_Identifier (Arg1, Name_Name);
8521 Check_Optional_Identifier (Arg2, Name_Convention);
8522 Check_Arg_Is_Identifier (Arg1);
8523 Check_Arg_Is_Identifier (Arg2);
8524 Idnam := Chars (Get_Pragma_Arg (Arg1));
8525 Cname := Chars (Get_Pragma_Arg (Arg2));
8526
8527 if Is_Convention_Name (Cname) then
8528 Record_Convention_Identifier
8529 (Idnam, Get_Convention_Id (Cname));
8530 else
8531 Error_Pragma_Arg
8532 ("second arg for % pragma must be convention", Arg2);
8533 end if;
8534 end Convention_Identifier;
8535
8536 ---------------
8537 -- CPP_Class --
8538 ---------------
8539
8540 -- pragma CPP_Class ([Entity =>] local_NAME)
8541
8542 when Pragma_CPP_Class => CPP_Class : declare
8543 begin
8544 GNAT_Pragma;
8545
8546 if Warn_On_Obsolescent_Feature then
8547 Error_Msg_N
8548 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
8549 & "effect; replace it by pragma import?j?", N);
8550 end if;
8551
8552 Check_Arg_Count (1);
8553
8554 Rewrite (N,
8555 Make_Pragma (Loc,
8556 Chars => Name_Import,
8557 Pragma_Argument_Associations => New_List (
8558 Make_Pragma_Argument_Association (Loc,
8559 Expression => Make_Identifier (Loc, Name_CPP)),
8560 New_Copy (First (Pragma_Argument_Associations (N))))));
8561 Analyze (N);
8562 end CPP_Class;
8563
8564 ---------------------
8565 -- CPP_Constructor --
8566 ---------------------
8567
8568 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
8569 -- [, [External_Name =>] static_string_EXPRESSION ]
8570 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8571
8572 when Pragma_CPP_Constructor => CPP_Constructor : declare
8573 Elmt : Elmt_Id;
8574 Id : Entity_Id;
8575 Def_Id : Entity_Id;
8576 Tag_Typ : Entity_Id;
8577
8578 begin
8579 GNAT_Pragma;
8580 Check_At_Least_N_Arguments (1);
8581 Check_At_Most_N_Arguments (3);
8582 Check_Optional_Identifier (Arg1, Name_Entity);
8583 Check_Arg_Is_Local_Name (Arg1);
8584
8585 Id := Get_Pragma_Arg (Arg1);
8586 Find_Program_Unit_Name (Id);
8587
8588 -- If we did not find the name, we are done
8589
8590 if Etype (Id) = Any_Type then
8591 return;
8592 end if;
8593
8594 Def_Id := Entity (Id);
8595
8596 -- Check if already defined as constructor
8597
8598 if Is_Constructor (Def_Id) then
8599 Error_Msg_N
8600 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
8601 return;
8602 end if;
8603
8604 if Ekind (Def_Id) = E_Function
8605 and then (Is_CPP_Class (Etype (Def_Id))
8606 or else (Is_Class_Wide_Type (Etype (Def_Id))
8607 and then
8608 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
8609 then
8610 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
8611 Error_Msg_N
8612 ("'C'P'P constructor must be defined in the scope of "
8613 & "its returned type", Arg1);
8614 end if;
8615
8616 if Arg_Count >= 2 then
8617 Set_Imported (Def_Id);
8618 Set_Is_Public (Def_Id);
8619 Process_Interface_Name (Def_Id, Arg2, Arg3);
8620 end if;
8621
8622 Set_Has_Completion (Def_Id);
8623 Set_Is_Constructor (Def_Id);
8624 Set_Convention (Def_Id, Convention_CPP);
8625
8626 -- Imported C++ constructors are not dispatching primitives
8627 -- because in C++ they don't have a dispatch table slot.
8628 -- However, in Ada the constructor has the profile of a
8629 -- function that returns a tagged type and therefore it has
8630 -- been treated as a primitive operation during semantic
8631 -- analysis. We now remove it from the list of primitive
8632 -- operations of the type.
8633
8634 if Is_Tagged_Type (Etype (Def_Id))
8635 and then not Is_Class_Wide_Type (Etype (Def_Id))
8636 and then Is_Dispatching_Operation (Def_Id)
8637 then
8638 Tag_Typ := Etype (Def_Id);
8639
8640 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
8641 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
8642 Next_Elmt (Elmt);
8643 end loop;
8644
8645 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
8646 Set_Is_Dispatching_Operation (Def_Id, False);
8647 end if;
8648
8649 -- For backward compatibility, if the constructor returns a
8650 -- class wide type, and we internally change the return type to
8651 -- the corresponding root type.
8652
8653 if Is_Class_Wide_Type (Etype (Def_Id)) then
8654 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
8655 end if;
8656 else
8657 Error_Pragma_Arg
8658 ("pragma% requires function returning a 'C'P'P_Class type",
8659 Arg1);
8660 end if;
8661 end CPP_Constructor;
8662
8663 -----------------
8664 -- CPP_Virtual --
8665 -----------------
8666
8667 when Pragma_CPP_Virtual => CPP_Virtual : declare
8668 begin
8669 GNAT_Pragma;
8670
8671 if Warn_On_Obsolescent_Feature then
8672 Error_Msg_N
8673 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has no "
8674 & "effect?j?", N);
8675 end if;
8676 end CPP_Virtual;
8677
8678 ----------------
8679 -- CPP_Vtable --
8680 ----------------
8681
8682 when Pragma_CPP_Vtable => CPP_Vtable : declare
8683 begin
8684 GNAT_Pragma;
8685
8686 if Warn_On_Obsolescent_Feature then
8687 Error_Msg_N
8688 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has no "
8689 & "effect?j?", N);
8690 end if;
8691 end CPP_Vtable;
8692
8693 ---------
8694 -- CPU --
8695 ---------
8696
8697 -- pragma CPU (EXPRESSION);
8698
8699 when Pragma_CPU => CPU : declare
8700 P : constant Node_Id := Parent (N);
8701 Arg : Node_Id;
8702 Ent : Entity_Id;
8703
8704 begin
8705 Ada_2012_Pragma;
8706 Check_No_Identifiers;
8707 Check_Arg_Count (1);
8708
8709 -- Subprogram case
8710
8711 if Nkind (P) = N_Subprogram_Body then
8712 Check_In_Main_Program;
8713
8714 Arg := Get_Pragma_Arg (Arg1);
8715 Analyze_And_Resolve (Arg, Any_Integer);
8716
8717 Ent := Defining_Unit_Name (Specification (P));
8718
8719 if Nkind (Ent) = N_Defining_Program_Unit_Name then
8720 Ent := Defining_Identifier (Ent);
8721 end if;
8722
8723 -- Must be static
8724
8725 if not Is_Static_Expression (Arg) then
8726 Flag_Non_Static_Expr
8727 ("main subprogram affinity is not static!", Arg);
8728 raise Pragma_Exit;
8729
8730 -- If constraint error, then we already signalled an error
8731
8732 elsif Raises_Constraint_Error (Arg) then
8733 null;
8734
8735 -- Otherwise check in range
8736
8737 else
8738 declare
8739 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
8740 -- This is the entity System.Multiprocessors.CPU_Range;
8741
8742 Val : constant Uint := Expr_Value (Arg);
8743
8744 begin
8745 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
8746 or else
8747 Val > Expr_Value (Type_High_Bound (CPU_Id))
8748 then
8749 Error_Pragma_Arg
8750 ("main subprogram CPU is out of range", Arg1);
8751 end if;
8752 end;
8753 end if;
8754
8755 Set_Main_CPU
8756 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8757
8758 -- Task case
8759
8760 elsif Nkind (P) = N_Task_Definition then
8761 Arg := Get_Pragma_Arg (Arg1);
8762 Ent := Defining_Identifier (Parent (P));
8763
8764 -- The expression must be analyzed in the special manner
8765 -- described in "Handling of Default and Per-Object
8766 -- Expressions" in sem.ads.
8767
8768 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
8769
8770 -- Anything else is incorrect
8771
8772 else
8773 Pragma_Misplaced;
8774 end if;
8775
8776 -- Check duplicate pragma before we chain the pragma in the Rep
8777 -- Item chain of Ent.
8778
8779 Check_Duplicate_Pragma (Ent);
8780 Record_Rep_Item (Ent, N);
8781 end CPU;
8782
8783 -----------
8784 -- Debug --
8785 -----------
8786
8787 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
8788
8789 when Pragma_Debug => Debug : declare
8790 Cond : Node_Id;
8791 Call : Node_Id;
8792
8793 begin
8794 GNAT_Pragma;
8795
8796 -- Skip analysis if disabled
8797
8798 if Debug_Pragmas_Disabled then
8799 Rewrite (N, Make_Null_Statement (Loc));
8800 Analyze (N);
8801 return;
8802 end if;
8803
8804 Cond :=
8805 New_Occurrence_Of
8806 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
8807 Loc);
8808
8809 if Debug_Pragmas_Enabled then
8810 Set_SCO_Pragma_Enabled (Loc);
8811 end if;
8812
8813 if Arg_Count = 2 then
8814 Cond :=
8815 Make_And_Then (Loc,
8816 Left_Opnd => Relocate_Node (Cond),
8817 Right_Opnd => Get_Pragma_Arg (Arg1));
8818 Call := Get_Pragma_Arg (Arg2);
8819 else
8820 Call := Get_Pragma_Arg (Arg1);
8821 end if;
8822
8823 if Nkind_In (Call,
8824 N_Indexed_Component,
8825 N_Function_Call,
8826 N_Identifier,
8827 N_Expanded_Name,
8828 N_Selected_Component)
8829 then
8830 -- If this pragma Debug comes from source, its argument was
8831 -- parsed as a name form (which is syntactically identical).
8832 -- In a generic context a parameterless call will be left as
8833 -- an expanded name (if global) or selected_component if local.
8834 -- Change it to a procedure call statement now.
8835
8836 Change_Name_To_Procedure_Call_Statement (Call);
8837
8838 elsif Nkind (Call) = N_Procedure_Call_Statement then
8839
8840 -- Already in the form of a procedure call statement: nothing
8841 -- to do (could happen in case of an internally generated
8842 -- pragma Debug).
8843
8844 null;
8845
8846 else
8847 -- All other cases: diagnose error
8848
8849 Error_Msg
8850 ("argument of pragma ""Debug"" is not procedure call",
8851 Sloc (Call));
8852 return;
8853 end if;
8854
8855 -- Rewrite into a conditional with an appropriate condition. We
8856 -- wrap the procedure call in a block so that overhead from e.g.
8857 -- use of the secondary stack does not generate execution overhead
8858 -- for suppressed conditions.
8859
8860 -- Normally the analysis that follows will freeze the subprogram
8861 -- being called. However, if the call is to a null procedure,
8862 -- we want to freeze it before creating the block, because the
8863 -- analysis that follows may be done with expansion disabled, in
8864 -- which case the body will not be generated, leading to spurious
8865 -- errors.
8866
8867 if Nkind (Call) = N_Procedure_Call_Statement
8868 and then Is_Entity_Name (Name (Call))
8869 then
8870 Analyze (Name (Call));
8871 Freeze_Before (N, Entity (Name (Call)));
8872 end if;
8873
8874 Rewrite (N, Make_Implicit_If_Statement (N,
8875 Condition => Cond,
8876 Then_Statements => New_List (
8877 Make_Block_Statement (Loc,
8878 Handled_Statement_Sequence =>
8879 Make_Handled_Sequence_Of_Statements (Loc,
8880 Statements => New_List (Relocate_Node (Call)))))));
8881 Analyze (N);
8882 end Debug;
8883
8884 ------------------
8885 -- Debug_Policy --
8886 ------------------
8887
8888 -- pragma Debug_Policy (Check | Ignore)
8889
8890 when Pragma_Debug_Policy =>
8891 GNAT_Pragma;
8892 Check_Arg_Count (1);
8893 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
8894 Debug_Pragmas_Enabled :=
8895 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
8896 Debug_Pragmas_Disabled :=
8897 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
8898
8899 -------------
8900 -- Depends --
8901 -------------
8902
8903 -- pragma Depends (DEPENDENCY_RELATION);
8904
8905 -- DEPENDENCY_RELATION ::=
8906 -- null
8907 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
8908
8909 -- DEPENDENCY_CLAUSE ::= OUTPUT_LIST =>[+] INPUT_LIST
8910
8911 -- OUTPUT_LIST ::= null | OUTPUT | (OUTPUT {, OUTPUT})
8912
8913 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
8914
8915 -- OUTPUT ::= NAME | FUNCTION_RESULT
8916 -- INPUT ::= NAME
8917
8918 -- where FUNCTION_RESULT is a function Result attribute_reference
8919
8920 when Pragma_Depends => Depends : declare
8921 All_Inputs_Seen : Elist_Id := No_Elist;
8922 -- A list containing the entities of all the inputs processed so
8923 -- far. This Elist is populated with unique entities because the
8924 -- same input may appear in multiple input lists.
8925
8926 Global_Seen : Boolean := False;
8927 -- A flag set when pragma Global has been processed
8928
8929 Outputs_Seen : Elist_Id := No_Elist;
8930 -- A list containing the entities of all the outputs processed so
8931 -- far. The elements of this list may come from different output
8932 -- lists.
8933
8934 Null_Output_Seen : Boolean := False;
8935 -- A flag used to track the legality of a null output
8936
8937 Result_Seen : Boolean := False;
8938 -- A flag set when Subp_Id'Result is processed
8939
8940 Subp_Id : Entity_Id;
8941 -- The entity of the subprogram subject to pragma Depends
8942
8943 Subp_Inputs : Elist_Id := No_Elist;
8944 Subp_Outputs : Elist_Id := No_Elist;
8945 -- Two lists containing the full set of inputs and output of the
8946 -- related subprograms. Note that these lists contain both nodes
8947 -- and entities.
8948
8949 procedure Analyze_Dependency_Clause
8950 (Clause : Node_Id;
8951 Is_Last : Boolean);
8952 -- Verify the legality of a single dependency clause. Flag Is_Last
8953 -- denotes whether Clause is the last clause in the relation.
8954
8955 function Appears_In
8956 (List : Elist_Id;
8957 Item_Id : Entity_Id) return Boolean;
8958 -- Determine whether a particular item appears in a mixed list of
8959 -- nodes and entities.
8960
8961 procedure Check_Function_Return;
8962 -- Verify that Funtion'Result appears as one of the outputs
8963
8964 procedure Check_Mode
8965 (Item : Node_Id;
8966 Item_Id : Entity_Id;
8967 Is_Input : Boolean);
8968 -- Ensure that an item has a proper "in", "in out" or "out" mode
8969 -- depending on its function. If this is not the case, emit an
8970 -- error.
8971
8972 procedure Check_Usage
8973 (Subp_List : Elist_Id;
8974 Item_List : Elist_Id;
8975 Is_Input : Boolean);
8976 -- Verify that all items from list Subp_List appear in Item_List.
8977 -- Emit an error if this is not the case.
8978
8979 procedure Collect_Subprogram_Inputs_Outputs;
8980 -- Gather all inputs and outputs of the subprogram. These are the
8981 -- formal parameters and entities classified in pragma Global.
8982
8983 procedure Normalize_Clause (Clause : Node_Id);
8984 -- Remove a self-dependency "+" from the input list of a clause.
8985 -- Depending on the contents of the relation, either split the
8986 -- the clause into multiple smaller clauses or perform the
8987 -- normalization in place.
8988
8989 -------------------------------
8990 -- Analyze_Dependency_Clause --
8991 -------------------------------
8992
8993 procedure Analyze_Dependency_Clause
8994 (Clause : Node_Id;
8995 Is_Last : Boolean)
8996 is
8997 procedure Analyze_Input_List (Inputs : Node_Id);
8998 -- Verify the legality of a single input list
8999
9000 procedure Analyze_Input_Output
9001 (Item : Node_Id;
9002 Is_Input : Boolean;
9003 Top_Level : Boolean;
9004 Seen : in out Elist_Id;
9005 Null_Seen : in out Boolean);
9006 -- Verify the legality of a single input or output item. Flag
9007 -- Is_Input should be set whenever Item is an input, False when
9008 -- it denotes an output. Flag Top_Level should be set whenever
9009 -- Item appears immediately within an input or output list.
9010 -- Seen is a collection of all abstract states, variables and
9011 -- formals processed so far. Flag Null_Seen denotes whether a
9012 -- null input or output has been encountered.
9013
9014 ------------------------
9015 -- Analyze_Input_List --
9016 ------------------------
9017
9018 procedure Analyze_Input_List (Inputs : Node_Id) is
9019 Inputs_Seen : Elist_Id := No_Elist;
9020 -- A list containing the entities of all inputs that appear
9021 -- in the current input list.
9022
9023 Null_Input_Seen : Boolean := False;
9024 -- A flag used to track the legality of a null input
9025
9026 Input : Node_Id;
9027
9028 begin
9029 -- Multiple inputs appear as an aggregate
9030
9031 if Nkind (Inputs) = N_Aggregate then
9032 if Present (Component_Associations (Inputs)) then
9033 Error_Msg_N
9034 ("nested dependency relations not allowed", Inputs);
9035
9036 elsif Present (Expressions (Inputs)) then
9037 Input := First (Expressions (Inputs));
9038 while Present (Input) loop
9039 Analyze_Input_Output
9040 (Item => Input,
9041 Is_Input => True,
9042 Top_Level => False,
9043 Seen => Inputs_Seen,
9044 Null_Seen => Null_Input_Seen);
9045
9046 Next (Input);
9047 end loop;
9048
9049 else
9050 Error_Msg_N
9051 ("malformed input dependency list", Inputs);
9052 end if;
9053
9054 -- Process a solitary input
9055
9056 else
9057 Analyze_Input_Output
9058 (Item => Inputs,
9059 Is_Input => True,
9060 Top_Level => False,
9061 Seen => Inputs_Seen,
9062 Null_Seen => Null_Input_Seen);
9063 end if;
9064 end Analyze_Input_List;
9065
9066 --------------------------
9067 -- Analyze_Input_Output --
9068 --------------------------
9069
9070 procedure Analyze_Input_Output
9071 (Item : Node_Id;
9072 Is_Input : Boolean;
9073 Top_Level : Boolean;
9074 Seen : in out Elist_Id;
9075 Null_Seen : in out Boolean)
9076 is
9077 Is_Output : constant Boolean := not Is_Input;
9078 Grouped : Node_Id;
9079 Item_Id : Entity_Id;
9080
9081 begin
9082 -- Multiple input or output items appear as an aggregate
9083
9084 if Nkind (Item) = N_Aggregate then
9085 if not Top_Level then
9086 Error_Msg_N
9087 ("nested grouping of items not allowed", Item);
9088
9089 elsif Present (Component_Associations (Item)) then
9090 Error_Msg_N
9091 ("nested dependency relations not allowed", Item);
9092
9093 -- Recursively analyze the grouped items
9094
9095 elsif Present (Expressions (Item)) then
9096 Grouped := First (Expressions (Item));
9097 while Present (Grouped) loop
9098 Analyze_Input_Output
9099 (Item => Grouped,
9100 Is_Input => Is_Input,
9101 Top_Level => False,
9102 Seen => Seen,
9103 Null_Seen => Null_Seen);
9104
9105 Next (Grouped);
9106 end loop;
9107
9108 else
9109 Error_Msg_N ("malformed dependency list", Item);
9110 end if;
9111
9112 -- Process Function'Result in the context of a dependency
9113 -- clause.
9114
9115 elsif Nkind (Item) = N_Attribute_Reference
9116 and then Attribute_Name (Item) = Name_Result
9117 then
9118 -- It is sufficent to analyze the prefix of 'Result in
9119 -- order to establish legality of the attribute.
9120
9121 Analyze (Prefix (Item));
9122
9123 -- The prefix of 'Result must denote the function for
9124 -- which aspect/pragma Depends applies.
9125
9126 if not Is_Entity_Name (Prefix (Item))
9127 or else Ekind (Subp_Id) /= E_Function
9128 or else Entity (Prefix (Item)) /= Subp_Id
9129 then
9130 Error_Msg_Name_1 := Name_Result;
9131 Error_Msg_N
9132 ("prefix of attribute % must denote the enclosing "
9133 & "function", Item);
9134
9135 -- Function'Result is allowed to appear on the output
9136 -- side of a dependency clause.
9137
9138 elsif Is_Input then
9139 Error_Msg_N
9140 ("function result cannot act as input", Item);
9141
9142 else
9143 Result_Seen := True;
9144 end if;
9145
9146 -- Detect multiple uses of null in a single dependency list
9147 -- or throughout the whole relation. Verify the placement of
9148 -- a null output list relative to the other clauses.
9149
9150 elsif Nkind (Item) = N_Null then
9151 if Null_Seen then
9152 Error_Msg_N
9153 ("multiple null dependency relations not allowed",
9154 Item);
9155 else
9156 Null_Seen := True;
9157
9158 if Is_Output and then not Is_Last then
9159 Error_Msg_N
9160 ("null output list must be the last clause in "
9161 & "a dependency relation", Item);
9162 end if;
9163 end if;
9164
9165 -- Default case
9166
9167 else
9168 Analyze (Item);
9169
9170 -- Find the entity of the item. If this is a renaming,
9171 -- climb the renaming chain to reach the root object.
9172 -- Renamings of non-entire objects do not yield an
9173 -- entity (Empty).
9174
9175 Item_Id := Entity_Of (Item);
9176
9177 if Present (Item_Id) then
9178 if Ekind_In (Item_Id, E_Abstract_State,
9179 E_In_Parameter,
9180 E_In_Out_Parameter,
9181 E_Out_Parameter,
9182 E_Variable)
9183 then
9184 -- Ensure that the item is of the correct mode
9185 -- depending on its function.
9186
9187 Check_Mode (Item, Item_Id, Is_Input);
9188
9189 -- Detect multiple uses of the same state, variable
9190 -- or formal parameter. If this is not the case,
9191 -- add the item to the list of processed relations.
9192
9193 if Contains (Seen, Item_Id) then
9194 Error_Msg_N ("duplicate use of item", Item);
9195 else
9196 Add_Item (Item_Id, Seen);
9197 end if;
9198
9199 -- Detect an illegal use of an input related to a
9200 -- null output. Such input items cannot appear in
9201 -- other input lists.
9202
9203 if Null_Output_Seen
9204 and then Contains (All_Inputs_Seen, Item_Id)
9205 then
9206 Error_Msg_N
9207 ("input of a null output list appears in "
9208 & "multiple input lists", Item);
9209 else
9210 Add_Item (Item_Id, All_Inputs_Seen);
9211 end if;
9212
9213 -- When the item renames an entire object, replace
9214 -- the item with a reference to the object.
9215
9216 if Present (Renamed_Object (Entity (Item))) then
9217 Rewrite (Item,
9218 New_Reference_To (Item_Id, Sloc (Item)));
9219 Analyze (Item);
9220 end if;
9221
9222 -- All other input/output items are illegal
9223
9224 else
9225 Error_Msg_N
9226 ("item must denote variable, state or formal "
9227 & "parameter", Item);
9228 end if;
9229
9230 -- All other input/output items are illegal
9231
9232 else
9233 Error_Msg_N
9234 ("item must denote variable, state or formal "
9235 & "parameter", Item);
9236 end if;
9237 end if;
9238 end Analyze_Input_Output;
9239
9240 -- Local variables
9241
9242 Inputs : Node_Id;
9243 Output : Node_Id;
9244
9245 -- Start of processing for Analyze_Dependency_Clause
9246
9247 begin
9248 -- Process the output_list of a dependency_clause
9249
9250 Output := First (Choices (Clause));
9251 while Present (Output) loop
9252 Analyze_Input_Output
9253 (Item => Output,
9254 Is_Input => False,
9255 Top_Level => True,
9256 Seen => Outputs_Seen,
9257 Null_Seen => Null_Output_Seen);
9258
9259 Next (Output);
9260 end loop;
9261
9262 -- Process the input_list of a dependency_clause
9263
9264 Inputs := Expression (Clause);
9265
9266 -- An input list with a self-dependency appears as operator "+"
9267 -- where the actuals inputs are the right operand.
9268
9269 if Nkind (Inputs) = N_Op_Plus then
9270 Inputs := Right_Opnd (Inputs);
9271 end if;
9272
9273 Analyze_Input_List (Inputs);
9274 end Analyze_Dependency_Clause;
9275
9276 ----------------
9277 -- Appears_In --
9278 ----------------
9279
9280 function Appears_In
9281 (List : Elist_Id;
9282 Item_Id : Entity_Id) return Boolean
9283 is
9284 Elmt : Elmt_Id;
9285 Id : Entity_Id;
9286
9287 begin
9288 if Present (List) then
9289 Elmt := First_Elmt (List);
9290 while Present (Elmt) loop
9291 if Nkind (Node (Elmt)) = N_Defining_Identifier then
9292 Id := Node (Elmt);
9293 else
9294 Id := Entity (Node (Elmt));
9295 end if;
9296
9297 if Id = Item_Id then
9298 return True;
9299 end if;
9300
9301 Next_Elmt (Elmt);
9302 end loop;
9303 end if;
9304
9305 return False;
9306 end Appears_In;
9307
9308 ----------------------------
9309 -- Check_Function_Return --
9310 ----------------------------
9311
9312 procedure Check_Function_Return is
9313 begin
9314 if Ekind (Subp_Id) = E_Function and then not Result_Seen then
9315 Error_Msg_NE
9316 ("result of & must appear in exactly one output list",
9317 N, Subp_Id);
9318 end if;
9319 end Check_Function_Return;
9320
9321 ----------------
9322 -- Check_Mode --
9323 ----------------
9324
9325 procedure Check_Mode
9326 (Item : Node_Id;
9327 Item_Id : Entity_Id;
9328 Is_Input : Boolean)
9329 is
9330 begin
9331 if Is_Input then
9332 if Ekind (Item_Id) = E_Out_Parameter
9333 or else (Global_Seen
9334 and then not Appears_In (Subp_Inputs, Item_Id))
9335 then
9336 Error_Msg_NE
9337 ("item & must have mode in or in out", Item, Item_Id);
9338 end if;
9339
9340 -- Output
9341
9342 else
9343 if Ekind (Item_Id) = E_In_Parameter
9344 or else
9345 (Global_Seen
9346 and then not Appears_In (Subp_Outputs, Item_Id))
9347 then
9348 Error_Msg_NE
9349 ("item & must have mode out or in out", Item, Item_Id);
9350 end if;
9351 end if;
9352 end Check_Mode;
9353
9354 -----------------
9355 -- Check_Usage --
9356 -----------------
9357
9358 procedure Check_Usage
9359 (Subp_List : Elist_Id;
9360 Item_List : Elist_Id;
9361 Is_Input : Boolean)
9362 is
9363 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id);
9364 -- Emit an error concerning the erroneous usage of an item
9365
9366 -----------------
9367 -- Usage_Error --
9368 -----------------
9369
9370 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id) is
9371 begin
9372 if Is_Input then
9373 Error_Msg_NE
9374 ("item & must appear in at least one input list of "
9375 & "aspect Depends", Item, Item_Id);
9376 else
9377 Error_Msg_NE
9378 ("item & must appear in exactly one output list of "
9379 & "aspect Depends", Item, Item_Id);
9380 end if;
9381 end Usage_Error;
9382
9383 -- Local variables
9384
9385 Elmt : Elmt_Id;
9386 Item : Node_Id;
9387 Item_Id : Entity_Id;
9388
9389 -- Start of processing for Check_Usage
9390
9391 begin
9392 if No (Subp_List) then
9393 return;
9394 end if;
9395
9396 -- Each input or output of the subprogram must appear in a
9397 -- dependency relation.
9398
9399 Elmt := First_Elmt (Subp_List);
9400 while Present (Elmt) loop
9401 Item := Node (Elmt);
9402
9403 if Nkind (Item) = N_Defining_Identifier then
9404 Item_Id := Item;
9405 else
9406 Item_Id := Entity (Item);
9407 end if;
9408
9409 -- The item does not appear in a dependency
9410
9411 if not Contains (Item_List, Item_Id) then
9412 if Is_Formal (Item_Id) then
9413 Usage_Error (Item, Item_Id);
9414
9415 -- States and global variables are not used properly only
9416 -- when the subprogram is subject to pragma Global.
9417
9418 elsif Global_Seen then
9419 Usage_Error (Item, Item_Id);
9420 end if;
9421 end if;
9422
9423 Next_Elmt (Elmt);
9424 end loop;
9425 end Check_Usage;
9426
9427 ---------------------------------------
9428 -- Collect_Subprogram_Inputs_Outputs --
9429 ---------------------------------------
9430
9431 procedure Collect_Subprogram_Inputs_Outputs is
9432 procedure Collect_Global_List
9433 (List : Node_Id;
9434 Mode : Name_Id := Name_Input);
9435 -- Collect all relevant items from a global list
9436
9437 -------------------------
9438 -- Collect_Global_List --
9439 -------------------------
9440
9441 procedure Collect_Global_List
9442 (List : Node_Id;
9443 Mode : Name_Id := Name_Input)
9444 is
9445 procedure Collect_Global_Item
9446 (Item : Node_Id;
9447 Mode : Name_Id);
9448 -- Add an item to the proper subprogram input or output
9449 -- collection.
9450
9451 -------------------------
9452 -- Collect_Global_Item --
9453 -------------------------
9454
9455 procedure Collect_Global_Item
9456 (Item : Node_Id;
9457 Mode : Name_Id)
9458 is
9459 begin
9460 if Mode = Name_In_Out or else Mode = Name_Input then
9461 Add_Item (Item, Subp_Inputs);
9462 end if;
9463
9464 if Mode = Name_In_Out or else Mode = Name_Output then
9465 Add_Item (Item, Subp_Outputs);
9466 end if;
9467 end Collect_Global_Item;
9468
9469 -- Local variables
9470
9471 Assoc : Node_Id;
9472 Item : Node_Id;
9473
9474 -- Start of processing for Collect_Global_List
9475
9476 begin
9477 -- Single global item declaration
9478
9479 if Nkind_In (List, N_Identifier, N_Selected_Component) then
9480 Collect_Global_Item (List, Mode);
9481
9482 -- Simple global list or moded global list declaration
9483
9484 else
9485 if Present (Expressions (List)) then
9486 Item := First (Expressions (List));
9487 while Present (Item) loop
9488 Collect_Global_Item (Item, Mode);
9489
9490 Next (Item);
9491 end loop;
9492
9493 else
9494 Assoc := First (Component_Associations (List));
9495 while Present (Assoc) loop
9496 Collect_Global_List
9497 (List => Expression (Assoc),
9498 Mode => Chars (First (Choices (Assoc))));
9499
9500 Next (Assoc);
9501 end loop;
9502 end if;
9503 end if;
9504 end Collect_Global_List;
9505
9506 -- Local variables
9507
9508 Formal : Entity_Id;
9509 Global : Node_Id;
9510 List : Node_Id;
9511
9512 -- Start of processing for Collect_Subprogram_Inputs_Outputs
9513
9514 begin
9515 -- Process all formal parameters
9516
9517 Formal := First_Formal (Subp_Id);
9518 while Present (Formal) loop
9519 if Ekind_In (Formal, E_In_Out_Parameter,
9520 E_In_Parameter)
9521 then
9522 Add_Item (Formal, Subp_Inputs);
9523 end if;
9524
9525 if Ekind_In (Formal, E_In_Out_Parameter,
9526 E_Out_Parameter)
9527 then
9528 Add_Item (Formal, Subp_Outputs);
9529 end if;
9530
9531 Next_Formal (Formal);
9532 end loop;
9533
9534 -- If the subprogram is subject to pragma Global, traverse all
9535 -- global lists and gather the relevant items.
9536
9537 Global := Find_Aspect (Subp_Id, Aspect_Global);
9538 if Present (Global) then
9539 Global_Seen := True;
9540
9541 -- Retrieve the pragma as it contains the analyzed lists
9542
9543 Global := Aspect_Rep_Item (Parent (Global));
9544
9545 -- The pragma may not have been analyzed because of the
9546 -- arbitrary declaration order of aspects. Make sure that
9547 -- it is analyzed for the purposes of item extraction.
9548
9549 if not Analyzed (Global) then
9550 Analyze (Global);
9551 end if;
9552
9553 List :=
9554 Expression (First (Pragma_Argument_Associations (Global)));
9555
9556 -- Nothing to be done for a null global list
9557
9558 if Nkind (List) /= N_Null then
9559 Collect_Global_List (List);
9560 end if;
9561 end if;
9562 end Collect_Subprogram_Inputs_Outputs;
9563
9564 ----------------------
9565 -- Normalize_Clause --
9566 ----------------------
9567
9568 procedure Normalize_Clause (Clause : Node_Id) is
9569 procedure Create_Or_Modify_Clause
9570 (Output : Node_Id;
9571 Outputs : Node_Id;
9572 Inputs : Node_Id;
9573 After : Node_Id;
9574 In_Place : Boolean;
9575 Multiple : Boolean);
9576 -- Create a brand new clause to represent the self-reference
9577 -- or modify the input and/or output lists of an existing
9578 -- clause. Output denotes a self-referencial output. Outputs
9579 -- is the output list of a clause. Inputs is the input list
9580 -- of a clause. After denotes the clause after which the new
9581 -- clause is to be inserted. Flag In_Place should be set when
9582 -- normalizing the last output of an output list. Flag Multiple
9583 -- should be set when Output comes from a list with multiple
9584 -- items.
9585
9586 -----------------------------
9587 -- Create_Or_Modify_Clause --
9588 -----------------------------
9589
9590 procedure Create_Or_Modify_Clause
9591 (Output : Node_Id;
9592 Outputs : Node_Id;
9593 Inputs : Node_Id;
9594 After : Node_Id;
9595 In_Place : Boolean;
9596 Multiple : Boolean)
9597 is
9598 procedure Propagate_Output
9599 (Output : Node_Id;
9600 Inputs : Node_Id);
9601 -- Handle the various cases of output propagation to the
9602 -- input list. Output denotes a self-referencial output
9603 -- item. Inputs is the input list of a clause.
9604
9605 ----------------------
9606 -- Propagate_Output --
9607 ----------------------
9608
9609 procedure Propagate_Output
9610 (Output : Node_Id;
9611 Inputs : Node_Id)
9612 is
9613 function In_Input_List
9614 (Item : Entity_Id;
9615 Inputs : List_Id) return Boolean;
9616 -- Determine whether a particulat item appears in the
9617 -- input list of a clause.
9618
9619 -------------------
9620 -- In_Input_List --
9621 -------------------
9622
9623 function In_Input_List
9624 (Item : Entity_Id;
9625 Inputs : List_Id) return Boolean
9626 is
9627 Elmt : Node_Id;
9628
9629 begin
9630 Elmt := First (Inputs);
9631 while Present (Elmt) loop
9632 if Entity_Of (Elmt) = Item then
9633 return True;
9634 end if;
9635
9636 Next (Elmt);
9637 end loop;
9638
9639 return False;
9640 end In_Input_List;
9641
9642 -- Local variables
9643
9644 Output_Id : constant Entity_Id := Entity_Of (Output);
9645 Grouped : List_Id;
9646
9647 -- Start of processing for Propagate_Output
9648
9649 begin
9650 -- The clause is of the form:
9651
9652 -- (Output =>+ null)
9653
9654 -- Remove the null input and replace it with a copy of
9655 -- the output:
9656
9657 -- (Output => Output)
9658
9659 if Nkind (Inputs) = N_Null then
9660 Rewrite (Inputs, New_Copy_Tree (Output));
9661
9662 -- The clause is of the form:
9663
9664 -- (Output =>+ (Input1, ..., InputN))
9665
9666 -- Determine whether the output is not already mentioned
9667 -- in the input list and if not, add it to the list of
9668 -- inputs:
9669
9670 -- (Output => (Output, Input1, ..., InputN))
9671
9672 elsif Nkind (Inputs) = N_Aggregate then
9673 Grouped := Expressions (Inputs);
9674
9675 if not In_Input_List
9676 (Item => Output_Id,
9677 Inputs => Grouped)
9678 then
9679 Prepend_To (Grouped, New_Copy_Tree (Output));
9680 end if;
9681
9682 -- The clause is of the form:
9683
9684 -- (Output =>+ Input)
9685
9686 -- If the input does not mention the output, group the
9687 -- two together:
9688
9689 -- (Output => (Output, Input))
9690
9691 elsif Entity_Of (Inputs) /= Output_Id then
9692 Rewrite (Inputs,
9693 Make_Aggregate (Loc,
9694 Expressions => New_List (
9695 New_Copy_Tree (Output),
9696 New_Copy_Tree (Inputs))));
9697 end if;
9698 end Propagate_Output;
9699
9700 -- Local variables
9701
9702 Loc : constant Source_Ptr := Sloc (Output);
9703 Clause : Node_Id;
9704
9705 -- Start of processing for Create_Or_Modify_Clause
9706
9707 begin
9708 -- A function result cannot depend on itself because it
9709 -- cannot appear in the input list of a relation.
9710
9711 if Nkind (Output) = N_Attribute_Reference
9712 and then Attribute_Name (Output) = Name_Result
9713 then
9714 Error_Msg_N
9715 ("function result cannot depend on itself", Output);
9716 return;
9717
9718 -- A null output depending on itself does not require any
9719 -- normalization.
9720
9721 elsif Nkind (Output) = N_Null then
9722 return;
9723 end if;
9724
9725 -- When performing the transformation in place, simply add
9726 -- the output to the list of inputs (if not already there).
9727 -- This case arises when dealing with the last output of an
9728 -- output list - we perform the normalization in place to
9729 -- avoid generating a malformed tree.
9730
9731 if In_Place then
9732 Propagate_Output (Output, Inputs);
9733
9734 -- A list with multiple outputs is slowly trimmed until
9735 -- only one element remains. When this happens, replace
9736 -- the aggregate with the element itself.
9737
9738 if Multiple then
9739 Remove (Output);
9740 Rewrite (Outputs, Output);
9741 end if;
9742
9743 -- Default case
9744
9745 else
9746 -- Unchain the output from its output list as it will
9747 -- appear in a new clause. Note that we cannot simply
9748 -- rewrite the output as null because this will violate
9749 -- the semantics of aspect/pragma Depends.
9750
9751 Remove (Output);
9752
9753 -- Create a new clause of the form:
9754
9755 -- (Output => Inputs)
9756
9757 Clause :=
9758 Make_Component_Association (Loc,
9759 Choices => New_List (Output),
9760 Expression => New_Copy_Tree (Inputs));
9761
9762 -- The new clause contains replicated content that has
9763 -- already been analyzed. There is not need to reanalyze
9764 -- it or renormalize it again.
9765
9766 Set_Analyzed (Clause);
9767
9768 Propagate_Output
9769 (Output => First (Choices (Clause)),
9770 Inputs => Expression (Clause));
9771
9772 Insert_After (After, Clause);
9773 end if;
9774 end Create_Or_Modify_Clause;
9775
9776 -- Local variables
9777
9778 Outputs : constant Node_Id := First (Choices (Clause));
9779 Inputs : Node_Id;
9780 Last_Output : Node_Id;
9781 Next_Output : Node_Id;
9782 Output : Node_Id;
9783
9784 -- Start of processing for Normalize_Clause
9785
9786 begin
9787 -- A self-dependency appears as operator "+". Remove the "+"
9788 -- from the tree by moving the real inputs to their proper
9789 -- place.
9790
9791 if Nkind (Expression (Clause)) = N_Op_Plus then
9792 Rewrite
9793 (Expression (Clause), Right_Opnd (Expression (Clause)));
9794 Inputs := Expression (Clause);
9795
9796 -- Multiple outputs appear as an aggregate
9797
9798 if Nkind (Outputs) = N_Aggregate then
9799 Last_Output := Last (Expressions (Outputs));
9800
9801 Output := First (Expressions (Outputs));
9802 while Present (Output) loop
9803
9804 -- Normalization may remove an output from its list,
9805 -- preserve the subsequent output now.
9806
9807 Next_Output := Next (Output);
9808
9809 Create_Or_Modify_Clause
9810 (Output => Output,
9811 Outputs => Outputs,
9812 Inputs => Inputs,
9813 After => Clause,
9814 In_Place => Output = Last_Output,
9815 Multiple => True);
9816
9817 Output := Next_Output;
9818 end loop;
9819
9820 -- Solitary output
9821
9822 else
9823 Create_Or_Modify_Clause
9824 (Output => Outputs,
9825 Outputs => Empty,
9826 Inputs => Inputs,
9827 After => Empty,
9828 In_Place => True,
9829 Multiple => False);
9830 end if;
9831 end if;
9832 end Normalize_Clause;
9833
9834 -- Local variables
9835
9836 Clause : Node_Id;
9837 Errors : Nat;
9838 Last_Clause : Node_Id;
9839 Subp_Decl : Node_Id;
9840
9841 -- Start of processing for Depends
9842
9843 begin
9844 GNAT_Pragma;
9845 S14_Pragma;
9846 Check_Arg_Count (1);
9847
9848 -- Ensure the proper placement of the pragma. Depends must be
9849 -- associated with a subprogram declaration.
9850
9851 Subp_Decl := Parent (Corresponding_Aspect (N));
9852
9853 if Nkind (Subp_Decl) /= N_Subprogram_Declaration then
9854 Pragma_Misplaced;
9855 return;
9856 end if;
9857
9858 Subp_Id := Defining_Unit_Name (Specification (Subp_Decl));
9859 Clause := Expression (Arg1);
9860
9861 -- Empty dependency list
9862
9863 if Nkind (Clause) = N_Null then
9864
9865 -- Gather all states, variables and formal parameters that the
9866 -- subprogram may depend on. These items are obtained from the
9867 -- parameter profile or pragma Global (if available).
9868
9869 Collect_Subprogram_Inputs_Outputs;
9870
9871 -- Verify that every input or output of the subprogram appear
9872 -- in a dependency.
9873
9874 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
9875 Check_Usage (Subp_Outputs, Outputs_Seen, False);
9876 Check_Function_Return;
9877
9878 -- Dependency clauses appear as component associations of an
9879 -- aggregate.
9880
9881 elsif Nkind (Clause) = N_Aggregate
9882 and then Present (Component_Associations (Clause))
9883 then
9884 Last_Clause := Last (Component_Associations (Clause));
9885
9886 -- Gather all states, variables and formal parameters that the
9887 -- subprogram may depend on. These items are obtained from the
9888 -- parameter profile or pragma Global (if available).
9889
9890 Collect_Subprogram_Inputs_Outputs;
9891
9892 -- Ensure that the formal parameters are visible when analyzing
9893 -- all clauses. This falls out of the general rule of aspects
9894 -- pertaining to subprogram declarations.
9895
9896 Push_Scope (Subp_Id);
9897 Install_Formals (Subp_Id);
9898
9899 Clause := First (Component_Associations (Clause));
9900 while Present (Clause) loop
9901 Errors := Serious_Errors_Detected;
9902
9903 -- Normalization may create extra clauses that contain
9904 -- replicated input and output names. There is no need
9905 -- to reanalyze or renormalize these extra clauses.
9906
9907 if not Analyzed (Clause) then
9908 Set_Analyzed (Clause);
9909
9910 Analyze_Dependency_Clause
9911 (Clause => Clause,
9912 Is_Last => Clause = Last_Clause);
9913
9914 -- Do not normalize an erroneous clause because the
9915 -- inputs or outputs may denote illegal items.
9916
9917 if Errors = Serious_Errors_Detected then
9918 Normalize_Clause (Clause);
9919 end if;
9920 end if;
9921
9922 Next (Clause);
9923 end loop;
9924
9925 End_Scope;
9926
9927 -- Verify that every input or output of the subprogram appear
9928 -- in a dependency.
9929
9930 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
9931 Check_Usage (Subp_Outputs, Outputs_Seen, False);
9932 Check_Function_Return;
9933
9934 -- The top level dependency relation is malformed
9935
9936 else
9937 Error_Msg_N ("malformed dependency relation", Clause);
9938 end if;
9939 end Depends;
9940
9941 ---------------------
9942 -- Detect_Blocking --
9943 ---------------------
9944
9945 -- pragma Detect_Blocking;
9946
9947 when Pragma_Detect_Blocking =>
9948 Ada_2005_Pragma;
9949 Check_Arg_Count (0);
9950 Check_Valid_Configuration_Pragma;
9951 Detect_Blocking := True;
9952
9953 --------------------------
9954 -- Default_Storage_Pool --
9955 --------------------------
9956
9957 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
9958
9959 when Pragma_Default_Storage_Pool =>
9960 Ada_2012_Pragma;
9961 Check_Arg_Count (1);
9962
9963 -- Default_Storage_Pool can appear as a configuration pragma, or
9964 -- in a declarative part or a package spec.
9965
9966 if not Is_Configuration_Pragma then
9967 Check_Is_In_Decl_Part_Or_Package_Spec;
9968 end if;
9969
9970 -- Case of Default_Storage_Pool (null);
9971
9972 if Nkind (Expression (Arg1)) = N_Null then
9973 Analyze (Expression (Arg1));
9974
9975 -- This is an odd case, this is not really an expression, so
9976 -- we don't have a type for it. So just set the type to Empty.
9977
9978 Set_Etype (Expression (Arg1), Empty);
9979
9980 -- Case of Default_Storage_Pool (storage_pool_NAME);
9981
9982 else
9983 -- If it's a configuration pragma, then the only allowed
9984 -- argument is "null".
9985
9986 if Is_Configuration_Pragma then
9987 Error_Pragma_Arg ("NULL expected", Arg1);
9988 end if;
9989
9990 -- The expected type for a non-"null" argument is
9991 -- Root_Storage_Pool'Class.
9992
9993 Analyze_And_Resolve
9994 (Get_Pragma_Arg (Arg1),
9995 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
9996 end if;
9997
9998 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
9999 -- for an access type will use this information to set the
10000 -- appropriate attributes of the access type.
10001
10002 Default_Pool := Expression (Arg1);
10003
10004 ------------------------------------
10005 -- Disable_Atomic_Synchronization --
10006 ------------------------------------
10007
10008 -- pragma Disable_Atomic_Synchronization [(Entity)];
10009
10010 when Pragma_Disable_Atomic_Synchronization =>
10011 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
10012
10013 -------------------
10014 -- Discard_Names --
10015 -------------------
10016
10017 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
10018
10019 when Pragma_Discard_Names => Discard_Names : declare
10020 E : Entity_Id;
10021 E_Id : Entity_Id;
10022
10023 begin
10024 Check_Ada_83_Warning;
10025
10026 -- Deal with configuration pragma case
10027
10028 if Arg_Count = 0 and then Is_Configuration_Pragma then
10029 Global_Discard_Names := True;
10030 return;
10031
10032 -- Otherwise, check correct appropriate context
10033
10034 else
10035 Check_Is_In_Decl_Part_Or_Package_Spec;
10036
10037 if Arg_Count = 0 then
10038
10039 -- If there is no parameter, then from now on this pragma
10040 -- applies to any enumeration, exception or tagged type
10041 -- defined in the current declarative part, and recursively
10042 -- to any nested scope.
10043
10044 Set_Discard_Names (Current_Scope);
10045 return;
10046
10047 else
10048 Check_Arg_Count (1);
10049 Check_Optional_Identifier (Arg1, Name_On);
10050 Check_Arg_Is_Local_Name (Arg1);
10051
10052 E_Id := Get_Pragma_Arg (Arg1);
10053
10054 if Etype (E_Id) = Any_Type then
10055 return;
10056 else
10057 E := Entity (E_Id);
10058 end if;
10059
10060 if (Is_First_Subtype (E)
10061 and then
10062 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
10063 or else Ekind (E) = E_Exception
10064 then
10065 Set_Discard_Names (E);
10066 Record_Rep_Item (E, N);
10067
10068 else
10069 Error_Pragma_Arg
10070 ("inappropriate entity for pragma%", Arg1);
10071 end if;
10072
10073 end if;
10074 end if;
10075 end Discard_Names;
10076
10077 ------------------------
10078 -- Dispatching_Domain --
10079 ------------------------
10080
10081 -- pragma Dispatching_Domain (EXPRESSION);
10082
10083 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
10084 P : constant Node_Id := Parent (N);
10085 Arg : Node_Id;
10086 Ent : Entity_Id;
10087
10088 begin
10089 Ada_2012_Pragma;
10090 Check_No_Identifiers;
10091 Check_Arg_Count (1);
10092
10093 -- This pragma is born obsolete, but not the aspect
10094
10095 if not From_Aspect_Specification (N) then
10096 Check_Restriction
10097 (No_Obsolescent_Features, Pragma_Identifier (N));
10098 end if;
10099
10100 if Nkind (P) = N_Task_Definition then
10101 Arg := Get_Pragma_Arg (Arg1);
10102 Ent := Defining_Identifier (Parent (P));
10103
10104 -- The expression must be analyzed in the special manner
10105 -- described in "Handling of Default and Per-Object
10106 -- Expressions" in sem.ads.
10107
10108 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
10109
10110 -- Check duplicate pragma before we chain the pragma in the Rep
10111 -- Item chain of Ent.
10112
10113 Check_Duplicate_Pragma (Ent);
10114 Record_Rep_Item (Ent, N);
10115
10116 -- Anything else is incorrect
10117
10118 else
10119 Pragma_Misplaced;
10120 end if;
10121 end Dispatching_Domain;
10122
10123 ---------------
10124 -- Elaborate --
10125 ---------------
10126
10127 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
10128
10129 when Pragma_Elaborate => Elaborate : declare
10130 Arg : Node_Id;
10131 Citem : Node_Id;
10132
10133 begin
10134 -- Pragma must be in context items list of a compilation unit
10135
10136 if not Is_In_Context_Clause then
10137 Pragma_Misplaced;
10138 end if;
10139
10140 -- Must be at least one argument
10141
10142 if Arg_Count = 0 then
10143 Error_Pragma ("pragma% requires at least one argument");
10144 end if;
10145
10146 -- In Ada 83 mode, there can be no items following it in the
10147 -- context list except other pragmas and implicit with clauses
10148 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
10149 -- placement rule does not apply.
10150
10151 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
10152 Citem := Next (N);
10153 while Present (Citem) loop
10154 if Nkind (Citem) = N_Pragma
10155 or else (Nkind (Citem) = N_With_Clause
10156 and then Implicit_With (Citem))
10157 then
10158 null;
10159 else
10160 Error_Pragma
10161 ("(Ada 83) pragma% must be at end of context clause");
10162 end if;
10163
10164 Next (Citem);
10165 end loop;
10166 end if;
10167
10168 -- Finally, the arguments must all be units mentioned in a with
10169 -- clause in the same context clause. Note we already checked (in
10170 -- Par.Prag) that the arguments are all identifiers or selected
10171 -- components.
10172
10173 Arg := Arg1;
10174 Outer : while Present (Arg) loop
10175 Citem := First (List_Containing (N));
10176 Inner : while Citem /= N loop
10177 if Nkind (Citem) = N_With_Clause
10178 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
10179 then
10180 Set_Elaborate_Present (Citem, True);
10181 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
10182 Generate_Reference (Entity (Name (Citem)), Citem);
10183
10184 -- With the pragma present, elaboration calls on
10185 -- subprograms from the named unit need no further
10186 -- checks, as long as the pragma appears in the current
10187 -- compilation unit. If the pragma appears in some unit
10188 -- in the context, there might still be a need for an
10189 -- Elaborate_All_Desirable from the current compilation
10190 -- to the named unit, so we keep the check enabled.
10191
10192 if In_Extended_Main_Source_Unit (N) then
10193 Set_Suppress_Elaboration_Warnings
10194 (Entity (Name (Citem)));
10195 end if;
10196
10197 exit Inner;
10198 end if;
10199
10200 Next (Citem);
10201 end loop Inner;
10202
10203 if Citem = N then
10204 Error_Pragma_Arg
10205 ("argument of pragma% is not withed unit", Arg);
10206 end if;
10207
10208 Next (Arg);
10209 end loop Outer;
10210
10211 -- Give a warning if operating in static mode with -gnatwl
10212 -- (elaboration warnings enabled) switch set.
10213
10214 if Elab_Warnings and not Dynamic_Elaboration_Checks then
10215 Error_Msg_N
10216 ("?l?use of pragma Elaborate may not be safe", N);
10217 Error_Msg_N
10218 ("?l?use pragma Elaborate_All instead if possible", N);
10219 end if;
10220 end Elaborate;
10221
10222 -------------------
10223 -- Elaborate_All --
10224 -------------------
10225
10226 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
10227
10228 when Pragma_Elaborate_All => Elaborate_All : declare
10229 Arg : Node_Id;
10230 Citem : Node_Id;
10231
10232 begin
10233 Check_Ada_83_Warning;
10234
10235 -- Pragma must be in context items list of a compilation unit
10236
10237 if not Is_In_Context_Clause then
10238 Pragma_Misplaced;
10239 end if;
10240
10241 -- Must be at least one argument
10242
10243 if Arg_Count = 0 then
10244 Error_Pragma ("pragma% requires at least one argument");
10245 end if;
10246
10247 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
10248 -- have to appear at the end of the context clause, but may
10249 -- appear mixed in with other items, even in Ada 83 mode.
10250
10251 -- Final check: the arguments must all be units mentioned in
10252 -- a with clause in the same context clause. Note that we
10253 -- already checked (in Par.Prag) that all the arguments are
10254 -- either identifiers or selected components.
10255
10256 Arg := Arg1;
10257 Outr : while Present (Arg) loop
10258 Citem := First (List_Containing (N));
10259 Innr : while Citem /= N loop
10260 if Nkind (Citem) = N_With_Clause
10261 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
10262 then
10263 Set_Elaborate_All_Present (Citem, True);
10264 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
10265
10266 -- Suppress warnings and elaboration checks on the named
10267 -- unit if the pragma is in the current compilation, as
10268 -- for pragma Elaborate.
10269
10270 if In_Extended_Main_Source_Unit (N) then
10271 Set_Suppress_Elaboration_Warnings
10272 (Entity (Name (Citem)));
10273 end if;
10274 exit Innr;
10275 end if;
10276
10277 Next (Citem);
10278 end loop Innr;
10279
10280 if Citem = N then
10281 Set_Error_Posted (N);
10282 Error_Pragma_Arg
10283 ("argument of pragma% is not withed unit", Arg);
10284 end if;
10285
10286 Next (Arg);
10287 end loop Outr;
10288 end Elaborate_All;
10289
10290 --------------------
10291 -- Elaborate_Body --
10292 --------------------
10293
10294 -- pragma Elaborate_Body [( library_unit_NAME )];
10295
10296 when Pragma_Elaborate_Body => Elaborate_Body : declare
10297 Cunit_Node : Node_Id;
10298 Cunit_Ent : Entity_Id;
10299
10300 begin
10301 Check_Ada_83_Warning;
10302 Check_Valid_Library_Unit_Pragma;
10303
10304 if Nkind (N) = N_Null_Statement then
10305 return;
10306 end if;
10307
10308 Cunit_Node := Cunit (Current_Sem_Unit);
10309 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10310
10311 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
10312 N_Subprogram_Body)
10313 then
10314 Error_Pragma ("pragma% must refer to a spec, not a body");
10315 else
10316 Set_Body_Required (Cunit_Node, True);
10317 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
10318
10319 -- If we are in dynamic elaboration mode, then we suppress
10320 -- elaboration warnings for the unit, since it is definitely
10321 -- fine NOT to do dynamic checks at the first level (and such
10322 -- checks will be suppressed because no elaboration boolean
10323 -- is created for Elaborate_Body packages).
10324
10325 -- But in the static model of elaboration, Elaborate_Body is
10326 -- definitely NOT good enough to ensure elaboration safety on
10327 -- its own, since the body may WITH other units that are not
10328 -- safe from an elaboration point of view, so a client must
10329 -- still do an Elaborate_All on such units.
10330
10331 -- Debug flag -gnatdD restores the old behavior of 3.13, where
10332 -- Elaborate_Body always suppressed elab warnings.
10333
10334 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
10335 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
10336 end if;
10337 end if;
10338 end Elaborate_Body;
10339
10340 ------------------------
10341 -- Elaboration_Checks --
10342 ------------------------
10343
10344 -- pragma Elaboration_Checks (Static | Dynamic);
10345
10346 when Pragma_Elaboration_Checks =>
10347 GNAT_Pragma;
10348 Check_Arg_Count (1);
10349 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
10350 Dynamic_Elaboration_Checks :=
10351 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
10352
10353 ---------------
10354 -- Eliminate --
10355 ---------------
10356
10357 -- pragma Eliminate (
10358 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
10359 -- [,[Entity =>] IDENTIFIER |
10360 -- SELECTED_COMPONENT |
10361 -- STRING_LITERAL]
10362 -- [, OVERLOADING_RESOLUTION]);
10363
10364 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
10365 -- SOURCE_LOCATION
10366
10367 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
10368 -- FUNCTION_PROFILE
10369
10370 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
10371
10372 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
10373 -- Result_Type => result_SUBTYPE_NAME]
10374
10375 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
10376 -- SUBTYPE_NAME ::= STRING_LITERAL
10377
10378 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
10379 -- SOURCE_TRACE ::= STRING_LITERAL
10380
10381 when Pragma_Eliminate => Eliminate : declare
10382 Args : Args_List (1 .. 5);
10383 Names : constant Name_List (1 .. 5) := (
10384 Name_Unit_Name,
10385 Name_Entity,
10386 Name_Parameter_Types,
10387 Name_Result_Type,
10388 Name_Source_Location);
10389
10390 Unit_Name : Node_Id renames Args (1);
10391 Entity : Node_Id renames Args (2);
10392 Parameter_Types : Node_Id renames Args (3);
10393 Result_Type : Node_Id renames Args (4);
10394 Source_Location : Node_Id renames Args (5);
10395
10396 begin
10397 GNAT_Pragma;
10398 Check_Valid_Configuration_Pragma;
10399 Gather_Associations (Names, Args);
10400
10401 if No (Unit_Name) then
10402 Error_Pragma ("missing Unit_Name argument for pragma%");
10403 end if;
10404
10405 if No (Entity)
10406 and then (Present (Parameter_Types)
10407 or else
10408 Present (Result_Type)
10409 or else
10410 Present (Source_Location))
10411 then
10412 Error_Pragma ("missing Entity argument for pragma%");
10413 end if;
10414
10415 if (Present (Parameter_Types)
10416 or else
10417 Present (Result_Type))
10418 and then
10419 Present (Source_Location)
10420 then
10421 Error_Pragma
10422 ("parameter profile and source location cannot be used "
10423 & "together in pragma%");
10424 end if;
10425
10426 Process_Eliminate_Pragma
10427 (N,
10428 Unit_Name,
10429 Entity,
10430 Parameter_Types,
10431 Result_Type,
10432 Source_Location);
10433 end Eliminate;
10434
10435 -----------------------------------
10436 -- Enable_Atomic_Synchronization --
10437 -----------------------------------
10438
10439 -- pragma Enable_Atomic_Synchronization [(Entity)];
10440
10441 when Pragma_Enable_Atomic_Synchronization =>
10442 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
10443
10444 ------------
10445 -- Export --
10446 ------------
10447
10448 -- pragma Export (
10449 -- [ Convention =>] convention_IDENTIFIER,
10450 -- [ Entity =>] local_NAME
10451 -- [, [External_Name =>] static_string_EXPRESSION ]
10452 -- [, [Link_Name =>] static_string_EXPRESSION ]);
10453
10454 when Pragma_Export => Export : declare
10455 C : Convention_Id;
10456 Def_Id : Entity_Id;
10457
10458 pragma Warnings (Off, C);
10459
10460 begin
10461 Check_Ada_83_Warning;
10462 Check_Arg_Order
10463 ((Name_Convention,
10464 Name_Entity,
10465 Name_External_Name,
10466 Name_Link_Name));
10467
10468 Check_At_Least_N_Arguments (2);
10469
10470 Check_At_Most_N_Arguments (4);
10471 Process_Convention (C, Def_Id);
10472
10473 if Ekind (Def_Id) /= E_Constant then
10474 Note_Possible_Modification
10475 (Get_Pragma_Arg (Arg2), Sure => False);
10476 end if;
10477
10478 Process_Interface_Name (Def_Id, Arg3, Arg4);
10479 Set_Exported (Def_Id, Arg2);
10480
10481 -- If the entity is a deferred constant, propagate the information
10482 -- to the full view, because gigi elaborates the full view only.
10483
10484 if Ekind (Def_Id) = E_Constant
10485 and then Present (Full_View (Def_Id))
10486 then
10487 declare
10488 Id2 : constant Entity_Id := Full_View (Def_Id);
10489 begin
10490 Set_Is_Exported (Id2, Is_Exported (Def_Id));
10491 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
10492 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
10493 end;
10494 end if;
10495 end Export;
10496
10497 ----------------------
10498 -- Export_Exception --
10499 ----------------------
10500
10501 -- pragma Export_Exception (
10502 -- [Internal =>] LOCAL_NAME
10503 -- [, [External =>] EXTERNAL_SYMBOL]
10504 -- [, [Form =>] Ada | VMS]
10505 -- [, [Code =>] static_integer_EXPRESSION]);
10506
10507 when Pragma_Export_Exception => Export_Exception : declare
10508 Args : Args_List (1 .. 4);
10509 Names : constant Name_List (1 .. 4) := (
10510 Name_Internal,
10511 Name_External,
10512 Name_Form,
10513 Name_Code);
10514
10515 Internal : Node_Id renames Args (1);
10516 External : Node_Id renames Args (2);
10517 Form : Node_Id renames Args (3);
10518 Code : Node_Id renames Args (4);
10519
10520 begin
10521 GNAT_Pragma;
10522
10523 if Inside_A_Generic then
10524 Error_Pragma ("pragma% cannot be used for generic entities");
10525 end if;
10526
10527 Gather_Associations (Names, Args);
10528 Process_Extended_Import_Export_Exception_Pragma (
10529 Arg_Internal => Internal,
10530 Arg_External => External,
10531 Arg_Form => Form,
10532 Arg_Code => Code);
10533
10534 if not Is_VMS_Exception (Entity (Internal)) then
10535 Set_Exported (Entity (Internal), Internal);
10536 end if;
10537 end Export_Exception;
10538
10539 ---------------------
10540 -- Export_Function --
10541 ---------------------
10542
10543 -- pragma Export_Function (
10544 -- [Internal =>] LOCAL_NAME
10545 -- [, [External =>] EXTERNAL_SYMBOL]
10546 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10547 -- [, [Result_Type =>] TYPE_DESIGNATOR]
10548 -- [, [Mechanism =>] MECHANISM]
10549 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
10550
10551 -- EXTERNAL_SYMBOL ::=
10552 -- IDENTIFIER
10553 -- | static_string_EXPRESSION
10554
10555 -- PARAMETER_TYPES ::=
10556 -- null
10557 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10558
10559 -- TYPE_DESIGNATOR ::=
10560 -- subtype_NAME
10561 -- | subtype_Name ' Access
10562
10563 -- MECHANISM ::=
10564 -- MECHANISM_NAME
10565 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10566
10567 -- MECHANISM_ASSOCIATION ::=
10568 -- [formal_parameter_NAME =>] MECHANISM_NAME
10569
10570 -- MECHANISM_NAME ::=
10571 -- Value
10572 -- | Reference
10573 -- | Descriptor [([Class =>] CLASS_NAME)]
10574
10575 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10576
10577 when Pragma_Export_Function => Export_Function : declare
10578 Args : Args_List (1 .. 6);
10579 Names : constant Name_List (1 .. 6) := (
10580 Name_Internal,
10581 Name_External,
10582 Name_Parameter_Types,
10583 Name_Result_Type,
10584 Name_Mechanism,
10585 Name_Result_Mechanism);
10586
10587 Internal : Node_Id renames Args (1);
10588 External : Node_Id renames Args (2);
10589 Parameter_Types : Node_Id renames Args (3);
10590 Result_Type : Node_Id renames Args (4);
10591 Mechanism : Node_Id renames Args (5);
10592 Result_Mechanism : Node_Id renames Args (6);
10593
10594 begin
10595 GNAT_Pragma;
10596 Gather_Associations (Names, Args);
10597 Process_Extended_Import_Export_Subprogram_Pragma (
10598 Arg_Internal => Internal,
10599 Arg_External => External,
10600 Arg_Parameter_Types => Parameter_Types,
10601 Arg_Result_Type => Result_Type,
10602 Arg_Mechanism => Mechanism,
10603 Arg_Result_Mechanism => Result_Mechanism);
10604 end Export_Function;
10605
10606 -------------------
10607 -- Export_Object --
10608 -------------------
10609
10610 -- pragma Export_Object (
10611 -- [Internal =>] LOCAL_NAME
10612 -- [, [External =>] EXTERNAL_SYMBOL]
10613 -- [, [Size =>] EXTERNAL_SYMBOL]);
10614
10615 -- EXTERNAL_SYMBOL ::=
10616 -- IDENTIFIER
10617 -- | static_string_EXPRESSION
10618
10619 -- PARAMETER_TYPES ::=
10620 -- null
10621 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10622
10623 -- TYPE_DESIGNATOR ::=
10624 -- subtype_NAME
10625 -- | subtype_Name ' Access
10626
10627 -- MECHANISM ::=
10628 -- MECHANISM_NAME
10629 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10630
10631 -- MECHANISM_ASSOCIATION ::=
10632 -- [formal_parameter_NAME =>] MECHANISM_NAME
10633
10634 -- MECHANISM_NAME ::=
10635 -- Value
10636 -- | Reference
10637 -- | Descriptor [([Class =>] CLASS_NAME)]
10638
10639 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10640
10641 when Pragma_Export_Object => Export_Object : declare
10642 Args : Args_List (1 .. 3);
10643 Names : constant Name_List (1 .. 3) := (
10644 Name_Internal,
10645 Name_External,
10646 Name_Size);
10647
10648 Internal : Node_Id renames Args (1);
10649 External : Node_Id renames Args (2);
10650 Size : Node_Id renames Args (3);
10651
10652 begin
10653 GNAT_Pragma;
10654 Gather_Associations (Names, Args);
10655 Process_Extended_Import_Export_Object_Pragma (
10656 Arg_Internal => Internal,
10657 Arg_External => External,
10658 Arg_Size => Size);
10659 end Export_Object;
10660
10661 ----------------------
10662 -- Export_Procedure --
10663 ----------------------
10664
10665 -- pragma Export_Procedure (
10666 -- [Internal =>] LOCAL_NAME
10667 -- [, [External =>] EXTERNAL_SYMBOL]
10668 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10669 -- [, [Mechanism =>] MECHANISM]);
10670
10671 -- EXTERNAL_SYMBOL ::=
10672 -- IDENTIFIER
10673 -- | static_string_EXPRESSION
10674
10675 -- PARAMETER_TYPES ::=
10676 -- null
10677 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10678
10679 -- TYPE_DESIGNATOR ::=
10680 -- subtype_NAME
10681 -- | subtype_Name ' Access
10682
10683 -- MECHANISM ::=
10684 -- MECHANISM_NAME
10685 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10686
10687 -- MECHANISM_ASSOCIATION ::=
10688 -- [formal_parameter_NAME =>] MECHANISM_NAME
10689
10690 -- MECHANISM_NAME ::=
10691 -- Value
10692 -- | Reference
10693 -- | Descriptor [([Class =>] CLASS_NAME)]
10694
10695 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10696
10697 when Pragma_Export_Procedure => Export_Procedure : declare
10698 Args : Args_List (1 .. 4);
10699 Names : constant Name_List (1 .. 4) := (
10700 Name_Internal,
10701 Name_External,
10702 Name_Parameter_Types,
10703 Name_Mechanism);
10704
10705 Internal : Node_Id renames Args (1);
10706 External : Node_Id renames Args (2);
10707 Parameter_Types : Node_Id renames Args (3);
10708 Mechanism : Node_Id renames Args (4);
10709
10710 begin
10711 GNAT_Pragma;
10712 Gather_Associations (Names, Args);
10713 Process_Extended_Import_Export_Subprogram_Pragma (
10714 Arg_Internal => Internal,
10715 Arg_External => External,
10716 Arg_Parameter_Types => Parameter_Types,
10717 Arg_Mechanism => Mechanism);
10718 end Export_Procedure;
10719
10720 ------------------
10721 -- Export_Value --
10722 ------------------
10723
10724 -- pragma Export_Value (
10725 -- [Value =>] static_integer_EXPRESSION,
10726 -- [Link_Name =>] static_string_EXPRESSION);
10727
10728 when Pragma_Export_Value =>
10729 GNAT_Pragma;
10730 Check_Arg_Order ((Name_Value, Name_Link_Name));
10731 Check_Arg_Count (2);
10732
10733 Check_Optional_Identifier (Arg1, Name_Value);
10734 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10735
10736 Check_Optional_Identifier (Arg2, Name_Link_Name);
10737 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10738
10739 -----------------------------
10740 -- Export_Valued_Procedure --
10741 -----------------------------
10742
10743 -- pragma Export_Valued_Procedure (
10744 -- [Internal =>] LOCAL_NAME
10745 -- [, [External =>] EXTERNAL_SYMBOL,]
10746 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10747 -- [, [Mechanism =>] MECHANISM]);
10748
10749 -- EXTERNAL_SYMBOL ::=
10750 -- IDENTIFIER
10751 -- | static_string_EXPRESSION
10752
10753 -- PARAMETER_TYPES ::=
10754 -- null
10755 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10756
10757 -- TYPE_DESIGNATOR ::=
10758 -- subtype_NAME
10759 -- | subtype_Name ' Access
10760
10761 -- MECHANISM ::=
10762 -- MECHANISM_NAME
10763 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10764
10765 -- MECHANISM_ASSOCIATION ::=
10766 -- [formal_parameter_NAME =>] MECHANISM_NAME
10767
10768 -- MECHANISM_NAME ::=
10769 -- Value
10770 -- | Reference
10771 -- | Descriptor [([Class =>] CLASS_NAME)]
10772
10773 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10774
10775 when Pragma_Export_Valued_Procedure =>
10776 Export_Valued_Procedure : declare
10777 Args : Args_List (1 .. 4);
10778 Names : constant Name_List (1 .. 4) := (
10779 Name_Internal,
10780 Name_External,
10781 Name_Parameter_Types,
10782 Name_Mechanism);
10783
10784 Internal : Node_Id renames Args (1);
10785 External : Node_Id renames Args (2);
10786 Parameter_Types : Node_Id renames Args (3);
10787 Mechanism : Node_Id renames Args (4);
10788
10789 begin
10790 GNAT_Pragma;
10791 Gather_Associations (Names, Args);
10792 Process_Extended_Import_Export_Subprogram_Pragma (
10793 Arg_Internal => Internal,
10794 Arg_External => External,
10795 Arg_Parameter_Types => Parameter_Types,
10796 Arg_Mechanism => Mechanism);
10797 end Export_Valued_Procedure;
10798
10799 -------------------
10800 -- Extend_System --
10801 -------------------
10802
10803 -- pragma Extend_System ([Name =>] Identifier);
10804
10805 when Pragma_Extend_System => Extend_System : declare
10806 begin
10807 GNAT_Pragma;
10808 Check_Valid_Configuration_Pragma;
10809 Check_Arg_Count (1);
10810 Check_Optional_Identifier (Arg1, Name_Name);
10811 Check_Arg_Is_Identifier (Arg1);
10812
10813 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10814
10815 if Name_Len > 4
10816 and then Name_Buffer (1 .. 4) = "aux_"
10817 then
10818 if Present (System_Extend_Pragma_Arg) then
10819 if Chars (Get_Pragma_Arg (Arg1)) =
10820 Chars (Expression (System_Extend_Pragma_Arg))
10821 then
10822 null;
10823 else
10824 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
10825 Error_Pragma ("pragma% conflicts with that #");
10826 end if;
10827
10828 else
10829 System_Extend_Pragma_Arg := Arg1;
10830
10831 if not GNAT_Mode then
10832 System_Extend_Unit := Arg1;
10833 end if;
10834 end if;
10835 else
10836 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
10837 end if;
10838 end Extend_System;
10839
10840 ------------------------
10841 -- Extensions_Allowed --
10842 ------------------------
10843
10844 -- pragma Extensions_Allowed (ON | OFF);
10845
10846 when Pragma_Extensions_Allowed =>
10847 GNAT_Pragma;
10848 Check_Arg_Count (1);
10849 Check_No_Identifiers;
10850 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10851
10852 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
10853 Extensions_Allowed := True;
10854 Ada_Version := Ada_Version_Type'Last;
10855
10856 else
10857 Extensions_Allowed := False;
10858 Ada_Version := Ada_Version_Explicit;
10859 end if;
10860
10861 --------------
10862 -- External --
10863 --------------
10864
10865 -- pragma External (
10866 -- [ Convention =>] convention_IDENTIFIER,
10867 -- [ Entity =>] local_NAME
10868 -- [, [External_Name =>] static_string_EXPRESSION ]
10869 -- [, [Link_Name =>] static_string_EXPRESSION ]);
10870
10871 when Pragma_External => External : declare
10872 Def_Id : Entity_Id;
10873
10874 C : Convention_Id;
10875 pragma Warnings (Off, C);
10876
10877 begin
10878 GNAT_Pragma;
10879 Check_Arg_Order
10880 ((Name_Convention,
10881 Name_Entity,
10882 Name_External_Name,
10883 Name_Link_Name));
10884 Check_At_Least_N_Arguments (2);
10885 Check_At_Most_N_Arguments (4);
10886 Process_Convention (C, Def_Id);
10887 Note_Possible_Modification
10888 (Get_Pragma_Arg (Arg2), Sure => False);
10889 Process_Interface_Name (Def_Id, Arg3, Arg4);
10890 Set_Exported (Def_Id, Arg2);
10891 end External;
10892
10893 --------------------------
10894 -- External_Name_Casing --
10895 --------------------------
10896
10897 -- pragma External_Name_Casing (
10898 -- UPPERCASE | LOWERCASE
10899 -- [, AS_IS | UPPERCASE | LOWERCASE]);
10900
10901 when Pragma_External_Name_Casing => External_Name_Casing : declare
10902 begin
10903 GNAT_Pragma;
10904 Check_No_Identifiers;
10905
10906 if Arg_Count = 2 then
10907 Check_Arg_Is_One_Of
10908 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
10909
10910 case Chars (Get_Pragma_Arg (Arg2)) is
10911 when Name_As_Is =>
10912 Opt.External_Name_Exp_Casing := As_Is;
10913
10914 when Name_Uppercase =>
10915 Opt.External_Name_Exp_Casing := Uppercase;
10916
10917 when Name_Lowercase =>
10918 Opt.External_Name_Exp_Casing := Lowercase;
10919
10920 when others =>
10921 null;
10922 end case;
10923
10924 else
10925 Check_Arg_Count (1);
10926 end if;
10927
10928 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
10929
10930 case Chars (Get_Pragma_Arg (Arg1)) is
10931 when Name_Uppercase =>
10932 Opt.External_Name_Imp_Casing := Uppercase;
10933
10934 when Name_Lowercase =>
10935 Opt.External_Name_Imp_Casing := Lowercase;
10936
10937 when others =>
10938 null;
10939 end case;
10940 end External_Name_Casing;
10941
10942 --------------------------
10943 -- Favor_Top_Level --
10944 --------------------------
10945
10946 -- pragma Favor_Top_Level (type_NAME);
10947
10948 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
10949 Named_Entity : Entity_Id;
10950
10951 begin
10952 GNAT_Pragma;
10953 Check_No_Identifiers;
10954 Check_Arg_Count (1);
10955 Check_Arg_Is_Local_Name (Arg1);
10956 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
10957
10958 -- If it's an access-to-subprogram type (in particular, not a
10959 -- subtype), set the flag on that type.
10960
10961 if Is_Access_Subprogram_Type (Named_Entity) then
10962 Set_Can_Use_Internal_Rep (Named_Entity, False);
10963
10964 -- Otherwise it's an error (name denotes the wrong sort of entity)
10965
10966 else
10967 Error_Pragma_Arg
10968 ("access-to-subprogram type expected",
10969 Get_Pragma_Arg (Arg1));
10970 end if;
10971 end Favor_Top_Level;
10972
10973 ---------------
10974 -- Fast_Math --
10975 ---------------
10976
10977 -- pragma Fast_Math;
10978
10979 when Pragma_Fast_Math =>
10980 GNAT_Pragma;
10981 Check_No_Identifiers;
10982 Check_Valid_Configuration_Pragma;
10983 Fast_Math := True;
10984
10985 ---------------------------
10986 -- Finalize_Storage_Only --
10987 ---------------------------
10988
10989 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
10990
10991 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
10992 Assoc : constant Node_Id := Arg1;
10993 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
10994 Typ : Entity_Id;
10995
10996 begin
10997 GNAT_Pragma;
10998 Check_No_Identifiers;
10999 Check_Arg_Count (1);
11000 Check_Arg_Is_Local_Name (Arg1);
11001
11002 Find_Type (Type_Id);
11003 Typ := Entity (Type_Id);
11004
11005 if Typ = Any_Type
11006 or else Rep_Item_Too_Early (Typ, N)
11007 then
11008 return;
11009 else
11010 Typ := Underlying_Type (Typ);
11011 end if;
11012
11013 if not Is_Controlled (Typ) then
11014 Error_Pragma ("pragma% must specify controlled type");
11015 end if;
11016
11017 Check_First_Subtype (Arg1);
11018
11019 if Finalize_Storage_Only (Typ) then
11020 Error_Pragma ("duplicate pragma%, only one allowed");
11021
11022 elsif not Rep_Item_Too_Late (Typ, N) then
11023 Set_Finalize_Storage_Only (Base_Type (Typ), True);
11024 end if;
11025 end Finalize_Storage;
11026
11027 --------------------------
11028 -- Float_Representation --
11029 --------------------------
11030
11031 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
11032
11033 -- FLOAT_REP ::= VAX_Float | IEEE_Float
11034
11035 when Pragma_Float_Representation => Float_Representation : declare
11036 Argx : Node_Id;
11037 Digs : Nat;
11038 Ent : Entity_Id;
11039
11040 begin
11041 GNAT_Pragma;
11042
11043 if Arg_Count = 1 then
11044 Check_Valid_Configuration_Pragma;
11045 else
11046 Check_Arg_Count (2);
11047 Check_Optional_Identifier (Arg2, Name_Entity);
11048 Check_Arg_Is_Local_Name (Arg2);
11049 end if;
11050
11051 Check_No_Identifier (Arg1);
11052 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
11053
11054 if not OpenVMS_On_Target then
11055 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
11056 Error_Pragma
11057 ("??pragma% ignored (applies only to Open'V'M'S)");
11058 end if;
11059
11060 return;
11061 end if;
11062
11063 -- One argument case
11064
11065 if Arg_Count = 1 then
11066 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
11067 if Opt.Float_Format = 'I' then
11068 Error_Pragma ("'I'E'E'E format previously specified");
11069 end if;
11070
11071 Opt.Float_Format := 'V';
11072
11073 else
11074 if Opt.Float_Format = 'V' then
11075 Error_Pragma ("'V'A'X format previously specified");
11076 end if;
11077
11078 Opt.Float_Format := 'I';
11079 end if;
11080
11081 Set_Standard_Fpt_Formats;
11082
11083 -- Two argument case
11084
11085 else
11086 Argx := Get_Pragma_Arg (Arg2);
11087
11088 if not Is_Entity_Name (Argx)
11089 or else not Is_Floating_Point_Type (Entity (Argx))
11090 then
11091 Error_Pragma_Arg
11092 ("second argument of% pragma must be floating-point type",
11093 Arg2);
11094 end if;
11095
11096 Ent := Entity (Argx);
11097 Digs := UI_To_Int (Digits_Value (Ent));
11098
11099 -- Two arguments, VAX_Float case
11100
11101 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
11102 case Digs is
11103 when 6 => Set_F_Float (Ent);
11104 when 9 => Set_D_Float (Ent);
11105 when 15 => Set_G_Float (Ent);
11106
11107 when others =>
11108 Error_Pragma_Arg
11109 ("wrong digits value, must be 6,9 or 15", Arg2);
11110 end case;
11111
11112 -- Two arguments, IEEE_Float case
11113
11114 else
11115 case Digs is
11116 when 6 => Set_IEEE_Short (Ent);
11117 when 15 => Set_IEEE_Long (Ent);
11118
11119 when others =>
11120 Error_Pragma_Arg
11121 ("wrong digits value, must be 6 or 15", Arg2);
11122 end case;
11123 end if;
11124 end if;
11125 end Float_Representation;
11126
11127 ------------
11128 -- Global --
11129 ------------
11130
11131 -- pragma Global (GLOBAL_SPECIFICATION)
11132
11133 -- GLOBAL_SPECIFICATION ::=
11134 -- null
11135 -- | GLOBAL_LIST
11136 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
11137
11138 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
11139
11140 -- MODE_SELECTOR ::= Input | Output | In_Out | Contract_In
11141 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
11142 -- GLOBAL_ITEM ::= NAME
11143
11144 when Pragma_Global => Global : declare
11145 Subp_Id : Entity_Id;
11146
11147 Seen : Elist_Id := No_Elist;
11148 -- A list containing the entities of all the items processed so
11149 -- far. It plays a role in detecting distinct entities.
11150
11151 Contract_Seen : Boolean := False;
11152 In_Out_Seen : Boolean := False;
11153 Input_Seen : Boolean := False;
11154 Output_Seen : Boolean := False;
11155 -- Flags used to verify the consistency of modes
11156
11157 procedure Analyze_Global_List
11158 (List : Node_Id;
11159 Global_Mode : Name_Id := Name_Input);
11160 -- Verify the legality of a single global list declaration.
11161 -- Global_Mode denotes the current mode in effect.
11162
11163 -------------------------
11164 -- Analyze_Global_List --
11165 -------------------------
11166
11167 procedure Analyze_Global_List
11168 (List : Node_Id;
11169 Global_Mode : Name_Id := Name_Input)
11170 is
11171 procedure Analyze_Global_Item
11172 (Item : Node_Id;
11173 Global_Mode : Name_Id);
11174 -- Verify the legality of a single global item declaration.
11175 -- Global_Mode denotes the current mode in effect.
11176
11177 procedure Check_Duplicate_Mode
11178 (Mode : Node_Id;
11179 Status : in out Boolean);
11180 -- Flag Status denotes whether a particular mode has been seen
11181 -- while processing a global list. This routine verifies that
11182 -- Mode is not a duplicate mode and sets the flag Status.
11183
11184 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
11185 -- Mode denotes either In_Out or Output. Depending on the kind
11186 -- of the related subprogram, emit an error if those two modes
11187 -- apply to a function.
11188
11189 -------------------------
11190 -- Analyze_Global_Item --
11191 -------------------------
11192
11193 procedure Analyze_Global_Item
11194 (Item : Node_Id;
11195 Global_Mode : Name_Id)
11196 is
11197 Item_Id : Entity_Id;
11198
11199 begin
11200 -- Detect one of the following cases
11201
11202 -- with Global => (null, Name)
11203 -- with Global => (Name_1, null, Name_2)
11204 -- with Global => (Name, null)
11205
11206 if Nkind (Item) = N_Null then
11207 Error_Msg_N
11208 ("cannot mix null and non-null global items", Item);
11209 return;
11210 end if;
11211
11212 Analyze (Item);
11213
11214 -- Find the entity of the item. If this is a renaming, climb
11215 -- the renaming chain to reach the root object. Renamings of
11216 -- non-entire objects do not yield an entity (Empty).
11217
11218 Item_Id := Entity_Of (Item);
11219
11220 if Present (Item_Id) then
11221
11222 -- A global item cannot reference a formal parameter. Do
11223 -- this check first to provide a better error diagnostic.
11224
11225 if Is_Formal (Item_Id) then
11226 Error_Msg_N
11227 ("global item cannot reference formal parameter",
11228 Item);
11229 return;
11230
11231 -- The only legal references are those to abstract states
11232 -- and variables.
11233
11234 elsif not Ekind_In (Item_Id, E_Abstract_State,
11235 E_Variable)
11236 then
11237 Error_Msg_N
11238 ("global item must denote variable or state", Item);
11239 return;
11240 end if;
11241
11242 -- When the item renames an entire object, replace the
11243 -- item with a reference to the object.
11244
11245 if Present (Renamed_Object (Entity (Item))) then
11246 Rewrite (Item,
11247 New_Reference_To (Item_Id, Sloc (Item)));
11248 Analyze (Item);
11249 end if;
11250
11251 -- Some form of illegal construct masquerading as a name
11252
11253 else
11254 Error_Msg_N
11255 ("global item must denote variable or state", Item);
11256 return;
11257 end if;
11258
11259 -- The same entity might be referenced through various way.
11260 -- Check the entity of the item rather than the item itself.
11261
11262 if Contains (Seen, Item_Id) then
11263 Error_Msg_N ("duplicate global item", Item);
11264
11265 -- Add the entity of the current item to the list of
11266 -- processed items.
11267
11268 else
11269 Add_Item (Item_Id, Seen);
11270 end if;
11271
11272 if Ekind (Item_Id) = E_Abstract_State
11273 and then Is_Volatile_State (Item_Id)
11274 then
11275 -- A global item of mode In_Out or Output cannot denote a
11276 -- volatile Input state.
11277
11278 if Is_Input_State (Item_Id)
11279 and then (Global_Mode = Name_In_Out
11280 or else
11281 Global_Mode = Name_Output)
11282 then
11283 Error_Msg_N
11284 ("global item of mode In_Out or Output cannot "
11285 & "reference Volatile Input state", Item);
11286
11287 -- A global item of mode In_Out or Input cannot reference
11288 -- a volatile Output state.
11289
11290 elsif Is_Output_State (Item_Id)
11291 and then (Global_Mode = Name_In_Out
11292 or else
11293 Global_Mode = Name_Input)
11294 then
11295 Error_Msg_N
11296 ("global item of mode In_Out or Input cannot "
11297 & "reference Volatile Output state", Item);
11298 end if;
11299 end if;
11300 end Analyze_Global_Item;
11301
11302 --------------------------
11303 -- Check_Duplicate_Mode --
11304 --------------------------
11305
11306 procedure Check_Duplicate_Mode
11307 (Mode : Node_Id;
11308 Status : in out Boolean)
11309 is
11310 begin
11311 if Status then
11312 Error_Msg_N ("duplicate global mode", Mode);
11313 end if;
11314
11315 Status := True;
11316 end Check_Duplicate_Mode;
11317
11318 ----------------------------------------
11319 -- Check_Mode_Restriction_In_Function --
11320 ----------------------------------------
11321
11322 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
11323 begin
11324 if Ekind (Subp_Id) = E_Function then
11325 Error_Msg_NE
11326 ("global mode & not applicable to functions",
11327 Mode, Mode);
11328 end if;
11329 end Check_Mode_Restriction_In_Function;
11330
11331 -- Local variables
11332
11333 Assoc : Node_Id;
11334 Item : Node_Id;
11335 Mode : Node_Id;
11336
11337 -- Start of processing for Analyze_Global_List
11338
11339 begin
11340 -- Single global item declaration
11341
11342 if Nkind_In (List, N_Identifier, N_Selected_Component) then
11343 Analyze_Global_Item (List, Global_Mode);
11344
11345 -- Simple global list or moded global list declaration
11346
11347 elsif Nkind (List) = N_Aggregate then
11348
11349 -- The declaration of a simple global list appear as a
11350 -- collection of expressions.
11351
11352 if Present (Expressions (List)) then
11353 if Present (Component_Associations (List)) then
11354 Error_Msg_N
11355 ("cannot mix moded and non-moded global lists",
11356 List);
11357 end if;
11358
11359 Item := First (Expressions (List));
11360 while Present (Item) loop
11361 Analyze_Global_Item (Item, Global_Mode);
11362
11363 Next (Item);
11364 end loop;
11365
11366 -- The declaration of a moded global list appears as a
11367 -- collection of component associations where individual
11368 -- choices denote modes.
11369
11370 elsif Present (Component_Associations (List)) then
11371 if Present (Expressions (List)) then
11372 Error_Msg_N
11373 ("cannot mix moded and non-moded global lists",
11374 List);
11375 end if;
11376
11377 Assoc := First (Component_Associations (List));
11378 while Present (Assoc) loop
11379 Mode := First (Choices (Assoc));
11380
11381 if Nkind (Mode) = N_Identifier then
11382 if Chars (Mode) = Name_Contract_In then
11383 Check_Duplicate_Mode (Mode, Contract_Seen);
11384
11385 elsif Chars (Mode) = Name_In_Out then
11386 Check_Duplicate_Mode (Mode, In_Out_Seen);
11387 Check_Mode_Restriction_In_Function (Mode);
11388
11389 elsif Chars (Mode) = Name_Input then
11390 Check_Duplicate_Mode (Mode, Input_Seen);
11391
11392 elsif Chars (Mode) = Name_Output then
11393 Check_Duplicate_Mode (Mode, Output_Seen);
11394 Check_Mode_Restriction_In_Function (Mode);
11395
11396 else
11397 Error_Msg_N ("invalid mode selector", Mode);
11398 end if;
11399
11400 else
11401 Error_Msg_N ("invalid mode selector", Mode);
11402 end if;
11403
11404 -- Items in a moded list appear as a collection of
11405 -- expressions. Reuse the existing machinery to
11406 -- analyze them.
11407
11408 Analyze_Global_List
11409 (List => Expression (Assoc),
11410 Global_Mode => Chars (Mode));
11411
11412 Next (Assoc);
11413 end loop;
11414
11415 -- Something went horribly wrong, we have a malformed tree
11416
11417 else
11418 raise Program_Error;
11419 end if;
11420
11421 -- Any other attempt to declare a global item is erroneous
11422
11423 else
11424 Error_Msg_N ("malformed global list declaration", List);
11425 end if;
11426 end Analyze_Global_List;
11427
11428 -- Local variables
11429
11430 List : Node_Id;
11431 Subp : Node_Id;
11432
11433 -- Start of processing for Global
11434
11435 begin
11436 GNAT_Pragma;
11437 S14_Pragma;
11438 Check_Arg_Count (1);
11439
11440 -- Ensure the proper placement of the pragma. Global must be
11441 -- associated with a subprogram declaration.
11442
11443 Subp := Parent (Corresponding_Aspect (N));
11444
11445 if Nkind (Subp) /= N_Subprogram_Declaration then
11446 Pragma_Misplaced;
11447 return;
11448 end if;
11449
11450 Subp_Id := Defining_Unit_Name (Specification (Subp));
11451 List := Expression (Arg1);
11452
11453 -- There is nothing to be done for a null global list
11454
11455 if Nkind (List) = N_Null then
11456 null;
11457
11458 -- Analyze the various forms of global lists and items. Note that
11459 -- some of these may be malformed in which case the analysis emits
11460 -- error messages.
11461
11462 else
11463 -- Ensure that the formal parameters are visible when
11464 -- processing an item. This falls out of the general rule of
11465 -- aspects pertaining to subprogram declarations.
11466
11467 Push_Scope (Subp_Id);
11468 Install_Formals (Subp_Id);
11469
11470 Analyze_Global_List (List);
11471
11472 End_Scope;
11473 end if;
11474 end Global;
11475
11476 -----------
11477 -- Ident --
11478 -----------
11479
11480 -- pragma Ident (static_string_EXPRESSION)
11481
11482 -- Note: pragma Comment shares this processing. Pragma Comment is
11483 -- identical to Ident, except that the restriction of the argument to
11484 -- 31 characters and the placement restrictions are not enforced for
11485 -- pragma Comment.
11486
11487 when Pragma_Ident | Pragma_Comment => Ident : declare
11488 Str : Node_Id;
11489
11490 begin
11491 GNAT_Pragma;
11492 Check_Arg_Count (1);
11493 Check_No_Identifiers;
11494 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11495 Store_Note (N);
11496
11497 -- For pragma Ident, preserve DEC compatibility by requiring the
11498 -- pragma to appear in a declarative part or package spec.
11499
11500 if Prag_Id = Pragma_Ident then
11501 Check_Is_In_Decl_Part_Or_Package_Spec;
11502 end if;
11503
11504 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
11505
11506 declare
11507 CS : Node_Id;
11508 GP : Node_Id;
11509
11510 begin
11511 GP := Parent (Parent (N));
11512
11513 if Nkind_In (GP, N_Package_Declaration,
11514 N_Generic_Package_Declaration)
11515 then
11516 GP := Parent (GP);
11517 end if;
11518
11519 -- If we have a compilation unit, then record the ident value,
11520 -- checking for improper duplication.
11521
11522 if Nkind (GP) = N_Compilation_Unit then
11523 CS := Ident_String (Current_Sem_Unit);
11524
11525 if Present (CS) then
11526
11527 -- For Ident, we do not permit multiple instances
11528
11529 if Prag_Id = Pragma_Ident then
11530 Error_Pragma ("duplicate% pragma not permitted");
11531
11532 -- For Comment, we concatenate the string, unless we want
11533 -- to preserve the tree structure for ASIS.
11534
11535 elsif not ASIS_Mode then
11536 Start_String (Strval (CS));
11537 Store_String_Char (' ');
11538 Store_String_Chars (Strval (Str));
11539 Set_Strval (CS, End_String);
11540 end if;
11541
11542 else
11543 -- In VMS, the effect of IDENT is achieved by passing
11544 -- --identification=name as a --for-linker switch.
11545
11546 if OpenVMS_On_Target then
11547 Start_String;
11548 Store_String_Chars
11549 ("--for-linker=--identification=");
11550 String_To_Name_Buffer (Strval (Str));
11551 Store_String_Chars (Name_Buffer (1 .. Name_Len));
11552
11553 -- Only the last processed IDENT is saved. The main
11554 -- purpose is so an IDENT associated with a main
11555 -- procedure will be used in preference to an IDENT
11556 -- associated with a with'd package.
11557
11558 Replace_Linker_Option_String
11559 (End_String, "--for-linker=--identification=");
11560 end if;
11561
11562 Set_Ident_String (Current_Sem_Unit, Str);
11563 end if;
11564
11565 -- For subunits, we just ignore the Ident, since in GNAT these
11566 -- are not separate object files, and hence not separate units
11567 -- in the unit table.
11568
11569 elsif Nkind (GP) = N_Subunit then
11570 null;
11571
11572 -- Otherwise we have a misplaced pragma Ident, but we ignore
11573 -- this if we are in an instantiation, since it comes from
11574 -- a generic, and has no relevance to the instantiation.
11575
11576 elsif Prag_Id = Pragma_Ident then
11577 if Instantiation_Location (Loc) = No_Location then
11578 Error_Pragma ("pragma% only allowed at outer level");
11579 end if;
11580 end if;
11581 end;
11582 end Ident;
11583
11584 ----------------------------
11585 -- Implementation_Defined --
11586 ----------------------------
11587
11588 -- pragma Implementation_Defined (local_NAME);
11589
11590 -- Marks previously declared entity as implementation defined. For
11591 -- an overloaded entity, applies to the most recent homonym.
11592
11593 -- pragma Implementation_Defined;
11594
11595 -- The form with no arguments appears anywhere within a scope, most
11596 -- typically a package spec, and indicates that all entities that are
11597 -- defined within the package spec are Implementation_Defined.
11598
11599 when Pragma_Implementation_Defined => Implementation_Defined : declare
11600 Ent : Entity_Id;
11601
11602 begin
11603 Check_No_Identifiers;
11604
11605 -- Form with no arguments
11606
11607 if Arg_Count = 0 then
11608 Set_Is_Implementation_Defined (Current_Scope);
11609
11610 -- Form with one argument
11611
11612 else
11613 Check_Arg_Count (1);
11614 Check_Arg_Is_Local_Name (Arg1);
11615 Ent := Entity (Get_Pragma_Arg (Arg1));
11616 Set_Is_Implementation_Defined (Ent);
11617 end if;
11618 end Implementation_Defined;
11619
11620 -----------------
11621 -- Implemented --
11622 -----------------
11623
11624 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
11625
11626 -- IMPLEMENTATION_KIND ::=
11627 -- By_Entry | By_Protected_Procedure | By_Any | Optional
11628
11629 -- "By_Any" and "Optional" are treated as synonyms in order to
11630 -- support Ada 2012 aspect Synchronization.
11631
11632 when Pragma_Implemented => Implemented : declare
11633 Proc_Id : Entity_Id;
11634 Typ : Entity_Id;
11635
11636 begin
11637 Ada_2012_Pragma;
11638 Check_Arg_Count (2);
11639 Check_No_Identifiers;
11640 Check_Arg_Is_Identifier (Arg1);
11641 Check_Arg_Is_Local_Name (Arg1);
11642 Check_Arg_Is_One_Of (Arg2,
11643 Name_By_Any,
11644 Name_By_Entry,
11645 Name_By_Protected_Procedure,
11646 Name_Optional);
11647
11648 -- Extract the name of the local procedure
11649
11650 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
11651
11652 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
11653 -- primitive procedure of a synchronized tagged type.
11654
11655 if Ekind (Proc_Id) = E_Procedure
11656 and then Is_Primitive (Proc_Id)
11657 and then Present (First_Formal (Proc_Id))
11658 then
11659 Typ := Etype (First_Formal (Proc_Id));
11660
11661 if Is_Tagged_Type (Typ)
11662 and then
11663
11664 -- Check for a protected, a synchronized or a task interface
11665
11666 ((Is_Interface (Typ)
11667 and then Is_Synchronized_Interface (Typ))
11668
11669 -- Check for a protected type or a task type that implements
11670 -- an interface.
11671
11672 or else
11673 (Is_Concurrent_Record_Type (Typ)
11674 and then Present (Interfaces (Typ)))
11675
11676 -- Check for a private record extension with keyword
11677 -- "synchronized".
11678
11679 or else
11680 (Ekind_In (Typ, E_Record_Type_With_Private,
11681 E_Record_Subtype_With_Private)
11682 and then Synchronized_Present (Parent (Typ))))
11683 then
11684 null;
11685 else
11686 Error_Pragma_Arg
11687 ("controlling formal must be of synchronized tagged type",
11688 Arg1);
11689 return;
11690 end if;
11691
11692 -- Procedures declared inside a protected type must be accepted
11693
11694 elsif Ekind (Proc_Id) = E_Procedure
11695 and then Is_Protected_Type (Scope (Proc_Id))
11696 then
11697 null;
11698
11699 -- The first argument is not a primitive procedure
11700
11701 else
11702 Error_Pragma_Arg
11703 ("pragma % must be applied to a primitive procedure", Arg1);
11704 return;
11705 end if;
11706
11707 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
11708 -- By_Protected_Procedure to the primitive procedure of a task
11709 -- interface.
11710
11711 if Chars (Arg2) = Name_By_Protected_Procedure
11712 and then Is_Interface (Typ)
11713 and then Is_Task_Interface (Typ)
11714 then
11715 Error_Pragma_Arg
11716 ("implementation kind By_Protected_Procedure cannot be "
11717 & "applied to a task interface primitive", Arg2);
11718 return;
11719 end if;
11720
11721 Record_Rep_Item (Proc_Id, N);
11722 end Implemented;
11723
11724 ----------------------
11725 -- Implicit_Packing --
11726 ----------------------
11727
11728 -- pragma Implicit_Packing;
11729
11730 when Pragma_Implicit_Packing =>
11731 GNAT_Pragma;
11732 Check_Arg_Count (0);
11733 Implicit_Packing := True;
11734
11735 ------------
11736 -- Import --
11737 ------------
11738
11739 -- pragma Import (
11740 -- [Convention =>] convention_IDENTIFIER,
11741 -- [Entity =>] local_NAME
11742 -- [, [External_Name =>] static_string_EXPRESSION ]
11743 -- [, [Link_Name =>] static_string_EXPRESSION ]);
11744
11745 when Pragma_Import =>
11746 Check_Ada_83_Warning;
11747 Check_Arg_Order
11748 ((Name_Convention,
11749 Name_Entity,
11750 Name_External_Name,
11751 Name_Link_Name));
11752
11753 Check_At_Least_N_Arguments (2);
11754 Check_At_Most_N_Arguments (4);
11755 Process_Import_Or_Interface;
11756
11757 ----------------------
11758 -- Import_Exception --
11759 ----------------------
11760
11761 -- pragma Import_Exception (
11762 -- [Internal =>] LOCAL_NAME
11763 -- [, [External =>] EXTERNAL_SYMBOL]
11764 -- [, [Form =>] Ada | VMS]
11765 -- [, [Code =>] static_integer_EXPRESSION]);
11766
11767 when Pragma_Import_Exception => Import_Exception : declare
11768 Args : Args_List (1 .. 4);
11769 Names : constant Name_List (1 .. 4) := (
11770 Name_Internal,
11771 Name_External,
11772 Name_Form,
11773 Name_Code);
11774
11775 Internal : Node_Id renames Args (1);
11776 External : Node_Id renames Args (2);
11777 Form : Node_Id renames Args (3);
11778 Code : Node_Id renames Args (4);
11779
11780 begin
11781 GNAT_Pragma;
11782 Gather_Associations (Names, Args);
11783
11784 if Present (External) and then Present (Code) then
11785 Error_Pragma
11786 ("cannot give both External and Code options for pragma%");
11787 end if;
11788
11789 Process_Extended_Import_Export_Exception_Pragma (
11790 Arg_Internal => Internal,
11791 Arg_External => External,
11792 Arg_Form => Form,
11793 Arg_Code => Code);
11794
11795 if not Is_VMS_Exception (Entity (Internal)) then
11796 Set_Imported (Entity (Internal));
11797 end if;
11798 end Import_Exception;
11799
11800 ---------------------
11801 -- Import_Function --
11802 ---------------------
11803
11804 -- pragma Import_Function (
11805 -- [Internal =>] LOCAL_NAME,
11806 -- [, [External =>] EXTERNAL_SYMBOL]
11807 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
11808 -- [, [Result_Type =>] SUBTYPE_MARK]
11809 -- [, [Mechanism =>] MECHANISM]
11810 -- [, [Result_Mechanism =>] MECHANISM_NAME]
11811 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
11812
11813 -- EXTERNAL_SYMBOL ::=
11814 -- IDENTIFIER
11815 -- | static_string_EXPRESSION
11816
11817 -- PARAMETER_TYPES ::=
11818 -- null
11819 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
11820
11821 -- TYPE_DESIGNATOR ::=
11822 -- subtype_NAME
11823 -- | subtype_Name ' Access
11824
11825 -- MECHANISM ::=
11826 -- MECHANISM_NAME
11827 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
11828
11829 -- MECHANISM_ASSOCIATION ::=
11830 -- [formal_parameter_NAME =>] MECHANISM_NAME
11831
11832 -- MECHANISM_NAME ::=
11833 -- Value
11834 -- | Reference
11835 -- | Descriptor [([Class =>] CLASS_NAME)]
11836
11837 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
11838
11839 when Pragma_Import_Function => Import_Function : declare
11840 Args : Args_List (1 .. 7);
11841 Names : constant Name_List (1 .. 7) := (
11842 Name_Internal,
11843 Name_External,
11844 Name_Parameter_Types,
11845 Name_Result_Type,
11846 Name_Mechanism,
11847 Name_Result_Mechanism,
11848 Name_First_Optional_Parameter);
11849
11850 Internal : Node_Id renames Args (1);
11851 External : Node_Id renames Args (2);
11852 Parameter_Types : Node_Id renames Args (3);
11853 Result_Type : Node_Id renames Args (4);
11854 Mechanism : Node_Id renames Args (5);
11855 Result_Mechanism : Node_Id renames Args (6);
11856 First_Optional_Parameter : Node_Id renames Args (7);
11857
11858 begin
11859 GNAT_Pragma;
11860 Gather_Associations (Names, Args);
11861 Process_Extended_Import_Export_Subprogram_Pragma (
11862 Arg_Internal => Internal,
11863 Arg_External => External,
11864 Arg_Parameter_Types => Parameter_Types,
11865 Arg_Result_Type => Result_Type,
11866 Arg_Mechanism => Mechanism,
11867 Arg_Result_Mechanism => Result_Mechanism,
11868 Arg_First_Optional_Parameter => First_Optional_Parameter);
11869 end Import_Function;
11870
11871 -------------------
11872 -- Import_Object --
11873 -------------------
11874
11875 -- pragma Import_Object (
11876 -- [Internal =>] LOCAL_NAME
11877 -- [, [External =>] EXTERNAL_SYMBOL]
11878 -- [, [Size =>] EXTERNAL_SYMBOL]);
11879
11880 -- EXTERNAL_SYMBOL ::=
11881 -- IDENTIFIER
11882 -- | static_string_EXPRESSION
11883
11884 when Pragma_Import_Object => Import_Object : declare
11885 Args : Args_List (1 .. 3);
11886 Names : constant Name_List (1 .. 3) := (
11887 Name_Internal,
11888 Name_External,
11889 Name_Size);
11890
11891 Internal : Node_Id renames Args (1);
11892 External : Node_Id renames Args (2);
11893 Size : Node_Id renames Args (3);
11894
11895 begin
11896 GNAT_Pragma;
11897 Gather_Associations (Names, Args);
11898 Process_Extended_Import_Export_Object_Pragma (
11899 Arg_Internal => Internal,
11900 Arg_External => External,
11901 Arg_Size => Size);
11902 end Import_Object;
11903
11904 ----------------------
11905 -- Import_Procedure --
11906 ----------------------
11907
11908 -- pragma Import_Procedure (
11909 -- [Internal =>] LOCAL_NAME
11910 -- [, [External =>] EXTERNAL_SYMBOL]
11911 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
11912 -- [, [Mechanism =>] MECHANISM]
11913 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
11914
11915 -- EXTERNAL_SYMBOL ::=
11916 -- IDENTIFIER
11917 -- | static_string_EXPRESSION
11918
11919 -- PARAMETER_TYPES ::=
11920 -- null
11921 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
11922
11923 -- TYPE_DESIGNATOR ::=
11924 -- subtype_NAME
11925 -- | subtype_Name ' Access
11926
11927 -- MECHANISM ::=
11928 -- MECHANISM_NAME
11929 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
11930
11931 -- MECHANISM_ASSOCIATION ::=
11932 -- [formal_parameter_NAME =>] MECHANISM_NAME
11933
11934 -- MECHANISM_NAME ::=
11935 -- Value
11936 -- | Reference
11937 -- | Descriptor [([Class =>] CLASS_NAME)]
11938
11939 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
11940
11941 when Pragma_Import_Procedure => Import_Procedure : declare
11942 Args : Args_List (1 .. 5);
11943 Names : constant Name_List (1 .. 5) := (
11944 Name_Internal,
11945 Name_External,
11946 Name_Parameter_Types,
11947 Name_Mechanism,
11948 Name_First_Optional_Parameter);
11949
11950 Internal : Node_Id renames Args (1);
11951 External : Node_Id renames Args (2);
11952 Parameter_Types : Node_Id renames Args (3);
11953 Mechanism : Node_Id renames Args (4);
11954 First_Optional_Parameter : Node_Id renames Args (5);
11955
11956 begin
11957 GNAT_Pragma;
11958 Gather_Associations (Names, Args);
11959 Process_Extended_Import_Export_Subprogram_Pragma (
11960 Arg_Internal => Internal,
11961 Arg_External => External,
11962 Arg_Parameter_Types => Parameter_Types,
11963 Arg_Mechanism => Mechanism,
11964 Arg_First_Optional_Parameter => First_Optional_Parameter);
11965 end Import_Procedure;
11966
11967 -----------------------------
11968 -- Import_Valued_Procedure --
11969 -----------------------------
11970
11971 -- pragma Import_Valued_Procedure (
11972 -- [Internal =>] LOCAL_NAME
11973 -- [, [External =>] EXTERNAL_SYMBOL]
11974 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
11975 -- [, [Mechanism =>] MECHANISM]
11976 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
11977
11978 -- EXTERNAL_SYMBOL ::=
11979 -- IDENTIFIER
11980 -- | static_string_EXPRESSION
11981
11982 -- PARAMETER_TYPES ::=
11983 -- null
11984 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
11985
11986 -- TYPE_DESIGNATOR ::=
11987 -- subtype_NAME
11988 -- | subtype_Name ' Access
11989
11990 -- MECHANISM ::=
11991 -- MECHANISM_NAME
11992 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
11993
11994 -- MECHANISM_ASSOCIATION ::=
11995 -- [formal_parameter_NAME =>] MECHANISM_NAME
11996
11997 -- MECHANISM_NAME ::=
11998 -- Value
11999 -- | Reference
12000 -- | Descriptor [([Class =>] CLASS_NAME)]
12001
12002 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12003
12004 when Pragma_Import_Valued_Procedure =>
12005 Import_Valued_Procedure : declare
12006 Args : Args_List (1 .. 5);
12007 Names : constant Name_List (1 .. 5) := (
12008 Name_Internal,
12009 Name_External,
12010 Name_Parameter_Types,
12011 Name_Mechanism,
12012 Name_First_Optional_Parameter);
12013
12014 Internal : Node_Id renames Args (1);
12015 External : Node_Id renames Args (2);
12016 Parameter_Types : Node_Id renames Args (3);
12017 Mechanism : Node_Id renames Args (4);
12018 First_Optional_Parameter : Node_Id renames Args (5);
12019
12020 begin
12021 GNAT_Pragma;
12022 Gather_Associations (Names, Args);
12023 Process_Extended_Import_Export_Subprogram_Pragma (
12024 Arg_Internal => Internal,
12025 Arg_External => External,
12026 Arg_Parameter_Types => Parameter_Types,
12027 Arg_Mechanism => Mechanism,
12028 Arg_First_Optional_Parameter => First_Optional_Parameter);
12029 end Import_Valued_Procedure;
12030
12031 -----------------
12032 -- Independent --
12033 -----------------
12034
12035 -- pragma Independent (LOCAL_NAME);
12036
12037 when Pragma_Independent => Independent : declare
12038 E_Id : Node_Id;
12039 E : Entity_Id;
12040 D : Node_Id;
12041 K : Node_Kind;
12042
12043 begin
12044 Check_Ada_83_Warning;
12045 Ada_2012_Pragma;
12046 Check_No_Identifiers;
12047 Check_Arg_Count (1);
12048 Check_Arg_Is_Local_Name (Arg1);
12049 E_Id := Get_Pragma_Arg (Arg1);
12050
12051 if Etype (E_Id) = Any_Type then
12052 return;
12053 end if;
12054
12055 E := Entity (E_Id);
12056 D := Declaration_Node (E);
12057 K := Nkind (D);
12058
12059 -- Check duplicate before we chain ourselves!
12060
12061 Check_Duplicate_Pragma (E);
12062
12063 -- Check appropriate entity
12064
12065 if Is_Type (E) then
12066 if Rep_Item_Too_Early (E, N)
12067 or else
12068 Rep_Item_Too_Late (E, N)
12069 then
12070 return;
12071 else
12072 Check_First_Subtype (Arg1);
12073 end if;
12074
12075 elsif K = N_Object_Declaration
12076 or else (K = N_Component_Declaration
12077 and then Original_Record_Component (E) = E)
12078 then
12079 if Rep_Item_Too_Late (E, N) then
12080 return;
12081 end if;
12082
12083 else
12084 Error_Pragma_Arg
12085 ("inappropriate entity for pragma%", Arg1);
12086 end if;
12087
12088 Independence_Checks.Append ((N, E));
12089 end Independent;
12090
12091 ----------------------------
12092 -- Independent_Components --
12093 ----------------------------
12094
12095 -- pragma Atomic_Components (array_LOCAL_NAME);
12096
12097 -- This processing is shared by Volatile_Components
12098
12099 when Pragma_Independent_Components => Independent_Components : declare
12100 E_Id : Node_Id;
12101 E : Entity_Id;
12102 D : Node_Id;
12103 K : Node_Kind;
12104
12105 begin
12106 Check_Ada_83_Warning;
12107 Ada_2012_Pragma;
12108 Check_No_Identifiers;
12109 Check_Arg_Count (1);
12110 Check_Arg_Is_Local_Name (Arg1);
12111 E_Id := Get_Pragma_Arg (Arg1);
12112
12113 if Etype (E_Id) = Any_Type then
12114 return;
12115 end if;
12116
12117 E := Entity (E_Id);
12118
12119 -- Check duplicate before we chain ourselves!
12120
12121 Check_Duplicate_Pragma (E);
12122
12123 -- Check appropriate entity
12124
12125 if Rep_Item_Too_Early (E, N)
12126 or else
12127 Rep_Item_Too_Late (E, N)
12128 then
12129 return;
12130 end if;
12131
12132 D := Declaration_Node (E);
12133 K := Nkind (D);
12134
12135 if K = N_Full_Type_Declaration
12136 and then (Is_Array_Type (E) or else Is_Record_Type (E))
12137 then
12138 Independence_Checks.Append ((N, E));
12139 Set_Has_Independent_Components (Base_Type (E));
12140
12141 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
12142 and then Nkind (D) = N_Object_Declaration
12143 and then Nkind (Object_Definition (D)) =
12144 N_Constrained_Array_Definition
12145 then
12146 Independence_Checks.Append ((N, E));
12147 Set_Has_Independent_Components (E);
12148
12149 else
12150 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
12151 end if;
12152 end Independent_Components;
12153
12154 ------------------------
12155 -- Initialize_Scalars --
12156 ------------------------
12157
12158 -- pragma Initialize_Scalars;
12159
12160 when Pragma_Initialize_Scalars =>
12161 GNAT_Pragma;
12162 Check_Arg_Count (0);
12163 Check_Valid_Configuration_Pragma;
12164 Check_Restriction (No_Initialize_Scalars, N);
12165
12166 -- Initialize_Scalars creates false positives in CodePeer, and
12167 -- incorrect negative results in Alfa mode, so ignore this pragma
12168 -- in these modes.
12169
12170 if not Restriction_Active (No_Initialize_Scalars)
12171 and then not (CodePeer_Mode or Alfa_Mode)
12172 then
12173 Init_Or_Norm_Scalars := True;
12174 Initialize_Scalars := True;
12175 end if;
12176
12177 ------------
12178 -- Inline --
12179 ------------
12180
12181 -- pragma Inline ( NAME {, NAME} );
12182
12183 when Pragma_Inline =>
12184
12185 -- Inline status is Enabled if inlining option is active
12186
12187 if Inline_Active then
12188 Process_Inline (Enabled);
12189 else
12190 Process_Inline (Disabled);
12191 end if;
12192
12193 -------------------
12194 -- Inline_Always --
12195 -------------------
12196
12197 -- pragma Inline_Always ( NAME {, NAME} );
12198
12199 when Pragma_Inline_Always =>
12200 GNAT_Pragma;
12201
12202 -- Pragma always active unless in CodePeer or Alfa mode, since
12203 -- this causes walk order issues.
12204
12205 if not (CodePeer_Mode or Alfa_Mode) then
12206 Process_Inline (Enabled);
12207 end if;
12208
12209 --------------------
12210 -- Inline_Generic --
12211 --------------------
12212
12213 -- pragma Inline_Generic (NAME {, NAME});
12214
12215 when Pragma_Inline_Generic =>
12216 GNAT_Pragma;
12217 Process_Generic_List;
12218
12219 ----------------------
12220 -- Inspection_Point --
12221 ----------------------
12222
12223 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
12224
12225 when Pragma_Inspection_Point => Inspection_Point : declare
12226 Arg : Node_Id;
12227 Exp : Node_Id;
12228
12229 begin
12230 if Arg_Count > 0 then
12231 Arg := Arg1;
12232 loop
12233 Exp := Get_Pragma_Arg (Arg);
12234 Analyze (Exp);
12235
12236 if not Is_Entity_Name (Exp)
12237 or else not Is_Object (Entity (Exp))
12238 then
12239 Error_Pragma_Arg ("object name required", Arg);
12240 end if;
12241
12242 Next (Arg);
12243 exit when No (Arg);
12244 end loop;
12245 end if;
12246 end Inspection_Point;
12247
12248 ---------------
12249 -- Interface --
12250 ---------------
12251
12252 -- pragma Interface (
12253 -- [ Convention =>] convention_IDENTIFIER,
12254 -- [ Entity =>] local_NAME
12255 -- [, [External_Name =>] static_string_EXPRESSION ]
12256 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12257
12258 when Pragma_Interface =>
12259 GNAT_Pragma;
12260 Check_Arg_Order
12261 ((Name_Convention,
12262 Name_Entity,
12263 Name_External_Name,
12264 Name_Link_Name));
12265 Check_At_Least_N_Arguments (2);
12266 Check_At_Most_N_Arguments (4);
12267 Process_Import_Or_Interface;
12268
12269 -- In Ada 2005, the permission to use Interface (a reserved word)
12270 -- as a pragma name is considered an obsolescent feature, and this
12271 -- pragma was already obsolescent in Ada 95.
12272
12273 if Ada_Version >= Ada_95 then
12274 Check_Restriction
12275 (No_Obsolescent_Features, Pragma_Identifier (N));
12276
12277 if Warn_On_Obsolescent_Feature then
12278 Error_Msg_N
12279 ("pragma Interface is an obsolescent feature?j?", N);
12280 Error_Msg_N
12281 ("|use pragma Import instead?j?", N);
12282 end if;
12283 end if;
12284
12285 --------------------
12286 -- Interface_Name --
12287 --------------------
12288
12289 -- pragma Interface_Name (
12290 -- [ Entity =>] local_NAME
12291 -- [,[External_Name =>] static_string_EXPRESSION ]
12292 -- [,[Link_Name =>] static_string_EXPRESSION ]);
12293
12294 when Pragma_Interface_Name => Interface_Name : declare
12295 Id : Node_Id;
12296 Def_Id : Entity_Id;
12297 Hom_Id : Entity_Id;
12298 Found : Boolean;
12299
12300 begin
12301 GNAT_Pragma;
12302 Check_Arg_Order
12303 ((Name_Entity, Name_External_Name, Name_Link_Name));
12304 Check_At_Least_N_Arguments (2);
12305 Check_At_Most_N_Arguments (3);
12306 Id := Get_Pragma_Arg (Arg1);
12307 Analyze (Id);
12308
12309 -- This is obsolete from Ada 95 on, but it is an implementation
12310 -- defined pragma, so we do not consider that it violates the
12311 -- restriction (No_Obsolescent_Features).
12312
12313 if Ada_Version >= Ada_95 then
12314 if Warn_On_Obsolescent_Feature then
12315 Error_Msg_N
12316 ("pragma Interface_Name is an obsolescent feature?j?", N);
12317 Error_Msg_N
12318 ("|use pragma Import instead?j?", N);
12319 end if;
12320 end if;
12321
12322 if not Is_Entity_Name (Id) then
12323 Error_Pragma_Arg
12324 ("first argument for pragma% must be entity name", Arg1);
12325 elsif Etype (Id) = Any_Type then
12326 return;
12327 else
12328 Def_Id := Entity (Id);
12329 end if;
12330
12331 -- Special DEC-compatible processing for the object case, forces
12332 -- object to be imported.
12333
12334 if Ekind (Def_Id) = E_Variable then
12335 Kill_Size_Check_Code (Def_Id);
12336 Note_Possible_Modification (Id, Sure => False);
12337
12338 -- Initialization is not allowed for imported variable
12339
12340 if Present (Expression (Parent (Def_Id)))
12341 and then Comes_From_Source (Expression (Parent (Def_Id)))
12342 then
12343 Error_Msg_Sloc := Sloc (Def_Id);
12344 Error_Pragma_Arg
12345 ("no initialization allowed for declaration of& #",
12346 Arg2);
12347
12348 else
12349 -- For compatibility, support VADS usage of providing both
12350 -- pragmas Interface and Interface_Name to obtain the effect
12351 -- of a single Import pragma.
12352
12353 if Is_Imported (Def_Id)
12354 and then Present (First_Rep_Item (Def_Id))
12355 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
12356 and then
12357 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
12358 then
12359 null;
12360 else
12361 Set_Imported (Def_Id);
12362 end if;
12363
12364 Set_Is_Public (Def_Id);
12365 Process_Interface_Name (Def_Id, Arg2, Arg3);
12366 end if;
12367
12368 -- Otherwise must be subprogram
12369
12370 elsif not Is_Subprogram (Def_Id) then
12371 Error_Pragma_Arg
12372 ("argument of pragma% is not subprogram", Arg1);
12373
12374 else
12375 Check_At_Most_N_Arguments (3);
12376 Hom_Id := Def_Id;
12377 Found := False;
12378
12379 -- Loop through homonyms
12380
12381 loop
12382 Def_Id := Get_Base_Subprogram (Hom_Id);
12383
12384 if Is_Imported (Def_Id) then
12385 Process_Interface_Name (Def_Id, Arg2, Arg3);
12386 Found := True;
12387 end if;
12388
12389 exit when From_Aspect_Specification (N);
12390 Hom_Id := Homonym (Hom_Id);
12391
12392 exit when No (Hom_Id)
12393 or else Scope (Hom_Id) /= Current_Scope;
12394 end loop;
12395
12396 if not Found then
12397 Error_Pragma_Arg
12398 ("argument of pragma% is not imported subprogram",
12399 Arg1);
12400 end if;
12401 end if;
12402 end Interface_Name;
12403
12404 -----------------------
12405 -- Interrupt_Handler --
12406 -----------------------
12407
12408 -- pragma Interrupt_Handler (handler_NAME);
12409
12410 when Pragma_Interrupt_Handler =>
12411 Check_Ada_83_Warning;
12412 Check_Arg_Count (1);
12413 Check_No_Identifiers;
12414
12415 if No_Run_Time_Mode then
12416 Error_Msg_CRT ("Interrupt_Handler pragma", N);
12417 else
12418 Check_Interrupt_Or_Attach_Handler;
12419 Process_Interrupt_Or_Attach_Handler;
12420 end if;
12421
12422 ------------------------
12423 -- Interrupt_Priority --
12424 ------------------------
12425
12426 -- pragma Interrupt_Priority [(EXPRESSION)];
12427
12428 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
12429 P : constant Node_Id := Parent (N);
12430 Arg : Node_Id;
12431 Ent : Entity_Id;
12432
12433 begin
12434 Check_Ada_83_Warning;
12435
12436 if Arg_Count /= 0 then
12437 Arg := Get_Pragma_Arg (Arg1);
12438 Check_Arg_Count (1);
12439 Check_No_Identifiers;
12440
12441 -- The expression must be analyzed in the special manner
12442 -- described in "Handling of Default and Per-Object
12443 -- Expressions" in sem.ads.
12444
12445 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
12446 end if;
12447
12448 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
12449 Pragma_Misplaced;
12450 return;
12451
12452 else
12453 Ent := Defining_Identifier (Parent (P));
12454
12455 -- Check duplicate pragma before we chain the pragma in the Rep
12456 -- Item chain of Ent.
12457
12458 Check_Duplicate_Pragma (Ent);
12459 Record_Rep_Item (Ent, N);
12460 end if;
12461 end Interrupt_Priority;
12462
12463 ---------------------
12464 -- Interrupt_State --
12465 ---------------------
12466
12467 -- pragma Interrupt_State (
12468 -- [Name =>] INTERRUPT_ID,
12469 -- [State =>] INTERRUPT_STATE);
12470
12471 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
12472 -- INTERRUPT_STATE => System | Runtime | User
12473
12474 -- Note: if the interrupt id is given as an identifier, then it must
12475 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
12476 -- given as a static integer expression which must be in the range of
12477 -- Ada.Interrupts.Interrupt_ID.
12478
12479 when Pragma_Interrupt_State => Interrupt_State : declare
12480
12481 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
12482 -- This is the entity Ada.Interrupts.Interrupt_ID;
12483
12484 State_Type : Character;
12485 -- Set to 's'/'r'/'u' for System/Runtime/User
12486
12487 IST_Num : Pos;
12488 -- Index to entry in Interrupt_States table
12489
12490 Int_Val : Uint;
12491 -- Value of interrupt
12492
12493 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
12494 -- The first argument to the pragma
12495
12496 Int_Ent : Entity_Id;
12497 -- Interrupt entity in Ada.Interrupts.Names
12498
12499 begin
12500 GNAT_Pragma;
12501 Check_Arg_Order ((Name_Name, Name_State));
12502 Check_Arg_Count (2);
12503
12504 Check_Optional_Identifier (Arg1, Name_Name);
12505 Check_Optional_Identifier (Arg2, Name_State);
12506 Check_Arg_Is_Identifier (Arg2);
12507
12508 -- First argument is identifier
12509
12510 if Nkind (Arg1X) = N_Identifier then
12511
12512 -- Search list of names in Ada.Interrupts.Names
12513
12514 Int_Ent := First_Entity (RTE (RE_Names));
12515 loop
12516 if No (Int_Ent) then
12517 Error_Pragma_Arg ("invalid interrupt name", Arg1);
12518
12519 elsif Chars (Int_Ent) = Chars (Arg1X) then
12520 Int_Val := Expr_Value (Constant_Value (Int_Ent));
12521 exit;
12522 end if;
12523
12524 Next_Entity (Int_Ent);
12525 end loop;
12526
12527 -- First argument is not an identifier, so it must be a static
12528 -- expression of type Ada.Interrupts.Interrupt_ID.
12529
12530 else
12531 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
12532 Int_Val := Expr_Value (Arg1X);
12533
12534 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
12535 or else
12536 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
12537 then
12538 Error_Pragma_Arg
12539 ("value not in range of type "
12540 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
12541 end if;
12542 end if;
12543
12544 -- Check OK state
12545
12546 case Chars (Get_Pragma_Arg (Arg2)) is
12547 when Name_Runtime => State_Type := 'r';
12548 when Name_System => State_Type := 's';
12549 when Name_User => State_Type := 'u';
12550
12551 when others =>
12552 Error_Pragma_Arg ("invalid interrupt state", Arg2);
12553 end case;
12554
12555 -- Check if entry is already stored
12556
12557 IST_Num := Interrupt_States.First;
12558 loop
12559 -- If entry not found, add it
12560
12561 if IST_Num > Interrupt_States.Last then
12562 Interrupt_States.Append
12563 ((Interrupt_Number => UI_To_Int (Int_Val),
12564 Interrupt_State => State_Type,
12565 Pragma_Loc => Loc));
12566 exit;
12567
12568 -- Case of entry for the same entry
12569
12570 elsif Int_Val = Interrupt_States.Table (IST_Num).
12571 Interrupt_Number
12572 then
12573 -- If state matches, done, no need to make redundant entry
12574
12575 exit when
12576 State_Type = Interrupt_States.Table (IST_Num).
12577 Interrupt_State;
12578
12579 -- Otherwise if state does not match, error
12580
12581 Error_Msg_Sloc :=
12582 Interrupt_States.Table (IST_Num).Pragma_Loc;
12583 Error_Pragma_Arg
12584 ("state conflicts with that given #", Arg2);
12585 exit;
12586 end if;
12587
12588 IST_Num := IST_Num + 1;
12589 end loop;
12590 end Interrupt_State;
12591
12592 ---------------
12593 -- Invariant --
12594 ---------------
12595
12596 -- pragma Invariant
12597 -- ([Entity =>] type_LOCAL_NAME,
12598 -- [Check =>] EXPRESSION
12599 -- [,[Message =>] String_Expression]);
12600
12601 when Pragma_Invariant => Invariant : declare
12602 Type_Id : Node_Id;
12603 Typ : Entity_Id;
12604 PDecl : Node_Id;
12605
12606 Discard : Boolean;
12607 pragma Unreferenced (Discard);
12608
12609 begin
12610 GNAT_Pragma;
12611 Check_At_Least_N_Arguments (2);
12612 Check_At_Most_N_Arguments (3);
12613 Check_Optional_Identifier (Arg1, Name_Entity);
12614 Check_Optional_Identifier (Arg2, Name_Check);
12615
12616 if Arg_Count = 3 then
12617 Check_Optional_Identifier (Arg3, Name_Message);
12618 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
12619 end if;
12620
12621 Check_Arg_Is_Local_Name (Arg1);
12622
12623 Type_Id := Get_Pragma_Arg (Arg1);
12624 Find_Type (Type_Id);
12625 Typ := Entity (Type_Id);
12626
12627 if Typ = Any_Type then
12628 return;
12629
12630 -- An invariant must apply to a private type, or appear in the
12631 -- private part of a package spec and apply to a completion.
12632
12633 elsif Ekind_In (Typ, E_Private_Type,
12634 E_Record_Type_With_Private,
12635 E_Limited_Private_Type)
12636 then
12637 null;
12638
12639 elsif In_Private_Part (Current_Scope)
12640 and then Has_Private_Declaration (Typ)
12641 then
12642 null;
12643
12644 elsif In_Private_Part (Current_Scope) then
12645 Error_Pragma_Arg
12646 ("pragma% only allowed for private type declared in "
12647 & "visible part", Arg1);
12648
12649 else
12650 Error_Pragma_Arg
12651 ("pragma% only allowed for private type", Arg1);
12652 end if;
12653
12654 -- Note that the type has at least one invariant, and also that
12655 -- it has inheritable invariants if we have Invariant'Class.
12656 -- Build the corresponding invariant procedure declaration, so
12657 -- that calls to it can be generated before the body is built
12658 -- (for example wihin an expression function).
12659
12660 PDecl := Build_Invariant_Procedure_Declaration (Typ);
12661 Insert_After (N, PDecl);
12662 Analyze (PDecl);
12663
12664 if Class_Present (N) then
12665 Set_Has_Inheritable_Invariants (Typ);
12666 end if;
12667
12668 -- The remaining processing is simply to link the pragma on to
12669 -- the rep item chain, for processing when the type is frozen.
12670 -- This is accomplished by a call to Rep_Item_Too_Late.
12671
12672 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12673 end Invariant;
12674
12675 ----------------------
12676 -- Java_Constructor --
12677 ----------------------
12678
12679 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
12680
12681 -- Also handles pragma CIL_Constructor
12682
12683 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
12684 Java_Constructor : declare
12685 Convention : Convention_Id;
12686 Def_Id : Entity_Id;
12687 Hom_Id : Entity_Id;
12688 Id : Entity_Id;
12689 This_Formal : Entity_Id;
12690
12691 begin
12692 GNAT_Pragma;
12693 Check_Arg_Count (1);
12694 Check_Optional_Identifier (Arg1, Name_Entity);
12695 Check_Arg_Is_Local_Name (Arg1);
12696
12697 Id := Get_Pragma_Arg (Arg1);
12698 Find_Program_Unit_Name (Id);
12699
12700 -- If we did not find the name, we are done
12701
12702 if Etype (Id) = Any_Type then
12703 return;
12704 end if;
12705
12706 -- Check wrong use of pragma in wrong VM target
12707
12708 if VM_Target = No_VM then
12709 return;
12710
12711 elsif VM_Target = CLI_Target
12712 and then Prag_Id = Pragma_Java_Constructor
12713 then
12714 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
12715
12716 elsif VM_Target = JVM_Target
12717 and then Prag_Id = Pragma_CIL_Constructor
12718 then
12719 Error_Pragma ("must use pragma 'Java_'Constructor");
12720 end if;
12721
12722 case Prag_Id is
12723 when Pragma_CIL_Constructor => Convention := Convention_CIL;
12724 when Pragma_Java_Constructor => Convention := Convention_Java;
12725 when others => null;
12726 end case;
12727
12728 Hom_Id := Entity (Id);
12729
12730 -- Loop through homonyms
12731
12732 loop
12733 Def_Id := Get_Base_Subprogram (Hom_Id);
12734
12735 -- The constructor is required to be a function
12736
12737 if Ekind (Def_Id) /= E_Function then
12738 if VM_Target = JVM_Target then
12739 Error_Pragma_Arg
12740 ("pragma% requires function returning a 'Java access "
12741 & "type", Def_Id);
12742 else
12743 Error_Pragma_Arg
12744 ("pragma% requires function returning a 'C'I'L access "
12745 & "type", Def_Id);
12746 end if;
12747 end if;
12748
12749 -- Check arguments: For tagged type the first formal must be
12750 -- named "this" and its type must be a named access type
12751 -- designating a class-wide tagged type that has convention
12752 -- CIL/Java. The first formal must also have a null default
12753 -- value. For example:
12754
12755 -- type Typ is tagged ...
12756 -- type Ref is access all Typ;
12757 -- pragma Convention (CIL, Typ);
12758
12759 -- function New_Typ (This : Ref) return Ref;
12760 -- function New_Typ (This : Ref; I : Integer) return Ref;
12761 -- pragma Cil_Constructor (New_Typ);
12762
12763 -- Reason: The first formal must NOT be a primitive of the
12764 -- tagged type.
12765
12766 -- This rule also applies to constructors of delegates used
12767 -- to interface with standard target libraries. For example:
12768
12769 -- type Delegate is access procedure ...
12770 -- pragma Import (CIL, Delegate, ...);
12771
12772 -- function new_Delegate
12773 -- (This : Delegate := null; ... ) return Delegate;
12774
12775 -- For value-types this rule does not apply.
12776
12777 if not Is_Value_Type (Etype (Def_Id)) then
12778 if No (First_Formal (Def_Id)) then
12779 Error_Msg_Name_1 := Pname;
12780 Error_Msg_N ("% function must have parameters", Def_Id);
12781 return;
12782 end if;
12783
12784 -- In the JRE library we have several occurrences in which
12785 -- the "this" parameter is not the first formal.
12786
12787 This_Formal := First_Formal (Def_Id);
12788
12789 -- In the JRE library we have several occurrences in which
12790 -- the "this" parameter is not the first formal. Search for
12791 -- it.
12792
12793 if VM_Target = JVM_Target then
12794 while Present (This_Formal)
12795 and then Get_Name_String (Chars (This_Formal)) /= "this"
12796 loop
12797 Next_Formal (This_Formal);
12798 end loop;
12799
12800 if No (This_Formal) then
12801 This_Formal := First_Formal (Def_Id);
12802 end if;
12803 end if;
12804
12805 -- Warning: The first parameter should be named "this".
12806 -- We temporarily allow it because we have the following
12807 -- case in the Java runtime (file s-osinte.ads) ???
12808
12809 -- function new_Thread
12810 -- (Self_Id : System.Address) return Thread_Id;
12811 -- pragma Java_Constructor (new_Thread);
12812
12813 if VM_Target = JVM_Target
12814 and then Get_Name_String (Chars (First_Formal (Def_Id)))
12815 = "self_id"
12816 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
12817 then
12818 null;
12819
12820 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
12821 Error_Msg_Name_1 := Pname;
12822 Error_Msg_N
12823 ("first formal of % function must be named `this`",
12824 Parent (This_Formal));
12825
12826 elsif not Is_Access_Type (Etype (This_Formal)) then
12827 Error_Msg_Name_1 := Pname;
12828 Error_Msg_N
12829 ("first formal of % function must be an access type",
12830 Parameter_Type (Parent (This_Formal)));
12831
12832 -- For delegates the type of the first formal must be a
12833 -- named access-to-subprogram type (see previous example)
12834
12835 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
12836 and then Ekind (Etype (This_Formal))
12837 /= E_Access_Subprogram_Type
12838 then
12839 Error_Msg_Name_1 := Pname;
12840 Error_Msg_N
12841 ("first formal of % function must be a named access "
12842 & "to subprogram type",
12843 Parameter_Type (Parent (This_Formal)));
12844
12845 -- Warning: We should reject anonymous access types because
12846 -- the constructor must not be handled as a primitive of the
12847 -- tagged type. We temporarily allow it because this profile
12848 -- is currently generated by cil2ada???
12849
12850 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
12851 and then not Ekind_In (Etype (This_Formal),
12852 E_Access_Type,
12853 E_General_Access_Type,
12854 E_Anonymous_Access_Type)
12855 then
12856 Error_Msg_Name_1 := Pname;
12857 Error_Msg_N
12858 ("first formal of % function must be a named access "
12859 & "type", Parameter_Type (Parent (This_Formal)));
12860
12861 elsif Atree.Convention
12862 (Designated_Type (Etype (This_Formal))) /= Convention
12863 then
12864 Error_Msg_Name_1 := Pname;
12865
12866 if Convention = Convention_Java then
12867 Error_Msg_N
12868 ("pragma% requires convention 'Cil in designated "
12869 & "type", Parameter_Type (Parent (This_Formal)));
12870 else
12871 Error_Msg_N
12872 ("pragma% requires convention 'Java in designated "
12873 & "type", Parameter_Type (Parent (This_Formal)));
12874 end if;
12875
12876 elsif No (Expression (Parent (This_Formal)))
12877 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
12878 then
12879 Error_Msg_Name_1 := Pname;
12880 Error_Msg_N
12881 ("pragma% requires first formal with default `null`",
12882 Parameter_Type (Parent (This_Formal)));
12883 end if;
12884 end if;
12885
12886 -- Check result type: the constructor must be a function
12887 -- returning:
12888 -- * a value type (only allowed in the CIL compiler)
12889 -- * an access-to-subprogram type with convention Java/CIL
12890 -- * an access-type designating a type that has convention
12891 -- Java/CIL.
12892
12893 if Is_Value_Type (Etype (Def_Id)) then
12894 null;
12895
12896 -- Access-to-subprogram type with convention Java/CIL
12897
12898 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
12899 if Atree.Convention (Etype (Def_Id)) /= Convention then
12900 if Convention = Convention_Java then
12901 Error_Pragma_Arg
12902 ("pragma% requires function returning a 'Java "
12903 & "access type", Arg1);
12904 else
12905 pragma Assert (Convention = Convention_CIL);
12906 Error_Pragma_Arg
12907 ("pragma% requires function returning a 'C'I'L "
12908 & "access type", Arg1);
12909 end if;
12910 end if;
12911
12912 elsif Ekind (Etype (Def_Id)) in Access_Kind then
12913 if not Ekind_In (Etype (Def_Id), E_Access_Type,
12914 E_General_Access_Type)
12915 or else
12916 Atree.Convention
12917 (Designated_Type (Etype (Def_Id))) /= Convention
12918 then
12919 Error_Msg_Name_1 := Pname;
12920
12921 if Convention = Convention_Java then
12922 Error_Pragma_Arg
12923 ("pragma% requires function returning a named "
12924 & "'Java access type", Arg1);
12925 else
12926 Error_Pragma_Arg
12927 ("pragma% requires function returning a named "
12928 & "'C'I'L access type", Arg1);
12929 end if;
12930 end if;
12931 end if;
12932
12933 Set_Is_Constructor (Def_Id);
12934 Set_Convention (Def_Id, Convention);
12935 Set_Is_Imported (Def_Id);
12936
12937 exit when From_Aspect_Specification (N);
12938 Hom_Id := Homonym (Hom_Id);
12939
12940 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
12941 end loop;
12942 end Java_Constructor;
12943
12944 ----------------------
12945 -- Java_Interface --
12946 ----------------------
12947
12948 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
12949
12950 when Pragma_Java_Interface => Java_Interface : declare
12951 Arg : Node_Id;
12952 Typ : Entity_Id;
12953
12954 begin
12955 GNAT_Pragma;
12956 Check_Arg_Count (1);
12957 Check_Optional_Identifier (Arg1, Name_Entity);
12958 Check_Arg_Is_Local_Name (Arg1);
12959
12960 Arg := Get_Pragma_Arg (Arg1);
12961 Analyze (Arg);
12962
12963 if Etype (Arg) = Any_Type then
12964 return;
12965 end if;
12966
12967 if not Is_Entity_Name (Arg)
12968 or else not Is_Type (Entity (Arg))
12969 then
12970 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
12971 end if;
12972
12973 Typ := Underlying_Type (Entity (Arg));
12974
12975 -- For now simply check some of the semantic constraints on the
12976 -- type. This currently leaves out some restrictions on interface
12977 -- types, namely that the parent type must be java.lang.Object.Typ
12978 -- and that all primitives of the type should be declared
12979 -- abstract. ???
12980
12981 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
12982 Error_Pragma_Arg ("pragma% requires an abstract "
12983 & "tagged type", Arg1);
12984
12985 elsif not Has_Discriminants (Typ)
12986 or else Ekind (Etype (First_Discriminant (Typ)))
12987 /= E_Anonymous_Access_Type
12988 or else
12989 not Is_Class_Wide_Type
12990 (Designated_Type (Etype (First_Discriminant (Typ))))
12991 then
12992 Error_Pragma_Arg
12993 ("type must have a class-wide access discriminant", Arg1);
12994 end if;
12995 end Java_Interface;
12996
12997 ----------------
12998 -- Keep_Names --
12999 ----------------
13000
13001 -- pragma Keep_Names ([On => ] local_NAME);
13002
13003 when Pragma_Keep_Names => Keep_Names : declare
13004 Arg : Node_Id;
13005
13006 begin
13007 GNAT_Pragma;
13008 Check_Arg_Count (1);
13009 Check_Optional_Identifier (Arg1, Name_On);
13010 Check_Arg_Is_Local_Name (Arg1);
13011
13012 Arg := Get_Pragma_Arg (Arg1);
13013 Analyze (Arg);
13014
13015 if Etype (Arg) = Any_Type then
13016 return;
13017 end if;
13018
13019 if not Is_Entity_Name (Arg)
13020 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
13021 then
13022 Error_Pragma_Arg
13023 ("pragma% requires a local enumeration type", Arg1);
13024 end if;
13025
13026 Set_Discard_Names (Entity (Arg), False);
13027 end Keep_Names;
13028
13029 -------------
13030 -- License --
13031 -------------
13032
13033 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
13034
13035 when Pragma_License =>
13036 GNAT_Pragma;
13037 Check_Arg_Count (1);
13038 Check_No_Identifiers;
13039 Check_Valid_Configuration_Pragma;
13040 Check_Arg_Is_Identifier (Arg1);
13041
13042 declare
13043 Sind : constant Source_File_Index :=
13044 Source_Index (Current_Sem_Unit);
13045
13046 begin
13047 case Chars (Get_Pragma_Arg (Arg1)) is
13048 when Name_GPL =>
13049 Set_License (Sind, GPL);
13050
13051 when Name_Modified_GPL =>
13052 Set_License (Sind, Modified_GPL);
13053
13054 when Name_Restricted =>
13055 Set_License (Sind, Restricted);
13056
13057 when Name_Unrestricted =>
13058 Set_License (Sind, Unrestricted);
13059
13060 when others =>
13061 Error_Pragma_Arg ("invalid license name", Arg1);
13062 end case;
13063 end;
13064
13065 ---------------
13066 -- Link_With --
13067 ---------------
13068
13069 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
13070
13071 when Pragma_Link_With => Link_With : declare
13072 Arg : Node_Id;
13073
13074 begin
13075 GNAT_Pragma;
13076
13077 if Operating_Mode = Generate_Code
13078 and then In_Extended_Main_Source_Unit (N)
13079 then
13080 Check_At_Least_N_Arguments (1);
13081 Check_No_Identifiers;
13082 Check_Is_In_Decl_Part_Or_Package_Spec;
13083 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13084 Start_String;
13085
13086 Arg := Arg1;
13087 while Present (Arg) loop
13088 Check_Arg_Is_Static_Expression (Arg, Standard_String);
13089
13090 -- Store argument, converting sequences of spaces to a
13091 -- single null character (this is one of the differences
13092 -- in processing between Link_With and Linker_Options).
13093
13094 Arg_Store : declare
13095 C : constant Char_Code := Get_Char_Code (' ');
13096 S : constant String_Id :=
13097 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
13098 L : constant Nat := String_Length (S);
13099 F : Nat := 1;
13100
13101 procedure Skip_Spaces;
13102 -- Advance F past any spaces
13103
13104 -----------------
13105 -- Skip_Spaces --
13106 -----------------
13107
13108 procedure Skip_Spaces is
13109 begin
13110 while F <= L and then Get_String_Char (S, F) = C loop
13111 F := F + 1;
13112 end loop;
13113 end Skip_Spaces;
13114
13115 -- Start of processing for Arg_Store
13116
13117 begin
13118 Skip_Spaces; -- skip leading spaces
13119
13120 -- Loop through characters, changing any embedded
13121 -- sequence of spaces to a single null character (this
13122 -- is how Link_With/Linker_Options differ)
13123
13124 while F <= L loop
13125 if Get_String_Char (S, F) = C then
13126 Skip_Spaces;
13127 exit when F > L;
13128 Store_String_Char (ASCII.NUL);
13129
13130 else
13131 Store_String_Char (Get_String_Char (S, F));
13132 F := F + 1;
13133 end if;
13134 end loop;
13135 end Arg_Store;
13136
13137 Arg := Next (Arg);
13138
13139 if Present (Arg) then
13140 Store_String_Char (ASCII.NUL);
13141 end if;
13142 end loop;
13143
13144 Store_Linker_Option_String (End_String);
13145 end if;
13146 end Link_With;
13147
13148 ------------------
13149 -- Linker_Alias --
13150 ------------------
13151
13152 -- pragma Linker_Alias (
13153 -- [Entity =>] LOCAL_NAME
13154 -- [Target =>] static_string_EXPRESSION);
13155
13156 when Pragma_Linker_Alias =>
13157 GNAT_Pragma;
13158 Check_Arg_Order ((Name_Entity, Name_Target));
13159 Check_Arg_Count (2);
13160 Check_Optional_Identifier (Arg1, Name_Entity);
13161 Check_Optional_Identifier (Arg2, Name_Target);
13162 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13163 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
13164
13165 -- The only processing required is to link this item on to the
13166 -- list of rep items for the given entity. This is accomplished
13167 -- by the call to Rep_Item_Too_Late (when no error is detected
13168 -- and False is returned).
13169
13170 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
13171 return;
13172 else
13173 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
13174 end if;
13175
13176 ------------------------
13177 -- Linker_Constructor --
13178 ------------------------
13179
13180 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
13181
13182 -- Code is shared with Linker_Destructor
13183
13184 -----------------------
13185 -- Linker_Destructor --
13186 -----------------------
13187
13188 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
13189
13190 when Pragma_Linker_Constructor |
13191 Pragma_Linker_Destructor =>
13192 Linker_Constructor : declare
13193 Arg1_X : Node_Id;
13194 Proc : Entity_Id;
13195
13196 begin
13197 GNAT_Pragma;
13198 Check_Arg_Count (1);
13199 Check_No_Identifiers;
13200 Check_Arg_Is_Local_Name (Arg1);
13201 Arg1_X := Get_Pragma_Arg (Arg1);
13202 Analyze (Arg1_X);
13203 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
13204
13205 if not Is_Library_Level_Entity (Proc) then
13206 Error_Pragma_Arg
13207 ("argument for pragma% must be library level entity", Arg1);
13208 end if;
13209
13210 -- The only processing required is to link this item on to the
13211 -- list of rep items for the given entity. This is accomplished
13212 -- by the call to Rep_Item_Too_Late (when no error is detected
13213 -- and False is returned).
13214
13215 if Rep_Item_Too_Late (Proc, N) then
13216 return;
13217 else
13218 Set_Has_Gigi_Rep_Item (Proc);
13219 end if;
13220 end Linker_Constructor;
13221
13222 --------------------
13223 -- Linker_Options --
13224 --------------------
13225
13226 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
13227
13228 when Pragma_Linker_Options => Linker_Options : declare
13229 Arg : Node_Id;
13230
13231 begin
13232 Check_Ada_83_Warning;
13233 Check_No_Identifiers;
13234 Check_Arg_Count (1);
13235 Check_Is_In_Decl_Part_Or_Package_Spec;
13236 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13237 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
13238
13239 Arg := Arg2;
13240 while Present (Arg) loop
13241 Check_Arg_Is_Static_Expression (Arg, Standard_String);
13242 Store_String_Char (ASCII.NUL);
13243 Store_String_Chars
13244 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
13245 Arg := Next (Arg);
13246 end loop;
13247
13248 if Operating_Mode = Generate_Code
13249 and then In_Extended_Main_Source_Unit (N)
13250 then
13251 Store_Linker_Option_String (End_String);
13252 end if;
13253 end Linker_Options;
13254
13255 --------------------
13256 -- Linker_Section --
13257 --------------------
13258
13259 -- pragma Linker_Section (
13260 -- [Entity =>] LOCAL_NAME
13261 -- [Section =>] static_string_EXPRESSION);
13262
13263 when Pragma_Linker_Section =>
13264 GNAT_Pragma;
13265 Check_Arg_Order ((Name_Entity, Name_Section));
13266 Check_Arg_Count (2);
13267 Check_Optional_Identifier (Arg1, Name_Entity);
13268 Check_Optional_Identifier (Arg2, Name_Section);
13269 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13270 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
13271
13272 -- This pragma applies only to objects
13273
13274 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
13275 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
13276 end if;
13277
13278 -- The only processing required is to link this item on to the
13279 -- list of rep items for the given entity. This is accomplished
13280 -- by the call to Rep_Item_Too_Late (when no error is detected
13281 -- and False is returned).
13282
13283 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
13284 return;
13285 else
13286 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
13287 end if;
13288
13289 ----------
13290 -- List --
13291 ----------
13292
13293 -- pragma List (On | Off)
13294
13295 -- There is nothing to do here, since we did all the processing for
13296 -- this pragma in Par.Prag (so that it works properly even in syntax
13297 -- only mode).
13298
13299 when Pragma_List =>
13300 null;
13301
13302 ---------------
13303 -- Lock_Free --
13304 ---------------
13305
13306 -- pragma Lock_Free [(Boolean_EXPRESSION)];
13307
13308 when Pragma_Lock_Free => Lock_Free : declare
13309 P : constant Node_Id := Parent (N);
13310 Arg : Node_Id;
13311 Ent : Entity_Id;
13312 Val : Boolean;
13313
13314 begin
13315 Check_No_Identifiers;
13316 Check_At_Most_N_Arguments (1);
13317
13318 -- Protected definition case
13319
13320 if Nkind (P) = N_Protected_Definition then
13321 Ent := Defining_Identifier (Parent (P));
13322
13323 -- One argument
13324
13325 if Arg_Count = 1 then
13326 Arg := Get_Pragma_Arg (Arg1);
13327 Val := Is_True (Static_Boolean (Arg));
13328
13329 -- No arguments (expression is considered to be True)
13330
13331 else
13332 Val := True;
13333 end if;
13334
13335 -- Check duplicate pragma before we chain the pragma in the Rep
13336 -- Item chain of Ent.
13337
13338 Check_Duplicate_Pragma (Ent);
13339 Record_Rep_Item (Ent, N);
13340 Set_Uses_Lock_Free (Ent, Val);
13341
13342 -- Anything else is incorrect placement
13343
13344 else
13345 Pragma_Misplaced;
13346 end if;
13347 end Lock_Free;
13348
13349 --------------------
13350 -- Locking_Policy --
13351 --------------------
13352
13353 -- pragma Locking_Policy (policy_IDENTIFIER);
13354
13355 when Pragma_Locking_Policy => declare
13356 subtype LP_Range is Name_Id
13357 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
13358 LP_Val : LP_Range;
13359 LP : Character;
13360
13361 begin
13362 Check_Ada_83_Warning;
13363 Check_Arg_Count (1);
13364 Check_No_Identifiers;
13365 Check_Arg_Is_Locking_Policy (Arg1);
13366 Check_Valid_Configuration_Pragma;
13367 LP_Val := Chars (Get_Pragma_Arg (Arg1));
13368
13369 case LP_Val is
13370 when Name_Ceiling_Locking =>
13371 LP := 'C';
13372 when Name_Inheritance_Locking =>
13373 LP := 'I';
13374 when Name_Concurrent_Readers_Locking =>
13375 LP := 'R';
13376 end case;
13377
13378 if Locking_Policy /= ' '
13379 and then Locking_Policy /= LP
13380 then
13381 Error_Msg_Sloc := Locking_Policy_Sloc;
13382 Error_Pragma ("locking policy incompatible with policy#");
13383
13384 -- Set new policy, but always preserve System_Location since we
13385 -- like the error message with the run time name.
13386
13387 else
13388 Locking_Policy := LP;
13389
13390 if Locking_Policy_Sloc /= System_Location then
13391 Locking_Policy_Sloc := Loc;
13392 end if;
13393 end if;
13394 end;
13395
13396 ----------------
13397 -- Long_Float --
13398 ----------------
13399
13400 -- pragma Long_Float (D_Float | G_Float);
13401
13402 when Pragma_Long_Float => Long_Float : declare
13403 begin
13404 GNAT_Pragma;
13405 Check_Valid_Configuration_Pragma;
13406 Check_Arg_Count (1);
13407 Check_No_Identifier (Arg1);
13408 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
13409
13410 if not OpenVMS_On_Target then
13411 Error_Pragma ("??pragma% ignored (applies only to Open'V'M'S)");
13412 end if;
13413
13414 -- D_Float case
13415
13416 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
13417 if Opt.Float_Format_Long = 'G' then
13418 Error_Pragma_Arg
13419 ("G_Float previously specified", Arg1);
13420
13421 elsif Current_Sem_Unit /= Main_Unit
13422 and then Opt.Float_Format_Long /= 'D'
13423 then
13424 Error_Pragma_Arg
13425 ("main unit not compiled with pragma Long_Float (D_Float)",
13426 "\pragma% must be used consistently for whole partition",
13427 Arg1);
13428
13429 else
13430 Opt.Float_Format_Long := 'D';
13431 end if;
13432
13433 -- G_Float case (this is the default, does not need overriding)
13434
13435 else
13436 if Opt.Float_Format_Long = 'D' then
13437 Error_Pragma ("D_Float previously specified");
13438
13439 elsif Current_Sem_Unit /= Main_Unit
13440 and then Opt.Float_Format_Long /= 'G'
13441 then
13442 Error_Pragma_Arg
13443 ("main unit not compiled with pragma Long_Float (G_Float)",
13444 "\pragma% must be used consistently for whole partition",
13445 Arg1);
13446
13447 else
13448 Opt.Float_Format_Long := 'G';
13449 end if;
13450 end if;
13451
13452 Set_Standard_Fpt_Formats;
13453 end Long_Float;
13454
13455 --------------------
13456 -- Loop_Invariant --
13457 --------------------
13458
13459 -- pragma Loop_Invariant ( boolean_EXPRESSION );
13460
13461 when Pragma_Loop_Invariant => Loop_Invariant : declare
13462 begin
13463 GNAT_Pragma;
13464 S14_Pragma;
13465 Check_Arg_Count (1);
13466 Check_Loop_Pragma_Placement;
13467
13468 -- Completely ignore if disabled
13469
13470 if not Check_Enabled (Pname) then
13471 Rewrite (N, Make_Null_Statement (Loc));
13472 Analyze (N);
13473 return;
13474 end if;
13475
13476 Preanalyze_And_Resolve (Expression (Arg1), Any_Boolean);
13477
13478 -- Transform pragma Loop_Invariant into equivalent pragma Check
13479 -- Generate:
13480 -- pragma Check (Loop_Invaraint, Arg1);
13481
13482 -- Seems completely wrong to hijack pragma Check this way ???
13483
13484 Rewrite (N,
13485 Make_Pragma (Loc,
13486 Chars => Name_Check,
13487 Pragma_Argument_Associations => New_List (
13488 Make_Pragma_Argument_Association (Loc,
13489 Expression => Make_Identifier (Loc, Name_Loop_Invariant)),
13490 Relocate_Node (Arg1))));
13491
13492 Analyze (N);
13493 end Loop_Invariant;
13494
13495 -------------------
13496 -- Loop_Optimize --
13497 -------------------
13498
13499 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
13500
13501 -- OPTIMIZATION_HINT ::= No_Unroll | Unroll | No_Vector | Vector
13502
13503 when Pragma_Loop_Optimize => Loop_Optimize : declare
13504 Hint : Node_Id;
13505
13506 begin
13507 GNAT_Pragma;
13508 Check_At_Least_N_Arguments (1);
13509 Check_No_Identifiers;
13510
13511 Hint := First (Pragma_Argument_Associations (N));
13512 while Present (Hint) loop
13513 Check_Arg_Is_One_Of (Hint,
13514 Name_No_Unroll, Name_Unroll, Name_No_Vector, Name_Vector);
13515 Next (Hint);
13516 end loop;
13517
13518 Check_Loop_Pragma_Placement;
13519 end Loop_Optimize;
13520
13521 ------------------
13522 -- Loop_Variant --
13523 ------------------
13524
13525 -- pragma Loop_Variant
13526 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
13527
13528 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
13529
13530 -- CHANGE_DIRECTION ::= Increases | Decreases
13531
13532 when Pragma_Loop_Variant => Loop_Variant : declare
13533 Variant : Node_Id;
13534
13535 begin
13536 GNAT_Pragma;
13537 S14_Pragma;
13538 Check_At_Least_N_Arguments (1);
13539 Check_Loop_Pragma_Placement;
13540
13541 -- Completely ignore if disabled
13542
13543 if not Check_Enabled (Pname) then
13544 Rewrite (N, Make_Null_Statement (Loc));
13545 Analyze (N);
13546 return;
13547 end if;
13548
13549 -- Process all increasing / decreasing expressions
13550
13551 Variant := First (Pragma_Argument_Associations (N));
13552 while Present (Variant) loop
13553 if Chars (Variant) /= Name_Decreases
13554 and then Chars (Variant) /= Name_Increases
13555 then
13556 Error_Pragma_Arg ("wrong change modifier", Variant);
13557 end if;
13558
13559 Preanalyze_And_Resolve (Expression (Variant), Any_Discrete);
13560
13561 Next (Variant);
13562 end loop;
13563 end Loop_Variant;
13564
13565 -----------------------
13566 -- Machine_Attribute --
13567 -----------------------
13568
13569 -- pragma Machine_Attribute (
13570 -- [Entity =>] LOCAL_NAME,
13571 -- [Attribute_Name =>] static_string_EXPRESSION
13572 -- [, [Info =>] static_EXPRESSION] );
13573
13574 when Pragma_Machine_Attribute => Machine_Attribute : declare
13575 Def_Id : Entity_Id;
13576
13577 begin
13578 GNAT_Pragma;
13579 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
13580
13581 if Arg_Count = 3 then
13582 Check_Optional_Identifier (Arg3, Name_Info);
13583 Check_Arg_Is_Static_Expression (Arg3);
13584 else
13585 Check_Arg_Count (2);
13586 end if;
13587
13588 Check_Optional_Identifier (Arg1, Name_Entity);
13589 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
13590 Check_Arg_Is_Local_Name (Arg1);
13591 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
13592 Def_Id := Entity (Get_Pragma_Arg (Arg1));
13593
13594 if Is_Access_Type (Def_Id) then
13595 Def_Id := Designated_Type (Def_Id);
13596 end if;
13597
13598 if Rep_Item_Too_Early (Def_Id, N) then
13599 return;
13600 end if;
13601
13602 Def_Id := Underlying_Type (Def_Id);
13603
13604 -- The only processing required is to link this item on to the
13605 -- list of rep items for the given entity. This is accomplished
13606 -- by the call to Rep_Item_Too_Late (when no error is detected
13607 -- and False is returned).
13608
13609 if Rep_Item_Too_Late (Def_Id, N) then
13610 return;
13611 else
13612 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
13613 end if;
13614 end Machine_Attribute;
13615
13616 ----------
13617 -- Main --
13618 ----------
13619
13620 -- pragma Main
13621 -- (MAIN_OPTION [, MAIN_OPTION]);
13622
13623 -- MAIN_OPTION ::=
13624 -- [STACK_SIZE =>] static_integer_EXPRESSION
13625 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
13626 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
13627
13628 when Pragma_Main => Main : declare
13629 Args : Args_List (1 .. 3);
13630 Names : constant Name_List (1 .. 3) := (
13631 Name_Stack_Size,
13632 Name_Task_Stack_Size_Default,
13633 Name_Time_Slicing_Enabled);
13634
13635 Nod : Node_Id;
13636
13637 begin
13638 GNAT_Pragma;
13639 Gather_Associations (Names, Args);
13640
13641 for J in 1 .. 2 loop
13642 if Present (Args (J)) then
13643 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
13644 end if;
13645 end loop;
13646
13647 if Present (Args (3)) then
13648 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
13649 end if;
13650
13651 Nod := Next (N);
13652 while Present (Nod) loop
13653 if Nkind (Nod) = N_Pragma
13654 and then Pragma_Name (Nod) = Name_Main
13655 then
13656 Error_Msg_Name_1 := Pname;
13657 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13658 end if;
13659
13660 Next (Nod);
13661 end loop;
13662 end Main;
13663
13664 ------------------
13665 -- Main_Storage --
13666 ------------------
13667
13668 -- pragma Main_Storage
13669 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
13670
13671 -- MAIN_STORAGE_OPTION ::=
13672 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
13673 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
13674
13675 when Pragma_Main_Storage => Main_Storage : declare
13676 Args : Args_List (1 .. 2);
13677 Names : constant Name_List (1 .. 2) := (
13678 Name_Working_Storage,
13679 Name_Top_Guard);
13680
13681 Nod : Node_Id;
13682
13683 begin
13684 GNAT_Pragma;
13685 Gather_Associations (Names, Args);
13686
13687 for J in 1 .. 2 loop
13688 if Present (Args (J)) then
13689 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
13690 end if;
13691 end loop;
13692
13693 Check_In_Main_Program;
13694
13695 Nod := Next (N);
13696 while Present (Nod) loop
13697 if Nkind (Nod) = N_Pragma
13698 and then Pragma_Name (Nod) = Name_Main_Storage
13699 then
13700 Error_Msg_Name_1 := Pname;
13701 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13702 end if;
13703
13704 Next (Nod);
13705 end loop;
13706 end Main_Storage;
13707
13708 -----------------
13709 -- Memory_Size --
13710 -----------------
13711
13712 -- pragma Memory_Size (NUMERIC_LITERAL)
13713
13714 when Pragma_Memory_Size =>
13715 GNAT_Pragma;
13716
13717 -- Memory size is simply ignored
13718
13719 Check_No_Identifiers;
13720 Check_Arg_Count (1);
13721 Check_Arg_Is_Integer_Literal (Arg1);
13722
13723 -------------
13724 -- No_Body --
13725 -------------
13726
13727 -- pragma No_Body;
13728
13729 -- The only correct use of this pragma is on its own in a file, in
13730 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
13731 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
13732 -- check for a file containing nothing but a No_Body pragma). If we
13733 -- attempt to process it during normal semantics processing, it means
13734 -- it was misplaced.
13735
13736 when Pragma_No_Body =>
13737 GNAT_Pragma;
13738 Pragma_Misplaced;
13739
13740 ---------------
13741 -- No_Inline --
13742 ---------------
13743
13744 -- pragma No_Inline ( NAME {, NAME} );
13745
13746 when Pragma_No_Inline =>
13747 GNAT_Pragma;
13748 Process_Inline (Suppressed);
13749
13750 ---------------
13751 -- No_Return --
13752 ---------------
13753
13754 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
13755
13756 when Pragma_No_Return => No_Return : declare
13757 Id : Node_Id;
13758 E : Entity_Id;
13759 Found : Boolean;
13760 Arg : Node_Id;
13761
13762 begin
13763 Ada_2005_Pragma;
13764 Check_At_Least_N_Arguments (1);
13765
13766 -- Loop through arguments of pragma
13767
13768 Arg := Arg1;
13769 while Present (Arg) loop
13770 Check_Arg_Is_Local_Name (Arg);
13771 Id := Get_Pragma_Arg (Arg);
13772 Analyze (Id);
13773
13774 if not Is_Entity_Name (Id) then
13775 Error_Pragma_Arg ("entity name required", Arg);
13776 end if;
13777
13778 if Etype (Id) = Any_Type then
13779 raise Pragma_Exit;
13780 end if;
13781
13782 -- Loop to find matching procedures
13783
13784 E := Entity (Id);
13785 Found := False;
13786 while Present (E)
13787 and then Scope (E) = Current_Scope
13788 loop
13789 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
13790 Set_No_Return (E);
13791
13792 -- Set flag on any alias as well
13793
13794 if Is_Overloadable (E) and then Present (Alias (E)) then
13795 Set_No_Return (Alias (E));
13796 end if;
13797
13798 Found := True;
13799 end if;
13800
13801 exit when From_Aspect_Specification (N);
13802 E := Homonym (E);
13803 end loop;
13804
13805 if not Found then
13806 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
13807 end if;
13808
13809 Next (Arg);
13810 end loop;
13811 end No_Return;
13812
13813 -----------------
13814 -- No_Run_Time --
13815 -----------------
13816
13817 -- pragma No_Run_Time;
13818
13819 -- Note: this pragma is retained for backwards compatibility. See
13820 -- body of Rtsfind for full details on its handling.
13821
13822 when Pragma_No_Run_Time =>
13823 GNAT_Pragma;
13824 Check_Valid_Configuration_Pragma;
13825 Check_Arg_Count (0);
13826
13827 No_Run_Time_Mode := True;
13828 Configurable_Run_Time_Mode := True;
13829
13830 -- Set Duration to 32 bits if word size is 32
13831
13832 if Ttypes.System_Word_Size = 32 then
13833 Duration_32_Bits_On_Target := True;
13834 end if;
13835
13836 -- Set appropriate restrictions
13837
13838 Set_Restriction (No_Finalization, N);
13839 Set_Restriction (No_Exception_Handlers, N);
13840 Set_Restriction (Max_Tasks, N, 0);
13841 Set_Restriction (No_Tasking, N);
13842
13843 ------------------------
13844 -- No_Strict_Aliasing --
13845 ------------------------
13846
13847 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
13848
13849 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
13850 E_Id : Entity_Id;
13851
13852 begin
13853 GNAT_Pragma;
13854 Check_At_Most_N_Arguments (1);
13855
13856 if Arg_Count = 0 then
13857 Check_Valid_Configuration_Pragma;
13858 Opt.No_Strict_Aliasing := True;
13859
13860 else
13861 Check_Optional_Identifier (Arg2, Name_Entity);
13862 Check_Arg_Is_Local_Name (Arg1);
13863 E_Id := Entity (Get_Pragma_Arg (Arg1));
13864
13865 if E_Id = Any_Type then
13866 return;
13867 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
13868 Error_Pragma_Arg ("pragma% requires access type", Arg1);
13869 end if;
13870
13871 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
13872 end if;
13873 end No_Strict_Aliasing;
13874
13875 -----------------------
13876 -- Normalize_Scalars --
13877 -----------------------
13878
13879 -- pragma Normalize_Scalars;
13880
13881 when Pragma_Normalize_Scalars =>
13882 Check_Ada_83_Warning;
13883 Check_Arg_Count (0);
13884 Check_Valid_Configuration_Pragma;
13885
13886 -- Normalize_Scalars creates false positives in CodePeer, and
13887 -- incorrect negative results in Alfa mode, so ignore this pragma
13888 -- in these modes.
13889
13890 if not (CodePeer_Mode or Alfa_Mode) then
13891 Normalize_Scalars := True;
13892 Init_Or_Norm_Scalars := True;
13893 end if;
13894
13895 -----------------
13896 -- Obsolescent --
13897 -----------------
13898
13899 -- pragma Obsolescent;
13900
13901 -- pragma Obsolescent (
13902 -- [Message =>] static_string_EXPRESSION
13903 -- [,[Version =>] Ada_05]]);
13904
13905 -- pragma Obsolescent (
13906 -- [Entity =>] NAME
13907 -- [,[Message =>] static_string_EXPRESSION
13908 -- [,[Version =>] Ada_05]] );
13909
13910 when Pragma_Obsolescent => Obsolescent : declare
13911 Ename : Node_Id;
13912 Decl : Node_Id;
13913
13914 procedure Set_Obsolescent (E : Entity_Id);
13915 -- Given an entity Ent, mark it as obsolescent if appropriate
13916
13917 ---------------------
13918 -- Set_Obsolescent --
13919 ---------------------
13920
13921 procedure Set_Obsolescent (E : Entity_Id) is
13922 Active : Boolean;
13923 Ent : Entity_Id;
13924 S : String_Id;
13925
13926 begin
13927 Active := True;
13928 Ent := E;
13929
13930 -- Entity name was given
13931
13932 if Present (Ename) then
13933
13934 -- If entity name matches, we are fine. Save entity in
13935 -- pragma argument, for ASIS use.
13936
13937 if Chars (Ename) = Chars (Ent) then
13938 Set_Entity (Ename, Ent);
13939 Generate_Reference (Ent, Ename);
13940
13941 -- If entity name does not match, only possibility is an
13942 -- enumeration literal from an enumeration type declaration.
13943
13944 elsif Ekind (Ent) /= E_Enumeration_Type then
13945 Error_Pragma
13946 ("pragma % entity name does not match declaration");
13947
13948 else
13949 Ent := First_Literal (E);
13950 loop
13951 if No (Ent) then
13952 Error_Pragma
13953 ("pragma % entity name does not match any "
13954 & "enumeration literal");
13955
13956 elsif Chars (Ent) = Chars (Ename) then
13957 Set_Entity (Ename, Ent);
13958 Generate_Reference (Ent, Ename);
13959 exit;
13960
13961 else
13962 Ent := Next_Literal (Ent);
13963 end if;
13964 end loop;
13965 end if;
13966 end if;
13967
13968 -- Ent points to entity to be marked
13969
13970 if Arg_Count >= 1 then
13971
13972 -- Deal with static string argument
13973
13974 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13975 S := Strval (Get_Pragma_Arg (Arg1));
13976
13977 for J in 1 .. String_Length (S) loop
13978 if not In_Character_Range (Get_String_Char (S, J)) then
13979 Error_Pragma_Arg
13980 ("pragma% argument does not allow wide characters",
13981 Arg1);
13982 end if;
13983 end loop;
13984
13985 Obsolescent_Warnings.Append
13986 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
13987
13988 -- Check for Ada_05 parameter
13989
13990 if Arg_Count /= 1 then
13991 Check_Arg_Count (2);
13992
13993 declare
13994 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
13995
13996 begin
13997 Check_Arg_Is_Identifier (Argx);
13998
13999 if Chars (Argx) /= Name_Ada_05 then
14000 Error_Msg_Name_2 := Name_Ada_05;
14001 Error_Pragma_Arg
14002 ("only allowed argument for pragma% is %", Argx);
14003 end if;
14004
14005 if Ada_Version_Explicit < Ada_2005
14006 or else not Warn_On_Ada_2005_Compatibility
14007 then
14008 Active := False;
14009 end if;
14010 end;
14011 end if;
14012 end if;
14013
14014 -- Set flag if pragma active
14015
14016 if Active then
14017 Set_Is_Obsolescent (Ent);
14018 end if;
14019
14020 return;
14021 end Set_Obsolescent;
14022
14023 -- Start of processing for pragma Obsolescent
14024
14025 begin
14026 GNAT_Pragma;
14027
14028 Check_At_Most_N_Arguments (3);
14029
14030 -- See if first argument specifies an entity name
14031
14032 if Arg_Count >= 1
14033 and then
14034 (Chars (Arg1) = Name_Entity
14035 or else
14036 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
14037 N_Identifier,
14038 N_Operator_Symbol))
14039 then
14040 Ename := Get_Pragma_Arg (Arg1);
14041
14042 -- Eliminate first argument, so we can share processing
14043
14044 Arg1 := Arg2;
14045 Arg2 := Arg3;
14046 Arg_Count := Arg_Count - 1;
14047
14048 -- No Entity name argument given
14049
14050 else
14051 Ename := Empty;
14052 end if;
14053
14054 if Arg_Count >= 1 then
14055 Check_Optional_Identifier (Arg1, Name_Message);
14056
14057 if Arg_Count = 2 then
14058 Check_Optional_Identifier (Arg2, Name_Version);
14059 end if;
14060 end if;
14061
14062 -- Get immediately preceding declaration
14063
14064 Decl := Prev (N);
14065 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
14066 Prev (Decl);
14067 end loop;
14068
14069 -- Cases where we do not follow anything other than another pragma
14070
14071 if No (Decl) then
14072
14073 -- First case: library level compilation unit declaration with
14074 -- the pragma immediately following the declaration.
14075
14076 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
14077 Set_Obsolescent
14078 (Defining_Entity (Unit (Parent (Parent (N)))));
14079 return;
14080
14081 -- Case 2: library unit placement for package
14082
14083 else
14084 declare
14085 Ent : constant Entity_Id := Find_Lib_Unit_Name;
14086 begin
14087 if Is_Package_Or_Generic_Package (Ent) then
14088 Set_Obsolescent (Ent);
14089 return;
14090 end if;
14091 end;
14092 end if;
14093
14094 -- Cases where we must follow a declaration
14095
14096 else
14097 if Nkind (Decl) not in N_Declaration
14098 and then Nkind (Decl) not in N_Later_Decl_Item
14099 and then Nkind (Decl) not in N_Generic_Declaration
14100 and then Nkind (Decl) not in N_Renaming_Declaration
14101 then
14102 Error_Pragma
14103 ("pragma% misplaced, "
14104 & "must immediately follow a declaration");
14105
14106 else
14107 Set_Obsolescent (Defining_Entity (Decl));
14108 return;
14109 end if;
14110 end if;
14111 end Obsolescent;
14112
14113 --------------
14114 -- Optimize --
14115 --------------
14116
14117 -- pragma Optimize (Time | Space | Off);
14118
14119 -- The actual check for optimize is done in Gigi. Note that this
14120 -- pragma does not actually change the optimization setting, it
14121 -- simply checks that it is consistent with the pragma.
14122
14123 when Pragma_Optimize =>
14124 Check_No_Identifiers;
14125 Check_Arg_Count (1);
14126 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
14127
14128 ------------------------
14129 -- Optimize_Alignment --
14130 ------------------------
14131
14132 -- pragma Optimize_Alignment (Time | Space | Off);
14133
14134 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
14135 GNAT_Pragma;
14136 Check_No_Identifiers;
14137 Check_Arg_Count (1);
14138 Check_Valid_Configuration_Pragma;
14139
14140 declare
14141 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
14142 begin
14143 case Nam is
14144 when Name_Time =>
14145 Opt.Optimize_Alignment := 'T';
14146 when Name_Space =>
14147 Opt.Optimize_Alignment := 'S';
14148 when Name_Off =>
14149 Opt.Optimize_Alignment := 'O';
14150 when others =>
14151 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
14152 end case;
14153 end;
14154
14155 -- Set indication that mode is set locally. If we are in fact in a
14156 -- configuration pragma file, this setting is harmless since the
14157 -- switch will get reset anyway at the start of each unit.
14158
14159 Optimize_Alignment_Local := True;
14160 end Optimize_Alignment;
14161
14162 -------------------
14163 -- Overflow_Mode --
14164 -------------------
14165
14166 -- pragma Overflow_Mode
14167 -- ([General => ] MODE [, [Assertions => ] MODE]);
14168
14169 -- MODE := STRICT | MINIMIZED | ELIMINATED
14170
14171 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
14172 -- since System.Bignums makes this assumption. This is true of nearly
14173 -- all (all?) targets.
14174
14175 when Pragma_Overflow_Mode => Overflow_Mode : declare
14176 function Get_Overflow_Mode
14177 (Name : Name_Id;
14178 Arg : Node_Id) return Overflow_Mode_Type;
14179 -- Function to process one pragma argument, Arg. If an identifier
14180 -- is present, it must be Name. Mode type is returned if a valid
14181 -- argument exists, otherwise an error is signalled.
14182
14183 -----------------------
14184 -- Get_Overflow_Mode --
14185 -----------------------
14186
14187 function Get_Overflow_Mode
14188 (Name : Name_Id;
14189 Arg : Node_Id) return Overflow_Mode_Type
14190 is
14191 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
14192
14193 begin
14194 Check_Optional_Identifier (Arg, Name);
14195 Check_Arg_Is_Identifier (Argx);
14196
14197 if Chars (Argx) = Name_Strict then
14198 return Strict;
14199
14200 elsif Chars (Argx) = Name_Minimized then
14201 return Minimized;
14202
14203 elsif Chars (Argx) = Name_Eliminated then
14204 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
14205 Error_Pragma_Arg
14206 ("Eliminated not implemented on this target", Argx);
14207 else
14208 return Eliminated;
14209 end if;
14210
14211 else
14212 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
14213 end if;
14214 end Get_Overflow_Mode;
14215
14216 -- Start of processing for Overflow_Mode
14217
14218 begin
14219 GNAT_Pragma;
14220 Check_At_Least_N_Arguments (1);
14221 Check_At_Most_N_Arguments (2);
14222
14223 -- Process first argument
14224
14225 Scope_Suppress.Overflow_Mode_General :=
14226 Get_Overflow_Mode (Name_General, Arg1);
14227
14228 -- Case of only one argument
14229
14230 if Arg_Count = 1 then
14231 Scope_Suppress.Overflow_Mode_Assertions :=
14232 Scope_Suppress.Overflow_Mode_General;
14233
14234 -- Case of two arguments present
14235
14236 else
14237 Scope_Suppress.Overflow_Mode_Assertions :=
14238 Get_Overflow_Mode (Name_Assertions, Arg2);
14239 end if;
14240 end Overflow_Mode;
14241
14242 when Pragma_Overriding_Renamings =>
14243 Overriding_Renamings := True;
14244
14245 -------------
14246 -- Ordered --
14247 -------------
14248
14249 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
14250
14251 when Pragma_Ordered => Ordered : declare
14252 Assoc : constant Node_Id := Arg1;
14253 Type_Id : Node_Id;
14254 Typ : Entity_Id;
14255
14256 begin
14257 GNAT_Pragma;
14258 Check_No_Identifiers;
14259 Check_Arg_Count (1);
14260 Check_Arg_Is_Local_Name (Arg1);
14261
14262 Type_Id := Get_Pragma_Arg (Assoc);
14263 Find_Type (Type_Id);
14264 Typ := Entity (Type_Id);
14265
14266 if Typ = Any_Type then
14267 return;
14268 else
14269 Typ := Underlying_Type (Typ);
14270 end if;
14271
14272 if not Is_Enumeration_Type (Typ) then
14273 Error_Pragma ("pragma% must specify enumeration type");
14274 end if;
14275
14276 Check_First_Subtype (Arg1);
14277 Set_Has_Pragma_Ordered (Base_Type (Typ));
14278 end Ordered;
14279
14280 ----------
14281 -- Pack --
14282 ----------
14283
14284 -- pragma Pack (first_subtype_LOCAL_NAME);
14285
14286 when Pragma_Pack => Pack : declare
14287 Assoc : constant Node_Id := Arg1;
14288 Type_Id : Node_Id;
14289 Typ : Entity_Id;
14290 Ctyp : Entity_Id;
14291 Ignore : Boolean := False;
14292
14293 begin
14294 Check_No_Identifiers;
14295 Check_Arg_Count (1);
14296 Check_Arg_Is_Local_Name (Arg1);
14297
14298 Type_Id := Get_Pragma_Arg (Assoc);
14299 Find_Type (Type_Id);
14300 Typ := Entity (Type_Id);
14301
14302 if Typ = Any_Type
14303 or else Rep_Item_Too_Early (Typ, N)
14304 then
14305 return;
14306 else
14307 Typ := Underlying_Type (Typ);
14308 end if;
14309
14310 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
14311 Error_Pragma ("pragma% must specify array or record type");
14312 end if;
14313
14314 Check_First_Subtype (Arg1);
14315 Check_Duplicate_Pragma (Typ);
14316
14317 -- Array type
14318
14319 if Is_Array_Type (Typ) then
14320 Ctyp := Component_Type (Typ);
14321
14322 -- Ignore pack that does nothing
14323
14324 if Known_Static_Esize (Ctyp)
14325 and then Known_Static_RM_Size (Ctyp)
14326 and then Esize (Ctyp) = RM_Size (Ctyp)
14327 and then Addressable (Esize (Ctyp))
14328 then
14329 Ignore := True;
14330 end if;
14331
14332 -- Process OK pragma Pack. Note that if there is a separate
14333 -- component clause present, the Pack will be cancelled. This
14334 -- processing is in Freeze.
14335
14336 if not Rep_Item_Too_Late (Typ, N) then
14337
14338 -- In the context of static code analysis, we do not need
14339 -- complex front-end expansions related to pragma Pack,
14340 -- so disable handling of pragma Pack in these cases.
14341
14342 if CodePeer_Mode or Alfa_Mode then
14343 null;
14344
14345 -- Don't attempt any packing for VM targets. We possibly
14346 -- could deal with some cases of array bit-packing, but we
14347 -- don't bother, since this is not a typical kind of
14348 -- representation in the VM context anyway (and would not
14349 -- for example work nicely with the debugger).
14350
14351 elsif VM_Target /= No_VM then
14352 if not GNAT_Mode then
14353 Error_Pragma
14354 ("??pragma% ignored in this configuration");
14355 end if;
14356
14357 -- Normal case where we do the pack action
14358
14359 else
14360 if not Ignore then
14361 Set_Is_Packed (Base_Type (Typ));
14362 Set_Has_Non_Standard_Rep (Base_Type (Typ));
14363 end if;
14364
14365 Set_Has_Pragma_Pack (Base_Type (Typ));
14366 end if;
14367 end if;
14368
14369 -- For record types, the pack is always effective
14370
14371 else pragma Assert (Is_Record_Type (Typ));
14372 if not Rep_Item_Too_Late (Typ, N) then
14373
14374 -- Ignore pack request with warning in VM mode (skip warning
14375 -- if we are compiling GNAT run time library).
14376
14377 if VM_Target /= No_VM then
14378 if not GNAT_Mode then
14379 Error_Pragma
14380 ("??pragma% ignored in this configuration");
14381 end if;
14382
14383 -- Normal case of pack request active
14384
14385 else
14386 Set_Is_Packed (Base_Type (Typ));
14387 Set_Has_Pragma_Pack (Base_Type (Typ));
14388 Set_Has_Non_Standard_Rep (Base_Type (Typ));
14389 end if;
14390 end if;
14391 end if;
14392 end Pack;
14393
14394 ----------
14395 -- Page --
14396 ----------
14397
14398 -- pragma Page;
14399
14400 -- There is nothing to do here, since we did all the processing for
14401 -- this pragma in Par.Prag (so that it works properly even in syntax
14402 -- only mode).
14403
14404 when Pragma_Page =>
14405 null;
14406
14407 ----------------------------------
14408 -- Partition_Elaboration_Policy --
14409 ----------------------------------
14410
14411 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
14412
14413 when Pragma_Partition_Elaboration_Policy => declare
14414 subtype PEP_Range is Name_Id
14415 range First_Partition_Elaboration_Policy_Name
14416 .. Last_Partition_Elaboration_Policy_Name;
14417 PEP_Val : PEP_Range;
14418 PEP : Character;
14419
14420 begin
14421 Ada_2005_Pragma;
14422 Check_Arg_Count (1);
14423 Check_No_Identifiers;
14424 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
14425 Check_Valid_Configuration_Pragma;
14426 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
14427
14428 case PEP_Val is
14429 when Name_Concurrent =>
14430 PEP := 'C';
14431 when Name_Sequential =>
14432 PEP := 'S';
14433 end case;
14434
14435 if Partition_Elaboration_Policy /= ' '
14436 and then Partition_Elaboration_Policy /= PEP
14437 then
14438 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
14439 Error_Pragma
14440 ("partition elaboration policy incompatible with policy#");
14441
14442 -- Set new policy, but always preserve System_Location since we
14443 -- like the error message with the run time name.
14444
14445 else
14446 Partition_Elaboration_Policy := PEP;
14447
14448 if Partition_Elaboration_Policy_Sloc /= System_Location then
14449 Partition_Elaboration_Policy_Sloc := Loc;
14450 end if;
14451 end if;
14452 end;
14453
14454 -------------
14455 -- Passive --
14456 -------------
14457
14458 -- pragma Passive [(PASSIVE_FORM)];
14459
14460 -- PASSIVE_FORM ::= Semaphore | No
14461
14462 when Pragma_Passive =>
14463 GNAT_Pragma;
14464
14465 if Nkind (Parent (N)) /= N_Task_Definition then
14466 Error_Pragma ("pragma% must be within task definition");
14467 end if;
14468
14469 if Arg_Count /= 0 then
14470 Check_Arg_Count (1);
14471 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
14472 end if;
14473
14474 ----------------------------------
14475 -- Preelaborable_Initialization --
14476 ----------------------------------
14477
14478 -- pragma Preelaborable_Initialization (DIRECT_NAME);
14479
14480 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
14481 Ent : Entity_Id;
14482
14483 begin
14484 Ada_2005_Pragma;
14485 Check_Arg_Count (1);
14486 Check_No_Identifiers;
14487 Check_Arg_Is_Identifier (Arg1);
14488 Check_Arg_Is_Local_Name (Arg1);
14489 Check_First_Subtype (Arg1);
14490 Ent := Entity (Get_Pragma_Arg (Arg1));
14491
14492 -- The pragma may come from an aspect on a private declaration,
14493 -- even if the freeze point at which this is analyzed in the
14494 -- private part after the full view.
14495
14496 if Has_Private_Declaration (Ent)
14497 and then From_Aspect_Specification (N)
14498 then
14499 null;
14500
14501 elsif Is_Private_Type (Ent)
14502 or else Is_Protected_Type (Ent)
14503 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
14504 then
14505 null;
14506
14507 else
14508 Error_Pragma_Arg
14509 ("pragma % can only be applied to private, formal derived or "
14510 & "protected type",
14511 Arg1);
14512 end if;
14513
14514 -- Give an error if the pragma is applied to a protected type that
14515 -- does not qualify (due to having entries, or due to components
14516 -- that do not qualify).
14517
14518 if Is_Protected_Type (Ent)
14519 and then not Has_Preelaborable_Initialization (Ent)
14520 then
14521 Error_Msg_N
14522 ("protected type & does not have preelaborable "
14523 & "initialization", Ent);
14524
14525 -- Otherwise mark the type as definitely having preelaborable
14526 -- initialization.
14527
14528 else
14529 Set_Known_To_Have_Preelab_Init (Ent);
14530 end if;
14531
14532 if Has_Pragma_Preelab_Init (Ent)
14533 and then Warn_On_Redundant_Constructs
14534 then
14535 Error_Pragma ("?r?duplicate pragma%!");
14536 else
14537 Set_Has_Pragma_Preelab_Init (Ent);
14538 end if;
14539 end Preelab_Init;
14540
14541 --------------------
14542 -- Persistent_BSS --
14543 --------------------
14544
14545 -- pragma Persistent_BSS [(object_NAME)];
14546
14547 when Pragma_Persistent_BSS => Persistent_BSS : declare
14548 Decl : Node_Id;
14549 Ent : Entity_Id;
14550 Prag : Node_Id;
14551
14552 begin
14553 GNAT_Pragma;
14554 Check_At_Most_N_Arguments (1);
14555
14556 -- Case of application to specific object (one argument)
14557
14558 if Arg_Count = 1 then
14559 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14560
14561 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
14562 or else not
14563 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
14564 E_Constant)
14565 then
14566 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
14567 end if;
14568
14569 Ent := Entity (Get_Pragma_Arg (Arg1));
14570 Decl := Parent (Ent);
14571
14572 -- Check for duplication before inserting in list of
14573 -- representation items.
14574
14575 Check_Duplicate_Pragma (Ent);
14576
14577 if Rep_Item_Too_Late (Ent, N) then
14578 return;
14579 end if;
14580
14581 if Present (Expression (Decl)) then
14582 Error_Pragma_Arg
14583 ("object for pragma% cannot have initialization", Arg1);
14584 end if;
14585
14586 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
14587 Error_Pragma_Arg
14588 ("object type for pragma% is not potentially persistent",
14589 Arg1);
14590 end if;
14591
14592 Prag :=
14593 Make_Linker_Section_Pragma
14594 (Ent, Sloc (N), ".persistent.bss");
14595 Insert_After (N, Prag);
14596 Analyze (Prag);
14597
14598 -- Case of use as configuration pragma with no arguments
14599
14600 else
14601 Check_Valid_Configuration_Pragma;
14602 Persistent_BSS_Mode := True;
14603 end if;
14604 end Persistent_BSS;
14605
14606 -------------
14607 -- Polling --
14608 -------------
14609
14610 -- pragma Polling (ON | OFF);
14611
14612 when Pragma_Polling =>
14613 GNAT_Pragma;
14614 Check_Arg_Count (1);
14615 Check_No_Identifiers;
14616 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14617 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
14618
14619 -------------------
14620 -- Postcondition --
14621 -------------------
14622
14623 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
14624 -- [,[Message =>] String_EXPRESSION]);
14625
14626 when Pragma_Postcondition => Postcondition : declare
14627 In_Body : Boolean;
14628
14629 begin
14630 GNAT_Pragma;
14631 Check_At_Least_N_Arguments (1);
14632 Check_At_Most_N_Arguments (2);
14633 Check_Optional_Identifier (Arg1, Name_Check);
14634
14635 -- Verify the proper placement of the pragma. The remainder of the
14636 -- processing is found in Sem_Ch6/Sem_Ch7.
14637
14638 Check_Precondition_Postcondition (In_Body);
14639
14640 -- When the pragma is a source contruct and appears inside a body,
14641 -- preanalyze the boolean_expression to detect illegal forward
14642 -- references:
14643
14644 -- procedure P is
14645 -- pragma Postcondition (X'Old ...);
14646 -- X : ...
14647
14648 if Comes_From_Source (N) and then In_Body then
14649 Preanalyze_Spec_Expression (Expression (Arg1), Any_Boolean);
14650 end if;
14651 end Postcondition;
14652
14653 ------------------
14654 -- Precondition --
14655 ------------------
14656
14657 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
14658 -- [,[Message =>] String_EXPRESSION]);
14659
14660 when Pragma_Precondition => Precondition : declare
14661 In_Body : Boolean;
14662
14663 begin
14664 GNAT_Pragma;
14665 Check_At_Least_N_Arguments (1);
14666 Check_At_Most_N_Arguments (2);
14667 Check_Optional_Identifier (Arg1, Name_Check);
14668 Check_Precondition_Postcondition (In_Body);
14669
14670 -- If in spec, nothing more to do. If in body, then we convert the
14671 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
14672 -- this whether or not precondition checks are enabled. That works
14673 -- fine since pragma Check will do this check, and will also
14674 -- analyze the condition itself in the proper context.
14675
14676 if In_Body then
14677 Rewrite (N,
14678 Make_Pragma (Loc,
14679 Chars => Name_Check,
14680 Pragma_Argument_Associations => New_List (
14681 Make_Pragma_Argument_Association (Loc,
14682 Expression => Make_Identifier (Loc, Name_Precondition)),
14683
14684 Make_Pragma_Argument_Association (Sloc (Arg1),
14685 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
14686
14687 if Arg_Count = 2 then
14688 Append_To (Pragma_Argument_Associations (N),
14689 Make_Pragma_Argument_Association (Sloc (Arg2),
14690 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
14691 end if;
14692
14693 Analyze (N);
14694 end if;
14695 end Precondition;
14696
14697 ---------------
14698 -- Predicate --
14699 ---------------
14700
14701 -- pragma Predicate
14702 -- ([Entity =>] type_LOCAL_NAME,
14703 -- [Check =>] EXPRESSION);
14704
14705 when Pragma_Predicate => Predicate : declare
14706 Type_Id : Node_Id;
14707 Typ : Entity_Id;
14708
14709 Discard : Boolean;
14710 pragma Unreferenced (Discard);
14711
14712 begin
14713 GNAT_Pragma;
14714 Check_Arg_Count (2);
14715 Check_Optional_Identifier (Arg1, Name_Entity);
14716 Check_Optional_Identifier (Arg2, Name_Check);
14717
14718 Check_Arg_Is_Local_Name (Arg1);
14719
14720 Type_Id := Get_Pragma_Arg (Arg1);
14721 Find_Type (Type_Id);
14722 Typ := Entity (Type_Id);
14723
14724 if Typ = Any_Type then
14725 return;
14726 end if;
14727
14728 -- The remaining processing is simply to link the pragma on to
14729 -- the rep item chain, for processing when the type is frozen.
14730 -- This is accomplished by a call to Rep_Item_Too_Late. We also
14731 -- mark the type as having predicates.
14732
14733 Set_Has_Predicates (Typ);
14734 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
14735 end Predicate;
14736
14737 ------------------
14738 -- Preelaborate --
14739 ------------------
14740
14741 -- pragma Preelaborate [(library_unit_NAME)];
14742
14743 -- Set the flag Is_Preelaborated of program unit name entity
14744
14745 when Pragma_Preelaborate => Preelaborate : declare
14746 Pa : constant Node_Id := Parent (N);
14747 Pk : constant Node_Kind := Nkind (Pa);
14748 Ent : Entity_Id;
14749
14750 begin
14751 Check_Ada_83_Warning;
14752 Check_Valid_Library_Unit_Pragma;
14753
14754 if Nkind (N) = N_Null_Statement then
14755 return;
14756 end if;
14757
14758 Ent := Find_Lib_Unit_Name;
14759 Check_Duplicate_Pragma (Ent);
14760
14761 -- This filters out pragmas inside generic parent then
14762 -- show up inside instantiation
14763
14764 if Present (Ent)
14765 and then not (Pk = N_Package_Specification
14766 and then Present (Generic_Parent (Pa)))
14767 then
14768 if not Debug_Flag_U then
14769 Set_Is_Preelaborated (Ent);
14770 Set_Suppress_Elaboration_Warnings (Ent);
14771 end if;
14772 end if;
14773 end Preelaborate;
14774
14775 ---------------------
14776 -- Preelaborate_05 --
14777 ---------------------
14778
14779 -- pragma Preelaborate_05 [(library_unit_NAME)];
14780
14781 -- This pragma is useable only in GNAT_Mode, where it is used like
14782 -- pragma Preelaborate but it is only effective in Ada 2005 mode
14783 -- (otherwise it is ignored). This is used to implement AI-362 which
14784 -- recategorizes some run-time packages in Ada 2005 mode.
14785
14786 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
14787 Ent : Entity_Id;
14788
14789 begin
14790 GNAT_Pragma;
14791 Check_Valid_Library_Unit_Pragma;
14792
14793 if not GNAT_Mode then
14794 Error_Pragma ("pragma% only available in GNAT mode");
14795 end if;
14796
14797 if Nkind (N) = N_Null_Statement then
14798 return;
14799 end if;
14800
14801 -- This is one of the few cases where we need to test the value of
14802 -- Ada_Version_Explicit rather than Ada_Version (which is always
14803 -- set to Ada_2012 in a predefined unit), we need to know the
14804 -- explicit version set to know if this pragma is active.
14805
14806 if Ada_Version_Explicit >= Ada_2005 then
14807 Ent := Find_Lib_Unit_Name;
14808 Set_Is_Preelaborated (Ent);
14809 Set_Suppress_Elaboration_Warnings (Ent);
14810 end if;
14811 end Preelaborate_05;
14812
14813 --------------
14814 -- Priority --
14815 --------------
14816
14817 -- pragma Priority (EXPRESSION);
14818
14819 when Pragma_Priority => Priority : declare
14820 P : constant Node_Id := Parent (N);
14821 Arg : Node_Id;
14822 Ent : Entity_Id;
14823
14824 begin
14825 Check_No_Identifiers;
14826 Check_Arg_Count (1);
14827
14828 -- Subprogram case
14829
14830 if Nkind (P) = N_Subprogram_Body then
14831 Check_In_Main_Program;
14832
14833 Ent := Defining_Unit_Name (Specification (P));
14834
14835 if Nkind (Ent) = N_Defining_Program_Unit_Name then
14836 Ent := Defining_Identifier (Ent);
14837 end if;
14838
14839 Arg := Get_Pragma_Arg (Arg1);
14840 Analyze_And_Resolve (Arg, Standard_Integer);
14841
14842 -- Must be static
14843
14844 if not Is_Static_Expression (Arg) then
14845 Flag_Non_Static_Expr
14846 ("main subprogram priority is not static!", Arg);
14847 raise Pragma_Exit;
14848
14849 -- If constraint error, then we already signalled an error
14850
14851 elsif Raises_Constraint_Error (Arg) then
14852 null;
14853
14854 -- Otherwise check in range
14855
14856 else
14857 declare
14858 Val : constant Uint := Expr_Value (Arg);
14859
14860 begin
14861 if Val < 0
14862 or else Val > Expr_Value (Expression
14863 (Parent (RTE (RE_Max_Priority))))
14864 then
14865 Error_Pragma_Arg
14866 ("main subprogram priority is out of range", Arg1);
14867 end if;
14868 end;
14869 end if;
14870
14871 Set_Main_Priority
14872 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
14873
14874 -- Load an arbitrary entity from System.Tasking to make sure
14875 -- this package is implicitly with'ed, since we need to have
14876 -- the tasking run-time active for the pragma Priority to have
14877 -- any effect.
14878
14879 declare
14880 Discard : Entity_Id;
14881 pragma Warnings (Off, Discard);
14882 begin
14883 Discard := RTE (RE_Task_List);
14884 end;
14885
14886 -- Task or Protected, must be of type Integer
14887
14888 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
14889 Arg := Get_Pragma_Arg (Arg1);
14890 Ent := Defining_Identifier (Parent (P));
14891
14892 -- The expression must be analyzed in the special manner
14893 -- described in "Handling of Default and Per-Object
14894 -- Expressions" in sem.ads.
14895
14896 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
14897
14898 if not Is_Static_Expression (Arg) then
14899 Check_Restriction (Static_Priorities, Arg);
14900 end if;
14901
14902 -- Anything else is incorrect
14903
14904 else
14905 Pragma_Misplaced;
14906 end if;
14907
14908 -- Check duplicate pragma before we chain the pragma in the Rep
14909 -- Item chain of Ent.
14910
14911 Check_Duplicate_Pragma (Ent);
14912 Record_Rep_Item (Ent, N);
14913 end Priority;
14914
14915 -----------------------------------
14916 -- Priority_Specific_Dispatching --
14917 -----------------------------------
14918
14919 -- pragma Priority_Specific_Dispatching (
14920 -- policy_IDENTIFIER,
14921 -- first_priority_EXPRESSION,
14922 -- last_priority_EXPRESSION);
14923
14924 when Pragma_Priority_Specific_Dispatching =>
14925 Priority_Specific_Dispatching : declare
14926 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
14927 -- This is the entity System.Any_Priority;
14928
14929 DP : Character;
14930 Lower_Bound : Node_Id;
14931 Upper_Bound : Node_Id;
14932 Lower_Val : Uint;
14933 Upper_Val : Uint;
14934
14935 begin
14936 Ada_2005_Pragma;
14937 Check_Arg_Count (3);
14938 Check_No_Identifiers;
14939 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
14940 Check_Valid_Configuration_Pragma;
14941 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
14942 DP := Fold_Upper (Name_Buffer (1));
14943
14944 Lower_Bound := Get_Pragma_Arg (Arg2);
14945 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
14946 Lower_Val := Expr_Value (Lower_Bound);
14947
14948 Upper_Bound := Get_Pragma_Arg (Arg3);
14949 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
14950 Upper_Val := Expr_Value (Upper_Bound);
14951
14952 -- It is not allowed to use Task_Dispatching_Policy and
14953 -- Priority_Specific_Dispatching in the same partition.
14954
14955 if Task_Dispatching_Policy /= ' ' then
14956 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
14957 Error_Pragma
14958 ("pragma% incompatible with Task_Dispatching_Policy#");
14959
14960 -- Check lower bound in range
14961
14962 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
14963 or else
14964 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
14965 then
14966 Error_Pragma_Arg
14967 ("first_priority is out of range", Arg2);
14968
14969 -- Check upper bound in range
14970
14971 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
14972 or else
14973 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
14974 then
14975 Error_Pragma_Arg
14976 ("last_priority is out of range", Arg3);
14977
14978 -- Check that the priority range is valid
14979
14980 elsif Lower_Val > Upper_Val then
14981 Error_Pragma
14982 ("last_priority_expression must be greater than or equal to "
14983 & "first_priority_expression");
14984
14985 -- Store the new policy, but always preserve System_Location since
14986 -- we like the error message with the run-time name.
14987
14988 else
14989 -- Check overlapping in the priority ranges specified in other
14990 -- Priority_Specific_Dispatching pragmas within the same
14991 -- partition. We can only check those we know about!
14992
14993 for J in
14994 Specific_Dispatching.First .. Specific_Dispatching.Last
14995 loop
14996 if Specific_Dispatching.Table (J).First_Priority in
14997 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
14998 or else Specific_Dispatching.Table (J).Last_Priority in
14999 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
15000 then
15001 Error_Msg_Sloc :=
15002 Specific_Dispatching.Table (J).Pragma_Loc;
15003 Error_Pragma
15004 ("priority range overlaps with "
15005 & "Priority_Specific_Dispatching#");
15006 end if;
15007 end loop;
15008
15009 -- The use of Priority_Specific_Dispatching is incompatible
15010 -- with Task_Dispatching_Policy.
15011
15012 if Task_Dispatching_Policy /= ' ' then
15013 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
15014 Error_Pragma
15015 ("Priority_Specific_Dispatching incompatible "
15016 & "with Task_Dispatching_Policy#");
15017 end if;
15018
15019 -- The use of Priority_Specific_Dispatching forces ceiling
15020 -- locking policy.
15021
15022 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
15023 Error_Msg_Sloc := Locking_Policy_Sloc;
15024 Error_Pragma
15025 ("Priority_Specific_Dispatching incompatible "
15026 & "with Locking_Policy#");
15027
15028 -- Set the Ceiling_Locking policy, but preserve System_Location
15029 -- since we like the error message with the run time name.
15030
15031 else
15032 Locking_Policy := 'C';
15033
15034 if Locking_Policy_Sloc /= System_Location then
15035 Locking_Policy_Sloc := Loc;
15036 end if;
15037 end if;
15038
15039 -- Add entry in the table
15040
15041 Specific_Dispatching.Append
15042 ((Dispatching_Policy => DP,
15043 First_Priority => UI_To_Int (Lower_Val),
15044 Last_Priority => UI_To_Int (Upper_Val),
15045 Pragma_Loc => Loc));
15046 end if;
15047 end Priority_Specific_Dispatching;
15048
15049 -------------
15050 -- Profile --
15051 -------------
15052
15053 -- pragma Profile (profile_IDENTIFIER);
15054
15055 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
15056
15057 when Pragma_Profile =>
15058 Ada_2005_Pragma;
15059 Check_Arg_Count (1);
15060 Check_Valid_Configuration_Pragma;
15061 Check_No_Identifiers;
15062
15063 declare
15064 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
15065
15066 begin
15067 if Chars (Argx) = Name_Ravenscar then
15068 Set_Ravenscar_Profile (N);
15069
15070 elsif Chars (Argx) = Name_Restricted then
15071 Set_Profile_Restrictions
15072 (Restricted,
15073 N, Warn => Treat_Restrictions_As_Warnings);
15074
15075 elsif Chars (Argx) = Name_Rational then
15076 Set_Rational_Profile;
15077
15078 elsif Chars (Argx) = Name_No_Implementation_Extensions then
15079 Set_Profile_Restrictions
15080 (No_Implementation_Extensions,
15081 N, Warn => Treat_Restrictions_As_Warnings);
15082
15083 else
15084 Error_Pragma_Arg ("& is not a valid profile", Argx);
15085 end if;
15086 end;
15087
15088 ----------------------
15089 -- Profile_Warnings --
15090 ----------------------
15091
15092 -- pragma Profile_Warnings (profile_IDENTIFIER);
15093
15094 -- profile_IDENTIFIER => Restricted | Ravenscar
15095
15096 when Pragma_Profile_Warnings =>
15097 GNAT_Pragma;
15098 Check_Arg_Count (1);
15099 Check_Valid_Configuration_Pragma;
15100 Check_No_Identifiers;
15101
15102 declare
15103 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
15104
15105 begin
15106 if Chars (Argx) = Name_Ravenscar then
15107 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
15108
15109 elsif Chars (Argx) = Name_Restricted then
15110 Set_Profile_Restrictions (Restricted, N, Warn => True);
15111
15112 elsif Chars (Argx) = Name_No_Implementation_Extensions then
15113 Set_Profile_Restrictions
15114 (No_Implementation_Extensions, N, Warn => True);
15115
15116 else
15117 Error_Pragma_Arg ("& is not a valid profile", Argx);
15118 end if;
15119 end;
15120
15121 --------------------------
15122 -- Propagate_Exceptions --
15123 --------------------------
15124
15125 -- pragma Propagate_Exceptions;
15126
15127 -- Note: this pragma is obsolete and has no effect
15128
15129 when Pragma_Propagate_Exceptions =>
15130 GNAT_Pragma;
15131 Check_Arg_Count (0);
15132
15133 if In_Extended_Main_Source_Unit (N) then
15134 Propagate_Exceptions := True;
15135 end if;
15136
15137 ------------------
15138 -- Psect_Object --
15139 ------------------
15140
15141 -- pragma Psect_Object (
15142 -- [Internal =>] LOCAL_NAME,
15143 -- [, [External =>] EXTERNAL_SYMBOL]
15144 -- [, [Size =>] EXTERNAL_SYMBOL]);
15145
15146 when Pragma_Psect_Object | Pragma_Common_Object =>
15147 Psect_Object : declare
15148 Args : Args_List (1 .. 3);
15149 Names : constant Name_List (1 .. 3) := (
15150 Name_Internal,
15151 Name_External,
15152 Name_Size);
15153
15154 Internal : Node_Id renames Args (1);
15155 External : Node_Id renames Args (2);
15156 Size : Node_Id renames Args (3);
15157
15158 Def_Id : Entity_Id;
15159
15160 procedure Check_Too_Long (Arg : Node_Id);
15161 -- Posts message if the argument is an identifier with more
15162 -- than 31 characters, or a string literal with more than
15163 -- 31 characters, and we are operating under VMS
15164
15165 --------------------
15166 -- Check_Too_Long --
15167 --------------------
15168
15169 procedure Check_Too_Long (Arg : Node_Id) is
15170 X : constant Node_Id := Original_Node (Arg);
15171
15172 begin
15173 if not Nkind_In (X, N_String_Literal, N_Identifier) then
15174 Error_Pragma_Arg
15175 ("inappropriate argument for pragma %", Arg);
15176 end if;
15177
15178 if OpenVMS_On_Target then
15179 if (Nkind (X) = N_String_Literal
15180 and then String_Length (Strval (X)) > 31)
15181 or else
15182 (Nkind (X) = N_Identifier
15183 and then Length_Of_Name (Chars (X)) > 31)
15184 then
15185 Error_Pragma_Arg
15186 ("argument for pragma % is longer than 31 characters",
15187 Arg);
15188 end if;
15189 end if;
15190 end Check_Too_Long;
15191
15192 -- Start of processing for Common_Object/Psect_Object
15193
15194 begin
15195 GNAT_Pragma;
15196 Gather_Associations (Names, Args);
15197 Process_Extended_Import_Export_Internal_Arg (Internal);
15198
15199 Def_Id := Entity (Internal);
15200
15201 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
15202 Error_Pragma_Arg
15203 ("pragma% must designate an object", Internal);
15204 end if;
15205
15206 Check_Too_Long (Internal);
15207
15208 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
15209 Error_Pragma_Arg
15210 ("cannot use pragma% for imported/exported object",
15211 Internal);
15212 end if;
15213
15214 if Is_Concurrent_Type (Etype (Internal)) then
15215 Error_Pragma_Arg
15216 ("cannot specify pragma % for task/protected object",
15217 Internal);
15218 end if;
15219
15220 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
15221 or else
15222 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
15223 then
15224 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
15225 end if;
15226
15227 if Ekind (Def_Id) = E_Constant then
15228 Error_Pragma_Arg
15229 ("cannot specify pragma % for a constant", Internal);
15230 end if;
15231
15232 if Is_Record_Type (Etype (Internal)) then
15233 declare
15234 Ent : Entity_Id;
15235 Decl : Entity_Id;
15236
15237 begin
15238 Ent := First_Entity (Etype (Internal));
15239 while Present (Ent) loop
15240 Decl := Declaration_Node (Ent);
15241
15242 if Ekind (Ent) = E_Component
15243 and then Nkind (Decl) = N_Component_Declaration
15244 and then Present (Expression (Decl))
15245 and then Warn_On_Export_Import
15246 then
15247 Error_Msg_N
15248 ("?x?object for pragma % has defaults", Internal);
15249 exit;
15250
15251 else
15252 Next_Entity (Ent);
15253 end if;
15254 end loop;
15255 end;
15256 end if;
15257
15258 if Present (Size) then
15259 Check_Too_Long (Size);
15260 end if;
15261
15262 if Present (External) then
15263 Check_Arg_Is_External_Name (External);
15264 Check_Too_Long (External);
15265 end if;
15266
15267 -- If all error tests pass, link pragma on to the rep item chain
15268
15269 Record_Rep_Item (Def_Id, N);
15270 end Psect_Object;
15271
15272 ----------
15273 -- Pure --
15274 ----------
15275
15276 -- pragma Pure [(library_unit_NAME)];
15277
15278 when Pragma_Pure => Pure : declare
15279 Ent : Entity_Id;
15280
15281 begin
15282 Check_Ada_83_Warning;
15283 Check_Valid_Library_Unit_Pragma;
15284
15285 if Nkind (N) = N_Null_Statement then
15286 return;
15287 end if;
15288
15289 Ent := Find_Lib_Unit_Name;
15290 Set_Is_Pure (Ent);
15291 Set_Has_Pragma_Pure (Ent);
15292 Set_Suppress_Elaboration_Warnings (Ent);
15293 end Pure;
15294
15295 -------------
15296 -- Pure_05 --
15297 -------------
15298
15299 -- pragma Pure_05 [(library_unit_NAME)];
15300
15301 -- This pragma is useable only in GNAT_Mode, where it is used like
15302 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
15303 -- it is ignored). It may be used after a pragma Preelaborate, in
15304 -- which case it overrides the effect of the pragma Preelaborate.
15305 -- This is used to implement AI-362 which recategorizes some run-time
15306 -- packages in Ada 2005 mode.
15307
15308 when Pragma_Pure_05 => Pure_05 : declare
15309 Ent : Entity_Id;
15310
15311 begin
15312 GNAT_Pragma;
15313 Check_Valid_Library_Unit_Pragma;
15314
15315 if not GNAT_Mode then
15316 Error_Pragma ("pragma% only available in GNAT mode");
15317 end if;
15318
15319 if Nkind (N) = N_Null_Statement then
15320 return;
15321 end if;
15322
15323 -- This is one of the few cases where we need to test the value of
15324 -- Ada_Version_Explicit rather than Ada_Version (which is always
15325 -- set to Ada_2012 in a predefined unit), we need to know the
15326 -- explicit version set to know if this pragma is active.
15327
15328 if Ada_Version_Explicit >= Ada_2005 then
15329 Ent := Find_Lib_Unit_Name;
15330 Set_Is_Preelaborated (Ent, False);
15331 Set_Is_Pure (Ent);
15332 Set_Suppress_Elaboration_Warnings (Ent);
15333 end if;
15334 end Pure_05;
15335
15336 -------------
15337 -- Pure_12 --
15338 -------------
15339
15340 -- pragma Pure_12 [(library_unit_NAME)];
15341
15342 -- This pragma is useable only in GNAT_Mode, where it is used like
15343 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
15344 -- it is ignored). It may be used after a pragma Preelaborate, in
15345 -- which case it overrides the effect of the pragma Preelaborate.
15346 -- This is used to implement AI05-0212 which recategorizes some
15347 -- run-time packages in Ada 2012 mode.
15348
15349 when Pragma_Pure_12 => Pure_12 : declare
15350 Ent : Entity_Id;
15351
15352 begin
15353 GNAT_Pragma;
15354 Check_Valid_Library_Unit_Pragma;
15355
15356 if not GNAT_Mode then
15357 Error_Pragma ("pragma% only available in GNAT mode");
15358 end if;
15359
15360 if Nkind (N) = N_Null_Statement then
15361 return;
15362 end if;
15363
15364 -- This is one of the few cases where we need to test the value of
15365 -- Ada_Version_Explicit rather than Ada_Version (which is always
15366 -- set to Ada_2012 in a predefined unit), we need to know the
15367 -- explicit version set to know if this pragma is active.
15368
15369 if Ada_Version_Explicit >= Ada_2012 then
15370 Ent := Find_Lib_Unit_Name;
15371 Set_Is_Preelaborated (Ent, False);
15372 Set_Is_Pure (Ent);
15373 Set_Suppress_Elaboration_Warnings (Ent);
15374 end if;
15375 end Pure_12;
15376
15377 -------------------
15378 -- Pure_Function --
15379 -------------------
15380
15381 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
15382
15383 when Pragma_Pure_Function => Pure_Function : declare
15384 E_Id : Node_Id;
15385 E : Entity_Id;
15386 Def_Id : Entity_Id;
15387 Effective : Boolean := False;
15388
15389 begin
15390 GNAT_Pragma;
15391 Check_Arg_Count (1);
15392 Check_Optional_Identifier (Arg1, Name_Entity);
15393 Check_Arg_Is_Local_Name (Arg1);
15394 E_Id := Get_Pragma_Arg (Arg1);
15395
15396 if Error_Posted (E_Id) then
15397 return;
15398 end if;
15399
15400 -- Loop through homonyms (overloadings) of referenced entity
15401
15402 E := Entity (E_Id);
15403
15404 if Present (E) then
15405 loop
15406 Def_Id := Get_Base_Subprogram (E);
15407
15408 if not Ekind_In (Def_Id, E_Function,
15409 E_Generic_Function,
15410 E_Operator)
15411 then
15412 Error_Pragma_Arg
15413 ("pragma% requires a function name", Arg1);
15414 end if;
15415
15416 Set_Is_Pure (Def_Id);
15417
15418 if not Has_Pragma_Pure_Function (Def_Id) then
15419 Set_Has_Pragma_Pure_Function (Def_Id);
15420 Effective := True;
15421 end if;
15422
15423 exit when From_Aspect_Specification (N);
15424 E := Homonym (E);
15425 exit when No (E) or else Scope (E) /= Current_Scope;
15426 end loop;
15427
15428 if not Effective
15429 and then Warn_On_Redundant_Constructs
15430 then
15431 Error_Msg_NE
15432 ("pragma Pure_Function on& is redundant?r?",
15433 N, Entity (E_Id));
15434 end if;
15435 end if;
15436 end Pure_Function;
15437
15438 --------------------
15439 -- Queuing_Policy --
15440 --------------------
15441
15442 -- pragma Queuing_Policy (policy_IDENTIFIER);
15443
15444 when Pragma_Queuing_Policy => declare
15445 QP : Character;
15446
15447 begin
15448 Check_Ada_83_Warning;
15449 Check_Arg_Count (1);
15450 Check_No_Identifiers;
15451 Check_Arg_Is_Queuing_Policy (Arg1);
15452 Check_Valid_Configuration_Pragma;
15453 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15454 QP := Fold_Upper (Name_Buffer (1));
15455
15456 if Queuing_Policy /= ' '
15457 and then Queuing_Policy /= QP
15458 then
15459 Error_Msg_Sloc := Queuing_Policy_Sloc;
15460 Error_Pragma ("queuing policy incompatible with policy#");
15461
15462 -- Set new policy, but always preserve System_Location since we
15463 -- like the error message with the run time name.
15464
15465 else
15466 Queuing_Policy := QP;
15467
15468 if Queuing_Policy_Sloc /= System_Location then
15469 Queuing_Policy_Sloc := Loc;
15470 end if;
15471 end if;
15472 end;
15473
15474 --------------
15475 -- Rational --
15476 --------------
15477
15478 -- pragma Rational, for compatibility with foreign compiler
15479
15480 when Pragma_Rational =>
15481 Set_Rational_Profile;
15482
15483 -----------------------
15484 -- Relative_Deadline --
15485 -----------------------
15486
15487 -- pragma Relative_Deadline (time_span_EXPRESSION);
15488
15489 when Pragma_Relative_Deadline => Relative_Deadline : declare
15490 P : constant Node_Id := Parent (N);
15491 Arg : Node_Id;
15492
15493 begin
15494 Ada_2005_Pragma;
15495 Check_No_Identifiers;
15496 Check_Arg_Count (1);
15497
15498 Arg := Get_Pragma_Arg (Arg1);
15499
15500 -- The expression must be analyzed in the special manner described
15501 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
15502
15503 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
15504
15505 -- Subprogram case
15506
15507 if Nkind (P) = N_Subprogram_Body then
15508 Check_In_Main_Program;
15509
15510 -- Only Task and subprogram cases allowed
15511
15512 elsif Nkind (P) /= N_Task_Definition then
15513 Pragma_Misplaced;
15514 end if;
15515
15516 -- Check duplicate pragma before we set the corresponding flag
15517
15518 if Has_Relative_Deadline_Pragma (P) then
15519 Error_Pragma ("duplicate pragma% not allowed");
15520 end if;
15521
15522 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
15523 -- Relative_Deadline pragma node cannot be inserted in the Rep
15524 -- Item chain of Ent since it is rewritten by the expander as a
15525 -- procedure call statement that will break the chain.
15526
15527 Set_Has_Relative_Deadline_Pragma (P, True);
15528 end Relative_Deadline;
15529
15530 ------------------------
15531 -- Remote_Access_Type --
15532 ------------------------
15533
15534 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
15535
15536 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
15537 E : Entity_Id;
15538
15539 begin
15540 GNAT_Pragma;
15541 Check_Arg_Count (1);
15542 Check_Optional_Identifier (Arg1, Name_Entity);
15543 Check_Arg_Is_Local_Name (Arg1);
15544
15545 E := Entity (Get_Pragma_Arg (Arg1));
15546
15547 if Nkind (Parent (E)) = N_Formal_Type_Declaration
15548 and then Ekind (E) = E_General_Access_Type
15549 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
15550 and then Scope (Root_Type (Directly_Designated_Type (E)))
15551 = Scope (E)
15552 and then Is_Valid_Remote_Object_Type
15553 (Root_Type (Directly_Designated_Type (E)))
15554 then
15555 Set_Is_Remote_Types (E);
15556
15557 else
15558 Error_Pragma_Arg
15559 ("pragma% applies only to formal access to classwide types",
15560 Arg1);
15561 end if;
15562 end Remote_Access_Type;
15563
15564 ---------------------------
15565 -- Remote_Call_Interface --
15566 ---------------------------
15567
15568 -- pragma Remote_Call_Interface [(library_unit_NAME)];
15569
15570 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
15571 Cunit_Node : Node_Id;
15572 Cunit_Ent : Entity_Id;
15573 K : Node_Kind;
15574
15575 begin
15576 Check_Ada_83_Warning;
15577 Check_Valid_Library_Unit_Pragma;
15578
15579 if Nkind (N) = N_Null_Statement then
15580 return;
15581 end if;
15582
15583 Cunit_Node := Cunit (Current_Sem_Unit);
15584 K := Nkind (Unit (Cunit_Node));
15585 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
15586
15587 if K = N_Package_Declaration
15588 or else K = N_Generic_Package_Declaration
15589 or else K = N_Subprogram_Declaration
15590 or else K = N_Generic_Subprogram_Declaration
15591 or else (K = N_Subprogram_Body
15592 and then Acts_As_Spec (Unit (Cunit_Node)))
15593 then
15594 null;
15595 else
15596 Error_Pragma (
15597 "pragma% must apply to package or subprogram declaration");
15598 end if;
15599
15600 Set_Is_Remote_Call_Interface (Cunit_Ent);
15601 end Remote_Call_Interface;
15602
15603 ------------------
15604 -- Remote_Types --
15605 ------------------
15606
15607 -- pragma Remote_Types [(library_unit_NAME)];
15608
15609 when Pragma_Remote_Types => Remote_Types : declare
15610 Cunit_Node : Node_Id;
15611 Cunit_Ent : Entity_Id;
15612
15613 begin
15614 Check_Ada_83_Warning;
15615 Check_Valid_Library_Unit_Pragma;
15616
15617 if Nkind (N) = N_Null_Statement then
15618 return;
15619 end if;
15620
15621 Cunit_Node := Cunit (Current_Sem_Unit);
15622 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
15623
15624 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
15625 N_Generic_Package_Declaration)
15626 then
15627 Error_Pragma
15628 ("pragma% can only apply to a package declaration");
15629 end if;
15630
15631 Set_Is_Remote_Types (Cunit_Ent);
15632 end Remote_Types;
15633
15634 ---------------
15635 -- Ravenscar --
15636 ---------------
15637
15638 -- pragma Ravenscar;
15639
15640 when Pragma_Ravenscar =>
15641 GNAT_Pragma;
15642 Check_Arg_Count (0);
15643 Check_Valid_Configuration_Pragma;
15644 Set_Ravenscar_Profile (N);
15645
15646 if Warn_On_Obsolescent_Feature then
15647 Error_Msg_N
15648 ("pragma Ravenscar is an obsolescent feature?j?", N);
15649 Error_Msg_N
15650 ("|use pragma Profile (Ravenscar) instead?j?", N);
15651 end if;
15652
15653 -------------------------
15654 -- Restricted_Run_Time --
15655 -------------------------
15656
15657 -- pragma Restricted_Run_Time;
15658
15659 when Pragma_Restricted_Run_Time =>
15660 GNAT_Pragma;
15661 Check_Arg_Count (0);
15662 Check_Valid_Configuration_Pragma;
15663 Set_Profile_Restrictions
15664 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
15665
15666 if Warn_On_Obsolescent_Feature then
15667 Error_Msg_N
15668 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
15669 N);
15670 Error_Msg_N
15671 ("|use pragma Profile (Restricted) instead?j?", N);
15672 end if;
15673
15674 ------------------
15675 -- Restrictions --
15676 ------------------
15677
15678 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
15679
15680 -- RESTRICTION ::=
15681 -- restriction_IDENTIFIER
15682 -- | restriction_parameter_IDENTIFIER => EXPRESSION
15683
15684 when Pragma_Restrictions =>
15685 Process_Restrictions_Or_Restriction_Warnings
15686 (Warn => Treat_Restrictions_As_Warnings);
15687
15688 --------------------------
15689 -- Restriction_Warnings --
15690 --------------------------
15691
15692 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
15693
15694 -- RESTRICTION ::=
15695 -- restriction_IDENTIFIER
15696 -- | restriction_parameter_IDENTIFIER => EXPRESSION
15697
15698 when Pragma_Restriction_Warnings =>
15699 GNAT_Pragma;
15700 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
15701
15702 ----------------
15703 -- Reviewable --
15704 ----------------
15705
15706 -- pragma Reviewable;
15707
15708 when Pragma_Reviewable =>
15709 Check_Ada_83_Warning;
15710 Check_Arg_Count (0);
15711
15712 -- Call dummy debugging function rv. This is done to assist front
15713 -- end debugging. By placing a Reviewable pragma in the source
15714 -- program, a breakpoint on rv catches this place in the source,
15715 -- allowing convenient stepping to the point of interest.
15716
15717 rv;
15718
15719 --------------------------
15720 -- Short_Circuit_And_Or --
15721 --------------------------
15722
15723 when Pragma_Short_Circuit_And_Or =>
15724 GNAT_Pragma;
15725 Check_Arg_Count (0);
15726 Check_Valid_Configuration_Pragma;
15727 Short_Circuit_And_Or := True;
15728
15729 -------------------
15730 -- Share_Generic --
15731 -------------------
15732
15733 -- pragma Share_Generic (NAME {, NAME});
15734
15735 when Pragma_Share_Generic =>
15736 GNAT_Pragma;
15737 Process_Generic_List;
15738
15739 ------------
15740 -- Shared --
15741 ------------
15742
15743 -- pragma Shared (LOCAL_NAME);
15744
15745 when Pragma_Shared =>
15746 GNAT_Pragma;
15747 Process_Atomic_Shared_Volatile;
15748
15749 --------------------
15750 -- Shared_Passive --
15751 --------------------
15752
15753 -- pragma Shared_Passive [(library_unit_NAME)];
15754
15755 -- Set the flag Is_Shared_Passive of program unit name entity
15756
15757 when Pragma_Shared_Passive => Shared_Passive : declare
15758 Cunit_Node : Node_Id;
15759 Cunit_Ent : Entity_Id;
15760
15761 begin
15762 Check_Ada_83_Warning;
15763 Check_Valid_Library_Unit_Pragma;
15764
15765 if Nkind (N) = N_Null_Statement then
15766 return;
15767 end if;
15768
15769 Cunit_Node := Cunit (Current_Sem_Unit);
15770 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
15771
15772 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
15773 N_Generic_Package_Declaration)
15774 then
15775 Error_Pragma
15776 ("pragma% can only apply to a package declaration");
15777 end if;
15778
15779 Set_Is_Shared_Passive (Cunit_Ent);
15780 end Shared_Passive;
15781
15782 -----------------------
15783 -- Short_Descriptors --
15784 -----------------------
15785
15786 -- pragma Short_Descriptors;
15787
15788 when Pragma_Short_Descriptors =>
15789 GNAT_Pragma;
15790 Check_Arg_Count (0);
15791 Check_Valid_Configuration_Pragma;
15792 Short_Descriptors := True;
15793
15794 ------------------------------
15795 -- Simple_Storage_Pool_Type --
15796 ------------------------------
15797
15798 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
15799
15800 when Pragma_Simple_Storage_Pool_Type =>
15801 Simple_Storage_Pool_Type : declare
15802 Type_Id : Node_Id;
15803 Typ : Entity_Id;
15804
15805 begin
15806 GNAT_Pragma;
15807 Check_Arg_Count (1);
15808 Check_Arg_Is_Library_Level_Local_Name (Arg1);
15809
15810 Type_Id := Get_Pragma_Arg (Arg1);
15811 Find_Type (Type_Id);
15812 Typ := Entity (Type_Id);
15813
15814 if Typ = Any_Type then
15815 return;
15816 end if;
15817
15818 -- We require the pragma to apply to a type declared in a package
15819 -- declaration, but not (immediately) within a package body.
15820
15821 if Ekind (Current_Scope) /= E_Package
15822 or else In_Package_Body (Current_Scope)
15823 then
15824 Error_Pragma
15825 ("pragma% can only apply to type declared immediately "
15826 & "within a package declaration");
15827 end if;
15828
15829 -- A simple storage pool type must be an immutably limited record
15830 -- or private type. If the pragma is given for a private type,
15831 -- the full type is similarly restricted (which is checked later
15832 -- in Freeze_Entity).
15833
15834 if Is_Record_Type (Typ)
15835 and then not Is_Immutably_Limited_Type (Typ)
15836 then
15837 Error_Pragma
15838 ("pragma% can only apply to explicitly limited record type");
15839
15840 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
15841 Error_Pragma
15842 ("pragma% can only apply to a private type that is limited");
15843
15844 elsif not Is_Record_Type (Typ)
15845 and then not Is_Private_Type (Typ)
15846 then
15847 Error_Pragma
15848 ("pragma% can only apply to limited record or private type");
15849 end if;
15850
15851 Record_Rep_Item (Typ, N);
15852 end Simple_Storage_Pool_Type;
15853
15854 ----------------------
15855 -- Source_File_Name --
15856 ----------------------
15857
15858 -- There are five forms for this pragma:
15859
15860 -- pragma Source_File_Name (
15861 -- [UNIT_NAME =>] unit_NAME,
15862 -- BODY_FILE_NAME => STRING_LITERAL
15863 -- [, [INDEX =>] INTEGER_LITERAL]);
15864
15865 -- pragma Source_File_Name (
15866 -- [UNIT_NAME =>] unit_NAME,
15867 -- SPEC_FILE_NAME => STRING_LITERAL
15868 -- [, [INDEX =>] INTEGER_LITERAL]);
15869
15870 -- pragma Source_File_Name (
15871 -- BODY_FILE_NAME => STRING_LITERAL
15872 -- [, DOT_REPLACEMENT => STRING_LITERAL]
15873 -- [, CASING => CASING_SPEC]);
15874
15875 -- pragma Source_File_Name (
15876 -- SPEC_FILE_NAME => STRING_LITERAL
15877 -- [, DOT_REPLACEMENT => STRING_LITERAL]
15878 -- [, CASING => CASING_SPEC]);
15879
15880 -- pragma Source_File_Name (
15881 -- SUBUNIT_FILE_NAME => STRING_LITERAL
15882 -- [, DOT_REPLACEMENT => STRING_LITERAL]
15883 -- [, CASING => CASING_SPEC]);
15884
15885 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
15886
15887 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
15888 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
15889 -- only be used when no project file is used, while SFNP can only be
15890 -- used when a project file is used.
15891
15892 -- No processing here. Processing was completed during parsing, since
15893 -- we need to have file names set as early as possible. Units are
15894 -- loaded well before semantic processing starts.
15895
15896 -- The only processing we defer to this point is the check for
15897 -- correct placement.
15898
15899 when Pragma_Source_File_Name =>
15900 GNAT_Pragma;
15901 Check_Valid_Configuration_Pragma;
15902
15903 ------------------------------
15904 -- Source_File_Name_Project --
15905 ------------------------------
15906
15907 -- See Source_File_Name for syntax
15908
15909 -- No processing here. Processing was completed during parsing, since
15910 -- we need to have file names set as early as possible. Units are
15911 -- loaded well before semantic processing starts.
15912
15913 -- The only processing we defer to this point is the check for
15914 -- correct placement.
15915
15916 when Pragma_Source_File_Name_Project =>
15917 GNAT_Pragma;
15918 Check_Valid_Configuration_Pragma;
15919
15920 -- Check that a pragma Source_File_Name_Project is used only in a
15921 -- configuration pragmas file.
15922
15923 -- Pragmas Source_File_Name_Project should only be generated by
15924 -- the Project Manager in configuration pragmas files.
15925
15926 -- This is really an ugly test. It seems to depend on some
15927 -- accidental and undocumented property. At the very least it
15928 -- needs to be documented, but it would be better to have a
15929 -- clean way of testing if we are in a configuration file???
15930
15931 if Present (Parent (N)) then
15932 Error_Pragma
15933 ("pragma% can only appear in a configuration pragmas file");
15934 end if;
15935
15936 ----------------------
15937 -- Source_Reference --
15938 ----------------------
15939
15940 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
15941
15942 -- Nothing to do, all processing completed in Par.Prag, since we need
15943 -- the information for possible parser messages that are output.
15944
15945 when Pragma_Source_Reference =>
15946 GNAT_Pragma;
15947
15948 --------------------------------
15949 -- Static_Elaboration_Desired --
15950 --------------------------------
15951
15952 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
15953
15954 when Pragma_Static_Elaboration_Desired =>
15955 GNAT_Pragma;
15956 Check_At_Most_N_Arguments (1);
15957
15958 if Is_Compilation_Unit (Current_Scope)
15959 and then Ekind (Current_Scope) = E_Package
15960 then
15961 Set_Static_Elaboration_Desired (Current_Scope, True);
15962 else
15963 Error_Pragma ("pragma% must apply to a library-level package");
15964 end if;
15965
15966 ------------------
15967 -- Storage_Size --
15968 ------------------
15969
15970 -- pragma Storage_Size (EXPRESSION);
15971
15972 when Pragma_Storage_Size => Storage_Size : declare
15973 P : constant Node_Id := Parent (N);
15974 Arg : Node_Id;
15975
15976 begin
15977 Check_No_Identifiers;
15978 Check_Arg_Count (1);
15979
15980 -- The expression must be analyzed in the special manner described
15981 -- in "Handling of Default Expressions" in sem.ads.
15982
15983 Arg := Get_Pragma_Arg (Arg1);
15984 Preanalyze_Spec_Expression (Arg, Any_Integer);
15985
15986 if not Is_Static_Expression (Arg) then
15987 Check_Restriction (Static_Storage_Size, Arg);
15988 end if;
15989
15990 if Nkind (P) /= N_Task_Definition then
15991 Pragma_Misplaced;
15992 return;
15993
15994 else
15995 if Has_Storage_Size_Pragma (P) then
15996 Error_Pragma ("duplicate pragma% not allowed");
15997 else
15998 Set_Has_Storage_Size_Pragma (P, True);
15999 end if;
16000
16001 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
16002 end if;
16003 end Storage_Size;
16004
16005 ------------------
16006 -- Storage_Unit --
16007 ------------------
16008
16009 -- pragma Storage_Unit (NUMERIC_LITERAL);
16010
16011 -- Only permitted argument is System'Storage_Unit value
16012
16013 when Pragma_Storage_Unit =>
16014 Check_No_Identifiers;
16015 Check_Arg_Count (1);
16016 Check_Arg_Is_Integer_Literal (Arg1);
16017
16018 if Intval (Get_Pragma_Arg (Arg1)) /=
16019 UI_From_Int (Ttypes.System_Storage_Unit)
16020 then
16021 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
16022 Error_Pragma_Arg
16023 ("the only allowed argument for pragma% is ^", Arg1);
16024 end if;
16025
16026 --------------------
16027 -- Stream_Convert --
16028 --------------------
16029
16030 -- pragma Stream_Convert (
16031 -- [Entity =>] type_LOCAL_NAME,
16032 -- [Read =>] function_NAME,
16033 -- [Write =>] function NAME);
16034
16035 when Pragma_Stream_Convert => Stream_Convert : declare
16036
16037 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
16038 -- Check that the given argument is the name of a local function
16039 -- of one argument that is not overloaded earlier in the current
16040 -- local scope. A check is also made that the argument is a
16041 -- function with one parameter.
16042
16043 --------------------------------------
16044 -- Check_OK_Stream_Convert_Function --
16045 --------------------------------------
16046
16047 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
16048 Ent : Entity_Id;
16049
16050 begin
16051 Check_Arg_Is_Local_Name (Arg);
16052 Ent := Entity (Get_Pragma_Arg (Arg));
16053
16054 if Has_Homonym (Ent) then
16055 Error_Pragma_Arg
16056 ("argument for pragma% may not be overloaded", Arg);
16057 end if;
16058
16059 if Ekind (Ent) /= E_Function
16060 or else No (First_Formal (Ent))
16061 or else Present (Next_Formal (First_Formal (Ent)))
16062 then
16063 Error_Pragma_Arg
16064 ("argument for pragma% must be function of one argument",
16065 Arg);
16066 end if;
16067 end Check_OK_Stream_Convert_Function;
16068
16069 -- Start of processing for Stream_Convert
16070
16071 begin
16072 GNAT_Pragma;
16073 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
16074 Check_Arg_Count (3);
16075 Check_Optional_Identifier (Arg1, Name_Entity);
16076 Check_Optional_Identifier (Arg2, Name_Read);
16077 Check_Optional_Identifier (Arg3, Name_Write);
16078 Check_Arg_Is_Local_Name (Arg1);
16079 Check_OK_Stream_Convert_Function (Arg2);
16080 Check_OK_Stream_Convert_Function (Arg3);
16081
16082 declare
16083 Typ : constant Entity_Id :=
16084 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
16085 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
16086 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
16087
16088 begin
16089 Check_First_Subtype (Arg1);
16090
16091 -- Check for too early or too late. Note that we don't enforce
16092 -- the rule about primitive operations in this case, since, as
16093 -- is the case for explicit stream attributes themselves, these
16094 -- restrictions are not appropriate. Note that the chaining of
16095 -- the pragma by Rep_Item_Too_Late is actually the critical
16096 -- processing done for this pragma.
16097
16098 if Rep_Item_Too_Early (Typ, N)
16099 or else
16100 Rep_Item_Too_Late (Typ, N, FOnly => True)
16101 then
16102 return;
16103 end if;
16104
16105 -- Return if previous error
16106
16107 if Etype (Typ) = Any_Type
16108 or else
16109 Etype (Read) = Any_Type
16110 or else
16111 Etype (Write) = Any_Type
16112 then
16113 return;
16114 end if;
16115
16116 -- Error checks
16117
16118 if Underlying_Type (Etype (Read)) /= Typ then
16119 Error_Pragma_Arg
16120 ("incorrect return type for function&", Arg2);
16121 end if;
16122
16123 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
16124 Error_Pragma_Arg
16125 ("incorrect parameter type for function&", Arg3);
16126 end if;
16127
16128 if Underlying_Type (Etype (First_Formal (Read))) /=
16129 Underlying_Type (Etype (Write))
16130 then
16131 Error_Pragma_Arg
16132 ("result type of & does not match Read parameter type",
16133 Arg3);
16134 end if;
16135 end;
16136 end Stream_Convert;
16137
16138 ------------------
16139 -- Style_Checks --
16140 ------------------
16141
16142 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
16143
16144 -- This is processed by the parser since some of the style checks
16145 -- take place during source scanning and parsing. This means that
16146 -- we don't need to issue error messages here.
16147
16148 when Pragma_Style_Checks => Style_Checks : declare
16149 A : constant Node_Id := Get_Pragma_Arg (Arg1);
16150 S : String_Id;
16151 C : Char_Code;
16152
16153 begin
16154 GNAT_Pragma;
16155 Check_No_Identifiers;
16156
16157 -- Two argument form
16158
16159 if Arg_Count = 2 then
16160 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
16161
16162 declare
16163 E_Id : Node_Id;
16164 E : Entity_Id;
16165
16166 begin
16167 E_Id := Get_Pragma_Arg (Arg2);
16168 Analyze (E_Id);
16169
16170 if not Is_Entity_Name (E_Id) then
16171 Error_Pragma_Arg
16172 ("second argument of pragma% must be entity name",
16173 Arg2);
16174 end if;
16175
16176 E := Entity (E_Id);
16177
16178 if not Ignore_Style_Checks_Pragmas then
16179 if E = Any_Id then
16180 return;
16181 else
16182 loop
16183 Set_Suppress_Style_Checks
16184 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
16185 exit when No (Homonym (E));
16186 E := Homonym (E);
16187 end loop;
16188 end if;
16189 end if;
16190 end;
16191
16192 -- One argument form
16193
16194 else
16195 Check_Arg_Count (1);
16196
16197 if Nkind (A) = N_String_Literal then
16198 S := Strval (A);
16199
16200 declare
16201 Slen : constant Natural := Natural (String_Length (S));
16202 Options : String (1 .. Slen);
16203 J : Natural;
16204
16205 begin
16206 J := 1;
16207 loop
16208 C := Get_String_Char (S, Int (J));
16209 exit when not In_Character_Range (C);
16210 Options (J) := Get_Character (C);
16211
16212 -- If at end of string, set options. As per discussion
16213 -- above, no need to check for errors, since we issued
16214 -- them in the parser.
16215
16216 if J = Slen then
16217 if not Ignore_Style_Checks_Pragmas then
16218 Set_Style_Check_Options (Options);
16219 end if;
16220
16221 exit;
16222 end if;
16223
16224 J := J + 1;
16225 end loop;
16226 end;
16227
16228 elsif Nkind (A) = N_Identifier then
16229 if Chars (A) = Name_All_Checks then
16230 if not Ignore_Style_Checks_Pragmas then
16231 if GNAT_Mode then
16232 Set_GNAT_Style_Check_Options;
16233 else
16234 Set_Default_Style_Check_Options;
16235 end if;
16236 end if;
16237
16238 elsif Chars (A) = Name_On then
16239 if not Ignore_Style_Checks_Pragmas then
16240 Style_Check := True;
16241 end if;
16242
16243 elsif Chars (A) = Name_Off then
16244 if not Ignore_Style_Checks_Pragmas then
16245 Style_Check := False;
16246 end if;
16247 end if;
16248 end if;
16249 end if;
16250 end Style_Checks;
16251
16252 --------------
16253 -- Subtitle --
16254 --------------
16255
16256 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
16257
16258 when Pragma_Subtitle =>
16259 GNAT_Pragma;
16260 Check_Arg_Count (1);
16261 Check_Optional_Identifier (Arg1, Name_Subtitle);
16262 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
16263 Store_Note (N);
16264
16265 --------------
16266 -- Suppress --
16267 --------------
16268
16269 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
16270
16271 when Pragma_Suppress =>
16272 Process_Suppress_Unsuppress (True);
16273
16274 ------------------
16275 -- Suppress_All --
16276 ------------------
16277
16278 -- pragma Suppress_All;
16279
16280 -- The only check made here is that the pragma has no arguments.
16281 -- There are no placement rules, and the processing required (setting
16282 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
16283 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
16284 -- then creates and inserts a pragma Suppress (All_Checks).
16285
16286 when Pragma_Suppress_All =>
16287 GNAT_Pragma;
16288 Check_Arg_Count (0);
16289
16290 -------------------------
16291 -- Suppress_Debug_Info --
16292 -------------------------
16293
16294 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
16295
16296 when Pragma_Suppress_Debug_Info =>
16297 GNAT_Pragma;
16298 Check_Arg_Count (1);
16299 Check_Optional_Identifier (Arg1, Name_Entity);
16300 Check_Arg_Is_Local_Name (Arg1);
16301 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
16302
16303 ----------------------------------
16304 -- Suppress_Exception_Locations --
16305 ----------------------------------
16306
16307 -- pragma Suppress_Exception_Locations;
16308
16309 when Pragma_Suppress_Exception_Locations =>
16310 GNAT_Pragma;
16311 Check_Arg_Count (0);
16312 Check_Valid_Configuration_Pragma;
16313 Exception_Locations_Suppressed := True;
16314
16315 -----------------------------
16316 -- Suppress_Initialization --
16317 -----------------------------
16318
16319 -- pragma Suppress_Initialization ([Entity =>] type_Name);
16320
16321 when Pragma_Suppress_Initialization => Suppress_Init : declare
16322 E_Id : Node_Id;
16323 E : Entity_Id;
16324
16325 begin
16326 GNAT_Pragma;
16327 Check_Arg_Count (1);
16328 Check_Optional_Identifier (Arg1, Name_Entity);
16329 Check_Arg_Is_Local_Name (Arg1);
16330
16331 E_Id := Get_Pragma_Arg (Arg1);
16332
16333 if Etype (E_Id) = Any_Type then
16334 return;
16335 end if;
16336
16337 E := Entity (E_Id);
16338
16339 if not Is_Type (E) then
16340 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
16341 end if;
16342
16343 if Rep_Item_Too_Early (E, N)
16344 or else
16345 Rep_Item_Too_Late (E, N, FOnly => True)
16346 then
16347 return;
16348 end if;
16349
16350 -- For incomplete/private type, set flag on full view
16351
16352 if Is_Incomplete_Or_Private_Type (E) then
16353 if No (Full_View (Base_Type (E))) then
16354 Error_Pragma_Arg
16355 ("argument of pragma% cannot be an incomplete type", Arg1);
16356 else
16357 Set_Suppress_Initialization (Full_View (Base_Type (E)));
16358 end if;
16359
16360 -- For first subtype, set flag on base type
16361
16362 elsif Is_First_Subtype (E) then
16363 Set_Suppress_Initialization (Base_Type (E));
16364
16365 -- For other than first subtype, set flag on subtype itself
16366
16367 else
16368 Set_Suppress_Initialization (E);
16369 end if;
16370 end Suppress_Init;
16371
16372 -----------------
16373 -- System_Name --
16374 -----------------
16375
16376 -- pragma System_Name (DIRECT_NAME);
16377
16378 -- Syntax check: one argument, which must be the identifier GNAT or
16379 -- the identifier GCC, no other identifiers are acceptable.
16380
16381 when Pragma_System_Name =>
16382 GNAT_Pragma;
16383 Check_No_Identifiers;
16384 Check_Arg_Count (1);
16385 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
16386
16387 -----------------------------
16388 -- Task_Dispatching_Policy --
16389 -----------------------------
16390
16391 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
16392
16393 when Pragma_Task_Dispatching_Policy => declare
16394 DP : Character;
16395
16396 begin
16397 Check_Ada_83_Warning;
16398 Check_Arg_Count (1);
16399 Check_No_Identifiers;
16400 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
16401 Check_Valid_Configuration_Pragma;
16402 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
16403 DP := Fold_Upper (Name_Buffer (1));
16404
16405 if Task_Dispatching_Policy /= ' '
16406 and then Task_Dispatching_Policy /= DP
16407 then
16408 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
16409 Error_Pragma
16410 ("task dispatching policy incompatible with policy#");
16411
16412 -- Set new policy, but always preserve System_Location since we
16413 -- like the error message with the run time name.
16414
16415 else
16416 Task_Dispatching_Policy := DP;
16417
16418 if Task_Dispatching_Policy_Sloc /= System_Location then
16419 Task_Dispatching_Policy_Sloc := Loc;
16420 end if;
16421 end if;
16422 end;
16423
16424 ---------------
16425 -- Task_Info --
16426 ---------------
16427
16428 -- pragma Task_Info (EXPRESSION);
16429
16430 when Pragma_Task_Info => Task_Info : declare
16431 P : constant Node_Id := Parent (N);
16432 Ent : Entity_Id;
16433
16434 begin
16435 GNAT_Pragma;
16436
16437 if Nkind (P) /= N_Task_Definition then
16438 Error_Pragma ("pragma% must appear in task definition");
16439 end if;
16440
16441 Check_No_Identifiers;
16442 Check_Arg_Count (1);
16443
16444 Analyze_And_Resolve
16445 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
16446
16447 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
16448 return;
16449 end if;
16450
16451 Ent := Defining_Identifier (Parent (P));
16452
16453 -- Check duplicate pragma before we chain the pragma in the Rep
16454 -- Item chain of Ent.
16455
16456 if Has_Rep_Pragma
16457 (Ent, Name_Task_Info, Check_Parents => False)
16458 then
16459 Error_Pragma ("duplicate pragma% not allowed");
16460 end if;
16461
16462 Record_Rep_Item (Ent, N);
16463 end Task_Info;
16464
16465 ---------------
16466 -- Task_Name --
16467 ---------------
16468
16469 -- pragma Task_Name (string_EXPRESSION);
16470
16471 when Pragma_Task_Name => Task_Name : declare
16472 P : constant Node_Id := Parent (N);
16473 Arg : Node_Id;
16474 Ent : Entity_Id;
16475
16476 begin
16477 Check_No_Identifiers;
16478 Check_Arg_Count (1);
16479
16480 Arg := Get_Pragma_Arg (Arg1);
16481
16482 -- The expression is used in the call to Create_Task, and must be
16483 -- expanded there, not in the context of the current spec. It must
16484 -- however be analyzed to capture global references, in case it
16485 -- appears in a generic context.
16486
16487 Preanalyze_And_Resolve (Arg, Standard_String);
16488
16489 if Nkind (P) /= N_Task_Definition then
16490 Pragma_Misplaced;
16491 end if;
16492
16493 Ent := Defining_Identifier (Parent (P));
16494
16495 -- Check duplicate pragma before we chain the pragma in the Rep
16496 -- Item chain of Ent.
16497
16498 if Has_Rep_Pragma
16499 (Ent, Name_Task_Name, Check_Parents => False)
16500 then
16501 Error_Pragma ("duplicate pragma% not allowed");
16502 end if;
16503
16504 Record_Rep_Item (Ent, N);
16505 end Task_Name;
16506
16507 ------------------
16508 -- Task_Storage --
16509 ------------------
16510
16511 -- pragma Task_Storage (
16512 -- [Task_Type =>] LOCAL_NAME,
16513 -- [Top_Guard =>] static_integer_EXPRESSION);
16514
16515 when Pragma_Task_Storage => Task_Storage : declare
16516 Args : Args_List (1 .. 2);
16517 Names : constant Name_List (1 .. 2) := (
16518 Name_Task_Type,
16519 Name_Top_Guard);
16520
16521 Task_Type : Node_Id renames Args (1);
16522 Top_Guard : Node_Id renames Args (2);
16523
16524 Ent : Entity_Id;
16525
16526 begin
16527 GNAT_Pragma;
16528 Gather_Associations (Names, Args);
16529
16530 if No (Task_Type) then
16531 Error_Pragma
16532 ("missing task_type argument for pragma%");
16533 end if;
16534
16535 Check_Arg_Is_Local_Name (Task_Type);
16536
16537 Ent := Entity (Task_Type);
16538
16539 if not Is_Task_Type (Ent) then
16540 Error_Pragma_Arg
16541 ("argument for pragma% must be task type", Task_Type);
16542 end if;
16543
16544 if No (Top_Guard) then
16545 Error_Pragma_Arg
16546 ("pragma% takes two arguments", Task_Type);
16547 else
16548 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
16549 end if;
16550
16551 Check_First_Subtype (Task_Type);
16552
16553 if Rep_Item_Too_Late (Ent, N) then
16554 raise Pragma_Exit;
16555 end if;
16556 end Task_Storage;
16557
16558 ---------------
16559 -- Test_Case --
16560 ---------------
16561
16562 -- pragma Test_Case
16563 -- ([Name =>] Static_String_EXPRESSION
16564 -- ,[Mode =>] MODE_TYPE
16565 -- [, Requires => Boolean_EXPRESSION]
16566 -- [, Ensures => Boolean_EXPRESSION]);
16567
16568 -- MODE_TYPE ::= Nominal | Robustness
16569
16570 when Pragma_Test_Case =>
16571 Check_Contract_Or_Test_Case;
16572
16573 --------------------------
16574 -- Thread_Local_Storage --
16575 --------------------------
16576
16577 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
16578
16579 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
16580 Id : Node_Id;
16581 E : Entity_Id;
16582
16583 begin
16584 GNAT_Pragma;
16585 Check_Arg_Count (1);
16586 Check_Optional_Identifier (Arg1, Name_Entity);
16587 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16588
16589 Id := Get_Pragma_Arg (Arg1);
16590 Analyze (Id);
16591
16592 if not Is_Entity_Name (Id)
16593 or else Ekind (Entity (Id)) /= E_Variable
16594 then
16595 Error_Pragma_Arg ("local variable name required", Arg1);
16596 end if;
16597
16598 E := Entity (Id);
16599
16600 if Rep_Item_Too_Early (E, N)
16601 or else Rep_Item_Too_Late (E, N)
16602 then
16603 raise Pragma_Exit;
16604 end if;
16605
16606 Set_Has_Pragma_Thread_Local_Storage (E);
16607 Set_Has_Gigi_Rep_Item (E);
16608 end Thread_Local_Storage;
16609
16610 ----------------
16611 -- Time_Slice --
16612 ----------------
16613
16614 -- pragma Time_Slice (static_duration_EXPRESSION);
16615
16616 when Pragma_Time_Slice => Time_Slice : declare
16617 Val : Ureal;
16618 Nod : Node_Id;
16619
16620 begin
16621 GNAT_Pragma;
16622 Check_Arg_Count (1);
16623 Check_No_Identifiers;
16624 Check_In_Main_Program;
16625 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
16626
16627 if not Error_Posted (Arg1) then
16628 Nod := Next (N);
16629 while Present (Nod) loop
16630 if Nkind (Nod) = N_Pragma
16631 and then Pragma_Name (Nod) = Name_Time_Slice
16632 then
16633 Error_Msg_Name_1 := Pname;
16634 Error_Msg_N ("duplicate pragma% not permitted", Nod);
16635 end if;
16636
16637 Next (Nod);
16638 end loop;
16639 end if;
16640
16641 -- Process only if in main unit
16642
16643 if Get_Source_Unit (Loc) = Main_Unit then
16644 Opt.Time_Slice_Set := True;
16645 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
16646
16647 if Val <= Ureal_0 then
16648 Opt.Time_Slice_Value := 0;
16649
16650 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
16651 Opt.Time_Slice_Value := 1_000_000_000;
16652
16653 else
16654 Opt.Time_Slice_Value :=
16655 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
16656 end if;
16657 end if;
16658 end Time_Slice;
16659
16660 -----------
16661 -- Title --
16662 -----------
16663
16664 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
16665
16666 -- TITLING_OPTION ::=
16667 -- [Title =>] STRING_LITERAL
16668 -- | [Subtitle =>] STRING_LITERAL
16669
16670 when Pragma_Title => Title : declare
16671 Args : Args_List (1 .. 2);
16672 Names : constant Name_List (1 .. 2) := (
16673 Name_Title,
16674 Name_Subtitle);
16675
16676 begin
16677 GNAT_Pragma;
16678 Gather_Associations (Names, Args);
16679 Store_Note (N);
16680
16681 for J in 1 .. 2 loop
16682 if Present (Args (J)) then
16683 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
16684 end if;
16685 end loop;
16686 end Title;
16687
16688 ---------------------
16689 -- Unchecked_Union --
16690 ---------------------
16691
16692 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
16693
16694 when Pragma_Unchecked_Union => Unchecked_Union : declare
16695 Assoc : constant Node_Id := Arg1;
16696 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
16697 Typ : Entity_Id;
16698 Tdef : Node_Id;
16699 Clist : Node_Id;
16700 Vpart : Node_Id;
16701 Comp : Node_Id;
16702 Variant : Node_Id;
16703
16704 begin
16705 Ada_2005_Pragma;
16706 Check_No_Identifiers;
16707 Check_Arg_Count (1);
16708 Check_Arg_Is_Local_Name (Arg1);
16709
16710 Find_Type (Type_Id);
16711
16712 Typ := Entity (Type_Id);
16713
16714 if Typ = Any_Type
16715 or else Rep_Item_Too_Early (Typ, N)
16716 then
16717 return;
16718 else
16719 Typ := Underlying_Type (Typ);
16720 end if;
16721
16722 if Rep_Item_Too_Late (Typ, N) then
16723 return;
16724 end if;
16725
16726 Check_First_Subtype (Arg1);
16727
16728 -- Note remaining cases are references to a type in the current
16729 -- declarative part. If we find an error, we post the error on
16730 -- the relevant type declaration at an appropriate point.
16731
16732 if not Is_Record_Type (Typ) then
16733 Error_Msg_N ("unchecked union must be record type", Typ);
16734 return;
16735
16736 elsif Is_Tagged_Type (Typ) then
16737 Error_Msg_N ("unchecked union must not be tagged", Typ);
16738 return;
16739
16740 elsif not Has_Discriminants (Typ) then
16741 Error_Msg_N
16742 ("unchecked union must have one discriminant", Typ);
16743 return;
16744
16745 -- Note: in previous versions of GNAT we used to check for limited
16746 -- types and give an error, but in fact the standard does allow
16747 -- Unchecked_Union on limited types, so this check was removed.
16748
16749 -- Similarly, GNAT used to require that all discriminants have
16750 -- default values, but this is not mandated by the RM.
16751
16752 -- Proceed with basic error checks completed
16753
16754 else
16755 Tdef := Type_Definition (Declaration_Node (Typ));
16756 Clist := Component_List (Tdef);
16757
16758 -- Check presence of component list and variant part
16759
16760 if No (Clist) or else No (Variant_Part (Clist)) then
16761 Error_Msg_N
16762 ("unchecked union must have variant part", Tdef);
16763 return;
16764 end if;
16765
16766 -- Check components
16767
16768 Comp := First (Component_Items (Clist));
16769 while Present (Comp) loop
16770 Check_Component (Comp, Typ);
16771 Next (Comp);
16772 end loop;
16773
16774 -- Check variant part
16775
16776 Vpart := Variant_Part (Clist);
16777
16778 Variant := First (Variants (Vpart));
16779 while Present (Variant) loop
16780 Check_Variant (Variant, Typ);
16781 Next (Variant);
16782 end loop;
16783 end if;
16784
16785 Set_Is_Unchecked_Union (Typ);
16786 Set_Convention (Typ, Convention_C);
16787 Set_Has_Unchecked_Union (Base_Type (Typ));
16788 Set_Is_Unchecked_Union (Base_Type (Typ));
16789 end Unchecked_Union;
16790
16791 ------------------------
16792 -- Unimplemented_Unit --
16793 ------------------------
16794
16795 -- pragma Unimplemented_Unit;
16796
16797 -- Note: this only gives an error if we are generating code, or if
16798 -- we are in a generic library unit (where the pragma appears in the
16799 -- body, not in the spec).
16800
16801 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
16802 Cunitent : constant Entity_Id :=
16803 Cunit_Entity (Get_Source_Unit (Loc));
16804 Ent_Kind : constant Entity_Kind :=
16805 Ekind (Cunitent);
16806
16807 begin
16808 GNAT_Pragma;
16809 Check_Arg_Count (0);
16810
16811 if Operating_Mode = Generate_Code
16812 or else Ent_Kind = E_Generic_Function
16813 or else Ent_Kind = E_Generic_Procedure
16814 or else Ent_Kind = E_Generic_Package
16815 then
16816 Get_Name_String (Chars (Cunitent));
16817 Set_Casing (Mixed_Case);
16818 Write_Str (Name_Buffer (1 .. Name_Len));
16819 Write_Str (" is not supported in this configuration");
16820 Write_Eol;
16821 raise Unrecoverable_Error;
16822 end if;
16823 end Unimplemented_Unit;
16824
16825 ------------------------
16826 -- Universal_Aliasing --
16827 ------------------------
16828
16829 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
16830
16831 when Pragma_Universal_Aliasing => Universal_Alias : declare
16832 E_Id : Entity_Id;
16833
16834 begin
16835 GNAT_Pragma;
16836 Check_Arg_Count (1);
16837 Check_Optional_Identifier (Arg2, Name_Entity);
16838 Check_Arg_Is_Local_Name (Arg1);
16839 E_Id := Entity (Get_Pragma_Arg (Arg1));
16840
16841 if E_Id = Any_Type then
16842 return;
16843 elsif No (E_Id) or else not Is_Type (E_Id) then
16844 Error_Pragma_Arg ("pragma% requires type", Arg1);
16845 end if;
16846
16847 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
16848 Record_Rep_Item (E_Id, N);
16849 end Universal_Alias;
16850
16851 --------------------
16852 -- Universal_Data --
16853 --------------------
16854
16855 -- pragma Universal_Data [(library_unit_NAME)];
16856
16857 when Pragma_Universal_Data =>
16858 GNAT_Pragma;
16859
16860 -- If this is a configuration pragma, then set the universal
16861 -- addressing option, otherwise confirm that the pragma satisfies
16862 -- the requirements of library unit pragma placement and leave it
16863 -- to the GNAAMP back end to detect the pragma (avoids transitive
16864 -- setting of the option due to withed units).
16865
16866 if Is_Configuration_Pragma then
16867 Universal_Addressing_On_AAMP := True;
16868 else
16869 Check_Valid_Library_Unit_Pragma;
16870 end if;
16871
16872 if not AAMP_On_Target then
16873 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
16874 end if;
16875
16876 ----------------
16877 -- Unmodified --
16878 ----------------
16879
16880 -- pragma Unmodified (local_Name {, local_Name});
16881
16882 when Pragma_Unmodified => Unmodified : declare
16883 Arg_Node : Node_Id;
16884 Arg_Expr : Node_Id;
16885 Arg_Ent : Entity_Id;
16886
16887 begin
16888 GNAT_Pragma;
16889 Check_At_Least_N_Arguments (1);
16890
16891 -- Loop through arguments
16892
16893 Arg_Node := Arg1;
16894 while Present (Arg_Node) loop
16895 Check_No_Identifier (Arg_Node);
16896
16897 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
16898 -- in fact generate reference, so that the entity will have a
16899 -- reference, which will inhibit any warnings about it not
16900 -- being referenced, and also properly show up in the ali file
16901 -- as a reference. But this reference is recorded before the
16902 -- Has_Pragma_Unreferenced flag is set, so that no warning is
16903 -- generated for this reference.
16904
16905 Check_Arg_Is_Local_Name (Arg_Node);
16906 Arg_Expr := Get_Pragma_Arg (Arg_Node);
16907
16908 if Is_Entity_Name (Arg_Expr) then
16909 Arg_Ent := Entity (Arg_Expr);
16910
16911 if not Is_Assignable (Arg_Ent) then
16912 Error_Pragma_Arg
16913 ("pragma% can only be applied to a variable",
16914 Arg_Expr);
16915 else
16916 Set_Has_Pragma_Unmodified (Arg_Ent);
16917 end if;
16918 end if;
16919
16920 Next (Arg_Node);
16921 end loop;
16922 end Unmodified;
16923
16924 ------------------
16925 -- Unreferenced --
16926 ------------------
16927
16928 -- pragma Unreferenced (local_Name {, local_Name});
16929
16930 -- or when used in a context clause:
16931
16932 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
16933
16934 when Pragma_Unreferenced => Unreferenced : declare
16935 Arg_Node : Node_Id;
16936 Arg_Expr : Node_Id;
16937 Arg_Ent : Entity_Id;
16938 Citem : Node_Id;
16939
16940 begin
16941 GNAT_Pragma;
16942 Check_At_Least_N_Arguments (1);
16943
16944 -- Check case of appearing within context clause
16945
16946 if Is_In_Context_Clause then
16947
16948 -- The arguments must all be units mentioned in a with clause
16949 -- in the same context clause. Note we already checked (in
16950 -- Par.Prag) that the arguments are either identifiers or
16951 -- selected components.
16952
16953 Arg_Node := Arg1;
16954 while Present (Arg_Node) loop
16955 Citem := First (List_Containing (N));
16956 while Citem /= N loop
16957 if Nkind (Citem) = N_With_Clause
16958 and then
16959 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
16960 then
16961 Set_Has_Pragma_Unreferenced
16962 (Cunit_Entity
16963 (Get_Source_Unit
16964 (Library_Unit (Citem))));
16965 Set_Unit_Name
16966 (Get_Pragma_Arg (Arg_Node), Name (Citem));
16967 exit;
16968 end if;
16969
16970 Next (Citem);
16971 end loop;
16972
16973 if Citem = N then
16974 Error_Pragma_Arg
16975 ("argument of pragma% is not withed unit", Arg_Node);
16976 end if;
16977
16978 Next (Arg_Node);
16979 end loop;
16980
16981 -- Case of not in list of context items
16982
16983 else
16984 Arg_Node := Arg1;
16985 while Present (Arg_Node) loop
16986 Check_No_Identifier (Arg_Node);
16987
16988 -- Note: the analyze call done by Check_Arg_Is_Local_Name
16989 -- will in fact generate reference, so that the entity will
16990 -- have a reference, which will inhibit any warnings about
16991 -- it not being referenced, and also properly show up in the
16992 -- ali file as a reference. But this reference is recorded
16993 -- before the Has_Pragma_Unreferenced flag is set, so that
16994 -- no warning is generated for this reference.
16995
16996 Check_Arg_Is_Local_Name (Arg_Node);
16997 Arg_Expr := Get_Pragma_Arg (Arg_Node);
16998
16999 if Is_Entity_Name (Arg_Expr) then
17000 Arg_Ent := Entity (Arg_Expr);
17001
17002 -- If the entity is overloaded, the pragma applies to the
17003 -- most recent overloading, as documented. In this case,
17004 -- name resolution does not generate a reference, so it
17005 -- must be done here explicitly.
17006
17007 if Is_Overloaded (Arg_Expr) then
17008 Generate_Reference (Arg_Ent, N);
17009 end if;
17010
17011 Set_Has_Pragma_Unreferenced (Arg_Ent);
17012 end if;
17013
17014 Next (Arg_Node);
17015 end loop;
17016 end if;
17017 end Unreferenced;
17018
17019 --------------------------
17020 -- Unreferenced_Objects --
17021 --------------------------
17022
17023 -- pragma Unreferenced_Objects (local_Name {, local_Name});
17024
17025 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
17026 Arg_Node : Node_Id;
17027 Arg_Expr : Node_Id;
17028
17029 begin
17030 GNAT_Pragma;
17031 Check_At_Least_N_Arguments (1);
17032
17033 Arg_Node := Arg1;
17034 while Present (Arg_Node) loop
17035 Check_No_Identifier (Arg_Node);
17036 Check_Arg_Is_Local_Name (Arg_Node);
17037 Arg_Expr := Get_Pragma_Arg (Arg_Node);
17038
17039 if not Is_Entity_Name (Arg_Expr)
17040 or else not Is_Type (Entity (Arg_Expr))
17041 then
17042 Error_Pragma_Arg
17043 ("argument for pragma% must be type or subtype", Arg_Node);
17044 end if;
17045
17046 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
17047 Next (Arg_Node);
17048 end loop;
17049 end Unreferenced_Objects;
17050
17051 ------------------------------
17052 -- Unreserve_All_Interrupts --
17053 ------------------------------
17054
17055 -- pragma Unreserve_All_Interrupts;
17056
17057 when Pragma_Unreserve_All_Interrupts =>
17058 GNAT_Pragma;
17059 Check_Arg_Count (0);
17060
17061 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
17062 Unreserve_All_Interrupts := True;
17063 end if;
17064
17065 ----------------
17066 -- Unsuppress --
17067 ----------------
17068
17069 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
17070
17071 when Pragma_Unsuppress =>
17072 Ada_2005_Pragma;
17073 Process_Suppress_Unsuppress (False);
17074
17075 -------------------
17076 -- Use_VADS_Size --
17077 -------------------
17078
17079 -- pragma Use_VADS_Size;
17080
17081 when Pragma_Use_VADS_Size =>
17082 GNAT_Pragma;
17083 Check_Arg_Count (0);
17084 Check_Valid_Configuration_Pragma;
17085 Use_VADS_Size := True;
17086
17087 ---------------------
17088 -- Validity_Checks --
17089 ---------------------
17090
17091 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
17092
17093 when Pragma_Validity_Checks => Validity_Checks : declare
17094 A : constant Node_Id := Get_Pragma_Arg (Arg1);
17095 S : String_Id;
17096 C : Char_Code;
17097
17098 begin
17099 GNAT_Pragma;
17100 Check_Arg_Count (1);
17101 Check_No_Identifiers;
17102
17103 if Nkind (A) = N_String_Literal then
17104 S := Strval (A);
17105
17106 declare
17107 Slen : constant Natural := Natural (String_Length (S));
17108 Options : String (1 .. Slen);
17109 J : Natural;
17110
17111 begin
17112 J := 1;
17113 loop
17114 C := Get_String_Char (S, Int (J));
17115 exit when not In_Character_Range (C);
17116 Options (J) := Get_Character (C);
17117
17118 if J = Slen then
17119 Set_Validity_Check_Options (Options);
17120 exit;
17121 else
17122 J := J + 1;
17123 end if;
17124 end loop;
17125 end;
17126
17127 elsif Nkind (A) = N_Identifier then
17128 if Chars (A) = Name_All_Checks then
17129 Set_Validity_Check_Options ("a");
17130 elsif Chars (A) = Name_On then
17131 Validity_Checks_On := True;
17132 elsif Chars (A) = Name_Off then
17133 Validity_Checks_On := False;
17134 end if;
17135 end if;
17136 end Validity_Checks;
17137
17138 --------------
17139 -- Volatile --
17140 --------------
17141
17142 -- pragma Volatile (LOCAL_NAME);
17143
17144 when Pragma_Volatile =>
17145 Process_Atomic_Shared_Volatile;
17146
17147 -------------------------
17148 -- Volatile_Components --
17149 -------------------------
17150
17151 -- pragma Volatile_Components (array_LOCAL_NAME);
17152
17153 -- Volatile is handled by the same circuit as Atomic_Components
17154
17155 --------------
17156 -- Warnings --
17157 --------------
17158
17159 -- pragma Warnings (On | Off);
17160 -- pragma Warnings (On | Off, LOCAL_NAME);
17161 -- pragma Warnings (static_string_EXPRESSION);
17162 -- pragma Warnings (On | Off, STRING_LITERAL);
17163
17164 when Pragma_Warnings => Warnings : begin
17165 GNAT_Pragma;
17166 Check_At_Least_N_Arguments (1);
17167 Check_No_Identifiers;
17168
17169 -- If debug flag -gnatd.i is set, pragma is ignored
17170
17171 if Debug_Flag_Dot_I then
17172 return;
17173 end if;
17174
17175 -- Process various forms of the pragma
17176
17177 declare
17178 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
17179
17180 begin
17181 -- One argument case
17182
17183 if Arg_Count = 1 then
17184
17185 -- On/Off one argument case was processed by parser
17186
17187 if Nkind (Argx) = N_Identifier
17188 and then
17189 (Chars (Argx) = Name_On
17190 or else
17191 Chars (Argx) = Name_Off)
17192 then
17193 null;
17194
17195 -- One argument case must be ON/OFF or static string expr
17196
17197 elsif not Is_Static_String_Expression (Arg1) then
17198 Error_Pragma_Arg
17199 ("argument of pragma% must be On/Off or static string "
17200 & "expression", Arg1);
17201
17202 -- One argument string expression case
17203
17204 else
17205 declare
17206 Lit : constant Node_Id := Expr_Value_S (Argx);
17207 Str : constant String_Id := Strval (Lit);
17208 Len : constant Nat := String_Length (Str);
17209 C : Char_Code;
17210 J : Nat;
17211 OK : Boolean;
17212 Chr : Character;
17213
17214 begin
17215 J := 1;
17216 while J <= Len loop
17217 C := Get_String_Char (Str, J);
17218 OK := In_Character_Range (C);
17219
17220 if OK then
17221 Chr := Get_Character (C);
17222
17223 -- Dash case: only -Wxxx is accepted
17224
17225 if J = 1
17226 and then J < Len
17227 and then Chr = '-'
17228 then
17229 J := J + 1;
17230 C := Get_String_Char (Str, J);
17231 Chr := Get_Character (C);
17232 exit when Chr = 'W';
17233 OK := False;
17234
17235 -- Dot case
17236
17237 elsif J < Len and then Chr = '.' then
17238 J := J + 1;
17239 C := Get_String_Char (Str, J);
17240 Chr := Get_Character (C);
17241
17242 if not Set_Dot_Warning_Switch (Chr) then
17243 Error_Pragma_Arg
17244 ("invalid warning switch character "
17245 & '.' & Chr, Arg1);
17246 end if;
17247
17248 -- Non-Dot case
17249
17250 else
17251 OK := Set_Warning_Switch (Chr);
17252 end if;
17253 end if;
17254
17255 if not OK then
17256 Error_Pragma_Arg
17257 ("invalid warning switch character " & Chr,
17258 Arg1);
17259 end if;
17260
17261 J := J + 1;
17262 end loop;
17263 end;
17264 end if;
17265
17266 -- Two or more arguments (must be two)
17267
17268 else
17269 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
17270 Check_At_Most_N_Arguments (2);
17271
17272 declare
17273 E_Id : Node_Id;
17274 E : Entity_Id;
17275 Err : Boolean;
17276
17277 begin
17278 E_Id := Get_Pragma_Arg (Arg2);
17279 Analyze (E_Id);
17280
17281 -- In the expansion of an inlined body, a reference to
17282 -- the formal may be wrapped in a conversion if the
17283 -- actual is a conversion. Retrieve the real entity name.
17284
17285 if (In_Instance_Body or In_Inlined_Body)
17286 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
17287 then
17288 E_Id := Expression (E_Id);
17289 end if;
17290
17291 -- Entity name case
17292
17293 if Is_Entity_Name (E_Id) then
17294 E := Entity (E_Id);
17295
17296 if E = Any_Id then
17297 return;
17298 else
17299 loop
17300 Set_Warnings_Off
17301 (E, (Chars (Get_Pragma_Arg (Arg1)) =
17302 Name_Off));
17303
17304 -- For OFF case, make entry in warnings off
17305 -- pragma table for later processing. But we do
17306 -- not do that within an instance, since these
17307 -- warnings are about what is needed in the
17308 -- template, not an instance of it.
17309
17310 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
17311 and then Warn_On_Warnings_Off
17312 and then not In_Instance
17313 then
17314 Warnings_Off_Pragmas.Append ((N, E));
17315 end if;
17316
17317 if Is_Enumeration_Type (E) then
17318 declare
17319 Lit : Entity_Id;
17320 begin
17321 Lit := First_Literal (E);
17322 while Present (Lit) loop
17323 Set_Warnings_Off (Lit);
17324 Next_Literal (Lit);
17325 end loop;
17326 end;
17327 end if;
17328
17329 exit when No (Homonym (E));
17330 E := Homonym (E);
17331 end loop;
17332 end if;
17333
17334 -- Error if not entity or static string literal case
17335
17336 elsif not Is_Static_String_Expression (Arg2) then
17337 Error_Pragma_Arg
17338 ("second argument of pragma% must be entity name "
17339 & "or static string expression", Arg2);
17340
17341 -- String literal case
17342
17343 else
17344 String_To_Name_Buffer
17345 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
17346
17347 -- Note on configuration pragma case: If this is a
17348 -- configuration pragma, then for an OFF pragma, we
17349 -- just set Config True in the call, which is all
17350 -- that needs to be done. For the case of ON, this
17351 -- is normally an error, unless it is canceling the
17352 -- effect of a previous OFF pragma in the same file.
17353 -- In any other case, an error will be signalled (ON
17354 -- with no matching OFF).
17355
17356 -- Note: We set Used if we are inside a generic to
17357 -- disable the test that the non-config case actually
17358 -- cancels a warning. That's because we can't be sure
17359 -- there isn't an instantiation in some other unit
17360 -- where a warning is suppressed.
17361
17362 -- We could do a little better here by checking if the
17363 -- generic unit we are inside is public, but for now
17364 -- we don't bother with that refinement.
17365
17366 if Chars (Argx) = Name_Off then
17367 Set_Specific_Warning_Off
17368 (Loc, Name_Buffer (1 .. Name_Len),
17369 Config => Is_Configuration_Pragma,
17370 Used => Inside_A_Generic or else In_Instance);
17371
17372 elsif Chars (Argx) = Name_On then
17373 Set_Specific_Warning_On
17374 (Loc, Name_Buffer (1 .. Name_Len), Err);
17375
17376 if Err then
17377 Error_Msg
17378 ("??pragma Warnings On with no matching "
17379 & "Warnings Off", Loc);
17380 end if;
17381 end if;
17382 end if;
17383 end;
17384 end if;
17385 end;
17386 end Warnings;
17387
17388 -------------------
17389 -- Weak_External --
17390 -------------------
17391
17392 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
17393
17394 when Pragma_Weak_External => Weak_External : declare
17395 Ent : Entity_Id;
17396
17397 begin
17398 GNAT_Pragma;
17399 Check_Arg_Count (1);
17400 Check_Optional_Identifier (Arg1, Name_Entity);
17401 Check_Arg_Is_Library_Level_Local_Name (Arg1);
17402 Ent := Entity (Get_Pragma_Arg (Arg1));
17403
17404 if Rep_Item_Too_Early (Ent, N) then
17405 return;
17406 else
17407 Ent := Underlying_Type (Ent);
17408 end if;
17409
17410 -- The only processing required is to link this item on to the
17411 -- list of rep items for the given entity. This is accomplished
17412 -- by the call to Rep_Item_Too_Late (when no error is detected
17413 -- and False is returned).
17414
17415 if Rep_Item_Too_Late (Ent, N) then
17416 return;
17417 else
17418 Set_Has_Gigi_Rep_Item (Ent);
17419 end if;
17420 end Weak_External;
17421
17422 -----------------------------
17423 -- Wide_Character_Encoding --
17424 -----------------------------
17425
17426 -- pragma Wide_Character_Encoding (IDENTIFIER);
17427
17428 when Pragma_Wide_Character_Encoding =>
17429 GNAT_Pragma;
17430
17431 -- Nothing to do, handled in parser. Note that we do not enforce
17432 -- configuration pragma placement, this pragma can appear at any
17433 -- place in the source, allowing mixed encodings within a single
17434 -- source program.
17435
17436 null;
17437
17438 --------------------
17439 -- Unknown_Pragma --
17440 --------------------
17441
17442 -- Should be impossible, since the case of an unknown pragma is
17443 -- separately processed before the case statement is entered.
17444
17445 when Unknown_Pragma =>
17446 raise Program_Error;
17447 end case;
17448
17449 -- AI05-0144: detect dangerous order dependence. Disabled for now,
17450 -- until AI is formally approved.
17451
17452 -- Check_Order_Dependence;
17453
17454 exception
17455 when Pragma_Exit => null;
17456 end Analyze_Pragma;
17457
17458 -------------------
17459 -- Check_Enabled --
17460 -------------------
17461
17462 function Check_Enabled (Nam : Name_Id) return Boolean is
17463 PP : Node_Id;
17464
17465 begin
17466 -- Loop through entries in check policy list
17467
17468 PP := Opt.Check_Policy_List;
17469 loop
17470 -- If there are no specific entries that matched, then we let the
17471 -- setting of assertions govern. Note that this provides the needed
17472 -- compatibility with the RM for the cases of assertion, invariant,
17473 -- precondition, predicate, and postcondition.
17474
17475 if No (PP) then
17476 return Assertions_Enabled;
17477
17478 -- Here we have an entry see if it matches
17479
17480 else
17481 declare
17482 PPA : constant List_Id := Pragma_Argument_Associations (PP);
17483
17484 begin
17485 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
17486 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
17487 when Name_On | Name_Check =>
17488 return True;
17489 when Name_Off | Name_Disable | Name_Ignore =>
17490 return False;
17491 when others =>
17492 raise Program_Error;
17493 end case;
17494
17495 else
17496 PP := Next_Pragma (PP);
17497 end if;
17498 end;
17499 end if;
17500 end loop;
17501 end Check_Enabled;
17502
17503 ---------------------------------
17504 -- Delay_Config_Pragma_Analyze --
17505 ---------------------------------
17506
17507 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
17508 begin
17509 return Pragma_Name (N) = Name_Interrupt_State
17510 or else
17511 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
17512 end Delay_Config_Pragma_Analyze;
17513
17514 -------------------------
17515 -- Get_Base_Subprogram --
17516 -------------------------
17517
17518 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
17519 Result : Entity_Id;
17520
17521 begin
17522 -- Follow subprogram renaming chain
17523
17524 Result := Def_Id;
17525
17526 if Is_Subprogram (Result)
17527 and then
17528 Nkind (Parent (Declaration_Node (Result))) =
17529 N_Subprogram_Renaming_Declaration
17530 and then Present (Alias (Result))
17531 then
17532 Result := Alias (Result);
17533 end if;
17534
17535 return Result;
17536 end Get_Base_Subprogram;
17537
17538 ----------------
17539 -- Initialize --
17540 ----------------
17541
17542 procedure Initialize is
17543 begin
17544 Externals.Init;
17545 end Initialize;
17546
17547 -----------------------------
17548 -- Is_Config_Static_String --
17549 -----------------------------
17550
17551 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
17552
17553 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
17554 -- This is an internal recursive function that is just like the outer
17555 -- function except that it adds the string to the name buffer rather
17556 -- than placing the string in the name buffer.
17557
17558 ------------------------------
17559 -- Add_Config_Static_String --
17560 ------------------------------
17561
17562 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
17563 N : Node_Id;
17564 C : Char_Code;
17565
17566 begin
17567 N := Arg;
17568
17569 if Nkind (N) = N_Op_Concat then
17570 if Add_Config_Static_String (Left_Opnd (N)) then
17571 N := Right_Opnd (N);
17572 else
17573 return False;
17574 end if;
17575 end if;
17576
17577 if Nkind (N) /= N_String_Literal then
17578 Error_Msg_N ("string literal expected for pragma argument", N);
17579 return False;
17580
17581 else
17582 for J in 1 .. String_Length (Strval (N)) loop
17583 C := Get_String_Char (Strval (N), J);
17584
17585 if not In_Character_Range (C) then
17586 Error_Msg
17587 ("string literal contains invalid wide character",
17588 Sloc (N) + 1 + Source_Ptr (J));
17589 return False;
17590 end if;
17591
17592 Add_Char_To_Name_Buffer (Get_Character (C));
17593 end loop;
17594 end if;
17595
17596 return True;
17597 end Add_Config_Static_String;
17598
17599 -- Start of processing for Is_Config_Static_String
17600
17601 begin
17602
17603 Name_Len := 0;
17604 return Add_Config_Static_String (Arg);
17605 end Is_Config_Static_String;
17606
17607 -----------------------------------------
17608 -- Is_Non_Significant_Pragma_Reference --
17609 -----------------------------------------
17610
17611 -- This function makes use of the following static table which indicates
17612 -- whether appearance of some name in a given pragma is to be considered
17613 -- as a reference for the purposes of warnings about unreferenced objects.
17614
17615 -- -1 indicates that references in any argument position are significant
17616 -- 0 indicates that appearance in any argument is not significant
17617 -- +n indicates that appearance as argument n is significant, but all
17618 -- other arguments are not significant
17619 -- 99 special processing required (e.g. for pragma Check)
17620
17621 Sig_Flags : constant array (Pragma_Id) of Int :=
17622 (Pragma_AST_Entry => -1,
17623 Pragma_Abort_Defer => -1,
17624 Pragma_Abstract_State => -1,
17625 Pragma_Ada_83 => -1,
17626 Pragma_Ada_95 => -1,
17627 Pragma_Ada_05 => -1,
17628 Pragma_Ada_2005 => -1,
17629 Pragma_Ada_12 => -1,
17630 Pragma_Ada_2012 => -1,
17631 Pragma_All_Calls_Remote => -1,
17632 Pragma_Annotate => -1,
17633 Pragma_Assert => -1,
17634 Pragma_Assert_And_Cut => -1,
17635 Pragma_Assertion_Policy => 0,
17636 Pragma_Assume => 0,
17637 Pragma_Assume_No_Invalid_Values => 0,
17638 Pragma_Attribute_Definition => +3,
17639 Pragma_Asynchronous => -1,
17640 Pragma_Atomic => 0,
17641 Pragma_Atomic_Components => 0,
17642 Pragma_Attach_Handler => -1,
17643 Pragma_Check => 99,
17644 Pragma_Check_Float_Overflow => 0,
17645 Pragma_Check_Name => 0,
17646 Pragma_Check_Policy => 0,
17647 Pragma_CIL_Constructor => -1,
17648 Pragma_CPP_Class => 0,
17649 Pragma_CPP_Constructor => 0,
17650 Pragma_CPP_Virtual => 0,
17651 Pragma_CPP_Vtable => 0,
17652 Pragma_CPU => -1,
17653 Pragma_C_Pass_By_Copy => 0,
17654 Pragma_Comment => 0,
17655 Pragma_Common_Object => -1,
17656 Pragma_Compile_Time_Error => -1,
17657 Pragma_Compile_Time_Warning => -1,
17658 Pragma_Compiler_Unit => 0,
17659 Pragma_Complete_Representation => 0,
17660 Pragma_Complex_Representation => 0,
17661 Pragma_Component_Alignment => -1,
17662 Pragma_Contract_Case => -1,
17663 Pragma_Contract_Cases => -1,
17664 Pragma_Controlled => 0,
17665 Pragma_Convention => 0,
17666 Pragma_Convention_Identifier => 0,
17667 Pragma_Debug => -1,
17668 Pragma_Debug_Policy => 0,
17669 Pragma_Detect_Blocking => -1,
17670 Pragma_Default_Storage_Pool => -1,
17671 Pragma_Depends => -1,
17672 Pragma_Disable_Atomic_Synchronization => -1,
17673 Pragma_Discard_Names => 0,
17674 Pragma_Dispatching_Domain => -1,
17675 Pragma_Elaborate => -1,
17676 Pragma_Elaborate_All => -1,
17677 Pragma_Elaborate_Body => -1,
17678 Pragma_Elaboration_Checks => -1,
17679 Pragma_Eliminate => -1,
17680 Pragma_Enable_Atomic_Synchronization => -1,
17681 Pragma_Export => -1,
17682 Pragma_Export_Exception => -1,
17683 Pragma_Export_Function => -1,
17684 Pragma_Export_Object => -1,
17685 Pragma_Export_Procedure => -1,
17686 Pragma_Export_Value => -1,
17687 Pragma_Export_Valued_Procedure => -1,
17688 Pragma_Extend_System => -1,
17689 Pragma_Extensions_Allowed => -1,
17690 Pragma_External => -1,
17691 Pragma_Favor_Top_Level => -1,
17692 Pragma_External_Name_Casing => -1,
17693 Pragma_Fast_Math => -1,
17694 Pragma_Finalize_Storage_Only => 0,
17695 Pragma_Float_Representation => 0,
17696 Pragma_Global => -1,
17697 Pragma_Ident => -1,
17698 Pragma_Implementation_Defined => -1,
17699 Pragma_Implemented => -1,
17700 Pragma_Implicit_Packing => 0,
17701 Pragma_Import => +2,
17702 Pragma_Import_Exception => 0,
17703 Pragma_Import_Function => 0,
17704 Pragma_Import_Object => 0,
17705 Pragma_Import_Procedure => 0,
17706 Pragma_Import_Valued_Procedure => 0,
17707 Pragma_Independent => 0,
17708 Pragma_Independent_Components => 0,
17709 Pragma_Initialize_Scalars => -1,
17710 Pragma_Inline => 0,
17711 Pragma_Inline_Always => 0,
17712 Pragma_Inline_Generic => 0,
17713 Pragma_Inspection_Point => -1,
17714 Pragma_Interface => +2,
17715 Pragma_Interface_Name => +2,
17716 Pragma_Interrupt_Handler => -1,
17717 Pragma_Interrupt_Priority => -1,
17718 Pragma_Interrupt_State => -1,
17719 Pragma_Invariant => -1,
17720 Pragma_Java_Constructor => -1,
17721 Pragma_Java_Interface => -1,
17722 Pragma_Keep_Names => 0,
17723 Pragma_License => -1,
17724 Pragma_Link_With => -1,
17725 Pragma_Linker_Alias => -1,
17726 Pragma_Linker_Constructor => -1,
17727 Pragma_Linker_Destructor => -1,
17728 Pragma_Linker_Options => -1,
17729 Pragma_Linker_Section => -1,
17730 Pragma_List => -1,
17731 Pragma_Lock_Free => -1,
17732 Pragma_Locking_Policy => -1,
17733 Pragma_Long_Float => -1,
17734 Pragma_Loop_Invariant => -1,
17735 Pragma_Loop_Optimize => -1,
17736 Pragma_Loop_Variant => -1,
17737 Pragma_Machine_Attribute => -1,
17738 Pragma_Main => -1,
17739 Pragma_Main_Storage => -1,
17740 Pragma_Memory_Size => -1,
17741 Pragma_No_Return => 0,
17742 Pragma_No_Body => 0,
17743 Pragma_No_Inline => 0,
17744 Pragma_No_Run_Time => -1,
17745 Pragma_No_Strict_Aliasing => -1,
17746 Pragma_Normalize_Scalars => -1,
17747 Pragma_Obsolescent => 0,
17748 Pragma_Optimize => -1,
17749 Pragma_Optimize_Alignment => -1,
17750 Pragma_Overflow_Mode => 0,
17751 Pragma_Overriding_Renamings => 0,
17752 Pragma_Ordered => 0,
17753 Pragma_Pack => 0,
17754 Pragma_Page => -1,
17755 Pragma_Partition_Elaboration_Policy => -1,
17756 Pragma_Passive => -1,
17757 Pragma_Preelaborable_Initialization => -1,
17758 Pragma_Polling => -1,
17759 Pragma_Persistent_BSS => 0,
17760 Pragma_Postcondition => -1,
17761 Pragma_Precondition => -1,
17762 Pragma_Predicate => -1,
17763 Pragma_Preelaborate => -1,
17764 Pragma_Preelaborate_05 => -1,
17765 Pragma_Priority => -1,
17766 Pragma_Priority_Specific_Dispatching => -1,
17767 Pragma_Profile => 0,
17768 Pragma_Profile_Warnings => 0,
17769 Pragma_Propagate_Exceptions => -1,
17770 Pragma_Psect_Object => -1,
17771 Pragma_Pure => -1,
17772 Pragma_Pure_05 => -1,
17773 Pragma_Pure_12 => -1,
17774 Pragma_Pure_Function => -1,
17775 Pragma_Queuing_Policy => -1,
17776 Pragma_Rational => -1,
17777 Pragma_Ravenscar => -1,
17778 Pragma_Relative_Deadline => -1,
17779 Pragma_Remote_Access_Type => -1,
17780 Pragma_Remote_Call_Interface => -1,
17781 Pragma_Remote_Types => -1,
17782 Pragma_Restricted_Run_Time => -1,
17783 Pragma_Restriction_Warnings => -1,
17784 Pragma_Restrictions => -1,
17785 Pragma_Reviewable => -1,
17786 Pragma_Short_Circuit_And_Or => -1,
17787 Pragma_Share_Generic => -1,
17788 Pragma_Shared => -1,
17789 Pragma_Shared_Passive => -1,
17790 Pragma_Short_Descriptors => 0,
17791 Pragma_Simple_Storage_Pool_Type => 0,
17792 Pragma_Source_File_Name => -1,
17793 Pragma_Source_File_Name_Project => -1,
17794 Pragma_Source_Reference => -1,
17795 Pragma_Storage_Size => -1,
17796 Pragma_Storage_Unit => -1,
17797 Pragma_Static_Elaboration_Desired => -1,
17798 Pragma_Stream_Convert => -1,
17799 Pragma_Style_Checks => -1,
17800 Pragma_Subtitle => -1,
17801 Pragma_Suppress => 0,
17802 Pragma_Suppress_Exception_Locations => 0,
17803 Pragma_Suppress_All => -1,
17804 Pragma_Suppress_Debug_Info => 0,
17805 Pragma_Suppress_Initialization => 0,
17806 Pragma_System_Name => -1,
17807 Pragma_Task_Dispatching_Policy => -1,
17808 Pragma_Task_Info => -1,
17809 Pragma_Task_Name => -1,
17810 Pragma_Task_Storage => 0,
17811 Pragma_Test_Case => -1,
17812 Pragma_Thread_Local_Storage => 0,
17813 Pragma_Time_Slice => -1,
17814 Pragma_Title => -1,
17815 Pragma_Unchecked_Union => 0,
17816 Pragma_Unimplemented_Unit => -1,
17817 Pragma_Universal_Aliasing => -1,
17818 Pragma_Universal_Data => -1,
17819 Pragma_Unmodified => -1,
17820 Pragma_Unreferenced => -1,
17821 Pragma_Unreferenced_Objects => -1,
17822 Pragma_Unreserve_All_Interrupts => -1,
17823 Pragma_Unsuppress => 0,
17824 Pragma_Use_VADS_Size => -1,
17825 Pragma_Validity_Checks => -1,
17826 Pragma_Volatile => 0,
17827 Pragma_Volatile_Components => 0,
17828 Pragma_Warnings => -1,
17829 Pragma_Weak_External => -1,
17830 Pragma_Wide_Character_Encoding => 0,
17831 Unknown_Pragma => 0);
17832
17833 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
17834 Id : Pragma_Id;
17835 P : Node_Id;
17836 C : Int;
17837 A : Node_Id;
17838
17839 begin
17840 P := Parent (N);
17841
17842 if Nkind (P) /= N_Pragma_Argument_Association then
17843 return False;
17844
17845 else
17846 Id := Get_Pragma_Id (Parent (P));
17847 C := Sig_Flags (Id);
17848
17849 case C is
17850 when -1 =>
17851 return False;
17852
17853 when 0 =>
17854 return True;
17855
17856 when 99 =>
17857 case Id is
17858
17859 -- For pragma Check, the first argument is not significant,
17860 -- the second and the third (if present) arguments are
17861 -- significant.
17862
17863 when Pragma_Check =>
17864 return
17865 P = First (Pragma_Argument_Associations (Parent (P)));
17866
17867 when others =>
17868 raise Program_Error;
17869 end case;
17870
17871 when others =>
17872 A := First (Pragma_Argument_Associations (Parent (P)));
17873 for J in 1 .. C - 1 loop
17874 if No (A) then
17875 return False;
17876 end if;
17877
17878 Next (A);
17879 end loop;
17880
17881 return A = P; -- is this wrong way round ???
17882 end case;
17883 end if;
17884 end Is_Non_Significant_Pragma_Reference;
17885
17886 ------------------------------
17887 -- Is_Pragma_String_Literal --
17888 ------------------------------
17889
17890 -- This function returns true if the corresponding pragma argument is a
17891 -- static string expression. These are the only cases in which string
17892 -- literals can appear as pragma arguments. We also allow a string literal
17893 -- as the first argument to pragma Assert (although it will of course
17894 -- always generate a type error).
17895
17896 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
17897 Pragn : constant Node_Id := Parent (Par);
17898 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
17899 Pname : constant Name_Id := Pragma_Name (Pragn);
17900 Argn : Natural;
17901 N : Node_Id;
17902
17903 begin
17904 Argn := 1;
17905 N := First (Assoc);
17906 loop
17907 exit when N = Par;
17908 Argn := Argn + 1;
17909 Next (N);
17910 end loop;
17911
17912 if Pname = Name_Assert then
17913 return True;
17914
17915 elsif Pname = Name_Export then
17916 return Argn > 2;
17917
17918 elsif Pname = Name_Ident then
17919 return Argn = 1;
17920
17921 elsif Pname = Name_Import then
17922 return Argn > 2;
17923
17924 elsif Pname = Name_Interface_Name then
17925 return Argn > 1;
17926
17927 elsif Pname = Name_Linker_Alias then
17928 return Argn = 2;
17929
17930 elsif Pname = Name_Linker_Section then
17931 return Argn = 2;
17932
17933 elsif Pname = Name_Machine_Attribute then
17934 return Argn = 2;
17935
17936 elsif Pname = Name_Source_File_Name then
17937 return True;
17938
17939 elsif Pname = Name_Source_Reference then
17940 return Argn = 2;
17941
17942 elsif Pname = Name_Title then
17943 return True;
17944
17945 elsif Pname = Name_Subtitle then
17946 return True;
17947
17948 else
17949 return False;
17950 end if;
17951 end Is_Pragma_String_Literal;
17952
17953 -----------------------------------------
17954 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
17955 -----------------------------------------
17956
17957 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
17958 Aspects : constant List_Id := New_List;
17959 Loc : constant Source_Ptr := Sloc (Decl);
17960 Or_Decl : constant Node_Id := Original_Node (Decl);
17961
17962 Original_Aspects : List_Id;
17963 -- To capture global references, a copy of the created aspects must be
17964 -- inserted in the original tree.
17965
17966 Prag : Node_Id;
17967 Prag_Arg_Ass : Node_Id;
17968 Prag_Id : Pragma_Id;
17969
17970 begin
17971 -- Check for any PPC pragmas that appear within Decl
17972
17973 Prag := Next (Decl);
17974 while Nkind (Prag) = N_Pragma loop
17975 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
17976
17977 case Prag_Id is
17978 when Pragma_Postcondition | Pragma_Precondition =>
17979 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
17980
17981 -- Make an aspect from any PPC pragma
17982
17983 Append_To (Aspects,
17984 Make_Aspect_Specification (Loc,
17985 Identifier =>
17986 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
17987 Expression =>
17988 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
17989
17990 -- Generate the analysis information in the pragma expression
17991 -- and then set the pragma node analyzed to avoid any further
17992 -- analysis.
17993
17994 Analyze (Expression (Prag_Arg_Ass));
17995 Set_Analyzed (Prag, True);
17996
17997 when others => null;
17998 end case;
17999
18000 Next (Prag);
18001 end loop;
18002
18003 -- Set all new aspects into the generic declaration node
18004
18005 if Is_Non_Empty_List (Aspects) then
18006
18007 -- Create the list of aspects to be inserted in the original tree
18008
18009 Original_Aspects := Copy_Separate_List (Aspects);
18010
18011 -- Check if Decl already has aspects
18012
18013 -- Attach the new lists of aspects to both the generic copy and the
18014 -- original tree.
18015
18016 if Has_Aspects (Decl) then
18017 Append_List (Aspects, Aspect_Specifications (Decl));
18018 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
18019
18020 else
18021 Set_Parent (Aspects, Decl);
18022 Set_Aspect_Specifications (Decl, Aspects);
18023 Set_Parent (Original_Aspects, Or_Decl);
18024 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
18025 end if;
18026 end if;
18027 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
18028
18029 -------------------------
18030 -- Preanalyze_CTC_Args --
18031 -------------------------
18032
18033 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
18034 begin
18035 -- Preanalyze the boolean expressions, we treat these as spec
18036 -- expressions (i.e. similar to a default expression).
18037
18038 if Present (Arg_Req) then
18039 Preanalyze_Assert_Expression
18040 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
18041
18042 -- In ASIS mode, for a pragma generated from a source aspect, also
18043 -- analyze the original aspect expression.
18044
18045 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
18046 Preanalyze_Assert_Expression
18047 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
18048 end if;
18049 end if;
18050
18051 if Present (Arg_Ens) then
18052 Preanalyze_Assert_Expression
18053 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
18054
18055 -- In ASIS mode, for a pragma generated from a source aspect, also
18056 -- analyze the original aspect expression.
18057
18058 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
18059 Preanalyze_Assert_Expression
18060 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
18061 end if;
18062 end if;
18063 end Preanalyze_CTC_Args;
18064
18065 --------------------------------------
18066 -- Process_Compilation_Unit_Pragmas --
18067 --------------------------------------
18068
18069 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
18070 begin
18071 -- A special check for pragma Suppress_All, a very strange DEC pragma,
18072 -- strange because it comes at the end of the unit. Rational has the
18073 -- same name for a pragma, but treats it as a program unit pragma, In
18074 -- GNAT we just decide to allow it anywhere at all. If it appeared then
18075 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
18076 -- node, and we insert a pragma Suppress (All_Checks) at the start of
18077 -- the context clause to ensure the correct processing.
18078
18079 if Has_Pragma_Suppress_All (N) then
18080 Prepend_To (Context_Items (N),
18081 Make_Pragma (Sloc (N),
18082 Chars => Name_Suppress,
18083 Pragma_Argument_Associations => New_List (
18084 Make_Pragma_Argument_Association (Sloc (N),
18085 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
18086 end if;
18087
18088 -- Nothing else to do at the current time!
18089
18090 end Process_Compilation_Unit_Pragmas;
18091
18092 --------
18093 -- rv --
18094 --------
18095
18096 procedure rv is
18097 begin
18098 null;
18099 end rv;
18100
18101 --------------------------------
18102 -- Set_Encoded_Interface_Name --
18103 --------------------------------
18104
18105 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
18106 Str : constant String_Id := Strval (S);
18107 Len : constant Int := String_Length (Str);
18108 CC : Char_Code;
18109 C : Character;
18110 J : Int;
18111
18112 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
18113
18114 procedure Encode;
18115 -- Stores encoded value of character code CC. The encoding we use an
18116 -- underscore followed by four lower case hex digits.
18117
18118 ------------
18119 -- Encode --
18120 ------------
18121
18122 procedure Encode is
18123 begin
18124 Store_String_Char (Get_Char_Code ('_'));
18125 Store_String_Char
18126 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
18127 Store_String_Char
18128 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
18129 Store_String_Char
18130 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
18131 Store_String_Char
18132 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
18133 end Encode;
18134
18135 -- Start of processing for Set_Encoded_Interface_Name
18136
18137 begin
18138 -- If first character is asterisk, this is a link name, and we leave it
18139 -- completely unmodified. We also ignore null strings (the latter case
18140 -- happens only in error cases) and no encoding should occur for Java or
18141 -- AAMP interface names.
18142
18143 if Len = 0
18144 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
18145 or else VM_Target /= No_VM
18146 or else AAMP_On_Target
18147 then
18148 Set_Interface_Name (E, S);
18149
18150 else
18151 J := 1;
18152 loop
18153 CC := Get_String_Char (Str, J);
18154
18155 exit when not In_Character_Range (CC);
18156
18157 C := Get_Character (CC);
18158
18159 exit when C /= '_' and then C /= '$'
18160 and then C not in '0' .. '9'
18161 and then C not in 'a' .. 'z'
18162 and then C not in 'A' .. 'Z';
18163
18164 if J = Len then
18165 Set_Interface_Name (E, S);
18166 return;
18167
18168 else
18169 J := J + 1;
18170 end if;
18171 end loop;
18172
18173 -- Here we need to encode. The encoding we use as follows:
18174 -- three underscores + four hex digits (lower case)
18175
18176 Start_String;
18177
18178 for J in 1 .. String_Length (Str) loop
18179 CC := Get_String_Char (Str, J);
18180
18181 if not In_Character_Range (CC) then
18182 Encode;
18183 else
18184 C := Get_Character (CC);
18185
18186 if C = '_' or else C = '$'
18187 or else C in '0' .. '9'
18188 or else C in 'a' .. 'z'
18189 or else C in 'A' .. 'Z'
18190 then
18191 Store_String_Char (CC);
18192 else
18193 Encode;
18194 end if;
18195 end if;
18196 end loop;
18197
18198 Set_Interface_Name (E,
18199 Make_String_Literal (Sloc (S),
18200 Strval => End_String));
18201 end if;
18202 end Set_Encoded_Interface_Name;
18203
18204 -------------------
18205 -- Set_Unit_Name --
18206 -------------------
18207
18208 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
18209 Pref : Node_Id;
18210 Scop : Entity_Id;
18211
18212 begin
18213 if Nkind (N) = N_Identifier
18214 and then Nkind (With_Item) = N_Identifier
18215 then
18216 Set_Entity (N, Entity (With_Item));
18217
18218 elsif Nkind (N) = N_Selected_Component then
18219 Change_Selected_Component_To_Expanded_Name (N);
18220 Set_Entity (N, Entity (With_Item));
18221 Set_Entity (Selector_Name (N), Entity (N));
18222
18223 Pref := Prefix (N);
18224 Scop := Scope (Entity (N));
18225 while Nkind (Pref) = N_Selected_Component loop
18226 Change_Selected_Component_To_Expanded_Name (Pref);
18227 Set_Entity (Selector_Name (Pref), Scop);
18228 Set_Entity (Pref, Scop);
18229 Pref := Prefix (Pref);
18230 Scop := Scope (Scop);
18231 end loop;
18232
18233 Set_Entity (Pref, Scop);
18234 end if;
18235 end Set_Unit_Name;
18236
18237 end Sem_Prag;