35410b8be3f035d4fa187650450ff153e70cd02d
[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-2012, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
31
32 with Aspects; use Aspects;
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Checks; use Checks;
36 with Csets; use Csets;
37 with Debug; use Debug;
38 with Einfo; use Einfo;
39 with Elists; use Elists;
40 with Errout; use Errout;
41 with Exp_Dist; use Exp_Dist;
42 with Exp_Util; use Exp_Util;
43 with Freeze; use Freeze;
44 with Lib; use Lib;
45 with Lib.Writ; use Lib.Writ;
46 with Lib.Xref; use Lib.Xref;
47 with Namet.Sp; use Namet.Sp;
48 with Nlists; use Nlists;
49 with Nmake; use Nmake;
50 with Opt; use Opt;
51 with Output; use Output;
52 with Par_SCO; use Par_SCO;
53 with Restrict; use Restrict;
54 with Rident; use Rident;
55 with Rtsfind; use Rtsfind;
56 with Sem; use Sem;
57 with Sem_Aux; use Sem_Aux;
58 with Sem_Ch3; use Sem_Ch3;
59 with Sem_Ch6; use Sem_Ch6;
60 with Sem_Ch8; use Sem_Ch8;
61 with Sem_Ch12; use Sem_Ch12;
62 with Sem_Ch13; use Sem_Ch13;
63 with Sem_Disp; use Sem_Disp;
64 with Sem_Dist; use Sem_Dist;
65 with Sem_Elim; use Sem_Elim;
66 with Sem_Eval; use Sem_Eval;
67 with Sem_Intr; use Sem_Intr;
68 with Sem_Mech; use Sem_Mech;
69 with Sem_Res; use Sem_Res;
70 with Sem_Type; use Sem_Type;
71 with Sem_Util; use Sem_Util;
72 with Sem_VFpt; use Sem_VFpt;
73 with Sem_Warn; use Sem_Warn;
74 with Stand; use Stand;
75 with Sinfo; use Sinfo;
76 with Sinfo.CN; use Sinfo.CN;
77 with Sinput; use Sinput;
78 with Snames; use Snames;
79 with Stringt; use Stringt;
80 with Stylesw; use Stylesw;
81 with Table;
82 with Targparm; use Targparm;
83 with Tbuild; use Tbuild;
84 with Ttypes;
85 with Uintp; use Uintp;
86 with Uname; use Uname;
87 with Urealp; use Urealp;
88 with Validsw; use Validsw;
89 with Warnsw; use Warnsw;
90
91 package body Sem_Prag is
92
93 ----------------------------------------------
94 -- Common Handling of Import-Export Pragmas --
95 ----------------------------------------------
96
97 -- In the following section, a number of Import_xxx and Export_xxx pragmas
98 -- are defined by GNAT. These are compatible with the DEC pragmas of the
99 -- same name, and all have the following common form and processing:
100
101 -- pragma Export_xxx
102 -- [Internal =>] LOCAL_NAME
103 -- [, [External =>] EXTERNAL_SYMBOL]
104 -- [, other optional parameters ]);
105
106 -- pragma Import_xxx
107 -- [Internal =>] LOCAL_NAME
108 -- [, [External =>] EXTERNAL_SYMBOL]
109 -- [, other optional parameters ]);
110
111 -- EXTERNAL_SYMBOL ::=
112 -- IDENTIFIER
113 -- | static_string_EXPRESSION
114
115 -- The internal LOCAL_NAME designates the entity that is imported or
116 -- exported, and must refer to an entity in the current declarative
117 -- part (as required by the rules for LOCAL_NAME).
118
119 -- The external linker name is designated by the External parameter if
120 -- given, or the Internal parameter if not (if there is no External
121 -- parameter, the External parameter is a copy of the Internal name).
122
123 -- If the External parameter is given as a string, then this string is
124 -- treated as an external name (exactly as though it had been given as an
125 -- External_Name parameter for a normal Import pragma).
126
127 -- If the External parameter is given as an identifier (or there is no
128 -- External parameter, so that the Internal identifier is used), then
129 -- the external name is the characters of the identifier, translated
130 -- to all upper case letters for OpenVMS versions of GNAT, and to all
131 -- lower case letters for all other versions
132
133 -- Note: the external name specified or implied by any of these special
134 -- Import_xxx or Export_xxx pragmas override an external or link name
135 -- specified in a previous Import or Export pragma.
136
137 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
138 -- named notation, following the standard rules for subprogram calls, i.e.
139 -- parameters can be given in any order if named notation is used, and
140 -- positional and named notation can be mixed, subject to the rule that all
141 -- positional parameters must appear first.
142
143 -- Note: All these pragmas are implemented exactly following the DEC design
144 -- and implementation and are intended to be fully compatible with the use
145 -- of these pragmas in the DEC Ada compiler.
146
147 --------------------------------------------
148 -- Checking for Duplicated External Names --
149 --------------------------------------------
150
151 -- It is suspicious if two separate Export pragmas use the same external
152 -- name. The following table is used to diagnose this situation so that
153 -- an appropriate warning can be issued.
154
155 -- The Node_Id stored is for the N_String_Literal node created to hold
156 -- the value of the external name. The Sloc of this node is used to
157 -- cross-reference the location of the duplication.
158
159 package Externals is new Table.Table (
160 Table_Component_Type => Node_Id,
161 Table_Index_Type => Int,
162 Table_Low_Bound => 0,
163 Table_Initial => 100,
164 Table_Increment => 100,
165 Table_Name => "Name_Externals");
166
167 -------------------------------------
168 -- Local Subprograms and Variables --
169 -------------------------------------
170
171 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
172 -- This routine is used for possible casing adjustment of an explicit
173 -- external name supplied as a string literal (the node N), according to
174 -- the casing requirement of Opt.External_Name_Casing. If this is set to
175 -- As_Is, then the string literal is returned unchanged, but if it is set
176 -- to Uppercase or Lowercase, then a new string literal with appropriate
177 -- casing is constructed.
178
179 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
180 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
181 -- original one, following the renaming chain) is returned. Otherwise the
182 -- entity is returned unchanged. Should be in Einfo???
183
184 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id);
185 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
186 -- of a Contract_Case or Test_Case pragma if present (possibly Empty). We
187 -- treat these as spec expressions (i.e. similar to a default expression).
188
189 procedure rv;
190 -- This is a dummy function called by the processing for pragma Reviewable.
191 -- It is there for assisting front end debugging. By placing a Reviewable
192 -- pragma in the source program, a breakpoint on rv catches this place in
193 -- the source, allowing convenient stepping to the point of interest.
194
195 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
196 -- Place semantic information on the argument of an Elaborate/Elaborate_All
197 -- pragma. Entity name for unit and its parents is taken from item in
198 -- previous with_clause that mentions the unit.
199
200 -------------------------------
201 -- Adjust_External_Name_Case --
202 -------------------------------
203
204 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
205 CC : Char_Code;
206
207 begin
208 -- Adjust case of literal if required
209
210 if Opt.External_Name_Exp_Casing = As_Is then
211 return N;
212
213 else
214 -- Copy existing string
215
216 Start_String;
217
218 -- Set proper casing
219
220 for J in 1 .. String_Length (Strval (N)) loop
221 CC := Get_String_Char (Strval (N), J);
222
223 if Opt.External_Name_Exp_Casing = Uppercase
224 and then CC >= Get_Char_Code ('a')
225 and then CC <= Get_Char_Code ('z')
226 then
227 Store_String_Char (CC - 32);
228
229 elsif Opt.External_Name_Exp_Casing = Lowercase
230 and then CC >= Get_Char_Code ('A')
231 and then CC <= Get_Char_Code ('Z')
232 then
233 Store_String_Char (CC + 32);
234
235 else
236 Store_String_Char (CC);
237 end if;
238 end loop;
239
240 return
241 Make_String_Literal (Sloc (N),
242 Strval => End_String);
243 end if;
244 end Adjust_External_Name_Case;
245
246 ------------------------------
247 -- Analyze_CTC_In_Decl_Part --
248 ------------------------------
249
250 procedure Analyze_CTC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
251 begin
252 -- Install formals and push subprogram spec onto scope stack so that we
253 -- can see the formals from the pragma.
254
255 Install_Formals (S);
256 Push_Scope (S);
257
258 -- Preanalyze the boolean expressions, we treat these as spec
259 -- expressions (i.e. similar to a default expression).
260
261 Preanalyze_CTC_Args
262 (N,
263 Get_Requires_From_CTC_Pragma (N),
264 Get_Ensures_From_CTC_Pragma (N));
265
266 -- Remove the subprogram from the scope stack now that the pre-analysis
267 -- of the expressions in the contract case or test case is done.
268
269 End_Scope;
270 end Analyze_CTC_In_Decl_Part;
271
272 ------------------------------
273 -- Analyze_PPC_In_Decl_Part --
274 ------------------------------
275
276 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
277 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
278
279 begin
280 -- Install formals and push subprogram spec onto scope stack so that we
281 -- can see the formals from the pragma.
282
283 Install_Formals (S);
284 Push_Scope (S);
285
286 -- Preanalyze the boolean expression, we treat this as a spec expression
287 -- (i.e. similar to a default expression).
288
289 Preanalyze_Assert_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean);
290
291 -- In ASIS mode, for a pragma generated from a source aspect, also
292 -- analyze the original aspect expression.
293
294 if ASIS_Mode
295 and then Present (Corresponding_Aspect (N))
296 then
297 Preanalyze_Assert_Expression
298 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
299 end if;
300
301 -- For a class-wide condition, a reference to a controlling formal must
302 -- be interpreted as having the class-wide type (or an access to such)
303 -- so that the inherited condition can be properly applied to any
304 -- overriding operation (see ARM12 6.6.1 (7)).
305
306 if Class_Present (N) then
307 Class_Wide_Condition : declare
308 T : constant Entity_Id := Find_Dispatching_Type (S);
309
310 ACW : Entity_Id := Empty;
311 -- Access to T'class, created if there is a controlling formal
312 -- that is an access parameter.
313
314 function Get_ACW return Entity_Id;
315 -- If the expression has a reference to an controlling access
316 -- parameter, create an access to T'class for the necessary
317 -- conversions if one does not exist.
318
319 function Process (N : Node_Id) return Traverse_Result;
320 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
321 -- aspect for a primitive subprogram of a tagged type T, a name
322 -- that denotes a formal parameter of type T is interpreted as
323 -- having type T'Class. Similarly, a name that denotes a formal
324 -- accessparameter of type access-to-T is interpreted as having
325 -- type access-to-T'Class. This ensures the expression is well-
326 -- defined for a primitive subprogram of a type descended from T.
327
328 -------------
329 -- Get_ACW --
330 -------------
331
332 function Get_ACW return Entity_Id is
333 Loc : constant Source_Ptr := Sloc (N);
334 Decl : Node_Id;
335
336 begin
337 if No (ACW) then
338 Decl := Make_Full_Type_Declaration (Loc,
339 Defining_Identifier => Make_Temporary (Loc, 'T'),
340 Type_Definition =>
341 Make_Access_To_Object_Definition (Loc,
342 Subtype_Indication =>
343 New_Occurrence_Of (Class_Wide_Type (T), Loc),
344 All_Present => True));
345
346 Insert_Before (Unit_Declaration_Node (S), Decl);
347 Analyze (Decl);
348 ACW := Defining_Identifier (Decl);
349 Freeze_Before (Unit_Declaration_Node (S), ACW);
350 end if;
351
352 return ACW;
353 end Get_ACW;
354
355 -------------
356 -- Process --
357 -------------
358
359 function Process (N : Node_Id) return Traverse_Result is
360 Loc : constant Source_Ptr := Sloc (N);
361 Typ : Entity_Id;
362
363 begin
364 if Is_Entity_Name (N)
365 and then Is_Formal (Entity (N))
366 and then Nkind (Parent (N)) /= N_Type_Conversion
367 then
368 if Etype (Entity (N)) = T then
369 Typ := Class_Wide_Type (T);
370
371 elsif Is_Access_Type (Etype (Entity (N)))
372 and then Designated_Type (Etype (Entity (N))) = T
373 then
374 Typ := Get_ACW;
375 else
376 Typ := Empty;
377 end if;
378
379 if Present (Typ) then
380 Rewrite (N,
381 Make_Type_Conversion (Loc,
382 Subtype_Mark =>
383 New_Occurrence_Of (Typ, Loc),
384 Expression => New_Occurrence_Of (Entity (N), Loc)));
385 Set_Etype (N, Typ);
386 end if;
387 end if;
388
389 return OK;
390 end Process;
391
392 procedure Replace_Type is new Traverse_Proc (Process);
393
394 -- Start of processing for Class_Wide_Condition
395
396 begin
397 if not Present (T) then
398 Error_Msg_Name_1 :=
399 Chars (Identifier (Corresponding_Aspect (N)));
400
401 Error_Msg_Name_2 := Name_Class;
402
403 Error_Msg_N
404 ("aspect `%''%` can only be specified for a primitive " &
405 "operation of a tagged type",
406 Corresponding_Aspect (N));
407 end if;
408
409 Replace_Type (Get_Pragma_Arg (Arg1));
410 end Class_Wide_Condition;
411 end if;
412
413 -- Remove the subprogram from the scope stack now that the pre-analysis
414 -- of the precondition/postcondition is done.
415
416 End_Scope;
417 end Analyze_PPC_In_Decl_Part;
418
419 --------------------
420 -- Analyze_Pragma --
421 --------------------
422
423 procedure Analyze_Pragma (N : Node_Id) is
424 Loc : constant Source_Ptr := Sloc (N);
425 Prag_Id : Pragma_Id;
426
427 Pname : Name_Id;
428 -- Name of the source pragma, or name of the corresponding aspect for
429 -- pragmas which originate in a source aspect. In the latter case, the
430 -- name may be different from the pragma name.
431
432 Pragma_Exit : exception;
433 -- This exception is used to exit pragma processing completely. It is
434 -- used when an error is detected, and no further processing is
435 -- required. It is also used if an earlier error has left the tree in
436 -- a state where the pragma should not be processed.
437
438 Arg_Count : Nat;
439 -- Number of pragma argument associations
440
441 Arg1 : Node_Id;
442 Arg2 : Node_Id;
443 Arg3 : Node_Id;
444 Arg4 : Node_Id;
445 -- First four pragma arguments (pragma argument association nodes, or
446 -- Empty if the corresponding argument does not exist).
447
448 type Name_List is array (Natural range <>) of Name_Id;
449 type Args_List is array (Natural range <>) of Node_Id;
450 -- Types used for arguments to Check_Arg_Order and Gather_Associations
451
452 procedure Ada_2005_Pragma;
453 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
454 -- Ada 95 mode, these are implementation defined pragmas, so should be
455 -- caught by the No_Implementation_Pragmas restriction.
456
457 procedure Ada_2012_Pragma;
458 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
459 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
460 -- should be caught by the No_Implementation_Pragmas restriction.
461
462 procedure Check_Ada_83_Warning;
463 -- Issues a warning message for the current pragma if operating in Ada
464 -- 83 mode (used for language pragmas that are not a standard part of
465 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
466 -- of 95 pragma.
467
468 procedure Check_Arg_Count (Required : Nat);
469 -- Check argument count for pragma is equal to given parameter. If not,
470 -- then issue an error message and raise Pragma_Exit.
471
472 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
473 -- Arg which can either be a pragma argument association, in which case
474 -- the check is applied to the expression of the association or an
475 -- expression directly.
476
477 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
478 -- Check that an argument has the right form for an EXTERNAL_NAME
479 -- parameter of an extended import/export pragma. The rule is that the
480 -- name must be an identifier or string literal (in Ada 83 mode) or a
481 -- static string expression (in Ada 95 mode).
482
483 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
484 -- Check the specified argument Arg to make sure that it is an
485 -- identifier. If not give error and raise Pragma_Exit.
486
487 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
488 -- Check the specified argument Arg to make sure that it is an integer
489 -- literal. If not give error and raise Pragma_Exit.
490
491 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
492 -- Check the specified argument Arg to make sure that it has the proper
493 -- syntactic form for a local name and meets the semantic requirements
494 -- for a local name. The local name is analyzed as part of the
495 -- processing for this call. In addition, the local name is required
496 -- to represent an entity at the library level.
497
498 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
499 -- Check the specified argument Arg to make sure that it has the proper
500 -- syntactic form for a local name and meets the semantic requirements
501 -- for a local name. The local name is analyzed as part of the
502 -- processing for this call.
503
504 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
505 -- Check the specified argument Arg to make sure that it is a valid
506 -- locking policy name. If not give error and raise Pragma_Exit.
507
508 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
509 -- Check the specified argument Arg to make sure that it is a valid
510 -- elaboration policy name. If not give error and raise Pragma_Exit.
511
512 procedure Check_Arg_Is_One_Of
513 (Arg : Node_Id;
514 N1, N2 : Name_Id);
515 procedure Check_Arg_Is_One_Of
516 (Arg : Node_Id;
517 N1, N2, N3 : Name_Id);
518 procedure Check_Arg_Is_One_Of
519 (Arg : Node_Id;
520 N1, N2, N3, N4 : Name_Id);
521 procedure Check_Arg_Is_One_Of
522 (Arg : Node_Id;
523 N1, N2, N3, N4, N5 : Name_Id);
524 -- Check the specified argument Arg to make sure that it is an
525 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
526 -- present). If not then give error and raise Pragma_Exit.
527
528 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
529 -- Check the specified argument Arg to make sure that it is a valid
530 -- queuing policy name. If not give error and raise Pragma_Exit.
531
532 procedure Check_Arg_Is_Static_Expression
533 (Arg : Node_Id;
534 Typ : Entity_Id := Empty);
535 -- Check the specified argument Arg to make sure that it is a static
536 -- expression of the given type (i.e. it will be analyzed and resolved
537 -- using this type, which can be any valid argument to Resolve, e.g.
538 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
539 -- Typ is left Empty, then any static expression is allowed.
540
541 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
542 -- Check the specified argument Arg to make sure that it is a valid task
543 -- dispatching policy name. If not give error and raise Pragma_Exit.
544
545 procedure Check_Arg_Order (Names : Name_List);
546 -- Checks for an instance of two arguments with identifiers for the
547 -- current pragma which are not in the sequence indicated by Names,
548 -- and if so, generates a fatal message about bad order of arguments.
549
550 procedure Check_At_Least_N_Arguments (N : Nat);
551 -- Check there are at least N arguments present
552
553 procedure Check_At_Most_N_Arguments (N : Nat);
554 -- Check there are no more than N arguments present
555
556 procedure Check_Component
557 (Comp : Node_Id;
558 UU_Typ : Entity_Id;
559 In_Variant_Part : Boolean := False);
560 -- Examine an Unchecked_Union component for correct use of per-object
561 -- constrained subtypes, and for restrictions on finalizable components.
562 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
563 -- should be set when Comp comes from a record variant.
564
565 procedure Check_Contract_Or_Test_Case;
566 -- Called to process a contract-case or test-case pragma. It
567 -- starts with checking pragma arguments, and the rest of the
568 -- treatment is similar to the one for pre- and postcondition in
569 -- Check_Precondition_Postcondition, except the placement rules for the
570 -- contract-case and test-case pragmas are stricter. These pragmas may
571 -- only occur after a subprogram spec declared directly in a package
572 -- spec unit. In this case, the pragma is chained to the subprogram in
573 -- question (using Spec_CTC_List and Next_Pragma) and analysis of the
574 -- pragma is delayed till the end of the spec. In all other cases, an
575 -- error message for bad placement is given.
576
577 procedure Check_Duplicate_Pragma (E : Entity_Id);
578 -- Check if a rep item of the same name as the current pragma is already
579 -- chained as a rep pragma to the given entity. If so give a message
580 -- about the duplicate, and then raise Pragma_Exit so does not return.
581
582 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
583 -- Nam is an N_String_Literal node containing the external name set by
584 -- an Import or Export pragma (or extended Import or Export pragma).
585 -- This procedure checks for possible duplications if this is the export
586 -- case, and if found, issues an appropriate error message.
587
588 procedure Check_Expr_Is_Static_Expression
589 (Expr : Node_Id;
590 Typ : Entity_Id := Empty);
591 -- Check the specified expression Expr to make sure that it is a static
592 -- expression of the given type (i.e. it will be analyzed and resolved
593 -- using this type, which can be any valid argument to Resolve, e.g.
594 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
595 -- Typ is left Empty, then any static expression is allowed.
596
597 procedure Check_First_Subtype (Arg : Node_Id);
598 -- Checks that Arg, whose expression is an entity name, references a
599 -- first subtype.
600
601 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
602 -- Checks that the given argument has an identifier, and if so, requires
603 -- it to match the given identifier name. If there is no identifier, or
604 -- a non-matching identifier, then an error message is given and
605 -- Pragma_Exit is raised.
606
607 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
608 -- Checks that the given argument has an identifier, and if so, requires
609 -- it to match one of the given identifier names. If there is no
610 -- identifier, or a non-matching identifier, then an error message is
611 -- given and Pragma_Exit is raised.
612
613 procedure Check_In_Main_Program;
614 -- Common checks for pragmas that appear within a main program
615 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
616
617 procedure Check_Interrupt_Or_Attach_Handler;
618 -- Common processing for first argument of pragma Interrupt_Handler or
619 -- pragma Attach_Handler.
620
621 procedure Check_Loop_Invariant_Variant_Placement;
622 -- Verify whether pragma Loop_Invariant or pragma Loop_Variant appear
623 -- immediately within a construct restricted to loops.
624
625 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
626 -- Check that pragma appears in a declarative part, or in a package
627 -- specification, i.e. that it does not occur in a statement sequence
628 -- in a body.
629
630 procedure Check_No_Identifier (Arg : Node_Id);
631 -- Checks that the given argument does not have an identifier. If
632 -- an identifier is present, then an error message is issued, and
633 -- Pragma_Exit is raised.
634
635 procedure Check_No_Identifiers;
636 -- Checks that none of the arguments to the pragma has an identifier.
637 -- If any argument has an identifier, then an error message is issued,
638 -- and Pragma_Exit is raised.
639
640 procedure Check_No_Link_Name;
641 -- Checks that no link name is specified
642
643 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
644 -- Checks if the given argument has an identifier, and if so, requires
645 -- it to match the given identifier name. If there is a non-matching
646 -- identifier, then an error message is given and Pragma_Exit is raised.
647
648 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
649 -- Checks if the given argument has an identifier, and if so, requires
650 -- it to match the given identifier name. If there is a non-matching
651 -- identifier, then an error message is given and Pragma_Exit is raised.
652 -- In this version of the procedure, the identifier name is given as
653 -- a string with lower case letters.
654
655 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
656 -- Called to process a precondition or postcondition pragma. There are
657 -- three cases:
658 --
659 -- The pragma appears after a subprogram spec
660 --
661 -- If the corresponding check is not enabled, the pragma is analyzed
662 -- but otherwise ignored and control returns with In_Body set False.
663 --
664 -- If the check is enabled, then the first step is to analyze the
665 -- pragma, but this is skipped if the subprogram spec appears within
666 -- a package specification (because this is the case where we delay
667 -- analysis till the end of the spec). Then (whether or not it was
668 -- analyzed), the pragma is chained to the subprogram in question
669 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
670 -- caller with In_Body set False.
671 --
672 -- The pragma appears at the start of subprogram body declarations
673 --
674 -- In this case an immediate return to the caller is made with
675 -- In_Body set True, and the pragma is NOT analyzed.
676 --
677 -- In all other cases, an error message for bad placement is given
678
679 procedure Check_Static_Constraint (Constr : Node_Id);
680 -- Constr is a constraint from an N_Subtype_Indication node from a
681 -- component constraint in an Unchecked_Union type. This routine checks
682 -- that the constraint is static as required by the restrictions for
683 -- Unchecked_Union.
684
685 procedure Check_Valid_Configuration_Pragma;
686 -- Legality checks for placement of a configuration pragma
687
688 procedure Check_Valid_Library_Unit_Pragma;
689 -- Legality checks for library unit pragmas. A special case arises for
690 -- pragmas in generic instances that come from copies of the original
691 -- library unit pragmas in the generic templates. In the case of other
692 -- than library level instantiations these can appear in contexts which
693 -- would normally be invalid (they only apply to the original template
694 -- and to library level instantiations), and they are simply ignored,
695 -- which is implemented by rewriting them as null statements.
696
697 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
698 -- Check an Unchecked_Union variant for lack of nested variants and
699 -- presence of at least one component. UU_Typ is the related Unchecked_
700 -- Union type.
701
702 procedure Error_Pragma (Msg : String);
703 pragma No_Return (Error_Pragma);
704 -- Outputs error message for current pragma. The message contains a %
705 -- that will be replaced with the pragma name, and the flag is placed
706 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
707 -- calls Fix_Error (see spec of that function for details).
708
709 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
710 pragma No_Return (Error_Pragma_Arg);
711 -- Outputs error message for current pragma. The message may contain
712 -- a % that will be replaced with the pragma name. The parameter Arg
713 -- may either be a pragma argument association, in which case the flag
714 -- is placed on the expression of this association, or an expression,
715 -- in which case the flag is placed directly on the expression. The
716 -- message is placed using Error_Msg_N, so the message may also contain
717 -- an & insertion character which will reference the given Arg value.
718 -- After placing the message, Pragma_Exit is raised. Note: this routine
719 -- calls Fix_Error (see spec of that function for details).
720
721 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
722 pragma No_Return (Error_Pragma_Arg);
723 -- Similar to above form of Error_Pragma_Arg except that two messages
724 -- are provided, the second is a continuation comment starting with \.
725
726 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
727 pragma No_Return (Error_Pragma_Arg_Ident);
728 -- Outputs error message for current pragma. The message may contain
729 -- a % that will be replaced with the pragma name. The parameter Arg
730 -- must be a pragma argument association with a non-empty identifier
731 -- (i.e. its Chars field must be set), and the error message is placed
732 -- on the identifier. The message is placed using Error_Msg_N so
733 -- the message may also contain an & insertion character which will
734 -- reference the identifier. After placing the message, Pragma_Exit
735 -- is raised. Note: this routine calls Fix_Error (see spec of that
736 -- function for details).
737
738 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
739 pragma No_Return (Error_Pragma_Ref);
740 -- Outputs error message for current pragma. The message may contain
741 -- a % that will be replaced with the pragma name. The parameter Ref
742 -- must be an entity whose name can be referenced by & and sloc by #.
743 -- After placing the message, Pragma_Exit is raised. Note: this routine
744 -- calls Fix_Error (see spec of that function for details).
745
746 function Find_Lib_Unit_Name return Entity_Id;
747 -- Used for a library unit pragma to find the entity to which the
748 -- library unit pragma applies, returns the entity found.
749
750 procedure Find_Program_Unit_Name (Id : Node_Id);
751 -- If the pragma is a compilation unit pragma, the id must denote the
752 -- compilation unit in the same compilation, and the pragma must appear
753 -- in the list of preceding or trailing pragmas. If it is a program
754 -- unit pragma that is not a compilation unit pragma, then the
755 -- identifier must be visible.
756
757 function Find_Unique_Parameterless_Procedure
758 (Name : Entity_Id;
759 Arg : Node_Id) return Entity_Id;
760 -- Used for a procedure pragma to find the unique parameterless
761 -- procedure identified by Name, returns it if it exists, otherwise
762 -- errors out and uses Arg as the pragma argument for the message.
763
764 procedure Fix_Error (Msg : in out String);
765 -- This is called prior to issuing an error message. Msg is a string
766 -- that typically contains the substring "pragma". If the current pragma
767 -- comes from an aspect, each such "pragma" substring is replaced with
768 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
769 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
770
771 procedure Gather_Associations
772 (Names : Name_List;
773 Args : out Args_List);
774 -- This procedure is used to gather the arguments for a pragma that
775 -- permits arbitrary ordering of parameters using the normal rules
776 -- for named and positional parameters. The Names argument is a list
777 -- of Name_Id values that corresponds to the allowed pragma argument
778 -- association identifiers in order. The result returned in Args is
779 -- a list of corresponding expressions that are the pragma arguments.
780 -- Note that this is a list of expressions, not of pragma argument
781 -- associations (Gather_Associations has completely checked all the
782 -- optional identifiers when it returns). An entry in Args is Empty
783 -- on return if the corresponding argument is not present.
784
785 procedure GNAT_Pragma;
786 -- Called for all GNAT defined pragmas to check the relevant restriction
787 -- (No_Implementation_Pragmas).
788
789 procedure S14_Pragma;
790 -- Called for all pragmas defined for formal verification to check that
791 -- the S14_Extensions flag is set.
792
793 function Is_Before_First_Decl
794 (Pragma_Node : Node_Id;
795 Decls : List_Id) return Boolean;
796 -- Return True if Pragma_Node is before the first declarative item in
797 -- Decls where Decls is the list of declarative items.
798
799 function Is_Configuration_Pragma return Boolean;
800 -- Determines if the placement of the current pragma is appropriate
801 -- for a configuration pragma.
802
803 function Is_In_Context_Clause return Boolean;
804 -- Returns True if pragma appears within the context clause of a unit,
805 -- and False for any other placement (does not generate any messages).
806
807 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
808 -- Analyzes the argument, and determines if it is a static string
809 -- expression, returns True if so, False if non-static or not String.
810
811 procedure Pragma_Misplaced;
812 pragma No_Return (Pragma_Misplaced);
813 -- Issue fatal error message for misplaced pragma
814
815 procedure Process_Atomic_Shared_Volatile;
816 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
817 -- Shared is an obsolete Ada 83 pragma, treated as being identical
818 -- in effect to pragma Atomic.
819
820 procedure Process_Compile_Time_Warning_Or_Error;
821 -- Common processing for Compile_Time_Error and Compile_Time_Warning
822
823 procedure Process_Convention
824 (C : out Convention_Id;
825 Ent : out Entity_Id);
826 -- Common processing for Convention, Interface, Import and Export.
827 -- Checks first two arguments of pragma, and sets the appropriate
828 -- convention value in the specified entity or entities. On return
829 -- C is the convention, Ent is the referenced entity.
830
831 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
832 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
833 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
834
835 procedure Process_Extended_Import_Export_Exception_Pragma
836 (Arg_Internal : Node_Id;
837 Arg_External : Node_Id;
838 Arg_Form : Node_Id;
839 Arg_Code : Node_Id);
840 -- Common processing for the pragmas Import/Export_Exception. The three
841 -- arguments correspond to the three named parameters of the pragma. An
842 -- argument is empty if the corresponding parameter is not present in
843 -- the pragma.
844
845 procedure Process_Extended_Import_Export_Object_Pragma
846 (Arg_Internal : Node_Id;
847 Arg_External : Node_Id;
848 Arg_Size : Node_Id);
849 -- Common processing for the pragmas Import/Export_Object. The three
850 -- arguments correspond to the three named parameters of the pragmas. An
851 -- argument is empty if the corresponding parameter is not present in
852 -- the pragma.
853
854 procedure Process_Extended_Import_Export_Internal_Arg
855 (Arg_Internal : Node_Id := Empty);
856 -- Common processing for all extended Import and Export pragmas. The
857 -- argument is the pragma parameter for the Internal argument. If
858 -- Arg_Internal is empty or inappropriate, an error message is posted.
859 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
860 -- set to identify the referenced entity.
861
862 procedure Process_Extended_Import_Export_Subprogram_Pragma
863 (Arg_Internal : Node_Id;
864 Arg_External : Node_Id;
865 Arg_Parameter_Types : Node_Id;
866 Arg_Result_Type : Node_Id := Empty;
867 Arg_Mechanism : Node_Id;
868 Arg_Result_Mechanism : Node_Id := Empty;
869 Arg_First_Optional_Parameter : Node_Id := Empty);
870 -- Common processing for all extended Import and Export pragmas applying
871 -- to subprograms. The caller omits any arguments that do not apply to
872 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
873 -- only in the Import_Function and Export_Function cases). The argument
874 -- names correspond to the allowed pragma association identifiers.
875
876 procedure Process_Generic_List;
877 -- Common processing for Share_Generic and Inline_Generic
878
879 procedure Process_Import_Or_Interface;
880 -- Common processing for Import of Interface
881
882 procedure Process_Import_Predefined_Type;
883 -- Processing for completing a type with pragma Import. This is used
884 -- to declare types that match predefined C types, especially for cases
885 -- without corresponding Ada predefined type.
886
887 procedure Process_Inline (Active : Boolean);
888 -- Common processing for Inline and Inline_Always. The parameter
889 -- indicates if the inline pragma is active, i.e. if it should actually
890 -- cause inlining to occur.
891
892 procedure Process_Interface_Name
893 (Subprogram_Def : Entity_Id;
894 Ext_Arg : Node_Id;
895 Link_Arg : Node_Id);
896 -- Given the last two arguments of pragma Import, pragma Export, or
897 -- pragma Interface_Name, performs validity checks and sets the
898 -- Interface_Name field of the given subprogram entity to the
899 -- appropriate external or link name, depending on the arguments given.
900 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
901 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
902 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
903 -- nor Link_Arg is present, the interface name is set to the default
904 -- from the subprogram name.
905
906 procedure Process_Interrupt_Or_Attach_Handler;
907 -- Common processing for Interrupt and Attach_Handler pragmas
908
909 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
910 -- Common processing for Restrictions and Restriction_Warnings pragmas.
911 -- Warn is True for Restriction_Warnings, or for Restrictions if the
912 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
913 -- is not set in the Restrictions case.
914
915 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
916 -- Common processing for Suppress and Unsuppress. The boolean parameter
917 -- Suppress_Case is True for the Suppress case, and False for the
918 -- Unsuppress case.
919
920 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
921 -- This procedure sets the Is_Exported flag for the given entity,
922 -- checking that the entity was not previously imported. Arg is
923 -- the argument that specified the entity. A check is also made
924 -- for exporting inappropriate entities.
925
926 procedure Set_Extended_Import_Export_External_Name
927 (Internal_Ent : Entity_Id;
928 Arg_External : Node_Id);
929 -- Common processing for all extended import export pragmas. The first
930 -- argument, Internal_Ent, is the internal entity, which has already
931 -- been checked for validity by the caller. Arg_External is from the
932 -- Import or Export pragma, and may be null if no External parameter
933 -- was present. If Arg_External is present and is a non-null string
934 -- (a null string is treated as the default), then the Interface_Name
935 -- field of Internal_Ent is set appropriately.
936
937 procedure Set_Imported (E : Entity_Id);
938 -- This procedure sets the Is_Imported flag for the given entity,
939 -- checking that it is not previously exported or imported.
940
941 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
942 -- Mech is a parameter passing mechanism (see Import_Function syntax
943 -- for MECHANISM_NAME). This routine checks that the mechanism argument
944 -- has the right form, and if not issues an error message. If the
945 -- argument has the right form then the Mechanism field of Ent is
946 -- set appropriately.
947
948 procedure Set_Ravenscar_Profile (N : Node_Id);
949 -- Activate the set of configuration pragmas and restrictions that make
950 -- up the Ravenscar Profile. N is the corresponding pragma node, which
951 -- is used for error messages on any constructs that violate the
952 -- profile.
953
954 ---------------------
955 -- Ada_2005_Pragma --
956 ---------------------
957
958 procedure Ada_2005_Pragma is
959 begin
960 if Ada_Version <= Ada_95 then
961 Check_Restriction (No_Implementation_Pragmas, N);
962 end if;
963 end Ada_2005_Pragma;
964
965 ---------------------
966 -- Ada_2012_Pragma --
967 ---------------------
968
969 procedure Ada_2012_Pragma is
970 begin
971 if Ada_Version <= Ada_2005 then
972 Check_Restriction (No_Implementation_Pragmas, N);
973 end if;
974 end Ada_2012_Pragma;
975
976 --------------------------
977 -- Check_Ada_83_Warning --
978 --------------------------
979
980 procedure Check_Ada_83_Warning is
981 begin
982 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
983 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
984 end if;
985 end Check_Ada_83_Warning;
986
987 ---------------------
988 -- Check_Arg_Count --
989 ---------------------
990
991 procedure Check_Arg_Count (Required : Nat) is
992 begin
993 if Arg_Count /= Required then
994 Error_Pragma ("wrong number of arguments for pragma%");
995 end if;
996 end Check_Arg_Count;
997
998 --------------------------------
999 -- Check_Arg_Is_External_Name --
1000 --------------------------------
1001
1002 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
1003 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1004
1005 begin
1006 if Nkind (Argx) = N_Identifier then
1007 return;
1008
1009 else
1010 Analyze_And_Resolve (Argx, Standard_String);
1011
1012 if Is_OK_Static_Expression (Argx) then
1013 return;
1014
1015 elsif Etype (Argx) = Any_Type then
1016 raise Pragma_Exit;
1017
1018 -- An interesting special case, if we have a string literal and
1019 -- we are in Ada 83 mode, then we allow it even though it will
1020 -- not be flagged as static. This allows expected Ada 83 mode
1021 -- use of external names which are string literals, even though
1022 -- technically these are not static in Ada 83.
1023
1024 elsif Ada_Version = Ada_83
1025 and then Nkind (Argx) = N_String_Literal
1026 then
1027 return;
1028
1029 -- Static expression that raises Constraint_Error. This has
1030 -- already been flagged, so just exit from pragma processing.
1031
1032 elsif Is_Static_Expression (Argx) then
1033 raise Pragma_Exit;
1034
1035 -- Here we have a real error (non-static expression)
1036
1037 else
1038 Error_Msg_Name_1 := Pname;
1039
1040 declare
1041 Msg : String :=
1042 "argument for pragma% must be a identifier or "
1043 & "static string expression!";
1044 begin
1045 Fix_Error (Msg);
1046 Flag_Non_Static_Expr (Msg, Argx);
1047 raise Pragma_Exit;
1048 end;
1049 end if;
1050 end if;
1051 end Check_Arg_Is_External_Name;
1052
1053 -----------------------------
1054 -- Check_Arg_Is_Identifier --
1055 -----------------------------
1056
1057 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
1058 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1059 begin
1060 if Nkind (Argx) /= N_Identifier then
1061 Error_Pragma_Arg
1062 ("argument for pragma% must be identifier", Argx);
1063 end if;
1064 end Check_Arg_Is_Identifier;
1065
1066 ----------------------------------
1067 -- Check_Arg_Is_Integer_Literal --
1068 ----------------------------------
1069
1070 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1071 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1072 begin
1073 if Nkind (Argx) /= N_Integer_Literal then
1074 Error_Pragma_Arg
1075 ("argument for pragma% must be integer literal", Argx);
1076 end if;
1077 end Check_Arg_Is_Integer_Literal;
1078
1079 -------------------------------------------
1080 -- Check_Arg_Is_Library_Level_Local_Name --
1081 -------------------------------------------
1082
1083 -- LOCAL_NAME ::=
1084 -- DIRECT_NAME
1085 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1086 -- | library_unit_NAME
1087
1088 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1089 begin
1090 Check_Arg_Is_Local_Name (Arg);
1091
1092 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1093 and then Comes_From_Source (N)
1094 then
1095 Error_Pragma_Arg
1096 ("argument for pragma% must be library level entity", Arg);
1097 end if;
1098 end Check_Arg_Is_Library_Level_Local_Name;
1099
1100 -----------------------------
1101 -- Check_Arg_Is_Local_Name --
1102 -----------------------------
1103
1104 -- LOCAL_NAME ::=
1105 -- DIRECT_NAME
1106 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1107 -- | library_unit_NAME
1108
1109 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1110 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1111
1112 begin
1113 Analyze (Argx);
1114
1115 if Nkind (Argx) not in N_Direct_Name
1116 and then (Nkind (Argx) /= N_Attribute_Reference
1117 or else Present (Expressions (Argx))
1118 or else Nkind (Prefix (Argx)) /= N_Identifier)
1119 and then (not Is_Entity_Name (Argx)
1120 or else not Is_Compilation_Unit (Entity (Argx)))
1121 then
1122 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1123 end if;
1124
1125 -- No further check required if not an entity name
1126
1127 if not Is_Entity_Name (Argx) then
1128 null;
1129
1130 else
1131 declare
1132 OK : Boolean;
1133 Ent : constant Entity_Id := Entity (Argx);
1134 Scop : constant Entity_Id := Scope (Ent);
1135 begin
1136 -- Case of a pragma applied to a compilation unit: pragma must
1137 -- occur immediately after the program unit in the compilation.
1138
1139 if Is_Compilation_Unit (Ent) then
1140 declare
1141 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1142
1143 begin
1144 -- Case of pragma placed immediately after spec
1145
1146 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1147 OK := True;
1148
1149 -- Case of pragma placed immediately after body
1150
1151 elsif Nkind (Decl) = N_Subprogram_Declaration
1152 and then Present (Corresponding_Body (Decl))
1153 then
1154 OK := Parent (N) =
1155 Aux_Decls_Node
1156 (Parent (Unit_Declaration_Node
1157 (Corresponding_Body (Decl))));
1158
1159 -- All other cases are illegal
1160
1161 else
1162 OK := False;
1163 end if;
1164 end;
1165
1166 -- Special restricted placement rule from 10.2.1(11.8/2)
1167
1168 elsif Is_Generic_Formal (Ent)
1169 and then Prag_Id = Pragma_Preelaborable_Initialization
1170 then
1171 OK := List_Containing (N) =
1172 Generic_Formal_Declarations
1173 (Unit_Declaration_Node (Scop));
1174
1175 -- Default case, just check that the pragma occurs in the scope
1176 -- of the entity denoted by the name.
1177
1178 else
1179 OK := Current_Scope = Scop;
1180 end if;
1181
1182 if not OK then
1183 Error_Pragma_Arg
1184 ("pragma% argument must be in same declarative part", Arg);
1185 end if;
1186 end;
1187 end if;
1188 end Check_Arg_Is_Local_Name;
1189
1190 ---------------------------------
1191 -- Check_Arg_Is_Locking_Policy --
1192 ---------------------------------
1193
1194 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1195 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1196
1197 begin
1198 Check_Arg_Is_Identifier (Argx);
1199
1200 if not Is_Locking_Policy_Name (Chars (Argx)) then
1201 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1202 end if;
1203 end Check_Arg_Is_Locking_Policy;
1204
1205 -----------------------------------------------
1206 -- Check_Arg_Is_Partition_Elaboration_Policy --
1207 -----------------------------------------------
1208
1209 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
1210 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1211
1212 begin
1213 Check_Arg_Is_Identifier (Argx);
1214
1215 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
1216 Error_Pragma_Arg
1217 ("& is not a valid partition elaboration policy name", Argx);
1218 end if;
1219 end Check_Arg_Is_Partition_Elaboration_Policy;
1220
1221 -------------------------
1222 -- Check_Arg_Is_One_Of --
1223 -------------------------
1224
1225 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1226 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1227
1228 begin
1229 Check_Arg_Is_Identifier (Argx);
1230
1231 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1232 Error_Msg_Name_2 := N1;
1233 Error_Msg_Name_3 := N2;
1234 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1235 end if;
1236 end Check_Arg_Is_One_Of;
1237
1238 procedure Check_Arg_Is_One_Of
1239 (Arg : Node_Id;
1240 N1, N2, N3 : Name_Id)
1241 is
1242 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1243
1244 begin
1245 Check_Arg_Is_Identifier (Argx);
1246
1247 if Chars (Argx) /= N1
1248 and then Chars (Argx) /= N2
1249 and then Chars (Argx) /= N3
1250 then
1251 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1252 end if;
1253 end Check_Arg_Is_One_Of;
1254
1255 procedure Check_Arg_Is_One_Of
1256 (Arg : Node_Id;
1257 N1, N2, N3, N4 : Name_Id)
1258 is
1259 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1260
1261 begin
1262 Check_Arg_Is_Identifier (Argx);
1263
1264 if Chars (Argx) /= N1
1265 and then Chars (Argx) /= N2
1266 and then Chars (Argx) /= N3
1267 and then Chars (Argx) /= N4
1268 then
1269 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1270 end if;
1271 end Check_Arg_Is_One_Of;
1272
1273 procedure Check_Arg_Is_One_Of
1274 (Arg : Node_Id;
1275 N1, N2, N3, N4, N5 : Name_Id)
1276 is
1277 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1278
1279 begin
1280 Check_Arg_Is_Identifier (Argx);
1281
1282 if Chars (Argx) /= N1
1283 and then Chars (Argx) /= N2
1284 and then Chars (Argx) /= N3
1285 and then Chars (Argx) /= N4
1286 and then Chars (Argx) /= N5
1287 then
1288 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1289 end if;
1290 end Check_Arg_Is_One_Of;
1291
1292 ---------------------------------
1293 -- Check_Arg_Is_Queuing_Policy --
1294 ---------------------------------
1295
1296 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1297 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1298
1299 begin
1300 Check_Arg_Is_Identifier (Argx);
1301
1302 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1303 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1304 end if;
1305 end Check_Arg_Is_Queuing_Policy;
1306
1307 ------------------------------------
1308 -- Check_Arg_Is_Static_Expression --
1309 ------------------------------------
1310
1311 procedure Check_Arg_Is_Static_Expression
1312 (Arg : Node_Id;
1313 Typ : Entity_Id := Empty)
1314 is
1315 begin
1316 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1317 end Check_Arg_Is_Static_Expression;
1318
1319 ------------------------------------------
1320 -- Check_Arg_Is_Task_Dispatching_Policy --
1321 ------------------------------------------
1322
1323 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1324 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1325
1326 begin
1327 Check_Arg_Is_Identifier (Argx);
1328
1329 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1330 Error_Pragma_Arg
1331 ("& is not a valid task dispatching policy name", Argx);
1332 end if;
1333 end Check_Arg_Is_Task_Dispatching_Policy;
1334
1335 ---------------------
1336 -- Check_Arg_Order --
1337 ---------------------
1338
1339 procedure Check_Arg_Order (Names : Name_List) is
1340 Arg : Node_Id;
1341
1342 Highest_So_Far : Natural := 0;
1343 -- Highest index in Names seen do far
1344
1345 begin
1346 Arg := Arg1;
1347 for J in 1 .. Arg_Count loop
1348 if Chars (Arg) /= No_Name then
1349 for K in Names'Range loop
1350 if Chars (Arg) = Names (K) then
1351 if K < Highest_So_Far then
1352 Error_Msg_Name_1 := Pname;
1353 Error_Msg_N
1354 ("parameters out of order for pragma%", Arg);
1355 Error_Msg_Name_1 := Names (K);
1356 Error_Msg_Name_2 := Names (Highest_So_Far);
1357 Error_Msg_N ("\% must appear before %", Arg);
1358 raise Pragma_Exit;
1359
1360 else
1361 Highest_So_Far := K;
1362 end if;
1363 end if;
1364 end loop;
1365 end if;
1366
1367 Arg := Next (Arg);
1368 end loop;
1369 end Check_Arg_Order;
1370
1371 --------------------------------
1372 -- Check_At_Least_N_Arguments --
1373 --------------------------------
1374
1375 procedure Check_At_Least_N_Arguments (N : Nat) is
1376 begin
1377 if Arg_Count < N then
1378 Error_Pragma ("too few arguments for pragma%");
1379 end if;
1380 end Check_At_Least_N_Arguments;
1381
1382 -------------------------------
1383 -- Check_At_Most_N_Arguments --
1384 -------------------------------
1385
1386 procedure Check_At_Most_N_Arguments (N : Nat) is
1387 Arg : Node_Id;
1388 begin
1389 if Arg_Count > N then
1390 Arg := Arg1;
1391 for J in 1 .. N loop
1392 Next (Arg);
1393 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1394 end loop;
1395 end if;
1396 end Check_At_Most_N_Arguments;
1397
1398 ---------------------
1399 -- Check_Component --
1400 ---------------------
1401
1402 procedure Check_Component
1403 (Comp : Node_Id;
1404 UU_Typ : Entity_Id;
1405 In_Variant_Part : Boolean := False)
1406 is
1407 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1408 Sindic : constant Node_Id :=
1409 Subtype_Indication (Component_Definition (Comp));
1410 Typ : constant Entity_Id := Etype (Comp_Id);
1411
1412 begin
1413 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1414 -- object constraint, then the component type shall be an Unchecked_
1415 -- Union.
1416
1417 if Nkind (Sindic) = N_Subtype_Indication
1418 and then Has_Per_Object_Constraint (Comp_Id)
1419 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1420 then
1421 Error_Msg_N
1422 ("component subtype subject to per-object constraint " &
1423 "must be an Unchecked_Union", Comp);
1424
1425 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1426 -- the body of a generic unit, or within the body of any of its
1427 -- descendant library units, no part of the type of a component
1428 -- declared in a variant_part of the unchecked union type shall be of
1429 -- a formal private type or formal private extension declared within
1430 -- the formal part of the generic unit.
1431
1432 elsif Ada_Version >= Ada_2012
1433 and then In_Generic_Body (UU_Typ)
1434 and then In_Variant_Part
1435 and then Is_Private_Type (Typ)
1436 and then Is_Generic_Type (Typ)
1437 then
1438 Error_Msg_N
1439 ("component of unchecked union cannot be of generic type", Comp);
1440
1441 elsif Needs_Finalization (Typ) then
1442 Error_Msg_N
1443 ("component of unchecked union cannot be controlled", Comp);
1444
1445 elsif Has_Task (Typ) then
1446 Error_Msg_N
1447 ("component of unchecked union cannot have tasks", Comp);
1448 end if;
1449 end Check_Component;
1450
1451 ---------------------------------
1452 -- Check_Contract_Or_Test_Case --
1453 ---------------------------------
1454
1455 procedure Check_Contract_Or_Test_Case is
1456 P : Node_Id;
1457 PO : Node_Id;
1458
1459 procedure Chain_CTC (PO : Node_Id);
1460 -- If PO is a [generic] subprogram declaration node, then the
1461 -- contract-case or test-case applies to this subprogram and the
1462 -- processing for the pragma is completed. Otherwise the pragma
1463 -- is misplaced.
1464
1465 ---------------
1466 -- Chain_CTC --
1467 ---------------
1468
1469 procedure Chain_CTC (PO : Node_Id) is
1470 S : Entity_Id;
1471
1472 begin
1473 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1474 Error_Pragma
1475 ("pragma% cannot be applied to abstract subprogram");
1476
1477 elsif Nkind (PO) = N_Entry_Declaration then
1478 Error_Pragma ("pragma% cannot be applied to entry");
1479
1480 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1481 N_Generic_Subprogram_Declaration)
1482 then
1483 Pragma_Misplaced;
1484 end if;
1485
1486 -- Here if we have [generic] subprogram declaration
1487
1488 S := Defining_Unit_Name (Specification (PO));
1489
1490 -- Note: we do not analyze the pragma at this point. Instead we
1491 -- delay this analysis until the end of the declarative part in
1492 -- which the pragma appears. This implements the required delay
1493 -- in this analysis, allowing forward references. The analysis
1494 -- happens at the end of Analyze_Declarations.
1495
1496 -- There should not be another contract-case or test-case with the
1497 -- same name associated to this subprogram.
1498
1499 declare
1500 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
1501 CTC : Node_Id;
1502
1503 begin
1504 CTC := Spec_CTC_List (Contract (S));
1505 while Present (CTC) loop
1506
1507 -- Omit pragma Contract_Cases because it does not introduce
1508 -- a unique case name and it does not follow the syntax of
1509 -- Contract_Case and Test_Case.
1510
1511 if Pragma_Name (CTC) = Name_Contract_Cases then
1512 null;
1513
1514 elsif String_Equal
1515 (Name, Get_Name_From_CTC_Pragma (CTC))
1516 then
1517 Error_Msg_Sloc := Sloc (CTC);
1518 Error_Pragma ("name for pragma% is already used#");
1519 end if;
1520
1521 CTC := Next_Pragma (CTC);
1522 end loop;
1523 end;
1524
1525 -- Chain spec CTC pragma to list for subprogram
1526
1527 Set_Next_Pragma (N, Spec_CTC_List (Contract (S)));
1528 Set_Spec_CTC_List (Contract (S), N);
1529 end Chain_CTC;
1530
1531 -- Start of processing for Check_Contract_Or_Test_Case
1532
1533 begin
1534 -- First check pragma arguments
1535
1536 GNAT_Pragma;
1537 Check_At_Least_N_Arguments (2);
1538 Check_At_Most_N_Arguments (4);
1539 Check_Arg_Order
1540 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
1541
1542 Check_Optional_Identifier (Arg1, Name_Name);
1543 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
1544
1545 -- In ASIS mode, for a pragma generated from a source aspect, also
1546 -- analyze the original aspect expression.
1547
1548 if ASIS_Mode
1549 and then Present (Corresponding_Aspect (N))
1550 then
1551 Check_Expr_Is_Static_Expression
1552 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
1553 end if;
1554
1555 Check_Optional_Identifier (Arg2, Name_Mode);
1556 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
1557
1558 if Arg_Count = 4 then
1559 Check_Identifier (Arg3, Name_Requires);
1560 Check_Identifier (Arg4, Name_Ensures);
1561
1562 elsif Arg_Count = 3 then
1563 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
1564 end if;
1565
1566 -- Check pragma placement
1567
1568 if not Is_List_Member (N) then
1569 Pragma_Misplaced;
1570 end if;
1571
1572 -- Contract-case or test-case should only appear in package spec unit
1573
1574 if Get_Source_Unit (N) = No_Unit
1575 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
1576 N_Package_Declaration,
1577 N_Generic_Package_Declaration)
1578 then
1579 Pragma_Misplaced;
1580 end if;
1581
1582 -- Search prior declarations
1583
1584 P := N;
1585 while Present (Prev (P)) loop
1586 P := Prev (P);
1587
1588 -- If the previous node is a generic subprogram, do not go to to
1589 -- the original node, which is the unanalyzed tree: we need to
1590 -- attach the contract-case or test-case to the analyzed version
1591 -- at this point. They get propagated to the original tree when
1592 -- analyzing the corresponding body.
1593
1594 if Nkind (P) not in N_Generic_Declaration then
1595 PO := Original_Node (P);
1596 else
1597 PO := P;
1598 end if;
1599
1600 -- Skip past prior pragma
1601
1602 if Nkind (PO) = N_Pragma then
1603 null;
1604
1605 -- Skip stuff not coming from source
1606
1607 elsif not Comes_From_Source (PO) then
1608 null;
1609
1610 -- Only remaining possibility is subprogram declaration. First
1611 -- check that it is declared directly in a package declaration.
1612 -- This may be either the package declaration for the current unit
1613 -- being defined or a local package declaration.
1614
1615 elsif not Present (Parent (Parent (PO)))
1616 or else not Present (Parent (Parent (Parent (PO))))
1617 or else not Nkind_In (Parent (Parent (PO)),
1618 N_Package_Declaration,
1619 N_Generic_Package_Declaration)
1620 then
1621 Pragma_Misplaced;
1622
1623 else
1624 Chain_CTC (PO);
1625 return;
1626 end if;
1627 end loop;
1628
1629 -- If we fall through, pragma was misplaced
1630
1631 Pragma_Misplaced;
1632 end Check_Contract_Or_Test_Case;
1633
1634 ----------------------------
1635 -- Check_Duplicate_Pragma --
1636 ----------------------------
1637
1638 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1639 Id : Entity_Id := E;
1640 P : Node_Id;
1641
1642 begin
1643 -- Nothing to do if this pragma comes from an aspect specification,
1644 -- since we could not be duplicating a pragma, and we dealt with the
1645 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1646
1647 if From_Aspect_Specification (N) then
1648 return;
1649 end if;
1650
1651 -- Otherwise current pragma may duplicate previous pragma or a
1652 -- previously given aspect specification or attribute definition
1653 -- clause for the same pragma.
1654
1655 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
1656
1657 if Present (P) then
1658 Error_Msg_Name_1 := Pragma_Name (N);
1659 Error_Msg_Sloc := Sloc (P);
1660
1661 -- For a single protected or a single task object, the error is
1662 -- issued on the original entity.
1663
1664 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
1665 Id := Defining_Identifier (Original_Node (Parent (Id)));
1666 end if;
1667
1668 if Nkind (P) = N_Aspect_Specification
1669 or else From_Aspect_Specification (P)
1670 then
1671 Error_Msg_NE ("aspect% for & previously given#", N, Id);
1672 else
1673 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
1674 end if;
1675
1676 raise Pragma_Exit;
1677 end if;
1678 end Check_Duplicate_Pragma;
1679
1680 ----------------------------------
1681 -- Check_Duplicated_Export_Name --
1682 ----------------------------------
1683
1684 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1685 String_Val : constant String_Id := Strval (Nam);
1686
1687 begin
1688 -- We are only interested in the export case, and in the case of
1689 -- generics, it is the instance, not the template, that is the
1690 -- problem (the template will generate a warning in any case).
1691
1692 if not Inside_A_Generic
1693 and then (Prag_Id = Pragma_Export
1694 or else
1695 Prag_Id = Pragma_Export_Procedure
1696 or else
1697 Prag_Id = Pragma_Export_Valued_Procedure
1698 or else
1699 Prag_Id = Pragma_Export_Function)
1700 then
1701 for J in Externals.First .. Externals.Last loop
1702 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1703 Error_Msg_Sloc := Sloc (Externals.Table (J));
1704 Error_Msg_N ("external name duplicates name given#", Nam);
1705 exit;
1706 end if;
1707 end loop;
1708
1709 Externals.Append (Nam);
1710 end if;
1711 end Check_Duplicated_Export_Name;
1712
1713 -------------------------------------
1714 -- Check_Expr_Is_Static_Expression --
1715 -------------------------------------
1716
1717 procedure Check_Expr_Is_Static_Expression
1718 (Expr : Node_Id;
1719 Typ : Entity_Id := Empty)
1720 is
1721 begin
1722 if Present (Typ) then
1723 Analyze_And_Resolve (Expr, Typ);
1724 else
1725 Analyze_And_Resolve (Expr);
1726 end if;
1727
1728 if Is_OK_Static_Expression (Expr) then
1729 return;
1730
1731 elsif Etype (Expr) = Any_Type then
1732 raise Pragma_Exit;
1733
1734 -- An interesting special case, if we have a string literal and we
1735 -- are in Ada 83 mode, then we allow it even though it will not be
1736 -- flagged as static. This allows the use of Ada 95 pragmas like
1737 -- Import in Ada 83 mode. They will of course be flagged with
1738 -- warnings as usual, but will not cause errors.
1739
1740 elsif Ada_Version = Ada_83
1741 and then Nkind (Expr) = N_String_Literal
1742 then
1743 return;
1744
1745 -- Static expression that raises Constraint_Error. This has already
1746 -- been flagged, so just exit from pragma processing.
1747
1748 elsif Is_Static_Expression (Expr) then
1749 raise Pragma_Exit;
1750
1751 -- Finally, we have a real error
1752
1753 else
1754 Error_Msg_Name_1 := Pname;
1755
1756 declare
1757 Msg : String :=
1758 "argument for pragma% must be a static expression!";
1759 begin
1760 Fix_Error (Msg);
1761 Flag_Non_Static_Expr (Msg, Expr);
1762 end;
1763
1764 raise Pragma_Exit;
1765 end if;
1766 end Check_Expr_Is_Static_Expression;
1767
1768 -------------------------
1769 -- Check_First_Subtype --
1770 -------------------------
1771
1772 procedure Check_First_Subtype (Arg : Node_Id) is
1773 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1774 Ent : constant Entity_Id := Entity (Argx);
1775
1776 begin
1777 if Is_First_Subtype (Ent) then
1778 null;
1779
1780 elsif Is_Type (Ent) then
1781 Error_Pragma_Arg
1782 ("pragma% cannot apply to subtype", Argx);
1783
1784 elsif Is_Object (Ent) then
1785 Error_Pragma_Arg
1786 ("pragma% cannot apply to object, requires a type", Argx);
1787
1788 else
1789 Error_Pragma_Arg
1790 ("pragma% cannot apply to&, requires a type", Argx);
1791 end if;
1792 end Check_First_Subtype;
1793
1794 ----------------------
1795 -- Check_Identifier --
1796 ----------------------
1797
1798 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1799 begin
1800 if Present (Arg)
1801 and then Nkind (Arg) = N_Pragma_Argument_Association
1802 then
1803 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1804 Error_Msg_Name_1 := Pname;
1805 Error_Msg_Name_2 := Id;
1806 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1807 raise Pragma_Exit;
1808 end if;
1809 end if;
1810 end Check_Identifier;
1811
1812 --------------------------------
1813 -- Check_Identifier_Is_One_Of --
1814 --------------------------------
1815
1816 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1817 begin
1818 if Present (Arg)
1819 and then Nkind (Arg) = N_Pragma_Argument_Association
1820 then
1821 if Chars (Arg) = No_Name then
1822 Error_Msg_Name_1 := Pname;
1823 Error_Msg_N ("pragma% argument expects an identifier", Arg);
1824 raise Pragma_Exit;
1825
1826 elsif Chars (Arg) /= N1
1827 and then Chars (Arg) /= N2
1828 then
1829 Error_Msg_Name_1 := Pname;
1830 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1831 raise Pragma_Exit;
1832 end if;
1833 end if;
1834 end Check_Identifier_Is_One_Of;
1835
1836 ---------------------------
1837 -- Check_In_Main_Program --
1838 ---------------------------
1839
1840 procedure Check_In_Main_Program is
1841 P : constant Node_Id := Parent (N);
1842
1843 begin
1844 -- Must be at in subprogram body
1845
1846 if Nkind (P) /= N_Subprogram_Body then
1847 Error_Pragma ("% pragma allowed only in subprogram");
1848
1849 -- Otherwise warn if obviously not main program
1850
1851 elsif Present (Parameter_Specifications (Specification (P)))
1852 or else not Is_Compilation_Unit (Defining_Entity (P))
1853 then
1854 Error_Msg_Name_1 := Pname;
1855 Error_Msg_N
1856 ("?pragma% is only effective in main program", N);
1857 end if;
1858 end Check_In_Main_Program;
1859
1860 ---------------------------------------
1861 -- Check_Interrupt_Or_Attach_Handler --
1862 ---------------------------------------
1863
1864 procedure Check_Interrupt_Or_Attach_Handler is
1865 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1866 Handler_Proc, Proc_Scope : Entity_Id;
1867
1868 begin
1869 Analyze (Arg1_X);
1870
1871 if Prag_Id = Pragma_Interrupt_Handler then
1872 Check_Restriction (No_Dynamic_Attachment, N);
1873 end if;
1874
1875 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1876 Proc_Scope := Scope (Handler_Proc);
1877
1878 -- On AAMP only, a pragma Interrupt_Handler is supported for
1879 -- nonprotected parameterless procedures.
1880
1881 if not AAMP_On_Target
1882 or else Prag_Id = Pragma_Attach_Handler
1883 then
1884 if Ekind (Proc_Scope) /= E_Protected_Type then
1885 Error_Pragma_Arg
1886 ("argument of pragma% must be protected procedure", Arg1);
1887 end if;
1888
1889 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1890 Error_Pragma ("pragma% must be in protected definition");
1891 end if;
1892 end if;
1893
1894 if not Is_Library_Level_Entity (Proc_Scope)
1895 or else (AAMP_On_Target
1896 and then not Is_Library_Level_Entity (Handler_Proc))
1897 then
1898 Error_Pragma_Arg
1899 ("argument for pragma% must be library level entity", Arg1);
1900 end if;
1901
1902 -- AI05-0033: A pragma cannot appear within a generic body, because
1903 -- instance can be in a nested scope. The check that protected type
1904 -- is itself a library-level declaration is done elsewhere.
1905
1906 -- Note: we omit this check in Codepeer mode to properly handle code
1907 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1908
1909 if Inside_A_Generic then
1910 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1911 and then In_Package_Body (Scope (Current_Scope))
1912 and then not CodePeer_Mode
1913 then
1914 Error_Pragma ("pragma% cannot be used inside a generic");
1915 end if;
1916 end if;
1917 end Check_Interrupt_Or_Attach_Handler;
1918
1919 --------------------------------------------
1920 -- Check_Loop_Invariant_Variant_Placement --
1921 --------------------------------------------
1922
1923 procedure Check_Loop_Invariant_Variant_Placement is
1924 procedure Placement_Error (Constr : Node_Id);
1925 -- Node Constr denotes the last loop restricted construct before we
1926 -- encountered an illegal relation between enclosing constructs. Emit
1927 -- an error depending on what Constr was.
1928
1929 ---------------------
1930 -- Placement_Error --
1931 ---------------------
1932
1933 procedure Placement_Error (Constr : Node_Id) is
1934 begin
1935 if Nkind (Constr) = N_Pragma then
1936 Error_Pragma
1937 ("pragma % must appear immediately within the statements " &
1938 "of a loop");
1939 else
1940 Error_Pragma_Arg
1941 ("block containing pragma % must appear immediately within " &
1942 "the statements of a loop", Constr);
1943 end if;
1944 end Placement_Error;
1945
1946 -- Local declarations
1947
1948 Prev : Node_Id;
1949 Stmt : Node_Id;
1950
1951 -- Start of processing for Check_Loop_Invariant_Variant_Placement
1952
1953 begin
1954 Prev := N;
1955 Stmt := Parent (N);
1956 while Present (Stmt) loop
1957
1958 -- The pragma or previous block must appear immediately within the
1959 -- current block's declarative or statement part.
1960
1961 if Nkind (Stmt) = N_Block_Statement then
1962 if (No (Declarations (Stmt))
1963 or else List_Containing (Prev) /= Declarations (Stmt))
1964 and then
1965 List_Containing (Prev) /=
1966 Statements (Handled_Statement_Sequence (Stmt))
1967 then
1968 Placement_Error (Prev);
1969 return;
1970
1971 -- Keep inspecting the parents because we are now within a
1972 -- chain of nested blocks.
1973
1974 else
1975 Prev := Stmt;
1976 Stmt := Parent (Stmt);
1977 end if;
1978
1979 -- The pragma or previous block must appear immediately within the
1980 -- statements of the loop.
1981
1982 elsif Nkind (Stmt) = N_Loop_Statement then
1983 if List_Containing (Prev) /= Statements (Stmt) then
1984 Placement_Error (Prev);
1985 end if;
1986
1987 -- Stop the traversal because we reached the innermost loop
1988 -- regardless of whether we encountered an error or not.
1989
1990 return;
1991
1992 -- Ignore a handled statement sequence. Note that this node may
1993 -- be related to a subprogram body in which case we will emit an
1994 -- error on the next iteration of the search.
1995
1996 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
1997 Stmt := Parent (Stmt);
1998
1999 -- Any other statement breaks the chain from the pragma to the
2000 -- loop.
2001
2002 else
2003 Placement_Error (Prev);
2004 return;
2005 end if;
2006 end loop;
2007 end Check_Loop_Invariant_Variant_Placement;
2008
2009 -------------------------------------------
2010 -- Check_Is_In_Decl_Part_Or_Package_Spec --
2011 -------------------------------------------
2012
2013 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
2014 P : Node_Id;
2015
2016 begin
2017 P := Parent (N);
2018 loop
2019 if No (P) then
2020 exit;
2021
2022 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
2023 exit;
2024
2025 elsif Nkind_In (P, N_Package_Specification,
2026 N_Block_Statement)
2027 then
2028 return;
2029
2030 -- Note: the following tests seem a little peculiar, because
2031 -- they test for bodies, but if we were in the statement part
2032 -- of the body, we would already have hit the handled statement
2033 -- sequence, so the only way we get here is by being in the
2034 -- declarative part of the body.
2035
2036 elsif Nkind_In (P, N_Subprogram_Body,
2037 N_Package_Body,
2038 N_Task_Body,
2039 N_Entry_Body)
2040 then
2041 return;
2042 end if;
2043
2044 P := Parent (P);
2045 end loop;
2046
2047 Error_Pragma ("pragma% is not in declarative part or package spec");
2048 end Check_Is_In_Decl_Part_Or_Package_Spec;
2049
2050 -------------------------
2051 -- Check_No_Identifier --
2052 -------------------------
2053
2054 procedure Check_No_Identifier (Arg : Node_Id) is
2055 begin
2056 if Nkind (Arg) = N_Pragma_Argument_Association
2057 and then Chars (Arg) /= No_Name
2058 then
2059 Error_Pragma_Arg_Ident
2060 ("pragma% does not permit identifier& here", Arg);
2061 end if;
2062 end Check_No_Identifier;
2063
2064 --------------------------
2065 -- Check_No_Identifiers --
2066 --------------------------
2067
2068 procedure Check_No_Identifiers is
2069 Arg_Node : Node_Id;
2070 begin
2071 if Arg_Count > 0 then
2072 Arg_Node := Arg1;
2073 while Present (Arg_Node) loop
2074 Check_No_Identifier (Arg_Node);
2075 Next (Arg_Node);
2076 end loop;
2077 end if;
2078 end Check_No_Identifiers;
2079
2080 ------------------------
2081 -- Check_No_Link_Name --
2082 ------------------------
2083
2084 procedure Check_No_Link_Name is
2085 begin
2086 if Present (Arg3)
2087 and then Chars (Arg3) = Name_Link_Name
2088 then
2089 Arg4 := Arg3;
2090 end if;
2091
2092 if Present (Arg4) then
2093 Error_Pragma_Arg
2094 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
2095 end if;
2096 end Check_No_Link_Name;
2097
2098 -------------------------------
2099 -- Check_Optional_Identifier --
2100 -------------------------------
2101
2102 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
2103 begin
2104 if Present (Arg)
2105 and then Nkind (Arg) = N_Pragma_Argument_Association
2106 and then Chars (Arg) /= No_Name
2107 then
2108 if Chars (Arg) /= Id then
2109 Error_Msg_Name_1 := Pname;
2110 Error_Msg_Name_2 := Id;
2111 Error_Msg_N ("pragma% argument expects identifier%", Arg);
2112 raise Pragma_Exit;
2113 end if;
2114 end if;
2115 end Check_Optional_Identifier;
2116
2117 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
2118 begin
2119 Name_Buffer (1 .. Id'Length) := Id;
2120 Name_Len := Id'Length;
2121 Check_Optional_Identifier (Arg, Name_Find);
2122 end Check_Optional_Identifier;
2123
2124 --------------------------------------
2125 -- Check_Precondition_Postcondition --
2126 --------------------------------------
2127
2128 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
2129 P : Node_Id;
2130 PO : Node_Id;
2131
2132 procedure Chain_PPC (PO : Node_Id);
2133 -- If PO is an entry or a [generic] subprogram declaration node, then
2134 -- the precondition/postcondition applies to this subprogram and the
2135 -- processing for the pragma is completed. Otherwise the pragma is
2136 -- misplaced.
2137
2138 ---------------
2139 -- Chain_PPC --
2140 ---------------
2141
2142 procedure Chain_PPC (PO : Node_Id) is
2143 S : Entity_Id;
2144
2145 begin
2146 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2147 if not From_Aspect_Specification (N) then
2148 Error_Pragma
2149 ("pragma% cannot be applied to abstract subprogram");
2150
2151 elsif Class_Present (N) then
2152 null;
2153
2154 else
2155 Error_Pragma
2156 ("aspect % requires ''Class for abstract subprogram");
2157 end if;
2158
2159 -- AI05-0230: The same restriction applies to null procedures. For
2160 -- compatibility with earlier uses of the Ada pragma, apply this
2161 -- rule only to aspect specifications.
2162
2163 -- The above discrpency needs documentation. Robert is dubious
2164 -- about whether it is a good idea ???
2165
2166 elsif Nkind (PO) = N_Subprogram_Declaration
2167 and then Nkind (Specification (PO)) = N_Procedure_Specification
2168 and then Null_Present (Specification (PO))
2169 and then From_Aspect_Specification (N)
2170 and then not Class_Present (N)
2171 then
2172 Error_Pragma
2173 ("aspect % requires ''Class for null procedure");
2174
2175 -- Pre/postconditions are legal on a subprogram body if it is not
2176 -- a completion of a declaration.
2177
2178 elsif Nkind (PO) = N_Subprogram_Body
2179 and then Acts_As_Spec (PO)
2180 then
2181 null;
2182
2183 elsif not Nkind_In (PO, N_Subprogram_Declaration,
2184 N_Expression_Function,
2185 N_Generic_Subprogram_Declaration,
2186 N_Entry_Declaration)
2187 then
2188 Pragma_Misplaced;
2189 end if;
2190
2191 -- Here if we have [generic] subprogram or entry declaration
2192
2193 if Nkind (PO) = N_Entry_Declaration then
2194 S := Defining_Entity (PO);
2195 else
2196 S := Defining_Unit_Name (Specification (PO));
2197
2198 if Nkind (S) = N_Defining_Program_Unit_Name then
2199 S := Defining_Identifier (S);
2200 end if;
2201 end if;
2202
2203 -- Note: we do not analyze the pragma at this point. Instead we
2204 -- delay this analysis until the end of the declarative part in
2205 -- which the pragma appears. This implements the required delay
2206 -- in this analysis, allowing forward references. The analysis
2207 -- happens at the end of Analyze_Declarations.
2208
2209 -- Chain spec PPC pragma to list for subprogram
2210
2211 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
2212 Set_Spec_PPC_List (Contract (S), N);
2213
2214 -- Return indicating spec case
2215
2216 In_Body := False;
2217 return;
2218 end Chain_PPC;
2219
2220 -- Start of processing for Check_Precondition_Postcondition
2221
2222 begin
2223 if not Is_List_Member (N) then
2224 Pragma_Misplaced;
2225 end if;
2226
2227 -- Preanalyze message argument if present. Visibility in this
2228 -- argument is established at the point of pragma occurrence.
2229
2230 if Arg_Count = 2 then
2231 Check_Optional_Identifier (Arg2, Name_Message);
2232 Preanalyze_Spec_Expression
2233 (Get_Pragma_Arg (Arg2), Standard_String);
2234 end if;
2235
2236 -- For a pragma PPC in the extended main source unit, record enabled
2237 -- status in SCO.
2238
2239 -- This may seem redundant with the call to Check_Enabled occurring
2240 -- later on when the pragma is rewritten into a pragma Check but
2241 -- is actually required in the case of a postcondition within a
2242 -- generic.
2243
2244 if Check_Enabled (Pname) and then not Split_PPC (N) then
2245 Set_SCO_Pragma_Enabled (Loc);
2246 end if;
2247
2248 -- If we are within an inlined body, the legality of the pragma
2249 -- has been checked already.
2250
2251 if In_Inlined_Body then
2252 In_Body := True;
2253 return;
2254 end if;
2255
2256 -- Search prior declarations
2257
2258 P := N;
2259 while Present (Prev (P)) loop
2260 P := Prev (P);
2261
2262 -- If the previous node is a generic subprogram, do not go to to
2263 -- the original node, which is the unanalyzed tree: we need to
2264 -- attach the pre/postconditions to the analyzed version at this
2265 -- point. They get propagated to the original tree when analyzing
2266 -- the corresponding body.
2267
2268 if Nkind (P) not in N_Generic_Declaration then
2269 PO := Original_Node (P);
2270 else
2271 PO := P;
2272 end if;
2273
2274 -- Skip past prior pragma
2275
2276 if Nkind (PO) = N_Pragma then
2277 null;
2278
2279 -- Skip stuff not coming from source
2280
2281 elsif not Comes_From_Source (PO) then
2282
2283 -- The condition may apply to a subprogram instantiation
2284
2285 if Nkind (PO) = N_Subprogram_Declaration
2286 and then Present (Generic_Parent (Specification (PO)))
2287 then
2288 Chain_PPC (PO);
2289 return;
2290
2291 elsif Nkind (PO) = N_Subprogram_Declaration
2292 and then In_Instance
2293 then
2294 Chain_PPC (PO);
2295 return;
2296
2297 -- For all other cases of non source code, do nothing
2298
2299 else
2300 null;
2301 end if;
2302
2303 -- Only remaining possibility is subprogram declaration
2304
2305 else
2306 Chain_PPC (PO);
2307 return;
2308 end if;
2309 end loop;
2310
2311 -- If we fall through loop, pragma is at start of list, so see if it
2312 -- is at the start of declarations of a subprogram body.
2313
2314 if Nkind (Parent (N)) = N_Subprogram_Body
2315 and then List_Containing (N) = Declarations (Parent (N))
2316 then
2317 if Operating_Mode /= Generate_Code
2318 or else Inside_A_Generic
2319 then
2320 -- Analyze pragma expression for correctness and for ASIS use
2321
2322 Preanalyze_Assert_Expression
2323 (Get_Pragma_Arg (Arg1), Standard_Boolean);
2324
2325 -- In ASIS mode, for a pragma generated from a source aspect,
2326 -- also analyze the original aspect expression.
2327
2328 if ASIS_Mode
2329 and then Present (Corresponding_Aspect (N))
2330 then
2331 Preanalyze_Assert_Expression
2332 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2333 end if;
2334 end if;
2335
2336 In_Body := True;
2337 return;
2338
2339 -- See if it is in the pragmas after a library level subprogram
2340
2341 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2342
2343 -- In formal verification mode, analyze pragma expression for
2344 -- correctness, as it is not expanded later.
2345
2346 if Alfa_Mode then
2347 Analyze_PPC_In_Decl_Part
2348 (N, Defining_Entity (Unit (Parent (Parent (N)))));
2349 end if;
2350
2351 Chain_PPC (Unit (Parent (Parent (N))));
2352 return;
2353 end if;
2354
2355 -- If we fall through, pragma was misplaced
2356
2357 Pragma_Misplaced;
2358 end Check_Precondition_Postcondition;
2359
2360 -----------------------------
2361 -- Check_Static_Constraint --
2362 -----------------------------
2363
2364 -- Note: for convenience in writing this procedure, in addition to
2365 -- the officially (i.e. by spec) allowed argument which is always a
2366 -- constraint, it also allows ranges and discriminant associations.
2367 -- Above is not clear ???
2368
2369 procedure Check_Static_Constraint (Constr : Node_Id) is
2370
2371 procedure Require_Static (E : Node_Id);
2372 -- Require given expression to be static expression
2373
2374 --------------------
2375 -- Require_Static --
2376 --------------------
2377
2378 procedure Require_Static (E : Node_Id) is
2379 begin
2380 if not Is_OK_Static_Expression (E) then
2381 Flag_Non_Static_Expr
2382 ("non-static constraint not allowed in Unchecked_Union!", E);
2383 raise Pragma_Exit;
2384 end if;
2385 end Require_Static;
2386
2387 -- Start of processing for Check_Static_Constraint
2388
2389 begin
2390 case Nkind (Constr) is
2391 when N_Discriminant_Association =>
2392 Require_Static (Expression (Constr));
2393
2394 when N_Range =>
2395 Require_Static (Low_Bound (Constr));
2396 Require_Static (High_Bound (Constr));
2397
2398 when N_Attribute_Reference =>
2399 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
2400 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2401
2402 when N_Range_Constraint =>
2403 Check_Static_Constraint (Range_Expression (Constr));
2404
2405 when N_Index_Or_Discriminant_Constraint =>
2406 declare
2407 IDC : Entity_Id;
2408 begin
2409 IDC := First (Constraints (Constr));
2410 while Present (IDC) loop
2411 Check_Static_Constraint (IDC);
2412 Next (IDC);
2413 end loop;
2414 end;
2415
2416 when others =>
2417 null;
2418 end case;
2419 end Check_Static_Constraint;
2420
2421 --------------------------------------
2422 -- Check_Valid_Configuration_Pragma --
2423 --------------------------------------
2424
2425 -- A configuration pragma must appear in the context clause of a
2426 -- compilation unit, and only other pragmas may precede it. Note that
2427 -- the test also allows use in a configuration pragma file.
2428
2429 procedure Check_Valid_Configuration_Pragma is
2430 begin
2431 if not Is_Configuration_Pragma then
2432 Error_Pragma ("incorrect placement for configuration pragma%");
2433 end if;
2434 end Check_Valid_Configuration_Pragma;
2435
2436 -------------------------------------
2437 -- Check_Valid_Library_Unit_Pragma --
2438 -------------------------------------
2439
2440 procedure Check_Valid_Library_Unit_Pragma is
2441 Plist : List_Id;
2442 Parent_Node : Node_Id;
2443 Unit_Name : Entity_Id;
2444 Unit_Kind : Node_Kind;
2445 Unit_Node : Node_Id;
2446 Sindex : Source_File_Index;
2447
2448 begin
2449 if not Is_List_Member (N) then
2450 Pragma_Misplaced;
2451
2452 else
2453 Plist := List_Containing (N);
2454 Parent_Node := Parent (Plist);
2455
2456 if Parent_Node = Empty then
2457 Pragma_Misplaced;
2458
2459 -- Case of pragma appearing after a compilation unit. In this case
2460 -- it must have an argument with the corresponding name and must
2461 -- be part of the following pragmas of its parent.
2462
2463 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2464 if Plist /= Pragmas_After (Parent_Node) then
2465 Pragma_Misplaced;
2466
2467 elsif Arg_Count = 0 then
2468 Error_Pragma
2469 ("argument required if outside compilation unit");
2470
2471 else
2472 Check_No_Identifiers;
2473 Check_Arg_Count (1);
2474 Unit_Node := Unit (Parent (Parent_Node));
2475 Unit_Kind := Nkind (Unit_Node);
2476
2477 Analyze (Get_Pragma_Arg (Arg1));
2478
2479 if Unit_Kind = N_Generic_Subprogram_Declaration
2480 or else Unit_Kind = N_Subprogram_Declaration
2481 then
2482 Unit_Name := Defining_Entity (Unit_Node);
2483
2484 elsif Unit_Kind in N_Generic_Instantiation then
2485 Unit_Name := Defining_Entity (Unit_Node);
2486
2487 else
2488 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2489 end if;
2490
2491 if Chars (Unit_Name) /=
2492 Chars (Entity (Get_Pragma_Arg (Arg1)))
2493 then
2494 Error_Pragma_Arg
2495 ("pragma% argument is not current unit name", Arg1);
2496 end if;
2497
2498 if Ekind (Unit_Name) = E_Package
2499 and then Present (Renamed_Entity (Unit_Name))
2500 then
2501 Error_Pragma ("pragma% not allowed for renamed package");
2502 end if;
2503 end if;
2504
2505 -- Pragma appears other than after a compilation unit
2506
2507 else
2508 -- Here we check for the generic instantiation case and also
2509 -- for the case of processing a generic formal package. We
2510 -- detect these cases by noting that the Sloc on the node
2511 -- does not belong to the current compilation unit.
2512
2513 Sindex := Source_Index (Current_Sem_Unit);
2514
2515 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2516 Rewrite (N, Make_Null_Statement (Loc));
2517 return;
2518
2519 -- If before first declaration, the pragma applies to the
2520 -- enclosing unit, and the name if present must be this name.
2521
2522 elsif Is_Before_First_Decl (N, Plist) then
2523 Unit_Node := Unit_Declaration_Node (Current_Scope);
2524 Unit_Kind := Nkind (Unit_Node);
2525
2526 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2527 Pragma_Misplaced;
2528
2529 elsif Unit_Kind = N_Subprogram_Body
2530 and then not Acts_As_Spec (Unit_Node)
2531 then
2532 Pragma_Misplaced;
2533
2534 elsif Nkind (Parent_Node) = N_Package_Body then
2535 Pragma_Misplaced;
2536
2537 elsif Nkind (Parent_Node) = N_Package_Specification
2538 and then Plist = Private_Declarations (Parent_Node)
2539 then
2540 Pragma_Misplaced;
2541
2542 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2543 or else Nkind (Parent_Node) =
2544 N_Generic_Subprogram_Declaration)
2545 and then Plist = Generic_Formal_Declarations (Parent_Node)
2546 then
2547 Pragma_Misplaced;
2548
2549 elsif Arg_Count > 0 then
2550 Analyze (Get_Pragma_Arg (Arg1));
2551
2552 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2553 Error_Pragma_Arg
2554 ("name in pragma% must be enclosing unit", Arg1);
2555 end if;
2556
2557 -- It is legal to have no argument in this context
2558
2559 else
2560 return;
2561 end if;
2562
2563 -- Error if not before first declaration. This is because a
2564 -- library unit pragma argument must be the name of a library
2565 -- unit (RM 10.1.5(7)), but the only names permitted in this
2566 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2567 -- generic subprogram declarations or generic instantiations.
2568
2569 else
2570 Error_Pragma
2571 ("pragma% misplaced, must be before first declaration");
2572 end if;
2573 end if;
2574 end if;
2575 end Check_Valid_Library_Unit_Pragma;
2576
2577 -------------------
2578 -- Check_Variant --
2579 -------------------
2580
2581 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2582 Clist : constant Node_Id := Component_List (Variant);
2583 Comp : Node_Id;
2584
2585 begin
2586 Comp := First (Component_Items (Clist));
2587 while Present (Comp) loop
2588 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2589 Next (Comp);
2590 end loop;
2591 end Check_Variant;
2592
2593 ------------------
2594 -- Error_Pragma --
2595 ------------------
2596
2597 procedure Error_Pragma (Msg : String) is
2598 MsgF : String := Msg;
2599 begin
2600 Error_Msg_Name_1 := Pname;
2601 Fix_Error (MsgF);
2602 Error_Msg_N (MsgF, N);
2603 raise Pragma_Exit;
2604 end Error_Pragma;
2605
2606 ----------------------
2607 -- Error_Pragma_Arg --
2608 ----------------------
2609
2610 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2611 MsgF : String := Msg;
2612 begin
2613 Error_Msg_Name_1 := Pname;
2614 Fix_Error (MsgF);
2615 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2616 raise Pragma_Exit;
2617 end Error_Pragma_Arg;
2618
2619 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2620 MsgF : String := Msg1;
2621 begin
2622 Error_Msg_Name_1 := Pname;
2623 Fix_Error (MsgF);
2624 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2625 Error_Pragma_Arg (Msg2, Arg);
2626 end Error_Pragma_Arg;
2627
2628 ----------------------------
2629 -- Error_Pragma_Arg_Ident --
2630 ----------------------------
2631
2632 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2633 MsgF : String := Msg;
2634 begin
2635 Error_Msg_Name_1 := Pname;
2636 Fix_Error (MsgF);
2637 Error_Msg_N (MsgF, Arg);
2638 raise Pragma_Exit;
2639 end Error_Pragma_Arg_Ident;
2640
2641 ----------------------
2642 -- Error_Pragma_Ref --
2643 ----------------------
2644
2645 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2646 MsgF : String := Msg;
2647 begin
2648 Error_Msg_Name_1 := Pname;
2649 Fix_Error (MsgF);
2650 Error_Msg_Sloc := Sloc (Ref);
2651 Error_Msg_NE (MsgF, N, Ref);
2652 raise Pragma_Exit;
2653 end Error_Pragma_Ref;
2654
2655 ------------------------
2656 -- Find_Lib_Unit_Name --
2657 ------------------------
2658
2659 function Find_Lib_Unit_Name return Entity_Id is
2660 begin
2661 -- Return inner compilation unit entity, for case of nested
2662 -- categorization pragmas. This happens in generic unit.
2663
2664 if Nkind (Parent (N)) = N_Package_Specification
2665 and then Defining_Entity (Parent (N)) /= Current_Scope
2666 then
2667 return Defining_Entity (Parent (N));
2668 else
2669 return Current_Scope;
2670 end if;
2671 end Find_Lib_Unit_Name;
2672
2673 ----------------------------
2674 -- Find_Program_Unit_Name --
2675 ----------------------------
2676
2677 procedure Find_Program_Unit_Name (Id : Node_Id) is
2678 Unit_Name : Entity_Id;
2679 Unit_Kind : Node_Kind;
2680 P : constant Node_Id := Parent (N);
2681
2682 begin
2683 if Nkind (P) = N_Compilation_Unit then
2684 Unit_Kind := Nkind (Unit (P));
2685
2686 if Unit_Kind = N_Subprogram_Declaration
2687 or else Unit_Kind = N_Package_Declaration
2688 or else Unit_Kind in N_Generic_Declaration
2689 then
2690 Unit_Name := Defining_Entity (Unit (P));
2691
2692 if Chars (Id) = Chars (Unit_Name) then
2693 Set_Entity (Id, Unit_Name);
2694 Set_Etype (Id, Etype (Unit_Name));
2695 else
2696 Set_Etype (Id, Any_Type);
2697 Error_Pragma
2698 ("cannot find program unit referenced by pragma%");
2699 end if;
2700
2701 else
2702 Set_Etype (Id, Any_Type);
2703 Error_Pragma ("pragma% inapplicable to this unit");
2704 end if;
2705
2706 else
2707 Analyze (Id);
2708 end if;
2709 end Find_Program_Unit_Name;
2710
2711 -----------------------------------------
2712 -- Find_Unique_Parameterless_Procedure --
2713 -----------------------------------------
2714
2715 function Find_Unique_Parameterless_Procedure
2716 (Name : Entity_Id;
2717 Arg : Node_Id) return Entity_Id
2718 is
2719 Proc : Entity_Id := Empty;
2720
2721 begin
2722 -- The body of this procedure needs some comments ???
2723
2724 if not Is_Entity_Name (Name) then
2725 Error_Pragma_Arg
2726 ("argument of pragma% must be entity name", Arg);
2727
2728 elsif not Is_Overloaded (Name) then
2729 Proc := Entity (Name);
2730
2731 if Ekind (Proc) /= E_Procedure
2732 or else Present (First_Formal (Proc))
2733 then
2734 Error_Pragma_Arg
2735 ("argument of pragma% must be parameterless procedure", Arg);
2736 end if;
2737
2738 else
2739 declare
2740 Found : Boolean := False;
2741 It : Interp;
2742 Index : Interp_Index;
2743
2744 begin
2745 Get_First_Interp (Name, Index, It);
2746 while Present (It.Nam) loop
2747 Proc := It.Nam;
2748
2749 if Ekind (Proc) = E_Procedure
2750 and then No (First_Formal (Proc))
2751 then
2752 if not Found then
2753 Found := True;
2754 Set_Entity (Name, Proc);
2755 Set_Is_Overloaded (Name, False);
2756 else
2757 Error_Pragma_Arg
2758 ("ambiguous handler name for pragma% ", Arg);
2759 end if;
2760 end if;
2761
2762 Get_Next_Interp (Index, It);
2763 end loop;
2764
2765 if not Found then
2766 Error_Pragma_Arg
2767 ("argument of pragma% must be parameterless procedure",
2768 Arg);
2769 else
2770 Proc := Entity (Name);
2771 end if;
2772 end;
2773 end if;
2774
2775 return Proc;
2776 end Find_Unique_Parameterless_Procedure;
2777
2778 ---------------
2779 -- Fix_Error --
2780 ---------------
2781
2782 procedure Fix_Error (Msg : in out String) is
2783 begin
2784 if From_Aspect_Specification (N) then
2785 for J in Msg'First .. Msg'Last - 5 loop
2786 if Msg (J .. J + 5) = "pragma" then
2787 Msg (J .. J + 5) := "aspect";
2788 end if;
2789 end loop;
2790
2791 if Error_Msg_Name_1 = Name_Precondition then
2792 Error_Msg_Name_1 := Name_Pre;
2793 elsif Error_Msg_Name_1 = Name_Postcondition then
2794 Error_Msg_Name_1 := Name_Post;
2795 end if;
2796 end if;
2797 end Fix_Error;
2798
2799 -------------------------
2800 -- Gather_Associations --
2801 -------------------------
2802
2803 procedure Gather_Associations
2804 (Names : Name_List;
2805 Args : out Args_List)
2806 is
2807 Arg : Node_Id;
2808
2809 begin
2810 -- Initialize all parameters to Empty
2811
2812 for J in Args'Range loop
2813 Args (J) := Empty;
2814 end loop;
2815
2816 -- That's all we have to do if there are no argument associations
2817
2818 if No (Pragma_Argument_Associations (N)) then
2819 return;
2820 end if;
2821
2822 -- Otherwise first deal with any positional parameters present
2823
2824 Arg := First (Pragma_Argument_Associations (N));
2825 for Index in Args'Range loop
2826 exit when No (Arg) or else Chars (Arg) /= No_Name;
2827 Args (Index) := Get_Pragma_Arg (Arg);
2828 Next (Arg);
2829 end loop;
2830
2831 -- Positional parameters all processed, if any left, then we
2832 -- have too many positional parameters.
2833
2834 if Present (Arg) and then Chars (Arg) = No_Name then
2835 Error_Pragma_Arg
2836 ("too many positional associations for pragma%", Arg);
2837 end if;
2838
2839 -- Process named parameters if any are present
2840
2841 while Present (Arg) loop
2842 if Chars (Arg) = No_Name then
2843 Error_Pragma_Arg
2844 ("positional association cannot follow named association",
2845 Arg);
2846
2847 else
2848 for Index in Names'Range loop
2849 if Names (Index) = Chars (Arg) then
2850 if Present (Args (Index)) then
2851 Error_Pragma_Arg
2852 ("duplicate argument association for pragma%", Arg);
2853 else
2854 Args (Index) := Get_Pragma_Arg (Arg);
2855 exit;
2856 end if;
2857 end if;
2858
2859 if Index = Names'Last then
2860 Error_Msg_Name_1 := Pname;
2861 Error_Msg_N ("pragma% does not allow & argument", Arg);
2862
2863 -- Check for possible misspelling
2864
2865 for Index1 in Names'Range loop
2866 if Is_Bad_Spelling_Of
2867 (Chars (Arg), Names (Index1))
2868 then
2869 Error_Msg_Name_1 := Names (Index1);
2870 Error_Msg_N -- CODEFIX
2871 ("\possible misspelling of%", Arg);
2872 exit;
2873 end if;
2874 end loop;
2875
2876 raise Pragma_Exit;
2877 end if;
2878 end loop;
2879 end if;
2880
2881 Next (Arg);
2882 end loop;
2883 end Gather_Associations;
2884
2885 -----------------
2886 -- GNAT_Pragma --
2887 -----------------
2888
2889 procedure GNAT_Pragma is
2890 begin
2891 -- We need to check the No_Implementation_Pragmas restriction for
2892 -- the case of a pragma from source. Note that the case of aspects
2893 -- generating corresponding pragmas marks these pragmas as not being
2894 -- from source, so this test also catches that case.
2895
2896 if Comes_From_Source (N) then
2897 Check_Restriction (No_Implementation_Pragmas, N);
2898 end if;
2899 end GNAT_Pragma;
2900
2901 --------------------------
2902 -- Is_Before_First_Decl --
2903 --------------------------
2904
2905 function Is_Before_First_Decl
2906 (Pragma_Node : Node_Id;
2907 Decls : List_Id) return Boolean
2908 is
2909 Item : Node_Id := First (Decls);
2910
2911 begin
2912 -- Only other pragmas can come before this pragma
2913
2914 loop
2915 if No (Item) or else Nkind (Item) /= N_Pragma then
2916 return False;
2917
2918 elsif Item = Pragma_Node then
2919 return True;
2920 end if;
2921
2922 Next (Item);
2923 end loop;
2924 end Is_Before_First_Decl;
2925
2926 -----------------------------
2927 -- Is_Configuration_Pragma --
2928 -----------------------------
2929
2930 -- A configuration pragma must appear in the context clause of a
2931 -- compilation unit, and only other pragmas may precede it. Note that
2932 -- the test below also permits use in a configuration pragma file.
2933
2934 function Is_Configuration_Pragma return Boolean is
2935 Lis : constant List_Id := List_Containing (N);
2936 Par : constant Node_Id := Parent (N);
2937 Prg : Node_Id;
2938
2939 begin
2940 -- If no parent, then we are in the configuration pragma file,
2941 -- so the placement is definitely appropriate.
2942
2943 if No (Par) then
2944 return True;
2945
2946 -- Otherwise we must be in the context clause of a compilation unit
2947 -- and the only thing allowed before us in the context list is more
2948 -- configuration pragmas.
2949
2950 elsif Nkind (Par) = N_Compilation_Unit
2951 and then Context_Items (Par) = Lis
2952 then
2953 Prg := First (Lis);
2954
2955 loop
2956 if Prg = N then
2957 return True;
2958 elsif Nkind (Prg) /= N_Pragma then
2959 return False;
2960 end if;
2961
2962 Next (Prg);
2963 end loop;
2964
2965 else
2966 return False;
2967 end if;
2968 end Is_Configuration_Pragma;
2969
2970 --------------------------
2971 -- Is_In_Context_Clause --
2972 --------------------------
2973
2974 function Is_In_Context_Clause return Boolean is
2975 Plist : List_Id;
2976 Parent_Node : Node_Id;
2977
2978 begin
2979 if not Is_List_Member (N) then
2980 return False;
2981
2982 else
2983 Plist := List_Containing (N);
2984 Parent_Node := Parent (Plist);
2985
2986 if Parent_Node = Empty
2987 or else Nkind (Parent_Node) /= N_Compilation_Unit
2988 or else Context_Items (Parent_Node) /= Plist
2989 then
2990 return False;
2991 end if;
2992 end if;
2993
2994 return True;
2995 end Is_In_Context_Clause;
2996
2997 ---------------------------------
2998 -- Is_Static_String_Expression --
2999 ---------------------------------
3000
3001 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
3002 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3003
3004 begin
3005 Analyze_And_Resolve (Argx);
3006 return Is_OK_Static_Expression (Argx)
3007 and then Nkind (Argx) = N_String_Literal;
3008 end Is_Static_String_Expression;
3009
3010 ----------------------
3011 -- Pragma_Misplaced --
3012 ----------------------
3013
3014 procedure Pragma_Misplaced is
3015 begin
3016 Error_Pragma ("incorrect placement of pragma%");
3017 end Pragma_Misplaced;
3018
3019 ------------------------------------
3020 -- Process_Atomic_Shared_Volatile --
3021 ------------------------------------
3022
3023 procedure Process_Atomic_Shared_Volatile is
3024 E_Id : Node_Id;
3025 E : Entity_Id;
3026 D : Node_Id;
3027 K : Node_Kind;
3028 Utyp : Entity_Id;
3029
3030 procedure Set_Atomic (E : Entity_Id);
3031 -- Set given type as atomic, and if no explicit alignment was given,
3032 -- set alignment to unknown, since back end knows what the alignment
3033 -- requirements are for atomic arrays. Note: this step is necessary
3034 -- for derived types.
3035
3036 ----------------
3037 -- Set_Atomic --
3038 ----------------
3039
3040 procedure Set_Atomic (E : Entity_Id) is
3041 begin
3042 Set_Is_Atomic (E);
3043
3044 if not Has_Alignment_Clause (E) then
3045 Set_Alignment (E, Uint_0);
3046 end if;
3047 end Set_Atomic;
3048
3049 -- Start of processing for Process_Atomic_Shared_Volatile
3050
3051 begin
3052 Check_Ada_83_Warning;
3053 Check_No_Identifiers;
3054 Check_Arg_Count (1);
3055 Check_Arg_Is_Local_Name (Arg1);
3056 E_Id := Get_Pragma_Arg (Arg1);
3057
3058 if Etype (E_Id) = Any_Type then
3059 return;
3060 end if;
3061
3062 E := Entity (E_Id);
3063 D := Declaration_Node (E);
3064 K := Nkind (D);
3065
3066 -- Check duplicate before we chain ourselves!
3067
3068 Check_Duplicate_Pragma (E);
3069
3070 -- Now check appropriateness of the entity
3071
3072 if Is_Type (E) then
3073 if Rep_Item_Too_Early (E, N)
3074 or else
3075 Rep_Item_Too_Late (E, N)
3076 then
3077 return;
3078 else
3079 Check_First_Subtype (Arg1);
3080 end if;
3081
3082 if Prag_Id /= Pragma_Volatile then
3083 Set_Atomic (E);
3084 Set_Atomic (Underlying_Type (E));
3085 Set_Atomic (Base_Type (E));
3086 end if;
3087
3088 -- Attribute belongs on the base type. If the view of the type is
3089 -- currently private, it also belongs on the underlying type.
3090
3091 Set_Is_Volatile (Base_Type (E));
3092 Set_Is_Volatile (Underlying_Type (E));
3093
3094 Set_Treat_As_Volatile (E);
3095 Set_Treat_As_Volatile (Underlying_Type (E));
3096
3097 elsif K = N_Object_Declaration
3098 or else (K = N_Component_Declaration
3099 and then Original_Record_Component (E) = E)
3100 then
3101 if Rep_Item_Too_Late (E, N) then
3102 return;
3103 end if;
3104
3105 if Prag_Id /= Pragma_Volatile then
3106 Set_Is_Atomic (E);
3107
3108 -- If the object declaration has an explicit initialization, a
3109 -- temporary may have to be created to hold the expression, to
3110 -- ensure that access to the object remain atomic.
3111
3112 if Nkind (Parent (E)) = N_Object_Declaration
3113 and then Present (Expression (Parent (E)))
3114 then
3115 Set_Has_Delayed_Freeze (E);
3116 end if;
3117
3118 -- An interesting improvement here. If an object of composite
3119 -- type X is declared atomic, and the type X isn't, that's a
3120 -- pity, since it may not have appropriate alignment etc. We
3121 -- can rescue this in the special case where the object and
3122 -- type are in the same unit by just setting the type as
3123 -- atomic, so that the back end will process it as atomic.
3124
3125 -- Note: we used to do this for elementary types as well,
3126 -- but that turns out to be a bad idea and can have unwanted
3127 -- effects, most notably if the type is elementary, the object
3128 -- a simple component within a record, and both are in a spec:
3129 -- every object of this type in the entire program will be
3130 -- treated as atomic, thus incurring a potentially costly
3131 -- synchronization operation for every access.
3132
3133 -- Of course it would be best if the back end could just adjust
3134 -- the alignment etc for the specific object, but that's not
3135 -- something we are capable of doing at this point.
3136
3137 Utyp := Underlying_Type (Etype (E));
3138
3139 if Present (Utyp)
3140 and then Is_Composite_Type (Utyp)
3141 and then Sloc (E) > No_Location
3142 and then Sloc (Utyp) > No_Location
3143 and then
3144 Get_Source_File_Index (Sloc (E)) =
3145 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
3146 then
3147 Set_Is_Atomic (Underlying_Type (Etype (E)));
3148 end if;
3149 end if;
3150
3151 Set_Is_Volatile (E);
3152 Set_Treat_As_Volatile (E);
3153
3154 else
3155 Error_Pragma_Arg
3156 ("inappropriate entity for pragma%", Arg1);
3157 end if;
3158 end Process_Atomic_Shared_Volatile;
3159
3160 -------------------------------------------
3161 -- Process_Compile_Time_Warning_Or_Error --
3162 -------------------------------------------
3163
3164 procedure Process_Compile_Time_Warning_Or_Error is
3165 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
3166
3167 begin
3168 Check_Arg_Count (2);
3169 Check_No_Identifiers;
3170 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3171 Analyze_And_Resolve (Arg1x, Standard_Boolean);
3172
3173 if Compile_Time_Known_Value (Arg1x) then
3174 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3175 declare
3176 Str : constant String_Id :=
3177 Strval (Get_Pragma_Arg (Arg2));
3178 Len : constant Int := String_Length (Str);
3179 Cont : Boolean;
3180 Ptr : Nat;
3181 CC : Char_Code;
3182 C : Character;
3183 Cent : constant Entity_Id :=
3184 Cunit_Entity (Current_Sem_Unit);
3185
3186 Force : constant Boolean :=
3187 Prag_Id = Pragma_Compile_Time_Warning
3188 and then
3189 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3190 and then (Ekind (Cent) /= E_Package
3191 or else not In_Private_Part (Cent));
3192 -- Set True if this is the warning case, and we are in the
3193 -- visible part of a package spec, or in a subprogram spec,
3194 -- in which case we want to force the client to see the
3195 -- warning, even though it is not in the main unit.
3196
3197 begin
3198 -- Loop through segments of message separated by line feeds.
3199 -- We output these segments as separate messages with
3200 -- continuation marks for all but the first.
3201
3202 Cont := False;
3203 Ptr := 1;
3204 loop
3205 Error_Msg_Strlen := 0;
3206
3207 -- Loop to copy characters from argument to error message
3208 -- string buffer.
3209
3210 loop
3211 exit when Ptr > Len;
3212 CC := Get_String_Char (Str, Ptr);
3213 Ptr := Ptr + 1;
3214
3215 -- Ignore wide chars ??? else store character
3216
3217 if In_Character_Range (CC) then
3218 C := Get_Character (CC);
3219 exit when C = ASCII.LF;
3220 Error_Msg_Strlen := Error_Msg_Strlen + 1;
3221 Error_Msg_String (Error_Msg_Strlen) := C;
3222 end if;
3223 end loop;
3224
3225 -- Here with one line ready to go
3226
3227 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3228
3229 -- If this is a warning in a spec, then we want clients
3230 -- to see the warning, so mark the message with the
3231 -- special sequence !! to force the warning. In the case
3232 -- of a package spec, we do not force this if we are in
3233 -- the private part of the spec.
3234
3235 if Force then
3236 if Cont = False then
3237 Error_Msg_N ("<~!!", Arg1);
3238 Cont := True;
3239 else
3240 Error_Msg_N ("\<~!!", Arg1);
3241 end if;
3242
3243 -- Error, rather than warning, or in a body, so we do not
3244 -- need to force visibility for client (error will be
3245 -- output in any case, and this is the situation in which
3246 -- we do not want a client to get a warning, since the
3247 -- warning is in the body or the spec private part).
3248
3249 else
3250 if Cont = False then
3251 Error_Msg_N ("<~", Arg1);
3252 Cont := True;
3253 else
3254 Error_Msg_N ("\<~", Arg1);
3255 end if;
3256 end if;
3257
3258 exit when Ptr > Len;
3259 end loop;
3260 end;
3261 end if;
3262 end if;
3263 end Process_Compile_Time_Warning_Or_Error;
3264
3265 ------------------------
3266 -- Process_Convention --
3267 ------------------------
3268
3269 procedure Process_Convention
3270 (C : out Convention_Id;
3271 Ent : out Entity_Id)
3272 is
3273 Id : Node_Id;
3274 E : Entity_Id;
3275 E1 : Entity_Id;
3276 Cname : Name_Id;
3277 Comp_Unit : Unit_Number_Type;
3278
3279 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3280 -- Called if we have more than one Export/Import/Convention pragma.
3281 -- This is generally illegal, but we have a special case of allowing
3282 -- Import and Interface to coexist if they specify the convention in
3283 -- a consistent manner. We are allowed to do this, since Interface is
3284 -- an implementation defined pragma, and we choose to do it since we
3285 -- know Rational allows this combination. S is the entity id of the
3286 -- subprogram in question. This procedure also sets the special flag
3287 -- Import_Interface_Present in both pragmas in the case where we do
3288 -- have matching Import and Interface pragmas.
3289
3290 procedure Set_Convention_From_Pragma (E : Entity_Id);
3291 -- Set convention in entity E, and also flag that the entity has a
3292 -- convention pragma. If entity is for a private or incomplete type,
3293 -- also set convention and flag on underlying type. This procedure
3294 -- also deals with the special case of C_Pass_By_Copy convention.
3295
3296 -------------------------------
3297 -- Diagnose_Multiple_Pragmas --
3298 -------------------------------
3299
3300 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3301 Pdec : constant Node_Id := Declaration_Node (S);
3302 Decl : Node_Id;
3303 Err : Boolean;
3304
3305 function Same_Convention (Decl : Node_Id) return Boolean;
3306 -- Decl is a pragma node. This function returns True if this
3307 -- pragma has a first argument that is an identifier with a
3308 -- Chars field corresponding to the Convention_Id C.
3309
3310 function Same_Name (Decl : Node_Id) return Boolean;
3311 -- Decl is a pragma node. This function returns True if this
3312 -- pragma has a second argument that is an identifier with a
3313 -- Chars field that matches the Chars of the current subprogram.
3314
3315 ---------------------
3316 -- Same_Convention --
3317 ---------------------
3318
3319 function Same_Convention (Decl : Node_Id) return Boolean is
3320 Arg1 : constant Node_Id :=
3321 First (Pragma_Argument_Associations (Decl));
3322
3323 begin
3324 if Present (Arg1) then
3325 declare
3326 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3327 begin
3328 if Nkind (Arg) = N_Identifier
3329 and then Is_Convention_Name (Chars (Arg))
3330 and then Get_Convention_Id (Chars (Arg)) = C
3331 then
3332 return True;
3333 end if;
3334 end;
3335 end if;
3336
3337 return False;
3338 end Same_Convention;
3339
3340 ---------------
3341 -- Same_Name --
3342 ---------------
3343
3344 function Same_Name (Decl : Node_Id) return Boolean is
3345 Arg1 : constant Node_Id :=
3346 First (Pragma_Argument_Associations (Decl));
3347 Arg2 : Node_Id;
3348
3349 begin
3350 if No (Arg1) then
3351 return False;
3352 end if;
3353
3354 Arg2 := Next (Arg1);
3355
3356 if No (Arg2) then
3357 return False;
3358 end if;
3359
3360 declare
3361 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3362 begin
3363 if Nkind (Arg) = N_Identifier
3364 and then Chars (Arg) = Chars (S)
3365 then
3366 return True;
3367 end if;
3368 end;
3369
3370 return False;
3371 end Same_Name;
3372
3373 -- Start of processing for Diagnose_Multiple_Pragmas
3374
3375 begin
3376 Err := True;
3377
3378 -- Definitely give message if we have Convention/Export here
3379
3380 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3381 null;
3382
3383 -- If we have an Import or Export, scan back from pragma to
3384 -- find any previous pragma applying to the same procedure.
3385 -- The scan will be terminated by the start of the list, or
3386 -- hitting the subprogram declaration. This won't allow one
3387 -- pragma to appear in the public part and one in the private
3388 -- part, but that seems very unlikely in practice.
3389
3390 else
3391 Decl := Prev (N);
3392 while Present (Decl) and then Decl /= Pdec loop
3393
3394 -- Look for pragma with same name as us
3395
3396 if Nkind (Decl) = N_Pragma
3397 and then Same_Name (Decl)
3398 then
3399 -- Give error if same as our pragma or Export/Convention
3400
3401 if Pragma_Name (Decl) = Name_Export
3402 or else
3403 Pragma_Name (Decl) = Name_Convention
3404 or else
3405 Pragma_Name (Decl) = Pragma_Name (N)
3406 then
3407 exit;
3408
3409 -- Case of Import/Interface or the other way round
3410
3411 elsif Pragma_Name (Decl) = Name_Interface
3412 or else
3413 Pragma_Name (Decl) = Name_Import
3414 then
3415 -- Here we know that we have Import and Interface. It
3416 -- doesn't matter which way round they are. See if
3417 -- they specify the same convention. If so, all OK,
3418 -- and set special flags to stop other messages
3419
3420 if Same_Convention (Decl) then
3421 Set_Import_Interface_Present (N);
3422 Set_Import_Interface_Present (Decl);
3423 Err := False;
3424
3425 -- If different conventions, special message
3426
3427 else
3428 Error_Msg_Sloc := Sloc (Decl);
3429 Error_Pragma_Arg
3430 ("convention differs from that given#", Arg1);
3431 return;
3432 end if;
3433 end if;
3434 end if;
3435
3436 Next (Decl);
3437 end loop;
3438 end if;
3439
3440 -- Give message if needed if we fall through those tests
3441
3442 if Err then
3443 Error_Pragma_Arg
3444 ("at most one Convention/Export/Import pragma is allowed",
3445 Arg2);
3446 end if;
3447 end Diagnose_Multiple_Pragmas;
3448
3449 --------------------------------
3450 -- Set_Convention_From_Pragma --
3451 --------------------------------
3452
3453 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3454 begin
3455 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3456 -- for an overridden dispatching operation. Technically this is
3457 -- an amendment and should only be done in Ada 2005 mode. However,
3458 -- this is clearly a mistake, since the problem that is addressed
3459 -- by this AI is that there is a clear gap in the RM!
3460
3461 if Is_Dispatching_Operation (E)
3462 and then Present (Overridden_Operation (E))
3463 and then C /= Convention (Overridden_Operation (E))
3464 then
3465 Error_Pragma_Arg
3466 ("cannot change convention for " &
3467 "overridden dispatching operation",
3468 Arg1);
3469 end if;
3470
3471 -- Set the convention
3472
3473 Set_Convention (E, C);
3474 Set_Has_Convention_Pragma (E);
3475
3476 if Is_Incomplete_Or_Private_Type (E)
3477 and then Present (Underlying_Type (E))
3478 then
3479 Set_Convention (Underlying_Type (E), C);
3480 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3481 end if;
3482
3483 -- A class-wide type should inherit the convention of the specific
3484 -- root type (although this isn't specified clearly by the RM).
3485
3486 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3487 Set_Convention (Class_Wide_Type (E), C);
3488 end if;
3489
3490 -- If the entity is a record type, then check for special case of
3491 -- C_Pass_By_Copy, which is treated the same as C except that the
3492 -- special record flag is set. This convention is only permitted
3493 -- on record types (see AI95-00131).
3494
3495 if Cname = Name_C_Pass_By_Copy then
3496 if Is_Record_Type (E) then
3497 Set_C_Pass_By_Copy (Base_Type (E));
3498 elsif Is_Incomplete_Or_Private_Type (E)
3499 and then Is_Record_Type (Underlying_Type (E))
3500 then
3501 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3502 else
3503 Error_Pragma_Arg
3504 ("C_Pass_By_Copy convention allowed only for record type",
3505 Arg2);
3506 end if;
3507 end if;
3508
3509 -- If the entity is a derived boolean type, check for the special
3510 -- case of convention C, C++, or Fortran, where we consider any
3511 -- nonzero value to represent true.
3512
3513 if Is_Discrete_Type (E)
3514 and then Root_Type (Etype (E)) = Standard_Boolean
3515 and then
3516 (C = Convention_C
3517 or else
3518 C = Convention_CPP
3519 or else
3520 C = Convention_Fortran)
3521 then
3522 Set_Nonzero_Is_True (Base_Type (E));
3523 end if;
3524 end Set_Convention_From_Pragma;
3525
3526 -- Start of processing for Process_Convention
3527
3528 begin
3529 Check_At_Least_N_Arguments (2);
3530 Check_Optional_Identifier (Arg1, Name_Convention);
3531 Check_Arg_Is_Identifier (Arg1);
3532 Cname := Chars (Get_Pragma_Arg (Arg1));
3533
3534 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3535 -- tested again below to set the critical flag).
3536
3537 if Cname = Name_C_Pass_By_Copy then
3538 C := Convention_C;
3539
3540 -- Otherwise we must have something in the standard convention list
3541
3542 elsif Is_Convention_Name (Cname) then
3543 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3544
3545 -- In DEC VMS, it seems that there is an undocumented feature that
3546 -- any unrecognized convention is treated as the default, which for
3547 -- us is convention C. It does not seem so terrible to do this
3548 -- unconditionally, silently in the VMS case, and with a warning
3549 -- in the non-VMS case.
3550
3551 else
3552 if Warn_On_Export_Import and not OpenVMS_On_Target then
3553 Error_Msg_N
3554 ("?unrecognized convention name, C assumed",
3555 Get_Pragma_Arg (Arg1));
3556 end if;
3557
3558 C := Convention_C;
3559 end if;
3560
3561 Check_Optional_Identifier (Arg2, Name_Entity);
3562 Check_Arg_Is_Local_Name (Arg2);
3563
3564 Id := Get_Pragma_Arg (Arg2);
3565 Analyze (Id);
3566
3567 if not Is_Entity_Name (Id) then
3568 Error_Pragma_Arg ("entity name required", Arg2);
3569 end if;
3570
3571 E := Entity (Id);
3572
3573 -- Set entity to return
3574
3575 Ent := E;
3576
3577 -- Ada_Pass_By_Copy special checking
3578
3579 if C = Convention_Ada_Pass_By_Copy then
3580 if not Is_First_Subtype (E) then
3581 Error_Pragma_Arg
3582 ("convention `Ada_Pass_By_Copy` only "
3583 & "allowed for types", Arg2);
3584 end if;
3585
3586 if Is_By_Reference_Type (E) then
3587 Error_Pragma_Arg
3588 ("convention `Ada_Pass_By_Copy` not allowed for "
3589 & "by-reference type", Arg1);
3590 end if;
3591 end if;
3592
3593 -- Ada_Pass_By_Reference special checking
3594
3595 if C = Convention_Ada_Pass_By_Reference then
3596 if not Is_First_Subtype (E) then
3597 Error_Pragma_Arg
3598 ("convention `Ada_Pass_By_Reference` only "
3599 & "allowed for types", Arg2);
3600 end if;
3601
3602 if Is_By_Copy_Type (E) then
3603 Error_Pragma_Arg
3604 ("convention `Ada_Pass_By_Reference` not allowed for "
3605 & "by-copy type", Arg1);
3606 end if;
3607 end if;
3608
3609 -- Go to renamed subprogram if present, since convention applies to
3610 -- the actual renamed entity, not to the renaming entity. If the
3611 -- subprogram is inherited, go to parent subprogram.
3612
3613 if Is_Subprogram (E)
3614 and then Present (Alias (E))
3615 then
3616 if Nkind (Parent (Declaration_Node (E))) =
3617 N_Subprogram_Renaming_Declaration
3618 then
3619 if Scope (E) /= Scope (Alias (E)) then
3620 Error_Pragma_Ref
3621 ("cannot apply pragma% to non-local entity&#", E);
3622 end if;
3623
3624 E := Alias (E);
3625
3626 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3627 N_Private_Extension_Declaration)
3628 and then Scope (E) = Scope (Alias (E))
3629 then
3630 E := Alias (E);
3631
3632 -- Return the parent subprogram the entity was inherited from
3633
3634 Ent := E;
3635 end if;
3636 end if;
3637
3638 -- Check that we are not applying this to a specless body
3639
3640 if Is_Subprogram (E)
3641 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3642 then
3643 Error_Pragma
3644 ("pragma% requires separate spec and must come before body");
3645 end if;
3646
3647 -- Check that we are not applying this to a named constant
3648
3649 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3650 Error_Msg_Name_1 := Pname;
3651 Error_Msg_N
3652 ("cannot apply pragma% to named constant!",
3653 Get_Pragma_Arg (Arg2));
3654 Error_Pragma_Arg
3655 ("\supply appropriate type for&!", Arg2);
3656 end if;
3657
3658 if Ekind (E) = E_Enumeration_Literal then
3659 Error_Pragma ("enumeration literal not allowed for pragma%");
3660 end if;
3661
3662 -- Check for rep item appearing too early or too late
3663
3664 if Etype (E) = Any_Type
3665 or else Rep_Item_Too_Early (E, N)
3666 then
3667 raise Pragma_Exit;
3668
3669 elsif Present (Underlying_Type (E)) then
3670 E := Underlying_Type (E);
3671 end if;
3672
3673 if Rep_Item_Too_Late (E, N) then
3674 raise Pragma_Exit;
3675 end if;
3676
3677 if Has_Convention_Pragma (E) then
3678 Diagnose_Multiple_Pragmas (E);
3679
3680 elsif Convention (E) = Convention_Protected
3681 or else Ekind (Scope (E)) = E_Protected_Type
3682 then
3683 Error_Pragma_Arg
3684 ("a protected operation cannot be given a different convention",
3685 Arg2);
3686 end if;
3687
3688 -- For Intrinsic, a subprogram is required
3689
3690 if C = Convention_Intrinsic
3691 and then not Is_Subprogram (E)
3692 and then not Is_Generic_Subprogram (E)
3693 then
3694 Error_Pragma_Arg
3695 ("second argument of pragma% must be a subprogram", Arg2);
3696 end if;
3697
3698 -- Stdcall case
3699
3700 if C = Convention_Stdcall then
3701
3702 -- A dispatching call is not allowed. A dispatching subprogram
3703 -- cannot be used to interface to the Win32 API, so in fact this
3704 -- check does not impose any effective restriction.
3705
3706 if Is_Dispatching_Operation (E) then
3707
3708 Error_Pragma
3709 ("dispatching subprograms cannot use Stdcall convention");
3710
3711 -- Subprogram is allowed, but not a generic subprogram, and not a
3712 -- dispatching operation.
3713
3714 elsif not Is_Subprogram (E)
3715 and then not Is_Generic_Subprogram (E)
3716
3717 -- A variable is OK
3718
3719 and then Ekind (E) /= E_Variable
3720
3721 -- An access to subprogram is also allowed
3722
3723 and then not
3724 (Is_Access_Type (E)
3725 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3726 then
3727 Error_Pragma_Arg
3728 ("second argument of pragma% must be subprogram (type)",
3729 Arg2);
3730 end if;
3731 end if;
3732
3733 if not Is_Subprogram (E)
3734 and then not Is_Generic_Subprogram (E)
3735 then
3736 Set_Convention_From_Pragma (E);
3737
3738 if Is_Type (E) then
3739 Check_First_Subtype (Arg2);
3740 Set_Convention_From_Pragma (Base_Type (E));
3741
3742 -- For subprograms, we must set the convention on the
3743 -- internally generated directly designated type as well.
3744
3745 if Ekind (E) = E_Access_Subprogram_Type then
3746 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3747 end if;
3748 end if;
3749
3750 -- For the subprogram case, set proper convention for all homonyms
3751 -- in same scope and the same declarative part, i.e. the same
3752 -- compilation unit.
3753
3754 else
3755 Comp_Unit := Get_Source_Unit (E);
3756 Set_Convention_From_Pragma (E);
3757
3758 -- Treat a pragma Import as an implicit body, and pragma import
3759 -- as implicit reference (for navigation in GPS).
3760
3761 if Prag_Id = Pragma_Import then
3762 Generate_Reference (E, Id, 'b');
3763
3764 -- For exported entities we restrict the generation of references
3765 -- to entities exported to foreign languages since entities
3766 -- exported to Ada do not provide further information to GPS and
3767 -- add undesired references to the output of the gnatxref tool.
3768
3769 elsif Prag_Id = Pragma_Export
3770 and then Convention (E) /= Convention_Ada
3771 then
3772 Generate_Reference (E, Id, 'i');
3773 end if;
3774
3775 -- If the pragma comes from from an aspect, it only applies
3776 -- to the given entity, not its homonyms.
3777
3778 if From_Aspect_Specification (N) then
3779 return;
3780 end if;
3781
3782 -- Otherwise Loop through the homonyms of the pragma argument's
3783 -- entity, an apply convention to those in the current scope.
3784
3785 E1 := Ent;
3786
3787 loop
3788 E1 := Homonym (E1);
3789 exit when No (E1) or else Scope (E1) /= Current_Scope;
3790
3791 -- Do not set the pragma on inherited operations or on formal
3792 -- subprograms.
3793
3794 if Comes_From_Source (E1)
3795 and then Comp_Unit = Get_Source_Unit (E1)
3796 and then not Is_Formal_Subprogram (E1)
3797 and then Nkind (Original_Node (Parent (E1))) /=
3798 N_Full_Type_Declaration
3799 then
3800 if Present (Alias (E1))
3801 and then Scope (E1) /= Scope (Alias (E1))
3802 then
3803 Error_Pragma_Ref
3804 ("cannot apply pragma% to non-local entity& declared#",
3805 E1);
3806 end if;
3807
3808 Set_Convention_From_Pragma (E1);
3809
3810 if Prag_Id = Pragma_Import then
3811 Generate_Reference (E1, Id, 'b');
3812 end if;
3813 end if;
3814 end loop;
3815 end if;
3816 end Process_Convention;
3817
3818 ----------------------------------------
3819 -- Process_Disable_Enable_Atomic_Sync --
3820 ----------------------------------------
3821
3822 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3823 begin
3824 GNAT_Pragma;
3825 Check_No_Identifiers;
3826 Check_At_Most_N_Arguments (1);
3827
3828 -- Modeled internally as
3829 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
3830
3831 Rewrite (N,
3832 Make_Pragma (Loc,
3833 Pragma_Identifier =>
3834 Make_Identifier (Loc, Nam),
3835 Pragma_Argument_Associations => New_List (
3836 Make_Pragma_Argument_Association (Loc,
3837 Expression =>
3838 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3839
3840 if Present (Arg1) then
3841 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3842 end if;
3843
3844 Analyze (N);
3845 end Process_Disable_Enable_Atomic_Sync;
3846
3847 -----------------------------------------------------
3848 -- Process_Extended_Import_Export_Exception_Pragma --
3849 -----------------------------------------------------
3850
3851 procedure Process_Extended_Import_Export_Exception_Pragma
3852 (Arg_Internal : Node_Id;
3853 Arg_External : Node_Id;
3854 Arg_Form : Node_Id;
3855 Arg_Code : Node_Id)
3856 is
3857 Def_Id : Entity_Id;
3858 Code_Val : Uint;
3859
3860 begin
3861 if not OpenVMS_On_Target then
3862 Error_Pragma
3863 ("?pragma% ignored (applies only to Open'V'M'S)");
3864 end if;
3865
3866 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3867 Def_Id := Entity (Arg_Internal);
3868
3869 if Ekind (Def_Id) /= E_Exception then
3870 Error_Pragma_Arg
3871 ("pragma% must refer to declared exception", Arg_Internal);
3872 end if;
3873
3874 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3875
3876 if Present (Arg_Form) then
3877 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3878 end if;
3879
3880 if Present (Arg_Form)
3881 and then Chars (Arg_Form) = Name_Ada
3882 then
3883 null;
3884 else
3885 Set_Is_VMS_Exception (Def_Id);
3886 Set_Exception_Code (Def_Id, No_Uint);
3887 end if;
3888
3889 if Present (Arg_Code) then
3890 if not Is_VMS_Exception (Def_Id) then
3891 Error_Pragma_Arg
3892 ("Code option for pragma% not allowed for Ada case",
3893 Arg_Code);
3894 end if;
3895
3896 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3897 Code_Val := Expr_Value (Arg_Code);
3898
3899 if not UI_Is_In_Int_Range (Code_Val) then
3900 Error_Pragma_Arg
3901 ("Code option for pragma% must be in 32-bit range",
3902 Arg_Code);
3903
3904 else
3905 Set_Exception_Code (Def_Id, Code_Val);
3906 end if;
3907 end if;
3908 end Process_Extended_Import_Export_Exception_Pragma;
3909
3910 -------------------------------------------------
3911 -- Process_Extended_Import_Export_Internal_Arg --
3912 -------------------------------------------------
3913
3914 procedure Process_Extended_Import_Export_Internal_Arg
3915 (Arg_Internal : Node_Id := Empty)
3916 is
3917 begin
3918 if No (Arg_Internal) then
3919 Error_Pragma ("Internal parameter required for pragma%");
3920 end if;
3921
3922 if Nkind (Arg_Internal) = N_Identifier then
3923 null;
3924
3925 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3926 and then (Prag_Id = Pragma_Import_Function
3927 or else
3928 Prag_Id = Pragma_Export_Function)
3929 then
3930 null;
3931
3932 else
3933 Error_Pragma_Arg
3934 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3935 end if;
3936
3937 Check_Arg_Is_Local_Name (Arg_Internal);
3938 end Process_Extended_Import_Export_Internal_Arg;
3939
3940 --------------------------------------------------
3941 -- Process_Extended_Import_Export_Object_Pragma --
3942 --------------------------------------------------
3943
3944 procedure Process_Extended_Import_Export_Object_Pragma
3945 (Arg_Internal : Node_Id;
3946 Arg_External : Node_Id;
3947 Arg_Size : Node_Id)
3948 is
3949 Def_Id : Entity_Id;
3950
3951 begin
3952 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3953 Def_Id := Entity (Arg_Internal);
3954
3955 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3956 Error_Pragma_Arg
3957 ("pragma% must designate an object", Arg_Internal);
3958 end if;
3959
3960 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3961 or else
3962 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3963 then
3964 Error_Pragma_Arg
3965 ("previous Common/Psect_Object applies, pragma % not permitted",
3966 Arg_Internal);
3967 end if;
3968
3969 if Rep_Item_Too_Late (Def_Id, N) then
3970 raise Pragma_Exit;
3971 end if;
3972
3973 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3974
3975 if Present (Arg_Size) then
3976 Check_Arg_Is_External_Name (Arg_Size);
3977 end if;
3978
3979 -- Export_Object case
3980
3981 if Prag_Id = Pragma_Export_Object then
3982 if not Is_Library_Level_Entity (Def_Id) then
3983 Error_Pragma_Arg
3984 ("argument for pragma% must be library level entity",
3985 Arg_Internal);
3986 end if;
3987
3988 if Ekind (Current_Scope) = E_Generic_Package then
3989 Error_Pragma ("pragma& cannot appear in a generic unit");
3990 end if;
3991
3992 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3993 Error_Pragma_Arg
3994 ("exported object must have compile time known size",
3995 Arg_Internal);
3996 end if;
3997
3998 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3999 Error_Msg_N ("?duplicate Export_Object pragma", N);
4000 else
4001 Set_Exported (Def_Id, Arg_Internal);
4002 end if;
4003
4004 -- Import_Object case
4005
4006 else
4007 if Is_Concurrent_Type (Etype (Def_Id)) then
4008 Error_Pragma_Arg
4009 ("cannot use pragma% for task/protected object",
4010 Arg_Internal);
4011 end if;
4012
4013 if Ekind (Def_Id) = E_Constant then
4014 Error_Pragma_Arg
4015 ("cannot import a constant", Arg_Internal);
4016 end if;
4017
4018 if Warn_On_Export_Import
4019 and then Has_Discriminants (Etype (Def_Id))
4020 then
4021 Error_Msg_N
4022 ("imported value must be initialized?", Arg_Internal);
4023 end if;
4024
4025 if Warn_On_Export_Import
4026 and then Is_Access_Type (Etype (Def_Id))
4027 then
4028 Error_Pragma_Arg
4029 ("cannot import object of an access type?", Arg_Internal);
4030 end if;
4031
4032 if Warn_On_Export_Import
4033 and then Is_Imported (Def_Id)
4034 then
4035 Error_Msg_N
4036 ("?duplicate Import_Object pragma", N);
4037
4038 -- Check for explicit initialization present. Note that an
4039 -- initialization generated by the code generator, e.g. for an
4040 -- access type, does not count here.
4041
4042 elsif Present (Expression (Parent (Def_Id)))
4043 and then
4044 Comes_From_Source
4045 (Original_Node (Expression (Parent (Def_Id))))
4046 then
4047 Error_Msg_Sloc := Sloc (Def_Id);
4048 Error_Pragma_Arg
4049 ("imported entities cannot be initialized (RM B.1(24))",
4050 "\no initialization allowed for & declared#", Arg1);
4051 else
4052 Set_Imported (Def_Id);
4053 Note_Possible_Modification (Arg_Internal, Sure => False);
4054 end if;
4055 end if;
4056 end Process_Extended_Import_Export_Object_Pragma;
4057
4058 ------------------------------------------------------
4059 -- Process_Extended_Import_Export_Subprogram_Pragma --
4060 ------------------------------------------------------
4061
4062 procedure Process_Extended_Import_Export_Subprogram_Pragma
4063 (Arg_Internal : Node_Id;
4064 Arg_External : Node_Id;
4065 Arg_Parameter_Types : Node_Id;
4066 Arg_Result_Type : Node_Id := Empty;
4067 Arg_Mechanism : Node_Id;
4068 Arg_Result_Mechanism : Node_Id := Empty;
4069 Arg_First_Optional_Parameter : Node_Id := Empty)
4070 is
4071 Ent : Entity_Id;
4072 Def_Id : Entity_Id;
4073 Hom_Id : Entity_Id;
4074 Formal : Entity_Id;
4075 Ambiguous : Boolean;
4076 Match : Boolean;
4077 Dval : Node_Id;
4078
4079 function Same_Base_Type
4080 (Ptype : Node_Id;
4081 Formal : Entity_Id) return Boolean;
4082 -- Determines if Ptype references the type of Formal. Note that only
4083 -- the base types need to match according to the spec. Ptype here is
4084 -- the argument from the pragma, which is either a type name, or an
4085 -- access attribute.
4086
4087 --------------------
4088 -- Same_Base_Type --
4089 --------------------
4090
4091 function Same_Base_Type
4092 (Ptype : Node_Id;
4093 Formal : Entity_Id) return Boolean
4094 is
4095 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
4096 Pref : Node_Id;
4097
4098 begin
4099 -- Case where pragma argument is typ'Access
4100
4101 if Nkind (Ptype) = N_Attribute_Reference
4102 and then Attribute_Name (Ptype) = Name_Access
4103 then
4104 Pref := Prefix (Ptype);
4105 Find_Type (Pref);
4106
4107 if not Is_Entity_Name (Pref)
4108 or else Entity (Pref) = Any_Type
4109 then
4110 raise Pragma_Exit;
4111 end if;
4112
4113 -- We have a match if the corresponding argument is of an
4114 -- anonymous access type, and its designated type matches the
4115 -- type of the prefix of the access attribute
4116
4117 return Ekind (Ftyp) = E_Anonymous_Access_Type
4118 and then Base_Type (Entity (Pref)) =
4119 Base_Type (Etype (Designated_Type (Ftyp)));
4120
4121 -- Case where pragma argument is a type name
4122
4123 else
4124 Find_Type (Ptype);
4125
4126 if not Is_Entity_Name (Ptype)
4127 or else Entity (Ptype) = Any_Type
4128 then
4129 raise Pragma_Exit;
4130 end if;
4131
4132 -- We have a match if the corresponding argument is of the type
4133 -- given in the pragma (comparing base types)
4134
4135 return Base_Type (Entity (Ptype)) = Ftyp;
4136 end if;
4137 end Same_Base_Type;
4138
4139 -- Start of processing for
4140 -- Process_Extended_Import_Export_Subprogram_Pragma
4141
4142 begin
4143 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
4144 Ent := Empty;
4145 Ambiguous := False;
4146
4147 -- Loop through homonyms (overloadings) of the entity
4148
4149 Hom_Id := Entity (Arg_Internal);
4150 while Present (Hom_Id) loop
4151 Def_Id := Get_Base_Subprogram (Hom_Id);
4152
4153 -- We need a subprogram in the current scope
4154
4155 if not Is_Subprogram (Def_Id)
4156 or else Scope (Def_Id) /= Current_Scope
4157 then
4158 null;
4159
4160 else
4161 Match := True;
4162
4163 -- Pragma cannot apply to subprogram body
4164
4165 if Is_Subprogram (Def_Id)
4166 and then Nkind (Parent (Declaration_Node (Def_Id))) =
4167 N_Subprogram_Body
4168 then
4169 Error_Pragma
4170 ("pragma% requires separate spec"
4171 & " and must come before body");
4172 end if;
4173
4174 -- Test result type if given, note that the result type
4175 -- parameter can only be present for the function cases.
4176
4177 if Present (Arg_Result_Type)
4178 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
4179 then
4180 Match := False;
4181
4182 elsif Etype (Def_Id) /= Standard_Void_Type
4183 and then
4184 (Pname = Name_Export_Procedure
4185 or else
4186 Pname = Name_Import_Procedure)
4187 then
4188 Match := False;
4189
4190 -- Test parameter types if given. Note that this parameter
4191 -- has not been analyzed (and must not be, since it is
4192 -- semantic nonsense), so we get it as the parser left it.
4193
4194 elsif Present (Arg_Parameter_Types) then
4195 Check_Matching_Types : declare
4196 Formal : Entity_Id;
4197 Ptype : Node_Id;
4198
4199 begin
4200 Formal := First_Formal (Def_Id);
4201
4202 if Nkind (Arg_Parameter_Types) = N_Null then
4203 if Present (Formal) then
4204 Match := False;
4205 end if;
4206
4207 -- A list of one type, e.g. (List) is parsed as
4208 -- a parenthesized expression.
4209
4210 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4211 and then Paren_Count (Arg_Parameter_Types) = 1
4212 then
4213 if No (Formal)
4214 or else Present (Next_Formal (Formal))
4215 then
4216 Match := False;
4217 else
4218 Match :=
4219 Same_Base_Type (Arg_Parameter_Types, Formal);
4220 end if;
4221
4222 -- A list of more than one type is parsed as a aggregate
4223
4224 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4225 and then Paren_Count (Arg_Parameter_Types) = 0
4226 then
4227 Ptype := First (Expressions (Arg_Parameter_Types));
4228 while Present (Ptype) or else Present (Formal) loop
4229 if No (Ptype)
4230 or else No (Formal)
4231 or else not Same_Base_Type (Ptype, Formal)
4232 then
4233 Match := False;
4234 exit;
4235 else
4236 Next_Formal (Formal);
4237 Next (Ptype);
4238 end if;
4239 end loop;
4240
4241 -- Anything else is of the wrong form
4242
4243 else
4244 Error_Pragma_Arg
4245 ("wrong form for Parameter_Types parameter",
4246 Arg_Parameter_Types);
4247 end if;
4248 end Check_Matching_Types;
4249 end if;
4250
4251 -- Match is now False if the entry we found did not match
4252 -- either a supplied Parameter_Types or Result_Types argument
4253
4254 if Match then
4255 if No (Ent) then
4256 Ent := Def_Id;
4257
4258 -- Ambiguous case, the flag Ambiguous shows if we already
4259 -- detected this and output the initial messages.
4260
4261 else
4262 if not Ambiguous then
4263 Ambiguous := True;
4264 Error_Msg_Name_1 := Pname;
4265 Error_Msg_N
4266 ("pragma% does not uniquely identify subprogram!",
4267 N);
4268 Error_Msg_Sloc := Sloc (Ent);
4269 Error_Msg_N ("matching subprogram #!", N);
4270 Ent := Empty;
4271 end if;
4272
4273 Error_Msg_Sloc := Sloc (Def_Id);
4274 Error_Msg_N ("matching subprogram #!", N);
4275 end if;
4276 end if;
4277 end if;
4278
4279 Hom_Id := Homonym (Hom_Id);
4280 end loop;
4281
4282 -- See if we found an entry
4283
4284 if No (Ent) then
4285 if not Ambiguous then
4286 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4287 Error_Pragma
4288 ("pragma% cannot be given for generic subprogram");
4289 else
4290 Error_Pragma
4291 ("pragma% does not identify local subprogram");
4292 end if;
4293 end if;
4294
4295 return;
4296 end if;
4297
4298 -- Import pragmas must be for imported entities
4299
4300 if Prag_Id = Pragma_Import_Function
4301 or else
4302 Prag_Id = Pragma_Import_Procedure
4303 or else
4304 Prag_Id = Pragma_Import_Valued_Procedure
4305 then
4306 if not Is_Imported (Ent) then
4307 Error_Pragma
4308 ("pragma Import or Interface must precede pragma%");
4309 end if;
4310
4311 -- Here we have the Export case which can set the entity as exported
4312
4313 -- But does not do so if the specified external name is null, since
4314 -- that is taken as a signal in DEC Ada 83 (with which we want to be
4315 -- compatible) to request no external name.
4316
4317 elsif Nkind (Arg_External) = N_String_Literal
4318 and then String_Length (Strval (Arg_External)) = 0
4319 then
4320 null;
4321
4322 -- In all other cases, set entity as exported
4323
4324 else
4325 Set_Exported (Ent, Arg_Internal);
4326 end if;
4327
4328 -- Special processing for Valued_Procedure cases
4329
4330 if Prag_Id = Pragma_Import_Valued_Procedure
4331 or else
4332 Prag_Id = Pragma_Export_Valued_Procedure
4333 then
4334 Formal := First_Formal (Ent);
4335
4336 if No (Formal) then
4337 Error_Pragma ("at least one parameter required for pragma%");
4338
4339 elsif Ekind (Formal) /= E_Out_Parameter then
4340 Error_Pragma ("first parameter must have mode out for pragma%");
4341
4342 else
4343 Set_Is_Valued_Procedure (Ent);
4344 end if;
4345 end if;
4346
4347 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4348
4349 -- Process Result_Mechanism argument if present. We have already
4350 -- checked that this is only allowed for the function case.
4351
4352 if Present (Arg_Result_Mechanism) then
4353 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4354 end if;
4355
4356 -- Process Mechanism parameter if present. Note that this parameter
4357 -- is not analyzed, and must not be analyzed since it is semantic
4358 -- nonsense, so we get it in exactly as the parser left it.
4359
4360 if Present (Arg_Mechanism) then
4361 declare
4362 Formal : Entity_Id;
4363 Massoc : Node_Id;
4364 Mname : Node_Id;
4365 Choice : Node_Id;
4366
4367 begin
4368 -- A single mechanism association without a formal parameter
4369 -- name is parsed as a parenthesized expression. All other
4370 -- cases are parsed as aggregates, so we rewrite the single
4371 -- parameter case as an aggregate for consistency.
4372
4373 if Nkind (Arg_Mechanism) /= N_Aggregate
4374 and then Paren_Count (Arg_Mechanism) = 1
4375 then
4376 Rewrite (Arg_Mechanism,
4377 Make_Aggregate (Sloc (Arg_Mechanism),
4378 Expressions => New_List (
4379 Relocate_Node (Arg_Mechanism))));
4380 end if;
4381
4382 -- Case of only mechanism name given, applies to all formals
4383
4384 if Nkind (Arg_Mechanism) /= N_Aggregate then
4385 Formal := First_Formal (Ent);
4386 while Present (Formal) loop
4387 Set_Mechanism_Value (Formal, Arg_Mechanism);
4388 Next_Formal (Formal);
4389 end loop;
4390
4391 -- Case of list of mechanism associations given
4392
4393 else
4394 if Null_Record_Present (Arg_Mechanism) then
4395 Error_Pragma_Arg
4396 ("inappropriate form for Mechanism parameter",
4397 Arg_Mechanism);
4398 end if;
4399
4400 -- Deal with positional ones first
4401
4402 Formal := First_Formal (Ent);
4403
4404 if Present (Expressions (Arg_Mechanism)) then
4405 Mname := First (Expressions (Arg_Mechanism));
4406 while Present (Mname) loop
4407 if No (Formal) then
4408 Error_Pragma_Arg
4409 ("too many mechanism associations", Mname);
4410 end if;
4411
4412 Set_Mechanism_Value (Formal, Mname);
4413 Next_Formal (Formal);
4414 Next (Mname);
4415 end loop;
4416 end if;
4417
4418 -- Deal with named entries
4419
4420 if Present (Component_Associations (Arg_Mechanism)) then
4421 Massoc := First (Component_Associations (Arg_Mechanism));
4422 while Present (Massoc) loop
4423 Choice := First (Choices (Massoc));
4424
4425 if Nkind (Choice) /= N_Identifier
4426 or else Present (Next (Choice))
4427 then
4428 Error_Pragma_Arg
4429 ("incorrect form for mechanism association",
4430 Massoc);
4431 end if;
4432
4433 Formal := First_Formal (Ent);
4434 loop
4435 if No (Formal) then
4436 Error_Pragma_Arg
4437 ("parameter name & not present", Choice);
4438 end if;
4439
4440 if Chars (Choice) = Chars (Formal) then
4441 Set_Mechanism_Value
4442 (Formal, Expression (Massoc));
4443
4444 -- Set entity on identifier (needed by ASIS)
4445
4446 Set_Entity (Choice, Formal);
4447
4448 exit;
4449 end if;
4450
4451 Next_Formal (Formal);
4452 end loop;
4453
4454 Next (Massoc);
4455 end loop;
4456 end if;
4457 end if;
4458 end;
4459 end if;
4460
4461 -- Process First_Optional_Parameter argument if present. We have
4462 -- already checked that this is only allowed for the Import case.
4463
4464 if Present (Arg_First_Optional_Parameter) then
4465 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4466 Error_Pragma_Arg
4467 ("first optional parameter must be formal parameter name",
4468 Arg_First_Optional_Parameter);
4469 end if;
4470
4471 Formal := First_Formal (Ent);
4472 loop
4473 if No (Formal) then
4474 Error_Pragma_Arg
4475 ("specified formal parameter& not found",
4476 Arg_First_Optional_Parameter);
4477 end if;
4478
4479 exit when Chars (Formal) =
4480 Chars (Arg_First_Optional_Parameter);
4481
4482 Next_Formal (Formal);
4483 end loop;
4484
4485 Set_First_Optional_Parameter (Ent, Formal);
4486
4487 -- Check specified and all remaining formals have right form
4488
4489 while Present (Formal) loop
4490 if Ekind (Formal) /= E_In_Parameter then
4491 Error_Msg_NE
4492 ("optional formal& is not of mode in!",
4493 Arg_First_Optional_Parameter, Formal);
4494
4495 else
4496 Dval := Default_Value (Formal);
4497
4498 if No (Dval) then
4499 Error_Msg_NE
4500 ("optional formal& does not have default value!",
4501 Arg_First_Optional_Parameter, Formal);
4502
4503 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4504 null;
4505
4506 else
4507 Error_Msg_FE
4508 ("default value for optional formal& is non-static!",
4509 Arg_First_Optional_Parameter, Formal);
4510 end if;
4511 end if;
4512
4513 Set_Is_Optional_Parameter (Formal);
4514 Next_Formal (Formal);
4515 end loop;
4516 end if;
4517 end Process_Extended_Import_Export_Subprogram_Pragma;
4518
4519 --------------------------
4520 -- Process_Generic_List --
4521 --------------------------
4522
4523 procedure Process_Generic_List is
4524 Arg : Node_Id;
4525 Exp : Node_Id;
4526
4527 begin
4528 Check_No_Identifiers;
4529 Check_At_Least_N_Arguments (1);
4530
4531 Arg := Arg1;
4532 while Present (Arg) loop
4533 Exp := Get_Pragma_Arg (Arg);
4534 Analyze (Exp);
4535
4536 if not Is_Entity_Name (Exp)
4537 or else
4538 (not Is_Generic_Instance (Entity (Exp))
4539 and then
4540 not Is_Generic_Unit (Entity (Exp)))
4541 then
4542 Error_Pragma_Arg
4543 ("pragma% argument must be name of generic unit/instance",
4544 Arg);
4545 end if;
4546
4547 Next (Arg);
4548 end loop;
4549 end Process_Generic_List;
4550
4551 ------------------------------------
4552 -- Process_Import_Predefined_Type --
4553 ------------------------------------
4554
4555 procedure Process_Import_Predefined_Type is
4556 Loc : constant Source_Ptr := Sloc (N);
4557 Elmt : Elmt_Id;
4558 Ftyp : Node_Id := Empty;
4559 Decl : Node_Id;
4560 Def : Node_Id;
4561 Nam : Name_Id;
4562
4563 begin
4564 String_To_Name_Buffer (Strval (Expression (Arg3)));
4565 Nam := Name_Find;
4566
4567 Elmt := First_Elmt (Predefined_Float_Types);
4568 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4569 Next_Elmt (Elmt);
4570 end loop;
4571
4572 Ftyp := Node (Elmt);
4573
4574 if Present (Ftyp) then
4575
4576 -- Don't build a derived type declaration, because predefined C
4577 -- types have no declaration anywhere, so cannot really be named.
4578 -- Instead build a full type declaration, starting with an
4579 -- appropriate type definition is built
4580
4581 if Is_Floating_Point_Type (Ftyp) then
4582 Def := Make_Floating_Point_Definition (Loc,
4583 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4584 Make_Real_Range_Specification (Loc,
4585 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4586 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4587
4588 -- Should never have a predefined type we cannot handle
4589
4590 else
4591 raise Program_Error;
4592 end if;
4593
4594 -- Build and insert a Full_Type_Declaration, which will be
4595 -- analyzed as soon as this list entry has been analyzed.
4596
4597 Decl := Make_Full_Type_Declaration (Loc,
4598 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4599 Type_Definition => Def);
4600
4601 Insert_After (N, Decl);
4602 Mark_Rewrite_Insertion (Decl);
4603
4604 else
4605 Error_Pragma_Arg ("no matching type found for pragma%",
4606 Arg2);
4607 end if;
4608 end Process_Import_Predefined_Type;
4609
4610 ---------------------------------
4611 -- Process_Import_Or_Interface --
4612 ---------------------------------
4613
4614 procedure Process_Import_Or_Interface is
4615 C : Convention_Id;
4616 Def_Id : Entity_Id;
4617 Hom_Id : Entity_Id;
4618
4619 begin
4620 Process_Convention (C, Def_Id);
4621 Kill_Size_Check_Code (Def_Id);
4622 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4623
4624 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4625
4626 -- We do not permit Import to apply to a renaming declaration
4627
4628 if Present (Renamed_Object (Def_Id)) then
4629 Error_Pragma_Arg
4630 ("pragma% not allowed for object renaming", Arg2);
4631
4632 -- User initialization is not allowed for imported object, but
4633 -- the object declaration may contain a default initialization,
4634 -- that will be discarded. Note that an explicit initialization
4635 -- only counts if it comes from source, otherwise it is simply
4636 -- the code generator making an implicit initialization explicit.
4637
4638 elsif Present (Expression (Parent (Def_Id)))
4639 and then Comes_From_Source (Expression (Parent (Def_Id)))
4640 then
4641 Error_Msg_Sloc := Sloc (Def_Id);
4642 Error_Pragma_Arg
4643 ("no initialization allowed for declaration of& #",
4644 "\imported entities cannot be initialized (RM B.1(24))",
4645 Arg2);
4646
4647 else
4648 Set_Imported (Def_Id);
4649 Process_Interface_Name (Def_Id, Arg3, Arg4);
4650
4651 -- Note that we do not set Is_Public here. That's because we
4652 -- only want to set it if there is no address clause, and we
4653 -- don't know that yet, so we delay that processing till
4654 -- freeze time.
4655
4656 -- pragma Import completes deferred constants
4657
4658 if Ekind (Def_Id) = E_Constant then
4659 Set_Has_Completion (Def_Id);
4660 end if;
4661
4662 -- It is not possible to import a constant of an unconstrained
4663 -- array type (e.g. string) because there is no simple way to
4664 -- write a meaningful subtype for it.
4665
4666 if Is_Array_Type (Etype (Def_Id))
4667 and then not Is_Constrained (Etype (Def_Id))
4668 then
4669 Error_Msg_NE
4670 ("imported constant& must have a constrained subtype",
4671 N, Def_Id);
4672 end if;
4673 end if;
4674
4675 elsif Is_Subprogram (Def_Id)
4676 or else Is_Generic_Subprogram (Def_Id)
4677 then
4678 -- If the name is overloaded, pragma applies to all of the denoted
4679 -- entities in the same declarative part, unless the pragma comes
4680 -- from an aspect specification.
4681
4682 Hom_Id := Def_Id;
4683 while Present (Hom_Id) loop
4684
4685 Def_Id := Get_Base_Subprogram (Hom_Id);
4686
4687 -- Ignore inherited subprograms because the pragma will apply
4688 -- to the parent operation, which is the one called.
4689
4690 if Is_Overloadable (Def_Id)
4691 and then Present (Alias (Def_Id))
4692 then
4693 null;
4694
4695 -- If it is not a subprogram, it must be in an outer scope and
4696 -- pragma does not apply.
4697
4698 elsif not Is_Subprogram (Def_Id)
4699 and then not Is_Generic_Subprogram (Def_Id)
4700 then
4701 null;
4702
4703 -- The pragma does not apply to primitives of interfaces
4704
4705 elsif Is_Dispatching_Operation (Def_Id)
4706 and then Present (Find_Dispatching_Type (Def_Id))
4707 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4708 then
4709 null;
4710
4711 -- Verify that the homonym is in the same declarative part (not
4712 -- just the same scope). If the pragma comes from an aspect
4713 -- specification we know that it is part of the declaration.
4714
4715 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4716 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4717 and then not From_Aspect_Specification (N)
4718 then
4719 exit;
4720
4721 else
4722 Set_Imported (Def_Id);
4723
4724 -- Reject an Import applied to an abstract subprogram
4725
4726 if Is_Subprogram (Def_Id)
4727 and then Is_Abstract_Subprogram (Def_Id)
4728 then
4729 Error_Msg_Sloc := Sloc (Def_Id);
4730 Error_Msg_NE
4731 ("cannot import abstract subprogram& declared#",
4732 Arg2, Def_Id);
4733 end if;
4734
4735 -- Special processing for Convention_Intrinsic
4736
4737 if C = Convention_Intrinsic then
4738
4739 -- Link_Name argument not allowed for intrinsic
4740
4741 Check_No_Link_Name;
4742
4743 Set_Is_Intrinsic_Subprogram (Def_Id);
4744
4745 -- If no external name is present, then check that this
4746 -- is a valid intrinsic subprogram. If an external name
4747 -- is present, then this is handled by the back end.
4748
4749 if No (Arg3) then
4750 Check_Intrinsic_Subprogram
4751 (Def_Id, Get_Pragma_Arg (Arg2));
4752 end if;
4753 end if;
4754
4755 -- All interfaced procedures need an external symbol created
4756 -- for them since they are always referenced from another
4757 -- object file.
4758
4759 Set_Is_Public (Def_Id);
4760
4761 -- Verify that the subprogram does not have a completion
4762 -- through a renaming declaration. For other completions the
4763 -- pragma appears as a too late representation.
4764
4765 declare
4766 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4767
4768 begin
4769 if Present (Decl)
4770 and then Nkind (Decl) = N_Subprogram_Declaration
4771 and then Present (Corresponding_Body (Decl))
4772 and then Nkind (Unit_Declaration_Node
4773 (Corresponding_Body (Decl))) =
4774 N_Subprogram_Renaming_Declaration
4775 then
4776 Error_Msg_Sloc := Sloc (Def_Id);
4777 Error_Msg_NE
4778 ("cannot import&, renaming already provided for " &
4779 "declaration #", N, Def_Id);
4780 end if;
4781 end;
4782
4783 Set_Has_Completion (Def_Id);
4784 Process_Interface_Name (Def_Id, Arg3, Arg4);
4785 end if;
4786
4787 if Is_Compilation_Unit (Hom_Id) then
4788
4789 -- Its possible homonyms are not affected by the pragma.
4790 -- Such homonyms might be present in the context of other
4791 -- units being compiled.
4792
4793 exit;
4794
4795 elsif From_Aspect_Specification (N) then
4796 exit;
4797
4798 else
4799 Hom_Id := Homonym (Hom_Id);
4800 end if;
4801 end loop;
4802
4803 -- When the convention is Java or CIL, we also allow Import to be
4804 -- given for packages, generic packages, exceptions, record
4805 -- components, and access to subprograms.
4806
4807 elsif (C = Convention_Java or else C = Convention_CIL)
4808 and then
4809 (Is_Package_Or_Generic_Package (Def_Id)
4810 or else Ekind (Def_Id) = E_Exception
4811 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4812 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4813 then
4814 Set_Imported (Def_Id);
4815 Set_Is_Public (Def_Id);
4816 Process_Interface_Name (Def_Id, Arg3, Arg4);
4817
4818 -- Import a CPP class
4819
4820 elsif C = Convention_CPP
4821 and then (Is_Record_Type (Def_Id)
4822 or else Ekind (Def_Id) = E_Incomplete_Type)
4823 then
4824 if Ekind (Def_Id) = E_Incomplete_Type then
4825 if Present (Full_View (Def_Id)) then
4826 Def_Id := Full_View (Def_Id);
4827
4828 else
4829 Error_Msg_N
4830 ("cannot import 'C'P'P type before full declaration seen",
4831 Get_Pragma_Arg (Arg2));
4832
4833 -- Although we have reported the error we decorate it as
4834 -- CPP_Class to avoid reporting spurious errors
4835
4836 Set_Is_CPP_Class (Def_Id);
4837 return;
4838 end if;
4839 end if;
4840
4841 -- Types treated as CPP classes must be declared limited (note:
4842 -- this used to be a warning but there is no real benefit to it
4843 -- since we did effectively intend to treat the type as limited
4844 -- anyway).
4845
4846 if not Is_Limited_Type (Def_Id) then
4847 Error_Msg_N
4848 ("imported 'C'P'P type must be limited",
4849 Get_Pragma_Arg (Arg2));
4850 end if;
4851
4852 if Etype (Def_Id) /= Def_Id
4853 and then not Is_CPP_Class (Root_Type (Def_Id))
4854 then
4855 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
4856 end if;
4857
4858 Set_Is_CPP_Class (Def_Id);
4859
4860 -- Imported CPP types must not have discriminants (because C++
4861 -- classes do not have discriminants).
4862
4863 if Has_Discriminants (Def_Id) then
4864 Error_Msg_N
4865 ("imported 'C'P'P type cannot have discriminants",
4866 First (Discriminant_Specifications
4867 (Declaration_Node (Def_Id))));
4868 end if;
4869
4870 -- Check that components of imported CPP types do not have default
4871 -- expressions. For private types this check is performed when the
4872 -- full view is analyzed (see Process_Full_View).
4873
4874 if not Is_Private_Type (Def_Id) then
4875 Check_CPP_Type_Has_No_Defaults (Def_Id);
4876 end if;
4877
4878 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4879 Check_No_Link_Name;
4880 Check_Arg_Count (3);
4881 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4882
4883 Process_Import_Predefined_Type;
4884
4885 else
4886 Error_Pragma_Arg
4887 ("second argument of pragma% must be object, subprogram "
4888 & "or incomplete type",
4889 Arg2);
4890 end if;
4891
4892 -- If this pragma applies to a compilation unit, then the unit, which
4893 -- is a subprogram, does not require (or allow) a body. We also do
4894 -- not need to elaborate imported procedures.
4895
4896 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4897 declare
4898 Cunit : constant Node_Id := Parent (Parent (N));
4899 begin
4900 Set_Body_Required (Cunit, False);
4901 end;
4902 end if;
4903 end Process_Import_Or_Interface;
4904
4905 --------------------
4906 -- Process_Inline --
4907 --------------------
4908
4909 procedure Process_Inline (Active : Boolean) is
4910 Assoc : Node_Id;
4911 Decl : Node_Id;
4912 Subp_Id : Node_Id;
4913 Subp : Entity_Id;
4914 Applies : Boolean;
4915
4916 Effective : Boolean := False;
4917 -- Set True if inline has some effect, i.e. if there is at least one
4918 -- subprogram set as inlined as a result of the use of the pragma.
4919
4920 procedure Make_Inline (Subp : Entity_Id);
4921 -- Subp is the defining unit name of the subprogram declaration. Set
4922 -- the flag, as well as the flag in the corresponding body, if there
4923 -- is one present.
4924
4925 procedure Set_Inline_Flags (Subp : Entity_Id);
4926 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4927 -- Has_Pragma_Inline_Always for the Inline_Always case.
4928
4929 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4930 -- Returns True if it can be determined at this stage that inlining
4931 -- is not possible, for example if the body is available and contains
4932 -- exception handlers, we prevent inlining, since otherwise we can
4933 -- get undefined symbols at link time. This function also emits a
4934 -- warning if front-end inlining is enabled and the pragma appears
4935 -- too late.
4936 --
4937 -- ??? is business with link symbols still valid, or does it relate
4938 -- to front end ZCX which is being phased out ???
4939
4940 ---------------------------
4941 -- Inlining_Not_Possible --
4942 ---------------------------
4943
4944 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4945 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4946 Stats : Node_Id;
4947
4948 begin
4949 if Nkind (Decl) = N_Subprogram_Body then
4950 Stats := Handled_Statement_Sequence (Decl);
4951 return Present (Exception_Handlers (Stats))
4952 or else Present (At_End_Proc (Stats));
4953
4954 elsif Nkind (Decl) = N_Subprogram_Declaration
4955 and then Present (Corresponding_Body (Decl))
4956 then
4957 if Front_End_Inlining
4958 and then Analyzed (Corresponding_Body (Decl))
4959 then
4960 Error_Msg_N ("pragma appears too late, ignored?", N);
4961 return True;
4962
4963 -- If the subprogram is a renaming as body, the body is just a
4964 -- call to the renamed subprogram, and inlining is trivially
4965 -- possible.
4966
4967 elsif
4968 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4969 N_Subprogram_Renaming_Declaration
4970 then
4971 return False;
4972
4973 else
4974 Stats :=
4975 Handled_Statement_Sequence
4976 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4977
4978 return
4979 Present (Exception_Handlers (Stats))
4980 or else Present (At_End_Proc (Stats));
4981 end if;
4982
4983 else
4984 -- If body is not available, assume the best, the check is
4985 -- performed again when compiling enclosing package bodies.
4986
4987 return False;
4988 end if;
4989 end Inlining_Not_Possible;
4990
4991 -----------------
4992 -- Make_Inline --
4993 -----------------
4994
4995 procedure Make_Inline (Subp : Entity_Id) is
4996 Kind : constant Entity_Kind := Ekind (Subp);
4997 Inner_Subp : Entity_Id := Subp;
4998
4999 begin
5000 -- Ignore if bad type, avoid cascaded error
5001
5002 if Etype (Subp) = Any_Type then
5003 Applies := True;
5004 return;
5005
5006 -- Ignore if all inlining is suppressed
5007
5008 elsif Suppress_All_Inlining then
5009 Applies := True;
5010 return;
5011
5012 -- If inlining is not possible, for now do not treat as an error
5013
5014 elsif Inlining_Not_Possible (Subp) then
5015 Applies := True;
5016 return;
5017
5018 -- Here we have a candidate for inlining, but we must exclude
5019 -- derived operations. Otherwise we would end up trying to inline
5020 -- a phantom declaration, and the result would be to drag in a
5021 -- body which has no direct inlining associated with it. That
5022 -- would not only be inefficient but would also result in the
5023 -- backend doing cross-unit inlining in cases where it was
5024 -- definitely inappropriate to do so.
5025
5026 -- However, a simple Comes_From_Source test is insufficient, since
5027 -- we do want to allow inlining of generic instances which also do
5028 -- not come from source. We also need to recognize specs generated
5029 -- by the front-end for bodies that carry the pragma. Finally,
5030 -- predefined operators do not come from source but are not
5031 -- inlineable either.
5032
5033 elsif Is_Generic_Instance (Subp)
5034 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
5035 then
5036 null;
5037
5038 elsif not Comes_From_Source (Subp)
5039 and then Scope (Subp) /= Standard_Standard
5040 then
5041 Applies := True;
5042 return;
5043 end if;
5044
5045 -- The referenced entity must either be the enclosing entity, or
5046 -- an entity declared within the current open scope.
5047
5048 if Present (Scope (Subp))
5049 and then Scope (Subp) /= Current_Scope
5050 and then Subp /= Current_Scope
5051 then
5052 Error_Pragma_Arg
5053 ("argument of% must be entity in current scope", Assoc);
5054 return;
5055 end if;
5056
5057 -- Processing for procedure, operator or function. If subprogram
5058 -- is aliased (as for an instance) indicate that the renamed
5059 -- entity (if declared in the same unit) is inlined.
5060
5061 if Is_Subprogram (Subp) then
5062 Inner_Subp := Ultimate_Alias (Inner_Subp);
5063
5064 if In_Same_Source_Unit (Subp, Inner_Subp) then
5065 Set_Inline_Flags (Inner_Subp);
5066
5067 Decl := Parent (Parent (Inner_Subp));
5068
5069 if Nkind (Decl) = N_Subprogram_Declaration
5070 and then Present (Corresponding_Body (Decl))
5071 then
5072 Set_Inline_Flags (Corresponding_Body (Decl));
5073
5074 elsif Is_Generic_Instance (Subp) then
5075
5076 -- Indicate that the body needs to be created for
5077 -- inlining subsequent calls. The instantiation node
5078 -- follows the declaration of the wrapper package
5079 -- created for it.
5080
5081 if Scope (Subp) /= Standard_Standard
5082 and then
5083 Need_Subprogram_Instance_Body
5084 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
5085 Subp)
5086 then
5087 null;
5088 end if;
5089
5090 -- Inline is a program unit pragma (RM 10.1.5) and cannot
5091 -- appear in a formal part to apply to a formal subprogram.
5092 -- Do not apply check within an instance or a formal package
5093 -- the test will have been applied to the original generic.
5094
5095 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
5096 and then List_Containing (Decl) = List_Containing (N)
5097 and then not In_Instance
5098 then
5099 Error_Msg_N
5100 ("Inline cannot apply to a formal subprogram", N);
5101
5102 -- If Subp is a renaming, it is the renamed entity that
5103 -- will appear in any call, and be inlined. However, for
5104 -- ASIS uses it is convenient to indicate that the renaming
5105 -- itself is an inlined subprogram, so that some gnatcheck
5106 -- rules can be applied in the absence of expansion.
5107
5108 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
5109 Set_Inline_Flags (Subp);
5110 end if;
5111 end if;
5112
5113 Applies := True;
5114
5115 -- For a generic subprogram set flag as well, for use at the point
5116 -- of instantiation, to determine whether the body should be
5117 -- generated.
5118
5119 elsif Is_Generic_Subprogram (Subp) then
5120 Set_Inline_Flags (Subp);
5121 Applies := True;
5122
5123 -- Literals are by definition inlined
5124
5125 elsif Kind = E_Enumeration_Literal then
5126 null;
5127
5128 -- Anything else is an error
5129
5130 else
5131 Error_Pragma_Arg
5132 ("expect subprogram name for pragma%", Assoc);
5133 end if;
5134 end Make_Inline;
5135
5136 ----------------------
5137 -- Set_Inline_Flags --
5138 ----------------------
5139
5140 procedure Set_Inline_Flags (Subp : Entity_Id) is
5141 begin
5142 if Active then
5143 Set_Is_Inlined (Subp);
5144 end if;
5145
5146 if not Has_Pragma_Inline (Subp) then
5147 Set_Has_Pragma_Inline (Subp);
5148 Effective := True;
5149 end if;
5150
5151 if Prag_Id = Pragma_Inline_Always then
5152 Set_Has_Pragma_Inline_Always (Subp);
5153 end if;
5154 end Set_Inline_Flags;
5155
5156 -- Start of processing for Process_Inline
5157
5158 begin
5159 Check_No_Identifiers;
5160 Check_At_Least_N_Arguments (1);
5161
5162 if Active then
5163 Inline_Processing_Required := True;
5164 end if;
5165
5166 Assoc := Arg1;
5167 while Present (Assoc) loop
5168 Subp_Id := Get_Pragma_Arg (Assoc);
5169 Analyze (Subp_Id);
5170 Applies := False;
5171
5172 if Is_Entity_Name (Subp_Id) then
5173 Subp := Entity (Subp_Id);
5174
5175 if Subp = Any_Id then
5176
5177 -- If previous error, avoid cascaded errors
5178
5179 Check_Error_Detected;
5180 Applies := True;
5181 Effective := True;
5182
5183 else
5184 Make_Inline (Subp);
5185
5186 -- For the pragma case, climb homonym chain. This is
5187 -- what implements allowing the pragma in the renaming
5188 -- case, with the result applying to the ancestors, and
5189 -- also allows Inline to apply to all previous homonyms.
5190
5191 if not From_Aspect_Specification (N) then
5192 while Present (Homonym (Subp))
5193 and then Scope (Homonym (Subp)) = Current_Scope
5194 loop
5195 Make_Inline (Homonym (Subp));
5196 Subp := Homonym (Subp);
5197 end loop;
5198 end if;
5199 end if;
5200 end if;
5201
5202 if not Applies then
5203 Error_Pragma_Arg
5204 ("inappropriate argument for pragma%", Assoc);
5205
5206 elsif not Effective
5207 and then Warn_On_Redundant_Constructs
5208 and then not Suppress_All_Inlining
5209 then
5210 if Inlining_Not_Possible (Subp) then
5211 Error_Msg_NE
5212 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
5213 else
5214 Error_Msg_NE
5215 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
5216 end if;
5217 end if;
5218
5219 Next (Assoc);
5220 end loop;
5221 end Process_Inline;
5222
5223 ----------------------------
5224 -- Process_Interface_Name --
5225 ----------------------------
5226
5227 procedure Process_Interface_Name
5228 (Subprogram_Def : Entity_Id;
5229 Ext_Arg : Node_Id;
5230 Link_Arg : Node_Id)
5231 is
5232 Ext_Nam : Node_Id;
5233 Link_Nam : Node_Id;
5234 String_Val : String_Id;
5235
5236 procedure Check_Form_Of_Interface_Name
5237 (SN : Node_Id;
5238 Ext_Name_Case : Boolean);
5239 -- SN is a string literal node for an interface name. This routine
5240 -- performs some minimal checks that the name is reasonable. In
5241 -- particular that no spaces or other obviously incorrect characters
5242 -- appear. This is only a warning, since any characters are allowed.
5243 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
5244
5245 ----------------------------------
5246 -- Check_Form_Of_Interface_Name --
5247 ----------------------------------
5248
5249 procedure Check_Form_Of_Interface_Name
5250 (SN : Node_Id;
5251 Ext_Name_Case : Boolean)
5252 is
5253 S : constant String_Id := Strval (Expr_Value_S (SN));
5254 SL : constant Nat := String_Length (S);
5255 C : Char_Code;
5256
5257 begin
5258 if SL = 0 then
5259 Error_Msg_N ("interface name cannot be null string", SN);
5260 end if;
5261
5262 for J in 1 .. SL loop
5263 C := Get_String_Char (S, J);
5264
5265 -- Look for dubious character and issue unconditional warning.
5266 -- Definitely dubious if not in character range.
5267
5268 if not In_Character_Range (C)
5269
5270 -- For all cases except CLI target,
5271 -- commas, spaces and slashes are dubious (in CLI, we use
5272 -- commas and backslashes in external names to specify
5273 -- assembly version and public key, while slashes and spaces
5274 -- can be used in names to mark nested classes and
5275 -- valuetypes).
5276
5277 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5278 and then (Get_Character (C) = ','
5279 or else
5280 Get_Character (C) = '\'))
5281 or else (VM_Target /= CLI_Target
5282 and then (Get_Character (C) = ' '
5283 or else
5284 Get_Character (C) = '/'))
5285 then
5286 Error_Msg
5287 ("?interface name contains illegal character",
5288 Sloc (SN) + Source_Ptr (J));
5289 end if;
5290 end loop;
5291 end Check_Form_Of_Interface_Name;
5292
5293 -- Start of processing for Process_Interface_Name
5294
5295 begin
5296 if No (Link_Arg) then
5297 if No (Ext_Arg) then
5298 if VM_Target = CLI_Target
5299 and then Ekind (Subprogram_Def) = E_Package
5300 and then Nkind (Parent (Subprogram_Def)) =
5301 N_Package_Specification
5302 and then Present (Generic_Parent (Parent (Subprogram_Def)))
5303 then
5304 Set_Interface_Name
5305 (Subprogram_Def,
5306 Interface_Name
5307 (Generic_Parent (Parent (Subprogram_Def))));
5308 end if;
5309
5310 return;
5311
5312 elsif Chars (Ext_Arg) = Name_Link_Name then
5313 Ext_Nam := Empty;
5314 Link_Nam := Expression (Ext_Arg);
5315
5316 else
5317 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5318 Ext_Nam := Expression (Ext_Arg);
5319 Link_Nam := Empty;
5320 end if;
5321
5322 else
5323 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5324 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5325 Ext_Nam := Expression (Ext_Arg);
5326 Link_Nam := Expression (Link_Arg);
5327 end if;
5328
5329 -- Check expressions for external name and link name are static
5330
5331 if Present (Ext_Nam) then
5332 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5333 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5334
5335 -- Verify that external name is not the name of a local entity,
5336 -- which would hide the imported one and could lead to run-time
5337 -- surprises. The problem can only arise for entities declared in
5338 -- a package body (otherwise the external name is fully qualified
5339 -- and will not conflict).
5340
5341 declare
5342 Nam : Name_Id;
5343 E : Entity_Id;
5344 Par : Node_Id;
5345
5346 begin
5347 if Prag_Id = Pragma_Import then
5348 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5349 Nam := Name_Find;
5350 E := Entity_Id (Get_Name_Table_Info (Nam));
5351
5352 if Nam /= Chars (Subprogram_Def)
5353 and then Present (E)
5354 and then not Is_Overloadable (E)
5355 and then Is_Immediately_Visible (E)
5356 and then not Is_Imported (E)
5357 and then Ekind (Scope (E)) = E_Package
5358 then
5359 Par := Parent (E);
5360 while Present (Par) loop
5361 if Nkind (Par) = N_Package_Body then
5362 Error_Msg_Sloc := Sloc (E);
5363 Error_Msg_NE
5364 ("imported entity is hidden by & declared#",
5365 Ext_Arg, E);
5366 exit;
5367 end if;
5368
5369 Par := Parent (Par);
5370 end loop;
5371 end if;
5372 end if;
5373 end;
5374 end if;
5375
5376 if Present (Link_Nam) then
5377 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5378 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5379 end if;
5380
5381 -- If there is no link name, just set the external name
5382
5383 if No (Link_Nam) then
5384 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5385
5386 -- For the Link_Name case, the given literal is preceded by an
5387 -- asterisk, which indicates to GCC that the given name should be
5388 -- taken literally, and in particular that no prepending of
5389 -- underlines should occur, even in systems where this is the
5390 -- normal default.
5391
5392 else
5393 Start_String;
5394
5395 if VM_Target = No_VM then
5396 Store_String_Char (Get_Char_Code ('*'));
5397 end if;
5398
5399 String_Val := Strval (Expr_Value_S (Link_Nam));
5400 Store_String_Chars (String_Val);
5401 Link_Nam :=
5402 Make_String_Literal (Sloc (Link_Nam),
5403 Strval => End_String);
5404 end if;
5405
5406 -- Set the interface name. If the entity is a generic instance, use
5407 -- its alias, which is the callable entity.
5408
5409 if Is_Generic_Instance (Subprogram_Def) then
5410 Set_Encoded_Interface_Name
5411 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5412 else
5413 Set_Encoded_Interface_Name
5414 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5415 end if;
5416
5417 -- We allow duplicated export names in CIL/Java, as they are always
5418 -- enclosed in a namespace that differentiates them, and overloaded
5419 -- entities are supported by the VM.
5420
5421 if Convention (Subprogram_Def) /= Convention_CIL
5422 and then
5423 Convention (Subprogram_Def) /= Convention_Java
5424 then
5425 Check_Duplicated_Export_Name (Link_Nam);
5426 end if;
5427 end Process_Interface_Name;
5428
5429 -----------------------------------------
5430 -- Process_Interrupt_Or_Attach_Handler --
5431 -----------------------------------------
5432
5433 procedure Process_Interrupt_Or_Attach_Handler is
5434 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5435 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5436 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
5437
5438 begin
5439 Set_Is_Interrupt_Handler (Handler_Proc);
5440
5441 -- If the pragma is not associated with a handler procedure within a
5442 -- protected type, then it must be for a nonprotected procedure for
5443 -- the AAMP target, in which case we don't associate a representation
5444 -- item with the procedure's scope.
5445
5446 if Ekind (Proc_Scope) = E_Protected_Type then
5447 if Prag_Id = Pragma_Interrupt_Handler
5448 or else
5449 Prag_Id = Pragma_Attach_Handler
5450 then
5451 Record_Rep_Item (Proc_Scope, N);
5452 end if;
5453 end if;
5454 end Process_Interrupt_Or_Attach_Handler;
5455
5456 --------------------------------------------------
5457 -- Process_Restrictions_Or_Restriction_Warnings --
5458 --------------------------------------------------
5459
5460 -- Note: some of the simple identifier cases were handled in par-prag,
5461 -- but it is harmless (and more straightforward) to simply handle all
5462 -- cases here, even if it means we repeat a bit of work in some cases.
5463
5464 procedure Process_Restrictions_Or_Restriction_Warnings
5465 (Warn : Boolean)
5466 is
5467 Arg : Node_Id;
5468 R_Id : Restriction_Id;
5469 Id : Name_Id;
5470 Expr : Node_Id;
5471 Val : Uint;
5472
5473 procedure Check_Unit_Name (N : Node_Id);
5474 -- Checks unit name parameter for No_Dependence. Returns if it has
5475 -- an appropriate form, otherwise raises pragma argument error.
5476
5477 ---------------------
5478 -- Check_Unit_Name --
5479 ---------------------
5480
5481 procedure Check_Unit_Name (N : Node_Id) is
5482 begin
5483 if Nkind (N) = N_Selected_Component then
5484 Check_Unit_Name (Prefix (N));
5485 Check_Unit_Name (Selector_Name (N));
5486
5487 elsif Nkind (N) = N_Identifier then
5488 return;
5489
5490 else
5491 Error_Pragma_Arg
5492 ("wrong form for unit name for No_Dependence", N);
5493 end if;
5494 end Check_Unit_Name;
5495
5496 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5497
5498 begin
5499 -- Ignore all Restrictions pragma in CodePeer mode
5500
5501 if CodePeer_Mode then
5502 return;
5503 end if;
5504
5505 Check_Ada_83_Warning;
5506 Check_At_Least_N_Arguments (1);
5507 Check_Valid_Configuration_Pragma;
5508
5509 Arg := Arg1;
5510 while Present (Arg) loop
5511 Id := Chars (Arg);
5512 Expr := Get_Pragma_Arg (Arg);
5513
5514 -- Case of no restriction identifier present
5515
5516 if Id = No_Name then
5517 if Nkind (Expr) /= N_Identifier then
5518 Error_Pragma_Arg
5519 ("invalid form for restriction", Arg);
5520 end if;
5521
5522 R_Id :=
5523 Get_Restriction_Id
5524 (Process_Restriction_Synonyms (Expr));
5525
5526 if R_Id not in All_Boolean_Restrictions then
5527 Error_Msg_Name_1 := Pname;
5528 Error_Msg_N
5529 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5530
5531 -- Check for possible misspelling
5532
5533 for J in Restriction_Id loop
5534 declare
5535 Rnm : constant String := Restriction_Id'Image (J);
5536
5537 begin
5538 Name_Buffer (1 .. Rnm'Length) := Rnm;
5539 Name_Len := Rnm'Length;
5540 Set_Casing (All_Lower_Case);
5541
5542 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5543 Set_Casing
5544 (Identifier_Casing (Current_Source_File));
5545 Error_Msg_String (1 .. Rnm'Length) :=
5546 Name_Buffer (1 .. Name_Len);
5547 Error_Msg_Strlen := Rnm'Length;
5548 Error_Msg_N -- CODEFIX
5549 ("\possible misspelling of ""~""",
5550 Get_Pragma_Arg (Arg));
5551 exit;
5552 end if;
5553 end;
5554 end loop;
5555
5556 raise Pragma_Exit;
5557 end if;
5558
5559 if Implementation_Restriction (R_Id) then
5560 Check_Restriction (No_Implementation_Restrictions, Arg);
5561 end if;
5562
5563 -- Special processing for No_Elaboration_Code restriction
5564
5565 if R_Id = No_Elaboration_Code then
5566
5567 -- Restriction is only recognized within a configuration
5568 -- pragma file, or within a unit of the main extended
5569 -- program. Note: the test for Main_Unit is needed to
5570 -- properly include the case of configuration pragma files.
5571
5572 if not (Current_Sem_Unit = Main_Unit
5573 or else In_Extended_Main_Source_Unit (N))
5574 then
5575 return;
5576
5577 -- Don't allow in a subunit unless already specified in
5578 -- body or spec.
5579
5580 elsif Nkind (Parent (N)) = N_Compilation_Unit
5581 and then Nkind (Unit (Parent (N))) = N_Subunit
5582 and then not Restriction_Active (No_Elaboration_Code)
5583 then
5584 Error_Msg_N
5585 ("invalid specification of ""No_Elaboration_Code""",
5586 N);
5587 Error_Msg_N
5588 ("\restriction cannot be specified in a subunit", N);
5589 Error_Msg_N
5590 ("\unless also specified in body or spec", N);
5591 return;
5592
5593 -- If we have a No_Elaboration_Code pragma that we
5594 -- accept, then it needs to be added to the configuration
5595 -- restrcition set so that we get proper application to
5596 -- other units in the main extended source as required.
5597
5598 else
5599 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
5600 end if;
5601 end if;
5602
5603 -- If this is a warning, then set the warning unless we already
5604 -- have a real restriction active (we never want a warning to
5605 -- override a real restriction).
5606
5607 if Warn then
5608 if not Restriction_Active (R_Id) then
5609 Set_Restriction (R_Id, N);
5610 Restriction_Warnings (R_Id) := True;
5611 end if;
5612
5613 -- If real restriction case, then set it and make sure that the
5614 -- restriction warning flag is off, since a real restriction
5615 -- always overrides a warning.
5616
5617 else
5618 Set_Restriction (R_Id, N);
5619 Restriction_Warnings (R_Id) := False;
5620 end if;
5621
5622 -- Check for obsolescent restrictions in Ada 2005 mode
5623
5624 if not Warn
5625 and then Ada_Version >= Ada_2005
5626 and then (R_Id = No_Asynchronous_Control
5627 or else
5628 R_Id = No_Unchecked_Deallocation
5629 or else
5630 R_Id = No_Unchecked_Conversion)
5631 then
5632 Check_Restriction (No_Obsolescent_Features, N);
5633 end if;
5634
5635 -- A very special case that must be processed here: pragma
5636 -- Restrictions (No_Exceptions) turns off all run-time
5637 -- checking. This is a bit dubious in terms of the formal
5638 -- language definition, but it is what is intended by RM
5639 -- H.4(12). Restriction_Warnings never affects generated code
5640 -- so this is done only in the real restriction case.
5641
5642 -- Atomic_Synchronization is not a real check, so it is not
5643 -- affected by this processing).
5644
5645 if R_Id = No_Exceptions and then not Warn then
5646 for J in Scope_Suppress.Suppress'Range loop
5647 if J /= Atomic_Synchronization then
5648 Scope_Suppress.Suppress (J) := True;
5649 end if;
5650 end loop;
5651 end if;
5652
5653 -- Case of No_Dependence => unit-name. Note that the parser
5654 -- already made the necessary entry in the No_Dependence table.
5655
5656 elsif Id = Name_No_Dependence then
5657 Check_Unit_Name (Expr);
5658
5659 -- Case of No_Specification_Of_Aspect => Identifier.
5660
5661 elsif Id = Name_No_Specification_Of_Aspect then
5662 declare
5663 A_Id : Aspect_Id;
5664
5665 begin
5666 if Nkind (Expr) /= N_Identifier then
5667 A_Id := No_Aspect;
5668 else
5669 A_Id := Get_Aspect_Id (Chars (Expr));
5670 end if;
5671
5672 if A_Id = No_Aspect then
5673 Error_Pragma_Arg ("invalid restriction name", Arg);
5674 else
5675 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5676 end if;
5677 end;
5678
5679 -- All other cases of restriction identifier present
5680
5681 else
5682 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5683 Analyze_And_Resolve (Expr, Any_Integer);
5684
5685 if R_Id not in All_Parameter_Restrictions then
5686 Error_Pragma_Arg
5687 ("invalid restriction parameter identifier", Arg);
5688
5689 elsif not Is_OK_Static_Expression (Expr) then
5690 Flag_Non_Static_Expr
5691 ("value must be static expression!", Expr);
5692 raise Pragma_Exit;
5693
5694 elsif not Is_Integer_Type (Etype (Expr))
5695 or else Expr_Value (Expr) < 0
5696 then
5697 Error_Pragma_Arg
5698 ("value must be non-negative integer", Arg);
5699 end if;
5700
5701 -- Restriction pragma is active
5702
5703 Val := Expr_Value (Expr);
5704
5705 if not UI_Is_In_Int_Range (Val) then
5706 Error_Pragma_Arg
5707 ("pragma ignored, value too large?", Arg);
5708 end if;
5709
5710 -- Warning case. If the real restriction is active, then we
5711 -- ignore the request, since warning never overrides a real
5712 -- restriction. Otherwise we set the proper warning. Note that
5713 -- this circuit sets the warning again if it is already set,
5714 -- which is what we want, since the constant may have changed.
5715
5716 if Warn then
5717 if not Restriction_Active (R_Id) then
5718 Set_Restriction
5719 (R_Id, N, Integer (UI_To_Int (Val)));
5720 Restriction_Warnings (R_Id) := True;
5721 end if;
5722
5723 -- Real restriction case, set restriction and make sure warning
5724 -- flag is off since real restriction always overrides warning.
5725
5726 else
5727 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5728 Restriction_Warnings (R_Id) := False;
5729 end if;
5730 end if;
5731
5732 Next (Arg);
5733 end loop;
5734 end Process_Restrictions_Or_Restriction_Warnings;
5735
5736 ---------------------------------
5737 -- Process_Suppress_Unsuppress --
5738 ---------------------------------
5739
5740 -- Note: this procedure makes entries in the check suppress data
5741 -- structures managed by Sem. See spec of package Sem for full
5742 -- details on how we handle recording of check suppression.
5743
5744 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5745 C : Check_Id;
5746 E_Id : Node_Id;
5747 E : Entity_Id;
5748
5749 In_Package_Spec : constant Boolean :=
5750 Is_Package_Or_Generic_Package (Current_Scope)
5751 and then not In_Package_Body (Current_Scope);
5752
5753 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5754 -- Used to suppress a single check on the given entity
5755
5756 --------------------------------
5757 -- Suppress_Unsuppress_Echeck --
5758 --------------------------------
5759
5760 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5761 begin
5762 -- Check for error of trying to set atomic synchronization for
5763 -- a non-atomic variable.
5764
5765 if C = Atomic_Synchronization
5766 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5767 then
5768 Error_Msg_N
5769 ("pragma & requires atomic type or variable",
5770 Pragma_Identifier (Original_Node (N)));
5771 end if;
5772
5773 Set_Checks_May_Be_Suppressed (E);
5774
5775 if In_Package_Spec then
5776 Push_Global_Suppress_Stack_Entry
5777 (Entity => E,
5778 Check => C,
5779 Suppress => Suppress_Case);
5780 else
5781 Push_Local_Suppress_Stack_Entry
5782 (Entity => E,
5783 Check => C,
5784 Suppress => Suppress_Case);
5785 end if;
5786
5787 -- If this is a first subtype, and the base type is distinct,
5788 -- then also set the suppress flags on the base type.
5789
5790 if Is_First_Subtype (E) and then Etype (E) /= E then
5791 Suppress_Unsuppress_Echeck (Etype (E), C);
5792 end if;
5793 end Suppress_Unsuppress_Echeck;
5794
5795 -- Start of processing for Process_Suppress_Unsuppress
5796
5797 begin
5798 -- Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5799 -- user code: we want to generate checks for analysis purposes, as
5800 -- set respectively by -gnatC and -gnatd.F
5801
5802 if (CodePeer_Mode or Alfa_Mode) and then Comes_From_Source (N) then
5803 return;
5804 end if;
5805
5806 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5807 -- declarative part or a package spec (RM 11.5(5)).
5808
5809 if not Is_Configuration_Pragma then
5810 Check_Is_In_Decl_Part_Or_Package_Spec;
5811 end if;
5812
5813 Check_At_Least_N_Arguments (1);
5814 Check_At_Most_N_Arguments (2);
5815 Check_No_Identifier (Arg1);
5816 Check_Arg_Is_Identifier (Arg1);
5817
5818 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5819
5820 if C = No_Check_Id then
5821 Error_Pragma_Arg
5822 ("argument of pragma% is not valid check name", Arg1);
5823 end if;
5824
5825 if Arg_Count = 1 then
5826
5827 -- Make an entry in the local scope suppress table. This is the
5828 -- table that directly shows the current value of the scope
5829 -- suppress check for any check id value.
5830
5831 if C = All_Checks then
5832
5833 -- For All_Checks, we set all specific predefined checks with
5834 -- the exception of Elaboration_Check, which is handled
5835 -- specially because of not wanting All_Checks to have the
5836 -- effect of deactivating static elaboration order processing.
5837 -- Atomic_Synchronization is also not affected, since this is
5838 -- not a real check.
5839
5840 for J in Scope_Suppress.Suppress'Range loop
5841 if J /= Elaboration_Check
5842 and then
5843 J /= Atomic_Synchronization
5844 then
5845 Scope_Suppress.Suppress (J) := Suppress_Case;
5846 end if;
5847 end loop;
5848
5849 -- If not All_Checks, and predefined check, then set appropriate
5850 -- scope entry. Note that we will set Elaboration_Check if this
5851 -- is explicitly specified. Atomic_Synchronization is allowed
5852 -- only if internally generated and entity is atomic.
5853
5854 elsif C in Predefined_Check_Id
5855 and then (not Comes_From_Source (N)
5856 or else C /= Atomic_Synchronization)
5857 then
5858 Scope_Suppress.Suppress (C) := Suppress_Case;
5859 end if;
5860
5861 -- Also make an entry in the Local_Entity_Suppress table
5862
5863 Push_Local_Suppress_Stack_Entry
5864 (Entity => Empty,
5865 Check => C,
5866 Suppress => Suppress_Case);
5867
5868 -- Case of two arguments present, where the check is suppressed for
5869 -- a specified entity (given as the second argument of the pragma)
5870
5871 else
5872 -- This is obsolescent in Ada 2005 mode
5873
5874 if Ada_Version >= Ada_2005 then
5875 Check_Restriction (No_Obsolescent_Features, Arg2);
5876 end if;
5877
5878 Check_Optional_Identifier (Arg2, Name_On);
5879 E_Id := Get_Pragma_Arg (Arg2);
5880 Analyze (E_Id);
5881
5882 if not Is_Entity_Name (E_Id) then
5883 Error_Pragma_Arg
5884 ("second argument of pragma% must be entity name", Arg2);
5885 end if;
5886
5887 E := Entity (E_Id);
5888
5889 if E = Any_Id then
5890 return;
5891 end if;
5892
5893 -- Enforce RM 11.5(7) which requires that for a pragma that
5894 -- appears within a package spec, the named entity must be
5895 -- within the package spec. We allow the package name itself
5896 -- to be mentioned since that makes sense, although it is not
5897 -- strictly allowed by 11.5(7).
5898
5899 if In_Package_Spec
5900 and then E /= Current_Scope
5901 and then Scope (E) /= Current_Scope
5902 then
5903 Error_Pragma_Arg
5904 ("entity in pragma% is not in package spec (RM 11.5(7))",
5905 Arg2);
5906 end if;
5907
5908 -- Loop through homonyms. As noted below, in the case of a package
5909 -- spec, only homonyms within the package spec are considered.
5910
5911 loop
5912 Suppress_Unsuppress_Echeck (E, C);
5913
5914 if Is_Generic_Instance (E)
5915 and then Is_Subprogram (E)
5916 and then Present (Alias (E))
5917 then
5918 Suppress_Unsuppress_Echeck (Alias (E), C);
5919 end if;
5920
5921 -- Move to next homonym if not aspect spec case
5922
5923 exit when From_Aspect_Specification (N);
5924 E := Homonym (E);
5925 exit when No (E);
5926
5927 -- If we are within a package specification, the pragma only
5928 -- applies to homonyms in the same scope.
5929
5930 exit when In_Package_Spec
5931 and then Scope (E) /= Current_Scope;
5932 end loop;
5933 end if;
5934 end Process_Suppress_Unsuppress;
5935
5936 ------------------
5937 -- Set_Exported --
5938 ------------------
5939
5940 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5941 begin
5942 if Is_Imported (E) then
5943 Error_Pragma_Arg
5944 ("cannot export entity& that was previously imported", Arg);
5945
5946 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5947 Error_Pragma_Arg
5948 ("cannot export entity& that has an address clause", Arg);
5949 end if;
5950
5951 Set_Is_Exported (E);
5952
5953 -- Generate a reference for entity explicitly, because the
5954 -- identifier may be overloaded and name resolution will not
5955 -- generate one.
5956
5957 Generate_Reference (E, Arg);
5958
5959 -- Deal with exporting non-library level entity
5960
5961 if not Is_Library_Level_Entity (E) then
5962
5963 -- Not allowed at all for subprograms
5964
5965 if Is_Subprogram (E) then
5966 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5967
5968 -- Otherwise set public and statically allocated
5969
5970 else
5971 Set_Is_Public (E);
5972 Set_Is_Statically_Allocated (E);
5973
5974 -- Warn if the corresponding W flag is set and the pragma comes
5975 -- from source. The latter may not be true e.g. on VMS where we
5976 -- expand export pragmas for exception codes associated with
5977 -- imported or exported exceptions. We do not want to generate
5978 -- a warning for something that the user did not write.
5979
5980 if Warn_On_Export_Import
5981 and then Comes_From_Source (Arg)
5982 then
5983 Error_Msg_NE
5984 ("?& has been made static as a result of Export", Arg, E);
5985 Error_Msg_N
5986 ("\this usage is non-standard and non-portable", Arg);
5987 end if;
5988 end if;
5989 end if;
5990
5991 if Warn_On_Export_Import and then Is_Type (E) then
5992 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5993 end if;
5994
5995 if Warn_On_Export_Import and Inside_A_Generic then
5996 Error_Msg_NE
5997 ("all instances of& will have the same external name?", Arg, E);
5998 end if;
5999 end Set_Exported;
6000
6001 ----------------------------------------------
6002 -- Set_Extended_Import_Export_External_Name --
6003 ----------------------------------------------
6004
6005 procedure Set_Extended_Import_Export_External_Name
6006 (Internal_Ent : Entity_Id;
6007 Arg_External : Node_Id)
6008 is
6009 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
6010 New_Name : Node_Id;
6011
6012 begin
6013 if No (Arg_External) then
6014 return;
6015 end if;
6016
6017 Check_Arg_Is_External_Name (Arg_External);
6018
6019 if Nkind (Arg_External) = N_String_Literal then
6020 if String_Length (Strval (Arg_External)) = 0 then
6021 return;
6022 else
6023 New_Name := Adjust_External_Name_Case (Arg_External);
6024 end if;
6025
6026 elsif Nkind (Arg_External) = N_Identifier then
6027 New_Name := Get_Default_External_Name (Arg_External);
6028
6029 -- Check_Arg_Is_External_Name should let through only identifiers and
6030 -- string literals or static string expressions (which are folded to
6031 -- string literals).
6032
6033 else
6034 raise Program_Error;
6035 end if;
6036
6037 -- If we already have an external name set (by a prior normal Import
6038 -- or Export pragma), then the external names must match
6039
6040 if Present (Interface_Name (Internal_Ent)) then
6041 Check_Matching_Internal_Names : declare
6042 S1 : constant String_Id := Strval (Old_Name);
6043 S2 : constant String_Id := Strval (New_Name);
6044
6045 procedure Mismatch;
6046 -- Called if names do not match
6047
6048 --------------
6049 -- Mismatch --
6050 --------------
6051
6052 procedure Mismatch is
6053 begin
6054 Error_Msg_Sloc := Sloc (Old_Name);
6055 Error_Pragma_Arg
6056 ("external name does not match that given #",
6057 Arg_External);
6058 end Mismatch;
6059
6060 -- Start of processing for Check_Matching_Internal_Names
6061
6062 begin
6063 if String_Length (S1) /= String_Length (S2) then
6064 Mismatch;
6065
6066 else
6067 for J in 1 .. String_Length (S1) loop
6068 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
6069 Mismatch;
6070 end if;
6071 end loop;
6072 end if;
6073 end Check_Matching_Internal_Names;
6074
6075 -- Otherwise set the given name
6076
6077 else
6078 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
6079 Check_Duplicated_Export_Name (New_Name);
6080 end if;
6081 end Set_Extended_Import_Export_External_Name;
6082
6083 ------------------
6084 -- Set_Imported --
6085 ------------------
6086
6087 procedure Set_Imported (E : Entity_Id) is
6088 begin
6089 -- Error message if already imported or exported
6090
6091 if Is_Exported (E) or else Is_Imported (E) then
6092
6093 -- Error if being set Exported twice
6094
6095 if Is_Exported (E) then
6096 Error_Msg_NE ("entity& was previously exported", N, E);
6097
6098 -- OK if Import/Interface case
6099
6100 elsif Import_Interface_Present (N) then
6101 goto OK;
6102
6103 -- Error if being set Imported twice
6104
6105 else
6106 Error_Msg_NE ("entity& was previously imported", N, E);
6107 end if;
6108
6109 Error_Msg_Name_1 := Pname;
6110 Error_Msg_N
6111 ("\(pragma% applies to all previous entities)", N);
6112
6113 Error_Msg_Sloc := Sloc (E);
6114 Error_Msg_NE ("\import not allowed for& declared#", N, E);
6115
6116 -- Here if not previously imported or exported, OK to import
6117
6118 else
6119 Set_Is_Imported (E);
6120
6121 -- If the entity is an object that is not at the library level,
6122 -- then it is statically allocated. We do not worry about objects
6123 -- with address clauses in this context since they are not really
6124 -- imported in the linker sense.
6125
6126 if Is_Object (E)
6127 and then not Is_Library_Level_Entity (E)
6128 and then No (Address_Clause (E))
6129 then
6130 Set_Is_Statically_Allocated (E);
6131 end if;
6132 end if;
6133
6134 <<OK>> null;
6135 end Set_Imported;
6136
6137 -------------------------
6138 -- Set_Mechanism_Value --
6139 -------------------------
6140
6141 -- Note: the mechanism name has not been analyzed (and cannot indeed be
6142 -- analyzed, since it is semantic nonsense), so we get it in the exact
6143 -- form created by the parser.
6144
6145 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
6146 Class : Node_Id;
6147 Param : Node_Id;
6148 Mech_Name_Id : Name_Id;
6149
6150 procedure Bad_Class;
6151 -- Signal bad descriptor class name
6152
6153 procedure Bad_Mechanism;
6154 -- Signal bad mechanism name
6155
6156 ---------------
6157 -- Bad_Class --
6158 ---------------
6159
6160 procedure Bad_Class is
6161 begin
6162 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
6163 end Bad_Class;
6164
6165 -------------------------
6166 -- Bad_Mechanism_Value --
6167 -------------------------
6168
6169 procedure Bad_Mechanism is
6170 begin
6171 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
6172 end Bad_Mechanism;
6173
6174 -- Start of processing for Set_Mechanism_Value
6175
6176 begin
6177 if Mechanism (Ent) /= Default_Mechanism then
6178 Error_Msg_NE
6179 ("mechanism for & has already been set", Mech_Name, Ent);
6180 end if;
6181
6182 -- MECHANISM_NAME ::= value | reference | descriptor |
6183 -- short_descriptor
6184
6185 if Nkind (Mech_Name) = N_Identifier then
6186 if Chars (Mech_Name) = Name_Value then
6187 Set_Mechanism (Ent, By_Copy);
6188 return;
6189
6190 elsif Chars (Mech_Name) = Name_Reference then
6191 Set_Mechanism (Ent, By_Reference);
6192 return;
6193
6194 elsif Chars (Mech_Name) = Name_Descriptor then
6195 Check_VMS (Mech_Name);
6196
6197 -- Descriptor => Short_Descriptor if pragma was given
6198
6199 if Short_Descriptors then
6200 Set_Mechanism (Ent, By_Short_Descriptor);
6201 else
6202 Set_Mechanism (Ent, By_Descriptor);
6203 end if;
6204
6205 return;
6206
6207 elsif Chars (Mech_Name) = Name_Short_Descriptor then
6208 Check_VMS (Mech_Name);
6209 Set_Mechanism (Ent, By_Short_Descriptor);
6210 return;
6211
6212 elsif Chars (Mech_Name) = Name_Copy then
6213 Error_Pragma_Arg
6214 ("bad mechanism name, Value assumed", Mech_Name);
6215
6216 else
6217 Bad_Mechanism;
6218 end if;
6219
6220 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
6221 -- short_descriptor (CLASS_NAME)
6222 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6223
6224 -- Note: this form is parsed as an indexed component
6225
6226 elsif Nkind (Mech_Name) = N_Indexed_Component then
6227 Class := First (Expressions (Mech_Name));
6228
6229 if Nkind (Prefix (Mech_Name)) /= N_Identifier
6230 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
6231 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
6232 or else Present (Next (Class))
6233 then
6234 Bad_Mechanism;
6235 else
6236 Mech_Name_Id := Chars (Prefix (Mech_Name));
6237
6238 -- Change Descriptor => Short_Descriptor if pragma was given
6239
6240 if Mech_Name_Id = Name_Descriptor
6241 and then Short_Descriptors
6242 then
6243 Mech_Name_Id := Name_Short_Descriptor;
6244 end if;
6245 end if;
6246
6247 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
6248 -- short_descriptor (Class => CLASS_NAME)
6249 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6250
6251 -- Note: this form is parsed as a function call
6252
6253 elsif Nkind (Mech_Name) = N_Function_Call then
6254 Param := First (Parameter_Associations (Mech_Name));
6255
6256 if Nkind (Name (Mech_Name)) /= N_Identifier
6257 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6258 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6259 or else Present (Next (Param))
6260 or else No (Selector_Name (Param))
6261 or else Chars (Selector_Name (Param)) /= Name_Class
6262 then
6263 Bad_Mechanism;
6264 else
6265 Class := Explicit_Actual_Parameter (Param);
6266 Mech_Name_Id := Chars (Name (Mech_Name));
6267 end if;
6268
6269 else
6270 Bad_Mechanism;
6271 end if;
6272
6273 -- Fall through here with Class set to descriptor class name
6274
6275 Check_VMS (Mech_Name);
6276
6277 if Nkind (Class) /= N_Identifier then
6278 Bad_Class;
6279
6280 elsif Mech_Name_Id = Name_Descriptor
6281 and then Chars (Class) = Name_UBS
6282 then
6283 Set_Mechanism (Ent, By_Descriptor_UBS);
6284
6285 elsif Mech_Name_Id = Name_Descriptor
6286 and then Chars (Class) = Name_UBSB
6287 then
6288 Set_Mechanism (Ent, By_Descriptor_UBSB);
6289
6290 elsif Mech_Name_Id = Name_Descriptor
6291 and then Chars (Class) = Name_UBA
6292 then
6293 Set_Mechanism (Ent, By_Descriptor_UBA);
6294
6295 elsif Mech_Name_Id = Name_Descriptor
6296 and then Chars (Class) = Name_S
6297 then
6298 Set_Mechanism (Ent, By_Descriptor_S);
6299
6300 elsif Mech_Name_Id = Name_Descriptor
6301 and then Chars (Class) = Name_SB
6302 then
6303 Set_Mechanism (Ent, By_Descriptor_SB);
6304
6305 elsif Mech_Name_Id = Name_Descriptor
6306 and then Chars (Class) = Name_A
6307 then
6308 Set_Mechanism (Ent, By_Descriptor_A);
6309
6310 elsif Mech_Name_Id = Name_Descriptor
6311 and then Chars (Class) = Name_NCA
6312 then
6313 Set_Mechanism (Ent, By_Descriptor_NCA);
6314
6315 elsif Mech_Name_Id = Name_Short_Descriptor
6316 and then Chars (Class) = Name_UBS
6317 then
6318 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6319
6320 elsif Mech_Name_Id = Name_Short_Descriptor
6321 and then Chars (Class) = Name_UBSB
6322 then
6323 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6324
6325 elsif Mech_Name_Id = Name_Short_Descriptor
6326 and then Chars (Class) = Name_UBA
6327 then
6328 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6329
6330 elsif Mech_Name_Id = Name_Short_Descriptor
6331 and then Chars (Class) = Name_S
6332 then
6333 Set_Mechanism (Ent, By_Short_Descriptor_S);
6334
6335 elsif Mech_Name_Id = Name_Short_Descriptor
6336 and then Chars (Class) = Name_SB
6337 then
6338 Set_Mechanism (Ent, By_Short_Descriptor_SB);
6339
6340 elsif Mech_Name_Id = Name_Short_Descriptor
6341 and then Chars (Class) = Name_A
6342 then
6343 Set_Mechanism (Ent, By_Short_Descriptor_A);
6344
6345 elsif Mech_Name_Id = Name_Short_Descriptor
6346 and then Chars (Class) = Name_NCA
6347 then
6348 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6349
6350 else
6351 Bad_Class;
6352 end if;
6353 end Set_Mechanism_Value;
6354
6355 ---------------------------
6356 -- Set_Ravenscar_Profile --
6357 ---------------------------
6358
6359 -- The tasks to be done here are
6360
6361 -- Set required policies
6362
6363 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6364 -- pragma Locking_Policy (Ceiling_Locking)
6365
6366 -- Set Detect_Blocking mode
6367
6368 -- Set required restrictions (see System.Rident for detailed list)
6369
6370 -- Set the No_Dependence rules
6371 -- No_Dependence => Ada.Asynchronous_Task_Control
6372 -- No_Dependence => Ada.Calendar
6373 -- No_Dependence => Ada.Execution_Time.Group_Budget
6374 -- No_Dependence => Ada.Execution_Time.Timers
6375 -- No_Dependence => Ada.Task_Attributes
6376 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6377
6378 procedure Set_Ravenscar_Profile (N : Node_Id) is
6379 Prefix_Entity : Entity_Id;
6380 Selector_Entity : Entity_Id;
6381 Prefix_Node : Node_Id;
6382 Node : Node_Id;
6383
6384 begin
6385 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6386
6387 if Task_Dispatching_Policy /= ' '
6388 and then Task_Dispatching_Policy /= 'F'
6389 then
6390 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6391 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6392
6393 -- Set the FIFO_Within_Priorities policy, but always preserve
6394 -- System_Location since we like the error message with the run time
6395 -- name.
6396
6397 else
6398 Task_Dispatching_Policy := 'F';
6399
6400 if Task_Dispatching_Policy_Sloc /= System_Location then
6401 Task_Dispatching_Policy_Sloc := Loc;
6402 end if;
6403 end if;
6404
6405 -- pragma Locking_Policy (Ceiling_Locking)
6406
6407 if Locking_Policy /= ' '
6408 and then Locking_Policy /= 'C'
6409 then
6410 Error_Msg_Sloc := Locking_Policy_Sloc;
6411 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6412
6413 -- Set the Ceiling_Locking policy, but preserve System_Location since
6414 -- we like the error message with the run time name.
6415
6416 else
6417 Locking_Policy := 'C';
6418
6419 if Locking_Policy_Sloc /= System_Location then
6420 Locking_Policy_Sloc := Loc;
6421 end if;
6422 end if;
6423
6424 -- pragma Detect_Blocking
6425
6426 Detect_Blocking := True;
6427
6428 -- Set the corresponding restrictions
6429
6430 Set_Profile_Restrictions
6431 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6432
6433 -- Set the No_Dependence restrictions
6434
6435 -- The following No_Dependence restrictions:
6436 -- No_Dependence => Ada.Asynchronous_Task_Control
6437 -- No_Dependence => Ada.Calendar
6438 -- No_Dependence => Ada.Task_Attributes
6439 -- are already set by previous call to Set_Profile_Restrictions.
6440
6441 -- Set the following restrictions which were added to Ada 2005:
6442 -- No_Dependence => Ada.Execution_Time.Group_Budget
6443 -- No_Dependence => Ada.Execution_Time.Timers
6444
6445 if Ada_Version >= Ada_2005 then
6446 Name_Buffer (1 .. 3) := "ada";
6447 Name_Len := 3;
6448
6449 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6450
6451 Name_Buffer (1 .. 14) := "execution_time";
6452 Name_Len := 14;
6453
6454 Selector_Entity := Make_Identifier (Loc, Name_Find);
6455
6456 Prefix_Node :=
6457 Make_Selected_Component
6458 (Sloc => Loc,
6459 Prefix => Prefix_Entity,
6460 Selector_Name => Selector_Entity);
6461
6462 Name_Buffer (1 .. 13) := "group_budgets";
6463 Name_Len := 13;
6464
6465 Selector_Entity := Make_Identifier (Loc, Name_Find);
6466
6467 Node :=
6468 Make_Selected_Component
6469 (Sloc => Loc,
6470 Prefix => Prefix_Node,
6471 Selector_Name => Selector_Entity);
6472
6473 Set_Restriction_No_Dependence
6474 (Unit => Node,
6475 Warn => Treat_Restrictions_As_Warnings,
6476 Profile => Ravenscar);
6477
6478 Name_Buffer (1 .. 6) := "timers";
6479 Name_Len := 6;
6480
6481 Selector_Entity := Make_Identifier (Loc, Name_Find);
6482
6483 Node :=
6484 Make_Selected_Component
6485 (Sloc => Loc,
6486 Prefix => Prefix_Node,
6487 Selector_Name => Selector_Entity);
6488
6489 Set_Restriction_No_Dependence
6490 (Unit => Node,
6491 Warn => Treat_Restrictions_As_Warnings,
6492 Profile => Ravenscar);
6493 end if;
6494
6495 -- Set the following restrictions which was added to Ada 2012 (see
6496 -- AI-0171):
6497 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
6498
6499 if Ada_Version >= Ada_2012 then
6500 Name_Buffer (1 .. 6) := "system";
6501 Name_Len := 6;
6502
6503 Prefix_Entity := Make_Identifier (Loc, Name_Find);
6504
6505 Name_Buffer (1 .. 15) := "multiprocessors";
6506 Name_Len := 15;
6507
6508 Selector_Entity := Make_Identifier (Loc, Name_Find);
6509
6510 Prefix_Node :=
6511 Make_Selected_Component
6512 (Sloc => Loc,
6513 Prefix => Prefix_Entity,
6514 Selector_Name => Selector_Entity);
6515
6516 Name_Buffer (1 .. 19) := "dispatching_domains";
6517 Name_Len := 19;
6518
6519 Selector_Entity := Make_Identifier (Loc, Name_Find);
6520
6521 Node :=
6522 Make_Selected_Component
6523 (Sloc => Loc,
6524 Prefix => Prefix_Node,
6525 Selector_Name => Selector_Entity);
6526
6527 Set_Restriction_No_Dependence
6528 (Unit => Node,
6529 Warn => Treat_Restrictions_As_Warnings,
6530 Profile => Ravenscar);
6531 end if;
6532 end Set_Ravenscar_Profile;
6533
6534 ----------------
6535 -- S14_Pragma --
6536 ----------------
6537
6538 procedure S14_Pragma is
6539 begin
6540 if not Formal_Extensions then
6541 Error_Pragma ("pragma% requires the use of debug switch -gnatd.V");
6542 end if;
6543 end S14_Pragma;
6544
6545 -- Start of processing for Analyze_Pragma
6546
6547 begin
6548 -- The following code is a defense against recursion. Not clear that
6549 -- this can happen legitimately, but perhaps some error situations
6550 -- can cause it, and we did see this recursion during testing.
6551
6552 if Analyzed (N) then
6553 return;
6554 else
6555 Set_Analyzed (N, True);
6556 end if;
6557
6558 -- Deal with unrecognized pragma
6559
6560 Pname := Pragma_Name (N);
6561
6562 if not Is_Pragma_Name (Pname) then
6563 if Warn_On_Unrecognized_Pragma then
6564 Error_Msg_Name_1 := Pname;
6565 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6566
6567 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6568 if Is_Bad_Spelling_Of (Pname, PN) then
6569 Error_Msg_Name_1 := PN;
6570 Error_Msg_N -- CODEFIX
6571 ("\?possible misspelling of %!", Pragma_Identifier (N));
6572 exit;
6573 end if;
6574 end loop;
6575 end if;
6576
6577 return;
6578 end if;
6579
6580 -- Here to start processing for recognized pragma
6581
6582 Prag_Id := Get_Pragma_Id (Pname);
6583
6584 if Present (Corresponding_Aspect (N)) then
6585 Pname := Chars (Identifier (Corresponding_Aspect (N)));
6586 end if;
6587
6588 -- Preset arguments
6589
6590 Arg_Count := 0;
6591 Arg1 := Empty;
6592 Arg2 := Empty;
6593 Arg3 := Empty;
6594 Arg4 := Empty;
6595
6596 if Present (Pragma_Argument_Associations (N)) then
6597 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6598 Arg1 := First (Pragma_Argument_Associations (N));
6599
6600 if Present (Arg1) then
6601 Arg2 := Next (Arg1);
6602
6603 if Present (Arg2) then
6604 Arg3 := Next (Arg2);
6605
6606 if Present (Arg3) then
6607 Arg4 := Next (Arg3);
6608 end if;
6609 end if;
6610 end if;
6611 end if;
6612
6613 -- An enumeration type defines the pragmas that are supported by the
6614 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6615 -- into the corresponding enumeration value for the following case.
6616
6617 case Prag_Id is
6618
6619 -----------------
6620 -- Abort_Defer --
6621 -----------------
6622
6623 -- pragma Abort_Defer;
6624
6625 when Pragma_Abort_Defer =>
6626 GNAT_Pragma;
6627 Check_Arg_Count (0);
6628
6629 -- The only required semantic processing is to check the
6630 -- placement. This pragma must appear at the start of the
6631 -- statement sequence of a handled sequence of statements.
6632
6633 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6634 or else N /= First (Statements (Parent (N)))
6635 then
6636 Pragma_Misplaced;
6637 end if;
6638
6639 ------------
6640 -- Ada_83 --
6641 ------------
6642
6643 -- pragma Ada_83;
6644
6645 -- Note: this pragma also has some specific processing in Par.Prag
6646 -- because we want to set the Ada version mode during parsing.
6647
6648 when Pragma_Ada_83 =>
6649 GNAT_Pragma;
6650 Check_Arg_Count (0);
6651
6652 -- We really should check unconditionally for proper configuration
6653 -- pragma placement, since we really don't want mixed Ada modes
6654 -- within a single unit, and the GNAT reference manual has always
6655 -- said this was a configuration pragma, but we did not check and
6656 -- are hesitant to add the check now.
6657
6658 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6659 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6660 -- or Ada 2012 mode.
6661
6662 if Ada_Version >= Ada_2005 then
6663 Check_Valid_Configuration_Pragma;
6664 end if;
6665
6666 -- Now set Ada 83 mode
6667
6668 Ada_Version := Ada_83;
6669 Ada_Version_Explicit := Ada_Version;
6670
6671 ------------
6672 -- Ada_95 --
6673 ------------
6674
6675 -- pragma Ada_95;
6676
6677 -- Note: this pragma also has some specific processing in Par.Prag
6678 -- because we want to set the Ada 83 version mode during parsing.
6679
6680 when Pragma_Ada_95 =>
6681 GNAT_Pragma;
6682 Check_Arg_Count (0);
6683
6684 -- We really should check unconditionally for proper configuration
6685 -- pragma placement, since we really don't want mixed Ada modes
6686 -- within a single unit, and the GNAT reference manual has always
6687 -- said this was a configuration pragma, but we did not check and
6688 -- are hesitant to add the check now.
6689
6690 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
6691 -- or Ada 95, so we must check if we are in Ada 2005 mode.
6692
6693 if Ada_Version >= Ada_2005 then
6694 Check_Valid_Configuration_Pragma;
6695 end if;
6696
6697 -- Now set Ada 95 mode
6698
6699 Ada_Version := Ada_95;
6700 Ada_Version_Explicit := Ada_Version;
6701
6702 ---------------------
6703 -- Ada_05/Ada_2005 --
6704 ---------------------
6705
6706 -- pragma Ada_05;
6707 -- pragma Ada_05 (LOCAL_NAME);
6708
6709 -- pragma Ada_2005;
6710 -- pragma Ada_2005 (LOCAL_NAME):
6711
6712 -- Note: these pragmas also have some specific processing in Par.Prag
6713 -- because we want to set the Ada 2005 version mode during parsing.
6714
6715 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6716 E_Id : Node_Id;
6717
6718 begin
6719 GNAT_Pragma;
6720
6721 if Arg_Count = 1 then
6722 Check_Arg_Is_Local_Name (Arg1);
6723 E_Id := Get_Pragma_Arg (Arg1);
6724
6725 if Etype (E_Id) = Any_Type then
6726 return;
6727 end if;
6728
6729 Set_Is_Ada_2005_Only (Entity (E_Id));
6730 Record_Rep_Item (Entity (E_Id), N);
6731
6732 else
6733 Check_Arg_Count (0);
6734
6735 -- For Ada_2005 we unconditionally enforce the documented
6736 -- configuration pragma placement, since we do not want to
6737 -- tolerate mixed modes in a unit involving Ada 2005. That
6738 -- would cause real difficulties for those cases where there
6739 -- are incompatibilities between Ada 95 and Ada 2005.
6740
6741 Check_Valid_Configuration_Pragma;
6742
6743 -- Now set appropriate Ada mode
6744
6745 Ada_Version := Ada_2005;
6746 Ada_Version_Explicit := Ada_2005;
6747 end if;
6748 end;
6749
6750 ---------------------
6751 -- Ada_12/Ada_2012 --
6752 ---------------------
6753
6754 -- pragma Ada_12;
6755 -- pragma Ada_12 (LOCAL_NAME);
6756
6757 -- pragma Ada_2012;
6758 -- pragma Ada_2012 (LOCAL_NAME):
6759
6760 -- Note: these pragmas also have some specific processing in Par.Prag
6761 -- because we want to set the Ada 2012 version mode during parsing.
6762
6763 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6764 E_Id : Node_Id;
6765
6766 begin
6767 GNAT_Pragma;
6768
6769 if Arg_Count = 1 then
6770 Check_Arg_Is_Local_Name (Arg1);
6771 E_Id := Get_Pragma_Arg (Arg1);
6772
6773 if Etype (E_Id) = Any_Type then
6774 return;
6775 end if;
6776
6777 Set_Is_Ada_2012_Only (Entity (E_Id));
6778 Record_Rep_Item (Entity (E_Id), N);
6779
6780 else
6781 Check_Arg_Count (0);
6782
6783 -- For Ada_2012 we unconditionally enforce the documented
6784 -- configuration pragma placement, since we do not want to
6785 -- tolerate mixed modes in a unit involving Ada 2012. That
6786 -- would cause real difficulties for those cases where there
6787 -- are incompatibilities between Ada 95 and Ada 2012. We could
6788 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6789
6790 Check_Valid_Configuration_Pragma;
6791
6792 -- Now set appropriate Ada mode
6793
6794 Ada_Version := Ada_2012;
6795 Ada_Version_Explicit := Ada_2012;
6796 end if;
6797 end;
6798
6799 ----------------------
6800 -- All_Calls_Remote --
6801 ----------------------
6802
6803 -- pragma All_Calls_Remote [(library_package_NAME)];
6804
6805 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6806 Lib_Entity : Entity_Id;
6807
6808 begin
6809 Check_Ada_83_Warning;
6810 Check_Valid_Library_Unit_Pragma;
6811
6812 if Nkind (N) = N_Null_Statement then
6813 return;
6814 end if;
6815
6816 Lib_Entity := Find_Lib_Unit_Name;
6817
6818 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6819
6820 if Present (Lib_Entity)
6821 and then not Debug_Flag_U
6822 then
6823 if not Is_Remote_Call_Interface (Lib_Entity) then
6824 Error_Pragma ("pragma% only apply to rci unit");
6825
6826 -- Set flag for entity of the library unit
6827
6828 else
6829 Set_Has_All_Calls_Remote (Lib_Entity);
6830 end if;
6831
6832 end if;
6833 end All_Calls_Remote;
6834
6835 --------------
6836 -- Annotate --
6837 --------------
6838
6839 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6840 -- ARG ::= NAME | EXPRESSION
6841
6842 -- The first two arguments are by convention intended to refer to an
6843 -- external tool and a tool-specific function. These arguments are
6844 -- not analyzed.
6845
6846 when Pragma_Annotate => Annotate : declare
6847 Arg : Node_Id;
6848 Exp : Node_Id;
6849
6850 begin
6851 GNAT_Pragma;
6852 Check_At_Least_N_Arguments (1);
6853 Check_Arg_Is_Identifier (Arg1);
6854 Check_No_Identifiers;
6855 Store_Note (N);
6856
6857 -- Second parameter is optional, it is never analyzed
6858
6859 if No (Arg2) then
6860 null;
6861
6862 -- Here if we have a second parameter
6863
6864 else
6865 -- Second parameter must be identifier
6866
6867 Check_Arg_Is_Identifier (Arg2);
6868
6869 -- Process remaining parameters if any
6870
6871 Arg := Next (Arg2);
6872 while Present (Arg) loop
6873 Exp := Get_Pragma_Arg (Arg);
6874 Analyze (Exp);
6875
6876 if Is_Entity_Name (Exp) then
6877 null;
6878
6879 -- For string literals, we assume Standard_String as the
6880 -- type, unless the string contains wide or wide_wide
6881 -- characters.
6882
6883 elsif Nkind (Exp) = N_String_Literal then
6884 if Has_Wide_Wide_Character (Exp) then
6885 Resolve (Exp, Standard_Wide_Wide_String);
6886 elsif Has_Wide_Character (Exp) then
6887 Resolve (Exp, Standard_Wide_String);
6888 else
6889 Resolve (Exp, Standard_String);
6890 end if;
6891
6892 elsif Is_Overloaded (Exp) then
6893 Error_Pragma_Arg
6894 ("ambiguous argument for pragma%", Exp);
6895
6896 else
6897 Resolve (Exp);
6898 end if;
6899
6900 Next (Arg);
6901 end loop;
6902 end if;
6903 end Annotate;
6904
6905 ---------------------------
6906 -- Assert/Assert_And_Cut --
6907 ---------------------------
6908
6909 -- pragma Assert
6910 -- ( [Check => ] Boolean_EXPRESSION
6911 -- [, [Message =>] Static_String_EXPRESSION]);
6912
6913 -- pragma Assert_And_Cut
6914 -- ( [Check => ] Boolean_EXPRESSION
6915 -- [, [Message =>] Static_String_EXPRESSION]);
6916
6917 when Pragma_Assert | Pragma_Assert_And_Cut => Assert : declare
6918 Expr : Node_Id;
6919 Newa : List_Id;
6920
6921 begin
6922 if Prag_Id = Pragma_Assert then
6923 Ada_2005_Pragma;
6924 else -- Pragma_Assert_And_Cut
6925 GNAT_Pragma;
6926 S14_Pragma;
6927 end if;
6928
6929 Check_At_Least_N_Arguments (1);
6930 Check_At_Most_N_Arguments (2);
6931 Check_Arg_Order ((Name_Check, Name_Message));
6932 Check_Optional_Identifier (Arg1, Name_Check);
6933
6934 -- We treat pragma Assert as equivalent to:
6935
6936 -- pragma Check (Assertion, condition [, msg]);
6937
6938 -- So rewrite pragma in this manner, transfer the message
6939 -- argument if present, and analyze the result
6940
6941 -- Pragma Assert_And_Cut is treated exactly like pragma Assert by
6942 -- the frontend. Formal verification tools may use it to "cut" the
6943 -- paths through the code, to make verification tractable. When
6944 -- dealing with a semantically analyzed tree, the information that
6945 -- a Check node N corresponds to a source Assert_And_Cut pragma
6946 -- can be retrieved from the pragma kind of Original_Node(N).
6947
6948 Expr := Get_Pragma_Arg (Arg1);
6949 Newa := New_List (
6950 Make_Pragma_Argument_Association (Loc,
6951 Expression => Make_Identifier (Loc, Name_Assertion)),
6952
6953 Make_Pragma_Argument_Association (Sloc (Expr),
6954 Expression => Expr));
6955
6956 if Arg_Count > 1 then
6957 Check_Optional_Identifier (Arg2, Name_Message);
6958 Append_To (Newa, New_Copy_Tree (Arg2));
6959 end if;
6960
6961 Rewrite (N,
6962 Make_Pragma (Loc,
6963 Chars => Name_Check,
6964 Pragma_Argument_Associations => Newa));
6965 Analyze (N);
6966 end Assert;
6967
6968 ----------------------
6969 -- Assertion_Policy --
6970 ----------------------
6971
6972 -- pragma Assertion_Policy (Check | Disable | Ignore)
6973
6974 when Pragma_Assertion_Policy => Assertion_Policy : declare
6975 Policy : Node_Id;
6976
6977 begin
6978 Ada_2005_Pragma;
6979 Check_Valid_Configuration_Pragma;
6980 Check_Arg_Count (1);
6981 Check_No_Identifiers;
6982 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6983
6984 -- We treat pragma Assertion_Policy as equivalent to:
6985
6986 -- pragma Check_Policy (Assertion, policy)
6987
6988 -- So rewrite the pragma in that manner and link on to the chain
6989 -- of Check_Policy pragmas, marking the pragma as analyzed.
6990
6991 Policy := Get_Pragma_Arg (Arg1);
6992
6993 Rewrite (N,
6994 Make_Pragma (Loc,
6995 Chars => Name_Check_Policy,
6996
6997 Pragma_Argument_Associations => New_List (
6998 Make_Pragma_Argument_Association (Loc,
6999 Expression => Make_Identifier (Loc, Name_Assertion)),
7000
7001 Make_Pragma_Argument_Association (Loc,
7002 Expression =>
7003 Make_Identifier (Sloc (Policy), Chars (Policy))))));
7004
7005 Set_Analyzed (N);
7006 Set_Next_Pragma (N, Opt.Check_Policy_List);
7007 Opt.Check_Policy_List := N;
7008 end Assertion_Policy;
7009
7010 ------------
7011 -- Assume --
7012 ------------
7013
7014 -- pragma Assume (boolean_EXPRESSION);
7015
7016 when Pragma_Assume => Assume : declare
7017 begin
7018 GNAT_Pragma;
7019 S14_Pragma;
7020 Check_Arg_Count (1);
7021
7022 -- Pragma Assume is transformed into pragma Check in the following
7023 -- manner:
7024
7025 -- pragma Check (Assume, Expr);
7026
7027 Rewrite (N,
7028 Make_Pragma (Loc,
7029 Chars => Name_Check,
7030 Pragma_Argument_Associations => New_List (
7031 Make_Pragma_Argument_Association (Loc,
7032 Expression => Make_Identifier (Loc, Name_Assume)),
7033
7034 Make_Pragma_Argument_Association (Loc,
7035 Expression => Relocate_Node (Expression (Arg1))))));
7036 Analyze (N);
7037 end Assume;
7038
7039 ------------------------------
7040 -- Assume_No_Invalid_Values --
7041 ------------------------------
7042
7043 -- pragma Assume_No_Invalid_Values (On | Off);
7044
7045 when Pragma_Assume_No_Invalid_Values =>
7046 GNAT_Pragma;
7047 Check_Valid_Configuration_Pragma;
7048 Check_Arg_Count (1);
7049 Check_No_Identifiers;
7050 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7051
7052 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
7053 Assume_No_Invalid_Values := True;
7054 else
7055 Assume_No_Invalid_Values := False;
7056 end if;
7057
7058 --------------------------
7059 -- Attribute_Definition --
7060 --------------------------
7061
7062 -- pragma Attribute_Definition
7063 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
7064 -- [Entity =>] LOCAL_NAME,
7065 -- [Expression =>] EXPRESSION | NAME);
7066
7067 when Pragma_Attribute_Definition => Attribute_Definition : declare
7068 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
7069 Aname : Name_Id;
7070
7071 begin
7072 GNAT_Pragma;
7073 Check_Arg_Count (3);
7074 Check_Optional_Identifier (Arg1, "attribute");
7075 Check_Optional_Identifier (Arg2, "entity");
7076 Check_Optional_Identifier (Arg3, "expression");
7077
7078 if Nkind (Attribute_Designator) /= N_Identifier then
7079 Error_Msg_N ("attribute name expected", Attribute_Designator);
7080 return;
7081 end if;
7082
7083 Check_Arg_Is_Local_Name (Arg2);
7084
7085 -- If the attribute is not recognized, then issue a warning (not
7086 -- an error), and ignore the pragma.
7087
7088 Aname := Chars (Attribute_Designator);
7089
7090 if not Is_Attribute_Name (Aname) then
7091 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
7092 return;
7093 end if;
7094
7095 -- Otherwise, rewrite the pragma as an attribute definition clause
7096
7097 Rewrite (N,
7098 Make_Attribute_Definition_Clause (Loc,
7099 Name => Get_Pragma_Arg (Arg2),
7100 Chars => Aname,
7101 Expression => Get_Pragma_Arg (Arg3)));
7102 Analyze (N);
7103 end Attribute_Definition;
7104
7105 ---------------
7106 -- AST_Entry --
7107 ---------------
7108
7109 -- pragma AST_Entry (entry_IDENTIFIER);
7110
7111 when Pragma_AST_Entry => AST_Entry : declare
7112 Ent : Node_Id;
7113
7114 begin
7115 GNAT_Pragma;
7116 Check_VMS (N);
7117 Check_Arg_Count (1);
7118 Check_No_Identifiers;
7119 Check_Arg_Is_Local_Name (Arg1);
7120 Ent := Entity (Get_Pragma_Arg (Arg1));
7121
7122 -- Note: the implementation of the AST_Entry pragma could handle
7123 -- the entry family case fine, but for now we are consistent with
7124 -- the DEC rules, and do not allow the pragma, which of course
7125 -- has the effect of also forbidding the attribute.
7126
7127 if Ekind (Ent) /= E_Entry then
7128 Error_Pragma_Arg
7129 ("pragma% argument must be simple entry name", Arg1);
7130
7131 elsif Is_AST_Entry (Ent) then
7132 Error_Pragma_Arg
7133 ("duplicate % pragma for entry", Arg1);
7134
7135 elsif Has_Homonym (Ent) then
7136 Error_Pragma_Arg
7137 ("pragma% argument cannot specify overloaded entry", Arg1);
7138
7139 else
7140 declare
7141 FF : constant Entity_Id := First_Formal (Ent);
7142
7143 begin
7144 if Present (FF) then
7145 if Present (Next_Formal (FF)) then
7146 Error_Pragma_Arg
7147 ("entry for pragma% can have only one argument",
7148 Arg1);
7149
7150 elsif Parameter_Mode (FF) /= E_In_Parameter then
7151 Error_Pragma_Arg
7152 ("entry parameter for pragma% must have mode IN",
7153 Arg1);
7154 end if;
7155 end if;
7156 end;
7157
7158 Set_Is_AST_Entry (Ent);
7159 end if;
7160 end AST_Entry;
7161
7162 ------------------
7163 -- Asynchronous --
7164 ------------------
7165
7166 -- pragma Asynchronous (LOCAL_NAME);
7167
7168 when Pragma_Asynchronous => Asynchronous : declare
7169 Nm : Entity_Id;
7170 C_Ent : Entity_Id;
7171 L : List_Id;
7172 S : Node_Id;
7173 N : Node_Id;
7174 Formal : Entity_Id;
7175
7176 procedure Process_Async_Pragma;
7177 -- Common processing for procedure and access-to-procedure case
7178
7179 --------------------------
7180 -- Process_Async_Pragma --
7181 --------------------------
7182
7183 procedure Process_Async_Pragma is
7184 begin
7185 if No (L) then
7186 Set_Is_Asynchronous (Nm);
7187 return;
7188 end if;
7189
7190 -- The formals should be of mode IN (RM E.4.1(6))
7191
7192 S := First (L);
7193 while Present (S) loop
7194 Formal := Defining_Identifier (S);
7195
7196 if Nkind (Formal) = N_Defining_Identifier
7197 and then Ekind (Formal) /= E_In_Parameter
7198 then
7199 Error_Pragma_Arg
7200 ("pragma% procedure can only have IN parameter",
7201 Arg1);
7202 end if;
7203
7204 Next (S);
7205 end loop;
7206
7207 Set_Is_Asynchronous (Nm);
7208 end Process_Async_Pragma;
7209
7210 -- Start of processing for pragma Asynchronous
7211
7212 begin
7213 Check_Ada_83_Warning;
7214 Check_No_Identifiers;
7215 Check_Arg_Count (1);
7216 Check_Arg_Is_Local_Name (Arg1);
7217
7218 if Debug_Flag_U then
7219 return;
7220 end if;
7221
7222 C_Ent := Cunit_Entity (Current_Sem_Unit);
7223 Analyze (Get_Pragma_Arg (Arg1));
7224 Nm := Entity (Get_Pragma_Arg (Arg1));
7225
7226 if not Is_Remote_Call_Interface (C_Ent)
7227 and then not Is_Remote_Types (C_Ent)
7228 then
7229 -- This pragma should only appear in an RCI or Remote Types
7230 -- unit (RM E.4.1(4)).
7231
7232 Error_Pragma
7233 ("pragma% not in Remote_Call_Interface or " &
7234 "Remote_Types unit");
7235 end if;
7236
7237 if Ekind (Nm) = E_Procedure
7238 and then Nkind (Parent (Nm)) = N_Procedure_Specification
7239 then
7240 if not Is_Remote_Call_Interface (Nm) then
7241 Error_Pragma_Arg
7242 ("pragma% cannot be applied on non-remote procedure",
7243 Arg1);
7244 end if;
7245
7246 L := Parameter_Specifications (Parent (Nm));
7247 Process_Async_Pragma;
7248 return;
7249
7250 elsif Ekind (Nm) = E_Function then
7251 Error_Pragma_Arg
7252 ("pragma% cannot be applied to function", Arg1);
7253
7254 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
7255 if Is_Record_Type (Nm) then
7256
7257 -- A record type that is the Equivalent_Type for a remote
7258 -- access-to-subprogram type.
7259
7260 N := Declaration_Node (Corresponding_Remote_Type (Nm));
7261
7262 else
7263 -- A non-expanded RAS type (distribution is not enabled)
7264
7265 N := Declaration_Node (Nm);
7266 end if;
7267
7268 if Nkind (N) = N_Full_Type_Declaration
7269 and then Nkind (Type_Definition (N)) =
7270 N_Access_Procedure_Definition
7271 then
7272 L := Parameter_Specifications (Type_Definition (N));
7273 Process_Async_Pragma;
7274
7275 if Is_Asynchronous (Nm)
7276 and then Expander_Active
7277 and then Get_PCS_Name /= Name_No_DSA
7278 then
7279 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
7280 end if;
7281
7282 else
7283 Error_Pragma_Arg
7284 ("pragma% cannot reference access-to-function type",
7285 Arg1);
7286 end if;
7287
7288 -- Only other possibility is Access-to-class-wide type
7289
7290 elsif Is_Access_Type (Nm)
7291 and then Is_Class_Wide_Type (Designated_Type (Nm))
7292 then
7293 Check_First_Subtype (Arg1);
7294 Set_Is_Asynchronous (Nm);
7295 if Expander_Active then
7296 RACW_Type_Is_Asynchronous (Nm);
7297 end if;
7298
7299 else
7300 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
7301 end if;
7302 end Asynchronous;
7303
7304 ------------
7305 -- Atomic --
7306 ------------
7307
7308 -- pragma Atomic (LOCAL_NAME);
7309
7310 when Pragma_Atomic =>
7311 Process_Atomic_Shared_Volatile;
7312
7313 -----------------------
7314 -- Atomic_Components --
7315 -----------------------
7316
7317 -- pragma Atomic_Components (array_LOCAL_NAME);
7318
7319 -- This processing is shared by Volatile_Components
7320
7321 when Pragma_Atomic_Components |
7322 Pragma_Volatile_Components =>
7323
7324 Atomic_Components : declare
7325 E_Id : Node_Id;
7326 E : Entity_Id;
7327 D : Node_Id;
7328 K : Node_Kind;
7329
7330 begin
7331 Check_Ada_83_Warning;
7332 Check_No_Identifiers;
7333 Check_Arg_Count (1);
7334 Check_Arg_Is_Local_Name (Arg1);
7335 E_Id := Get_Pragma_Arg (Arg1);
7336
7337 if Etype (E_Id) = Any_Type then
7338 return;
7339 end if;
7340
7341 E := Entity (E_Id);
7342
7343 Check_Duplicate_Pragma (E);
7344
7345 if Rep_Item_Too_Early (E, N)
7346 or else
7347 Rep_Item_Too_Late (E, N)
7348 then
7349 return;
7350 end if;
7351
7352 D := Declaration_Node (E);
7353 K := Nkind (D);
7354
7355 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
7356 or else
7357 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7358 and then Nkind (D) = N_Object_Declaration
7359 and then Nkind (Object_Definition (D)) =
7360 N_Constrained_Array_Definition)
7361 then
7362 -- The flag is set on the object, or on the base type
7363
7364 if Nkind (D) /= N_Object_Declaration then
7365 E := Base_Type (E);
7366 end if;
7367
7368 Set_Has_Volatile_Components (E);
7369
7370 if Prag_Id = Pragma_Atomic_Components then
7371 Set_Has_Atomic_Components (E);
7372 end if;
7373
7374 else
7375 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7376 end if;
7377 end Atomic_Components;
7378
7379 --------------------
7380 -- Attach_Handler --
7381 --------------------
7382
7383 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
7384
7385 when Pragma_Attach_Handler =>
7386 Check_Ada_83_Warning;
7387 Check_No_Identifiers;
7388 Check_Arg_Count (2);
7389
7390 if No_Run_Time_Mode then
7391 Error_Msg_CRT ("Attach_Handler pragma", N);
7392 else
7393 Check_Interrupt_Or_Attach_Handler;
7394
7395 -- The expression that designates the attribute may depend on a
7396 -- discriminant, and is therefore a per-object expression, to
7397 -- be expanded in the init proc. If expansion is enabled, then
7398 -- perform semantic checks on a copy only.
7399
7400 if Expander_Active then
7401 declare
7402 Temp : constant Node_Id :=
7403 New_Copy_Tree (Get_Pragma_Arg (Arg2));
7404 begin
7405 Set_Parent (Temp, N);
7406 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7407 end;
7408
7409 else
7410 Analyze (Get_Pragma_Arg (Arg2));
7411 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7412 end if;
7413
7414 Process_Interrupt_Or_Attach_Handler;
7415 end if;
7416
7417 --------------------
7418 -- C_Pass_By_Copy --
7419 --------------------
7420
7421 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7422
7423 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7424 Arg : Node_Id;
7425 Val : Uint;
7426
7427 begin
7428 GNAT_Pragma;
7429 Check_Valid_Configuration_Pragma;
7430 Check_Arg_Count (1);
7431 Check_Optional_Identifier (Arg1, "max_size");
7432
7433 Arg := Get_Pragma_Arg (Arg1);
7434 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7435
7436 Val := Expr_Value (Arg);
7437
7438 if Val <= 0 then
7439 Error_Pragma_Arg
7440 ("maximum size for pragma% must be positive", Arg1);
7441
7442 elsif UI_Is_In_Int_Range (Val) then
7443 Default_C_Record_Mechanism := UI_To_Int (Val);
7444
7445 -- If a giant value is given, Int'Last will do well enough.
7446 -- If sometime someone complains that a record larger than
7447 -- two gigabytes is not copied, we will worry about it then!
7448
7449 else
7450 Default_C_Record_Mechanism := Mechanism_Type'Last;
7451 end if;
7452 end C_Pass_By_Copy;
7453
7454 -----------
7455 -- Check --
7456 -----------
7457
7458 -- pragma Check ([Name =>] IDENTIFIER,
7459 -- [Check =>] Boolean_EXPRESSION
7460 -- [,[Message =>] String_EXPRESSION]);
7461
7462 when Pragma_Check => Check : declare
7463 Expr : Node_Id;
7464 Eloc : Source_Ptr;
7465 Cname : Name_Id;
7466
7467 Check_On : Boolean;
7468 -- Set True if category of assertions referenced by Name enabled
7469
7470 begin
7471 GNAT_Pragma;
7472 Check_At_Least_N_Arguments (2);
7473 Check_At_Most_N_Arguments (3);
7474 Check_Optional_Identifier (Arg1, Name_Name);
7475 Check_Optional_Identifier (Arg2, Name_Check);
7476
7477 if Arg_Count = 3 then
7478 Check_Optional_Identifier (Arg3, Name_Message);
7479 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
7480 end if;
7481
7482 Check_Arg_Is_Identifier (Arg1);
7483
7484 -- Completely ignore if disabled
7485
7486 if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
7487 Rewrite (N, Make_Null_Statement (Loc));
7488 Analyze (N);
7489 return;
7490 end if;
7491
7492 Cname := Chars (Get_Pragma_Arg (Arg1));
7493 Check_On := Check_Enabled (Cname);
7494
7495 case Cname is
7496 when Name_Predicate |
7497 Name_Invariant =>
7498
7499 -- Nothing to do: since checks occur in client units,
7500 -- the SCO for the aspect in the declaration unit is
7501 -- conservatively always enabled.
7502
7503 null;
7504
7505 when others =>
7506
7507 if Check_On and then not Split_PPC (N) then
7508
7509 -- Mark pragma/aspect SCO as enabled
7510
7511 Set_SCO_Pragma_Enabled (Loc);
7512 end if;
7513 end case;
7514
7515 -- If expansion is active and the check is not enabled then we
7516 -- rewrite the Check as:
7517
7518 -- if False and then condition then
7519 -- null;
7520 -- end if;
7521
7522 -- The reason we do this rewriting during semantic analysis rather
7523 -- than as part of normal expansion is that we cannot analyze and
7524 -- expand the code for the boolean expression directly, or it may
7525 -- cause insertion of actions that would escape the attempt to
7526 -- suppress the check code.
7527
7528 -- Note that the Sloc for the if statement corresponds to the
7529 -- argument condition, not the pragma itself. The reason for this
7530 -- is that we may generate a warning if the condition is False at
7531 -- compile time, and we do not want to delete this warning when we
7532 -- delete the if statement.
7533
7534 Expr := Get_Pragma_Arg (Arg2);
7535
7536 if Expander_Active and then not Check_On then
7537 Eloc := Sloc (Expr);
7538
7539 Rewrite (N,
7540 Make_If_Statement (Eloc,
7541 Condition =>
7542 Make_And_Then (Eloc,
7543 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
7544 Right_Opnd => Expr),
7545 Then_Statements => New_List (
7546 Make_Null_Statement (Eloc))));
7547
7548 Analyze (N);
7549
7550 -- Check is active
7551
7552 else
7553 In_Assertion_Expr := In_Assertion_Expr + 1;
7554 Analyze_And_Resolve (Expr, Any_Boolean);
7555 In_Assertion_Expr := In_Assertion_Expr - 1;
7556 end if;
7557 end Check;
7558
7559 ----------------
7560 -- Check_Name --
7561 ----------------
7562
7563 -- pragma Check_Name (check_IDENTIFIER);
7564
7565 when Pragma_Check_Name =>
7566 Check_No_Identifiers;
7567 GNAT_Pragma;
7568 Check_Valid_Configuration_Pragma;
7569 Check_Arg_Count (1);
7570 Check_Arg_Is_Identifier (Arg1);
7571
7572 declare
7573 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7574
7575 begin
7576 for J in Check_Names.First .. Check_Names.Last loop
7577 if Check_Names.Table (J) = Nam then
7578 return;
7579 end if;
7580 end loop;
7581
7582 Check_Names.Append (Nam);
7583 end;
7584
7585 ------------------
7586 -- Check_Policy --
7587 ------------------
7588
7589 -- pragma Check_Policy (
7590 -- [Name =>] IDENTIFIER,
7591 -- [Policy =>] POLICY_IDENTIFIER);
7592
7593 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7594
7595 -- Note: this is a configuration pragma, but it is allowed to appear
7596 -- anywhere else.
7597
7598 when Pragma_Check_Policy =>
7599 GNAT_Pragma;
7600 Check_Arg_Count (2);
7601 Check_Optional_Identifier (Arg1, Name_Name);
7602 Check_Optional_Identifier (Arg2, Name_Policy);
7603 Check_Arg_Is_One_Of
7604 (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7605
7606 -- A Check_Policy pragma can appear either as a configuration
7607 -- pragma, or in a declarative part or a package spec (see RM
7608 -- 11.5(5) for rules for Suppress/Unsuppress which are also
7609 -- followed for Check_Policy).
7610
7611 if not Is_Configuration_Pragma then
7612 Check_Is_In_Decl_Part_Or_Package_Spec;
7613 end if;
7614
7615 Set_Next_Pragma (N, Opt.Check_Policy_List);
7616 Opt.Check_Policy_List := N;
7617
7618 ---------------------
7619 -- CIL_Constructor --
7620 ---------------------
7621
7622 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7623
7624 -- Processing for this pragma is shared with Java_Constructor
7625
7626 -------------
7627 -- Comment --
7628 -------------
7629
7630 -- pragma Comment (static_string_EXPRESSION)
7631
7632 -- Processing for pragma Comment shares the circuitry for pragma
7633 -- Ident. The only differences are that Ident enforces a limit of 31
7634 -- characters on its argument, and also enforces limitations on
7635 -- placement for DEC compatibility. Pragma Comment shares neither of
7636 -- these restrictions.
7637
7638 -------------------
7639 -- Common_Object --
7640 -------------------
7641
7642 -- pragma Common_Object (
7643 -- [Internal =>] LOCAL_NAME
7644 -- [, [External =>] EXTERNAL_SYMBOL]
7645 -- [, [Size =>] EXTERNAL_SYMBOL]);
7646
7647 -- Processing for this pragma is shared with Psect_Object
7648
7649 ------------------------
7650 -- Compile_Time_Error --
7651 ------------------------
7652
7653 -- pragma Compile_Time_Error
7654 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7655
7656 when Pragma_Compile_Time_Error =>
7657 GNAT_Pragma;
7658 Process_Compile_Time_Warning_Or_Error;
7659
7660 --------------------------
7661 -- Compile_Time_Warning --
7662 --------------------------
7663
7664 -- pragma Compile_Time_Warning
7665 -- (boolean_EXPRESSION, static_string_EXPRESSION);
7666
7667 when Pragma_Compile_Time_Warning =>
7668 GNAT_Pragma;
7669 Process_Compile_Time_Warning_Or_Error;
7670
7671 -------------------
7672 -- Compiler_Unit --
7673 -------------------
7674
7675 when Pragma_Compiler_Unit =>
7676 GNAT_Pragma;
7677 Check_Arg_Count (0);
7678 Set_Is_Compiler_Unit (Get_Source_Unit (N));
7679
7680 -----------------------------
7681 -- Complete_Representation --
7682 -----------------------------
7683
7684 -- pragma Complete_Representation;
7685
7686 when Pragma_Complete_Representation =>
7687 GNAT_Pragma;
7688 Check_Arg_Count (0);
7689
7690 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7691 Error_Pragma
7692 ("pragma & must appear within record representation clause");
7693 end if;
7694
7695 ----------------------------
7696 -- Complex_Representation --
7697 ----------------------------
7698
7699 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7700
7701 when Pragma_Complex_Representation => Complex_Representation : declare
7702 E_Id : Entity_Id;
7703 E : Entity_Id;
7704 Ent : Entity_Id;
7705
7706 begin
7707 GNAT_Pragma;
7708 Check_Arg_Count (1);
7709 Check_Optional_Identifier (Arg1, Name_Entity);
7710 Check_Arg_Is_Local_Name (Arg1);
7711 E_Id := Get_Pragma_Arg (Arg1);
7712
7713 if Etype (E_Id) = Any_Type then
7714 return;
7715 end if;
7716
7717 E := Entity (E_Id);
7718
7719 if not Is_Record_Type (E) then
7720 Error_Pragma_Arg
7721 ("argument for pragma% must be record type", Arg1);
7722 end if;
7723
7724 Ent := First_Entity (E);
7725
7726 if No (Ent)
7727 or else No (Next_Entity (Ent))
7728 or else Present (Next_Entity (Next_Entity (Ent)))
7729 or else not Is_Floating_Point_Type (Etype (Ent))
7730 or else Etype (Ent) /= Etype (Next_Entity (Ent))
7731 then
7732 Error_Pragma_Arg
7733 ("record for pragma% must have two fields of the same "
7734 & "floating-point type", Arg1);
7735
7736 else
7737 Set_Has_Complex_Representation (Base_Type (E));
7738
7739 -- We need to treat the type has having a non-standard
7740 -- representation, for back-end purposes, even though in
7741 -- general a complex will have the default representation
7742 -- of a record with two real components.
7743
7744 Set_Has_Non_Standard_Rep (Base_Type (E));
7745 end if;
7746 end Complex_Representation;
7747
7748 -------------------------
7749 -- Component_Alignment --
7750 -------------------------
7751
7752 -- pragma Component_Alignment (
7753 -- [Form =>] ALIGNMENT_CHOICE
7754 -- [, [Name =>] type_LOCAL_NAME]);
7755 --
7756 -- ALIGNMENT_CHOICE ::=
7757 -- Component_Size
7758 -- | Component_Size_4
7759 -- | Storage_Unit
7760 -- | Default
7761
7762 when Pragma_Component_Alignment => Component_AlignmentP : declare
7763 Args : Args_List (1 .. 2);
7764 Names : constant Name_List (1 .. 2) := (
7765 Name_Form,
7766 Name_Name);
7767
7768 Form : Node_Id renames Args (1);
7769 Name : Node_Id renames Args (2);
7770
7771 Atype : Component_Alignment_Kind;
7772 Typ : Entity_Id;
7773
7774 begin
7775 GNAT_Pragma;
7776 Gather_Associations (Names, Args);
7777
7778 if No (Form) then
7779 Error_Pragma ("missing Form argument for pragma%");
7780 end if;
7781
7782 Check_Arg_Is_Identifier (Form);
7783
7784 -- Get proper alignment, note that Default = Component_Size on all
7785 -- machines we have so far, and we want to set this value rather
7786 -- than the default value to indicate that it has been explicitly
7787 -- set (and thus will not get overridden by the default component
7788 -- alignment for the current scope)
7789
7790 if Chars (Form) = Name_Component_Size then
7791 Atype := Calign_Component_Size;
7792
7793 elsif Chars (Form) = Name_Component_Size_4 then
7794 Atype := Calign_Component_Size_4;
7795
7796 elsif Chars (Form) = Name_Default then
7797 Atype := Calign_Component_Size;
7798
7799 elsif Chars (Form) = Name_Storage_Unit then
7800 Atype := Calign_Storage_Unit;
7801
7802 else
7803 Error_Pragma_Arg
7804 ("invalid Form parameter for pragma%", Form);
7805 end if;
7806
7807 -- Case with no name, supplied, affects scope table entry
7808
7809 if No (Name) then
7810 Scope_Stack.Table
7811 (Scope_Stack.Last).Component_Alignment_Default := Atype;
7812
7813 -- Case of name supplied
7814
7815 else
7816 Check_Arg_Is_Local_Name (Name);
7817 Find_Type (Name);
7818 Typ := Entity (Name);
7819
7820 if Typ = Any_Type
7821 or else Rep_Item_Too_Early (Typ, N)
7822 then
7823 return;
7824 else
7825 Typ := Underlying_Type (Typ);
7826 end if;
7827
7828 if not Is_Record_Type (Typ)
7829 and then not Is_Array_Type (Typ)
7830 then
7831 Error_Pragma_Arg
7832 ("Name parameter of pragma% must identify record or " &
7833 "array type", Name);
7834 end if;
7835
7836 -- An explicit Component_Alignment pragma overrides an
7837 -- implicit pragma Pack, but not an explicit one.
7838
7839 if not Has_Pragma_Pack (Base_Type (Typ)) then
7840 Set_Is_Packed (Base_Type (Typ), False);
7841 Set_Component_Alignment (Base_Type (Typ), Atype);
7842 end if;
7843 end if;
7844 end Component_AlignmentP;
7845
7846 -------------------
7847 -- Contract_Case --
7848 -------------------
7849
7850 -- pragma Contract_Case
7851 -- ([Name =>] Static_String_EXPRESSION
7852 -- ,[Mode =>] MODE_TYPE
7853 -- [, Requires => Boolean_EXPRESSION]
7854 -- [, Ensures => Boolean_EXPRESSION]);
7855
7856 -- MODE_TYPE ::= Nominal | Robustness
7857
7858 when Pragma_Contract_Case =>
7859 Check_Contract_Or_Test_Case;
7860
7861 --------------------
7862 -- Contract_Cases --
7863 --------------------
7864
7865 -- pragma Contract_Cases (CONTRACT_CASE_LIST);
7866
7867 -- CONTRACT_CASE_LIST ::= CONTRACT_CASE {, CONTRACT_CASE}
7868
7869 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
7870
7871 -- CASE_GUARD ::= boolean_EXPRESSION | others
7872
7873 -- CONSEQUENCE ::= boolean_EXPRESSION
7874
7875 when Pragma_Contract_Cases => Contract_Cases : declare
7876 procedure Chain_Contract_Cases (Subp_Decl : Node_Id);
7877 -- Chain pragma Contract_Cases to the contract of a subprogram.
7878 -- Subp_Decl is the declaration of the subprogram.
7879
7880 --------------------------
7881 -- Chain_Contract_Cases --
7882 --------------------------
7883
7884 procedure Chain_Contract_Cases (Subp_Decl : Node_Id) is
7885 Subp : constant Entity_Id :=
7886 Defining_Unit_Name (Specification (Subp_Decl));
7887 CTC : Node_Id;
7888
7889 begin
7890 Check_Duplicate_Pragma (Subp);
7891 CTC := Spec_CTC_List (Contract (Subp));
7892 while Present (CTC) loop
7893 if Chars (Pragma_Identifier (CTC)) = Pname then
7894 Error_Msg_Name_1 := Pname;
7895 Error_Msg_Sloc := Sloc (CTC);
7896
7897 if From_Aspect_Specification (CTC) then
7898 Error_Msg_NE
7899 ("aspect% for & previously given#", N, Subp);
7900 else
7901 Error_Msg_NE
7902 ("pragma% for & duplicates pragma#", N, Subp);
7903 end if;
7904
7905 raise Pragma_Exit;
7906 end if;
7907
7908 CTC := Next_Pragma (CTC);
7909 end loop;
7910
7911 -- Prepend pragma Contract_Cases to the contract
7912
7913 Set_Next_Pragma (N, Spec_CTC_List (Contract (Subp)));
7914 Set_Spec_CTC_List (Contract (Subp), N);
7915 end Chain_Contract_Cases;
7916
7917 -- Local variables
7918
7919 Case_Guard : Node_Id;
7920 Decl : Node_Id;
7921 Extra : Node_Id;
7922 Others_Seen : Boolean := False;
7923 Contract_Case : Node_Id;
7924 Subp_Decl : Node_Id;
7925
7926 -- Start of processing for Contract_Cases
7927
7928 begin
7929 GNAT_Pragma;
7930 S14_Pragma;
7931 Check_Arg_Count (1);
7932
7933 -- Completely ignore if disabled
7934
7935 if Check_Disabled (Pname) then
7936 Rewrite (N, Make_Null_Statement (Loc));
7937 Analyze (N);
7938 return;
7939 end if;
7940
7941 -- Check the placement of the pragma
7942
7943 if not Is_List_Member (N) then
7944 Pragma_Misplaced;
7945 end if;
7946
7947 -- Pragma Contract_Cases must be associated with a subprogram
7948
7949 Decl := N;
7950 while Present (Prev (Decl)) loop
7951 Decl := Prev (Decl);
7952
7953 if Nkind (Decl) in N_Generic_Declaration then
7954 Subp_Decl := Decl;
7955 else
7956 Subp_Decl := Original_Node (Decl);
7957 end if;
7958
7959 -- Skip prior pragmas
7960
7961 if Nkind (Subp_Decl) = N_Pragma then
7962 null;
7963
7964 -- Skip internally generated code
7965
7966 elsif not Comes_From_Source (Subp_Decl) then
7967 null;
7968
7969 -- We have found the related subprogram
7970
7971 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
7972 N_Subprogram_Declaration)
7973 then
7974 exit;
7975
7976 else
7977 Pragma_Misplaced;
7978 end if;
7979 end loop;
7980
7981 -- All contract cases must appear as an aggregate
7982
7983 if Nkind (Expression (Arg1)) /= N_Aggregate then
7984 Error_Pragma ("wrong syntax for pragma %");
7985 return;
7986 end if;
7987
7988 -- Verify the legality of individual contract cases
7989
7990 Contract_Case :=
7991 First (Component_Associations (Expression (Arg1)));
7992 while Present (Contract_Case) loop
7993 if Nkind (Contract_Case) /= N_Component_Association then
7994 Error_Pragma_Arg
7995 ("wrong syntax in contract case", Contract_Case);
7996 return;
7997 end if;
7998
7999 Case_Guard := First (Choices (Contract_Case));
8000
8001 -- Each contract case must have exactly on case guard
8002
8003 Extra := Next (Case_Guard);
8004 if Present (Extra) then
8005 Error_Pragma_Arg
8006 ("contract case may have only one case guard", Extra);
8007 return;
8008 end if;
8009
8010 -- Check the placement of "others" (if available)
8011
8012 if Nkind (Case_Guard) = N_Others_Choice then
8013 if Others_Seen then
8014 Error_Pragma_Arg
8015 ("only one others choice allowed in pragma %",
8016 Case_Guard);
8017 return;
8018 else
8019 Others_Seen := True;
8020 end if;
8021
8022 elsif Others_Seen then
8023 Error_Pragma_Arg
8024 ("others must be the last choice in pragma %", N);
8025 return;
8026 end if;
8027
8028 Next (Contract_Case);
8029 end loop;
8030
8031 Chain_Contract_Cases (Subp_Decl);
8032 end Contract_Cases;
8033
8034 ----------------
8035 -- Controlled --
8036 ----------------
8037
8038 -- pragma Controlled (first_subtype_LOCAL_NAME);
8039
8040 when Pragma_Controlled => Controlled : declare
8041 Arg : Node_Id;
8042
8043 begin
8044 Check_No_Identifiers;
8045 Check_Arg_Count (1);
8046 Check_Arg_Is_Local_Name (Arg1);
8047 Arg := Get_Pragma_Arg (Arg1);
8048
8049 if not Is_Entity_Name (Arg)
8050 or else not Is_Access_Type (Entity (Arg))
8051 then
8052 Error_Pragma_Arg ("pragma% requires access type", Arg1);
8053 else
8054 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
8055 end if;
8056 end Controlled;
8057
8058 ----------------
8059 -- Convention --
8060 ----------------
8061
8062 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
8063 -- [Entity =>] LOCAL_NAME);
8064
8065 when Pragma_Convention => Convention : declare
8066 C : Convention_Id;
8067 E : Entity_Id;
8068 pragma Warnings (Off, C);
8069 pragma Warnings (Off, E);
8070 begin
8071 Check_Arg_Order ((Name_Convention, Name_Entity));
8072 Check_Ada_83_Warning;
8073 Check_Arg_Count (2);
8074 Process_Convention (C, E);
8075 end Convention;
8076
8077 ---------------------------
8078 -- Convention_Identifier --
8079 ---------------------------
8080
8081 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
8082 -- [Convention =>] convention_IDENTIFIER);
8083
8084 when Pragma_Convention_Identifier => Convention_Identifier : declare
8085 Idnam : Name_Id;
8086 Cname : Name_Id;
8087
8088 begin
8089 GNAT_Pragma;
8090 Check_Arg_Order ((Name_Name, Name_Convention));
8091 Check_Arg_Count (2);
8092 Check_Optional_Identifier (Arg1, Name_Name);
8093 Check_Optional_Identifier (Arg2, Name_Convention);
8094 Check_Arg_Is_Identifier (Arg1);
8095 Check_Arg_Is_Identifier (Arg2);
8096 Idnam := Chars (Get_Pragma_Arg (Arg1));
8097 Cname := Chars (Get_Pragma_Arg (Arg2));
8098
8099 if Is_Convention_Name (Cname) then
8100 Record_Convention_Identifier
8101 (Idnam, Get_Convention_Id (Cname));
8102 else
8103 Error_Pragma_Arg
8104 ("second arg for % pragma must be convention", Arg2);
8105 end if;
8106 end Convention_Identifier;
8107
8108 ---------------
8109 -- CPP_Class --
8110 ---------------
8111
8112 -- pragma CPP_Class ([Entity =>] local_NAME)
8113
8114 when Pragma_CPP_Class => CPP_Class : declare
8115 begin
8116 GNAT_Pragma;
8117
8118 if Warn_On_Obsolescent_Feature then
8119 -- Following message is obsolete ???
8120 Error_Msg_N
8121 ("'G'N'A'T pragma cpp'_class is now obsolete and has no " &
8122 "effect; replace it by pragma import?", N);
8123 end if;
8124
8125 Check_Arg_Count (1);
8126
8127 Rewrite (N,
8128 Make_Pragma (Loc,
8129 Chars => Name_Import,
8130 Pragma_Argument_Associations =>
8131 New_List (
8132 Make_Pragma_Argument_Association (Loc,
8133 Expression => Make_Identifier (Loc, Name_CPP)),
8134 New_Copy (First (Pragma_Argument_Associations (N))))));
8135 Analyze (N);
8136 end CPP_Class;
8137
8138 ---------------------
8139 -- CPP_Constructor --
8140 ---------------------
8141
8142 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
8143 -- [, [External_Name =>] static_string_EXPRESSION ]
8144 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8145
8146 when Pragma_CPP_Constructor => CPP_Constructor : declare
8147 Elmt : Elmt_Id;
8148 Id : Entity_Id;
8149 Def_Id : Entity_Id;
8150 Tag_Typ : Entity_Id;
8151
8152 begin
8153 GNAT_Pragma;
8154 Check_At_Least_N_Arguments (1);
8155 Check_At_Most_N_Arguments (3);
8156 Check_Optional_Identifier (Arg1, Name_Entity);
8157 Check_Arg_Is_Local_Name (Arg1);
8158
8159 Id := Get_Pragma_Arg (Arg1);
8160 Find_Program_Unit_Name (Id);
8161
8162 -- If we did not find the name, we are done
8163
8164 if Etype (Id) = Any_Type then
8165 return;
8166 end if;
8167
8168 Def_Id := Entity (Id);
8169
8170 -- Check if already defined as constructor
8171
8172 if Is_Constructor (Def_Id) then
8173 Error_Msg_N
8174 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
8175 return;
8176 end if;
8177
8178 if Ekind (Def_Id) = E_Function
8179 and then (Is_CPP_Class (Etype (Def_Id))
8180 or else (Is_Class_Wide_Type (Etype (Def_Id))
8181 and then
8182 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
8183 then
8184 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
8185 Error_Msg_N
8186 ("'C'P'P constructor must be defined in the scope of " &
8187 "its returned type", Arg1);
8188 end if;
8189
8190 if Arg_Count >= 2 then
8191 Set_Imported (Def_Id);
8192 Set_Is_Public (Def_Id);
8193 Process_Interface_Name (Def_Id, Arg2, Arg3);
8194 end if;
8195
8196 Set_Has_Completion (Def_Id);
8197 Set_Is_Constructor (Def_Id);
8198 Set_Convention (Def_Id, Convention_CPP);
8199
8200 -- Imported C++ constructors are not dispatching primitives
8201 -- because in C++ they don't have a dispatch table slot.
8202 -- However, in Ada the constructor has the profile of a
8203 -- function that returns a tagged type and therefore it has
8204 -- been treated as a primitive operation during semantic
8205 -- analysis. We now remove it from the list of primitive
8206 -- operations of the type.
8207
8208 if Is_Tagged_Type (Etype (Def_Id))
8209 and then not Is_Class_Wide_Type (Etype (Def_Id))
8210 and then Is_Dispatching_Operation (Def_Id)
8211 then
8212 Tag_Typ := Etype (Def_Id);
8213
8214 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
8215 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
8216 Next_Elmt (Elmt);
8217 end loop;
8218
8219 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
8220 Set_Is_Dispatching_Operation (Def_Id, False);
8221 end if;
8222
8223 -- For backward compatibility, if the constructor returns a
8224 -- class wide type, and we internally change the return type to
8225 -- the corresponding root type.
8226
8227 if Is_Class_Wide_Type (Etype (Def_Id)) then
8228 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
8229 end if;
8230 else
8231 Error_Pragma_Arg
8232 ("pragma% requires function returning a 'C'P'P_Class type",
8233 Arg1);
8234 end if;
8235 end CPP_Constructor;
8236
8237 -----------------
8238 -- CPP_Virtual --
8239 -----------------
8240
8241 when Pragma_CPP_Virtual => CPP_Virtual : declare
8242 begin
8243 GNAT_Pragma;
8244
8245 if Warn_On_Obsolescent_Feature then
8246 Error_Msg_N
8247 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
8248 "no effect?", N);
8249 end if;
8250 end CPP_Virtual;
8251
8252 ----------------
8253 -- CPP_Vtable --
8254 ----------------
8255
8256 when Pragma_CPP_Vtable => CPP_Vtable : declare
8257 begin
8258 GNAT_Pragma;
8259
8260 if Warn_On_Obsolescent_Feature then
8261 Error_Msg_N
8262 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
8263 "no effect?", N);
8264 end if;
8265 end CPP_Vtable;
8266
8267 ---------
8268 -- CPU --
8269 ---------
8270
8271 -- pragma CPU (EXPRESSION);
8272
8273 when Pragma_CPU => CPU : declare
8274 P : constant Node_Id := Parent (N);
8275 Arg : Node_Id;
8276 Ent : Entity_Id;
8277
8278 begin
8279 Ada_2012_Pragma;
8280 Check_No_Identifiers;
8281 Check_Arg_Count (1);
8282
8283 -- Subprogram case
8284
8285 if Nkind (P) = N_Subprogram_Body then
8286 Check_In_Main_Program;
8287
8288 Arg := Get_Pragma_Arg (Arg1);
8289 Analyze_And_Resolve (Arg, Any_Integer);
8290
8291 Ent := Defining_Unit_Name (Specification (P));
8292
8293 if Nkind (Ent) = N_Defining_Program_Unit_Name then
8294 Ent := Defining_Identifier (Ent);
8295 end if;
8296
8297 -- Must be static
8298
8299 if not Is_Static_Expression (Arg) then
8300 Flag_Non_Static_Expr
8301 ("main subprogram affinity is not static!", Arg);
8302 raise Pragma_Exit;
8303
8304 -- If constraint error, then we already signalled an error
8305
8306 elsif Raises_Constraint_Error (Arg) then
8307 null;
8308
8309 -- Otherwise check in range
8310
8311 else
8312 declare
8313 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
8314 -- This is the entity System.Multiprocessors.CPU_Range;
8315
8316 Val : constant Uint := Expr_Value (Arg);
8317
8318 begin
8319 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
8320 or else
8321 Val > Expr_Value (Type_High_Bound (CPU_Id))
8322 then
8323 Error_Pragma_Arg
8324 ("main subprogram CPU is out of range", Arg1);
8325 end if;
8326 end;
8327 end if;
8328
8329 Set_Main_CPU
8330 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8331
8332 -- Task case
8333
8334 elsif Nkind (P) = N_Task_Definition then
8335 Arg := Get_Pragma_Arg (Arg1);
8336 Ent := Defining_Identifier (Parent (P));
8337
8338 -- The expression must be analyzed in the special manner
8339 -- described in "Handling of Default and Per-Object
8340 -- Expressions" in sem.ads.
8341
8342 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
8343
8344 -- Anything else is incorrect
8345
8346 else
8347 Pragma_Misplaced;
8348 end if;
8349
8350 -- Check duplicate pragma before we chain the pragma in the Rep
8351 -- Item chain of Ent.
8352
8353 Check_Duplicate_Pragma (Ent);
8354 Record_Rep_Item (Ent, N);
8355 end CPU;
8356
8357 -----------
8358 -- Debug --
8359 -----------
8360
8361 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
8362
8363 when Pragma_Debug => Debug : declare
8364 Cond : Node_Id;
8365 Call : Node_Id;
8366
8367 begin
8368 GNAT_Pragma;
8369
8370 -- Skip analysis if disabled
8371
8372 if Debug_Pragmas_Disabled then
8373 Rewrite (N, Make_Null_Statement (Loc));
8374 Analyze (N);
8375 return;
8376 end if;
8377
8378 Cond :=
8379 New_Occurrence_Of
8380 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
8381 Loc);
8382
8383 if Debug_Pragmas_Enabled then
8384 Set_SCO_Pragma_Enabled (Loc);
8385 end if;
8386
8387 if Arg_Count = 2 then
8388 Cond :=
8389 Make_And_Then (Loc,
8390 Left_Opnd => Relocate_Node (Cond),
8391 Right_Opnd => Get_Pragma_Arg (Arg1));
8392 Call := Get_Pragma_Arg (Arg2);
8393 else
8394 Call := Get_Pragma_Arg (Arg1);
8395 end if;
8396
8397 if Nkind_In (Call,
8398 N_Indexed_Component,
8399 N_Function_Call,
8400 N_Identifier,
8401 N_Expanded_Name,
8402 N_Selected_Component)
8403 then
8404 -- If this pragma Debug comes from source, its argument was
8405 -- parsed as a name form (which is syntactically identical).
8406 -- In a generic context a parameterless call will be left as
8407 -- an expanded name (if global) or selected_component if local.
8408 -- Change it to a procedure call statement now.
8409
8410 Change_Name_To_Procedure_Call_Statement (Call);
8411
8412 elsif Nkind (Call) = N_Procedure_Call_Statement then
8413
8414 -- Already in the form of a procedure call statement: nothing
8415 -- to do (could happen in case of an internally generated
8416 -- pragma Debug).
8417
8418 null;
8419
8420 else
8421 -- All other cases: diagnose error
8422
8423 Error_Msg
8424 ("argument of pragma ""Debug"" is not procedure call",
8425 Sloc (Call));
8426 return;
8427 end if;
8428
8429 -- Rewrite into a conditional with an appropriate condition. We
8430 -- wrap the procedure call in a block so that overhead from e.g.
8431 -- use of the secondary stack does not generate execution overhead
8432 -- for suppressed conditions.
8433
8434 -- Normally the analysis that follows will freeze the subprogram
8435 -- being called. However, if the call is to a null procedure,
8436 -- we want to freeze it before creating the block, because the
8437 -- analysis that follows may be done with expansion disabled, in
8438 -- which case the body will not be generated, leading to spurious
8439 -- errors.
8440
8441 if Nkind (Call) = N_Procedure_Call_Statement
8442 and then Is_Entity_Name (Name (Call))
8443 then
8444 Analyze (Name (Call));
8445 Freeze_Before (N, Entity (Name (Call)));
8446 end if;
8447
8448 Rewrite (N, Make_Implicit_If_Statement (N,
8449 Condition => Cond,
8450 Then_Statements => New_List (
8451 Make_Block_Statement (Loc,
8452 Handled_Statement_Sequence =>
8453 Make_Handled_Sequence_Of_Statements (Loc,
8454 Statements => New_List (Relocate_Node (Call)))))));
8455 Analyze (N);
8456 end Debug;
8457
8458 ------------------
8459 -- Debug_Policy --
8460 ------------------
8461
8462 -- pragma Debug_Policy (Check | Ignore)
8463
8464 when Pragma_Debug_Policy =>
8465 GNAT_Pragma;
8466 Check_Arg_Count (1);
8467 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
8468 Debug_Pragmas_Enabled :=
8469 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
8470 Debug_Pragmas_Disabled :=
8471 Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
8472
8473 ---------------------
8474 -- Detect_Blocking --
8475 ---------------------
8476
8477 -- pragma Detect_Blocking;
8478
8479 when Pragma_Detect_Blocking =>
8480 Ada_2005_Pragma;
8481 Check_Arg_Count (0);
8482 Check_Valid_Configuration_Pragma;
8483 Detect_Blocking := True;
8484
8485 --------------------------
8486 -- Default_Storage_Pool --
8487 --------------------------
8488
8489 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
8490
8491 when Pragma_Default_Storage_Pool =>
8492 Ada_2012_Pragma;
8493 Check_Arg_Count (1);
8494
8495 -- Default_Storage_Pool can appear as a configuration pragma, or
8496 -- in a declarative part or a package spec.
8497
8498 if not Is_Configuration_Pragma then
8499 Check_Is_In_Decl_Part_Or_Package_Spec;
8500 end if;
8501
8502 -- Case of Default_Storage_Pool (null);
8503
8504 if Nkind (Expression (Arg1)) = N_Null then
8505 Analyze (Expression (Arg1));
8506
8507 -- This is an odd case, this is not really an expression, so
8508 -- we don't have a type for it. So just set the type to Empty.
8509
8510 Set_Etype (Expression (Arg1), Empty);
8511
8512 -- Case of Default_Storage_Pool (storage_pool_NAME);
8513
8514 else
8515 -- If it's a configuration pragma, then the only allowed
8516 -- argument is "null".
8517
8518 if Is_Configuration_Pragma then
8519 Error_Pragma_Arg ("NULL expected", Arg1);
8520 end if;
8521
8522 -- The expected type for a non-"null" argument is
8523 -- Root_Storage_Pool'Class.
8524
8525 Analyze_And_Resolve
8526 (Get_Pragma_Arg (Arg1),
8527 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8528 end if;
8529
8530 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
8531 -- for an access type will use this information to set the
8532 -- appropriate attributes of the access type.
8533
8534 Default_Pool := Expression (Arg1);
8535
8536 ------------------------------------
8537 -- Disable_Atomic_Synchronization --
8538 ------------------------------------
8539
8540 -- pragma Disable_Atomic_Synchronization [(Entity)];
8541
8542 when Pragma_Disable_Atomic_Synchronization =>
8543 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8544
8545 -------------------
8546 -- Discard_Names --
8547 -------------------
8548
8549 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
8550
8551 when Pragma_Discard_Names => Discard_Names : declare
8552 E : Entity_Id;
8553 E_Id : Entity_Id;
8554
8555 begin
8556 Check_Ada_83_Warning;
8557
8558 -- Deal with configuration pragma case
8559
8560 if Arg_Count = 0 and then Is_Configuration_Pragma then
8561 Global_Discard_Names := True;
8562 return;
8563
8564 -- Otherwise, check correct appropriate context
8565
8566 else
8567 Check_Is_In_Decl_Part_Or_Package_Spec;
8568
8569 if Arg_Count = 0 then
8570
8571 -- If there is no parameter, then from now on this pragma
8572 -- applies to any enumeration, exception or tagged type
8573 -- defined in the current declarative part, and recursively
8574 -- to any nested scope.
8575
8576 Set_Discard_Names (Current_Scope);
8577 return;
8578
8579 else
8580 Check_Arg_Count (1);
8581 Check_Optional_Identifier (Arg1, Name_On);
8582 Check_Arg_Is_Local_Name (Arg1);
8583
8584 E_Id := Get_Pragma_Arg (Arg1);
8585
8586 if Etype (E_Id) = Any_Type then
8587 return;
8588 else
8589 E := Entity (E_Id);
8590 end if;
8591
8592 if (Is_First_Subtype (E)
8593 and then
8594 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8595 or else Ekind (E) = E_Exception
8596 then
8597 Set_Discard_Names (E);
8598 Record_Rep_Item (E, N);
8599
8600 else
8601 Error_Pragma_Arg
8602 ("inappropriate entity for pragma%", Arg1);
8603 end if;
8604
8605 end if;
8606 end if;
8607 end Discard_Names;
8608
8609 ------------------------
8610 -- Dispatching_Domain --
8611 ------------------------
8612
8613 -- pragma Dispatching_Domain (EXPRESSION);
8614
8615 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
8616 P : constant Node_Id := Parent (N);
8617 Arg : Node_Id;
8618 Ent : Entity_Id;
8619
8620 begin
8621 Ada_2012_Pragma;
8622 Check_No_Identifiers;
8623 Check_Arg_Count (1);
8624
8625 -- This pragma is born obsolete, but not the aspect
8626
8627 if not From_Aspect_Specification (N) then
8628 Check_Restriction
8629 (No_Obsolescent_Features, Pragma_Identifier (N));
8630 end if;
8631
8632 if Nkind (P) = N_Task_Definition then
8633 Arg := Get_Pragma_Arg (Arg1);
8634 Ent := Defining_Identifier (Parent (P));
8635
8636 -- The expression must be analyzed in the special manner
8637 -- described in "Handling of Default and Per-Object
8638 -- Expressions" in sem.ads.
8639
8640 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8641
8642 -- Check duplicate pragma before we chain the pragma in the Rep
8643 -- Item chain of Ent.
8644
8645 Check_Duplicate_Pragma (Ent);
8646 Record_Rep_Item (Ent, N);
8647
8648 -- Anything else is incorrect
8649
8650 else
8651 Pragma_Misplaced;
8652 end if;
8653 end Dispatching_Domain;
8654
8655 ---------------
8656 -- Elaborate --
8657 ---------------
8658
8659 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8660
8661 when Pragma_Elaborate => Elaborate : declare
8662 Arg : Node_Id;
8663 Citem : Node_Id;
8664
8665 begin
8666 -- Pragma must be in context items list of a compilation unit
8667
8668 if not Is_In_Context_Clause then
8669 Pragma_Misplaced;
8670 end if;
8671
8672 -- Must be at least one argument
8673
8674 if Arg_Count = 0 then
8675 Error_Pragma ("pragma% requires at least one argument");
8676 end if;
8677
8678 -- In Ada 83 mode, there can be no items following it in the
8679 -- context list except other pragmas and implicit with clauses
8680 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8681 -- placement rule does not apply.
8682
8683 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8684 Citem := Next (N);
8685 while Present (Citem) loop
8686 if Nkind (Citem) = N_Pragma
8687 or else (Nkind (Citem) = N_With_Clause
8688 and then Implicit_With (Citem))
8689 then
8690 null;
8691 else
8692 Error_Pragma
8693 ("(Ada 83) pragma% must be at end of context clause");
8694 end if;
8695
8696 Next (Citem);
8697 end loop;
8698 end if;
8699
8700 -- Finally, the arguments must all be units mentioned in a with
8701 -- clause in the same context clause. Note we already checked (in
8702 -- Par.Prag) that the arguments are all identifiers or selected
8703 -- components.
8704
8705 Arg := Arg1;
8706 Outer : while Present (Arg) loop
8707 Citem := First (List_Containing (N));
8708 Inner : while Citem /= N loop
8709 if Nkind (Citem) = N_With_Clause
8710 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8711 then
8712 Set_Elaborate_Present (Citem, True);
8713 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8714 Generate_Reference (Entity (Name (Citem)), Citem);
8715
8716 -- With the pragma present, elaboration calls on
8717 -- subprograms from the named unit need no further
8718 -- checks, as long as the pragma appears in the current
8719 -- compilation unit. If the pragma appears in some unit
8720 -- in the context, there might still be a need for an
8721 -- Elaborate_All_Desirable from the current compilation
8722 -- to the named unit, so we keep the check enabled.
8723
8724 if In_Extended_Main_Source_Unit (N) then
8725 Set_Suppress_Elaboration_Warnings
8726 (Entity (Name (Citem)));
8727 end if;
8728
8729 exit Inner;
8730 end if;
8731
8732 Next (Citem);
8733 end loop Inner;
8734
8735 if Citem = N then
8736 Error_Pragma_Arg
8737 ("argument of pragma% is not withed unit", Arg);
8738 end if;
8739
8740 Next (Arg);
8741 end loop Outer;
8742
8743 -- Give a warning if operating in static mode with -gnatwl
8744 -- (elaboration warnings enabled) switch set.
8745
8746 if Elab_Warnings and not Dynamic_Elaboration_Checks then
8747 Error_Msg_N
8748 ("?use of pragma Elaborate may not be safe", N);
8749 Error_Msg_N
8750 ("?use pragma Elaborate_All instead if possible", N);
8751 end if;
8752 end Elaborate;
8753
8754 -------------------
8755 -- Elaborate_All --
8756 -------------------
8757
8758 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8759
8760 when Pragma_Elaborate_All => Elaborate_All : declare
8761 Arg : Node_Id;
8762 Citem : Node_Id;
8763
8764 begin
8765 Check_Ada_83_Warning;
8766
8767 -- Pragma must be in context items list of a compilation unit
8768
8769 if not Is_In_Context_Clause then
8770 Pragma_Misplaced;
8771 end if;
8772
8773 -- Must be at least one argument
8774
8775 if Arg_Count = 0 then
8776 Error_Pragma ("pragma% requires at least one argument");
8777 end if;
8778
8779 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
8780 -- have to appear at the end of the context clause, but may
8781 -- appear mixed in with other items, even in Ada 83 mode.
8782
8783 -- Final check: the arguments must all be units mentioned in
8784 -- a with clause in the same context clause. Note that we
8785 -- already checked (in Par.Prag) that all the arguments are
8786 -- either identifiers or selected components.
8787
8788 Arg := Arg1;
8789 Outr : while Present (Arg) loop
8790 Citem := First (List_Containing (N));
8791 Innr : while Citem /= N loop
8792 if Nkind (Citem) = N_With_Clause
8793 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8794 then
8795 Set_Elaborate_All_Present (Citem, True);
8796 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8797
8798 -- Suppress warnings and elaboration checks on the named
8799 -- unit if the pragma is in the current compilation, as
8800 -- for pragma Elaborate.
8801
8802 if In_Extended_Main_Source_Unit (N) then
8803 Set_Suppress_Elaboration_Warnings
8804 (Entity (Name (Citem)));
8805 end if;
8806 exit Innr;
8807 end if;
8808
8809 Next (Citem);
8810 end loop Innr;
8811
8812 if Citem = N then
8813 Set_Error_Posted (N);
8814 Error_Pragma_Arg
8815 ("argument of pragma% is not withed unit", Arg);
8816 end if;
8817
8818 Next (Arg);
8819 end loop Outr;
8820 end Elaborate_All;
8821
8822 --------------------
8823 -- Elaborate_Body --
8824 --------------------
8825
8826 -- pragma Elaborate_Body [( library_unit_NAME )];
8827
8828 when Pragma_Elaborate_Body => Elaborate_Body : declare
8829 Cunit_Node : Node_Id;
8830 Cunit_Ent : Entity_Id;
8831
8832 begin
8833 Check_Ada_83_Warning;
8834 Check_Valid_Library_Unit_Pragma;
8835
8836 if Nkind (N) = N_Null_Statement then
8837 return;
8838 end if;
8839
8840 Cunit_Node := Cunit (Current_Sem_Unit);
8841 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8842
8843 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8844 N_Subprogram_Body)
8845 then
8846 Error_Pragma ("pragma% must refer to a spec, not a body");
8847 else
8848 Set_Body_Required (Cunit_Node, True);
8849 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8850
8851 -- If we are in dynamic elaboration mode, then we suppress
8852 -- elaboration warnings for the unit, since it is definitely
8853 -- fine NOT to do dynamic checks at the first level (and such
8854 -- checks will be suppressed because no elaboration boolean
8855 -- is created for Elaborate_Body packages).
8856
8857 -- But in the static model of elaboration, Elaborate_Body is
8858 -- definitely NOT good enough to ensure elaboration safety on
8859 -- its own, since the body may WITH other units that are not
8860 -- safe from an elaboration point of view, so a client must
8861 -- still do an Elaborate_All on such units.
8862
8863 -- Debug flag -gnatdD restores the old behavior of 3.13, where
8864 -- Elaborate_Body always suppressed elab warnings.
8865
8866 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8867 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8868 end if;
8869 end if;
8870 end Elaborate_Body;
8871
8872 ------------------------
8873 -- Elaboration_Checks --
8874 ------------------------
8875
8876 -- pragma Elaboration_Checks (Static | Dynamic);
8877
8878 when Pragma_Elaboration_Checks =>
8879 GNAT_Pragma;
8880 Check_Arg_Count (1);
8881 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8882 Dynamic_Elaboration_Checks :=
8883 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8884
8885 ---------------
8886 -- Eliminate --
8887 ---------------
8888
8889 -- pragma Eliminate (
8890 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
8891 -- [,[Entity =>] IDENTIFIER |
8892 -- SELECTED_COMPONENT |
8893 -- STRING_LITERAL]
8894 -- [, OVERLOADING_RESOLUTION]);
8895
8896 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8897 -- SOURCE_LOCATION
8898
8899 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8900 -- FUNCTION_PROFILE
8901
8902 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8903
8904 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8905 -- Result_Type => result_SUBTYPE_NAME]
8906
8907 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8908 -- SUBTYPE_NAME ::= STRING_LITERAL
8909
8910 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8911 -- SOURCE_TRACE ::= STRING_LITERAL
8912
8913 when Pragma_Eliminate => Eliminate : declare
8914 Args : Args_List (1 .. 5);
8915 Names : constant Name_List (1 .. 5) := (
8916 Name_Unit_Name,
8917 Name_Entity,
8918 Name_Parameter_Types,
8919 Name_Result_Type,
8920 Name_Source_Location);
8921
8922 Unit_Name : Node_Id renames Args (1);
8923 Entity : Node_Id renames Args (2);
8924 Parameter_Types : Node_Id renames Args (3);
8925 Result_Type : Node_Id renames Args (4);
8926 Source_Location : Node_Id renames Args (5);
8927
8928 begin
8929 GNAT_Pragma;
8930 Check_Valid_Configuration_Pragma;
8931 Gather_Associations (Names, Args);
8932
8933 if No (Unit_Name) then
8934 Error_Pragma ("missing Unit_Name argument for pragma%");
8935 end if;
8936
8937 if No (Entity)
8938 and then (Present (Parameter_Types)
8939 or else
8940 Present (Result_Type)
8941 or else
8942 Present (Source_Location))
8943 then
8944 Error_Pragma ("missing Entity argument for pragma%");
8945 end if;
8946
8947 if (Present (Parameter_Types)
8948 or else
8949 Present (Result_Type))
8950 and then
8951 Present (Source_Location)
8952 then
8953 Error_Pragma
8954 ("parameter profile and source location cannot " &
8955 "be used together in pragma%");
8956 end if;
8957
8958 Process_Eliminate_Pragma
8959 (N,
8960 Unit_Name,
8961 Entity,
8962 Parameter_Types,
8963 Result_Type,
8964 Source_Location);
8965 end Eliminate;
8966
8967 -----------------------------------
8968 -- Enable_Atomic_Synchronization --
8969 -----------------------------------
8970
8971 -- pragma Enable_Atomic_Synchronization [(Entity)];
8972
8973 when Pragma_Enable_Atomic_Synchronization =>
8974 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
8975
8976 ------------
8977 -- Export --
8978 ------------
8979
8980 -- pragma Export (
8981 -- [ Convention =>] convention_IDENTIFIER,
8982 -- [ Entity =>] local_NAME
8983 -- [, [External_Name =>] static_string_EXPRESSION ]
8984 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8985
8986 when Pragma_Export => Export : declare
8987 C : Convention_Id;
8988 Def_Id : Entity_Id;
8989
8990 pragma Warnings (Off, C);
8991
8992 begin
8993 Check_Ada_83_Warning;
8994 Check_Arg_Order
8995 ((Name_Convention,
8996 Name_Entity,
8997 Name_External_Name,
8998 Name_Link_Name));
8999
9000 Check_At_Least_N_Arguments (2);
9001
9002 Check_At_Most_N_Arguments (4);
9003 Process_Convention (C, Def_Id);
9004
9005 if Ekind (Def_Id) /= E_Constant then
9006 Note_Possible_Modification
9007 (Get_Pragma_Arg (Arg2), Sure => False);
9008 end if;
9009
9010 Process_Interface_Name (Def_Id, Arg3, Arg4);
9011 Set_Exported (Def_Id, Arg2);
9012
9013 -- If the entity is a deferred constant, propagate the information
9014 -- to the full view, because gigi elaborates the full view only.
9015
9016 if Ekind (Def_Id) = E_Constant
9017 and then Present (Full_View (Def_Id))
9018 then
9019 declare
9020 Id2 : constant Entity_Id := Full_View (Def_Id);
9021 begin
9022 Set_Is_Exported (Id2, Is_Exported (Def_Id));
9023 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
9024 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
9025 end;
9026 end if;
9027 end Export;
9028
9029 ----------------------
9030 -- Export_Exception --
9031 ----------------------
9032
9033 -- pragma Export_Exception (
9034 -- [Internal =>] LOCAL_NAME
9035 -- [, [External =>] EXTERNAL_SYMBOL]
9036 -- [, [Form =>] Ada | VMS]
9037 -- [, [Code =>] static_integer_EXPRESSION]);
9038
9039 when Pragma_Export_Exception => Export_Exception : declare
9040 Args : Args_List (1 .. 4);
9041 Names : constant Name_List (1 .. 4) := (
9042 Name_Internal,
9043 Name_External,
9044 Name_Form,
9045 Name_Code);
9046
9047 Internal : Node_Id renames Args (1);
9048 External : Node_Id renames Args (2);
9049 Form : Node_Id renames Args (3);
9050 Code : Node_Id renames Args (4);
9051
9052 begin
9053 GNAT_Pragma;
9054
9055 if Inside_A_Generic then
9056 Error_Pragma ("pragma% cannot be used for generic entities");
9057 end if;
9058
9059 Gather_Associations (Names, Args);
9060 Process_Extended_Import_Export_Exception_Pragma (
9061 Arg_Internal => Internal,
9062 Arg_External => External,
9063 Arg_Form => Form,
9064 Arg_Code => Code);
9065
9066 if not Is_VMS_Exception (Entity (Internal)) then
9067 Set_Exported (Entity (Internal), Internal);
9068 end if;
9069 end Export_Exception;
9070
9071 ---------------------
9072 -- Export_Function --
9073 ---------------------
9074
9075 -- pragma Export_Function (
9076 -- [Internal =>] LOCAL_NAME
9077 -- [, [External =>] EXTERNAL_SYMBOL]
9078 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9079 -- [, [Result_Type =>] TYPE_DESIGNATOR]
9080 -- [, [Mechanism =>] MECHANISM]
9081 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
9082
9083 -- EXTERNAL_SYMBOL ::=
9084 -- IDENTIFIER
9085 -- | static_string_EXPRESSION
9086
9087 -- PARAMETER_TYPES ::=
9088 -- null
9089 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9090
9091 -- TYPE_DESIGNATOR ::=
9092 -- subtype_NAME
9093 -- | subtype_Name ' Access
9094
9095 -- MECHANISM ::=
9096 -- MECHANISM_NAME
9097 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9098
9099 -- MECHANISM_ASSOCIATION ::=
9100 -- [formal_parameter_NAME =>] MECHANISM_NAME
9101
9102 -- MECHANISM_NAME ::=
9103 -- Value
9104 -- | Reference
9105 -- | Descriptor [([Class =>] CLASS_NAME)]
9106
9107 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9108
9109 when Pragma_Export_Function => Export_Function : declare
9110 Args : Args_List (1 .. 6);
9111 Names : constant Name_List (1 .. 6) := (
9112 Name_Internal,
9113 Name_External,
9114 Name_Parameter_Types,
9115 Name_Result_Type,
9116 Name_Mechanism,
9117 Name_Result_Mechanism);
9118
9119 Internal : Node_Id renames Args (1);
9120 External : Node_Id renames Args (2);
9121 Parameter_Types : Node_Id renames Args (3);
9122 Result_Type : Node_Id renames Args (4);
9123 Mechanism : Node_Id renames Args (5);
9124 Result_Mechanism : Node_Id renames Args (6);
9125
9126 begin
9127 GNAT_Pragma;
9128 Gather_Associations (Names, Args);
9129 Process_Extended_Import_Export_Subprogram_Pragma (
9130 Arg_Internal => Internal,
9131 Arg_External => External,
9132 Arg_Parameter_Types => Parameter_Types,
9133 Arg_Result_Type => Result_Type,
9134 Arg_Mechanism => Mechanism,
9135 Arg_Result_Mechanism => Result_Mechanism);
9136 end Export_Function;
9137
9138 -------------------
9139 -- Export_Object --
9140 -------------------
9141
9142 -- pragma Export_Object (
9143 -- [Internal =>] LOCAL_NAME
9144 -- [, [External =>] EXTERNAL_SYMBOL]
9145 -- [, [Size =>] EXTERNAL_SYMBOL]);
9146
9147 -- EXTERNAL_SYMBOL ::=
9148 -- IDENTIFIER
9149 -- | static_string_EXPRESSION
9150
9151 -- PARAMETER_TYPES ::=
9152 -- null
9153 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9154
9155 -- TYPE_DESIGNATOR ::=
9156 -- subtype_NAME
9157 -- | subtype_Name ' Access
9158
9159 -- MECHANISM ::=
9160 -- MECHANISM_NAME
9161 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9162
9163 -- MECHANISM_ASSOCIATION ::=
9164 -- [formal_parameter_NAME =>] MECHANISM_NAME
9165
9166 -- MECHANISM_NAME ::=
9167 -- Value
9168 -- | Reference
9169 -- | Descriptor [([Class =>] CLASS_NAME)]
9170
9171 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9172
9173 when Pragma_Export_Object => Export_Object : declare
9174 Args : Args_List (1 .. 3);
9175 Names : constant Name_List (1 .. 3) := (
9176 Name_Internal,
9177 Name_External,
9178 Name_Size);
9179
9180 Internal : Node_Id renames Args (1);
9181 External : Node_Id renames Args (2);
9182 Size : Node_Id renames Args (3);
9183
9184 begin
9185 GNAT_Pragma;
9186 Gather_Associations (Names, Args);
9187 Process_Extended_Import_Export_Object_Pragma (
9188 Arg_Internal => Internal,
9189 Arg_External => External,
9190 Arg_Size => Size);
9191 end Export_Object;
9192
9193 ----------------------
9194 -- Export_Procedure --
9195 ----------------------
9196
9197 -- pragma Export_Procedure (
9198 -- [Internal =>] LOCAL_NAME
9199 -- [, [External =>] EXTERNAL_SYMBOL]
9200 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9201 -- [, [Mechanism =>] MECHANISM]);
9202
9203 -- EXTERNAL_SYMBOL ::=
9204 -- IDENTIFIER
9205 -- | static_string_EXPRESSION
9206
9207 -- PARAMETER_TYPES ::=
9208 -- null
9209 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9210
9211 -- TYPE_DESIGNATOR ::=
9212 -- subtype_NAME
9213 -- | subtype_Name ' Access
9214
9215 -- MECHANISM ::=
9216 -- MECHANISM_NAME
9217 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9218
9219 -- MECHANISM_ASSOCIATION ::=
9220 -- [formal_parameter_NAME =>] MECHANISM_NAME
9221
9222 -- MECHANISM_NAME ::=
9223 -- Value
9224 -- | Reference
9225 -- | Descriptor [([Class =>] CLASS_NAME)]
9226
9227 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9228
9229 when Pragma_Export_Procedure => Export_Procedure : declare
9230 Args : Args_List (1 .. 4);
9231 Names : constant Name_List (1 .. 4) := (
9232 Name_Internal,
9233 Name_External,
9234 Name_Parameter_Types,
9235 Name_Mechanism);
9236
9237 Internal : Node_Id renames Args (1);
9238 External : Node_Id renames Args (2);
9239 Parameter_Types : Node_Id renames Args (3);
9240 Mechanism : Node_Id renames Args (4);
9241
9242 begin
9243 GNAT_Pragma;
9244 Gather_Associations (Names, Args);
9245 Process_Extended_Import_Export_Subprogram_Pragma (
9246 Arg_Internal => Internal,
9247 Arg_External => External,
9248 Arg_Parameter_Types => Parameter_Types,
9249 Arg_Mechanism => Mechanism);
9250 end Export_Procedure;
9251
9252 ------------------
9253 -- Export_Value --
9254 ------------------
9255
9256 -- pragma Export_Value (
9257 -- [Value =>] static_integer_EXPRESSION,
9258 -- [Link_Name =>] static_string_EXPRESSION);
9259
9260 when Pragma_Export_Value =>
9261 GNAT_Pragma;
9262 Check_Arg_Order ((Name_Value, Name_Link_Name));
9263 Check_Arg_Count (2);
9264
9265 Check_Optional_Identifier (Arg1, Name_Value);
9266 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9267
9268 Check_Optional_Identifier (Arg2, Name_Link_Name);
9269 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9270
9271 -----------------------------
9272 -- Export_Valued_Procedure --
9273 -----------------------------
9274
9275 -- pragma Export_Valued_Procedure (
9276 -- [Internal =>] LOCAL_NAME
9277 -- [, [External =>] EXTERNAL_SYMBOL,]
9278 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9279 -- [, [Mechanism =>] MECHANISM]);
9280
9281 -- EXTERNAL_SYMBOL ::=
9282 -- IDENTIFIER
9283 -- | static_string_EXPRESSION
9284
9285 -- PARAMETER_TYPES ::=
9286 -- null
9287 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9288
9289 -- TYPE_DESIGNATOR ::=
9290 -- subtype_NAME
9291 -- | subtype_Name ' Access
9292
9293 -- MECHANISM ::=
9294 -- MECHANISM_NAME
9295 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9296
9297 -- MECHANISM_ASSOCIATION ::=
9298 -- [formal_parameter_NAME =>] MECHANISM_NAME
9299
9300 -- MECHANISM_NAME ::=
9301 -- Value
9302 -- | Reference
9303 -- | Descriptor [([Class =>] CLASS_NAME)]
9304
9305 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9306
9307 when Pragma_Export_Valued_Procedure =>
9308 Export_Valued_Procedure : declare
9309 Args : Args_List (1 .. 4);
9310 Names : constant Name_List (1 .. 4) := (
9311 Name_Internal,
9312 Name_External,
9313 Name_Parameter_Types,
9314 Name_Mechanism);
9315
9316 Internal : Node_Id renames Args (1);
9317 External : Node_Id renames Args (2);
9318 Parameter_Types : Node_Id renames Args (3);
9319 Mechanism : Node_Id renames Args (4);
9320
9321 begin
9322 GNAT_Pragma;
9323 Gather_Associations (Names, Args);
9324 Process_Extended_Import_Export_Subprogram_Pragma (
9325 Arg_Internal => Internal,
9326 Arg_External => External,
9327 Arg_Parameter_Types => Parameter_Types,
9328 Arg_Mechanism => Mechanism);
9329 end Export_Valued_Procedure;
9330
9331 -------------------
9332 -- Extend_System --
9333 -------------------
9334
9335 -- pragma Extend_System ([Name =>] Identifier);
9336
9337 when Pragma_Extend_System => Extend_System : declare
9338 begin
9339 GNAT_Pragma;
9340 Check_Valid_Configuration_Pragma;
9341 Check_Arg_Count (1);
9342 Check_Optional_Identifier (Arg1, Name_Name);
9343 Check_Arg_Is_Identifier (Arg1);
9344
9345 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
9346
9347 if Name_Len > 4
9348 and then Name_Buffer (1 .. 4) = "aux_"
9349 then
9350 if Present (System_Extend_Pragma_Arg) then
9351 if Chars (Get_Pragma_Arg (Arg1)) =
9352 Chars (Expression (System_Extend_Pragma_Arg))
9353 then
9354 null;
9355 else
9356 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
9357 Error_Pragma ("pragma% conflicts with that #");
9358 end if;
9359
9360 else
9361 System_Extend_Pragma_Arg := Arg1;
9362
9363 if not GNAT_Mode then
9364 System_Extend_Unit := Arg1;
9365 end if;
9366 end if;
9367 else
9368 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
9369 end if;
9370 end Extend_System;
9371
9372 ------------------------
9373 -- Extensions_Allowed --
9374 ------------------------
9375
9376 -- pragma Extensions_Allowed (ON | OFF);
9377
9378 when Pragma_Extensions_Allowed =>
9379 GNAT_Pragma;
9380 Check_Arg_Count (1);
9381 Check_No_Identifiers;
9382 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9383
9384 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
9385 Extensions_Allowed := True;
9386 Ada_Version := Ada_Version_Type'Last;
9387
9388 else
9389 Extensions_Allowed := False;
9390 Ada_Version := Ada_Version_Explicit;
9391 end if;
9392
9393 --------------
9394 -- External --
9395 --------------
9396
9397 -- pragma External (
9398 -- [ Convention =>] convention_IDENTIFIER,
9399 -- [ Entity =>] local_NAME
9400 -- [, [External_Name =>] static_string_EXPRESSION ]
9401 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9402
9403 when Pragma_External => External : declare
9404 Def_Id : Entity_Id;
9405
9406 C : Convention_Id;
9407 pragma Warnings (Off, C);
9408
9409 begin
9410 GNAT_Pragma;
9411 Check_Arg_Order
9412 ((Name_Convention,
9413 Name_Entity,
9414 Name_External_Name,
9415 Name_Link_Name));
9416 Check_At_Least_N_Arguments (2);
9417 Check_At_Most_N_Arguments (4);
9418 Process_Convention (C, Def_Id);
9419 Note_Possible_Modification
9420 (Get_Pragma_Arg (Arg2), Sure => False);
9421 Process_Interface_Name (Def_Id, Arg3, Arg4);
9422 Set_Exported (Def_Id, Arg2);
9423 end External;
9424
9425 --------------------------
9426 -- External_Name_Casing --
9427 --------------------------
9428
9429 -- pragma External_Name_Casing (
9430 -- UPPERCASE | LOWERCASE
9431 -- [, AS_IS | UPPERCASE | LOWERCASE]);
9432
9433 when Pragma_External_Name_Casing => External_Name_Casing : declare
9434 begin
9435 GNAT_Pragma;
9436 Check_No_Identifiers;
9437
9438 if Arg_Count = 2 then
9439 Check_Arg_Is_One_Of
9440 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
9441
9442 case Chars (Get_Pragma_Arg (Arg2)) is
9443 when Name_As_Is =>
9444 Opt.External_Name_Exp_Casing := As_Is;
9445
9446 when Name_Uppercase =>
9447 Opt.External_Name_Exp_Casing := Uppercase;
9448
9449 when Name_Lowercase =>
9450 Opt.External_Name_Exp_Casing := Lowercase;
9451
9452 when others =>
9453 null;
9454 end case;
9455
9456 else
9457 Check_Arg_Count (1);
9458 end if;
9459
9460 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
9461
9462 case Chars (Get_Pragma_Arg (Arg1)) is
9463 when Name_Uppercase =>
9464 Opt.External_Name_Imp_Casing := Uppercase;
9465
9466 when Name_Lowercase =>
9467 Opt.External_Name_Imp_Casing := Lowercase;
9468
9469 when others =>
9470 null;
9471 end case;
9472 end External_Name_Casing;
9473
9474 --------------------------
9475 -- Favor_Top_Level --
9476 --------------------------
9477
9478 -- pragma Favor_Top_Level (type_NAME);
9479
9480 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
9481 Named_Entity : Entity_Id;
9482
9483 begin
9484 GNAT_Pragma;
9485 Check_No_Identifiers;
9486 Check_Arg_Count (1);
9487 Check_Arg_Is_Local_Name (Arg1);
9488 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
9489
9490 -- If it's an access-to-subprogram type (in particular, not a
9491 -- subtype), set the flag on that type.
9492
9493 if Is_Access_Subprogram_Type (Named_Entity) then
9494 Set_Can_Use_Internal_Rep (Named_Entity, False);
9495
9496 -- Otherwise it's an error (name denotes the wrong sort of entity)
9497
9498 else
9499 Error_Pragma_Arg
9500 ("access-to-subprogram type expected",
9501 Get_Pragma_Arg (Arg1));
9502 end if;
9503 end Favor_Top_Level;
9504
9505 ---------------
9506 -- Fast_Math --
9507 ---------------
9508
9509 -- pragma Fast_Math;
9510
9511 when Pragma_Fast_Math =>
9512 GNAT_Pragma;
9513 Check_No_Identifiers;
9514 Check_Valid_Configuration_Pragma;
9515 Fast_Math := True;
9516
9517 ---------------------------
9518 -- Finalize_Storage_Only --
9519 ---------------------------
9520
9521 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9522
9523 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
9524 Assoc : constant Node_Id := Arg1;
9525 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
9526 Typ : Entity_Id;
9527
9528 begin
9529 GNAT_Pragma;
9530 Check_No_Identifiers;
9531 Check_Arg_Count (1);
9532 Check_Arg_Is_Local_Name (Arg1);
9533
9534 Find_Type (Type_Id);
9535 Typ := Entity (Type_Id);
9536
9537 if Typ = Any_Type
9538 or else Rep_Item_Too_Early (Typ, N)
9539 then
9540 return;
9541 else
9542 Typ := Underlying_Type (Typ);
9543 end if;
9544
9545 if not Is_Controlled (Typ) then
9546 Error_Pragma ("pragma% must specify controlled type");
9547 end if;
9548
9549 Check_First_Subtype (Arg1);
9550
9551 if Finalize_Storage_Only (Typ) then
9552 Error_Pragma ("duplicate pragma%, only one allowed");
9553
9554 elsif not Rep_Item_Too_Late (Typ, N) then
9555 Set_Finalize_Storage_Only (Base_Type (Typ), True);
9556 end if;
9557 end Finalize_Storage;
9558
9559 --------------------------
9560 -- Float_Representation --
9561 --------------------------
9562
9563 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9564
9565 -- FLOAT_REP ::= VAX_Float | IEEE_Float
9566
9567 when Pragma_Float_Representation => Float_Representation : declare
9568 Argx : Node_Id;
9569 Digs : Nat;
9570 Ent : Entity_Id;
9571
9572 begin
9573 GNAT_Pragma;
9574
9575 if Arg_Count = 1 then
9576 Check_Valid_Configuration_Pragma;
9577 else
9578 Check_Arg_Count (2);
9579 Check_Optional_Identifier (Arg2, Name_Entity);
9580 Check_Arg_Is_Local_Name (Arg2);
9581 end if;
9582
9583 Check_No_Identifier (Arg1);
9584 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9585
9586 if not OpenVMS_On_Target then
9587 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9588 Error_Pragma
9589 ("?pragma% ignored (applies only to Open'V'M'S)");
9590 end if;
9591
9592 return;
9593 end if;
9594
9595 -- One argument case
9596
9597 if Arg_Count = 1 then
9598 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9599 if Opt.Float_Format = 'I' then
9600 Error_Pragma ("'I'E'E'E format previously specified");
9601 end if;
9602
9603 Opt.Float_Format := 'V';
9604
9605 else
9606 if Opt.Float_Format = 'V' then
9607 Error_Pragma ("'V'A'X format previously specified");
9608 end if;
9609
9610 Opt.Float_Format := 'I';
9611 end if;
9612
9613 Set_Standard_Fpt_Formats;
9614
9615 -- Two argument case
9616
9617 else
9618 Argx := Get_Pragma_Arg (Arg2);
9619
9620 if not Is_Entity_Name (Argx)
9621 or else not Is_Floating_Point_Type (Entity (Argx))
9622 then
9623 Error_Pragma_Arg
9624 ("second argument of% pragma must be floating-point type",
9625 Arg2);
9626 end if;
9627
9628 Ent := Entity (Argx);
9629 Digs := UI_To_Int (Digits_Value (Ent));
9630
9631 -- Two arguments, VAX_Float case
9632
9633 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9634 case Digs is
9635 when 6 => Set_F_Float (Ent);
9636 when 9 => Set_D_Float (Ent);
9637 when 15 => Set_G_Float (Ent);
9638
9639 when others =>
9640 Error_Pragma_Arg
9641 ("wrong digits value, must be 6,9 or 15", Arg2);
9642 end case;
9643
9644 -- Two arguments, IEEE_Float case
9645
9646 else
9647 case Digs is
9648 when 6 => Set_IEEE_Short (Ent);
9649 when 15 => Set_IEEE_Long (Ent);
9650
9651 when others =>
9652 Error_Pragma_Arg
9653 ("wrong digits value, must be 6 or 15", Arg2);
9654 end case;
9655 end if;
9656 end if;
9657 end Float_Representation;
9658
9659 -----------
9660 -- Ident --
9661 -----------
9662
9663 -- pragma Ident (static_string_EXPRESSION)
9664
9665 -- Note: pragma Comment shares this processing. Pragma Comment is
9666 -- identical to Ident, except that the restriction of the argument to
9667 -- 31 characters and the placement restrictions are not enforced for
9668 -- pragma Comment.
9669
9670 when Pragma_Ident | Pragma_Comment => Ident : declare
9671 Str : Node_Id;
9672
9673 begin
9674 GNAT_Pragma;
9675 Check_Arg_Count (1);
9676 Check_No_Identifiers;
9677 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9678 Store_Note (N);
9679
9680 -- For pragma Ident, preserve DEC compatibility by requiring the
9681 -- pragma to appear in a declarative part or package spec.
9682
9683 if Prag_Id = Pragma_Ident then
9684 Check_Is_In_Decl_Part_Or_Package_Spec;
9685 end if;
9686
9687 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
9688
9689 declare
9690 CS : Node_Id;
9691 GP : Node_Id;
9692
9693 begin
9694 GP := Parent (Parent (N));
9695
9696 if Nkind_In (GP, N_Package_Declaration,
9697 N_Generic_Package_Declaration)
9698 then
9699 GP := Parent (GP);
9700 end if;
9701
9702 -- If we have a compilation unit, then record the ident value,
9703 -- checking for improper duplication.
9704
9705 if Nkind (GP) = N_Compilation_Unit then
9706 CS := Ident_String (Current_Sem_Unit);
9707
9708 if Present (CS) then
9709
9710 -- For Ident, we do not permit multiple instances
9711
9712 if Prag_Id = Pragma_Ident then
9713 Error_Pragma ("duplicate% pragma not permitted");
9714
9715 -- For Comment, we concatenate the string, unless we want
9716 -- to preserve the tree structure for ASIS.
9717
9718 elsif not ASIS_Mode then
9719 Start_String (Strval (CS));
9720 Store_String_Char (' ');
9721 Store_String_Chars (Strval (Str));
9722 Set_Strval (CS, End_String);
9723 end if;
9724
9725 else
9726 -- In VMS, the effect of IDENT is achieved by passing
9727 -- --identification=name as a --for-linker switch.
9728
9729 if OpenVMS_On_Target then
9730 Start_String;
9731 Store_String_Chars
9732 ("--for-linker=--identification=");
9733 String_To_Name_Buffer (Strval (Str));
9734 Store_String_Chars (Name_Buffer (1 .. Name_Len));
9735
9736 -- Only the last processed IDENT is saved. The main
9737 -- purpose is so an IDENT associated with a main
9738 -- procedure will be used in preference to an IDENT
9739 -- associated with a with'd package.
9740
9741 Replace_Linker_Option_String
9742 (End_String, "--for-linker=--identification=");
9743 end if;
9744
9745 Set_Ident_String (Current_Sem_Unit, Str);
9746 end if;
9747
9748 -- For subunits, we just ignore the Ident, since in GNAT these
9749 -- are not separate object files, and hence not separate units
9750 -- in the unit table.
9751
9752 elsif Nkind (GP) = N_Subunit then
9753 null;
9754
9755 -- Otherwise we have a misplaced pragma Ident, but we ignore
9756 -- this if we are in an instantiation, since it comes from
9757 -- a generic, and has no relevance to the instantiation.
9758
9759 elsif Prag_Id = Pragma_Ident then
9760 if Instantiation_Location (Loc) = No_Location then
9761 Error_Pragma ("pragma% only allowed at outer level");
9762 end if;
9763 end if;
9764 end;
9765 end Ident;
9766
9767 ----------------------------
9768 -- Implementation_Defined --
9769 ----------------------------
9770
9771 -- pragma Implementation_Defined (local_NAME);
9772
9773 -- Marks previously declared entity as implementation defined. For
9774 -- an overloaded entity, applies to the most recent homonym.
9775
9776 -- pragma Implementation_Defined;
9777
9778 -- The form with no arguments appears anywhere within a scope, most
9779 -- typically a package spec, and indicates that all entities that are
9780 -- defined within the package spec are Implementation_Defined.
9781
9782 when Pragma_Implementation_Defined => Implementation_Defined : declare
9783 Ent : Entity_Id;
9784
9785 begin
9786 Check_No_Identifiers;
9787
9788 -- Form with no arguments
9789
9790 if Arg_Count = 0 then
9791 Set_Is_Implementation_Defined (Current_Scope);
9792
9793 -- Form with one argument
9794
9795 else
9796 Check_Arg_Count (1);
9797 Check_Arg_Is_Local_Name (Arg1);
9798 Ent := Entity (Get_Pragma_Arg (Arg1));
9799 Set_Is_Implementation_Defined (Ent);
9800 end if;
9801 end Implementation_Defined;
9802
9803 -----------------
9804 -- Implemented --
9805 -----------------
9806
9807 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9808 -- implementation_kind ::=
9809 -- By_Entry | By_Protected_Procedure | By_Any | Optional
9810
9811 -- "By_Any" and "Optional" are treated as synonyms in order to
9812 -- support Ada 2012 aspect Synchronization.
9813
9814 when Pragma_Implemented => Implemented : declare
9815 Proc_Id : Entity_Id;
9816 Typ : Entity_Id;
9817
9818 begin
9819 Ada_2012_Pragma;
9820 Check_Arg_Count (2);
9821 Check_No_Identifiers;
9822 Check_Arg_Is_Identifier (Arg1);
9823 Check_Arg_Is_Local_Name (Arg1);
9824 Check_Arg_Is_One_Of (Arg2,
9825 Name_By_Any,
9826 Name_By_Entry,
9827 Name_By_Protected_Procedure,
9828 Name_Optional);
9829
9830 -- Extract the name of the local procedure
9831
9832 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
9833
9834 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9835 -- primitive procedure of a synchronized tagged type.
9836
9837 if Ekind (Proc_Id) = E_Procedure
9838 and then Is_Primitive (Proc_Id)
9839 and then Present (First_Formal (Proc_Id))
9840 then
9841 Typ := Etype (First_Formal (Proc_Id));
9842
9843 if Is_Tagged_Type (Typ)
9844 and then
9845
9846 -- Check for a protected, a synchronized or a task interface
9847
9848 ((Is_Interface (Typ)
9849 and then Is_Synchronized_Interface (Typ))
9850
9851 -- Check for a protected type or a task type that implements
9852 -- an interface.
9853
9854 or else
9855 (Is_Concurrent_Record_Type (Typ)
9856 and then Present (Interfaces (Typ)))
9857
9858 -- Check for a private record extension with keyword
9859 -- "synchronized".
9860
9861 or else
9862 (Ekind_In (Typ, E_Record_Type_With_Private,
9863 E_Record_Subtype_With_Private)
9864 and then Synchronized_Present (Parent (Typ))))
9865 then
9866 null;
9867 else
9868 Error_Pragma_Arg
9869 ("controlling formal must be of synchronized " &
9870 "tagged type", Arg1);
9871 return;
9872 end if;
9873
9874 -- Procedures declared inside a protected type must be accepted
9875
9876 elsif Ekind (Proc_Id) = E_Procedure
9877 and then Is_Protected_Type (Scope (Proc_Id))
9878 then
9879 null;
9880
9881 -- The first argument is not a primitive procedure
9882
9883 else
9884 Error_Pragma_Arg
9885 ("pragma % must be applied to a primitive procedure", Arg1);
9886 return;
9887 end if;
9888
9889 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9890 -- By_Protected_Procedure to the primitive procedure of a task
9891 -- interface.
9892
9893 if Chars (Arg2) = Name_By_Protected_Procedure
9894 and then Is_Interface (Typ)
9895 and then Is_Task_Interface (Typ)
9896 then
9897 Error_Pragma_Arg
9898 ("implementation kind By_Protected_Procedure cannot be " &
9899 "applied to a task interface primitive", Arg2);
9900 return;
9901 end if;
9902
9903 Record_Rep_Item (Proc_Id, N);
9904 end Implemented;
9905
9906 ----------------------
9907 -- Implicit_Packing --
9908 ----------------------
9909
9910 -- pragma Implicit_Packing;
9911
9912 when Pragma_Implicit_Packing =>
9913 GNAT_Pragma;
9914 Check_Arg_Count (0);
9915 Implicit_Packing := True;
9916
9917 ------------
9918 -- Import --
9919 ------------
9920
9921 -- pragma Import (
9922 -- [Convention =>] convention_IDENTIFIER,
9923 -- [Entity =>] local_NAME
9924 -- [, [External_Name =>] static_string_EXPRESSION ]
9925 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9926
9927 when Pragma_Import =>
9928 Check_Ada_83_Warning;
9929 Check_Arg_Order
9930 ((Name_Convention,
9931 Name_Entity,
9932 Name_External_Name,
9933 Name_Link_Name));
9934
9935 Check_At_Least_N_Arguments (2);
9936 Check_At_Most_N_Arguments (4);
9937 Process_Import_Or_Interface;
9938
9939 ----------------------
9940 -- Import_Exception --
9941 ----------------------
9942
9943 -- pragma Import_Exception (
9944 -- [Internal =>] LOCAL_NAME
9945 -- [, [External =>] EXTERNAL_SYMBOL]
9946 -- [, [Form =>] Ada | VMS]
9947 -- [, [Code =>] static_integer_EXPRESSION]);
9948
9949 when Pragma_Import_Exception => Import_Exception : declare
9950 Args : Args_List (1 .. 4);
9951 Names : constant Name_List (1 .. 4) := (
9952 Name_Internal,
9953 Name_External,
9954 Name_Form,
9955 Name_Code);
9956
9957 Internal : Node_Id renames Args (1);
9958 External : Node_Id renames Args (2);
9959 Form : Node_Id renames Args (3);
9960 Code : Node_Id renames Args (4);
9961
9962 begin
9963 GNAT_Pragma;
9964 Gather_Associations (Names, Args);
9965
9966 if Present (External) and then Present (Code) then
9967 Error_Pragma
9968 ("cannot give both External and Code options for pragma%");
9969 end if;
9970
9971 Process_Extended_Import_Export_Exception_Pragma (
9972 Arg_Internal => Internal,
9973 Arg_External => External,
9974 Arg_Form => Form,
9975 Arg_Code => Code);
9976
9977 if not Is_VMS_Exception (Entity (Internal)) then
9978 Set_Imported (Entity (Internal));
9979 end if;
9980 end Import_Exception;
9981
9982 ---------------------
9983 -- Import_Function --
9984 ---------------------
9985
9986 -- pragma Import_Function (
9987 -- [Internal =>] LOCAL_NAME,
9988 -- [, [External =>] EXTERNAL_SYMBOL]
9989 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9990 -- [, [Result_Type =>] SUBTYPE_MARK]
9991 -- [, [Mechanism =>] MECHANISM]
9992 -- [, [Result_Mechanism =>] MECHANISM_NAME]
9993 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9994
9995 -- EXTERNAL_SYMBOL ::=
9996 -- IDENTIFIER
9997 -- | static_string_EXPRESSION
9998
9999 -- PARAMETER_TYPES ::=
10000 -- null
10001 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10002
10003 -- TYPE_DESIGNATOR ::=
10004 -- subtype_NAME
10005 -- | subtype_Name ' Access
10006
10007 -- MECHANISM ::=
10008 -- MECHANISM_NAME
10009 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10010
10011 -- MECHANISM_ASSOCIATION ::=
10012 -- [formal_parameter_NAME =>] MECHANISM_NAME
10013
10014 -- MECHANISM_NAME ::=
10015 -- Value
10016 -- | Reference
10017 -- | Descriptor [([Class =>] CLASS_NAME)]
10018
10019 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10020
10021 when Pragma_Import_Function => Import_Function : declare
10022 Args : Args_List (1 .. 7);
10023 Names : constant Name_List (1 .. 7) := (
10024 Name_Internal,
10025 Name_External,
10026 Name_Parameter_Types,
10027 Name_Result_Type,
10028 Name_Mechanism,
10029 Name_Result_Mechanism,
10030 Name_First_Optional_Parameter);
10031
10032 Internal : Node_Id renames Args (1);
10033 External : Node_Id renames Args (2);
10034 Parameter_Types : Node_Id renames Args (3);
10035 Result_Type : Node_Id renames Args (4);
10036 Mechanism : Node_Id renames Args (5);
10037 Result_Mechanism : Node_Id renames Args (6);
10038 First_Optional_Parameter : Node_Id renames Args (7);
10039
10040 begin
10041 GNAT_Pragma;
10042 Gather_Associations (Names, Args);
10043 Process_Extended_Import_Export_Subprogram_Pragma (
10044 Arg_Internal => Internal,
10045 Arg_External => External,
10046 Arg_Parameter_Types => Parameter_Types,
10047 Arg_Result_Type => Result_Type,
10048 Arg_Mechanism => Mechanism,
10049 Arg_Result_Mechanism => Result_Mechanism,
10050 Arg_First_Optional_Parameter => First_Optional_Parameter);
10051 end Import_Function;
10052
10053 -------------------
10054 -- Import_Object --
10055 -------------------
10056
10057 -- pragma Import_Object (
10058 -- [Internal =>] LOCAL_NAME
10059 -- [, [External =>] EXTERNAL_SYMBOL]
10060 -- [, [Size =>] EXTERNAL_SYMBOL]);
10061
10062 -- EXTERNAL_SYMBOL ::=
10063 -- IDENTIFIER
10064 -- | static_string_EXPRESSION
10065
10066 when Pragma_Import_Object => Import_Object : declare
10067 Args : Args_List (1 .. 3);
10068 Names : constant Name_List (1 .. 3) := (
10069 Name_Internal,
10070 Name_External,
10071 Name_Size);
10072
10073 Internal : Node_Id renames Args (1);
10074 External : Node_Id renames Args (2);
10075 Size : Node_Id renames Args (3);
10076
10077 begin
10078 GNAT_Pragma;
10079 Gather_Associations (Names, Args);
10080 Process_Extended_Import_Export_Object_Pragma (
10081 Arg_Internal => Internal,
10082 Arg_External => External,
10083 Arg_Size => Size);
10084 end Import_Object;
10085
10086 ----------------------
10087 -- Import_Procedure --
10088 ----------------------
10089
10090 -- pragma Import_Procedure (
10091 -- [Internal =>] LOCAL_NAME
10092 -- [, [External =>] EXTERNAL_SYMBOL]
10093 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10094 -- [, [Mechanism =>] MECHANISM]
10095 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
10096
10097 -- EXTERNAL_SYMBOL ::=
10098 -- IDENTIFIER
10099 -- | static_string_EXPRESSION
10100
10101 -- PARAMETER_TYPES ::=
10102 -- null
10103 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10104
10105 -- TYPE_DESIGNATOR ::=
10106 -- subtype_NAME
10107 -- | subtype_Name ' Access
10108
10109 -- MECHANISM ::=
10110 -- MECHANISM_NAME
10111 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10112
10113 -- MECHANISM_ASSOCIATION ::=
10114 -- [formal_parameter_NAME =>] MECHANISM_NAME
10115
10116 -- MECHANISM_NAME ::=
10117 -- Value
10118 -- | Reference
10119 -- | Descriptor [([Class =>] CLASS_NAME)]
10120
10121 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10122
10123 when Pragma_Import_Procedure => Import_Procedure : declare
10124 Args : Args_List (1 .. 5);
10125 Names : constant Name_List (1 .. 5) := (
10126 Name_Internal,
10127 Name_External,
10128 Name_Parameter_Types,
10129 Name_Mechanism,
10130 Name_First_Optional_Parameter);
10131
10132 Internal : Node_Id renames Args (1);
10133 External : Node_Id renames Args (2);
10134 Parameter_Types : Node_Id renames Args (3);
10135 Mechanism : Node_Id renames Args (4);
10136 First_Optional_Parameter : Node_Id renames Args (5);
10137
10138 begin
10139 GNAT_Pragma;
10140 Gather_Associations (Names, Args);
10141 Process_Extended_Import_Export_Subprogram_Pragma (
10142 Arg_Internal => Internal,
10143 Arg_External => External,
10144 Arg_Parameter_Types => Parameter_Types,
10145 Arg_Mechanism => Mechanism,
10146 Arg_First_Optional_Parameter => First_Optional_Parameter);
10147 end Import_Procedure;
10148
10149 -----------------------------
10150 -- Import_Valued_Procedure --
10151 -----------------------------
10152
10153 -- pragma Import_Valued_Procedure (
10154 -- [Internal =>] LOCAL_NAME
10155 -- [, [External =>] EXTERNAL_SYMBOL]
10156 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
10157 -- [, [Mechanism =>] MECHANISM]
10158 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
10159
10160 -- EXTERNAL_SYMBOL ::=
10161 -- IDENTIFIER
10162 -- | static_string_EXPRESSION
10163
10164 -- PARAMETER_TYPES ::=
10165 -- null
10166 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
10167
10168 -- TYPE_DESIGNATOR ::=
10169 -- subtype_NAME
10170 -- | subtype_Name ' Access
10171
10172 -- MECHANISM ::=
10173 -- MECHANISM_NAME
10174 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
10175
10176 -- MECHANISM_ASSOCIATION ::=
10177 -- [formal_parameter_NAME =>] MECHANISM_NAME
10178
10179 -- MECHANISM_NAME ::=
10180 -- Value
10181 -- | Reference
10182 -- | Descriptor [([Class =>] CLASS_NAME)]
10183
10184 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
10185
10186 when Pragma_Import_Valued_Procedure =>
10187 Import_Valued_Procedure : declare
10188 Args : Args_List (1 .. 5);
10189 Names : constant Name_List (1 .. 5) := (
10190 Name_Internal,
10191 Name_External,
10192 Name_Parameter_Types,
10193 Name_Mechanism,
10194 Name_First_Optional_Parameter);
10195
10196 Internal : Node_Id renames Args (1);
10197 External : Node_Id renames Args (2);
10198 Parameter_Types : Node_Id renames Args (3);
10199 Mechanism : Node_Id renames Args (4);
10200 First_Optional_Parameter : Node_Id renames Args (5);
10201
10202 begin
10203 GNAT_Pragma;
10204 Gather_Associations (Names, Args);
10205 Process_Extended_Import_Export_Subprogram_Pragma (
10206 Arg_Internal => Internal,
10207 Arg_External => External,
10208 Arg_Parameter_Types => Parameter_Types,
10209 Arg_Mechanism => Mechanism,
10210 Arg_First_Optional_Parameter => First_Optional_Parameter);
10211 end Import_Valued_Procedure;
10212
10213 -----------------
10214 -- Independent --
10215 -----------------
10216
10217 -- pragma Independent (LOCAL_NAME);
10218
10219 when Pragma_Independent => Independent : declare
10220 E_Id : Node_Id;
10221 E : Entity_Id;
10222 D : Node_Id;
10223 K : Node_Kind;
10224
10225 begin
10226 Check_Ada_83_Warning;
10227 Ada_2012_Pragma;
10228 Check_No_Identifiers;
10229 Check_Arg_Count (1);
10230 Check_Arg_Is_Local_Name (Arg1);
10231 E_Id := Get_Pragma_Arg (Arg1);
10232
10233 if Etype (E_Id) = Any_Type then
10234 return;
10235 end if;
10236
10237 E := Entity (E_Id);
10238 D := Declaration_Node (E);
10239 K := Nkind (D);
10240
10241 -- Check duplicate before we chain ourselves!
10242
10243 Check_Duplicate_Pragma (E);
10244
10245 -- Check appropriate entity
10246
10247 if Is_Type (E) then
10248 if Rep_Item_Too_Early (E, N)
10249 or else
10250 Rep_Item_Too_Late (E, N)
10251 then
10252 return;
10253 else
10254 Check_First_Subtype (Arg1);
10255 end if;
10256
10257 elsif K = N_Object_Declaration
10258 or else (K = N_Component_Declaration
10259 and then Original_Record_Component (E) = E)
10260 then
10261 if Rep_Item_Too_Late (E, N) then
10262 return;
10263 end if;
10264
10265 else
10266 Error_Pragma_Arg
10267 ("inappropriate entity for pragma%", Arg1);
10268 end if;
10269
10270 Independence_Checks.Append ((N, E));
10271 end Independent;
10272
10273 ----------------------------
10274 -- Independent_Components --
10275 ----------------------------
10276
10277 -- pragma Atomic_Components (array_LOCAL_NAME);
10278
10279 -- This processing is shared by Volatile_Components
10280
10281 when Pragma_Independent_Components => Independent_Components : declare
10282 E_Id : Node_Id;
10283 E : Entity_Id;
10284 D : Node_Id;
10285 K : Node_Kind;
10286
10287 begin
10288 Check_Ada_83_Warning;
10289 Ada_2012_Pragma;
10290 Check_No_Identifiers;
10291 Check_Arg_Count (1);
10292 Check_Arg_Is_Local_Name (Arg1);
10293 E_Id := Get_Pragma_Arg (Arg1);
10294
10295 if Etype (E_Id) = Any_Type then
10296 return;
10297 end if;
10298
10299 E := Entity (E_Id);
10300
10301 -- Check duplicate before we chain ourselves!
10302
10303 Check_Duplicate_Pragma (E);
10304
10305 -- Check appropriate entity
10306
10307 if Rep_Item_Too_Early (E, N)
10308 or else
10309 Rep_Item_Too_Late (E, N)
10310 then
10311 return;
10312 end if;
10313
10314 D := Declaration_Node (E);
10315 K := Nkind (D);
10316
10317 if (K = N_Full_Type_Declaration
10318 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
10319 or else
10320 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
10321 and then Nkind (D) = N_Object_Declaration
10322 and then Nkind (Object_Definition (D)) =
10323 N_Constrained_Array_Definition)
10324 then
10325 Independence_Checks.Append ((N, E));
10326
10327 else
10328 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
10329 end if;
10330 end Independent_Components;
10331
10332 ------------------------
10333 -- Initialize_Scalars --
10334 ------------------------
10335
10336 -- pragma Initialize_Scalars;
10337
10338 when Pragma_Initialize_Scalars =>
10339 GNAT_Pragma;
10340 Check_Arg_Count (0);
10341 Check_Valid_Configuration_Pragma;
10342 Check_Restriction (No_Initialize_Scalars, N);
10343
10344 -- Initialize_Scalars creates false positives in CodePeer, and
10345 -- incorrect negative results in Alfa mode, so ignore this pragma
10346 -- in these modes.
10347
10348 if not Restriction_Active (No_Initialize_Scalars)
10349 and then not (CodePeer_Mode or Alfa_Mode)
10350 then
10351 Init_Or_Norm_Scalars := True;
10352 Initialize_Scalars := True;
10353 end if;
10354
10355 ------------
10356 -- Inline --
10357 ------------
10358
10359 -- pragma Inline ( NAME {, NAME} );
10360
10361 when Pragma_Inline =>
10362
10363 -- Pragma is active if inlining option is active
10364
10365 Process_Inline (Inline_Active);
10366
10367 -------------------
10368 -- Inline_Always --
10369 -------------------
10370
10371 -- pragma Inline_Always ( NAME {, NAME} );
10372
10373 when Pragma_Inline_Always =>
10374 GNAT_Pragma;
10375
10376 -- Pragma always active unless in CodePeer or Alfa mode, since
10377 -- this causes walk order issues.
10378
10379 if not (CodePeer_Mode or Alfa_Mode) then
10380 Process_Inline (True);
10381 end if;
10382
10383 --------------------
10384 -- Inline_Generic --
10385 --------------------
10386
10387 -- pragma Inline_Generic (NAME {, NAME});
10388
10389 when Pragma_Inline_Generic =>
10390 GNAT_Pragma;
10391 Process_Generic_List;
10392
10393 ----------------------
10394 -- Inspection_Point --
10395 ----------------------
10396
10397 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
10398
10399 when Pragma_Inspection_Point => Inspection_Point : declare
10400 Arg : Node_Id;
10401 Exp : Node_Id;
10402
10403 begin
10404 if Arg_Count > 0 then
10405 Arg := Arg1;
10406 loop
10407 Exp := Get_Pragma_Arg (Arg);
10408 Analyze (Exp);
10409
10410 if not Is_Entity_Name (Exp)
10411 or else not Is_Object (Entity (Exp))
10412 then
10413 Error_Pragma_Arg ("object name required", Arg);
10414 end if;
10415
10416 Next (Arg);
10417 exit when No (Arg);
10418 end loop;
10419 end if;
10420 end Inspection_Point;
10421
10422 ---------------
10423 -- Interface --
10424 ---------------
10425
10426 -- pragma Interface (
10427 -- [ Convention =>] convention_IDENTIFIER,
10428 -- [ Entity =>] local_NAME
10429 -- [, [External_Name =>] static_string_EXPRESSION ]
10430 -- [, [Link_Name =>] static_string_EXPRESSION ]);
10431
10432 when Pragma_Interface =>
10433 GNAT_Pragma;
10434 Check_Arg_Order
10435 ((Name_Convention,
10436 Name_Entity,
10437 Name_External_Name,
10438 Name_Link_Name));
10439 Check_At_Least_N_Arguments (2);
10440 Check_At_Most_N_Arguments (4);
10441 Process_Import_Or_Interface;
10442
10443 -- In Ada 2005, the permission to use Interface (a reserved word)
10444 -- as a pragma name is considered an obsolescent feature.
10445
10446 if Ada_Version >= Ada_2005 then
10447 Check_Restriction
10448 (No_Obsolescent_Features, Pragma_Identifier (N));
10449 end if;
10450
10451 --------------------
10452 -- Interface_Name --
10453 --------------------
10454
10455 -- pragma Interface_Name (
10456 -- [ Entity =>] local_NAME
10457 -- [,[External_Name =>] static_string_EXPRESSION ]
10458 -- [,[Link_Name =>] static_string_EXPRESSION ]);
10459
10460 when Pragma_Interface_Name => Interface_Name : declare
10461 Id : Node_Id;
10462 Def_Id : Entity_Id;
10463 Hom_Id : Entity_Id;
10464 Found : Boolean;
10465
10466 begin
10467 GNAT_Pragma;
10468 Check_Arg_Order
10469 ((Name_Entity, Name_External_Name, Name_Link_Name));
10470 Check_At_Least_N_Arguments (2);
10471 Check_At_Most_N_Arguments (3);
10472 Id := Get_Pragma_Arg (Arg1);
10473 Analyze (Id);
10474
10475 if not Is_Entity_Name (Id) then
10476 Error_Pragma_Arg
10477 ("first argument for pragma% must be entity name", Arg1);
10478 elsif Etype (Id) = Any_Type then
10479 return;
10480 else
10481 Def_Id := Entity (Id);
10482 end if;
10483
10484 -- Special DEC-compatible processing for the object case, forces
10485 -- object to be imported.
10486
10487 if Ekind (Def_Id) = E_Variable then
10488 Kill_Size_Check_Code (Def_Id);
10489 Note_Possible_Modification (Id, Sure => False);
10490
10491 -- Initialization is not allowed for imported variable
10492
10493 if Present (Expression (Parent (Def_Id)))
10494 and then Comes_From_Source (Expression (Parent (Def_Id)))
10495 then
10496 Error_Msg_Sloc := Sloc (Def_Id);
10497 Error_Pragma_Arg
10498 ("no initialization allowed for declaration of& #",
10499 Arg2);
10500
10501 else
10502 -- For compatibility, support VADS usage of providing both
10503 -- pragmas Interface and Interface_Name to obtain the effect
10504 -- of a single Import pragma.
10505
10506 if Is_Imported (Def_Id)
10507 and then Present (First_Rep_Item (Def_Id))
10508 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
10509 and then
10510 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
10511 then
10512 null;
10513 else
10514 Set_Imported (Def_Id);
10515 end if;
10516
10517 Set_Is_Public (Def_Id);
10518 Process_Interface_Name (Def_Id, Arg2, Arg3);
10519 end if;
10520
10521 -- Otherwise must be subprogram
10522
10523 elsif not Is_Subprogram (Def_Id) then
10524 Error_Pragma_Arg
10525 ("argument of pragma% is not subprogram", Arg1);
10526
10527 else
10528 Check_At_Most_N_Arguments (3);
10529 Hom_Id := Def_Id;
10530 Found := False;
10531
10532 -- Loop through homonyms
10533
10534 loop
10535 Def_Id := Get_Base_Subprogram (Hom_Id);
10536
10537 if Is_Imported (Def_Id) then
10538 Process_Interface_Name (Def_Id, Arg2, Arg3);
10539 Found := True;
10540 end if;
10541
10542 exit when From_Aspect_Specification (N);
10543 Hom_Id := Homonym (Hom_Id);
10544
10545 exit when No (Hom_Id)
10546 or else Scope (Hom_Id) /= Current_Scope;
10547 end loop;
10548
10549 if not Found then
10550 Error_Pragma_Arg
10551 ("argument of pragma% is not imported subprogram",
10552 Arg1);
10553 end if;
10554 end if;
10555 end Interface_Name;
10556
10557 -----------------------
10558 -- Interrupt_Handler --
10559 -----------------------
10560
10561 -- pragma Interrupt_Handler (handler_NAME);
10562
10563 when Pragma_Interrupt_Handler =>
10564 Check_Ada_83_Warning;
10565 Check_Arg_Count (1);
10566 Check_No_Identifiers;
10567
10568 if No_Run_Time_Mode then
10569 Error_Msg_CRT ("Interrupt_Handler pragma", N);
10570 else
10571 Check_Interrupt_Or_Attach_Handler;
10572 Process_Interrupt_Or_Attach_Handler;
10573 end if;
10574
10575 ------------------------
10576 -- Interrupt_Priority --
10577 ------------------------
10578
10579 -- pragma Interrupt_Priority [(EXPRESSION)];
10580
10581 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
10582 P : constant Node_Id := Parent (N);
10583 Arg : Node_Id;
10584 Ent : Entity_Id;
10585
10586 begin
10587 Check_Ada_83_Warning;
10588
10589 if Arg_Count /= 0 then
10590 Arg := Get_Pragma_Arg (Arg1);
10591 Check_Arg_Count (1);
10592 Check_No_Identifiers;
10593
10594 -- The expression must be analyzed in the special manner
10595 -- described in "Handling of Default and Per-Object
10596 -- Expressions" in sem.ads.
10597
10598 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
10599 end if;
10600
10601 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
10602 Pragma_Misplaced;
10603 return;
10604
10605 else
10606 Ent := Defining_Identifier (Parent (P));
10607
10608 -- Check duplicate pragma before we chain the pragma in the Rep
10609 -- Item chain of Ent.
10610
10611 Check_Duplicate_Pragma (Ent);
10612 Record_Rep_Item (Ent, N);
10613 end if;
10614 end Interrupt_Priority;
10615
10616 ---------------------
10617 -- Interrupt_State --
10618 ---------------------
10619
10620 -- pragma Interrupt_State (
10621 -- [Name =>] INTERRUPT_ID,
10622 -- [State =>] INTERRUPT_STATE);
10623
10624 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
10625 -- INTERRUPT_STATE => System | Runtime | User
10626
10627 -- Note: if the interrupt id is given as an identifier, then it must
10628 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
10629 -- given as a static integer expression which must be in the range of
10630 -- Ada.Interrupts.Interrupt_ID.
10631
10632 when Pragma_Interrupt_State => Interrupt_State : declare
10633
10634 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
10635 -- This is the entity Ada.Interrupts.Interrupt_ID;
10636
10637 State_Type : Character;
10638 -- Set to 's'/'r'/'u' for System/Runtime/User
10639
10640 IST_Num : Pos;
10641 -- Index to entry in Interrupt_States table
10642
10643 Int_Val : Uint;
10644 -- Value of interrupt
10645
10646 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
10647 -- The first argument to the pragma
10648
10649 Int_Ent : Entity_Id;
10650 -- Interrupt entity in Ada.Interrupts.Names
10651
10652 begin
10653 GNAT_Pragma;
10654 Check_Arg_Order ((Name_Name, Name_State));
10655 Check_Arg_Count (2);
10656
10657 Check_Optional_Identifier (Arg1, Name_Name);
10658 Check_Optional_Identifier (Arg2, Name_State);
10659 Check_Arg_Is_Identifier (Arg2);
10660
10661 -- First argument is identifier
10662
10663 if Nkind (Arg1X) = N_Identifier then
10664
10665 -- Search list of names in Ada.Interrupts.Names
10666
10667 Int_Ent := First_Entity (RTE (RE_Names));
10668 loop
10669 if No (Int_Ent) then
10670 Error_Pragma_Arg ("invalid interrupt name", Arg1);
10671
10672 elsif Chars (Int_Ent) = Chars (Arg1X) then
10673 Int_Val := Expr_Value (Constant_Value (Int_Ent));
10674 exit;
10675 end if;
10676
10677 Next_Entity (Int_Ent);
10678 end loop;
10679
10680 -- First argument is not an identifier, so it must be a static
10681 -- expression of type Ada.Interrupts.Interrupt_ID.
10682
10683 else
10684 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10685 Int_Val := Expr_Value (Arg1X);
10686
10687 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
10688 or else
10689 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
10690 then
10691 Error_Pragma_Arg
10692 ("value not in range of type " &
10693 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
10694 end if;
10695 end if;
10696
10697 -- Check OK state
10698
10699 case Chars (Get_Pragma_Arg (Arg2)) is
10700 when Name_Runtime => State_Type := 'r';
10701 when Name_System => State_Type := 's';
10702 when Name_User => State_Type := 'u';
10703
10704 when others =>
10705 Error_Pragma_Arg ("invalid interrupt state", Arg2);
10706 end case;
10707
10708 -- Check if entry is already stored
10709
10710 IST_Num := Interrupt_States.First;
10711 loop
10712 -- If entry not found, add it
10713
10714 if IST_Num > Interrupt_States.Last then
10715 Interrupt_States.Append
10716 ((Interrupt_Number => UI_To_Int (Int_Val),
10717 Interrupt_State => State_Type,
10718 Pragma_Loc => Loc));
10719 exit;
10720
10721 -- Case of entry for the same entry
10722
10723 elsif Int_Val = Interrupt_States.Table (IST_Num).
10724 Interrupt_Number
10725 then
10726 -- If state matches, done, no need to make redundant entry
10727
10728 exit when
10729 State_Type = Interrupt_States.Table (IST_Num).
10730 Interrupt_State;
10731
10732 -- Otherwise if state does not match, error
10733
10734 Error_Msg_Sloc :=
10735 Interrupt_States.Table (IST_Num).Pragma_Loc;
10736 Error_Pragma_Arg
10737 ("state conflicts with that given #", Arg2);
10738 exit;
10739 end if;
10740
10741 IST_Num := IST_Num + 1;
10742 end loop;
10743 end Interrupt_State;
10744
10745 ---------------
10746 -- Invariant --
10747 ---------------
10748
10749 -- pragma Invariant
10750 -- ([Entity =>] type_LOCAL_NAME,
10751 -- [Check =>] EXPRESSION
10752 -- [,[Message =>] String_Expression]);
10753
10754 when Pragma_Invariant => Invariant : declare
10755 Type_Id : Node_Id;
10756 Typ : Entity_Id;
10757 PDecl : Node_Id;
10758
10759 Discard : Boolean;
10760 pragma Unreferenced (Discard);
10761
10762 begin
10763 GNAT_Pragma;
10764 Check_At_Least_N_Arguments (2);
10765 Check_At_Most_N_Arguments (3);
10766 Check_Optional_Identifier (Arg1, Name_Entity);
10767 Check_Optional_Identifier (Arg2, Name_Check);
10768
10769 if Arg_Count = 3 then
10770 Check_Optional_Identifier (Arg3, Name_Message);
10771 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10772 end if;
10773
10774 Check_Arg_Is_Local_Name (Arg1);
10775
10776 Type_Id := Get_Pragma_Arg (Arg1);
10777 Find_Type (Type_Id);
10778 Typ := Entity (Type_Id);
10779
10780 if Typ = Any_Type then
10781 return;
10782
10783 -- An invariant must apply to a private type, or appear in the
10784 -- private part of a package spec and apply to a completion.
10785
10786 elsif Ekind_In (Typ, E_Private_Type,
10787 E_Record_Type_With_Private,
10788 E_Limited_Private_Type)
10789 then
10790 null;
10791
10792 elsif In_Private_Part (Current_Scope)
10793 and then Has_Private_Declaration (Typ)
10794 then
10795 null;
10796
10797 elsif In_Private_Part (Current_Scope) then
10798 Error_Pragma_Arg
10799 ("pragma% only allowed for private type " &
10800 "declared in visible part", Arg1);
10801
10802 else
10803 Error_Pragma_Arg
10804 ("pragma% only allowed for private type", Arg1);
10805 end if;
10806
10807 -- Note that the type has at least one invariant, and also that
10808 -- it has inheritable invariants if we have Invariant'Class.
10809 -- Build the corresponding invariant procedure declaration, so
10810 -- that calls to it can be generated before the body is built
10811 -- (for example wihin an expression function).
10812
10813 PDecl := Build_Invariant_Procedure_Declaration (Typ);
10814 Insert_After (N, PDecl);
10815 Analyze (PDecl);
10816
10817 if Class_Present (N) then
10818 Set_Has_Inheritable_Invariants (Typ);
10819 end if;
10820
10821 -- The remaining processing is simply to link the pragma on to
10822 -- the rep item chain, for processing when the type is frozen.
10823 -- This is accomplished by a call to Rep_Item_Too_Late.
10824
10825 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10826 end Invariant;
10827
10828 ----------------------
10829 -- Java_Constructor --
10830 ----------------------
10831
10832 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10833
10834 -- Also handles pragma CIL_Constructor
10835
10836 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10837 Java_Constructor : declare
10838 Convention : Convention_Id;
10839 Def_Id : Entity_Id;
10840 Hom_Id : Entity_Id;
10841 Id : Entity_Id;
10842 This_Formal : Entity_Id;
10843
10844 begin
10845 GNAT_Pragma;
10846 Check_Arg_Count (1);
10847 Check_Optional_Identifier (Arg1, Name_Entity);
10848 Check_Arg_Is_Local_Name (Arg1);
10849
10850 Id := Get_Pragma_Arg (Arg1);
10851 Find_Program_Unit_Name (Id);
10852
10853 -- If we did not find the name, we are done
10854
10855 if Etype (Id) = Any_Type then
10856 return;
10857 end if;
10858
10859 -- Check wrong use of pragma in wrong VM target
10860
10861 if VM_Target = No_VM then
10862 return;
10863
10864 elsif VM_Target = CLI_Target
10865 and then Prag_Id = Pragma_Java_Constructor
10866 then
10867 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10868
10869 elsif VM_Target = JVM_Target
10870 and then Prag_Id = Pragma_CIL_Constructor
10871 then
10872 Error_Pragma ("must use pragma 'Java_'Constructor");
10873 end if;
10874
10875 case Prag_Id is
10876 when Pragma_CIL_Constructor => Convention := Convention_CIL;
10877 when Pragma_Java_Constructor => Convention := Convention_Java;
10878 when others => null;
10879 end case;
10880
10881 Hom_Id := Entity (Id);
10882
10883 -- Loop through homonyms
10884
10885 loop
10886 Def_Id := Get_Base_Subprogram (Hom_Id);
10887
10888 -- The constructor is required to be a function
10889
10890 if Ekind (Def_Id) /= E_Function then
10891 if VM_Target = JVM_Target then
10892 Error_Pragma_Arg
10893 ("pragma% requires function returning a " &
10894 "'Java access type", Def_Id);
10895 else
10896 Error_Pragma_Arg
10897 ("pragma% requires function returning a " &
10898 "'C'I'L access type", Def_Id);
10899 end if;
10900 end if;
10901
10902 -- Check arguments: For tagged type the first formal must be
10903 -- named "this" and its type must be a named access type
10904 -- designating a class-wide tagged type that has convention
10905 -- CIL/Java. The first formal must also have a null default
10906 -- value. For example:
10907
10908 -- type Typ is tagged ...
10909 -- type Ref is access all Typ;
10910 -- pragma Convention (CIL, Typ);
10911
10912 -- function New_Typ (This : Ref) return Ref;
10913 -- function New_Typ (This : Ref; I : Integer) return Ref;
10914 -- pragma Cil_Constructor (New_Typ);
10915
10916 -- Reason: The first formal must NOT be a primitive of the
10917 -- tagged type.
10918
10919 -- This rule also applies to constructors of delegates used
10920 -- to interface with standard target libraries. For example:
10921
10922 -- type Delegate is access procedure ...
10923 -- pragma Import (CIL, Delegate, ...);
10924
10925 -- function new_Delegate
10926 -- (This : Delegate := null; ... ) return Delegate;
10927
10928 -- For value-types this rule does not apply.
10929
10930 if not Is_Value_Type (Etype (Def_Id)) then
10931 if No (First_Formal (Def_Id)) then
10932 Error_Msg_Name_1 := Pname;
10933 Error_Msg_N ("% function must have parameters", Def_Id);
10934 return;
10935 end if;
10936
10937 -- In the JRE library we have several occurrences in which
10938 -- the "this" parameter is not the first formal.
10939
10940 This_Formal := First_Formal (Def_Id);
10941
10942 -- In the JRE library we have several occurrences in which
10943 -- the "this" parameter is not the first formal. Search for
10944 -- it.
10945
10946 if VM_Target = JVM_Target then
10947 while Present (This_Formal)
10948 and then Get_Name_String (Chars (This_Formal)) /= "this"
10949 loop
10950 Next_Formal (This_Formal);
10951 end loop;
10952
10953 if No (This_Formal) then
10954 This_Formal := First_Formal (Def_Id);
10955 end if;
10956 end if;
10957
10958 -- Warning: The first parameter should be named "this".
10959 -- We temporarily allow it because we have the following
10960 -- case in the Java runtime (file s-osinte.ads) ???
10961
10962 -- function new_Thread
10963 -- (Self_Id : System.Address) return Thread_Id;
10964 -- pragma Java_Constructor (new_Thread);
10965
10966 if VM_Target = JVM_Target
10967 and then Get_Name_String (Chars (First_Formal (Def_Id)))
10968 = "self_id"
10969 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10970 then
10971 null;
10972
10973 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10974 Error_Msg_Name_1 := Pname;
10975 Error_Msg_N
10976 ("first formal of % function must be named `this`",
10977 Parent (This_Formal));
10978
10979 elsif not Is_Access_Type (Etype (This_Formal)) then
10980 Error_Msg_Name_1 := Pname;
10981 Error_Msg_N
10982 ("first formal of % function must be an access type",
10983 Parameter_Type (Parent (This_Formal)));
10984
10985 -- For delegates the type of the first formal must be a
10986 -- named access-to-subprogram type (see previous example)
10987
10988 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10989 and then Ekind (Etype (This_Formal))
10990 /= E_Access_Subprogram_Type
10991 then
10992 Error_Msg_Name_1 := Pname;
10993 Error_Msg_N
10994 ("first formal of % function must be a named access" &
10995 " to subprogram type",
10996 Parameter_Type (Parent (This_Formal)));
10997
10998 -- Warning: We should reject anonymous access types because
10999 -- the constructor must not be handled as a primitive of the
11000 -- tagged type. We temporarily allow it because this profile
11001 -- is currently generated by cil2ada???
11002
11003 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
11004 and then not Ekind_In (Etype (This_Formal),
11005 E_Access_Type,
11006 E_General_Access_Type,
11007 E_Anonymous_Access_Type)
11008 then
11009 Error_Msg_Name_1 := Pname;
11010 Error_Msg_N
11011 ("first formal of % function must be a named access" &
11012 " type",
11013 Parameter_Type (Parent (This_Formal)));
11014
11015 elsif Atree.Convention
11016 (Designated_Type (Etype (This_Formal))) /= Convention
11017 then
11018 Error_Msg_Name_1 := Pname;
11019
11020 if Convention = Convention_Java then
11021 Error_Msg_N
11022 ("pragma% requires convention 'Cil in designated" &
11023 " type",
11024 Parameter_Type (Parent (This_Formal)));
11025 else
11026 Error_Msg_N
11027 ("pragma% requires convention 'Java in designated" &
11028 " type",
11029 Parameter_Type (Parent (This_Formal)));
11030 end if;
11031
11032 elsif No (Expression (Parent (This_Formal)))
11033 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
11034 then
11035 Error_Msg_Name_1 := Pname;
11036 Error_Msg_N
11037 ("pragma% requires first formal with default `null`",
11038 Parameter_Type (Parent (This_Formal)));
11039 end if;
11040 end if;
11041
11042 -- Check result type: the constructor must be a function
11043 -- returning:
11044 -- * a value type (only allowed in the CIL compiler)
11045 -- * an access-to-subprogram type with convention Java/CIL
11046 -- * an access-type designating a type that has convention
11047 -- Java/CIL.
11048
11049 if Is_Value_Type (Etype (Def_Id)) then
11050 null;
11051
11052 -- Access-to-subprogram type with convention Java/CIL
11053
11054 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
11055 if Atree.Convention (Etype (Def_Id)) /= Convention then
11056 if Convention = Convention_Java then
11057 Error_Pragma_Arg
11058 ("pragma% requires function returning a " &
11059 "'Java access type", Arg1);
11060 else
11061 pragma Assert (Convention = Convention_CIL);
11062 Error_Pragma_Arg
11063 ("pragma% requires function returning a " &
11064 "'C'I'L access type", Arg1);
11065 end if;
11066 end if;
11067
11068 elsif Ekind (Etype (Def_Id)) in Access_Kind then
11069 if not Ekind_In (Etype (Def_Id), E_Access_Type,
11070 E_General_Access_Type)
11071 or else
11072 Atree.Convention
11073 (Designated_Type (Etype (Def_Id))) /= Convention
11074 then
11075 Error_Msg_Name_1 := Pname;
11076
11077 if Convention = Convention_Java then
11078 Error_Pragma_Arg
11079 ("pragma% requires function returning a named" &
11080 "'Java access type", Arg1);
11081 else
11082 Error_Pragma_Arg
11083 ("pragma% requires function returning a named" &
11084 "'C'I'L access type", Arg1);
11085 end if;
11086 end if;
11087 end if;
11088
11089 Set_Is_Constructor (Def_Id);
11090 Set_Convention (Def_Id, Convention);
11091 Set_Is_Imported (Def_Id);
11092
11093 exit when From_Aspect_Specification (N);
11094 Hom_Id := Homonym (Hom_Id);
11095
11096 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
11097 end loop;
11098 end Java_Constructor;
11099
11100 ----------------------
11101 -- Java_Interface --
11102 ----------------------
11103
11104 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
11105
11106 when Pragma_Java_Interface => Java_Interface : declare
11107 Arg : Node_Id;
11108 Typ : Entity_Id;
11109
11110 begin
11111 GNAT_Pragma;
11112 Check_Arg_Count (1);
11113 Check_Optional_Identifier (Arg1, Name_Entity);
11114 Check_Arg_Is_Local_Name (Arg1);
11115
11116 Arg := Get_Pragma_Arg (Arg1);
11117 Analyze (Arg);
11118
11119 if Etype (Arg) = Any_Type then
11120 return;
11121 end if;
11122
11123 if not Is_Entity_Name (Arg)
11124 or else not Is_Type (Entity (Arg))
11125 then
11126 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
11127 end if;
11128
11129 Typ := Underlying_Type (Entity (Arg));
11130
11131 -- For now simply check some of the semantic constraints on the
11132 -- type. This currently leaves out some restrictions on interface
11133 -- types, namely that the parent type must be java.lang.Object.Typ
11134 -- and that all primitives of the type should be declared
11135 -- abstract. ???
11136
11137 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
11138 Error_Pragma_Arg ("pragma% requires an abstract "
11139 & "tagged type", Arg1);
11140
11141 elsif not Has_Discriminants (Typ)
11142 or else Ekind (Etype (First_Discriminant (Typ)))
11143 /= E_Anonymous_Access_Type
11144 or else
11145 not Is_Class_Wide_Type
11146 (Designated_Type (Etype (First_Discriminant (Typ))))
11147 then
11148 Error_Pragma_Arg
11149 ("type must have a class-wide access discriminant", Arg1);
11150 end if;
11151 end Java_Interface;
11152
11153 ----------------
11154 -- Keep_Names --
11155 ----------------
11156
11157 -- pragma Keep_Names ([On => ] local_NAME);
11158
11159 when Pragma_Keep_Names => Keep_Names : declare
11160 Arg : Node_Id;
11161
11162 begin
11163 GNAT_Pragma;
11164 Check_Arg_Count (1);
11165 Check_Optional_Identifier (Arg1, Name_On);
11166 Check_Arg_Is_Local_Name (Arg1);
11167
11168 Arg := Get_Pragma_Arg (Arg1);
11169 Analyze (Arg);
11170
11171 if Etype (Arg) = Any_Type then
11172 return;
11173 end if;
11174
11175 if not Is_Entity_Name (Arg)
11176 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
11177 then
11178 Error_Pragma_Arg
11179 ("pragma% requires a local enumeration type", Arg1);
11180 end if;
11181
11182 Set_Discard_Names (Entity (Arg), False);
11183 end Keep_Names;
11184
11185 -------------
11186 -- License --
11187 -------------
11188
11189 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
11190
11191 when Pragma_License =>
11192 GNAT_Pragma;
11193 Check_Arg_Count (1);
11194 Check_No_Identifiers;
11195 Check_Valid_Configuration_Pragma;
11196 Check_Arg_Is_Identifier (Arg1);
11197
11198 declare
11199 Sind : constant Source_File_Index :=
11200 Source_Index (Current_Sem_Unit);
11201
11202 begin
11203 case Chars (Get_Pragma_Arg (Arg1)) is
11204 when Name_GPL =>
11205 Set_License (Sind, GPL);
11206
11207 when Name_Modified_GPL =>
11208 Set_License (Sind, Modified_GPL);
11209
11210 when Name_Restricted =>
11211 Set_License (Sind, Restricted);
11212
11213 when Name_Unrestricted =>
11214 Set_License (Sind, Unrestricted);
11215
11216 when others =>
11217 Error_Pragma_Arg ("invalid license name", Arg1);
11218 end case;
11219 end;
11220
11221 ---------------
11222 -- Link_With --
11223 ---------------
11224
11225 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
11226
11227 when Pragma_Link_With => Link_With : declare
11228 Arg : Node_Id;
11229
11230 begin
11231 GNAT_Pragma;
11232
11233 if Operating_Mode = Generate_Code
11234 and then In_Extended_Main_Source_Unit (N)
11235 then
11236 Check_At_Least_N_Arguments (1);
11237 Check_No_Identifiers;
11238 Check_Is_In_Decl_Part_Or_Package_Spec;
11239 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11240 Start_String;
11241
11242 Arg := Arg1;
11243 while Present (Arg) loop
11244 Check_Arg_Is_Static_Expression (Arg, Standard_String);
11245
11246 -- Store argument, converting sequences of spaces to a
11247 -- single null character (this is one of the differences
11248 -- in processing between Link_With and Linker_Options).
11249
11250 Arg_Store : declare
11251 C : constant Char_Code := Get_Char_Code (' ');
11252 S : constant String_Id :=
11253 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
11254 L : constant Nat := String_Length (S);
11255 F : Nat := 1;
11256
11257 procedure Skip_Spaces;
11258 -- Advance F past any spaces
11259
11260 -----------------
11261 -- Skip_Spaces --
11262 -----------------
11263
11264 procedure Skip_Spaces is
11265 begin
11266 while F <= L and then Get_String_Char (S, F) = C loop
11267 F := F + 1;
11268 end loop;
11269 end Skip_Spaces;
11270
11271 -- Start of processing for Arg_Store
11272
11273 begin
11274 Skip_Spaces; -- skip leading spaces
11275
11276 -- Loop through characters, changing any embedded
11277 -- sequence of spaces to a single null character (this
11278 -- is how Link_With/Linker_Options differ)
11279
11280 while F <= L loop
11281 if Get_String_Char (S, F) = C then
11282 Skip_Spaces;
11283 exit when F > L;
11284 Store_String_Char (ASCII.NUL);
11285
11286 else
11287 Store_String_Char (Get_String_Char (S, F));
11288 F := F + 1;
11289 end if;
11290 end loop;
11291 end Arg_Store;
11292
11293 Arg := Next (Arg);
11294
11295 if Present (Arg) then
11296 Store_String_Char (ASCII.NUL);
11297 end if;
11298 end loop;
11299
11300 Store_Linker_Option_String (End_String);
11301 end if;
11302 end Link_With;
11303
11304 ------------------
11305 -- Linker_Alias --
11306 ------------------
11307
11308 -- pragma Linker_Alias (
11309 -- [Entity =>] LOCAL_NAME
11310 -- [Target =>] static_string_EXPRESSION);
11311
11312 when Pragma_Linker_Alias =>
11313 GNAT_Pragma;
11314 Check_Arg_Order ((Name_Entity, Name_Target));
11315 Check_Arg_Count (2);
11316 Check_Optional_Identifier (Arg1, Name_Entity);
11317 Check_Optional_Identifier (Arg2, Name_Target);
11318 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11319 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11320
11321 -- The only processing required is to link this item on to the
11322 -- list of rep items for the given entity. This is accomplished
11323 -- by the call to Rep_Item_Too_Late (when no error is detected
11324 -- and False is returned).
11325
11326 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
11327 return;
11328 else
11329 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11330 end if;
11331
11332 ------------------------
11333 -- Linker_Constructor --
11334 ------------------------
11335
11336 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
11337
11338 -- Code is shared with Linker_Destructor
11339
11340 -----------------------
11341 -- Linker_Destructor --
11342 -----------------------
11343
11344 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
11345
11346 when Pragma_Linker_Constructor |
11347 Pragma_Linker_Destructor =>
11348 Linker_Constructor : declare
11349 Arg1_X : Node_Id;
11350 Proc : Entity_Id;
11351
11352 begin
11353 GNAT_Pragma;
11354 Check_Arg_Count (1);
11355 Check_No_Identifiers;
11356 Check_Arg_Is_Local_Name (Arg1);
11357 Arg1_X := Get_Pragma_Arg (Arg1);
11358 Analyze (Arg1_X);
11359 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
11360
11361 if not Is_Library_Level_Entity (Proc) then
11362 Error_Pragma_Arg
11363 ("argument for pragma% must be library level entity", Arg1);
11364 end if;
11365
11366 -- The only processing required is to link this item on to the
11367 -- list of rep items for the given entity. This is accomplished
11368 -- by the call to Rep_Item_Too_Late (when no error is detected
11369 -- and False is returned).
11370
11371 if Rep_Item_Too_Late (Proc, N) then
11372 return;
11373 else
11374 Set_Has_Gigi_Rep_Item (Proc);
11375 end if;
11376 end Linker_Constructor;
11377
11378 --------------------
11379 -- Linker_Options --
11380 --------------------
11381
11382 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
11383
11384 when Pragma_Linker_Options => Linker_Options : declare
11385 Arg : Node_Id;
11386
11387 begin
11388 Check_Ada_83_Warning;
11389 Check_No_Identifiers;
11390 Check_Arg_Count (1);
11391 Check_Is_In_Decl_Part_Or_Package_Spec;
11392 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11393 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
11394
11395 Arg := Arg2;
11396 while Present (Arg) loop
11397 Check_Arg_Is_Static_Expression (Arg, Standard_String);
11398 Store_String_Char (ASCII.NUL);
11399 Store_String_Chars
11400 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
11401 Arg := Next (Arg);
11402 end loop;
11403
11404 if Operating_Mode = Generate_Code
11405 and then In_Extended_Main_Source_Unit (N)
11406 then
11407 Store_Linker_Option_String (End_String);
11408 end if;
11409 end Linker_Options;
11410
11411 --------------------
11412 -- Linker_Section --
11413 --------------------
11414
11415 -- pragma Linker_Section (
11416 -- [Entity =>] LOCAL_NAME
11417 -- [Section =>] static_string_EXPRESSION);
11418
11419 when Pragma_Linker_Section =>
11420 GNAT_Pragma;
11421 Check_Arg_Order ((Name_Entity, Name_Section));
11422 Check_Arg_Count (2);
11423 Check_Optional_Identifier (Arg1, Name_Entity);
11424 Check_Optional_Identifier (Arg2, Name_Section);
11425 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11426 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11427
11428 -- This pragma applies only to objects
11429
11430 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
11431 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
11432 end if;
11433
11434 -- The only processing required is to link this item on to the
11435 -- list of rep items for the given entity. This is accomplished
11436 -- by the call to Rep_Item_Too_Late (when no error is detected
11437 -- and False is returned).
11438
11439 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
11440 return;
11441 else
11442 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11443 end if;
11444
11445 ----------
11446 -- List --
11447 ----------
11448
11449 -- pragma List (On | Off)
11450
11451 -- There is nothing to do here, since we did all the processing for
11452 -- this pragma in Par.Prag (so that it works properly even in syntax
11453 -- only mode).
11454
11455 when Pragma_List =>
11456 null;
11457
11458 ---------------
11459 -- Lock_Free --
11460 ---------------
11461
11462 -- pragma Lock_Free [(Boolean_EXPRESSION)];
11463
11464 when Pragma_Lock_Free => Lock_Free : declare
11465 P : constant Node_Id := Parent (N);
11466 Arg : Node_Id;
11467 Ent : Entity_Id;
11468 Val : Boolean;
11469
11470 begin
11471 Check_No_Identifiers;
11472 Check_At_Most_N_Arguments (1);
11473
11474 -- Protected definition case
11475
11476 if Nkind (P) = N_Protected_Definition then
11477 Ent := Defining_Identifier (Parent (P));
11478
11479 -- One argument
11480
11481 if Arg_Count = 1 then
11482 Arg := Get_Pragma_Arg (Arg1);
11483 Val := Is_True (Static_Boolean (Arg));
11484
11485 -- No arguments (expression is considered to be True)
11486
11487 else
11488 Val := True;
11489 end if;
11490
11491 -- Check duplicate pragma before we chain the pragma in the Rep
11492 -- Item chain of Ent.
11493
11494 Check_Duplicate_Pragma (Ent);
11495 Record_Rep_Item (Ent, N);
11496 Set_Uses_Lock_Free (Ent, Val);
11497
11498 -- Anything else is incorrect placement
11499
11500 else
11501 Pragma_Misplaced;
11502 end if;
11503 end Lock_Free;
11504
11505 --------------------
11506 -- Locking_Policy --
11507 --------------------
11508
11509 -- pragma Locking_Policy (policy_IDENTIFIER);
11510
11511 when Pragma_Locking_Policy => declare
11512 subtype LP_Range is Name_Id
11513 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
11514 LP_Val : LP_Range;
11515 LP : Character;
11516
11517 begin
11518 Check_Ada_83_Warning;
11519 Check_Arg_Count (1);
11520 Check_No_Identifiers;
11521 Check_Arg_Is_Locking_Policy (Arg1);
11522 Check_Valid_Configuration_Pragma;
11523 LP_Val := Chars (Get_Pragma_Arg (Arg1));
11524
11525 case LP_Val is
11526 when Name_Ceiling_Locking =>
11527 LP := 'C';
11528 when Name_Inheritance_Locking =>
11529 LP := 'I';
11530 when Name_Concurrent_Readers_Locking =>
11531 LP := 'R';
11532 end case;
11533
11534 if Locking_Policy /= ' '
11535 and then Locking_Policy /= LP
11536 then
11537 Error_Msg_Sloc := Locking_Policy_Sloc;
11538 Error_Pragma ("locking policy incompatible with policy#");
11539
11540 -- Set new policy, but always preserve System_Location since we
11541 -- like the error message with the run time name.
11542
11543 else
11544 Locking_Policy := LP;
11545
11546 if Locking_Policy_Sloc /= System_Location then
11547 Locking_Policy_Sloc := Loc;
11548 end if;
11549 end if;
11550 end;
11551
11552 ----------------
11553 -- Long_Float --
11554 ----------------
11555
11556 -- pragma Long_Float (D_Float | G_Float);
11557
11558 when Pragma_Long_Float => Long_Float : declare
11559 begin
11560 GNAT_Pragma;
11561 Check_Valid_Configuration_Pragma;
11562 Check_Arg_Count (1);
11563 Check_No_Identifier (Arg1);
11564 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
11565
11566 if not OpenVMS_On_Target then
11567 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
11568 end if;
11569
11570 -- D_Float case
11571
11572 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
11573 if Opt.Float_Format_Long = 'G' then
11574 Error_Pragma_Arg
11575 ("G_Float previously specified", Arg1);
11576
11577 elsif Current_Sem_Unit /= Main_Unit
11578 and then Opt.Float_Format_Long /= 'D'
11579 then
11580 Error_Pragma_Arg
11581 ("main unit not compiled with pragma Long_Float (D_Float)",
11582 "\pragma% must be used consistently for whole partition",
11583 Arg1);
11584
11585 else
11586 Opt.Float_Format_Long := 'D';
11587 end if;
11588
11589 -- G_Float case (this is the default, does not need overriding)
11590
11591 else
11592 if Opt.Float_Format_Long = 'D' then
11593 Error_Pragma ("D_Float previously specified");
11594
11595 elsif Current_Sem_Unit /= Main_Unit
11596 and then Opt.Float_Format_Long /= 'G'
11597 then
11598 Error_Pragma_Arg
11599 ("main unit not compiled with pragma Long_Float (G_Float)",
11600 "\pragma% must be used consistently for whole partition",
11601 Arg1);
11602
11603 else
11604 Opt.Float_Format_Long := 'G';
11605 end if;
11606 end if;
11607
11608 Set_Standard_Fpt_Formats;
11609 end Long_Float;
11610
11611 --------------------
11612 -- Loop_Invariant --
11613 --------------------
11614
11615 -- pragma Loop_Invariant ( boolean_EXPRESSION );
11616
11617 when Pragma_Loop_Invariant => Loop_Invariant : declare
11618 begin
11619 GNAT_Pragma;
11620 S14_Pragma;
11621 Check_Arg_Count (1);
11622 Check_Loop_Invariant_Variant_Placement;
11623
11624 -- Completely ignore if disabled
11625
11626 if Check_Disabled (Pname) then
11627 Rewrite (N, Make_Null_Statement (Loc));
11628 Analyze (N);
11629 return;
11630 end if;
11631
11632 Preanalyze_And_Resolve (Expression (Arg1), Any_Boolean);
11633
11634 -- Transform pragma Loop_Invariant into equivalent pragma Check
11635 -- Generate:
11636 -- pragma Check (Loop_Invaraint, Arg1);
11637
11638 -- Seems completely wrong to hijack pragma Check this way ???
11639
11640 Rewrite (N,
11641 Make_Pragma (Loc,
11642 Chars => Name_Check,
11643 Pragma_Argument_Associations => New_List (
11644 Make_Pragma_Argument_Association (Loc,
11645 Expression => Make_Identifier (Loc, Name_Loop_Invariant)),
11646 Relocate_Node (Arg1))));
11647
11648 Analyze (N);
11649 end Loop_Invariant;
11650
11651 ------------------
11652 -- Loop_Variant --
11653 ------------------
11654
11655 -- pragma Loop_Variant
11656 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
11657
11658 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
11659
11660 -- CHANGE_DIRECTION ::= Increases | Decreases
11661
11662 when Pragma_Loop_Variant => Loop_Variant : declare
11663 Variant : Node_Id;
11664
11665 begin
11666 GNAT_Pragma;
11667 S14_Pragma;
11668 Check_At_Least_N_Arguments (1);
11669 Check_Loop_Invariant_Variant_Placement;
11670
11671 -- Completely ignore if disabled
11672
11673 if Check_Disabled (Pname) then
11674 Rewrite (N, Make_Null_Statement (Loc));
11675 Analyze (N);
11676 return;
11677 end if;
11678
11679 -- Process all increasing / decreasing expressions
11680
11681 Variant := First (Pragma_Argument_Associations (N));
11682 while Present (Variant) loop
11683 if Chars (Variant) /= Name_Decreases
11684 and then Chars (Variant) /= Name_Increases
11685 then
11686 Error_Pragma_Arg ("wrong change modifier", Variant);
11687 end if;
11688
11689 Preanalyze_And_Resolve (Expression (Variant), Any_Discrete);
11690
11691 Next (Variant);
11692 end loop;
11693 end Loop_Variant;
11694
11695 -----------------------
11696 -- Machine_Attribute --
11697 -----------------------
11698
11699 -- pragma Machine_Attribute (
11700 -- [Entity =>] LOCAL_NAME,
11701 -- [Attribute_Name =>] static_string_EXPRESSION
11702 -- [, [Info =>] static_EXPRESSION] );
11703
11704 when Pragma_Machine_Attribute => Machine_Attribute : declare
11705 Def_Id : Entity_Id;
11706
11707 begin
11708 GNAT_Pragma;
11709 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
11710
11711 if Arg_Count = 3 then
11712 Check_Optional_Identifier (Arg3, Name_Info);
11713 Check_Arg_Is_Static_Expression (Arg3);
11714 else
11715 Check_Arg_Count (2);
11716 end if;
11717
11718 Check_Optional_Identifier (Arg1, Name_Entity);
11719 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
11720 Check_Arg_Is_Local_Name (Arg1);
11721 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11722 Def_Id := Entity (Get_Pragma_Arg (Arg1));
11723
11724 if Is_Access_Type (Def_Id) then
11725 Def_Id := Designated_Type (Def_Id);
11726 end if;
11727
11728 if Rep_Item_Too_Early (Def_Id, N) then
11729 return;
11730 end if;
11731
11732 Def_Id := Underlying_Type (Def_Id);
11733
11734 -- The only processing required is to link this item on to the
11735 -- list of rep items for the given entity. This is accomplished
11736 -- by the call to Rep_Item_Too_Late (when no error is detected
11737 -- and False is returned).
11738
11739 if Rep_Item_Too_Late (Def_Id, N) then
11740 return;
11741 else
11742 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11743 end if;
11744 end Machine_Attribute;
11745
11746 ----------
11747 -- Main --
11748 ----------
11749
11750 -- pragma Main
11751 -- (MAIN_OPTION [, MAIN_OPTION]);
11752
11753 -- MAIN_OPTION ::=
11754 -- [STACK_SIZE =>] static_integer_EXPRESSION
11755 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
11756 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
11757
11758 when Pragma_Main => Main : declare
11759 Args : Args_List (1 .. 3);
11760 Names : constant Name_List (1 .. 3) := (
11761 Name_Stack_Size,
11762 Name_Task_Stack_Size_Default,
11763 Name_Time_Slicing_Enabled);
11764
11765 Nod : Node_Id;
11766
11767 begin
11768 GNAT_Pragma;
11769 Gather_Associations (Names, Args);
11770
11771 for J in 1 .. 2 loop
11772 if Present (Args (J)) then
11773 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11774 end if;
11775 end loop;
11776
11777 if Present (Args (3)) then
11778 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
11779 end if;
11780
11781 Nod := Next (N);
11782 while Present (Nod) loop
11783 if Nkind (Nod) = N_Pragma
11784 and then Pragma_Name (Nod) = Name_Main
11785 then
11786 Error_Msg_Name_1 := Pname;
11787 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11788 end if;
11789
11790 Next (Nod);
11791 end loop;
11792 end Main;
11793
11794 ------------------
11795 -- Main_Storage --
11796 ------------------
11797
11798 -- pragma Main_Storage
11799 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
11800
11801 -- MAIN_STORAGE_OPTION ::=
11802 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
11803 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
11804
11805 when Pragma_Main_Storage => Main_Storage : declare
11806 Args : Args_List (1 .. 2);
11807 Names : constant Name_List (1 .. 2) := (
11808 Name_Working_Storage,
11809 Name_Top_Guard);
11810
11811 Nod : Node_Id;
11812
11813 begin
11814 GNAT_Pragma;
11815 Gather_Associations (Names, Args);
11816
11817 for J in 1 .. 2 loop
11818 if Present (Args (J)) then
11819 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11820 end if;
11821 end loop;
11822
11823 Check_In_Main_Program;
11824
11825 Nod := Next (N);
11826 while Present (Nod) loop
11827 if Nkind (Nod) = N_Pragma
11828 and then Pragma_Name (Nod) = Name_Main_Storage
11829 then
11830 Error_Msg_Name_1 := Pname;
11831 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11832 end if;
11833
11834 Next (Nod);
11835 end loop;
11836 end Main_Storage;
11837
11838 -----------------
11839 -- Memory_Size --
11840 -----------------
11841
11842 -- pragma Memory_Size (NUMERIC_LITERAL)
11843
11844 when Pragma_Memory_Size =>
11845 GNAT_Pragma;
11846
11847 -- Memory size is simply ignored
11848
11849 Check_No_Identifiers;
11850 Check_Arg_Count (1);
11851 Check_Arg_Is_Integer_Literal (Arg1);
11852
11853 -------------
11854 -- No_Body --
11855 -------------
11856
11857 -- pragma No_Body;
11858
11859 -- The only correct use of this pragma is on its own in a file, in
11860 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
11861 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
11862 -- check for a file containing nothing but a No_Body pragma). If we
11863 -- attempt to process it during normal semantics processing, it means
11864 -- it was misplaced.
11865
11866 when Pragma_No_Body =>
11867 GNAT_Pragma;
11868 Pragma_Misplaced;
11869
11870 ---------------
11871 -- No_Return --
11872 ---------------
11873
11874 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
11875
11876 when Pragma_No_Return => No_Return : declare
11877 Id : Node_Id;
11878 E : Entity_Id;
11879 Found : Boolean;
11880 Arg : Node_Id;
11881
11882 begin
11883 Ada_2005_Pragma;
11884 Check_At_Least_N_Arguments (1);
11885
11886 -- Loop through arguments of pragma
11887
11888 Arg := Arg1;
11889 while Present (Arg) loop
11890 Check_Arg_Is_Local_Name (Arg);
11891 Id := Get_Pragma_Arg (Arg);
11892 Analyze (Id);
11893
11894 if not Is_Entity_Name (Id) then
11895 Error_Pragma_Arg ("entity name required", Arg);
11896 end if;
11897
11898 if Etype (Id) = Any_Type then
11899 raise Pragma_Exit;
11900 end if;
11901
11902 -- Loop to find matching procedures
11903
11904 E := Entity (Id);
11905 Found := False;
11906 while Present (E)
11907 and then Scope (E) = Current_Scope
11908 loop
11909 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
11910 Set_No_Return (E);
11911
11912 -- Set flag on any alias as well
11913
11914 if Is_Overloadable (E) and then Present (Alias (E)) then
11915 Set_No_Return (Alias (E));
11916 end if;
11917
11918 Found := True;
11919 end if;
11920
11921 exit when From_Aspect_Specification (N);
11922 E := Homonym (E);
11923 end loop;
11924
11925 if not Found then
11926 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11927 end if;
11928
11929 Next (Arg);
11930 end loop;
11931 end No_Return;
11932
11933 -----------------
11934 -- No_Run_Time --
11935 -----------------
11936
11937 -- pragma No_Run_Time;
11938
11939 -- Note: this pragma is retained for backwards compatibility. See
11940 -- body of Rtsfind for full details on its handling.
11941
11942 when Pragma_No_Run_Time =>
11943 GNAT_Pragma;
11944 Check_Valid_Configuration_Pragma;
11945 Check_Arg_Count (0);
11946
11947 No_Run_Time_Mode := True;
11948 Configurable_Run_Time_Mode := True;
11949
11950 -- Set Duration to 32 bits if word size is 32
11951
11952 if Ttypes.System_Word_Size = 32 then
11953 Duration_32_Bits_On_Target := True;
11954 end if;
11955
11956 -- Set appropriate restrictions
11957
11958 Set_Restriction (No_Finalization, N);
11959 Set_Restriction (No_Exception_Handlers, N);
11960 Set_Restriction (Max_Tasks, N, 0);
11961 Set_Restriction (No_Tasking, N);
11962
11963 ------------------------
11964 -- No_Strict_Aliasing --
11965 ------------------------
11966
11967 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11968
11969 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
11970 E_Id : Entity_Id;
11971
11972 begin
11973 GNAT_Pragma;
11974 Check_At_Most_N_Arguments (1);
11975
11976 if Arg_Count = 0 then
11977 Check_Valid_Configuration_Pragma;
11978 Opt.No_Strict_Aliasing := True;
11979
11980 else
11981 Check_Optional_Identifier (Arg2, Name_Entity);
11982 Check_Arg_Is_Local_Name (Arg1);
11983 E_Id := Entity (Get_Pragma_Arg (Arg1));
11984
11985 if E_Id = Any_Type then
11986 return;
11987 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11988 Error_Pragma_Arg ("pragma% requires access type", Arg1);
11989 end if;
11990
11991 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
11992 end if;
11993 end No_Strict_Aliasing;
11994
11995 -----------------------
11996 -- Normalize_Scalars --
11997 -----------------------
11998
11999 -- pragma Normalize_Scalars;
12000
12001 when Pragma_Normalize_Scalars =>
12002 Check_Ada_83_Warning;
12003 Check_Arg_Count (0);
12004 Check_Valid_Configuration_Pragma;
12005
12006 -- Normalize_Scalars creates false positives in CodePeer, and
12007 -- incorrect negative results in Alfa mode, so ignore this pragma
12008 -- in these modes.
12009
12010 if not (CodePeer_Mode or Alfa_Mode) then
12011 Normalize_Scalars := True;
12012 Init_Or_Norm_Scalars := True;
12013 end if;
12014
12015 -----------------
12016 -- Obsolescent --
12017 -----------------
12018
12019 -- pragma Obsolescent;
12020
12021 -- pragma Obsolescent (
12022 -- [Message =>] static_string_EXPRESSION
12023 -- [,[Version =>] Ada_05]]);
12024
12025 -- pragma Obsolescent (
12026 -- [Entity =>] NAME
12027 -- [,[Message =>] static_string_EXPRESSION
12028 -- [,[Version =>] Ada_05]] );
12029
12030 when Pragma_Obsolescent => Obsolescent : declare
12031 Ename : Node_Id;
12032 Decl : Node_Id;
12033
12034 procedure Set_Obsolescent (E : Entity_Id);
12035 -- Given an entity Ent, mark it as obsolescent if appropriate
12036
12037 ---------------------
12038 -- Set_Obsolescent --
12039 ---------------------
12040
12041 procedure Set_Obsolescent (E : Entity_Id) is
12042 Active : Boolean;
12043 Ent : Entity_Id;
12044 S : String_Id;
12045
12046 begin
12047 Active := True;
12048 Ent := E;
12049
12050 -- Entity name was given
12051
12052 if Present (Ename) then
12053
12054 -- If entity name matches, we are fine. Save entity in
12055 -- pragma argument, for ASIS use.
12056
12057 if Chars (Ename) = Chars (Ent) then
12058 Set_Entity (Ename, Ent);
12059 Generate_Reference (Ent, Ename);
12060
12061 -- If entity name does not match, only possibility is an
12062 -- enumeration literal from an enumeration type declaration.
12063
12064 elsif Ekind (Ent) /= E_Enumeration_Type then
12065 Error_Pragma
12066 ("pragma % entity name does not match declaration");
12067
12068 else
12069 Ent := First_Literal (E);
12070 loop
12071 if No (Ent) then
12072 Error_Pragma
12073 ("pragma % entity name does not match any " &
12074 "enumeration literal");
12075
12076 elsif Chars (Ent) = Chars (Ename) then
12077 Set_Entity (Ename, Ent);
12078 Generate_Reference (Ent, Ename);
12079 exit;
12080
12081 else
12082 Ent := Next_Literal (Ent);
12083 end if;
12084 end loop;
12085 end if;
12086 end if;
12087
12088 -- Ent points to entity to be marked
12089
12090 if Arg_Count >= 1 then
12091
12092 -- Deal with static string argument
12093
12094 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12095 S := Strval (Get_Pragma_Arg (Arg1));
12096
12097 for J in 1 .. String_Length (S) loop
12098 if not In_Character_Range (Get_String_Char (S, J)) then
12099 Error_Pragma_Arg
12100 ("pragma% argument does not allow wide characters",
12101 Arg1);
12102 end if;
12103 end loop;
12104
12105 Obsolescent_Warnings.Append
12106 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
12107
12108 -- Check for Ada_05 parameter
12109
12110 if Arg_Count /= 1 then
12111 Check_Arg_Count (2);
12112
12113 declare
12114 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
12115
12116 begin
12117 Check_Arg_Is_Identifier (Argx);
12118
12119 if Chars (Argx) /= Name_Ada_05 then
12120 Error_Msg_Name_2 := Name_Ada_05;
12121 Error_Pragma_Arg
12122 ("only allowed argument for pragma% is %", Argx);
12123 end if;
12124
12125 if Ada_Version_Explicit < Ada_2005
12126 or else not Warn_On_Ada_2005_Compatibility
12127 then
12128 Active := False;
12129 end if;
12130 end;
12131 end if;
12132 end if;
12133
12134 -- Set flag if pragma active
12135
12136 if Active then
12137 Set_Is_Obsolescent (Ent);
12138 end if;
12139
12140 return;
12141 end Set_Obsolescent;
12142
12143 -- Start of processing for pragma Obsolescent
12144
12145 begin
12146 GNAT_Pragma;
12147
12148 Check_At_Most_N_Arguments (3);
12149
12150 -- See if first argument specifies an entity name
12151
12152 if Arg_Count >= 1
12153 and then
12154 (Chars (Arg1) = Name_Entity
12155 or else
12156 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
12157 N_Identifier,
12158 N_Operator_Symbol))
12159 then
12160 Ename := Get_Pragma_Arg (Arg1);
12161
12162 -- Eliminate first argument, so we can share processing
12163
12164 Arg1 := Arg2;
12165 Arg2 := Arg3;
12166 Arg_Count := Arg_Count - 1;
12167
12168 -- No Entity name argument given
12169
12170 else
12171 Ename := Empty;
12172 end if;
12173
12174 if Arg_Count >= 1 then
12175 Check_Optional_Identifier (Arg1, Name_Message);
12176
12177 if Arg_Count = 2 then
12178 Check_Optional_Identifier (Arg2, Name_Version);
12179 end if;
12180 end if;
12181
12182 -- Get immediately preceding declaration
12183
12184 Decl := Prev (N);
12185 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
12186 Prev (Decl);
12187 end loop;
12188
12189 -- Cases where we do not follow anything other than another pragma
12190
12191 if No (Decl) then
12192
12193 -- First case: library level compilation unit declaration with
12194 -- the pragma immediately following the declaration.
12195
12196 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
12197 Set_Obsolescent
12198 (Defining_Entity (Unit (Parent (Parent (N)))));
12199 return;
12200
12201 -- Case 2: library unit placement for package
12202
12203 else
12204 declare
12205 Ent : constant Entity_Id := Find_Lib_Unit_Name;
12206 begin
12207 if Is_Package_Or_Generic_Package (Ent) then
12208 Set_Obsolescent (Ent);
12209 return;
12210 end if;
12211 end;
12212 end if;
12213
12214 -- Cases where we must follow a declaration
12215
12216 else
12217 if Nkind (Decl) not in N_Declaration
12218 and then Nkind (Decl) not in N_Later_Decl_Item
12219 and then Nkind (Decl) not in N_Generic_Declaration
12220 and then Nkind (Decl) not in N_Renaming_Declaration
12221 then
12222 Error_Pragma
12223 ("pragma% misplaced, "
12224 & "must immediately follow a declaration");
12225
12226 else
12227 Set_Obsolescent (Defining_Entity (Decl));
12228 return;
12229 end if;
12230 end if;
12231 end Obsolescent;
12232
12233 --------------
12234 -- Optimize --
12235 --------------
12236
12237 -- pragma Optimize (Time | Space | Off);
12238
12239 -- The actual check for optimize is done in Gigi. Note that this
12240 -- pragma does not actually change the optimization setting, it
12241 -- simply checks that it is consistent with the pragma.
12242
12243 when Pragma_Optimize =>
12244 Check_No_Identifiers;
12245 Check_Arg_Count (1);
12246 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
12247
12248 ------------------------
12249 -- Optimize_Alignment --
12250 ------------------------
12251
12252 -- pragma Optimize_Alignment (Time | Space | Off);
12253
12254 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
12255 GNAT_Pragma;
12256 Check_No_Identifiers;
12257 Check_Arg_Count (1);
12258 Check_Valid_Configuration_Pragma;
12259
12260 declare
12261 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
12262 begin
12263 case Nam is
12264 when Name_Time =>
12265 Opt.Optimize_Alignment := 'T';
12266 when Name_Space =>
12267 Opt.Optimize_Alignment := 'S';
12268 when Name_Off =>
12269 Opt.Optimize_Alignment := 'O';
12270 when others =>
12271 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
12272 end case;
12273 end;
12274
12275 -- Set indication that mode is set locally. If we are in fact in a
12276 -- configuration pragma file, this setting is harmless since the
12277 -- switch will get reset anyway at the start of each unit.
12278
12279 Optimize_Alignment_Local := True;
12280 end Optimize_Alignment;
12281
12282 -------------------
12283 -- Overflow_Mode --
12284 -------------------
12285
12286 -- pragma Overflow_Mode
12287 -- ([General => ] MODE [, [Assertions => ] MODE]);
12288
12289 -- MODE := STRICT | MINIMIZED | ELIMINATED
12290
12291 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
12292 -- since System.Bignums makes this assumption. This is true of nearly
12293 -- all (all?) targets.
12294
12295 when Pragma_Overflow_Mode => Overflow_Mode : declare
12296 function Get_Overflow_Mode
12297 (Name : Name_Id;
12298 Arg : Node_Id) return Overflow_Mode_Type;
12299 -- Function to process one pragma argument, Arg. If an identifier
12300 -- is present, it must be Name. Mode type is returned if a valid
12301 -- argument exists, otherwise an error is signalled.
12302
12303 -----------------------
12304 -- Get_Overflow_Mode --
12305 -----------------------
12306
12307 function Get_Overflow_Mode
12308 (Name : Name_Id;
12309 Arg : Node_Id) return Overflow_Mode_Type
12310 is
12311 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
12312
12313 begin
12314 Check_Optional_Identifier (Arg, Name);
12315 Check_Arg_Is_Identifier (Argx);
12316
12317 if Chars (Argx) = Name_Strict then
12318 return Strict;
12319
12320 elsif Chars (Argx) = Name_Minimized then
12321 return Minimized;
12322
12323 elsif Chars (Argx) = Name_Eliminated then
12324 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
12325 Error_Pragma_Arg
12326 ("Eliminated not implemented on this target", Argx);
12327 else
12328 return Eliminated;
12329 end if;
12330
12331 else
12332 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
12333 end if;
12334 end Get_Overflow_Mode;
12335
12336 -- Start of processing for Overflow_Mode
12337
12338 begin
12339 GNAT_Pragma;
12340 Check_At_Least_N_Arguments (1);
12341 Check_At_Most_N_Arguments (2);
12342
12343 -- Process first argument
12344
12345 Scope_Suppress.Overflow_Mode_General :=
12346 Get_Overflow_Mode (Name_General, Arg1);
12347
12348 -- Case of only one argument
12349
12350 if Arg_Count = 1 then
12351 Scope_Suppress.Overflow_Mode_Assertions :=
12352 Scope_Suppress.Overflow_Mode_General;
12353
12354 -- Case of two arguments present
12355
12356 else
12357 Scope_Suppress.Overflow_Mode_Assertions :=
12358 Get_Overflow_Mode (Name_Assertions, Arg2);
12359 end if;
12360 end Overflow_Mode;
12361
12362 -------------
12363 -- Ordered --
12364 -------------
12365
12366 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
12367
12368 when Pragma_Ordered => Ordered : declare
12369 Assoc : constant Node_Id := Arg1;
12370 Type_Id : Node_Id;
12371 Typ : Entity_Id;
12372
12373 begin
12374 GNAT_Pragma;
12375 Check_No_Identifiers;
12376 Check_Arg_Count (1);
12377 Check_Arg_Is_Local_Name (Arg1);
12378
12379 Type_Id := Get_Pragma_Arg (Assoc);
12380 Find_Type (Type_Id);
12381 Typ := Entity (Type_Id);
12382
12383 if Typ = Any_Type then
12384 return;
12385 else
12386 Typ := Underlying_Type (Typ);
12387 end if;
12388
12389 if not Is_Enumeration_Type (Typ) then
12390 Error_Pragma ("pragma% must specify enumeration type");
12391 end if;
12392
12393 Check_First_Subtype (Arg1);
12394 Set_Has_Pragma_Ordered (Base_Type (Typ));
12395 end Ordered;
12396
12397 ----------
12398 -- Pack --
12399 ----------
12400
12401 -- pragma Pack (first_subtype_LOCAL_NAME);
12402
12403 when Pragma_Pack => Pack : declare
12404 Assoc : constant Node_Id := Arg1;
12405 Type_Id : Node_Id;
12406 Typ : Entity_Id;
12407 Ctyp : Entity_Id;
12408 Ignore : Boolean := False;
12409
12410 begin
12411 Check_No_Identifiers;
12412 Check_Arg_Count (1);
12413 Check_Arg_Is_Local_Name (Arg1);
12414
12415 Type_Id := Get_Pragma_Arg (Assoc);
12416 Find_Type (Type_Id);
12417 Typ := Entity (Type_Id);
12418
12419 if Typ = Any_Type
12420 or else Rep_Item_Too_Early (Typ, N)
12421 then
12422 return;
12423 else
12424 Typ := Underlying_Type (Typ);
12425 end if;
12426
12427 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
12428 Error_Pragma ("pragma% must specify array or record type");
12429 end if;
12430
12431 Check_First_Subtype (Arg1);
12432 Check_Duplicate_Pragma (Typ);
12433
12434 -- Array type
12435
12436 if Is_Array_Type (Typ) then
12437 Ctyp := Component_Type (Typ);
12438
12439 -- Ignore pack that does nothing
12440
12441 if Known_Static_Esize (Ctyp)
12442 and then Known_Static_RM_Size (Ctyp)
12443 and then Esize (Ctyp) = RM_Size (Ctyp)
12444 and then Addressable (Esize (Ctyp))
12445 then
12446 Ignore := True;
12447 end if;
12448
12449 -- Process OK pragma Pack. Note that if there is a separate
12450 -- component clause present, the Pack will be cancelled. This
12451 -- processing is in Freeze.
12452
12453 if not Rep_Item_Too_Late (Typ, N) then
12454
12455 -- In the context of static code analysis, we do not need
12456 -- complex front-end expansions related to pragma Pack,
12457 -- so disable handling of pragma Pack in these cases.
12458
12459 if CodePeer_Mode or Alfa_Mode then
12460 null;
12461
12462 -- Don't attempt any packing for VM targets. We possibly
12463 -- could deal with some cases of array bit-packing, but we
12464 -- don't bother, since this is not a typical kind of
12465 -- representation in the VM context anyway (and would not
12466 -- for example work nicely with the debugger).
12467
12468 elsif VM_Target /= No_VM then
12469 if not GNAT_Mode then
12470 Error_Pragma
12471 ("?pragma% ignored in this configuration");
12472 end if;
12473
12474 -- Normal case where we do the pack action
12475
12476 else
12477 if not Ignore then
12478 Set_Is_Packed (Base_Type (Typ));
12479 Set_Has_Non_Standard_Rep (Base_Type (Typ));
12480 end if;
12481
12482 Set_Has_Pragma_Pack (Base_Type (Typ));
12483 end if;
12484 end if;
12485
12486 -- For record types, the pack is always effective
12487
12488 else pragma Assert (Is_Record_Type (Typ));
12489 if not Rep_Item_Too_Late (Typ, N) then
12490
12491 -- Ignore pack request with warning in VM mode (skip warning
12492 -- if we are compiling GNAT run time library).
12493
12494 if VM_Target /= No_VM then
12495 if not GNAT_Mode then
12496 Error_Pragma
12497 ("?pragma% ignored in this configuration");
12498 end if;
12499
12500 -- Normal case of pack request active
12501
12502 else
12503 Set_Is_Packed (Base_Type (Typ));
12504 Set_Has_Pragma_Pack (Base_Type (Typ));
12505 Set_Has_Non_Standard_Rep (Base_Type (Typ));
12506 end if;
12507 end if;
12508 end if;
12509 end Pack;
12510
12511 ----------
12512 -- Page --
12513 ----------
12514
12515 -- pragma Page;
12516
12517 -- There is nothing to do here, since we did all the processing for
12518 -- this pragma in Par.Prag (so that it works properly even in syntax
12519 -- only mode).
12520
12521 when Pragma_Page =>
12522 null;
12523
12524 ----------------------------------
12525 -- Partition_Elaboration_Policy --
12526 ----------------------------------
12527
12528 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
12529
12530 when Pragma_Partition_Elaboration_Policy => declare
12531 subtype PEP_Range is Name_Id
12532 range First_Partition_Elaboration_Policy_Name
12533 .. Last_Partition_Elaboration_Policy_Name;
12534 PEP_Val : PEP_Range;
12535 PEP : Character;
12536
12537 begin
12538 Ada_2005_Pragma;
12539 Check_Arg_Count (1);
12540 Check_No_Identifiers;
12541 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
12542 Check_Valid_Configuration_Pragma;
12543 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
12544
12545 case PEP_Val is
12546 when Name_Concurrent =>
12547 PEP := 'C';
12548 when Name_Sequential =>
12549 PEP := 'S';
12550 end case;
12551
12552 if Partition_Elaboration_Policy /= ' '
12553 and then Partition_Elaboration_Policy /= PEP
12554 then
12555 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
12556 Error_Pragma
12557 ("partition elaboration policy incompatible with policy#");
12558
12559 -- Set new policy, but always preserve System_Location since we
12560 -- like the error message with the run time name.
12561
12562 else
12563 Partition_Elaboration_Policy := PEP;
12564
12565 if Partition_Elaboration_Policy_Sloc /= System_Location then
12566 Partition_Elaboration_Policy_Sloc := Loc;
12567 end if;
12568 end if;
12569 end;
12570
12571 -------------
12572 -- Passive --
12573 -------------
12574
12575 -- pragma Passive [(PASSIVE_FORM)];
12576
12577 -- PASSIVE_FORM ::= Semaphore | No
12578
12579 when Pragma_Passive =>
12580 GNAT_Pragma;
12581
12582 if Nkind (Parent (N)) /= N_Task_Definition then
12583 Error_Pragma ("pragma% must be within task definition");
12584 end if;
12585
12586 if Arg_Count /= 0 then
12587 Check_Arg_Count (1);
12588 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
12589 end if;
12590
12591 ----------------------------------
12592 -- Preelaborable_Initialization --
12593 ----------------------------------
12594
12595 -- pragma Preelaborable_Initialization (DIRECT_NAME);
12596
12597 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
12598 Ent : Entity_Id;
12599
12600 begin
12601 Ada_2005_Pragma;
12602 Check_Arg_Count (1);
12603 Check_No_Identifiers;
12604 Check_Arg_Is_Identifier (Arg1);
12605 Check_Arg_Is_Local_Name (Arg1);
12606 Check_First_Subtype (Arg1);
12607 Ent := Entity (Get_Pragma_Arg (Arg1));
12608
12609 if not (Is_Private_Type (Ent)
12610 or else
12611 Is_Protected_Type (Ent)
12612 or else
12613 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
12614 then
12615 Error_Pragma_Arg
12616 ("pragma % can only be applied to private, formal derived or "
12617 & "protected type",
12618 Arg1);
12619 end if;
12620
12621 -- Give an error if the pragma is applied to a protected type that
12622 -- does not qualify (due to having entries, or due to components
12623 -- that do not qualify).
12624
12625 if Is_Protected_Type (Ent)
12626 and then not Has_Preelaborable_Initialization (Ent)
12627 then
12628 Error_Msg_N
12629 ("protected type & does not have preelaborable " &
12630 "initialization", Ent);
12631
12632 -- Otherwise mark the type as definitely having preelaborable
12633 -- initialization.
12634
12635 else
12636 Set_Known_To_Have_Preelab_Init (Ent);
12637 end if;
12638
12639 if Has_Pragma_Preelab_Init (Ent)
12640 and then Warn_On_Redundant_Constructs
12641 then
12642 Error_Pragma ("?duplicate pragma%!");
12643 else
12644 Set_Has_Pragma_Preelab_Init (Ent);
12645 end if;
12646 end Preelab_Init;
12647
12648 --------------------
12649 -- Persistent_BSS --
12650 --------------------
12651
12652 -- pragma Persistent_BSS [(object_NAME)];
12653
12654 when Pragma_Persistent_BSS => Persistent_BSS : declare
12655 Decl : Node_Id;
12656 Ent : Entity_Id;
12657 Prag : Node_Id;
12658
12659 begin
12660 GNAT_Pragma;
12661 Check_At_Most_N_Arguments (1);
12662
12663 -- Case of application to specific object (one argument)
12664
12665 if Arg_Count = 1 then
12666 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12667
12668 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
12669 or else not
12670 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
12671 E_Constant)
12672 then
12673 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
12674 end if;
12675
12676 Ent := Entity (Get_Pragma_Arg (Arg1));
12677 Decl := Parent (Ent);
12678
12679 -- Check for duplication before inserting in list of
12680 -- representation items.
12681
12682 Check_Duplicate_Pragma (Ent);
12683
12684 if Rep_Item_Too_Late (Ent, N) then
12685 return;
12686 end if;
12687
12688 if Present (Expression (Decl)) then
12689 Error_Pragma_Arg
12690 ("object for pragma% cannot have initialization", Arg1);
12691 end if;
12692
12693 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
12694 Error_Pragma_Arg
12695 ("object type for pragma% is not potentially persistent",
12696 Arg1);
12697 end if;
12698
12699 Prag :=
12700 Make_Linker_Section_Pragma
12701 (Ent, Sloc (N), ".persistent.bss");
12702 Insert_After (N, Prag);
12703 Analyze (Prag);
12704
12705 -- Case of use as configuration pragma with no arguments
12706
12707 else
12708 Check_Valid_Configuration_Pragma;
12709 Persistent_BSS_Mode := True;
12710 end if;
12711 end Persistent_BSS;
12712
12713 -------------
12714 -- Polling --
12715 -------------
12716
12717 -- pragma Polling (ON | OFF);
12718
12719 when Pragma_Polling =>
12720 GNAT_Pragma;
12721 Check_Arg_Count (1);
12722 Check_No_Identifiers;
12723 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12724 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
12725
12726 -------------------
12727 -- Postcondition --
12728 -------------------
12729
12730 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
12731 -- [,[Message =>] String_EXPRESSION]);
12732
12733 when Pragma_Postcondition => Postcondition : declare
12734 In_Body : Boolean;
12735 pragma Warnings (Off, In_Body);
12736
12737 begin
12738 GNAT_Pragma;
12739 Check_At_Least_N_Arguments (1);
12740 Check_At_Most_N_Arguments (2);
12741 Check_Optional_Identifier (Arg1, Name_Check);
12742
12743 -- All we need to do here is call the common check procedure,
12744 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
12745
12746 Check_Precondition_Postcondition (In_Body);
12747 end Postcondition;
12748
12749 ------------------
12750 -- Precondition --
12751 ------------------
12752
12753 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
12754 -- [,[Message =>] String_EXPRESSION]);
12755
12756 when Pragma_Precondition => Precondition : declare
12757 In_Body : Boolean;
12758
12759 begin
12760 GNAT_Pragma;
12761 Check_At_Least_N_Arguments (1);
12762 Check_At_Most_N_Arguments (2);
12763 Check_Optional_Identifier (Arg1, Name_Check);
12764 Check_Precondition_Postcondition (In_Body);
12765
12766 -- If in spec, nothing more to do. If in body, then we convert the
12767 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
12768 -- this whether or not precondition checks are enabled. That works
12769 -- fine since pragma Check will do this check, and will also
12770 -- analyze the condition itself in the proper context.
12771
12772 if In_Body then
12773 Rewrite (N,
12774 Make_Pragma (Loc,
12775 Chars => Name_Check,
12776 Pragma_Argument_Associations => New_List (
12777 Make_Pragma_Argument_Association (Loc,
12778 Expression => Make_Identifier (Loc, Name_Precondition)),
12779
12780 Make_Pragma_Argument_Association (Sloc (Arg1),
12781 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
12782
12783 if Arg_Count = 2 then
12784 Append_To (Pragma_Argument_Associations (N),
12785 Make_Pragma_Argument_Association (Sloc (Arg2),
12786 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
12787 end if;
12788
12789 Analyze (N);
12790 end if;
12791 end Precondition;
12792
12793 ---------------
12794 -- Predicate --
12795 ---------------
12796
12797 -- pragma Predicate
12798 -- ([Entity =>] type_LOCAL_NAME,
12799 -- [Check =>] EXPRESSION);
12800
12801 when Pragma_Predicate => Predicate : declare
12802 Type_Id : Node_Id;
12803 Typ : Entity_Id;
12804
12805 Discard : Boolean;
12806 pragma Unreferenced (Discard);
12807
12808 begin
12809 GNAT_Pragma;
12810 Check_Arg_Count (2);
12811 Check_Optional_Identifier (Arg1, Name_Entity);
12812 Check_Optional_Identifier (Arg2, Name_Check);
12813
12814 Check_Arg_Is_Local_Name (Arg1);
12815
12816 Type_Id := Get_Pragma_Arg (Arg1);
12817 Find_Type (Type_Id);
12818 Typ := Entity (Type_Id);
12819
12820 if Typ = Any_Type then
12821 return;
12822 end if;
12823
12824 -- The remaining processing is simply to link the pragma on to
12825 -- the rep item chain, for processing when the type is frozen.
12826 -- This is accomplished by a call to Rep_Item_Too_Late. We also
12827 -- mark the type as having predicates.
12828
12829 Set_Has_Predicates (Typ);
12830 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12831 end Predicate;
12832
12833 ------------------
12834 -- Preelaborate --
12835 ------------------
12836
12837 -- pragma Preelaborate [(library_unit_NAME)];
12838
12839 -- Set the flag Is_Preelaborated of program unit name entity
12840
12841 when Pragma_Preelaborate => Preelaborate : declare
12842 Pa : constant Node_Id := Parent (N);
12843 Pk : constant Node_Kind := Nkind (Pa);
12844 Ent : Entity_Id;
12845
12846 begin
12847 Check_Ada_83_Warning;
12848 Check_Valid_Library_Unit_Pragma;
12849
12850 if Nkind (N) = N_Null_Statement then
12851 return;
12852 end if;
12853
12854 Ent := Find_Lib_Unit_Name;
12855 Check_Duplicate_Pragma (Ent);
12856
12857 -- This filters out pragmas inside generic parent then
12858 -- show up inside instantiation
12859
12860 if Present (Ent)
12861 and then not (Pk = N_Package_Specification
12862 and then Present (Generic_Parent (Pa)))
12863 then
12864 if not Debug_Flag_U then
12865 Set_Is_Preelaborated (Ent);
12866 Set_Suppress_Elaboration_Warnings (Ent);
12867 end if;
12868 end if;
12869 end Preelaborate;
12870
12871 ---------------------
12872 -- Preelaborate_05 --
12873 ---------------------
12874
12875 -- pragma Preelaborate_05 [(library_unit_NAME)];
12876
12877 -- This pragma is useable only in GNAT_Mode, where it is used like
12878 -- pragma Preelaborate but it is only effective in Ada 2005 mode
12879 -- (otherwise it is ignored). This is used to implement AI-362 which
12880 -- recategorizes some run-time packages in Ada 2005 mode.
12881
12882 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
12883 Ent : Entity_Id;
12884
12885 begin
12886 GNAT_Pragma;
12887 Check_Valid_Library_Unit_Pragma;
12888
12889 if not GNAT_Mode then
12890 Error_Pragma ("pragma% only available in GNAT mode");
12891 end if;
12892
12893 if Nkind (N) = N_Null_Statement then
12894 return;
12895 end if;
12896
12897 -- This is one of the few cases where we need to test the value of
12898 -- Ada_Version_Explicit rather than Ada_Version (which is always
12899 -- set to Ada_2012 in a predefined unit), we need to know the
12900 -- explicit version set to know if this pragma is active.
12901
12902 if Ada_Version_Explicit >= Ada_2005 then
12903 Ent := Find_Lib_Unit_Name;
12904 Set_Is_Preelaborated (Ent);
12905 Set_Suppress_Elaboration_Warnings (Ent);
12906 end if;
12907 end Preelaborate_05;
12908
12909 --------------
12910 -- Priority --
12911 --------------
12912
12913 -- pragma Priority (EXPRESSION);
12914
12915 when Pragma_Priority => Priority : declare
12916 P : constant Node_Id := Parent (N);
12917 Arg : Node_Id;
12918 Ent : Entity_Id;
12919
12920 begin
12921 Check_No_Identifiers;
12922 Check_Arg_Count (1);
12923
12924 -- Subprogram case
12925
12926 if Nkind (P) = N_Subprogram_Body then
12927 Check_In_Main_Program;
12928
12929 Ent := Defining_Unit_Name (Specification (P));
12930
12931 if Nkind (Ent) = N_Defining_Program_Unit_Name then
12932 Ent := Defining_Identifier (Ent);
12933 end if;
12934
12935 Arg := Get_Pragma_Arg (Arg1);
12936 Analyze_And_Resolve (Arg, Standard_Integer);
12937
12938 -- Must be static
12939
12940 if not Is_Static_Expression (Arg) then
12941 Flag_Non_Static_Expr
12942 ("main subprogram priority is not static!", Arg);
12943 raise Pragma_Exit;
12944
12945 -- If constraint error, then we already signalled an error
12946
12947 elsif Raises_Constraint_Error (Arg) then
12948 null;
12949
12950 -- Otherwise check in range
12951
12952 else
12953 declare
12954 Val : constant Uint := Expr_Value (Arg);
12955
12956 begin
12957 if Val < 0
12958 or else Val > Expr_Value (Expression
12959 (Parent (RTE (RE_Max_Priority))))
12960 then
12961 Error_Pragma_Arg
12962 ("main subprogram priority is out of range", Arg1);
12963 end if;
12964 end;
12965 end if;
12966
12967 Set_Main_Priority
12968 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12969
12970 -- Load an arbitrary entity from System.Tasking to make sure
12971 -- this package is implicitly with'ed, since we need to have
12972 -- the tasking run-time active for the pragma Priority to have
12973 -- any effect.
12974
12975 declare
12976 Discard : Entity_Id;
12977 pragma Warnings (Off, Discard);
12978 begin
12979 Discard := RTE (RE_Task_List);
12980 end;
12981
12982 -- Task or Protected, must be of type Integer
12983
12984 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12985 Arg := Get_Pragma_Arg (Arg1);
12986 Ent := Defining_Identifier (Parent (P));
12987
12988 -- The expression must be analyzed in the special manner
12989 -- described in "Handling of Default and Per-Object
12990 -- Expressions" in sem.ads.
12991
12992 Preanalyze_Spec_Expression (Arg, Standard_Integer);
12993
12994 if not Is_Static_Expression (Arg) then
12995 Check_Restriction (Static_Priorities, Arg);
12996 end if;
12997
12998 -- Anything else is incorrect
12999
13000 else
13001 Pragma_Misplaced;
13002 end if;
13003
13004 -- Check duplicate pragma before we chain the pragma in the Rep
13005 -- Item chain of Ent.
13006
13007 Check_Duplicate_Pragma (Ent);
13008 Record_Rep_Item (Ent, N);
13009 end Priority;
13010
13011 -----------------------------------
13012 -- Priority_Specific_Dispatching --
13013 -----------------------------------
13014
13015 -- pragma Priority_Specific_Dispatching (
13016 -- policy_IDENTIFIER,
13017 -- first_priority_EXPRESSION,
13018 -- last_priority_EXPRESSION);
13019
13020 when Pragma_Priority_Specific_Dispatching =>
13021 Priority_Specific_Dispatching : declare
13022 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
13023 -- This is the entity System.Any_Priority;
13024
13025 DP : Character;
13026 Lower_Bound : Node_Id;
13027 Upper_Bound : Node_Id;
13028 Lower_Val : Uint;
13029 Upper_Val : Uint;
13030
13031 begin
13032 Ada_2005_Pragma;
13033 Check_Arg_Count (3);
13034 Check_No_Identifiers;
13035 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13036 Check_Valid_Configuration_Pragma;
13037 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13038 DP := Fold_Upper (Name_Buffer (1));
13039
13040 Lower_Bound := Get_Pragma_Arg (Arg2);
13041 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
13042 Lower_Val := Expr_Value (Lower_Bound);
13043
13044 Upper_Bound := Get_Pragma_Arg (Arg3);
13045 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
13046 Upper_Val := Expr_Value (Upper_Bound);
13047
13048 -- It is not allowed to use Task_Dispatching_Policy and
13049 -- Priority_Specific_Dispatching in the same partition.
13050
13051 if Task_Dispatching_Policy /= ' ' then
13052 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13053 Error_Pragma
13054 ("pragma% incompatible with Task_Dispatching_Policy#");
13055
13056 -- Check lower bound in range
13057
13058 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
13059 or else
13060 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
13061 then
13062 Error_Pragma_Arg
13063 ("first_priority is out of range", Arg2);
13064
13065 -- Check upper bound in range
13066
13067 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
13068 or else
13069 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
13070 then
13071 Error_Pragma_Arg
13072 ("last_priority is out of range", Arg3);
13073
13074 -- Check that the priority range is valid
13075
13076 elsif Lower_Val > Upper_Val then
13077 Error_Pragma
13078 ("last_priority_expression must be greater than" &
13079 " or equal to first_priority_expression");
13080
13081 -- Store the new policy, but always preserve System_Location since
13082 -- we like the error message with the run-time name.
13083
13084 else
13085 -- Check overlapping in the priority ranges specified in other
13086 -- Priority_Specific_Dispatching pragmas within the same
13087 -- partition. We can only check those we know about!
13088
13089 for J in
13090 Specific_Dispatching.First .. Specific_Dispatching.Last
13091 loop
13092 if Specific_Dispatching.Table (J).First_Priority in
13093 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
13094 or else Specific_Dispatching.Table (J).Last_Priority in
13095 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
13096 then
13097 Error_Msg_Sloc :=
13098 Specific_Dispatching.Table (J).Pragma_Loc;
13099 Error_Pragma
13100 ("priority range overlaps with "
13101 & "Priority_Specific_Dispatching#");
13102 end if;
13103 end loop;
13104
13105 -- The use of Priority_Specific_Dispatching is incompatible
13106 -- with Task_Dispatching_Policy.
13107
13108 if Task_Dispatching_Policy /= ' ' then
13109 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13110 Error_Pragma
13111 ("Priority_Specific_Dispatching incompatible "
13112 & "with Task_Dispatching_Policy#");
13113 end if;
13114
13115 -- The use of Priority_Specific_Dispatching forces ceiling
13116 -- locking policy.
13117
13118 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
13119 Error_Msg_Sloc := Locking_Policy_Sloc;
13120 Error_Pragma
13121 ("Priority_Specific_Dispatching incompatible "
13122 & "with Locking_Policy#");
13123
13124 -- Set the Ceiling_Locking policy, but preserve System_Location
13125 -- since we like the error message with the run time name.
13126
13127 else
13128 Locking_Policy := 'C';
13129
13130 if Locking_Policy_Sloc /= System_Location then
13131 Locking_Policy_Sloc := Loc;
13132 end if;
13133 end if;
13134
13135 -- Add entry in the table
13136
13137 Specific_Dispatching.Append
13138 ((Dispatching_Policy => DP,
13139 First_Priority => UI_To_Int (Lower_Val),
13140 Last_Priority => UI_To_Int (Upper_Val),
13141 Pragma_Loc => Loc));
13142 end if;
13143 end Priority_Specific_Dispatching;
13144
13145 -------------
13146 -- Profile --
13147 -------------
13148
13149 -- pragma Profile (profile_IDENTIFIER);
13150
13151 -- profile_IDENTIFIER => Restricted | Ravenscar
13152
13153 when Pragma_Profile =>
13154 Ada_2005_Pragma;
13155 Check_Arg_Count (1);
13156 Check_Valid_Configuration_Pragma;
13157 Check_No_Identifiers;
13158
13159 declare
13160 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13161
13162 begin
13163 if Chars (Argx) = Name_Ravenscar then
13164 Set_Ravenscar_Profile (N);
13165
13166 elsif Chars (Argx) = Name_Restricted then
13167 Set_Profile_Restrictions
13168 (Restricted,
13169 N, Warn => Treat_Restrictions_As_Warnings);
13170
13171 elsif Chars (Argx) = Name_No_Implementation_Extensions then
13172 Set_Profile_Restrictions
13173 (No_Implementation_Extensions,
13174 N, Warn => Treat_Restrictions_As_Warnings);
13175
13176 else
13177 Error_Pragma_Arg ("& is not a valid profile", Argx);
13178 end if;
13179 end;
13180
13181 ----------------------
13182 -- Profile_Warnings --
13183 ----------------------
13184
13185 -- pragma Profile_Warnings (profile_IDENTIFIER);
13186
13187 -- profile_IDENTIFIER => Restricted | Ravenscar
13188
13189 when Pragma_Profile_Warnings =>
13190 GNAT_Pragma;
13191 Check_Arg_Count (1);
13192 Check_Valid_Configuration_Pragma;
13193 Check_No_Identifiers;
13194
13195 declare
13196 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13197
13198 begin
13199 if Chars (Argx) = Name_Ravenscar then
13200 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
13201
13202 elsif Chars (Argx) = Name_Restricted then
13203 Set_Profile_Restrictions (Restricted, N, Warn => True);
13204
13205 elsif Chars (Argx) = Name_No_Implementation_Extensions then
13206 Set_Profile_Restrictions
13207 (No_Implementation_Extensions, N, Warn => True);
13208
13209 else
13210 Error_Pragma_Arg ("& is not a valid profile", Argx);
13211 end if;
13212 end;
13213
13214 --------------------------
13215 -- Propagate_Exceptions --
13216 --------------------------
13217
13218 -- pragma Propagate_Exceptions;
13219
13220 -- Note: this pragma is obsolete and has no effect
13221
13222 when Pragma_Propagate_Exceptions =>
13223 GNAT_Pragma;
13224 Check_Arg_Count (0);
13225
13226 if In_Extended_Main_Source_Unit (N) then
13227 Propagate_Exceptions := True;
13228 end if;
13229
13230 ------------------
13231 -- Psect_Object --
13232 ------------------
13233
13234 -- pragma Psect_Object (
13235 -- [Internal =>] LOCAL_NAME,
13236 -- [, [External =>] EXTERNAL_SYMBOL]
13237 -- [, [Size =>] EXTERNAL_SYMBOL]);
13238
13239 when Pragma_Psect_Object | Pragma_Common_Object =>
13240 Psect_Object : declare
13241 Args : Args_List (1 .. 3);
13242 Names : constant Name_List (1 .. 3) := (
13243 Name_Internal,
13244 Name_External,
13245 Name_Size);
13246
13247 Internal : Node_Id renames Args (1);
13248 External : Node_Id renames Args (2);
13249 Size : Node_Id renames Args (3);
13250
13251 Def_Id : Entity_Id;
13252
13253 procedure Check_Too_Long (Arg : Node_Id);
13254 -- Posts message if the argument is an identifier with more
13255 -- than 31 characters, or a string literal with more than
13256 -- 31 characters, and we are operating under VMS
13257
13258 --------------------
13259 -- Check_Too_Long --
13260 --------------------
13261
13262 procedure Check_Too_Long (Arg : Node_Id) is
13263 X : constant Node_Id := Original_Node (Arg);
13264
13265 begin
13266 if not Nkind_In (X, N_String_Literal, N_Identifier) then
13267 Error_Pragma_Arg
13268 ("inappropriate argument for pragma %", Arg);
13269 end if;
13270
13271 if OpenVMS_On_Target then
13272 if (Nkind (X) = N_String_Literal
13273 and then String_Length (Strval (X)) > 31)
13274 or else
13275 (Nkind (X) = N_Identifier
13276 and then Length_Of_Name (Chars (X)) > 31)
13277 then
13278 Error_Pragma_Arg
13279 ("argument for pragma % is longer than 31 characters",
13280 Arg);
13281 end if;
13282 end if;
13283 end Check_Too_Long;
13284
13285 -- Start of processing for Common_Object/Psect_Object
13286
13287 begin
13288 GNAT_Pragma;
13289 Gather_Associations (Names, Args);
13290 Process_Extended_Import_Export_Internal_Arg (Internal);
13291
13292 Def_Id := Entity (Internal);
13293
13294 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
13295 Error_Pragma_Arg
13296 ("pragma% must designate an object", Internal);
13297 end if;
13298
13299 Check_Too_Long (Internal);
13300
13301 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
13302 Error_Pragma_Arg
13303 ("cannot use pragma% for imported/exported object",
13304 Internal);
13305 end if;
13306
13307 if Is_Concurrent_Type (Etype (Internal)) then
13308 Error_Pragma_Arg
13309 ("cannot specify pragma % for task/protected object",
13310 Internal);
13311 end if;
13312
13313 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
13314 or else
13315 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
13316 then
13317 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
13318 end if;
13319
13320 if Ekind (Def_Id) = E_Constant then
13321 Error_Pragma_Arg
13322 ("cannot specify pragma % for a constant", Internal);
13323 end if;
13324
13325 if Is_Record_Type (Etype (Internal)) then
13326 declare
13327 Ent : Entity_Id;
13328 Decl : Entity_Id;
13329
13330 begin
13331 Ent := First_Entity (Etype (Internal));
13332 while Present (Ent) loop
13333 Decl := Declaration_Node (Ent);
13334
13335 if Ekind (Ent) = E_Component
13336 and then Nkind (Decl) = N_Component_Declaration
13337 and then Present (Expression (Decl))
13338 and then Warn_On_Export_Import
13339 then
13340 Error_Msg_N
13341 ("?object for pragma % has defaults", Internal);
13342 exit;
13343
13344 else
13345 Next_Entity (Ent);
13346 end if;
13347 end loop;
13348 end;
13349 end if;
13350
13351 if Present (Size) then
13352 Check_Too_Long (Size);
13353 end if;
13354
13355 if Present (External) then
13356 Check_Arg_Is_External_Name (External);
13357 Check_Too_Long (External);
13358 end if;
13359
13360 -- If all error tests pass, link pragma on to the rep item chain
13361
13362 Record_Rep_Item (Def_Id, N);
13363 end Psect_Object;
13364
13365 ----------
13366 -- Pure --
13367 ----------
13368
13369 -- pragma Pure [(library_unit_NAME)];
13370
13371 when Pragma_Pure => Pure : declare
13372 Ent : Entity_Id;
13373
13374 begin
13375 Check_Ada_83_Warning;
13376 Check_Valid_Library_Unit_Pragma;
13377
13378 if Nkind (N) = N_Null_Statement then
13379 return;
13380 end if;
13381
13382 Ent := Find_Lib_Unit_Name;
13383 Set_Is_Pure (Ent);
13384 Set_Has_Pragma_Pure (Ent);
13385 Set_Suppress_Elaboration_Warnings (Ent);
13386 end Pure;
13387
13388 -------------
13389 -- Pure_05 --
13390 -------------
13391
13392 -- pragma Pure_05 [(library_unit_NAME)];
13393
13394 -- This pragma is useable only in GNAT_Mode, where it is used like
13395 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
13396 -- it is ignored). It may be used after a pragma Preelaborate, in
13397 -- which case it overrides the effect of the pragma Preelaborate.
13398 -- This is used to implement AI-362 which recategorizes some run-time
13399 -- packages in Ada 2005 mode.
13400
13401 when Pragma_Pure_05 => Pure_05 : declare
13402 Ent : Entity_Id;
13403
13404 begin
13405 GNAT_Pragma;
13406 Check_Valid_Library_Unit_Pragma;
13407
13408 if not GNAT_Mode then
13409 Error_Pragma ("pragma% only available in GNAT mode");
13410 end if;
13411
13412 if Nkind (N) = N_Null_Statement then
13413 return;
13414 end if;
13415
13416 -- This is one of the few cases where we need to test the value of
13417 -- Ada_Version_Explicit rather than Ada_Version (which is always
13418 -- set to Ada_2012 in a predefined unit), we need to know the
13419 -- explicit version set to know if this pragma is active.
13420
13421 if Ada_Version_Explicit >= Ada_2005 then
13422 Ent := Find_Lib_Unit_Name;
13423 Set_Is_Preelaborated (Ent, False);
13424 Set_Is_Pure (Ent);
13425 Set_Suppress_Elaboration_Warnings (Ent);
13426 end if;
13427 end Pure_05;
13428
13429 -------------
13430 -- Pure_12 --
13431 -------------
13432
13433 -- pragma Pure_12 [(library_unit_NAME)];
13434
13435 -- This pragma is useable only in GNAT_Mode, where it is used like
13436 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
13437 -- it is ignored). It may be used after a pragma Preelaborate, in
13438 -- which case it overrides the effect of the pragma Preelaborate.
13439 -- This is used to implement AI05-0212 which recategorizes some
13440 -- run-time packages in Ada 2012 mode.
13441
13442 when Pragma_Pure_12 => Pure_12 : declare
13443 Ent : Entity_Id;
13444
13445 begin
13446 GNAT_Pragma;
13447 Check_Valid_Library_Unit_Pragma;
13448
13449 if not GNAT_Mode then
13450 Error_Pragma ("pragma% only available in GNAT mode");
13451 end if;
13452
13453 if Nkind (N) = N_Null_Statement then
13454 return;
13455 end if;
13456
13457 -- This is one of the few cases where we need to test the value of
13458 -- Ada_Version_Explicit rather than Ada_Version (which is always
13459 -- set to Ada_2012 in a predefined unit), we need to know the
13460 -- explicit version set to know if this pragma is active.
13461
13462 if Ada_Version_Explicit >= Ada_2012 then
13463 Ent := Find_Lib_Unit_Name;
13464 Set_Is_Preelaborated (Ent, False);
13465 Set_Is_Pure (Ent);
13466 Set_Suppress_Elaboration_Warnings (Ent);
13467 end if;
13468 end Pure_12;
13469
13470 -------------------
13471 -- Pure_Function --
13472 -------------------
13473
13474 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
13475
13476 when Pragma_Pure_Function => Pure_Function : declare
13477 E_Id : Node_Id;
13478 E : Entity_Id;
13479 Def_Id : Entity_Id;
13480 Effective : Boolean := False;
13481
13482 begin
13483 GNAT_Pragma;
13484 Check_Arg_Count (1);
13485 Check_Optional_Identifier (Arg1, Name_Entity);
13486 Check_Arg_Is_Local_Name (Arg1);
13487 E_Id := Get_Pragma_Arg (Arg1);
13488
13489 if Error_Posted (E_Id) then
13490 return;
13491 end if;
13492
13493 -- Loop through homonyms (overloadings) of referenced entity
13494
13495 E := Entity (E_Id);
13496
13497 if Present (E) then
13498 loop
13499 Def_Id := Get_Base_Subprogram (E);
13500
13501 if not Ekind_In (Def_Id, E_Function,
13502 E_Generic_Function,
13503 E_Operator)
13504 then
13505 Error_Pragma_Arg
13506 ("pragma% requires a function name", Arg1);
13507 end if;
13508
13509 Set_Is_Pure (Def_Id);
13510
13511 if not Has_Pragma_Pure_Function (Def_Id) then
13512 Set_Has_Pragma_Pure_Function (Def_Id);
13513 Effective := True;
13514 end if;
13515
13516 exit when From_Aspect_Specification (N);
13517 E := Homonym (E);
13518 exit when No (E) or else Scope (E) /= Current_Scope;
13519 end loop;
13520
13521 if not Effective
13522 and then Warn_On_Redundant_Constructs
13523 then
13524 Error_Msg_NE
13525 ("pragma Pure_Function on& is redundant?",
13526 N, Entity (E_Id));
13527 end if;
13528 end if;
13529 end Pure_Function;
13530
13531 --------------------
13532 -- Queuing_Policy --
13533 --------------------
13534
13535 -- pragma Queuing_Policy (policy_IDENTIFIER);
13536
13537 when Pragma_Queuing_Policy => declare
13538 QP : Character;
13539
13540 begin
13541 Check_Ada_83_Warning;
13542 Check_Arg_Count (1);
13543 Check_No_Identifiers;
13544 Check_Arg_Is_Queuing_Policy (Arg1);
13545 Check_Valid_Configuration_Pragma;
13546 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13547 QP := Fold_Upper (Name_Buffer (1));
13548
13549 if Queuing_Policy /= ' '
13550 and then Queuing_Policy /= QP
13551 then
13552 Error_Msg_Sloc := Queuing_Policy_Sloc;
13553 Error_Pragma ("queuing policy incompatible with policy#");
13554
13555 -- Set new policy, but always preserve System_Location since we
13556 -- like the error message with the run time name.
13557
13558 else
13559 Queuing_Policy := QP;
13560
13561 if Queuing_Policy_Sloc /= System_Location then
13562 Queuing_Policy_Sloc := Loc;
13563 end if;
13564 end if;
13565 end;
13566
13567 -----------------------
13568 -- Relative_Deadline --
13569 -----------------------
13570
13571 -- pragma Relative_Deadline (time_span_EXPRESSION);
13572
13573 when Pragma_Relative_Deadline => Relative_Deadline : declare
13574 P : constant Node_Id := Parent (N);
13575 Arg : Node_Id;
13576
13577 begin
13578 Ada_2005_Pragma;
13579 Check_No_Identifiers;
13580 Check_Arg_Count (1);
13581
13582 Arg := Get_Pragma_Arg (Arg1);
13583
13584 -- The expression must be analyzed in the special manner described
13585 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
13586
13587 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
13588
13589 -- Subprogram case
13590
13591 if Nkind (P) = N_Subprogram_Body then
13592 Check_In_Main_Program;
13593
13594 -- Only Task and subprogram cases allowed
13595
13596 elsif Nkind (P) /= N_Task_Definition then
13597 Pragma_Misplaced;
13598 end if;
13599
13600 -- Check duplicate pragma before we set the corresponding flag
13601
13602 if Has_Relative_Deadline_Pragma (P) then
13603 Error_Pragma ("duplicate pragma% not allowed");
13604 end if;
13605
13606 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
13607 -- Relative_Deadline pragma node cannot be inserted in the Rep
13608 -- Item chain of Ent since it is rewritten by the expander as a
13609 -- procedure call statement that will break the chain.
13610
13611 Set_Has_Relative_Deadline_Pragma (P, True);
13612 end Relative_Deadline;
13613
13614 ------------------------
13615 -- Remote_Access_Type --
13616 ------------------------
13617
13618 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
13619
13620 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
13621 E : Entity_Id;
13622
13623 begin
13624 GNAT_Pragma;
13625 Check_Arg_Count (1);
13626 Check_Optional_Identifier (Arg1, Name_Entity);
13627 Check_Arg_Is_Local_Name (Arg1);
13628
13629 E := Entity (Get_Pragma_Arg (Arg1));
13630
13631 if Nkind (Parent (E)) = N_Formal_Type_Declaration
13632 and then Ekind (E) = E_General_Access_Type
13633 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
13634 and then Scope (Root_Type (Directly_Designated_Type (E)))
13635 = Scope (E)
13636 and then Is_Valid_Remote_Object_Type
13637 (Root_Type (Directly_Designated_Type (E)))
13638 then
13639 Set_Is_Remote_Types (E);
13640
13641 else
13642 Error_Pragma_Arg
13643 ("pragma% applies only to formal access to classwide types",
13644 Arg1);
13645 end if;
13646 end Remote_Access_Type;
13647
13648 ---------------------------
13649 -- Remote_Call_Interface --
13650 ---------------------------
13651
13652 -- pragma Remote_Call_Interface [(library_unit_NAME)];
13653
13654 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
13655 Cunit_Node : Node_Id;
13656 Cunit_Ent : Entity_Id;
13657 K : Node_Kind;
13658
13659 begin
13660 Check_Ada_83_Warning;
13661 Check_Valid_Library_Unit_Pragma;
13662
13663 if Nkind (N) = N_Null_Statement then
13664 return;
13665 end if;
13666
13667 Cunit_Node := Cunit (Current_Sem_Unit);
13668 K := Nkind (Unit (Cunit_Node));
13669 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13670
13671 if K = N_Package_Declaration
13672 or else K = N_Generic_Package_Declaration
13673 or else K = N_Subprogram_Declaration
13674 or else K = N_Generic_Subprogram_Declaration
13675 or else (K = N_Subprogram_Body
13676 and then Acts_As_Spec (Unit (Cunit_Node)))
13677 then
13678 null;
13679 else
13680 Error_Pragma (
13681 "pragma% must apply to package or subprogram declaration");
13682 end if;
13683
13684 Set_Is_Remote_Call_Interface (Cunit_Ent);
13685 end Remote_Call_Interface;
13686
13687 ------------------
13688 -- Remote_Types --
13689 ------------------
13690
13691 -- pragma Remote_Types [(library_unit_NAME)];
13692
13693 when Pragma_Remote_Types => Remote_Types : declare
13694 Cunit_Node : Node_Id;
13695 Cunit_Ent : Entity_Id;
13696
13697 begin
13698 Check_Ada_83_Warning;
13699 Check_Valid_Library_Unit_Pragma;
13700
13701 if Nkind (N) = N_Null_Statement then
13702 return;
13703 end if;
13704
13705 Cunit_Node := Cunit (Current_Sem_Unit);
13706 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13707
13708 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
13709 N_Generic_Package_Declaration)
13710 then
13711 Error_Pragma
13712 ("pragma% can only apply to a package declaration");
13713 end if;
13714
13715 Set_Is_Remote_Types (Cunit_Ent);
13716 end Remote_Types;
13717
13718 ---------------
13719 -- Ravenscar --
13720 ---------------
13721
13722 -- pragma Ravenscar;
13723
13724 when Pragma_Ravenscar =>
13725 GNAT_Pragma;
13726 Check_Arg_Count (0);
13727 Check_Valid_Configuration_Pragma;
13728 Set_Ravenscar_Profile (N);
13729
13730 if Warn_On_Obsolescent_Feature then
13731 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
13732 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
13733 end if;
13734
13735 -------------------------
13736 -- Restricted_Run_Time --
13737 -------------------------
13738
13739 -- pragma Restricted_Run_Time;
13740
13741 when Pragma_Restricted_Run_Time =>
13742 GNAT_Pragma;
13743 Check_Arg_Count (0);
13744 Check_Valid_Configuration_Pragma;
13745 Set_Profile_Restrictions
13746 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
13747
13748 if Warn_On_Obsolescent_Feature then
13749 Error_Msg_N
13750 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
13751 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
13752 end if;
13753
13754 ------------------
13755 -- Restrictions --
13756 ------------------
13757
13758 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
13759
13760 -- RESTRICTION ::=
13761 -- restriction_IDENTIFIER
13762 -- | restriction_parameter_IDENTIFIER => EXPRESSION
13763
13764 when Pragma_Restrictions =>
13765 Process_Restrictions_Or_Restriction_Warnings
13766 (Warn => Treat_Restrictions_As_Warnings);
13767
13768 --------------------------
13769 -- Restriction_Warnings --
13770 --------------------------
13771
13772 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
13773
13774 -- RESTRICTION ::=
13775 -- restriction_IDENTIFIER
13776 -- | restriction_parameter_IDENTIFIER => EXPRESSION
13777
13778 when Pragma_Restriction_Warnings =>
13779 GNAT_Pragma;
13780 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
13781
13782 ----------------
13783 -- Reviewable --
13784 ----------------
13785
13786 -- pragma Reviewable;
13787
13788 when Pragma_Reviewable =>
13789 Check_Ada_83_Warning;
13790 Check_Arg_Count (0);
13791
13792 -- Call dummy debugging function rv. This is done to assist front
13793 -- end debugging. By placing a Reviewable pragma in the source
13794 -- program, a breakpoint on rv catches this place in the source,
13795 -- allowing convenient stepping to the point of interest.
13796
13797 rv;
13798
13799 --------------------------
13800 -- Short_Circuit_And_Or --
13801 --------------------------
13802
13803 when Pragma_Short_Circuit_And_Or =>
13804 GNAT_Pragma;
13805 Check_Arg_Count (0);
13806 Check_Valid_Configuration_Pragma;
13807 Short_Circuit_And_Or := True;
13808
13809 -------------------
13810 -- Share_Generic --
13811 -------------------
13812
13813 -- pragma Share_Generic (NAME {, NAME});
13814
13815 when Pragma_Share_Generic =>
13816 GNAT_Pragma;
13817 Process_Generic_List;
13818
13819 ------------
13820 -- Shared --
13821 ------------
13822
13823 -- pragma Shared (LOCAL_NAME);
13824
13825 when Pragma_Shared =>
13826 GNAT_Pragma;
13827 Process_Atomic_Shared_Volatile;
13828
13829 --------------------
13830 -- Shared_Passive --
13831 --------------------
13832
13833 -- pragma Shared_Passive [(library_unit_NAME)];
13834
13835 -- Set the flag Is_Shared_Passive of program unit name entity
13836
13837 when Pragma_Shared_Passive => Shared_Passive : declare
13838 Cunit_Node : Node_Id;
13839 Cunit_Ent : Entity_Id;
13840
13841 begin
13842 Check_Ada_83_Warning;
13843 Check_Valid_Library_Unit_Pragma;
13844
13845 if Nkind (N) = N_Null_Statement then
13846 return;
13847 end if;
13848
13849 Cunit_Node := Cunit (Current_Sem_Unit);
13850 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13851
13852 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
13853 N_Generic_Package_Declaration)
13854 then
13855 Error_Pragma
13856 ("pragma% can only apply to a package declaration");
13857 end if;
13858
13859 Set_Is_Shared_Passive (Cunit_Ent);
13860 end Shared_Passive;
13861
13862 -----------------------
13863 -- Short_Descriptors --
13864 -----------------------
13865
13866 -- pragma Short_Descriptors;
13867
13868 when Pragma_Short_Descriptors =>
13869 GNAT_Pragma;
13870 Check_Arg_Count (0);
13871 Check_Valid_Configuration_Pragma;
13872 Short_Descriptors := True;
13873
13874 ------------------------------
13875 -- Simple_Storage_Pool_Type --
13876 ------------------------------
13877
13878 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
13879
13880 when Pragma_Simple_Storage_Pool_Type =>
13881 Simple_Storage_Pool_Type : declare
13882 Type_Id : Node_Id;
13883 Typ : Entity_Id;
13884
13885 begin
13886 GNAT_Pragma;
13887 Check_Arg_Count (1);
13888 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13889
13890 Type_Id := Get_Pragma_Arg (Arg1);
13891 Find_Type (Type_Id);
13892 Typ := Entity (Type_Id);
13893
13894 if Typ = Any_Type then
13895 return;
13896 end if;
13897
13898 -- We require the pragma to apply to a type declared in a package
13899 -- declaration, but not (immediately) within a package body.
13900
13901 if Ekind (Current_Scope) /= E_Package
13902 or else In_Package_Body (Current_Scope)
13903 then
13904 Error_Pragma
13905 ("pragma% can only apply to type declared immediately " &
13906 "within a package declaration");
13907 end if;
13908
13909 -- A simple storage pool type must be an immutably limited record
13910 -- or private type. If the pragma is given for a private type,
13911 -- the full type is similarly restricted (which is checked later
13912 -- in Freeze_Entity).
13913
13914 if Is_Record_Type (Typ)
13915 and then not Is_Immutably_Limited_Type (Typ)
13916 then
13917 Error_Pragma
13918 ("pragma% can only apply to explicitly limited record type");
13919
13920 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
13921 Error_Pragma
13922 ("pragma% can only apply to a private type that is limited");
13923
13924 elsif not Is_Record_Type (Typ)
13925 and then not Is_Private_Type (Typ)
13926 then
13927 Error_Pragma
13928 ("pragma% can only apply to limited record or private type");
13929 end if;
13930
13931 Record_Rep_Item (Typ, N);
13932 end Simple_Storage_Pool_Type;
13933
13934 ----------------------
13935 -- Source_File_Name --
13936 ----------------------
13937
13938 -- There are five forms for this pragma:
13939
13940 -- pragma Source_File_Name (
13941 -- [UNIT_NAME =>] unit_NAME,
13942 -- BODY_FILE_NAME => STRING_LITERAL
13943 -- [, [INDEX =>] INTEGER_LITERAL]);
13944
13945 -- pragma Source_File_Name (
13946 -- [UNIT_NAME =>] unit_NAME,
13947 -- SPEC_FILE_NAME => STRING_LITERAL
13948 -- [, [INDEX =>] INTEGER_LITERAL]);
13949
13950 -- pragma Source_File_Name (
13951 -- BODY_FILE_NAME => STRING_LITERAL
13952 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13953 -- [, CASING => CASING_SPEC]);
13954
13955 -- pragma Source_File_Name (
13956 -- SPEC_FILE_NAME => STRING_LITERAL
13957 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13958 -- [, CASING => CASING_SPEC]);
13959
13960 -- pragma Source_File_Name (
13961 -- SUBUNIT_FILE_NAME => STRING_LITERAL
13962 -- [, DOT_REPLACEMENT => STRING_LITERAL]
13963 -- [, CASING => CASING_SPEC]);
13964
13965 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
13966
13967 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
13968 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
13969 -- only be used when no project file is used, while SFNP can only be
13970 -- used when a project file is used.
13971
13972 -- No processing here. Processing was completed during parsing, since
13973 -- we need to have file names set as early as possible. Units are
13974 -- loaded well before semantic processing starts.
13975
13976 -- The only processing we defer to this point is the check for
13977 -- correct placement.
13978
13979 when Pragma_Source_File_Name =>
13980 GNAT_Pragma;
13981 Check_Valid_Configuration_Pragma;
13982
13983 ------------------------------
13984 -- Source_File_Name_Project --
13985 ------------------------------
13986
13987 -- See Source_File_Name for syntax
13988
13989 -- No processing here. Processing was completed during parsing, since
13990 -- we need to have file names set as early as possible. Units are
13991 -- loaded well before semantic processing starts.
13992
13993 -- The only processing we defer to this point is the check for
13994 -- correct placement.
13995
13996 when Pragma_Source_File_Name_Project =>
13997 GNAT_Pragma;
13998 Check_Valid_Configuration_Pragma;
13999
14000 -- Check that a pragma Source_File_Name_Project is used only in a
14001 -- configuration pragmas file.
14002
14003 -- Pragmas Source_File_Name_Project should only be generated by
14004 -- the Project Manager in configuration pragmas files.
14005
14006 -- This is really an ugly test. It seems to depend on some
14007 -- accidental and undocumented property. At the very least it
14008 -- needs to be documented, but it would be better to have a
14009 -- clean way of testing if we are in a configuration file???
14010
14011 if Present (Parent (N)) then
14012 Error_Pragma
14013 ("pragma% can only appear in a configuration pragmas file");
14014 end if;
14015
14016 ----------------------
14017 -- Source_Reference --
14018 ----------------------
14019
14020 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
14021
14022 -- Nothing to do, all processing completed in Par.Prag, since we need
14023 -- the information for possible parser messages that are output.
14024
14025 when Pragma_Source_Reference =>
14026 GNAT_Pragma;
14027
14028 --------------------------------
14029 -- Static_Elaboration_Desired --
14030 --------------------------------
14031
14032 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
14033
14034 when Pragma_Static_Elaboration_Desired =>
14035 GNAT_Pragma;
14036 Check_At_Most_N_Arguments (1);
14037
14038 if Is_Compilation_Unit (Current_Scope)
14039 and then Ekind (Current_Scope) = E_Package
14040 then
14041 Set_Static_Elaboration_Desired (Current_Scope, True);
14042 else
14043 Error_Pragma ("pragma% must apply to a library-level package");
14044 end if;
14045
14046 ------------------
14047 -- Storage_Size --
14048 ------------------
14049
14050 -- pragma Storage_Size (EXPRESSION);
14051
14052 when Pragma_Storage_Size => Storage_Size : declare
14053 P : constant Node_Id := Parent (N);
14054 Arg : Node_Id;
14055
14056 begin
14057 Check_No_Identifiers;
14058 Check_Arg_Count (1);
14059
14060 -- The expression must be analyzed in the special manner described
14061 -- in "Handling of Default Expressions" in sem.ads.
14062
14063 Arg := Get_Pragma_Arg (Arg1);
14064 Preanalyze_Spec_Expression (Arg, Any_Integer);
14065
14066 if not Is_Static_Expression (Arg) then
14067 Check_Restriction (Static_Storage_Size, Arg);
14068 end if;
14069
14070 if Nkind (P) /= N_Task_Definition then
14071 Pragma_Misplaced;
14072 return;
14073
14074 else
14075 if Has_Storage_Size_Pragma (P) then
14076 Error_Pragma ("duplicate pragma% not allowed");
14077 else
14078 Set_Has_Storage_Size_Pragma (P, True);
14079 end if;
14080
14081 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
14082 end if;
14083 end Storage_Size;
14084
14085 ------------------
14086 -- Storage_Unit --
14087 ------------------
14088
14089 -- pragma Storage_Unit (NUMERIC_LITERAL);
14090
14091 -- Only permitted argument is System'Storage_Unit value
14092
14093 when Pragma_Storage_Unit =>
14094 Check_No_Identifiers;
14095 Check_Arg_Count (1);
14096 Check_Arg_Is_Integer_Literal (Arg1);
14097
14098 if Intval (Get_Pragma_Arg (Arg1)) /=
14099 UI_From_Int (Ttypes.System_Storage_Unit)
14100 then
14101 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
14102 Error_Pragma_Arg
14103 ("the only allowed argument for pragma% is ^", Arg1);
14104 end if;
14105
14106 --------------------
14107 -- Stream_Convert --
14108 --------------------
14109
14110 -- pragma Stream_Convert (
14111 -- [Entity =>] type_LOCAL_NAME,
14112 -- [Read =>] function_NAME,
14113 -- [Write =>] function NAME);
14114
14115 when Pragma_Stream_Convert => Stream_Convert : declare
14116
14117 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
14118 -- Check that the given argument is the name of a local function
14119 -- of one argument that is not overloaded earlier in the current
14120 -- local scope. A check is also made that the argument is a
14121 -- function with one parameter.
14122
14123 --------------------------------------
14124 -- Check_OK_Stream_Convert_Function --
14125 --------------------------------------
14126
14127 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
14128 Ent : Entity_Id;
14129
14130 begin
14131 Check_Arg_Is_Local_Name (Arg);
14132 Ent := Entity (Get_Pragma_Arg (Arg));
14133
14134 if Has_Homonym (Ent) then
14135 Error_Pragma_Arg
14136 ("argument for pragma% may not be overloaded", Arg);
14137 end if;
14138
14139 if Ekind (Ent) /= E_Function
14140 or else No (First_Formal (Ent))
14141 or else Present (Next_Formal (First_Formal (Ent)))
14142 then
14143 Error_Pragma_Arg
14144 ("argument for pragma% must be" &
14145 " function of one argument", Arg);
14146 end if;
14147 end Check_OK_Stream_Convert_Function;
14148
14149 -- Start of processing for Stream_Convert
14150
14151 begin
14152 GNAT_Pragma;
14153 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
14154 Check_Arg_Count (3);
14155 Check_Optional_Identifier (Arg1, Name_Entity);
14156 Check_Optional_Identifier (Arg2, Name_Read);
14157 Check_Optional_Identifier (Arg3, Name_Write);
14158 Check_Arg_Is_Local_Name (Arg1);
14159 Check_OK_Stream_Convert_Function (Arg2);
14160 Check_OK_Stream_Convert_Function (Arg3);
14161
14162 declare
14163 Typ : constant Entity_Id :=
14164 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
14165 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
14166 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
14167
14168 begin
14169 Check_First_Subtype (Arg1);
14170
14171 -- Check for too early or too late. Note that we don't enforce
14172 -- the rule about primitive operations in this case, since, as
14173 -- is the case for explicit stream attributes themselves, these
14174 -- restrictions are not appropriate. Note that the chaining of
14175 -- the pragma by Rep_Item_Too_Late is actually the critical
14176 -- processing done for this pragma.
14177
14178 if Rep_Item_Too_Early (Typ, N)
14179 or else
14180 Rep_Item_Too_Late (Typ, N, FOnly => True)
14181 then
14182 return;
14183 end if;
14184
14185 -- Return if previous error
14186
14187 if Etype (Typ) = Any_Type
14188 or else
14189 Etype (Read) = Any_Type
14190 or else
14191 Etype (Write) = Any_Type
14192 then
14193 return;
14194 end if;
14195
14196 -- Error checks
14197
14198 if Underlying_Type (Etype (Read)) /= Typ then
14199 Error_Pragma_Arg
14200 ("incorrect return type for function&", Arg2);
14201 end if;
14202
14203 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
14204 Error_Pragma_Arg
14205 ("incorrect parameter type for function&", Arg3);
14206 end if;
14207
14208 if Underlying_Type (Etype (First_Formal (Read))) /=
14209 Underlying_Type (Etype (Write))
14210 then
14211 Error_Pragma_Arg
14212 ("result type of & does not match Read parameter type",
14213 Arg3);
14214 end if;
14215 end;
14216 end Stream_Convert;
14217
14218 ------------------
14219 -- Style_Checks --
14220 ------------------
14221
14222 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14223
14224 -- This is processed by the parser since some of the style checks
14225 -- take place during source scanning and parsing. This means that
14226 -- we don't need to issue error messages here.
14227
14228 when Pragma_Style_Checks => Style_Checks : declare
14229 A : constant Node_Id := Get_Pragma_Arg (Arg1);
14230 S : String_Id;
14231 C : Char_Code;
14232
14233 begin
14234 GNAT_Pragma;
14235 Check_No_Identifiers;
14236
14237 -- Two argument form
14238
14239 if Arg_Count = 2 then
14240 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14241
14242 declare
14243 E_Id : Node_Id;
14244 E : Entity_Id;
14245
14246 begin
14247 E_Id := Get_Pragma_Arg (Arg2);
14248 Analyze (E_Id);
14249
14250 if not Is_Entity_Name (E_Id) then
14251 Error_Pragma_Arg
14252 ("second argument of pragma% must be entity name",
14253 Arg2);
14254 end if;
14255
14256 E := Entity (E_Id);
14257
14258 if E = Any_Id then
14259 return;
14260 else
14261 loop
14262 Set_Suppress_Style_Checks (E,
14263 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
14264 exit when No (Homonym (E));
14265 E := Homonym (E);
14266 end loop;
14267 end if;
14268 end;
14269
14270 -- One argument form
14271
14272 else
14273 Check_Arg_Count (1);
14274
14275 if Nkind (A) = N_String_Literal then
14276 S := Strval (A);
14277
14278 declare
14279 Slen : constant Natural := Natural (String_Length (S));
14280 Options : String (1 .. Slen);
14281 J : Natural;
14282
14283 begin
14284 J := 1;
14285 loop
14286 C := Get_String_Char (S, Int (J));
14287 exit when not In_Character_Range (C);
14288 Options (J) := Get_Character (C);
14289
14290 -- If at end of string, set options. As per discussion
14291 -- above, no need to check for errors, since we issued
14292 -- them in the parser.
14293
14294 if J = Slen then
14295 Set_Style_Check_Options (Options);
14296 exit;
14297 end if;
14298
14299 J := J + 1;
14300 end loop;
14301 end;
14302
14303 elsif Nkind (A) = N_Identifier then
14304 if Chars (A) = Name_All_Checks then
14305 if GNAT_Mode then
14306 Set_GNAT_Style_Check_Options;
14307 else
14308 Set_Default_Style_Check_Options;
14309 end if;
14310
14311 elsif Chars (A) = Name_On then
14312 Style_Check := True;
14313
14314 elsif Chars (A) = Name_Off then
14315 Style_Check := False;
14316 end if;
14317 end if;
14318 end if;
14319 end Style_Checks;
14320
14321 --------------
14322 -- Subtitle --
14323 --------------
14324
14325 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
14326
14327 when Pragma_Subtitle =>
14328 GNAT_Pragma;
14329 Check_Arg_Count (1);
14330 Check_Optional_Identifier (Arg1, Name_Subtitle);
14331 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
14332 Store_Note (N);
14333
14334 --------------
14335 -- Suppress --
14336 --------------
14337
14338 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
14339
14340 when Pragma_Suppress =>
14341 Process_Suppress_Unsuppress (True);
14342
14343 ------------------
14344 -- Suppress_All --
14345 ------------------
14346
14347 -- pragma Suppress_All;
14348
14349 -- The only check made here is that the pragma has no arguments.
14350 -- There are no placement rules, and the processing required (setting
14351 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
14352 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
14353 -- then creates and inserts a pragma Suppress (All_Checks).
14354
14355 when Pragma_Suppress_All =>
14356 GNAT_Pragma;
14357 Check_Arg_Count (0);
14358
14359 -------------------------
14360 -- Suppress_Debug_Info --
14361 -------------------------
14362
14363 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
14364
14365 when Pragma_Suppress_Debug_Info =>
14366 GNAT_Pragma;
14367 Check_Arg_Count (1);
14368 Check_Optional_Identifier (Arg1, Name_Entity);
14369 Check_Arg_Is_Local_Name (Arg1);
14370 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
14371
14372 ----------------------------------
14373 -- Suppress_Exception_Locations --
14374 ----------------------------------
14375
14376 -- pragma Suppress_Exception_Locations;
14377
14378 when Pragma_Suppress_Exception_Locations =>
14379 GNAT_Pragma;
14380 Check_Arg_Count (0);
14381 Check_Valid_Configuration_Pragma;
14382 Exception_Locations_Suppressed := True;
14383
14384 -----------------------------
14385 -- Suppress_Initialization --
14386 -----------------------------
14387
14388 -- pragma Suppress_Initialization ([Entity =>] type_Name);
14389
14390 when Pragma_Suppress_Initialization => Suppress_Init : declare
14391 E_Id : Node_Id;
14392 E : Entity_Id;
14393
14394 begin
14395 GNAT_Pragma;
14396 Check_Arg_Count (1);
14397 Check_Optional_Identifier (Arg1, Name_Entity);
14398 Check_Arg_Is_Local_Name (Arg1);
14399
14400 E_Id := Get_Pragma_Arg (Arg1);
14401
14402 if Etype (E_Id) = Any_Type then
14403 return;
14404 end if;
14405
14406 E := Entity (E_Id);
14407
14408 if not Is_Type (E) then
14409 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
14410 end if;
14411
14412 if Rep_Item_Too_Early (E, N)
14413 or else
14414 Rep_Item_Too_Late (E, N, FOnly => True)
14415 then
14416 return;
14417 end if;
14418
14419 -- For incomplete/private type, set flag on full view
14420
14421 if Is_Incomplete_Or_Private_Type (E) then
14422 if No (Full_View (Base_Type (E))) then
14423 Error_Pragma_Arg
14424 ("argument of pragma% cannot be an incomplete type", Arg1);
14425 else
14426 Set_Suppress_Initialization (Full_View (Base_Type (E)));
14427 end if;
14428
14429 -- For first subtype, set flag on base type
14430
14431 elsif Is_First_Subtype (E) then
14432 Set_Suppress_Initialization (Base_Type (E));
14433
14434 -- For other than first subtype, set flag on subtype itself
14435
14436 else
14437 Set_Suppress_Initialization (E);
14438 end if;
14439 end Suppress_Init;
14440
14441 -----------------
14442 -- System_Name --
14443 -----------------
14444
14445 -- pragma System_Name (DIRECT_NAME);
14446
14447 -- Syntax check: one argument, which must be the identifier GNAT or
14448 -- the identifier GCC, no other identifiers are acceptable.
14449
14450 when Pragma_System_Name =>
14451 GNAT_Pragma;
14452 Check_No_Identifiers;
14453 Check_Arg_Count (1);
14454 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
14455
14456 -----------------------------
14457 -- Task_Dispatching_Policy --
14458 -----------------------------
14459
14460 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
14461
14462 when Pragma_Task_Dispatching_Policy => declare
14463 DP : Character;
14464
14465 begin
14466 Check_Ada_83_Warning;
14467 Check_Arg_Count (1);
14468 Check_No_Identifiers;
14469 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
14470 Check_Valid_Configuration_Pragma;
14471 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
14472 DP := Fold_Upper (Name_Buffer (1));
14473
14474 if Task_Dispatching_Policy /= ' '
14475 and then Task_Dispatching_Policy /= DP
14476 then
14477 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
14478 Error_Pragma
14479 ("task dispatching policy incompatible with policy#");
14480
14481 -- Set new policy, but always preserve System_Location since we
14482 -- like the error message with the run time name.
14483
14484 else
14485 Task_Dispatching_Policy := DP;
14486
14487 if Task_Dispatching_Policy_Sloc /= System_Location then
14488 Task_Dispatching_Policy_Sloc := Loc;
14489 end if;
14490 end if;
14491 end;
14492
14493 ---------------
14494 -- Task_Info --
14495 ---------------
14496
14497 -- pragma Task_Info (EXPRESSION);
14498
14499 when Pragma_Task_Info => Task_Info : declare
14500 P : constant Node_Id := Parent (N);
14501 Ent : Entity_Id;
14502
14503 begin
14504 GNAT_Pragma;
14505
14506 if Nkind (P) /= N_Task_Definition then
14507 Error_Pragma ("pragma% must appear in task definition");
14508 end if;
14509
14510 Check_No_Identifiers;
14511 Check_Arg_Count (1);
14512
14513 Analyze_And_Resolve
14514 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
14515
14516 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
14517 return;
14518 end if;
14519
14520 Ent := Defining_Identifier (Parent (P));
14521
14522 -- Check duplicate pragma before we chain the pragma in the Rep
14523 -- Item chain of Ent.
14524
14525 if Has_Rep_Pragma
14526 (Ent, Name_Task_Info, Check_Parents => False)
14527 then
14528 Error_Pragma ("duplicate pragma% not allowed");
14529 end if;
14530
14531 Record_Rep_Item (Ent, N);
14532 end Task_Info;
14533
14534 ---------------
14535 -- Task_Name --
14536 ---------------
14537
14538 -- pragma Task_Name (string_EXPRESSION);
14539
14540 when Pragma_Task_Name => Task_Name : declare
14541 P : constant Node_Id := Parent (N);
14542 Arg : Node_Id;
14543 Ent : Entity_Id;
14544
14545 begin
14546 Check_No_Identifiers;
14547 Check_Arg_Count (1);
14548
14549 Arg := Get_Pragma_Arg (Arg1);
14550
14551 -- The expression is used in the call to Create_Task, and must be
14552 -- expanded there, not in the context of the current spec. It must
14553 -- however be analyzed to capture global references, in case it
14554 -- appears in a generic context.
14555
14556 Preanalyze_And_Resolve (Arg, Standard_String);
14557
14558 if Nkind (P) /= N_Task_Definition then
14559 Pragma_Misplaced;
14560 end if;
14561
14562 Ent := Defining_Identifier (Parent (P));
14563
14564 -- Check duplicate pragma before we chain the pragma in the Rep
14565 -- Item chain of Ent.
14566
14567 if Has_Rep_Pragma
14568 (Ent, Name_Task_Name, Check_Parents => False)
14569 then
14570 Error_Pragma ("duplicate pragma% not allowed");
14571 end if;
14572
14573 Record_Rep_Item (Ent, N);
14574 end Task_Name;
14575
14576 ------------------
14577 -- Task_Storage --
14578 ------------------
14579
14580 -- pragma Task_Storage (
14581 -- [Task_Type =>] LOCAL_NAME,
14582 -- [Top_Guard =>] static_integer_EXPRESSION);
14583
14584 when Pragma_Task_Storage => Task_Storage : declare
14585 Args : Args_List (1 .. 2);
14586 Names : constant Name_List (1 .. 2) := (
14587 Name_Task_Type,
14588 Name_Top_Guard);
14589
14590 Task_Type : Node_Id renames Args (1);
14591 Top_Guard : Node_Id renames Args (2);
14592
14593 Ent : Entity_Id;
14594
14595 begin
14596 GNAT_Pragma;
14597 Gather_Associations (Names, Args);
14598
14599 if No (Task_Type) then
14600 Error_Pragma
14601 ("missing task_type argument for pragma%");
14602 end if;
14603
14604 Check_Arg_Is_Local_Name (Task_Type);
14605
14606 Ent := Entity (Task_Type);
14607
14608 if not Is_Task_Type (Ent) then
14609 Error_Pragma_Arg
14610 ("argument for pragma% must be task type", Task_Type);
14611 end if;
14612
14613 if No (Top_Guard) then
14614 Error_Pragma_Arg
14615 ("pragma% takes two arguments", Task_Type);
14616 else
14617 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
14618 end if;
14619
14620 Check_First_Subtype (Task_Type);
14621
14622 if Rep_Item_Too_Late (Ent, N) then
14623 raise Pragma_Exit;
14624 end if;
14625 end Task_Storage;
14626
14627 ---------------
14628 -- Test_Case --
14629 ---------------
14630
14631 -- pragma Test_Case
14632 -- ([Name =>] Static_String_EXPRESSION
14633 -- ,[Mode =>] MODE_TYPE
14634 -- [, Requires => Boolean_EXPRESSION]
14635 -- [, Ensures => Boolean_EXPRESSION]);
14636
14637 -- MODE_TYPE ::= Nominal | Robustness
14638
14639 when Pragma_Test_Case =>
14640 Check_Contract_Or_Test_Case;
14641
14642 --------------------------
14643 -- Thread_Local_Storage --
14644 --------------------------
14645
14646 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
14647
14648 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
14649 Id : Node_Id;
14650 E : Entity_Id;
14651
14652 begin
14653 GNAT_Pragma;
14654 Check_Arg_Count (1);
14655 Check_Optional_Identifier (Arg1, Name_Entity);
14656 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14657
14658 Id := Get_Pragma_Arg (Arg1);
14659 Analyze (Id);
14660
14661 if not Is_Entity_Name (Id)
14662 or else Ekind (Entity (Id)) /= E_Variable
14663 then
14664 Error_Pragma_Arg ("local variable name required", Arg1);
14665 end if;
14666
14667 E := Entity (Id);
14668
14669 if Rep_Item_Too_Early (E, N)
14670 or else Rep_Item_Too_Late (E, N)
14671 then
14672 raise Pragma_Exit;
14673 end if;
14674
14675 Set_Has_Pragma_Thread_Local_Storage (E);
14676 Set_Has_Gigi_Rep_Item (E);
14677 end Thread_Local_Storage;
14678
14679 ----------------
14680 -- Time_Slice --
14681 ----------------
14682
14683 -- pragma Time_Slice (static_duration_EXPRESSION);
14684
14685 when Pragma_Time_Slice => Time_Slice : declare
14686 Val : Ureal;
14687 Nod : Node_Id;
14688
14689 begin
14690 GNAT_Pragma;
14691 Check_Arg_Count (1);
14692 Check_No_Identifiers;
14693 Check_In_Main_Program;
14694 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
14695
14696 if not Error_Posted (Arg1) then
14697 Nod := Next (N);
14698 while Present (Nod) loop
14699 if Nkind (Nod) = N_Pragma
14700 and then Pragma_Name (Nod) = Name_Time_Slice
14701 then
14702 Error_Msg_Name_1 := Pname;
14703 Error_Msg_N ("duplicate pragma% not permitted", Nod);
14704 end if;
14705
14706 Next (Nod);
14707 end loop;
14708 end if;
14709
14710 -- Process only if in main unit
14711
14712 if Get_Source_Unit (Loc) = Main_Unit then
14713 Opt.Time_Slice_Set := True;
14714 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
14715
14716 if Val <= Ureal_0 then
14717 Opt.Time_Slice_Value := 0;
14718
14719 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
14720 Opt.Time_Slice_Value := 1_000_000_000;
14721
14722 else
14723 Opt.Time_Slice_Value :=
14724 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
14725 end if;
14726 end if;
14727 end Time_Slice;
14728
14729 -----------
14730 -- Title --
14731 -----------
14732
14733 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
14734
14735 -- TITLING_OPTION ::=
14736 -- [Title =>] STRING_LITERAL
14737 -- | [Subtitle =>] STRING_LITERAL
14738
14739 when Pragma_Title => Title : declare
14740 Args : Args_List (1 .. 2);
14741 Names : constant Name_List (1 .. 2) := (
14742 Name_Title,
14743 Name_Subtitle);
14744
14745 begin
14746 GNAT_Pragma;
14747 Gather_Associations (Names, Args);
14748 Store_Note (N);
14749
14750 for J in 1 .. 2 loop
14751 if Present (Args (J)) then
14752 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
14753 end if;
14754 end loop;
14755 end Title;
14756
14757 ---------------------
14758 -- Unchecked_Union --
14759 ---------------------
14760
14761 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
14762
14763 when Pragma_Unchecked_Union => Unchecked_Union : declare
14764 Assoc : constant Node_Id := Arg1;
14765 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
14766 Typ : Entity_Id;
14767 Tdef : Node_Id;
14768 Clist : Node_Id;
14769 Vpart : Node_Id;
14770 Comp : Node_Id;
14771 Variant : Node_Id;
14772
14773 begin
14774 Ada_2005_Pragma;
14775 Check_No_Identifiers;
14776 Check_Arg_Count (1);
14777 Check_Arg_Is_Local_Name (Arg1);
14778
14779 Find_Type (Type_Id);
14780
14781 Typ := Entity (Type_Id);
14782
14783 if Typ = Any_Type
14784 or else Rep_Item_Too_Early (Typ, N)
14785 then
14786 return;
14787 else
14788 Typ := Underlying_Type (Typ);
14789 end if;
14790
14791 if Rep_Item_Too_Late (Typ, N) then
14792 return;
14793 end if;
14794
14795 Check_First_Subtype (Arg1);
14796
14797 -- Note remaining cases are references to a type in the current
14798 -- declarative part. If we find an error, we post the error on
14799 -- the relevant type declaration at an appropriate point.
14800
14801 if not Is_Record_Type (Typ) then
14802 Error_Msg_N ("unchecked union must be record type", Typ);
14803 return;
14804
14805 elsif Is_Tagged_Type (Typ) then
14806 Error_Msg_N ("unchecked union must not be tagged", Typ);
14807 return;
14808
14809 elsif not Has_Discriminants (Typ) then
14810 Error_Msg_N
14811 ("unchecked union must have one discriminant", Typ);
14812 return;
14813
14814 -- Note: in previous versions of GNAT we used to check for limited
14815 -- types and give an error, but in fact the standard does allow
14816 -- Unchecked_Union on limited types, so this check was removed.
14817
14818 -- Similarly, GNAT used to require that all discriminants have
14819 -- default values, but this is not mandated by the RM.
14820
14821 -- Proceed with basic error checks completed
14822
14823 else
14824 Tdef := Type_Definition (Declaration_Node (Typ));
14825 Clist := Component_List (Tdef);
14826
14827 -- Check presence of component list and variant part
14828
14829 if No (Clist) or else No (Variant_Part (Clist)) then
14830 Error_Msg_N
14831 ("unchecked union must have variant part", Tdef);
14832 return;
14833 end if;
14834
14835 -- Check components
14836
14837 Comp := First (Component_Items (Clist));
14838 while Present (Comp) loop
14839 Check_Component (Comp, Typ);
14840 Next (Comp);
14841 end loop;
14842
14843 -- Check variant part
14844
14845 Vpart := Variant_Part (Clist);
14846
14847 Variant := First (Variants (Vpart));
14848 while Present (Variant) loop
14849 Check_Variant (Variant, Typ);
14850 Next (Variant);
14851 end loop;
14852 end if;
14853
14854 Set_Is_Unchecked_Union (Typ);
14855 Set_Convention (Typ, Convention_C);
14856 Set_Has_Unchecked_Union (Base_Type (Typ));
14857 Set_Is_Unchecked_Union (Base_Type (Typ));
14858 end Unchecked_Union;
14859
14860 ------------------------
14861 -- Unimplemented_Unit --
14862 ------------------------
14863
14864 -- pragma Unimplemented_Unit;
14865
14866 -- Note: this only gives an error if we are generating code, or if
14867 -- we are in a generic library unit (where the pragma appears in the
14868 -- body, not in the spec).
14869
14870 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
14871 Cunitent : constant Entity_Id :=
14872 Cunit_Entity (Get_Source_Unit (Loc));
14873 Ent_Kind : constant Entity_Kind :=
14874 Ekind (Cunitent);
14875
14876 begin
14877 GNAT_Pragma;
14878 Check_Arg_Count (0);
14879
14880 if Operating_Mode = Generate_Code
14881 or else Ent_Kind = E_Generic_Function
14882 or else Ent_Kind = E_Generic_Procedure
14883 or else Ent_Kind = E_Generic_Package
14884 then
14885 Get_Name_String (Chars (Cunitent));
14886 Set_Casing (Mixed_Case);
14887 Write_Str (Name_Buffer (1 .. Name_Len));
14888 Write_Str (" is not supported in this configuration");
14889 Write_Eol;
14890 raise Unrecoverable_Error;
14891 end if;
14892 end Unimplemented_Unit;
14893
14894 ------------------------
14895 -- Universal_Aliasing --
14896 ------------------------
14897
14898 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
14899
14900 when Pragma_Universal_Aliasing => Universal_Alias : declare
14901 E_Id : Entity_Id;
14902
14903 begin
14904 GNAT_Pragma;
14905 Check_Arg_Count (1);
14906 Check_Optional_Identifier (Arg2, Name_Entity);
14907 Check_Arg_Is_Local_Name (Arg1);
14908 E_Id := Entity (Get_Pragma_Arg (Arg1));
14909
14910 if E_Id = Any_Type then
14911 return;
14912 elsif No (E_Id) or else not Is_Type (E_Id) then
14913 Error_Pragma_Arg ("pragma% requires type", Arg1);
14914 end if;
14915
14916 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
14917 Record_Rep_Item (E_Id, N);
14918 end Universal_Alias;
14919
14920 --------------------
14921 -- Universal_Data --
14922 --------------------
14923
14924 -- pragma Universal_Data [(library_unit_NAME)];
14925
14926 when Pragma_Universal_Data =>
14927 GNAT_Pragma;
14928
14929 -- If this is a configuration pragma, then set the universal
14930 -- addressing option, otherwise confirm that the pragma satisfies
14931 -- the requirements of library unit pragma placement and leave it
14932 -- to the GNAAMP back end to detect the pragma (avoids transitive
14933 -- setting of the option due to withed units).
14934
14935 if Is_Configuration_Pragma then
14936 Universal_Addressing_On_AAMP := True;
14937 else
14938 Check_Valid_Library_Unit_Pragma;
14939 end if;
14940
14941 if not AAMP_On_Target then
14942 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
14943 end if;
14944
14945 ----------------
14946 -- Unmodified --
14947 ----------------
14948
14949 -- pragma Unmodified (local_Name {, local_Name});
14950
14951 when Pragma_Unmodified => Unmodified : declare
14952 Arg_Node : Node_Id;
14953 Arg_Expr : Node_Id;
14954 Arg_Ent : Entity_Id;
14955
14956 begin
14957 GNAT_Pragma;
14958 Check_At_Least_N_Arguments (1);
14959
14960 -- Loop through arguments
14961
14962 Arg_Node := Arg1;
14963 while Present (Arg_Node) loop
14964 Check_No_Identifier (Arg_Node);
14965
14966 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
14967 -- in fact generate reference, so that the entity will have a
14968 -- reference, which will inhibit any warnings about it not
14969 -- being referenced, and also properly show up in the ali file
14970 -- as a reference. But this reference is recorded before the
14971 -- Has_Pragma_Unreferenced flag is set, so that no warning is
14972 -- generated for this reference.
14973
14974 Check_Arg_Is_Local_Name (Arg_Node);
14975 Arg_Expr := Get_Pragma_Arg (Arg_Node);
14976
14977 if Is_Entity_Name (Arg_Expr) then
14978 Arg_Ent := Entity (Arg_Expr);
14979
14980 if not Is_Assignable (Arg_Ent) then
14981 Error_Pragma_Arg
14982 ("pragma% can only be applied to a variable",
14983 Arg_Expr);
14984 else
14985 Set_Has_Pragma_Unmodified (Arg_Ent);
14986 end if;
14987 end if;
14988
14989 Next (Arg_Node);
14990 end loop;
14991 end Unmodified;
14992
14993 ------------------
14994 -- Unreferenced --
14995 ------------------
14996
14997 -- pragma Unreferenced (local_Name {, local_Name});
14998
14999 -- or when used in a context clause:
15000
15001 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
15002
15003 when Pragma_Unreferenced => Unreferenced : declare
15004 Arg_Node : Node_Id;
15005 Arg_Expr : Node_Id;
15006 Arg_Ent : Entity_Id;
15007 Citem : Node_Id;
15008
15009 begin
15010 GNAT_Pragma;
15011 Check_At_Least_N_Arguments (1);
15012
15013 -- Check case of appearing within context clause
15014
15015 if Is_In_Context_Clause then
15016
15017 -- The arguments must all be units mentioned in a with clause
15018 -- in the same context clause. Note we already checked (in
15019 -- Par.Prag) that the arguments are either identifiers or
15020 -- selected components.
15021
15022 Arg_Node := Arg1;
15023 while Present (Arg_Node) loop
15024 Citem := First (List_Containing (N));
15025 while Citem /= N loop
15026 if Nkind (Citem) = N_With_Clause
15027 and then
15028 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
15029 then
15030 Set_Has_Pragma_Unreferenced
15031 (Cunit_Entity
15032 (Get_Source_Unit
15033 (Library_Unit (Citem))));
15034 Set_Unit_Name
15035 (Get_Pragma_Arg (Arg_Node), Name (Citem));
15036 exit;
15037 end if;
15038
15039 Next (Citem);
15040 end loop;
15041
15042 if Citem = N then
15043 Error_Pragma_Arg
15044 ("argument of pragma% is not withed unit", Arg_Node);
15045 end if;
15046
15047 Next (Arg_Node);
15048 end loop;
15049
15050 -- Case of not in list of context items
15051
15052 else
15053 Arg_Node := Arg1;
15054 while Present (Arg_Node) loop
15055 Check_No_Identifier (Arg_Node);
15056
15057 -- Note: the analyze call done by Check_Arg_Is_Local_Name
15058 -- will in fact generate reference, so that the entity will
15059 -- have a reference, which will inhibit any warnings about
15060 -- it not being referenced, and also properly show up in the
15061 -- ali file as a reference. But this reference is recorded
15062 -- before the Has_Pragma_Unreferenced flag is set, so that
15063 -- no warning is generated for this reference.
15064
15065 Check_Arg_Is_Local_Name (Arg_Node);
15066 Arg_Expr := Get_Pragma_Arg (Arg_Node);
15067
15068 if Is_Entity_Name (Arg_Expr) then
15069 Arg_Ent := Entity (Arg_Expr);
15070
15071 -- If the entity is overloaded, the pragma applies to the
15072 -- most recent overloading, as documented. In this case,
15073 -- name resolution does not generate a reference, so it
15074 -- must be done here explicitly.
15075
15076 if Is_Overloaded (Arg_Expr) then
15077 Generate_Reference (Arg_Ent, N);
15078 end if;
15079
15080 Set_Has_Pragma_Unreferenced (Arg_Ent);
15081 end if;
15082
15083 Next (Arg_Node);
15084 end loop;
15085 end if;
15086 end Unreferenced;
15087
15088 --------------------------
15089 -- Unreferenced_Objects --
15090 --------------------------
15091
15092 -- pragma Unreferenced_Objects (local_Name {, local_Name});
15093
15094 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
15095 Arg_Node : Node_Id;
15096 Arg_Expr : Node_Id;
15097
15098 begin
15099 GNAT_Pragma;
15100 Check_At_Least_N_Arguments (1);
15101
15102 Arg_Node := Arg1;
15103 while Present (Arg_Node) loop
15104 Check_No_Identifier (Arg_Node);
15105 Check_Arg_Is_Local_Name (Arg_Node);
15106 Arg_Expr := Get_Pragma_Arg (Arg_Node);
15107
15108 if not Is_Entity_Name (Arg_Expr)
15109 or else not Is_Type (Entity (Arg_Expr))
15110 then
15111 Error_Pragma_Arg
15112 ("argument for pragma% must be type or subtype", Arg_Node);
15113 end if;
15114
15115 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
15116 Next (Arg_Node);
15117 end loop;
15118 end Unreferenced_Objects;
15119
15120 ------------------------------
15121 -- Unreserve_All_Interrupts --
15122 ------------------------------
15123
15124 -- pragma Unreserve_All_Interrupts;
15125
15126 when Pragma_Unreserve_All_Interrupts =>
15127 GNAT_Pragma;
15128 Check_Arg_Count (0);
15129
15130 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
15131 Unreserve_All_Interrupts := True;
15132 end if;
15133
15134 ----------------
15135 -- Unsuppress --
15136 ----------------
15137
15138 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
15139
15140 when Pragma_Unsuppress =>
15141 Ada_2005_Pragma;
15142 Process_Suppress_Unsuppress (False);
15143
15144 -------------------
15145 -- Use_VADS_Size --
15146 -------------------
15147
15148 -- pragma Use_VADS_Size;
15149
15150 when Pragma_Use_VADS_Size =>
15151 GNAT_Pragma;
15152 Check_Arg_Count (0);
15153 Check_Valid_Configuration_Pragma;
15154 Use_VADS_Size := True;
15155
15156 ---------------------
15157 -- Validity_Checks --
15158 ---------------------
15159
15160 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
15161
15162 when Pragma_Validity_Checks => Validity_Checks : declare
15163 A : constant Node_Id := Get_Pragma_Arg (Arg1);
15164 S : String_Id;
15165 C : Char_Code;
15166
15167 begin
15168 GNAT_Pragma;
15169 Check_Arg_Count (1);
15170 Check_No_Identifiers;
15171
15172 if Nkind (A) = N_String_Literal then
15173 S := Strval (A);
15174
15175 declare
15176 Slen : constant Natural := Natural (String_Length (S));
15177 Options : String (1 .. Slen);
15178 J : Natural;
15179
15180 begin
15181 J := 1;
15182 loop
15183 C := Get_String_Char (S, Int (J));
15184 exit when not In_Character_Range (C);
15185 Options (J) := Get_Character (C);
15186
15187 if J = Slen then
15188 Set_Validity_Check_Options (Options);
15189 exit;
15190 else
15191 J := J + 1;
15192 end if;
15193 end loop;
15194 end;
15195
15196 elsif Nkind (A) = N_Identifier then
15197 if Chars (A) = Name_All_Checks then
15198 Set_Validity_Check_Options ("a");
15199 elsif Chars (A) = Name_On then
15200 Validity_Checks_On := True;
15201 elsif Chars (A) = Name_Off then
15202 Validity_Checks_On := False;
15203 end if;
15204 end if;
15205 end Validity_Checks;
15206
15207 --------------
15208 -- Volatile --
15209 --------------
15210
15211 -- pragma Volatile (LOCAL_NAME);
15212
15213 when Pragma_Volatile =>
15214 Process_Atomic_Shared_Volatile;
15215
15216 -------------------------
15217 -- Volatile_Components --
15218 -------------------------
15219
15220 -- pragma Volatile_Components (array_LOCAL_NAME);
15221
15222 -- Volatile is handled by the same circuit as Atomic_Components
15223
15224 --------------
15225 -- Warnings --
15226 --------------
15227
15228 -- pragma Warnings (On | Off);
15229 -- pragma Warnings (On | Off, LOCAL_NAME);
15230 -- pragma Warnings (static_string_EXPRESSION);
15231 -- pragma Warnings (On | Off, STRING_LITERAL);
15232
15233 when Pragma_Warnings => Warnings : begin
15234 GNAT_Pragma;
15235 Check_At_Least_N_Arguments (1);
15236 Check_No_Identifiers;
15237
15238 -- If debug flag -gnatd.i is set, pragma is ignored
15239
15240 if Debug_Flag_Dot_I then
15241 return;
15242 end if;
15243
15244 -- Process various forms of the pragma
15245
15246 declare
15247 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
15248
15249 begin
15250 -- One argument case
15251
15252 if Arg_Count = 1 then
15253
15254 -- On/Off one argument case was processed by parser
15255
15256 if Nkind (Argx) = N_Identifier
15257 and then
15258 (Chars (Argx) = Name_On
15259 or else
15260 Chars (Argx) = Name_Off)
15261 then
15262 null;
15263
15264 -- One argument case must be ON/OFF or static string expr
15265
15266 elsif not Is_Static_String_Expression (Arg1) then
15267 Error_Pragma_Arg
15268 ("argument of pragma% must be On/Off or " &
15269 "static string expression", Arg1);
15270
15271 -- One argument string expression case
15272
15273 else
15274 declare
15275 Lit : constant Node_Id := Expr_Value_S (Argx);
15276 Str : constant String_Id := Strval (Lit);
15277 Len : constant Nat := String_Length (Str);
15278 C : Char_Code;
15279 J : Nat;
15280 OK : Boolean;
15281 Chr : Character;
15282
15283 begin
15284 J := 1;
15285 while J <= Len loop
15286 C := Get_String_Char (Str, J);
15287 OK := In_Character_Range (C);
15288
15289 if OK then
15290 Chr := Get_Character (C);
15291
15292 -- Dot case
15293
15294 if J < Len and then Chr = '.' then
15295 J := J + 1;
15296 C := Get_String_Char (Str, J);
15297 Chr := Get_Character (C);
15298
15299 if not Set_Dot_Warning_Switch (Chr) then
15300 Error_Pragma_Arg
15301 ("invalid warning switch character " &
15302 '.' & Chr, Arg1);
15303 end if;
15304
15305 -- Non-Dot case
15306
15307 else
15308 OK := Set_Warning_Switch (Chr);
15309 end if;
15310 end if;
15311
15312 if not OK then
15313 Error_Pragma_Arg
15314 ("invalid warning switch character " & Chr,
15315 Arg1);
15316 end if;
15317
15318 J := J + 1;
15319 end loop;
15320 end;
15321 end if;
15322
15323 -- Two or more arguments (must be two)
15324
15325 else
15326 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
15327 Check_At_Most_N_Arguments (2);
15328
15329 declare
15330 E_Id : Node_Id;
15331 E : Entity_Id;
15332 Err : Boolean;
15333
15334 begin
15335 E_Id := Get_Pragma_Arg (Arg2);
15336 Analyze (E_Id);
15337
15338 -- In the expansion of an inlined body, a reference to
15339 -- the formal may be wrapped in a conversion if the
15340 -- actual is a conversion. Retrieve the real entity name.
15341
15342 if (In_Instance_Body or In_Inlined_Body)
15343 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
15344 then
15345 E_Id := Expression (E_Id);
15346 end if;
15347
15348 -- Entity name case
15349
15350 if Is_Entity_Name (E_Id) then
15351 E := Entity (E_Id);
15352
15353 if E = Any_Id then
15354 return;
15355 else
15356 loop
15357 Set_Warnings_Off
15358 (E, (Chars (Get_Pragma_Arg (Arg1)) =
15359 Name_Off));
15360
15361 -- For OFF case, make entry in warnings off
15362 -- pragma table for later processing. But we do
15363 -- not do that within an instance, since these
15364 -- warnings are about what is needed in the
15365 -- template, not an instance of it.
15366
15367 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
15368 and then Warn_On_Warnings_Off
15369 and then not In_Instance
15370 then
15371 Warnings_Off_Pragmas.Append ((N, E));
15372 end if;
15373
15374 if Is_Enumeration_Type (E) then
15375 declare
15376 Lit : Entity_Id;
15377 begin
15378 Lit := First_Literal (E);
15379 while Present (Lit) loop
15380 Set_Warnings_Off (Lit);
15381 Next_Literal (Lit);
15382 end loop;
15383 end;
15384 end if;
15385
15386 exit when No (Homonym (E));
15387 E := Homonym (E);
15388 end loop;
15389 end if;
15390
15391 -- Error if not entity or static string literal case
15392
15393 elsif not Is_Static_String_Expression (Arg2) then
15394 Error_Pragma_Arg
15395 ("second argument of pragma% must be entity " &
15396 "name or static string expression", Arg2);
15397
15398 -- String literal case
15399
15400 else
15401 String_To_Name_Buffer
15402 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
15403
15404 -- Note on configuration pragma case: If this is a
15405 -- configuration pragma, then for an OFF pragma, we
15406 -- just set Config True in the call, which is all
15407 -- that needs to be done. For the case of ON, this
15408 -- is normally an error, unless it is canceling the
15409 -- effect of a previous OFF pragma in the same file.
15410 -- In any other case, an error will be signalled (ON
15411 -- with no matching OFF).
15412
15413 -- Note: We set Used if we are inside a generic to
15414 -- disable the test that the non-config case actually
15415 -- cancels a warning. That's because we can't be sure
15416 -- there isn't an instantiation in some other unit
15417 -- where a warning is suppressed.
15418
15419 -- We could do a little better here by checking if the
15420 -- generic unit we are inside is public, but for now
15421 -- we don't bother with that refinement.
15422
15423 if Chars (Argx) = Name_Off then
15424 Set_Specific_Warning_Off
15425 (Loc, Name_Buffer (1 .. Name_Len),
15426 Config => Is_Configuration_Pragma,
15427 Used => Inside_A_Generic or else In_Instance);
15428
15429 elsif Chars (Argx) = Name_On then
15430 Set_Specific_Warning_On
15431 (Loc, Name_Buffer (1 .. Name_Len), Err);
15432
15433 if Err then
15434 Error_Msg
15435 ("?pragma Warnings On with no " &
15436 "matching Warnings Off",
15437 Loc);
15438 end if;
15439 end if;
15440 end if;
15441 end;
15442 end if;
15443 end;
15444 end Warnings;
15445
15446 -------------------
15447 -- Weak_External --
15448 -------------------
15449
15450 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
15451
15452 when Pragma_Weak_External => Weak_External : declare
15453 Ent : Entity_Id;
15454
15455 begin
15456 GNAT_Pragma;
15457 Check_Arg_Count (1);
15458 Check_Optional_Identifier (Arg1, Name_Entity);
15459 Check_Arg_Is_Library_Level_Local_Name (Arg1);
15460 Ent := Entity (Get_Pragma_Arg (Arg1));
15461
15462 if Rep_Item_Too_Early (Ent, N) then
15463 return;
15464 else
15465 Ent := Underlying_Type (Ent);
15466 end if;
15467
15468 -- The only processing required is to link this item on to the
15469 -- list of rep items for the given entity. This is accomplished
15470 -- by the call to Rep_Item_Too_Late (when no error is detected
15471 -- and False is returned).
15472
15473 if Rep_Item_Too_Late (Ent, N) then
15474 return;
15475 else
15476 Set_Has_Gigi_Rep_Item (Ent);
15477 end if;
15478 end Weak_External;
15479
15480 -----------------------------
15481 -- Wide_Character_Encoding --
15482 -----------------------------
15483
15484 -- pragma Wide_Character_Encoding (IDENTIFIER);
15485
15486 when Pragma_Wide_Character_Encoding =>
15487 GNAT_Pragma;
15488
15489 -- Nothing to do, handled in parser. Note that we do not enforce
15490 -- configuration pragma placement, this pragma can appear at any
15491 -- place in the source, allowing mixed encodings within a single
15492 -- source program.
15493
15494 null;
15495
15496 --------------------
15497 -- Unknown_Pragma --
15498 --------------------
15499
15500 -- Should be impossible, since the case of an unknown pragma is
15501 -- separately processed before the case statement is entered.
15502
15503 when Unknown_Pragma =>
15504 raise Program_Error;
15505 end case;
15506
15507 -- AI05-0144: detect dangerous order dependence. Disabled for now,
15508 -- until AI is formally approved.
15509
15510 -- Check_Order_Dependence;
15511
15512 exception
15513 when Pragma_Exit => null;
15514 end Analyze_Pragma;
15515
15516 --------------------
15517 -- Check_Disabled --
15518 --------------------
15519
15520 function Check_Disabled (Nam : Name_Id) return Boolean is
15521 PP : Node_Id;
15522
15523 begin
15524 -- Loop through entries in check policy list
15525
15526 PP := Opt.Check_Policy_List;
15527 loop
15528 -- If there are no specific entries that matched, then nothing is
15529 -- disabled, so return False.
15530
15531 if No (PP) then
15532 return False;
15533
15534 -- Here we have an entry see if it matches
15535
15536 else
15537 declare
15538 PPA : constant List_Id := Pragma_Argument_Associations (PP);
15539 begin
15540 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
15541 return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
15542 else
15543 PP := Next_Pragma (PP);
15544 end if;
15545 end;
15546 end if;
15547 end loop;
15548 end Check_Disabled;
15549
15550 -------------------
15551 -- Check_Enabled --
15552 -------------------
15553
15554 function Check_Enabled (Nam : Name_Id) return Boolean is
15555 PP : Node_Id;
15556
15557 begin
15558 -- Loop through entries in check policy list
15559
15560 PP := Opt.Check_Policy_List;
15561 loop
15562 -- If there are no specific entries that matched, then we let the
15563 -- setting of assertions govern. Note that this provides the needed
15564 -- compatibility with the RM for the cases of assertion, invariant,
15565 -- precondition, predicate, and postcondition.
15566
15567 if No (PP) then
15568 return Assertions_Enabled;
15569
15570 -- Here we have an entry see if it matches
15571
15572 else
15573 declare
15574 PPA : constant List_Id := Pragma_Argument_Associations (PP);
15575
15576 begin
15577 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
15578 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
15579 when Name_On | Name_Check =>
15580 return True;
15581 when Name_Off | Name_Ignore =>
15582 return False;
15583 when others =>
15584 raise Program_Error;
15585 end case;
15586
15587 else
15588 PP := Next_Pragma (PP);
15589 end if;
15590 end;
15591 end if;
15592 end loop;
15593 end Check_Enabled;
15594
15595 ---------------------------------
15596 -- Delay_Config_Pragma_Analyze --
15597 ---------------------------------
15598
15599 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
15600 begin
15601 return Pragma_Name (N) = Name_Interrupt_State
15602 or else
15603 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
15604 end Delay_Config_Pragma_Analyze;
15605
15606 -------------------------
15607 -- Get_Base_Subprogram --
15608 -------------------------
15609
15610 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
15611 Result : Entity_Id;
15612
15613 begin
15614 -- Follow subprogram renaming chain
15615
15616 Result := Def_Id;
15617
15618 if Is_Subprogram (Result)
15619 and then
15620 Nkind (Parent (Declaration_Node (Result))) =
15621 N_Subprogram_Renaming_Declaration
15622 and then Present (Alias (Result))
15623 then
15624 Result := Alias (Result);
15625 end if;
15626
15627 return Result;
15628 end Get_Base_Subprogram;
15629
15630 ----------------
15631 -- Initialize --
15632 ----------------
15633
15634 procedure Initialize is
15635 begin
15636 Externals.Init;
15637 end Initialize;
15638
15639 -----------------------------
15640 -- Is_Config_Static_String --
15641 -----------------------------
15642
15643 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
15644
15645 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
15646 -- This is an internal recursive function that is just like the outer
15647 -- function except that it adds the string to the name buffer rather
15648 -- than placing the string in the name buffer.
15649
15650 ------------------------------
15651 -- Add_Config_Static_String --
15652 ------------------------------
15653
15654 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
15655 N : Node_Id;
15656 C : Char_Code;
15657
15658 begin
15659 N := Arg;
15660
15661 if Nkind (N) = N_Op_Concat then
15662 if Add_Config_Static_String (Left_Opnd (N)) then
15663 N := Right_Opnd (N);
15664 else
15665 return False;
15666 end if;
15667 end if;
15668
15669 if Nkind (N) /= N_String_Literal then
15670 Error_Msg_N ("string literal expected for pragma argument", N);
15671 return False;
15672
15673 else
15674 for J in 1 .. String_Length (Strval (N)) loop
15675 C := Get_String_Char (Strval (N), J);
15676
15677 if not In_Character_Range (C) then
15678 Error_Msg
15679 ("string literal contains invalid wide character",
15680 Sloc (N) + 1 + Source_Ptr (J));
15681 return False;
15682 end if;
15683
15684 Add_Char_To_Name_Buffer (Get_Character (C));
15685 end loop;
15686 end if;
15687
15688 return True;
15689 end Add_Config_Static_String;
15690
15691 -- Start of processing for Is_Config_Static_String
15692
15693 begin
15694
15695 Name_Len := 0;
15696 return Add_Config_Static_String (Arg);
15697 end Is_Config_Static_String;
15698
15699 -----------------------------------------
15700 -- Is_Non_Significant_Pragma_Reference --
15701 -----------------------------------------
15702
15703 -- This function makes use of the following static table which indicates
15704 -- whether appearance of some name in a given pragma is to be considered
15705 -- as a reference for the purposes of warnings about unreferenced objects.
15706
15707 -- -1 indicates that references in any argument position are significant
15708 -- 0 indicates that appearance in any argument is not significant
15709 -- +n indicates that appearance as argument n is significant, but all
15710 -- other arguments are not significant
15711 -- 99 special processing required (e.g. for pragma Check)
15712
15713 Sig_Flags : constant array (Pragma_Id) of Int :=
15714 (Pragma_AST_Entry => -1,
15715 Pragma_Abort_Defer => -1,
15716 Pragma_Ada_83 => -1,
15717 Pragma_Ada_95 => -1,
15718 Pragma_Ada_05 => -1,
15719 Pragma_Ada_2005 => -1,
15720 Pragma_Ada_12 => -1,
15721 Pragma_Ada_2012 => -1,
15722 Pragma_All_Calls_Remote => -1,
15723 Pragma_Annotate => -1,
15724 Pragma_Assert => -1,
15725 Pragma_Assert_And_Cut => -1,
15726 Pragma_Assertion_Policy => 0,
15727 Pragma_Assume => 0,
15728 Pragma_Assume_No_Invalid_Values => 0,
15729 Pragma_Attribute_Definition => +3,
15730 Pragma_Asynchronous => -1,
15731 Pragma_Atomic => 0,
15732 Pragma_Atomic_Components => 0,
15733 Pragma_Attach_Handler => -1,
15734 Pragma_Check => 99,
15735 Pragma_Check_Name => 0,
15736 Pragma_Check_Policy => 0,
15737 Pragma_CIL_Constructor => -1,
15738 Pragma_CPP_Class => 0,
15739 Pragma_CPP_Constructor => 0,
15740 Pragma_CPP_Virtual => 0,
15741 Pragma_CPP_Vtable => 0,
15742 Pragma_CPU => -1,
15743 Pragma_C_Pass_By_Copy => 0,
15744 Pragma_Comment => 0,
15745 Pragma_Common_Object => -1,
15746 Pragma_Compile_Time_Error => -1,
15747 Pragma_Compile_Time_Warning => -1,
15748 Pragma_Compiler_Unit => 0,
15749 Pragma_Complete_Representation => 0,
15750 Pragma_Complex_Representation => 0,
15751 Pragma_Component_Alignment => -1,
15752 Pragma_Contract_Case => -1,
15753 Pragma_Contract_Cases => -1,
15754 Pragma_Controlled => 0,
15755 Pragma_Convention => 0,
15756 Pragma_Convention_Identifier => 0,
15757 Pragma_Debug => -1,
15758 Pragma_Debug_Policy => 0,
15759 Pragma_Detect_Blocking => -1,
15760 Pragma_Default_Storage_Pool => -1,
15761 Pragma_Disable_Atomic_Synchronization => -1,
15762 Pragma_Discard_Names => 0,
15763 Pragma_Dispatching_Domain => -1,
15764 Pragma_Elaborate => -1,
15765 Pragma_Elaborate_All => -1,
15766 Pragma_Elaborate_Body => -1,
15767 Pragma_Elaboration_Checks => -1,
15768 Pragma_Eliminate => -1,
15769 Pragma_Enable_Atomic_Synchronization => -1,
15770 Pragma_Export => -1,
15771 Pragma_Export_Exception => -1,
15772 Pragma_Export_Function => -1,
15773 Pragma_Export_Object => -1,
15774 Pragma_Export_Procedure => -1,
15775 Pragma_Export_Value => -1,
15776 Pragma_Export_Valued_Procedure => -1,
15777 Pragma_Extend_System => -1,
15778 Pragma_Extensions_Allowed => -1,
15779 Pragma_External => -1,
15780 Pragma_Favor_Top_Level => -1,
15781 Pragma_External_Name_Casing => -1,
15782 Pragma_Fast_Math => -1,
15783 Pragma_Finalize_Storage_Only => 0,
15784 Pragma_Float_Representation => 0,
15785 Pragma_Ident => -1,
15786 Pragma_Implementation_Defined => -1,
15787 Pragma_Implemented => -1,
15788 Pragma_Implicit_Packing => 0,
15789 Pragma_Import => +2,
15790 Pragma_Import_Exception => 0,
15791 Pragma_Import_Function => 0,
15792 Pragma_Import_Object => 0,
15793 Pragma_Import_Procedure => 0,
15794 Pragma_Import_Valued_Procedure => 0,
15795 Pragma_Independent => 0,
15796 Pragma_Independent_Components => 0,
15797 Pragma_Initialize_Scalars => -1,
15798 Pragma_Inline => 0,
15799 Pragma_Inline_Always => 0,
15800 Pragma_Inline_Generic => 0,
15801 Pragma_Inspection_Point => -1,
15802 Pragma_Interface => +2,
15803 Pragma_Interface_Name => +2,
15804 Pragma_Interrupt_Handler => -1,
15805 Pragma_Interrupt_Priority => -1,
15806 Pragma_Interrupt_State => -1,
15807 Pragma_Invariant => -1,
15808 Pragma_Java_Constructor => -1,
15809 Pragma_Java_Interface => -1,
15810 Pragma_Keep_Names => 0,
15811 Pragma_License => -1,
15812 Pragma_Link_With => -1,
15813 Pragma_Linker_Alias => -1,
15814 Pragma_Linker_Constructor => -1,
15815 Pragma_Linker_Destructor => -1,
15816 Pragma_Linker_Options => -1,
15817 Pragma_Linker_Section => -1,
15818 Pragma_List => -1,
15819 Pragma_Lock_Free => -1,
15820 Pragma_Locking_Policy => -1,
15821 Pragma_Long_Float => -1,
15822 Pragma_Loop_Invariant => -1,
15823 Pragma_Loop_Variant => -1,
15824 Pragma_Machine_Attribute => -1,
15825 Pragma_Main => -1,
15826 Pragma_Main_Storage => -1,
15827 Pragma_Memory_Size => -1,
15828 Pragma_No_Return => 0,
15829 Pragma_No_Body => 0,
15830 Pragma_No_Run_Time => -1,
15831 Pragma_No_Strict_Aliasing => -1,
15832 Pragma_Normalize_Scalars => -1,
15833 Pragma_Obsolescent => 0,
15834 Pragma_Optimize => -1,
15835 Pragma_Optimize_Alignment => -1,
15836 Pragma_Overflow_Mode => 0,
15837 Pragma_Ordered => 0,
15838 Pragma_Pack => 0,
15839 Pragma_Page => -1,
15840 Pragma_Partition_Elaboration_Policy => -1,
15841 Pragma_Passive => -1,
15842 Pragma_Preelaborable_Initialization => -1,
15843 Pragma_Polling => -1,
15844 Pragma_Persistent_BSS => 0,
15845 Pragma_Postcondition => -1,
15846 Pragma_Precondition => -1,
15847 Pragma_Predicate => -1,
15848 Pragma_Preelaborate => -1,
15849 Pragma_Preelaborate_05 => -1,
15850 Pragma_Priority => -1,
15851 Pragma_Priority_Specific_Dispatching => -1,
15852 Pragma_Profile => 0,
15853 Pragma_Profile_Warnings => 0,
15854 Pragma_Propagate_Exceptions => -1,
15855 Pragma_Psect_Object => -1,
15856 Pragma_Pure => -1,
15857 Pragma_Pure_05 => -1,
15858 Pragma_Pure_12 => -1,
15859 Pragma_Pure_Function => -1,
15860 Pragma_Queuing_Policy => -1,
15861 Pragma_Ravenscar => -1,
15862 Pragma_Relative_Deadline => -1,
15863 Pragma_Remote_Access_Type => -1,
15864 Pragma_Remote_Call_Interface => -1,
15865 Pragma_Remote_Types => -1,
15866 Pragma_Restricted_Run_Time => -1,
15867 Pragma_Restriction_Warnings => -1,
15868 Pragma_Restrictions => -1,
15869 Pragma_Reviewable => -1,
15870 Pragma_Short_Circuit_And_Or => -1,
15871 Pragma_Share_Generic => -1,
15872 Pragma_Shared => -1,
15873 Pragma_Shared_Passive => -1,
15874 Pragma_Short_Descriptors => 0,
15875 Pragma_Simple_Storage_Pool_Type => 0,
15876 Pragma_Source_File_Name => -1,
15877 Pragma_Source_File_Name_Project => -1,
15878 Pragma_Source_Reference => -1,
15879 Pragma_Storage_Size => -1,
15880 Pragma_Storage_Unit => -1,
15881 Pragma_Static_Elaboration_Desired => -1,
15882 Pragma_Stream_Convert => -1,
15883 Pragma_Style_Checks => -1,
15884 Pragma_Subtitle => -1,
15885 Pragma_Suppress => 0,
15886 Pragma_Suppress_Exception_Locations => 0,
15887 Pragma_Suppress_All => -1,
15888 Pragma_Suppress_Debug_Info => 0,
15889 Pragma_Suppress_Initialization => 0,
15890 Pragma_System_Name => -1,
15891 Pragma_Task_Dispatching_Policy => -1,
15892 Pragma_Task_Info => -1,
15893 Pragma_Task_Name => -1,
15894 Pragma_Task_Storage => 0,
15895 Pragma_Test_Case => -1,
15896 Pragma_Thread_Local_Storage => 0,
15897 Pragma_Time_Slice => -1,
15898 Pragma_Title => -1,
15899 Pragma_Unchecked_Union => 0,
15900 Pragma_Unimplemented_Unit => -1,
15901 Pragma_Universal_Aliasing => -1,
15902 Pragma_Universal_Data => -1,
15903 Pragma_Unmodified => -1,
15904 Pragma_Unreferenced => -1,
15905 Pragma_Unreferenced_Objects => -1,
15906 Pragma_Unreserve_All_Interrupts => -1,
15907 Pragma_Unsuppress => 0,
15908 Pragma_Use_VADS_Size => -1,
15909 Pragma_Validity_Checks => -1,
15910 Pragma_Volatile => 0,
15911 Pragma_Volatile_Components => 0,
15912 Pragma_Warnings => -1,
15913 Pragma_Weak_External => -1,
15914 Pragma_Wide_Character_Encoding => 0,
15915 Unknown_Pragma => 0);
15916
15917 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
15918 Id : Pragma_Id;
15919 P : Node_Id;
15920 C : Int;
15921 A : Node_Id;
15922
15923 begin
15924 P := Parent (N);
15925
15926 if Nkind (P) /= N_Pragma_Argument_Association then
15927 return False;
15928
15929 else
15930 Id := Get_Pragma_Id (Parent (P));
15931 C := Sig_Flags (Id);
15932
15933 case C is
15934 when -1 =>
15935 return False;
15936
15937 when 0 =>
15938 return True;
15939
15940 when 99 =>
15941 case Id is
15942
15943 -- For pragma Check, the first argument is not significant,
15944 -- the second and the third (if present) arguments are
15945 -- significant.
15946
15947 when Pragma_Check =>
15948 return
15949 P = First (Pragma_Argument_Associations (Parent (P)));
15950
15951 when others =>
15952 raise Program_Error;
15953 end case;
15954
15955 when others =>
15956 A := First (Pragma_Argument_Associations (Parent (P)));
15957 for J in 1 .. C - 1 loop
15958 if No (A) then
15959 return False;
15960 end if;
15961
15962 Next (A);
15963 end loop;
15964
15965 return A = P; -- is this wrong way round ???
15966 end case;
15967 end if;
15968 end Is_Non_Significant_Pragma_Reference;
15969
15970 ------------------------------
15971 -- Is_Pragma_String_Literal --
15972 ------------------------------
15973
15974 -- This function returns true if the corresponding pragma argument is a
15975 -- static string expression. These are the only cases in which string
15976 -- literals can appear as pragma arguments. We also allow a string literal
15977 -- as the first argument to pragma Assert (although it will of course
15978 -- always generate a type error).
15979
15980 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
15981 Pragn : constant Node_Id := Parent (Par);
15982 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
15983 Pname : constant Name_Id := Pragma_Name (Pragn);
15984 Argn : Natural;
15985 N : Node_Id;
15986
15987 begin
15988 Argn := 1;
15989 N := First (Assoc);
15990 loop
15991 exit when N = Par;
15992 Argn := Argn + 1;
15993 Next (N);
15994 end loop;
15995
15996 if Pname = Name_Assert then
15997 return True;
15998
15999 elsif Pname = Name_Export then
16000 return Argn > 2;
16001
16002 elsif Pname = Name_Ident then
16003 return Argn = 1;
16004
16005 elsif Pname = Name_Import then
16006 return Argn > 2;
16007
16008 elsif Pname = Name_Interface_Name then
16009 return Argn > 1;
16010
16011 elsif Pname = Name_Linker_Alias then
16012 return Argn = 2;
16013
16014 elsif Pname = Name_Linker_Section then
16015 return Argn = 2;
16016
16017 elsif Pname = Name_Machine_Attribute then
16018 return Argn = 2;
16019
16020 elsif Pname = Name_Source_File_Name then
16021 return True;
16022
16023 elsif Pname = Name_Source_Reference then
16024 return Argn = 2;
16025
16026 elsif Pname = Name_Title then
16027 return True;
16028
16029 elsif Pname = Name_Subtitle then
16030 return True;
16031
16032 else
16033 return False;
16034 end if;
16035 end Is_Pragma_String_Literal;
16036
16037 -----------------------------------------
16038 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
16039 -----------------------------------------
16040
16041 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
16042 Aspects : constant List_Id := New_List;
16043 Loc : constant Source_Ptr := Sloc (Decl);
16044 Or_Decl : constant Node_Id := Original_Node (Decl);
16045
16046 Original_Aspects : List_Id;
16047 -- To capture global references, a copy of the created aspects must be
16048 -- inserted in the original tree.
16049
16050 Prag : Node_Id;
16051 Prag_Arg_Ass : Node_Id;
16052 Prag_Id : Pragma_Id;
16053
16054 begin
16055 -- Check for any PPC pragmas that appear within Decl
16056
16057 Prag := Next (Decl);
16058 while Nkind (Prag) = N_Pragma loop
16059 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
16060
16061 case Prag_Id is
16062 when Pragma_Postcondition | Pragma_Precondition =>
16063 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
16064
16065 -- Make an aspect from any PPC pragma
16066
16067 Append_To (Aspects,
16068 Make_Aspect_Specification (Loc,
16069 Identifier =>
16070 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
16071 Expression =>
16072 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
16073
16074 -- Generate the analysis information in the pragma expression
16075 -- and then set the pragma node analyzed to avoid any further
16076 -- analysis.
16077
16078 Analyze (Expression (Prag_Arg_Ass));
16079 Set_Analyzed (Prag, True);
16080
16081 when others => null;
16082 end case;
16083
16084 Next (Prag);
16085 end loop;
16086
16087 -- Set all new aspects into the generic declaration node
16088
16089 if Is_Non_Empty_List (Aspects) then
16090
16091 -- Create the list of aspects to be inserted in the original tree
16092
16093 Original_Aspects := Copy_Separate_List (Aspects);
16094
16095 -- Check if Decl already has aspects
16096
16097 -- Attach the new lists of aspects to both the generic copy and the
16098 -- original tree.
16099
16100 if Has_Aspects (Decl) then
16101 Append_List (Aspects, Aspect_Specifications (Decl));
16102 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
16103
16104 else
16105 Set_Parent (Aspects, Decl);
16106 Set_Aspect_Specifications (Decl, Aspects);
16107 Set_Parent (Original_Aspects, Or_Decl);
16108 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
16109 end if;
16110 end if;
16111 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
16112
16113 -------------------------
16114 -- Preanalyze_CTC_Args --
16115 -------------------------
16116
16117 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
16118 begin
16119 -- Preanalyze the boolean expressions, we treat these as spec
16120 -- expressions (i.e. similar to a default expression).
16121
16122 if Present (Arg_Req) then
16123 Preanalyze_Assert_Expression
16124 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
16125
16126 -- In ASIS mode, for a pragma generated from a source aspect, also
16127 -- analyze the original aspect expression.
16128
16129 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
16130 Preanalyze_Assert_Expression
16131 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
16132 end if;
16133 end if;
16134
16135 if Present (Arg_Ens) then
16136 Preanalyze_Assert_Expression
16137 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
16138
16139 -- In ASIS mode, for a pragma generated from a source aspect, also
16140 -- analyze the original aspect expression.
16141
16142 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
16143 Preanalyze_Assert_Expression
16144 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
16145 end if;
16146 end if;
16147 end Preanalyze_CTC_Args;
16148
16149 --------------------------------------
16150 -- Process_Compilation_Unit_Pragmas --
16151 --------------------------------------
16152
16153 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
16154 begin
16155 -- A special check for pragma Suppress_All, a very strange DEC pragma,
16156 -- strange because it comes at the end of the unit. Rational has the
16157 -- same name for a pragma, but treats it as a program unit pragma, In
16158 -- GNAT we just decide to allow it anywhere at all. If it appeared then
16159 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
16160 -- node, and we insert a pragma Suppress (All_Checks) at the start of
16161 -- the context clause to ensure the correct processing.
16162
16163 if Has_Pragma_Suppress_All (N) then
16164 Prepend_To (Context_Items (N),
16165 Make_Pragma (Sloc (N),
16166 Chars => Name_Suppress,
16167 Pragma_Argument_Associations => New_List (
16168 Make_Pragma_Argument_Association (Sloc (N),
16169 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
16170 end if;
16171
16172 -- Nothing else to do at the current time!
16173
16174 end Process_Compilation_Unit_Pragmas;
16175
16176 --------
16177 -- rv --
16178 --------
16179
16180 procedure rv is
16181 begin
16182 null;
16183 end rv;
16184
16185 --------------------------------
16186 -- Set_Encoded_Interface_Name --
16187 --------------------------------
16188
16189 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
16190 Str : constant String_Id := Strval (S);
16191 Len : constant Int := String_Length (Str);
16192 CC : Char_Code;
16193 C : Character;
16194 J : Int;
16195
16196 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
16197
16198 procedure Encode;
16199 -- Stores encoded value of character code CC. The encoding we use an
16200 -- underscore followed by four lower case hex digits.
16201
16202 ------------
16203 -- Encode --
16204 ------------
16205
16206 procedure Encode is
16207 begin
16208 Store_String_Char (Get_Char_Code ('_'));
16209 Store_String_Char
16210 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
16211 Store_String_Char
16212 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
16213 Store_String_Char
16214 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
16215 Store_String_Char
16216 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
16217 end Encode;
16218
16219 -- Start of processing for Set_Encoded_Interface_Name
16220
16221 begin
16222 -- If first character is asterisk, this is a link name, and we leave it
16223 -- completely unmodified. We also ignore null strings (the latter case
16224 -- happens only in error cases) and no encoding should occur for Java or
16225 -- AAMP interface names.
16226
16227 if Len = 0
16228 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
16229 or else VM_Target /= No_VM
16230 or else AAMP_On_Target
16231 then
16232 Set_Interface_Name (E, S);
16233
16234 else
16235 J := 1;
16236 loop
16237 CC := Get_String_Char (Str, J);
16238
16239 exit when not In_Character_Range (CC);
16240
16241 C := Get_Character (CC);
16242
16243 exit when C /= '_' and then C /= '$'
16244 and then C not in '0' .. '9'
16245 and then C not in 'a' .. 'z'
16246 and then C not in 'A' .. 'Z';
16247
16248 if J = Len then
16249 Set_Interface_Name (E, S);
16250 return;
16251
16252 else
16253 J := J + 1;
16254 end if;
16255 end loop;
16256
16257 -- Here we need to encode. The encoding we use as follows:
16258 -- three underscores + four hex digits (lower case)
16259
16260 Start_String;
16261
16262 for J in 1 .. String_Length (Str) loop
16263 CC := Get_String_Char (Str, J);
16264
16265 if not In_Character_Range (CC) then
16266 Encode;
16267 else
16268 C := Get_Character (CC);
16269
16270 if C = '_' or else C = '$'
16271 or else C in '0' .. '9'
16272 or else C in 'a' .. 'z'
16273 or else C in 'A' .. 'Z'
16274 then
16275 Store_String_Char (CC);
16276 else
16277 Encode;
16278 end if;
16279 end if;
16280 end loop;
16281
16282 Set_Interface_Name (E,
16283 Make_String_Literal (Sloc (S),
16284 Strval => End_String));
16285 end if;
16286 end Set_Encoded_Interface_Name;
16287
16288 -------------------
16289 -- Set_Unit_Name --
16290 -------------------
16291
16292 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
16293 Pref : Node_Id;
16294 Scop : Entity_Id;
16295
16296 begin
16297 if Nkind (N) = N_Identifier
16298 and then Nkind (With_Item) = N_Identifier
16299 then
16300 Set_Entity (N, Entity (With_Item));
16301
16302 elsif Nkind (N) = N_Selected_Component then
16303 Change_Selected_Component_To_Expanded_Name (N);
16304 Set_Entity (N, Entity (With_Item));
16305 Set_Entity (Selector_Name (N), Entity (N));
16306
16307 Pref := Prefix (N);
16308 Scop := Scope (Entity (N));
16309 while Nkind (Pref) = N_Selected_Component loop
16310 Change_Selected_Component_To_Expanded_Name (Pref);
16311 Set_Entity (Selector_Name (Pref), Scop);
16312 Set_Entity (Pref, Scop);
16313 Pref := Prefix (Pref);
16314 Scop := Scope (Scop);
16315 end loop;
16316
16317 Set_Entity (Pref, Scop);
16318 end if;
16319 end Set_Unit_Name;
16320
16321 end Sem_Prag;