fixing pr42337
[official-gcc.git] / gcc / ada / sem_prag.adb
blobdaa08b4e95f487aa4247caf9e02c31bce8443373
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-2009, 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 ------------------------------------------------------------------------------
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).
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_Dist; use Exp_Dist;
41 with Lib; use Lib;
42 with Lib.Writ; use Lib.Writ;
43 with Lib.Xref; use Lib.Xref;
44 with Namet.Sp; use Namet.Sp;
45 with Nlists; use Nlists;
46 with Nmake; use Nmake;
47 with Opt; use Opt;
48 with Output; use Output;
49 with Restrict; use Restrict;
50 with Rident; use Rident;
51 with Rtsfind; use Rtsfind;
52 with Sem; use Sem;
53 with Sem_Aux; use Sem_Aux;
54 with Sem_Ch3; use Sem_Ch3;
55 with Sem_Ch6; use Sem_Ch6;
56 with Sem_Ch8; use Sem_Ch8;
57 with Sem_Ch12; use Sem_Ch12;
58 with Sem_Ch13; use Sem_Ch13;
59 with Sem_Dist; use Sem_Dist;
60 with Sem_Elim; use Sem_Elim;
61 with Sem_Eval; use Sem_Eval;
62 with Sem_Intr; use Sem_Intr;
63 with Sem_Mech; use Sem_Mech;
64 with Sem_Res; use Sem_Res;
65 with Sem_Type; use Sem_Type;
66 with Sem_Util; use Sem_Util;
67 with Sem_VFpt; use Sem_VFpt;
68 with Sem_Warn; use Sem_Warn;
69 with Stand; use Stand;
70 with Sinfo; use Sinfo;
71 with Sinfo.CN; use Sinfo.CN;
72 with Sinput; use Sinput;
73 with Snames; use Snames;
74 with Stringt; use Stringt;
75 with Stylesw; use Stylesw;
76 with Table;
77 with Targparm; use Targparm;
78 with Tbuild; use Tbuild;
79 with Ttypes;
80 with Uintp; use Uintp;
81 with Uname; use Uname;
82 with Urealp; use Urealp;
83 with Validsw; use Validsw;
85 package body Sem_Prag is
87 ----------------------------------------------
88 -- Common Handling of Import-Export Pragmas --
89 ----------------------------------------------
91 -- In the following section, a number of Import_xxx and Export_xxx
92 -- pragmas are defined by GNAT. These are compatible with the DEC
93 -- pragmas of the same name, and all have the following common
94 -- form and processing:
96 -- pragma Export_xxx
97 -- [Internal =>] LOCAL_NAME
98 -- [, [External =>] EXTERNAL_SYMBOL]
99 -- [, other optional parameters ]);
101 -- pragma Import_xxx
102 -- [Internal =>] LOCAL_NAME
103 -- [, [External =>] EXTERNAL_SYMBOL]
104 -- [, other optional parameters ]);
106 -- EXTERNAL_SYMBOL ::=
107 -- IDENTIFIER
108 -- | static_string_EXPRESSION
110 -- The internal LOCAL_NAME designates the entity that is imported or
111 -- exported, and must refer to an entity in the current declarative
112 -- part (as required by the rules for LOCAL_NAME).
114 -- The external linker name is designated by the External parameter if
115 -- given, or the Internal parameter if not (if there is no External
116 -- parameter, the External parameter is a copy of the Internal name).
118 -- If the External parameter is given as a string, then this string is
119 -- treated as an external name (exactly as though it had been given as an
120 -- External_Name parameter for a normal Import pragma).
122 -- If the External parameter is given as an identifier (or there is no
123 -- External parameter, so that the Internal identifier is used), then
124 -- the external name is the characters of the identifier, translated
125 -- to all upper case letters for OpenVMS versions of GNAT, and to all
126 -- lower case letters for all other versions
128 -- Note: the external name specified or implied by any of these special
129 -- Import_xxx or Export_xxx pragmas override an external or link name
130 -- specified in a previous Import or Export pragma.
132 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
133 -- named notation, following the standard rules for subprogram calls, i.e.
134 -- parameters can be given in any order if named notation is used, and
135 -- positional and named notation can be mixed, subject to the rule that all
136 -- positional parameters must appear first.
138 -- Note: All these pragmas are implemented exactly following the DEC design
139 -- and implementation and are intended to be fully compatible with the use
140 -- of these pragmas in the DEC Ada compiler.
142 --------------------------------------------
143 -- Checking for Duplicated External Names --
144 --------------------------------------------
146 -- It is suspicious if two separate Export pragmas use the same external
147 -- name. The following table is used to diagnose this situation so that
148 -- an appropriate warning can be issued.
150 -- The Node_Id stored is for the N_String_Literal node created to hold
151 -- the value of the external name. The Sloc of this node is used to
152 -- cross-reference the location of the duplication.
154 package Externals is new Table.Table (
155 Table_Component_Type => Node_Id,
156 Table_Index_Type => Int,
157 Table_Low_Bound => 0,
158 Table_Initial => 100,
159 Table_Increment => 100,
160 Table_Name => "Name_Externals");
162 -------------------------------------
163 -- Local Subprograms and Variables --
164 -------------------------------------
166 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
167 -- This routine is used for possible casing adjustment of an explicit
168 -- external name supplied as a string literal (the node N), according to
169 -- the casing requirement of Opt.External_Name_Casing. If this is set to
170 -- As_Is, then the string literal is returned unchanged, but if it is set
171 -- to Uppercase or Lowercase, then a new string literal with appropriate
172 -- casing is constructed.
174 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
175 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
176 -- original one, following the renaming chain) is returned. Otherwise the
177 -- entity is returned unchanged. Should be in Einfo???
179 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
180 -- All the routines that check pragma arguments take either a pragma
181 -- argument association (in which case the expression of the argument
182 -- association is checked), or the expression directly. The function
183 -- Get_Pragma_Arg is a utility used to deal with these two cases. If Arg
184 -- is a pragma argument association node, then its expression is returned,
185 -- otherwise Arg is returned unchanged.
187 procedure rv;
188 -- This is a dummy function called by the processing for pragma Reviewable.
189 -- It is there for assisting front end debugging. By placing a Reviewable
190 -- pragma in the source program, a breakpoint on rv catches this place in
191 -- the source, allowing convenient stepping to the point of interest.
193 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
194 -- Place semantic information on the argument of an Elaborate/Elaborate_All
195 -- pragma. Entity name for unit and its parents is taken from item in
196 -- previous with_clause that mentions the unit.
198 -------------------------------
199 -- Adjust_External_Name_Case --
200 -------------------------------
202 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
203 CC : Char_Code;
205 begin
206 -- Adjust case of literal if required
208 if Opt.External_Name_Exp_Casing = As_Is then
209 return N;
211 else
212 -- Copy existing string
214 Start_String;
216 -- Set proper casing
218 for J in 1 .. String_Length (Strval (N)) loop
219 CC := Get_String_Char (Strval (N), J);
221 if Opt.External_Name_Exp_Casing = Uppercase
222 and then CC >= Get_Char_Code ('a')
223 and then CC <= Get_Char_Code ('z')
224 then
225 Store_String_Char (CC - 32);
227 elsif Opt.External_Name_Exp_Casing = Lowercase
228 and then CC >= Get_Char_Code ('A')
229 and then CC <= Get_Char_Code ('Z')
230 then
231 Store_String_Char (CC + 32);
233 else
234 Store_String_Char (CC);
235 end if;
236 end loop;
238 return
239 Make_String_Literal (Sloc (N),
240 Strval => End_String);
241 end if;
242 end Adjust_External_Name_Case;
244 ------------------------------
245 -- Analyze_PPC_In_Decl_Part --
246 ------------------------------
248 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
249 Arg1 : constant Node_Id :=
250 First (Pragma_Argument_Associations (N));
251 Arg2 : constant Node_Id := Next (Arg1);
253 begin
254 -- Install formals and push subprogram spec onto scope stack so that we
255 -- can see the formals from the pragma.
257 Install_Formals (S);
258 Push_Scope (S);
260 -- Preanalyze the boolean expression, we treat this as a spec expression
261 -- (i.e. similar to a default expression).
263 Preanalyze_Spec_Expression
264 (Get_Pragma_Arg (Arg1), Standard_Boolean);
266 -- If there is a message argument, analyze it the same way
268 if Present (Arg2) then
269 Preanalyze_Spec_Expression
270 (Get_Pragma_Arg (Arg2), Standard_String);
271 end if;
273 -- Remove the subprogram from the scope stack now that the pre-analysis
274 -- of the precondition/postcondition is done.
276 End_Scope;
277 end Analyze_PPC_In_Decl_Part;
279 --------------------
280 -- Analyze_Pragma --
281 --------------------
283 procedure Analyze_Pragma (N : Node_Id) is
284 Loc : constant Source_Ptr := Sloc (N);
285 Pname : constant Name_Id := Pragma_Name (N);
286 Prag_Id : Pragma_Id;
288 Pragma_Exit : exception;
289 -- This exception is used to exit pragma processing completely. It is
290 -- used when an error is detected, and no further processing is
291 -- required. It is also used if an earlier error has left the tree in
292 -- a state where the pragma should not be processed.
294 Arg_Count : Nat;
295 -- Number of pragma argument associations
297 Arg1 : Node_Id;
298 Arg2 : Node_Id;
299 Arg3 : Node_Id;
300 Arg4 : Node_Id;
301 -- First four pragma arguments (pragma argument association nodes, or
302 -- Empty if the corresponding argument does not exist).
304 type Name_List is array (Natural range <>) of Name_Id;
305 type Args_List is array (Natural range <>) of Node_Id;
306 -- Types used for arguments to Check_Arg_Order and Gather_Associations
308 procedure Ada_2005_Pragma;
309 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
310 -- Ada 95 mode, these are implementation defined pragmas, so should be
311 -- caught by the No_Implementation_Pragmas restriction
313 procedure Check_Ada_83_Warning;
314 -- Issues a warning message for the current pragma if operating in Ada
315 -- 83 mode (used for language pragmas that are not a standard part of
316 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
317 -- of 95 pragma.
319 procedure Check_Arg_Count (Required : Nat);
320 -- Check argument count for pragma is equal to given parameter. If not,
321 -- then issue an error message and raise Pragma_Exit.
323 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
324 -- Arg which can either be a pragma argument association, in which case
325 -- the check is applied to the expression of the association or an
326 -- expression directly.
328 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
329 -- Check that an argument has the right form for an EXTERNAL_NAME
330 -- parameter of an extended import/export pragma. The rule is that the
331 -- name must be an identifier or string literal (in Ada 83 mode) or a
332 -- static string expression (in Ada 95 mode).
334 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
335 -- Check the specified argument Arg to make sure that it is an
336 -- identifier. If not give error and raise Pragma_Exit.
338 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
339 -- Check the specified argument Arg to make sure that it is an integer
340 -- literal. If not give error and raise Pragma_Exit.
342 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
343 -- Check the specified argument Arg to make sure that it has the proper
344 -- syntactic form for a local name and meets the semantic requirements
345 -- for a local name. The local name is analyzed as part of the
346 -- processing for this call. In addition, the local name is required
347 -- to represent an entity at the library level.
349 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
350 -- Check the specified argument Arg to make sure that it has the proper
351 -- syntactic form for a local name and meets the semantic requirements
352 -- for a local name. The local name is analyzed as part of the
353 -- processing for this call.
355 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
356 -- Check the specified argument Arg to make sure that it is a valid
357 -- locking policy name. If not give error and raise Pragma_Exit.
359 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
360 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
361 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
362 -- Check the specified argument Arg to make sure that it is an
363 -- identifier whose name matches either N1 or N2 (or N3 if present).
364 -- If not then give error and raise Pragma_Exit.
366 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
367 -- Check the specified argument Arg to make sure that it is a valid
368 -- queuing policy name. If not give error and raise Pragma_Exit.
370 procedure Check_Arg_Is_Static_Expression
371 (Arg : Node_Id;
372 Typ : Entity_Id := Empty);
373 -- Check the specified argument Arg to make sure that it is a static
374 -- expression of the given type (i.e. it will be analyzed and resolved
375 -- using this type, which can be any valid argument to Resolve, e.g.
376 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
377 -- Typ is left Empty, then any static expression is allowed.
379 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
380 -- Check the specified argument Arg to make sure that it is a string
381 -- literal. If not give error and raise Pragma_Exit
383 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
384 -- Check the specified argument Arg to make sure that it is a valid task
385 -- dispatching policy name. If not give error and raise Pragma_Exit.
387 procedure Check_Arg_Order (Names : Name_List);
388 -- Checks for an instance of two arguments with identifiers for the
389 -- current pragma which are not in the sequence indicated by Names,
390 -- and if so, generates a fatal message about bad order of arguments.
392 procedure Check_At_Least_N_Arguments (N : Nat);
393 -- Check there are at least N arguments present
395 procedure Check_At_Most_N_Arguments (N : Nat);
396 -- Check there are no more than N arguments present
398 procedure Check_Component (Comp : Node_Id);
399 -- Examine Unchecked_Union component for correct use of per-object
400 -- constrained subtypes, and for restrictions on finalizable components.
402 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
403 -- Nam is an N_String_Literal node containing the external name set by
404 -- an Import or Export pragma (or extended Import or Export pragma).
405 -- This procedure checks for possible duplications if this is the export
406 -- case, and if found, issues an appropriate error message.
408 procedure Check_First_Subtype (Arg : Node_Id);
409 -- Checks that Arg, whose expression is an entity name referencing a
410 -- subtype, does not reference a type that is not a first subtype.
412 procedure Check_In_Main_Program;
413 -- Common checks for pragmas that appear within a main program
414 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline).
416 procedure Check_Interrupt_Or_Attach_Handler;
417 -- Common processing for first argument of pragma Interrupt_Handler or
418 -- pragma Attach_Handler.
420 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
421 -- Check that pragma appears in a declarative part, or in a package
422 -- specification, i.e. that it does not occur in a statement sequence
423 -- in a body.
425 procedure Check_No_Identifier (Arg : Node_Id);
426 -- Checks that the given argument does not have an identifier. If
427 -- an identifier is present, then an error message is issued, and
428 -- Pragma_Exit is raised.
430 procedure Check_No_Identifiers;
431 -- Checks that none of the arguments to the pragma has an identifier.
432 -- If any argument has an identifier, then an error message is issued,
433 -- and Pragma_Exit is raised.
435 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
436 -- Checks if the given argument has an identifier, and if so, requires
437 -- it to match the given identifier name. If there is a non-matching
438 -- identifier, then an error message is given and Error_Pragmas raised.
440 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
441 -- Checks if the given argument has an identifier, and if so, requires
442 -- it to match the given identifier name. If there is a non-matching
443 -- identifier, then an error message is given and Error_Pragmas raised.
444 -- In this version of the procedure, the identifier name is given as
445 -- a string with lower case letters.
447 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
448 -- Called to process a precondition or postcondition pragma. There are
449 -- three cases:
451 -- The pragma appears after a subprogram spec
453 -- If the corresponding check is not enabled, the pragma is analyzed
454 -- but otherwise ignored and control returns with In_Body set False.
456 -- If the check is enabled, then the first step is to analyze the
457 -- pragma, but this is skipped if the subprogram spec appears within
458 -- a package specification (because this is the case where we delay
459 -- analysis till the end of the spec). Then (whether or not it was
460 -- analyzed), the pragma is chained to the subprogram in question
461 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
462 -- caller with In_Body set False.
464 -- The pragma appears at the start of subprogram body declarations
466 -- In this case an immediate return to the caller is made with
467 -- In_Body set True, and the pragma is NOT analyzed.
469 -- In all other cases, an error message for bad placement is given
471 procedure Check_Static_Constraint (Constr : Node_Id);
472 -- Constr is a constraint from an N_Subtype_Indication node from a
473 -- component constraint in an Unchecked_Union type. This routine checks
474 -- that the constraint is static as required by the restrictions for
475 -- Unchecked_Union.
477 procedure Check_Valid_Configuration_Pragma;
478 -- Legality checks for placement of a configuration pragma
480 procedure Check_Valid_Library_Unit_Pragma;
481 -- Legality checks for library unit pragmas. A special case arises for
482 -- pragmas in generic instances that come from copies of the original
483 -- library unit pragmas in the generic templates. In the case of other
484 -- than library level instantiations these can appear in contexts which
485 -- would normally be invalid (they only apply to the original template
486 -- and to library level instantiations), and they are simply ignored,
487 -- which is implemented by rewriting them as null statements.
489 procedure Check_Variant (Variant : Node_Id);
490 -- Check Unchecked_Union variant for lack of nested variants and
491 -- presence of at least one component.
493 procedure Error_Pragma (Msg : String);
494 pragma No_Return (Error_Pragma);
495 -- Outputs error message for current pragma. The message contains a %
496 -- that will be replaced with the pragma name, and the flag is placed
497 -- on the pragma itself. Pragma_Exit is then raised.
499 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
500 pragma No_Return (Error_Pragma_Arg);
501 -- Outputs error message for current pragma. The message may contain
502 -- a % that will be replaced with the pragma name. The parameter Arg
503 -- may either be a pragma argument association, in which case the flag
504 -- is placed on the expression of this association, or an expression,
505 -- in which case the flag is placed directly on the expression. The
506 -- message is placed using Error_Msg_N, so the message may also contain
507 -- an & insertion character which will reference the given Arg value.
508 -- After placing the message, Pragma_Exit is raised.
510 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
511 pragma No_Return (Error_Pragma_Arg);
512 -- Similar to above form of Error_Pragma_Arg except that two messages
513 -- are provided, the second is a continuation comment starting with \.
515 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
516 pragma No_Return (Error_Pragma_Arg_Ident);
517 -- Outputs error message for current pragma. The message may contain
518 -- a % that will be replaced with the pragma name. The parameter Arg
519 -- must be a pragma argument association with a non-empty identifier
520 -- (i.e. its Chars field must be set), and the error message is placed
521 -- on the identifier. The message is placed using Error_Msg_N so
522 -- the message may also contain an & insertion character which will
523 -- reference the identifier. After placing the message, Pragma_Exit
524 -- is raised.
526 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
527 pragma No_Return (Error_Pragma_Ref);
528 -- Outputs error message for current pragma. The message may contain
529 -- a % that will be replaced with the pragma name. The parameter Ref
530 -- must be an entity whose name can be referenced by & and sloc by #.
531 -- After placing the message, Pragma_Exit is raised.
533 function Find_Lib_Unit_Name return Entity_Id;
534 -- Used for a library unit pragma to find the entity to which the
535 -- library unit pragma applies, returns the entity found.
537 procedure Find_Program_Unit_Name (Id : Node_Id);
538 -- If the pragma is a compilation unit pragma, the id must denote the
539 -- compilation unit in the same compilation, and the pragma must appear
540 -- in the list of preceding or trailing pragmas. If it is a program
541 -- unit pragma that is not a compilation unit pragma, then the
542 -- identifier must be visible.
544 function Find_Unique_Parameterless_Procedure
545 (Name : Entity_Id;
546 Arg : Node_Id) return Entity_Id;
547 -- Used for a procedure pragma to find the unique parameterless
548 -- procedure identified by Name, returns it if it exists, otherwise
549 -- errors out and uses Arg as the pragma argument for the message.
551 procedure Gather_Associations
552 (Names : Name_List;
553 Args : out Args_List);
554 -- This procedure is used to gather the arguments for a pragma that
555 -- permits arbitrary ordering of parameters using the normal rules
556 -- for named and positional parameters. The Names argument is a list
557 -- of Name_Id values that corresponds to the allowed pragma argument
558 -- association identifiers in order. The result returned in Args is
559 -- a list of corresponding expressions that are the pragma arguments.
560 -- Note that this is a list of expressions, not of pragma argument
561 -- associations (Gather_Associations has completely checked all the
562 -- optional identifiers when it returns). An entry in Args is Empty
563 -- on return if the corresponding argument is not present.
565 procedure GNAT_Pragma;
566 -- Called for all GNAT defined pragmas to check the relevant restriction
567 -- (No_Implementation_Pragmas).
569 function Is_Before_First_Decl
570 (Pragma_Node : Node_Id;
571 Decls : List_Id) return Boolean;
572 -- Return True if Pragma_Node is before the first declarative item in
573 -- Decls where Decls is the list of declarative items.
575 function Is_Configuration_Pragma return Boolean;
576 -- Determines if the placement of the current pragma is appropriate
577 -- for a configuration pragma.
579 function Is_In_Context_Clause return Boolean;
580 -- Returns True if pragma appears within the context clause of a unit,
581 -- and False for any other placement (does not generate any messages).
583 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
584 -- Analyzes the argument, and determines if it is a static string
585 -- expression, returns True if so, False if non-static or not String.
587 procedure Pragma_Misplaced;
588 pragma No_Return (Pragma_Misplaced);
589 -- Issue fatal error message for misplaced pragma
591 procedure Process_Atomic_Shared_Volatile;
592 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
593 -- Shared is an obsolete Ada 83 pragma, treated as being identical
594 -- in effect to pragma Atomic.
596 procedure Process_Compile_Time_Warning_Or_Error;
597 -- Common processing for Compile_Time_Error and Compile_Time_Warning
599 procedure Process_Convention
600 (C : out Convention_Id;
601 Ent : out Entity_Id);
602 -- Common processing for Convention, Interface, Import and Export.
603 -- Checks first two arguments of pragma, and sets the appropriate
604 -- convention value in the specified entity or entities. On return
605 -- C is the convention, Ent is the referenced entity.
607 procedure Process_Extended_Import_Export_Exception_Pragma
608 (Arg_Internal : Node_Id;
609 Arg_External : Node_Id;
610 Arg_Form : Node_Id;
611 Arg_Code : Node_Id);
612 -- Common processing for the pragmas Import/Export_Exception. The three
613 -- arguments correspond to the three named parameters of the pragma. An
614 -- argument is empty if the corresponding parameter is not present in
615 -- the pragma.
617 procedure Process_Extended_Import_Export_Object_Pragma
618 (Arg_Internal : Node_Id;
619 Arg_External : Node_Id;
620 Arg_Size : Node_Id);
621 -- Common processing for the pragmas Import/Export_Object. The three
622 -- arguments correspond to the three named parameters of the pragmas. An
623 -- argument is empty if the corresponding parameter is not present in
624 -- the pragma.
626 procedure Process_Extended_Import_Export_Internal_Arg
627 (Arg_Internal : Node_Id := Empty);
628 -- Common processing for all extended Import and Export pragmas. The
629 -- argument is the pragma parameter for the Internal argument. If
630 -- Arg_Internal is empty or inappropriate, an error message is posted.
631 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
632 -- set to identify the referenced entity.
634 procedure Process_Extended_Import_Export_Subprogram_Pragma
635 (Arg_Internal : Node_Id;
636 Arg_External : Node_Id;
637 Arg_Parameter_Types : Node_Id;
638 Arg_Result_Type : Node_Id := Empty;
639 Arg_Mechanism : Node_Id;
640 Arg_Result_Mechanism : Node_Id := Empty;
641 Arg_First_Optional_Parameter : Node_Id := Empty);
642 -- Common processing for all extended Import and Export pragmas applying
643 -- to subprograms. The caller omits any arguments that do not apply to
644 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
645 -- only in the Import_Function and Export_Function cases). The argument
646 -- names correspond to the allowed pragma association identifiers.
648 procedure Process_Generic_List;
649 -- Common processing for Share_Generic and Inline_Generic
651 procedure Process_Import_Or_Interface;
652 -- Common processing for Import of Interface
654 procedure Process_Inline (Active : Boolean);
655 -- Common processing for Inline and Inline_Always. The parameter
656 -- indicates if the inline pragma is active, i.e. if it should actually
657 -- cause inlining to occur.
659 procedure Process_Interface_Name
660 (Subprogram_Def : Entity_Id;
661 Ext_Arg : Node_Id;
662 Link_Arg : Node_Id);
663 -- Given the last two arguments of pragma Import, pragma Export, or
664 -- pragma Interface_Name, performs validity checks and sets the
665 -- Interface_Name field of the given subprogram entity to the
666 -- appropriate external or link name, depending on the arguments given.
667 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
668 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
669 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
670 -- nor Link_Arg is present, the interface name is set to the default
671 -- from the subprogram name.
673 procedure Process_Interrupt_Or_Attach_Handler;
674 -- Common processing for Interrupt and Attach_Handler pragmas
676 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
677 -- Common processing for Restrictions and Restriction_Warnings pragmas.
678 -- Warn is True for Restriction_Warnings, or for Restrictions if the
679 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
680 -- is not set in the Restrictions case.
682 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
683 -- Common processing for Suppress and Unsuppress. The boolean parameter
684 -- Suppress_Case is True for the Suppress case, and False for the
685 -- Unsuppress case.
687 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
688 -- This procedure sets the Is_Exported flag for the given entity,
689 -- checking that the entity was not previously imported. Arg is
690 -- the argument that specified the entity. A check is also made
691 -- for exporting inappropriate entities.
693 procedure Set_Extended_Import_Export_External_Name
694 (Internal_Ent : Entity_Id;
695 Arg_External : Node_Id);
696 -- Common processing for all extended import export pragmas. The first
697 -- argument, Internal_Ent, is the internal entity, which has already
698 -- been checked for validity by the caller. Arg_External is from the
699 -- Import or Export pragma, and may be null if no External parameter
700 -- was present. If Arg_External is present and is a non-null string
701 -- (a null string is treated as the default), then the Interface_Name
702 -- field of Internal_Ent is set appropriately.
704 procedure Set_Imported (E : Entity_Id);
705 -- This procedure sets the Is_Imported flag for the given entity,
706 -- checking that it is not previously exported or imported.
708 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
709 -- Mech is a parameter passing mechanism (see Import_Function syntax
710 -- for MECHANISM_NAME). This routine checks that the mechanism argument
711 -- has the right form, and if not issues an error message. If the
712 -- argument has the right form then the Mechanism field of Ent is
713 -- set appropriately.
715 procedure Set_Ravenscar_Profile (N : Node_Id);
716 -- Activate the set of configuration pragmas and restrictions that make
717 -- up the Ravenscar Profile. N is the corresponding pragma node, which
718 -- is used for error messages on any constructs that violate the
719 -- profile.
721 ---------------------
722 -- Ada_2005_Pragma --
723 ---------------------
725 procedure Ada_2005_Pragma is
726 begin
727 if Ada_Version <= Ada_95 then
728 Check_Restriction (No_Implementation_Pragmas, N);
729 end if;
730 end Ada_2005_Pragma;
732 --------------------------
733 -- Check_Ada_83_Warning --
734 --------------------------
736 procedure Check_Ada_83_Warning is
737 begin
738 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
739 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
740 end if;
741 end Check_Ada_83_Warning;
743 ---------------------
744 -- Check_Arg_Count --
745 ---------------------
747 procedure Check_Arg_Count (Required : Nat) is
748 begin
749 if Arg_Count /= Required then
750 Error_Pragma ("wrong number of arguments for pragma%");
751 end if;
752 end Check_Arg_Count;
754 --------------------------------
755 -- Check_Arg_Is_External_Name --
756 --------------------------------
758 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
759 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
761 begin
762 if Nkind (Argx) = N_Identifier then
763 return;
765 else
766 Analyze_And_Resolve (Argx, Standard_String);
768 if Is_OK_Static_Expression (Argx) then
769 return;
771 elsif Etype (Argx) = Any_Type then
772 raise Pragma_Exit;
774 -- An interesting special case, if we have a string literal and
775 -- we are in Ada 83 mode, then we allow it even though it will
776 -- not be flagged as static. This allows expected Ada 83 mode
777 -- use of external names which are string literals, even though
778 -- technically these are not static in Ada 83.
780 elsif Ada_Version = Ada_83
781 and then Nkind (Argx) = N_String_Literal
782 then
783 return;
785 -- Static expression that raises Constraint_Error. This has
786 -- already been flagged, so just exit from pragma processing.
788 elsif Is_Static_Expression (Argx) then
789 raise Pragma_Exit;
791 -- Here we have a real error (non-static expression)
793 else
794 Error_Msg_Name_1 := Pname;
795 Flag_Non_Static_Expr
796 ("argument for pragma% must be a identifier or " &
797 "static string expression!", Argx);
798 raise Pragma_Exit;
799 end if;
800 end if;
801 end Check_Arg_Is_External_Name;
803 -----------------------------
804 -- Check_Arg_Is_Identifier --
805 -----------------------------
807 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
808 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
809 begin
810 if Nkind (Argx) /= N_Identifier then
811 Error_Pragma_Arg
812 ("argument for pragma% must be identifier", Argx);
813 end if;
814 end Check_Arg_Is_Identifier;
816 ----------------------------------
817 -- Check_Arg_Is_Integer_Literal --
818 ----------------------------------
820 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
821 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
822 begin
823 if Nkind (Argx) /= N_Integer_Literal then
824 Error_Pragma_Arg
825 ("argument for pragma% must be integer literal", Argx);
826 end if;
827 end Check_Arg_Is_Integer_Literal;
829 -------------------------------------------
830 -- Check_Arg_Is_Library_Level_Local_Name --
831 -------------------------------------------
833 -- LOCAL_NAME ::=
834 -- DIRECT_NAME
835 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
836 -- | library_unit_NAME
838 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
839 begin
840 Check_Arg_Is_Local_Name (Arg);
842 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
843 and then Comes_From_Source (N)
844 then
845 Error_Pragma_Arg
846 ("argument for pragma% must be library level entity", Arg);
847 end if;
848 end Check_Arg_Is_Library_Level_Local_Name;
850 -----------------------------
851 -- Check_Arg_Is_Local_Name --
852 -----------------------------
854 -- LOCAL_NAME ::=
855 -- DIRECT_NAME
856 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
857 -- | library_unit_NAME
859 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
860 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
862 begin
863 Analyze (Argx);
865 if Nkind (Argx) not in N_Direct_Name
866 and then (Nkind (Argx) /= N_Attribute_Reference
867 or else Present (Expressions (Argx))
868 or else Nkind (Prefix (Argx)) /= N_Identifier)
869 and then (not Is_Entity_Name (Argx)
870 or else not Is_Compilation_Unit (Entity (Argx)))
871 then
872 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
873 end if;
875 if Is_Entity_Name (Argx)
876 and then Scope (Entity (Argx)) /= Current_Scope
877 then
878 Error_Pragma_Arg
879 ("pragma% argument must be in same declarative part", Arg);
880 end if;
881 end Check_Arg_Is_Local_Name;
883 ---------------------------------
884 -- Check_Arg_Is_Locking_Policy --
885 ---------------------------------
887 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
888 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
890 begin
891 Check_Arg_Is_Identifier (Argx);
893 if not Is_Locking_Policy_Name (Chars (Argx)) then
894 Error_Pragma_Arg
895 ("& is not a valid locking policy name", Argx);
896 end if;
897 end Check_Arg_Is_Locking_Policy;
899 -------------------------
900 -- Check_Arg_Is_One_Of --
901 -------------------------
903 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
904 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
906 begin
907 Check_Arg_Is_Identifier (Argx);
909 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
910 Error_Msg_Name_2 := N1;
911 Error_Msg_Name_3 := N2;
912 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
913 end if;
914 end Check_Arg_Is_One_Of;
916 procedure Check_Arg_Is_One_Of
917 (Arg : Node_Id;
918 N1, N2, N3 : Name_Id)
920 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
922 begin
923 Check_Arg_Is_Identifier (Argx);
925 if Chars (Argx) /= N1
926 and then Chars (Argx) /= N2
927 and then Chars (Argx) /= N3
928 then
929 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
930 end if;
931 end Check_Arg_Is_One_Of;
933 procedure Check_Arg_Is_One_Of
934 (Arg : Node_Id;
935 N1, N2, N3, N4 : Name_Id)
937 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
939 begin
940 Check_Arg_Is_Identifier (Argx);
942 if Chars (Argx) /= N1
943 and then Chars (Argx) /= N2
944 and then Chars (Argx) /= N3
945 and then Chars (Argx) /= N4
946 then
947 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
948 end if;
949 end Check_Arg_Is_One_Of;
951 ---------------------------------
952 -- Check_Arg_Is_Queuing_Policy --
953 ---------------------------------
955 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
956 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
958 begin
959 Check_Arg_Is_Identifier (Argx);
961 if not Is_Queuing_Policy_Name (Chars (Argx)) then
962 Error_Pragma_Arg
963 ("& is not a valid queuing policy name", Argx);
964 end if;
965 end Check_Arg_Is_Queuing_Policy;
967 ------------------------------------
968 -- Check_Arg_Is_Static_Expression --
969 ------------------------------------
971 procedure Check_Arg_Is_Static_Expression
972 (Arg : Node_Id;
973 Typ : Entity_Id := Empty)
975 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
977 begin
978 if Present (Typ) then
979 Analyze_And_Resolve (Argx, Typ);
980 else
981 Analyze_And_Resolve (Argx);
982 end if;
984 if Is_OK_Static_Expression (Argx) then
985 return;
987 elsif Etype (Argx) = Any_Type then
988 raise Pragma_Exit;
990 -- An interesting special case, if we have a string literal and we
991 -- are in Ada 83 mode, then we allow it even though it will not be
992 -- flagged as static. This allows the use of Ada 95 pragmas like
993 -- Import in Ada 83 mode. They will of course be flagged with
994 -- warnings as usual, but will not cause errors.
996 elsif Ada_Version = Ada_83
997 and then Nkind (Argx) = N_String_Literal
998 then
999 return;
1001 -- Static expression that raises Constraint_Error. This has already
1002 -- been flagged, so just exit from pragma processing.
1004 elsif Is_Static_Expression (Argx) then
1005 raise Pragma_Exit;
1007 -- Finally, we have a real error
1009 else
1010 Error_Msg_Name_1 := Pname;
1011 Flag_Non_Static_Expr
1012 ("argument for pragma% must be a static expression!", Argx);
1013 raise Pragma_Exit;
1014 end if;
1015 end Check_Arg_Is_Static_Expression;
1017 ---------------------------------
1018 -- Check_Arg_Is_String_Literal --
1019 ---------------------------------
1021 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
1022 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1023 begin
1024 if Nkind (Argx) /= N_String_Literal then
1025 Error_Pragma_Arg
1026 ("argument for pragma% must be string literal", Argx);
1027 end if;
1028 end Check_Arg_Is_String_Literal;
1030 ------------------------------------------
1031 -- Check_Arg_Is_Task_Dispatching_Policy --
1032 ------------------------------------------
1034 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1035 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1037 begin
1038 Check_Arg_Is_Identifier (Argx);
1040 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1041 Error_Pragma_Arg
1042 ("& is not a valid task dispatching policy name", Argx);
1043 end if;
1044 end Check_Arg_Is_Task_Dispatching_Policy;
1046 ---------------------
1047 -- Check_Arg_Order --
1048 ---------------------
1050 procedure Check_Arg_Order (Names : Name_List) is
1051 Arg : Node_Id;
1053 Highest_So_Far : Natural := 0;
1054 -- Highest index in Names seen do far
1056 begin
1057 Arg := Arg1;
1058 for J in 1 .. Arg_Count loop
1059 if Chars (Arg) /= No_Name then
1060 for K in Names'Range loop
1061 if Chars (Arg) = Names (K) then
1062 if K < Highest_So_Far then
1063 Error_Msg_Name_1 := Pname;
1064 Error_Msg_N
1065 ("parameters out of order for pragma%", Arg);
1066 Error_Msg_Name_1 := Names (K);
1067 Error_Msg_Name_2 := Names (Highest_So_Far);
1068 Error_Msg_N ("\% must appear before %", Arg);
1069 raise Pragma_Exit;
1071 else
1072 Highest_So_Far := K;
1073 end if;
1074 end if;
1075 end loop;
1076 end if;
1078 Arg := Next (Arg);
1079 end loop;
1080 end Check_Arg_Order;
1082 --------------------------------
1083 -- Check_At_Least_N_Arguments --
1084 --------------------------------
1086 procedure Check_At_Least_N_Arguments (N : Nat) is
1087 begin
1088 if Arg_Count < N then
1089 Error_Pragma ("too few arguments for pragma%");
1090 end if;
1091 end Check_At_Least_N_Arguments;
1093 -------------------------------
1094 -- Check_At_Most_N_Arguments --
1095 -------------------------------
1097 procedure Check_At_Most_N_Arguments (N : Nat) is
1098 Arg : Node_Id;
1099 begin
1100 if Arg_Count > N then
1101 Arg := Arg1;
1102 for J in 1 .. N loop
1103 Next (Arg);
1104 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1105 end loop;
1106 end if;
1107 end Check_At_Most_N_Arguments;
1109 ---------------------
1110 -- Check_Component --
1111 ---------------------
1113 procedure Check_Component (Comp : Node_Id) is
1114 begin
1115 if Nkind (Comp) = N_Component_Declaration then
1116 declare
1117 Sindic : constant Node_Id :=
1118 Subtype_Indication (Component_Definition (Comp));
1119 Typ : constant Entity_Id :=
1120 Etype (Defining_Identifier (Comp));
1121 begin
1122 if Nkind (Sindic) = N_Subtype_Indication then
1124 -- Ada 2005 (AI-216): If a component subtype is subject to
1125 -- a per-object constraint, then the component type shall
1126 -- be an Unchecked_Union.
1128 if Has_Per_Object_Constraint (Defining_Identifier (Comp))
1129 and then
1130 not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1131 then
1132 Error_Msg_N ("component subtype subject to per-object" &
1133 " constraint must be an Unchecked_Union", Comp);
1134 end if;
1135 end if;
1137 if Is_Controlled (Typ) then
1138 Error_Msg_N
1139 ("component of unchecked union cannot be controlled", Comp);
1141 elsif Has_Task (Typ) then
1142 Error_Msg_N
1143 ("component of unchecked union cannot have tasks", Comp);
1144 end if;
1145 end;
1146 end if;
1147 end Check_Component;
1149 ----------------------------------
1150 -- Check_Duplicated_Export_Name --
1151 ----------------------------------
1153 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1154 String_Val : constant String_Id := Strval (Nam);
1156 begin
1157 -- We allow duplicated export names in CIL, as they are always
1158 -- enclosed in a namespace that differentiates them, and overloaded
1159 -- entities are supported by the VM.
1161 if VM_Target = CLI_Target then
1162 return;
1163 end if;
1165 -- We are only interested in the export case, and in the case of
1166 -- generics, it is the instance, not the template, that is the
1167 -- problem (the template will generate a warning in any case).
1169 if not Inside_A_Generic
1170 and then (Prag_Id = Pragma_Export
1171 or else
1172 Prag_Id = Pragma_Export_Procedure
1173 or else
1174 Prag_Id = Pragma_Export_Valued_Procedure
1175 or else
1176 Prag_Id = Pragma_Export_Function)
1177 then
1178 for J in Externals.First .. Externals.Last loop
1179 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1180 Error_Msg_Sloc := Sloc (Externals.Table (J));
1181 Error_Msg_N ("external name duplicates name given#", Nam);
1182 exit;
1183 end if;
1184 end loop;
1186 Externals.Append (Nam);
1187 end if;
1188 end Check_Duplicated_Export_Name;
1190 -------------------------
1191 -- Check_First_Subtype --
1192 -------------------------
1194 procedure Check_First_Subtype (Arg : Node_Id) is
1195 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1196 begin
1197 if not Is_First_Subtype (Entity (Argx)) then
1198 Error_Pragma_Arg
1199 ("pragma% cannot apply to subtype", Argx);
1200 end if;
1201 end Check_First_Subtype;
1203 ---------------------------
1204 -- Check_In_Main_Program --
1205 ---------------------------
1207 procedure Check_In_Main_Program is
1208 P : constant Node_Id := Parent (N);
1210 begin
1211 -- Must be at in subprogram body
1213 if Nkind (P) /= N_Subprogram_Body then
1214 Error_Pragma ("% pragma allowed only in subprogram");
1216 -- Otherwise warn if obviously not main program
1218 elsif Present (Parameter_Specifications (Specification (P)))
1219 or else not Is_Compilation_Unit (Defining_Entity (P))
1220 then
1221 Error_Msg_Name_1 := Pname;
1222 Error_Msg_N
1223 ("?pragma% is only effective in main program", N);
1224 end if;
1225 end Check_In_Main_Program;
1227 ---------------------------------------
1228 -- Check_Interrupt_Or_Attach_Handler --
1229 ---------------------------------------
1231 procedure Check_Interrupt_Or_Attach_Handler is
1232 Arg1_X : constant Node_Id := Expression (Arg1);
1233 Handler_Proc, Proc_Scope : Entity_Id;
1235 begin
1236 Analyze (Arg1_X);
1238 if Prag_Id = Pragma_Interrupt_Handler then
1239 Check_Restriction (No_Dynamic_Attachment, N);
1240 end if;
1242 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1243 Proc_Scope := Scope (Handler_Proc);
1245 -- On AAMP only, a pragma Interrupt_Handler is supported for
1246 -- nonprotected parameterless procedures.
1248 if not AAMP_On_Target
1249 or else Prag_Id = Pragma_Attach_Handler
1250 then
1251 if Ekind (Proc_Scope) /= E_Protected_Type then
1252 Error_Pragma_Arg
1253 ("argument of pragma% must be protected procedure", Arg1);
1254 end if;
1256 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1257 Error_Pragma ("pragma% must be in protected definition");
1258 end if;
1259 end if;
1261 if not Is_Library_Level_Entity (Proc_Scope)
1262 or else (AAMP_On_Target
1263 and then not Is_Library_Level_Entity (Handler_Proc))
1264 then
1265 Error_Pragma_Arg
1266 ("argument for pragma% must be library level entity", Arg1);
1267 end if;
1268 end Check_Interrupt_Or_Attach_Handler;
1270 -------------------------------------------
1271 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1272 -------------------------------------------
1274 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1275 P : Node_Id;
1277 begin
1278 P := Parent (N);
1279 loop
1280 if No (P) then
1281 exit;
1283 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1284 exit;
1286 elsif Nkind_In (P, N_Package_Specification,
1287 N_Block_Statement)
1288 then
1289 return;
1291 -- Note: the following tests seem a little peculiar, because
1292 -- they test for bodies, but if we were in the statement part
1293 -- of the body, we would already have hit the handled statement
1294 -- sequence, so the only way we get here is by being in the
1295 -- declarative part of the body.
1297 elsif Nkind_In (P, N_Subprogram_Body,
1298 N_Package_Body,
1299 N_Task_Body,
1300 N_Entry_Body)
1301 then
1302 return;
1303 end if;
1305 P := Parent (P);
1306 end loop;
1308 Error_Pragma ("pragma% is not in declarative part or package spec");
1309 end Check_Is_In_Decl_Part_Or_Package_Spec;
1311 -------------------------
1312 -- Check_No_Identifier --
1313 -------------------------
1315 procedure Check_No_Identifier (Arg : Node_Id) is
1316 begin
1317 if Chars (Arg) /= No_Name then
1318 Error_Pragma_Arg_Ident
1319 ("pragma% does not permit identifier& here", Arg);
1320 end if;
1321 end Check_No_Identifier;
1323 --------------------------
1324 -- Check_No_Identifiers --
1325 --------------------------
1327 procedure Check_No_Identifiers is
1328 Arg_Node : Node_Id;
1329 begin
1330 if Arg_Count > 0 then
1331 Arg_Node := Arg1;
1332 while Present (Arg_Node) loop
1333 Check_No_Identifier (Arg_Node);
1334 Next (Arg_Node);
1335 end loop;
1336 end if;
1337 end Check_No_Identifiers;
1339 -------------------------------
1340 -- Check_Optional_Identifier --
1341 -------------------------------
1343 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1344 begin
1345 if Present (Arg) and then Chars (Arg) /= No_Name then
1346 if Chars (Arg) /= Id then
1347 Error_Msg_Name_1 := Pname;
1348 Error_Msg_Name_2 := Id;
1349 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1350 raise Pragma_Exit;
1351 end if;
1352 end if;
1353 end Check_Optional_Identifier;
1355 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1356 begin
1357 Name_Buffer (1 .. Id'Length) := Id;
1358 Name_Len := Id'Length;
1359 Check_Optional_Identifier (Arg, Name_Find);
1360 end Check_Optional_Identifier;
1362 --------------------------------------
1363 -- Check_Precondition_Postcondition --
1364 --------------------------------------
1366 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1367 P : Node_Id;
1368 PO : Node_Id;
1370 procedure Chain_PPC (PO : Node_Id);
1371 -- If PO is a subprogram declaration node (or a generic subprogram
1372 -- declaration node), then the precondition/postcondition applies
1373 -- to this subprogram and the processing for the pragma is completed.
1374 -- Otherwise the pragma is misplaced.
1376 ---------------
1377 -- Chain_PPC --
1378 ---------------
1380 procedure Chain_PPC (PO : Node_Id) is
1381 S : Node_Id;
1383 begin
1384 if not Nkind_In (PO, N_Subprogram_Declaration,
1385 N_Generic_Subprogram_Declaration)
1386 then
1387 Pragma_Misplaced;
1388 end if;
1390 -- Here if we have subprogram or generic subprogram declaration
1392 S := Defining_Unit_Name (Specification (PO));
1394 -- Analyze the pragma unless it appears within a package spec,
1395 -- which is the case where we delay the analysis of the PPC until
1396 -- the end of the package declarations (for details, see
1397 -- Analyze_Package_Specification.Analyze_PPCs).
1399 if not Is_Package_Or_Generic_Package (Scope (S)) then
1400 Analyze_PPC_In_Decl_Part (N, S);
1401 end if;
1403 -- Chain spec PPC pragma to list for subprogram
1405 Set_Next_Pragma (N, Spec_PPC_List (S));
1406 Set_Spec_PPC_List (S, N);
1408 -- Return indicating spec case
1410 In_Body := False;
1411 return;
1412 end Chain_PPC;
1414 -- Start of processing for Check_Precondition_Postcondition
1416 begin
1417 if not Is_List_Member (N) then
1418 Pragma_Misplaced;
1419 end if;
1421 -- Record whether pragma is enabled
1423 Set_PPC_Enabled (N, Check_Enabled (Pname));
1425 -- If we are within an inlined body, the legality of the pragma
1426 -- has been checked already.
1428 if In_Inlined_Body then
1429 In_Body := True;
1430 return;
1431 end if;
1433 -- Search prior declarations
1435 P := N;
1436 while Present (Prev (P)) loop
1437 P := Prev (P);
1439 -- If the previous node is a generic subprogram, do not go to to
1440 -- the original node, which is the unanalyzed tree: we need to
1441 -- attach the pre/postconditions to the analyzed version at this
1442 -- point. They get propagated to the original tree when analyzing
1443 -- the corresponding body.
1445 if Nkind (P) not in N_Generic_Declaration then
1446 PO := Original_Node (P);
1447 else
1448 PO := P;
1449 end if;
1451 -- Skip past prior pragma
1453 if Nkind (PO) = N_Pragma then
1454 null;
1456 -- Skip stuff not coming from source
1458 elsif not Comes_From_Source (PO) then
1459 null;
1461 -- Only remaining possibility is subprogram declaration
1463 else
1464 Chain_PPC (PO);
1465 return;
1466 end if;
1467 end loop;
1469 -- If we fall through loop, pragma is at start of list, so see if it
1470 -- is at the start of declarations of a subprogram body.
1472 if Nkind (Parent (N)) = N_Subprogram_Body
1473 and then List_Containing (N) = Declarations (Parent (N))
1474 then
1475 if Operating_Mode /= Generate_Code
1476 or else Inside_A_Generic
1477 then
1479 -- Analyze expression in pragma, for correctness
1480 -- and for ASIS use.
1482 Preanalyze_Spec_Expression
1483 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1484 end if;
1486 In_Body := True;
1487 return;
1489 -- See if it is in the pragmas after a library level subprogram
1491 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1492 Chain_PPC (Unit (Parent (Parent (N))));
1493 return;
1494 end if;
1496 -- If we fall through, pragma was misplaced
1498 Pragma_Misplaced;
1499 end Check_Precondition_Postcondition;
1501 -----------------------------
1502 -- Check_Static_Constraint --
1503 -----------------------------
1505 -- Note: for convenience in writing this procedure, in addition to
1506 -- the officially (i.e. by spec) allowed argument which is always a
1507 -- constraint, it also allows ranges and discriminant associations.
1508 -- Above is not clear ???
1510 procedure Check_Static_Constraint (Constr : Node_Id) is
1512 procedure Require_Static (E : Node_Id);
1513 -- Require given expression to be static expression
1515 --------------------
1516 -- Require_Static --
1517 --------------------
1519 procedure Require_Static (E : Node_Id) is
1520 begin
1521 if not Is_OK_Static_Expression (E) then
1522 Flag_Non_Static_Expr
1523 ("non-static constraint not allowed in Unchecked_Union!", E);
1524 raise Pragma_Exit;
1525 end if;
1526 end Require_Static;
1528 -- Start of processing for Check_Static_Constraint
1530 begin
1531 case Nkind (Constr) is
1532 when N_Discriminant_Association =>
1533 Require_Static (Expression (Constr));
1535 when N_Range =>
1536 Require_Static (Low_Bound (Constr));
1537 Require_Static (High_Bound (Constr));
1539 when N_Attribute_Reference =>
1540 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1541 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1543 when N_Range_Constraint =>
1544 Check_Static_Constraint (Range_Expression (Constr));
1546 when N_Index_Or_Discriminant_Constraint =>
1547 declare
1548 IDC : Entity_Id;
1549 begin
1550 IDC := First (Constraints (Constr));
1551 while Present (IDC) loop
1552 Check_Static_Constraint (IDC);
1553 Next (IDC);
1554 end loop;
1555 end;
1557 when others =>
1558 null;
1559 end case;
1560 end Check_Static_Constraint;
1562 --------------------------------------
1563 -- Check_Valid_Configuration_Pragma --
1564 --------------------------------------
1566 -- A configuration pragma must appear in the context clause of a
1567 -- compilation unit, and only other pragmas may precede it. Note that
1568 -- the test also allows use in a configuration pragma file.
1570 procedure Check_Valid_Configuration_Pragma is
1571 begin
1572 if not Is_Configuration_Pragma then
1573 Error_Pragma ("incorrect placement for configuration pragma%");
1574 end if;
1575 end Check_Valid_Configuration_Pragma;
1577 -------------------------------------
1578 -- Check_Valid_Library_Unit_Pragma --
1579 -------------------------------------
1581 procedure Check_Valid_Library_Unit_Pragma is
1582 Plist : List_Id;
1583 Parent_Node : Node_Id;
1584 Unit_Name : Entity_Id;
1585 Unit_Kind : Node_Kind;
1586 Unit_Node : Node_Id;
1587 Sindex : Source_File_Index;
1589 begin
1590 if not Is_List_Member (N) then
1591 Pragma_Misplaced;
1593 else
1594 Plist := List_Containing (N);
1595 Parent_Node := Parent (Plist);
1597 if Parent_Node = Empty then
1598 Pragma_Misplaced;
1600 -- Case of pragma appearing after a compilation unit. In this case
1601 -- it must have an argument with the corresponding name and must
1602 -- be part of the following pragmas of its parent.
1604 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1605 if Plist /= Pragmas_After (Parent_Node) then
1606 Pragma_Misplaced;
1608 elsif Arg_Count = 0 then
1609 Error_Pragma
1610 ("argument required if outside compilation unit");
1612 else
1613 Check_No_Identifiers;
1614 Check_Arg_Count (1);
1615 Unit_Node := Unit (Parent (Parent_Node));
1616 Unit_Kind := Nkind (Unit_Node);
1618 Analyze (Expression (Arg1));
1620 if Unit_Kind = N_Generic_Subprogram_Declaration
1621 or else Unit_Kind = N_Subprogram_Declaration
1622 then
1623 Unit_Name := Defining_Entity (Unit_Node);
1625 elsif Unit_Kind in N_Generic_Instantiation then
1626 Unit_Name := Defining_Entity (Unit_Node);
1628 else
1629 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1630 end if;
1632 if Chars (Unit_Name) /=
1633 Chars (Entity (Expression (Arg1)))
1634 then
1635 Error_Pragma_Arg
1636 ("pragma% argument is not current unit name", Arg1);
1637 end if;
1639 if Ekind (Unit_Name) = E_Package
1640 and then Present (Renamed_Entity (Unit_Name))
1641 then
1642 Error_Pragma ("pragma% not allowed for renamed package");
1643 end if;
1644 end if;
1646 -- Pragma appears other than after a compilation unit
1648 else
1649 -- Here we check for the generic instantiation case and also
1650 -- for the case of processing a generic formal package. We
1651 -- detect these cases by noting that the Sloc on the node
1652 -- does not belong to the current compilation unit.
1654 Sindex := Source_Index (Current_Sem_Unit);
1656 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1657 Rewrite (N, Make_Null_Statement (Loc));
1658 return;
1660 -- If before first declaration, the pragma applies to the
1661 -- enclosing unit, and the name if present must be this name.
1663 elsif Is_Before_First_Decl (N, Plist) then
1664 Unit_Node := Unit_Declaration_Node (Current_Scope);
1665 Unit_Kind := Nkind (Unit_Node);
1667 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1668 Pragma_Misplaced;
1670 elsif Unit_Kind = N_Subprogram_Body
1671 and then not Acts_As_Spec (Unit_Node)
1672 then
1673 Pragma_Misplaced;
1675 elsif Nkind (Parent_Node) = N_Package_Body then
1676 Pragma_Misplaced;
1678 elsif Nkind (Parent_Node) = N_Package_Specification
1679 and then Plist = Private_Declarations (Parent_Node)
1680 then
1681 Pragma_Misplaced;
1683 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1684 or else Nkind (Parent_Node) =
1685 N_Generic_Subprogram_Declaration)
1686 and then Plist = Generic_Formal_Declarations (Parent_Node)
1687 then
1688 Pragma_Misplaced;
1690 elsif Arg_Count > 0 then
1691 Analyze (Expression (Arg1));
1693 if Entity (Expression (Arg1)) /= Current_Scope then
1694 Error_Pragma_Arg
1695 ("name in pragma% must be enclosing unit", Arg1);
1696 end if;
1698 -- It is legal to have no argument in this context
1700 else
1701 return;
1702 end if;
1704 -- Error if not before first declaration. This is because a
1705 -- library unit pragma argument must be the name of a library
1706 -- unit (RM 10.1.5(7)), but the only names permitted in this
1707 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1708 -- generic subprogram declarations or generic instantiations.
1710 else
1711 Error_Pragma
1712 ("pragma% misplaced, must be before first declaration");
1713 end if;
1714 end if;
1715 end if;
1716 end Check_Valid_Library_Unit_Pragma;
1718 -------------------
1719 -- Check_Variant --
1720 -------------------
1722 procedure Check_Variant (Variant : Node_Id) is
1723 Clist : constant Node_Id := Component_List (Variant);
1724 Comp : Node_Id;
1726 begin
1727 if not Is_Non_Empty_List (Component_Items (Clist)) then
1728 Error_Msg_N
1729 ("Unchecked_Union may not have empty component list",
1730 Variant);
1731 return;
1732 end if;
1734 Comp := First (Component_Items (Clist));
1735 while Present (Comp) loop
1736 Check_Component (Comp);
1737 Next (Comp);
1738 end loop;
1739 end Check_Variant;
1741 ------------------
1742 -- Error_Pragma --
1743 ------------------
1745 procedure Error_Pragma (Msg : String) is
1746 begin
1747 Error_Msg_Name_1 := Pname;
1748 Error_Msg_N (Msg, N);
1749 raise Pragma_Exit;
1750 end Error_Pragma;
1752 ----------------------
1753 -- Error_Pragma_Arg --
1754 ----------------------
1756 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1757 begin
1758 Error_Msg_Name_1 := Pname;
1759 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1760 raise Pragma_Exit;
1761 end Error_Pragma_Arg;
1763 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1764 begin
1765 Error_Msg_Name_1 := Pname;
1766 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1767 Error_Pragma_Arg (Msg2, Arg);
1768 end Error_Pragma_Arg;
1770 ----------------------------
1771 -- Error_Pragma_Arg_Ident --
1772 ----------------------------
1774 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1775 begin
1776 Error_Msg_Name_1 := Pname;
1777 Error_Msg_N (Msg, Arg);
1778 raise Pragma_Exit;
1779 end Error_Pragma_Arg_Ident;
1781 ----------------------
1782 -- Error_Pragma_Ref --
1783 ----------------------
1785 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
1786 begin
1787 Error_Msg_Name_1 := Pname;
1788 Error_Msg_Sloc := Sloc (Ref);
1789 Error_Msg_NE (Msg, N, Ref);
1790 raise Pragma_Exit;
1791 end Error_Pragma_Ref;
1793 ------------------------
1794 -- Find_Lib_Unit_Name --
1795 ------------------------
1797 function Find_Lib_Unit_Name return Entity_Id is
1798 begin
1799 -- Return inner compilation unit entity, for case of nested
1800 -- categorization pragmas. This happens in generic unit.
1802 if Nkind (Parent (N)) = N_Package_Specification
1803 and then Defining_Entity (Parent (N)) /= Current_Scope
1804 then
1805 return Defining_Entity (Parent (N));
1806 else
1807 return Current_Scope;
1808 end if;
1809 end Find_Lib_Unit_Name;
1811 ----------------------------
1812 -- Find_Program_Unit_Name --
1813 ----------------------------
1815 procedure Find_Program_Unit_Name (Id : Node_Id) is
1816 Unit_Name : Entity_Id;
1817 Unit_Kind : Node_Kind;
1818 P : constant Node_Id := Parent (N);
1820 begin
1821 if Nkind (P) = N_Compilation_Unit then
1822 Unit_Kind := Nkind (Unit (P));
1824 if Unit_Kind = N_Subprogram_Declaration
1825 or else Unit_Kind = N_Package_Declaration
1826 or else Unit_Kind in N_Generic_Declaration
1827 then
1828 Unit_Name := Defining_Entity (Unit (P));
1830 if Chars (Id) = Chars (Unit_Name) then
1831 Set_Entity (Id, Unit_Name);
1832 Set_Etype (Id, Etype (Unit_Name));
1833 else
1834 Set_Etype (Id, Any_Type);
1835 Error_Pragma
1836 ("cannot find program unit referenced by pragma%");
1837 end if;
1839 else
1840 Set_Etype (Id, Any_Type);
1841 Error_Pragma ("pragma% inapplicable to this unit");
1842 end if;
1844 else
1845 Analyze (Id);
1846 end if;
1847 end Find_Program_Unit_Name;
1849 -----------------------------------------
1850 -- Find_Unique_Parameterless_Procedure --
1851 -----------------------------------------
1853 function Find_Unique_Parameterless_Procedure
1854 (Name : Entity_Id;
1855 Arg : Node_Id) return Entity_Id
1857 Proc : Entity_Id := Empty;
1859 begin
1860 -- The body of this procedure needs some comments ???
1862 if not Is_Entity_Name (Name) then
1863 Error_Pragma_Arg
1864 ("argument of pragma% must be entity name", Arg);
1866 elsif not Is_Overloaded (Name) then
1867 Proc := Entity (Name);
1869 if Ekind (Proc) /= E_Procedure
1870 or else Present (First_Formal (Proc)) then
1871 Error_Pragma_Arg
1872 ("argument of pragma% must be parameterless procedure", Arg);
1873 end if;
1875 else
1876 declare
1877 Found : Boolean := False;
1878 It : Interp;
1879 Index : Interp_Index;
1881 begin
1882 Get_First_Interp (Name, Index, It);
1883 while Present (It.Nam) loop
1884 Proc := It.Nam;
1886 if Ekind (Proc) = E_Procedure
1887 and then No (First_Formal (Proc))
1888 then
1889 if not Found then
1890 Found := True;
1891 Set_Entity (Name, Proc);
1892 Set_Is_Overloaded (Name, False);
1893 else
1894 Error_Pragma_Arg
1895 ("ambiguous handler name for pragma% ", Arg);
1896 end if;
1897 end if;
1899 Get_Next_Interp (Index, It);
1900 end loop;
1902 if not Found then
1903 Error_Pragma_Arg
1904 ("argument of pragma% must be parameterless procedure",
1905 Arg);
1906 else
1907 Proc := Entity (Name);
1908 end if;
1909 end;
1910 end if;
1912 return Proc;
1913 end Find_Unique_Parameterless_Procedure;
1915 -------------------------
1916 -- Gather_Associations --
1917 -------------------------
1919 procedure Gather_Associations
1920 (Names : Name_List;
1921 Args : out Args_List)
1923 Arg : Node_Id;
1925 begin
1926 -- Initialize all parameters to Empty
1928 for J in Args'Range loop
1929 Args (J) := Empty;
1930 end loop;
1932 -- That's all we have to do if there are no argument associations
1934 if No (Pragma_Argument_Associations (N)) then
1935 return;
1936 end if;
1938 -- Otherwise first deal with any positional parameters present
1940 Arg := First (Pragma_Argument_Associations (N));
1941 for Index in Args'Range loop
1942 exit when No (Arg) or else Chars (Arg) /= No_Name;
1943 Args (Index) := Expression (Arg);
1944 Next (Arg);
1945 end loop;
1947 -- Positional parameters all processed, if any left, then we
1948 -- have too many positional parameters.
1950 if Present (Arg) and then Chars (Arg) = No_Name then
1951 Error_Pragma_Arg
1952 ("too many positional associations for pragma%", Arg);
1953 end if;
1955 -- Process named parameters if any are present
1957 while Present (Arg) loop
1958 if Chars (Arg) = No_Name then
1959 Error_Pragma_Arg
1960 ("positional association cannot follow named association",
1961 Arg);
1963 else
1964 for Index in Names'Range loop
1965 if Names (Index) = Chars (Arg) then
1966 if Present (Args (Index)) then
1967 Error_Pragma_Arg
1968 ("duplicate argument association for pragma%", Arg);
1969 else
1970 Args (Index) := Expression (Arg);
1971 exit;
1972 end if;
1973 end if;
1975 if Index = Names'Last then
1976 Error_Msg_Name_1 := Pname;
1977 Error_Msg_N ("pragma% does not allow & argument", Arg);
1979 -- Check for possible misspelling
1981 for Index1 in Names'Range loop
1982 if Is_Bad_Spelling_Of
1983 (Chars (Arg), Names (Index1))
1984 then
1985 Error_Msg_Name_1 := Names (Index1);
1986 Error_Msg_N -- CODEFIX
1987 ("\possible misspelling of%", Arg);
1988 exit;
1989 end if;
1990 end loop;
1992 raise Pragma_Exit;
1993 end if;
1994 end loop;
1995 end if;
1997 Next (Arg);
1998 end loop;
1999 end Gather_Associations;
2001 -----------------
2002 -- GNAT_Pragma --
2003 -----------------
2005 procedure GNAT_Pragma is
2006 begin
2007 Check_Restriction (No_Implementation_Pragmas, N);
2008 end GNAT_Pragma;
2010 --------------------------
2011 -- Is_Before_First_Decl --
2012 --------------------------
2014 function Is_Before_First_Decl
2015 (Pragma_Node : Node_Id;
2016 Decls : List_Id) return Boolean
2018 Item : Node_Id := First (Decls);
2020 begin
2021 -- Only other pragmas can come before this pragma
2023 loop
2024 if No (Item) or else Nkind (Item) /= N_Pragma then
2025 return False;
2027 elsif Item = Pragma_Node then
2028 return True;
2029 end if;
2031 Next (Item);
2032 end loop;
2033 end Is_Before_First_Decl;
2035 -----------------------------
2036 -- Is_Configuration_Pragma --
2037 -----------------------------
2039 -- A configuration pragma must appear in the context clause of a
2040 -- compilation unit, and only other pragmas may precede it. Note that
2041 -- the test below also permits use in a configuration pragma file.
2043 function Is_Configuration_Pragma return Boolean is
2044 Lis : constant List_Id := List_Containing (N);
2045 Par : constant Node_Id := Parent (N);
2046 Prg : Node_Id;
2048 begin
2049 -- If no parent, then we are in the configuration pragma file,
2050 -- so the placement is definitely appropriate.
2052 if No (Par) then
2053 return True;
2055 -- Otherwise we must be in the context clause of a compilation unit
2056 -- and the only thing allowed before us in the context list is more
2057 -- configuration pragmas.
2059 elsif Nkind (Par) = N_Compilation_Unit
2060 and then Context_Items (Par) = Lis
2061 then
2062 Prg := First (Lis);
2064 loop
2065 if Prg = N then
2066 return True;
2067 elsif Nkind (Prg) /= N_Pragma then
2068 return False;
2069 end if;
2071 Next (Prg);
2072 end loop;
2074 else
2075 return False;
2076 end if;
2077 end Is_Configuration_Pragma;
2079 --------------------------
2080 -- Is_In_Context_Clause --
2081 --------------------------
2083 function Is_In_Context_Clause return Boolean is
2084 Plist : List_Id;
2085 Parent_Node : Node_Id;
2087 begin
2088 if not Is_List_Member (N) then
2089 return False;
2091 else
2092 Plist := List_Containing (N);
2093 Parent_Node := Parent (Plist);
2095 if Parent_Node = Empty
2096 or else Nkind (Parent_Node) /= N_Compilation_Unit
2097 or else Context_Items (Parent_Node) /= Plist
2098 then
2099 return False;
2100 end if;
2101 end if;
2103 return True;
2104 end Is_In_Context_Clause;
2106 ---------------------------------
2107 -- Is_Static_String_Expression --
2108 ---------------------------------
2110 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2111 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2113 begin
2114 Analyze_And_Resolve (Argx);
2115 return Is_OK_Static_Expression (Argx)
2116 and then Nkind (Argx) = N_String_Literal;
2117 end Is_Static_String_Expression;
2119 ----------------------
2120 -- Pragma_Misplaced --
2121 ----------------------
2123 procedure Pragma_Misplaced is
2124 begin
2125 Error_Pragma ("incorrect placement of pragma%");
2126 end Pragma_Misplaced;
2128 ------------------------------------
2129 -- Process Atomic_Shared_Volatile --
2130 ------------------------------------
2132 procedure Process_Atomic_Shared_Volatile is
2133 E_Id : Node_Id;
2134 E : Entity_Id;
2135 D : Node_Id;
2136 K : Node_Kind;
2137 Utyp : Entity_Id;
2139 procedure Set_Atomic (E : Entity_Id);
2140 -- Set given type as atomic, and if no explicit alignment was given,
2141 -- set alignment to unknown, since back end knows what the alignment
2142 -- requirements are for atomic arrays. Note: this step is necessary
2143 -- for derived types.
2145 ----------------
2146 -- Set_Atomic --
2147 ----------------
2149 procedure Set_Atomic (E : Entity_Id) is
2150 begin
2151 Set_Is_Atomic (E);
2153 if not Has_Alignment_Clause (E) then
2154 Set_Alignment (E, Uint_0);
2155 end if;
2156 end Set_Atomic;
2158 -- Start of processing for Process_Atomic_Shared_Volatile
2160 begin
2161 Check_Ada_83_Warning;
2162 Check_No_Identifiers;
2163 Check_Arg_Count (1);
2164 Check_Arg_Is_Local_Name (Arg1);
2165 E_Id := Expression (Arg1);
2167 if Etype (E_Id) = Any_Type then
2168 return;
2169 end if;
2171 E := Entity (E_Id);
2172 D := Declaration_Node (E);
2173 K := Nkind (D);
2175 if Is_Type (E) then
2176 if Rep_Item_Too_Early (E, N)
2177 or else
2178 Rep_Item_Too_Late (E, N)
2179 then
2180 return;
2181 else
2182 Check_First_Subtype (Arg1);
2183 end if;
2185 if Prag_Id /= Pragma_Volatile then
2186 Set_Atomic (E);
2187 Set_Atomic (Underlying_Type (E));
2188 Set_Atomic (Base_Type (E));
2189 end if;
2191 -- Attribute belongs on the base type. If the view of the type is
2192 -- currently private, it also belongs on the underlying type.
2194 Set_Is_Volatile (Base_Type (E));
2195 Set_Is_Volatile (Underlying_Type (E));
2197 Set_Treat_As_Volatile (E);
2198 Set_Treat_As_Volatile (Underlying_Type (E));
2200 elsif K = N_Object_Declaration
2201 or else (K = N_Component_Declaration
2202 and then Original_Record_Component (E) = E)
2203 then
2204 if Rep_Item_Too_Late (E, N) then
2205 return;
2206 end if;
2208 if Prag_Id /= Pragma_Volatile then
2209 Set_Is_Atomic (E);
2211 -- If the object declaration has an explicit initialization, a
2212 -- temporary may have to be created to hold the expression, to
2213 -- ensure that access to the object remain atomic.
2215 if Nkind (Parent (E)) = N_Object_Declaration
2216 and then Present (Expression (Parent (E)))
2217 then
2218 Set_Has_Delayed_Freeze (E);
2219 end if;
2221 -- An interesting improvement here. If an object of type X is
2222 -- declared atomic, and the type X is not atomic, that's a
2223 -- pity, since it may not have appropriate alignment etc. We
2224 -- can rescue this in the special case where the object and
2225 -- type are in the same unit by just setting the type as
2226 -- atomic, so that the back end will process it as atomic.
2228 Utyp := Underlying_Type (Etype (E));
2230 if Present (Utyp)
2231 and then Sloc (E) > No_Location
2232 and then Sloc (Utyp) > No_Location
2233 and then
2234 Get_Source_File_Index (Sloc (E)) =
2235 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2236 then
2237 Set_Is_Atomic (Underlying_Type (Etype (E)));
2238 end if;
2239 end if;
2241 Set_Is_Volatile (E);
2242 Set_Treat_As_Volatile (E);
2244 else
2245 Error_Pragma_Arg
2246 ("inappropriate entity for pragma%", Arg1);
2247 end if;
2248 end Process_Atomic_Shared_Volatile;
2250 -------------------------------------------
2251 -- Process_Compile_Time_Warning_Or_Error --
2252 -------------------------------------------
2254 procedure Process_Compile_Time_Warning_Or_Error is
2255 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2257 begin
2258 Check_Arg_Count (2);
2259 Check_No_Identifiers;
2260 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2261 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2263 if Compile_Time_Known_Value (Arg1x) then
2264 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2265 declare
2266 Str : constant String_Id :=
2267 Strval (Get_Pragma_Arg (Arg2));
2268 Len : constant Int := String_Length (Str);
2269 Cont : Boolean;
2270 Ptr : Nat;
2271 CC : Char_Code;
2272 C : Character;
2273 Cent : constant Entity_Id :=
2274 Cunit_Entity (Current_Sem_Unit);
2276 Force : constant Boolean :=
2277 Prag_Id = Pragma_Compile_Time_Warning
2278 and then
2279 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2280 and then (Ekind (Cent) /= E_Package
2281 or else not In_Private_Part (Cent));
2282 -- Set True if this is the warning case, and we are in the
2283 -- visible part of a package spec, or in a subprogram spec,
2284 -- in which case we want to force the client to see the
2285 -- warning, even though it is not in the main unit.
2287 begin
2288 -- Loop through segments of message separated by line feeds.
2289 -- We output these segments as separate messages with
2290 -- continuation marks for all but the first.
2292 Cont := False;
2293 Ptr := 1;
2294 loop
2295 Error_Msg_Strlen := 0;
2297 -- Loop to copy characters from argument to error message
2298 -- string buffer.
2300 loop
2301 exit when Ptr > Len;
2302 CC := Get_String_Char (Str, Ptr);
2303 Ptr := Ptr + 1;
2305 -- Ignore wide chars ??? else store character
2307 if In_Character_Range (CC) then
2308 C := Get_Character (CC);
2309 exit when C = ASCII.LF;
2310 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2311 Error_Msg_String (Error_Msg_Strlen) := C;
2312 end if;
2313 end loop;
2315 -- Here with one line ready to go
2317 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2319 -- If this is a warning in a spec, then we want clients
2320 -- to see the warning, so mark the message with the
2321 -- special sequence !! to force the warning. In the case
2322 -- of a package spec, we do not force this if we are in
2323 -- the private part of the spec.
2325 if Force then
2326 if Cont = False then
2327 Error_Msg_N ("<~!!", Arg1);
2328 Cont := True;
2329 else
2330 Error_Msg_N ("\<~!!", Arg1);
2331 end if;
2333 -- Error, rather than warning, or in a body, so we do not
2334 -- need to force visibility for client (error will be
2335 -- output in any case, and this is the situation in which
2336 -- we do not want a client to get a warning, since the
2337 -- warning is in the body or the spec private part.
2339 else
2340 if Cont = False then
2341 Error_Msg_N ("<~", Arg1);
2342 Cont := True;
2343 else
2344 Error_Msg_N ("\<~", Arg1);
2345 end if;
2346 end if;
2348 exit when Ptr > Len;
2349 end loop;
2350 end;
2351 end if;
2352 end if;
2353 end Process_Compile_Time_Warning_Or_Error;
2355 ------------------------
2356 -- Process_Convention --
2357 ------------------------
2359 procedure Process_Convention
2360 (C : out Convention_Id;
2361 Ent : out Entity_Id)
2363 Id : Node_Id;
2364 E : Entity_Id;
2365 E1 : Entity_Id;
2366 Cname : Name_Id;
2367 Comp_Unit : Unit_Number_Type;
2369 procedure Set_Convention_From_Pragma (E : Entity_Id);
2370 -- Set convention in entity E, and also flag that the entity has a
2371 -- convention pragma. If entity is for a private or incomplete type,
2372 -- also set convention and flag on underlying type. This procedure
2373 -- also deals with the special case of C_Pass_By_Copy convention.
2375 --------------------------------
2376 -- Set_Convention_From_Pragma --
2377 --------------------------------
2379 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2380 begin
2381 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2382 -- for an overridden dispatching operation. Technically this is
2383 -- an amendment and should only be done in Ada 2005 mode. However,
2384 -- this is clearly a mistake, since the problem that is addressed
2385 -- by this AI is that there is a clear gap in the RM!
2387 if Is_Dispatching_Operation (E)
2388 and then Present (Overridden_Operation (E))
2389 and then C /= Convention (Overridden_Operation (E))
2390 then
2391 Error_Pragma_Arg
2392 ("cannot change convention for " &
2393 "overridden dispatching operation",
2394 Arg1);
2395 end if;
2397 -- Set the convention
2399 Set_Convention (E, C);
2400 Set_Has_Convention_Pragma (E);
2402 if Is_Incomplete_Or_Private_Type (E) then
2403 Set_Convention (Underlying_Type (E), C);
2404 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2405 end if;
2407 -- A class-wide type should inherit the convention of the specific
2408 -- root type (although this isn't specified clearly by the RM).
2410 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2411 Set_Convention (Class_Wide_Type (E), C);
2412 end if;
2414 -- If the entity is a record type, then check for special case of
2415 -- C_Pass_By_Copy, which is treated the same as C except that the
2416 -- special record flag is set. This convention is only permitted
2417 -- on record types (see AI95-00131).
2419 if Cname = Name_C_Pass_By_Copy then
2420 if Is_Record_Type (E) then
2421 Set_C_Pass_By_Copy (Base_Type (E));
2422 elsif Is_Incomplete_Or_Private_Type (E)
2423 and then Is_Record_Type (Underlying_Type (E))
2424 then
2425 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2426 else
2427 Error_Pragma_Arg
2428 ("C_Pass_By_Copy convention allowed only for record type",
2429 Arg2);
2430 end if;
2431 end if;
2433 -- If the entity is a derived boolean type, check for the special
2434 -- case of convention C, C++, or Fortran, where we consider any
2435 -- nonzero value to represent true.
2437 if Is_Discrete_Type (E)
2438 and then Root_Type (Etype (E)) = Standard_Boolean
2439 and then
2440 (C = Convention_C
2441 or else
2442 C = Convention_CPP
2443 or else
2444 C = Convention_Fortran)
2445 then
2446 Set_Nonzero_Is_True (Base_Type (E));
2447 end if;
2448 end Set_Convention_From_Pragma;
2450 -- Start of processing for Process_Convention
2452 begin
2453 Check_At_Least_N_Arguments (2);
2454 Check_Optional_Identifier (Arg1, Name_Convention);
2455 Check_Arg_Is_Identifier (Arg1);
2456 Cname := Chars (Expression (Arg1));
2458 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2459 -- tested again below to set the critical flag).
2460 if Cname = Name_C_Pass_By_Copy then
2461 C := Convention_C;
2463 -- Otherwise we must have something in the standard convention list
2465 elsif Is_Convention_Name (Cname) then
2466 C := Get_Convention_Id (Chars (Expression (Arg1)));
2468 -- In DEC VMS, it seems that there is an undocumented feature that
2469 -- any unrecognized convention is treated as the default, which for
2470 -- us is convention C. It does not seem so terrible to do this
2471 -- unconditionally, silently in the VMS case, and with a warning
2472 -- in the non-VMS case.
2474 else
2475 if Warn_On_Export_Import and not OpenVMS_On_Target then
2476 Error_Msg_N
2477 ("?unrecognized convention name, C assumed",
2478 Expression (Arg1));
2479 end if;
2481 C := Convention_C;
2482 end if;
2484 Check_Optional_Identifier (Arg2, Name_Entity);
2485 Check_Arg_Is_Local_Name (Arg2);
2487 Id := Expression (Arg2);
2488 Analyze (Id);
2490 if not Is_Entity_Name (Id) then
2491 Error_Pragma_Arg ("entity name required", Arg2);
2492 end if;
2494 E := Entity (Id);
2496 -- Set entity to return
2498 Ent := E;
2500 -- Go to renamed subprogram if present, since convention applies to
2501 -- the actual renamed entity, not to the renaming entity. If the
2502 -- subprogram is inherited, go to parent subprogram.
2504 if Is_Subprogram (E)
2505 and then Present (Alias (E))
2506 then
2507 if Nkind (Parent (Declaration_Node (E))) =
2508 N_Subprogram_Renaming_Declaration
2509 then
2510 if Scope (E) /= Scope (Alias (E)) then
2511 Error_Pragma_Ref
2512 ("cannot apply pragma% to non-local entity&#", E);
2513 end if;
2515 E := Alias (E);
2517 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
2518 N_Private_Extension_Declaration)
2519 and then Scope (E) = Scope (Alias (E))
2520 then
2521 E := Alias (E);
2523 -- Return the parent subprogram the entity was inherited from
2525 Ent := E;
2526 end if;
2527 end if;
2529 -- Check that we are not applying this to a specless body
2531 if Is_Subprogram (E)
2532 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2533 then
2534 Error_Pragma
2535 ("pragma% requires separate spec and must come before body");
2536 end if;
2538 -- Check that we are not applying this to a named constant
2540 if Ekind (E) = E_Named_Integer
2541 or else
2542 Ekind (E) = E_Named_Real
2543 then
2544 Error_Msg_Name_1 := Pname;
2545 Error_Msg_N
2546 ("cannot apply pragma% to named constant!",
2547 Get_Pragma_Arg (Arg2));
2548 Error_Pragma_Arg
2549 ("\supply appropriate type for&!", Arg2);
2550 end if;
2552 if Ekind (E) = E_Enumeration_Literal then
2553 Error_Pragma ("enumeration literal not allowed for pragma%");
2554 end if;
2556 -- Check for rep item appearing too early or too late
2558 if Etype (E) = Any_Type
2559 or else Rep_Item_Too_Early (E, N)
2560 then
2561 raise Pragma_Exit;
2562 else
2563 E := Underlying_Type (E);
2564 end if;
2566 if Rep_Item_Too_Late (E, N) then
2567 raise Pragma_Exit;
2568 end if;
2570 if Has_Convention_Pragma (E) then
2571 Error_Pragma_Arg
2572 ("at most one Convention/Export/Import pragma is allowed", Arg2);
2574 elsif Convention (E) = Convention_Protected
2575 or else Ekind (Scope (E)) = E_Protected_Type
2576 then
2577 Error_Pragma_Arg
2578 ("a protected operation cannot be given a different convention",
2579 Arg2);
2580 end if;
2582 -- For Intrinsic, a subprogram is required
2584 if C = Convention_Intrinsic
2585 and then not Is_Subprogram (E)
2586 and then not Is_Generic_Subprogram (E)
2587 then
2588 Error_Pragma_Arg
2589 ("second argument of pragma% must be a subprogram", Arg2);
2590 end if;
2592 -- For Stdcall, a subprogram, variable or subprogram type is required
2594 if C = Convention_Stdcall
2595 and then not Is_Subprogram (E)
2596 and then not Is_Generic_Subprogram (E)
2597 and then Ekind (E) /= E_Variable
2598 and then not
2599 (Is_Access_Type (E)
2600 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2601 then
2602 Error_Pragma_Arg
2603 ("second argument of pragma% must be subprogram (type)",
2604 Arg2);
2605 end if;
2607 if not Is_Subprogram (E)
2608 and then not Is_Generic_Subprogram (E)
2609 then
2610 Set_Convention_From_Pragma (E);
2612 if Is_Type (E) then
2614 Check_First_Subtype (Arg2);
2615 Set_Convention_From_Pragma (Base_Type (E));
2617 -- For subprograms, we must set the convention on the
2618 -- internally generated directly designated type as well.
2620 if Ekind (E) = E_Access_Subprogram_Type then
2621 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2622 end if;
2623 end if;
2625 -- For the subprogram case, set proper convention for all homonyms
2626 -- in same scope and the same declarative part, i.e. the same
2627 -- compilation unit.
2629 else
2630 Comp_Unit := Get_Source_Unit (E);
2631 Set_Convention_From_Pragma (E);
2633 -- Treat a pragma Import as an implicit body, for GPS use
2635 if Prag_Id = Pragma_Import then
2636 Generate_Reference (E, Id, 'b');
2637 end if;
2639 -- Loop through the homonyms of the pragma argument's entity
2641 E1 := Ent;
2642 loop
2643 E1 := Homonym (E1);
2644 exit when No (E1) or else Scope (E1) /= Current_Scope;
2646 -- Do not set the pragma on inherited operations or on formal
2647 -- subprograms.
2649 if Comes_From_Source (E1)
2650 and then Comp_Unit = Get_Source_Unit (E1)
2651 and then not Is_Formal_Subprogram (E1)
2652 and then Nkind (Original_Node (Parent (E1))) /=
2653 N_Full_Type_Declaration
2654 then
2655 if Present (Alias (E1))
2656 and then Scope (E1) /= Scope (Alias (E1))
2657 then
2658 Error_Pragma_Ref
2659 ("cannot apply pragma% to non-local entity& declared#",
2660 E1);
2661 end if;
2663 Set_Convention_From_Pragma (E1);
2665 if Prag_Id = Pragma_Import then
2666 Generate_Reference (E1, Id, 'b');
2667 end if;
2668 end if;
2669 end loop;
2670 end if;
2671 end Process_Convention;
2673 -----------------------------------------------------
2674 -- Process_Extended_Import_Export_Exception_Pragma --
2675 -----------------------------------------------------
2677 procedure Process_Extended_Import_Export_Exception_Pragma
2678 (Arg_Internal : Node_Id;
2679 Arg_External : Node_Id;
2680 Arg_Form : Node_Id;
2681 Arg_Code : Node_Id)
2683 Def_Id : Entity_Id;
2684 Code_Val : Uint;
2686 begin
2687 if not OpenVMS_On_Target then
2688 Error_Pragma
2689 ("?pragma% ignored (applies only to Open'V'M'S)");
2690 end if;
2692 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2693 Def_Id := Entity (Arg_Internal);
2695 if Ekind (Def_Id) /= E_Exception then
2696 Error_Pragma_Arg
2697 ("pragma% must refer to declared exception", Arg_Internal);
2698 end if;
2700 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2702 if Present (Arg_Form) then
2703 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2704 end if;
2706 if Present (Arg_Form)
2707 and then Chars (Arg_Form) = Name_Ada
2708 then
2709 null;
2710 else
2711 Set_Is_VMS_Exception (Def_Id);
2712 Set_Exception_Code (Def_Id, No_Uint);
2713 end if;
2715 if Present (Arg_Code) then
2716 if not Is_VMS_Exception (Def_Id) then
2717 Error_Pragma_Arg
2718 ("Code option for pragma% not allowed for Ada case",
2719 Arg_Code);
2720 end if;
2722 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2723 Code_Val := Expr_Value (Arg_Code);
2725 if not UI_Is_In_Int_Range (Code_Val) then
2726 Error_Pragma_Arg
2727 ("Code option for pragma% must be in 32-bit range",
2728 Arg_Code);
2730 else
2731 Set_Exception_Code (Def_Id, Code_Val);
2732 end if;
2733 end if;
2734 end Process_Extended_Import_Export_Exception_Pragma;
2736 -------------------------------------------------
2737 -- Process_Extended_Import_Export_Internal_Arg --
2738 -------------------------------------------------
2740 procedure Process_Extended_Import_Export_Internal_Arg
2741 (Arg_Internal : Node_Id := Empty)
2743 begin
2744 if No (Arg_Internal) then
2745 Error_Pragma ("Internal parameter required for pragma%");
2746 end if;
2748 if Nkind (Arg_Internal) = N_Identifier then
2749 null;
2751 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2752 and then (Prag_Id = Pragma_Import_Function
2753 or else
2754 Prag_Id = Pragma_Export_Function)
2755 then
2756 null;
2758 else
2759 Error_Pragma_Arg
2760 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2761 end if;
2763 Check_Arg_Is_Local_Name (Arg_Internal);
2764 end Process_Extended_Import_Export_Internal_Arg;
2766 --------------------------------------------------
2767 -- Process_Extended_Import_Export_Object_Pragma --
2768 --------------------------------------------------
2770 procedure Process_Extended_Import_Export_Object_Pragma
2771 (Arg_Internal : Node_Id;
2772 Arg_External : Node_Id;
2773 Arg_Size : Node_Id)
2775 Def_Id : Entity_Id;
2777 begin
2778 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2779 Def_Id := Entity (Arg_Internal);
2781 if Ekind (Def_Id) /= E_Constant
2782 and then Ekind (Def_Id) /= E_Variable
2783 then
2784 Error_Pragma_Arg
2785 ("pragma% must designate an object", Arg_Internal);
2786 end if;
2788 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2789 or else
2790 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2791 then
2792 Error_Pragma_Arg
2793 ("previous Common/Psect_Object applies, pragma % not permitted",
2794 Arg_Internal);
2795 end if;
2797 if Rep_Item_Too_Late (Def_Id, N) then
2798 raise Pragma_Exit;
2799 end if;
2801 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2803 if Present (Arg_Size) then
2804 Check_Arg_Is_External_Name (Arg_Size);
2805 end if;
2807 -- Export_Object case
2809 if Prag_Id = Pragma_Export_Object then
2810 if not Is_Library_Level_Entity (Def_Id) then
2811 Error_Pragma_Arg
2812 ("argument for pragma% must be library level entity",
2813 Arg_Internal);
2814 end if;
2816 if Ekind (Current_Scope) = E_Generic_Package then
2817 Error_Pragma ("pragma& cannot appear in a generic unit");
2818 end if;
2820 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2821 Error_Pragma_Arg
2822 ("exported object must have compile time known size",
2823 Arg_Internal);
2824 end if;
2826 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2827 Error_Msg_N ("?duplicate Export_Object pragma", N);
2828 else
2829 Set_Exported (Def_Id, Arg_Internal);
2830 end if;
2832 -- Import_Object case
2834 else
2835 if Is_Concurrent_Type (Etype (Def_Id)) then
2836 Error_Pragma_Arg
2837 ("cannot use pragma% for task/protected object",
2838 Arg_Internal);
2839 end if;
2841 if Ekind (Def_Id) = E_Constant then
2842 Error_Pragma_Arg
2843 ("cannot import a constant", Arg_Internal);
2844 end if;
2846 if Warn_On_Export_Import
2847 and then Has_Discriminants (Etype (Def_Id))
2848 then
2849 Error_Msg_N
2850 ("imported value must be initialized?", Arg_Internal);
2851 end if;
2853 if Warn_On_Export_Import
2854 and then Is_Access_Type (Etype (Def_Id))
2855 then
2856 Error_Pragma_Arg
2857 ("cannot import object of an access type?", Arg_Internal);
2858 end if;
2860 if Warn_On_Export_Import
2861 and then Is_Imported (Def_Id)
2862 then
2863 Error_Msg_N
2864 ("?duplicate Import_Object pragma", N);
2866 -- Check for explicit initialization present. Note that an
2867 -- initialization generated by the code generator, e.g. for an
2868 -- access type, does not count here.
2870 elsif Present (Expression (Parent (Def_Id)))
2871 and then
2872 Comes_From_Source
2873 (Original_Node (Expression (Parent (Def_Id))))
2874 then
2875 Error_Msg_Sloc := Sloc (Def_Id);
2876 Error_Pragma_Arg
2877 ("imported entities cannot be initialized (RM B.1(24))",
2878 "\no initialization allowed for & declared#", Arg1);
2879 else
2880 Set_Imported (Def_Id);
2881 Note_Possible_Modification (Arg_Internal, Sure => False);
2882 end if;
2883 end if;
2884 end Process_Extended_Import_Export_Object_Pragma;
2886 ------------------------------------------------------
2887 -- Process_Extended_Import_Export_Subprogram_Pragma --
2888 ------------------------------------------------------
2890 procedure Process_Extended_Import_Export_Subprogram_Pragma
2891 (Arg_Internal : Node_Id;
2892 Arg_External : Node_Id;
2893 Arg_Parameter_Types : Node_Id;
2894 Arg_Result_Type : Node_Id := Empty;
2895 Arg_Mechanism : Node_Id;
2896 Arg_Result_Mechanism : Node_Id := Empty;
2897 Arg_First_Optional_Parameter : Node_Id := Empty)
2899 Ent : Entity_Id;
2900 Def_Id : Entity_Id;
2901 Hom_Id : Entity_Id;
2902 Formal : Entity_Id;
2903 Ambiguous : Boolean;
2904 Match : Boolean;
2905 Dval : Node_Id;
2907 function Same_Base_Type
2908 (Ptype : Node_Id;
2909 Formal : Entity_Id) return Boolean;
2910 -- Determines if Ptype references the type of Formal. Note that only
2911 -- the base types need to match according to the spec. Ptype here is
2912 -- the argument from the pragma, which is either a type name, or an
2913 -- access attribute.
2915 --------------------
2916 -- Same_Base_Type --
2917 --------------------
2919 function Same_Base_Type
2920 (Ptype : Node_Id;
2921 Formal : Entity_Id) return Boolean
2923 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2924 Pref : Node_Id;
2926 begin
2927 -- Case where pragma argument is typ'Access
2929 if Nkind (Ptype) = N_Attribute_Reference
2930 and then Attribute_Name (Ptype) = Name_Access
2931 then
2932 Pref := Prefix (Ptype);
2933 Find_Type (Pref);
2935 if not Is_Entity_Name (Pref)
2936 or else Entity (Pref) = Any_Type
2937 then
2938 raise Pragma_Exit;
2939 end if;
2941 -- We have a match if the corresponding argument is of an
2942 -- anonymous access type, and its designated type matches the
2943 -- type of the prefix of the access attribute
2945 return Ekind (Ftyp) = E_Anonymous_Access_Type
2946 and then Base_Type (Entity (Pref)) =
2947 Base_Type (Etype (Designated_Type (Ftyp)));
2949 -- Case where pragma argument is a type name
2951 else
2952 Find_Type (Ptype);
2954 if not Is_Entity_Name (Ptype)
2955 or else Entity (Ptype) = Any_Type
2956 then
2957 raise Pragma_Exit;
2958 end if;
2960 -- We have a match if the corresponding argument is of the type
2961 -- given in the pragma (comparing base types)
2963 return Base_Type (Entity (Ptype)) = Ftyp;
2964 end if;
2965 end Same_Base_Type;
2967 -- Start of processing for
2968 -- Process_Extended_Import_Export_Subprogram_Pragma
2970 begin
2971 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2972 Ent := Empty;
2973 Ambiguous := False;
2975 -- Loop through homonyms (overloadings) of the entity
2977 Hom_Id := Entity (Arg_Internal);
2978 while Present (Hom_Id) loop
2979 Def_Id := Get_Base_Subprogram (Hom_Id);
2981 -- We need a subprogram in the current scope
2983 if not Is_Subprogram (Def_Id)
2984 or else Scope (Def_Id) /= Current_Scope
2985 then
2986 null;
2988 else
2989 Match := True;
2991 -- Pragma cannot apply to subprogram body
2993 if Is_Subprogram (Def_Id)
2994 and then Nkind (Parent (Declaration_Node (Def_Id))) =
2995 N_Subprogram_Body
2996 then
2997 Error_Pragma
2998 ("pragma% requires separate spec"
2999 & " and must come before body");
3000 end if;
3002 -- Test result type if given, note that the result type
3003 -- parameter can only be present for the function cases.
3005 if Present (Arg_Result_Type)
3006 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3007 then
3008 Match := False;
3010 elsif Etype (Def_Id) /= Standard_Void_Type
3011 and then
3012 (Pname = Name_Export_Procedure
3013 or else
3014 Pname = Name_Import_Procedure)
3015 then
3016 Match := False;
3018 -- Test parameter types if given. Note that this parameter
3019 -- has not been analyzed (and must not be, since it is
3020 -- semantic nonsense), so we get it as the parser left it.
3022 elsif Present (Arg_Parameter_Types) then
3023 Check_Matching_Types : declare
3024 Formal : Entity_Id;
3025 Ptype : Node_Id;
3027 begin
3028 Formal := First_Formal (Def_Id);
3030 if Nkind (Arg_Parameter_Types) = N_Null then
3031 if Present (Formal) then
3032 Match := False;
3033 end if;
3035 -- A list of one type, e.g. (List) is parsed as
3036 -- a parenthesized expression.
3038 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3039 and then Paren_Count (Arg_Parameter_Types) = 1
3040 then
3041 if No (Formal)
3042 or else Present (Next_Formal (Formal))
3043 then
3044 Match := False;
3045 else
3046 Match :=
3047 Same_Base_Type (Arg_Parameter_Types, Formal);
3048 end if;
3050 -- A list of more than one type is parsed as a aggregate
3052 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3053 and then Paren_Count (Arg_Parameter_Types) = 0
3054 then
3055 Ptype := First (Expressions (Arg_Parameter_Types));
3056 while Present (Ptype) or else Present (Formal) loop
3057 if No (Ptype)
3058 or else No (Formal)
3059 or else not Same_Base_Type (Ptype, Formal)
3060 then
3061 Match := False;
3062 exit;
3063 else
3064 Next_Formal (Formal);
3065 Next (Ptype);
3066 end if;
3067 end loop;
3069 -- Anything else is of the wrong form
3071 else
3072 Error_Pragma_Arg
3073 ("wrong form for Parameter_Types parameter",
3074 Arg_Parameter_Types);
3075 end if;
3076 end Check_Matching_Types;
3077 end if;
3079 -- Match is now False if the entry we found did not match
3080 -- either a supplied Parameter_Types or Result_Types argument
3082 if Match then
3083 if No (Ent) then
3084 Ent := Def_Id;
3086 -- Ambiguous case, the flag Ambiguous shows if we already
3087 -- detected this and output the initial messages.
3089 else
3090 if not Ambiguous then
3091 Ambiguous := True;
3092 Error_Msg_Name_1 := Pname;
3093 Error_Msg_N
3094 ("pragma% does not uniquely identify subprogram!",
3096 Error_Msg_Sloc := Sloc (Ent);
3097 Error_Msg_N ("matching subprogram #!", N);
3098 Ent := Empty;
3099 end if;
3101 Error_Msg_Sloc := Sloc (Def_Id);
3102 Error_Msg_N ("matching subprogram #!", N);
3103 end if;
3104 end if;
3105 end if;
3107 Hom_Id := Homonym (Hom_Id);
3108 end loop;
3110 -- See if we found an entry
3112 if No (Ent) then
3113 if not Ambiguous then
3114 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3115 Error_Pragma
3116 ("pragma% cannot be given for generic subprogram");
3117 else
3118 Error_Pragma
3119 ("pragma% does not identify local subprogram");
3120 end if;
3121 end if;
3123 return;
3124 end if;
3126 -- Import pragmas must be for imported entities
3128 if Prag_Id = Pragma_Import_Function
3129 or else
3130 Prag_Id = Pragma_Import_Procedure
3131 or else
3132 Prag_Id = Pragma_Import_Valued_Procedure
3133 then
3134 if not Is_Imported (Ent) then
3135 Error_Pragma -- CODEFIX???
3136 ("pragma Import or Interface must precede pragma%");
3137 end if;
3139 -- Here we have the Export case which can set the entity as exported
3141 -- But does not do so if the specified external name is null, since
3142 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3143 -- compatible) to request no external name.
3145 elsif Nkind (Arg_External) = N_String_Literal
3146 and then String_Length (Strval (Arg_External)) = 0
3147 then
3148 null;
3150 -- In all other cases, set entity as exported
3152 else
3153 Set_Exported (Ent, Arg_Internal);
3154 end if;
3156 -- Special processing for Valued_Procedure cases
3158 if Prag_Id = Pragma_Import_Valued_Procedure
3159 or else
3160 Prag_Id = Pragma_Export_Valued_Procedure
3161 then
3162 Formal := First_Formal (Ent);
3164 if No (Formal) then
3165 Error_Pragma ("at least one parameter required for pragma%");
3167 elsif Ekind (Formal) /= E_Out_Parameter then
3168 Error_Pragma ("first parameter must have mode out for pragma%");
3170 else
3171 Set_Is_Valued_Procedure (Ent);
3172 end if;
3173 end if;
3175 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3177 -- Process Result_Mechanism argument if present. We have already
3178 -- checked that this is only allowed for the function case.
3180 if Present (Arg_Result_Mechanism) then
3181 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3182 end if;
3184 -- Process Mechanism parameter if present. Note that this parameter
3185 -- is not analyzed, and must not be analyzed since it is semantic
3186 -- nonsense, so we get it in exactly as the parser left it.
3188 if Present (Arg_Mechanism) then
3189 declare
3190 Formal : Entity_Id;
3191 Massoc : Node_Id;
3192 Mname : Node_Id;
3193 Choice : Node_Id;
3195 begin
3196 -- A single mechanism association without a formal parameter
3197 -- name is parsed as a parenthesized expression. All other
3198 -- cases are parsed as aggregates, so we rewrite the single
3199 -- parameter case as an aggregate for consistency.
3201 if Nkind (Arg_Mechanism) /= N_Aggregate
3202 and then Paren_Count (Arg_Mechanism) = 1
3203 then
3204 Rewrite (Arg_Mechanism,
3205 Make_Aggregate (Sloc (Arg_Mechanism),
3206 Expressions => New_List (
3207 Relocate_Node (Arg_Mechanism))));
3208 end if;
3210 -- Case of only mechanism name given, applies to all formals
3212 if Nkind (Arg_Mechanism) /= N_Aggregate then
3213 Formal := First_Formal (Ent);
3214 while Present (Formal) loop
3215 Set_Mechanism_Value (Formal, Arg_Mechanism);
3216 Next_Formal (Formal);
3217 end loop;
3219 -- Case of list of mechanism associations given
3221 else
3222 if Null_Record_Present (Arg_Mechanism) then
3223 Error_Pragma_Arg
3224 ("inappropriate form for Mechanism parameter",
3225 Arg_Mechanism);
3226 end if;
3228 -- Deal with positional ones first
3230 Formal := First_Formal (Ent);
3232 if Present (Expressions (Arg_Mechanism)) then
3233 Mname := First (Expressions (Arg_Mechanism));
3234 while Present (Mname) loop
3235 if No (Formal) then
3236 Error_Pragma_Arg
3237 ("too many mechanism associations", Mname);
3238 end if;
3240 Set_Mechanism_Value (Formal, Mname);
3241 Next_Formal (Formal);
3242 Next (Mname);
3243 end loop;
3244 end if;
3246 -- Deal with named entries
3248 if Present (Component_Associations (Arg_Mechanism)) then
3249 Massoc := First (Component_Associations (Arg_Mechanism));
3250 while Present (Massoc) loop
3251 Choice := First (Choices (Massoc));
3253 if Nkind (Choice) /= N_Identifier
3254 or else Present (Next (Choice))
3255 then
3256 Error_Pragma_Arg
3257 ("incorrect form for mechanism association",
3258 Massoc);
3259 end if;
3261 Formal := First_Formal (Ent);
3262 loop
3263 if No (Formal) then
3264 Error_Pragma_Arg
3265 ("parameter name & not present", Choice);
3266 end if;
3268 if Chars (Choice) = Chars (Formal) then
3269 Set_Mechanism_Value
3270 (Formal, Expression (Massoc));
3272 -- Set entity on identifier for ASIS
3274 Set_Entity (Choice, Formal);
3276 exit;
3277 end if;
3279 Next_Formal (Formal);
3280 end loop;
3282 Next (Massoc);
3283 end loop;
3284 end if;
3285 end if;
3286 end;
3287 end if;
3289 -- Process First_Optional_Parameter argument if present. We have
3290 -- already checked that this is only allowed for the Import case.
3292 if Present (Arg_First_Optional_Parameter) then
3293 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3294 Error_Pragma_Arg
3295 ("first optional parameter must be formal parameter name",
3296 Arg_First_Optional_Parameter);
3297 end if;
3299 Formal := First_Formal (Ent);
3300 loop
3301 if No (Formal) then
3302 Error_Pragma_Arg
3303 ("specified formal parameter& not found",
3304 Arg_First_Optional_Parameter);
3305 end if;
3307 exit when Chars (Formal) =
3308 Chars (Arg_First_Optional_Parameter);
3310 Next_Formal (Formal);
3311 end loop;
3313 Set_First_Optional_Parameter (Ent, Formal);
3315 -- Check specified and all remaining formals have right form
3317 while Present (Formal) loop
3318 if Ekind (Formal) /= E_In_Parameter then
3319 Error_Msg_NE
3320 ("optional formal& is not of mode in!",
3321 Arg_First_Optional_Parameter, Formal);
3323 else
3324 Dval := Default_Value (Formal);
3326 if No (Dval) then
3327 Error_Msg_NE
3328 ("optional formal& does not have default value!",
3329 Arg_First_Optional_Parameter, Formal);
3331 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3332 null;
3334 else
3335 Error_Msg_FE
3336 ("default value for optional formal& is non-static!",
3337 Arg_First_Optional_Parameter, Formal);
3338 end if;
3339 end if;
3341 Set_Is_Optional_Parameter (Formal);
3342 Next_Formal (Formal);
3343 end loop;
3344 end if;
3345 end Process_Extended_Import_Export_Subprogram_Pragma;
3347 --------------------------
3348 -- Process_Generic_List --
3349 --------------------------
3351 procedure Process_Generic_List is
3352 Arg : Node_Id;
3353 Exp : Node_Id;
3355 begin
3356 Check_No_Identifiers;
3357 Check_At_Least_N_Arguments (1);
3359 Arg := Arg1;
3360 while Present (Arg) loop
3361 Exp := Expression (Arg);
3362 Analyze (Exp);
3364 if not Is_Entity_Name (Exp)
3365 or else
3366 (not Is_Generic_Instance (Entity (Exp))
3367 and then
3368 not Is_Generic_Unit (Entity (Exp)))
3369 then
3370 Error_Pragma_Arg
3371 ("pragma% argument must be name of generic unit/instance",
3372 Arg);
3373 end if;
3375 Next (Arg);
3376 end loop;
3377 end Process_Generic_List;
3379 ---------------------------------
3380 -- Process_Import_Or_Interface --
3381 ---------------------------------
3383 procedure Process_Import_Or_Interface is
3384 C : Convention_Id;
3385 Def_Id : Entity_Id;
3386 Hom_Id : Entity_Id;
3388 begin
3389 Process_Convention (C, Def_Id);
3390 Kill_Size_Check_Code (Def_Id);
3391 Note_Possible_Modification (Expression (Arg2), Sure => False);
3393 if Ekind (Def_Id) = E_Variable
3394 or else
3395 Ekind (Def_Id) = E_Constant
3396 then
3397 -- We do not permit Import to apply to a renaming declaration
3399 if Present (Renamed_Object (Def_Id)) then
3400 Error_Pragma_Arg
3401 ("pragma% not allowed for object renaming", Arg2);
3403 -- User initialization is not allowed for imported object, but
3404 -- the object declaration may contain a default initialization,
3405 -- that will be discarded. Note that an explicit initialization
3406 -- only counts if it comes from source, otherwise it is simply
3407 -- the code generator making an implicit initialization explicit.
3409 elsif Present (Expression (Parent (Def_Id)))
3410 and then Comes_From_Source (Expression (Parent (Def_Id)))
3411 then
3412 Error_Msg_Sloc := Sloc (Def_Id);
3413 Error_Pragma_Arg
3414 ("no initialization allowed for declaration of& #",
3415 "\imported entities cannot be initialized (RM B.1(24))",
3416 Arg2);
3418 else
3419 Set_Imported (Def_Id);
3420 Process_Interface_Name (Def_Id, Arg3, Arg4);
3422 -- Note that we do not set Is_Public here. That's because we
3423 -- only want to set it if there is no address clause, and we
3424 -- don't know that yet, so we delay that processing till
3425 -- freeze time.
3427 -- pragma Import completes deferred constants
3429 if Ekind (Def_Id) = E_Constant then
3430 Set_Has_Completion (Def_Id);
3431 end if;
3433 -- It is not possible to import a constant of an unconstrained
3434 -- array type (e.g. string) because there is no simple way to
3435 -- write a meaningful subtype for it.
3437 if Is_Array_Type (Etype (Def_Id))
3438 and then not Is_Constrained (Etype (Def_Id))
3439 then
3440 Error_Msg_NE
3441 ("imported constant& must have a constrained subtype",
3442 N, Def_Id);
3443 end if;
3444 end if;
3446 elsif Is_Subprogram (Def_Id)
3447 or else Is_Generic_Subprogram (Def_Id)
3448 then
3449 -- If the name is overloaded, pragma applies to all of the
3450 -- denoted entities in the same declarative part.
3452 Hom_Id := Def_Id;
3453 while Present (Hom_Id) loop
3454 Def_Id := Get_Base_Subprogram (Hom_Id);
3456 -- Ignore inherited subprograms because the pragma will
3457 -- apply to the parent operation, which is the one called.
3459 if Is_Overloadable (Def_Id)
3460 and then Present (Alias (Def_Id))
3461 then
3462 null;
3464 -- If it is not a subprogram, it must be in an outer scope and
3465 -- pragma does not apply.
3467 elsif not Is_Subprogram (Def_Id)
3468 and then not Is_Generic_Subprogram (Def_Id)
3469 then
3470 null;
3472 -- Verify that the homonym is in the same declarative part (not
3473 -- just the same scope).
3475 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3476 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3477 then
3478 exit;
3480 else
3481 Set_Imported (Def_Id);
3483 -- Reject an Import applied to an abstract subprogram
3485 if Is_Subprogram (Def_Id)
3486 and then Is_Abstract_Subprogram (Def_Id)
3487 then
3488 Error_Msg_Sloc := Sloc (Def_Id);
3489 Error_Msg_NE
3490 ("cannot import abstract subprogram& declared#",
3491 Arg2, Def_Id);
3492 end if;
3494 -- Special processing for Convention_Intrinsic
3496 if C = Convention_Intrinsic then
3498 -- Link_Name argument not allowed for intrinsic
3500 if Present (Arg3)
3501 and then Chars (Arg3) = Name_Link_Name
3502 then
3503 Arg4 := Arg3;
3504 end if;
3506 if Present (Arg4) then
3507 Error_Pragma_Arg
3508 ("Link_Name argument not allowed for " &
3509 "Import Intrinsic",
3510 Arg4);
3511 end if;
3513 Set_Is_Intrinsic_Subprogram (Def_Id);
3515 -- If no external name is present, then check that this
3516 -- is a valid intrinsic subprogram. If an external name
3517 -- is present, then this is handled by the back end.
3519 if No (Arg3) then
3520 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3521 end if;
3522 end if;
3524 -- All interfaced procedures need an external symbol created
3525 -- for them since they are always referenced from another
3526 -- object file.
3528 Set_Is_Public (Def_Id);
3530 -- Verify that the subprogram does not have a completion
3531 -- through a renaming declaration. For other completions the
3532 -- pragma appears as a too late representation.
3534 declare
3535 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3537 begin
3538 if Present (Decl)
3539 and then Nkind (Decl) = N_Subprogram_Declaration
3540 and then Present (Corresponding_Body (Decl))
3541 and then Nkind (Unit_Declaration_Node
3542 (Corresponding_Body (Decl))) =
3543 N_Subprogram_Renaming_Declaration
3544 then
3545 Error_Msg_Sloc := Sloc (Def_Id);
3546 Error_Msg_NE
3547 ("cannot import&, renaming already provided for " &
3548 "declaration #", N, Def_Id);
3549 end if;
3550 end;
3552 Set_Has_Completion (Def_Id);
3553 Process_Interface_Name (Def_Id, Arg3, Arg4);
3554 end if;
3556 if Is_Compilation_Unit (Hom_Id) then
3558 -- Its possible homonyms are not affected by the pragma.
3559 -- Such homonyms might be present in the context of other
3560 -- units being compiled.
3562 exit;
3564 else
3565 Hom_Id := Homonym (Hom_Id);
3566 end if;
3567 end loop;
3569 -- When the convention is Java or CIL, we also allow Import to be
3570 -- given for packages, generic packages, exceptions, record
3571 -- components, and access to subprograms.
3573 elsif (C = Convention_Java or else C = Convention_CIL)
3574 and then
3575 (Is_Package_Or_Generic_Package (Def_Id)
3576 or else Ekind (Def_Id) = E_Exception
3577 or else Ekind (Def_Id) = E_Access_Subprogram_Type
3578 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3579 then
3580 Set_Imported (Def_Id);
3581 Set_Is_Public (Def_Id);
3582 Process_Interface_Name (Def_Id, Arg3, Arg4);
3584 -- Import a CPP class
3586 elsif Is_Record_Type (Def_Id)
3587 and then C = Convention_CPP
3588 then
3589 -- Types treated as CPP classes are treated as limited, but we
3590 -- don't require them to be declared this way. A warning is
3591 -- issued to encourage the user to declare them as limited.
3592 -- This is not an error, for compatibility reasons, because
3593 -- these types have been supported this way for some time.
3595 if not Is_Limited_Type (Def_Id) then
3596 Error_Msg_N
3597 ("imported 'C'P'P type should be " &
3598 "explicitly declared limited?",
3599 Get_Pragma_Arg (Arg2));
3600 Error_Msg_N
3601 ("\type will be considered limited",
3602 Get_Pragma_Arg (Arg2));
3603 end if;
3605 Set_Is_CPP_Class (Def_Id);
3606 Set_Is_Limited_Record (Def_Id);
3608 -- Imported CPP types must not have discriminants (because C++
3609 -- classes do not have discriminants).
3611 if Has_Discriminants (Def_Id) then
3612 Error_Msg_N
3613 ("imported 'C'P'P type cannot have discriminants",
3614 First (Discriminant_Specifications
3615 (Declaration_Node (Def_Id))));
3616 end if;
3618 -- Components of imported CPP types must not have default
3619 -- expressions because the constructor (if any) is on the
3620 -- C++ side.
3622 declare
3623 Tdef : constant Node_Id :=
3624 Type_Definition (Declaration_Node (Def_Id));
3625 Clist : Node_Id;
3626 Comp : Node_Id;
3628 begin
3629 if Nkind (Tdef) = N_Record_Definition then
3630 Clist := Component_List (Tdef);
3632 else
3633 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
3634 Clist := Component_List (Record_Extension_Part (Tdef));
3635 end if;
3637 if Present (Clist) then
3638 Comp := First (Component_Items (Clist));
3639 while Present (Comp) loop
3640 if Present (Expression (Comp)) then
3641 Error_Msg_N
3642 ("component of imported 'C'P'P type cannot have" &
3643 " default expression", Expression (Comp));
3644 end if;
3646 Next (Comp);
3647 end loop;
3648 end if;
3649 end;
3651 else
3652 Error_Pragma_Arg
3653 ("second argument of pragma% must be object or subprogram",
3654 Arg2);
3655 end if;
3657 -- If this pragma applies to a compilation unit, then the unit, which
3658 -- is a subprogram, does not require (or allow) a body. We also do
3659 -- not need to elaborate imported procedures.
3661 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3662 declare
3663 Cunit : constant Node_Id := Parent (Parent (N));
3664 begin
3665 Set_Body_Required (Cunit, False);
3666 end;
3667 end if;
3668 end Process_Import_Or_Interface;
3670 --------------------
3671 -- Process_Inline --
3672 --------------------
3674 procedure Process_Inline (Active : Boolean) is
3675 Assoc : Node_Id;
3676 Decl : Node_Id;
3677 Subp_Id : Node_Id;
3678 Subp : Entity_Id;
3679 Applies : Boolean;
3680 Effective : Boolean := False;
3682 procedure Make_Inline (Subp : Entity_Id);
3683 -- Subp is the defining unit name of the subprogram declaration. Set
3684 -- the flag, as well as the flag in the corresponding body, if there
3685 -- is one present.
3687 procedure Set_Inline_Flags (Subp : Entity_Id);
3688 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
3689 -- Has_Pragma_Inline_Always for the Inline_Always case.
3691 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3692 -- Returns True if it can be determined at this stage that inlining
3693 -- is not possible, for example if the body is available and contains
3694 -- exception handlers, we prevent inlining, since otherwise we can
3695 -- get undefined symbols at link time. This function also emits a
3696 -- warning if front-end inlining is enabled and the pragma appears
3697 -- too late.
3699 -- ??? is business with link symbols still valid, or does it relate
3700 -- to front end ZCX which is being phased out ???
3702 ---------------------------
3703 -- Inlining_Not_Possible --
3704 ---------------------------
3706 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3707 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3708 Stats : Node_Id;
3710 begin
3711 if Nkind (Decl) = N_Subprogram_Body then
3712 Stats := Handled_Statement_Sequence (Decl);
3713 return Present (Exception_Handlers (Stats))
3714 or else Present (At_End_Proc (Stats));
3716 elsif Nkind (Decl) = N_Subprogram_Declaration
3717 and then Present (Corresponding_Body (Decl))
3718 then
3719 if Front_End_Inlining
3720 and then Analyzed (Corresponding_Body (Decl))
3721 then
3722 Error_Msg_N ("pragma appears too late, ignored?", N);
3723 return True;
3725 -- If the subprogram is a renaming as body, the body is just a
3726 -- call to the renamed subprogram, and inlining is trivially
3727 -- possible.
3729 elsif
3730 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
3731 N_Subprogram_Renaming_Declaration
3732 then
3733 return False;
3735 else
3736 Stats :=
3737 Handled_Statement_Sequence
3738 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3740 return
3741 Present (Exception_Handlers (Stats))
3742 or else Present (At_End_Proc (Stats));
3743 end if;
3745 else
3746 -- If body is not available, assume the best, the check is
3747 -- performed again when compiling enclosing package bodies.
3749 return False;
3750 end if;
3751 end Inlining_Not_Possible;
3753 -----------------
3754 -- Make_Inline --
3755 -----------------
3757 procedure Make_Inline (Subp : Entity_Id) is
3758 Kind : constant Entity_Kind := Ekind (Subp);
3759 Inner_Subp : Entity_Id := Subp;
3761 begin
3762 -- Ignore if bad type, avoid cascaded error
3764 if Etype (Subp) = Any_Type then
3765 Applies := True;
3766 return;
3768 -- Ignore if all inlining is suppressed
3770 elsif Suppress_All_Inlining then
3771 Applies := True;
3772 return;
3774 -- If inlining is not possible, for now do not treat as an error
3776 elsif Inlining_Not_Possible (Subp) then
3777 Applies := True;
3778 return;
3780 -- Here we have a candidate for inlining, but we must exclude
3781 -- derived operations. Otherwise we would end up trying to inline
3782 -- a phantom declaration, and the result would be to drag in a
3783 -- body which has no direct inlining associated with it. That
3784 -- would not only be inefficient but would also result in the
3785 -- backend doing cross-unit inlining in cases where it was
3786 -- definitely inappropriate to do so.
3788 -- However, a simple Comes_From_Source test is insufficient, since
3789 -- we do want to allow inlining of generic instances which also do
3790 -- not come from source. We also need to recognize specs generated
3791 -- by the front-end for bodies that carry the pragma. Finally,
3792 -- predefined operators do not come from source but are not
3793 -- inlineable either.
3795 elsif Is_Generic_Instance (Subp)
3796 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
3797 then
3798 null;
3800 elsif not Comes_From_Source (Subp)
3801 and then Scope (Subp) /= Standard_Standard
3802 then
3803 Applies := True;
3804 return;
3805 end if;
3807 -- The referenced entity must either be the enclosing entity, or
3808 -- an entity declared within the current open scope.
3810 if Present (Scope (Subp))
3811 and then Scope (Subp) /= Current_Scope
3812 and then Subp /= Current_Scope
3813 then
3814 Error_Pragma_Arg
3815 ("argument of% must be entity in current scope", Assoc);
3816 return;
3817 end if;
3819 -- Processing for procedure, operator or function. If subprogram
3820 -- is aliased (as for an instance) indicate that the renamed
3821 -- entity (if declared in the same unit) is inlined.
3823 if Is_Subprogram (Subp) then
3824 while Present (Alias (Inner_Subp)) loop
3825 Inner_Subp := Alias (Inner_Subp);
3826 end loop;
3828 if In_Same_Source_Unit (Subp, Inner_Subp) then
3829 Set_Inline_Flags (Inner_Subp);
3831 Decl := Parent (Parent (Inner_Subp));
3833 if Nkind (Decl) = N_Subprogram_Declaration
3834 and then Present (Corresponding_Body (Decl))
3835 then
3836 Set_Inline_Flags (Corresponding_Body (Decl));
3838 elsif Is_Generic_Instance (Subp) then
3840 -- Indicate that the body needs to be created for
3841 -- inlining subsequent calls. The instantiation node
3842 -- follows the declaration of the wrapper package
3843 -- created for it.
3845 if Scope (Subp) /= Standard_Standard
3846 and then
3847 Need_Subprogram_Instance_Body
3848 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
3849 Subp)
3850 then
3851 null;
3852 end if;
3853 end if;
3854 end if;
3856 Applies := True;
3858 -- For a generic subprogram set flag as well, for use at the point
3859 -- of instantiation, to determine whether the body should be
3860 -- generated.
3862 elsif Is_Generic_Subprogram (Subp) then
3863 Set_Inline_Flags (Subp);
3864 Applies := True;
3866 -- Literals are by definition inlined
3868 elsif Kind = E_Enumeration_Literal then
3869 null;
3871 -- Anything else is an error
3873 else
3874 Error_Pragma_Arg
3875 ("expect subprogram name for pragma%", Assoc);
3876 end if;
3877 end Make_Inline;
3879 ----------------------
3880 -- Set_Inline_Flags --
3881 ----------------------
3883 procedure Set_Inline_Flags (Subp : Entity_Id) is
3884 begin
3885 if Active then
3886 Set_Is_Inlined (Subp, True);
3887 end if;
3889 if not Has_Pragma_Inline (Subp) then
3890 Set_Has_Pragma_Inline (Subp);
3891 Effective := True;
3892 end if;
3894 if Prag_Id = Pragma_Inline_Always then
3895 Set_Has_Pragma_Inline_Always (Subp);
3896 end if;
3897 end Set_Inline_Flags;
3899 -- Start of processing for Process_Inline
3901 begin
3902 Check_No_Identifiers;
3903 Check_At_Least_N_Arguments (1);
3905 if Active then
3906 Inline_Processing_Required := True;
3907 end if;
3909 Assoc := Arg1;
3910 while Present (Assoc) loop
3911 Subp_Id := Expression (Assoc);
3912 Analyze (Subp_Id);
3913 Applies := False;
3915 if Is_Entity_Name (Subp_Id) then
3916 Subp := Entity (Subp_Id);
3918 if Subp = Any_Id then
3920 -- If previous error, avoid cascaded errors
3922 Applies := True;
3923 Effective := True;
3925 else
3926 Make_Inline (Subp);
3928 while Present (Homonym (Subp))
3929 and then Scope (Homonym (Subp)) = Current_Scope
3930 loop
3931 Make_Inline (Homonym (Subp));
3932 Subp := Homonym (Subp);
3933 end loop;
3934 end if;
3935 end if;
3937 if not Applies then
3938 Error_Pragma_Arg
3939 ("inappropriate argument for pragma%", Assoc);
3941 elsif not Effective
3942 and then Warn_On_Redundant_Constructs
3943 and then not Suppress_All_Inlining
3944 then
3945 if Inlining_Not_Possible (Subp) then
3946 Error_Msg_NE
3947 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
3948 else
3949 Error_Msg_NE
3950 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
3951 end if;
3952 end if;
3954 Next (Assoc);
3955 end loop;
3956 end Process_Inline;
3958 ----------------------------
3959 -- Process_Interface_Name --
3960 ----------------------------
3962 procedure Process_Interface_Name
3963 (Subprogram_Def : Entity_Id;
3964 Ext_Arg : Node_Id;
3965 Link_Arg : Node_Id)
3967 Ext_Nam : Node_Id;
3968 Link_Nam : Node_Id;
3969 String_Val : String_Id;
3971 procedure Check_Form_Of_Interface_Name
3972 (SN : Node_Id;
3973 Ext_Name_Case : Boolean);
3974 -- SN is a string literal node for an interface name. This routine
3975 -- performs some minimal checks that the name is reasonable. In
3976 -- particular that no spaces or other obviously incorrect characters
3977 -- appear. This is only a warning, since any characters are allowed.
3978 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
3980 ----------------------------------
3981 -- Check_Form_Of_Interface_Name --
3982 ----------------------------------
3984 procedure Check_Form_Of_Interface_Name
3985 (SN : Node_Id;
3986 Ext_Name_Case : Boolean)
3988 S : constant String_Id := Strval (Expr_Value_S (SN));
3989 SL : constant Nat := String_Length (S);
3990 C : Char_Code;
3992 begin
3993 if SL = 0 then
3994 Error_Msg_N ("interface name cannot be null string", SN);
3995 end if;
3997 for J in 1 .. SL loop
3998 C := Get_String_Char (S, J);
4000 -- Look for dubious character and issue unconditional warning.
4001 -- Definitely dubious if not in character range.
4003 if not In_Character_Range (C)
4005 -- For all cases except CLI target,
4006 -- commas, spaces and slashes are dubious (in CLI, we use
4007 -- commas and backslashes in external names to specify
4008 -- assembly version and public key, while slashes and spaces
4009 -- can be used in names to mark nested classes and
4010 -- valuetypes).
4012 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4013 and then (Get_Character (C) = ','
4014 or else
4015 Get_Character (C) = '\'))
4016 or else (VM_Target /= CLI_Target
4017 and then (Get_Character (C) = ' '
4018 or else
4019 Get_Character (C) = '/'))
4020 then
4021 Error_Msg
4022 ("?interface name contains illegal character",
4023 Sloc (SN) + Source_Ptr (J));
4024 end if;
4025 end loop;
4026 end Check_Form_Of_Interface_Name;
4028 -- Start of processing for Process_Interface_Name
4030 begin
4031 if No (Link_Arg) then
4032 if No (Ext_Arg) then
4033 if VM_Target = CLI_Target
4034 and then Ekind (Subprogram_Def) = E_Package
4035 and then Nkind (Parent (Subprogram_Def)) =
4036 N_Package_Specification
4037 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4038 then
4039 Set_Interface_Name
4040 (Subprogram_Def,
4041 Interface_Name
4042 (Generic_Parent (Parent (Subprogram_Def))));
4043 end if;
4045 return;
4047 elsif Chars (Ext_Arg) = Name_Link_Name then
4048 Ext_Nam := Empty;
4049 Link_Nam := Expression (Ext_Arg);
4051 else
4052 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4053 Ext_Nam := Expression (Ext_Arg);
4054 Link_Nam := Empty;
4055 end if;
4057 else
4058 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4059 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4060 Ext_Nam := Expression (Ext_Arg);
4061 Link_Nam := Expression (Link_Arg);
4062 end if;
4064 -- Check expressions for external name and link name are static
4066 if Present (Ext_Nam) then
4067 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4068 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4070 -- Verify that external name is not the name of a local entity,
4071 -- which would hide the imported one and could lead to run-time
4072 -- surprises. The problem can only arise for entities declared in
4073 -- a package body (otherwise the external name is fully qualified
4074 -- and will not conflict).
4076 declare
4077 Nam : Name_Id;
4078 E : Entity_Id;
4079 Par : Node_Id;
4081 begin
4082 if Prag_Id = Pragma_Import then
4083 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4084 Nam := Name_Find;
4085 E := Entity_Id (Get_Name_Table_Info (Nam));
4087 if Nam /= Chars (Subprogram_Def)
4088 and then Present (E)
4089 and then not Is_Overloadable (E)
4090 and then Is_Immediately_Visible (E)
4091 and then not Is_Imported (E)
4092 and then Ekind (Scope (E)) = E_Package
4093 then
4094 Par := Parent (E);
4095 while Present (Par) loop
4096 if Nkind (Par) = N_Package_Body then
4097 Error_Msg_Sloc := Sloc (E);
4098 Error_Msg_NE
4099 ("imported entity is hidden by & declared#",
4100 Ext_Arg, E);
4101 exit;
4102 end if;
4104 Par := Parent (Par);
4105 end loop;
4106 end if;
4107 end if;
4108 end;
4109 end if;
4111 if Present (Link_Nam) then
4112 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4113 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4114 end if;
4116 -- If there is no link name, just set the external name
4118 if No (Link_Nam) then
4119 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4121 -- For the Link_Name case, the given literal is preceded by an
4122 -- asterisk, which indicates to GCC that the given name should be
4123 -- taken literally, and in particular that no prepending of
4124 -- underlines should occur, even in systems where this is the
4125 -- normal default.
4127 else
4128 Start_String;
4130 if VM_Target = No_VM then
4131 Store_String_Char (Get_Char_Code ('*'));
4132 end if;
4134 String_Val := Strval (Expr_Value_S (Link_Nam));
4135 Store_String_Chars (String_Val);
4136 Link_Nam :=
4137 Make_String_Literal (Sloc (Link_Nam),
4138 Strval => End_String);
4139 end if;
4141 Set_Encoded_Interface_Name
4142 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4143 Check_Duplicated_Export_Name (Link_Nam);
4144 end Process_Interface_Name;
4146 -----------------------------------------
4147 -- Process_Interrupt_Or_Attach_Handler --
4148 -----------------------------------------
4150 procedure Process_Interrupt_Or_Attach_Handler is
4151 Arg1_X : constant Node_Id := Expression (Arg1);
4152 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4153 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4155 begin
4156 Set_Is_Interrupt_Handler (Handler_Proc);
4158 -- If the pragma is not associated with a handler procedure within a
4159 -- protected type, then it must be for a nonprotected procedure for
4160 -- the AAMP target, in which case we don't associate a representation
4161 -- item with the procedure's scope.
4163 if Ekind (Proc_Scope) = E_Protected_Type then
4164 if Prag_Id = Pragma_Interrupt_Handler
4165 or else
4166 Prag_Id = Pragma_Attach_Handler
4167 then
4168 Record_Rep_Item (Proc_Scope, N);
4169 end if;
4170 end if;
4171 end Process_Interrupt_Or_Attach_Handler;
4173 --------------------------------------------------
4174 -- Process_Restrictions_Or_Restriction_Warnings --
4175 --------------------------------------------------
4177 -- Note: some of the simple identifier cases were handled in par-prag,
4178 -- but it is harmless (and more straightforward) to simply handle all
4179 -- cases here, even if it means we repeat a bit of work in some cases.
4181 procedure Process_Restrictions_Or_Restriction_Warnings
4182 (Warn : Boolean)
4184 Arg : Node_Id;
4185 R_Id : Restriction_Id;
4186 Id : Name_Id;
4187 Expr : Node_Id;
4188 Val : Uint;
4190 procedure Check_Unit_Name (N : Node_Id);
4191 -- Checks unit name parameter for No_Dependence. Returns if it has
4192 -- an appropriate form, otherwise raises pragma argument error.
4194 ---------------------
4195 -- Check_Unit_Name --
4196 ---------------------
4198 procedure Check_Unit_Name (N : Node_Id) is
4199 begin
4200 if Nkind (N) = N_Selected_Component then
4201 Check_Unit_Name (Prefix (N));
4202 Check_Unit_Name (Selector_Name (N));
4204 elsif Nkind (N) = N_Identifier then
4205 return;
4207 else
4208 Error_Pragma_Arg
4209 ("wrong form for unit name for No_Dependence", N);
4210 end if;
4211 end Check_Unit_Name;
4213 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4215 begin
4216 Check_Ada_83_Warning;
4217 Check_At_Least_N_Arguments (1);
4218 Check_Valid_Configuration_Pragma;
4220 Arg := Arg1;
4221 while Present (Arg) loop
4222 Id := Chars (Arg);
4223 Expr := Expression (Arg);
4225 -- Case of no restriction identifier present
4227 if Id = No_Name then
4228 if Nkind (Expr) /= N_Identifier then
4229 Error_Pragma_Arg
4230 ("invalid form for restriction", Arg);
4231 end if;
4233 R_Id :=
4234 Get_Restriction_Id
4235 (Process_Restriction_Synonyms (Expr));
4237 if R_Id not in All_Boolean_Restrictions then
4238 Error_Msg_Name_1 := Pname;
4239 Error_Msg_N
4240 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4242 -- Check for possible misspelling
4244 for J in Restriction_Id loop
4245 declare
4246 Rnm : constant String := Restriction_Id'Image (J);
4248 begin
4249 Name_Buffer (1 .. Rnm'Length) := Rnm;
4250 Name_Len := Rnm'Length;
4251 Set_Casing (All_Lower_Case);
4253 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4254 Set_Casing
4255 (Identifier_Casing (Current_Source_File));
4256 Error_Msg_String (1 .. Rnm'Length) :=
4257 Name_Buffer (1 .. Name_Len);
4258 Error_Msg_Strlen := Rnm'Length;
4259 Error_Msg_N -- CODEFIX
4260 ("\possible misspelling of ""~""",
4261 Get_Pragma_Arg (Arg));
4262 exit;
4263 end if;
4264 end;
4265 end loop;
4267 raise Pragma_Exit;
4268 end if;
4270 if Implementation_Restriction (R_Id) then
4271 Check_Restriction (No_Implementation_Restrictions, Arg);
4272 end if;
4274 -- If this is a warning, then set the warning unless we already
4275 -- have a real restriction active (we never want a warning to
4276 -- override a real restriction).
4278 if Warn then
4279 if not Restriction_Active (R_Id) then
4280 Set_Restriction (R_Id, N);
4281 Restriction_Warnings (R_Id) := True;
4282 end if;
4284 -- If real restriction case, then set it and make sure that the
4285 -- restriction warning flag is off, since a real restriction
4286 -- always overrides a warning.
4288 else
4289 Set_Restriction (R_Id, N);
4290 Restriction_Warnings (R_Id) := False;
4291 end if;
4293 -- A very special case that must be processed here: pragma
4294 -- Restrictions (No_Exceptions) turns off all run-time
4295 -- checking. This is a bit dubious in terms of the formal
4296 -- language definition, but it is what is intended by RM
4297 -- H.4(12). Restriction_Warnings never affects generated code
4298 -- so this is done only in the real restriction case.
4300 if R_Id = No_Exceptions and then not Warn then
4301 Scope_Suppress := (others => True);
4302 end if;
4304 -- Case of No_Dependence => unit-name. Note that the parser
4305 -- already made the necessary entry in the No_Dependence table.
4307 elsif Id = Name_No_Dependence then
4308 Check_Unit_Name (Expr);
4310 -- All other cases of restriction identifier present
4312 else
4313 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4314 Analyze_And_Resolve (Expr, Any_Integer);
4316 if R_Id not in All_Parameter_Restrictions then
4317 Error_Pragma_Arg
4318 ("invalid restriction parameter identifier", Arg);
4320 elsif not Is_OK_Static_Expression (Expr) then
4321 Flag_Non_Static_Expr
4322 ("value must be static expression!", Expr);
4323 raise Pragma_Exit;
4325 elsif not Is_Integer_Type (Etype (Expr))
4326 or else Expr_Value (Expr) < 0
4327 then
4328 Error_Pragma_Arg
4329 ("value must be non-negative integer", Arg);
4330 end if;
4332 -- Restriction pragma is active
4334 Val := Expr_Value (Expr);
4336 if not UI_Is_In_Int_Range (Val) then
4337 Error_Pragma_Arg
4338 ("pragma ignored, value too large?", Arg);
4339 end if;
4341 -- Warning case. If the real restriction is active, then we
4342 -- ignore the request, since warning never overrides a real
4343 -- restriction. Otherwise we set the proper warning. Note that
4344 -- this circuit sets the warning again if it is already set,
4345 -- which is what we want, since the constant may have changed.
4347 if Warn then
4348 if not Restriction_Active (R_Id) then
4349 Set_Restriction
4350 (R_Id, N, Integer (UI_To_Int (Val)));
4351 Restriction_Warnings (R_Id) := True;
4352 end if;
4354 -- Real restriction case, set restriction and make sure warning
4355 -- flag is off since real restriction always overrides warning.
4357 else
4358 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4359 Restriction_Warnings (R_Id) := False;
4360 end if;
4361 end if;
4363 Next (Arg);
4364 end loop;
4365 end Process_Restrictions_Or_Restriction_Warnings;
4367 ---------------------------------
4368 -- Process_Suppress_Unsuppress --
4369 ---------------------------------
4371 -- Note: this procedure makes entries in the check suppress data
4372 -- structures managed by Sem. See spec of package Sem for full
4373 -- details on how we handle recording of check suppression.
4375 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4376 C : Check_Id;
4377 E_Id : Node_Id;
4378 E : Entity_Id;
4380 In_Package_Spec : constant Boolean :=
4381 Is_Package_Or_Generic_Package (Current_Scope)
4382 and then not In_Package_Body (Current_Scope);
4384 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4385 -- Used to suppress a single check on the given entity
4387 --------------------------------
4388 -- Suppress_Unsuppress_Echeck --
4389 --------------------------------
4391 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4392 begin
4393 Set_Checks_May_Be_Suppressed (E);
4395 if In_Package_Spec then
4396 Push_Global_Suppress_Stack_Entry
4397 (Entity => E,
4398 Check => C,
4399 Suppress => Suppress_Case);
4401 else
4402 Push_Local_Suppress_Stack_Entry
4403 (Entity => E,
4404 Check => C,
4405 Suppress => Suppress_Case);
4406 end if;
4408 -- If this is a first subtype, and the base type is distinct,
4409 -- then also set the suppress flags on the base type.
4411 if Is_First_Subtype (E)
4412 and then Etype (E) /= E
4413 then
4414 Suppress_Unsuppress_Echeck (Etype (E), C);
4415 end if;
4416 end Suppress_Unsuppress_Echeck;
4418 -- Start of processing for Process_Suppress_Unsuppress
4420 begin
4421 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
4422 -- declarative part or a package spec (RM 11.5(5)).
4424 if not Is_Configuration_Pragma then
4425 Check_Is_In_Decl_Part_Or_Package_Spec;
4426 end if;
4428 Check_At_Least_N_Arguments (1);
4429 Check_At_Most_N_Arguments (2);
4430 Check_No_Identifier (Arg1);
4431 Check_Arg_Is_Identifier (Arg1);
4433 C := Get_Check_Id (Chars (Expression (Arg1)));
4435 if C = No_Check_Id then
4436 Error_Pragma_Arg
4437 ("argument of pragma% is not valid check name", Arg1);
4438 end if;
4440 if not Suppress_Case
4441 and then (C = All_Checks or else C = Overflow_Check)
4442 then
4443 Opt.Overflow_Checks_Unsuppressed := True;
4444 end if;
4446 if Arg_Count = 1 then
4448 -- Make an entry in the local scope suppress table. This is the
4449 -- table that directly shows the current value of the scope
4450 -- suppress check for any check id value.
4452 if C = All_Checks then
4454 -- For All_Checks, we set all specific predefined checks with
4455 -- the exception of Elaboration_Check, which is handled
4456 -- specially because of not wanting All_Checks to have the
4457 -- effect of deactivating static elaboration order processing.
4459 for J in Scope_Suppress'Range loop
4460 if J /= Elaboration_Check then
4461 Scope_Suppress (J) := Suppress_Case;
4462 end if;
4463 end loop;
4465 -- If not All_Checks, and predefined check, then set appropriate
4466 -- scope entry. Note that we will set Elaboration_Check if this
4467 -- is explicitly specified.
4469 elsif C in Predefined_Check_Id then
4470 Scope_Suppress (C) := Suppress_Case;
4471 end if;
4473 -- Also make an entry in the Local_Entity_Suppress table
4475 Push_Local_Suppress_Stack_Entry
4476 (Entity => Empty,
4477 Check => C,
4478 Suppress => Suppress_Case);
4480 -- Case of two arguments present, where the check is suppressed for
4481 -- a specified entity (given as the second argument of the pragma)
4483 else
4484 Check_Optional_Identifier (Arg2, Name_On);
4485 E_Id := Expression (Arg2);
4486 Analyze (E_Id);
4488 if not Is_Entity_Name (E_Id) then
4489 Error_Pragma_Arg
4490 ("second argument of pragma% must be entity name", Arg2);
4491 end if;
4493 E := Entity (E_Id);
4495 if E = Any_Id then
4496 return;
4497 end if;
4499 -- Enforce RM 11.5(7) which requires that for a pragma that
4500 -- appears within a package spec, the named entity must be
4501 -- within the package spec. We allow the package name itself
4502 -- to be mentioned since that makes sense, although it is not
4503 -- strictly allowed by 11.5(7).
4505 if In_Package_Spec
4506 and then E /= Current_Scope
4507 and then Scope (E) /= Current_Scope
4508 then
4509 Error_Pragma_Arg
4510 ("entity in pragma% is not in package spec (RM 11.5(7))",
4511 Arg2);
4512 end if;
4514 -- Loop through homonyms. As noted below, in the case of a package
4515 -- spec, only homonyms within the package spec are considered.
4517 loop
4518 Suppress_Unsuppress_Echeck (E, C);
4520 if Is_Generic_Instance (E)
4521 and then Is_Subprogram (E)
4522 and then Present (Alias (E))
4523 then
4524 Suppress_Unsuppress_Echeck (Alias (E), C);
4525 end if;
4527 -- Move to next homonym
4529 E := Homonym (E);
4530 exit when No (E);
4532 -- If we are within a package specification, the pragma only
4533 -- applies to homonyms in the same scope.
4535 exit when In_Package_Spec
4536 and then Scope (E) /= Current_Scope;
4537 end loop;
4538 end if;
4539 end Process_Suppress_Unsuppress;
4541 ------------------
4542 -- Set_Exported --
4543 ------------------
4545 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
4546 begin
4547 if Is_Imported (E) then
4548 Error_Pragma_Arg
4549 ("cannot export entity& that was previously imported", Arg);
4551 elsif Present (Address_Clause (E)) then
4552 Error_Pragma_Arg
4553 ("cannot export entity& that has an address clause", Arg);
4554 end if;
4556 Set_Is_Exported (E);
4558 -- Generate a reference for entity explicitly, because the
4559 -- identifier may be overloaded and name resolution will not
4560 -- generate one.
4562 Generate_Reference (E, Arg);
4564 -- Deal with exporting non-library level entity
4566 if not Is_Library_Level_Entity (E) then
4568 -- Not allowed at all for subprograms
4570 if Is_Subprogram (E) then
4571 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
4573 -- Otherwise set public and statically allocated
4575 else
4576 Set_Is_Public (E);
4577 Set_Is_Statically_Allocated (E);
4579 -- Warn if the corresponding W flag is set and the pragma comes
4580 -- from source. The latter may not be true e.g. on VMS where we
4581 -- expand export pragmas for exception codes associated with
4582 -- imported or exported exceptions. We do not want to generate
4583 -- a warning for something that the user did not write.
4585 if Warn_On_Export_Import
4586 and then Comes_From_Source (Arg)
4587 then
4588 Error_Msg_NE
4589 ("?& has been made static as a result of Export", Arg, E);
4590 Error_Msg_N
4591 ("\this usage is non-standard and non-portable", Arg);
4592 end if;
4593 end if;
4594 end if;
4596 if Warn_On_Export_Import and then Is_Type (E) then
4597 Error_Msg_NE
4598 ("exporting a type has no effect?", Arg, E);
4599 end if;
4601 if Warn_On_Export_Import and Inside_A_Generic then
4602 Error_Msg_NE
4603 ("all instances of& will have the same external name?", Arg, E);
4604 end if;
4605 end Set_Exported;
4607 ----------------------------------------------
4608 -- Set_Extended_Import_Export_External_Name --
4609 ----------------------------------------------
4611 procedure Set_Extended_Import_Export_External_Name
4612 (Internal_Ent : Entity_Id;
4613 Arg_External : Node_Id)
4615 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
4616 New_Name : Node_Id;
4618 begin
4619 if No (Arg_External) then
4620 return;
4621 end if;
4623 Check_Arg_Is_External_Name (Arg_External);
4625 if Nkind (Arg_External) = N_String_Literal then
4626 if String_Length (Strval (Arg_External)) = 0 then
4627 return;
4628 else
4629 New_Name := Adjust_External_Name_Case (Arg_External);
4630 end if;
4632 elsif Nkind (Arg_External) = N_Identifier then
4633 New_Name := Get_Default_External_Name (Arg_External);
4635 -- Check_Arg_Is_External_Name should let through only identifiers and
4636 -- string literals or static string expressions (which are folded to
4637 -- string literals).
4639 else
4640 raise Program_Error;
4641 end if;
4643 -- If we already have an external name set (by a prior normal Import
4644 -- or Export pragma), then the external names must match
4646 if Present (Interface_Name (Internal_Ent)) then
4647 Check_Matching_Internal_Names : declare
4648 S1 : constant String_Id := Strval (Old_Name);
4649 S2 : constant String_Id := Strval (New_Name);
4651 procedure Mismatch;
4652 -- Called if names do not match
4654 --------------
4655 -- Mismatch --
4656 --------------
4658 procedure Mismatch is
4659 begin
4660 Error_Msg_Sloc := Sloc (Old_Name);
4661 Error_Pragma_Arg
4662 ("external name does not match that given #",
4663 Arg_External);
4664 end Mismatch;
4666 -- Start of processing for Check_Matching_Internal_Names
4668 begin
4669 if String_Length (S1) /= String_Length (S2) then
4670 Mismatch;
4672 else
4673 for J in 1 .. String_Length (S1) loop
4674 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4675 Mismatch;
4676 end if;
4677 end loop;
4678 end if;
4679 end Check_Matching_Internal_Names;
4681 -- Otherwise set the given name
4683 else
4684 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4685 Check_Duplicated_Export_Name (New_Name);
4686 end if;
4687 end Set_Extended_Import_Export_External_Name;
4689 ------------------
4690 -- Set_Imported --
4691 ------------------
4693 procedure Set_Imported (E : Entity_Id) is
4694 begin
4695 -- Error message if already imported or exported
4697 if Is_Exported (E) or else Is_Imported (E) then
4698 if Is_Exported (E) then
4699 Error_Msg_NE ("entity& was previously exported", N, E);
4700 else
4701 Error_Msg_NE ("entity& was previously imported", N, E);
4702 end if;
4704 Error_Msg_Name_1 := Pname;
4705 Error_Msg_N
4706 ("\(pragma% applies to all previous entities)", N);
4708 Error_Msg_Sloc := Sloc (E);
4709 Error_Msg_NE ("\import not allowed for& declared#", N, E);
4711 -- Here if not previously imported or exported, OK to import
4713 else
4714 Set_Is_Imported (E);
4716 -- If the entity is an object that is not at the library level,
4717 -- then it is statically allocated. We do not worry about objects
4718 -- with address clauses in this context since they are not really
4719 -- imported in the linker sense.
4721 if Is_Object (E)
4722 and then not Is_Library_Level_Entity (E)
4723 and then No (Address_Clause (E))
4724 then
4725 Set_Is_Statically_Allocated (E);
4726 end if;
4727 end if;
4728 end Set_Imported;
4730 -------------------------
4731 -- Set_Mechanism_Value --
4732 -------------------------
4734 -- Note: the mechanism name has not been analyzed (and cannot indeed be
4735 -- analyzed, since it is semantic nonsense), so we get it in the exact
4736 -- form created by the parser.
4738 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4739 Class : Node_Id;
4740 Param : Node_Id;
4741 Mech_Name_Id : Name_Id;
4743 procedure Bad_Class;
4744 -- Signal bad descriptor class name
4746 procedure Bad_Mechanism;
4747 -- Signal bad mechanism name
4749 ---------------
4750 -- Bad_Class --
4751 ---------------
4753 procedure Bad_Class is
4754 begin
4755 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4756 end Bad_Class;
4758 -------------------------
4759 -- Bad_Mechanism_Value --
4760 -------------------------
4762 procedure Bad_Mechanism is
4763 begin
4764 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4765 end Bad_Mechanism;
4767 -- Start of processing for Set_Mechanism_Value
4769 begin
4770 if Mechanism (Ent) /= Default_Mechanism then
4771 Error_Msg_NE
4772 ("mechanism for & has already been set", Mech_Name, Ent);
4773 end if;
4775 -- MECHANISM_NAME ::= value | reference | descriptor |
4776 -- short_descriptor
4778 if Nkind (Mech_Name) = N_Identifier then
4779 if Chars (Mech_Name) = Name_Value then
4780 Set_Mechanism (Ent, By_Copy);
4781 return;
4783 elsif Chars (Mech_Name) = Name_Reference then
4784 Set_Mechanism (Ent, By_Reference);
4785 return;
4787 elsif Chars (Mech_Name) = Name_Descriptor then
4788 Check_VMS (Mech_Name);
4789 Set_Mechanism (Ent, By_Descriptor);
4790 return;
4792 elsif Chars (Mech_Name) = Name_Short_Descriptor then
4793 Check_VMS (Mech_Name);
4794 Set_Mechanism (Ent, By_Short_Descriptor);
4795 return;
4797 elsif Chars (Mech_Name) = Name_Copy then
4798 Error_Pragma_Arg
4799 ("bad mechanism name, Value assumed", Mech_Name);
4801 else
4802 Bad_Mechanism;
4803 end if;
4805 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
4806 -- short_descriptor (CLASS_NAME)
4807 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4809 -- Note: this form is parsed as an indexed component
4811 elsif Nkind (Mech_Name) = N_Indexed_Component then
4813 Class := First (Expressions (Mech_Name));
4815 if Nkind (Prefix (Mech_Name)) /= N_Identifier
4816 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
4817 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
4818 or else Present (Next (Class))
4819 then
4820 Bad_Mechanism;
4821 else
4822 Mech_Name_Id := Chars (Prefix (Mech_Name));
4823 end if;
4825 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
4826 -- short_descriptor (Class => CLASS_NAME)
4827 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4829 -- Note: this form is parsed as a function call
4831 elsif Nkind (Mech_Name) = N_Function_Call then
4833 Param := First (Parameter_Associations (Mech_Name));
4835 if Nkind (Name (Mech_Name)) /= N_Identifier
4836 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
4837 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
4838 or else Present (Next (Param))
4839 or else No (Selector_Name (Param))
4840 or else Chars (Selector_Name (Param)) /= Name_Class
4841 then
4842 Bad_Mechanism;
4843 else
4844 Class := Explicit_Actual_Parameter (Param);
4845 Mech_Name_Id := Chars (Name (Mech_Name));
4846 end if;
4848 else
4849 Bad_Mechanism;
4850 end if;
4852 -- Fall through here with Class set to descriptor class name
4854 Check_VMS (Mech_Name);
4856 if Nkind (Class) /= N_Identifier then
4857 Bad_Class;
4859 elsif Mech_Name_Id = Name_Descriptor
4860 and then Chars (Class) = Name_UBS
4861 then
4862 Set_Mechanism (Ent, By_Descriptor_UBS);
4864 elsif Mech_Name_Id = Name_Descriptor
4865 and then Chars (Class) = Name_UBSB
4866 then
4867 Set_Mechanism (Ent, By_Descriptor_UBSB);
4869 elsif Mech_Name_Id = Name_Descriptor
4870 and then Chars (Class) = Name_UBA
4871 then
4872 Set_Mechanism (Ent, By_Descriptor_UBA);
4874 elsif Mech_Name_Id = Name_Descriptor
4875 and then Chars (Class) = Name_S
4876 then
4877 Set_Mechanism (Ent, By_Descriptor_S);
4879 elsif Mech_Name_Id = Name_Descriptor
4880 and then Chars (Class) = Name_SB
4881 then
4882 Set_Mechanism (Ent, By_Descriptor_SB);
4884 elsif Mech_Name_Id = Name_Descriptor
4885 and then Chars (Class) = Name_A
4886 then
4887 Set_Mechanism (Ent, By_Descriptor_A);
4889 elsif Mech_Name_Id = Name_Descriptor
4890 and then Chars (Class) = Name_NCA
4891 then
4892 Set_Mechanism (Ent, By_Descriptor_NCA);
4894 elsif Mech_Name_Id = Name_Short_Descriptor
4895 and then Chars (Class) = Name_UBS
4896 then
4897 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
4899 elsif Mech_Name_Id = Name_Short_Descriptor
4900 and then Chars (Class) = Name_UBSB
4901 then
4902 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
4904 elsif Mech_Name_Id = Name_Short_Descriptor
4905 and then Chars (Class) = Name_UBA
4906 then
4907 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
4909 elsif Mech_Name_Id = Name_Short_Descriptor
4910 and then Chars (Class) = Name_S
4911 then
4912 Set_Mechanism (Ent, By_Short_Descriptor_S);
4914 elsif Mech_Name_Id = Name_Short_Descriptor
4915 and then Chars (Class) = Name_SB
4916 then
4917 Set_Mechanism (Ent, By_Short_Descriptor_SB);
4919 elsif Mech_Name_Id = Name_Short_Descriptor
4920 and then Chars (Class) = Name_A
4921 then
4922 Set_Mechanism (Ent, By_Short_Descriptor_A);
4924 elsif Mech_Name_Id = Name_Short_Descriptor
4925 and then Chars (Class) = Name_NCA
4926 then
4927 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
4929 else
4930 Bad_Class;
4931 end if;
4932 end Set_Mechanism_Value;
4934 ---------------------------
4935 -- Set_Ravenscar_Profile --
4936 ---------------------------
4938 -- The tasks to be done here are
4940 -- Set required policies
4942 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4943 -- pragma Locking_Policy (Ceiling_Locking)
4945 -- Set Detect_Blocking mode
4947 -- Set required restrictions (see System.Rident for detailed list)
4949 procedure Set_Ravenscar_Profile (N : Node_Id) is
4950 begin
4951 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4953 if Task_Dispatching_Policy /= ' '
4954 and then Task_Dispatching_Policy /= 'F'
4955 then
4956 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4957 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4959 -- Set the FIFO_Within_Priorities policy, but always preserve
4960 -- System_Location since we like the error message with the run time
4961 -- name.
4963 else
4964 Task_Dispatching_Policy := 'F';
4966 if Task_Dispatching_Policy_Sloc /= System_Location then
4967 Task_Dispatching_Policy_Sloc := Loc;
4968 end if;
4969 end if;
4971 -- pragma Locking_Policy (Ceiling_Locking)
4973 if Locking_Policy /= ' '
4974 and then Locking_Policy /= 'C'
4975 then
4976 Error_Msg_Sloc := Locking_Policy_Sloc;
4977 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4979 -- Set the Ceiling_Locking policy, but preserve System_Location since
4980 -- we like the error message with the run time name.
4982 else
4983 Locking_Policy := 'C';
4985 if Locking_Policy_Sloc /= System_Location then
4986 Locking_Policy_Sloc := Loc;
4987 end if;
4988 end if;
4990 -- pragma Detect_Blocking
4992 Detect_Blocking := True;
4994 -- Set the corresponding restrictions
4996 Set_Profile_Restrictions
4997 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
4998 end Set_Ravenscar_Profile;
5000 -- Start of processing for Analyze_Pragma
5002 begin
5003 -- Deal with unrecognized pragma
5005 if not Is_Pragma_Name (Pname) then
5006 if Warn_On_Unrecognized_Pragma then
5007 Error_Msg_Name_1 := Pname;
5008 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5010 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5011 if Is_Bad_Spelling_Of (Pname, PN) then
5012 Error_Msg_Name_1 := PN;
5013 Error_Msg_N -- CODEFIX
5014 ("\?possible misspelling of %!", Pragma_Identifier (N));
5015 exit;
5016 end if;
5017 end loop;
5018 end if;
5020 return;
5021 end if;
5023 -- Here to start processing for recognized pragma
5025 Prag_Id := Get_Pragma_Id (Pname);
5027 -- Preset arguments
5029 Arg1 := Empty;
5030 Arg2 := Empty;
5031 Arg3 := Empty;
5032 Arg4 := Empty;
5034 if Present (Pragma_Argument_Associations (N)) then
5035 Arg1 := First (Pragma_Argument_Associations (N));
5037 if Present (Arg1) then
5038 Arg2 := Next (Arg1);
5040 if Present (Arg2) then
5041 Arg3 := Next (Arg2);
5043 if Present (Arg3) then
5044 Arg4 := Next (Arg3);
5045 end if;
5046 end if;
5047 end if;
5048 end if;
5050 -- Count number of arguments
5052 declare
5053 Arg_Node : Node_Id;
5054 begin
5055 Arg_Count := 0;
5056 Arg_Node := Arg1;
5057 while Present (Arg_Node) loop
5058 Arg_Count := Arg_Count + 1;
5059 Next (Arg_Node);
5060 end loop;
5061 end;
5063 -- An enumeration type defines the pragmas that are supported by the
5064 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5065 -- into the corresponding enumeration value for the following case.
5067 case Prag_Id is
5069 -----------------
5070 -- Abort_Defer --
5071 -----------------
5073 -- pragma Abort_Defer;
5075 when Pragma_Abort_Defer =>
5076 GNAT_Pragma;
5077 Check_Arg_Count (0);
5079 -- The only required semantic processing is to check the
5080 -- placement. This pragma must appear at the start of the
5081 -- statement sequence of a handled sequence of statements.
5083 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5084 or else N /= First (Statements (Parent (N)))
5085 then
5086 Pragma_Misplaced;
5087 end if;
5089 ------------
5090 -- Ada_83 --
5091 ------------
5093 -- pragma Ada_83;
5095 -- Note: this pragma also has some specific processing in Par.Prag
5096 -- because we want to set the Ada version mode during parsing.
5098 when Pragma_Ada_83 =>
5099 GNAT_Pragma;
5100 Check_Arg_Count (0);
5102 -- We really should check unconditionally for proper configuration
5103 -- pragma placement, since we really don't want mixed Ada modes
5104 -- within a single unit, and the GNAT reference manual has always
5105 -- said this was a configuration pragma, but we did not check and
5106 -- are hesitant to add the check now.
5108 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5109 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5111 if Ada_Version >= Ada_05 then
5112 Check_Valid_Configuration_Pragma;
5113 end if;
5115 -- Now set Ada 83 mode
5117 Ada_Version := Ada_83;
5118 Ada_Version_Explicit := Ada_Version;
5120 ------------
5121 -- Ada_95 --
5122 ------------
5124 -- pragma Ada_95;
5126 -- Note: this pragma also has some specific processing in Par.Prag
5127 -- because we want to set the Ada 83 version mode during parsing.
5129 when Pragma_Ada_95 =>
5130 GNAT_Pragma;
5131 Check_Arg_Count (0);
5133 -- We really should check unconditionally for proper configuration
5134 -- pragma placement, since we really don't want mixed Ada modes
5135 -- within a single unit, and the GNAT reference manual has always
5136 -- said this was a configuration pragma, but we did not check and
5137 -- are hesitant to add the check now.
5139 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5140 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5142 if Ada_Version >= Ada_05 then
5143 Check_Valid_Configuration_Pragma;
5144 end if;
5146 -- Now set Ada 95 mode
5148 Ada_Version := Ada_95;
5149 Ada_Version_Explicit := Ada_Version;
5151 ---------------------
5152 -- Ada_05/Ada_2005 --
5153 ---------------------
5155 -- pragma Ada_05;
5156 -- pragma Ada_05 (LOCAL_NAME);
5158 -- pragma Ada_2005;
5159 -- pragma Ada_2005 (LOCAL_NAME):
5161 -- Note: these pragma also have some specific processing in Par.Prag
5162 -- because we want to set the Ada 2005 version mode during parsing.
5164 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5165 E_Id : Node_Id;
5167 begin
5168 GNAT_Pragma;
5170 if Arg_Count = 1 then
5171 Check_Arg_Is_Local_Name (Arg1);
5172 E_Id := Expression (Arg1);
5174 if Etype (E_Id) = Any_Type then
5175 return;
5176 end if;
5178 Set_Is_Ada_2005_Only (Entity (E_Id));
5180 else
5181 Check_Arg_Count (0);
5183 -- For Ada_2005 we unconditionally enforce the documented
5184 -- configuration pragma placement, since we do not want to
5185 -- tolerate mixed modes in a unit involving Ada 2005. That
5186 -- would cause real difficulties for those cases where there
5187 -- are incompatibilities between Ada 95 and Ada 2005.
5189 Check_Valid_Configuration_Pragma;
5191 -- Now set Ada 2005 mode
5193 Ada_Version := Ada_05;
5194 Ada_Version_Explicit := Ada_05;
5195 end if;
5196 end;
5198 ----------------------
5199 -- All_Calls_Remote --
5200 ----------------------
5202 -- pragma All_Calls_Remote [(library_package_NAME)];
5204 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5205 Lib_Entity : Entity_Id;
5207 begin
5208 Check_Ada_83_Warning;
5209 Check_Valid_Library_Unit_Pragma;
5211 if Nkind (N) = N_Null_Statement then
5212 return;
5213 end if;
5215 Lib_Entity := Find_Lib_Unit_Name;
5217 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5219 if Present (Lib_Entity)
5220 and then not Debug_Flag_U
5221 then
5222 if not Is_Remote_Call_Interface (Lib_Entity) then
5223 Error_Pragma ("pragma% only apply to rci unit");
5225 -- Set flag for entity of the library unit
5227 else
5228 Set_Has_All_Calls_Remote (Lib_Entity);
5229 end if;
5231 end if;
5232 end All_Calls_Remote;
5234 --------------
5235 -- Annotate --
5236 --------------
5238 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
5239 -- ARG ::= NAME | EXPRESSION
5241 -- The first two arguments are by convention intended to refer to an
5242 -- external tool and a tool-specific function. These arguments are
5243 -- not analyzed.
5245 when Pragma_Annotate => Annotate : begin
5246 GNAT_Pragma;
5247 Check_At_Least_N_Arguments (1);
5248 Check_Arg_Is_Identifier (Arg1);
5250 declare
5251 Arg : Node_Id;
5252 Exp : Node_Id;
5254 begin
5255 -- Second unanalyzed parameter is optional
5257 if No (Arg2) then
5258 null;
5259 else
5260 Arg := Next (Arg2);
5261 while Present (Arg) loop
5262 Exp := Expression (Arg);
5263 Analyze (Exp);
5265 if Is_Entity_Name (Exp) then
5266 null;
5268 elsif Nkind (Exp) = N_String_Literal then
5269 Resolve (Exp, Standard_String);
5271 elsif Is_Overloaded (Exp) then
5272 Error_Pragma_Arg
5273 ("ambiguous argument for pragma%", Exp);
5275 else
5276 Resolve (Exp);
5277 end if;
5279 Next (Arg);
5280 end loop;
5281 end if;
5282 end;
5283 end Annotate;
5285 ------------
5286 -- Assert --
5287 ------------
5289 -- pragma Assert ([Check =>] Boolean_EXPRESSION
5290 -- [, [Message =>] Static_String_EXPRESSION]);
5292 when Pragma_Assert => Assert : declare
5293 Expr : Node_Id;
5294 Newa : List_Id;
5296 begin
5297 Ada_2005_Pragma;
5298 Check_At_Least_N_Arguments (1);
5299 Check_At_Most_N_Arguments (2);
5300 Check_Arg_Order ((Name_Check, Name_Message));
5301 Check_Optional_Identifier (Arg1, Name_Check);
5303 -- We treat pragma Assert as equivalent to:
5305 -- pragma Check (Assertion, condition [, msg]);
5307 -- So rewrite pragma in this manner, and analyze the result
5309 Expr := Get_Pragma_Arg (Arg1);
5310 Newa := New_List (
5311 Make_Pragma_Argument_Association (Loc,
5312 Expression =>
5313 Make_Identifier (Loc,
5314 Chars => Name_Assertion)),
5316 Make_Pragma_Argument_Association (Sloc (Expr),
5317 Expression => Expr));
5319 if Arg_Count > 1 then
5320 Check_Optional_Identifier (Arg2, Name_Message);
5321 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
5322 Append_To (Newa, Relocate_Node (Arg2));
5323 end if;
5325 Rewrite (N,
5326 Make_Pragma (Loc,
5327 Chars => Name_Check,
5328 Pragma_Argument_Associations => Newa));
5329 Analyze (N);
5330 end Assert;
5332 ----------------------
5333 -- Assertion_Policy --
5334 ----------------------
5336 -- pragma Assertion_Policy (Check | Ignore)
5338 when Pragma_Assertion_Policy => Assertion_Policy : declare
5339 Policy : Node_Id;
5341 begin
5342 Ada_2005_Pragma;
5343 Check_Valid_Configuration_Pragma;
5344 Check_Arg_Count (1);
5345 Check_No_Identifiers;
5346 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5348 -- We treat pragma Assertion_Policy as equivalent to:
5350 -- pragma Check_Policy (Assertion, policy)
5352 -- So rewrite the pragma in that manner and link on to the chain
5353 -- of Check_Policy pragmas, marking the pragma as analyzed.
5355 Policy := Get_Pragma_Arg (Arg1);
5357 Rewrite (N,
5358 Make_Pragma (Loc,
5359 Chars => Name_Check_Policy,
5361 Pragma_Argument_Associations => New_List (
5362 Make_Pragma_Argument_Association (Loc,
5363 Expression =>
5364 Make_Identifier (Loc,
5365 Chars => Name_Assertion)),
5367 Make_Pragma_Argument_Association (Loc,
5368 Expression =>
5369 Make_Identifier (Sloc (Policy),
5370 Chars => Chars (Policy))))));
5372 Set_Analyzed (N);
5373 Set_Next_Pragma (N, Opt.Check_Policy_List);
5374 Opt.Check_Policy_List := N;
5375 end Assertion_Policy;
5377 ------------------------------
5378 -- Assume_No_Invalid_Values --
5379 ------------------------------
5381 -- pragma Assume_No_Invalid_Values (On | Off);
5383 when Pragma_Assume_No_Invalid_Values =>
5384 GNAT_Pragma;
5385 Check_Valid_Configuration_Pragma;
5386 Check_Arg_Count (1);
5387 Check_No_Identifiers;
5388 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5390 if Chars (Expression (Arg1)) = Name_On then
5391 Assume_No_Invalid_Values := True;
5392 else
5393 Assume_No_Invalid_Values := False;
5394 end if;
5396 ---------------
5397 -- AST_Entry --
5398 ---------------
5400 -- pragma AST_Entry (entry_IDENTIFIER);
5402 when Pragma_AST_Entry => AST_Entry : declare
5403 Ent : Node_Id;
5405 begin
5406 GNAT_Pragma;
5407 Check_VMS (N);
5408 Check_Arg_Count (1);
5409 Check_No_Identifiers;
5410 Check_Arg_Is_Local_Name (Arg1);
5411 Ent := Entity (Expression (Arg1));
5413 -- Note: the implementation of the AST_Entry pragma could handle
5414 -- the entry family case fine, but for now we are consistent with
5415 -- the DEC rules, and do not allow the pragma, which of course
5416 -- has the effect of also forbidding the attribute.
5418 if Ekind (Ent) /= E_Entry then
5419 Error_Pragma_Arg
5420 ("pragma% argument must be simple entry name", Arg1);
5422 elsif Is_AST_Entry (Ent) then
5423 Error_Pragma_Arg
5424 ("duplicate % pragma for entry", Arg1);
5426 elsif Has_Homonym (Ent) then
5427 Error_Pragma_Arg
5428 ("pragma% argument cannot specify overloaded entry", Arg1);
5430 else
5431 declare
5432 FF : constant Entity_Id := First_Formal (Ent);
5434 begin
5435 if Present (FF) then
5436 if Present (Next_Formal (FF)) then
5437 Error_Pragma_Arg
5438 ("entry for pragma% can have only one argument",
5439 Arg1);
5441 elsif Parameter_Mode (FF) /= E_In_Parameter then
5442 Error_Pragma_Arg
5443 ("entry parameter for pragma% must have mode IN",
5444 Arg1);
5445 end if;
5446 end if;
5447 end;
5449 Set_Is_AST_Entry (Ent);
5450 end if;
5451 end AST_Entry;
5453 ------------------
5454 -- Asynchronous --
5455 ------------------
5457 -- pragma Asynchronous (LOCAL_NAME);
5459 when Pragma_Asynchronous => Asynchronous : declare
5460 Nm : Entity_Id;
5461 C_Ent : Entity_Id;
5462 L : List_Id;
5463 S : Node_Id;
5464 N : Node_Id;
5465 Formal : Entity_Id;
5467 procedure Process_Async_Pragma;
5468 -- Common processing for procedure and access-to-procedure case
5470 --------------------------
5471 -- Process_Async_Pragma --
5472 --------------------------
5474 procedure Process_Async_Pragma is
5475 begin
5476 if No (L) then
5477 Set_Is_Asynchronous (Nm);
5478 return;
5479 end if;
5481 -- The formals should be of mode IN (RM E.4.1(6))
5483 S := First (L);
5484 while Present (S) loop
5485 Formal := Defining_Identifier (S);
5487 if Nkind (Formal) = N_Defining_Identifier
5488 and then Ekind (Formal) /= E_In_Parameter
5489 then
5490 Error_Pragma_Arg
5491 ("pragma% procedure can only have IN parameter",
5492 Arg1);
5493 end if;
5495 Next (S);
5496 end loop;
5498 Set_Is_Asynchronous (Nm);
5499 end Process_Async_Pragma;
5501 -- Start of processing for pragma Asynchronous
5503 begin
5504 Check_Ada_83_Warning;
5505 Check_No_Identifiers;
5506 Check_Arg_Count (1);
5507 Check_Arg_Is_Local_Name (Arg1);
5509 if Debug_Flag_U then
5510 return;
5511 end if;
5513 C_Ent := Cunit_Entity (Current_Sem_Unit);
5514 Analyze (Expression (Arg1));
5515 Nm := Entity (Expression (Arg1));
5517 if not Is_Remote_Call_Interface (C_Ent)
5518 and then not Is_Remote_Types (C_Ent)
5519 then
5520 -- This pragma should only appear in an RCI or Remote Types
5521 -- unit (RM E.4.1(4)).
5523 Error_Pragma
5524 ("pragma% not in Remote_Call_Interface or " &
5525 "Remote_Types unit");
5526 end if;
5528 if Ekind (Nm) = E_Procedure
5529 and then Nkind (Parent (Nm)) = N_Procedure_Specification
5530 then
5531 if not Is_Remote_Call_Interface (Nm) then
5532 Error_Pragma_Arg
5533 ("pragma% cannot be applied on non-remote procedure",
5534 Arg1);
5535 end if;
5537 L := Parameter_Specifications (Parent (Nm));
5538 Process_Async_Pragma;
5539 return;
5541 elsif Ekind (Nm) = E_Function then
5542 Error_Pragma_Arg
5543 ("pragma% cannot be applied to function", Arg1);
5545 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
5547 if Is_Record_Type (Nm) then
5549 -- A record type that is the Equivalent_Type for a remote
5550 -- access-to-subprogram type.
5552 N := Declaration_Node (Corresponding_Remote_Type (Nm));
5554 else
5555 -- A non-expanded RAS type (distribution is not enabled)
5557 N := Declaration_Node (Nm);
5558 end if;
5560 if Nkind (N) = N_Full_Type_Declaration
5561 and then Nkind (Type_Definition (N)) =
5562 N_Access_Procedure_Definition
5563 then
5564 L := Parameter_Specifications (Type_Definition (N));
5565 Process_Async_Pragma;
5567 if Is_Asynchronous (Nm)
5568 and then Expander_Active
5569 and then Get_PCS_Name /= Name_No_DSA
5570 then
5571 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
5572 end if;
5574 else
5575 Error_Pragma_Arg
5576 ("pragma% cannot reference access-to-function type",
5577 Arg1);
5578 end if;
5580 -- Only other possibility is Access-to-class-wide type
5582 elsif Is_Access_Type (Nm)
5583 and then Is_Class_Wide_Type (Designated_Type (Nm))
5584 then
5585 Check_First_Subtype (Arg1);
5586 Set_Is_Asynchronous (Nm);
5587 if Expander_Active then
5588 RACW_Type_Is_Asynchronous (Nm);
5589 end if;
5591 else
5592 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
5593 end if;
5594 end Asynchronous;
5596 ------------
5597 -- Atomic --
5598 ------------
5600 -- pragma Atomic (LOCAL_NAME);
5602 when Pragma_Atomic =>
5603 Process_Atomic_Shared_Volatile;
5605 -----------------------
5606 -- Atomic_Components --
5607 -----------------------
5609 -- pragma Atomic_Components (array_LOCAL_NAME);
5611 -- This processing is shared by Volatile_Components
5613 when Pragma_Atomic_Components |
5614 Pragma_Volatile_Components =>
5616 Atomic_Components : declare
5617 E_Id : Node_Id;
5618 E : Entity_Id;
5619 D : Node_Id;
5620 K : Node_Kind;
5622 begin
5623 Check_Ada_83_Warning;
5624 Check_No_Identifiers;
5625 Check_Arg_Count (1);
5626 Check_Arg_Is_Local_Name (Arg1);
5627 E_Id := Expression (Arg1);
5629 if Etype (E_Id) = Any_Type then
5630 return;
5631 end if;
5633 E := Entity (E_Id);
5635 if Rep_Item_Too_Early (E, N)
5636 or else
5637 Rep_Item_Too_Late (E, N)
5638 then
5639 return;
5640 end if;
5642 D := Declaration_Node (E);
5643 K := Nkind (D);
5645 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
5646 or else
5647 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
5648 and then Nkind (D) = N_Object_Declaration
5649 and then Nkind (Object_Definition (D)) =
5650 N_Constrained_Array_Definition)
5651 then
5652 -- The flag is set on the object, or on the base type
5654 if Nkind (D) /= N_Object_Declaration then
5655 E := Base_Type (E);
5656 end if;
5658 Set_Has_Volatile_Components (E);
5660 if Prag_Id = Pragma_Atomic_Components then
5661 Set_Has_Atomic_Components (E);
5663 if Is_Packed (E) then
5664 Set_Is_Packed (E, False);
5666 Error_Pragma_Arg
5667 ("?Pack canceled, cannot pack atomic components",
5668 Arg1);
5669 end if;
5670 end if;
5672 else
5673 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
5674 end if;
5675 end Atomic_Components;
5677 --------------------
5678 -- Attach_Handler --
5679 --------------------
5681 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
5683 when Pragma_Attach_Handler =>
5684 Check_Ada_83_Warning;
5685 Check_No_Identifiers;
5686 Check_Arg_Count (2);
5688 if No_Run_Time_Mode then
5689 Error_Msg_CRT ("Attach_Handler pragma", N);
5690 else
5691 Check_Interrupt_Or_Attach_Handler;
5693 -- The expression that designates the attribute may
5694 -- depend on a discriminant, and is therefore a per-
5695 -- object expression, to be expanded in the init proc.
5696 -- If expansion is enabled, perform semantic checks
5697 -- on a copy only.
5699 if Expander_Active then
5700 declare
5701 Temp : constant Node_Id :=
5702 New_Copy_Tree (Expression (Arg2));
5703 begin
5704 Set_Parent (Temp, N);
5705 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
5706 end;
5708 else
5709 Analyze (Expression (Arg2));
5710 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
5711 end if;
5713 Process_Interrupt_Or_Attach_Handler;
5714 end if;
5716 --------------------
5717 -- C_Pass_By_Copy --
5718 --------------------
5720 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
5722 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
5723 Arg : Node_Id;
5724 Val : Uint;
5726 begin
5727 GNAT_Pragma;
5728 Check_Valid_Configuration_Pragma;
5729 Check_Arg_Count (1);
5730 Check_Optional_Identifier (Arg1, "max_size");
5732 Arg := Expression (Arg1);
5733 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
5735 Val := Expr_Value (Arg);
5737 if Val <= 0 then
5738 Error_Pragma_Arg
5739 ("maximum size for pragma% must be positive", Arg1);
5741 elsif UI_Is_In_Int_Range (Val) then
5742 Default_C_Record_Mechanism := UI_To_Int (Val);
5744 -- If a giant value is given, Int'Last will do well enough.
5745 -- If sometime someone complains that a record larger than
5746 -- two gigabytes is not copied, we will worry about it then!
5748 else
5749 Default_C_Record_Mechanism := Mechanism_Type'Last;
5750 end if;
5751 end C_Pass_By_Copy;
5753 -----------
5754 -- Check --
5755 -----------
5757 -- pragma Check ([Name =>] Identifier,
5758 -- [Check =>] Boolean_Expression
5759 -- [,[Message =>] String_Expression]);
5761 when Pragma_Check => Check : declare
5762 Expr : Node_Id;
5763 Eloc : Source_Ptr;
5765 Check_On : Boolean;
5766 -- Set True if category of assertions referenced by Name enabled
5768 begin
5769 GNAT_Pragma;
5770 Check_At_Least_N_Arguments (2);
5771 Check_At_Most_N_Arguments (3);
5772 Check_Optional_Identifier (Arg1, Name_Name);
5773 Check_Optional_Identifier (Arg2, Name_Check);
5775 if Arg_Count = 3 then
5776 Check_Optional_Identifier (Arg3, Name_Message);
5777 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
5778 end if;
5780 Check_Arg_Is_Identifier (Arg1);
5781 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
5783 -- If expansion is active and the check is not enabled then we
5784 -- rewrite the Check as:
5786 -- if False and then condition then
5787 -- null;
5788 -- end if;
5790 -- The reason we do this rewriting during semantic analysis rather
5791 -- than as part of normal expansion is that we cannot analyze and
5792 -- expand the code for the boolean expression directly, or it may
5793 -- cause insertion of actions that would escape the attempt to
5794 -- suppress the check code.
5796 -- Note that the Sloc for the if statement corresponds to the
5797 -- argument condition, not the pragma itself. The reason for this
5798 -- is that we may generate a warning if the condition is False at
5799 -- compile time, and we do not want to delete this warning when we
5800 -- delete the if statement.
5802 Expr := Expression (Arg2);
5804 if Expander_Active and then not Check_On then
5805 Eloc := Sloc (Expr);
5807 Rewrite (N,
5808 Make_If_Statement (Eloc,
5809 Condition =>
5810 Make_And_Then (Eloc,
5811 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
5812 Right_Opnd => Expr),
5813 Then_Statements => New_List (
5814 Make_Null_Statement (Eloc))));
5816 Analyze (N);
5818 -- Check is active
5820 else
5821 Analyze_And_Resolve (Expr, Any_Boolean);
5822 end if;
5823 end Check;
5825 ----------------
5826 -- Check_Name --
5827 ----------------
5829 -- pragma Check_Name (check_IDENTIFIER);
5831 when Pragma_Check_Name =>
5832 Check_No_Identifiers;
5833 GNAT_Pragma;
5834 Check_Valid_Configuration_Pragma;
5835 Check_Arg_Count (1);
5836 Check_Arg_Is_Identifier (Arg1);
5838 declare
5839 Nam : constant Name_Id := Chars (Expression (Arg1));
5841 begin
5842 for J in Check_Names.First .. Check_Names.Last loop
5843 if Check_Names.Table (J) = Nam then
5844 return;
5845 end if;
5846 end loop;
5848 Check_Names.Append (Nam);
5849 end;
5851 ------------------
5852 -- Check_Policy --
5853 ------------------
5855 -- pragma Check_Policy (
5856 -- [Name =>] IDENTIFIER,
5857 -- [Policy =>] POLICY_IDENTIFIER);
5859 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
5861 -- Note: this is a configuration pragma, but it is allowed to appear
5862 -- anywhere else.
5864 when Pragma_Check_Policy =>
5865 GNAT_Pragma;
5866 Check_Arg_Count (2);
5867 Check_Optional_Identifier (Arg1, Name_Name);
5868 Check_Optional_Identifier (Arg2, Name_Policy);
5869 Check_Arg_Is_One_Of
5870 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
5872 -- A Check_Policy pragma can appear either as a configuration
5873 -- pragma, or in a declarative part or a package spec (see RM
5874 -- 11.5(5) for rules for Suppress/Unsuppress which are also
5875 -- followed for Check_Policy).
5877 if not Is_Configuration_Pragma then
5878 Check_Is_In_Decl_Part_Or_Package_Spec;
5879 end if;
5881 Set_Next_Pragma (N, Opt.Check_Policy_List);
5882 Opt.Check_Policy_List := N;
5884 ---------------------
5885 -- CIL_Constructor --
5886 ---------------------
5888 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
5890 -- Processing for this pragma is shared with Java_Constructor
5892 -------------
5893 -- Comment --
5894 -------------
5896 -- pragma Comment (static_string_EXPRESSION)
5898 -- Processing for pragma Comment shares the circuitry for pragma
5899 -- Ident. The only differences are that Ident enforces a limit of 31
5900 -- characters on its argument, and also enforces limitations on
5901 -- placement for DEC compatibility. Pragma Comment shares neither of
5902 -- these restrictions.
5904 -------------------
5905 -- Common_Object --
5906 -------------------
5908 -- pragma Common_Object (
5909 -- [Internal =>] LOCAL_NAME
5910 -- [, [External =>] EXTERNAL_SYMBOL]
5911 -- [, [Size =>] EXTERNAL_SYMBOL]);
5913 -- Processing for this pragma is shared with Psect_Object
5915 ------------------------
5916 -- Compile_Time_Error --
5917 ------------------------
5919 -- pragma Compile_Time_Error
5920 -- (boolean_EXPRESSION, static_string_EXPRESSION);
5922 when Pragma_Compile_Time_Error =>
5923 GNAT_Pragma;
5924 Process_Compile_Time_Warning_Or_Error;
5926 --------------------------
5927 -- Compile_Time_Warning --
5928 --------------------------
5930 -- pragma Compile_Time_Warning
5931 -- (boolean_EXPRESSION, static_string_EXPRESSION);
5933 when Pragma_Compile_Time_Warning =>
5934 GNAT_Pragma;
5935 Process_Compile_Time_Warning_Or_Error;
5937 -------------------
5938 -- Compiler_Unit --
5939 -------------------
5941 when Pragma_Compiler_Unit =>
5942 GNAT_Pragma;
5943 Check_Arg_Count (0);
5944 Set_Is_Compiler_Unit (Get_Source_Unit (N));
5946 -----------------------------
5947 -- Complete_Representation --
5948 -----------------------------
5950 -- pragma Complete_Representation;
5952 when Pragma_Complete_Representation =>
5953 GNAT_Pragma;
5954 Check_Arg_Count (0);
5956 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
5957 Error_Pragma
5958 ("pragma & must appear within record representation clause");
5959 end if;
5961 ----------------------------
5962 -- Complex_Representation --
5963 ----------------------------
5965 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
5967 when Pragma_Complex_Representation => Complex_Representation : declare
5968 E_Id : Entity_Id;
5969 E : Entity_Id;
5970 Ent : Entity_Id;
5972 begin
5973 GNAT_Pragma;
5974 Check_Arg_Count (1);
5975 Check_Optional_Identifier (Arg1, Name_Entity);
5976 Check_Arg_Is_Local_Name (Arg1);
5977 E_Id := Expression (Arg1);
5979 if Etype (E_Id) = Any_Type then
5980 return;
5981 end if;
5983 E := Entity (E_Id);
5985 if not Is_Record_Type (E) then
5986 Error_Pragma_Arg
5987 ("argument for pragma% must be record type", Arg1);
5988 end if;
5990 Ent := First_Entity (E);
5992 if No (Ent)
5993 or else No (Next_Entity (Ent))
5994 or else Present (Next_Entity (Next_Entity (Ent)))
5995 or else not Is_Floating_Point_Type (Etype (Ent))
5996 or else Etype (Ent) /= Etype (Next_Entity (Ent))
5997 then
5998 Error_Pragma_Arg
5999 ("record for pragma% must have two fields of the same "
6000 & "floating-point type", Arg1);
6002 else
6003 Set_Has_Complex_Representation (Base_Type (E));
6005 -- We need to treat the type has having a non-standard
6006 -- representation, for back-end purposes, even though in
6007 -- general a complex will have the default representation
6008 -- of a record with two real components.
6010 Set_Has_Non_Standard_Rep (Base_Type (E));
6011 end if;
6012 end Complex_Representation;
6014 -------------------------
6015 -- Component_Alignment --
6016 -------------------------
6018 -- pragma Component_Alignment (
6019 -- [Form =>] ALIGNMENT_CHOICE
6020 -- [, [Name =>] type_LOCAL_NAME]);
6022 -- ALIGNMENT_CHOICE ::=
6023 -- Component_Size
6024 -- | Component_Size_4
6025 -- | Storage_Unit
6026 -- | Default
6028 when Pragma_Component_Alignment => Component_AlignmentP : declare
6029 Args : Args_List (1 .. 2);
6030 Names : constant Name_List (1 .. 2) := (
6031 Name_Form,
6032 Name_Name);
6034 Form : Node_Id renames Args (1);
6035 Name : Node_Id renames Args (2);
6037 Atype : Component_Alignment_Kind;
6038 Typ : Entity_Id;
6040 begin
6041 GNAT_Pragma;
6042 Gather_Associations (Names, Args);
6044 if No (Form) then
6045 Error_Pragma ("missing Form argument for pragma%");
6046 end if;
6048 Check_Arg_Is_Identifier (Form);
6050 -- Get proper alignment, note that Default = Component_Size on all
6051 -- machines we have so far, and we want to set this value rather
6052 -- than the default value to indicate that it has been explicitly
6053 -- set (and thus will not get overridden by the default component
6054 -- alignment for the current scope)
6056 if Chars (Form) = Name_Component_Size then
6057 Atype := Calign_Component_Size;
6059 elsif Chars (Form) = Name_Component_Size_4 then
6060 Atype := Calign_Component_Size_4;
6062 elsif Chars (Form) = Name_Default then
6063 Atype := Calign_Component_Size;
6065 elsif Chars (Form) = Name_Storage_Unit then
6066 Atype := Calign_Storage_Unit;
6068 else
6069 Error_Pragma_Arg
6070 ("invalid Form parameter for pragma%", Form);
6071 end if;
6073 -- Case with no name, supplied, affects scope table entry
6075 if No (Name) then
6076 Scope_Stack.Table
6077 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6079 -- Case of name supplied
6081 else
6082 Check_Arg_Is_Local_Name (Name);
6083 Find_Type (Name);
6084 Typ := Entity (Name);
6086 if Typ = Any_Type
6087 or else Rep_Item_Too_Early (Typ, N)
6088 then
6089 return;
6090 else
6091 Typ := Underlying_Type (Typ);
6092 end if;
6094 if not Is_Record_Type (Typ)
6095 and then not Is_Array_Type (Typ)
6096 then
6097 Error_Pragma_Arg
6098 ("Name parameter of pragma% must identify record or " &
6099 "array type", Name);
6100 end if;
6102 -- An explicit Component_Alignment pragma overrides an
6103 -- implicit pragma Pack, but not an explicit one.
6105 if not Has_Pragma_Pack (Base_Type (Typ)) then
6106 Set_Is_Packed (Base_Type (Typ), False);
6107 Set_Component_Alignment (Base_Type (Typ), Atype);
6108 end if;
6109 end if;
6110 end Component_AlignmentP;
6112 ----------------
6113 -- Controlled --
6114 ----------------
6116 -- pragma Controlled (first_subtype_LOCAL_NAME);
6118 when Pragma_Controlled => Controlled : declare
6119 Arg : Node_Id;
6121 begin
6122 Check_No_Identifiers;
6123 Check_Arg_Count (1);
6124 Check_Arg_Is_Local_Name (Arg1);
6125 Arg := Expression (Arg1);
6127 if not Is_Entity_Name (Arg)
6128 or else not Is_Access_Type (Entity (Arg))
6129 then
6130 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6131 else
6132 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6133 end if;
6134 end Controlled;
6136 ----------------
6137 -- Convention --
6138 ----------------
6140 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6141 -- [Entity =>] LOCAL_NAME);
6143 when Pragma_Convention => Convention : declare
6144 C : Convention_Id;
6145 E : Entity_Id;
6146 pragma Warnings (Off, C);
6147 pragma Warnings (Off, E);
6148 begin
6149 Check_Arg_Order ((Name_Convention, Name_Entity));
6150 Check_Ada_83_Warning;
6151 Check_Arg_Count (2);
6152 Process_Convention (C, E);
6153 end Convention;
6155 ---------------------------
6156 -- Convention_Identifier --
6157 ---------------------------
6159 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6160 -- [Convention =>] convention_IDENTIFIER);
6162 when Pragma_Convention_Identifier => Convention_Identifier : declare
6163 Idnam : Name_Id;
6164 Cname : Name_Id;
6166 begin
6167 GNAT_Pragma;
6168 Check_Arg_Order ((Name_Name, Name_Convention));
6169 Check_Arg_Count (2);
6170 Check_Optional_Identifier (Arg1, Name_Name);
6171 Check_Optional_Identifier (Arg2, Name_Convention);
6172 Check_Arg_Is_Identifier (Arg1);
6173 Check_Arg_Is_Identifier (Arg2);
6174 Idnam := Chars (Expression (Arg1));
6175 Cname := Chars (Expression (Arg2));
6177 if Is_Convention_Name (Cname) then
6178 Record_Convention_Identifier
6179 (Idnam, Get_Convention_Id (Cname));
6180 else
6181 Error_Pragma_Arg
6182 ("second arg for % pragma must be convention", Arg2);
6183 end if;
6184 end Convention_Identifier;
6186 ---------------
6187 -- CPP_Class --
6188 ---------------
6190 -- pragma CPP_Class ([Entity =>] local_NAME)
6192 when Pragma_CPP_Class => CPP_Class : declare
6193 Arg : Node_Id;
6194 Typ : Entity_Id;
6196 begin
6197 if Warn_On_Obsolescent_Feature then
6198 Error_Msg_N
6199 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6200 " by pragma import?", N);
6201 end if;
6203 GNAT_Pragma;
6204 Check_Arg_Count (1);
6205 Check_Optional_Identifier (Arg1, Name_Entity);
6206 Check_Arg_Is_Local_Name (Arg1);
6208 Arg := Expression (Arg1);
6209 Analyze (Arg);
6211 if Etype (Arg) = Any_Type then
6212 return;
6213 end if;
6215 if not Is_Entity_Name (Arg)
6216 or else not Is_Type (Entity (Arg))
6217 then
6218 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6219 end if;
6221 Typ := Entity (Arg);
6223 if not Is_Tagged_Type (Typ) then
6224 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6225 end if;
6227 -- Types treated as CPP classes are treated as limited, but we
6228 -- don't require them to be declared this way. A warning is issued
6229 -- to encourage the user to declare them as limited. This is not
6230 -- an error, for compatibility reasons, because these types have
6231 -- been supported this way for some time.
6233 if not Is_Limited_Type (Typ) then
6234 Error_Msg_N
6235 ("imported 'C'P'P type should be " &
6236 "explicitly declared limited?",
6237 Get_Pragma_Arg (Arg1));
6238 Error_Msg_N
6239 ("\type will be considered limited",
6240 Get_Pragma_Arg (Arg1));
6241 end if;
6243 Set_Is_CPP_Class (Typ);
6244 Set_Is_Limited_Record (Typ);
6245 Set_Convention (Typ, Convention_CPP);
6247 -- Imported CPP types must not have discriminants (because C++
6248 -- classes do not have discriminants).
6250 if Has_Discriminants (Typ) then
6251 Error_Msg_N
6252 ("imported 'C'P'P type cannot have discriminants",
6253 First (Discriminant_Specifications
6254 (Declaration_Node (Typ))));
6255 end if;
6257 -- Components of imported CPP types must not have default
6258 -- expressions because the constructor (if any) is in the
6259 -- C++ side.
6261 if Is_Incomplete_Or_Private_Type (Typ)
6262 and then No (Underlying_Type (Typ))
6263 then
6264 -- It should be an error to apply pragma CPP to a private
6265 -- type if the underlying type is not visible (as it is
6266 -- for any representation item). For now, for backward
6267 -- compatibility we do nothing but we cannot check components
6268 -- because they are not available at this stage. All this code
6269 -- will be removed when we cleanup this obsolete GNAT pragma???
6271 null;
6273 else
6274 declare
6275 Tdef : constant Node_Id :=
6276 Type_Definition (Declaration_Node (Typ));
6277 Clist : Node_Id;
6278 Comp : Node_Id;
6280 begin
6281 if Nkind (Tdef) = N_Record_Definition then
6282 Clist := Component_List (Tdef);
6283 else
6284 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
6285 Clist := Component_List (Record_Extension_Part (Tdef));
6286 end if;
6288 if Present (Clist) then
6289 Comp := First (Component_Items (Clist));
6290 while Present (Comp) loop
6291 if Present (Expression (Comp)) then
6292 Error_Msg_N
6293 ("component of imported 'C'P'P type cannot have" &
6294 " default expression", Expression (Comp));
6295 end if;
6297 Next (Comp);
6298 end loop;
6299 end if;
6300 end;
6301 end if;
6302 end CPP_Class;
6304 ---------------------
6305 -- CPP_Constructor --
6306 ---------------------
6308 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
6309 -- [, [External_Name =>] static_string_EXPRESSION ]
6310 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6312 when Pragma_CPP_Constructor => CPP_Constructor : declare
6313 Elmt : Elmt_Id;
6314 Id : Entity_Id;
6315 Def_Id : Entity_Id;
6316 Tag_Typ : Entity_Id;
6318 begin
6319 GNAT_Pragma;
6320 Check_At_Least_N_Arguments (1);
6321 Check_At_Most_N_Arguments (3);
6322 Check_Optional_Identifier (Arg1, Name_Entity);
6323 Check_Arg_Is_Local_Name (Arg1);
6325 Id := Expression (Arg1);
6326 Find_Program_Unit_Name (Id);
6328 -- If we did not find the name, we are done
6330 if Etype (Id) = Any_Type then
6331 return;
6332 end if;
6334 Def_Id := Entity (Id);
6336 if Ekind (Def_Id) = E_Function
6337 and then (Is_CPP_Class (Etype (Def_Id))
6338 or else (Is_Class_Wide_Type (Etype (Def_Id))
6339 and then
6340 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
6341 then
6342 if Arg_Count >= 2 then
6343 Set_Imported (Def_Id);
6344 Set_Is_Public (Def_Id);
6345 Process_Interface_Name (Def_Id, Arg2, Arg3);
6346 end if;
6348 Set_Has_Completion (Def_Id);
6349 Set_Is_Constructor (Def_Id);
6351 -- Imported C++ constructors are not dispatching primitives
6352 -- because in C++ they don't have a dispatch table slot.
6353 -- However, in Ada the constructor has the profile of a
6354 -- function that returns a tagged type and therefore it has
6355 -- been treated as a primitive operation during semantic
6356 -- analysis. We now remove it from the list of primitive
6357 -- operations of the type.
6359 if Is_Tagged_Type (Etype (Def_Id))
6360 and then not Is_Class_Wide_Type (Etype (Def_Id))
6361 then
6362 pragma Assert (Is_Dispatching_Operation (Def_Id));
6363 Tag_Typ := Etype (Def_Id);
6365 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
6366 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
6367 Next_Elmt (Elmt);
6368 end loop;
6370 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
6371 Set_Is_Dispatching_Operation (Def_Id, False);
6372 end if;
6374 -- For backward compatibility, if the constructor returns a
6375 -- class wide type, and we internally change the return type to
6376 -- the corresponding root type.
6378 if Is_Class_Wide_Type (Etype (Def_Id)) then
6379 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
6380 end if;
6381 else
6382 Error_Pragma_Arg
6383 ("pragma% requires function returning a 'C'P'P_Class type",
6384 Arg1);
6385 end if;
6386 end CPP_Constructor;
6388 -----------------
6389 -- CPP_Virtual --
6390 -----------------
6392 when Pragma_CPP_Virtual => CPP_Virtual : declare
6393 begin
6394 GNAT_Pragma;
6396 if Warn_On_Obsolescent_Feature then
6397 Error_Msg_N
6398 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
6399 "no effect?", N);
6400 end if;
6401 end CPP_Virtual;
6403 ----------------
6404 -- CPP_Vtable --
6405 ----------------
6407 when Pragma_CPP_Vtable => CPP_Vtable : declare
6408 begin
6409 GNAT_Pragma;
6411 if Warn_On_Obsolescent_Feature then
6412 Error_Msg_N
6413 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
6414 "no effect?", N);
6415 end if;
6416 end CPP_Vtable;
6418 -----------
6419 -- Debug --
6420 -----------
6422 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
6424 when Pragma_Debug => Debug : declare
6425 Cond : Node_Id;
6427 begin
6428 GNAT_Pragma;
6430 Cond :=
6431 New_Occurrence_Of
6432 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
6433 Loc);
6435 if Arg_Count = 2 then
6436 Cond :=
6437 Make_And_Then (Loc,
6438 Left_Opnd => Relocate_Node (Cond),
6439 Right_Opnd => Expression (Arg1));
6440 end if;
6442 -- Rewrite into a conditional with an appropriate condition. We
6443 -- wrap the procedure call in a block so that overhead from e.g.
6444 -- use of the secondary stack does not generate execution overhead
6445 -- for suppressed conditions.
6447 Rewrite (N, Make_Implicit_If_Statement (N,
6448 Condition => Cond,
6449 Then_Statements => New_List (
6450 Make_Block_Statement (Loc,
6451 Handled_Statement_Sequence =>
6452 Make_Handled_Sequence_Of_Statements (Loc,
6453 Statements => New_List (
6454 Relocate_Node (Debug_Statement (N))))))));
6455 Analyze (N);
6456 end Debug;
6458 ------------------
6459 -- Debug_Policy --
6460 ------------------
6462 -- pragma Debug_Policy (Check | Ignore)
6464 when Pragma_Debug_Policy =>
6465 GNAT_Pragma;
6466 Check_Arg_Count (1);
6467 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6468 Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
6470 ---------------------
6471 -- Detect_Blocking --
6472 ---------------------
6474 -- pragma Detect_Blocking;
6476 when Pragma_Detect_Blocking =>
6477 Ada_2005_Pragma;
6478 Check_Arg_Count (0);
6479 Check_Valid_Configuration_Pragma;
6480 Detect_Blocking := True;
6482 -------------------
6483 -- Discard_Names --
6484 -------------------
6486 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
6488 when Pragma_Discard_Names => Discard_Names : declare
6489 E : Entity_Id;
6490 E_Id : Entity_Id;
6492 begin
6493 Check_Ada_83_Warning;
6495 -- Deal with configuration pragma case
6497 if Arg_Count = 0 and then Is_Configuration_Pragma then
6498 Global_Discard_Names := True;
6499 return;
6501 -- Otherwise, check correct appropriate context
6503 else
6504 Check_Is_In_Decl_Part_Or_Package_Spec;
6506 if Arg_Count = 0 then
6508 -- If there is no parameter, then from now on this pragma
6509 -- applies to any enumeration, exception or tagged type
6510 -- defined in the current declarative part, and recursively
6511 -- to any nested scope.
6513 Set_Discard_Names (Current_Scope);
6514 return;
6516 else
6517 Check_Arg_Count (1);
6518 Check_Optional_Identifier (Arg1, Name_On);
6519 Check_Arg_Is_Local_Name (Arg1);
6521 E_Id := Expression (Arg1);
6523 if Etype (E_Id) = Any_Type then
6524 return;
6525 else
6526 E := Entity (E_Id);
6527 end if;
6529 if (Is_First_Subtype (E)
6530 and then
6531 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
6532 or else Ekind (E) = E_Exception
6533 then
6534 Set_Discard_Names (E);
6535 else
6536 Error_Pragma_Arg
6537 ("inappropriate entity for pragma%", Arg1);
6538 end if;
6540 end if;
6541 end if;
6542 end Discard_Names;
6544 ---------------
6545 -- Elaborate --
6546 ---------------
6548 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
6550 when Pragma_Elaborate => Elaborate : declare
6551 Arg : Node_Id;
6552 Citem : Node_Id;
6554 begin
6555 -- Pragma must be in context items list of a compilation unit
6557 if not Is_In_Context_Clause then
6558 Pragma_Misplaced;
6559 end if;
6561 -- Must be at least one argument
6563 if Arg_Count = 0 then
6564 Error_Pragma ("pragma% requires at least one argument");
6565 end if;
6567 -- In Ada 83 mode, there can be no items following it in the
6568 -- context list except other pragmas and implicit with clauses
6569 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
6570 -- placement rule does not apply.
6572 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
6573 Citem := Next (N);
6574 while Present (Citem) loop
6575 if Nkind (Citem) = N_Pragma
6576 or else (Nkind (Citem) = N_With_Clause
6577 and then Implicit_With (Citem))
6578 then
6579 null;
6580 else
6581 Error_Pragma
6582 ("(Ada 83) pragma% must be at end of context clause");
6583 end if;
6585 Next (Citem);
6586 end loop;
6587 end if;
6589 -- Finally, the arguments must all be units mentioned in a with
6590 -- clause in the same context clause. Note we already checked (in
6591 -- Par.Prag) that the arguments are all identifiers or selected
6592 -- components.
6594 Arg := Arg1;
6595 Outer : while Present (Arg) loop
6596 Citem := First (List_Containing (N));
6597 Inner : while Citem /= N loop
6598 if Nkind (Citem) = N_With_Clause
6599 and then Same_Name (Name (Citem), Expression (Arg))
6600 then
6601 Set_Elaborate_Present (Citem, True);
6602 Set_Unit_Name (Expression (Arg), Name (Citem));
6604 -- With the pragma present, elaboration calls on
6605 -- subprograms from the named unit need no further
6606 -- checks, as long as the pragma appears in the current
6607 -- compilation unit. If the pragma appears in some unit
6608 -- in the context, there might still be a need for an
6609 -- Elaborate_All_Desirable from the current compilation
6610 -- to the named unit, so we keep the check enabled.
6612 if In_Extended_Main_Source_Unit (N) then
6613 Set_Suppress_Elaboration_Warnings
6614 (Entity (Name (Citem)));
6615 end if;
6617 exit Inner;
6618 end if;
6620 Next (Citem);
6621 end loop Inner;
6623 if Citem = N then
6624 Error_Pragma_Arg
6625 ("argument of pragma% is not with'ed unit", Arg);
6626 end if;
6628 Next (Arg);
6629 end loop Outer;
6631 -- Give a warning if operating in static mode with -gnatwl
6632 -- (elaboration warnings enabled) switch set.
6634 if Elab_Warnings and not Dynamic_Elaboration_Checks then
6635 Error_Msg_N
6636 ("?use of pragma Elaborate may not be safe", N);
6637 Error_Msg_N
6638 ("?use pragma Elaborate_All instead if possible", N);
6639 end if;
6640 end Elaborate;
6642 -------------------
6643 -- Elaborate_All --
6644 -------------------
6646 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
6648 when Pragma_Elaborate_All => Elaborate_All : declare
6649 Arg : Node_Id;
6650 Citem : Node_Id;
6652 begin
6653 Check_Ada_83_Warning;
6655 -- Pragma must be in context items list of a compilation unit
6657 if not Is_In_Context_Clause then
6658 Pragma_Misplaced;
6659 end if;
6661 -- Must be at least one argument
6663 if Arg_Count = 0 then
6664 Error_Pragma ("pragma% requires at least one argument");
6665 end if;
6667 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
6668 -- have to appear at the end of the context clause, but may
6669 -- appear mixed in with other items, even in Ada 83 mode.
6671 -- Final check: the arguments must all be units mentioned in
6672 -- a with clause in the same context clause. Note that we
6673 -- already checked (in Par.Prag) that all the arguments are
6674 -- either identifiers or selected components.
6676 Arg := Arg1;
6677 Outr : while Present (Arg) loop
6678 Citem := First (List_Containing (N));
6679 Innr : while Citem /= N loop
6680 if Nkind (Citem) = N_With_Clause
6681 and then Same_Name (Name (Citem), Expression (Arg))
6682 then
6683 Set_Elaborate_All_Present (Citem, True);
6684 Set_Unit_Name (Expression (Arg), Name (Citem));
6686 -- Suppress warnings and elaboration checks on the named
6687 -- unit if the pragma is in the current compilation, as
6688 -- for pragma Elaborate.
6690 if In_Extended_Main_Source_Unit (N) then
6691 Set_Suppress_Elaboration_Warnings
6692 (Entity (Name (Citem)));
6693 end if;
6694 exit Innr;
6695 end if;
6697 Next (Citem);
6698 end loop Innr;
6700 if Citem = N then
6701 Set_Error_Posted (N);
6702 Error_Pragma_Arg
6703 ("argument of pragma% is not with'ed unit", Arg);
6704 end if;
6706 Next (Arg);
6707 end loop Outr;
6708 end Elaborate_All;
6710 --------------------
6711 -- Elaborate_Body --
6712 --------------------
6714 -- pragma Elaborate_Body [( library_unit_NAME )];
6716 when Pragma_Elaborate_Body => Elaborate_Body : declare
6717 Cunit_Node : Node_Id;
6718 Cunit_Ent : Entity_Id;
6720 begin
6721 Check_Ada_83_Warning;
6722 Check_Valid_Library_Unit_Pragma;
6724 if Nkind (N) = N_Null_Statement then
6725 return;
6726 end if;
6728 Cunit_Node := Cunit (Current_Sem_Unit);
6729 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
6731 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
6732 N_Subprogram_Body)
6733 then
6734 Error_Pragma ("pragma% must refer to a spec, not a body");
6735 else
6736 Set_Body_Required (Cunit_Node, True);
6737 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
6739 -- If we are in dynamic elaboration mode, then we suppress
6740 -- elaboration warnings for the unit, since it is definitely
6741 -- fine NOT to do dynamic checks at the first level (and such
6742 -- checks will be suppressed because no elaboration boolean
6743 -- is created for Elaborate_Body packages).
6745 -- But in the static model of elaboration, Elaborate_Body is
6746 -- definitely NOT good enough to ensure elaboration safety on
6747 -- its own, since the body may WITH other units that are not
6748 -- safe from an elaboration point of view, so a client must
6749 -- still do an Elaborate_All on such units.
6751 -- Debug flag -gnatdD restores the old behavior of 3.13, where
6752 -- Elaborate_Body always suppressed elab warnings.
6754 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
6755 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
6756 end if;
6757 end if;
6758 end Elaborate_Body;
6760 ------------------------
6761 -- Elaboration_Checks --
6762 ------------------------
6764 -- pragma Elaboration_Checks (Static | Dynamic);
6766 when Pragma_Elaboration_Checks =>
6767 GNAT_Pragma;
6768 Check_Arg_Count (1);
6769 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
6770 Dynamic_Elaboration_Checks :=
6771 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
6773 ---------------
6774 -- Eliminate --
6775 ---------------
6777 -- pragma Eliminate (
6778 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
6779 -- [,[Entity =>] IDENTIFIER |
6780 -- SELECTED_COMPONENT |
6781 -- STRING_LITERAL]
6782 -- [, OVERLOADING_RESOLUTION]);
6784 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
6785 -- SOURCE_LOCATION
6787 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
6788 -- FUNCTION_PROFILE
6790 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
6792 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
6793 -- Result_Type => result_SUBTYPE_NAME]
6795 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
6796 -- SUBTYPE_NAME ::= STRING_LITERAL
6798 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
6799 -- SOURCE_TRACE ::= STRING_LITERAL
6801 when Pragma_Eliminate => Eliminate : declare
6802 Args : Args_List (1 .. 5);
6803 Names : constant Name_List (1 .. 5) := (
6804 Name_Unit_Name,
6805 Name_Entity,
6806 Name_Parameter_Types,
6807 Name_Result_Type,
6808 Name_Source_Location);
6810 Unit_Name : Node_Id renames Args (1);
6811 Entity : Node_Id renames Args (2);
6812 Parameter_Types : Node_Id renames Args (3);
6813 Result_Type : Node_Id renames Args (4);
6814 Source_Location : Node_Id renames Args (5);
6816 begin
6817 GNAT_Pragma;
6818 Check_Valid_Configuration_Pragma;
6819 Gather_Associations (Names, Args);
6821 if No (Unit_Name) then
6822 Error_Pragma ("missing Unit_Name argument for pragma%");
6823 end if;
6825 if No (Entity)
6826 and then (Present (Parameter_Types)
6827 or else
6828 Present (Result_Type)
6829 or else
6830 Present (Source_Location))
6831 then
6832 Error_Pragma ("missing Entity argument for pragma%");
6833 end if;
6835 if (Present (Parameter_Types)
6836 or else
6837 Present (Result_Type))
6838 and then
6839 Present (Source_Location)
6840 then
6841 Error_Pragma
6842 ("parameter profile and source location cannot " &
6843 "be used together in pragma%");
6844 end if;
6846 Process_Eliminate_Pragma
6848 Unit_Name,
6849 Entity,
6850 Parameter_Types,
6851 Result_Type,
6852 Source_Location);
6853 end Eliminate;
6855 ------------
6856 -- Export --
6857 ------------
6859 -- pragma Export (
6860 -- [ Convention =>] convention_IDENTIFIER,
6861 -- [ Entity =>] local_NAME
6862 -- [, [External_Name =>] static_string_EXPRESSION ]
6863 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6865 when Pragma_Export => Export : declare
6866 C : Convention_Id;
6867 Def_Id : Entity_Id;
6869 pragma Warnings (Off, C);
6871 begin
6872 Check_Ada_83_Warning;
6873 Check_Arg_Order
6874 ((Name_Convention,
6875 Name_Entity,
6876 Name_External_Name,
6877 Name_Link_Name));
6878 Check_At_Least_N_Arguments (2);
6879 Check_At_Most_N_Arguments (4);
6880 Process_Convention (C, Def_Id);
6882 if Ekind (Def_Id) /= E_Constant then
6883 Note_Possible_Modification (Expression (Arg2), Sure => False);
6884 end if;
6886 Process_Interface_Name (Def_Id, Arg3, Arg4);
6887 Set_Exported (Def_Id, Arg2);
6889 -- If the entity is a deferred constant, propagate the information
6890 -- to the full view, because gigi elaborates the full view only.
6892 if Ekind (Def_Id) = E_Constant
6893 and then Present (Full_View (Def_Id))
6894 then
6895 declare
6896 Id2 : constant Entity_Id := Full_View (Def_Id);
6897 begin
6898 Set_Is_Exported (Id2, Is_Exported (Def_Id));
6899 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
6900 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
6901 end;
6902 end if;
6903 end Export;
6905 ----------------------
6906 -- Export_Exception --
6907 ----------------------
6909 -- pragma Export_Exception (
6910 -- [Internal =>] LOCAL_NAME
6911 -- [, [External =>] EXTERNAL_SYMBOL]
6912 -- [, [Form =>] Ada | VMS]
6913 -- [, [Code =>] static_integer_EXPRESSION]);
6915 when Pragma_Export_Exception => Export_Exception : declare
6916 Args : Args_List (1 .. 4);
6917 Names : constant Name_List (1 .. 4) := (
6918 Name_Internal,
6919 Name_External,
6920 Name_Form,
6921 Name_Code);
6923 Internal : Node_Id renames Args (1);
6924 External : Node_Id renames Args (2);
6925 Form : Node_Id renames Args (3);
6926 Code : Node_Id renames Args (4);
6928 begin
6929 GNAT_Pragma;
6931 if Inside_A_Generic then
6932 Error_Pragma ("pragma% cannot be used for generic entities");
6933 end if;
6935 Gather_Associations (Names, Args);
6936 Process_Extended_Import_Export_Exception_Pragma (
6937 Arg_Internal => Internal,
6938 Arg_External => External,
6939 Arg_Form => Form,
6940 Arg_Code => Code);
6942 if not Is_VMS_Exception (Entity (Internal)) then
6943 Set_Exported (Entity (Internal), Internal);
6944 end if;
6945 end Export_Exception;
6947 ---------------------
6948 -- Export_Function --
6949 ---------------------
6951 -- pragma Export_Function (
6952 -- [Internal =>] LOCAL_NAME
6953 -- [, [External =>] EXTERNAL_SYMBOL]
6954 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6955 -- [, [Result_Type =>] TYPE_DESIGNATOR]
6956 -- [, [Mechanism =>] MECHANISM]
6957 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
6959 -- EXTERNAL_SYMBOL ::=
6960 -- IDENTIFIER
6961 -- | static_string_EXPRESSION
6963 -- PARAMETER_TYPES ::=
6964 -- null
6965 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6967 -- TYPE_DESIGNATOR ::=
6968 -- subtype_NAME
6969 -- | subtype_Name ' Access
6971 -- MECHANISM ::=
6972 -- MECHANISM_NAME
6973 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6975 -- MECHANISM_ASSOCIATION ::=
6976 -- [formal_parameter_NAME =>] MECHANISM_NAME
6978 -- MECHANISM_NAME ::=
6979 -- Value
6980 -- | Reference
6981 -- | Descriptor [([Class =>] CLASS_NAME)]
6983 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6985 when Pragma_Export_Function => Export_Function : declare
6986 Args : Args_List (1 .. 6);
6987 Names : constant Name_List (1 .. 6) := (
6988 Name_Internal,
6989 Name_External,
6990 Name_Parameter_Types,
6991 Name_Result_Type,
6992 Name_Mechanism,
6993 Name_Result_Mechanism);
6995 Internal : Node_Id renames Args (1);
6996 External : Node_Id renames Args (2);
6997 Parameter_Types : Node_Id renames Args (3);
6998 Result_Type : Node_Id renames Args (4);
6999 Mechanism : Node_Id renames Args (5);
7000 Result_Mechanism : Node_Id renames Args (6);
7002 begin
7003 GNAT_Pragma;
7004 Gather_Associations (Names, Args);
7005 Process_Extended_Import_Export_Subprogram_Pragma (
7006 Arg_Internal => Internal,
7007 Arg_External => External,
7008 Arg_Parameter_Types => Parameter_Types,
7009 Arg_Result_Type => Result_Type,
7010 Arg_Mechanism => Mechanism,
7011 Arg_Result_Mechanism => Result_Mechanism);
7012 end Export_Function;
7014 -------------------
7015 -- Export_Object --
7016 -------------------
7018 -- pragma Export_Object (
7019 -- [Internal =>] LOCAL_NAME
7020 -- [, [External =>] EXTERNAL_SYMBOL]
7021 -- [, [Size =>] EXTERNAL_SYMBOL]);
7023 -- EXTERNAL_SYMBOL ::=
7024 -- IDENTIFIER
7025 -- | static_string_EXPRESSION
7027 -- PARAMETER_TYPES ::=
7028 -- null
7029 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7031 -- TYPE_DESIGNATOR ::=
7032 -- subtype_NAME
7033 -- | subtype_Name ' Access
7035 -- MECHANISM ::=
7036 -- MECHANISM_NAME
7037 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7039 -- MECHANISM_ASSOCIATION ::=
7040 -- [formal_parameter_NAME =>] MECHANISM_NAME
7042 -- MECHANISM_NAME ::=
7043 -- Value
7044 -- | Reference
7045 -- | Descriptor [([Class =>] CLASS_NAME)]
7047 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7049 when Pragma_Export_Object => Export_Object : declare
7050 Args : Args_List (1 .. 3);
7051 Names : constant Name_List (1 .. 3) := (
7052 Name_Internal,
7053 Name_External,
7054 Name_Size);
7056 Internal : Node_Id renames Args (1);
7057 External : Node_Id renames Args (2);
7058 Size : Node_Id renames Args (3);
7060 begin
7061 GNAT_Pragma;
7062 Gather_Associations (Names, Args);
7063 Process_Extended_Import_Export_Object_Pragma (
7064 Arg_Internal => Internal,
7065 Arg_External => External,
7066 Arg_Size => Size);
7067 end Export_Object;
7069 ----------------------
7070 -- Export_Procedure --
7071 ----------------------
7073 -- pragma Export_Procedure (
7074 -- [Internal =>] LOCAL_NAME
7075 -- [, [External =>] EXTERNAL_SYMBOL]
7076 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7077 -- [, [Mechanism =>] MECHANISM]);
7079 -- EXTERNAL_SYMBOL ::=
7080 -- IDENTIFIER
7081 -- | static_string_EXPRESSION
7083 -- PARAMETER_TYPES ::=
7084 -- null
7085 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7087 -- TYPE_DESIGNATOR ::=
7088 -- subtype_NAME
7089 -- | subtype_Name ' Access
7091 -- MECHANISM ::=
7092 -- MECHANISM_NAME
7093 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7095 -- MECHANISM_ASSOCIATION ::=
7096 -- [formal_parameter_NAME =>] MECHANISM_NAME
7098 -- MECHANISM_NAME ::=
7099 -- Value
7100 -- | Reference
7101 -- | Descriptor [([Class =>] CLASS_NAME)]
7103 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7105 when Pragma_Export_Procedure => Export_Procedure : declare
7106 Args : Args_List (1 .. 4);
7107 Names : constant Name_List (1 .. 4) := (
7108 Name_Internal,
7109 Name_External,
7110 Name_Parameter_Types,
7111 Name_Mechanism);
7113 Internal : Node_Id renames Args (1);
7114 External : Node_Id renames Args (2);
7115 Parameter_Types : Node_Id renames Args (3);
7116 Mechanism : Node_Id renames Args (4);
7118 begin
7119 GNAT_Pragma;
7120 Gather_Associations (Names, Args);
7121 Process_Extended_Import_Export_Subprogram_Pragma (
7122 Arg_Internal => Internal,
7123 Arg_External => External,
7124 Arg_Parameter_Types => Parameter_Types,
7125 Arg_Mechanism => Mechanism);
7126 end Export_Procedure;
7128 ------------------
7129 -- Export_Value --
7130 ------------------
7132 -- pragma Export_Value (
7133 -- [Value =>] static_integer_EXPRESSION,
7134 -- [Link_Name =>] static_string_EXPRESSION);
7136 when Pragma_Export_Value =>
7137 GNAT_Pragma;
7138 Check_Arg_Order ((Name_Value, Name_Link_Name));
7139 Check_Arg_Count (2);
7141 Check_Optional_Identifier (Arg1, Name_Value);
7142 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7144 Check_Optional_Identifier (Arg2, Name_Link_Name);
7145 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7147 -----------------------------
7148 -- Export_Valued_Procedure --
7149 -----------------------------
7151 -- pragma Export_Valued_Procedure (
7152 -- [Internal =>] LOCAL_NAME
7153 -- [, [External =>] EXTERNAL_SYMBOL,]
7154 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7155 -- [, [Mechanism =>] MECHANISM]);
7157 -- EXTERNAL_SYMBOL ::=
7158 -- IDENTIFIER
7159 -- | static_string_EXPRESSION
7161 -- PARAMETER_TYPES ::=
7162 -- null
7163 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7165 -- TYPE_DESIGNATOR ::=
7166 -- subtype_NAME
7167 -- | subtype_Name ' Access
7169 -- MECHANISM ::=
7170 -- MECHANISM_NAME
7171 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7173 -- MECHANISM_ASSOCIATION ::=
7174 -- [formal_parameter_NAME =>] MECHANISM_NAME
7176 -- MECHANISM_NAME ::=
7177 -- Value
7178 -- | Reference
7179 -- | Descriptor [([Class =>] CLASS_NAME)]
7181 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7183 when Pragma_Export_Valued_Procedure =>
7184 Export_Valued_Procedure : declare
7185 Args : Args_List (1 .. 4);
7186 Names : constant Name_List (1 .. 4) := (
7187 Name_Internal,
7188 Name_External,
7189 Name_Parameter_Types,
7190 Name_Mechanism);
7192 Internal : Node_Id renames Args (1);
7193 External : Node_Id renames Args (2);
7194 Parameter_Types : Node_Id renames Args (3);
7195 Mechanism : Node_Id renames Args (4);
7197 begin
7198 GNAT_Pragma;
7199 Gather_Associations (Names, Args);
7200 Process_Extended_Import_Export_Subprogram_Pragma (
7201 Arg_Internal => Internal,
7202 Arg_External => External,
7203 Arg_Parameter_Types => Parameter_Types,
7204 Arg_Mechanism => Mechanism);
7205 end Export_Valued_Procedure;
7207 -------------------
7208 -- Extend_System --
7209 -------------------
7211 -- pragma Extend_System ([Name =>] Identifier);
7213 when Pragma_Extend_System => Extend_System : declare
7214 begin
7215 GNAT_Pragma;
7216 Check_Valid_Configuration_Pragma;
7217 Check_Arg_Count (1);
7218 Check_Optional_Identifier (Arg1, Name_Name);
7219 Check_Arg_Is_Identifier (Arg1);
7221 Get_Name_String (Chars (Expression (Arg1)));
7223 if Name_Len > 4
7224 and then Name_Buffer (1 .. 4) = "aux_"
7225 then
7226 if Present (System_Extend_Pragma_Arg) then
7227 if Chars (Expression (Arg1)) =
7228 Chars (Expression (System_Extend_Pragma_Arg))
7229 then
7230 null;
7231 else
7232 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
7233 Error_Pragma ("pragma% conflicts with that #");
7234 end if;
7236 else
7237 System_Extend_Pragma_Arg := Arg1;
7239 if not GNAT_Mode then
7240 System_Extend_Unit := Arg1;
7241 end if;
7242 end if;
7243 else
7244 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
7245 end if;
7246 end Extend_System;
7248 ------------------------
7249 -- Extensions_Allowed --
7250 ------------------------
7252 -- pragma Extensions_Allowed (ON | OFF);
7254 when Pragma_Extensions_Allowed =>
7255 GNAT_Pragma;
7256 Check_Arg_Count (1);
7257 Check_No_Identifiers;
7258 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7260 if Chars (Expression (Arg1)) = Name_On then
7261 Extensions_Allowed := True;
7262 else
7263 Extensions_Allowed := False;
7264 end if;
7266 --------------
7267 -- External --
7268 --------------
7270 -- pragma External (
7271 -- [ Convention =>] convention_IDENTIFIER,
7272 -- [ Entity =>] local_NAME
7273 -- [, [External_Name =>] static_string_EXPRESSION ]
7274 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7276 when Pragma_External => External : declare
7277 Def_Id : Entity_Id;
7279 C : Convention_Id;
7280 pragma Warnings (Off, C);
7282 begin
7283 GNAT_Pragma;
7284 Check_Arg_Order
7285 ((Name_Convention,
7286 Name_Entity,
7287 Name_External_Name,
7288 Name_Link_Name));
7289 Check_At_Least_N_Arguments (2);
7290 Check_At_Most_N_Arguments (4);
7291 Process_Convention (C, Def_Id);
7292 Note_Possible_Modification (Expression (Arg2), Sure => False);
7293 Process_Interface_Name (Def_Id, Arg3, Arg4);
7294 Set_Exported (Def_Id, Arg2);
7295 end External;
7297 --------------------------
7298 -- External_Name_Casing --
7299 --------------------------
7301 -- pragma External_Name_Casing (
7302 -- UPPERCASE | LOWERCASE
7303 -- [, AS_IS | UPPERCASE | LOWERCASE]);
7305 when Pragma_External_Name_Casing => External_Name_Casing : declare
7306 begin
7307 GNAT_Pragma;
7308 Check_No_Identifiers;
7310 if Arg_Count = 2 then
7311 Check_Arg_Is_One_Of
7312 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
7314 case Chars (Get_Pragma_Arg (Arg2)) is
7315 when Name_As_Is =>
7316 Opt.External_Name_Exp_Casing := As_Is;
7318 when Name_Uppercase =>
7319 Opt.External_Name_Exp_Casing := Uppercase;
7321 when Name_Lowercase =>
7322 Opt.External_Name_Exp_Casing := Lowercase;
7324 when others =>
7325 null;
7326 end case;
7328 else
7329 Check_Arg_Count (1);
7330 end if;
7332 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
7334 case Chars (Get_Pragma_Arg (Arg1)) is
7335 when Name_Uppercase =>
7336 Opt.External_Name_Imp_Casing := Uppercase;
7338 when Name_Lowercase =>
7339 Opt.External_Name_Imp_Casing := Lowercase;
7341 when others =>
7342 null;
7343 end case;
7344 end External_Name_Casing;
7346 --------------------------
7347 -- Favor_Top_Level --
7348 --------------------------
7350 -- pragma Favor_Top_Level (type_NAME);
7352 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
7353 Named_Entity : Entity_Id;
7355 begin
7356 GNAT_Pragma;
7357 Check_No_Identifiers;
7358 Check_Arg_Count (1);
7359 Check_Arg_Is_Local_Name (Arg1);
7360 Named_Entity := Entity (Expression (Arg1));
7362 -- If it's an access-to-subprogram type (in particular, not a
7363 -- subtype), set the flag on that type.
7365 if Is_Access_Subprogram_Type (Named_Entity) then
7366 Set_Can_Use_Internal_Rep (Named_Entity, False);
7368 -- Otherwise it's an error (name denotes the wrong sort of entity)
7370 else
7371 Error_Pragma_Arg
7372 ("access-to-subprogram type expected", Expression (Arg1));
7373 end if;
7374 end Favor_Top_Level;
7376 ---------------
7377 -- Fast_Math --
7378 ---------------
7380 -- pragma Fast_Math;
7382 when Pragma_Fast_Math =>
7383 GNAT_Pragma;
7384 Check_No_Identifiers;
7385 Check_Valid_Configuration_Pragma;
7386 Fast_Math := True;
7388 ---------------------------
7389 -- Finalize_Storage_Only --
7390 ---------------------------
7392 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
7394 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
7395 Assoc : constant Node_Id := Arg1;
7396 Type_Id : constant Node_Id := Expression (Assoc);
7397 Typ : Entity_Id;
7399 begin
7400 GNAT_Pragma;
7401 Check_No_Identifiers;
7402 Check_Arg_Count (1);
7403 Check_Arg_Is_Local_Name (Arg1);
7405 Find_Type (Type_Id);
7406 Typ := Entity (Type_Id);
7408 if Typ = Any_Type
7409 or else Rep_Item_Too_Early (Typ, N)
7410 then
7411 return;
7412 else
7413 Typ := Underlying_Type (Typ);
7414 end if;
7416 if not Is_Controlled (Typ) then
7417 Error_Pragma ("pragma% must specify controlled type");
7418 end if;
7420 Check_First_Subtype (Arg1);
7422 if Finalize_Storage_Only (Typ) then
7423 Error_Pragma ("duplicate pragma%, only one allowed");
7425 elsif not Rep_Item_Too_Late (Typ, N) then
7426 Set_Finalize_Storage_Only (Base_Type (Typ), True);
7427 end if;
7428 end Finalize_Storage;
7430 --------------------------
7431 -- Float_Representation --
7432 --------------------------
7434 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
7436 -- FLOAT_REP ::= VAX_Float | IEEE_Float
7438 when Pragma_Float_Representation => Float_Representation : declare
7439 Argx : Node_Id;
7440 Digs : Nat;
7441 Ent : Entity_Id;
7443 begin
7444 GNAT_Pragma;
7446 if Arg_Count = 1 then
7447 Check_Valid_Configuration_Pragma;
7448 else
7449 Check_Arg_Count (2);
7450 Check_Optional_Identifier (Arg2, Name_Entity);
7451 Check_Arg_Is_Local_Name (Arg2);
7452 end if;
7454 Check_No_Identifier (Arg1);
7455 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
7457 if not OpenVMS_On_Target then
7458 if Chars (Expression (Arg1)) = Name_VAX_Float then
7459 Error_Pragma
7460 ("?pragma% ignored (applies only to Open'V'M'S)");
7461 end if;
7463 return;
7464 end if;
7466 -- One argument case
7468 if Arg_Count = 1 then
7469 if Chars (Expression (Arg1)) = Name_VAX_Float then
7470 if Opt.Float_Format = 'I' then
7471 Error_Pragma ("'I'E'E'E format previously specified");
7472 end if;
7474 Opt.Float_Format := 'V';
7476 else
7477 if Opt.Float_Format = 'V' then
7478 Error_Pragma ("'V'A'X format previously specified");
7479 end if;
7481 Opt.Float_Format := 'I';
7482 end if;
7484 Set_Standard_Fpt_Formats;
7486 -- Two argument case
7488 else
7489 Argx := Get_Pragma_Arg (Arg2);
7491 if not Is_Entity_Name (Argx)
7492 or else not Is_Floating_Point_Type (Entity (Argx))
7493 then
7494 Error_Pragma_Arg
7495 ("second argument of% pragma must be floating-point type",
7496 Arg2);
7497 end if;
7499 Ent := Entity (Argx);
7500 Digs := UI_To_Int (Digits_Value (Ent));
7502 -- Two arguments, VAX_Float case
7504 if Chars (Expression (Arg1)) = Name_VAX_Float then
7505 case Digs is
7506 when 6 => Set_F_Float (Ent);
7507 when 9 => Set_D_Float (Ent);
7508 when 15 => Set_G_Float (Ent);
7510 when others =>
7511 Error_Pragma_Arg
7512 ("wrong digits value, must be 6,9 or 15", Arg2);
7513 end case;
7515 -- Two arguments, IEEE_Float case
7517 else
7518 case Digs is
7519 when 6 => Set_IEEE_Short (Ent);
7520 when 15 => Set_IEEE_Long (Ent);
7522 when others =>
7523 Error_Pragma_Arg
7524 ("wrong digits value, must be 6 or 15", Arg2);
7525 end case;
7526 end if;
7527 end if;
7528 end Float_Representation;
7530 -----------
7531 -- Ident --
7532 -----------
7534 -- pragma Ident (static_string_EXPRESSION)
7536 -- Note: pragma Comment shares this processing. Pragma Comment is
7537 -- identical to Ident, except that the restriction of the argument to
7538 -- 31 characters and the placement restrictions are not enforced for
7539 -- pragma Comment.
7541 when Pragma_Ident | Pragma_Comment => Ident : declare
7542 Str : Node_Id;
7544 begin
7545 GNAT_Pragma;
7546 Check_Arg_Count (1);
7547 Check_No_Identifiers;
7548 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7550 -- For pragma Ident, preserve DEC compatibility by requiring the
7551 -- pragma to appear in a declarative part or package spec.
7553 if Prag_Id = Pragma_Ident then
7554 Check_Is_In_Decl_Part_Or_Package_Spec;
7555 end if;
7557 Str := Expr_Value_S (Expression (Arg1));
7559 declare
7560 CS : Node_Id;
7561 GP : Node_Id;
7563 begin
7564 GP := Parent (Parent (N));
7566 if Nkind_In (GP, N_Package_Declaration,
7567 N_Generic_Package_Declaration)
7568 then
7569 GP := Parent (GP);
7570 end if;
7572 -- If we have a compilation unit, then record the ident value,
7573 -- checking for improper duplication.
7575 if Nkind (GP) = N_Compilation_Unit then
7576 CS := Ident_String (Current_Sem_Unit);
7578 if Present (CS) then
7580 -- For Ident, we do not permit multiple instances
7582 if Prag_Id = Pragma_Ident then
7583 Error_Pragma ("duplicate% pragma not permitted");
7585 -- For Comment, we concatenate the string, unless we want
7586 -- to preserve the tree structure for ASIS.
7588 elsif not ASIS_Mode then
7589 Start_String (Strval (CS));
7590 Store_String_Char (' ');
7591 Store_String_Chars (Strval (Str));
7592 Set_Strval (CS, End_String);
7593 end if;
7595 else
7596 -- In VMS, the effect of IDENT is achieved by passing
7597 -- IDENTIFICATION=name as a --for-linker switch.
7599 if OpenVMS_On_Target then
7600 Start_String;
7601 Store_String_Chars
7602 ("--for-linker=IDENTIFICATION=");
7603 String_To_Name_Buffer (Strval (Str));
7604 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7606 -- Only the last processed IDENT is saved. The main
7607 -- purpose is so an IDENT associated with a main
7608 -- procedure will be used in preference to an IDENT
7609 -- associated with a with'd package.
7611 Replace_Linker_Option_String
7612 (End_String, "--for-linker=IDENTIFICATION=");
7613 end if;
7615 Set_Ident_String (Current_Sem_Unit, Str);
7616 end if;
7618 -- For subunits, we just ignore the Ident, since in GNAT these
7619 -- are not separate object files, and hence not separate units
7620 -- in the unit table.
7622 elsif Nkind (GP) = N_Subunit then
7623 null;
7625 -- Otherwise we have a misplaced pragma Ident, but we ignore
7626 -- this if we are in an instantiation, since it comes from
7627 -- a generic, and has no relevance to the instantiation.
7629 elsif Prag_Id = Pragma_Ident then
7630 if Instantiation_Location (Loc) = No_Location then
7631 Error_Pragma ("pragma% only allowed at outer level");
7632 end if;
7633 end if;
7634 end;
7635 end Ident;
7637 --------------------------
7638 -- Implemented_By_Entry --
7639 --------------------------
7641 -- pragma Implemented_By_Entry (DIRECT_NAME);
7643 when Pragma_Implemented_By_Entry => Implemented_By_Entry : declare
7644 Ent : Entity_Id;
7646 begin
7647 Ada_2005_Pragma;
7648 Check_Arg_Count (1);
7649 Check_No_Identifiers;
7650 Check_Arg_Is_Identifier (Arg1);
7651 Check_Arg_Is_Local_Name (Arg1);
7652 Ent := Entity (Expression (Arg1));
7654 -- Pragma Implemented_By_Entry must be applied only to protected
7655 -- synchronized or task interface primitives.
7657 if (Ekind (Ent) /= E_Function
7658 and then Ekind (Ent) /= E_Procedure)
7659 or else not Present (First_Formal (Ent))
7660 or else not Is_Concurrent_Interface (Etype (First_Formal (Ent)))
7661 then
7662 Error_Pragma_Arg
7663 ("pragma % must be applied to a concurrent interface " &
7664 "primitive", Arg1);
7666 else
7667 if Einfo.Implemented_By_Entry (Ent)
7668 and then Warn_On_Redundant_Constructs
7669 then
7670 Error_Pragma ("?duplicate pragma%!");
7671 else
7672 Set_Implemented_By_Entry (Ent);
7673 end if;
7674 end if;
7675 end Implemented_By_Entry;
7677 -----------------------
7678 -- Implicit_Packing --
7679 -----------------------
7681 -- pragma Implicit_Packing;
7683 when Pragma_Implicit_Packing =>
7684 GNAT_Pragma;
7685 Check_Arg_Count (0);
7686 Implicit_Packing := True;
7688 ------------
7689 -- Import --
7690 ------------
7692 -- pragma Import (
7693 -- [Convention =>] convention_IDENTIFIER,
7694 -- [Entity =>] local_NAME
7695 -- [, [External_Name =>] static_string_EXPRESSION ]
7696 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7698 when Pragma_Import =>
7699 Check_Ada_83_Warning;
7700 Check_Arg_Order
7701 ((Name_Convention,
7702 Name_Entity,
7703 Name_External_Name,
7704 Name_Link_Name));
7705 Check_At_Least_N_Arguments (2);
7706 Check_At_Most_N_Arguments (4);
7707 Process_Import_Or_Interface;
7709 ----------------------
7710 -- Import_Exception --
7711 ----------------------
7713 -- pragma Import_Exception (
7714 -- [Internal =>] LOCAL_NAME
7715 -- [, [External =>] EXTERNAL_SYMBOL]
7716 -- [, [Form =>] Ada | VMS]
7717 -- [, [Code =>] static_integer_EXPRESSION]);
7719 when Pragma_Import_Exception => Import_Exception : declare
7720 Args : Args_List (1 .. 4);
7721 Names : constant Name_List (1 .. 4) := (
7722 Name_Internal,
7723 Name_External,
7724 Name_Form,
7725 Name_Code);
7727 Internal : Node_Id renames Args (1);
7728 External : Node_Id renames Args (2);
7729 Form : Node_Id renames Args (3);
7730 Code : Node_Id renames Args (4);
7732 begin
7733 GNAT_Pragma;
7734 Gather_Associations (Names, Args);
7736 if Present (External) and then Present (Code) then
7737 Error_Pragma
7738 ("cannot give both External and Code options for pragma%");
7739 end if;
7741 Process_Extended_Import_Export_Exception_Pragma (
7742 Arg_Internal => Internal,
7743 Arg_External => External,
7744 Arg_Form => Form,
7745 Arg_Code => Code);
7747 if not Is_VMS_Exception (Entity (Internal)) then
7748 Set_Imported (Entity (Internal));
7749 end if;
7750 end Import_Exception;
7752 ---------------------
7753 -- Import_Function --
7754 ---------------------
7756 -- pragma Import_Function (
7757 -- [Internal =>] LOCAL_NAME,
7758 -- [, [External =>] EXTERNAL_SYMBOL]
7759 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7760 -- [, [Result_Type =>] SUBTYPE_MARK]
7761 -- [, [Mechanism =>] MECHANISM]
7762 -- [, [Result_Mechanism =>] MECHANISM_NAME]
7763 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7765 -- EXTERNAL_SYMBOL ::=
7766 -- IDENTIFIER
7767 -- | static_string_EXPRESSION
7769 -- PARAMETER_TYPES ::=
7770 -- null
7771 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7773 -- TYPE_DESIGNATOR ::=
7774 -- subtype_NAME
7775 -- | subtype_Name ' Access
7777 -- MECHANISM ::=
7778 -- MECHANISM_NAME
7779 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7781 -- MECHANISM_ASSOCIATION ::=
7782 -- [formal_parameter_NAME =>] MECHANISM_NAME
7784 -- MECHANISM_NAME ::=
7785 -- Value
7786 -- | Reference
7787 -- | Descriptor [([Class =>] CLASS_NAME)]
7789 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7791 when Pragma_Import_Function => Import_Function : declare
7792 Args : Args_List (1 .. 7);
7793 Names : constant Name_List (1 .. 7) := (
7794 Name_Internal,
7795 Name_External,
7796 Name_Parameter_Types,
7797 Name_Result_Type,
7798 Name_Mechanism,
7799 Name_Result_Mechanism,
7800 Name_First_Optional_Parameter);
7802 Internal : Node_Id renames Args (1);
7803 External : Node_Id renames Args (2);
7804 Parameter_Types : Node_Id renames Args (3);
7805 Result_Type : Node_Id renames Args (4);
7806 Mechanism : Node_Id renames Args (5);
7807 Result_Mechanism : Node_Id renames Args (6);
7808 First_Optional_Parameter : Node_Id renames Args (7);
7810 begin
7811 GNAT_Pragma;
7812 Gather_Associations (Names, Args);
7813 Process_Extended_Import_Export_Subprogram_Pragma (
7814 Arg_Internal => Internal,
7815 Arg_External => External,
7816 Arg_Parameter_Types => Parameter_Types,
7817 Arg_Result_Type => Result_Type,
7818 Arg_Mechanism => Mechanism,
7819 Arg_Result_Mechanism => Result_Mechanism,
7820 Arg_First_Optional_Parameter => First_Optional_Parameter);
7821 end Import_Function;
7823 -------------------
7824 -- Import_Object --
7825 -------------------
7827 -- pragma Import_Object (
7828 -- [Internal =>] LOCAL_NAME
7829 -- [, [External =>] EXTERNAL_SYMBOL]
7830 -- [, [Size =>] EXTERNAL_SYMBOL]);
7832 -- EXTERNAL_SYMBOL ::=
7833 -- IDENTIFIER
7834 -- | static_string_EXPRESSION
7836 when Pragma_Import_Object => Import_Object : declare
7837 Args : Args_List (1 .. 3);
7838 Names : constant Name_List (1 .. 3) := (
7839 Name_Internal,
7840 Name_External,
7841 Name_Size);
7843 Internal : Node_Id renames Args (1);
7844 External : Node_Id renames Args (2);
7845 Size : Node_Id renames Args (3);
7847 begin
7848 GNAT_Pragma;
7849 Gather_Associations (Names, Args);
7850 Process_Extended_Import_Export_Object_Pragma (
7851 Arg_Internal => Internal,
7852 Arg_External => External,
7853 Arg_Size => Size);
7854 end Import_Object;
7856 ----------------------
7857 -- Import_Procedure --
7858 ----------------------
7860 -- pragma Import_Procedure (
7861 -- [Internal =>] LOCAL_NAME
7862 -- [, [External =>] EXTERNAL_SYMBOL]
7863 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7864 -- [, [Mechanism =>] MECHANISM]
7865 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7867 -- EXTERNAL_SYMBOL ::=
7868 -- IDENTIFIER
7869 -- | static_string_EXPRESSION
7871 -- PARAMETER_TYPES ::=
7872 -- null
7873 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7875 -- TYPE_DESIGNATOR ::=
7876 -- subtype_NAME
7877 -- | subtype_Name ' Access
7879 -- MECHANISM ::=
7880 -- MECHANISM_NAME
7881 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7883 -- MECHANISM_ASSOCIATION ::=
7884 -- [formal_parameter_NAME =>] MECHANISM_NAME
7886 -- MECHANISM_NAME ::=
7887 -- Value
7888 -- | Reference
7889 -- | Descriptor [([Class =>] CLASS_NAME)]
7891 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7893 when Pragma_Import_Procedure => Import_Procedure : declare
7894 Args : Args_List (1 .. 5);
7895 Names : constant Name_List (1 .. 5) := (
7896 Name_Internal,
7897 Name_External,
7898 Name_Parameter_Types,
7899 Name_Mechanism,
7900 Name_First_Optional_Parameter);
7902 Internal : Node_Id renames Args (1);
7903 External : Node_Id renames Args (2);
7904 Parameter_Types : Node_Id renames Args (3);
7905 Mechanism : Node_Id renames Args (4);
7906 First_Optional_Parameter : Node_Id renames Args (5);
7908 begin
7909 GNAT_Pragma;
7910 Gather_Associations (Names, Args);
7911 Process_Extended_Import_Export_Subprogram_Pragma (
7912 Arg_Internal => Internal,
7913 Arg_External => External,
7914 Arg_Parameter_Types => Parameter_Types,
7915 Arg_Mechanism => Mechanism,
7916 Arg_First_Optional_Parameter => First_Optional_Parameter);
7917 end Import_Procedure;
7919 -----------------------------
7920 -- Import_Valued_Procedure --
7921 -----------------------------
7923 -- pragma Import_Valued_Procedure (
7924 -- [Internal =>] LOCAL_NAME
7925 -- [, [External =>] EXTERNAL_SYMBOL]
7926 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7927 -- [, [Mechanism =>] MECHANISM]
7928 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7930 -- EXTERNAL_SYMBOL ::=
7931 -- IDENTIFIER
7932 -- | static_string_EXPRESSION
7934 -- PARAMETER_TYPES ::=
7935 -- null
7936 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7938 -- TYPE_DESIGNATOR ::=
7939 -- subtype_NAME
7940 -- | subtype_Name ' Access
7942 -- MECHANISM ::=
7943 -- MECHANISM_NAME
7944 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7946 -- MECHANISM_ASSOCIATION ::=
7947 -- [formal_parameter_NAME =>] MECHANISM_NAME
7949 -- MECHANISM_NAME ::=
7950 -- Value
7951 -- | Reference
7952 -- | Descriptor [([Class =>] CLASS_NAME)]
7954 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7956 when Pragma_Import_Valued_Procedure =>
7957 Import_Valued_Procedure : declare
7958 Args : Args_List (1 .. 5);
7959 Names : constant Name_List (1 .. 5) := (
7960 Name_Internal,
7961 Name_External,
7962 Name_Parameter_Types,
7963 Name_Mechanism,
7964 Name_First_Optional_Parameter);
7966 Internal : Node_Id renames Args (1);
7967 External : Node_Id renames Args (2);
7968 Parameter_Types : Node_Id renames Args (3);
7969 Mechanism : Node_Id renames Args (4);
7970 First_Optional_Parameter : Node_Id renames Args (5);
7972 begin
7973 GNAT_Pragma;
7974 Gather_Associations (Names, Args);
7975 Process_Extended_Import_Export_Subprogram_Pragma (
7976 Arg_Internal => Internal,
7977 Arg_External => External,
7978 Arg_Parameter_Types => Parameter_Types,
7979 Arg_Mechanism => Mechanism,
7980 Arg_First_Optional_Parameter => First_Optional_Parameter);
7981 end Import_Valued_Procedure;
7983 ------------------------
7984 -- Initialize_Scalars --
7985 ------------------------
7987 -- pragma Initialize_Scalars;
7989 when Pragma_Initialize_Scalars =>
7990 GNAT_Pragma;
7991 Check_Arg_Count (0);
7992 Check_Valid_Configuration_Pragma;
7993 Check_Restriction (No_Initialize_Scalars, N);
7995 -- Initialize_Scalars creates false positives in CodePeer,
7996 -- so ignore this pragma in this mode.
7998 if not Restriction_Active (No_Initialize_Scalars)
7999 and then not CodePeer_Mode
8000 then
8001 Init_Or_Norm_Scalars := True;
8002 Initialize_Scalars := True;
8003 end if;
8005 ------------
8006 -- Inline --
8007 ------------
8009 -- pragma Inline ( NAME {, NAME} );
8011 when Pragma_Inline =>
8013 -- Pragma is active if inlining option is active
8015 Process_Inline (Inline_Active);
8017 -------------------
8018 -- Inline_Always --
8019 -------------------
8021 -- pragma Inline_Always ( NAME {, NAME} );
8023 when Pragma_Inline_Always =>
8024 GNAT_Pragma;
8025 Process_Inline (True);
8027 --------------------
8028 -- Inline_Generic --
8029 --------------------
8031 -- pragma Inline_Generic (NAME {, NAME});
8033 when Pragma_Inline_Generic =>
8034 GNAT_Pragma;
8035 Process_Generic_List;
8037 ----------------------
8038 -- Inspection_Point --
8039 ----------------------
8041 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
8043 when Pragma_Inspection_Point => Inspection_Point : declare
8044 Arg : Node_Id;
8045 Exp : Node_Id;
8047 begin
8048 if Arg_Count > 0 then
8049 Arg := Arg1;
8050 loop
8051 Exp := Expression (Arg);
8052 Analyze (Exp);
8054 if not Is_Entity_Name (Exp)
8055 or else not Is_Object (Entity (Exp))
8056 then
8057 Error_Pragma_Arg ("object name required", Arg);
8058 end if;
8060 Next (Arg);
8061 exit when No (Arg);
8062 end loop;
8063 end if;
8064 end Inspection_Point;
8066 ---------------
8067 -- Interface --
8068 ---------------
8070 -- pragma Interface (
8071 -- [ Convention =>] convention_IDENTIFIER,
8072 -- [ Entity =>] local_NAME
8073 -- [, [External_Name =>] static_string_EXPRESSION ]
8074 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8076 when Pragma_Interface =>
8077 GNAT_Pragma;
8078 Check_Arg_Order
8079 ((Name_Convention,
8080 Name_Entity,
8081 Name_External_Name,
8082 Name_Link_Name));
8083 Check_At_Least_N_Arguments (2);
8084 Check_At_Most_N_Arguments (4);
8085 Process_Import_Or_Interface;
8087 --------------------
8088 -- Interface_Name --
8089 --------------------
8091 -- pragma Interface_Name (
8092 -- [ Entity =>] local_NAME
8093 -- [,[External_Name =>] static_string_EXPRESSION ]
8094 -- [,[Link_Name =>] static_string_EXPRESSION ]);
8096 when Pragma_Interface_Name => Interface_Name : declare
8097 Id : Node_Id;
8098 Def_Id : Entity_Id;
8099 Hom_Id : Entity_Id;
8100 Found : Boolean;
8102 begin
8103 GNAT_Pragma;
8104 Check_Arg_Order
8105 ((Name_Entity, Name_External_Name, Name_Link_Name));
8106 Check_At_Least_N_Arguments (2);
8107 Check_At_Most_N_Arguments (3);
8108 Id := Expression (Arg1);
8109 Analyze (Id);
8111 if not Is_Entity_Name (Id) then
8112 Error_Pragma_Arg
8113 ("first argument for pragma% must be entity name", Arg1);
8114 elsif Etype (Id) = Any_Type then
8115 return;
8116 else
8117 Def_Id := Entity (Id);
8118 end if;
8120 -- Special DEC-compatible processing for the object case, forces
8121 -- object to be imported.
8123 if Ekind (Def_Id) = E_Variable then
8124 Kill_Size_Check_Code (Def_Id);
8125 Note_Possible_Modification (Id, Sure => False);
8127 -- Initialization is not allowed for imported variable
8129 if Present (Expression (Parent (Def_Id)))
8130 and then Comes_From_Source (Expression (Parent (Def_Id)))
8131 then
8132 Error_Msg_Sloc := Sloc (Def_Id);
8133 Error_Pragma_Arg
8134 ("no initialization allowed for declaration of& #",
8135 Arg2);
8137 else
8138 -- For compatibility, support VADS usage of providing both
8139 -- pragmas Interface and Interface_Name to obtain the effect
8140 -- of a single Import pragma.
8142 if Is_Imported (Def_Id)
8143 and then Present (First_Rep_Item (Def_Id))
8144 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
8145 and then
8146 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
8147 then
8148 null;
8149 else
8150 Set_Imported (Def_Id);
8151 end if;
8153 Set_Is_Public (Def_Id);
8154 Process_Interface_Name (Def_Id, Arg2, Arg3);
8155 end if;
8157 -- Otherwise must be subprogram
8159 elsif not Is_Subprogram (Def_Id) then
8160 Error_Pragma_Arg
8161 ("argument of pragma% is not subprogram", Arg1);
8163 else
8164 Check_At_Most_N_Arguments (3);
8165 Hom_Id := Def_Id;
8166 Found := False;
8168 -- Loop through homonyms
8170 loop
8171 Def_Id := Get_Base_Subprogram (Hom_Id);
8173 if Is_Imported (Def_Id) then
8174 Process_Interface_Name (Def_Id, Arg2, Arg3);
8175 Found := True;
8176 end if;
8178 Hom_Id := Homonym (Hom_Id);
8180 exit when No (Hom_Id)
8181 or else Scope (Hom_Id) /= Current_Scope;
8182 end loop;
8184 if not Found then
8185 Error_Pragma_Arg
8186 ("argument of pragma% is not imported subprogram",
8187 Arg1);
8188 end if;
8189 end if;
8190 end Interface_Name;
8192 -----------------------
8193 -- Interrupt_Handler --
8194 -----------------------
8196 -- pragma Interrupt_Handler (handler_NAME);
8198 when Pragma_Interrupt_Handler =>
8199 Check_Ada_83_Warning;
8200 Check_Arg_Count (1);
8201 Check_No_Identifiers;
8203 if No_Run_Time_Mode then
8204 Error_Msg_CRT ("Interrupt_Handler pragma", N);
8205 else
8206 Check_Interrupt_Or_Attach_Handler;
8207 Process_Interrupt_Or_Attach_Handler;
8208 end if;
8210 ------------------------
8211 -- Interrupt_Priority --
8212 ------------------------
8214 -- pragma Interrupt_Priority [(EXPRESSION)];
8216 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
8217 P : constant Node_Id := Parent (N);
8218 Arg : Node_Id;
8220 begin
8221 Check_Ada_83_Warning;
8223 if Arg_Count /= 0 then
8224 Arg := Expression (Arg1);
8225 Check_Arg_Count (1);
8226 Check_No_Identifiers;
8228 -- The expression must be analyzed in the special manner
8229 -- described in "Handling of Default and Per-Object
8230 -- Expressions" in sem.ads.
8232 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
8233 end if;
8235 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
8236 Pragma_Misplaced;
8237 return;
8239 elsif Has_Priority_Pragma (P) then
8240 Error_Pragma ("duplicate pragma% not allowed");
8242 else
8243 Set_Has_Priority_Pragma (P, True);
8244 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8245 end if;
8246 end Interrupt_Priority;
8248 ---------------------
8249 -- Interrupt_State --
8250 ---------------------
8252 -- pragma Interrupt_State (
8253 -- [Name =>] INTERRUPT_ID,
8254 -- [State =>] INTERRUPT_STATE);
8256 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
8257 -- INTERRUPT_STATE => System | Runtime | User
8259 -- Note: if the interrupt id is given as an identifier, then it must
8260 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
8261 -- given as a static integer expression which must be in the range of
8262 -- Ada.Interrupts.Interrupt_ID.
8264 when Pragma_Interrupt_State => Interrupt_State : declare
8266 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
8267 -- This is the entity Ada.Interrupts.Interrupt_ID;
8269 State_Type : Character;
8270 -- Set to 's'/'r'/'u' for System/Runtime/User
8272 IST_Num : Pos;
8273 -- Index to entry in Interrupt_States table
8275 Int_Val : Uint;
8276 -- Value of interrupt
8278 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
8279 -- The first argument to the pragma
8281 Int_Ent : Entity_Id;
8282 -- Interrupt entity in Ada.Interrupts.Names
8284 begin
8285 GNAT_Pragma;
8286 Check_Arg_Order ((Name_Name, Name_State));
8287 Check_Arg_Count (2);
8289 Check_Optional_Identifier (Arg1, Name_Name);
8290 Check_Optional_Identifier (Arg2, Name_State);
8291 Check_Arg_Is_Identifier (Arg2);
8293 -- First argument is identifier
8295 if Nkind (Arg1X) = N_Identifier then
8297 -- Search list of names in Ada.Interrupts.Names
8299 Int_Ent := First_Entity (RTE (RE_Names));
8300 loop
8301 if No (Int_Ent) then
8302 Error_Pragma_Arg ("invalid interrupt name", Arg1);
8304 elsif Chars (Int_Ent) = Chars (Arg1X) then
8305 Int_Val := Expr_Value (Constant_Value (Int_Ent));
8306 exit;
8307 end if;
8309 Next_Entity (Int_Ent);
8310 end loop;
8312 -- First argument is not an identifier, so it must be a static
8313 -- expression of type Ada.Interrupts.Interrupt_ID.
8315 else
8316 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8317 Int_Val := Expr_Value (Arg1X);
8319 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
8320 or else
8321 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
8322 then
8323 Error_Pragma_Arg
8324 ("value not in range of type " &
8325 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
8326 end if;
8327 end if;
8329 -- Check OK state
8331 case Chars (Get_Pragma_Arg (Arg2)) is
8332 when Name_Runtime => State_Type := 'r';
8333 when Name_System => State_Type := 's';
8334 when Name_User => State_Type := 'u';
8336 when others =>
8337 Error_Pragma_Arg ("invalid interrupt state", Arg2);
8338 end case;
8340 -- Check if entry is already stored
8342 IST_Num := Interrupt_States.First;
8343 loop
8344 -- If entry not found, add it
8346 if IST_Num > Interrupt_States.Last then
8347 Interrupt_States.Append
8348 ((Interrupt_Number => UI_To_Int (Int_Val),
8349 Interrupt_State => State_Type,
8350 Pragma_Loc => Loc));
8351 exit;
8353 -- Case of entry for the same entry
8355 elsif Int_Val = Interrupt_States.Table (IST_Num).
8356 Interrupt_Number
8357 then
8358 -- If state matches, done, no need to make redundant entry
8360 exit when
8361 State_Type = Interrupt_States.Table (IST_Num).
8362 Interrupt_State;
8364 -- Otherwise if state does not match, error
8366 Error_Msg_Sloc :=
8367 Interrupt_States.Table (IST_Num).Pragma_Loc;
8368 Error_Pragma_Arg
8369 ("state conflicts with that given #", Arg2);
8370 exit;
8371 end if;
8373 IST_Num := IST_Num + 1;
8374 end loop;
8375 end Interrupt_State;
8377 ----------------------
8378 -- Java_Constructor --
8379 ----------------------
8381 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
8383 -- Also handles pragma CIL_Constructor
8385 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
8386 Java_Constructor : declare
8387 Id : Entity_Id;
8388 Def_Id : Entity_Id;
8389 Hom_Id : Entity_Id;
8390 Convention : Convention_Id;
8392 begin
8393 GNAT_Pragma;
8394 Check_Arg_Count (1);
8395 Check_Optional_Identifier (Arg1, Name_Entity);
8396 Check_Arg_Is_Local_Name (Arg1);
8398 Id := Expression (Arg1);
8399 Find_Program_Unit_Name (Id);
8401 -- If we did not find the name, we are done
8403 if Etype (Id) = Any_Type then
8404 return;
8405 end if;
8407 case Prag_Id is
8408 when Pragma_CIL_Constructor => Convention := Convention_CIL;
8409 when Pragma_Java_Constructor => Convention := Convention_Java;
8410 when others => null;
8411 end case;
8413 Hom_Id := Entity (Id);
8415 -- Loop through homonyms
8417 loop
8418 Def_Id := Get_Base_Subprogram (Hom_Id);
8420 -- The constructor is required to be a function returning an
8421 -- access type whose designated type has convention Java/CIL.
8423 if Ekind (Def_Id) = E_Function
8424 and then
8425 (Is_Value_Type (Etype (Def_Id))
8426 or else
8427 (Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
8428 and then
8429 Atree.Convention (Etype (Def_Id)) = Convention)
8430 or else
8431 (Ekind (Etype (Def_Id)) in Access_Kind
8432 and then
8433 (Atree.Convention
8434 (Designated_Type (Etype (Def_Id))) = Convention
8435 or else
8436 Atree.Convention
8437 (Root_Type (Designated_Type (Etype (Def_Id)))) =
8438 Convention)))
8439 then
8440 Set_Is_Constructor (Def_Id);
8441 Set_Convention (Def_Id, Convention);
8442 Set_Is_Imported (Def_Id);
8444 else
8445 if Convention = Convention_Java then
8446 Error_Pragma_Arg
8447 ("pragma% requires function returning a " &
8448 "'Java access type", Arg1);
8449 else
8450 pragma Assert (Convention = Convention_CIL);
8451 Error_Pragma_Arg
8452 ("pragma% requires function returning a " &
8453 "'C'I'L access type", Arg1);
8454 end if;
8455 end if;
8457 Hom_Id := Homonym (Hom_Id);
8459 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
8460 end loop;
8461 end Java_Constructor;
8463 ----------------------
8464 -- Java_Interface --
8465 ----------------------
8467 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
8469 when Pragma_Java_Interface => Java_Interface : declare
8470 Arg : Node_Id;
8471 Typ : Entity_Id;
8473 begin
8474 GNAT_Pragma;
8475 Check_Arg_Count (1);
8476 Check_Optional_Identifier (Arg1, Name_Entity);
8477 Check_Arg_Is_Local_Name (Arg1);
8479 Arg := Expression (Arg1);
8480 Analyze (Arg);
8482 if Etype (Arg) = Any_Type then
8483 return;
8484 end if;
8486 if not Is_Entity_Name (Arg)
8487 or else not Is_Type (Entity (Arg))
8488 then
8489 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
8490 end if;
8492 Typ := Underlying_Type (Entity (Arg));
8494 -- For now simply check some of the semantic constraints on the
8495 -- type. This currently leaves out some restrictions on interface
8496 -- types, namely that the parent type must be java.lang.Object.Typ
8497 -- and that all primitives of the type should be declared
8498 -- abstract. ???
8500 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
8501 Error_Pragma_Arg ("pragma% requires an abstract "
8502 & "tagged type", Arg1);
8504 elsif not Has_Discriminants (Typ)
8505 or else Ekind (Etype (First_Discriminant (Typ)))
8506 /= E_Anonymous_Access_Type
8507 or else
8508 not Is_Class_Wide_Type
8509 (Designated_Type (Etype (First_Discriminant (Typ))))
8510 then
8511 Error_Pragma_Arg
8512 ("type must have a class-wide access discriminant", Arg1);
8513 end if;
8514 end Java_Interface;
8516 ----------------
8517 -- Keep_Names --
8518 ----------------
8520 -- pragma Keep_Names ([On => ] local_NAME);
8522 when Pragma_Keep_Names => Keep_Names : declare
8523 Arg : Node_Id;
8525 begin
8526 GNAT_Pragma;
8527 Check_Arg_Count (1);
8528 Check_Optional_Identifier (Arg1, Name_On);
8529 Check_Arg_Is_Local_Name (Arg1);
8531 Arg := Expression (Arg1);
8532 Analyze (Arg);
8534 if Etype (Arg) = Any_Type then
8535 return;
8536 end if;
8538 if not Is_Entity_Name (Arg)
8539 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
8540 then
8541 Error_Pragma_Arg
8542 ("pragma% requires a local enumeration type", Arg1);
8543 end if;
8545 Set_Discard_Names (Entity (Arg), False);
8546 end Keep_Names;
8548 -------------
8549 -- License --
8550 -------------
8552 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
8554 when Pragma_License =>
8555 GNAT_Pragma;
8556 Check_Arg_Count (1);
8557 Check_No_Identifiers;
8558 Check_Valid_Configuration_Pragma;
8559 Check_Arg_Is_Identifier (Arg1);
8561 declare
8562 Sind : constant Source_File_Index :=
8563 Source_Index (Current_Sem_Unit);
8565 begin
8566 case Chars (Get_Pragma_Arg (Arg1)) is
8567 when Name_GPL =>
8568 Set_License (Sind, GPL);
8570 when Name_Modified_GPL =>
8571 Set_License (Sind, Modified_GPL);
8573 when Name_Restricted =>
8574 Set_License (Sind, Restricted);
8576 when Name_Unrestricted =>
8577 Set_License (Sind, Unrestricted);
8579 when others =>
8580 Error_Pragma_Arg ("invalid license name", Arg1);
8581 end case;
8582 end;
8584 ---------------
8585 -- Link_With --
8586 ---------------
8588 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
8590 when Pragma_Link_With => Link_With : declare
8591 Arg : Node_Id;
8593 begin
8594 GNAT_Pragma;
8596 if Operating_Mode = Generate_Code
8597 and then In_Extended_Main_Source_Unit (N)
8598 then
8599 Check_At_Least_N_Arguments (1);
8600 Check_No_Identifiers;
8601 Check_Is_In_Decl_Part_Or_Package_Spec;
8602 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8603 Start_String;
8605 Arg := Arg1;
8606 while Present (Arg) loop
8607 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8609 -- Store argument, converting sequences of spaces to a
8610 -- single null character (this is one of the differences
8611 -- in processing between Link_With and Linker_Options).
8613 Arg_Store : declare
8614 C : constant Char_Code := Get_Char_Code (' ');
8615 S : constant String_Id :=
8616 Strval (Expr_Value_S (Expression (Arg)));
8617 L : constant Nat := String_Length (S);
8618 F : Nat := 1;
8620 procedure Skip_Spaces;
8621 -- Advance F past any spaces
8623 -----------------
8624 -- Skip_Spaces --
8625 -----------------
8627 procedure Skip_Spaces is
8628 begin
8629 while F <= L and then Get_String_Char (S, F) = C loop
8630 F := F + 1;
8631 end loop;
8632 end Skip_Spaces;
8634 -- Start of processing for Arg_Store
8636 begin
8637 Skip_Spaces; -- skip leading spaces
8639 -- Loop through characters, changing any embedded
8640 -- sequence of spaces to a single null character (this
8641 -- is how Link_With/Linker_Options differ)
8643 while F <= L loop
8644 if Get_String_Char (S, F) = C then
8645 Skip_Spaces;
8646 exit when F > L;
8647 Store_String_Char (ASCII.NUL);
8649 else
8650 Store_String_Char (Get_String_Char (S, F));
8651 F := F + 1;
8652 end if;
8653 end loop;
8654 end Arg_Store;
8656 Arg := Next (Arg);
8658 if Present (Arg) then
8659 Store_String_Char (ASCII.NUL);
8660 end if;
8661 end loop;
8663 Store_Linker_Option_String (End_String);
8664 end if;
8665 end Link_With;
8667 ------------------
8668 -- Linker_Alias --
8669 ------------------
8671 -- pragma Linker_Alias (
8672 -- [Entity =>] LOCAL_NAME
8673 -- [Target =>] static_string_EXPRESSION);
8675 when Pragma_Linker_Alias =>
8676 GNAT_Pragma;
8677 Check_Arg_Order ((Name_Entity, Name_Target));
8678 Check_Arg_Count (2);
8679 Check_Optional_Identifier (Arg1, Name_Entity);
8680 Check_Optional_Identifier (Arg2, Name_Target);
8681 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8682 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8684 -- The only processing required is to link this item on to the
8685 -- list of rep items for the given entity. This is accomplished
8686 -- by the call to Rep_Item_Too_Late (when no error is detected
8687 -- and False is returned).
8689 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8690 return;
8691 else
8692 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8693 end if;
8695 ------------------------
8696 -- Linker_Constructor --
8697 ------------------------
8699 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
8701 -- Code is shared with Linker_Destructor
8703 -----------------------
8704 -- Linker_Destructor --
8705 -----------------------
8707 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
8709 when Pragma_Linker_Constructor |
8710 Pragma_Linker_Destructor =>
8711 Linker_Constructor : declare
8712 Arg1_X : Node_Id;
8713 Proc : Entity_Id;
8715 begin
8716 GNAT_Pragma;
8717 Check_Arg_Count (1);
8718 Check_No_Identifiers;
8719 Check_Arg_Is_Local_Name (Arg1);
8720 Arg1_X := Expression (Arg1);
8721 Analyze (Arg1_X);
8722 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
8724 if not Is_Library_Level_Entity (Proc) then
8725 Error_Pragma_Arg
8726 ("argument for pragma% must be library level entity", Arg1);
8727 end if;
8729 -- The only processing required is to link this item on to the
8730 -- list of rep items for the given entity. This is accomplished
8731 -- by the call to Rep_Item_Too_Late (when no error is detected
8732 -- and False is returned).
8734 if Rep_Item_Too_Late (Proc, N) then
8735 return;
8736 else
8737 Set_Has_Gigi_Rep_Item (Proc);
8738 end if;
8739 end Linker_Constructor;
8741 --------------------
8742 -- Linker_Options --
8743 --------------------
8745 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
8747 when Pragma_Linker_Options => Linker_Options : declare
8748 Arg : Node_Id;
8750 begin
8751 Check_Ada_83_Warning;
8752 Check_No_Identifiers;
8753 Check_Arg_Count (1);
8754 Check_Is_In_Decl_Part_Or_Package_Spec;
8755 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8756 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
8758 Arg := Arg2;
8759 while Present (Arg) loop
8760 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8761 Store_String_Char (ASCII.NUL);
8762 Store_String_Chars (Strval (Expr_Value_S (Expression (Arg))));
8763 Arg := Next (Arg);
8764 end loop;
8766 if Operating_Mode = Generate_Code
8767 and then In_Extended_Main_Source_Unit (N)
8768 then
8769 Store_Linker_Option_String (End_String);
8770 end if;
8771 end Linker_Options;
8773 --------------------
8774 -- Linker_Section --
8775 --------------------
8777 -- pragma Linker_Section (
8778 -- [Entity =>] LOCAL_NAME
8779 -- [Section =>] static_string_EXPRESSION);
8781 when Pragma_Linker_Section =>
8782 GNAT_Pragma;
8783 Check_Arg_Order ((Name_Entity, Name_Section));
8784 Check_Arg_Count (2);
8785 Check_Optional_Identifier (Arg1, Name_Entity);
8786 Check_Optional_Identifier (Arg2, Name_Section);
8787 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8788 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8790 -- This pragma applies only to objects
8792 if not Is_Object (Entity (Expression (Arg1))) then
8793 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
8794 end if;
8796 -- The only processing required is to link this item on to the
8797 -- list of rep items for the given entity. This is accomplished
8798 -- by the call to Rep_Item_Too_Late (when no error is detected
8799 -- and False is returned).
8801 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8802 return;
8803 else
8804 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8805 end if;
8807 ----------
8808 -- List --
8809 ----------
8811 -- pragma List (On | Off)
8813 -- There is nothing to do here, since we did all the processing for
8814 -- this pragma in Par.Prag (so that it works properly even in syntax
8815 -- only mode).
8817 when Pragma_List =>
8818 null;
8820 --------------------
8821 -- Locking_Policy --
8822 --------------------
8824 -- pragma Locking_Policy (policy_IDENTIFIER);
8826 when Pragma_Locking_Policy => declare
8827 LP : Character;
8829 begin
8830 Check_Ada_83_Warning;
8831 Check_Arg_Count (1);
8832 Check_No_Identifiers;
8833 Check_Arg_Is_Locking_Policy (Arg1);
8834 Check_Valid_Configuration_Pragma;
8835 Get_Name_String (Chars (Expression (Arg1)));
8836 LP := Fold_Upper (Name_Buffer (1));
8838 if Locking_Policy /= ' '
8839 and then Locking_Policy /= LP
8840 then
8841 Error_Msg_Sloc := Locking_Policy_Sloc;
8842 Error_Pragma ("locking policy incompatible with policy#");
8844 -- Set new policy, but always preserve System_Location since we
8845 -- like the error message with the run time name.
8847 else
8848 Locking_Policy := LP;
8850 if Locking_Policy_Sloc /= System_Location then
8851 Locking_Policy_Sloc := Loc;
8852 end if;
8853 end if;
8854 end;
8856 ----------------
8857 -- Long_Float --
8858 ----------------
8860 -- pragma Long_Float (D_Float | G_Float);
8862 when Pragma_Long_Float =>
8863 GNAT_Pragma;
8864 Check_Valid_Configuration_Pragma;
8865 Check_Arg_Count (1);
8866 Check_No_Identifier (Arg1);
8867 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
8869 if not OpenVMS_On_Target then
8870 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
8871 end if;
8873 -- D_Float case
8875 if Chars (Expression (Arg1)) = Name_D_Float then
8876 if Opt.Float_Format_Long = 'G' then
8877 Error_Pragma ("G_Float previously specified");
8878 end if;
8880 Opt.Float_Format_Long := 'D';
8882 -- G_Float case (this is the default, does not need overriding)
8884 else
8885 if Opt.Float_Format_Long = 'D' then
8886 Error_Pragma ("D_Float previously specified");
8887 end if;
8889 Opt.Float_Format_Long := 'G';
8890 end if;
8892 Set_Standard_Fpt_Formats;
8894 -----------------------
8895 -- Machine_Attribute --
8896 -----------------------
8898 -- pragma Machine_Attribute (
8899 -- [Entity =>] LOCAL_NAME,
8900 -- [Attribute_Name =>] static_string_EXPRESSION
8901 -- [, [Info =>] static_EXPRESSION] );
8903 when Pragma_Machine_Attribute => Machine_Attribute : declare
8904 Def_Id : Entity_Id;
8906 begin
8907 GNAT_Pragma;
8908 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
8910 if Arg_Count = 3 then
8911 Check_Optional_Identifier (Arg3, Name_Info);
8912 Check_Arg_Is_Static_Expression (Arg3);
8913 else
8914 Check_Arg_Count (2);
8915 end if;
8917 Check_Optional_Identifier (Arg1, Name_Entity);
8918 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
8919 Check_Arg_Is_Local_Name (Arg1);
8920 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8921 Def_Id := Entity (Expression (Arg1));
8923 if Is_Access_Type (Def_Id) then
8924 Def_Id := Designated_Type (Def_Id);
8925 end if;
8927 if Rep_Item_Too_Early (Def_Id, N) then
8928 return;
8929 end if;
8931 Def_Id := Underlying_Type (Def_Id);
8933 -- The only processing required is to link this item on to the
8934 -- list of rep items for the given entity. This is accomplished
8935 -- by the call to Rep_Item_Too_Late (when no error is detected
8936 -- and False is returned).
8938 if Rep_Item_Too_Late (Def_Id, N) then
8939 return;
8940 else
8941 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8942 end if;
8943 end Machine_Attribute;
8945 ----------
8946 -- Main --
8947 ----------
8949 -- pragma Main
8950 -- (MAIN_OPTION [, MAIN_OPTION]);
8952 -- MAIN_OPTION ::=
8953 -- [STACK_SIZE =>] static_integer_EXPRESSION
8954 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
8955 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
8957 when Pragma_Main => Main : declare
8958 Args : Args_List (1 .. 3);
8959 Names : constant Name_List (1 .. 3) := (
8960 Name_Stack_Size,
8961 Name_Task_Stack_Size_Default,
8962 Name_Time_Slicing_Enabled);
8964 Nod : Node_Id;
8966 begin
8967 GNAT_Pragma;
8968 Gather_Associations (Names, Args);
8970 for J in 1 .. 2 loop
8971 if Present (Args (J)) then
8972 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8973 end if;
8974 end loop;
8976 if Present (Args (3)) then
8977 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
8978 end if;
8980 Nod := Next (N);
8981 while Present (Nod) loop
8982 if Nkind (Nod) = N_Pragma
8983 and then Pragma_Name (Nod) = Name_Main
8984 then
8985 Error_Msg_Name_1 := Pname;
8986 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8987 end if;
8989 Next (Nod);
8990 end loop;
8991 end Main;
8993 ------------------
8994 -- Main_Storage --
8995 ------------------
8997 -- pragma Main_Storage
8998 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
9000 -- MAIN_STORAGE_OPTION ::=
9001 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
9002 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
9004 when Pragma_Main_Storage => Main_Storage : declare
9005 Args : Args_List (1 .. 2);
9006 Names : constant Name_List (1 .. 2) := (
9007 Name_Working_Storage,
9008 Name_Top_Guard);
9010 Nod : Node_Id;
9012 begin
9013 GNAT_Pragma;
9014 Gather_Associations (Names, Args);
9016 for J in 1 .. 2 loop
9017 if Present (Args (J)) then
9018 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
9019 end if;
9020 end loop;
9022 Check_In_Main_Program;
9024 Nod := Next (N);
9025 while Present (Nod) loop
9026 if Nkind (Nod) = N_Pragma
9027 and then Pragma_Name (Nod) = Name_Main_Storage
9028 then
9029 Error_Msg_Name_1 := Pname;
9030 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9031 end if;
9033 Next (Nod);
9034 end loop;
9035 end Main_Storage;
9037 -----------------
9038 -- Memory_Size --
9039 -----------------
9041 -- pragma Memory_Size (NUMERIC_LITERAL)
9043 when Pragma_Memory_Size =>
9044 GNAT_Pragma;
9046 -- Memory size is simply ignored
9048 Check_No_Identifiers;
9049 Check_Arg_Count (1);
9050 Check_Arg_Is_Integer_Literal (Arg1);
9052 -------------
9053 -- No_Body --
9054 -------------
9056 -- pragma No_Body;
9058 -- The only correct use of this pragma is on its own in a file, in
9059 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
9060 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
9061 -- check for a file containing nothing but a No_Body pragma). If we
9062 -- attempt to process it during normal semantics processing, it means
9063 -- it was misplaced.
9065 when Pragma_No_Body =>
9066 GNAT_Pragma;
9067 Pragma_Misplaced;
9069 ---------------
9070 -- No_Return --
9071 ---------------
9073 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
9075 when Pragma_No_Return => No_Return : declare
9076 Id : Node_Id;
9077 E : Entity_Id;
9078 Found : Boolean;
9079 Arg : Node_Id;
9081 begin
9082 Ada_2005_Pragma;
9083 Check_At_Least_N_Arguments (1);
9085 -- Loop through arguments of pragma
9087 Arg := Arg1;
9088 while Present (Arg) loop
9089 Check_Arg_Is_Local_Name (Arg);
9090 Id := Expression (Arg);
9091 Analyze (Id);
9093 if not Is_Entity_Name (Id) then
9094 Error_Pragma_Arg ("entity name required", Arg);
9095 end if;
9097 if Etype (Id) = Any_Type then
9098 raise Pragma_Exit;
9099 end if;
9101 -- Loop to find matching procedures
9103 E := Entity (Id);
9104 Found := False;
9105 while Present (E)
9106 and then Scope (E) = Current_Scope
9107 loop
9108 if Ekind (E) = E_Procedure
9109 or else Ekind (E) = E_Generic_Procedure
9110 then
9111 Set_No_Return (E);
9113 -- Set flag on any alias as well
9115 if Is_Overloadable (E) and then Present (Alias (E)) then
9116 Set_No_Return (Alias (E));
9117 end if;
9119 Found := True;
9120 end if;
9122 E := Homonym (E);
9123 end loop;
9125 if not Found then
9126 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
9127 end if;
9129 Next (Arg);
9130 end loop;
9131 end No_Return;
9133 -----------------
9134 -- No_Run_Time --
9135 -----------------
9137 -- pragma No_Run_Time;
9139 -- Note: this pragma is retained for backwards compatibility. See
9140 -- body of Rtsfind for full details on its handling.
9142 when Pragma_No_Run_Time =>
9143 GNAT_Pragma;
9144 Check_Valid_Configuration_Pragma;
9145 Check_Arg_Count (0);
9147 No_Run_Time_Mode := True;
9148 Configurable_Run_Time_Mode := True;
9150 -- Set Duration to 32 bits if word size is 32
9152 if Ttypes.System_Word_Size = 32 then
9153 Duration_32_Bits_On_Target := True;
9154 end if;
9156 -- Set appropriate restrictions
9158 Set_Restriction (No_Finalization, N);
9159 Set_Restriction (No_Exception_Handlers, N);
9160 Set_Restriction (Max_Tasks, N, 0);
9161 Set_Restriction (No_Tasking, N);
9163 ------------------------
9164 -- No_Strict_Aliasing --
9165 ------------------------
9167 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
9169 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
9170 E_Id : Entity_Id;
9172 begin
9173 GNAT_Pragma;
9174 Check_At_Most_N_Arguments (1);
9176 if Arg_Count = 0 then
9177 Check_Valid_Configuration_Pragma;
9178 Opt.No_Strict_Aliasing := True;
9180 else
9181 Check_Optional_Identifier (Arg2, Name_Entity);
9182 Check_Arg_Is_Local_Name (Arg1);
9183 E_Id := Entity (Expression (Arg1));
9185 if E_Id = Any_Type then
9186 return;
9187 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
9188 Error_Pragma_Arg ("pragma% requires access type", Arg1);
9189 end if;
9191 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
9192 end if;
9193 end No_Strict_Aliasing;
9195 -----------------------
9196 -- Normalize_Scalars --
9197 -----------------------
9199 -- pragma Normalize_Scalars;
9201 when Pragma_Normalize_Scalars =>
9202 Check_Ada_83_Warning;
9203 Check_Arg_Count (0);
9204 Check_Valid_Configuration_Pragma;
9206 -- Normalize_Scalars creates false positives in CodePeer, so
9207 -- ignore this pragma in this mode.
9209 if not CodePeer_Mode then
9210 Normalize_Scalars := True;
9211 Init_Or_Norm_Scalars := True;
9212 end if;
9214 -----------------
9215 -- Obsolescent --
9216 -----------------
9218 -- pragma Obsolescent;
9220 -- pragma Obsolescent (
9221 -- [Message =>] static_string_EXPRESSION
9222 -- [,[Version =>] Ada_05]]);
9224 -- pragma Obsolescent (
9225 -- [Entity =>] NAME
9226 -- [,[Message =>] static_string_EXPRESSION
9227 -- [,[Version =>] Ada_05]] );
9229 when Pragma_Obsolescent => Obsolescent : declare
9230 Ename : Node_Id;
9231 Decl : Node_Id;
9233 procedure Set_Obsolescent (E : Entity_Id);
9234 -- Given an entity Ent, mark it as obsolescent if appropriate
9236 ---------------------
9237 -- Set_Obsolescent --
9238 ---------------------
9240 procedure Set_Obsolescent (E : Entity_Id) is
9241 Active : Boolean;
9242 Ent : Entity_Id;
9243 S : String_Id;
9245 begin
9246 Active := True;
9247 Ent := E;
9249 -- Entity name was given
9251 if Present (Ename) then
9253 -- If entity name matches, we are fine. Save entity in
9254 -- pragma argument, for ASIS use.
9256 if Chars (Ename) = Chars (Ent) then
9257 Set_Entity (Ename, Ent);
9258 Generate_Reference (Ent, Ename);
9260 -- If entity name does not match, only possibility is an
9261 -- enumeration literal from an enumeration type declaration.
9263 elsif Ekind (Ent) /= E_Enumeration_Type then
9264 Error_Pragma
9265 ("pragma % entity name does not match declaration");
9267 else
9268 Ent := First_Literal (E);
9269 loop
9270 if No (Ent) then
9271 Error_Pragma
9272 ("pragma % entity name does not match any " &
9273 "enumeration literal");
9275 elsif Chars (Ent) = Chars (Ename) then
9276 Set_Entity (Ename, Ent);
9277 Generate_Reference (Ent, Ename);
9278 exit;
9280 else
9281 Ent := Next_Literal (Ent);
9282 end if;
9283 end loop;
9284 end if;
9285 end if;
9287 -- Ent points to entity to be marked
9289 if Arg_Count >= 1 then
9291 -- Deal with static string argument
9293 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9294 S := Strval (Expression (Arg1));
9296 for J in 1 .. String_Length (S) loop
9297 if not In_Character_Range (Get_String_Char (S, J)) then
9298 Error_Pragma_Arg
9299 ("pragma% argument does not allow wide characters",
9300 Arg1);
9301 end if;
9302 end loop;
9304 Obsolescent_Warnings.Append
9305 ((Ent => Ent, Msg => Strval (Expression (Arg1))));
9307 -- Check for Ada_05 parameter
9309 if Arg_Count /= 1 then
9310 Check_Arg_Count (2);
9312 declare
9313 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
9315 begin
9316 Check_Arg_Is_Identifier (Argx);
9318 if Chars (Argx) /= Name_Ada_05 then
9319 Error_Msg_Name_2 := Name_Ada_05;
9320 Error_Pragma_Arg
9321 ("only allowed argument for pragma% is %", Argx);
9322 end if;
9324 if Ada_Version_Explicit < Ada_05
9325 or else not Warn_On_Ada_2005_Compatibility
9326 then
9327 Active := False;
9328 end if;
9329 end;
9330 end if;
9331 end if;
9333 -- Set flag if pragma active
9335 if Active then
9336 Set_Is_Obsolescent (Ent);
9337 end if;
9339 return;
9340 end Set_Obsolescent;
9342 -- Start of processing for pragma Obsolescent
9344 begin
9345 GNAT_Pragma;
9347 Check_At_Most_N_Arguments (3);
9349 -- See if first argument specifies an entity name
9351 if Arg_Count >= 1
9352 and then
9353 (Chars (Arg1) = Name_Entity
9354 or else
9355 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
9356 N_Identifier,
9357 N_Operator_Symbol))
9358 then
9359 Ename := Get_Pragma_Arg (Arg1);
9361 -- Eliminate first argument, so we can share processing
9363 Arg1 := Arg2;
9364 Arg2 := Arg3;
9365 Arg_Count := Arg_Count - 1;
9367 -- No Entity name argument given
9369 else
9370 Ename := Empty;
9371 end if;
9373 if Arg_Count >= 1 then
9374 Check_Optional_Identifier (Arg1, Name_Message);
9376 if Arg_Count = 2 then
9377 Check_Optional_Identifier (Arg2, Name_Version);
9378 end if;
9379 end if;
9381 -- Get immediately preceding declaration
9383 Decl := Prev (N);
9384 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
9385 Prev (Decl);
9386 end loop;
9388 -- Cases where we do not follow anything other than another pragma
9390 if No (Decl) then
9392 -- First case: library level compilation unit declaration with
9393 -- the pragma immediately following the declaration.
9395 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9396 Set_Obsolescent
9397 (Defining_Entity (Unit (Parent (Parent (N)))));
9398 return;
9400 -- Case 2: library unit placement for package
9402 else
9403 declare
9404 Ent : constant Entity_Id := Find_Lib_Unit_Name;
9405 begin
9406 if Is_Package_Or_Generic_Package (Ent) then
9407 Set_Obsolescent (Ent);
9408 return;
9409 end if;
9410 end;
9411 end if;
9413 -- Cases where we must follow a declaration
9415 else
9416 if Nkind (Decl) not in N_Declaration
9417 and then Nkind (Decl) not in N_Later_Decl_Item
9418 and then Nkind (Decl) not in N_Generic_Declaration
9419 and then Nkind (Decl) not in N_Renaming_Declaration
9420 then
9421 Error_Pragma
9422 ("pragma% misplaced, "
9423 & "must immediately follow a declaration");
9425 else
9426 Set_Obsolescent (Defining_Entity (Decl));
9427 return;
9428 end if;
9429 end if;
9430 end Obsolescent;
9432 --------------
9433 -- Optimize --
9434 --------------
9436 -- pragma Optimize (Time | Space | Off);
9438 -- The actual check for optimize is done in Gigi. Note that this
9439 -- pragma does not actually change the optimization setting, it
9440 -- simply checks that it is consistent with the pragma.
9442 when Pragma_Optimize =>
9443 Check_No_Identifiers;
9444 Check_Arg_Count (1);
9445 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
9447 ------------------------
9448 -- Optimize_Alignment --
9449 ------------------------
9451 -- pragma Optimize_Alignment (Time | Space | Off);
9453 when Pragma_Optimize_Alignment =>
9454 GNAT_Pragma;
9455 Check_No_Identifiers;
9456 Check_Arg_Count (1);
9457 Check_Valid_Configuration_Pragma;
9459 declare
9460 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
9461 begin
9462 case Nam is
9463 when Name_Time =>
9464 Opt.Optimize_Alignment := 'T';
9465 when Name_Space =>
9466 Opt.Optimize_Alignment := 'S';
9467 when Name_Off =>
9468 Opt.Optimize_Alignment := 'O';
9469 when others =>
9470 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
9471 end case;
9472 end;
9474 -- Set indication that mode is set locally. If we are in fact in a
9475 -- configuration pragma file, this setting is harmless since the
9476 -- switch will get reset anyway at the start of each unit.
9478 Optimize_Alignment_Local := True;
9480 ----------
9481 -- Pack --
9482 ----------
9484 -- pragma Pack (first_subtype_LOCAL_NAME);
9486 when Pragma_Pack => Pack : declare
9487 Assoc : constant Node_Id := Arg1;
9488 Type_Id : Node_Id;
9489 Typ : Entity_Id;
9491 begin
9492 Check_No_Identifiers;
9493 Check_Arg_Count (1);
9494 Check_Arg_Is_Local_Name (Arg1);
9496 Type_Id := Expression (Assoc);
9497 Find_Type (Type_Id);
9498 Typ := Entity (Type_Id);
9500 if Typ = Any_Type
9501 or else Rep_Item_Too_Early (Typ, N)
9502 then
9503 return;
9504 else
9505 Typ := Underlying_Type (Typ);
9506 end if;
9508 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
9509 Error_Pragma ("pragma% must specify array or record type");
9510 end if;
9512 Check_First_Subtype (Arg1);
9514 if Has_Pragma_Pack (Typ) then
9515 Error_Pragma ("duplicate pragma%, only one allowed");
9517 -- Array type
9519 elsif Is_Array_Type (Typ) then
9521 -- Pack not allowed for aliased or atomic components
9523 if Has_Aliased_Components (Base_Type (Typ)) then
9524 Error_Pragma
9525 ("pragma% ignored, cannot pack aliased components?");
9527 elsif Has_Atomic_Components (Typ)
9528 or else Is_Atomic (Component_Type (Typ))
9529 then
9530 Error_Pragma
9531 ("?pragma% ignored, cannot pack atomic components");
9532 end if;
9534 -- If we had an explicit component size given, then we do not
9535 -- let Pack override this given size. We also give a warning
9536 -- that Pack is being ignored unless we can tell for sure that
9537 -- the Pack would not have had any effect anyway.
9539 if Has_Component_Size_Clause (Typ) then
9540 if Known_Static_RM_Size (Component_Type (Typ))
9541 and then
9542 RM_Size (Component_Type (Typ)) = Component_Size (Typ)
9543 then
9544 null;
9545 else
9546 Error_Pragma
9547 ("?pragma% ignored, explicit component size given");
9548 end if;
9550 -- If no prior array component size given, Pack is effective
9552 else
9553 if not Rep_Item_Too_Late (Typ, N) then
9555 -- In the context of static code analysis, we do not need
9556 -- complex front-end expansions related to pragma Pack,
9557 -- so disable handling of pragma Pack in this case.
9559 if CodePeer_Mode then
9560 null;
9562 -- For normal non-VM target, do the packing
9564 elsif VM_Target = No_VM then
9565 Set_Is_Packed (Base_Type (Typ));
9566 Set_Has_Pragma_Pack (Base_Type (Typ));
9567 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9569 -- If we ignore the pack, then warn about this, except
9570 -- that we suppress the warning in GNAT mode.
9572 elsif not GNAT_Mode then
9573 Error_Pragma
9574 ("?pragma% ignored in this configuration");
9575 end if;
9576 end if;
9577 end if;
9579 -- For record types, the pack is always effective
9581 else pragma Assert (Is_Record_Type (Typ));
9582 if not Rep_Item_Too_Late (Typ, N) then
9583 if VM_Target = No_VM then
9584 Set_Is_Packed (Base_Type (Typ));
9585 Set_Has_Pragma_Pack (Base_Type (Typ));
9586 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9588 elsif not GNAT_Mode then
9589 Error_Pragma ("?pragma% ignored in this configuration");
9590 end if;
9591 end if;
9592 end if;
9593 end Pack;
9595 ----------
9596 -- Page --
9597 ----------
9599 -- pragma Page;
9601 -- There is nothing to do here, since we did all the processing for
9602 -- this pragma in Par.Prag (so that it works properly even in syntax
9603 -- only mode).
9605 when Pragma_Page =>
9606 null;
9608 -------------
9609 -- Passive --
9610 -------------
9612 -- pragma Passive [(PASSIVE_FORM)];
9614 -- PASSIVE_FORM ::= Semaphore | No
9616 when Pragma_Passive =>
9617 GNAT_Pragma;
9619 if Nkind (Parent (N)) /= N_Task_Definition then
9620 Error_Pragma ("pragma% must be within task definition");
9621 end if;
9623 if Arg_Count /= 0 then
9624 Check_Arg_Count (1);
9625 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
9626 end if;
9628 ----------------------------------
9629 -- Preelaborable_Initialization --
9630 ----------------------------------
9632 -- pragma Preelaborable_Initialization (DIRECT_NAME);
9634 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
9635 Ent : Entity_Id;
9637 begin
9638 Ada_2005_Pragma;
9639 Check_Arg_Count (1);
9640 Check_No_Identifiers;
9641 Check_Arg_Is_Identifier (Arg1);
9642 Check_Arg_Is_Local_Name (Arg1);
9643 Check_First_Subtype (Arg1);
9644 Ent := Entity (Expression (Arg1));
9646 if not Is_Private_Type (Ent)
9647 and then not Is_Protected_Type (Ent)
9648 then
9649 Error_Pragma_Arg
9650 ("pragma % can only be applied to private or protected type",
9651 Arg1);
9652 end if;
9654 -- Give an error if the pragma is applied to a protected type that
9655 -- does not qualify (due to having entries, or due to components
9656 -- that do not qualify).
9658 if Is_Protected_Type (Ent)
9659 and then not Has_Preelaborable_Initialization (Ent)
9660 then
9661 Error_Msg_N
9662 ("protected type & does not have preelaborable " &
9663 "initialization", Ent);
9665 -- Otherwise mark the type as definitely having preelaborable
9666 -- initialization.
9668 else
9669 Set_Known_To_Have_Preelab_Init (Ent);
9670 end if;
9672 if Has_Pragma_Preelab_Init (Ent)
9673 and then Warn_On_Redundant_Constructs
9674 then
9675 Error_Pragma ("?duplicate pragma%!");
9676 else
9677 Set_Has_Pragma_Preelab_Init (Ent);
9678 end if;
9679 end Preelab_Init;
9681 --------------------
9682 -- Persistent_BSS --
9683 --------------------
9685 when Pragma_Persistent_BSS => Persistent_BSS : declare
9686 Decl : Node_Id;
9687 Ent : Entity_Id;
9688 Prag : Node_Id;
9690 begin
9691 GNAT_Pragma;
9692 Check_At_Most_N_Arguments (1);
9694 -- Case of application to specific object (one argument)
9696 if Arg_Count = 1 then
9697 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9699 if not Is_Entity_Name (Expression (Arg1))
9700 or else
9701 (Ekind (Entity (Expression (Arg1))) /= E_Variable
9702 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
9703 then
9704 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
9705 end if;
9707 Ent := Entity (Expression (Arg1));
9708 Decl := Parent (Ent);
9710 if Rep_Item_Too_Late (Ent, N) then
9711 return;
9712 end if;
9714 if Present (Expression (Decl)) then
9715 Error_Pragma_Arg
9716 ("object for pragma% cannot have initialization", Arg1);
9717 end if;
9719 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
9720 Error_Pragma_Arg
9721 ("object type for pragma% is not potentially persistent",
9722 Arg1);
9723 end if;
9725 Prag :=
9726 Make_Linker_Section_Pragma
9727 (Ent, Sloc (N), ".persistent.bss");
9728 Insert_After (N, Prag);
9729 Analyze (Prag);
9731 -- Case of use as configuration pragma with no arguments
9733 else
9734 Check_Valid_Configuration_Pragma;
9735 Persistent_BSS_Mode := True;
9736 end if;
9737 end Persistent_BSS;
9739 -------------
9740 -- Polling --
9741 -------------
9743 -- pragma Polling (ON | OFF);
9745 when Pragma_Polling =>
9746 GNAT_Pragma;
9747 Check_Arg_Count (1);
9748 Check_No_Identifiers;
9749 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9750 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
9752 -------------------
9753 -- Postcondition --
9754 -------------------
9756 -- pragma Postcondition ([Check =>] Boolean_Expression
9757 -- [,[Message =>] String_Expression]);
9759 when Pragma_Postcondition => Postcondition : declare
9760 In_Body : Boolean;
9761 pragma Warnings (Off, In_Body);
9763 begin
9764 GNAT_Pragma;
9765 Check_At_Least_N_Arguments (1);
9766 Check_At_Most_N_Arguments (2);
9767 Check_Optional_Identifier (Arg1, Name_Check);
9769 -- All we need to do here is call the common check procedure,
9770 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
9772 Check_Precondition_Postcondition (In_Body);
9773 end Postcondition;
9775 ------------------
9776 -- Precondition --
9777 ------------------
9779 -- pragma Precondition ([Check =>] Boolean_Expression
9780 -- [,[Message =>] String_Expression]);
9782 when Pragma_Precondition => Precondition : declare
9783 In_Body : Boolean;
9785 begin
9786 GNAT_Pragma;
9787 Check_At_Least_N_Arguments (1);
9788 Check_At_Most_N_Arguments (2);
9789 Check_Optional_Identifier (Arg1, Name_Check);
9791 Check_Precondition_Postcondition (In_Body);
9793 -- If in spec, nothing more to do. If in body, then we convert the
9794 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
9795 -- this whether or not precondition checks are enabled. That works
9796 -- fine since pragma Check will do this check, and will also
9797 -- analyze the condition itself in the proper context.
9799 if In_Body then
9800 if Arg_Count = 2 then
9801 Check_Optional_Identifier (Arg3, Name_Message);
9802 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
9803 end if;
9805 Rewrite (N,
9806 Make_Pragma (Loc,
9807 Chars => Name_Check,
9808 Pragma_Argument_Associations => New_List (
9809 Make_Pragma_Argument_Association (Loc,
9810 Expression =>
9811 Make_Identifier (Loc,
9812 Chars => Name_Precondition)),
9814 Make_Pragma_Argument_Association (Sloc (Arg1),
9815 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
9817 if Arg_Count = 2 then
9818 Append_To (Pragma_Argument_Associations (N),
9819 Make_Pragma_Argument_Association (Sloc (Arg2),
9820 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
9821 end if;
9823 Analyze (N);
9824 end if;
9825 end Precondition;
9827 ------------------
9828 -- Preelaborate --
9829 ------------------
9831 -- pragma Preelaborate [(library_unit_NAME)];
9833 -- Set the flag Is_Preelaborated of program unit name entity
9835 when Pragma_Preelaborate => Preelaborate : declare
9836 Pa : constant Node_Id := Parent (N);
9837 Pk : constant Node_Kind := Nkind (Pa);
9838 Ent : Entity_Id;
9840 begin
9841 Check_Ada_83_Warning;
9842 Check_Valid_Library_Unit_Pragma;
9844 if Nkind (N) = N_Null_Statement then
9845 return;
9846 end if;
9848 Ent := Find_Lib_Unit_Name;
9850 -- This filters out pragmas inside generic parent then
9851 -- show up inside instantiation
9853 if Present (Ent)
9854 and then not (Pk = N_Package_Specification
9855 and then Present (Generic_Parent (Pa)))
9856 then
9857 if not Debug_Flag_U then
9858 Set_Is_Preelaborated (Ent);
9859 Set_Suppress_Elaboration_Warnings (Ent);
9860 end if;
9861 end if;
9862 end Preelaborate;
9864 ---------------------
9865 -- Preelaborate_05 --
9866 ---------------------
9868 -- pragma Preelaborate_05 [(library_unit_NAME)];
9870 -- This pragma is useable only in GNAT_Mode, where it is used like
9871 -- pragma Preelaborate but it is only effective in Ada 2005 mode
9872 -- (otherwise it is ignored). This is used to implement AI-362 which
9873 -- recategorizes some run-time packages in Ada 2005 mode.
9875 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
9876 Ent : Entity_Id;
9878 begin
9879 GNAT_Pragma;
9880 Check_Valid_Library_Unit_Pragma;
9882 if not GNAT_Mode then
9883 Error_Pragma ("pragma% only available in GNAT mode");
9884 end if;
9886 if Nkind (N) = N_Null_Statement then
9887 return;
9888 end if;
9890 -- This is one of the few cases where we need to test the value of
9891 -- Ada_Version_Explicit rather than Ada_Version (which is always
9892 -- set to Ada_05 in a predefined unit), we need to know the
9893 -- explicit version set to know if this pragma is active.
9895 if Ada_Version_Explicit >= Ada_05 then
9896 Ent := Find_Lib_Unit_Name;
9897 Set_Is_Preelaborated (Ent);
9898 Set_Suppress_Elaboration_Warnings (Ent);
9899 end if;
9900 end Preelaborate_05;
9902 --------------
9903 -- Priority --
9904 --------------
9906 -- pragma Priority (EXPRESSION);
9908 when Pragma_Priority => Priority : declare
9909 P : constant Node_Id := Parent (N);
9910 Arg : Node_Id;
9912 begin
9913 Check_No_Identifiers;
9914 Check_Arg_Count (1);
9916 -- Subprogram case
9918 if Nkind (P) = N_Subprogram_Body then
9919 Check_In_Main_Program;
9921 Arg := Expression (Arg1);
9922 Analyze_And_Resolve (Arg, Standard_Integer);
9924 -- Must be static
9926 if not Is_Static_Expression (Arg) then
9927 Flag_Non_Static_Expr
9928 ("main subprogram priority is not static!", Arg);
9929 raise Pragma_Exit;
9931 -- If constraint error, then we already signalled an error
9933 elsif Raises_Constraint_Error (Arg) then
9934 null;
9936 -- Otherwise check in range
9938 else
9939 declare
9940 Val : constant Uint := Expr_Value (Arg);
9942 begin
9943 if Val < 0
9944 or else Val > Expr_Value (Expression
9945 (Parent (RTE (RE_Max_Priority))))
9946 then
9947 Error_Pragma_Arg
9948 ("main subprogram priority is out of range", Arg1);
9949 end if;
9950 end;
9951 end if;
9953 Set_Main_Priority
9954 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
9956 -- Load an arbitrary entity from System.Tasking to make sure
9957 -- this package is implicitly with'ed, since we need to have
9958 -- the tasking run-time active for the pragma Priority to have
9959 -- any effect.
9961 declare
9962 Discard : Entity_Id;
9963 pragma Warnings (Off, Discard);
9964 begin
9965 Discard := RTE (RE_Task_List);
9966 end;
9968 -- Task or Protected, must be of type Integer
9970 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
9971 Arg := Expression (Arg1);
9973 -- The expression must be analyzed in the special manner
9974 -- described in "Handling of Default and Per-Object
9975 -- Expressions" in sem.ads.
9977 Preanalyze_Spec_Expression (Arg, Standard_Integer);
9979 if not Is_Static_Expression (Arg) then
9980 Check_Restriction (Static_Priorities, Arg);
9981 end if;
9983 -- Anything else is incorrect
9985 else
9986 Pragma_Misplaced;
9987 end if;
9989 if Has_Priority_Pragma (P) then
9990 Error_Pragma ("duplicate pragma% not allowed");
9991 else
9992 Set_Has_Priority_Pragma (P, True);
9994 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
9995 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9996 -- exp_ch9 should use this ???
9997 end if;
9998 end if;
9999 end Priority;
10001 -----------------------------------
10002 -- Priority_Specific_Dispatching --
10003 -----------------------------------
10005 -- pragma Priority_Specific_Dispatching (
10006 -- policy_IDENTIFIER,
10007 -- first_priority_EXPRESSION,
10008 -- last_priority_EXPRESSION);
10010 when Pragma_Priority_Specific_Dispatching =>
10011 Priority_Specific_Dispatching : declare
10012 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
10013 -- This is the entity System.Any_Priority;
10015 DP : Character;
10016 Lower_Bound : Node_Id;
10017 Upper_Bound : Node_Id;
10018 Lower_Val : Uint;
10019 Upper_Val : Uint;
10021 begin
10022 Ada_2005_Pragma;
10023 Check_Arg_Count (3);
10024 Check_No_Identifiers;
10025 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
10026 Check_Valid_Configuration_Pragma;
10027 Get_Name_String (Chars (Expression (Arg1)));
10028 DP := Fold_Upper (Name_Buffer (1));
10030 Lower_Bound := Expression (Arg2);
10031 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
10032 Lower_Val := Expr_Value (Lower_Bound);
10034 Upper_Bound := Expression (Arg3);
10035 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
10036 Upper_Val := Expr_Value (Upper_Bound);
10038 -- It is not allowed to use Task_Dispatching_Policy and
10039 -- Priority_Specific_Dispatching in the same partition.
10041 if Task_Dispatching_Policy /= ' ' then
10042 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10043 Error_Pragma
10044 ("pragma% incompatible with Task_Dispatching_Policy#");
10046 -- Check lower bound in range
10048 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10049 or else
10050 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
10051 then
10052 Error_Pragma_Arg
10053 ("first_priority is out of range", Arg2);
10055 -- Check upper bound in range
10057 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10058 or else
10059 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
10060 then
10061 Error_Pragma_Arg
10062 ("last_priority is out of range", Arg3);
10064 -- Check that the priority range is valid
10066 elsif Lower_Val > Upper_Val then
10067 Error_Pragma
10068 ("last_priority_expression must be greater than" &
10069 " or equal to first_priority_expression");
10071 -- Store the new policy, but always preserve System_Location since
10072 -- we like the error message with the run-time name.
10074 else
10075 -- Check overlapping in the priority ranges specified in other
10076 -- Priority_Specific_Dispatching pragmas within the same
10077 -- partition. We can only check those we know about!
10079 for J in
10080 Specific_Dispatching.First .. Specific_Dispatching.Last
10081 loop
10082 if Specific_Dispatching.Table (J).First_Priority in
10083 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10084 or else Specific_Dispatching.Table (J).Last_Priority in
10085 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10086 then
10087 Error_Msg_Sloc :=
10088 Specific_Dispatching.Table (J).Pragma_Loc;
10089 Error_Pragma
10090 ("priority range overlaps with "
10091 & "Priority_Specific_Dispatching#");
10092 end if;
10093 end loop;
10095 -- The use of Priority_Specific_Dispatching is incompatible
10096 -- with Task_Dispatching_Policy.
10098 if Task_Dispatching_Policy /= ' ' then
10099 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10100 Error_Pragma
10101 ("Priority_Specific_Dispatching incompatible "
10102 & "with Task_Dispatching_Policy#");
10103 end if;
10105 -- The use of Priority_Specific_Dispatching forces ceiling
10106 -- locking policy.
10108 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
10109 Error_Msg_Sloc := Locking_Policy_Sloc;
10110 Error_Pragma
10111 ("Priority_Specific_Dispatching incompatible "
10112 & "with Locking_Policy#");
10114 -- Set the Ceiling_Locking policy, but preserve System_Location
10115 -- since we like the error message with the run time name.
10117 else
10118 Locking_Policy := 'C';
10120 if Locking_Policy_Sloc /= System_Location then
10121 Locking_Policy_Sloc := Loc;
10122 end if;
10123 end if;
10125 -- Add entry in the table
10127 Specific_Dispatching.Append
10128 ((Dispatching_Policy => DP,
10129 First_Priority => UI_To_Int (Lower_Val),
10130 Last_Priority => UI_To_Int (Upper_Val),
10131 Pragma_Loc => Loc));
10132 end if;
10133 end Priority_Specific_Dispatching;
10135 -------------
10136 -- Profile --
10137 -------------
10139 -- pragma Profile (profile_IDENTIFIER);
10141 -- profile_IDENTIFIER => Restricted | Ravenscar
10143 when Pragma_Profile =>
10144 Ada_2005_Pragma;
10145 Check_Arg_Count (1);
10146 Check_Valid_Configuration_Pragma;
10147 Check_No_Identifiers;
10149 declare
10150 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10151 begin
10152 if Chars (Argx) = Name_Ravenscar then
10153 Set_Ravenscar_Profile (N);
10154 elsif Chars (Argx) = Name_Restricted then
10155 Set_Profile_Restrictions
10156 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10157 else
10158 Error_Pragma_Arg ("& is not a valid profile", Argx);
10159 end if;
10160 end;
10162 ----------------------
10163 -- Profile_Warnings --
10164 ----------------------
10166 -- pragma Profile_Warnings (profile_IDENTIFIER);
10168 -- profile_IDENTIFIER => Restricted | Ravenscar
10170 when Pragma_Profile_Warnings =>
10171 GNAT_Pragma;
10172 Check_Arg_Count (1);
10173 Check_Valid_Configuration_Pragma;
10174 Check_No_Identifiers;
10176 declare
10177 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10178 begin
10179 if Chars (Argx) = Name_Ravenscar then
10180 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
10181 elsif Chars (Argx) = Name_Restricted then
10182 Set_Profile_Restrictions (Restricted, N, Warn => True);
10183 else
10184 Error_Pragma_Arg ("& is not a valid profile", Argx);
10185 end if;
10186 end;
10188 --------------------------
10189 -- Propagate_Exceptions --
10190 --------------------------
10192 -- pragma Propagate_Exceptions;
10194 -- Note: this pragma is obsolete and has no effect
10196 when Pragma_Propagate_Exceptions =>
10197 GNAT_Pragma;
10198 Check_Arg_Count (0);
10200 if In_Extended_Main_Source_Unit (N) then
10201 Propagate_Exceptions := True;
10202 end if;
10204 ------------------
10205 -- Psect_Object --
10206 ------------------
10208 -- pragma Psect_Object (
10209 -- [Internal =>] LOCAL_NAME,
10210 -- [, [External =>] EXTERNAL_SYMBOL]
10211 -- [, [Size =>] EXTERNAL_SYMBOL]);
10213 when Pragma_Psect_Object | Pragma_Common_Object =>
10214 Psect_Object : declare
10215 Args : Args_List (1 .. 3);
10216 Names : constant Name_List (1 .. 3) := (
10217 Name_Internal,
10218 Name_External,
10219 Name_Size);
10221 Internal : Node_Id renames Args (1);
10222 External : Node_Id renames Args (2);
10223 Size : Node_Id renames Args (3);
10225 Def_Id : Entity_Id;
10227 procedure Check_Too_Long (Arg : Node_Id);
10228 -- Posts message if the argument is an identifier with more
10229 -- than 31 characters, or a string literal with more than
10230 -- 31 characters, and we are operating under VMS
10232 --------------------
10233 -- Check_Too_Long --
10234 --------------------
10236 procedure Check_Too_Long (Arg : Node_Id) is
10237 X : constant Node_Id := Original_Node (Arg);
10239 begin
10240 if not Nkind_In (X, N_String_Literal, N_Identifier) then
10241 Error_Pragma_Arg
10242 ("inappropriate argument for pragma %", Arg);
10243 end if;
10245 if OpenVMS_On_Target then
10246 if (Nkind (X) = N_String_Literal
10247 and then String_Length (Strval (X)) > 31)
10248 or else
10249 (Nkind (X) = N_Identifier
10250 and then Length_Of_Name (Chars (X)) > 31)
10251 then
10252 Error_Pragma_Arg
10253 ("argument for pragma % is longer than 31 characters",
10254 Arg);
10255 end if;
10256 end if;
10257 end Check_Too_Long;
10259 -- Start of processing for Common_Object/Psect_Object
10261 begin
10262 GNAT_Pragma;
10263 Gather_Associations (Names, Args);
10264 Process_Extended_Import_Export_Internal_Arg (Internal);
10266 Def_Id := Entity (Internal);
10268 if Ekind (Def_Id) /= E_Constant
10269 and then Ekind (Def_Id) /= E_Variable
10270 then
10271 Error_Pragma_Arg
10272 ("pragma% must designate an object", Internal);
10273 end if;
10275 Check_Too_Long (Internal);
10277 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
10278 Error_Pragma_Arg
10279 ("cannot use pragma% for imported/exported object",
10280 Internal);
10281 end if;
10283 if Is_Concurrent_Type (Etype (Internal)) then
10284 Error_Pragma_Arg
10285 ("cannot specify pragma % for task/protected object",
10286 Internal);
10287 end if;
10289 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
10290 or else
10291 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
10292 then
10293 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
10294 end if;
10296 if Ekind (Def_Id) = E_Constant then
10297 Error_Pragma_Arg
10298 ("cannot specify pragma % for a constant", Internal);
10299 end if;
10301 if Is_Record_Type (Etype (Internal)) then
10302 declare
10303 Ent : Entity_Id;
10304 Decl : Entity_Id;
10306 begin
10307 Ent := First_Entity (Etype (Internal));
10308 while Present (Ent) loop
10309 Decl := Declaration_Node (Ent);
10311 if Ekind (Ent) = E_Component
10312 and then Nkind (Decl) = N_Component_Declaration
10313 and then Present (Expression (Decl))
10314 and then Warn_On_Export_Import
10315 then
10316 Error_Msg_N
10317 ("?object for pragma % has defaults", Internal);
10318 exit;
10320 else
10321 Next_Entity (Ent);
10322 end if;
10323 end loop;
10324 end;
10325 end if;
10327 if Present (Size) then
10328 Check_Too_Long (Size);
10329 end if;
10331 if Present (External) then
10332 Check_Arg_Is_External_Name (External);
10333 Check_Too_Long (External);
10334 end if;
10336 -- If all error tests pass, link pragma on to the rep item chain
10338 Record_Rep_Item (Def_Id, N);
10339 end Psect_Object;
10341 ----------
10342 -- Pure --
10343 ----------
10345 -- pragma Pure [(library_unit_NAME)];
10347 when Pragma_Pure => Pure : declare
10348 Ent : Entity_Id;
10350 begin
10351 Check_Ada_83_Warning;
10352 Check_Valid_Library_Unit_Pragma;
10354 if Nkind (N) = N_Null_Statement then
10355 return;
10356 end if;
10358 Ent := Find_Lib_Unit_Name;
10359 Set_Is_Pure (Ent);
10360 Set_Has_Pragma_Pure (Ent);
10361 Set_Suppress_Elaboration_Warnings (Ent);
10362 end Pure;
10364 -------------
10365 -- Pure_05 --
10366 -------------
10368 -- pragma Pure_05 [(library_unit_NAME)];
10370 -- This pragma is useable only in GNAT_Mode, where it is used like
10371 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
10372 -- it is ignored). It may be used after a pragma Preelaborate, in
10373 -- which case it overrides the effect of the pragma Preelaborate.
10374 -- This is used to implement AI-362 which recategorizes some run-time
10375 -- packages in Ada 2005 mode.
10377 when Pragma_Pure_05 => Pure_05 : declare
10378 Ent : Entity_Id;
10380 begin
10381 GNAT_Pragma;
10382 Check_Valid_Library_Unit_Pragma;
10384 if not GNAT_Mode then
10385 Error_Pragma ("pragma% only available in GNAT mode");
10386 end if;
10388 if Nkind (N) = N_Null_Statement then
10389 return;
10390 end if;
10392 -- This is one of the few cases where we need to test the value of
10393 -- Ada_Version_Explicit rather than Ada_Version (which is always
10394 -- set to Ada_05 in a predefined unit), we need to know the
10395 -- explicit version set to know if this pragma is active.
10397 if Ada_Version_Explicit >= Ada_05 then
10398 Ent := Find_Lib_Unit_Name;
10399 Set_Is_Preelaborated (Ent, False);
10400 Set_Is_Pure (Ent);
10401 Set_Suppress_Elaboration_Warnings (Ent);
10402 end if;
10403 end Pure_05;
10405 -------------------
10406 -- Pure_Function --
10407 -------------------
10409 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
10411 when Pragma_Pure_Function => Pure_Function : declare
10412 E_Id : Node_Id;
10413 E : Entity_Id;
10414 Def_Id : Entity_Id;
10415 Effective : Boolean := False;
10417 begin
10418 GNAT_Pragma;
10419 Check_Arg_Count (1);
10420 Check_Optional_Identifier (Arg1, Name_Entity);
10421 Check_Arg_Is_Local_Name (Arg1);
10422 E_Id := Expression (Arg1);
10424 if Error_Posted (E_Id) then
10425 return;
10426 end if;
10428 -- Loop through homonyms (overloadings) of referenced entity
10430 E := Entity (E_Id);
10432 if Present (E) then
10433 loop
10434 Def_Id := Get_Base_Subprogram (E);
10436 if Ekind (Def_Id) /= E_Function
10437 and then Ekind (Def_Id) /= E_Generic_Function
10438 and then Ekind (Def_Id) /= E_Operator
10439 then
10440 Error_Pragma_Arg
10441 ("pragma% requires a function name", Arg1);
10442 end if;
10444 Set_Is_Pure (Def_Id);
10446 if not Has_Pragma_Pure_Function (Def_Id) then
10447 Set_Has_Pragma_Pure_Function (Def_Id);
10448 Effective := True;
10449 end if;
10451 E := Homonym (E);
10452 exit when No (E) or else Scope (E) /= Current_Scope;
10453 end loop;
10455 if not Effective
10456 and then Warn_On_Redundant_Constructs
10457 then
10458 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
10459 N, Entity (E_Id));
10460 end if;
10461 end if;
10462 end Pure_Function;
10464 --------------------
10465 -- Queuing_Policy --
10466 --------------------
10468 -- pragma Queuing_Policy (policy_IDENTIFIER);
10470 when Pragma_Queuing_Policy => declare
10471 QP : Character;
10473 begin
10474 Check_Ada_83_Warning;
10475 Check_Arg_Count (1);
10476 Check_No_Identifiers;
10477 Check_Arg_Is_Queuing_Policy (Arg1);
10478 Check_Valid_Configuration_Pragma;
10479 Get_Name_String (Chars (Expression (Arg1)));
10480 QP := Fold_Upper (Name_Buffer (1));
10482 if Queuing_Policy /= ' '
10483 and then Queuing_Policy /= QP
10484 then
10485 Error_Msg_Sloc := Queuing_Policy_Sloc;
10486 Error_Pragma ("queuing policy incompatible with policy#");
10488 -- Set new policy, but always preserve System_Location since we
10489 -- like the error message with the run time name.
10491 else
10492 Queuing_Policy := QP;
10494 if Queuing_Policy_Sloc /= System_Location then
10495 Queuing_Policy_Sloc := Loc;
10496 end if;
10497 end if;
10498 end;
10500 -----------------------
10501 -- Relative_Deadline --
10502 -----------------------
10504 -- pragma Relative_Deadline (time_span_EXPRESSION);
10506 when Pragma_Relative_Deadline => Relative_Deadline : declare
10507 P : constant Node_Id := Parent (N);
10508 Arg : Node_Id;
10510 begin
10511 Ada_2005_Pragma;
10512 Check_No_Identifiers;
10513 Check_Arg_Count (1);
10515 Arg := Expression (Arg1);
10517 -- The expression must be analyzed in the special manner described
10518 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
10520 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
10522 -- Subprogram case
10524 if Nkind (P) = N_Subprogram_Body then
10525 Check_In_Main_Program;
10527 -- Tasks
10529 elsif Nkind (P) = N_Task_Definition then
10530 null;
10532 -- Anything else is incorrect
10534 else
10535 Pragma_Misplaced;
10536 end if;
10538 if Has_Relative_Deadline_Pragma (P) then
10539 Error_Pragma ("duplicate pragma% not allowed");
10540 else
10541 Set_Has_Relative_Deadline_Pragma (P, True);
10543 if Nkind (P) = N_Task_Definition then
10544 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10545 end if;
10546 end if;
10547 end Relative_Deadline;
10549 ---------------------------
10550 -- Remote_Call_Interface --
10551 ---------------------------
10553 -- pragma Remote_Call_Interface [(library_unit_NAME)];
10555 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
10556 Cunit_Node : Node_Id;
10557 Cunit_Ent : Entity_Id;
10558 K : Node_Kind;
10560 begin
10561 Check_Ada_83_Warning;
10562 Check_Valid_Library_Unit_Pragma;
10564 if Nkind (N) = N_Null_Statement then
10565 return;
10566 end if;
10568 Cunit_Node := Cunit (Current_Sem_Unit);
10569 K := Nkind (Unit (Cunit_Node));
10570 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10572 if K = N_Package_Declaration
10573 or else K = N_Generic_Package_Declaration
10574 or else K = N_Subprogram_Declaration
10575 or else K = N_Generic_Subprogram_Declaration
10576 or else (K = N_Subprogram_Body
10577 and then Acts_As_Spec (Unit (Cunit_Node)))
10578 then
10579 null;
10580 else
10581 Error_Pragma (
10582 "pragma% must apply to package or subprogram declaration");
10583 end if;
10585 Set_Is_Remote_Call_Interface (Cunit_Ent);
10586 end Remote_Call_Interface;
10588 ------------------
10589 -- Remote_Types --
10590 ------------------
10592 -- pragma Remote_Types [(library_unit_NAME)];
10594 when Pragma_Remote_Types => Remote_Types : declare
10595 Cunit_Node : Node_Id;
10596 Cunit_Ent : Entity_Id;
10598 begin
10599 Check_Ada_83_Warning;
10600 Check_Valid_Library_Unit_Pragma;
10602 if Nkind (N) = N_Null_Statement then
10603 return;
10604 end if;
10606 Cunit_Node := Cunit (Current_Sem_Unit);
10607 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10609 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
10610 N_Generic_Package_Declaration)
10611 then
10612 Error_Pragma
10613 ("pragma% can only apply to a package declaration");
10614 end if;
10616 Set_Is_Remote_Types (Cunit_Ent);
10617 end Remote_Types;
10619 ---------------
10620 -- Ravenscar --
10621 ---------------
10623 -- pragma Ravenscar;
10625 when Pragma_Ravenscar =>
10626 GNAT_Pragma;
10627 Check_Arg_Count (0);
10628 Check_Valid_Configuration_Pragma;
10629 Set_Ravenscar_Profile (N);
10631 if Warn_On_Obsolescent_Feature then
10632 Error_Msg_N
10633 ("pragma Ravenscar is an obsolescent feature?", N);
10634 Error_Msg_N
10635 ("|use pragma Profile (Ravenscar) instead", N);
10636 end if;
10638 -------------------------
10639 -- Restricted_Run_Time --
10640 -------------------------
10642 -- pragma Restricted_Run_Time;
10644 when Pragma_Restricted_Run_Time =>
10645 GNAT_Pragma;
10646 Check_Arg_Count (0);
10647 Check_Valid_Configuration_Pragma;
10648 Set_Profile_Restrictions
10649 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10651 if Warn_On_Obsolescent_Feature then
10652 Error_Msg_N
10653 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
10654 Error_Msg_N
10655 ("|use pragma Profile (Restricted) instead", N);
10656 end if;
10658 ------------------
10659 -- Restrictions --
10660 ------------------
10662 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
10664 -- RESTRICTION ::=
10665 -- restriction_IDENTIFIER
10666 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10668 when Pragma_Restrictions =>
10669 Process_Restrictions_Or_Restriction_Warnings
10670 (Warn => Treat_Restrictions_As_Warnings);
10672 --------------------------
10673 -- Restriction_Warnings --
10674 --------------------------
10676 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
10678 -- RESTRICTION ::=
10679 -- restriction_IDENTIFIER
10680 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10682 when Pragma_Restriction_Warnings =>
10683 GNAT_Pragma;
10684 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
10686 ----------------
10687 -- Reviewable --
10688 ----------------
10690 -- pragma Reviewable;
10692 when Pragma_Reviewable =>
10693 Check_Ada_83_Warning;
10694 Check_Arg_Count (0);
10696 -- Call dummy debugging function rv. This is done to assist front
10697 -- end debugging. By placing a Reviewable pragma in the source
10698 -- program, a breakpoint on rv catches this place in the source,
10699 -- allowing convenient stepping to the point of interest.
10703 --------------------------
10704 -- Short_Circuit_And_Or --
10705 --------------------------
10707 when Pragma_Short_Circuit_And_Or =>
10708 GNAT_Pragma;
10709 Check_Arg_Count (0);
10710 Check_Valid_Configuration_Pragma;
10711 Short_Circuit_And_Or := True;
10713 -------------------
10714 -- Share_Generic --
10715 -------------------
10717 -- pragma Share_Generic (NAME {, NAME});
10719 when Pragma_Share_Generic =>
10720 GNAT_Pragma;
10721 Process_Generic_List;
10723 ------------
10724 -- Shared --
10725 ------------
10727 -- pragma Shared (LOCAL_NAME);
10729 when Pragma_Shared =>
10730 GNAT_Pragma;
10731 Process_Atomic_Shared_Volatile;
10733 --------------------
10734 -- Shared_Passive --
10735 --------------------
10737 -- pragma Shared_Passive [(library_unit_NAME)];
10739 -- Set the flag Is_Shared_Passive of program unit name entity
10741 when Pragma_Shared_Passive => Shared_Passive : declare
10742 Cunit_Node : Node_Id;
10743 Cunit_Ent : Entity_Id;
10745 begin
10746 Check_Ada_83_Warning;
10747 Check_Valid_Library_Unit_Pragma;
10749 if Nkind (N) = N_Null_Statement then
10750 return;
10751 end if;
10753 Cunit_Node := Cunit (Current_Sem_Unit);
10754 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10756 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
10757 N_Generic_Package_Declaration)
10758 then
10759 Error_Pragma
10760 ("pragma% can only apply to a package declaration");
10761 end if;
10763 Set_Is_Shared_Passive (Cunit_Ent);
10764 end Shared_Passive;
10766 ----------------------
10767 -- Source_File_Name --
10768 ----------------------
10770 -- There are five forms for this pragma:
10772 -- pragma Source_File_Name (
10773 -- [UNIT_NAME =>] unit_NAME,
10774 -- BODY_FILE_NAME => STRING_LITERAL
10775 -- [, [INDEX =>] INTEGER_LITERAL]);
10777 -- pragma Source_File_Name (
10778 -- [UNIT_NAME =>] unit_NAME,
10779 -- SPEC_FILE_NAME => STRING_LITERAL
10780 -- [, [INDEX =>] INTEGER_LITERAL]);
10782 -- pragma Source_File_Name (
10783 -- BODY_FILE_NAME => STRING_LITERAL
10784 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10785 -- [, CASING => CASING_SPEC]);
10787 -- pragma Source_File_Name (
10788 -- SPEC_FILE_NAME => STRING_LITERAL
10789 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10790 -- [, CASING => CASING_SPEC]);
10792 -- pragma Source_File_Name (
10793 -- SUBUNIT_FILE_NAME => STRING_LITERAL
10794 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10795 -- [, CASING => CASING_SPEC]);
10797 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
10799 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
10800 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
10801 -- only be used when no project file is used, while SFNP can only be
10802 -- used when a project file is used.
10804 -- No processing here. Processing was completed during parsing, since
10805 -- we need to have file names set as early as possible. Units are
10806 -- loaded well before semantic processing starts.
10808 -- The only processing we defer to this point is the check for
10809 -- correct placement.
10811 when Pragma_Source_File_Name =>
10812 GNAT_Pragma;
10813 Check_Valid_Configuration_Pragma;
10815 ------------------------------
10816 -- Source_File_Name_Project --
10817 ------------------------------
10819 -- See Source_File_Name for syntax
10821 -- No processing here. Processing was completed during parsing, since
10822 -- we need to have file names set as early as possible. Units are
10823 -- loaded well before semantic processing starts.
10825 -- The only processing we defer to this point is the check for
10826 -- correct placement.
10828 when Pragma_Source_File_Name_Project =>
10829 GNAT_Pragma;
10830 Check_Valid_Configuration_Pragma;
10832 -- Check that a pragma Source_File_Name_Project is used only in a
10833 -- configuration pragmas file.
10835 -- Pragmas Source_File_Name_Project should only be generated by
10836 -- the Project Manager in configuration pragmas files.
10838 -- This is really an ugly test. It seems to depend on some
10839 -- accidental and undocumented property. At the very least it
10840 -- needs to be documented, but it would be better to have a
10841 -- clean way of testing if we are in a configuration file???
10843 if Present (Parent (N)) then
10844 Error_Pragma
10845 ("pragma% can only appear in a configuration pragmas file");
10846 end if;
10848 ----------------------
10849 -- Source_Reference --
10850 ----------------------
10852 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
10854 -- Nothing to do, all processing completed in Par.Prag, since we need
10855 -- the information for possible parser messages that are output.
10857 when Pragma_Source_Reference =>
10858 GNAT_Pragma;
10860 --------------------------------
10861 -- Static_Elaboration_Desired --
10862 --------------------------------
10864 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
10866 when Pragma_Static_Elaboration_Desired =>
10867 GNAT_Pragma;
10868 Check_At_Most_N_Arguments (1);
10870 if Is_Compilation_Unit (Current_Scope)
10871 and then Ekind (Current_Scope) = E_Package
10872 then
10873 Set_Static_Elaboration_Desired (Current_Scope, True);
10874 else
10875 Error_Pragma ("pragma% must apply to a library-level package");
10876 end if;
10878 ------------------
10879 -- Storage_Size --
10880 ------------------
10882 -- pragma Storage_Size (EXPRESSION);
10884 when Pragma_Storage_Size => Storage_Size : declare
10885 P : constant Node_Id := Parent (N);
10886 Arg : Node_Id;
10888 begin
10889 Check_No_Identifiers;
10890 Check_Arg_Count (1);
10892 -- The expression must be analyzed in the special manner described
10893 -- in "Handling of Default Expressions" in sem.ads.
10895 Arg := Expression (Arg1);
10896 Preanalyze_Spec_Expression (Arg, Any_Integer);
10898 if not Is_Static_Expression (Arg) then
10899 Check_Restriction (Static_Storage_Size, Arg);
10900 end if;
10902 if Nkind (P) /= N_Task_Definition then
10903 Pragma_Misplaced;
10904 return;
10906 else
10907 if Has_Storage_Size_Pragma (P) then
10908 Error_Pragma ("duplicate pragma% not allowed");
10909 else
10910 Set_Has_Storage_Size_Pragma (P, True);
10911 end if;
10913 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10914 -- ??? exp_ch9 should use this!
10915 end if;
10916 end Storage_Size;
10918 ------------------
10919 -- Storage_Unit --
10920 ------------------
10922 -- pragma Storage_Unit (NUMERIC_LITERAL);
10924 -- Only permitted argument is System'Storage_Unit value
10926 when Pragma_Storage_Unit =>
10927 Check_No_Identifiers;
10928 Check_Arg_Count (1);
10929 Check_Arg_Is_Integer_Literal (Arg1);
10931 if Intval (Expression (Arg1)) /=
10932 UI_From_Int (Ttypes.System_Storage_Unit)
10933 then
10934 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
10935 Error_Pragma_Arg
10936 ("the only allowed argument for pragma% is ^", Arg1);
10937 end if;
10939 --------------------
10940 -- Stream_Convert --
10941 --------------------
10943 -- pragma Stream_Convert (
10944 -- [Entity =>] type_LOCAL_NAME,
10945 -- [Read =>] function_NAME,
10946 -- [Write =>] function NAME);
10948 when Pragma_Stream_Convert => Stream_Convert : declare
10950 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
10951 -- Check that the given argument is the name of a local function
10952 -- of one argument that is not overloaded earlier in the current
10953 -- local scope. A check is also made that the argument is a
10954 -- function with one parameter.
10956 --------------------------------------
10957 -- Check_OK_Stream_Convert_Function --
10958 --------------------------------------
10960 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
10961 Ent : Entity_Id;
10963 begin
10964 Check_Arg_Is_Local_Name (Arg);
10965 Ent := Entity (Expression (Arg));
10967 if Has_Homonym (Ent) then
10968 Error_Pragma_Arg
10969 ("argument for pragma% may not be overloaded", Arg);
10970 end if;
10972 if Ekind (Ent) /= E_Function
10973 or else No (First_Formal (Ent))
10974 or else Present (Next_Formal (First_Formal (Ent)))
10975 then
10976 Error_Pragma_Arg
10977 ("argument for pragma% must be" &
10978 " function of one argument", Arg);
10979 end if;
10980 end Check_OK_Stream_Convert_Function;
10982 -- Start of processing for Stream_Convert
10984 begin
10985 GNAT_Pragma;
10986 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
10987 Check_Arg_Count (3);
10988 Check_Optional_Identifier (Arg1, Name_Entity);
10989 Check_Optional_Identifier (Arg2, Name_Read);
10990 Check_Optional_Identifier (Arg3, Name_Write);
10991 Check_Arg_Is_Local_Name (Arg1);
10992 Check_OK_Stream_Convert_Function (Arg2);
10993 Check_OK_Stream_Convert_Function (Arg3);
10995 declare
10996 Typ : constant Entity_Id :=
10997 Underlying_Type (Entity (Expression (Arg1)));
10998 Read : constant Entity_Id := Entity (Expression (Arg2));
10999 Write : constant Entity_Id := Entity (Expression (Arg3));
11001 begin
11002 Check_First_Subtype (Arg1);
11004 -- Check for too early or too late. Note that we don't enforce
11005 -- the rule about primitive operations in this case, since, as
11006 -- is the case for explicit stream attributes themselves, these
11007 -- restrictions are not appropriate. Note that the chaining of
11008 -- the pragma by Rep_Item_Too_Late is actually the critical
11009 -- processing done for this pragma.
11011 if Rep_Item_Too_Early (Typ, N)
11012 or else
11013 Rep_Item_Too_Late (Typ, N, FOnly => True)
11014 then
11015 return;
11016 end if;
11018 -- Return if previous error
11020 if Etype (Typ) = Any_Type
11021 or else
11022 Etype (Read) = Any_Type
11023 or else
11024 Etype (Write) = Any_Type
11025 then
11026 return;
11027 end if;
11029 -- Error checks
11031 if Underlying_Type (Etype (Read)) /= Typ then
11032 Error_Pragma_Arg
11033 ("incorrect return type for function&", Arg2);
11034 end if;
11036 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
11037 Error_Pragma_Arg
11038 ("incorrect parameter type for function&", Arg3);
11039 end if;
11041 if Underlying_Type (Etype (First_Formal (Read))) /=
11042 Underlying_Type (Etype (Write))
11043 then
11044 Error_Pragma_Arg
11045 ("result type of & does not match Read parameter type",
11046 Arg3);
11047 end if;
11048 end;
11049 end Stream_Convert;
11051 -------------------------
11052 -- Style_Checks (GNAT) --
11053 -------------------------
11055 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11057 -- This is processed by the parser since some of the style checks
11058 -- take place during source scanning and parsing. This means that
11059 -- we don't need to issue error messages here.
11061 when Pragma_Style_Checks => Style_Checks : declare
11062 A : constant Node_Id := Expression (Arg1);
11063 S : String_Id;
11064 C : Char_Code;
11066 begin
11067 GNAT_Pragma;
11068 Check_No_Identifiers;
11070 -- Two argument form
11072 if Arg_Count = 2 then
11073 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11075 declare
11076 E_Id : Node_Id;
11077 E : Entity_Id;
11079 begin
11080 E_Id := Expression (Arg2);
11081 Analyze (E_Id);
11083 if not Is_Entity_Name (E_Id) then
11084 Error_Pragma_Arg
11085 ("second argument of pragma% must be entity name",
11086 Arg2);
11087 end if;
11089 E := Entity (E_Id);
11091 if E = Any_Id then
11092 return;
11093 else
11094 loop
11095 Set_Suppress_Style_Checks (E,
11096 (Chars (Expression (Arg1)) = Name_Off));
11097 exit when No (Homonym (E));
11098 E := Homonym (E);
11099 end loop;
11100 end if;
11101 end;
11103 -- One argument form
11105 else
11106 Check_Arg_Count (1);
11108 if Nkind (A) = N_String_Literal then
11109 S := Strval (A);
11111 declare
11112 Slen : constant Natural := Natural (String_Length (S));
11113 Options : String (1 .. Slen);
11114 J : Natural;
11116 begin
11117 J := 1;
11118 loop
11119 C := Get_String_Char (S, Int (J));
11120 exit when not In_Character_Range (C);
11121 Options (J) := Get_Character (C);
11123 -- If at end of string, set options. As per discussion
11124 -- above, no need to check for errors, since we issued
11125 -- them in the parser.
11127 if J = Slen then
11128 Set_Style_Check_Options (Options);
11129 exit;
11130 end if;
11132 J := J + 1;
11133 end loop;
11134 end;
11136 elsif Nkind (A) = N_Identifier then
11137 if Chars (A) = Name_All_Checks then
11138 Set_Default_Style_Check_Options;
11140 elsif Chars (A) = Name_On then
11141 Style_Check := True;
11143 elsif Chars (A) = Name_Off then
11144 Style_Check := False;
11145 end if;
11146 end if;
11147 end if;
11148 end Style_Checks;
11150 --------------
11151 -- Subtitle --
11152 --------------
11154 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
11156 when Pragma_Subtitle =>
11157 GNAT_Pragma;
11158 Check_Arg_Count (1);
11159 Check_Optional_Identifier (Arg1, Name_Subtitle);
11160 Check_Arg_Is_String_Literal (Arg1);
11162 --------------
11163 -- Suppress --
11164 --------------
11166 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
11168 when Pragma_Suppress =>
11169 Process_Suppress_Unsuppress (True);
11171 ------------------
11172 -- Suppress_All --
11173 ------------------
11175 -- pragma Suppress_All;
11177 -- The only check made here is that the pragma appears in the proper
11178 -- place, i.e. following a compilation unit. If indeed it appears in
11179 -- this context, then the parser has already inserted an equivalent
11180 -- pragma Suppress (All_Checks) to get the required effect.
11182 when Pragma_Suppress_All =>
11183 GNAT_Pragma;
11184 Check_Arg_Count (0);
11186 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
11187 or else not Is_List_Member (N)
11188 or else List_Containing (N) /= Pragmas_After (Parent (N))
11189 then
11190 Error_Pragma
11191 ("misplaced pragma%, must follow compilation unit");
11192 end if;
11194 -------------------------
11195 -- Suppress_Debug_Info --
11196 -------------------------
11198 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
11200 when Pragma_Suppress_Debug_Info =>
11201 GNAT_Pragma;
11202 Check_Arg_Count (1);
11203 Check_Optional_Identifier (Arg1, Name_Entity);
11204 Check_Arg_Is_Local_Name (Arg1);
11205 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
11207 ----------------------------------
11208 -- Suppress_Exception_Locations --
11209 ----------------------------------
11211 -- pragma Suppress_Exception_Locations;
11213 when Pragma_Suppress_Exception_Locations =>
11214 GNAT_Pragma;
11215 Check_Arg_Count (0);
11216 Check_Valid_Configuration_Pragma;
11217 Exception_Locations_Suppressed := True;
11219 -----------------------------
11220 -- Suppress_Initialization --
11221 -----------------------------
11223 -- pragma Suppress_Initialization ([Entity =>] type_Name);
11225 when Pragma_Suppress_Initialization => Suppress_Init : declare
11226 E_Id : Node_Id;
11227 E : Entity_Id;
11229 begin
11230 GNAT_Pragma;
11231 Check_Arg_Count (1);
11232 Check_Optional_Identifier (Arg1, Name_Entity);
11233 Check_Arg_Is_Local_Name (Arg1);
11235 E_Id := Expression (Arg1);
11237 if Etype (E_Id) = Any_Type then
11238 return;
11239 end if;
11241 E := Entity (E_Id);
11243 if Is_Type (E) then
11244 if Is_Incomplete_Or_Private_Type (E) then
11245 if No (Full_View (Base_Type (E))) then
11246 Error_Pragma_Arg
11247 ("argument of pragma% cannot be an incomplete type",
11248 Arg1);
11249 else
11250 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
11251 end if;
11252 else
11253 Set_Suppress_Init_Proc (Base_Type (E));
11254 end if;
11256 else
11257 Error_Pragma_Arg
11258 ("pragma% requires argument that is a type name", Arg1);
11259 end if;
11260 end Suppress_Init;
11262 -----------------
11263 -- System_Name --
11264 -----------------
11266 -- pragma System_Name (DIRECT_NAME);
11268 -- Syntax check: one argument, which must be the identifier GNAT or
11269 -- the identifier GCC, no other identifiers are acceptable.
11271 when Pragma_System_Name =>
11272 GNAT_Pragma;
11273 Check_No_Identifiers;
11274 Check_Arg_Count (1);
11275 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
11277 -----------------------------
11278 -- Task_Dispatching_Policy --
11279 -----------------------------
11281 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
11283 when Pragma_Task_Dispatching_Policy => declare
11284 DP : Character;
11286 begin
11287 Check_Ada_83_Warning;
11288 Check_Arg_Count (1);
11289 Check_No_Identifiers;
11290 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11291 Check_Valid_Configuration_Pragma;
11292 Get_Name_String (Chars (Expression (Arg1)));
11293 DP := Fold_Upper (Name_Buffer (1));
11295 if Task_Dispatching_Policy /= ' '
11296 and then Task_Dispatching_Policy /= DP
11297 then
11298 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11299 Error_Pragma
11300 ("task dispatching policy incompatible with policy#");
11302 -- Set new policy, but always preserve System_Location since we
11303 -- like the error message with the run time name.
11305 else
11306 Task_Dispatching_Policy := DP;
11308 if Task_Dispatching_Policy_Sloc /= System_Location then
11309 Task_Dispatching_Policy_Sloc := Loc;
11310 end if;
11311 end if;
11312 end;
11314 --------------
11315 -- Task_Info --
11316 --------------
11318 -- pragma Task_Info (EXPRESSION);
11320 when Pragma_Task_Info => Task_Info : declare
11321 P : constant Node_Id := Parent (N);
11323 begin
11324 GNAT_Pragma;
11326 if Nkind (P) /= N_Task_Definition then
11327 Error_Pragma ("pragma% must appear in task definition");
11328 end if;
11330 Check_No_Identifiers;
11331 Check_Arg_Count (1);
11333 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
11335 if Etype (Expression (Arg1)) = Any_Type then
11336 return;
11337 end if;
11339 if Has_Task_Info_Pragma (P) then
11340 Error_Pragma ("duplicate pragma% not allowed");
11341 else
11342 Set_Has_Task_Info_Pragma (P, True);
11343 end if;
11344 end Task_Info;
11346 ---------------
11347 -- Task_Name --
11348 ---------------
11350 -- pragma Task_Name (string_EXPRESSION);
11352 when Pragma_Task_Name => Task_Name : declare
11353 P : constant Node_Id := Parent (N);
11354 Arg : Node_Id;
11356 begin
11357 Check_No_Identifiers;
11358 Check_Arg_Count (1);
11360 Arg := Expression (Arg1);
11362 -- The expression is used in the call to Create_Task, and must be
11363 -- expanded there, not in the context of the current spec. It must
11364 -- however be analyzed to capture global references, in case it
11365 -- appears in a generic context.
11367 Preanalyze_And_Resolve (Arg, Standard_String);
11369 if Nkind (P) /= N_Task_Definition then
11370 Pragma_Misplaced;
11371 end if;
11373 if Has_Task_Name_Pragma (P) then
11374 Error_Pragma ("duplicate pragma% not allowed");
11375 else
11376 Set_Has_Task_Name_Pragma (P, True);
11377 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11378 end if;
11379 end Task_Name;
11381 ------------------
11382 -- Task_Storage --
11383 ------------------
11385 -- pragma Task_Storage (
11386 -- [Task_Type =>] LOCAL_NAME,
11387 -- [Top_Guard =>] static_integer_EXPRESSION);
11389 when Pragma_Task_Storage => Task_Storage : declare
11390 Args : Args_List (1 .. 2);
11391 Names : constant Name_List (1 .. 2) := (
11392 Name_Task_Type,
11393 Name_Top_Guard);
11395 Task_Type : Node_Id renames Args (1);
11396 Top_Guard : Node_Id renames Args (2);
11398 Ent : Entity_Id;
11400 begin
11401 GNAT_Pragma;
11402 Gather_Associations (Names, Args);
11404 if No (Task_Type) then
11405 Error_Pragma
11406 ("missing task_type argument for pragma%");
11407 end if;
11409 Check_Arg_Is_Local_Name (Task_Type);
11411 Ent := Entity (Task_Type);
11413 if not Is_Task_Type (Ent) then
11414 Error_Pragma_Arg
11415 ("argument for pragma% must be task type", Task_Type);
11416 end if;
11418 if No (Top_Guard) then
11419 Error_Pragma_Arg
11420 ("pragma% takes two arguments", Task_Type);
11421 else
11422 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
11423 end if;
11425 Check_First_Subtype (Task_Type);
11427 if Rep_Item_Too_Late (Ent, N) then
11428 raise Pragma_Exit;
11429 end if;
11430 end Task_Storage;
11432 --------------------------
11433 -- Thread_Local_Storage --
11434 --------------------------
11436 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
11438 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
11439 Id : Node_Id;
11440 E : Entity_Id;
11442 begin
11443 GNAT_Pragma;
11444 Check_Arg_Count (1);
11445 Check_Optional_Identifier (Arg1, Name_Entity);
11446 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11448 Id := Expression (Arg1);
11449 Analyze (Id);
11451 if not Is_Entity_Name (Id)
11452 or else Ekind (Entity (Id)) /= E_Variable
11453 then
11454 Error_Pragma_Arg ("local variable name required", Arg1);
11455 end if;
11457 E := Entity (Id);
11459 if Rep_Item_Too_Early (E, N)
11460 or else Rep_Item_Too_Late (E, N)
11461 then
11462 raise Pragma_Exit;
11463 end if;
11465 Set_Has_Pragma_Thread_Local_Storage (E);
11466 Set_Has_Gigi_Rep_Item (E);
11467 end Thread_Local_Storage;
11469 ----------------
11470 -- Time_Slice --
11471 ----------------
11473 -- pragma Time_Slice (static_duration_EXPRESSION);
11475 when Pragma_Time_Slice => Time_Slice : declare
11476 Val : Ureal;
11477 Nod : Node_Id;
11479 begin
11480 GNAT_Pragma;
11481 Check_Arg_Count (1);
11482 Check_No_Identifiers;
11483 Check_In_Main_Program;
11484 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
11486 if not Error_Posted (Arg1) then
11487 Nod := Next (N);
11488 while Present (Nod) loop
11489 if Nkind (Nod) = N_Pragma
11490 and then Pragma_Name (Nod) = Name_Time_Slice
11491 then
11492 Error_Msg_Name_1 := Pname;
11493 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11494 end if;
11496 Next (Nod);
11497 end loop;
11498 end if;
11500 -- Process only if in main unit
11502 if Get_Source_Unit (Loc) = Main_Unit then
11503 Opt.Time_Slice_Set := True;
11504 Val := Expr_Value_R (Expression (Arg1));
11506 if Val <= Ureal_0 then
11507 Opt.Time_Slice_Value := 0;
11509 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
11510 Opt.Time_Slice_Value := 1_000_000_000;
11512 else
11513 Opt.Time_Slice_Value :=
11514 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
11515 end if;
11516 end if;
11517 end Time_Slice;
11519 -----------
11520 -- Title --
11521 -----------
11523 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
11525 -- TITLING_OPTION ::=
11526 -- [Title =>] STRING_LITERAL
11527 -- | [Subtitle =>] STRING_LITERAL
11529 when Pragma_Title => Title : declare
11530 Args : Args_List (1 .. 2);
11531 Names : constant Name_List (1 .. 2) := (
11532 Name_Title,
11533 Name_Subtitle);
11535 begin
11536 GNAT_Pragma;
11537 Gather_Associations (Names, Args);
11539 for J in 1 .. 2 loop
11540 if Present (Args (J)) then
11541 Check_Arg_Is_String_Literal (Args (J));
11542 end if;
11543 end loop;
11544 end Title;
11546 ---------------------
11547 -- Unchecked_Union --
11548 ---------------------
11550 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
11552 when Pragma_Unchecked_Union => Unchecked_Union : declare
11553 Assoc : constant Node_Id := Arg1;
11554 Type_Id : constant Node_Id := Expression (Assoc);
11555 Typ : Entity_Id;
11556 Discr : Entity_Id;
11557 Tdef : Node_Id;
11558 Clist : Node_Id;
11559 Vpart : Node_Id;
11560 Comp : Node_Id;
11561 Variant : Node_Id;
11563 begin
11564 Ada_2005_Pragma;
11565 Check_No_Identifiers;
11566 Check_Arg_Count (1);
11567 Check_Arg_Is_Local_Name (Arg1);
11569 Find_Type (Type_Id);
11570 Typ := Entity (Type_Id);
11572 if Typ = Any_Type
11573 or else Rep_Item_Too_Early (Typ, N)
11574 then
11575 return;
11576 else
11577 Typ := Underlying_Type (Typ);
11578 end if;
11580 if Rep_Item_Too_Late (Typ, N) then
11581 return;
11582 end if;
11584 Check_First_Subtype (Arg1);
11586 -- Note remaining cases are references to a type in the current
11587 -- declarative part. If we find an error, we post the error on
11588 -- the relevant type declaration at an appropriate point.
11590 if not Is_Record_Type (Typ) then
11591 Error_Msg_N ("Unchecked_Union must be record type", Typ);
11592 return;
11594 elsif Is_Tagged_Type (Typ) then
11595 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
11596 return;
11598 elsif Is_Limited_Type (Typ) then
11599 Error_Msg_N
11600 ("Unchecked_Union must not be limited record type", Typ);
11601 Explain_Limited_Type (Typ, Typ);
11602 return;
11604 else
11605 if not Has_Discriminants (Typ) then
11606 Error_Msg_N
11607 ("Unchecked_Union must have one discriminant", Typ);
11608 return;
11609 end if;
11611 Discr := First_Discriminant (Typ);
11612 while Present (Discr) loop
11613 if No (Discriminant_Default_Value (Discr)) then
11614 Error_Msg_N
11615 ("Unchecked_Union discriminant must have default value",
11616 Discr);
11617 end if;
11618 Next_Discriminant (Discr);
11619 end loop;
11621 Tdef := Type_Definition (Declaration_Node (Typ));
11622 Clist := Component_List (Tdef);
11624 Comp := First (Component_Items (Clist));
11625 while Present (Comp) loop
11626 Check_Component (Comp);
11627 Next (Comp);
11628 end loop;
11630 if No (Clist) or else No (Variant_Part (Clist)) then
11631 Error_Msg_N
11632 ("Unchecked_Union must have variant part",
11633 Tdef);
11634 return;
11635 end if;
11637 Vpart := Variant_Part (Clist);
11639 Variant := First (Variants (Vpart));
11640 while Present (Variant) loop
11641 Check_Variant (Variant);
11642 Next (Variant);
11643 end loop;
11644 end if;
11646 Set_Is_Unchecked_Union (Typ, True);
11647 Set_Convention (Typ, Convention_C);
11649 Set_Has_Unchecked_Union (Base_Type (Typ), True);
11650 Set_Is_Unchecked_Union (Base_Type (Typ), True);
11651 end Unchecked_Union;
11653 ------------------------
11654 -- Unimplemented_Unit --
11655 ------------------------
11657 -- pragma Unimplemented_Unit;
11659 -- Note: this only gives an error if we are generating code, or if
11660 -- we are in a generic library unit (where the pragma appears in the
11661 -- body, not in the spec).
11663 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
11664 Cunitent : constant Entity_Id :=
11665 Cunit_Entity (Get_Source_Unit (Loc));
11666 Ent_Kind : constant Entity_Kind :=
11667 Ekind (Cunitent);
11669 begin
11670 GNAT_Pragma;
11671 Check_Arg_Count (0);
11673 if Operating_Mode = Generate_Code
11674 or else Ent_Kind = E_Generic_Function
11675 or else Ent_Kind = E_Generic_Procedure
11676 or else Ent_Kind = E_Generic_Package
11677 then
11678 Get_Name_String (Chars (Cunitent));
11679 Set_Casing (Mixed_Case);
11680 Write_Str (Name_Buffer (1 .. Name_Len));
11681 Write_Str (" is not supported in this configuration");
11682 Write_Eol;
11683 raise Unrecoverable_Error;
11684 end if;
11685 end Unimplemented_Unit;
11687 ------------------------
11688 -- Universal_Aliasing --
11689 ------------------------
11691 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
11693 when Pragma_Universal_Aliasing => Universal_Alias : declare
11694 E_Id : Entity_Id;
11696 begin
11697 GNAT_Pragma;
11698 Check_Arg_Count (1);
11699 Check_Optional_Identifier (Arg2, Name_Entity);
11700 Check_Arg_Is_Local_Name (Arg1);
11701 E_Id := Entity (Expression (Arg1));
11703 if E_Id = Any_Type then
11704 return;
11705 elsif No (E_Id) or else not Is_Type (E_Id) then
11706 Error_Pragma_Arg ("pragma% requires type", Arg1);
11707 end if;
11709 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
11710 end Universal_Alias;
11712 --------------------
11713 -- Universal_Data --
11714 --------------------
11716 -- pragma Universal_Data [(library_unit_NAME)];
11718 when Pragma_Universal_Data =>
11719 GNAT_Pragma;
11721 -- If this is a configuration pragma, then set the universal
11722 -- addressing option, otherwise confirm that the pragma satisfies
11723 -- the requirements of library unit pragma placement and leave it
11724 -- to the GNAAMP back end to detect the pragma (avoids transitive
11725 -- setting of the option due to withed units).
11727 if Is_Configuration_Pragma then
11728 Universal_Addressing_On_AAMP := True;
11729 else
11730 Check_Valid_Library_Unit_Pragma;
11731 end if;
11733 if not AAMP_On_Target then
11734 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
11735 end if;
11737 ----------------
11738 -- Unmodified --
11739 ----------------
11741 -- pragma Unmodified (local_Name {, local_Name});
11743 when Pragma_Unmodified => Unmodified : declare
11744 Arg_Node : Node_Id;
11745 Arg_Expr : Node_Id;
11746 Arg_Ent : Entity_Id;
11748 begin
11749 GNAT_Pragma;
11750 Check_At_Least_N_Arguments (1);
11752 -- Loop through arguments
11754 Arg_Node := Arg1;
11755 while Present (Arg_Node) loop
11756 Check_No_Identifier (Arg_Node);
11758 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
11759 -- in fact generate reference, so that the entity will have a
11760 -- reference, which will inhibit any warnings about it not
11761 -- being referenced, and also properly show up in the ali file
11762 -- as a reference. But this reference is recorded before the
11763 -- Has_Pragma_Unreferenced flag is set, so that no warning is
11764 -- generated for this reference.
11766 Check_Arg_Is_Local_Name (Arg_Node);
11767 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11769 if Is_Entity_Name (Arg_Expr) then
11770 Arg_Ent := Entity (Arg_Expr);
11772 if not Is_Assignable (Arg_Ent) then
11773 Error_Pragma_Arg
11774 ("pragma% can only be applied to a variable",
11775 Arg_Expr);
11776 else
11777 Set_Has_Pragma_Unmodified (Arg_Ent);
11778 end if;
11779 end if;
11781 Next (Arg_Node);
11782 end loop;
11783 end Unmodified;
11785 ------------------
11786 -- Unreferenced --
11787 ------------------
11789 -- pragma Unreferenced (local_Name {, local_Name});
11791 -- or when used in a context clause:
11793 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
11795 when Pragma_Unreferenced => Unreferenced : declare
11796 Arg_Node : Node_Id;
11797 Arg_Expr : Node_Id;
11798 Arg_Ent : Entity_Id;
11799 Citem : Node_Id;
11801 begin
11802 GNAT_Pragma;
11803 Check_At_Least_N_Arguments (1);
11805 -- Check case of appearing within context clause
11807 if Is_In_Context_Clause then
11809 -- The arguments must all be units mentioned in a with clause
11810 -- in the same context clause. Note we already checked (in
11811 -- Par.Prag) that the arguments are either identifiers or
11812 -- selected components.
11814 Arg_Node := Arg1;
11815 while Present (Arg_Node) loop
11816 Citem := First (List_Containing (N));
11817 while Citem /= N loop
11818 if Nkind (Citem) = N_With_Clause
11819 and then Same_Name (Name (Citem), Expression (Arg_Node))
11820 then
11821 Set_Has_Pragma_Unreferenced
11822 (Cunit_Entity
11823 (Get_Source_Unit
11824 (Library_Unit (Citem))));
11825 Set_Unit_Name (Expression (Arg_Node), Name (Citem));
11826 exit;
11827 end if;
11829 Next (Citem);
11830 end loop;
11832 if Citem = N then
11833 Error_Pragma_Arg
11834 ("argument of pragma% is not with'ed unit", Arg_Node);
11835 end if;
11837 Next (Arg_Node);
11838 end loop;
11840 -- Case of not in list of context items
11842 else
11843 Arg_Node := Arg1;
11844 while Present (Arg_Node) loop
11845 Check_No_Identifier (Arg_Node);
11847 -- Note: the analyze call done by Check_Arg_Is_Local_Name
11848 -- will in fact generate reference, so that the entity will
11849 -- have a reference, which will inhibit any warnings about
11850 -- it not being referenced, and also properly show up in the
11851 -- ali file as a reference. But this reference is recorded
11852 -- before the Has_Pragma_Unreferenced flag is set, so that
11853 -- no warning is generated for this reference.
11855 Check_Arg_Is_Local_Name (Arg_Node);
11856 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11858 if Is_Entity_Name (Arg_Expr) then
11859 Arg_Ent := Entity (Arg_Expr);
11861 -- If the entity is overloaded, the pragma applies to the
11862 -- most recent overloading, as documented. In this case,
11863 -- name resolution does not generate a reference, so it
11864 -- must be done here explicitly.
11866 if Is_Overloaded (Arg_Expr) then
11867 Generate_Reference (Arg_Ent, N);
11868 end if;
11870 Set_Has_Pragma_Unreferenced (Arg_Ent);
11871 end if;
11873 Next (Arg_Node);
11874 end loop;
11875 end if;
11876 end Unreferenced;
11878 --------------------------
11879 -- Unreferenced_Objects --
11880 --------------------------
11882 -- pragma Unreferenced_Objects (local_Name {, local_Name});
11884 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
11885 Arg_Node : Node_Id;
11886 Arg_Expr : Node_Id;
11888 begin
11889 GNAT_Pragma;
11890 Check_At_Least_N_Arguments (1);
11892 Arg_Node := Arg1;
11893 while Present (Arg_Node) loop
11894 Check_No_Identifier (Arg_Node);
11895 Check_Arg_Is_Local_Name (Arg_Node);
11896 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11898 if not Is_Entity_Name (Arg_Expr)
11899 or else not Is_Type (Entity (Arg_Expr))
11900 then
11901 Error_Pragma_Arg
11902 ("argument for pragma% must be type or subtype", Arg_Node);
11903 end if;
11905 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
11906 Next (Arg_Node);
11907 end loop;
11908 end Unreferenced_Objects;
11910 ------------------------------
11911 -- Unreserve_All_Interrupts --
11912 ------------------------------
11914 -- pragma Unreserve_All_Interrupts;
11916 when Pragma_Unreserve_All_Interrupts =>
11917 GNAT_Pragma;
11918 Check_Arg_Count (0);
11920 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
11921 Unreserve_All_Interrupts := True;
11922 end if;
11924 ----------------
11925 -- Unsuppress --
11926 ----------------
11928 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
11930 when Pragma_Unsuppress =>
11931 Ada_2005_Pragma;
11932 Process_Suppress_Unsuppress (False);
11934 -------------------
11935 -- Use_VADS_Size --
11936 -------------------
11938 -- pragma Use_VADS_Size;
11940 when Pragma_Use_VADS_Size =>
11941 GNAT_Pragma;
11942 Check_Arg_Count (0);
11943 Check_Valid_Configuration_Pragma;
11944 Use_VADS_Size := True;
11946 ---------------------
11947 -- Validity_Checks --
11948 ---------------------
11950 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11952 when Pragma_Validity_Checks => Validity_Checks : declare
11953 A : constant Node_Id := Expression (Arg1);
11954 S : String_Id;
11955 C : Char_Code;
11957 begin
11958 GNAT_Pragma;
11959 Check_Arg_Count (1);
11960 Check_No_Identifiers;
11962 if Nkind (A) = N_String_Literal then
11963 S := Strval (A);
11965 declare
11966 Slen : constant Natural := Natural (String_Length (S));
11967 Options : String (1 .. Slen);
11968 J : Natural;
11970 begin
11971 J := 1;
11972 loop
11973 C := Get_String_Char (S, Int (J));
11974 exit when not In_Character_Range (C);
11975 Options (J) := Get_Character (C);
11977 if J = Slen then
11978 Set_Validity_Check_Options (Options);
11979 exit;
11980 else
11981 J := J + 1;
11982 end if;
11983 end loop;
11984 end;
11986 elsif Nkind (A) = N_Identifier then
11988 if Chars (A) = Name_All_Checks then
11989 Set_Validity_Check_Options ("a");
11991 elsif Chars (A) = Name_On then
11992 Validity_Checks_On := True;
11994 elsif Chars (A) = Name_Off then
11995 Validity_Checks_On := False;
11997 end if;
11998 end if;
11999 end Validity_Checks;
12001 --------------
12002 -- Volatile --
12003 --------------
12005 -- pragma Volatile (LOCAL_NAME);
12007 when Pragma_Volatile =>
12008 Process_Atomic_Shared_Volatile;
12010 -------------------------
12011 -- Volatile_Components --
12012 -------------------------
12014 -- pragma Volatile_Components (array_LOCAL_NAME);
12016 -- Volatile is handled by the same circuit as Atomic_Components
12018 --------------
12019 -- Warnings --
12020 --------------
12022 -- pragma Warnings (On | Off);
12023 -- pragma Warnings (On | Off, LOCAL_NAME);
12024 -- pragma Warnings (static_string_EXPRESSION);
12025 -- pragma Warnings (On | Off, STRING_LITERAL);
12027 when Pragma_Warnings => Warnings : begin
12028 GNAT_Pragma;
12029 Check_At_Least_N_Arguments (1);
12030 Check_No_Identifiers;
12032 -- If debug flag -gnatd.i is set, pragma is ignored
12034 if Debug_Flag_Dot_I then
12035 return;
12036 end if;
12038 -- Process various forms of the pragma
12040 declare
12041 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12043 begin
12044 -- One argument case
12046 if Arg_Count = 1 then
12048 -- On/Off one argument case was processed by parser
12050 if Nkind (Argx) = N_Identifier
12051 and then
12052 (Chars (Argx) = Name_On
12053 or else
12054 Chars (Argx) = Name_Off)
12055 then
12056 null;
12058 -- One argument case must be ON/OFF or static string expr
12060 elsif not Is_Static_String_Expression (Arg1) then
12061 Error_Pragma_Arg
12062 ("argument of pragma% must be On/Off or " &
12063 "static string expression", Arg2);
12065 -- One argument string expression case
12067 else
12068 declare
12069 Lit : constant Node_Id := Expr_Value_S (Argx);
12070 Str : constant String_Id := Strval (Lit);
12071 Len : constant Nat := String_Length (Str);
12072 C : Char_Code;
12073 J : Nat;
12074 OK : Boolean;
12075 Chr : Character;
12077 begin
12078 J := 1;
12079 while J <= Len loop
12080 C := Get_String_Char (Str, J);
12081 OK := In_Character_Range (C);
12083 if OK then
12084 Chr := Get_Character (C);
12086 -- Dot case
12088 if J < Len and then Chr = '.' then
12089 J := J + 1;
12090 C := Get_String_Char (Str, J);
12091 Chr := Get_Character (C);
12093 if not Set_Dot_Warning_Switch (Chr) then
12094 Error_Pragma_Arg
12095 ("invalid warning switch character " &
12096 '.' & Chr, Arg1);
12097 end if;
12099 -- Non-Dot case
12101 else
12102 OK := Set_Warning_Switch (Chr);
12103 end if;
12104 end if;
12106 if not OK then
12107 Error_Pragma_Arg
12108 ("invalid warning switch character " & Chr,
12109 Arg1);
12110 end if;
12112 J := J + 1;
12113 end loop;
12114 end;
12115 end if;
12117 -- Two or more arguments (must be two)
12119 else
12120 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12121 Check_At_Most_N_Arguments (2);
12123 declare
12124 E_Id : Node_Id;
12125 E : Entity_Id;
12126 Err : Boolean;
12128 begin
12129 E_Id := Expression (Arg2);
12130 Analyze (E_Id);
12132 -- In the expansion of an inlined body, a reference to
12133 -- the formal may be wrapped in a conversion if the
12134 -- actual is a conversion. Retrieve the real entity name.
12136 if (In_Instance_Body
12137 or else In_Inlined_Body)
12138 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
12139 then
12140 E_Id := Expression (E_Id);
12141 end if;
12143 -- Entity name case
12145 if Is_Entity_Name (E_Id) then
12146 E := Entity (E_Id);
12148 if E = Any_Id then
12149 return;
12150 else
12151 loop
12152 Set_Warnings_Off
12153 (E, (Chars (Expression (Arg1)) = Name_Off));
12155 if Chars (Expression (Arg1)) = Name_Off
12156 and then Warn_On_Warnings_Off
12157 then
12158 Warnings_Off_Pragmas.Append ((N, E));
12159 end if;
12161 if Is_Enumeration_Type (E) then
12162 declare
12163 Lit : Entity_Id;
12164 begin
12165 Lit := First_Literal (E);
12166 while Present (Lit) loop
12167 Set_Warnings_Off (Lit);
12168 Next_Literal (Lit);
12169 end loop;
12170 end;
12171 end if;
12173 exit when No (Homonym (E));
12174 E := Homonym (E);
12175 end loop;
12176 end if;
12178 -- Error if not entity or static string literal case
12180 elsif not Is_Static_String_Expression (Arg2) then
12181 Error_Pragma_Arg
12182 ("second argument of pragma% must be entity " &
12183 "name or static string expression", Arg2);
12185 -- String literal case
12187 else
12188 String_To_Name_Buffer
12189 (Strval (Expr_Value_S (Expression (Arg2))));
12191 -- Note on configuration pragma case: If this is a
12192 -- configuration pragma, then for an OFF pragma, we
12193 -- just set Config True in the call, which is all
12194 -- that needs to be done. For the case of ON, this
12195 -- is normally an error, unless it is canceling the
12196 -- effect of a previous OFF pragma in the same file.
12197 -- In any other case, an error will be signalled (ON
12198 -- with no matching OFF).
12200 if Chars (Argx) = Name_Off then
12201 Set_Specific_Warning_Off
12202 (Loc, Name_Buffer (1 .. Name_Len),
12203 Config => Is_Configuration_Pragma);
12205 elsif Chars (Argx) = Name_On then
12206 Set_Specific_Warning_On
12207 (Loc, Name_Buffer (1 .. Name_Len), Err);
12209 if Err then
12210 Error_Msg
12211 ("?pragma Warnings On with no " &
12212 "matching Warnings Off",
12213 Loc);
12214 end if;
12215 end if;
12216 end if;
12217 end;
12218 end if;
12219 end;
12220 end Warnings;
12222 -------------------
12223 -- Weak_External --
12224 -------------------
12226 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
12228 when Pragma_Weak_External => Weak_External : declare
12229 Ent : Entity_Id;
12231 begin
12232 GNAT_Pragma;
12233 Check_Arg_Count (1);
12234 Check_Optional_Identifier (Arg1, Name_Entity);
12235 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12236 Ent := Entity (Expression (Arg1));
12238 if Rep_Item_Too_Early (Ent, N) then
12239 return;
12240 else
12241 Ent := Underlying_Type (Ent);
12242 end if;
12244 -- The only processing required is to link this item on to the
12245 -- list of rep items for the given entity. This is accomplished
12246 -- by the call to Rep_Item_Too_Late (when no error is detected
12247 -- and False is returned).
12249 if Rep_Item_Too_Late (Ent, N) then
12250 return;
12251 else
12252 Set_Has_Gigi_Rep_Item (Ent);
12253 end if;
12254 end Weak_External;
12256 -----------------------------
12257 -- Wide_Character_Encoding --
12258 -----------------------------
12260 -- pragma Wide_Character_Encoding (IDENTIFIER);
12262 when Pragma_Wide_Character_Encoding =>
12263 GNAT_Pragma;
12265 -- Nothing to do, handled in parser. Note that we do not enforce
12266 -- configuration pragma placement, this pragma can appear at any
12267 -- place in the source, allowing mixed encodings within a single
12268 -- source program.
12270 null;
12272 --------------------
12273 -- Unknown_Pragma --
12274 --------------------
12276 -- Should be impossible, since the case of an unknown pragma is
12277 -- separately processed before the case statement is entered.
12279 when Unknown_Pragma =>
12280 raise Program_Error;
12281 end case;
12283 exception
12284 when Pragma_Exit => null;
12285 end Analyze_Pragma;
12287 -------------------
12288 -- Check_Enabled --
12289 -------------------
12291 function Check_Enabled (Nam : Name_Id) return Boolean is
12292 PP : Node_Id;
12294 begin
12295 PP := Opt.Check_Policy_List;
12296 loop
12297 if No (PP) then
12298 return Assertions_Enabled;
12300 elsif
12301 Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
12302 then
12303 case
12304 Chars (Expression (Last (Pragma_Argument_Associations (PP))))
12306 when Name_On | Name_Check =>
12307 return True;
12308 when Name_Off | Name_Ignore =>
12309 return False;
12310 when others =>
12311 raise Program_Error;
12312 end case;
12314 else
12315 PP := Next_Pragma (PP);
12316 end if;
12317 end loop;
12318 end Check_Enabled;
12320 ---------------------------------
12321 -- Delay_Config_Pragma_Analyze --
12322 ---------------------------------
12324 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
12325 begin
12326 return Pragma_Name (N) = Name_Interrupt_State
12327 or else
12328 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
12329 end Delay_Config_Pragma_Analyze;
12331 -------------------------
12332 -- Get_Base_Subprogram --
12333 -------------------------
12335 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
12336 Result : Entity_Id;
12338 begin
12339 -- Follow subprogram renaming chain
12341 Result := Def_Id;
12342 while Is_Subprogram (Result)
12343 and then
12344 (Is_Generic_Instance (Result)
12345 or else Nkind (Parent (Declaration_Node (Result))) =
12346 N_Subprogram_Renaming_Declaration)
12347 and then Present (Alias (Result))
12348 loop
12349 Result := Alias (Result);
12350 end loop;
12352 return Result;
12353 end Get_Base_Subprogram;
12355 --------------------
12356 -- Get_Pragma_Arg --
12357 --------------------
12359 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
12360 begin
12361 if Nkind (Arg) = N_Pragma_Argument_Association then
12362 return Expression (Arg);
12363 else
12364 return Arg;
12365 end if;
12366 end Get_Pragma_Arg;
12368 ----------------
12369 -- Initialize --
12370 ----------------
12372 procedure Initialize is
12373 begin
12374 Externals.Init;
12375 end Initialize;
12377 -----------------------------
12378 -- Is_Config_Static_String --
12379 -----------------------------
12381 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
12383 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
12384 -- This is an internal recursive function that is just like the outer
12385 -- function except that it adds the string to the name buffer rather
12386 -- than placing the string in the name buffer.
12388 ------------------------------
12389 -- Add_Config_Static_String --
12390 ------------------------------
12392 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
12393 N : Node_Id;
12394 C : Char_Code;
12396 begin
12397 N := Arg;
12399 if Nkind (N) = N_Op_Concat then
12400 if Add_Config_Static_String (Left_Opnd (N)) then
12401 N := Right_Opnd (N);
12402 else
12403 return False;
12404 end if;
12405 end if;
12407 if Nkind (N) /= N_String_Literal then
12408 Error_Msg_N ("string literal expected for pragma argument", N);
12409 return False;
12411 else
12412 for J in 1 .. String_Length (Strval (N)) loop
12413 C := Get_String_Char (Strval (N), J);
12415 if not In_Character_Range (C) then
12416 Error_Msg
12417 ("string literal contains invalid wide character",
12418 Sloc (N) + 1 + Source_Ptr (J));
12419 return False;
12420 end if;
12422 Add_Char_To_Name_Buffer (Get_Character (C));
12423 end loop;
12424 end if;
12426 return True;
12427 end Add_Config_Static_String;
12429 -- Start of processing for Is_Config_Static_String
12431 begin
12433 Name_Len := 0;
12434 return Add_Config_Static_String (Arg);
12435 end Is_Config_Static_String;
12437 -----------------------------------------
12438 -- Is_Non_Significant_Pragma_Reference --
12439 -----------------------------------------
12441 -- This function makes use of the following static table which indicates
12442 -- whether a given pragma is significant. A value of -1 in this table
12443 -- indicates that the reference is significant. A value of zero indicates
12444 -- than appearance as any argument is insignificant, a positive value
12445 -- indicates that appearance in that parameter position is significant.
12447 -- A value of 99 flags a special case requiring a special check (this is
12448 -- used for cases not covered by this standard encoding, e.g. pragma Check
12449 -- where the first argument is not significant, but the others are).
12451 Sig_Flags : constant array (Pragma_Id) of Int :=
12452 (Pragma_AST_Entry => -1,
12453 Pragma_Abort_Defer => -1,
12454 Pragma_Ada_83 => -1,
12455 Pragma_Ada_95 => -1,
12456 Pragma_Ada_05 => -1,
12457 Pragma_Ada_2005 => -1,
12458 Pragma_All_Calls_Remote => -1,
12459 Pragma_Annotate => -1,
12460 Pragma_Assert => -1,
12461 Pragma_Assertion_Policy => 0,
12462 Pragma_Assume_No_Invalid_Values => 0,
12463 Pragma_Asynchronous => -1,
12464 Pragma_Atomic => 0,
12465 Pragma_Atomic_Components => 0,
12466 Pragma_Attach_Handler => -1,
12467 Pragma_Check => 99,
12468 Pragma_Check_Name => 0,
12469 Pragma_Check_Policy => 0,
12470 Pragma_CIL_Constructor => -1,
12471 Pragma_CPP_Class => 0,
12472 Pragma_CPP_Constructor => 0,
12473 Pragma_CPP_Virtual => 0,
12474 Pragma_CPP_Vtable => 0,
12475 Pragma_C_Pass_By_Copy => 0,
12476 Pragma_Comment => 0,
12477 Pragma_Common_Object => -1,
12478 Pragma_Compile_Time_Error => -1,
12479 Pragma_Compile_Time_Warning => -1,
12480 Pragma_Compiler_Unit => 0,
12481 Pragma_Complete_Representation => 0,
12482 Pragma_Complex_Representation => 0,
12483 Pragma_Component_Alignment => -1,
12484 Pragma_Controlled => 0,
12485 Pragma_Convention => 0,
12486 Pragma_Convention_Identifier => 0,
12487 Pragma_Debug => -1,
12488 Pragma_Debug_Policy => 0,
12489 Pragma_Detect_Blocking => -1,
12490 Pragma_Discard_Names => 0,
12491 Pragma_Elaborate => -1,
12492 Pragma_Elaborate_All => -1,
12493 Pragma_Elaborate_Body => -1,
12494 Pragma_Elaboration_Checks => -1,
12495 Pragma_Eliminate => -1,
12496 Pragma_Export => -1,
12497 Pragma_Export_Exception => -1,
12498 Pragma_Export_Function => -1,
12499 Pragma_Export_Object => -1,
12500 Pragma_Export_Procedure => -1,
12501 Pragma_Export_Value => -1,
12502 Pragma_Export_Valued_Procedure => -1,
12503 Pragma_Extend_System => -1,
12504 Pragma_Extensions_Allowed => -1,
12505 Pragma_External => -1,
12506 Pragma_Favor_Top_Level => -1,
12507 Pragma_External_Name_Casing => -1,
12508 Pragma_Fast_Math => -1,
12509 Pragma_Finalize_Storage_Only => 0,
12510 Pragma_Float_Representation => 0,
12511 Pragma_Ident => -1,
12512 Pragma_Implemented_By_Entry => -1,
12513 Pragma_Implicit_Packing => 0,
12514 Pragma_Import => +2,
12515 Pragma_Import_Exception => 0,
12516 Pragma_Import_Function => 0,
12517 Pragma_Import_Object => 0,
12518 Pragma_Import_Procedure => 0,
12519 Pragma_Import_Valued_Procedure => 0,
12520 Pragma_Initialize_Scalars => -1,
12521 Pragma_Inline => 0,
12522 Pragma_Inline_Always => 0,
12523 Pragma_Inline_Generic => 0,
12524 Pragma_Inspection_Point => -1,
12525 Pragma_Interface => +2,
12526 Pragma_Interface_Name => +2,
12527 Pragma_Interrupt_Handler => -1,
12528 Pragma_Interrupt_Priority => -1,
12529 Pragma_Interrupt_State => -1,
12530 Pragma_Java_Constructor => -1,
12531 Pragma_Java_Interface => -1,
12532 Pragma_Keep_Names => 0,
12533 Pragma_License => -1,
12534 Pragma_Link_With => -1,
12535 Pragma_Linker_Alias => -1,
12536 Pragma_Linker_Constructor => -1,
12537 Pragma_Linker_Destructor => -1,
12538 Pragma_Linker_Options => -1,
12539 Pragma_Linker_Section => -1,
12540 Pragma_List => -1,
12541 Pragma_Locking_Policy => -1,
12542 Pragma_Long_Float => -1,
12543 Pragma_Machine_Attribute => -1,
12544 Pragma_Main => -1,
12545 Pragma_Main_Storage => -1,
12546 Pragma_Memory_Size => -1,
12547 Pragma_No_Return => 0,
12548 Pragma_No_Body => 0,
12549 Pragma_No_Run_Time => -1,
12550 Pragma_No_Strict_Aliasing => -1,
12551 Pragma_Normalize_Scalars => -1,
12552 Pragma_Obsolescent => 0,
12553 Pragma_Optimize => -1,
12554 Pragma_Optimize_Alignment => -1,
12555 Pragma_Pack => 0,
12556 Pragma_Page => -1,
12557 Pragma_Passive => -1,
12558 Pragma_Preelaborable_Initialization => -1,
12559 Pragma_Polling => -1,
12560 Pragma_Persistent_BSS => 0,
12561 Pragma_Postcondition => -1,
12562 Pragma_Precondition => -1,
12563 Pragma_Preelaborate => -1,
12564 Pragma_Preelaborate_05 => -1,
12565 Pragma_Priority => -1,
12566 Pragma_Priority_Specific_Dispatching => -1,
12567 Pragma_Profile => 0,
12568 Pragma_Profile_Warnings => 0,
12569 Pragma_Propagate_Exceptions => -1,
12570 Pragma_Psect_Object => -1,
12571 Pragma_Pure => -1,
12572 Pragma_Pure_05 => -1,
12573 Pragma_Pure_Function => -1,
12574 Pragma_Queuing_Policy => -1,
12575 Pragma_Ravenscar => -1,
12576 Pragma_Relative_Deadline => -1,
12577 Pragma_Remote_Call_Interface => -1,
12578 Pragma_Remote_Types => -1,
12579 Pragma_Restricted_Run_Time => -1,
12580 Pragma_Restriction_Warnings => -1,
12581 Pragma_Restrictions => -1,
12582 Pragma_Reviewable => -1,
12583 Pragma_Short_Circuit_And_Or => -1,
12584 Pragma_Share_Generic => -1,
12585 Pragma_Shared => -1,
12586 Pragma_Shared_Passive => -1,
12587 Pragma_Source_File_Name => -1,
12588 Pragma_Source_File_Name_Project => -1,
12589 Pragma_Source_Reference => -1,
12590 Pragma_Storage_Size => -1,
12591 Pragma_Storage_Unit => -1,
12592 Pragma_Static_Elaboration_Desired => -1,
12593 Pragma_Stream_Convert => -1,
12594 Pragma_Style_Checks => -1,
12595 Pragma_Subtitle => -1,
12596 Pragma_Suppress => 0,
12597 Pragma_Suppress_Exception_Locations => 0,
12598 Pragma_Suppress_All => -1,
12599 Pragma_Suppress_Debug_Info => 0,
12600 Pragma_Suppress_Initialization => 0,
12601 Pragma_System_Name => -1,
12602 Pragma_Task_Dispatching_Policy => -1,
12603 Pragma_Task_Info => -1,
12604 Pragma_Task_Name => -1,
12605 Pragma_Task_Storage => 0,
12606 Pragma_Thread_Local_Storage => 0,
12607 Pragma_Time_Slice => -1,
12608 Pragma_Title => -1,
12609 Pragma_Unchecked_Union => 0,
12610 Pragma_Unimplemented_Unit => -1,
12611 Pragma_Universal_Aliasing => -1,
12612 Pragma_Universal_Data => -1,
12613 Pragma_Unmodified => -1,
12614 Pragma_Unreferenced => -1,
12615 Pragma_Unreferenced_Objects => -1,
12616 Pragma_Unreserve_All_Interrupts => -1,
12617 Pragma_Unsuppress => 0,
12618 Pragma_Use_VADS_Size => -1,
12619 Pragma_Validity_Checks => -1,
12620 Pragma_Volatile => 0,
12621 Pragma_Volatile_Components => 0,
12622 Pragma_Warnings => -1,
12623 Pragma_Weak_External => -1,
12624 Pragma_Wide_Character_Encoding => 0,
12625 Unknown_Pragma => 0);
12627 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
12628 Id : Pragma_Id;
12629 P : Node_Id;
12630 C : Int;
12631 A : Node_Id;
12633 begin
12634 P := Parent (N);
12636 if Nkind (P) /= N_Pragma_Argument_Association then
12637 return False;
12639 else
12640 Id := Get_Pragma_Id (Parent (P));
12641 C := Sig_Flags (Id);
12643 case C is
12644 when -1 =>
12645 return False;
12647 when 0 =>
12648 return True;
12650 when 99 =>
12651 case Id is
12653 -- For pragma Check, the first argument is not significant,
12654 -- the second and the third (if present) arguments are
12655 -- significant.
12657 when Pragma_Check =>
12658 return
12659 P = First (Pragma_Argument_Associations (Parent (P)));
12661 when others =>
12662 raise Program_Error;
12663 end case;
12665 when others =>
12666 A := First (Pragma_Argument_Associations (Parent (P)));
12667 for J in 1 .. C - 1 loop
12668 if No (A) then
12669 return False;
12670 end if;
12672 Next (A);
12673 end loop;
12675 return A = P; -- is this wrong way round ???
12676 end case;
12677 end if;
12678 end Is_Non_Significant_Pragma_Reference;
12680 ------------------------------
12681 -- Is_Pragma_String_Literal --
12682 ------------------------------
12684 -- This function returns true if the corresponding pragma argument is a
12685 -- static string expression. These are the only cases in which string
12686 -- literals can appear as pragma arguments. We also allow a string literal
12687 -- as the first argument to pragma Assert (although it will of course
12688 -- always generate a type error).
12690 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
12691 Pragn : constant Node_Id := Parent (Par);
12692 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
12693 Pname : constant Name_Id := Pragma_Name (Pragn);
12694 Argn : Natural;
12695 N : Node_Id;
12697 begin
12698 Argn := 1;
12699 N := First (Assoc);
12700 loop
12701 exit when N = Par;
12702 Argn := Argn + 1;
12703 Next (N);
12704 end loop;
12706 if Pname = Name_Assert then
12707 return True;
12709 elsif Pname = Name_Export then
12710 return Argn > 2;
12712 elsif Pname = Name_Ident then
12713 return Argn = 1;
12715 elsif Pname = Name_Import then
12716 return Argn > 2;
12718 elsif Pname = Name_Interface_Name then
12719 return Argn > 1;
12721 elsif Pname = Name_Linker_Alias then
12722 return Argn = 2;
12724 elsif Pname = Name_Linker_Section then
12725 return Argn = 2;
12727 elsif Pname = Name_Machine_Attribute then
12728 return Argn = 2;
12730 elsif Pname = Name_Source_File_Name then
12731 return True;
12733 elsif Pname = Name_Source_Reference then
12734 return Argn = 2;
12736 elsif Pname = Name_Title then
12737 return True;
12739 elsif Pname = Name_Subtitle then
12740 return True;
12742 else
12743 return False;
12744 end if;
12745 end Is_Pragma_String_Literal;
12747 --------------------------------------
12748 -- Process_Compilation_Unit_Pragmas --
12749 --------------------------------------
12751 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
12752 begin
12753 -- A special check for pragma Suppress_All, a very strange DEC pragma,
12754 -- strange because it comes at the end of the unit. If we have a pragma
12755 -- Suppress_All in the Pragmas_After of the current unit, then we insert
12756 -- a pragma Suppress (All_Checks) at the start of the context clause to
12757 -- ensure the correct processing.
12759 declare
12760 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
12761 P : Node_Id;
12763 begin
12764 if Present (PA) then
12765 P := First (PA);
12766 while Present (P) loop
12767 if Pragma_Name (P) = Name_Suppress_All then
12768 Prepend_To (Context_Items (N),
12769 Make_Pragma (Sloc (P),
12770 Chars => Name_Suppress,
12771 Pragma_Argument_Associations => New_List (
12772 Make_Pragma_Argument_Association (Sloc (P),
12773 Expression =>
12774 Make_Identifier (Sloc (P),
12775 Chars => Name_All_Checks)))));
12776 exit;
12777 end if;
12779 Next (P);
12780 end loop;
12781 end if;
12782 end;
12783 end Process_Compilation_Unit_Pragmas;
12785 --------
12786 -- rv --
12787 --------
12789 procedure rv is
12790 begin
12791 null;
12792 end rv;
12794 --------------------------------
12795 -- Set_Encoded_Interface_Name --
12796 --------------------------------
12798 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
12799 Str : constant String_Id := Strval (S);
12800 Len : constant Int := String_Length (Str);
12801 CC : Char_Code;
12802 C : Character;
12803 J : Int;
12805 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
12807 procedure Encode;
12808 -- Stores encoded value of character code CC. The encoding we use an
12809 -- underscore followed by four lower case hex digits.
12811 ------------
12812 -- Encode --
12813 ------------
12815 procedure Encode is
12816 begin
12817 Store_String_Char (Get_Char_Code ('_'));
12818 Store_String_Char
12819 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
12820 Store_String_Char
12821 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
12822 Store_String_Char
12823 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
12824 Store_String_Char
12825 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
12826 end Encode;
12828 -- Start of processing for Set_Encoded_Interface_Name
12830 begin
12831 -- If first character is asterisk, this is a link name, and we leave it
12832 -- completely unmodified. We also ignore null strings (the latter case
12833 -- happens only in error cases) and no encoding should occur for Java or
12834 -- AAMP interface names.
12836 if Len = 0
12837 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
12838 or else VM_Target /= No_VM
12839 or else AAMP_On_Target
12840 then
12841 Set_Interface_Name (E, S);
12843 else
12844 J := 1;
12845 loop
12846 CC := Get_String_Char (Str, J);
12848 exit when not In_Character_Range (CC);
12850 C := Get_Character (CC);
12852 exit when C /= '_' and then C /= '$'
12853 and then C not in '0' .. '9'
12854 and then C not in 'a' .. 'z'
12855 and then C not in 'A' .. 'Z';
12857 if J = Len then
12858 Set_Interface_Name (E, S);
12859 return;
12861 else
12862 J := J + 1;
12863 end if;
12864 end loop;
12866 -- Here we need to encode. The encoding we use as follows:
12867 -- three underscores + four hex digits (lower case)
12869 Start_String;
12871 for J in 1 .. String_Length (Str) loop
12872 CC := Get_String_Char (Str, J);
12874 if not In_Character_Range (CC) then
12875 Encode;
12876 else
12877 C := Get_Character (CC);
12879 if C = '_' or else C = '$'
12880 or else C in '0' .. '9'
12881 or else C in 'a' .. 'z'
12882 or else C in 'A' .. 'Z'
12883 then
12884 Store_String_Char (CC);
12885 else
12886 Encode;
12887 end if;
12888 end if;
12889 end loop;
12891 Set_Interface_Name (E,
12892 Make_String_Literal (Sloc (S),
12893 Strval => End_String));
12894 end if;
12895 end Set_Encoded_Interface_Name;
12897 -------------------
12898 -- Set_Unit_Name --
12899 -------------------
12901 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
12902 Pref : Node_Id;
12903 Scop : Entity_Id;
12905 begin
12906 if Nkind (N) = N_Identifier
12907 and then Nkind (With_Item) = N_Identifier
12908 then
12909 Set_Entity (N, Entity (With_Item));
12911 elsif Nkind (N) = N_Selected_Component then
12912 Change_Selected_Component_To_Expanded_Name (N);
12913 Set_Entity (N, Entity (With_Item));
12914 Set_Entity (Selector_Name (N), Entity (N));
12916 Pref := Prefix (N);
12917 Scop := Scope (Entity (N));
12918 while Nkind (Pref) = N_Selected_Component loop
12919 Change_Selected_Component_To_Expanded_Name (Pref);
12920 Set_Entity (Selector_Name (Pref), Scop);
12921 Set_Entity (Pref, Scop);
12922 Pref := Prefix (Pref);
12923 Scop := Scope (Scop);
12924 end loop;
12926 Set_Entity (Pref, Scop);
12927 end if;
12928 end Set_Unit_Name;
12930 end Sem_Prag;