d60c41ef9564cd9f55ee02794a9b1cf6fd613eaf
[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
252 procedure Analyze_Contract_Cases (Aggr : Node_Id);
253 -- Pre-analyze the guard and consequence expressions of a Contract_Cases
254 -- pragma/aspect aggregate expression.
255
256 ----------------------------
257 -- Analyze_Contract_Cases --
258 ----------------------------
259
260 procedure Analyze_Contract_Cases (Aggr : Node_Id) is
261 Case_Guard : Node_Id;
262 Conseq : Node_Id;
263 Post_Case : Node_Id;
264
265 begin
266 Post_Case := First (Component_Associations (Aggr));
267 while Present (Post_Case) loop
268 Case_Guard := First (Choices (Post_Case));
269 Conseq := Expression (Post_Case);
270
271 -- Preanalyze the boolean expression, we treat this as a spec
272 -- expression (i.e. similar to a default expression).
273
274 if Nkind (Case_Guard) /= N_Others_Choice then
275 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
276 end if;
277
278 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
279
280 Next (Post_Case);
281 end loop;
282 end Analyze_Contract_Cases;
283
284 -- Start of processing for Analyze_CTC_In_Decl_Part
285
286 begin
287 -- Install formals and push subprogram spec onto scope stack so that we
288 -- can see the formals from the pragma.
289
290 Push_Scope (S);
291 Install_Formals (S);
292
293 -- Preanalyze the boolean expressions, we treat these as spec
294 -- expressions (i.e. similar to a default expression).
295
296 if Pragma_Name (N) = Name_Test_Case
297 or else Pragma_Name (N) = Name_Contract_Case
298 then
299 Preanalyze_CTC_Args
300 (N,
301 Get_Requires_From_CTC_Pragma (N),
302 Get_Ensures_From_CTC_Pragma (N));
303
304 elsif Pragma_Name (N) = Name_Contract_Cases then
305 Analyze_Contract_Cases
306 (Expression (First (Pragma_Argument_Associations (N))));
307
308 -- In ASIS mode, for a pragma generated from a source aspect, also
309 -- analyze the original aspect expression.
310
311 if ASIS_Mode
312 and then Present (Corresponding_Aspect (N))
313 then
314 Analyze_Contract_Cases (Expression (Corresponding_Aspect (N)));
315 end if;
316 end if;
317
318 -- Remove the subprogram from the scope stack now that the pre-analysis
319 -- of the expressions in the contract case or test case is done.
320
321 End_Scope;
322 end Analyze_CTC_In_Decl_Part;
323
324 ------------------------------
325 -- Analyze_PPC_In_Decl_Part --
326 ------------------------------
327
328 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
329 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
330
331 begin
332 -- Install formals and push subprogram spec onto scope stack so that we
333 -- can see the formals from the pragma.
334
335 Install_Formals (S);
336 Push_Scope (S);
337
338 -- Preanalyze the boolean expression, we treat this as a spec expression
339 -- (i.e. similar to a default expression).
340
341 Preanalyze_Assert_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean);
342
343 -- In ASIS mode, for a pragma generated from a source aspect, also
344 -- analyze the original aspect expression.
345
346 if ASIS_Mode
347 and then Present (Corresponding_Aspect (N))
348 then
349 Preanalyze_Assert_Expression
350 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
351 end if;
352
353 -- For a class-wide condition, a reference to a controlling formal must
354 -- be interpreted as having the class-wide type (or an access to such)
355 -- so that the inherited condition can be properly applied to any
356 -- overriding operation (see ARM12 6.6.1 (7)).
357
358 if Class_Present (N) then
359 Class_Wide_Condition : declare
360 T : constant Entity_Id := Find_Dispatching_Type (S);
361
362 ACW : Entity_Id := Empty;
363 -- Access to T'class, created if there is a controlling formal
364 -- that is an access parameter.
365
366 function Get_ACW return Entity_Id;
367 -- If the expression has a reference to an controlling access
368 -- parameter, create an access to T'class for the necessary
369 -- conversions if one does not exist.
370
371 function Process (N : Node_Id) return Traverse_Result;
372 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
373 -- aspect for a primitive subprogram of a tagged type T, a name
374 -- that denotes a formal parameter of type T is interpreted as
375 -- having type T'Class. Similarly, a name that denotes a formal
376 -- accessparameter of type access-to-T is interpreted as having
377 -- type access-to-T'Class. This ensures the expression is well-
378 -- defined for a primitive subprogram of a type descended from T.
379
380 -------------
381 -- Get_ACW --
382 -------------
383
384 function Get_ACW return Entity_Id is
385 Loc : constant Source_Ptr := Sloc (N);
386 Decl : Node_Id;
387
388 begin
389 if No (ACW) then
390 Decl := Make_Full_Type_Declaration (Loc,
391 Defining_Identifier => Make_Temporary (Loc, 'T'),
392 Type_Definition =>
393 Make_Access_To_Object_Definition (Loc,
394 Subtype_Indication =>
395 New_Occurrence_Of (Class_Wide_Type (T), Loc),
396 All_Present => True));
397
398 Insert_Before (Unit_Declaration_Node (S), Decl);
399 Analyze (Decl);
400 ACW := Defining_Identifier (Decl);
401 Freeze_Before (Unit_Declaration_Node (S), ACW);
402 end if;
403
404 return ACW;
405 end Get_ACW;
406
407 -------------
408 -- Process --
409 -------------
410
411 function Process (N : Node_Id) return Traverse_Result is
412 Loc : constant Source_Ptr := Sloc (N);
413 Typ : Entity_Id;
414
415 begin
416 if Is_Entity_Name (N)
417 and then Is_Formal (Entity (N))
418 and then Nkind (Parent (N)) /= N_Type_Conversion
419 then
420 if Etype (Entity (N)) = T then
421 Typ := Class_Wide_Type (T);
422
423 elsif Is_Access_Type (Etype (Entity (N)))
424 and then Designated_Type (Etype (Entity (N))) = T
425 then
426 Typ := Get_ACW;
427 else
428 Typ := Empty;
429 end if;
430
431 if Present (Typ) then
432 Rewrite (N,
433 Make_Type_Conversion (Loc,
434 Subtype_Mark =>
435 New_Occurrence_Of (Typ, Loc),
436 Expression => New_Occurrence_Of (Entity (N), Loc)));
437 Set_Etype (N, Typ);
438 end if;
439 end if;
440
441 return OK;
442 end Process;
443
444 procedure Replace_Type is new Traverse_Proc (Process);
445
446 -- Start of processing for Class_Wide_Condition
447
448 begin
449 if not Present (T) then
450 Error_Msg_Name_1 :=
451 Chars (Identifier (Corresponding_Aspect (N)));
452
453 Error_Msg_Name_2 := Name_Class;
454
455 Error_Msg_N
456 ("aspect `%''%` can only be specified for a primitive "
457 & "operation of a tagged type", Corresponding_Aspect (N));
458 end if;
459
460 Replace_Type (Get_Pragma_Arg (Arg1));
461 end Class_Wide_Condition;
462 end if;
463
464 -- Remove the subprogram from the scope stack now that the pre-analysis
465 -- of the precondition/postcondition is done.
466
467 End_Scope;
468 end Analyze_PPC_In_Decl_Part;
469
470 --------------------
471 -- Analyze_Pragma --
472 --------------------
473
474 procedure Analyze_Pragma (N : Node_Id) is
475 Loc : constant Source_Ptr := Sloc (N);
476 Prag_Id : Pragma_Id;
477
478 Pname : Name_Id;
479 -- Name of the source pragma, or name of the corresponding aspect for
480 -- pragmas which originate in a source aspect. In the latter case, the
481 -- name may be different from the pragma name.
482
483 Pragma_Exit : exception;
484 -- This exception is used to exit pragma processing completely. It is
485 -- used when an error is detected, and no further processing is
486 -- required. It is also used if an earlier error has left the tree in
487 -- a state where the pragma should not be processed.
488
489 Arg_Count : Nat;
490 -- Number of pragma argument associations
491
492 Arg1 : Node_Id;
493 Arg2 : Node_Id;
494 Arg3 : Node_Id;
495 Arg4 : Node_Id;
496 -- First four pragma arguments (pragma argument association nodes, or
497 -- Empty if the corresponding argument does not exist).
498
499 type Name_List is array (Natural range <>) of Name_Id;
500 type Args_List is array (Natural range <>) of Node_Id;
501 -- Types used for arguments to Check_Arg_Order and Gather_Associations
502
503 procedure Ada_2005_Pragma;
504 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
505 -- Ada 95 mode, these are implementation defined pragmas, so should be
506 -- caught by the No_Implementation_Pragmas restriction.
507
508 procedure Ada_2012_Pragma;
509 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
510 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
511 -- should be caught by the No_Implementation_Pragmas restriction.
512
513 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id);
514 -- Subsidiary routine to the analysis of pragmas Depends and Global.
515 -- Append an input or output item to a list. If the list is empty, a
516 -- new one is created.
517
518 procedure Check_Ada_83_Warning;
519 -- Issues a warning message for the current pragma if operating in Ada
520 -- 83 mode (used for language pragmas that are not a standard part of
521 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
522 -- of 95 pragma.
523
524 procedure Check_Arg_Count (Required : Nat);
525 -- Check argument count for pragma is equal to given parameter. If not,
526 -- then issue an error message and raise Pragma_Exit.
527
528 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
529 -- Arg which can either be a pragma argument association, in which case
530 -- the check is applied to the expression of the association or an
531 -- expression directly.
532
533 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
534 -- Check that an argument has the right form for an EXTERNAL_NAME
535 -- parameter of an extended import/export pragma. The rule is that the
536 -- name must be an identifier or string literal (in Ada 83 mode) or a
537 -- static string expression (in Ada 95 mode).
538
539 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
540 -- Check the specified argument Arg to make sure that it is an
541 -- identifier. If not give error and raise Pragma_Exit.
542
543 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
544 -- Check the specified argument Arg to make sure that it is an integer
545 -- literal. If not give error and raise Pragma_Exit.
546
547 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
548 -- Check the specified argument Arg to make sure that it has the proper
549 -- syntactic form for a local name and meets the semantic requirements
550 -- for a local name. The local name is analyzed as part of the
551 -- processing for this call. In addition, the local name is required
552 -- to represent an entity at the library level.
553
554 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
555 -- Check the specified argument Arg to make sure that it has the proper
556 -- syntactic form for a local name and meets the semantic requirements
557 -- for a local name. The local name is analyzed as part of the
558 -- processing for this call.
559
560 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
561 -- Check the specified argument Arg to make sure that it is a valid
562 -- locking policy name. If not give error and raise Pragma_Exit.
563
564 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
565 -- Check the specified argument Arg to make sure that it is a valid
566 -- elaboration policy name. If not give error and raise Pragma_Exit.
567
568 procedure Check_Arg_Is_One_Of
569 (Arg : Node_Id;
570 N1, N2 : Name_Id);
571 procedure Check_Arg_Is_One_Of
572 (Arg : Node_Id;
573 N1, N2, N3 : Name_Id);
574 procedure Check_Arg_Is_One_Of
575 (Arg : Node_Id;
576 N1, N2, N3, N4 : Name_Id);
577 procedure Check_Arg_Is_One_Of
578 (Arg : Node_Id;
579 N1, N2, N3, N4, N5 : Name_Id);
580 -- Check the specified argument Arg to make sure that it is an
581 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
582 -- present). If not then give error and raise Pragma_Exit.
583
584 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
585 -- Check the specified argument Arg to make sure that it is a valid
586 -- queuing policy name. If not give error and raise Pragma_Exit.
587
588 procedure Check_Arg_Is_Static_Expression
589 (Arg : Node_Id;
590 Typ : Entity_Id := Empty);
591 -- Check the specified argument Arg to make sure that it is a static
592 -- expression of the given type (i.e. it will be analyzed and resolved
593 -- using this type, which can be any valid argument to Resolve, e.g.
594 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
595 -- Typ is left Empty, then any static expression is allowed.
596
597 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
598 -- Check the specified argument Arg to make sure that it is a valid task
599 -- dispatching policy name. If not give error and raise Pragma_Exit.
600
601 procedure Check_Arg_Order (Names : Name_List);
602 -- Checks for an instance of two arguments with identifiers for the
603 -- current pragma which are not in the sequence indicated by Names,
604 -- and if so, generates a fatal message about bad order of arguments.
605
606 procedure Check_At_Least_N_Arguments (N : Nat);
607 -- Check there are at least N arguments present
608
609 procedure Check_At_Most_N_Arguments (N : Nat);
610 -- Check there are no more than N arguments present
611
612 procedure Check_Component
613 (Comp : Node_Id;
614 UU_Typ : Entity_Id;
615 In_Variant_Part : Boolean := False);
616 -- Examine an Unchecked_Union component for correct use of per-object
617 -- constrained subtypes, and for restrictions on finalizable components.
618 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
619 -- should be set when Comp comes from a record variant.
620
621 procedure Check_Contract_Or_Test_Case;
622 -- Called to process a contract-case or test-case pragma. It
623 -- starts with checking pragma arguments, and the rest of the
624 -- treatment is similar to the one for pre- and postcondition in
625 -- Check_Precondition_Postcondition, except the placement rules for the
626 -- contract-case and test-case pragmas are stricter. These pragmas may
627 -- only occur after a subprogram spec declared directly in a package
628 -- spec unit. In this case, the pragma is chained to the subprogram in
629 -- question (using Spec_CTC_List and Next_Pragma) and analysis of the
630 -- pragma is delayed till the end of the spec. In all other cases, an
631 -- error message for bad placement is given.
632
633 procedure Check_Duplicate_Pragma (E : Entity_Id);
634 -- Check if a rep item of the same name as the current pragma is already
635 -- chained as a rep pragma to the given entity. If so give a message
636 -- about the duplicate, and then raise Pragma_Exit so does not return.
637
638 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
639 -- Nam is an N_String_Literal node containing the external name set by
640 -- an Import or Export pragma (or extended Import or Export pragma).
641 -- This procedure checks for possible duplications if this is the export
642 -- case, and if found, issues an appropriate error message.
643
644 procedure Check_Expr_Is_Static_Expression
645 (Expr : Node_Id;
646 Typ : Entity_Id := Empty);
647 -- Check the specified expression Expr to make sure that it is a static
648 -- expression of the given type (i.e. it will be analyzed and resolved
649 -- using this type, which can be any valid argument to Resolve, e.g.
650 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
651 -- Typ is left Empty, then any static expression is allowed.
652
653 procedure Check_First_Subtype (Arg : Node_Id);
654 -- Checks that Arg, whose expression is an entity name, references a
655 -- first subtype.
656
657 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
658 -- Checks that the given argument has an identifier, and if so, requires
659 -- it to match the given identifier name. If there is no identifier, or
660 -- a non-matching identifier, then an error message is given and
661 -- Pragma_Exit is raised.
662
663 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
664 -- Checks that the given argument has an identifier, and if so, requires
665 -- it to match one of the given identifier names. If there is no
666 -- identifier, or a non-matching identifier, then an error message is
667 -- given and Pragma_Exit is raised.
668
669 procedure Check_In_Main_Program;
670 -- Common checks for pragmas that appear within a main program
671 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
672
673 procedure Check_Interrupt_Or_Attach_Handler;
674 -- Common processing for first argument of pragma Interrupt_Handler or
675 -- pragma Attach_Handler.
676
677 procedure Check_Loop_Pragma_Placement;
678 -- Verify whether pragma Loop_Invariant or Loop_Optimize or Loop_Variant
679 -- appear immediately within a construct restricted to loops.
680
681 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
682 -- Check that pragma appears in a declarative part, or in a package
683 -- specification, i.e. that it does not occur in a statement sequence
684 -- in a body.
685
686 procedure Check_No_Identifier (Arg : Node_Id);
687 -- Checks that the given argument does not have an identifier. If
688 -- an identifier is present, then an error message is issued, and
689 -- Pragma_Exit is raised.
690
691 procedure Check_No_Identifiers;
692 -- Checks that none of the arguments to the pragma has an identifier.
693 -- If any argument has an identifier, then an error message is issued,
694 -- and Pragma_Exit is raised.
695
696 procedure Check_No_Link_Name;
697 -- Checks that no link name is specified
698
699 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
700 -- Checks if the given argument has an identifier, and if so, requires
701 -- it to match the given identifier name. If there is a non-matching
702 -- identifier, then an error message is given and Pragma_Exit is raised.
703
704 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
705 -- Checks if the given argument has an identifier, and if so, requires
706 -- it to match the given identifier name. If there is a non-matching
707 -- identifier, then an error message is given and Pragma_Exit is raised.
708 -- In this version of the procedure, the identifier name is given as
709 -- a string with lower case letters.
710
711 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
712 -- Called to process a precondition or postcondition pragma. There are
713 -- three cases:
714 --
715 -- The pragma appears after a subprogram spec
716 --
717 -- If the corresponding check is not enabled, the pragma is analyzed
718 -- but otherwise ignored and control returns with In_Body set False.
719 --
720 -- If the check is enabled, then the first step is to analyze the
721 -- pragma, but this is skipped if the subprogram spec appears within
722 -- a package specification (because this is the case where we delay
723 -- analysis till the end of the spec). Then (whether or not it was
724 -- analyzed), the pragma is chained to the subprogram in question
725 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
726 -- caller with In_Body set False.
727 --
728 -- The pragma appears at the start of subprogram body declarations
729 --
730 -- In this case an immediate return to the caller is made with
731 -- In_Body set True, and the pragma is NOT analyzed.
732 --
733 -- In all other cases, an error message for bad placement is given
734
735 procedure Check_Static_Constraint (Constr : Node_Id);
736 -- Constr is a constraint from an N_Subtype_Indication node from a
737 -- component constraint in an Unchecked_Union type. This routine checks
738 -- that the constraint is static as required by the restrictions for
739 -- Unchecked_Union.
740
741 procedure Check_Valid_Configuration_Pragma;
742 -- Legality checks for placement of a configuration pragma
743
744 procedure Check_Valid_Library_Unit_Pragma;
745 -- Legality checks for library unit pragmas. A special case arises for
746 -- pragmas in generic instances that come from copies of the original
747 -- library unit pragmas in the generic templates. In the case of other
748 -- than library level instantiations these can appear in contexts which
749 -- would normally be invalid (they only apply to the original template
750 -- and to library level instantiations), and they are simply ignored,
751 -- which is implemented by rewriting them as null statements.
752
753 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
754 -- Check an Unchecked_Union variant for lack of nested variants and
755 -- presence of at least one component. UU_Typ is the related Unchecked_
756 -- Union type.
757
758 procedure Error_Pragma (Msg : String);
759 pragma No_Return (Error_Pragma);
760 -- Outputs error message for current pragma. The message contains a %
761 -- that will be replaced with the pragma name, and the flag is placed
762 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
763 -- calls Fix_Error (see spec of that function for details).
764
765 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
766 pragma No_Return (Error_Pragma_Arg);
767 -- Outputs error message for current pragma. The message may contain
768 -- a % that will be replaced with the pragma name. The parameter Arg
769 -- may either be a pragma argument association, in which case the flag
770 -- is placed on the expression of this association, or an expression,
771 -- in which case the flag is placed directly on the expression. The
772 -- message is placed using Error_Msg_N, so the message may also contain
773 -- an & insertion character which will reference the given Arg value.
774 -- After placing the message, Pragma_Exit is raised. Note: this routine
775 -- calls Fix_Error (see spec of that function for details).
776
777 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
778 pragma No_Return (Error_Pragma_Arg);
779 -- Similar to above form of Error_Pragma_Arg except that two messages
780 -- are provided, the second is a continuation comment starting with \.
781
782 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
783 pragma No_Return (Error_Pragma_Arg_Ident);
784 -- Outputs error message for current pragma. The message may contain
785 -- a % that will be replaced with the pragma name. The parameter Arg
786 -- must be a pragma argument association with a non-empty identifier
787 -- (i.e. its Chars field must be set), and the error message is placed
788 -- on the identifier. The message is placed using Error_Msg_N so
789 -- the message may also contain an & insertion character which will
790 -- reference the identifier. After placing the message, Pragma_Exit
791 -- is raised. Note: this routine calls Fix_Error (see spec of that
792 -- function for details).
793
794 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
795 pragma No_Return (Error_Pragma_Ref);
796 -- Outputs error message for current pragma. The message may contain
797 -- a % that will be replaced with the pragma name. The parameter Ref
798 -- must be an entity whose name can be referenced by & and sloc by #.
799 -- After placing the message, Pragma_Exit is raised. Note: this routine
800 -- calls Fix_Error (see spec of that function for details).
801
802 function Find_Lib_Unit_Name return Entity_Id;
803 -- Used for a library unit pragma to find the entity to which the
804 -- library unit pragma applies, returns the entity found.
805
806 procedure Find_Program_Unit_Name (Id : Node_Id);
807 -- If the pragma is a compilation unit pragma, the id must denote the
808 -- compilation unit in the same compilation, and the pragma must appear
809 -- in the list of preceding or trailing pragmas. If it is a program
810 -- unit pragma that is not a compilation unit pragma, then the
811 -- identifier must be visible.
812
813 function Find_Unique_Parameterless_Procedure
814 (Name : Entity_Id;
815 Arg : Node_Id) return Entity_Id;
816 -- Used for a procedure pragma to find the unique parameterless
817 -- procedure identified by Name, returns it if it exists, otherwise
818 -- errors out and uses Arg as the pragma argument for the message.
819
820 procedure Fix_Error (Msg : in out String);
821 -- This is called prior to issuing an error message. Msg is a string
822 -- that typically contains the substring "pragma". If the current pragma
823 -- comes from an aspect, each such "pragma" substring is replaced with
824 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
825 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
826
827 procedure Gather_Associations
828 (Names : Name_List;
829 Args : out Args_List);
830 -- This procedure is used to gather the arguments for a pragma that
831 -- permits arbitrary ordering of parameters using the normal rules
832 -- for named and positional parameters. The Names argument is a list
833 -- of Name_Id values that corresponds to the allowed pragma argument
834 -- association identifiers in order. The result returned in Args is
835 -- a list of corresponding expressions that are the pragma arguments.
836 -- Note that this is a list of expressions, not of pragma argument
837 -- associations (Gather_Associations has completely checked all the
838 -- optional identifiers when it returns). An entry in Args is Empty
839 -- on return if the corresponding argument is not present.
840
841 procedure GNAT_Pragma;
842 -- Called for all GNAT defined pragmas to check the relevant restriction
843 -- (No_Implementation_Pragmas).
844
845 procedure S14_Pragma;
846 -- Called for all pragmas defined for formal verification to check that
847 -- the S14_Extensions flag is set.
848 -- This name needs fixing ??? There is no such thing as an
849 -- "S14_Extensions" flag ???
850
851 function Is_Before_First_Decl
852 (Pragma_Node : Node_Id;
853 Decls : List_Id) return Boolean;
854 -- Return True if Pragma_Node is before the first declarative item in
855 -- Decls where Decls is the list of declarative items.
856
857 function Is_Configuration_Pragma return Boolean;
858 -- Determines if the placement of the current pragma is appropriate
859 -- for a configuration pragma.
860
861 function Is_In_Context_Clause return Boolean;
862 -- Returns True if pragma appears within the context clause of a unit,
863 -- and False for any other placement (does not generate any messages).
864
865 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
866 -- Analyzes the argument, and determines if it is a static string
867 -- expression, returns True if so, False if non-static or not String.
868
869 procedure Pragma_Misplaced;
870 pragma No_Return (Pragma_Misplaced);
871 -- Issue fatal error message for misplaced pragma
872
873 procedure Process_Atomic_Shared_Volatile;
874 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
875 -- Shared is an obsolete Ada 83 pragma, treated as being identical
876 -- in effect to pragma Atomic.
877
878 procedure Process_Compile_Time_Warning_Or_Error;
879 -- Common processing for Compile_Time_Error and Compile_Time_Warning
880
881 procedure Process_Convention
882 (C : out Convention_Id;
883 Ent : out Entity_Id);
884 -- Common processing for Convention, Interface, Import and Export.
885 -- Checks first two arguments of pragma, and sets the appropriate
886 -- convention value in the specified entity or entities. On return
887 -- C is the convention, Ent is the referenced entity.
888
889 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
890 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
891 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
892
893 procedure Process_Extended_Import_Export_Exception_Pragma
894 (Arg_Internal : Node_Id;
895 Arg_External : Node_Id;
896 Arg_Form : Node_Id;
897 Arg_Code : Node_Id);
898 -- Common processing for the pragmas Import/Export_Exception. The three
899 -- arguments correspond to the three named parameters of the pragma. An
900 -- argument is empty if the corresponding parameter is not present in
901 -- the pragma.
902
903 procedure Process_Extended_Import_Export_Object_Pragma
904 (Arg_Internal : Node_Id;
905 Arg_External : Node_Id;
906 Arg_Size : Node_Id);
907 -- Common processing for the pragmas Import/Export_Object. The three
908 -- arguments correspond to the three named parameters of the pragmas. An
909 -- argument is empty if the corresponding parameter is not present in
910 -- the pragma.
911
912 procedure Process_Extended_Import_Export_Internal_Arg
913 (Arg_Internal : Node_Id := Empty);
914 -- Common processing for all extended Import and Export pragmas. The
915 -- argument is the pragma parameter for the Internal argument. If
916 -- Arg_Internal is empty or inappropriate, an error message is posted.
917 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
918 -- set to identify the referenced entity.
919
920 procedure Process_Extended_Import_Export_Subprogram_Pragma
921 (Arg_Internal : Node_Id;
922 Arg_External : Node_Id;
923 Arg_Parameter_Types : Node_Id;
924 Arg_Result_Type : Node_Id := Empty;
925 Arg_Mechanism : Node_Id;
926 Arg_Result_Mechanism : Node_Id := Empty;
927 Arg_First_Optional_Parameter : Node_Id := Empty);
928 -- Common processing for all extended Import and Export pragmas applying
929 -- to subprograms. The caller omits any arguments that do not apply to
930 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
931 -- only in the Import_Function and Export_Function cases). The argument
932 -- names correspond to the allowed pragma association identifiers.
933
934 procedure Process_Generic_List;
935 -- Common processing for Share_Generic and Inline_Generic
936
937 procedure Process_Import_Or_Interface;
938 -- Common processing for Import of Interface
939
940 procedure Process_Import_Predefined_Type;
941 -- Processing for completing a type with pragma Import. This is used
942 -- to declare types that match predefined C types, especially for cases
943 -- without corresponding Ada predefined type.
944
945 type Inline_Status is (Suppressed, Disabled, Enabled);
946 -- Inline status of a subprogram, indicated as follows:
947 -- Suppressed: inlining is suppressed for the subprogram
948 -- Disabled: no inlining is requested for the subprogram
949 -- Enabled: inlining is requested/required for the subprogram
950
951 procedure Process_Inline (Status : Inline_Status);
952 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
953 -- indicates the inline status specified by the pragma.
954
955 procedure Process_Interface_Name
956 (Subprogram_Def : Entity_Id;
957 Ext_Arg : Node_Id;
958 Link_Arg : Node_Id);
959 -- Given the last two arguments of pragma Import, pragma Export, or
960 -- pragma Interface_Name, performs validity checks and sets the
961 -- Interface_Name field of the given subprogram entity to the
962 -- appropriate external or link name, depending on the arguments given.
963 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
964 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
965 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
966 -- nor Link_Arg is present, the interface name is set to the default
967 -- from the subprogram name.
968
969 procedure Process_Interrupt_Or_Attach_Handler;
970 -- Common processing for Interrupt and Attach_Handler pragmas
971
972 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
973 -- Common processing for Restrictions and Restriction_Warnings pragmas.
974 -- Warn is True for Restriction_Warnings, or for Restrictions if the
975 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
976 -- is not set in the Restrictions case.
977
978 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
979 -- Common processing for Suppress and Unsuppress. The boolean parameter
980 -- Suppress_Case is True for the Suppress case, and False for the
981 -- Unsuppress case.
982
983 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
984 -- This procedure sets the Is_Exported flag for the given entity,
985 -- checking that the entity was not previously imported. Arg is
986 -- the argument that specified the entity. A check is also made
987 -- for exporting inappropriate entities.
988
989 procedure Set_Extended_Import_Export_External_Name
990 (Internal_Ent : Entity_Id;
991 Arg_External : Node_Id);
992 -- Common processing for all extended import export pragmas. The first
993 -- argument, Internal_Ent, is the internal entity, which has already
994 -- been checked for validity by the caller. Arg_External is from the
995 -- Import or Export pragma, and may be null if no External parameter
996 -- was present. If Arg_External is present and is a non-null string
997 -- (a null string is treated as the default), then the Interface_Name
998 -- field of Internal_Ent is set appropriately.
999
1000 procedure Set_Imported (E : Entity_Id);
1001 -- This procedure sets the Is_Imported flag for the given entity,
1002 -- checking that it is not previously exported or imported.
1003
1004 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
1005 -- Mech is a parameter passing mechanism (see Import_Function syntax
1006 -- for MECHANISM_NAME). This routine checks that the mechanism argument
1007 -- has the right form, and if not issues an error message. If the
1008 -- argument has the right form then the Mechanism field of Ent is
1009 -- set appropriately.
1010
1011 procedure Set_Rational_Profile;
1012 -- Activate the set of configuration pragmas and permissions that make
1013 -- up the Rational profile.
1014
1015 procedure Set_Ravenscar_Profile (N : Node_Id);
1016 -- Activate the set of configuration pragmas and restrictions that make
1017 -- up the Ravenscar Profile. N is the corresponding pragma node, which
1018 -- is used for error messages on any constructs that violate the
1019 -- profile.
1020
1021 ---------------------
1022 -- Ada_2005_Pragma --
1023 ---------------------
1024
1025 procedure Ada_2005_Pragma is
1026 begin
1027 if Ada_Version <= Ada_95 then
1028 Check_Restriction (No_Implementation_Pragmas, N);
1029 end if;
1030 end Ada_2005_Pragma;
1031
1032 ---------------------
1033 -- Ada_2012_Pragma --
1034 ---------------------
1035
1036 procedure Ada_2012_Pragma is
1037 begin
1038 if Ada_Version <= Ada_2005 then
1039 Check_Restriction (No_Implementation_Pragmas, N);
1040 end if;
1041 end Ada_2012_Pragma;
1042
1043 --------------
1044 -- Add_Item --
1045 --------------
1046
1047 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id) is
1048 begin
1049 if No (To_List) then
1050 To_List := New_Elmt_List;
1051 end if;
1052
1053 Append_Unique_Elmt (Item, To_List);
1054 end Add_Item;
1055
1056 --------------------------
1057 -- Check_Ada_83_Warning --
1058 --------------------------
1059
1060 procedure Check_Ada_83_Warning is
1061 begin
1062 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
1063 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
1064 end if;
1065 end Check_Ada_83_Warning;
1066
1067 ---------------------
1068 -- Check_Arg_Count --
1069 ---------------------
1070
1071 procedure Check_Arg_Count (Required : Nat) is
1072 begin
1073 if Arg_Count /= Required then
1074 Error_Pragma ("wrong number of arguments for pragma%");
1075 end if;
1076 end Check_Arg_Count;
1077
1078 --------------------------------
1079 -- Check_Arg_Is_External_Name --
1080 --------------------------------
1081
1082 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
1083 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1084
1085 begin
1086 if Nkind (Argx) = N_Identifier then
1087 return;
1088
1089 else
1090 Analyze_And_Resolve (Argx, Standard_String);
1091
1092 if Is_OK_Static_Expression (Argx) then
1093 return;
1094
1095 elsif Etype (Argx) = Any_Type then
1096 raise Pragma_Exit;
1097
1098 -- An interesting special case, if we have a string literal and
1099 -- we are in Ada 83 mode, then we allow it even though it will
1100 -- not be flagged as static. This allows expected Ada 83 mode
1101 -- use of external names which are string literals, even though
1102 -- technically these are not static in Ada 83.
1103
1104 elsif Ada_Version = Ada_83
1105 and then Nkind (Argx) = N_String_Literal
1106 then
1107 return;
1108
1109 -- Static expression that raises Constraint_Error. This has
1110 -- already been flagged, so just exit from pragma processing.
1111
1112 elsif Is_Static_Expression (Argx) then
1113 raise Pragma_Exit;
1114
1115 -- Here we have a real error (non-static expression)
1116
1117 else
1118 Error_Msg_Name_1 := Pname;
1119
1120 declare
1121 Msg : String :=
1122 "argument for pragma% must be a identifier or "
1123 & "static string expression!";
1124 begin
1125 Fix_Error (Msg);
1126 Flag_Non_Static_Expr (Msg, Argx);
1127 raise Pragma_Exit;
1128 end;
1129 end if;
1130 end if;
1131 end Check_Arg_Is_External_Name;
1132
1133 -----------------------------
1134 -- Check_Arg_Is_Identifier --
1135 -----------------------------
1136
1137 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
1138 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1139 begin
1140 if Nkind (Argx) /= N_Identifier then
1141 Error_Pragma_Arg
1142 ("argument for pragma% must be identifier", Argx);
1143 end if;
1144 end Check_Arg_Is_Identifier;
1145
1146 ----------------------------------
1147 -- Check_Arg_Is_Integer_Literal --
1148 ----------------------------------
1149
1150 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1151 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1152 begin
1153 if Nkind (Argx) /= N_Integer_Literal then
1154 Error_Pragma_Arg
1155 ("argument for pragma% must be integer literal", Argx);
1156 end if;
1157 end Check_Arg_Is_Integer_Literal;
1158
1159 -------------------------------------------
1160 -- Check_Arg_Is_Library_Level_Local_Name --
1161 -------------------------------------------
1162
1163 -- LOCAL_NAME ::=
1164 -- DIRECT_NAME
1165 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1166 -- | library_unit_NAME
1167
1168 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1169 begin
1170 Check_Arg_Is_Local_Name (Arg);
1171
1172 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1173 and then Comes_From_Source (N)
1174 then
1175 Error_Pragma_Arg
1176 ("argument for pragma% must be library level entity", Arg);
1177 end if;
1178 end Check_Arg_Is_Library_Level_Local_Name;
1179
1180 -----------------------------
1181 -- Check_Arg_Is_Local_Name --
1182 -----------------------------
1183
1184 -- LOCAL_NAME ::=
1185 -- DIRECT_NAME
1186 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1187 -- | library_unit_NAME
1188
1189 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1190 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1191
1192 begin
1193 Analyze (Argx);
1194
1195 if Nkind (Argx) not in N_Direct_Name
1196 and then (Nkind (Argx) /= N_Attribute_Reference
1197 or else Present (Expressions (Argx))
1198 or else Nkind (Prefix (Argx)) /= N_Identifier)
1199 and then (not Is_Entity_Name (Argx)
1200 or else not Is_Compilation_Unit (Entity (Argx)))
1201 then
1202 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1203 end if;
1204
1205 -- No further check required if not an entity name
1206
1207 if not Is_Entity_Name (Argx) then
1208 null;
1209
1210 else
1211 declare
1212 OK : Boolean;
1213 Ent : constant Entity_Id := Entity (Argx);
1214 Scop : constant Entity_Id := Scope (Ent);
1215 begin
1216 -- Case of a pragma applied to a compilation unit: pragma must
1217 -- occur immediately after the program unit in the compilation.
1218
1219 if Is_Compilation_Unit (Ent) then
1220 declare
1221 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1222
1223 begin
1224 -- Case of pragma placed immediately after spec
1225
1226 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1227 OK := True;
1228
1229 -- Case of pragma placed immediately after body
1230
1231 elsif Nkind (Decl) = N_Subprogram_Declaration
1232 and then Present (Corresponding_Body (Decl))
1233 then
1234 OK := Parent (N) =
1235 Aux_Decls_Node
1236 (Parent (Unit_Declaration_Node
1237 (Corresponding_Body (Decl))));
1238
1239 -- All other cases are illegal
1240
1241 else
1242 OK := False;
1243 end if;
1244 end;
1245
1246 -- Special restricted placement rule from 10.2.1(11.8/2)
1247
1248 elsif Is_Generic_Formal (Ent)
1249 and then Prag_Id = Pragma_Preelaborable_Initialization
1250 then
1251 OK := List_Containing (N) =
1252 Generic_Formal_Declarations
1253 (Unit_Declaration_Node (Scop));
1254
1255 -- Default case, just check that the pragma occurs in the scope
1256 -- of the entity denoted by the name.
1257
1258 else
1259 OK := Current_Scope = Scop;
1260 end if;
1261
1262 if not OK then
1263 Error_Pragma_Arg
1264 ("pragma% argument must be in same declarative part", Arg);
1265 end if;
1266 end;
1267 end if;
1268 end Check_Arg_Is_Local_Name;
1269
1270 ---------------------------------
1271 -- Check_Arg_Is_Locking_Policy --
1272 ---------------------------------
1273
1274 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1275 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1276
1277 begin
1278 Check_Arg_Is_Identifier (Argx);
1279
1280 if not Is_Locking_Policy_Name (Chars (Argx)) then
1281 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1282 end if;
1283 end Check_Arg_Is_Locking_Policy;
1284
1285 -----------------------------------------------
1286 -- Check_Arg_Is_Partition_Elaboration_Policy --
1287 -----------------------------------------------
1288
1289 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
1290 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1291
1292 begin
1293 Check_Arg_Is_Identifier (Argx);
1294
1295 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
1296 Error_Pragma_Arg
1297 ("& is not a valid partition elaboration policy name", Argx);
1298 end if;
1299 end Check_Arg_Is_Partition_Elaboration_Policy;
1300
1301 -------------------------
1302 -- Check_Arg_Is_One_Of --
1303 -------------------------
1304
1305 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1306 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1307
1308 begin
1309 Check_Arg_Is_Identifier (Argx);
1310
1311 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1312 Error_Msg_Name_2 := N1;
1313 Error_Msg_Name_3 := N2;
1314 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1315 end if;
1316 end Check_Arg_Is_One_Of;
1317
1318 procedure Check_Arg_Is_One_Of
1319 (Arg : Node_Id;
1320 N1, N2, N3 : Name_Id)
1321 is
1322 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1323
1324 begin
1325 Check_Arg_Is_Identifier (Argx);
1326
1327 if Chars (Argx) /= N1
1328 and then Chars (Argx) /= N2
1329 and then Chars (Argx) /= N3
1330 then
1331 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1332 end if;
1333 end Check_Arg_Is_One_Of;
1334
1335 procedure Check_Arg_Is_One_Of
1336 (Arg : Node_Id;
1337 N1, N2, N3, N4 : Name_Id)
1338 is
1339 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1340
1341 begin
1342 Check_Arg_Is_Identifier (Argx);
1343
1344 if Chars (Argx) /= N1
1345 and then Chars (Argx) /= N2
1346 and then Chars (Argx) /= N3
1347 and then Chars (Argx) /= N4
1348 then
1349 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1350 end if;
1351 end Check_Arg_Is_One_Of;
1352
1353 procedure Check_Arg_Is_One_Of
1354 (Arg : Node_Id;
1355 N1, N2, N3, N4, N5 : Name_Id)
1356 is
1357 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1358
1359 begin
1360 Check_Arg_Is_Identifier (Argx);
1361
1362 if Chars (Argx) /= N1
1363 and then Chars (Argx) /= N2
1364 and then Chars (Argx) /= N3
1365 and then Chars (Argx) /= N4
1366 and then Chars (Argx) /= N5
1367 then
1368 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1369 end if;
1370 end Check_Arg_Is_One_Of;
1371
1372 ---------------------------------
1373 -- Check_Arg_Is_Queuing_Policy --
1374 ---------------------------------
1375
1376 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1377 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1378
1379 begin
1380 Check_Arg_Is_Identifier (Argx);
1381
1382 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1383 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1384 end if;
1385 end Check_Arg_Is_Queuing_Policy;
1386
1387 ------------------------------------
1388 -- Check_Arg_Is_Static_Expression --
1389 ------------------------------------
1390
1391 procedure Check_Arg_Is_Static_Expression
1392 (Arg : Node_Id;
1393 Typ : Entity_Id := Empty)
1394 is
1395 begin
1396 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1397 end Check_Arg_Is_Static_Expression;
1398
1399 ------------------------------------------
1400 -- Check_Arg_Is_Task_Dispatching_Policy --
1401 ------------------------------------------
1402
1403 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1404 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1405
1406 begin
1407 Check_Arg_Is_Identifier (Argx);
1408
1409 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1410 Error_Pragma_Arg
1411 ("& is not a valid task dispatching policy name", Argx);
1412 end if;
1413 end Check_Arg_Is_Task_Dispatching_Policy;
1414
1415 ---------------------
1416 -- Check_Arg_Order --
1417 ---------------------
1418
1419 procedure Check_Arg_Order (Names : Name_List) is
1420 Arg : Node_Id;
1421
1422 Highest_So_Far : Natural := 0;
1423 -- Highest index in Names seen do far
1424
1425 begin
1426 Arg := Arg1;
1427 for J in 1 .. Arg_Count loop
1428 if Chars (Arg) /= No_Name then
1429 for K in Names'Range loop
1430 if Chars (Arg) = Names (K) then
1431 if K < Highest_So_Far then
1432 Error_Msg_Name_1 := Pname;
1433 Error_Msg_N
1434 ("parameters out of order for pragma%", Arg);
1435 Error_Msg_Name_1 := Names (K);
1436 Error_Msg_Name_2 := Names (Highest_So_Far);
1437 Error_Msg_N ("\% must appear before %", Arg);
1438 raise Pragma_Exit;
1439
1440 else
1441 Highest_So_Far := K;
1442 end if;
1443 end if;
1444 end loop;
1445 end if;
1446
1447 Arg := Next (Arg);
1448 end loop;
1449 end Check_Arg_Order;
1450
1451 --------------------------------
1452 -- Check_At_Least_N_Arguments --
1453 --------------------------------
1454
1455 procedure Check_At_Least_N_Arguments (N : Nat) is
1456 begin
1457 if Arg_Count < N then
1458 Error_Pragma ("too few arguments for pragma%");
1459 end if;
1460 end Check_At_Least_N_Arguments;
1461
1462 -------------------------------
1463 -- Check_At_Most_N_Arguments --
1464 -------------------------------
1465
1466 procedure Check_At_Most_N_Arguments (N : Nat) is
1467 Arg : Node_Id;
1468 begin
1469 if Arg_Count > N then
1470 Arg := Arg1;
1471 for J in 1 .. N loop
1472 Next (Arg);
1473 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1474 end loop;
1475 end if;
1476 end Check_At_Most_N_Arguments;
1477
1478 ---------------------
1479 -- Check_Component --
1480 ---------------------
1481
1482 procedure Check_Component
1483 (Comp : Node_Id;
1484 UU_Typ : Entity_Id;
1485 In_Variant_Part : Boolean := False)
1486 is
1487 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1488 Sindic : constant Node_Id :=
1489 Subtype_Indication (Component_Definition (Comp));
1490 Typ : constant Entity_Id := Etype (Comp_Id);
1491
1492 begin
1493 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1494 -- object constraint, then the component type shall be an Unchecked_
1495 -- Union.
1496
1497 if Nkind (Sindic) = N_Subtype_Indication
1498 and then Has_Per_Object_Constraint (Comp_Id)
1499 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1500 then
1501 Error_Msg_N
1502 ("component subtype subject to per-object constraint "
1503 & "must be an Unchecked_Union", Comp);
1504
1505 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1506 -- the body of a generic unit, or within the body of any of its
1507 -- descendant library units, no part of the type of a component
1508 -- declared in a variant_part of the unchecked union type shall be of
1509 -- a formal private type or formal private extension declared within
1510 -- the formal part of the generic unit.
1511
1512 elsif Ada_Version >= Ada_2012
1513 and then In_Generic_Body (UU_Typ)
1514 and then In_Variant_Part
1515 and then Is_Private_Type (Typ)
1516 and then Is_Generic_Type (Typ)
1517 then
1518 Error_Msg_N
1519 ("component of unchecked union cannot be of generic type", Comp);
1520
1521 elsif Needs_Finalization (Typ) then
1522 Error_Msg_N
1523 ("component of unchecked union cannot be controlled", Comp);
1524
1525 elsif Has_Task (Typ) then
1526 Error_Msg_N
1527 ("component of unchecked union cannot have tasks", Comp);
1528 end if;
1529 end Check_Component;
1530
1531 ---------------------------------
1532 -- Check_Contract_Or_Test_Case --
1533 ---------------------------------
1534
1535 procedure Check_Contract_Or_Test_Case is
1536 P : Node_Id;
1537 PO : Node_Id;
1538
1539 procedure Chain_CTC (PO : Node_Id);
1540 -- If PO is a [generic] subprogram declaration node, then the
1541 -- contract-case or test-case applies to this subprogram and the
1542 -- processing for the pragma is completed. Otherwise the pragma
1543 -- is misplaced.
1544
1545 ---------------
1546 -- Chain_CTC --
1547 ---------------
1548
1549 procedure Chain_CTC (PO : Node_Id) is
1550 S : Entity_Id;
1551
1552 begin
1553 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1554 Error_Pragma
1555 ("pragma% cannot be applied to abstract subprogram");
1556
1557 elsif Nkind (PO) = N_Entry_Declaration then
1558 Error_Pragma ("pragma% cannot be applied to entry");
1559
1560 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1561 N_Generic_Subprogram_Declaration)
1562 then
1563 Pragma_Misplaced;
1564 end if;
1565
1566 -- Here if we have [generic] subprogram declaration
1567
1568 S := Defining_Unit_Name (Specification (PO));
1569
1570 -- Note: we do not analyze the pragma at this point. Instead we
1571 -- delay this analysis until the end of the declarative part in
1572 -- which the pragma appears. This implements the required delay
1573 -- in this analysis, allowing forward references. The analysis
1574 -- happens at the end of Analyze_Declarations.
1575
1576 -- There should not be another contract-case or test-case with the
1577 -- same name associated to this subprogram.
1578
1579 declare
1580 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
1581 CTC : Node_Id;
1582
1583 begin
1584 CTC := Spec_CTC_List (Contract (S));
1585 while Present (CTC) loop
1586
1587 -- Omit pragma Contract_Cases because it does not introduce
1588 -- a unique case name and it does not follow the syntax of
1589 -- Contract_Case and Test_Case.
1590
1591 if Pragma_Name (CTC) = Name_Contract_Cases then
1592 null;
1593
1594 elsif String_Equal
1595 (Name, Get_Name_From_CTC_Pragma (CTC))
1596 then
1597 Error_Msg_Sloc := Sloc (CTC);
1598 Error_Pragma ("name for pragma% is already used#");
1599 end if;
1600
1601 CTC := Next_Pragma (CTC);
1602 end loop;
1603 end;
1604
1605 -- Chain spec CTC pragma to list for subprogram
1606
1607 Set_Next_Pragma (N, Spec_CTC_List (Contract (S)));
1608 Set_Spec_CTC_List (Contract (S), N);
1609 end Chain_CTC;
1610
1611 -- Start of processing for Check_Contract_Or_Test_Case
1612
1613 begin
1614 -- First check pragma arguments
1615
1616 GNAT_Pragma;
1617 Check_At_Least_N_Arguments (2);
1618 Check_At_Most_N_Arguments (4);
1619 Check_Arg_Order
1620 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
1621
1622 Check_Optional_Identifier (Arg1, Name_Name);
1623 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
1624
1625 -- In ASIS mode, for a pragma generated from a source aspect, also
1626 -- analyze the original aspect expression.
1627
1628 if ASIS_Mode
1629 and then Present (Corresponding_Aspect (N))
1630 then
1631 Check_Expr_Is_Static_Expression
1632 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
1633 end if;
1634
1635 Check_Optional_Identifier (Arg2, Name_Mode);
1636 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
1637
1638 if Arg_Count = 4 then
1639 Check_Identifier (Arg3, Name_Requires);
1640 Check_Identifier (Arg4, Name_Ensures);
1641
1642 elsif Arg_Count = 3 then
1643 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
1644 end if;
1645
1646 -- Check pragma placement
1647
1648 if not Is_List_Member (N) then
1649 Pragma_Misplaced;
1650 end if;
1651
1652 -- Contract-case or test-case should only appear in package spec unit
1653
1654 if Get_Source_Unit (N) = No_Unit
1655 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
1656 N_Package_Declaration,
1657 N_Generic_Package_Declaration)
1658 then
1659 Pragma_Misplaced;
1660 end if;
1661
1662 -- Search prior declarations
1663
1664 P := N;
1665 while Present (Prev (P)) loop
1666 P := Prev (P);
1667
1668 -- If the previous node is a generic subprogram, do not go to to
1669 -- the original node, which is the unanalyzed tree: we need to
1670 -- attach the contract-case or test-case to the analyzed version
1671 -- at this point. They get propagated to the original tree when
1672 -- analyzing the corresponding body.
1673
1674 if Nkind (P) not in N_Generic_Declaration then
1675 PO := Original_Node (P);
1676 else
1677 PO := P;
1678 end if;
1679
1680 -- Skip past prior pragma
1681
1682 if Nkind (PO) = N_Pragma then
1683 null;
1684
1685 -- Skip stuff not coming from source
1686
1687 elsif not Comes_From_Source (PO) then
1688 null;
1689
1690 -- Only remaining possibility is subprogram declaration. First
1691 -- check that it is declared directly in a package declaration.
1692 -- This may be either the package declaration for the current unit
1693 -- being defined or a local package declaration.
1694
1695 elsif not Present (Parent (Parent (PO)))
1696 or else not Present (Parent (Parent (Parent (PO))))
1697 or else not Nkind_In (Parent (Parent (PO)),
1698 N_Package_Declaration,
1699 N_Generic_Package_Declaration)
1700 then
1701 Pragma_Misplaced;
1702
1703 else
1704 Chain_CTC (PO);
1705 return;
1706 end if;
1707 end loop;
1708
1709 -- If we fall through, pragma was misplaced
1710
1711 Pragma_Misplaced;
1712 end Check_Contract_Or_Test_Case;
1713
1714 ----------------------------
1715 -- Check_Duplicate_Pragma --
1716 ----------------------------
1717
1718 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1719 Id : Entity_Id := E;
1720 P : Node_Id;
1721
1722 begin
1723 -- Nothing to do if this pragma comes from an aspect specification,
1724 -- since we could not be duplicating a pragma, and we dealt with the
1725 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1726
1727 if From_Aspect_Specification (N) then
1728 return;
1729 end if;
1730
1731 -- Otherwise current pragma may duplicate previous pragma or a
1732 -- previously given aspect specification or attribute definition
1733 -- clause for the same pragma.
1734
1735 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
1736
1737 if Present (P) then
1738 Error_Msg_Name_1 := Pragma_Name (N);
1739 Error_Msg_Sloc := Sloc (P);
1740
1741 -- For a single protected or a single task object, the error is
1742 -- issued on the original entity.
1743
1744 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
1745 Id := Defining_Identifier (Original_Node (Parent (Id)));
1746 end if;
1747
1748 if Nkind (P) = N_Aspect_Specification
1749 or else From_Aspect_Specification (P)
1750 then
1751 Error_Msg_NE ("aspect% for & previously given#", N, Id);
1752 else
1753 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
1754 end if;
1755
1756 raise Pragma_Exit;
1757 end if;
1758 end Check_Duplicate_Pragma;
1759
1760 ----------------------------------
1761 -- Check_Duplicated_Export_Name --
1762 ----------------------------------
1763
1764 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1765 String_Val : constant String_Id := Strval (Nam);
1766
1767 begin
1768 -- We are only interested in the export case, and in the case of
1769 -- generics, it is the instance, not the template, that is the
1770 -- problem (the template will generate a warning in any case).
1771
1772 if not Inside_A_Generic
1773 and then (Prag_Id = Pragma_Export
1774 or else
1775 Prag_Id = Pragma_Export_Procedure
1776 or else
1777 Prag_Id = Pragma_Export_Valued_Procedure
1778 or else
1779 Prag_Id = Pragma_Export_Function)
1780 then
1781 for J in Externals.First .. Externals.Last loop
1782 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1783 Error_Msg_Sloc := Sloc (Externals.Table (J));
1784 Error_Msg_N ("external name duplicates name given#", Nam);
1785 exit;
1786 end if;
1787 end loop;
1788
1789 Externals.Append (Nam);
1790 end if;
1791 end Check_Duplicated_Export_Name;
1792
1793 -------------------------------------
1794 -- Check_Expr_Is_Static_Expression --
1795 -------------------------------------
1796
1797 procedure Check_Expr_Is_Static_Expression
1798 (Expr : Node_Id;
1799 Typ : Entity_Id := Empty)
1800 is
1801 begin
1802 if Present (Typ) then
1803 Analyze_And_Resolve (Expr, Typ);
1804 else
1805 Analyze_And_Resolve (Expr);
1806 end if;
1807
1808 if Is_OK_Static_Expression (Expr) then
1809 return;
1810
1811 elsif Etype (Expr) = Any_Type then
1812 raise Pragma_Exit;
1813
1814 -- An interesting special case, if we have a string literal and we
1815 -- are in Ada 83 mode, then we allow it even though it will not be
1816 -- flagged as static. This allows the use of Ada 95 pragmas like
1817 -- Import in Ada 83 mode. They will of course be flagged with
1818 -- warnings as usual, but will not cause errors.
1819
1820 elsif Ada_Version = Ada_83
1821 and then Nkind (Expr) = N_String_Literal
1822 then
1823 return;
1824
1825 -- Static expression that raises Constraint_Error. This has already
1826 -- been flagged, so just exit from pragma processing.
1827
1828 elsif Is_Static_Expression (Expr) then
1829 raise Pragma_Exit;
1830
1831 -- Finally, we have a real error
1832
1833 else
1834 Error_Msg_Name_1 := Pname;
1835
1836 declare
1837 Msg : String :=
1838 "argument for pragma% must be a static expression!";
1839 begin
1840 Fix_Error (Msg);
1841 Flag_Non_Static_Expr (Msg, Expr);
1842 end;
1843
1844 raise Pragma_Exit;
1845 end if;
1846 end Check_Expr_Is_Static_Expression;
1847
1848 -------------------------
1849 -- Check_First_Subtype --
1850 -------------------------
1851
1852 procedure Check_First_Subtype (Arg : Node_Id) is
1853 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1854 Ent : constant Entity_Id := Entity (Argx);
1855
1856 begin
1857 if Is_First_Subtype (Ent) then
1858 null;
1859
1860 elsif Is_Type (Ent) then
1861 Error_Pragma_Arg
1862 ("pragma% cannot apply to subtype", Argx);
1863
1864 elsif Is_Object (Ent) then
1865 Error_Pragma_Arg
1866 ("pragma% cannot apply to object, requires a type", Argx);
1867
1868 else
1869 Error_Pragma_Arg
1870 ("pragma% cannot apply to&, requires a type", Argx);
1871 end if;
1872 end Check_First_Subtype;
1873
1874 ----------------------
1875 -- Check_Identifier --
1876 ----------------------
1877
1878 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1879 begin
1880 if Present (Arg)
1881 and then Nkind (Arg) = N_Pragma_Argument_Association
1882 then
1883 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1884 Error_Msg_Name_1 := Pname;
1885 Error_Msg_Name_2 := Id;
1886 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1887 raise Pragma_Exit;
1888 end if;
1889 end if;
1890 end Check_Identifier;
1891
1892 --------------------------------
1893 -- Check_Identifier_Is_One_Of --
1894 --------------------------------
1895
1896 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1897 begin
1898 if Present (Arg)
1899 and then Nkind (Arg) = N_Pragma_Argument_Association
1900 then
1901 if Chars (Arg) = No_Name then
1902 Error_Msg_Name_1 := Pname;
1903 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1904 raise Pragma_Exit;
1905
1906 elsif Chars (Arg) /= N1
1907 and then Chars (Arg) /= N2
1908 then
1909 Error_Msg_Name_1 := Pname;
1910 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1911 raise Pragma_Exit;
1912 end if;
1913 end if;
1914 end Check_Identifier_Is_One_Of;
1915
1916 ---------------------------
1917 -- Check_In_Main_Program --
1918 ---------------------------
1919
1920 procedure Check_In_Main_Program is
1921 P : constant Node_Id := Parent (N);
1922
1923 begin
1924 -- Must be at in subprogram body
1925
1926 if Nkind (P) /= N_Subprogram_Body then
1927 Error_Pragma ("% pragma allowed only in subprogram");
1928
1929 -- Otherwise warn if obviously not main program
1930
1931 elsif Present (Parameter_Specifications (Specification (P)))
1932 or else not Is_Compilation_Unit (Defining_Entity (P))
1933 then
1934 Error_Msg_Name_1 := Pname;
1935 Error_Msg_N
1936 ("??pragma% is only effective in main program", N);
1937 end if;
1938 end Check_In_Main_Program;
1939
1940 ---------------------------------------
1941 -- Check_Interrupt_Or_Attach_Handler --
1942 ---------------------------------------
1943
1944 procedure Check_Interrupt_Or_Attach_Handler is
1945 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1946 Handler_Proc, Proc_Scope : Entity_Id;
1947
1948 begin
1949 Analyze (Arg1_X);
1950
1951 if Prag_Id = Pragma_Interrupt_Handler then
1952 Check_Restriction (No_Dynamic_Attachment, N);
1953 end if;
1954
1955 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1956 Proc_Scope := Scope (Handler_Proc);
1957
1958 -- On AAMP only, a pragma Interrupt_Handler is supported for
1959 -- nonprotected parameterless procedures.
1960
1961 if not AAMP_On_Target
1962 or else Prag_Id = Pragma_Attach_Handler
1963 then
1964 if Ekind (Proc_Scope) /= E_Protected_Type then
1965 Error_Pragma_Arg
1966 ("argument of pragma% must be protected procedure", Arg1);
1967 end if;
1968
1969 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1970 Error_Pragma ("pragma% must be in protected definition");
1971 end if;
1972 end if;
1973
1974 if not Is_Library_Level_Entity (Proc_Scope)
1975 or else (AAMP_On_Target
1976 and then not Is_Library_Level_Entity (Handler_Proc))
1977 then
1978 Error_Pragma_Arg
1979 ("argument for pragma% must be library level entity", Arg1);
1980 end if;
1981
1982 -- AI05-0033: A pragma cannot appear within a generic body, because
1983 -- instance can be in a nested scope. The check that protected type
1984 -- is itself a library-level declaration is done elsewhere.
1985
1986 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
1987 -- handle code prior to AI-0033. Analysis tools typically are not
1988 -- interested in this pragma in any case, so no need to worry too
1989 -- much about its placement.
1990
1991 if Inside_A_Generic then
1992 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1993 and then In_Package_Body (Scope (Current_Scope))
1994 and then not Relaxed_RM_Semantics
1995 then
1996 Error_Pragma ("pragma% cannot be used inside a generic");
1997 end if;
1998 end if;
1999 end Check_Interrupt_Or_Attach_Handler;
2000
2001 ---------------------------------
2002 -- Check_Loop_Pragma_Placement --
2003 ---------------------------------
2004
2005 procedure Check_Loop_Pragma_Placement is
2006 procedure Placement_Error (Constr : Node_Id);
2007 pragma No_Return (Placement_Error);
2008 -- Node Constr denotes the last loop restricted construct before we
2009 -- encountered an illegal relation between enclosing constructs. Emit
2010 -- an error depending on what Constr was.
2011
2012 ---------------------
2013 -- Placement_Error --
2014 ---------------------
2015
2016 procedure Placement_Error (Constr : Node_Id) is
2017 begin
2018 if Nkind (Constr) = N_Pragma then
2019 Error_Pragma
2020 ("pragma % must appear immediately within the statements "
2021 & "of a loop");
2022 else
2023 Error_Pragma_Arg
2024 ("block containing pragma % must appear immediately within "
2025 & "the statements of a loop", Constr);
2026 end if;
2027 end Placement_Error;
2028
2029 -- Local declarations
2030
2031 Prev : Node_Id;
2032 Stmt : Node_Id;
2033
2034 -- Start of processing for Check_Loop_Pragma_Placement
2035
2036 begin
2037 Prev := N;
2038 Stmt := Parent (N);
2039 while Present (Stmt) loop
2040
2041 -- The pragma or previous block must appear immediately within the
2042 -- current block's declarative or statement part.
2043
2044 if Nkind (Stmt) = N_Block_Statement then
2045 if (No (Declarations (Stmt))
2046 or else List_Containing (Prev) /= Declarations (Stmt))
2047 and then
2048 List_Containing (Prev) /=
2049 Statements (Handled_Statement_Sequence (Stmt))
2050 then
2051 Placement_Error (Prev);
2052 return;
2053
2054 -- Keep inspecting the parents because we are now within a
2055 -- chain of nested blocks.
2056
2057 else
2058 Prev := Stmt;
2059 Stmt := Parent (Stmt);
2060 end if;
2061
2062 -- The pragma or previous block must appear immediately within the
2063 -- statements of the loop.
2064
2065 elsif Nkind (Stmt) = N_Loop_Statement then
2066 if List_Containing (Prev) /= Statements (Stmt) then
2067 Placement_Error (Prev);
2068 end if;
2069
2070 -- Stop the traversal because we reached the innermost loop
2071 -- regardless of whether we encountered an error or not.
2072
2073 return;
2074
2075 -- Ignore a handled statement sequence. Note that this node may
2076 -- be related to a subprogram body in which case we will emit an
2077 -- error on the next iteration of the search.
2078
2079 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
2080 Stmt := Parent (Stmt);
2081
2082 -- Any other statement breaks the chain from the pragma to the
2083 -- loop.
2084
2085 else
2086 Placement_Error (Prev);
2087 return;
2088 end if;
2089 end loop;
2090 end Check_Loop_Pragma_Placement;
2091
2092 -------------------------------------------
2093 -- Check_Is_In_Decl_Part_Or_Package_Spec --
2094 -------------------------------------------
2095
2096 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
2097 P : Node_Id;
2098
2099 begin
2100 P := Parent (N);
2101 loop
2102 if No (P) then
2103 exit;
2104
2105 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
2106 exit;
2107
2108 elsif Nkind_In (P, N_Package_Specification,
2109 N_Block_Statement)
2110 then
2111 return;
2112
2113 -- Note: the following tests seem a little peculiar, because
2114 -- they test for bodies, but if we were in the statement part
2115 -- of the body, we would already have hit the handled statement
2116 -- sequence, so the only way we get here is by being in the
2117 -- declarative part of the body.
2118
2119 elsif Nkind_In (P, N_Subprogram_Body,
2120 N_Package_Body,
2121 N_Task_Body,
2122 N_Entry_Body)
2123 then
2124 return;
2125 end if;
2126
2127 P := Parent (P);
2128 end loop;
2129
2130 Error_Pragma ("pragma% is not in declarative part or package spec");
2131 end Check_Is_In_Decl_Part_Or_Package_Spec;
2132
2133 -------------------------
2134 -- Check_No_Identifier --
2135 -------------------------
2136
2137 procedure Check_No_Identifier (Arg : Node_Id) is
2138 begin
2139 if Nkind (Arg) = N_Pragma_Argument_Association
2140 and then Chars (Arg) /= No_Name
2141 then
2142 Error_Pragma_Arg_Ident
2143 ("pragma% does not permit identifier& here", Arg);
2144 end if;
2145 end Check_No_Identifier;
2146
2147 --------------------------
2148 -- Check_No_Identifiers --
2149 --------------------------
2150
2151 procedure Check_No_Identifiers is
2152 Arg_Node : Node_Id;
2153 begin
2154 if Arg_Count > 0 then
2155 Arg_Node := Arg1;
2156 while Present (Arg_Node) loop
2157 Check_No_Identifier (Arg_Node);
2158 Next (Arg_Node);
2159 end loop;
2160 end if;
2161 end Check_No_Identifiers;
2162
2163 ------------------------
2164 -- Check_No_Link_Name --
2165 ------------------------
2166
2167 procedure Check_No_Link_Name is
2168 begin
2169 if Present (Arg3)
2170 and then Chars (Arg3) = Name_Link_Name
2171 then
2172 Arg4 := Arg3;
2173 end if;
2174
2175 if Present (Arg4) then
2176 Error_Pragma_Arg
2177 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
2178 end if;
2179 end Check_No_Link_Name;
2180
2181 -------------------------------
2182 -- Check_Optional_Identifier --
2183 -------------------------------
2184
2185 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
2186 begin
2187 if Present (Arg)
2188 and then Nkind (Arg) = N_Pragma_Argument_Association
2189 and then Chars (Arg) /= No_Name
2190 then
2191 if Chars (Arg) /= Id then
2192 Error_Msg_Name_1 := Pname;
2193 Error_Msg_Name_2 := Id;
2194 Error_Msg_N ("pragma% argument expects identifier%", Arg);
2195 raise Pragma_Exit;
2196 end if;
2197 end if;
2198 end Check_Optional_Identifier;
2199
2200 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
2201 begin
2202 Name_Buffer (1 .. Id'Length) := Id;
2203 Name_Len := Id'Length;
2204 Check_Optional_Identifier (Arg, Name_Find);
2205 end Check_Optional_Identifier;
2206
2207 --------------------------------------
2208 -- Check_Precondition_Postcondition --
2209 --------------------------------------
2210
2211 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
2212 P : Node_Id;
2213 PO : Node_Id;
2214
2215 procedure Chain_PPC (PO : Node_Id);
2216 -- If PO is an entry or a [generic] subprogram declaration node, then
2217 -- the precondition/postcondition applies to this subprogram and the
2218 -- processing for the pragma is completed. Otherwise the pragma is
2219 -- misplaced.
2220
2221 ---------------
2222 -- Chain_PPC --
2223 ---------------
2224
2225 procedure Chain_PPC (PO : Node_Id) is
2226 S : Entity_Id;
2227
2228 begin
2229 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2230 if not From_Aspect_Specification (N) then
2231 Error_Pragma
2232 ("pragma% cannot be applied to abstract subprogram");
2233
2234 elsif Class_Present (N) then
2235 null;
2236
2237 else
2238 Error_Pragma
2239 ("aspect % requires ''Class for abstract subprogram");
2240 end if;
2241
2242 -- AI05-0230: The same restriction applies to null procedures. For
2243 -- compatibility with earlier uses of the Ada pragma, apply this
2244 -- rule only to aspect specifications.
2245
2246 -- The above discrpency needs documentation. Robert is dubious
2247 -- about whether it is a good idea ???
2248
2249 elsif Nkind (PO) = N_Subprogram_Declaration
2250 and then Nkind (Specification (PO)) = N_Procedure_Specification
2251 and then Null_Present (Specification (PO))
2252 and then From_Aspect_Specification (N)
2253 and then not Class_Present (N)
2254 then
2255 Error_Pragma
2256 ("aspect % requires ''Class for null procedure");
2257
2258 -- Pre/postconditions are legal on a subprogram body if it is not
2259 -- a completion of a declaration. They are also legal on a stub
2260 -- with no previous declarations (this is checked when processing
2261 -- the corresponding aspects).
2262
2263 elsif Nkind (PO) = N_Subprogram_Body
2264 and then Acts_As_Spec (PO)
2265 then
2266 null;
2267
2268 elsif Nkind (PO) = N_Subprogram_Body_Stub then
2269 null;
2270
2271 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2272 N_Expression_Function,
2273 N_Generic_Subprogram_Declaration,
2274 N_Entry_Declaration)
2275 then
2276 Pragma_Misplaced;
2277 end if;
2278
2279 -- Here if we have [generic] subprogram or entry declaration
2280
2281 if Nkind (PO) = N_Entry_Declaration then
2282 S := Defining_Entity (PO);
2283 else
2284 S := Defining_Unit_Name (Specification (PO));
2285
2286 if Nkind (S) = N_Defining_Program_Unit_Name then
2287 S := Defining_Identifier (S);
2288 end if;
2289 end if;
2290
2291 -- Note: we do not analyze the pragma at this point. Instead we
2292 -- delay this analysis until the end of the declarative part in
2293 -- which the pragma appears. This implements the required delay
2294 -- in this analysis, allowing forward references. The analysis
2295 -- happens at the end of Analyze_Declarations.
2296
2297 -- Chain spec PPC pragma to list for subprogram
2298
2299 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
2300 Set_Spec_PPC_List (Contract (S), N);
2301
2302 -- Return indicating spec case
2303
2304 In_Body := False;
2305 return;
2306 end Chain_PPC;
2307
2308 -- Start of processing for Check_Precondition_Postcondition
2309
2310 begin
2311 if not Is_List_Member (N) then
2312 Pragma_Misplaced;
2313 end if;
2314
2315 -- Preanalyze message argument if present. Visibility in this
2316 -- argument is established at the point of pragma occurrence.
2317
2318 if Arg_Count = 2 then
2319 Check_Optional_Identifier (Arg2, Name_Message);
2320 Preanalyze_Spec_Expression
2321 (Get_Pragma_Arg (Arg2), Standard_String);
2322 end if;
2323
2324 -- For a pragma PPC in the extended main source unit, record enabled
2325 -- status in SCO.
2326
2327 -- This may seem redundant with the call to Check_Enabled occurring
2328 -- later on when the pragma is rewritten into a pragma Check but
2329 -- is actually required in the case of a postcondition within a
2330 -- generic.
2331
2332 if Check_Enabled (Pname) and then not Split_PPC (N) then
2333 Set_SCO_Pragma_Enabled (Loc);
2334 end if;
2335
2336 -- If we are within an inlined body, the legality of the pragma
2337 -- has been checked already.
2338
2339 if In_Inlined_Body then
2340 In_Body := True;
2341 return;
2342 end if;
2343
2344 -- Search prior declarations
2345
2346 P := N;
2347 while Present (Prev (P)) loop
2348 P := Prev (P);
2349
2350 -- If the previous node is a generic subprogram, do not go to to
2351 -- the original node, which is the unanalyzed tree: we need to
2352 -- attach the pre/postconditions to the analyzed version at this
2353 -- point. They get propagated to the original tree when analyzing
2354 -- the corresponding body.
2355
2356 if Nkind (P) not in N_Generic_Declaration then
2357 PO := Original_Node (P);
2358 else
2359 PO := P;
2360 end if;
2361
2362 -- Skip past prior pragma
2363
2364 if Nkind (PO) = N_Pragma then
2365 null;
2366
2367 -- Skip stuff not coming from source
2368
2369 elsif not Comes_From_Source (PO) then
2370
2371 -- The condition may apply to a subprogram instantiation
2372
2373 if Nkind (PO) = N_Subprogram_Declaration
2374 and then Present (Generic_Parent (Specification (PO)))
2375 then
2376 Chain_PPC (PO);
2377 return;
2378
2379 elsif Nkind (PO) = N_Subprogram_Declaration
2380 and then In_Instance
2381 then
2382 Chain_PPC (PO);
2383 return;
2384
2385 -- For all other cases of non source code, do nothing
2386
2387 else
2388 null;
2389 end if;
2390
2391 -- Only remaining possibility is subprogram declaration
2392
2393 else
2394 Chain_PPC (PO);
2395 return;
2396 end if;
2397 end loop;
2398
2399 -- If we fall through loop, pragma is at start of list, so see if it
2400 -- is at the start of declarations of a subprogram body.
2401
2402 if Nkind (Parent (N)) = N_Subprogram_Body
2403 and then List_Containing (N) = Declarations (Parent (N))
2404 then
2405 if Operating_Mode /= Generate_Code
2406 or else Inside_A_Generic
2407 then
2408 -- Analyze pragma expression for correctness and for ASIS use
2409
2410 Preanalyze_Assert_Expression
2411 (Get_Pragma_Arg (Arg1), Standard_Boolean);
2412
2413 -- In ASIS mode, for a pragma generated from a source aspect,
2414 -- also analyze the original aspect expression.
2415
2416 if ASIS_Mode
2417 and then Present (Corresponding_Aspect (N))
2418 then
2419 Preanalyze_Assert_Expression
2420 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2421 end if;
2422 end if;
2423
2424 In_Body := True;
2425 return;
2426
2427 -- See if it is in the pragmas after a library level subprogram
2428
2429 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2430
2431 -- In formal verification mode, analyze pragma expression for
2432 -- correctness, as it is not expanded later.
2433
2434 if Alfa_Mode then
2435 Analyze_PPC_In_Decl_Part
2436 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2437 end if;
2438
2439 Chain_PPC (Unit (Parent (Parent (N))));
2440 return;
2441 end if;
2442
2443 -- If we fall through, pragma was misplaced
2444
2445 Pragma_Misplaced;
2446 end Check_Precondition_Postcondition;
2447
2448 -----------------------------
2449 -- Check_Static_Constraint --
2450 -----------------------------
2451
2452 -- Note: for convenience in writing this procedure, in addition to
2453 -- the officially (i.e. by spec) allowed argument which is always a
2454 -- constraint, it also allows ranges and discriminant associations.
2455 -- Above is not clear ???
2456
2457 procedure Check_Static_Constraint (Constr : Node_Id) is
2458
2459 procedure Require_Static (E : Node_Id);
2460 -- Require given expression to be static expression
2461
2462 --------------------
2463 -- Require_Static --
2464 --------------------
2465
2466 procedure Require_Static (E : Node_Id) is
2467 begin
2468 if not Is_OK_Static_Expression (E) then
2469 Flag_Non_Static_Expr
2470 ("non-static constraint not allowed in Unchecked_Union!", E);
2471 raise Pragma_Exit;
2472 end if;
2473 end Require_Static;
2474
2475 -- Start of processing for Check_Static_Constraint
2476
2477 begin
2478 case Nkind (Constr) is
2479 when N_Discriminant_Association =>
2480 Require_Static (Expression (Constr));
2481
2482 when N_Range =>
2483 Require_Static (Low_Bound (Constr));
2484 Require_Static (High_Bound (Constr));
2485
2486 when N_Attribute_Reference =>
2487 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2488 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2489
2490 when N_Range_Constraint =>
2491 Check_Static_Constraint (Range_Expression (Constr));
2492
2493 when N_Index_Or_Discriminant_Constraint =>
2494 declare
2495 IDC : Entity_Id;
2496 begin
2497 IDC := First (Constraints (Constr));
2498 while Present (IDC) loop
2499 Check_Static_Constraint (IDC);
2500 Next (IDC);
2501 end loop;
2502 end;
2503
2504 when others =>
2505 null;
2506 end case;
2507 end Check_Static_Constraint;
2508
2509 --------------------------------------
2510 -- Check_Valid_Configuration_Pragma --
2511 --------------------------------------
2512
2513 -- A configuration pragma must appear in the context clause of a
2514 -- compilation unit, and only other pragmas may precede it. Note that
2515 -- the test also allows use in a configuration pragma file.
2516
2517 procedure Check_Valid_Configuration_Pragma is
2518 begin
2519 if not Is_Configuration_Pragma then
2520 Error_Pragma ("incorrect placement for configuration pragma%");
2521 end if;
2522 end Check_Valid_Configuration_Pragma;
2523
2524 -------------------------------------
2525 -- Check_Valid_Library_Unit_Pragma --
2526 -------------------------------------
2527
2528 procedure Check_Valid_Library_Unit_Pragma is
2529 Plist : List_Id;
2530 Parent_Node : Node_Id;
2531 Unit_Name : Entity_Id;
2532 Unit_Kind : Node_Kind;
2533 Unit_Node : Node_Id;
2534 Sindex : Source_File_Index;
2535
2536 begin
2537 if not Is_List_Member (N) then
2538 Pragma_Misplaced;
2539
2540 else
2541 Plist := List_Containing (N);
2542 Parent_Node := Parent (Plist);
2543
2544 if Parent_Node = Empty then
2545 Pragma_Misplaced;
2546
2547 -- Case of pragma appearing after a compilation unit. In this case
2548 -- it must have an argument with the corresponding name and must
2549 -- be part of the following pragmas of its parent.
2550
2551 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2552 if Plist /= Pragmas_After (Parent_Node) then
2553 Pragma_Misplaced;
2554
2555 elsif Arg_Count = 0 then
2556 Error_Pragma
2557 ("argument required if outside compilation unit");
2558
2559 else
2560 Check_No_Identifiers;
2561 Check_Arg_Count (1);
2562 Unit_Node := Unit (Parent (Parent_Node));
2563 Unit_Kind := Nkind (Unit_Node);
2564
2565 Analyze (Get_Pragma_Arg (Arg1));
2566
2567 if Unit_Kind = N_Generic_Subprogram_Declaration
2568 or else Unit_Kind = N_Subprogram_Declaration
2569 then
2570 Unit_Name := Defining_Entity (Unit_Node);
2571
2572 elsif Unit_Kind in N_Generic_Instantiation then
2573 Unit_Name := Defining_Entity (Unit_Node);
2574
2575 else
2576 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2577 end if;
2578
2579 if Chars (Unit_Name) /=
2580 Chars (Entity (Get_Pragma_Arg (Arg1)))
2581 then
2582 Error_Pragma_Arg
2583 ("pragma% argument is not current unit name", Arg1);
2584 end if;
2585
2586 if Ekind (Unit_Name) = E_Package
2587 and then Present (Renamed_Entity (Unit_Name))
2588 then
2589 Error_Pragma ("pragma% not allowed for renamed package");
2590 end if;
2591 end if;
2592
2593 -- Pragma appears other than after a compilation unit
2594
2595 else
2596 -- Here we check for the generic instantiation case and also
2597 -- for the case of processing a generic formal package. We
2598 -- detect these cases by noting that the Sloc on the node
2599 -- does not belong to the current compilation unit.
2600
2601 Sindex := Source_Index (Current_Sem_Unit);
2602
2603 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2604 Rewrite (N, Make_Null_Statement (Loc));
2605 return;
2606
2607 -- If before first declaration, the pragma applies to the
2608 -- enclosing unit, and the name if present must be this name.
2609
2610 elsif Is_Before_First_Decl (N, Plist) then
2611 Unit_Node := Unit_Declaration_Node (Current_Scope);
2612 Unit_Kind := Nkind (Unit_Node);
2613
2614 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2615 Pragma_Misplaced;
2616
2617 elsif Unit_Kind = N_Subprogram_Body
2618 and then not Acts_As_Spec (Unit_Node)
2619 then
2620 Pragma_Misplaced;
2621
2622 elsif Nkind (Parent_Node) = N_Package_Body then
2623 Pragma_Misplaced;
2624
2625 elsif Nkind (Parent_Node) = N_Package_Specification
2626 and then Plist = Private_Declarations (Parent_Node)
2627 then
2628 Pragma_Misplaced;
2629
2630 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2631 or else Nkind (Parent_Node) =
2632 N_Generic_Subprogram_Declaration)
2633 and then Plist = Generic_Formal_Declarations (Parent_Node)
2634 then
2635 Pragma_Misplaced;
2636
2637 elsif Arg_Count > 0 then
2638 Analyze (Get_Pragma_Arg (Arg1));
2639
2640 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2641 Error_Pragma_Arg
2642 ("name in pragma% must be enclosing unit", Arg1);
2643 end if;
2644
2645 -- It is legal to have no argument in this context
2646
2647 else
2648 return;
2649 end if;
2650
2651 -- Error if not before first declaration. This is because a
2652 -- library unit pragma argument must be the name of a library
2653 -- unit (RM 10.1.5(7)), but the only names permitted in this
2654 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2655 -- generic subprogram declarations or generic instantiations.
2656
2657 else
2658 Error_Pragma
2659 ("pragma% misplaced, must be before first declaration");
2660 end if;
2661 end if;
2662 end if;
2663 end Check_Valid_Library_Unit_Pragma;
2664
2665 -------------------
2666 -- Check_Variant --
2667 -------------------
2668
2669 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2670 Clist : constant Node_Id := Component_List (Variant);
2671 Comp : Node_Id;
2672
2673 begin
2674 Comp := First (Component_Items (Clist));
2675 while Present (Comp) loop
2676 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2677 Next (Comp);
2678 end loop;
2679 end Check_Variant;
2680
2681 ------------------
2682 -- Error_Pragma --
2683 ------------------
2684
2685 procedure Error_Pragma (Msg : String) is
2686 MsgF : String := Msg;
2687 begin
2688 Error_Msg_Name_1 := Pname;
2689 Fix_Error (MsgF);
2690 Error_Msg_N (MsgF, N);
2691 raise Pragma_Exit;
2692 end Error_Pragma;
2693
2694 ----------------------
2695 -- Error_Pragma_Arg --
2696 ----------------------
2697
2698 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2699 MsgF : String := Msg;
2700 begin
2701 Error_Msg_Name_1 := Pname;
2702 Fix_Error (MsgF);
2703 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2704 raise Pragma_Exit;
2705 end Error_Pragma_Arg;
2706
2707 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2708 MsgF : String := Msg1;
2709 begin
2710 Error_Msg_Name_1 := Pname;
2711 Fix_Error (MsgF);
2712 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2713 Error_Pragma_Arg (Msg2, Arg);
2714 end Error_Pragma_Arg;
2715
2716 ----------------------------
2717 -- Error_Pragma_Arg_Ident --
2718 ----------------------------
2719
2720 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2721 MsgF : String := Msg;
2722 begin
2723 Error_Msg_Name_1 := Pname;
2724 Fix_Error (MsgF);
2725 Error_Msg_N (MsgF, Arg);
2726 raise Pragma_Exit;
2727 end Error_Pragma_Arg_Ident;
2728
2729 ----------------------
2730 -- Error_Pragma_Ref --
2731 ----------------------
2732
2733 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2734 MsgF : String := Msg;
2735 begin
2736 Error_Msg_Name_1 := Pname;
2737 Fix_Error (MsgF);
2738 Error_Msg_Sloc := Sloc (Ref);
2739 Error_Msg_NE (MsgF, N, Ref);
2740 raise Pragma_Exit;
2741 end Error_Pragma_Ref;
2742
2743 ------------------------
2744 -- Find_Lib_Unit_Name --
2745 ------------------------
2746
2747 function Find_Lib_Unit_Name return Entity_Id is
2748 begin
2749 -- Return inner compilation unit entity, for case of nested
2750 -- categorization pragmas. This happens in generic unit.
2751
2752 if Nkind (Parent (N)) = N_Package_Specification
2753 and then Defining_Entity (Parent (N)) /= Current_Scope
2754 then
2755 return Defining_Entity (Parent (N));
2756 else
2757 return Current_Scope;
2758 end if;
2759 end Find_Lib_Unit_Name;
2760
2761 ----------------------------
2762 -- Find_Program_Unit_Name --
2763 ----------------------------
2764
2765 procedure Find_Program_Unit_Name (Id : Node_Id) is
2766 Unit_Name : Entity_Id;
2767 Unit_Kind : Node_Kind;
2768 P : constant Node_Id := Parent (N);
2769
2770 begin
2771 if Nkind (P) = N_Compilation_Unit then
2772 Unit_Kind := Nkind (Unit (P));
2773
2774 if Unit_Kind = N_Subprogram_Declaration
2775 or else Unit_Kind = N_Package_Declaration
2776 or else Unit_Kind in N_Generic_Declaration
2777 then
2778 Unit_Name := Defining_Entity (Unit (P));
2779
2780 if Chars (Id) = Chars (Unit_Name) then
2781 Set_Entity (Id, Unit_Name);
2782 Set_Etype (Id, Etype (Unit_Name));
2783 else
2784 Set_Etype (Id, Any_Type);
2785 Error_Pragma
2786 ("cannot find program unit referenced by pragma%");
2787 end if;
2788
2789 else
2790 Set_Etype (Id, Any_Type);
2791 Error_Pragma ("pragma% inapplicable to this unit");
2792 end if;
2793
2794 else
2795 Analyze (Id);
2796 end if;
2797 end Find_Program_Unit_Name;
2798
2799 -----------------------------------------
2800 -- Find_Unique_Parameterless_Procedure --
2801 -----------------------------------------
2802
2803 function Find_Unique_Parameterless_Procedure
2804 (Name : Entity_Id;
2805 Arg : Node_Id) return Entity_Id
2806 is
2807 Proc : Entity_Id := Empty;
2808
2809 begin
2810 -- The body of this procedure needs some comments ???
2811
2812 if not Is_Entity_Name (Name) then
2813 Error_Pragma_Arg
2814 ("argument of pragma% must be entity name", Arg);
2815
2816 elsif not Is_Overloaded (Name) then
2817 Proc := Entity (Name);
2818
2819 if Ekind (Proc) /= E_Procedure
2820 or else Present (First_Formal (Proc))
2821 then
2822 Error_Pragma_Arg
2823 ("argument of pragma% must be parameterless procedure", Arg);
2824 end if;
2825
2826 else
2827 declare
2828 Found : Boolean := False;
2829 It : Interp;
2830 Index : Interp_Index;
2831
2832 begin
2833 Get_First_Interp (Name, Index, It);
2834 while Present (It.Nam) loop
2835 Proc := It.Nam;
2836
2837 if Ekind (Proc) = E_Procedure
2838 and then No (First_Formal (Proc))
2839 then
2840 if not Found then
2841 Found := True;
2842 Set_Entity (Name, Proc);
2843 Set_Is_Overloaded (Name, False);
2844 else
2845 Error_Pragma_Arg
2846 ("ambiguous handler name for pragma% ", Arg);
2847 end if;
2848 end if;
2849
2850 Get_Next_Interp (Index, It);
2851 end loop;
2852
2853 if not Found then
2854 Error_Pragma_Arg
2855 ("argument of pragma% must be parameterless procedure",
2856 Arg);
2857 else
2858 Proc := Entity (Name);
2859 end if;
2860 end;
2861 end if;
2862
2863 return Proc;
2864 end Find_Unique_Parameterless_Procedure;
2865
2866 ---------------
2867 -- Fix_Error --
2868 ---------------
2869
2870 procedure Fix_Error (Msg : in out String) is
2871 begin
2872 if From_Aspect_Specification (N) then
2873 for J in Msg'First .. Msg'Last - 5 loop
2874 if Msg (J .. J + 5) = "pragma" then
2875 Msg (J .. J + 5) := "aspect";
2876 end if;
2877 end loop;
2878
2879 if Error_Msg_Name_1 = Name_Precondition then
2880 Error_Msg_Name_1 := Name_Pre;
2881 elsif Error_Msg_Name_1 = Name_Postcondition then
2882 Error_Msg_Name_1 := Name_Post;
2883 end if;
2884 end if;
2885 end Fix_Error;
2886
2887 -------------------------
2888 -- Gather_Associations --
2889 -------------------------
2890
2891 procedure Gather_Associations
2892 (Names : Name_List;
2893 Args : out Args_List)
2894 is
2895 Arg : Node_Id;
2896
2897 begin
2898 -- Initialize all parameters to Empty
2899
2900 for J in Args'Range loop
2901 Args (J) := Empty;
2902 end loop;
2903
2904 -- That's all we have to do if there are no argument associations
2905
2906 if No (Pragma_Argument_Associations (N)) then
2907 return;
2908 end if;
2909
2910 -- Otherwise first deal with any positional parameters present
2911
2912 Arg := First (Pragma_Argument_Associations (N));
2913 for Index in Args'Range loop
2914 exit when No (Arg) or else Chars (Arg) /= No_Name;
2915 Args (Index) := Get_Pragma_Arg (Arg);
2916 Next (Arg);
2917 end loop;
2918
2919 -- Positional parameters all processed, if any left, then we
2920 -- have too many positional parameters.
2921
2922 if Present (Arg) and then Chars (Arg) = No_Name then
2923 Error_Pragma_Arg
2924 ("too many positional associations for pragma%", Arg);
2925 end if;
2926
2927 -- Process named parameters if any are present
2928
2929 while Present (Arg) loop
2930 if Chars (Arg) = No_Name then
2931 Error_Pragma_Arg
2932 ("positional association cannot follow named association",
2933 Arg);
2934
2935 else
2936 for Index in Names'Range loop
2937 if Names (Index) = Chars (Arg) then
2938 if Present (Args (Index)) then
2939 Error_Pragma_Arg
2940 ("duplicate argument association for pragma%", Arg);
2941 else
2942 Args (Index) := Get_Pragma_Arg (Arg);
2943 exit;
2944 end if;
2945 end if;
2946
2947 if Index = Names'Last then
2948 Error_Msg_Name_1 := Pname;
2949 Error_Msg_N ("pragma% does not allow & argument", Arg);
2950
2951 -- Check for possible misspelling
2952
2953 for Index1 in Names'Range loop
2954 if Is_Bad_Spelling_Of
2955 (Chars (Arg), Names (Index1))
2956 then
2957 Error_Msg_Name_1 := Names (Index1);
2958 Error_Msg_N -- CODEFIX
2959 ("\possible misspelling of%", Arg);
2960 exit;
2961 end if;
2962 end loop;
2963
2964 raise Pragma_Exit;
2965 end if;
2966 end loop;
2967 end if;
2968
2969 Next (Arg);
2970 end loop;
2971 end Gather_Associations;
2972
2973 -----------------
2974 -- GNAT_Pragma --
2975 -----------------
2976
2977 procedure GNAT_Pragma is
2978 begin
2979 -- We need to check the No_Implementation_Pragmas restriction for
2980 -- the case of a pragma from source. Note that the case of aspects
2981 -- generating corresponding pragmas marks these pragmas as not being
2982 -- from source, so this test also catches that case.
2983
2984 if Comes_From_Source (N) then
2985 Check_Restriction (No_Implementation_Pragmas, N);
2986 end if;
2987 end GNAT_Pragma;
2988
2989 --------------------------
2990 -- Is_Before_First_Decl --
2991 --------------------------
2992
2993 function Is_Before_First_Decl
2994 (Pragma_Node : Node_Id;
2995 Decls : List_Id) return Boolean
2996 is
2997 Item : Node_Id := First (Decls);
2998
2999 begin
3000 -- Only other pragmas can come before this pragma
3001
3002 loop
3003 if No (Item) or else Nkind (Item) /= N_Pragma then
3004 return False;
3005
3006 elsif Item = Pragma_Node then
3007 return True;
3008 end if;
3009
3010 Next (Item);
3011 end loop;
3012 end Is_Before_First_Decl;
3013
3014 -----------------------------
3015 -- Is_Configuration_Pragma --
3016 -----------------------------
3017
3018 -- A configuration pragma must appear in the context clause of a
3019 -- compilation unit, and only other pragmas may precede it. Note that
3020 -- the test below also permits use in a configuration pragma file.
3021
3022 function Is_Configuration_Pragma return Boolean is
3023 Lis : constant List_Id := List_Containing (N);
3024 Par : constant Node_Id := Parent (N);
3025 Prg : Node_Id;
3026
3027 begin
3028 -- If no parent, then we are in the configuration pragma file,
3029 -- so the placement is definitely appropriate.
3030
3031 if No (Par) then
3032 return True;
3033
3034 -- Otherwise we must be in the context clause of a compilation unit
3035 -- and the only thing allowed before us in the context list is more
3036 -- configuration pragmas.
3037
3038 elsif Nkind (Par) = N_Compilation_Unit
3039 and then Context_Items (Par) = Lis
3040 then
3041 Prg := First (Lis);
3042
3043 loop
3044 if Prg = N then
3045 return True;
3046 elsif Nkind (Prg) /= N_Pragma then
3047 return False;
3048 end if;
3049
3050 Next (Prg);
3051 end loop;
3052
3053 else
3054 return False;
3055 end if;
3056 end Is_Configuration_Pragma;
3057
3058 --------------------------
3059 -- Is_In_Context_Clause --
3060 --------------------------
3061
3062 function Is_In_Context_Clause return Boolean is
3063 Plist : List_Id;
3064 Parent_Node : Node_Id;
3065
3066 begin
3067 if not Is_List_Member (N) then
3068 return False;
3069
3070 else
3071 Plist := List_Containing (N);
3072 Parent_Node := Parent (Plist);
3073
3074 if Parent_Node = Empty
3075 or else Nkind (Parent_Node) /= N_Compilation_Unit
3076 or else Context_Items (Parent_Node) /= Plist
3077 then
3078 return False;
3079 end if;
3080 end if;
3081
3082 return True;
3083 end Is_In_Context_Clause;
3084
3085 ---------------------------------
3086 -- Is_Static_String_Expression --
3087 ---------------------------------
3088
3089 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
3090 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3091
3092 begin
3093 Analyze_And_Resolve (Argx);
3094 return Is_OK_Static_Expression (Argx)
3095 and then Nkind (Argx) = N_String_Literal;
3096 end Is_Static_String_Expression;
3097
3098 ----------------------
3099 -- Pragma_Misplaced --
3100 ----------------------
3101
3102 procedure Pragma_Misplaced is
3103 begin
3104 Error_Pragma ("incorrect placement of pragma%");
3105 end Pragma_Misplaced;
3106
3107 ------------------------------------
3108 -- Process_Atomic_Shared_Volatile --
3109 ------------------------------------
3110
3111 procedure Process_Atomic_Shared_Volatile is
3112 E_Id : Node_Id;
3113 E : Entity_Id;
3114 D : Node_Id;
3115 K : Node_Kind;
3116 Utyp : Entity_Id;
3117
3118 procedure Set_Atomic (E : Entity_Id);
3119 -- Set given type as atomic, and if no explicit alignment was given,
3120 -- set alignment to unknown, since back end knows what the alignment
3121 -- requirements are for atomic arrays. Note: this step is necessary
3122 -- for derived types.
3123
3124 ----------------
3125 -- Set_Atomic --
3126 ----------------
3127
3128 procedure Set_Atomic (E : Entity_Id) is
3129 begin
3130 Set_Is_Atomic (E);
3131
3132 if not Has_Alignment_Clause (E) then
3133 Set_Alignment (E, Uint_0);
3134 end if;
3135 end Set_Atomic;
3136
3137 -- Start of processing for Process_Atomic_Shared_Volatile
3138
3139 begin
3140 Check_Ada_83_Warning;
3141 Check_No_Identifiers;
3142 Check_Arg_Count (1);
3143 Check_Arg_Is_Local_Name (Arg1);
3144 E_Id := Get_Pragma_Arg (Arg1);
3145
3146 if Etype (E_Id) = Any_Type then
3147 return;
3148 end if;
3149
3150 E := Entity (E_Id);
3151 D := Declaration_Node (E);
3152 K := Nkind (D);
3153
3154 -- Check duplicate before we chain ourselves!
3155
3156 Check_Duplicate_Pragma (E);
3157
3158 -- Now check appropriateness of the entity
3159
3160 if Is_Type (E) then
3161 if Rep_Item_Too_Early (E, N)
3162 or else
3163 Rep_Item_Too_Late (E, N)
3164 then
3165 return;
3166 else
3167 Check_First_Subtype (Arg1);
3168 end if;
3169
3170 if Prag_Id /= Pragma_Volatile then
3171 Set_Atomic (E);
3172 Set_Atomic (Underlying_Type (E));
3173 Set_Atomic (Base_Type (E));
3174 end if;
3175
3176 -- Attribute belongs on the base type. If the view of the type is
3177 -- currently private, it also belongs on the underlying type.
3178
3179 Set_Is_Volatile (Base_Type (E));
3180 Set_Is_Volatile (Underlying_Type (E));
3181
3182 Set_Treat_As_Volatile (E);
3183 Set_Treat_As_Volatile (Underlying_Type (E));
3184
3185 elsif K = N_Object_Declaration
3186 or else (K = N_Component_Declaration
3187 and then Original_Record_Component (E) = E)
3188 then
3189 if Rep_Item_Too_Late (E, N) then
3190 return;
3191 end if;
3192
3193 if Prag_Id /= Pragma_Volatile then
3194 Set_Is_Atomic (E);
3195
3196 -- If the object declaration has an explicit initialization, a
3197 -- temporary may have to be created to hold the expression, to
3198 -- ensure that access to the object remain atomic.
3199
3200 if Nkind (Parent (E)) = N_Object_Declaration
3201 and then Present (Expression (Parent (E)))
3202 then
3203 Set_Has_Delayed_Freeze (E);
3204 end if;
3205
3206 -- An interesting improvement here. If an object of composite
3207 -- type X is declared atomic, and the type X isn't, that's a
3208 -- pity, since it may not have appropriate alignment etc. We
3209 -- can rescue this in the special case where the object and
3210 -- type are in the same unit by just setting the type as
3211 -- atomic, so that the back end will process it as atomic.
3212
3213 -- Note: we used to do this for elementary types as well,
3214 -- but that turns out to be a bad idea and can have unwanted
3215 -- effects, most notably if the type is elementary, the object
3216 -- a simple component within a record, and both are in a spec:
3217 -- every object of this type in the entire program will be
3218 -- treated as atomic, thus incurring a potentially costly
3219 -- synchronization operation for every access.
3220
3221 -- Of course it would be best if the back end could just adjust
3222 -- the alignment etc for the specific object, but that's not
3223 -- something we are capable of doing at this point.
3224
3225 Utyp := Underlying_Type (Etype (E));
3226
3227 if Present (Utyp)
3228 and then Is_Composite_Type (Utyp)
3229 and then Sloc (E) > No_Location
3230 and then Sloc (Utyp) > No_Location
3231 and then
3232 Get_Source_File_Index (Sloc (E)) =
3233 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
3234 then
3235 Set_Is_Atomic (Underlying_Type (Etype (E)));
3236 end if;
3237 end if;
3238
3239 Set_Is_Volatile (E);
3240 Set_Treat_As_Volatile (E);
3241
3242 else
3243 Error_Pragma_Arg
3244 ("inappropriate entity for pragma%", Arg1);
3245 end if;
3246 end Process_Atomic_Shared_Volatile;
3247
3248 -------------------------------------------
3249 -- Process_Compile_Time_Warning_Or_Error --
3250 -------------------------------------------
3251
3252 procedure Process_Compile_Time_Warning_Or_Error is
3253 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
3254
3255 begin
3256 Check_Arg_Count (2);
3257 Check_No_Identifiers;
3258 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3259 Analyze_And_Resolve (Arg1x, Standard_Boolean);
3260
3261 if Compile_Time_Known_Value (Arg1x) then
3262 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3263 declare
3264 Str : constant String_Id :=
3265 Strval (Get_Pragma_Arg (Arg2));
3266 Len : constant Int := String_Length (Str);
3267 Cont : Boolean;
3268 Ptr : Nat;
3269 CC : Char_Code;
3270 C : Character;
3271 Cent : constant Entity_Id :=
3272 Cunit_Entity (Current_Sem_Unit);
3273
3274 Force : constant Boolean :=
3275 Prag_Id = Pragma_Compile_Time_Warning
3276 and then
3277 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3278 and then (Ekind (Cent) /= E_Package
3279 or else not In_Private_Part (Cent));
3280 -- Set True if this is the warning case, and we are in the
3281 -- visible part of a package spec, or in a subprogram spec,
3282 -- in which case we want to force the client to see the
3283 -- warning, even though it is not in the main unit.
3284
3285 begin
3286 -- Loop through segments of message separated by line feeds.
3287 -- We output these segments as separate messages with
3288 -- continuation marks for all but the first.
3289
3290 Cont := False;
3291 Ptr := 1;
3292 loop
3293 Error_Msg_Strlen := 0;
3294
3295 -- Loop to copy characters from argument to error message
3296 -- string buffer.
3297
3298 loop
3299 exit when Ptr > Len;
3300 CC := Get_String_Char (Str, Ptr);
3301 Ptr := Ptr + 1;
3302
3303 -- Ignore wide chars ??? else store character
3304
3305 if In_Character_Range (CC) then
3306 C := Get_Character (CC);
3307 exit when C = ASCII.LF;
3308 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3309 Error_Msg_String (Error_Msg_Strlen) := C;
3310 end if;
3311 end loop;
3312
3313 -- Here with one line ready to go
3314
3315 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3316
3317 -- If this is a warning in a spec, then we want clients
3318 -- to see the warning, so mark the message with the
3319 -- special sequence !! to force the warning. In the case
3320 -- of a package spec, we do not force this if we are in
3321 -- the private part of the spec.
3322
3323 if Force then
3324 if Cont = False then
3325 Error_Msg_N ("<~!!", Arg1);
3326 Cont := True;
3327 else
3328 Error_Msg_N ("\<~!!", Arg1);
3329 end if;
3330
3331 -- Error, rather than warning, or in a body, so we do not
3332 -- need to force visibility for client (error will be
3333 -- output in any case, and this is the situation in which
3334 -- we do not want a client to get a warning, since the
3335 -- warning is in the body or the spec private part).
3336
3337 else
3338 if Cont = False then
3339 Error_Msg_N ("<~", Arg1);
3340 Cont := True;
3341 else
3342 Error_Msg_N ("\<~", Arg1);
3343 end if;
3344 end if;
3345
3346 exit when Ptr > Len;
3347 end loop;
3348 end;
3349 end if;
3350 end if;
3351 end Process_Compile_Time_Warning_Or_Error;
3352
3353 ------------------------
3354 -- Process_Convention --
3355 ------------------------
3356
3357 procedure Process_Convention
3358 (C : out Convention_Id;
3359 Ent : out Entity_Id)
3360 is
3361 Id : Node_Id;
3362 E : Entity_Id;
3363 E1 : Entity_Id;
3364 Cname : Name_Id;
3365 Comp_Unit : Unit_Number_Type;
3366
3367 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3368 -- Called if we have more than one Export/Import/Convention pragma.
3369 -- This is generally illegal, but we have a special case of allowing
3370 -- Import and Interface to coexist if they specify the convention in
3371 -- a consistent manner. We are allowed to do this, since Interface is
3372 -- an implementation defined pragma, and we choose to do it since we
3373 -- know Rational allows this combination. S is the entity id of the
3374 -- subprogram in question. This procedure also sets the special flag
3375 -- Import_Interface_Present in both pragmas in the case where we do
3376 -- have matching Import and Interface pragmas.
3377
3378 procedure Set_Convention_From_Pragma (E : Entity_Id);
3379 -- Set convention in entity E, and also flag that the entity has a
3380 -- convention pragma. If entity is for a private or incomplete type,
3381 -- also set convention and flag on underlying type. This procedure
3382 -- also deals with the special case of C_Pass_By_Copy convention.
3383
3384 -------------------------------
3385 -- Diagnose_Multiple_Pragmas --
3386 -------------------------------
3387
3388 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3389 Pdec : constant Node_Id := Declaration_Node (S);
3390 Decl : Node_Id;
3391 Err : Boolean;
3392
3393 function Same_Convention (Decl : Node_Id) return Boolean;
3394 -- Decl is a pragma node. This function returns True if this
3395 -- pragma has a first argument that is an identifier with a
3396 -- Chars field corresponding to the Convention_Id C.
3397
3398 function Same_Name (Decl : Node_Id) return Boolean;
3399 -- Decl is a pragma node. This function returns True if this
3400 -- pragma has a second argument that is an identifier with a
3401 -- Chars field that matches the Chars of the current subprogram.
3402
3403 ---------------------
3404 -- Same_Convention --
3405 ---------------------
3406
3407 function Same_Convention (Decl : Node_Id) return Boolean is
3408 Arg1 : constant Node_Id :=
3409 First (Pragma_Argument_Associations (Decl));
3410
3411 begin
3412 if Present (Arg1) then
3413 declare
3414 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3415 begin
3416 if Nkind (Arg) = N_Identifier
3417 and then Is_Convention_Name (Chars (Arg))
3418 and then Get_Convention_Id (Chars (Arg)) = C
3419 then
3420 return True;
3421 end if;
3422 end;
3423 end if;
3424
3425 return False;
3426 end Same_Convention;
3427
3428 ---------------
3429 -- Same_Name --
3430 ---------------
3431
3432 function Same_Name (Decl : Node_Id) return Boolean is
3433 Arg1 : constant Node_Id :=
3434 First (Pragma_Argument_Associations (Decl));
3435 Arg2 : Node_Id;
3436
3437 begin
3438 if No (Arg1) then
3439 return False;
3440 end if;
3441
3442 Arg2 := Next (Arg1);
3443
3444 if No (Arg2) then
3445 return False;
3446 end if;
3447
3448 declare
3449 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3450 begin
3451 if Nkind (Arg) = N_Identifier
3452 and then Chars (Arg) = Chars (S)
3453 then
3454 return True;
3455 end if;
3456 end;
3457
3458 return False;
3459 end Same_Name;
3460
3461 -- Start of processing for Diagnose_Multiple_Pragmas
3462
3463 begin
3464 Err := True;
3465
3466 -- Definitely give message if we have Convention/Export here
3467
3468 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3469 null;
3470
3471 -- If we have an Import or Export, scan back from pragma to
3472 -- find any previous pragma applying to the same procedure.
3473 -- The scan will be terminated by the start of the list, or
3474 -- hitting the subprogram declaration. This won't allow one
3475 -- pragma to appear in the public part and one in the private
3476 -- part, but that seems very unlikely in practice.
3477
3478 else
3479 Decl := Prev (N);
3480 while Present (Decl) and then Decl /= Pdec loop
3481
3482 -- Look for pragma with same name as us
3483
3484 if Nkind (Decl) = N_Pragma
3485 and then Same_Name (Decl)
3486 then
3487 -- Give error if same as our pragma or Export/Convention
3488
3489 if Pragma_Name (Decl) = Name_Export
3490 or else
3491 Pragma_Name (Decl) = Name_Convention
3492 or else
3493 Pragma_Name (Decl) = Pragma_Name (N)
3494 then
3495 exit;
3496
3497 -- Case of Import/Interface or the other way round
3498
3499 elsif Pragma_Name (Decl) = Name_Interface
3500 or else
3501 Pragma_Name (Decl) = Name_Import
3502 then
3503 -- Here we know that we have Import and Interface. It
3504 -- doesn't matter which way round they are. See if
3505 -- they specify the same convention. If so, all OK,
3506 -- and set special flags to stop other messages
3507
3508 if Same_Convention (Decl) then
3509 Set_Import_Interface_Present (N);
3510 Set_Import_Interface_Present (Decl);
3511 Err := False;
3512
3513 -- If different conventions, special message
3514
3515 else
3516 Error_Msg_Sloc := Sloc (Decl);
3517 Error_Pragma_Arg
3518 ("convention differs from that given#", Arg1);
3519 return;
3520 end if;
3521 end if;
3522 end if;
3523
3524 Next (Decl);
3525 end loop;
3526 end if;
3527
3528 -- Give message if needed if we fall through those tests
3529 -- except on Relaxed_RM_Semantics where we let go: either this
3530 -- is a case accepted/ignored by other Ada compilers (e.g.
3531 -- a mix of Convention and Import), or another error will be
3532 -- generated later (e.g. using both Import and Export).
3533
3534 if Err and not Relaxed_RM_Semantics then
3535 Error_Pragma_Arg
3536 ("at most one Convention/Export/Import pragma is allowed",
3537 Arg2);
3538 end if;
3539 end Diagnose_Multiple_Pragmas;
3540
3541 --------------------------------
3542 -- Set_Convention_From_Pragma --
3543 --------------------------------
3544
3545 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3546 begin
3547 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3548 -- for an overridden dispatching operation. Technically this is
3549 -- an amendment and should only be done in Ada 2005 mode. However,
3550 -- this is clearly a mistake, since the problem that is addressed
3551 -- by this AI is that there is a clear gap in the RM!
3552
3553 if Is_Dispatching_Operation (E)
3554 and then Present (Overridden_Operation (E))
3555 and then C /= Convention (Overridden_Operation (E))
3556 then
3557 Error_Pragma_Arg
3558 ("cannot change convention for overridden dispatching "
3559 & "operation", Arg1);
3560 end if;
3561
3562 -- Set the convention
3563
3564 Set_Convention (E, C);
3565 Set_Has_Convention_Pragma (E);
3566
3567 if Is_Incomplete_Or_Private_Type (E)
3568 and then Present (Underlying_Type (E))
3569 then
3570 Set_Convention (Underlying_Type (E), C);
3571 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3572 end if;
3573
3574 -- A class-wide type should inherit the convention of the specific
3575 -- root type (although this isn't specified clearly by the RM).
3576
3577 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3578 Set_Convention (Class_Wide_Type (E), C);
3579 end if;
3580
3581 -- If the entity is a record type, then check for special case of
3582 -- C_Pass_By_Copy, which is treated the same as C except that the
3583 -- special record flag is set. This convention is only permitted
3584 -- on record types (see AI95-00131).
3585
3586 if Cname = Name_C_Pass_By_Copy then
3587 if Is_Record_Type (E) then
3588 Set_C_Pass_By_Copy (Base_Type (E));
3589 elsif Is_Incomplete_Or_Private_Type (E)
3590 and then Is_Record_Type (Underlying_Type (E))
3591 then
3592 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3593 else
3594 Error_Pragma_Arg
3595 ("C_Pass_By_Copy convention allowed only for record type",
3596 Arg2);
3597 end if;
3598 end if;
3599
3600 -- If the entity is a derived boolean type, check for the special
3601 -- case of convention C, C++, or Fortran, where we consider any
3602 -- nonzero value to represent true.
3603
3604 if Is_Discrete_Type (E)
3605 and then Root_Type (Etype (E)) = Standard_Boolean
3606 and then
3607 (C = Convention_C
3608 or else
3609 C = Convention_CPP
3610 or else
3611 C = Convention_Fortran)
3612 then
3613 Set_Nonzero_Is_True (Base_Type (E));
3614 end if;
3615 end Set_Convention_From_Pragma;
3616
3617 -- Start of processing for Process_Convention
3618
3619 begin
3620 Check_At_Least_N_Arguments (2);
3621 Check_Optional_Identifier (Arg1, Name_Convention);
3622 Check_Arg_Is_Identifier (Arg1);
3623 Cname := Chars (Get_Pragma_Arg (Arg1));
3624
3625 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3626 -- tested again below to set the critical flag).
3627
3628 if Cname = Name_C_Pass_By_Copy then
3629 C := Convention_C;
3630
3631 -- Otherwise we must have something in the standard convention list
3632
3633 elsif Is_Convention_Name (Cname) then
3634 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3635
3636 -- In DEC VMS, it seems that there is an undocumented feature that
3637 -- any unrecognized convention is treated as the default, which for
3638 -- us is convention C. It does not seem so terrible to do this
3639 -- unconditionally, silently in the VMS case, and with a warning
3640 -- in the non-VMS case.
3641
3642 else
3643 if Warn_On_Export_Import and not OpenVMS_On_Target then
3644 Error_Msg_N
3645 ("??unrecognized convention name, C assumed",
3646 Get_Pragma_Arg (Arg1));
3647 end if;
3648
3649 C := Convention_C;
3650 end if;
3651
3652 Check_Optional_Identifier (Arg2, Name_Entity);
3653 Check_Arg_Is_Local_Name (Arg2);
3654
3655 Id := Get_Pragma_Arg (Arg2);
3656 Analyze (Id);
3657
3658 if not Is_Entity_Name (Id) then
3659 Error_Pragma_Arg ("entity name required", Arg2);
3660 end if;
3661
3662 E := Entity (Id);
3663
3664 -- Set entity to return
3665
3666 Ent := E;
3667
3668 -- Ada_Pass_By_Copy special checking
3669
3670 if C = Convention_Ada_Pass_By_Copy then
3671 if not Is_First_Subtype (E) then
3672 Error_Pragma_Arg
3673 ("convention `Ada_Pass_By_Copy` only "
3674 & "allowed for types", Arg2);
3675 end if;
3676
3677 if Is_By_Reference_Type (E) then
3678 Error_Pragma_Arg
3679 ("convention `Ada_Pass_By_Copy` not allowed for "
3680 & "by-reference type", Arg1);
3681 end if;
3682 end if;
3683
3684 -- Ada_Pass_By_Reference special checking
3685
3686 if C = Convention_Ada_Pass_By_Reference then
3687 if not Is_First_Subtype (E) then
3688 Error_Pragma_Arg
3689 ("convention `Ada_Pass_By_Reference` only "
3690 & "allowed for types", Arg2);
3691 end if;
3692
3693 if Is_By_Copy_Type (E) then
3694 Error_Pragma_Arg
3695 ("convention `Ada_Pass_By_Reference` not allowed for "
3696 & "by-copy type", Arg1);
3697 end if;
3698 end if;
3699
3700 -- Go to renamed subprogram if present, since convention applies to
3701 -- the actual renamed entity, not to the renaming entity. If the
3702 -- subprogram is inherited, go to parent subprogram.
3703
3704 if Is_Subprogram (E)
3705 and then Present (Alias (E))
3706 then
3707 if Nkind (Parent (Declaration_Node (E))) =
3708 N_Subprogram_Renaming_Declaration
3709 then
3710 if Scope (E) /= Scope (Alias (E)) then
3711 Error_Pragma_Ref
3712 ("cannot apply pragma% to non-local entity&#", E);
3713 end if;
3714
3715 E := Alias (E);
3716
3717 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3718 N_Private_Extension_Declaration)
3719 and then Scope (E) = Scope (Alias (E))
3720 then
3721 E := Alias (E);
3722
3723 -- Return the parent subprogram the entity was inherited from
3724
3725 Ent := E;
3726 end if;
3727 end if;
3728
3729 -- Check that we are not applying this to a specless body
3730 -- Relax this check if Relaxed_RM_Semantics to accomodate other Ada
3731 -- compilers.
3732
3733 if Is_Subprogram (E)
3734 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3735 and then not Relaxed_RM_Semantics
3736 then
3737 Error_Pragma
3738 ("pragma% requires separate spec and must come before body");
3739 end if;
3740
3741 -- Check that we are not applying this to a named constant
3742
3743 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3744 Error_Msg_Name_1 := Pname;
3745 Error_Msg_N
3746 ("cannot apply pragma% to named constant!",
3747 Get_Pragma_Arg (Arg2));
3748 Error_Pragma_Arg
3749 ("\supply appropriate type for&!", Arg2);
3750 end if;
3751
3752 if Ekind (E) = E_Enumeration_Literal then
3753 Error_Pragma ("enumeration literal not allowed for pragma%");
3754 end if;
3755
3756 -- Check for rep item appearing too early or too late
3757
3758 if Etype (E) = Any_Type
3759 or else Rep_Item_Too_Early (E, N)
3760 then
3761 raise Pragma_Exit;
3762
3763 elsif Present (Underlying_Type (E)) then
3764 E := Underlying_Type (E);
3765 end if;
3766
3767 if Rep_Item_Too_Late (E, N) then
3768 raise Pragma_Exit;
3769 end if;
3770
3771 if Has_Convention_Pragma (E) then
3772 Diagnose_Multiple_Pragmas (E);
3773
3774 elsif Convention (E) = Convention_Protected
3775 or else Ekind (Scope (E)) = E_Protected_Type
3776 then
3777 Error_Pragma_Arg
3778 ("a protected operation cannot be given a different convention",
3779 Arg2);
3780 end if;
3781
3782 -- For Intrinsic, a subprogram is required
3783
3784 if C = Convention_Intrinsic
3785 and then not Is_Subprogram (E)
3786 and then not Is_Generic_Subprogram (E)
3787 then
3788 Error_Pragma_Arg
3789 ("second argument of pragma% must be a subprogram", Arg2);
3790 end if;
3791
3792 -- Stdcall case
3793
3794 if C = Convention_Stdcall then
3795
3796 -- A dispatching call is not allowed. A dispatching subprogram
3797 -- cannot be used to interface to the Win32 API, so in fact this
3798 -- check does not impose any effective restriction.
3799
3800 if Is_Dispatching_Operation (E) then
3801
3802 Error_Pragma
3803 ("dispatching subprograms cannot use Stdcall convention");
3804
3805 -- Subprogram is allowed, but not a generic subprogram, and not a
3806 -- dispatching operation.
3807
3808 elsif not Is_Subprogram (E)
3809 and then not Is_Generic_Subprogram (E)
3810
3811 -- A variable is OK
3812
3813 and then Ekind (E) /= E_Variable
3814
3815 -- An access to subprogram is also allowed
3816
3817 and then not
3818 (Is_Access_Type (E)
3819 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3820 then
3821 Error_Pragma_Arg
3822 ("second argument of pragma% must be subprogram (type)",
3823 Arg2);
3824 end if;
3825 end if;
3826
3827 if not Is_Subprogram (E)
3828 and then not Is_Generic_Subprogram (E)
3829 then
3830 Set_Convention_From_Pragma (E);
3831
3832 if Is_Type (E) then
3833 Check_First_Subtype (Arg2);
3834 Set_Convention_From_Pragma (Base_Type (E));
3835
3836 -- For subprograms, we must set the convention on the
3837 -- internally generated directly designated type as well.
3838
3839 if Ekind (E) = E_Access_Subprogram_Type then
3840 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3841 end if;
3842 end if;
3843
3844 -- For the subprogram case, set proper convention for all homonyms
3845 -- in same scope and the same declarative part, i.e. the same
3846 -- compilation unit.
3847
3848 else
3849 Comp_Unit := Get_Source_Unit (E);
3850 Set_Convention_From_Pragma (E);
3851
3852 -- Treat a pragma Import as an implicit body, and pragma import
3853 -- as implicit reference (for navigation in GPS).
3854
3855 if Prag_Id = Pragma_Import then
3856 Generate_Reference (E, Id, 'b');
3857
3858 -- For exported entities we restrict the generation of references
3859 -- to entities exported to foreign languages since entities
3860 -- exported to Ada do not provide further information to GPS and
3861 -- add undesired references to the output of the gnatxref tool.
3862
3863 elsif Prag_Id = Pragma_Export
3864 and then Convention (E) /= Convention_Ada
3865 then
3866 Generate_Reference (E, Id, 'i');
3867 end if;
3868
3869 -- If the pragma comes from from an aspect, it only applies
3870 -- to the given entity, not its homonyms.
3871
3872 if From_Aspect_Specification (N) then
3873 return;
3874 end if;
3875
3876 -- Otherwise Loop through the homonyms of the pragma argument's
3877 -- entity, an apply convention to those in the current scope.
3878
3879 E1 := Ent;
3880
3881 loop
3882 E1 := Homonym (E1);
3883 exit when No (E1) or else Scope (E1) /= Current_Scope;
3884
3885 -- Do not set the pragma on inherited operations or on formal
3886 -- subprograms.
3887
3888 if Comes_From_Source (E1)
3889 and then Comp_Unit = Get_Source_Unit (E1)
3890 and then not Is_Formal_Subprogram (E1)
3891 and then Nkind (Original_Node (Parent (E1))) /=
3892 N_Full_Type_Declaration
3893 then
3894 if Present (Alias (E1))
3895 and then Scope (E1) /= Scope (Alias (E1))
3896 then
3897 Error_Pragma_Ref
3898 ("cannot apply pragma% to non-local entity& declared#",
3899 E1);
3900 end if;
3901
3902 Set_Convention_From_Pragma (E1);
3903
3904 if Prag_Id = Pragma_Import then
3905 Generate_Reference (E1, Id, 'b');
3906 end if;
3907 end if;
3908 end loop;
3909 end if;
3910 end Process_Convention;
3911
3912 ----------------------------------------
3913 -- Process_Disable_Enable_Atomic_Sync --
3914 ----------------------------------------
3915
3916 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3917 begin
3918 GNAT_Pragma;
3919 Check_No_Identifiers;
3920 Check_At_Most_N_Arguments (1);
3921
3922 -- Modeled internally as
3923 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
3924
3925 Rewrite (N,
3926 Make_Pragma (Loc,
3927 Pragma_Identifier =>
3928 Make_Identifier (Loc, Nam),
3929 Pragma_Argument_Associations => New_List (
3930 Make_Pragma_Argument_Association (Loc,
3931 Expression =>
3932 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3933
3934 if Present (Arg1) then
3935 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3936 end if;
3937
3938 Analyze (N);
3939 end Process_Disable_Enable_Atomic_Sync;
3940
3941 -----------------------------------------------------
3942 -- Process_Extended_Import_Export_Exception_Pragma --
3943 -----------------------------------------------------
3944
3945 procedure Process_Extended_Import_Export_Exception_Pragma
3946 (Arg_Internal : Node_Id;
3947 Arg_External : Node_Id;
3948 Arg_Form : Node_Id;
3949 Arg_Code : Node_Id)
3950 is
3951 Def_Id : Entity_Id;
3952 Code_Val : Uint;
3953
3954 begin
3955 if not OpenVMS_On_Target then
3956 Error_Pragma
3957 ("??pragma% ignored (applies only to Open'V'M'S)");
3958 end if;
3959
3960 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3961 Def_Id := Entity (Arg_Internal);
3962
3963 if Ekind (Def_Id) /= E_Exception then
3964 Error_Pragma_Arg
3965 ("pragma% must refer to declared exception", Arg_Internal);
3966 end if;
3967
3968 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3969
3970 if Present (Arg_Form) then
3971 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3972 end if;
3973
3974 if Present (Arg_Form)
3975 and then Chars (Arg_Form) = Name_Ada
3976 then
3977 null;
3978 else
3979 Set_Is_VMS_Exception (Def_Id);
3980 Set_Exception_Code (Def_Id, No_Uint);
3981 end if;
3982
3983 if Present (Arg_Code) then
3984 if not Is_VMS_Exception (Def_Id) then
3985 Error_Pragma_Arg
3986 ("Code option for pragma% not allowed for Ada case",
3987 Arg_Code);
3988 end if;
3989
3990 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3991 Code_Val := Expr_Value (Arg_Code);
3992
3993 if not UI_Is_In_Int_Range (Code_Val) then
3994 Error_Pragma_Arg
3995 ("Code option for pragma% must be in 32-bit range",
3996 Arg_Code);
3997
3998 else
3999 Set_Exception_Code (Def_Id, Code_Val);
4000 end if;
4001 end if;
4002 end Process_Extended_Import_Export_Exception_Pragma;
4003
4004 -------------------------------------------------
4005 -- Process_Extended_Import_Export_Internal_Arg --
4006 -------------------------------------------------
4007
4008 procedure Process_Extended_Import_Export_Internal_Arg
4009 (Arg_Internal : Node_Id := Empty)
4010 is
4011 begin
4012 if No (Arg_Internal) then
4013 Error_Pragma ("Internal parameter required for pragma%");
4014 end if;
4015
4016 if Nkind (Arg_Internal) = N_Identifier then
4017 null;
4018
4019 elsif Nkind (Arg_Internal) = N_Operator_Symbol
4020 and then (Prag_Id = Pragma_Import_Function
4021 or else
4022 Prag_Id = Pragma_Export_Function)
4023 then
4024 null;
4025
4026 else
4027 Error_Pragma_Arg
4028 ("wrong form for Internal parameter for pragma%", Arg_Internal);
4029 end if;
4030
4031 Check_Arg_Is_Local_Name (Arg_Internal);
4032 end Process_Extended_Import_Export_Internal_Arg;
4033
4034 --------------------------------------------------
4035 -- Process_Extended_Import_Export_Object_Pragma --
4036 --------------------------------------------------
4037
4038 procedure Process_Extended_Import_Export_Object_Pragma
4039 (Arg_Internal : Node_Id;
4040 Arg_External : Node_Id;
4041 Arg_Size : Node_Id)
4042 is
4043 Def_Id : Entity_Id;
4044
4045 begin
4046 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
4047 Def_Id := Entity (Arg_Internal);
4048
4049 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
4050 Error_Pragma_Arg
4051 ("pragma% must designate an object", Arg_Internal);
4052 end if;
4053
4054 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
4055 or else
4056 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
4057 then
4058 Error_Pragma_Arg
4059 ("previous Common/Psect_Object applies, pragma % not permitted",
4060 Arg_Internal);
4061 end if;
4062
4063 if Rep_Item_Too_Late (Def_Id, N) then
4064 raise Pragma_Exit;
4065 end if;
4066
4067 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
4068
4069 if Present (Arg_Size) then
4070 Check_Arg_Is_External_Name (Arg_Size);
4071 end if;
4072
4073 -- Export_Object case
4074
4075 if Prag_Id = Pragma_Export_Object then
4076 if not Is_Library_Level_Entity (Def_Id) then
4077 Error_Pragma_Arg
4078 ("argument for pragma% must be library level entity",
4079 Arg_Internal);
4080 end if;
4081
4082 if Ekind (Current_Scope) = E_Generic_Package then
4083 Error_Pragma ("pragma& cannot appear in a generic unit");
4084 end if;
4085
4086 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
4087 Error_Pragma_Arg
4088 ("exported object must have compile time known size",
4089 Arg_Internal);
4090 end if;
4091
4092 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
4093 Error_Msg_N ("??duplicate Export_Object pragma", N);
4094 else
4095 Set_Exported (Def_Id, Arg_Internal);
4096 end if;
4097
4098 -- Import_Object case
4099
4100 else
4101 if Is_Concurrent_Type (Etype (Def_Id)) then
4102 Error_Pragma_Arg
4103 ("cannot use pragma% for task/protected object",
4104 Arg_Internal);
4105 end if;
4106
4107 if Ekind (Def_Id) = E_Constant then
4108 Error_Pragma_Arg
4109 ("cannot import a constant", Arg_Internal);
4110 end if;
4111
4112 if Warn_On_Export_Import
4113 and then Has_Discriminants (Etype (Def_Id))
4114 then
4115 Error_Msg_N
4116 ("imported value must be initialized??", Arg_Internal);
4117 end if;
4118
4119 if Warn_On_Export_Import
4120 and then Is_Access_Type (Etype (Def_Id))
4121 then
4122 Error_Pragma_Arg
4123 ("cannot import object of an access type??", Arg_Internal);
4124 end if;
4125
4126 if Warn_On_Export_Import
4127 and then Is_Imported (Def_Id)
4128 then
4129 Error_Msg_N ("??duplicate Import_Object pragma", N);
4130
4131 -- Check for explicit initialization present. Note that an
4132 -- initialization generated by the code generator, e.g. for an
4133 -- access type, does not count here.
4134
4135 elsif Present (Expression (Parent (Def_Id)))
4136 and then
4137 Comes_From_Source
4138 (Original_Node (Expression (Parent (Def_Id))))
4139 then
4140 Error_Msg_Sloc := Sloc (Def_Id);
4141 Error_Pragma_Arg
4142 ("imported entities cannot be initialized (RM B.1(24))",
4143 "\no initialization allowed for & declared#", Arg1);
4144 else
4145 Set_Imported (Def_Id);
4146 Note_Possible_Modification (Arg_Internal, Sure => False);
4147 end if;
4148 end if;
4149 end Process_Extended_Import_Export_Object_Pragma;
4150
4151 ------------------------------------------------------
4152 -- Process_Extended_Import_Export_Subprogram_Pragma --
4153 ------------------------------------------------------
4154
4155 procedure Process_Extended_Import_Export_Subprogram_Pragma
4156 (Arg_Internal : Node_Id;
4157 Arg_External : Node_Id;
4158 Arg_Parameter_Types : Node_Id;
4159 Arg_Result_Type : Node_Id := Empty;
4160 Arg_Mechanism : Node_Id;
4161 Arg_Result_Mechanism : Node_Id := Empty;
4162 Arg_First_Optional_Parameter : Node_Id := Empty)
4163 is
4164 Ent : Entity_Id;
4165 Def_Id : Entity_Id;
4166 Hom_Id : Entity_Id;
4167 Formal : Entity_Id;
4168 Ambiguous : Boolean;
4169 Match : Boolean;
4170 Dval : Node_Id;
4171
4172 function Same_Base_Type
4173 (Ptype : Node_Id;
4174 Formal : Entity_Id) return Boolean;
4175 -- Determines if Ptype references the type of Formal. Note that only
4176 -- the base types need to match according to the spec. Ptype here is
4177 -- the argument from the pragma, which is either a type name, or an
4178 -- access attribute.
4179
4180 --------------------
4181 -- Same_Base_Type --
4182 --------------------
4183
4184 function Same_Base_Type
4185 (Ptype : Node_Id;
4186 Formal : Entity_Id) return Boolean
4187 is
4188 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
4189 Pref : Node_Id;
4190
4191 begin
4192 -- Case where pragma argument is typ'Access
4193
4194 if Nkind (Ptype) = N_Attribute_Reference
4195 and then Attribute_Name (Ptype) = Name_Access
4196 then
4197 Pref := Prefix (Ptype);
4198 Find_Type (Pref);
4199
4200 if not Is_Entity_Name (Pref)
4201 or else Entity (Pref) = Any_Type
4202 then
4203 raise Pragma_Exit;
4204 end if;
4205
4206 -- We have a match if the corresponding argument is of an
4207 -- anonymous access type, and its designated type matches the
4208 -- type of the prefix of the access attribute
4209
4210 return Ekind (Ftyp) = E_Anonymous_Access_Type
4211 and then Base_Type (Entity (Pref)) =
4212 Base_Type (Etype (Designated_Type (Ftyp)));
4213
4214 -- Case where pragma argument is a type name
4215
4216 else
4217 Find_Type (Ptype);
4218
4219 if not Is_Entity_Name (Ptype)
4220 or else Entity (Ptype) = Any_Type
4221 then
4222 raise Pragma_Exit;
4223 end if;
4224
4225 -- We have a match if the corresponding argument is of the type
4226 -- given in the pragma (comparing base types)
4227
4228 return Base_Type (Entity (Ptype)) = Ftyp;
4229 end if;
4230 end Same_Base_Type;
4231
4232 -- Start of processing for
4233 -- Process_Extended_Import_Export_Subprogram_Pragma
4234
4235 begin
4236 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
4237 Ent := Empty;
4238 Ambiguous := False;
4239
4240 -- Loop through homonyms (overloadings) of the entity
4241
4242 Hom_Id := Entity (Arg_Internal);
4243 while Present (Hom_Id) loop
4244 Def_Id := Get_Base_Subprogram (Hom_Id);
4245
4246 -- We need a subprogram in the current scope
4247
4248 if not Is_Subprogram (Def_Id)
4249 or else Scope (Def_Id) /= Current_Scope
4250 then
4251 null;
4252
4253 else
4254 Match := True;
4255
4256 -- Pragma cannot apply to subprogram body
4257
4258 if Is_Subprogram (Def_Id)
4259 and then Nkind (Parent (Declaration_Node (Def_Id))) =
4260 N_Subprogram_Body
4261 then
4262 Error_Pragma
4263 ("pragma% requires separate spec"
4264 & " and must come before body");
4265 end if;
4266
4267 -- Test result type if given, note that the result type
4268 -- parameter can only be present for the function cases.
4269
4270 if Present (Arg_Result_Type)
4271 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
4272 then
4273 Match := False;
4274
4275 elsif Etype (Def_Id) /= Standard_Void_Type
4276 and then
4277 (Pname = Name_Export_Procedure
4278 or else
4279 Pname = Name_Import_Procedure)
4280 then
4281 Match := False;
4282
4283 -- Test parameter types if given. Note that this parameter
4284 -- has not been analyzed (and must not be, since it is
4285 -- semantic nonsense), so we get it as the parser left it.
4286
4287 elsif Present (Arg_Parameter_Types) then
4288 Check_Matching_Types : declare
4289 Formal : Entity_Id;
4290 Ptype : Node_Id;
4291
4292 begin
4293 Formal := First_Formal (Def_Id);
4294
4295 if Nkind (Arg_Parameter_Types) = N_Null then
4296 if Present (Formal) then
4297 Match := False;
4298 end if;
4299
4300 -- A list of one type, e.g. (List) is parsed as
4301 -- a parenthesized expression.
4302
4303 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4304 and then Paren_Count (Arg_Parameter_Types) = 1
4305 then
4306 if No (Formal)
4307 or else Present (Next_Formal (Formal))
4308 then
4309 Match := False;
4310 else
4311 Match :=
4312 Same_Base_Type (Arg_Parameter_Types, Formal);
4313 end if;
4314
4315 -- A list of more than one type is parsed as a aggregate
4316
4317 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4318 and then Paren_Count (Arg_Parameter_Types) = 0
4319 then
4320 Ptype := First (Expressions (Arg_Parameter_Types));
4321 while Present (Ptype) or else Present (Formal) loop
4322 if No (Ptype)
4323 or else No (Formal)
4324 or else not Same_Base_Type (Ptype, Formal)
4325 then
4326 Match := False;
4327 exit;
4328 else
4329 Next_Formal (Formal);
4330 Next (Ptype);
4331 end if;
4332 end loop;
4333
4334 -- Anything else is of the wrong form
4335
4336 else
4337 Error_Pragma_Arg
4338 ("wrong form for Parameter_Types parameter",
4339 Arg_Parameter_Types);
4340 end if;
4341 end Check_Matching_Types;
4342 end if;
4343
4344 -- Match is now False if the entry we found did not match
4345 -- either a supplied Parameter_Types or Result_Types argument
4346
4347 if Match then
4348 if No (Ent) then
4349 Ent := Def_Id;
4350
4351 -- Ambiguous case, the flag Ambiguous shows if we already
4352 -- detected this and output the initial messages.
4353
4354 else
4355 if not Ambiguous then
4356 Ambiguous := True;
4357 Error_Msg_Name_1 := Pname;
4358 Error_Msg_N
4359 ("pragma% does not uniquely identify subprogram!",
4360 N);
4361 Error_Msg_Sloc := Sloc (Ent);
4362 Error_Msg_N ("matching subprogram #!", N);
4363 Ent := Empty;
4364 end if;
4365
4366 Error_Msg_Sloc := Sloc (Def_Id);
4367 Error_Msg_N ("matching subprogram #!", N);
4368 end if;
4369 end if;
4370 end if;
4371
4372 Hom_Id := Homonym (Hom_Id);
4373 end loop;
4374
4375 -- See if we found an entry
4376
4377 if No (Ent) then
4378 if not Ambiguous then
4379 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4380 Error_Pragma
4381 ("pragma% cannot be given for generic subprogram");
4382 else
4383 Error_Pragma
4384 ("pragma% does not identify local subprogram");
4385 end if;
4386 end if;
4387
4388 return;
4389 end if;
4390
4391 -- Import pragmas must be for imported entities
4392
4393 if Prag_Id = Pragma_Import_Function
4394 or else
4395 Prag_Id = Pragma_Import_Procedure
4396 or else
4397 Prag_Id = Pragma_Import_Valued_Procedure
4398 then
4399 if not Is_Imported (Ent) then
4400 Error_Pragma
4401 ("pragma Import or Interface must precede pragma%");
4402 end if;
4403
4404 -- Here we have the Export case which can set the entity as exported
4405
4406 -- But does not do so if the specified external name is null, since
4407 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4408 -- compatible) to request no external name.
4409
4410 elsif Nkind (Arg_External) = N_String_Literal
4411 and then String_Length (Strval (Arg_External)) = 0
4412 then
4413 null;
4414
4415 -- In all other cases, set entity as exported
4416
4417 else
4418 Set_Exported (Ent, Arg_Internal);
4419 end if;
4420
4421 -- Special processing for Valued_Procedure cases
4422
4423 if Prag_Id = Pragma_Import_Valued_Procedure
4424 or else
4425 Prag_Id = Pragma_Export_Valued_Procedure
4426 then
4427 Formal := First_Formal (Ent);
4428
4429 if No (Formal) then
4430 Error_Pragma ("at least one parameter required for pragma%");
4431
4432 elsif Ekind (Formal) /= E_Out_Parameter then
4433 Error_Pragma ("first parameter must have mode out for pragma%");
4434
4435 else
4436 Set_Is_Valued_Procedure (Ent);
4437 end if;
4438 end if;
4439
4440 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4441
4442 -- Process Result_Mechanism argument if present. We have already
4443 -- checked that this is only allowed for the function case.
4444
4445 if Present (Arg_Result_Mechanism) then
4446 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4447 end if;
4448
4449 -- Process Mechanism parameter if present. Note that this parameter
4450 -- is not analyzed, and must not be analyzed since it is semantic
4451 -- nonsense, so we get it in exactly as the parser left it.
4452
4453 if Present (Arg_Mechanism) then
4454 declare
4455 Formal : Entity_Id;
4456 Massoc : Node_Id;
4457 Mname : Node_Id;
4458 Choice : Node_Id;
4459
4460 begin
4461 -- A single mechanism association without a formal parameter
4462 -- name is parsed as a parenthesized expression. All other
4463 -- cases are parsed as aggregates, so we rewrite the single
4464 -- parameter case as an aggregate for consistency.
4465
4466 if Nkind (Arg_Mechanism) /= N_Aggregate
4467 and then Paren_Count (Arg_Mechanism) = 1
4468 then
4469 Rewrite (Arg_Mechanism,
4470 Make_Aggregate (Sloc (Arg_Mechanism),
4471 Expressions => New_List (
4472 Relocate_Node (Arg_Mechanism))));
4473 end if;
4474
4475 -- Case of only mechanism name given, applies to all formals
4476
4477 if Nkind (Arg_Mechanism) /= N_Aggregate then
4478 Formal := First_Formal (Ent);
4479 while Present (Formal) loop
4480 Set_Mechanism_Value (Formal, Arg_Mechanism);
4481 Next_Formal (Formal);
4482 end loop;
4483
4484 -- Case of list of mechanism associations given
4485
4486 else
4487 if Null_Record_Present (Arg_Mechanism) then
4488 Error_Pragma_Arg
4489 ("inappropriate form for Mechanism parameter",
4490 Arg_Mechanism);
4491 end if;
4492
4493 -- Deal with positional ones first
4494
4495 Formal := First_Formal (Ent);
4496
4497 if Present (Expressions (Arg_Mechanism)) then
4498 Mname := First (Expressions (Arg_Mechanism));
4499 while Present (Mname) loop
4500 if No (Formal) then
4501 Error_Pragma_Arg
4502 ("too many mechanism associations", Mname);
4503 end if;
4504
4505 Set_Mechanism_Value (Formal, Mname);
4506 Next_Formal (Formal);
4507 Next (Mname);
4508 end loop;
4509 end if;
4510
4511 -- Deal with named entries
4512
4513 if Present (Component_Associations (Arg_Mechanism)) then
4514 Massoc := First (Component_Associations (Arg_Mechanism));
4515 while Present (Massoc) loop
4516 Choice := First (Choices (Massoc));
4517
4518 if Nkind (Choice) /= N_Identifier
4519 or else Present (Next (Choice))
4520 then
4521 Error_Pragma_Arg
4522 ("incorrect form for mechanism association",
4523 Massoc);
4524 end if;
4525
4526 Formal := First_Formal (Ent);
4527 loop
4528 if No (Formal) then
4529 Error_Pragma_Arg
4530 ("parameter name & not present", Choice);
4531 end if;
4532
4533 if Chars (Choice) = Chars (Formal) then
4534 Set_Mechanism_Value
4535 (Formal, Expression (Massoc));
4536
4537 -- Set entity on identifier (needed by ASIS)
4538
4539 Set_Entity (Choice, Formal);
4540
4541 exit;
4542 end if;
4543
4544 Next_Formal (Formal);
4545 end loop;
4546
4547 Next (Massoc);
4548 end loop;
4549 end if;
4550 end if;
4551 end;
4552 end if;
4553
4554 -- Process First_Optional_Parameter argument if present. We have
4555 -- already checked that this is only allowed for the Import case.
4556
4557 if Present (Arg_First_Optional_Parameter) then
4558 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4559 Error_Pragma_Arg
4560 ("first optional parameter must be formal parameter name",
4561 Arg_First_Optional_Parameter);
4562 end if;
4563
4564 Formal := First_Formal (Ent);
4565 loop
4566 if No (Formal) then
4567 Error_Pragma_Arg
4568 ("specified formal parameter& not found",
4569 Arg_First_Optional_Parameter);
4570 end if;
4571
4572 exit when Chars (Formal) =
4573 Chars (Arg_First_Optional_Parameter);
4574
4575 Next_Formal (Formal);
4576 end loop;
4577
4578 Set_First_Optional_Parameter (Ent, Formal);
4579
4580 -- Check specified and all remaining formals have right form
4581
4582 while Present (Formal) loop
4583 if Ekind (Formal) /= E_In_Parameter then
4584 Error_Msg_NE
4585 ("optional formal& is not of mode in!",
4586 Arg_First_Optional_Parameter, Formal);
4587
4588 else
4589 Dval := Default_Value (Formal);
4590
4591 if No (Dval) then
4592 Error_Msg_NE
4593 ("optional formal& does not have default value!",
4594 Arg_First_Optional_Parameter, Formal);
4595
4596 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4597 null;
4598
4599 else
4600 Error_Msg_FE
4601 ("default value for optional formal& is non-static!",
4602 Arg_First_Optional_Parameter, Formal);
4603 end if;
4604 end if;
4605
4606 Set_Is_Optional_Parameter (Formal);
4607 Next_Formal (Formal);
4608 end loop;
4609 end if;
4610 end Process_Extended_Import_Export_Subprogram_Pragma;
4611
4612 --------------------------
4613 -- Process_Generic_List --
4614 --------------------------
4615
4616 procedure Process_Generic_List is
4617 Arg : Node_Id;
4618 Exp : Node_Id;
4619
4620 begin
4621 Check_No_Identifiers;
4622 Check_At_Least_N_Arguments (1);
4623
4624 Arg := Arg1;
4625 while Present (Arg) loop
4626 Exp := Get_Pragma_Arg (Arg);
4627 Analyze (Exp);
4628
4629 if not Is_Entity_Name (Exp)
4630 or else
4631 (not Is_Generic_Instance (Entity (Exp))
4632 and then
4633 not Is_Generic_Unit (Entity (Exp)))
4634 then
4635 Error_Pragma_Arg
4636 ("pragma% argument must be name of generic unit/instance",
4637 Arg);
4638 end if;
4639
4640 Next (Arg);
4641 end loop;
4642 end Process_Generic_List;
4643
4644 ------------------------------------
4645 -- Process_Import_Predefined_Type --
4646 ------------------------------------
4647
4648 procedure Process_Import_Predefined_Type is
4649 Loc : constant Source_Ptr := Sloc (N);
4650 Elmt : Elmt_Id;
4651 Ftyp : Node_Id := Empty;
4652 Decl : Node_Id;
4653 Def : Node_Id;
4654 Nam : Name_Id;
4655
4656 begin
4657 String_To_Name_Buffer (Strval (Expression (Arg3)));
4658 Nam := Name_Find;
4659
4660 Elmt := First_Elmt (Predefined_Float_Types);
4661 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4662 Next_Elmt (Elmt);
4663 end loop;
4664
4665 Ftyp := Node (Elmt);
4666
4667 if Present (Ftyp) then
4668
4669 -- Don't build a derived type declaration, because predefined C
4670 -- types have no declaration anywhere, so cannot really be named.
4671 -- Instead build a full type declaration, starting with an
4672 -- appropriate type definition is built
4673
4674 if Is_Floating_Point_Type (Ftyp) then
4675 Def := Make_Floating_Point_Definition (Loc,
4676 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4677 Make_Real_Range_Specification (Loc,
4678 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4679 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4680
4681 -- Should never have a predefined type we cannot handle
4682
4683 else
4684 raise Program_Error;
4685 end if;
4686
4687 -- Build and insert a Full_Type_Declaration, which will be
4688 -- analyzed as soon as this list entry has been analyzed.
4689
4690 Decl := Make_Full_Type_Declaration (Loc,
4691 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4692 Type_Definition => Def);
4693
4694 Insert_After (N, Decl);
4695 Mark_Rewrite_Insertion (Decl);
4696
4697 else
4698 Error_Pragma_Arg ("no matching type found for pragma%",
4699 Arg2);
4700 end if;
4701 end Process_Import_Predefined_Type;
4702
4703 ---------------------------------
4704 -- Process_Import_Or_Interface --
4705 ---------------------------------
4706
4707 procedure Process_Import_Or_Interface is
4708 C : Convention_Id;
4709 Def_Id : Entity_Id;
4710 Hom_Id : Entity_Id;
4711
4712 begin
4713 Process_Convention (C, Def_Id);
4714 Kill_Size_Check_Code (Def_Id);
4715 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4716
4717 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4718
4719 -- We do not permit Import to apply to a renaming declaration
4720
4721 if Present (Renamed_Object (Def_Id)) then
4722 Error_Pragma_Arg
4723 ("pragma% not allowed for object renaming", Arg2);
4724
4725 -- User initialization is not allowed for imported object, but
4726 -- the object declaration may contain a default initialization,
4727 -- that will be discarded. Note that an explicit initialization
4728 -- only counts if it comes from source, otherwise it is simply
4729 -- the code generator making an implicit initialization explicit.
4730
4731 elsif Present (Expression (Parent (Def_Id)))
4732 and then Comes_From_Source (Expression (Parent (Def_Id)))
4733 then
4734 Error_Msg_Sloc := Sloc (Def_Id);
4735 Error_Pragma_Arg
4736 ("no initialization allowed for declaration of& #",
4737 "\imported entities cannot be initialized (RM B.1(24))",
4738 Arg2);
4739
4740 else
4741 Set_Imported (Def_Id);
4742 Process_Interface_Name (Def_Id, Arg3, Arg4);
4743
4744 -- Note that we do not set Is_Public here. That's because we
4745 -- only want to set it if there is no address clause, and we
4746 -- don't know that yet, so we delay that processing till
4747 -- freeze time.
4748
4749 -- pragma Import completes deferred constants
4750
4751 if Ekind (Def_Id) = E_Constant then
4752 Set_Has_Completion (Def_Id);
4753 end if;
4754
4755 -- It is not possible to import a constant of an unconstrained
4756 -- array type (e.g. string) because there is no simple way to
4757 -- write a meaningful subtype for it.
4758
4759 if Is_Array_Type (Etype (Def_Id))
4760 and then not Is_Constrained (Etype (Def_Id))
4761 then
4762 Error_Msg_NE
4763 ("imported constant& must have a constrained subtype",
4764 N, Def_Id);
4765 end if;
4766 end if;
4767
4768 elsif Is_Subprogram (Def_Id)
4769 or else Is_Generic_Subprogram (Def_Id)
4770 then
4771 -- If the name is overloaded, pragma applies to all of the denoted
4772 -- entities in the same declarative part, unless the pragma comes
4773 -- from an aspect specification.
4774
4775 Hom_Id := Def_Id;
4776 while Present (Hom_Id) loop
4777
4778 Def_Id := Get_Base_Subprogram (Hom_Id);
4779
4780 -- Ignore inherited subprograms because the pragma will apply
4781 -- to the parent operation, which is the one called.
4782
4783 if Is_Overloadable (Def_Id)
4784 and then Present (Alias (Def_Id))
4785 then
4786 null;
4787
4788 -- If it is not a subprogram, it must be in an outer scope and
4789 -- pragma does not apply.
4790
4791 elsif not Is_Subprogram (Def_Id)
4792 and then not Is_Generic_Subprogram (Def_Id)
4793 then
4794 null;
4795
4796 -- The pragma does not apply to primitives of interfaces
4797
4798 elsif Is_Dispatching_Operation (Def_Id)
4799 and then Present (Find_Dispatching_Type (Def_Id))
4800 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4801 then
4802 null;
4803
4804 -- Verify that the homonym is in the same declarative part (not
4805 -- just the same scope). If the pragma comes from an aspect
4806 -- specification we know that it is part of the declaration.
4807
4808 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4809 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4810 and then not From_Aspect_Specification (N)
4811 then
4812 exit;
4813
4814 else
4815 Set_Imported (Def_Id);
4816
4817 -- Reject an Import applied to an abstract subprogram
4818
4819 if Is_Subprogram (Def_Id)
4820 and then Is_Abstract_Subprogram (Def_Id)
4821 then
4822 Error_Msg_Sloc := Sloc (Def_Id);
4823 Error_Msg_NE
4824 ("cannot import abstract subprogram& declared#",
4825 Arg2, Def_Id);
4826 end if;
4827
4828 -- Special processing for Convention_Intrinsic
4829
4830 if C = Convention_Intrinsic then
4831
4832 -- Link_Name argument not allowed for intrinsic
4833
4834 Check_No_Link_Name;
4835
4836 Set_Is_Intrinsic_Subprogram (Def_Id);
4837
4838 -- If no external name is present, then check that this
4839 -- is a valid intrinsic subprogram. If an external name
4840 -- is present, then this is handled by the back end.
4841
4842 if No (Arg3) then
4843 Check_Intrinsic_Subprogram
4844 (Def_Id, Get_Pragma_Arg (Arg2));
4845 end if;
4846 end if;
4847
4848 -- All interfaced procedures need an external symbol created
4849 -- for them since they are always referenced from another
4850 -- object file.
4851
4852 Set_Is_Public (Def_Id);
4853
4854 -- Verify that the subprogram does not have a completion
4855 -- through a renaming declaration. For other completions the
4856 -- pragma appears as a too late representation.
4857
4858 declare
4859 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4860
4861 begin
4862 if Present (Decl)
4863 and then Nkind (Decl) = N_Subprogram_Declaration
4864 and then Present (Corresponding_Body (Decl))
4865 and then Nkind (Unit_Declaration_Node
4866 (Corresponding_Body (Decl))) =
4867 N_Subprogram_Renaming_Declaration
4868 then
4869 Error_Msg_Sloc := Sloc (Def_Id);
4870 Error_Msg_NE
4871 ("cannot import&, renaming already provided for "
4872 & "declaration #", N, Def_Id);
4873 end if;
4874 end;
4875
4876 Set_Has_Completion (Def_Id);
4877 Process_Interface_Name (Def_Id, Arg3, Arg4);
4878 end if;
4879
4880 if Is_Compilation_Unit (Hom_Id) then
4881
4882 -- Its possible homonyms are not affected by the pragma.
4883 -- Such homonyms might be present in the context of other
4884 -- units being compiled.
4885
4886 exit;
4887
4888 elsif From_Aspect_Specification (N) then
4889 exit;
4890
4891 else
4892 Hom_Id := Homonym (Hom_Id);
4893 end if;
4894 end loop;
4895
4896 -- When the convention is Java or CIL, we also allow Import to be
4897 -- given for packages, generic packages, exceptions, record
4898 -- components, and access to subprograms.
4899
4900 elsif (C = Convention_Java or else C = Convention_CIL)
4901 and then
4902 (Is_Package_Or_Generic_Package (Def_Id)
4903 or else Ekind (Def_Id) = E_Exception
4904 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4905 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4906 then
4907 Set_Imported (Def_Id);
4908 Set_Is_Public (Def_Id);
4909 Process_Interface_Name (Def_Id, Arg3, Arg4);
4910
4911 -- Import a CPP class
4912
4913 elsif C = Convention_CPP
4914 and then (Is_Record_Type (Def_Id)
4915 or else Ekind (Def_Id) = E_Incomplete_Type)
4916 then
4917 if Ekind (Def_Id) = E_Incomplete_Type then
4918 if Present (Full_View (Def_Id)) then
4919 Def_Id := Full_View (Def_Id);
4920
4921 else
4922 Error_Msg_N
4923 ("cannot import 'C'P'P type before full declaration seen",
4924 Get_Pragma_Arg (Arg2));
4925
4926 -- Although we have reported the error we decorate it as
4927 -- CPP_Class to avoid reporting spurious errors
4928
4929 Set_Is_CPP_Class (Def_Id);
4930 return;
4931 end if;
4932 end if;
4933
4934 -- Types treated as CPP classes must be declared limited (note:
4935 -- this used to be a warning but there is no real benefit to it
4936 -- since we did effectively intend to treat the type as limited
4937 -- anyway).
4938
4939 if not Is_Limited_Type (Def_Id) then
4940 Error_Msg_N
4941 ("imported 'C'P'P type must be limited",
4942 Get_Pragma_Arg (Arg2));
4943 end if;
4944
4945 if Etype (Def_Id) /= Def_Id
4946 and then not Is_CPP_Class (Root_Type (Def_Id))
4947 then
4948 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
4949 end if;
4950
4951 Set_Is_CPP_Class (Def_Id);
4952
4953 -- Imported CPP types must not have discriminants (because C++
4954 -- classes do not have discriminants).
4955
4956 if Has_Discriminants (Def_Id) then
4957 Error_Msg_N
4958 ("imported 'C'P'P type cannot have discriminants",
4959 First (Discriminant_Specifications
4960 (Declaration_Node (Def_Id))));
4961 end if;
4962
4963 -- Check that components of imported CPP types do not have default
4964 -- expressions. For private types this check is performed when the
4965 -- full view is analyzed (see Process_Full_View).
4966
4967 if not Is_Private_Type (Def_Id) then
4968 Check_CPP_Type_Has_No_Defaults (Def_Id);
4969 end if;
4970
4971 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4972 Check_No_Link_Name;
4973 Check_Arg_Count (3);
4974 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4975
4976 Process_Import_Predefined_Type;
4977
4978 else
4979 Error_Pragma_Arg
4980 ("second argument of pragma% must be object, subprogram "
4981 & "or incomplete type",
4982 Arg2);
4983 end if;
4984
4985 -- If this pragma applies to a compilation unit, then the unit, which
4986 -- is a subprogram, does not require (or allow) a body. We also do
4987 -- not need to elaborate imported procedures.
4988
4989 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4990 declare
4991 Cunit : constant Node_Id := Parent (Parent (N));
4992 begin
4993 Set_Body_Required (Cunit, False);
4994 end;
4995 end if;
4996 end Process_Import_Or_Interface;
4997
4998 --------------------
4999 -- Process_Inline --
5000 --------------------
5001
5002 procedure Process_Inline (Status : Inline_Status) is
5003 Assoc : Node_Id;
5004 Decl : Node_Id;
5005 Subp_Id : Node_Id;
5006 Subp : Entity_Id;
5007 Applies : Boolean;
5008
5009 Effective : Boolean := False;
5010 -- Set True if inline has some effect, i.e. if there is at least one
5011 -- subprogram set as inlined as a result of the use of the pragma.
5012
5013 procedure Make_Inline (Subp : Entity_Id);
5014 -- Subp is the defining unit name of the subprogram declaration. Set
5015 -- the flag, as well as the flag in the corresponding body, if there
5016 -- is one present.
5017
5018 procedure Set_Inline_Flags (Subp : Entity_Id);
5019 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
5020 -- Has_Pragma_Inline_Always for the Inline_Always case.
5021
5022 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
5023 -- Returns True if it can be determined at this stage that inlining
5024 -- is not possible, for example if the body is available and contains
5025 -- exception handlers, we prevent inlining, since otherwise we can
5026 -- get undefined symbols at link time. This function also emits a
5027 -- warning if front-end inlining is enabled and the pragma appears
5028 -- too late.
5029 --
5030 -- ??? is business with link symbols still valid, or does it relate
5031 -- to front end ZCX which is being phased out ???
5032
5033 ---------------------------
5034 -- Inlining_Not_Possible --
5035 ---------------------------
5036
5037 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
5038 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
5039 Stats : Node_Id;
5040
5041 begin
5042 if Nkind (Decl) = N_Subprogram_Body then
5043 Stats := Handled_Statement_Sequence (Decl);
5044 return Present (Exception_Handlers (Stats))
5045 or else Present (At_End_Proc (Stats));
5046
5047 elsif Nkind (Decl) = N_Subprogram_Declaration
5048 and then Present (Corresponding_Body (Decl))
5049 then
5050 if Front_End_Inlining
5051 and then Analyzed (Corresponding_Body (Decl))
5052 then
5053 Error_Msg_N ("pragma appears too late, ignored??", N);
5054 return True;
5055
5056 -- If the subprogram is a renaming as body, the body is just a
5057 -- call to the renamed subprogram, and inlining is trivially
5058 -- possible.
5059
5060 elsif
5061 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
5062 N_Subprogram_Renaming_Declaration
5063 then
5064 return False;
5065
5066 else
5067 Stats :=
5068 Handled_Statement_Sequence
5069 (Unit_Declaration_Node (Corresponding_Body (Decl)));
5070
5071 return
5072 Present (Exception_Handlers (Stats))
5073 or else Present (At_End_Proc (Stats));
5074 end if;
5075
5076 else
5077 -- If body is not available, assume the best, the check is
5078 -- performed again when compiling enclosing package bodies.
5079
5080 return False;
5081 end if;
5082 end Inlining_Not_Possible;
5083
5084 -----------------
5085 -- Make_Inline --
5086 -----------------
5087
5088 procedure Make_Inline (Subp : Entity_Id) is
5089 Kind : constant Entity_Kind := Ekind (Subp);
5090 Inner_Subp : Entity_Id := Subp;
5091
5092 begin
5093 -- Ignore if bad type, avoid cascaded error
5094
5095 if Etype (Subp) = Any_Type then
5096 Applies := True;
5097 return;
5098
5099 -- Ignore if all inlining is suppressed
5100
5101 elsif Suppress_All_Inlining then
5102 Applies := True;
5103 return;
5104
5105 -- If inlining is not possible, for now do not treat as an error
5106
5107 elsif Status /= Suppressed
5108 and then Inlining_Not_Possible (Subp)
5109 then
5110 Applies := True;
5111 return;
5112
5113 -- Here we have a candidate for inlining, but we must exclude
5114 -- derived operations. Otherwise we would end up trying to inline
5115 -- a phantom declaration, and the result would be to drag in a
5116 -- body which has no direct inlining associated with it. That
5117 -- would not only be inefficient but would also result in the
5118 -- backend doing cross-unit inlining in cases where it was
5119 -- definitely inappropriate to do so.
5120
5121 -- However, a simple Comes_From_Source test is insufficient, since
5122 -- we do want to allow inlining of generic instances which also do
5123 -- not come from source. We also need to recognize specs generated
5124 -- by the front-end for bodies that carry the pragma. Finally,
5125 -- predefined operators do not come from source but are not
5126 -- inlineable either.
5127
5128 elsif Is_Generic_Instance (Subp)
5129 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
5130 then
5131 null;
5132
5133 elsif not Comes_From_Source (Subp)
5134 and then Scope (Subp) /= Standard_Standard
5135 then
5136 Applies := True;
5137 return;
5138 end if;
5139
5140 -- The referenced entity must either be the enclosing entity, or
5141 -- an entity declared within the current open scope.
5142
5143 if Present (Scope (Subp))
5144 and then Scope (Subp) /= Current_Scope
5145 and then Subp /= Current_Scope
5146 then
5147 Error_Pragma_Arg
5148 ("argument of% must be entity in current scope", Assoc);
5149 return;
5150 end if;
5151
5152 -- Processing for procedure, operator or function. If subprogram
5153 -- is aliased (as for an instance) indicate that the renamed
5154 -- entity (if declared in the same unit) is inlined.
5155
5156 if Is_Subprogram (Subp) then
5157 Inner_Subp := Ultimate_Alias (Inner_Subp);
5158
5159 if In_Same_Source_Unit (Subp, Inner_Subp) then
5160 Set_Inline_Flags (Inner_Subp);
5161
5162 Decl := Parent (Parent (Inner_Subp));
5163
5164 if Nkind (Decl) = N_Subprogram_Declaration
5165 and then Present (Corresponding_Body (Decl))
5166 then
5167 Set_Inline_Flags (Corresponding_Body (Decl));
5168
5169 elsif Is_Generic_Instance (Subp) then
5170
5171 -- Indicate that the body needs to be created for
5172 -- inlining subsequent calls. The instantiation node
5173 -- follows the declaration of the wrapper package
5174 -- created for it.
5175
5176 if Scope (Subp) /= Standard_Standard
5177 and then
5178 Need_Subprogram_Instance_Body
5179 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
5180 Subp)
5181 then
5182 null;
5183 end if;
5184
5185 -- Inline is a program unit pragma (RM 10.1.5) and cannot
5186 -- appear in a formal part to apply to a formal subprogram.
5187 -- Do not apply check within an instance or a formal package
5188 -- the test will have been applied to the original generic.
5189
5190 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
5191 and then List_Containing (Decl) = List_Containing (N)
5192 and then not In_Instance
5193 then
5194 Error_Msg_N
5195 ("Inline cannot apply to a formal subprogram", N);
5196
5197 -- If Subp is a renaming, it is the renamed entity that
5198 -- will appear in any call, and be inlined. However, for
5199 -- ASIS uses it is convenient to indicate that the renaming
5200 -- itself is an inlined subprogram, so that some gnatcheck
5201 -- rules can be applied in the absence of expansion.
5202
5203 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
5204 Set_Inline_Flags (Subp);
5205 end if;
5206 end if;
5207
5208 Applies := True;
5209
5210 -- For a generic subprogram set flag as well, for use at the point
5211 -- of instantiation, to determine whether the body should be
5212 -- generated.
5213
5214 elsif Is_Generic_Subprogram (Subp) then
5215 Set_Inline_Flags (Subp);
5216 Applies := True;
5217
5218 -- Literals are by definition inlined
5219
5220 elsif Kind = E_Enumeration_Literal then
5221 null;
5222
5223 -- Anything else is an error
5224
5225 else
5226 Error_Pragma_Arg
5227 ("expect subprogram name for pragma%", Assoc);
5228 end if;
5229 end Make_Inline;
5230
5231 ----------------------
5232 -- Set_Inline_Flags --
5233 ----------------------
5234
5235 procedure Set_Inline_Flags (Subp : Entity_Id) is
5236 begin
5237 -- First set the Has_Pragma_XXX flags and issue the appropriate
5238 -- errors and warnings for suspicious combinations.
5239
5240 if Prag_Id = Pragma_No_Inline then
5241 if Has_Pragma_Inline_Always (Subp) then
5242 Error_Msg_N
5243 ("Inline_Always and No_Inline are mutually exclusive", N);
5244 elsif Has_Pragma_Inline (Subp) then
5245 Error_Msg_NE
5246 ("Inline and No_Inline both specified for& ??",
5247 N, Entity (Subp_Id));
5248 end if;
5249
5250 Set_Has_Pragma_No_Inline (Subp);
5251 else
5252 if Prag_Id = Pragma_Inline_Always then
5253 if Has_Pragma_No_Inline (Subp) then
5254 Error_Msg_N
5255 ("Inline_Always and No_Inline are mutually exclusive",
5256 N);
5257 end if;
5258
5259 Set_Has_Pragma_Inline_Always (Subp);
5260 else
5261 if Has_Pragma_No_Inline (Subp) then
5262 Error_Msg_NE
5263 ("Inline and No_Inline both specified for& ??",
5264 N, Entity (Subp_Id));
5265 end if;
5266 end if;
5267
5268 if not Has_Pragma_Inline (Subp) then
5269 Set_Has_Pragma_Inline (Subp);
5270 Effective := True;
5271 end if;
5272 end if;
5273
5274 -- Then adjust the Is_Inlined flag. It can never be set if the
5275 -- subprogram is subject to pragma No_Inline.
5276
5277 case Status is
5278 when Suppressed =>
5279 Set_Is_Inlined (Subp, False);
5280 when Disabled =>
5281 null;
5282 when Enabled =>
5283 if not Has_Pragma_No_Inline (Subp) then
5284 Set_Is_Inlined (Subp, True);
5285 end if;
5286 end case;
5287 end Set_Inline_Flags;
5288
5289 -- Start of processing for Process_Inline
5290
5291 begin
5292 Check_No_Identifiers;
5293 Check_At_Least_N_Arguments (1);
5294
5295 if Status = Enabled then
5296 Inline_Processing_Required := True;
5297 end if;
5298
5299 Assoc := Arg1;
5300 while Present (Assoc) loop
5301 Subp_Id := Get_Pragma_Arg (Assoc);
5302 Analyze (Subp_Id);
5303 Applies := False;
5304
5305 if Is_Entity_Name (Subp_Id) then
5306 Subp := Entity (Subp_Id);
5307
5308 if Subp = Any_Id then
5309
5310 -- If previous error, avoid cascaded errors
5311
5312 Check_Error_Detected;
5313 Applies := True;
5314 Effective := True;
5315
5316 else
5317 Make_Inline (Subp);
5318
5319 -- For the pragma case, climb homonym chain. This is
5320 -- what implements allowing the pragma in the renaming
5321 -- case, with the result applying to the ancestors, and
5322 -- also allows Inline to apply to all previous homonyms.
5323
5324 if not From_Aspect_Specification (N) then
5325 while Present (Homonym (Subp))
5326 and then Scope (Homonym (Subp)) = Current_Scope
5327 loop
5328 Make_Inline (Homonym (Subp));
5329 Subp := Homonym (Subp);
5330 end loop;
5331 end if;
5332 end if;
5333 end if;
5334
5335 if not Applies then
5336 Error_Pragma_Arg
5337 ("inappropriate argument for pragma%", Assoc);
5338
5339 elsif not Effective
5340 and then Warn_On_Redundant_Constructs
5341 and then not (Status = Suppressed or else Suppress_All_Inlining)
5342 then
5343 if Inlining_Not_Possible (Subp) then
5344 Error_Msg_NE
5345 ("pragma Inline for& is ignored?r?",
5346 N, Entity (Subp_Id));
5347 else
5348 Error_Msg_NE
5349 ("pragma Inline for& is redundant?r?",
5350 N, Entity (Subp_Id));
5351 end if;
5352 end if;
5353
5354 Next (Assoc);
5355 end loop;
5356 end Process_Inline;
5357
5358 ----------------------------
5359 -- Process_Interface_Name --
5360 ----------------------------
5361
5362 procedure Process_Interface_Name
5363 (Subprogram_Def : Entity_Id;
5364 Ext_Arg : Node_Id;
5365 Link_Arg : Node_Id)
5366 is
5367 Ext_Nam : Node_Id;
5368 Link_Nam : Node_Id;
5369 String_Val : String_Id;
5370
5371 procedure Check_Form_Of_Interface_Name
5372 (SN : Node_Id;
5373 Ext_Name_Case : Boolean);
5374 -- SN is a string literal node for an interface name. This routine
5375 -- performs some minimal checks that the name is reasonable. In
5376 -- particular that no spaces or other obviously incorrect characters
5377 -- appear. This is only a warning, since any characters are allowed.
5378 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
5379
5380 ----------------------------------
5381 -- Check_Form_Of_Interface_Name --
5382 ----------------------------------
5383
5384 procedure Check_Form_Of_Interface_Name
5385 (SN : Node_Id;
5386 Ext_Name_Case : Boolean)
5387 is
5388 S : constant String_Id := Strval (Expr_Value_S (SN));
5389 SL : constant Nat := String_Length (S);
5390 C : Char_Code;
5391
5392 begin
5393 if SL = 0 then
5394 Error_Msg_N ("interface name cannot be null string", SN);
5395 end if;
5396
5397 for J in 1 .. SL loop
5398 C := Get_String_Char (S, J);
5399
5400 -- Look for dubious character and issue unconditional warning.
5401 -- Definitely dubious if not in character range.
5402
5403 if not In_Character_Range (C)
5404
5405 -- For all cases except CLI target,
5406 -- commas, spaces and slashes are dubious (in CLI, we use
5407 -- commas and backslashes in external names to specify
5408 -- assembly version and public key, while slashes and spaces
5409 -- can be used in names to mark nested classes and
5410 -- valuetypes).
5411
5412 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5413 and then (Get_Character (C) = ','
5414 or else
5415 Get_Character (C) = '\'))
5416 or else (VM_Target /= CLI_Target
5417 and then (Get_Character (C) = ' '
5418 or else
5419 Get_Character (C) = '/'))
5420 then
5421 Error_Msg
5422 ("??interface name contains illegal character",
5423 Sloc (SN) + Source_Ptr (J));
5424 end if;
5425 end loop;
5426 end Check_Form_Of_Interface_Name;
5427
5428 -- Start of processing for Process_Interface_Name
5429
5430 begin
5431 if No (Link_Arg) then
5432 if No (Ext_Arg) then
5433 if VM_Target = CLI_Target
5434 and then Ekind (Subprogram_Def) = E_Package
5435 and then Nkind (Parent (Subprogram_Def)) =
5436 N_Package_Specification
5437 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5438 then
5439 Set_Interface_Name
5440 (Subprogram_Def,
5441 Interface_Name
5442 (Generic_Parent (Parent (Subprogram_Def))));
5443 end if;
5444
5445 return;
5446
5447 elsif Chars (Ext_Arg) = Name_Link_Name then
5448 Ext_Nam := Empty;
5449 Link_Nam := Expression (Ext_Arg);
5450
5451 else
5452 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5453 Ext_Nam := Expression (Ext_Arg);
5454 Link_Nam := Empty;
5455 end if;
5456
5457 else
5458 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5459 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5460 Ext_Nam := Expression (Ext_Arg);
5461 Link_Nam := Expression (Link_Arg);
5462 end if;
5463
5464 -- Check expressions for external name and link name are static
5465
5466 if Present (Ext_Nam) then
5467 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5468 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5469
5470 -- Verify that external name is not the name of a local entity,
5471 -- which would hide the imported one and could lead to run-time
5472 -- surprises. The problem can only arise for entities declared in
5473 -- a package body (otherwise the external name is fully qualified
5474 -- and will not conflict).
5475
5476 declare
5477 Nam : Name_Id;
5478 E : Entity_Id;
5479 Par : Node_Id;
5480
5481 begin
5482 if Prag_Id = Pragma_Import then
5483 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5484 Nam := Name_Find;
5485 E := Entity_Id (Get_Name_Table_Info (Nam));
5486
5487 if Nam /= Chars (Subprogram_Def)
5488 and then Present (E)
5489 and then not Is_Overloadable (E)
5490 and then Is_Immediately_Visible (E)
5491 and then not Is_Imported (E)
5492 and then Ekind (Scope (E)) = E_Package
5493 then
5494 Par := Parent (E);
5495 while Present (Par) loop
5496 if Nkind (Par) = N_Package_Body then
5497 Error_Msg_Sloc := Sloc (E);
5498 Error_Msg_NE
5499 ("imported entity is hidden by & declared#",
5500 Ext_Arg, E);
5501 exit;
5502 end if;
5503
5504 Par := Parent (Par);
5505 end loop;
5506 end if;
5507 end if;
5508 end;
5509 end if;
5510
5511 if Present (Link_Nam) then
5512 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5513 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5514 end if;
5515
5516 -- If there is no link name, just set the external name
5517
5518 if No (Link_Nam) then
5519 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5520
5521 -- For the Link_Name case, the given literal is preceded by an
5522 -- asterisk, which indicates to GCC that the given name should be
5523 -- taken literally, and in particular that no prepending of
5524 -- underlines should occur, even in systems where this is the
5525 -- normal default.
5526
5527 else
5528 Start_String;
5529
5530 if VM_Target = No_VM then
5531 Store_String_Char (Get_Char_Code ('*'));
5532 end if;
5533
5534 String_Val := Strval (Expr_Value_S (Link_Nam));
5535 Store_String_Chars (String_Val);
5536 Link_Nam :=
5537 Make_String_Literal (Sloc (Link_Nam),
5538 Strval => End_String);
5539 end if;
5540
5541 -- Set the interface name. If the entity is a generic instance, use
5542 -- its alias, which is the callable entity.
5543
5544 if Is_Generic_Instance (Subprogram_Def) then
5545 Set_Encoded_Interface_Name
5546 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5547 else
5548 Set_Encoded_Interface_Name
5549 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5550 end if;
5551
5552 -- We allow duplicated export names in CIL/Java, as they are always
5553 -- enclosed in a namespace that differentiates them, and overloaded
5554 -- entities are supported by the VM.
5555
5556 if Convention (Subprogram_Def) /= Convention_CIL
5557 and then
5558 Convention (Subprogram_Def) /= Convention_Java
5559 then
5560 Check_Duplicated_Export_Name (Link_Nam);
5561 end if;
5562 end Process_Interface_Name;
5563
5564 -----------------------------------------
5565 -- Process_Interrupt_Or_Attach_Handler --
5566 -----------------------------------------
5567
5568 procedure Process_Interrupt_Or_Attach_Handler is
5569 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5570 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5571 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5572
5573 begin
5574 Set_Is_Interrupt_Handler (Handler_Proc);
5575
5576 -- If the pragma is not associated with a handler procedure within a
5577 -- protected type, then it must be for a nonprotected procedure for
5578 -- the AAMP target, in which case we don't associate a representation
5579 -- item with the procedure's scope.
5580
5581 if Ekind (Proc_Scope) = E_Protected_Type then
5582 if Prag_Id = Pragma_Interrupt_Handler
5583 or else
5584 Prag_Id = Pragma_Attach_Handler
5585 then
5586 Record_Rep_Item (Proc_Scope, N);
5587 end if;
5588 end if;
5589 end Process_Interrupt_Or_Attach_Handler;
5590
5591 --------------------------------------------------
5592 -- Process_Restrictions_Or_Restriction_Warnings --
5593 --------------------------------------------------
5594
5595 -- Note: some of the simple identifier cases were handled in par-prag,
5596 -- but it is harmless (and more straightforward) to simply handle all
5597 -- cases here, even if it means we repeat a bit of work in some cases.
5598
5599 procedure Process_Restrictions_Or_Restriction_Warnings
5600 (Warn : Boolean)
5601 is
5602 Arg : Node_Id;
5603 R_Id : Restriction_Id;
5604 Id : Name_Id;
5605 Expr : Node_Id;
5606 Val : Uint;
5607
5608 procedure Check_Unit_Name (N : Node_Id);
5609 -- Checks unit name parameter for No_Dependence. Returns if it has
5610 -- an appropriate form, otherwise raises pragma argument error.
5611
5612 ---------------------
5613 -- Check_Unit_Name --
5614 ---------------------
5615
5616 procedure Check_Unit_Name (N : Node_Id) is
5617 begin
5618 if Nkind (N) = N_Selected_Component then
5619 Check_Unit_Name (Prefix (N));
5620 Check_Unit_Name (Selector_Name (N));
5621
5622 elsif Nkind (N) = N_Identifier then
5623 return;
5624
5625 else
5626 Error_Pragma_Arg
5627 ("wrong form for unit name for No_Dependence", N);
5628 end if;
5629 end Check_Unit_Name;
5630
5631 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5632
5633 begin
5634 -- Ignore all Restrictions pragma in CodePeer mode
5635
5636 if CodePeer_Mode then
5637 return;
5638 end if;
5639
5640 Check_Ada_83_Warning;
5641 Check_At_Least_N_Arguments (1);
5642 Check_Valid_Configuration_Pragma;
5643
5644 Arg := Arg1;
5645 while Present (Arg) loop
5646 Id := Chars (Arg);
5647 Expr := Get_Pragma_Arg (Arg);
5648
5649 -- Case of no restriction identifier present
5650
5651 if Id = No_Name then
5652 if Nkind (Expr) /= N_Identifier then
5653 Error_Pragma_Arg
5654 ("invalid form for restriction", Arg);
5655 end if;
5656
5657 R_Id :=
5658 Get_Restriction_Id
5659 (Process_Restriction_Synonyms (Expr));
5660
5661 if R_Id not in All_Boolean_Restrictions then
5662 Error_Msg_Name_1 := Pname;
5663 Error_Msg_N
5664 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5665
5666 -- Check for possible misspelling
5667
5668 for J in Restriction_Id loop
5669 declare
5670 Rnm : constant String := Restriction_Id'Image (J);
5671
5672 begin
5673 Name_Buffer (1 .. Rnm'Length) := Rnm;
5674 Name_Len := Rnm'Length;
5675 Set_Casing (All_Lower_Case);
5676
5677 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5678 Set_Casing
5679 (Identifier_Casing (Current_Source_File));
5680 Error_Msg_String (1 .. Rnm'Length) :=
5681 Name_Buffer (1 .. Name_Len);
5682 Error_Msg_Strlen := Rnm'Length;
5683 Error_Msg_N -- CODEFIX
5684 ("\possible misspelling of ""~""",
5685 Get_Pragma_Arg (Arg));
5686 exit;
5687 end if;
5688 end;
5689 end loop;
5690
5691 raise Pragma_Exit;
5692 end if;
5693
5694 if Implementation_Restriction (R_Id) then
5695 Check_Restriction (No_Implementation_Restrictions, Arg);
5696 end if;
5697
5698 -- Special processing for No_Elaboration_Code restriction
5699
5700 if R_Id = No_Elaboration_Code then
5701
5702 -- Restriction is only recognized within a configuration
5703 -- pragma file, or within a unit of the main extended
5704 -- program. Note: the test for Main_Unit is needed to
5705 -- properly include the case of configuration pragma files.
5706
5707 if not (Current_Sem_Unit = Main_Unit
5708 or else In_Extended_Main_Source_Unit (N))
5709 then
5710 return;
5711
5712 -- Don't allow in a subunit unless already specified in
5713 -- body or spec.
5714
5715 elsif Nkind (Parent (N)) = N_Compilation_Unit
5716 and then Nkind (Unit (Parent (N))) = N_Subunit
5717 and then not Restriction_Active (No_Elaboration_Code)
5718 then
5719 Error_Msg_N
5720 ("invalid specification of ""No_Elaboration_Code""",
5721 N);
5722 Error_Msg_N
5723 ("\restriction cannot be specified in a subunit", N);
5724 Error_Msg_N
5725 ("\unless also specified in body or spec", N);
5726 return;
5727
5728 -- If we have a No_Elaboration_Code pragma that we
5729 -- accept, then it needs to be added to the configuration
5730 -- restrcition set so that we get proper application to
5731 -- other units in the main extended source as required.
5732
5733 else
5734 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
5735 end if;
5736 end if;
5737
5738 -- If this is a warning, then set the warning unless we already
5739 -- have a real restriction active (we never want a warning to
5740 -- override a real restriction).
5741
5742 if Warn then
5743 if not Restriction_Active (R_Id) then
5744 Set_Restriction (R_Id, N);
5745 Restriction_Warnings (R_Id) := True;
5746 end if;
5747
5748 -- If real restriction case, then set it and make sure that the
5749 -- restriction warning flag is off, since a real restriction
5750 -- always overrides a warning.
5751
5752 else
5753 Set_Restriction (R_Id, N);
5754 Restriction_Warnings (R_Id) := False;
5755 end if;
5756
5757 -- Check for obsolescent restrictions in Ada 2005 mode
5758
5759 if not Warn
5760 and then Ada_Version >= Ada_2005
5761 and then (R_Id = No_Asynchronous_Control
5762 or else
5763 R_Id = No_Unchecked_Deallocation
5764 or else
5765 R_Id = No_Unchecked_Conversion)
5766 then
5767 Check_Restriction (No_Obsolescent_Features, N);
5768 end if;
5769
5770 -- A very special case that must be processed here: pragma
5771 -- Restrictions (No_Exceptions) turns off all run-time
5772 -- checking. This is a bit dubious in terms of the formal
5773 -- language definition, but it is what is intended by RM
5774 -- H.4(12). Restriction_Warnings never affects generated code
5775 -- so this is done only in the real restriction case.
5776
5777 -- Atomic_Synchronization is not a real check, so it is not
5778 -- affected by this processing).
5779
5780 if R_Id = No_Exceptions and then not Warn then
5781 for J in Scope_Suppress.Suppress'Range loop
5782 if J /= Atomic_Synchronization then
5783 Scope_Suppress.Suppress (J) := True;
5784 end if;
5785 end loop;
5786 end if;
5787
5788 -- Case of No_Dependence => unit-name. Note that the parser
5789 -- already made the necessary entry in the No_Dependence table.
5790
5791 elsif Id = Name_No_Dependence then
5792 Check_Unit_Name (Expr);
5793
5794 -- Case of No_Specification_Of_Aspect => Identifier.
5795
5796 elsif Id = Name_No_Specification_Of_Aspect then
5797 declare
5798 A_Id : Aspect_Id;
5799
5800 begin
5801 if Nkind (Expr) /= N_Identifier then
5802 A_Id := No_Aspect;
5803 else
5804 A_Id := Get_Aspect_Id (Chars (Expr));
5805 end if;
5806
5807 if A_Id = No_Aspect then
5808 Error_Pragma_Arg ("invalid restriction name", Arg);
5809 else
5810 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5811 end if;
5812 end;
5813
5814 elsif Id = Name_No_Use_Of_Attribute then
5815 if Nkind (Expr) /= N_Identifier
5816 or else not Is_Attribute_Name (Chars (Expr))
5817 then
5818 Error_Msg_N ("unknown attribute name?", Expr);
5819
5820 else
5821 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
5822 end if;
5823
5824 elsif Id = Name_No_Use_Of_Pragma then
5825 if Nkind (Expr) /= N_Identifier
5826 or else not Is_Pragma_Name (Chars (Expr))
5827 then
5828 Error_Msg_N ("unknown pragma name?", Expr);
5829
5830 else
5831 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
5832 end if;
5833
5834 -- All other cases of restriction identifier present
5835
5836 else
5837 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5838 Analyze_And_Resolve (Expr, Any_Integer);
5839
5840 if R_Id not in All_Parameter_Restrictions then
5841 Error_Pragma_Arg
5842 ("invalid restriction parameter identifier", Arg);
5843
5844 elsif not Is_OK_Static_Expression (Expr) then
5845 Flag_Non_Static_Expr
5846 ("value must be static expression!", Expr);
5847 raise Pragma_Exit;
5848
5849 elsif not Is_Integer_Type (Etype (Expr))
5850 or else Expr_Value (Expr) < 0
5851 then
5852 Error_Pragma_Arg
5853 ("value must be non-negative integer", Arg);
5854 end if;
5855
5856 -- Restriction pragma is active
5857
5858 Val := Expr_Value (Expr);
5859
5860 if not UI_Is_In_Int_Range (Val) then
5861 Error_Pragma_Arg
5862 ("pragma ignored, value too large??", Arg);
5863 end if;
5864
5865 -- Warning case. If the real restriction is active, then we
5866 -- ignore the request, since warning never overrides a real
5867 -- restriction. Otherwise we set the proper warning. Note that
5868 -- this circuit sets the warning again if it is already set,
5869 -- which is what we want, since the constant may have changed.
5870
5871 if Warn then
5872 if not Restriction_Active (R_Id) then
5873 Set_Restriction
5874 (R_Id, N, Integer (UI_To_Int (Val)));
5875 Restriction_Warnings (R_Id) := True;
5876 end if;
5877
5878 -- Real restriction case, set restriction and make sure warning
5879 -- flag is off since real restriction always overrides warning.
5880
5881 else
5882 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5883 Restriction_Warnings (R_Id) := False;
5884 end if;
5885 end if;
5886
5887 Next (Arg);
5888 end loop;
5889 end Process_Restrictions_Or_Restriction_Warnings;
5890
5891 ---------------------------------
5892 -- Process_Suppress_Unsuppress --
5893 ---------------------------------
5894
5895 -- Note: this procedure makes entries in the check suppress data
5896 -- structures managed by Sem. See spec of package Sem for full
5897 -- details on how we handle recording of check suppression.
5898
5899 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5900 C : Check_Id;
5901 E_Id : Node_Id;
5902 E : Entity_Id;
5903
5904 In_Package_Spec : constant Boolean :=
5905 Is_Package_Or_Generic_Package (Current_Scope)
5906 and then not In_Package_Body (Current_Scope);
5907
5908 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5909 -- Used to suppress a single check on the given entity
5910
5911 --------------------------------
5912 -- Suppress_Unsuppress_Echeck --
5913 --------------------------------
5914
5915 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5916 begin
5917 -- Check for error of trying to set atomic synchronization for
5918 -- a non-atomic variable.
5919
5920 if C = Atomic_Synchronization
5921 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5922 then
5923 Error_Msg_N
5924 ("pragma & requires atomic type or variable",
5925 Pragma_Identifier (Original_Node (N)));
5926 end if;
5927
5928 Set_Checks_May_Be_Suppressed (E);
5929
5930 if In_Package_Spec then
5931 Push_Global_Suppress_Stack_Entry
5932 (Entity => E,
5933 Check => C,
5934 Suppress => Suppress_Case);
5935 else
5936 Push_Local_Suppress_Stack_Entry
5937 (Entity => E,
5938 Check => C,
5939 Suppress => Suppress_Case);
5940 end if;
5941
5942 -- If this is a first subtype, and the base type is distinct,
5943 -- then also set the suppress flags on the base type.
5944
5945 if Is_First_Subtype (E) and then Etype (E) /= E then
5946 Suppress_Unsuppress_Echeck (Etype (E), C);
5947 end if;
5948 end Suppress_Unsuppress_Echeck;
5949
5950 -- Start of processing for Process_Suppress_Unsuppress
5951
5952 begin
5953 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5954 -- user code: we want to generate checks for analysis purposes, as
5955 -- set respectively by -gnatC and -gnatd.F
5956
5957 if (CodePeer_Mode or Alfa_Mode) and then Comes_From_Source (N) then
5958 return;
5959 end if;
5960
5961 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5962 -- declarative part or a package spec (RM 11.5(5)).
5963
5964 if not Is_Configuration_Pragma then
5965 Check_Is_In_Decl_Part_Or_Package_Spec;
5966 end if;
5967
5968 Check_At_Least_N_Arguments (1);
5969 Check_At_Most_N_Arguments (2);
5970 Check_No_Identifier (Arg1);
5971 Check_Arg_Is_Identifier (Arg1);
5972
5973 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5974
5975 if C = No_Check_Id then
5976 Error_Pragma_Arg
5977 ("argument of pragma% is not valid check name", Arg1);
5978 end if;
5979
5980 if Arg_Count = 1 then
5981
5982 -- Make an entry in the local scope suppress table. This is the
5983 -- table that directly shows the current value of the scope
5984 -- suppress check for any check id value.
5985
5986 if C = All_Checks then
5987
5988 -- For All_Checks, we set all specific predefined checks with
5989 -- the exception of Elaboration_Check, which is handled
5990 -- specially because of not wanting All_Checks to have the
5991 -- effect of deactivating static elaboration order processing.
5992 -- Atomic_Synchronization is also not affected, since this is
5993 -- not a real check.
5994
5995 for J in Scope_Suppress.Suppress'Range loop
5996 if J /= Elaboration_Check
5997 and then
5998 J /= Atomic_Synchronization
5999 then
6000 Scope_Suppress.Suppress (J) := Suppress_Case;
6001 end if;
6002 end loop;
6003
6004 -- If not All_Checks, and predefined check, then set appropriate
6005 -- scope entry. Note that we will set Elaboration_Check if this
6006 -- is explicitly specified. Atomic_Synchronization is allowed
6007 -- only if internally generated and entity is atomic.
6008
6009 elsif C in Predefined_Check_Id
6010 and then (not Comes_From_Source (N)
6011 or else C /= Atomic_Synchronization)
6012 then
6013 Scope_Suppress.Suppress (C) := Suppress_Case;
6014 end if;
6015
6016 -- Also make an entry in the Local_Entity_Suppress table
6017
6018 Push_Local_Suppress_Stack_Entry
6019 (Entity => Empty,
6020 Check => C,
6021 Suppress => Suppress_Case);
6022
6023 -- Case of two arguments present, where the check is suppressed for
6024 -- a specified entity (given as the second argument of the pragma)
6025
6026 else
6027 -- This is obsolescent in Ada 2005 mode
6028
6029 if Ada_Version >= Ada_2005 then
6030 Check_Restriction (No_Obsolescent_Features, Arg2);
6031 end if;
6032
6033 Check_Optional_Identifier (Arg2, Name_On);
6034 E_Id := Get_Pragma_Arg (Arg2);
6035 Analyze (E_Id);
6036
6037 if not Is_Entity_Name (E_Id) then
6038 Error_Pragma_Arg
6039 ("second argument of pragma% must be entity name", Arg2);
6040 end if;
6041
6042 E := Entity (E_Id);
6043
6044 if E = Any_Id then
6045 return;
6046 end if;
6047
6048 -- Enforce RM 11.5(7) which requires that for a pragma that
6049 -- appears within a package spec, the named entity must be
6050 -- within the package spec. We allow the package name itself
6051 -- to be mentioned since that makes sense, although it is not
6052 -- strictly allowed by 11.5(7).
6053
6054 if In_Package_Spec
6055 and then E /= Current_Scope
6056 and then Scope (E) /= Current_Scope
6057 then
6058 Error_Pragma_Arg
6059 ("entity in pragma% is not in package spec (RM 11.5(7))",
6060 Arg2);
6061 end if;
6062
6063 -- Loop through homonyms. As noted below, in the case of a package
6064 -- spec, only homonyms within the package spec are considered.
6065
6066 loop
6067 Suppress_Unsuppress_Echeck (E, C);
6068
6069 if Is_Generic_Instance (E)
6070 and then Is_Subprogram (E)
6071 and then Present (Alias (E))
6072 then
6073 Suppress_Unsuppress_Echeck (Alias (E), C);
6074 end if;
6075
6076 -- Move to next homonym if not aspect spec case
6077
6078 exit when From_Aspect_Specification (N);
6079 E := Homonym (E);
6080 exit when No (E);
6081
6082 -- If we are within a package specification, the pragma only
6083 -- applies to homonyms in the same scope.
6084
6085 exit when In_Package_Spec
6086 and then Scope (E) /= Current_Scope;
6087 end loop;
6088 end if;
6089 end Process_Suppress_Unsuppress;
6090
6091 ------------------
6092 -- Set_Exported --
6093 ------------------
6094
6095 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
6096 begin
6097 if Is_Imported (E) then
6098 Error_Pragma_Arg
6099 ("cannot export entity& that was previously imported", Arg);
6100
6101 elsif Present (Address_Clause (E))
6102 and then not Relaxed_RM_Semantics
6103 then
6104 Error_Pragma_Arg
6105 ("cannot export entity& that has an address clause", Arg);
6106 end if;
6107
6108 Set_Is_Exported (E);
6109
6110 -- Generate a reference for entity explicitly, because the
6111 -- identifier may be overloaded and name resolution will not
6112 -- generate one.
6113
6114 Generate_Reference (E, Arg);
6115
6116 -- Deal with exporting non-library level entity
6117
6118 if not Is_Library_Level_Entity (E) then
6119
6120 -- Not allowed at all for subprograms
6121
6122 if Is_Subprogram (E) then
6123 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
6124
6125 -- Otherwise set public and statically allocated
6126
6127 else
6128 Set_Is_Public (E);
6129 Set_Is_Statically_Allocated (E);
6130
6131 -- Warn if the corresponding W flag is set and the pragma comes
6132 -- from source. The latter may not be true e.g. on VMS where we
6133 -- expand export pragmas for exception codes associated with
6134 -- imported or exported exceptions. We do not want to generate
6135 -- a warning for something that the user did not write.
6136
6137 if Warn_On_Export_Import
6138 and then Comes_From_Source (Arg)
6139 then
6140 Error_Msg_NE
6141 ("?x?& has been made static as a result of Export",
6142 Arg, E);
6143 Error_Msg_N
6144 ("\?x?this usage is non-standard and non-portable",
6145 Arg);
6146 end if;
6147 end if;
6148 end if;
6149
6150 if Warn_On_Export_Import and then Is_Type (E) then
6151 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
6152 end if;
6153
6154 if Warn_On_Export_Import and Inside_A_Generic then
6155 Error_Msg_NE
6156 ("all instances of& will have the same external name?x?",
6157 Arg, E);
6158 end if;
6159 end Set_Exported;
6160
6161 ----------------------------------------------
6162 -- Set_Extended_Import_Export_External_Name --
6163 ----------------------------------------------
6164
6165 procedure Set_Extended_Import_Export_External_Name
6166 (Internal_Ent : Entity_Id;
6167 Arg_External : Node_Id)
6168 is
6169 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
6170 New_Name : Node_Id;
6171
6172 begin
6173 if No (Arg_External) then
6174 return;
6175 end if;
6176
6177 Check_Arg_Is_External_Name (Arg_External);
6178
6179 if Nkind (Arg_External) = N_String_Literal then
6180 if String_Length (Strval (Arg_External)) = 0 then
6181 return;
6182 else
6183 New_Name := Adjust_External_Name_Case (Arg_External);
6184 end if;
6185
6186 elsif Nkind (Arg_External) = N_Identifier then
6187 New_Name := Get_Default_External_Name (Arg_External);
6188
6189 -- Check_Arg_Is_External_Name should let through only identifiers and
6190 -- string literals or static string expressions (which are folded to
6191 -- string literals).
6192
6193 else
6194 raise Program_Error;
6195 end if;
6196
6197 -- If we already have an external name set (by a prior normal Import
6198 -- or Export pragma), then the external names must match
6199
6200 if Present (Interface_Name (Internal_Ent)) then
6201 Check_Matching_Internal_Names : declare
6202 S1 : constant String_Id := Strval (Old_Name);
6203 S2 : constant String_Id := Strval (New_Name);
6204
6205 procedure Mismatch;
6206 pragma No_Return (Mismatch);
6207 -- Called if names do not match
6208
6209 --------------
6210 -- Mismatch --
6211 --------------
6212
6213 procedure Mismatch is
6214 begin
6215 Error_Msg_Sloc := Sloc (Old_Name);
6216 Error_Pragma_Arg
6217 ("external name does not match that given #",
6218 Arg_External);
6219 end Mismatch;
6220
6221 -- Start of processing for Check_Matching_Internal_Names
6222
6223 begin
6224 if String_Length (S1) /= String_Length (S2) then
6225 Mismatch;
6226
6227 else
6228 for J in 1 .. String_Length (S1) loop
6229 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
6230 Mismatch;
6231 end if;
6232 end loop;
6233 end if;
6234 end Check_Matching_Internal_Names;
6235
6236 -- Otherwise set the given name
6237
6238 else
6239 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
6240 Check_Duplicated_Export_Name (New_Name);
6241 end if;
6242 end Set_Extended_Import_Export_External_Name;
6243
6244 ------------------
6245 -- Set_Imported --
6246 ------------------
6247
6248 procedure Set_Imported (E : Entity_Id) is
6249 begin
6250 -- Error message if already imported or exported
6251
6252 if Is_Exported (E) or else Is_Imported (E) then
6253
6254 -- Error if being set Exported twice
6255
6256 if Is_Exported (E) then
6257 Error_Msg_NE ("entity& was previously exported", N, E);
6258
6259 -- Ignore error in CodePeer mode where we treat all imported
6260 -- subprograms as unknown.
6261
6262 elsif CodePeer_Mode then
6263 goto OK;
6264
6265 -- OK if Import/Interface case
6266
6267 elsif Import_Interface_Present (N) then
6268 goto OK;
6269
6270 -- Error if being set Imported twice
6271
6272 else
6273 Error_Msg_NE ("entity& was previously imported", N, E);
6274 end if;
6275
6276 Error_Msg_Name_1 := Pname;
6277 Error_Msg_N
6278 ("\(pragma% applies to all previous entities)", N);
6279
6280 Error_Msg_Sloc := Sloc (E);
6281 Error_Msg_NE ("\import not allowed for& declared#", N, E);
6282
6283 -- Here if not previously imported or exported, OK to import
6284
6285 else
6286 Set_Is_Imported (E);
6287
6288 -- If the entity is an object that is not at the library level,
6289 -- then it is statically allocated. We do not worry about objects
6290 -- with address clauses in this context since they are not really
6291 -- imported in the linker sense.
6292
6293 if Is_Object (E)
6294 and then not Is_Library_Level_Entity (E)
6295 and then No (Address_Clause (E))
6296 then
6297 Set_Is_Statically_Allocated (E);
6298 end if;
6299 end if;
6300
6301 <<OK>> null;
6302 end Set_Imported;
6303
6304 -------------------------
6305 -- Set_Mechanism_Value --
6306 -------------------------
6307
6308 -- Note: the mechanism name has not been analyzed (and cannot indeed be
6309 -- analyzed, since it is semantic nonsense), so we get it in the exact
6310 -- form created by the parser.
6311
6312 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
6313 Class : Node_Id;
6314 Param : Node_Id;
6315 Mech_Name_Id : Name_Id;
6316
6317 procedure Bad_Class;
6318 pragma No_Return (Bad_Class);
6319 -- Signal bad descriptor class name
6320
6321 procedure Bad_Mechanism;
6322 pragma No_Return (Bad_Mechanism);
6323 -- Signal bad mechanism name
6324
6325 ---------------
6326 -- Bad_Class --
6327 ---------------
6328
6329 procedure Bad_Class is
6330 begin
6331 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
6332 end Bad_Class;
6333
6334 -------------------------
6335 -- Bad_Mechanism_Value --
6336 -------------------------
6337
6338 procedure Bad_Mechanism is
6339 begin
6340 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
6341 end Bad_Mechanism;
6342
6343 -- Start of processing for Set_Mechanism_Value
6344
6345 begin
6346 if Mechanism (Ent) /= Default_Mechanism then
6347 Error_Msg_NE
6348 ("mechanism for & has already been set", Mech_Name, Ent);
6349 end if;
6350
6351 -- MECHANISM_NAME ::= value | reference | descriptor |
6352 -- short_descriptor
6353
6354 if Nkind (Mech_Name) = N_Identifier then
6355 if Chars (Mech_Name) = Name_Value then
6356 Set_Mechanism (Ent, By_Copy);
6357 return;
6358
6359 elsif Chars (Mech_Name) = Name_Reference then
6360 Set_Mechanism (Ent, By_Reference);
6361 return;
6362
6363 elsif Chars (Mech_Name) = Name_Descriptor then
6364 Check_VMS (Mech_Name);
6365
6366 -- Descriptor => Short_Descriptor if pragma was given
6367
6368 if Short_Descriptors then
6369 Set_Mechanism (Ent, By_Short_Descriptor);
6370 else
6371 Set_Mechanism (Ent, By_Descriptor);
6372 end if;
6373
6374 return;
6375
6376 elsif Chars (Mech_Name) = Name_Short_Descriptor then
6377 Check_VMS (Mech_Name);
6378 Set_Mechanism (Ent, By_Short_Descriptor);
6379 return;
6380
6381 elsif Chars (Mech_Name) = Name_Copy then
6382 Error_Pragma_Arg
6383 ("bad mechanism name, Value assumed", Mech_Name);
6384
6385 else
6386 Bad_Mechanism;
6387 end if;
6388
6389 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
6390 -- short_descriptor (CLASS_NAME)
6391 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6392
6393 -- Note: this form is parsed as an indexed component
6394
6395 elsif Nkind (Mech_Name) = N_Indexed_Component then
6396 Class := First (Expressions (Mech_Name));
6397
6398 if Nkind (Prefix (Mech_Name)) /= N_Identifier
6399 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
6400 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
6401 or else Present (Next (Class))
6402 then
6403 Bad_Mechanism;
6404 else
6405 Mech_Name_Id := Chars (Prefix (Mech_Name));
6406
6407 -- Change Descriptor => Short_Descriptor if pragma was given
6408
6409 if Mech_Name_Id = Name_Descriptor
6410 and then Short_Descriptors
6411 then
6412 Mech_Name_Id := Name_Short_Descriptor;
6413 end if;
6414 end if;
6415
6416 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
6417 -- short_descriptor (Class => CLASS_NAME)
6418 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6419
6420 -- Note: this form is parsed as a function call
6421
6422 elsif Nkind (Mech_Name) = N_Function_Call then
6423 Param := First (Parameter_Associations (Mech_Name));
6424
6425 if Nkind (Name (Mech_Name)) /= N_Identifier
6426 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6427 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6428 or else Present (Next (Param))
6429 or else No (Selector_Name (Param))
6430 or else Chars (Selector_Name (Param)) /= Name_Class
6431 then
6432 Bad_Mechanism;
6433 else
6434 Class := Explicit_Actual_Parameter (Param);
6435 Mech_Name_Id := Chars (Name (Mech_Name));
6436 end if;
6437
6438 else
6439 Bad_Mechanism;
6440 end if;
6441
6442 -- Fall through here with Class set to descriptor class name
6443
6444 Check_VMS (Mech_Name);
6445
6446 if Nkind (Class) /= N_Identifier then
6447 Bad_Class;
6448
6449 elsif Mech_Name_Id = Name_Descriptor
6450 and then Chars (Class) = Name_UBS
6451 then
6452 Set_Mechanism (Ent, By_Descriptor_UBS);
6453
6454 elsif Mech_Name_Id = Name_Descriptor
6455 and then Chars (Class) = Name_UBSB
6456 then
6457 Set_Mechanism (Ent, By_Descriptor_UBSB);
6458
6459 elsif Mech_Name_Id = Name_Descriptor
6460 and then Chars (Class) = Name_UBA
6461 then
6462 Set_Mechanism (Ent, By_Descriptor_UBA);
6463
6464 elsif Mech_Name_Id = Name_Descriptor
6465 and then Chars (Class) = Name_S
6466 then
6467 Set_Mechanism (Ent, By_Descriptor_S);
6468
6469 elsif Mech_Name_Id = Name_Descriptor
6470 and then Chars (Class) = Name_SB
6471 then
6472 Set_Mechanism (Ent, By_Descriptor_SB);
6473
6474 elsif Mech_Name_Id = Name_Descriptor
6475 and then Chars (Class) = Name_A
6476 then
6477 Set_Mechanism (Ent, By_Descriptor_A);
6478
6479 elsif Mech_Name_Id = Name_Descriptor
6480 and then Chars (Class) = Name_NCA
6481 then
6482 Set_Mechanism (Ent, By_Descriptor_NCA);
6483
6484 elsif Mech_Name_Id = Name_Short_Descriptor
6485 and then Chars (Class) = Name_UBS
6486 then
6487 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6488
6489 elsif Mech_Name_Id = Name_Short_Descriptor
6490 and then Chars (Class) = Name_UBSB
6491 then
6492 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6493
6494 elsif Mech_Name_Id = Name_Short_Descriptor
6495 and then Chars (Class) = Name_UBA
6496 then
6497 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6498
6499 elsif Mech_Name_Id = Name_Short_Descriptor
6500 and then Chars (Class) = Name_S
6501 then
6502 Set_Mechanism (Ent, By_Short_Descriptor_S);
6503
6504 elsif Mech_Name_Id = Name_Short_Descriptor
6505 and then Chars (Class) = Name_SB
6506 then
6507 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6508
6509 elsif Mech_Name_Id = Name_Short_Descriptor
6510 and then Chars (Class) = Name_A
6511 then
6512 Set_Mechanism (Ent, By_Short_Descriptor_A);
6513
6514 elsif Mech_Name_Id = Name_Short_Descriptor
6515 and then Chars (Class) = Name_NCA
6516 then
6517 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6518
6519 else
6520 Bad_Class;
6521 end if;
6522 end Set_Mechanism_Value;
6523
6524 --------------------------
6525 -- Set_Rational_Profile --
6526 --------------------------
6527
6528 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
6529 -- and extension to the semantics of renaming declarations.
6530
6531 procedure Set_Rational_Profile is
6532 begin
6533 Implicit_Packing := True;
6534 Overriding_Renamings := True;
6535 Use_VADS_Size := True;
6536 end Set_Rational_Profile;
6537
6538 ---------------------------
6539 -- Set_Ravenscar_Profile --
6540 ---------------------------
6541
6542 -- The tasks to be done here are
6543
6544 -- Set required policies
6545
6546 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6547 -- pragma Locking_Policy (Ceiling_Locking)
6548
6549 -- Set Detect_Blocking mode
6550
6551 -- Set required restrictions (see System.Rident for detailed list)
6552
6553 -- Set the No_Dependence rules
6554 -- No_Dependence => Ada.Asynchronous_Task_Control
6555 -- No_Dependence => Ada.Calendar
6556 -- No_Dependence => Ada.Execution_Time.Group_Budget
6557 -- No_Dependence => Ada.Execution_Time.Timers
6558 -- No_Dependence => Ada.Task_Attributes
6559 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6560
6561 procedure Set_Ravenscar_Profile (N : Node_Id) is
6562 Prefix_Entity : Entity_Id;
6563 Selector_Entity : Entity_Id;
6564 Prefix_Node : Node_Id;
6565 Node : Node_Id;
6566
6567 begin
6568 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6569
6570 if Task_Dispatching_Policy /= ' '
6571 and then Task_Dispatching_Policy /= 'F'
6572 then
6573 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6574 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6575
6576 -- Set the FIFO_Within_Priorities policy, but always preserve
6577 -- System_Location since we like the error message with the run time
6578 -- name.
6579
6580 else
6581 Task_Dispatching_Policy := 'F';
6582
6583 if Task_Dispatching_Policy_Sloc /= System_Location then
6584 Task_Dispatching_Policy_Sloc := Loc;
6585 end if;
6586 end if;
6587
6588 -- pragma Locking_Policy (Ceiling_Locking)
6589
6590 if Locking_Policy /= ' '
6591 and then Locking_Policy /= 'C'
6592 then
6593 Error_Msg_Sloc := Locking_Policy_Sloc;
6594 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6595
6596 -- Set the Ceiling_Locking policy, but preserve System_Location since
6597 -- we like the error message with the run time name.
6598
6599 else
6600 Locking_Policy := 'C';
6601
6602 if Locking_Policy_Sloc /= System_Location then
6603 Locking_Policy_Sloc := Loc;
6604 end if;
6605 end if;
6606
6607 -- pragma Detect_Blocking
6608
6609 Detect_Blocking := True;
6610
6611 -- Set the corresponding restrictions
6612
6613 Set_Profile_Restrictions
6614 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6615
6616 -- Set the No_Dependence restrictions
6617
6618 -- The following No_Dependence restrictions:
6619 -- No_Dependence => Ada.Asynchronous_Task_Control
6620 -- No_Dependence => Ada.Calendar
6621 -- No_Dependence => Ada.Task_Attributes
6622 -- are already set by previous call to Set_Profile_Restrictions.
6623
6624 -- Set the following restrictions which were added to Ada 2005:
6625 -- No_Dependence => Ada.Execution_Time.Group_Budget
6626 -- No_Dependence => Ada.Execution_Time.Timers
6627
6628 if Ada_Version >= Ada_2005 then
6629 Name_Buffer (1 .. 3) := "ada";
6630 Name_Len := 3;
6631
6632 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6633
6634 Name_Buffer (1 .. 14) := "execution_time";
6635 Name_Len := 14;
6636
6637 Selector_Entity := Make_Identifier (Loc, Name_Find);
6638
6639 Prefix_Node :=
6640 Make_Selected_Component
6641 (Sloc => Loc,
6642 Prefix => Prefix_Entity,
6643 Selector_Name => Selector_Entity);
6644
6645 Name_Buffer (1 .. 13) := "group_budgets";
6646 Name_Len := 13;
6647
6648 Selector_Entity := Make_Identifier (Loc, Name_Find);
6649
6650 Node :=
6651 Make_Selected_Component
6652 (Sloc => Loc,
6653 Prefix => Prefix_Node,
6654 Selector_Name => Selector_Entity);
6655
6656 Set_Restriction_No_Dependence
6657 (Unit => Node,
6658 Warn => Treat_Restrictions_As_Warnings,
6659 Profile => Ravenscar);
6660
6661 Name_Buffer (1 .. 6) := "timers";
6662 Name_Len := 6;
6663
6664 Selector_Entity := Make_Identifier (Loc, Name_Find);
6665
6666 Node :=
6667 Make_Selected_Component
6668 (Sloc => Loc,
6669 Prefix => Prefix_Node,
6670 Selector_Name => Selector_Entity);
6671
6672 Set_Restriction_No_Dependence
6673 (Unit => Node,
6674 Warn => Treat_Restrictions_As_Warnings,
6675 Profile => Ravenscar);
6676 end if;
6677
6678 -- Set the following restrictions which was added to Ada 2012 (see
6679 -- AI-0171):
6680 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6681
6682 if Ada_Version >= Ada_2012 then
6683 Name_Buffer (1 .. 6) := "system";
6684 Name_Len := 6;
6685
6686 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6687
6688 Name_Buffer (1 .. 15) := "multiprocessors";
6689 Name_Len := 15;
6690
6691 Selector_Entity := Make_Identifier (Loc, Name_Find);
6692
6693 Prefix_Node :=
6694 Make_Selected_Component
6695 (Sloc => Loc,
6696 Prefix => Prefix_Entity,
6697 Selector_Name => Selector_Entity);
6698
6699 Name_Buffer (1 .. 19) := "dispatching_domains";
6700 Name_Len := 19;
6701
6702 Selector_Entity := Make_Identifier (Loc, Name_Find);
6703
6704 Node :=
6705 Make_Selected_Component
6706 (Sloc => Loc,
6707 Prefix => Prefix_Node,
6708 Selector_Name => Selector_Entity);
6709
6710 Set_Restriction_No_Dependence
6711 (Unit => Node,
6712 Warn => Treat_Restrictions_As_Warnings,
6713 Profile => Ravenscar);
6714 end if;
6715 end Set_Ravenscar_Profile;
6716
6717 ----------------
6718 -- S14_Pragma --
6719 ----------------
6720
6721 procedure S14_Pragma is
6722 begin
6723 if not Formal_Extensions then
6724 Error_Pragma ("pragma% requires the use of debug switch -gnatd.V");
6725 end if;
6726 end S14_Pragma;
6727
6728 -- Start of processing for Analyze_Pragma
6729
6730 begin
6731 -- The following code is a defense against recursion. Not clear that
6732 -- this can happen legitimately, but perhaps some error situations
6733 -- can cause it, and we did see this recursion during testing.
6734
6735 if Analyzed (N) then
6736 return;
6737 else
6738 Set_Analyzed (N, True);
6739 end if;
6740
6741 -- Deal with unrecognized pragma
6742
6743 Pname := Pragma_Name (N);
6744
6745 if not Is_Pragma_Name (Pname) then
6746 if Warn_On_Unrecognized_Pragma then
6747 Error_Msg_Name_1 := Pname;
6748 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
6749
6750 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6751 if Is_Bad_Spelling_Of (Pname, PN) then
6752 Error_Msg_Name_1 := PN;
6753 Error_Msg_N -- CODEFIX
6754 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
6755 exit;
6756 end if;
6757 end loop;
6758 end if;
6759
6760 return;
6761 end if;
6762
6763 -- Here to start processing for recognized pragma
6764
6765 Prag_Id := Get_Pragma_Id (Pname);
6766
6767 if Present (Corresponding_Aspect (N)) then
6768 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6769 end if;
6770
6771 -- Preset arguments
6772
6773 Arg_Count := 0;
6774 Arg1 := Empty;
6775 Arg2 := Empty;
6776 Arg3 := Empty;
6777 Arg4 := Empty;
6778
6779 if Present (Pragma_Argument_Associations (N)) then
6780 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6781 Arg1 := First (Pragma_Argument_Associations (N));
6782
6783 if Present (Arg1) then
6784 Arg2 := Next (Arg1);
6785
6786 if Present (Arg2) then
6787 Arg3 := Next (Arg2);
6788
6789 if Present (Arg3) then
6790 Arg4 := Next (Arg3);
6791 end if;
6792 end if;
6793 end if;
6794 end if;
6795
6796 Check_Restriction_No_Use_Of_Pragma (N);
6797
6798 -- An enumeration type defines the pragmas that are supported by the
6799 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6800 -- into the corresponding enumeration value for the following case.
6801
6802 case Prag_Id is
6803
6804 -----------------
6805 -- Abort_Defer --
6806 -----------------
6807
6808 -- pragma Abort_Defer;
6809
6810 when Pragma_Abort_Defer =>
6811 GNAT_Pragma;
6812 Check_Arg_Count (0);
6813
6814 -- The only required semantic processing is to check the
6815 -- placement. This pragma must appear at the start of the
6816 -- statement sequence of a handled sequence of statements.
6817
6818 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6819 or else N /= First (Statements (Parent (N)))
6820 then
6821 Pragma_Misplaced;
6822 end if;
6823
6824 --------------------
6825 -- Abstract_State --
6826 --------------------
6827
6828 -- pragma Abstract_State (ABSTRACT_STATE_LIST)
6829
6830 -- ABSTRACT_STATE_LIST ::=
6831 -- null
6832 -- | STATE_NAME_WITH_PROPERTIES {, STATE_NAME_WITH_PROPERTIES}
6833
6834 -- STATE_NAME_WITH_PROPERTIES ::=
6835 -- STATE_NAME
6836 -- | (STATE_NAME with PROPERTY_LIST)
6837
6838 -- PROPERTY_LIST ::= PROPERTY {, PROPERTY}
6839 -- PROPERTY ::= SIMPLE_PROPERTY | NAME_VALUE_PROPERTY
6840
6841 -- SIMPLE_PROPERTY ::= IDENTIFIER
6842 -- NAME_VALUE_PROPERTY ::= IDENTIFIER => EXPRESSION
6843
6844 -- STATE_NAME ::= DEFINING_IDENTIFIER
6845
6846 when Pragma_Abstract_State => Abstract_State : declare
6847 Pack_Id : Entity_Id;
6848
6849 -- Flags used to verify the consistency of states
6850
6851 Non_Null_Seen : Boolean := False;
6852 Null_Seen : Boolean := False;
6853
6854 procedure Analyze_Abstract_State (State : Node_Id);
6855 -- Verify the legality of a single state declaration. Create and
6856 -- decorate a state abstraction entity and introduce it into the
6857 -- visibility chain.
6858
6859 ----------------------------
6860 -- Analyze_Abstract_State --
6861 ----------------------------
6862
6863 procedure Analyze_Abstract_State (State : Node_Id) is
6864 procedure Check_Duplicate_Property
6865 (Prop : Node_Id;
6866 Status : in out Boolean);
6867 -- Flag Status denotes whether a particular property has been
6868 -- seen while processing a state. This routine verifies that
6869 -- Prop is not a duplicate property and sets the flag Status.
6870
6871 ------------------------------
6872 -- Check_Duplicate_Property --
6873 ------------------------------
6874
6875 procedure Check_Duplicate_Property
6876 (Prop : Node_Id;
6877 Status : in out Boolean)
6878 is
6879 begin
6880 if Status then
6881 Error_Msg_N ("duplicate state property", Prop);
6882 end if;
6883
6884 Status := True;
6885 end Check_Duplicate_Property;
6886
6887 -- Local variables
6888
6889 Errors : constant Nat := Serious_Errors_Detected;
6890 Loc : constant Source_Ptr := Sloc (State);
6891 Assoc : Node_Id;
6892 Id : Entity_Id;
6893 Is_Null : Boolean := False;
6894 Level : Uint := Uint_0;
6895 Name : Name_Id;
6896 Prop : Node_Id;
6897
6898 -- Flags used to verify the consistency of properties
6899
6900 Input_Seen : Boolean := False;
6901 Integrity_Seen : Boolean := False;
6902 Output_Seen : Boolean := False;
6903 Volatile_Seen : Boolean := False;
6904
6905 -- Start of processing for Analyze_Abstract_State
6906
6907 begin
6908 -- A package with a null abstract state is not allowed to
6909 -- declare additional states.
6910
6911 if Null_Seen then
6912 Error_Msg_NE
6913 ("package & has null abstract state", State, Pack_Id);
6914
6915 -- Null states appear as internally generated entities
6916
6917 elsif Nkind (State) = N_Null then
6918 Name := New_Internal_Name ('S');
6919 Is_Null := True;
6920 Null_Seen := True;
6921
6922 -- Catch a case where a null state appears in a list of
6923 -- non-null states.
6924
6925 if Non_Null_Seen then
6926 Error_Msg_NE
6927 ("package & has non-null abstract state",
6928 State, Pack_Id);
6929 end if;
6930
6931 -- Simple state declaration
6932
6933 elsif Nkind (State) = N_Identifier then
6934 Name := Chars (State);
6935 Non_Null_Seen := True;
6936
6937 -- State declaration with various properties. This construct
6938 -- appears as an extension aggregate in the tree.
6939
6940 elsif Nkind (State) = N_Extension_Aggregate then
6941 if Nkind (Ancestor_Part (State)) = N_Identifier then
6942 Name := Chars (Ancestor_Part (State));
6943 Non_Null_Seen := True;
6944 else
6945 Error_Msg_N
6946 ("state name must be an identifier",
6947 Ancestor_Part (State));
6948 end if;
6949
6950 -- Process properties Input, Output and Volatile. Ensure
6951 -- that none of them appear more than once.
6952
6953 Prop := First (Expressions (State));
6954 while Present (Prop) loop
6955 if Nkind (Prop) = N_Identifier then
6956 if Chars (Prop) = Name_Input then
6957 Check_Duplicate_Property (Prop, Input_Seen);
6958 elsif Chars (Prop) = Name_Output then
6959 Check_Duplicate_Property (Prop, Output_Seen);
6960 elsif Chars (Prop) = Name_Volatile then
6961 Check_Duplicate_Property (Prop, Volatile_Seen);
6962 else
6963 Error_Msg_N ("invalid state property", Prop);
6964 end if;
6965 else
6966 Error_Msg_N ("invalid state property", Prop);
6967 end if;
6968
6969 Next (Prop);
6970 end loop;
6971
6972 -- Volatile requires exactly one Input or Output
6973
6974 if Volatile_Seen
6975 and then
6976 ((Input_Seen and then Output_Seen) -- both
6977 or else
6978 (not Input_Seen and then not Output_Seen)) -- none
6979 then
6980 Error_Msg_N
6981 ("property Volatile requires exactly one Input or "
6982 & "Output", State);
6983 end if;
6984
6985 -- Either Input or Output require Volatile
6986
6987 if (Input_Seen or Output_Seen)
6988 and then not Volatile_Seen
6989 then
6990 Error_Msg_N
6991 ("properties Input and Output require Volatile", State);
6992 end if;
6993
6994 -- State property Integrity appears as a component
6995 -- association.
6996
6997 Assoc := First (Component_Associations (State));
6998 while Present (Assoc) loop
6999 Prop := First (Choices (Assoc));
7000 while Present (Prop) loop
7001 if Nkind (Prop) = N_Identifier
7002 and then Chars (Prop) = Name_Integrity
7003 then
7004 Check_Duplicate_Property (Prop, Integrity_Seen);
7005 else
7006 Error_Msg_N ("invalid state property", Prop);
7007 end if;
7008
7009 Next (Prop);
7010 end loop;
7011
7012 if Nkind (Expression (Assoc)) = N_Integer_Literal then
7013 Level := Intval (Expression (Assoc));
7014 else
7015 Error_Msg_N
7016 ("integrity level must be an integer literal",
7017 Expression (Assoc));
7018 end if;
7019
7020 Next (Assoc);
7021 end loop;
7022
7023 -- Any other attempt to declare a state is erroneous
7024
7025 else
7026 Error_Msg_N ("malformed abstract state declaration", State);
7027 end if;
7028
7029 -- Do not generate a state abstraction entity if it was not
7030 -- properly declared.
7031
7032 if Serious_Errors_Detected > Errors then
7033 return;
7034 end if;
7035
7036 -- The generated state abstraction reuses the same characters
7037 -- from the original state declaration. Decorate the entity.
7038
7039 Id := Make_Defining_Identifier (Loc, New_External_Name (Name));
7040 Set_Comes_From_Source (Id, not Is_Null);
7041 Set_Parent (Id, State);
7042 Set_Ekind (Id, E_Abstract_State);
7043 Set_Etype (Id, Standard_Void_Type);
7044 Set_Integrity_Level (Id, Level);
7045 Set_Refined_State (Id, Empty);
7046
7047 -- Every non-null state must be nameable and resolvable the
7048 -- same way a constant is.
7049
7050 if not Is_Null then
7051 Push_Scope (Pack_Id);
7052 Enter_Name (Id);
7053 Pop_Scope;
7054 end if;
7055
7056 -- Associate the state with its related package
7057
7058 if No (Abstract_States (Pack_Id)) then
7059 Set_Abstract_States (Pack_Id, New_Elmt_List);
7060 end if;
7061
7062 Append_Elmt (Id, Abstract_States (Pack_Id));
7063 end Analyze_Abstract_State;
7064
7065 -- Local variables
7066
7067 Par : Node_Id;
7068 State : Node_Id;
7069
7070 -- Start of processing for Abstract_State
7071
7072 begin
7073 GNAT_Pragma;
7074 S14_Pragma;
7075 Check_Arg_Count (1);
7076
7077 -- Ensure the proper placement of the pragma. Abstract states must
7078 -- be associated with a package declaration.
7079
7080 if From_Aspect_Specification (N) then
7081 Par := Parent (Corresponding_Aspect (N));
7082 else
7083 Par := Parent (Parent (N));
7084 end if;
7085
7086 if Nkind (Par) = N_Compilation_Unit then
7087 Par := Unit (Par);
7088 end if;
7089
7090 if Nkind (Par) /= N_Package_Declaration then
7091 Pragma_Misplaced;
7092 return;
7093 end if;
7094
7095 Pack_Id := Defining_Entity (Par);
7096 State := Expression (Arg1);
7097
7098 -- Multiple abstract states appear as an aggregate
7099
7100 if Nkind (State) = N_Aggregate then
7101 State := First (Expressions (State));
7102 while Present (State) loop
7103 Analyze_Abstract_State (State);
7104
7105 Next (State);
7106 end loop;
7107
7108 -- Various forms of a single abstract state. Note that these may
7109 -- include malformed state declarations.
7110
7111 else
7112 Analyze_Abstract_State (State);
7113 end if;
7114 end Abstract_State;
7115
7116 ------------
7117 -- Ada_83 --
7118 ------------
7119
7120 -- pragma Ada_83;
7121
7122 -- Note: this pragma also has some specific processing in Par.Prag
7123 -- because we want to set the Ada version mode during parsing.
7124
7125 when Pragma_Ada_83 =>
7126 GNAT_Pragma;
7127 Check_Arg_Count (0);
7128
7129 -- We really should check unconditionally for proper configuration
7130 -- pragma placement, since we really don't want mixed Ada modes
7131 -- within a single unit, and the GNAT reference manual has always
7132 -- said this was a configuration pragma, but we did not check and
7133 -- are hesitant to add the check now.
7134
7135 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
7136 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
7137 -- or Ada 2012 mode.
7138
7139 if Ada_Version >= Ada_2005 then
7140 Check_Valid_Configuration_Pragma;
7141 end if;
7142
7143 -- Now set Ada 83 mode
7144
7145 Ada_Version := Ada_83;
7146 Ada_Version_Explicit := Ada_Version;
7147
7148 ------------
7149 -- Ada_95 --
7150 ------------
7151
7152 -- pragma Ada_95;
7153
7154 -- Note: this pragma also has some specific processing in Par.Prag
7155 -- because we want to set the Ada 83 version mode during parsing.
7156
7157 when Pragma_Ada_95 =>
7158 GNAT_Pragma;
7159 Check_Arg_Count (0);
7160
7161 -- We really should check unconditionally for proper configuration
7162 -- pragma placement, since we really don't want mixed Ada modes
7163 -- within a single unit, and the GNAT reference manual has always
7164 -- said this was a configuration pragma, but we did not check and
7165 -- are hesitant to add the check now.
7166
7167 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
7168 -- or Ada 95, so we must check if we are in Ada 2005 mode.
7169
7170 if Ada_Version >= Ada_2005 then
7171 Check_Valid_Configuration_Pragma;
7172 end if;
7173
7174 -- Now set Ada 95 mode
7175
7176 Ada_Version := Ada_95;
7177 Ada_Version_Explicit := Ada_Version;
7178
7179 ---------------------
7180 -- Ada_05/Ada_2005 --
7181 ---------------------
7182
7183 -- pragma Ada_05;
7184 -- pragma Ada_05 (LOCAL_NAME);
7185
7186 -- pragma Ada_2005;
7187 -- pragma Ada_2005 (LOCAL_NAME):
7188
7189 -- Note: these pragmas also have some specific processing in Par.Prag
7190 -- because we want to set the Ada 2005 version mode during parsing.
7191
7192 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
7193 E_Id : Node_Id;
7194
7195 begin
7196 GNAT_Pragma;
7197
7198 if Arg_Count = 1 then
7199 Check_Arg_Is_Local_Name (Arg1);
7200 E_Id := Get_Pragma_Arg (Arg1);
7201
7202 if Etype (E_Id) = Any_Type then
7203 return;
7204 end if;
7205
7206 Set_Is_Ada_2005_Only (Entity (E_Id));
7207 Record_Rep_Item (Entity (E_Id), N);
7208
7209 else
7210 Check_Arg_Count (0);
7211
7212 -- For Ada_2005 we unconditionally enforce the documented
7213 -- configuration pragma placement, since we do not want to
7214 -- tolerate mixed modes in a unit involving Ada 2005. That
7215 -- would cause real difficulties for those cases where there
7216 -- are incompatibilities between Ada 95 and Ada 2005.
7217
7218 Check_Valid_Configuration_Pragma;
7219
7220 -- Now set appropriate Ada mode
7221
7222 Ada_Version := Ada_2005;
7223 Ada_Version_Explicit := Ada_2005;
7224 end if;
7225 end;
7226
7227 ---------------------
7228 -- Ada_12/Ada_2012 --
7229 ---------------------
7230
7231 -- pragma Ada_12;
7232 -- pragma Ada_12 (LOCAL_NAME);
7233
7234 -- pragma Ada_2012;
7235 -- pragma Ada_2012 (LOCAL_NAME):
7236
7237 -- Note: these pragmas also have some specific processing in Par.Prag
7238 -- because we want to set the Ada 2012 version mode during parsing.
7239
7240 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
7241 E_Id : Node_Id;
7242
7243 begin
7244 GNAT_Pragma;
7245
7246 if Arg_Count = 1 then
7247 Check_Arg_Is_Local_Name (Arg1);
7248 E_Id := Get_Pragma_Arg (Arg1);
7249
7250 if Etype (E_Id) = Any_Type then
7251 return;
7252 end if;
7253
7254 Set_Is_Ada_2012_Only (Entity (E_Id));
7255 Record_Rep_Item (Entity (E_Id), N);
7256
7257 else
7258 Check_Arg_Count (0);
7259
7260 -- For Ada_2012 we unconditionally enforce the documented
7261 -- configuration pragma placement, since we do not want to
7262 -- tolerate mixed modes in a unit involving Ada 2012. That
7263 -- would cause real difficulties for those cases where there
7264 -- are incompatibilities between Ada 95 and Ada 2012. We could
7265 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
7266
7267 Check_Valid_Configuration_Pragma;
7268
7269 -- Now set appropriate Ada mode
7270
7271 Ada_Version := Ada_2012;
7272 Ada_Version_Explicit := Ada_2012;
7273 end if;
7274 end;
7275
7276 ----------------------
7277 -- All_Calls_Remote --
7278 ----------------------
7279
7280 -- pragma All_Calls_Remote [(library_package_NAME)];
7281
7282 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
7283 Lib_Entity : Entity_Id;
7284
7285 begin
7286 Check_Ada_83_Warning;
7287 Check_Valid_Library_Unit_Pragma;
7288
7289 if Nkind (N) = N_Null_Statement then
7290 return;
7291 end if;
7292
7293 Lib_Entity := Find_Lib_Unit_Name;
7294
7295 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
7296
7297 if Present (Lib_Entity)
7298 and then not Debug_Flag_U
7299 then
7300 if not Is_Remote_Call_Interface (Lib_Entity) then
7301 Error_Pragma ("pragma% only apply to rci unit");
7302
7303 -- Set flag for entity of the library unit
7304
7305 else
7306 Set_Has_All_Calls_Remote (Lib_Entity);
7307 end if;
7308
7309 end if;
7310 end All_Calls_Remote;
7311
7312 --------------
7313 -- Annotate --
7314 --------------
7315
7316 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
7317 -- ARG ::= NAME | EXPRESSION
7318
7319 -- The first two arguments are by convention intended to refer to an
7320 -- external tool and a tool-specific function. These arguments are
7321 -- not analyzed.
7322
7323 when Pragma_Annotate => Annotate : declare
7324 Arg : Node_Id;
7325 Exp : Node_Id;
7326
7327 begin
7328 GNAT_Pragma;
7329 Check_At_Least_N_Arguments (1);
7330 Check_Arg_Is_Identifier (Arg1);
7331 Check_No_Identifiers;
7332 Store_Note (N);
7333
7334 -- Second parameter is optional, it is never analyzed
7335
7336 if No (Arg2) then
7337 null;
7338
7339 -- Here if we have a second parameter
7340
7341 else
7342 -- Second parameter must be identifier
7343
7344 Check_Arg_Is_Identifier (Arg2);
7345
7346 -- Process remaining parameters if any
7347
7348 Arg := Next (Arg2);
7349 while Present (Arg) loop
7350 Exp := Get_Pragma_Arg (Arg);
7351 Analyze (Exp);
7352
7353 if Is_Entity_Name (Exp) then
7354 null;
7355
7356 -- For string literals, we assume Standard_String as the
7357 -- type, unless the string contains wide or wide_wide
7358 -- characters.
7359
7360 elsif Nkind (Exp) = N_String_Literal then
7361 if Has_Wide_Wide_Character (Exp) then
7362 Resolve (Exp, Standard_Wide_Wide_String);
7363 elsif Has_Wide_Character (Exp) then
7364 Resolve (Exp, Standard_Wide_String);
7365 else
7366 Resolve (Exp, Standard_String);
7367 end if;
7368
7369 elsif Is_Overloaded (Exp) then
7370 Error_Pragma_Arg
7371 ("ambiguous argument for pragma%", Exp);
7372
7373 else
7374 Resolve (Exp);
7375 end if;
7376
7377 Next (Arg);
7378 end loop;
7379 end if;
7380 end Annotate;
7381
7382 ---------------------------
7383 -- Assert/Assert_And_Cut --
7384 ---------------------------
7385
7386 -- pragma Assert
7387 -- ( [Check => ] Boolean_EXPRESSION
7388 -- [, [Message =>] Static_String_EXPRESSION]);
7389
7390 -- pragma Assert_And_Cut
7391 -- ( [Check => ] Boolean_EXPRESSION
7392 -- [, [Message =>] Static_String_EXPRESSION]);
7393
7394 when Pragma_Assert | Pragma_Assert_And_Cut => Assert : declare
7395 Expr : Node_Id;
7396 Newa : List_Id;
7397
7398 begin
7399 if Prag_Id = Pragma_Assert then
7400 Ada_2005_Pragma;
7401 else -- Pragma_Assert_And_Cut
7402 GNAT_Pragma;
7403 S14_Pragma;
7404 end if;
7405
7406 Check_At_Least_N_Arguments (1);
7407 Check_At_Most_N_Arguments (2);
7408 Check_Arg_Order ((Name_Check, Name_Message));
7409 Check_Optional_Identifier (Arg1, Name_Check);
7410
7411 -- We treat pragma Assert as equivalent to:
7412
7413 -- pragma Check (Assertion, condition [, msg]);
7414
7415 -- So rewrite pragma in this manner, transfer the message
7416 -- argument if present, and analyze the result
7417
7418 -- Pragma Assert_And_Cut is treated exactly like pragma Assert by
7419 -- the frontend. Formal verification tools may use it to "cut" the
7420 -- paths through the code, to make verification tractable. When
7421 -- dealing with a semantically analyzed tree, the information that
7422 -- a Check node N corresponds to a source Assert_And_Cut pragma
7423 -- can be retrieved from the pragma kind of Original_Node(N).
7424
7425 Expr := Get_Pragma_Arg (Arg1);
7426 Newa := New_List (
7427 Make_Pragma_Argument_Association (Loc,
7428 Expression => Make_Identifier (Loc, Name_Assertion)),
7429
7430 Make_Pragma_Argument_Association (Sloc (Expr),
7431 Expression => Expr));
7432
7433 if Arg_Count > 1 then
7434 Check_Optional_Identifier (Arg2, Name_Message);
7435 Append_To (Newa, New_Copy_Tree (Arg2));
7436 end if;
7437
7438 Rewrite (N,
7439 Make_Pragma (Loc,
7440 Chars => Name_Check,
7441 Pragma_Argument_Associations => Newa));
7442 Analyze (N);
7443 end Assert;
7444
7445 ----------------------
7446 -- Assertion_Policy --
7447 ----------------------
7448
7449 -- pragma Assertion_Policy (Check | Disable | Ignore)
7450
7451 when Pragma_Assertion_Policy => Assertion_Policy : declare
7452 Policy : Node_Id;
7453
7454 begin
7455 Ada_2005_Pragma;
7456 Check_Valid_Configuration_Pragma;
7457 Check_Arg_Count (1);
7458 Check_No_Identifiers;
7459 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7460
7461 -- We treat pragma Assertion_Policy as equivalent to:
7462
7463 -- pragma Check_Policy (Assertion, policy)
7464
7465 -- So rewrite the pragma in that manner and link on to the chain
7466 -- of Check_Policy pragmas, marking the pragma as analyzed.
7467
7468 Policy := Get_Pragma_Arg (Arg1);
7469
7470 Rewrite (N,
7471 Make_Pragma (Loc,
7472 Chars => Name_Check_Policy,
7473 Pragma_Argument_Associations => New_List (
7474 Make_Pragma_Argument_Association (Loc,
7475 Expression => Make_Identifier (Loc, Name_Assertion)),
7476
7477 Make_Pragma_Argument_Association (Loc,
7478 Expression =>
7479 Make_Identifier (Sloc (Policy), Chars (Policy))))));
7480
7481 Set_Analyzed (N);
7482 Set_Next_Pragma (N, Opt.Check_Policy_List);
7483 Opt.Check_Policy_List := N;
7484 end Assertion_Policy;
7485
7486 ------------
7487 -- Assume --
7488 ------------
7489
7490 -- pragma Assume (boolean_EXPRESSION);
7491
7492 when Pragma_Assume => Assume : declare
7493 begin
7494 GNAT_Pragma;
7495 S14_Pragma;
7496 Check_Arg_Count (1);
7497
7498 -- Pragma Assume is transformed into pragma Check in the following
7499 -- manner:
7500
7501 -- pragma Check (Assume, Expr);
7502
7503 Rewrite (N,
7504 Make_Pragma (Loc,
7505 Chars => Name_Check,
7506 Pragma_Argument_Associations => New_List (
7507 Make_Pragma_Argument_Association (Loc,
7508 Expression => Make_Identifier (Loc, Name_Assume)),
7509
7510 Make_Pragma_Argument_Association (Loc,
7511 Expression => Relocate_Node (Expression (Arg1))))));
7512 Analyze (N);
7513 end Assume;
7514
7515 ------------------------------
7516 -- Assume_No_Invalid_Values --
7517 ------------------------------
7518
7519 -- pragma Assume_No_Invalid_Values (On | Off);
7520
7521 when Pragma_Assume_No_Invalid_Values =>
7522 GNAT_Pragma;
7523 Check_Valid_Configuration_Pragma;
7524 Check_Arg_Count (1);
7525 Check_No_Identifiers;
7526 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7527
7528 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
7529 Assume_No_Invalid_Values := True;
7530 else
7531 Assume_No_Invalid_Values := False;
7532 end if;
7533
7534 --------------------------
7535 -- Attribute_Definition --
7536 --------------------------
7537
7538 -- pragma Attribute_Definition
7539 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
7540 -- [Entity =>] LOCAL_NAME,
7541 -- [Expression =>] EXPRESSION | NAME);
7542
7543 when Pragma_Attribute_Definition => Attribute_Definition : declare
7544 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
7545 Aname : Name_Id;
7546
7547 begin
7548 GNAT_Pragma;
7549 Check_Arg_Count (3);
7550 Check_Optional_Identifier (Arg1, "attribute");
7551 Check_Optional_Identifier (Arg2, "entity");
7552 Check_Optional_Identifier (Arg3, "expression");
7553
7554 if Nkind (Attribute_Designator) /= N_Identifier then
7555 Error_Msg_N ("attribute name expected", Attribute_Designator);
7556 return;
7557 end if;
7558
7559 Check_Arg_Is_Local_Name (Arg2);
7560
7561 -- If the attribute is not recognized, then issue a warning (not
7562 -- an error), and ignore the pragma.
7563
7564 Aname := Chars (Attribute_Designator);
7565
7566 if not Is_Attribute_Name (Aname) then
7567 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
7568 return;
7569 end if;
7570
7571 -- Otherwise, rewrite the pragma as an attribute definition clause
7572
7573 Rewrite (N,
7574 Make_Attribute_Definition_Clause (Loc,
7575 Name => Get_Pragma_Arg (Arg2),
7576 Chars => Aname,
7577 Expression => Get_Pragma_Arg (Arg3)));
7578 Analyze (N);
7579 end Attribute_Definition;
7580
7581 ---------------
7582 -- AST_Entry --
7583 ---------------
7584
7585 -- pragma AST_Entry (entry_IDENTIFIER);
7586
7587 when Pragma_AST_Entry => AST_Entry : declare
7588 Ent : Node_Id;
7589
7590 begin
7591 GNAT_Pragma;
7592 Check_VMS (N);
7593 Check_Arg_Count (1);
7594 Check_No_Identifiers;
7595 Check_Arg_Is_Local_Name (Arg1);
7596 Ent := Entity (Get_Pragma_Arg (Arg1));
7597
7598 -- Note: the implementation of the AST_Entry pragma could handle
7599 -- the entry family case fine, but for now we are consistent with
7600 -- the DEC rules, and do not allow the pragma, which of course
7601 -- has the effect of also forbidding the attribute.
7602
7603 if Ekind (Ent) /= E_Entry then
7604 Error_Pragma_Arg
7605 ("pragma% argument must be simple entry name", Arg1);
7606
7607 elsif Is_AST_Entry (Ent) then
7608 Error_Pragma_Arg
7609 ("duplicate % pragma for entry", Arg1);
7610
7611 elsif Has_Homonym (Ent) then
7612 Error_Pragma_Arg
7613 ("pragma% argument cannot specify overloaded entry", Arg1);
7614
7615 else
7616 declare
7617 FF : constant Entity_Id := First_Formal (Ent);
7618
7619 begin
7620 if Present (FF) then
7621 if Present (Next_Formal (FF)) then
7622 Error_Pragma_Arg
7623 ("entry for pragma% can have only one argument",
7624 Arg1);
7625
7626 elsif Parameter_Mode (FF) /= E_In_Parameter then
7627 Error_Pragma_Arg
7628 ("entry parameter for pragma% must have mode IN",
7629 Arg1);
7630 end if;
7631 end if;
7632 end;
7633
7634 Set_Is_AST_Entry (Ent);
7635 end if;
7636 end AST_Entry;
7637
7638 ------------------
7639 -- Asynchronous --
7640 ------------------
7641
7642 -- pragma Asynchronous (LOCAL_NAME);
7643
7644 when Pragma_Asynchronous => Asynchronous : declare
7645 Nm : Entity_Id;
7646 C_Ent : Entity_Id;
7647 L : List_Id;
7648 S : Node_Id;
7649 N : Node_Id;
7650 Formal : Entity_Id;
7651
7652 procedure Process_Async_Pragma;
7653 -- Common processing for procedure and access-to-procedure case
7654
7655 --------------------------
7656 -- Process_Async_Pragma --
7657 --------------------------
7658
7659 procedure Process_Async_Pragma is
7660 begin
7661 if No (L) then
7662 Set_Is_Asynchronous (Nm);
7663 return;
7664 end if;
7665
7666 -- The formals should be of mode IN (RM E.4.1(6))
7667
7668 S := First (L);
7669 while Present (S) loop
7670 Formal := Defining_Identifier (S);
7671
7672 if Nkind (Formal) = N_Defining_Identifier
7673 and then Ekind (Formal) /= E_In_Parameter
7674 then
7675 Error_Pragma_Arg
7676 ("pragma% procedure can only have IN parameter",
7677 Arg1);
7678 end if;
7679
7680 Next (S);
7681 end loop;
7682
7683 Set_Is_Asynchronous (Nm);
7684 end Process_Async_Pragma;
7685
7686 -- Start of processing for pragma Asynchronous
7687
7688 begin
7689 Check_Ada_83_Warning;
7690 Check_No_Identifiers;
7691 Check_Arg_Count (1);
7692 Check_Arg_Is_Local_Name (Arg1);
7693
7694 if Debug_Flag_U then
7695 return;
7696 end if;
7697
7698 C_Ent := Cunit_Entity (Current_Sem_Unit);
7699 Analyze (Get_Pragma_Arg (Arg1));
7700 Nm := Entity (Get_Pragma_Arg (Arg1));
7701
7702 if not Is_Remote_Call_Interface (C_Ent)
7703 and then not Is_Remote_Types (C_Ent)
7704 then
7705 -- This pragma should only appear in an RCI or Remote Types
7706 -- unit (RM E.4.1(4)).
7707
7708 Error_Pragma
7709 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
7710 end if;
7711
7712 if Ekind (Nm) = E_Procedure
7713 and then Nkind (Parent (Nm)) = N_Procedure_Specification
7714 then
7715 if not Is_Remote_Call_Interface (Nm) then
7716 Error_Pragma_Arg
7717 ("pragma% cannot be applied on non-remote procedure",
7718 Arg1);
7719 end if;
7720
7721 L := Parameter_Specifications (Parent (Nm));
7722 Process_Async_Pragma;
7723 return;
7724
7725 elsif Ekind (Nm) = E_Function then
7726 Error_Pragma_Arg
7727 ("pragma% cannot be applied to function", Arg1);
7728
7729 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
7730 if Is_Record_Type (Nm) then
7731
7732 -- A record type that is the Equivalent_Type for a remote
7733 -- access-to-subprogram type.
7734
7735 N := Declaration_Node (Corresponding_Remote_Type (Nm));
7736
7737 else
7738 -- A non-expanded RAS type (distribution is not enabled)
7739
7740 N := Declaration_Node (Nm);
7741 end if;
7742
7743 if Nkind (N) = N_Full_Type_Declaration
7744 and then Nkind (Type_Definition (N)) =
7745 N_Access_Procedure_Definition
7746 then
7747 L := Parameter_Specifications (Type_Definition (N));
7748 Process_Async_Pragma;
7749
7750 if Is_Asynchronous (Nm)
7751 and then Expander_Active
7752 and then Get_PCS_Name /= Name_No_DSA
7753 then
7754 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
7755 end if;
7756
7757 else
7758 Error_Pragma_Arg
7759 ("pragma% cannot reference access-to-function type",
7760 Arg1);
7761 end if;
7762
7763 -- Only other possibility is Access-to-class-wide type
7764
7765 elsif Is_Access_Type (Nm)
7766 and then Is_Class_Wide_Type (Designated_Type (Nm))
7767 then
7768 Check_First_Subtype (Arg1);
7769 Set_Is_Asynchronous (Nm);
7770 if Expander_Active then
7771 RACW_Type_Is_Asynchronous (Nm);
7772 end if;
7773
7774 else
7775 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
7776 end if;
7777 end Asynchronous;
7778
7779 ------------
7780 -- Atomic --
7781 ------------
7782
7783 -- pragma Atomic (LOCAL_NAME);
7784
7785 when Pragma_Atomic =>
7786 Process_Atomic_Shared_Volatile;
7787
7788 -----------------------
7789 -- Atomic_Components --
7790 -----------------------
7791
7792 -- pragma Atomic_Components (array_LOCAL_NAME);
7793
7794 -- This processing is shared by Volatile_Components
7795
7796 when Pragma_Atomic_Components |
7797 Pragma_Volatile_Components =>
7798
7799 Atomic_Components : declare
7800 E_Id : Node_Id;
7801 E : Entity_Id;
7802 D : Node_Id;
7803 K : Node_Kind;
7804
7805 begin
7806 Check_Ada_83_Warning;
7807 Check_No_Identifiers;
7808 Check_Arg_Count (1);
7809 Check_Arg_Is_Local_Name (Arg1);
7810 E_Id := Get_Pragma_Arg (Arg1);
7811
7812 if Etype (E_Id) = Any_Type then
7813 return;
7814 end if;
7815
7816 E := Entity (E_Id);
7817
7818 Check_Duplicate_Pragma (E);
7819
7820 if Rep_Item_Too_Early (E, N)
7821 or else
7822 Rep_Item_Too_Late (E, N)
7823 then
7824 return;
7825 end if;
7826
7827 D := Declaration_Node (E);
7828 K := Nkind (D);
7829
7830 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
7831 or else
7832 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7833 and then Nkind (D) = N_Object_Declaration
7834 and then Nkind (Object_Definition (D)) =
7835 N_Constrained_Array_Definition)
7836 then
7837 -- The flag is set on the object, or on the base type
7838
7839 if Nkind (D) /= N_Object_Declaration then
7840 E := Base_Type (E);
7841 end if;
7842
7843 Set_Has_Volatile_Components (E);
7844
7845 if Prag_Id = Pragma_Atomic_Components then
7846 Set_Has_Atomic_Components (E);
7847 end if;
7848
7849 else
7850 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7851 end if;
7852 end Atomic_Components;
7853
7854 --------------------
7855 -- Attach_Handler --
7856 --------------------
7857
7858 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7859
7860 when Pragma_Attach_Handler =>
7861 Check_Ada_83_Warning;
7862 Check_No_Identifiers;
7863 Check_Arg_Count (2);
7864
7865 if No_Run_Time_Mode then
7866 Error_Msg_CRT ("Attach_Handler pragma", N);
7867 else
7868 Check_Interrupt_Or_Attach_Handler;
7869
7870 -- The expression that designates the attribute may depend on a
7871 -- discriminant, and is therefore a per-object expression, to
7872 -- be expanded in the init proc. If expansion is enabled, then
7873 -- perform semantic checks on a copy only.
7874
7875 if Expander_Active then
7876 declare
7877 Temp : constant Node_Id :=
7878 New_Copy_Tree (Get_Pragma_Arg (Arg2));
7879 begin
7880 Set_Parent (Temp, N);
7881 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7882 end;
7883
7884 else
7885 Analyze (Get_Pragma_Arg (Arg2));
7886 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7887 end if;
7888
7889 Process_Interrupt_Or_Attach_Handler;
7890 end if;
7891
7892 --------------------
7893 -- C_Pass_By_Copy --
7894 --------------------
7895
7896 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7897
7898 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7899 Arg : Node_Id;
7900 Val : Uint;
7901
7902 begin
7903 GNAT_Pragma;
7904 Check_Valid_Configuration_Pragma;
7905 Check_Arg_Count (1);
7906 Check_Optional_Identifier (Arg1, "max_size");
7907
7908 Arg := Get_Pragma_Arg (Arg1);
7909 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7910
7911 Val := Expr_Value (Arg);
7912
7913 if Val <= 0 then
7914 Error_Pragma_Arg
7915 ("maximum size for pragma% must be positive", Arg1);
7916
7917 elsif UI_Is_In_Int_Range (Val) then
7918 Default_C_Record_Mechanism := UI_To_Int (Val);
7919
7920 -- If a giant value is given, Int'Last will do well enough.
7921 -- If sometime someone complains that a record larger than
7922 -- two gigabytes is not copied, we will worry about it then!
7923
7924 else
7925 Default_C_Record_Mechanism := Mechanism_Type'Last;
7926 end if;
7927 end C_Pass_By_Copy;
7928
7929 -----------
7930 -- Check --
7931 -----------
7932
7933 -- pragma Check ([Name =>] IDENTIFIER,
7934 -- [Check =>] Boolean_EXPRESSION
7935 -- [,[Message =>] String_EXPRESSION]);
7936
7937 when Pragma_Check => Check : declare
7938 Expr : Node_Id;
7939 Eloc : Source_Ptr;
7940 Cname : Name_Id;
7941 Str : Node_Id;
7942
7943 Check_On : Boolean;
7944 -- Set True if category of assertions referenced by Name enabled
7945
7946 begin
7947 GNAT_Pragma;
7948 Check_At_Least_N_Arguments (2);
7949 Check_At_Most_N_Arguments (3);
7950 Check_Optional_Identifier (Arg1, Name_Name);
7951 Check_Optional_Identifier (Arg2, Name_Check);
7952
7953 if Arg_Count = 3 then
7954 Check_Optional_Identifier (Arg3, Name_Message);
7955 Str := Get_Pragma_Arg (Arg3);
7956 end if;
7957
7958 Check_Arg_Is_Identifier (Arg1);
7959 Cname := Chars (Get_Pragma_Arg (Arg1));
7960 Check_On := Check_Enabled (Cname);
7961 Expr := Get_Pragma_Arg (Arg2);
7962
7963 -- Deal with SCO generation
7964
7965 case Cname is
7966 when Name_Predicate |
7967 Name_Invariant =>
7968
7969 -- Nothing to do: since checks occur in client units,
7970 -- the SCO for the aspect in the declaration unit is
7971 -- conservatively always enabled.
7972
7973 null;
7974
7975 when others =>
7976
7977 if Check_On and then not Split_PPC (N) then
7978
7979 -- Mark pragma/aspect SCO as enabled
7980
7981 Set_SCO_Pragma_Enabled (Loc);
7982 end if;
7983 end case;
7984
7985 -- Deal with analyzing the string argument.
7986
7987 if Arg_Count = 3 then
7988
7989 -- If checks are not on we don't want any expansion (since
7990 -- such expansion would not get properly deleted) but
7991 -- we do want to analyze (to get proper references).
7992 -- The Preanalyze_And_Resolve routine does just what we want
7993
7994 if not Check_On then
7995 Preanalyze_And_Resolve (Str, Standard_String);
7996
7997 -- Otherwise we need a proper analysis and expansion
7998
7999 else
8000 Analyze_And_Resolve (Str, Standard_String);
8001 end if;
8002 end if;
8003
8004 -- Now you might think we could just do the same with the Boolean
8005 -- expression if checks are off (and expansion is on) and then
8006 -- rewrite the check as a null statement. This would work but we
8007 -- would lose the useful warnings about an assertion being bound
8008 -- to fail even if assertions are turned off.
8009
8010 -- So instead we wrap the boolean expression in an if statement
8011 -- that looks like:
8012
8013 -- if False and then condition then
8014 -- null;
8015 -- end if;
8016
8017 -- The reason we do this rewriting during semantic analysis
8018 -- rather than as part of normal expansion is that we cannot
8019 -- analyze and expand the code for the boolean expression
8020 -- directly, or it may cause insertion of actions that would
8021 -- escape the attempt to suppress the check code.
8022
8023 -- Note that the Sloc for the if statement corresponds to the
8024 -- argument condition, not the pragma itself. The reason for
8025 -- this is that we may generate a warning if the condition is
8026 -- False at compile time, and we do not want to delete this
8027 -- warning when we delete the if statement.
8028
8029 if Expander_Active and not Check_On then
8030 Eloc := Sloc (Expr);
8031
8032 Rewrite (N,
8033 Make_If_Statement (Eloc,
8034 Condition =>
8035 Make_And_Then (Eloc,
8036 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
8037 Right_Opnd => Expr),
8038 Then_Statements => New_List (
8039 Make_Null_Statement (Eloc))));
8040
8041 In_Assertion_Expr := In_Assertion_Expr + 1;
8042 Analyze (N);
8043 In_Assertion_Expr := In_Assertion_Expr - 1;
8044
8045 -- Check is active or expansion not active. In these cases we can
8046 -- just go ahead and analyze the boolean with no worries.
8047
8048 else
8049 In_Assertion_Expr := In_Assertion_Expr + 1;
8050 Analyze_And_Resolve (Expr, Any_Boolean);
8051 In_Assertion_Expr := In_Assertion_Expr - 1;
8052 end if;
8053 end Check;
8054
8055 --------------------------
8056 -- Check_Float_Overflow --
8057 --------------------------
8058
8059 -- pragma Check_Float_Overflow;
8060
8061 when Pragma_Check_Float_Overflow =>
8062 GNAT_Pragma;
8063 Check_Valid_Configuration_Pragma;
8064 Check_Arg_Count (0);
8065 Check_Float_Overflow := True;
8066
8067 ----------------
8068 -- Check_Name --
8069 ----------------
8070
8071 -- pragma Check_Name (check_IDENTIFIER);
8072
8073 when Pragma_Check_Name =>
8074 Check_No_Identifiers;
8075 GNAT_Pragma;
8076 Check_Valid_Configuration_Pragma;
8077 Check_Arg_Count (1);
8078 Check_Arg_Is_Identifier (Arg1);
8079
8080 declare
8081 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
8082
8083 begin
8084 for J in Check_Names.First .. Check_Names.Last loop
8085 if Check_Names.Table (J) = Nam then
8086 return;
8087 end if;
8088 end loop;
8089
8090 Check_Names.Append (Nam);
8091 end;
8092
8093 ------------------
8094 -- Check_Policy --
8095 ------------------
8096
8097 -- pragma Check_Policy (
8098 -- [Name =>] IDENTIFIER,
8099 -- [Policy =>] POLICY_IDENTIFIER);
8100
8101 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
8102
8103 -- Note: this is a configuration pragma, but it is allowed to appear
8104 -- anywhere else.
8105
8106 when Pragma_Check_Policy =>
8107 GNAT_Pragma;
8108 Check_Arg_Count (2);
8109 Check_Optional_Identifier (Arg1, Name_Name);
8110 Check_Optional_Identifier (Arg2, Name_Policy);
8111 Check_Arg_Is_One_Of
8112 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
8113
8114 -- A Check_Policy pragma can appear either as a configuration
8115 -- pragma, or in a declarative part or a package spec (see RM
8116 -- 11.5(5) for rules for Suppress/Unsuppress which are also
8117 -- followed for Check_Policy).
8118
8119 if not Is_Configuration_Pragma then
8120 Check_Is_In_Decl_Part_Or_Package_Spec;
8121 end if;
8122
8123 Set_Next_Pragma (N, Opt.Check_Policy_List);
8124 Opt.Check_Policy_List := N;
8125
8126 ---------------------
8127 -- CIL_Constructor --
8128 ---------------------
8129
8130 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
8131
8132 -- Processing for this pragma is shared with Java_Constructor
8133
8134 -------------
8135 -- Comment --
8136 -------------
8137
8138 -- pragma Comment (static_string_EXPRESSION)
8139
8140 -- Processing for pragma Comment shares the circuitry for pragma
8141 -- Ident. The only differences are that Ident enforces a limit of 31
8142 -- characters on its argument, and also enforces limitations on
8143 -- placement for DEC compatibility. Pragma Comment shares neither of
8144 -- these restrictions.
8145
8146 -------------------
8147 -- Common_Object --
8148 -------------------
8149
8150 -- pragma Common_Object (
8151 -- [Internal =>] LOCAL_NAME
8152 -- [, [External =>] EXTERNAL_SYMBOL]
8153 -- [, [Size =>] EXTERNAL_SYMBOL]);
8154
8155 -- Processing for this pragma is shared with Psect_Object
8156
8157 ------------------------
8158 -- Compile_Time_Error --
8159 ------------------------
8160
8161 -- pragma Compile_Time_Error
8162 -- (boolean_EXPRESSION, static_string_EXPRESSION);
8163
8164 when Pragma_Compile_Time_Error =>
8165 GNAT_Pragma;
8166 Process_Compile_Time_Warning_Or_Error;
8167
8168 --------------------------
8169 -- Compile_Time_Warning --
8170 --------------------------
8171
8172 -- pragma Compile_Time_Warning
8173 -- (boolean_EXPRESSION, static_string_EXPRESSION);
8174
8175 when Pragma_Compile_Time_Warning =>
8176 GNAT_Pragma;
8177 Process_Compile_Time_Warning_Or_Error;
8178
8179 -------------------
8180 -- Compiler_Unit --
8181 -------------------
8182
8183 when Pragma_Compiler_Unit =>
8184 GNAT_Pragma;
8185 Check_Arg_Count (0);
8186 Set_Is_Compiler_Unit (Get_Source_Unit (N));
8187
8188 -----------------------------
8189 -- Complete_Representation --
8190 -----------------------------
8191
8192 -- pragma Complete_Representation;
8193
8194 when Pragma_Complete_Representation =>
8195 GNAT_Pragma;
8196 Check_Arg_Count (0);
8197
8198 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
8199 Error_Pragma
8200 ("pragma & must appear within record representation clause");
8201 end if;
8202
8203 ----------------------------
8204 -- Complex_Representation --
8205 ----------------------------
8206
8207 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
8208
8209 when Pragma_Complex_Representation => Complex_Representation : declare
8210 E_Id : Entity_Id;
8211 E : Entity_Id;
8212 Ent : Entity_Id;
8213
8214 begin
8215 GNAT_Pragma;
8216 Check_Arg_Count (1);
8217 Check_Optional_Identifier (Arg1, Name_Entity);
8218 Check_Arg_Is_Local_Name (Arg1);
8219 E_Id := Get_Pragma_Arg (Arg1);
8220
8221 if Etype (E_Id) = Any_Type then
8222 return;
8223 end if;
8224
8225 E := Entity (E_Id);
8226
8227 if not Is_Record_Type (E) then
8228 Error_Pragma_Arg
8229 ("argument for pragma% must be record type", Arg1);
8230 end if;
8231
8232 Ent := First_Entity (E);
8233
8234 if No (Ent)
8235 or else No (Next_Entity (Ent))
8236 or else Present (Next_Entity (Next_Entity (Ent)))
8237 or else not Is_Floating_Point_Type (Etype (Ent))
8238 or else Etype (Ent) /= Etype (Next_Entity (Ent))
8239 then
8240 Error_Pragma_Arg
8241 ("record for pragma% must have two fields of the same "
8242 & "floating-point type", Arg1);
8243
8244 else
8245 Set_Has_Complex_Representation (Base_Type (E));
8246
8247 -- We need to treat the type has having a non-standard
8248 -- representation, for back-end purposes, even though in
8249 -- general a complex will have the default representation
8250 -- of a record with two real components.
8251
8252 Set_Has_Non_Standard_Rep (Base_Type (E));
8253 end if;
8254 end Complex_Representation;
8255
8256 -------------------------
8257 -- Component_Alignment --
8258 -------------------------
8259
8260 -- pragma Component_Alignment (
8261 -- [Form =>] ALIGNMENT_CHOICE
8262 -- [, [Name =>] type_LOCAL_NAME]);
8263 --
8264 -- ALIGNMENT_CHOICE ::=
8265 -- Component_Size
8266 -- | Component_Size_4
8267 -- | Storage_Unit
8268 -- | Default
8269
8270 when Pragma_Component_Alignment => Component_AlignmentP : declare
8271 Args : Args_List (1 .. 2);
8272 Names : constant Name_List (1 .. 2) := (
8273 Name_Form,
8274 Name_Name);
8275
8276 Form : Node_Id renames Args (1);
8277 Name : Node_Id renames Args (2);
8278
8279 Atype : Component_Alignment_Kind;
8280 Typ : Entity_Id;
8281
8282 begin
8283 GNAT_Pragma;
8284 Gather_Associations (Names, Args);
8285
8286 if No (Form) then
8287 Error_Pragma ("missing Form argument for pragma%");
8288 end if;
8289
8290 Check_Arg_Is_Identifier (Form);
8291
8292 -- Get proper alignment, note that Default = Component_Size on all
8293 -- machines we have so far, and we want to set this value rather
8294 -- than the default value to indicate that it has been explicitly
8295 -- set (and thus will not get overridden by the default component
8296 -- alignment for the current scope)
8297
8298 if Chars (Form) = Name_Component_Size then
8299 Atype := Calign_Component_Size;
8300
8301 elsif Chars (Form) = Name_Component_Size_4 then
8302 Atype := Calign_Component_Size_4;
8303
8304 elsif Chars (Form) = Name_Default then
8305 Atype := Calign_Component_Size;
8306
8307 elsif Chars (Form) = Name_Storage_Unit then
8308 Atype := Calign_Storage_Unit;
8309
8310 else
8311 Error_Pragma_Arg
8312 ("invalid Form parameter for pragma%", Form);
8313 end if;
8314
8315 -- Case with no name, supplied, affects scope table entry
8316
8317 if No (Name) then
8318 Scope_Stack.Table
8319 (Scope_Stack.Last).Component_Alignment_Default := Atype;
8320
8321 -- Case of name supplied
8322
8323 else
8324 Check_Arg_Is_Local_Name (Name);
8325 Find_Type (Name);
8326 Typ := Entity (Name);
8327
8328 if Typ = Any_Type
8329 or else Rep_Item_Too_Early (Typ, N)
8330 then
8331 return;
8332 else
8333 Typ := Underlying_Type (Typ);
8334 end if;
8335
8336 if not Is_Record_Type (Typ)
8337 and then not Is_Array_Type (Typ)
8338 then
8339 Error_Pragma_Arg
8340 ("Name parameter of pragma% must identify record or "
8341 & "array type", Name);
8342 end if;
8343
8344 -- An explicit Component_Alignment pragma overrides an
8345 -- implicit pragma Pack, but not an explicit one.
8346
8347 if not Has_Pragma_Pack (Base_Type (Typ)) then
8348 Set_Is_Packed (Base_Type (Typ), False);
8349 Set_Component_Alignment (Base_Type (Typ), Atype);
8350 end if;
8351 end if;
8352 end Component_AlignmentP;
8353
8354 -------------------
8355 -- Contract_Case --
8356 -------------------
8357
8358 -- pragma Contract_Case
8359 -- ([Name =>] Static_String_EXPRESSION
8360 -- ,[Mode =>] MODE_TYPE
8361 -- [, Requires => Boolean_EXPRESSION]
8362 -- [, Ensures => Boolean_EXPRESSION]);
8363
8364 -- MODE_TYPE ::= Nominal | Robustness
8365
8366 when Pragma_Contract_Case =>
8367 Check_Contract_Or_Test_Case;
8368
8369 --------------------
8370 -- Contract_Cases --
8371 --------------------
8372
8373 -- pragma Contract_Cases (CONTRACT_CASE_LIST);
8374
8375 -- CONTRACT_CASE_LIST ::= CONTRACT_CASE {, CONTRACT_CASE}
8376
8377 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
8378
8379 -- CASE_GUARD ::= boolean_EXPRESSION | others
8380
8381 -- CONSEQUENCE ::= boolean_EXPRESSION
8382
8383 when Pragma_Contract_Cases => Contract_Cases : declare
8384 procedure Chain_Contract_Cases (Subp_Decl : Node_Id);
8385 -- Chain pragma Contract_Cases to the contract of a subprogram.
8386 -- Subp_Decl is the declaration of the subprogram.
8387
8388 --------------------------
8389 -- Chain_Contract_Cases --
8390 --------------------------
8391
8392 procedure Chain_Contract_Cases (Subp_Decl : Node_Id) is
8393 Subp : constant Entity_Id :=
8394 Defining_Unit_Name (Specification (Subp_Decl));
8395 CTC : Node_Id;
8396
8397 begin
8398 Check_Duplicate_Pragma (Subp);
8399 CTC := Spec_CTC_List (Contract (Subp));
8400 while Present (CTC) loop
8401 if Chars (Pragma_Identifier (CTC)) = Pname then
8402 Error_Msg_Name_1 := Pname;
8403 Error_Msg_Sloc := Sloc (CTC);
8404
8405 if From_Aspect_Specification (CTC) then
8406 Error_Msg_NE
8407 ("aspect% for & previously given#", N, Subp);
8408 else
8409 Error_Msg_NE
8410 ("pragma% for & duplicates pragma#", N, Subp);
8411 end if;
8412
8413 raise Pragma_Exit;
8414 end if;
8415
8416 CTC := Next_Pragma (CTC);
8417 end loop;
8418
8419 -- Prepend pragma Contract_Cases to the contract
8420
8421 Set_Next_Pragma (N, Spec_CTC_List (Contract (Subp)));
8422 Set_Spec_CTC_List (Contract (Subp), N);
8423 end Chain_Contract_Cases;
8424
8425 -- Local variables
8426
8427 Case_Guard : Node_Id;
8428 Decl : Node_Id;
8429 Extra : Node_Id;
8430 Others_Seen : Boolean := False;
8431 Contract_Case : Node_Id;
8432 Subp_Decl : Node_Id;
8433
8434 -- Start of processing for Contract_Cases
8435
8436 begin
8437 GNAT_Pragma;
8438 S14_Pragma;
8439 Check_Arg_Count (1);
8440
8441 -- Completely ignore if disabled
8442
8443 if not Check_Enabled (Pname) then
8444 Rewrite (N, Make_Null_Statement (Loc));
8445 Analyze (N);
8446 return;
8447 end if;
8448
8449 -- Check the placement of the pragma
8450
8451 if not Is_List_Member (N) then
8452 Pragma_Misplaced;
8453 end if;
8454
8455 -- Pragma Contract_Cases must be associated with a subprogram
8456
8457 Decl := N;
8458 while Present (Prev (Decl)) loop
8459 Decl := Prev (Decl);
8460
8461 if Nkind (Decl) in N_Generic_Declaration then
8462 Subp_Decl := Decl;
8463 else
8464 Subp_Decl := Original_Node (Decl);
8465 end if;
8466
8467 -- Skip prior pragmas
8468
8469 if Nkind (Subp_Decl) = N_Pragma then
8470 null;
8471
8472 -- Skip internally generated code
8473
8474 elsif not Comes_From_Source (Subp_Decl) then
8475 null;
8476
8477 -- We have found the related subprogram
8478
8479 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
8480 N_Subprogram_Declaration)
8481 then
8482 exit;
8483
8484 else
8485 Pragma_Misplaced;
8486 end if;
8487 end loop;
8488
8489 -- All contract cases must appear as an aggregate
8490
8491 if Nkind (Expression (Arg1)) /= N_Aggregate then
8492 Error_Pragma ("wrong syntax for pragma %");
8493 return;
8494 end if;
8495
8496 -- Verify the legality of individual contract cases
8497
8498 Contract_Case :=
8499 First (Component_Associations (Expression (Arg1)));
8500 while Present (Contract_Case) loop
8501 if Nkind (Contract_Case) /= N_Component_Association then
8502 Error_Pragma_Arg
8503 ("wrong syntax in contract case", Contract_Case);
8504 return;
8505 end if;
8506
8507 Case_Guard := First (Choices (Contract_Case));
8508
8509 -- Each contract case must have exactly on case guard
8510
8511 Extra := Next (Case_Guard);
8512 if Present (Extra) then
8513 Error_Pragma_Arg
8514 ("contract case may have only one case guard", Extra);
8515 return;
8516 end if;
8517
8518 -- Check the placement of "others" (if available)
8519
8520 if Nkind (Case_Guard) = N_Others_Choice then
8521 if Others_Seen then
8522 Error_Pragma_Arg
8523 ("only one others choice allowed in pragma %",
8524 Case_Guard);
8525 return;
8526 else
8527 Others_Seen := True;
8528 end if;
8529
8530 elsif Others_Seen then
8531 Error_Pragma_Arg
8532 ("others must be the last choice in pragma %", N);
8533 return;
8534 end if;
8535
8536 Next (Contract_Case);
8537 end loop;
8538
8539 Chain_Contract_Cases (Subp_Decl);
8540 end Contract_Cases;
8541
8542 ----------------
8543 -- Controlled --
8544 ----------------
8545
8546 -- pragma Controlled (first_subtype_LOCAL_NAME);
8547
8548 when Pragma_Controlled => Controlled : declare
8549 Arg : Node_Id;
8550
8551 begin
8552 Check_No_Identifiers;
8553 Check_Arg_Count (1);
8554 Check_Arg_Is_Local_Name (Arg1);
8555 Arg := Get_Pragma_Arg (Arg1);
8556
8557 if not Is_Entity_Name (Arg)
8558 or else not Is_Access_Type (Entity (Arg))
8559 then
8560 Error_Pragma_Arg ("pragma% requires access type", Arg1);
8561 else
8562 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
8563 end if;
8564 end Controlled;
8565
8566 ----------------
8567 -- Convention --
8568 ----------------
8569
8570 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
8571 -- [Entity =>] LOCAL_NAME);
8572
8573 when Pragma_Convention => Convention : declare
8574 C : Convention_Id;
8575 E : Entity_Id;
8576 pragma Warnings (Off, C);
8577 pragma Warnings (Off, E);
8578 begin
8579 Check_Arg_Order ((Name_Convention, Name_Entity));
8580 Check_Ada_83_Warning;
8581 Check_Arg_Count (2);
8582 Process_Convention (C, E);
8583 end Convention;
8584
8585 ---------------------------
8586 -- Convention_Identifier --
8587 ---------------------------
8588
8589 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
8590 -- [Convention =>] convention_IDENTIFIER);
8591
8592 when Pragma_Convention_Identifier => Convention_Identifier : declare
8593 Idnam : Name_Id;
8594 Cname : Name_Id;
8595
8596 begin
8597 GNAT_Pragma;
8598 Check_Arg_Order ((Name_Name, Name_Convention));
8599 Check_Arg_Count (2);
8600 Check_Optional_Identifier (Arg1, Name_Name);
8601 Check_Optional_Identifier (Arg2, Name_Convention);
8602 Check_Arg_Is_Identifier (Arg1);
8603 Check_Arg_Is_Identifier (Arg2);
8604 Idnam := Chars (Get_Pragma_Arg (Arg1));
8605 Cname := Chars (Get_Pragma_Arg (Arg2));
8606
8607 if Is_Convention_Name (Cname) then
8608 Record_Convention_Identifier
8609 (Idnam, Get_Convention_Id (Cname));
8610 else
8611 Error_Pragma_Arg
8612 ("second arg for % pragma must be convention", Arg2);
8613 end if;
8614 end Convention_Identifier;
8615
8616 ---------------
8617 -- CPP_Class --
8618 ---------------
8619
8620 -- pragma CPP_Class ([Entity =>] local_NAME)
8621
8622 when Pragma_CPP_Class => CPP_Class : declare
8623 begin
8624 GNAT_Pragma;
8625
8626 if Warn_On_Obsolescent_Feature then
8627 Error_Msg_N
8628 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
8629 & "effect; replace it by pragma import?j?", N);
8630 end if;
8631
8632 Check_Arg_Count (1);
8633
8634 Rewrite (N,
8635 Make_Pragma (Loc,
8636 Chars => Name_Import,
8637 Pragma_Argument_Associations => New_List (
8638 Make_Pragma_Argument_Association (Loc,
8639 Expression => Make_Identifier (Loc, Name_CPP)),
8640 New_Copy (First (Pragma_Argument_Associations (N))))));
8641 Analyze (N);
8642 end CPP_Class;
8643
8644 ---------------------
8645 -- CPP_Constructor --
8646 ---------------------
8647
8648 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
8649 -- [, [External_Name =>] static_string_EXPRESSION ]
8650 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8651
8652 when Pragma_CPP_Constructor => CPP_Constructor : declare
8653 Elmt : Elmt_Id;
8654 Id : Entity_Id;
8655 Def_Id : Entity_Id;
8656 Tag_Typ : Entity_Id;
8657
8658 begin
8659 GNAT_Pragma;
8660 Check_At_Least_N_Arguments (1);
8661 Check_At_Most_N_Arguments (3);
8662 Check_Optional_Identifier (Arg1, Name_Entity);
8663 Check_Arg_Is_Local_Name (Arg1);
8664
8665 Id := Get_Pragma_Arg (Arg1);
8666 Find_Program_Unit_Name (Id);
8667
8668 -- If we did not find the name, we are done
8669
8670 if Etype (Id) = Any_Type then
8671 return;
8672 end if;
8673
8674 Def_Id := Entity (Id);
8675
8676 -- Check if already defined as constructor
8677
8678 if Is_Constructor (Def_Id) then
8679 Error_Msg_N
8680 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
8681 return;
8682 end if;
8683
8684 if Ekind (Def_Id) = E_Function
8685 and then (Is_CPP_Class (Etype (Def_Id))
8686 or else (Is_Class_Wide_Type (Etype (Def_Id))
8687 and then
8688 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
8689 then
8690 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
8691 Error_Msg_N
8692 ("'C'P'P constructor must be defined in the scope of "
8693 & "its returned type", Arg1);
8694 end if;
8695
8696 if Arg_Count >= 2 then
8697 Set_Imported (Def_Id);
8698 Set_Is_Public (Def_Id);
8699 Process_Interface_Name (Def_Id, Arg2, Arg3);
8700 end if;
8701
8702 Set_Has_Completion (Def_Id);
8703 Set_Is_Constructor (Def_Id);
8704 Set_Convention (Def_Id, Convention_CPP);
8705
8706 -- Imported C++ constructors are not dispatching primitives
8707 -- because in C++ they don't have a dispatch table slot.
8708 -- However, in Ada the constructor has the profile of a
8709 -- function that returns a tagged type and therefore it has
8710 -- been treated as a primitive operation during semantic
8711 -- analysis. We now remove it from the list of primitive
8712 -- operations of the type.
8713
8714 if Is_Tagged_Type (Etype (Def_Id))
8715 and then not Is_Class_Wide_Type (Etype (Def_Id))
8716 and then Is_Dispatching_Operation (Def_Id)
8717 then
8718 Tag_Typ := Etype (Def_Id);
8719
8720 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
8721 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
8722 Next_Elmt (Elmt);
8723 end loop;
8724
8725 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
8726 Set_Is_Dispatching_Operation (Def_Id, False);
8727 end if;
8728
8729 -- For backward compatibility, if the constructor returns a
8730 -- class wide type, and we internally change the return type to
8731 -- the corresponding root type.
8732
8733 if Is_Class_Wide_Type (Etype (Def_Id)) then
8734 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
8735 end if;
8736 else
8737 Error_Pragma_Arg
8738 ("pragma% requires function returning a 'C'P'P_Class type",
8739 Arg1);
8740 end if;
8741 end CPP_Constructor;
8742
8743 -----------------
8744 -- CPP_Virtual --
8745 -----------------
8746
8747 when Pragma_CPP_Virtual => CPP_Virtual : declare
8748 begin
8749 GNAT_Pragma;
8750
8751 if Warn_On_Obsolescent_Feature then
8752 Error_Msg_N
8753 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has no "
8754 & "effect?j?", N);
8755 end if;
8756 end CPP_Virtual;
8757
8758 ----------------
8759 -- CPP_Vtable --
8760 ----------------
8761
8762 when Pragma_CPP_Vtable => CPP_Vtable : declare
8763 begin
8764 GNAT_Pragma;
8765
8766 if Warn_On_Obsolescent_Feature then
8767 Error_Msg_N
8768 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has no "
8769 & "effect?j?", N);
8770 end if;
8771 end CPP_Vtable;
8772
8773 ---------
8774 -- CPU --
8775 ---------
8776
8777 -- pragma CPU (EXPRESSION);
8778
8779 when Pragma_CPU => CPU : declare
8780 P : constant Node_Id := Parent (N);
8781 Arg : Node_Id;
8782 Ent : Entity_Id;
8783
8784 begin
8785 Ada_2012_Pragma;
8786 Check_No_Identifiers;
8787 Check_Arg_Count (1);
8788
8789 -- Subprogram case
8790
8791 if Nkind (P) = N_Subprogram_Body then
8792 Check_In_Main_Program;
8793
8794 Arg := Get_Pragma_Arg (Arg1);
8795 Analyze_And_Resolve (Arg, Any_Integer);
8796
8797 Ent := Defining_Unit_Name (Specification (P));
8798
8799 if Nkind (Ent) = N_Defining_Program_Unit_Name then
8800 Ent := Defining_Identifier (Ent);
8801 end if;
8802
8803 -- Must be static
8804
8805 if not Is_Static_Expression (Arg) then
8806 Flag_Non_Static_Expr
8807 ("main subprogram affinity is not static!", Arg);
8808 raise Pragma_Exit;
8809
8810 -- If constraint error, then we already signalled an error
8811
8812 elsif Raises_Constraint_Error (Arg) then
8813 null;
8814
8815 -- Otherwise check in range
8816
8817 else
8818 declare
8819 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
8820 -- This is the entity System.Multiprocessors.CPU_Range;
8821
8822 Val : constant Uint := Expr_Value (Arg);
8823
8824 begin
8825 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
8826 or else
8827 Val > Expr_Value (Type_High_Bound (CPU_Id))
8828 then
8829 Error_Pragma_Arg
8830 ("main subprogram CPU is out of range", Arg1);
8831 end if;
8832 end;
8833 end if;
8834
8835 Set_Main_CPU
8836 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8837
8838 -- Task case
8839
8840 elsif Nkind (P) = N_Task_Definition then
8841 Arg := Get_Pragma_Arg (Arg1);
8842 Ent := Defining_Identifier (Parent (P));
8843
8844 -- The expression must be analyzed in the special manner
8845 -- described in "Handling of Default and Per-Object
8846 -- Expressions" in sem.ads.
8847
8848 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
8849
8850 -- Anything else is incorrect
8851
8852 else
8853 Pragma_Misplaced;
8854 end if;
8855
8856 -- Check duplicate pragma before we chain the pragma in the Rep
8857 -- Item chain of Ent.
8858
8859 Check_Duplicate_Pragma (Ent);
8860 Record_Rep_Item (Ent, N);
8861 end CPU;
8862
8863 -----------
8864 -- Debug --
8865 -----------
8866
8867 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
8868
8869 when Pragma_Debug => Debug : declare
8870 Cond : Node_Id;
8871 Call : Node_Id;
8872
8873 begin
8874 GNAT_Pragma;
8875
8876 -- Skip analysis if disabled
8877
8878 if Debug_Pragmas_Disabled then
8879 Rewrite (N, Make_Null_Statement (Loc));
8880 Analyze (N);
8881 return;
8882 end if;
8883
8884 Cond :=
8885 New_Occurrence_Of
8886 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
8887 Loc);
8888
8889 if Debug_Pragmas_Enabled then
8890 Set_SCO_Pragma_Enabled (Loc);
8891 end if;
8892
8893 if Arg_Count = 2 then
8894 Cond :=
8895 Make_And_Then (Loc,
8896 Left_Opnd => Relocate_Node (Cond),
8897 Right_Opnd => Get_Pragma_Arg (Arg1));
8898 Call := Get_Pragma_Arg (Arg2);
8899 else
8900 Call := Get_Pragma_Arg (Arg1);
8901 end if;
8902
8903 if Nkind_In (Call,
8904 N_Indexed_Component,
8905 N_Function_Call,
8906 N_Identifier,
8907 N_Expanded_Name,
8908 N_Selected_Component)
8909 then
8910 -- If this pragma Debug comes from source, its argument was
8911 -- parsed as a name form (which is syntactically identical).
8912 -- In a generic context a parameterless call will be left as
8913 -- an expanded name (if global) or selected_component if local.
8914 -- Change it to a procedure call statement now.
8915
8916 Change_Name_To_Procedure_Call_Statement (Call);
8917
8918 elsif Nkind (Call) = N_Procedure_Call_Statement then
8919
8920 -- Already in the form of a procedure call statement: nothing
8921 -- to do (could happen in case of an internally generated
8922 -- pragma Debug).
8923
8924 null;
8925
8926 else
8927 -- All other cases: diagnose error
8928
8929 Error_Msg
8930 ("argument of pragma ""Debug"" is not procedure call",
8931 Sloc (Call));
8932 return;
8933 end if;
8934
8935 -- Rewrite into a conditional with an appropriate condition. We
8936 -- wrap the procedure call in a block so that overhead from e.g.
8937 -- use of the secondary stack does not generate execution overhead
8938 -- for suppressed conditions.
8939
8940 -- Normally the analysis that follows will freeze the subprogram
8941 -- being called. However, if the call is to a null procedure,
8942 -- we want to freeze it before creating the block, because the
8943 -- analysis that follows may be done with expansion disabled, in
8944 -- which case the body will not be generated, leading to spurious
8945 -- errors.
8946
8947 if Nkind (Call) = N_Procedure_Call_Statement
8948 and then Is_Entity_Name (Name (Call))
8949 then
8950 Analyze (Name (Call));
8951 Freeze_Before (N, Entity (Name (Call)));
8952 end if;
8953
8954 Rewrite (N, Make_Implicit_If_Statement (N,
8955 Condition => Cond,
8956 Then_Statements => New_List (
8957 Make_Block_Statement (Loc,
8958 Handled_Statement_Sequence =>
8959 Make_Handled_Sequence_Of_Statements (Loc,
8960 Statements => New_List (Relocate_Node (Call)))))));
8961 Analyze (N);
8962 end Debug;
8963
8964 ------------------
8965 -- Debug_Policy --
8966 ------------------
8967
8968 -- pragma Debug_Policy (Check | Ignore)
8969
8970 when Pragma_Debug_Policy =>
8971 GNAT_Pragma;
8972 Check_Arg_Count (1);
8973 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
8974 Debug_Pragmas_Enabled :=
8975 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
8976 Debug_Pragmas_Disabled :=
8977 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
8978
8979 -------------
8980 -- Depends --
8981 -------------
8982
8983 -- pragma Depends (DEPENDENCY_RELATION);
8984
8985 -- DEPENDENCY_RELATION ::=
8986 -- null
8987 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
8988
8989 -- DEPENDENCY_CLAUSE ::= OUTPUT_LIST =>[+] INPUT_LIST
8990
8991 -- OUTPUT_LIST ::= null | OUTPUT | (OUTPUT {, OUTPUT})
8992
8993 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
8994
8995 -- OUTPUT ::= NAME | FUNCTION_RESULT
8996 -- INPUT ::= NAME
8997
8998 -- where FUNCTION_RESULT is a function Result attribute_reference
8999
9000 when Pragma_Depends => Depends : declare
9001 All_Inputs_Seen : Elist_Id := No_Elist;
9002 -- A list containing the entities of all the inputs processed so
9003 -- far. This Elist is populated with unique entities because the
9004 -- same input may appear in multiple input lists.
9005
9006 Global_Seen : Boolean := False;
9007 -- A flag set when pragma Global has been processed
9008
9009 Outputs_Seen : Elist_Id := No_Elist;
9010 -- A list containing the entities of all the outputs processed so
9011 -- far. The elements of this list may come from different output
9012 -- lists.
9013
9014 Null_Output_Seen : Boolean := False;
9015 -- A flag used to track the legality of a null output
9016
9017 Result_Seen : Boolean := False;
9018 -- A flag set when Subp_Id'Result is processed
9019
9020 Subp_Id : Entity_Id;
9021 -- The entity of the subprogram subject to pragma Depends
9022
9023 Subp_Inputs : Elist_Id := No_Elist;
9024 Subp_Outputs : Elist_Id := No_Elist;
9025 -- Two lists containing the full set of inputs and output of the
9026 -- related subprograms. Note that these lists contain both nodes
9027 -- and entities.
9028
9029 procedure Analyze_Dependency_Clause
9030 (Clause : Node_Id;
9031 Is_Last : Boolean);
9032 -- Verify the legality of a single dependency clause. Flag Is_Last
9033 -- denotes whether Clause is the last clause in the relation.
9034
9035 function Appears_In
9036 (List : Elist_Id;
9037 Item_Id : Entity_Id) return Boolean;
9038 -- Determine whether a particular item appears in a mixed list of
9039 -- nodes and entities.
9040
9041 procedure Check_Function_Return;
9042 -- Verify that Funtion'Result appears as one of the outputs
9043
9044 procedure Check_Mode
9045 (Item : Node_Id;
9046 Item_Id : Entity_Id;
9047 Is_Input : Boolean);
9048 -- Ensure that an item has a proper "in", "in out" or "out" mode
9049 -- depending on its function. If this is not the case, emit an
9050 -- error.
9051
9052 procedure Check_Usage
9053 (Subp_List : Elist_Id;
9054 Item_List : Elist_Id;
9055 Is_Input : Boolean);
9056 -- Verify that all items from list Subp_List appear in Item_List.
9057 -- Emit an error if this is not the case.
9058
9059 procedure Collect_Subprogram_Inputs_Outputs;
9060 -- Gather all inputs and outputs of the subprogram. These are the
9061 -- formal parameters and entities classified in pragma Global.
9062
9063 procedure Normalize_Clause (Clause : Node_Id);
9064 -- Remove a self-dependency "+" from the input list of a clause.
9065 -- Depending on the contents of the relation, either split the
9066 -- the clause into multiple smaller clauses or perform the
9067 -- normalization in place.
9068
9069 -------------------------------
9070 -- Analyze_Dependency_Clause --
9071 -------------------------------
9072
9073 procedure Analyze_Dependency_Clause
9074 (Clause : Node_Id;
9075 Is_Last : Boolean)
9076 is
9077 procedure Analyze_Input_List (Inputs : Node_Id);
9078 -- Verify the legality of a single input list
9079
9080 procedure Analyze_Input_Output
9081 (Item : Node_Id;
9082 Is_Input : Boolean;
9083 Top_Level : Boolean;
9084 Seen : in out Elist_Id;
9085 Null_Seen : in out Boolean);
9086 -- Verify the legality of a single input or output item. Flag
9087 -- Is_Input should be set whenever Item is an input, False when
9088 -- it denotes an output. Flag Top_Level should be set whenever
9089 -- Item appears immediately within an input or output list.
9090 -- Seen is a collection of all abstract states, variables and
9091 -- formals processed so far. Flag Null_Seen denotes whether a
9092 -- null input or output has been encountered.
9093
9094 ------------------------
9095 -- Analyze_Input_List --
9096 ------------------------
9097
9098 procedure Analyze_Input_List (Inputs : Node_Id) is
9099 Inputs_Seen : Elist_Id := No_Elist;
9100 -- A list containing the entities of all inputs that appear
9101 -- in the current input list.
9102
9103 Null_Input_Seen : Boolean := False;
9104 -- A flag used to track the legality of a null input
9105
9106 Input : Node_Id;
9107
9108 begin
9109 -- Multiple inputs appear as an aggregate
9110
9111 if Nkind (Inputs) = N_Aggregate then
9112 if Present (Component_Associations (Inputs)) then
9113 Error_Msg_N
9114 ("nested dependency relations not allowed", Inputs);
9115
9116 elsif Present (Expressions (Inputs)) then
9117 Input := First (Expressions (Inputs));
9118 while Present (Input) loop
9119 Analyze_Input_Output
9120 (Item => Input,
9121 Is_Input => True,
9122 Top_Level => False,
9123 Seen => Inputs_Seen,
9124 Null_Seen => Null_Input_Seen);
9125
9126 Next (Input);
9127 end loop;
9128
9129 else
9130 Error_Msg_N
9131 ("malformed input dependency list", Inputs);
9132 end if;
9133
9134 -- Process a solitary input
9135
9136 else
9137 Analyze_Input_Output
9138 (Item => Inputs,
9139 Is_Input => True,
9140 Top_Level => False,
9141 Seen => Inputs_Seen,
9142 Null_Seen => Null_Input_Seen);
9143 end if;
9144 end Analyze_Input_List;
9145
9146 --------------------------
9147 -- Analyze_Input_Output --
9148 --------------------------
9149
9150 procedure Analyze_Input_Output
9151 (Item : Node_Id;
9152 Is_Input : Boolean;
9153 Top_Level : Boolean;
9154 Seen : in out Elist_Id;
9155 Null_Seen : in out Boolean)
9156 is
9157 Is_Output : constant Boolean := not Is_Input;
9158 Grouped : Node_Id;
9159 Item_Id : Entity_Id;
9160
9161 begin
9162 -- Multiple input or output items appear as an aggregate
9163
9164 if Nkind (Item) = N_Aggregate then
9165 if not Top_Level then
9166 Error_Msg_N
9167 ("nested grouping of items not allowed", Item);
9168
9169 elsif Present (Component_Associations (Item)) then
9170 Error_Msg_N
9171 ("nested dependency relations not allowed", Item);
9172
9173 -- Recursively analyze the grouped items
9174
9175 elsif Present (Expressions (Item)) then
9176 Grouped := First (Expressions (Item));
9177 while Present (Grouped) loop
9178 Analyze_Input_Output
9179 (Item => Grouped,
9180 Is_Input => Is_Input,
9181 Top_Level => False,
9182 Seen => Seen,
9183 Null_Seen => Null_Seen);
9184
9185 Next (Grouped);
9186 end loop;
9187
9188 else
9189 Error_Msg_N ("malformed dependency list", Item);
9190 end if;
9191
9192 -- Process Function'Result in the context of a dependency
9193 -- clause.
9194
9195 elsif Nkind (Item) = N_Attribute_Reference
9196 and then Attribute_Name (Item) = Name_Result
9197 then
9198 -- It is sufficent to analyze the prefix of 'Result in
9199 -- order to establish legality of the attribute.
9200
9201 Analyze (Prefix (Item));
9202
9203 -- The prefix of 'Result must denote the function for
9204 -- which aspect/pragma Depends applies.
9205
9206 if not Is_Entity_Name (Prefix (Item))
9207 or else Ekind (Subp_Id) /= E_Function
9208 or else Entity (Prefix (Item)) /= Subp_Id
9209 then
9210 Error_Msg_Name_1 := Name_Result;
9211 Error_Msg_N
9212 ("prefix of attribute % must denote the enclosing "
9213 & "function", Item);
9214
9215 -- Function'Result is allowed to appear on the output
9216 -- side of a dependency clause.
9217
9218 elsif Is_Input then
9219 Error_Msg_N
9220 ("function result cannot act as input", Item);
9221
9222 else
9223 Result_Seen := True;
9224 end if;
9225
9226 -- Detect multiple uses of null in a single dependency list
9227 -- or throughout the whole relation. Verify the placement of
9228 -- a null output list relative to the other clauses.
9229
9230 elsif Nkind (Item) = N_Null then
9231 if Null_Seen then
9232 Error_Msg_N
9233 ("multiple null dependency relations not allowed",
9234 Item);
9235 else
9236 Null_Seen := True;
9237
9238 if Is_Output and then not Is_Last then
9239 Error_Msg_N
9240 ("null output list must be the last clause in "
9241 & "a dependency relation", Item);
9242 end if;
9243 end if;
9244
9245 -- Default case
9246
9247 else
9248 Analyze (Item);
9249
9250 -- Find the entity of the item. If this is a renaming,
9251 -- climb the renaming chain to reach the root object.
9252 -- Renamings of non-entire objects do not yield an
9253 -- entity (Empty).
9254
9255 Item_Id := Entity_Of (Item);
9256
9257 if Present (Item_Id) then
9258 if Ekind_In (Item_Id, E_Abstract_State,
9259 E_In_Parameter,
9260 E_In_Out_Parameter,
9261 E_Out_Parameter,
9262 E_Variable)
9263 then
9264 -- Ensure that the item is of the correct mode
9265 -- depending on its function.
9266
9267 Check_Mode (Item, Item_Id, Is_Input);
9268
9269 -- Detect multiple uses of the same state, variable
9270 -- or formal parameter. If this is not the case,
9271 -- add the item to the list of processed relations.
9272
9273 if Contains (Seen, Item_Id) then
9274 Error_Msg_N ("duplicate use of item", Item);
9275 else
9276 Add_Item (Item_Id, Seen);
9277 end if;
9278
9279 -- Detect an illegal use of an input related to a
9280 -- null output. Such input items cannot appear in
9281 -- other input lists.
9282
9283 if Null_Output_Seen
9284 and then Contains (All_Inputs_Seen, Item_Id)
9285 then
9286 Error_Msg_N
9287 ("input of a null output list appears in "
9288 & "multiple input lists", Item);
9289 else
9290 Add_Item (Item_Id, All_Inputs_Seen);
9291 end if;
9292
9293 -- When the item renames an entire object, replace
9294 -- the item with a reference to the object.
9295
9296 if Present (Renamed_Object (Entity (Item))) then
9297 Rewrite (Item,
9298 New_Reference_To (Item_Id, Sloc (Item)));
9299 Analyze (Item);
9300 end if;
9301
9302 -- All other input/output items are illegal
9303
9304 else
9305 Error_Msg_N
9306 ("item must denote variable, state or formal "
9307 & "parameter", Item);
9308 end if;
9309
9310 -- All other input/output items are illegal
9311
9312 else
9313 Error_Msg_N
9314 ("item must denote variable, state or formal "
9315 & "parameter", Item);
9316 end if;
9317 end if;
9318 end Analyze_Input_Output;
9319
9320 -- Local variables
9321
9322 Inputs : Node_Id;
9323 Output : Node_Id;
9324
9325 -- Start of processing for Analyze_Dependency_Clause
9326
9327 begin
9328 -- Process the output_list of a dependency_clause
9329
9330 Output := First (Choices (Clause));
9331 while Present (Output) loop
9332 Analyze_Input_Output
9333 (Item => Output,
9334 Is_Input => False,
9335 Top_Level => True,
9336 Seen => Outputs_Seen,
9337 Null_Seen => Null_Output_Seen);
9338
9339 Next (Output);
9340 end loop;
9341
9342 -- Process the input_list of a dependency_clause
9343
9344 Inputs := Expression (Clause);
9345
9346 -- An input list with a self-dependency appears as operator "+"
9347 -- where the actuals inputs are the right operand.
9348
9349 if Nkind (Inputs) = N_Op_Plus then
9350 Inputs := Right_Opnd (Inputs);
9351 end if;
9352
9353 Analyze_Input_List (Inputs);
9354 end Analyze_Dependency_Clause;
9355
9356 ----------------
9357 -- Appears_In --
9358 ----------------
9359
9360 function Appears_In
9361 (List : Elist_Id;
9362 Item_Id : Entity_Id) return Boolean
9363 is
9364 Elmt : Elmt_Id;
9365 Id : Entity_Id;
9366
9367 begin
9368 if Present (List) then
9369 Elmt := First_Elmt (List);
9370 while Present (Elmt) loop
9371 if Nkind (Node (Elmt)) = N_Defining_Identifier then
9372 Id := Node (Elmt);
9373 else
9374 Id := Entity (Node (Elmt));
9375 end if;
9376
9377 if Id = Item_Id then
9378 return True;
9379 end if;
9380
9381 Next_Elmt (Elmt);
9382 end loop;
9383 end if;
9384
9385 return False;
9386 end Appears_In;
9387
9388 ----------------------------
9389 -- Check_Function_Return --
9390 ----------------------------
9391
9392 procedure Check_Function_Return is
9393 begin
9394 if Ekind (Subp_Id) = E_Function and then not Result_Seen then
9395 Error_Msg_NE
9396 ("result of & must appear in exactly one output list",
9397 N, Subp_Id);
9398 end if;
9399 end Check_Function_Return;
9400
9401 ----------------
9402 -- Check_Mode --
9403 ----------------
9404
9405 procedure Check_Mode
9406 (Item : Node_Id;
9407 Item_Id : Entity_Id;
9408 Is_Input : Boolean)
9409 is
9410 begin
9411 if Is_Input then
9412 if Ekind (Item_Id) = E_Out_Parameter
9413 or else (Global_Seen
9414 and then not Appears_In (Subp_Inputs, Item_Id))
9415 then
9416 Error_Msg_NE
9417 ("item & must have mode in or in out", Item, Item_Id);
9418 end if;
9419
9420 -- Output
9421
9422 else
9423 if Ekind (Item_Id) = E_In_Parameter
9424 or else
9425 (Global_Seen
9426 and then not Appears_In (Subp_Outputs, Item_Id))
9427 then
9428 Error_Msg_NE
9429 ("item & must have mode out or in out", Item, Item_Id);
9430 end if;
9431 end if;
9432 end Check_Mode;
9433
9434 -----------------
9435 -- Check_Usage --
9436 -----------------
9437
9438 procedure Check_Usage
9439 (Subp_List : Elist_Id;
9440 Item_List : Elist_Id;
9441 Is_Input : Boolean)
9442 is
9443 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id);
9444 -- Emit an error concerning the erroneous usage of an item
9445
9446 -----------------
9447 -- Usage_Error --
9448 -----------------
9449
9450 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id) is
9451 begin
9452 if Is_Input then
9453 Error_Msg_NE
9454 ("item & must appear in at least one input list of "
9455 & "aspect Depends", Item, Item_Id);
9456 else
9457 Error_Msg_NE
9458 ("item & must appear in exactly one output list of "
9459 & "aspect Depends", Item, Item_Id);
9460 end if;
9461 end Usage_Error;
9462
9463 -- Local variables
9464
9465 Elmt : Elmt_Id;
9466 Item : Node_Id;
9467 Item_Id : Entity_Id;
9468
9469 -- Start of processing for Check_Usage
9470
9471 begin
9472 if No (Subp_List) then
9473 return;
9474 end if;
9475
9476 -- Each input or output of the subprogram must appear in a
9477 -- dependency relation.
9478
9479 Elmt := First_Elmt (Subp_List);
9480 while Present (Elmt) loop
9481 Item := Node (Elmt);
9482
9483 if Nkind (Item) = N_Defining_Identifier then
9484 Item_Id := Item;
9485 else
9486 Item_Id := Entity (Item);
9487 end if;
9488
9489 -- The item does not appear in a dependency
9490
9491 if not Contains (Item_List, Item_Id) then
9492 if Is_Formal (Item_Id) then
9493 Usage_Error (Item, Item_Id);
9494
9495 -- States and global variables are not used properly only
9496 -- when the subprogram is subject to pragma Global.
9497
9498 elsif Global_Seen then
9499 Usage_Error (Item, Item_Id);
9500 end if;
9501 end if;
9502
9503 Next_Elmt (Elmt);
9504 end loop;
9505 end Check_Usage;
9506
9507 ---------------------------------------
9508 -- Collect_Subprogram_Inputs_Outputs --
9509 ---------------------------------------
9510
9511 procedure Collect_Subprogram_Inputs_Outputs is
9512 procedure Collect_Global_List
9513 (List : Node_Id;
9514 Mode : Name_Id := Name_Input);
9515 -- Collect all relevant items from a global list
9516
9517 -------------------------
9518 -- Collect_Global_List --
9519 -------------------------
9520
9521 procedure Collect_Global_List
9522 (List : Node_Id;
9523 Mode : Name_Id := Name_Input)
9524 is
9525 procedure Collect_Global_Item
9526 (Item : Node_Id;
9527 Mode : Name_Id);
9528 -- Add an item to the proper subprogram input or output
9529 -- collection.
9530
9531 -------------------------
9532 -- Collect_Global_Item --
9533 -------------------------
9534
9535 procedure Collect_Global_Item
9536 (Item : Node_Id;
9537 Mode : Name_Id)
9538 is
9539 begin
9540 if Mode = Name_In_Out or else Mode = Name_Input then
9541 Add_Item (Item, Subp_Inputs);
9542 end if;
9543
9544 if Mode = Name_In_Out or else Mode = Name_Output then
9545 Add_Item (Item, Subp_Outputs);
9546 end if;
9547 end Collect_Global_Item;
9548
9549 -- Local variables
9550
9551 Assoc : Node_Id;
9552 Item : Node_Id;
9553
9554 -- Start of processing for Collect_Global_List
9555
9556 begin
9557 -- Single global item declaration
9558
9559 if Nkind_In (List, N_Identifier, N_Selected_Component) then
9560 Collect_Global_Item (List, Mode);
9561
9562 -- Simple global list or moded global list declaration
9563
9564 else
9565 if Present (Expressions (List)) then
9566 Item := First (Expressions (List));
9567 while Present (Item) loop
9568 Collect_Global_Item (Item, Mode);
9569
9570 Next (Item);
9571 end loop;
9572
9573 else
9574 Assoc := First (Component_Associations (List));
9575 while Present (Assoc) loop
9576 Collect_Global_List
9577 (List => Expression (Assoc),
9578 Mode => Chars (First (Choices (Assoc))));
9579
9580 Next (Assoc);
9581 end loop;
9582 end if;
9583 end if;
9584 end Collect_Global_List;
9585
9586 -- Local variables
9587
9588 Formal : Entity_Id;
9589 Global : Node_Id;
9590 List : Node_Id;
9591
9592 -- Start of processing for Collect_Subprogram_Inputs_Outputs
9593
9594 begin
9595 -- Process all formal parameters
9596
9597 Formal := First_Formal (Subp_Id);
9598 while Present (Formal) loop
9599 if Ekind_In (Formal, E_In_Out_Parameter,
9600 E_In_Parameter)
9601 then
9602 Add_Item (Formal, Subp_Inputs);
9603 end if;
9604
9605 if Ekind_In (Formal, E_In_Out_Parameter,
9606 E_Out_Parameter)
9607 then
9608 Add_Item (Formal, Subp_Outputs);
9609 end if;
9610
9611 Next_Formal (Formal);
9612 end loop;
9613
9614 -- If the subprogram is subject to pragma Global, traverse all
9615 -- global lists and gather the relevant items.
9616
9617 Global := Find_Aspect (Subp_Id, Aspect_Global);
9618 if Present (Global) then
9619 Global_Seen := True;
9620
9621 -- Retrieve the pragma as it contains the analyzed lists
9622
9623 Global := Aspect_Rep_Item (Global);
9624
9625 -- The pragma may not have been analyzed because of the
9626 -- arbitrary declaration order of aspects. Make sure that
9627 -- it is analyzed for the purposes of item extraction.
9628
9629 if not Analyzed (Global) then
9630 Analyze (Global);
9631 end if;
9632
9633 List :=
9634 Expression (First (Pragma_Argument_Associations (Global)));
9635
9636 -- Nothing to be done for a null global list
9637
9638 if Nkind (List) /= N_Null then
9639 Collect_Global_List (List);
9640 end if;
9641 end if;
9642 end Collect_Subprogram_Inputs_Outputs;
9643
9644 ----------------------
9645 -- Normalize_Clause --
9646 ----------------------
9647
9648 procedure Normalize_Clause (Clause : Node_Id) is
9649 procedure Create_Or_Modify_Clause
9650 (Output : Node_Id;
9651 Outputs : Node_Id;
9652 Inputs : Node_Id;
9653 After : Node_Id;
9654 In_Place : Boolean;
9655 Multiple : Boolean);
9656 -- Create a brand new clause to represent the self-reference
9657 -- or modify the input and/or output lists of an existing
9658 -- clause. Output denotes a self-referencial output. Outputs
9659 -- is the output list of a clause. Inputs is the input list
9660 -- of a clause. After denotes the clause after which the new
9661 -- clause is to be inserted. Flag In_Place should be set when
9662 -- normalizing the last output of an output list. Flag Multiple
9663 -- should be set when Output comes from a list with multiple
9664 -- items.
9665
9666 -----------------------------
9667 -- Create_Or_Modify_Clause --
9668 -----------------------------
9669
9670 procedure Create_Or_Modify_Clause
9671 (Output : Node_Id;
9672 Outputs : Node_Id;
9673 Inputs : Node_Id;
9674 After : Node_Id;
9675 In_Place : Boolean;
9676 Multiple : Boolean)
9677 is
9678 procedure Propagate_Output
9679 (Output : Node_Id;
9680 Inputs : Node_Id);
9681 -- Handle the various cases of output propagation to the
9682 -- input list. Output denotes a self-referencial output
9683 -- item. Inputs is the input list of a clause.
9684
9685 ----------------------
9686 -- Propagate_Output --
9687 ----------------------
9688
9689 procedure Propagate_Output
9690 (Output : Node_Id;
9691 Inputs : Node_Id)
9692 is
9693 function In_Input_List
9694 (Item : Entity_Id;
9695 Inputs : List_Id) return Boolean;
9696 -- Determine whether a particulat item appears in the
9697 -- input list of a clause.
9698
9699 -------------------
9700 -- In_Input_List --
9701 -------------------
9702
9703 function In_Input_List
9704 (Item : Entity_Id;
9705 Inputs : List_Id) return Boolean
9706 is
9707 Elmt : Node_Id;
9708
9709 begin
9710 Elmt := First (Inputs);
9711 while Present (Elmt) loop
9712 if Entity_Of (Elmt) = Item then
9713 return True;
9714 end if;
9715
9716 Next (Elmt);
9717 end loop;
9718
9719 return False;
9720 end In_Input_List;
9721
9722 -- Local variables
9723
9724 Output_Id : constant Entity_Id := Entity_Of (Output);
9725 Grouped : List_Id;
9726
9727 -- Start of processing for Propagate_Output
9728
9729 begin
9730 -- The clause is of the form:
9731
9732 -- (Output =>+ null)
9733
9734 -- Remove the null input and replace it with a copy of
9735 -- the output:
9736
9737 -- (Output => Output)
9738
9739 if Nkind (Inputs) = N_Null then
9740 Rewrite (Inputs, New_Copy_Tree (Output));
9741
9742 -- The clause is of the form:
9743
9744 -- (Output =>+ (Input1, ..., InputN))
9745
9746 -- Determine whether the output is not already mentioned
9747 -- in the input list and if not, add it to the list of
9748 -- inputs:
9749
9750 -- (Output => (Output, Input1, ..., InputN))
9751
9752 elsif Nkind (Inputs) = N_Aggregate then
9753 Grouped := Expressions (Inputs);
9754
9755 if not In_Input_List
9756 (Item => Output_Id,
9757 Inputs => Grouped)
9758 then
9759 Prepend_To (Grouped, New_Copy_Tree (Output));
9760 end if;
9761
9762 -- The clause is of the form:
9763
9764 -- (Output =>+ Input)
9765
9766 -- If the input does not mention the output, group the
9767 -- two together:
9768
9769 -- (Output => (Output, Input))
9770
9771 elsif Entity_Of (Inputs) /= Output_Id then
9772 Rewrite (Inputs,
9773 Make_Aggregate (Loc,
9774 Expressions => New_List (
9775 New_Copy_Tree (Output),
9776 New_Copy_Tree (Inputs))));
9777 end if;
9778 end Propagate_Output;
9779
9780 -- Local variables
9781
9782 Loc : constant Source_Ptr := Sloc (Output);
9783 Clause : Node_Id;
9784
9785 -- Start of processing for Create_Or_Modify_Clause
9786
9787 begin
9788 -- A function result cannot depend on itself because it
9789 -- cannot appear in the input list of a relation.
9790
9791 if Nkind (Output) = N_Attribute_Reference
9792 and then Attribute_Name (Output) = Name_Result
9793 then
9794 Error_Msg_N
9795 ("function result cannot depend on itself", Output);
9796 return;
9797
9798 -- A null output depending on itself does not require any
9799 -- normalization.
9800
9801 elsif Nkind (Output) = N_Null then
9802 return;
9803 end if;
9804
9805 -- When performing the transformation in place, simply add
9806 -- the output to the list of inputs (if not already there).
9807 -- This case arises when dealing with the last output of an
9808 -- output list - we perform the normalization in place to
9809 -- avoid generating a malformed tree.
9810
9811 if In_Place then
9812 Propagate_Output (Output, Inputs);
9813
9814 -- A list with multiple outputs is slowly trimmed until
9815 -- only one element remains. When this happens, replace
9816 -- the aggregate with the element itself.
9817
9818 if Multiple then
9819 Remove (Output);
9820 Rewrite (Outputs, Output);
9821 end if;
9822
9823 -- Default case
9824
9825 else
9826 -- Unchain the output from its output list as it will
9827 -- appear in a new clause. Note that we cannot simply
9828 -- rewrite the output as null because this will violate
9829 -- the semantics of aspect/pragma Depends.
9830
9831 Remove (Output);
9832
9833 -- Create a new clause of the form:
9834
9835 -- (Output => Inputs)
9836
9837 Clause :=
9838 Make_Component_Association (Loc,
9839 Choices => New_List (Output),
9840 Expression => New_Copy_Tree (Inputs));
9841
9842 -- The new clause contains replicated content that has
9843 -- already been analyzed. There is not need to reanalyze
9844 -- it or renormalize it again.
9845
9846 Set_Analyzed (Clause);
9847
9848 Propagate_Output
9849 (Output => First (Choices (Clause)),
9850 Inputs => Expression (Clause));
9851
9852 Insert_After (After, Clause);
9853 end if;
9854 end Create_Or_Modify_Clause;
9855
9856 -- Local variables
9857
9858 Outputs : constant Node_Id := First (Choices (Clause));
9859 Inputs : Node_Id;
9860 Last_Output : Node_Id;
9861 Next_Output : Node_Id;
9862 Output : Node_Id;
9863
9864 -- Start of processing for Normalize_Clause
9865
9866 begin
9867 -- A self-dependency appears as operator "+". Remove the "+"
9868 -- from the tree by moving the real inputs to their proper
9869 -- place.
9870
9871 if Nkind (Expression (Clause)) = N_Op_Plus then
9872 Rewrite
9873 (Expression (Clause), Right_Opnd (Expression (Clause)));
9874 Inputs := Expression (Clause);
9875
9876 -- Multiple outputs appear as an aggregate
9877
9878 if Nkind (Outputs) = N_Aggregate then
9879 Last_Output := Last (Expressions (Outputs));
9880
9881 Output := First (Expressions (Outputs));
9882 while Present (Output) loop
9883
9884 -- Normalization may remove an output from its list,
9885 -- preserve the subsequent output now.
9886
9887 Next_Output := Next (Output);
9888
9889 Create_Or_Modify_Clause
9890 (Output => Output,
9891 Outputs => Outputs,
9892 Inputs => Inputs,
9893 After => Clause,
9894 In_Place => Output = Last_Output,
9895 Multiple => True);
9896
9897 Output := Next_Output;
9898 end loop;
9899
9900 -- Solitary output
9901
9902 else
9903 Create_Or_Modify_Clause
9904 (Output => Outputs,
9905 Outputs => Empty,
9906 Inputs => Inputs,
9907 After => Empty,
9908 In_Place => True,
9909 Multiple => False);
9910 end if;
9911 end if;
9912 end Normalize_Clause;
9913
9914 -- Local variables
9915
9916 Clause : Node_Id;
9917 Errors : Nat;
9918 Last_Clause : Node_Id;
9919 Subp_Decl : Node_Id;
9920
9921 -- Start of processing for Depends
9922
9923 begin
9924 GNAT_Pragma;
9925 S14_Pragma;
9926 Check_Arg_Count (1);
9927
9928 -- Ensure the proper placement of the pragma. Depends must be
9929 -- associated with a subprogram declaration.
9930
9931 Subp_Decl := Parent (Corresponding_Aspect (N));
9932
9933 if Nkind (Subp_Decl) /= N_Subprogram_Declaration then
9934 Pragma_Misplaced;
9935 return;
9936 end if;
9937
9938 Subp_Id := Defining_Unit_Name (Specification (Subp_Decl));
9939 Clause := Expression (Arg1);
9940
9941 -- Empty dependency list
9942
9943 if Nkind (Clause) = N_Null then
9944
9945 -- Gather all states, variables and formal parameters that the
9946 -- subprogram may depend on. These items are obtained from the
9947 -- parameter profile or pragma Global (if available).
9948
9949 Collect_Subprogram_Inputs_Outputs;
9950
9951 -- Verify that every input or output of the subprogram appear
9952 -- in a dependency.
9953
9954 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
9955 Check_Usage (Subp_Outputs, Outputs_Seen, False);
9956 Check_Function_Return;
9957
9958 -- Dependency clauses appear as component associations of an
9959 -- aggregate.
9960
9961 elsif Nkind (Clause) = N_Aggregate
9962 and then Present (Component_Associations (Clause))
9963 then
9964 Last_Clause := Last (Component_Associations (Clause));
9965
9966 -- Gather all states, variables and formal parameters that the
9967 -- subprogram may depend on. These items are obtained from the
9968 -- parameter profile or pragma Global (if available).
9969
9970 Collect_Subprogram_Inputs_Outputs;
9971
9972 -- Ensure that the formal parameters are visible when analyzing
9973 -- all clauses. This falls out of the general rule of aspects
9974 -- pertaining to subprogram declarations.
9975
9976 Push_Scope (Subp_Id);
9977 Install_Formals (Subp_Id);
9978
9979 Clause := First (Component_Associations (Clause));
9980 while Present (Clause) loop
9981 Errors := Serious_Errors_Detected;
9982
9983 -- Normalization may create extra clauses that contain
9984 -- replicated input and output names. There is no need
9985 -- to reanalyze or renormalize these extra clauses.
9986
9987 if not Analyzed (Clause) then
9988 Set_Analyzed (Clause);
9989
9990 Analyze_Dependency_Clause
9991 (Clause => Clause,
9992 Is_Last => Clause = Last_Clause);
9993
9994 -- Do not normalize an erroneous clause because the
9995 -- inputs or outputs may denote illegal items.
9996
9997 if Errors = Serious_Errors_Detected then
9998 Normalize_Clause (Clause);
9999 end if;
10000 end if;
10001
10002 Next (Clause);
10003 end loop;
10004
10005 End_Scope;
10006
10007 -- Verify that every input or output of the subprogram appear
10008 -- in a dependency.
10009
10010 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
10011 Check_Usage (Subp_Outputs, Outputs_Seen, False);
10012 Check_Function_Return;
10013
10014 -- The top level dependency relation is malformed
10015
10016 else
10017 Error_Msg_N ("malformed dependency relation", Clause);
10018 end if;
10019 end Depends;
10020
10021 ---------------------
10022 -- Detect_Blocking --
10023 ---------------------
10024
10025 -- pragma Detect_Blocking;
10026
10027 when Pragma_Detect_Blocking =>
10028 Ada_2005_Pragma;
10029 Check_Arg_Count (0);
10030 Check_Valid_Configuration_Pragma;
10031 Detect_Blocking := True;
10032
10033 --------------------------
10034 -- Default_Storage_Pool --
10035 --------------------------
10036
10037 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
10038
10039 when Pragma_Default_Storage_Pool =>
10040 Ada_2012_Pragma;
10041 Check_Arg_Count (1);
10042
10043 -- Default_Storage_Pool can appear as a configuration pragma, or
10044 -- in a declarative part or a package spec.
10045
10046 if not Is_Configuration_Pragma then
10047 Check_Is_In_Decl_Part_Or_Package_Spec;
10048 end if;
10049
10050 -- Case of Default_Storage_Pool (null);
10051
10052 if Nkind (Expression (Arg1)) = N_Null then
10053 Analyze (Expression (Arg1));
10054
10055 -- This is an odd case, this is not really an expression, so
10056 -- we don't have a type for it. So just set the type to Empty.
10057
10058 Set_Etype (Expression (Arg1), Empty);
10059
10060 -- Case of Default_Storage_Pool (storage_pool_NAME);
10061
10062 else
10063 -- If it's a configuration pragma, then the only allowed
10064 -- argument is "null".
10065
10066 if Is_Configuration_Pragma then
10067 Error_Pragma_Arg ("NULL expected", Arg1);
10068 end if;
10069
10070 -- The expected type for a non-"null" argument is
10071 -- Root_Storage_Pool'Class.
10072
10073 Analyze_And_Resolve
10074 (Get_Pragma_Arg (Arg1),
10075 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
10076 end if;
10077
10078 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
10079 -- for an access type will use this information to set the
10080 -- appropriate attributes of the access type.
10081
10082 Default_Pool := Expression (Arg1);
10083
10084 ------------------------------------
10085 -- Disable_Atomic_Synchronization --
10086 ------------------------------------
10087
10088 -- pragma Disable_Atomic_Synchronization [(Entity)];
10089
10090 when Pragma_Disable_Atomic_Synchronization =>
10091 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
10092
10093 -------------------
10094 -- Discard_Names --
10095 -------------------
10096
10097 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
10098
10099 when Pragma_Discard_Names => Discard_Names : declare
10100 E : Entity_Id;
10101 E_Id : Entity_Id;
10102
10103 begin
10104 Check_Ada_83_Warning;
10105
10106 -- Deal with configuration pragma case
10107
10108 if Arg_Count = 0 and then Is_Configuration_Pragma then
10109 Global_Discard_Names := True;
10110 return;
10111
10112 -- Otherwise, check correct appropriate context
10113
10114 else
10115 Check_Is_In_Decl_Part_Or_Package_Spec;
10116
10117 if Arg_Count = 0 then
10118
10119 -- If there is no parameter, then from now on this pragma
10120 -- applies to any enumeration, exception or tagged type
10121 -- defined in the current declarative part, and recursively
10122 -- to any nested scope.
10123
10124 Set_Discard_Names (Current_Scope);
10125 return;
10126
10127 else
10128 Check_Arg_Count (1);
10129 Check_Optional_Identifier (Arg1, Name_On);
10130 Check_Arg_Is_Local_Name (Arg1);
10131
10132 E_Id := Get_Pragma_Arg (Arg1);
10133
10134 if Etype (E_Id) = Any_Type then
10135 return;
10136 else
10137 E := Entity (E_Id);
10138 end if;
10139
10140 if (Is_First_Subtype (E)
10141 and then
10142 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
10143 or else Ekind (E) = E_Exception
10144 then
10145 Set_Discard_Names (E);
10146 Record_Rep_Item (E, N);
10147
10148 else
10149 Error_Pragma_Arg
10150 ("inappropriate entity for pragma%", Arg1);
10151 end if;
10152
10153 end if;
10154 end if;
10155 end Discard_Names;
10156
10157 ------------------------
10158 -- Dispatching_Domain --
10159 ------------------------
10160
10161 -- pragma Dispatching_Domain (EXPRESSION);
10162
10163 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
10164 P : constant Node_Id := Parent (N);
10165 Arg : Node_Id;
10166 Ent : Entity_Id;
10167
10168 begin
10169 Ada_2012_Pragma;
10170 Check_No_Identifiers;
10171 Check_Arg_Count (1);
10172
10173 -- This pragma is born obsolete, but not the aspect
10174
10175 if not From_Aspect_Specification (N) then
10176 Check_Restriction
10177 (No_Obsolescent_Features, Pragma_Identifier (N));
10178 end if;
10179
10180 if Nkind (P) = N_Task_Definition then
10181 Arg := Get_Pragma_Arg (Arg1);
10182 Ent := Defining_Identifier (Parent (P));
10183
10184 -- The expression must be analyzed in the special manner
10185 -- described in "Handling of Default and Per-Object
10186 -- Expressions" in sem.ads.
10187
10188 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
10189
10190 -- Check duplicate pragma before we chain the pragma in the Rep
10191 -- Item chain of Ent.
10192
10193 Check_Duplicate_Pragma (Ent);
10194 Record_Rep_Item (Ent, N);
10195
10196 -- Anything else is incorrect
10197
10198 else
10199 Pragma_Misplaced;
10200 end if;
10201 end Dispatching_Domain;
10202
10203 ---------------
10204 -- Elaborate --
10205 ---------------
10206
10207 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
10208
10209 when Pragma_Elaborate => Elaborate : declare
10210 Arg : Node_Id;
10211 Citem : Node_Id;
10212
10213 begin
10214 -- Pragma must be in context items list of a compilation unit
10215
10216 if not Is_In_Context_Clause then
10217 Pragma_Misplaced;
10218 end if;
10219
10220 -- Must be at least one argument
10221
10222 if Arg_Count = 0 then
10223 Error_Pragma ("pragma% requires at least one argument");
10224 end if;
10225
10226 -- In Ada 83 mode, there can be no items following it in the
10227 -- context list except other pragmas and implicit with clauses
10228 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
10229 -- placement rule does not apply.
10230
10231 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
10232 Citem := Next (N);
10233 while Present (Citem) loop
10234 if Nkind (Citem) = N_Pragma
10235 or else (Nkind (Citem) = N_With_Clause
10236 and then Implicit_With (Citem))
10237 then
10238 null;
10239 else
10240 Error_Pragma
10241 ("(Ada 83) pragma% must be at end of context clause");
10242 end if;
10243
10244 Next (Citem);
10245 end loop;
10246 end if;
10247
10248 -- Finally, the arguments must all be units mentioned in a with
10249 -- clause in the same context clause. Note we already checked (in
10250 -- Par.Prag) that the arguments are all identifiers or selected
10251 -- components.
10252
10253 Arg := Arg1;
10254 Outer : while Present (Arg) loop
10255 Citem := First (List_Containing (N));
10256 Inner : while Citem /= N loop
10257 if Nkind (Citem) = N_With_Clause
10258 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
10259 then
10260 Set_Elaborate_Present (Citem, True);
10261 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
10262 Generate_Reference (Entity (Name (Citem)), Citem);
10263
10264 -- With the pragma present, elaboration calls on
10265 -- subprograms from the named unit need no further
10266 -- checks, as long as the pragma appears in the current
10267 -- compilation unit. If the pragma appears in some unit
10268 -- in the context, there might still be a need for an
10269 -- Elaborate_All_Desirable from the current compilation
10270 -- to the named unit, so we keep the check enabled.
10271
10272 if In_Extended_Main_Source_Unit (N) then
10273 Set_Suppress_Elaboration_Warnings
10274 (Entity (Name (Citem)));
10275 end if;
10276
10277 exit Inner;
10278 end if;
10279
10280 Next (Citem);
10281 end loop Inner;
10282
10283 if Citem = N then
10284 Error_Pragma_Arg
10285 ("argument of pragma% is not withed unit", Arg);
10286 end if;
10287
10288 Next (Arg);
10289 end loop Outer;
10290
10291 -- Give a warning if operating in static mode with -gnatwl
10292 -- (elaboration warnings enabled) switch set.
10293
10294 if Elab_Warnings and not Dynamic_Elaboration_Checks then
10295 Error_Msg_N
10296 ("?l?use of pragma Elaborate may not be safe", N);
10297 Error_Msg_N
10298 ("?l?use pragma Elaborate_All instead if possible", N);
10299 end if;
10300 end Elaborate;
10301
10302 -------------------
10303 -- Elaborate_All --
10304 -------------------
10305
10306 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
10307
10308 when Pragma_Elaborate_All => Elaborate_All : declare
10309 Arg : Node_Id;
10310 Citem : Node_Id;
10311
10312 begin
10313 Check_Ada_83_Warning;
10314
10315 -- Pragma must be in context items list of a compilation unit
10316
10317 if not Is_In_Context_Clause then
10318 Pragma_Misplaced;
10319 end if;
10320
10321 -- Must be at least one argument
10322
10323 if Arg_Count = 0 then
10324 Error_Pragma ("pragma% requires at least one argument");
10325 end if;
10326
10327 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
10328 -- have to appear at the end of the context clause, but may
10329 -- appear mixed in with other items, even in Ada 83 mode.
10330
10331 -- Final check: the arguments must all be units mentioned in
10332 -- a with clause in the same context clause. Note that we
10333 -- already checked (in Par.Prag) that all the arguments are
10334 -- either identifiers or selected components.
10335
10336 Arg := Arg1;
10337 Outr : while Present (Arg) loop
10338 Citem := First (List_Containing (N));
10339 Innr : while Citem /= N loop
10340 if Nkind (Citem) = N_With_Clause
10341 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
10342 then
10343 Set_Elaborate_All_Present (Citem, True);
10344 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
10345
10346 -- Suppress warnings and elaboration checks on the named
10347 -- unit if the pragma is in the current compilation, as
10348 -- for pragma Elaborate.
10349
10350 if In_Extended_Main_Source_Unit (N) then
10351 Set_Suppress_Elaboration_Warnings
10352 (Entity (Name (Citem)));
10353 end if;
10354 exit Innr;
10355 end if;
10356
10357 Next (Citem);
10358 end loop Innr;
10359
10360 if Citem = N then
10361 Set_Error_Posted (N);
10362 Error_Pragma_Arg
10363 ("argument of pragma% is not withed unit", Arg);
10364 end if;
10365
10366 Next (Arg);
10367 end loop Outr;
10368 end Elaborate_All;
10369
10370 --------------------
10371 -- Elaborate_Body --
10372 --------------------
10373
10374 -- pragma Elaborate_Body [( library_unit_NAME )];
10375
10376 when Pragma_Elaborate_Body => Elaborate_Body : declare
10377 Cunit_Node : Node_Id;
10378 Cunit_Ent : Entity_Id;
10379
10380 begin
10381 Check_Ada_83_Warning;
10382 Check_Valid_Library_Unit_Pragma;
10383
10384 if Nkind (N) = N_Null_Statement then
10385 return;
10386 end if;
10387
10388 Cunit_Node := Cunit (Current_Sem_Unit);
10389 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10390
10391 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
10392 N_Subprogram_Body)
10393 then
10394 Error_Pragma ("pragma% must refer to a spec, not a body");
10395 else
10396 Set_Body_Required (Cunit_Node, True);
10397 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
10398
10399 -- If we are in dynamic elaboration mode, then we suppress
10400 -- elaboration warnings for the unit, since it is definitely
10401 -- fine NOT to do dynamic checks at the first level (and such
10402 -- checks will be suppressed because no elaboration boolean
10403 -- is created for Elaborate_Body packages).
10404
10405 -- But in the static model of elaboration, Elaborate_Body is
10406 -- definitely NOT good enough to ensure elaboration safety on
10407 -- its own, since the body may WITH other units that are not
10408 -- safe from an elaboration point of view, so a client must
10409 -- still do an Elaborate_All on such units.
10410
10411 -- Debug flag -gnatdD restores the old behavior of 3.13, where
10412 -- Elaborate_Body always suppressed elab warnings.
10413
10414 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
10415 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
10416 end if;
10417 end if;
10418 end Elaborate_Body;
10419
10420 ------------------------
10421 -- Elaboration_Checks --
10422 ------------------------
10423
10424 -- pragma Elaboration_Checks (Static | Dynamic);
10425
10426 when Pragma_Elaboration_Checks =>
10427 GNAT_Pragma;
10428 Check_Arg_Count (1);
10429 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
10430 Dynamic_Elaboration_Checks :=
10431 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
10432
10433 ---------------
10434 -- Eliminate --
10435 ---------------
10436
10437 -- pragma Eliminate (
10438 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
10439 -- [,[Entity =>] IDENTIFIER |
10440 -- SELECTED_COMPONENT |
10441 -- STRING_LITERAL]
10442 -- [, OVERLOADING_RESOLUTION]);
10443
10444 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
10445 -- SOURCE_LOCATION
10446
10447 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
10448 -- FUNCTION_PROFILE
10449
10450 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
10451
10452 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
10453 -- Result_Type => result_SUBTYPE_NAME]
10454
10455 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
10456 -- SUBTYPE_NAME ::= STRING_LITERAL
10457
10458 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
10459 -- SOURCE_TRACE ::= STRING_LITERAL
10460
10461 when Pragma_Eliminate => Eliminate : declare
10462 Args : Args_List (1 .. 5);
10463 Names : constant Name_List (1 .. 5) := (
10464 Name_Unit_Name,
10465 Name_Entity,
10466 Name_Parameter_Types,
10467 Name_Result_Type,
10468 Name_Source_Location);
10469
10470 Unit_Name : Node_Id renames Args (1);
10471 Entity : Node_Id renames Args (2);
10472 Parameter_Types : Node_Id renames Args (3);
10473 Result_Type : Node_Id renames Args (4);
10474 Source_Location : Node_Id renames Args (5);
10475
10476 begin
10477 GNAT_Pragma;
10478 Check_Valid_Configuration_Pragma;
10479 Gather_Associations (Names, Args);
10480
10481 if No (Unit_Name) then
10482 Error_Pragma ("missing Unit_Name argument for pragma%");
10483 end if;
10484
10485 if No (Entity)
10486 and then (Present (Parameter_Types)
10487 or else
10488 Present (Result_Type)
10489 or else
10490 Present (Source_Location))
10491 then
10492 Error_Pragma ("missing Entity argument for pragma%");
10493 end if;
10494
10495 if (Present (Parameter_Types)
10496 or else
10497 Present (Result_Type))
10498 and then
10499 Present (Source_Location)
10500 then
10501 Error_Pragma
10502 ("parameter profile and source location cannot be used "
10503 & "together in pragma%");
10504 end if;
10505
10506 Process_Eliminate_Pragma
10507 (N,
10508 Unit_Name,
10509 Entity,
10510 Parameter_Types,
10511 Result_Type,
10512 Source_Location);
10513 end Eliminate;
10514
10515 -----------------------------------
10516 -- Enable_Atomic_Synchronization --
10517 -----------------------------------
10518
10519 -- pragma Enable_Atomic_Synchronization [(Entity)];
10520
10521 when Pragma_Enable_Atomic_Synchronization =>
10522 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
10523
10524 ------------
10525 -- Export --
10526 ------------
10527
10528 -- pragma Export (
10529 -- [ Convention =>] convention_IDENTIFIER,
10530 -- [ Entity =>] local_NAME
10531 -- [, [External_Name =>] static_string_EXPRESSION ]
10532 -- [, [Link_Name =>] static_string_EXPRESSION ]);
10533
10534 when Pragma_Export => Export : declare
10535 C : Convention_Id;
10536 Def_Id : Entity_Id;
10537
10538 pragma Warnings (Off, C);
10539
10540 begin
10541 Check_Ada_83_Warning;
10542 Check_Arg_Order
10543 ((Name_Convention,
10544 Name_Entity,
10545 Name_External_Name,
10546 Name_Link_Name));
10547
10548 Check_At_Least_N_Arguments (2);
10549
10550 Check_At_Most_N_Arguments (4);
10551 Process_Convention (C, Def_Id);
10552
10553 if Ekind (Def_Id) /= E_Constant then
10554 Note_Possible_Modification
10555 (Get_Pragma_Arg (Arg2), Sure => False);
10556 end if;
10557
10558 Process_Interface_Name (Def_Id, Arg3, Arg4);
10559 Set_Exported (Def_Id, Arg2);
10560
10561 -- If the entity is a deferred constant, propagate the information
10562 -- to the full view, because gigi elaborates the full view only.
10563
10564 if Ekind (Def_Id) = E_Constant
10565 and then Present (Full_View (Def_Id))
10566 then
10567 declare
10568 Id2 : constant Entity_Id := Full_View (Def_Id);
10569 begin
10570 Set_Is_Exported (Id2, Is_Exported (Def_Id));
10571 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
10572 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
10573 end;
10574 end if;
10575 end Export;
10576
10577 ----------------------
10578 -- Export_Exception --
10579 ----------------------
10580
10581 -- pragma Export_Exception (
10582 -- [Internal =>] LOCAL_NAME
10583 -- [, [External =>] EXTERNAL_SYMBOL]
10584 -- [, [Form =>] Ada | VMS]
10585 -- [, [Code =>] static_integer_EXPRESSION]);
10586
10587 when Pragma_Export_Exception => Export_Exception : declare
10588 Args : Args_List (1 .. 4);
10589 Names : constant Name_List (1 .. 4) := (
10590 Name_Internal,
10591 Name_External,
10592 Name_Form,
10593 Name_Code);
10594
10595 Internal : Node_Id renames Args (1);
10596 External : Node_Id renames Args (2);
10597 Form : Node_Id renames Args (3);
10598 Code : Node_Id renames Args (4);
10599
10600 begin
10601 GNAT_Pragma;
10602
10603 if Inside_A_Generic then
10604 Error_Pragma ("pragma% cannot be used for generic entities");
10605 end if;
10606
10607 Gather_Associations (Names, Args);
10608 Process_Extended_Import_Export_Exception_Pragma (
10609 Arg_Internal => Internal,
10610 Arg_External => External,
10611 Arg_Form => Form,
10612 Arg_Code => Code);
10613
10614 if not Is_VMS_Exception (Entity (Internal)) then
10615 Set_Exported (Entity (Internal), Internal);
10616 end if;
10617 end Export_Exception;
10618
10619 ---------------------
10620 -- Export_Function --
10621 ---------------------
10622
10623 -- pragma Export_Function (
10624 -- [Internal =>] LOCAL_NAME
10625 -- [, [External =>] EXTERNAL_SYMBOL]
10626 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10627 -- [, [Result_Type =>] TYPE_DESIGNATOR]
10628 -- [, [Mechanism =>] MECHANISM]
10629 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
10630
10631 -- EXTERNAL_SYMBOL ::=
10632 -- IDENTIFIER
10633 -- | static_string_EXPRESSION
10634
10635 -- PARAMETER_TYPES ::=
10636 -- null
10637 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10638
10639 -- TYPE_DESIGNATOR ::=
10640 -- subtype_NAME
10641 -- | subtype_Name ' Access
10642
10643 -- MECHANISM ::=
10644 -- MECHANISM_NAME
10645 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10646
10647 -- MECHANISM_ASSOCIATION ::=
10648 -- [formal_parameter_NAME =>] MECHANISM_NAME
10649
10650 -- MECHANISM_NAME ::=
10651 -- Value
10652 -- | Reference
10653 -- | Descriptor [([Class =>] CLASS_NAME)]
10654
10655 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10656
10657 when Pragma_Export_Function => Export_Function : declare
10658 Args : Args_List (1 .. 6);
10659 Names : constant Name_List (1 .. 6) := (
10660 Name_Internal,
10661 Name_External,
10662 Name_Parameter_Types,
10663 Name_Result_Type,
10664 Name_Mechanism,
10665 Name_Result_Mechanism);
10666
10667 Internal : Node_Id renames Args (1);
10668 External : Node_Id renames Args (2);
10669 Parameter_Types : Node_Id renames Args (3);
10670 Result_Type : Node_Id renames Args (4);
10671 Mechanism : Node_Id renames Args (5);
10672 Result_Mechanism : Node_Id renames Args (6);
10673
10674 begin
10675 GNAT_Pragma;
10676 Gather_Associations (Names, Args);
10677 Process_Extended_Import_Export_Subprogram_Pragma (
10678 Arg_Internal => Internal,
10679 Arg_External => External,
10680 Arg_Parameter_Types => Parameter_Types,
10681 Arg_Result_Type => Result_Type,
10682 Arg_Mechanism => Mechanism,
10683 Arg_Result_Mechanism => Result_Mechanism);
10684 end Export_Function;
10685
10686 -------------------
10687 -- Export_Object --
10688 -------------------
10689
10690 -- pragma Export_Object (
10691 -- [Internal =>] LOCAL_NAME
10692 -- [, [External =>] EXTERNAL_SYMBOL]
10693 -- [, [Size =>] EXTERNAL_SYMBOL]);
10694
10695 -- EXTERNAL_SYMBOL ::=
10696 -- IDENTIFIER
10697 -- | static_string_EXPRESSION
10698
10699 -- PARAMETER_TYPES ::=
10700 -- null
10701 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10702
10703 -- TYPE_DESIGNATOR ::=
10704 -- subtype_NAME
10705 -- | subtype_Name ' Access
10706
10707 -- MECHANISM ::=
10708 -- MECHANISM_NAME
10709 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10710
10711 -- MECHANISM_ASSOCIATION ::=
10712 -- [formal_parameter_NAME =>] MECHANISM_NAME
10713
10714 -- MECHANISM_NAME ::=
10715 -- Value
10716 -- | Reference
10717 -- | Descriptor [([Class =>] CLASS_NAME)]
10718
10719 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10720
10721 when Pragma_Export_Object => Export_Object : declare
10722 Args : Args_List (1 .. 3);
10723 Names : constant Name_List (1 .. 3) := (
10724 Name_Internal,
10725 Name_External,
10726 Name_Size);
10727
10728 Internal : Node_Id renames Args (1);
10729 External : Node_Id renames Args (2);
10730 Size : Node_Id renames Args (3);
10731
10732 begin
10733 GNAT_Pragma;
10734 Gather_Associations (Names, Args);
10735 Process_Extended_Import_Export_Object_Pragma (
10736 Arg_Internal => Internal,
10737 Arg_External => External,
10738 Arg_Size => Size);
10739 end Export_Object;
10740
10741 ----------------------
10742 -- Export_Procedure --
10743 ----------------------
10744
10745 -- pragma Export_Procedure (
10746 -- [Internal =>] LOCAL_NAME
10747 -- [, [External =>] EXTERNAL_SYMBOL]
10748 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10749 -- [, [Mechanism =>] MECHANISM]);
10750
10751 -- EXTERNAL_SYMBOL ::=
10752 -- IDENTIFIER
10753 -- | static_string_EXPRESSION
10754
10755 -- PARAMETER_TYPES ::=
10756 -- null
10757 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10758
10759 -- TYPE_DESIGNATOR ::=
10760 -- subtype_NAME
10761 -- | subtype_Name ' Access
10762
10763 -- MECHANISM ::=
10764 -- MECHANISM_NAME
10765 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10766
10767 -- MECHANISM_ASSOCIATION ::=
10768 -- [formal_parameter_NAME =>] MECHANISM_NAME
10769
10770 -- MECHANISM_NAME ::=
10771 -- Value
10772 -- | Reference
10773 -- | Descriptor [([Class =>] CLASS_NAME)]
10774
10775 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10776
10777 when Pragma_Export_Procedure => Export_Procedure : declare
10778 Args : Args_List (1 .. 4);
10779 Names : constant Name_List (1 .. 4) := (
10780 Name_Internal,
10781 Name_External,
10782 Name_Parameter_Types,
10783 Name_Mechanism);
10784
10785 Internal : Node_Id renames Args (1);
10786 External : Node_Id renames Args (2);
10787 Parameter_Types : Node_Id renames Args (3);
10788 Mechanism : Node_Id renames Args (4);
10789
10790 begin
10791 GNAT_Pragma;
10792 Gather_Associations (Names, Args);
10793 Process_Extended_Import_Export_Subprogram_Pragma (
10794 Arg_Internal => Internal,
10795 Arg_External => External,
10796 Arg_Parameter_Types => Parameter_Types,
10797 Arg_Mechanism => Mechanism);
10798 end Export_Procedure;
10799
10800 ------------------
10801 -- Export_Value --
10802 ------------------
10803
10804 -- pragma Export_Value (
10805 -- [Value =>] static_integer_EXPRESSION,
10806 -- [Link_Name =>] static_string_EXPRESSION);
10807
10808 when Pragma_Export_Value =>
10809 GNAT_Pragma;
10810 Check_Arg_Order ((Name_Value, Name_Link_Name));
10811 Check_Arg_Count (2);
10812
10813 Check_Optional_Identifier (Arg1, Name_Value);
10814 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10815
10816 Check_Optional_Identifier (Arg2, Name_Link_Name);
10817 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10818
10819 -----------------------------
10820 -- Export_Valued_Procedure --
10821 -----------------------------
10822
10823 -- pragma Export_Valued_Procedure (
10824 -- [Internal =>] LOCAL_NAME
10825 -- [, [External =>] EXTERNAL_SYMBOL,]
10826 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10827 -- [, [Mechanism =>] MECHANISM]);
10828
10829 -- EXTERNAL_SYMBOL ::=
10830 -- IDENTIFIER
10831 -- | static_string_EXPRESSION
10832
10833 -- PARAMETER_TYPES ::=
10834 -- null
10835 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10836
10837 -- TYPE_DESIGNATOR ::=
10838 -- subtype_NAME
10839 -- | subtype_Name ' Access
10840
10841 -- MECHANISM ::=
10842 -- MECHANISM_NAME
10843 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10844
10845 -- MECHANISM_ASSOCIATION ::=
10846 -- [formal_parameter_NAME =>] MECHANISM_NAME
10847
10848 -- MECHANISM_NAME ::=
10849 -- Value
10850 -- | Reference
10851 -- | Descriptor [([Class =>] CLASS_NAME)]
10852
10853 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10854
10855 when Pragma_Export_Valued_Procedure =>
10856 Export_Valued_Procedure : declare
10857 Args : Args_List (1 .. 4);
10858 Names : constant Name_List (1 .. 4) := (
10859 Name_Internal,
10860 Name_External,
10861 Name_Parameter_Types,
10862 Name_Mechanism);
10863
10864 Internal : Node_Id renames Args (1);
10865 External : Node_Id renames Args (2);
10866 Parameter_Types : Node_Id renames Args (3);
10867 Mechanism : Node_Id renames Args (4);
10868
10869 begin
10870 GNAT_Pragma;
10871 Gather_Associations (Names, Args);
10872 Process_Extended_Import_Export_Subprogram_Pragma (
10873 Arg_Internal => Internal,
10874 Arg_External => External,
10875 Arg_Parameter_Types => Parameter_Types,
10876 Arg_Mechanism => Mechanism);
10877 end Export_Valued_Procedure;
10878
10879 -------------------
10880 -- Extend_System --
10881 -------------------
10882
10883 -- pragma Extend_System ([Name =>] Identifier);
10884
10885 when Pragma_Extend_System => Extend_System : declare
10886 begin
10887 GNAT_Pragma;
10888 Check_Valid_Configuration_Pragma;
10889 Check_Arg_Count (1);
10890 Check_Optional_Identifier (Arg1, Name_Name);
10891 Check_Arg_Is_Identifier (Arg1);
10892
10893 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10894
10895 if Name_Len > 4
10896 and then Name_Buffer (1 .. 4) = "aux_"
10897 then
10898 if Present (System_Extend_Pragma_Arg) then
10899 if Chars (Get_Pragma_Arg (Arg1)) =
10900 Chars (Expression (System_Extend_Pragma_Arg))
10901 then
10902 null;
10903 else
10904 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
10905 Error_Pragma ("pragma% conflicts with that #");
10906 end if;
10907
10908 else
10909 System_Extend_Pragma_Arg := Arg1;
10910
10911 if not GNAT_Mode then
10912 System_Extend_Unit := Arg1;
10913 end if;
10914 end if;
10915 else
10916 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
10917 end if;
10918 end Extend_System;
10919
10920 ------------------------
10921 -- Extensions_Allowed --
10922 ------------------------
10923
10924 -- pragma Extensions_Allowed (ON | OFF);
10925
10926 when Pragma_Extensions_Allowed =>
10927 GNAT_Pragma;
10928 Check_Arg_Count (1);
10929 Check_No_Identifiers;
10930 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10931
10932 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
10933 Extensions_Allowed := True;
10934 Ada_Version := Ada_Version_Type'Last;
10935
10936 else
10937 Extensions_Allowed := False;
10938 Ada_Version := Ada_Version_Explicit;
10939 end if;
10940
10941 --------------
10942 -- External --
10943 --------------
10944
10945 -- pragma External (
10946 -- [ Convention =>] convention_IDENTIFIER,
10947 -- [ Entity =>] local_NAME
10948 -- [, [External_Name =>] static_string_EXPRESSION ]
10949 -- [, [Link_Name =>] static_string_EXPRESSION ]);
10950
10951 when Pragma_External => External : declare
10952 Def_Id : Entity_Id;
10953
10954 C : Convention_Id;
10955 pragma Warnings (Off, C);
10956
10957 begin
10958 GNAT_Pragma;
10959 Check_Arg_Order
10960 ((Name_Convention,
10961 Name_Entity,
10962 Name_External_Name,
10963 Name_Link_Name));
10964 Check_At_Least_N_Arguments (2);
10965 Check_At_Most_N_Arguments (4);
10966 Process_Convention (C, Def_Id);
10967 Note_Possible_Modification
10968 (Get_Pragma_Arg (Arg2), Sure => False);
10969 Process_Interface_Name (Def_Id, Arg3, Arg4);
10970 Set_Exported (Def_Id, Arg2);
10971 end External;
10972
10973 --------------------------
10974 -- External_Name_Casing --
10975 --------------------------
10976
10977 -- pragma External_Name_Casing (
10978 -- UPPERCASE | LOWERCASE
10979 -- [, AS_IS | UPPERCASE | LOWERCASE]);
10980
10981 when Pragma_External_Name_Casing => External_Name_Casing : declare
10982 begin
10983 GNAT_Pragma;
10984 Check_No_Identifiers;
10985
10986 if Arg_Count = 2 then
10987 Check_Arg_Is_One_Of
10988 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
10989
10990 case Chars (Get_Pragma_Arg (Arg2)) is
10991 when Name_As_Is =>
10992 Opt.External_Name_Exp_Casing := As_Is;
10993
10994 when Name_Uppercase =>
10995 Opt.External_Name_Exp_Casing := Uppercase;
10996
10997 when Name_Lowercase =>
10998 Opt.External_Name_Exp_Casing := Lowercase;
10999
11000 when others =>
11001 null;
11002 end case;
11003
11004 else
11005 Check_Arg_Count (1);
11006 end if;
11007
11008 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
11009
11010 case Chars (Get_Pragma_Arg (Arg1)) is
11011 when Name_Uppercase =>
11012 Opt.External_Name_Imp_Casing := Uppercase;
11013
11014 when Name_Lowercase =>
11015 Opt.External_Name_Imp_Casing := Lowercase;
11016
11017 when others =>
11018 null;
11019 end case;
11020 end External_Name_Casing;
11021
11022 --------------------------
11023 -- Favor_Top_Level --
11024 --------------------------
11025
11026 -- pragma Favor_Top_Level (type_NAME);
11027
11028 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
11029 Named_Entity : Entity_Id;
11030
11031 begin
11032 GNAT_Pragma;
11033 Check_No_Identifiers;
11034 Check_Arg_Count (1);
11035 Check_Arg_Is_Local_Name (Arg1);
11036 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
11037
11038 -- If it's an access-to-subprogram type (in particular, not a
11039 -- subtype), set the flag on that type.
11040
11041 if Is_Access_Subprogram_Type (Named_Entity) then
11042 Set_Can_Use_Internal_Rep (Named_Entity, False);
11043
11044 -- Otherwise it's an error (name denotes the wrong sort of entity)
11045
11046 else
11047 Error_Pragma_Arg
11048 ("access-to-subprogram type expected",
11049 Get_Pragma_Arg (Arg1));
11050 end if;
11051 end Favor_Top_Level;
11052
11053 ---------------
11054 -- Fast_Math --
11055 ---------------
11056
11057 -- pragma Fast_Math;
11058
11059 when Pragma_Fast_Math =>
11060 GNAT_Pragma;
11061 Check_No_Identifiers;
11062 Check_Valid_Configuration_Pragma;
11063 Fast_Math := True;
11064
11065 ---------------------------
11066 -- Finalize_Storage_Only --
11067 ---------------------------
11068
11069 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
11070
11071 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
11072 Assoc : constant Node_Id := Arg1;
11073 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
11074 Typ : Entity_Id;
11075
11076 begin
11077 GNAT_Pragma;
11078 Check_No_Identifiers;
11079 Check_Arg_Count (1);
11080 Check_Arg_Is_Local_Name (Arg1);
11081
11082 Find_Type (Type_Id);
11083 Typ := Entity (Type_Id);
11084
11085 if Typ = Any_Type
11086 or else Rep_Item_Too_Early (Typ, N)
11087 then
11088 return;
11089 else
11090 Typ := Underlying_Type (Typ);
11091 end if;
11092
11093 if not Is_Controlled (Typ) then
11094 Error_Pragma ("pragma% must specify controlled type");
11095 end if;
11096
11097 Check_First_Subtype (Arg1);
11098
11099 if Finalize_Storage_Only (Typ) then
11100 Error_Pragma ("duplicate pragma%, only one allowed");
11101
11102 elsif not Rep_Item_Too_Late (Typ, N) then
11103 Set_Finalize_Storage_Only (Base_Type (Typ), True);
11104 end if;
11105 end Finalize_Storage;
11106
11107 --------------------------
11108 -- Float_Representation --
11109 --------------------------
11110
11111 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
11112
11113 -- FLOAT_REP ::= VAX_Float | IEEE_Float
11114
11115 when Pragma_Float_Representation => Float_Representation : declare
11116 Argx : Node_Id;
11117 Digs : Nat;
11118 Ent : Entity_Id;
11119
11120 begin
11121 GNAT_Pragma;
11122
11123 if Arg_Count = 1 then
11124 Check_Valid_Configuration_Pragma;
11125 else
11126 Check_Arg_Count (2);
11127 Check_Optional_Identifier (Arg2, Name_Entity);
11128 Check_Arg_Is_Local_Name (Arg2);
11129 end if;
11130
11131 Check_No_Identifier (Arg1);
11132 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
11133
11134 if not OpenVMS_On_Target then
11135 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
11136 Error_Pragma
11137 ("??pragma% ignored (applies only to Open'V'M'S)");
11138 end if;
11139
11140 return;
11141 end if;
11142
11143 -- One argument case
11144
11145 if Arg_Count = 1 then
11146 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
11147 if Opt.Float_Format = 'I' then
11148 Error_Pragma ("'I'E'E'E format previously specified");
11149 end if;
11150
11151 Opt.Float_Format := 'V';
11152
11153 else
11154 if Opt.Float_Format = 'V' then
11155 Error_Pragma ("'V'A'X format previously specified");
11156 end if;
11157
11158 Opt.Float_Format := 'I';
11159 end if;
11160
11161 Set_Standard_Fpt_Formats;
11162
11163 -- Two argument case
11164
11165 else
11166 Argx := Get_Pragma_Arg (Arg2);
11167
11168 if not Is_Entity_Name (Argx)
11169 or else not Is_Floating_Point_Type (Entity (Argx))
11170 then
11171 Error_Pragma_Arg
11172 ("second argument of% pragma must be floating-point type",
11173 Arg2);
11174 end if;
11175
11176 Ent := Entity (Argx);
11177 Digs := UI_To_Int (Digits_Value (Ent));
11178
11179 -- Two arguments, VAX_Float case
11180
11181 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
11182 case Digs is
11183 when 6 => Set_F_Float (Ent);
11184 when 9 => Set_D_Float (Ent);
11185 when 15 => Set_G_Float (Ent);
11186
11187 when others =>
11188 Error_Pragma_Arg
11189 ("wrong digits value, must be 6,9 or 15", Arg2);
11190 end case;
11191
11192 -- Two arguments, IEEE_Float case
11193
11194 else
11195 case Digs is
11196 when 6 => Set_IEEE_Short (Ent);
11197 when 15 => Set_IEEE_Long (Ent);
11198
11199 when others =>
11200 Error_Pragma_Arg
11201 ("wrong digits value, must be 6 or 15", Arg2);
11202 end case;
11203 end if;
11204 end if;
11205 end Float_Representation;
11206
11207 -----------
11208 -- Ghost --
11209 -----------
11210
11211 -- pragma GHOST (function_LOCAL_NAME);
11212
11213 when Pragma_Ghost => Ghost : declare
11214 Subp : Node_Id;
11215 Subp_Id : Entity_Id;
11216
11217 begin
11218 GNAT_Pragma;
11219 S14_Pragma;
11220 Check_Arg_Count (1);
11221 Check_Arg_Is_Local_Name (Arg1);
11222
11223 -- Ensure the proper placement of the pragma. Ghost must be
11224 -- associated with a subprogram declaration.
11225
11226 Subp := Parent (Corresponding_Aspect (N));
11227
11228 if Nkind (Subp) /= N_Subprogram_Declaration then
11229 Pragma_Misplaced;
11230 return;
11231 end if;
11232
11233 Subp_Id := Defining_Unit_Name (Specification (Subp));
11234
11235 if Ekind (Subp_Id) /= E_Function then
11236 Error_Pragma ("pragma % must be applied to a function");
11237 end if;
11238 end Ghost;
11239
11240 ------------
11241 -- Global --
11242 ------------
11243
11244 -- pragma Global (GLOBAL_SPECIFICATION)
11245
11246 -- GLOBAL_SPECIFICATION ::=
11247 -- null
11248 -- | GLOBAL_LIST
11249 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
11250
11251 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
11252
11253 -- MODE_SELECTOR ::= Input | Output | In_Out | Contract_In
11254 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
11255 -- GLOBAL_ITEM ::= NAME
11256
11257 when Pragma_Global => Global : declare
11258 Subp_Id : Entity_Id;
11259
11260 Seen : Elist_Id := No_Elist;
11261 -- A list containing the entities of all the items processed so
11262 -- far. It plays a role in detecting distinct entities.
11263
11264 Contract_Seen : Boolean := False;
11265 In_Out_Seen : Boolean := False;
11266 Input_Seen : Boolean := False;
11267 Output_Seen : Boolean := False;
11268 -- Flags used to verify the consistency of modes
11269
11270 procedure Analyze_Global_List
11271 (List : Node_Id;
11272 Global_Mode : Name_Id := Name_Input);
11273 -- Verify the legality of a single global list declaration.
11274 -- Global_Mode denotes the current mode in effect.
11275
11276 -------------------------
11277 -- Analyze_Global_List --
11278 -------------------------
11279
11280 procedure Analyze_Global_List
11281 (List : Node_Id;
11282 Global_Mode : Name_Id := Name_Input)
11283 is
11284 procedure Analyze_Global_Item
11285 (Item : Node_Id;
11286 Global_Mode : Name_Id);
11287 -- Verify the legality of a single global item declaration.
11288 -- Global_Mode denotes the current mode in effect.
11289
11290 procedure Check_Duplicate_Mode
11291 (Mode : Node_Id;
11292 Status : in out Boolean);
11293 -- Flag Status denotes whether a particular mode has been seen
11294 -- while processing a global list. This routine verifies that
11295 -- Mode is not a duplicate mode and sets the flag Status.
11296
11297 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
11298 -- Mode denotes either In_Out or Output. Depending on the kind
11299 -- of the related subprogram, emit an error if those two modes
11300 -- apply to a function.
11301
11302 -------------------------
11303 -- Analyze_Global_Item --
11304 -------------------------
11305
11306 procedure Analyze_Global_Item
11307 (Item : Node_Id;
11308 Global_Mode : Name_Id)
11309 is
11310 Item_Id : Entity_Id;
11311
11312 begin
11313 -- Detect one of the following cases
11314
11315 -- with Global => (null, Name)
11316 -- with Global => (Name_1, null, Name_2)
11317 -- with Global => (Name, null)
11318
11319 if Nkind (Item) = N_Null then
11320 Error_Msg_N
11321 ("cannot mix null and non-null global items", Item);
11322 return;
11323 end if;
11324
11325 Analyze (Item);
11326
11327 -- Find the entity of the item. If this is a renaming, climb
11328 -- the renaming chain to reach the root object. Renamings of
11329 -- non-entire objects do not yield an entity (Empty).
11330
11331 Item_Id := Entity_Of (Item);
11332
11333 if Present (Item_Id) then
11334
11335 -- A global item cannot reference a formal parameter. Do
11336 -- this check first to provide a better error diagnostic.
11337
11338 if Is_Formal (Item_Id) then
11339 Error_Msg_N
11340 ("global item cannot reference formal parameter",
11341 Item);
11342 return;
11343
11344 -- The only legal references are those to abstract states
11345 -- and variables.
11346
11347 elsif not Ekind_In (Item_Id, E_Abstract_State,
11348 E_Variable)
11349 then
11350 Error_Msg_N
11351 ("global item must denote variable or state", Item);
11352 return;
11353 end if;
11354
11355 -- When the item renames an entire object, replace the
11356 -- item with a reference to the object.
11357
11358 if Present (Renamed_Object (Entity (Item))) then
11359 Rewrite (Item,
11360 New_Reference_To (Item_Id, Sloc (Item)));
11361 Analyze (Item);
11362 end if;
11363
11364 -- Some form of illegal construct masquerading as a name
11365
11366 else
11367 Error_Msg_N
11368 ("global item must denote variable or state", Item);
11369 return;
11370 end if;
11371
11372 -- The same entity might be referenced through various way.
11373 -- Check the entity of the item rather than the item itself.
11374
11375 if Contains (Seen, Item_Id) then
11376 Error_Msg_N ("duplicate global item", Item);
11377
11378 -- Add the entity of the current item to the list of
11379 -- processed items.
11380
11381 else
11382 Add_Item (Item_Id, Seen);
11383 end if;
11384
11385 if Ekind (Item_Id) = E_Abstract_State
11386 and then Is_Volatile_State (Item_Id)
11387 then
11388 -- A global item of mode In_Out or Output cannot denote a
11389 -- volatile Input state.
11390
11391 if Is_Input_State (Item_Id)
11392 and then (Global_Mode = Name_In_Out
11393 or else
11394 Global_Mode = Name_Output)
11395 then
11396 Error_Msg_N
11397 ("global item of mode In_Out or Output cannot "
11398 & "reference Volatile Input state", Item);
11399
11400 -- A global item of mode In_Out or Input cannot reference
11401 -- a volatile Output state.
11402
11403 elsif Is_Output_State (Item_Id)
11404 and then (Global_Mode = Name_In_Out
11405 or else
11406 Global_Mode = Name_Input)
11407 then
11408 Error_Msg_N
11409 ("global item of mode In_Out or Input cannot "
11410 & "reference Volatile Output state", Item);
11411 end if;
11412 end if;
11413 end Analyze_Global_Item;
11414
11415 --------------------------
11416 -- Check_Duplicate_Mode --
11417 --------------------------
11418
11419 procedure Check_Duplicate_Mode
11420 (Mode : Node_Id;
11421 Status : in out Boolean)
11422 is
11423 begin
11424 if Status then
11425 Error_Msg_N ("duplicate global mode", Mode);
11426 end if;
11427
11428 Status := True;
11429 end Check_Duplicate_Mode;
11430
11431 ----------------------------------------
11432 -- Check_Mode_Restriction_In_Function --
11433 ----------------------------------------
11434
11435 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
11436 begin
11437 if Ekind (Subp_Id) = E_Function then
11438 Error_Msg_N
11439 ("global mode & not applicable to functions", Mode);
11440 end if;
11441 end Check_Mode_Restriction_In_Function;
11442
11443 -- Local variables
11444
11445 Assoc : Node_Id;
11446 Item : Node_Id;
11447 Mode : Node_Id;
11448
11449 -- Start of processing for Analyze_Global_List
11450
11451 begin
11452 -- Single global item declaration
11453
11454 if Nkind_In (List, N_Identifier, N_Selected_Component) then
11455 Analyze_Global_Item (List, Global_Mode);
11456
11457 -- Simple global list or moded global list declaration
11458
11459 elsif Nkind (List) = N_Aggregate then
11460
11461 -- The declaration of a simple global list appear as a
11462 -- collection of expressions.
11463
11464 if Present (Expressions (List)) then
11465 if Present (Component_Associations (List)) then
11466 Error_Msg_N
11467 ("cannot mix moded and non-moded global lists",
11468 List);
11469 end if;
11470
11471 Item := First (Expressions (List));
11472 while Present (Item) loop
11473 Analyze_Global_Item (Item, Global_Mode);
11474
11475 Next (Item);
11476 end loop;
11477
11478 -- The declaration of a moded global list appears as a
11479 -- collection of component associations where individual
11480 -- choices denote modes.
11481
11482 elsif Present (Component_Associations (List)) then
11483 if Present (Expressions (List)) then
11484 Error_Msg_N
11485 ("cannot mix moded and non-moded global lists",
11486 List);
11487 end if;
11488
11489 Assoc := First (Component_Associations (List));
11490 while Present (Assoc) loop
11491 Mode := First (Choices (Assoc));
11492
11493 if Nkind (Mode) = N_Identifier then
11494 if Chars (Mode) = Name_Contract_In then
11495 Check_Duplicate_Mode (Mode, Contract_Seen);
11496
11497 elsif Chars (Mode) = Name_In_Out then
11498 Check_Duplicate_Mode (Mode, In_Out_Seen);
11499 Check_Mode_Restriction_In_Function (Mode);
11500
11501 elsif Chars (Mode) = Name_Input then
11502 Check_Duplicate_Mode (Mode, Input_Seen);
11503
11504 elsif Chars (Mode) = Name_Output then
11505 Check_Duplicate_Mode (Mode, Output_Seen);
11506 Check_Mode_Restriction_In_Function (Mode);
11507
11508 else
11509 Error_Msg_N ("invalid mode selector", Mode);
11510 end if;
11511
11512 else
11513 Error_Msg_N ("invalid mode selector", Mode);
11514 end if;
11515
11516 -- Items in a moded list appear as a collection of
11517 -- expressions. Reuse the existing machinery to
11518 -- analyze them.
11519
11520 Analyze_Global_List
11521 (List => Expression (Assoc),
11522 Global_Mode => Chars (Mode));
11523
11524 Next (Assoc);
11525 end loop;
11526
11527 -- Something went horribly wrong, we have a malformed tree
11528
11529 else
11530 raise Program_Error;
11531 end if;
11532
11533 -- Any other attempt to declare a global item is erroneous
11534
11535 else
11536 Error_Msg_N ("malformed global list declaration", List);
11537 end if;
11538 end Analyze_Global_List;
11539
11540 -- Local variables
11541
11542 List : Node_Id;
11543 Subp : Node_Id;
11544
11545 -- Start of processing for Global
11546
11547 begin
11548 GNAT_Pragma;
11549 S14_Pragma;
11550 Check_Arg_Count (1);
11551
11552 -- Ensure the proper placement of the pragma. Global must be
11553 -- associated with a subprogram declaration.
11554
11555 Subp := Parent (Corresponding_Aspect (N));
11556
11557 if Nkind (Subp) /= N_Subprogram_Declaration then
11558 Pragma_Misplaced;
11559 return;
11560 end if;
11561
11562 Subp_Id := Defining_Unit_Name (Specification (Subp));
11563 List := Expression (Arg1);
11564
11565 -- There is nothing to be done for a null global list
11566
11567 if Nkind (List) = N_Null then
11568 null;
11569
11570 -- Analyze the various forms of global lists and items. Note that
11571 -- some of these may be malformed in which case the analysis emits
11572 -- error messages.
11573
11574 else
11575 -- Ensure that the formal parameters are visible when
11576 -- processing an item. This falls out of the general rule of
11577 -- aspects pertaining to subprogram declarations.
11578
11579 Push_Scope (Subp_Id);
11580 Install_Formals (Subp_Id);
11581
11582 Analyze_Global_List (List);
11583
11584 End_Scope;
11585 end if;
11586 end Global;
11587
11588 -----------
11589 -- Ident --
11590 -----------
11591
11592 -- pragma Ident (static_string_EXPRESSION)
11593
11594 -- Note: pragma Comment shares this processing. Pragma Comment is
11595 -- identical to Ident, except that the restriction of the argument to
11596 -- 31 characters and the placement restrictions are not enforced for
11597 -- pragma Comment.
11598
11599 when Pragma_Ident | Pragma_Comment => Ident : declare
11600 Str : Node_Id;
11601
11602 begin
11603 GNAT_Pragma;
11604 Check_Arg_Count (1);
11605 Check_No_Identifiers;
11606 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11607 Store_Note (N);
11608
11609 -- For pragma Ident, preserve DEC compatibility by requiring the
11610 -- pragma to appear in a declarative part or package spec.
11611
11612 if Prag_Id = Pragma_Ident then
11613 Check_Is_In_Decl_Part_Or_Package_Spec;
11614 end if;
11615
11616 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
11617
11618 declare
11619 CS : Node_Id;
11620 GP : Node_Id;
11621
11622 begin
11623 GP := Parent (Parent (N));
11624
11625 if Nkind_In (GP, N_Package_Declaration,
11626 N_Generic_Package_Declaration)
11627 then
11628 GP := Parent (GP);
11629 end if;
11630
11631 -- If we have a compilation unit, then record the ident value,
11632 -- checking for improper duplication.
11633
11634 if Nkind (GP) = N_Compilation_Unit then
11635 CS := Ident_String (Current_Sem_Unit);
11636
11637 if Present (CS) then
11638
11639 -- For Ident, we do not permit multiple instances
11640
11641 if Prag_Id = Pragma_Ident then
11642 Error_Pragma ("duplicate% pragma not permitted");
11643
11644 -- For Comment, we concatenate the string, unless we want
11645 -- to preserve the tree structure for ASIS.
11646
11647 elsif not ASIS_Mode then
11648 Start_String (Strval (CS));
11649 Store_String_Char (' ');
11650 Store_String_Chars (Strval (Str));
11651 Set_Strval (CS, End_String);
11652 end if;
11653
11654 else
11655 -- In VMS, the effect of IDENT is achieved by passing
11656 -- --identification=name as a --for-linker switch.
11657
11658 if OpenVMS_On_Target then
11659 Start_String;
11660 Store_String_Chars
11661 ("--for-linker=--identification=");
11662 String_To_Name_Buffer (Strval (Str));
11663 Store_String_Chars (Name_Buffer (1 .. Name_Len));
11664
11665 -- Only the last processed IDENT is saved. The main
11666 -- purpose is so an IDENT associated with a main
11667 -- procedure will be used in preference to an IDENT
11668 -- associated with a with'd package.
11669
11670 Replace_Linker_Option_String
11671 (End_String, "--for-linker=--identification=");
11672 end if;
11673
11674 Set_Ident_String (Current_Sem_Unit, Str);
11675 end if;
11676
11677 -- For subunits, we just ignore the Ident, since in GNAT these
11678 -- are not separate object files, and hence not separate units
11679 -- in the unit table.
11680
11681 elsif Nkind (GP) = N_Subunit then
11682 null;
11683
11684 -- Otherwise we have a misplaced pragma Ident, but we ignore
11685 -- this if we are in an instantiation, since it comes from
11686 -- a generic, and has no relevance to the instantiation.
11687
11688 elsif Prag_Id = Pragma_Ident then
11689 if Instantiation_Location (Loc) = No_Location then
11690 Error_Pragma ("pragma% only allowed at outer level");
11691 end if;
11692 end if;
11693 end;
11694 end Ident;
11695
11696 ----------------------------
11697 -- Implementation_Defined --
11698 ----------------------------
11699
11700 -- pragma Implementation_Defined (local_NAME);
11701
11702 -- Marks previously declared entity as implementation defined. For
11703 -- an overloaded entity, applies to the most recent homonym.
11704
11705 -- pragma Implementation_Defined;
11706
11707 -- The form with no arguments appears anywhere within a scope, most
11708 -- typically a package spec, and indicates that all entities that are
11709 -- defined within the package spec are Implementation_Defined.
11710
11711 when Pragma_Implementation_Defined => Implementation_Defined : declare
11712 Ent : Entity_Id;
11713
11714 begin
11715 Check_No_Identifiers;
11716
11717 -- Form with no arguments
11718
11719 if Arg_Count = 0 then
11720 Set_Is_Implementation_Defined (Current_Scope);
11721
11722 -- Form with one argument
11723
11724 else
11725 Check_Arg_Count (1);
11726 Check_Arg_Is_Local_Name (Arg1);
11727 Ent := Entity (Get_Pragma_Arg (Arg1));
11728 Set_Is_Implementation_Defined (Ent);
11729 end if;
11730 end Implementation_Defined;
11731
11732 -----------------
11733 -- Implemented --
11734 -----------------
11735
11736 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
11737
11738 -- IMPLEMENTATION_KIND ::=
11739 -- By_Entry | By_Protected_Procedure | By_Any | Optional
11740
11741 -- "By_Any" and "Optional" are treated as synonyms in order to
11742 -- support Ada 2012 aspect Synchronization.
11743
11744 when Pragma_Implemented => Implemented : declare
11745 Proc_Id : Entity_Id;
11746 Typ : Entity_Id;
11747
11748 begin
11749 Ada_2012_Pragma;
11750 Check_Arg_Count (2);
11751 Check_No_Identifiers;
11752 Check_Arg_Is_Identifier (Arg1);
11753 Check_Arg_Is_Local_Name (Arg1);
11754 Check_Arg_Is_One_Of (Arg2,
11755 Name_By_Any,
11756 Name_By_Entry,
11757 Name_By_Protected_Procedure,
11758 Name_Optional);
11759
11760 -- Extract the name of the local procedure
11761
11762 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
11763
11764 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
11765 -- primitive procedure of a synchronized tagged type.
11766
11767 if Ekind (Proc_Id) = E_Procedure
11768 and then Is_Primitive (Proc_Id)
11769 and then Present (First_Formal (Proc_Id))
11770 then
11771 Typ := Etype (First_Formal (Proc_Id));
11772
11773 if Is_Tagged_Type (Typ)
11774 and then
11775
11776 -- Check for a protected, a synchronized or a task interface
11777
11778 ((Is_Interface (Typ)
11779 and then Is_Synchronized_Interface (Typ))
11780
11781 -- Check for a protected type or a task type that implements
11782 -- an interface.
11783
11784 or else
11785 (Is_Concurrent_Record_Type (Typ)
11786 and then Present (Interfaces (Typ)))
11787
11788 -- Check for a private record extension with keyword
11789 -- "synchronized".
11790
11791 or else
11792 (Ekind_In (Typ, E_Record_Type_With_Private,
11793 E_Record_Subtype_With_Private)
11794 and then Synchronized_Present (Parent (Typ))))
11795 then
11796 null;
11797 else
11798 Error_Pragma_Arg
11799 ("controlling formal must be of synchronized tagged type",
11800 Arg1);
11801 return;
11802 end if;
11803
11804 -- Procedures declared inside a protected type must be accepted
11805
11806 elsif Ekind (Proc_Id) = E_Procedure
11807 and then Is_Protected_Type (Scope (Proc_Id))
11808 then
11809 null;
11810
11811 -- The first argument is not a primitive procedure
11812
11813 else
11814 Error_Pragma_Arg
11815 ("pragma % must be applied to a primitive procedure", Arg1);
11816 return;
11817 end if;
11818
11819 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
11820 -- By_Protected_Procedure to the primitive procedure of a task
11821 -- interface.
11822
11823 if Chars (Arg2) = Name_By_Protected_Procedure
11824 and then Is_Interface (Typ)
11825 and then Is_Task_Interface (Typ)
11826 then
11827 Error_Pragma_Arg
11828 ("implementation kind By_Protected_Procedure cannot be "
11829 & "applied to a task interface primitive", Arg2);
11830 return;
11831 end if;
11832
11833 Record_Rep_Item (Proc_Id, N);
11834 end Implemented;
11835
11836 ----------------------
11837 -- Implicit_Packing --
11838 ----------------------
11839
11840 -- pragma Implicit_Packing;
11841
11842 when Pragma_Implicit_Packing =>
11843 GNAT_Pragma;
11844 Check_Arg_Count (0);
11845 Implicit_Packing := True;
11846
11847 ------------
11848 -- Import --
11849 ------------
11850
11851 -- pragma Import (
11852 -- [Convention =>] convention_IDENTIFIER,
11853 -- [Entity =>] local_NAME
11854 -- [, [External_Name =>] static_string_EXPRESSION ]
11855 -- [, [Link_Name =>] static_string_EXPRESSION ]);
11856
11857 when Pragma_Import =>
11858 Check_Ada_83_Warning;
11859 Check_Arg_Order
11860 ((Name_Convention,
11861 Name_Entity,
11862 Name_External_Name,
11863 Name_Link_Name));
11864
11865 Check_At_Least_N_Arguments (2);
11866 Check_At_Most_N_Arguments (4);
11867 Process_Import_Or_Interface;
11868
11869 ----------------------
11870 -- Import_Exception --
11871 ----------------------
11872
11873 -- pragma Import_Exception (
11874 -- [Internal =>] LOCAL_NAME
11875 -- [, [External =>] EXTERNAL_SYMBOL]
11876 -- [, [Form =>] Ada | VMS]
11877 -- [, [Code =>] static_integer_EXPRESSION]);
11878
11879 when Pragma_Import_Exception => Import_Exception : declare
11880 Args : Args_List (1 .. 4);
11881 Names : constant Name_List (1 .. 4) := (
11882 Name_Internal,
11883 Name_External,
11884 Name_Form,
11885 Name_Code);
11886
11887 Internal : Node_Id renames Args (1);
11888 External : Node_Id renames Args (2);
11889 Form : Node_Id renames Args (3);
11890 Code : Node_Id renames Args (4);
11891
11892 begin
11893 GNAT_Pragma;
11894 Gather_Associations (Names, Args);
11895
11896 if Present (External) and then Present (Code) then
11897 Error_Pragma
11898 ("cannot give both External and Code options for pragma%");
11899 end if;
11900
11901 Process_Extended_Import_Export_Exception_Pragma (
11902 Arg_Internal => Internal,
11903 Arg_External => External,
11904 Arg_Form => Form,
11905 Arg_Code => Code);
11906
11907 if not Is_VMS_Exception (Entity (Internal)) then
11908 Set_Imported (Entity (Internal));
11909 end if;
11910 end Import_Exception;
11911
11912 ---------------------
11913 -- Import_Function --
11914 ---------------------
11915
11916 -- pragma Import_Function (
11917 -- [Internal =>] LOCAL_NAME,
11918 -- [, [External =>] EXTERNAL_SYMBOL]
11919 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
11920 -- [, [Result_Type =>] SUBTYPE_MARK]
11921 -- [, [Mechanism =>] MECHANISM]
11922 -- [, [Result_Mechanism =>] MECHANISM_NAME]
11923 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
11924
11925 -- EXTERNAL_SYMBOL ::=
11926 -- IDENTIFIER
11927 -- | static_string_EXPRESSION
11928
11929 -- PARAMETER_TYPES ::=
11930 -- null
11931 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
11932
11933 -- TYPE_DESIGNATOR ::=
11934 -- subtype_NAME
11935 -- | subtype_Name ' Access
11936
11937 -- MECHANISM ::=
11938 -- MECHANISM_NAME
11939 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
11940
11941 -- MECHANISM_ASSOCIATION ::=
11942 -- [formal_parameter_NAME =>] MECHANISM_NAME
11943
11944 -- MECHANISM_NAME ::=
11945 -- Value
11946 -- | Reference
11947 -- | Descriptor [([Class =>] CLASS_NAME)]
11948
11949 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
11950
11951 when Pragma_Import_Function => Import_Function : declare
11952 Args : Args_List (1 .. 7);
11953 Names : constant Name_List (1 .. 7) := (
11954 Name_Internal,
11955 Name_External,
11956 Name_Parameter_Types,
11957 Name_Result_Type,
11958 Name_Mechanism,
11959 Name_Result_Mechanism,
11960 Name_First_Optional_Parameter);
11961
11962 Internal : Node_Id renames Args (1);
11963 External : Node_Id renames Args (2);
11964 Parameter_Types : Node_Id renames Args (3);
11965 Result_Type : Node_Id renames Args (4);
11966 Mechanism : Node_Id renames Args (5);
11967 Result_Mechanism : Node_Id renames Args (6);
11968 First_Optional_Parameter : Node_Id renames Args (7);
11969
11970 begin
11971 GNAT_Pragma;
11972 Gather_Associations (Names, Args);
11973 Process_Extended_Import_Export_Subprogram_Pragma (
11974 Arg_Internal => Internal,
11975 Arg_External => External,
11976 Arg_Parameter_Types => Parameter_Types,
11977 Arg_Result_Type => Result_Type,
11978 Arg_Mechanism => Mechanism,
11979 Arg_Result_Mechanism => Result_Mechanism,
11980 Arg_First_Optional_Parameter => First_Optional_Parameter);
11981 end Import_Function;
11982
11983 -------------------
11984 -- Import_Object --
11985 -------------------
11986
11987 -- pragma Import_Object (
11988 -- [Internal =>] LOCAL_NAME
11989 -- [, [External =>] EXTERNAL_SYMBOL]
11990 -- [, [Size =>] EXTERNAL_SYMBOL]);
11991
11992 -- EXTERNAL_SYMBOL ::=
11993 -- IDENTIFIER
11994 -- | static_string_EXPRESSION
11995
11996 when Pragma_Import_Object => Import_Object : declare
11997 Args : Args_List (1 .. 3);
11998 Names : constant Name_List (1 .. 3) := (
11999 Name_Internal,
12000 Name_External,
12001 Name_Size);
12002
12003 Internal : Node_Id renames Args (1);
12004 External : Node_Id renames Args (2);
12005 Size : Node_Id renames Args (3);
12006
12007 begin
12008 GNAT_Pragma;
12009 Gather_Associations (Names, Args);
12010 Process_Extended_Import_Export_Object_Pragma (
12011 Arg_Internal => Internal,
12012 Arg_External => External,
12013 Arg_Size => Size);
12014 end Import_Object;
12015
12016 ----------------------
12017 -- Import_Procedure --
12018 ----------------------
12019
12020 -- pragma Import_Procedure (
12021 -- [Internal =>] LOCAL_NAME
12022 -- [, [External =>] EXTERNAL_SYMBOL]
12023 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
12024 -- [, [Mechanism =>] MECHANISM]
12025 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
12026
12027 -- EXTERNAL_SYMBOL ::=
12028 -- IDENTIFIER
12029 -- | static_string_EXPRESSION
12030
12031 -- PARAMETER_TYPES ::=
12032 -- null
12033 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
12034
12035 -- TYPE_DESIGNATOR ::=
12036 -- subtype_NAME
12037 -- | subtype_Name ' Access
12038
12039 -- MECHANISM ::=
12040 -- MECHANISM_NAME
12041 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
12042
12043 -- MECHANISM_ASSOCIATION ::=
12044 -- [formal_parameter_NAME =>] MECHANISM_NAME
12045
12046 -- MECHANISM_NAME ::=
12047 -- Value
12048 -- | Reference
12049 -- | Descriptor [([Class =>] CLASS_NAME)]
12050
12051 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12052
12053 when Pragma_Import_Procedure => Import_Procedure : declare
12054 Args : Args_List (1 .. 5);
12055 Names : constant Name_List (1 .. 5) := (
12056 Name_Internal,
12057 Name_External,
12058 Name_Parameter_Types,
12059 Name_Mechanism,
12060 Name_First_Optional_Parameter);
12061
12062 Internal : Node_Id renames Args (1);
12063 External : Node_Id renames Args (2);
12064 Parameter_Types : Node_Id renames Args (3);
12065 Mechanism : Node_Id renames Args (4);
12066 First_Optional_Parameter : Node_Id renames Args (5);
12067
12068 begin
12069 GNAT_Pragma;
12070 Gather_Associations (Names, Args);
12071 Process_Extended_Import_Export_Subprogram_Pragma (
12072 Arg_Internal => Internal,
12073 Arg_External => External,
12074 Arg_Parameter_Types => Parameter_Types,
12075 Arg_Mechanism => Mechanism,
12076 Arg_First_Optional_Parameter => First_Optional_Parameter);
12077 end Import_Procedure;
12078
12079 -----------------------------
12080 -- Import_Valued_Procedure --
12081 -----------------------------
12082
12083 -- pragma Import_Valued_Procedure (
12084 -- [Internal =>] LOCAL_NAME
12085 -- [, [External =>] EXTERNAL_SYMBOL]
12086 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
12087 -- [, [Mechanism =>] MECHANISM]
12088 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
12089
12090 -- EXTERNAL_SYMBOL ::=
12091 -- IDENTIFIER
12092 -- | static_string_EXPRESSION
12093
12094 -- PARAMETER_TYPES ::=
12095 -- null
12096 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
12097
12098 -- TYPE_DESIGNATOR ::=
12099 -- subtype_NAME
12100 -- | subtype_Name ' Access
12101
12102 -- MECHANISM ::=
12103 -- MECHANISM_NAME
12104 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
12105
12106 -- MECHANISM_ASSOCIATION ::=
12107 -- [formal_parameter_NAME =>] MECHANISM_NAME
12108
12109 -- MECHANISM_NAME ::=
12110 -- Value
12111 -- | Reference
12112 -- | Descriptor [([Class =>] CLASS_NAME)]
12113
12114 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12115
12116 when Pragma_Import_Valued_Procedure =>
12117 Import_Valued_Procedure : declare
12118 Args : Args_List (1 .. 5);
12119 Names : constant Name_List (1 .. 5) := (
12120 Name_Internal,
12121 Name_External,
12122 Name_Parameter_Types,
12123 Name_Mechanism,
12124 Name_First_Optional_Parameter);
12125
12126 Internal : Node_Id renames Args (1);
12127 External : Node_Id renames Args (2);
12128 Parameter_Types : Node_Id renames Args (3);
12129 Mechanism : Node_Id renames Args (4);
12130 First_Optional_Parameter : Node_Id renames Args (5);
12131
12132 begin
12133 GNAT_Pragma;
12134 Gather_Associations (Names, Args);
12135 Process_Extended_Import_Export_Subprogram_Pragma (
12136 Arg_Internal => Internal,
12137 Arg_External => External,
12138 Arg_Parameter_Types => Parameter_Types,
12139 Arg_Mechanism => Mechanism,
12140 Arg_First_Optional_Parameter => First_Optional_Parameter);
12141 end Import_Valued_Procedure;
12142
12143 -----------------
12144 -- Independent --
12145 -----------------
12146
12147 -- pragma Independent (LOCAL_NAME);
12148
12149 when Pragma_Independent => Independent : declare
12150 E_Id : Node_Id;
12151 E : Entity_Id;
12152 D : Node_Id;
12153 K : Node_Kind;
12154
12155 begin
12156 Check_Ada_83_Warning;
12157 Ada_2012_Pragma;
12158 Check_No_Identifiers;
12159 Check_Arg_Count (1);
12160 Check_Arg_Is_Local_Name (Arg1);
12161 E_Id := Get_Pragma_Arg (Arg1);
12162
12163 if Etype (E_Id) = Any_Type then
12164 return;
12165 end if;
12166
12167 E := Entity (E_Id);
12168 D := Declaration_Node (E);
12169 K := Nkind (D);
12170
12171 -- Check duplicate before we chain ourselves!
12172
12173 Check_Duplicate_Pragma (E);
12174
12175 -- Check appropriate entity
12176
12177 if Is_Type (E) then
12178 if Rep_Item_Too_Early (E, N)
12179 or else
12180 Rep_Item_Too_Late (E, N)
12181 then
12182 return;
12183 else
12184 Check_First_Subtype (Arg1);
12185 end if;
12186
12187 elsif K = N_Object_Declaration
12188 or else (K = N_Component_Declaration
12189 and then Original_Record_Component (E) = E)
12190 then
12191 if Rep_Item_Too_Late (E, N) then
12192 return;
12193 end if;
12194
12195 else
12196 Error_Pragma_Arg
12197 ("inappropriate entity for pragma%", Arg1);
12198 end if;
12199
12200 Independence_Checks.Append ((N, E));
12201 end Independent;
12202
12203 ----------------------------
12204 -- Independent_Components --
12205 ----------------------------
12206
12207 -- pragma Atomic_Components (array_LOCAL_NAME);
12208
12209 -- This processing is shared by Volatile_Components
12210
12211 when Pragma_Independent_Components => Independent_Components : declare
12212 E_Id : Node_Id;
12213 E : Entity_Id;
12214 D : Node_Id;
12215 K : Node_Kind;
12216
12217 begin
12218 Check_Ada_83_Warning;
12219 Ada_2012_Pragma;
12220 Check_No_Identifiers;
12221 Check_Arg_Count (1);
12222 Check_Arg_Is_Local_Name (Arg1);
12223 E_Id := Get_Pragma_Arg (Arg1);
12224
12225 if Etype (E_Id) = Any_Type then
12226 return;
12227 end if;
12228
12229 E := Entity (E_Id);
12230
12231 -- Check duplicate before we chain ourselves!
12232
12233 Check_Duplicate_Pragma (E);
12234
12235 -- Check appropriate entity
12236
12237 if Rep_Item_Too_Early (E, N)
12238 or else
12239 Rep_Item_Too_Late (E, N)
12240 then
12241 return;
12242 end if;
12243
12244 D := Declaration_Node (E);
12245 K := Nkind (D);
12246
12247 if K = N_Full_Type_Declaration
12248 and then (Is_Array_Type (E) or else Is_Record_Type (E))
12249 then
12250 Independence_Checks.Append ((N, E));
12251 Set_Has_Independent_Components (Base_Type (E));
12252
12253 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
12254 and then Nkind (D) = N_Object_Declaration
12255 and then Nkind (Object_Definition (D)) =
12256 N_Constrained_Array_Definition
12257 then
12258 Independence_Checks.Append ((N, E));
12259 Set_Has_Independent_Components (E);
12260
12261 else
12262 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
12263 end if;
12264 end Independent_Components;
12265
12266 ------------------------
12267 -- Initialize_Scalars --
12268 ------------------------
12269
12270 -- pragma Initialize_Scalars;
12271
12272 when Pragma_Initialize_Scalars =>
12273 GNAT_Pragma;
12274 Check_Arg_Count (0);
12275 Check_Valid_Configuration_Pragma;
12276 Check_Restriction (No_Initialize_Scalars, N);
12277
12278 -- Initialize_Scalars creates false positives in CodePeer, and
12279 -- incorrect negative results in Alfa mode, so ignore this pragma
12280 -- in these modes.
12281
12282 if not Restriction_Active (No_Initialize_Scalars)
12283 and then not (CodePeer_Mode or Alfa_Mode)
12284 then
12285 Init_Or_Norm_Scalars := True;
12286 Initialize_Scalars := True;
12287 end if;
12288
12289 ------------
12290 -- Inline --
12291 ------------
12292
12293 -- pragma Inline ( NAME {, NAME} );
12294
12295 when Pragma_Inline =>
12296
12297 -- Inline status is Enabled if inlining option is active
12298
12299 if Inline_Active then
12300 Process_Inline (Enabled);
12301 else
12302 Process_Inline (Disabled);
12303 end if;
12304
12305 -------------------
12306 -- Inline_Always --
12307 -------------------
12308
12309 -- pragma Inline_Always ( NAME {, NAME} );
12310
12311 when Pragma_Inline_Always =>
12312 GNAT_Pragma;
12313
12314 -- Pragma always active unless in CodePeer or Alfa mode, since
12315 -- this causes walk order issues.
12316
12317 if not (CodePeer_Mode or Alfa_Mode) then
12318 Process_Inline (Enabled);
12319 end if;
12320
12321 --------------------
12322 -- Inline_Generic --
12323 --------------------
12324
12325 -- pragma Inline_Generic (NAME {, NAME});
12326
12327 when Pragma_Inline_Generic =>
12328 GNAT_Pragma;
12329 Process_Generic_List;
12330
12331 ----------------------
12332 -- Inspection_Point --
12333 ----------------------
12334
12335 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
12336
12337 when Pragma_Inspection_Point => Inspection_Point : declare
12338 Arg : Node_Id;
12339 Exp : Node_Id;
12340
12341 begin
12342 if Arg_Count > 0 then
12343 Arg := Arg1;
12344 loop
12345 Exp := Get_Pragma_Arg (Arg);
12346 Analyze (Exp);
12347
12348 if not Is_Entity_Name (Exp)
12349 or else not Is_Object (Entity (Exp))
12350 then
12351 Error_Pragma_Arg ("object name required", Arg);
12352 end if;
12353
12354 Next (Arg);
12355 exit when No (Arg);
12356 end loop;
12357 end if;
12358 end Inspection_Point;
12359
12360 ---------------
12361 -- Interface --
12362 ---------------
12363
12364 -- pragma Interface (
12365 -- [ Convention =>] convention_IDENTIFIER,
12366 -- [ Entity =>] local_NAME
12367 -- [, [External_Name =>] static_string_EXPRESSION ]
12368 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12369
12370 when Pragma_Interface =>
12371 GNAT_Pragma;
12372 Check_Arg_Order
12373 ((Name_Convention,
12374 Name_Entity,
12375 Name_External_Name,
12376 Name_Link_Name));
12377 Check_At_Least_N_Arguments (2);
12378 Check_At_Most_N_Arguments (4);
12379 Process_Import_Or_Interface;
12380
12381 -- In Ada 2005, the permission to use Interface (a reserved word)
12382 -- as a pragma name is considered an obsolescent feature, and this
12383 -- pragma was already obsolescent in Ada 95.
12384
12385 if Ada_Version >= Ada_95 then
12386 Check_Restriction
12387 (No_Obsolescent_Features, Pragma_Identifier (N));
12388
12389 if Warn_On_Obsolescent_Feature then
12390 Error_Msg_N
12391 ("pragma Interface is an obsolescent feature?j?", N);
12392 Error_Msg_N
12393 ("|use pragma Import instead?j?", N);
12394 end if;
12395 end if;
12396
12397 --------------------
12398 -- Interface_Name --
12399 --------------------
12400
12401 -- pragma Interface_Name (
12402 -- [ Entity =>] local_NAME
12403 -- [,[External_Name =>] static_string_EXPRESSION ]
12404 -- [,[Link_Name =>] static_string_EXPRESSION ]);
12405
12406 when Pragma_Interface_Name => Interface_Name : declare
12407 Id : Node_Id;
12408 Def_Id : Entity_Id;
12409 Hom_Id : Entity_Id;
12410 Found : Boolean;
12411
12412 begin
12413 GNAT_Pragma;
12414 Check_Arg_Order
12415 ((Name_Entity, Name_External_Name, Name_Link_Name));
12416 Check_At_Least_N_Arguments (2);
12417 Check_At_Most_N_Arguments (3);
12418 Id := Get_Pragma_Arg (Arg1);
12419 Analyze (Id);
12420
12421 -- This is obsolete from Ada 95 on, but it is an implementation
12422 -- defined pragma, so we do not consider that it violates the
12423 -- restriction (No_Obsolescent_Features).
12424
12425 if Ada_Version >= Ada_95 then
12426 if Warn_On_Obsolescent_Feature then
12427 Error_Msg_N
12428 ("pragma Interface_Name is an obsolescent feature?j?", N);
12429 Error_Msg_N
12430 ("|use pragma Import instead?j?", N);
12431 end if;
12432 end if;
12433
12434 if not Is_Entity_Name (Id) then
12435 Error_Pragma_Arg
12436 ("first argument for pragma% must be entity name", Arg1);
12437 elsif Etype (Id) = Any_Type then
12438 return;
12439 else
12440 Def_Id := Entity (Id);
12441 end if;
12442
12443 -- Special DEC-compatible processing for the object case, forces
12444 -- object to be imported.
12445
12446 if Ekind (Def_Id) = E_Variable then
12447 Kill_Size_Check_Code (Def_Id);
12448 Note_Possible_Modification (Id, Sure => False);
12449
12450 -- Initialization is not allowed for imported variable
12451
12452 if Present (Expression (Parent (Def_Id)))
12453 and then Comes_From_Source (Expression (Parent (Def_Id)))
12454 then
12455 Error_Msg_Sloc := Sloc (Def_Id);
12456 Error_Pragma_Arg
12457 ("no initialization allowed for declaration of& #",
12458 Arg2);
12459
12460 else
12461 -- For compatibility, support VADS usage of providing both
12462 -- pragmas Interface and Interface_Name to obtain the effect
12463 -- of a single Import pragma.
12464
12465 if Is_Imported (Def_Id)
12466 and then Present (First_Rep_Item (Def_Id))
12467 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
12468 and then
12469 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
12470 then
12471 null;
12472 else
12473 Set_Imported (Def_Id);
12474 end if;
12475
12476 Set_Is_Public (Def_Id);
12477 Process_Interface_Name (Def_Id, Arg2, Arg3);
12478 end if;
12479
12480 -- Otherwise must be subprogram
12481
12482 elsif not Is_Subprogram (Def_Id) then
12483 Error_Pragma_Arg
12484 ("argument of pragma% is not subprogram", Arg1);
12485
12486 else
12487 Check_At_Most_N_Arguments (3);
12488 Hom_Id := Def_Id;
12489 Found := False;
12490
12491 -- Loop through homonyms
12492
12493 loop
12494 Def_Id := Get_Base_Subprogram (Hom_Id);
12495
12496 if Is_Imported (Def_Id) then
12497 Process_Interface_Name (Def_Id, Arg2, Arg3);
12498 Found := True;
12499 end if;
12500
12501 exit when From_Aspect_Specification (N);
12502 Hom_Id := Homonym (Hom_Id);
12503
12504 exit when No (Hom_Id)
12505 or else Scope (Hom_Id) /= Current_Scope;
12506 end loop;
12507
12508 if not Found then
12509 Error_Pragma_Arg
12510 ("argument of pragma% is not imported subprogram",
12511 Arg1);
12512 end if;
12513 end if;
12514 end Interface_Name;
12515
12516 -----------------------
12517 -- Interrupt_Handler --
12518 -----------------------
12519
12520 -- pragma Interrupt_Handler (handler_NAME);
12521
12522 when Pragma_Interrupt_Handler =>
12523 Check_Ada_83_Warning;
12524 Check_Arg_Count (1);
12525 Check_No_Identifiers;
12526
12527 if No_Run_Time_Mode then
12528 Error_Msg_CRT ("Interrupt_Handler pragma", N);
12529 else
12530 Check_Interrupt_Or_Attach_Handler;
12531 Process_Interrupt_Or_Attach_Handler;
12532 end if;
12533
12534 ------------------------
12535 -- Interrupt_Priority --
12536 ------------------------
12537
12538 -- pragma Interrupt_Priority [(EXPRESSION)];
12539
12540 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
12541 P : constant Node_Id := Parent (N);
12542 Arg : Node_Id;
12543 Ent : Entity_Id;
12544
12545 begin
12546 Check_Ada_83_Warning;
12547
12548 if Arg_Count /= 0 then
12549 Arg := Get_Pragma_Arg (Arg1);
12550 Check_Arg_Count (1);
12551 Check_No_Identifiers;
12552
12553 -- The expression must be analyzed in the special manner
12554 -- described in "Handling of Default and Per-Object
12555 -- Expressions" in sem.ads.
12556
12557 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
12558 end if;
12559
12560 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
12561 Pragma_Misplaced;
12562 return;
12563
12564 else
12565 Ent := Defining_Identifier (Parent (P));
12566
12567 -- Check duplicate pragma before we chain the pragma in the Rep
12568 -- Item chain of Ent.
12569
12570 Check_Duplicate_Pragma (Ent);
12571 Record_Rep_Item (Ent, N);
12572 end if;
12573 end Interrupt_Priority;
12574
12575 ---------------------
12576 -- Interrupt_State --
12577 ---------------------
12578
12579 -- pragma Interrupt_State (
12580 -- [Name =>] INTERRUPT_ID,
12581 -- [State =>] INTERRUPT_STATE);
12582
12583 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
12584 -- INTERRUPT_STATE => System | Runtime | User
12585
12586 -- Note: if the interrupt id is given as an identifier, then it must
12587 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
12588 -- given as a static integer expression which must be in the range of
12589 -- Ada.Interrupts.Interrupt_ID.
12590
12591 when Pragma_Interrupt_State => Interrupt_State : declare
12592
12593 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
12594 -- This is the entity Ada.Interrupts.Interrupt_ID;
12595
12596 State_Type : Character;
12597 -- Set to 's'/'r'/'u' for System/Runtime/User
12598
12599 IST_Num : Pos;
12600 -- Index to entry in Interrupt_States table
12601
12602 Int_Val : Uint;
12603 -- Value of interrupt
12604
12605 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
12606 -- The first argument to the pragma
12607
12608 Int_Ent : Entity_Id;
12609 -- Interrupt entity in Ada.Interrupts.Names
12610
12611 begin
12612 GNAT_Pragma;
12613 Check_Arg_Order ((Name_Name, Name_State));
12614 Check_Arg_Count (2);
12615
12616 Check_Optional_Identifier (Arg1, Name_Name);
12617 Check_Optional_Identifier (Arg2, Name_State);
12618 Check_Arg_Is_Identifier (Arg2);
12619
12620 -- First argument is identifier
12621
12622 if Nkind (Arg1X) = N_Identifier then
12623
12624 -- Search list of names in Ada.Interrupts.Names
12625
12626 Int_Ent := First_Entity (RTE (RE_Names));
12627 loop
12628 if No (Int_Ent) then
12629 Error_Pragma_Arg ("invalid interrupt name", Arg1);
12630
12631 elsif Chars (Int_Ent) = Chars (Arg1X) then
12632 Int_Val := Expr_Value (Constant_Value (Int_Ent));
12633 exit;
12634 end if;
12635
12636 Next_Entity (Int_Ent);
12637 end loop;
12638
12639 -- First argument is not an identifier, so it must be a static
12640 -- expression of type Ada.Interrupts.Interrupt_ID.
12641
12642 else
12643 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
12644 Int_Val := Expr_Value (Arg1X);
12645
12646 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
12647 or else
12648 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
12649 then
12650 Error_Pragma_Arg
12651 ("value not in range of type "
12652 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
12653 end if;
12654 end if;
12655
12656 -- Check OK state
12657
12658 case Chars (Get_Pragma_Arg (Arg2)) is
12659 when Name_Runtime => State_Type := 'r';
12660 when Name_System => State_Type := 's';
12661 when Name_User => State_Type := 'u';
12662
12663 when others =>
12664 Error_Pragma_Arg ("invalid interrupt state", Arg2);
12665 end case;
12666
12667 -- Check if entry is already stored
12668
12669 IST_Num := Interrupt_States.First;
12670 loop
12671 -- If entry not found, add it
12672
12673 if IST_Num > Interrupt_States.Last then
12674 Interrupt_States.Append
12675 ((Interrupt_Number => UI_To_Int (Int_Val),
12676 Interrupt_State => State_Type,
12677 Pragma_Loc => Loc));
12678 exit;
12679
12680 -- Case of entry for the same entry
12681
12682 elsif Int_Val = Interrupt_States.Table (IST_Num).
12683 Interrupt_Number
12684 then
12685 -- If state matches, done, no need to make redundant entry
12686
12687 exit when
12688 State_Type = Interrupt_States.Table (IST_Num).
12689 Interrupt_State;
12690
12691 -- Otherwise if state does not match, error
12692
12693 Error_Msg_Sloc :=
12694 Interrupt_States.Table (IST_Num).Pragma_Loc;
12695 Error_Pragma_Arg
12696 ("state conflicts with that given #", Arg2);
12697 exit;
12698 end if;
12699
12700 IST_Num := IST_Num + 1;
12701 end loop;
12702 end Interrupt_State;
12703
12704 ---------------
12705 -- Invariant --
12706 ---------------
12707
12708 -- pragma Invariant
12709 -- ([Entity =>] type_LOCAL_NAME,
12710 -- [Check =>] EXPRESSION
12711 -- [,[Message =>] String_Expression]);
12712
12713 when Pragma_Invariant => Invariant : declare
12714 Type_Id : Node_Id;
12715 Typ : Entity_Id;
12716 PDecl : Node_Id;
12717
12718 Discard : Boolean;
12719 pragma Unreferenced (Discard);
12720
12721 begin
12722 GNAT_Pragma;
12723 Check_At_Least_N_Arguments (2);
12724 Check_At_Most_N_Arguments (3);
12725 Check_Optional_Identifier (Arg1, Name_Entity);
12726 Check_Optional_Identifier (Arg2, Name_Check);
12727
12728 if Arg_Count = 3 then
12729 Check_Optional_Identifier (Arg3, Name_Message);
12730 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
12731 end if;
12732
12733 Check_Arg_Is_Local_Name (Arg1);
12734
12735 Type_Id := Get_Pragma_Arg (Arg1);
12736 Find_Type (Type_Id);
12737 Typ := Entity (Type_Id);
12738
12739 if Typ = Any_Type then
12740 return;
12741
12742 -- An invariant must apply to a private type, or appear in the
12743 -- private part of a package spec and apply to a completion.
12744
12745 elsif Ekind_In (Typ, E_Private_Type,
12746 E_Record_Type_With_Private,
12747 E_Limited_Private_Type)
12748 then
12749 null;
12750
12751 elsif In_Private_Part (Current_Scope)
12752 and then Has_Private_Declaration (Typ)
12753 then
12754 null;
12755
12756 elsif In_Private_Part (Current_Scope) then
12757 Error_Pragma_Arg
12758 ("pragma% only allowed for private type declared in "
12759 & "visible part", Arg1);
12760
12761 else
12762 Error_Pragma_Arg
12763 ("pragma% only allowed for private type", Arg1);
12764 end if;
12765
12766 -- Note that the type has at least one invariant, and also that
12767 -- it has inheritable invariants if we have Invariant'Class.
12768 -- Build the corresponding invariant procedure declaration, so
12769 -- that calls to it can be generated before the body is built
12770 -- (for example wihin an expression function).
12771
12772 PDecl := Build_Invariant_Procedure_Declaration (Typ);
12773 Insert_After (N, PDecl);
12774 Analyze (PDecl);
12775
12776 if Class_Present (N) then
12777 Set_Has_Inheritable_Invariants (Typ);
12778 end if;
12779
12780 -- The remaining processing is simply to link the pragma on to
12781 -- the rep item chain, for processing when the type is frozen.
12782 -- This is accomplished by a call to Rep_Item_Too_Late.
12783
12784 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12785 end Invariant;
12786
12787 ----------------------
12788 -- Java_Constructor --
12789 ----------------------
12790
12791 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
12792
12793 -- Also handles pragma CIL_Constructor
12794
12795 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
12796 Java_Constructor : declare
12797 Convention : Convention_Id;
12798 Def_Id : Entity_Id;
12799 Hom_Id : Entity_Id;
12800 Id : Entity_Id;
12801 This_Formal : Entity_Id;
12802
12803 begin
12804 GNAT_Pragma;
12805 Check_Arg_Count (1);
12806 Check_Optional_Identifier (Arg1, Name_Entity);
12807 Check_Arg_Is_Local_Name (Arg1);
12808
12809 Id := Get_Pragma_Arg (Arg1);
12810 Find_Program_Unit_Name (Id);
12811
12812 -- If we did not find the name, we are done
12813
12814 if Etype (Id) = Any_Type then
12815 return;
12816 end if;
12817
12818 -- Check wrong use of pragma in wrong VM target
12819
12820 if VM_Target = No_VM then
12821 return;
12822
12823 elsif VM_Target = CLI_Target
12824 and then Prag_Id = Pragma_Java_Constructor
12825 then
12826 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
12827
12828 elsif VM_Target = JVM_Target
12829 and then Prag_Id = Pragma_CIL_Constructor
12830 then
12831 Error_Pragma ("must use pragma 'Java_'Constructor");
12832 end if;
12833
12834 case Prag_Id is
12835 when Pragma_CIL_Constructor => Convention := Convention_CIL;
12836 when Pragma_Java_Constructor => Convention := Convention_Java;
12837 when others => null;
12838 end case;
12839
12840 Hom_Id := Entity (Id);
12841
12842 -- Loop through homonyms
12843
12844 loop
12845 Def_Id := Get_Base_Subprogram (Hom_Id);
12846
12847 -- The constructor is required to be a function
12848
12849 if Ekind (Def_Id) /= E_Function then
12850 if VM_Target = JVM_Target then
12851 Error_Pragma_Arg
12852 ("pragma% requires function returning a 'Java access "
12853 & "type", Def_Id);
12854 else
12855 Error_Pragma_Arg
12856 ("pragma% requires function returning a 'C'I'L access "
12857 & "type", Def_Id);
12858 end if;
12859 end if;
12860
12861 -- Check arguments: For tagged type the first formal must be
12862 -- named "this" and its type must be a named access type
12863 -- designating a class-wide tagged type that has convention
12864 -- CIL/Java. The first formal must also have a null default
12865 -- value. For example:
12866
12867 -- type Typ is tagged ...
12868 -- type Ref is access all Typ;
12869 -- pragma Convention (CIL, Typ);
12870
12871 -- function New_Typ (This : Ref) return Ref;
12872 -- function New_Typ (This : Ref; I : Integer) return Ref;
12873 -- pragma Cil_Constructor (New_Typ);
12874
12875 -- Reason: The first formal must NOT be a primitive of the
12876 -- tagged type.
12877
12878 -- This rule also applies to constructors of delegates used
12879 -- to interface with standard target libraries. For example:
12880
12881 -- type Delegate is access procedure ...
12882 -- pragma Import (CIL, Delegate, ...);
12883
12884 -- function new_Delegate
12885 -- (This : Delegate := null; ... ) return Delegate;
12886
12887 -- For value-types this rule does not apply.
12888
12889 if not Is_Value_Type (Etype (Def_Id)) then
12890 if No (First_Formal (Def_Id)) then
12891 Error_Msg_Name_1 := Pname;
12892 Error_Msg_N ("% function must have parameters", Def_Id);
12893 return;
12894 end if;
12895
12896 -- In the JRE library we have several occurrences in which
12897 -- the "this" parameter is not the first formal.
12898
12899 This_Formal := First_Formal (Def_Id);
12900
12901 -- In the JRE library we have several occurrences in which
12902 -- the "this" parameter is not the first formal. Search for
12903 -- it.
12904
12905 if VM_Target = JVM_Target then
12906 while Present (This_Formal)
12907 and then Get_Name_String (Chars (This_Formal)) /= "this"
12908 loop
12909 Next_Formal (This_Formal);
12910 end loop;
12911
12912 if No (This_Formal) then
12913 This_Formal := First_Formal (Def_Id);
12914 end if;
12915 end if;
12916
12917 -- Warning: The first parameter should be named "this".
12918 -- We temporarily allow it because we have the following
12919 -- case in the Java runtime (file s-osinte.ads) ???
12920
12921 -- function new_Thread
12922 -- (Self_Id : System.Address) return Thread_Id;
12923 -- pragma Java_Constructor (new_Thread);
12924
12925 if VM_Target = JVM_Target
12926 and then Get_Name_String (Chars (First_Formal (Def_Id)))
12927 = "self_id"
12928 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
12929 then
12930 null;
12931
12932 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
12933 Error_Msg_Name_1 := Pname;
12934 Error_Msg_N
12935 ("first formal of % function must be named `this`",
12936 Parent (This_Formal));
12937
12938 elsif not Is_Access_Type (Etype (This_Formal)) then
12939 Error_Msg_Name_1 := Pname;
12940 Error_Msg_N
12941 ("first formal of % function must be an access type",
12942 Parameter_Type (Parent (This_Formal)));
12943
12944 -- For delegates the type of the first formal must be a
12945 -- named access-to-subprogram type (see previous example)
12946
12947 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
12948 and then Ekind (Etype (This_Formal))
12949 /= E_Access_Subprogram_Type
12950 then
12951 Error_Msg_Name_1 := Pname;
12952 Error_Msg_N
12953 ("first formal of % function must be a named access "
12954 & "to subprogram type",
12955 Parameter_Type (Parent (This_Formal)));
12956
12957 -- Warning: We should reject anonymous access types because
12958 -- the constructor must not be handled as a primitive of the
12959 -- tagged type. We temporarily allow it because this profile
12960 -- is currently generated by cil2ada???
12961
12962 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
12963 and then not Ekind_In (Etype (This_Formal),
12964 E_Access_Type,
12965 E_General_Access_Type,
12966 E_Anonymous_Access_Type)
12967 then
12968 Error_Msg_Name_1 := Pname;
12969 Error_Msg_N
12970 ("first formal of % function must be a named access "
12971 & "type", Parameter_Type (Parent (This_Formal)));
12972
12973 elsif Atree.Convention
12974 (Designated_Type (Etype (This_Formal))) /= Convention
12975 then
12976 Error_Msg_Name_1 := Pname;
12977
12978 if Convention = Convention_Java then
12979 Error_Msg_N
12980 ("pragma% requires convention 'Cil in designated "
12981 & "type", Parameter_Type (Parent (This_Formal)));
12982 else
12983 Error_Msg_N
12984 ("pragma% requires convention 'Java in designated "
12985 & "type", Parameter_Type (Parent (This_Formal)));
12986 end if;
12987
12988 elsif No (Expression (Parent (This_Formal)))
12989 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
12990 then
12991 Error_Msg_Name_1 := Pname;
12992 Error_Msg_N
12993 ("pragma% requires first formal with default `null`",
12994 Parameter_Type (Parent (This_Formal)));
12995 end if;
12996 end if;
12997
12998 -- Check result type: the constructor must be a function
12999 -- returning:
13000 -- * a value type (only allowed in the CIL compiler)
13001 -- * an access-to-subprogram type with convention Java/CIL
13002 -- * an access-type designating a type that has convention
13003 -- Java/CIL.
13004
13005 if Is_Value_Type (Etype (Def_Id)) then
13006 null;
13007
13008 -- Access-to-subprogram type with convention Java/CIL
13009
13010 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
13011 if Atree.Convention (Etype (Def_Id)) /= Convention then
13012 if Convention = Convention_Java then
13013 Error_Pragma_Arg
13014 ("pragma% requires function returning a 'Java "
13015 & "access type", Arg1);
13016 else
13017 pragma Assert (Convention = Convention_CIL);
13018 Error_Pragma_Arg
13019 ("pragma% requires function returning a 'C'I'L "
13020 & "access type", Arg1);
13021 end if;
13022 end if;
13023
13024 elsif Ekind (Etype (Def_Id)) in Access_Kind then
13025 if not Ekind_In (Etype (Def_Id), E_Access_Type,
13026 E_General_Access_Type)
13027 or else
13028 Atree.Convention
13029 (Designated_Type (Etype (Def_Id))) /= Convention
13030 then
13031 Error_Msg_Name_1 := Pname;
13032
13033 if Convention = Convention_Java then
13034 Error_Pragma_Arg
13035 ("pragma% requires function returning a named "
13036 & "'Java access type", Arg1);
13037 else
13038 Error_Pragma_Arg
13039 ("pragma% requires function returning a named "
13040 & "'C'I'L access type", Arg1);
13041 end if;
13042 end if;
13043 end if;
13044
13045 Set_Is_Constructor (Def_Id);
13046 Set_Convention (Def_Id, Convention);
13047 Set_Is_Imported (Def_Id);
13048
13049 exit when From_Aspect_Specification (N);
13050 Hom_Id := Homonym (Hom_Id);
13051
13052 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
13053 end loop;
13054 end Java_Constructor;
13055
13056 ----------------------
13057 -- Java_Interface --
13058 ----------------------
13059
13060 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
13061
13062 when Pragma_Java_Interface => Java_Interface : declare
13063 Arg : Node_Id;
13064 Typ : Entity_Id;
13065
13066 begin
13067 GNAT_Pragma;
13068 Check_Arg_Count (1);
13069 Check_Optional_Identifier (Arg1, Name_Entity);
13070 Check_Arg_Is_Local_Name (Arg1);
13071
13072 Arg := Get_Pragma_Arg (Arg1);
13073 Analyze (Arg);
13074
13075 if Etype (Arg) = Any_Type then
13076 return;
13077 end if;
13078
13079 if not Is_Entity_Name (Arg)
13080 or else not Is_Type (Entity (Arg))
13081 then
13082 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
13083 end if;
13084
13085 Typ := Underlying_Type (Entity (Arg));
13086
13087 -- For now simply check some of the semantic constraints on the
13088 -- type. This currently leaves out some restrictions on interface
13089 -- types, namely that the parent type must be java.lang.Object.Typ
13090 -- and that all primitives of the type should be declared
13091 -- abstract. ???
13092
13093 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
13094 Error_Pragma_Arg ("pragma% requires an abstract "
13095 & "tagged type", Arg1);
13096
13097 elsif not Has_Discriminants (Typ)
13098 or else Ekind (Etype (First_Discriminant (Typ)))
13099 /= E_Anonymous_Access_Type
13100 or else
13101 not Is_Class_Wide_Type
13102 (Designated_Type (Etype (First_Discriminant (Typ))))
13103 then
13104 Error_Pragma_Arg
13105 ("type must have a class-wide access discriminant", Arg1);
13106 end if;
13107 end Java_Interface;
13108
13109 ----------------
13110 -- Keep_Names --
13111 ----------------
13112
13113 -- pragma Keep_Names ([On => ] local_NAME);
13114
13115 when Pragma_Keep_Names => Keep_Names : declare
13116 Arg : Node_Id;
13117
13118 begin
13119 GNAT_Pragma;
13120 Check_Arg_Count (1);
13121 Check_Optional_Identifier (Arg1, Name_On);
13122 Check_Arg_Is_Local_Name (Arg1);
13123
13124 Arg := Get_Pragma_Arg (Arg1);
13125 Analyze (Arg);
13126
13127 if Etype (Arg) = Any_Type then
13128 return;
13129 end if;
13130
13131 if not Is_Entity_Name (Arg)
13132 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
13133 then
13134 Error_Pragma_Arg
13135 ("pragma% requires a local enumeration type", Arg1);
13136 end if;
13137
13138 Set_Discard_Names (Entity (Arg), False);
13139 end Keep_Names;
13140
13141 -------------
13142 -- License --
13143 -------------
13144
13145 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
13146
13147 when Pragma_License =>
13148 GNAT_Pragma;
13149 Check_Arg_Count (1);
13150 Check_No_Identifiers;
13151 Check_Valid_Configuration_Pragma;
13152 Check_Arg_Is_Identifier (Arg1);
13153
13154 declare
13155 Sind : constant Source_File_Index :=
13156 Source_Index (Current_Sem_Unit);
13157
13158 begin
13159 case Chars (Get_Pragma_Arg (Arg1)) is
13160 when Name_GPL =>
13161 Set_License (Sind, GPL);
13162
13163 when Name_Modified_GPL =>
13164 Set_License (Sind, Modified_GPL);
13165
13166 when Name_Restricted =>
13167 Set_License (Sind, Restricted);
13168
13169 when Name_Unrestricted =>
13170 Set_License (Sind, Unrestricted);
13171
13172 when others =>
13173 Error_Pragma_Arg ("invalid license name", Arg1);
13174 end case;
13175 end;
13176
13177 ---------------
13178 -- Link_With --
13179 ---------------
13180
13181 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
13182
13183 when Pragma_Link_With => Link_With : declare
13184 Arg : Node_Id;
13185
13186 begin
13187 GNAT_Pragma;
13188
13189 if Operating_Mode = Generate_Code
13190 and then In_Extended_Main_Source_Unit (N)
13191 then
13192 Check_At_Least_N_Arguments (1);
13193 Check_No_Identifiers;
13194 Check_Is_In_Decl_Part_Or_Package_Spec;
13195 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13196 Start_String;
13197
13198 Arg := Arg1;
13199 while Present (Arg) loop
13200 Check_Arg_Is_Static_Expression (Arg, Standard_String);
13201
13202 -- Store argument, converting sequences of spaces to a
13203 -- single null character (this is one of the differences
13204 -- in processing between Link_With and Linker_Options).
13205
13206 Arg_Store : declare
13207 C : constant Char_Code := Get_Char_Code (' ');
13208 S : constant String_Id :=
13209 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
13210 L : constant Nat := String_Length (S);
13211 F : Nat := 1;
13212
13213 procedure Skip_Spaces;
13214 -- Advance F past any spaces
13215
13216 -----------------
13217 -- Skip_Spaces --
13218 -----------------
13219
13220 procedure Skip_Spaces is
13221 begin
13222 while F <= L and then Get_String_Char (S, F) = C loop
13223 F := F + 1;
13224 end loop;
13225 end Skip_Spaces;
13226
13227 -- Start of processing for Arg_Store
13228
13229 begin
13230 Skip_Spaces; -- skip leading spaces
13231
13232 -- Loop through characters, changing any embedded
13233 -- sequence of spaces to a single null character (this
13234 -- is how Link_With/Linker_Options differ)
13235
13236 while F <= L loop
13237 if Get_String_Char (S, F) = C then
13238 Skip_Spaces;
13239 exit when F > L;
13240 Store_String_Char (ASCII.NUL);
13241
13242 else
13243 Store_String_Char (Get_String_Char (S, F));
13244 F := F + 1;
13245 end if;
13246 end loop;
13247 end Arg_Store;
13248
13249 Arg := Next (Arg);
13250
13251 if Present (Arg) then
13252 Store_String_Char (ASCII.NUL);
13253 end if;
13254 end loop;
13255
13256 Store_Linker_Option_String (End_String);
13257 end if;
13258 end Link_With;
13259
13260 ------------------
13261 -- Linker_Alias --
13262 ------------------
13263
13264 -- pragma Linker_Alias (
13265 -- [Entity =>] LOCAL_NAME
13266 -- [Target =>] static_string_EXPRESSION);
13267
13268 when Pragma_Linker_Alias =>
13269 GNAT_Pragma;
13270 Check_Arg_Order ((Name_Entity, Name_Target));
13271 Check_Arg_Count (2);
13272 Check_Optional_Identifier (Arg1, Name_Entity);
13273 Check_Optional_Identifier (Arg2, Name_Target);
13274 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13275 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
13276
13277 -- The only processing required is to link this item on to the
13278 -- list of rep items for the given entity. This is accomplished
13279 -- by the call to Rep_Item_Too_Late (when no error is detected
13280 -- and False is returned).
13281
13282 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
13283 return;
13284 else
13285 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
13286 end if;
13287
13288 ------------------------
13289 -- Linker_Constructor --
13290 ------------------------
13291
13292 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
13293
13294 -- Code is shared with Linker_Destructor
13295
13296 -----------------------
13297 -- Linker_Destructor --
13298 -----------------------
13299
13300 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
13301
13302 when Pragma_Linker_Constructor |
13303 Pragma_Linker_Destructor =>
13304 Linker_Constructor : declare
13305 Arg1_X : Node_Id;
13306 Proc : Entity_Id;
13307
13308 begin
13309 GNAT_Pragma;
13310 Check_Arg_Count (1);
13311 Check_No_Identifiers;
13312 Check_Arg_Is_Local_Name (Arg1);
13313 Arg1_X := Get_Pragma_Arg (Arg1);
13314 Analyze (Arg1_X);
13315 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
13316
13317 if not Is_Library_Level_Entity (Proc) then
13318 Error_Pragma_Arg
13319 ("argument for pragma% must be library level entity", Arg1);
13320 end if;
13321
13322 -- The only processing required is to link this item on to the
13323 -- list of rep items for the given entity. This is accomplished
13324 -- by the call to Rep_Item_Too_Late (when no error is detected
13325 -- and False is returned).
13326
13327 if Rep_Item_Too_Late (Proc, N) then
13328 return;
13329 else
13330 Set_Has_Gigi_Rep_Item (Proc);
13331 end if;
13332 end Linker_Constructor;
13333
13334 --------------------
13335 -- Linker_Options --
13336 --------------------
13337
13338 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
13339
13340 when Pragma_Linker_Options => Linker_Options : declare
13341 Arg : Node_Id;
13342
13343 begin
13344 Check_Ada_83_Warning;
13345 Check_No_Identifiers;
13346 Check_Arg_Count (1);
13347 Check_Is_In_Decl_Part_Or_Package_Spec;
13348 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13349 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
13350
13351 Arg := Arg2;
13352 while Present (Arg) loop
13353 Check_Arg_Is_Static_Expression (Arg, Standard_String);
13354 Store_String_Char (ASCII.NUL);
13355 Store_String_Chars
13356 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
13357 Arg := Next (Arg);
13358 end loop;
13359
13360 if Operating_Mode = Generate_Code
13361 and then In_Extended_Main_Source_Unit (N)
13362 then
13363 Store_Linker_Option_String (End_String);
13364 end if;
13365 end Linker_Options;
13366
13367 --------------------
13368 -- Linker_Section --
13369 --------------------
13370
13371 -- pragma Linker_Section (
13372 -- [Entity =>] LOCAL_NAME
13373 -- [Section =>] static_string_EXPRESSION);
13374
13375 when Pragma_Linker_Section =>
13376 GNAT_Pragma;
13377 Check_Arg_Order ((Name_Entity, Name_Section));
13378 Check_Arg_Count (2);
13379 Check_Optional_Identifier (Arg1, Name_Entity);
13380 Check_Optional_Identifier (Arg2, Name_Section);
13381 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13382 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
13383
13384 -- This pragma applies only to objects
13385
13386 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
13387 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
13388 end if;
13389
13390 -- The only processing required is to link this item on to the
13391 -- list of rep items for the given entity. This is accomplished
13392 -- by the call to Rep_Item_Too_Late (when no error is detected
13393 -- and False is returned).
13394
13395 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
13396 return;
13397 else
13398 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
13399 end if;
13400
13401 ----------
13402 -- List --
13403 ----------
13404
13405 -- pragma List (On | Off)
13406
13407 -- There is nothing to do here, since we did all the processing for
13408 -- this pragma in Par.Prag (so that it works properly even in syntax
13409 -- only mode).
13410
13411 when Pragma_List =>
13412 null;
13413
13414 ---------------
13415 -- Lock_Free --
13416 ---------------
13417
13418 -- pragma Lock_Free [(Boolean_EXPRESSION)];
13419
13420 when Pragma_Lock_Free => Lock_Free : declare
13421 P : constant Node_Id := Parent (N);
13422 Arg : Node_Id;
13423 Ent : Entity_Id;
13424 Val : Boolean;
13425
13426 begin
13427 Check_No_Identifiers;
13428 Check_At_Most_N_Arguments (1);
13429
13430 -- Protected definition case
13431
13432 if Nkind (P) = N_Protected_Definition then
13433 Ent := Defining_Identifier (Parent (P));
13434
13435 -- One argument
13436
13437 if Arg_Count = 1 then
13438 Arg := Get_Pragma_Arg (Arg1);
13439 Val := Is_True (Static_Boolean (Arg));
13440
13441 -- No arguments (expression is considered to be True)
13442
13443 else
13444 Val := True;
13445 end if;
13446
13447 -- Check duplicate pragma before we chain the pragma in the Rep
13448 -- Item chain of Ent.
13449
13450 Check_Duplicate_Pragma (Ent);
13451 Record_Rep_Item (Ent, N);
13452 Set_Uses_Lock_Free (Ent, Val);
13453
13454 -- Anything else is incorrect placement
13455
13456 else
13457 Pragma_Misplaced;
13458 end if;
13459 end Lock_Free;
13460
13461 --------------------
13462 -- Locking_Policy --
13463 --------------------
13464
13465 -- pragma Locking_Policy (policy_IDENTIFIER);
13466
13467 when Pragma_Locking_Policy => declare
13468 subtype LP_Range is Name_Id
13469 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
13470 LP_Val : LP_Range;
13471 LP : Character;
13472
13473 begin
13474 Check_Ada_83_Warning;
13475 Check_Arg_Count (1);
13476 Check_No_Identifiers;
13477 Check_Arg_Is_Locking_Policy (Arg1);
13478 Check_Valid_Configuration_Pragma;
13479 LP_Val := Chars (Get_Pragma_Arg (Arg1));
13480
13481 case LP_Val is
13482 when Name_Ceiling_Locking =>
13483 LP := 'C';
13484 when Name_Inheritance_Locking =>
13485 LP := 'I';
13486 when Name_Concurrent_Readers_Locking =>
13487 LP := 'R';
13488 end case;
13489
13490 if Locking_Policy /= ' '
13491 and then Locking_Policy /= LP
13492 then
13493 Error_Msg_Sloc := Locking_Policy_Sloc;
13494 Error_Pragma ("locking policy incompatible with policy#");
13495
13496 -- Set new policy, but always preserve System_Location since we
13497 -- like the error message with the run time name.
13498
13499 else
13500 Locking_Policy := LP;
13501
13502 if Locking_Policy_Sloc /= System_Location then
13503 Locking_Policy_Sloc := Loc;
13504 end if;
13505 end if;
13506 end;
13507
13508 ----------------
13509 -- Long_Float --
13510 ----------------
13511
13512 -- pragma Long_Float (D_Float | G_Float);
13513
13514 when Pragma_Long_Float => Long_Float : declare
13515 begin
13516 GNAT_Pragma;
13517 Check_Valid_Configuration_Pragma;
13518 Check_Arg_Count (1);
13519 Check_No_Identifier (Arg1);
13520 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
13521
13522 if not OpenVMS_On_Target then
13523 Error_Pragma ("??pragma% ignored (applies only to Open'V'M'S)");
13524 end if;
13525
13526 -- D_Float case
13527
13528 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
13529 if Opt.Float_Format_Long = 'G' then
13530 Error_Pragma_Arg
13531 ("G_Float previously specified", Arg1);
13532
13533 elsif Current_Sem_Unit /= Main_Unit
13534 and then Opt.Float_Format_Long /= 'D'
13535 then
13536 Error_Pragma_Arg
13537 ("main unit not compiled with pragma Long_Float (D_Float)",
13538 "\pragma% must be used consistently for whole partition",
13539 Arg1);
13540
13541 else
13542 Opt.Float_Format_Long := 'D';
13543 end if;
13544
13545 -- G_Float case (this is the default, does not need overriding)
13546
13547 else
13548 if Opt.Float_Format_Long = 'D' then
13549 Error_Pragma ("D_Float previously specified");
13550
13551 elsif Current_Sem_Unit /= Main_Unit
13552 and then Opt.Float_Format_Long /= 'G'
13553 then
13554 Error_Pragma_Arg
13555 ("main unit not compiled with pragma Long_Float (G_Float)",
13556 "\pragma% must be used consistently for whole partition",
13557 Arg1);
13558
13559 else
13560 Opt.Float_Format_Long := 'G';
13561 end if;
13562 end if;
13563
13564 Set_Standard_Fpt_Formats;
13565 end Long_Float;
13566
13567 --------------------
13568 -- Loop_Invariant --
13569 --------------------
13570
13571 -- pragma Loop_Invariant ( boolean_EXPRESSION );
13572
13573 when Pragma_Loop_Invariant => Loop_Invariant : declare
13574 begin
13575 GNAT_Pragma;
13576 S14_Pragma;
13577 Check_Arg_Count (1);
13578 Check_Loop_Pragma_Placement;
13579
13580 -- Completely ignore if disabled
13581
13582 if not Check_Enabled (Pname) then
13583 Rewrite (N, Make_Null_Statement (Loc));
13584 Analyze (N);
13585 return;
13586 end if;
13587
13588 Preanalyze_Assert_Expression (Expression (Arg1), Any_Boolean);
13589
13590 -- Transform pragma Loop_Invariant into equivalent pragma Check
13591 -- Generate:
13592 -- pragma Check (Loop_Invaraint, Arg1);
13593
13594 Rewrite (N,
13595 Make_Pragma (Loc,
13596 Chars => Name_Check,
13597 Pragma_Argument_Associations => New_List (
13598 Make_Pragma_Argument_Association (Loc,
13599 Expression => Make_Identifier (Loc, Name_Loop_Invariant)),
13600 Relocate_Node (Arg1))));
13601
13602 Analyze (N);
13603 end Loop_Invariant;
13604
13605 -------------------
13606 -- Loop_Optimize --
13607 -------------------
13608
13609 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
13610
13611 -- OPTIMIZATION_HINT ::= No_Unroll | Unroll | No_Vector | Vector
13612
13613 when Pragma_Loop_Optimize => Loop_Optimize : declare
13614 Hint : Node_Id;
13615
13616 begin
13617 GNAT_Pragma;
13618 Check_At_Least_N_Arguments (1);
13619 Check_No_Identifiers;
13620
13621 Hint := First (Pragma_Argument_Associations (N));
13622 while Present (Hint) loop
13623 Check_Arg_Is_One_Of (Hint,
13624 Name_No_Unroll, Name_Unroll, Name_No_Vector, Name_Vector);
13625 Next (Hint);
13626 end loop;
13627
13628 Check_Loop_Pragma_Placement;
13629 end Loop_Optimize;
13630
13631 ------------------
13632 -- Loop_Variant --
13633 ------------------
13634
13635 -- pragma Loop_Variant
13636 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
13637
13638 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
13639
13640 -- CHANGE_DIRECTION ::= Increases | Decreases
13641
13642 when Pragma_Loop_Variant => Loop_Variant : declare
13643 Variant : Node_Id;
13644
13645 begin
13646 GNAT_Pragma;
13647 S14_Pragma;
13648 Check_At_Least_N_Arguments (1);
13649 Check_Loop_Pragma_Placement;
13650
13651 -- Completely ignore if disabled
13652
13653 if not Check_Enabled (Pname) then
13654 Rewrite (N, Make_Null_Statement (Loc));
13655 Analyze (N);
13656 return;
13657 end if;
13658
13659 -- Process all increasing / decreasing expressions
13660
13661 Variant := First (Pragma_Argument_Associations (N));
13662 while Present (Variant) loop
13663 if Chars (Variant) /= Name_Decreases
13664 and then Chars (Variant) /= Name_Increases
13665 then
13666 Error_Pragma_Arg ("wrong change modifier", Variant);
13667 end if;
13668
13669 Preanalyze_Assert_Expression
13670 (Expression (Variant), Any_Discrete);
13671
13672 Next (Variant);
13673 end loop;
13674 end Loop_Variant;
13675
13676 -----------------------
13677 -- Machine_Attribute --
13678 -----------------------
13679
13680 -- pragma Machine_Attribute (
13681 -- [Entity =>] LOCAL_NAME,
13682 -- [Attribute_Name =>] static_string_EXPRESSION
13683 -- [, [Info =>] static_EXPRESSION] );
13684
13685 when Pragma_Machine_Attribute => Machine_Attribute : declare
13686 Def_Id : Entity_Id;
13687
13688 begin
13689 GNAT_Pragma;
13690 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
13691
13692 if Arg_Count = 3 then
13693 Check_Optional_Identifier (Arg3, Name_Info);
13694 Check_Arg_Is_Static_Expression (Arg3);
13695 else
13696 Check_Arg_Count (2);
13697 end if;
13698
13699 Check_Optional_Identifier (Arg1, Name_Entity);
13700 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
13701 Check_Arg_Is_Local_Name (Arg1);
13702 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
13703 Def_Id := Entity (Get_Pragma_Arg (Arg1));
13704
13705 if Is_Access_Type (Def_Id) then
13706 Def_Id := Designated_Type (Def_Id);
13707 end if;
13708
13709 if Rep_Item_Too_Early (Def_Id, N) then
13710 return;
13711 end if;
13712
13713 Def_Id := Underlying_Type (Def_Id);
13714
13715 -- The only processing required is to link this item on to the
13716 -- list of rep items for the given entity. This is accomplished
13717 -- by the call to Rep_Item_Too_Late (when no error is detected
13718 -- and False is returned).
13719
13720 if Rep_Item_Too_Late (Def_Id, N) then
13721 return;
13722 else
13723 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
13724 end if;
13725 end Machine_Attribute;
13726
13727 ----------
13728 -- Main --
13729 ----------
13730
13731 -- pragma Main
13732 -- (MAIN_OPTION [, MAIN_OPTION]);
13733
13734 -- MAIN_OPTION ::=
13735 -- [STACK_SIZE =>] static_integer_EXPRESSION
13736 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
13737 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
13738
13739 when Pragma_Main => Main : declare
13740 Args : Args_List (1 .. 3);
13741 Names : constant Name_List (1 .. 3) := (
13742 Name_Stack_Size,
13743 Name_Task_Stack_Size_Default,
13744 Name_Time_Slicing_Enabled);
13745
13746 Nod : Node_Id;
13747
13748 begin
13749 GNAT_Pragma;
13750 Gather_Associations (Names, Args);
13751
13752 for J in 1 .. 2 loop
13753 if Present (Args (J)) then
13754 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
13755 end if;
13756 end loop;
13757
13758 if Present (Args (3)) then
13759 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
13760 end if;
13761
13762 Nod := Next (N);
13763 while Present (Nod) loop
13764 if Nkind (Nod) = N_Pragma
13765 and then Pragma_Name (Nod) = Name_Main
13766 then
13767 Error_Msg_Name_1 := Pname;
13768 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13769 end if;
13770
13771 Next (Nod);
13772 end loop;
13773 end Main;
13774
13775 ------------------
13776 -- Main_Storage --
13777 ------------------
13778
13779 -- pragma Main_Storage
13780 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
13781
13782 -- MAIN_STORAGE_OPTION ::=
13783 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
13784 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
13785
13786 when Pragma_Main_Storage => Main_Storage : declare
13787 Args : Args_List (1 .. 2);
13788 Names : constant Name_List (1 .. 2) := (
13789 Name_Working_Storage,
13790 Name_Top_Guard);
13791
13792 Nod : Node_Id;
13793
13794 begin
13795 GNAT_Pragma;
13796 Gather_Associations (Names, Args);
13797
13798 for J in 1 .. 2 loop
13799 if Present (Args (J)) then
13800 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
13801 end if;
13802 end loop;
13803
13804 Check_In_Main_Program;
13805
13806 Nod := Next (N);
13807 while Present (Nod) loop
13808 if Nkind (Nod) = N_Pragma
13809 and then Pragma_Name (Nod) = Name_Main_Storage
13810 then
13811 Error_Msg_Name_1 := Pname;
13812 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13813 end if;
13814
13815 Next (Nod);
13816 end loop;
13817 end Main_Storage;
13818
13819 -----------------
13820 -- Memory_Size --
13821 -----------------
13822
13823 -- pragma Memory_Size (NUMERIC_LITERAL)
13824
13825 when Pragma_Memory_Size =>
13826 GNAT_Pragma;
13827
13828 -- Memory size is simply ignored
13829
13830 Check_No_Identifiers;
13831 Check_Arg_Count (1);
13832 Check_Arg_Is_Integer_Literal (Arg1);
13833
13834 -------------
13835 -- No_Body --
13836 -------------
13837
13838 -- pragma No_Body;
13839
13840 -- The only correct use of this pragma is on its own in a file, in
13841 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
13842 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
13843 -- check for a file containing nothing but a No_Body pragma). If we
13844 -- attempt to process it during normal semantics processing, it means
13845 -- it was misplaced.
13846
13847 when Pragma_No_Body =>
13848 GNAT_Pragma;
13849 Pragma_Misplaced;
13850
13851 ---------------
13852 -- No_Inline --
13853 ---------------
13854
13855 -- pragma No_Inline ( NAME {, NAME} );
13856
13857 when Pragma_No_Inline =>
13858 GNAT_Pragma;
13859 Process_Inline (Suppressed);
13860
13861 ---------------
13862 -- No_Return --
13863 ---------------
13864
13865 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
13866
13867 when Pragma_No_Return => No_Return : declare
13868 Id : Node_Id;
13869 E : Entity_Id;
13870 Found : Boolean;
13871 Arg : Node_Id;
13872
13873 begin
13874 Ada_2005_Pragma;
13875 Check_At_Least_N_Arguments (1);
13876
13877 -- Loop through arguments of pragma
13878
13879 Arg := Arg1;
13880 while Present (Arg) loop
13881 Check_Arg_Is_Local_Name (Arg);
13882 Id := Get_Pragma_Arg (Arg);
13883 Analyze (Id);
13884
13885 if not Is_Entity_Name (Id) then
13886 Error_Pragma_Arg ("entity name required", Arg);
13887 end if;
13888
13889 if Etype (Id) = Any_Type then
13890 raise Pragma_Exit;
13891 end if;
13892
13893 -- Loop to find matching procedures
13894
13895 E := Entity (Id);
13896 Found := False;
13897 while Present (E)
13898 and then Scope (E) = Current_Scope
13899 loop
13900 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
13901 Set_No_Return (E);
13902
13903 -- Set flag on any alias as well
13904
13905 if Is_Overloadable (E) and then Present (Alias (E)) then
13906 Set_No_Return (Alias (E));
13907 end if;
13908
13909 Found := True;
13910 end if;
13911
13912 exit when From_Aspect_Specification (N);
13913 E := Homonym (E);
13914 end loop;
13915
13916 if not Found then
13917 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
13918 end if;
13919
13920 Next (Arg);
13921 end loop;
13922 end No_Return;
13923
13924 -----------------
13925 -- No_Run_Time --
13926 -----------------
13927
13928 -- pragma No_Run_Time;
13929
13930 -- Note: this pragma is retained for backwards compatibility. See
13931 -- body of Rtsfind for full details on its handling.
13932
13933 when Pragma_No_Run_Time =>
13934 GNAT_Pragma;
13935 Check_Valid_Configuration_Pragma;
13936 Check_Arg_Count (0);
13937
13938 No_Run_Time_Mode := True;
13939 Configurable_Run_Time_Mode := True;
13940
13941 -- Set Duration to 32 bits if word size is 32
13942
13943 if Ttypes.System_Word_Size = 32 then
13944 Duration_32_Bits_On_Target := True;
13945 end if;
13946
13947 -- Set appropriate restrictions
13948
13949 Set_Restriction (No_Finalization, N);
13950 Set_Restriction (No_Exception_Handlers, N);
13951 Set_Restriction (Max_Tasks, N, 0);
13952 Set_Restriction (No_Tasking, N);
13953
13954 ------------------------
13955 -- No_Strict_Aliasing --
13956 ------------------------
13957
13958 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
13959
13960 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
13961 E_Id : Entity_Id;
13962
13963 begin
13964 GNAT_Pragma;
13965 Check_At_Most_N_Arguments (1);
13966
13967 if Arg_Count = 0 then
13968 Check_Valid_Configuration_Pragma;
13969 Opt.No_Strict_Aliasing := True;
13970
13971 else
13972 Check_Optional_Identifier (Arg2, Name_Entity);
13973 Check_Arg_Is_Local_Name (Arg1);
13974 E_Id := Entity (Get_Pragma_Arg (Arg1));
13975
13976 if E_Id = Any_Type then
13977 return;
13978 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
13979 Error_Pragma_Arg ("pragma% requires access type", Arg1);
13980 end if;
13981
13982 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
13983 end if;
13984 end No_Strict_Aliasing;
13985
13986 -----------------------
13987 -- Normalize_Scalars --
13988 -----------------------
13989
13990 -- pragma Normalize_Scalars;
13991
13992 when Pragma_Normalize_Scalars =>
13993 Check_Ada_83_Warning;
13994 Check_Arg_Count (0);
13995 Check_Valid_Configuration_Pragma;
13996
13997 -- Normalize_Scalars creates false positives in CodePeer, and
13998 -- incorrect negative results in Alfa mode, so ignore this pragma
13999 -- in these modes.
14000
14001 if not (CodePeer_Mode or Alfa_Mode) then
14002 Normalize_Scalars := True;
14003 Init_Or_Norm_Scalars := True;
14004 end if;
14005
14006 -----------------
14007 -- Obsolescent --
14008 -----------------
14009
14010 -- pragma Obsolescent;
14011
14012 -- pragma Obsolescent (
14013 -- [Message =>] static_string_EXPRESSION
14014 -- [,[Version =>] Ada_05]]);
14015
14016 -- pragma Obsolescent (
14017 -- [Entity =>] NAME
14018 -- [,[Message =>] static_string_EXPRESSION
14019 -- [,[Version =>] Ada_05]] );
14020
14021 when Pragma_Obsolescent => Obsolescent : declare
14022 Ename : Node_Id;
14023 Decl : Node_Id;
14024
14025 procedure Set_Obsolescent (E : Entity_Id);
14026 -- Given an entity Ent, mark it as obsolescent if appropriate
14027
14028 ---------------------
14029 -- Set_Obsolescent --
14030 ---------------------
14031
14032 procedure Set_Obsolescent (E : Entity_Id) is
14033 Active : Boolean;
14034 Ent : Entity_Id;
14035 S : String_Id;
14036
14037 begin
14038 Active := True;
14039 Ent := E;
14040
14041 -- Entity name was given
14042
14043 if Present (Ename) then
14044
14045 -- If entity name matches, we are fine. Save entity in
14046 -- pragma argument, for ASIS use.
14047
14048 if Chars (Ename) = Chars (Ent) then
14049 Set_Entity (Ename, Ent);
14050 Generate_Reference (Ent, Ename);
14051
14052 -- If entity name does not match, only possibility is an
14053 -- enumeration literal from an enumeration type declaration.
14054
14055 elsif Ekind (Ent) /= E_Enumeration_Type then
14056 Error_Pragma
14057 ("pragma % entity name does not match declaration");
14058
14059 else
14060 Ent := First_Literal (E);
14061 loop
14062 if No (Ent) then
14063 Error_Pragma
14064 ("pragma % entity name does not match any "
14065 & "enumeration literal");
14066
14067 elsif Chars (Ent) = Chars (Ename) then
14068 Set_Entity (Ename, Ent);
14069 Generate_Reference (Ent, Ename);
14070 exit;
14071
14072 else
14073 Ent := Next_Literal (Ent);
14074 end if;
14075 end loop;
14076 end if;
14077 end if;
14078
14079 -- Ent points to entity to be marked
14080
14081 if Arg_Count >= 1 then
14082
14083 -- Deal with static string argument
14084
14085 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
14086 S := Strval (Get_Pragma_Arg (Arg1));
14087
14088 for J in 1 .. String_Length (S) loop
14089 if not In_Character_Range (Get_String_Char (S, J)) then
14090 Error_Pragma_Arg
14091 ("pragma% argument does not allow wide characters",
14092 Arg1);
14093 end if;
14094 end loop;
14095
14096 Obsolescent_Warnings.Append
14097 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
14098
14099 -- Check for Ada_05 parameter
14100
14101 if Arg_Count /= 1 then
14102 Check_Arg_Count (2);
14103
14104 declare
14105 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
14106
14107 begin
14108 Check_Arg_Is_Identifier (Argx);
14109
14110 if Chars (Argx) /= Name_Ada_05 then
14111 Error_Msg_Name_2 := Name_Ada_05;
14112 Error_Pragma_Arg
14113 ("only allowed argument for pragma% is %", Argx);
14114 end if;
14115
14116 if Ada_Version_Explicit < Ada_2005
14117 or else not Warn_On_Ada_2005_Compatibility
14118 then
14119 Active := False;
14120 end if;
14121 end;
14122 end if;
14123 end if;
14124
14125 -- Set flag if pragma active
14126
14127 if Active then
14128 Set_Is_Obsolescent (Ent);
14129 end if;
14130
14131 return;
14132 end Set_Obsolescent;
14133
14134 -- Start of processing for pragma Obsolescent
14135
14136 begin
14137 GNAT_Pragma;
14138
14139 Check_At_Most_N_Arguments (3);
14140
14141 -- See if first argument specifies an entity name
14142
14143 if Arg_Count >= 1
14144 and then
14145 (Chars (Arg1) = Name_Entity
14146 or else
14147 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
14148 N_Identifier,
14149 N_Operator_Symbol))
14150 then
14151 Ename := Get_Pragma_Arg (Arg1);
14152
14153 -- Eliminate first argument, so we can share processing
14154
14155 Arg1 := Arg2;
14156 Arg2 := Arg3;
14157 Arg_Count := Arg_Count - 1;
14158
14159 -- No Entity name argument given
14160
14161 else
14162 Ename := Empty;
14163 end if;
14164
14165 if Arg_Count >= 1 then
14166 Check_Optional_Identifier (Arg1, Name_Message);
14167
14168 if Arg_Count = 2 then
14169 Check_Optional_Identifier (Arg2, Name_Version);
14170 end if;
14171 end if;
14172
14173 -- Get immediately preceding declaration
14174
14175 Decl := Prev (N);
14176 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
14177 Prev (Decl);
14178 end loop;
14179
14180 -- Cases where we do not follow anything other than another pragma
14181
14182 if No (Decl) then
14183
14184 -- First case: library level compilation unit declaration with
14185 -- the pragma immediately following the declaration.
14186
14187 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
14188 Set_Obsolescent
14189 (Defining_Entity (Unit (Parent (Parent (N)))));
14190 return;
14191
14192 -- Case 2: library unit placement for package
14193
14194 else
14195 declare
14196 Ent : constant Entity_Id := Find_Lib_Unit_Name;
14197 begin
14198 if Is_Package_Or_Generic_Package (Ent) then
14199 Set_Obsolescent (Ent);
14200 return;
14201 end if;
14202 end;
14203 end if;
14204
14205 -- Cases where we must follow a declaration
14206
14207 else
14208 if Nkind (Decl) not in N_Declaration
14209 and then Nkind (Decl) not in N_Later_Decl_Item
14210 and then Nkind (Decl) not in N_Generic_Declaration
14211 and then Nkind (Decl) not in N_Renaming_Declaration
14212 then
14213 Error_Pragma
14214 ("pragma% misplaced, "
14215 & "must immediately follow a declaration");
14216
14217 else
14218 Set_Obsolescent (Defining_Entity (Decl));
14219 return;
14220 end if;
14221 end if;
14222 end Obsolescent;
14223
14224 --------------
14225 -- Optimize --
14226 --------------
14227
14228 -- pragma Optimize (Time | Space | Off);
14229
14230 -- The actual check for optimize is done in Gigi. Note that this
14231 -- pragma does not actually change the optimization setting, it
14232 -- simply checks that it is consistent with the pragma.
14233
14234 when Pragma_Optimize =>
14235 Check_No_Identifiers;
14236 Check_Arg_Count (1);
14237 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
14238
14239 ------------------------
14240 -- Optimize_Alignment --
14241 ------------------------
14242
14243 -- pragma Optimize_Alignment (Time | Space | Off);
14244
14245 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
14246 GNAT_Pragma;
14247 Check_No_Identifiers;
14248 Check_Arg_Count (1);
14249 Check_Valid_Configuration_Pragma;
14250
14251 declare
14252 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
14253 begin
14254 case Nam is
14255 when Name_Time =>
14256 Opt.Optimize_Alignment := 'T';
14257 when Name_Space =>
14258 Opt.Optimize_Alignment := 'S';
14259 when Name_Off =>
14260 Opt.Optimize_Alignment := 'O';
14261 when others =>
14262 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
14263 end case;
14264 end;
14265
14266 -- Set indication that mode is set locally. If we are in fact in a
14267 -- configuration pragma file, this setting is harmless since the
14268 -- switch will get reset anyway at the start of each unit.
14269
14270 Optimize_Alignment_Local := True;
14271 end Optimize_Alignment;
14272
14273 -------------------
14274 -- Overflow_Mode --
14275 -------------------
14276
14277 -- pragma Overflow_Mode
14278 -- ([General => ] MODE [, [Assertions => ] MODE]);
14279
14280 -- MODE := STRICT | MINIMIZED | ELIMINATED
14281
14282 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
14283 -- since System.Bignums makes this assumption. This is true of nearly
14284 -- all (all?) targets.
14285
14286 when Pragma_Overflow_Mode => Overflow_Mode : declare
14287 function Get_Overflow_Mode
14288 (Name : Name_Id;
14289 Arg : Node_Id) return Overflow_Mode_Type;
14290 -- Function to process one pragma argument, Arg. If an identifier
14291 -- is present, it must be Name. Mode type is returned if a valid
14292 -- argument exists, otherwise an error is signalled.
14293
14294 -----------------------
14295 -- Get_Overflow_Mode --
14296 -----------------------
14297
14298 function Get_Overflow_Mode
14299 (Name : Name_Id;
14300 Arg : Node_Id) return Overflow_Mode_Type
14301 is
14302 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
14303
14304 begin
14305 Check_Optional_Identifier (Arg, Name);
14306 Check_Arg_Is_Identifier (Argx);
14307
14308 if Chars (Argx) = Name_Strict then
14309 return Strict;
14310
14311 elsif Chars (Argx) = Name_Minimized then
14312 return Minimized;
14313
14314 elsif Chars (Argx) = Name_Eliminated then
14315 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
14316 Error_Pragma_Arg
14317 ("Eliminated not implemented on this target", Argx);
14318 else
14319 return Eliminated;
14320 end if;
14321
14322 else
14323 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
14324 end if;
14325 end Get_Overflow_Mode;
14326
14327 -- Start of processing for Overflow_Mode
14328
14329 begin
14330 GNAT_Pragma;
14331 Check_At_Least_N_Arguments (1);
14332 Check_At_Most_N_Arguments (2);
14333
14334 -- Process first argument
14335
14336 Scope_Suppress.Overflow_Mode_General :=
14337 Get_Overflow_Mode (Name_General, Arg1);
14338
14339 -- Case of only one argument
14340
14341 if Arg_Count = 1 then
14342 Scope_Suppress.Overflow_Mode_Assertions :=
14343 Scope_Suppress.Overflow_Mode_General;
14344
14345 -- Case of two arguments present
14346
14347 else
14348 Scope_Suppress.Overflow_Mode_Assertions :=
14349 Get_Overflow_Mode (Name_Assertions, Arg2);
14350 end if;
14351 end Overflow_Mode;
14352
14353 when Pragma_Overriding_Renamings =>
14354 Overriding_Renamings := True;
14355
14356 -------------
14357 -- Ordered --
14358 -------------
14359
14360 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
14361
14362 when Pragma_Ordered => Ordered : declare
14363 Assoc : constant Node_Id := Arg1;
14364 Type_Id : Node_Id;
14365 Typ : Entity_Id;
14366
14367 begin
14368 GNAT_Pragma;
14369 Check_No_Identifiers;
14370 Check_Arg_Count (1);
14371 Check_Arg_Is_Local_Name (Arg1);
14372
14373 Type_Id := Get_Pragma_Arg (Assoc);
14374 Find_Type (Type_Id);
14375 Typ := Entity (Type_Id);
14376
14377 if Typ = Any_Type then
14378 return;
14379 else
14380 Typ := Underlying_Type (Typ);
14381 end if;
14382
14383 if not Is_Enumeration_Type (Typ) then
14384 Error_Pragma ("pragma% must specify enumeration type");
14385 end if;
14386
14387 Check_First_Subtype (Arg1);
14388 Set_Has_Pragma_Ordered (Base_Type (Typ));
14389 end Ordered;
14390
14391 ----------
14392 -- Pack --
14393 ----------
14394
14395 -- pragma Pack (first_subtype_LOCAL_NAME);
14396
14397 when Pragma_Pack => Pack : declare
14398 Assoc : constant Node_Id := Arg1;
14399 Type_Id : Node_Id;
14400 Typ : Entity_Id;
14401 Ctyp : Entity_Id;
14402 Ignore : Boolean := False;
14403
14404 begin
14405 Check_No_Identifiers;
14406 Check_Arg_Count (1);
14407 Check_Arg_Is_Local_Name (Arg1);
14408
14409 Type_Id := Get_Pragma_Arg (Assoc);
14410 Find_Type (Type_Id);
14411 Typ := Entity (Type_Id);
14412
14413 if Typ = Any_Type
14414 or else Rep_Item_Too_Early (Typ, N)
14415 then
14416 return;
14417 else
14418 Typ := Underlying_Type (Typ);
14419 end if;
14420
14421 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
14422 Error_Pragma ("pragma% must specify array or record type");
14423 end if;
14424
14425 Check_First_Subtype (Arg1);
14426 Check_Duplicate_Pragma (Typ);
14427
14428 -- Array type
14429
14430 if Is_Array_Type (Typ) then
14431 Ctyp := Component_Type (Typ);
14432
14433 -- Ignore pack that does nothing
14434
14435 if Known_Static_Esize (Ctyp)
14436 and then Known_Static_RM_Size (Ctyp)
14437 and then Esize (Ctyp) = RM_Size (Ctyp)
14438 and then Addressable (Esize (Ctyp))
14439 then
14440 Ignore := True;
14441 end if;
14442
14443 -- Process OK pragma Pack. Note that if there is a separate
14444 -- component clause present, the Pack will be cancelled. This
14445 -- processing is in Freeze.
14446
14447 if not Rep_Item_Too_Late (Typ, N) then
14448
14449 -- In the context of static code analysis, we do not need
14450 -- complex front-end expansions related to pragma Pack,
14451 -- so disable handling of pragma Pack in these cases.
14452
14453 if CodePeer_Mode or Alfa_Mode then
14454 null;
14455
14456 -- Don't attempt any packing for VM targets. We possibly
14457 -- could deal with some cases of array bit-packing, but we
14458 -- don't bother, since this is not a typical kind of
14459 -- representation in the VM context anyway (and would not
14460 -- for example work nicely with the debugger).
14461
14462 elsif VM_Target /= No_VM then
14463 if not GNAT_Mode then
14464 Error_Pragma
14465 ("??pragma% ignored in this configuration");
14466 end if;
14467
14468 -- Normal case where we do the pack action
14469
14470 else
14471 if not Ignore then
14472 Set_Is_Packed (Base_Type (Typ));
14473 Set_Has_Non_Standard_Rep (Base_Type (Typ));
14474 end if;
14475
14476 Set_Has_Pragma_Pack (Base_Type (Typ));
14477 end if;
14478 end if;
14479
14480 -- For record types, the pack is always effective
14481
14482 else pragma Assert (Is_Record_Type (Typ));
14483 if not Rep_Item_Too_Late (Typ, N) then
14484
14485 -- Ignore pack request with warning in VM mode (skip warning
14486 -- if we are compiling GNAT run time library).
14487
14488 if VM_Target /= No_VM then
14489 if not GNAT_Mode then
14490 Error_Pragma
14491 ("??pragma% ignored in this configuration");
14492 end if;
14493
14494 -- Normal case of pack request active
14495
14496 else
14497 Set_Is_Packed (Base_Type (Typ));
14498 Set_Has_Pragma_Pack (Base_Type (Typ));
14499 Set_Has_Non_Standard_Rep (Base_Type (Typ));
14500 end if;
14501 end if;
14502 end if;
14503 end Pack;
14504
14505 ----------
14506 -- Page --
14507 ----------
14508
14509 -- pragma Page;
14510
14511 -- There is nothing to do here, since we did all the processing for
14512 -- this pragma in Par.Prag (so that it works properly even in syntax
14513 -- only mode).
14514
14515 when Pragma_Page =>
14516 null;
14517
14518 ----------------------------------
14519 -- Partition_Elaboration_Policy --
14520 ----------------------------------
14521
14522 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
14523
14524 when Pragma_Partition_Elaboration_Policy => declare
14525 subtype PEP_Range is Name_Id
14526 range First_Partition_Elaboration_Policy_Name
14527 .. Last_Partition_Elaboration_Policy_Name;
14528 PEP_Val : PEP_Range;
14529 PEP : Character;
14530
14531 begin
14532 Ada_2005_Pragma;
14533 Check_Arg_Count (1);
14534 Check_No_Identifiers;
14535 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
14536 Check_Valid_Configuration_Pragma;
14537 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
14538
14539 case PEP_Val is
14540 when Name_Concurrent =>
14541 PEP := 'C';
14542 when Name_Sequential =>
14543 PEP := 'S';
14544 end case;
14545
14546 if Partition_Elaboration_Policy /= ' '
14547 and then Partition_Elaboration_Policy /= PEP
14548 then
14549 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
14550 Error_Pragma
14551 ("partition elaboration policy incompatible with policy#");
14552
14553 -- Set new policy, but always preserve System_Location since we
14554 -- like the error message with the run time name.
14555
14556 else
14557 Partition_Elaboration_Policy := PEP;
14558
14559 if Partition_Elaboration_Policy_Sloc /= System_Location then
14560 Partition_Elaboration_Policy_Sloc := Loc;
14561 end if;
14562 end if;
14563 end;
14564
14565 -------------
14566 -- Passive --
14567 -------------
14568
14569 -- pragma Passive [(PASSIVE_FORM)];
14570
14571 -- PASSIVE_FORM ::= Semaphore | No
14572
14573 when Pragma_Passive =>
14574 GNAT_Pragma;
14575
14576 if Nkind (Parent (N)) /= N_Task_Definition then
14577 Error_Pragma ("pragma% must be within task definition");
14578 end if;
14579
14580 if Arg_Count /= 0 then
14581 Check_Arg_Count (1);
14582 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
14583 end if;
14584
14585 ----------------------------------
14586 -- Preelaborable_Initialization --
14587 ----------------------------------
14588
14589 -- pragma Preelaborable_Initialization (DIRECT_NAME);
14590
14591 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
14592 Ent : Entity_Id;
14593
14594 begin
14595 Ada_2005_Pragma;
14596 Check_Arg_Count (1);
14597 Check_No_Identifiers;
14598 Check_Arg_Is_Identifier (Arg1);
14599 Check_Arg_Is_Local_Name (Arg1);
14600 Check_First_Subtype (Arg1);
14601 Ent := Entity (Get_Pragma_Arg (Arg1));
14602
14603 -- The pragma may come from an aspect on a private declaration,
14604 -- even if the freeze point at which this is analyzed in the
14605 -- private part after the full view.
14606
14607 if Has_Private_Declaration (Ent)
14608 and then From_Aspect_Specification (N)
14609 then
14610 null;
14611
14612 elsif Is_Private_Type (Ent)
14613 or else Is_Protected_Type (Ent)
14614 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
14615 then
14616 null;
14617
14618 else
14619 Error_Pragma_Arg
14620 ("pragma % can only be applied to private, formal derived or "
14621 & "protected type",
14622 Arg1);
14623 end if;
14624
14625 -- Give an error if the pragma is applied to a protected type that
14626 -- does not qualify (due to having entries, or due to components
14627 -- that do not qualify).
14628
14629 if Is_Protected_Type (Ent)
14630 and then not Has_Preelaborable_Initialization (Ent)
14631 then
14632 Error_Msg_N
14633 ("protected type & does not have preelaborable "
14634 & "initialization", Ent);
14635
14636 -- Otherwise mark the type as definitely having preelaborable
14637 -- initialization.
14638
14639 else
14640 Set_Known_To_Have_Preelab_Init (Ent);
14641 end if;
14642
14643 if Has_Pragma_Preelab_Init (Ent)
14644 and then Warn_On_Redundant_Constructs
14645 then
14646 Error_Pragma ("?r?duplicate pragma%!");
14647 else
14648 Set_Has_Pragma_Preelab_Init (Ent);
14649 end if;
14650 end Preelab_Init;
14651
14652 --------------------
14653 -- Persistent_BSS --
14654 --------------------
14655
14656 -- pragma Persistent_BSS [(object_NAME)];
14657
14658 when Pragma_Persistent_BSS => Persistent_BSS : declare
14659 Decl : Node_Id;
14660 Ent : Entity_Id;
14661 Prag : Node_Id;
14662
14663 begin
14664 GNAT_Pragma;
14665 Check_At_Most_N_Arguments (1);
14666
14667 -- Case of application to specific object (one argument)
14668
14669 if Arg_Count = 1 then
14670 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14671
14672 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
14673 or else not
14674 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
14675 E_Constant)
14676 then
14677 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
14678 end if;
14679
14680 Ent := Entity (Get_Pragma_Arg (Arg1));
14681 Decl := Parent (Ent);
14682
14683 -- Check for duplication before inserting in list of
14684 -- representation items.
14685
14686 Check_Duplicate_Pragma (Ent);
14687
14688 if Rep_Item_Too_Late (Ent, N) then
14689 return;
14690 end if;
14691
14692 if Present (Expression (Decl)) then
14693 Error_Pragma_Arg
14694 ("object for pragma% cannot have initialization", Arg1);
14695 end if;
14696
14697 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
14698 Error_Pragma_Arg
14699 ("object type for pragma% is not potentially persistent",
14700 Arg1);
14701 end if;
14702
14703 Prag :=
14704 Make_Linker_Section_Pragma
14705 (Ent, Sloc (N), ".persistent.bss");
14706 Insert_After (N, Prag);
14707 Analyze (Prag);
14708
14709 -- Case of use as configuration pragma with no arguments
14710
14711 else
14712 Check_Valid_Configuration_Pragma;
14713 Persistent_BSS_Mode := True;
14714 end if;
14715 end Persistent_BSS;
14716
14717 -------------
14718 -- Polling --
14719 -------------
14720
14721 -- pragma Polling (ON | OFF);
14722
14723 when Pragma_Polling =>
14724 GNAT_Pragma;
14725 Check_Arg_Count (1);
14726 Check_No_Identifiers;
14727 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14728 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
14729
14730 -------------------
14731 -- Postcondition --
14732 -------------------
14733
14734 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
14735 -- [,[Message =>] String_EXPRESSION]);
14736
14737 when Pragma_Postcondition => Postcondition : declare
14738 In_Body : Boolean;
14739
14740 begin
14741 GNAT_Pragma;
14742 Check_At_Least_N_Arguments (1);
14743 Check_At_Most_N_Arguments (2);
14744 Check_Optional_Identifier (Arg1, Name_Check);
14745
14746 -- Verify the proper placement of the pragma. The remainder of the
14747 -- processing is found in Sem_Ch6/Sem_Ch7.
14748
14749 Check_Precondition_Postcondition (In_Body);
14750
14751 -- When the pragma is a source contruct and appears inside a body,
14752 -- preanalyze the boolean_expression to detect illegal forward
14753 -- references:
14754
14755 -- procedure P is
14756 -- pragma Postcondition (X'Old ...);
14757 -- X : ...
14758
14759 if Comes_From_Source (N) and then In_Body then
14760 Preanalyze_Spec_Expression (Expression (Arg1), Any_Boolean);
14761 end if;
14762 end Postcondition;
14763
14764 ------------------
14765 -- Precondition --
14766 ------------------
14767
14768 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
14769 -- [,[Message =>] String_EXPRESSION]);
14770
14771 when Pragma_Precondition => Precondition : declare
14772 In_Body : Boolean;
14773
14774 begin
14775 GNAT_Pragma;
14776 Check_At_Least_N_Arguments (1);
14777 Check_At_Most_N_Arguments (2);
14778 Check_Optional_Identifier (Arg1, Name_Check);
14779 Check_Precondition_Postcondition (In_Body);
14780
14781 -- If in spec, nothing more to do. If in body, then we convert the
14782 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
14783 -- this whether or not precondition checks are enabled. That works
14784 -- fine since pragma Check will do this check, and will also
14785 -- analyze the condition itself in the proper context.
14786
14787 if In_Body then
14788 Rewrite (N,
14789 Make_Pragma (Loc,
14790 Chars => Name_Check,
14791 Pragma_Argument_Associations => New_List (
14792 Make_Pragma_Argument_Association (Loc,
14793 Expression => Make_Identifier (Loc, Name_Precondition)),
14794
14795 Make_Pragma_Argument_Association (Sloc (Arg1),
14796 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
14797
14798 if Arg_Count = 2 then
14799 Append_To (Pragma_Argument_Associations (N),
14800 Make_Pragma_Argument_Association (Sloc (Arg2),
14801 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
14802 end if;
14803
14804 Analyze (N);
14805 end if;
14806 end Precondition;
14807
14808 ---------------
14809 -- Predicate --
14810 ---------------
14811
14812 -- pragma Predicate
14813 -- ([Entity =>] type_LOCAL_NAME,
14814 -- [Check =>] EXPRESSION);
14815
14816 when Pragma_Predicate => Predicate : declare
14817 Type_Id : Node_Id;
14818 Typ : Entity_Id;
14819
14820 Discard : Boolean;
14821 pragma Unreferenced (Discard);
14822
14823 begin
14824 GNAT_Pragma;
14825 Check_Arg_Count (2);
14826 Check_Optional_Identifier (Arg1, Name_Entity);
14827 Check_Optional_Identifier (Arg2, Name_Check);
14828
14829 Check_Arg_Is_Local_Name (Arg1);
14830
14831 Type_Id := Get_Pragma_Arg (Arg1);
14832 Find_Type (Type_Id);
14833 Typ := Entity (Type_Id);
14834
14835 if Typ = Any_Type then
14836 return;
14837 end if;
14838
14839 -- The remaining processing is simply to link the pragma on to
14840 -- the rep item chain, for processing when the type is frozen.
14841 -- This is accomplished by a call to Rep_Item_Too_Late. We also
14842 -- mark the type as having predicates.
14843
14844 Set_Has_Predicates (Typ);
14845 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
14846 end Predicate;
14847
14848 ------------------
14849 -- Preelaborate --
14850 ------------------
14851
14852 -- pragma Preelaborate [(library_unit_NAME)];
14853
14854 -- Set the flag Is_Preelaborated of program unit name entity
14855
14856 when Pragma_Preelaborate => Preelaborate : declare
14857 Pa : constant Node_Id := Parent (N);
14858 Pk : constant Node_Kind := Nkind (Pa);
14859 Ent : Entity_Id;
14860
14861 begin
14862 Check_Ada_83_Warning;
14863 Check_Valid_Library_Unit_Pragma;
14864
14865 if Nkind (N) = N_Null_Statement then
14866 return;
14867 end if;
14868
14869 Ent := Find_Lib_Unit_Name;
14870 Check_Duplicate_Pragma (Ent);
14871
14872 -- This filters out pragmas inside generic parent then
14873 -- show up inside instantiation
14874
14875 if Present (Ent)
14876 and then not (Pk = N_Package_Specification
14877 and then Present (Generic_Parent (Pa)))
14878 then
14879 if not Debug_Flag_U then
14880 Set_Is_Preelaborated (Ent);
14881 Set_Suppress_Elaboration_Warnings (Ent);
14882 end if;
14883 end if;
14884 end Preelaborate;
14885
14886 ---------------------
14887 -- Preelaborate_05 --
14888 ---------------------
14889
14890 -- pragma Preelaborate_05 [(library_unit_NAME)];
14891
14892 -- This pragma is useable only in GNAT_Mode, where it is used like
14893 -- pragma Preelaborate but it is only effective in Ada 2005 mode
14894 -- (otherwise it is ignored). This is used to implement AI-362 which
14895 -- recategorizes some run-time packages in Ada 2005 mode.
14896
14897 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
14898 Ent : Entity_Id;
14899
14900 begin
14901 GNAT_Pragma;
14902 Check_Valid_Library_Unit_Pragma;
14903
14904 if not GNAT_Mode then
14905 Error_Pragma ("pragma% only available in GNAT mode");
14906 end if;
14907
14908 if Nkind (N) = N_Null_Statement then
14909 return;
14910 end if;
14911
14912 -- This is one of the few cases where we need to test the value of
14913 -- Ada_Version_Explicit rather than Ada_Version (which is always
14914 -- set to Ada_2012 in a predefined unit), we need to know the
14915 -- explicit version set to know if this pragma is active.
14916
14917 if Ada_Version_Explicit >= Ada_2005 then
14918 Ent := Find_Lib_Unit_Name;
14919 Set_Is_Preelaborated (Ent);
14920 Set_Suppress_Elaboration_Warnings (Ent);
14921 end if;
14922 end Preelaborate_05;
14923
14924 --------------
14925 -- Priority --
14926 --------------
14927
14928 -- pragma Priority (EXPRESSION);
14929
14930 when Pragma_Priority => Priority : declare
14931 P : constant Node_Id := Parent (N);
14932 Arg : Node_Id;
14933 Ent : Entity_Id;
14934
14935 begin
14936 Check_No_Identifiers;
14937 Check_Arg_Count (1);
14938
14939 -- Subprogram case
14940
14941 if Nkind (P) = N_Subprogram_Body then
14942 Check_In_Main_Program;
14943
14944 Ent := Defining_Unit_Name (Specification (P));
14945
14946 if Nkind (Ent) = N_Defining_Program_Unit_Name then
14947 Ent := Defining_Identifier (Ent);
14948 end if;
14949
14950 Arg := Get_Pragma_Arg (Arg1);
14951 Analyze_And_Resolve (Arg, Standard_Integer);
14952
14953 -- Must be static
14954
14955 if not Is_Static_Expression (Arg) then
14956 Flag_Non_Static_Expr
14957 ("main subprogram priority is not static!", Arg);
14958 raise Pragma_Exit;
14959
14960 -- If constraint error, then we already signalled an error
14961
14962 elsif Raises_Constraint_Error (Arg) then
14963 null;
14964
14965 -- Otherwise check in range
14966
14967 else
14968 declare
14969 Val : constant Uint := Expr_Value (Arg);
14970
14971 begin
14972 if Val < 0
14973 or else Val > Expr_Value (Expression
14974 (Parent (RTE (RE_Max_Priority))))
14975 then
14976 Error_Pragma_Arg
14977 ("main subprogram priority is out of range", Arg1);
14978 end if;
14979 end;
14980 end if;
14981
14982 Set_Main_Priority
14983 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
14984
14985 -- Load an arbitrary entity from System.Tasking to make sure
14986 -- this package is implicitly with'ed, since we need to have
14987 -- the tasking run-time active for the pragma Priority to have
14988 -- any effect.
14989
14990 declare
14991 Discard : Entity_Id;
14992 pragma Warnings (Off, Discard);
14993 begin
14994 Discard := RTE (RE_Task_List);
14995 end;
14996
14997 -- Task or Protected, must be of type Integer
14998
14999 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
15000 Arg := Get_Pragma_Arg (Arg1);
15001 Ent := Defining_Identifier (Parent (P));
15002
15003 -- The expression must be analyzed in the special manner
15004 -- described in "Handling of Default and Per-Object
15005 -- Expressions" in sem.ads.
15006
15007 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
15008
15009 if not Is_Static_Expression (Arg) then
15010 Check_Restriction (Static_Priorities, Arg);
15011 end if;
15012
15013 -- Anything else is incorrect
15014
15015 else
15016 Pragma_Misplaced;
15017 end if;
15018
15019 -- Check duplicate pragma before we chain the pragma in the Rep
15020 -- Item chain of Ent.
15021
15022 Check_Duplicate_Pragma (Ent);
15023 Record_Rep_Item (Ent, N);
15024 end Priority;
15025
15026 -----------------------------------
15027 -- Priority_Specific_Dispatching --
15028 -----------------------------------
15029
15030 -- pragma Priority_Specific_Dispatching (
15031 -- policy_IDENTIFIER,
15032 -- first_priority_EXPRESSION,
15033 -- last_priority_EXPRESSION);
15034
15035 when Pragma_Priority_Specific_Dispatching =>
15036 Priority_Specific_Dispatching : declare
15037 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
15038 -- This is the entity System.Any_Priority;
15039
15040 DP : Character;
15041 Lower_Bound : Node_Id;
15042 Upper_Bound : Node_Id;
15043 Lower_Val : Uint;
15044 Upper_Val : Uint;
15045
15046 begin
15047 Ada_2005_Pragma;
15048 Check_Arg_Count (3);
15049 Check_No_Identifiers;
15050 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
15051 Check_Valid_Configuration_Pragma;
15052 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15053 DP := Fold_Upper (Name_Buffer (1));
15054
15055 Lower_Bound := Get_Pragma_Arg (Arg2);
15056 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
15057 Lower_Val := Expr_Value (Lower_Bound);
15058
15059 Upper_Bound := Get_Pragma_Arg (Arg3);
15060 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
15061 Upper_Val := Expr_Value (Upper_Bound);
15062
15063 -- It is not allowed to use Task_Dispatching_Policy and
15064 -- Priority_Specific_Dispatching in the same partition.
15065
15066 if Task_Dispatching_Policy /= ' ' then
15067 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
15068 Error_Pragma
15069 ("pragma% incompatible with Task_Dispatching_Policy#");
15070
15071 -- Check lower bound in range
15072
15073 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
15074 or else
15075 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
15076 then
15077 Error_Pragma_Arg
15078 ("first_priority is out of range", Arg2);
15079
15080 -- Check upper bound in range
15081
15082 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
15083 or else
15084 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
15085 then
15086 Error_Pragma_Arg
15087 ("last_priority is out of range", Arg3);
15088
15089 -- Check that the priority range is valid
15090
15091 elsif Lower_Val > Upper_Val then
15092 Error_Pragma
15093 ("last_priority_expression must be greater than or equal to "
15094 & "first_priority_expression");
15095
15096 -- Store the new policy, but always preserve System_Location since
15097 -- we like the error message with the run-time name.
15098
15099 else
15100 -- Check overlapping in the priority ranges specified in other
15101 -- Priority_Specific_Dispatching pragmas within the same
15102 -- partition. We can only check those we know about!
15103
15104 for J in
15105 Specific_Dispatching.First .. Specific_Dispatching.Last
15106 loop
15107 if Specific_Dispatching.Table (J).First_Priority in
15108 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
15109 or else Specific_Dispatching.Table (J).Last_Priority in
15110 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
15111 then
15112 Error_Msg_Sloc :=
15113 Specific_Dispatching.Table (J).Pragma_Loc;
15114 Error_Pragma
15115 ("priority range overlaps with "
15116 & "Priority_Specific_Dispatching#");
15117 end if;
15118 end loop;
15119
15120 -- The use of Priority_Specific_Dispatching is incompatible
15121 -- with Task_Dispatching_Policy.
15122
15123 if Task_Dispatching_Policy /= ' ' then
15124 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
15125 Error_Pragma
15126 ("Priority_Specific_Dispatching incompatible "
15127 & "with Task_Dispatching_Policy#");
15128 end if;
15129
15130 -- The use of Priority_Specific_Dispatching forces ceiling
15131 -- locking policy.
15132
15133 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
15134 Error_Msg_Sloc := Locking_Policy_Sloc;
15135 Error_Pragma
15136 ("Priority_Specific_Dispatching incompatible "
15137 & "with Locking_Policy#");
15138
15139 -- Set the Ceiling_Locking policy, but preserve System_Location
15140 -- since we like the error message with the run time name.
15141
15142 else
15143 Locking_Policy := 'C';
15144
15145 if Locking_Policy_Sloc /= System_Location then
15146 Locking_Policy_Sloc := Loc;
15147 end if;
15148 end if;
15149
15150 -- Add entry in the table
15151
15152 Specific_Dispatching.Append
15153 ((Dispatching_Policy => DP,
15154 First_Priority => UI_To_Int (Lower_Val),
15155 Last_Priority => UI_To_Int (Upper_Val),
15156 Pragma_Loc => Loc));
15157 end if;
15158 end Priority_Specific_Dispatching;
15159
15160 -------------
15161 -- Profile --
15162 -------------
15163
15164 -- pragma Profile (profile_IDENTIFIER);
15165
15166 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
15167
15168 when Pragma_Profile =>
15169 Ada_2005_Pragma;
15170 Check_Arg_Count (1);
15171 Check_Valid_Configuration_Pragma;
15172 Check_No_Identifiers;
15173
15174 declare
15175 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
15176
15177 begin
15178 if Chars (Argx) = Name_Ravenscar then
15179 Set_Ravenscar_Profile (N);
15180
15181 elsif Chars (Argx) = Name_Restricted then
15182 Set_Profile_Restrictions
15183 (Restricted,
15184 N, Warn => Treat_Restrictions_As_Warnings);
15185
15186 elsif Chars (Argx) = Name_Rational then
15187 Set_Rational_Profile;
15188
15189 elsif Chars (Argx) = Name_No_Implementation_Extensions then
15190 Set_Profile_Restrictions
15191 (No_Implementation_Extensions,
15192 N, Warn => Treat_Restrictions_As_Warnings);
15193
15194 else
15195 Error_Pragma_Arg ("& is not a valid profile", Argx);
15196 end if;
15197 end;
15198
15199 ----------------------
15200 -- Profile_Warnings --
15201 ----------------------
15202
15203 -- pragma Profile_Warnings (profile_IDENTIFIER);
15204
15205 -- profile_IDENTIFIER => Restricted | Ravenscar
15206
15207 when Pragma_Profile_Warnings =>
15208 GNAT_Pragma;
15209 Check_Arg_Count (1);
15210 Check_Valid_Configuration_Pragma;
15211 Check_No_Identifiers;
15212
15213 declare
15214 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
15215
15216 begin
15217 if Chars (Argx) = Name_Ravenscar then
15218 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
15219
15220 elsif Chars (Argx) = Name_Restricted then
15221 Set_Profile_Restrictions (Restricted, N, Warn => True);
15222
15223 elsif Chars (Argx) = Name_No_Implementation_Extensions then
15224 Set_Profile_Restrictions
15225 (No_Implementation_Extensions, N, Warn => True);
15226
15227 else
15228 Error_Pragma_Arg ("& is not a valid profile", Argx);
15229 end if;
15230 end;
15231
15232 --------------------------
15233 -- Propagate_Exceptions --
15234 --------------------------
15235
15236 -- pragma Propagate_Exceptions;
15237
15238 -- Note: this pragma is obsolete and has no effect
15239
15240 when Pragma_Propagate_Exceptions =>
15241 GNAT_Pragma;
15242 Check_Arg_Count (0);
15243
15244 if In_Extended_Main_Source_Unit (N) then
15245 Propagate_Exceptions := True;
15246 end if;
15247
15248 ------------------
15249 -- Psect_Object --
15250 ------------------
15251
15252 -- pragma Psect_Object (
15253 -- [Internal =>] LOCAL_NAME,
15254 -- [, [External =>] EXTERNAL_SYMBOL]
15255 -- [, [Size =>] EXTERNAL_SYMBOL]);
15256
15257 when Pragma_Psect_Object | Pragma_Common_Object =>
15258 Psect_Object : declare
15259 Args : Args_List (1 .. 3);
15260 Names : constant Name_List (1 .. 3) := (
15261 Name_Internal,
15262 Name_External,
15263 Name_Size);
15264
15265 Internal : Node_Id renames Args (1);
15266 External : Node_Id renames Args (2);
15267 Size : Node_Id renames Args (3);
15268
15269 Def_Id : Entity_Id;
15270
15271 procedure Check_Too_Long (Arg : Node_Id);
15272 -- Posts message if the argument is an identifier with more
15273 -- than 31 characters, or a string literal with more than
15274 -- 31 characters, and we are operating under VMS
15275
15276 --------------------
15277 -- Check_Too_Long --
15278 --------------------
15279
15280 procedure Check_Too_Long (Arg : Node_Id) is
15281 X : constant Node_Id := Original_Node (Arg);
15282
15283 begin
15284 if not Nkind_In (X, N_String_Literal, N_Identifier) then
15285 Error_Pragma_Arg
15286 ("inappropriate argument for pragma %", Arg);
15287 end if;
15288
15289 if OpenVMS_On_Target then
15290 if (Nkind (X) = N_String_Literal
15291 and then String_Length (Strval (X)) > 31)
15292 or else
15293 (Nkind (X) = N_Identifier
15294 and then Length_Of_Name (Chars (X)) > 31)
15295 then
15296 Error_Pragma_Arg
15297 ("argument for pragma % is longer than 31 characters",
15298 Arg);
15299 end if;
15300 end if;
15301 end Check_Too_Long;
15302
15303 -- Start of processing for Common_Object/Psect_Object
15304
15305 begin
15306 GNAT_Pragma;
15307 Gather_Associations (Names, Args);
15308 Process_Extended_Import_Export_Internal_Arg (Internal);
15309
15310 Def_Id := Entity (Internal);
15311
15312 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
15313 Error_Pragma_Arg
15314 ("pragma% must designate an object", Internal);
15315 end if;
15316
15317 Check_Too_Long (Internal);
15318
15319 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
15320 Error_Pragma_Arg
15321 ("cannot use pragma% for imported/exported object",
15322 Internal);
15323 end if;
15324
15325 if Is_Concurrent_Type (Etype (Internal)) then
15326 Error_Pragma_Arg
15327 ("cannot specify pragma % for task/protected object",
15328 Internal);
15329 end if;
15330
15331 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
15332 or else
15333 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
15334 then
15335 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
15336 end if;
15337
15338 if Ekind (Def_Id) = E_Constant then
15339 Error_Pragma_Arg
15340 ("cannot specify pragma % for a constant", Internal);
15341 end if;
15342
15343 if Is_Record_Type (Etype (Internal)) then
15344 declare
15345 Ent : Entity_Id;
15346 Decl : Entity_Id;
15347
15348 begin
15349 Ent := First_Entity (Etype (Internal));
15350 while Present (Ent) loop
15351 Decl := Declaration_Node (Ent);
15352
15353 if Ekind (Ent) = E_Component
15354 and then Nkind (Decl) = N_Component_Declaration
15355 and then Present (Expression (Decl))
15356 and then Warn_On_Export_Import
15357 then
15358 Error_Msg_N
15359 ("?x?object for pragma % has defaults", Internal);
15360 exit;
15361
15362 else
15363 Next_Entity (Ent);
15364 end if;
15365 end loop;
15366 end;
15367 end if;
15368
15369 if Present (Size) then
15370 Check_Too_Long (Size);
15371 end if;
15372
15373 if Present (External) then
15374 Check_Arg_Is_External_Name (External);
15375 Check_Too_Long (External);
15376 end if;
15377
15378 -- If all error tests pass, link pragma on to the rep item chain
15379
15380 Record_Rep_Item (Def_Id, N);
15381 end Psect_Object;
15382
15383 ----------
15384 -- Pure --
15385 ----------
15386
15387 -- pragma Pure [(library_unit_NAME)];
15388
15389 when Pragma_Pure => Pure : declare
15390 Ent : Entity_Id;
15391
15392 begin
15393 Check_Ada_83_Warning;
15394 Check_Valid_Library_Unit_Pragma;
15395
15396 if Nkind (N) = N_Null_Statement then
15397 return;
15398 end if;
15399
15400 Ent := Find_Lib_Unit_Name;
15401 Set_Is_Pure (Ent);
15402 Set_Has_Pragma_Pure (Ent);
15403 Set_Suppress_Elaboration_Warnings (Ent);
15404 end Pure;
15405
15406 -------------
15407 -- Pure_05 --
15408 -------------
15409
15410 -- pragma Pure_05 [(library_unit_NAME)];
15411
15412 -- This pragma is useable only in GNAT_Mode, where it is used like
15413 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
15414 -- it is ignored). It may be used after a pragma Preelaborate, in
15415 -- which case it overrides the effect of the pragma Preelaborate.
15416 -- This is used to implement AI-362 which recategorizes some run-time
15417 -- packages in Ada 2005 mode.
15418
15419 when Pragma_Pure_05 => Pure_05 : declare
15420 Ent : Entity_Id;
15421
15422 begin
15423 GNAT_Pragma;
15424 Check_Valid_Library_Unit_Pragma;
15425
15426 if not GNAT_Mode then
15427 Error_Pragma ("pragma% only available in GNAT mode");
15428 end if;
15429
15430 if Nkind (N) = N_Null_Statement then
15431 return;
15432 end if;
15433
15434 -- This is one of the few cases where we need to test the value of
15435 -- Ada_Version_Explicit rather than Ada_Version (which is always
15436 -- set to Ada_2012 in a predefined unit), we need to know the
15437 -- explicit version set to know if this pragma is active.
15438
15439 if Ada_Version_Explicit >= Ada_2005 then
15440 Ent := Find_Lib_Unit_Name;
15441 Set_Is_Preelaborated (Ent, False);
15442 Set_Is_Pure (Ent);
15443 Set_Suppress_Elaboration_Warnings (Ent);
15444 end if;
15445 end Pure_05;
15446
15447 -------------
15448 -- Pure_12 --
15449 -------------
15450
15451 -- pragma Pure_12 [(library_unit_NAME)];
15452
15453 -- This pragma is useable only in GNAT_Mode, where it is used like
15454 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
15455 -- it is ignored). It may be used after a pragma Preelaborate, in
15456 -- which case it overrides the effect of the pragma Preelaborate.
15457 -- This is used to implement AI05-0212 which recategorizes some
15458 -- run-time packages in Ada 2012 mode.
15459
15460 when Pragma_Pure_12 => Pure_12 : declare
15461 Ent : Entity_Id;
15462
15463 begin
15464 GNAT_Pragma;
15465 Check_Valid_Library_Unit_Pragma;
15466
15467 if not GNAT_Mode then
15468 Error_Pragma ("pragma% only available in GNAT mode");
15469 end if;
15470
15471 if Nkind (N) = N_Null_Statement then
15472 return;
15473 end if;
15474
15475 -- This is one of the few cases where we need to test the value of
15476 -- Ada_Version_Explicit rather than Ada_Version (which is always
15477 -- set to Ada_2012 in a predefined unit), we need to know the
15478 -- explicit version set to know if this pragma is active.
15479
15480 if Ada_Version_Explicit >= Ada_2012 then
15481 Ent := Find_Lib_Unit_Name;
15482 Set_Is_Preelaborated (Ent, False);
15483 Set_Is_Pure (Ent);
15484 Set_Suppress_Elaboration_Warnings (Ent);
15485 end if;
15486 end Pure_12;
15487
15488 -------------------
15489 -- Pure_Function --
15490 -------------------
15491
15492 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
15493
15494 when Pragma_Pure_Function => Pure_Function : declare
15495 E_Id : Node_Id;
15496 E : Entity_Id;
15497 Def_Id : Entity_Id;
15498 Effective : Boolean := False;
15499
15500 begin
15501 GNAT_Pragma;
15502 Check_Arg_Count (1);
15503 Check_Optional_Identifier (Arg1, Name_Entity);
15504 Check_Arg_Is_Local_Name (Arg1);
15505 E_Id := Get_Pragma_Arg (Arg1);
15506
15507 if Error_Posted (E_Id) then
15508 return;
15509 end if;
15510
15511 -- Loop through homonyms (overloadings) of referenced entity
15512
15513 E := Entity (E_Id);
15514
15515 if Present (E) then
15516 loop
15517 Def_Id := Get_Base_Subprogram (E);
15518
15519 if not Ekind_In (Def_Id, E_Function,
15520 E_Generic_Function,
15521 E_Operator)
15522 then
15523 Error_Pragma_Arg
15524 ("pragma% requires a function name", Arg1);
15525 end if;
15526
15527 Set_Is_Pure (Def_Id);
15528
15529 if not Has_Pragma_Pure_Function (Def_Id) then
15530 Set_Has_Pragma_Pure_Function (Def_Id);
15531 Effective := True;
15532 end if;
15533
15534 exit when From_Aspect_Specification (N);
15535 E := Homonym (E);
15536 exit when No (E) or else Scope (E) /= Current_Scope;
15537 end loop;
15538
15539 if not Effective
15540 and then Warn_On_Redundant_Constructs
15541 then
15542 Error_Msg_NE
15543 ("pragma Pure_Function on& is redundant?r?",
15544 N, Entity (E_Id));
15545 end if;
15546 end if;
15547 end Pure_Function;
15548
15549 --------------------
15550 -- Queuing_Policy --
15551 --------------------
15552
15553 -- pragma Queuing_Policy (policy_IDENTIFIER);
15554
15555 when Pragma_Queuing_Policy => declare
15556 QP : Character;
15557
15558 begin
15559 Check_Ada_83_Warning;
15560 Check_Arg_Count (1);
15561 Check_No_Identifiers;
15562 Check_Arg_Is_Queuing_Policy (Arg1);
15563 Check_Valid_Configuration_Pragma;
15564 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15565 QP := Fold_Upper (Name_Buffer (1));
15566
15567 if Queuing_Policy /= ' '
15568 and then Queuing_Policy /= QP
15569 then
15570 Error_Msg_Sloc := Queuing_Policy_Sloc;
15571 Error_Pragma ("queuing policy incompatible with policy#");
15572
15573 -- Set new policy, but always preserve System_Location since we
15574 -- like the error message with the run time name.
15575
15576 else
15577 Queuing_Policy := QP;
15578
15579 if Queuing_Policy_Sloc /= System_Location then
15580 Queuing_Policy_Sloc := Loc;
15581 end if;
15582 end if;
15583 end;
15584
15585 --------------
15586 -- Rational --
15587 --------------
15588
15589 -- pragma Rational, for compatibility with foreign compiler
15590
15591 when Pragma_Rational =>
15592 Set_Rational_Profile;
15593
15594 -----------------------
15595 -- Relative_Deadline --
15596 -----------------------
15597
15598 -- pragma Relative_Deadline (time_span_EXPRESSION);
15599
15600 when Pragma_Relative_Deadline => Relative_Deadline : declare
15601 P : constant Node_Id := Parent (N);
15602 Arg : Node_Id;
15603
15604 begin
15605 Ada_2005_Pragma;
15606 Check_No_Identifiers;
15607 Check_Arg_Count (1);
15608
15609 Arg := Get_Pragma_Arg (Arg1);
15610
15611 -- The expression must be analyzed in the special manner described
15612 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
15613
15614 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
15615
15616 -- Subprogram case
15617
15618 if Nkind (P) = N_Subprogram_Body then
15619 Check_In_Main_Program;
15620
15621 -- Only Task and subprogram cases allowed
15622
15623 elsif Nkind (P) /= N_Task_Definition then
15624 Pragma_Misplaced;
15625 end if;
15626
15627 -- Check duplicate pragma before we set the corresponding flag
15628
15629 if Has_Relative_Deadline_Pragma (P) then
15630 Error_Pragma ("duplicate pragma% not allowed");
15631 end if;
15632
15633 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
15634 -- Relative_Deadline pragma node cannot be inserted in the Rep
15635 -- Item chain of Ent since it is rewritten by the expander as a
15636 -- procedure call statement that will break the chain.
15637
15638 Set_Has_Relative_Deadline_Pragma (P, True);
15639 end Relative_Deadline;
15640
15641 ------------------------
15642 -- Remote_Access_Type --
15643 ------------------------
15644
15645 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
15646
15647 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
15648 E : Entity_Id;
15649
15650 begin
15651 GNAT_Pragma;
15652 Check_Arg_Count (1);
15653 Check_Optional_Identifier (Arg1, Name_Entity);
15654 Check_Arg_Is_Local_Name (Arg1);
15655
15656 E := Entity (Get_Pragma_Arg (Arg1));
15657
15658 if Nkind (Parent (E)) = N_Formal_Type_Declaration
15659 and then Ekind (E) = E_General_Access_Type
15660 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
15661 and then Scope (Root_Type (Directly_Designated_Type (E)))
15662 = Scope (E)
15663 and then Is_Valid_Remote_Object_Type
15664 (Root_Type (Directly_Designated_Type (E)))
15665 then
15666 Set_Is_Remote_Types (E);
15667
15668 else
15669 Error_Pragma_Arg
15670 ("pragma% applies only to formal access to classwide types",
15671 Arg1);
15672 end if;
15673 end Remote_Access_Type;
15674
15675 ---------------------------
15676 -- Remote_Call_Interface --
15677 ---------------------------
15678
15679 -- pragma Remote_Call_Interface [(library_unit_NAME)];
15680
15681 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
15682 Cunit_Node : Node_Id;
15683 Cunit_Ent : Entity_Id;
15684 K : Node_Kind;
15685
15686 begin
15687 Check_Ada_83_Warning;
15688 Check_Valid_Library_Unit_Pragma;
15689
15690 if Nkind (N) = N_Null_Statement then
15691 return;
15692 end if;
15693
15694 Cunit_Node := Cunit (Current_Sem_Unit);
15695 K := Nkind (Unit (Cunit_Node));
15696 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
15697
15698 if K = N_Package_Declaration
15699 or else K = N_Generic_Package_Declaration
15700 or else K = N_Subprogram_Declaration
15701 or else K = N_Generic_Subprogram_Declaration
15702 or else (K = N_Subprogram_Body
15703 and then Acts_As_Spec (Unit (Cunit_Node)))
15704 then
15705 null;
15706 else
15707 Error_Pragma (
15708 "pragma% must apply to package or subprogram declaration");
15709 end if;
15710
15711 Set_Is_Remote_Call_Interface (Cunit_Ent);
15712 end Remote_Call_Interface;
15713
15714 ------------------
15715 -- Remote_Types --
15716 ------------------
15717
15718 -- pragma Remote_Types [(library_unit_NAME)];
15719
15720 when Pragma_Remote_Types => Remote_Types : declare
15721 Cunit_Node : Node_Id;
15722 Cunit_Ent : Entity_Id;
15723
15724 begin
15725 Check_Ada_83_Warning;
15726 Check_Valid_Library_Unit_Pragma;
15727
15728 if Nkind (N) = N_Null_Statement then
15729 return;
15730 end if;
15731
15732 Cunit_Node := Cunit (Current_Sem_Unit);
15733 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
15734
15735 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
15736 N_Generic_Package_Declaration)
15737 then
15738 Error_Pragma
15739 ("pragma% can only apply to a package declaration");
15740 end if;
15741
15742 Set_Is_Remote_Types (Cunit_Ent);
15743 end Remote_Types;
15744
15745 ---------------
15746 -- Ravenscar --
15747 ---------------
15748
15749 -- pragma Ravenscar;
15750
15751 when Pragma_Ravenscar =>
15752 GNAT_Pragma;
15753 Check_Arg_Count (0);
15754 Check_Valid_Configuration_Pragma;
15755 Set_Ravenscar_Profile (N);
15756
15757 if Warn_On_Obsolescent_Feature then
15758 Error_Msg_N
15759 ("pragma Ravenscar is an obsolescent feature?j?", N);
15760 Error_Msg_N
15761 ("|use pragma Profile (Ravenscar) instead?j?", N);
15762 end if;
15763
15764 -------------------------
15765 -- Restricted_Run_Time --
15766 -------------------------
15767
15768 -- pragma Restricted_Run_Time;
15769
15770 when Pragma_Restricted_Run_Time =>
15771 GNAT_Pragma;
15772 Check_Arg_Count (0);
15773 Check_Valid_Configuration_Pragma;
15774 Set_Profile_Restrictions
15775 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
15776
15777 if Warn_On_Obsolescent_Feature then
15778 Error_Msg_N
15779 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
15780 N);
15781 Error_Msg_N
15782 ("|use pragma Profile (Restricted) instead?j?", N);
15783 end if;
15784
15785 ------------------
15786 -- Restrictions --
15787 ------------------
15788
15789 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
15790
15791 -- RESTRICTION ::=
15792 -- restriction_IDENTIFIER
15793 -- | restriction_parameter_IDENTIFIER => EXPRESSION
15794
15795 when Pragma_Restrictions =>
15796 Process_Restrictions_Or_Restriction_Warnings
15797 (Warn => Treat_Restrictions_As_Warnings);
15798
15799 --------------------------
15800 -- Restriction_Warnings --
15801 --------------------------
15802
15803 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
15804
15805 -- RESTRICTION ::=
15806 -- restriction_IDENTIFIER
15807 -- | restriction_parameter_IDENTIFIER => EXPRESSION
15808
15809 when Pragma_Restriction_Warnings =>
15810 GNAT_Pragma;
15811 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
15812
15813 ----------------
15814 -- Reviewable --
15815 ----------------
15816
15817 -- pragma Reviewable;
15818
15819 when Pragma_Reviewable =>
15820 Check_Ada_83_Warning;
15821 Check_Arg_Count (0);
15822
15823 -- Call dummy debugging function rv. This is done to assist front
15824 -- end debugging. By placing a Reviewable pragma in the source
15825 -- program, a breakpoint on rv catches this place in the source,
15826 -- allowing convenient stepping to the point of interest.
15827
15828 rv;
15829
15830 --------------------------
15831 -- Short_Circuit_And_Or --
15832 --------------------------
15833
15834 when Pragma_Short_Circuit_And_Or =>
15835 GNAT_Pragma;
15836 Check_Arg_Count (0);
15837 Check_Valid_Configuration_Pragma;
15838 Short_Circuit_And_Or := True;
15839
15840 -------------------
15841 -- Share_Generic --
15842 -------------------
15843
15844 -- pragma Share_Generic (NAME {, NAME});
15845
15846 when Pragma_Share_Generic =>
15847 GNAT_Pragma;
15848 Process_Generic_List;
15849
15850 ------------
15851 -- Shared --
15852 ------------
15853
15854 -- pragma Shared (LOCAL_NAME);
15855
15856 when Pragma_Shared =>
15857 GNAT_Pragma;
15858 Process_Atomic_Shared_Volatile;
15859
15860 --------------------
15861 -- Shared_Passive --
15862 --------------------
15863
15864 -- pragma Shared_Passive [(library_unit_NAME)];
15865
15866 -- Set the flag Is_Shared_Passive of program unit name entity
15867
15868 when Pragma_Shared_Passive => Shared_Passive : declare
15869 Cunit_Node : Node_Id;
15870 Cunit_Ent : Entity_Id;
15871
15872 begin
15873 Check_Ada_83_Warning;
15874 Check_Valid_Library_Unit_Pragma;
15875
15876 if Nkind (N) = N_Null_Statement then
15877 return;
15878 end if;
15879
15880 Cunit_Node := Cunit (Current_Sem_Unit);
15881 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
15882
15883 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
15884 N_Generic_Package_Declaration)
15885 then
15886 Error_Pragma
15887 ("pragma% can only apply to a package declaration");
15888 end if;
15889
15890 Set_Is_Shared_Passive (Cunit_Ent);
15891 end Shared_Passive;
15892
15893 -----------------------
15894 -- Short_Descriptors --
15895 -----------------------
15896
15897 -- pragma Short_Descriptors;
15898
15899 when Pragma_Short_Descriptors =>
15900 GNAT_Pragma;
15901 Check_Arg_Count (0);
15902 Check_Valid_Configuration_Pragma;
15903 Short_Descriptors := True;
15904
15905 ------------------------------
15906 -- Simple_Storage_Pool_Type --
15907 ------------------------------
15908
15909 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
15910
15911 when Pragma_Simple_Storage_Pool_Type =>
15912 Simple_Storage_Pool_Type : declare
15913 Type_Id : Node_Id;
15914 Typ : Entity_Id;
15915
15916 begin
15917 GNAT_Pragma;
15918 Check_Arg_Count (1);
15919 Check_Arg_Is_Library_Level_Local_Name (Arg1);
15920
15921 Type_Id := Get_Pragma_Arg (Arg1);
15922 Find_Type (Type_Id);
15923 Typ := Entity (Type_Id);
15924
15925 if Typ = Any_Type then
15926 return;
15927 end if;
15928
15929 -- We require the pragma to apply to a type declared in a package
15930 -- declaration, but not (immediately) within a package body.
15931
15932 if Ekind (Current_Scope) /= E_Package
15933 or else In_Package_Body (Current_Scope)
15934 then
15935 Error_Pragma
15936 ("pragma% can only apply to type declared immediately "
15937 & "within a package declaration");
15938 end if;
15939
15940 -- A simple storage pool type must be an immutably limited record
15941 -- or private type. If the pragma is given for a private type,
15942 -- the full type is similarly restricted (which is checked later
15943 -- in Freeze_Entity).
15944
15945 if Is_Record_Type (Typ)
15946 and then not Is_Immutably_Limited_Type (Typ)
15947 then
15948 Error_Pragma
15949 ("pragma% can only apply to explicitly limited record type");
15950
15951 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
15952 Error_Pragma
15953 ("pragma% can only apply to a private type that is limited");
15954
15955 elsif not Is_Record_Type (Typ)
15956 and then not Is_Private_Type (Typ)
15957 then
15958 Error_Pragma
15959 ("pragma% can only apply to limited record or private type");
15960 end if;
15961
15962 Record_Rep_Item (Typ, N);
15963 end Simple_Storage_Pool_Type;
15964
15965 ----------------------
15966 -- Source_File_Name --
15967 ----------------------
15968
15969 -- There are five forms for this pragma:
15970
15971 -- pragma Source_File_Name (
15972 -- [UNIT_NAME =>] unit_NAME,
15973 -- BODY_FILE_NAME => STRING_LITERAL
15974 -- [, [INDEX =>] INTEGER_LITERAL]);
15975
15976 -- pragma Source_File_Name (
15977 -- [UNIT_NAME =>] unit_NAME,
15978 -- SPEC_FILE_NAME => STRING_LITERAL
15979 -- [, [INDEX =>] INTEGER_LITERAL]);
15980
15981 -- pragma Source_File_Name (
15982 -- BODY_FILE_NAME => STRING_LITERAL
15983 -- [, DOT_REPLACEMENT => STRING_LITERAL]
15984 -- [, CASING => CASING_SPEC]);
15985
15986 -- pragma Source_File_Name (
15987 -- SPEC_FILE_NAME => STRING_LITERAL
15988 -- [, DOT_REPLACEMENT => STRING_LITERAL]
15989 -- [, CASING => CASING_SPEC]);
15990
15991 -- pragma Source_File_Name (
15992 -- SUBUNIT_FILE_NAME => STRING_LITERAL
15993 -- [, DOT_REPLACEMENT => STRING_LITERAL]
15994 -- [, CASING => CASING_SPEC]);
15995
15996 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
15997
15998 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
15999 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
16000 -- only be used when no project file is used, while SFNP can only be
16001 -- used when a project file is used.
16002
16003 -- No processing here. Processing was completed during parsing, since
16004 -- we need to have file names set as early as possible. Units are
16005 -- loaded well before semantic processing starts.
16006
16007 -- The only processing we defer to this point is the check for
16008 -- correct placement.
16009
16010 when Pragma_Source_File_Name =>
16011 GNAT_Pragma;
16012 Check_Valid_Configuration_Pragma;
16013
16014 ------------------------------
16015 -- Source_File_Name_Project --
16016 ------------------------------
16017
16018 -- See Source_File_Name for syntax
16019
16020 -- No processing here. Processing was completed during parsing, since
16021 -- we need to have file names set as early as possible. Units are
16022 -- loaded well before semantic processing starts.
16023
16024 -- The only processing we defer to this point is the check for
16025 -- correct placement.
16026
16027 when Pragma_Source_File_Name_Project =>
16028 GNAT_Pragma;
16029 Check_Valid_Configuration_Pragma;
16030
16031 -- Check that a pragma Source_File_Name_Project is used only in a
16032 -- configuration pragmas file.
16033
16034 -- Pragmas Source_File_Name_Project should only be generated by
16035 -- the Project Manager in configuration pragmas files.
16036
16037 -- This is really an ugly test. It seems to depend on some
16038 -- accidental and undocumented property. At the very least it
16039 -- needs to be documented, but it would be better to have a
16040 -- clean way of testing if we are in a configuration file???
16041
16042 if Present (Parent (N)) then
16043 Error_Pragma
16044 ("pragma% can only appear in a configuration pragmas file");
16045 end if;
16046
16047 ----------------------
16048 -- Source_Reference --
16049 ----------------------
16050
16051 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
16052
16053 -- Nothing to do, all processing completed in Par.Prag, since we need
16054 -- the information for possible parser messages that are output.
16055
16056 when Pragma_Source_Reference =>
16057 GNAT_Pragma;
16058
16059 --------------------------------
16060 -- Static_Elaboration_Desired --
16061 --------------------------------
16062
16063 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
16064
16065 when Pragma_Static_Elaboration_Desired =>
16066 GNAT_Pragma;
16067 Check_At_Most_N_Arguments (1);
16068
16069 if Is_Compilation_Unit (Current_Scope)
16070 and then Ekind (Current_Scope) = E_Package
16071 then
16072 Set_Static_Elaboration_Desired (Current_Scope, True);
16073 else
16074 Error_Pragma ("pragma% must apply to a library-level package");
16075 end if;
16076
16077 ------------------
16078 -- Storage_Size --
16079 ------------------
16080
16081 -- pragma Storage_Size (EXPRESSION);
16082
16083 when Pragma_Storage_Size => Storage_Size : declare
16084 P : constant Node_Id := Parent (N);
16085 Arg : Node_Id;
16086
16087 begin
16088 Check_No_Identifiers;
16089 Check_Arg_Count (1);
16090
16091 -- The expression must be analyzed in the special manner described
16092 -- in "Handling of Default Expressions" in sem.ads.
16093
16094 Arg := Get_Pragma_Arg (Arg1);
16095 Preanalyze_Spec_Expression (Arg, Any_Integer);
16096
16097 if not Is_Static_Expression (Arg) then
16098 Check_Restriction (Static_Storage_Size, Arg);
16099 end if;
16100
16101 if Nkind (P) /= N_Task_Definition then
16102 Pragma_Misplaced;
16103 return;
16104
16105 else
16106 if Has_Storage_Size_Pragma (P) then
16107 Error_Pragma ("duplicate pragma% not allowed");
16108 else
16109 Set_Has_Storage_Size_Pragma (P, True);
16110 end if;
16111
16112 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
16113 end if;
16114 end Storage_Size;
16115
16116 ------------------
16117 -- Storage_Unit --
16118 ------------------
16119
16120 -- pragma Storage_Unit (NUMERIC_LITERAL);
16121
16122 -- Only permitted argument is System'Storage_Unit value
16123
16124 when Pragma_Storage_Unit =>
16125 Check_No_Identifiers;
16126 Check_Arg_Count (1);
16127 Check_Arg_Is_Integer_Literal (Arg1);
16128
16129 if Intval (Get_Pragma_Arg (Arg1)) /=
16130 UI_From_Int (Ttypes.System_Storage_Unit)
16131 then
16132 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
16133 Error_Pragma_Arg
16134 ("the only allowed argument for pragma% is ^", Arg1);
16135 end if;
16136
16137 --------------------
16138 -- Stream_Convert --
16139 --------------------
16140
16141 -- pragma Stream_Convert (
16142 -- [Entity =>] type_LOCAL_NAME,
16143 -- [Read =>] function_NAME,
16144 -- [Write =>] function NAME);
16145
16146 when Pragma_Stream_Convert => Stream_Convert : declare
16147
16148 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
16149 -- Check that the given argument is the name of a local function
16150 -- of one argument that is not overloaded earlier in the current
16151 -- local scope. A check is also made that the argument is a
16152 -- function with one parameter.
16153
16154 --------------------------------------
16155 -- Check_OK_Stream_Convert_Function --
16156 --------------------------------------
16157
16158 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
16159 Ent : Entity_Id;
16160
16161 begin
16162 Check_Arg_Is_Local_Name (Arg);
16163 Ent := Entity (Get_Pragma_Arg (Arg));
16164
16165 if Has_Homonym (Ent) then
16166 Error_Pragma_Arg
16167 ("argument for pragma% may not be overloaded", Arg);
16168 end if;
16169
16170 if Ekind (Ent) /= E_Function
16171 or else No (First_Formal (Ent))
16172 or else Present (Next_Formal (First_Formal (Ent)))
16173 then
16174 Error_Pragma_Arg
16175 ("argument for pragma% must be function of one argument",
16176 Arg);
16177 end if;
16178 end Check_OK_Stream_Convert_Function;
16179
16180 -- Start of processing for Stream_Convert
16181
16182 begin
16183 GNAT_Pragma;
16184 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
16185 Check_Arg_Count (3);
16186 Check_Optional_Identifier (Arg1, Name_Entity);
16187 Check_Optional_Identifier (Arg2, Name_Read);
16188 Check_Optional_Identifier (Arg3, Name_Write);
16189 Check_Arg_Is_Local_Name (Arg1);
16190 Check_OK_Stream_Convert_Function (Arg2);
16191 Check_OK_Stream_Convert_Function (Arg3);
16192
16193 declare
16194 Typ : constant Entity_Id :=
16195 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
16196 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
16197 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
16198
16199 begin
16200 Check_First_Subtype (Arg1);
16201
16202 -- Check for too early or too late. Note that we don't enforce
16203 -- the rule about primitive operations in this case, since, as
16204 -- is the case for explicit stream attributes themselves, these
16205 -- restrictions are not appropriate. Note that the chaining of
16206 -- the pragma by Rep_Item_Too_Late is actually the critical
16207 -- processing done for this pragma.
16208
16209 if Rep_Item_Too_Early (Typ, N)
16210 or else
16211 Rep_Item_Too_Late (Typ, N, FOnly => True)
16212 then
16213 return;
16214 end if;
16215
16216 -- Return if previous error
16217
16218 if Etype (Typ) = Any_Type
16219 or else
16220 Etype (Read) = Any_Type
16221 or else
16222 Etype (Write) = Any_Type
16223 then
16224 return;
16225 end if;
16226
16227 -- Error checks
16228
16229 if Underlying_Type (Etype (Read)) /= Typ then
16230 Error_Pragma_Arg
16231 ("incorrect return type for function&", Arg2);
16232 end if;
16233
16234 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
16235 Error_Pragma_Arg
16236 ("incorrect parameter type for function&", Arg3);
16237 end if;
16238
16239 if Underlying_Type (Etype (First_Formal (Read))) /=
16240 Underlying_Type (Etype (Write))
16241 then
16242 Error_Pragma_Arg
16243 ("result type of & does not match Read parameter type",
16244 Arg3);
16245 end if;
16246 end;
16247 end Stream_Convert;
16248
16249 ------------------
16250 -- Style_Checks --
16251 ------------------
16252
16253 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
16254
16255 -- This is processed by the parser since some of the style checks
16256 -- take place during source scanning and parsing. This means that
16257 -- we don't need to issue error messages here.
16258
16259 when Pragma_Style_Checks => Style_Checks : declare
16260 A : constant Node_Id := Get_Pragma_Arg (Arg1);
16261 S : String_Id;
16262 C : Char_Code;
16263
16264 begin
16265 GNAT_Pragma;
16266 Check_No_Identifiers;
16267
16268 -- Two argument form
16269
16270 if Arg_Count = 2 then
16271 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
16272
16273 declare
16274 E_Id : Node_Id;
16275 E : Entity_Id;
16276
16277 begin
16278 E_Id := Get_Pragma_Arg (Arg2);
16279 Analyze (E_Id);
16280
16281 if not Is_Entity_Name (E_Id) then
16282 Error_Pragma_Arg
16283 ("second argument of pragma% must be entity name",
16284 Arg2);
16285 end if;
16286
16287 E := Entity (E_Id);
16288
16289 if not Ignore_Style_Checks_Pragmas then
16290 if E = Any_Id then
16291 return;
16292 else
16293 loop
16294 Set_Suppress_Style_Checks
16295 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
16296 exit when No (Homonym (E));
16297 E := Homonym (E);
16298 end loop;
16299 end if;
16300 end if;
16301 end;
16302
16303 -- One argument form
16304
16305 else
16306 Check_Arg_Count (1);
16307
16308 if Nkind (A) = N_String_Literal then
16309 S := Strval (A);
16310
16311 declare
16312 Slen : constant Natural := Natural (String_Length (S));
16313 Options : String (1 .. Slen);
16314 J : Natural;
16315
16316 begin
16317 J := 1;
16318 loop
16319 C := Get_String_Char (S, Int (J));
16320 exit when not In_Character_Range (C);
16321 Options (J) := Get_Character (C);
16322
16323 -- If at end of string, set options. As per discussion
16324 -- above, no need to check for errors, since we issued
16325 -- them in the parser.
16326
16327 if J = Slen then
16328 if not Ignore_Style_Checks_Pragmas then
16329 Set_Style_Check_Options (Options);
16330 end if;
16331
16332 exit;
16333 end if;
16334
16335 J := J + 1;
16336 end loop;
16337 end;
16338
16339 elsif Nkind (A) = N_Identifier then
16340 if Chars (A) = Name_All_Checks then
16341 if not Ignore_Style_Checks_Pragmas then
16342 if GNAT_Mode then
16343 Set_GNAT_Style_Check_Options;
16344 else
16345 Set_Default_Style_Check_Options;
16346 end if;
16347 end if;
16348
16349 elsif Chars (A) = Name_On then
16350 if not Ignore_Style_Checks_Pragmas then
16351 Style_Check := True;
16352 end if;
16353
16354 elsif Chars (A) = Name_Off then
16355 if not Ignore_Style_Checks_Pragmas then
16356 Style_Check := False;
16357 end if;
16358 end if;
16359 end if;
16360 end if;
16361 end Style_Checks;
16362
16363 --------------
16364 -- Subtitle --
16365 --------------
16366
16367 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
16368
16369 when Pragma_Subtitle =>
16370 GNAT_Pragma;
16371 Check_Arg_Count (1);
16372 Check_Optional_Identifier (Arg1, Name_Subtitle);
16373 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
16374 Store_Note (N);
16375
16376 --------------
16377 -- Suppress --
16378 --------------
16379
16380 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
16381
16382 when Pragma_Suppress =>
16383 Process_Suppress_Unsuppress (True);
16384
16385 ------------------
16386 -- Suppress_All --
16387 ------------------
16388
16389 -- pragma Suppress_All;
16390
16391 -- The only check made here is that the pragma has no arguments.
16392 -- There are no placement rules, and the processing required (setting
16393 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
16394 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
16395 -- then creates and inserts a pragma Suppress (All_Checks).
16396
16397 when Pragma_Suppress_All =>
16398 GNAT_Pragma;
16399 Check_Arg_Count (0);
16400
16401 -------------------------
16402 -- Suppress_Debug_Info --
16403 -------------------------
16404
16405 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
16406
16407 when Pragma_Suppress_Debug_Info =>
16408 GNAT_Pragma;
16409 Check_Arg_Count (1);
16410 Check_Optional_Identifier (Arg1, Name_Entity);
16411 Check_Arg_Is_Local_Name (Arg1);
16412 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
16413
16414 ----------------------------------
16415 -- Suppress_Exception_Locations --
16416 ----------------------------------
16417
16418 -- pragma Suppress_Exception_Locations;
16419
16420 when Pragma_Suppress_Exception_Locations =>
16421 GNAT_Pragma;
16422 Check_Arg_Count (0);
16423 Check_Valid_Configuration_Pragma;
16424 Exception_Locations_Suppressed := True;
16425
16426 -----------------------------
16427 -- Suppress_Initialization --
16428 -----------------------------
16429
16430 -- pragma Suppress_Initialization ([Entity =>] type_Name);
16431
16432 when Pragma_Suppress_Initialization => Suppress_Init : declare
16433 E_Id : Node_Id;
16434 E : Entity_Id;
16435
16436 begin
16437 GNAT_Pragma;
16438 Check_Arg_Count (1);
16439 Check_Optional_Identifier (Arg1, Name_Entity);
16440 Check_Arg_Is_Local_Name (Arg1);
16441
16442 E_Id := Get_Pragma_Arg (Arg1);
16443
16444 if Etype (E_Id) = Any_Type then
16445 return;
16446 end if;
16447
16448 E := Entity (E_Id);
16449
16450 if not Is_Type (E) then
16451 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
16452 end if;
16453
16454 if Rep_Item_Too_Early (E, N)
16455 or else
16456 Rep_Item_Too_Late (E, N, FOnly => True)
16457 then
16458 return;
16459 end if;
16460
16461 -- For incomplete/private type, set flag on full view
16462
16463 if Is_Incomplete_Or_Private_Type (E) then
16464 if No (Full_View (Base_Type (E))) then
16465 Error_Pragma_Arg
16466 ("argument of pragma% cannot be an incomplete type", Arg1);
16467 else
16468 Set_Suppress_Initialization (Full_View (Base_Type (E)));
16469 end if;
16470
16471 -- For first subtype, set flag on base type
16472
16473 elsif Is_First_Subtype (E) then
16474 Set_Suppress_Initialization (Base_Type (E));
16475
16476 -- For other than first subtype, set flag on subtype itself
16477
16478 else
16479 Set_Suppress_Initialization (E);
16480 end if;
16481 end Suppress_Init;
16482
16483 -----------------
16484 -- System_Name --
16485 -----------------
16486
16487 -- pragma System_Name (DIRECT_NAME);
16488
16489 -- Syntax check: one argument, which must be the identifier GNAT or
16490 -- the identifier GCC, no other identifiers are acceptable.
16491
16492 when Pragma_System_Name =>
16493 GNAT_Pragma;
16494 Check_No_Identifiers;
16495 Check_Arg_Count (1);
16496 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
16497
16498 -----------------------------
16499 -- Task_Dispatching_Policy --
16500 -----------------------------
16501
16502 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
16503
16504 when Pragma_Task_Dispatching_Policy => declare
16505 DP : Character;
16506
16507 begin
16508 Check_Ada_83_Warning;
16509 Check_Arg_Count (1);
16510 Check_No_Identifiers;
16511 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
16512 Check_Valid_Configuration_Pragma;
16513 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
16514 DP := Fold_Upper (Name_Buffer (1));
16515
16516 if Task_Dispatching_Policy /= ' '
16517 and then Task_Dispatching_Policy /= DP
16518 then
16519 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
16520 Error_Pragma
16521 ("task dispatching policy incompatible with policy#");
16522
16523 -- Set new policy, but always preserve System_Location since we
16524 -- like the error message with the run time name.
16525
16526 else
16527 Task_Dispatching_Policy := DP;
16528
16529 if Task_Dispatching_Policy_Sloc /= System_Location then
16530 Task_Dispatching_Policy_Sloc := Loc;
16531 end if;
16532 end if;
16533 end;
16534
16535 ---------------
16536 -- Task_Info --
16537 ---------------
16538
16539 -- pragma Task_Info (EXPRESSION);
16540
16541 when Pragma_Task_Info => Task_Info : declare
16542 P : constant Node_Id := Parent (N);
16543 Ent : Entity_Id;
16544
16545 begin
16546 GNAT_Pragma;
16547
16548 if Nkind (P) /= N_Task_Definition then
16549 Error_Pragma ("pragma% must appear in task definition");
16550 end if;
16551
16552 Check_No_Identifiers;
16553 Check_Arg_Count (1);
16554
16555 Analyze_And_Resolve
16556 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
16557
16558 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
16559 return;
16560 end if;
16561
16562 Ent := Defining_Identifier (Parent (P));
16563
16564 -- Check duplicate pragma before we chain the pragma in the Rep
16565 -- Item chain of Ent.
16566
16567 if Has_Rep_Pragma
16568 (Ent, Name_Task_Info, Check_Parents => False)
16569 then
16570 Error_Pragma ("duplicate pragma% not allowed");
16571 end if;
16572
16573 Record_Rep_Item (Ent, N);
16574 end Task_Info;
16575
16576 ---------------
16577 -- Task_Name --
16578 ---------------
16579
16580 -- pragma Task_Name (string_EXPRESSION);
16581
16582 when Pragma_Task_Name => Task_Name : declare
16583 P : constant Node_Id := Parent (N);
16584 Arg : Node_Id;
16585 Ent : Entity_Id;
16586
16587 begin
16588 Check_No_Identifiers;
16589 Check_Arg_Count (1);
16590
16591 Arg := Get_Pragma_Arg (Arg1);
16592
16593 -- The expression is used in the call to Create_Task, and must be
16594 -- expanded there, not in the context of the current spec. It must
16595 -- however be analyzed to capture global references, in case it
16596 -- appears in a generic context.
16597
16598 Preanalyze_And_Resolve (Arg, Standard_String);
16599
16600 if Nkind (P) /= N_Task_Definition then
16601 Pragma_Misplaced;
16602 end if;
16603
16604 Ent := Defining_Identifier (Parent (P));
16605
16606 -- Check duplicate pragma before we chain the pragma in the Rep
16607 -- Item chain of Ent.
16608
16609 if Has_Rep_Pragma
16610 (Ent, Name_Task_Name, Check_Parents => False)
16611 then
16612 Error_Pragma ("duplicate pragma% not allowed");
16613 end if;
16614
16615 Record_Rep_Item (Ent, N);
16616 end Task_Name;
16617
16618 ------------------
16619 -- Task_Storage --
16620 ------------------
16621
16622 -- pragma Task_Storage (
16623 -- [Task_Type =>] LOCAL_NAME,
16624 -- [Top_Guard =>] static_integer_EXPRESSION);
16625
16626 when Pragma_Task_Storage => Task_Storage : declare
16627 Args : Args_List (1 .. 2);
16628 Names : constant Name_List (1 .. 2) := (
16629 Name_Task_Type,
16630 Name_Top_Guard);
16631
16632 Task_Type : Node_Id renames Args (1);
16633 Top_Guard : Node_Id renames Args (2);
16634
16635 Ent : Entity_Id;
16636
16637 begin
16638 GNAT_Pragma;
16639 Gather_Associations (Names, Args);
16640
16641 if No (Task_Type) then
16642 Error_Pragma
16643 ("missing task_type argument for pragma%");
16644 end if;
16645
16646 Check_Arg_Is_Local_Name (Task_Type);
16647
16648 Ent := Entity (Task_Type);
16649
16650 if not Is_Task_Type (Ent) then
16651 Error_Pragma_Arg
16652 ("argument for pragma% must be task type", Task_Type);
16653 end if;
16654
16655 if No (Top_Guard) then
16656 Error_Pragma_Arg
16657 ("pragma% takes two arguments", Task_Type);
16658 else
16659 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
16660 end if;
16661
16662 Check_First_Subtype (Task_Type);
16663
16664 if Rep_Item_Too_Late (Ent, N) then
16665 raise Pragma_Exit;
16666 end if;
16667 end Task_Storage;
16668
16669 ---------------
16670 -- Test_Case --
16671 ---------------
16672
16673 -- pragma Test_Case
16674 -- ([Name =>] Static_String_EXPRESSION
16675 -- ,[Mode =>] MODE_TYPE
16676 -- [, Requires => Boolean_EXPRESSION]
16677 -- [, Ensures => Boolean_EXPRESSION]);
16678
16679 -- MODE_TYPE ::= Nominal | Robustness
16680
16681 when Pragma_Test_Case =>
16682 Check_Contract_Or_Test_Case;
16683
16684 --------------------------
16685 -- Thread_Local_Storage --
16686 --------------------------
16687
16688 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
16689
16690 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
16691 Id : Node_Id;
16692 E : Entity_Id;
16693
16694 begin
16695 GNAT_Pragma;
16696 Check_Arg_Count (1);
16697 Check_Optional_Identifier (Arg1, Name_Entity);
16698 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16699
16700 Id := Get_Pragma_Arg (Arg1);
16701 Analyze (Id);
16702
16703 if not Is_Entity_Name (Id)
16704 or else Ekind (Entity (Id)) /= E_Variable
16705 then
16706 Error_Pragma_Arg ("local variable name required", Arg1);
16707 end if;
16708
16709 E := Entity (Id);
16710
16711 if Rep_Item_Too_Early (E, N)
16712 or else Rep_Item_Too_Late (E, N)
16713 then
16714 raise Pragma_Exit;
16715 end if;
16716
16717 Set_Has_Pragma_Thread_Local_Storage (E);
16718 Set_Has_Gigi_Rep_Item (E);
16719 end Thread_Local_Storage;
16720
16721 ----------------
16722 -- Time_Slice --
16723 ----------------
16724
16725 -- pragma Time_Slice (static_duration_EXPRESSION);
16726
16727 when Pragma_Time_Slice => Time_Slice : declare
16728 Val : Ureal;
16729 Nod : Node_Id;
16730
16731 begin
16732 GNAT_Pragma;
16733 Check_Arg_Count (1);
16734 Check_No_Identifiers;
16735 Check_In_Main_Program;
16736 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
16737
16738 if not Error_Posted (Arg1) then
16739 Nod := Next (N);
16740 while Present (Nod) loop
16741 if Nkind (Nod) = N_Pragma
16742 and then Pragma_Name (Nod) = Name_Time_Slice
16743 then
16744 Error_Msg_Name_1 := Pname;
16745 Error_Msg_N ("duplicate pragma% not permitted", Nod);
16746 end if;
16747
16748 Next (Nod);
16749 end loop;
16750 end if;
16751
16752 -- Process only if in main unit
16753
16754 if Get_Source_Unit (Loc) = Main_Unit then
16755 Opt.Time_Slice_Set := True;
16756 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
16757
16758 if Val <= Ureal_0 then
16759 Opt.Time_Slice_Value := 0;
16760
16761 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
16762 Opt.Time_Slice_Value := 1_000_000_000;
16763
16764 else
16765 Opt.Time_Slice_Value :=
16766 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
16767 end if;
16768 end if;
16769 end Time_Slice;
16770
16771 -----------
16772 -- Title --
16773 -----------
16774
16775 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
16776
16777 -- TITLING_OPTION ::=
16778 -- [Title =>] STRING_LITERAL
16779 -- | [Subtitle =>] STRING_LITERAL
16780
16781 when Pragma_Title => Title : declare
16782 Args : Args_List (1 .. 2);
16783 Names : constant Name_List (1 .. 2) := (
16784 Name_Title,
16785 Name_Subtitle);
16786
16787 begin
16788 GNAT_Pragma;
16789 Gather_Associations (Names, Args);
16790 Store_Note (N);
16791
16792 for J in 1 .. 2 loop
16793 if Present (Args (J)) then
16794 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
16795 end if;
16796 end loop;
16797 end Title;
16798
16799 ---------------------
16800 -- Unchecked_Union --
16801 ---------------------
16802
16803 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
16804
16805 when Pragma_Unchecked_Union => Unchecked_Union : declare
16806 Assoc : constant Node_Id := Arg1;
16807 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
16808 Typ : Entity_Id;
16809 Tdef : Node_Id;
16810 Clist : Node_Id;
16811 Vpart : Node_Id;
16812 Comp : Node_Id;
16813 Variant : Node_Id;
16814
16815 begin
16816 Ada_2005_Pragma;
16817 Check_No_Identifiers;
16818 Check_Arg_Count (1);
16819 Check_Arg_Is_Local_Name (Arg1);
16820
16821 Find_Type (Type_Id);
16822
16823 Typ := Entity (Type_Id);
16824
16825 if Typ = Any_Type
16826 or else Rep_Item_Too_Early (Typ, N)
16827 then
16828 return;
16829 else
16830 Typ := Underlying_Type (Typ);
16831 end if;
16832
16833 if Rep_Item_Too_Late (Typ, N) then
16834 return;
16835 end if;
16836
16837 Check_First_Subtype (Arg1);
16838
16839 -- Note remaining cases are references to a type in the current
16840 -- declarative part. If we find an error, we post the error on
16841 -- the relevant type declaration at an appropriate point.
16842
16843 if not Is_Record_Type (Typ) then
16844 Error_Msg_N ("unchecked union must be record type", Typ);
16845 return;
16846
16847 elsif Is_Tagged_Type (Typ) then
16848 Error_Msg_N ("unchecked union must not be tagged", Typ);
16849 return;
16850
16851 elsif not Has_Discriminants (Typ) then
16852 Error_Msg_N
16853 ("unchecked union must have one discriminant", Typ);
16854 return;
16855
16856 -- Note: in previous versions of GNAT we used to check for limited
16857 -- types and give an error, but in fact the standard does allow
16858 -- Unchecked_Union on limited types, so this check was removed.
16859
16860 -- Similarly, GNAT used to require that all discriminants have
16861 -- default values, but this is not mandated by the RM.
16862
16863 -- Proceed with basic error checks completed
16864
16865 else
16866 Tdef := Type_Definition (Declaration_Node (Typ));
16867 Clist := Component_List (Tdef);
16868
16869 -- Check presence of component list and variant part
16870
16871 if No (Clist) or else No (Variant_Part (Clist)) then
16872 Error_Msg_N
16873 ("unchecked union must have variant part", Tdef);
16874 return;
16875 end if;
16876
16877 -- Check components
16878
16879 Comp := First (Component_Items (Clist));
16880 while Present (Comp) loop
16881 Check_Component (Comp, Typ);
16882 Next (Comp);
16883 end loop;
16884
16885 -- Check variant part
16886
16887 Vpart := Variant_Part (Clist);
16888
16889 Variant := First (Variants (Vpart));
16890 while Present (Variant) loop
16891 Check_Variant (Variant, Typ);
16892 Next (Variant);
16893 end loop;
16894 end if;
16895
16896 Set_Is_Unchecked_Union (Typ);
16897 Set_Convention (Typ, Convention_C);
16898 Set_Has_Unchecked_Union (Base_Type (Typ));
16899 Set_Is_Unchecked_Union (Base_Type (Typ));
16900 end Unchecked_Union;
16901
16902 ------------------------
16903 -- Unimplemented_Unit --
16904 ------------------------
16905
16906 -- pragma Unimplemented_Unit;
16907
16908 -- Note: this only gives an error if we are generating code, or if
16909 -- we are in a generic library unit (where the pragma appears in the
16910 -- body, not in the spec).
16911
16912 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
16913 Cunitent : constant Entity_Id :=
16914 Cunit_Entity (Get_Source_Unit (Loc));
16915 Ent_Kind : constant Entity_Kind :=
16916 Ekind (Cunitent);
16917
16918 begin
16919 GNAT_Pragma;
16920 Check_Arg_Count (0);
16921
16922 if Operating_Mode = Generate_Code
16923 or else Ent_Kind = E_Generic_Function
16924 or else Ent_Kind = E_Generic_Procedure
16925 or else Ent_Kind = E_Generic_Package
16926 then
16927 Get_Name_String (Chars (Cunitent));
16928 Set_Casing (Mixed_Case);
16929 Write_Str (Name_Buffer (1 .. Name_Len));
16930 Write_Str (" is not supported in this configuration");
16931 Write_Eol;
16932 raise Unrecoverable_Error;
16933 end if;
16934 end Unimplemented_Unit;
16935
16936 ------------------------
16937 -- Universal_Aliasing --
16938 ------------------------
16939
16940 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
16941
16942 when Pragma_Universal_Aliasing => Universal_Alias : declare
16943 E_Id : Entity_Id;
16944
16945 begin
16946 GNAT_Pragma;
16947 Check_Arg_Count (1);
16948 Check_Optional_Identifier (Arg2, Name_Entity);
16949 Check_Arg_Is_Local_Name (Arg1);
16950 E_Id := Entity (Get_Pragma_Arg (Arg1));
16951
16952 if E_Id = Any_Type then
16953 return;
16954 elsif No (E_Id) or else not Is_Type (E_Id) then
16955 Error_Pragma_Arg ("pragma% requires type", Arg1);
16956 end if;
16957
16958 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
16959 Record_Rep_Item (E_Id, N);
16960 end Universal_Alias;
16961
16962 --------------------
16963 -- Universal_Data --
16964 --------------------
16965
16966 -- pragma Universal_Data [(library_unit_NAME)];
16967
16968 when Pragma_Universal_Data =>
16969 GNAT_Pragma;
16970
16971 -- If this is a configuration pragma, then set the universal
16972 -- addressing option, otherwise confirm that the pragma satisfies
16973 -- the requirements of library unit pragma placement and leave it
16974 -- to the GNAAMP back end to detect the pragma (avoids transitive
16975 -- setting of the option due to withed units).
16976
16977 if Is_Configuration_Pragma then
16978 Universal_Addressing_On_AAMP := True;
16979 else
16980 Check_Valid_Library_Unit_Pragma;
16981 end if;
16982
16983 if not AAMP_On_Target then
16984 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
16985 end if;
16986
16987 ----------------
16988 -- Unmodified --
16989 ----------------
16990
16991 -- pragma Unmodified (local_Name {, local_Name});
16992
16993 when Pragma_Unmodified => Unmodified : declare
16994 Arg_Node : Node_Id;
16995 Arg_Expr : Node_Id;
16996 Arg_Ent : Entity_Id;
16997
16998 begin
16999 GNAT_Pragma;
17000 Check_At_Least_N_Arguments (1);
17001
17002 -- Loop through arguments
17003
17004 Arg_Node := Arg1;
17005 while Present (Arg_Node) loop
17006 Check_No_Identifier (Arg_Node);
17007
17008 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
17009 -- in fact generate reference, so that the entity will have a
17010 -- reference, which will inhibit any warnings about it not
17011 -- being referenced, and also properly show up in the ali file
17012 -- as a reference. But this reference is recorded before the
17013 -- Has_Pragma_Unreferenced flag is set, so that no warning is
17014 -- generated for this reference.
17015
17016 Check_Arg_Is_Local_Name (Arg_Node);
17017 Arg_Expr := Get_Pragma_Arg (Arg_Node);
17018
17019 if Is_Entity_Name (Arg_Expr) then
17020 Arg_Ent := Entity (Arg_Expr);
17021
17022 if not Is_Assignable (Arg_Ent) then
17023 Error_Pragma_Arg
17024 ("pragma% can only be applied to a variable",
17025 Arg_Expr);
17026 else
17027 Set_Has_Pragma_Unmodified (Arg_Ent);
17028 end if;
17029 end if;
17030
17031 Next (Arg_Node);
17032 end loop;
17033 end Unmodified;
17034
17035 ------------------
17036 -- Unreferenced --
17037 ------------------
17038
17039 -- pragma Unreferenced (local_Name {, local_Name});
17040
17041 -- or when used in a context clause:
17042
17043 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
17044
17045 when Pragma_Unreferenced => Unreferenced : declare
17046 Arg_Node : Node_Id;
17047 Arg_Expr : Node_Id;
17048 Arg_Ent : Entity_Id;
17049 Citem : Node_Id;
17050
17051 begin
17052 GNAT_Pragma;
17053 Check_At_Least_N_Arguments (1);
17054
17055 -- Check case of appearing within context clause
17056
17057 if Is_In_Context_Clause then
17058
17059 -- The arguments must all be units mentioned in a with clause
17060 -- in the same context clause. Note we already checked (in
17061 -- Par.Prag) that the arguments are either identifiers or
17062 -- selected components.
17063
17064 Arg_Node := Arg1;
17065 while Present (Arg_Node) loop
17066 Citem := First (List_Containing (N));
17067 while Citem /= N loop
17068 if Nkind (Citem) = N_With_Clause
17069 and then
17070 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
17071 then
17072 Set_Has_Pragma_Unreferenced
17073 (Cunit_Entity
17074 (Get_Source_Unit
17075 (Library_Unit (Citem))));
17076 Set_Unit_Name
17077 (Get_Pragma_Arg (Arg_Node), Name (Citem));
17078 exit;
17079 end if;
17080
17081 Next (Citem);
17082 end loop;
17083
17084 if Citem = N then
17085 Error_Pragma_Arg
17086 ("argument of pragma% is not withed unit", Arg_Node);
17087 end if;
17088
17089 Next (Arg_Node);
17090 end loop;
17091
17092 -- Case of not in list of context items
17093
17094 else
17095 Arg_Node := Arg1;
17096 while Present (Arg_Node) loop
17097 Check_No_Identifier (Arg_Node);
17098
17099 -- Note: the analyze call done by Check_Arg_Is_Local_Name
17100 -- will in fact generate reference, so that the entity will
17101 -- have a reference, which will inhibit any warnings about
17102 -- it not being referenced, and also properly show up in the
17103 -- ali file as a reference. But this reference is recorded
17104 -- before the Has_Pragma_Unreferenced flag is set, so that
17105 -- no warning is generated for this reference.
17106
17107 Check_Arg_Is_Local_Name (Arg_Node);
17108 Arg_Expr := Get_Pragma_Arg (Arg_Node);
17109
17110 if Is_Entity_Name (Arg_Expr) then
17111 Arg_Ent := Entity (Arg_Expr);
17112
17113 -- If the entity is overloaded, the pragma applies to the
17114 -- most recent overloading, as documented. In this case,
17115 -- name resolution does not generate a reference, so it
17116 -- must be done here explicitly.
17117
17118 if Is_Overloaded (Arg_Expr) then
17119 Generate_Reference (Arg_Ent, N);
17120 end if;
17121
17122 Set_Has_Pragma_Unreferenced (Arg_Ent);
17123 end if;
17124
17125 Next (Arg_Node);
17126 end loop;
17127 end if;
17128 end Unreferenced;
17129
17130 --------------------------
17131 -- Unreferenced_Objects --
17132 --------------------------
17133
17134 -- pragma Unreferenced_Objects (local_Name {, local_Name});
17135
17136 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
17137 Arg_Node : Node_Id;
17138 Arg_Expr : Node_Id;
17139
17140 begin
17141 GNAT_Pragma;
17142 Check_At_Least_N_Arguments (1);
17143
17144 Arg_Node := Arg1;
17145 while Present (Arg_Node) loop
17146 Check_No_Identifier (Arg_Node);
17147 Check_Arg_Is_Local_Name (Arg_Node);
17148 Arg_Expr := Get_Pragma_Arg (Arg_Node);
17149
17150 if not Is_Entity_Name (Arg_Expr)
17151 or else not Is_Type (Entity (Arg_Expr))
17152 then
17153 Error_Pragma_Arg
17154 ("argument for pragma% must be type or subtype", Arg_Node);
17155 end if;
17156
17157 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
17158 Next (Arg_Node);
17159 end loop;
17160 end Unreferenced_Objects;
17161
17162 ------------------------------
17163 -- Unreserve_All_Interrupts --
17164 ------------------------------
17165
17166 -- pragma Unreserve_All_Interrupts;
17167
17168 when Pragma_Unreserve_All_Interrupts =>
17169 GNAT_Pragma;
17170 Check_Arg_Count (0);
17171
17172 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
17173 Unreserve_All_Interrupts := True;
17174 end if;
17175
17176 ----------------
17177 -- Unsuppress --
17178 ----------------
17179
17180 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
17181
17182 when Pragma_Unsuppress =>
17183 Ada_2005_Pragma;
17184 Process_Suppress_Unsuppress (False);
17185
17186 -------------------
17187 -- Use_VADS_Size --
17188 -------------------
17189
17190 -- pragma Use_VADS_Size;
17191
17192 when Pragma_Use_VADS_Size =>
17193 GNAT_Pragma;
17194 Check_Arg_Count (0);
17195 Check_Valid_Configuration_Pragma;
17196 Use_VADS_Size := True;
17197
17198 ---------------------
17199 -- Validity_Checks --
17200 ---------------------
17201
17202 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
17203
17204 when Pragma_Validity_Checks => Validity_Checks : declare
17205 A : constant Node_Id := Get_Pragma_Arg (Arg1);
17206 S : String_Id;
17207 C : Char_Code;
17208
17209 begin
17210 GNAT_Pragma;
17211 Check_Arg_Count (1);
17212 Check_No_Identifiers;
17213
17214 if Nkind (A) = N_String_Literal then
17215 S := Strval (A);
17216
17217 declare
17218 Slen : constant Natural := Natural (String_Length (S));
17219 Options : String (1 .. Slen);
17220 J : Natural;
17221
17222 begin
17223 J := 1;
17224 loop
17225 C := Get_String_Char (S, Int (J));
17226 exit when not In_Character_Range (C);
17227 Options (J) := Get_Character (C);
17228
17229 if J = Slen then
17230 Set_Validity_Check_Options (Options);
17231 exit;
17232 else
17233 J := J + 1;
17234 end if;
17235 end loop;
17236 end;
17237
17238 elsif Nkind (A) = N_Identifier then
17239 if Chars (A) = Name_All_Checks then
17240 Set_Validity_Check_Options ("a");
17241 elsif Chars (A) = Name_On then
17242 Validity_Checks_On := True;
17243 elsif Chars (A) = Name_Off then
17244 Validity_Checks_On := False;
17245 end if;
17246 end if;
17247 end Validity_Checks;
17248
17249 --------------
17250 -- Volatile --
17251 --------------
17252
17253 -- pragma Volatile (LOCAL_NAME);
17254
17255 when Pragma_Volatile =>
17256 Process_Atomic_Shared_Volatile;
17257
17258 -------------------------
17259 -- Volatile_Components --
17260 -------------------------
17261
17262 -- pragma Volatile_Components (array_LOCAL_NAME);
17263
17264 -- Volatile is handled by the same circuit as Atomic_Components
17265
17266 --------------
17267 -- Warnings --
17268 --------------
17269
17270 -- pragma Warnings (On | Off);
17271 -- pragma Warnings (On | Off, LOCAL_NAME);
17272 -- pragma Warnings (static_string_EXPRESSION);
17273 -- pragma Warnings (On | Off, STRING_LITERAL);
17274
17275 when Pragma_Warnings => Warnings : begin
17276 GNAT_Pragma;
17277 Check_At_Least_N_Arguments (1);
17278 Check_No_Identifiers;
17279
17280 -- If debug flag -gnatd.i is set, pragma is ignored
17281
17282 if Debug_Flag_Dot_I then
17283 return;
17284 end if;
17285
17286 -- Process various forms of the pragma
17287
17288 declare
17289 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
17290
17291 begin
17292 -- One argument case
17293
17294 if Arg_Count = 1 then
17295
17296 -- On/Off one argument case was processed by parser
17297
17298 if Nkind (Argx) = N_Identifier
17299 and then
17300 (Chars (Argx) = Name_On
17301 or else
17302 Chars (Argx) = Name_Off)
17303 then
17304 null;
17305
17306 -- One argument case must be ON/OFF or static string expr
17307
17308 elsif not Is_Static_String_Expression (Arg1) then
17309 Error_Pragma_Arg
17310 ("argument of pragma% must be On/Off or static string "
17311 & "expression", Arg1);
17312
17313 -- One argument string expression case
17314
17315 else
17316 declare
17317 Lit : constant Node_Id := Expr_Value_S (Argx);
17318 Str : constant String_Id := Strval (Lit);
17319 Len : constant Nat := String_Length (Str);
17320 C : Char_Code;
17321 J : Nat;
17322 OK : Boolean;
17323 Chr : Character;
17324
17325 begin
17326 J := 1;
17327 while J <= Len loop
17328 C := Get_String_Char (Str, J);
17329 OK := In_Character_Range (C);
17330
17331 if OK then
17332 Chr := Get_Character (C);
17333
17334 -- Dash case: only -Wxxx is accepted
17335
17336 if J = 1
17337 and then J < Len
17338 and then Chr = '-'
17339 then
17340 J := J + 1;
17341 C := Get_String_Char (Str, J);
17342 Chr := Get_Character (C);
17343 exit when Chr = 'W';
17344 OK := False;
17345
17346 -- Dot case
17347
17348 elsif J < Len and then Chr = '.' then
17349 J := J + 1;
17350 C := Get_String_Char (Str, J);
17351 Chr := Get_Character (C);
17352
17353 if not Set_Dot_Warning_Switch (Chr) then
17354 Error_Pragma_Arg
17355 ("invalid warning switch character "
17356 & '.' & Chr, Arg1);
17357 end if;
17358
17359 -- Non-Dot case
17360
17361 else
17362 OK := Set_Warning_Switch (Chr);
17363 end if;
17364 end if;
17365
17366 if not OK then
17367 Error_Pragma_Arg
17368 ("invalid warning switch character " & Chr,
17369 Arg1);
17370 end if;
17371
17372 J := J + 1;
17373 end loop;
17374 end;
17375 end if;
17376
17377 -- Two or more arguments (must be two)
17378
17379 else
17380 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
17381 Check_At_Most_N_Arguments (2);
17382
17383 declare
17384 E_Id : Node_Id;
17385 E : Entity_Id;
17386 Err : Boolean;
17387
17388 begin
17389 E_Id := Get_Pragma_Arg (Arg2);
17390 Analyze (E_Id);
17391
17392 -- In the expansion of an inlined body, a reference to
17393 -- the formal may be wrapped in a conversion if the
17394 -- actual is a conversion. Retrieve the real entity name.
17395
17396 if (In_Instance_Body or In_Inlined_Body)
17397 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
17398 then
17399 E_Id := Expression (E_Id);
17400 end if;
17401
17402 -- Entity name case
17403
17404 if Is_Entity_Name (E_Id) then
17405 E := Entity (E_Id);
17406
17407 if E = Any_Id then
17408 return;
17409 else
17410 loop
17411 Set_Warnings_Off
17412 (E, (Chars (Get_Pragma_Arg (Arg1)) =
17413 Name_Off));
17414
17415 -- For OFF case, make entry in warnings off
17416 -- pragma table for later processing. But we do
17417 -- not do that within an instance, since these
17418 -- warnings are about what is needed in the
17419 -- template, not an instance of it.
17420
17421 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
17422 and then Warn_On_Warnings_Off
17423 and then not In_Instance
17424 then
17425 Warnings_Off_Pragmas.Append ((N, E));
17426 end if;
17427
17428 if Is_Enumeration_Type (E) then
17429 declare
17430 Lit : Entity_Id;
17431 begin
17432 Lit := First_Literal (E);
17433 while Present (Lit) loop
17434 Set_Warnings_Off (Lit);
17435 Next_Literal (Lit);
17436 end loop;
17437 end;
17438 end if;
17439
17440 exit when No (Homonym (E));
17441 E := Homonym (E);
17442 end loop;
17443 end if;
17444
17445 -- Error if not entity or static string literal case
17446
17447 elsif not Is_Static_String_Expression (Arg2) then
17448 Error_Pragma_Arg
17449 ("second argument of pragma% must be entity name "
17450 & "or static string expression", Arg2);
17451
17452 -- String literal case
17453
17454 else
17455 String_To_Name_Buffer
17456 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
17457
17458 -- Note on configuration pragma case: If this is a
17459 -- configuration pragma, then for an OFF pragma, we
17460 -- just set Config True in the call, which is all
17461 -- that needs to be done. For the case of ON, this
17462 -- is normally an error, unless it is canceling the
17463 -- effect of a previous OFF pragma in the same file.
17464 -- In any other case, an error will be signalled (ON
17465 -- with no matching OFF).
17466
17467 -- Note: We set Used if we are inside a generic to
17468 -- disable the test that the non-config case actually
17469 -- cancels a warning. That's because we can't be sure
17470 -- there isn't an instantiation in some other unit
17471 -- where a warning is suppressed.
17472
17473 -- We could do a little better here by checking if the
17474 -- generic unit we are inside is public, but for now
17475 -- we don't bother with that refinement.
17476
17477 if Chars (Argx) = Name_Off then
17478 Set_Specific_Warning_Off
17479 (Loc, Name_Buffer (1 .. Name_Len),
17480 Config => Is_Configuration_Pragma,
17481 Used => Inside_A_Generic or else In_Instance);
17482
17483 elsif Chars (Argx) = Name_On then
17484 Set_Specific_Warning_On
17485 (Loc, Name_Buffer (1 .. Name_Len), Err);
17486
17487 if Err then
17488 Error_Msg
17489 ("??pragma Warnings On with no matching "
17490 & "Warnings Off", Loc);
17491 end if;
17492 end if;
17493 end if;
17494 end;
17495 end if;
17496 end;
17497 end Warnings;
17498
17499 -------------------
17500 -- Weak_External --
17501 -------------------
17502
17503 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
17504
17505 when Pragma_Weak_External => Weak_External : declare
17506 Ent : Entity_Id;
17507
17508 begin
17509 GNAT_Pragma;
17510 Check_Arg_Count (1);
17511 Check_Optional_Identifier (Arg1, Name_Entity);
17512 Check_Arg_Is_Library_Level_Local_Name (Arg1);
17513 Ent := Entity (Get_Pragma_Arg (Arg1));
17514
17515 if Rep_Item_Too_Early (Ent, N) then
17516 return;
17517 else
17518 Ent := Underlying_Type (Ent);
17519 end if;
17520
17521 -- The only processing required is to link this item on to the
17522 -- list of rep items for the given entity. This is accomplished
17523 -- by the call to Rep_Item_Too_Late (when no error is detected
17524 -- and False is returned).
17525
17526 if Rep_Item_Too_Late (Ent, N) then
17527 return;
17528 else
17529 Set_Has_Gigi_Rep_Item (Ent);
17530 end if;
17531 end Weak_External;
17532
17533 -----------------------------
17534 -- Wide_Character_Encoding --
17535 -----------------------------
17536
17537 -- pragma Wide_Character_Encoding (IDENTIFIER);
17538
17539 when Pragma_Wide_Character_Encoding =>
17540 GNAT_Pragma;
17541
17542 -- Nothing to do, handled in parser. Note that we do not enforce
17543 -- configuration pragma placement, this pragma can appear at any
17544 -- place in the source, allowing mixed encodings within a single
17545 -- source program.
17546
17547 null;
17548
17549 --------------------
17550 -- Unknown_Pragma --
17551 --------------------
17552
17553 -- Should be impossible, since the case of an unknown pragma is
17554 -- separately processed before the case statement is entered.
17555
17556 when Unknown_Pragma =>
17557 raise Program_Error;
17558 end case;
17559
17560 -- AI05-0144: detect dangerous order dependence. Disabled for now,
17561 -- until AI is formally approved.
17562
17563 -- Check_Order_Dependence;
17564
17565 exception
17566 when Pragma_Exit => null;
17567 end Analyze_Pragma;
17568
17569 -------------------
17570 -- Check_Enabled --
17571 -------------------
17572
17573 function Check_Enabled (Nam : Name_Id) return Boolean is
17574 PP : Node_Id;
17575
17576 begin
17577 -- Loop through entries in check policy list
17578
17579 PP := Opt.Check_Policy_List;
17580 loop
17581 -- If there are no specific entries that matched, then we let the
17582 -- setting of assertions govern. Note that this provides the needed
17583 -- compatibility with the RM for the cases of assertion, invariant,
17584 -- precondition, predicate, and postcondition.
17585
17586 if No (PP) then
17587 return Assertions_Enabled;
17588
17589 -- Here we have an entry see if it matches
17590
17591 else
17592 declare
17593 PPA : constant List_Id := Pragma_Argument_Associations (PP);
17594
17595 begin
17596 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
17597 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
17598 when Name_On | Name_Check =>
17599 return True;
17600 when Name_Off | Name_Disable | Name_Ignore =>
17601 return False;
17602 when others =>
17603 raise Program_Error;
17604 end case;
17605
17606 else
17607 PP := Next_Pragma (PP);
17608 end if;
17609 end;
17610 end if;
17611 end loop;
17612 end Check_Enabled;
17613
17614 ---------------------------------
17615 -- Delay_Config_Pragma_Analyze --
17616 ---------------------------------
17617
17618 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
17619 begin
17620 return Pragma_Name (N) = Name_Interrupt_State
17621 or else
17622 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
17623 end Delay_Config_Pragma_Analyze;
17624
17625 -------------------------
17626 -- Get_Base_Subprogram --
17627 -------------------------
17628
17629 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
17630 Result : Entity_Id;
17631
17632 begin
17633 -- Follow subprogram renaming chain
17634
17635 Result := Def_Id;
17636
17637 if Is_Subprogram (Result)
17638 and then
17639 Nkind (Parent (Declaration_Node (Result))) =
17640 N_Subprogram_Renaming_Declaration
17641 and then Present (Alias (Result))
17642 then
17643 Result := Alias (Result);
17644 end if;
17645
17646 return Result;
17647 end Get_Base_Subprogram;
17648
17649 ----------------
17650 -- Initialize --
17651 ----------------
17652
17653 procedure Initialize is
17654 begin
17655 Externals.Init;
17656 end Initialize;
17657
17658 -----------------------------
17659 -- Is_Config_Static_String --
17660 -----------------------------
17661
17662 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
17663
17664 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
17665 -- This is an internal recursive function that is just like the outer
17666 -- function except that it adds the string to the name buffer rather
17667 -- than placing the string in the name buffer.
17668
17669 ------------------------------
17670 -- Add_Config_Static_String --
17671 ------------------------------
17672
17673 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
17674 N : Node_Id;
17675 C : Char_Code;
17676
17677 begin
17678 N := Arg;
17679
17680 if Nkind (N) = N_Op_Concat then
17681 if Add_Config_Static_String (Left_Opnd (N)) then
17682 N := Right_Opnd (N);
17683 else
17684 return False;
17685 end if;
17686 end if;
17687
17688 if Nkind (N) /= N_String_Literal then
17689 Error_Msg_N ("string literal expected for pragma argument", N);
17690 return False;
17691
17692 else
17693 for J in 1 .. String_Length (Strval (N)) loop
17694 C := Get_String_Char (Strval (N), J);
17695
17696 if not In_Character_Range (C) then
17697 Error_Msg
17698 ("string literal contains invalid wide character",
17699 Sloc (N) + 1 + Source_Ptr (J));
17700 return False;
17701 end if;
17702
17703 Add_Char_To_Name_Buffer (Get_Character (C));
17704 end loop;
17705 end if;
17706
17707 return True;
17708 end Add_Config_Static_String;
17709
17710 -- Start of processing for Is_Config_Static_String
17711
17712 begin
17713
17714 Name_Len := 0;
17715 return Add_Config_Static_String (Arg);
17716 end Is_Config_Static_String;
17717
17718 -----------------------------------------
17719 -- Is_Non_Significant_Pragma_Reference --
17720 -----------------------------------------
17721
17722 -- This function makes use of the following static table which indicates
17723 -- whether appearance of some name in a given pragma is to be considered
17724 -- as a reference for the purposes of warnings about unreferenced objects.
17725
17726 -- -1 indicates that references in any argument position are significant
17727 -- 0 indicates that appearance in any argument is not significant
17728 -- +n indicates that appearance as argument n is significant, but all
17729 -- other arguments are not significant
17730 -- 99 special processing required (e.g. for pragma Check)
17731
17732 Sig_Flags : constant array (Pragma_Id) of Int :=
17733 (Pragma_AST_Entry => -1,
17734 Pragma_Abort_Defer => -1,
17735 Pragma_Abstract_State => -1,
17736 Pragma_Ada_83 => -1,
17737 Pragma_Ada_95 => -1,
17738 Pragma_Ada_05 => -1,
17739 Pragma_Ada_2005 => -1,
17740 Pragma_Ada_12 => -1,
17741 Pragma_Ada_2012 => -1,
17742 Pragma_All_Calls_Remote => -1,
17743 Pragma_Annotate => -1,
17744 Pragma_Assert => -1,
17745 Pragma_Assert_And_Cut => -1,
17746 Pragma_Assertion_Policy => 0,
17747 Pragma_Assume => 0,
17748 Pragma_Assume_No_Invalid_Values => 0,
17749 Pragma_Attribute_Definition => +3,
17750 Pragma_Asynchronous => -1,
17751 Pragma_Atomic => 0,
17752 Pragma_Atomic_Components => 0,
17753 Pragma_Attach_Handler => -1,
17754 Pragma_Check => 99,
17755 Pragma_Check_Float_Overflow => 0,
17756 Pragma_Check_Name => 0,
17757 Pragma_Check_Policy => 0,
17758 Pragma_CIL_Constructor => -1,
17759 Pragma_CPP_Class => 0,
17760 Pragma_CPP_Constructor => 0,
17761 Pragma_CPP_Virtual => 0,
17762 Pragma_CPP_Vtable => 0,
17763 Pragma_CPU => -1,
17764 Pragma_C_Pass_By_Copy => 0,
17765 Pragma_Comment => 0,
17766 Pragma_Common_Object => -1,
17767 Pragma_Compile_Time_Error => -1,
17768 Pragma_Compile_Time_Warning => -1,
17769 Pragma_Compiler_Unit => 0,
17770 Pragma_Complete_Representation => 0,
17771 Pragma_Complex_Representation => 0,
17772 Pragma_Component_Alignment => -1,
17773 Pragma_Contract_Case => -1,
17774 Pragma_Contract_Cases => -1,
17775 Pragma_Controlled => 0,
17776 Pragma_Convention => 0,
17777 Pragma_Convention_Identifier => 0,
17778 Pragma_Debug => -1,
17779 Pragma_Debug_Policy => 0,
17780 Pragma_Detect_Blocking => -1,
17781 Pragma_Default_Storage_Pool => -1,
17782 Pragma_Depends => -1,
17783 Pragma_Disable_Atomic_Synchronization => -1,
17784 Pragma_Discard_Names => 0,
17785 Pragma_Dispatching_Domain => -1,
17786 Pragma_Elaborate => -1,
17787 Pragma_Elaborate_All => -1,
17788 Pragma_Elaborate_Body => -1,
17789 Pragma_Elaboration_Checks => -1,
17790 Pragma_Eliminate => -1,
17791 Pragma_Enable_Atomic_Synchronization => -1,
17792 Pragma_Export => -1,
17793 Pragma_Export_Exception => -1,
17794 Pragma_Export_Function => -1,
17795 Pragma_Export_Object => -1,
17796 Pragma_Export_Procedure => -1,
17797 Pragma_Export_Value => -1,
17798 Pragma_Export_Valued_Procedure => -1,
17799 Pragma_Extend_System => -1,
17800 Pragma_Extensions_Allowed => -1,
17801 Pragma_External => -1,
17802 Pragma_Favor_Top_Level => -1,
17803 Pragma_External_Name_Casing => -1,
17804 Pragma_Fast_Math => -1,
17805 Pragma_Finalize_Storage_Only => 0,
17806 Pragma_Float_Representation => 0,
17807 Pragma_Ghost => 0,
17808 Pragma_Global => -1,
17809 Pragma_Ident => -1,
17810 Pragma_Implementation_Defined => -1,
17811 Pragma_Implemented => -1,
17812 Pragma_Implicit_Packing => 0,
17813 Pragma_Import => +2,
17814 Pragma_Import_Exception => 0,
17815 Pragma_Import_Function => 0,
17816 Pragma_Import_Object => 0,
17817 Pragma_Import_Procedure => 0,
17818 Pragma_Import_Valued_Procedure => 0,
17819 Pragma_Independent => 0,
17820 Pragma_Independent_Components => 0,
17821 Pragma_Initialize_Scalars => -1,
17822 Pragma_Inline => 0,
17823 Pragma_Inline_Always => 0,
17824 Pragma_Inline_Generic => 0,
17825 Pragma_Inspection_Point => -1,
17826 Pragma_Interface => +2,
17827 Pragma_Interface_Name => +2,
17828 Pragma_Interrupt_Handler => -1,
17829 Pragma_Interrupt_Priority => -1,
17830 Pragma_Interrupt_State => -1,
17831 Pragma_Invariant => -1,
17832 Pragma_Java_Constructor => -1,
17833 Pragma_Java_Interface => -1,
17834 Pragma_Keep_Names => 0,
17835 Pragma_License => -1,
17836 Pragma_Link_With => -1,
17837 Pragma_Linker_Alias => -1,
17838 Pragma_Linker_Constructor => -1,
17839 Pragma_Linker_Destructor => -1,
17840 Pragma_Linker_Options => -1,
17841 Pragma_Linker_Section => -1,
17842 Pragma_List => -1,
17843 Pragma_Lock_Free => -1,
17844 Pragma_Locking_Policy => -1,
17845 Pragma_Long_Float => -1,
17846 Pragma_Loop_Invariant => -1,
17847 Pragma_Loop_Optimize => -1,
17848 Pragma_Loop_Variant => -1,
17849 Pragma_Machine_Attribute => -1,
17850 Pragma_Main => -1,
17851 Pragma_Main_Storage => -1,
17852 Pragma_Memory_Size => -1,
17853 Pragma_No_Return => 0,
17854 Pragma_No_Body => 0,
17855 Pragma_No_Inline => 0,
17856 Pragma_No_Run_Time => -1,
17857 Pragma_No_Strict_Aliasing => -1,
17858 Pragma_Normalize_Scalars => -1,
17859 Pragma_Obsolescent => 0,
17860 Pragma_Optimize => -1,
17861 Pragma_Optimize_Alignment => -1,
17862 Pragma_Overflow_Mode => 0,
17863 Pragma_Overriding_Renamings => 0,
17864 Pragma_Ordered => 0,
17865 Pragma_Pack => 0,
17866 Pragma_Page => -1,
17867 Pragma_Partition_Elaboration_Policy => -1,
17868 Pragma_Passive => -1,
17869 Pragma_Preelaborable_Initialization => -1,
17870 Pragma_Polling => -1,
17871 Pragma_Persistent_BSS => 0,
17872 Pragma_Postcondition => -1,
17873 Pragma_Precondition => -1,
17874 Pragma_Predicate => -1,
17875 Pragma_Preelaborate => -1,
17876 Pragma_Preelaborate_05 => -1,
17877 Pragma_Priority => -1,
17878 Pragma_Priority_Specific_Dispatching => -1,
17879 Pragma_Profile => 0,
17880 Pragma_Profile_Warnings => 0,
17881 Pragma_Propagate_Exceptions => -1,
17882 Pragma_Psect_Object => -1,
17883 Pragma_Pure => -1,
17884 Pragma_Pure_05 => -1,
17885 Pragma_Pure_12 => -1,
17886 Pragma_Pure_Function => -1,
17887 Pragma_Queuing_Policy => -1,
17888 Pragma_Rational => -1,
17889 Pragma_Ravenscar => -1,
17890 Pragma_Relative_Deadline => -1,
17891 Pragma_Remote_Access_Type => -1,
17892 Pragma_Remote_Call_Interface => -1,
17893 Pragma_Remote_Types => -1,
17894 Pragma_Restricted_Run_Time => -1,
17895 Pragma_Restriction_Warnings => -1,
17896 Pragma_Restrictions => -1,
17897 Pragma_Reviewable => -1,
17898 Pragma_Short_Circuit_And_Or => -1,
17899 Pragma_Share_Generic => -1,
17900 Pragma_Shared => -1,
17901 Pragma_Shared_Passive => -1,
17902 Pragma_Short_Descriptors => 0,
17903 Pragma_Simple_Storage_Pool_Type => 0,
17904 Pragma_Source_File_Name => -1,
17905 Pragma_Source_File_Name_Project => -1,
17906 Pragma_Source_Reference => -1,
17907 Pragma_Storage_Size => -1,
17908 Pragma_Storage_Unit => -1,
17909 Pragma_Static_Elaboration_Desired => -1,
17910 Pragma_Stream_Convert => -1,
17911 Pragma_Style_Checks => -1,
17912 Pragma_Subtitle => -1,
17913 Pragma_Suppress => 0,
17914 Pragma_Suppress_Exception_Locations => 0,
17915 Pragma_Suppress_All => -1,
17916 Pragma_Suppress_Debug_Info => 0,
17917 Pragma_Suppress_Initialization => 0,
17918 Pragma_System_Name => -1,
17919 Pragma_Task_Dispatching_Policy => -1,
17920 Pragma_Task_Info => -1,
17921 Pragma_Task_Name => -1,
17922 Pragma_Task_Storage => 0,
17923 Pragma_Test_Case => -1,
17924 Pragma_Thread_Local_Storage => 0,
17925 Pragma_Time_Slice => -1,
17926 Pragma_Title => -1,
17927 Pragma_Unchecked_Union => 0,
17928 Pragma_Unimplemented_Unit => -1,
17929 Pragma_Universal_Aliasing => -1,
17930 Pragma_Universal_Data => -1,
17931 Pragma_Unmodified => -1,
17932 Pragma_Unreferenced => -1,
17933 Pragma_Unreferenced_Objects => -1,
17934 Pragma_Unreserve_All_Interrupts => -1,
17935 Pragma_Unsuppress => 0,
17936 Pragma_Use_VADS_Size => -1,
17937 Pragma_Validity_Checks => -1,
17938 Pragma_Volatile => 0,
17939 Pragma_Volatile_Components => 0,
17940 Pragma_Warnings => -1,
17941 Pragma_Weak_External => -1,
17942 Pragma_Wide_Character_Encoding => 0,
17943 Unknown_Pragma => 0);
17944
17945 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
17946 Id : Pragma_Id;
17947 P : Node_Id;
17948 C : Int;
17949 A : Node_Id;
17950
17951 begin
17952 P := Parent (N);
17953
17954 if Nkind (P) /= N_Pragma_Argument_Association then
17955 return False;
17956
17957 else
17958 Id := Get_Pragma_Id (Parent (P));
17959 C := Sig_Flags (Id);
17960
17961 case C is
17962 when -1 =>
17963 return False;
17964
17965 when 0 =>
17966 return True;
17967
17968 when 99 =>
17969 case Id is
17970
17971 -- For pragma Check, the first argument is not significant,
17972 -- the second and the third (if present) arguments are
17973 -- significant.
17974
17975 when Pragma_Check =>
17976 return
17977 P = First (Pragma_Argument_Associations (Parent (P)));
17978
17979 when others =>
17980 raise Program_Error;
17981 end case;
17982
17983 when others =>
17984 A := First (Pragma_Argument_Associations (Parent (P)));
17985 for J in 1 .. C - 1 loop
17986 if No (A) then
17987 return False;
17988 end if;
17989
17990 Next (A);
17991 end loop;
17992
17993 return A = P; -- is this wrong way round ???
17994 end case;
17995 end if;
17996 end Is_Non_Significant_Pragma_Reference;
17997
17998 ------------------------------
17999 -- Is_Pragma_String_Literal --
18000 ------------------------------
18001
18002 -- This function returns true if the corresponding pragma argument is a
18003 -- static string expression. These are the only cases in which string
18004 -- literals can appear as pragma arguments. We also allow a string literal
18005 -- as the first argument to pragma Assert (although it will of course
18006 -- always generate a type error).
18007
18008 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
18009 Pragn : constant Node_Id := Parent (Par);
18010 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
18011 Pname : constant Name_Id := Pragma_Name (Pragn);
18012 Argn : Natural;
18013 N : Node_Id;
18014
18015 begin
18016 Argn := 1;
18017 N := First (Assoc);
18018 loop
18019 exit when N = Par;
18020 Argn := Argn + 1;
18021 Next (N);
18022 end loop;
18023
18024 if Pname = Name_Assert then
18025 return True;
18026
18027 elsif Pname = Name_Export then
18028 return Argn > 2;
18029
18030 elsif Pname = Name_Ident then
18031 return Argn = 1;
18032
18033 elsif Pname = Name_Import then
18034 return Argn > 2;
18035
18036 elsif Pname = Name_Interface_Name then
18037 return Argn > 1;
18038
18039 elsif Pname = Name_Linker_Alias then
18040 return Argn = 2;
18041
18042 elsif Pname = Name_Linker_Section then
18043 return Argn = 2;
18044
18045 elsif Pname = Name_Machine_Attribute then
18046 return Argn = 2;
18047
18048 elsif Pname = Name_Source_File_Name then
18049 return True;
18050
18051 elsif Pname = Name_Source_Reference then
18052 return Argn = 2;
18053
18054 elsif Pname = Name_Title then
18055 return True;
18056
18057 elsif Pname = Name_Subtitle then
18058 return True;
18059
18060 else
18061 return False;
18062 end if;
18063 end Is_Pragma_String_Literal;
18064
18065 -----------------------------------------
18066 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
18067 -----------------------------------------
18068
18069 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
18070 Aspects : constant List_Id := New_List;
18071 Loc : constant Source_Ptr := Sloc (Decl);
18072 Or_Decl : constant Node_Id := Original_Node (Decl);
18073
18074 Original_Aspects : List_Id;
18075 -- To capture global references, a copy of the created aspects must be
18076 -- inserted in the original tree.
18077
18078 Prag : Node_Id;
18079 Prag_Arg_Ass : Node_Id;
18080 Prag_Id : Pragma_Id;
18081
18082 begin
18083 -- Check for any PPC pragmas that appear within Decl
18084
18085 Prag := Next (Decl);
18086 while Nkind (Prag) = N_Pragma loop
18087 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
18088
18089 case Prag_Id is
18090 when Pragma_Postcondition | Pragma_Precondition =>
18091 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
18092
18093 -- Make an aspect from any PPC pragma
18094
18095 Append_To (Aspects,
18096 Make_Aspect_Specification (Loc,
18097 Identifier =>
18098 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
18099 Expression =>
18100 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
18101
18102 -- Generate the analysis information in the pragma expression
18103 -- and then set the pragma node analyzed to avoid any further
18104 -- analysis.
18105
18106 Analyze (Expression (Prag_Arg_Ass));
18107 Set_Analyzed (Prag, True);
18108
18109 when others => null;
18110 end case;
18111
18112 Next (Prag);
18113 end loop;
18114
18115 -- Set all new aspects into the generic declaration node
18116
18117 if Is_Non_Empty_List (Aspects) then
18118
18119 -- Create the list of aspects to be inserted in the original tree
18120
18121 Original_Aspects := Copy_Separate_List (Aspects);
18122
18123 -- Check if Decl already has aspects
18124
18125 -- Attach the new lists of aspects to both the generic copy and the
18126 -- original tree.
18127
18128 if Has_Aspects (Decl) then
18129 Append_List (Aspects, Aspect_Specifications (Decl));
18130 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
18131
18132 else
18133 Set_Parent (Aspects, Decl);
18134 Set_Aspect_Specifications (Decl, Aspects);
18135 Set_Parent (Original_Aspects, Or_Decl);
18136 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
18137 end if;
18138 end if;
18139 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
18140
18141 -------------------------
18142 -- Preanalyze_CTC_Args --
18143 -------------------------
18144
18145 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
18146 begin
18147 -- Preanalyze the boolean expressions, we treat these as spec
18148 -- expressions (i.e. similar to a default expression).
18149
18150 if Present (Arg_Req) then
18151 Preanalyze_Assert_Expression
18152 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
18153
18154 -- In ASIS mode, for a pragma generated from a source aspect, also
18155 -- analyze the original aspect expression.
18156
18157 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
18158 Preanalyze_Assert_Expression
18159 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
18160 end if;
18161 end if;
18162
18163 if Present (Arg_Ens) then
18164 Preanalyze_Assert_Expression
18165 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
18166
18167 -- In ASIS mode, for a pragma generated from a source aspect, also
18168 -- analyze the original aspect expression.
18169
18170 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
18171 Preanalyze_Assert_Expression
18172 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
18173 end if;
18174 end if;
18175 end Preanalyze_CTC_Args;
18176
18177 --------------------------------------
18178 -- Process_Compilation_Unit_Pragmas --
18179 --------------------------------------
18180
18181 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
18182 begin
18183 -- A special check for pragma Suppress_All, a very strange DEC pragma,
18184 -- strange because it comes at the end of the unit. Rational has the
18185 -- same name for a pragma, but treats it as a program unit pragma, In
18186 -- GNAT we just decide to allow it anywhere at all. If it appeared then
18187 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
18188 -- node, and we insert a pragma Suppress (All_Checks) at the start of
18189 -- the context clause to ensure the correct processing.
18190
18191 if Has_Pragma_Suppress_All (N) then
18192 Prepend_To (Context_Items (N),
18193 Make_Pragma (Sloc (N),
18194 Chars => Name_Suppress,
18195 Pragma_Argument_Associations => New_List (
18196 Make_Pragma_Argument_Association (Sloc (N),
18197 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
18198 end if;
18199
18200 -- Nothing else to do at the current time!
18201
18202 end Process_Compilation_Unit_Pragmas;
18203
18204 --------
18205 -- rv --
18206 --------
18207
18208 procedure rv is
18209 begin
18210 null;
18211 end rv;
18212
18213 --------------------------------
18214 -- Set_Encoded_Interface_Name --
18215 --------------------------------
18216
18217 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
18218 Str : constant String_Id := Strval (S);
18219 Len : constant Int := String_Length (Str);
18220 CC : Char_Code;
18221 C : Character;
18222 J : Int;
18223
18224 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
18225
18226 procedure Encode;
18227 -- Stores encoded value of character code CC. The encoding we use an
18228 -- underscore followed by four lower case hex digits.
18229
18230 ------------
18231 -- Encode --
18232 ------------
18233
18234 procedure Encode is
18235 begin
18236 Store_String_Char (Get_Char_Code ('_'));
18237 Store_String_Char
18238 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
18239 Store_String_Char
18240 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
18241 Store_String_Char
18242 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
18243 Store_String_Char
18244 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
18245 end Encode;
18246
18247 -- Start of processing for Set_Encoded_Interface_Name
18248
18249 begin
18250 -- If first character is asterisk, this is a link name, and we leave it
18251 -- completely unmodified. We also ignore null strings (the latter case
18252 -- happens only in error cases) and no encoding should occur for Java or
18253 -- AAMP interface names.
18254
18255 if Len = 0
18256 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
18257 or else VM_Target /= No_VM
18258 or else AAMP_On_Target
18259 then
18260 Set_Interface_Name (E, S);
18261
18262 else
18263 J := 1;
18264 loop
18265 CC := Get_String_Char (Str, J);
18266
18267 exit when not In_Character_Range (CC);
18268
18269 C := Get_Character (CC);
18270
18271 exit when C /= '_' and then C /= '$'
18272 and then C not in '0' .. '9'
18273 and then C not in 'a' .. 'z'
18274 and then C not in 'A' .. 'Z';
18275
18276 if J = Len then
18277 Set_Interface_Name (E, S);
18278 return;
18279
18280 else
18281 J := J + 1;
18282 end if;
18283 end loop;
18284
18285 -- Here we need to encode. The encoding we use as follows:
18286 -- three underscores + four hex digits (lower case)
18287
18288 Start_String;
18289
18290 for J in 1 .. String_Length (Str) loop
18291 CC := Get_String_Char (Str, J);
18292
18293 if not In_Character_Range (CC) then
18294 Encode;
18295 else
18296 C := Get_Character (CC);
18297
18298 if C = '_' or else C = '$'
18299 or else C in '0' .. '9'
18300 or else C in 'a' .. 'z'
18301 or else C in 'A' .. 'Z'
18302 then
18303 Store_String_Char (CC);
18304 else
18305 Encode;
18306 end if;
18307 end if;
18308 end loop;
18309
18310 Set_Interface_Name (E,
18311 Make_String_Literal (Sloc (S),
18312 Strval => End_String));
18313 end if;
18314 end Set_Encoded_Interface_Name;
18315
18316 -------------------
18317 -- Set_Unit_Name --
18318 -------------------
18319
18320 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
18321 Pref : Node_Id;
18322 Scop : Entity_Id;
18323
18324 begin
18325 if Nkind (N) = N_Identifier
18326 and then Nkind (With_Item) = N_Identifier
18327 then
18328 Set_Entity (N, Entity (With_Item));
18329
18330 elsif Nkind (N) = N_Selected_Component then
18331 Change_Selected_Component_To_Expanded_Name (N);
18332 Set_Entity (N, Entity (With_Item));
18333 Set_Entity (Selector_Name (N), Entity (N));
18334
18335 Pref := Prefix (N);
18336 Scop := Scope (Entity (N));
18337 while Nkind (Pref) = N_Selected_Component loop
18338 Change_Selected_Component_To_Expanded_Name (Pref);
18339 Set_Entity (Selector_Name (Pref), Scop);
18340 Set_Entity (Pref, Scop);
18341 Pref := Prefix (Pref);
18342 Scop := Scope (Scop);
18343 end loop;
18344
18345 Set_Entity (Pref, Scop);
18346 end if;
18347 end Set_Unit_Name;
18348
18349 end Sem_Prag;