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