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