exp_ch4.adb (Expand_Concatenate): Remove wrapping in expression-with-actions node.
[gcc.git] / gcc / ada / sem_prag.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ P R A G --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
31
32 with Aspects; use Aspects;
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Checks; use Checks;
36 with Csets; use Csets;
37 with Debug; use Debug;
38 with Einfo; use Einfo;
39 with Elists; use Elists;
40 with Errout; use Errout;
41 with Exp_Dist; use Exp_Dist;
42 with Exp_Util; use Exp_Util;
43 with Freeze; use Freeze;
44 with Lib; use Lib;
45 with Lib.Writ; use Lib.Writ;
46 with Lib.Xref; use Lib.Xref;
47 with Namet.Sp; use Namet.Sp;
48 with Nlists; use Nlists;
49 with Nmake; use Nmake;
50 with Opt; use Opt;
51 with Output; use Output;
52 with Par_SCO; use Par_SCO;
53 with Restrict; use Restrict;
54 with Rident; use Rident;
55 with Rtsfind; use Rtsfind;
56 with Sem; use Sem;
57 with Sem_Aux; use Sem_Aux;
58 with Sem_Ch3; use Sem_Ch3;
59 with Sem_Ch6; use Sem_Ch6;
60 with Sem_Ch8; use Sem_Ch8;
61 with Sem_Ch12; use Sem_Ch12;
62 with Sem_Ch13; use Sem_Ch13;
63 with Sem_Disp; use Sem_Disp;
64 with Sem_Dist; use Sem_Dist;
65 with Sem_Elim; use Sem_Elim;
66 with Sem_Eval; use Sem_Eval;
67 with Sem_Intr; use Sem_Intr;
68 with Sem_Mech; use Sem_Mech;
69 with Sem_Res; use Sem_Res;
70 with Sem_Type; use Sem_Type;
71 with Sem_Util; use Sem_Util;
72 with Sem_VFpt; use Sem_VFpt;
73 with Sem_Warn; use Sem_Warn;
74 with Stand; use Stand;
75 with Sinfo; use Sinfo;
76 with Sinfo.CN; use Sinfo.CN;
77 with Sinput; use Sinput;
78 with Snames; use Snames;
79 with Stringt; use Stringt;
80 with Stylesw; use Stylesw;
81 with Table;
82 with Targparm; use Targparm;
83 with Tbuild; use Tbuild;
84 with Ttypes;
85 with Uintp; use Uintp;
86 with Uname; use Uname;
87 with Urealp; use Urealp;
88 with Validsw; use Validsw;
89 with Warnsw; use Warnsw;
90
91 package body Sem_Prag is
92
93 ----------------------------------------------
94 -- Common Handling of Import-Export Pragmas --
95 ----------------------------------------------
96
97 -- In the following section, a number of Import_xxx and Export_xxx pragmas
98 -- are defined by GNAT. These are compatible with the DEC pragmas of the
99 -- same name, and all have the following common form and processing:
100
101 -- pragma Export_xxx
102 -- [Internal =>] LOCAL_NAME
103 -- [, [External =>] EXTERNAL_SYMBOL]
104 -- [, other optional parameters ]);
105
106 -- pragma Import_xxx
107 -- [Internal =>] LOCAL_NAME
108 -- [, [External =>] EXTERNAL_SYMBOL]
109 -- [, other optional parameters ]);
110
111 -- EXTERNAL_SYMBOL ::=
112 -- IDENTIFIER
113 -- | static_string_EXPRESSION
114
115 -- The internal LOCAL_NAME designates the entity that is imported or
116 -- exported, and must refer to an entity in the current declarative
117 -- part (as required by the rules for LOCAL_NAME).
118
119 -- The external linker name is designated by the External parameter if
120 -- given, or the Internal parameter if not (if there is no External
121 -- parameter, the External parameter is a copy of the Internal name).
122
123 -- If the External parameter is given as a string, then this string is
124 -- treated as an external name (exactly as though it had been given as an
125 -- External_Name parameter for a normal Import pragma).
126
127 -- If the External parameter is given as an identifier (or there is no
128 -- External parameter, so that the Internal identifier is used), then
129 -- the external name is the characters of the identifier, translated
130 -- to all upper case letters for OpenVMS versions of GNAT, and to all
131 -- lower case letters for all other versions
132
133 -- Note: the external name specified or implied by any of these special
134 -- Import_xxx or Export_xxx pragmas override an external or link name
135 -- specified in a previous Import or Export pragma.
136
137 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
138 -- named notation, following the standard rules for subprogram calls, i.e.
139 -- parameters can be given in any order if named notation is used, and
140 -- positional and named notation can be mixed, subject to the rule that all
141 -- positional parameters must appear first.
142
143 -- Note: All these pragmas are implemented exactly following the DEC design
144 -- and implementation and are intended to be fully compatible with the use
145 -- of these pragmas in the DEC Ada compiler.
146
147 --------------------------------------------
148 -- Checking for Duplicated External Names --
149 --------------------------------------------
150
151 -- It is suspicious if two separate Export pragmas use the same external
152 -- name. The following table is used to diagnose this situation so that
153 -- an appropriate warning can be issued.
154
155 -- The Node_Id stored is for the N_String_Literal node created to hold
156 -- the value of the external name. The Sloc of this node is used to
157 -- cross-reference the location of the duplication.
158
159 package Externals is new Table.Table (
160 Table_Component_Type => Node_Id,
161 Table_Index_Type => Int,
162 Table_Low_Bound => 0,
163 Table_Initial => 100,
164 Table_Increment => 100,
165 Table_Name => "Name_Externals");
166
167 -------------------------------------
168 -- Local Subprograms and Variables --
169 -------------------------------------
170
171 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
172 -- This routine is used for possible casing adjustment of an explicit
173 -- external name supplied as a string literal (the node N), according to
174 -- the casing requirement of Opt.External_Name_Casing. If this is set to
175 -- As_Is, then the string literal is returned unchanged, but if it is set
176 -- to Uppercase or Lowercase, then a new string literal with appropriate
177 -- casing is constructed.
178
179 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
180 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
181 -- original one, following the renaming chain) is returned. Otherwise the
182 -- entity is returned unchanged. Should be in Einfo???
183
184 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id);
185 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
186 -- of a Contract_Case or Test_Case pragma if present (possibly Empty). We
187 -- treat these as spec expressions (i.e. similar to a default expression).
188
189 procedure rv;
190 -- This is a dummy function called by the processing for pragma Reviewable.
191 -- It is there for assisting front end debugging. By placing a Reviewable
192 -- pragma in the source program, a breakpoint on rv catches this place in
193 -- the source, allowing convenient stepping to the point of interest.
194
195 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
196 -- Place semantic information on the argument of an Elaborate/Elaborate_All
197 -- pragma. Entity name for unit and its parents is taken from item in
198 -- previous with_clause that mentions the unit.
199
200 -------------------------------
201 -- Adjust_External_Name_Case --
202 -------------------------------
203
204 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
205 CC : Char_Code;
206
207 begin
208 -- Adjust case of literal if required
209
210 if Opt.External_Name_Exp_Casing = As_Is then
211 return N;
212
213 else
214 -- Copy existing string
215
216 Start_String;
217
218 -- Set proper casing
219
220 for J in 1 .. String_Length (Strval (N)) loop
221 CC := Get_String_Char (Strval (N), J);
222
223 if Opt.External_Name_Exp_Casing = Uppercase
224 and then CC >= Get_Char_Code ('a')
225 and then CC <= Get_Char_Code ('z')
226 then
227 Store_String_Char (CC - 32);
228
229 elsif Opt.External_Name_Exp_Casing = Lowercase
230 and then CC >= Get_Char_Code ('A')
231 and then CC <= Get_Char_Code ('Z')
232 then
233 Store_String_Char (CC + 32);
234
235 else
236 Store_String_Char (CC);
237 end if;
238 end loop;
239
240 return
241 Make_String_Literal (Sloc (N),
242 Strval => End_String);
243 end if;
244 end Adjust_External_Name_Case;
245
246 ------------------------------
247 -- Analyze_CTC_In_Decl_Part --
248 ------------------------------
249
250 procedure Analyze_CTC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
251 begin
252 -- Install formals and push subprogram spec onto scope stack so that we
253 -- can see the formals from the pragma.
254
255 Install_Formals (S);
256 Push_Scope (S);
257
258 -- Preanalyze the boolean expressions, we treat these as spec
259 -- expressions (i.e. similar to a default expression).
260
261 Preanalyze_CTC_Args
262 (N,
263 Get_Requires_From_CTC_Pragma (N),
264 Get_Ensures_From_CTC_Pragma (N));
265
266 -- Remove the subprogram from the scope stack now that the pre-analysis
267 -- of the expressions in the contract case or test case is done.
268
269 End_Scope;
270 end Analyze_CTC_In_Decl_Part;
271
272 ------------------------------
273 -- Analyze_PPC_In_Decl_Part --
274 ------------------------------
275
276 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
277 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
278
279 begin
280 -- Install formals and push subprogram spec onto scope stack so that we
281 -- can see the formals from the pragma.
282
283 Install_Formals (S);
284 Push_Scope (S);
285
286 -- Preanalyze the boolean expression, we treat this as a spec expression
287 -- (i.e. similar to a default expression).
288
289 Preanalyze_Assert_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean);
290
291 -- In ASIS mode, for a pragma generated from a source aspect, also
292 -- analyze the original aspect expression.
293
294 if ASIS_Mode
295 and then Present (Corresponding_Aspect (N))
296 then
297 Preanalyze_Assert_Expression
298 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
299 end if;
300
301 -- For a class-wide condition, a reference to a controlling formal must
302 -- be interpreted as having the class-wide type (or an access to such)
303 -- so that the inherited condition can be properly applied to any
304 -- overriding operation (see ARM12 6.6.1 (7)).
305
306 if Class_Present (N) then
307 Class_Wide_Condition : declare
308 T : constant Entity_Id := Find_Dispatching_Type (S);
309
310 ACW : Entity_Id := Empty;
311 -- Access to T'class, created if there is a controlling formal
312 -- that is an access parameter.
313
314 function Get_ACW return Entity_Id;
315 -- If the expression has a reference to an controlling access
316 -- parameter, create an access to T'class for the necessary
317 -- conversions if one does not exist.
318
319 function Process (N : Node_Id) return Traverse_Result;
320 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
321 -- aspect for a primitive subprogram of a tagged type T, a name
322 -- that denotes a formal parameter of type T is interpreted as
323 -- having type T'Class. Similarly, a name that denotes a formal
324 -- accessparameter of type access-to-T is interpreted as having
325 -- type access-to-T'Class. This ensures the expression is well-
326 -- defined for a primitive subprogram of a type descended from T.
327
328 -------------
329 -- Get_ACW --
330 -------------
331
332 function Get_ACW return Entity_Id is
333 Loc : constant Source_Ptr := Sloc (N);
334 Decl : Node_Id;
335
336 begin
337 if No (ACW) then
338 Decl := Make_Full_Type_Declaration (Loc,
339 Defining_Identifier => Make_Temporary (Loc, 'T'),
340 Type_Definition =>
341 Make_Access_To_Object_Definition (Loc,
342 Subtype_Indication =>
343 New_Occurrence_Of (Class_Wide_Type (T), Loc),
344 All_Present => True));
345
346 Insert_Before (Unit_Declaration_Node (S), Decl);
347 Analyze (Decl);
348 ACW := Defining_Identifier (Decl);
349 Freeze_Before (Unit_Declaration_Node (S), ACW);
350 end if;
351
352 return ACW;
353 end Get_ACW;
354
355 -------------
356 -- Process --
357 -------------
358
359 function Process (N : Node_Id) return Traverse_Result is
360 Loc : constant Source_Ptr := Sloc (N);
361 Typ : Entity_Id;
362
363 begin
364 if Is_Entity_Name (N)
365 and then Is_Formal (Entity (N))
366 and then Nkind (Parent (N)) /= N_Type_Conversion
367 then
368 if Etype (Entity (N)) = T then
369 Typ := Class_Wide_Type (T);
370
371 elsif Is_Access_Type (Etype (Entity (N)))
372 and then Designated_Type (Etype (Entity (N))) = T
373 then
374 Typ := Get_ACW;
375 else
376 Typ := Empty;
377 end if;
378
379 if Present (Typ) then
380 Rewrite (N,
381 Make_Type_Conversion (Loc,
382 Subtype_Mark =>
383 New_Occurrence_Of (Typ, Loc),
384 Expression => New_Occurrence_Of (Entity (N), Loc)));
385 Set_Etype (N, Typ);
386 end if;
387 end if;
388
389 return OK;
390 end Process;
391
392 procedure Replace_Type is new Traverse_Proc (Process);
393
394 -- Start of processing for Class_Wide_Condition
395
396 begin
397 if not Present (T) then
398 Error_Msg_Name_1 :=
399 Chars (Identifier (Corresponding_Aspect (N)));
400
401 Error_Msg_Name_2 := Name_Class;
402
403 Error_Msg_N
404 ("aspect `%''%` can only be specified for a primitive " &
405 "operation of a tagged type",
406 Corresponding_Aspect (N));
407 end if;
408
409 Replace_Type (Get_Pragma_Arg (Arg1));
410 end Class_Wide_Condition;
411 end if;
412
413 -- Remove the subprogram from the scope stack now that the pre-analysis
414 -- of the precondition/postcondition is done.
415
416 End_Scope;
417 end Analyze_PPC_In_Decl_Part;
418
419 --------------------
420 -- Analyze_Pragma --
421 --------------------
422
423 procedure Analyze_Pragma (N : Node_Id) is
424 Loc : constant Source_Ptr := Sloc (N);
425 Prag_Id : Pragma_Id;
426
427 Pname : Name_Id;
428 -- Name of the source pragma, or name of the corresponding aspect for
429 -- pragmas which originate in a source aspect. In the latter case, the
430 -- name may be different from the pragma name.
431
432 Pragma_Exit : exception;
433 -- This exception is used to exit pragma processing completely. It is
434 -- used when an error is detected, and no further processing is
435 -- required. It is also used if an earlier error has left the tree in
436 -- a state where the pragma should not be processed.
437
438 Arg_Count : Nat;
439 -- Number of pragma argument associations
440
441 Arg1 : Node_Id;
442 Arg2 : Node_Id;
443 Arg3 : Node_Id;
444 Arg4 : Node_Id;
445 -- First four pragma arguments (pragma argument association nodes, or
446 -- Empty if the corresponding argument does not exist).
447
448 type Name_List is array (Natural range <>) of Name_Id;
449 type Args_List is array (Natural range <>) of Node_Id;
450 -- Types used for arguments to Check_Arg_Order and Gather_Associations
451
452 procedure Ada_2005_Pragma;
453 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
454 -- Ada 95 mode, these are implementation defined pragmas, so should be
455 -- caught by the No_Implementation_Pragmas restriction.
456
457 procedure Ada_2012_Pragma;
458 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
459 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
460 -- should be caught by the No_Implementation_Pragmas restriction.
461
462 procedure Check_Ada_83_Warning;
463 -- Issues a warning message for the current pragma if operating in Ada
464 -- 83 mode (used for language pragmas that are not a standard part of
465 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
466 -- of 95 pragma.
467
468 procedure Check_Arg_Count (Required : Nat);
469 -- Check argument count for pragma is equal to given parameter. If not,
470 -- then issue an error message and raise Pragma_Exit.
471
472 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
473 -- Arg which can either be a pragma argument association, in which case
474 -- the check is applied to the expression of the association or an
475 -- expression directly.
476
477 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
478 -- Check that an argument has the right form for an EXTERNAL_NAME
479 -- parameter of an extended import/export pragma. The rule is that the
480 -- name must be an identifier or string literal (in Ada 83 mode) or a
481 -- static string expression (in Ada 95 mode).
482
483 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
484 -- Check the specified argument Arg to make sure that it is an
485 -- identifier. If not give error and raise Pragma_Exit.
486
487 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
488 -- Check the specified argument Arg to make sure that it is an integer
489 -- literal. If not give error and raise Pragma_Exit.
490
491 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
492 -- Check the specified argument Arg to make sure that it has the proper
493 -- syntactic form for a local name and meets the semantic requirements
494 -- for a local name. The local name is analyzed as part of the
495 -- processing for this call. In addition, the local name is required
496 -- to represent an entity at the library level.
497
498 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
499 -- Check the specified argument Arg to make sure that it has the proper
500 -- syntactic form for a local name and meets the semantic requirements
501 -- for a local name. The local name is analyzed as part of the
502 -- processing for this call.
503
504 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
505 -- Check the specified argument Arg to make sure that it is a valid
506 -- locking policy name. If not give error and raise Pragma_Exit.
507
508 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
509 -- Check the specified argument Arg to make sure that it is a valid
510 -- elaboration policy name. If not give error and raise Pragma_Exit.
511
512 procedure Check_Arg_Is_One_Of
513 (Arg : Node_Id;
514 N1, N2 : Name_Id);
515 procedure Check_Arg_Is_One_Of
516 (Arg : Node_Id;
517 N1, N2, N3 : Name_Id);
518 procedure Check_Arg_Is_One_Of
519 (Arg : Node_Id;
520 N1, N2, N3, N4 : Name_Id);
521 procedure Check_Arg_Is_One_Of
522 (Arg : Node_Id;
523 N1, N2, N3, N4, N5 : Name_Id);
524 -- Check the specified argument Arg to make sure that it is an
525 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
526 -- present). If not then give error and raise Pragma_Exit.
527
528 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
529 -- Check the specified argument Arg to make sure that it is a valid
530 -- queuing policy name. If not give error and raise Pragma_Exit.
531
532 procedure Check_Arg_Is_Static_Expression
533 (Arg : Node_Id;
534 Typ : Entity_Id := Empty);
535 -- Check the specified argument Arg to make sure that it is a static
536 -- expression of the given type (i.e. it will be analyzed and resolved
537 -- using this type, which can be any valid argument to Resolve, e.g.
538 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
539 -- Typ is left Empty, then any static expression is allowed.
540
541 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
542 -- Check the specified argument Arg to make sure that it is a valid task
543 -- dispatching policy name. If not give error and raise Pragma_Exit.
544
545 procedure Check_Arg_Order (Names : Name_List);
546 -- Checks for an instance of two arguments with identifiers for the
547 -- current pragma which are not in the sequence indicated by Names,
548 -- and if so, generates a fatal message about bad order of arguments.
549
550 procedure Check_At_Least_N_Arguments (N : Nat);
551 -- Check there are at least N arguments present
552
553 procedure Check_At_Most_N_Arguments (N : Nat);
554 -- Check there are no more than N arguments present
555
556 procedure Check_Component
557 (Comp : Node_Id;
558 UU_Typ : Entity_Id;
559 In_Variant_Part : Boolean := False);
560 -- Examine an Unchecked_Union component for correct use of per-object
561 -- constrained subtypes, and for restrictions on finalizable components.
562 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
563 -- should be set when Comp comes from a record variant.
564
565 procedure Check_Contract_Or_Test_Case;
566 -- Called to process a contract-case or test-case pragma. It
567 -- starts with checking pragma arguments, and the rest of the
568 -- treatment is similar to the one for pre- and postcondition in
569 -- Check_Precondition_Postcondition, except the placement rules for the
570 -- contract-case and test-case pragmas are stricter. These pragmas may
571 -- only occur after a subprogram spec declared directly in a package
572 -- spec unit. In this case, the pragma is chained to the subprogram in
573 -- question (using Spec_CTC_List and Next_Pragma) and analysis of the
574 -- pragma is delayed till the end of the spec. In all other cases, an
575 -- error message for bad placement is given.
576
577 procedure Check_Duplicate_Pragma (E : Entity_Id);
578 -- Check if a rep item of the same name as the current pragma is already
579 -- chained as a rep pragma to the given entity. If so give a message
580 -- about the duplicate, and then raise Pragma_Exit so does not return.
581
582 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
583 -- Nam is an N_String_Literal node containing the external name set by
584 -- an Import or Export pragma (or extended Import or Export pragma).
585 -- This procedure checks for possible duplications if this is the export
586 -- case, and if found, issues an appropriate error message.
587
588 procedure Check_Expr_Is_Static_Expression
589 (Expr : Node_Id;
590 Typ : Entity_Id := Empty);
591 -- Check the specified expression Expr to make sure that it is a static
592 -- expression of the given type (i.e. it will be analyzed and resolved
593 -- using this type, which can be any valid argument to Resolve, e.g.
594 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
595 -- Typ is left Empty, then any static expression is allowed.
596
597 procedure Check_First_Subtype (Arg : Node_Id);
598 -- Checks that Arg, whose expression is an entity name, references a
599 -- first subtype.
600
601 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
602 -- Checks that the given argument has an identifier, and if so, requires
603 -- it to match the given identifier name. If there is no identifier, or
604 -- a non-matching identifier, then an error message is given and
605 -- Pragma_Exit is raised.
606
607 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
608 -- Checks that the given argument has an identifier, and if so, requires
609 -- it to match one of the given identifier names. If there is no
610 -- identifier, or a non-matching identifier, then an error message is
611 -- given and Pragma_Exit is raised.
612
613 procedure Check_In_Main_Program;
614 -- Common checks for pragmas that appear within a main program
615 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
616
617 procedure Check_Interrupt_Or_Attach_Handler;
618 -- Common processing for first argument of pragma Interrupt_Handler or
619 -- pragma Attach_Handler.
620
621 procedure Check_Loop_Pragma_Placement;
622 -- Verify whether pragma Loop_Invariant or Loop_Optimize or Loop_Variant
623 -- appear immediately within a construct restricted to loops.
624
625 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
626 -- Check that pragma appears in a declarative part, or in a package
627 -- specification, i.e. that it does not occur in a statement sequence
628 -- in a body.
629
630 procedure Check_No_Identifier (Arg : Node_Id);
631 -- Checks that the given argument does not have an identifier. If
632 -- an identifier is present, then an error message is issued, and
633 -- Pragma_Exit is raised.
634
635 procedure Check_No_Identifiers;
636 -- Checks that none of the arguments to the pragma has an identifier.
637 -- If any argument has an identifier, then an error message is issued,
638 -- and Pragma_Exit is raised.
639
640 procedure Check_No_Link_Name;
641 -- Checks that no link name is specified
642
643 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
644 -- Checks if the given argument has an identifier, and if so, requires
645 -- it to match the given identifier name. If there is a non-matching
646 -- identifier, then an error message is given and Pragma_Exit is raised.
647
648 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
649 -- Checks if the given argument has an identifier, and if so, requires
650 -- it to match the given identifier name. If there is a non-matching
651 -- identifier, then an error message is given and Pragma_Exit is raised.
652 -- In this version of the procedure, the identifier name is given as
653 -- a string with lower case letters.
654
655 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
656 -- Called to process a precondition or postcondition pragma. There are
657 -- three cases:
658 --
659 -- The pragma appears after a subprogram spec
660 --
661 -- If the corresponding check is not enabled, the pragma is analyzed
662 -- but otherwise ignored and control returns with In_Body set False.
663 --
664 -- If the check is enabled, then the first step is to analyze the
665 -- pragma, but this is skipped if the subprogram spec appears within
666 -- a package specification (because this is the case where we delay
667 -- analysis till the end of the spec). Then (whether or not it was
668 -- analyzed), the pragma is chained to the subprogram in question
669 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
670 -- caller with In_Body set False.
671 --
672 -- The pragma appears at the start of subprogram body declarations
673 --
674 -- In this case an immediate return to the caller is made with
675 -- In_Body set True, and the pragma is NOT analyzed.
676 --
677 -- In all other cases, an error message for bad placement is given
678
679 procedure Check_Static_Constraint (Constr : Node_Id);
680 -- Constr is a constraint from an N_Subtype_Indication node from a
681 -- component constraint in an Unchecked_Union type. This routine checks
682 -- that the constraint is static as required by the restrictions for
683 -- Unchecked_Union.
684
685 procedure Check_Valid_Configuration_Pragma;
686 -- Legality checks for placement of a configuration pragma
687
688 procedure Check_Valid_Library_Unit_Pragma;
689 -- Legality checks for library unit pragmas. A special case arises for
690 -- pragmas in generic instances that come from copies of the original
691 -- library unit pragmas in the generic templates. In the case of other
692 -- than library level instantiations these can appear in contexts which
693 -- would normally be invalid (they only apply to the original template
694 -- and to library level instantiations), and they are simply ignored,
695 -- which is implemented by rewriting them as null statements.
696
697 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
698 -- Check an Unchecked_Union variant for lack of nested variants and
699 -- presence of at least one component. UU_Typ is the related Unchecked_
700 -- Union type.
701
702 procedure Error_Pragma (Msg : String);
703 pragma No_Return (Error_Pragma);
704 -- Outputs error message for current pragma. The message contains a %
705 -- that will be replaced with the pragma name, and the flag is placed
706 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
707 -- calls Fix_Error (see spec of that function for details).
708
709 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
710 pragma No_Return (Error_Pragma_Arg);
711 -- Outputs error message for current pragma. The message may contain
712 -- a % that will be replaced with the pragma name. The parameter Arg
713 -- may either be a pragma argument association, in which case the flag
714 -- is placed on the expression of this association, or an expression,
715 -- in which case the flag is placed directly on the expression. The
716 -- message is placed using Error_Msg_N, so the message may also contain
717 -- an & insertion character which will reference the given Arg value.
718 -- After placing the message, Pragma_Exit is raised. Note: this routine
719 -- calls Fix_Error (see spec of that function for details).
720
721 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
722 pragma No_Return (Error_Pragma_Arg);
723 -- Similar to above form of Error_Pragma_Arg except that two messages
724 -- are provided, the second is a continuation comment starting with \.
725
726 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
727 pragma No_Return (Error_Pragma_Arg_Ident);
728 -- Outputs error message for current pragma. The message may contain
729 -- a % that will be replaced with the pragma name. The parameter Arg
730 -- must be a pragma argument association with a non-empty identifier
731 -- (i.e. its Chars field must be set), and the error message is placed
732 -- on the identifier. The message is placed using Error_Msg_N so
733 -- the message may also contain an & insertion character which will
734 -- reference the identifier. After placing the message, Pragma_Exit
735 -- is raised. Note: this routine calls Fix_Error (see spec of that
736 -- function for details).
737
738 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
739 pragma No_Return (Error_Pragma_Ref);
740 -- Outputs error message for current pragma. The message may contain
741 -- a % that will be replaced with the pragma name. The parameter Ref
742 -- must be an entity whose name can be referenced by & and sloc by #.
743 -- After placing the message, Pragma_Exit is raised. Note: this routine
744 -- calls Fix_Error (see spec of that function for details).
745
746 function Find_Lib_Unit_Name return Entity_Id;
747 -- Used for a library unit pragma to find the entity to which the
748 -- library unit pragma applies, returns the entity found.
749
750 procedure Find_Program_Unit_Name (Id : Node_Id);
751 -- If the pragma is a compilation unit pragma, the id must denote the
752 -- compilation unit in the same compilation, and the pragma must appear
753 -- in the list of preceding or trailing pragmas. If it is a program
754 -- unit pragma that is not a compilation unit pragma, then the
755 -- identifier must be visible.
756
757 function Find_Unique_Parameterless_Procedure
758 (Name : Entity_Id;
759 Arg : Node_Id) return Entity_Id;
760 -- Used for a procedure pragma to find the unique parameterless
761 -- procedure identified by Name, returns it if it exists, otherwise
762 -- errors out and uses Arg as the pragma argument for the message.
763
764 procedure Fix_Error (Msg : in out String);
765 -- This is called prior to issuing an error message. Msg is a string
766 -- that typically contains the substring "pragma". If the current pragma
767 -- comes from an aspect, each such "pragma" substring is replaced with
768 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
769 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
770
771 procedure Gather_Associations
772 (Names : Name_List;
773 Args : out Args_List);
774 -- This procedure is used to gather the arguments for a pragma that
775 -- permits arbitrary ordering of parameters using the normal rules
776 -- for named and positional parameters. The Names argument is a list
777 -- of Name_Id values that corresponds to the allowed pragma argument
778 -- association identifiers in order. The result returned in Args is
779 -- a list of corresponding expressions that are the pragma arguments.
780 -- Note that this is a list of expressions, not of pragma argument
781 -- associations (Gather_Associations has completely checked all the
782 -- optional identifiers when it returns). An entry in Args is Empty
783 -- on return if the corresponding argument is not present.
784
785 procedure GNAT_Pragma;
786 -- Called for all GNAT defined pragmas to check the relevant restriction
787 -- (No_Implementation_Pragmas).
788
789 procedure S14_Pragma;
790 -- Called for all pragmas defined for formal verification to check that
791 -- the S14_Extensions flag is set.
792 -- This name needs fixing ??? There is no such thing as an
793 -- "S14_Extensions" flag ???
794
795 function Is_Before_First_Decl
796 (Pragma_Node : Node_Id;
797 Decls : List_Id) return Boolean;
798 -- Return True if Pragma_Node is before the first declarative item in
799 -- Decls where Decls is the list of declarative items.
800
801 function Is_Configuration_Pragma return Boolean;
802 -- Determines if the placement of the current pragma is appropriate
803 -- for a configuration pragma.
804
805 function Is_In_Context_Clause return Boolean;
806 -- Returns True if pragma appears within the context clause of a unit,
807 -- and False for any other placement (does not generate any messages).
808
809 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
810 -- Analyzes the argument, and determines if it is a static string
811 -- expression, returns True if so, False if non-static or not String.
812
813 procedure Pragma_Misplaced;
814 pragma No_Return (Pragma_Misplaced);
815 -- Issue fatal error message for misplaced pragma
816
817 procedure Process_Atomic_Shared_Volatile;
818 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
819 -- Shared is an obsolete Ada 83 pragma, treated as being identical
820 -- in effect to pragma Atomic.
821
822 procedure Process_Compile_Time_Warning_Or_Error;
823 -- Common processing for Compile_Time_Error and Compile_Time_Warning
824
825 procedure Process_Convention
826 (C : out Convention_Id;
827 Ent : out Entity_Id);
828 -- Common processing for Convention, Interface, Import and Export.
829 -- Checks first two arguments of pragma, and sets the appropriate
830 -- convention value in the specified entity or entities. On return
831 -- C is the convention, Ent is the referenced entity.
832
833 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
834 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
835 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
836
837 procedure Process_Extended_Import_Export_Exception_Pragma
838 (Arg_Internal : Node_Id;
839 Arg_External : Node_Id;
840 Arg_Form : Node_Id;
841 Arg_Code : Node_Id);
842 -- Common processing for the pragmas Import/Export_Exception. The three
843 -- arguments correspond to the three named parameters of the pragma. An
844 -- argument is empty if the corresponding parameter is not present in
845 -- the pragma.
846
847 procedure Process_Extended_Import_Export_Object_Pragma
848 (Arg_Internal : Node_Id;
849 Arg_External : Node_Id;
850 Arg_Size : Node_Id);
851 -- Common processing for the pragmas Import/Export_Object. The three
852 -- arguments correspond to the three named parameters of the pragmas. An
853 -- argument is empty if the corresponding parameter is not present in
854 -- the pragma.
855
856 procedure Process_Extended_Import_Export_Internal_Arg
857 (Arg_Internal : Node_Id := Empty);
858 -- Common processing for all extended Import and Export pragmas. The
859 -- argument is the pragma parameter for the Internal argument. If
860 -- Arg_Internal is empty or inappropriate, an error message is posted.
861 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
862 -- set to identify the referenced entity.
863
864 procedure Process_Extended_Import_Export_Subprogram_Pragma
865 (Arg_Internal : Node_Id;
866 Arg_External : Node_Id;
867 Arg_Parameter_Types : Node_Id;
868 Arg_Result_Type : Node_Id := Empty;
869 Arg_Mechanism : Node_Id;
870 Arg_Result_Mechanism : Node_Id := Empty;
871 Arg_First_Optional_Parameter : Node_Id := Empty);
872 -- Common processing for all extended Import and Export pragmas applying
873 -- to subprograms. The caller omits any arguments that do not apply to
874 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
875 -- only in the Import_Function and Export_Function cases). The argument
876 -- names correspond to the allowed pragma association identifiers.
877
878 procedure Process_Generic_List;
879 -- Common processing for Share_Generic and Inline_Generic
880
881 procedure Process_Import_Or_Interface;
882 -- Common processing for Import of Interface
883
884 procedure Process_Import_Predefined_Type;
885 -- Processing for completing a type with pragma Import. This is used
886 -- to declare types that match predefined C types, especially for cases
887 -- without corresponding Ada predefined type.
888
889 type Inline_Status is (Suppressed, Disabled, Enabled);
890 -- Inline status of a subprogram, indicated as follows:
891 -- Suppressed: inlining is suppressed for the subprogram
892 -- Disabled: no inlining is requested for the subprogram
893 -- Enabled: inlining is requested/required for the subprogram
894
895 procedure Process_Inline (Status : Inline_Status);
896 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
897 -- indicates the inline status specified by the pragma.
898
899 procedure Process_Interface_Name
900 (Subprogram_Def : Entity_Id;
901 Ext_Arg : Node_Id;
902 Link_Arg : Node_Id);
903 -- Given the last two arguments of pragma Import, pragma Export, or
904 -- pragma Interface_Name, performs validity checks and sets the
905 -- Interface_Name field of the given subprogram entity to the
906 -- appropriate external or link name, depending on the arguments given.
907 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
908 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
909 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
910 -- nor Link_Arg is present, the interface name is set to the default
911 -- from the subprogram name.
912
913 procedure Process_Interrupt_Or_Attach_Handler;
914 -- Common processing for Interrupt and Attach_Handler pragmas
915
916 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
917 -- Common processing for Restrictions and Restriction_Warnings pragmas.
918 -- Warn is True for Restriction_Warnings, or for Restrictions if the
919 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
920 -- is not set in the Restrictions case.
921
922 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
923 -- Common processing for Suppress and Unsuppress. The boolean parameter
924 -- Suppress_Case is True for the Suppress case, and False for the
925 -- Unsuppress case.
926
927 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
928 -- This procedure sets the Is_Exported flag for the given entity,
929 -- checking that the entity was not previously imported. Arg is
930 -- the argument that specified the entity. A check is also made
931 -- for exporting inappropriate entities.
932
933 procedure Set_Extended_Import_Export_External_Name
934 (Internal_Ent : Entity_Id;
935 Arg_External : Node_Id);
936 -- Common processing for all extended import export pragmas. The first
937 -- argument, Internal_Ent, is the internal entity, which has already
938 -- been checked for validity by the caller. Arg_External is from the
939 -- Import or Export pragma, and may be null if no External parameter
940 -- was present. If Arg_External is present and is a non-null string
941 -- (a null string is treated as the default), then the Interface_Name
942 -- field of Internal_Ent is set appropriately.
943
944 procedure Set_Imported (E : Entity_Id);
945 -- This procedure sets the Is_Imported flag for the given entity,
946 -- checking that it is not previously exported or imported.
947
948 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
949 -- Mech is a parameter passing mechanism (see Import_Function syntax
950 -- for MECHANISM_NAME). This routine checks that the mechanism argument
951 -- has the right form, and if not issues an error message. If the
952 -- argument has the right form then the Mechanism field of Ent is
953 -- set appropriately.
954
955 procedure Set_Rational_Profile;
956 -- Activate the set of configuration pragmas and permissions that make
957 -- up the Rational profile.
958
959 procedure Set_Ravenscar_Profile (N : Node_Id);
960 -- Activate the set of configuration pragmas and restrictions that make
961 -- up the Ravenscar Profile. N is the corresponding pragma node, which
962 -- is used for error messages on any constructs that violate the
963 -- profile.
964
965 ---------------------
966 -- Ada_2005_Pragma --
967 ---------------------
968
969 procedure Ada_2005_Pragma is
970 begin
971 if Ada_Version <= Ada_95 then
972 Check_Restriction (No_Implementation_Pragmas, N);
973 end if;
974 end Ada_2005_Pragma;
975
976 ---------------------
977 -- Ada_2012_Pragma --
978 ---------------------
979
980 procedure Ada_2012_Pragma is
981 begin
982 if Ada_Version <= Ada_2005 then
983 Check_Restriction (No_Implementation_Pragmas, N);
984 end if;
985 end Ada_2012_Pragma;
986
987 --------------------------
988 -- Check_Ada_83_Warning --
989 --------------------------
990
991 procedure Check_Ada_83_Warning is
992 begin
993 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
994 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
995 end if;
996 end Check_Ada_83_Warning;
997
998 ---------------------
999 -- Check_Arg_Count --
1000 ---------------------
1001
1002 procedure Check_Arg_Count (Required : Nat) is
1003 begin
1004 if Arg_Count /= Required then
1005 Error_Pragma ("wrong number of arguments for pragma%");
1006 end if;
1007 end Check_Arg_Count;
1008
1009 --------------------------------
1010 -- Check_Arg_Is_External_Name --
1011 --------------------------------
1012
1013 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
1014 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1015
1016 begin
1017 if Nkind (Argx) = N_Identifier then
1018 return;
1019
1020 else
1021 Analyze_And_Resolve (Argx, Standard_String);
1022
1023 if Is_OK_Static_Expression (Argx) then
1024 return;
1025
1026 elsif Etype (Argx) = Any_Type then
1027 raise Pragma_Exit;
1028
1029 -- An interesting special case, if we have a string literal and
1030 -- we are in Ada 83 mode, then we allow it even though it will
1031 -- not be flagged as static. This allows expected Ada 83 mode
1032 -- use of external names which are string literals, even though
1033 -- technically these are not static in Ada 83.
1034
1035 elsif Ada_Version = Ada_83
1036 and then Nkind (Argx) = N_String_Literal
1037 then
1038 return;
1039
1040 -- Static expression that raises Constraint_Error. This has
1041 -- already been flagged, so just exit from pragma processing.
1042
1043 elsif Is_Static_Expression (Argx) then
1044 raise Pragma_Exit;
1045
1046 -- Here we have a real error (non-static expression)
1047
1048 else
1049 Error_Msg_Name_1 := Pname;
1050
1051 declare
1052 Msg : String :=
1053 "argument for pragma% must be a identifier or "
1054 & "static string expression!";
1055 begin
1056 Fix_Error (Msg);
1057 Flag_Non_Static_Expr (Msg, Argx);
1058 raise Pragma_Exit;
1059 end;
1060 end if;
1061 end if;
1062 end Check_Arg_Is_External_Name;
1063
1064 -----------------------------
1065 -- Check_Arg_Is_Identifier --
1066 -----------------------------
1067
1068 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
1069 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1070 begin
1071 if Nkind (Argx) /= N_Identifier then
1072 Error_Pragma_Arg
1073 ("argument for pragma% must be identifier", Argx);
1074 end if;
1075 end Check_Arg_Is_Identifier;
1076
1077 ----------------------------------
1078 -- Check_Arg_Is_Integer_Literal --
1079 ----------------------------------
1080
1081 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1082 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1083 begin
1084 if Nkind (Argx) /= N_Integer_Literal then
1085 Error_Pragma_Arg
1086 ("argument for pragma% must be integer literal", Argx);
1087 end if;
1088 end Check_Arg_Is_Integer_Literal;
1089
1090 -------------------------------------------
1091 -- Check_Arg_Is_Library_Level_Local_Name --
1092 -------------------------------------------
1093
1094 -- LOCAL_NAME ::=
1095 -- DIRECT_NAME
1096 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1097 -- | library_unit_NAME
1098
1099 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1100 begin
1101 Check_Arg_Is_Local_Name (Arg);
1102
1103 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1104 and then Comes_From_Source (N)
1105 then
1106 Error_Pragma_Arg
1107 ("argument for pragma% must be library level entity", Arg);
1108 end if;
1109 end Check_Arg_Is_Library_Level_Local_Name;
1110
1111 -----------------------------
1112 -- Check_Arg_Is_Local_Name --
1113 -----------------------------
1114
1115 -- LOCAL_NAME ::=
1116 -- DIRECT_NAME
1117 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1118 -- | library_unit_NAME
1119
1120 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1121 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1122
1123 begin
1124 Analyze (Argx);
1125
1126 if Nkind (Argx) not in N_Direct_Name
1127 and then (Nkind (Argx) /= N_Attribute_Reference
1128 or else Present (Expressions (Argx))
1129 or else Nkind (Prefix (Argx)) /= N_Identifier)
1130 and then (not Is_Entity_Name (Argx)
1131 or else not Is_Compilation_Unit (Entity (Argx)))
1132 then
1133 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1134 end if;
1135
1136 -- No further check required if not an entity name
1137
1138 if not Is_Entity_Name (Argx) then
1139 null;
1140
1141 else
1142 declare
1143 OK : Boolean;
1144 Ent : constant Entity_Id := Entity (Argx);
1145 Scop : constant Entity_Id := Scope (Ent);
1146 begin
1147 -- Case of a pragma applied to a compilation unit: pragma must
1148 -- occur immediately after the program unit in the compilation.
1149
1150 if Is_Compilation_Unit (Ent) then
1151 declare
1152 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1153
1154 begin
1155 -- Case of pragma placed immediately after spec
1156
1157 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1158 OK := True;
1159
1160 -- Case of pragma placed immediately after body
1161
1162 elsif Nkind (Decl) = N_Subprogram_Declaration
1163 and then Present (Corresponding_Body (Decl))
1164 then
1165 OK := Parent (N) =
1166 Aux_Decls_Node
1167 (Parent (Unit_Declaration_Node
1168 (Corresponding_Body (Decl))));
1169
1170 -- All other cases are illegal
1171
1172 else
1173 OK := False;
1174 end if;
1175 end;
1176
1177 -- Special restricted placement rule from 10.2.1(11.8/2)
1178
1179 elsif Is_Generic_Formal (Ent)
1180 and then Prag_Id = Pragma_Preelaborable_Initialization
1181 then
1182 OK := List_Containing (N) =
1183 Generic_Formal_Declarations
1184 (Unit_Declaration_Node (Scop));
1185
1186 -- Default case, just check that the pragma occurs in the scope
1187 -- of the entity denoted by the name.
1188
1189 else
1190 OK := Current_Scope = Scop;
1191 end if;
1192
1193 if not OK then
1194 Error_Pragma_Arg
1195 ("pragma% argument must be in same declarative part", Arg);
1196 end if;
1197 end;
1198 end if;
1199 end Check_Arg_Is_Local_Name;
1200
1201 ---------------------------------
1202 -- Check_Arg_Is_Locking_Policy --
1203 ---------------------------------
1204
1205 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1206 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1207
1208 begin
1209 Check_Arg_Is_Identifier (Argx);
1210
1211 if not Is_Locking_Policy_Name (Chars (Argx)) then
1212 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1213 end if;
1214 end Check_Arg_Is_Locking_Policy;
1215
1216 -----------------------------------------------
1217 -- Check_Arg_Is_Partition_Elaboration_Policy --
1218 -----------------------------------------------
1219
1220 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
1221 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1222
1223 begin
1224 Check_Arg_Is_Identifier (Argx);
1225
1226 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
1227 Error_Pragma_Arg
1228 ("& is not a valid partition elaboration policy name", Argx);
1229 end if;
1230 end Check_Arg_Is_Partition_Elaboration_Policy;
1231
1232 -------------------------
1233 -- Check_Arg_Is_One_Of --
1234 -------------------------
1235
1236 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1237 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1238
1239 begin
1240 Check_Arg_Is_Identifier (Argx);
1241
1242 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1243 Error_Msg_Name_2 := N1;
1244 Error_Msg_Name_3 := N2;
1245 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1246 end if;
1247 end Check_Arg_Is_One_Of;
1248
1249 procedure Check_Arg_Is_One_Of
1250 (Arg : Node_Id;
1251 N1, N2, N3 : Name_Id)
1252 is
1253 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1254
1255 begin
1256 Check_Arg_Is_Identifier (Argx);
1257
1258 if Chars (Argx) /= N1
1259 and then Chars (Argx) /= N2
1260 and then Chars (Argx) /= N3
1261 then
1262 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1263 end if;
1264 end Check_Arg_Is_One_Of;
1265
1266 procedure Check_Arg_Is_One_Of
1267 (Arg : Node_Id;
1268 N1, N2, N3, N4 : Name_Id)
1269 is
1270 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1271
1272 begin
1273 Check_Arg_Is_Identifier (Argx);
1274
1275 if Chars (Argx) /= N1
1276 and then Chars (Argx) /= N2
1277 and then Chars (Argx) /= N3
1278 and then Chars (Argx) /= N4
1279 then
1280 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1281 end if;
1282 end Check_Arg_Is_One_Of;
1283
1284 procedure Check_Arg_Is_One_Of
1285 (Arg : Node_Id;
1286 N1, N2, N3, N4, N5 : Name_Id)
1287 is
1288 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1289
1290 begin
1291 Check_Arg_Is_Identifier (Argx);
1292
1293 if Chars (Argx) /= N1
1294 and then Chars (Argx) /= N2
1295 and then Chars (Argx) /= N3
1296 and then Chars (Argx) /= N4
1297 and then Chars (Argx) /= N5
1298 then
1299 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1300 end if;
1301 end Check_Arg_Is_One_Of;
1302
1303 ---------------------------------
1304 -- Check_Arg_Is_Queuing_Policy --
1305 ---------------------------------
1306
1307 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1308 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1309
1310 begin
1311 Check_Arg_Is_Identifier (Argx);
1312
1313 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1314 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1315 end if;
1316 end Check_Arg_Is_Queuing_Policy;
1317
1318 ------------------------------------
1319 -- Check_Arg_Is_Static_Expression --
1320 ------------------------------------
1321
1322 procedure Check_Arg_Is_Static_Expression
1323 (Arg : Node_Id;
1324 Typ : Entity_Id := Empty)
1325 is
1326 begin
1327 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1328 end Check_Arg_Is_Static_Expression;
1329
1330 ------------------------------------------
1331 -- Check_Arg_Is_Task_Dispatching_Policy --
1332 ------------------------------------------
1333
1334 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1335 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1336
1337 begin
1338 Check_Arg_Is_Identifier (Argx);
1339
1340 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1341 Error_Pragma_Arg
1342 ("& is not a valid task dispatching policy name", Argx);
1343 end if;
1344 end Check_Arg_Is_Task_Dispatching_Policy;
1345
1346 ---------------------
1347 -- Check_Arg_Order --
1348 ---------------------
1349
1350 procedure Check_Arg_Order (Names : Name_List) is
1351 Arg : Node_Id;
1352
1353 Highest_So_Far : Natural := 0;
1354 -- Highest index in Names seen do far
1355
1356 begin
1357 Arg := Arg1;
1358 for J in 1 .. Arg_Count loop
1359 if Chars (Arg) /= No_Name then
1360 for K in Names'Range loop
1361 if Chars (Arg) = Names (K) then
1362 if K < Highest_So_Far then
1363 Error_Msg_Name_1 := Pname;
1364 Error_Msg_N
1365 ("parameters out of order for pragma%", Arg);
1366 Error_Msg_Name_1 := Names (K);
1367 Error_Msg_Name_2 := Names (Highest_So_Far);
1368 Error_Msg_N ("\% must appear before %", Arg);
1369 raise Pragma_Exit;
1370
1371 else
1372 Highest_So_Far := K;
1373 end if;
1374 end if;
1375 end loop;
1376 end if;
1377
1378 Arg := Next (Arg);
1379 end loop;
1380 end Check_Arg_Order;
1381
1382 --------------------------------
1383 -- Check_At_Least_N_Arguments --
1384 --------------------------------
1385
1386 procedure Check_At_Least_N_Arguments (N : Nat) is
1387 begin
1388 if Arg_Count < N then
1389 Error_Pragma ("too few arguments for pragma%");
1390 end if;
1391 end Check_At_Least_N_Arguments;
1392
1393 -------------------------------
1394 -- Check_At_Most_N_Arguments --
1395 -------------------------------
1396
1397 procedure Check_At_Most_N_Arguments (N : Nat) is
1398 Arg : Node_Id;
1399 begin
1400 if Arg_Count > N then
1401 Arg := Arg1;
1402 for J in 1 .. N loop
1403 Next (Arg);
1404 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1405 end loop;
1406 end if;
1407 end Check_At_Most_N_Arguments;
1408
1409 ---------------------
1410 -- Check_Component --
1411 ---------------------
1412
1413 procedure Check_Component
1414 (Comp : Node_Id;
1415 UU_Typ : Entity_Id;
1416 In_Variant_Part : Boolean := False)
1417 is
1418 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1419 Sindic : constant Node_Id :=
1420 Subtype_Indication (Component_Definition (Comp));
1421 Typ : constant Entity_Id := Etype (Comp_Id);
1422
1423 begin
1424 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1425 -- object constraint, then the component type shall be an Unchecked_
1426 -- Union.
1427
1428 if Nkind (Sindic) = N_Subtype_Indication
1429 and then Has_Per_Object_Constraint (Comp_Id)
1430 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1431 then
1432 Error_Msg_N
1433 ("component subtype subject to per-object constraint " &
1434 "must be an Unchecked_Union", Comp);
1435
1436 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1437 -- the body of a generic unit, or within the body of any of its
1438 -- descendant library units, no part of the type of a component
1439 -- declared in a variant_part of the unchecked union type shall be of
1440 -- a formal private type or formal private extension declared within
1441 -- the formal part of the generic unit.
1442
1443 elsif Ada_Version >= Ada_2012
1444 and then In_Generic_Body (UU_Typ)
1445 and then In_Variant_Part
1446 and then Is_Private_Type (Typ)
1447 and then Is_Generic_Type (Typ)
1448 then
1449 Error_Msg_N
1450 ("component of unchecked union cannot be of generic type", Comp);
1451
1452 elsif Needs_Finalization (Typ) then
1453 Error_Msg_N
1454 ("component of unchecked union cannot be controlled", Comp);
1455
1456 elsif Has_Task (Typ) then
1457 Error_Msg_N
1458 ("component of unchecked union cannot have tasks", Comp);
1459 end if;
1460 end Check_Component;
1461
1462 ---------------------------------
1463 -- Check_Contract_Or_Test_Case --
1464 ---------------------------------
1465
1466 procedure Check_Contract_Or_Test_Case is
1467 P : Node_Id;
1468 PO : Node_Id;
1469
1470 procedure Chain_CTC (PO : Node_Id);
1471 -- If PO is a [generic] subprogram declaration node, then the
1472 -- contract-case or test-case applies to this subprogram and the
1473 -- processing for the pragma is completed. Otherwise the pragma
1474 -- is misplaced.
1475
1476 ---------------
1477 -- Chain_CTC --
1478 ---------------
1479
1480 procedure Chain_CTC (PO : Node_Id) is
1481 S : Entity_Id;
1482
1483 begin
1484 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1485 Error_Pragma
1486 ("pragma% cannot be applied to abstract subprogram");
1487
1488 elsif Nkind (PO) = N_Entry_Declaration then
1489 Error_Pragma ("pragma% cannot be applied to entry");
1490
1491 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1492 N_Generic_Subprogram_Declaration)
1493 then
1494 Pragma_Misplaced;
1495 end if;
1496
1497 -- Here if we have [generic] subprogram declaration
1498
1499 S := Defining_Unit_Name (Specification (PO));
1500
1501 -- Note: we do not analyze the pragma at this point. Instead we
1502 -- delay this analysis until the end of the declarative part in
1503 -- which the pragma appears. This implements the required delay
1504 -- in this analysis, allowing forward references. The analysis
1505 -- happens at the end of Analyze_Declarations.
1506
1507 -- There should not be another contract-case or test-case with the
1508 -- same name associated to this subprogram.
1509
1510 declare
1511 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
1512 CTC : Node_Id;
1513
1514 begin
1515 CTC := Spec_CTC_List (Contract (S));
1516 while Present (CTC) loop
1517
1518 -- Omit pragma Contract_Cases because it does not introduce
1519 -- a unique case name and it does not follow the syntax of
1520 -- Contract_Case and Test_Case.
1521
1522 if Pragma_Name (CTC) = Name_Contract_Cases then
1523 null;
1524
1525 elsif String_Equal
1526 (Name, Get_Name_From_CTC_Pragma (CTC))
1527 then
1528 Error_Msg_Sloc := Sloc (CTC);
1529 Error_Pragma ("name for pragma% is already used#");
1530 end if;
1531
1532 CTC := Next_Pragma (CTC);
1533 end loop;
1534 end;
1535
1536 -- Chain spec CTC pragma to list for subprogram
1537
1538 Set_Next_Pragma (N, Spec_CTC_List (Contract (S)));
1539 Set_Spec_CTC_List (Contract (S), N);
1540 end Chain_CTC;
1541
1542 -- Start of processing for Check_Contract_Or_Test_Case
1543
1544 begin
1545 -- First check pragma arguments
1546
1547 GNAT_Pragma;
1548 Check_At_Least_N_Arguments (2);
1549 Check_At_Most_N_Arguments (4);
1550 Check_Arg_Order
1551 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
1552
1553 Check_Optional_Identifier (Arg1, Name_Name);
1554 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
1555
1556 -- In ASIS mode, for a pragma generated from a source aspect, also
1557 -- analyze the original aspect expression.
1558
1559 if ASIS_Mode
1560 and then Present (Corresponding_Aspect (N))
1561 then
1562 Check_Expr_Is_Static_Expression
1563 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
1564 end if;
1565
1566 Check_Optional_Identifier (Arg2, Name_Mode);
1567 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
1568
1569 if Arg_Count = 4 then
1570 Check_Identifier (Arg3, Name_Requires);
1571 Check_Identifier (Arg4, Name_Ensures);
1572
1573 elsif Arg_Count = 3 then
1574 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
1575 end if;
1576
1577 -- Check pragma placement
1578
1579 if not Is_List_Member (N) then
1580 Pragma_Misplaced;
1581 end if;
1582
1583 -- Contract-case or test-case should only appear in package spec unit
1584
1585 if Get_Source_Unit (N) = No_Unit
1586 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
1587 N_Package_Declaration,
1588 N_Generic_Package_Declaration)
1589 then
1590 Pragma_Misplaced;
1591 end if;
1592
1593 -- Search prior declarations
1594
1595 P := N;
1596 while Present (Prev (P)) loop
1597 P := Prev (P);
1598
1599 -- If the previous node is a generic subprogram, do not go to to
1600 -- the original node, which is the unanalyzed tree: we need to
1601 -- attach the contract-case or test-case to the analyzed version
1602 -- at this point. They get propagated to the original tree when
1603 -- analyzing the corresponding body.
1604
1605 if Nkind (P) not in N_Generic_Declaration then
1606 PO := Original_Node (P);
1607 else
1608 PO := P;
1609 end if;
1610
1611 -- Skip past prior pragma
1612
1613 if Nkind (PO) = N_Pragma then
1614 null;
1615
1616 -- Skip stuff not coming from source
1617
1618 elsif not Comes_From_Source (PO) then
1619 null;
1620
1621 -- Only remaining possibility is subprogram declaration. First
1622 -- check that it is declared directly in a package declaration.
1623 -- This may be either the package declaration for the current unit
1624 -- being defined or a local package declaration.
1625
1626 elsif not Present (Parent (Parent (PO)))
1627 or else not Present (Parent (Parent (Parent (PO))))
1628 or else not Nkind_In (Parent (Parent (PO)),
1629 N_Package_Declaration,
1630 N_Generic_Package_Declaration)
1631 then
1632 Pragma_Misplaced;
1633
1634 else
1635 Chain_CTC (PO);
1636 return;
1637 end if;
1638 end loop;
1639
1640 -- If we fall through, pragma was misplaced
1641
1642 Pragma_Misplaced;
1643 end Check_Contract_Or_Test_Case;
1644
1645 ----------------------------
1646 -- Check_Duplicate_Pragma --
1647 ----------------------------
1648
1649 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1650 Id : Entity_Id := E;
1651 P : Node_Id;
1652
1653 begin
1654 -- Nothing to do if this pragma comes from an aspect specification,
1655 -- since we could not be duplicating a pragma, and we dealt with the
1656 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1657
1658 if From_Aspect_Specification (N) then
1659 return;
1660 end if;
1661
1662 -- Otherwise current pragma may duplicate previous pragma or a
1663 -- previously given aspect specification or attribute definition
1664 -- clause for the same pragma.
1665
1666 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
1667
1668 if Present (P) then
1669 Error_Msg_Name_1 := Pragma_Name (N);
1670 Error_Msg_Sloc := Sloc (P);
1671
1672 -- For a single protected or a single task object, the error is
1673 -- issued on the original entity.
1674
1675 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
1676 Id := Defining_Identifier (Original_Node (Parent (Id)));
1677 end if;
1678
1679 if Nkind (P) = N_Aspect_Specification
1680 or else From_Aspect_Specification (P)
1681 then
1682 Error_Msg_NE ("aspect% for & previously given#", N, Id);
1683 else
1684 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
1685 end if;
1686
1687 raise Pragma_Exit;
1688 end if;
1689 end Check_Duplicate_Pragma;
1690
1691 ----------------------------------
1692 -- Check_Duplicated_Export_Name --
1693 ----------------------------------
1694
1695 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1696 String_Val : constant String_Id := Strval (Nam);
1697
1698 begin
1699 -- We are only interested in the export case, and in the case of
1700 -- generics, it is the instance, not the template, that is the
1701 -- problem (the template will generate a warning in any case).
1702
1703 if not Inside_A_Generic
1704 and then (Prag_Id = Pragma_Export
1705 or else
1706 Prag_Id = Pragma_Export_Procedure
1707 or else
1708 Prag_Id = Pragma_Export_Valued_Procedure
1709 or else
1710 Prag_Id = Pragma_Export_Function)
1711 then
1712 for J in Externals.First .. Externals.Last loop
1713 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1714 Error_Msg_Sloc := Sloc (Externals.Table (J));
1715 Error_Msg_N ("external name duplicates name given#", Nam);
1716 exit;
1717 end if;
1718 end loop;
1719
1720 Externals.Append (Nam);
1721 end if;
1722 end Check_Duplicated_Export_Name;
1723
1724 -------------------------------------
1725 -- Check_Expr_Is_Static_Expression --
1726 -------------------------------------
1727
1728 procedure Check_Expr_Is_Static_Expression
1729 (Expr : Node_Id;
1730 Typ : Entity_Id := Empty)
1731 is
1732 begin
1733 if Present (Typ) then
1734 Analyze_And_Resolve (Expr, Typ);
1735 else
1736 Analyze_And_Resolve (Expr);
1737 end if;
1738
1739 if Is_OK_Static_Expression (Expr) then
1740 return;
1741
1742 elsif Etype (Expr) = Any_Type then
1743 raise Pragma_Exit;
1744
1745 -- An interesting special case, if we have a string literal and we
1746 -- are in Ada 83 mode, then we allow it even though it will not be
1747 -- flagged as static. This allows the use of Ada 95 pragmas like
1748 -- Import in Ada 83 mode. They will of course be flagged with
1749 -- warnings as usual, but will not cause errors.
1750
1751 elsif Ada_Version = Ada_83
1752 and then Nkind (Expr) = N_String_Literal
1753 then
1754 return;
1755
1756 -- Static expression that raises Constraint_Error. This has already
1757 -- been flagged, so just exit from pragma processing.
1758
1759 elsif Is_Static_Expression (Expr) then
1760 raise Pragma_Exit;
1761
1762 -- Finally, we have a real error
1763
1764 else
1765 Error_Msg_Name_1 := Pname;
1766
1767 declare
1768 Msg : String :=
1769 "argument for pragma% must be a static expression!";
1770 begin
1771 Fix_Error (Msg);
1772 Flag_Non_Static_Expr (Msg, Expr);
1773 end;
1774
1775 raise Pragma_Exit;
1776 end if;
1777 end Check_Expr_Is_Static_Expression;
1778
1779 -------------------------
1780 -- Check_First_Subtype --
1781 -------------------------
1782
1783 procedure Check_First_Subtype (Arg : Node_Id) is
1784 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1785 Ent : constant Entity_Id := Entity (Argx);
1786
1787 begin
1788 if Is_First_Subtype (Ent) then
1789 null;
1790
1791 elsif Is_Type (Ent) then
1792 Error_Pragma_Arg
1793 ("pragma% cannot apply to subtype", Argx);
1794
1795 elsif Is_Object (Ent) then
1796 Error_Pragma_Arg
1797 ("pragma% cannot apply to object, requires a type", Argx);
1798
1799 else
1800 Error_Pragma_Arg
1801 ("pragma% cannot apply to&, requires a type", Argx);
1802 end if;
1803 end Check_First_Subtype;
1804
1805 ----------------------
1806 -- Check_Identifier --
1807 ----------------------
1808
1809 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1810 begin
1811 if Present (Arg)
1812 and then Nkind (Arg) = N_Pragma_Argument_Association
1813 then
1814 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1815 Error_Msg_Name_1 := Pname;
1816 Error_Msg_Name_2 := Id;
1817 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1818 raise Pragma_Exit;
1819 end if;
1820 end if;
1821 end Check_Identifier;
1822
1823 --------------------------------
1824 -- Check_Identifier_Is_One_Of --
1825 --------------------------------
1826
1827 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1828 begin
1829 if Present (Arg)
1830 and then Nkind (Arg) = N_Pragma_Argument_Association
1831 then
1832 if Chars (Arg) = No_Name then
1833 Error_Msg_Name_1 := Pname;
1834 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1835 raise Pragma_Exit;
1836
1837 elsif Chars (Arg) /= N1
1838 and then Chars (Arg) /= N2
1839 then
1840 Error_Msg_Name_1 := Pname;
1841 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1842 raise Pragma_Exit;
1843 end if;
1844 end if;
1845 end Check_Identifier_Is_One_Of;
1846
1847 ---------------------------
1848 -- Check_In_Main_Program --
1849 ---------------------------
1850
1851 procedure Check_In_Main_Program is
1852 P : constant Node_Id := Parent (N);
1853
1854 begin
1855 -- Must be at in subprogram body
1856
1857 if Nkind (P) /= N_Subprogram_Body then
1858 Error_Pragma ("% pragma allowed only in subprogram");
1859
1860 -- Otherwise warn if obviously not main program
1861
1862 elsif Present (Parameter_Specifications (Specification (P)))
1863 or else not Is_Compilation_Unit (Defining_Entity (P))
1864 then
1865 Error_Msg_Name_1 := Pname;
1866 Error_Msg_N
1867 ("??pragma% is only effective in main program", N);
1868 end if;
1869 end Check_In_Main_Program;
1870
1871 ---------------------------------------
1872 -- Check_Interrupt_Or_Attach_Handler --
1873 ---------------------------------------
1874
1875 procedure Check_Interrupt_Or_Attach_Handler is
1876 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1877 Handler_Proc, Proc_Scope : Entity_Id;
1878
1879 begin
1880 Analyze (Arg1_X);
1881
1882 if Prag_Id = Pragma_Interrupt_Handler then
1883 Check_Restriction (No_Dynamic_Attachment, N);
1884 end if;
1885
1886 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1887 Proc_Scope := Scope (Handler_Proc);
1888
1889 -- On AAMP only, a pragma Interrupt_Handler is supported for
1890 -- nonprotected parameterless procedures.
1891
1892 if not AAMP_On_Target
1893 or else Prag_Id = Pragma_Attach_Handler
1894 then
1895 if Ekind (Proc_Scope) /= E_Protected_Type then
1896 Error_Pragma_Arg
1897 ("argument of pragma% must be protected procedure", Arg1);
1898 end if;
1899
1900 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1901 Error_Pragma ("pragma% must be in protected definition");
1902 end if;
1903 end if;
1904
1905 if not Is_Library_Level_Entity (Proc_Scope)
1906 or else (AAMP_On_Target
1907 and then not Is_Library_Level_Entity (Handler_Proc))
1908 then
1909 Error_Pragma_Arg
1910 ("argument for pragma% must be library level entity", Arg1);
1911 end if;
1912
1913 -- AI05-0033: A pragma cannot appear within a generic body, because
1914 -- instance can be in a nested scope. The check that protected type
1915 -- is itself a library-level declaration is done elsewhere.
1916
1917 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
1918 -- handle code prior to AI-0033. Analysis tools typically are not
1919 -- interested in this pragma in any case, so no need to worry too
1920 -- much about its placement.
1921
1922 if Inside_A_Generic then
1923 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1924 and then In_Package_Body (Scope (Current_Scope))
1925 and then not Relaxed_RM_Semantics
1926 then
1927 Error_Pragma ("pragma% cannot be used inside a generic");
1928 end if;
1929 end if;
1930 end Check_Interrupt_Or_Attach_Handler;
1931
1932 ---------------------------------
1933 -- Check_Loop_Pragma_Placement --
1934 ---------------------------------
1935
1936 procedure Check_Loop_Pragma_Placement is
1937 procedure Placement_Error (Constr : Node_Id);
1938 pragma No_Return (Placement_Error);
1939 -- Node Constr denotes the last loop restricted construct before we
1940 -- encountered an illegal relation between enclosing constructs. Emit
1941 -- an error depending on what Constr was.
1942
1943 ---------------------
1944 -- Placement_Error --
1945 ---------------------
1946
1947 procedure Placement_Error (Constr : Node_Id) is
1948 begin
1949 if Nkind (Constr) = N_Pragma then
1950 Error_Pragma
1951 ("pragma % must appear immediately within the statements " &
1952 "of a loop");
1953 else
1954 Error_Pragma_Arg
1955 ("block containing pragma % must appear immediately within " &
1956 "the statements of a loop", Constr);
1957 end if;
1958 end Placement_Error;
1959
1960 -- Local declarations
1961
1962 Prev : Node_Id;
1963 Stmt : Node_Id;
1964
1965 -- Start of processing for Check_Loop_Pragma_Placement
1966
1967 begin
1968 Prev := N;
1969 Stmt := Parent (N);
1970 while Present (Stmt) loop
1971
1972 -- The pragma or previous block must appear immediately within the
1973 -- current block's declarative or statement part.
1974
1975 if Nkind (Stmt) = N_Block_Statement then
1976 if (No (Declarations (Stmt))
1977 or else List_Containing (Prev) /= Declarations (Stmt))
1978 and then
1979 List_Containing (Prev) /=
1980 Statements (Handled_Statement_Sequence (Stmt))
1981 then
1982 Placement_Error (Prev);
1983 return;
1984
1985 -- Keep inspecting the parents because we are now within a
1986 -- chain of nested blocks.
1987
1988 else
1989 Prev := Stmt;
1990 Stmt := Parent (Stmt);
1991 end if;
1992
1993 -- The pragma or previous block must appear immediately within the
1994 -- statements of the loop.
1995
1996 elsif Nkind (Stmt) = N_Loop_Statement then
1997 if List_Containing (Prev) /= Statements (Stmt) then
1998 Placement_Error (Prev);
1999 end if;
2000
2001 -- Stop the traversal because we reached the innermost loop
2002 -- regardless of whether we encountered an error or not.
2003
2004 return;
2005
2006 -- Ignore a handled statement sequence. Note that this node may
2007 -- be related to a subprogram body in which case we will emit an
2008 -- error on the next iteration of the search.
2009
2010 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
2011 Stmt := Parent (Stmt);
2012
2013 -- Any other statement breaks the chain from the pragma to the
2014 -- loop.
2015
2016 else
2017 Placement_Error (Prev);
2018 return;
2019 end if;
2020 end loop;
2021 end Check_Loop_Pragma_Placement;
2022
2023 -------------------------------------------
2024 -- Check_Is_In_Decl_Part_Or_Package_Spec --
2025 -------------------------------------------
2026
2027 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
2028 P : Node_Id;
2029
2030 begin
2031 P := Parent (N);
2032 loop
2033 if No (P) then
2034 exit;
2035
2036 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
2037 exit;
2038
2039 elsif Nkind_In (P, N_Package_Specification,
2040 N_Block_Statement)
2041 then
2042 return;
2043
2044 -- Note: the following tests seem a little peculiar, because
2045 -- they test for bodies, but if we were in the statement part
2046 -- of the body, we would already have hit the handled statement
2047 -- sequence, so the only way we get here is by being in the
2048 -- declarative part of the body.
2049
2050 elsif Nkind_In (P, N_Subprogram_Body,
2051 N_Package_Body,
2052 N_Task_Body,
2053 N_Entry_Body)
2054 then
2055 return;
2056 end if;
2057
2058 P := Parent (P);
2059 end loop;
2060
2061 Error_Pragma ("pragma% is not in declarative part or package spec");
2062 end Check_Is_In_Decl_Part_Or_Package_Spec;
2063
2064 -------------------------
2065 -- Check_No_Identifier --
2066 -------------------------
2067
2068 procedure Check_No_Identifier (Arg : Node_Id) is
2069 begin
2070 if Nkind (Arg) = N_Pragma_Argument_Association
2071 and then Chars (Arg) /= No_Name
2072 then
2073 Error_Pragma_Arg_Ident
2074 ("pragma% does not permit identifier& here", Arg);
2075 end if;
2076 end Check_No_Identifier;
2077
2078 --------------------------
2079 -- Check_No_Identifiers --
2080 --------------------------
2081
2082 procedure Check_No_Identifiers is
2083 Arg_Node : Node_Id;
2084 begin
2085 if Arg_Count > 0 then
2086 Arg_Node := Arg1;
2087 while Present (Arg_Node) loop
2088 Check_No_Identifier (Arg_Node);
2089 Next (Arg_Node);
2090 end loop;
2091 end if;
2092 end Check_No_Identifiers;
2093
2094 ------------------------
2095 -- Check_No_Link_Name --
2096 ------------------------
2097
2098 procedure Check_No_Link_Name is
2099 begin
2100 if Present (Arg3)
2101 and then Chars (Arg3) = Name_Link_Name
2102 then
2103 Arg4 := Arg3;
2104 end if;
2105
2106 if Present (Arg4) then
2107 Error_Pragma_Arg
2108 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
2109 end if;
2110 end Check_No_Link_Name;
2111
2112 -------------------------------
2113 -- Check_Optional_Identifier --
2114 -------------------------------
2115
2116 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
2117 begin
2118 if Present (Arg)
2119 and then Nkind (Arg) = N_Pragma_Argument_Association
2120 and then Chars (Arg) /= No_Name
2121 then
2122 if Chars (Arg) /= Id then
2123 Error_Msg_Name_1 := Pname;
2124 Error_Msg_Name_2 := Id;
2125 Error_Msg_N ("pragma% argument expects identifier%", Arg);
2126 raise Pragma_Exit;
2127 end if;
2128 end if;
2129 end Check_Optional_Identifier;
2130
2131 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
2132 begin
2133 Name_Buffer (1 .. Id'Length) := Id;
2134 Name_Len := Id'Length;
2135 Check_Optional_Identifier (Arg, Name_Find);
2136 end Check_Optional_Identifier;
2137
2138 --------------------------------------
2139 -- Check_Precondition_Postcondition --
2140 --------------------------------------
2141
2142 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
2143 P : Node_Id;
2144 PO : Node_Id;
2145
2146 procedure Chain_PPC (PO : Node_Id);
2147 -- If PO is an entry or a [generic] subprogram declaration node, then
2148 -- the precondition/postcondition applies to this subprogram and the
2149 -- processing for the pragma is completed. Otherwise the pragma is
2150 -- misplaced.
2151
2152 ---------------
2153 -- Chain_PPC --
2154 ---------------
2155
2156 procedure Chain_PPC (PO : Node_Id) is
2157 S : Entity_Id;
2158
2159 begin
2160 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2161 if not From_Aspect_Specification (N) then
2162 Error_Pragma
2163 ("pragma% cannot be applied to abstract subprogram");
2164
2165 elsif Class_Present (N) then
2166 null;
2167
2168 else
2169 Error_Pragma
2170 ("aspect % requires ''Class for abstract subprogram");
2171 end if;
2172
2173 -- AI05-0230: The same restriction applies to null procedures. For
2174 -- compatibility with earlier uses of the Ada pragma, apply this
2175 -- rule only to aspect specifications.
2176
2177 -- The above discrpency needs documentation. Robert is dubious
2178 -- about whether it is a good idea ???
2179
2180 elsif Nkind (PO) = N_Subprogram_Declaration
2181 and then Nkind (Specification (PO)) = N_Procedure_Specification
2182 and then Null_Present (Specification (PO))
2183 and then From_Aspect_Specification (N)
2184 and then not Class_Present (N)
2185 then
2186 Error_Pragma
2187 ("aspect % requires ''Class for null procedure");
2188
2189 -- Pre/postconditions are legal on a subprogram body if it is not
2190 -- a completion of a declaration.
2191
2192 elsif Nkind (PO) = N_Subprogram_Body
2193 and then Acts_As_Spec (PO)
2194 then
2195 null;
2196
2197 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2198 N_Expression_Function,
2199 N_Generic_Subprogram_Declaration,
2200 N_Entry_Declaration)
2201 then
2202 Pragma_Misplaced;
2203 end if;
2204
2205 -- Here if we have [generic] subprogram or entry declaration
2206
2207 if Nkind (PO) = N_Entry_Declaration then
2208 S := Defining_Entity (PO);
2209 else
2210 S := Defining_Unit_Name (Specification (PO));
2211
2212 if Nkind (S) = N_Defining_Program_Unit_Name then
2213 S := Defining_Identifier (S);
2214 end if;
2215 end if;
2216
2217 -- Note: we do not analyze the pragma at this point. Instead we
2218 -- delay this analysis until the end of the declarative part in
2219 -- which the pragma appears. This implements the required delay
2220 -- in this analysis, allowing forward references. The analysis
2221 -- happens at the end of Analyze_Declarations.
2222
2223 -- Chain spec PPC pragma to list for subprogram
2224
2225 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
2226 Set_Spec_PPC_List (Contract (S), N);
2227
2228 -- Return indicating spec case
2229
2230 In_Body := False;
2231 return;
2232 end Chain_PPC;
2233
2234 -- Start of processing for Check_Precondition_Postcondition
2235
2236 begin
2237 if not Is_List_Member (N) then
2238 Pragma_Misplaced;
2239 end if;
2240
2241 -- Preanalyze message argument if present. Visibility in this
2242 -- argument is established at the point of pragma occurrence.
2243
2244 if Arg_Count = 2 then
2245 Check_Optional_Identifier (Arg2, Name_Message);
2246 Preanalyze_Spec_Expression
2247 (Get_Pragma_Arg (Arg2), Standard_String);
2248 end if;
2249
2250 -- For a pragma PPC in the extended main source unit, record enabled
2251 -- status in SCO.
2252
2253 -- This may seem redundant with the call to Check_Enabled occurring
2254 -- later on when the pragma is rewritten into a pragma Check but
2255 -- is actually required in the case of a postcondition within a
2256 -- generic.
2257
2258 if Check_Enabled (Pname) and then not Split_PPC (N) then
2259 Set_SCO_Pragma_Enabled (Loc);
2260 end if;
2261
2262 -- If we are within an inlined body, the legality of the pragma
2263 -- has been checked already.
2264
2265 if In_Inlined_Body then
2266 In_Body := True;
2267 return;
2268 end if;
2269
2270 -- Search prior declarations
2271
2272 P := N;
2273 while Present (Prev (P)) loop
2274 P := Prev (P);
2275
2276 -- If the previous node is a generic subprogram, do not go to to
2277 -- the original node, which is the unanalyzed tree: we need to
2278 -- attach the pre/postconditions to the analyzed version at this
2279 -- point. They get propagated to the original tree when analyzing
2280 -- the corresponding body.
2281
2282 if Nkind (P) not in N_Generic_Declaration then
2283 PO := Original_Node (P);
2284 else
2285 PO := P;
2286 end if;
2287
2288 -- Skip past prior pragma
2289
2290 if Nkind (PO) = N_Pragma then
2291 null;
2292
2293 -- Skip stuff not coming from source
2294
2295 elsif not Comes_From_Source (PO) then
2296
2297 -- The condition may apply to a subprogram instantiation
2298
2299 if Nkind (PO) = N_Subprogram_Declaration
2300 and then Present (Generic_Parent (Specification (PO)))
2301 then
2302 Chain_PPC (PO);
2303 return;
2304
2305 elsif Nkind (PO) = N_Subprogram_Declaration
2306 and then In_Instance
2307 then
2308 Chain_PPC (PO);
2309 return;
2310
2311 -- For all other cases of non source code, do nothing
2312
2313 else
2314 null;
2315 end if;
2316
2317 -- Only remaining possibility is subprogram declaration
2318
2319 else
2320 Chain_PPC (PO);
2321 return;
2322 end if;
2323 end loop;
2324
2325 -- If we fall through loop, pragma is at start of list, so see if it
2326 -- is at the start of declarations of a subprogram body.
2327
2328 if Nkind (Parent (N)) = N_Subprogram_Body
2329 and then List_Containing (N) = Declarations (Parent (N))
2330 then
2331 if Operating_Mode /= Generate_Code
2332 or else Inside_A_Generic
2333 then
2334 -- Analyze pragma expression for correctness and for ASIS use
2335
2336 Preanalyze_Assert_Expression
2337 (Get_Pragma_Arg (Arg1), Standard_Boolean);
2338
2339 -- In ASIS mode, for a pragma generated from a source aspect,
2340 -- also analyze the original aspect expression.
2341
2342 if ASIS_Mode
2343 and then Present (Corresponding_Aspect (N))
2344 then
2345 Preanalyze_Assert_Expression
2346 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2347 end if;
2348 end if;
2349
2350 In_Body := True;
2351 return;
2352
2353 -- See if it is in the pragmas after a library level subprogram
2354
2355 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2356
2357 -- In formal verification mode, analyze pragma expression for
2358 -- correctness, as it is not expanded later.
2359
2360 if Alfa_Mode then
2361 Analyze_PPC_In_Decl_Part
2362 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2363 end if;
2364
2365 Chain_PPC (Unit (Parent (Parent (N))));
2366 return;
2367 end if;
2368
2369 -- If we fall through, pragma was misplaced
2370
2371 Pragma_Misplaced;
2372 end Check_Precondition_Postcondition;
2373
2374 -----------------------------
2375 -- Check_Static_Constraint --
2376 -----------------------------
2377
2378 -- Note: for convenience in writing this procedure, in addition to
2379 -- the officially (i.e. by spec) allowed argument which is always a
2380 -- constraint, it also allows ranges and discriminant associations.
2381 -- Above is not clear ???
2382
2383 procedure Check_Static_Constraint (Constr : Node_Id) is
2384
2385 procedure Require_Static (E : Node_Id);
2386 -- Require given expression to be static expression
2387
2388 --------------------
2389 -- Require_Static --
2390 --------------------
2391
2392 procedure Require_Static (E : Node_Id) is
2393 begin
2394 if not Is_OK_Static_Expression (E) then
2395 Flag_Non_Static_Expr
2396 ("non-static constraint not allowed in Unchecked_Union!", E);
2397 raise Pragma_Exit;
2398 end if;
2399 end Require_Static;
2400
2401 -- Start of processing for Check_Static_Constraint
2402
2403 begin
2404 case Nkind (Constr) is
2405 when N_Discriminant_Association =>
2406 Require_Static (Expression (Constr));
2407
2408 when N_Range =>
2409 Require_Static (Low_Bound (Constr));
2410 Require_Static (High_Bound (Constr));
2411
2412 when N_Attribute_Reference =>
2413 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2414 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2415
2416 when N_Range_Constraint =>
2417 Check_Static_Constraint (Range_Expression (Constr));
2418
2419 when N_Index_Or_Discriminant_Constraint =>
2420 declare
2421 IDC : Entity_Id;
2422 begin
2423 IDC := First (Constraints (Constr));
2424 while Present (IDC) loop
2425 Check_Static_Constraint (IDC);
2426 Next (IDC);
2427 end loop;
2428 end;
2429
2430 when others =>
2431 null;
2432 end case;
2433 end Check_Static_Constraint;
2434
2435 --------------------------------------
2436 -- Check_Valid_Configuration_Pragma --
2437 --------------------------------------
2438
2439 -- A configuration pragma must appear in the context clause of a
2440 -- compilation unit, and only other pragmas may precede it. Note that
2441 -- the test also allows use in a configuration pragma file.
2442
2443 procedure Check_Valid_Configuration_Pragma is
2444 begin
2445 if not Is_Configuration_Pragma then
2446 Error_Pragma ("incorrect placement for configuration pragma%");
2447 end if;
2448 end Check_Valid_Configuration_Pragma;
2449
2450 -------------------------------------
2451 -- Check_Valid_Library_Unit_Pragma --
2452 -------------------------------------
2453
2454 procedure Check_Valid_Library_Unit_Pragma is
2455 Plist : List_Id;
2456 Parent_Node : Node_Id;
2457 Unit_Name : Entity_Id;
2458 Unit_Kind : Node_Kind;
2459 Unit_Node : Node_Id;
2460 Sindex : Source_File_Index;
2461
2462 begin
2463 if not Is_List_Member (N) then
2464 Pragma_Misplaced;
2465
2466 else
2467 Plist := List_Containing (N);
2468 Parent_Node := Parent (Plist);
2469
2470 if Parent_Node = Empty then
2471 Pragma_Misplaced;
2472
2473 -- Case of pragma appearing after a compilation unit. In this case
2474 -- it must have an argument with the corresponding name and must
2475 -- be part of the following pragmas of its parent.
2476
2477 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2478 if Plist /= Pragmas_After (Parent_Node) then
2479 Pragma_Misplaced;
2480
2481 elsif Arg_Count = 0 then
2482 Error_Pragma
2483 ("argument required if outside compilation unit");
2484
2485 else
2486 Check_No_Identifiers;
2487 Check_Arg_Count (1);
2488 Unit_Node := Unit (Parent (Parent_Node));
2489 Unit_Kind := Nkind (Unit_Node);
2490
2491 Analyze (Get_Pragma_Arg (Arg1));
2492
2493 if Unit_Kind = N_Generic_Subprogram_Declaration
2494 or else Unit_Kind = N_Subprogram_Declaration
2495 then
2496 Unit_Name := Defining_Entity (Unit_Node);
2497
2498 elsif Unit_Kind in N_Generic_Instantiation then
2499 Unit_Name := Defining_Entity (Unit_Node);
2500
2501 else
2502 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2503 end if;
2504
2505 if Chars (Unit_Name) /=
2506 Chars (Entity (Get_Pragma_Arg (Arg1)))
2507 then
2508 Error_Pragma_Arg
2509 ("pragma% argument is not current unit name", Arg1);
2510 end if;
2511
2512 if Ekind (Unit_Name) = E_Package
2513 and then Present (Renamed_Entity (Unit_Name))
2514 then
2515 Error_Pragma ("pragma% not allowed for renamed package");
2516 end if;
2517 end if;
2518
2519 -- Pragma appears other than after a compilation unit
2520
2521 else
2522 -- Here we check for the generic instantiation case and also
2523 -- for the case of processing a generic formal package. We
2524 -- detect these cases by noting that the Sloc on the node
2525 -- does not belong to the current compilation unit.
2526
2527 Sindex := Source_Index (Current_Sem_Unit);
2528
2529 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2530 Rewrite (N, Make_Null_Statement (Loc));
2531 return;
2532
2533 -- If before first declaration, the pragma applies to the
2534 -- enclosing unit, and the name if present must be this name.
2535
2536 elsif Is_Before_First_Decl (N, Plist) then
2537 Unit_Node := Unit_Declaration_Node (Current_Scope);
2538 Unit_Kind := Nkind (Unit_Node);
2539
2540 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2541 Pragma_Misplaced;
2542
2543 elsif Unit_Kind = N_Subprogram_Body
2544 and then not Acts_As_Spec (Unit_Node)
2545 then
2546 Pragma_Misplaced;
2547
2548 elsif Nkind (Parent_Node) = N_Package_Body then
2549 Pragma_Misplaced;
2550
2551 elsif Nkind (Parent_Node) = N_Package_Specification
2552 and then Plist = Private_Declarations (Parent_Node)
2553 then
2554 Pragma_Misplaced;
2555
2556 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2557 or else Nkind (Parent_Node) =
2558 N_Generic_Subprogram_Declaration)
2559 and then Plist = Generic_Formal_Declarations (Parent_Node)
2560 then
2561 Pragma_Misplaced;
2562
2563 elsif Arg_Count > 0 then
2564 Analyze (Get_Pragma_Arg (Arg1));
2565
2566 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2567 Error_Pragma_Arg
2568 ("name in pragma% must be enclosing unit", Arg1);
2569 end if;
2570
2571 -- It is legal to have no argument in this context
2572
2573 else
2574 return;
2575 end if;
2576
2577 -- Error if not before first declaration. This is because a
2578 -- library unit pragma argument must be the name of a library
2579 -- unit (RM 10.1.5(7)), but the only names permitted in this
2580 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2581 -- generic subprogram declarations or generic instantiations.
2582
2583 else
2584 Error_Pragma
2585 ("pragma% misplaced, must be before first declaration");
2586 end if;
2587 end if;
2588 end if;
2589 end Check_Valid_Library_Unit_Pragma;
2590
2591 -------------------
2592 -- Check_Variant --
2593 -------------------
2594
2595 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2596 Clist : constant Node_Id := Component_List (Variant);
2597 Comp : Node_Id;
2598
2599 begin
2600 Comp := First (Component_Items (Clist));
2601 while Present (Comp) loop
2602 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2603 Next (Comp);
2604 end loop;
2605 end Check_Variant;
2606
2607 ------------------
2608 -- Error_Pragma --
2609 ------------------
2610
2611 procedure Error_Pragma (Msg : String) is
2612 MsgF : String := Msg;
2613 begin
2614 Error_Msg_Name_1 := Pname;
2615 Fix_Error (MsgF);
2616 Error_Msg_N (MsgF, N);
2617 raise Pragma_Exit;
2618 end Error_Pragma;
2619
2620 ----------------------
2621 -- Error_Pragma_Arg --
2622 ----------------------
2623
2624 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2625 MsgF : String := Msg;
2626 begin
2627 Error_Msg_Name_1 := Pname;
2628 Fix_Error (MsgF);
2629 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2630 raise Pragma_Exit;
2631 end Error_Pragma_Arg;
2632
2633 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2634 MsgF : String := Msg1;
2635 begin
2636 Error_Msg_Name_1 := Pname;
2637 Fix_Error (MsgF);
2638 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2639 Error_Pragma_Arg (Msg2, Arg);
2640 end Error_Pragma_Arg;
2641
2642 ----------------------------
2643 -- Error_Pragma_Arg_Ident --
2644 ----------------------------
2645
2646 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2647 MsgF : String := Msg;
2648 begin
2649 Error_Msg_Name_1 := Pname;
2650 Fix_Error (MsgF);
2651 Error_Msg_N (MsgF, Arg);
2652 raise Pragma_Exit;
2653 end Error_Pragma_Arg_Ident;
2654
2655 ----------------------
2656 -- Error_Pragma_Ref --
2657 ----------------------
2658
2659 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2660 MsgF : String := Msg;
2661 begin
2662 Error_Msg_Name_1 := Pname;
2663 Fix_Error (MsgF);
2664 Error_Msg_Sloc := Sloc (Ref);
2665 Error_Msg_NE (MsgF, N, Ref);
2666 raise Pragma_Exit;
2667 end Error_Pragma_Ref;
2668
2669 ------------------------
2670 -- Find_Lib_Unit_Name --
2671 ------------------------
2672
2673 function Find_Lib_Unit_Name return Entity_Id is
2674 begin
2675 -- Return inner compilation unit entity, for case of nested
2676 -- categorization pragmas. This happens in generic unit.
2677
2678 if Nkind (Parent (N)) = N_Package_Specification
2679 and then Defining_Entity (Parent (N)) /= Current_Scope
2680 then
2681 return Defining_Entity (Parent (N));
2682 else
2683 return Current_Scope;
2684 end if;
2685 end Find_Lib_Unit_Name;
2686
2687 ----------------------------
2688 -- Find_Program_Unit_Name --
2689 ----------------------------
2690
2691 procedure Find_Program_Unit_Name (Id : Node_Id) is
2692 Unit_Name : Entity_Id;
2693 Unit_Kind : Node_Kind;
2694 P : constant Node_Id := Parent (N);
2695
2696 begin
2697 if Nkind (P) = N_Compilation_Unit then
2698 Unit_Kind := Nkind (Unit (P));
2699
2700 if Unit_Kind = N_Subprogram_Declaration
2701 or else Unit_Kind = N_Package_Declaration
2702 or else Unit_Kind in N_Generic_Declaration
2703 then
2704 Unit_Name := Defining_Entity (Unit (P));
2705
2706 if Chars (Id) = Chars (Unit_Name) then
2707 Set_Entity (Id, Unit_Name);
2708 Set_Etype (Id, Etype (Unit_Name));
2709 else
2710 Set_Etype (Id, Any_Type);
2711 Error_Pragma
2712 ("cannot find program unit referenced by pragma%");
2713 end if;
2714
2715 else
2716 Set_Etype (Id, Any_Type);
2717 Error_Pragma ("pragma% inapplicable to this unit");
2718 end if;
2719
2720 else
2721 Analyze (Id);
2722 end if;
2723 end Find_Program_Unit_Name;
2724
2725 -----------------------------------------
2726 -- Find_Unique_Parameterless_Procedure --
2727 -----------------------------------------
2728
2729 function Find_Unique_Parameterless_Procedure
2730 (Name : Entity_Id;
2731 Arg : Node_Id) return Entity_Id
2732 is
2733 Proc : Entity_Id := Empty;
2734
2735 begin
2736 -- The body of this procedure needs some comments ???
2737
2738 if not Is_Entity_Name (Name) then
2739 Error_Pragma_Arg
2740 ("argument of pragma% must be entity name", Arg);
2741
2742 elsif not Is_Overloaded (Name) then
2743 Proc := Entity (Name);
2744
2745 if Ekind (Proc) /= E_Procedure
2746 or else Present (First_Formal (Proc))
2747 then
2748 Error_Pragma_Arg
2749 ("argument of pragma% must be parameterless procedure", Arg);
2750 end if;
2751
2752 else
2753 declare
2754 Found : Boolean := False;
2755 It : Interp;
2756 Index : Interp_Index;
2757
2758 begin
2759 Get_First_Interp (Name, Index, It);
2760 while Present (It.Nam) loop
2761 Proc := It.Nam;
2762
2763 if Ekind (Proc) = E_Procedure
2764 and then No (First_Formal (Proc))
2765 then
2766 if not Found then
2767 Found := True;
2768 Set_Entity (Name, Proc);
2769 Set_Is_Overloaded (Name, False);
2770 else
2771 Error_Pragma_Arg
2772 ("ambiguous handler name for pragma% ", Arg);
2773 end if;
2774 end if;
2775
2776 Get_Next_Interp (Index, It);
2777 end loop;
2778
2779 if not Found then
2780 Error_Pragma_Arg
2781 ("argument of pragma% must be parameterless procedure",
2782 Arg);
2783 else
2784 Proc := Entity (Name);
2785 end if;
2786 end;
2787 end if;
2788
2789 return Proc;
2790 end Find_Unique_Parameterless_Procedure;
2791
2792 ---------------
2793 -- Fix_Error --
2794 ---------------
2795
2796 procedure Fix_Error (Msg : in out String) is
2797 begin
2798 if From_Aspect_Specification (N) then
2799 for J in Msg'First .. Msg'Last - 5 loop
2800 if Msg (J .. J + 5) = "pragma" then
2801 Msg (J .. J + 5) := "aspect";
2802 end if;
2803 end loop;
2804
2805 if Error_Msg_Name_1 = Name_Precondition then
2806 Error_Msg_Name_1 := Name_Pre;
2807 elsif Error_Msg_Name_1 = Name_Postcondition then
2808 Error_Msg_Name_1 := Name_Post;
2809 end if;
2810 end if;
2811 end Fix_Error;
2812
2813 -------------------------
2814 -- Gather_Associations --
2815 -------------------------
2816
2817 procedure Gather_Associations
2818 (Names : Name_List;
2819 Args : out Args_List)
2820 is
2821 Arg : Node_Id;
2822
2823 begin
2824 -- Initialize all parameters to Empty
2825
2826 for J in Args'Range loop
2827 Args (J) := Empty;
2828 end loop;
2829
2830 -- That's all we have to do if there are no argument associations
2831
2832 if No (Pragma_Argument_Associations (N)) then
2833 return;
2834 end if;
2835
2836 -- Otherwise first deal with any positional parameters present
2837
2838 Arg := First (Pragma_Argument_Associations (N));
2839 for Index in Args'Range loop
2840 exit when No (Arg) or else Chars (Arg) /= No_Name;
2841 Args (Index) := Get_Pragma_Arg (Arg);
2842 Next (Arg);
2843 end loop;
2844
2845 -- Positional parameters all processed, if any left, then we
2846 -- have too many positional parameters.
2847
2848 if Present (Arg) and then Chars (Arg) = No_Name then
2849 Error_Pragma_Arg
2850 ("too many positional associations for pragma%", Arg);
2851 end if;
2852
2853 -- Process named parameters if any are present
2854
2855 while Present (Arg) loop
2856 if Chars (Arg) = No_Name then
2857 Error_Pragma_Arg
2858 ("positional association cannot follow named association",
2859 Arg);
2860
2861 else
2862 for Index in Names'Range loop
2863 if Names (Index) = Chars (Arg) then
2864 if Present (Args (Index)) then
2865 Error_Pragma_Arg
2866 ("duplicate argument association for pragma%", Arg);
2867 else
2868 Args (Index) := Get_Pragma_Arg (Arg);
2869 exit;
2870 end if;
2871 end if;
2872
2873 if Index = Names'Last then
2874 Error_Msg_Name_1 := Pname;
2875 Error_Msg_N ("pragma% does not allow & argument", Arg);
2876
2877 -- Check for possible misspelling
2878
2879 for Index1 in Names'Range loop
2880 if Is_Bad_Spelling_Of
2881 (Chars (Arg), Names (Index1))
2882 then
2883 Error_Msg_Name_1 := Names (Index1);
2884 Error_Msg_N -- CODEFIX
2885 ("\possible misspelling of%", Arg);
2886 exit;
2887 end if;
2888 end loop;
2889
2890 raise Pragma_Exit;
2891 end if;
2892 end loop;
2893 end if;
2894
2895 Next (Arg);
2896 end loop;
2897 end Gather_Associations;
2898
2899 -----------------
2900 -- GNAT_Pragma --
2901 -----------------
2902
2903 procedure GNAT_Pragma is
2904 begin
2905 -- We need to check the No_Implementation_Pragmas restriction for
2906 -- the case of a pragma from source. Note that the case of aspects
2907 -- generating corresponding pragmas marks these pragmas as not being
2908 -- from source, so this test also catches that case.
2909
2910 if Comes_From_Source (N) then
2911 Check_Restriction (No_Implementation_Pragmas, N);
2912 end if;
2913 end GNAT_Pragma;
2914
2915 --------------------------
2916 -- Is_Before_First_Decl --
2917 --------------------------
2918
2919 function Is_Before_First_Decl
2920 (Pragma_Node : Node_Id;
2921 Decls : List_Id) return Boolean
2922 is
2923 Item : Node_Id := First (Decls);
2924
2925 begin
2926 -- Only other pragmas can come before this pragma
2927
2928 loop
2929 if No (Item) or else Nkind (Item) /= N_Pragma then
2930 return False;
2931
2932 elsif Item = Pragma_Node then
2933 return True;
2934 end if;
2935
2936 Next (Item);
2937 end loop;
2938 end Is_Before_First_Decl;
2939
2940 -----------------------------
2941 -- Is_Configuration_Pragma --
2942 -----------------------------
2943
2944 -- A configuration pragma must appear in the context clause of a
2945 -- compilation unit, and only other pragmas may precede it. Note that
2946 -- the test below also permits use in a configuration pragma file.
2947
2948 function Is_Configuration_Pragma return Boolean is
2949 Lis : constant List_Id := List_Containing (N);
2950 Par : constant Node_Id := Parent (N);
2951 Prg : Node_Id;
2952
2953 begin
2954 -- If no parent, then we are in the configuration pragma file,
2955 -- so the placement is definitely appropriate.
2956
2957 if No (Par) then
2958 return True;
2959
2960 -- Otherwise we must be in the context clause of a compilation unit
2961 -- and the only thing allowed before us in the context list is more
2962 -- configuration pragmas.
2963
2964 elsif Nkind (Par) = N_Compilation_Unit
2965 and then Context_Items (Par) = Lis
2966 then
2967 Prg := First (Lis);
2968
2969 loop
2970 if Prg = N then
2971 return True;
2972 elsif Nkind (Prg) /= N_Pragma then
2973 return False;
2974 end if;
2975
2976 Next (Prg);
2977 end loop;
2978
2979 else
2980 return False;
2981 end if;
2982 end Is_Configuration_Pragma;
2983
2984 --------------------------
2985 -- Is_In_Context_Clause --
2986 --------------------------
2987
2988 function Is_In_Context_Clause return Boolean is
2989 Plist : List_Id;
2990 Parent_Node : Node_Id;
2991
2992 begin
2993 if not Is_List_Member (N) then
2994 return False;
2995
2996 else
2997 Plist := List_Containing (N);
2998 Parent_Node := Parent (Plist);
2999
3000 if Parent_Node = Empty
3001 or else Nkind (Parent_Node) /= N_Compilation_Unit
3002 or else Context_Items (Parent_Node) /= Plist
3003 then
3004 return False;
3005 end if;
3006 end if;
3007
3008 return True;
3009 end Is_In_Context_Clause;
3010
3011 ---------------------------------
3012 -- Is_Static_String_Expression --
3013 ---------------------------------
3014
3015 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
3016 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3017
3018 begin
3019 Analyze_And_Resolve (Argx);
3020 return Is_OK_Static_Expression (Argx)
3021 and then Nkind (Argx) = N_String_Literal;
3022 end Is_Static_String_Expression;
3023
3024 ----------------------
3025 -- Pragma_Misplaced --
3026 ----------------------
3027
3028 procedure Pragma_Misplaced is
3029 begin
3030 Error_Pragma ("incorrect placement of pragma%");
3031 end Pragma_Misplaced;
3032
3033 ------------------------------------
3034 -- Process_Atomic_Shared_Volatile --
3035 ------------------------------------
3036
3037 procedure Process_Atomic_Shared_Volatile is
3038 E_Id : Node_Id;
3039 E : Entity_Id;
3040 D : Node_Id;
3041 K : Node_Kind;
3042 Utyp : Entity_Id;
3043
3044 procedure Set_Atomic (E : Entity_Id);
3045 -- Set given type as atomic, and if no explicit alignment was given,
3046 -- set alignment to unknown, since back end knows what the alignment
3047 -- requirements are for atomic arrays. Note: this step is necessary
3048 -- for derived types.
3049
3050 ----------------
3051 -- Set_Atomic --
3052 ----------------
3053
3054 procedure Set_Atomic (E : Entity_Id) is
3055 begin
3056 Set_Is_Atomic (E);
3057
3058 if not Has_Alignment_Clause (E) then
3059 Set_Alignment (E, Uint_0);
3060 end if;
3061 end Set_Atomic;
3062
3063 -- Start of processing for Process_Atomic_Shared_Volatile
3064
3065 begin
3066 Check_Ada_83_Warning;
3067 Check_No_Identifiers;
3068 Check_Arg_Count (1);
3069 Check_Arg_Is_Local_Name (Arg1);
3070 E_Id := Get_Pragma_Arg (Arg1);
3071
3072 if Etype (E_Id) = Any_Type then
3073 return;
3074 end if;
3075
3076 E := Entity (E_Id);
3077 D := Declaration_Node (E);
3078 K := Nkind (D);
3079
3080 -- Check duplicate before we chain ourselves!
3081
3082 Check_Duplicate_Pragma (E);
3083
3084 -- Now check appropriateness of the entity
3085
3086 if Is_Type (E) then
3087 if Rep_Item_Too_Early (E, N)
3088 or else
3089 Rep_Item_Too_Late (E, N)
3090 then
3091 return;
3092 else
3093 Check_First_Subtype (Arg1);
3094 end if;
3095
3096 if Prag_Id /= Pragma_Volatile then
3097 Set_Atomic (E);
3098 Set_Atomic (Underlying_Type (E));
3099 Set_Atomic (Base_Type (E));
3100 end if;
3101
3102 -- Attribute belongs on the base type. If the view of the type is
3103 -- currently private, it also belongs on the underlying type.
3104
3105 Set_Is_Volatile (Base_Type (E));
3106 Set_Is_Volatile (Underlying_Type (E));
3107
3108 Set_Treat_As_Volatile (E);
3109 Set_Treat_As_Volatile (Underlying_Type (E));
3110
3111 elsif K = N_Object_Declaration
3112 or else (K = N_Component_Declaration
3113 and then Original_Record_Component (E) = E)
3114 then
3115 if Rep_Item_Too_Late (E, N) then
3116 return;
3117 end if;
3118
3119 if Prag_Id /= Pragma_Volatile then
3120 Set_Is_Atomic (E);
3121
3122 -- If the object declaration has an explicit initialization, a
3123 -- temporary may have to be created to hold the expression, to
3124 -- ensure that access to the object remain atomic.
3125
3126 if Nkind (Parent (E)) = N_Object_Declaration
3127 and then Present (Expression (Parent (E)))
3128 then
3129 Set_Has_Delayed_Freeze (E);
3130 end if;
3131
3132 -- An interesting improvement here. If an object of composite
3133 -- type X is declared atomic, and the type X isn't, that's a
3134 -- pity, since it may not have appropriate alignment etc. We
3135 -- can rescue this in the special case where the object and
3136 -- type are in the same unit by just setting the type as
3137 -- atomic, so that the back end will process it as atomic.
3138
3139 -- Note: we used to do this for elementary types as well,
3140 -- but that turns out to be a bad idea and can have unwanted
3141 -- effects, most notably if the type is elementary, the object
3142 -- a simple component within a record, and both are in a spec:
3143 -- every object of this type in the entire program will be
3144 -- treated as atomic, thus incurring a potentially costly
3145 -- synchronization operation for every access.
3146
3147 -- Of course it would be best if the back end could just adjust
3148 -- the alignment etc for the specific object, but that's not
3149 -- something we are capable of doing at this point.
3150
3151 Utyp := Underlying_Type (Etype (E));
3152
3153 if Present (Utyp)
3154 and then Is_Composite_Type (Utyp)
3155 and then Sloc (E) > No_Location
3156 and then Sloc (Utyp) > No_Location
3157 and then
3158 Get_Source_File_Index (Sloc (E)) =
3159 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
3160 then
3161 Set_Is_Atomic (Underlying_Type (Etype (E)));
3162 end if;
3163 end if;
3164
3165 Set_Is_Volatile (E);
3166 Set_Treat_As_Volatile (E);
3167
3168 else
3169 Error_Pragma_Arg
3170 ("inappropriate entity for pragma%", Arg1);
3171 end if;
3172 end Process_Atomic_Shared_Volatile;
3173
3174 -------------------------------------------
3175 -- Process_Compile_Time_Warning_Or_Error --
3176 -------------------------------------------
3177
3178 procedure Process_Compile_Time_Warning_Or_Error is
3179 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
3180
3181 begin
3182 Check_Arg_Count (2);
3183 Check_No_Identifiers;
3184 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3185 Analyze_And_Resolve (Arg1x, Standard_Boolean);
3186
3187 if Compile_Time_Known_Value (Arg1x) then
3188 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3189 declare
3190 Str : constant String_Id :=
3191 Strval (Get_Pragma_Arg (Arg2));
3192 Len : constant Int := String_Length (Str);
3193 Cont : Boolean;
3194 Ptr : Nat;
3195 CC : Char_Code;
3196 C : Character;
3197 Cent : constant Entity_Id :=
3198 Cunit_Entity (Current_Sem_Unit);
3199
3200 Force : constant Boolean :=
3201 Prag_Id = Pragma_Compile_Time_Warning
3202 and then
3203 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3204 and then (Ekind (Cent) /= E_Package
3205 or else not In_Private_Part (Cent));
3206 -- Set True if this is the warning case, and we are in the
3207 -- visible part of a package spec, or in a subprogram spec,
3208 -- in which case we want to force the client to see the
3209 -- warning, even though it is not in the main unit.
3210
3211 begin
3212 -- Loop through segments of message separated by line feeds.
3213 -- We output these segments as separate messages with
3214 -- continuation marks for all but the first.
3215
3216 Cont := False;
3217 Ptr := 1;
3218 loop
3219 Error_Msg_Strlen := 0;
3220
3221 -- Loop to copy characters from argument to error message
3222 -- string buffer.
3223
3224 loop
3225 exit when Ptr > Len;
3226 CC := Get_String_Char (Str, Ptr);
3227 Ptr := Ptr + 1;
3228
3229 -- Ignore wide chars ??? else store character
3230
3231 if In_Character_Range (CC) then
3232 C := Get_Character (CC);
3233 exit when C = ASCII.LF;
3234 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3235 Error_Msg_String (Error_Msg_Strlen) := C;
3236 end if;
3237 end loop;
3238
3239 -- Here with one line ready to go
3240
3241 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3242
3243 -- If this is a warning in a spec, then we want clients
3244 -- to see the warning, so mark the message with the
3245 -- special sequence !! to force the warning. In the case
3246 -- of a package spec, we do not force this if we are in
3247 -- the private part of the spec.
3248
3249 if Force then
3250 if Cont = False then
3251 Error_Msg_N ("<~!!", Arg1);
3252 Cont := True;
3253 else
3254 Error_Msg_N ("\<~!!", Arg1);
3255 end if;
3256
3257 -- Error, rather than warning, or in a body, so we do not
3258 -- need to force visibility for client (error will be
3259 -- output in any case, and this is the situation in which
3260 -- we do not want a client to get a warning, since the
3261 -- warning is in the body or the spec private part).
3262
3263 else
3264 if Cont = False then
3265 Error_Msg_N ("<~", Arg1);
3266 Cont := True;
3267 else
3268 Error_Msg_N ("\<~", Arg1);
3269 end if;
3270 end if;
3271
3272 exit when Ptr > Len;
3273 end loop;
3274 end;
3275 end if;
3276 end if;
3277 end Process_Compile_Time_Warning_Or_Error;
3278
3279 ------------------------
3280 -- Process_Convention --
3281 ------------------------
3282
3283 procedure Process_Convention
3284 (C : out Convention_Id;
3285 Ent : out Entity_Id)
3286 is
3287 Id : Node_Id;
3288 E : Entity_Id;
3289 E1 : Entity_Id;
3290 Cname : Name_Id;
3291 Comp_Unit : Unit_Number_Type;
3292
3293 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3294 -- Called if we have more than one Export/Import/Convention pragma.
3295 -- This is generally illegal, but we have a special case of allowing
3296 -- Import and Interface to coexist if they specify the convention in
3297 -- a consistent manner. We are allowed to do this, since Interface is
3298 -- an implementation defined pragma, and we choose to do it since we
3299 -- know Rational allows this combination. S is the entity id of the
3300 -- subprogram in question. This procedure also sets the special flag
3301 -- Import_Interface_Present in both pragmas in the case where we do
3302 -- have matching Import and Interface pragmas.
3303
3304 procedure Set_Convention_From_Pragma (E : Entity_Id);
3305 -- Set convention in entity E, and also flag that the entity has a
3306 -- convention pragma. If entity is for a private or incomplete type,
3307 -- also set convention and flag on underlying type. This procedure
3308 -- also deals with the special case of C_Pass_By_Copy convention.
3309
3310 -------------------------------
3311 -- Diagnose_Multiple_Pragmas --
3312 -------------------------------
3313
3314 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3315 Pdec : constant Node_Id := Declaration_Node (S);
3316 Decl : Node_Id;
3317 Err : Boolean;
3318
3319 function Same_Convention (Decl : Node_Id) return Boolean;
3320 -- Decl is a pragma node. This function returns True if this
3321 -- pragma has a first argument that is an identifier with a
3322 -- Chars field corresponding to the Convention_Id C.
3323
3324 function Same_Name (Decl : Node_Id) return Boolean;
3325 -- Decl is a pragma node. This function returns True if this
3326 -- pragma has a second argument that is an identifier with a
3327 -- Chars field that matches the Chars of the current subprogram.
3328
3329 ---------------------
3330 -- Same_Convention --
3331 ---------------------
3332
3333 function Same_Convention (Decl : Node_Id) return Boolean is
3334 Arg1 : constant Node_Id :=
3335 First (Pragma_Argument_Associations (Decl));
3336
3337 begin
3338 if Present (Arg1) then
3339 declare
3340 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3341 begin
3342 if Nkind (Arg) = N_Identifier
3343 and then Is_Convention_Name (Chars (Arg))
3344 and then Get_Convention_Id (Chars (Arg)) = C
3345 then
3346 return True;
3347 end if;
3348 end;
3349 end if;
3350
3351 return False;
3352 end Same_Convention;
3353
3354 ---------------
3355 -- Same_Name --
3356 ---------------
3357
3358 function Same_Name (Decl : Node_Id) return Boolean is
3359 Arg1 : constant Node_Id :=
3360 First (Pragma_Argument_Associations (Decl));
3361 Arg2 : Node_Id;
3362
3363 begin
3364 if No (Arg1) then
3365 return False;
3366 end if;
3367
3368 Arg2 := Next (Arg1);
3369
3370 if No (Arg2) then
3371 return False;
3372 end if;
3373
3374 declare
3375 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3376 begin
3377 if Nkind (Arg) = N_Identifier
3378 and then Chars (Arg) = Chars (S)
3379 then
3380 return True;
3381 end if;
3382 end;
3383
3384 return False;
3385 end Same_Name;
3386
3387 -- Start of processing for Diagnose_Multiple_Pragmas
3388
3389 begin
3390 Err := True;
3391
3392 -- Definitely give message if we have Convention/Export here
3393
3394 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3395 null;
3396
3397 -- If we have an Import or Export, scan back from pragma to
3398 -- find any previous pragma applying to the same procedure.
3399 -- The scan will be terminated by the start of the list, or
3400 -- hitting the subprogram declaration. This won't allow one
3401 -- pragma to appear in the public part and one in the private
3402 -- part, but that seems very unlikely in practice.
3403
3404 else
3405 Decl := Prev (N);
3406 while Present (Decl) and then Decl /= Pdec loop
3407
3408 -- Look for pragma with same name as us
3409
3410 if Nkind (Decl) = N_Pragma
3411 and then Same_Name (Decl)
3412 then
3413 -- Give error if same as our pragma or Export/Convention
3414
3415 if Pragma_Name (Decl) = Name_Export
3416 or else
3417 Pragma_Name (Decl) = Name_Convention
3418 or else
3419 Pragma_Name (Decl) = Pragma_Name (N)
3420 then
3421 exit;
3422
3423 -- Case of Import/Interface or the other way round
3424
3425 elsif Pragma_Name (Decl) = Name_Interface
3426 or else
3427 Pragma_Name (Decl) = Name_Import
3428 then
3429 -- Here we know that we have Import and Interface. It
3430 -- doesn't matter which way round they are. See if
3431 -- they specify the same convention. If so, all OK,
3432 -- and set special flags to stop other messages
3433
3434 if Same_Convention (Decl) then
3435 Set_Import_Interface_Present (N);
3436 Set_Import_Interface_Present (Decl);
3437 Err := False;
3438
3439 -- If different conventions, special message
3440
3441 else
3442 Error_Msg_Sloc := Sloc (Decl);
3443 Error_Pragma_Arg
3444 ("convention differs from that given#", Arg1);
3445 return;
3446 end if;
3447 end if;
3448 end if;
3449
3450 Next (Decl);
3451 end loop;
3452 end if;
3453
3454 -- Give message if needed if we fall through those tests
3455
3456 if Err then
3457 Error_Pragma_Arg
3458 ("at most one Convention/Export/Import pragma is allowed",
3459 Arg2);
3460 end if;
3461 end Diagnose_Multiple_Pragmas;
3462
3463 --------------------------------
3464 -- Set_Convention_From_Pragma --
3465 --------------------------------
3466
3467 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3468 begin
3469 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3470 -- for an overridden dispatching operation. Technically this is
3471 -- an amendment and should only be done in Ada 2005 mode. However,
3472 -- this is clearly a mistake, since the problem that is addressed
3473 -- by this AI is that there is a clear gap in the RM!
3474
3475 if Is_Dispatching_Operation (E)
3476 and then Present (Overridden_Operation (E))
3477 and then C /= Convention (Overridden_Operation (E))
3478 then
3479 Error_Pragma_Arg
3480 ("cannot change convention for " &
3481 "overridden dispatching operation",
3482 Arg1);
3483 end if;
3484
3485 -- Set the convention
3486
3487 Set_Convention (E, C);
3488 Set_Has_Convention_Pragma (E);
3489
3490 if Is_Incomplete_Or_Private_Type (E)
3491 and then Present (Underlying_Type (E))
3492 then
3493 Set_Convention (Underlying_Type (E), C);
3494 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3495 end if;
3496
3497 -- A class-wide type should inherit the convention of the specific
3498 -- root type (although this isn't specified clearly by the RM).
3499
3500 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3501 Set_Convention (Class_Wide_Type (E), C);
3502 end if;
3503
3504 -- If the entity is a record type, then check for special case of
3505 -- C_Pass_By_Copy, which is treated the same as C except that the
3506 -- special record flag is set. This convention is only permitted
3507 -- on record types (see AI95-00131).
3508
3509 if Cname = Name_C_Pass_By_Copy then
3510 if Is_Record_Type (E) then
3511 Set_C_Pass_By_Copy (Base_Type (E));
3512 elsif Is_Incomplete_Or_Private_Type (E)
3513 and then Is_Record_Type (Underlying_Type (E))
3514 then
3515 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3516 else
3517 Error_Pragma_Arg
3518 ("C_Pass_By_Copy convention allowed only for record type",
3519 Arg2);
3520 end if;
3521 end if;
3522
3523 -- If the entity is a derived boolean type, check for the special
3524 -- case of convention C, C++, or Fortran, where we consider any
3525 -- nonzero value to represent true.
3526
3527 if Is_Discrete_Type (E)
3528 and then Root_Type (Etype (E)) = Standard_Boolean
3529 and then
3530 (C = Convention_C
3531 or else
3532 C = Convention_CPP
3533 or else
3534 C = Convention_Fortran)
3535 then
3536 Set_Nonzero_Is_True (Base_Type (E));
3537 end if;
3538 end Set_Convention_From_Pragma;
3539
3540 -- Start of processing for Process_Convention
3541
3542 begin
3543 Check_At_Least_N_Arguments (2);
3544 Check_Optional_Identifier (Arg1, Name_Convention);
3545 Check_Arg_Is_Identifier (Arg1);
3546 Cname := Chars (Get_Pragma_Arg (Arg1));
3547
3548 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3549 -- tested again below to set the critical flag).
3550
3551 if Cname = Name_C_Pass_By_Copy then
3552 C := Convention_C;
3553
3554 -- Otherwise we must have something in the standard convention list
3555
3556 elsif Is_Convention_Name (Cname) then
3557 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3558
3559 -- In DEC VMS, it seems that there is an undocumented feature that
3560 -- any unrecognized convention is treated as the default, which for
3561 -- us is convention C. It does not seem so terrible to do this
3562 -- unconditionally, silently in the VMS case, and with a warning
3563 -- in the non-VMS case.
3564
3565 else
3566 if Warn_On_Export_Import and not OpenVMS_On_Target then
3567 Error_Msg_N
3568 ("??unrecognized convention name, C assumed",
3569 Get_Pragma_Arg (Arg1));
3570 end if;
3571
3572 C := Convention_C;
3573 end if;
3574
3575 Check_Optional_Identifier (Arg2, Name_Entity);
3576 Check_Arg_Is_Local_Name (Arg2);
3577
3578 Id := Get_Pragma_Arg (Arg2);
3579 Analyze (Id);
3580
3581 if not Is_Entity_Name (Id) then
3582 Error_Pragma_Arg ("entity name required", Arg2);
3583 end if;
3584
3585 E := Entity (Id);
3586
3587 -- Set entity to return
3588
3589 Ent := E;
3590
3591 -- Ada_Pass_By_Copy special checking
3592
3593 if C = Convention_Ada_Pass_By_Copy then
3594 if not Is_First_Subtype (E) then
3595 Error_Pragma_Arg
3596 ("convention `Ada_Pass_By_Copy` only "
3597 & "allowed for types", Arg2);
3598 end if;
3599
3600 if Is_By_Reference_Type (E) then
3601 Error_Pragma_Arg
3602 ("convention `Ada_Pass_By_Copy` not allowed for "
3603 & "by-reference type", Arg1);
3604 end if;
3605 end if;
3606
3607 -- Ada_Pass_By_Reference special checking
3608
3609 if C = Convention_Ada_Pass_By_Reference then
3610 if not Is_First_Subtype (E) then
3611 Error_Pragma_Arg
3612 ("convention `Ada_Pass_By_Reference` only "
3613 & "allowed for types", Arg2);
3614 end if;
3615
3616 if Is_By_Copy_Type (E) then
3617 Error_Pragma_Arg
3618 ("convention `Ada_Pass_By_Reference` not allowed for "
3619 & "by-copy type", Arg1);
3620 end if;
3621 end if;
3622
3623 -- Go to renamed subprogram if present, since convention applies to
3624 -- the actual renamed entity, not to the renaming entity. If the
3625 -- subprogram is inherited, go to parent subprogram.
3626
3627 if Is_Subprogram (E)
3628 and then Present (Alias (E))
3629 then
3630 if Nkind (Parent (Declaration_Node (E))) =
3631 N_Subprogram_Renaming_Declaration
3632 then
3633 if Scope (E) /= Scope (Alias (E)) then
3634 Error_Pragma_Ref
3635 ("cannot apply pragma% to non-local entity&#", E);
3636 end if;
3637
3638 E := Alias (E);
3639
3640 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3641 N_Private_Extension_Declaration)
3642 and then Scope (E) = Scope (Alias (E))
3643 then
3644 E := Alias (E);
3645
3646 -- Return the parent subprogram the entity was inherited from
3647
3648 Ent := E;
3649 end if;
3650 end if;
3651
3652 -- Check that we are not applying this to a specless body
3653 -- Relax this check if Relaxed_RM_Semantics to accomodate other Ada
3654 -- compilers.
3655
3656 if Is_Subprogram (E)
3657 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3658 and then not Relaxed_RM_Semantics
3659 then
3660 Error_Pragma
3661 ("pragma% requires separate spec and must come before body");
3662 end if;
3663
3664 -- Check that we are not applying this to a named constant
3665
3666 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3667 Error_Msg_Name_1 := Pname;
3668 Error_Msg_N
3669 ("cannot apply pragma% to named constant!",
3670 Get_Pragma_Arg (Arg2));
3671 Error_Pragma_Arg
3672 ("\supply appropriate type for&!", Arg2);
3673 end if;
3674
3675 if Ekind (E) = E_Enumeration_Literal then
3676 Error_Pragma ("enumeration literal not allowed for pragma%");
3677 end if;
3678
3679 -- Check for rep item appearing too early or too late
3680
3681 if Etype (E) = Any_Type
3682 or else Rep_Item_Too_Early (E, N)
3683 then
3684 raise Pragma_Exit;
3685
3686 elsif Present (Underlying_Type (E)) then
3687 E := Underlying_Type (E);
3688 end if;
3689
3690 if Rep_Item_Too_Late (E, N) then
3691 raise Pragma_Exit;
3692 end if;
3693
3694 if Has_Convention_Pragma (E) then
3695 Diagnose_Multiple_Pragmas (E);
3696
3697 elsif Convention (E) = Convention_Protected
3698 or else Ekind (Scope (E)) = E_Protected_Type
3699 then
3700 Error_Pragma_Arg
3701 ("a protected operation cannot be given a different convention",
3702 Arg2);
3703 end if;
3704
3705 -- For Intrinsic, a subprogram is required
3706
3707 if C = Convention_Intrinsic
3708 and then not Is_Subprogram (E)
3709 and then not Is_Generic_Subprogram (E)
3710 then
3711 Error_Pragma_Arg
3712 ("second argument of pragma% must be a subprogram", Arg2);
3713 end if;
3714
3715 -- Stdcall case
3716
3717 if C = Convention_Stdcall then
3718
3719 -- A dispatching call is not allowed. A dispatching subprogram
3720 -- cannot be used to interface to the Win32 API, so in fact this
3721 -- check does not impose any effective restriction.
3722
3723 if Is_Dispatching_Operation (E) then
3724
3725 Error_Pragma
3726 ("dispatching subprograms cannot use Stdcall convention");
3727
3728 -- Subprogram is allowed, but not a generic subprogram, and not a
3729 -- dispatching operation.
3730
3731 elsif not Is_Subprogram (E)
3732 and then not Is_Generic_Subprogram (E)
3733
3734 -- A variable is OK
3735
3736 and then Ekind (E) /= E_Variable
3737
3738 -- An access to subprogram is also allowed
3739
3740 and then not
3741 (Is_Access_Type (E)
3742 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3743 then
3744 Error_Pragma_Arg
3745 ("second argument of pragma% must be subprogram (type)",
3746 Arg2);
3747 end if;
3748 end if;
3749
3750 if not Is_Subprogram (E)
3751 and then not Is_Generic_Subprogram (E)
3752 then
3753 Set_Convention_From_Pragma (E);
3754
3755 if Is_Type (E) then
3756 Check_First_Subtype (Arg2);
3757 Set_Convention_From_Pragma (Base_Type (E));
3758
3759 -- For subprograms, we must set the convention on the
3760 -- internally generated directly designated type as well.
3761
3762 if Ekind (E) = E_Access_Subprogram_Type then
3763 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3764 end if;
3765 end if;
3766
3767 -- For the subprogram case, set proper convention for all homonyms
3768 -- in same scope and the same declarative part, i.e. the same
3769 -- compilation unit.
3770
3771 else
3772 Comp_Unit := Get_Source_Unit (E);
3773 Set_Convention_From_Pragma (E);
3774
3775 -- Treat a pragma Import as an implicit body, and pragma import
3776 -- as implicit reference (for navigation in GPS).
3777
3778 if Prag_Id = Pragma_Import then
3779 Generate_Reference (E, Id, 'b');
3780
3781 -- For exported entities we restrict the generation of references
3782 -- to entities exported to foreign languages since entities
3783 -- exported to Ada do not provide further information to GPS and
3784 -- add undesired references to the output of the gnatxref tool.
3785
3786 elsif Prag_Id = Pragma_Export
3787 and then Convention (E) /= Convention_Ada
3788 then
3789 Generate_Reference (E, Id, 'i');
3790 end if;
3791
3792 -- If the pragma comes from from an aspect, it only applies
3793 -- to the given entity, not its homonyms.
3794
3795 if From_Aspect_Specification (N) then
3796 return;
3797 end if;
3798
3799 -- Otherwise Loop through the homonyms of the pragma argument's
3800 -- entity, an apply convention to those in the current scope.
3801
3802 E1 := Ent;
3803
3804 loop
3805 E1 := Homonym (E1);
3806 exit when No (E1) or else Scope (E1) /= Current_Scope;
3807
3808 -- Do not set the pragma on inherited operations or on formal
3809 -- subprograms.
3810
3811 if Comes_From_Source (E1)
3812 and then Comp_Unit = Get_Source_Unit (E1)
3813 and then not Is_Formal_Subprogram (E1)
3814 and then Nkind (Original_Node (Parent (E1))) /=
3815 N_Full_Type_Declaration
3816 then
3817 if Present (Alias (E1))
3818 and then Scope (E1) /= Scope (Alias (E1))
3819 then
3820 Error_Pragma_Ref
3821 ("cannot apply pragma% to non-local entity& declared#",
3822 E1);
3823 end if;
3824
3825 Set_Convention_From_Pragma (E1);
3826
3827 if Prag_Id = Pragma_Import then
3828 Generate_Reference (E1, Id, 'b');
3829 end if;
3830 end if;
3831 end loop;
3832 end if;
3833 end Process_Convention;
3834
3835 ----------------------------------------
3836 -- Process_Disable_Enable_Atomic_Sync --
3837 ----------------------------------------
3838
3839 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3840 begin
3841 GNAT_Pragma;
3842 Check_No_Identifiers;
3843 Check_At_Most_N_Arguments (1);
3844
3845 -- Modeled internally as
3846 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
3847
3848 Rewrite (N,
3849 Make_Pragma (Loc,
3850 Pragma_Identifier =>
3851 Make_Identifier (Loc, Nam),
3852 Pragma_Argument_Associations => New_List (
3853 Make_Pragma_Argument_Association (Loc,
3854 Expression =>
3855 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3856
3857 if Present (Arg1) then
3858 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3859 end if;
3860
3861 Analyze (N);
3862 end Process_Disable_Enable_Atomic_Sync;
3863
3864 -----------------------------------------------------
3865 -- Process_Extended_Import_Export_Exception_Pragma --
3866 -----------------------------------------------------
3867
3868 procedure Process_Extended_Import_Export_Exception_Pragma
3869 (Arg_Internal : Node_Id;
3870 Arg_External : Node_Id;
3871 Arg_Form : Node_Id;
3872 Arg_Code : Node_Id)
3873 is
3874 Def_Id : Entity_Id;
3875 Code_Val : Uint;
3876
3877 begin
3878 if not OpenVMS_On_Target then
3879 Error_Pragma
3880 ("??pragma% ignored (applies only to Open'V'M'S)");
3881 end if;
3882
3883 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3884 Def_Id := Entity (Arg_Internal);
3885
3886 if Ekind (Def_Id) /= E_Exception then
3887 Error_Pragma_Arg
3888 ("pragma% must refer to declared exception", Arg_Internal);
3889 end if;
3890
3891 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3892
3893 if Present (Arg_Form) then
3894 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3895 end if;
3896
3897 if Present (Arg_Form)
3898 and then Chars (Arg_Form) = Name_Ada
3899 then
3900 null;
3901 else
3902 Set_Is_VMS_Exception (Def_Id);
3903 Set_Exception_Code (Def_Id, No_Uint);
3904 end if;
3905
3906 if Present (Arg_Code) then
3907 if not Is_VMS_Exception (Def_Id) then
3908 Error_Pragma_Arg
3909 ("Code option for pragma% not allowed for Ada case",
3910 Arg_Code);
3911 end if;
3912
3913 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3914 Code_Val := Expr_Value (Arg_Code);
3915
3916 if not UI_Is_In_Int_Range (Code_Val) then
3917 Error_Pragma_Arg
3918 ("Code option for pragma% must be in 32-bit range",
3919 Arg_Code);
3920
3921 else
3922 Set_Exception_Code (Def_Id, Code_Val);
3923 end if;
3924 end if;
3925 end Process_Extended_Import_Export_Exception_Pragma;
3926
3927 -------------------------------------------------
3928 -- Process_Extended_Import_Export_Internal_Arg --
3929 -------------------------------------------------
3930
3931 procedure Process_Extended_Import_Export_Internal_Arg
3932 (Arg_Internal : Node_Id := Empty)
3933 is
3934 begin
3935 if No (Arg_Internal) then
3936 Error_Pragma ("Internal parameter required for pragma%");
3937 end if;
3938
3939 if Nkind (Arg_Internal) = N_Identifier then
3940 null;
3941
3942 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3943 and then (Prag_Id = Pragma_Import_Function
3944 or else
3945 Prag_Id = Pragma_Export_Function)
3946 then
3947 null;
3948
3949 else
3950 Error_Pragma_Arg
3951 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3952 end if;
3953
3954 Check_Arg_Is_Local_Name (Arg_Internal);
3955 end Process_Extended_Import_Export_Internal_Arg;
3956
3957 --------------------------------------------------
3958 -- Process_Extended_Import_Export_Object_Pragma --
3959 --------------------------------------------------
3960
3961 procedure Process_Extended_Import_Export_Object_Pragma
3962 (Arg_Internal : Node_Id;
3963 Arg_External : Node_Id;
3964 Arg_Size : Node_Id)
3965 is
3966 Def_Id : Entity_Id;
3967
3968 begin
3969 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3970 Def_Id := Entity (Arg_Internal);
3971
3972 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3973 Error_Pragma_Arg
3974 ("pragma% must designate an object", Arg_Internal);
3975 end if;
3976
3977 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3978 or else
3979 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3980 then
3981 Error_Pragma_Arg
3982 ("previous Common/Psect_Object applies, pragma % not permitted",
3983 Arg_Internal);
3984 end if;
3985
3986 if Rep_Item_Too_Late (Def_Id, N) then
3987 raise Pragma_Exit;
3988 end if;
3989
3990 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3991
3992 if Present (Arg_Size) then
3993 Check_Arg_Is_External_Name (Arg_Size);
3994 end if;
3995
3996 -- Export_Object case
3997
3998 if Prag_Id = Pragma_Export_Object then
3999 if not Is_Library_Level_Entity (Def_Id) then
4000 Error_Pragma_Arg
4001 ("argument for pragma% must be library level entity",
4002 Arg_Internal);
4003 end if;
4004
4005 if Ekind (Current_Scope) = E_Generic_Package then
4006 Error_Pragma ("pragma& cannot appear in a generic unit");
4007 end if;
4008
4009 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
4010 Error_Pragma_Arg
4011 ("exported object must have compile time known size",
4012 Arg_Internal);
4013 end if;
4014
4015 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
4016 Error_Msg_N ("??duplicate Export_Object pragma", N);
4017 else
4018 Set_Exported (Def_Id, Arg_Internal);
4019 end if;
4020
4021 -- Import_Object case
4022
4023 else
4024 if Is_Concurrent_Type (Etype (Def_Id)) then
4025 Error_Pragma_Arg
4026 ("cannot use pragma% for task/protected object",
4027 Arg_Internal);
4028 end if;
4029
4030 if Ekind (Def_Id) = E_Constant then
4031 Error_Pragma_Arg
4032 ("cannot import a constant", Arg_Internal);
4033 end if;
4034
4035 if Warn_On_Export_Import
4036 and then Has_Discriminants (Etype (Def_Id))
4037 then
4038 Error_Msg_N
4039 ("imported value must be initialized??", Arg_Internal);
4040 end if;
4041
4042 if Warn_On_Export_Import
4043 and then Is_Access_Type (Etype (Def_Id))
4044 then
4045 Error_Pragma_Arg
4046 ("cannot import object of an access type??", Arg_Internal);
4047 end if;
4048
4049 if Warn_On_Export_Import
4050 and then Is_Imported (Def_Id)
4051 then
4052 Error_Msg_N ("??duplicate Import_Object pragma", N);
4053
4054 -- Check for explicit initialization present. Note that an
4055 -- initialization generated by the code generator, e.g. for an
4056 -- access type, does not count here.
4057
4058 elsif Present (Expression (Parent (Def_Id)))
4059 and then
4060 Comes_From_Source
4061 (Original_Node (Expression (Parent (Def_Id))))
4062 then
4063 Error_Msg_Sloc := Sloc (Def_Id);
4064 Error_Pragma_Arg
4065 ("imported entities cannot be initialized (RM B.1(24))",
4066 "\no initialization allowed for & declared#", Arg1);
4067 else
4068 Set_Imported (Def_Id);
4069 Note_Possible_Modification (Arg_Internal, Sure => False);
4070 end if;
4071 end if;
4072 end Process_Extended_Import_Export_Object_Pragma;
4073
4074 ------------------------------------------------------
4075 -- Process_Extended_Import_Export_Subprogram_Pragma --
4076 ------------------------------------------------------
4077
4078 procedure Process_Extended_Import_Export_Subprogram_Pragma
4079 (Arg_Internal : Node_Id;
4080 Arg_External : Node_Id;
4081 Arg_Parameter_Types : Node_Id;
4082 Arg_Result_Type : Node_Id := Empty;
4083 Arg_Mechanism : Node_Id;
4084 Arg_Result_Mechanism : Node_Id := Empty;
4085 Arg_First_Optional_Parameter : Node_Id := Empty)
4086 is
4087 Ent : Entity_Id;
4088 Def_Id : Entity_Id;
4089 Hom_Id : Entity_Id;
4090 Formal : Entity_Id;
4091 Ambiguous : Boolean;
4092 Match : Boolean;
4093 Dval : Node_Id;
4094
4095 function Same_Base_Type
4096 (Ptype : Node_Id;
4097 Formal : Entity_Id) return Boolean;
4098 -- Determines if Ptype references the type of Formal. Note that only
4099 -- the base types need to match according to the spec. Ptype here is
4100 -- the argument from the pragma, which is either a type name, or an
4101 -- access attribute.
4102
4103 --------------------
4104 -- Same_Base_Type --
4105 --------------------
4106
4107 function Same_Base_Type
4108 (Ptype : Node_Id;
4109 Formal : Entity_Id) return Boolean
4110 is
4111 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
4112 Pref : Node_Id;
4113
4114 begin
4115 -- Case where pragma argument is typ'Access
4116
4117 if Nkind (Ptype) = N_Attribute_Reference
4118 and then Attribute_Name (Ptype) = Name_Access
4119 then
4120 Pref := Prefix (Ptype);
4121 Find_Type (Pref);
4122
4123 if not Is_Entity_Name (Pref)
4124 or else Entity (Pref) = Any_Type
4125 then
4126 raise Pragma_Exit;
4127 end if;
4128
4129 -- We have a match if the corresponding argument is of an
4130 -- anonymous access type, and its designated type matches the
4131 -- type of the prefix of the access attribute
4132
4133 return Ekind (Ftyp) = E_Anonymous_Access_Type
4134 and then Base_Type (Entity (Pref)) =
4135 Base_Type (Etype (Designated_Type (Ftyp)));
4136
4137 -- Case where pragma argument is a type name
4138
4139 else
4140 Find_Type (Ptype);
4141
4142 if not Is_Entity_Name (Ptype)
4143 or else Entity (Ptype) = Any_Type
4144 then
4145 raise Pragma_Exit;
4146 end if;
4147
4148 -- We have a match if the corresponding argument is of the type
4149 -- given in the pragma (comparing base types)
4150
4151 return Base_Type (Entity (Ptype)) = Ftyp;
4152 end if;
4153 end Same_Base_Type;
4154
4155 -- Start of processing for
4156 -- Process_Extended_Import_Export_Subprogram_Pragma
4157
4158 begin
4159 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
4160 Ent := Empty;
4161 Ambiguous := False;
4162
4163 -- Loop through homonyms (overloadings) of the entity
4164
4165 Hom_Id := Entity (Arg_Internal);
4166 while Present (Hom_Id) loop
4167 Def_Id := Get_Base_Subprogram (Hom_Id);
4168
4169 -- We need a subprogram in the current scope
4170
4171 if not Is_Subprogram (Def_Id)
4172 or else Scope (Def_Id) /= Current_Scope
4173 then
4174 null;
4175
4176 else
4177 Match := True;
4178
4179 -- Pragma cannot apply to subprogram body
4180
4181 if Is_Subprogram (Def_Id)
4182 and then Nkind (Parent (Declaration_Node (Def_Id))) =
4183 N_Subprogram_Body
4184 then
4185 Error_Pragma
4186 ("pragma% requires separate spec"
4187 & " and must come before body");
4188 end if;
4189
4190 -- Test result type if given, note that the result type
4191 -- parameter can only be present for the function cases.
4192
4193 if Present (Arg_Result_Type)
4194 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
4195 then
4196 Match := False;
4197
4198 elsif Etype (Def_Id) /= Standard_Void_Type
4199 and then
4200 (Pname = Name_Export_Procedure
4201 or else
4202 Pname = Name_Import_Procedure)
4203 then
4204 Match := False;
4205
4206 -- Test parameter types if given. Note that this parameter
4207 -- has not been analyzed (and must not be, since it is
4208 -- semantic nonsense), so we get it as the parser left it.
4209
4210 elsif Present (Arg_Parameter_Types) then
4211 Check_Matching_Types : declare
4212 Formal : Entity_Id;
4213 Ptype : Node_Id;
4214
4215 begin
4216 Formal := First_Formal (Def_Id);
4217
4218 if Nkind (Arg_Parameter_Types) = N_Null then
4219 if Present (Formal) then
4220 Match := False;
4221 end if;
4222
4223 -- A list of one type, e.g. (List) is parsed as
4224 -- a parenthesized expression.
4225
4226 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4227 and then Paren_Count (Arg_Parameter_Types) = 1
4228 then
4229 if No (Formal)
4230 or else Present (Next_Formal (Formal))
4231 then
4232 Match := False;
4233 else
4234 Match :=
4235 Same_Base_Type (Arg_Parameter_Types, Formal);
4236 end if;
4237
4238 -- A list of more than one type is parsed as a aggregate
4239
4240 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4241 and then Paren_Count (Arg_Parameter_Types) = 0
4242 then
4243 Ptype := First (Expressions (Arg_Parameter_Types));
4244 while Present (Ptype) or else Present (Formal) loop
4245 if No (Ptype)
4246 or else No (Formal)
4247 or else not Same_Base_Type (Ptype, Formal)
4248 then
4249 Match := False;
4250 exit;
4251 else
4252 Next_Formal (Formal);
4253 Next (Ptype);
4254 end if;
4255 end loop;
4256
4257 -- Anything else is of the wrong form
4258
4259 else
4260 Error_Pragma_Arg
4261 ("wrong form for Parameter_Types parameter",
4262 Arg_Parameter_Types);
4263 end if;
4264 end Check_Matching_Types;
4265 end if;
4266
4267 -- Match is now False if the entry we found did not match
4268 -- either a supplied Parameter_Types or Result_Types argument
4269
4270 if Match then
4271 if No (Ent) then
4272 Ent := Def_Id;
4273
4274 -- Ambiguous case, the flag Ambiguous shows if we already
4275 -- detected this and output the initial messages.
4276
4277 else
4278 if not Ambiguous then
4279 Ambiguous := True;
4280 Error_Msg_Name_1 := Pname;
4281 Error_Msg_N
4282 ("pragma% does not uniquely identify subprogram!",
4283 N);
4284 Error_Msg_Sloc := Sloc (Ent);
4285 Error_Msg_N ("matching subprogram #!", N);
4286 Ent := Empty;
4287 end if;
4288
4289 Error_Msg_Sloc := Sloc (Def_Id);
4290 Error_Msg_N ("matching subprogram #!", N);
4291 end if;
4292 end if;
4293 end if;
4294
4295 Hom_Id := Homonym (Hom_Id);
4296 end loop;
4297
4298 -- See if we found an entry
4299
4300 if No (Ent) then
4301 if not Ambiguous then
4302 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4303 Error_Pragma
4304 ("pragma% cannot be given for generic subprogram");
4305 else
4306 Error_Pragma
4307 ("pragma% does not identify local subprogram");
4308 end if;
4309 end if;
4310
4311 return;
4312 end if;
4313
4314 -- Import pragmas must be for imported entities
4315
4316 if Prag_Id = Pragma_Import_Function
4317 or else
4318 Prag_Id = Pragma_Import_Procedure
4319 or else
4320 Prag_Id = Pragma_Import_Valued_Procedure
4321 then
4322 if not Is_Imported (Ent) then
4323 Error_Pragma
4324 ("pragma Import or Interface must precede pragma%");
4325 end if;
4326
4327 -- Here we have the Export case which can set the entity as exported
4328
4329 -- But does not do so if the specified external name is null, since
4330 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4331 -- compatible) to request no external name.
4332
4333 elsif Nkind (Arg_External) = N_String_Literal
4334 and then String_Length (Strval (Arg_External)) = 0
4335 then
4336 null;
4337
4338 -- In all other cases, set entity as exported
4339
4340 else
4341 Set_Exported (Ent, Arg_Internal);
4342 end if;
4343
4344 -- Special processing for Valued_Procedure cases
4345
4346 if Prag_Id = Pragma_Import_Valued_Procedure
4347 or else
4348 Prag_Id = Pragma_Export_Valued_Procedure
4349 then
4350 Formal := First_Formal (Ent);
4351
4352 if No (Formal) then
4353 Error_Pragma ("at least one parameter required for pragma%");
4354
4355 elsif Ekind (Formal) /= E_Out_Parameter then
4356 Error_Pragma ("first parameter must have mode out for pragma%");
4357
4358 else
4359 Set_Is_Valued_Procedure (Ent);
4360 end if;
4361 end if;
4362
4363 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4364
4365 -- Process Result_Mechanism argument if present. We have already
4366 -- checked that this is only allowed for the function case.
4367
4368 if Present (Arg_Result_Mechanism) then
4369 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4370 end if;
4371
4372 -- Process Mechanism parameter if present. Note that this parameter
4373 -- is not analyzed, and must not be analyzed since it is semantic
4374 -- nonsense, so we get it in exactly as the parser left it.
4375
4376 if Present (Arg_Mechanism) then
4377 declare
4378 Formal : Entity_Id;
4379 Massoc : Node_Id;
4380 Mname : Node_Id;
4381 Choice : Node_Id;
4382
4383 begin
4384 -- A single mechanism association without a formal parameter
4385 -- name is parsed as a parenthesized expression. All other
4386 -- cases are parsed as aggregates, so we rewrite the single
4387 -- parameter case as an aggregate for consistency.
4388
4389 if Nkind (Arg_Mechanism) /= N_Aggregate
4390 and then Paren_Count (Arg_Mechanism) = 1
4391 then
4392 Rewrite (Arg_Mechanism,
4393 Make_Aggregate (Sloc (Arg_Mechanism),
4394 Expressions => New_List (
4395 Relocate_Node (Arg_Mechanism))));
4396 end if;
4397
4398 -- Case of only mechanism name given, applies to all formals
4399
4400 if Nkind (Arg_Mechanism) /= N_Aggregate then
4401 Formal := First_Formal (Ent);
4402 while Present (Formal) loop
4403 Set_Mechanism_Value (Formal, Arg_Mechanism);
4404 Next_Formal (Formal);
4405 end loop;
4406
4407 -- Case of list of mechanism associations given
4408
4409 else
4410 if Null_Record_Present (Arg_Mechanism) then
4411 Error_Pragma_Arg
4412 ("inappropriate form for Mechanism parameter",
4413 Arg_Mechanism);
4414 end if;
4415
4416 -- Deal with positional ones first
4417
4418 Formal := First_Formal (Ent);
4419
4420 if Present (Expressions (Arg_Mechanism)) then
4421 Mname := First (Expressions (Arg_Mechanism));
4422 while Present (Mname) loop
4423 if No (Formal) then
4424 Error_Pragma_Arg
4425 ("too many mechanism associations", Mname);
4426 end if;
4427
4428 Set_Mechanism_Value (Formal, Mname);
4429 Next_Formal (Formal);
4430 Next (Mname);
4431 end loop;
4432 end if;
4433
4434 -- Deal with named entries
4435
4436 if Present (Component_Associations (Arg_Mechanism)) then
4437 Massoc := First (Component_Associations (Arg_Mechanism));
4438 while Present (Massoc) loop
4439 Choice := First (Choices (Massoc));
4440
4441 if Nkind (Choice) /= N_Identifier
4442 or else Present (Next (Choice))
4443 then
4444 Error_Pragma_Arg
4445 ("incorrect form for mechanism association",
4446 Massoc);
4447 end if;
4448
4449 Formal := First_Formal (Ent);
4450 loop
4451 if No (Formal) then
4452 Error_Pragma_Arg
4453 ("parameter name & not present", Choice);
4454 end if;
4455
4456 if Chars (Choice) = Chars (Formal) then
4457 Set_Mechanism_Value
4458 (Formal, Expression (Massoc));
4459
4460 -- Set entity on identifier (needed by ASIS)
4461
4462 Set_Entity (Choice, Formal);
4463
4464 exit;
4465 end if;
4466
4467 Next_Formal (Formal);
4468 end loop;
4469
4470 Next (Massoc);
4471 end loop;
4472 end if;
4473 end if;
4474 end;
4475 end if;
4476
4477 -- Process First_Optional_Parameter argument if present. We have
4478 -- already checked that this is only allowed for the Import case.
4479
4480 if Present (Arg_First_Optional_Parameter) then
4481 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4482 Error_Pragma_Arg
4483 ("first optional parameter must be formal parameter name",
4484 Arg_First_Optional_Parameter);
4485 end if;
4486
4487 Formal := First_Formal (Ent);
4488 loop
4489 if No (Formal) then
4490 Error_Pragma_Arg
4491 ("specified formal parameter& not found",
4492 Arg_First_Optional_Parameter);
4493 end if;
4494
4495 exit when Chars (Formal) =
4496 Chars (Arg_First_Optional_Parameter);
4497
4498 Next_Formal (Formal);
4499 end loop;
4500
4501 Set_First_Optional_Parameter (Ent, Formal);
4502
4503 -- Check specified and all remaining formals have right form
4504
4505 while Present (Formal) loop
4506 if Ekind (Formal) /= E_In_Parameter then
4507 Error_Msg_NE
4508 ("optional formal& is not of mode in!",
4509 Arg_First_Optional_Parameter, Formal);
4510
4511 else
4512 Dval := Default_Value (Formal);
4513
4514 if No (Dval) then
4515 Error_Msg_NE
4516 ("optional formal& does not have default value!",
4517 Arg_First_Optional_Parameter, Formal);
4518
4519 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4520 null;
4521
4522 else
4523 Error_Msg_FE
4524 ("default value for optional formal& is non-static!",
4525 Arg_First_Optional_Parameter, Formal);
4526 end if;
4527 end if;
4528
4529 Set_Is_Optional_Parameter (Formal);
4530 Next_Formal (Formal);
4531 end loop;
4532 end if;
4533 end Process_Extended_Import_Export_Subprogram_Pragma;
4534
4535 --------------------------
4536 -- Process_Generic_List --
4537 --------------------------
4538
4539 procedure Process_Generic_List is
4540 Arg : Node_Id;
4541 Exp : Node_Id;
4542
4543 begin
4544 Check_No_Identifiers;
4545 Check_At_Least_N_Arguments (1);
4546
4547 Arg := Arg1;
4548 while Present (Arg) loop
4549 Exp := Get_Pragma_Arg (Arg);
4550 Analyze (Exp);
4551
4552 if not Is_Entity_Name (Exp)
4553 or else
4554 (not Is_Generic_Instance (Entity (Exp))
4555 and then
4556 not Is_Generic_Unit (Entity (Exp)))
4557 then
4558 Error_Pragma_Arg
4559 ("pragma% argument must be name of generic unit/instance",
4560 Arg);
4561 end if;
4562
4563 Next (Arg);
4564 end loop;
4565 end Process_Generic_List;
4566
4567 ------------------------------------
4568 -- Process_Import_Predefined_Type --
4569 ------------------------------------
4570
4571 procedure Process_Import_Predefined_Type is
4572 Loc : constant Source_Ptr := Sloc (N);
4573 Elmt : Elmt_Id;
4574 Ftyp : Node_Id := Empty;
4575 Decl : Node_Id;
4576 Def : Node_Id;
4577 Nam : Name_Id;
4578
4579 begin
4580 String_To_Name_Buffer (Strval (Expression (Arg3)));
4581 Nam := Name_Find;
4582
4583 Elmt := First_Elmt (Predefined_Float_Types);
4584 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4585 Next_Elmt (Elmt);
4586 end loop;
4587
4588 Ftyp := Node (Elmt);
4589
4590 if Present (Ftyp) then
4591
4592 -- Don't build a derived type declaration, because predefined C
4593 -- types have no declaration anywhere, so cannot really be named.
4594 -- Instead build a full type declaration, starting with an
4595 -- appropriate type definition is built
4596
4597 if Is_Floating_Point_Type (Ftyp) then
4598 Def := Make_Floating_Point_Definition (Loc,
4599 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4600 Make_Real_Range_Specification (Loc,
4601 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4602 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4603
4604 -- Should never have a predefined type we cannot handle
4605
4606 else
4607 raise Program_Error;
4608 end if;
4609
4610 -- Build and insert a Full_Type_Declaration, which will be
4611 -- analyzed as soon as this list entry has been analyzed.
4612
4613 Decl := Make_Full_Type_Declaration (Loc,
4614 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4615 Type_Definition => Def);
4616
4617 Insert_After (N, Decl);
4618 Mark_Rewrite_Insertion (Decl);
4619
4620 else
4621 Error_Pragma_Arg ("no matching type found for pragma%",
4622 Arg2);
4623 end if;
4624 end Process_Import_Predefined_Type;
4625
4626 ---------------------------------
4627 -- Process_Import_Or_Interface --
4628 ---------------------------------
4629
4630 procedure Process_Import_Or_Interface is
4631 C : Convention_Id;
4632 Def_Id : Entity_Id;
4633 Hom_Id : Entity_Id;
4634
4635 begin
4636 Process_Convention (C, Def_Id);
4637 Kill_Size_Check_Code (Def_Id);
4638 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4639
4640 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4641
4642 -- We do not permit Import to apply to a renaming declaration
4643
4644 if Present (Renamed_Object (Def_Id)) then
4645 Error_Pragma_Arg
4646 ("pragma% not allowed for object renaming", Arg2);
4647
4648 -- User initialization is not allowed for imported object, but
4649 -- the object declaration may contain a default initialization,
4650 -- that will be discarded. Note that an explicit initialization
4651 -- only counts if it comes from source, otherwise it is simply
4652 -- the code generator making an implicit initialization explicit.
4653
4654 elsif Present (Expression (Parent (Def_Id)))
4655 and then Comes_From_Source (Expression (Parent (Def_Id)))
4656 then
4657 Error_Msg_Sloc := Sloc (Def_Id);
4658 Error_Pragma_Arg
4659 ("no initialization allowed for declaration of& #",
4660 "\imported entities cannot be initialized (RM B.1(24))",
4661 Arg2);
4662
4663 else
4664 Set_Imported (Def_Id);
4665 Process_Interface_Name (Def_Id, Arg3, Arg4);
4666
4667 -- Note that we do not set Is_Public here. That's because we
4668 -- only want to set it if there is no address clause, and we
4669 -- don't know that yet, so we delay that processing till
4670 -- freeze time.
4671
4672 -- pragma Import completes deferred constants
4673
4674 if Ekind (Def_Id) = E_Constant then
4675 Set_Has_Completion (Def_Id);
4676 end if;
4677
4678 -- It is not possible to import a constant of an unconstrained
4679 -- array type (e.g. string) because there is no simple way to
4680 -- write a meaningful subtype for it.
4681
4682 if Is_Array_Type (Etype (Def_Id))
4683 and then not Is_Constrained (Etype (Def_Id))
4684 then
4685 Error_Msg_NE
4686 ("imported constant& must have a constrained subtype",
4687 N, Def_Id);
4688 end if;
4689 end if;
4690
4691 elsif Is_Subprogram (Def_Id)
4692 or else Is_Generic_Subprogram (Def_Id)
4693 then
4694 -- If the name is overloaded, pragma applies to all of the denoted
4695 -- entities in the same declarative part, unless the pragma comes
4696 -- from an aspect specification.
4697
4698 Hom_Id := Def_Id;
4699 while Present (Hom_Id) loop
4700
4701 Def_Id := Get_Base_Subprogram (Hom_Id);
4702
4703 -- Ignore inherited subprograms because the pragma will apply
4704 -- to the parent operation, which is the one called.
4705
4706 if Is_Overloadable (Def_Id)
4707 and then Present (Alias (Def_Id))
4708 then
4709 null;
4710
4711 -- If it is not a subprogram, it must be in an outer scope and
4712 -- pragma does not apply.
4713
4714 elsif not Is_Subprogram (Def_Id)
4715 and then not Is_Generic_Subprogram (Def_Id)
4716 then
4717 null;
4718
4719 -- The pragma does not apply to primitives of interfaces
4720
4721 elsif Is_Dispatching_Operation (Def_Id)
4722 and then Present (Find_Dispatching_Type (Def_Id))
4723 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4724 then
4725 null;
4726
4727 -- Verify that the homonym is in the same declarative part (not
4728 -- just the same scope). If the pragma comes from an aspect
4729 -- specification we know that it is part of the declaration.
4730
4731 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4732 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4733 and then not From_Aspect_Specification (N)
4734 then
4735 exit;
4736
4737 else
4738 Set_Imported (Def_Id);
4739
4740 -- Reject an Import applied to an abstract subprogram
4741
4742 if Is_Subprogram (Def_Id)
4743 and then Is_Abstract_Subprogram (Def_Id)
4744 then
4745 Error_Msg_Sloc := Sloc (Def_Id);
4746 Error_Msg_NE
4747 ("cannot import abstract subprogram& declared#",
4748 Arg2, Def_Id);
4749 end if;
4750
4751 -- Special processing for Convention_Intrinsic
4752
4753 if C = Convention_Intrinsic then
4754
4755 -- Link_Name argument not allowed for intrinsic
4756
4757 Check_No_Link_Name;
4758
4759 Set_Is_Intrinsic_Subprogram (Def_Id);
4760
4761 -- If no external name is present, then check that this
4762 -- is a valid intrinsic subprogram. If an external name
4763 -- is present, then this is handled by the back end.
4764
4765 if No (Arg3) then
4766 Check_Intrinsic_Subprogram
4767 (Def_Id, Get_Pragma_Arg (Arg2));
4768 end if;
4769 end if;
4770
4771 -- All interfaced procedures need an external symbol created
4772 -- for them since they are always referenced from another
4773 -- object file.
4774
4775 Set_Is_Public (Def_Id);
4776
4777 -- Verify that the subprogram does not have a completion
4778 -- through a renaming declaration. For other completions the
4779 -- pragma appears as a too late representation.
4780
4781 declare
4782 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4783
4784 begin
4785 if Present (Decl)
4786 and then Nkind (Decl) = N_Subprogram_Declaration
4787 and then Present (Corresponding_Body (Decl))
4788 and then Nkind (Unit_Declaration_Node
4789 (Corresponding_Body (Decl))) =
4790 N_Subprogram_Renaming_Declaration
4791 then
4792 Error_Msg_Sloc := Sloc (Def_Id);
4793 Error_Msg_NE
4794 ("cannot import&, renaming already provided for " &
4795 "declaration #", N, Def_Id);
4796 end if;
4797 end;
4798
4799 Set_Has_Completion (Def_Id);
4800 Process_Interface_Name (Def_Id, Arg3, Arg4);
4801 end if;
4802
4803 if Is_Compilation_Unit (Hom_Id) then
4804
4805 -- Its possible homonyms are not affected by the pragma.
4806 -- Such homonyms might be present in the context of other
4807 -- units being compiled.
4808
4809 exit;
4810
4811 elsif From_Aspect_Specification (N) then
4812 exit;
4813
4814 else
4815 Hom_Id := Homonym (Hom_Id);
4816 end if;
4817 end loop;
4818
4819 -- When the convention is Java or CIL, we also allow Import to be
4820 -- given for packages, generic packages, exceptions, record
4821 -- components, and access to subprograms.
4822
4823 elsif (C = Convention_Java or else C = Convention_CIL)
4824 and then
4825 (Is_Package_Or_Generic_Package (Def_Id)
4826 or else Ekind (Def_Id) = E_Exception
4827 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4828 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4829 then
4830 Set_Imported (Def_Id);
4831 Set_Is_Public (Def_Id);
4832 Process_Interface_Name (Def_Id, Arg3, Arg4);
4833
4834 -- Import a CPP class
4835
4836 elsif C = Convention_CPP
4837 and then (Is_Record_Type (Def_Id)
4838 or else Ekind (Def_Id) = E_Incomplete_Type)
4839 then
4840 if Ekind (Def_Id) = E_Incomplete_Type then
4841 if Present (Full_View (Def_Id)) then
4842 Def_Id := Full_View (Def_Id);
4843
4844 else
4845 Error_Msg_N
4846 ("cannot import 'C'P'P type before full declaration seen",
4847 Get_Pragma_Arg (Arg2));
4848
4849 -- Although we have reported the error we decorate it as
4850 -- CPP_Class to avoid reporting spurious errors
4851
4852 Set_Is_CPP_Class (Def_Id);
4853 return;
4854 end if;
4855 end if;
4856
4857 -- Types treated as CPP classes must be declared limited (note:
4858 -- this used to be a warning but there is no real benefit to it
4859 -- since we did effectively intend to treat the type as limited
4860 -- anyway).
4861
4862 if not Is_Limited_Type (Def_Id) then
4863 Error_Msg_N
4864 ("imported 'C'P'P type must be limited",
4865 Get_Pragma_Arg (Arg2));
4866 end if;
4867
4868 if Etype (Def_Id) /= Def_Id
4869 and then not Is_CPP_Class (Root_Type (Def_Id))
4870 then
4871 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
4872 end if;
4873
4874 Set_Is_CPP_Class (Def_Id);
4875
4876 -- Imported CPP types must not have discriminants (because C++
4877 -- classes do not have discriminants).
4878
4879 if Has_Discriminants (Def_Id) then
4880 Error_Msg_N
4881 ("imported 'C'P'P type cannot have discriminants",
4882 First (Discriminant_Specifications
4883 (Declaration_Node (Def_Id))));
4884 end if;
4885
4886 -- Check that components of imported CPP types do not have default
4887 -- expressions. For private types this check is performed when the
4888 -- full view is analyzed (see Process_Full_View).
4889
4890 if not Is_Private_Type (Def_Id) then
4891 Check_CPP_Type_Has_No_Defaults (Def_Id);
4892 end if;
4893
4894 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4895 Check_No_Link_Name;
4896 Check_Arg_Count (3);
4897 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4898
4899 Process_Import_Predefined_Type;
4900
4901 else
4902 Error_Pragma_Arg
4903 ("second argument of pragma% must be object, subprogram "
4904 & "or incomplete type",
4905 Arg2);
4906 end if;
4907
4908 -- If this pragma applies to a compilation unit, then the unit, which
4909 -- is a subprogram, does not require (or allow) a body. We also do
4910 -- not need to elaborate imported procedures.
4911
4912 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4913 declare
4914 Cunit : constant Node_Id := Parent (Parent (N));
4915 begin
4916 Set_Body_Required (Cunit, False);
4917 end;
4918 end if;
4919 end Process_Import_Or_Interface;
4920
4921 --------------------
4922 -- Process_Inline --
4923 --------------------
4924
4925 procedure Process_Inline (Status : Inline_Status) is
4926 Assoc : Node_Id;
4927 Decl : Node_Id;
4928 Subp_Id : Node_Id;
4929 Subp : Entity_Id;
4930 Applies : Boolean;
4931
4932 Effective : Boolean := False;
4933 -- Set True if inline has some effect, i.e. if there is at least one
4934 -- subprogram set as inlined as a result of the use of the pragma.
4935
4936 procedure Make_Inline (Subp : Entity_Id);
4937 -- Subp is the defining unit name of the subprogram declaration. Set
4938 -- the flag, as well as the flag in the corresponding body, if there
4939 -- is one present.
4940
4941 procedure Set_Inline_Flags (Subp : Entity_Id);
4942 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4943 -- Has_Pragma_Inline_Always for the Inline_Always case.
4944
4945 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4946 -- Returns True if it can be determined at this stage that inlining
4947 -- is not possible, for example if the body is available and contains
4948 -- exception handlers, we prevent inlining, since otherwise we can
4949 -- get undefined symbols at link time. This function also emits a
4950 -- warning if front-end inlining is enabled and the pragma appears
4951 -- too late.
4952 --
4953 -- ??? is business with link symbols still valid, or does it relate
4954 -- to front end ZCX which is being phased out ???
4955
4956 ---------------------------
4957 -- Inlining_Not_Possible --
4958 ---------------------------
4959
4960 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4961 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4962 Stats : Node_Id;
4963
4964 begin
4965 if Nkind (Decl) = N_Subprogram_Body then
4966 Stats := Handled_Statement_Sequence (Decl);
4967 return Present (Exception_Handlers (Stats))
4968 or else Present (At_End_Proc (Stats));
4969
4970 elsif Nkind (Decl) = N_Subprogram_Declaration
4971 and then Present (Corresponding_Body (Decl))
4972 then
4973 if Front_End_Inlining
4974 and then Analyzed (Corresponding_Body (Decl))
4975 then
4976 Error_Msg_N ("pragma appears too late, ignored??", N);
4977 return True;
4978
4979 -- If the subprogram is a renaming as body, the body is just a
4980 -- call to the renamed subprogram, and inlining is trivially
4981 -- possible.
4982
4983 elsif
4984 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4985 N_Subprogram_Renaming_Declaration
4986 then
4987 return False;
4988
4989 else
4990 Stats :=
4991 Handled_Statement_Sequence
4992 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4993
4994 return
4995 Present (Exception_Handlers (Stats))
4996 or else Present (At_End_Proc (Stats));
4997 end if;
4998
4999 else
5000 -- If body is not available, assume the best, the check is
5001 -- performed again when compiling enclosing package bodies.
5002
5003 return False;
5004 end if;
5005 end Inlining_Not_Possible;
5006
5007 -----------------
5008 -- Make_Inline --
5009 -----------------
5010
5011 procedure Make_Inline (Subp : Entity_Id) is
5012 Kind : constant Entity_Kind := Ekind (Subp);
5013 Inner_Subp : Entity_Id := Subp;
5014
5015 begin
5016 -- Ignore if bad type, avoid cascaded error
5017
5018 if Etype (Subp) = Any_Type then
5019 Applies := True;
5020 return;
5021
5022 -- Ignore if all inlining is suppressed
5023
5024 elsif Suppress_All_Inlining then
5025 Applies := True;
5026 return;
5027
5028 -- If inlining is not possible, for now do not treat as an error
5029
5030 elsif Status /= Suppressed
5031 and then Inlining_Not_Possible (Subp)
5032 then
5033 Applies := True;
5034 return;
5035
5036 -- Here we have a candidate for inlining, but we must exclude
5037 -- derived operations. Otherwise we would end up trying to inline
5038 -- a phantom declaration, and the result would be to drag in a
5039 -- body which has no direct inlining associated with it. That
5040 -- would not only be inefficient but would also result in the
5041 -- backend doing cross-unit inlining in cases where it was
5042 -- definitely inappropriate to do so.
5043
5044 -- However, a simple Comes_From_Source test is insufficient, since
5045 -- we do want to allow inlining of generic instances which also do
5046 -- not come from source. We also need to recognize specs generated
5047 -- by the front-end for bodies that carry the pragma. Finally,
5048 -- predefined operators do not come from source but are not
5049 -- inlineable either.
5050
5051 elsif Is_Generic_Instance (Subp)
5052 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
5053 then
5054 null;
5055
5056 elsif not Comes_From_Source (Subp)
5057 and then Scope (Subp) /= Standard_Standard
5058 then
5059 Applies := True;
5060 return;
5061 end if;
5062
5063 -- The referenced entity must either be the enclosing entity, or
5064 -- an entity declared within the current open scope.
5065
5066 if Present (Scope (Subp))
5067 and then Scope (Subp) /= Current_Scope
5068 and then Subp /= Current_Scope
5069 then
5070 Error_Pragma_Arg
5071 ("argument of% must be entity in current scope", Assoc);
5072 return;
5073 end if;
5074
5075 -- Processing for procedure, operator or function. If subprogram
5076 -- is aliased (as for an instance) indicate that the renamed
5077 -- entity (if declared in the same unit) is inlined.
5078
5079 if Is_Subprogram (Subp) then
5080 Inner_Subp := Ultimate_Alias (Inner_Subp);
5081
5082 if In_Same_Source_Unit (Subp, Inner_Subp) then
5083 Set_Inline_Flags (Inner_Subp);
5084
5085 Decl := Parent (Parent (Inner_Subp));
5086
5087 if Nkind (Decl) = N_Subprogram_Declaration
5088 and then Present (Corresponding_Body (Decl))
5089 then
5090 Set_Inline_Flags (Corresponding_Body (Decl));
5091
5092 elsif Is_Generic_Instance (Subp) then
5093
5094 -- Indicate that the body needs to be created for
5095 -- inlining subsequent calls. The instantiation node
5096 -- follows the declaration of the wrapper package
5097 -- created for it.
5098
5099 if Scope (Subp) /= Standard_Standard
5100 and then
5101 Need_Subprogram_Instance_Body
5102 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
5103 Subp)
5104 then
5105 null;
5106 end if;
5107
5108 -- Inline is a program unit pragma (RM 10.1.5) and cannot
5109 -- appear in a formal part to apply to a formal subprogram.
5110 -- Do not apply check within an instance or a formal package
5111 -- the test will have been applied to the original generic.
5112
5113 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
5114 and then List_Containing (Decl) = List_Containing (N)
5115 and then not In_Instance
5116 then
5117 Error_Msg_N
5118 ("Inline cannot apply to a formal subprogram", N);
5119
5120 -- If Subp is a renaming, it is the renamed entity that
5121 -- will appear in any call, and be inlined. However, for
5122 -- ASIS uses it is convenient to indicate that the renaming
5123 -- itself is an inlined subprogram, so that some gnatcheck
5124 -- rules can be applied in the absence of expansion.
5125
5126 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
5127 Set_Inline_Flags (Subp);
5128 end if;
5129 end if;
5130
5131 Applies := True;
5132
5133 -- For a generic subprogram set flag as well, for use at the point
5134 -- of instantiation, to determine whether the body should be
5135 -- generated.
5136
5137 elsif Is_Generic_Subprogram (Subp) then
5138 Set_Inline_Flags (Subp);
5139 Applies := True;
5140
5141 -- Literals are by definition inlined
5142
5143 elsif Kind = E_Enumeration_Literal then
5144 null;
5145
5146 -- Anything else is an error
5147
5148 else
5149 Error_Pragma_Arg
5150 ("expect subprogram name for pragma%", Assoc);
5151 end if;
5152 end Make_Inline;
5153
5154 ----------------------
5155 -- Set_Inline_Flags --
5156 ----------------------
5157
5158 procedure Set_Inline_Flags (Subp : Entity_Id) is
5159 begin
5160 -- First set the Has_Pragma_XXX flags and issue the appropriate
5161 -- errors and warnings for suspicious combinations.
5162
5163 if Prag_Id = Pragma_No_Inline then
5164 if Has_Pragma_Inline_Always (Subp) then
5165 Error_Msg_N
5166 ("Inline_Always and No_Inline are mutually exclusive", N);
5167 elsif Has_Pragma_Inline (Subp) then
5168 Error_Msg_NE
5169 ("Inline and No_Inline both specified for& ??",
5170 N, Entity (Subp_Id));
5171 end if;
5172
5173 Set_Has_Pragma_No_Inline (Subp);
5174 else
5175 if Prag_Id = Pragma_Inline_Always then
5176 if Has_Pragma_No_Inline (Subp) then
5177 Error_Msg_N
5178 ("Inline_Always and No_Inline are mutually exclusive",
5179 N);
5180 end if;
5181
5182 Set_Has_Pragma_Inline_Always (Subp);
5183 else
5184 if Has_Pragma_No_Inline (Subp) then
5185 Error_Msg_NE
5186 ("Inline and No_Inline both specified for& ??",
5187 N, Entity (Subp_Id));
5188 end if;
5189 end if;
5190
5191 if not Has_Pragma_Inline (Subp) then
5192 Set_Has_Pragma_Inline (Subp);
5193 Effective := True;
5194 end if;
5195 end if;
5196
5197 -- Then adjust the Is_Inlined flag. It can never be set if the
5198 -- subprogram is subject to pragma No_Inline.
5199
5200 case Status is
5201 when Suppressed =>
5202 Set_Is_Inlined (Subp, False);
5203 when Disabled =>
5204 null;
5205 when Enabled =>
5206 if not Has_Pragma_No_Inline (Subp) then
5207 Set_Is_Inlined (Subp, True);
5208 end if;
5209 end case;
5210 end Set_Inline_Flags;
5211
5212 -- Start of processing for Process_Inline
5213
5214 begin
5215 Check_No_Identifiers;
5216 Check_At_Least_N_Arguments (1);
5217
5218 if Status = Enabled then
5219 Inline_Processing_Required := True;
5220 end if;
5221
5222 Assoc := Arg1;
5223 while Present (Assoc) loop
5224 Subp_Id := Get_Pragma_Arg (Assoc);
5225 Analyze (Subp_Id);
5226 Applies := False;
5227
5228 if Is_Entity_Name (Subp_Id) then
5229 Subp := Entity (Subp_Id);
5230
5231 if Subp = Any_Id then
5232
5233 -- If previous error, avoid cascaded errors
5234
5235 Check_Error_Detected;
5236 Applies := True;
5237 Effective := True;
5238
5239 else
5240 Make_Inline (Subp);
5241
5242 -- For the pragma case, climb homonym chain. This is
5243 -- what implements allowing the pragma in the renaming
5244 -- case, with the result applying to the ancestors, and
5245 -- also allows Inline to apply to all previous homonyms.
5246
5247 if not From_Aspect_Specification (N) then
5248 while Present (Homonym (Subp))
5249 and then Scope (Homonym (Subp)) = Current_Scope
5250 loop
5251 Make_Inline (Homonym (Subp));
5252 Subp := Homonym (Subp);
5253 end loop;
5254 end if;
5255 end if;
5256 end if;
5257
5258 if not Applies then
5259 Error_Pragma_Arg
5260 ("inappropriate argument for pragma%", Assoc);
5261
5262 elsif not Effective
5263 and then Warn_On_Redundant_Constructs
5264 and then not (Status = Suppressed or else Suppress_All_Inlining)
5265 then
5266 if Inlining_Not_Possible (Subp) then
5267 Error_Msg_NE
5268 ("pragma Inline for& is ignored?r?",
5269 N, Entity (Subp_Id));
5270 else
5271 Error_Msg_NE
5272 ("pragma Inline for& is redundant?r?",
5273 N, Entity (Subp_Id));
5274 end if;
5275 end if;
5276
5277 Next (Assoc);
5278 end loop;
5279 end Process_Inline;
5280
5281 ----------------------------
5282 -- Process_Interface_Name --
5283 ----------------------------
5284
5285 procedure Process_Interface_Name
5286 (Subprogram_Def : Entity_Id;
5287 Ext_Arg : Node_Id;
5288 Link_Arg : Node_Id)
5289 is
5290 Ext_Nam : Node_Id;
5291 Link_Nam : Node_Id;
5292 String_Val : String_Id;
5293
5294 procedure Check_Form_Of_Interface_Name
5295 (SN : Node_Id;
5296 Ext_Name_Case : Boolean);
5297 -- SN is a string literal node for an interface name. This routine
5298 -- performs some minimal checks that the name is reasonable. In
5299 -- particular that no spaces or other obviously incorrect characters
5300 -- appear. This is only a warning, since any characters are allowed.
5301 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
5302
5303 ----------------------------------
5304 -- Check_Form_Of_Interface_Name --
5305 ----------------------------------
5306
5307 procedure Check_Form_Of_Interface_Name
5308 (SN : Node_Id;
5309 Ext_Name_Case : Boolean)
5310 is
5311 S : constant String_Id := Strval (Expr_Value_S (SN));
5312 SL : constant Nat := String_Length (S);
5313 C : Char_Code;
5314
5315 begin
5316 if SL = 0 then
5317 Error_Msg_N ("interface name cannot be null string", SN);
5318 end if;
5319
5320 for J in 1 .. SL loop
5321 C := Get_String_Char (S, J);
5322
5323 -- Look for dubious character and issue unconditional warning.
5324 -- Definitely dubious if not in character range.
5325
5326 if not In_Character_Range (C)
5327
5328 -- For all cases except CLI target,
5329 -- commas, spaces and slashes are dubious (in CLI, we use
5330 -- commas and backslashes in external names to specify
5331 -- assembly version and public key, while slashes and spaces
5332 -- can be used in names to mark nested classes and
5333 -- valuetypes).
5334
5335 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5336 and then (Get_Character (C) = ','
5337 or else
5338 Get_Character (C) = '\'))
5339 or else (VM_Target /= CLI_Target
5340 and then (Get_Character (C) = ' '
5341 or else
5342 Get_Character (C) = '/'))
5343 then
5344 Error_Msg
5345 ("??interface name contains illegal character",
5346 Sloc (SN) + Source_Ptr (J));
5347 end if;
5348 end loop;
5349 end Check_Form_Of_Interface_Name;
5350
5351 -- Start of processing for Process_Interface_Name
5352
5353 begin
5354 if No (Link_Arg) then
5355 if No (Ext_Arg) then
5356 if VM_Target = CLI_Target
5357 and then Ekind (Subprogram_Def) = E_Package
5358 and then Nkind (Parent (Subprogram_Def)) =
5359 N_Package_Specification
5360 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5361 then
5362 Set_Interface_Name
5363 (Subprogram_Def,
5364 Interface_Name
5365 (Generic_Parent (Parent (Subprogram_Def))));
5366 end if;
5367
5368 return;
5369
5370 elsif Chars (Ext_Arg) = Name_Link_Name then
5371 Ext_Nam := Empty;
5372 Link_Nam := Expression (Ext_Arg);
5373
5374 else
5375 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5376 Ext_Nam := Expression (Ext_Arg);
5377 Link_Nam := Empty;
5378 end if;
5379
5380 else
5381 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5382 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5383 Ext_Nam := Expression (Ext_Arg);
5384 Link_Nam := Expression (Link_Arg);
5385 end if;
5386
5387 -- Check expressions for external name and link name are static
5388
5389 if Present (Ext_Nam) then
5390 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5391 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5392
5393 -- Verify that external name is not the name of a local entity,
5394 -- which would hide the imported one and could lead to run-time
5395 -- surprises. The problem can only arise for entities declared in
5396 -- a package body (otherwise the external name is fully qualified
5397 -- and will not conflict).
5398
5399 declare
5400 Nam : Name_Id;
5401 E : Entity_Id;
5402 Par : Node_Id;
5403
5404 begin
5405 if Prag_Id = Pragma_Import then
5406 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5407 Nam := Name_Find;
5408 E := Entity_Id (Get_Name_Table_Info (Nam));
5409
5410 if Nam /= Chars (Subprogram_Def)
5411 and then Present (E)
5412 and then not Is_Overloadable (E)
5413 and then Is_Immediately_Visible (E)
5414 and then not Is_Imported (E)
5415 and then Ekind (Scope (E)) = E_Package
5416 then
5417 Par := Parent (E);
5418 while Present (Par) loop
5419 if Nkind (Par) = N_Package_Body then
5420 Error_Msg_Sloc := Sloc (E);
5421 Error_Msg_NE
5422 ("imported entity is hidden by & declared#",
5423 Ext_Arg, E);
5424 exit;
5425 end if;
5426
5427 Par := Parent (Par);
5428 end loop;
5429 end if;
5430 end if;
5431 end;
5432 end if;
5433
5434 if Present (Link_Nam) then
5435 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5436 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5437 end if;
5438
5439 -- If there is no link name, just set the external name
5440
5441 if No (Link_Nam) then
5442 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5443
5444 -- For the Link_Name case, the given literal is preceded by an
5445 -- asterisk, which indicates to GCC that the given name should be
5446 -- taken literally, and in particular that no prepending of
5447 -- underlines should occur, even in systems where this is the
5448 -- normal default.
5449
5450 else
5451 Start_String;
5452
5453 if VM_Target = No_VM then
5454 Store_String_Char (Get_Char_Code ('*'));
5455 end if;
5456
5457 String_Val := Strval (Expr_Value_S (Link_Nam));
5458 Store_String_Chars (String_Val);
5459 Link_Nam :=
5460 Make_String_Literal (Sloc (Link_Nam),
5461 Strval => End_String);
5462 end if;
5463
5464 -- Set the interface name. If the entity is a generic instance, use
5465 -- its alias, which is the callable entity.
5466
5467 if Is_Generic_Instance (Subprogram_Def) then
5468 Set_Encoded_Interface_Name
5469 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5470 else
5471 Set_Encoded_Interface_Name
5472 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5473 end if;
5474
5475 -- We allow duplicated export names in CIL/Java, as they are always
5476 -- enclosed in a namespace that differentiates them, and overloaded
5477 -- entities are supported by the VM.
5478
5479 if Convention (Subprogram_Def) /= Convention_CIL
5480 and then
5481 Convention (Subprogram_Def) /= Convention_Java
5482 then
5483 Check_Duplicated_Export_Name (Link_Nam);
5484 end if;
5485 end Process_Interface_Name;
5486
5487 -----------------------------------------
5488 -- Process_Interrupt_Or_Attach_Handler --
5489 -----------------------------------------
5490
5491 procedure Process_Interrupt_Or_Attach_Handler is
5492 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5493 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5494 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5495
5496 begin
5497 Set_Is_Interrupt_Handler (Handler_Proc);
5498
5499 -- If the pragma is not associated with a handler procedure within a
5500 -- protected type, then it must be for a nonprotected procedure for
5501 -- the AAMP target, in which case we don't associate a representation
5502 -- item with the procedure's scope.
5503
5504 if Ekind (Proc_Scope) = E_Protected_Type then
5505 if Prag_Id = Pragma_Interrupt_Handler
5506 or else
5507 Prag_Id = Pragma_Attach_Handler
5508 then
5509 Record_Rep_Item (Proc_Scope, N);
5510 end if;
5511 end if;
5512 end Process_Interrupt_Or_Attach_Handler;
5513
5514 --------------------------------------------------
5515 -- Process_Restrictions_Or_Restriction_Warnings --
5516 --------------------------------------------------
5517
5518 -- Note: some of the simple identifier cases were handled in par-prag,
5519 -- but it is harmless (and more straightforward) to simply handle all
5520 -- cases here, even if it means we repeat a bit of work in some cases.
5521
5522 procedure Process_Restrictions_Or_Restriction_Warnings
5523 (Warn : Boolean)
5524 is
5525 Arg : Node_Id;
5526 R_Id : Restriction_Id;
5527 Id : Name_Id;
5528 Expr : Node_Id;
5529 Val : Uint;
5530
5531 procedure Check_Unit_Name (N : Node_Id);
5532 -- Checks unit name parameter for No_Dependence. Returns if it has
5533 -- an appropriate form, otherwise raises pragma argument error.
5534
5535 ---------------------
5536 -- Check_Unit_Name --
5537 ---------------------
5538
5539 procedure Check_Unit_Name (N : Node_Id) is
5540 begin
5541 if Nkind (N) = N_Selected_Component then
5542 Check_Unit_Name (Prefix (N));
5543 Check_Unit_Name (Selector_Name (N));
5544
5545 elsif Nkind (N) = N_Identifier then
5546 return;
5547
5548 else
5549 Error_Pragma_Arg
5550 ("wrong form for unit name for No_Dependence", N);
5551 end if;
5552 end Check_Unit_Name;
5553
5554 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5555
5556 begin
5557 -- Ignore all Restrictions pragma in CodePeer mode
5558
5559 if CodePeer_Mode then
5560 return;
5561 end if;
5562
5563 Check_Ada_83_Warning;
5564 Check_At_Least_N_Arguments (1);
5565 Check_Valid_Configuration_Pragma;
5566
5567 Arg := Arg1;
5568 while Present (Arg) loop
5569 Id := Chars (Arg);
5570 Expr := Get_Pragma_Arg (Arg);
5571
5572 -- Case of no restriction identifier present
5573
5574 if Id = No_Name then
5575 if Nkind (Expr) /= N_Identifier then
5576 Error_Pragma_Arg
5577 ("invalid form for restriction", Arg);
5578 end if;
5579
5580 R_Id :=
5581 Get_Restriction_Id
5582 (Process_Restriction_Synonyms (Expr));
5583
5584 if R_Id not in All_Boolean_Restrictions then
5585 Error_Msg_Name_1 := Pname;
5586 Error_Msg_N
5587 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5588
5589 -- Check for possible misspelling
5590
5591 for J in Restriction_Id loop
5592 declare
5593 Rnm : constant String := Restriction_Id'Image (J);
5594
5595 begin
5596 Name_Buffer (1 .. Rnm'Length) := Rnm;
5597 Name_Len := Rnm'Length;
5598 Set_Casing (All_Lower_Case);
5599
5600 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5601 Set_Casing
5602 (Identifier_Casing (Current_Source_File));
5603 Error_Msg_String (1 .. Rnm'Length) :=
5604 Name_Buffer (1 .. Name_Len);
5605 Error_Msg_Strlen := Rnm'Length;
5606 Error_Msg_N -- CODEFIX
5607 ("\possible misspelling of ""~""",
5608 Get_Pragma_Arg (Arg));
5609 exit;
5610 end if;
5611 end;
5612 end loop;
5613
5614 raise Pragma_Exit;
5615 end if;
5616
5617 if Implementation_Restriction (R_Id) then
5618 Check_Restriction (No_Implementation_Restrictions, Arg);
5619 end if;
5620
5621 -- Special processing for No_Elaboration_Code restriction
5622
5623 if R_Id = No_Elaboration_Code then
5624
5625 -- Restriction is only recognized within a configuration
5626 -- pragma file, or within a unit of the main extended
5627 -- program. Note: the test for Main_Unit is needed to
5628 -- properly include the case of configuration pragma files.
5629
5630 if not (Current_Sem_Unit = Main_Unit
5631 or else In_Extended_Main_Source_Unit (N))
5632 then
5633 return;
5634
5635 -- Don't allow in a subunit unless already specified in
5636 -- body or spec.
5637
5638 elsif Nkind (Parent (N)) = N_Compilation_Unit
5639 and then Nkind (Unit (Parent (N))) = N_Subunit
5640 and then not Restriction_Active (No_Elaboration_Code)
5641 then
5642 Error_Msg_N
5643 ("invalid specification of ""No_Elaboration_Code""",
5644 N);
5645 Error_Msg_N
5646 ("\restriction cannot be specified in a subunit", N);
5647 Error_Msg_N
5648 ("\unless also specified in body or spec", N);
5649 return;
5650
5651 -- If we have a No_Elaboration_Code pragma that we
5652 -- accept, then it needs to be added to the configuration
5653 -- restrcition set so that we get proper application to
5654 -- other units in the main extended source as required.
5655
5656 else
5657 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
5658 end if;
5659 end if;
5660
5661 -- If this is a warning, then set the warning unless we already
5662 -- have a real restriction active (we never want a warning to
5663 -- override a real restriction).
5664
5665 if Warn then
5666 if not Restriction_Active (R_Id) then
5667 Set_Restriction (R_Id, N);
5668 Restriction_Warnings (R_Id) := True;
5669 end if;
5670
5671 -- If real restriction case, then set it and make sure that the
5672 -- restriction warning flag is off, since a real restriction
5673 -- always overrides a warning.
5674
5675 else
5676 Set_Restriction (R_Id, N);
5677 Restriction_Warnings (R_Id) := False;
5678 end if;
5679
5680 -- Check for obsolescent restrictions in Ada 2005 mode
5681
5682 if not Warn
5683 and then Ada_Version >= Ada_2005
5684 and then (R_Id = No_Asynchronous_Control
5685 or else
5686 R_Id = No_Unchecked_Deallocation
5687 or else
5688 R_Id = No_Unchecked_Conversion)
5689 then
5690 Check_Restriction (No_Obsolescent_Features, N);
5691 end if;
5692
5693 -- A very special case that must be processed here: pragma
5694 -- Restrictions (No_Exceptions) turns off all run-time
5695 -- checking. This is a bit dubious in terms of the formal
5696 -- language definition, but it is what is intended by RM
5697 -- H.4(12). Restriction_Warnings never affects generated code
5698 -- so this is done only in the real restriction case.
5699
5700 -- Atomic_Synchronization is not a real check, so it is not
5701 -- affected by this processing).
5702
5703 if R_Id = No_Exceptions and then not Warn then
5704 for J in Scope_Suppress.Suppress'Range loop
5705 if J /= Atomic_Synchronization then
5706 Scope_Suppress.Suppress (J) := True;
5707 end if;
5708 end loop;
5709 end if;
5710
5711 -- Case of No_Dependence => unit-name. Note that the parser
5712 -- already made the necessary entry in the No_Dependence table.
5713
5714 elsif Id = Name_No_Dependence then
5715 Check_Unit_Name (Expr);
5716
5717 -- Case of No_Specification_Of_Aspect => Identifier.
5718
5719 elsif Id = Name_No_Specification_Of_Aspect then
5720 declare
5721 A_Id : Aspect_Id;
5722
5723 begin
5724 if Nkind (Expr) /= N_Identifier then
5725 A_Id := No_Aspect;
5726 else
5727 A_Id := Get_Aspect_Id (Chars (Expr));
5728 end if;
5729
5730 if A_Id = No_Aspect then
5731 Error_Pragma_Arg ("invalid restriction name", Arg);
5732 else
5733 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5734 end if;
5735 end;
5736
5737 -- All other cases of restriction identifier present
5738
5739 else
5740 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5741 Analyze_And_Resolve (Expr, Any_Integer);
5742
5743 if R_Id not in All_Parameter_Restrictions then
5744 Error_Pragma_Arg
5745 ("invalid restriction parameter identifier", Arg);
5746
5747 elsif not Is_OK_Static_Expression (Expr) then
5748 Flag_Non_Static_Expr
5749 ("value must be static expression!", Expr);
5750 raise Pragma_Exit;
5751
5752 elsif not Is_Integer_Type (Etype (Expr))
5753 or else Expr_Value (Expr) < 0
5754 then
5755 Error_Pragma_Arg
5756 ("value must be non-negative integer", Arg);
5757 end if;
5758
5759 -- Restriction pragma is active
5760
5761 Val := Expr_Value (Expr);
5762
5763 if not UI_Is_In_Int_Range (Val) then
5764 Error_Pragma_Arg
5765 ("pragma ignored, value too large??", Arg);
5766 end if;
5767
5768 -- Warning case. If the real restriction is active, then we
5769 -- ignore the request, since warning never overrides a real
5770 -- restriction. Otherwise we set the proper warning. Note that
5771 -- this circuit sets the warning again if it is already set,
5772 -- which is what we want, since the constant may have changed.
5773
5774 if Warn then
5775 if not Restriction_Active (R_Id) then
5776 Set_Restriction
5777 (R_Id, N, Integer (UI_To_Int (Val)));
5778 Restriction_Warnings (R_Id) := True;
5779 end if;
5780
5781 -- Real restriction case, set restriction and make sure warning
5782 -- flag is off since real restriction always overrides warning.
5783
5784 else
5785 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5786 Restriction_Warnings (R_Id) := False;
5787 end if;
5788 end if;
5789
5790 Next (Arg);
5791 end loop;
5792 end Process_Restrictions_Or_Restriction_Warnings;
5793
5794 ---------------------------------
5795 -- Process_Suppress_Unsuppress --
5796 ---------------------------------
5797
5798 -- Note: this procedure makes entries in the check suppress data
5799 -- structures managed by Sem. See spec of package Sem for full
5800 -- details on how we handle recording of check suppression.
5801
5802 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5803 C : Check_Id;
5804 E_Id : Node_Id;
5805 E : Entity_Id;
5806
5807 In_Package_Spec : constant Boolean :=
5808 Is_Package_Or_Generic_Package (Current_Scope)
5809 and then not In_Package_Body (Current_Scope);
5810
5811 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5812 -- Used to suppress a single check on the given entity
5813
5814 --------------------------------
5815 -- Suppress_Unsuppress_Echeck --
5816 --------------------------------
5817
5818 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5819 begin
5820 -- Check for error of trying to set atomic synchronization for
5821 -- a non-atomic variable.
5822
5823 if C = Atomic_Synchronization
5824 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5825 then
5826 Error_Msg_N
5827 ("pragma & requires atomic type or variable",
5828 Pragma_Identifier (Original_Node (N)));
5829 end if;
5830
5831 Set_Checks_May_Be_Suppressed (E);
5832
5833 if In_Package_Spec then
5834 Push_Global_Suppress_Stack_Entry
5835 (Entity => E,
5836 Check => C,
5837 Suppress => Suppress_Case);
5838 else
5839 Push_Local_Suppress_Stack_Entry
5840 (Entity => E,
5841 Check => C,
5842 Suppress => Suppress_Case);
5843 end if;
5844
5845 -- If this is a first subtype, and the base type is distinct,
5846 -- then also set the suppress flags on the base type.
5847
5848 if Is_First_Subtype (E) and then Etype (E) /= E then
5849 Suppress_Unsuppress_Echeck (Etype (E), C);
5850 end if;
5851 end Suppress_Unsuppress_Echeck;
5852
5853 -- Start of processing for Process_Suppress_Unsuppress
5854
5855 begin
5856 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5857 -- user code: we want to generate checks for analysis purposes, as
5858 -- set respectively by -gnatC and -gnatd.F
5859
5860 if (CodePeer_Mode or Alfa_Mode) and then Comes_From_Source (N) then
5861 return;
5862 end if;
5863
5864 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5865 -- declarative part or a package spec (RM 11.5(5)).
5866
5867 if not Is_Configuration_Pragma then
5868 Check_Is_In_Decl_Part_Or_Package_Spec;
5869 end if;
5870
5871 Check_At_Least_N_Arguments (1);
5872 Check_At_Most_N_Arguments (2);
5873 Check_No_Identifier (Arg1);
5874 Check_Arg_Is_Identifier (Arg1);
5875
5876 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5877
5878 if C = No_Check_Id then
5879 Error_Pragma_Arg
5880 ("argument of pragma% is not valid check name", Arg1);
5881 end if;
5882
5883 if Arg_Count = 1 then
5884
5885 -- Make an entry in the local scope suppress table. This is the
5886 -- table that directly shows the current value of the scope
5887 -- suppress check for any check id value.
5888
5889 if C = All_Checks then
5890
5891 -- For All_Checks, we set all specific predefined checks with
5892 -- the exception of Elaboration_Check, which is handled
5893 -- specially because of not wanting All_Checks to have the
5894 -- effect of deactivating static elaboration order processing.
5895 -- Atomic_Synchronization is also not affected, since this is
5896 -- not a real check.
5897
5898 for J in Scope_Suppress.Suppress'Range loop
5899 if J /= Elaboration_Check
5900 and then
5901 J /= Atomic_Synchronization
5902 then
5903 Scope_Suppress.Suppress (J) := Suppress_Case;
5904 end if;
5905 end loop;
5906
5907 -- If not All_Checks, and predefined check, then set appropriate
5908 -- scope entry. Note that we will set Elaboration_Check if this
5909 -- is explicitly specified. Atomic_Synchronization is allowed
5910 -- only if internally generated and entity is atomic.
5911
5912 elsif C in Predefined_Check_Id
5913 and then (not Comes_From_Source (N)
5914 or else C /= Atomic_Synchronization)
5915 then
5916 Scope_Suppress.Suppress (C) := Suppress_Case;
5917 end if;
5918
5919 -- Also make an entry in the Local_Entity_Suppress table
5920
5921 Push_Local_Suppress_Stack_Entry
5922 (Entity => Empty,
5923 Check => C,
5924 Suppress => Suppress_Case);
5925
5926 -- Case of two arguments present, where the check is suppressed for
5927 -- a specified entity (given as the second argument of the pragma)
5928
5929 else
5930 -- This is obsolescent in Ada 2005 mode
5931
5932 if Ada_Version >= Ada_2005 then
5933 Check_Restriction (No_Obsolescent_Features, Arg2);
5934 end if;
5935
5936 Check_Optional_Identifier (Arg2, Name_On);
5937 E_Id := Get_Pragma_Arg (Arg2);
5938 Analyze (E_Id);
5939
5940 if not Is_Entity_Name (E_Id) then
5941 Error_Pragma_Arg
5942 ("second argument of pragma% must be entity name", Arg2);
5943 end if;
5944
5945 E := Entity (E_Id);
5946
5947 if E = Any_Id then
5948 return;
5949 end if;
5950
5951 -- Enforce RM 11.5(7) which requires that for a pragma that
5952 -- appears within a package spec, the named entity must be
5953 -- within the package spec. We allow the package name itself
5954 -- to be mentioned since that makes sense, although it is not
5955 -- strictly allowed by 11.5(7).
5956
5957 if In_Package_Spec
5958 and then E /= Current_Scope
5959 and then Scope (E) /= Current_Scope
5960 then
5961 Error_Pragma_Arg
5962 ("entity in pragma% is not in package spec (RM 11.5(7))",
5963 Arg2);
5964 end if;
5965
5966 -- Loop through homonyms. As noted below, in the case of a package
5967 -- spec, only homonyms within the package spec are considered.
5968
5969 loop
5970 Suppress_Unsuppress_Echeck (E, C);
5971
5972 if Is_Generic_Instance (E)
5973 and then Is_Subprogram (E)
5974 and then Present (Alias (E))
5975 then
5976 Suppress_Unsuppress_Echeck (Alias (E), C);
5977 end if;
5978
5979 -- Move to next homonym if not aspect spec case
5980
5981 exit when From_Aspect_Specification (N);
5982 E := Homonym (E);
5983 exit when No (E);
5984
5985 -- If we are within a package specification, the pragma only
5986 -- applies to homonyms in the same scope.
5987
5988 exit when In_Package_Spec
5989 and then Scope (E) /= Current_Scope;
5990 end loop;
5991 end if;
5992 end Process_Suppress_Unsuppress;
5993
5994 ------------------
5995 -- Set_Exported --
5996 ------------------
5997
5998 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5999 begin
6000 if Is_Imported (E) then
6001 Error_Pragma_Arg
6002 ("cannot export entity& that was previously imported", Arg);
6003
6004 elsif Present (Address_Clause (E))
6005 and then not Relaxed_RM_Semantics
6006 then
6007 Error_Pragma_Arg
6008 ("cannot export entity& that has an address clause", Arg);
6009 end if;
6010
6011 Set_Is_Exported (E);
6012
6013 -- Generate a reference for entity explicitly, because the
6014 -- identifier may be overloaded and name resolution will not
6015 -- generate one.
6016
6017 Generate_Reference (E, Arg);
6018
6019 -- Deal with exporting non-library level entity
6020
6021 if not Is_Library_Level_Entity (E) then
6022
6023 -- Not allowed at all for subprograms
6024
6025 if Is_Subprogram (E) then
6026 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
6027
6028 -- Otherwise set public and statically allocated
6029
6030 else
6031 Set_Is_Public (E);
6032 Set_Is_Statically_Allocated (E);
6033
6034 -- Warn if the corresponding W flag is set and the pragma comes
6035 -- from source. The latter may not be true e.g. on VMS where we
6036 -- expand export pragmas for exception codes associated with
6037 -- imported or exported exceptions. We do not want to generate
6038 -- a warning for something that the user did not write.
6039
6040 if Warn_On_Export_Import
6041 and then Comes_From_Source (Arg)
6042 then
6043 Error_Msg_NE
6044 ("?x?& has been made static as a result of Export",
6045 Arg, E);
6046 Error_Msg_N
6047 ("\?x?this usage is non-standard and non-portable",
6048 Arg);
6049 end if;
6050 end if;
6051 end if;
6052
6053 if Warn_On_Export_Import and then Is_Type (E) then
6054 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
6055 end if;
6056
6057 if Warn_On_Export_Import and Inside_A_Generic then
6058 Error_Msg_NE
6059 ("all instances of& will have the same external name?x?",
6060 Arg, E);
6061 end if;
6062 end Set_Exported;
6063
6064 ----------------------------------------------
6065 -- Set_Extended_Import_Export_External_Name --
6066 ----------------------------------------------
6067
6068 procedure Set_Extended_Import_Export_External_Name
6069 (Internal_Ent : Entity_Id;
6070 Arg_External : Node_Id)
6071 is
6072 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
6073 New_Name : Node_Id;
6074
6075 begin
6076 if No (Arg_External) then
6077 return;
6078 end if;
6079
6080 Check_Arg_Is_External_Name (Arg_External);
6081
6082 if Nkind (Arg_External) = N_String_Literal then
6083 if String_Length (Strval (Arg_External)) = 0 then
6084 return;
6085 else
6086 New_Name := Adjust_External_Name_Case (Arg_External);
6087 end if;
6088
6089 elsif Nkind (Arg_External) = N_Identifier then
6090 New_Name := Get_Default_External_Name (Arg_External);
6091
6092 -- Check_Arg_Is_External_Name should let through only identifiers and
6093 -- string literals or static string expressions (which are folded to
6094 -- string literals).
6095
6096 else
6097 raise Program_Error;
6098 end if;
6099
6100 -- If we already have an external name set (by a prior normal Import
6101 -- or Export pragma), then the external names must match
6102
6103 if Present (Interface_Name (Internal_Ent)) then
6104 Check_Matching_Internal_Names : declare
6105 S1 : constant String_Id := Strval (Old_Name);
6106 S2 : constant String_Id := Strval (New_Name);
6107
6108 procedure Mismatch;
6109 pragma No_Return (Mismatch);
6110 -- Called if names do not match
6111
6112 --------------
6113 -- Mismatch --
6114 --------------
6115
6116 procedure Mismatch is
6117 begin
6118 Error_Msg_Sloc := Sloc (Old_Name);
6119 Error_Pragma_Arg
6120 ("external name does not match that given #",
6121 Arg_External);
6122 end Mismatch;
6123
6124 -- Start of processing for Check_Matching_Internal_Names
6125
6126 begin
6127 if String_Length (S1) /= String_Length (S2) then
6128 Mismatch;
6129
6130 else
6131 for J in 1 .. String_Length (S1) loop
6132 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
6133 Mismatch;
6134 end if;
6135 end loop;
6136 end if;
6137 end Check_Matching_Internal_Names;
6138
6139 -- Otherwise set the given name
6140
6141 else
6142 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
6143 Check_Duplicated_Export_Name (New_Name);
6144 end if;
6145 end Set_Extended_Import_Export_External_Name;
6146
6147 ------------------
6148 -- Set_Imported --
6149 ------------------
6150
6151 procedure Set_Imported (E : Entity_Id) is
6152 begin
6153 -- Error message if already imported or exported
6154
6155 if Is_Exported (E) or else Is_Imported (E) then
6156
6157 -- Error if being set Exported twice
6158
6159 if Is_Exported (E) then
6160 Error_Msg_NE ("entity& was previously exported", N, E);
6161
6162 -- OK if Import/Interface case
6163
6164 elsif Import_Interface_Present (N) then
6165 goto OK;
6166
6167 -- Error if being set Imported twice
6168
6169 else
6170 Error_Msg_NE ("entity& was previously imported", N, E);
6171 end if;
6172
6173 Error_Msg_Name_1 := Pname;
6174 Error_Msg_N
6175 ("\(pragma% applies to all previous entities)", N);
6176
6177 Error_Msg_Sloc := Sloc (E);
6178 Error_Msg_NE ("\import not allowed for& declared#", N, E);
6179
6180 -- Here if not previously imported or exported, OK to import
6181
6182 else
6183 Set_Is_Imported (E);
6184
6185 -- If the entity is an object that is not at the library level,
6186 -- then it is statically allocated. We do not worry about objects
6187 -- with address clauses in this context since they are not really
6188 -- imported in the linker sense.
6189
6190 if Is_Object (E)
6191 and then not Is_Library_Level_Entity (E)
6192 and then No (Address_Clause (E))
6193 then
6194 Set_Is_Statically_Allocated (E);
6195 end if;
6196 end if;
6197
6198 <<OK>> null;
6199 end Set_Imported;
6200
6201 -------------------------
6202 -- Set_Mechanism_Value --
6203 -------------------------
6204
6205 -- Note: the mechanism name has not been analyzed (and cannot indeed be
6206 -- analyzed, since it is semantic nonsense), so we get it in the exact
6207 -- form created by the parser.
6208
6209 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
6210 Class : Node_Id;
6211 Param : Node_Id;
6212 Mech_Name_Id : Name_Id;
6213
6214 procedure Bad_Class;
6215 pragma No_Return (Bad_Class);
6216 -- Signal bad descriptor class name
6217
6218 procedure Bad_Mechanism;
6219 pragma No_Return (Bad_Mechanism);
6220 -- Signal bad mechanism name
6221
6222 ---------------
6223 -- Bad_Class --
6224 ---------------
6225
6226 procedure Bad_Class is
6227 begin
6228 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
6229 end Bad_Class;
6230
6231 -------------------------
6232 -- Bad_Mechanism_Value --
6233 -------------------------
6234
6235 procedure Bad_Mechanism is
6236 begin
6237 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
6238 end Bad_Mechanism;
6239
6240 -- Start of processing for Set_Mechanism_Value
6241
6242 begin
6243 if Mechanism (Ent) /= Default_Mechanism then
6244 Error_Msg_NE
6245 ("mechanism for & has already been set", Mech_Name, Ent);
6246 end if;
6247
6248 -- MECHANISM_NAME ::= value | reference | descriptor |
6249 -- short_descriptor
6250
6251 if Nkind (Mech_Name) = N_Identifier then
6252 if Chars (Mech_Name) = Name_Value then
6253 Set_Mechanism (Ent, By_Copy);
6254 return;
6255
6256 elsif Chars (Mech_Name) = Name_Reference then
6257 Set_Mechanism (Ent, By_Reference);
6258 return;
6259
6260 elsif Chars (Mech_Name) = Name_Descriptor then
6261 Check_VMS (Mech_Name);
6262
6263 -- Descriptor => Short_Descriptor if pragma was given
6264
6265 if Short_Descriptors then
6266 Set_Mechanism (Ent, By_Short_Descriptor);
6267 else
6268 Set_Mechanism (Ent, By_Descriptor);
6269 end if;
6270
6271 return;
6272
6273 elsif Chars (Mech_Name) = Name_Short_Descriptor then
6274 Check_VMS (Mech_Name);
6275 Set_Mechanism (Ent, By_Short_Descriptor);
6276 return;
6277
6278 elsif Chars (Mech_Name) = Name_Copy then
6279 Error_Pragma_Arg
6280 ("bad mechanism name, Value assumed", Mech_Name);
6281
6282 else
6283 Bad_Mechanism;
6284 end if;
6285
6286 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
6287 -- short_descriptor (CLASS_NAME)
6288 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6289
6290 -- Note: this form is parsed as an indexed component
6291
6292 elsif Nkind (Mech_Name) = N_Indexed_Component then
6293 Class := First (Expressions (Mech_Name));
6294
6295 if Nkind (Prefix (Mech_Name)) /= N_Identifier
6296 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
6297 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
6298 or else Present (Next (Class))
6299 then
6300 Bad_Mechanism;
6301 else
6302 Mech_Name_Id := Chars (Prefix (Mech_Name));
6303
6304 -- Change Descriptor => Short_Descriptor if pragma was given
6305
6306 if Mech_Name_Id = Name_Descriptor
6307 and then Short_Descriptors
6308 then
6309 Mech_Name_Id := Name_Short_Descriptor;
6310 end if;
6311 end if;
6312
6313 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
6314 -- short_descriptor (Class => CLASS_NAME)
6315 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6316
6317 -- Note: this form is parsed as a function call
6318
6319 elsif Nkind (Mech_Name) = N_Function_Call then
6320 Param := First (Parameter_Associations (Mech_Name));
6321
6322 if Nkind (Name (Mech_Name)) /= N_Identifier
6323 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6324 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6325 or else Present (Next (Param))
6326 or else No (Selector_Name (Param))
6327 or else Chars (Selector_Name (Param)) /= Name_Class
6328 then
6329 Bad_Mechanism;
6330 else
6331 Class := Explicit_Actual_Parameter (Param);
6332 Mech_Name_Id := Chars (Name (Mech_Name));
6333 end if;
6334
6335 else
6336 Bad_Mechanism;
6337 end if;
6338
6339 -- Fall through here with Class set to descriptor class name
6340
6341 Check_VMS (Mech_Name);
6342
6343 if Nkind (Class) /= N_Identifier then
6344 Bad_Class;
6345
6346 elsif Mech_Name_Id = Name_Descriptor
6347 and then Chars (Class) = Name_UBS
6348 then
6349 Set_Mechanism (Ent, By_Descriptor_UBS);
6350
6351 elsif Mech_Name_Id = Name_Descriptor
6352 and then Chars (Class) = Name_UBSB
6353 then
6354 Set_Mechanism (Ent, By_Descriptor_UBSB);
6355
6356 elsif Mech_Name_Id = Name_Descriptor
6357 and then Chars (Class) = Name_UBA
6358 then
6359 Set_Mechanism (Ent, By_Descriptor_UBA);
6360
6361 elsif Mech_Name_Id = Name_Descriptor
6362 and then Chars (Class) = Name_S
6363 then
6364 Set_Mechanism (Ent, By_Descriptor_S);
6365
6366 elsif Mech_Name_Id = Name_Descriptor
6367 and then Chars (Class) = Name_SB
6368 then
6369 Set_Mechanism (Ent, By_Descriptor_SB);
6370
6371 elsif Mech_Name_Id = Name_Descriptor
6372 and then Chars (Class) = Name_A
6373 then
6374 Set_Mechanism (Ent, By_Descriptor_A);
6375
6376 elsif Mech_Name_Id = Name_Descriptor
6377 and then Chars (Class) = Name_NCA
6378 then
6379 Set_Mechanism (Ent, By_Descriptor_NCA);
6380
6381 elsif Mech_Name_Id = Name_Short_Descriptor
6382 and then Chars (Class) = Name_UBS
6383 then
6384 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6385
6386 elsif Mech_Name_Id = Name_Short_Descriptor
6387 and then Chars (Class) = Name_UBSB
6388 then
6389 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6390
6391 elsif Mech_Name_Id = Name_Short_Descriptor
6392 and then Chars (Class) = Name_UBA
6393 then
6394 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6395
6396 elsif Mech_Name_Id = Name_Short_Descriptor
6397 and then Chars (Class) = Name_S
6398 then
6399 Set_Mechanism (Ent, By_Short_Descriptor_S);
6400
6401 elsif Mech_Name_Id = Name_Short_Descriptor
6402 and then Chars (Class) = Name_SB
6403 then
6404 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6405
6406 elsif Mech_Name_Id = Name_Short_Descriptor
6407 and then Chars (Class) = Name_A
6408 then
6409 Set_Mechanism (Ent, By_Short_Descriptor_A);
6410
6411 elsif Mech_Name_Id = Name_Short_Descriptor
6412 and then Chars (Class) = Name_NCA
6413 then
6414 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6415
6416 else
6417 Bad_Class;
6418 end if;
6419 end Set_Mechanism_Value;
6420
6421 --------------------------
6422 -- Set_Rational_Profile --
6423 --------------------------
6424
6425 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
6426 -- and extension to the semantics of renaming declarations.
6427
6428 procedure Set_Rational_Profile is
6429 begin
6430 Implicit_Packing := True;
6431 Overriding_Renamings := True;
6432 Use_VADS_Size := True;
6433 end Set_Rational_Profile;
6434
6435 ---------------------------
6436 -- Set_Ravenscar_Profile --
6437 ---------------------------
6438
6439 -- The tasks to be done here are
6440
6441 -- Set required policies
6442
6443 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6444 -- pragma Locking_Policy (Ceiling_Locking)
6445
6446 -- Set Detect_Blocking mode
6447
6448 -- Set required restrictions (see System.Rident for detailed list)
6449
6450 -- Set the No_Dependence rules
6451 -- No_Dependence => Ada.Asynchronous_Task_Control
6452 -- No_Dependence => Ada.Calendar
6453 -- No_Dependence => Ada.Execution_Time.Group_Budget
6454 -- No_Dependence => Ada.Execution_Time.Timers
6455 -- No_Dependence => Ada.Task_Attributes
6456 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6457
6458 procedure Set_Ravenscar_Profile (N : Node_Id) is
6459 Prefix_Entity : Entity_Id;
6460 Selector_Entity : Entity_Id;
6461 Prefix_Node : Node_Id;
6462 Node : Node_Id;
6463
6464 begin
6465 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6466
6467 if Task_Dispatching_Policy /= ' '
6468 and then Task_Dispatching_Policy /= 'F'
6469 then
6470 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6471 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6472
6473 -- Set the FIFO_Within_Priorities policy, but always preserve
6474 -- System_Location since we like the error message with the run time
6475 -- name.
6476
6477 else
6478 Task_Dispatching_Policy := 'F';
6479
6480 if Task_Dispatching_Policy_Sloc /= System_Location then
6481 Task_Dispatching_Policy_Sloc := Loc;
6482 end if;
6483 end if;
6484
6485 -- pragma Locking_Policy (Ceiling_Locking)
6486
6487 if Locking_Policy /= ' '
6488 and then Locking_Policy /= 'C'
6489 then
6490 Error_Msg_Sloc := Locking_Policy_Sloc;
6491 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6492
6493 -- Set the Ceiling_Locking policy, but preserve System_Location since
6494 -- we like the error message with the run time name.
6495
6496 else
6497 Locking_Policy := 'C';
6498
6499 if Locking_Policy_Sloc /= System_Location then
6500 Locking_Policy_Sloc := Loc;
6501 end if;
6502 end if;
6503
6504 -- pragma Detect_Blocking
6505
6506 Detect_Blocking := True;
6507
6508 -- Set the corresponding restrictions
6509
6510 Set_Profile_Restrictions
6511 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6512
6513 -- Set the No_Dependence restrictions
6514
6515 -- The following No_Dependence restrictions:
6516 -- No_Dependence => Ada.Asynchronous_Task_Control
6517 -- No_Dependence => Ada.Calendar
6518 -- No_Dependence => Ada.Task_Attributes
6519 -- are already set by previous call to Set_Profile_Restrictions.
6520
6521 -- Set the following restrictions which were added to Ada 2005:
6522 -- No_Dependence => Ada.Execution_Time.Group_Budget
6523 -- No_Dependence => Ada.Execution_Time.Timers
6524
6525 if Ada_Version >= Ada_2005 then
6526 Name_Buffer (1 .. 3) := "ada";
6527 Name_Len := 3;
6528
6529 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6530
6531 Name_Buffer (1 .. 14) := "execution_time";
6532 Name_Len := 14;
6533
6534 Selector_Entity := Make_Identifier (Loc, Name_Find);
6535
6536 Prefix_Node :=
6537 Make_Selected_Component
6538 (Sloc => Loc,
6539 Prefix => Prefix_Entity,
6540 Selector_Name => Selector_Entity);
6541
6542 Name_Buffer (1 .. 13) := "group_budgets";
6543 Name_Len := 13;
6544
6545 Selector_Entity := Make_Identifier (Loc, Name_Find);
6546
6547 Node :=
6548 Make_Selected_Component
6549 (Sloc => Loc,
6550 Prefix => Prefix_Node,
6551 Selector_Name => Selector_Entity);
6552
6553 Set_Restriction_No_Dependence
6554 (Unit => Node,
6555 Warn => Treat_Restrictions_As_Warnings,
6556 Profile => Ravenscar);
6557
6558 Name_Buffer (1 .. 6) := "timers";
6559 Name_Len := 6;
6560
6561 Selector_Entity := Make_Identifier (Loc, Name_Find);
6562
6563 Node :=
6564 Make_Selected_Component
6565 (Sloc => Loc,
6566 Prefix => Prefix_Node,
6567 Selector_Name => Selector_Entity);
6568
6569 Set_Restriction_No_Dependence
6570 (Unit => Node,
6571 Warn => Treat_Restrictions_As_Warnings,
6572 Profile => Ravenscar);
6573 end if;
6574
6575 -- Set the following restrictions which was added to Ada 2012 (see
6576 -- AI-0171):
6577 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6578
6579 if Ada_Version >= Ada_2012 then
6580 Name_Buffer (1 .. 6) := "system";
6581 Name_Len := 6;
6582
6583 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6584
6585 Name_Buffer (1 .. 15) := "multiprocessors";
6586 Name_Len := 15;
6587
6588 Selector_Entity := Make_Identifier (Loc, Name_Find);
6589
6590 Prefix_Node :=
6591 Make_Selected_Component
6592 (Sloc => Loc,
6593 Prefix => Prefix_Entity,
6594 Selector_Name => Selector_Entity);
6595
6596 Name_Buffer (1 .. 19) := "dispatching_domains";
6597 Name_Len := 19;
6598
6599 Selector_Entity := Make_Identifier (Loc, Name_Find);
6600
6601 Node :=
6602 Make_Selected_Component
6603 (Sloc => Loc,
6604 Prefix => Prefix_Node,
6605 Selector_Name => Selector_Entity);
6606
6607 Set_Restriction_No_Dependence
6608 (Unit => Node,
6609 Warn => Treat_Restrictions_As_Warnings,
6610 Profile => Ravenscar);
6611 end if;
6612 end Set_Ravenscar_Profile;
6613
6614 ----------------
6615 -- S14_Pragma --
6616 ----------------
6617
6618 procedure S14_Pragma is
6619 begin
6620 if not Formal_Extensions then
6621 Error_Pragma ("pragma% requires the use of debug switch -gnatd.V");
6622 end if;
6623 end S14_Pragma;
6624
6625 -- Start of processing for Analyze_Pragma
6626
6627 begin
6628 -- The following code is a defense against recursion. Not clear that
6629 -- this can happen legitimately, but perhaps some error situations
6630 -- can cause it, and we did see this recursion during testing.
6631
6632 if Analyzed (N) then
6633 return;
6634 else
6635 Set_Analyzed (N, True);
6636 end if;
6637
6638 -- Deal with unrecognized pragma
6639
6640 Pname := Pragma_Name (N);
6641
6642 if not Is_Pragma_Name (Pname) then
6643 if Warn_On_Unrecognized_Pragma then
6644 Error_Msg_Name_1 := Pname;
6645 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
6646
6647 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6648 if Is_Bad_Spelling_Of (Pname, PN) then
6649 Error_Msg_Name_1 := PN;
6650 Error_Msg_N -- CODEFIX
6651 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
6652 exit;
6653 end if;
6654 end loop;
6655 end if;
6656
6657 return;
6658 end if;
6659
6660 -- Here to start processing for recognized pragma
6661
6662 Prag_Id := Get_Pragma_Id (Pname);
6663
6664 if Present (Corresponding_Aspect (N)) then
6665 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6666 end if;
6667
6668 -- Preset arguments
6669
6670 Arg_Count := 0;
6671 Arg1 := Empty;
6672 Arg2 := Empty;
6673 Arg3 := Empty;
6674 Arg4 := Empty;
6675
6676 if Present (Pragma_Argument_Associations (N)) then
6677 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6678 Arg1 := First (Pragma_Argument_Associations (N));
6679
6680 if Present (Arg1) then
6681 Arg2 := Next (Arg1);
6682
6683 if Present (Arg2) then
6684 Arg3 := Next (Arg2);
6685
6686 if Present (Arg3) then
6687 Arg4 := Next (Arg3);
6688 end if;
6689 end if;
6690 end if;
6691 end if;
6692
6693 -- An enumeration type defines the pragmas that are supported by the
6694 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6695 -- into the corresponding enumeration value for the following case.
6696
6697 case Prag_Id is
6698
6699 -----------------
6700 -- Abort_Defer --
6701 -----------------
6702
6703 -- pragma Abort_Defer;
6704
6705 when Pragma_Abort_Defer =>
6706 GNAT_Pragma;
6707 Check_Arg_Count (0);
6708
6709 -- The only required semantic processing is to check the
6710 -- placement. This pragma must appear at the start of the
6711 -- statement sequence of a handled sequence of statements.
6712
6713 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6714 or else N /= First (Statements (Parent (N)))
6715 then
6716 Pragma_Misplaced;
6717 end if;
6718
6719 --------------------
6720 -- Abstract_State --
6721 --------------------
6722
6723 -- pragma Abstract_State (ABSTRACT_STATE_LIST)
6724
6725 -- ABSTRACT_STATE_LIST ::=
6726 -- null
6727 -- | STATE_NAME_WITH_PROPERTIES {, STATE_NAME_WITH_PROPERTIES}
6728
6729 -- STATE_NAME_WITH_PROPERTIES ::=
6730 -- STATE_NAME
6731 -- | (STATE_NAME with PROPERTY_LIST)
6732
6733 -- PROPERTY_LIST ::= PROPERTY {, PROPERTY}
6734 -- PROPERTY ::= SIMPLE_PROPERTY
6735 -- | NAME_VALUE_PROPERTY
6736 -- SIMPLE_PROPERTY ::= IDENTIFIER
6737 -- NAME_VALUE_PROPERTY ::= IDENTIFIER => EXPRESSION
6738 -- STATE_NAME ::= DEFINING_IDENTIFIER
6739
6740 when Pragma_Abstract_State => Abstract_State : declare
6741 Pack_Id : Entity_Id;
6742
6743 -- Flags used to verify the consistency of states
6744
6745 Non_Null_Seen : Boolean := False;
6746 Null_Seen : Boolean := False;
6747
6748 procedure Analyze_Abstract_State (State : Node_Id);
6749 -- Verify the legality of a single state declaration. Create and
6750 -- decorate a state abstraction entity and introduce it into the
6751 -- visibility chain.
6752
6753 ----------------------------
6754 -- Analyze_Abstract_State --
6755 ----------------------------
6756
6757 procedure Analyze_Abstract_State (State : Node_Id) is
6758 procedure Check_Duplicate_Property
6759 (Prop : Node_Id;
6760 Status : in out Boolean);
6761 -- Flag Status denotes whether a particular property has been
6762 -- seen while processing a state. This routine verifies that
6763 -- Prop is not a duplicate property and sets the flag Status.
6764
6765 ------------------------------
6766 -- Check_Duplicate_Property --
6767 ------------------------------
6768
6769 procedure Check_Duplicate_Property
6770 (Prop : Node_Id;
6771 Status : in out Boolean)
6772 is
6773 begin
6774 if Status then
6775 Error_Msg_N ("duplicate state property", Prop);
6776 end if;
6777
6778 Status := True;
6779 end Check_Duplicate_Property;
6780
6781 -- Local variables
6782
6783 Errors : constant Nat := Serious_Errors_Detected;
6784 Loc : constant Source_Ptr := Sloc (State);
6785 Assoc : Node_Id;
6786 Id : Entity_Id;
6787 Is_Null : Boolean := False;
6788 Level : Uint := Uint_0;
6789 Name : Name_Id;
6790 Prop : Node_Id;
6791
6792 -- Flags used to verify the consistency of properties
6793
6794 Input_Seen : Boolean := False;
6795 Integrity_Seen : Boolean := False;
6796 Output_Seen : Boolean := False;
6797 Volatile_Seen : Boolean := False;
6798
6799 -- Start of processing for Analyze_Abstract_State
6800
6801 begin
6802 -- A package with a null abstract state is not allowed to
6803 -- declare additional states.
6804
6805 if Null_Seen then
6806 Error_Msg_Name_1 := Chars (Pack_Id);
6807 Error_Msg_N ("package % has null abstract state", State);
6808
6809 -- Null states appear as internally generated entities
6810
6811 elsif Nkind (State) = N_Null then
6812 Name := New_Internal_Name ('S');
6813 Is_Null := True;
6814 Null_Seen := True;
6815
6816 -- Catch a case where a null state appears in a list of
6817 -- non-null states.
6818
6819 if Non_Null_Seen then
6820 Error_Msg_Name_1 := Chars (Pack_Id);
6821 Error_Msg_N
6822 ("package % has non-null abstract state", State);
6823 end if;
6824
6825 -- Simple state declaration
6826
6827 elsif Nkind (State) = N_Identifier then
6828 Name := Chars (State);
6829 Non_Null_Seen := True;
6830
6831 -- State declaration with various properties. This construct
6832 -- appears as an extension aggregate in the tree.
6833
6834 elsif Nkind (State) = N_Extension_Aggregate then
6835 if Nkind (Ancestor_Part (State)) = N_Identifier then
6836 Name := Chars (Ancestor_Part (State));
6837 Non_Null_Seen := True;
6838 else
6839 Error_Msg_N
6840 ("state name must be an identifier",
6841 Ancestor_Part (State));
6842 end if;
6843
6844 -- Process properties Input, Output and Volatile. Ensure
6845 -- that none of them appear more than once.
6846
6847 Prop := First (Expressions (State));
6848 while Present (Prop) loop
6849 if Nkind (Prop) = N_Identifier then
6850 if Chars (Prop) = Name_Input then
6851 Check_Duplicate_Property (Prop, Input_Seen);
6852 elsif Chars (Prop) = Name_Output then
6853 Check_Duplicate_Property (Prop, Output_Seen);
6854 elsif Chars (Prop) = Name_Volatile then
6855 Check_Duplicate_Property (Prop, Volatile_Seen);
6856 else
6857 Error_Msg_N ("invalid state property", Prop);
6858 end if;
6859 else
6860 Error_Msg_N ("invalid state property", Prop);
6861 end if;
6862
6863 Next (Prop);
6864 end loop;
6865
6866 -- Volatile requires exactly one Input or Output
6867
6868 if Volatile_Seen
6869 and then
6870 ((Input_Seen and then Output_Seen) -- both
6871 or else
6872 (not Input_Seen and then not Output_Seen)) -- none
6873 then
6874 Error_Msg_N
6875 ("property Volatile requires exactly one Input or " &
6876 "Output", State);
6877 end if;
6878
6879 -- Either Input or Output require Volatile
6880
6881 if (Input_Seen or Output_Seen)
6882 and then not Volatile_Seen
6883 then
6884 Error_Msg_N
6885 ("properties Input and Output require Volatile", State);
6886 end if;
6887
6888 -- State property Integrity appears as a component
6889 -- association.
6890
6891 Assoc := First (Component_Associations (State));
6892 while Present (Assoc) loop
6893 Prop := First (Choices (Assoc));
6894 while Present (Prop) loop
6895 if Nkind (Prop) = N_Identifier
6896 and then Chars (Prop) = Name_Integrity
6897 then
6898 Check_Duplicate_Property (Prop, Integrity_Seen);
6899 else
6900 Error_Msg_N ("invalid state property", Prop);
6901 end if;
6902
6903 Next (Prop);
6904 end loop;
6905
6906 if Nkind (Expression (Assoc)) = N_Integer_Literal then
6907 Level := Intval (Expression (Assoc));
6908 else
6909 Error_Msg_N
6910 ("integrity level must be an integer literal",
6911 Expression (Assoc));
6912 end if;
6913
6914 Next (Assoc);
6915 end loop;
6916
6917 -- Any other attempt to declare a state is erroneous
6918
6919 else
6920 Error_Msg_N ("malformed abstract state declaration", State);
6921 end if;
6922
6923 -- Do not generate a state abstraction entity if it was not
6924 -- properly declared.
6925
6926 if Serious_Errors_Detected > Errors then
6927 return;
6928 end if;
6929
6930 -- The generated state abstraction reuses the same characters
6931 -- from the original state declaration. Decorate the entity.
6932
6933 Id := Make_Defining_Identifier (Loc, New_External_Name (Name));
6934 Set_Comes_From_Source (Id, not Is_Null);
6935 Set_Parent (Id, State);
6936 Set_Ekind (Id, E_Abstract_State);
6937 Set_Etype (Id, Standard_Void_Type);
6938 Set_Integrity_Level (Id, Level);
6939 Set_Refined_State (Id, Empty);
6940
6941 -- Every non-null state must be nameable and resolvable the
6942 -- same way a constant is.
6943
6944 if not Is_Null then
6945 Push_Scope (Pack_Id);
6946 Enter_Name (Id);
6947 Pop_Scope;
6948 end if;
6949
6950 -- Associate the state with its related package
6951
6952 if No (Abstract_States (Pack_Id)) then
6953 Set_Abstract_States (Pack_Id, New_Elmt_List);
6954 end if;
6955
6956 Append_Elmt (Id, Abstract_States (Pack_Id));
6957 end Analyze_Abstract_State;
6958
6959 -- Local variables
6960
6961 Par : Node_Id;
6962 State : Node_Id;
6963
6964 -- Start of processing for Abstract_State
6965
6966 begin
6967 GNAT_Pragma;
6968 S14_Pragma;
6969 Check_Arg_Count (1);
6970
6971 -- Ensure the proper placement of the pragma. Abstract states must
6972 -- be associated with a package declaration.
6973
6974 if From_Aspect_Specification (N) then
6975 Par := Parent (Corresponding_Aspect (N));
6976 else
6977 Par := Parent (Parent (N));
6978 end if;
6979
6980 if Nkind (Par) = N_Compilation_Unit then
6981 Par := Unit (Par);
6982 end if;
6983
6984 if Nkind (Par) /= N_Package_Declaration then
6985 Pragma_Misplaced;
6986 return;
6987 end if;
6988
6989 Pack_Id := Defining_Unit_Name (Specification (Par));
6990 State := Expression (Arg1);
6991
6992 -- Multiple abstract states appear as an aggregate
6993
6994 if Nkind (State) = N_Aggregate then
6995 State := First (Expressions (State));
6996 while Present (State) loop
6997 Analyze_Abstract_State (State);
6998
6999 Next (State);
7000 end loop;
7001
7002 -- Various forms of a single abstract state. Note that these may
7003 -- include malformed state declarations.
7004
7005 else
7006 Analyze_Abstract_State (State);
7007 end if;
7008 end Abstract_State;
7009
7010 ------------
7011 -- Ada_83 --
7012 ------------
7013
7014 -- pragma Ada_83;
7015
7016 -- Note: this pragma also has some specific processing in Par.Prag
7017 -- because we want to set the Ada version mode during parsing.
7018
7019 when Pragma_Ada_83 =>
7020 GNAT_Pragma;
7021 Check_Arg_Count (0);
7022
7023 -- We really should check unconditionally for proper configuration
7024 -- pragma placement, since we really don't want mixed Ada modes
7025 -- within a single unit, and the GNAT reference manual has always
7026 -- said this was a configuration pragma, but we did not check and
7027 -- are hesitant to add the check now.
7028
7029 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
7030 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
7031 -- or Ada 2012 mode.
7032
7033 if Ada_Version >= Ada_2005 then
7034 Check_Valid_Configuration_Pragma;
7035 end if;
7036
7037 -- Now set Ada 83 mode
7038
7039 Ada_Version := Ada_83;
7040 Ada_Version_Explicit := Ada_Version;
7041
7042 ------------
7043 -- Ada_95 --
7044 ------------
7045
7046 -- pragma Ada_95;
7047
7048 -- Note: this pragma also has some specific processing in Par.Prag
7049 -- because we want to set the Ada 83 version mode during parsing.
7050
7051 when Pragma_Ada_95 =>
7052 GNAT_Pragma;
7053 Check_Arg_Count (0);
7054
7055 -- We really should check unconditionally for proper configuration
7056 -- pragma placement, since we really don't want mixed Ada modes
7057 -- within a single unit, and the GNAT reference manual has always
7058 -- said this was a configuration pragma, but we did not check and
7059 -- are hesitant to add the check now.
7060
7061 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
7062 -- or Ada 95, so we must check if we are in Ada 2005 mode.
7063
7064 if Ada_Version >= Ada_2005 then
7065 Check_Valid_Configuration_Pragma;
7066 end if;
7067
7068 -- Now set Ada 95 mode
7069
7070 Ada_Version := Ada_95;
7071 Ada_Version_Explicit := Ada_Version;
7072
7073 ---------------------
7074 -- Ada_05/Ada_2005 --
7075 ---------------------
7076
7077 -- pragma Ada_05;
7078 -- pragma Ada_05 (LOCAL_NAME);
7079
7080 -- pragma Ada_2005;
7081 -- pragma Ada_2005 (LOCAL_NAME):
7082
7083 -- Note: these pragmas also have some specific processing in Par.Prag
7084 -- because we want to set the Ada 2005 version mode during parsing.
7085
7086 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
7087 E_Id : Node_Id;
7088
7089 begin
7090 GNAT_Pragma;
7091
7092 if Arg_Count = 1 then
7093 Check_Arg_Is_Local_Name (Arg1);
7094 E_Id := Get_Pragma_Arg (Arg1);
7095
7096 if Etype (E_Id) = Any_Type then
7097 return;
7098 end if;
7099
7100 Set_Is_Ada_2005_Only (Entity (E_Id));
7101 Record_Rep_Item (Entity (E_Id), N);
7102
7103 else
7104 Check_Arg_Count (0);
7105
7106 -- For Ada_2005 we unconditionally enforce the documented
7107 -- configuration pragma placement, since we do not want to
7108 -- tolerate mixed modes in a unit involving Ada 2005. That
7109 -- would cause real difficulties for those cases where there
7110 -- are incompatibilities between Ada 95 and Ada 2005.
7111
7112 Check_Valid_Configuration_Pragma;
7113
7114 -- Now set appropriate Ada mode
7115
7116 Ada_Version := Ada_2005;
7117 Ada_Version_Explicit := Ada_2005;
7118 end if;
7119 end;
7120
7121 ---------------------
7122 -- Ada_12/Ada_2012 --
7123 ---------------------
7124
7125 -- pragma Ada_12;
7126 -- pragma Ada_12 (LOCAL_NAME);
7127
7128 -- pragma Ada_2012;
7129 -- pragma Ada_2012 (LOCAL_NAME):
7130
7131 -- Note: these pragmas also have some specific processing in Par.Prag
7132 -- because we want to set the Ada 2012 version mode during parsing.
7133
7134 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
7135 E_Id : Node_Id;
7136
7137 begin
7138 GNAT_Pragma;
7139
7140 if Arg_Count = 1 then
7141 Check_Arg_Is_Local_Name (Arg1);
7142 E_Id := Get_Pragma_Arg (Arg1);
7143
7144 if Etype (E_Id) = Any_Type then
7145 return;
7146 end if;
7147
7148 Set_Is_Ada_2012_Only (Entity (E_Id));
7149 Record_Rep_Item (Entity (E_Id), N);
7150
7151 else
7152 Check_Arg_Count (0);
7153
7154 -- For Ada_2012 we unconditionally enforce the documented
7155 -- configuration pragma placement, since we do not want to
7156 -- tolerate mixed modes in a unit involving Ada 2012. That
7157 -- would cause real difficulties for those cases where there
7158 -- are incompatibilities between Ada 95 and Ada 2012. We could
7159 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
7160
7161 Check_Valid_Configuration_Pragma;
7162
7163 -- Now set appropriate Ada mode
7164
7165 Ada_Version := Ada_2012;
7166 Ada_Version_Explicit := Ada_2012;
7167 end if;
7168 end;
7169
7170 ----------------------
7171 -- All_Calls_Remote --
7172 ----------------------
7173
7174 -- pragma All_Calls_Remote [(library_package_NAME)];
7175
7176 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
7177 Lib_Entity : Entity_Id;
7178
7179 begin
7180 Check_Ada_83_Warning;
7181 Check_Valid_Library_Unit_Pragma;
7182
7183 if Nkind (N) = N_Null_Statement then
7184 return;
7185 end if;
7186
7187 Lib_Entity := Find_Lib_Unit_Name;
7188
7189 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
7190
7191 if Present (Lib_Entity)
7192 and then not Debug_Flag_U
7193 then
7194 if not Is_Remote_Call_Interface (Lib_Entity) then
7195 Error_Pragma ("pragma% only apply to rci unit");
7196
7197 -- Set flag for entity of the library unit
7198
7199 else
7200 Set_Has_All_Calls_Remote (Lib_Entity);
7201 end if;
7202
7203 end if;
7204 end All_Calls_Remote;
7205
7206 --------------
7207 -- Annotate --
7208 --------------
7209
7210 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
7211 -- ARG ::= NAME | EXPRESSION
7212
7213 -- The first two arguments are by convention intended to refer to an
7214 -- external tool and a tool-specific function. These arguments are
7215 -- not analyzed.
7216
7217 when Pragma_Annotate => Annotate : declare
7218 Arg : Node_Id;
7219 Exp : Node_Id;
7220
7221 begin
7222 GNAT_Pragma;
7223 Check_At_Least_N_Arguments (1);
7224 Check_Arg_Is_Identifier (Arg1);
7225 Check_No_Identifiers;
7226 Store_Note (N);
7227
7228 -- Second parameter is optional, it is never analyzed
7229
7230 if No (Arg2) then
7231 null;
7232
7233 -- Here if we have a second parameter
7234
7235 else
7236 -- Second parameter must be identifier
7237
7238 Check_Arg_Is_Identifier (Arg2);
7239
7240 -- Process remaining parameters if any
7241
7242 Arg := Next (Arg2);
7243 while Present (Arg) loop
7244 Exp := Get_Pragma_Arg (Arg);
7245 Analyze (Exp);
7246
7247 if Is_Entity_Name (Exp) then
7248 null;
7249
7250 -- For string literals, we assume Standard_String as the
7251 -- type, unless the string contains wide or wide_wide
7252 -- characters.
7253
7254 elsif Nkind (Exp) = N_String_Literal then
7255 if Has_Wide_Wide_Character (Exp) then
7256 Resolve (Exp, Standard_Wide_Wide_String);
7257 elsif Has_Wide_Character (Exp) then
7258 Resolve (Exp, Standard_Wide_String);
7259 else
7260 Resolve (Exp, Standard_String);
7261 end if;
7262
7263 elsif Is_Overloaded (Exp) then
7264 Error_Pragma_Arg
7265 ("ambiguous argument for pragma%", Exp);
7266
7267 else
7268 Resolve (Exp);
7269 end if;
7270
7271 Next (Arg);
7272 end loop;
7273 end if;
7274 end Annotate;
7275
7276 ---------------------------
7277 -- Assert/Assert_And_Cut --
7278 ---------------------------
7279
7280 -- pragma Assert
7281 -- ( [Check => ] Boolean_EXPRESSION
7282 -- [, [Message =>] Static_String_EXPRESSION]);
7283
7284 -- pragma Assert_And_Cut
7285 -- ( [Check => ] Boolean_EXPRESSION
7286 -- [, [Message =>] Static_String_EXPRESSION]);
7287
7288 when Pragma_Assert | Pragma_Assert_And_Cut => Assert : declare
7289 Expr : Node_Id;
7290 Newa : List_Id;
7291
7292 begin
7293 if Prag_Id = Pragma_Assert then
7294 Ada_2005_Pragma;
7295 else -- Pragma_Assert_And_Cut
7296 GNAT_Pragma;
7297 S14_Pragma;
7298 end if;
7299
7300 Check_At_Least_N_Arguments (1);
7301 Check_At_Most_N_Arguments (2);
7302 Check_Arg_Order ((Name_Check, Name_Message));
7303 Check_Optional_Identifier (Arg1, Name_Check);
7304
7305 -- We treat pragma Assert as equivalent to:
7306
7307 -- pragma Check (Assertion, condition [, msg]);
7308
7309 -- So rewrite pragma in this manner, transfer the message
7310 -- argument if present, and analyze the result
7311
7312 -- Pragma Assert_And_Cut is treated exactly like pragma Assert by
7313 -- the frontend. Formal verification tools may use it to "cut" the
7314 -- paths through the code, to make verification tractable. When
7315 -- dealing with a semantically analyzed tree, the information that
7316 -- a Check node N corresponds to a source Assert_And_Cut pragma
7317 -- can be retrieved from the pragma kind of Original_Node(N).
7318
7319 Expr := Get_Pragma_Arg (Arg1);
7320 Newa := New_List (
7321 Make_Pragma_Argument_Association (Loc,
7322 Expression => Make_Identifier (Loc, Name_Assertion)),
7323
7324 Make_Pragma_Argument_Association (Sloc (Expr),
7325 Expression => Expr));
7326
7327 if Arg_Count > 1 then
7328 Check_Optional_Identifier (Arg2, Name_Message);
7329 Append_To (Newa, New_Copy_Tree (Arg2));
7330 end if;
7331
7332 Rewrite (N,
7333 Make_Pragma (Loc,
7334 Chars => Name_Check,
7335 Pragma_Argument_Associations => Newa));
7336 Analyze (N);
7337 end Assert;
7338
7339 ----------------------
7340 -- Assertion_Policy --
7341 ----------------------
7342
7343 -- pragma Assertion_Policy (Check | Disable | Ignore)
7344
7345 when Pragma_Assertion_Policy => Assertion_Policy : declare
7346 Policy : Node_Id;
7347
7348 begin
7349 Ada_2005_Pragma;
7350 Check_Valid_Configuration_Pragma;
7351 Check_Arg_Count (1);
7352 Check_No_Identifiers;
7353 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7354
7355 -- We treat pragma Assertion_Policy as equivalent to:
7356
7357 -- pragma Check_Policy (Assertion, policy)
7358
7359 -- So rewrite the pragma in that manner and link on to the chain
7360 -- of Check_Policy pragmas, marking the pragma as analyzed.
7361
7362 Policy := Get_Pragma_Arg (Arg1);
7363
7364 Rewrite (N,
7365 Make_Pragma (Loc,
7366 Chars => Name_Check_Policy,
7367 Pragma_Argument_Associations => New_List (
7368 Make_Pragma_Argument_Association (Loc,
7369 Expression => Make_Identifier (Loc, Name_Assertion)),
7370
7371 Make_Pragma_Argument_Association (Loc,
7372 Expression =>
7373 Make_Identifier (Sloc (Policy), Chars (Policy))))));
7374
7375 Set_Analyzed (N);
7376 Set_Next_Pragma (N, Opt.Check_Policy_List);
7377 Opt.Check_Policy_List := N;
7378 end Assertion_Policy;
7379
7380 ------------
7381 -- Assume --
7382 ------------
7383
7384 -- pragma Assume (boolean_EXPRESSION);
7385
7386 when Pragma_Assume => Assume : declare
7387 begin
7388 GNAT_Pragma;
7389 S14_Pragma;
7390 Check_Arg_Count (1);
7391
7392 -- Pragma Assume is transformed into pragma Check in the following
7393 -- manner:
7394
7395 -- pragma Check (Assume, Expr);
7396
7397 Rewrite (N,
7398 Make_Pragma (Loc,
7399 Chars => Name_Check,
7400 Pragma_Argument_Associations => New_List (
7401 Make_Pragma_Argument_Association (Loc,
7402 Expression => Make_Identifier (Loc, Name_Assume)),
7403
7404 Make_Pragma_Argument_Association (Loc,
7405 Expression => Relocate_Node (Expression (Arg1))))));
7406 Analyze (N);
7407 end Assume;
7408
7409 ------------------------------
7410 -- Assume_No_Invalid_Values --
7411 ------------------------------
7412
7413 -- pragma Assume_No_Invalid_Values (On | Off);
7414
7415 when Pragma_Assume_No_Invalid_Values =>
7416 GNAT_Pragma;
7417 Check_Valid_Configuration_Pragma;
7418 Check_Arg_Count (1);
7419 Check_No_Identifiers;
7420 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7421
7422 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
7423 Assume_No_Invalid_Values := True;
7424 else
7425 Assume_No_Invalid_Values := False;
7426 end if;
7427
7428 --------------------------
7429 -- Attribute_Definition --
7430 --------------------------
7431
7432 -- pragma Attribute_Definition
7433 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
7434 -- [Entity =>] LOCAL_NAME,
7435 -- [Expression =>] EXPRESSION | NAME);
7436
7437 when Pragma_Attribute_Definition => Attribute_Definition : declare
7438 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
7439 Aname : Name_Id;
7440
7441 begin
7442 GNAT_Pragma;
7443 Check_Arg_Count (3);
7444 Check_Optional_Identifier (Arg1, "attribute");
7445 Check_Optional_Identifier (Arg2, "entity");
7446 Check_Optional_Identifier (Arg3, "expression");
7447
7448 if Nkind (Attribute_Designator) /= N_Identifier then
7449 Error_Msg_N ("attribute name expected", Attribute_Designator);
7450 return;
7451 end if;
7452
7453 Check_Arg_Is_Local_Name (Arg2);
7454
7455 -- If the attribute is not recognized, then issue a warning (not
7456 -- an error), and ignore the pragma.
7457
7458 Aname := Chars (Attribute_Designator);
7459
7460 if not Is_Attribute_Name (Aname) then
7461 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
7462 return;
7463 end if;
7464
7465 -- Otherwise, rewrite the pragma as an attribute definition clause
7466
7467 Rewrite (N,
7468 Make_Attribute_Definition_Clause (Loc,
7469 Name => Get_Pragma_Arg (Arg2),
7470 Chars => Aname,
7471 Expression => Get_Pragma_Arg (Arg3)));
7472 Analyze (N);
7473 end Attribute_Definition;
7474
7475 ---------------
7476 -- AST_Entry --
7477 ---------------
7478
7479 -- pragma AST_Entry (entry_IDENTIFIER);
7480
7481 when Pragma_AST_Entry => AST_Entry : declare
7482 Ent : Node_Id;
7483
7484 begin
7485 GNAT_Pragma;
7486 Check_VMS (N);
7487 Check_Arg_Count (1);
7488 Check_No_Identifiers;
7489 Check_Arg_Is_Local_Name (Arg1);
7490 Ent := Entity (Get_Pragma_Arg (Arg1));
7491
7492 -- Note: the implementation of the AST_Entry pragma could handle
7493 -- the entry family case fine, but for now we are consistent with
7494 -- the DEC rules, and do not allow the pragma, which of course
7495 -- has the effect of also forbidding the attribute.
7496
7497 if Ekind (Ent) /= E_Entry then
7498 Error_Pragma_Arg
7499 ("pragma% argument must be simple entry name", Arg1);
7500
7501 elsif Is_AST_Entry (Ent) then
7502 Error_Pragma_Arg
7503 ("duplicate % pragma for entry", Arg1);
7504
7505 elsif Has_Homonym (Ent) then
7506 Error_Pragma_Arg
7507 ("pragma% argument cannot specify overloaded entry", Arg1);
7508
7509 else
7510 declare
7511 FF : constant Entity_Id := First_Formal (Ent);
7512
7513 begin
7514 if Present (FF) then
7515 if Present (Next_Formal (FF)) then
7516 Error_Pragma_Arg
7517 ("entry for pragma% can have only one argument",
7518 Arg1);
7519
7520 elsif Parameter_Mode (FF) /= E_In_Parameter then
7521 Error_Pragma_Arg
7522 ("entry parameter for pragma% must have mode IN",
7523 Arg1);
7524 end if;
7525 end if;
7526 end;
7527
7528 Set_Is_AST_Entry (Ent);
7529 end if;
7530 end AST_Entry;
7531
7532 ------------------
7533 -- Asynchronous --
7534 ------------------
7535
7536 -- pragma Asynchronous (LOCAL_NAME);
7537
7538 when Pragma_Asynchronous => Asynchronous : declare
7539 Nm : Entity_Id;
7540 C_Ent : Entity_Id;
7541 L : List_Id;
7542 S : Node_Id;
7543 N : Node_Id;
7544 Formal : Entity_Id;
7545
7546 procedure Process_Async_Pragma;
7547 -- Common processing for procedure and access-to-procedure case
7548
7549 --------------------------
7550 -- Process_Async_Pragma --
7551 --------------------------
7552
7553 procedure Process_Async_Pragma is
7554 begin
7555 if No (L) then
7556 Set_Is_Asynchronous (Nm);
7557 return;
7558 end if;
7559
7560 -- The formals should be of mode IN (RM E.4.1(6))
7561
7562 S := First (L);
7563 while Present (S) loop
7564 Formal := Defining_Identifier (S);
7565
7566 if Nkind (Formal) = N_Defining_Identifier
7567 and then Ekind (Formal) /= E_In_Parameter
7568 then
7569 Error_Pragma_Arg
7570 ("pragma% procedure can only have IN parameter",
7571 Arg1);
7572 end if;
7573
7574 Next (S);
7575 end loop;
7576
7577 Set_Is_Asynchronous (Nm);
7578 end Process_Async_Pragma;
7579
7580 -- Start of processing for pragma Asynchronous
7581
7582 begin
7583 Check_Ada_83_Warning;
7584 Check_No_Identifiers;
7585 Check_Arg_Count (1);
7586 Check_Arg_Is_Local_Name (Arg1);
7587
7588 if Debug_Flag_U then
7589 return;
7590 end if;
7591
7592 C_Ent := Cunit_Entity (Current_Sem_Unit);
7593 Analyze (Get_Pragma_Arg (Arg1));
7594 Nm := Entity (Get_Pragma_Arg (Arg1));
7595
7596 if not Is_Remote_Call_Interface (C_Ent)
7597 and then not Is_Remote_Types (C_Ent)
7598 then
7599 -- This pragma should only appear in an RCI or Remote Types
7600 -- unit (RM E.4.1(4)).
7601
7602 Error_Pragma
7603 ("pragma% not in Remote_Call_Interface or " &
7604 "Remote_Types unit");
7605 end if;
7606
7607 if Ekind (Nm) = E_Procedure
7608 and then Nkind (Parent (Nm)) = N_Procedure_Specification
7609 then
7610 if not Is_Remote_Call_Interface (Nm) then
7611 Error_Pragma_Arg
7612 ("pragma% cannot be applied on non-remote procedure",
7613 Arg1);
7614 end if;
7615
7616 L := Parameter_Specifications (Parent (Nm));
7617 Process_Async_Pragma;
7618 return;
7619
7620 elsif Ekind (Nm) = E_Function then
7621 Error_Pragma_Arg
7622 ("pragma% cannot be applied to function", Arg1);
7623
7624 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
7625 if Is_Record_Type (Nm) then
7626
7627 -- A record type that is the Equivalent_Type for a remote
7628 -- access-to-subprogram type.
7629
7630 N := Declaration_Node (Corresponding_Remote_Type (Nm));
7631
7632 else
7633 -- A non-expanded RAS type (distribution is not enabled)
7634
7635 N := Declaration_Node (Nm);
7636 end if;
7637
7638 if Nkind (N) = N_Full_Type_Declaration
7639 and then Nkind (Type_Definition (N)) =
7640 N_Access_Procedure_Definition
7641 then
7642 L := Parameter_Specifications (Type_Definition (N));
7643 Process_Async_Pragma;
7644
7645 if Is_Asynchronous (Nm)
7646 and then Expander_Active
7647 and then Get_PCS_Name /= Name_No_DSA
7648 then
7649 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
7650 end if;
7651
7652 else
7653 Error_Pragma_Arg
7654 ("pragma% cannot reference access-to-function type",
7655 Arg1);
7656 end if;
7657
7658 -- Only other possibility is Access-to-class-wide type
7659
7660 elsif Is_Access_Type (Nm)
7661 and then Is_Class_Wide_Type (Designated_Type (Nm))
7662 then
7663 Check_First_Subtype (Arg1);
7664 Set_Is_Asynchronous (Nm);
7665 if Expander_Active then
7666 RACW_Type_Is_Asynchronous (Nm);
7667 end if;
7668
7669 else
7670 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
7671 end if;
7672 end Asynchronous;
7673
7674 ------------
7675 -- Atomic --
7676 ------------
7677
7678 -- pragma Atomic (LOCAL_NAME);
7679
7680 when Pragma_Atomic =>
7681 Process_Atomic_Shared_Volatile;
7682
7683 -----------------------
7684 -- Atomic_Components --
7685 -----------------------
7686
7687 -- pragma Atomic_Components (array_LOCAL_NAME);
7688
7689 -- This processing is shared by Volatile_Components
7690
7691 when Pragma_Atomic_Components |
7692 Pragma_Volatile_Components =>
7693
7694 Atomic_Components : declare
7695 E_Id : Node_Id;
7696 E : Entity_Id;
7697 D : Node_Id;
7698 K : Node_Kind;
7699
7700 begin
7701 Check_Ada_83_Warning;
7702 Check_No_Identifiers;
7703 Check_Arg_Count (1);
7704 Check_Arg_Is_Local_Name (Arg1);
7705 E_Id := Get_Pragma_Arg (Arg1);
7706
7707 if Etype (E_Id) = Any_Type then
7708 return;
7709 end if;
7710
7711 E := Entity (E_Id);
7712
7713 Check_Duplicate_Pragma (E);
7714
7715 if Rep_Item_Too_Early (E, N)
7716 or else
7717 Rep_Item_Too_Late (E, N)
7718 then
7719 return;
7720 end if;
7721
7722 D := Declaration_Node (E);
7723 K := Nkind (D);
7724
7725 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
7726 or else
7727 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7728 and then Nkind (D) = N_Object_Declaration
7729 and then Nkind (Object_Definition (D)) =
7730 N_Constrained_Array_Definition)
7731 then
7732 -- The flag is set on the object, or on the base type
7733
7734 if Nkind (D) /= N_Object_Declaration then
7735 E := Base_Type (E);
7736 end if;
7737
7738 Set_Has_Volatile_Components (E);
7739
7740 if Prag_Id = Pragma_Atomic_Components then
7741 Set_Has_Atomic_Components (E);
7742 end if;
7743
7744 else
7745 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7746 end if;
7747 end Atomic_Components;
7748
7749 --------------------
7750 -- Attach_Handler --
7751 --------------------
7752
7753 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7754
7755 when Pragma_Attach_Handler =>
7756 Check_Ada_83_Warning;
7757 Check_No_Identifiers;
7758 Check_Arg_Count (2);
7759
7760 if No_Run_Time_Mode then
7761 Error_Msg_CRT ("Attach_Handler pragma", N);
7762 else
7763 Check_Interrupt_Or_Attach_Handler;
7764
7765 -- The expression that designates the attribute may depend on a
7766 -- discriminant, and is therefore a per-object expression, to
7767 -- be expanded in the init proc. If expansion is enabled, then
7768 -- perform semantic checks on a copy only.
7769
7770 if Expander_Active then
7771 declare
7772 Temp : constant Node_Id :=
7773 New_Copy_Tree (Get_Pragma_Arg (Arg2));
7774 begin
7775 Set_Parent (Temp, N);
7776 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7777 end;
7778
7779 else
7780 Analyze (Get_Pragma_Arg (Arg2));
7781 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7782 end if;
7783
7784 Process_Interrupt_Or_Attach_Handler;
7785 end if;
7786
7787 --------------------
7788 -- C_Pass_By_Copy --
7789 --------------------
7790
7791 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7792
7793 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7794 Arg : Node_Id;
7795 Val : Uint;
7796
7797 begin
7798 GNAT_Pragma;
7799 Check_Valid_Configuration_Pragma;
7800 Check_Arg_Count (1);
7801 Check_Optional_Identifier (Arg1, "max_size");
7802
7803 Arg := Get_Pragma_Arg (Arg1);
7804 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7805
7806 Val := Expr_Value (Arg);
7807
7808 if Val <= 0 then
7809 Error_Pragma_Arg
7810 ("maximum size for pragma% must be positive", Arg1);
7811
7812 elsif UI_Is_In_Int_Range (Val) then
7813 Default_C_Record_Mechanism := UI_To_Int (Val);
7814
7815 -- If a giant value is given, Int'Last will do well enough.
7816 -- If sometime someone complains that a record larger than
7817 -- two gigabytes is not copied, we will worry about it then!
7818
7819 else
7820 Default_C_Record_Mechanism := Mechanism_Type'Last;
7821 end if;
7822 end C_Pass_By_Copy;
7823
7824 -----------
7825 -- Check --
7826 -----------
7827
7828 -- pragma Check ([Name =>] IDENTIFIER,
7829 -- [Check =>] Boolean_EXPRESSION
7830 -- [,[Message =>] String_EXPRESSION]);
7831
7832 when Pragma_Check => Check : declare
7833 Expr : Node_Id;
7834 Eloc : Source_Ptr;
7835 Cname : Name_Id;
7836 Str : Node_Id;
7837
7838 Check_On : Boolean;
7839 -- Set True if category of assertions referenced by Name enabled
7840
7841 begin
7842 GNAT_Pragma;
7843 Check_At_Least_N_Arguments (2);
7844 Check_At_Most_N_Arguments (3);
7845 Check_Optional_Identifier (Arg1, Name_Name);
7846 Check_Optional_Identifier (Arg2, Name_Check);
7847
7848 if Arg_Count = 3 then
7849 Check_Optional_Identifier (Arg3, Name_Message);
7850 Str := Get_Pragma_Arg (Arg3);
7851 end if;
7852
7853 Check_Arg_Is_Identifier (Arg1);
7854 Cname := Chars (Get_Pragma_Arg (Arg1));
7855 Check_On := Check_Enabled (Cname);
7856 Expr := Get_Pragma_Arg (Arg2);
7857
7858 -- Deal with SCO generation
7859
7860 case Cname is
7861 when Name_Predicate |
7862 Name_Invariant =>
7863
7864 -- Nothing to do: since checks occur in client units,
7865 -- the SCO for the aspect in the declaration unit is
7866 -- conservatively always enabled.
7867
7868 null;
7869
7870 when others =>
7871
7872 if Check_On and then not Split_PPC (N) then
7873
7874 -- Mark pragma/aspect SCO as enabled
7875
7876 Set_SCO_Pragma_Enabled (Loc);
7877 end if;
7878 end case;
7879
7880 -- Deal with analyzing the string argument.
7881
7882 if Arg_Count = 3 then
7883
7884 -- If checks are not on we don't want any expansion (since
7885 -- such expansion would not get properly deleted) but
7886 -- we do want to analyze (to get proper references).
7887 -- The Preanalyze_And_Resolve routine does just what we want
7888
7889 if not Check_On then
7890 Preanalyze_And_Resolve (Str, Standard_String);
7891
7892 -- Otherwise we need a proper analysis and expansion
7893
7894 else
7895 Analyze_And_Resolve (Str, Standard_String);
7896 end if;
7897 end if;
7898
7899 -- Now you might think we could just do the same with the
7900 -- Boolean expression if checks are off (and expansion is on)
7901 -- and then rewrite the check as a null
7902 -- statement. This would work but we would lose the useful
7903 -- warnings about an assertion being bound to fail even if
7904 -- assertions are turned off.
7905
7906 -- So instead we wrap the boolean expression in an if statement
7907 -- that looks like:
7908
7909 -- if False and then condition then
7910 -- null;
7911 -- end if;
7912
7913 -- The reason we do this rewriting during semantic analysis
7914 -- rather than as part of normal expansion is that we cannot
7915 -- analyze and expand the code for the boolean expression
7916 -- directly, or it may cause insertion of actions that would
7917 -- escape the attempt to suppress the check code.
7918
7919 -- Note that the Sloc for the if statement corresponds to the
7920 -- argument condition, not the pragma itself. The reason for
7921 -- this is that we may generate a warning if the condition is
7922 -- False at compile time, and we do not want to delete this
7923 -- warning when we delete the if statement.
7924
7925 if Expander_Active and not Check_On then
7926 Eloc := Sloc (Expr);
7927
7928 Rewrite (N,
7929 Make_If_Statement (Eloc,
7930 Condition =>
7931 Make_And_Then (Eloc,
7932 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7933 Right_Opnd => Expr),
7934 Then_Statements => New_List (
7935 Make_Null_Statement (Eloc))));
7936
7937 In_Assertion_Expr := In_Assertion_Expr + 1;
7938 Analyze (N);
7939 In_Assertion_Expr := In_Assertion_Expr - 1;
7940
7941 -- Check is active or expansion not active. In these cases we can
7942 -- just go ahead and analyze the boolean with no worries.
7943
7944 else
7945 In_Assertion_Expr := In_Assertion_Expr + 1;
7946 Analyze_And_Resolve (Expr, Any_Boolean);
7947 In_Assertion_Expr := In_Assertion_Expr - 1;
7948 end if;
7949 end Check;
7950
7951 --------------------------
7952 -- Check_Float_Overflow --
7953 --------------------------
7954
7955 -- pragma Check_Float_Overflow;
7956
7957 when Pragma_Check_Float_Overflow =>
7958 GNAT_Pragma;
7959 Check_Valid_Configuration_Pragma;
7960 Check_Arg_Count (0);
7961 Check_Float_Overflow := True;
7962
7963 ----------------
7964 -- Check_Name --
7965 ----------------
7966
7967 -- pragma Check_Name (check_IDENTIFIER);
7968
7969 when Pragma_Check_Name =>
7970 Check_No_Identifiers;
7971 GNAT_Pragma;
7972 Check_Valid_Configuration_Pragma;
7973 Check_Arg_Count (1);
7974 Check_Arg_Is_Identifier (Arg1);
7975
7976 declare
7977 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7978
7979 begin
7980 for J in Check_Names.First .. Check_Names.Last loop
7981 if Check_Names.Table (J) = Nam then
7982 return;
7983 end if;
7984 end loop;
7985
7986 Check_Names.Append (Nam);
7987 end;
7988
7989 ------------------
7990 -- Check_Policy --
7991 ------------------
7992
7993 -- pragma Check_Policy (
7994 -- [Name =>] IDENTIFIER,
7995 -- [Policy =>] POLICY_IDENTIFIER);
7996
7997 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7998
7999 -- Note: this is a configuration pragma, but it is allowed to appear
8000 -- anywhere else.
8001
8002 when Pragma_Check_Policy =>
8003 GNAT_Pragma;
8004 Check_Arg_Count (2);
8005 Check_Optional_Identifier (Arg1, Name_Name);
8006 Check_Optional_Identifier (Arg2, Name_Policy);
8007 Check_Arg_Is_One_Of
8008 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
8009
8010 -- A Check_Policy pragma can appear either as a configuration
8011 -- pragma, or in a declarative part or a package spec (see RM
8012 -- 11.5(5) for rules for Suppress/Unsuppress which are also
8013 -- followed for Check_Policy).
8014
8015 if not Is_Configuration_Pragma then
8016 Check_Is_In_Decl_Part_Or_Package_Spec;
8017 end if;
8018
8019 Set_Next_Pragma (N, Opt.Check_Policy_List);
8020 Opt.Check_Policy_List := N;
8021
8022 ---------------------
8023 -- CIL_Constructor --
8024 ---------------------
8025
8026 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
8027
8028 -- Processing for this pragma is shared with Java_Constructor
8029
8030 -------------
8031 -- Comment --
8032 -------------
8033
8034 -- pragma Comment (static_string_EXPRESSION)
8035
8036 -- Processing for pragma Comment shares the circuitry for pragma
8037 -- Ident. The only differences are that Ident enforces a limit of 31
8038 -- characters on its argument, and also enforces limitations on
8039 -- placement for DEC compatibility. Pragma Comment shares neither of
8040 -- these restrictions.
8041
8042 -------------------
8043 -- Common_Object --
8044 -------------------
8045
8046 -- pragma Common_Object (
8047 -- [Internal =>] LOCAL_NAME
8048 -- [, [External =>] EXTERNAL_SYMBOL]
8049 -- [, [Size =>] EXTERNAL_SYMBOL]);
8050
8051 -- Processing for this pragma is shared with Psect_Object
8052
8053 ------------------------
8054 -- Compile_Time_Error --
8055 ------------------------
8056
8057 -- pragma Compile_Time_Error
8058 -- (boolean_EXPRESSION, static_string_EXPRESSION);
8059
8060 when Pragma_Compile_Time_Error =>
8061 GNAT_Pragma;
8062 Process_Compile_Time_Warning_Or_Error;
8063
8064 --------------------------
8065 -- Compile_Time_Warning --
8066 --------------------------
8067
8068 -- pragma Compile_Time_Warning
8069 -- (boolean_EXPRESSION, static_string_EXPRESSION);
8070
8071 when Pragma_Compile_Time_Warning =>
8072 GNAT_Pragma;
8073 Process_Compile_Time_Warning_Or_Error;
8074
8075 -------------------
8076 -- Compiler_Unit --
8077 -------------------
8078
8079 when Pragma_Compiler_Unit =>
8080 GNAT_Pragma;
8081 Check_Arg_Count (0);
8082 Set_Is_Compiler_Unit (Get_Source_Unit (N));
8083
8084 -----------------------------
8085 -- Complete_Representation --
8086 -----------------------------
8087
8088 -- pragma Complete_Representation;
8089
8090 when Pragma_Complete_Representation =>
8091 GNAT_Pragma;
8092 Check_Arg_Count (0);
8093
8094 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
8095 Error_Pragma
8096 ("pragma & must appear within record representation clause");
8097 end if;
8098
8099 ----------------------------
8100 -- Complex_Representation --
8101 ----------------------------
8102
8103 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
8104
8105 when Pragma_Complex_Representation => Complex_Representation : declare
8106 E_Id : Entity_Id;
8107 E : Entity_Id;
8108 Ent : Entity_Id;
8109
8110 begin
8111 GNAT_Pragma;
8112 Check_Arg_Count (1);
8113 Check_Optional_Identifier (Arg1, Name_Entity);
8114 Check_Arg_Is_Local_Name (Arg1);
8115 E_Id := Get_Pragma_Arg (Arg1);
8116
8117 if Etype (E_Id) = Any_Type then
8118 return;
8119 end if;
8120
8121 E := Entity (E_Id);
8122
8123 if not Is_Record_Type (E) then
8124 Error_Pragma_Arg
8125 ("argument for pragma% must be record type", Arg1);
8126 end if;
8127
8128 Ent := First_Entity (E);
8129
8130 if No (Ent)
8131 or else No (Next_Entity (Ent))
8132 or else Present (Next_Entity (Next_Entity (Ent)))
8133 or else not Is_Floating_Point_Type (Etype (Ent))
8134 or else Etype (Ent) /= Etype (Next_Entity (Ent))
8135 then
8136 Error_Pragma_Arg
8137 ("record for pragma% must have two fields of the same "
8138 & "floating-point type", Arg1);
8139
8140 else
8141 Set_Has_Complex_Representation (Base_Type (E));
8142
8143 -- We need to treat the type has having a non-standard
8144 -- representation, for back-end purposes, even though in
8145 -- general a complex will have the default representation
8146 -- of a record with two real components.
8147
8148 Set_Has_Non_Standard_Rep (Base_Type (E));
8149 end if;
8150 end Complex_Representation;
8151
8152 -------------------------
8153 -- Component_Alignment --
8154 -------------------------
8155
8156 -- pragma Component_Alignment (
8157 -- [Form =>] ALIGNMENT_CHOICE
8158 -- [, [Name =>] type_LOCAL_NAME]);
8159 --
8160 -- ALIGNMENT_CHOICE ::=
8161 -- Component_Size
8162 -- | Component_Size_4
8163 -- | Storage_Unit
8164 -- | Default
8165
8166 when Pragma_Component_Alignment => Component_AlignmentP : declare
8167 Args : Args_List (1 .. 2);
8168 Names : constant Name_List (1 .. 2) := (
8169 Name_Form,
8170 Name_Name);
8171
8172 Form : Node_Id renames Args (1);
8173 Name : Node_Id renames Args (2);
8174
8175 Atype : Component_Alignment_Kind;
8176 Typ : Entity_Id;
8177
8178 begin
8179 GNAT_Pragma;
8180 Gather_Associations (Names, Args);
8181
8182 if No (Form) then
8183 Error_Pragma ("missing Form argument for pragma%");
8184 end if;
8185
8186 Check_Arg_Is_Identifier (Form);
8187
8188 -- Get proper alignment, note that Default = Component_Size on all
8189 -- machines we have so far, and we want to set this value rather
8190 -- than the default value to indicate that it has been explicitly
8191 -- set (and thus will not get overridden by the default component
8192 -- alignment for the current scope)
8193
8194 if Chars (Form) = Name_Component_Size then
8195 Atype := Calign_Component_Size;
8196
8197 elsif Chars (Form) = Name_Component_Size_4 then
8198 Atype := Calign_Component_Size_4;
8199
8200 elsif Chars (Form) = Name_Default then
8201 Atype := Calign_Component_Size;
8202
8203 elsif Chars (Form) = Name_Storage_Unit then
8204 Atype := Calign_Storage_Unit;
8205
8206 else
8207 Error_Pragma_Arg
8208 ("invalid Form parameter for pragma%", Form);
8209 end if;
8210
8211 -- Case with no name, supplied, affects scope table entry
8212
8213 if No (Name) then
8214 Scope_Stack.Table
8215 (Scope_Stack.Last).Component_Alignment_Default := Atype;
8216
8217 -- Case of name supplied
8218
8219 else
8220 Check_Arg_Is_Local_Name (Name);
8221 Find_Type (Name);
8222 Typ := Entity (Name);
8223
8224 if Typ = Any_Type
8225 or else Rep_Item_Too_Early (Typ, N)
8226 then
8227 return;
8228 else
8229 Typ := Underlying_Type (Typ);
8230 end if;
8231
8232 if not Is_Record_Type (Typ)
8233 and then not Is_Array_Type (Typ)
8234 then
8235 Error_Pragma_Arg
8236 ("Name parameter of pragma% must identify record or " &
8237 "array type", Name);
8238 end if;
8239
8240 -- An explicit Component_Alignment pragma overrides an
8241 -- implicit pragma Pack, but not an explicit one.
8242
8243 if not Has_Pragma_Pack (Base_Type (Typ)) then
8244 Set_Is_Packed (Base_Type (Typ), False);
8245 Set_Component_Alignment (Base_Type (Typ), Atype);
8246 end if;
8247 end if;
8248 end Component_AlignmentP;
8249
8250 -------------------
8251 -- Contract_Case --
8252 -------------------
8253
8254 -- pragma Contract_Case
8255 -- ([Name =>] Static_String_EXPRESSION
8256 -- ,[Mode =>] MODE_TYPE
8257 -- [, Requires => Boolean_EXPRESSION]
8258 -- [, Ensures => Boolean_EXPRESSION]);
8259
8260 -- MODE_TYPE ::= Nominal | Robustness
8261
8262 when Pragma_Contract_Case =>
8263 Check_Contract_Or_Test_Case;
8264
8265 --------------------
8266 -- Contract_Cases --
8267 --------------------
8268
8269 -- pragma Contract_Cases (CONTRACT_CASE_LIST);
8270
8271 -- CONTRACT_CASE_LIST ::= CONTRACT_CASE {, CONTRACT_CASE}
8272
8273 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
8274
8275 -- CASE_GUARD ::= boolean_EXPRESSION | others
8276
8277 -- CONSEQUENCE ::= boolean_EXPRESSION
8278
8279 when Pragma_Contract_Cases => Contract_Cases : declare
8280 procedure Chain_Contract_Cases (Subp_Decl : Node_Id);
8281 -- Chain pragma Contract_Cases to the contract of a subprogram.
8282 -- Subp_Decl is the declaration of the subprogram.
8283
8284 --------------------------
8285 -- Chain_Contract_Cases --
8286 --------------------------
8287
8288 procedure Chain_Contract_Cases (Subp_Decl : Node_Id) is
8289 Subp : constant Entity_Id :=
8290 Defining_Unit_Name (Specification (Subp_Decl));
8291 CTC : Node_Id;
8292
8293 begin
8294 Check_Duplicate_Pragma (Subp);
8295 CTC := Spec_CTC_List (Contract (Subp));
8296 while Present (CTC) loop
8297 if Chars (Pragma_Identifier (CTC)) = Pname then
8298 Error_Msg_Name_1 := Pname;
8299 Error_Msg_Sloc := Sloc (CTC);
8300
8301 if From_Aspect_Specification (CTC) then
8302 Error_Msg_NE
8303 ("aspect% for & previously given#", N, Subp);
8304 else
8305 Error_Msg_NE
8306 ("pragma% for & duplicates pragma#", N, Subp);
8307 end if;
8308
8309 raise Pragma_Exit;
8310 end if;
8311
8312 CTC := Next_Pragma (CTC);
8313 end loop;
8314
8315 -- Prepend pragma Contract_Cases to the contract
8316
8317 Set_Next_Pragma (N, Spec_CTC_List (Contract (Subp)));
8318 Set_Spec_CTC_List (Contract (Subp), N);
8319 end Chain_Contract_Cases;
8320
8321 -- Local variables
8322
8323 Case_Guard : Node_Id;
8324 Decl : Node_Id;
8325 Extra : Node_Id;
8326 Others_Seen : Boolean := False;
8327 Contract_Case : Node_Id;
8328 Subp_Decl : Node_Id;
8329
8330 -- Start of processing for Contract_Cases
8331
8332 begin
8333 GNAT_Pragma;
8334 S14_Pragma;
8335 Check_Arg_Count (1);
8336
8337 -- Completely ignore if disabled
8338
8339 if not Check_Enabled (Pname) then
8340 Rewrite (N, Make_Null_Statement (Loc));
8341 Analyze (N);
8342 return;
8343 end if;
8344
8345 -- Check the placement of the pragma
8346
8347 if not Is_List_Member (N) then
8348 Pragma_Misplaced;
8349 end if;
8350
8351 -- Pragma Contract_Cases must be associated with a subprogram
8352
8353 Decl := N;
8354 while Present (Prev (Decl)) loop
8355 Decl := Prev (Decl);
8356
8357 if Nkind (Decl) in N_Generic_Declaration then
8358 Subp_Decl := Decl;
8359 else
8360 Subp_Decl := Original_Node (Decl);
8361 end if;
8362
8363 -- Skip prior pragmas
8364
8365 if Nkind (Subp_Decl) = N_Pragma then
8366 null;
8367
8368 -- Skip internally generated code
8369
8370 elsif not Comes_From_Source (Subp_Decl) then
8371 null;
8372
8373 -- We have found the related subprogram
8374
8375 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
8376 N_Subprogram_Declaration)
8377 then
8378 exit;
8379
8380 else
8381 Pragma_Misplaced;
8382 end if;
8383 end loop;
8384
8385 -- All contract cases must appear as an aggregate
8386
8387 if Nkind (Expression (Arg1)) /= N_Aggregate then
8388 Error_Pragma ("wrong syntax for pragma %");
8389 return;
8390 end if;
8391
8392 -- Verify the legality of individual contract cases
8393
8394 Contract_Case :=
8395 First (Component_Associations (Expression (Arg1)));
8396 while Present (Contract_Case) loop
8397 if Nkind (Contract_Case) /= N_Component_Association then
8398 Error_Pragma_Arg
8399 ("wrong syntax in contract case", Contract_Case);
8400 return;
8401 end if;
8402
8403 Case_Guard := First (Choices (Contract_Case));
8404
8405 -- Each contract case must have exactly on case guard
8406
8407 Extra := Next (Case_Guard);
8408 if Present (Extra) then
8409 Error_Pragma_Arg
8410 ("contract case may have only one case guard", Extra);
8411 return;
8412 end if;
8413
8414 -- Check the placement of "others" (if available)
8415
8416 if Nkind (Case_Guard) = N_Others_Choice then
8417 if Others_Seen then
8418 Error_Pragma_Arg
8419 ("only one others choice allowed in pragma %",
8420 Case_Guard);
8421 return;
8422 else
8423 Others_Seen := True;
8424 end if;
8425
8426 elsif Others_Seen then
8427 Error_Pragma_Arg
8428 ("others must be the last choice in pragma %", N);
8429 return;
8430 end if;
8431
8432 Next (Contract_Case);
8433 end loop;
8434
8435 Chain_Contract_Cases (Subp_Decl);
8436 end Contract_Cases;
8437
8438 ----------------
8439 -- Controlled --
8440 ----------------
8441
8442 -- pragma Controlled (first_subtype_LOCAL_NAME);
8443
8444 when Pragma_Controlled => Controlled : declare
8445 Arg : Node_Id;
8446
8447 begin
8448 Check_No_Identifiers;
8449 Check_Arg_Count (1);
8450 Check_Arg_Is_Local_Name (Arg1);
8451 Arg := Get_Pragma_Arg (Arg1);
8452
8453 if not Is_Entity_Name (Arg)
8454 or else not Is_Access_Type (Entity (Arg))
8455 then
8456 Error_Pragma_Arg ("pragma% requires access type", Arg1);
8457 else
8458 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
8459 end if;
8460 end Controlled;
8461
8462 ----------------
8463 -- Convention --
8464 ----------------
8465
8466 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
8467 -- [Entity =>] LOCAL_NAME);
8468
8469 when Pragma_Convention => Convention : declare
8470 C : Convention_Id;
8471 E : Entity_Id;
8472 pragma Warnings (Off, C);
8473 pragma Warnings (Off, E);
8474 begin
8475 Check_Arg_Order ((Name_Convention, Name_Entity));
8476 Check_Ada_83_Warning;
8477 Check_Arg_Count (2);
8478 Process_Convention (C, E);
8479 end Convention;
8480
8481 ---------------------------
8482 -- Convention_Identifier --
8483 ---------------------------
8484
8485 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
8486 -- [Convention =>] convention_IDENTIFIER);
8487
8488 when Pragma_Convention_Identifier => Convention_Identifier : declare
8489 Idnam : Name_Id;
8490 Cname : Name_Id;
8491
8492 begin
8493 GNAT_Pragma;
8494 Check_Arg_Order ((Name_Name, Name_Convention));
8495 Check_Arg_Count (2);
8496 Check_Optional_Identifier (Arg1, Name_Name);
8497 Check_Optional_Identifier (Arg2, Name_Convention);
8498 Check_Arg_Is_Identifier (Arg1);
8499 Check_Arg_Is_Identifier (Arg2);
8500 Idnam := Chars (Get_Pragma_Arg (Arg1));
8501 Cname := Chars (Get_Pragma_Arg (Arg2));
8502
8503 if Is_Convention_Name (Cname) then
8504 Record_Convention_Identifier
8505 (Idnam, Get_Convention_Id (Cname));
8506 else
8507 Error_Pragma_Arg
8508 ("second arg for % pragma must be convention", Arg2);
8509 end if;
8510 end Convention_Identifier;
8511
8512 ---------------
8513 -- CPP_Class --
8514 ---------------
8515
8516 -- pragma CPP_Class ([Entity =>] local_NAME)
8517
8518 when Pragma_CPP_Class => CPP_Class : declare
8519 begin
8520 GNAT_Pragma;
8521
8522 if Warn_On_Obsolescent_Feature then
8523 -- Following message is obsolete ???
8524 Error_Msg_N
8525 ("'G'N'A'T pragma cpp'_class is now obsolete and has no " &
8526 "effect; replace it by pragma import?j?", N);
8527 end if;
8528
8529 Check_Arg_Count (1);
8530
8531 Rewrite (N,
8532 Make_Pragma (Loc,
8533 Chars => Name_Import,
8534 Pragma_Argument_Associations => New_List (
8535 Make_Pragma_Argument_Association (Loc,
8536 Expression => Make_Identifier (Loc, Name_CPP)),
8537 New_Copy (First (Pragma_Argument_Associations (N))))));
8538 Analyze (N);
8539 end CPP_Class;
8540
8541 ---------------------
8542 -- CPP_Constructor --
8543 ---------------------
8544
8545 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
8546 -- [, [External_Name =>] static_string_EXPRESSION ]
8547 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8548
8549 when Pragma_CPP_Constructor => CPP_Constructor : declare
8550 Elmt : Elmt_Id;
8551 Id : Entity_Id;
8552 Def_Id : Entity_Id;
8553 Tag_Typ : Entity_Id;
8554
8555 begin
8556 GNAT_Pragma;
8557 Check_At_Least_N_Arguments (1);
8558 Check_At_Most_N_Arguments (3);
8559 Check_Optional_Identifier (Arg1, Name_Entity);
8560 Check_Arg_Is_Local_Name (Arg1);
8561
8562 Id := Get_Pragma_Arg (Arg1);
8563 Find_Program_Unit_Name (Id);
8564
8565 -- If we did not find the name, we are done
8566
8567 if Etype (Id) = Any_Type then
8568 return;
8569 end if;
8570
8571 Def_Id := Entity (Id);
8572
8573 -- Check if already defined as constructor
8574
8575 if Is_Constructor (Def_Id) then
8576 Error_Msg_N
8577 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
8578 return;
8579 end if;
8580
8581 if Ekind (Def_Id) = E_Function
8582 and then (Is_CPP_Class (Etype (Def_Id))
8583 or else (Is_Class_Wide_Type (Etype (Def_Id))
8584 and then
8585 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
8586 then
8587 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
8588 Error_Msg_N
8589 ("'C'P'P constructor must be defined in the scope of " &
8590 "its returned type", Arg1);
8591 end if;
8592
8593 if Arg_Count >= 2 then
8594 Set_Imported (Def_Id);
8595 Set_Is_Public (Def_Id);
8596 Process_Interface_Name (Def_Id, Arg2, Arg3);
8597 end if;
8598
8599 Set_Has_Completion (Def_Id);
8600 Set_Is_Constructor (Def_Id);
8601 Set_Convention (Def_Id, Convention_CPP);
8602
8603 -- Imported C++ constructors are not dispatching primitives
8604 -- because in C++ they don't have a dispatch table slot.
8605 -- However, in Ada the constructor has the profile of a
8606 -- function that returns a tagged type and therefore it has
8607 -- been treated as a primitive operation during semantic
8608 -- analysis. We now remove it from the list of primitive
8609 -- operations of the type.
8610
8611 if Is_Tagged_Type (Etype (Def_Id))
8612 and then not Is_Class_Wide_Type (Etype (Def_Id))
8613 and then Is_Dispatching_Operation (Def_Id)
8614 then
8615 Tag_Typ := Etype (Def_Id);
8616
8617 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
8618 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
8619 Next_Elmt (Elmt);
8620 end loop;
8621
8622 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
8623 Set_Is_Dispatching_Operation (Def_Id, False);
8624 end if;
8625
8626 -- For backward compatibility, if the constructor returns a
8627 -- class wide type, and we internally change the return type to
8628 -- the corresponding root type.
8629
8630 if Is_Class_Wide_Type (Etype (Def_Id)) then
8631 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
8632 end if;
8633 else
8634 Error_Pragma_Arg
8635 ("pragma% requires function returning a 'C'P'P_Class type",
8636 Arg1);
8637 end if;
8638 end CPP_Constructor;
8639
8640 -----------------
8641 -- CPP_Virtual --
8642 -----------------
8643
8644 when Pragma_CPP_Virtual => CPP_Virtual : declare
8645 begin
8646 GNAT_Pragma;
8647
8648 if Warn_On_Obsolescent_Feature then
8649 Error_Msg_N
8650 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
8651 "no effect?j?", N);
8652 end if;
8653 end CPP_Virtual;
8654
8655 ----------------
8656 -- CPP_Vtable --
8657 ----------------
8658
8659 when Pragma_CPP_Vtable => CPP_Vtable : declare
8660 begin
8661 GNAT_Pragma;
8662
8663 if Warn_On_Obsolescent_Feature then
8664 Error_Msg_N
8665 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
8666 "no effect?j?", N);
8667 end if;
8668 end CPP_Vtable;
8669
8670 ---------
8671 -- CPU --
8672 ---------
8673
8674 -- pragma CPU (EXPRESSION);
8675
8676 when Pragma_CPU => CPU : declare
8677 P : constant Node_Id := Parent (N);
8678 Arg : Node_Id;
8679 Ent : Entity_Id;
8680
8681 begin
8682 Ada_2012_Pragma;
8683 Check_No_Identifiers;
8684 Check_Arg_Count (1);
8685
8686 -- Subprogram case
8687
8688 if Nkind (P) = N_Subprogram_Body then
8689 Check_In_Main_Program;
8690
8691 Arg := Get_Pragma_Arg (Arg1);
8692 Analyze_And_Resolve (Arg, Any_Integer);
8693
8694 Ent := Defining_Unit_Name (Specification (P));
8695
8696 if Nkind (Ent) = N_Defining_Program_Unit_Name then
8697 Ent := Defining_Identifier (Ent);
8698 end if;
8699
8700 -- Must be static
8701
8702 if not Is_Static_Expression (Arg) then
8703 Flag_Non_Static_Expr
8704 ("main subprogram affinity is not static!", Arg);
8705 raise Pragma_Exit;
8706
8707 -- If constraint error, then we already signalled an error
8708
8709 elsif Raises_Constraint_Error (Arg) then
8710 null;
8711
8712 -- Otherwise check in range
8713
8714 else
8715 declare
8716 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
8717 -- This is the entity System.Multiprocessors.CPU_Range;
8718
8719 Val : constant Uint := Expr_Value (Arg);
8720
8721 begin
8722 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
8723 or else
8724 Val > Expr_Value (Type_High_Bound (CPU_Id))
8725 then
8726 Error_Pragma_Arg
8727 ("main subprogram CPU is out of range", Arg1);
8728 end if;
8729 end;
8730 end if;
8731
8732 Set_Main_CPU
8733 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8734
8735 -- Task case
8736
8737 elsif Nkind (P) = N_Task_Definition then
8738 Arg := Get_Pragma_Arg (Arg1);
8739 Ent := Defining_Identifier (Parent (P));
8740
8741 -- The expression must be analyzed in the special manner
8742 -- described in "Handling of Default and Per-Object
8743 -- Expressions" in sem.ads.
8744
8745 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
8746
8747 -- Anything else is incorrect
8748
8749 else
8750 Pragma_Misplaced;
8751 end if;
8752
8753 -- Check duplicate pragma before we chain the pragma in the Rep
8754 -- Item chain of Ent.
8755
8756 Check_Duplicate_Pragma (Ent);
8757 Record_Rep_Item (Ent, N);
8758 end CPU;
8759
8760 -----------
8761 -- Debug --
8762 -----------
8763
8764 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
8765
8766 when Pragma_Debug => Debug : declare
8767 Cond : Node_Id;
8768 Call : Node_Id;
8769
8770 begin
8771 GNAT_Pragma;
8772
8773 -- Skip analysis if disabled
8774
8775 if Debug_Pragmas_Disabled then
8776 Rewrite (N, Make_Null_Statement (Loc));
8777 Analyze (N);
8778 return;
8779 end if;
8780
8781 Cond :=
8782 New_Occurrence_Of
8783 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
8784 Loc);
8785
8786 if Debug_Pragmas_Enabled then
8787 Set_SCO_Pragma_Enabled (Loc);
8788 end if;
8789
8790 if Arg_Count = 2 then
8791 Cond :=
8792 Make_And_Then (Loc,
8793 Left_Opnd => Relocate_Node (Cond),
8794 Right_Opnd => Get_Pragma_Arg (Arg1));
8795 Call := Get_Pragma_Arg (Arg2);
8796 else
8797 Call := Get_Pragma_Arg (Arg1);
8798 end if;
8799
8800 if Nkind_In (Call,
8801 N_Indexed_Component,
8802 N_Function_Call,
8803 N_Identifier,
8804 N_Expanded_Name,
8805 N_Selected_Component)
8806 then
8807 -- If this pragma Debug comes from source, its argument was
8808 -- parsed as a name form (which is syntactically identical).
8809 -- In a generic context a parameterless call will be left as
8810 -- an expanded name (if global) or selected_component if local.
8811 -- Change it to a procedure call statement now.
8812
8813 Change_Name_To_Procedure_Call_Statement (Call);
8814
8815 elsif Nkind (Call) = N_Procedure_Call_Statement then
8816
8817 -- Already in the form of a procedure call statement: nothing
8818 -- to do (could happen in case of an internally generated
8819 -- pragma Debug).
8820
8821 null;
8822
8823 else
8824 -- All other cases: diagnose error
8825
8826 Error_Msg
8827 ("argument of pragma ""Debug"" is not procedure call",
8828 Sloc (Call));
8829 return;
8830 end if;
8831
8832 -- Rewrite into a conditional with an appropriate condition. We
8833 -- wrap the procedure call in a block so that overhead from e.g.
8834 -- use of the secondary stack does not generate execution overhead
8835 -- for suppressed conditions.
8836
8837 -- Normally the analysis that follows will freeze the subprogram
8838 -- being called. However, if the call is to a null procedure,
8839 -- we want to freeze it before creating the block, because the
8840 -- analysis that follows may be done with expansion disabled, in
8841 -- which case the body will not be generated, leading to spurious
8842 -- errors.
8843
8844 if Nkind (Call) = N_Procedure_Call_Statement
8845 and then Is_Entity_Name (Name (Call))
8846 then
8847 Analyze (Name (Call));
8848 Freeze_Before (N, Entity (Name (Call)));
8849 end if;
8850
8851 Rewrite (N, Make_Implicit_If_Statement (N,
8852 Condition => Cond,
8853 Then_Statements => New_List (
8854 Make_Block_Statement (Loc,
8855 Handled_Statement_Sequence =>
8856 Make_Handled_Sequence_Of_Statements (Loc,
8857 Statements => New_List (Relocate_Node (Call)))))));
8858 Analyze (N);
8859 end Debug;
8860
8861 ------------------
8862 -- Debug_Policy --
8863 ------------------
8864
8865 -- pragma Debug_Policy (Check | Ignore)
8866
8867 when Pragma_Debug_Policy =>
8868 GNAT_Pragma;
8869 Check_Arg_Count (1);
8870 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
8871 Debug_Pragmas_Enabled :=
8872 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
8873 Debug_Pragmas_Disabled :=
8874 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
8875
8876 ---------------------
8877 -- Detect_Blocking --
8878 ---------------------
8879
8880 -- pragma Detect_Blocking;
8881
8882 when Pragma_Detect_Blocking =>
8883 Ada_2005_Pragma;
8884 Check_Arg_Count (0);
8885 Check_Valid_Configuration_Pragma;
8886 Detect_Blocking := True;
8887
8888 --------------------------
8889 -- Default_Storage_Pool --
8890 --------------------------
8891
8892 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
8893
8894 when Pragma_Default_Storage_Pool =>
8895 Ada_2012_Pragma;
8896 Check_Arg_Count (1);
8897
8898 -- Default_Storage_Pool can appear as a configuration pragma, or
8899 -- in a declarative part or a package spec.
8900
8901 if not Is_Configuration_Pragma then
8902 Check_Is_In_Decl_Part_Or_Package_Spec;
8903 end if;
8904
8905 -- Case of Default_Storage_Pool (null);
8906
8907 if Nkind (Expression (Arg1)) = N_Null then
8908 Analyze (Expression (Arg1));
8909
8910 -- This is an odd case, this is not really an expression, so
8911 -- we don't have a type for it. So just set the type to Empty.
8912
8913 Set_Etype (Expression (Arg1), Empty);
8914
8915 -- Case of Default_Storage_Pool (storage_pool_NAME);
8916
8917 else
8918 -- If it's a configuration pragma, then the only allowed
8919 -- argument is "null".
8920
8921 if Is_Configuration_Pragma then
8922 Error_Pragma_Arg ("NULL expected", Arg1);
8923 end if;
8924
8925 -- The expected type for a non-"null" argument is
8926 -- Root_Storage_Pool'Class.
8927
8928 Analyze_And_Resolve
8929 (Get_Pragma_Arg (Arg1),
8930 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8931 end if;
8932
8933 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
8934 -- for an access type will use this information to set the
8935 -- appropriate attributes of the access type.
8936
8937 Default_Pool := Expression (Arg1);
8938
8939 ------------------------------------
8940 -- Disable_Atomic_Synchronization --
8941 ------------------------------------
8942
8943 -- pragma Disable_Atomic_Synchronization [(Entity)];
8944
8945 when Pragma_Disable_Atomic_Synchronization =>
8946 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8947
8948 -------------------
8949 -- Discard_Names --
8950 -------------------
8951
8952 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
8953
8954 when Pragma_Discard_Names => Discard_Names : declare
8955 E : Entity_Id;
8956 E_Id : Entity_Id;
8957
8958 begin
8959 Check_Ada_83_Warning;
8960
8961 -- Deal with configuration pragma case
8962
8963 if Arg_Count = 0 and then Is_Configuration_Pragma then
8964 Global_Discard_Names := True;
8965 return;
8966
8967 -- Otherwise, check correct appropriate context
8968
8969 else
8970 Check_Is_In_Decl_Part_Or_Package_Spec;
8971
8972 if Arg_Count = 0 then
8973
8974 -- If there is no parameter, then from now on this pragma
8975 -- applies to any enumeration, exception or tagged type
8976 -- defined in the current declarative part, and recursively
8977 -- to any nested scope.
8978
8979 Set_Discard_Names (Current_Scope);
8980 return;
8981
8982 else
8983 Check_Arg_Count (1);
8984 Check_Optional_Identifier (Arg1, Name_On);
8985 Check_Arg_Is_Local_Name (Arg1);
8986
8987 E_Id := Get_Pragma_Arg (Arg1);
8988
8989 if Etype (E_Id) = Any_Type then
8990 return;
8991 else
8992 E := Entity (E_Id);
8993 end if;
8994
8995 if (Is_First_Subtype (E)
8996 and then
8997 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8998 or else Ekind (E) = E_Exception
8999 then
9000 Set_Discard_Names (E);
9001 Record_Rep_Item (E, N);
9002
9003 else
9004 Error_Pragma_Arg
9005 ("inappropriate entity for pragma%", Arg1);
9006 end if;
9007
9008 end if;
9009 end if;
9010 end Discard_Names;
9011
9012 ------------------------
9013 -- Dispatching_Domain --
9014 ------------------------
9015
9016 -- pragma Dispatching_Domain (EXPRESSION);
9017
9018 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
9019 P : constant Node_Id := Parent (N);
9020 Arg : Node_Id;
9021 Ent : Entity_Id;
9022
9023 begin
9024 Ada_2012_Pragma;
9025 Check_No_Identifiers;
9026 Check_Arg_Count (1);
9027
9028 -- This pragma is born obsolete, but not the aspect
9029
9030 if not From_Aspect_Specification (N) then
9031 Check_Restriction
9032 (No_Obsolescent_Features, Pragma_Identifier (N));
9033 end if;
9034
9035 if Nkind (P) = N_Task_Definition then
9036 Arg := Get_Pragma_Arg (Arg1);
9037 Ent := Defining_Identifier (Parent (P));
9038
9039 -- The expression must be analyzed in the special manner
9040 -- described in "Handling of Default and Per-Object
9041 -- Expressions" in sem.ads.
9042
9043 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
9044
9045 -- Check duplicate pragma before we chain the pragma in the Rep
9046 -- Item chain of Ent.
9047
9048 Check_Duplicate_Pragma (Ent);
9049 Record_Rep_Item (Ent, N);
9050
9051 -- Anything else is incorrect
9052
9053 else
9054 Pragma_Misplaced;
9055 end if;
9056 end Dispatching_Domain;
9057
9058 ---------------
9059 -- Elaborate --
9060 ---------------
9061
9062 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
9063
9064 when Pragma_Elaborate => Elaborate : declare
9065 Arg : Node_Id;
9066 Citem : Node_Id;
9067
9068 begin
9069 -- Pragma must be in context items list of a compilation unit
9070
9071 if not Is_In_Context_Clause then
9072 Pragma_Misplaced;
9073 end if;
9074
9075 -- Must be at least one argument
9076
9077 if Arg_Count = 0 then
9078 Error_Pragma ("pragma% requires at least one argument");
9079 end if;
9080
9081 -- In Ada 83 mode, there can be no items following it in the
9082 -- context list except other pragmas and implicit with clauses
9083 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
9084 -- placement rule does not apply.
9085
9086 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
9087 Citem := Next (N);
9088 while Present (Citem) loop
9089 if Nkind (Citem) = N_Pragma
9090 or else (Nkind (Citem) = N_With_Clause
9091 and then Implicit_With (Citem))
9092 then
9093 null;
9094 else
9095 Error_Pragma
9096 ("(Ada 83) pragma% must be at end of context clause");
9097 end if;
9098
9099 Next (Citem);
9100 end loop;
9101 end if;
9102
9103 -- Finally, the arguments must all be units mentioned in a with
9104 -- clause in the same context clause. Note we already checked (in
9105 -- Par.Prag) that the arguments are all identifiers or selected
9106 -- components.
9107
9108 Arg := Arg1;
9109 Outer : while Present (Arg) loop
9110 Citem := First (List_Containing (N));
9111 Inner : while Citem /= N loop
9112 if Nkind (Citem) = N_With_Clause
9113 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
9114 then
9115 Set_Elaborate_Present (Citem, True);
9116 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
9117 Generate_Reference (Entity (Name (Citem)), Citem);
9118
9119 -- With the pragma present, elaboration calls on
9120 -- subprograms from the named unit need no further
9121 -- checks, as long as the pragma appears in the current
9122 -- compilation unit. If the pragma appears in some unit
9123 -- in the context, there might still be a need for an
9124 -- Elaborate_All_Desirable from the current compilation
9125 -- to the named unit, so we keep the check enabled.
9126
9127 if In_Extended_Main_Source_Unit (N) then
9128 Set_Suppress_Elaboration_Warnings
9129 (Entity (Name (Citem)));
9130 end if;
9131
9132 exit Inner;
9133 end if;
9134
9135 Next (Citem);
9136 end loop Inner;
9137
9138 if Citem = N then
9139 Error_Pragma_Arg
9140 ("argument of pragma% is not withed unit", Arg);
9141 end if;
9142
9143 Next (Arg);
9144 end loop Outer;
9145
9146 -- Give a warning if operating in static mode with -gnatwl
9147 -- (elaboration warnings enabled) switch set.
9148
9149 if Elab_Warnings and not Dynamic_Elaboration_Checks then
9150 Error_Msg_N
9151 ("?l?use of pragma Elaborate may not be safe", N);
9152 Error_Msg_N
9153 ("?l?use pragma Elaborate_All instead if possible", N);
9154 end if;
9155 end Elaborate;
9156
9157 -------------------
9158 -- Elaborate_All --
9159 -------------------
9160
9161 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
9162
9163 when Pragma_Elaborate_All => Elaborate_All : declare
9164 Arg : Node_Id;
9165 Citem : Node_Id;
9166
9167 begin
9168 Check_Ada_83_Warning;
9169
9170 -- Pragma must be in context items list of a compilation unit
9171
9172 if not Is_In_Context_Clause then
9173 Pragma_Misplaced;
9174 end if;
9175
9176 -- Must be at least one argument
9177
9178 if Arg_Count = 0 then
9179 Error_Pragma ("pragma% requires at least one argument");
9180 end if;
9181
9182 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
9183 -- have to appear at the end of the context clause, but may
9184 -- appear mixed in with other items, even in Ada 83 mode.
9185
9186 -- Final check: the arguments must all be units mentioned in
9187 -- a with clause in the same context clause. Note that we
9188 -- already checked (in Par.Prag) that all the arguments are
9189 -- either identifiers or selected components.
9190
9191 Arg := Arg1;
9192 Outr : while Present (Arg) loop
9193 Citem := First (List_Containing (N));
9194 Innr : while Citem /= N loop
9195 if Nkind (Citem) = N_With_Clause
9196 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
9197 then
9198 Set_Elaborate_All_Present (Citem, True);
9199 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
9200
9201 -- Suppress warnings and elaboration checks on the named
9202 -- unit if the pragma is in the current compilation, as
9203 -- for pragma Elaborate.
9204
9205 if In_Extended_Main_Source_Unit (N) then
9206 Set_Suppress_Elaboration_Warnings
9207 (Entity (Name (Citem)));
9208 end if;
9209 exit Innr;
9210 end if;
9211
9212 Next (Citem);
9213 end loop Innr;
9214
9215 if Citem = N then
9216 Set_Error_Posted (N);
9217 Error_Pragma_Arg
9218 ("argument of pragma% is not withed unit", Arg);
9219 end if;
9220
9221 Next (Arg);
9222 end loop Outr;
9223 end Elaborate_All;
9224
9225 --------------------
9226 -- Elaborate_Body --
9227 --------------------
9228
9229 -- pragma Elaborate_Body [( library_unit_NAME )];
9230
9231 when Pragma_Elaborate_Body => Elaborate_Body : declare
9232 Cunit_Node : Node_Id;
9233 Cunit_Ent : Entity_Id;
9234
9235 begin
9236 Check_Ada_83_Warning;
9237 Check_Valid_Library_Unit_Pragma;
9238
9239 if Nkind (N) = N_Null_Statement then
9240 return;
9241 end if;
9242
9243 Cunit_Node := Cunit (Current_Sem_Unit);
9244 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
9245
9246 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
9247 N_Subprogram_Body)
9248 then
9249 Error_Pragma ("pragma% must refer to a spec, not a body");
9250 else
9251 Set_Body_Required (Cunit_Node, True);
9252 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
9253
9254 -- If we are in dynamic elaboration mode, then we suppress
9255 -- elaboration warnings for the unit, since it is definitely
9256 -- fine NOT to do dynamic checks at the first level (and such
9257 -- checks will be suppressed because no elaboration boolean
9258 -- is created for Elaborate_Body packages).
9259
9260 -- But in the static model of elaboration, Elaborate_Body is
9261 -- definitely NOT good enough to ensure elaboration safety on
9262 -- its own, since the body may WITH other units that are not
9263 -- safe from an elaboration point of view, so a client must
9264 -- still do an Elaborate_All on such units.
9265
9266 -- Debug flag -gnatdD restores the old behavior of 3.13, where
9267 -- Elaborate_Body always suppressed elab warnings.
9268
9269 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
9270 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
9271 end if;
9272 end if;
9273 end Elaborate_Body;
9274
9275 ------------------------
9276 -- Elaboration_Checks --
9277 ------------------------
9278
9279 -- pragma Elaboration_Checks (Static | Dynamic);
9280
9281 when Pragma_Elaboration_Checks =>
9282 GNAT_Pragma;
9283 Check_Arg_Count (1);
9284 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
9285 Dynamic_Elaboration_Checks :=
9286 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
9287
9288 ---------------
9289 -- Eliminate --
9290 ---------------
9291
9292 -- pragma Eliminate (
9293 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
9294 -- [,[Entity =>] IDENTIFIER |
9295 -- SELECTED_COMPONENT |
9296 -- STRING_LITERAL]
9297 -- [, OVERLOADING_RESOLUTION]);
9298
9299 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
9300 -- SOURCE_LOCATION
9301
9302 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
9303 -- FUNCTION_PROFILE
9304
9305 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
9306
9307 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
9308 -- Result_Type => result_SUBTYPE_NAME]
9309
9310 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
9311 -- SUBTYPE_NAME ::= STRING_LITERAL
9312
9313 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
9314 -- SOURCE_TRACE ::= STRING_LITERAL
9315
9316 when Pragma_Eliminate => Eliminate : declare
9317 Args : Args_List (1 .. 5);
9318 Names : constant Name_List (1 .. 5) := (
9319 Name_Unit_Name,
9320 Name_Entity,
9321 Name_Parameter_Types,
9322 Name_Result_Type,
9323 Name_Source_Location);
9324
9325 Unit_Name : Node_Id renames Args (1);
9326 Entity : Node_Id renames Args (2);
9327 Parameter_Types : Node_Id renames Args (3);
9328 Result_Type : Node_Id renames Args (4);
9329 Source_Location : Node_Id renames Args (5);
9330
9331 begin
9332 GNAT_Pragma;
9333 Check_Valid_Configuration_Pragma;
9334 Gather_Associations (Names, Args);
9335
9336 if No (Unit_Name) then
9337 Error_Pragma ("missing Unit_Name argument for pragma%");
9338 end if;
9339
9340 if No (Entity)
9341 and then (Present (Parameter_Types)
9342 or else
9343 Present (Result_Type)
9344 or else
9345 Present (Source_Location))
9346 then
9347 Error_Pragma ("missing Entity argument for pragma%");
9348 end if;
9349
9350 if (Present (Parameter_Types)
9351 or else
9352 Present (Result_Type))
9353 and then
9354 Present (Source_Location)
9355 then
9356 Error_Pragma
9357 ("parameter profile and source location cannot " &
9358 "be used together in pragma%");
9359 end if;
9360
9361 Process_Eliminate_Pragma
9362 (N,
9363 Unit_Name,
9364 Entity,
9365 Parameter_Types,
9366 Result_Type,
9367 Source_Location);
9368 end Eliminate;
9369
9370 -----------------------------------
9371 -- Enable_Atomic_Synchronization --
9372 -----------------------------------
9373
9374 -- pragma Enable_Atomic_Synchronization [(Entity)];
9375
9376 when Pragma_Enable_Atomic_Synchronization =>
9377 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
9378
9379 ------------
9380 -- Export --
9381 ------------
9382
9383 -- pragma Export (
9384 -- [ Convention =>] convention_IDENTIFIER,
9385 -- [ Entity =>] local_NAME
9386 -- [, [External_Name =>] static_string_EXPRESSION ]
9387 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9388
9389 when Pragma_Export => Export : declare
9390 C : Convention_Id;
9391 Def_Id : Entity_Id;
9392
9393 pragma Warnings (Off, C);
9394
9395 begin
9396 Check_Ada_83_Warning;
9397 Check_Arg_Order
9398 ((Name_Convention,
9399 Name_Entity,
9400 Name_External_Name,
9401 Name_Link_Name));
9402
9403 Check_At_Least_N_Arguments (2);
9404
9405 Check_At_Most_N_Arguments (4);
9406 Process_Convention (C, Def_Id);
9407
9408 if Ekind (Def_Id) /= E_Constant then
9409 Note_Possible_Modification
9410 (Get_Pragma_Arg (Arg2), Sure => False);
9411 end if;
9412
9413 Process_Interface_Name (Def_Id, Arg3, Arg4);
9414 Set_Exported (Def_Id, Arg2);
9415
9416 -- If the entity is a deferred constant, propagate the information
9417 -- to the full view, because gigi elaborates the full view only.
9418
9419 if Ekind (Def_Id) = E_Constant
9420 and then Present (Full_View (Def_Id))
9421 then
9422 declare
9423 Id2 : constant Entity_Id := Full_View (Def_Id);
9424 begin
9425 Set_Is_Exported (Id2, Is_Exported (Def_Id));
9426 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
9427 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
9428 end;
9429 end if;
9430 end Export;
9431
9432 ----------------------
9433 -- Export_Exception --
9434 ----------------------
9435
9436 -- pragma Export_Exception (
9437 -- [Internal =>] LOCAL_NAME
9438 -- [, [External =>] EXTERNAL_SYMBOL]
9439 -- [, [Form =>] Ada | VMS]
9440 -- [, [Code =>] static_integer_EXPRESSION]);
9441
9442 when Pragma_Export_Exception => Export_Exception : declare
9443 Args : Args_List (1 .. 4);
9444 Names : constant Name_List (1 .. 4) := (
9445 Name_Internal,
9446 Name_External,
9447 Name_Form,
9448 Name_Code);
9449
9450 Internal : Node_Id renames Args (1);
9451 External : Node_Id renames Args (2);
9452 Form : Node_Id renames Args (3);
9453 Code : Node_Id renames Args (4);
9454
9455 begin
9456 GNAT_Pragma;
9457
9458 if Inside_A_Generic then
9459 Error_Pragma ("pragma% cannot be used for generic entities");
9460 end if;
9461
9462 Gather_Associations (Names, Args);
9463 Process_Extended_Import_Export_Exception_Pragma (
9464 Arg_Internal => Internal,
9465 Arg_External => External,
9466 Arg_Form => Form,
9467 Arg_Code => Code);
9468
9469 if not Is_VMS_Exception (Entity (Internal)) then
9470 Set_Exported (Entity (Internal), Internal);
9471 end if;
9472 end Export_Exception;
9473
9474 ---------------------
9475 -- Export_Function --
9476 ---------------------
9477
9478 -- pragma Export_Function (
9479 -- [Internal =>] LOCAL_NAME
9480 -- [, [External =>] EXTERNAL_SYMBOL]
9481 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9482 -- [, [Result_Type =>] TYPE_DESIGNATOR]
9483 -- [, [Mechanism =>] MECHANISM]
9484 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
9485
9486 -- EXTERNAL_SYMBOL ::=
9487 -- IDENTIFIER
9488 -- | static_string_EXPRESSION
9489
9490 -- PARAMETER_TYPES ::=
9491 -- null
9492 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9493
9494 -- TYPE_DESIGNATOR ::=
9495 -- subtype_NAME
9496 -- | subtype_Name ' Access
9497
9498 -- MECHANISM ::=
9499 -- MECHANISM_NAME
9500 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9501
9502 -- MECHANISM_ASSOCIATION ::=
9503 -- [formal_parameter_NAME =>] MECHANISM_NAME
9504
9505 -- MECHANISM_NAME ::=
9506 -- Value
9507 -- | Reference
9508 -- | Descriptor [([Class =>] CLASS_NAME)]
9509
9510 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9511
9512 when Pragma_Export_Function => Export_Function : declare
9513 Args : Args_List (1 .. 6);
9514 Names : constant Name_List (1 .. 6) := (
9515 Name_Internal,
9516 Name_External,
9517 Name_Parameter_Types,
9518 Name_Result_Type,
9519 Name_Mechanism,
9520 Name_Result_Mechanism);
9521
9522 Internal : Node_Id renames Args (1);
9523 External : Node_Id renames Args (2);
9524 Parameter_Types : Node_Id renames Args (3);
9525 Result_Type : Node_Id renames Args (4);
9526 Mechanism : Node_Id renames Args (5);
9527 Result_Mechanism : Node_Id renames Args (6);
9528
9529 begin
9530 GNAT_Pragma;
9531 Gather_Associations (Names, Args);
9532 Process_Extended_Import_Export_Subprogram_Pragma (
9533 Arg_Internal => Internal,
9534 Arg_External => External,
9535 Arg_Parameter_Types => Parameter_Types,
9536 Arg_Result_Type => Result_Type,
9537 Arg_Mechanism => Mechanism,
9538 Arg_Result_Mechanism => Result_Mechanism);
9539 end Export_Function;
9540
9541 -------------------
9542 -- Export_Object --
9543 -------------------
9544
9545 -- pragma Export_Object (
9546 -- [Internal =>] LOCAL_NAME
9547 -- [, [External =>] EXTERNAL_SYMBOL]
9548 -- [, [Size =>] EXTERNAL_SYMBOL]);
9549
9550 -- EXTERNAL_SYMBOL ::=
9551 -- IDENTIFIER
9552 -- | static_string_EXPRESSION
9553
9554 -- PARAMETER_TYPES ::=
9555 -- null
9556 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9557
9558 -- TYPE_DESIGNATOR ::=
9559 -- subtype_NAME
9560 -- | subtype_Name ' Access
9561
9562 -- MECHANISM ::=
9563 -- MECHANISM_NAME
9564 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9565
9566 -- MECHANISM_ASSOCIATION ::=
9567 -- [formal_parameter_NAME =>] MECHANISM_NAME
9568
9569 -- MECHANISM_NAME ::=
9570 -- Value
9571 -- | Reference
9572 -- | Descriptor [([Class =>] CLASS_NAME)]
9573
9574 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9575
9576 when Pragma_Export_Object => Export_Object : declare
9577 Args : Args_List (1 .. 3);
9578 Names : constant Name_List (1 .. 3) := (
9579 Name_Internal,
9580 Name_External,
9581 Name_Size);
9582
9583 Internal : Node_Id renames Args (1);
9584 External : Node_Id renames Args (2);
9585 Size : Node_Id renames Args (3);
9586
9587 begin
9588 GNAT_Pragma;
9589 Gather_Associations (Names, Args);
9590 Process_Extended_Import_Export_Object_Pragma (
9591 Arg_Internal => Internal,
9592 Arg_External => External,
9593 Arg_Size => Size);
9594 end Export_Object;
9595
9596 ----------------------
9597 -- Export_Procedure --
9598 ----------------------
9599
9600 -- pragma Export_Procedure (
9601 -- [Internal =>] LOCAL_NAME
9602 -- [, [External =>] EXTERNAL_SYMBOL]
9603 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9604 -- [, [Mechanism =>] MECHANISM]);
9605
9606 -- EXTERNAL_SYMBOL ::=
9607 -- IDENTIFIER
9608 -- | static_string_EXPRESSION
9609
9610 -- PARAMETER_TYPES ::=
9611 -- null
9612 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9613
9614 -- TYPE_DESIGNATOR ::=
9615 -- subtype_NAME
9616 -- | subtype_Name ' Access
9617
9618 -- MECHANISM ::=
9619 -- MECHANISM_NAME
9620 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9621
9622 -- MECHANISM_ASSOCIATION ::=
9623 -- [formal_parameter_NAME =>] MECHANISM_NAME
9624
9625 -- MECHANISM_NAME ::=
9626 -- Value
9627 -- | Reference
9628 -- | Descriptor [([Class =>] CLASS_NAME)]
9629
9630 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9631
9632 when Pragma_Export_Procedure => Export_Procedure : declare
9633 Args : Args_List (1 .. 4);
9634 Names : constant Name_List (1 .. 4) := (
9635 Name_Internal,
9636 Name_External,
9637 Name_Parameter_Types,
9638 Name_Mechanism);
9639
9640 Internal : Node_Id renames Args (1);
9641 External : Node_Id renames Args (2);
9642 Parameter_Types : Node_Id renames Args (3);
9643 Mechanism : Node_Id renames Args (4);
9644
9645 begin
9646 GNAT_Pragma;
9647 Gather_Associations (Names, Args);
9648 Process_Extended_Import_Export_Subprogram_Pragma (
9649 Arg_Internal => Internal,
9650 Arg_External => External,
9651 Arg_Parameter_Types => Parameter_Types,
9652 Arg_Mechanism => Mechanism);
9653 end Export_Procedure;
9654
9655 ------------------
9656 -- Export_Value --
9657 ------------------
9658
9659 -- pragma Export_Value (
9660 -- [Value =>] static_integer_EXPRESSION,
9661 -- [Link_Name =>] static_string_EXPRESSION);
9662
9663 when Pragma_Export_Value =>
9664 GNAT_Pragma;
9665 Check_Arg_Order ((Name_Value, Name_Link_Name));
9666 Check_Arg_Count (2);
9667
9668 Check_Optional_Identifier (Arg1, Name_Value);
9669 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9670
9671 Check_Optional_Identifier (Arg2, Name_Link_Name);
9672 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9673
9674 -----------------------------
9675 -- Export_Valued_Procedure --
9676 -----------------------------
9677
9678 -- pragma Export_Valued_Procedure (
9679 -- [Internal =>] LOCAL_NAME
9680 -- [, [External =>] EXTERNAL_SYMBOL,]
9681 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9682 -- [, [Mechanism =>] MECHANISM]);
9683
9684 -- EXTERNAL_SYMBOL ::=
9685 -- IDENTIFIER
9686 -- | static_string_EXPRESSION
9687
9688 -- PARAMETER_TYPES ::=
9689 -- null
9690 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9691
9692 -- TYPE_DESIGNATOR ::=
9693 -- subtype_NAME
9694 -- | subtype_Name ' Access
9695
9696 -- MECHANISM ::=
9697 -- MECHANISM_NAME
9698 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9699
9700 -- MECHANISM_ASSOCIATION ::=
9701 -- [formal_parameter_NAME =>] MECHANISM_NAME
9702
9703 -- MECHANISM_NAME ::=
9704 -- Value
9705 -- | Reference
9706 -- | Descriptor [([Class =>] CLASS_NAME)]
9707
9708 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9709
9710 when Pragma_Export_Valued_Procedure =>
9711 Export_Valued_Procedure : declare
9712 Args : Args_List (1 .. 4);
9713 Names : constant Name_List (1 .. 4) := (
9714 Name_Internal,
9715 Name_External,
9716 Name_Parameter_Types,
9717 Name_Mechanism);
9718
9719 Internal : Node_Id renames Args (1);
9720 External : Node_Id renames Args (2);
9721 Parameter_Types : Node_Id renames Args (3);
9722 Mechanism : Node_Id renames Args (4);
9723
9724 begin
9725 GNAT_Pragma;
9726 Gather_Associations (Names, Args);
9727 Process_Extended_Import_Export_Subprogram_Pragma (
9728 Arg_Internal => Internal,
9729 Arg_External => External,
9730 Arg_Parameter_Types => Parameter_Types,
9731 Arg_Mechanism => Mechanism);
9732 end Export_Valued_Procedure;
9733
9734 -------------------
9735 -- Extend_System --
9736 -------------------
9737
9738 -- pragma Extend_System ([Name =>] Identifier);
9739
9740 when Pragma_Extend_System => Extend_System : declare
9741 begin
9742 GNAT_Pragma;
9743 Check_Valid_Configuration_Pragma;
9744 Check_Arg_Count (1);
9745 Check_Optional_Identifier (Arg1, Name_Name);
9746 Check_Arg_Is_Identifier (Arg1);
9747
9748 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
9749
9750 if Name_Len > 4
9751 and then Name_Buffer (1 .. 4) = "aux_"
9752 then
9753 if Present (System_Extend_Pragma_Arg) then
9754 if Chars (Get_Pragma_Arg (Arg1)) =
9755 Chars (Expression (System_Extend_Pragma_Arg))
9756 then
9757 null;
9758 else
9759 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
9760 Error_Pragma ("pragma% conflicts with that #");
9761 end if;
9762
9763 else
9764 System_Extend_Pragma_Arg := Arg1;
9765
9766 if not GNAT_Mode then
9767 System_Extend_Unit := Arg1;
9768 end if;
9769 end if;
9770 else
9771 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
9772 end if;
9773 end Extend_System;
9774
9775 ------------------------
9776 -- Extensions_Allowed --
9777 ------------------------
9778
9779 -- pragma Extensions_Allowed (ON | OFF);
9780
9781 when Pragma_Extensions_Allowed =>
9782 GNAT_Pragma;
9783 Check_Arg_Count (1);
9784 Check_No_Identifiers;
9785 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9786
9787 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
9788 Extensions_Allowed := True;
9789 Ada_Version := Ada_Version_Type'Last;
9790
9791 else
9792 Extensions_Allowed := False;
9793 Ada_Version := Ada_Version_Explicit;
9794 end if;
9795
9796 --------------
9797 -- External --
9798 --------------
9799
9800 -- pragma External (
9801 -- [ Convention =>] convention_IDENTIFIER,
9802 -- [ Entity =>] local_NAME
9803 -- [, [External_Name =>] static_string_EXPRESSION ]
9804 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9805
9806 when Pragma_External => External : declare
9807 Def_Id : Entity_Id;
9808
9809 C : Convention_Id;
9810 pragma Warnings (Off, C);
9811
9812 begin
9813 GNAT_Pragma;
9814 Check_Arg_Order
9815 ((Name_Convention,
9816 Name_Entity,
9817 Name_External_Name,
9818 Name_Link_Name));
9819 Check_At_Least_N_Arguments (2);
9820 Check_At_Most_N_Arguments (4);
9821 Process_Convention (C, Def_Id);
9822 Note_Possible_Modification
9823 (Get_Pragma_Arg (Arg2), Sure => False);
9824 Process_Interface_Name (Def_Id, Arg3, Arg4);
9825 Set_Exported (Def_Id, Arg2);
9826 end External;
9827
9828 --------------------------
9829 -- External_Name_Casing --
9830 --------------------------
9831
9832 -- pragma External_Name_Casing (
9833 -- UPPERCASE | LOWERCASE
9834 -- [, AS_IS | UPPERCASE | LOWERCASE]);
9835
9836 when Pragma_External_Name_Casing => External_Name_Casing : declare
9837 begin
9838 GNAT_Pragma;
9839 Check_No_Identifiers;
9840
9841 if Arg_Count = 2 then
9842 Check_Arg_Is_One_Of
9843 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
9844
9845 case Chars (Get_Pragma_Arg (Arg2)) is
9846 when Name_As_Is =>
9847 Opt.External_Name_Exp_Casing := As_Is;
9848
9849 when Name_Uppercase =>
9850 Opt.External_Name_Exp_Casing := Uppercase;
9851
9852 when Name_Lowercase =>
9853 Opt.External_Name_Exp_Casing := Lowercase;
9854
9855 when others =>
9856 null;
9857 end case;
9858
9859 else
9860 Check_Arg_Count (1);
9861 end if;
9862
9863 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
9864
9865 case Chars (Get_Pragma_Arg (Arg1)) is
9866 when Name_Uppercase =>
9867 Opt.External_Name_Imp_Casing := Uppercase;
9868
9869 when Name_Lowercase =>
9870 Opt.External_Name_Imp_Casing := Lowercase;
9871
9872 when others =>
9873 null;
9874 end case;
9875 end External_Name_Casing;
9876
9877 --------------------------
9878 -- Favor_Top_Level --
9879 --------------------------
9880
9881 -- pragma Favor_Top_Level (type_NAME);
9882
9883 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
9884 Named_Entity : Entity_Id;
9885
9886 begin
9887 GNAT_Pragma;
9888 Check_No_Identifiers;
9889 Check_Arg_Count (1);
9890 Check_Arg_Is_Local_Name (Arg1);
9891 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
9892
9893 -- If it's an access-to-subprogram type (in particular, not a
9894 -- subtype), set the flag on that type.
9895
9896 if Is_Access_Subprogram_Type (Named_Entity) then
9897 Set_Can_Use_Internal_Rep (Named_Entity, False);
9898
9899 -- Otherwise it's an error (name denotes the wrong sort of entity)
9900
9901 else
9902 Error_Pragma_Arg
9903 ("access-to-subprogram type expected",
9904 Get_Pragma_Arg (Arg1));
9905 end if;
9906 end Favor_Top_Level;
9907
9908 ---------------
9909 -- Fast_Math --
9910 ---------------
9911
9912 -- pragma Fast_Math;
9913
9914 when Pragma_Fast_Math =>
9915 GNAT_Pragma;
9916 Check_No_Identifiers;
9917 Check_Valid_Configuration_Pragma;
9918 Fast_Math := True;
9919
9920 ---------------------------
9921 -- Finalize_Storage_Only --
9922 ---------------------------
9923
9924 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9925
9926 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
9927 Assoc : constant Node_Id := Arg1;
9928 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
9929 Typ : Entity_Id;
9930
9931 begin
9932 GNAT_Pragma;
9933 Check_No_Identifiers;
9934 Check_Arg_Count (1);
9935 Check_Arg_Is_Local_Name (Arg1);
9936
9937 Find_Type (Type_Id);
9938 Typ := Entity (Type_Id);
9939
9940 if Typ = Any_Type
9941 or else Rep_Item_Too_Early (Typ, N)
9942 then
9943 return;
9944 else
9945 Typ := Underlying_Type (Typ);
9946 end if;
9947
9948 if not Is_Controlled (Typ) then
9949 Error_Pragma ("pragma% must specify controlled type");
9950 end if;
9951
9952 Check_First_Subtype (Arg1);
9953
9954 if Finalize_Storage_Only (Typ) then
9955 Error_Pragma ("duplicate pragma%, only one allowed");
9956
9957 elsif not Rep_Item_Too_Late (Typ, N) then
9958 Set_Finalize_Storage_Only (Base_Type (Typ), True);
9959 end if;
9960 end Finalize_Storage;
9961
9962 --------------------------
9963 -- Float_Representation --
9964 --------------------------
9965
9966 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9967
9968 -- FLOAT_REP ::= VAX_Float | IEEE_Float
9969
9970 when Pragma_Float_Representation => Float_Representation : declare
9971 Argx : Node_Id;
9972 Digs : Nat;
9973 Ent : Entity_Id;
9974
9975 begin
9976 GNAT_Pragma;
9977
9978 if Arg_Count = 1 then
9979 Check_Valid_Configuration_Pragma;
9980 else
9981 Check_Arg_Count (2);
9982 Check_Optional_Identifier (Arg2, Name_Entity);
9983 Check_Arg_Is_Local_Name (Arg2);
9984 end if;
9985
9986 Check_No_Identifier (Arg1);
9987 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9988
9989 if not OpenVMS_On_Target then
9990 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9991 Error_Pragma
9992 ("??pragma% ignored (applies only to Open'V'M'S)");
9993 end if;
9994
9995 return;
9996 end if;
9997
9998 -- One argument case
9999
10000 if Arg_Count = 1 then
10001 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
10002 if Opt.Float_Format = 'I' then
10003 Error_Pragma ("'I'E'E'E format previously specified");
10004 end if;
10005
10006 Opt.Float_Format := 'V';
10007
10008 else
10009 if Opt.Float_Format = 'V' then
10010 Error_Pragma ("'V'A'X format previously specified");
10011 end if;
10012
10013 Opt.Float_Format := 'I';
10014 end if;
10015
10016 Set_Standard_Fpt_Formats;
10017
10018 -- Two argument case
10019
10020 else
10021 Argx := Get_Pragma_Arg (Arg2);
10022
10023 if not Is_Entity_Name (Argx)
10024 or else not Is_Floating_Point_Type (Entity (Argx))
10025 then
10026 Error_Pragma_Arg
10027 ("second argument of% pragma must be floating-point type",
10028 Arg2);
10029 end if;
10030
10031 Ent := Entity (Argx);
10032 Digs := UI_To_Int (Digits_Value (Ent));
10033
10034 -- Two arguments, VAX_Float case
10035
10036 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
10037 case Digs is
10038 when 6 => Set_F_Float (Ent);
10039 when 9 => Set_D_Float (Ent);
10040 when 15 => Set_G_Float (Ent);
10041
10042 when others =>
10043 Error_Pragma_Arg
10044 ("wrong digits value, must be 6,9 or 15", Arg2);
10045 end case;
10046
10047 -- Two arguments, IEEE_Float case
10048
10049 else
10050 case Digs is
10051 when 6 => Set_IEEE_Short (Ent);
10052 when 15 => Set_IEEE_Long (Ent);
10053
10054 when others =>
10055 Error_Pragma_Arg
10056 ("wrong digits value, must be 6 or 15", Arg2);
10057 end case;
10058 end if;
10059 end if;
10060 end Float_Representation;
10061
10062 ------------
10063 -- Global --
10064 ------------
10065
10066 -- pragma Global (GLOBAL_SPECIFICATION)
10067
10068 -- GLOBAL_SPECIFICATION ::= MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
10069 -- | GLOBAL_LIST
10070 -- | null
10071 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
10072 -- MODE_SELECTOR ::= Input | Output | In_Out | Contract_In
10073 -- GLOBAL_LIST ::= GLOBAL_ITEM
10074 -- | (GLOBAL_ITEM {, GLOBAL_ITEM})
10075 -- GLOBAL_ITEM ::= NAME
10076
10077 when Pragma_Global => Global : declare
10078 Subp_Id : Entity_Id;
10079
10080 Seen : Elist_Id := No_Elist;
10081 -- A list containing the entities of all the items processed so
10082 -- far. It plays a role in detecting distinct entities.
10083
10084 -- Flags used to verify the consistency of modes
10085
10086 Contract_Seen : Boolean := False;
10087 In_Out_Seen : Boolean := False;
10088 Input_Seen : Boolean := False;
10089 Output_Seen : Boolean := False;
10090
10091 procedure Analyze_Global_List
10092 (List : Node_Id;
10093 Global_Mode : Name_Id := Name_Input);
10094 -- Verify the legality of a single global list declaration.
10095 -- Global_Mode denotes the current mode in effect.
10096
10097 -------------------------
10098 -- Analyze_Global_List --
10099 -------------------------
10100
10101 procedure Analyze_Global_List
10102 (List : Node_Id;
10103 Global_Mode : Name_Id := Name_Input)
10104 is
10105 procedure Analyze_Global_Item
10106 (Item : Node_Id;
10107 Global_Mode : Name_Id);
10108 -- Verify the legality of a single global item declaration.
10109 -- Global_Mode denotes the current mode in effect.
10110
10111 procedure Check_Duplicate_Mode
10112 (Mode : Node_Id;
10113 Status : in out Boolean);
10114 -- Flag Status denotes whether a particular mode has been seen
10115 -- while processing a global list. This routine verifies that
10116 -- Mode is not a duplicate mode and sets the flag Status.
10117
10118 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
10119 -- Mode denotes either In_Out or Output. Depending on the kind
10120 -- of the related subprogram, emit an error if those two modes
10121 -- apply to a function.
10122
10123 -------------------------
10124 -- Analyze_Global_Item --
10125 -------------------------
10126
10127 procedure Analyze_Global_Item
10128 (Item : Node_Id;
10129 Global_Mode : Name_Id)
10130 is
10131 function Is_Duplicate_Item (Id : Entity_Id) return Boolean;
10132 -- Determine whether Id has already been processed
10133
10134 -----------------------
10135 -- Is_Duplicate_Item --
10136 -----------------------
10137
10138 function Is_Duplicate_Item (Id : Entity_Id) return Boolean is
10139 Item_Elmt : Elmt_Id;
10140
10141 begin
10142 if Present (Seen) then
10143 Item_Elmt := First_Elmt (Seen);
10144 while Present (Item_Elmt) loop
10145 if Node (Item_Elmt) = Id then
10146 return True;
10147 end if;
10148
10149 Next_Elmt (Item_Elmt);
10150 end loop;
10151 end if;
10152
10153 return False;
10154 end Is_Duplicate_Item;
10155
10156 -- Local declarations
10157
10158 Id : Entity_Id;
10159
10160 -- Start of processing for Analyze_Global_Item
10161
10162 begin
10163 -- Detect one of the following cases
10164
10165 -- with Global => (null, Name)
10166 -- with Global => (Name_1, null, Name_2)
10167 -- with Global => (Name, null)
10168
10169 if Nkind (Item) = N_Null then
10170 Error_Msg_N
10171 ("cannot mix null and non-null global items", Item);
10172 return;
10173 end if;
10174
10175 Analyze (Item);
10176
10177 if Is_Entity_Name (Item) then
10178 Id := Entity (Item);
10179
10180 -- A global item cannot reference a formal parameter. Do
10181 -- this check first to provide a better error diagnostic.
10182
10183 if Is_Formal (Id) then
10184 Error_Msg_N
10185 ("global item cannot reference formal parameter",
10186 Item);
10187 return;
10188
10189 -- The only legal references are those to abstract states
10190 -- and variables.
10191
10192 elsif not Ekind_In (Entity (Item), E_Abstract_State,
10193 E_Variable)
10194 then
10195 Error_Msg_N
10196 ("global item must denote variable or state", Item);
10197 return;
10198 end if;
10199
10200 -- Some form of illegal construct masquerading as a name
10201
10202 else
10203 Error_Msg_N
10204 ("global item must denote variable or state", Item);
10205 return;
10206 end if;
10207
10208 -- The same entity might be referenced through various way.
10209 -- Check the entity of the item rather than the item itself.
10210
10211 if Is_Duplicate_Item (Id) then
10212 Error_Msg_N ("duplicate global item", Item);
10213
10214 -- Add the entity of the current item to the list of
10215 -- processed items.
10216
10217 else
10218 if No (Seen) then
10219 Seen := New_Elmt_List;
10220 end if;
10221
10222 Append_Elmt (Id, Seen);
10223 end if;
10224
10225 if Ekind (Id) = E_Abstract_State
10226 and then Is_Volatile_State (Id)
10227 then
10228 -- A global item of mode In_Out or Output cannot denote a
10229 -- volatile Input state.
10230
10231 if Is_Input_State (Id)
10232 and then (Global_Mode = Name_In_Out
10233 or else
10234 Global_Mode = Name_Output)
10235 then
10236 Error_Msg_N
10237 ("global item of mode In_Out or Output cannot " &
10238 "reference Volatile Input state", Item);
10239
10240 -- A global item of mode In_Out or Input cannot reference
10241 -- a volatile Output state.
10242
10243 elsif Is_Output_State (Id)
10244 and then (Global_Mode = Name_In_Out
10245 or else
10246 Global_Mode = Name_Input)
10247 then
10248 Error_Msg_N
10249 ("global item of mode In_Out or Input cannot "
10250 & "reference Volatile Output state", Item);
10251 end if;
10252 end if;
10253 end Analyze_Global_Item;
10254
10255 --------------------------
10256 -- Check_Duplicate_Mode --
10257 --------------------------
10258
10259 procedure Check_Duplicate_Mode
10260 (Mode : Node_Id;
10261 Status : in out Boolean)
10262 is
10263 begin
10264 if Status then
10265 Error_Msg_N ("duplicate global mode", Mode);
10266 end if;
10267
10268 Status := True;
10269 end Check_Duplicate_Mode;
10270
10271 ----------------------------------------
10272 -- Check_Mode_Restriction_In_Function --
10273 ----------------------------------------
10274
10275 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
10276 begin
10277 if Ekind (Subp_Id) = E_Function then
10278 Error_Msg_Name_1 := Chars (Mode);
10279 Error_Msg_N
10280 ("global mode % not applicable to functions", Mode);
10281 end if;
10282 end Check_Mode_Restriction_In_Function;
10283
10284 -- Local variables
10285
10286 Assoc : Node_Id;
10287 Item : Node_Id;
10288 Mode : Node_Id;
10289
10290 -- Start of processing for Analyze_Global_List
10291
10292 begin
10293 -- Single global item declaration
10294
10295 if Nkind_In (List, N_Identifier, N_Selected_Component) then
10296 Analyze_Global_Item (List, Global_Mode);
10297
10298 -- Simple global list or moded global list declaration
10299
10300 elsif Nkind (List) = N_Aggregate then
10301
10302 -- The declaration of a simple global list appear as a
10303 -- collection of expressions.
10304
10305 if Present (Expressions (List)) then
10306 if Present (Component_Associations (List)) then
10307 Error_Msg_N
10308 ("cannot mix moded and non-moded global lists",
10309 List);
10310 end if;
10311
10312 Item := First (Expressions (List));
10313 while Present (Item) loop
10314 Analyze_Global_Item (Item, Global_Mode);
10315
10316 Next (Item);
10317 end loop;
10318
10319 -- The declaration of a moded global list appears as a
10320 -- collection of component associations where individual
10321 -- choices denote modes.
10322
10323 elsif Present (Component_Associations (List)) then
10324 if Present (Expressions (List)) then
10325 Error_Msg_N
10326 ("cannot mix moded and non-moded global lists",
10327 List);
10328 end if;
10329
10330 Assoc := First (Component_Associations (List));
10331 while Present (Assoc) loop
10332 Mode := First (Choices (Assoc));
10333
10334 if Nkind (Mode) = N_Identifier then
10335 if Chars (Mode) = Name_Contract_In then
10336 Check_Duplicate_Mode (Mode, Contract_Seen);
10337
10338 elsif Chars (Mode) = Name_In_Out then
10339 Check_Duplicate_Mode (Mode, In_Out_Seen);
10340 Check_Mode_Restriction_In_Function (Mode);
10341
10342 elsif Chars (Mode) = Name_Input then
10343 Check_Duplicate_Mode (Mode, Input_Seen);
10344
10345 elsif Chars (Mode) = Name_Output then
10346 Check_Duplicate_Mode (Mode, Output_Seen);
10347 Check_Mode_Restriction_In_Function (Mode);
10348
10349 else
10350 Error_Msg_N ("invalid mode selector", Mode);
10351 end if;
10352
10353 else
10354 Error_Msg_N ("invalid mode selector", Mode);
10355 end if;
10356
10357 -- Items in a moded list appear as a collection of
10358 -- expressions. Reuse the existing machinery to
10359 -- analyze them.
10360
10361 Analyze_Global_List
10362 (List => Expression (Assoc),
10363 Global_Mode => Chars (Mode));
10364
10365 Next (Assoc);
10366 end loop;
10367
10368 -- Something went horribly wrong, we have a malformed tree
10369
10370 else
10371 raise Program_Error;
10372 end if;
10373
10374 -- Any other attempt to declare a global item is erroneous
10375
10376 else
10377 Error_Msg_N ("malformed global list declaration", List);
10378 end if;
10379 end Analyze_Global_List;
10380
10381 -- Local variables
10382
10383 List : Node_Id;
10384 Subp : Node_Id;
10385
10386 -- Start of processing for Global
10387
10388 begin
10389 GNAT_Pragma;
10390 S14_Pragma;
10391 Check_Arg_Count (1);
10392
10393 -- Ensure the proper placement of the pragma. Global must be
10394 -- associated with a subprogram declaration.
10395
10396 Subp := Parent (Corresponding_Aspect (N));
10397
10398 if Nkind (Subp) /= N_Subprogram_Declaration then
10399 Pragma_Misplaced;
10400 return;
10401 end if;
10402
10403 Subp_Id := Defining_Unit_Name (Specification (Subp));
10404 List := Expression (Arg1);
10405
10406 -- There is nothing to be done for a null global list
10407
10408 if Nkind (List) = N_Null then
10409 null;
10410
10411 -- Analyze the various forms of global lists and items. Note that
10412 -- some of these may be malformed in which case the analysis emits
10413 -- error messages.
10414
10415 else
10416 -- Ensure that the formal parameters are visible when
10417 -- processing an item. This falls out of the general rule of
10418 -- aspects pertaining to subprogram declarations.
10419
10420 Push_Scope (Subp_Id);
10421 Install_Formals (Subp_Id);
10422
10423 Analyze_Global_List (List);
10424
10425 Pop_Scope;
10426 end if;
10427 end Global;
10428
10429 -----------
10430 -- Ident --
10431 -----------
10432
10433 -- pragma Ident (static_string_EXPRESSION)
10434
10435 -- Note: pragma Comment shares this processing. Pragma Comment is
10436 -- identical to Ident, except that the restriction of the argument to
10437 -- 31 characters and the placement restrictions are not enforced for
10438 -- pragma Comment.
10439
10440 when Pragma_Ident | Pragma_Comment => Ident : declare
10441 Str : Node_Id;
10442
10443 begin
10444 GNAT_Pragma;
10445 Check_Arg_Count (1);
10446 Check_No_Identifiers;
10447 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10448 Store_Note (N);
10449
10450 -- For pragma Ident, preserve DEC compatibility by requiring the
10451 -- pragma to appear in a declarative part or package spec.
10452
10453 if Prag_Id = Pragma_Ident then
10454 Check_Is_In_Decl_Part_Or_Package_Spec;
10455 end if;
10456
10457 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
10458
10459 declare
10460 CS : Node_Id;
10461 GP : Node_Id;
10462
10463 begin
10464 GP := Parent (Parent (N));
10465
10466 if Nkind_In (GP, N_Package_Declaration,
10467 N_Generic_Package_Declaration)
10468 then
10469 GP := Parent (GP);
10470 end if;
10471
10472 -- If we have a compilation unit, then record the ident value,
10473 -- checking for improper duplication.
10474
10475 if Nkind (GP) = N_Compilation_Unit then
10476 CS := Ident_String (Current_Sem_Unit);
10477
10478 if Present (CS) then
10479
10480 -- For Ident, we do not permit multiple instances
10481
10482 if Prag_Id = Pragma_Ident then
10483 Error_Pragma ("duplicate% pragma not permitted");
10484
10485 -- For Comment, we concatenate the string, unless we want
10486 -- to preserve the tree structure for ASIS.
10487
10488 elsif not ASIS_Mode then
10489 Start_String (Strval (CS));
10490 Store_String_Char (' ');
10491 Store_String_Chars (Strval (Str));
10492 Set_Strval (CS, End_String);
10493 end if;
10494
10495 else
10496 -- In VMS, the effect of IDENT is achieved by passing
10497 -- --identification=name as a --for-linker switch.
10498
10499 if OpenVMS_On_Target then
10500 Start_String;
10501 Store_String_Chars
10502 ("--for-linker=--identification=");
10503 String_To_Name_Buffer (Strval (Str));
10504 Store_String_Chars (Name_Buffer (1 .. Name_Len));
10505
10506 -- Only the last processed IDENT is saved. The main
10507 -- purpose is so an IDENT associated with a main
10508 -- procedure will be used in preference to an IDENT
10509 -- associated with a with'd package.
10510
10511 Replace_Linker_Option_String
10512 (End_String, "--for-linker=--identification=");
10513 end if;
10514
10515 Set_Ident_String (Current_Sem_Unit, Str);
10516 end if;
10517
10518 -- For subunits, we just ignore the Ident, since in GNAT these
10519 -- are not separate object files, and hence not separate units
10520 -- in the unit table.
10521
10522 elsif Nkind (GP) = N_Subunit then
10523 null;
10524
10525 -- Otherwise we have a misplaced pragma Ident, but we ignore
10526 -- this if we are in an instantiation, since it comes from
10527 -- a generic, and has no relevance to the instantiation.
10528
10529 elsif Prag_Id = Pragma_Ident then
10530 if Instantiation_Location (Loc) = No_Location then
10531 Error_Pragma ("pragma% only allowed at outer level");
10532 end if;
10533 end if;
10534 end;
10535 end Ident;
10536
10537 ----------------------------
10538 -- Implementation_Defined --
10539 ----------------------------
10540
10541 -- pragma Implementation_Defined (local_NAME);
10542
10543 -- Marks previously declared entity as implementation defined. For
10544 -- an overloaded entity, applies to the most recent homonym.
10545
10546 -- pragma Implementation_Defined;
10547
10548 -- The form with no arguments appears anywhere within a scope, most
10549 -- typically a package spec, and indicates that all entities that are
10550 -- defined within the package spec are Implementation_Defined.
10551
10552 when Pragma_Implementation_Defined => Implementation_Defined : declare
10553 Ent : Entity_Id;
10554
10555 begin
10556 Check_No_Identifiers;
10557
10558 -- Form with no arguments
10559
10560 if Arg_Count = 0 then
10561 Set_Is_Implementation_Defined (Current_Scope);
10562
10563 -- Form with one argument
10564
10565 else
10566 Check_Arg_Count (1);
10567 Check_Arg_Is_Local_Name (Arg1);
10568 Ent := Entity (Get_Pragma_Arg (Arg1));
10569 Set_Is_Implementation_Defined (Ent);
10570 end if;
10571 end Implementation_Defined;
10572
10573 -----------------
10574 -- Implemented --
10575 -----------------
10576
10577 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
10578
10579 -- IMPLEMENTATION_KIND ::=
10580 -- By_Entry | By_Protected_Procedure | By_Any | Optional
10581
10582 -- "By_Any" and "Optional" are treated as synonyms in order to
10583 -- support Ada 2012 aspect Synchronization.
10584
10585 when Pragma_Implemented => Implemented : declare
10586 Proc_Id : Entity_Id;
10587 Typ : Entity_Id;
10588
10589 begin
10590 Ada_2012_Pragma;
10591 Check_Arg_Count (2);
10592 Check_No_Identifiers;
10593 Check_Arg_Is_Identifier (Arg1);
10594 Check_Arg_Is_Local_Name (Arg1);
10595 Check_Arg_Is_One_Of (Arg2,
10596 Name_By_Any,
10597 Name_By_Entry,
10598 Name_By_Protected_Procedure,
10599 Name_Optional);
10600
10601 -- Extract the name of the local procedure
10602
10603 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
10604
10605 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
10606 -- primitive procedure of a synchronized tagged type.
10607
10608 if Ekind (Proc_Id) = E_Procedure
10609 and then Is_Primitive (Proc_Id)
10610 and then Present (First_Formal (Proc_Id))
10611 then
10612 Typ := Etype (First_Formal (Proc_Id));
10613
10614 if Is_Tagged_Type (Typ)
10615 and then
10616
10617 -- Check for a protected, a synchronized or a task interface
10618
10619 ((Is_Interface (Typ)
10620 and then Is_Synchronized_Interface (Typ))
10621
10622 -- Check for a protected type or a task type that implements
10623 -- an interface.
10624
10625 or else
10626 (Is_Concurrent_Record_Type (Typ)
10627 and then Present (Interfaces (Typ)))
10628
10629 -- Check for a private record extension with keyword
10630 -- "synchronized".
10631
10632 or else
10633 (Ekind_In (Typ, E_Record_Type_With_Private,
10634 E_Record_Subtype_With_Private)
10635 and then Synchronized_Present (Parent (Typ))))
10636 then
10637 null;
10638 else
10639 Error_Pragma_Arg
10640 ("controlling formal must be of synchronized " &
10641 "tagged type", Arg1);
10642 return;
10643 end if;
10644
10645 -- Procedures declared inside a protected type must be accepted
10646
10647 elsif Ekind (Proc_Id) = E_Procedure
10648 and then Is_Protected_Type (Scope (Proc_Id))
10649 then
10650 null;
10651
10652 -- The first argument is not a primitive procedure
10653
10654 else
10655 Error_Pragma_Arg
10656 ("pragma % must be applied to a primitive procedure", Arg1);
10657 return;
10658 end if;
10659
10660 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
10661 -- By_Protected_Procedure to the primitive procedure of a task
10662 -- interface.
10663
10664 if Chars (Arg2) = Name_By_Protected_Procedure
10665 and then Is_Interface (Typ)
10666 and then Is_Task_Interface (Typ)
10667 then
10668 Error_Pragma_Arg
10669 ("implementation kind By_Protected_Procedure cannot be " &
10670 "applied to a task interface primitive", Arg2);
10671 return;
10672 end if;
10673
10674 Record_Rep_Item (Proc_Id, N);
10675 end Implemented;
10676
10677 ----------------------
10678 -- Implicit_Packing --
10679 ----------------------
10680
10681 -- pragma Implicit_Packing;
10682
10683 when Pragma_Implicit_Packing =>
10684 GNAT_Pragma;
10685 Check_Arg_Count (0);
10686 Implicit_Packing := True;
10687
10688 ------------
10689 -- Import --
10690 ------------
10691
10692 -- pragma Import (
10693 -- [Convention =>] convention_IDENTIFIER,
10694 -- [Entity =>] local_NAME
10695 -- [, [External_Name =>] static_string_EXPRESSION ]
10696 -- [, [Link_Name =>] static_string_EXPRESSION ]);
10697
10698 when Pragma_Import =>
10699 Check_Ada_83_Warning;
10700 Check_Arg_Order
10701 ((Name_Convention,
10702 Name_Entity,
10703 Name_External_Name,
10704 Name_Link_Name));
10705
10706 Check_At_Least_N_Arguments (2);
10707 Check_At_Most_N_Arguments (4);
10708 Process_Import_Or_Interface;
10709
10710 ----------------------
10711 -- Import_Exception --
10712 ----------------------
10713
10714 -- pragma Import_Exception (
10715 -- [Internal =>] LOCAL_NAME
10716 -- [, [External =>] EXTERNAL_SYMBOL]
10717 -- [, [Form =>] Ada | VMS]
10718 -- [, [Code =>] static_integer_EXPRESSION]);
10719
10720 when Pragma_Import_Exception => Import_Exception : declare
10721 Args : Args_List (1 .. 4);
10722 Names : constant Name_List (1 .. 4) := (
10723 Name_Internal,
10724 Name_External,
10725 Name_Form,
10726 Name_Code);
10727
10728 Internal : Node_Id renames Args (1);
10729 External : Node_Id renames Args (2);
10730 Form : Node_Id renames Args (3);
10731 Code : Node_Id renames Args (4);
10732
10733 begin
10734 GNAT_Pragma;
10735 Gather_Associations (Names, Args);
10736
10737 if Present (External) and then Present (Code) then
10738 Error_Pragma
10739 ("cannot give both External and Code options for pragma%");
10740 end if;
10741
10742 Process_Extended_Import_Export_Exception_Pragma (
10743 Arg_Internal => Internal,
10744 Arg_External => External,
10745 Arg_Form => Form,
10746 Arg_Code => Code);
10747
10748 if not Is_VMS_Exception (Entity (Internal)) then
10749 Set_Imported (Entity (Internal));
10750 end if;
10751 end Import_Exception;
10752
10753 ---------------------
10754 -- Import_Function --
10755 ---------------------
10756
10757 -- pragma Import_Function (
10758 -- [Internal =>] LOCAL_NAME,
10759 -- [, [External =>] EXTERNAL_SYMBOL]
10760 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10761 -- [, [Result_Type =>] SUBTYPE_MARK]
10762 -- [, [Mechanism =>] MECHANISM]
10763 -- [, [Result_Mechanism =>] MECHANISM_NAME]
10764 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
10765
10766 -- EXTERNAL_SYMBOL ::=
10767 -- IDENTIFIER
10768 -- | static_string_EXPRESSION
10769
10770 -- PARAMETER_TYPES ::=
10771 -- null
10772 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10773
10774 -- TYPE_DESIGNATOR ::=
10775 -- subtype_NAME
10776 -- | subtype_Name ' Access
10777
10778 -- MECHANISM ::=
10779 -- MECHANISM_NAME
10780 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10781
10782 -- MECHANISM_ASSOCIATION ::=
10783 -- [formal_parameter_NAME =>] MECHANISM_NAME
10784
10785 -- MECHANISM_NAME ::=
10786 -- Value
10787 -- | Reference
10788 -- | Descriptor [([Class =>] CLASS_NAME)]
10789
10790 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10791
10792 when Pragma_Import_Function => Import_Function : declare
10793 Args : Args_List (1 .. 7);
10794 Names : constant Name_List (1 .. 7) := (
10795 Name_Internal,
10796 Name_External,
10797 Name_Parameter_Types,
10798 Name_Result_Type,
10799 Name_Mechanism,
10800 Name_Result_Mechanism,
10801 Name_First_Optional_Parameter);
10802
10803 Internal : Node_Id renames Args (1);
10804 External : Node_Id renames Args (2);
10805 Parameter_Types : Node_Id renames Args (3);
10806 Result_Type : Node_Id renames Args (4);
10807 Mechanism : Node_Id renames Args (5);
10808 Result_Mechanism : Node_Id renames Args (6);
10809 First_Optional_Parameter : Node_Id renames Args (7);
10810
10811 begin
10812 GNAT_Pragma;
10813 Gather_Associations (Names, Args);
10814 Process_Extended_Import_Export_Subprogram_Pragma (
10815 Arg_Internal => Internal,
10816 Arg_External => External,
10817 Arg_Parameter_Types => Parameter_Types,
10818 Arg_Result_Type => Result_Type,
10819 Arg_Mechanism => Mechanism,
10820 Arg_Result_Mechanism => Result_Mechanism,
10821 Arg_First_Optional_Parameter => First_Optional_Parameter);
10822 end Import_Function;
10823
10824 -------------------
10825 -- Import_Object --
10826 -------------------
10827
10828 -- pragma Import_Object (
10829 -- [Internal =>] LOCAL_NAME
10830 -- [, [External =>] EXTERNAL_SYMBOL]
10831 -- [, [Size =>] EXTERNAL_SYMBOL]);
10832
10833 -- EXTERNAL_SYMBOL ::=
10834 -- IDENTIFIER
10835 -- | static_string_EXPRESSION
10836
10837 when Pragma_Import_Object => Import_Object : declare
10838 Args : Args_List (1 .. 3);
10839 Names : constant Name_List (1 .. 3) := (
10840 Name_Internal,
10841 Name_External,
10842 Name_Size);
10843
10844 Internal : Node_Id renames Args (1);
10845 External : Node_Id renames Args (2);
10846 Size : Node_Id renames Args (3);
10847
10848 begin
10849 GNAT_Pragma;
10850 Gather_Associations (Names, Args);
10851 Process_Extended_Import_Export_Object_Pragma (
10852 Arg_Internal => Internal,
10853 Arg_External => External,
10854 Arg_Size => Size);
10855 end Import_Object;
10856
10857 ----------------------
10858 -- Import_Procedure --
10859 ----------------------
10860
10861 -- pragma Import_Procedure (
10862 -- [Internal =>] LOCAL_NAME
10863 -- [, [External =>] EXTERNAL_SYMBOL]
10864 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10865 -- [, [Mechanism =>] MECHANISM]
10866 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
10867
10868 -- EXTERNAL_SYMBOL ::=
10869 -- IDENTIFIER
10870 -- | static_string_EXPRESSION
10871
10872 -- PARAMETER_TYPES ::=
10873 -- null
10874 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10875
10876 -- TYPE_DESIGNATOR ::=
10877 -- subtype_NAME
10878 -- | subtype_Name ' Access
10879
10880 -- MECHANISM ::=
10881 -- MECHANISM_NAME
10882 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10883
10884 -- MECHANISM_ASSOCIATION ::=
10885 -- [formal_parameter_NAME =>] MECHANISM_NAME
10886
10887 -- MECHANISM_NAME ::=
10888 -- Value
10889 -- | Reference
10890 -- | Descriptor [([Class =>] CLASS_NAME)]
10891
10892 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10893
10894 when Pragma_Import_Procedure => Import_Procedure : declare
10895 Args : Args_List (1 .. 5);
10896 Names : constant Name_List (1 .. 5) := (
10897 Name_Internal,
10898 Name_External,
10899 Name_Parameter_Types,
10900 Name_Mechanism,
10901 Name_First_Optional_Parameter);
10902
10903 Internal : Node_Id renames Args (1);
10904 External : Node_Id renames Args (2);
10905 Parameter_Types : Node_Id renames Args (3);
10906 Mechanism : Node_Id renames Args (4);
10907 First_Optional_Parameter : Node_Id renames Args (5);
10908
10909 begin
10910 GNAT_Pragma;
10911 Gather_Associations (Names, Args);
10912 Process_Extended_Import_Export_Subprogram_Pragma (
10913 Arg_Internal => Internal,
10914 Arg_External => External,
10915 Arg_Parameter_Types => Parameter_Types,
10916 Arg_Mechanism => Mechanism,
10917 Arg_First_Optional_Parameter => First_Optional_Parameter);
10918 end Import_Procedure;
10919
10920 -----------------------------
10921 -- Import_Valued_Procedure --
10922 -----------------------------
10923
10924 -- pragma Import_Valued_Procedure (
10925 -- [Internal =>] LOCAL_NAME
10926 -- [, [External =>] EXTERNAL_SYMBOL]
10927 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10928 -- [, [Mechanism =>] MECHANISM]
10929 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
10930
10931 -- EXTERNAL_SYMBOL ::=
10932 -- IDENTIFIER
10933 -- | static_string_EXPRESSION
10934
10935 -- PARAMETER_TYPES ::=
10936 -- null
10937 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10938
10939 -- TYPE_DESIGNATOR ::=
10940 -- subtype_NAME
10941 -- | subtype_Name ' Access
10942
10943 -- MECHANISM ::=
10944 -- MECHANISM_NAME
10945 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10946
10947 -- MECHANISM_ASSOCIATION ::=
10948 -- [formal_parameter_NAME =>] MECHANISM_NAME
10949
10950 -- MECHANISM_NAME ::=
10951 -- Value
10952 -- | Reference
10953 -- | Descriptor [([Class =>] CLASS_NAME)]
10954
10955 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10956
10957 when Pragma_Import_Valued_Procedure =>
10958 Import_Valued_Procedure : declare
10959 Args : Args_List (1 .. 5);
10960 Names : constant Name_List (1 .. 5) := (
10961 Name_Internal,
10962 Name_External,
10963 Name_Parameter_Types,
10964 Name_Mechanism,
10965 Name_First_Optional_Parameter);
10966
10967 Internal : Node_Id renames Args (1);
10968 External : Node_Id renames Args (2);
10969 Parameter_Types : Node_Id renames Args (3);
10970 Mechanism : Node_Id renames Args (4);
10971 First_Optional_Parameter : Node_Id renames Args (5);
10972
10973 begin
10974 GNAT_Pragma;
10975 Gather_Associations (Names, Args);
10976 Process_Extended_Import_Export_Subprogram_Pragma (
10977 Arg_Internal => Internal,
10978 Arg_External => External,
10979 Arg_Parameter_Types => Parameter_Types,
10980 Arg_Mechanism => Mechanism,
10981 Arg_First_Optional_Parameter => First_Optional_Parameter);
10982 end Import_Valued_Procedure;
10983
10984 -----------------
10985 -- Independent --
10986 -----------------
10987
10988 -- pragma Independent (LOCAL_NAME);
10989
10990 when Pragma_Independent => Independent : declare
10991 E_Id : Node_Id;
10992 E : Entity_Id;
10993 D : Node_Id;
10994 K : Node_Kind;
10995
10996 begin
10997 Check_Ada_83_Warning;
10998 Ada_2012_Pragma;
10999 Check_No_Identifiers;
11000 Check_Arg_Count (1);
11001 Check_Arg_Is_Local_Name (Arg1);
11002 E_Id := Get_Pragma_Arg (Arg1);
11003
11004 if Etype (E_Id) = Any_Type then
11005 return;
11006 end if;
11007
11008 E := Entity (E_Id);
11009 D := Declaration_Node (E);
11010 K := Nkind (D);
11011
11012 -- Check duplicate before we chain ourselves!
11013
11014 Check_Duplicate_Pragma (E);
11015
11016 -- Check appropriate entity
11017
11018 if Is_Type (E) then
11019 if Rep_Item_Too_Early (E, N)
11020 or else
11021 Rep_Item_Too_Late (E, N)
11022 then
11023 return;
11024 else
11025 Check_First_Subtype (Arg1);
11026 end if;
11027
11028 elsif K = N_Object_Declaration
11029 or else (K = N_Component_Declaration
11030 and then Original_Record_Component (E) = E)
11031 then
11032 if Rep_Item_Too_Late (E, N) then
11033 return;
11034 end if;
11035
11036 else
11037 Error_Pragma_Arg
11038 ("inappropriate entity for pragma%", Arg1);
11039 end if;
11040
11041 Independence_Checks.Append ((N, E));
11042 end Independent;
11043
11044 ----------------------------
11045 -- Independent_Components --
11046 ----------------------------
11047
11048 -- pragma Atomic_Components (array_LOCAL_NAME);
11049
11050 -- This processing is shared by Volatile_Components
11051
11052 when Pragma_Independent_Components => Independent_Components : declare
11053 E_Id : Node_Id;
11054 E : Entity_Id;
11055 D : Node_Id;
11056 K : Node_Kind;
11057
11058 begin
11059 Check_Ada_83_Warning;
11060 Ada_2012_Pragma;
11061 Check_No_Identifiers;
11062 Check_Arg_Count (1);
11063 Check_Arg_Is_Local_Name (Arg1);
11064 E_Id := Get_Pragma_Arg (Arg1);
11065
11066 if Etype (E_Id) = Any_Type then
11067 return;
11068 end if;
11069
11070 E := Entity (E_Id);
11071
11072 -- Check duplicate before we chain ourselves!
11073
11074 Check_Duplicate_Pragma (E);
11075
11076 -- Check appropriate entity
11077
11078 if Rep_Item_Too_Early (E, N)
11079 or else
11080 Rep_Item_Too_Late (E, N)
11081 then
11082 return;
11083 end if;
11084
11085 D := Declaration_Node (E);
11086 K := Nkind (D);
11087
11088 if K = N_Full_Type_Declaration
11089 and then (Is_Array_Type (E) or else Is_Record_Type (E))
11090 then
11091 Independence_Checks.Append ((N, E));
11092 Set_Has_Independent_Components (Base_Type (E));
11093
11094 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
11095 and then Nkind (D) = N_Object_Declaration
11096 and then Nkind (Object_Definition (D)) =
11097 N_Constrained_Array_Definition
11098 then
11099 Independence_Checks.Append ((N, E));
11100 Set_Has_Independent_Components (E);
11101
11102 else
11103 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
11104 end if;
11105 end Independent_Components;
11106
11107 ------------------------
11108 -- Initialize_Scalars --
11109 ------------------------
11110
11111 -- pragma Initialize_Scalars;
11112
11113 when Pragma_Initialize_Scalars =>
11114 GNAT_Pragma;
11115 Check_Arg_Count (0);
11116 Check_Valid_Configuration_Pragma;
11117 Check_Restriction (No_Initialize_Scalars, N);
11118
11119 -- Initialize_Scalars creates false positives in CodePeer, and
11120 -- incorrect negative results in Alfa mode, so ignore this pragma
11121 -- in these modes.
11122
11123 if not Restriction_Active (No_Initialize_Scalars)
11124 and then not (CodePeer_Mode or Alfa_Mode)
11125 then
11126 Init_Or_Norm_Scalars := True;
11127 Initialize_Scalars := True;
11128 end if;
11129
11130 ------------
11131 -- Inline --
11132 ------------
11133
11134 -- pragma Inline ( NAME {, NAME} );
11135
11136 when Pragma_Inline =>
11137
11138 -- Inline status is Enabled if inlining option is active
11139
11140 if Inline_Active then
11141 Process_Inline (Enabled);
11142 else
11143 Process_Inline (Disabled);
11144 end if;
11145
11146 -------------------
11147 -- Inline_Always --
11148 -------------------
11149
11150 -- pragma Inline_Always ( NAME {, NAME} );
11151
11152 when Pragma_Inline_Always =>
11153 GNAT_Pragma;
11154
11155 -- Pragma always active unless in CodePeer or Alfa mode, since
11156 -- this causes walk order issues.
11157
11158 if not (CodePeer_Mode or Alfa_Mode) then
11159 Process_Inline (Enabled);
11160 end if;
11161
11162 --------------------
11163 -- Inline_Generic --
11164 --------------------
11165
11166 -- pragma Inline_Generic (NAME {, NAME});
11167
11168 when Pragma_Inline_Generic =>
11169 GNAT_Pragma;
11170 Process_Generic_List;
11171
11172 ----------------------
11173 -- Inspection_Point --
11174 ----------------------
11175
11176 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
11177
11178 when Pragma_Inspection_Point => Inspection_Point : declare
11179 Arg : Node_Id;
11180 Exp : Node_Id;
11181
11182 begin
11183 if Arg_Count > 0 then
11184 Arg := Arg1;
11185 loop
11186 Exp := Get_Pragma_Arg (Arg);
11187 Analyze (Exp);
11188
11189 if not Is_Entity_Name (Exp)
11190 or else not Is_Object (Entity (Exp))
11191 then
11192 Error_Pragma_Arg ("object name required", Arg);
11193 end if;
11194
11195 Next (Arg);
11196 exit when No (Arg);
11197 end loop;
11198 end if;
11199 end Inspection_Point;
11200
11201 ---------------
11202 -- Interface --
11203 ---------------
11204
11205 -- pragma Interface (
11206 -- [ Convention =>] convention_IDENTIFIER,
11207 -- [ Entity =>] local_NAME
11208 -- [, [External_Name =>] static_string_EXPRESSION ]
11209 -- [, [Link_Name =>] static_string_EXPRESSION ]);
11210
11211 when Pragma_Interface =>
11212 GNAT_Pragma;
11213 Check_Arg_Order
11214 ((Name_Convention,
11215 Name_Entity,
11216 Name_External_Name,
11217 Name_Link_Name));
11218 Check_At_Least_N_Arguments (2);
11219 Check_At_Most_N_Arguments (4);
11220 Process_Import_Or_Interface;
11221
11222 -- In Ada 2005, the permission to use Interface (a reserved word)
11223 -- as a pragma name is considered an obsolescent feature, and this
11224 -- pragma was already obsolescent in Ada 95.
11225
11226 if Ada_Version >= Ada_95 then
11227 Check_Restriction
11228 (No_Obsolescent_Features, Pragma_Identifier (N));
11229
11230 if Warn_On_Obsolescent_Feature then
11231 Error_Msg_N
11232 ("pragma Interface is an obsolescent feature?j?", N);
11233 Error_Msg_N
11234 ("|use pragma Import instead?j?", N);
11235 end if;
11236 end if;
11237
11238 --------------------
11239 -- Interface_Name --
11240 --------------------
11241
11242 -- pragma Interface_Name (
11243 -- [ Entity =>] local_NAME
11244 -- [,[External_Name =>] static_string_EXPRESSION ]
11245 -- [,[Link_Name =>] static_string_EXPRESSION ]);
11246
11247 when Pragma_Interface_Name => Interface_Name : declare
11248 Id : Node_Id;
11249 Def_Id : Entity_Id;
11250 Hom_Id : Entity_Id;
11251 Found : Boolean;
11252
11253 begin
11254 GNAT_Pragma;
11255 Check_Arg_Order
11256 ((Name_Entity, Name_External_Name, Name_Link_Name));
11257 Check_At_Least_N_Arguments (2);
11258 Check_At_Most_N_Arguments (3);
11259 Id := Get_Pragma_Arg (Arg1);
11260 Analyze (Id);
11261
11262 -- This is obsolete from Ada 95 on, but it is an implementation
11263 -- defined pragma, so we do not consider that it violates the
11264 -- restriction (No_Obsolescent_Features).
11265
11266 if Ada_Version >= Ada_95 then
11267 if Warn_On_Obsolescent_Feature then
11268 Error_Msg_N
11269 ("pragma Interface_Name is an obsolescent feature?j?", N);
11270 Error_Msg_N
11271 ("|use pragma Import instead?j?", N);
11272 end if;
11273 end if;
11274
11275 if not Is_Entity_Name (Id) then
11276 Error_Pragma_Arg
11277 ("first argument for pragma% must be entity name", Arg1);
11278 elsif Etype (Id) = Any_Type then
11279 return;
11280 else
11281 Def_Id := Entity (Id);
11282 end if;
11283
11284 -- Special DEC-compatible processing for the object case, forces
11285 -- object to be imported.
11286
11287 if Ekind (Def_Id) = E_Variable then
11288 Kill_Size_Check_Code (Def_Id);
11289 Note_Possible_Modification (Id, Sure => False);
11290
11291 -- Initialization is not allowed for imported variable
11292
11293 if Present (Expression (Parent (Def_Id)))
11294 and then Comes_From_Source (Expression (Parent (Def_Id)))
11295 then
11296 Error_Msg_Sloc := Sloc (Def_Id);
11297 Error_Pragma_Arg
11298 ("no initialization allowed for declaration of& #",
11299 Arg2);
11300
11301 else
11302 -- For compatibility, support VADS usage of providing both
11303 -- pragmas Interface and Interface_Name to obtain the effect
11304 -- of a single Import pragma.
11305
11306 if Is_Imported (Def_Id)
11307 and then Present (First_Rep_Item (Def_Id))
11308 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
11309 and then
11310 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
11311 then
11312 null;
11313 else
11314 Set_Imported (Def_Id);
11315 end if;
11316
11317 Set_Is_Public (Def_Id);
11318 Process_Interface_Name (Def_Id, Arg2, Arg3);
11319 end if;
11320
11321 -- Otherwise must be subprogram
11322
11323 elsif not Is_Subprogram (Def_Id) then
11324 Error_Pragma_Arg
11325 ("argument of pragma% is not subprogram", Arg1);
11326
11327 else
11328 Check_At_Most_N_Arguments (3);
11329 Hom_Id := Def_Id;
11330 Found := False;
11331
11332 -- Loop through homonyms
11333
11334 loop
11335 Def_Id := Get_Base_Subprogram (Hom_Id);
11336
11337 if Is_Imported (Def_Id) then
11338 Process_Interface_Name (Def_Id, Arg2, Arg3);
11339 Found := True;
11340 end if;
11341
11342 exit when From_Aspect_Specification (N);
11343 Hom_Id := Homonym (Hom_Id);
11344
11345 exit when No (Hom_Id)
11346 or else Scope (Hom_Id) /= Current_Scope;
11347 end loop;
11348
11349 if not Found then
11350 Error_Pragma_Arg
11351 ("argument of pragma% is not imported subprogram",
11352 Arg1);
11353 end if;
11354 end if;
11355 end Interface_Name;
11356
11357 -----------------------
11358 -- Interrupt_Handler --
11359 -----------------------
11360
11361 -- pragma Interrupt_Handler (handler_NAME);
11362
11363 when Pragma_Interrupt_Handler =>
11364 Check_Ada_83_Warning;
11365 Check_Arg_Count (1);
11366 Check_No_Identifiers;
11367
11368 if No_Run_Time_Mode then
11369 Error_Msg_CRT ("Interrupt_Handler pragma", N);
11370 else
11371 Check_Interrupt_Or_Attach_Handler;
11372 Process_Interrupt_Or_Attach_Handler;
11373 end if;
11374
11375 ------------------------
11376 -- Interrupt_Priority --
11377 ------------------------
11378
11379 -- pragma Interrupt_Priority [(EXPRESSION)];
11380
11381 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
11382 P : constant Node_Id := Parent (N);
11383 Arg : Node_Id;
11384 Ent : Entity_Id;
11385
11386 begin
11387 Check_Ada_83_Warning;
11388
11389 if Arg_Count /= 0 then
11390 Arg := Get_Pragma_Arg (Arg1);
11391 Check_Arg_Count (1);
11392 Check_No_Identifiers;
11393
11394 -- The expression must be analyzed in the special manner
11395 -- described in "Handling of Default and Per-Object
11396 -- Expressions" in sem.ads.
11397
11398 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
11399 end if;
11400
11401 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
11402 Pragma_Misplaced;
11403 return;
11404
11405 else
11406 Ent := Defining_Identifier (Parent (P));
11407
11408 -- Check duplicate pragma before we chain the pragma in the Rep
11409 -- Item chain of Ent.
11410
11411 Check_Duplicate_Pragma (Ent);
11412 Record_Rep_Item (Ent, N);
11413 end if;
11414 end Interrupt_Priority;
11415
11416 ---------------------
11417 -- Interrupt_State --
11418 ---------------------
11419
11420 -- pragma Interrupt_State (
11421 -- [Name =>] INTERRUPT_ID,
11422 -- [State =>] INTERRUPT_STATE);
11423
11424 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
11425 -- INTERRUPT_STATE => System | Runtime | User
11426
11427 -- Note: if the interrupt id is given as an identifier, then it must
11428 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
11429 -- given as a static integer expression which must be in the range of
11430 -- Ada.Interrupts.Interrupt_ID.
11431
11432 when Pragma_Interrupt_State => Interrupt_State : declare
11433
11434 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
11435 -- This is the entity Ada.Interrupts.Interrupt_ID;
11436
11437 State_Type : Character;
11438 -- Set to 's'/'r'/'u' for System/Runtime/User
11439
11440 IST_Num : Pos;
11441 -- Index to entry in Interrupt_States table
11442
11443 Int_Val : Uint;
11444 -- Value of interrupt
11445
11446 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
11447 -- The first argument to the pragma
11448
11449 Int_Ent : Entity_Id;
11450 -- Interrupt entity in Ada.Interrupts.Names
11451
11452 begin
11453 GNAT_Pragma;
11454 Check_Arg_Order ((Name_Name, Name_State));
11455 Check_Arg_Count (2);
11456
11457 Check_Optional_Identifier (Arg1, Name_Name);
11458 Check_Optional_Identifier (Arg2, Name_State);
11459 Check_Arg_Is_Identifier (Arg2);
11460
11461 -- First argument is identifier
11462
11463 if Nkind (Arg1X) = N_Identifier then
11464
11465 -- Search list of names in Ada.Interrupts.Names
11466
11467 Int_Ent := First_Entity (RTE (RE_Names));
11468 loop
11469 if No (Int_Ent) then
11470 Error_Pragma_Arg ("invalid interrupt name", Arg1);
11471
11472 elsif Chars (Int_Ent) = Chars (Arg1X) then
11473 Int_Val := Expr_Value (Constant_Value (Int_Ent));
11474 exit;
11475 end if;
11476
11477 Next_Entity (Int_Ent);
11478 end loop;
11479
11480 -- First argument is not an identifier, so it must be a static
11481 -- expression of type Ada.Interrupts.Interrupt_ID.
11482
11483 else
11484 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
11485 Int_Val := Expr_Value (Arg1X);
11486
11487 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
11488 or else
11489 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
11490 then
11491 Error_Pragma_Arg
11492 ("value not in range of type " &
11493 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
11494 end if;
11495 end if;
11496
11497 -- Check OK state
11498
11499 case Chars (Get_Pragma_Arg (Arg2)) is
11500 when Name_Runtime => State_Type := 'r';
11501 when Name_System => State_Type := 's';
11502 when Name_User => State_Type := 'u';
11503
11504 when others =>
11505 Error_Pragma_Arg ("invalid interrupt state", Arg2);
11506 end case;
11507
11508 -- Check if entry is already stored
11509
11510 IST_Num := Interrupt_States.First;
11511 loop
11512 -- If entry not found, add it
11513
11514 if IST_Num > Interrupt_States.Last then
11515 Interrupt_States.Append
11516 ((Interrupt_Number => UI_To_Int (Int_Val),
11517 Interrupt_State => State_Type,
11518 Pragma_Loc => Loc));
11519 exit;
11520
11521 -- Case of entry for the same entry
11522
11523 elsif Int_Val = Interrupt_States.Table (IST_Num).
11524 Interrupt_Number
11525 then
11526 -- If state matches, done, no need to make redundant entry
11527
11528 exit when
11529 State_Type = Interrupt_States.Table (IST_Num).
11530 Interrupt_State;
11531
11532 -- Otherwise if state does not match, error
11533
11534 Error_Msg_Sloc :=
11535 Interrupt_States.Table (IST_Num).Pragma_Loc;
11536 Error_Pragma_Arg
11537 ("state conflicts with that given #", Arg2);
11538 exit;
11539 end if;
11540
11541 IST_Num := IST_Num + 1;
11542 end loop;
11543 end Interrupt_State;
11544
11545 ---------------
11546 -- Invariant --
11547 ---------------
11548
11549 -- pragma Invariant
11550 -- ([Entity =>] type_LOCAL_NAME,
11551 -- [Check =>] EXPRESSION
11552 -- [,[Message =>] String_Expression]);
11553
11554 when Pragma_Invariant => Invariant : declare
11555 Type_Id : Node_Id;
11556 Typ : Entity_Id;
11557 PDecl : Node_Id;
11558
11559 Discard : Boolean;
11560 pragma Unreferenced (Discard);
11561
11562 begin
11563 GNAT_Pragma;
11564 Check_At_Least_N_Arguments (2);
11565 Check_At_Most_N_Arguments (3);
11566 Check_Optional_Identifier (Arg1, Name_Entity);
11567 Check_Optional_Identifier (Arg2, Name_Check);
11568
11569 if Arg_Count = 3 then
11570 Check_Optional_Identifier (Arg3, Name_Message);
11571 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
11572 end if;
11573
11574 Check_Arg_Is_Local_Name (Arg1);
11575
11576 Type_Id := Get_Pragma_Arg (Arg1);
11577 Find_Type (Type_Id);
11578 Typ := Entity (Type_Id);
11579
11580 if Typ = Any_Type then
11581 return;
11582
11583 -- An invariant must apply to a private type, or appear in the
11584 -- private part of a package spec and apply to a completion.
11585
11586 elsif Ekind_In (Typ, E_Private_Type,
11587 E_Record_Type_With_Private,
11588 E_Limited_Private_Type)
11589 then
11590 null;
11591
11592 elsif In_Private_Part (Current_Scope)
11593 and then Has_Private_Declaration (Typ)
11594 then
11595 null;
11596
11597 elsif In_Private_Part (Current_Scope) then
11598 Error_Pragma_Arg
11599 ("pragma% only allowed for private type " &
11600 "declared in visible part", Arg1);
11601
11602 else
11603 Error_Pragma_Arg
11604 ("pragma% only allowed for private type", Arg1);
11605 end if;
11606
11607 -- Note that the type has at least one invariant, and also that
11608 -- it has inheritable invariants if we have Invariant'Class.
11609 -- Build the corresponding invariant procedure declaration, so
11610 -- that calls to it can be generated before the body is built
11611 -- (for example wihin an expression function).
11612
11613 PDecl := Build_Invariant_Procedure_Declaration (Typ);
11614 Insert_After (N, PDecl);
11615 Analyze (PDecl);
11616
11617 if Class_Present (N) then
11618 Set_Has_Inheritable_Invariants (Typ);
11619 end if;
11620
11621 -- The remaining processing is simply to link the pragma on to
11622 -- the rep item chain, for processing when the type is frozen.
11623 -- This is accomplished by a call to Rep_Item_Too_Late.
11624
11625 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11626 end Invariant;
11627
11628 ----------------------
11629 -- Java_Constructor --
11630 ----------------------
11631
11632 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
11633
11634 -- Also handles pragma CIL_Constructor
11635
11636 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
11637 Java_Constructor : declare
11638 Convention : Convention_Id;
11639 Def_Id : Entity_Id;
11640 Hom_Id : Entity_Id;
11641 Id : Entity_Id;
11642 This_Formal : Entity_Id;
11643
11644 begin
11645 GNAT_Pragma;
11646 Check_Arg_Count (1);
11647 Check_Optional_Identifier (Arg1, Name_Entity);
11648 Check_Arg_Is_Local_Name (Arg1);
11649
11650 Id := Get_Pragma_Arg (Arg1);
11651 Find_Program_Unit_Name (Id);
11652
11653 -- If we did not find the name, we are done
11654
11655 if Etype (Id) = Any_Type then
11656 return;
11657 end if;
11658
11659 -- Check wrong use of pragma in wrong VM target
11660
11661 if VM_Target = No_VM then
11662 return;
11663
11664 elsif VM_Target = CLI_Target
11665 and then Prag_Id = Pragma_Java_Constructor
11666 then
11667 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
11668
11669 elsif VM_Target = JVM_Target
11670 and then Prag_Id = Pragma_CIL_Constructor
11671 then
11672 Error_Pragma ("must use pragma 'Java_'Constructor");
11673 end if;
11674
11675 case Prag_Id is
11676 when Pragma_CIL_Constructor => Convention := Convention_CIL;
11677 when Pragma_Java_Constructor => Convention := Convention_Java;
11678 when others => null;
11679 end case;
11680
11681 Hom_Id := Entity (Id);
11682
11683 -- Loop through homonyms
11684
11685 loop
11686 Def_Id := Get_Base_Subprogram (Hom_Id);
11687
11688 -- The constructor is required to be a function
11689
11690 if Ekind (Def_Id) /= E_Function then
11691 if VM_Target = JVM_Target then
11692 Error_Pragma_Arg
11693 ("pragma% requires function returning a " &
11694 "'Java access type", Def_Id);
11695 else
11696 Error_Pragma_Arg
11697 ("pragma% requires function returning a " &
11698 "'C'I'L access type", Def_Id);
11699 end if;
11700 end if;
11701
11702 -- Check arguments: For tagged type the first formal must be
11703 -- named "this" and its type must be a named access type
11704 -- designating a class-wide tagged type that has convention
11705 -- CIL/Java. The first formal must also have a null default
11706 -- value. For example:
11707
11708 -- type Typ is tagged ...
11709 -- type Ref is access all Typ;
11710 -- pragma Convention (CIL, Typ);
11711
11712 -- function New_Typ (This : Ref) return Ref;
11713 -- function New_Typ (This : Ref; I : Integer) return Ref;
11714 -- pragma Cil_Constructor (New_Typ);
11715
11716 -- Reason: The first formal must NOT be a primitive of the
11717 -- tagged type.
11718
11719 -- This rule also applies to constructors of delegates used
11720 -- to interface with standard target libraries. For example:
11721
11722 -- type Delegate is access procedure ...
11723 -- pragma Import (CIL, Delegate, ...);
11724
11725 -- function new_Delegate
11726 -- (This : Delegate := null; ... ) return Delegate;
11727
11728 -- For value-types this rule does not apply.
11729
11730 if not Is_Value_Type (Etype (Def_Id)) then
11731 if No (First_Formal (Def_Id)) then
11732 Error_Msg_Name_1 := Pname;
11733 Error_Msg_N ("% function must have parameters", Def_Id);
11734 return;
11735 end if;
11736
11737 -- In the JRE library we have several occurrences in which
11738 -- the "this" parameter is not the first formal.
11739
11740 This_Formal := First_Formal (Def_Id);
11741
11742 -- In the JRE library we have several occurrences in which
11743 -- the "this" parameter is not the first formal. Search for
11744 -- it.
11745
11746 if VM_Target = JVM_Target then
11747 while Present (This_Formal)
11748 and then Get_Name_String (Chars (This_Formal)) /= "this"
11749 loop
11750 Next_Formal (This_Formal);
11751 end loop;
11752
11753 if No (This_Formal) then
11754 This_Formal := First_Formal (Def_Id);
11755 end if;
11756 end if;
11757
11758 -- Warning: The first parameter should be named "this".
11759 -- We temporarily allow it because we have the following
11760 -- case in the Java runtime (file s-osinte.ads) ???
11761
11762 -- function new_Thread
11763 -- (Self_Id : System.Address) return Thread_Id;
11764 -- pragma Java_Constructor (new_Thread);
11765
11766 if VM_Target = JVM_Target
11767 and then Get_Name_String (Chars (First_Formal (Def_Id)))
11768 = "self_id"
11769 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
11770 then
11771 null;
11772
11773 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
11774 Error_Msg_Name_1 := Pname;
11775 Error_Msg_N
11776 ("first formal of % function must be named `this`",
11777 Parent (This_Formal));
11778
11779 elsif not Is_Access_Type (Etype (This_Formal)) then
11780 Error_Msg_Name_1 := Pname;
11781 Error_Msg_N
11782 ("first formal of % function must be an access type",
11783 Parameter_Type (Parent (This_Formal)));
11784
11785 -- For delegates the type of the first formal must be a
11786 -- named access-to-subprogram type (see previous example)
11787
11788 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
11789 and then Ekind (Etype (This_Formal))
11790 /= E_Access_Subprogram_Type
11791 then
11792 Error_Msg_Name_1 := Pname;
11793 Error_Msg_N
11794 ("first formal of % function must be a named access" &
11795 " to subprogram type",
11796 Parameter_Type (Parent (This_Formal)));
11797
11798 -- Warning: We should reject anonymous access types because
11799 -- the constructor must not be handled as a primitive of the
11800 -- tagged type. We temporarily allow it because this profile
11801 -- is currently generated by cil2ada???
11802
11803 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
11804 and then not Ekind_In (Etype (This_Formal),
11805 E_Access_Type,
11806 E_General_Access_Type,
11807 E_Anonymous_Access_Type)
11808 then
11809 Error_Msg_Name_1 := Pname;
11810 Error_Msg_N
11811 ("first formal of % function must be a named access" &
11812 " type",
11813 Parameter_Type (Parent (This_Formal)));
11814
11815 elsif Atree.Convention
11816 (Designated_Type (Etype (This_Formal))) /= Convention
11817 then
11818 Error_Msg_Name_1 := Pname;
11819
11820 if Convention = Convention_Java then
11821 Error_Msg_N
11822 ("pragma% requires convention 'Cil in designated" &
11823 " type",
11824 Parameter_Type (Parent (This_Formal)));
11825 else
11826 Error_Msg_N
11827 ("pragma% requires convention 'Java in designated" &
11828 " type",
11829 Parameter_Type (Parent (This_Formal)));
11830 end if;
11831
11832 elsif No (Expression (Parent (This_Formal)))
11833 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
11834 then
11835 Error_Msg_Name_1 := Pname;
11836 Error_Msg_N
11837 ("pragma% requires first formal with default `null`",
11838 Parameter_Type (Parent (This_Formal)));
11839 end if;
11840 end if;
11841
11842 -- Check result type: the constructor must be a function
11843 -- returning:
11844 -- * a value type (only allowed in the CIL compiler)
11845 -- * an access-to-subprogram type with convention Java/CIL
11846 -- * an access-type designating a type that has convention
11847 -- Java/CIL.
11848
11849 if Is_Value_Type (Etype (Def_Id)) then
11850 null;
11851
11852 -- Access-to-subprogram type with convention Java/CIL
11853
11854 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
11855 if Atree.Convention (Etype (Def_Id)) /= Convention then
11856 if Convention = Convention_Java then
11857 Error_Pragma_Arg
11858 ("pragma% requires function returning a " &
11859 "'Java access type", Arg1);
11860 else
11861 pragma Assert (Convention = Convention_CIL);
11862 Error_Pragma_Arg
11863 ("pragma% requires function returning a " &
11864 "'C'I'L access type", Arg1);
11865 end if;
11866 end if;
11867
11868 elsif Ekind (Etype (Def_Id)) in Access_Kind then
11869 if not Ekind_In (Etype (Def_Id), E_Access_Type,
11870 E_General_Access_Type)
11871 or else
11872 Atree.Convention
11873 (Designated_Type (Etype (Def_Id))) /= Convention
11874 then
11875 Error_Msg_Name_1 := Pname;
11876
11877 if Convention = Convention_Java then
11878 Error_Pragma_Arg
11879 ("pragma% requires function returning a named" &
11880 "'Java access type", Arg1);
11881 else
11882 Error_Pragma_Arg
11883 ("pragma% requires function returning a named" &
11884 "'C'I'L access type", Arg1);
11885 end if;
11886 end if;
11887 end if;
11888
11889 Set_Is_Constructor (Def_Id);
11890 Set_Convention (Def_Id, Convention);
11891 Set_Is_Imported (Def_Id);
11892
11893 exit when From_Aspect_Specification (N);
11894 Hom_Id := Homonym (Hom_Id);
11895
11896 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
11897 end loop;
11898 end Java_Constructor;
11899
11900 ----------------------
11901 -- Java_Interface --
11902 ----------------------
11903
11904 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
11905
11906 when Pragma_Java_Interface => Java_Interface : declare
11907 Arg : Node_Id;
11908 Typ : Entity_Id;
11909
11910 begin
11911 GNAT_Pragma;
11912 Check_Arg_Count (1);
11913 Check_Optional_Identifier (Arg1, Name_Entity);
11914 Check_Arg_Is_Local_Name (Arg1);
11915
11916 Arg := Get_Pragma_Arg (Arg1);
11917 Analyze (Arg);
11918
11919 if Etype (Arg) = Any_Type then
11920 return;
11921 end if;
11922
11923 if not Is_Entity_Name (Arg)
11924 or else not Is_Type (Entity (Arg))
11925 then
11926 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
11927 end if;
11928
11929 Typ := Underlying_Type (Entity (Arg));
11930
11931 -- For now simply check some of the semantic constraints on the
11932 -- type. This currently leaves out some restrictions on interface
11933 -- types, namely that the parent type must be java.lang.Object.Typ
11934 -- and that all primitives of the type should be declared
11935 -- abstract. ???
11936
11937 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
11938 Error_Pragma_Arg ("pragma% requires an abstract "
11939 & "tagged type", Arg1);
11940
11941 elsif not Has_Discriminants (Typ)
11942 or else Ekind (Etype (First_Discriminant (Typ)))
11943 /= E_Anonymous_Access_Type
11944 or else
11945 not Is_Class_Wide_Type
11946 (Designated_Type (Etype (First_Discriminant (Typ))))
11947 then
11948 Error_Pragma_Arg
11949 ("type must have a class-wide access discriminant", Arg1);
11950 end if;
11951 end Java_Interface;
11952
11953 ----------------
11954 -- Keep_Names --
11955 ----------------
11956
11957 -- pragma Keep_Names ([On => ] local_NAME);
11958
11959 when Pragma_Keep_Names => Keep_Names : declare
11960 Arg : Node_Id;
11961
11962 begin
11963 GNAT_Pragma;
11964 Check_Arg_Count (1);
11965 Check_Optional_Identifier (Arg1, Name_On);
11966 Check_Arg_Is_Local_Name (Arg1);
11967
11968 Arg := Get_Pragma_Arg (Arg1);
11969 Analyze (Arg);
11970
11971 if Etype (Arg) = Any_Type then
11972 return;
11973 end if;
11974
11975 if not Is_Entity_Name (Arg)
11976 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
11977 then
11978 Error_Pragma_Arg
11979 ("pragma% requires a local enumeration type", Arg1);
11980 end if;
11981
11982 Set_Discard_Names (Entity (Arg), False);
11983 end Keep_Names;
11984
11985 -------------
11986 -- License --
11987 -------------
11988
11989 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
11990
11991 when Pragma_License =>
11992 GNAT_Pragma;
11993 Check_Arg_Count (1);
11994 Check_No_Identifiers;
11995 Check_Valid_Configuration_Pragma;
11996 Check_Arg_Is_Identifier (Arg1);
11997
11998 declare
11999 Sind : constant Source_File_Index :=
12000 Source_Index (Current_Sem_Unit);
12001
12002 begin
12003 case Chars (Get_Pragma_Arg (Arg1)) is
12004 when Name_GPL =>
12005 Set_License (Sind, GPL);
12006
12007 when Name_Modified_GPL =>
12008 Set_License (Sind, Modified_GPL);
12009
12010 when Name_Restricted =>
12011 Set_License (Sind, Restricted);
12012
12013 when Name_Unrestricted =>
12014 Set_License (Sind, Unrestricted);
12015
12016 when others =>
12017 Error_Pragma_Arg ("invalid license name", Arg1);
12018 end case;
12019 end;
12020
12021 ---------------
12022 -- Link_With --
12023 ---------------
12024
12025 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
12026
12027 when Pragma_Link_With => Link_With : declare
12028 Arg : Node_Id;
12029
12030 begin
12031 GNAT_Pragma;
12032
12033 if Operating_Mode = Generate_Code
12034 and then In_Extended_Main_Source_Unit (N)
12035 then
12036 Check_At_Least_N_Arguments (1);
12037 Check_No_Identifiers;
12038 Check_Is_In_Decl_Part_Or_Package_Spec;
12039 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12040 Start_String;
12041
12042 Arg := Arg1;
12043 while Present (Arg) loop
12044 Check_Arg_Is_Static_Expression (Arg, Standard_String);
12045
12046 -- Store argument, converting sequences of spaces to a
12047 -- single null character (this is one of the differences
12048 -- in processing between Link_With and Linker_Options).
12049
12050 Arg_Store : declare
12051 C : constant Char_Code := Get_Char_Code (' ');
12052 S : constant String_Id :=
12053 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
12054 L : constant Nat := String_Length (S);
12055 F : Nat := 1;
12056
12057 procedure Skip_Spaces;
12058 -- Advance F past any spaces
12059
12060 -----------------
12061 -- Skip_Spaces --
12062 -----------------
12063
12064 procedure Skip_Spaces is
12065 begin
12066 while F <= L and then Get_String_Char (S, F) = C loop
12067 F := F + 1;
12068 end loop;
12069 end Skip_Spaces;
12070
12071 -- Start of processing for Arg_Store
12072
12073 begin
12074 Skip_Spaces; -- skip leading spaces
12075
12076 -- Loop through characters, changing any embedded
12077 -- sequence of spaces to a single null character (this
12078 -- is how Link_With/Linker_Options differ)
12079
12080 while F <= L loop
12081 if Get_String_Char (S, F) = C then
12082 Skip_Spaces;
12083 exit when F > L;
12084 Store_String_Char (ASCII.NUL);
12085
12086 else
12087 Store_String_Char (Get_String_Char (S, F));
12088 F := F + 1;
12089 end if;
12090 end loop;
12091 end Arg_Store;
12092
12093 Arg := Next (Arg);
12094
12095 if Present (Arg) then
12096 Store_String_Char (ASCII.NUL);
12097 end if;
12098 end loop;
12099
12100 Store_Linker_Option_String (End_String);
12101 end if;
12102 end Link_With;
12103
12104 ------------------
12105 -- Linker_Alias --
12106 ------------------
12107
12108 -- pragma Linker_Alias (
12109 -- [Entity =>] LOCAL_NAME
12110 -- [Target =>] static_string_EXPRESSION);
12111
12112 when Pragma_Linker_Alias =>
12113 GNAT_Pragma;
12114 Check_Arg_Order ((Name_Entity, Name_Target));
12115 Check_Arg_Count (2);
12116 Check_Optional_Identifier (Arg1, Name_Entity);
12117 Check_Optional_Identifier (Arg2, Name_Target);
12118 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12119 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
12120
12121 -- The only processing required is to link this item on to the
12122 -- list of rep items for the given entity. This is accomplished
12123 -- by the call to Rep_Item_Too_Late (when no error is detected
12124 -- and False is returned).
12125
12126 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
12127 return;
12128 else
12129 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
12130 end if;
12131
12132 ------------------------
12133 -- Linker_Constructor --
12134 ------------------------
12135
12136 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
12137
12138 -- Code is shared with Linker_Destructor
12139
12140 -----------------------
12141 -- Linker_Destructor --
12142 -----------------------
12143
12144 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
12145
12146 when Pragma_Linker_Constructor |
12147 Pragma_Linker_Destructor =>
12148 Linker_Constructor : declare
12149 Arg1_X : Node_Id;
12150 Proc : Entity_Id;
12151
12152 begin
12153 GNAT_Pragma;
12154 Check_Arg_Count (1);
12155 Check_No_Identifiers;
12156 Check_Arg_Is_Local_Name (Arg1);
12157 Arg1_X := Get_Pragma_Arg (Arg1);
12158 Analyze (Arg1_X);
12159 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
12160
12161 if not Is_Library_Level_Entity (Proc) then
12162 Error_Pragma_Arg
12163 ("argument for pragma% must be library level entity", Arg1);
12164 end if;
12165
12166 -- The only processing required is to link this item on to the
12167 -- list of rep items for the given entity. This is accomplished
12168 -- by the call to Rep_Item_Too_Late (when no error is detected
12169 -- and False is returned).
12170
12171 if Rep_Item_Too_Late (Proc, N) then
12172 return;
12173 else
12174 Set_Has_Gigi_Rep_Item (Proc);
12175 end if;
12176 end Linker_Constructor;
12177
12178 --------------------
12179 -- Linker_Options --
12180 --------------------
12181
12182 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
12183
12184 when Pragma_Linker_Options => Linker_Options : declare
12185 Arg : Node_Id;
12186
12187 begin
12188 Check_Ada_83_Warning;
12189 Check_No_Identifiers;
12190 Check_Arg_Count (1);
12191 Check_Is_In_Decl_Part_Or_Package_Spec;
12192 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12193 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
12194
12195 Arg := Arg2;
12196 while Present (Arg) loop
12197 Check_Arg_Is_Static_Expression (Arg, Standard_String);
12198 Store_String_Char (ASCII.NUL);
12199 Store_String_Chars
12200 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
12201 Arg := Next (Arg);
12202 end loop;
12203
12204 if Operating_Mode = Generate_Code
12205 and then In_Extended_Main_Source_Unit (N)
12206 then
12207 Store_Linker_Option_String (End_String);
12208 end if;
12209 end Linker_Options;
12210
12211 --------------------
12212 -- Linker_Section --
12213 --------------------
12214
12215 -- pragma Linker_Section (
12216 -- [Entity =>] LOCAL_NAME
12217 -- [Section =>] static_string_EXPRESSION);
12218
12219 when Pragma_Linker_Section =>
12220 GNAT_Pragma;
12221 Check_Arg_Order ((Name_Entity, Name_Section));
12222 Check_Arg_Count (2);
12223 Check_Optional_Identifier (Arg1, Name_Entity);
12224 Check_Optional_Identifier (Arg2, Name_Section);
12225 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12226 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
12227
12228 -- This pragma applies only to objects
12229
12230 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
12231 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
12232 end if;
12233
12234 -- The only processing required is to link this item on to the
12235 -- list of rep items for the given entity. This is accomplished
12236 -- by the call to Rep_Item_Too_Late (when no error is detected
12237 -- and False is returned).
12238
12239 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
12240 return;
12241 else
12242 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
12243 end if;
12244
12245 ----------
12246 -- List --
12247 ----------
12248
12249 -- pragma List (On | Off)
12250
12251 -- There is nothing to do here, since we did all the processing for
12252 -- this pragma in Par.Prag (so that it works properly even in syntax
12253 -- only mode).
12254
12255 when Pragma_List =>
12256 null;
12257
12258 ---------------
12259 -- Lock_Free --
12260 ---------------
12261
12262 -- pragma Lock_Free [(Boolean_EXPRESSION)];
12263
12264 when Pragma_Lock_Free => Lock_Free : declare
12265 P : constant Node_Id := Parent (N);
12266 Arg : Node_Id;
12267 Ent : Entity_Id;
12268 Val : Boolean;
12269
12270 begin
12271 Check_No_Identifiers;
12272 Check_At_Most_N_Arguments (1);
12273
12274 -- Protected definition case
12275
12276 if Nkind (P) = N_Protected_Definition then
12277 Ent := Defining_Identifier (Parent (P));
12278
12279 -- One argument
12280
12281 if Arg_Count = 1 then
12282 Arg := Get_Pragma_Arg (Arg1);
12283 Val := Is_True (Static_Boolean (Arg));
12284
12285 -- No arguments (expression is considered to be True)
12286
12287 else
12288 Val := True;
12289 end if;
12290
12291 -- Check duplicate pragma before we chain the pragma in the Rep
12292 -- Item chain of Ent.
12293
12294 Check_Duplicate_Pragma (Ent);
12295 Record_Rep_Item (Ent, N);
12296 Set_Uses_Lock_Free (Ent, Val);
12297
12298 -- Anything else is incorrect placement
12299
12300 else
12301 Pragma_Misplaced;
12302 end if;
12303 end Lock_Free;
12304
12305 --------------------
12306 -- Locking_Policy --
12307 --------------------
12308
12309 -- pragma Locking_Policy (policy_IDENTIFIER);
12310
12311 when Pragma_Locking_Policy => declare
12312 subtype LP_Range is Name_Id
12313 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
12314 LP_Val : LP_Range;
12315 LP : Character;
12316
12317 begin
12318 Check_Ada_83_Warning;
12319 Check_Arg_Count (1);
12320 Check_No_Identifiers;
12321 Check_Arg_Is_Locking_Policy (Arg1);
12322 Check_Valid_Configuration_Pragma;
12323 LP_Val := Chars (Get_Pragma_Arg (Arg1));
12324
12325 case LP_Val is
12326 when Name_Ceiling_Locking =>
12327 LP := 'C';
12328 when Name_Inheritance_Locking =>
12329 LP := 'I';
12330 when Name_Concurrent_Readers_Locking =>
12331 LP := 'R';
12332 end case;
12333
12334 if Locking_Policy /= ' '
12335 and then Locking_Policy /= LP
12336 then
12337 Error_Msg_Sloc := Locking_Policy_Sloc;
12338 Error_Pragma ("locking policy incompatible with policy#");
12339
12340 -- Set new policy, but always preserve System_Location since we
12341 -- like the error message with the run time name.
12342
12343 else
12344 Locking_Policy := LP;
12345
12346 if Locking_Policy_Sloc /= System_Location then
12347 Locking_Policy_Sloc := Loc;
12348 end if;
12349 end if;
12350 end;
12351
12352 ----------------
12353 -- Long_Float --
12354 ----------------
12355
12356 -- pragma Long_Float (D_Float | G_Float);
12357
12358 when Pragma_Long_Float => Long_Float : declare
12359 begin
12360 GNAT_Pragma;
12361 Check_Valid_Configuration_Pragma;
12362 Check_Arg_Count (1);
12363 Check_No_Identifier (Arg1);
12364 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
12365
12366 if not OpenVMS_On_Target then
12367 Error_Pragma ("??pragma% ignored (applies only to Open'V'M'S)");
12368 end if;
12369
12370 -- D_Float case
12371
12372 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
12373 if Opt.Float_Format_Long = 'G' then
12374 Error_Pragma_Arg
12375 ("G_Float previously specified", Arg1);
12376
12377 elsif Current_Sem_Unit /= Main_Unit
12378 and then Opt.Float_Format_Long /= 'D'
12379 then
12380 Error_Pragma_Arg
12381 ("main unit not compiled with pragma Long_Float (D_Float)",
12382 "\pragma% must be used consistently for whole partition",
12383 Arg1);
12384
12385 else
12386 Opt.Float_Format_Long := 'D';
12387 end if;
12388
12389 -- G_Float case (this is the default, does not need overriding)
12390
12391 else
12392 if Opt.Float_Format_Long = 'D' then
12393 Error_Pragma ("D_Float previously specified");
12394
12395 elsif Current_Sem_Unit /= Main_Unit
12396 and then Opt.Float_Format_Long /= 'G'
12397 then
12398 Error_Pragma_Arg
12399 ("main unit not compiled with pragma Long_Float (G_Float)",
12400 "\pragma% must be used consistently for whole partition",
12401 Arg1);
12402
12403 else
12404 Opt.Float_Format_Long := 'G';
12405 end if;
12406 end if;
12407
12408 Set_Standard_Fpt_Formats;
12409 end Long_Float;
12410
12411 --------------------
12412 -- Loop_Invariant --
12413 --------------------
12414
12415 -- pragma Loop_Invariant ( boolean_EXPRESSION );
12416
12417 when Pragma_Loop_Invariant => Loop_Invariant : declare
12418 begin
12419 GNAT_Pragma;
12420 S14_Pragma;
12421 Check_Arg_Count (1);
12422 Check_Loop_Pragma_Placement;
12423
12424 -- Completely ignore if disabled
12425
12426 if not Check_Enabled (Pname) then
12427 Rewrite (N, Make_Null_Statement (Loc));
12428 Analyze (N);
12429 return;
12430 end if;
12431
12432 Preanalyze_And_Resolve (Expression (Arg1), Any_Boolean);
12433
12434 -- Transform pragma Loop_Invariant into equivalent pragma Check
12435 -- Generate:
12436 -- pragma Check (Loop_Invaraint, Arg1);
12437
12438 -- Seems completely wrong to hijack pragma Check this way ???
12439
12440 Rewrite (N,
12441 Make_Pragma (Loc,
12442 Chars => Name_Check,
12443 Pragma_Argument_Associations => New_List (
12444 Make_Pragma_Argument_Association (Loc,
12445 Expression => Make_Identifier (Loc, Name_Loop_Invariant)),
12446 Relocate_Node (Arg1))));
12447
12448 Analyze (N);
12449 end Loop_Invariant;
12450
12451 -------------------
12452 -- Loop_Optimize --
12453 -------------------
12454
12455 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
12456
12457 -- OPTIMIZATION_HINT ::= No_Unroll | Unroll | No_Vector | Vector
12458
12459 when Pragma_Loop_Optimize => Loop_Optimize : declare
12460 Hint : Node_Id;
12461
12462 begin
12463 GNAT_Pragma;
12464 Check_At_Least_N_Arguments (1);
12465 Check_No_Identifiers;
12466
12467 Hint := First (Pragma_Argument_Associations (N));
12468 while Present (Hint) loop
12469 Check_Arg_Is_One_Of (Hint,
12470 Name_No_Unroll, Name_Unroll, Name_No_Vector, Name_Vector);
12471 Next (Hint);
12472 end loop;
12473
12474 Check_Loop_Pragma_Placement;
12475 end Loop_Optimize;
12476
12477 ------------------
12478 -- Loop_Variant --
12479 ------------------
12480
12481 -- pragma Loop_Variant
12482 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
12483
12484 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
12485
12486 -- CHANGE_DIRECTION ::= Increases | Decreases
12487
12488 when Pragma_Loop_Variant => Loop_Variant : declare
12489 Variant : Node_Id;
12490
12491 begin
12492 GNAT_Pragma;
12493 S14_Pragma;
12494 Check_At_Least_N_Arguments (1);
12495 Check_Loop_Pragma_Placement;
12496
12497 -- Completely ignore if disabled
12498
12499 if not Check_Enabled (Pname) then
12500 Rewrite (N, Make_Null_Statement (Loc));
12501 Analyze (N);
12502 return;
12503 end if;
12504
12505 -- Process all increasing / decreasing expressions
12506
12507 Variant := First (Pragma_Argument_Associations (N));
12508 while Present (Variant) loop
12509 if Chars (Variant) /= Name_Decreases
12510 and then Chars (Variant) /= Name_Increases
12511 then
12512 Error_Pragma_Arg ("wrong change modifier", Variant);
12513 end if;
12514
12515 Preanalyze_And_Resolve (Expression (Variant), Any_Discrete);
12516
12517 Next (Variant);
12518 end loop;
12519 end Loop_Variant;
12520
12521 -----------------------
12522 -- Machine_Attribute --
12523 -----------------------
12524
12525 -- pragma Machine_Attribute (
12526 -- [Entity =>] LOCAL_NAME,
12527 -- [Attribute_Name =>] static_string_EXPRESSION
12528 -- [, [Info =>] static_EXPRESSION] );
12529
12530 when Pragma_Machine_Attribute => Machine_Attribute : declare
12531 Def_Id : Entity_Id;
12532
12533 begin
12534 GNAT_Pragma;
12535 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
12536
12537 if Arg_Count = 3 then
12538 Check_Optional_Identifier (Arg3, Name_Info);
12539 Check_Arg_Is_Static_Expression (Arg3);
12540 else
12541 Check_Arg_Count (2);
12542 end if;
12543
12544 Check_Optional_Identifier (Arg1, Name_Entity);
12545 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
12546 Check_Arg_Is_Local_Name (Arg1);
12547 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
12548 Def_Id := Entity (Get_Pragma_Arg (Arg1));
12549
12550 if Is_Access_Type (Def_Id) then
12551 Def_Id := Designated_Type (Def_Id);
12552 end if;
12553
12554 if Rep_Item_Too_Early (Def_Id, N) then
12555 return;
12556 end if;
12557
12558 Def_Id := Underlying_Type (Def_Id);
12559
12560 -- The only processing required is to link this item on to the
12561 -- list of rep items for the given entity. This is accomplished
12562 -- by the call to Rep_Item_Too_Late (when no error is detected
12563 -- and False is returned).
12564
12565 if Rep_Item_Too_Late (Def_Id, N) then
12566 return;
12567 else
12568 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
12569 end if;
12570 end Machine_Attribute;
12571
12572 ----------
12573 -- Main --
12574 ----------
12575
12576 -- pragma Main
12577 -- (MAIN_OPTION [, MAIN_OPTION]);
12578
12579 -- MAIN_OPTION ::=
12580 -- [STACK_SIZE =>] static_integer_EXPRESSION
12581 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
12582 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
12583
12584 when Pragma_Main => Main : declare
12585 Args : Args_List (1 .. 3);
12586 Names : constant Name_List (1 .. 3) := (
12587 Name_Stack_Size,
12588 Name_Task_Stack_Size_Default,
12589 Name_Time_Slicing_Enabled);
12590
12591 Nod : Node_Id;
12592
12593 begin
12594 GNAT_Pragma;
12595 Gather_Associations (Names, Args);
12596
12597 for J in 1 .. 2 loop
12598 if Present (Args (J)) then
12599 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
12600 end if;
12601 end loop;
12602
12603 if Present (Args (3)) then
12604 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
12605 end if;
12606
12607 Nod := Next (N);
12608 while Present (Nod) loop
12609 if Nkind (Nod) = N_Pragma
12610 and then Pragma_Name (Nod) = Name_Main
12611 then
12612 Error_Msg_Name_1 := Pname;
12613 Error_Msg_N ("duplicate pragma% not permitted", Nod);
12614 end if;
12615
12616 Next (Nod);
12617 end loop;
12618 end Main;
12619
12620 ------------------
12621 -- Main_Storage --
12622 ------------------
12623
12624 -- pragma Main_Storage
12625 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
12626
12627 -- MAIN_STORAGE_OPTION ::=
12628 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
12629 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
12630
12631 when Pragma_Main_Storage => Main_Storage : declare
12632 Args : Args_List (1 .. 2);
12633 Names : constant Name_List (1 .. 2) := (
12634 Name_Working_Storage,
12635 Name_Top_Guard);
12636
12637 Nod : Node_Id;
12638
12639 begin
12640 GNAT_Pragma;
12641 Gather_Associations (Names, Args);
12642
12643 for J in 1 .. 2 loop
12644 if Present (Args (J)) then
12645 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
12646 end if;
12647 end loop;
12648
12649 Check_In_Main_Program;
12650
12651 Nod := Next (N);
12652 while Present (Nod) loop
12653 if Nkind (Nod) = N_Pragma
12654 and then Pragma_Name (Nod) = Name_Main_Storage
12655 then
12656 Error_Msg_Name_1 := Pname;
12657 Error_Msg_N ("duplicate pragma% not permitted", Nod);
12658 end if;
12659
12660 Next (Nod);
12661 end loop;
12662 end Main_Storage;
12663
12664 -----------------
12665 -- Memory_Size --
12666 -----------------
12667
12668 -- pragma Memory_Size (NUMERIC_LITERAL)
12669
12670 when Pragma_Memory_Size =>
12671 GNAT_Pragma;
12672
12673 -- Memory size is simply ignored
12674
12675 Check_No_Identifiers;
12676 Check_Arg_Count (1);
12677 Check_Arg_Is_Integer_Literal (Arg1);
12678
12679 -------------
12680 -- No_Body --
12681 -------------
12682
12683 -- pragma No_Body;
12684
12685 -- The only correct use of this pragma is on its own in a file, in
12686 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
12687 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
12688 -- check for a file containing nothing but a No_Body pragma). If we
12689 -- attempt to process it during normal semantics processing, it means
12690 -- it was misplaced.
12691
12692 when Pragma_No_Body =>
12693 GNAT_Pragma;
12694 Pragma_Misplaced;
12695
12696 ---------------
12697 -- No_Inline --
12698 ---------------
12699
12700 -- pragma No_Inline ( NAME {, NAME} );
12701
12702 when Pragma_No_Inline =>
12703 GNAT_Pragma;
12704 Process_Inline (Suppressed);
12705
12706 ---------------
12707 -- No_Return --
12708 ---------------
12709
12710 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
12711
12712 when Pragma_No_Return => No_Return : declare
12713 Id : Node_Id;
12714 E : Entity_Id;
12715 Found : Boolean;
12716 Arg : Node_Id;
12717
12718 begin
12719 Ada_2005_Pragma;
12720 Check_At_Least_N_Arguments (1);
12721
12722 -- Loop through arguments of pragma
12723
12724 Arg := Arg1;
12725 while Present (Arg) loop
12726 Check_Arg_Is_Local_Name (Arg);
12727 Id := Get_Pragma_Arg (Arg);
12728 Analyze (Id);
12729
12730 if not Is_Entity_Name (Id) then
12731 Error_Pragma_Arg ("entity name required", Arg);
12732 end if;
12733
12734 if Etype (Id) = Any_Type then
12735 raise Pragma_Exit;
12736 end if;
12737
12738 -- Loop to find matching procedures
12739
12740 E := Entity (Id);
12741 Found := False;
12742 while Present (E)
12743 and then Scope (E) = Current_Scope
12744 loop
12745 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
12746 Set_No_Return (E);
12747
12748 -- Set flag on any alias as well
12749
12750 if Is_Overloadable (E) and then Present (Alias (E)) then
12751 Set_No_Return (Alias (E));
12752 end if;
12753
12754 Found := True;
12755 end if;
12756
12757 exit when From_Aspect_Specification (N);
12758 E := Homonym (E);
12759 end loop;
12760
12761 if not Found then
12762 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
12763 end if;
12764
12765 Next (Arg);
12766 end loop;
12767 end No_Return;
12768
12769 -----------------
12770 -- No_Run_Time --
12771 -----------------
12772
12773 -- pragma No_Run_Time;
12774
12775 -- Note: this pragma is retained for backwards compatibility. See
12776 -- body of Rtsfind for full details on its handling.
12777
12778 when Pragma_No_Run_Time =>
12779 GNAT_Pragma;
12780 Check_Valid_Configuration_Pragma;
12781 Check_Arg_Count (0);
12782
12783 No_Run_Time_Mode := True;
12784 Configurable_Run_Time_Mode := True;
12785
12786 -- Set Duration to 32 bits if word size is 32
12787
12788 if Ttypes.System_Word_Size = 32 then
12789 Duration_32_Bits_On_Target := True;
12790 end if;
12791
12792 -- Set appropriate restrictions
12793
12794 Set_Restriction (No_Finalization, N);
12795 Set_Restriction (No_Exception_Handlers, N);
12796 Set_Restriction (Max_Tasks, N, 0);
12797 Set_Restriction (No_Tasking, N);
12798
12799 ------------------------
12800 -- No_Strict_Aliasing --
12801 ------------------------
12802
12803 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
12804
12805 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
12806 E_Id : Entity_Id;
12807
12808 begin
12809 GNAT_Pragma;
12810 Check_At_Most_N_Arguments (1);
12811
12812 if Arg_Count = 0 then
12813 Check_Valid_Configuration_Pragma;
12814 Opt.No_Strict_Aliasing := True;
12815
12816 else
12817 Check_Optional_Identifier (Arg2, Name_Entity);
12818 Check_Arg_Is_Local_Name (Arg1);
12819 E_Id := Entity (Get_Pragma_Arg (Arg1));
12820
12821 if E_Id = Any_Type then
12822 return;
12823 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
12824 Error_Pragma_Arg ("pragma% requires access type", Arg1);
12825 end if;
12826
12827 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
12828 end if;
12829 end No_Strict_Aliasing;
12830
12831 -----------------------
12832 -- Normalize_Scalars --
12833 -----------------------
12834
12835 -- pragma Normalize_Scalars;
12836
12837 when Pragma_Normalize_Scalars =>
12838 Check_Ada_83_Warning;
12839 Check_Arg_Count (0);
12840 Check_Valid_Configuration_Pragma;
12841
12842 -- Normalize_Scalars creates false positives in CodePeer, and
12843 -- incorrect negative results in Alfa mode, so ignore this pragma
12844 -- in these modes.
12845
12846 if not (CodePeer_Mode or Alfa_Mode) then
12847 Normalize_Scalars := True;
12848 Init_Or_Norm_Scalars := True;
12849 end if;
12850
12851 -----------------
12852 -- Obsolescent --
12853 -----------------
12854
12855 -- pragma Obsolescent;
12856
12857 -- pragma Obsolescent (
12858 -- [Message =>] static_string_EXPRESSION
12859 -- [,[Version =>] Ada_05]]);
12860
12861 -- pragma Obsolescent (
12862 -- [Entity =>] NAME
12863 -- [,[Message =>] static_string_EXPRESSION
12864 -- [,[Version =>] Ada_05]] );
12865
12866 when Pragma_Obsolescent => Obsolescent : declare
12867 Ename : Node_Id;
12868 Decl : Node_Id;
12869
12870 procedure Set_Obsolescent (E : Entity_Id);
12871 -- Given an entity Ent, mark it as obsolescent if appropriate
12872
12873 ---------------------
12874 -- Set_Obsolescent --
12875 ---------------------
12876
12877 procedure Set_Obsolescent (E : Entity_Id) is
12878 Active : Boolean;
12879 Ent : Entity_Id;
12880 S : String_Id;
12881
12882 begin
12883 Active := True;
12884 Ent := E;
12885
12886 -- Entity name was given
12887
12888 if Present (Ename) then
12889
12890 -- If entity name matches, we are fine. Save entity in
12891 -- pragma argument, for ASIS use.
12892
12893 if Chars (Ename) = Chars (Ent) then
12894 Set_Entity (Ename, Ent);
12895 Generate_Reference (Ent, Ename);
12896
12897 -- If entity name does not match, only possibility is an
12898 -- enumeration literal from an enumeration type declaration.
12899
12900 elsif Ekind (Ent) /= E_Enumeration_Type then
12901 Error_Pragma
12902 ("pragma % entity name does not match declaration");
12903
12904 else
12905 Ent := First_Literal (E);
12906 loop
12907 if No (Ent) then
12908 Error_Pragma
12909 ("pragma % entity name does not match any " &
12910 "enumeration literal");
12911
12912 elsif Chars (Ent) = Chars (Ename) then
12913 Set_Entity (Ename, Ent);
12914 Generate_Reference (Ent, Ename);
12915 exit;
12916
12917 else
12918 Ent := Next_Literal (Ent);
12919 end if;
12920 end loop;
12921 end if;
12922 end if;
12923
12924 -- Ent points to entity to be marked
12925
12926 if Arg_Count >= 1 then
12927
12928 -- Deal with static string argument
12929
12930 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12931 S := Strval (Get_Pragma_Arg (Arg1));
12932
12933 for J in 1 .. String_Length (S) loop
12934 if not In_Character_Range (Get_String_Char (S, J)) then
12935 Error_Pragma_Arg
12936 ("pragma% argument does not allow wide characters",
12937 Arg1);
12938 end if;
12939 end loop;
12940
12941 Obsolescent_Warnings.Append
12942 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
12943
12944 -- Check for Ada_05 parameter
12945
12946 if Arg_Count /= 1 then
12947 Check_Arg_Count (2);
12948
12949 declare
12950 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
12951
12952 begin
12953 Check_Arg_Is_Identifier (Argx);
12954
12955 if Chars (Argx) /= Name_Ada_05 then
12956 Error_Msg_Name_2 := Name_Ada_05;
12957 Error_Pragma_Arg
12958 ("only allowed argument for pragma% is %", Argx);
12959 end if;
12960
12961 if Ada_Version_Explicit < Ada_2005
12962 or else not Warn_On_Ada_2005_Compatibility
12963 then
12964 Active := False;
12965 end if;
12966 end;
12967 end if;
12968 end if;
12969
12970 -- Set flag if pragma active
12971
12972 if Active then
12973 Set_Is_Obsolescent (Ent);
12974 end if;
12975
12976 return;
12977 end Set_Obsolescent;
12978
12979 -- Start of processing for pragma Obsolescent
12980
12981 begin
12982 GNAT_Pragma;
12983
12984 Check_At_Most_N_Arguments (3);
12985
12986 -- See if first argument specifies an entity name
12987
12988 if Arg_Count >= 1
12989 and then
12990 (Chars (Arg1) = Name_Entity
12991 or else
12992 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
12993 N_Identifier,
12994 N_Operator_Symbol))
12995 then
12996 Ename := Get_Pragma_Arg (Arg1);
12997
12998 -- Eliminate first argument, so we can share processing
12999
13000 Arg1 := Arg2;
13001 Arg2 := Arg3;
13002 Arg_Count := Arg_Count - 1;
13003
13004 -- No Entity name argument given
13005
13006 else
13007 Ename := Empty;
13008 end if;
13009
13010 if Arg_Count >= 1 then
13011 Check_Optional_Identifier (Arg1, Name_Message);
13012
13013 if Arg_Count = 2 then
13014 Check_Optional_Identifier (Arg2, Name_Version);
13015 end if;
13016 end if;
13017
13018 -- Get immediately preceding declaration
13019
13020 Decl := Prev (N);
13021 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
13022 Prev (Decl);
13023 end loop;
13024
13025 -- Cases where we do not follow anything other than another pragma
13026
13027 if No (Decl) then
13028
13029 -- First case: library level compilation unit declaration with
13030 -- the pragma immediately following the declaration.
13031
13032 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
13033 Set_Obsolescent
13034 (Defining_Entity (Unit (Parent (Parent (N)))));
13035 return;
13036
13037 -- Case 2: library unit placement for package
13038
13039 else
13040 declare
13041 Ent : constant Entity_Id := Find_Lib_Unit_Name;
13042 begin
13043 if Is_Package_Or_Generic_Package (Ent) then
13044 Set_Obsolescent (Ent);
13045 return;
13046 end if;
13047 end;
13048 end if;
13049
13050 -- Cases where we must follow a declaration
13051
13052 else
13053 if Nkind (Decl) not in N_Declaration
13054 and then Nkind (Decl) not in N_Later_Decl_Item
13055 and then Nkind (Decl) not in N_Generic_Declaration
13056 and then Nkind (Decl) not in N_Renaming_Declaration
13057 then
13058 Error_Pragma
13059 ("pragma% misplaced, "
13060 & "must immediately follow a declaration");
13061
13062 else
13063 Set_Obsolescent (Defining_Entity (Decl));
13064 return;
13065 end if;
13066 end if;
13067 end Obsolescent;
13068
13069 --------------
13070 -- Optimize --
13071 --------------
13072
13073 -- pragma Optimize (Time | Space | Off);
13074
13075 -- The actual check for optimize is done in Gigi. Note that this
13076 -- pragma does not actually change the optimization setting, it
13077 -- simply checks that it is consistent with the pragma.
13078
13079 when Pragma_Optimize =>
13080 Check_No_Identifiers;
13081 Check_Arg_Count (1);
13082 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
13083
13084 ------------------------
13085 -- Optimize_Alignment --
13086 ------------------------
13087
13088 -- pragma Optimize_Alignment (Time | Space | Off);
13089
13090 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
13091 GNAT_Pragma;
13092 Check_No_Identifiers;
13093 Check_Arg_Count (1);
13094 Check_Valid_Configuration_Pragma;
13095
13096 declare
13097 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
13098 begin
13099 case Nam is
13100 when Name_Time =>
13101 Opt.Optimize_Alignment := 'T';
13102 when Name_Space =>
13103 Opt.Optimize_Alignment := 'S';
13104 when Name_Off =>
13105 Opt.Optimize_Alignment := 'O';
13106 when others =>
13107 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
13108 end case;
13109 end;
13110
13111 -- Set indication that mode is set locally. If we are in fact in a
13112 -- configuration pragma file, this setting is harmless since the
13113 -- switch will get reset anyway at the start of each unit.
13114
13115 Optimize_Alignment_Local := True;
13116 end Optimize_Alignment;
13117
13118 -------------------
13119 -- Overflow_Mode --
13120 -------------------
13121
13122 -- pragma Overflow_Mode
13123 -- ([General => ] MODE [, [Assertions => ] MODE]);
13124
13125 -- MODE := STRICT | MINIMIZED | ELIMINATED
13126
13127 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
13128 -- since System.Bignums makes this assumption. This is true of nearly
13129 -- all (all?) targets.
13130
13131 when Pragma_Overflow_Mode => Overflow_Mode : declare
13132 function Get_Overflow_Mode
13133 (Name : Name_Id;
13134 Arg : Node_Id) return Overflow_Mode_Type;
13135 -- Function to process one pragma argument, Arg. If an identifier
13136 -- is present, it must be Name. Mode type is returned if a valid
13137 -- argument exists, otherwise an error is signalled.
13138
13139 -----------------------
13140 -- Get_Overflow_Mode --
13141 -----------------------
13142
13143 function Get_Overflow_Mode
13144 (Name : Name_Id;
13145 Arg : Node_Id) return Overflow_Mode_Type
13146 is
13147 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
13148
13149 begin
13150 Check_Optional_Identifier (Arg, Name);
13151 Check_Arg_Is_Identifier (Argx);
13152
13153 if Chars (Argx) = Name_Strict then
13154 return Strict;
13155
13156 elsif Chars (Argx) = Name_Minimized then
13157 return Minimized;
13158
13159 elsif Chars (Argx) = Name_Eliminated then
13160 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
13161 Error_Pragma_Arg
13162 ("Eliminated not implemented on this target", Argx);
13163 else
13164 return Eliminated;
13165 end if;
13166
13167 else
13168 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
13169 end if;
13170 end Get_Overflow_Mode;
13171
13172 -- Start of processing for Overflow_Mode
13173
13174 begin
13175 GNAT_Pragma;
13176 Check_At_Least_N_Arguments (1);
13177 Check_At_Most_N_Arguments (2);
13178
13179 -- Process first argument
13180
13181 Scope_Suppress.Overflow_Mode_General :=
13182 Get_Overflow_Mode (Name_General, Arg1);
13183
13184 -- Case of only one argument
13185
13186 if Arg_Count = 1 then
13187 Scope_Suppress.Overflow_Mode_Assertions :=
13188 Scope_Suppress.Overflow_Mode_General;
13189
13190 -- Case of two arguments present
13191
13192 else
13193 Scope_Suppress.Overflow_Mode_Assertions :=
13194 Get_Overflow_Mode (Name_Assertions, Arg2);
13195 end if;
13196 end Overflow_Mode;
13197
13198 when Pragma_Overriding_Renamings =>
13199 Overriding_Renamings := True;
13200
13201 -------------
13202 -- Ordered --
13203 -------------
13204
13205 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
13206
13207 when Pragma_Ordered => Ordered : declare
13208 Assoc : constant Node_Id := Arg1;
13209 Type_Id : Node_Id;
13210 Typ : Entity_Id;
13211
13212 begin
13213 GNAT_Pragma;
13214 Check_No_Identifiers;
13215 Check_Arg_Count (1);
13216 Check_Arg_Is_Local_Name (Arg1);
13217
13218 Type_Id := Get_Pragma_Arg (Assoc);
13219 Find_Type (Type_Id);
13220 Typ := Entity (Type_Id);
13221
13222 if Typ = Any_Type then
13223 return;
13224 else
13225 Typ := Underlying_Type (Typ);
13226 end if;
13227
13228 if not Is_Enumeration_Type (Typ) then
13229 Error_Pragma ("pragma% must specify enumeration type");
13230 end if;
13231
13232 Check_First_Subtype (Arg1);
13233 Set_Has_Pragma_Ordered (Base_Type (Typ));
13234 end Ordered;
13235
13236 ----------
13237 -- Pack --
13238 ----------
13239
13240 -- pragma Pack (first_subtype_LOCAL_NAME);
13241
13242 when Pragma_Pack => Pack : declare
13243 Assoc : constant Node_Id := Arg1;
13244 Type_Id : Node_Id;
13245 Typ : Entity_Id;
13246 Ctyp : Entity_Id;
13247 Ignore : Boolean := False;
13248
13249 begin
13250 Check_No_Identifiers;
13251 Check_Arg_Count (1);
13252 Check_Arg_Is_Local_Name (Arg1);
13253
13254 Type_Id := Get_Pragma_Arg (Assoc);
13255 Find_Type (Type_Id);
13256 Typ := Entity (Type_Id);
13257
13258 if Typ = Any_Type
13259 or else Rep_Item_Too_Early (Typ, N)
13260 then
13261 return;
13262 else
13263 Typ := Underlying_Type (Typ);
13264 end if;
13265
13266 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
13267 Error_Pragma ("pragma% must specify array or record type");
13268 end if;
13269
13270 Check_First_Subtype (Arg1);
13271 Check_Duplicate_Pragma (Typ);
13272
13273 -- Array type
13274
13275 if Is_Array_Type (Typ) then
13276 Ctyp := Component_Type (Typ);
13277
13278 -- Ignore pack that does nothing
13279
13280 if Known_Static_Esize (Ctyp)
13281 and then Known_Static_RM_Size (Ctyp)
13282 and then Esize (Ctyp) = RM_Size (Ctyp)
13283 and then Addressable (Esize (Ctyp))
13284 then
13285 Ignore := True;
13286 end if;
13287
13288 -- Process OK pragma Pack. Note that if there is a separate
13289 -- component clause present, the Pack will be cancelled. This
13290 -- processing is in Freeze.
13291
13292 if not Rep_Item_Too_Late (Typ, N) then
13293
13294 -- In the context of static code analysis, we do not need
13295 -- complex front-end expansions related to pragma Pack,
13296 -- so disable handling of pragma Pack in these cases.
13297
13298 if CodePeer_Mode or Alfa_Mode then
13299 null;
13300
13301 -- Don't attempt any packing for VM targets. We possibly
13302 -- could deal with some cases of array bit-packing, but we
13303 -- don't bother, since this is not a typical kind of
13304 -- representation in the VM context anyway (and would not
13305 -- for example work nicely with the debugger).
13306
13307 elsif VM_Target /= No_VM then
13308 if not GNAT_Mode then
13309 Error_Pragma
13310 ("??pragma% ignored in this configuration");
13311 end if;
13312
13313 -- Normal case where we do the pack action
13314
13315 else
13316 if not Ignore then
13317 Set_Is_Packed (Base_Type (Typ));
13318 Set_Has_Non_Standard_Rep (Base_Type (Typ));
13319 end if;
13320
13321 Set_Has_Pragma_Pack (Base_Type (Typ));
13322 end if;
13323 end if;
13324
13325 -- For record types, the pack is always effective
13326
13327 else pragma Assert (Is_Record_Type (Typ));
13328 if not Rep_Item_Too_Late (Typ, N) then
13329
13330 -- Ignore pack request with warning in VM mode (skip warning
13331 -- if we are compiling GNAT run time library).
13332
13333 if VM_Target /= No_VM then
13334 if not GNAT_Mode then
13335 Error_Pragma
13336 ("??pragma% ignored in this configuration");
13337 end if;
13338
13339 -- Normal case of pack request active
13340
13341 else
13342 Set_Is_Packed (Base_Type (Typ));
13343 Set_Has_Pragma_Pack (Base_Type (Typ));
13344 Set_Has_Non_Standard_Rep (Base_Type (Typ));
13345 end if;
13346 end if;
13347 end if;
13348 end Pack;
13349
13350 ----------
13351 -- Page --
13352 ----------
13353
13354 -- pragma Page;
13355
13356 -- There is nothing to do here, since we did all the processing for
13357 -- this pragma in Par.Prag (so that it works properly even in syntax
13358 -- only mode).
13359
13360 when Pragma_Page =>
13361 null;
13362
13363 ----------------------------------
13364 -- Partition_Elaboration_Policy --
13365 ----------------------------------
13366
13367 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
13368
13369 when Pragma_Partition_Elaboration_Policy => declare
13370 subtype PEP_Range is Name_Id
13371 range First_Partition_Elaboration_Policy_Name
13372 .. Last_Partition_Elaboration_Policy_Name;
13373 PEP_Val : PEP_Range;
13374 PEP : Character;
13375
13376 begin
13377 Ada_2005_Pragma;
13378 Check_Arg_Count (1);
13379 Check_No_Identifiers;
13380 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
13381 Check_Valid_Configuration_Pragma;
13382 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
13383
13384 case PEP_Val is
13385 when Name_Concurrent =>
13386 PEP := 'C';
13387 when Name_Sequential =>
13388 PEP := 'S';
13389 end case;
13390
13391 if Partition_Elaboration_Policy /= ' '
13392 and then Partition_Elaboration_Policy /= PEP
13393 then
13394 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
13395 Error_Pragma
13396 ("partition elaboration policy incompatible with policy#");
13397
13398 -- Set new policy, but always preserve System_Location since we
13399 -- like the error message with the run time name.
13400
13401 else
13402 Partition_Elaboration_Policy := PEP;
13403
13404 if Partition_Elaboration_Policy_Sloc /= System_Location then
13405 Partition_Elaboration_Policy_Sloc := Loc;
13406 end if;
13407 end if;
13408 end;
13409
13410 -------------
13411 -- Passive --
13412 -------------
13413
13414 -- pragma Passive [(PASSIVE_FORM)];
13415
13416 -- PASSIVE_FORM ::= Semaphore | No
13417
13418 when Pragma_Passive =>
13419 GNAT_Pragma;
13420
13421 if Nkind (Parent (N)) /= N_Task_Definition then
13422 Error_Pragma ("pragma% must be within task definition");
13423 end if;
13424
13425 if Arg_Count /= 0 then
13426 Check_Arg_Count (1);
13427 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
13428 end if;
13429
13430 ----------------------------------
13431 -- Preelaborable_Initialization --
13432 ----------------------------------
13433
13434 -- pragma Preelaborable_Initialization (DIRECT_NAME);
13435
13436 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
13437 Ent : Entity_Id;
13438
13439 begin
13440 Ada_2005_Pragma;
13441 Check_Arg_Count (1);
13442 Check_No_Identifiers;
13443 Check_Arg_Is_Identifier (Arg1);
13444 Check_Arg_Is_Local_Name (Arg1);
13445 Check_First_Subtype (Arg1);
13446 Ent := Entity (Get_Pragma_Arg (Arg1));
13447
13448 -- The pragma may come from an aspect on a private declaration,
13449 -- even if the freeze point at which this is analyzed in the
13450 -- private part after the full view.
13451
13452 if Has_Private_Declaration (Ent)
13453 and then From_Aspect_Specification (N)
13454 then
13455 null;
13456
13457 elsif Is_Private_Type (Ent)
13458 or else Is_Protected_Type (Ent)
13459 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
13460 then
13461 null;
13462
13463 else
13464 Error_Pragma_Arg
13465 ("pragma % can only be applied to private, formal derived or "
13466 & "protected type",
13467 Arg1);
13468 end if;
13469
13470 -- Give an error if the pragma is applied to a protected type that
13471 -- does not qualify (due to having entries, or due to components
13472 -- that do not qualify).
13473
13474 if Is_Protected_Type (Ent)
13475 and then not Has_Preelaborable_Initialization (Ent)
13476 then
13477 Error_Msg_N
13478 ("protected type & does not have preelaborable " &
13479 "initialization", Ent);
13480
13481 -- Otherwise mark the type as definitely having preelaborable
13482 -- initialization.
13483
13484 else
13485 Set_Known_To_Have_Preelab_Init (Ent);
13486 end if;
13487
13488 if Has_Pragma_Preelab_Init (Ent)
13489 and then Warn_On_Redundant_Constructs
13490 then
13491 Error_Pragma ("?r?duplicate pragma%!");
13492 else
13493 Set_Has_Pragma_Preelab_Init (Ent);
13494 end if;
13495 end Preelab_Init;
13496
13497 --------------------
13498 -- Persistent_BSS --
13499 --------------------
13500
13501 -- pragma Persistent_BSS [(object_NAME)];
13502
13503 when Pragma_Persistent_BSS => Persistent_BSS : declare
13504 Decl : Node_Id;
13505 Ent : Entity_Id;
13506 Prag : Node_Id;
13507
13508 begin
13509 GNAT_Pragma;
13510 Check_At_Most_N_Arguments (1);
13511
13512 -- Case of application to specific object (one argument)
13513
13514 if Arg_Count = 1 then
13515 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13516
13517 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
13518 or else not
13519 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
13520 E_Constant)
13521 then
13522 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
13523 end if;
13524
13525 Ent := Entity (Get_Pragma_Arg (Arg1));
13526 Decl := Parent (Ent);
13527
13528 -- Check for duplication before inserting in list of
13529 -- representation items.
13530
13531 Check_Duplicate_Pragma (Ent);
13532
13533 if Rep_Item_Too_Late (Ent, N) then
13534 return;
13535 end if;
13536
13537 if Present (Expression (Decl)) then
13538 Error_Pragma_Arg
13539 ("object for pragma% cannot have initialization", Arg1);
13540 end if;
13541
13542 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
13543 Error_Pragma_Arg
13544 ("object type for pragma% is not potentially persistent",
13545 Arg1);
13546 end if;
13547
13548 Prag :=
13549 Make_Linker_Section_Pragma
13550 (Ent, Sloc (N), ".persistent.bss");
13551 Insert_After (N, Prag);
13552 Analyze (Prag);
13553
13554 -- Case of use as configuration pragma with no arguments
13555
13556 else
13557 Check_Valid_Configuration_Pragma;
13558 Persistent_BSS_Mode := True;
13559 end if;
13560 end Persistent_BSS;
13561
13562 -------------
13563 -- Polling --
13564 -------------
13565
13566 -- pragma Polling (ON | OFF);
13567
13568 when Pragma_Polling =>
13569 GNAT_Pragma;
13570 Check_Arg_Count (1);
13571 Check_No_Identifiers;
13572 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13573 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
13574
13575 -------------------
13576 -- Postcondition --
13577 -------------------
13578
13579 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
13580 -- [,[Message =>] String_EXPRESSION]);
13581
13582 when Pragma_Postcondition => Postcondition : declare
13583 In_Body : Boolean;
13584
13585 begin
13586 GNAT_Pragma;
13587 Check_At_Least_N_Arguments (1);
13588 Check_At_Most_N_Arguments (2);
13589 Check_Optional_Identifier (Arg1, Name_Check);
13590
13591 -- Verify the proper placement of the pragma. The remainder of the
13592 -- processing is found in Sem_Ch6/Sem_Ch7.
13593
13594 Check_Precondition_Postcondition (In_Body);
13595
13596 -- When the pragma is a source contruct and appears inside a body,
13597 -- preanalyze the boolean_expression to detect illegal forward
13598 -- references:
13599
13600 -- procedure P is
13601 -- pragma Postcondition (X'Old ...);
13602 -- X : ...
13603
13604 if Comes_From_Source (N) and then In_Body then
13605 Preanalyze_Spec_Expression (Expression (Arg1), Any_Boolean);
13606 end if;
13607 end Postcondition;
13608
13609 ------------------
13610 -- Precondition --
13611 ------------------
13612
13613 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
13614 -- [,[Message =>] String_EXPRESSION]);
13615
13616 when Pragma_Precondition => Precondition : declare
13617 In_Body : Boolean;
13618
13619 begin
13620 GNAT_Pragma;
13621 Check_At_Least_N_Arguments (1);
13622 Check_At_Most_N_Arguments (2);
13623 Check_Optional_Identifier (Arg1, Name_Check);
13624 Check_Precondition_Postcondition (In_Body);
13625
13626 -- If in spec, nothing more to do. If in body, then we convert the
13627 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
13628 -- this whether or not precondition checks are enabled. That works
13629 -- fine since pragma Check will do this check, and will also
13630 -- analyze the condition itself in the proper context.
13631
13632 if In_Body then
13633 Rewrite (N,
13634 Make_Pragma (Loc,
13635 Chars => Name_Check,
13636 Pragma_Argument_Associations => New_List (
13637 Make_Pragma_Argument_Association (Loc,
13638 Expression => Make_Identifier (Loc, Name_Precondition)),
13639
13640 Make_Pragma_Argument_Association (Sloc (Arg1),
13641 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
13642
13643 if Arg_Count = 2 then
13644 Append_To (Pragma_Argument_Associations (N),
13645 Make_Pragma_Argument_Association (Sloc (Arg2),
13646 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
13647 end if;
13648
13649 Analyze (N);
13650 end if;
13651 end Precondition;
13652
13653 ---------------
13654 -- Predicate --
13655 ---------------
13656
13657 -- pragma Predicate
13658 -- ([Entity =>] type_LOCAL_NAME,
13659 -- [Check =>] EXPRESSION);
13660
13661 when Pragma_Predicate => Predicate : declare
13662 Type_Id : Node_Id;
13663 Typ : Entity_Id;
13664
13665 Discard : Boolean;
13666 pragma Unreferenced (Discard);
13667
13668 begin
13669 GNAT_Pragma;
13670 Check_Arg_Count (2);
13671 Check_Optional_Identifier (Arg1, Name_Entity);
13672 Check_Optional_Identifier (Arg2, Name_Check);
13673
13674 Check_Arg_Is_Local_Name (Arg1);
13675
13676 Type_Id := Get_Pragma_Arg (Arg1);
13677 Find_Type (Type_Id);
13678 Typ := Entity (Type_Id);
13679
13680 if Typ = Any_Type then
13681 return;
13682 end if;
13683
13684 -- The remaining processing is simply to link the pragma on to
13685 -- the rep item chain, for processing when the type is frozen.
13686 -- This is accomplished by a call to Rep_Item_Too_Late. We also
13687 -- mark the type as having predicates.
13688
13689 Set_Has_Predicates (Typ);
13690 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
13691 end Predicate;
13692
13693 ------------------
13694 -- Preelaborate --
13695 ------------------
13696
13697 -- pragma Preelaborate [(library_unit_NAME)];
13698
13699 -- Set the flag Is_Preelaborated of program unit name entity
13700
13701 when Pragma_Preelaborate => Preelaborate : declare
13702 Pa : constant Node_Id := Parent (N);
13703 Pk : constant Node_Kind := Nkind (Pa);
13704 Ent : Entity_Id;
13705
13706 begin
13707 Check_Ada_83_Warning;
13708 Check_Valid_Library_Unit_Pragma;
13709
13710 if Nkind (N) = N_Null_Statement then
13711 return;
13712 end if;
13713
13714 Ent := Find_Lib_Unit_Name;
13715 Check_Duplicate_Pragma (Ent);
13716
13717 -- This filters out pragmas inside generic parent then
13718 -- show up inside instantiation
13719
13720 if Present (Ent)
13721 and then not (Pk = N_Package_Specification
13722 and then Present (Generic_Parent (Pa)))
13723 then
13724 if not Debug_Flag_U then
13725 Set_Is_Preelaborated (Ent);
13726 Set_Suppress_Elaboration_Warnings (Ent);
13727 end if;
13728 end if;
13729 end Preelaborate;
13730
13731 ---------------------
13732 -- Preelaborate_05 --
13733 ---------------------
13734
13735 -- pragma Preelaborate_05 [(library_unit_NAME)];
13736
13737 -- This pragma is useable only in GNAT_Mode, where it is used like
13738 -- pragma Preelaborate but it is only effective in Ada 2005 mode
13739 -- (otherwise it is ignored). This is used to implement AI-362 which
13740 -- recategorizes some run-time packages in Ada 2005 mode.
13741
13742 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
13743 Ent : Entity_Id;
13744
13745 begin
13746 GNAT_Pragma;
13747 Check_Valid_Library_Unit_Pragma;
13748
13749 if not GNAT_Mode then
13750 Error_Pragma ("pragma% only available in GNAT mode");
13751 end if;
13752
13753 if Nkind (N) = N_Null_Statement then
13754 return;
13755 end if;
13756
13757 -- This is one of the few cases where we need to test the value of
13758 -- Ada_Version_Explicit rather than Ada_Version (which is always
13759 -- set to Ada_2012 in a predefined unit), we need to know the
13760 -- explicit version set to know if this pragma is active.
13761
13762 if Ada_Version_Explicit >= Ada_2005 then
13763 Ent := Find_Lib_Unit_Name;
13764 Set_Is_Preelaborated (Ent);
13765 Set_Suppress_Elaboration_Warnings (Ent);
13766 end if;
13767 end Preelaborate_05;
13768
13769 --------------
13770 -- Priority --
13771 --------------
13772
13773 -- pragma Priority (EXPRESSION);
13774
13775 when Pragma_Priority => Priority : declare
13776 P : constant Node_Id := Parent (N);
13777 Arg : Node_Id;
13778 Ent : Entity_Id;
13779
13780 begin
13781 Check_No_Identifiers;
13782 Check_Arg_Count (1);
13783
13784 -- Subprogram case
13785
13786 if Nkind (P) = N_Subprogram_Body then
13787 Check_In_Main_Program;
13788
13789 Ent := Defining_Unit_Name (Specification (P));
13790
13791 if Nkind (Ent) = N_Defining_Program_Unit_Name then
13792 Ent := Defining_Identifier (Ent);
13793 end if;
13794
13795 Arg := Get_Pragma_Arg (Arg1);
13796 Analyze_And_Resolve (Arg, Standard_Integer);
13797
13798 -- Must be static
13799
13800 if not Is_Static_Expression (Arg) then
13801 Flag_Non_Static_Expr
13802 ("main subprogram priority is not static!", Arg);
13803 raise Pragma_Exit;
13804
13805 -- If constraint error, then we already signalled an error
13806
13807 elsif Raises_Constraint_Error (Arg) then
13808 null;
13809
13810 -- Otherwise check in range
13811
13812 else
13813 declare
13814 Val : constant Uint := Expr_Value (Arg);
13815
13816 begin
13817 if Val < 0
13818 or else Val > Expr_Value (Expression
13819 (Parent (RTE (RE_Max_Priority))))
13820 then
13821 Error_Pragma_Arg
13822 ("main subprogram priority is out of range", Arg1);
13823 end if;
13824 end;
13825 end if;
13826
13827 Set_Main_Priority
13828 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
13829
13830 -- Load an arbitrary entity from System.Tasking to make sure
13831 -- this package is implicitly with'ed, since we need to have
13832 -- the tasking run-time active for the pragma Priority to have
13833 -- any effect.
13834
13835 declare
13836 Discard : Entity_Id;
13837 pragma Warnings (Off, Discard);
13838 begin
13839 Discard := RTE (RE_Task_List);
13840 end;
13841
13842 -- Task or Protected, must be of type Integer
13843
13844 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
13845 Arg := Get_Pragma_Arg (Arg1);
13846 Ent := Defining_Identifier (Parent (P));
13847
13848 -- The expression must be analyzed in the special manner
13849 -- described in "Handling of Default and Per-Object
13850 -- Expressions" in sem.ads.
13851
13852 Preanalyze_Spec_Expression (Arg, Standard_Integer);
13853
13854 if not Is_Static_Expression (Arg) then
13855 Check_Restriction (Static_Priorities, Arg);
13856 end if;
13857
13858 -- Anything else is incorrect
13859
13860 else
13861 Pragma_Misplaced;
13862 end if;
13863
13864 -- Check duplicate pragma before we chain the pragma in the Rep
13865 -- Item chain of Ent.
13866
13867 Check_Duplicate_Pragma (Ent);
13868 Record_Rep_Item (Ent, N);
13869 end Priority;
13870
13871 -----------------------------------
13872 -- Priority_Specific_Dispatching --
13873 -----------------------------------
13874
13875 -- pragma Priority_Specific_Dispatching (
13876 -- policy_IDENTIFIER,
13877 -- first_priority_EXPRESSION,
13878 -- last_priority_EXPRESSION);
13879
13880 when Pragma_Priority_Specific_Dispatching =>
13881 Priority_Specific_Dispatching : declare
13882 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
13883 -- This is the entity System.Any_Priority;
13884
13885 DP : Character;
13886 Lower_Bound : Node_Id;
13887 Upper_Bound : Node_Id;
13888 Lower_Val : Uint;
13889 Upper_Val : Uint;
13890
13891 begin
13892 Ada_2005_Pragma;
13893 Check_Arg_Count (3);
13894 Check_No_Identifiers;
13895 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13896 Check_Valid_Configuration_Pragma;
13897 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13898 DP := Fold_Upper (Name_Buffer (1));
13899
13900 Lower_Bound := Get_Pragma_Arg (Arg2);
13901 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
13902 Lower_Val := Expr_Value (Lower_Bound);
13903
13904 Upper_Bound := Get_Pragma_Arg (Arg3);
13905 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
13906 Upper_Val := Expr_Value (Upper_Bound);
13907
13908 -- It is not allowed to use Task_Dispatching_Policy and
13909 -- Priority_Specific_Dispatching in the same partition.
13910
13911 if Task_Dispatching_Policy /= ' ' then
13912 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13913 Error_Pragma
13914 ("pragma% incompatible with Task_Dispatching_Policy#");
13915
13916 -- Check lower bound in range
13917
13918 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
13919 or else
13920 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
13921 then
13922 Error_Pragma_Arg
13923 ("first_priority is out of range", Arg2);
13924
13925 -- Check upper bound in range
13926
13927 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
13928 or else
13929 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
13930 then
13931 Error_Pragma_Arg
13932 ("last_priority is out of range", Arg3);
13933
13934 -- Check that the priority range is valid
13935
13936 elsif Lower_Val > Upper_Val then
13937 Error_Pragma
13938 ("last_priority_expression must be greater than" &
13939 " or equal to first_priority_expression");
13940
13941 -- Store the new policy, but always preserve System_Location since
13942 -- we like the error message with the run-time name.
13943
13944 else
13945 -- Check overlapping in the priority ranges specified in other
13946 -- Priority_Specific_Dispatching pragmas within the same
13947 -- partition. We can only check those we know about!
13948
13949 for J in
13950 Specific_Dispatching.First .. Specific_Dispatching.Last
13951 loop
13952 if Specific_Dispatching.Table (J).First_Priority in
13953 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
13954 or else Specific_Dispatching.Table (J).Last_Priority in
13955 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
13956 then
13957 Error_Msg_Sloc :=
13958 Specific_Dispatching.Table (J).Pragma_Loc;
13959 Error_Pragma
13960 ("priority range overlaps with "
13961 & "Priority_Specific_Dispatching#");
13962 end if;
13963 end loop;
13964
13965 -- The use of Priority_Specific_Dispatching is incompatible
13966 -- with Task_Dispatching_Policy.
13967
13968 if Task_Dispatching_Policy /= ' ' then
13969 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13970 Error_Pragma
13971 ("Priority_Specific_Dispatching incompatible "
13972 & "with Task_Dispatching_Policy#");
13973 end if;
13974
13975 -- The use of Priority_Specific_Dispatching forces ceiling
13976 -- locking policy.
13977
13978 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
13979 Error_Msg_Sloc := Locking_Policy_Sloc;
13980 Error_Pragma
13981 ("Priority_Specific_Dispatching incompatible "
13982 & "with Locking_Policy#");
13983
13984 -- Set the Ceiling_Locking policy, but preserve System_Location
13985 -- since we like the error message with the run time name.
13986
13987 else
13988 Locking_Policy := 'C';
13989
13990 if Locking_Policy_Sloc /= System_Location then
13991 Locking_Policy_Sloc := Loc;
13992 end if;
13993 end if;
13994
13995 -- Add entry in the table
13996
13997 Specific_Dispatching.Append
13998 ((Dispatching_Policy => DP,
13999 First_Priority => UI_To_Int (Lower_Val),
14000 Last_Priority => UI_To_Int (Upper_Val),
14001 Pragma_Loc => Loc));
14002 end if;
14003 end Priority_Specific_Dispatching;
14004
14005 -------------
14006 -- Profile --
14007 -------------
14008
14009 -- pragma Profile (profile_IDENTIFIER);
14010
14011 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
14012
14013 when Pragma_Profile =>
14014 Ada_2005_Pragma;
14015 Check_Arg_Count (1);
14016 Check_Valid_Configuration_Pragma;
14017 Check_No_Identifiers;
14018
14019 declare
14020 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14021
14022 begin
14023 if Chars (Argx) = Name_Ravenscar then
14024 Set_Ravenscar_Profile (N);
14025
14026 elsif Chars (Argx) = Name_Restricted then
14027 Set_Profile_Restrictions
14028 (Restricted,
14029 N, Warn => Treat_Restrictions_As_Warnings);
14030
14031 elsif Chars (Argx) = Name_Rational then
14032 Set_Rational_Profile;
14033
14034 elsif Chars (Argx) = Name_No_Implementation_Extensions then
14035 Set_Profile_Restrictions
14036 (No_Implementation_Extensions,
14037 N, Warn => Treat_Restrictions_As_Warnings);
14038
14039 else
14040 Error_Pragma_Arg ("& is not a valid profile", Argx);
14041 end if;
14042 end;
14043
14044 ----------------------
14045 -- Profile_Warnings --
14046 ----------------------
14047
14048 -- pragma Profile_Warnings (profile_IDENTIFIER);
14049
14050 -- profile_IDENTIFIER => Restricted | Ravenscar
14051
14052 when Pragma_Profile_Warnings =>
14053 GNAT_Pragma;
14054 Check_Arg_Count (1);
14055 Check_Valid_Configuration_Pragma;
14056 Check_No_Identifiers;
14057
14058 declare
14059 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14060
14061 begin
14062 if Chars (Argx) = Name_Ravenscar then
14063 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
14064
14065 elsif Chars (Argx) = Name_Restricted then
14066 Set_Profile_Restrictions (Restricted, N, Warn => True);
14067
14068 elsif Chars (Argx) = Name_No_Implementation_Extensions then
14069 Set_Profile_Restrictions
14070 (No_Implementation_Extensions, N, Warn => True);
14071
14072 else
14073 Error_Pragma_Arg ("& is not a valid profile", Argx);
14074 end if;
14075 end;
14076
14077 --------------------------
14078 -- Propagate_Exceptions --
14079 --------------------------
14080
14081 -- pragma Propagate_Exceptions;
14082
14083 -- Note: this pragma is obsolete and has no effect
14084
14085 when Pragma_Propagate_Exceptions =>
14086 GNAT_Pragma;
14087 Check_Arg_Count (0);
14088
14089 if In_Extended_Main_Source_Unit (N) then
14090 Propagate_Exceptions := True;
14091 end if;
14092
14093 ------------------
14094 -- Psect_Object --
14095 ------------------
14096
14097 -- pragma Psect_Object (
14098 -- [Internal =>] LOCAL_NAME,
14099 -- [, [External =>] EXTERNAL_SYMBOL]
14100 -- [, [Size =>] EXTERNAL_SYMBOL]);
14101
14102 when Pragma_Psect_Object | Pragma_Common_Object =>
14103 Psect_Object : declare
14104 Args : Args_List (1 .. 3);
14105 Names : constant Name_List (1 .. 3) := (
14106 Name_Internal,
14107 Name_External,
14108 Name_Size);
14109
14110 Internal : Node_Id renames Args (1);
14111 External : Node_Id renames Args (2);
14112 Size : Node_Id renames Args (3);
14113
14114 Def_Id : Entity_Id;
14115
14116 procedure Check_Too_Long (Arg : Node_Id);
14117 -- Posts message if the argument is an identifier with more
14118 -- than 31 characters, or a string literal with more than
14119 -- 31 characters, and we are operating under VMS
14120
14121 --------------------
14122 -- Check_Too_Long --
14123 --------------------
14124
14125 procedure Check_Too_Long (Arg : Node_Id) is
14126 X : constant Node_Id := Original_Node (Arg);
14127
14128 begin
14129 if not Nkind_In (X, N_String_Literal, N_Identifier) then
14130 Error_Pragma_Arg
14131 ("inappropriate argument for pragma %", Arg);
14132 end if;
14133
14134 if OpenVMS_On_Target then
14135 if (Nkind (X) = N_String_Literal
14136 and then String_Length (Strval (X)) > 31)
14137 or else
14138 (Nkind (X) = N_Identifier
14139 and then Length_Of_Name (Chars (X)) > 31)
14140 then
14141 Error_Pragma_Arg
14142 ("argument for pragma % is longer than 31 characters",
14143 Arg);
14144 end if;
14145 end if;
14146 end Check_Too_Long;
14147
14148 -- Start of processing for Common_Object/Psect_Object
14149
14150 begin
14151 GNAT_Pragma;
14152 Gather_Associations (Names, Args);
14153 Process_Extended_Import_Export_Internal_Arg (Internal);
14154
14155 Def_Id := Entity (Internal);
14156
14157 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
14158 Error_Pragma_Arg
14159 ("pragma% must designate an object", Internal);
14160 end if;
14161
14162 Check_Too_Long (Internal);
14163
14164 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
14165 Error_Pragma_Arg
14166 ("cannot use pragma% for imported/exported object",
14167 Internal);
14168 end if;
14169
14170 if Is_Concurrent_Type (Etype (Internal)) then
14171 Error_Pragma_Arg
14172 ("cannot specify pragma % for task/protected object",
14173 Internal);
14174 end if;
14175
14176 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
14177 or else
14178 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
14179 then
14180 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
14181 end if;
14182
14183 if Ekind (Def_Id) = E_Constant then
14184 Error_Pragma_Arg
14185 ("cannot specify pragma % for a constant", Internal);
14186 end if;
14187
14188 if Is_Record_Type (Etype (Internal)) then
14189 declare
14190 Ent : Entity_Id;
14191 Decl : Entity_Id;
14192
14193 begin
14194 Ent := First_Entity (Etype (Internal));
14195 while Present (Ent) loop
14196 Decl := Declaration_Node (Ent);
14197
14198 if Ekind (Ent) = E_Component
14199 and then Nkind (Decl) = N_Component_Declaration
14200 and then Present (Expression (Decl))
14201 and then Warn_On_Export_Import
14202 then
14203 Error_Msg_N
14204 ("?x?object for pragma % has defaults", Internal);
14205 exit;
14206
14207 else
14208 Next_Entity (Ent);
14209 end if;
14210 end loop;
14211 end;
14212 end if;
14213
14214 if Present (Size) then
14215 Check_Too_Long (Size);
14216 end if;
14217
14218 if Present (External) then
14219 Check_Arg_Is_External_Name (External);
14220 Check_Too_Long (External);
14221 end if;
14222
14223 -- If all error tests pass, link pragma on to the rep item chain
14224
14225 Record_Rep_Item (Def_Id, N);
14226 end Psect_Object;
14227
14228 ----------
14229 -- Pure --
14230 ----------
14231
14232 -- pragma Pure [(library_unit_NAME)];
14233
14234 when Pragma_Pure => Pure : declare
14235 Ent : Entity_Id;
14236
14237 begin
14238 Check_Ada_83_Warning;
14239 Check_Valid_Library_Unit_Pragma;
14240
14241 if Nkind (N) = N_Null_Statement then
14242 return;
14243 end if;
14244
14245 Ent := Find_Lib_Unit_Name;
14246 Set_Is_Pure (Ent);
14247 Set_Has_Pragma_Pure (Ent);
14248 Set_Suppress_Elaboration_Warnings (Ent);
14249 end Pure;
14250
14251 -------------
14252 -- Pure_05 --
14253 -------------
14254
14255 -- pragma Pure_05 [(library_unit_NAME)];
14256
14257 -- This pragma is useable only in GNAT_Mode, where it is used like
14258 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
14259 -- it is ignored). It may be used after a pragma Preelaborate, in
14260 -- which case it overrides the effect of the pragma Preelaborate.
14261 -- This is used to implement AI-362 which recategorizes some run-time
14262 -- packages in Ada 2005 mode.
14263
14264 when Pragma_Pure_05 => Pure_05 : declare
14265 Ent : Entity_Id;
14266
14267 begin
14268 GNAT_Pragma;
14269 Check_Valid_Library_Unit_Pragma;
14270
14271 if not GNAT_Mode then
14272 Error_Pragma ("pragma% only available in GNAT mode");
14273 end if;
14274
14275 if Nkind (N) = N_Null_Statement then
14276 return;
14277 end if;
14278
14279 -- This is one of the few cases where we need to test the value of
14280 -- Ada_Version_Explicit rather than Ada_Version (which is always
14281 -- set to Ada_2012 in a predefined unit), we need to know the
14282 -- explicit version set to know if this pragma is active.
14283
14284 if Ada_Version_Explicit >= Ada_2005 then
14285 Ent := Find_Lib_Unit_Name;
14286 Set_Is_Preelaborated (Ent, False);
14287 Set_Is_Pure (Ent);
14288 Set_Suppress_Elaboration_Warnings (Ent);
14289 end if;
14290 end Pure_05;
14291
14292 -------------
14293 -- Pure_12 --
14294 -------------
14295
14296 -- pragma Pure_12 [(library_unit_NAME)];
14297
14298 -- This pragma is useable only in GNAT_Mode, where it is used like
14299 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
14300 -- it is ignored). It may be used after a pragma Preelaborate, in
14301 -- which case it overrides the effect of the pragma Preelaborate.
14302 -- This is used to implement AI05-0212 which recategorizes some
14303 -- run-time packages in Ada 2012 mode.
14304
14305 when Pragma_Pure_12 => Pure_12 : declare
14306 Ent : Entity_Id;
14307
14308 begin
14309 GNAT_Pragma;
14310 Check_Valid_Library_Unit_Pragma;
14311
14312 if not GNAT_Mode then
14313 Error_Pragma ("pragma% only available in GNAT mode");
14314 end if;
14315
14316 if Nkind (N) = N_Null_Statement then
14317 return;
14318 end if;
14319
14320 -- This is one of the few cases where we need to test the value of
14321 -- Ada_Version_Explicit rather than Ada_Version (which is always
14322 -- set to Ada_2012 in a predefined unit), we need to know the
14323 -- explicit version set to know if this pragma is active.
14324
14325 if Ada_Version_Explicit >= Ada_2012 then
14326 Ent := Find_Lib_Unit_Name;
14327 Set_Is_Preelaborated (Ent, False);
14328 Set_Is_Pure (Ent);
14329 Set_Suppress_Elaboration_Warnings (Ent);
14330 end if;
14331 end Pure_12;
14332
14333 -------------------
14334 -- Pure_Function --
14335 -------------------
14336
14337 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
14338
14339 when Pragma_Pure_Function => Pure_Function : declare
14340 E_Id : Node_Id;
14341 E : Entity_Id;
14342 Def_Id : Entity_Id;
14343 Effective : Boolean := False;
14344
14345 begin
14346 GNAT_Pragma;
14347 Check_Arg_Count (1);
14348 Check_Optional_Identifier (Arg1, Name_Entity);
14349 Check_Arg_Is_Local_Name (Arg1);
14350 E_Id := Get_Pragma_Arg (Arg1);
14351
14352 if Error_Posted (E_Id) then
14353 return;
14354 end if;
14355
14356 -- Loop through homonyms (overloadings) of referenced entity
14357
14358 E := Entity (E_Id);
14359
14360 if Present (E) then
14361 loop
14362 Def_Id := Get_Base_Subprogram (E);
14363
14364 if not Ekind_In (Def_Id, E_Function,
14365 E_Generic_Function,
14366 E_Operator)
14367 then
14368 Error_Pragma_Arg
14369 ("pragma% requires a function name", Arg1);
14370 end if;
14371
14372 Set_Is_Pure (Def_Id);
14373
14374 if not Has_Pragma_Pure_Function (Def_Id) then
14375 Set_Has_Pragma_Pure_Function (Def_Id);
14376 Effective := True;
14377 end if;
14378
14379 exit when From_Aspect_Specification (N);
14380 E := Homonym (E);
14381 exit when No (E) or else Scope (E) /= Current_Scope;
14382 end loop;
14383
14384 if not Effective
14385 and then Warn_On_Redundant_Constructs
14386 then
14387 Error_Msg_NE
14388 ("pragma Pure_Function on& is redundant?r?",
14389 N, Entity (E_Id));
14390 end if;
14391 end if;
14392 end Pure_Function;
14393
14394 --------------------
14395 -- Queuing_Policy --
14396 --------------------
14397
14398 -- pragma Queuing_Policy (policy_IDENTIFIER);
14399
14400 when Pragma_Queuing_Policy => declare
14401 QP : Character;
14402
14403 begin
14404 Check_Ada_83_Warning;
14405 Check_Arg_Count (1);
14406 Check_No_Identifiers;
14407 Check_Arg_Is_Queuing_Policy (Arg1);
14408 Check_Valid_Configuration_Pragma;
14409 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
14410 QP := Fold_Upper (Name_Buffer (1));
14411
14412 if Queuing_Policy /= ' '
14413 and then Queuing_Policy /= QP
14414 then
14415 Error_Msg_Sloc := Queuing_Policy_Sloc;
14416 Error_Pragma ("queuing policy incompatible with policy#");
14417
14418 -- Set new policy, but always preserve System_Location since we
14419 -- like the error message with the run time name.
14420
14421 else
14422 Queuing_Policy := QP;
14423
14424 if Queuing_Policy_Sloc /= System_Location then
14425 Queuing_Policy_Sloc := Loc;
14426 end if;
14427 end if;
14428 end;
14429
14430 --------------
14431 -- Rational --
14432 --------------
14433
14434 -- pragma Rational, for compatibility with foreign compiler
14435
14436 when Pragma_Rational =>
14437 Set_Rational_Profile;
14438
14439 -----------------------
14440 -- Relative_Deadline --
14441 -----------------------
14442
14443 -- pragma Relative_Deadline (time_span_EXPRESSION);
14444
14445 when Pragma_Relative_Deadline => Relative_Deadline : declare
14446 P : constant Node_Id := Parent (N);
14447 Arg : Node_Id;
14448
14449 begin
14450 Ada_2005_Pragma;
14451 Check_No_Identifiers;
14452 Check_Arg_Count (1);
14453
14454 Arg := Get_Pragma_Arg (Arg1);
14455
14456 -- The expression must be analyzed in the special manner described
14457 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
14458
14459 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
14460
14461 -- Subprogram case
14462
14463 if Nkind (P) = N_Subprogram_Body then
14464 Check_In_Main_Program;
14465
14466 -- Only Task and subprogram cases allowed
14467
14468 elsif Nkind (P) /= N_Task_Definition then
14469 Pragma_Misplaced;
14470 end if;
14471
14472 -- Check duplicate pragma before we set the corresponding flag
14473
14474 if Has_Relative_Deadline_Pragma (P) then
14475 Error_Pragma ("duplicate pragma% not allowed");
14476 end if;
14477
14478 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
14479 -- Relative_Deadline pragma node cannot be inserted in the Rep
14480 -- Item chain of Ent since it is rewritten by the expander as a
14481 -- procedure call statement that will break the chain.
14482
14483 Set_Has_Relative_Deadline_Pragma (P, True);
14484 end Relative_Deadline;
14485
14486 ------------------------
14487 -- Remote_Access_Type --
14488 ------------------------
14489
14490 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
14491
14492 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
14493 E : Entity_Id;
14494
14495 begin
14496 GNAT_Pragma;
14497 Check_Arg_Count (1);
14498 Check_Optional_Identifier (Arg1, Name_Entity);
14499 Check_Arg_Is_Local_Name (Arg1);
14500
14501 E := Entity (Get_Pragma_Arg (Arg1));
14502
14503 if Nkind (Parent (E)) = N_Formal_Type_Declaration
14504 and then Ekind (E) = E_General_Access_Type
14505 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
14506 and then Scope (Root_Type (Directly_Designated_Type (E)))
14507 = Scope (E)
14508 and then Is_Valid_Remote_Object_Type
14509 (Root_Type (Directly_Designated_Type (E)))
14510 then
14511 Set_Is_Remote_Types (E);
14512
14513 else
14514 Error_Pragma_Arg
14515 ("pragma% applies only to formal access to classwide types",
14516 Arg1);
14517 end if;
14518 end Remote_Access_Type;
14519
14520 ---------------------------
14521 -- Remote_Call_Interface --
14522 ---------------------------
14523
14524 -- pragma Remote_Call_Interface [(library_unit_NAME)];
14525
14526 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
14527 Cunit_Node : Node_Id;
14528 Cunit_Ent : Entity_Id;
14529 K : Node_Kind;
14530
14531 begin
14532 Check_Ada_83_Warning;
14533 Check_Valid_Library_Unit_Pragma;
14534
14535 if Nkind (N) = N_Null_Statement then
14536 return;
14537 end if;
14538
14539 Cunit_Node := Cunit (Current_Sem_Unit);
14540 K := Nkind (Unit (Cunit_Node));
14541 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
14542
14543 if K = N_Package_Declaration
14544 or else K = N_Generic_Package_Declaration
14545 or else K = N_Subprogram_Declaration
14546 or else K = N_Generic_Subprogram_Declaration
14547 or else (K = N_Subprogram_Body
14548 and then Acts_As_Spec (Unit (Cunit_Node)))
14549 then
14550 null;
14551 else
14552 Error_Pragma (
14553 "pragma% must apply to package or subprogram declaration");
14554 end if;
14555
14556 Set_Is_Remote_Call_Interface (Cunit_Ent);
14557 end Remote_Call_Interface;
14558
14559 ------------------
14560 -- Remote_Types --
14561 ------------------
14562
14563 -- pragma Remote_Types [(library_unit_NAME)];
14564
14565 when Pragma_Remote_Types => Remote_Types : declare
14566 Cunit_Node : Node_Id;
14567 Cunit_Ent : Entity_Id;
14568
14569 begin
14570 Check_Ada_83_Warning;
14571 Check_Valid_Library_Unit_Pragma;
14572
14573 if Nkind (N) = N_Null_Statement then
14574 return;
14575 end if;
14576
14577 Cunit_Node := Cunit (Current_Sem_Unit);
14578 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
14579
14580 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
14581 N_Generic_Package_Declaration)
14582 then
14583 Error_Pragma
14584 ("pragma% can only apply to a package declaration");
14585 end if;
14586
14587 Set_Is_Remote_Types (Cunit_Ent);
14588 end Remote_Types;
14589
14590 ---------------
14591 -- Ravenscar --
14592 ---------------
14593
14594 -- pragma Ravenscar;
14595
14596 when Pragma_Ravenscar =>
14597 GNAT_Pragma;
14598 Check_Arg_Count (0);
14599 Check_Valid_Configuration_Pragma;
14600 Set_Ravenscar_Profile (N);
14601
14602 if Warn_On_Obsolescent_Feature then
14603 Error_Msg_N
14604 ("pragma Ravenscar is an obsolescent feature?j?", N);
14605 Error_Msg_N
14606 ("|use pragma Profile (Ravenscar) instead?j?", N);
14607 end if;
14608
14609 -------------------------
14610 -- Restricted_Run_Time --
14611 -------------------------
14612
14613 -- pragma Restricted_Run_Time;
14614
14615 when Pragma_Restricted_Run_Time =>
14616 GNAT_Pragma;
14617 Check_Arg_Count (0);
14618 Check_Valid_Configuration_Pragma;
14619 Set_Profile_Restrictions
14620 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
14621
14622 if Warn_On_Obsolescent_Feature then
14623 Error_Msg_N
14624 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
14625 N);
14626 Error_Msg_N
14627 ("|use pragma Profile (Restricted) instead?j?", N);
14628 end if;
14629
14630 ------------------
14631 -- Restrictions --
14632 ------------------
14633
14634 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
14635
14636 -- RESTRICTION ::=
14637 -- restriction_IDENTIFIER
14638 -- | restriction_parameter_IDENTIFIER => EXPRESSION
14639
14640 when Pragma_Restrictions =>
14641 Process_Restrictions_Or_Restriction_Warnings
14642 (Warn => Treat_Restrictions_As_Warnings);
14643
14644 --------------------------
14645 -- Restriction_Warnings --
14646 --------------------------
14647
14648 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
14649
14650 -- RESTRICTION ::=
14651 -- restriction_IDENTIFIER
14652 -- | restriction_parameter_IDENTIFIER => EXPRESSION
14653
14654 when Pragma_Restriction_Warnings =>
14655 GNAT_Pragma;
14656 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
14657
14658 ----------------
14659 -- Reviewable --
14660 ----------------
14661
14662 -- pragma Reviewable;
14663
14664 when Pragma_Reviewable =>
14665 Check_Ada_83_Warning;
14666 Check_Arg_Count (0);
14667
14668 -- Call dummy debugging function rv. This is done to assist front
14669 -- end debugging. By placing a Reviewable pragma in the source
14670 -- program, a breakpoint on rv catches this place in the source,
14671 -- allowing convenient stepping to the point of interest.
14672
14673 rv;
14674
14675 --------------------------
14676 -- Short_Circuit_And_Or --
14677 --------------------------
14678
14679 when Pragma_Short_Circuit_And_Or =>
14680 GNAT_Pragma;
14681 Check_Arg_Count (0);
14682 Check_Valid_Configuration_Pragma;
14683 Short_Circuit_And_Or := True;
14684
14685 -------------------
14686 -- Share_Generic --
14687 -------------------
14688
14689 -- pragma Share_Generic (NAME {, NAME});
14690
14691 when Pragma_Share_Generic =>
14692 GNAT_Pragma;
14693 Process_Generic_List;
14694
14695 ------------
14696 -- Shared --
14697 ------------
14698
14699 -- pragma Shared (LOCAL_NAME);
14700
14701 when Pragma_Shared =>
14702 GNAT_Pragma;
14703 Process_Atomic_Shared_Volatile;
14704
14705 --------------------
14706 -- Shared_Passive --
14707 --------------------
14708
14709 -- pragma Shared_Passive [(library_unit_NAME)];
14710
14711 -- Set the flag Is_Shared_Passive of program unit name entity
14712
14713 when Pragma_Shared_Passive => Shared_Passive : declare
14714 Cunit_Node : Node_Id;
14715 Cunit_Ent : Entity_Id;
14716
14717 begin
14718 Check_Ada_83_Warning;
14719 Check_Valid_Library_Unit_Pragma;
14720
14721 if Nkind (N) = N_Null_Statement then
14722 return;
14723 end if;
14724
14725 Cunit_Node := Cunit (Current_Sem_Unit);
14726 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
14727
14728 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
14729 N_Generic_Package_Declaration)
14730 then
14731 Error_Pragma
14732 ("pragma% can only apply to a package declaration");
14733 end if;
14734
14735 Set_Is_Shared_Passive (Cunit_Ent);
14736 end Shared_Passive;
14737
14738 -----------------------
14739 -- Short_Descriptors --
14740 -----------------------
14741
14742 -- pragma Short_Descriptors;
14743
14744 when Pragma_Short_Descriptors =>
14745 GNAT_Pragma;
14746 Check_Arg_Count (0);
14747 Check_Valid_Configuration_Pragma;
14748 Short_Descriptors := True;
14749
14750 ------------------------------
14751 -- Simple_Storage_Pool_Type --
14752 ------------------------------
14753
14754 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
14755
14756 when Pragma_Simple_Storage_Pool_Type =>
14757 Simple_Storage_Pool_Type : declare
14758 Type_Id : Node_Id;
14759 Typ : Entity_Id;
14760
14761 begin
14762 GNAT_Pragma;
14763 Check_Arg_Count (1);
14764 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14765
14766 Type_Id := Get_Pragma_Arg (Arg1);
14767 Find_Type (Type_Id);
14768 Typ := Entity (Type_Id);
14769
14770 if Typ = Any_Type then
14771 return;
14772 end if;
14773
14774 -- We require the pragma to apply to a type declared in a package
14775 -- declaration, but not (immediately) within a package body.
14776
14777 if Ekind (Current_Scope) /= E_Package
14778 or else In_Package_Body (Current_Scope)
14779 then
14780 Error_Pragma
14781 ("pragma% can only apply to type declared immediately " &
14782 "within a package declaration");
14783 end if;
14784
14785 -- A simple storage pool type must be an immutably limited record
14786 -- or private type. If the pragma is given for a private type,
14787 -- the full type is similarly restricted (which is checked later
14788 -- in Freeze_Entity).
14789
14790 if Is_Record_Type (Typ)
14791 and then not Is_Immutably_Limited_Type (Typ)
14792 then
14793 Error_Pragma
14794 ("pragma% can only apply to explicitly limited record type");
14795
14796 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
14797 Error_Pragma
14798 ("pragma% can only apply to a private type that is limited");
14799
14800 elsif not Is_Record_Type (Typ)
14801 and then not Is_Private_Type (Typ)
14802 then
14803 Error_Pragma
14804 ("pragma% can only apply to limited record or private type");
14805 end if;
14806
14807 Record_Rep_Item (Typ, N);
14808 end Simple_Storage_Pool_Type;
14809
14810 ----------------------
14811 -- Source_File_Name --
14812 ----------------------
14813
14814 -- There are five forms for this pragma:
14815
14816 -- pragma Source_File_Name (
14817 -- [UNIT_NAME =>] unit_NAME,
14818 -- BODY_FILE_NAME => STRING_LITERAL
14819 -- [, [INDEX =>] INTEGER_LITERAL]);
14820
14821 -- pragma Source_File_Name (
14822 -- [UNIT_NAME =>] unit_NAME,
14823 -- SPEC_FILE_NAME => STRING_LITERAL
14824 -- [, [INDEX =>] INTEGER_LITERAL]);
14825
14826 -- pragma Source_File_Name (
14827 -- BODY_FILE_NAME => STRING_LITERAL
14828 -- [, DOT_REPLACEMENT => STRING_LITERAL]
14829 -- [, CASING => CASING_SPEC]);
14830
14831 -- pragma Source_File_Name (
14832 -- SPEC_FILE_NAME => STRING_LITERAL
14833 -- [, DOT_REPLACEMENT => STRING_LITERAL]
14834 -- [, CASING => CASING_SPEC]);
14835
14836 -- pragma Source_File_Name (
14837 -- SUBUNIT_FILE_NAME => STRING_LITERAL
14838 -- [, DOT_REPLACEMENT => STRING_LITERAL]
14839 -- [, CASING => CASING_SPEC]);
14840
14841 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
14842
14843 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
14844 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
14845 -- only be used when no project file is used, while SFNP can only be
14846 -- used when a project file is used.
14847
14848 -- No processing here. Processing was completed during parsing, since
14849 -- we need to have file names set as early as possible. Units are
14850 -- loaded well before semantic processing starts.
14851
14852 -- The only processing we defer to this point is the check for
14853 -- correct placement.
14854
14855 when Pragma_Source_File_Name =>
14856 GNAT_Pragma;
14857 Check_Valid_Configuration_Pragma;
14858
14859 ------------------------------
14860 -- Source_File_Name_Project --
14861 ------------------------------
14862
14863 -- See Source_File_Name for syntax
14864
14865 -- No processing here. Processing was completed during parsing, since
14866 -- we need to have file names set as early as possible. Units are
14867 -- loaded well before semantic processing starts.
14868
14869 -- The only processing we defer to this point is the check for
14870 -- correct placement.
14871
14872 when Pragma_Source_File_Name_Project =>
14873 GNAT_Pragma;
14874 Check_Valid_Configuration_Pragma;
14875
14876 -- Check that a pragma Source_File_Name_Project is used only in a
14877 -- configuration pragmas file.
14878
14879 -- Pragmas Source_File_Name_Project should only be generated by
14880 -- the Project Manager in configuration pragmas files.
14881
14882 -- This is really an ugly test. It seems to depend on some
14883 -- accidental and undocumented property. At the very least it
14884 -- needs to be documented, but it would be better to have a
14885 -- clean way of testing if we are in a configuration file???
14886
14887 if Present (Parent (N)) then
14888 Error_Pragma
14889 ("pragma% can only appear in a configuration pragmas file");
14890 end if;
14891
14892 ----------------------
14893 -- Source_Reference --
14894 ----------------------
14895
14896 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
14897
14898 -- Nothing to do, all processing completed in Par.Prag, since we need
14899 -- the information for possible parser messages that are output.
14900
14901 when Pragma_Source_Reference =>
14902 GNAT_Pragma;
14903
14904 --------------------------------
14905 -- Static_Elaboration_Desired --
14906 --------------------------------
14907
14908 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
14909
14910 when Pragma_Static_Elaboration_Desired =>
14911 GNAT_Pragma;
14912 Check_At_Most_N_Arguments (1);
14913
14914 if Is_Compilation_Unit (Current_Scope)
14915 and then Ekind (Current_Scope) = E_Package
14916 then
14917 Set_Static_Elaboration_Desired (Current_Scope, True);
14918 else
14919 Error_Pragma ("pragma% must apply to a library-level package");
14920 end if;
14921
14922 ------------------
14923 -- Storage_Size --
14924 ------------------
14925
14926 -- pragma Storage_Size (EXPRESSION);
14927
14928 when Pragma_Storage_Size => Storage_Size : declare
14929 P : constant Node_Id := Parent (N);
14930 Arg : Node_Id;
14931
14932 begin
14933 Check_No_Identifiers;
14934 Check_Arg_Count (1);
14935
14936 -- The expression must be analyzed in the special manner described
14937 -- in "Handling of Default Expressions" in sem.ads.
14938
14939 Arg := Get_Pragma_Arg (Arg1);
14940 Preanalyze_Spec_Expression (Arg, Any_Integer);
14941
14942 if not Is_Static_Expression (Arg) then
14943 Check_Restriction (Static_Storage_Size, Arg);
14944 end if;
14945
14946 if Nkind (P) /= N_Task_Definition then
14947 Pragma_Misplaced;
14948 return;
14949
14950 else
14951 if Has_Storage_Size_Pragma (P) then
14952 Error_Pragma ("duplicate pragma% not allowed");
14953 else
14954 Set_Has_Storage_Size_Pragma (P, True);
14955 end if;
14956
14957 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
14958 end if;
14959 end Storage_Size;
14960
14961 ------------------
14962 -- Storage_Unit --
14963 ------------------
14964
14965 -- pragma Storage_Unit (NUMERIC_LITERAL);
14966
14967 -- Only permitted argument is System'Storage_Unit value
14968
14969 when Pragma_Storage_Unit =>
14970 Check_No_Identifiers;
14971 Check_Arg_Count (1);
14972 Check_Arg_Is_Integer_Literal (Arg1);
14973
14974 if Intval (Get_Pragma_Arg (Arg1)) /=
14975 UI_From_Int (Ttypes.System_Storage_Unit)
14976 then
14977 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
14978 Error_Pragma_Arg
14979 ("the only allowed argument for pragma% is ^", Arg1);
14980 end if;
14981
14982 --------------------
14983 -- Stream_Convert --
14984 --------------------
14985
14986 -- pragma Stream_Convert (
14987 -- [Entity =>] type_LOCAL_NAME,
14988 -- [Read =>] function_NAME,
14989 -- [Write =>] function NAME);
14990
14991 when Pragma_Stream_Convert => Stream_Convert : declare
14992
14993 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
14994 -- Check that the given argument is the name of a local function
14995 -- of one argument that is not overloaded earlier in the current
14996 -- local scope. A check is also made that the argument is a
14997 -- function with one parameter.
14998
14999 --------------------------------------
15000 -- Check_OK_Stream_Convert_Function --
15001 --------------------------------------
15002
15003 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
15004 Ent : Entity_Id;
15005
15006 begin
15007 Check_Arg_Is_Local_Name (Arg);
15008 Ent := Entity (Get_Pragma_Arg (Arg));
15009
15010 if Has_Homonym (Ent) then
15011 Error_Pragma_Arg
15012 ("argument for pragma% may not be overloaded", Arg);
15013 end if;
15014
15015 if Ekind (Ent) /= E_Function
15016 or else No (First_Formal (Ent))
15017 or else Present (Next_Formal (First_Formal (Ent)))
15018 then
15019 Error_Pragma_Arg
15020 ("argument for pragma% must be" &
15021 " function of one argument", Arg);
15022 end if;
15023 end Check_OK_Stream_Convert_Function;
15024
15025 -- Start of processing for Stream_Convert
15026
15027 begin
15028 GNAT_Pragma;
15029 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
15030 Check_Arg_Count (3);
15031 Check_Optional_Identifier (Arg1, Name_Entity);
15032 Check_Optional_Identifier (Arg2, Name_Read);
15033 Check_Optional_Identifier (Arg3, Name_Write);
15034 Check_Arg_Is_Local_Name (Arg1);
15035 Check_OK_Stream_Convert_Function (Arg2);
15036 Check_OK_Stream_Convert_Function (Arg3);
15037
15038 declare
15039 Typ : constant Entity_Id :=
15040 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
15041 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
15042 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
15043
15044 begin
15045 Check_First_Subtype (Arg1);
15046
15047 -- Check for too early or too late. Note that we don't enforce
15048 -- the rule about primitive operations in this case, since, as
15049 -- is the case for explicit stream attributes themselves, these
15050 -- restrictions are not appropriate. Note that the chaining of
15051 -- the pragma by Rep_Item_Too_Late is actually the critical
15052 -- processing done for this pragma.
15053
15054 if Rep_Item_Too_Early (Typ, N)
15055 or else
15056 Rep_Item_Too_Late (Typ, N, FOnly => True)
15057 then
15058 return;
15059 end if;
15060
15061 -- Return if previous error
15062
15063 if Etype (Typ) = Any_Type
15064 or else
15065 Etype (Read) = Any_Type
15066 or else
15067 Etype (Write) = Any_Type
15068 then
15069 return;
15070 end if;
15071
15072 -- Error checks
15073
15074 if Underlying_Type (Etype (Read)) /= Typ then
15075 Error_Pragma_Arg
15076 ("incorrect return type for function&", Arg2);
15077 end if;
15078
15079 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
15080 Error_Pragma_Arg
15081 ("incorrect parameter type for function&", Arg3);
15082 end if;
15083
15084 if Underlying_Type (Etype (First_Formal (Read))) /=
15085 Underlying_Type (Etype (Write))
15086 then
15087 Error_Pragma_Arg
15088 ("result type of & does not match Read parameter type",
15089 Arg3);
15090 end if;
15091 end;
15092 end Stream_Convert;
15093
15094 ------------------
15095 -- Style_Checks --
15096 ------------------
15097
15098 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
15099
15100 -- This is processed by the parser since some of the style checks
15101 -- take place during source scanning and parsing. This means that
15102 -- we don't need to issue error messages here.
15103
15104 when Pragma_Style_Checks => Style_Checks : declare
15105 A : constant Node_Id := Get_Pragma_Arg (Arg1);
15106 S : String_Id;
15107 C : Char_Code;
15108
15109 begin
15110 GNAT_Pragma;
15111 Check_No_Identifiers;
15112
15113 -- Two argument form
15114
15115 if Arg_Count = 2 then
15116 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
15117
15118 declare
15119 E_Id : Node_Id;
15120 E : Entity_Id;
15121
15122 begin
15123 E_Id := Get_Pragma_Arg (Arg2);
15124 Analyze (E_Id);
15125
15126 if not Is_Entity_Name (E_Id) then
15127 Error_Pragma_Arg
15128 ("second argument of pragma% must be entity name",
15129 Arg2);
15130 end if;
15131
15132 E := Entity (E_Id);
15133
15134 if not Ignore_Style_Checks_Pragmas then
15135 if E = Any_Id then
15136 return;
15137 else
15138 loop
15139 Set_Suppress_Style_Checks
15140 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
15141 exit when No (Homonym (E));
15142 E := Homonym (E);
15143 end loop;
15144 end if;
15145 end if;
15146 end;
15147
15148 -- One argument form
15149
15150 else
15151 Check_Arg_Count (1);
15152
15153 if Nkind (A) = N_String_Literal then
15154 S := Strval (A);
15155
15156 declare
15157 Slen : constant Natural := Natural (String_Length (S));
15158 Options : String (1 .. Slen);
15159 J : Natural;
15160
15161 begin
15162 J := 1;
15163 loop
15164 C := Get_String_Char (S, Int (J));
15165 exit when not In_Character_Range (C);
15166 Options (J) := Get_Character (C);
15167
15168 -- If at end of string, set options. As per discussion
15169 -- above, no need to check for errors, since we issued
15170 -- them in the parser.
15171
15172 if J = Slen then
15173 if not Ignore_Style_Checks_Pragmas then
15174 Set_Style_Check_Options (Options);
15175 end if;
15176
15177 exit;
15178 end if;
15179
15180 J := J + 1;
15181 end loop;
15182 end;
15183
15184 elsif Nkind (A) = N_Identifier then
15185 if Chars (A) = Name_All_Checks then
15186 if not Ignore_Style_Checks_Pragmas then
15187 if GNAT_Mode then
15188 Set_GNAT_Style_Check_Options;
15189 else
15190 Set_Default_Style_Check_Options;
15191 end if;
15192 end if;
15193
15194 elsif Chars (A) = Name_On then
15195 if not Ignore_Style_Checks_Pragmas then
15196 Style_Check := True;
15197 end if;
15198
15199 elsif Chars (A) = Name_Off then
15200 if not Ignore_Style_Checks_Pragmas then
15201 Style_Check := False;
15202 end if;
15203 end if;
15204 end if;
15205 end if;
15206 end Style_Checks;
15207
15208 --------------
15209 -- Subtitle --
15210 --------------
15211
15212 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
15213
15214 when Pragma_Subtitle =>
15215 GNAT_Pragma;
15216 Check_Arg_Count (1);
15217 Check_Optional_Identifier (Arg1, Name_Subtitle);
15218 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
15219 Store_Note (N);
15220
15221 --------------
15222 -- Suppress --
15223 --------------
15224
15225 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
15226
15227 when Pragma_Suppress =>
15228 Process_Suppress_Unsuppress (True);
15229
15230 ------------------
15231 -- Suppress_All --
15232 ------------------
15233
15234 -- pragma Suppress_All;
15235
15236 -- The only check made here is that the pragma has no arguments.
15237 -- There are no placement rules, and the processing required (setting
15238 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
15239 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
15240 -- then creates and inserts a pragma Suppress (All_Checks).
15241
15242 when Pragma_Suppress_All =>
15243 GNAT_Pragma;
15244 Check_Arg_Count (0);
15245
15246 -------------------------
15247 -- Suppress_Debug_Info --
15248 -------------------------
15249
15250 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
15251
15252 when Pragma_Suppress_Debug_Info =>
15253 GNAT_Pragma;
15254 Check_Arg_Count (1);
15255 Check_Optional_Identifier (Arg1, Name_Entity);
15256 Check_Arg_Is_Local_Name (Arg1);
15257 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
15258
15259 ----------------------------------
15260 -- Suppress_Exception_Locations --
15261 ----------------------------------
15262
15263 -- pragma Suppress_Exception_Locations;
15264
15265 when Pragma_Suppress_Exception_Locations =>
15266 GNAT_Pragma;
15267 Check_Arg_Count (0);
15268 Check_Valid_Configuration_Pragma;
15269 Exception_Locations_Suppressed := True;
15270
15271 -----------------------------
15272 -- Suppress_Initialization --
15273 -----------------------------
15274
15275 -- pragma Suppress_Initialization ([Entity =>] type_Name);
15276
15277 when Pragma_Suppress_Initialization => Suppress_Init : declare
15278 E_Id : Node_Id;
15279 E : Entity_Id;
15280
15281 begin
15282 GNAT_Pragma;
15283 Check_Arg_Count (1);
15284 Check_Optional_Identifier (Arg1, Name_Entity);
15285 Check_Arg_Is_Local_Name (Arg1);
15286
15287 E_Id := Get_Pragma_Arg (Arg1);
15288
15289 if Etype (E_Id) = Any_Type then
15290 return;
15291 end if;
15292
15293 E := Entity (E_Id);
15294
15295 if not Is_Type (E) then
15296 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
15297 end if;
15298
15299 if Rep_Item_Too_Early (E, N)
15300 or else
15301 Rep_Item_Too_Late (E, N, FOnly => True)
15302 then
15303 return;
15304 end if;
15305
15306 -- For incomplete/private type, set flag on full view
15307
15308 if Is_Incomplete_Or_Private_Type (E) then
15309 if No (Full_View (Base_Type (E))) then
15310 Error_Pragma_Arg
15311 ("argument of pragma% cannot be an incomplete type", Arg1);
15312 else
15313 Set_Suppress_Initialization (Full_View (Base_Type (E)));
15314 end if;
15315
15316 -- For first subtype, set flag on base type
15317
15318 elsif Is_First_Subtype (E) then
15319 Set_Suppress_Initialization (Base_Type (E));
15320
15321 -- For other than first subtype, set flag on subtype itself
15322
15323 else
15324 Set_Suppress_Initialization (E);
15325 end if;
15326 end Suppress_Init;
15327
15328 -----------------
15329 -- System_Name --
15330 -----------------
15331
15332 -- pragma System_Name (DIRECT_NAME);
15333
15334 -- Syntax check: one argument, which must be the identifier GNAT or
15335 -- the identifier GCC, no other identifiers are acceptable.
15336
15337 when Pragma_System_Name =>
15338 GNAT_Pragma;
15339 Check_No_Identifiers;
15340 Check_Arg_Count (1);
15341 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
15342
15343 -----------------------------
15344 -- Task_Dispatching_Policy --
15345 -----------------------------
15346
15347 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
15348
15349 when Pragma_Task_Dispatching_Policy => declare
15350 DP : Character;
15351
15352 begin
15353 Check_Ada_83_Warning;
15354 Check_Arg_Count (1);
15355 Check_No_Identifiers;
15356 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
15357 Check_Valid_Configuration_Pragma;
15358 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15359 DP := Fold_Upper (Name_Buffer (1));
15360
15361 if Task_Dispatching_Policy /= ' '
15362 and then Task_Dispatching_Policy /= DP
15363 then
15364 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
15365 Error_Pragma
15366 ("task dispatching policy incompatible with policy#");
15367
15368 -- Set new policy, but always preserve System_Location since we
15369 -- like the error message with the run time name.
15370
15371 else
15372 Task_Dispatching_Policy := DP;
15373
15374 if Task_Dispatching_Policy_Sloc /= System_Location then
15375 Task_Dispatching_Policy_Sloc := Loc;
15376 end if;
15377 end if;
15378 end;
15379
15380 ---------------
15381 -- Task_Info --
15382 ---------------
15383
15384 -- pragma Task_Info (EXPRESSION);
15385
15386 when Pragma_Task_Info => Task_Info : declare
15387 P : constant Node_Id := Parent (N);
15388 Ent : Entity_Id;
15389
15390 begin
15391 GNAT_Pragma;
15392
15393 if Nkind (P) /= N_Task_Definition then
15394 Error_Pragma ("pragma% must appear in task definition");
15395 end if;
15396
15397 Check_No_Identifiers;
15398 Check_Arg_Count (1);
15399
15400 Analyze_And_Resolve
15401 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
15402
15403 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
15404 return;
15405 end if;
15406
15407 Ent := Defining_Identifier (Parent (P));
15408
15409 -- Check duplicate pragma before we chain the pragma in the Rep
15410 -- Item chain of Ent.
15411
15412 if Has_Rep_Pragma
15413 (Ent, Name_Task_Info, Check_Parents => False)
15414 then
15415 Error_Pragma ("duplicate pragma% not allowed");
15416 end if;
15417
15418 Record_Rep_Item (Ent, N);
15419 end Task_Info;
15420
15421 ---------------
15422 -- Task_Name --
15423 ---------------
15424
15425 -- pragma Task_Name (string_EXPRESSION);
15426
15427 when Pragma_Task_Name => Task_Name : declare
15428 P : constant Node_Id := Parent (N);
15429 Arg : Node_Id;
15430 Ent : Entity_Id;
15431
15432 begin
15433 Check_No_Identifiers;
15434 Check_Arg_Count (1);
15435
15436 Arg := Get_Pragma_Arg (Arg1);
15437
15438 -- The expression is used in the call to Create_Task, and must be
15439 -- expanded there, not in the context of the current spec. It must
15440 -- however be analyzed to capture global references, in case it
15441 -- appears in a generic context.
15442
15443 Preanalyze_And_Resolve (Arg, Standard_String);
15444
15445 if Nkind (P) /= N_Task_Definition then
15446 Pragma_Misplaced;
15447 end if;
15448
15449 Ent := Defining_Identifier (Parent (P));
15450
15451 -- Check duplicate pragma before we chain the pragma in the Rep
15452 -- Item chain of Ent.
15453
15454 if Has_Rep_Pragma
15455 (Ent, Name_Task_Name, Check_Parents => False)
15456 then
15457 Error_Pragma ("duplicate pragma% not allowed");
15458 end if;
15459
15460 Record_Rep_Item (Ent, N);
15461 end Task_Name;
15462
15463 ------------------
15464 -- Task_Storage --
15465 ------------------
15466
15467 -- pragma Task_Storage (
15468 -- [Task_Type =>] LOCAL_NAME,
15469 -- [Top_Guard =>] static_integer_EXPRESSION);
15470
15471 when Pragma_Task_Storage => Task_Storage : declare
15472 Args : Args_List (1 .. 2);
15473 Names : constant Name_List (1 .. 2) := (
15474 Name_Task_Type,
15475 Name_Top_Guard);
15476
15477 Task_Type : Node_Id renames Args (1);
15478 Top_Guard : Node_Id renames Args (2);
15479
15480 Ent : Entity_Id;
15481
15482 begin
15483 GNAT_Pragma;
15484 Gather_Associations (Names, Args);
15485
15486 if No (Task_Type) then
15487 Error_Pragma
15488 ("missing task_type argument for pragma%");
15489 end if;
15490
15491 Check_Arg_Is_Local_Name (Task_Type);
15492
15493 Ent := Entity (Task_Type);
15494
15495 if not Is_Task_Type (Ent) then
15496 Error_Pragma_Arg
15497 ("argument for pragma% must be task type", Task_Type);
15498 end if;
15499
15500 if No (Top_Guard) then
15501 Error_Pragma_Arg
15502 ("pragma% takes two arguments", Task_Type);
15503 else
15504 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
15505 end if;
15506
15507 Check_First_Subtype (Task_Type);
15508
15509 if Rep_Item_Too_Late (Ent, N) then
15510 raise Pragma_Exit;
15511 end if;
15512 end Task_Storage;
15513
15514 ---------------
15515 -- Test_Case --
15516 ---------------
15517
15518 -- pragma Test_Case
15519 -- ([Name =>] Static_String_EXPRESSION
15520 -- ,[Mode =>] MODE_TYPE
15521 -- [, Requires => Boolean_EXPRESSION]
15522 -- [, Ensures => Boolean_EXPRESSION]);
15523
15524 -- MODE_TYPE ::= Nominal | Robustness
15525
15526 when Pragma_Test_Case =>
15527 Check_Contract_Or_Test_Case;
15528
15529 --------------------------
15530 -- Thread_Local_Storage --
15531 --------------------------
15532
15533 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
15534
15535 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
15536 Id : Node_Id;
15537 E : Entity_Id;
15538
15539 begin
15540 GNAT_Pragma;
15541 Check_Arg_Count (1);
15542 Check_Optional_Identifier (Arg1, Name_Entity);
15543 Check_Arg_Is_Library_Level_Local_Name (Arg1);
15544
15545 Id := Get_Pragma_Arg (Arg1);
15546 Analyze (Id);
15547
15548 if not Is_Entity_Name (Id)
15549 or else Ekind (Entity (Id)) /= E_Variable
15550 then
15551 Error_Pragma_Arg ("local variable name required", Arg1);
15552 end if;
15553
15554 E := Entity (Id);
15555
15556 if Rep_Item_Too_Early (E, N)
15557 or else Rep_Item_Too_Late (E, N)
15558 then
15559 raise Pragma_Exit;
15560 end if;
15561
15562 Set_Has_Pragma_Thread_Local_Storage (E);
15563 Set_Has_Gigi_Rep_Item (E);
15564 end Thread_Local_Storage;
15565
15566 ----------------
15567 -- Time_Slice --
15568 ----------------
15569
15570 -- pragma Time_Slice (static_duration_EXPRESSION);
15571
15572 when Pragma_Time_Slice => Time_Slice : declare
15573 Val : Ureal;
15574 Nod : Node_Id;
15575
15576 begin
15577 GNAT_Pragma;
15578 Check_Arg_Count (1);
15579 Check_No_Identifiers;
15580 Check_In_Main_Program;
15581 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
15582
15583 if not Error_Posted (Arg1) then
15584 Nod := Next (N);
15585 while Present (Nod) loop
15586 if Nkind (Nod) = N_Pragma
15587 and then Pragma_Name (Nod) = Name_Time_Slice
15588 then
15589 Error_Msg_Name_1 := Pname;
15590 Error_Msg_N ("duplicate pragma% not permitted", Nod);
15591 end if;
15592
15593 Next (Nod);
15594 end loop;
15595 end if;
15596
15597 -- Process only if in main unit
15598
15599 if Get_Source_Unit (Loc) = Main_Unit then
15600 Opt.Time_Slice_Set := True;
15601 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
15602
15603 if Val <= Ureal_0 then
15604 Opt.Time_Slice_Value := 0;
15605
15606 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
15607 Opt.Time_Slice_Value := 1_000_000_000;
15608
15609 else
15610 Opt.Time_Slice_Value :=
15611 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
15612 end if;
15613 end if;
15614 end Time_Slice;
15615
15616 -----------
15617 -- Title --
15618 -----------
15619
15620 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
15621
15622 -- TITLING_OPTION ::=
15623 -- [Title =>] STRING_LITERAL
15624 -- | [Subtitle =>] STRING_LITERAL
15625
15626 when Pragma_Title => Title : declare
15627 Args : Args_List (1 .. 2);
15628 Names : constant Name_List (1 .. 2) := (
15629 Name_Title,
15630 Name_Subtitle);
15631
15632 begin
15633 GNAT_Pragma;
15634 Gather_Associations (Names, Args);
15635 Store_Note (N);
15636
15637 for J in 1 .. 2 loop
15638 if Present (Args (J)) then
15639 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
15640 end if;
15641 end loop;
15642 end Title;
15643
15644 ---------------------
15645 -- Unchecked_Union --
15646 ---------------------
15647
15648 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
15649
15650 when Pragma_Unchecked_Union => Unchecked_Union : declare
15651 Assoc : constant Node_Id := Arg1;
15652 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
15653 Typ : Entity_Id;
15654 Tdef : Node_Id;
15655 Clist : Node_Id;
15656 Vpart : Node_Id;
15657 Comp : Node_Id;
15658 Variant : Node_Id;
15659
15660 begin
15661 Ada_2005_Pragma;
15662 Check_No_Identifiers;
15663 Check_Arg_Count (1);
15664 Check_Arg_Is_Local_Name (Arg1);
15665
15666 Find_Type (Type_Id);
15667
15668 Typ := Entity (Type_Id);
15669
15670 if Typ = Any_Type
15671 or else Rep_Item_Too_Early (Typ, N)
15672 then
15673 return;
15674 else
15675 Typ := Underlying_Type (Typ);
15676 end if;
15677
15678 if Rep_Item_Too_Late (Typ, N) then
15679 return;
15680 end if;
15681
15682 Check_First_Subtype (Arg1);
15683
15684 -- Note remaining cases are references to a type in the current
15685 -- declarative part. If we find an error, we post the error on
15686 -- the relevant type declaration at an appropriate point.
15687
15688 if not Is_Record_Type (Typ) then
15689 Error_Msg_N ("unchecked union must be record type", Typ);
15690 return;
15691
15692 elsif Is_Tagged_Type (Typ) then
15693 Error_Msg_N ("unchecked union must not be tagged", Typ);
15694 return;
15695
15696 elsif not Has_Discriminants (Typ) then
15697 Error_Msg_N
15698 ("unchecked union must have one discriminant", Typ);
15699 return;
15700
15701 -- Note: in previous versions of GNAT we used to check for limited
15702 -- types and give an error, but in fact the standard does allow
15703 -- Unchecked_Union on limited types, so this check was removed.
15704
15705 -- Similarly, GNAT used to require that all discriminants have
15706 -- default values, but this is not mandated by the RM.
15707
15708 -- Proceed with basic error checks completed
15709
15710 else
15711 Tdef := Type_Definition (Declaration_Node (Typ));
15712 Clist := Component_List (Tdef);
15713
15714 -- Check presence of component list and variant part
15715
15716 if No (Clist) or else No (Variant_Part (Clist)) then
15717 Error_Msg_N
15718 ("unchecked union must have variant part", Tdef);
15719 return;
15720 end if;
15721
15722 -- Check components
15723
15724 Comp := First (Component_Items (Clist));
15725 while Present (Comp) loop
15726 Check_Component (Comp, Typ);
15727 Next (Comp);
15728 end loop;
15729
15730 -- Check variant part
15731
15732 Vpart := Variant_Part (Clist);
15733
15734 Variant := First (Variants (Vpart));
15735 while Present (Variant) loop
15736 Check_Variant (Variant, Typ);
15737 Next (Variant);
15738 end loop;
15739 end if;
15740
15741 Set_Is_Unchecked_Union (Typ);
15742 Set_Convention (Typ, Convention_C);
15743 Set_Has_Unchecked_Union (Base_Type (Typ));
15744 Set_Is_Unchecked_Union (Base_Type (Typ));
15745 end Unchecked_Union;
15746
15747 ------------------------
15748 -- Unimplemented_Unit --
15749 ------------------------
15750
15751 -- pragma Unimplemented_Unit;
15752
15753 -- Note: this only gives an error if we are generating code, or if
15754 -- we are in a generic library unit (where the pragma appears in the
15755 -- body, not in the spec).
15756
15757 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
15758 Cunitent : constant Entity_Id :=
15759 Cunit_Entity (Get_Source_Unit (Loc));
15760 Ent_Kind : constant Entity_Kind :=
15761 Ekind (Cunitent);
15762
15763 begin
15764 GNAT_Pragma;
15765 Check_Arg_Count (0);
15766
15767 if Operating_Mode = Generate_Code
15768 or else Ent_Kind = E_Generic_Function
15769 or else Ent_Kind = E_Generic_Procedure
15770 or else Ent_Kind = E_Generic_Package
15771 then
15772 Get_Name_String (Chars (Cunitent));
15773 Set_Casing (Mixed_Case);
15774 Write_Str (Name_Buffer (1 .. Name_Len));
15775 Write_Str (" is not supported in this configuration");
15776 Write_Eol;
15777 raise Unrecoverable_Error;
15778 end if;
15779 end Unimplemented_Unit;
15780
15781 ------------------------
15782 -- Universal_Aliasing --
15783 ------------------------
15784
15785 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
15786
15787 when Pragma_Universal_Aliasing => Universal_Alias : declare
15788 E_Id : Entity_Id;
15789
15790 begin
15791 GNAT_Pragma;
15792 Check_Arg_Count (1);
15793 Check_Optional_Identifier (Arg2, Name_Entity);
15794 Check_Arg_Is_Local_Name (Arg1);
15795 E_Id := Entity (Get_Pragma_Arg (Arg1));
15796
15797 if E_Id = Any_Type then
15798 return;
15799 elsif No (E_Id) or else not Is_Type (E_Id) then
15800 Error_Pragma_Arg ("pragma% requires type", Arg1);
15801 end if;
15802
15803 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
15804 Record_Rep_Item (E_Id, N);
15805 end Universal_Alias;
15806
15807 --------------------
15808 -- Universal_Data --
15809 --------------------
15810
15811 -- pragma Universal_Data [(library_unit_NAME)];
15812
15813 when Pragma_Universal_Data =>
15814 GNAT_Pragma;
15815
15816 -- If this is a configuration pragma, then set the universal
15817 -- addressing option, otherwise confirm that the pragma satisfies
15818 -- the requirements of library unit pragma placement and leave it
15819 -- to the GNAAMP back end to detect the pragma (avoids transitive
15820 -- setting of the option due to withed units).
15821
15822 if Is_Configuration_Pragma then
15823 Universal_Addressing_On_AAMP := True;
15824 else
15825 Check_Valid_Library_Unit_Pragma;
15826 end if;
15827
15828 if not AAMP_On_Target then
15829 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
15830 end if;
15831
15832 ----------------
15833 -- Unmodified --
15834 ----------------
15835
15836 -- pragma Unmodified (local_Name {, local_Name});
15837
15838 when Pragma_Unmodified => Unmodified : declare
15839 Arg_Node : Node_Id;
15840 Arg_Expr : Node_Id;
15841 Arg_Ent : Entity_Id;
15842
15843 begin
15844 GNAT_Pragma;
15845 Check_At_Least_N_Arguments (1);
15846
15847 -- Loop through arguments
15848
15849 Arg_Node := Arg1;
15850 while Present (Arg_Node) loop
15851 Check_No_Identifier (Arg_Node);
15852
15853 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
15854 -- in fact generate reference, so that the entity will have a
15855 -- reference, which will inhibit any warnings about it not
15856 -- being referenced, and also properly show up in the ali file
15857 -- as a reference. But this reference is recorded before the
15858 -- Has_Pragma_Unreferenced flag is set, so that no warning is
15859 -- generated for this reference.
15860
15861 Check_Arg_Is_Local_Name (Arg_Node);
15862 Arg_Expr := Get_Pragma_Arg (Arg_Node);
15863
15864 if Is_Entity_Name (Arg_Expr) then
15865 Arg_Ent := Entity (Arg_Expr);
15866
15867 if not Is_Assignable (Arg_Ent) then
15868 Error_Pragma_Arg
15869 ("pragma% can only be applied to a variable",
15870 Arg_Expr);
15871 else
15872 Set_Has_Pragma_Unmodified (Arg_Ent);
15873 end if;
15874 end if;
15875
15876 Next (Arg_Node);
15877 end loop;
15878 end Unmodified;
15879
15880 ------------------
15881 -- Unreferenced --
15882 ------------------
15883
15884 -- pragma Unreferenced (local_Name {, local_Name});
15885
15886 -- or when used in a context clause:
15887
15888 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
15889
15890 when Pragma_Unreferenced => Unreferenced : declare
15891 Arg_Node : Node_Id;
15892 Arg_Expr : Node_Id;
15893 Arg_Ent : Entity_Id;
15894 Citem : Node_Id;
15895
15896 begin
15897 GNAT_Pragma;
15898 Check_At_Least_N_Arguments (1);
15899
15900 -- Check case of appearing within context clause
15901
15902 if Is_In_Context_Clause then
15903
15904 -- The arguments must all be units mentioned in a with clause
15905 -- in the same context clause. Note we already checked (in
15906 -- Par.Prag) that the arguments are either identifiers or
15907 -- selected components.
15908
15909 Arg_Node := Arg1;
15910 while Present (Arg_Node) loop
15911 Citem := First (List_Containing (N));
15912 while Citem /= N loop
15913 if Nkind (Citem) = N_With_Clause
15914 and then
15915 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
15916 then
15917 Set_Has_Pragma_Unreferenced
15918 (Cunit_Entity
15919 (Get_Source_Unit
15920 (Library_Unit (Citem))));
15921 Set_Unit_Name
15922 (Get_Pragma_Arg (Arg_Node), Name (Citem));
15923 exit;
15924 end if;
15925
15926 Next (Citem);
15927 end loop;
15928
15929 if Citem = N then
15930 Error_Pragma_Arg
15931 ("argument of pragma% is not withed unit", Arg_Node);
15932 end if;
15933
15934 Next (Arg_Node);
15935 end loop;
15936
15937 -- Case of not in list of context items
15938
15939 else
15940 Arg_Node := Arg1;
15941 while Present (Arg_Node) loop
15942 Check_No_Identifier (Arg_Node);
15943
15944 -- Note: the analyze call done by Check_Arg_Is_Local_Name
15945 -- will in fact generate reference, so that the entity will
15946 -- have a reference, which will inhibit any warnings about
15947 -- it not being referenced, and also properly show up in the
15948 -- ali file as a reference. But this reference is recorded
15949 -- before the Has_Pragma_Unreferenced flag is set, so that
15950 -- no warning is generated for this reference.
15951
15952 Check_Arg_Is_Local_Name (Arg_Node);
15953 Arg_Expr := Get_Pragma_Arg (Arg_Node);
15954
15955 if Is_Entity_Name (Arg_Expr) then
15956 Arg_Ent := Entity (Arg_Expr);
15957
15958 -- If the entity is overloaded, the pragma applies to the
15959 -- most recent overloading, as documented. In this case,
15960 -- name resolution does not generate a reference, so it
15961 -- must be done here explicitly.
15962
15963 if Is_Overloaded (Arg_Expr) then
15964 Generate_Reference (Arg_Ent, N);
15965 end if;
15966
15967 Set_Has_Pragma_Unreferenced (Arg_Ent);
15968 end if;
15969
15970 Next (Arg_Node);
15971 end loop;
15972 end if;
15973 end Unreferenced;
15974
15975 --------------------------
15976 -- Unreferenced_Objects --
15977 --------------------------
15978
15979 -- pragma Unreferenced_Objects (local_Name {, local_Name});
15980
15981 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
15982 Arg_Node : Node_Id;
15983 Arg_Expr : Node_Id;
15984
15985 begin
15986 GNAT_Pragma;
15987 Check_At_Least_N_Arguments (1);
15988
15989 Arg_Node := Arg1;
15990 while Present (Arg_Node) loop
15991 Check_No_Identifier (Arg_Node);
15992 Check_Arg_Is_Local_Name (Arg_Node);
15993 Arg_Expr := Get_Pragma_Arg (Arg_Node);
15994
15995 if not Is_Entity_Name (Arg_Expr)
15996 or else not Is_Type (Entity (Arg_Expr))
15997 then
15998 Error_Pragma_Arg
15999 ("argument for pragma% must be type or subtype", Arg_Node);
16000 end if;
16001
16002 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
16003 Next (Arg_Node);
16004 end loop;
16005 end Unreferenced_Objects;
16006
16007 ------------------------------
16008 -- Unreserve_All_Interrupts --
16009 ------------------------------
16010
16011 -- pragma Unreserve_All_Interrupts;
16012
16013 when Pragma_Unreserve_All_Interrupts =>
16014 GNAT_Pragma;
16015 Check_Arg_Count (0);
16016
16017 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
16018 Unreserve_All_Interrupts := True;
16019 end if;
16020
16021 ----------------
16022 -- Unsuppress --
16023 ----------------
16024
16025 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
16026
16027 when Pragma_Unsuppress =>
16028 Ada_2005_Pragma;
16029 Process_Suppress_Unsuppress (False);
16030
16031 -------------------
16032 -- Use_VADS_Size --
16033 -------------------
16034
16035 -- pragma Use_VADS_Size;
16036
16037 when Pragma_Use_VADS_Size =>
16038 GNAT_Pragma;
16039 Check_Arg_Count (0);
16040 Check_Valid_Configuration_Pragma;
16041 Use_VADS_Size := True;
16042
16043 ---------------------
16044 -- Validity_Checks --
16045 ---------------------
16046
16047 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
16048
16049 when Pragma_Validity_Checks => Validity_Checks : declare
16050 A : constant Node_Id := Get_Pragma_Arg (Arg1);
16051 S : String_Id;
16052 C : Char_Code;
16053
16054 begin
16055 GNAT_Pragma;
16056 Check_Arg_Count (1);
16057 Check_No_Identifiers;
16058
16059 if Nkind (A) = N_String_Literal then
16060 S := Strval (A);
16061
16062 declare
16063 Slen : constant Natural := Natural (String_Length (S));
16064 Options : String (1 .. Slen);
16065 J : Natural;
16066
16067 begin
16068 J := 1;
16069 loop
16070 C := Get_String_Char (S, Int (J));
16071 exit when not In_Character_Range (C);
16072 Options (J) := Get_Character (C);
16073
16074 if J = Slen then
16075 Set_Validity_Check_Options (Options);
16076 exit;
16077 else
16078 J := J + 1;
16079 end if;
16080 end loop;
16081 end;
16082
16083 elsif Nkind (A) = N_Identifier then
16084 if Chars (A) = Name_All_Checks then
16085 Set_Validity_Check_Options ("a");
16086 elsif Chars (A) = Name_On then
16087 Validity_Checks_On := True;
16088 elsif Chars (A) = Name_Off then
16089 Validity_Checks_On := False;
16090 end if;
16091 end if;
16092 end Validity_Checks;
16093
16094 --------------
16095 -- Volatile --
16096 --------------
16097
16098 -- pragma Volatile (LOCAL_NAME);
16099
16100 when Pragma_Volatile =>
16101 Process_Atomic_Shared_Volatile;
16102
16103 -------------------------
16104 -- Volatile_Components --
16105 -------------------------
16106
16107 -- pragma Volatile_Components (array_LOCAL_NAME);
16108
16109 -- Volatile is handled by the same circuit as Atomic_Components
16110
16111 --------------
16112 -- Warnings --
16113 --------------
16114
16115 -- pragma Warnings (On | Off);
16116 -- pragma Warnings (On | Off, LOCAL_NAME);
16117 -- pragma Warnings (static_string_EXPRESSION);
16118 -- pragma Warnings (On | Off, STRING_LITERAL);
16119
16120 when Pragma_Warnings => Warnings : begin
16121 GNAT_Pragma;
16122 Check_At_Least_N_Arguments (1);
16123 Check_No_Identifiers;
16124
16125 -- If debug flag -gnatd.i is set, pragma is ignored
16126
16127 if Debug_Flag_Dot_I then
16128 return;
16129 end if;
16130
16131 -- Process various forms of the pragma
16132
16133 declare
16134 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
16135
16136 begin
16137 -- One argument case
16138
16139 if Arg_Count = 1 then
16140
16141 -- On/Off one argument case was processed by parser
16142
16143 if Nkind (Argx) = N_Identifier
16144 and then
16145 (Chars (Argx) = Name_On
16146 or else
16147 Chars (Argx) = Name_Off)
16148 then
16149 null;
16150
16151 -- One argument case must be ON/OFF or static string expr
16152
16153 elsif not Is_Static_String_Expression (Arg1) then
16154 Error_Pragma_Arg
16155 ("argument of pragma% must be On/Off or " &
16156 "static string expression", Arg1);
16157
16158 -- One argument string expression case
16159
16160 else
16161 declare
16162 Lit : constant Node_Id := Expr_Value_S (Argx);
16163 Str : constant String_Id := Strval (Lit);
16164 Len : constant Nat := String_Length (Str);
16165 C : Char_Code;
16166 J : Nat;
16167 OK : Boolean;
16168 Chr : Character;
16169
16170 begin
16171 J := 1;
16172 while J <= Len loop
16173 C := Get_String_Char (Str, J);
16174 OK := In_Character_Range (C);
16175
16176 if OK then
16177 Chr := Get_Character (C);
16178
16179 -- Dash case: only -Wxxx is accepted
16180
16181 if J = 1
16182 and then J < Len
16183 and then Chr = '-'
16184 then
16185 J := J + 1;
16186 C := Get_String_Char (Str, J);
16187 Chr := Get_Character (C);
16188 exit when Chr = 'W';
16189 OK := False;
16190
16191 -- Dot case
16192
16193 elsif J < Len and then Chr = '.' then
16194 J := J + 1;
16195 C := Get_String_Char (Str, J);
16196 Chr := Get_Character (C);
16197
16198 if not Set_Dot_Warning_Switch (Chr) then
16199 Error_Pragma_Arg
16200 ("invalid warning switch character " &
16201 '.' & Chr, Arg1);
16202 end if;
16203
16204 -- Non-Dot case
16205
16206 else
16207 OK := Set_Warning_Switch (Chr);
16208 end if;
16209 end if;
16210
16211 if not OK then
16212 Error_Pragma_Arg
16213 ("invalid warning switch character " & Chr,
16214 Arg1);
16215 end if;
16216
16217 J := J + 1;
16218 end loop;
16219 end;
16220 end if;
16221
16222 -- Two or more arguments (must be two)
16223
16224 else
16225 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
16226 Check_At_Most_N_Arguments (2);
16227
16228 declare
16229 E_Id : Node_Id;
16230 E : Entity_Id;
16231 Err : Boolean;
16232
16233 begin
16234 E_Id := Get_Pragma_Arg (Arg2);
16235 Analyze (E_Id);
16236
16237 -- In the expansion of an inlined body, a reference to
16238 -- the formal may be wrapped in a conversion if the
16239 -- actual is a conversion. Retrieve the real entity name.
16240
16241 if (In_Instance_Body or In_Inlined_Body)
16242 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
16243 then
16244 E_Id := Expression (E_Id);
16245 end if;
16246
16247 -- Entity name case
16248
16249 if Is_Entity_Name (E_Id) then
16250 E := Entity (E_Id);
16251
16252 if E = Any_Id then
16253 return;
16254 else
16255 loop
16256 Set_Warnings_Off
16257 (E, (Chars (Get_Pragma_Arg (Arg1)) =
16258 Name_Off));
16259
16260 -- For OFF case, make entry in warnings off
16261 -- pragma table for later processing. But we do
16262 -- not do that within an instance, since these
16263 -- warnings are about what is needed in the
16264 -- template, not an instance of it.
16265
16266 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
16267 and then Warn_On_Warnings_Off
16268 and then not In_Instance
16269 then
16270 Warnings_Off_Pragmas.Append ((N, E));
16271 end if;
16272
16273 if Is_Enumeration_Type (E) then
16274 declare
16275 Lit : Entity_Id;
16276 begin
16277 Lit := First_Literal (E);
16278 while Present (Lit) loop
16279 Set_Warnings_Off (Lit);
16280 Next_Literal (Lit);
16281 end loop;
16282 end;
16283 end if;
16284
16285 exit when No (Homonym (E));
16286 E := Homonym (E);
16287 end loop;
16288 end if;
16289
16290 -- Error if not entity or static string literal case
16291
16292 elsif not Is_Static_String_Expression (Arg2) then
16293 Error_Pragma_Arg
16294 ("second argument of pragma% must be entity " &
16295 "name or static string expression", Arg2);
16296
16297 -- String literal case
16298
16299 else
16300 String_To_Name_Buffer
16301 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
16302
16303 -- Note on configuration pragma case: If this is a
16304 -- configuration pragma, then for an OFF pragma, we
16305 -- just set Config True in the call, which is all
16306 -- that needs to be done. For the case of ON, this
16307 -- is normally an error, unless it is canceling the
16308 -- effect of a previous OFF pragma in the same file.
16309 -- In any other case, an error will be signalled (ON
16310 -- with no matching OFF).
16311
16312 -- Note: We set Used if we are inside a generic to
16313 -- disable the test that the non-config case actually
16314 -- cancels a warning. That's because we can't be sure
16315 -- there isn't an instantiation in some other unit
16316 -- where a warning is suppressed.
16317
16318 -- We could do a little better here by checking if the
16319 -- generic unit we are inside is public, but for now
16320 -- we don't bother with that refinement.
16321
16322 if Chars (Argx) = Name_Off then
16323 Set_Specific_Warning_Off
16324 (Loc, Name_Buffer (1 .. Name_Len),
16325 Config => Is_Configuration_Pragma,
16326 Used => Inside_A_Generic or else In_Instance);
16327
16328 elsif Chars (Argx) = Name_On then
16329 Set_Specific_Warning_On
16330 (Loc, Name_Buffer (1 .. Name_Len), Err);
16331
16332 if Err then
16333 Error_Msg
16334 ("??pragma Warnings On with no " &
16335 "matching Warnings Off",
16336 Loc);
16337 end if;
16338 end if;
16339 end if;
16340 end;
16341 end if;
16342 end;
16343 end Warnings;
16344
16345 -------------------
16346 -- Weak_External --
16347 -------------------
16348
16349 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
16350
16351 when Pragma_Weak_External => Weak_External : declare
16352 Ent : Entity_Id;
16353
16354 begin
16355 GNAT_Pragma;
16356 Check_Arg_Count (1);
16357 Check_Optional_Identifier (Arg1, Name_Entity);
16358 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16359 Ent := Entity (Get_Pragma_Arg (Arg1));
16360
16361 if Rep_Item_Too_Early (Ent, N) then
16362 return;
16363 else
16364 Ent := Underlying_Type (Ent);
16365 end if;
16366
16367 -- The only processing required is to link this item on to the
16368 -- list of rep items for the given entity. This is accomplished
16369 -- by the call to Rep_Item_Too_Late (when no error is detected
16370 -- and False is returned).
16371
16372 if Rep_Item_Too_Late (Ent, N) then
16373 return;
16374 else
16375 Set_Has_Gigi_Rep_Item (Ent);
16376 end if;
16377 end Weak_External;
16378
16379 -----------------------------
16380 -- Wide_Character_Encoding --
16381 -----------------------------
16382
16383 -- pragma Wide_Character_Encoding (IDENTIFIER);
16384
16385 when Pragma_Wide_Character_Encoding =>
16386 GNAT_Pragma;
16387
16388 -- Nothing to do, handled in parser. Note that we do not enforce
16389 -- configuration pragma placement, this pragma can appear at any
16390 -- place in the source, allowing mixed encodings within a single
16391 -- source program.
16392
16393 null;
16394
16395 --------------------
16396 -- Unknown_Pragma --
16397 --------------------
16398
16399 -- Should be impossible, since the case of an unknown pragma is
16400 -- separately processed before the case statement is entered.
16401
16402 when Unknown_Pragma =>
16403 raise Program_Error;
16404 end case;
16405
16406 -- AI05-0144: detect dangerous order dependence. Disabled for now,
16407 -- until AI is formally approved.
16408
16409 -- Check_Order_Dependence;
16410
16411 exception
16412 when Pragma_Exit => null;
16413 end Analyze_Pragma;
16414
16415 -------------------
16416 -- Check_Enabled --
16417 -------------------
16418
16419 function Check_Enabled (Nam : Name_Id) return Boolean is
16420 PP : Node_Id;
16421
16422 begin
16423 -- Loop through entries in check policy list
16424
16425 PP := Opt.Check_Policy_List;
16426 loop
16427 -- If there are no specific entries that matched, then we let the
16428 -- setting of assertions govern. Note that this provides the needed
16429 -- compatibility with the RM for the cases of assertion, invariant,
16430 -- precondition, predicate, and postcondition.
16431
16432 if No (PP) then
16433 return Assertions_Enabled;
16434
16435 -- Here we have an entry see if it matches
16436
16437 else
16438 declare
16439 PPA : constant List_Id := Pragma_Argument_Associations (PP);
16440
16441 begin
16442 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
16443 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
16444 when Name_On | Name_Check =>
16445 return True;
16446 when Name_Off | Name_Disable | Name_Ignore =>
16447 return False;
16448 when others =>
16449 raise Program_Error;
16450 end case;
16451
16452 else
16453 PP := Next_Pragma (PP);
16454 end if;
16455 end;
16456 end if;
16457 end loop;
16458 end Check_Enabled;
16459
16460 ---------------------------------
16461 -- Delay_Config_Pragma_Analyze --
16462 ---------------------------------
16463
16464 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
16465 begin
16466 return Pragma_Name (N) = Name_Interrupt_State
16467 or else
16468 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
16469 end Delay_Config_Pragma_Analyze;
16470
16471 -------------------------
16472 -- Get_Base_Subprogram --
16473 -------------------------
16474
16475 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
16476 Result : Entity_Id;
16477
16478 begin
16479 -- Follow subprogram renaming chain
16480
16481 Result := Def_Id;
16482
16483 if Is_Subprogram (Result)
16484 and then
16485 Nkind (Parent (Declaration_Node (Result))) =
16486 N_Subprogram_Renaming_Declaration
16487 and then Present (Alias (Result))
16488 then
16489 Result := Alias (Result);
16490 end if;
16491
16492 return Result;
16493 end Get_Base_Subprogram;
16494
16495 ----------------
16496 -- Initialize --
16497 ----------------
16498
16499 procedure Initialize is
16500 begin
16501 Externals.Init;
16502 end Initialize;
16503
16504 -----------------------------
16505 -- Is_Config_Static_String --
16506 -----------------------------
16507
16508 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
16509
16510 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
16511 -- This is an internal recursive function that is just like the outer
16512 -- function except that it adds the string to the name buffer rather
16513 -- than placing the string in the name buffer.
16514
16515 ------------------------------
16516 -- Add_Config_Static_String --
16517 ------------------------------
16518
16519 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
16520 N : Node_Id;
16521 C : Char_Code;
16522
16523 begin
16524 N := Arg;
16525
16526 if Nkind (N) = N_Op_Concat then
16527 if Add_Config_Static_String (Left_Opnd (N)) then
16528 N := Right_Opnd (N);
16529 else
16530 return False;
16531 end if;
16532 end if;
16533
16534 if Nkind (N) /= N_String_Literal then
16535 Error_Msg_N ("string literal expected for pragma argument", N);
16536 return False;
16537
16538 else
16539 for J in 1 .. String_Length (Strval (N)) loop
16540 C := Get_String_Char (Strval (N), J);
16541
16542 if not In_Character_Range (C) then
16543 Error_Msg
16544 ("string literal contains invalid wide character",
16545 Sloc (N) + 1 + Source_Ptr (J));
16546 return False;
16547 end if;
16548
16549 Add_Char_To_Name_Buffer (Get_Character (C));
16550 end loop;
16551 end if;
16552
16553 return True;
16554 end Add_Config_Static_String;
16555
16556 -- Start of processing for Is_Config_Static_String
16557
16558 begin
16559
16560 Name_Len := 0;
16561 return Add_Config_Static_String (Arg);
16562 end Is_Config_Static_String;
16563
16564 -----------------------------------------
16565 -- Is_Non_Significant_Pragma_Reference --
16566 -----------------------------------------
16567
16568 -- This function makes use of the following static table which indicates
16569 -- whether appearance of some name in a given pragma is to be considered
16570 -- as a reference for the purposes of warnings about unreferenced objects.
16571
16572 -- -1 indicates that references in any argument position are significant
16573 -- 0 indicates that appearance in any argument is not significant
16574 -- +n indicates that appearance as argument n is significant, but all
16575 -- other arguments are not significant
16576 -- 99 special processing required (e.g. for pragma Check)
16577
16578 Sig_Flags : constant array (Pragma_Id) of Int :=
16579 (Pragma_AST_Entry => -1,
16580 Pragma_Abort_Defer => -1,
16581 Pragma_Abstract_State => -1,
16582 Pragma_Ada_83 => -1,
16583 Pragma_Ada_95 => -1,
16584 Pragma_Ada_05 => -1,
16585 Pragma_Ada_2005 => -1,
16586 Pragma_Ada_12 => -1,
16587 Pragma_Ada_2012 => -1,
16588 Pragma_All_Calls_Remote => -1,
16589 Pragma_Annotate => -1,
16590 Pragma_Assert => -1,
16591 Pragma_Assert_And_Cut => -1,
16592 Pragma_Assertion_Policy => 0,
16593 Pragma_Assume => 0,
16594 Pragma_Assume_No_Invalid_Values => 0,
16595 Pragma_Attribute_Definition => +3,
16596 Pragma_Asynchronous => -1,
16597 Pragma_Atomic => 0,
16598 Pragma_Atomic_Components => 0,
16599 Pragma_Attach_Handler => -1,
16600 Pragma_Check => 99,
16601 Pragma_Check_Float_Overflow => 0,
16602 Pragma_Check_Name => 0,
16603 Pragma_Check_Policy => 0,
16604 Pragma_CIL_Constructor => -1,
16605 Pragma_CPP_Class => 0,
16606 Pragma_CPP_Constructor => 0,
16607 Pragma_CPP_Virtual => 0,
16608 Pragma_CPP_Vtable => 0,
16609 Pragma_CPU => -1,
16610 Pragma_C_Pass_By_Copy => 0,
16611 Pragma_Comment => 0,
16612 Pragma_Common_Object => -1,
16613 Pragma_Compile_Time_Error => -1,
16614 Pragma_Compile_Time_Warning => -1,
16615 Pragma_Compiler_Unit => 0,
16616 Pragma_Complete_Representation => 0,
16617 Pragma_Complex_Representation => 0,
16618 Pragma_Component_Alignment => -1,
16619 Pragma_Contract_Case => -1,
16620 Pragma_Contract_Cases => -1,
16621 Pragma_Controlled => 0,
16622 Pragma_Convention => 0,
16623 Pragma_Convention_Identifier => 0,
16624 Pragma_Debug => -1,
16625 Pragma_Debug_Policy => 0,
16626 Pragma_Detect_Blocking => -1,
16627 Pragma_Default_Storage_Pool => -1,
16628 Pragma_Disable_Atomic_Synchronization => -1,
16629 Pragma_Discard_Names => 0,
16630 Pragma_Dispatching_Domain => -1,
16631 Pragma_Elaborate => -1,
16632 Pragma_Elaborate_All => -1,
16633 Pragma_Elaborate_Body => -1,
16634 Pragma_Elaboration_Checks => -1,
16635 Pragma_Eliminate => -1,
16636 Pragma_Enable_Atomic_Synchronization => -1,
16637 Pragma_Export => -1,
16638 Pragma_Export_Exception => -1,
16639 Pragma_Export_Function => -1,
16640 Pragma_Export_Object => -1,
16641 Pragma_Export_Procedure => -1,
16642 Pragma_Export_Value => -1,
16643 Pragma_Export_Valued_Procedure => -1,
16644 Pragma_Extend_System => -1,
16645 Pragma_Extensions_Allowed => -1,
16646 Pragma_External => -1,
16647 Pragma_Favor_Top_Level => -1,
16648 Pragma_External_Name_Casing => -1,
16649 Pragma_Fast_Math => -1,
16650 Pragma_Finalize_Storage_Only => 0,
16651 Pragma_Float_Representation => 0,
16652 Pragma_Global => -1,
16653 Pragma_Ident => -1,
16654 Pragma_Implementation_Defined => -1,
16655 Pragma_Implemented => -1,
16656 Pragma_Implicit_Packing => 0,
16657 Pragma_Import => +2,
16658 Pragma_Import_Exception => 0,
16659 Pragma_Import_Function => 0,
16660 Pragma_Import_Object => 0,
16661 Pragma_Import_Procedure => 0,
16662 Pragma_Import_Valued_Procedure => 0,
16663 Pragma_Independent => 0,
16664 Pragma_Independent_Components => 0,
16665 Pragma_Initialize_Scalars => -1,
16666 Pragma_Inline => 0,
16667 Pragma_Inline_Always => 0,
16668 Pragma_Inline_Generic => 0,
16669 Pragma_Inspection_Point => -1,
16670 Pragma_Interface => +2,
16671 Pragma_Interface_Name => +2,
16672 Pragma_Interrupt_Handler => -1,
16673 Pragma_Interrupt_Priority => -1,
16674 Pragma_Interrupt_State => -1,
16675 Pragma_Invariant => -1,
16676 Pragma_Java_Constructor => -1,
16677 Pragma_Java_Interface => -1,
16678 Pragma_Keep_Names => 0,
16679 Pragma_License => -1,
16680 Pragma_Link_With => -1,
16681 Pragma_Linker_Alias => -1,
16682 Pragma_Linker_Constructor => -1,
16683 Pragma_Linker_Destructor => -1,
16684 Pragma_Linker_Options => -1,
16685 Pragma_Linker_Section => -1,
16686 Pragma_List => -1,
16687 Pragma_Lock_Free => -1,
16688 Pragma_Locking_Policy => -1,
16689 Pragma_Long_Float => -1,
16690 Pragma_Loop_Invariant => -1,
16691 Pragma_Loop_Optimize => -1,
16692 Pragma_Loop_Variant => -1,
16693 Pragma_Machine_Attribute => -1,
16694 Pragma_Main => -1,
16695 Pragma_Main_Storage => -1,
16696 Pragma_Memory_Size => -1,
16697 Pragma_No_Return => 0,
16698 Pragma_No_Body => 0,
16699 Pragma_No_Inline => 0,
16700 Pragma_No_Run_Time => -1,
16701 Pragma_No_Strict_Aliasing => -1,
16702 Pragma_Normalize_Scalars => -1,
16703 Pragma_Obsolescent => 0,
16704 Pragma_Optimize => -1,
16705 Pragma_Optimize_Alignment => -1,
16706 Pragma_Overflow_Mode => 0,
16707 Pragma_Overriding_Renamings => 0,
16708 Pragma_Ordered => 0,
16709 Pragma_Pack => 0,
16710 Pragma_Page => -1,
16711 Pragma_Partition_Elaboration_Policy => -1,
16712 Pragma_Passive => -1,
16713 Pragma_Preelaborable_Initialization => -1,
16714 Pragma_Polling => -1,
16715 Pragma_Persistent_BSS => 0,
16716 Pragma_Postcondition => -1,
16717 Pragma_Precondition => -1,
16718 Pragma_Predicate => -1,
16719 Pragma_Preelaborate => -1,
16720 Pragma_Preelaborate_05 => -1,
16721 Pragma_Priority => -1,
16722 Pragma_Priority_Specific_Dispatching => -1,
16723 Pragma_Profile => 0,
16724 Pragma_Profile_Warnings => 0,
16725 Pragma_Propagate_Exceptions => -1,
16726 Pragma_Psect_Object => -1,
16727 Pragma_Pure => -1,
16728 Pragma_Pure_05 => -1,
16729 Pragma_Pure_12 => -1,
16730 Pragma_Pure_Function => -1,
16731 Pragma_Queuing_Policy => -1,
16732 Pragma_Rational => -1,
16733 Pragma_Ravenscar => -1,
16734 Pragma_Relative_Deadline => -1,
16735 Pragma_Remote_Access_Type => -1,
16736 Pragma_Remote_Call_Interface => -1,
16737 Pragma_Remote_Types => -1,
16738 Pragma_Restricted_Run_Time => -1,
16739 Pragma_Restriction_Warnings => -1,
16740 Pragma_Restrictions => -1,
16741 Pragma_Reviewable => -1,
16742 Pragma_Short_Circuit_And_Or => -1,
16743 Pragma_Share_Generic => -1,
16744 Pragma_Shared => -1,
16745 Pragma_Shared_Passive => -1,
16746 Pragma_Short_Descriptors => 0,
16747 Pragma_Simple_Storage_Pool_Type => 0,
16748 Pragma_Source_File_Name => -1,
16749 Pragma_Source_File_Name_Project => -1,
16750 Pragma_Source_Reference => -1,
16751 Pragma_Storage_Size => -1,
16752 Pragma_Storage_Unit => -1,
16753 Pragma_Static_Elaboration_Desired => -1,
16754 Pragma_Stream_Convert => -1,
16755 Pragma_Style_Checks => -1,
16756 Pragma_Subtitle => -1,
16757 Pragma_Suppress => 0,
16758 Pragma_Suppress_Exception_Locations => 0,
16759 Pragma_Suppress_All => -1,
16760 Pragma_Suppress_Debug_Info => 0,
16761 Pragma_Suppress_Initialization => 0,
16762 Pragma_System_Name => -1,
16763 Pragma_Task_Dispatching_Policy => -1,
16764 Pragma_Task_Info => -1,
16765 Pragma_Task_Name => -1,
16766 Pragma_Task_Storage => 0,
16767 Pragma_Test_Case => -1,
16768 Pragma_Thread_Local_Storage => 0,
16769 Pragma_Time_Slice => -1,
16770 Pragma_Title => -1,
16771 Pragma_Unchecked_Union => 0,
16772 Pragma_Unimplemented_Unit => -1,
16773 Pragma_Universal_Aliasing => -1,
16774 Pragma_Universal_Data => -1,
16775 Pragma_Unmodified => -1,
16776 Pragma_Unreferenced => -1,
16777 Pragma_Unreferenced_Objects => -1,
16778 Pragma_Unreserve_All_Interrupts => -1,
16779 Pragma_Unsuppress => 0,
16780 Pragma_Use_VADS_Size => -1,
16781 Pragma_Validity_Checks => -1,
16782 Pragma_Volatile => 0,
16783 Pragma_Volatile_Components => 0,
16784 Pragma_Warnings => -1,
16785 Pragma_Weak_External => -1,
16786 Pragma_Wide_Character_Encoding => 0,
16787 Unknown_Pragma => 0);
16788
16789 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
16790 Id : Pragma_Id;
16791 P : Node_Id;
16792 C : Int;
16793 A : Node_Id;
16794
16795 begin
16796 P := Parent (N);
16797
16798 if Nkind (P) /= N_Pragma_Argument_Association then
16799 return False;
16800
16801 else
16802 Id := Get_Pragma_Id (Parent (P));
16803 C := Sig_Flags (Id);
16804
16805 case C is
16806 when -1 =>
16807 return False;
16808
16809 when 0 =>
16810 return True;
16811
16812 when 99 =>
16813 case Id is
16814
16815 -- For pragma Check, the first argument is not significant,
16816 -- the second and the third (if present) arguments are
16817 -- significant.
16818
16819 when Pragma_Check =>
16820 return
16821 P = First (Pragma_Argument_Associations (Parent (P)));
16822
16823 when others =>
16824 raise Program_Error;
16825 end case;
16826
16827 when others =>
16828 A := First (Pragma_Argument_Associations (Parent (P)));
16829 for J in 1 .. C - 1 loop
16830 if No (A) then
16831 return False;
16832 end if;
16833
16834 Next (A);
16835 end loop;
16836
16837 return A = P; -- is this wrong way round ???
16838 end case;
16839 end if;
16840 end Is_Non_Significant_Pragma_Reference;
16841
16842 ------------------------------
16843 -- Is_Pragma_String_Literal --
16844 ------------------------------
16845
16846 -- This function returns true if the corresponding pragma argument is a
16847 -- static string expression. These are the only cases in which string
16848 -- literals can appear as pragma arguments. We also allow a string literal
16849 -- as the first argument to pragma Assert (although it will of course
16850 -- always generate a type error).
16851
16852 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
16853 Pragn : constant Node_Id := Parent (Par);
16854 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
16855 Pname : constant Name_Id := Pragma_Name (Pragn);
16856 Argn : Natural;
16857 N : Node_Id;
16858
16859 begin
16860 Argn := 1;
16861 N := First (Assoc);
16862 loop
16863 exit when N = Par;
16864 Argn := Argn + 1;
16865 Next (N);
16866 end loop;
16867
16868 if Pname = Name_Assert then
16869 return True;
16870
16871 elsif Pname = Name_Export then
16872 return Argn > 2;
16873
16874 elsif Pname = Name_Ident then
16875 return Argn = 1;
16876
16877 elsif Pname = Name_Import then
16878 return Argn > 2;
16879
16880 elsif Pname = Name_Interface_Name then
16881 return Argn > 1;
16882
16883 elsif Pname = Name_Linker_Alias then
16884 return Argn = 2;
16885
16886 elsif Pname = Name_Linker_Section then
16887 return Argn = 2;
16888
16889 elsif Pname = Name_Machine_Attribute then
16890 return Argn = 2;
16891
16892 elsif Pname = Name_Source_File_Name then
16893 return True;
16894
16895 elsif Pname = Name_Source_Reference then
16896 return Argn = 2;
16897
16898 elsif Pname = Name_Title then
16899 return True;
16900
16901 elsif Pname = Name_Subtitle then
16902 return True;
16903
16904 else
16905 return False;
16906 end if;
16907 end Is_Pragma_String_Literal;
16908
16909 -----------------------------------------
16910 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
16911 -----------------------------------------
16912
16913 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
16914 Aspects : constant List_Id := New_List;
16915 Loc : constant Source_Ptr := Sloc (Decl);
16916 Or_Decl : constant Node_Id := Original_Node (Decl);
16917
16918 Original_Aspects : List_Id;
16919 -- To capture global references, a copy of the created aspects must be
16920 -- inserted in the original tree.
16921
16922 Prag : Node_Id;
16923 Prag_Arg_Ass : Node_Id;
16924 Prag_Id : Pragma_Id;
16925
16926 begin
16927 -- Check for any PPC pragmas that appear within Decl
16928
16929 Prag := Next (Decl);
16930 while Nkind (Prag) = N_Pragma loop
16931 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
16932
16933 case Prag_Id is
16934 when Pragma_Postcondition | Pragma_Precondition =>
16935 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
16936
16937 -- Make an aspect from any PPC pragma
16938
16939 Append_To (Aspects,
16940 Make_Aspect_Specification (Loc,
16941 Identifier =>
16942 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
16943 Expression =>
16944 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
16945
16946 -- Generate the analysis information in the pragma expression
16947 -- and then set the pragma node analyzed to avoid any further
16948 -- analysis.
16949
16950 Analyze (Expression (Prag_Arg_Ass));
16951 Set_Analyzed (Prag, True);
16952
16953 when others => null;
16954 end case;
16955
16956 Next (Prag);
16957 end loop;
16958
16959 -- Set all new aspects into the generic declaration node
16960
16961 if Is_Non_Empty_List (Aspects) then
16962
16963 -- Create the list of aspects to be inserted in the original tree
16964
16965 Original_Aspects := Copy_Separate_List (Aspects);
16966
16967 -- Check if Decl already has aspects
16968
16969 -- Attach the new lists of aspects to both the generic copy and the
16970 -- original tree.
16971
16972 if Has_Aspects (Decl) then
16973 Append_List (Aspects, Aspect_Specifications (Decl));
16974 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
16975
16976 else
16977 Set_Parent (Aspects, Decl);
16978 Set_Aspect_Specifications (Decl, Aspects);
16979 Set_Parent (Original_Aspects, Or_Decl);
16980 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
16981 end if;
16982 end if;
16983 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
16984
16985 -------------------------
16986 -- Preanalyze_CTC_Args --
16987 -------------------------
16988
16989 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
16990 begin
16991 -- Preanalyze the boolean expressions, we treat these as spec
16992 -- expressions (i.e. similar to a default expression).
16993
16994 if Present (Arg_Req) then
16995 Preanalyze_Assert_Expression
16996 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
16997
16998 -- In ASIS mode, for a pragma generated from a source aspect, also
16999 -- analyze the original aspect expression.
17000
17001 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
17002 Preanalyze_Assert_Expression
17003 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
17004 end if;
17005 end if;
17006
17007 if Present (Arg_Ens) then
17008 Preanalyze_Assert_Expression
17009 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
17010
17011 -- In ASIS mode, for a pragma generated from a source aspect, also
17012 -- analyze the original aspect expression.
17013
17014 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
17015 Preanalyze_Assert_Expression
17016 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
17017 end if;
17018 end if;
17019 end Preanalyze_CTC_Args;
17020
17021 --------------------------------------
17022 -- Process_Compilation_Unit_Pragmas --
17023 --------------------------------------
17024
17025 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
17026 begin
17027 -- A special check for pragma Suppress_All, a very strange DEC pragma,
17028 -- strange because it comes at the end of the unit. Rational has the
17029 -- same name for a pragma, but treats it as a program unit pragma, In
17030 -- GNAT we just decide to allow it anywhere at all. If it appeared then
17031 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
17032 -- node, and we insert a pragma Suppress (All_Checks) at the start of
17033 -- the context clause to ensure the correct processing.
17034
17035 if Has_Pragma_Suppress_All (N) then
17036 Prepend_To (Context_Items (N),
17037 Make_Pragma (Sloc (N),
17038 Chars => Name_Suppress,
17039 Pragma_Argument_Associations => New_List (
17040 Make_Pragma_Argument_Association (Sloc (N),
17041 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
17042 end if;
17043
17044 -- Nothing else to do at the current time!
17045
17046 end Process_Compilation_Unit_Pragmas;
17047
17048 --------
17049 -- rv --
17050 --------
17051
17052 procedure rv is
17053 begin
17054 null;
17055 end rv;
17056
17057 --------------------------------
17058 -- Set_Encoded_Interface_Name --
17059 --------------------------------
17060
17061 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
17062 Str : constant String_Id := Strval (S);
17063 Len : constant Int := String_Length (Str);
17064 CC : Char_Code;
17065 C : Character;
17066 J : Int;
17067
17068 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
17069
17070 procedure Encode;
17071 -- Stores encoded value of character code CC. The encoding we use an
17072 -- underscore followed by four lower case hex digits.
17073
17074 ------------
17075 -- Encode --
17076 ------------
17077
17078 procedure Encode is
17079 begin
17080 Store_String_Char (Get_Char_Code ('_'));
17081 Store_String_Char
17082 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
17083 Store_String_Char
17084 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
17085 Store_String_Char
17086 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
17087 Store_String_Char
17088 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
17089 end Encode;
17090
17091 -- Start of processing for Set_Encoded_Interface_Name
17092
17093 begin
17094 -- If first character is asterisk, this is a link name, and we leave it
17095 -- completely unmodified. We also ignore null strings (the latter case
17096 -- happens only in error cases) and no encoding should occur for Java or
17097 -- AAMP interface names.
17098
17099 if Len = 0
17100 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
17101 or else VM_Target /= No_VM
17102 or else AAMP_On_Target
17103 then
17104 Set_Interface_Name (E, S);
17105
17106 else
17107 J := 1;
17108 loop
17109 CC := Get_String_Char (Str, J);
17110
17111 exit when not In_Character_Range (CC);
17112
17113 C := Get_Character (CC);
17114
17115 exit when C /= '_' and then C /= '$'
17116 and then C not in '0' .. '9'
17117 and then C not in 'a' .. 'z'
17118 and then C not in 'A' .. 'Z';
17119
17120 if J = Len then
17121 Set_Interface_Name (E, S);
17122 return;
17123
17124 else
17125 J := J + 1;
17126 end if;
17127 end loop;
17128
17129 -- Here we need to encode. The encoding we use as follows:
17130 -- three underscores + four hex digits (lower case)
17131
17132 Start_String;
17133
17134 for J in 1 .. String_Length (Str) loop
17135 CC := Get_String_Char (Str, J);
17136
17137 if not In_Character_Range (CC) then
17138 Encode;
17139 else
17140 C := Get_Character (CC);
17141
17142 if C = '_' or else C = '$'
17143 or else C in '0' .. '9'
17144 or else C in 'a' .. 'z'
17145 or else C in 'A' .. 'Z'
17146 then
17147 Store_String_Char (CC);
17148 else
17149 Encode;
17150 end if;
17151 end if;
17152 end loop;
17153
17154 Set_Interface_Name (E,
17155 Make_String_Literal (Sloc (S),
17156 Strval => End_String));
17157 end if;
17158 end Set_Encoded_Interface_Name;
17159
17160 -------------------
17161 -- Set_Unit_Name --
17162 -------------------
17163
17164 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
17165 Pref : Node_Id;
17166 Scop : Entity_Id;
17167
17168 begin
17169 if Nkind (N) = N_Identifier
17170 and then Nkind (With_Item) = N_Identifier
17171 then
17172 Set_Entity (N, Entity (With_Item));
17173
17174 elsif Nkind (N) = N_Selected_Component then
17175 Change_Selected_Component_To_Expanded_Name (N);
17176 Set_Entity (N, Entity (With_Item));
17177 Set_Entity (Selector_Name (N), Entity (N));
17178
17179 Pref := Prefix (N);
17180 Scop := Scope (Entity (N));
17181 while Nkind (Pref) = N_Selected_Component loop
17182 Change_Selected_Component_To_Expanded_Name (Pref);
17183 Set_Entity (Selector_Name (Pref), Scop);
17184 Set_Entity (Pref, Scop);
17185 Pref := Prefix (Pref);
17186 Scop := Scope (Scop);
17187 end loop;
17188
17189 Set_Entity (Pref, Scop);
17190 end if;
17191 end Set_Unit_Name;
17192
17193 end Sem_Prag;