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