[multiple changes]
[gcc.git] / gcc / ada / sem_prag.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ P R A G --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2010, 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 Atree; use Atree;
33 with Casing; use Casing;
34 with Checks; use Checks;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with Elists; use Elists;
39 with Errout; use Errout;
40 with Exp_Ch7; use Exp_Ch7;
41 with Exp_Dist; use Exp_Dist;
42 with Lib; use Lib;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref; use Lib.Xref;
45 with Namet.Sp; use Namet.Sp;
46 with Nlists; use Nlists;
47 with Nmake; use Nmake;
48 with Opt; use Opt;
49 with Output; use Output;
50 with Par_SCO; use Par_SCO;
51 with Restrict; use Restrict;
52 with Rident; use Rident;
53 with Rtsfind; use Rtsfind;
54 with Sem; use Sem;
55 with Sem_Aux; use Sem_Aux;
56 with Sem_Ch3; use Sem_Ch3;
57 with Sem_Ch6; use Sem_Ch6;
58 with Sem_Ch8; use Sem_Ch8;
59 with Sem_Ch12; use Sem_Ch12;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Disp; use Sem_Disp;
62 with Sem_Dist; use Sem_Dist;
63 with Sem_Elim; use Sem_Elim;
64 with Sem_Eval; use Sem_Eval;
65 with Sem_Intr; use Sem_Intr;
66 with Sem_Mech; use Sem_Mech;
67 with Sem_Res; use Sem_Res;
68 with Sem_Type; use Sem_Type;
69 with Sem_Util; use Sem_Util;
70 with Sem_VFpt; use Sem_VFpt;
71 with Sem_Warn; use Sem_Warn;
72 with Stand; use Stand;
73 with Sinfo; use Sinfo;
74 with Sinfo.CN; use Sinfo.CN;
75 with Sinput; use Sinput;
76 with Snames; use Snames;
77 with Stringt; use Stringt;
78 with Stylesw; use Stylesw;
79 with Table;
80 with Targparm; use Targparm;
81 with Tbuild; use Tbuild;
82 with Ttypes;
83 with Uintp; use Uintp;
84 with Uname; use Uname;
85 with Urealp; use Urealp;
86 with Validsw; use Validsw;
87 with Warnsw; use Warnsw;
88
89 package body Sem_Prag is
90
91 ----------------------------------------------
92 -- Common Handling of Import-Export Pragmas --
93 ----------------------------------------------
94
95 -- In the following section, a number of Import_xxx and Export_xxx pragmas
96 -- are defined by GNAT. These are compatible with the DEC pragmas of the
97 -- same name, and all have the following common form and processing:
98
99 -- pragma Export_xxx
100 -- [Internal =>] LOCAL_NAME
101 -- [, [External =>] EXTERNAL_SYMBOL]
102 -- [, other optional parameters ]);
103
104 -- pragma Import_xxx
105 -- [Internal =>] LOCAL_NAME
106 -- [, [External =>] EXTERNAL_SYMBOL]
107 -- [, other optional parameters ]);
108
109 -- EXTERNAL_SYMBOL ::=
110 -- IDENTIFIER
111 -- | static_string_EXPRESSION
112
113 -- The internal LOCAL_NAME designates the entity that is imported or
114 -- exported, and must refer to an entity in the current declarative
115 -- part (as required by the rules for LOCAL_NAME).
116
117 -- The external linker name is designated by the External parameter if
118 -- given, or the Internal parameter if not (if there is no External
119 -- parameter, the External parameter is a copy of the Internal name).
120
121 -- If the External parameter is given as a string, then this string is
122 -- treated as an external name (exactly as though it had been given as an
123 -- External_Name parameter for a normal Import pragma).
124
125 -- If the External parameter is given as an identifier (or there is no
126 -- External parameter, so that the Internal identifier is used), then
127 -- the external name is the characters of the identifier, translated
128 -- to all upper case letters for OpenVMS versions of GNAT, and to all
129 -- lower case letters for all other versions
130
131 -- Note: the external name specified or implied by any of these special
132 -- Import_xxx or Export_xxx pragmas override an external or link name
133 -- specified in a previous Import or Export pragma.
134
135 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
136 -- named notation, following the standard rules for subprogram calls, i.e.
137 -- parameters can be given in any order if named notation is used, and
138 -- positional and named notation can be mixed, subject to the rule that all
139 -- positional parameters must appear first.
140
141 -- Note: All these pragmas are implemented exactly following the DEC design
142 -- and implementation and are intended to be fully compatible with the use
143 -- of these pragmas in the DEC Ada compiler.
144
145 --------------------------------------------
146 -- Checking for Duplicated External Names --
147 --------------------------------------------
148
149 -- It is suspicious if two separate Export pragmas use the same external
150 -- name. The following table is used to diagnose this situation so that
151 -- an appropriate warning can be issued.
152
153 -- The Node_Id stored is for the N_String_Literal node created to hold
154 -- the value of the external name. The Sloc of this node is used to
155 -- cross-reference the location of the duplication.
156
157 package Externals is new Table.Table (
158 Table_Component_Type => Node_Id,
159 Table_Index_Type => Int,
160 Table_Low_Bound => 0,
161 Table_Initial => 100,
162 Table_Increment => 100,
163 Table_Name => "Name_Externals");
164
165 -------------------------------------
166 -- Local Subprograms and Variables --
167 -------------------------------------
168
169 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
170 -- This routine is used for possible casing adjustment of an explicit
171 -- external name supplied as a string literal (the node N), according to
172 -- the casing requirement of Opt.External_Name_Casing. If this is set to
173 -- As_Is, then the string literal is returned unchanged, but if it is set
174 -- to Uppercase or Lowercase, then a new string literal with appropriate
175 -- casing is constructed.
176
177 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
178 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
179 -- original one, following the renaming chain) is returned. Otherwise the
180 -- entity is returned unchanged. Should be in Einfo???
181
182 procedure rv;
183 -- This is a dummy function called by the processing for pragma Reviewable.
184 -- It is there for assisting front end debugging. By placing a Reviewable
185 -- pragma in the source program, a breakpoint on rv catches this place in
186 -- the source, allowing convenient stepping to the point of interest.
187
188 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
189 -- Place semantic information on the argument of an Elaborate/Elaborate_All
190 -- pragma. Entity name for unit and its parents is taken from item in
191 -- previous with_clause that mentions the unit.
192
193 -------------------------------
194 -- Adjust_External_Name_Case --
195 -------------------------------
196
197 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
198 CC : Char_Code;
199
200 begin
201 -- Adjust case of literal if required
202
203 if Opt.External_Name_Exp_Casing = As_Is then
204 return N;
205
206 else
207 -- Copy existing string
208
209 Start_String;
210
211 -- Set proper casing
212
213 for J in 1 .. String_Length (Strval (N)) loop
214 CC := Get_String_Char (Strval (N), J);
215
216 if Opt.External_Name_Exp_Casing = Uppercase
217 and then CC >= Get_Char_Code ('a')
218 and then CC <= Get_Char_Code ('z')
219 then
220 Store_String_Char (CC - 32);
221
222 elsif Opt.External_Name_Exp_Casing = Lowercase
223 and then CC >= Get_Char_Code ('A')
224 and then CC <= Get_Char_Code ('Z')
225 then
226 Store_String_Char (CC + 32);
227
228 else
229 Store_String_Char (CC);
230 end if;
231 end loop;
232
233 return
234 Make_String_Literal (Sloc (N),
235 Strval => End_String);
236 end if;
237 end Adjust_External_Name_Case;
238
239 ------------------------------
240 -- Analyze_PPC_In_Decl_Part --
241 ------------------------------
242
243 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
244 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
245
246 begin
247 -- Install formals and push subprogram spec onto scope stack so that we
248 -- can see the formals from the pragma.
249
250 Install_Formals (S);
251 Push_Scope (S);
252
253 -- Preanalyze the boolean expression, we treat this as a spec expression
254 -- (i.e. similar to a default expression).
255
256 Preanalyze_Spec_Expression
257 (Get_Pragma_Arg (Arg1), Standard_Boolean);
258
259 -- Remove the subprogram from the scope stack now that the pre-analysis
260 -- of the precondition/postcondition is done.
261
262 End_Scope;
263 end Analyze_PPC_In_Decl_Part;
264
265 --------------------
266 -- Analyze_Pragma --
267 --------------------
268
269 procedure Analyze_Pragma (N : Node_Id) is
270 Loc : constant Source_Ptr := Sloc (N);
271 Pname : constant Name_Id := Pragma_Name (N);
272 Prag_Id : Pragma_Id;
273
274 Pragma_Exit : exception;
275 -- This exception is used to exit pragma processing completely. It is
276 -- used when an error is detected, and no further processing is
277 -- required. It is also used if an earlier error has left the tree in
278 -- a state where the pragma should not be processed.
279
280 Arg_Count : Nat;
281 -- Number of pragma argument associations
282
283 Arg1 : Node_Id;
284 Arg2 : Node_Id;
285 Arg3 : Node_Id;
286 Arg4 : Node_Id;
287 -- First four pragma arguments (pragma argument association nodes, or
288 -- Empty if the corresponding argument does not exist).
289
290 type Name_List is array (Natural range <>) of Name_Id;
291 type Args_List is array (Natural range <>) of Node_Id;
292 -- Types used for arguments to Check_Arg_Order and Gather_Associations
293
294 procedure Ada_2005_Pragma;
295 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
296 -- Ada 95 mode, these are implementation defined pragmas, so should be
297 -- caught by the No_Implementation_Pragmas restriction.
298
299 procedure Ada_2012_Pragma;
300 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
301 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
302 -- should be caught by the No_Implementation_Pragmas restriction.
303
304 procedure Check_Ada_83_Warning;
305 -- Issues a warning message for the current pragma if operating in Ada
306 -- 83 mode (used for language pragmas that are not a standard part of
307 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
308 -- of 95 pragma.
309
310 procedure Check_Arg_Count (Required : Nat);
311 -- Check argument count for pragma is equal to given parameter. If not,
312 -- then issue an error message and raise Pragma_Exit.
313
314 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
315 -- Arg which can either be a pragma argument association, in which case
316 -- the check is applied to the expression of the association or an
317 -- expression directly.
318
319 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
320 -- Check that an argument has the right form for an EXTERNAL_NAME
321 -- parameter of an extended import/export pragma. The rule is that the
322 -- name must be an identifier or string literal (in Ada 83 mode) or a
323 -- static string expression (in Ada 95 mode).
324
325 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
326 -- Check the specified argument Arg to make sure that it is an
327 -- identifier. If not give error and raise Pragma_Exit.
328
329 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
330 -- Check the specified argument Arg to make sure that it is an integer
331 -- literal. If not give error and raise Pragma_Exit.
332
333 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
334 -- Check the specified argument Arg to make sure that it has the proper
335 -- syntactic form for a local name and meets the semantic requirements
336 -- for a local name. The local name is analyzed as part of the
337 -- processing for this call. In addition, the local name is required
338 -- to represent an entity at the library level.
339
340 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
341 -- Check the specified argument Arg to make sure that it has the proper
342 -- syntactic form for a local name and meets the semantic requirements
343 -- for a local name. The local name is analyzed as part of the
344 -- processing for this call.
345
346 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
347 -- Check the specified argument Arg to make sure that it is a valid
348 -- locking policy name. If not give error and raise Pragma_Exit.
349
350 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
351 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
352 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
353 -- Check the specified argument Arg to make sure that it is an
354 -- identifier whose name matches either N1 or N2 (or N3 if present).
355 -- If not then give error and raise Pragma_Exit.
356
357 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
358 -- Check the specified argument Arg to make sure that it is a valid
359 -- queuing policy name. If not give error and raise Pragma_Exit.
360
361 procedure Check_Arg_Is_Static_Expression
362 (Arg : Node_Id;
363 Typ : Entity_Id := Empty);
364 -- Check the specified argument Arg to make sure that it is a static
365 -- expression of the given type (i.e. it will be analyzed and resolved
366 -- using this type, which can be any valid argument to Resolve, e.g.
367 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
368 -- Typ is left Empty, then any static expression is allowed.
369
370 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
371 -- Check the specified argument Arg to make sure that it is a valid task
372 -- dispatching policy name. If not give error and raise Pragma_Exit.
373
374 procedure Check_Arg_Order (Names : Name_List);
375 -- Checks for an instance of two arguments with identifiers for the
376 -- current pragma which are not in the sequence indicated by Names,
377 -- and if so, generates a fatal message about bad order of arguments.
378
379 procedure Check_At_Least_N_Arguments (N : Nat);
380 -- Check there are at least N arguments present
381
382 procedure Check_At_Most_N_Arguments (N : Nat);
383 -- Check there are no more than N arguments present
384
385 procedure Check_Component
386 (Comp : Node_Id;
387 UU_Typ : Entity_Id;
388 In_Variant_Part : Boolean := False);
389 -- Examine an Unchecked_Union component for correct use of per-object
390 -- constrained subtypes, and for restrictions on finalizable components.
391 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
392 -- should be set when Comp comes from a record variant.
393
394 procedure Check_Duplicate_Pragma (E : Entity_Id);
395 -- Check if a pragma of the same name as the current pragma is already
396 -- chained as a rep pragma to the given entity. If so give a message
397 -- about the duplicate, and then raise Pragma_Exit so does not return.
398 -- Also checks for delayed aspect specification node in the chain.
399
400 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
401 -- Nam is an N_String_Literal node containing the external name set by
402 -- an Import or Export pragma (or extended Import or Export pragma).
403 -- This procedure checks for possible duplications if this is the export
404 -- case, and if found, issues an appropriate error message.
405
406 procedure Check_First_Subtype (Arg : Node_Id);
407 -- Checks that Arg, whose expression is an entity name, references a
408 -- first subtype.
409
410 procedure Check_In_Main_Program;
411 -- Common checks for pragmas that appear within a main program
412 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
413
414 procedure Check_Interrupt_Or_Attach_Handler;
415 -- Common processing for first argument of pragma Interrupt_Handler or
416 -- pragma Attach_Handler.
417
418 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
419 -- Check that pragma appears in a declarative part, or in a package
420 -- specification, i.e. that it does not occur in a statement sequence
421 -- in a body.
422
423 procedure Check_No_Identifier (Arg : Node_Id);
424 -- Checks that the given argument does not have an identifier. If
425 -- an identifier is present, then an error message is issued, and
426 -- Pragma_Exit is raised.
427
428 procedure Check_No_Identifiers;
429 -- Checks that none of the arguments to the pragma has an identifier.
430 -- If any argument has an identifier, then an error message is issued,
431 -- and Pragma_Exit is raised.
432
433 procedure Check_No_Link_Name;
434 -- Checks that no link name is specified
435
436 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
437 -- Checks if the given argument has an identifier, and if so, requires
438 -- it to match the given identifier name. If there is a non-matching
439 -- identifier, then an error message is given and Error_Pragmas raised.
440
441 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
442 -- Checks if the given argument has an identifier, and if so, requires
443 -- it to match the given identifier name. If there is a non-matching
444 -- identifier, then an error message is given and Error_Pragmas raised.
445 -- In this version of the procedure, the identifier name is given as
446 -- a string with lower case letters.
447
448 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
449 -- Called to process a precondition or postcondition pragma. There are
450 -- three cases:
451 --
452 -- The pragma appears after a subprogram spec
453 --
454 -- If the corresponding check is not enabled, the pragma is analyzed
455 -- but otherwise ignored and control returns with In_Body set False.
456 --
457 -- If the check is enabled, then the first step is to analyze the
458 -- pragma, but this is skipped if the subprogram spec appears within
459 -- a package specification (because this is the case where we delay
460 -- analysis till the end of the spec). Then (whether or not it was
461 -- analyzed), the pragma is chained to the subprogram in question
462 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
463 -- caller with In_Body set False.
464 --
465 -- The pragma appears at the start of subprogram body declarations
466 --
467 -- In this case an immediate return to the caller is made with
468 -- In_Body set True, and the pragma is NOT analyzed.
469 --
470 -- In all other cases, an error message for bad placement is given
471
472 procedure Check_Static_Constraint (Constr : Node_Id);
473 -- Constr is a constraint from an N_Subtype_Indication node from a
474 -- component constraint in an Unchecked_Union type. This routine checks
475 -- that the constraint is static as required by the restrictions for
476 -- Unchecked_Union.
477
478 procedure Check_Valid_Configuration_Pragma;
479 -- Legality checks for placement of a configuration pragma
480
481 procedure Check_Valid_Library_Unit_Pragma;
482 -- Legality checks for library unit pragmas. A special case arises for
483 -- pragmas in generic instances that come from copies of the original
484 -- library unit pragmas in the generic templates. In the case of other
485 -- than library level instantiations these can appear in contexts which
486 -- would normally be invalid (they only apply to the original template
487 -- and to library level instantiations), and they are simply ignored,
488 -- which is implemented by rewriting them as null statements.
489
490 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
491 -- Check an Unchecked_Union variant for lack of nested variants and
492 -- presence of at least one component. UU_Typ is the related Unchecked_
493 -- Union type.
494
495 procedure Error_Pragma (Msg : String);
496 pragma No_Return (Error_Pragma);
497 -- Outputs error message for current pragma. The message contains a %
498 -- that will be replaced with the pragma name, and the flag is placed
499 -- on the pragma itself. Pragma_Exit is then raised.
500
501 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
502 pragma No_Return (Error_Pragma_Arg);
503 -- Outputs error message for current pragma. The message may contain
504 -- a % that will be replaced with the pragma name. The parameter Arg
505 -- may either be a pragma argument association, in which case the flag
506 -- is placed on the expression of this association, or an expression,
507 -- in which case the flag is placed directly on the expression. The
508 -- message is placed using Error_Msg_N, so the message may also contain
509 -- an & insertion character which will reference the given Arg value.
510 -- After placing the message, Pragma_Exit is raised.
511
512 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
513 pragma No_Return (Error_Pragma_Arg);
514 -- Similar to above form of Error_Pragma_Arg except that two messages
515 -- are provided, the second is a continuation comment starting with \.
516
517 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
518 pragma No_Return (Error_Pragma_Arg_Ident);
519 -- Outputs error message for current pragma. The message may contain
520 -- a % that will be replaced with the pragma name. The parameter Arg
521 -- must be a pragma argument association with a non-empty identifier
522 -- (i.e. its Chars field must be set), and the error message is placed
523 -- on the identifier. The message is placed using Error_Msg_N so
524 -- the message may also contain an & insertion character which will
525 -- reference the identifier. After placing the message, Pragma_Exit
526 -- is raised.
527
528 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
529 pragma No_Return (Error_Pragma_Ref);
530 -- Outputs error message for current pragma. The message may contain
531 -- a % that will be replaced with the pragma name. The parameter Ref
532 -- must be an entity whose name can be referenced by & and sloc by #.
533 -- After placing the message, Pragma_Exit is raised.
534
535 function Find_Lib_Unit_Name return Entity_Id;
536 -- Used for a library unit pragma to find the entity to which the
537 -- library unit pragma applies, returns the entity found.
538
539 procedure Find_Program_Unit_Name (Id : Node_Id);
540 -- If the pragma is a compilation unit pragma, the id must denote the
541 -- compilation unit in the same compilation, and the pragma must appear
542 -- in the list of preceding or trailing pragmas. If it is a program
543 -- unit pragma that is not a compilation unit pragma, then the
544 -- identifier must be visible.
545
546 function Find_Unique_Parameterless_Procedure
547 (Name : Entity_Id;
548 Arg : Node_Id) return Entity_Id;
549 -- Used for a procedure pragma to find the unique parameterless
550 -- procedure identified by Name, returns it if it exists, otherwise
551 -- errors out and uses Arg as the pragma argument for the message.
552
553 procedure Fix_Error (Msg : in out String);
554 -- This is called prior to issuing an error message. Msg is a string
555 -- which typically contains the substring pragma. If the current pragma
556 -- comes from an aspect, each such "pragma" substring is replaced with
557 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
558 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
559
560 procedure Gather_Associations
561 (Names : Name_List;
562 Args : out Args_List);
563 -- This procedure is used to gather the arguments for a pragma that
564 -- permits arbitrary ordering of parameters using the normal rules
565 -- for named and positional parameters. The Names argument is a list
566 -- of Name_Id values that corresponds to the allowed pragma argument
567 -- association identifiers in order. The result returned in Args is
568 -- a list of corresponding expressions that are the pragma arguments.
569 -- Note that this is a list of expressions, not of pragma argument
570 -- associations (Gather_Associations has completely checked all the
571 -- optional identifiers when it returns). An entry in Args is Empty
572 -- on return if the corresponding argument is not present.
573
574 procedure GNAT_Pragma;
575 -- Called for all GNAT defined pragmas to check the relevant restriction
576 -- (No_Implementation_Pragmas).
577
578 function Is_Before_First_Decl
579 (Pragma_Node : Node_Id;
580 Decls : List_Id) return Boolean;
581 -- Return True if Pragma_Node is before the first declarative item in
582 -- Decls where Decls is the list of declarative items.
583
584 function Is_Configuration_Pragma return Boolean;
585 -- Determines if the placement of the current pragma is appropriate
586 -- for a configuration pragma.
587
588 function Is_In_Context_Clause return Boolean;
589 -- Returns True if pragma appears within the context clause of a unit,
590 -- and False for any other placement (does not generate any messages).
591
592 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
593 -- Analyzes the argument, and determines if it is a static string
594 -- expression, returns True if so, False if non-static or not String.
595
596 procedure Pragma_Misplaced;
597 pragma No_Return (Pragma_Misplaced);
598 -- Issue fatal error message for misplaced pragma
599
600 procedure Process_Atomic_Shared_Volatile;
601 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
602 -- Shared is an obsolete Ada 83 pragma, treated as being identical
603 -- in effect to pragma Atomic.
604
605 procedure Process_Compile_Time_Warning_Or_Error;
606 -- Common processing for Compile_Time_Error and Compile_Time_Warning
607
608 procedure Process_Convention
609 (C : out Convention_Id;
610 Ent : out Entity_Id);
611 -- Common processing for Convention, Interface, Import and Export.
612 -- Checks first two arguments of pragma, and sets the appropriate
613 -- convention value in the specified entity or entities. On return
614 -- C is the convention, Ent is the referenced entity.
615
616 procedure Process_Extended_Import_Export_Exception_Pragma
617 (Arg_Internal : Node_Id;
618 Arg_External : Node_Id;
619 Arg_Form : Node_Id;
620 Arg_Code : Node_Id);
621 -- Common processing for the pragmas Import/Export_Exception. The three
622 -- arguments correspond to the three named parameters of the pragma. An
623 -- argument is empty if the corresponding parameter is not present in
624 -- the pragma.
625
626 procedure Process_Extended_Import_Export_Object_Pragma
627 (Arg_Internal : Node_Id;
628 Arg_External : Node_Id;
629 Arg_Size : Node_Id);
630 -- Common processing for the pragmas Import/Export_Object. The three
631 -- arguments correspond to the three named parameters of the pragmas. An
632 -- argument is empty if the corresponding parameter is not present in
633 -- the pragma.
634
635 procedure Process_Extended_Import_Export_Internal_Arg
636 (Arg_Internal : Node_Id := Empty);
637 -- Common processing for all extended Import and Export pragmas. The
638 -- argument is the pragma parameter for the Internal argument. If
639 -- Arg_Internal is empty or inappropriate, an error message is posted.
640 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
641 -- set to identify the referenced entity.
642
643 procedure Process_Extended_Import_Export_Subprogram_Pragma
644 (Arg_Internal : Node_Id;
645 Arg_External : Node_Id;
646 Arg_Parameter_Types : Node_Id;
647 Arg_Result_Type : Node_Id := Empty;
648 Arg_Mechanism : Node_Id;
649 Arg_Result_Mechanism : Node_Id := Empty;
650 Arg_First_Optional_Parameter : Node_Id := Empty);
651 -- Common processing for all extended Import and Export pragmas applying
652 -- to subprograms. The caller omits any arguments that do not apply to
653 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
654 -- only in the Import_Function and Export_Function cases). The argument
655 -- names correspond to the allowed pragma association identifiers.
656
657 procedure Process_Generic_List;
658 -- Common processing for Share_Generic and Inline_Generic
659
660 procedure Process_Import_Or_Interface;
661 -- Common processing for Import of Interface
662
663 procedure Process_Import_Predefined_Type;
664 -- Processing for completing a type with pragma Import. This is used
665 -- to declare types that match predefined C types, especially for cases
666 -- without corresponding Ada predefined type.
667
668 procedure Process_Inline (Active : Boolean);
669 -- Common processing for Inline and Inline_Always. The parameter
670 -- indicates if the inline pragma is active, i.e. if it should actually
671 -- cause inlining to occur.
672
673 procedure Process_Interface_Name
674 (Subprogram_Def : Entity_Id;
675 Ext_Arg : Node_Id;
676 Link_Arg : Node_Id);
677 -- Given the last two arguments of pragma Import, pragma Export, or
678 -- pragma Interface_Name, performs validity checks and sets the
679 -- Interface_Name field of the given subprogram entity to the
680 -- appropriate external or link name, depending on the arguments given.
681 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
682 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
683 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
684 -- nor Link_Arg is present, the interface name is set to the default
685 -- from the subprogram name.
686
687 procedure Process_Interrupt_Or_Attach_Handler;
688 -- Common processing for Interrupt and Attach_Handler pragmas
689
690 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
691 -- Common processing for Restrictions and Restriction_Warnings pragmas.
692 -- Warn is True for Restriction_Warnings, or for Restrictions if the
693 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
694 -- is not set in the Restrictions case.
695
696 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
697 -- Common processing for Suppress and Unsuppress. The boolean parameter
698 -- Suppress_Case is True for the Suppress case, and False for the
699 -- Unsuppress case.
700
701 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
702 -- This procedure sets the Is_Exported flag for the given entity,
703 -- checking that the entity was not previously imported. Arg is
704 -- the argument that specified the entity. A check is also made
705 -- for exporting inappropriate entities.
706
707 procedure Set_Extended_Import_Export_External_Name
708 (Internal_Ent : Entity_Id;
709 Arg_External : Node_Id);
710 -- Common processing for all extended import export pragmas. The first
711 -- argument, Internal_Ent, is the internal entity, which has already
712 -- been checked for validity by the caller. Arg_External is from the
713 -- Import or Export pragma, and may be null if no External parameter
714 -- was present. If Arg_External is present and is a non-null string
715 -- (a null string is treated as the default), then the Interface_Name
716 -- field of Internal_Ent is set appropriately.
717
718 procedure Set_Imported (E : Entity_Id);
719 -- This procedure sets the Is_Imported flag for the given entity,
720 -- checking that it is not previously exported or imported.
721
722 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
723 -- Mech is a parameter passing mechanism (see Import_Function syntax
724 -- for MECHANISM_NAME). This routine checks that the mechanism argument
725 -- has the right form, and if not issues an error message. If the
726 -- argument has the right form then the Mechanism field of Ent is
727 -- set appropriately.
728
729 procedure Set_Ravenscar_Profile (N : Node_Id);
730 -- Activate the set of configuration pragmas and restrictions that make
731 -- up the Ravenscar Profile. N is the corresponding pragma node, which
732 -- is used for error messages on any constructs that violate the
733 -- profile.
734
735 ---------------------
736 -- Ada_2005_Pragma --
737 ---------------------
738
739 procedure Ada_2005_Pragma is
740 begin
741 if Ada_Version <= Ada_95 then
742 Check_Restriction (No_Implementation_Pragmas, N);
743 end if;
744 end Ada_2005_Pragma;
745
746 ---------------------
747 -- Ada_2012_Pragma --
748 ---------------------
749
750 procedure Ada_2012_Pragma is
751 begin
752 if Ada_Version <= Ada_2005 then
753 Check_Restriction (No_Implementation_Pragmas, N);
754 end if;
755 end Ada_2012_Pragma;
756
757 --------------------------
758 -- Check_Ada_83_Warning --
759 --------------------------
760
761 procedure Check_Ada_83_Warning is
762 begin
763 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
764 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
765 end if;
766 end Check_Ada_83_Warning;
767
768 ---------------------
769 -- Check_Arg_Count --
770 ---------------------
771
772 procedure Check_Arg_Count (Required : Nat) is
773 begin
774 if Arg_Count /= Required then
775 Error_Pragma ("wrong number of arguments for pragma%");
776 end if;
777 end Check_Arg_Count;
778
779 --------------------------------
780 -- Check_Arg_Is_External_Name --
781 --------------------------------
782
783 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
784 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
785
786 begin
787 if Nkind (Argx) = N_Identifier then
788 return;
789
790 else
791 Analyze_And_Resolve (Argx, Standard_String);
792
793 if Is_OK_Static_Expression (Argx) then
794 return;
795
796 elsif Etype (Argx) = Any_Type then
797 raise Pragma_Exit;
798
799 -- An interesting special case, if we have a string literal and
800 -- we are in Ada 83 mode, then we allow it even though it will
801 -- not be flagged as static. This allows expected Ada 83 mode
802 -- use of external names which are string literals, even though
803 -- technically these are not static in Ada 83.
804
805 elsif Ada_Version = Ada_83
806 and then Nkind (Argx) = N_String_Literal
807 then
808 return;
809
810 -- Static expression that raises Constraint_Error. This has
811 -- already been flagged, so just exit from pragma processing.
812
813 elsif Is_Static_Expression (Argx) then
814 raise Pragma_Exit;
815
816 -- Here we have a real error (non-static expression)
817
818 else
819 Error_Msg_Name_1 := Pname;
820
821 declare
822 Msg : String :=
823 "argument for pragma% must be a identifier or "
824 & "static string expression!";
825 begin
826 Fix_Error (Msg);
827 Flag_Non_Static_Expr (Msg, Argx);
828 raise Pragma_Exit;
829 end;
830 end if;
831 end if;
832 end Check_Arg_Is_External_Name;
833
834 -----------------------------
835 -- Check_Arg_Is_Identifier --
836 -----------------------------
837
838 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
839 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
840 begin
841 if Nkind (Argx) /= N_Identifier then
842 Error_Pragma_Arg
843 ("argument for pragma% must be identifier", Argx);
844 end if;
845 end Check_Arg_Is_Identifier;
846
847 ----------------------------------
848 -- Check_Arg_Is_Integer_Literal --
849 ----------------------------------
850
851 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
852 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
853 begin
854 if Nkind (Argx) /= N_Integer_Literal then
855 Error_Pragma_Arg
856 ("argument for pragma% must be integer literal", Argx);
857 end if;
858 end Check_Arg_Is_Integer_Literal;
859
860 -------------------------------------------
861 -- Check_Arg_Is_Library_Level_Local_Name --
862 -------------------------------------------
863
864 -- LOCAL_NAME ::=
865 -- DIRECT_NAME
866 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
867 -- | library_unit_NAME
868
869 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
870 begin
871 Check_Arg_Is_Local_Name (Arg);
872
873 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
874 and then Comes_From_Source (N)
875 then
876 Error_Pragma_Arg
877 ("argument for pragma% must be library level entity", Arg);
878 end if;
879 end Check_Arg_Is_Library_Level_Local_Name;
880
881 -----------------------------
882 -- Check_Arg_Is_Local_Name --
883 -----------------------------
884
885 -- LOCAL_NAME ::=
886 -- DIRECT_NAME
887 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
888 -- | library_unit_NAME
889
890 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
891 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
892
893 begin
894 Analyze (Argx);
895
896 if Nkind (Argx) not in N_Direct_Name
897 and then (Nkind (Argx) /= N_Attribute_Reference
898 or else Present (Expressions (Argx))
899 or else Nkind (Prefix (Argx)) /= N_Identifier)
900 and then (not Is_Entity_Name (Argx)
901 or else not Is_Compilation_Unit (Entity (Argx)))
902 then
903 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
904 end if;
905
906 -- No further check required if not an entity name
907
908 if not Is_Entity_Name (Argx) then
909 null;
910
911 else
912 declare
913 OK : Boolean;
914 Ent : constant Entity_Id := Entity (Argx);
915 Scop : constant Entity_Id := Scope (Ent);
916 begin
917 -- Case of a pragma applied to a compilation unit: pragma must
918 -- occur immediately after the program unit in the compilation.
919
920 if Is_Compilation_Unit (Ent) then
921 declare
922 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
923 begin
924 -- Case of pragma placed immediately after spec
925
926 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
927 OK := True;
928
929 -- Case of pragma placed immediately after body
930
931 elsif Nkind (Decl) = N_Subprogram_Declaration
932 and then Present (Corresponding_Body (Decl))
933 then
934 OK := Parent (N) =
935 Aux_Decls_Node
936 (Parent (Unit_Declaration_Node
937 (Corresponding_Body (Decl))));
938
939 -- All other cases are illegal
940
941 else
942 OK := False;
943 end if;
944 end;
945
946 -- Special restricted placement rule from 10.2.1(11.8/2)
947
948 elsif Is_Generic_Formal (Ent)
949 and then Prag_Id = Pragma_Preelaborable_Initialization
950 then
951 OK := List_Containing (N) =
952 Generic_Formal_Declarations
953 (Unit_Declaration_Node (Scop));
954
955 -- Default case, just check that the pragma occurs in the scope
956 -- of the entity denoted by the name.
957
958 else
959 OK := Current_Scope = Scop;
960 end if;
961
962 if not OK then
963 Error_Pragma_Arg
964 ("pragma% argument must be in same declarative part", Arg);
965 end if;
966 end;
967 end if;
968 end Check_Arg_Is_Local_Name;
969
970 ---------------------------------
971 -- Check_Arg_Is_Locking_Policy --
972 ---------------------------------
973
974 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
975 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
976
977 begin
978 Check_Arg_Is_Identifier (Argx);
979
980 if not Is_Locking_Policy_Name (Chars (Argx)) then
981 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
982 end if;
983 end Check_Arg_Is_Locking_Policy;
984
985 -------------------------
986 -- Check_Arg_Is_One_Of --
987 -------------------------
988
989 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
990 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
991
992 begin
993 Check_Arg_Is_Identifier (Argx);
994
995 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
996 Error_Msg_Name_2 := N1;
997 Error_Msg_Name_3 := N2;
998 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
999 end if;
1000 end Check_Arg_Is_One_Of;
1001
1002 procedure Check_Arg_Is_One_Of
1003 (Arg : Node_Id;
1004 N1, N2, N3 : Name_Id)
1005 is
1006 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1007
1008 begin
1009 Check_Arg_Is_Identifier (Argx);
1010
1011 if Chars (Argx) /= N1
1012 and then Chars (Argx) /= N2
1013 and then Chars (Argx) /= N3
1014 then
1015 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1016 end if;
1017 end Check_Arg_Is_One_Of;
1018
1019 procedure Check_Arg_Is_One_Of
1020 (Arg : Node_Id;
1021 N1, N2, N3, N4 : Name_Id)
1022 is
1023 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1024
1025 begin
1026 Check_Arg_Is_Identifier (Argx);
1027
1028 if Chars (Argx) /= N1
1029 and then Chars (Argx) /= N2
1030 and then Chars (Argx) /= N3
1031 and then Chars (Argx) /= N4
1032 then
1033 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1034 end if;
1035 end Check_Arg_Is_One_Of;
1036 ---------------------------------
1037 -- Check_Arg_Is_Queuing_Policy --
1038 ---------------------------------
1039
1040 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1041 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1042
1043 begin
1044 Check_Arg_Is_Identifier (Argx);
1045
1046 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1047 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1048 end if;
1049 end Check_Arg_Is_Queuing_Policy;
1050
1051 ------------------------------------
1052 -- Check_Arg_Is_Static_Expression --
1053 ------------------------------------
1054
1055 procedure Check_Arg_Is_Static_Expression
1056 (Arg : Node_Id;
1057 Typ : Entity_Id := Empty)
1058 is
1059 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1060
1061 begin
1062 if Present (Typ) then
1063 Analyze_And_Resolve (Argx, Typ);
1064 else
1065 Analyze_And_Resolve (Argx);
1066 end if;
1067
1068 if Is_OK_Static_Expression (Argx) then
1069 return;
1070
1071 elsif Etype (Argx) = Any_Type then
1072 raise Pragma_Exit;
1073
1074 -- An interesting special case, if we have a string literal and we
1075 -- are in Ada 83 mode, then we allow it even though it will not be
1076 -- flagged as static. This allows the use of Ada 95 pragmas like
1077 -- Import in Ada 83 mode. They will of course be flagged with
1078 -- warnings as usual, but will not cause errors.
1079
1080 elsif Ada_Version = Ada_83
1081 and then Nkind (Argx) = N_String_Literal
1082 then
1083 return;
1084
1085 -- Static expression that raises Constraint_Error. This has already
1086 -- been flagged, so just exit from pragma processing.
1087
1088 elsif Is_Static_Expression (Argx) then
1089 raise Pragma_Exit;
1090
1091 -- Finally, we have a real error
1092
1093 else
1094 Error_Msg_Name_1 := Pname;
1095
1096 declare
1097 Msg : String :=
1098 "argument for pragma% must be a static expression!";
1099 begin
1100 Fix_Error (Msg);
1101 Flag_Non_Static_Expr (Msg, Argx);
1102 end;
1103
1104 raise Pragma_Exit;
1105 end if;
1106 end Check_Arg_Is_Static_Expression;
1107
1108 ------------------------------------------
1109 -- Check_Arg_Is_Task_Dispatching_Policy --
1110 ------------------------------------------
1111
1112 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1113 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1114
1115 begin
1116 Check_Arg_Is_Identifier (Argx);
1117
1118 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1119 Error_Pragma_Arg
1120 ("& is not a valid task dispatching policy name", Argx);
1121 end if;
1122 end Check_Arg_Is_Task_Dispatching_Policy;
1123
1124 ---------------------
1125 -- Check_Arg_Order --
1126 ---------------------
1127
1128 procedure Check_Arg_Order (Names : Name_List) is
1129 Arg : Node_Id;
1130
1131 Highest_So_Far : Natural := 0;
1132 -- Highest index in Names seen do far
1133
1134 begin
1135 Arg := Arg1;
1136 for J in 1 .. Arg_Count loop
1137 if Chars (Arg) /= No_Name then
1138 for K in Names'Range loop
1139 if Chars (Arg) = Names (K) then
1140 if K < Highest_So_Far then
1141 Error_Msg_Name_1 := Pname;
1142 Error_Msg_N
1143 ("parameters out of order for pragma%", Arg);
1144 Error_Msg_Name_1 := Names (K);
1145 Error_Msg_Name_2 := Names (Highest_So_Far);
1146 Error_Msg_N ("\% must appear before %", Arg);
1147 raise Pragma_Exit;
1148
1149 else
1150 Highest_So_Far := K;
1151 end if;
1152 end if;
1153 end loop;
1154 end if;
1155
1156 Arg := Next (Arg);
1157 end loop;
1158 end Check_Arg_Order;
1159
1160 --------------------------------
1161 -- Check_At_Least_N_Arguments --
1162 --------------------------------
1163
1164 procedure Check_At_Least_N_Arguments (N : Nat) is
1165 begin
1166 if Arg_Count < N then
1167 Error_Pragma ("too few arguments for pragma%");
1168 end if;
1169 end Check_At_Least_N_Arguments;
1170
1171 -------------------------------
1172 -- Check_At_Most_N_Arguments --
1173 -------------------------------
1174
1175 procedure Check_At_Most_N_Arguments (N : Nat) is
1176 Arg : Node_Id;
1177 begin
1178 if Arg_Count > N then
1179 Arg := Arg1;
1180 for J in 1 .. N loop
1181 Next (Arg);
1182 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1183 end loop;
1184 end if;
1185 end Check_At_Most_N_Arguments;
1186
1187 ---------------------
1188 -- Check_Component --
1189 ---------------------
1190
1191 procedure Check_Component
1192 (Comp : Node_Id;
1193 UU_Typ : Entity_Id;
1194 In_Variant_Part : Boolean := False)
1195 is
1196 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1197 Sindic : constant Node_Id :=
1198 Subtype_Indication (Component_Definition (Comp));
1199 Typ : constant Entity_Id := Etype (Comp_Id);
1200
1201 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1202 -- Determine whether entity Id appears inside a generic body.
1203 -- Shouldn't this be in a more general place ???
1204
1205 -------------------------
1206 -- Inside_Generic_Body --
1207 -------------------------
1208
1209 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1210 S : Entity_Id;
1211
1212 begin
1213 S := Id;
1214 while Present (S) and then S /= Standard_Standard loop
1215 if Ekind (S) = E_Generic_Package
1216 and then In_Package_Body (S)
1217 then
1218 return True;
1219 end if;
1220
1221 S := Scope (S);
1222 end loop;
1223
1224 return False;
1225 end Inside_Generic_Body;
1226
1227 -- Start of processing for Check_Component
1228
1229 begin
1230 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1231 -- object constraint, then the component type shall be an Unchecked_
1232 -- Union.
1233
1234 if Nkind (Sindic) = N_Subtype_Indication
1235 and then Has_Per_Object_Constraint (Comp_Id)
1236 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1237 then
1238 Error_Msg_N
1239 ("component subtype subject to per-object constraint " &
1240 "must be an Unchecked_Union", Comp);
1241
1242 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1243 -- the body of a generic unit, or within the body of any of its
1244 -- descendant library units, no part of the type of a component
1245 -- declared in a variant_part of the unchecked union type shall be of
1246 -- a formal private type or formal private extension declared within
1247 -- the formal part of the generic unit.
1248
1249 elsif Ada_Version >= Ada_2012
1250 and then Inside_Generic_Body (UU_Typ)
1251 and then In_Variant_Part
1252 and then Is_Private_Type (Typ)
1253 and then Is_Generic_Type (Typ)
1254 then
1255 Error_Msg_N
1256 ("component of Unchecked_Union cannot be of generic type", Comp);
1257
1258 elsif Needs_Finalization (Typ) then
1259 Error_Msg_N
1260 ("component of Unchecked_Union cannot be controlled", Comp);
1261
1262 elsif Has_Task (Typ) then
1263 Error_Msg_N
1264 ("component of Unchecked_Union cannot have tasks", Comp);
1265 end if;
1266 end Check_Component;
1267
1268 ----------------------------
1269 -- Check_Duplicate_Pragma --
1270 ----------------------------
1271
1272 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1273 P : Node_Id;
1274
1275 begin
1276 -- Nothing to do if this pragma comes from an aspect specification,
1277 -- since we could not be duplicating a pragma, and we dealt with the
1278 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1279
1280 if From_Aspect_Specification (N) then
1281 return;
1282 end if;
1283
1284 -- Otherwise current pragma may duplicate previous pragma or a
1285 -- previously given aspect specification for the same pragma.
1286
1287 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1288
1289 if Present (P) then
1290 Error_Msg_Name_1 := Pragma_Name (N);
1291 Error_Msg_Sloc := Sloc (P);
1292
1293 if Nkind (P) = N_Aspect_Specification
1294 or else From_Aspect_Specification (P)
1295 then
1296 Error_Msg_NE ("aspect% for & previously given#", N, E);
1297 else
1298 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1299 end if;
1300
1301 raise Pragma_Exit;
1302 end if;
1303 end Check_Duplicate_Pragma;
1304
1305 ----------------------------------
1306 -- Check_Duplicated_Export_Name --
1307 ----------------------------------
1308
1309 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1310 String_Val : constant String_Id := Strval (Nam);
1311
1312 begin
1313 -- We are only interested in the export case, and in the case of
1314 -- generics, it is the instance, not the template, that is the
1315 -- problem (the template will generate a warning in any case).
1316
1317 if not Inside_A_Generic
1318 and then (Prag_Id = Pragma_Export
1319 or else
1320 Prag_Id = Pragma_Export_Procedure
1321 or else
1322 Prag_Id = Pragma_Export_Valued_Procedure
1323 or else
1324 Prag_Id = Pragma_Export_Function)
1325 then
1326 for J in Externals.First .. Externals.Last loop
1327 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1328 Error_Msg_Sloc := Sloc (Externals.Table (J));
1329 Error_Msg_N ("external name duplicates name given#", Nam);
1330 exit;
1331 end if;
1332 end loop;
1333
1334 Externals.Append (Nam);
1335 end if;
1336 end Check_Duplicated_Export_Name;
1337
1338 -------------------------
1339 -- Check_First_Subtype --
1340 -------------------------
1341
1342 procedure Check_First_Subtype (Arg : Node_Id) is
1343 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1344 Ent : constant Entity_Id := Entity (Argx);
1345
1346 begin
1347 if Is_First_Subtype (Ent) then
1348 null;
1349
1350 elsif Is_Type (Ent) then
1351 Error_Pragma_Arg
1352 ("pragma% cannot apply to subtype", Argx);
1353
1354 elsif Is_Object (Ent) then
1355 Error_Pragma_Arg
1356 ("pragma% cannot apply to object, requires a type", Argx);
1357
1358 else
1359 Error_Pragma_Arg
1360 ("pragma% cannot apply to&, requires a type", Argx);
1361 end if;
1362 end Check_First_Subtype;
1363
1364 ---------------------------
1365 -- Check_In_Main_Program --
1366 ---------------------------
1367
1368 procedure Check_In_Main_Program is
1369 P : constant Node_Id := Parent (N);
1370
1371 begin
1372 -- Must be at in subprogram body
1373
1374 if Nkind (P) /= N_Subprogram_Body then
1375 Error_Pragma ("% pragma allowed only in subprogram");
1376
1377 -- Otherwise warn if obviously not main program
1378
1379 elsif Present (Parameter_Specifications (Specification (P)))
1380 or else not Is_Compilation_Unit (Defining_Entity (P))
1381 then
1382 Error_Msg_Name_1 := Pname;
1383 Error_Msg_N
1384 ("?pragma% is only effective in main program", N);
1385 end if;
1386 end Check_In_Main_Program;
1387
1388 ---------------------------------------
1389 -- Check_Interrupt_Or_Attach_Handler --
1390 ---------------------------------------
1391
1392 procedure Check_Interrupt_Or_Attach_Handler is
1393 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1394 Handler_Proc, Proc_Scope : Entity_Id;
1395
1396 begin
1397 Analyze (Arg1_X);
1398
1399 if Prag_Id = Pragma_Interrupt_Handler then
1400 Check_Restriction (No_Dynamic_Attachment, N);
1401 end if;
1402
1403 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1404 Proc_Scope := Scope (Handler_Proc);
1405
1406 -- On AAMP only, a pragma Interrupt_Handler is supported for
1407 -- nonprotected parameterless procedures.
1408
1409 if not AAMP_On_Target
1410 or else Prag_Id = Pragma_Attach_Handler
1411 then
1412 if Ekind (Proc_Scope) /= E_Protected_Type then
1413 Error_Pragma_Arg
1414 ("argument of pragma% must be protected procedure", Arg1);
1415 end if;
1416
1417 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1418 Error_Pragma ("pragma% must be in protected definition");
1419 end if;
1420 end if;
1421
1422 if not Is_Library_Level_Entity (Proc_Scope)
1423 or else (AAMP_On_Target
1424 and then not Is_Library_Level_Entity (Handler_Proc))
1425 then
1426 Error_Pragma_Arg
1427 ("argument for pragma% must be library level entity", Arg1);
1428 end if;
1429
1430 -- AI05-0033: A pragma cannot appear within a generic body, because
1431 -- instance can be in a nested scope. The check that protected type
1432 -- is itself a library-level declaration is done elsewhere.
1433
1434 -- Note: we omit this check in Codepeer mode to properly handle code
1435 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1436
1437 if Inside_A_Generic then
1438 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1439 and then In_Package_Body (Scope (Current_Scope))
1440 and then not CodePeer_Mode
1441 then
1442 Error_Pragma ("pragma% cannot be used inside a generic");
1443 end if;
1444 end if;
1445 end Check_Interrupt_Or_Attach_Handler;
1446
1447 -------------------------------------------
1448 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1449 -------------------------------------------
1450
1451 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1452 P : Node_Id;
1453
1454 begin
1455 P := Parent (N);
1456 loop
1457 if No (P) then
1458 exit;
1459
1460 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1461 exit;
1462
1463 elsif Nkind_In (P, N_Package_Specification,
1464 N_Block_Statement)
1465 then
1466 return;
1467
1468 -- Note: the following tests seem a little peculiar, because
1469 -- they test for bodies, but if we were in the statement part
1470 -- of the body, we would already have hit the handled statement
1471 -- sequence, so the only way we get here is by being in the
1472 -- declarative part of the body.
1473
1474 elsif Nkind_In (P, N_Subprogram_Body,
1475 N_Package_Body,
1476 N_Task_Body,
1477 N_Entry_Body)
1478 then
1479 return;
1480 end if;
1481
1482 P := Parent (P);
1483 end loop;
1484
1485 Error_Pragma ("pragma% is not in declarative part or package spec");
1486 end Check_Is_In_Decl_Part_Or_Package_Spec;
1487
1488 -------------------------
1489 -- Check_No_Identifier --
1490 -------------------------
1491
1492 procedure Check_No_Identifier (Arg : Node_Id) is
1493 begin
1494 if Nkind (Arg) = N_Pragma_Argument_Association
1495 and then Chars (Arg) /= No_Name
1496 then
1497 Error_Pragma_Arg_Ident
1498 ("pragma% does not permit identifier& here", Arg);
1499 end if;
1500 end Check_No_Identifier;
1501
1502 --------------------------
1503 -- Check_No_Identifiers --
1504 --------------------------
1505
1506 procedure Check_No_Identifiers is
1507 Arg_Node : Node_Id;
1508 begin
1509 if Arg_Count > 0 then
1510 Arg_Node := Arg1;
1511 while Present (Arg_Node) loop
1512 Check_No_Identifier (Arg_Node);
1513 Next (Arg_Node);
1514 end loop;
1515 end if;
1516 end Check_No_Identifiers;
1517
1518 ------------------------
1519 -- Check_No_Link_Name --
1520 ------------------------
1521
1522 procedure Check_No_Link_Name is
1523 begin
1524 if Present (Arg3)
1525 and then Chars (Arg3) = Name_Link_Name
1526 then
1527 Arg4 := Arg3;
1528 end if;
1529
1530 if Present (Arg4) then
1531 Error_Pragma_Arg
1532 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1533 end if;
1534 end Check_No_Link_Name;
1535
1536 -------------------------------
1537 -- Check_Optional_Identifier --
1538 -------------------------------
1539
1540 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1541 begin
1542 if Present (Arg)
1543 and then Nkind (Arg) = N_Pragma_Argument_Association
1544 and then Chars (Arg) /= No_Name
1545 then
1546 if Chars (Arg) /= Id then
1547 Error_Msg_Name_1 := Pname;
1548 Error_Msg_Name_2 := Id;
1549 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1550 raise Pragma_Exit;
1551 end if;
1552 end if;
1553 end Check_Optional_Identifier;
1554
1555 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1556 begin
1557 Name_Buffer (1 .. Id'Length) := Id;
1558 Name_Len := Id'Length;
1559 Check_Optional_Identifier (Arg, Name_Find);
1560 end Check_Optional_Identifier;
1561
1562 --------------------------------------
1563 -- Check_Precondition_Postcondition --
1564 --------------------------------------
1565
1566 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1567 P : Node_Id;
1568 PO : Node_Id;
1569
1570 procedure Chain_PPC (PO : Node_Id);
1571 -- If PO is a subprogram declaration node (or a generic subprogram
1572 -- declaration node), then the precondition/postcondition applies
1573 -- to this subprogram and the processing for the pragma is completed.
1574 -- Otherwise the pragma is misplaced.
1575
1576 ---------------
1577 -- Chain_PPC --
1578 ---------------
1579
1580 procedure Chain_PPC (PO : Node_Id) is
1581 S : Entity_Id;
1582 P : Node_Id;
1583
1584 begin
1585 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1586 if not From_Aspect_Specification (N) then
1587 Error_Pragma
1588 ("pragma% cannot be applied to abstract subprogram");
1589
1590 elsif Class_Present (N) then
1591 null;
1592
1593 else
1594 Error_Pragma
1595 ("aspect % requires ''Class for abstract subprogram");
1596 end if;
1597
1598 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1599 N_Generic_Subprogram_Declaration,
1600 N_Entry_Declaration)
1601 then
1602 Pragma_Misplaced;
1603 end if;
1604
1605 -- Here if we have [generic] subprogram or entry declaration
1606
1607 if Nkind (PO) = N_Entry_Declaration then
1608 S := Defining_Entity (PO);
1609 else
1610 S := Defining_Unit_Name (Specification (PO));
1611 end if;
1612
1613 -- Make sure we do not have the case of a precondition pragma when
1614 -- the Pre'Class aspect is present.
1615
1616 -- We do this by looking at pragmas already chained to the entity
1617 -- since the aspect derived pragma will be put on this list first.
1618
1619 if Pragma_Name (N) = Name_Precondition then
1620 if not From_Aspect_Specification (N) then
1621 P := Spec_PPC_List (S);
1622 while Present (P) loop
1623 if Pragma_Name (P) = Name_Precondition
1624 and then From_Aspect_Specification (P)
1625 and then Class_Present (P)
1626 then
1627 Error_Msg_Sloc := Sloc (P);
1628 Error_Pragma
1629 ("pragma% not allowed, `Pre''Class` aspect given#");
1630 end if;
1631
1632 P := Next_Pragma (P);
1633 end loop;
1634 end if;
1635 end if;
1636
1637 -- Similarly check for Pre with inherited Pre'Class. Note that
1638 -- we cover the aspect case as well here.
1639
1640 if Pragma_Name (N) = Name_Precondition
1641 and then not Class_Present (N)
1642 then
1643 declare
1644 Inherited : constant Subprogram_List :=
1645 Inherited_Subprograms (S);
1646 P : Node_Id;
1647
1648 begin
1649 for J in Inherited'Range loop
1650 P := Spec_PPC_List (Inherited (J));
1651 while Present (P) loop
1652 if Pragma_Name (P) = Name_Precondition
1653 and then Class_Present (P)
1654 then
1655 Error_Msg_Sloc := Sloc (P);
1656 Error_Pragma
1657 ("pragma% not allowed, `Pre''Class` "
1658 & "aspect inherited from#");
1659 end if;
1660
1661 P := Next_Pragma (P);
1662 end loop;
1663 end loop;
1664 end;
1665 end if;
1666
1667 -- Note: we do not analyze the pragma at this point. Instead we
1668 -- delay this analysis until the end of the declarative part in
1669 -- which the pragma appears. This implements the required delay
1670 -- in this analysis, allowing forward references. The analysis
1671 -- happens at the end of Analyze_Declarations.
1672
1673 -- Chain spec PPC pragma to list for subprogram
1674
1675 Set_Next_Pragma (N, Spec_PPC_List (S));
1676 Set_Spec_PPC_List (S, N);
1677
1678 -- Return indicating spec case
1679
1680 In_Body := False;
1681 return;
1682 end Chain_PPC;
1683
1684 -- Start of processing for Check_Precondition_Postcondition
1685
1686 begin
1687 if not Is_List_Member (N) then
1688 Pragma_Misplaced;
1689 end if;
1690
1691 -- Preanalyze message argument if present. Visibility in this
1692 -- argument is established at the point of pragma occurrence.
1693
1694 if Arg_Count = 2 then
1695 Check_Optional_Identifier (Arg2, Name_Message);
1696 Preanalyze_Spec_Expression
1697 (Get_Pragma_Arg (Arg2), Standard_String);
1698 end if;
1699
1700 -- Record if pragma is enabled
1701
1702 if Check_Enabled (Pname) then
1703 Set_Pragma_Enabled (N);
1704 Set_SCO_Pragma_Enabled (Loc);
1705 end if;
1706
1707 -- If we are within an inlined body, the legality of the pragma
1708 -- has been checked already.
1709
1710 if In_Inlined_Body then
1711 In_Body := True;
1712 return;
1713 end if;
1714
1715 -- Search prior declarations
1716
1717 P := N;
1718 while Present (Prev (P)) loop
1719 P := Prev (P);
1720
1721 -- If the previous node is a generic subprogram, do not go to to
1722 -- the original node, which is the unanalyzed tree: we need to
1723 -- attach the pre/postconditions to the analyzed version at this
1724 -- point. They get propagated to the original tree when analyzing
1725 -- the corresponding body.
1726
1727 if Nkind (P) not in N_Generic_Declaration then
1728 PO := Original_Node (P);
1729 else
1730 PO := P;
1731 end if;
1732
1733 -- Skip past prior pragma
1734
1735 if Nkind (PO) = N_Pragma then
1736 null;
1737
1738 -- Skip stuff not coming from source
1739
1740 elsif not Comes_From_Source (PO) then
1741 null;
1742
1743 -- Only remaining possibility is subprogram declaration
1744
1745 else
1746 Chain_PPC (PO);
1747 return;
1748 end if;
1749 end loop;
1750
1751 -- If we fall through loop, pragma is at start of list, so see if it
1752 -- is at the start of declarations of a subprogram body.
1753
1754 if Nkind (Parent (N)) = N_Subprogram_Body
1755 and then List_Containing (N) = Declarations (Parent (N))
1756 then
1757 if Operating_Mode /= Generate_Code
1758 or else Inside_A_Generic
1759 then
1760 -- Analyze pragma expression for correctness and for ASIS use
1761
1762 Preanalyze_Spec_Expression
1763 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1764 end if;
1765
1766 In_Body := True;
1767 return;
1768
1769 -- See if it is in the pragmas after a library level subprogram
1770
1771 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1772 Chain_PPC (Unit (Parent (Parent (N))));
1773 return;
1774 end if;
1775
1776 -- If we fall through, pragma was misplaced
1777
1778 Pragma_Misplaced;
1779 end Check_Precondition_Postcondition;
1780
1781 -----------------------------
1782 -- Check_Static_Constraint --
1783 -----------------------------
1784
1785 -- Note: for convenience in writing this procedure, in addition to
1786 -- the officially (i.e. by spec) allowed argument which is always a
1787 -- constraint, it also allows ranges and discriminant associations.
1788 -- Above is not clear ???
1789
1790 procedure Check_Static_Constraint (Constr : Node_Id) is
1791
1792 procedure Require_Static (E : Node_Id);
1793 -- Require given expression to be static expression
1794
1795 --------------------
1796 -- Require_Static --
1797 --------------------
1798
1799 procedure Require_Static (E : Node_Id) is
1800 begin
1801 if not Is_OK_Static_Expression (E) then
1802 Flag_Non_Static_Expr
1803 ("non-static constraint not allowed in Unchecked_Union!", E);
1804 raise Pragma_Exit;
1805 end if;
1806 end Require_Static;
1807
1808 -- Start of processing for Check_Static_Constraint
1809
1810 begin
1811 case Nkind (Constr) is
1812 when N_Discriminant_Association =>
1813 Require_Static (Expression (Constr));
1814
1815 when N_Range =>
1816 Require_Static (Low_Bound (Constr));
1817 Require_Static (High_Bound (Constr));
1818
1819 when N_Attribute_Reference =>
1820 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1821 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1822
1823 when N_Range_Constraint =>
1824 Check_Static_Constraint (Range_Expression (Constr));
1825
1826 when N_Index_Or_Discriminant_Constraint =>
1827 declare
1828 IDC : Entity_Id;
1829 begin
1830 IDC := First (Constraints (Constr));
1831 while Present (IDC) loop
1832 Check_Static_Constraint (IDC);
1833 Next (IDC);
1834 end loop;
1835 end;
1836
1837 when others =>
1838 null;
1839 end case;
1840 end Check_Static_Constraint;
1841
1842 --------------------------------------
1843 -- Check_Valid_Configuration_Pragma --
1844 --------------------------------------
1845
1846 -- A configuration pragma must appear in the context clause of a
1847 -- compilation unit, and only other pragmas may precede it. Note that
1848 -- the test also allows use in a configuration pragma file.
1849
1850 procedure Check_Valid_Configuration_Pragma is
1851 begin
1852 if not Is_Configuration_Pragma then
1853 Error_Pragma ("incorrect placement for configuration pragma%");
1854 end if;
1855 end Check_Valid_Configuration_Pragma;
1856
1857 -------------------------------------
1858 -- Check_Valid_Library_Unit_Pragma --
1859 -------------------------------------
1860
1861 procedure Check_Valid_Library_Unit_Pragma is
1862 Plist : List_Id;
1863 Parent_Node : Node_Id;
1864 Unit_Name : Entity_Id;
1865 Unit_Kind : Node_Kind;
1866 Unit_Node : Node_Id;
1867 Sindex : Source_File_Index;
1868
1869 begin
1870 if not Is_List_Member (N) then
1871 Pragma_Misplaced;
1872
1873 else
1874 Plist := List_Containing (N);
1875 Parent_Node := Parent (Plist);
1876
1877 if Parent_Node = Empty then
1878 Pragma_Misplaced;
1879
1880 -- Case of pragma appearing after a compilation unit. In this case
1881 -- it must have an argument with the corresponding name and must
1882 -- be part of the following pragmas of its parent.
1883
1884 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1885 if Plist /= Pragmas_After (Parent_Node) then
1886 Pragma_Misplaced;
1887
1888 elsif Arg_Count = 0 then
1889 Error_Pragma
1890 ("argument required if outside compilation unit");
1891
1892 else
1893 Check_No_Identifiers;
1894 Check_Arg_Count (1);
1895 Unit_Node := Unit (Parent (Parent_Node));
1896 Unit_Kind := Nkind (Unit_Node);
1897
1898 Analyze (Get_Pragma_Arg (Arg1));
1899
1900 if Unit_Kind = N_Generic_Subprogram_Declaration
1901 or else Unit_Kind = N_Subprogram_Declaration
1902 then
1903 Unit_Name := Defining_Entity (Unit_Node);
1904
1905 elsif Unit_Kind in N_Generic_Instantiation then
1906 Unit_Name := Defining_Entity (Unit_Node);
1907
1908 else
1909 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1910 end if;
1911
1912 if Chars (Unit_Name) /=
1913 Chars (Entity (Get_Pragma_Arg (Arg1)))
1914 then
1915 Error_Pragma_Arg
1916 ("pragma% argument is not current unit name", Arg1);
1917 end if;
1918
1919 if Ekind (Unit_Name) = E_Package
1920 and then Present (Renamed_Entity (Unit_Name))
1921 then
1922 Error_Pragma ("pragma% not allowed for renamed package");
1923 end if;
1924 end if;
1925
1926 -- Pragma appears other than after a compilation unit
1927
1928 else
1929 -- Here we check for the generic instantiation case and also
1930 -- for the case of processing a generic formal package. We
1931 -- detect these cases by noting that the Sloc on the node
1932 -- does not belong to the current compilation unit.
1933
1934 Sindex := Source_Index (Current_Sem_Unit);
1935
1936 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1937 Rewrite (N, Make_Null_Statement (Loc));
1938 return;
1939
1940 -- If before first declaration, the pragma applies to the
1941 -- enclosing unit, and the name if present must be this name.
1942
1943 elsif Is_Before_First_Decl (N, Plist) then
1944 Unit_Node := Unit_Declaration_Node (Current_Scope);
1945 Unit_Kind := Nkind (Unit_Node);
1946
1947 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1948 Pragma_Misplaced;
1949
1950 elsif Unit_Kind = N_Subprogram_Body
1951 and then not Acts_As_Spec (Unit_Node)
1952 then
1953 Pragma_Misplaced;
1954
1955 elsif Nkind (Parent_Node) = N_Package_Body then
1956 Pragma_Misplaced;
1957
1958 elsif Nkind (Parent_Node) = N_Package_Specification
1959 and then Plist = Private_Declarations (Parent_Node)
1960 then
1961 Pragma_Misplaced;
1962
1963 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1964 or else Nkind (Parent_Node) =
1965 N_Generic_Subprogram_Declaration)
1966 and then Plist = Generic_Formal_Declarations (Parent_Node)
1967 then
1968 Pragma_Misplaced;
1969
1970 elsif Arg_Count > 0 then
1971 Analyze (Get_Pragma_Arg (Arg1));
1972
1973 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
1974 Error_Pragma_Arg
1975 ("name in pragma% must be enclosing unit", Arg1);
1976 end if;
1977
1978 -- It is legal to have no argument in this context
1979
1980 else
1981 return;
1982 end if;
1983
1984 -- Error if not before first declaration. This is because a
1985 -- library unit pragma argument must be the name of a library
1986 -- unit (RM 10.1.5(7)), but the only names permitted in this
1987 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1988 -- generic subprogram declarations or generic instantiations.
1989
1990 else
1991 Error_Pragma
1992 ("pragma% misplaced, must be before first declaration");
1993 end if;
1994 end if;
1995 end if;
1996 end Check_Valid_Library_Unit_Pragma;
1997
1998 -------------------
1999 -- Check_Variant --
2000 -------------------
2001
2002 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2003 Clist : constant Node_Id := Component_List (Variant);
2004 Comp : Node_Id;
2005
2006 begin
2007 if not Is_Non_Empty_List (Component_Items (Clist)) then
2008 Error_Msg_N
2009 ("Unchecked_Union may not have empty component list",
2010 Variant);
2011 return;
2012 end if;
2013
2014 Comp := First (Component_Items (Clist));
2015 while Present (Comp) loop
2016 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2017 Next (Comp);
2018 end loop;
2019 end Check_Variant;
2020
2021 ------------------
2022 -- Error_Pragma --
2023 ------------------
2024
2025 procedure Error_Pragma (Msg : String) is
2026 MsgF : String := Msg;
2027 begin
2028 Error_Msg_Name_1 := Pname;
2029 Fix_Error (MsgF);
2030 Error_Msg_N (MsgF, N);
2031 raise Pragma_Exit;
2032 end Error_Pragma;
2033
2034 ----------------------
2035 -- Error_Pragma_Arg --
2036 ----------------------
2037
2038 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2039 MsgF : String := Msg;
2040 begin
2041 Error_Msg_Name_1 := Pname;
2042 Fix_Error (MsgF);
2043 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2044 raise Pragma_Exit;
2045 end Error_Pragma_Arg;
2046
2047 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2048 MsgF : String := Msg1;
2049 begin
2050 Error_Msg_Name_1 := Pname;
2051 Fix_Error (MsgF);
2052 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2053 Error_Pragma_Arg (Msg2, Arg);
2054 end Error_Pragma_Arg;
2055
2056 ----------------------------
2057 -- Error_Pragma_Arg_Ident --
2058 ----------------------------
2059
2060 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2061 MsgF : String := Msg;
2062 begin
2063 Error_Msg_Name_1 := Pname;
2064 Fix_Error (MsgF);
2065 Error_Msg_N (MsgF, Arg);
2066 raise Pragma_Exit;
2067 end Error_Pragma_Arg_Ident;
2068
2069 ----------------------
2070 -- Error_Pragma_Ref --
2071 ----------------------
2072
2073 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2074 MsgF : String := Msg;
2075 begin
2076 Error_Msg_Name_1 := Pname;
2077 Fix_Error (MsgF);
2078 Error_Msg_Sloc := Sloc (Ref);
2079 Error_Msg_NE (MsgF, N, Ref);
2080 raise Pragma_Exit;
2081 end Error_Pragma_Ref;
2082
2083 ------------------------
2084 -- Find_Lib_Unit_Name --
2085 ------------------------
2086
2087 function Find_Lib_Unit_Name return Entity_Id is
2088 begin
2089 -- Return inner compilation unit entity, for case of nested
2090 -- categorization pragmas. This happens in generic unit.
2091
2092 if Nkind (Parent (N)) = N_Package_Specification
2093 and then Defining_Entity (Parent (N)) /= Current_Scope
2094 then
2095 return Defining_Entity (Parent (N));
2096 else
2097 return Current_Scope;
2098 end if;
2099 end Find_Lib_Unit_Name;
2100
2101 ----------------------------
2102 -- Find_Program_Unit_Name --
2103 ----------------------------
2104
2105 procedure Find_Program_Unit_Name (Id : Node_Id) is
2106 Unit_Name : Entity_Id;
2107 Unit_Kind : Node_Kind;
2108 P : constant Node_Id := Parent (N);
2109
2110 begin
2111 if Nkind (P) = N_Compilation_Unit then
2112 Unit_Kind := Nkind (Unit (P));
2113
2114 if Unit_Kind = N_Subprogram_Declaration
2115 or else Unit_Kind = N_Package_Declaration
2116 or else Unit_Kind in N_Generic_Declaration
2117 then
2118 Unit_Name := Defining_Entity (Unit (P));
2119
2120 if Chars (Id) = Chars (Unit_Name) then
2121 Set_Entity (Id, Unit_Name);
2122 Set_Etype (Id, Etype (Unit_Name));
2123 else
2124 Set_Etype (Id, Any_Type);
2125 Error_Pragma
2126 ("cannot find program unit referenced by pragma%");
2127 end if;
2128
2129 else
2130 Set_Etype (Id, Any_Type);
2131 Error_Pragma ("pragma% inapplicable to this unit");
2132 end if;
2133
2134 else
2135 Analyze (Id);
2136 end if;
2137 end Find_Program_Unit_Name;
2138
2139 -----------------------------------------
2140 -- Find_Unique_Parameterless_Procedure --
2141 -----------------------------------------
2142
2143 function Find_Unique_Parameterless_Procedure
2144 (Name : Entity_Id;
2145 Arg : Node_Id) return Entity_Id
2146 is
2147 Proc : Entity_Id := Empty;
2148
2149 begin
2150 -- The body of this procedure needs some comments ???
2151
2152 if not Is_Entity_Name (Name) then
2153 Error_Pragma_Arg
2154 ("argument of pragma% must be entity name", Arg);
2155
2156 elsif not Is_Overloaded (Name) then
2157 Proc := Entity (Name);
2158
2159 if Ekind (Proc) /= E_Procedure
2160 or else Present (First_Formal (Proc))
2161 then
2162 Error_Pragma_Arg
2163 ("argument of pragma% must be parameterless procedure", Arg);
2164 end if;
2165
2166 else
2167 declare
2168 Found : Boolean := False;
2169 It : Interp;
2170 Index : Interp_Index;
2171
2172 begin
2173 Get_First_Interp (Name, Index, It);
2174 while Present (It.Nam) loop
2175 Proc := It.Nam;
2176
2177 if Ekind (Proc) = E_Procedure
2178 and then No (First_Formal (Proc))
2179 then
2180 if not Found then
2181 Found := True;
2182 Set_Entity (Name, Proc);
2183 Set_Is_Overloaded (Name, False);
2184 else
2185 Error_Pragma_Arg
2186 ("ambiguous handler name for pragma% ", Arg);
2187 end if;
2188 end if;
2189
2190 Get_Next_Interp (Index, It);
2191 end loop;
2192
2193 if not Found then
2194 Error_Pragma_Arg
2195 ("argument of pragma% must be parameterless procedure",
2196 Arg);
2197 else
2198 Proc := Entity (Name);
2199 end if;
2200 end;
2201 end if;
2202
2203 return Proc;
2204 end Find_Unique_Parameterless_Procedure;
2205
2206 ---------------
2207 -- Fix_Error --
2208 ---------------
2209
2210 procedure Fix_Error (Msg : in out String) is
2211 begin
2212 if From_Aspect_Specification (N) then
2213 for J in Msg'First .. Msg'Last - 5 loop
2214 if Msg (J .. J + 5) = "pragma" then
2215 Msg (J .. J + 5) := "aspect";
2216 end if;
2217 end loop;
2218
2219 if Error_Msg_Name_1 = Name_Precondition then
2220 Error_Msg_Name_1 := Name_Pre;
2221 elsif Error_Msg_Name_1 = Name_Postcondition then
2222 Error_Msg_Name_1 := Name_Post;
2223 end if;
2224 end if;
2225 end Fix_Error;
2226
2227 -------------------------
2228 -- Gather_Associations --
2229 -------------------------
2230
2231 procedure Gather_Associations
2232 (Names : Name_List;
2233 Args : out Args_List)
2234 is
2235 Arg : Node_Id;
2236
2237 begin
2238 -- Initialize all parameters to Empty
2239
2240 for J in Args'Range loop
2241 Args (J) := Empty;
2242 end loop;
2243
2244 -- That's all we have to do if there are no argument associations
2245
2246 if No (Pragma_Argument_Associations (N)) then
2247 return;
2248 end if;
2249
2250 -- Otherwise first deal with any positional parameters present
2251
2252 Arg := First (Pragma_Argument_Associations (N));
2253 for Index in Args'Range loop
2254 exit when No (Arg) or else Chars (Arg) /= No_Name;
2255 Args (Index) := Get_Pragma_Arg (Arg);
2256 Next (Arg);
2257 end loop;
2258
2259 -- Positional parameters all processed, if any left, then we
2260 -- have too many positional parameters.
2261
2262 if Present (Arg) and then Chars (Arg) = No_Name then
2263 Error_Pragma_Arg
2264 ("too many positional associations for pragma%", Arg);
2265 end if;
2266
2267 -- Process named parameters if any are present
2268
2269 while Present (Arg) loop
2270 if Chars (Arg) = No_Name then
2271 Error_Pragma_Arg
2272 ("positional association cannot follow named association",
2273 Arg);
2274
2275 else
2276 for Index in Names'Range loop
2277 if Names (Index) = Chars (Arg) then
2278 if Present (Args (Index)) then
2279 Error_Pragma_Arg
2280 ("duplicate argument association for pragma%", Arg);
2281 else
2282 Args (Index) := Get_Pragma_Arg (Arg);
2283 exit;
2284 end if;
2285 end if;
2286
2287 if Index = Names'Last then
2288 Error_Msg_Name_1 := Pname;
2289 Error_Msg_N ("pragma% does not allow & argument", Arg);
2290
2291 -- Check for possible misspelling
2292
2293 for Index1 in Names'Range loop
2294 if Is_Bad_Spelling_Of
2295 (Chars (Arg), Names (Index1))
2296 then
2297 Error_Msg_Name_1 := Names (Index1);
2298 Error_Msg_N -- CODEFIX
2299 ("\possible misspelling of%", Arg);
2300 exit;
2301 end if;
2302 end loop;
2303
2304 raise Pragma_Exit;
2305 end if;
2306 end loop;
2307 end if;
2308
2309 Next (Arg);
2310 end loop;
2311 end Gather_Associations;
2312
2313 -----------------
2314 -- GNAT_Pragma --
2315 -----------------
2316
2317 procedure GNAT_Pragma is
2318 begin
2319 Check_Restriction (No_Implementation_Pragmas, N);
2320 end GNAT_Pragma;
2321
2322 --------------------------
2323 -- Is_Before_First_Decl --
2324 --------------------------
2325
2326 function Is_Before_First_Decl
2327 (Pragma_Node : Node_Id;
2328 Decls : List_Id) return Boolean
2329 is
2330 Item : Node_Id := First (Decls);
2331
2332 begin
2333 -- Only other pragmas can come before this pragma
2334
2335 loop
2336 if No (Item) or else Nkind (Item) /= N_Pragma then
2337 return False;
2338
2339 elsif Item = Pragma_Node then
2340 return True;
2341 end if;
2342
2343 Next (Item);
2344 end loop;
2345 end Is_Before_First_Decl;
2346
2347 -----------------------------
2348 -- Is_Configuration_Pragma --
2349 -----------------------------
2350
2351 -- A configuration pragma must appear in the context clause of a
2352 -- compilation unit, and only other pragmas may precede it. Note that
2353 -- the test below also permits use in a configuration pragma file.
2354
2355 function Is_Configuration_Pragma return Boolean is
2356 Lis : constant List_Id := List_Containing (N);
2357 Par : constant Node_Id := Parent (N);
2358 Prg : Node_Id;
2359
2360 begin
2361 -- If no parent, then we are in the configuration pragma file,
2362 -- so the placement is definitely appropriate.
2363
2364 if No (Par) then
2365 return True;
2366
2367 -- Otherwise we must be in the context clause of a compilation unit
2368 -- and the only thing allowed before us in the context list is more
2369 -- configuration pragmas.
2370
2371 elsif Nkind (Par) = N_Compilation_Unit
2372 and then Context_Items (Par) = Lis
2373 then
2374 Prg := First (Lis);
2375
2376 loop
2377 if Prg = N then
2378 return True;
2379 elsif Nkind (Prg) /= N_Pragma then
2380 return False;
2381 end if;
2382
2383 Next (Prg);
2384 end loop;
2385
2386 else
2387 return False;
2388 end if;
2389 end Is_Configuration_Pragma;
2390
2391 --------------------------
2392 -- Is_In_Context_Clause --
2393 --------------------------
2394
2395 function Is_In_Context_Clause return Boolean is
2396 Plist : List_Id;
2397 Parent_Node : Node_Id;
2398
2399 begin
2400 if not Is_List_Member (N) then
2401 return False;
2402
2403 else
2404 Plist := List_Containing (N);
2405 Parent_Node := Parent (Plist);
2406
2407 if Parent_Node = Empty
2408 or else Nkind (Parent_Node) /= N_Compilation_Unit
2409 or else Context_Items (Parent_Node) /= Plist
2410 then
2411 return False;
2412 end if;
2413 end if;
2414
2415 return True;
2416 end Is_In_Context_Clause;
2417
2418 ---------------------------------
2419 -- Is_Static_String_Expression --
2420 ---------------------------------
2421
2422 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2423 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2424
2425 begin
2426 Analyze_And_Resolve (Argx);
2427 return Is_OK_Static_Expression (Argx)
2428 and then Nkind (Argx) = N_String_Literal;
2429 end Is_Static_String_Expression;
2430
2431 ----------------------
2432 -- Pragma_Misplaced --
2433 ----------------------
2434
2435 procedure Pragma_Misplaced is
2436 begin
2437 Error_Pragma ("incorrect placement of pragma%");
2438 end Pragma_Misplaced;
2439
2440 ------------------------------------
2441 -- Process Atomic_Shared_Volatile --
2442 ------------------------------------
2443
2444 procedure Process_Atomic_Shared_Volatile is
2445 E_Id : Node_Id;
2446 E : Entity_Id;
2447 D : Node_Id;
2448 K : Node_Kind;
2449 Utyp : Entity_Id;
2450
2451 procedure Set_Atomic (E : Entity_Id);
2452 -- Set given type as atomic, and if no explicit alignment was given,
2453 -- set alignment to unknown, since back end knows what the alignment
2454 -- requirements are for atomic arrays. Note: this step is necessary
2455 -- for derived types.
2456
2457 ----------------
2458 -- Set_Atomic --
2459 ----------------
2460
2461 procedure Set_Atomic (E : Entity_Id) is
2462 begin
2463 Set_Is_Atomic (E);
2464
2465 if not Has_Alignment_Clause (E) then
2466 Set_Alignment (E, Uint_0);
2467 end if;
2468 end Set_Atomic;
2469
2470 -- Start of processing for Process_Atomic_Shared_Volatile
2471
2472 begin
2473 Check_Ada_83_Warning;
2474 Check_No_Identifiers;
2475 Check_Arg_Count (1);
2476 Check_Arg_Is_Local_Name (Arg1);
2477 E_Id := Get_Pragma_Arg (Arg1);
2478
2479 if Etype (E_Id) = Any_Type then
2480 return;
2481 end if;
2482
2483 E := Entity (E_Id);
2484 D := Declaration_Node (E);
2485 K := Nkind (D);
2486
2487 -- Check duplicate before we chain ourselves!
2488
2489 Check_Duplicate_Pragma (E);
2490
2491 -- Now check appropriateness of the entity
2492
2493 if Is_Type (E) then
2494 if Rep_Item_Too_Early (E, N)
2495 or else
2496 Rep_Item_Too_Late (E, N)
2497 then
2498 return;
2499 else
2500 Check_First_Subtype (Arg1);
2501 end if;
2502
2503 if Prag_Id /= Pragma_Volatile then
2504 Set_Atomic (E);
2505 Set_Atomic (Underlying_Type (E));
2506 Set_Atomic (Base_Type (E));
2507 end if;
2508
2509 -- Attribute belongs on the base type. If the view of the type is
2510 -- currently private, it also belongs on the underlying type.
2511
2512 Set_Is_Volatile (Base_Type (E));
2513 Set_Is_Volatile (Underlying_Type (E));
2514
2515 Set_Treat_As_Volatile (E);
2516 Set_Treat_As_Volatile (Underlying_Type (E));
2517
2518 elsif K = N_Object_Declaration
2519 or else (K = N_Component_Declaration
2520 and then Original_Record_Component (E) = E)
2521 then
2522 if Rep_Item_Too_Late (E, N) then
2523 return;
2524 end if;
2525
2526 if Prag_Id /= Pragma_Volatile then
2527 Set_Is_Atomic (E);
2528
2529 -- If the object declaration has an explicit initialization, a
2530 -- temporary may have to be created to hold the expression, to
2531 -- ensure that access to the object remain atomic.
2532
2533 if Nkind (Parent (E)) = N_Object_Declaration
2534 and then Present (Expression (Parent (E)))
2535 then
2536 Set_Has_Delayed_Freeze (E);
2537 end if;
2538
2539 -- An interesting improvement here. If an object of type X is
2540 -- declared atomic, and the type X is not atomic, that's a
2541 -- pity, since it may not have appropriate alignment etc. We
2542 -- can rescue this in the special case where the object and
2543 -- type are in the same unit by just setting the type as
2544 -- atomic, so that the back end will process it as atomic.
2545
2546 Utyp := Underlying_Type (Etype (E));
2547
2548 if Present (Utyp)
2549 and then Sloc (E) > No_Location
2550 and then Sloc (Utyp) > No_Location
2551 and then
2552 Get_Source_File_Index (Sloc (E)) =
2553 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2554 then
2555 Set_Is_Atomic (Underlying_Type (Etype (E)));
2556 end if;
2557 end if;
2558
2559 Set_Is_Volatile (E);
2560 Set_Treat_As_Volatile (E);
2561
2562 else
2563 Error_Pragma_Arg
2564 ("inappropriate entity for pragma%", Arg1);
2565 end if;
2566 end Process_Atomic_Shared_Volatile;
2567
2568 -------------------------------------------
2569 -- Process_Compile_Time_Warning_Or_Error --
2570 -------------------------------------------
2571
2572 procedure Process_Compile_Time_Warning_Or_Error is
2573 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2574
2575 begin
2576 Check_Arg_Count (2);
2577 Check_No_Identifiers;
2578 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2579 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2580
2581 if Compile_Time_Known_Value (Arg1x) then
2582 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2583 declare
2584 Str : constant String_Id :=
2585 Strval (Get_Pragma_Arg (Arg2));
2586 Len : constant Int := String_Length (Str);
2587 Cont : Boolean;
2588 Ptr : Nat;
2589 CC : Char_Code;
2590 C : Character;
2591 Cent : constant Entity_Id :=
2592 Cunit_Entity (Current_Sem_Unit);
2593
2594 Force : constant Boolean :=
2595 Prag_Id = Pragma_Compile_Time_Warning
2596 and then
2597 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2598 and then (Ekind (Cent) /= E_Package
2599 or else not In_Private_Part (Cent));
2600 -- Set True if this is the warning case, and we are in the
2601 -- visible part of a package spec, or in a subprogram spec,
2602 -- in which case we want to force the client to see the
2603 -- warning, even though it is not in the main unit.
2604
2605 begin
2606 -- Loop through segments of message separated by line feeds.
2607 -- We output these segments as separate messages with
2608 -- continuation marks for all but the first.
2609
2610 Cont := False;
2611 Ptr := 1;
2612 loop
2613 Error_Msg_Strlen := 0;
2614
2615 -- Loop to copy characters from argument to error message
2616 -- string buffer.
2617
2618 loop
2619 exit when Ptr > Len;
2620 CC := Get_String_Char (Str, Ptr);
2621 Ptr := Ptr + 1;
2622
2623 -- Ignore wide chars ??? else store character
2624
2625 if In_Character_Range (CC) then
2626 C := Get_Character (CC);
2627 exit when C = ASCII.LF;
2628 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2629 Error_Msg_String (Error_Msg_Strlen) := C;
2630 end if;
2631 end loop;
2632
2633 -- Here with one line ready to go
2634
2635 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2636
2637 -- If this is a warning in a spec, then we want clients
2638 -- to see the warning, so mark the message with the
2639 -- special sequence !! to force the warning. In the case
2640 -- of a package spec, we do not force this if we are in
2641 -- the private part of the spec.
2642
2643 if Force then
2644 if Cont = False then
2645 Error_Msg_N ("<~!!", Arg1);
2646 Cont := True;
2647 else
2648 Error_Msg_N ("\<~!!", Arg1);
2649 end if;
2650
2651 -- Error, rather than warning, or in a body, so we do not
2652 -- need to force visibility for client (error will be
2653 -- output in any case, and this is the situation in which
2654 -- we do not want a client to get a warning, since the
2655 -- warning is in the body or the spec private part).
2656
2657 else
2658 if Cont = False then
2659 Error_Msg_N ("<~", Arg1);
2660 Cont := True;
2661 else
2662 Error_Msg_N ("\<~", Arg1);
2663 end if;
2664 end if;
2665
2666 exit when Ptr > Len;
2667 end loop;
2668 end;
2669 end if;
2670 end if;
2671 end Process_Compile_Time_Warning_Or_Error;
2672
2673 ------------------------
2674 -- Process_Convention --
2675 ------------------------
2676
2677 procedure Process_Convention
2678 (C : out Convention_Id;
2679 Ent : out Entity_Id)
2680 is
2681 Id : Node_Id;
2682 E : Entity_Id;
2683 E1 : Entity_Id;
2684 Cname : Name_Id;
2685 Comp_Unit : Unit_Number_Type;
2686
2687 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2688 -- Called if we have more than one Export/Import/Convention pragma.
2689 -- This is generally illegal, but we have a special case of allowing
2690 -- Import and Interface to coexist if they specify the convention in
2691 -- a consistent manner. We are allowed to do this, since Interface is
2692 -- an implementation defined pragma, and we choose to do it since we
2693 -- know Rational allows this combination. S is the entity id of the
2694 -- subprogram in question. This procedure also sets the special flag
2695 -- Import_Interface_Present in both pragmas in the case where we do
2696 -- have matching Import and Interface pragmas.
2697
2698 procedure Set_Convention_From_Pragma (E : Entity_Id);
2699 -- Set convention in entity E, and also flag that the entity has a
2700 -- convention pragma. If entity is for a private or incomplete type,
2701 -- also set convention and flag on underlying type. This procedure
2702 -- also deals with the special case of C_Pass_By_Copy convention.
2703
2704 -------------------------------
2705 -- Diagnose_Multiple_Pragmas --
2706 -------------------------------
2707
2708 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2709 Pdec : constant Node_Id := Declaration_Node (S);
2710 Decl : Node_Id;
2711 Err : Boolean;
2712
2713 function Same_Convention (Decl : Node_Id) return Boolean;
2714 -- Decl is a pragma node. This function returns True if this
2715 -- pragma has a first argument that is an identifier with a
2716 -- Chars field corresponding to the Convention_Id C.
2717
2718 function Same_Name (Decl : Node_Id) return Boolean;
2719 -- Decl is a pragma node. This function returns True if this
2720 -- pragma has a second argument that is an identifier with a
2721 -- Chars field that matches the Chars of the current subprogram.
2722
2723 ---------------------
2724 -- Same_Convention --
2725 ---------------------
2726
2727 function Same_Convention (Decl : Node_Id) return Boolean is
2728 Arg1 : constant Node_Id :=
2729 First (Pragma_Argument_Associations (Decl));
2730
2731 begin
2732 if Present (Arg1) then
2733 declare
2734 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2735 begin
2736 if Nkind (Arg) = N_Identifier
2737 and then Is_Convention_Name (Chars (Arg))
2738 and then Get_Convention_Id (Chars (Arg)) = C
2739 then
2740 return True;
2741 end if;
2742 end;
2743 end if;
2744
2745 return False;
2746 end Same_Convention;
2747
2748 ---------------
2749 -- Same_Name --
2750 ---------------
2751
2752 function Same_Name (Decl : Node_Id) return Boolean is
2753 Arg1 : constant Node_Id :=
2754 First (Pragma_Argument_Associations (Decl));
2755 Arg2 : Node_Id;
2756
2757 begin
2758 if No (Arg1) then
2759 return False;
2760 end if;
2761
2762 Arg2 := Next (Arg1);
2763
2764 if No (Arg2) then
2765 return False;
2766 end if;
2767
2768 declare
2769 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2770 begin
2771 if Nkind (Arg) = N_Identifier
2772 and then Chars (Arg) = Chars (S)
2773 then
2774 return True;
2775 end if;
2776 end;
2777
2778 return False;
2779 end Same_Name;
2780
2781 -- Start of processing for Diagnose_Multiple_Pragmas
2782
2783 begin
2784 Err := True;
2785
2786 -- Definitely give message if we have Convention/Export here
2787
2788 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
2789 null;
2790
2791 -- If we have an Import or Export, scan back from pragma to
2792 -- find any previous pragma applying to the same procedure.
2793 -- The scan will be terminated by the start of the list, or
2794 -- hitting the subprogram declaration. This won't allow one
2795 -- pragma to appear in the public part and one in the private
2796 -- part, but that seems very unlikely in practice.
2797
2798 else
2799 Decl := Prev (N);
2800 while Present (Decl) and then Decl /= Pdec loop
2801
2802 -- Look for pragma with same name as us
2803
2804 if Nkind (Decl) = N_Pragma
2805 and then Same_Name (Decl)
2806 then
2807 -- Give error if same as our pragma or Export/Convention
2808
2809 if Pragma_Name (Decl) = Name_Export
2810 or else
2811 Pragma_Name (Decl) = Name_Convention
2812 or else
2813 Pragma_Name (Decl) = Pragma_Name (N)
2814 then
2815 exit;
2816
2817 -- Case of Import/Interface or the other way round
2818
2819 elsif Pragma_Name (Decl) = Name_Interface
2820 or else
2821 Pragma_Name (Decl) = Name_Import
2822 then
2823 -- Here we know that we have Import and Interface. It
2824 -- doesn't matter which way round they are. See if
2825 -- they specify the same convention. If so, all OK,
2826 -- and set special flags to stop other messages
2827
2828 if Same_Convention (Decl) then
2829 Set_Import_Interface_Present (N);
2830 Set_Import_Interface_Present (Decl);
2831 Err := False;
2832
2833 -- If different conventions, special message
2834
2835 else
2836 Error_Msg_Sloc := Sloc (Decl);
2837 Error_Pragma_Arg
2838 ("convention differs from that given#", Arg1);
2839 return;
2840 end if;
2841 end if;
2842 end if;
2843
2844 Next (Decl);
2845 end loop;
2846 end if;
2847
2848 -- Give message if needed if we fall through those tests
2849
2850 if Err then
2851 Error_Pragma_Arg
2852 ("at most one Convention/Export/Import pragma is allowed",
2853 Arg2);
2854 end if;
2855 end Diagnose_Multiple_Pragmas;
2856
2857 --------------------------------
2858 -- Set_Convention_From_Pragma --
2859 --------------------------------
2860
2861 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2862 begin
2863 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2864 -- for an overridden dispatching operation. Technically this is
2865 -- an amendment and should only be done in Ada 2005 mode. However,
2866 -- this is clearly a mistake, since the problem that is addressed
2867 -- by this AI is that there is a clear gap in the RM!
2868
2869 if Is_Dispatching_Operation (E)
2870 and then Present (Overridden_Operation (E))
2871 and then C /= Convention (Overridden_Operation (E))
2872 then
2873 Error_Pragma_Arg
2874 ("cannot change convention for " &
2875 "overridden dispatching operation",
2876 Arg1);
2877 end if;
2878
2879 -- Set the convention
2880
2881 Set_Convention (E, C);
2882 Set_Has_Convention_Pragma (E);
2883
2884 if Is_Incomplete_Or_Private_Type (E)
2885 and then Present (Underlying_Type (E))
2886 then
2887 Set_Convention (Underlying_Type (E), C);
2888 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2889 end if;
2890
2891 -- A class-wide type should inherit the convention of the specific
2892 -- root type (although this isn't specified clearly by the RM).
2893
2894 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2895 Set_Convention (Class_Wide_Type (E), C);
2896 end if;
2897
2898 -- If the entity is a record type, then check for special case of
2899 -- C_Pass_By_Copy, which is treated the same as C except that the
2900 -- special record flag is set. This convention is only permitted
2901 -- on record types (see AI95-00131).
2902
2903 if Cname = Name_C_Pass_By_Copy then
2904 if Is_Record_Type (E) then
2905 Set_C_Pass_By_Copy (Base_Type (E));
2906 elsif Is_Incomplete_Or_Private_Type (E)
2907 and then Is_Record_Type (Underlying_Type (E))
2908 then
2909 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2910 else
2911 Error_Pragma_Arg
2912 ("C_Pass_By_Copy convention allowed only for record type",
2913 Arg2);
2914 end if;
2915 end if;
2916
2917 -- If the entity is a derived boolean type, check for the special
2918 -- case of convention C, C++, or Fortran, where we consider any
2919 -- nonzero value to represent true.
2920
2921 if Is_Discrete_Type (E)
2922 and then Root_Type (Etype (E)) = Standard_Boolean
2923 and then
2924 (C = Convention_C
2925 or else
2926 C = Convention_CPP
2927 or else
2928 C = Convention_Fortran)
2929 then
2930 Set_Nonzero_Is_True (Base_Type (E));
2931 end if;
2932 end Set_Convention_From_Pragma;
2933
2934 -- Start of processing for Process_Convention
2935
2936 begin
2937 Check_At_Least_N_Arguments (2);
2938 Check_Optional_Identifier (Arg1, Name_Convention);
2939 Check_Arg_Is_Identifier (Arg1);
2940 Cname := Chars (Get_Pragma_Arg (Arg1));
2941
2942 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2943 -- tested again below to set the critical flag).
2944
2945 if Cname = Name_C_Pass_By_Copy then
2946 C := Convention_C;
2947
2948 -- Otherwise we must have something in the standard convention list
2949
2950 elsif Is_Convention_Name (Cname) then
2951 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
2952
2953 -- In DEC VMS, it seems that there is an undocumented feature that
2954 -- any unrecognized convention is treated as the default, which for
2955 -- us is convention C. It does not seem so terrible to do this
2956 -- unconditionally, silently in the VMS case, and with a warning
2957 -- in the non-VMS case.
2958
2959 else
2960 if Warn_On_Export_Import and not OpenVMS_On_Target then
2961 Error_Msg_N
2962 ("?unrecognized convention name, C assumed",
2963 Get_Pragma_Arg (Arg1));
2964 end if;
2965
2966 C := Convention_C;
2967 end if;
2968
2969 Check_Optional_Identifier (Arg2, Name_Entity);
2970 Check_Arg_Is_Local_Name (Arg2);
2971
2972 Id := Get_Pragma_Arg (Arg2);
2973 Analyze (Id);
2974
2975 if not Is_Entity_Name (Id) then
2976 Error_Pragma_Arg ("entity name required", Arg2);
2977 end if;
2978
2979 E := Entity (Id);
2980
2981 -- Set entity to return
2982
2983 Ent := E;
2984
2985 -- Go to renamed subprogram if present, since convention applies to
2986 -- the actual renamed entity, not to the renaming entity. If the
2987 -- subprogram is inherited, go to parent subprogram.
2988
2989 if Is_Subprogram (E)
2990 and then Present (Alias (E))
2991 then
2992 if Nkind (Parent (Declaration_Node (E))) =
2993 N_Subprogram_Renaming_Declaration
2994 then
2995 if Scope (E) /= Scope (Alias (E)) then
2996 Error_Pragma_Ref
2997 ("cannot apply pragma% to non-local entity&#", E);
2998 end if;
2999
3000 E := Alias (E);
3001
3002 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3003 N_Private_Extension_Declaration)
3004 and then Scope (E) = Scope (Alias (E))
3005 then
3006 E := Alias (E);
3007
3008 -- Return the parent subprogram the entity was inherited from
3009
3010 Ent := E;
3011 end if;
3012 end if;
3013
3014 -- Check that we are not applying this to a specless body
3015
3016 if Is_Subprogram (E)
3017 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3018 then
3019 Error_Pragma
3020 ("pragma% requires separate spec and must come before body");
3021 end if;
3022
3023 -- Check that we are not applying this to a named constant
3024
3025 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3026 Error_Msg_Name_1 := Pname;
3027 Error_Msg_N
3028 ("cannot apply pragma% to named constant!",
3029 Get_Pragma_Arg (Arg2));
3030 Error_Pragma_Arg
3031 ("\supply appropriate type for&!", Arg2);
3032 end if;
3033
3034 if Ekind (E) = E_Enumeration_Literal then
3035 Error_Pragma ("enumeration literal not allowed for pragma%");
3036 end if;
3037
3038 -- Check for rep item appearing too early or too late
3039
3040 if Etype (E) = Any_Type
3041 or else Rep_Item_Too_Early (E, N)
3042 then
3043 raise Pragma_Exit;
3044
3045 elsif Present (Underlying_Type (E)) then
3046 E := Underlying_Type (E);
3047 end if;
3048
3049 if Rep_Item_Too_Late (E, N) then
3050 raise Pragma_Exit;
3051 end if;
3052
3053 if Has_Convention_Pragma (E) then
3054 Diagnose_Multiple_Pragmas (E);
3055
3056 elsif Convention (E) = Convention_Protected
3057 or else Ekind (Scope (E)) = E_Protected_Type
3058 then
3059 Error_Pragma_Arg
3060 ("a protected operation cannot be given a different convention",
3061 Arg2);
3062 end if;
3063
3064 -- For Intrinsic, a subprogram is required
3065
3066 if C = Convention_Intrinsic
3067 and then not Is_Subprogram (E)
3068 and then not Is_Generic_Subprogram (E)
3069 then
3070 Error_Pragma_Arg
3071 ("second argument of pragma% must be a subprogram", Arg2);
3072 end if;
3073
3074 -- For Stdcall, a subprogram, variable or subprogram type is required
3075
3076 if C = Convention_Stdcall
3077 and then not Is_Subprogram (E)
3078 and then not Is_Generic_Subprogram (E)
3079 and then Ekind (E) /= E_Variable
3080 and then not
3081 (Is_Access_Type (E)
3082 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3083 then
3084 Error_Pragma_Arg
3085 ("second argument of pragma% must be subprogram (type)",
3086 Arg2);
3087 end if;
3088
3089 if not Is_Subprogram (E)
3090 and then not Is_Generic_Subprogram (E)
3091 then
3092 Set_Convention_From_Pragma (E);
3093
3094 if Is_Type (E) then
3095 Check_First_Subtype (Arg2);
3096 Set_Convention_From_Pragma (Base_Type (E));
3097
3098 -- For subprograms, we must set the convention on the
3099 -- internally generated directly designated type as well.
3100
3101 if Ekind (E) = E_Access_Subprogram_Type then
3102 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3103 end if;
3104 end if;
3105
3106 -- For the subprogram case, set proper convention for all homonyms
3107 -- in same scope and the same declarative part, i.e. the same
3108 -- compilation unit.
3109
3110 else
3111 Comp_Unit := Get_Source_Unit (E);
3112 Set_Convention_From_Pragma (E);
3113
3114 -- Treat a pragma Import as an implicit body, for GPS use
3115
3116 if Prag_Id = Pragma_Import then
3117 Generate_Reference (E, Id, 'b');
3118 end if;
3119
3120 -- Loop through the homonyms of the pragma argument's entity
3121
3122 E1 := Ent;
3123 loop
3124 E1 := Homonym (E1);
3125 exit when No (E1) or else Scope (E1) /= Current_Scope;
3126
3127 -- Do not set the pragma on inherited operations or on formal
3128 -- subprograms.
3129
3130 if Comes_From_Source (E1)
3131 and then Comp_Unit = Get_Source_Unit (E1)
3132 and then not Is_Formal_Subprogram (E1)
3133 and then Nkind (Original_Node (Parent (E1))) /=
3134 N_Full_Type_Declaration
3135 then
3136 if Present (Alias (E1))
3137 and then Scope (E1) /= Scope (Alias (E1))
3138 then
3139 Error_Pragma_Ref
3140 ("cannot apply pragma% to non-local entity& declared#",
3141 E1);
3142 end if;
3143
3144 Set_Convention_From_Pragma (E1);
3145
3146 if Prag_Id = Pragma_Import then
3147 Generate_Reference (E1, Id, 'b');
3148 end if;
3149 end if;
3150
3151 -- For aspect case, do NOT apply to homonyms
3152
3153 exit when From_Aspect_Specification (N);
3154 end loop;
3155 end if;
3156 end Process_Convention;
3157
3158 -----------------------------------------------------
3159 -- Process_Extended_Import_Export_Exception_Pragma --
3160 -----------------------------------------------------
3161
3162 procedure Process_Extended_Import_Export_Exception_Pragma
3163 (Arg_Internal : Node_Id;
3164 Arg_External : Node_Id;
3165 Arg_Form : Node_Id;
3166 Arg_Code : Node_Id)
3167 is
3168 Def_Id : Entity_Id;
3169 Code_Val : Uint;
3170
3171 begin
3172 if not OpenVMS_On_Target then
3173 Error_Pragma
3174 ("?pragma% ignored (applies only to Open'V'M'S)");
3175 end if;
3176
3177 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3178 Def_Id := Entity (Arg_Internal);
3179
3180 if Ekind (Def_Id) /= E_Exception then
3181 Error_Pragma_Arg
3182 ("pragma% must refer to declared exception", Arg_Internal);
3183 end if;
3184
3185 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3186
3187 if Present (Arg_Form) then
3188 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3189 end if;
3190
3191 if Present (Arg_Form)
3192 and then Chars (Arg_Form) = Name_Ada
3193 then
3194 null;
3195 else
3196 Set_Is_VMS_Exception (Def_Id);
3197 Set_Exception_Code (Def_Id, No_Uint);
3198 end if;
3199
3200 if Present (Arg_Code) then
3201 if not Is_VMS_Exception (Def_Id) then
3202 Error_Pragma_Arg
3203 ("Code option for pragma% not allowed for Ada case",
3204 Arg_Code);
3205 end if;
3206
3207 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3208 Code_Val := Expr_Value (Arg_Code);
3209
3210 if not UI_Is_In_Int_Range (Code_Val) then
3211 Error_Pragma_Arg
3212 ("Code option for pragma% must be in 32-bit range",
3213 Arg_Code);
3214
3215 else
3216 Set_Exception_Code (Def_Id, Code_Val);
3217 end if;
3218 end if;
3219 end Process_Extended_Import_Export_Exception_Pragma;
3220
3221 -------------------------------------------------
3222 -- Process_Extended_Import_Export_Internal_Arg --
3223 -------------------------------------------------
3224
3225 procedure Process_Extended_Import_Export_Internal_Arg
3226 (Arg_Internal : Node_Id := Empty)
3227 is
3228 begin
3229 if No (Arg_Internal) then
3230 Error_Pragma ("Internal parameter required for pragma%");
3231 end if;
3232
3233 if Nkind (Arg_Internal) = N_Identifier then
3234 null;
3235
3236 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3237 and then (Prag_Id = Pragma_Import_Function
3238 or else
3239 Prag_Id = Pragma_Export_Function)
3240 then
3241 null;
3242
3243 else
3244 Error_Pragma_Arg
3245 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3246 end if;
3247
3248 Check_Arg_Is_Local_Name (Arg_Internal);
3249 end Process_Extended_Import_Export_Internal_Arg;
3250
3251 --------------------------------------------------
3252 -- Process_Extended_Import_Export_Object_Pragma --
3253 --------------------------------------------------
3254
3255 procedure Process_Extended_Import_Export_Object_Pragma
3256 (Arg_Internal : Node_Id;
3257 Arg_External : Node_Id;
3258 Arg_Size : Node_Id)
3259 is
3260 Def_Id : Entity_Id;
3261
3262 begin
3263 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3264 Def_Id := Entity (Arg_Internal);
3265
3266 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3267 Error_Pragma_Arg
3268 ("pragma% must designate an object", Arg_Internal);
3269 end if;
3270
3271 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3272 or else
3273 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3274 then
3275 Error_Pragma_Arg
3276 ("previous Common/Psect_Object applies, pragma % not permitted",
3277 Arg_Internal);
3278 end if;
3279
3280 if Rep_Item_Too_Late (Def_Id, N) then
3281 raise Pragma_Exit;
3282 end if;
3283
3284 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3285
3286 if Present (Arg_Size) then
3287 Check_Arg_Is_External_Name (Arg_Size);
3288 end if;
3289
3290 -- Export_Object case
3291
3292 if Prag_Id = Pragma_Export_Object then
3293 if not Is_Library_Level_Entity (Def_Id) then
3294 Error_Pragma_Arg
3295 ("argument for pragma% must be library level entity",
3296 Arg_Internal);
3297 end if;
3298
3299 if Ekind (Current_Scope) = E_Generic_Package then
3300 Error_Pragma ("pragma& cannot appear in a generic unit");
3301 end if;
3302
3303 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3304 Error_Pragma_Arg
3305 ("exported object must have compile time known size",
3306 Arg_Internal);
3307 end if;
3308
3309 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3310 Error_Msg_N ("?duplicate Export_Object pragma", N);
3311 else
3312 Set_Exported (Def_Id, Arg_Internal);
3313 end if;
3314
3315 -- Import_Object case
3316
3317 else
3318 if Is_Concurrent_Type (Etype (Def_Id)) then
3319 Error_Pragma_Arg
3320 ("cannot use pragma% for task/protected object",
3321 Arg_Internal);
3322 end if;
3323
3324 if Ekind (Def_Id) = E_Constant then
3325 Error_Pragma_Arg
3326 ("cannot import a constant", Arg_Internal);
3327 end if;
3328
3329 if Warn_On_Export_Import
3330 and then Has_Discriminants (Etype (Def_Id))
3331 then
3332 Error_Msg_N
3333 ("imported value must be initialized?", Arg_Internal);
3334 end if;
3335
3336 if Warn_On_Export_Import
3337 and then Is_Access_Type (Etype (Def_Id))
3338 then
3339 Error_Pragma_Arg
3340 ("cannot import object of an access type?", Arg_Internal);
3341 end if;
3342
3343 if Warn_On_Export_Import
3344 and then Is_Imported (Def_Id)
3345 then
3346 Error_Msg_N
3347 ("?duplicate Import_Object pragma", N);
3348
3349 -- Check for explicit initialization present. Note that an
3350 -- initialization generated by the code generator, e.g. for an
3351 -- access type, does not count here.
3352
3353 elsif Present (Expression (Parent (Def_Id)))
3354 and then
3355 Comes_From_Source
3356 (Original_Node (Expression (Parent (Def_Id))))
3357 then
3358 Error_Msg_Sloc := Sloc (Def_Id);
3359 Error_Pragma_Arg
3360 ("imported entities cannot be initialized (RM B.1(24))",
3361 "\no initialization allowed for & declared#", Arg1);
3362 else
3363 Set_Imported (Def_Id);
3364 Note_Possible_Modification (Arg_Internal, Sure => False);
3365 end if;
3366 end if;
3367 end Process_Extended_Import_Export_Object_Pragma;
3368
3369 ------------------------------------------------------
3370 -- Process_Extended_Import_Export_Subprogram_Pragma --
3371 ------------------------------------------------------
3372
3373 procedure Process_Extended_Import_Export_Subprogram_Pragma
3374 (Arg_Internal : Node_Id;
3375 Arg_External : Node_Id;
3376 Arg_Parameter_Types : Node_Id;
3377 Arg_Result_Type : Node_Id := Empty;
3378 Arg_Mechanism : Node_Id;
3379 Arg_Result_Mechanism : Node_Id := Empty;
3380 Arg_First_Optional_Parameter : Node_Id := Empty)
3381 is
3382 Ent : Entity_Id;
3383 Def_Id : Entity_Id;
3384 Hom_Id : Entity_Id;
3385 Formal : Entity_Id;
3386 Ambiguous : Boolean;
3387 Match : Boolean;
3388 Dval : Node_Id;
3389
3390 function Same_Base_Type
3391 (Ptype : Node_Id;
3392 Formal : Entity_Id) return Boolean;
3393 -- Determines if Ptype references the type of Formal. Note that only
3394 -- the base types need to match according to the spec. Ptype here is
3395 -- the argument from the pragma, which is either a type name, or an
3396 -- access attribute.
3397
3398 --------------------
3399 -- Same_Base_Type --
3400 --------------------
3401
3402 function Same_Base_Type
3403 (Ptype : Node_Id;
3404 Formal : Entity_Id) return Boolean
3405 is
3406 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3407 Pref : Node_Id;
3408
3409 begin
3410 -- Case where pragma argument is typ'Access
3411
3412 if Nkind (Ptype) = N_Attribute_Reference
3413 and then Attribute_Name (Ptype) = Name_Access
3414 then
3415 Pref := Prefix (Ptype);
3416 Find_Type (Pref);
3417
3418 if not Is_Entity_Name (Pref)
3419 or else Entity (Pref) = Any_Type
3420 then
3421 raise Pragma_Exit;
3422 end if;
3423
3424 -- We have a match if the corresponding argument is of an
3425 -- anonymous access type, and its designated type matches the
3426 -- type of the prefix of the access attribute
3427
3428 return Ekind (Ftyp) = E_Anonymous_Access_Type
3429 and then Base_Type (Entity (Pref)) =
3430 Base_Type (Etype (Designated_Type (Ftyp)));
3431
3432 -- Case where pragma argument is a type name
3433
3434 else
3435 Find_Type (Ptype);
3436
3437 if not Is_Entity_Name (Ptype)
3438 or else Entity (Ptype) = Any_Type
3439 then
3440 raise Pragma_Exit;
3441 end if;
3442
3443 -- We have a match if the corresponding argument is of the type
3444 -- given in the pragma (comparing base types)
3445
3446 return Base_Type (Entity (Ptype)) = Ftyp;
3447 end if;
3448 end Same_Base_Type;
3449
3450 -- Start of processing for
3451 -- Process_Extended_Import_Export_Subprogram_Pragma
3452
3453 begin
3454 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3455 Ent := Empty;
3456 Ambiguous := False;
3457
3458 -- Loop through homonyms (overloadings) of the entity
3459
3460 Hom_Id := Entity (Arg_Internal);
3461 while Present (Hom_Id) loop
3462 Def_Id := Get_Base_Subprogram (Hom_Id);
3463
3464 -- We need a subprogram in the current scope
3465
3466 if not Is_Subprogram (Def_Id)
3467 or else Scope (Def_Id) /= Current_Scope
3468 then
3469 null;
3470
3471 else
3472 Match := True;
3473
3474 -- Pragma cannot apply to subprogram body
3475
3476 if Is_Subprogram (Def_Id)
3477 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3478 N_Subprogram_Body
3479 then
3480 Error_Pragma
3481 ("pragma% requires separate spec"
3482 & " and must come before body");
3483 end if;
3484
3485 -- Test result type if given, note that the result type
3486 -- parameter can only be present for the function cases.
3487
3488 if Present (Arg_Result_Type)
3489 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3490 then
3491 Match := False;
3492
3493 elsif Etype (Def_Id) /= Standard_Void_Type
3494 and then
3495 (Pname = Name_Export_Procedure
3496 or else
3497 Pname = Name_Import_Procedure)
3498 then
3499 Match := False;
3500
3501 -- Test parameter types if given. Note that this parameter
3502 -- has not been analyzed (and must not be, since it is
3503 -- semantic nonsense), so we get it as the parser left it.
3504
3505 elsif Present (Arg_Parameter_Types) then
3506 Check_Matching_Types : declare
3507 Formal : Entity_Id;
3508 Ptype : Node_Id;
3509
3510 begin
3511 Formal := First_Formal (Def_Id);
3512
3513 if Nkind (Arg_Parameter_Types) = N_Null then
3514 if Present (Formal) then
3515 Match := False;
3516 end if;
3517
3518 -- A list of one type, e.g. (List) is parsed as
3519 -- a parenthesized expression.
3520
3521 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3522 and then Paren_Count (Arg_Parameter_Types) = 1
3523 then
3524 if No (Formal)
3525 or else Present (Next_Formal (Formal))
3526 then
3527 Match := False;
3528 else
3529 Match :=
3530 Same_Base_Type (Arg_Parameter_Types, Formal);
3531 end if;
3532
3533 -- A list of more than one type is parsed as a aggregate
3534
3535 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3536 and then Paren_Count (Arg_Parameter_Types) = 0
3537 then
3538 Ptype := First (Expressions (Arg_Parameter_Types));
3539 while Present (Ptype) or else Present (Formal) loop
3540 if No (Ptype)
3541 or else No (Formal)
3542 or else not Same_Base_Type (Ptype, Formal)
3543 then
3544 Match := False;
3545 exit;
3546 else
3547 Next_Formal (Formal);
3548 Next (Ptype);
3549 end if;
3550 end loop;
3551
3552 -- Anything else is of the wrong form
3553
3554 else
3555 Error_Pragma_Arg
3556 ("wrong form for Parameter_Types parameter",
3557 Arg_Parameter_Types);
3558 end if;
3559 end Check_Matching_Types;
3560 end if;
3561
3562 -- Match is now False if the entry we found did not match
3563 -- either a supplied Parameter_Types or Result_Types argument
3564
3565 if Match then
3566 if No (Ent) then
3567 Ent := Def_Id;
3568
3569 -- Ambiguous case, the flag Ambiguous shows if we already
3570 -- detected this and output the initial messages.
3571
3572 else
3573 if not Ambiguous then
3574 Ambiguous := True;
3575 Error_Msg_Name_1 := Pname;
3576 Error_Msg_N
3577 ("pragma% does not uniquely identify subprogram!",
3578 N);
3579 Error_Msg_Sloc := Sloc (Ent);
3580 Error_Msg_N ("matching subprogram #!", N);
3581 Ent := Empty;
3582 end if;
3583
3584 Error_Msg_Sloc := Sloc (Def_Id);
3585 Error_Msg_N ("matching subprogram #!", N);
3586 end if;
3587 end if;
3588 end if;
3589
3590 Hom_Id := Homonym (Hom_Id);
3591 end loop;
3592
3593 -- See if we found an entry
3594
3595 if No (Ent) then
3596 if not Ambiguous then
3597 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3598 Error_Pragma
3599 ("pragma% cannot be given for generic subprogram");
3600 else
3601 Error_Pragma
3602 ("pragma% does not identify local subprogram");
3603 end if;
3604 end if;
3605
3606 return;
3607 end if;
3608
3609 -- Import pragmas must be for imported entities
3610
3611 if Prag_Id = Pragma_Import_Function
3612 or else
3613 Prag_Id = Pragma_Import_Procedure
3614 or else
3615 Prag_Id = Pragma_Import_Valued_Procedure
3616 then
3617 if not Is_Imported (Ent) then
3618 Error_Pragma
3619 ("pragma Import or Interface must precede pragma%");
3620 end if;
3621
3622 -- Here we have the Export case which can set the entity as exported
3623
3624 -- But does not do so if the specified external name is null, since
3625 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3626 -- compatible) to request no external name.
3627
3628 elsif Nkind (Arg_External) = N_String_Literal
3629 and then String_Length (Strval (Arg_External)) = 0
3630 then
3631 null;
3632
3633 -- In all other cases, set entity as exported
3634
3635 else
3636 Set_Exported (Ent, Arg_Internal);
3637 end if;
3638
3639 -- Special processing for Valued_Procedure cases
3640
3641 if Prag_Id = Pragma_Import_Valued_Procedure
3642 or else
3643 Prag_Id = Pragma_Export_Valued_Procedure
3644 then
3645 Formal := First_Formal (Ent);
3646
3647 if No (Formal) then
3648 Error_Pragma ("at least one parameter required for pragma%");
3649
3650 elsif Ekind (Formal) /= E_Out_Parameter then
3651 Error_Pragma ("first parameter must have mode out for pragma%");
3652
3653 else
3654 Set_Is_Valued_Procedure (Ent);
3655 end if;
3656 end if;
3657
3658 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3659
3660 -- Process Result_Mechanism argument if present. We have already
3661 -- checked that this is only allowed for the function case.
3662
3663 if Present (Arg_Result_Mechanism) then
3664 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3665 end if;
3666
3667 -- Process Mechanism parameter if present. Note that this parameter
3668 -- is not analyzed, and must not be analyzed since it is semantic
3669 -- nonsense, so we get it in exactly as the parser left it.
3670
3671 if Present (Arg_Mechanism) then
3672 declare
3673 Formal : Entity_Id;
3674 Massoc : Node_Id;
3675 Mname : Node_Id;
3676 Choice : Node_Id;
3677
3678 begin
3679 -- A single mechanism association without a formal parameter
3680 -- name is parsed as a parenthesized expression. All other
3681 -- cases are parsed as aggregates, so we rewrite the single
3682 -- parameter case as an aggregate for consistency.
3683
3684 if Nkind (Arg_Mechanism) /= N_Aggregate
3685 and then Paren_Count (Arg_Mechanism) = 1
3686 then
3687 Rewrite (Arg_Mechanism,
3688 Make_Aggregate (Sloc (Arg_Mechanism),
3689 Expressions => New_List (
3690 Relocate_Node (Arg_Mechanism))));
3691 end if;
3692
3693 -- Case of only mechanism name given, applies to all formals
3694
3695 if Nkind (Arg_Mechanism) /= N_Aggregate then
3696 Formal := First_Formal (Ent);
3697 while Present (Formal) loop
3698 Set_Mechanism_Value (Formal, Arg_Mechanism);
3699 Next_Formal (Formal);
3700 end loop;
3701
3702 -- Case of list of mechanism associations given
3703
3704 else
3705 if Null_Record_Present (Arg_Mechanism) then
3706 Error_Pragma_Arg
3707 ("inappropriate form for Mechanism parameter",
3708 Arg_Mechanism);
3709 end if;
3710
3711 -- Deal with positional ones first
3712
3713 Formal := First_Formal (Ent);
3714
3715 if Present (Expressions (Arg_Mechanism)) then
3716 Mname := First (Expressions (Arg_Mechanism));
3717 while Present (Mname) loop
3718 if No (Formal) then
3719 Error_Pragma_Arg
3720 ("too many mechanism associations", Mname);
3721 end if;
3722
3723 Set_Mechanism_Value (Formal, Mname);
3724 Next_Formal (Formal);
3725 Next (Mname);
3726 end loop;
3727 end if;
3728
3729 -- Deal with named entries
3730
3731 if Present (Component_Associations (Arg_Mechanism)) then
3732 Massoc := First (Component_Associations (Arg_Mechanism));
3733 while Present (Massoc) loop
3734 Choice := First (Choices (Massoc));
3735
3736 if Nkind (Choice) /= N_Identifier
3737 or else Present (Next (Choice))
3738 then
3739 Error_Pragma_Arg
3740 ("incorrect form for mechanism association",
3741 Massoc);
3742 end if;
3743
3744 Formal := First_Formal (Ent);
3745 loop
3746 if No (Formal) then
3747 Error_Pragma_Arg
3748 ("parameter name & not present", Choice);
3749 end if;
3750
3751 if Chars (Choice) = Chars (Formal) then
3752 Set_Mechanism_Value
3753 (Formal, Expression (Massoc));
3754
3755 -- Set entity on identifier (needed by ASIS)
3756
3757 Set_Entity (Choice, Formal);
3758
3759 exit;
3760 end if;
3761
3762 Next_Formal (Formal);
3763 end loop;
3764
3765 Next (Massoc);
3766 end loop;
3767 end if;
3768 end if;
3769 end;
3770 end if;
3771
3772 -- Process First_Optional_Parameter argument if present. We have
3773 -- already checked that this is only allowed for the Import case.
3774
3775 if Present (Arg_First_Optional_Parameter) then
3776 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3777 Error_Pragma_Arg
3778 ("first optional parameter must be formal parameter name",
3779 Arg_First_Optional_Parameter);
3780 end if;
3781
3782 Formal := First_Formal (Ent);
3783 loop
3784 if No (Formal) then
3785 Error_Pragma_Arg
3786 ("specified formal parameter& not found",
3787 Arg_First_Optional_Parameter);
3788 end if;
3789
3790 exit when Chars (Formal) =
3791 Chars (Arg_First_Optional_Parameter);
3792
3793 Next_Formal (Formal);
3794 end loop;
3795
3796 Set_First_Optional_Parameter (Ent, Formal);
3797
3798 -- Check specified and all remaining formals have right form
3799
3800 while Present (Formal) loop
3801 if Ekind (Formal) /= E_In_Parameter then
3802 Error_Msg_NE
3803 ("optional formal& is not of mode in!",
3804 Arg_First_Optional_Parameter, Formal);
3805
3806 else
3807 Dval := Default_Value (Formal);
3808
3809 if No (Dval) then
3810 Error_Msg_NE
3811 ("optional formal& does not have default value!",
3812 Arg_First_Optional_Parameter, Formal);
3813
3814 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3815 null;
3816
3817 else
3818 Error_Msg_FE
3819 ("default value for optional formal& is non-static!",
3820 Arg_First_Optional_Parameter, Formal);
3821 end if;
3822 end if;
3823
3824 Set_Is_Optional_Parameter (Formal);
3825 Next_Formal (Formal);
3826 end loop;
3827 end if;
3828 end Process_Extended_Import_Export_Subprogram_Pragma;
3829
3830 --------------------------
3831 -- Process_Generic_List --
3832 --------------------------
3833
3834 procedure Process_Generic_List is
3835 Arg : Node_Id;
3836 Exp : Node_Id;
3837
3838 begin
3839 Check_No_Identifiers;
3840 Check_At_Least_N_Arguments (1);
3841
3842 Arg := Arg1;
3843 while Present (Arg) loop
3844 Exp := Get_Pragma_Arg (Arg);
3845 Analyze (Exp);
3846
3847 if not Is_Entity_Name (Exp)
3848 or else
3849 (not Is_Generic_Instance (Entity (Exp))
3850 and then
3851 not Is_Generic_Unit (Entity (Exp)))
3852 then
3853 Error_Pragma_Arg
3854 ("pragma% argument must be name of generic unit/instance",
3855 Arg);
3856 end if;
3857
3858 Next (Arg);
3859 end loop;
3860 end Process_Generic_List;
3861
3862 ------------------------------------
3863 -- Process_Import_Predefined_Type --
3864 ------------------------------------
3865
3866 procedure Process_Import_Predefined_Type is
3867 Loc : constant Source_Ptr := Sloc (N);
3868 Elmt : Elmt_Id;
3869 Ftyp : Node_Id := Empty;
3870 Decl : Node_Id;
3871 Def : Node_Id;
3872 Nam : Name_Id;
3873
3874 begin
3875 String_To_Name_Buffer (Strval (Expression (Arg3)));
3876 Nam := Name_Find;
3877
3878 Elmt := First_Elmt (Predefined_Float_Types);
3879 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
3880 Next_Elmt (Elmt);
3881 end loop;
3882
3883 Ftyp := Node (Elmt);
3884
3885 if Present (Ftyp) then
3886
3887 -- Don't build a derived type declaration, because predefined C
3888 -- types have no declaration anywhere, so cannot really be named.
3889 -- Instead build a full type declaration, starting with an
3890 -- appropriate type definition is built
3891
3892 if Is_Floating_Point_Type (Ftyp) then
3893 Def := Make_Floating_Point_Definition (Loc,
3894 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
3895 Make_Real_Range_Specification (Loc,
3896 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
3897 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
3898
3899 -- Should never have a predefined type we cannot handle
3900
3901 else
3902 raise Program_Error;
3903 end if;
3904
3905 -- Build and insert a Full_Type_Declaration, which will be
3906 -- analyzed as soon as this list entry has been analyzed.
3907
3908 Decl := Make_Full_Type_Declaration (Loc,
3909 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
3910 Type_Definition => Def);
3911
3912 Insert_After (N, Decl);
3913 Mark_Rewrite_Insertion (Decl);
3914
3915 else
3916 Error_Pragma_Arg ("no matching type found for pragma%",
3917 Arg2);
3918 end if;
3919 end Process_Import_Predefined_Type;
3920
3921 ---------------------------------
3922 -- Process_Import_Or_Interface --
3923 ---------------------------------
3924
3925 procedure Process_Import_Or_Interface is
3926 C : Convention_Id;
3927 Def_Id : Entity_Id;
3928 Hom_Id : Entity_Id;
3929
3930 begin
3931 Process_Convention (C, Def_Id);
3932 Kill_Size_Check_Code (Def_Id);
3933 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
3934
3935 if Ekind_In (Def_Id, E_Variable, E_Constant) then
3936
3937 -- We do not permit Import to apply to a renaming declaration
3938
3939 if Present (Renamed_Object (Def_Id)) then
3940 Error_Pragma_Arg
3941 ("pragma% not allowed for object renaming", Arg2);
3942
3943 -- User initialization is not allowed for imported object, but
3944 -- the object declaration may contain a default initialization,
3945 -- that will be discarded. Note that an explicit initialization
3946 -- only counts if it comes from source, otherwise it is simply
3947 -- the code generator making an implicit initialization explicit.
3948
3949 elsif Present (Expression (Parent (Def_Id)))
3950 and then Comes_From_Source (Expression (Parent (Def_Id)))
3951 then
3952 Error_Msg_Sloc := Sloc (Def_Id);
3953 Error_Pragma_Arg
3954 ("no initialization allowed for declaration of& #",
3955 "\imported entities cannot be initialized (RM B.1(24))",
3956 Arg2);
3957
3958 else
3959 Set_Imported (Def_Id);
3960 Process_Interface_Name (Def_Id, Arg3, Arg4);
3961
3962 -- Note that we do not set Is_Public here. That's because we
3963 -- only want to set it if there is no address clause, and we
3964 -- don't know that yet, so we delay that processing till
3965 -- freeze time.
3966
3967 -- pragma Import completes deferred constants
3968
3969 if Ekind (Def_Id) = E_Constant then
3970 Set_Has_Completion (Def_Id);
3971 end if;
3972
3973 -- It is not possible to import a constant of an unconstrained
3974 -- array type (e.g. string) because there is no simple way to
3975 -- write a meaningful subtype for it.
3976
3977 if Is_Array_Type (Etype (Def_Id))
3978 and then not Is_Constrained (Etype (Def_Id))
3979 then
3980 Error_Msg_NE
3981 ("imported constant& must have a constrained subtype",
3982 N, Def_Id);
3983 end if;
3984 end if;
3985
3986 elsif Is_Subprogram (Def_Id)
3987 or else Is_Generic_Subprogram (Def_Id)
3988 then
3989 -- If the name is overloaded, pragma applies to all of the denoted
3990 -- entities in the same declarative part.
3991
3992 Hom_Id := Def_Id;
3993 while Present (Hom_Id) loop
3994 Def_Id := Get_Base_Subprogram (Hom_Id);
3995
3996 -- Ignore inherited subprograms because the pragma will apply
3997 -- to the parent operation, which is the one called.
3998
3999 if Is_Overloadable (Def_Id)
4000 and then Present (Alias (Def_Id))
4001 then
4002 null;
4003
4004 -- If it is not a subprogram, it must be in an outer scope and
4005 -- pragma does not apply.
4006
4007 elsif not Is_Subprogram (Def_Id)
4008 and then not Is_Generic_Subprogram (Def_Id)
4009 then
4010 null;
4011
4012 -- The pragma does not apply to primitives of interfaces
4013
4014 elsif Is_Dispatching_Operation (Def_Id)
4015 and then Present (Find_Dispatching_Type (Def_Id))
4016 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4017 then
4018 null;
4019
4020 -- Verify that the homonym is in the same declarative part (not
4021 -- just the same scope).
4022
4023 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4024 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4025 then
4026 exit;
4027
4028 else
4029 Set_Imported (Def_Id);
4030
4031 -- Reject an Import applied to an abstract subprogram
4032
4033 if Is_Subprogram (Def_Id)
4034 and then Is_Abstract_Subprogram (Def_Id)
4035 then
4036 Error_Msg_Sloc := Sloc (Def_Id);
4037 Error_Msg_NE
4038 ("cannot import abstract subprogram& declared#",
4039 Arg2, Def_Id);
4040 end if;
4041
4042 -- Special processing for Convention_Intrinsic
4043
4044 if C = Convention_Intrinsic then
4045
4046 -- Link_Name argument not allowed for intrinsic
4047
4048 Check_No_Link_Name;
4049
4050 Set_Is_Intrinsic_Subprogram (Def_Id);
4051
4052 -- If no external name is present, then check that this
4053 -- is a valid intrinsic subprogram. If an external name
4054 -- is present, then this is handled by the back end.
4055
4056 if No (Arg3) then
4057 Check_Intrinsic_Subprogram
4058 (Def_Id, Get_Pragma_Arg (Arg2));
4059 end if;
4060 end if;
4061
4062 -- All interfaced procedures need an external symbol created
4063 -- for them since they are always referenced from another
4064 -- object file.
4065
4066 Set_Is_Public (Def_Id);
4067
4068 -- Verify that the subprogram does not have a completion
4069 -- through a renaming declaration. For other completions the
4070 -- pragma appears as a too late representation.
4071
4072 declare
4073 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4074
4075 begin
4076 if Present (Decl)
4077 and then Nkind (Decl) = N_Subprogram_Declaration
4078 and then Present (Corresponding_Body (Decl))
4079 and then Nkind (Unit_Declaration_Node
4080 (Corresponding_Body (Decl))) =
4081 N_Subprogram_Renaming_Declaration
4082 then
4083 Error_Msg_Sloc := Sloc (Def_Id);
4084 Error_Msg_NE
4085 ("cannot import&, renaming already provided for " &
4086 "declaration #", N, Def_Id);
4087 end if;
4088 end;
4089
4090 Set_Has_Completion (Def_Id);
4091 Process_Interface_Name (Def_Id, Arg3, Arg4);
4092 end if;
4093
4094 if Is_Compilation_Unit (Hom_Id) then
4095
4096 -- Its possible homonyms are not affected by the pragma.
4097 -- Such homonyms might be present in the context of other
4098 -- units being compiled.
4099
4100 exit;
4101
4102 else
4103 Hom_Id := Homonym (Hom_Id);
4104 end if;
4105 end loop;
4106
4107 -- When the convention is Java or CIL, we also allow Import to be
4108 -- given for packages, generic packages, exceptions, record
4109 -- components, and access to subprograms.
4110
4111 elsif (C = Convention_Java or else C = Convention_CIL)
4112 and then
4113 (Is_Package_Or_Generic_Package (Def_Id)
4114 or else Ekind (Def_Id) = E_Exception
4115 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4116 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4117 then
4118 Set_Imported (Def_Id);
4119 Set_Is_Public (Def_Id);
4120 Process_Interface_Name (Def_Id, Arg3, Arg4);
4121
4122 -- Import a CPP class
4123
4124 elsif Is_Record_Type (Def_Id)
4125 and then C = Convention_CPP
4126 then
4127 -- Types treated as CPP classes are treated as limited, but we
4128 -- don't require them to be declared this way. A warning is issued
4129 -- to encourage the user to declare them as limited. This is not
4130 -- an error, for compatibility reasons, because these types have
4131 -- been supported this way for some time.
4132
4133 if not Is_Limited_Type (Def_Id) then
4134 Error_Msg_N
4135 ("imported 'C'P'P type should be " &
4136 "explicitly declared limited?",
4137 Get_Pragma_Arg (Arg2));
4138 Error_Msg_N
4139 ("\type will be considered limited",
4140 Get_Pragma_Arg (Arg2));
4141 end if;
4142
4143 Set_Is_CPP_Class (Def_Id);
4144 Set_Is_Limited_Record (Def_Id);
4145
4146 -- Imported CPP types must not have discriminants (because C++
4147 -- classes do not have discriminants).
4148
4149 if Has_Discriminants (Def_Id) then
4150 Error_Msg_N
4151 ("imported 'C'P'P type cannot have discriminants",
4152 First (Discriminant_Specifications
4153 (Declaration_Node (Def_Id))));
4154 end if;
4155
4156 -- Components of imported CPP types must not have default
4157 -- expressions because the constructor (if any) is on the
4158 -- C++ side.
4159
4160 declare
4161 Tdef : constant Node_Id :=
4162 Type_Definition (Declaration_Node (Def_Id));
4163 Clist : Node_Id;
4164 Comp : Node_Id;
4165
4166 begin
4167 if Nkind (Tdef) = N_Record_Definition then
4168 Clist := Component_List (Tdef);
4169
4170 else
4171 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4172 Clist := Component_List (Record_Extension_Part (Tdef));
4173 end if;
4174
4175 if Present (Clist) then
4176 Comp := First (Component_Items (Clist));
4177 while Present (Comp) loop
4178 if Present (Expression (Comp)) then
4179 Error_Msg_N
4180 ("component of imported 'C'P'P type cannot have" &
4181 " default expression", Expression (Comp));
4182 end if;
4183
4184 Next (Comp);
4185 end loop;
4186 end if;
4187 end;
4188
4189 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4190 Check_No_Link_Name;
4191 Check_Arg_Count (3);
4192 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4193
4194 Process_Import_Predefined_Type;
4195
4196 else
4197 Error_Pragma_Arg
4198 ("second argument of pragma% must be object, subprogram" &
4199 " or incomplete type",
4200 Arg2);
4201 end if;
4202
4203 -- If this pragma applies to a compilation unit, then the unit, which
4204 -- is a subprogram, does not require (or allow) a body. We also do
4205 -- not need to elaborate imported procedures.
4206
4207 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4208 declare
4209 Cunit : constant Node_Id := Parent (Parent (N));
4210 begin
4211 Set_Body_Required (Cunit, False);
4212 end;
4213 end if;
4214 end Process_Import_Or_Interface;
4215
4216 --------------------
4217 -- Process_Inline --
4218 --------------------
4219
4220 procedure Process_Inline (Active : Boolean) is
4221 Assoc : Node_Id;
4222 Decl : Node_Id;
4223 Subp_Id : Node_Id;
4224 Subp : Entity_Id;
4225 Applies : Boolean;
4226
4227 Effective : Boolean := False;
4228 -- Set True if inline has some effect, i.e. if there is at least one
4229 -- subprogram set as inlined as a result of the use of the pragma.
4230
4231 procedure Make_Inline (Subp : Entity_Id);
4232 -- Subp is the defining unit name of the subprogram declaration. Set
4233 -- the flag, as well as the flag in the corresponding body, if there
4234 -- is one present.
4235
4236 procedure Set_Inline_Flags (Subp : Entity_Id);
4237 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4238 -- Has_Pragma_Inline_Always for the Inline_Always case.
4239
4240 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4241 -- Returns True if it can be determined at this stage that inlining
4242 -- is not possible, for example if the body is available and contains
4243 -- exception handlers, we prevent inlining, since otherwise we can
4244 -- get undefined symbols at link time. This function also emits a
4245 -- warning if front-end inlining is enabled and the pragma appears
4246 -- too late.
4247 --
4248 -- ??? is business with link symbols still valid, or does it relate
4249 -- to front end ZCX which is being phased out ???
4250
4251 ---------------------------
4252 -- Inlining_Not_Possible --
4253 ---------------------------
4254
4255 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4256 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4257 Stats : Node_Id;
4258
4259 begin
4260 if Nkind (Decl) = N_Subprogram_Body then
4261 Stats := Handled_Statement_Sequence (Decl);
4262 return Present (Exception_Handlers (Stats))
4263 or else Present (At_End_Proc (Stats));
4264
4265 elsif Nkind (Decl) = N_Subprogram_Declaration
4266 and then Present (Corresponding_Body (Decl))
4267 then
4268 if Front_End_Inlining
4269 and then Analyzed (Corresponding_Body (Decl))
4270 then
4271 Error_Msg_N ("pragma appears too late, ignored?", N);
4272 return True;
4273
4274 -- If the subprogram is a renaming as body, the body is just a
4275 -- call to the renamed subprogram, and inlining is trivially
4276 -- possible.
4277
4278 elsif
4279 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4280 N_Subprogram_Renaming_Declaration
4281 then
4282 return False;
4283
4284 else
4285 Stats :=
4286 Handled_Statement_Sequence
4287 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4288
4289 return
4290 Present (Exception_Handlers (Stats))
4291 or else Present (At_End_Proc (Stats));
4292 end if;
4293
4294 else
4295 -- If body is not available, assume the best, the check is
4296 -- performed again when compiling enclosing package bodies.
4297
4298 return False;
4299 end if;
4300 end Inlining_Not_Possible;
4301
4302 -----------------
4303 -- Make_Inline --
4304 -----------------
4305
4306 procedure Make_Inline (Subp : Entity_Id) is
4307 Kind : constant Entity_Kind := Ekind (Subp);
4308 Inner_Subp : Entity_Id := Subp;
4309
4310 begin
4311 -- Ignore if bad type, avoid cascaded error
4312
4313 if Etype (Subp) = Any_Type then
4314 Applies := True;
4315 return;
4316
4317 -- Ignore if all inlining is suppressed
4318
4319 elsif Suppress_All_Inlining then
4320 Applies := True;
4321 return;
4322
4323 -- If inlining is not possible, for now do not treat as an error
4324
4325 elsif Inlining_Not_Possible (Subp) then
4326 Applies := True;
4327 return;
4328
4329 -- Here we have a candidate for inlining, but we must exclude
4330 -- derived operations. Otherwise we would end up trying to inline
4331 -- a phantom declaration, and the result would be to drag in a
4332 -- body which has no direct inlining associated with it. That
4333 -- would not only be inefficient but would also result in the
4334 -- backend doing cross-unit inlining in cases where it was
4335 -- definitely inappropriate to do so.
4336
4337 -- However, a simple Comes_From_Source test is insufficient, since
4338 -- we do want to allow inlining of generic instances which also do
4339 -- not come from source. We also need to recognize specs generated
4340 -- by the front-end for bodies that carry the pragma. Finally,
4341 -- predefined operators do not come from source but are not
4342 -- inlineable either.
4343
4344 elsif Is_Generic_Instance (Subp)
4345 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4346 then
4347 null;
4348
4349 elsif not Comes_From_Source (Subp)
4350 and then Scope (Subp) /= Standard_Standard
4351 then
4352 Applies := True;
4353 return;
4354 end if;
4355
4356 -- The referenced entity must either be the enclosing entity, or
4357 -- an entity declared within the current open scope.
4358
4359 if Present (Scope (Subp))
4360 and then Scope (Subp) /= Current_Scope
4361 and then Subp /= Current_Scope
4362 then
4363 Error_Pragma_Arg
4364 ("argument of% must be entity in current scope", Assoc);
4365 return;
4366 end if;
4367
4368 -- Processing for procedure, operator or function. If subprogram
4369 -- is aliased (as for an instance) indicate that the renamed
4370 -- entity (if declared in the same unit) is inlined.
4371
4372 if Is_Subprogram (Subp) then
4373 Inner_Subp := Ultimate_Alias (Inner_Subp);
4374
4375 if In_Same_Source_Unit (Subp, Inner_Subp) then
4376 Set_Inline_Flags (Inner_Subp);
4377
4378 Decl := Parent (Parent (Inner_Subp));
4379
4380 if Nkind (Decl) = N_Subprogram_Declaration
4381 and then Present (Corresponding_Body (Decl))
4382 then
4383 Set_Inline_Flags (Corresponding_Body (Decl));
4384
4385 elsif Is_Generic_Instance (Subp) then
4386
4387 -- Indicate that the body needs to be created for
4388 -- inlining subsequent calls. The instantiation node
4389 -- follows the declaration of the wrapper package
4390 -- created for it.
4391
4392 if Scope (Subp) /= Standard_Standard
4393 and then
4394 Need_Subprogram_Instance_Body
4395 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4396 Subp)
4397 then
4398 null;
4399 end if;
4400 end if;
4401 end if;
4402
4403 Applies := True;
4404
4405 -- For a generic subprogram set flag as well, for use at the point
4406 -- of instantiation, to determine whether the body should be
4407 -- generated.
4408
4409 elsif Is_Generic_Subprogram (Subp) then
4410 Set_Inline_Flags (Subp);
4411 Applies := True;
4412
4413 -- Literals are by definition inlined
4414
4415 elsif Kind = E_Enumeration_Literal then
4416 null;
4417
4418 -- Anything else is an error
4419
4420 else
4421 Error_Pragma_Arg
4422 ("expect subprogram name for pragma%", Assoc);
4423 end if;
4424 end Make_Inline;
4425
4426 ----------------------
4427 -- Set_Inline_Flags --
4428 ----------------------
4429
4430 procedure Set_Inline_Flags (Subp : Entity_Id) is
4431 begin
4432 if Active then
4433 Set_Is_Inlined (Subp);
4434 end if;
4435
4436 if not Has_Pragma_Inline (Subp) then
4437 Set_Has_Pragma_Inline (Subp);
4438 Effective := True;
4439 end if;
4440
4441 if Prag_Id = Pragma_Inline_Always then
4442 Set_Has_Pragma_Inline_Always (Subp);
4443 end if;
4444 end Set_Inline_Flags;
4445
4446 -- Start of processing for Process_Inline
4447
4448 begin
4449 Check_No_Identifiers;
4450 Check_At_Least_N_Arguments (1);
4451
4452 if Active then
4453 Inline_Processing_Required := True;
4454 end if;
4455
4456 Assoc := Arg1;
4457 while Present (Assoc) loop
4458 Subp_Id := Get_Pragma_Arg (Assoc);
4459 Analyze (Subp_Id);
4460 Applies := False;
4461
4462 if Is_Entity_Name (Subp_Id) then
4463 Subp := Entity (Subp_Id);
4464
4465 if Subp = Any_Id then
4466
4467 -- If previous error, avoid cascaded errors
4468
4469 Applies := True;
4470 Effective := True;
4471
4472 else
4473 Make_Inline (Subp);
4474
4475 -- For the pragma case, climb homonym chain. This is
4476 -- what implements allowing the pragma in the renaming
4477 -- case, with the result applying to the ancestors.
4478
4479 if not From_Aspect_Specification (N) then
4480 while Present (Homonym (Subp))
4481 and then Scope (Homonym (Subp)) = Current_Scope
4482 loop
4483 Make_Inline (Homonym (Subp));
4484 Subp := Homonym (Subp);
4485 end loop;
4486 end if;
4487 end if;
4488 end if;
4489
4490 if not Applies then
4491 Error_Pragma_Arg
4492 ("inappropriate argument for pragma%", Assoc);
4493
4494 elsif not Effective
4495 and then Warn_On_Redundant_Constructs
4496 and then not Suppress_All_Inlining
4497 then
4498 if Inlining_Not_Possible (Subp) then
4499 Error_Msg_NE
4500 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4501 else
4502 Error_Msg_NE
4503 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4504 end if;
4505 end if;
4506
4507 Next (Assoc);
4508 end loop;
4509 end Process_Inline;
4510
4511 ----------------------------
4512 -- Process_Interface_Name --
4513 ----------------------------
4514
4515 procedure Process_Interface_Name
4516 (Subprogram_Def : Entity_Id;
4517 Ext_Arg : Node_Id;
4518 Link_Arg : Node_Id)
4519 is
4520 Ext_Nam : Node_Id;
4521 Link_Nam : Node_Id;
4522 String_Val : String_Id;
4523
4524 procedure Check_Form_Of_Interface_Name
4525 (SN : Node_Id;
4526 Ext_Name_Case : Boolean);
4527 -- SN is a string literal node for an interface name. This routine
4528 -- performs some minimal checks that the name is reasonable. In
4529 -- particular that no spaces or other obviously incorrect characters
4530 -- appear. This is only a warning, since any characters are allowed.
4531 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4532
4533 ----------------------------------
4534 -- Check_Form_Of_Interface_Name --
4535 ----------------------------------
4536
4537 procedure Check_Form_Of_Interface_Name
4538 (SN : Node_Id;
4539 Ext_Name_Case : Boolean)
4540 is
4541 S : constant String_Id := Strval (Expr_Value_S (SN));
4542 SL : constant Nat := String_Length (S);
4543 C : Char_Code;
4544
4545 begin
4546 if SL = 0 then
4547 Error_Msg_N ("interface name cannot be null string", SN);
4548 end if;
4549
4550 for J in 1 .. SL loop
4551 C := Get_String_Char (S, J);
4552
4553 -- Look for dubious character and issue unconditional warning.
4554 -- Definitely dubious if not in character range.
4555
4556 if not In_Character_Range (C)
4557
4558 -- For all cases except CLI target,
4559 -- commas, spaces and slashes are dubious (in CLI, we use
4560 -- commas and backslashes in external names to specify
4561 -- assembly version and public key, while slashes and spaces
4562 -- can be used in names to mark nested classes and
4563 -- valuetypes).
4564
4565 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4566 and then (Get_Character (C) = ','
4567 or else
4568 Get_Character (C) = '\'))
4569 or else (VM_Target /= CLI_Target
4570 and then (Get_Character (C) = ' '
4571 or else
4572 Get_Character (C) = '/'))
4573 then
4574 Error_Msg
4575 ("?interface name contains illegal character",
4576 Sloc (SN) + Source_Ptr (J));
4577 end if;
4578 end loop;
4579 end Check_Form_Of_Interface_Name;
4580
4581 -- Start of processing for Process_Interface_Name
4582
4583 begin
4584 if No (Link_Arg) then
4585 if No (Ext_Arg) then
4586 if VM_Target = CLI_Target
4587 and then Ekind (Subprogram_Def) = E_Package
4588 and then Nkind (Parent (Subprogram_Def)) =
4589 N_Package_Specification
4590 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4591 then
4592 Set_Interface_Name
4593 (Subprogram_Def,
4594 Interface_Name
4595 (Generic_Parent (Parent (Subprogram_Def))));
4596 end if;
4597
4598 return;
4599
4600 elsif Chars (Ext_Arg) = Name_Link_Name then
4601 Ext_Nam := Empty;
4602 Link_Nam := Expression (Ext_Arg);
4603
4604 else
4605 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4606 Ext_Nam := Expression (Ext_Arg);
4607 Link_Nam := Empty;
4608 end if;
4609
4610 else
4611 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4612 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4613 Ext_Nam := Expression (Ext_Arg);
4614 Link_Nam := Expression (Link_Arg);
4615 end if;
4616
4617 -- Check expressions for external name and link name are static
4618
4619 if Present (Ext_Nam) then
4620 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4621 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4622
4623 -- Verify that external name is not the name of a local entity,
4624 -- which would hide the imported one and could lead to run-time
4625 -- surprises. The problem can only arise for entities declared in
4626 -- a package body (otherwise the external name is fully qualified
4627 -- and will not conflict).
4628
4629 declare
4630 Nam : Name_Id;
4631 E : Entity_Id;
4632 Par : Node_Id;
4633
4634 begin
4635 if Prag_Id = Pragma_Import then
4636 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4637 Nam := Name_Find;
4638 E := Entity_Id (Get_Name_Table_Info (Nam));
4639
4640 if Nam /= Chars (Subprogram_Def)
4641 and then Present (E)
4642 and then not Is_Overloadable (E)
4643 and then Is_Immediately_Visible (E)
4644 and then not Is_Imported (E)
4645 and then Ekind (Scope (E)) = E_Package
4646 then
4647 Par := Parent (E);
4648 while Present (Par) loop
4649 if Nkind (Par) = N_Package_Body then
4650 Error_Msg_Sloc := Sloc (E);
4651 Error_Msg_NE
4652 ("imported entity is hidden by & declared#",
4653 Ext_Arg, E);
4654 exit;
4655 end if;
4656
4657 Par := Parent (Par);
4658 end loop;
4659 end if;
4660 end if;
4661 end;
4662 end if;
4663
4664 if Present (Link_Nam) then
4665 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4666 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4667 end if;
4668
4669 -- If there is no link name, just set the external name
4670
4671 if No (Link_Nam) then
4672 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4673
4674 -- For the Link_Name case, the given literal is preceded by an
4675 -- asterisk, which indicates to GCC that the given name should be
4676 -- taken literally, and in particular that no prepending of
4677 -- underlines should occur, even in systems where this is the
4678 -- normal default.
4679
4680 else
4681 Start_String;
4682
4683 if VM_Target = No_VM then
4684 Store_String_Char (Get_Char_Code ('*'));
4685 end if;
4686
4687 String_Val := Strval (Expr_Value_S (Link_Nam));
4688 Store_String_Chars (String_Val);
4689 Link_Nam :=
4690 Make_String_Literal (Sloc (Link_Nam),
4691 Strval => End_String);
4692 end if;
4693
4694 Set_Encoded_Interface_Name
4695 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4696
4697 -- We allow duplicated export names in CIL, as they are always
4698 -- enclosed in a namespace that differentiates them, and overloaded
4699 -- entities are supported by the VM.
4700
4701 if Convention (Subprogram_Def) /= Convention_CIL then
4702 Check_Duplicated_Export_Name (Link_Nam);
4703 end if;
4704 end Process_Interface_Name;
4705
4706 -----------------------------------------
4707 -- Process_Interrupt_Or_Attach_Handler --
4708 -----------------------------------------
4709
4710 procedure Process_Interrupt_Or_Attach_Handler is
4711 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4712 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4713 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4714
4715 begin
4716 Set_Is_Interrupt_Handler (Handler_Proc);
4717
4718 -- If the pragma is not associated with a handler procedure within a
4719 -- protected type, then it must be for a nonprotected procedure for
4720 -- the AAMP target, in which case we don't associate a representation
4721 -- item with the procedure's scope.
4722
4723 if Ekind (Proc_Scope) = E_Protected_Type then
4724 if Prag_Id = Pragma_Interrupt_Handler
4725 or else
4726 Prag_Id = Pragma_Attach_Handler
4727 then
4728 Record_Rep_Item (Proc_Scope, N);
4729 end if;
4730 end if;
4731 end Process_Interrupt_Or_Attach_Handler;
4732
4733 --------------------------------------------------
4734 -- Process_Restrictions_Or_Restriction_Warnings --
4735 --------------------------------------------------
4736
4737 -- Note: some of the simple identifier cases were handled in par-prag,
4738 -- but it is harmless (and more straightforward) to simply handle all
4739 -- cases here, even if it means we repeat a bit of work in some cases.
4740
4741 procedure Process_Restrictions_Or_Restriction_Warnings
4742 (Warn : Boolean)
4743 is
4744 Arg : Node_Id;
4745 R_Id : Restriction_Id;
4746 Id : Name_Id;
4747 Expr : Node_Id;
4748 Val : Uint;
4749
4750 procedure Check_Unit_Name (N : Node_Id);
4751 -- Checks unit name parameter for No_Dependence. Returns if it has
4752 -- an appropriate form, otherwise raises pragma argument error.
4753
4754 ---------------------
4755 -- Check_Unit_Name --
4756 ---------------------
4757
4758 procedure Check_Unit_Name (N : Node_Id) is
4759 begin
4760 if Nkind (N) = N_Selected_Component then
4761 Check_Unit_Name (Prefix (N));
4762 Check_Unit_Name (Selector_Name (N));
4763
4764 elsif Nkind (N) = N_Identifier then
4765 return;
4766
4767 else
4768 Error_Pragma_Arg
4769 ("wrong form for unit name for No_Dependence", N);
4770 end if;
4771 end Check_Unit_Name;
4772
4773 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4774
4775 begin
4776 -- Ignore all Restrictions pragma in CodePeer mode
4777
4778 if CodePeer_Mode then
4779 return;
4780 end if;
4781
4782 Check_Ada_83_Warning;
4783 Check_At_Least_N_Arguments (1);
4784 Check_Valid_Configuration_Pragma;
4785
4786 Arg := Arg1;
4787 while Present (Arg) loop
4788 Id := Chars (Arg);
4789 Expr := Get_Pragma_Arg (Arg);
4790
4791 -- Case of no restriction identifier present
4792
4793 if Id = No_Name then
4794 if Nkind (Expr) /= N_Identifier then
4795 Error_Pragma_Arg
4796 ("invalid form for restriction", Arg);
4797 end if;
4798
4799 R_Id :=
4800 Get_Restriction_Id
4801 (Process_Restriction_Synonyms (Expr));
4802
4803 if R_Id not in All_Boolean_Restrictions then
4804 Error_Msg_Name_1 := Pname;
4805 Error_Msg_N
4806 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4807
4808 -- Check for possible misspelling
4809
4810 for J in Restriction_Id loop
4811 declare
4812 Rnm : constant String := Restriction_Id'Image (J);
4813
4814 begin
4815 Name_Buffer (1 .. Rnm'Length) := Rnm;
4816 Name_Len := Rnm'Length;
4817 Set_Casing (All_Lower_Case);
4818
4819 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4820 Set_Casing
4821 (Identifier_Casing (Current_Source_File));
4822 Error_Msg_String (1 .. Rnm'Length) :=
4823 Name_Buffer (1 .. Name_Len);
4824 Error_Msg_Strlen := Rnm'Length;
4825 Error_Msg_N -- CODEFIX
4826 ("\possible misspelling of ""~""",
4827 Get_Pragma_Arg (Arg));
4828 exit;
4829 end if;
4830 end;
4831 end loop;
4832
4833 raise Pragma_Exit;
4834 end if;
4835
4836 if Implementation_Restriction (R_Id) then
4837 Check_Restriction (No_Implementation_Restrictions, Arg);
4838 end if;
4839
4840 -- If this is a warning, then set the warning unless we already
4841 -- have a real restriction active (we never want a warning to
4842 -- override a real restriction).
4843
4844 if Warn then
4845 if not Restriction_Active (R_Id) then
4846 Set_Restriction (R_Id, N);
4847 Restriction_Warnings (R_Id) := True;
4848 end if;
4849
4850 -- If real restriction case, then set it and make sure that the
4851 -- restriction warning flag is off, since a real restriction
4852 -- always overrides a warning.
4853
4854 else
4855 Set_Restriction (R_Id, N);
4856 Restriction_Warnings (R_Id) := False;
4857 end if;
4858
4859 -- Check for obsolescent restrictions in Ada 2005 mode
4860
4861 if not Warn
4862 and then Ada_Version >= Ada_2005
4863 and then (R_Id = No_Asynchronous_Control
4864 or else
4865 R_Id = No_Unchecked_Deallocation
4866 or else
4867 R_Id = No_Unchecked_Conversion)
4868 then
4869 Check_Restriction (No_Obsolescent_Features, N);
4870 end if;
4871
4872 -- A very special case that must be processed here: pragma
4873 -- Restrictions (No_Exceptions) turns off all run-time
4874 -- checking. This is a bit dubious in terms of the formal
4875 -- language definition, but it is what is intended by RM
4876 -- H.4(12). Restriction_Warnings never affects generated code
4877 -- so this is done only in the real restriction case.
4878
4879 if R_Id = No_Exceptions and then not Warn then
4880 Scope_Suppress := (others => True);
4881 end if;
4882
4883 -- Case of No_Dependence => unit-name. Note that the parser
4884 -- already made the necessary entry in the No_Dependence table.
4885
4886 elsif Id = Name_No_Dependence then
4887 Check_Unit_Name (Expr);
4888
4889 -- All other cases of restriction identifier present
4890
4891 else
4892 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4893 Analyze_And_Resolve (Expr, Any_Integer);
4894
4895 if R_Id not in All_Parameter_Restrictions then
4896 Error_Pragma_Arg
4897 ("invalid restriction parameter identifier", Arg);
4898
4899 elsif not Is_OK_Static_Expression (Expr) then
4900 Flag_Non_Static_Expr
4901 ("value must be static expression!", Expr);
4902 raise Pragma_Exit;
4903
4904 elsif not Is_Integer_Type (Etype (Expr))
4905 or else Expr_Value (Expr) < 0
4906 then
4907 Error_Pragma_Arg
4908 ("value must be non-negative integer", Arg);
4909 end if;
4910
4911 -- Restriction pragma is active
4912
4913 Val := Expr_Value (Expr);
4914
4915 if not UI_Is_In_Int_Range (Val) then
4916 Error_Pragma_Arg
4917 ("pragma ignored, value too large?", Arg);
4918 end if;
4919
4920 -- Warning case. If the real restriction is active, then we
4921 -- ignore the request, since warning never overrides a real
4922 -- restriction. Otherwise we set the proper warning. Note that
4923 -- this circuit sets the warning again if it is already set,
4924 -- which is what we want, since the constant may have changed.
4925
4926 if Warn then
4927 if not Restriction_Active (R_Id) then
4928 Set_Restriction
4929 (R_Id, N, Integer (UI_To_Int (Val)));
4930 Restriction_Warnings (R_Id) := True;
4931 end if;
4932
4933 -- Real restriction case, set restriction and make sure warning
4934 -- flag is off since real restriction always overrides warning.
4935
4936 else
4937 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4938 Restriction_Warnings (R_Id) := False;
4939 end if;
4940 end if;
4941
4942 Next (Arg);
4943 end loop;
4944 end Process_Restrictions_Or_Restriction_Warnings;
4945
4946 ---------------------------------
4947 -- Process_Suppress_Unsuppress --
4948 ---------------------------------
4949
4950 -- Note: this procedure makes entries in the check suppress data
4951 -- structures managed by Sem. See spec of package Sem for full
4952 -- details on how we handle recording of check suppression.
4953
4954 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4955 C : Check_Id;
4956 E_Id : Node_Id;
4957 E : Entity_Id;
4958
4959 In_Package_Spec : constant Boolean :=
4960 Is_Package_Or_Generic_Package (Current_Scope)
4961 and then not In_Package_Body (Current_Scope);
4962
4963 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4964 -- Used to suppress a single check on the given entity
4965
4966 --------------------------------
4967 -- Suppress_Unsuppress_Echeck --
4968 --------------------------------
4969
4970 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4971 begin
4972 Set_Checks_May_Be_Suppressed (E);
4973
4974 if In_Package_Spec then
4975 Push_Global_Suppress_Stack_Entry
4976 (Entity => E,
4977 Check => C,
4978 Suppress => Suppress_Case);
4979
4980 else
4981 Push_Local_Suppress_Stack_Entry
4982 (Entity => E,
4983 Check => C,
4984 Suppress => Suppress_Case);
4985 end if;
4986
4987 -- If this is a first subtype, and the base type is distinct,
4988 -- then also set the suppress flags on the base type.
4989
4990 if Is_First_Subtype (E)
4991 and then Etype (E) /= E
4992 then
4993 Suppress_Unsuppress_Echeck (Etype (E), C);
4994 end if;
4995 end Suppress_Unsuppress_Echeck;
4996
4997 -- Start of processing for Process_Suppress_Unsuppress
4998
4999 begin
5000 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
5001 -- we want to generate checks for analysis purposes, as set by -gnatC
5002
5003 if CodePeer_Mode and then Comes_From_Source (N) then
5004 return;
5005 end if;
5006
5007 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5008 -- declarative part or a package spec (RM 11.5(5)).
5009
5010 if not Is_Configuration_Pragma then
5011 Check_Is_In_Decl_Part_Or_Package_Spec;
5012 end if;
5013
5014 Check_At_Least_N_Arguments (1);
5015 Check_At_Most_N_Arguments (2);
5016 Check_No_Identifier (Arg1);
5017 Check_Arg_Is_Identifier (Arg1);
5018
5019 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5020
5021 if C = No_Check_Id then
5022 Error_Pragma_Arg
5023 ("argument of pragma% is not valid check name", Arg1);
5024 end if;
5025
5026 if not Suppress_Case
5027 and then (C = All_Checks or else C = Overflow_Check)
5028 then
5029 Opt.Overflow_Checks_Unsuppressed := True;
5030 end if;
5031
5032 if Arg_Count = 1 then
5033
5034 -- Make an entry in the local scope suppress table. This is the
5035 -- table that directly shows the current value of the scope
5036 -- suppress check for any check id value.
5037
5038 if C = All_Checks then
5039
5040 -- For All_Checks, we set all specific predefined checks with
5041 -- the exception of Elaboration_Check, which is handled
5042 -- specially because of not wanting All_Checks to have the
5043 -- effect of deactivating static elaboration order processing.
5044
5045 for J in Scope_Suppress'Range loop
5046 if J /= Elaboration_Check then
5047 Scope_Suppress (J) := Suppress_Case;
5048 end if;
5049 end loop;
5050
5051 -- If not All_Checks, and predefined check, then set appropriate
5052 -- scope entry. Note that we will set Elaboration_Check if this
5053 -- is explicitly specified.
5054
5055 elsif C in Predefined_Check_Id then
5056 Scope_Suppress (C) := Suppress_Case;
5057 end if;
5058
5059 -- Also make an entry in the Local_Entity_Suppress table
5060
5061 Push_Local_Suppress_Stack_Entry
5062 (Entity => Empty,
5063 Check => C,
5064 Suppress => Suppress_Case);
5065
5066 -- Case of two arguments present, where the check is suppressed for
5067 -- a specified entity (given as the second argument of the pragma)
5068
5069 else
5070 -- This is obsolescent in Ada 2005 mode
5071
5072 if Ada_Version >= Ada_2005 then
5073 Check_Restriction (No_Obsolescent_Features, Arg2);
5074 end if;
5075
5076 Check_Optional_Identifier (Arg2, Name_On);
5077 E_Id := Get_Pragma_Arg (Arg2);
5078 Analyze (E_Id);
5079
5080 if not Is_Entity_Name (E_Id) then
5081 Error_Pragma_Arg
5082 ("second argument of pragma% must be entity name", Arg2);
5083 end if;
5084
5085 E := Entity (E_Id);
5086
5087 if E = Any_Id then
5088 return;
5089 end if;
5090
5091 -- Enforce RM 11.5(7) which requires that for a pragma that
5092 -- appears within a package spec, the named entity must be
5093 -- within the package spec. We allow the package name itself
5094 -- to be mentioned since that makes sense, although it is not
5095 -- strictly allowed by 11.5(7).
5096
5097 if In_Package_Spec
5098 and then E /= Current_Scope
5099 and then Scope (E) /= Current_Scope
5100 then
5101 Error_Pragma_Arg
5102 ("entity in pragma% is not in package spec (RM 11.5(7))",
5103 Arg2);
5104 end if;
5105
5106 -- Loop through homonyms. As noted below, in the case of a package
5107 -- spec, only homonyms within the package spec are considered.
5108
5109 loop
5110 Suppress_Unsuppress_Echeck (E, C);
5111
5112 if Is_Generic_Instance (E)
5113 and then Is_Subprogram (E)
5114 and then Present (Alias (E))
5115 then
5116 Suppress_Unsuppress_Echeck (Alias (E), C);
5117 end if;
5118
5119 -- Move to next homonym if not aspect spec case
5120
5121 exit when From_Aspect_Specification (N);
5122 E := Homonym (E);
5123 exit when No (E);
5124
5125 -- If we are within a package specification, the pragma only
5126 -- applies to homonyms in the same scope.
5127
5128 exit when In_Package_Spec
5129 and then Scope (E) /= Current_Scope;
5130 end loop;
5131 end if;
5132 end Process_Suppress_Unsuppress;
5133
5134 ------------------
5135 -- Set_Exported --
5136 ------------------
5137
5138 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5139 begin
5140 if Is_Imported (E) then
5141 Error_Pragma_Arg
5142 ("cannot export entity& that was previously imported", Arg);
5143
5144 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5145 Error_Pragma_Arg
5146 ("cannot export entity& that has an address clause", Arg);
5147 end if;
5148
5149 Set_Is_Exported (E);
5150
5151 -- Generate a reference for entity explicitly, because the
5152 -- identifier may be overloaded and name resolution will not
5153 -- generate one.
5154
5155 Generate_Reference (E, Arg);
5156
5157 -- Deal with exporting non-library level entity
5158
5159 if not Is_Library_Level_Entity (E) then
5160
5161 -- Not allowed at all for subprograms
5162
5163 if Is_Subprogram (E) then
5164 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5165
5166 -- Otherwise set public and statically allocated
5167
5168 else
5169 Set_Is_Public (E);
5170 Set_Is_Statically_Allocated (E);
5171
5172 -- Warn if the corresponding W flag is set and the pragma comes
5173 -- from source. The latter may not be true e.g. on VMS where we
5174 -- expand export pragmas for exception codes associated with
5175 -- imported or exported exceptions. We do not want to generate
5176 -- a warning for something that the user did not write.
5177
5178 if Warn_On_Export_Import
5179 and then Comes_From_Source (Arg)
5180 then
5181 Error_Msg_NE
5182 ("?& has been made static as a result of Export", Arg, E);
5183 Error_Msg_N
5184 ("\this usage is non-standard and non-portable", Arg);
5185 end if;
5186 end if;
5187 end if;
5188
5189 if Warn_On_Export_Import and then Is_Type (E) then
5190 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5191 end if;
5192
5193 if Warn_On_Export_Import and Inside_A_Generic then
5194 Error_Msg_NE
5195 ("all instances of& will have the same external name?", Arg, E);
5196 end if;
5197 end Set_Exported;
5198
5199 ----------------------------------------------
5200 -- Set_Extended_Import_Export_External_Name --
5201 ----------------------------------------------
5202
5203 procedure Set_Extended_Import_Export_External_Name
5204 (Internal_Ent : Entity_Id;
5205 Arg_External : Node_Id)
5206 is
5207 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5208 New_Name : Node_Id;
5209
5210 begin
5211 if No (Arg_External) then
5212 return;
5213 end if;
5214
5215 Check_Arg_Is_External_Name (Arg_External);
5216
5217 if Nkind (Arg_External) = N_String_Literal then
5218 if String_Length (Strval (Arg_External)) = 0 then
5219 return;
5220 else
5221 New_Name := Adjust_External_Name_Case (Arg_External);
5222 end if;
5223
5224 elsif Nkind (Arg_External) = N_Identifier then
5225 New_Name := Get_Default_External_Name (Arg_External);
5226
5227 -- Check_Arg_Is_External_Name should let through only identifiers and
5228 -- string literals or static string expressions (which are folded to
5229 -- string literals).
5230
5231 else
5232 raise Program_Error;
5233 end if;
5234
5235 -- If we already have an external name set (by a prior normal Import
5236 -- or Export pragma), then the external names must match
5237
5238 if Present (Interface_Name (Internal_Ent)) then
5239 Check_Matching_Internal_Names : declare
5240 S1 : constant String_Id := Strval (Old_Name);
5241 S2 : constant String_Id := Strval (New_Name);
5242
5243 procedure Mismatch;
5244 -- Called if names do not match
5245
5246 --------------
5247 -- Mismatch --
5248 --------------
5249
5250 procedure Mismatch is
5251 begin
5252 Error_Msg_Sloc := Sloc (Old_Name);
5253 Error_Pragma_Arg
5254 ("external name does not match that given #",
5255 Arg_External);
5256 end Mismatch;
5257
5258 -- Start of processing for Check_Matching_Internal_Names
5259
5260 begin
5261 if String_Length (S1) /= String_Length (S2) then
5262 Mismatch;
5263
5264 else
5265 for J in 1 .. String_Length (S1) loop
5266 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5267 Mismatch;
5268 end if;
5269 end loop;
5270 end if;
5271 end Check_Matching_Internal_Names;
5272
5273 -- Otherwise set the given name
5274
5275 else
5276 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5277 Check_Duplicated_Export_Name (New_Name);
5278 end if;
5279 end Set_Extended_Import_Export_External_Name;
5280
5281 ------------------
5282 -- Set_Imported --
5283 ------------------
5284
5285 procedure Set_Imported (E : Entity_Id) is
5286 begin
5287 -- Error message if already imported or exported
5288
5289 if Is_Exported (E) or else Is_Imported (E) then
5290
5291 -- Error if being set Exported twice
5292
5293 if Is_Exported (E) then
5294 Error_Msg_NE ("entity& was previously exported", N, E);
5295
5296 -- OK if Import/Interface case
5297
5298 elsif Import_Interface_Present (N) then
5299 goto OK;
5300
5301 -- Error if being set Imported twice
5302
5303 else
5304 Error_Msg_NE ("entity& was previously imported", N, E);
5305 end if;
5306
5307 Error_Msg_Name_1 := Pname;
5308 Error_Msg_N
5309 ("\(pragma% applies to all previous entities)", N);
5310
5311 Error_Msg_Sloc := Sloc (E);
5312 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5313
5314 -- Here if not previously imported or exported, OK to import
5315
5316 else
5317 Set_Is_Imported (E);
5318
5319 -- If the entity is an object that is not at the library level,
5320 -- then it is statically allocated. We do not worry about objects
5321 -- with address clauses in this context since they are not really
5322 -- imported in the linker sense.
5323
5324 if Is_Object (E)
5325 and then not Is_Library_Level_Entity (E)
5326 and then No (Address_Clause (E))
5327 then
5328 Set_Is_Statically_Allocated (E);
5329 end if;
5330 end if;
5331
5332 <<OK>> null;
5333 end Set_Imported;
5334
5335 -------------------------
5336 -- Set_Mechanism_Value --
5337 -------------------------
5338
5339 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5340 -- analyzed, since it is semantic nonsense), so we get it in the exact
5341 -- form created by the parser.
5342
5343 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5344 Class : Node_Id;
5345 Param : Node_Id;
5346 Mech_Name_Id : Name_Id;
5347
5348 procedure Bad_Class;
5349 -- Signal bad descriptor class name
5350
5351 procedure Bad_Mechanism;
5352 -- Signal bad mechanism name
5353
5354 ---------------
5355 -- Bad_Class --
5356 ---------------
5357
5358 procedure Bad_Class is
5359 begin
5360 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5361 end Bad_Class;
5362
5363 -------------------------
5364 -- Bad_Mechanism_Value --
5365 -------------------------
5366
5367 procedure Bad_Mechanism is
5368 begin
5369 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5370 end Bad_Mechanism;
5371
5372 -- Start of processing for Set_Mechanism_Value
5373
5374 begin
5375 if Mechanism (Ent) /= Default_Mechanism then
5376 Error_Msg_NE
5377 ("mechanism for & has already been set", Mech_Name, Ent);
5378 end if;
5379
5380 -- MECHANISM_NAME ::= value | reference | descriptor |
5381 -- short_descriptor
5382
5383 if Nkind (Mech_Name) = N_Identifier then
5384 if Chars (Mech_Name) = Name_Value then
5385 Set_Mechanism (Ent, By_Copy);
5386 return;
5387
5388 elsif Chars (Mech_Name) = Name_Reference then
5389 Set_Mechanism (Ent, By_Reference);
5390 return;
5391
5392 elsif Chars (Mech_Name) = Name_Descriptor then
5393 Check_VMS (Mech_Name);
5394
5395 -- Descriptor => Short_Descriptor if pragma was given
5396
5397 if Short_Descriptors then
5398 Set_Mechanism (Ent, By_Short_Descriptor);
5399 else
5400 Set_Mechanism (Ent, By_Descriptor);
5401 end if;
5402
5403 return;
5404
5405 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5406 Check_VMS (Mech_Name);
5407 Set_Mechanism (Ent, By_Short_Descriptor);
5408 return;
5409
5410 elsif Chars (Mech_Name) = Name_Copy then
5411 Error_Pragma_Arg
5412 ("bad mechanism name, Value assumed", Mech_Name);
5413
5414 else
5415 Bad_Mechanism;
5416 end if;
5417
5418 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5419 -- short_descriptor (CLASS_NAME)
5420 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5421
5422 -- Note: this form is parsed as an indexed component
5423
5424 elsif Nkind (Mech_Name) = N_Indexed_Component then
5425 Class := First (Expressions (Mech_Name));
5426
5427 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5428 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5429 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5430 or else Present (Next (Class))
5431 then
5432 Bad_Mechanism;
5433 else
5434 Mech_Name_Id := Chars (Prefix (Mech_Name));
5435
5436 -- Change Descriptor => Short_Descriptor if pragma was given
5437
5438 if Mech_Name_Id = Name_Descriptor
5439 and then Short_Descriptors
5440 then
5441 Mech_Name_Id := Name_Short_Descriptor;
5442 end if;
5443 end if;
5444
5445 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5446 -- short_descriptor (Class => CLASS_NAME)
5447 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5448
5449 -- Note: this form is parsed as a function call
5450
5451 elsif Nkind (Mech_Name) = N_Function_Call then
5452 Param := First (Parameter_Associations (Mech_Name));
5453
5454 if Nkind (Name (Mech_Name)) /= N_Identifier
5455 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5456 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5457 or else Present (Next (Param))
5458 or else No (Selector_Name (Param))
5459 or else Chars (Selector_Name (Param)) /= Name_Class
5460 then
5461 Bad_Mechanism;
5462 else
5463 Class := Explicit_Actual_Parameter (Param);
5464 Mech_Name_Id := Chars (Name (Mech_Name));
5465 end if;
5466
5467 else
5468 Bad_Mechanism;
5469 end if;
5470
5471 -- Fall through here with Class set to descriptor class name
5472
5473 Check_VMS (Mech_Name);
5474
5475 if Nkind (Class) /= N_Identifier then
5476 Bad_Class;
5477
5478 elsif Mech_Name_Id = Name_Descriptor
5479 and then Chars (Class) = Name_UBS
5480 then
5481 Set_Mechanism (Ent, By_Descriptor_UBS);
5482
5483 elsif Mech_Name_Id = Name_Descriptor
5484 and then Chars (Class) = Name_UBSB
5485 then
5486 Set_Mechanism (Ent, By_Descriptor_UBSB);
5487
5488 elsif Mech_Name_Id = Name_Descriptor
5489 and then Chars (Class) = Name_UBA
5490 then
5491 Set_Mechanism (Ent, By_Descriptor_UBA);
5492
5493 elsif Mech_Name_Id = Name_Descriptor
5494 and then Chars (Class) = Name_S
5495 then
5496 Set_Mechanism (Ent, By_Descriptor_S);
5497
5498 elsif Mech_Name_Id = Name_Descriptor
5499 and then Chars (Class) = Name_SB
5500 then
5501 Set_Mechanism (Ent, By_Descriptor_SB);
5502
5503 elsif Mech_Name_Id = Name_Descriptor
5504 and then Chars (Class) = Name_A
5505 then
5506 Set_Mechanism (Ent, By_Descriptor_A);
5507
5508 elsif Mech_Name_Id = Name_Descriptor
5509 and then Chars (Class) = Name_NCA
5510 then
5511 Set_Mechanism (Ent, By_Descriptor_NCA);
5512
5513 elsif Mech_Name_Id = Name_Short_Descriptor
5514 and then Chars (Class) = Name_UBS
5515 then
5516 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5517
5518 elsif Mech_Name_Id = Name_Short_Descriptor
5519 and then Chars (Class) = Name_UBSB
5520 then
5521 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5522
5523 elsif Mech_Name_Id = Name_Short_Descriptor
5524 and then Chars (Class) = Name_UBA
5525 then
5526 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5527
5528 elsif Mech_Name_Id = Name_Short_Descriptor
5529 and then Chars (Class) = Name_S
5530 then
5531 Set_Mechanism (Ent, By_Short_Descriptor_S);
5532
5533 elsif Mech_Name_Id = Name_Short_Descriptor
5534 and then Chars (Class) = Name_SB
5535 then
5536 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5537
5538 elsif Mech_Name_Id = Name_Short_Descriptor
5539 and then Chars (Class) = Name_A
5540 then
5541 Set_Mechanism (Ent, By_Short_Descriptor_A);
5542
5543 elsif Mech_Name_Id = Name_Short_Descriptor
5544 and then Chars (Class) = Name_NCA
5545 then
5546 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5547
5548 else
5549 Bad_Class;
5550 end if;
5551 end Set_Mechanism_Value;
5552
5553 ---------------------------
5554 -- Set_Ravenscar_Profile --
5555 ---------------------------
5556
5557 -- The tasks to be done here are
5558
5559 -- Set required policies
5560
5561 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5562 -- pragma Locking_Policy (Ceiling_Locking)
5563
5564 -- Set Detect_Blocking mode
5565
5566 -- Set required restrictions (see System.Rident for detailed list)
5567
5568 -- Set the No_Dependence rules
5569 -- No_Dependence => Ada.Asynchronous_Task_Control
5570 -- No_Dependence => Ada.Calendar
5571 -- No_Dependence => Ada.Execution_Time.Group_Budget
5572 -- No_Dependence => Ada.Execution_Time.Timers
5573 -- No_Dependence => Ada.Task_Attributes
5574 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5575
5576 procedure Set_Ravenscar_Profile (N : Node_Id) is
5577 Prefix_Entity : Entity_Id;
5578 Selector_Entity : Entity_Id;
5579 Prefix_Node : Node_Id;
5580 Node : Node_Id;
5581
5582 begin
5583 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5584
5585 if Task_Dispatching_Policy /= ' '
5586 and then Task_Dispatching_Policy /= 'F'
5587 then
5588 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5589 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5590
5591 -- Set the FIFO_Within_Priorities policy, but always preserve
5592 -- System_Location since we like the error message with the run time
5593 -- name.
5594
5595 else
5596 Task_Dispatching_Policy := 'F';
5597
5598 if Task_Dispatching_Policy_Sloc /= System_Location then
5599 Task_Dispatching_Policy_Sloc := Loc;
5600 end if;
5601 end if;
5602
5603 -- pragma Locking_Policy (Ceiling_Locking)
5604
5605 if Locking_Policy /= ' '
5606 and then Locking_Policy /= 'C'
5607 then
5608 Error_Msg_Sloc := Locking_Policy_Sloc;
5609 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5610
5611 -- Set the Ceiling_Locking policy, but preserve System_Location since
5612 -- we like the error message with the run time name.
5613
5614 else
5615 Locking_Policy := 'C';
5616
5617 if Locking_Policy_Sloc /= System_Location then
5618 Locking_Policy_Sloc := Loc;
5619 end if;
5620 end if;
5621
5622 -- pragma Detect_Blocking
5623
5624 Detect_Blocking := True;
5625
5626 -- Set the corresponding restrictions
5627
5628 Set_Profile_Restrictions
5629 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5630
5631 -- Set the No_Dependence restrictions
5632
5633 -- The following No_Dependence restrictions:
5634 -- No_Dependence => Ada.Asynchronous_Task_Control
5635 -- No_Dependence => Ada.Calendar
5636 -- No_Dependence => Ada.Task_Attributes
5637 -- are already set by previous call to Set_Profile_Restrictions.
5638
5639 -- Set the following restrictions which were added to Ada 2005:
5640 -- No_Dependence => Ada.Execution_Time.Group_Budget
5641 -- No_Dependence => Ada.Execution_Time.Timers
5642
5643 if Ada_Version >= Ada_2005 then
5644 Name_Buffer (1 .. 3) := "ada";
5645 Name_Len := 3;
5646
5647 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5648
5649 Name_Buffer (1 .. 14) := "execution_time";
5650 Name_Len := 14;
5651
5652 Selector_Entity := Make_Identifier (Loc, Name_Find);
5653
5654 Prefix_Node :=
5655 Make_Selected_Component
5656 (Sloc => Loc,
5657 Prefix => Prefix_Entity,
5658 Selector_Name => Selector_Entity);
5659
5660 Name_Buffer (1 .. 13) := "group_budgets";
5661 Name_Len := 13;
5662
5663 Selector_Entity := Make_Identifier (Loc, Name_Find);
5664
5665 Node :=
5666 Make_Selected_Component
5667 (Sloc => Loc,
5668 Prefix => Prefix_Node,
5669 Selector_Name => Selector_Entity);
5670
5671 Set_Restriction_No_Dependence
5672 (Unit => Node,
5673 Warn => Treat_Restrictions_As_Warnings,
5674 Profile => Ravenscar);
5675
5676 Name_Buffer (1 .. 6) := "timers";
5677 Name_Len := 6;
5678
5679 Selector_Entity := Make_Identifier (Loc, Name_Find);
5680
5681 Node :=
5682 Make_Selected_Component
5683 (Sloc => Loc,
5684 Prefix => Prefix_Node,
5685 Selector_Name => Selector_Entity);
5686
5687 Set_Restriction_No_Dependence
5688 (Unit => Node,
5689 Warn => Treat_Restrictions_As_Warnings,
5690 Profile => Ravenscar);
5691 end if;
5692
5693 -- Set the following restrictions which was added to Ada 2012 (see
5694 -- AI-0171):
5695 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5696
5697 if Ada_Version >= Ada_2012 then
5698 Name_Buffer (1 .. 6) := "system";
5699 Name_Len := 6;
5700
5701 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5702
5703 Name_Buffer (1 .. 15) := "multiprocessors";
5704 Name_Len := 15;
5705
5706 Selector_Entity := Make_Identifier (Loc, Name_Find);
5707
5708 Prefix_Node :=
5709 Make_Selected_Component
5710 (Sloc => Loc,
5711 Prefix => Prefix_Entity,
5712 Selector_Name => Selector_Entity);
5713
5714 Name_Buffer (1 .. 19) := "dispatching_domains";
5715 Name_Len := 19;
5716
5717 Selector_Entity := Make_Identifier (Loc, Name_Find);
5718
5719 Node :=
5720 Make_Selected_Component
5721 (Sloc => Loc,
5722 Prefix => Prefix_Node,
5723 Selector_Name => Selector_Entity);
5724
5725 Set_Restriction_No_Dependence
5726 (Unit => Node,
5727 Warn => Treat_Restrictions_As_Warnings,
5728 Profile => Ravenscar);
5729 end if;
5730 end Set_Ravenscar_Profile;
5731
5732 -- Start of processing for Analyze_Pragma
5733
5734 begin
5735 -- The following code is a defense against recursion. Not clear that
5736 -- this can happen legitimately, but perhaps some error situations
5737 -- can cause it, and we did see this recursion during testing.
5738
5739 if Analyzed (N) then
5740 return;
5741 else
5742 Set_Analyzed (N, True);
5743 end if;
5744
5745 -- Deal with unrecognized pragma
5746
5747 if not Is_Pragma_Name (Pname) then
5748 if Warn_On_Unrecognized_Pragma then
5749 Error_Msg_Name_1 := Pname;
5750 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5751
5752 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5753 if Is_Bad_Spelling_Of (Pname, PN) then
5754 Error_Msg_Name_1 := PN;
5755 Error_Msg_N -- CODEFIX
5756 ("\?possible misspelling of %!", Pragma_Identifier (N));
5757 exit;
5758 end if;
5759 end loop;
5760 end if;
5761
5762 return;
5763 end if;
5764
5765 -- Here to start processing for recognized pragma
5766
5767 Prag_Id := Get_Pragma_Id (Pname);
5768
5769 -- Preset arguments
5770
5771 Arg_Count := 0;
5772 Arg1 := Empty;
5773 Arg2 := Empty;
5774 Arg3 := Empty;
5775 Arg4 := Empty;
5776
5777 if Present (Pragma_Argument_Associations (N)) then
5778 Arg_Count := List_Length (Pragma_Argument_Associations (N));
5779 Arg1 := First (Pragma_Argument_Associations (N));
5780
5781 if Present (Arg1) then
5782 Arg2 := Next (Arg1);
5783
5784 if Present (Arg2) then
5785 Arg3 := Next (Arg2);
5786
5787 if Present (Arg3) then
5788 Arg4 := Next (Arg3);
5789 end if;
5790 end if;
5791 end if;
5792 end if;
5793
5794 -- An enumeration type defines the pragmas that are supported by the
5795 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5796 -- into the corresponding enumeration value for the following case.
5797
5798 case Prag_Id is
5799
5800 -----------------
5801 -- Abort_Defer --
5802 -----------------
5803
5804 -- pragma Abort_Defer;
5805
5806 when Pragma_Abort_Defer =>
5807 GNAT_Pragma;
5808 Check_Arg_Count (0);
5809
5810 -- The only required semantic processing is to check the
5811 -- placement. This pragma must appear at the start of the
5812 -- statement sequence of a handled sequence of statements.
5813
5814 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5815 or else N /= First (Statements (Parent (N)))
5816 then
5817 Pragma_Misplaced;
5818 end if;
5819
5820 ------------
5821 -- Ada_83 --
5822 ------------
5823
5824 -- pragma Ada_83;
5825
5826 -- Note: this pragma also has some specific processing in Par.Prag
5827 -- because we want to set the Ada version mode during parsing.
5828
5829 when Pragma_Ada_83 =>
5830 GNAT_Pragma;
5831 Check_Arg_Count (0);
5832
5833 -- We really should check unconditionally for proper configuration
5834 -- pragma placement, since we really don't want mixed Ada modes
5835 -- within a single unit, and the GNAT reference manual has always
5836 -- said this was a configuration pragma, but we did not check and
5837 -- are hesitant to add the check now.
5838
5839 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5840 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5841 -- or Ada 2012 mode.
5842
5843 if Ada_Version >= Ada_2005 then
5844 Check_Valid_Configuration_Pragma;
5845 end if;
5846
5847 -- Now set Ada 83 mode
5848
5849 Ada_Version := Ada_83;
5850 Ada_Version_Explicit := Ada_Version;
5851
5852 ------------
5853 -- Ada_95 --
5854 ------------
5855
5856 -- pragma Ada_95;
5857
5858 -- Note: this pragma also has some specific processing in Par.Prag
5859 -- because we want to set the Ada 83 version mode during parsing.
5860
5861 when Pragma_Ada_95 =>
5862 GNAT_Pragma;
5863 Check_Arg_Count (0);
5864
5865 -- We really should check unconditionally for proper configuration
5866 -- pragma placement, since we really don't want mixed Ada modes
5867 -- within a single unit, and the GNAT reference manual has always
5868 -- said this was a configuration pragma, but we did not check and
5869 -- are hesitant to add the check now.
5870
5871 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5872 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5873
5874 if Ada_Version >= Ada_2005 then
5875 Check_Valid_Configuration_Pragma;
5876 end if;
5877
5878 -- Now set Ada 95 mode
5879
5880 Ada_Version := Ada_95;
5881 Ada_Version_Explicit := Ada_Version;
5882
5883 ---------------------
5884 -- Ada_05/Ada_2005 --
5885 ---------------------
5886
5887 -- pragma Ada_05;
5888 -- pragma Ada_05 (LOCAL_NAME);
5889
5890 -- pragma Ada_2005;
5891 -- pragma Ada_2005 (LOCAL_NAME):
5892
5893 -- Note: these pragmas also have some specific processing in Par.Prag
5894 -- because we want to set the Ada 2005 version mode during parsing.
5895
5896 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5897 E_Id : Node_Id;
5898
5899 begin
5900 GNAT_Pragma;
5901
5902 if Arg_Count = 1 then
5903 Check_Arg_Is_Local_Name (Arg1);
5904 E_Id := Get_Pragma_Arg (Arg1);
5905
5906 if Etype (E_Id) = Any_Type then
5907 return;
5908 end if;
5909
5910 Set_Is_Ada_2005_Only (Entity (E_Id));
5911
5912 else
5913 Check_Arg_Count (0);
5914
5915 -- For Ada_2005 we unconditionally enforce the documented
5916 -- configuration pragma placement, since we do not want to
5917 -- tolerate mixed modes in a unit involving Ada 2005. That
5918 -- would cause real difficulties for those cases where there
5919 -- are incompatibilities between Ada 95 and Ada 2005.
5920
5921 Check_Valid_Configuration_Pragma;
5922
5923 -- Now set appropriate Ada mode
5924
5925 Ada_Version := Ada_2005;
5926 Ada_Version_Explicit := Ada_2005;
5927 end if;
5928 end;
5929
5930 ---------------------
5931 -- Ada_12/Ada_2012 --
5932 ---------------------
5933
5934 -- pragma Ada_12;
5935 -- pragma Ada_12 (LOCAL_NAME);
5936
5937 -- pragma Ada_2012;
5938 -- pragma Ada_2012 (LOCAL_NAME):
5939
5940 -- Note: these pragmas also have some specific processing in Par.Prag
5941 -- because we want to set the Ada 2012 version mode during parsing.
5942
5943 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5944 E_Id : Node_Id;
5945
5946 begin
5947 GNAT_Pragma;
5948
5949 if Arg_Count = 1 then
5950 Check_Arg_Is_Local_Name (Arg1);
5951 E_Id := Get_Pragma_Arg (Arg1);
5952
5953 if Etype (E_Id) = Any_Type then
5954 return;
5955 end if;
5956
5957 Set_Is_Ada_2012_Only (Entity (E_Id));
5958
5959 else
5960 Check_Arg_Count (0);
5961
5962 -- For Ada_2012 we unconditionally enforce the documented
5963 -- configuration pragma placement, since we do not want to
5964 -- tolerate mixed modes in a unit involving Ada 2012. That
5965 -- would cause real difficulties for those cases where there
5966 -- are incompatibilities between Ada 95 and Ada 2012. We could
5967 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5968
5969 Check_Valid_Configuration_Pragma;
5970
5971 -- Now set appropriate Ada mode
5972
5973 Ada_Version := Ada_2012;
5974 Ada_Version_Explicit := Ada_2012;
5975 end if;
5976 end;
5977
5978 ----------------------
5979 -- All_Calls_Remote --
5980 ----------------------
5981
5982 -- pragma All_Calls_Remote [(library_package_NAME)];
5983
5984 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5985 Lib_Entity : Entity_Id;
5986
5987 begin
5988 Check_Ada_83_Warning;
5989 Check_Valid_Library_Unit_Pragma;
5990
5991 if Nkind (N) = N_Null_Statement then
5992 return;
5993 end if;
5994
5995 Lib_Entity := Find_Lib_Unit_Name;
5996
5997 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5998
5999 if Present (Lib_Entity)
6000 and then not Debug_Flag_U
6001 then
6002 if not Is_Remote_Call_Interface (Lib_Entity) then
6003 Error_Pragma ("pragma% only apply to rci unit");
6004
6005 -- Set flag for entity of the library unit
6006
6007 else
6008 Set_Has_All_Calls_Remote (Lib_Entity);
6009 end if;
6010
6011 end if;
6012 end All_Calls_Remote;
6013
6014 --------------
6015 -- Annotate --
6016 --------------
6017
6018 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6019 -- ARG ::= NAME | EXPRESSION
6020
6021 -- The first two arguments are by convention intended to refer to an
6022 -- external tool and a tool-specific function. These arguments are
6023 -- not analyzed.
6024
6025 when Pragma_Annotate => Annotate : begin
6026 GNAT_Pragma;
6027 Check_At_Least_N_Arguments (1);
6028 Check_Arg_Is_Identifier (Arg1);
6029 Check_No_Identifiers;
6030 Store_Note (N);
6031
6032 declare
6033 Arg : Node_Id;
6034 Exp : Node_Id;
6035
6036 begin
6037 -- Second unanalyzed parameter is optional
6038
6039 if No (Arg2) then
6040 null;
6041 else
6042 Arg := Next (Arg2);
6043 while Present (Arg) loop
6044 Exp := Get_Pragma_Arg (Arg);
6045 Analyze (Exp);
6046
6047 if Is_Entity_Name (Exp) then
6048 null;
6049
6050 -- For string literals, we assume Standard_String as the
6051 -- type, unless the string contains wide or wide_wide
6052 -- characters.
6053
6054 elsif Nkind (Exp) = N_String_Literal then
6055 if Has_Wide_Wide_Character (Exp) then
6056 Resolve (Exp, Standard_Wide_Wide_String);
6057 elsif Has_Wide_Character (Exp) then
6058 Resolve (Exp, Standard_Wide_String);
6059 else
6060 Resolve (Exp, Standard_String);
6061 end if;
6062
6063 elsif Is_Overloaded (Exp) then
6064 Error_Pragma_Arg
6065 ("ambiguous argument for pragma%", Exp);
6066
6067 else
6068 Resolve (Exp);
6069 end if;
6070
6071 Next (Arg);
6072 end loop;
6073 end if;
6074 end;
6075 end Annotate;
6076
6077 ------------
6078 -- Assert --
6079 ------------
6080
6081 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6082 -- [, [Message =>] Static_String_EXPRESSION]);
6083
6084 when Pragma_Assert => Assert : declare
6085 Expr : Node_Id;
6086 Newa : List_Id;
6087
6088 begin
6089 Ada_2005_Pragma;
6090 Check_At_Least_N_Arguments (1);
6091 Check_At_Most_N_Arguments (2);
6092 Check_Arg_Order ((Name_Check, Name_Message));
6093 Check_Optional_Identifier (Arg1, Name_Check);
6094
6095 -- We treat pragma Assert as equivalent to:
6096
6097 -- pragma Check (Assertion, condition [, msg]);
6098
6099 -- So rewrite pragma in this manner, and analyze the result
6100
6101 Expr := Get_Pragma_Arg (Arg1);
6102 Newa := New_List (
6103 Make_Pragma_Argument_Association (Loc,
6104 Expression => Make_Identifier (Loc, Name_Assertion)),
6105
6106 Make_Pragma_Argument_Association (Sloc (Expr),
6107 Expression => Expr));
6108
6109 if Arg_Count > 1 then
6110 Check_Optional_Identifier (Arg2, Name_Message);
6111 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6112 Append_To (Newa, Relocate_Node (Arg2));
6113 end if;
6114
6115 Rewrite (N,
6116 Make_Pragma (Loc,
6117 Chars => Name_Check,
6118 Pragma_Argument_Associations => Newa));
6119 Analyze (N);
6120 end Assert;
6121
6122 ----------------------
6123 -- Assertion_Policy --
6124 ----------------------
6125
6126 -- pragma Assertion_Policy (Check | Ignore)
6127
6128 when Pragma_Assertion_Policy => Assertion_Policy : declare
6129 Policy : Node_Id;
6130
6131 begin
6132 Ada_2005_Pragma;
6133 Check_Valid_Configuration_Pragma;
6134 Check_Arg_Count (1);
6135 Check_No_Identifiers;
6136 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6137
6138 -- We treat pragma Assertion_Policy as equivalent to:
6139
6140 -- pragma Check_Policy (Assertion, policy)
6141
6142 -- So rewrite the pragma in that manner and link on to the chain
6143 -- of Check_Policy pragmas, marking the pragma as analyzed.
6144
6145 Policy := Get_Pragma_Arg (Arg1);
6146
6147 Rewrite (N,
6148 Make_Pragma (Loc,
6149 Chars => Name_Check_Policy,
6150
6151 Pragma_Argument_Associations => New_List (
6152 Make_Pragma_Argument_Association (Loc,
6153 Expression => Make_Identifier (Loc, Name_Assertion)),
6154
6155 Make_Pragma_Argument_Association (Loc,
6156 Expression =>
6157 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6158
6159 Set_Analyzed (N);
6160 Set_Next_Pragma (N, Opt.Check_Policy_List);
6161 Opt.Check_Policy_List := N;
6162 end Assertion_Policy;
6163
6164 ------------------------------
6165 -- Assume_No_Invalid_Values --
6166 ------------------------------
6167
6168 -- pragma Assume_No_Invalid_Values (On | Off);
6169
6170 when Pragma_Assume_No_Invalid_Values =>
6171 GNAT_Pragma;
6172 Check_Valid_Configuration_Pragma;
6173 Check_Arg_Count (1);
6174 Check_No_Identifiers;
6175 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6176
6177 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6178 Assume_No_Invalid_Values := True;
6179 else
6180 Assume_No_Invalid_Values := False;
6181 end if;
6182
6183 ---------------
6184 -- AST_Entry --
6185 ---------------
6186
6187 -- pragma AST_Entry (entry_IDENTIFIER);
6188
6189 when Pragma_AST_Entry => AST_Entry : declare
6190 Ent : Node_Id;
6191
6192 begin
6193 GNAT_Pragma;
6194 Check_VMS (N);
6195 Check_Arg_Count (1);
6196 Check_No_Identifiers;
6197 Check_Arg_Is_Local_Name (Arg1);
6198 Ent := Entity (Get_Pragma_Arg (Arg1));
6199
6200 -- Note: the implementation of the AST_Entry pragma could handle
6201 -- the entry family case fine, but for now we are consistent with
6202 -- the DEC rules, and do not allow the pragma, which of course
6203 -- has the effect of also forbidding the attribute.
6204
6205 if Ekind (Ent) /= E_Entry then
6206 Error_Pragma_Arg
6207 ("pragma% argument must be simple entry name", Arg1);
6208
6209 elsif Is_AST_Entry (Ent) then
6210 Error_Pragma_Arg
6211 ("duplicate % pragma for entry", Arg1);
6212
6213 elsif Has_Homonym (Ent) then
6214 Error_Pragma_Arg
6215 ("pragma% argument cannot specify overloaded entry", Arg1);
6216
6217 else
6218 declare
6219 FF : constant Entity_Id := First_Formal (Ent);
6220
6221 begin
6222 if Present (FF) then
6223 if Present (Next_Formal (FF)) then
6224 Error_Pragma_Arg
6225 ("entry for pragma% can have only one argument",
6226 Arg1);
6227
6228 elsif Parameter_Mode (FF) /= E_In_Parameter then
6229 Error_Pragma_Arg
6230 ("entry parameter for pragma% must have mode IN",
6231 Arg1);
6232 end if;
6233 end if;
6234 end;
6235
6236 Set_Is_AST_Entry (Ent);
6237 end if;
6238 end AST_Entry;
6239
6240 ------------------
6241 -- Asynchronous --
6242 ------------------
6243
6244 -- pragma Asynchronous (LOCAL_NAME);
6245
6246 when Pragma_Asynchronous => Asynchronous : declare
6247 Nm : Entity_Id;
6248 C_Ent : Entity_Id;
6249 L : List_Id;
6250 S : Node_Id;
6251 N : Node_Id;
6252 Formal : Entity_Id;
6253
6254 procedure Process_Async_Pragma;
6255 -- Common processing for procedure and access-to-procedure case
6256
6257 --------------------------
6258 -- Process_Async_Pragma --
6259 --------------------------
6260
6261 procedure Process_Async_Pragma is
6262 begin
6263 if No (L) then
6264 Set_Is_Asynchronous (Nm);
6265 return;
6266 end if;
6267
6268 -- The formals should be of mode IN (RM E.4.1(6))
6269
6270 S := First (L);
6271 while Present (S) loop
6272 Formal := Defining_Identifier (S);
6273
6274 if Nkind (Formal) = N_Defining_Identifier
6275 and then Ekind (Formal) /= E_In_Parameter
6276 then
6277 Error_Pragma_Arg
6278 ("pragma% procedure can only have IN parameter",
6279 Arg1);
6280 end if;
6281
6282 Next (S);
6283 end loop;
6284
6285 Set_Is_Asynchronous (Nm);
6286 end Process_Async_Pragma;
6287
6288 -- Start of processing for pragma Asynchronous
6289
6290 begin
6291 Check_Ada_83_Warning;
6292 Check_No_Identifiers;
6293 Check_Arg_Count (1);
6294 Check_Arg_Is_Local_Name (Arg1);
6295
6296 if Debug_Flag_U then
6297 return;
6298 end if;
6299
6300 C_Ent := Cunit_Entity (Current_Sem_Unit);
6301 Analyze (Get_Pragma_Arg (Arg1));
6302 Nm := Entity (Get_Pragma_Arg (Arg1));
6303
6304 if not Is_Remote_Call_Interface (C_Ent)
6305 and then not Is_Remote_Types (C_Ent)
6306 then
6307 -- This pragma should only appear in an RCI or Remote Types
6308 -- unit (RM E.4.1(4)).
6309
6310 Error_Pragma
6311 ("pragma% not in Remote_Call_Interface or " &
6312 "Remote_Types unit");
6313 end if;
6314
6315 if Ekind (Nm) = E_Procedure
6316 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6317 then
6318 if not Is_Remote_Call_Interface (Nm) then
6319 Error_Pragma_Arg
6320 ("pragma% cannot be applied on non-remote procedure",
6321 Arg1);
6322 end if;
6323
6324 L := Parameter_Specifications (Parent (Nm));
6325 Process_Async_Pragma;
6326 return;
6327
6328 elsif Ekind (Nm) = E_Function then
6329 Error_Pragma_Arg
6330 ("pragma% cannot be applied to function", Arg1);
6331
6332 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6333
6334 if Is_Record_Type (Nm) then
6335
6336 -- A record type that is the Equivalent_Type for a remote
6337 -- access-to-subprogram type.
6338
6339 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6340
6341 else
6342 -- A non-expanded RAS type (distribution is not enabled)
6343
6344 N := Declaration_Node (Nm);
6345 end if;
6346
6347 if Nkind (N) = N_Full_Type_Declaration
6348 and then Nkind (Type_Definition (N)) =
6349 N_Access_Procedure_Definition
6350 then
6351 L := Parameter_Specifications (Type_Definition (N));
6352 Process_Async_Pragma;
6353
6354 if Is_Asynchronous (Nm)
6355 and then Expander_Active
6356 and then Get_PCS_Name /= Name_No_DSA
6357 then
6358 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6359 end if;
6360
6361 else
6362 Error_Pragma_Arg
6363 ("pragma% cannot reference access-to-function type",
6364 Arg1);
6365 end if;
6366
6367 -- Only other possibility is Access-to-class-wide type
6368
6369 elsif Is_Access_Type (Nm)
6370 and then Is_Class_Wide_Type (Designated_Type (Nm))
6371 then
6372 Check_First_Subtype (Arg1);
6373 Set_Is_Asynchronous (Nm);
6374 if Expander_Active then
6375 RACW_Type_Is_Asynchronous (Nm);
6376 end if;
6377
6378 else
6379 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6380 end if;
6381 end Asynchronous;
6382
6383 ------------
6384 -- Atomic --
6385 ------------
6386
6387 -- pragma Atomic (LOCAL_NAME);
6388
6389 when Pragma_Atomic =>
6390 Process_Atomic_Shared_Volatile;
6391
6392 -----------------------
6393 -- Atomic_Components --
6394 -----------------------
6395
6396 -- pragma Atomic_Components (array_LOCAL_NAME);
6397
6398 -- This processing is shared by Volatile_Components
6399
6400 when Pragma_Atomic_Components |
6401 Pragma_Volatile_Components =>
6402
6403 Atomic_Components : declare
6404 E_Id : Node_Id;
6405 E : Entity_Id;
6406 D : Node_Id;
6407 K : Node_Kind;
6408
6409 begin
6410 Check_Ada_83_Warning;
6411 Check_No_Identifiers;
6412 Check_Arg_Count (1);
6413 Check_Arg_Is_Local_Name (Arg1);
6414 E_Id := Get_Pragma_Arg (Arg1);
6415
6416 if Etype (E_Id) = Any_Type then
6417 return;
6418 end if;
6419
6420 E := Entity (E_Id);
6421
6422 Check_Duplicate_Pragma (E);
6423
6424 if Rep_Item_Too_Early (E, N)
6425 or else
6426 Rep_Item_Too_Late (E, N)
6427 then
6428 return;
6429 end if;
6430
6431 D := Declaration_Node (E);
6432 K := Nkind (D);
6433
6434 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6435 or else
6436 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6437 and then Nkind (D) = N_Object_Declaration
6438 and then Nkind (Object_Definition (D)) =
6439 N_Constrained_Array_Definition)
6440 then
6441 -- The flag is set on the object, or on the base type
6442
6443 if Nkind (D) /= N_Object_Declaration then
6444 E := Base_Type (E);
6445 end if;
6446
6447 Set_Has_Volatile_Components (E);
6448
6449 if Prag_Id = Pragma_Atomic_Components then
6450 Set_Has_Atomic_Components (E);
6451 end if;
6452
6453 else
6454 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6455 end if;
6456 end Atomic_Components;
6457
6458 --------------------
6459 -- Attach_Handler --
6460 --------------------
6461
6462 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6463
6464 when Pragma_Attach_Handler =>
6465 Check_Ada_83_Warning;
6466 Check_No_Identifiers;
6467 Check_Arg_Count (2);
6468
6469 if No_Run_Time_Mode then
6470 Error_Msg_CRT ("Attach_Handler pragma", N);
6471 else
6472 Check_Interrupt_Or_Attach_Handler;
6473
6474 -- The expression that designates the attribute may depend on a
6475 -- discriminant, and is therefore a per- object expression, to
6476 -- be expanded in the init proc. If expansion is enabled, then
6477 -- perform semantic checks on a copy only.
6478
6479 if Expander_Active then
6480 declare
6481 Temp : constant Node_Id :=
6482 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6483 begin
6484 Set_Parent (Temp, N);
6485 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6486 end;
6487
6488 else
6489 Analyze (Get_Pragma_Arg (Arg2));
6490 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6491 end if;
6492
6493 Process_Interrupt_Or_Attach_Handler;
6494 end if;
6495
6496 --------------------
6497 -- C_Pass_By_Copy --
6498 --------------------
6499
6500 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6501
6502 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6503 Arg : Node_Id;
6504 Val : Uint;
6505
6506 begin
6507 GNAT_Pragma;
6508 Check_Valid_Configuration_Pragma;
6509 Check_Arg_Count (1);
6510 Check_Optional_Identifier (Arg1, "max_size");
6511
6512 Arg := Get_Pragma_Arg (Arg1);
6513 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6514
6515 Val := Expr_Value (Arg);
6516
6517 if Val <= 0 then
6518 Error_Pragma_Arg
6519 ("maximum size for pragma% must be positive", Arg1);
6520
6521 elsif UI_Is_In_Int_Range (Val) then
6522 Default_C_Record_Mechanism := UI_To_Int (Val);
6523
6524 -- If a giant value is given, Int'Last will do well enough.
6525 -- If sometime someone complains that a record larger than
6526 -- two gigabytes is not copied, we will worry about it then!
6527
6528 else
6529 Default_C_Record_Mechanism := Mechanism_Type'Last;
6530 end if;
6531 end C_Pass_By_Copy;
6532
6533 -----------
6534 -- Check --
6535 -----------
6536
6537 -- pragma Check ([Name =>] Identifier,
6538 -- [Check =>] Boolean_Expression
6539 -- [,[Message =>] String_Expression]);
6540
6541 when Pragma_Check => Check : declare
6542 Expr : Node_Id;
6543 Eloc : Source_Ptr;
6544
6545 Check_On : Boolean;
6546 -- Set True if category of assertions referenced by Name enabled
6547
6548 begin
6549 GNAT_Pragma;
6550 Check_At_Least_N_Arguments (2);
6551 Check_At_Most_N_Arguments (3);
6552 Check_Optional_Identifier (Arg1, Name_Name);
6553 Check_Optional_Identifier (Arg2, Name_Check);
6554
6555 if Arg_Count = 3 then
6556 Check_Optional_Identifier (Arg3, Name_Message);
6557 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6558 end if;
6559
6560 Check_Arg_Is_Identifier (Arg1);
6561
6562 -- Indicate if pragma is enabled. The Original_Node reference here
6563 -- is to deal with pragma Assert rewritten as a Check pragma.
6564
6565 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6566
6567 if Check_On then
6568 Set_Pragma_Enabled (N);
6569 Set_Pragma_Enabled (Original_Node (N));
6570 Set_SCO_Pragma_Enabled (Loc);
6571 end if;
6572
6573 -- If expansion is active and the check is not enabled then we
6574 -- rewrite the Check as:
6575
6576 -- if False and then condition then
6577 -- null;
6578 -- end if;
6579
6580 -- The reason we do this rewriting during semantic analysis rather
6581 -- than as part of normal expansion is that we cannot analyze and
6582 -- expand the code for the boolean expression directly, or it may
6583 -- cause insertion of actions that would escape the attempt to
6584 -- suppress the check code.
6585
6586 -- Note that the Sloc for the if statement corresponds to the
6587 -- argument condition, not the pragma itself. The reason for this
6588 -- is that we may generate a warning if the condition is False at
6589 -- compile time, and we do not want to delete this warning when we
6590 -- delete the if statement.
6591
6592 Expr := Get_Pragma_Arg (Arg2);
6593
6594 if Expander_Active and then not Check_On then
6595 Eloc := Sloc (Expr);
6596
6597 Rewrite (N,
6598 Make_If_Statement (Eloc,
6599 Condition =>
6600 Make_And_Then (Eloc,
6601 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6602 Right_Opnd => Expr),
6603 Then_Statements => New_List (
6604 Make_Null_Statement (Eloc))));
6605
6606 Analyze (N);
6607
6608 -- Check is active
6609
6610 else
6611 Analyze_And_Resolve (Expr, Any_Boolean);
6612 end if;
6613 end Check;
6614
6615 ----------------
6616 -- Check_Name --
6617 ----------------
6618
6619 -- pragma Check_Name (check_IDENTIFIER);
6620
6621 when Pragma_Check_Name =>
6622 Check_No_Identifiers;
6623 GNAT_Pragma;
6624 Check_Valid_Configuration_Pragma;
6625 Check_Arg_Count (1);
6626 Check_Arg_Is_Identifier (Arg1);
6627
6628 declare
6629 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6630
6631 begin
6632 for J in Check_Names.First .. Check_Names.Last loop
6633 if Check_Names.Table (J) = Nam then
6634 return;
6635 end if;
6636 end loop;
6637
6638 Check_Names.Append (Nam);
6639 end;
6640
6641 ------------------
6642 -- Check_Policy --
6643 ------------------
6644
6645 -- pragma Check_Policy (
6646 -- [Name =>] IDENTIFIER,
6647 -- [Policy =>] POLICY_IDENTIFIER);
6648
6649 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6650
6651 -- Note: this is a configuration pragma, but it is allowed to appear
6652 -- anywhere else.
6653
6654 when Pragma_Check_Policy =>
6655 GNAT_Pragma;
6656 Check_Arg_Count (2);
6657 Check_Optional_Identifier (Arg1, Name_Name);
6658 Check_Optional_Identifier (Arg2, Name_Policy);
6659 Check_Arg_Is_One_Of
6660 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6661
6662 -- A Check_Policy pragma can appear either as a configuration
6663 -- pragma, or in a declarative part or a package spec (see RM
6664 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6665 -- followed for Check_Policy).
6666
6667 if not Is_Configuration_Pragma then
6668 Check_Is_In_Decl_Part_Or_Package_Spec;
6669 end if;
6670
6671 Set_Next_Pragma (N, Opt.Check_Policy_List);
6672 Opt.Check_Policy_List := N;
6673
6674 ---------------------
6675 -- CIL_Constructor --
6676 ---------------------
6677
6678 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6679
6680 -- Processing for this pragma is shared with Java_Constructor
6681
6682 -------------
6683 -- Comment --
6684 -------------
6685
6686 -- pragma Comment (static_string_EXPRESSION)
6687
6688 -- Processing for pragma Comment shares the circuitry for pragma
6689 -- Ident. The only differences are that Ident enforces a limit of 31
6690 -- characters on its argument, and also enforces limitations on
6691 -- placement for DEC compatibility. Pragma Comment shares neither of
6692 -- these restrictions.
6693
6694 -------------------
6695 -- Common_Object --
6696 -------------------
6697
6698 -- pragma Common_Object (
6699 -- [Internal =>] LOCAL_NAME
6700 -- [, [External =>] EXTERNAL_SYMBOL]
6701 -- [, [Size =>] EXTERNAL_SYMBOL]);
6702
6703 -- Processing for this pragma is shared with Psect_Object
6704
6705 ------------------------
6706 -- Compile_Time_Error --
6707 ------------------------
6708
6709 -- pragma Compile_Time_Error
6710 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6711
6712 when Pragma_Compile_Time_Error =>
6713 GNAT_Pragma;
6714 Process_Compile_Time_Warning_Or_Error;
6715
6716 --------------------------
6717 -- Compile_Time_Warning --
6718 --------------------------
6719
6720 -- pragma Compile_Time_Warning
6721 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6722
6723 when Pragma_Compile_Time_Warning =>
6724 GNAT_Pragma;
6725 Process_Compile_Time_Warning_Or_Error;
6726
6727 -------------------
6728 -- Compiler_Unit --
6729 -------------------
6730
6731 when Pragma_Compiler_Unit =>
6732 GNAT_Pragma;
6733 Check_Arg_Count (0);
6734 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6735
6736 -----------------------------
6737 -- Complete_Representation --
6738 -----------------------------
6739
6740 -- pragma Complete_Representation;
6741
6742 when Pragma_Complete_Representation =>
6743 GNAT_Pragma;
6744 Check_Arg_Count (0);
6745
6746 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6747 Error_Pragma
6748 ("pragma & must appear within record representation clause");
6749 end if;
6750
6751 ----------------------------
6752 -- Complex_Representation --
6753 ----------------------------
6754
6755 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6756
6757 when Pragma_Complex_Representation => Complex_Representation : declare
6758 E_Id : Entity_Id;
6759 E : Entity_Id;
6760 Ent : Entity_Id;
6761
6762 begin
6763 GNAT_Pragma;
6764 Check_Arg_Count (1);
6765 Check_Optional_Identifier (Arg1, Name_Entity);
6766 Check_Arg_Is_Local_Name (Arg1);
6767 E_Id := Get_Pragma_Arg (Arg1);
6768
6769 if Etype (E_Id) = Any_Type then
6770 return;
6771 end if;
6772
6773 E := Entity (E_Id);
6774
6775 if not Is_Record_Type (E) then
6776 Error_Pragma_Arg
6777 ("argument for pragma% must be record type", Arg1);
6778 end if;
6779
6780 Ent := First_Entity (E);
6781
6782 if No (Ent)
6783 or else No (Next_Entity (Ent))
6784 or else Present (Next_Entity (Next_Entity (Ent)))
6785 or else not Is_Floating_Point_Type (Etype (Ent))
6786 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6787 then
6788 Error_Pragma_Arg
6789 ("record for pragma% must have two fields of the same "
6790 & "floating-point type", Arg1);
6791
6792 else
6793 Set_Has_Complex_Representation (Base_Type (E));
6794
6795 -- We need to treat the type has having a non-standard
6796 -- representation, for back-end purposes, even though in
6797 -- general a complex will have the default representation
6798 -- of a record with two real components.
6799
6800 Set_Has_Non_Standard_Rep (Base_Type (E));
6801 end if;
6802 end Complex_Representation;
6803
6804 -------------------------
6805 -- Component_Alignment --
6806 -------------------------
6807
6808 -- pragma Component_Alignment (
6809 -- [Form =>] ALIGNMENT_CHOICE
6810 -- [, [Name =>] type_LOCAL_NAME]);
6811 --
6812 -- ALIGNMENT_CHOICE ::=
6813 -- Component_Size
6814 -- | Component_Size_4
6815 -- | Storage_Unit
6816 -- | Default
6817
6818 when Pragma_Component_Alignment => Component_AlignmentP : declare
6819 Args : Args_List (1 .. 2);
6820 Names : constant Name_List (1 .. 2) := (
6821 Name_Form,
6822 Name_Name);
6823
6824 Form : Node_Id renames Args (1);
6825 Name : Node_Id renames Args (2);
6826
6827 Atype : Component_Alignment_Kind;
6828 Typ : Entity_Id;
6829
6830 begin
6831 GNAT_Pragma;
6832 Gather_Associations (Names, Args);
6833
6834 if No (Form) then
6835 Error_Pragma ("missing Form argument for pragma%");
6836 end if;
6837
6838 Check_Arg_Is_Identifier (Form);
6839
6840 -- Get proper alignment, note that Default = Component_Size on all
6841 -- machines we have so far, and we want to set this value rather
6842 -- than the default value to indicate that it has been explicitly
6843 -- set (and thus will not get overridden by the default component
6844 -- alignment for the current scope)
6845
6846 if Chars (Form) = Name_Component_Size then
6847 Atype := Calign_Component_Size;
6848
6849 elsif Chars (Form) = Name_Component_Size_4 then
6850 Atype := Calign_Component_Size_4;
6851
6852 elsif Chars (Form) = Name_Default then
6853 Atype := Calign_Component_Size;
6854
6855 elsif Chars (Form) = Name_Storage_Unit then
6856 Atype := Calign_Storage_Unit;
6857
6858 else
6859 Error_Pragma_Arg
6860 ("invalid Form parameter for pragma%", Form);
6861 end if;
6862
6863 -- Case with no name, supplied, affects scope table entry
6864
6865 if No (Name) then
6866 Scope_Stack.Table
6867 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6868
6869 -- Case of name supplied
6870
6871 else
6872 Check_Arg_Is_Local_Name (Name);
6873 Find_Type (Name);
6874 Typ := Entity (Name);
6875
6876 if Typ = Any_Type
6877 or else Rep_Item_Too_Early (Typ, N)
6878 then
6879 return;
6880 else
6881 Typ := Underlying_Type (Typ);
6882 end if;
6883
6884 if not Is_Record_Type (Typ)
6885 and then not Is_Array_Type (Typ)
6886 then
6887 Error_Pragma_Arg
6888 ("Name parameter of pragma% must identify record or " &
6889 "array type", Name);
6890 end if;
6891
6892 -- An explicit Component_Alignment pragma overrides an
6893 -- implicit pragma Pack, but not an explicit one.
6894
6895 if not Has_Pragma_Pack (Base_Type (Typ)) then
6896 Set_Is_Packed (Base_Type (Typ), False);
6897 Set_Component_Alignment (Base_Type (Typ), Atype);
6898 end if;
6899 end if;
6900 end Component_AlignmentP;
6901
6902 ----------------
6903 -- Controlled --
6904 ----------------
6905
6906 -- pragma Controlled (first_subtype_LOCAL_NAME);
6907
6908 when Pragma_Controlled => Controlled : declare
6909 Arg : Node_Id;
6910
6911 begin
6912 Check_No_Identifiers;
6913 Check_Arg_Count (1);
6914 Check_Arg_Is_Local_Name (Arg1);
6915 Arg := Get_Pragma_Arg (Arg1);
6916
6917 if not Is_Entity_Name (Arg)
6918 or else not Is_Access_Type (Entity (Arg))
6919 then
6920 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6921 else
6922 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6923 end if;
6924 end Controlled;
6925
6926 ----------------
6927 -- Convention --
6928 ----------------
6929
6930 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6931 -- [Entity =>] LOCAL_NAME);
6932
6933 when Pragma_Convention => Convention : declare
6934 C : Convention_Id;
6935 E : Entity_Id;
6936 pragma Warnings (Off, C);
6937 pragma Warnings (Off, E);
6938 begin
6939 Check_Arg_Order ((Name_Convention, Name_Entity));
6940 Check_Ada_83_Warning;
6941 Check_Arg_Count (2);
6942 Process_Convention (C, E);
6943 end Convention;
6944
6945 ---------------------------
6946 -- Convention_Identifier --
6947 ---------------------------
6948
6949 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6950 -- [Convention =>] convention_IDENTIFIER);
6951
6952 when Pragma_Convention_Identifier => Convention_Identifier : declare
6953 Idnam : Name_Id;
6954 Cname : Name_Id;
6955
6956 begin
6957 GNAT_Pragma;
6958 Check_Arg_Order ((Name_Name, Name_Convention));
6959 Check_Arg_Count (2);
6960 Check_Optional_Identifier (Arg1, Name_Name);
6961 Check_Optional_Identifier (Arg2, Name_Convention);
6962 Check_Arg_Is_Identifier (Arg1);
6963 Check_Arg_Is_Identifier (Arg2);
6964 Idnam := Chars (Get_Pragma_Arg (Arg1));
6965 Cname := Chars (Get_Pragma_Arg (Arg2));
6966
6967 if Is_Convention_Name (Cname) then
6968 Record_Convention_Identifier
6969 (Idnam, Get_Convention_Id (Cname));
6970 else
6971 Error_Pragma_Arg
6972 ("second arg for % pragma must be convention", Arg2);
6973 end if;
6974 end Convention_Identifier;
6975
6976 ---------------
6977 -- CPP_Class --
6978 ---------------
6979
6980 -- pragma CPP_Class ([Entity =>] local_NAME)
6981
6982 when Pragma_CPP_Class => CPP_Class : declare
6983 Arg : Node_Id;
6984 Typ : Entity_Id;
6985
6986 begin
6987 if Warn_On_Obsolescent_Feature then
6988 Error_Msg_N
6989 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6990 " by pragma import?", N);
6991 end if;
6992
6993 GNAT_Pragma;
6994 Check_Arg_Count (1);
6995 Check_Optional_Identifier (Arg1, Name_Entity);
6996 Check_Arg_Is_Local_Name (Arg1);
6997
6998 Arg := Get_Pragma_Arg (Arg1);
6999 Analyze (Arg);
7000
7001 if Etype (Arg) = Any_Type then
7002 return;
7003 end if;
7004
7005 if not Is_Entity_Name (Arg)
7006 or else not Is_Type (Entity (Arg))
7007 then
7008 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7009 end if;
7010
7011 Typ := Entity (Arg);
7012
7013 if not Is_Tagged_Type (Typ) then
7014 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7015 end if;
7016
7017 -- Types treated as CPP classes are treated as limited, but we
7018 -- don't require them to be declared this way. A warning is issued
7019 -- to encourage the user to declare them as limited. This is not
7020 -- an error, for compatibility reasons, because these types have
7021 -- been supported this way for some time.
7022
7023 if not Is_Limited_Type (Typ) then
7024 Error_Msg_N
7025 ("imported 'C'P'P type should be " &
7026 "explicitly declared limited?",
7027 Get_Pragma_Arg (Arg1));
7028 Error_Msg_N
7029 ("\type will be considered limited",
7030 Get_Pragma_Arg (Arg1));
7031 end if;
7032
7033 Set_Is_CPP_Class (Typ);
7034 Set_Is_Limited_Record (Typ);
7035 Set_Convention (Typ, Convention_CPP);
7036
7037 -- Imported CPP types must not have discriminants (because C++
7038 -- classes do not have discriminants).
7039
7040 if Has_Discriminants (Typ) then
7041 Error_Msg_N
7042 ("imported 'C'P'P type cannot have discriminants",
7043 First (Discriminant_Specifications
7044 (Declaration_Node (Typ))));
7045 end if;
7046
7047 -- Components of imported CPP types must not have default
7048 -- expressions because the constructor (if any) is in the
7049 -- C++ side.
7050
7051 if Is_Incomplete_Or_Private_Type (Typ)
7052 and then No (Underlying_Type (Typ))
7053 then
7054 -- It should be an error to apply pragma CPP to a private
7055 -- type if the underlying type is not visible (as it is
7056 -- for any representation item). For now, for backward
7057 -- compatibility we do nothing but we cannot check components
7058 -- because they are not available at this stage. All this code
7059 -- will be removed when we cleanup this obsolete GNAT pragma???
7060
7061 null;
7062
7063 else
7064 declare
7065 Tdef : constant Node_Id :=
7066 Type_Definition (Declaration_Node (Typ));
7067 Clist : Node_Id;
7068 Comp : Node_Id;
7069
7070 begin
7071 if Nkind (Tdef) = N_Record_Definition then
7072 Clist := Component_List (Tdef);
7073 else
7074 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7075 Clist := Component_List (Record_Extension_Part (Tdef));
7076 end if;
7077
7078 if Present (Clist) then
7079 Comp := First (Component_Items (Clist));
7080 while Present (Comp) loop
7081 if Present (Expression (Comp)) then
7082 Error_Msg_N
7083 ("component of imported 'C'P'P type cannot have" &
7084 " default expression", Expression (Comp));
7085 end if;
7086
7087 Next (Comp);
7088 end loop;
7089 end if;
7090 end;
7091 end if;
7092 end CPP_Class;
7093
7094 ---------------------
7095 -- CPP_Constructor --
7096 ---------------------
7097
7098 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7099 -- [, [External_Name =>] static_string_EXPRESSION ]
7100 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7101
7102 when Pragma_CPP_Constructor => CPP_Constructor : declare
7103 Elmt : Elmt_Id;
7104 Id : Entity_Id;
7105 Def_Id : Entity_Id;
7106 Tag_Typ : Entity_Id;
7107
7108 begin
7109 GNAT_Pragma;
7110 Check_At_Least_N_Arguments (1);
7111 Check_At_Most_N_Arguments (3);
7112 Check_Optional_Identifier (Arg1, Name_Entity);
7113 Check_Arg_Is_Local_Name (Arg1);
7114
7115 Id := Get_Pragma_Arg (Arg1);
7116 Find_Program_Unit_Name (Id);
7117
7118 -- If we did not find the name, we are done
7119
7120 if Etype (Id) = Any_Type then
7121 return;
7122 end if;
7123
7124 Def_Id := Entity (Id);
7125
7126 -- Check if already defined as constructor
7127
7128 if Is_Constructor (Def_Id) then
7129 Error_Msg_N
7130 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7131 return;
7132 end if;
7133
7134 if Ekind (Def_Id) = E_Function
7135 and then (Is_CPP_Class (Etype (Def_Id))
7136 or else (Is_Class_Wide_Type (Etype (Def_Id))
7137 and then
7138 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7139 then
7140 if Arg_Count >= 2 then
7141 Set_Imported (Def_Id);
7142 Set_Is_Public (Def_Id);
7143 Process_Interface_Name (Def_Id, Arg2, Arg3);
7144 end if;
7145
7146 Set_Has_Completion (Def_Id);
7147 Set_Is_Constructor (Def_Id);
7148
7149 -- Imported C++ constructors are not dispatching primitives
7150 -- because in C++ they don't have a dispatch table slot.
7151 -- However, in Ada the constructor has the profile of a
7152 -- function that returns a tagged type and therefore it has
7153 -- been treated as a primitive operation during semantic
7154 -- analysis. We now remove it from the list of primitive
7155 -- operations of the type.
7156
7157 if Is_Tagged_Type (Etype (Def_Id))
7158 and then not Is_Class_Wide_Type (Etype (Def_Id))
7159 then
7160 pragma Assert (Is_Dispatching_Operation (Def_Id));
7161 Tag_Typ := Etype (Def_Id);
7162
7163 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7164 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7165 Next_Elmt (Elmt);
7166 end loop;
7167
7168 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7169 Set_Is_Dispatching_Operation (Def_Id, False);
7170 end if;
7171
7172 -- For backward compatibility, if the constructor returns a
7173 -- class wide type, and we internally change the return type to
7174 -- the corresponding root type.
7175
7176 if Is_Class_Wide_Type (Etype (Def_Id)) then
7177 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7178 end if;
7179 else
7180 Error_Pragma_Arg
7181 ("pragma% requires function returning a 'C'P'P_Class type",
7182 Arg1);
7183 end if;
7184 end CPP_Constructor;
7185
7186 -----------------
7187 -- CPP_Virtual --
7188 -----------------
7189
7190 when Pragma_CPP_Virtual => CPP_Virtual : declare
7191 begin
7192 GNAT_Pragma;
7193
7194 if Warn_On_Obsolescent_Feature then
7195 Error_Msg_N
7196 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7197 "no effect?", N);
7198 end if;
7199 end CPP_Virtual;
7200
7201 ----------------
7202 -- CPP_Vtable --
7203 ----------------
7204
7205 when Pragma_CPP_Vtable => CPP_Vtable : declare
7206 begin
7207 GNAT_Pragma;
7208
7209 if Warn_On_Obsolescent_Feature then
7210 Error_Msg_N
7211 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7212 "no effect?", N);
7213 end if;
7214 end CPP_Vtable;
7215
7216 ---------
7217 -- CPU --
7218 ---------
7219
7220 -- pragma CPU (EXPRESSION);
7221
7222 when Pragma_CPU => CPU : declare
7223 P : constant Node_Id := Parent (N);
7224 Arg : Node_Id;
7225
7226 begin
7227 Ada_2012_Pragma;
7228 Check_No_Identifiers;
7229 Check_Arg_Count (1);
7230
7231 -- Subprogram case
7232
7233 if Nkind (P) = N_Subprogram_Body then
7234 Check_In_Main_Program;
7235
7236 Arg := Get_Pragma_Arg (Arg1);
7237 Analyze_And_Resolve (Arg, Any_Integer);
7238
7239 -- Must be static
7240
7241 if not Is_Static_Expression (Arg) then
7242 Flag_Non_Static_Expr
7243 ("main subprogram affinity is not static!", Arg);
7244 raise Pragma_Exit;
7245
7246 -- If constraint error, then we already signalled an error
7247
7248 elsif Raises_Constraint_Error (Arg) then
7249 null;
7250
7251 -- Otherwise check in range
7252
7253 else
7254 declare
7255 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7256 -- This is the entity System.Multiprocessors.CPU_Range;
7257
7258 Val : constant Uint := Expr_Value (Arg);
7259
7260 begin
7261 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7262 or else
7263 Val > Expr_Value (Type_High_Bound (CPU_Id))
7264 then
7265 Error_Pragma_Arg
7266 ("main subprogram CPU is out of range", Arg1);
7267 end if;
7268 end;
7269 end if;
7270
7271 Set_Main_CPU
7272 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7273
7274 -- Task case
7275
7276 elsif Nkind (P) = N_Task_Definition then
7277 Arg := Get_Pragma_Arg (Arg1);
7278
7279 -- The expression must be analyzed in the special manner
7280 -- described in "Handling of Default and Per-Object
7281 -- Expressions" in sem.ads.
7282
7283 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7284
7285 -- Anything else is incorrect
7286
7287 else
7288 Pragma_Misplaced;
7289 end if;
7290
7291 if Has_Pragma_CPU (P) then
7292 Error_Pragma ("duplicate pragma% not allowed");
7293 else
7294 Set_Has_Pragma_CPU (P, True);
7295
7296 if Nkind (P) = N_Task_Definition then
7297 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7298 end if;
7299 end if;
7300 end CPU;
7301
7302 -----------
7303 -- Debug --
7304 -----------
7305
7306 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7307
7308 when Pragma_Debug => Debug : declare
7309 Cond : Node_Id;
7310
7311 begin
7312 GNAT_Pragma;
7313
7314 Cond :=
7315 New_Occurrence_Of
7316 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7317 Loc);
7318
7319 if Arg_Count = 2 then
7320 Cond :=
7321 Make_And_Then (Loc,
7322 Left_Opnd => Relocate_Node (Cond),
7323 Right_Opnd => Get_Pragma_Arg (Arg1));
7324 end if;
7325
7326 -- Rewrite into a conditional with an appropriate condition. We
7327 -- wrap the procedure call in a block so that overhead from e.g.
7328 -- use of the secondary stack does not generate execution overhead
7329 -- for suppressed conditions.
7330
7331 Rewrite (N, Make_Implicit_If_Statement (N,
7332 Condition => Cond,
7333 Then_Statements => New_List (
7334 Make_Block_Statement (Loc,
7335 Handled_Statement_Sequence =>
7336 Make_Handled_Sequence_Of_Statements (Loc,
7337 Statements => New_List (
7338 Relocate_Node (Debug_Statement (N))))))));
7339 Analyze (N);
7340 end Debug;
7341
7342 ------------------
7343 -- Debug_Policy --
7344 ------------------
7345
7346 -- pragma Debug_Policy (Check | Ignore)
7347
7348 when Pragma_Debug_Policy =>
7349 GNAT_Pragma;
7350 Check_Arg_Count (1);
7351 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7352 Debug_Pragmas_Enabled :=
7353 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7354
7355 ---------------------
7356 -- Detect_Blocking --
7357 ---------------------
7358
7359 -- pragma Detect_Blocking;
7360
7361 when Pragma_Detect_Blocking =>
7362 Ada_2005_Pragma;
7363 Check_Arg_Count (0);
7364 Check_Valid_Configuration_Pragma;
7365 Detect_Blocking := True;
7366
7367 --------------------------
7368 -- Default_Storage_Pool --
7369 --------------------------
7370
7371 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7372
7373 when Pragma_Default_Storage_Pool =>
7374 Ada_2012_Pragma;
7375 Check_Arg_Count (1);
7376
7377 -- Default_Storage_Pool can appear as a configuration pragma, or
7378 -- in a declarative part or a package spec.
7379
7380 if not Is_Configuration_Pragma then
7381 Check_Is_In_Decl_Part_Or_Package_Spec;
7382 end if;
7383
7384 -- Case of Default_Storage_Pool (null);
7385
7386 if Nkind (Expression (Arg1)) = N_Null then
7387 Analyze (Expression (Arg1));
7388
7389 -- This is an odd case, this is not really an expression, so
7390 -- we don't have a type for it. So just set the type to Empty.
7391
7392 Set_Etype (Expression (Arg1), Empty);
7393
7394 -- Case of Default_Storage_Pool (storage_pool_NAME);
7395
7396 else
7397 -- If it's a configuration pragma, then the only allowed
7398 -- argument is "null".
7399
7400 if Is_Configuration_Pragma then
7401 Error_Pragma_Arg ("NULL expected", Arg1);
7402 end if;
7403
7404 -- The expected type for a non-"null" argument is
7405 -- Root_Storage_Pool'Class.
7406
7407 Analyze_And_Resolve
7408 (Get_Pragma_Arg (Arg1),
7409 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7410 end if;
7411
7412 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7413 -- for an access type will use this information to set the
7414 -- appropriate attributes of the access type.
7415
7416 Default_Pool := Expression (Arg1);
7417
7418 ---------------
7419 -- Dimension --
7420 ---------------
7421
7422 when Pragma_Dimension =>
7423 GNAT_Pragma;
7424 Check_Arg_Count (4);
7425 Check_No_Identifiers;
7426 Check_Arg_Is_Local_Name (Arg1);
7427
7428 if not Is_Type (Arg1) then
7429 Error_Pragma ("first argument for pragma% must be subtype");
7430 end if;
7431
7432 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7433 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7434 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7435
7436 -------------------
7437 -- Discard_Names --
7438 -------------------
7439
7440 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7441
7442 when Pragma_Discard_Names => Discard_Names : declare
7443 E : Entity_Id;
7444 E_Id : Entity_Id;
7445
7446 begin
7447 Check_Ada_83_Warning;
7448
7449 -- Deal with configuration pragma case
7450
7451 if Arg_Count = 0 and then Is_Configuration_Pragma then
7452 Global_Discard_Names := True;
7453 return;
7454
7455 -- Otherwise, check correct appropriate context
7456
7457 else
7458 Check_Is_In_Decl_Part_Or_Package_Spec;
7459
7460 if Arg_Count = 0 then
7461
7462 -- If there is no parameter, then from now on this pragma
7463 -- applies to any enumeration, exception or tagged type
7464 -- defined in the current declarative part, and recursively
7465 -- to any nested scope.
7466
7467 Set_Discard_Names (Current_Scope);
7468 return;
7469
7470 else
7471 Check_Arg_Count (1);
7472 Check_Optional_Identifier (Arg1, Name_On);
7473 Check_Arg_Is_Local_Name (Arg1);
7474
7475 E_Id := Get_Pragma_Arg (Arg1);
7476
7477 if Etype (E_Id) = Any_Type then
7478 return;
7479 else
7480 E := Entity (E_Id);
7481 end if;
7482
7483 if (Is_First_Subtype (E)
7484 and then
7485 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7486 or else Ekind (E) = E_Exception
7487 then
7488 Set_Discard_Names (E);
7489 else
7490 Error_Pragma_Arg
7491 ("inappropriate entity for pragma%", Arg1);
7492 end if;
7493
7494 end if;
7495 end if;
7496 end Discard_Names;
7497
7498 ---------------
7499 -- Elaborate --
7500 ---------------
7501
7502 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7503
7504 when Pragma_Elaborate => Elaborate : declare
7505 Arg : Node_Id;
7506 Citem : Node_Id;
7507
7508 begin
7509 -- Pragma must be in context items list of a compilation unit
7510
7511 if not Is_In_Context_Clause then
7512 Pragma_Misplaced;
7513 end if;
7514
7515 -- Must be at least one argument
7516
7517 if Arg_Count = 0 then
7518 Error_Pragma ("pragma% requires at least one argument");
7519 end if;
7520
7521 -- In Ada 83 mode, there can be no items following it in the
7522 -- context list except other pragmas and implicit with clauses
7523 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7524 -- placement rule does not apply.
7525
7526 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7527 Citem := Next (N);
7528 while Present (Citem) loop
7529 if Nkind (Citem) = N_Pragma
7530 or else (Nkind (Citem) = N_With_Clause
7531 and then Implicit_With (Citem))
7532 then
7533 null;
7534 else
7535 Error_Pragma
7536 ("(Ada 83) pragma% must be at end of context clause");
7537 end if;
7538
7539 Next (Citem);
7540 end loop;
7541 end if;
7542
7543 -- Finally, the arguments must all be units mentioned in a with
7544 -- clause in the same context clause. Note we already checked (in
7545 -- Par.Prag) that the arguments are all identifiers or selected
7546 -- components.
7547
7548 Arg := Arg1;
7549 Outer : while Present (Arg) loop
7550 Citem := First (List_Containing (N));
7551 Inner : while Citem /= N loop
7552 if Nkind (Citem) = N_With_Clause
7553 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7554 then
7555 Set_Elaborate_Present (Citem, True);
7556 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7557
7558 -- With the pragma present, elaboration calls on
7559 -- subprograms from the named unit need no further
7560 -- checks, as long as the pragma appears in the current
7561 -- compilation unit. If the pragma appears in some unit
7562 -- in the context, there might still be a need for an
7563 -- Elaborate_All_Desirable from the current compilation
7564 -- to the named unit, so we keep the check enabled.
7565
7566 if In_Extended_Main_Source_Unit (N) then
7567 Set_Suppress_Elaboration_Warnings
7568 (Entity (Name (Citem)));
7569 end if;
7570
7571 exit Inner;
7572 end if;
7573
7574 Next (Citem);
7575 end loop Inner;
7576
7577 if Citem = N then
7578 Error_Pragma_Arg
7579 ("argument of pragma% is not with'ed unit", Arg);
7580 end if;
7581
7582 Next (Arg);
7583 end loop Outer;
7584
7585 -- Give a warning if operating in static mode with -gnatwl
7586 -- (elaboration warnings enabled) switch set.
7587
7588 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7589 Error_Msg_N
7590 ("?use of pragma Elaborate may not be safe", N);
7591 Error_Msg_N
7592 ("?use pragma Elaborate_All instead if possible", N);
7593 end if;
7594 end Elaborate;
7595
7596 -------------------
7597 -- Elaborate_All --
7598 -------------------
7599
7600 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7601
7602 when Pragma_Elaborate_All => Elaborate_All : declare
7603 Arg : Node_Id;
7604 Citem : Node_Id;
7605
7606 begin
7607 Check_Ada_83_Warning;
7608
7609 -- Pragma must be in context items list of a compilation unit
7610
7611 if not Is_In_Context_Clause then
7612 Pragma_Misplaced;
7613 end if;
7614
7615 -- Must be at least one argument
7616
7617 if Arg_Count = 0 then
7618 Error_Pragma ("pragma% requires at least one argument");
7619 end if;
7620
7621 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7622 -- have to appear at the end of the context clause, but may
7623 -- appear mixed in with other items, even in Ada 83 mode.
7624
7625 -- Final check: the arguments must all be units mentioned in
7626 -- a with clause in the same context clause. Note that we
7627 -- already checked (in Par.Prag) that all the arguments are
7628 -- either identifiers or selected components.
7629
7630 Arg := Arg1;
7631 Outr : while Present (Arg) loop
7632 Citem := First (List_Containing (N));
7633 Innr : while Citem /= N loop
7634 if Nkind (Citem) = N_With_Clause
7635 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7636 then
7637 Set_Elaborate_All_Present (Citem, True);
7638 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7639
7640 -- Suppress warnings and elaboration checks on the named
7641 -- unit if the pragma is in the current compilation, as
7642 -- for pragma Elaborate.
7643
7644 if In_Extended_Main_Source_Unit (N) then
7645 Set_Suppress_Elaboration_Warnings
7646 (Entity (Name (Citem)));
7647 end if;
7648 exit Innr;
7649 end if;
7650
7651 Next (Citem);
7652 end loop Innr;
7653
7654 if Citem = N then
7655 Set_Error_Posted (N);
7656 Error_Pragma_Arg
7657 ("argument of pragma% is not with'ed unit", Arg);
7658 end if;
7659
7660 Next (Arg);
7661 end loop Outr;
7662 end Elaborate_All;
7663
7664 --------------------
7665 -- Elaborate_Body --
7666 --------------------
7667
7668 -- pragma Elaborate_Body [( library_unit_NAME )];
7669
7670 when Pragma_Elaborate_Body => Elaborate_Body : declare
7671 Cunit_Node : Node_Id;
7672 Cunit_Ent : Entity_Id;
7673
7674 begin
7675 Check_Ada_83_Warning;
7676 Check_Valid_Library_Unit_Pragma;
7677
7678 if Nkind (N) = N_Null_Statement then
7679 return;
7680 end if;
7681
7682 Cunit_Node := Cunit (Current_Sem_Unit);
7683 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7684
7685 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7686 N_Subprogram_Body)
7687 then
7688 Error_Pragma ("pragma% must refer to a spec, not a body");
7689 else
7690 Set_Body_Required (Cunit_Node, True);
7691 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7692
7693 -- If we are in dynamic elaboration mode, then we suppress
7694 -- elaboration warnings for the unit, since it is definitely
7695 -- fine NOT to do dynamic checks at the first level (and such
7696 -- checks will be suppressed because no elaboration boolean
7697 -- is created for Elaborate_Body packages).
7698
7699 -- But in the static model of elaboration, Elaborate_Body is
7700 -- definitely NOT good enough to ensure elaboration safety on
7701 -- its own, since the body may WITH other units that are not
7702 -- safe from an elaboration point of view, so a client must
7703 -- still do an Elaborate_All on such units.
7704
7705 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7706 -- Elaborate_Body always suppressed elab warnings.
7707
7708 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7709 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7710 end if;
7711 end if;
7712 end Elaborate_Body;
7713
7714 ------------------------
7715 -- Elaboration_Checks --
7716 ------------------------
7717
7718 -- pragma Elaboration_Checks (Static | Dynamic);
7719
7720 when Pragma_Elaboration_Checks =>
7721 GNAT_Pragma;
7722 Check_Arg_Count (1);
7723 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7724 Dynamic_Elaboration_Checks :=
7725 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7726
7727 ---------------
7728 -- Eliminate --
7729 ---------------
7730
7731 -- pragma Eliminate (
7732 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7733 -- [,[Entity =>] IDENTIFIER |
7734 -- SELECTED_COMPONENT |
7735 -- STRING_LITERAL]
7736 -- [, OVERLOADING_RESOLUTION]);
7737
7738 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7739 -- SOURCE_LOCATION
7740
7741 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7742 -- FUNCTION_PROFILE
7743
7744 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7745
7746 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7747 -- Result_Type => result_SUBTYPE_NAME]
7748
7749 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7750 -- SUBTYPE_NAME ::= STRING_LITERAL
7751
7752 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7753 -- SOURCE_TRACE ::= STRING_LITERAL
7754
7755 when Pragma_Eliminate => Eliminate : declare
7756 Args : Args_List (1 .. 5);
7757 Names : constant Name_List (1 .. 5) := (
7758 Name_Unit_Name,
7759 Name_Entity,
7760 Name_Parameter_Types,
7761 Name_Result_Type,
7762 Name_Source_Location);
7763
7764 Unit_Name : Node_Id renames Args (1);
7765 Entity : Node_Id renames Args (2);
7766 Parameter_Types : Node_Id renames Args (3);
7767 Result_Type : Node_Id renames Args (4);
7768 Source_Location : Node_Id renames Args (5);
7769
7770 begin
7771 GNAT_Pragma;
7772 Check_Valid_Configuration_Pragma;
7773 Gather_Associations (Names, Args);
7774
7775 if No (Unit_Name) then
7776 Error_Pragma ("missing Unit_Name argument for pragma%");
7777 end if;
7778
7779 if No (Entity)
7780 and then (Present (Parameter_Types)
7781 or else
7782 Present (Result_Type)
7783 or else
7784 Present (Source_Location))
7785 then
7786 Error_Pragma ("missing Entity argument for pragma%");
7787 end if;
7788
7789 if (Present (Parameter_Types)
7790 or else
7791 Present (Result_Type))
7792 and then
7793 Present (Source_Location)
7794 then
7795 Error_Pragma
7796 ("parameter profile and source location cannot " &
7797 "be used together in pragma%");
7798 end if;
7799
7800 Process_Eliminate_Pragma
7801 (N,
7802 Unit_Name,
7803 Entity,
7804 Parameter_Types,
7805 Result_Type,
7806 Source_Location);
7807 end Eliminate;
7808
7809 ------------
7810 -- Export --
7811 ------------
7812
7813 -- pragma Export (
7814 -- [ Convention =>] convention_IDENTIFIER,
7815 -- [ Entity =>] local_NAME
7816 -- [, [External_Name =>] static_string_EXPRESSION ]
7817 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7818
7819 when Pragma_Export => Export : declare
7820 C : Convention_Id;
7821 Def_Id : Entity_Id;
7822
7823 pragma Warnings (Off, C);
7824
7825 begin
7826 Check_Ada_83_Warning;
7827 Check_Arg_Order
7828 ((Name_Convention,
7829 Name_Entity,
7830 Name_External_Name,
7831 Name_Link_Name));
7832 Check_At_Least_N_Arguments (2);
7833 Check_At_Most_N_Arguments (4);
7834 Process_Convention (C, Def_Id);
7835
7836 if Ekind (Def_Id) /= E_Constant then
7837 Note_Possible_Modification
7838 (Get_Pragma_Arg (Arg2), Sure => False);
7839 end if;
7840
7841 Process_Interface_Name (Def_Id, Arg3, Arg4);
7842 Set_Exported (Def_Id, Arg2);
7843
7844 -- If the entity is a deferred constant, propagate the information
7845 -- to the full view, because gigi elaborates the full view only.
7846
7847 if Ekind (Def_Id) = E_Constant
7848 and then Present (Full_View (Def_Id))
7849 then
7850 declare
7851 Id2 : constant Entity_Id := Full_View (Def_Id);
7852 begin
7853 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7854 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7855 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7856 end;
7857 end if;
7858 end Export;
7859
7860 ----------------------
7861 -- Export_Exception --
7862 ----------------------
7863
7864 -- pragma Export_Exception (
7865 -- [Internal =>] LOCAL_NAME
7866 -- [, [External =>] EXTERNAL_SYMBOL]
7867 -- [, [Form =>] Ada | VMS]
7868 -- [, [Code =>] static_integer_EXPRESSION]);
7869
7870 when Pragma_Export_Exception => Export_Exception : declare
7871 Args : Args_List (1 .. 4);
7872 Names : constant Name_List (1 .. 4) := (
7873 Name_Internal,
7874 Name_External,
7875 Name_Form,
7876 Name_Code);
7877
7878 Internal : Node_Id renames Args (1);
7879 External : Node_Id renames Args (2);
7880 Form : Node_Id renames Args (3);
7881 Code : Node_Id renames Args (4);
7882
7883 begin
7884 GNAT_Pragma;
7885
7886 if Inside_A_Generic then
7887 Error_Pragma ("pragma% cannot be used for generic entities");
7888 end if;
7889
7890 Gather_Associations (Names, Args);
7891 Process_Extended_Import_Export_Exception_Pragma (
7892 Arg_Internal => Internal,
7893 Arg_External => External,
7894 Arg_Form => Form,
7895 Arg_Code => Code);
7896
7897 if not Is_VMS_Exception (Entity (Internal)) then
7898 Set_Exported (Entity (Internal), Internal);
7899 end if;
7900 end Export_Exception;
7901
7902 ---------------------
7903 -- Export_Function --
7904 ---------------------
7905
7906 -- pragma Export_Function (
7907 -- [Internal =>] LOCAL_NAME
7908 -- [, [External =>] EXTERNAL_SYMBOL]
7909 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7910 -- [, [Result_Type =>] TYPE_DESIGNATOR]
7911 -- [, [Mechanism =>] MECHANISM]
7912 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
7913
7914 -- EXTERNAL_SYMBOL ::=
7915 -- IDENTIFIER
7916 -- | static_string_EXPRESSION
7917
7918 -- PARAMETER_TYPES ::=
7919 -- null
7920 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7921
7922 -- TYPE_DESIGNATOR ::=
7923 -- subtype_NAME
7924 -- | subtype_Name ' Access
7925
7926 -- MECHANISM ::=
7927 -- MECHANISM_NAME
7928 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7929
7930 -- MECHANISM_ASSOCIATION ::=
7931 -- [formal_parameter_NAME =>] MECHANISM_NAME
7932
7933 -- MECHANISM_NAME ::=
7934 -- Value
7935 -- | Reference
7936 -- | Descriptor [([Class =>] CLASS_NAME)]
7937
7938 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7939
7940 when Pragma_Export_Function => Export_Function : declare
7941 Args : Args_List (1 .. 6);
7942 Names : constant Name_List (1 .. 6) := (
7943 Name_Internal,
7944 Name_External,
7945 Name_Parameter_Types,
7946 Name_Result_Type,
7947 Name_Mechanism,
7948 Name_Result_Mechanism);
7949
7950 Internal : Node_Id renames Args (1);
7951 External : Node_Id renames Args (2);
7952 Parameter_Types : Node_Id renames Args (3);
7953 Result_Type : Node_Id renames Args (4);
7954 Mechanism : Node_Id renames Args (5);
7955 Result_Mechanism : Node_Id renames Args (6);
7956
7957 begin
7958 GNAT_Pragma;
7959 Gather_Associations (Names, Args);
7960 Process_Extended_Import_Export_Subprogram_Pragma (
7961 Arg_Internal => Internal,
7962 Arg_External => External,
7963 Arg_Parameter_Types => Parameter_Types,
7964 Arg_Result_Type => Result_Type,
7965 Arg_Mechanism => Mechanism,
7966 Arg_Result_Mechanism => Result_Mechanism);
7967 end Export_Function;
7968
7969 -------------------
7970 -- Export_Object --
7971 -------------------
7972
7973 -- pragma Export_Object (
7974 -- [Internal =>] LOCAL_NAME
7975 -- [, [External =>] EXTERNAL_SYMBOL]
7976 -- [, [Size =>] EXTERNAL_SYMBOL]);
7977
7978 -- EXTERNAL_SYMBOL ::=
7979 -- IDENTIFIER
7980 -- | static_string_EXPRESSION
7981
7982 -- PARAMETER_TYPES ::=
7983 -- null
7984 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7985
7986 -- TYPE_DESIGNATOR ::=
7987 -- subtype_NAME
7988 -- | subtype_Name ' Access
7989
7990 -- MECHANISM ::=
7991 -- MECHANISM_NAME
7992 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7993
7994 -- MECHANISM_ASSOCIATION ::=
7995 -- [formal_parameter_NAME =>] MECHANISM_NAME
7996
7997 -- MECHANISM_NAME ::=
7998 -- Value
7999 -- | Reference
8000 -- | Descriptor [([Class =>] CLASS_NAME)]
8001
8002 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8003
8004 when Pragma_Export_Object => Export_Object : declare
8005 Args : Args_List (1 .. 3);
8006 Names : constant Name_List (1 .. 3) := (
8007 Name_Internal,
8008 Name_External,
8009 Name_Size);
8010
8011 Internal : Node_Id renames Args (1);
8012 External : Node_Id renames Args (2);
8013 Size : Node_Id renames Args (3);
8014
8015 begin
8016 GNAT_Pragma;
8017 Gather_Associations (Names, Args);
8018 Process_Extended_Import_Export_Object_Pragma (
8019 Arg_Internal => Internal,
8020 Arg_External => External,
8021 Arg_Size => Size);
8022 end Export_Object;
8023
8024 ----------------------
8025 -- Export_Procedure --
8026 ----------------------
8027
8028 -- pragma Export_Procedure (
8029 -- [Internal =>] LOCAL_NAME
8030 -- [, [External =>] EXTERNAL_SYMBOL]
8031 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8032 -- [, [Mechanism =>] MECHANISM]);
8033
8034 -- EXTERNAL_SYMBOL ::=
8035 -- IDENTIFIER
8036 -- | static_string_EXPRESSION
8037
8038 -- PARAMETER_TYPES ::=
8039 -- null
8040 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8041
8042 -- TYPE_DESIGNATOR ::=
8043 -- subtype_NAME
8044 -- | subtype_Name ' Access
8045
8046 -- MECHANISM ::=
8047 -- MECHANISM_NAME
8048 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8049
8050 -- MECHANISM_ASSOCIATION ::=
8051 -- [formal_parameter_NAME =>] MECHANISM_NAME
8052
8053 -- MECHANISM_NAME ::=
8054 -- Value
8055 -- | Reference
8056 -- | Descriptor [([Class =>] CLASS_NAME)]
8057
8058 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8059
8060 when Pragma_Export_Procedure => Export_Procedure : declare
8061 Args : Args_List (1 .. 4);
8062 Names : constant Name_List (1 .. 4) := (
8063 Name_Internal,
8064 Name_External,
8065 Name_Parameter_Types,
8066 Name_Mechanism);
8067
8068 Internal : Node_Id renames Args (1);
8069 External : Node_Id renames Args (2);
8070 Parameter_Types : Node_Id renames Args (3);
8071 Mechanism : Node_Id renames Args (4);
8072
8073 begin
8074 GNAT_Pragma;
8075 Gather_Associations (Names, Args);
8076 Process_Extended_Import_Export_Subprogram_Pragma (
8077 Arg_Internal => Internal,
8078 Arg_External => External,
8079 Arg_Parameter_Types => Parameter_Types,
8080 Arg_Mechanism => Mechanism);
8081 end Export_Procedure;
8082
8083 ------------------
8084 -- Export_Value --
8085 ------------------
8086
8087 -- pragma Export_Value (
8088 -- [Value =>] static_integer_EXPRESSION,
8089 -- [Link_Name =>] static_string_EXPRESSION);
8090
8091 when Pragma_Export_Value =>
8092 GNAT_Pragma;
8093 Check_Arg_Order ((Name_Value, Name_Link_Name));
8094 Check_Arg_Count (2);
8095
8096 Check_Optional_Identifier (Arg1, Name_Value);
8097 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8098
8099 Check_Optional_Identifier (Arg2, Name_Link_Name);
8100 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8101
8102 -----------------------------
8103 -- Export_Valued_Procedure --
8104 -----------------------------
8105
8106 -- pragma Export_Valued_Procedure (
8107 -- [Internal =>] LOCAL_NAME
8108 -- [, [External =>] EXTERNAL_SYMBOL,]
8109 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8110 -- [, [Mechanism =>] MECHANISM]);
8111
8112 -- EXTERNAL_SYMBOL ::=
8113 -- IDENTIFIER
8114 -- | static_string_EXPRESSION
8115
8116 -- PARAMETER_TYPES ::=
8117 -- null
8118 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8119
8120 -- TYPE_DESIGNATOR ::=
8121 -- subtype_NAME
8122 -- | subtype_Name ' Access
8123
8124 -- MECHANISM ::=
8125 -- MECHANISM_NAME
8126 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8127
8128 -- MECHANISM_ASSOCIATION ::=
8129 -- [formal_parameter_NAME =>] MECHANISM_NAME
8130
8131 -- MECHANISM_NAME ::=
8132 -- Value
8133 -- | Reference
8134 -- | Descriptor [([Class =>] CLASS_NAME)]
8135
8136 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8137
8138 when Pragma_Export_Valued_Procedure =>
8139 Export_Valued_Procedure : declare
8140 Args : Args_List (1 .. 4);
8141 Names : constant Name_List (1 .. 4) := (
8142 Name_Internal,
8143 Name_External,
8144 Name_Parameter_Types,
8145 Name_Mechanism);
8146
8147 Internal : Node_Id renames Args (1);
8148 External : Node_Id renames Args (2);
8149 Parameter_Types : Node_Id renames Args (3);
8150 Mechanism : Node_Id renames Args (4);
8151
8152 begin
8153 GNAT_Pragma;
8154 Gather_Associations (Names, Args);
8155 Process_Extended_Import_Export_Subprogram_Pragma (
8156 Arg_Internal => Internal,
8157 Arg_External => External,
8158 Arg_Parameter_Types => Parameter_Types,
8159 Arg_Mechanism => Mechanism);
8160 end Export_Valued_Procedure;
8161
8162 -------------------
8163 -- Extend_System --
8164 -------------------
8165
8166 -- pragma Extend_System ([Name =>] Identifier);
8167
8168 when Pragma_Extend_System => Extend_System : declare
8169 begin
8170 GNAT_Pragma;
8171 Check_Valid_Configuration_Pragma;
8172 Check_Arg_Count (1);
8173 Check_Optional_Identifier (Arg1, Name_Name);
8174 Check_Arg_Is_Identifier (Arg1);
8175
8176 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8177
8178 if Name_Len > 4
8179 and then Name_Buffer (1 .. 4) = "aux_"
8180 then
8181 if Present (System_Extend_Pragma_Arg) then
8182 if Chars (Get_Pragma_Arg (Arg1)) =
8183 Chars (Expression (System_Extend_Pragma_Arg))
8184 then
8185 null;
8186 else
8187 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8188 Error_Pragma ("pragma% conflicts with that #");
8189 end if;
8190
8191 else
8192 System_Extend_Pragma_Arg := Arg1;
8193
8194 if not GNAT_Mode then
8195 System_Extend_Unit := Arg1;
8196 end if;
8197 end if;
8198 else
8199 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8200 end if;
8201 end Extend_System;
8202
8203 ------------------------
8204 -- Extensions_Allowed --
8205 ------------------------
8206
8207 -- pragma Extensions_Allowed (ON | OFF);
8208
8209 when Pragma_Extensions_Allowed =>
8210 GNAT_Pragma;
8211 Check_Arg_Count (1);
8212 Check_No_Identifiers;
8213 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8214
8215 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8216 Extensions_Allowed := True;
8217 Ada_Version := Ada_Version_Type'Last;
8218
8219 else
8220 Extensions_Allowed := False;
8221 Ada_Version := Ada_Version_Explicit;
8222 end if;
8223
8224 --------------
8225 -- External --
8226 --------------
8227
8228 -- pragma External (
8229 -- [ Convention =>] convention_IDENTIFIER,
8230 -- [ Entity =>] local_NAME
8231 -- [, [External_Name =>] static_string_EXPRESSION ]
8232 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8233
8234 when Pragma_External => External : declare
8235 Def_Id : Entity_Id;
8236
8237 C : Convention_Id;
8238 pragma Warnings (Off, C);
8239
8240 begin
8241 GNAT_Pragma;
8242 Check_Arg_Order
8243 ((Name_Convention,
8244 Name_Entity,
8245 Name_External_Name,
8246 Name_Link_Name));
8247 Check_At_Least_N_Arguments (2);
8248 Check_At_Most_N_Arguments (4);
8249 Process_Convention (C, Def_Id);
8250 Note_Possible_Modification
8251 (Get_Pragma_Arg (Arg2), Sure => False);
8252 Process_Interface_Name (Def_Id, Arg3, Arg4);
8253 Set_Exported (Def_Id, Arg2);
8254 end External;
8255
8256 --------------------------
8257 -- External_Name_Casing --
8258 --------------------------
8259
8260 -- pragma External_Name_Casing (
8261 -- UPPERCASE | LOWERCASE
8262 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8263
8264 when Pragma_External_Name_Casing => External_Name_Casing : declare
8265 begin
8266 GNAT_Pragma;
8267 Check_No_Identifiers;
8268
8269 if Arg_Count = 2 then
8270 Check_Arg_Is_One_Of
8271 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8272
8273 case Chars (Get_Pragma_Arg (Arg2)) is
8274 when Name_As_Is =>
8275 Opt.External_Name_Exp_Casing := As_Is;
8276
8277 when Name_Uppercase =>
8278 Opt.External_Name_Exp_Casing := Uppercase;
8279
8280 when Name_Lowercase =>
8281 Opt.External_Name_Exp_Casing := Lowercase;
8282
8283 when others =>
8284 null;
8285 end case;
8286
8287 else
8288 Check_Arg_Count (1);
8289 end if;
8290
8291 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8292
8293 case Chars (Get_Pragma_Arg (Arg1)) is
8294 when Name_Uppercase =>
8295 Opt.External_Name_Imp_Casing := Uppercase;
8296
8297 when Name_Lowercase =>
8298 Opt.External_Name_Imp_Casing := Lowercase;
8299
8300 when others =>
8301 null;
8302 end case;
8303 end External_Name_Casing;
8304
8305 --------------------------
8306 -- Favor_Top_Level --
8307 --------------------------
8308
8309 -- pragma Favor_Top_Level (type_NAME);
8310
8311 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8312 Named_Entity : Entity_Id;
8313
8314 begin
8315 GNAT_Pragma;
8316 Check_No_Identifiers;
8317 Check_Arg_Count (1);
8318 Check_Arg_Is_Local_Name (Arg1);
8319 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8320
8321 -- If it's an access-to-subprogram type (in particular, not a
8322 -- subtype), set the flag on that type.
8323
8324 if Is_Access_Subprogram_Type (Named_Entity) then
8325 Set_Can_Use_Internal_Rep (Named_Entity, False);
8326
8327 -- Otherwise it's an error (name denotes the wrong sort of entity)
8328
8329 else
8330 Error_Pragma_Arg
8331 ("access-to-subprogram type expected",
8332 Get_Pragma_Arg (Arg1));
8333 end if;
8334 end Favor_Top_Level;
8335
8336 ---------------
8337 -- Fast_Math --
8338 ---------------
8339
8340 -- pragma Fast_Math;
8341
8342 when Pragma_Fast_Math =>
8343 GNAT_Pragma;
8344 Check_No_Identifiers;
8345 Check_Valid_Configuration_Pragma;
8346 Fast_Math := True;
8347
8348 ---------------------------
8349 -- Finalize_Storage_Only --
8350 ---------------------------
8351
8352 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8353
8354 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8355 Assoc : constant Node_Id := Arg1;
8356 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8357 Typ : Entity_Id;
8358
8359 begin
8360 GNAT_Pragma;
8361 Check_No_Identifiers;
8362 Check_Arg_Count (1);
8363 Check_Arg_Is_Local_Name (Arg1);
8364
8365 Find_Type (Type_Id);
8366 Typ := Entity (Type_Id);
8367
8368 if Typ = Any_Type
8369 or else Rep_Item_Too_Early (Typ, N)
8370 then
8371 return;
8372 else
8373 Typ := Underlying_Type (Typ);
8374 end if;
8375
8376 if not Is_Controlled (Typ) then
8377 Error_Pragma ("pragma% must specify controlled type");
8378 end if;
8379
8380 Check_First_Subtype (Arg1);
8381
8382 if Finalize_Storage_Only (Typ) then
8383 Error_Pragma ("duplicate pragma%, only one allowed");
8384
8385 elsif not Rep_Item_Too_Late (Typ, N) then
8386 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8387 end if;
8388 end Finalize_Storage;
8389
8390 --------------------------
8391 -- Float_Representation --
8392 --------------------------
8393
8394 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8395
8396 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8397
8398 when Pragma_Float_Representation => Float_Representation : declare
8399 Argx : Node_Id;
8400 Digs : Nat;
8401 Ent : Entity_Id;
8402
8403 begin
8404 GNAT_Pragma;
8405
8406 if Arg_Count = 1 then
8407 Check_Valid_Configuration_Pragma;
8408 else
8409 Check_Arg_Count (2);
8410 Check_Optional_Identifier (Arg2, Name_Entity);
8411 Check_Arg_Is_Local_Name (Arg2);
8412 end if;
8413
8414 Check_No_Identifier (Arg1);
8415 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8416
8417 if not OpenVMS_On_Target then
8418 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8419 Error_Pragma
8420 ("?pragma% ignored (applies only to Open'V'M'S)");
8421 end if;
8422
8423 return;
8424 end if;
8425
8426 -- One argument case
8427
8428 if Arg_Count = 1 then
8429 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8430 if Opt.Float_Format = 'I' then
8431 Error_Pragma ("'I'E'E'E format previously specified");
8432 end if;
8433
8434 Opt.Float_Format := 'V';
8435
8436 else
8437 if Opt.Float_Format = 'V' then
8438 Error_Pragma ("'V'A'X format previously specified");
8439 end if;
8440
8441 Opt.Float_Format := 'I';
8442 end if;
8443
8444 Set_Standard_Fpt_Formats;
8445
8446 -- Two argument case
8447
8448 else
8449 Argx := Get_Pragma_Arg (Arg2);
8450
8451 if not Is_Entity_Name (Argx)
8452 or else not Is_Floating_Point_Type (Entity (Argx))
8453 then
8454 Error_Pragma_Arg
8455 ("second argument of% pragma must be floating-point type",
8456 Arg2);
8457 end if;
8458
8459 Ent := Entity (Argx);
8460 Digs := UI_To_Int (Digits_Value (Ent));
8461
8462 -- Two arguments, VAX_Float case
8463
8464 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8465 case Digs is
8466 when 6 => Set_F_Float (Ent);
8467 when 9 => Set_D_Float (Ent);
8468 when 15 => Set_G_Float (Ent);
8469
8470 when others =>
8471 Error_Pragma_Arg
8472 ("wrong digits value, must be 6,9 or 15", Arg2);
8473 end case;
8474
8475 -- Two arguments, IEEE_Float case
8476
8477 else
8478 case Digs is
8479 when 6 => Set_IEEE_Short (Ent);
8480 when 15 => Set_IEEE_Long (Ent);
8481
8482 when others =>
8483 Error_Pragma_Arg
8484 ("wrong digits value, must be 6 or 15", Arg2);
8485 end case;
8486 end if;
8487 end if;
8488 end Float_Representation;
8489
8490 -----------
8491 -- Ident --
8492 -----------
8493
8494 -- pragma Ident (static_string_EXPRESSION)
8495
8496 -- Note: pragma Comment shares this processing. Pragma Comment is
8497 -- identical to Ident, except that the restriction of the argument to
8498 -- 31 characters and the placement restrictions are not enforced for
8499 -- pragma Comment.
8500
8501 when Pragma_Ident | Pragma_Comment => Ident : declare
8502 Str : Node_Id;
8503
8504 begin
8505 GNAT_Pragma;
8506 Check_Arg_Count (1);
8507 Check_No_Identifiers;
8508 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8509 Store_Note (N);
8510
8511 -- For pragma Ident, preserve DEC compatibility by requiring the
8512 -- pragma to appear in a declarative part or package spec.
8513
8514 if Prag_Id = Pragma_Ident then
8515 Check_Is_In_Decl_Part_Or_Package_Spec;
8516 end if;
8517
8518 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8519
8520 declare
8521 CS : Node_Id;
8522 GP : Node_Id;
8523
8524 begin
8525 GP := Parent (Parent (N));
8526
8527 if Nkind_In (GP, N_Package_Declaration,
8528 N_Generic_Package_Declaration)
8529 then
8530 GP := Parent (GP);
8531 end if;
8532
8533 -- If we have a compilation unit, then record the ident value,
8534 -- checking for improper duplication.
8535
8536 if Nkind (GP) = N_Compilation_Unit then
8537 CS := Ident_String (Current_Sem_Unit);
8538
8539 if Present (CS) then
8540
8541 -- For Ident, we do not permit multiple instances
8542
8543 if Prag_Id = Pragma_Ident then
8544 Error_Pragma ("duplicate% pragma not permitted");
8545
8546 -- For Comment, we concatenate the string, unless we want
8547 -- to preserve the tree structure for ASIS.
8548
8549 elsif not ASIS_Mode then
8550 Start_String (Strval (CS));
8551 Store_String_Char (' ');
8552 Store_String_Chars (Strval (Str));
8553 Set_Strval (CS, End_String);
8554 end if;
8555
8556 else
8557 -- In VMS, the effect of IDENT is achieved by passing
8558 -- --identification=name as a --for-linker switch.
8559
8560 if OpenVMS_On_Target then
8561 Start_String;
8562 Store_String_Chars
8563 ("--for-linker=--identification=");
8564 String_To_Name_Buffer (Strval (Str));
8565 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8566
8567 -- Only the last processed IDENT is saved. The main
8568 -- purpose is so an IDENT associated with a main
8569 -- procedure will be used in preference to an IDENT
8570 -- associated with a with'd package.
8571
8572 Replace_Linker_Option_String
8573 (End_String, "--for-linker=--identification=");
8574 end if;
8575
8576 Set_Ident_String (Current_Sem_Unit, Str);
8577 end if;
8578
8579 -- For subunits, we just ignore the Ident, since in GNAT these
8580 -- are not separate object files, and hence not separate units
8581 -- in the unit table.
8582
8583 elsif Nkind (GP) = N_Subunit then
8584 null;
8585
8586 -- Otherwise we have a misplaced pragma Ident, but we ignore
8587 -- this if we are in an instantiation, since it comes from
8588 -- a generic, and has no relevance to the instantiation.
8589
8590 elsif Prag_Id = Pragma_Ident then
8591 if Instantiation_Location (Loc) = No_Location then
8592 Error_Pragma ("pragma% only allowed at outer level");
8593 end if;
8594 end if;
8595 end;
8596 end Ident;
8597
8598 -----------------
8599 -- Implemented --
8600 -----------------
8601
8602 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8603 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8604
8605 when Pragma_Implemented => Implemented : declare
8606 Proc_Id : Entity_Id;
8607 Typ : Entity_Id;
8608
8609 begin
8610 Ada_2012_Pragma;
8611 Check_Arg_Count (2);
8612 Check_No_Identifiers;
8613 Check_Arg_Is_Identifier (Arg1);
8614 Check_Arg_Is_Local_Name (Arg1);
8615 Check_Arg_Is_One_Of
8616 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8617
8618 -- Extract the name of the local procedure
8619
8620 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8621
8622 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8623 -- primitive procedure of a synchronized tagged type.
8624
8625 if Ekind (Proc_Id) = E_Procedure
8626 and then Is_Primitive (Proc_Id)
8627 and then Present (First_Formal (Proc_Id))
8628 then
8629 Typ := Etype (First_Formal (Proc_Id));
8630
8631 if Is_Tagged_Type (Typ)
8632 and then
8633
8634 -- Check for a protected, a synchronized or a task interface
8635
8636 ((Is_Interface (Typ)
8637 and then Is_Synchronized_Interface (Typ))
8638
8639 -- Check for a protected type or a task type that implements
8640 -- an interface.
8641
8642 or else
8643 (Is_Concurrent_Record_Type (Typ)
8644 and then Present (Interfaces (Typ)))
8645
8646 -- Check for a private record extension with keyword
8647 -- "synchronized".
8648
8649 or else
8650 (Ekind_In (Typ, E_Record_Type_With_Private,
8651 E_Record_Subtype_With_Private)
8652 and then Synchronized_Present (Parent (Typ))))
8653 then
8654 null;
8655 else
8656 Error_Pragma_Arg
8657 ("controlling formal must be of synchronized " &
8658 "tagged type", Arg1);
8659 return;
8660 end if;
8661
8662 -- Procedures declared inside a protected type must be accepted
8663
8664 elsif Ekind (Proc_Id) = E_Procedure
8665 and then Is_Protected_Type (Scope (Proc_Id))
8666 then
8667 null;
8668
8669 -- The first argument is not a primitive procedure
8670
8671 else
8672 Error_Pragma_Arg
8673 ("pragma % must be applied to a primitive procedure", Arg1);
8674 return;
8675 end if;
8676
8677 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8678 -- By_Protected_Procedure to the primitive procedure of a task
8679 -- interface.
8680
8681 if Chars (Arg2) = Name_By_Protected_Procedure
8682 and then Is_Interface (Typ)
8683 and then Is_Task_Interface (Typ)
8684 then
8685 Error_Pragma_Arg
8686 ("implementation kind By_Protected_Procedure cannot be " &
8687 "applied to a task interface primitive", Arg2);
8688 return;
8689 end if;
8690
8691 Record_Rep_Item (Proc_Id, N);
8692 end Implemented;
8693
8694 ----------------------
8695 -- Implicit_Packing --
8696 ----------------------
8697
8698 -- pragma Implicit_Packing;
8699
8700 when Pragma_Implicit_Packing =>
8701 GNAT_Pragma;
8702 Check_Arg_Count (0);
8703 Implicit_Packing := True;
8704
8705 ------------
8706 -- Import --
8707 ------------
8708
8709 -- pragma Import (
8710 -- [Convention =>] convention_IDENTIFIER,
8711 -- [Entity =>] local_NAME
8712 -- [, [External_Name =>] static_string_EXPRESSION ]
8713 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8714
8715 when Pragma_Import =>
8716 Check_Ada_83_Warning;
8717 Check_Arg_Order
8718 ((Name_Convention,
8719 Name_Entity,
8720 Name_External_Name,
8721 Name_Link_Name));
8722 Check_At_Least_N_Arguments (2);
8723 Check_At_Most_N_Arguments (4);
8724 Process_Import_Or_Interface;
8725
8726 ----------------------
8727 -- Import_Exception --
8728 ----------------------
8729
8730 -- pragma Import_Exception (
8731 -- [Internal =>] LOCAL_NAME
8732 -- [, [External =>] EXTERNAL_SYMBOL]
8733 -- [, [Form =>] Ada | VMS]
8734 -- [, [Code =>] static_integer_EXPRESSION]);
8735
8736 when Pragma_Import_Exception => Import_Exception : declare
8737 Args : Args_List (1 .. 4);
8738 Names : constant Name_List (1 .. 4) := (
8739 Name_Internal,
8740 Name_External,
8741 Name_Form,
8742 Name_Code);
8743
8744 Internal : Node_Id renames Args (1);
8745 External : Node_Id renames Args (2);
8746 Form : Node_Id renames Args (3);
8747 Code : Node_Id renames Args (4);
8748
8749 begin
8750 GNAT_Pragma;
8751 Gather_Associations (Names, Args);
8752
8753 if Present (External) and then Present (Code) then
8754 Error_Pragma
8755 ("cannot give both External and Code options for pragma%");
8756 end if;
8757
8758 Process_Extended_Import_Export_Exception_Pragma (
8759 Arg_Internal => Internal,
8760 Arg_External => External,
8761 Arg_Form => Form,
8762 Arg_Code => Code);
8763
8764 if not Is_VMS_Exception (Entity (Internal)) then
8765 Set_Imported (Entity (Internal));
8766 end if;
8767 end Import_Exception;
8768
8769 ---------------------
8770 -- Import_Function --
8771 ---------------------
8772
8773 -- pragma Import_Function (
8774 -- [Internal =>] LOCAL_NAME,
8775 -- [, [External =>] EXTERNAL_SYMBOL]
8776 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8777 -- [, [Result_Type =>] SUBTYPE_MARK]
8778 -- [, [Mechanism =>] MECHANISM]
8779 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8780 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8781
8782 -- EXTERNAL_SYMBOL ::=
8783 -- IDENTIFIER
8784 -- | static_string_EXPRESSION
8785
8786 -- PARAMETER_TYPES ::=
8787 -- null
8788 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8789
8790 -- TYPE_DESIGNATOR ::=
8791 -- subtype_NAME
8792 -- | subtype_Name ' Access
8793
8794 -- MECHANISM ::=
8795 -- MECHANISM_NAME
8796 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8797
8798 -- MECHANISM_ASSOCIATION ::=
8799 -- [formal_parameter_NAME =>] MECHANISM_NAME
8800
8801 -- MECHANISM_NAME ::=
8802 -- Value
8803 -- | Reference
8804 -- | Descriptor [([Class =>] CLASS_NAME)]
8805
8806 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8807
8808 when Pragma_Import_Function => Import_Function : declare
8809 Args : Args_List (1 .. 7);
8810 Names : constant Name_List (1 .. 7) := (
8811 Name_Internal,
8812 Name_External,
8813 Name_Parameter_Types,
8814 Name_Result_Type,
8815 Name_Mechanism,
8816 Name_Result_Mechanism,
8817 Name_First_Optional_Parameter);
8818
8819 Internal : Node_Id renames Args (1);
8820 External : Node_Id renames Args (2);
8821 Parameter_Types : Node_Id renames Args (3);
8822 Result_Type : Node_Id renames Args (4);
8823 Mechanism : Node_Id renames Args (5);
8824 Result_Mechanism : Node_Id renames Args (6);
8825 First_Optional_Parameter : Node_Id renames Args (7);
8826
8827 begin
8828 GNAT_Pragma;
8829 Gather_Associations (Names, Args);
8830 Process_Extended_Import_Export_Subprogram_Pragma (
8831 Arg_Internal => Internal,
8832 Arg_External => External,
8833 Arg_Parameter_Types => Parameter_Types,
8834 Arg_Result_Type => Result_Type,
8835 Arg_Mechanism => Mechanism,
8836 Arg_Result_Mechanism => Result_Mechanism,
8837 Arg_First_Optional_Parameter => First_Optional_Parameter);
8838 end Import_Function;
8839
8840 -------------------
8841 -- Import_Object --
8842 -------------------
8843
8844 -- pragma Import_Object (
8845 -- [Internal =>] LOCAL_NAME
8846 -- [, [External =>] EXTERNAL_SYMBOL]
8847 -- [, [Size =>] EXTERNAL_SYMBOL]);
8848
8849 -- EXTERNAL_SYMBOL ::=
8850 -- IDENTIFIER
8851 -- | static_string_EXPRESSION
8852
8853 when Pragma_Import_Object => Import_Object : declare
8854 Args : Args_List (1 .. 3);
8855 Names : constant Name_List (1 .. 3) := (
8856 Name_Internal,
8857 Name_External,
8858 Name_Size);
8859
8860 Internal : Node_Id renames Args (1);
8861 External : Node_Id renames Args (2);
8862 Size : Node_Id renames Args (3);
8863
8864 begin
8865 GNAT_Pragma;
8866 Gather_Associations (Names, Args);
8867 Process_Extended_Import_Export_Object_Pragma (
8868 Arg_Internal => Internal,
8869 Arg_External => External,
8870 Arg_Size => Size);
8871 end Import_Object;
8872
8873 ----------------------
8874 -- Import_Procedure --
8875 ----------------------
8876
8877 -- pragma Import_Procedure (
8878 -- [Internal =>] LOCAL_NAME
8879 -- [, [External =>] EXTERNAL_SYMBOL]
8880 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8881 -- [, [Mechanism =>] MECHANISM]
8882 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8883
8884 -- EXTERNAL_SYMBOL ::=
8885 -- IDENTIFIER
8886 -- | static_string_EXPRESSION
8887
8888 -- PARAMETER_TYPES ::=
8889 -- null
8890 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8891
8892 -- TYPE_DESIGNATOR ::=
8893 -- subtype_NAME
8894 -- | subtype_Name ' Access
8895
8896 -- MECHANISM ::=
8897 -- MECHANISM_NAME
8898 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8899
8900 -- MECHANISM_ASSOCIATION ::=
8901 -- [formal_parameter_NAME =>] MECHANISM_NAME
8902
8903 -- MECHANISM_NAME ::=
8904 -- Value
8905 -- | Reference
8906 -- | Descriptor [([Class =>] CLASS_NAME)]
8907
8908 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8909
8910 when Pragma_Import_Procedure => Import_Procedure : declare
8911 Args : Args_List (1 .. 5);
8912 Names : constant Name_List (1 .. 5) := (
8913 Name_Internal,
8914 Name_External,
8915 Name_Parameter_Types,
8916 Name_Mechanism,
8917 Name_First_Optional_Parameter);
8918
8919 Internal : Node_Id renames Args (1);
8920 External : Node_Id renames Args (2);
8921 Parameter_Types : Node_Id renames Args (3);
8922 Mechanism : Node_Id renames Args (4);
8923 First_Optional_Parameter : Node_Id renames Args (5);
8924
8925 begin
8926 GNAT_Pragma;
8927 Gather_Associations (Names, Args);
8928 Process_Extended_Import_Export_Subprogram_Pragma (
8929 Arg_Internal => Internal,
8930 Arg_External => External,
8931 Arg_Parameter_Types => Parameter_Types,
8932 Arg_Mechanism => Mechanism,
8933 Arg_First_Optional_Parameter => First_Optional_Parameter);
8934 end Import_Procedure;
8935
8936 -----------------------------
8937 -- Import_Valued_Procedure --
8938 -----------------------------
8939
8940 -- pragma Import_Valued_Procedure (
8941 -- [Internal =>] LOCAL_NAME
8942 -- [, [External =>] EXTERNAL_SYMBOL]
8943 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8944 -- [, [Mechanism =>] MECHANISM]
8945 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8946
8947 -- EXTERNAL_SYMBOL ::=
8948 -- IDENTIFIER
8949 -- | static_string_EXPRESSION
8950
8951 -- PARAMETER_TYPES ::=
8952 -- null
8953 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8954
8955 -- TYPE_DESIGNATOR ::=
8956 -- subtype_NAME
8957 -- | subtype_Name ' Access
8958
8959 -- MECHANISM ::=
8960 -- MECHANISM_NAME
8961 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8962
8963 -- MECHANISM_ASSOCIATION ::=
8964 -- [formal_parameter_NAME =>] MECHANISM_NAME
8965
8966 -- MECHANISM_NAME ::=
8967 -- Value
8968 -- | Reference
8969 -- | Descriptor [([Class =>] CLASS_NAME)]
8970
8971 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8972
8973 when Pragma_Import_Valued_Procedure =>
8974 Import_Valued_Procedure : declare
8975 Args : Args_List (1 .. 5);
8976 Names : constant Name_List (1 .. 5) := (
8977 Name_Internal,
8978 Name_External,
8979 Name_Parameter_Types,
8980 Name_Mechanism,
8981 Name_First_Optional_Parameter);
8982
8983 Internal : Node_Id renames Args (1);
8984 External : Node_Id renames Args (2);
8985 Parameter_Types : Node_Id renames Args (3);
8986 Mechanism : Node_Id renames Args (4);
8987 First_Optional_Parameter : Node_Id renames Args (5);
8988
8989 begin
8990 GNAT_Pragma;
8991 Gather_Associations (Names, Args);
8992 Process_Extended_Import_Export_Subprogram_Pragma (
8993 Arg_Internal => Internal,
8994 Arg_External => External,
8995 Arg_Parameter_Types => Parameter_Types,
8996 Arg_Mechanism => Mechanism,
8997 Arg_First_Optional_Parameter => First_Optional_Parameter);
8998 end Import_Valued_Procedure;
8999
9000 -----------------
9001 -- Independent --
9002 -----------------
9003
9004 -- pragma Independent (LOCAL_NAME);
9005
9006 when Pragma_Independent => Independent : declare
9007 E_Id : Node_Id;
9008 E : Entity_Id;
9009 D : Node_Id;
9010 K : Node_Kind;
9011
9012 begin
9013 Check_Ada_83_Warning;
9014 Ada_2012_Pragma;
9015 Check_No_Identifiers;
9016 Check_Arg_Count (1);
9017 Check_Arg_Is_Local_Name (Arg1);
9018 E_Id := Get_Pragma_Arg (Arg1);
9019
9020 if Etype (E_Id) = Any_Type then
9021 return;
9022 end if;
9023
9024 E := Entity (E_Id);
9025 D := Declaration_Node (E);
9026 K := Nkind (D);
9027
9028 -- Check duplicate before we chain ourselves!
9029
9030 Check_Duplicate_Pragma (E);
9031
9032 -- Check appropriate entity
9033
9034 if Is_Type (E) then
9035 if Rep_Item_Too_Early (E, N)
9036 or else
9037 Rep_Item_Too_Late (E, N)
9038 then
9039 return;
9040 else
9041 Check_First_Subtype (Arg1);
9042 end if;
9043
9044 elsif K = N_Object_Declaration
9045 or else (K = N_Component_Declaration
9046 and then Original_Record_Component (E) = E)
9047 then
9048 if Rep_Item_Too_Late (E, N) then
9049 return;
9050 end if;
9051
9052 else
9053 Error_Pragma_Arg
9054 ("inappropriate entity for pragma%", Arg1);
9055 end if;
9056
9057 Independence_Checks.Append ((N, E));
9058 end Independent;
9059
9060 ----------------------------
9061 -- Independent_Components --
9062 ----------------------------
9063
9064 -- pragma Atomic_Components (array_LOCAL_NAME);
9065
9066 -- This processing is shared by Volatile_Components
9067
9068 when Pragma_Independent_Components => Independent_Components : declare
9069 E_Id : Node_Id;
9070 E : Entity_Id;
9071 D : Node_Id;
9072 K : Node_Kind;
9073
9074 begin
9075 Check_Ada_83_Warning;
9076 Ada_2012_Pragma;
9077 Check_No_Identifiers;
9078 Check_Arg_Count (1);
9079 Check_Arg_Is_Local_Name (Arg1);
9080 E_Id := Get_Pragma_Arg (Arg1);
9081
9082 if Etype (E_Id) = Any_Type then
9083 return;
9084 end if;
9085
9086 E := Entity (E_Id);
9087
9088 -- Check duplicate before we chain ourselves!
9089
9090 Check_Duplicate_Pragma (E);
9091
9092 -- Check appropriate entity
9093
9094 if Rep_Item_Too_Early (E, N)
9095 or else
9096 Rep_Item_Too_Late (E, N)
9097 then
9098 return;
9099 end if;
9100
9101 D := Declaration_Node (E);
9102 K := Nkind (D);
9103
9104 if (K = N_Full_Type_Declaration
9105 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9106 or else
9107 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9108 and then Nkind (D) = N_Object_Declaration
9109 and then Nkind (Object_Definition (D)) =
9110 N_Constrained_Array_Definition)
9111 then
9112 Independence_Checks.Append ((N, E));
9113
9114 else
9115 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9116 end if;
9117 end Independent_Components;
9118
9119 ------------------------
9120 -- Initialize_Scalars --
9121 ------------------------
9122
9123 -- pragma Initialize_Scalars;
9124
9125 when Pragma_Initialize_Scalars =>
9126 GNAT_Pragma;
9127 Check_Arg_Count (0);
9128 Check_Valid_Configuration_Pragma;
9129 Check_Restriction (No_Initialize_Scalars, N);
9130
9131 -- Initialize_Scalars creates false positives in CodePeer,
9132 -- so ignore this pragma in this mode.
9133
9134 if not Restriction_Active (No_Initialize_Scalars)
9135 and then not CodePeer_Mode
9136 then
9137 Init_Or_Norm_Scalars := True;
9138 Initialize_Scalars := True;
9139 end if;
9140
9141 ------------
9142 -- Inline --
9143 ------------
9144
9145 -- pragma Inline ( NAME {, NAME} );
9146
9147 when Pragma_Inline =>
9148
9149 -- Pragma is active if inlining option is active
9150
9151 Process_Inline (Inline_Active);
9152
9153 -------------------
9154 -- Inline_Always --
9155 -------------------
9156
9157 -- pragma Inline_Always ( NAME {, NAME} );
9158
9159 when Pragma_Inline_Always =>
9160 GNAT_Pragma;
9161
9162 -- Pragma always active unless in CodePeer mode, since this causes
9163 -- walk order issues.
9164
9165 if not CodePeer_Mode then
9166 Process_Inline (True);
9167 end if;
9168
9169 --------------------
9170 -- Inline_Generic --
9171 --------------------
9172
9173 -- pragma Inline_Generic (NAME {, NAME});
9174
9175 when Pragma_Inline_Generic =>
9176 GNAT_Pragma;
9177 Process_Generic_List;
9178
9179 ----------------------
9180 -- Inspection_Point --
9181 ----------------------
9182
9183 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9184
9185 when Pragma_Inspection_Point => Inspection_Point : declare
9186 Arg : Node_Id;
9187 Exp : Node_Id;
9188
9189 begin
9190 if Arg_Count > 0 then
9191 Arg := Arg1;
9192 loop
9193 Exp := Get_Pragma_Arg (Arg);
9194 Analyze (Exp);
9195
9196 if not Is_Entity_Name (Exp)
9197 or else not Is_Object (Entity (Exp))
9198 then
9199 Error_Pragma_Arg ("object name required", Arg);
9200 end if;
9201
9202 Next (Arg);
9203 exit when No (Arg);
9204 end loop;
9205 end if;
9206 end Inspection_Point;
9207
9208 ---------------
9209 -- Interface --
9210 ---------------
9211
9212 -- pragma Interface (
9213 -- [ Convention =>] convention_IDENTIFIER,
9214 -- [ Entity =>] local_NAME
9215 -- [, [External_Name =>] static_string_EXPRESSION ]
9216 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9217
9218 when Pragma_Interface =>
9219 GNAT_Pragma;
9220 Check_Arg_Order
9221 ((Name_Convention,
9222 Name_Entity,
9223 Name_External_Name,
9224 Name_Link_Name));
9225 Check_At_Least_N_Arguments (2);
9226 Check_At_Most_N_Arguments (4);
9227 Process_Import_Or_Interface;
9228
9229 -- In Ada 2005, the permission to use Interface (a reserved word)
9230 -- as a pragma name is considered an obsolescent feature.
9231
9232 if Ada_Version >= Ada_2005 then
9233 Check_Restriction
9234 (No_Obsolescent_Features, Pragma_Identifier (N));
9235 end if;
9236
9237 --------------------
9238 -- Interface_Name --
9239 --------------------
9240
9241 -- pragma Interface_Name (
9242 -- [ Entity =>] local_NAME
9243 -- [,[External_Name =>] static_string_EXPRESSION ]
9244 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9245
9246 when Pragma_Interface_Name => Interface_Name : declare
9247 Id : Node_Id;
9248 Def_Id : Entity_Id;
9249 Hom_Id : Entity_Id;
9250 Found : Boolean;
9251
9252 begin
9253 GNAT_Pragma;
9254 Check_Arg_Order
9255 ((Name_Entity, Name_External_Name, Name_Link_Name));
9256 Check_At_Least_N_Arguments (2);
9257 Check_At_Most_N_Arguments (3);
9258 Id := Get_Pragma_Arg (Arg1);
9259 Analyze (Id);
9260
9261 if not Is_Entity_Name (Id) then
9262 Error_Pragma_Arg
9263 ("first argument for pragma% must be entity name", Arg1);
9264 elsif Etype (Id) = Any_Type then
9265 return;
9266 else
9267 Def_Id := Entity (Id);
9268 end if;
9269
9270 -- Special DEC-compatible processing for the object case, forces
9271 -- object to be imported.
9272
9273 if Ekind (Def_Id) = E_Variable then
9274 Kill_Size_Check_Code (Def_Id);
9275 Note_Possible_Modification (Id, Sure => False);
9276
9277 -- Initialization is not allowed for imported variable
9278
9279 if Present (Expression (Parent (Def_Id)))
9280 and then Comes_From_Source (Expression (Parent (Def_Id)))
9281 then
9282 Error_Msg_Sloc := Sloc (Def_Id);
9283 Error_Pragma_Arg
9284 ("no initialization allowed for declaration of& #",
9285 Arg2);
9286
9287 else
9288 -- For compatibility, support VADS usage of providing both
9289 -- pragmas Interface and Interface_Name to obtain the effect
9290 -- of a single Import pragma.
9291
9292 if Is_Imported (Def_Id)
9293 and then Present (First_Rep_Item (Def_Id))
9294 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9295 and then
9296 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9297 then
9298 null;
9299 else
9300 Set_Imported (Def_Id);
9301 end if;
9302
9303 Set_Is_Public (Def_Id);
9304 Process_Interface_Name (Def_Id, Arg2, Arg3);
9305 end if;
9306
9307 -- Otherwise must be subprogram
9308
9309 elsif not Is_Subprogram (Def_Id) then
9310 Error_Pragma_Arg
9311 ("argument of pragma% is not subprogram", Arg1);
9312
9313 else
9314 Check_At_Most_N_Arguments (3);
9315 Hom_Id := Def_Id;
9316 Found := False;
9317
9318 -- Loop through homonyms
9319
9320 loop
9321 Def_Id := Get_Base_Subprogram (Hom_Id);
9322
9323 if Is_Imported (Def_Id) then
9324 Process_Interface_Name (Def_Id, Arg2, Arg3);
9325 Found := True;
9326 end if;
9327
9328 exit when From_Aspect_Specification (N);
9329 Hom_Id := Homonym (Hom_Id);
9330
9331 exit when No (Hom_Id)
9332 or else Scope (Hom_Id) /= Current_Scope;
9333 end loop;
9334
9335 if not Found then
9336 Error_Pragma_Arg
9337 ("argument of pragma% is not imported subprogram",
9338 Arg1);
9339 end if;
9340 end if;
9341 end Interface_Name;
9342
9343 -----------------------
9344 -- Interrupt_Handler --
9345 -----------------------
9346
9347 -- pragma Interrupt_Handler (handler_NAME);
9348
9349 when Pragma_Interrupt_Handler =>
9350 Check_Ada_83_Warning;
9351 Check_Arg_Count (1);
9352 Check_No_Identifiers;
9353
9354 if No_Run_Time_Mode then
9355 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9356 else
9357 Check_Interrupt_Or_Attach_Handler;
9358 Process_Interrupt_Or_Attach_Handler;
9359 end if;
9360
9361 ------------------------
9362 -- Interrupt_Priority --
9363 ------------------------
9364
9365 -- pragma Interrupt_Priority [(EXPRESSION)];
9366
9367 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9368 P : constant Node_Id := Parent (N);
9369 Arg : Node_Id;
9370
9371 begin
9372 Check_Ada_83_Warning;
9373
9374 if Arg_Count /= 0 then
9375 Arg := Get_Pragma_Arg (Arg1);
9376 Check_Arg_Count (1);
9377 Check_No_Identifiers;
9378
9379 -- The expression must be analyzed in the special manner
9380 -- described in "Handling of Default and Per-Object
9381 -- Expressions" in sem.ads.
9382
9383 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9384 end if;
9385
9386 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9387 Pragma_Misplaced;
9388 return;
9389
9390 elsif Has_Pragma_Priority (P) then
9391 Error_Pragma ("duplicate pragma% not allowed");
9392
9393 else
9394 Set_Has_Pragma_Priority (P, True);
9395 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9396 end if;
9397 end Interrupt_Priority;
9398
9399 ---------------------
9400 -- Interrupt_State --
9401 ---------------------
9402
9403 -- pragma Interrupt_State (
9404 -- [Name =>] INTERRUPT_ID,
9405 -- [State =>] INTERRUPT_STATE);
9406
9407 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9408 -- INTERRUPT_STATE => System | Runtime | User
9409
9410 -- Note: if the interrupt id is given as an identifier, then it must
9411 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9412 -- given as a static integer expression which must be in the range of
9413 -- Ada.Interrupts.Interrupt_ID.
9414
9415 when Pragma_Interrupt_State => Interrupt_State : declare
9416
9417 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9418 -- This is the entity Ada.Interrupts.Interrupt_ID;
9419
9420 State_Type : Character;
9421 -- Set to 's'/'r'/'u' for System/Runtime/User
9422
9423 IST_Num : Pos;
9424 -- Index to entry in Interrupt_States table
9425
9426 Int_Val : Uint;
9427 -- Value of interrupt
9428
9429 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9430 -- The first argument to the pragma
9431
9432 Int_Ent : Entity_Id;
9433 -- Interrupt entity in Ada.Interrupts.Names
9434
9435 begin
9436 GNAT_Pragma;
9437 Check_Arg_Order ((Name_Name, Name_State));
9438 Check_Arg_Count (2);
9439
9440 Check_Optional_Identifier (Arg1, Name_Name);
9441 Check_Optional_Identifier (Arg2, Name_State);
9442 Check_Arg_Is_Identifier (Arg2);
9443
9444 -- First argument is identifier
9445
9446 if Nkind (Arg1X) = N_Identifier then
9447
9448 -- Search list of names in Ada.Interrupts.Names
9449
9450 Int_Ent := First_Entity (RTE (RE_Names));
9451 loop
9452 if No (Int_Ent) then
9453 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9454
9455 elsif Chars (Int_Ent) = Chars (Arg1X) then
9456 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9457 exit;
9458 end if;
9459
9460 Next_Entity (Int_Ent);
9461 end loop;
9462
9463 -- First argument is not an identifier, so it must be a static
9464 -- expression of type Ada.Interrupts.Interrupt_ID.
9465
9466 else
9467 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9468 Int_Val := Expr_Value (Arg1X);
9469
9470 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9471 or else
9472 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9473 then
9474 Error_Pragma_Arg
9475 ("value not in range of type " &
9476 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9477 end if;
9478 end if;
9479
9480 -- Check OK state
9481
9482 case Chars (Get_Pragma_Arg (Arg2)) is
9483 when Name_Runtime => State_Type := 'r';
9484 when Name_System => State_Type := 's';
9485 when Name_User => State_Type := 'u';
9486
9487 when others =>
9488 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9489 end case;
9490
9491 -- Check if entry is already stored
9492
9493 IST_Num := Interrupt_States.First;
9494 loop
9495 -- If entry not found, add it
9496
9497 if IST_Num > Interrupt_States.Last then
9498 Interrupt_States.Append
9499 ((Interrupt_Number => UI_To_Int (Int_Val),
9500 Interrupt_State => State_Type,
9501 Pragma_Loc => Loc));
9502 exit;
9503
9504 -- Case of entry for the same entry
9505
9506 elsif Int_Val = Interrupt_States.Table (IST_Num).
9507 Interrupt_Number
9508 then
9509 -- If state matches, done, no need to make redundant entry
9510
9511 exit when
9512 State_Type = Interrupt_States.Table (IST_Num).
9513 Interrupt_State;
9514
9515 -- Otherwise if state does not match, error
9516
9517 Error_Msg_Sloc :=
9518 Interrupt_States.Table (IST_Num).Pragma_Loc;
9519 Error_Pragma_Arg
9520 ("state conflicts with that given #", Arg2);
9521 exit;
9522 end if;
9523
9524 IST_Num := IST_Num + 1;
9525 end loop;
9526 end Interrupt_State;
9527
9528 ---------------
9529 -- Invariant --
9530 ---------------
9531
9532 -- pragma Invariant
9533 -- ([Entity =>] type_LOCAL_NAME,
9534 -- [Check =>] EXPRESSION
9535 -- [,[Message =>] String_Expression]);
9536
9537 when Pragma_Invariant => Invariant : declare
9538 Type_Id : Node_Id;
9539 Typ : Entity_Id;
9540
9541 Discard : Boolean;
9542 pragma Unreferenced (Discard);
9543
9544 begin
9545 GNAT_Pragma;
9546 Check_At_Least_N_Arguments (2);
9547 Check_At_Most_N_Arguments (3);
9548 Check_Optional_Identifier (Arg1, Name_Entity);
9549 Check_Optional_Identifier (Arg2, Name_Check);
9550
9551 if Arg_Count = 3 then
9552 Check_Optional_Identifier (Arg3, Name_Message);
9553 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9554 end if;
9555
9556 Check_Arg_Is_Local_Name (Arg1);
9557
9558 Type_Id := Get_Pragma_Arg (Arg1);
9559 Find_Type (Type_Id);
9560 Typ := Entity (Type_Id);
9561
9562 if Typ = Any_Type then
9563 return;
9564
9565 elsif not Ekind_In (Typ, E_Private_Type,
9566 E_Record_Type_With_Private,
9567 E_Limited_Private_Type)
9568 then
9569 Error_Pragma_Arg
9570 ("pragma% only allowed for private type", Arg1);
9571 end if;
9572
9573 -- Note that the type has at least one invariant, and also that
9574 -- it has inheritable invariants if we have Invariant'Class.
9575
9576 Set_Has_Invariants (Typ);
9577
9578 if Class_Present (N) then
9579 Set_Has_Inheritable_Invariants (Typ);
9580 end if;
9581
9582 -- The remaining processing is simply to link the pragma on to
9583 -- the rep item chain, for processing when the type is frozen.
9584 -- This is accomplished by a call to Rep_Item_Too_Late.
9585
9586 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9587 end Invariant;
9588
9589 ----------------------
9590 -- Java_Constructor --
9591 ----------------------
9592
9593 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9594
9595 -- Also handles pragma CIL_Constructor
9596
9597 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9598 Java_Constructor : declare
9599 Convention : Convention_Id;
9600 Def_Id : Entity_Id;
9601 Hom_Id : Entity_Id;
9602 Id : Entity_Id;
9603 This_Formal : Entity_Id;
9604
9605 begin
9606 GNAT_Pragma;
9607 Check_Arg_Count (1);
9608 Check_Optional_Identifier (Arg1, Name_Entity);
9609 Check_Arg_Is_Local_Name (Arg1);
9610
9611 Id := Get_Pragma_Arg (Arg1);
9612 Find_Program_Unit_Name (Id);
9613
9614 -- If we did not find the name, we are done
9615
9616 if Etype (Id) = Any_Type then
9617 return;
9618 end if;
9619
9620 -- Check wrong use of pragma in wrong VM target
9621
9622 if VM_Target = No_VM then
9623 return;
9624
9625 elsif VM_Target = CLI_Target
9626 and then Prag_Id = Pragma_Java_Constructor
9627 then
9628 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9629
9630 elsif VM_Target = JVM_Target
9631 and then Prag_Id = Pragma_CIL_Constructor
9632 then
9633 Error_Pragma ("must use pragma 'Java_'Constructor");
9634 end if;
9635
9636 case Prag_Id is
9637 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9638 when Pragma_Java_Constructor => Convention := Convention_Java;
9639 when others => null;
9640 end case;
9641
9642 Hom_Id := Entity (Id);
9643
9644 -- Loop through homonyms
9645
9646 loop
9647 Def_Id := Get_Base_Subprogram (Hom_Id);
9648
9649 -- The constructor is required to be a function
9650
9651 if Ekind (Def_Id) /= E_Function then
9652 if VM_Target = JVM_Target then
9653 Error_Pragma_Arg
9654 ("pragma% requires function returning a " &
9655 "'Java access type", Def_Id);
9656 else
9657 Error_Pragma_Arg
9658 ("pragma% requires function returning a " &
9659 "'C'I'L access type", Def_Id);
9660 end if;
9661 end if;
9662
9663 -- Check arguments: For tagged type the first formal must be
9664 -- named "this" and its type must be a named access type
9665 -- designating a class-wide tagged type that has convention
9666 -- CIL/Java. The first formal must also have a null default
9667 -- value. For example:
9668
9669 -- type Typ is tagged ...
9670 -- type Ref is access all Typ;
9671 -- pragma Convention (CIL, Typ);
9672
9673 -- function New_Typ (This : Ref) return Ref;
9674 -- function New_Typ (This : Ref; I : Integer) return Ref;
9675 -- pragma Cil_Constructor (New_Typ);
9676
9677 -- Reason: The first formal must NOT be a primitive of the
9678 -- tagged type.
9679
9680 -- This rule also applies to constructors of delegates used
9681 -- to interface with standard target libraries. For example:
9682
9683 -- type Delegate is access procedure ...
9684 -- pragma Import (CIL, Delegate, ...);
9685
9686 -- function new_Delegate
9687 -- (This : Delegate := null; ... ) return Delegate;
9688
9689 -- For value-types this rule does not apply.
9690
9691 if not Is_Value_Type (Etype (Def_Id)) then
9692 if No (First_Formal (Def_Id)) then
9693 Error_Msg_Name_1 := Pname;
9694 Error_Msg_N ("% function must have parameters", Def_Id);
9695 return;
9696 end if;
9697
9698 -- In the JRE library we have several occurrences in which
9699 -- the "this" parameter is not the first formal.
9700
9701 This_Formal := First_Formal (Def_Id);
9702
9703 -- In the JRE library we have several occurrences in which
9704 -- the "this" parameter is not the first formal. Search for
9705 -- it.
9706
9707 if VM_Target = JVM_Target then
9708 while Present (This_Formal)
9709 and then Get_Name_String (Chars (This_Formal)) /= "this"
9710 loop
9711 Next_Formal (This_Formal);
9712 end loop;
9713
9714 if No (This_Formal) then
9715 This_Formal := First_Formal (Def_Id);
9716 end if;
9717 end if;
9718
9719 -- Warning: The first parameter should be named "this".
9720 -- We temporarily allow it because we have the following
9721 -- case in the Java runtime (file s-osinte.ads) ???
9722
9723 -- function new_Thread
9724 -- (Self_Id : System.Address) return Thread_Id;
9725 -- pragma Java_Constructor (new_Thread);
9726
9727 if VM_Target = JVM_Target
9728 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9729 = "self_id"
9730 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9731 then
9732 null;
9733
9734 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9735 Error_Msg_Name_1 := Pname;
9736 Error_Msg_N
9737 ("first formal of % function must be named `this`",
9738 Parent (This_Formal));
9739
9740 elsif not Is_Access_Type (Etype (This_Formal)) then
9741 Error_Msg_Name_1 := Pname;
9742 Error_Msg_N
9743 ("first formal of % function must be an access type",
9744 Parameter_Type (Parent (This_Formal)));
9745
9746 -- For delegates the type of the first formal must be a
9747 -- named access-to-subprogram type (see previous example)
9748
9749 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9750 and then Ekind (Etype (This_Formal))
9751 /= E_Access_Subprogram_Type
9752 then
9753 Error_Msg_Name_1 := Pname;
9754 Error_Msg_N
9755 ("first formal of % function must be a named access" &
9756 " to subprogram type",
9757 Parameter_Type (Parent (This_Formal)));
9758
9759 -- Warning: We should reject anonymous access types because
9760 -- the constructor must not be handled as a primitive of the
9761 -- tagged type. We temporarily allow it because this profile
9762 -- is currently generated by cil2ada???
9763
9764 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9765 and then not Ekind_In (Etype (This_Formal),
9766 E_Access_Type,
9767 E_General_Access_Type,
9768 E_Anonymous_Access_Type)
9769 then
9770 Error_Msg_Name_1 := Pname;
9771 Error_Msg_N
9772 ("first formal of % function must be a named access" &
9773 " type",
9774 Parameter_Type (Parent (This_Formal)));
9775
9776 elsif Atree.Convention
9777 (Designated_Type (Etype (This_Formal))) /= Convention
9778 then
9779 Error_Msg_Name_1 := Pname;
9780
9781 if Convention = Convention_Java then
9782 Error_Msg_N
9783 ("pragma% requires convention 'Cil in designated" &
9784 " type",
9785 Parameter_Type (Parent (This_Formal)));
9786 else
9787 Error_Msg_N
9788 ("pragma% requires convention 'Java in designated" &
9789 " type",
9790 Parameter_Type (Parent (This_Formal)));
9791 end if;
9792
9793 elsif No (Expression (Parent (This_Formal)))
9794 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9795 then
9796 Error_Msg_Name_1 := Pname;
9797 Error_Msg_N
9798 ("pragma% requires first formal with default `null`",
9799 Parameter_Type (Parent (This_Formal)));
9800 end if;
9801 end if;
9802
9803 -- Check result type: the constructor must be a function
9804 -- returning:
9805 -- * a value type (only allowed in the CIL compiler)
9806 -- * an access-to-subprogram type with convention Java/CIL
9807 -- * an access-type designating a type that has convention
9808 -- Java/CIL.
9809
9810 if Is_Value_Type (Etype (Def_Id)) then
9811 null;
9812
9813 -- Access-to-subprogram type with convention Java/CIL
9814
9815 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9816 if Atree.Convention (Etype (Def_Id)) /= Convention then
9817 if Convention = Convention_Java then
9818 Error_Pragma_Arg
9819 ("pragma% requires function returning a " &
9820 "'Java access type", Arg1);
9821 else
9822 pragma Assert (Convention = Convention_CIL);
9823 Error_Pragma_Arg
9824 ("pragma% requires function returning a " &
9825 "'C'I'L access type", Arg1);
9826 end if;
9827 end if;
9828
9829 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9830 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9831 E_General_Access_Type)
9832 or else
9833 Atree.Convention
9834 (Designated_Type (Etype (Def_Id))) /= Convention
9835 then
9836 Error_Msg_Name_1 := Pname;
9837
9838 if Convention = Convention_Java then
9839 Error_Pragma_Arg
9840 ("pragma% requires function returning a named" &
9841 "'Java access type", Arg1);
9842 else
9843 Error_Pragma_Arg
9844 ("pragma% requires function returning a named" &
9845 "'C'I'L access type", Arg1);
9846 end if;
9847 end if;
9848 end if;
9849
9850 Set_Is_Constructor (Def_Id);
9851 Set_Convention (Def_Id, Convention);
9852 Set_Is_Imported (Def_Id);
9853
9854 exit when From_Aspect_Specification (N);
9855 Hom_Id := Homonym (Hom_Id);
9856
9857 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9858 end loop;
9859 end Java_Constructor;
9860
9861 ----------------------
9862 -- Java_Interface --
9863 ----------------------
9864
9865 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
9866
9867 when Pragma_Java_Interface => Java_Interface : declare
9868 Arg : Node_Id;
9869 Typ : Entity_Id;
9870
9871 begin
9872 GNAT_Pragma;
9873 Check_Arg_Count (1);
9874 Check_Optional_Identifier (Arg1, Name_Entity);
9875 Check_Arg_Is_Local_Name (Arg1);
9876
9877 Arg := Get_Pragma_Arg (Arg1);
9878 Analyze (Arg);
9879
9880 if Etype (Arg) = Any_Type then
9881 return;
9882 end if;
9883
9884 if not Is_Entity_Name (Arg)
9885 or else not Is_Type (Entity (Arg))
9886 then
9887 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
9888 end if;
9889
9890 Typ := Underlying_Type (Entity (Arg));
9891
9892 -- For now simply check some of the semantic constraints on the
9893 -- type. This currently leaves out some restrictions on interface
9894 -- types, namely that the parent type must be java.lang.Object.Typ
9895 -- and that all primitives of the type should be declared
9896 -- abstract. ???
9897
9898 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
9899 Error_Pragma_Arg ("pragma% requires an abstract "
9900 & "tagged type", Arg1);
9901
9902 elsif not Has_Discriminants (Typ)
9903 or else Ekind (Etype (First_Discriminant (Typ)))
9904 /= E_Anonymous_Access_Type
9905 or else
9906 not Is_Class_Wide_Type
9907 (Designated_Type (Etype (First_Discriminant (Typ))))
9908 then
9909 Error_Pragma_Arg
9910 ("type must have a class-wide access discriminant", Arg1);
9911 end if;
9912 end Java_Interface;
9913
9914 ----------------
9915 -- Keep_Names --
9916 ----------------
9917
9918 -- pragma Keep_Names ([On => ] local_NAME);
9919
9920 when Pragma_Keep_Names => Keep_Names : declare
9921 Arg : Node_Id;
9922
9923 begin
9924 GNAT_Pragma;
9925 Check_Arg_Count (1);
9926 Check_Optional_Identifier (Arg1, Name_On);
9927 Check_Arg_Is_Local_Name (Arg1);
9928
9929 Arg := Get_Pragma_Arg (Arg1);
9930 Analyze (Arg);
9931
9932 if Etype (Arg) = Any_Type then
9933 return;
9934 end if;
9935
9936 if not Is_Entity_Name (Arg)
9937 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
9938 then
9939 Error_Pragma_Arg
9940 ("pragma% requires a local enumeration type", Arg1);
9941 end if;
9942
9943 Set_Discard_Names (Entity (Arg), False);
9944 end Keep_Names;
9945
9946 -------------
9947 -- License --
9948 -------------
9949
9950 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
9951
9952 when Pragma_License =>
9953 GNAT_Pragma;
9954 Check_Arg_Count (1);
9955 Check_No_Identifiers;
9956 Check_Valid_Configuration_Pragma;
9957 Check_Arg_Is_Identifier (Arg1);
9958
9959 declare
9960 Sind : constant Source_File_Index :=
9961 Source_Index (Current_Sem_Unit);
9962
9963 begin
9964 case Chars (Get_Pragma_Arg (Arg1)) is
9965 when Name_GPL =>
9966 Set_License (Sind, GPL);
9967
9968 when Name_Modified_GPL =>
9969 Set_License (Sind, Modified_GPL);
9970
9971 when Name_Restricted =>
9972 Set_License (Sind, Restricted);
9973
9974 when Name_Unrestricted =>
9975 Set_License (Sind, Unrestricted);
9976
9977 when others =>
9978 Error_Pragma_Arg ("invalid license name", Arg1);
9979 end case;
9980 end;
9981
9982 ---------------
9983 -- Link_With --
9984 ---------------
9985
9986 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
9987
9988 when Pragma_Link_With => Link_With : declare
9989 Arg : Node_Id;
9990
9991 begin
9992 GNAT_Pragma;
9993
9994 if Operating_Mode = Generate_Code
9995 and then In_Extended_Main_Source_Unit (N)
9996 then
9997 Check_At_Least_N_Arguments (1);
9998 Check_No_Identifiers;
9999 Check_Is_In_Decl_Part_Or_Package_Spec;
10000 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10001 Start_String;
10002
10003 Arg := Arg1;
10004 while Present (Arg) loop
10005 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10006
10007 -- Store argument, converting sequences of spaces to a
10008 -- single null character (this is one of the differences
10009 -- in processing between Link_With and Linker_Options).
10010
10011 Arg_Store : declare
10012 C : constant Char_Code := Get_Char_Code (' ');
10013 S : constant String_Id :=
10014 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10015 L : constant Nat := String_Length (S);
10016 F : Nat := 1;
10017
10018 procedure Skip_Spaces;
10019 -- Advance F past any spaces
10020
10021 -----------------
10022 -- Skip_Spaces --
10023 -----------------
10024
10025 procedure Skip_Spaces is
10026 begin
10027 while F <= L and then Get_String_Char (S, F) = C loop
10028 F := F + 1;
10029 end loop;
10030 end Skip_Spaces;
10031
10032 -- Start of processing for Arg_Store
10033
10034 begin
10035 Skip_Spaces; -- skip leading spaces
10036
10037 -- Loop through characters, changing any embedded
10038 -- sequence of spaces to a single null character (this
10039 -- is how Link_With/Linker_Options differ)
10040
10041 while F <= L loop
10042 if Get_String_Char (S, F) = C then
10043 Skip_Spaces;
10044 exit when F > L;
10045 Store_String_Char (ASCII.NUL);
10046
10047 else
10048 Store_String_Char (Get_String_Char (S, F));
10049 F := F + 1;
10050 end if;
10051 end loop;
10052 end Arg_Store;
10053
10054 Arg := Next (Arg);
10055
10056 if Present (Arg) then
10057 Store_String_Char (ASCII.NUL);
10058 end if;
10059 end loop;
10060
10061 Store_Linker_Option_String (End_String);
10062 end if;
10063 end Link_With;
10064
10065 ------------------
10066 -- Linker_Alias --
10067 ------------------
10068
10069 -- pragma Linker_Alias (
10070 -- [Entity =>] LOCAL_NAME
10071 -- [Target =>] static_string_EXPRESSION);
10072
10073 when Pragma_Linker_Alias =>
10074 GNAT_Pragma;
10075 Check_Arg_Order ((Name_Entity, Name_Target));
10076 Check_Arg_Count (2);
10077 Check_Optional_Identifier (Arg1, Name_Entity);
10078 Check_Optional_Identifier (Arg2, Name_Target);
10079 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10080 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10081
10082 -- The only processing required is to link this item on to the
10083 -- list of rep items for the given entity. This is accomplished
10084 -- by the call to Rep_Item_Too_Late (when no error is detected
10085 -- and False is returned).
10086
10087 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10088 return;
10089 else
10090 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10091 end if;
10092
10093 ------------------------
10094 -- Linker_Constructor --
10095 ------------------------
10096
10097 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10098
10099 -- Code is shared with Linker_Destructor
10100
10101 -----------------------
10102 -- Linker_Destructor --
10103 -----------------------
10104
10105 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10106
10107 when Pragma_Linker_Constructor |
10108 Pragma_Linker_Destructor =>
10109 Linker_Constructor : declare
10110 Arg1_X : Node_Id;
10111 Proc : Entity_Id;
10112
10113 begin
10114 GNAT_Pragma;
10115 Check_Arg_Count (1);
10116 Check_No_Identifiers;
10117 Check_Arg_Is_Local_Name (Arg1);
10118 Arg1_X := Get_Pragma_Arg (Arg1);
10119 Analyze (Arg1_X);
10120 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10121
10122 if not Is_Library_Level_Entity (Proc) then
10123 Error_Pragma_Arg
10124 ("argument for pragma% must be library level entity", Arg1);
10125 end if;
10126
10127 -- The only processing required is to link this item on to the
10128 -- list of rep items for the given entity. This is accomplished
10129 -- by the call to Rep_Item_Too_Late (when no error is detected
10130 -- and False is returned).
10131
10132 if Rep_Item_Too_Late (Proc, N) then
10133 return;
10134 else
10135 Set_Has_Gigi_Rep_Item (Proc);
10136 end if;
10137 end Linker_Constructor;
10138
10139 --------------------
10140 -- Linker_Options --
10141 --------------------
10142
10143 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10144
10145 when Pragma_Linker_Options => Linker_Options : declare
10146 Arg : Node_Id;
10147
10148 begin
10149 Check_Ada_83_Warning;
10150 Check_No_Identifiers;
10151 Check_Arg_Count (1);
10152 Check_Is_In_Decl_Part_Or_Package_Spec;
10153 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10154 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10155
10156 Arg := Arg2;
10157 while Present (Arg) loop
10158 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10159 Store_String_Char (ASCII.NUL);
10160 Store_String_Chars
10161 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10162 Arg := Next (Arg);
10163 end loop;
10164
10165 if Operating_Mode = Generate_Code
10166 and then In_Extended_Main_Source_Unit (N)
10167 then
10168 Store_Linker_Option_String (End_String);
10169 end if;
10170 end Linker_Options;
10171
10172 --------------------
10173 -- Linker_Section --
10174 --------------------
10175
10176 -- pragma Linker_Section (
10177 -- [Entity =>] LOCAL_NAME
10178 -- [Section =>] static_string_EXPRESSION);
10179
10180 when Pragma_Linker_Section =>
10181 GNAT_Pragma;
10182 Check_Arg_Order ((Name_Entity, Name_Section));
10183 Check_Arg_Count (2);
10184 Check_Optional_Identifier (Arg1, Name_Entity);
10185 Check_Optional_Identifier (Arg2, Name_Section);
10186 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10187 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10188
10189 -- This pragma applies only to objects
10190
10191 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10192 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10193 end if;
10194
10195 -- The only processing required is to link this item on to the
10196 -- list of rep items for the given entity. This is accomplished
10197 -- by the call to Rep_Item_Too_Late (when no error is detected
10198 -- and False is returned).
10199
10200 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10201 return;
10202 else
10203 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10204 end if;
10205
10206 ----------
10207 -- List --
10208 ----------
10209
10210 -- pragma List (On | Off)
10211
10212 -- There is nothing to do here, since we did all the processing for
10213 -- this pragma in Par.Prag (so that it works properly even in syntax
10214 -- only mode).
10215
10216 when Pragma_List =>
10217 null;
10218
10219 --------------------
10220 -- Locking_Policy --
10221 --------------------
10222
10223 -- pragma Locking_Policy (policy_IDENTIFIER);
10224
10225 when Pragma_Locking_Policy => declare
10226 LP : Character;
10227
10228 begin
10229 Check_Ada_83_Warning;
10230 Check_Arg_Count (1);
10231 Check_No_Identifiers;
10232 Check_Arg_Is_Locking_Policy (Arg1);
10233 Check_Valid_Configuration_Pragma;
10234 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10235 LP := Fold_Upper (Name_Buffer (1));
10236
10237 if Locking_Policy /= ' '
10238 and then Locking_Policy /= LP
10239 then
10240 Error_Msg_Sloc := Locking_Policy_Sloc;
10241 Error_Pragma ("locking policy incompatible with policy#");
10242
10243 -- Set new policy, but always preserve System_Location since we
10244 -- like the error message with the run time name.
10245
10246 else
10247 Locking_Policy := LP;
10248
10249 if Locking_Policy_Sloc /= System_Location then
10250 Locking_Policy_Sloc := Loc;
10251 end if;
10252 end if;
10253 end;
10254
10255 ----------------
10256 -- Long_Float --
10257 ----------------
10258
10259 -- pragma Long_Float (D_Float | G_Float);
10260
10261 when Pragma_Long_Float =>
10262 GNAT_Pragma;
10263 Check_Valid_Configuration_Pragma;
10264 Check_Arg_Count (1);
10265 Check_No_Identifier (Arg1);
10266 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10267
10268 if not OpenVMS_On_Target then
10269 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10270 end if;
10271
10272 -- D_Float case
10273
10274 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10275 if Opt.Float_Format_Long = 'G' then
10276 Error_Pragma ("G_Float previously specified");
10277 end if;
10278
10279 Opt.Float_Format_Long := 'D';
10280
10281 -- G_Float case (this is the default, does not need overriding)
10282
10283 else
10284 if Opt.Float_Format_Long = 'D' then
10285 Error_Pragma ("D_Float previously specified");
10286 end if;
10287
10288 Opt.Float_Format_Long := 'G';
10289 end if;
10290
10291 Set_Standard_Fpt_Formats;
10292
10293 -----------------------
10294 -- Machine_Attribute --
10295 -----------------------
10296
10297 -- pragma Machine_Attribute (
10298 -- [Entity =>] LOCAL_NAME,
10299 -- [Attribute_Name =>] static_string_EXPRESSION
10300 -- [, [Info =>] static_EXPRESSION] );
10301
10302 when Pragma_Machine_Attribute => Machine_Attribute : declare
10303 Def_Id : Entity_Id;
10304
10305 begin
10306 GNAT_Pragma;
10307 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10308
10309 if Arg_Count = 3 then
10310 Check_Optional_Identifier (Arg3, Name_Info);
10311 Check_Arg_Is_Static_Expression (Arg3);
10312 else
10313 Check_Arg_Count (2);
10314 end if;
10315
10316 Check_Optional_Identifier (Arg1, Name_Entity);
10317 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10318 Check_Arg_Is_Local_Name (Arg1);
10319 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10320 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10321
10322 if Is_Access_Type (Def_Id) then
10323 Def_Id := Designated_Type (Def_Id);
10324 end if;
10325
10326 if Rep_Item_Too_Early (Def_Id, N) then
10327 return;
10328 end if;
10329
10330 Def_Id := Underlying_Type (Def_Id);
10331
10332 -- The only processing required is to link this item on to the
10333 -- list of rep items for the given entity. This is accomplished
10334 -- by the call to Rep_Item_Too_Late (when no error is detected
10335 -- and False is returned).
10336
10337 if Rep_Item_Too_Late (Def_Id, N) then
10338 return;
10339 else
10340 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10341 end if;
10342 end Machine_Attribute;
10343
10344 ----------
10345 -- Main --
10346 ----------
10347
10348 -- pragma Main
10349 -- (MAIN_OPTION [, MAIN_OPTION]);
10350
10351 -- MAIN_OPTION ::=
10352 -- [STACK_SIZE =>] static_integer_EXPRESSION
10353 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10354 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10355
10356 when Pragma_Main => Main : declare
10357 Args : Args_List (1 .. 3);
10358 Names : constant Name_List (1 .. 3) := (
10359 Name_Stack_Size,
10360 Name_Task_Stack_Size_Default,
10361 Name_Time_Slicing_Enabled);
10362
10363 Nod : Node_Id;
10364
10365 begin
10366 GNAT_Pragma;
10367 Gather_Associations (Names, Args);
10368
10369 for J in 1 .. 2 loop
10370 if Present (Args (J)) then
10371 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10372 end if;
10373 end loop;
10374
10375 if Present (Args (3)) then
10376 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10377 end if;
10378
10379 Nod := Next (N);
10380 while Present (Nod) loop
10381 if Nkind (Nod) = N_Pragma
10382 and then Pragma_Name (Nod) = Name_Main
10383 then
10384 Error_Msg_Name_1 := Pname;
10385 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10386 end if;
10387
10388 Next (Nod);
10389 end loop;
10390 end Main;
10391
10392 ------------------
10393 -- Main_Storage --
10394 ------------------
10395
10396 -- pragma Main_Storage
10397 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10398
10399 -- MAIN_STORAGE_OPTION ::=
10400 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10401 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10402
10403 when Pragma_Main_Storage => Main_Storage : declare
10404 Args : Args_List (1 .. 2);
10405 Names : constant Name_List (1 .. 2) := (
10406 Name_Working_Storage,
10407 Name_Top_Guard);
10408
10409 Nod : Node_Id;
10410
10411 begin
10412 GNAT_Pragma;
10413 Gather_Associations (Names, Args);
10414
10415 for J in 1 .. 2 loop
10416 if Present (Args (J)) then
10417 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10418 end if;
10419 end loop;
10420
10421 Check_In_Main_Program;
10422
10423 Nod := Next (N);
10424 while Present (Nod) loop
10425 if Nkind (Nod) = N_Pragma
10426 and then Pragma_Name (Nod) = Name_Main_Storage
10427 then
10428 Error_Msg_Name_1 := Pname;
10429 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10430 end if;
10431
10432 Next (Nod);
10433 end loop;
10434 end Main_Storage;
10435
10436 -----------------
10437 -- Memory_Size --
10438 -----------------
10439
10440 -- pragma Memory_Size (NUMERIC_LITERAL)
10441
10442 when Pragma_Memory_Size =>
10443 GNAT_Pragma;
10444
10445 -- Memory size is simply ignored
10446
10447 Check_No_Identifiers;
10448 Check_Arg_Count (1);
10449 Check_Arg_Is_Integer_Literal (Arg1);
10450
10451 -------------
10452 -- No_Body --
10453 -------------
10454
10455 -- pragma No_Body;
10456
10457 -- The only correct use of this pragma is on its own in a file, in
10458 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10459 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10460 -- check for a file containing nothing but a No_Body pragma). If we
10461 -- attempt to process it during normal semantics processing, it means
10462 -- it was misplaced.
10463
10464 when Pragma_No_Body =>
10465 GNAT_Pragma;
10466 Pragma_Misplaced;
10467
10468 ---------------
10469 -- No_Return --
10470 ---------------
10471
10472 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10473
10474 when Pragma_No_Return => No_Return : declare
10475 Id : Node_Id;
10476 E : Entity_Id;
10477 Found : Boolean;
10478 Arg : Node_Id;
10479
10480 begin
10481 Ada_2005_Pragma;
10482 Check_At_Least_N_Arguments (1);
10483
10484 -- Loop through arguments of pragma
10485
10486 Arg := Arg1;
10487 while Present (Arg) loop
10488 Check_Arg_Is_Local_Name (Arg);
10489 Id := Get_Pragma_Arg (Arg);
10490 Analyze (Id);
10491
10492 if not Is_Entity_Name (Id) then
10493 Error_Pragma_Arg ("entity name required", Arg);
10494 end if;
10495
10496 if Etype (Id) = Any_Type then
10497 raise Pragma_Exit;
10498 end if;
10499
10500 -- Loop to find matching procedures
10501
10502 E := Entity (Id);
10503 Found := False;
10504 while Present (E)
10505 and then Scope (E) = Current_Scope
10506 loop
10507 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10508 Set_No_Return (E);
10509
10510 -- Set flag on any alias as well
10511
10512 if Is_Overloadable (E) and then Present (Alias (E)) then
10513 Set_No_Return (Alias (E));
10514 end if;
10515
10516 Found := True;
10517 end if;
10518
10519 exit when From_Aspect_Specification (N);
10520 E := Homonym (E);
10521 end loop;
10522
10523 if not Found then
10524 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10525 end if;
10526
10527 Next (Arg);
10528 end loop;
10529 end No_Return;
10530
10531 -----------------
10532 -- No_Run_Time --
10533 -----------------
10534
10535 -- pragma No_Run_Time;
10536
10537 -- Note: this pragma is retained for backwards compatibility. See
10538 -- body of Rtsfind for full details on its handling.
10539
10540 when Pragma_No_Run_Time =>
10541 GNAT_Pragma;
10542 Check_Valid_Configuration_Pragma;
10543 Check_Arg_Count (0);
10544
10545 No_Run_Time_Mode := True;
10546 Configurable_Run_Time_Mode := True;
10547
10548 -- Set Duration to 32 bits if word size is 32
10549
10550 if Ttypes.System_Word_Size = 32 then
10551 Duration_32_Bits_On_Target := True;
10552 end if;
10553
10554 -- Set appropriate restrictions
10555
10556 Set_Restriction (No_Finalization, N);
10557 Set_Restriction (No_Exception_Handlers, N);
10558 Set_Restriction (Max_Tasks, N, 0);
10559 Set_Restriction (No_Tasking, N);
10560
10561 ------------------------
10562 -- No_Strict_Aliasing --
10563 ------------------------
10564
10565 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10566
10567 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10568 E_Id : Entity_Id;
10569
10570 begin
10571 GNAT_Pragma;
10572 Check_At_Most_N_Arguments (1);
10573
10574 if Arg_Count = 0 then
10575 Check_Valid_Configuration_Pragma;
10576 Opt.No_Strict_Aliasing := True;
10577
10578 else
10579 Check_Optional_Identifier (Arg2, Name_Entity);
10580 Check_Arg_Is_Local_Name (Arg1);
10581 E_Id := Entity (Get_Pragma_Arg (Arg1));
10582
10583 if E_Id = Any_Type then
10584 return;
10585 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10586 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10587 end if;
10588
10589 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10590 end if;
10591 end No_Strict_Aliasing;
10592
10593 -----------------------
10594 -- Normalize_Scalars --
10595 -----------------------
10596
10597 -- pragma Normalize_Scalars;
10598
10599 when Pragma_Normalize_Scalars =>
10600 Check_Ada_83_Warning;
10601 Check_Arg_Count (0);
10602 Check_Valid_Configuration_Pragma;
10603
10604 -- Normalize_Scalars creates false positives in CodePeer, so
10605 -- ignore this pragma in this mode.
10606
10607 if not CodePeer_Mode then
10608 Normalize_Scalars := True;
10609 Init_Or_Norm_Scalars := True;
10610 end if;
10611
10612 -----------------
10613 -- Obsolescent --
10614 -----------------
10615
10616 -- pragma Obsolescent;
10617
10618 -- pragma Obsolescent (
10619 -- [Message =>] static_string_EXPRESSION
10620 -- [,[Version =>] Ada_05]]);
10621
10622 -- pragma Obsolescent (
10623 -- [Entity =>] NAME
10624 -- [,[Message =>] static_string_EXPRESSION
10625 -- [,[Version =>] Ada_05]] );
10626
10627 when Pragma_Obsolescent => Obsolescent : declare
10628 Ename : Node_Id;
10629 Decl : Node_Id;
10630
10631 procedure Set_Obsolescent (E : Entity_Id);
10632 -- Given an entity Ent, mark it as obsolescent if appropriate
10633
10634 ---------------------
10635 -- Set_Obsolescent --
10636 ---------------------
10637
10638 procedure Set_Obsolescent (E : Entity_Id) is
10639 Active : Boolean;
10640 Ent : Entity_Id;
10641 S : String_Id;
10642
10643 begin
10644 Active := True;
10645 Ent := E;
10646
10647 -- Entity name was given
10648
10649 if Present (Ename) then
10650
10651 -- If entity name matches, we are fine. Save entity in
10652 -- pragma argument, for ASIS use.
10653
10654 if Chars (Ename) = Chars (Ent) then
10655 Set_Entity (Ename, Ent);
10656 Generate_Reference (Ent, Ename);
10657
10658 -- If entity name does not match, only possibility is an
10659 -- enumeration literal from an enumeration type declaration.
10660
10661 elsif Ekind (Ent) /= E_Enumeration_Type then
10662 Error_Pragma
10663 ("pragma % entity name does not match declaration");
10664
10665 else
10666 Ent := First_Literal (E);
10667 loop
10668 if No (Ent) then
10669 Error_Pragma
10670 ("pragma % entity name does not match any " &
10671 "enumeration literal");
10672
10673 elsif Chars (Ent) = Chars (Ename) then
10674 Set_Entity (Ename, Ent);
10675 Generate_Reference (Ent, Ename);
10676 exit;
10677
10678 else
10679 Ent := Next_Literal (Ent);
10680 end if;
10681 end loop;
10682 end if;
10683 end if;
10684
10685 -- Ent points to entity to be marked
10686
10687 if Arg_Count >= 1 then
10688
10689 -- Deal with static string argument
10690
10691 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10692 S := Strval (Get_Pragma_Arg (Arg1));
10693
10694 for J in 1 .. String_Length (S) loop
10695 if not In_Character_Range (Get_String_Char (S, J)) then
10696 Error_Pragma_Arg
10697 ("pragma% argument does not allow wide characters",
10698 Arg1);
10699 end if;
10700 end loop;
10701
10702 Obsolescent_Warnings.Append
10703 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10704
10705 -- Check for Ada_05 parameter
10706
10707 if Arg_Count /= 1 then
10708 Check_Arg_Count (2);
10709
10710 declare
10711 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10712
10713 begin
10714 Check_Arg_Is_Identifier (Argx);
10715
10716 if Chars (Argx) /= Name_Ada_05 then
10717 Error_Msg_Name_2 := Name_Ada_05;
10718 Error_Pragma_Arg
10719 ("only allowed argument for pragma% is %", Argx);
10720 end if;
10721
10722 if Ada_Version_Explicit < Ada_2005
10723 or else not Warn_On_Ada_2005_Compatibility
10724 then
10725 Active := False;
10726 end if;
10727 end;
10728 end if;
10729 end if;
10730
10731 -- Set flag if pragma active
10732
10733 if Active then
10734 Set_Is_Obsolescent (Ent);
10735 end if;
10736
10737 return;
10738 end Set_Obsolescent;
10739
10740 -- Start of processing for pragma Obsolescent
10741
10742 begin
10743 GNAT_Pragma;
10744
10745 Check_At_Most_N_Arguments (3);
10746
10747 -- See if first argument specifies an entity name
10748
10749 if Arg_Count >= 1
10750 and then
10751 (Chars (Arg1) = Name_Entity
10752 or else
10753 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10754 N_Identifier,
10755 N_Operator_Symbol))
10756 then
10757 Ename := Get_Pragma_Arg (Arg1);
10758
10759 -- Eliminate first argument, so we can share processing
10760
10761 Arg1 := Arg2;
10762 Arg2 := Arg3;
10763 Arg_Count := Arg_Count - 1;
10764
10765 -- No Entity name argument given
10766
10767 else
10768 Ename := Empty;
10769 end if;
10770
10771 if Arg_Count >= 1 then
10772 Check_Optional_Identifier (Arg1, Name_Message);
10773
10774 if Arg_Count = 2 then
10775 Check_Optional_Identifier (Arg2, Name_Version);
10776 end if;
10777 end if;
10778
10779 -- Get immediately preceding declaration
10780
10781 Decl := Prev (N);
10782 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10783 Prev (Decl);
10784 end loop;
10785
10786 -- Cases where we do not follow anything other than another pragma
10787
10788 if No (Decl) then
10789
10790 -- First case: library level compilation unit declaration with
10791 -- the pragma immediately following the declaration.
10792
10793 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10794 Set_Obsolescent
10795 (Defining_Entity (Unit (Parent (Parent (N)))));
10796 return;
10797
10798 -- Case 2: library unit placement for package
10799
10800 else
10801 declare
10802 Ent : constant Entity_Id := Find_Lib_Unit_Name;
10803 begin
10804 if Is_Package_Or_Generic_Package (Ent) then
10805 Set_Obsolescent (Ent);
10806 return;
10807 end if;
10808 end;
10809 end if;
10810
10811 -- Cases where we must follow a declaration
10812
10813 else
10814 if Nkind (Decl) not in N_Declaration
10815 and then Nkind (Decl) not in N_Later_Decl_Item
10816 and then Nkind (Decl) not in N_Generic_Declaration
10817 and then Nkind (Decl) not in N_Renaming_Declaration
10818 then
10819 Error_Pragma
10820 ("pragma% misplaced, "
10821 & "must immediately follow a declaration");
10822
10823 else
10824 Set_Obsolescent (Defining_Entity (Decl));
10825 return;
10826 end if;
10827 end if;
10828 end Obsolescent;
10829
10830 --------------
10831 -- Optimize --
10832 --------------
10833
10834 -- pragma Optimize (Time | Space | Off);
10835
10836 -- The actual check for optimize is done in Gigi. Note that this
10837 -- pragma does not actually change the optimization setting, it
10838 -- simply checks that it is consistent with the pragma.
10839
10840 when Pragma_Optimize =>
10841 Check_No_Identifiers;
10842 Check_Arg_Count (1);
10843 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10844
10845 ------------------------
10846 -- Optimize_Alignment --
10847 ------------------------
10848
10849 -- pragma Optimize_Alignment (Time | Space | Off);
10850
10851 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10852 GNAT_Pragma;
10853 Check_No_Identifiers;
10854 Check_Arg_Count (1);
10855 Check_Valid_Configuration_Pragma;
10856
10857 declare
10858 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10859 begin
10860 case Nam is
10861 when Name_Time =>
10862 Opt.Optimize_Alignment := 'T';
10863 when Name_Space =>
10864 Opt.Optimize_Alignment := 'S';
10865 when Name_Off =>
10866 Opt.Optimize_Alignment := 'O';
10867 when others =>
10868 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10869 end case;
10870 end;
10871
10872 -- Set indication that mode is set locally. If we are in fact in a
10873 -- configuration pragma file, this setting is harmless since the
10874 -- switch will get reset anyway at the start of each unit.
10875
10876 Optimize_Alignment_Local := True;
10877 end Optimize_Alignment;
10878
10879 -------------
10880 -- Ordered --
10881 -------------
10882
10883 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
10884
10885 when Pragma_Ordered => Ordered : declare
10886 Assoc : constant Node_Id := Arg1;
10887 Type_Id : Node_Id;
10888 Typ : Entity_Id;
10889
10890 begin
10891 GNAT_Pragma;
10892 Check_No_Identifiers;
10893 Check_Arg_Count (1);
10894 Check_Arg_Is_Local_Name (Arg1);
10895
10896 Type_Id := Get_Pragma_Arg (Assoc);
10897 Find_Type (Type_Id);
10898 Typ := Entity (Type_Id);
10899
10900 if Typ = Any_Type then
10901 return;
10902 else
10903 Typ := Underlying_Type (Typ);
10904 end if;
10905
10906 if not Is_Enumeration_Type (Typ) then
10907 Error_Pragma ("pragma% must specify enumeration type");
10908 end if;
10909
10910 Check_First_Subtype (Arg1);
10911 Set_Has_Pragma_Ordered (Base_Type (Typ));
10912 end Ordered;
10913
10914 ----------
10915 -- Pack --
10916 ----------
10917
10918 -- pragma Pack (first_subtype_LOCAL_NAME);
10919
10920 when Pragma_Pack => Pack : declare
10921 Assoc : constant Node_Id := Arg1;
10922 Type_Id : Node_Id;
10923 Typ : Entity_Id;
10924 Ctyp : Entity_Id;
10925 Ignore : Boolean := False;
10926
10927 begin
10928 Check_No_Identifiers;
10929 Check_Arg_Count (1);
10930 Check_Arg_Is_Local_Name (Arg1);
10931
10932 Type_Id := Get_Pragma_Arg (Assoc);
10933 Find_Type (Type_Id);
10934 Typ := Entity (Type_Id);
10935
10936 if Typ = Any_Type
10937 or else Rep_Item_Too_Early (Typ, N)
10938 then
10939 return;
10940 else
10941 Typ := Underlying_Type (Typ);
10942 end if;
10943
10944 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
10945 Error_Pragma ("pragma% must specify array or record type");
10946 end if;
10947
10948 Check_First_Subtype (Arg1);
10949 Check_Duplicate_Pragma (Typ);
10950
10951 -- Array type
10952
10953 if Is_Array_Type (Typ) then
10954 Ctyp := Component_Type (Typ);
10955
10956 -- Ignore pack that does nothing
10957
10958 if Known_Static_Esize (Ctyp)
10959 and then Known_Static_RM_Size (Ctyp)
10960 and then Esize (Ctyp) = RM_Size (Ctyp)
10961 and then Addressable (Esize (Ctyp))
10962 then
10963 Ignore := True;
10964 end if;
10965
10966 -- Process OK pragma Pack. Note that if there is a separate
10967 -- component clause present, the Pack will be cancelled. This
10968 -- processing is in Freeze.
10969
10970 if not Rep_Item_Too_Late (Typ, N) then
10971
10972 -- In the context of static code analysis, we do not need
10973 -- complex front-end expansions related to pragma Pack,
10974 -- so disable handling of pragma Pack in this case.
10975
10976 if CodePeer_Mode then
10977 null;
10978
10979 -- Don't attempt any packing for VM targets. We possibly
10980 -- could deal with some cases of array bit-packing, but we
10981 -- don't bother, since this is not a typical kind of
10982 -- representation in the VM context anyway (and would not
10983 -- for example work nicely with the debugger).
10984
10985 elsif VM_Target /= No_VM then
10986 if not GNAT_Mode then
10987 Error_Pragma
10988 ("?pragma% ignored in this configuration");
10989 end if;
10990
10991 -- Normal case where we do the pack action
10992
10993 else
10994 if not Ignore then
10995 Set_Is_Packed (Base_Type (Typ));
10996 Set_Has_Non_Standard_Rep (Base_Type (Typ));
10997 end if;
10998
10999 Set_Has_Pragma_Pack (Base_Type (Typ));
11000 end if;
11001 end if;
11002
11003 -- For record types, the pack is always effective
11004
11005 else pragma Assert (Is_Record_Type (Typ));
11006 if not Rep_Item_Too_Late (Typ, N) then
11007
11008 -- Ignore pack request with warning in VM mode (skip warning
11009 -- if we are compiling GNAT run time library).
11010
11011 if VM_Target /= No_VM then
11012 if not GNAT_Mode then
11013 Error_Pragma
11014 ("?pragma% ignored in this configuration");
11015 end if;
11016
11017 -- Normal case of pack request active
11018
11019 else
11020 Set_Is_Packed (Base_Type (Typ));
11021 Set_Has_Pragma_Pack (Base_Type (Typ));
11022 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11023 end if;
11024 end if;
11025 end if;
11026 end Pack;
11027
11028 ----------
11029 -- Page --
11030 ----------
11031
11032 -- pragma Page;
11033
11034 -- There is nothing to do here, since we did all the processing for
11035 -- this pragma in Par.Prag (so that it works properly even in syntax
11036 -- only mode).
11037
11038 when Pragma_Page =>
11039 null;
11040
11041 -------------
11042 -- Passive --
11043 -------------
11044
11045 -- pragma Passive [(PASSIVE_FORM)];
11046
11047 -- PASSIVE_FORM ::= Semaphore | No
11048
11049 when Pragma_Passive =>
11050 GNAT_Pragma;
11051
11052 if Nkind (Parent (N)) /= N_Task_Definition then
11053 Error_Pragma ("pragma% must be within task definition");
11054 end if;
11055
11056 if Arg_Count /= 0 then
11057 Check_Arg_Count (1);
11058 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11059 end if;
11060
11061 ----------------------------------
11062 -- Preelaborable_Initialization --
11063 ----------------------------------
11064
11065 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11066
11067 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11068 Ent : Entity_Id;
11069
11070 begin
11071 Ada_2005_Pragma;
11072 Check_Arg_Count (1);
11073 Check_No_Identifiers;
11074 Check_Arg_Is_Identifier (Arg1);
11075 Check_Arg_Is_Local_Name (Arg1);
11076 Check_First_Subtype (Arg1);
11077 Ent := Entity (Get_Pragma_Arg (Arg1));
11078
11079 if not (Is_Private_Type (Ent)
11080 or else
11081 Is_Protected_Type (Ent)
11082 or else
11083 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11084 then
11085 Error_Pragma_Arg
11086 ("pragma % can only be applied to private, formal derived or "
11087 & "protected type",
11088 Arg1);
11089 end if;
11090
11091 -- Give an error if the pragma is applied to a protected type that
11092 -- does not qualify (due to having entries, or due to components
11093 -- that do not qualify).
11094
11095 if Is_Protected_Type (Ent)
11096 and then not Has_Preelaborable_Initialization (Ent)
11097 then
11098 Error_Msg_N
11099 ("protected type & does not have preelaborable " &
11100 "initialization", Ent);
11101
11102 -- Otherwise mark the type as definitely having preelaborable
11103 -- initialization.
11104
11105 else
11106 Set_Known_To_Have_Preelab_Init (Ent);
11107 end if;
11108
11109 if Has_Pragma_Preelab_Init (Ent)
11110 and then Warn_On_Redundant_Constructs
11111 then
11112 Error_Pragma ("?duplicate pragma%!");
11113 else
11114 Set_Has_Pragma_Preelab_Init (Ent);
11115 end if;
11116 end Preelab_Init;
11117
11118 --------------------
11119 -- Persistent_BSS --
11120 --------------------
11121
11122 -- pragma Persistent_BSS [(object_NAME)];
11123
11124 when Pragma_Persistent_BSS => Persistent_BSS : declare
11125 Decl : Node_Id;
11126 Ent : Entity_Id;
11127 Prag : Node_Id;
11128
11129 begin
11130 GNAT_Pragma;
11131 Check_At_Most_N_Arguments (1);
11132
11133 -- Case of application to specific object (one argument)
11134
11135 if Arg_Count = 1 then
11136 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11137
11138 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11139 or else not
11140 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11141 E_Constant)
11142 then
11143 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11144 end if;
11145
11146 Ent := Entity (Get_Pragma_Arg (Arg1));
11147 Decl := Parent (Ent);
11148
11149 if Rep_Item_Too_Late (Ent, N) then
11150 return;
11151 end if;
11152
11153 if Present (Expression (Decl)) then
11154 Error_Pragma_Arg
11155 ("object for pragma% cannot have initialization", Arg1);
11156 end if;
11157
11158 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11159 Error_Pragma_Arg
11160 ("object type for pragma% is not potentially persistent",
11161 Arg1);
11162 end if;
11163
11164 Check_Duplicate_Pragma (Ent);
11165
11166 Prag :=
11167 Make_Linker_Section_Pragma
11168 (Ent, Sloc (N), ".persistent.bss");
11169 Insert_After (N, Prag);
11170 Analyze (Prag);
11171
11172 -- Case of use as configuration pragma with no arguments
11173
11174 else
11175 Check_Valid_Configuration_Pragma;
11176 Persistent_BSS_Mode := True;
11177 end if;
11178 end Persistent_BSS;
11179
11180 -------------
11181 -- Polling --
11182 -------------
11183
11184 -- pragma Polling (ON | OFF);
11185
11186 when Pragma_Polling =>
11187 GNAT_Pragma;
11188 Check_Arg_Count (1);
11189 Check_No_Identifiers;
11190 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11191 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11192
11193 -------------------
11194 -- Postcondition --
11195 -------------------
11196
11197 -- pragma Postcondition ([Check =>] Boolean_Expression
11198 -- [,[Message =>] String_Expression]);
11199
11200 when Pragma_Postcondition => Postcondition : declare
11201 In_Body : Boolean;
11202 pragma Warnings (Off, In_Body);
11203
11204 begin
11205 GNAT_Pragma;
11206 Check_At_Least_N_Arguments (1);
11207 Check_At_Most_N_Arguments (2);
11208 Check_Optional_Identifier (Arg1, Name_Check);
11209
11210 -- All we need to do here is call the common check procedure,
11211 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11212
11213 Check_Precondition_Postcondition (In_Body);
11214 end Postcondition;
11215
11216 ------------------
11217 -- Precondition --
11218 ------------------
11219
11220 -- pragma Precondition ([Check =>] Boolean_Expression
11221 -- [,[Message =>] String_Expression]);
11222
11223 when Pragma_Precondition => Precondition : declare
11224 In_Body : Boolean;
11225
11226 begin
11227 GNAT_Pragma;
11228 Check_At_Least_N_Arguments (1);
11229 Check_At_Most_N_Arguments (2);
11230 Check_Optional_Identifier (Arg1, Name_Check);
11231 Check_Precondition_Postcondition (In_Body);
11232
11233 -- If in spec, nothing more to do. If in body, then we convert the
11234 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11235 -- this whether or not precondition checks are enabled. That works
11236 -- fine since pragma Check will do this check, and will also
11237 -- analyze the condition itself in the proper context.
11238
11239 if In_Body then
11240 Rewrite (N,
11241 Make_Pragma (Loc,
11242 Chars => Name_Check,
11243 Pragma_Argument_Associations => New_List (
11244 Make_Pragma_Argument_Association (Loc,
11245 Expression => Make_Identifier (Loc, Name_Precondition)),
11246
11247 Make_Pragma_Argument_Association (Sloc (Arg1),
11248 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11249
11250 if Arg_Count = 2 then
11251 Append_To (Pragma_Argument_Associations (N),
11252 Make_Pragma_Argument_Association (Sloc (Arg2),
11253 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11254 end if;
11255
11256 Analyze (N);
11257 end if;
11258 end Precondition;
11259
11260 ---------------
11261 -- Predicate --
11262 ---------------
11263
11264 -- pragma Predicate
11265 -- ([Entity =>] type_LOCAL_NAME,
11266 -- [Check =>] EXPRESSION);
11267
11268 when Pragma_Predicate => Predicate : declare
11269 Type_Id : Node_Id;
11270 Typ : Entity_Id;
11271
11272 Discard : Boolean;
11273 pragma Unreferenced (Discard);
11274
11275 begin
11276 GNAT_Pragma;
11277 Check_Arg_Count (2);
11278 Check_Optional_Identifier (Arg1, Name_Entity);
11279 Check_Optional_Identifier (Arg2, Name_Check);
11280
11281 Check_Arg_Is_Local_Name (Arg1);
11282
11283 Type_Id := Get_Pragma_Arg (Arg1);
11284 Find_Type (Type_Id);
11285 Typ := Entity (Type_Id);
11286
11287 if Typ = Any_Type then
11288 return;
11289 end if;
11290
11291 -- The remaining processing is simply to link the pragma on to
11292 -- the rep item chain, for processing when the type is frozen.
11293 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11294 -- mark the type as having predicates.
11295
11296 Set_Has_Predicates (Typ);
11297 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11298 end Predicate;
11299
11300 ------------------
11301 -- Preelaborate --
11302 ------------------
11303
11304 -- pragma Preelaborate [(library_unit_NAME)];
11305
11306 -- Set the flag Is_Preelaborated of program unit name entity
11307
11308 when Pragma_Preelaborate => Preelaborate : declare
11309 Pa : constant Node_Id := Parent (N);
11310 Pk : constant Node_Kind := Nkind (Pa);
11311 Ent : Entity_Id;
11312
11313 begin
11314 Check_Ada_83_Warning;
11315 Check_Valid_Library_Unit_Pragma;
11316
11317 if Nkind (N) = N_Null_Statement then
11318 return;
11319 end if;
11320
11321 Ent := Find_Lib_Unit_Name;
11322 Check_Duplicate_Pragma (Ent);
11323
11324 -- This filters out pragmas inside generic parent then
11325 -- show up inside instantiation
11326
11327 if Present (Ent)
11328 and then not (Pk = N_Package_Specification
11329 and then Present (Generic_Parent (Pa)))
11330 then
11331 if not Debug_Flag_U then
11332 Set_Is_Preelaborated (Ent);
11333 Set_Suppress_Elaboration_Warnings (Ent);
11334 end if;
11335 end if;
11336 end Preelaborate;
11337
11338 ---------------------
11339 -- Preelaborate_05 --
11340 ---------------------
11341
11342 -- pragma Preelaborate_05 [(library_unit_NAME)];
11343
11344 -- This pragma is useable only in GNAT_Mode, where it is used like
11345 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11346 -- (otherwise it is ignored). This is used to implement AI-362 which
11347 -- recategorizes some run-time packages in Ada 2005 mode.
11348
11349 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11350 Ent : Entity_Id;
11351
11352 begin
11353 GNAT_Pragma;
11354 Check_Valid_Library_Unit_Pragma;
11355
11356 if not GNAT_Mode then
11357 Error_Pragma ("pragma% only available in GNAT mode");
11358 end if;
11359
11360 if Nkind (N) = N_Null_Statement then
11361 return;
11362 end if;
11363
11364 -- This is one of the few cases where we need to test the value of
11365 -- Ada_Version_Explicit rather than Ada_Version (which is always
11366 -- set to Ada_2012 in a predefined unit), we need to know the
11367 -- explicit version set to know if this pragma is active.
11368
11369 if Ada_Version_Explicit >= Ada_2005 then
11370 Ent := Find_Lib_Unit_Name;
11371 Set_Is_Preelaborated (Ent);
11372 Set_Suppress_Elaboration_Warnings (Ent);
11373 end if;
11374 end Preelaborate_05;
11375
11376 --------------
11377 -- Priority --
11378 --------------
11379
11380 -- pragma Priority (EXPRESSION);
11381
11382 when Pragma_Priority => Priority : declare
11383 P : constant Node_Id := Parent (N);
11384 Arg : Node_Id;
11385
11386 begin
11387 Check_No_Identifiers;
11388 Check_Arg_Count (1);
11389
11390 -- Subprogram case
11391
11392 if Nkind (P) = N_Subprogram_Body then
11393 Check_In_Main_Program;
11394
11395 Arg := Get_Pragma_Arg (Arg1);
11396 Analyze_And_Resolve (Arg, Standard_Integer);
11397
11398 -- Must be static
11399
11400 if not Is_Static_Expression (Arg) then
11401 Flag_Non_Static_Expr
11402 ("main subprogram priority is not static!", Arg);
11403 raise Pragma_Exit;
11404
11405 -- If constraint error, then we already signalled an error
11406
11407 elsif Raises_Constraint_Error (Arg) then
11408 null;
11409
11410 -- Otherwise check in range
11411
11412 else
11413 declare
11414 Val : constant Uint := Expr_Value (Arg);
11415
11416 begin
11417 if Val < 0
11418 or else Val > Expr_Value (Expression
11419 (Parent (RTE (RE_Max_Priority))))
11420 then
11421 Error_Pragma_Arg
11422 ("main subprogram priority is out of range", Arg1);
11423 end if;
11424 end;
11425 end if;
11426
11427 Set_Main_Priority
11428 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11429
11430 -- Load an arbitrary entity from System.Tasking to make sure
11431 -- this package is implicitly with'ed, since we need to have
11432 -- the tasking run-time active for the pragma Priority to have
11433 -- any effect.
11434
11435 declare
11436 Discard : Entity_Id;
11437 pragma Warnings (Off, Discard);
11438 begin
11439 Discard := RTE (RE_Task_List);
11440 end;
11441
11442 -- Task or Protected, must be of type Integer
11443
11444 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11445 Arg := Get_Pragma_Arg (Arg1);
11446
11447 -- The expression must be analyzed in the special manner
11448 -- described in "Handling of Default and Per-Object
11449 -- Expressions" in sem.ads.
11450
11451 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11452
11453 if not Is_Static_Expression (Arg) then
11454 Check_Restriction (Static_Priorities, Arg);
11455 end if;
11456
11457 -- Anything else is incorrect
11458
11459 else
11460 Pragma_Misplaced;
11461 end if;
11462
11463 if Has_Pragma_Priority (P) then
11464 Error_Pragma ("duplicate pragma% not allowed");
11465 else
11466 Set_Has_Pragma_Priority (P, True);
11467
11468 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11469 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11470 -- exp_ch9 should use this ???
11471 end if;
11472 end if;
11473 end Priority;
11474
11475 -----------------------------------
11476 -- Priority_Specific_Dispatching --
11477 -----------------------------------
11478
11479 -- pragma Priority_Specific_Dispatching (
11480 -- policy_IDENTIFIER,
11481 -- first_priority_EXPRESSION,
11482 -- last_priority_EXPRESSION);
11483
11484 when Pragma_Priority_Specific_Dispatching =>
11485 Priority_Specific_Dispatching : declare
11486 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11487 -- This is the entity System.Any_Priority;
11488
11489 DP : Character;
11490 Lower_Bound : Node_Id;
11491 Upper_Bound : Node_Id;
11492 Lower_Val : Uint;
11493 Upper_Val : Uint;
11494
11495 begin
11496 Ada_2005_Pragma;
11497 Check_Arg_Count (3);
11498 Check_No_Identifiers;
11499 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11500 Check_Valid_Configuration_Pragma;
11501 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11502 DP := Fold_Upper (Name_Buffer (1));
11503
11504 Lower_Bound := Get_Pragma_Arg (Arg2);
11505 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11506 Lower_Val := Expr_Value (Lower_Bound);
11507
11508 Upper_Bound := Get_Pragma_Arg (Arg3);
11509 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11510 Upper_Val := Expr_Value (Upper_Bound);
11511
11512 -- It is not allowed to use Task_Dispatching_Policy and
11513 -- Priority_Specific_Dispatching in the same partition.
11514
11515 if Task_Dispatching_Policy /= ' ' then
11516 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11517 Error_Pragma
11518 ("pragma% incompatible with Task_Dispatching_Policy#");
11519
11520 -- Check lower bound in range
11521
11522 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11523 or else
11524 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11525 then
11526 Error_Pragma_Arg
11527 ("first_priority is out of range", Arg2);
11528
11529 -- Check upper bound in range
11530
11531 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11532 or else
11533 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11534 then
11535 Error_Pragma_Arg
11536 ("last_priority is out of range", Arg3);
11537
11538 -- Check that the priority range is valid
11539
11540 elsif Lower_Val > Upper_Val then
11541 Error_Pragma
11542 ("last_priority_expression must be greater than" &
11543 " or equal to first_priority_expression");
11544
11545 -- Store the new policy, but always preserve System_Location since
11546 -- we like the error message with the run-time name.
11547
11548 else
11549 -- Check overlapping in the priority ranges specified in other
11550 -- Priority_Specific_Dispatching pragmas within the same
11551 -- partition. We can only check those we know about!
11552
11553 for J in
11554 Specific_Dispatching.First .. Specific_Dispatching.Last
11555 loop
11556 if Specific_Dispatching.Table (J).First_Priority in
11557 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11558 or else Specific_Dispatching.Table (J).Last_Priority in
11559 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11560 then
11561 Error_Msg_Sloc :=
11562 Specific_Dispatching.Table (J).Pragma_Loc;
11563 Error_Pragma
11564 ("priority range overlaps with "
11565 & "Priority_Specific_Dispatching#");
11566 end if;
11567 end loop;
11568
11569 -- The use of Priority_Specific_Dispatching is incompatible
11570 -- with Task_Dispatching_Policy.
11571
11572 if Task_Dispatching_Policy /= ' ' then
11573 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11574 Error_Pragma
11575 ("Priority_Specific_Dispatching incompatible "
11576 & "with Task_Dispatching_Policy#");
11577 end if;
11578
11579 -- The use of Priority_Specific_Dispatching forces ceiling
11580 -- locking policy.
11581
11582 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11583 Error_Msg_Sloc := Locking_Policy_Sloc;
11584 Error_Pragma
11585 ("Priority_Specific_Dispatching incompatible "
11586 & "with Locking_Policy#");
11587
11588 -- Set the Ceiling_Locking policy, but preserve System_Location
11589 -- since we like the error message with the run time name.
11590
11591 else
11592 Locking_Policy := 'C';
11593
11594 if Locking_Policy_Sloc /= System_Location then
11595 Locking_Policy_Sloc := Loc;
11596 end if;
11597 end if;
11598
11599 -- Add entry in the table
11600
11601 Specific_Dispatching.Append
11602 ((Dispatching_Policy => DP,
11603 First_Priority => UI_To_Int (Lower_Val),
11604 Last_Priority => UI_To_Int (Upper_Val),
11605 Pragma_Loc => Loc));
11606 end if;
11607 end Priority_Specific_Dispatching;
11608
11609 -------------
11610 -- Profile --
11611 -------------
11612
11613 -- pragma Profile (profile_IDENTIFIER);
11614
11615 -- profile_IDENTIFIER => Restricted | Ravenscar
11616
11617 when Pragma_Profile =>
11618 Ada_2005_Pragma;
11619 Check_Arg_Count (1);
11620 Check_Valid_Configuration_Pragma;
11621 Check_No_Identifiers;
11622
11623 declare
11624 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11625 begin
11626 if Chars (Argx) = Name_Ravenscar then
11627 Set_Ravenscar_Profile (N);
11628 elsif Chars (Argx) = Name_Restricted then
11629 Set_Profile_Restrictions
11630 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11631 else
11632 Error_Pragma_Arg ("& is not a valid profile", Argx);
11633 end if;
11634 end;
11635
11636 ----------------------
11637 -- Profile_Warnings --
11638 ----------------------
11639
11640 -- pragma Profile_Warnings (profile_IDENTIFIER);
11641
11642 -- profile_IDENTIFIER => Restricted | Ravenscar
11643
11644 when Pragma_Profile_Warnings =>
11645 GNAT_Pragma;
11646 Check_Arg_Count (1);
11647 Check_Valid_Configuration_Pragma;
11648 Check_No_Identifiers;
11649
11650 declare
11651 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11652 begin
11653 if Chars (Argx) = Name_Ravenscar then
11654 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11655 elsif Chars (Argx) = Name_Restricted then
11656 Set_Profile_Restrictions (Restricted, N, Warn => True);
11657 else
11658 Error_Pragma_Arg ("& is not a valid profile", Argx);
11659 end if;
11660 end;
11661
11662 --------------------------
11663 -- Propagate_Exceptions --
11664 --------------------------
11665
11666 -- pragma Propagate_Exceptions;
11667
11668 -- Note: this pragma is obsolete and has no effect
11669
11670 when Pragma_Propagate_Exceptions =>
11671 GNAT_Pragma;
11672 Check_Arg_Count (0);
11673
11674 if In_Extended_Main_Source_Unit (N) then
11675 Propagate_Exceptions := True;
11676 end if;
11677
11678 ------------------
11679 -- Psect_Object --
11680 ------------------
11681
11682 -- pragma Psect_Object (
11683 -- [Internal =>] LOCAL_NAME,
11684 -- [, [External =>] EXTERNAL_SYMBOL]
11685 -- [, [Size =>] EXTERNAL_SYMBOL]);
11686
11687 when Pragma_Psect_Object | Pragma_Common_Object =>
11688 Psect_Object : declare
11689 Args : Args_List (1 .. 3);
11690 Names : constant Name_List (1 .. 3) := (
11691 Name_Internal,
11692 Name_External,
11693 Name_Size);
11694
11695 Internal : Node_Id renames Args (1);
11696 External : Node_Id renames Args (2);
11697 Size : Node_Id renames Args (3);
11698
11699 Def_Id : Entity_Id;
11700
11701 procedure Check_Too_Long (Arg : Node_Id);
11702 -- Posts message if the argument is an identifier with more
11703 -- than 31 characters, or a string literal with more than
11704 -- 31 characters, and we are operating under VMS
11705
11706 --------------------
11707 -- Check_Too_Long --
11708 --------------------
11709
11710 procedure Check_Too_Long (Arg : Node_Id) is
11711 X : constant Node_Id := Original_Node (Arg);
11712
11713 begin
11714 if not Nkind_In (X, N_String_Literal, N_Identifier) then
11715 Error_Pragma_Arg
11716 ("inappropriate argument for pragma %", Arg);
11717 end if;
11718
11719 if OpenVMS_On_Target then
11720 if (Nkind (X) = N_String_Literal
11721 and then String_Length (Strval (X)) > 31)
11722 or else
11723 (Nkind (X) = N_Identifier
11724 and then Length_Of_Name (Chars (X)) > 31)
11725 then
11726 Error_Pragma_Arg
11727 ("argument for pragma % is longer than 31 characters",
11728 Arg);
11729 end if;
11730 end if;
11731 end Check_Too_Long;
11732
11733 -- Start of processing for Common_Object/Psect_Object
11734
11735 begin
11736 GNAT_Pragma;
11737 Gather_Associations (Names, Args);
11738 Process_Extended_Import_Export_Internal_Arg (Internal);
11739
11740 Def_Id := Entity (Internal);
11741
11742 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11743 Error_Pragma_Arg
11744 ("pragma% must designate an object", Internal);
11745 end if;
11746
11747 Check_Too_Long (Internal);
11748
11749 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11750 Error_Pragma_Arg
11751 ("cannot use pragma% for imported/exported object",
11752 Internal);
11753 end if;
11754
11755 if Is_Concurrent_Type (Etype (Internal)) then
11756 Error_Pragma_Arg
11757 ("cannot specify pragma % for task/protected object",
11758 Internal);
11759 end if;
11760
11761 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11762 or else
11763 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11764 then
11765 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11766 end if;
11767
11768 if Ekind (Def_Id) = E_Constant then
11769 Error_Pragma_Arg
11770 ("cannot specify pragma % for a constant", Internal);
11771 end if;
11772
11773 if Is_Record_Type (Etype (Internal)) then
11774 declare
11775 Ent : Entity_Id;
11776 Decl : Entity_Id;
11777
11778 begin
11779 Ent := First_Entity (Etype (Internal));
11780 while Present (Ent) loop
11781 Decl := Declaration_Node (Ent);
11782
11783 if Ekind (Ent) = E_Component
11784 and then Nkind (Decl) = N_Component_Declaration
11785 and then Present (Expression (Decl))
11786 and then Warn_On_Export_Import
11787 then
11788 Error_Msg_N
11789 ("?object for pragma % has defaults", Internal);
11790 exit;
11791
11792 else
11793 Next_Entity (Ent);
11794 end if;
11795 end loop;
11796 end;
11797 end if;
11798
11799 if Present (Size) then
11800 Check_Too_Long (Size);
11801 end if;
11802
11803 if Present (External) then
11804 Check_Arg_Is_External_Name (External);
11805 Check_Too_Long (External);
11806 end if;
11807
11808 -- If all error tests pass, link pragma on to the rep item chain
11809
11810 Record_Rep_Item (Def_Id, N);
11811 end Psect_Object;
11812
11813 ----------
11814 -- Pure --
11815 ----------
11816
11817 -- pragma Pure [(library_unit_NAME)];
11818
11819 when Pragma_Pure => Pure : declare
11820 Ent : Entity_Id;
11821
11822 begin
11823 Check_Ada_83_Warning;
11824 Check_Valid_Library_Unit_Pragma;
11825
11826 if Nkind (N) = N_Null_Statement then
11827 return;
11828 end if;
11829
11830 Ent := Find_Lib_Unit_Name;
11831 Set_Is_Pure (Ent);
11832 Set_Has_Pragma_Pure (Ent);
11833 Set_Suppress_Elaboration_Warnings (Ent);
11834 end Pure;
11835
11836 -------------
11837 -- Pure_05 --
11838 -------------
11839
11840 -- pragma Pure_05 [(library_unit_NAME)];
11841
11842 -- This pragma is useable only in GNAT_Mode, where it is used like
11843 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11844 -- it is ignored). It may be used after a pragma Preelaborate, in
11845 -- which case it overrides the effect of the pragma Preelaborate.
11846 -- This is used to implement AI-362 which recategorizes some run-time
11847 -- packages in Ada 2005 mode.
11848
11849 when Pragma_Pure_05 => Pure_05 : declare
11850 Ent : Entity_Id;
11851
11852 begin
11853 GNAT_Pragma;
11854 Check_Valid_Library_Unit_Pragma;
11855
11856 if not GNAT_Mode then
11857 Error_Pragma ("pragma% only available in GNAT mode");
11858 end if;
11859
11860 if Nkind (N) = N_Null_Statement then
11861 return;
11862 end if;
11863
11864 -- This is one of the few cases where we need to test the value of
11865 -- Ada_Version_Explicit rather than Ada_Version (which is always
11866 -- set to Ada_2012 in a predefined unit), we need to know the
11867 -- explicit version set to know if this pragma is active.
11868
11869 if Ada_Version_Explicit >= Ada_2005 then
11870 Ent := Find_Lib_Unit_Name;
11871 Set_Is_Preelaborated (Ent, False);
11872 Set_Is_Pure (Ent);
11873 Set_Suppress_Elaboration_Warnings (Ent);
11874 end if;
11875 end Pure_05;
11876
11877 -------------------
11878 -- Pure_Function --
11879 -------------------
11880
11881 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
11882
11883 when Pragma_Pure_Function => Pure_Function : declare
11884 E_Id : Node_Id;
11885 E : Entity_Id;
11886 Def_Id : Entity_Id;
11887 Effective : Boolean := False;
11888
11889 begin
11890 GNAT_Pragma;
11891 Check_Arg_Count (1);
11892 Check_Optional_Identifier (Arg1, Name_Entity);
11893 Check_Arg_Is_Local_Name (Arg1);
11894 E_Id := Get_Pragma_Arg (Arg1);
11895
11896 if Error_Posted (E_Id) then
11897 return;
11898 end if;
11899
11900 -- Loop through homonyms (overloadings) of referenced entity
11901
11902 E := Entity (E_Id);
11903
11904 if Present (E) then
11905 loop
11906 Def_Id := Get_Base_Subprogram (E);
11907
11908 if not Ekind_In (Def_Id, E_Function,
11909 E_Generic_Function,
11910 E_Operator)
11911 then
11912 Error_Pragma_Arg
11913 ("pragma% requires a function name", Arg1);
11914 end if;
11915
11916 Set_Is_Pure (Def_Id);
11917
11918 if not Has_Pragma_Pure_Function (Def_Id) then
11919 Set_Has_Pragma_Pure_Function (Def_Id);
11920 Effective := True;
11921 end if;
11922
11923 exit when From_Aspect_Specification (N);
11924 E := Homonym (E);
11925 exit when No (E) or else Scope (E) /= Current_Scope;
11926 end loop;
11927
11928 if not Effective
11929 and then Warn_On_Redundant_Constructs
11930 then
11931 Error_Msg_NE
11932 ("pragma Pure_Function on& is redundant?",
11933 N, Entity (E_Id));
11934 end if;
11935 end if;
11936 end Pure_Function;
11937
11938 --------------------
11939 -- Queuing_Policy --
11940 --------------------
11941
11942 -- pragma Queuing_Policy (policy_IDENTIFIER);
11943
11944 when Pragma_Queuing_Policy => declare
11945 QP : Character;
11946
11947 begin
11948 Check_Ada_83_Warning;
11949 Check_Arg_Count (1);
11950 Check_No_Identifiers;
11951 Check_Arg_Is_Queuing_Policy (Arg1);
11952 Check_Valid_Configuration_Pragma;
11953 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11954 QP := Fold_Upper (Name_Buffer (1));
11955
11956 if Queuing_Policy /= ' '
11957 and then Queuing_Policy /= QP
11958 then
11959 Error_Msg_Sloc := Queuing_Policy_Sloc;
11960 Error_Pragma ("queuing policy incompatible with policy#");
11961
11962 -- Set new policy, but always preserve System_Location since we
11963 -- like the error message with the run time name.
11964
11965 else
11966 Queuing_Policy := QP;
11967
11968 if Queuing_Policy_Sloc /= System_Location then
11969 Queuing_Policy_Sloc := Loc;
11970 end if;
11971 end if;
11972 end;
11973
11974 -----------------------
11975 -- Relative_Deadline --
11976 -----------------------
11977
11978 -- pragma Relative_Deadline (time_span_EXPRESSION);
11979
11980 when Pragma_Relative_Deadline => Relative_Deadline : declare
11981 P : constant Node_Id := Parent (N);
11982 Arg : Node_Id;
11983
11984 begin
11985 Ada_2005_Pragma;
11986 Check_No_Identifiers;
11987 Check_Arg_Count (1);
11988
11989 Arg := Get_Pragma_Arg (Arg1);
11990
11991 -- The expression must be analyzed in the special manner described
11992 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
11993
11994 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
11995
11996 -- Subprogram case
11997
11998 if Nkind (P) = N_Subprogram_Body then
11999 Check_In_Main_Program;
12000
12001 -- Tasks
12002
12003 elsif Nkind (P) = N_Task_Definition then
12004 null;
12005
12006 -- Anything else is incorrect
12007
12008 else
12009 Pragma_Misplaced;
12010 end if;
12011
12012 if Has_Relative_Deadline_Pragma (P) then
12013 Error_Pragma ("duplicate pragma% not allowed");
12014 else
12015 Set_Has_Relative_Deadline_Pragma (P, True);
12016
12017 if Nkind (P) = N_Task_Definition then
12018 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12019 end if;
12020 end if;
12021 end Relative_Deadline;
12022
12023 ---------------------------
12024 -- Remote_Call_Interface --
12025 ---------------------------
12026
12027 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12028
12029 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12030 Cunit_Node : Node_Id;
12031 Cunit_Ent : Entity_Id;
12032 K : Node_Kind;
12033
12034 begin
12035 Check_Ada_83_Warning;
12036 Check_Valid_Library_Unit_Pragma;
12037
12038 if Nkind (N) = N_Null_Statement then
12039 return;
12040 end if;
12041
12042 Cunit_Node := Cunit (Current_Sem_Unit);
12043 K := Nkind (Unit (Cunit_Node));
12044 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12045
12046 if K = N_Package_Declaration
12047 or else K = N_Generic_Package_Declaration
12048 or else K = N_Subprogram_Declaration
12049 or else K = N_Generic_Subprogram_Declaration
12050 or else (K = N_Subprogram_Body
12051 and then Acts_As_Spec (Unit (Cunit_Node)))
12052 then
12053 null;
12054 else
12055 Error_Pragma (
12056 "pragma% must apply to package or subprogram declaration");
12057 end if;
12058
12059 Set_Is_Remote_Call_Interface (Cunit_Ent);
12060 end Remote_Call_Interface;
12061
12062 ------------------
12063 -- Remote_Types --
12064 ------------------
12065
12066 -- pragma Remote_Types [(library_unit_NAME)];
12067
12068 when Pragma_Remote_Types => Remote_Types : declare
12069 Cunit_Node : Node_Id;
12070 Cunit_Ent : Entity_Id;
12071
12072 begin
12073 Check_Ada_83_Warning;
12074 Check_Valid_Library_Unit_Pragma;
12075
12076 if Nkind (N) = N_Null_Statement then
12077 return;
12078 end if;
12079
12080 Cunit_Node := Cunit (Current_Sem_Unit);
12081 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12082
12083 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12084 N_Generic_Package_Declaration)
12085 then
12086 Error_Pragma
12087 ("pragma% can only apply to a package declaration");
12088 end if;
12089
12090 Set_Is_Remote_Types (Cunit_Ent);
12091 end Remote_Types;
12092
12093 ---------------
12094 -- Ravenscar --
12095 ---------------
12096
12097 -- pragma Ravenscar;
12098
12099 when Pragma_Ravenscar =>
12100 GNAT_Pragma;
12101 Check_Arg_Count (0);
12102 Check_Valid_Configuration_Pragma;
12103 Set_Ravenscar_Profile (N);
12104
12105 if Warn_On_Obsolescent_Feature then
12106 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12107 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12108 end if;
12109
12110 -------------------------
12111 -- Restricted_Run_Time --
12112 -------------------------
12113
12114 -- pragma Restricted_Run_Time;
12115
12116 when Pragma_Restricted_Run_Time =>
12117 GNAT_Pragma;
12118 Check_Arg_Count (0);
12119 Check_Valid_Configuration_Pragma;
12120 Set_Profile_Restrictions
12121 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12122
12123 if Warn_On_Obsolescent_Feature then
12124 Error_Msg_N
12125 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12126 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12127 end if;
12128
12129 ------------------
12130 -- Restrictions --
12131 ------------------
12132
12133 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12134
12135 -- RESTRICTION ::=
12136 -- restriction_IDENTIFIER
12137 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12138
12139 when Pragma_Restrictions =>
12140 Process_Restrictions_Or_Restriction_Warnings
12141 (Warn => Treat_Restrictions_As_Warnings);
12142
12143 --------------------------
12144 -- Restriction_Warnings --
12145 --------------------------
12146
12147 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12148
12149 -- RESTRICTION ::=
12150 -- restriction_IDENTIFIER
12151 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12152
12153 when Pragma_Restriction_Warnings =>
12154 GNAT_Pragma;
12155 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12156
12157 ----------------
12158 -- Reviewable --
12159 ----------------
12160
12161 -- pragma Reviewable;
12162
12163 when Pragma_Reviewable =>
12164 Check_Ada_83_Warning;
12165 Check_Arg_Count (0);
12166
12167 -- Call dummy debugging function rv. This is done to assist front
12168 -- end debugging. By placing a Reviewable pragma in the source
12169 -- program, a breakpoint on rv catches this place in the source,
12170 -- allowing convenient stepping to the point of interest.
12171
12172 rv;
12173
12174 --------------------------
12175 -- Short_Circuit_And_Or --
12176 --------------------------
12177
12178 when Pragma_Short_Circuit_And_Or =>
12179 GNAT_Pragma;
12180 Check_Arg_Count (0);
12181 Check_Valid_Configuration_Pragma;
12182 Short_Circuit_And_Or := True;
12183
12184 -------------------
12185 -- Share_Generic --
12186 -------------------
12187
12188 -- pragma Share_Generic (NAME {, NAME});
12189
12190 when Pragma_Share_Generic =>
12191 GNAT_Pragma;
12192 Process_Generic_List;
12193
12194 ------------
12195 -- Shared --
12196 ------------
12197
12198 -- pragma Shared (LOCAL_NAME);
12199
12200 when Pragma_Shared =>
12201 GNAT_Pragma;
12202 Process_Atomic_Shared_Volatile;
12203
12204 --------------------
12205 -- Shared_Passive --
12206 --------------------
12207
12208 -- pragma Shared_Passive [(library_unit_NAME)];
12209
12210 -- Set the flag Is_Shared_Passive of program unit name entity
12211
12212 when Pragma_Shared_Passive => Shared_Passive : declare
12213 Cunit_Node : Node_Id;
12214 Cunit_Ent : Entity_Id;
12215
12216 begin
12217 Check_Ada_83_Warning;
12218 Check_Valid_Library_Unit_Pragma;
12219
12220 if Nkind (N) = N_Null_Statement then
12221 return;
12222 end if;
12223
12224 Cunit_Node := Cunit (Current_Sem_Unit);
12225 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12226
12227 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12228 N_Generic_Package_Declaration)
12229 then
12230 Error_Pragma
12231 ("pragma% can only apply to a package declaration");
12232 end if;
12233
12234 Set_Is_Shared_Passive (Cunit_Ent);
12235 end Shared_Passive;
12236
12237 -----------------------
12238 -- Short_Descriptors --
12239 -----------------------
12240
12241 -- pragma Short_Descriptors;
12242
12243 when Pragma_Short_Descriptors =>
12244 GNAT_Pragma;
12245 Check_Arg_Count (0);
12246 Check_Valid_Configuration_Pragma;
12247 Short_Descriptors := True;
12248
12249 ----------------------
12250 -- Source_File_Name --
12251 ----------------------
12252
12253 -- There are five forms for this pragma:
12254
12255 -- pragma Source_File_Name (
12256 -- [UNIT_NAME =>] unit_NAME,
12257 -- BODY_FILE_NAME => STRING_LITERAL
12258 -- [, [INDEX =>] INTEGER_LITERAL]);
12259
12260 -- pragma Source_File_Name (
12261 -- [UNIT_NAME =>] unit_NAME,
12262 -- SPEC_FILE_NAME => STRING_LITERAL
12263 -- [, [INDEX =>] INTEGER_LITERAL]);
12264
12265 -- pragma Source_File_Name (
12266 -- BODY_FILE_NAME => STRING_LITERAL
12267 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12268 -- [, CASING => CASING_SPEC]);
12269
12270 -- pragma Source_File_Name (
12271 -- SPEC_FILE_NAME => STRING_LITERAL
12272 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12273 -- [, CASING => CASING_SPEC]);
12274
12275 -- pragma Source_File_Name (
12276 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12277 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12278 -- [, CASING => CASING_SPEC]);
12279
12280 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12281
12282 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12283 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12284 -- only be used when no project file is used, while SFNP can only be
12285 -- used when a project file is used.
12286
12287 -- No processing here. Processing was completed during parsing, since
12288 -- we need to have file names set as early as possible. Units are
12289 -- loaded well before semantic processing starts.
12290
12291 -- The only processing we defer to this point is the check for
12292 -- correct placement.
12293
12294 when Pragma_Source_File_Name =>
12295 GNAT_Pragma;
12296 Check_Valid_Configuration_Pragma;
12297
12298 ------------------------------
12299 -- Source_File_Name_Project --
12300 ------------------------------
12301
12302 -- See Source_File_Name for syntax
12303
12304 -- No processing here. Processing was completed during parsing, since
12305 -- we need to have file names set as early as possible. Units are
12306 -- loaded well before semantic processing starts.
12307
12308 -- The only processing we defer to this point is the check for
12309 -- correct placement.
12310
12311 when Pragma_Source_File_Name_Project =>
12312 GNAT_Pragma;
12313 Check_Valid_Configuration_Pragma;
12314
12315 -- Check that a pragma Source_File_Name_Project is used only in a
12316 -- configuration pragmas file.
12317
12318 -- Pragmas Source_File_Name_Project should only be generated by
12319 -- the Project Manager in configuration pragmas files.
12320
12321 -- This is really an ugly test. It seems to depend on some
12322 -- accidental and undocumented property. At the very least it
12323 -- needs to be documented, but it would be better to have a
12324 -- clean way of testing if we are in a configuration file???
12325
12326 if Present (Parent (N)) then
12327 Error_Pragma
12328 ("pragma% can only appear in a configuration pragmas file");
12329 end if;
12330
12331 ----------------------
12332 -- Source_Reference --
12333 ----------------------
12334
12335 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12336
12337 -- Nothing to do, all processing completed in Par.Prag, since we need
12338 -- the information for possible parser messages that are output.
12339
12340 when Pragma_Source_Reference =>
12341 GNAT_Pragma;
12342
12343 --------------------------------
12344 -- Static_Elaboration_Desired --
12345 --------------------------------
12346
12347 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12348
12349 when Pragma_Static_Elaboration_Desired =>
12350 GNAT_Pragma;
12351 Check_At_Most_N_Arguments (1);
12352
12353 if Is_Compilation_Unit (Current_Scope)
12354 and then Ekind (Current_Scope) = E_Package
12355 then
12356 Set_Static_Elaboration_Desired (Current_Scope, True);
12357 else
12358 Error_Pragma ("pragma% must apply to a library-level package");
12359 end if;
12360
12361 ------------------
12362 -- Storage_Size --
12363 ------------------
12364
12365 -- pragma Storage_Size (EXPRESSION);
12366
12367 when Pragma_Storage_Size => Storage_Size : declare
12368 P : constant Node_Id := Parent (N);
12369 Arg : Node_Id;
12370
12371 begin
12372 Check_No_Identifiers;
12373 Check_Arg_Count (1);
12374
12375 -- The expression must be analyzed in the special manner described
12376 -- in "Handling of Default Expressions" in sem.ads.
12377
12378 Arg := Get_Pragma_Arg (Arg1);
12379 Preanalyze_Spec_Expression (Arg, Any_Integer);
12380
12381 if not Is_Static_Expression (Arg) then
12382 Check_Restriction (Static_Storage_Size, Arg);
12383 end if;
12384
12385 if Nkind (P) /= N_Task_Definition then
12386 Pragma_Misplaced;
12387 return;
12388
12389 else
12390 if Has_Storage_Size_Pragma (P) then
12391 Error_Pragma ("duplicate pragma% not allowed");
12392 else
12393 Set_Has_Storage_Size_Pragma (P, True);
12394 end if;
12395
12396 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12397 -- ??? exp_ch9 should use this!
12398 end if;
12399 end Storage_Size;
12400
12401 ------------------
12402 -- Storage_Unit --
12403 ------------------
12404
12405 -- pragma Storage_Unit (NUMERIC_LITERAL);
12406
12407 -- Only permitted argument is System'Storage_Unit value
12408
12409 when Pragma_Storage_Unit =>
12410 Check_No_Identifiers;
12411 Check_Arg_Count (1);
12412 Check_Arg_Is_Integer_Literal (Arg1);
12413
12414 if Intval (Get_Pragma_Arg (Arg1)) /=
12415 UI_From_Int (Ttypes.System_Storage_Unit)
12416 then
12417 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12418 Error_Pragma_Arg
12419 ("the only allowed argument for pragma% is ^", Arg1);
12420 end if;
12421
12422 --------------------
12423 -- Stream_Convert --
12424 --------------------
12425
12426 -- pragma Stream_Convert (
12427 -- [Entity =>] type_LOCAL_NAME,
12428 -- [Read =>] function_NAME,
12429 -- [Write =>] function NAME);
12430
12431 when Pragma_Stream_Convert => Stream_Convert : declare
12432
12433 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12434 -- Check that the given argument is the name of a local function
12435 -- of one argument that is not overloaded earlier in the current
12436 -- local scope. A check is also made that the argument is a
12437 -- function with one parameter.
12438
12439 --------------------------------------
12440 -- Check_OK_Stream_Convert_Function --
12441 --------------------------------------
12442
12443 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12444 Ent : Entity_Id;
12445
12446 begin
12447 Check_Arg_Is_Local_Name (Arg);
12448 Ent := Entity (Get_Pragma_Arg (Arg));
12449
12450 if Has_Homonym (Ent) then
12451 Error_Pragma_Arg
12452 ("argument for pragma% may not be overloaded", Arg);
12453 end if;
12454
12455 if Ekind (Ent) /= E_Function
12456 or else No (First_Formal (Ent))
12457 or else Present (Next_Formal (First_Formal (Ent)))
12458 then
12459 Error_Pragma_Arg
12460 ("argument for pragma% must be" &
12461 " function of one argument", Arg);
12462 end if;
12463 end Check_OK_Stream_Convert_Function;
12464
12465 -- Start of processing for Stream_Convert
12466
12467 begin
12468 GNAT_Pragma;
12469 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12470 Check_Arg_Count (3);
12471 Check_Optional_Identifier (Arg1, Name_Entity);
12472 Check_Optional_Identifier (Arg2, Name_Read);
12473 Check_Optional_Identifier (Arg3, Name_Write);
12474 Check_Arg_Is_Local_Name (Arg1);
12475 Check_OK_Stream_Convert_Function (Arg2);
12476 Check_OK_Stream_Convert_Function (Arg3);
12477
12478 declare
12479 Typ : constant Entity_Id :=
12480 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12481 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12482 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12483
12484 begin
12485 Check_First_Subtype (Arg1);
12486
12487 -- Check for too early or too late. Note that we don't enforce
12488 -- the rule about primitive operations in this case, since, as
12489 -- is the case for explicit stream attributes themselves, these
12490 -- restrictions are not appropriate. Note that the chaining of
12491 -- the pragma by Rep_Item_Too_Late is actually the critical
12492 -- processing done for this pragma.
12493
12494 if Rep_Item_Too_Early (Typ, N)
12495 or else
12496 Rep_Item_Too_Late (Typ, N, FOnly => True)
12497 then
12498 return;
12499 end if;
12500
12501 -- Return if previous error
12502
12503 if Etype (Typ) = Any_Type
12504 or else
12505 Etype (Read) = Any_Type
12506 or else
12507 Etype (Write) = Any_Type
12508 then
12509 return;
12510 end if;
12511
12512 -- Error checks
12513
12514 if Underlying_Type (Etype (Read)) /= Typ then
12515 Error_Pragma_Arg
12516 ("incorrect return type for function&", Arg2);
12517 end if;
12518
12519 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12520 Error_Pragma_Arg
12521 ("incorrect parameter type for function&", Arg3);
12522 end if;
12523
12524 if Underlying_Type (Etype (First_Formal (Read))) /=
12525 Underlying_Type (Etype (Write))
12526 then
12527 Error_Pragma_Arg
12528 ("result type of & does not match Read parameter type",
12529 Arg3);
12530 end if;
12531 end;
12532 end Stream_Convert;
12533
12534 -------------------------
12535 -- Style_Checks (GNAT) --
12536 -------------------------
12537
12538 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12539
12540 -- This is processed by the parser since some of the style checks
12541 -- take place during source scanning and parsing. This means that
12542 -- we don't need to issue error messages here.
12543
12544 when Pragma_Style_Checks => Style_Checks : declare
12545 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12546 S : String_Id;
12547 C : Char_Code;
12548
12549 begin
12550 GNAT_Pragma;
12551 Check_No_Identifiers;
12552
12553 -- Two argument form
12554
12555 if Arg_Count = 2 then
12556 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12557
12558 declare
12559 E_Id : Node_Id;
12560 E : Entity_Id;
12561
12562 begin
12563 E_Id := Get_Pragma_Arg (Arg2);
12564 Analyze (E_Id);
12565
12566 if not Is_Entity_Name (E_Id) then
12567 Error_Pragma_Arg
12568 ("second argument of pragma% must be entity name",
12569 Arg2);
12570 end if;
12571
12572 E := Entity (E_Id);
12573
12574 if E = Any_Id then
12575 return;
12576 else
12577 loop
12578 Set_Suppress_Style_Checks (E,
12579 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12580 exit when No (Homonym (E));
12581 E := Homonym (E);
12582 end loop;
12583 end if;
12584 end;
12585
12586 -- One argument form
12587
12588 else
12589 Check_Arg_Count (1);
12590
12591 if Nkind (A) = N_String_Literal then
12592 S := Strval (A);
12593
12594 declare
12595 Slen : constant Natural := Natural (String_Length (S));
12596 Options : String (1 .. Slen);
12597 J : Natural;
12598
12599 begin
12600 J := 1;
12601 loop
12602 C := Get_String_Char (S, Int (J));
12603 exit when not In_Character_Range (C);
12604 Options (J) := Get_Character (C);
12605
12606 -- If at end of string, set options. As per discussion
12607 -- above, no need to check for errors, since we issued
12608 -- them in the parser.
12609
12610 if J = Slen then
12611 Set_Style_Check_Options (Options);
12612 exit;
12613 end if;
12614
12615 J := J + 1;
12616 end loop;
12617 end;
12618
12619 elsif Nkind (A) = N_Identifier then
12620 if Chars (A) = Name_All_Checks then
12621 if GNAT_Mode then
12622 Set_GNAT_Style_Check_Options;
12623 else
12624 Set_Default_Style_Check_Options;
12625 end if;
12626
12627 elsif Chars (A) = Name_On then
12628 Style_Check := True;
12629
12630 elsif Chars (A) = Name_Off then
12631 Style_Check := False;
12632 end if;
12633 end if;
12634 end if;
12635 end Style_Checks;
12636
12637 --------------
12638 -- Subtitle --
12639 --------------
12640
12641 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12642
12643 when Pragma_Subtitle =>
12644 GNAT_Pragma;
12645 Check_Arg_Count (1);
12646 Check_Optional_Identifier (Arg1, Name_Subtitle);
12647 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12648 Store_Note (N);
12649
12650 --------------
12651 -- Suppress --
12652 --------------
12653
12654 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12655
12656 when Pragma_Suppress =>
12657 Process_Suppress_Unsuppress (True);
12658
12659 ------------------
12660 -- Suppress_All --
12661 ------------------
12662
12663 -- pragma Suppress_All;
12664
12665 -- The only check made here is that the pragma has no arguments.
12666 -- There are no placement rules, and the processing required (setting
12667 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
12668 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
12669 -- then creates and inserts a pragma Suppress (All_Checks).
12670
12671 when Pragma_Suppress_All =>
12672 GNAT_Pragma;
12673 Check_Arg_Count (0);
12674
12675 -------------------------
12676 -- Suppress_Debug_Info --
12677 -------------------------
12678
12679 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12680
12681 when Pragma_Suppress_Debug_Info =>
12682 GNAT_Pragma;
12683 Check_Arg_Count (1);
12684 Check_Optional_Identifier (Arg1, Name_Entity);
12685 Check_Arg_Is_Local_Name (Arg1);
12686 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
12687
12688 ----------------------------------
12689 -- Suppress_Exception_Locations --
12690 ----------------------------------
12691
12692 -- pragma Suppress_Exception_Locations;
12693
12694 when Pragma_Suppress_Exception_Locations =>
12695 GNAT_Pragma;
12696 Check_Arg_Count (0);
12697 Check_Valid_Configuration_Pragma;
12698 Exception_Locations_Suppressed := True;
12699
12700 -----------------------------
12701 -- Suppress_Initialization --
12702 -----------------------------
12703
12704 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12705
12706 when Pragma_Suppress_Initialization => Suppress_Init : declare
12707 E_Id : Node_Id;
12708 E : Entity_Id;
12709
12710 begin
12711 GNAT_Pragma;
12712 Check_Arg_Count (1);
12713 Check_Optional_Identifier (Arg1, Name_Entity);
12714 Check_Arg_Is_Local_Name (Arg1);
12715
12716 E_Id := Get_Pragma_Arg (Arg1);
12717
12718 if Etype (E_Id) = Any_Type then
12719 return;
12720 end if;
12721
12722 E := Entity (E_Id);
12723
12724 if Is_Type (E) then
12725 if Is_Incomplete_Or_Private_Type (E) then
12726 if No (Full_View (Base_Type (E))) then
12727 Error_Pragma_Arg
12728 ("argument of pragma% cannot be an incomplete type",
12729 Arg1);
12730 else
12731 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
12732 end if;
12733 else
12734 Set_Suppress_Init_Proc (Base_Type (E));
12735 end if;
12736
12737 else
12738 Error_Pragma_Arg
12739 ("pragma% requires argument that is a type name", Arg1);
12740 end if;
12741 end Suppress_Init;
12742
12743 -----------------
12744 -- System_Name --
12745 -----------------
12746
12747 -- pragma System_Name (DIRECT_NAME);
12748
12749 -- Syntax check: one argument, which must be the identifier GNAT or
12750 -- the identifier GCC, no other identifiers are acceptable.
12751
12752 when Pragma_System_Name =>
12753 GNAT_Pragma;
12754 Check_No_Identifiers;
12755 Check_Arg_Count (1);
12756 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12757
12758 -----------------------------
12759 -- Task_Dispatching_Policy --
12760 -----------------------------
12761
12762 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12763
12764 when Pragma_Task_Dispatching_Policy => declare
12765 DP : Character;
12766
12767 begin
12768 Check_Ada_83_Warning;
12769 Check_Arg_Count (1);
12770 Check_No_Identifiers;
12771 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12772 Check_Valid_Configuration_Pragma;
12773 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12774 DP := Fold_Upper (Name_Buffer (1));
12775
12776 if Task_Dispatching_Policy /= ' '
12777 and then Task_Dispatching_Policy /= DP
12778 then
12779 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12780 Error_Pragma
12781 ("task dispatching policy incompatible with policy#");
12782
12783 -- Set new policy, but always preserve System_Location since we
12784 -- like the error message with the run time name.
12785
12786 else
12787 Task_Dispatching_Policy := DP;
12788
12789 if Task_Dispatching_Policy_Sloc /= System_Location then
12790 Task_Dispatching_Policy_Sloc := Loc;
12791 end if;
12792 end if;
12793 end;
12794
12795 --------------
12796 -- Task_Info --
12797 --------------
12798
12799 -- pragma Task_Info (EXPRESSION);
12800
12801 when Pragma_Task_Info => Task_Info : declare
12802 P : constant Node_Id := Parent (N);
12803
12804 begin
12805 GNAT_Pragma;
12806
12807 if Nkind (P) /= N_Task_Definition then
12808 Error_Pragma ("pragma% must appear in task definition");
12809 end if;
12810
12811 Check_No_Identifiers;
12812 Check_Arg_Count (1);
12813
12814 Analyze_And_Resolve
12815 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12816
12817 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12818 return;
12819 end if;
12820
12821 if Has_Task_Info_Pragma (P) then
12822 Error_Pragma ("duplicate pragma% not allowed");
12823 else
12824 Set_Has_Task_Info_Pragma (P, True);
12825 end if;
12826 end Task_Info;
12827
12828 ---------------
12829 -- Task_Name --
12830 ---------------
12831
12832 -- pragma Task_Name (string_EXPRESSION);
12833
12834 when Pragma_Task_Name => Task_Name : declare
12835 P : constant Node_Id := Parent (N);
12836 Arg : Node_Id;
12837
12838 begin
12839 Check_No_Identifiers;
12840 Check_Arg_Count (1);
12841
12842 Arg := Get_Pragma_Arg (Arg1);
12843
12844 -- The expression is used in the call to Create_Task, and must be
12845 -- expanded there, not in the context of the current spec. It must
12846 -- however be analyzed to capture global references, in case it
12847 -- appears in a generic context.
12848
12849 Preanalyze_And_Resolve (Arg, Standard_String);
12850
12851 if Nkind (P) /= N_Task_Definition then
12852 Pragma_Misplaced;
12853 end if;
12854
12855 if Has_Task_Name_Pragma (P) then
12856 Error_Pragma ("duplicate pragma% not allowed");
12857 else
12858 Set_Has_Task_Name_Pragma (P, True);
12859 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12860 end if;
12861 end Task_Name;
12862
12863 ------------------
12864 -- Task_Storage --
12865 ------------------
12866
12867 -- pragma Task_Storage (
12868 -- [Task_Type =>] LOCAL_NAME,
12869 -- [Top_Guard =>] static_integer_EXPRESSION);
12870
12871 when Pragma_Task_Storage => Task_Storage : declare
12872 Args : Args_List (1 .. 2);
12873 Names : constant Name_List (1 .. 2) := (
12874 Name_Task_Type,
12875 Name_Top_Guard);
12876
12877 Task_Type : Node_Id renames Args (1);
12878 Top_Guard : Node_Id renames Args (2);
12879
12880 Ent : Entity_Id;
12881
12882 begin
12883 GNAT_Pragma;
12884 Gather_Associations (Names, Args);
12885
12886 if No (Task_Type) then
12887 Error_Pragma
12888 ("missing task_type argument for pragma%");
12889 end if;
12890
12891 Check_Arg_Is_Local_Name (Task_Type);
12892
12893 Ent := Entity (Task_Type);
12894
12895 if not Is_Task_Type (Ent) then
12896 Error_Pragma_Arg
12897 ("argument for pragma% must be task type", Task_Type);
12898 end if;
12899
12900 if No (Top_Guard) then
12901 Error_Pragma_Arg
12902 ("pragma% takes two arguments", Task_Type);
12903 else
12904 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
12905 end if;
12906
12907 Check_First_Subtype (Task_Type);
12908
12909 if Rep_Item_Too_Late (Ent, N) then
12910 raise Pragma_Exit;
12911 end if;
12912 end Task_Storage;
12913
12914 --------------------------
12915 -- Thread_Local_Storage --
12916 --------------------------
12917
12918 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
12919
12920 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
12921 Id : Node_Id;
12922 E : Entity_Id;
12923
12924 begin
12925 GNAT_Pragma;
12926 Check_Arg_Count (1);
12927 Check_Optional_Identifier (Arg1, Name_Entity);
12928 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12929
12930 Id := Get_Pragma_Arg (Arg1);
12931 Analyze (Id);
12932
12933 if not Is_Entity_Name (Id)
12934 or else Ekind (Entity (Id)) /= E_Variable
12935 then
12936 Error_Pragma_Arg ("local variable name required", Arg1);
12937 end if;
12938
12939 E := Entity (Id);
12940
12941 if Rep_Item_Too_Early (E, N)
12942 or else Rep_Item_Too_Late (E, N)
12943 then
12944 raise Pragma_Exit;
12945 end if;
12946
12947 Set_Has_Pragma_Thread_Local_Storage (E);
12948 Set_Has_Gigi_Rep_Item (E);
12949 end Thread_Local_Storage;
12950
12951 ----------------
12952 -- Time_Slice --
12953 ----------------
12954
12955 -- pragma Time_Slice (static_duration_EXPRESSION);
12956
12957 when Pragma_Time_Slice => Time_Slice : declare
12958 Val : Ureal;
12959 Nod : Node_Id;
12960
12961 begin
12962 GNAT_Pragma;
12963 Check_Arg_Count (1);
12964 Check_No_Identifiers;
12965 Check_In_Main_Program;
12966 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
12967
12968 if not Error_Posted (Arg1) then
12969 Nod := Next (N);
12970 while Present (Nod) loop
12971 if Nkind (Nod) = N_Pragma
12972 and then Pragma_Name (Nod) = Name_Time_Slice
12973 then
12974 Error_Msg_Name_1 := Pname;
12975 Error_Msg_N ("duplicate pragma% not permitted", Nod);
12976 end if;
12977
12978 Next (Nod);
12979 end loop;
12980 end if;
12981
12982 -- Process only if in main unit
12983
12984 if Get_Source_Unit (Loc) = Main_Unit then
12985 Opt.Time_Slice_Set := True;
12986 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
12987
12988 if Val <= Ureal_0 then
12989 Opt.Time_Slice_Value := 0;
12990
12991 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
12992 Opt.Time_Slice_Value := 1_000_000_000;
12993
12994 else
12995 Opt.Time_Slice_Value :=
12996 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
12997 end if;
12998 end if;
12999 end Time_Slice;
13000
13001 -----------
13002 -- Title --
13003 -----------
13004
13005 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13006
13007 -- TITLING_OPTION ::=
13008 -- [Title =>] STRING_LITERAL
13009 -- | [Subtitle =>] STRING_LITERAL
13010
13011 when Pragma_Title => Title : declare
13012 Args : Args_List (1 .. 2);
13013 Names : constant Name_List (1 .. 2) := (
13014 Name_Title,
13015 Name_Subtitle);
13016
13017 begin
13018 GNAT_Pragma;
13019 Gather_Associations (Names, Args);
13020 Store_Note (N);
13021
13022 for J in 1 .. 2 loop
13023 if Present (Args (J)) then
13024 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13025 end if;
13026 end loop;
13027 end Title;
13028
13029 ---------------------
13030 -- Unchecked_Union --
13031 ---------------------
13032
13033 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13034
13035 when Pragma_Unchecked_Union => Unchecked_Union : declare
13036 Assoc : constant Node_Id := Arg1;
13037 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13038 Typ : Entity_Id;
13039 Discr : Entity_Id;
13040 Tdef : Node_Id;
13041 Clist : Node_Id;
13042 Vpart : Node_Id;
13043 Comp : Node_Id;
13044 Variant : Node_Id;
13045
13046 begin
13047 Ada_2005_Pragma;
13048 Check_No_Identifiers;
13049 Check_Arg_Count (1);
13050 Check_Arg_Is_Local_Name (Arg1);
13051
13052 Find_Type (Type_Id);
13053 Typ := Entity (Type_Id);
13054
13055 if Typ = Any_Type
13056 or else Rep_Item_Too_Early (Typ, N)
13057 then
13058 return;
13059 else
13060 Typ := Underlying_Type (Typ);
13061 end if;
13062
13063 if Rep_Item_Too_Late (Typ, N) then
13064 return;
13065 end if;
13066
13067 Check_First_Subtype (Arg1);
13068
13069 -- Note remaining cases are references to a type in the current
13070 -- declarative part. If we find an error, we post the error on
13071 -- the relevant type declaration at an appropriate point.
13072
13073 if not Is_Record_Type (Typ) then
13074 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13075 return;
13076
13077 elsif Is_Tagged_Type (Typ) then
13078 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13079 return;
13080
13081 elsif Is_Limited_Type (Typ) then
13082 Error_Msg_N
13083 ("Unchecked_Union must not be limited record type", Typ);
13084 Explain_Limited_Type (Typ, Typ);
13085 return;
13086
13087 else
13088 if not Has_Discriminants (Typ) then
13089 Error_Msg_N
13090 ("Unchecked_Union must have one discriminant", Typ);
13091 return;
13092 end if;
13093
13094 Discr := First_Discriminant (Typ);
13095 while Present (Discr) loop
13096 if No (Discriminant_Default_Value (Discr)) then
13097 Error_Msg_N
13098 ("Unchecked_Union discriminant must have default value",
13099 Discr);
13100 end if;
13101
13102 Next_Discriminant (Discr);
13103 end loop;
13104
13105 Tdef := Type_Definition (Declaration_Node (Typ));
13106 Clist := Component_List (Tdef);
13107
13108 Comp := First (Component_Items (Clist));
13109 while Present (Comp) loop
13110 Check_Component (Comp, Typ);
13111 Next (Comp);
13112 end loop;
13113
13114 if No (Clist) or else No (Variant_Part (Clist)) then
13115 Error_Msg_N
13116 ("Unchecked_Union must have variant part",
13117 Tdef);
13118 return;
13119 end if;
13120
13121 Vpart := Variant_Part (Clist);
13122
13123 Variant := First (Variants (Vpart));
13124 while Present (Variant) loop
13125 Check_Variant (Variant, Typ);
13126 Next (Variant);
13127 end loop;
13128 end if;
13129
13130 Set_Is_Unchecked_Union (Typ);
13131 Set_Convention (Typ, Convention_C);
13132 Set_Has_Unchecked_Union (Base_Type (Typ));
13133 Set_Is_Unchecked_Union (Base_Type (Typ));
13134 end Unchecked_Union;
13135
13136 ------------------------
13137 -- Unimplemented_Unit --
13138 ------------------------
13139
13140 -- pragma Unimplemented_Unit;
13141
13142 -- Note: this only gives an error if we are generating code, or if
13143 -- we are in a generic library unit (where the pragma appears in the
13144 -- body, not in the spec).
13145
13146 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13147 Cunitent : constant Entity_Id :=
13148 Cunit_Entity (Get_Source_Unit (Loc));
13149 Ent_Kind : constant Entity_Kind :=
13150 Ekind (Cunitent);
13151
13152 begin
13153 GNAT_Pragma;
13154 Check_Arg_Count (0);
13155
13156 if Operating_Mode = Generate_Code
13157 or else Ent_Kind = E_Generic_Function
13158 or else Ent_Kind = E_Generic_Procedure
13159 or else Ent_Kind = E_Generic_Package
13160 then
13161 Get_Name_String (Chars (Cunitent));
13162 Set_Casing (Mixed_Case);
13163 Write_Str (Name_Buffer (1 .. Name_Len));
13164 Write_Str (" is not supported in this configuration");
13165 Write_Eol;
13166 raise Unrecoverable_Error;
13167 end if;
13168 end Unimplemented_Unit;
13169
13170 ------------------------
13171 -- Universal_Aliasing --
13172 ------------------------
13173
13174 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13175
13176 when Pragma_Universal_Aliasing => Universal_Alias : declare
13177 E_Id : Entity_Id;
13178
13179 begin
13180 GNAT_Pragma;
13181 Check_Arg_Count (1);
13182 Check_Optional_Identifier (Arg2, Name_Entity);
13183 Check_Arg_Is_Local_Name (Arg1);
13184 E_Id := Entity (Get_Pragma_Arg (Arg1));
13185
13186 if E_Id = Any_Type then
13187 return;
13188 elsif No (E_Id) or else not Is_Type (E_Id) then
13189 Error_Pragma_Arg ("pragma% requires type", Arg1);
13190 end if;
13191
13192 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13193 end Universal_Alias;
13194
13195 --------------------
13196 -- Universal_Data --
13197 --------------------
13198
13199 -- pragma Universal_Data [(library_unit_NAME)];
13200
13201 when Pragma_Universal_Data =>
13202 GNAT_Pragma;
13203
13204 -- If this is a configuration pragma, then set the universal
13205 -- addressing option, otherwise confirm that the pragma satisfies
13206 -- the requirements of library unit pragma placement and leave it
13207 -- to the GNAAMP back end to detect the pragma (avoids transitive
13208 -- setting of the option due to withed units).
13209
13210 if Is_Configuration_Pragma then
13211 Universal_Addressing_On_AAMP := True;
13212 else
13213 Check_Valid_Library_Unit_Pragma;
13214 end if;
13215
13216 if not AAMP_On_Target then
13217 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13218 end if;
13219
13220 ----------------
13221 -- Unmodified --
13222 ----------------
13223
13224 -- pragma Unmodified (local_Name {, local_Name});
13225
13226 when Pragma_Unmodified => Unmodified : declare
13227 Arg_Node : Node_Id;
13228 Arg_Expr : Node_Id;
13229 Arg_Ent : Entity_Id;
13230
13231 begin
13232 GNAT_Pragma;
13233 Check_At_Least_N_Arguments (1);
13234
13235 -- Loop through arguments
13236
13237 Arg_Node := Arg1;
13238 while Present (Arg_Node) loop
13239 Check_No_Identifier (Arg_Node);
13240
13241 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13242 -- in fact generate reference, so that the entity will have a
13243 -- reference, which will inhibit any warnings about it not
13244 -- being referenced, and also properly show up in the ali file
13245 -- as a reference. But this reference is recorded before the
13246 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13247 -- generated for this reference.
13248
13249 Check_Arg_Is_Local_Name (Arg_Node);
13250 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13251
13252 if Is_Entity_Name (Arg_Expr) then
13253 Arg_Ent := Entity (Arg_Expr);
13254
13255 if not Is_Assignable (Arg_Ent) then
13256 Error_Pragma_Arg
13257 ("pragma% can only be applied to a variable",
13258 Arg_Expr);
13259 else
13260 Set_Has_Pragma_Unmodified (Arg_Ent);
13261 end if;
13262 end if;
13263
13264 Next (Arg_Node);
13265 end loop;
13266 end Unmodified;
13267
13268 ------------------
13269 -- Unreferenced --
13270 ------------------
13271
13272 -- pragma Unreferenced (local_Name {, local_Name});
13273
13274 -- or when used in a context clause:
13275
13276 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13277
13278 when Pragma_Unreferenced => Unreferenced : declare
13279 Arg_Node : Node_Id;
13280 Arg_Expr : Node_Id;
13281 Arg_Ent : Entity_Id;
13282 Citem : Node_Id;
13283
13284 begin
13285 GNAT_Pragma;
13286 Check_At_Least_N_Arguments (1);
13287
13288 -- Check case of appearing within context clause
13289
13290 if Is_In_Context_Clause then
13291
13292 -- The arguments must all be units mentioned in a with clause
13293 -- in the same context clause. Note we already checked (in
13294 -- Par.Prag) that the arguments are either identifiers or
13295 -- selected components.
13296
13297 Arg_Node := Arg1;
13298 while Present (Arg_Node) loop
13299 Citem := First (List_Containing (N));
13300 while Citem /= N loop
13301 if Nkind (Citem) = N_With_Clause
13302 and then
13303 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13304 then
13305 Set_Has_Pragma_Unreferenced
13306 (Cunit_Entity
13307 (Get_Source_Unit
13308 (Library_Unit (Citem))));
13309 Set_Unit_Name
13310 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13311 exit;
13312 end if;
13313
13314 Next (Citem);
13315 end loop;
13316
13317 if Citem = N then
13318 Error_Pragma_Arg
13319 ("argument of pragma% is not with'ed unit", Arg_Node);
13320 end if;
13321
13322 Next (Arg_Node);
13323 end loop;
13324
13325 -- Case of not in list of context items
13326
13327 else
13328 Arg_Node := Arg1;
13329 while Present (Arg_Node) loop
13330 Check_No_Identifier (Arg_Node);
13331
13332 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13333 -- will in fact generate reference, so that the entity will
13334 -- have a reference, which will inhibit any warnings about
13335 -- it not being referenced, and also properly show up in the
13336 -- ali file as a reference. But this reference is recorded
13337 -- before the Has_Pragma_Unreferenced flag is set, so that
13338 -- no warning is generated for this reference.
13339
13340 Check_Arg_Is_Local_Name (Arg_Node);
13341 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13342
13343 if Is_Entity_Name (Arg_Expr) then
13344 Arg_Ent := Entity (Arg_Expr);
13345
13346 -- If the entity is overloaded, the pragma applies to the
13347 -- most recent overloading, as documented. In this case,
13348 -- name resolution does not generate a reference, so it
13349 -- must be done here explicitly.
13350
13351 if Is_Overloaded (Arg_Expr) then
13352 Generate_Reference (Arg_Ent, N);
13353 end if;
13354
13355 Set_Has_Pragma_Unreferenced (Arg_Ent);
13356 end if;
13357
13358 Next (Arg_Node);
13359 end loop;
13360 end if;
13361 end Unreferenced;
13362
13363 --------------------------
13364 -- Unreferenced_Objects --
13365 --------------------------
13366
13367 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13368
13369 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13370 Arg_Node : Node_Id;
13371 Arg_Expr : Node_Id;
13372
13373 begin
13374 GNAT_Pragma;
13375 Check_At_Least_N_Arguments (1);
13376
13377 Arg_Node := Arg1;
13378 while Present (Arg_Node) loop
13379 Check_No_Identifier (Arg_Node);
13380 Check_Arg_Is_Local_Name (Arg_Node);
13381 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13382
13383 if not Is_Entity_Name (Arg_Expr)
13384 or else not Is_Type (Entity (Arg_Expr))
13385 then
13386 Error_Pragma_Arg
13387 ("argument for pragma% must be type or subtype", Arg_Node);
13388 end if;
13389
13390 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13391 Next (Arg_Node);
13392 end loop;
13393 end Unreferenced_Objects;
13394
13395 ------------------------------
13396 -- Unreserve_All_Interrupts --
13397 ------------------------------
13398
13399 -- pragma Unreserve_All_Interrupts;
13400
13401 when Pragma_Unreserve_All_Interrupts =>
13402 GNAT_Pragma;
13403 Check_Arg_Count (0);
13404
13405 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13406 Unreserve_All_Interrupts := True;
13407 end if;
13408
13409 ----------------
13410 -- Unsuppress --
13411 ----------------
13412
13413 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13414
13415 when Pragma_Unsuppress =>
13416 Ada_2005_Pragma;
13417 Process_Suppress_Unsuppress (False);
13418
13419 -------------------
13420 -- Use_VADS_Size --
13421 -------------------
13422
13423 -- pragma Use_VADS_Size;
13424
13425 when Pragma_Use_VADS_Size =>
13426 GNAT_Pragma;
13427 Check_Arg_Count (0);
13428 Check_Valid_Configuration_Pragma;
13429 Use_VADS_Size := True;
13430
13431 ---------------------
13432 -- Validity_Checks --
13433 ---------------------
13434
13435 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13436
13437 when Pragma_Validity_Checks => Validity_Checks : declare
13438 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13439 S : String_Id;
13440 C : Char_Code;
13441
13442 begin
13443 GNAT_Pragma;
13444 Check_Arg_Count (1);
13445 Check_No_Identifiers;
13446
13447 if Nkind (A) = N_String_Literal then
13448 S := Strval (A);
13449
13450 declare
13451 Slen : constant Natural := Natural (String_Length (S));
13452 Options : String (1 .. Slen);
13453 J : Natural;
13454
13455 begin
13456 J := 1;
13457 loop
13458 C := Get_String_Char (S, Int (J));
13459 exit when not In_Character_Range (C);
13460 Options (J) := Get_Character (C);
13461
13462 if J = Slen then
13463 Set_Validity_Check_Options (Options);
13464 exit;
13465 else
13466 J := J + 1;
13467 end if;
13468 end loop;
13469 end;
13470
13471 elsif Nkind (A) = N_Identifier then
13472
13473 if Chars (A) = Name_All_Checks then
13474 Set_Validity_Check_Options ("a");
13475
13476 elsif Chars (A) = Name_On then
13477 Validity_Checks_On := True;
13478
13479 elsif Chars (A) = Name_Off then
13480 Validity_Checks_On := False;
13481
13482 end if;
13483 end if;
13484 end Validity_Checks;
13485
13486 --------------
13487 -- Volatile --
13488 --------------
13489
13490 -- pragma Volatile (LOCAL_NAME);
13491
13492 when Pragma_Volatile =>
13493 Process_Atomic_Shared_Volatile;
13494
13495 -------------------------
13496 -- Volatile_Components --
13497 -------------------------
13498
13499 -- pragma Volatile_Components (array_LOCAL_NAME);
13500
13501 -- Volatile is handled by the same circuit as Atomic_Components
13502
13503 --------------
13504 -- Warnings --
13505 --------------
13506
13507 -- pragma Warnings (On | Off);
13508 -- pragma Warnings (On | Off, LOCAL_NAME);
13509 -- pragma Warnings (static_string_EXPRESSION);
13510 -- pragma Warnings (On | Off, STRING_LITERAL);
13511
13512 when Pragma_Warnings => Warnings : begin
13513 GNAT_Pragma;
13514 Check_At_Least_N_Arguments (1);
13515 Check_No_Identifiers;
13516
13517 -- If debug flag -gnatd.i is set, pragma is ignored
13518
13519 if Debug_Flag_Dot_I then
13520 return;
13521 end if;
13522
13523 -- Process various forms of the pragma
13524
13525 declare
13526 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13527
13528 begin
13529 -- One argument case
13530
13531 if Arg_Count = 1 then
13532
13533 -- On/Off one argument case was processed by parser
13534
13535 if Nkind (Argx) = N_Identifier
13536 and then
13537 (Chars (Argx) = Name_On
13538 or else
13539 Chars (Argx) = Name_Off)
13540 then
13541 null;
13542
13543 -- One argument case must be ON/OFF or static string expr
13544
13545 elsif not Is_Static_String_Expression (Arg1) then
13546 Error_Pragma_Arg
13547 ("argument of pragma% must be On/Off or " &
13548 "static string expression", Arg1);
13549
13550 -- One argument string expression case
13551
13552 else
13553 declare
13554 Lit : constant Node_Id := Expr_Value_S (Argx);
13555 Str : constant String_Id := Strval (Lit);
13556 Len : constant Nat := String_Length (Str);
13557 C : Char_Code;
13558 J : Nat;
13559 OK : Boolean;
13560 Chr : Character;
13561
13562 begin
13563 J := 1;
13564 while J <= Len loop
13565 C := Get_String_Char (Str, J);
13566 OK := In_Character_Range (C);
13567
13568 if OK then
13569 Chr := Get_Character (C);
13570
13571 -- Dot case
13572
13573 if J < Len and then Chr = '.' then
13574 J := J + 1;
13575 C := Get_String_Char (Str, J);
13576 Chr := Get_Character (C);
13577
13578 if not Set_Dot_Warning_Switch (Chr) then
13579 Error_Pragma_Arg
13580 ("invalid warning switch character " &
13581 '.' & Chr, Arg1);
13582 end if;
13583
13584 -- Non-Dot case
13585
13586 else
13587 OK := Set_Warning_Switch (Chr);
13588 end if;
13589 end if;
13590
13591 if not OK then
13592 Error_Pragma_Arg
13593 ("invalid warning switch character " & Chr,
13594 Arg1);
13595 end if;
13596
13597 J := J + 1;
13598 end loop;
13599 end;
13600 end if;
13601
13602 -- Two or more arguments (must be two)
13603
13604 else
13605 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13606 Check_At_Most_N_Arguments (2);
13607
13608 declare
13609 E_Id : Node_Id;
13610 E : Entity_Id;
13611 Err : Boolean;
13612
13613 begin
13614 E_Id := Get_Pragma_Arg (Arg2);
13615 Analyze (E_Id);
13616
13617 -- In the expansion of an inlined body, a reference to
13618 -- the formal may be wrapped in a conversion if the
13619 -- actual is a conversion. Retrieve the real entity name.
13620
13621 if (In_Instance_Body
13622 or else In_Inlined_Body)
13623 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13624 then
13625 E_Id := Expression (E_Id);
13626 end if;
13627
13628 -- Entity name case
13629
13630 if Is_Entity_Name (E_Id) then
13631 E := Entity (E_Id);
13632
13633 if E = Any_Id then
13634 return;
13635 else
13636 loop
13637 Set_Warnings_Off
13638 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13639 Name_Off));
13640
13641 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13642 and then Warn_On_Warnings_Off
13643 then
13644 Warnings_Off_Pragmas.Append ((N, E));
13645 end if;
13646
13647 if Is_Enumeration_Type (E) then
13648 declare
13649 Lit : Entity_Id;
13650 begin
13651 Lit := First_Literal (E);
13652 while Present (Lit) loop
13653 Set_Warnings_Off (Lit);
13654 Next_Literal (Lit);
13655 end loop;
13656 end;
13657 end if;
13658
13659 exit when No (Homonym (E));
13660 E := Homonym (E);
13661 end loop;
13662 end if;
13663
13664 -- Error if not entity or static string literal case
13665
13666 elsif not Is_Static_String_Expression (Arg2) then
13667 Error_Pragma_Arg
13668 ("second argument of pragma% must be entity " &
13669 "name or static string expression", Arg2);
13670
13671 -- String literal case
13672
13673 else
13674 String_To_Name_Buffer
13675 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13676
13677 -- Note on configuration pragma case: If this is a
13678 -- configuration pragma, then for an OFF pragma, we
13679 -- just set Config True in the call, which is all
13680 -- that needs to be done. For the case of ON, this
13681 -- is normally an error, unless it is canceling the
13682 -- effect of a previous OFF pragma in the same file.
13683 -- In any other case, an error will be signalled (ON
13684 -- with no matching OFF).
13685
13686 if Chars (Argx) = Name_Off then
13687 Set_Specific_Warning_Off
13688 (Loc, Name_Buffer (1 .. Name_Len),
13689 Config => Is_Configuration_Pragma);
13690
13691 elsif Chars (Argx) = Name_On then
13692 Set_Specific_Warning_On
13693 (Loc, Name_Buffer (1 .. Name_Len), Err);
13694
13695 if Err then
13696 Error_Msg
13697 ("?pragma Warnings On with no " &
13698 "matching Warnings Off",
13699 Loc);
13700 end if;
13701 end if;
13702 end if;
13703 end;
13704 end if;
13705 end;
13706 end Warnings;
13707
13708 -------------------
13709 -- Weak_External --
13710 -------------------
13711
13712 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13713
13714 when Pragma_Weak_External => Weak_External : declare
13715 Ent : Entity_Id;
13716
13717 begin
13718 GNAT_Pragma;
13719 Check_Arg_Count (1);
13720 Check_Optional_Identifier (Arg1, Name_Entity);
13721 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13722 Ent := Entity (Get_Pragma_Arg (Arg1));
13723
13724 if Rep_Item_Too_Early (Ent, N) then
13725 return;
13726 else
13727 Ent := Underlying_Type (Ent);
13728 end if;
13729
13730 -- The only processing required is to link this item on to the
13731 -- list of rep items for the given entity. This is accomplished
13732 -- by the call to Rep_Item_Too_Late (when no error is detected
13733 -- and False is returned).
13734
13735 if Rep_Item_Too_Late (Ent, N) then
13736 return;
13737 else
13738 Set_Has_Gigi_Rep_Item (Ent);
13739 end if;
13740 end Weak_External;
13741
13742 -----------------------------
13743 -- Wide_Character_Encoding --
13744 -----------------------------
13745
13746 -- pragma Wide_Character_Encoding (IDENTIFIER);
13747
13748 when Pragma_Wide_Character_Encoding =>
13749 GNAT_Pragma;
13750
13751 -- Nothing to do, handled in parser. Note that we do not enforce
13752 -- configuration pragma placement, this pragma can appear at any
13753 -- place in the source, allowing mixed encodings within a single
13754 -- source program.
13755
13756 null;
13757
13758 --------------------
13759 -- Unknown_Pragma --
13760 --------------------
13761
13762 -- Should be impossible, since the case of an unknown pragma is
13763 -- separately processed before the case statement is entered.
13764
13765 when Unknown_Pragma =>
13766 raise Program_Error;
13767 end case;
13768
13769 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13770 -- until AI is formally approved.
13771
13772 -- Check_Order_Dependence;
13773
13774 exception
13775 when Pragma_Exit => null;
13776 end Analyze_Pragma;
13777
13778 -------------------
13779 -- Check_Enabled --
13780 -------------------
13781
13782 function Check_Enabled (Nam : Name_Id) return Boolean is
13783 PP : Node_Id;
13784
13785 begin
13786 -- Loop through entries in check policy list
13787
13788 PP := Opt.Check_Policy_List;
13789 loop
13790 -- If there are no specific entries that matched, then we let the
13791 -- setting of assertions govern. Note that this provides the needed
13792 -- compatibility with the RM for the cases of assertion, invariant,
13793 -- precondition, predicate, and postcondition.
13794
13795 if No (PP) then
13796 return Assertions_Enabled;
13797
13798 -- Here we have an entry see if it matches
13799
13800 else
13801 declare
13802 PPA : constant List_Id := Pragma_Argument_Associations (PP);
13803
13804 begin
13805 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13806 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13807 when Name_On | Name_Check =>
13808 return True;
13809 when Name_Off | Name_Ignore =>
13810 return False;
13811 when others =>
13812 raise Program_Error;
13813 end case;
13814
13815 else
13816 PP := Next_Pragma (PP);
13817 end if;
13818 end;
13819 end if;
13820 end loop;
13821 end Check_Enabled;
13822
13823 ---------------------------------
13824 -- Delay_Config_Pragma_Analyze --
13825 ---------------------------------
13826
13827 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13828 begin
13829 return Pragma_Name (N) = Name_Interrupt_State
13830 or else
13831 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13832 end Delay_Config_Pragma_Analyze;
13833
13834 -------------------------
13835 -- Get_Base_Subprogram --
13836 -------------------------
13837
13838 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13839 Result : Entity_Id;
13840
13841 begin
13842 -- Follow subprogram renaming chain
13843
13844 Result := Def_Id;
13845 while Is_Subprogram (Result)
13846 and then
13847 (Is_Generic_Instance (Result)
13848 or else Nkind (Parent (Declaration_Node (Result))) =
13849 N_Subprogram_Renaming_Declaration)
13850 and then Present (Alias (Result))
13851 loop
13852 Result := Alias (Result);
13853 end loop;
13854
13855 return Result;
13856 end Get_Base_Subprogram;
13857
13858 ----------------
13859 -- Initialize --
13860 ----------------
13861
13862 procedure Initialize is
13863 begin
13864 Externals.Init;
13865 end Initialize;
13866
13867 -----------------------------
13868 -- Is_Config_Static_String --
13869 -----------------------------
13870
13871 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13872
13873 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
13874 -- This is an internal recursive function that is just like the outer
13875 -- function except that it adds the string to the name buffer rather
13876 -- than placing the string in the name buffer.
13877
13878 ------------------------------
13879 -- Add_Config_Static_String --
13880 ------------------------------
13881
13882 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
13883 N : Node_Id;
13884 C : Char_Code;
13885
13886 begin
13887 N := Arg;
13888
13889 if Nkind (N) = N_Op_Concat then
13890 if Add_Config_Static_String (Left_Opnd (N)) then
13891 N := Right_Opnd (N);
13892 else
13893 return False;
13894 end if;
13895 end if;
13896
13897 if Nkind (N) /= N_String_Literal then
13898 Error_Msg_N ("string literal expected for pragma argument", N);
13899 return False;
13900
13901 else
13902 for J in 1 .. String_Length (Strval (N)) loop
13903 C := Get_String_Char (Strval (N), J);
13904
13905 if not In_Character_Range (C) then
13906 Error_Msg
13907 ("string literal contains invalid wide character",
13908 Sloc (N) + 1 + Source_Ptr (J));
13909 return False;
13910 end if;
13911
13912 Add_Char_To_Name_Buffer (Get_Character (C));
13913 end loop;
13914 end if;
13915
13916 return True;
13917 end Add_Config_Static_String;
13918
13919 -- Start of processing for Is_Config_Static_String
13920
13921 begin
13922
13923 Name_Len := 0;
13924 return Add_Config_Static_String (Arg);
13925 end Is_Config_Static_String;
13926
13927 -----------------------------------------
13928 -- Is_Non_Significant_Pragma_Reference --
13929 -----------------------------------------
13930
13931 -- This function makes use of the following static table which indicates
13932 -- whether a given pragma is significant.
13933
13934 -- -1 indicates that references in any argument position are significant
13935 -- 0 indicates that appearance in any argument is not significant
13936 -- +n indicates that appearance as argument n is significant, but all
13937 -- other arguments are not significant
13938 -- 99 special processing required (e.g. for pragma Check)
13939
13940 Sig_Flags : constant array (Pragma_Id) of Int :=
13941 (Pragma_AST_Entry => -1,
13942 Pragma_Abort_Defer => -1,
13943 Pragma_Ada_83 => -1,
13944 Pragma_Ada_95 => -1,
13945 Pragma_Ada_05 => -1,
13946 Pragma_Ada_2005 => -1,
13947 Pragma_Ada_12 => -1,
13948 Pragma_Ada_2012 => -1,
13949 Pragma_All_Calls_Remote => -1,
13950 Pragma_Annotate => -1,
13951 Pragma_Assert => -1,
13952 Pragma_Assertion_Policy => 0,
13953 Pragma_Assume_No_Invalid_Values => 0,
13954 Pragma_Asynchronous => -1,
13955 Pragma_Atomic => 0,
13956 Pragma_Atomic_Components => 0,
13957 Pragma_Attach_Handler => -1,
13958 Pragma_Check => 99,
13959 Pragma_Check_Name => 0,
13960 Pragma_Check_Policy => 0,
13961 Pragma_CIL_Constructor => -1,
13962 Pragma_CPP_Class => 0,
13963 Pragma_CPP_Constructor => 0,
13964 Pragma_CPP_Virtual => 0,
13965 Pragma_CPP_Vtable => 0,
13966 Pragma_CPU => -1,
13967 Pragma_C_Pass_By_Copy => 0,
13968 Pragma_Comment => 0,
13969 Pragma_Common_Object => -1,
13970 Pragma_Compile_Time_Error => -1,
13971 Pragma_Compile_Time_Warning => -1,
13972 Pragma_Compiler_Unit => 0,
13973 Pragma_Complete_Representation => 0,
13974 Pragma_Complex_Representation => 0,
13975 Pragma_Component_Alignment => -1,
13976 Pragma_Controlled => 0,
13977 Pragma_Convention => 0,
13978 Pragma_Convention_Identifier => 0,
13979 Pragma_Debug => -1,
13980 Pragma_Debug_Policy => 0,
13981 Pragma_Detect_Blocking => -1,
13982 Pragma_Default_Storage_Pool => -1,
13983 Pragma_Dimension => -1,
13984 Pragma_Discard_Names => 0,
13985 Pragma_Elaborate => -1,
13986 Pragma_Elaborate_All => -1,
13987 Pragma_Elaborate_Body => -1,
13988 Pragma_Elaboration_Checks => -1,
13989 Pragma_Eliminate => -1,
13990 Pragma_Export => -1,
13991 Pragma_Export_Exception => -1,
13992 Pragma_Export_Function => -1,
13993 Pragma_Export_Object => -1,
13994 Pragma_Export_Procedure => -1,
13995 Pragma_Export_Value => -1,
13996 Pragma_Export_Valued_Procedure => -1,
13997 Pragma_Extend_System => -1,
13998 Pragma_Extensions_Allowed => -1,
13999 Pragma_External => -1,
14000 Pragma_Favor_Top_Level => -1,
14001 Pragma_External_Name_Casing => -1,
14002 Pragma_Fast_Math => -1,
14003 Pragma_Finalize_Storage_Only => 0,
14004 Pragma_Float_Representation => 0,
14005 Pragma_Ident => -1,
14006 Pragma_Implemented => -1,
14007 Pragma_Implicit_Packing => 0,
14008 Pragma_Import => +2,
14009 Pragma_Import_Exception => 0,
14010 Pragma_Import_Function => 0,
14011 Pragma_Import_Object => 0,
14012 Pragma_Import_Procedure => 0,
14013 Pragma_Import_Valued_Procedure => 0,
14014 Pragma_Independent => 0,
14015 Pragma_Independent_Components => 0,
14016 Pragma_Initialize_Scalars => -1,
14017 Pragma_Inline => 0,
14018 Pragma_Inline_Always => 0,
14019 Pragma_Inline_Generic => 0,
14020 Pragma_Inspection_Point => -1,
14021 Pragma_Interface => +2,
14022 Pragma_Interface_Name => +2,
14023 Pragma_Interrupt_Handler => -1,
14024 Pragma_Interrupt_Priority => -1,
14025 Pragma_Interrupt_State => -1,
14026 Pragma_Invariant => -1,
14027 Pragma_Java_Constructor => -1,
14028 Pragma_Java_Interface => -1,
14029 Pragma_Keep_Names => 0,
14030 Pragma_License => -1,
14031 Pragma_Link_With => -1,
14032 Pragma_Linker_Alias => -1,
14033 Pragma_Linker_Constructor => -1,
14034 Pragma_Linker_Destructor => -1,
14035 Pragma_Linker_Options => -1,
14036 Pragma_Linker_Section => -1,
14037 Pragma_List => -1,
14038 Pragma_Locking_Policy => -1,
14039 Pragma_Long_Float => -1,
14040 Pragma_Machine_Attribute => -1,
14041 Pragma_Main => -1,
14042 Pragma_Main_Storage => -1,
14043 Pragma_Memory_Size => -1,
14044 Pragma_No_Return => 0,
14045 Pragma_No_Body => 0,
14046 Pragma_No_Run_Time => -1,
14047 Pragma_No_Strict_Aliasing => -1,
14048 Pragma_Normalize_Scalars => -1,
14049 Pragma_Obsolescent => 0,
14050 Pragma_Optimize => -1,
14051 Pragma_Optimize_Alignment => -1,
14052 Pragma_Ordered => 0,
14053 Pragma_Pack => 0,
14054 Pragma_Page => -1,
14055 Pragma_Passive => -1,
14056 Pragma_Preelaborable_Initialization => -1,
14057 Pragma_Polling => -1,
14058 Pragma_Persistent_BSS => 0,
14059 Pragma_Postcondition => -1,
14060 Pragma_Precondition => -1,
14061 Pragma_Predicate => -1,
14062 Pragma_Preelaborate => -1,
14063 Pragma_Preelaborate_05 => -1,
14064 Pragma_Priority => -1,
14065 Pragma_Priority_Specific_Dispatching => -1,
14066 Pragma_Profile => 0,
14067 Pragma_Profile_Warnings => 0,
14068 Pragma_Propagate_Exceptions => -1,
14069 Pragma_Psect_Object => -1,
14070 Pragma_Pure => -1,
14071 Pragma_Pure_05 => -1,
14072 Pragma_Pure_Function => -1,
14073 Pragma_Queuing_Policy => -1,
14074 Pragma_Ravenscar => -1,
14075 Pragma_Relative_Deadline => -1,
14076 Pragma_Remote_Call_Interface => -1,
14077 Pragma_Remote_Types => -1,
14078 Pragma_Restricted_Run_Time => -1,
14079 Pragma_Restriction_Warnings => -1,
14080 Pragma_Restrictions => -1,
14081 Pragma_Reviewable => -1,
14082 Pragma_Short_Circuit_And_Or => -1,
14083 Pragma_Share_Generic => -1,
14084 Pragma_Shared => -1,
14085 Pragma_Shared_Passive => -1,
14086 Pragma_Short_Descriptors => 0,
14087 Pragma_Source_File_Name => -1,
14088 Pragma_Source_File_Name_Project => -1,
14089 Pragma_Source_Reference => -1,
14090 Pragma_Storage_Size => -1,
14091 Pragma_Storage_Unit => -1,
14092 Pragma_Static_Elaboration_Desired => -1,
14093 Pragma_Stream_Convert => -1,
14094 Pragma_Style_Checks => -1,
14095 Pragma_Subtitle => -1,
14096 Pragma_Suppress => 0,
14097 Pragma_Suppress_Exception_Locations => 0,
14098 Pragma_Suppress_All => -1,
14099 Pragma_Suppress_Debug_Info => 0,
14100 Pragma_Suppress_Initialization => 0,
14101 Pragma_System_Name => -1,
14102 Pragma_Task_Dispatching_Policy => -1,
14103 Pragma_Task_Info => -1,
14104 Pragma_Task_Name => -1,
14105 Pragma_Task_Storage => 0,
14106 Pragma_Thread_Local_Storage => 0,
14107 Pragma_Time_Slice => -1,
14108 Pragma_Title => -1,
14109 Pragma_Unchecked_Union => 0,
14110 Pragma_Unimplemented_Unit => -1,
14111 Pragma_Universal_Aliasing => -1,
14112 Pragma_Universal_Data => -1,
14113 Pragma_Unmodified => -1,
14114 Pragma_Unreferenced => -1,
14115 Pragma_Unreferenced_Objects => -1,
14116 Pragma_Unreserve_All_Interrupts => -1,
14117 Pragma_Unsuppress => 0,
14118 Pragma_Use_VADS_Size => -1,
14119 Pragma_Validity_Checks => -1,
14120 Pragma_Volatile => 0,
14121 Pragma_Volatile_Components => 0,
14122 Pragma_Warnings => -1,
14123 Pragma_Weak_External => -1,
14124 Pragma_Wide_Character_Encoding => 0,
14125 Unknown_Pragma => 0);
14126
14127 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14128 Id : Pragma_Id;
14129 P : Node_Id;
14130 C : Int;
14131 A : Node_Id;
14132
14133 begin
14134 P := Parent (N);
14135
14136 if Nkind (P) /= N_Pragma_Argument_Association then
14137 return False;
14138
14139 else
14140 Id := Get_Pragma_Id (Parent (P));
14141 C := Sig_Flags (Id);
14142
14143 case C is
14144 when -1 =>
14145 return False;
14146
14147 when 0 =>
14148 return True;
14149
14150 when 99 =>
14151 case Id is
14152
14153 -- For pragma Check, the first argument is not significant,
14154 -- the second and the third (if present) arguments are
14155 -- significant.
14156
14157 when Pragma_Check =>
14158 return
14159 P = First (Pragma_Argument_Associations (Parent (P)));
14160
14161 when others =>
14162 raise Program_Error;
14163 end case;
14164
14165 when others =>
14166 A := First (Pragma_Argument_Associations (Parent (P)));
14167 for J in 1 .. C - 1 loop
14168 if No (A) then
14169 return False;
14170 end if;
14171
14172 Next (A);
14173 end loop;
14174
14175 return A = P; -- is this wrong way round ???
14176 end case;
14177 end if;
14178 end Is_Non_Significant_Pragma_Reference;
14179
14180 ------------------------------
14181 -- Is_Pragma_String_Literal --
14182 ------------------------------
14183
14184 -- This function returns true if the corresponding pragma argument is a
14185 -- static string expression. These are the only cases in which string
14186 -- literals can appear as pragma arguments. We also allow a string literal
14187 -- as the first argument to pragma Assert (although it will of course
14188 -- always generate a type error).
14189
14190 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14191 Pragn : constant Node_Id := Parent (Par);
14192 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14193 Pname : constant Name_Id := Pragma_Name (Pragn);
14194 Argn : Natural;
14195 N : Node_Id;
14196
14197 begin
14198 Argn := 1;
14199 N := First (Assoc);
14200 loop
14201 exit when N = Par;
14202 Argn := Argn + 1;
14203 Next (N);
14204 end loop;
14205
14206 if Pname = Name_Assert then
14207 return True;
14208
14209 elsif Pname = Name_Export then
14210 return Argn > 2;
14211
14212 elsif Pname = Name_Ident then
14213 return Argn = 1;
14214
14215 elsif Pname = Name_Import then
14216 return Argn > 2;
14217
14218 elsif Pname = Name_Interface_Name then
14219 return Argn > 1;
14220
14221 elsif Pname = Name_Linker_Alias then
14222 return Argn = 2;
14223
14224 elsif Pname = Name_Linker_Section then
14225 return Argn = 2;
14226
14227 elsif Pname = Name_Machine_Attribute then
14228 return Argn = 2;
14229
14230 elsif Pname = Name_Source_File_Name then
14231 return True;
14232
14233 elsif Pname = Name_Source_Reference then
14234 return Argn = 2;
14235
14236 elsif Pname = Name_Title then
14237 return True;
14238
14239 elsif Pname = Name_Subtitle then
14240 return True;
14241
14242 else
14243 return False;
14244 end if;
14245 end Is_Pragma_String_Literal;
14246
14247 --------------------------------------
14248 -- Process_Compilation_Unit_Pragmas --
14249 --------------------------------------
14250
14251 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14252 begin
14253 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14254 -- strange because it comes at the end of the unit. Rational has the
14255 -- same name for a pragma, but treats it as a program unit pragma, In
14256 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14257 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14258 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14259 -- the context clause to ensure the correct processing.
14260
14261 if Has_Pragma_Suppress_All (N) then
14262 Prepend_To (Context_Items (N),
14263 Make_Pragma (Sloc (N),
14264 Chars => Name_Suppress,
14265 Pragma_Argument_Associations => New_List (
14266 Make_Pragma_Argument_Association (Sloc (N),
14267 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14268 end if;
14269
14270 -- Nothing else to do at the current time!
14271
14272 end Process_Compilation_Unit_Pragmas;
14273
14274 --------
14275 -- rv --
14276 --------
14277
14278 procedure rv is
14279 begin
14280 null;
14281 end rv;
14282
14283 --------------------------------
14284 -- Set_Encoded_Interface_Name --
14285 --------------------------------
14286
14287 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14288 Str : constant String_Id := Strval (S);
14289 Len : constant Int := String_Length (Str);
14290 CC : Char_Code;
14291 C : Character;
14292 J : Int;
14293
14294 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14295
14296 procedure Encode;
14297 -- Stores encoded value of character code CC. The encoding we use an
14298 -- underscore followed by four lower case hex digits.
14299
14300 ------------
14301 -- Encode --
14302 ------------
14303
14304 procedure Encode is
14305 begin
14306 Store_String_Char (Get_Char_Code ('_'));
14307 Store_String_Char
14308 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14309 Store_String_Char
14310 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14311 Store_String_Char
14312 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14313 Store_String_Char
14314 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14315 end Encode;
14316
14317 -- Start of processing for Set_Encoded_Interface_Name
14318
14319 begin
14320 -- If first character is asterisk, this is a link name, and we leave it
14321 -- completely unmodified. We also ignore null strings (the latter case
14322 -- happens only in error cases) and no encoding should occur for Java or
14323 -- AAMP interface names.
14324
14325 if Len = 0
14326 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14327 or else VM_Target /= No_VM
14328 or else AAMP_On_Target
14329 then
14330 Set_Interface_Name (E, S);
14331
14332 else
14333 J := 1;
14334 loop
14335 CC := Get_String_Char (Str, J);
14336
14337 exit when not In_Character_Range (CC);
14338
14339 C := Get_Character (CC);
14340
14341 exit when C /= '_' and then C /= '$'
14342 and then C not in '0' .. '9'
14343 and then C not in 'a' .. 'z'
14344 and then C not in 'A' .. 'Z';
14345
14346 if J = Len then
14347 Set_Interface_Name (E, S);
14348 return;
14349
14350 else
14351 J := J + 1;
14352 end if;
14353 end loop;
14354
14355 -- Here we need to encode. The encoding we use as follows:
14356 -- three underscores + four hex digits (lower case)
14357
14358 Start_String;
14359
14360 for J in 1 .. String_Length (Str) loop
14361 CC := Get_String_Char (Str, J);
14362
14363 if not In_Character_Range (CC) then
14364 Encode;
14365 else
14366 C := Get_Character (CC);
14367
14368 if C = '_' or else C = '$'
14369 or else C in '0' .. '9'
14370 or else C in 'a' .. 'z'
14371 or else C in 'A' .. 'Z'
14372 then
14373 Store_String_Char (CC);
14374 else
14375 Encode;
14376 end if;
14377 end if;
14378 end loop;
14379
14380 Set_Interface_Name (E,
14381 Make_String_Literal (Sloc (S),
14382 Strval => End_String));
14383 end if;
14384 end Set_Encoded_Interface_Name;
14385
14386 -------------------
14387 -- Set_Unit_Name --
14388 -------------------
14389
14390 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14391 Pref : Node_Id;
14392 Scop : Entity_Id;
14393
14394 begin
14395 if Nkind (N) = N_Identifier
14396 and then Nkind (With_Item) = N_Identifier
14397 then
14398 Set_Entity (N, Entity (With_Item));
14399
14400 elsif Nkind (N) = N_Selected_Component then
14401 Change_Selected_Component_To_Expanded_Name (N);
14402 Set_Entity (N, Entity (With_Item));
14403 Set_Entity (Selector_Name (N), Entity (N));
14404
14405 Pref := Prefix (N);
14406 Scop := Scope (Entity (N));
14407 while Nkind (Pref) = N_Selected_Component loop
14408 Change_Selected_Component_To_Expanded_Name (Pref);
14409 Set_Entity (Selector_Name (Pref), Scop);
14410 Set_Entity (Pref, Scop);
14411 Pref := Prefix (Pref);
14412 Scop := Scope (Scop);
14413 end loop;
14414
14415 Set_Entity (Pref, Scop);
14416 end if;
14417 end Set_Unit_Name;
14418
14419 end Sem_Prag;