Merge from mainline (163495:164578).
[official-gcc/graphite-test-results.git] / gcc / ada / sem_prag.adb
blobfa8cff8afa8d61cc4a324ec24c962b6db8ab03f5
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_Dist; use Exp_Dist;
41 with Lib; use Lib;
42 with Lib.Writ; use Lib.Writ;
43 with Lib.Xref; use Lib.Xref;
44 with Namet.Sp; use Namet.Sp;
45 with Nlists; use Nlists;
46 with Nmake; use Nmake;
47 with Opt; use Opt;
48 with Output; use Output;
49 with Par_SCO; use Par_SCO;
50 with Restrict; use Restrict;
51 with Rident; use Rident;
52 with Rtsfind; use Rtsfind;
53 with Sem; use Sem;
54 with Sem_Aux; use Sem_Aux;
55 with Sem_Ch3; use Sem_Ch3;
56 with Sem_Ch6; use Sem_Ch6;
57 with Sem_Ch8; use Sem_Ch8;
58 with Sem_Ch12; use Sem_Ch12;
59 with Sem_Ch13; use Sem_Ch13;
60 with Sem_Dist; use Sem_Dist;
61 with Sem_Elim; use Sem_Elim;
62 with Sem_Eval; use Sem_Eval;
63 with Sem_Intr; use Sem_Intr;
64 with Sem_Mech; use Sem_Mech;
65 with Sem_Res; use Sem_Res;
66 with Sem_Type; use Sem_Type;
67 with Sem_Util; use Sem_Util;
68 with Sem_VFpt; use Sem_VFpt;
69 with Sem_Warn; use Sem_Warn;
70 with Stand; use Stand;
71 with Sinfo; use Sinfo;
72 with Sinfo.CN; use Sinfo.CN;
73 with Sinput; use Sinput;
74 with Snames; use Snames;
75 with Stringt; use Stringt;
76 with Stylesw; use Stylesw;
77 with Table;
78 with Targparm; use Targparm;
79 with Tbuild; use Tbuild;
80 with Ttypes;
81 with Uintp; use Uintp;
82 with Uname; use Uname;
83 with Urealp; use Urealp;
84 with Validsw; use Validsw;
86 package body Sem_Prag is
88 ----------------------------------------------
89 -- Common Handling of Import-Export Pragmas --
90 ----------------------------------------------
92 -- In the following section, a number of Import_xxx and Export_xxx
93 -- pragmas are defined by GNAT. These are compatible with the DEC
94 -- pragmas of the same name, and all have the following common
95 -- form and processing:
97 -- pragma Export_xxx
98 -- [Internal =>] LOCAL_NAME
99 -- [, [External =>] EXTERNAL_SYMBOL]
100 -- [, other optional parameters ]);
102 -- pragma Import_xxx
103 -- [Internal =>] LOCAL_NAME
104 -- [, [External =>] EXTERNAL_SYMBOL]
105 -- [, other optional parameters ]);
107 -- EXTERNAL_SYMBOL ::=
108 -- IDENTIFIER
109 -- | static_string_EXPRESSION
111 -- The internal LOCAL_NAME designates the entity that is imported or
112 -- exported, and must refer to an entity in the current declarative
113 -- part (as required by the rules for LOCAL_NAME).
115 -- The external linker name is designated by the External parameter if
116 -- given, or the Internal parameter if not (if there is no External
117 -- parameter, the External parameter is a copy of the Internal name).
119 -- If the External parameter is given as a string, then this string is
120 -- treated as an external name (exactly as though it had been given as an
121 -- External_Name parameter for a normal Import pragma).
123 -- If the External parameter is given as an identifier (or there is no
124 -- External parameter, so that the Internal identifier is used), then
125 -- the external name is the characters of the identifier, translated
126 -- to all upper case letters for OpenVMS versions of GNAT, and to all
127 -- lower case letters for all other versions
129 -- Note: the external name specified or implied by any of these special
130 -- Import_xxx or Export_xxx pragmas override an external or link name
131 -- specified in a previous Import or Export pragma.
133 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
134 -- named notation, following the standard rules for subprogram calls, i.e.
135 -- parameters can be given in any order if named notation is used, and
136 -- positional and named notation can be mixed, subject to the rule that all
137 -- positional parameters must appear first.
139 -- Note: All these pragmas are implemented exactly following the DEC design
140 -- and implementation and are intended to be fully compatible with the use
141 -- of these pragmas in the DEC Ada compiler.
143 --------------------------------------------
144 -- Checking for Duplicated External Names --
145 --------------------------------------------
147 -- It is suspicious if two separate Export pragmas use the same external
148 -- name. The following table is used to diagnose this situation so that
149 -- an appropriate warning can be issued.
151 -- The Node_Id stored is for the N_String_Literal node created to hold
152 -- the value of the external name. The Sloc of this node is used to
153 -- cross-reference the location of the duplication.
155 package Externals is new Table.Table (
156 Table_Component_Type => Node_Id,
157 Table_Index_Type => Int,
158 Table_Low_Bound => 0,
159 Table_Initial => 100,
160 Table_Increment => 100,
161 Table_Name => "Name_Externals");
163 -------------------------------------
164 -- Local Subprograms and Variables --
165 -------------------------------------
167 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
168 -- This routine is used for possible casing adjustment of an explicit
169 -- external name supplied as a string literal (the node N), according to
170 -- the casing requirement of Opt.External_Name_Casing. If this is set to
171 -- As_Is, then the string literal is returned unchanged, but if it is set
172 -- to Uppercase or Lowercase, then a new string literal with appropriate
173 -- casing is constructed.
175 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
176 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
177 -- original one, following the renaming chain) is returned. Otherwise the
178 -- entity is returned unchanged. Should be in Einfo???
180 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
181 -- All the routines that check pragma arguments take either a pragma
182 -- argument association (in which case the expression of the argument
183 -- association is checked), or the expression directly. The function
184 -- Get_Pragma_Arg is a utility used to deal with these two cases. If Arg
185 -- is a pragma argument association node, then its expression is returned,
186 -- otherwise Arg is returned unchanged.
188 procedure rv;
189 -- This is a dummy function called by the processing for pragma Reviewable.
190 -- It is there for assisting front end debugging. By placing a Reviewable
191 -- pragma in the source program, a breakpoint on rv catches this place in
192 -- the source, allowing convenient stepping to the point of interest.
194 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
195 -- Place semantic information on the argument of an Elaborate/Elaborate_All
196 -- pragma. Entity name for unit and its parents is taken from item in
197 -- previous with_clause that mentions the unit.
199 -------------------------------
200 -- Adjust_External_Name_Case --
201 -------------------------------
203 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
204 CC : Char_Code;
206 begin
207 -- Adjust case of literal if required
209 if Opt.External_Name_Exp_Casing = As_Is then
210 return N;
212 else
213 -- Copy existing string
215 Start_String;
217 -- Set proper casing
219 for J in 1 .. String_Length (Strval (N)) loop
220 CC := Get_String_Char (Strval (N), J);
222 if Opt.External_Name_Exp_Casing = Uppercase
223 and then CC >= Get_Char_Code ('a')
224 and then CC <= Get_Char_Code ('z')
225 then
226 Store_String_Char (CC - 32);
228 elsif Opt.External_Name_Exp_Casing = Lowercase
229 and then CC >= Get_Char_Code ('A')
230 and then CC <= Get_Char_Code ('Z')
231 then
232 Store_String_Char (CC + 32);
234 else
235 Store_String_Char (CC);
236 end if;
237 end loop;
239 return
240 Make_String_Literal (Sloc (N),
241 Strval => End_String);
242 end if;
243 end Adjust_External_Name_Case;
245 ------------------------------
246 -- Analyze_PPC_In_Decl_Part --
247 ------------------------------
249 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
250 Arg1 : constant Node_Id :=
251 First (Pragma_Argument_Associations (N));
252 Arg2 : constant Node_Id := Next (Arg1);
254 begin
255 -- Install formals and push subprogram spec onto scope stack so that we
256 -- can see the formals from the pragma.
258 Install_Formals (S);
259 Push_Scope (S);
261 -- Preanalyze the boolean expression, we treat this as a spec expression
262 -- (i.e. similar to a default expression).
264 Preanalyze_Spec_Expression
265 (Get_Pragma_Arg (Arg1), Standard_Boolean);
267 -- If there is a message argument, analyze it the same way
269 if Present (Arg2) then
270 Preanalyze_Spec_Expression
271 (Get_Pragma_Arg (Arg2), Standard_String);
272 end if;
274 -- Remove the subprogram from the scope stack now that the pre-analysis
275 -- of the precondition/postcondition is done.
277 End_Scope;
278 end Analyze_PPC_In_Decl_Part;
280 --------------------
281 -- Analyze_Pragma --
282 --------------------
284 procedure Analyze_Pragma (N : Node_Id) is
285 Loc : constant Source_Ptr := Sloc (N);
286 Pname : constant Name_Id := Pragma_Name (N);
287 Prag_Id : Pragma_Id;
289 Pragma_Exit : exception;
290 -- This exception is used to exit pragma processing completely. It is
291 -- used when an error is detected, and no further processing is
292 -- required. It is also used if an earlier error has left the tree in
293 -- a state where the pragma should not be processed.
295 Arg_Count : Nat;
296 -- Number of pragma argument associations
298 Arg1 : Node_Id;
299 Arg2 : Node_Id;
300 Arg3 : Node_Id;
301 Arg4 : Node_Id;
302 -- First four pragma arguments (pragma argument association nodes, or
303 -- Empty if the corresponding argument does not exist).
305 type Name_List is array (Natural range <>) of Name_Id;
306 type Args_List is array (Natural range <>) of Node_Id;
307 -- Types used for arguments to Check_Arg_Order and Gather_Associations
309 procedure Ada_2005_Pragma;
310 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
311 -- Ada 95 mode, these are implementation defined pragmas, so should be
312 -- caught by the No_Implementation_Pragmas restriction
314 procedure Check_Ada_83_Warning;
315 -- Issues a warning message for the current pragma if operating in Ada
316 -- 83 mode (used for language pragmas that are not a standard part of
317 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
318 -- of 95 pragma.
320 procedure Check_Arg_Count (Required : Nat);
321 -- Check argument count for pragma is equal to given parameter. If not,
322 -- then issue an error message and raise Pragma_Exit.
324 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
325 -- Arg which can either be a pragma argument association, in which case
326 -- the check is applied to the expression of the association or an
327 -- expression directly.
329 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
330 -- Check that an argument has the right form for an EXTERNAL_NAME
331 -- parameter of an extended import/export pragma. The rule is that the
332 -- name must be an identifier or string literal (in Ada 83 mode) or a
333 -- static string expression (in Ada 95 mode).
335 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
336 -- Check the specified argument Arg to make sure that it is an
337 -- identifier. If not give error and raise Pragma_Exit.
339 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
340 -- Check the specified argument Arg to make sure that it is an integer
341 -- literal. If not give error and raise Pragma_Exit.
343 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
344 -- Check the specified argument Arg to make sure that it has the proper
345 -- syntactic form for a local name and meets the semantic requirements
346 -- for a local name. The local name is analyzed as part of the
347 -- processing for this call. In addition, the local name is required
348 -- to represent an entity at the library level.
350 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
351 -- Check the specified argument Arg to make sure that it has the proper
352 -- syntactic form for a local name and meets the semantic requirements
353 -- for a local name. The local name is analyzed as part of the
354 -- processing for this call.
356 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
357 -- Check the specified argument Arg to make sure that it is a valid
358 -- locking policy name. If not give error and raise Pragma_Exit.
360 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
361 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
362 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
363 -- Check the specified argument Arg to make sure that it is an
364 -- identifier whose name matches either N1 or N2 (or N3 if present).
365 -- If not then give error and raise Pragma_Exit.
367 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
368 -- Check the specified argument Arg to make sure that it is a valid
369 -- queuing policy name. If not give error and raise Pragma_Exit.
371 procedure Check_Arg_Is_Static_Expression
372 (Arg : Node_Id;
373 Typ : Entity_Id := Empty);
374 -- Check the specified argument Arg to make sure that it is a static
375 -- expression of the given type (i.e. it will be analyzed and resolved
376 -- using this type, which can be any valid argument to Resolve, e.g.
377 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
378 -- Typ is left Empty, then any static expression is allowed.
380 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
381 -- Check the specified argument Arg to make sure that it is a valid task
382 -- dispatching policy name. If not give error and raise Pragma_Exit.
384 procedure Check_Arg_Order (Names : Name_List);
385 -- Checks for an instance of two arguments with identifiers for the
386 -- current pragma which are not in the sequence indicated by Names,
387 -- and if so, generates a fatal message about bad order of arguments.
389 procedure Check_At_Least_N_Arguments (N : Nat);
390 -- Check there are at least N arguments present
392 procedure Check_At_Most_N_Arguments (N : Nat);
393 -- Check there are no more than N arguments present
395 procedure Check_Component (Comp : Node_Id);
396 -- Examine Unchecked_Union component for correct use of per-object
397 -- constrained subtypes, and for restrictions on finalizable components.
399 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
400 -- Nam is an N_String_Literal node containing the external name set by
401 -- an Import or Export pragma (or extended Import or Export pragma).
402 -- This procedure checks for possible duplications if this is the export
403 -- case, and if found, issues an appropriate error message.
405 procedure Check_First_Subtype (Arg : Node_Id);
406 -- Checks that Arg, whose expression is an entity name referencing a
407 -- subtype, does not reference a type that is not a first subtype.
409 procedure Check_In_Main_Program;
410 -- Common checks for pragmas that appear within a main program
411 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline).
413 procedure Check_Interrupt_Or_Attach_Handler;
414 -- Common processing for first argument of pragma Interrupt_Handler or
415 -- pragma Attach_Handler.
417 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
418 -- Check that pragma appears in a declarative part, or in a package
419 -- specification, i.e. that it does not occur in a statement sequence
420 -- in a body.
422 procedure Check_No_Identifier (Arg : Node_Id);
423 -- Checks that the given argument does not have an identifier. If
424 -- an identifier is present, then an error message is issued, and
425 -- Pragma_Exit is raised.
427 procedure Check_No_Identifiers;
428 -- Checks that none of the arguments to the pragma has an identifier.
429 -- If any argument has an identifier, then an error message is issued,
430 -- and Pragma_Exit is raised.
432 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
433 -- Checks if the given argument has an identifier, and if so, requires
434 -- it to match the given identifier name. If there is a non-matching
435 -- identifier, then an error message is given and Error_Pragmas raised.
437 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
438 -- Checks if the given argument has an identifier, and if so, requires
439 -- it to match the given identifier name. If there is a non-matching
440 -- identifier, then an error message is given and Error_Pragmas raised.
441 -- In this version of the procedure, the identifier name is given as
442 -- a string with lower case letters.
444 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
445 -- Called to process a precondition or postcondition pragma. There are
446 -- three cases:
448 -- The pragma appears after a subprogram spec
450 -- If the corresponding check is not enabled, the pragma is analyzed
451 -- but otherwise ignored and control returns with In_Body set False.
453 -- If the check is enabled, then the first step is to analyze the
454 -- pragma, but this is skipped if the subprogram spec appears within
455 -- a package specification (because this is the case where we delay
456 -- analysis till the end of the spec). Then (whether or not it was
457 -- analyzed), the pragma is chained to the subprogram in question
458 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
459 -- caller with In_Body set False.
461 -- The pragma appears at the start of subprogram body declarations
463 -- In this case an immediate return to the caller is made with
464 -- In_Body set True, and the pragma is NOT analyzed.
466 -- In all other cases, an error message for bad placement is given
468 procedure Check_Static_Constraint (Constr : Node_Id);
469 -- Constr is a constraint from an N_Subtype_Indication node from a
470 -- component constraint in an Unchecked_Union type. This routine checks
471 -- that the constraint is static as required by the restrictions for
472 -- Unchecked_Union.
474 procedure Check_Valid_Configuration_Pragma;
475 -- Legality checks for placement of a configuration pragma
477 procedure Check_Valid_Library_Unit_Pragma;
478 -- Legality checks for library unit pragmas. A special case arises for
479 -- pragmas in generic instances that come from copies of the original
480 -- library unit pragmas in the generic templates. In the case of other
481 -- than library level instantiations these can appear in contexts which
482 -- would normally be invalid (they only apply to the original template
483 -- and to library level instantiations), and they are simply ignored,
484 -- which is implemented by rewriting them as null statements.
486 procedure Check_Variant (Variant : Node_Id);
487 -- Check Unchecked_Union variant for lack of nested variants and
488 -- presence of at least one component.
490 procedure Error_Pragma (Msg : String);
491 pragma No_Return (Error_Pragma);
492 -- Outputs error message for current pragma. The message contains a %
493 -- that will be replaced with the pragma name, and the flag is placed
494 -- on the pragma itself. Pragma_Exit is then raised.
496 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
497 pragma No_Return (Error_Pragma_Arg);
498 -- Outputs error message for current pragma. The message may contain
499 -- a % that will be replaced with the pragma name. The parameter Arg
500 -- may either be a pragma argument association, in which case the flag
501 -- is placed on the expression of this association, or an expression,
502 -- in which case the flag is placed directly on the expression. The
503 -- message is placed using Error_Msg_N, so the message may also contain
504 -- an & insertion character which will reference the given Arg value.
505 -- After placing the message, Pragma_Exit is raised.
507 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
508 pragma No_Return (Error_Pragma_Arg);
509 -- Similar to above form of Error_Pragma_Arg except that two messages
510 -- are provided, the second is a continuation comment starting with \.
512 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
513 pragma No_Return (Error_Pragma_Arg_Ident);
514 -- Outputs error message for current pragma. The message may contain
515 -- a % that will be replaced with the pragma name. The parameter Arg
516 -- must be a pragma argument association with a non-empty identifier
517 -- (i.e. its Chars field must be set), and the error message is placed
518 -- on the identifier. The message is placed using Error_Msg_N so
519 -- the message may also contain an & insertion character which will
520 -- reference the identifier. After placing the message, Pragma_Exit
521 -- is raised.
523 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
524 pragma No_Return (Error_Pragma_Ref);
525 -- Outputs error message for current pragma. The message may contain
526 -- a % that will be replaced with the pragma name. The parameter Ref
527 -- must be an entity whose name can be referenced by & and sloc by #.
528 -- After placing the message, Pragma_Exit is raised.
530 function Find_Lib_Unit_Name return Entity_Id;
531 -- Used for a library unit pragma to find the entity to which the
532 -- library unit pragma applies, returns the entity found.
534 procedure Find_Program_Unit_Name (Id : Node_Id);
535 -- If the pragma is a compilation unit pragma, the id must denote the
536 -- compilation unit in the same compilation, and the pragma must appear
537 -- in the list of preceding or trailing pragmas. If it is a program
538 -- unit pragma that is not a compilation unit pragma, then the
539 -- identifier must be visible.
541 function Find_Unique_Parameterless_Procedure
542 (Name : Entity_Id;
543 Arg : Node_Id) return Entity_Id;
544 -- Used for a procedure pragma to find the unique parameterless
545 -- procedure identified by Name, returns it if it exists, otherwise
546 -- errors out and uses Arg as the pragma argument for the message.
548 procedure Gather_Associations
549 (Names : Name_List;
550 Args : out Args_List);
551 -- This procedure is used to gather the arguments for a pragma that
552 -- permits arbitrary ordering of parameters using the normal rules
553 -- for named and positional parameters. The Names argument is a list
554 -- of Name_Id values that corresponds to the allowed pragma argument
555 -- association identifiers in order. The result returned in Args is
556 -- a list of corresponding expressions that are the pragma arguments.
557 -- Note that this is a list of expressions, not of pragma argument
558 -- associations (Gather_Associations has completely checked all the
559 -- optional identifiers when it returns). An entry in Args is Empty
560 -- on return if the corresponding argument is not present.
562 procedure GNAT_Pragma;
563 -- Called for all GNAT defined pragmas to check the relevant restriction
564 -- (No_Implementation_Pragmas).
566 function Is_Before_First_Decl
567 (Pragma_Node : Node_Id;
568 Decls : List_Id) return Boolean;
569 -- Return True if Pragma_Node is before the first declarative item in
570 -- Decls where Decls is the list of declarative items.
572 function Is_Configuration_Pragma return Boolean;
573 -- Determines if the placement of the current pragma is appropriate
574 -- for a configuration pragma.
576 function Is_In_Context_Clause return Boolean;
577 -- Returns True if pragma appears within the context clause of a unit,
578 -- and False for any other placement (does not generate any messages).
580 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
581 -- Analyzes the argument, and determines if it is a static string
582 -- expression, returns True if so, False if non-static or not String.
584 procedure Pragma_Misplaced;
585 pragma No_Return (Pragma_Misplaced);
586 -- Issue fatal error message for misplaced pragma
588 procedure Process_Atomic_Shared_Volatile;
589 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
590 -- Shared is an obsolete Ada 83 pragma, treated as being identical
591 -- in effect to pragma Atomic.
593 procedure Process_Compile_Time_Warning_Or_Error;
594 -- Common processing for Compile_Time_Error and Compile_Time_Warning
596 procedure Process_Convention
597 (C : out Convention_Id;
598 Ent : out Entity_Id);
599 -- Common processing for Convention, Interface, Import and Export.
600 -- Checks first two arguments of pragma, and sets the appropriate
601 -- convention value in the specified entity or entities. On return
602 -- C is the convention, Ent is the referenced entity.
604 procedure Process_Extended_Import_Export_Exception_Pragma
605 (Arg_Internal : Node_Id;
606 Arg_External : Node_Id;
607 Arg_Form : Node_Id;
608 Arg_Code : Node_Id);
609 -- Common processing for the pragmas Import/Export_Exception. The three
610 -- arguments correspond to the three named parameters of the pragma. An
611 -- argument is empty if the corresponding parameter is not present in
612 -- the pragma.
614 procedure Process_Extended_Import_Export_Object_Pragma
615 (Arg_Internal : Node_Id;
616 Arg_External : Node_Id;
617 Arg_Size : Node_Id);
618 -- Common processing for the pragmas Import/Export_Object. The three
619 -- arguments correspond to the three named parameters of the pragmas. An
620 -- argument is empty if the corresponding parameter is not present in
621 -- the pragma.
623 procedure Process_Extended_Import_Export_Internal_Arg
624 (Arg_Internal : Node_Id := Empty);
625 -- Common processing for all extended Import and Export pragmas. The
626 -- argument is the pragma parameter for the Internal argument. If
627 -- Arg_Internal is empty or inappropriate, an error message is posted.
628 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
629 -- set to identify the referenced entity.
631 procedure Process_Extended_Import_Export_Subprogram_Pragma
632 (Arg_Internal : Node_Id;
633 Arg_External : Node_Id;
634 Arg_Parameter_Types : Node_Id;
635 Arg_Result_Type : Node_Id := Empty;
636 Arg_Mechanism : Node_Id;
637 Arg_Result_Mechanism : Node_Id := Empty;
638 Arg_First_Optional_Parameter : Node_Id := Empty);
639 -- Common processing for all extended Import and Export pragmas applying
640 -- to subprograms. The caller omits any arguments that do not apply to
641 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
642 -- only in the Import_Function and Export_Function cases). The argument
643 -- names correspond to the allowed pragma association identifiers.
645 procedure Process_Generic_List;
646 -- Common processing for Share_Generic and Inline_Generic
648 procedure Process_Import_Or_Interface;
649 -- Common processing for Import of Interface
651 procedure Process_Inline (Active : Boolean);
652 -- Common processing for Inline and Inline_Always. The parameter
653 -- indicates if the inline pragma is active, i.e. if it should actually
654 -- cause inlining to occur.
656 procedure Process_Interface_Name
657 (Subprogram_Def : Entity_Id;
658 Ext_Arg : Node_Id;
659 Link_Arg : Node_Id);
660 -- Given the last two arguments of pragma Import, pragma Export, or
661 -- pragma Interface_Name, performs validity checks and sets the
662 -- Interface_Name field of the given subprogram entity to the
663 -- appropriate external or link name, depending on the arguments given.
664 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
665 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
666 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
667 -- nor Link_Arg is present, the interface name is set to the default
668 -- from the subprogram name.
670 procedure Process_Interrupt_Or_Attach_Handler;
671 -- Common processing for Interrupt and Attach_Handler pragmas
673 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
674 -- Common processing for Restrictions and Restriction_Warnings pragmas.
675 -- Warn is True for Restriction_Warnings, or for Restrictions if the
676 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
677 -- is not set in the Restrictions case.
679 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
680 -- Common processing for Suppress and Unsuppress. The boolean parameter
681 -- Suppress_Case is True for the Suppress case, and False for the
682 -- Unsuppress case.
684 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
685 -- This procedure sets the Is_Exported flag for the given entity,
686 -- checking that the entity was not previously imported. Arg is
687 -- the argument that specified the entity. A check is also made
688 -- for exporting inappropriate entities.
690 procedure Set_Extended_Import_Export_External_Name
691 (Internal_Ent : Entity_Id;
692 Arg_External : Node_Id);
693 -- Common processing for all extended import export pragmas. The first
694 -- argument, Internal_Ent, is the internal entity, which has already
695 -- been checked for validity by the caller. Arg_External is from the
696 -- Import or Export pragma, and may be null if no External parameter
697 -- was present. If Arg_External is present and is a non-null string
698 -- (a null string is treated as the default), then the Interface_Name
699 -- field of Internal_Ent is set appropriately.
701 procedure Set_Imported (E : Entity_Id);
702 -- This procedure sets the Is_Imported flag for the given entity,
703 -- checking that it is not previously exported or imported.
705 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
706 -- Mech is a parameter passing mechanism (see Import_Function syntax
707 -- for MECHANISM_NAME). This routine checks that the mechanism argument
708 -- has the right form, and if not issues an error message. If the
709 -- argument has the right form then the Mechanism field of Ent is
710 -- set appropriately.
712 procedure Set_Ravenscar_Profile (N : Node_Id);
713 -- Activate the set of configuration pragmas and restrictions that make
714 -- up the Ravenscar Profile. N is the corresponding pragma node, which
715 -- is used for error messages on any constructs that violate the
716 -- profile.
718 ---------------------
719 -- Ada_2005_Pragma --
720 ---------------------
722 procedure Ada_2005_Pragma is
723 begin
724 if Ada_Version <= Ada_95 then
725 Check_Restriction (No_Implementation_Pragmas, N);
726 end if;
727 end Ada_2005_Pragma;
729 --------------------------
730 -- Check_Ada_83_Warning --
731 --------------------------
733 procedure Check_Ada_83_Warning is
734 begin
735 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
736 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
737 end if;
738 end Check_Ada_83_Warning;
740 ---------------------
741 -- Check_Arg_Count --
742 ---------------------
744 procedure Check_Arg_Count (Required : Nat) is
745 begin
746 if Arg_Count /= Required then
747 Error_Pragma ("wrong number of arguments for pragma%");
748 end if;
749 end Check_Arg_Count;
751 --------------------------------
752 -- Check_Arg_Is_External_Name --
753 --------------------------------
755 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
756 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
758 begin
759 if Nkind (Argx) = N_Identifier then
760 return;
762 else
763 Analyze_And_Resolve (Argx, Standard_String);
765 if Is_OK_Static_Expression (Argx) then
766 return;
768 elsif Etype (Argx) = Any_Type then
769 raise Pragma_Exit;
771 -- An interesting special case, if we have a string literal and
772 -- we are in Ada 83 mode, then we allow it even though it will
773 -- not be flagged as static. This allows expected Ada 83 mode
774 -- use of external names which are string literals, even though
775 -- technically these are not static in Ada 83.
777 elsif Ada_Version = Ada_83
778 and then Nkind (Argx) = N_String_Literal
779 then
780 return;
782 -- Static expression that raises Constraint_Error. This has
783 -- already been flagged, so just exit from pragma processing.
785 elsif Is_Static_Expression (Argx) then
786 raise Pragma_Exit;
788 -- Here we have a real error (non-static expression)
790 else
791 Error_Msg_Name_1 := Pname;
792 Flag_Non_Static_Expr
793 ("argument for pragma% must be a identifier or " &
794 "static string expression!", Argx);
795 raise Pragma_Exit;
796 end if;
797 end if;
798 end Check_Arg_Is_External_Name;
800 -----------------------------
801 -- Check_Arg_Is_Identifier --
802 -----------------------------
804 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
805 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
806 begin
807 if Nkind (Argx) /= N_Identifier then
808 Error_Pragma_Arg
809 ("argument for pragma% must be identifier", Argx);
810 end if;
811 end Check_Arg_Is_Identifier;
813 ----------------------------------
814 -- Check_Arg_Is_Integer_Literal --
815 ----------------------------------
817 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
818 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
819 begin
820 if Nkind (Argx) /= N_Integer_Literal then
821 Error_Pragma_Arg
822 ("argument for pragma% must be integer literal", Argx);
823 end if;
824 end Check_Arg_Is_Integer_Literal;
826 -------------------------------------------
827 -- Check_Arg_Is_Library_Level_Local_Name --
828 -------------------------------------------
830 -- LOCAL_NAME ::=
831 -- DIRECT_NAME
832 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
833 -- | library_unit_NAME
835 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
836 begin
837 Check_Arg_Is_Local_Name (Arg);
839 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
840 and then Comes_From_Source (N)
841 then
842 Error_Pragma_Arg
843 ("argument for pragma% must be library level entity", Arg);
844 end if;
845 end Check_Arg_Is_Library_Level_Local_Name;
847 -----------------------------
848 -- Check_Arg_Is_Local_Name --
849 -----------------------------
851 -- LOCAL_NAME ::=
852 -- DIRECT_NAME
853 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
854 -- | library_unit_NAME
856 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
857 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
859 begin
860 Analyze (Argx);
862 if Nkind (Argx) not in N_Direct_Name
863 and then (Nkind (Argx) /= N_Attribute_Reference
864 or else Present (Expressions (Argx))
865 or else Nkind (Prefix (Argx)) /= N_Identifier)
866 and then (not Is_Entity_Name (Argx)
867 or else not Is_Compilation_Unit (Entity (Argx)))
868 then
869 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
870 end if;
872 if Is_Entity_Name (Argx)
873 and then Scope (Entity (Argx)) /= Current_Scope
874 then
875 Error_Pragma_Arg
876 ("pragma% argument must be in same declarative part", Arg);
877 end if;
878 end Check_Arg_Is_Local_Name;
880 ---------------------------------
881 -- Check_Arg_Is_Locking_Policy --
882 ---------------------------------
884 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
885 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
887 begin
888 Check_Arg_Is_Identifier (Argx);
890 if not Is_Locking_Policy_Name (Chars (Argx)) then
891 Error_Pragma_Arg
892 ("& is not a valid locking policy name", Argx);
893 end if;
894 end Check_Arg_Is_Locking_Policy;
896 -------------------------
897 -- Check_Arg_Is_One_Of --
898 -------------------------
900 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
901 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
903 begin
904 Check_Arg_Is_Identifier (Argx);
906 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
907 Error_Msg_Name_2 := N1;
908 Error_Msg_Name_3 := N2;
909 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
910 end if;
911 end Check_Arg_Is_One_Of;
913 procedure Check_Arg_Is_One_Of
914 (Arg : Node_Id;
915 N1, N2, N3 : Name_Id)
917 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
919 begin
920 Check_Arg_Is_Identifier (Argx);
922 if Chars (Argx) /= N1
923 and then Chars (Argx) /= N2
924 and then Chars (Argx) /= N3
925 then
926 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
927 end if;
928 end Check_Arg_Is_One_Of;
930 procedure Check_Arg_Is_One_Of
931 (Arg : Node_Id;
932 N1, N2, N3, N4 : Name_Id)
934 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
936 begin
937 Check_Arg_Is_Identifier (Argx);
939 if Chars (Argx) /= N1
940 and then Chars (Argx) /= N2
941 and then Chars (Argx) /= N3
942 and then Chars (Argx) /= N4
943 then
944 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
945 end if;
946 end Check_Arg_Is_One_Of;
948 ---------------------------------
949 -- Check_Arg_Is_Queuing_Policy --
950 ---------------------------------
952 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
953 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
955 begin
956 Check_Arg_Is_Identifier (Argx);
958 if not Is_Queuing_Policy_Name (Chars (Argx)) then
959 Error_Pragma_Arg
960 ("& is not a valid queuing policy name", Argx);
961 end if;
962 end Check_Arg_Is_Queuing_Policy;
964 ------------------------------------
965 -- Check_Arg_Is_Static_Expression --
966 ------------------------------------
968 procedure Check_Arg_Is_Static_Expression
969 (Arg : Node_Id;
970 Typ : Entity_Id := Empty)
972 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
974 begin
975 if Present (Typ) then
976 Analyze_And_Resolve (Argx, Typ);
977 else
978 Analyze_And_Resolve (Argx);
979 end if;
981 if Is_OK_Static_Expression (Argx) then
982 return;
984 elsif Etype (Argx) = Any_Type then
985 raise Pragma_Exit;
987 -- An interesting special case, if we have a string literal and we
988 -- are in Ada 83 mode, then we allow it even though it will not be
989 -- flagged as static. This allows the use of Ada 95 pragmas like
990 -- Import in Ada 83 mode. They will of course be flagged with
991 -- warnings as usual, but will not cause errors.
993 elsif Ada_Version = Ada_83
994 and then Nkind (Argx) = N_String_Literal
995 then
996 return;
998 -- Static expression that raises Constraint_Error. This has already
999 -- been flagged, so just exit from pragma processing.
1001 elsif Is_Static_Expression (Argx) then
1002 raise Pragma_Exit;
1004 -- Finally, we have a real error
1006 else
1007 Error_Msg_Name_1 := Pname;
1008 Flag_Non_Static_Expr
1009 ("argument for pragma% must be a static expression!", Argx);
1010 raise Pragma_Exit;
1011 end if;
1012 end Check_Arg_Is_Static_Expression;
1014 ------------------------------------------
1015 -- Check_Arg_Is_Task_Dispatching_Policy --
1016 ------------------------------------------
1018 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1019 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1021 begin
1022 Check_Arg_Is_Identifier (Argx);
1024 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1025 Error_Pragma_Arg
1026 ("& is not a valid task dispatching policy name", Argx);
1027 end if;
1028 end Check_Arg_Is_Task_Dispatching_Policy;
1030 ---------------------
1031 -- Check_Arg_Order --
1032 ---------------------
1034 procedure Check_Arg_Order (Names : Name_List) is
1035 Arg : Node_Id;
1037 Highest_So_Far : Natural := 0;
1038 -- Highest index in Names seen do far
1040 begin
1041 Arg := Arg1;
1042 for J in 1 .. Arg_Count loop
1043 if Chars (Arg) /= No_Name then
1044 for K in Names'Range loop
1045 if Chars (Arg) = Names (K) then
1046 if K < Highest_So_Far then
1047 Error_Msg_Name_1 := Pname;
1048 Error_Msg_N
1049 ("parameters out of order for pragma%", Arg);
1050 Error_Msg_Name_1 := Names (K);
1051 Error_Msg_Name_2 := Names (Highest_So_Far);
1052 Error_Msg_N ("\% must appear before %", Arg);
1053 raise Pragma_Exit;
1055 else
1056 Highest_So_Far := K;
1057 end if;
1058 end if;
1059 end loop;
1060 end if;
1062 Arg := Next (Arg);
1063 end loop;
1064 end Check_Arg_Order;
1066 --------------------------------
1067 -- Check_At_Least_N_Arguments --
1068 --------------------------------
1070 procedure Check_At_Least_N_Arguments (N : Nat) is
1071 begin
1072 if Arg_Count < N then
1073 Error_Pragma ("too few arguments for pragma%");
1074 end if;
1075 end Check_At_Least_N_Arguments;
1077 -------------------------------
1078 -- Check_At_Most_N_Arguments --
1079 -------------------------------
1081 procedure Check_At_Most_N_Arguments (N : Nat) is
1082 Arg : Node_Id;
1083 begin
1084 if Arg_Count > N then
1085 Arg := Arg1;
1086 for J in 1 .. N loop
1087 Next (Arg);
1088 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1089 end loop;
1090 end if;
1091 end Check_At_Most_N_Arguments;
1093 ---------------------
1094 -- Check_Component --
1095 ---------------------
1097 procedure Check_Component (Comp : Node_Id) is
1098 begin
1099 if Nkind (Comp) = N_Component_Declaration then
1100 declare
1101 Sindic : constant Node_Id :=
1102 Subtype_Indication (Component_Definition (Comp));
1103 Typ : constant Entity_Id :=
1104 Etype (Defining_Identifier (Comp));
1105 begin
1106 if Nkind (Sindic) = N_Subtype_Indication then
1108 -- Ada 2005 (AI-216): If a component subtype is subject to
1109 -- a per-object constraint, then the component type shall
1110 -- be an Unchecked_Union.
1112 if Has_Per_Object_Constraint (Defining_Identifier (Comp))
1113 and then
1114 not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1115 then
1116 Error_Msg_N ("component subtype subject to per-object" &
1117 " constraint must be an Unchecked_Union", Comp);
1118 end if;
1119 end if;
1121 if Is_Controlled (Typ) then
1122 Error_Msg_N
1123 ("component of unchecked union cannot be controlled", Comp);
1125 elsif Has_Task (Typ) then
1126 Error_Msg_N
1127 ("component of unchecked union cannot have tasks", Comp);
1128 end if;
1129 end;
1130 end if;
1131 end Check_Component;
1133 ----------------------------------
1134 -- Check_Duplicated_Export_Name --
1135 ----------------------------------
1137 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1138 String_Val : constant String_Id := Strval (Nam);
1140 begin
1141 -- We are only interested in the export case, and in the case of
1142 -- generics, it is the instance, not the template, that is the
1143 -- problem (the template will generate a warning in any case).
1145 if not Inside_A_Generic
1146 and then (Prag_Id = Pragma_Export
1147 or else
1148 Prag_Id = Pragma_Export_Procedure
1149 or else
1150 Prag_Id = Pragma_Export_Valued_Procedure
1151 or else
1152 Prag_Id = Pragma_Export_Function)
1153 then
1154 for J in Externals.First .. Externals.Last loop
1155 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1156 Error_Msg_Sloc := Sloc (Externals.Table (J));
1157 Error_Msg_N ("external name duplicates name given#", Nam);
1158 exit;
1159 end if;
1160 end loop;
1162 Externals.Append (Nam);
1163 end if;
1164 end Check_Duplicated_Export_Name;
1166 -------------------------
1167 -- Check_First_Subtype --
1168 -------------------------
1170 procedure Check_First_Subtype (Arg : Node_Id) is
1171 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1172 begin
1173 if not Is_First_Subtype (Entity (Argx)) then
1174 Error_Pragma_Arg
1175 ("pragma% cannot apply to subtype", Argx);
1176 end if;
1177 end Check_First_Subtype;
1179 ---------------------------
1180 -- Check_In_Main_Program --
1181 ---------------------------
1183 procedure Check_In_Main_Program is
1184 P : constant Node_Id := Parent (N);
1186 begin
1187 -- Must be at in subprogram body
1189 if Nkind (P) /= N_Subprogram_Body then
1190 Error_Pragma ("% pragma allowed only in subprogram");
1192 -- Otherwise warn if obviously not main program
1194 elsif Present (Parameter_Specifications (Specification (P)))
1195 or else not Is_Compilation_Unit (Defining_Entity (P))
1196 then
1197 Error_Msg_Name_1 := Pname;
1198 Error_Msg_N
1199 ("?pragma% is only effective in main program", N);
1200 end if;
1201 end Check_In_Main_Program;
1203 ---------------------------------------
1204 -- Check_Interrupt_Or_Attach_Handler --
1205 ---------------------------------------
1207 procedure Check_Interrupt_Or_Attach_Handler is
1208 Arg1_X : constant Node_Id := Expression (Arg1);
1209 Handler_Proc, Proc_Scope : Entity_Id;
1211 begin
1212 Analyze (Arg1_X);
1214 if Prag_Id = Pragma_Interrupt_Handler then
1215 Check_Restriction (No_Dynamic_Attachment, N);
1216 end if;
1218 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1219 Proc_Scope := Scope (Handler_Proc);
1221 -- On AAMP only, a pragma Interrupt_Handler is supported for
1222 -- nonprotected parameterless procedures.
1224 if not AAMP_On_Target
1225 or else Prag_Id = Pragma_Attach_Handler
1226 then
1227 if Ekind (Proc_Scope) /= E_Protected_Type then
1228 Error_Pragma_Arg
1229 ("argument of pragma% must be protected procedure", Arg1);
1230 end if;
1232 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1233 Error_Pragma ("pragma% must be in protected definition");
1234 end if;
1235 end if;
1237 if not Is_Library_Level_Entity (Proc_Scope)
1238 or else (AAMP_On_Target
1239 and then not Is_Library_Level_Entity (Handler_Proc))
1240 then
1241 Error_Pragma_Arg
1242 ("argument for pragma% must be library level entity", Arg1);
1243 end if;
1244 end Check_Interrupt_Or_Attach_Handler;
1246 -------------------------------------------
1247 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1248 -------------------------------------------
1250 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1251 P : Node_Id;
1253 begin
1254 P := Parent (N);
1255 loop
1256 if No (P) then
1257 exit;
1259 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1260 exit;
1262 elsif Nkind_In (P, N_Package_Specification,
1263 N_Block_Statement)
1264 then
1265 return;
1267 -- Note: the following tests seem a little peculiar, because
1268 -- they test for bodies, but if we were in the statement part
1269 -- of the body, we would already have hit the handled statement
1270 -- sequence, so the only way we get here is by being in the
1271 -- declarative part of the body.
1273 elsif Nkind_In (P, N_Subprogram_Body,
1274 N_Package_Body,
1275 N_Task_Body,
1276 N_Entry_Body)
1277 then
1278 return;
1279 end if;
1281 P := Parent (P);
1282 end loop;
1284 Error_Pragma ("pragma% is not in declarative part or package spec");
1285 end Check_Is_In_Decl_Part_Or_Package_Spec;
1287 -------------------------
1288 -- Check_No_Identifier --
1289 -------------------------
1291 procedure Check_No_Identifier (Arg : Node_Id) is
1292 begin
1293 if Chars (Arg) /= No_Name then
1294 Error_Pragma_Arg_Ident
1295 ("pragma% does not permit identifier& here", Arg);
1296 end if;
1297 end Check_No_Identifier;
1299 --------------------------
1300 -- Check_No_Identifiers --
1301 --------------------------
1303 procedure Check_No_Identifiers is
1304 Arg_Node : Node_Id;
1305 begin
1306 if Arg_Count > 0 then
1307 Arg_Node := Arg1;
1308 while Present (Arg_Node) loop
1309 Check_No_Identifier (Arg_Node);
1310 Next (Arg_Node);
1311 end loop;
1312 end if;
1313 end Check_No_Identifiers;
1315 -------------------------------
1316 -- Check_Optional_Identifier --
1317 -------------------------------
1319 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1320 begin
1321 if Present (Arg) and then Chars (Arg) /= No_Name then
1322 if Chars (Arg) /= Id then
1323 Error_Msg_Name_1 := Pname;
1324 Error_Msg_Name_2 := Id;
1325 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1326 raise Pragma_Exit;
1327 end if;
1328 end if;
1329 end Check_Optional_Identifier;
1331 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1332 begin
1333 Name_Buffer (1 .. Id'Length) := Id;
1334 Name_Len := Id'Length;
1335 Check_Optional_Identifier (Arg, Name_Find);
1336 end Check_Optional_Identifier;
1338 --------------------------------------
1339 -- Check_Precondition_Postcondition --
1340 --------------------------------------
1342 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1343 P : Node_Id;
1344 PO : Node_Id;
1346 procedure Chain_PPC (PO : Node_Id);
1347 -- If PO is a subprogram declaration node (or a generic subprogram
1348 -- declaration node), then the precondition/postcondition applies
1349 -- to this subprogram and the processing for the pragma is completed.
1350 -- Otherwise the pragma is misplaced.
1352 ---------------
1353 -- Chain_PPC --
1354 ---------------
1356 procedure Chain_PPC (PO : Node_Id) is
1357 S : Node_Id;
1359 begin
1360 if not Nkind_In (PO, N_Subprogram_Declaration,
1361 N_Generic_Subprogram_Declaration)
1362 then
1363 Pragma_Misplaced;
1364 end if;
1366 -- Here if we have subprogram or generic subprogram declaration
1368 S := Defining_Unit_Name (Specification (PO));
1370 -- Analyze the pragma unless it appears within a package spec,
1371 -- which is the case where we delay the analysis of the PPC until
1372 -- the end of the package declarations (for details, see
1373 -- Analyze_Package_Specification.Analyze_PPCs).
1375 if not Is_Package_Or_Generic_Package (Scope (S)) then
1376 Analyze_PPC_In_Decl_Part (N, S);
1377 end if;
1379 -- Chain spec PPC pragma to list for subprogram
1381 Set_Next_Pragma (N, Spec_PPC_List (S));
1382 Set_Spec_PPC_List (S, N);
1384 -- Return indicating spec case
1386 In_Body := False;
1387 return;
1388 end Chain_PPC;
1390 -- Start of processing for Check_Precondition_Postcondition
1392 begin
1393 if not Is_List_Member (N) then
1394 Pragma_Misplaced;
1395 end if;
1397 -- Record if pragma is enabled
1399 if Check_Enabled (Pname) then
1400 Set_Pragma_Enabled (N);
1401 Set_SCO_Pragma_Enabled (Loc);
1402 end if;
1404 -- If we are within an inlined body, the legality of the pragma
1405 -- has been checked already.
1407 if In_Inlined_Body then
1408 In_Body := True;
1409 return;
1410 end if;
1412 -- Search prior declarations
1414 P := N;
1415 while Present (Prev (P)) loop
1416 P := Prev (P);
1418 -- If the previous node is a generic subprogram, do not go to to
1419 -- the original node, which is the unanalyzed tree: we need to
1420 -- attach the pre/postconditions to the analyzed version at this
1421 -- point. They get propagated to the original tree when analyzing
1422 -- the corresponding body.
1424 if Nkind (P) not in N_Generic_Declaration then
1425 PO := Original_Node (P);
1426 else
1427 PO := P;
1428 end if;
1430 -- Skip past prior pragma
1432 if Nkind (PO) = N_Pragma then
1433 null;
1435 -- Skip stuff not coming from source
1437 elsif not Comes_From_Source (PO) then
1438 null;
1440 -- Only remaining possibility is subprogram declaration
1442 else
1443 Chain_PPC (PO);
1444 return;
1445 end if;
1446 end loop;
1448 -- If we fall through loop, pragma is at start of list, so see if it
1449 -- is at the start of declarations of a subprogram body.
1451 if Nkind (Parent (N)) = N_Subprogram_Body
1452 and then List_Containing (N) = Declarations (Parent (N))
1453 then
1454 if Operating_Mode /= Generate_Code
1455 or else Inside_A_Generic
1456 then
1458 -- Analyze expression in pragma, for correctness
1459 -- and for ASIS use.
1461 Preanalyze_Spec_Expression
1462 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1463 end if;
1465 In_Body := True;
1466 return;
1468 -- See if it is in the pragmas after a library level subprogram
1470 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1471 Chain_PPC (Unit (Parent (Parent (N))));
1472 return;
1473 end if;
1475 -- If we fall through, pragma was misplaced
1477 Pragma_Misplaced;
1478 end Check_Precondition_Postcondition;
1480 -----------------------------
1481 -- Check_Static_Constraint --
1482 -----------------------------
1484 -- Note: for convenience in writing this procedure, in addition to
1485 -- the officially (i.e. by spec) allowed argument which is always a
1486 -- constraint, it also allows ranges and discriminant associations.
1487 -- Above is not clear ???
1489 procedure Check_Static_Constraint (Constr : Node_Id) is
1491 procedure Require_Static (E : Node_Id);
1492 -- Require given expression to be static expression
1494 --------------------
1495 -- Require_Static --
1496 --------------------
1498 procedure Require_Static (E : Node_Id) is
1499 begin
1500 if not Is_OK_Static_Expression (E) then
1501 Flag_Non_Static_Expr
1502 ("non-static constraint not allowed in Unchecked_Union!", E);
1503 raise Pragma_Exit;
1504 end if;
1505 end Require_Static;
1507 -- Start of processing for Check_Static_Constraint
1509 begin
1510 case Nkind (Constr) is
1511 when N_Discriminant_Association =>
1512 Require_Static (Expression (Constr));
1514 when N_Range =>
1515 Require_Static (Low_Bound (Constr));
1516 Require_Static (High_Bound (Constr));
1518 when N_Attribute_Reference =>
1519 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1520 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1522 when N_Range_Constraint =>
1523 Check_Static_Constraint (Range_Expression (Constr));
1525 when N_Index_Or_Discriminant_Constraint =>
1526 declare
1527 IDC : Entity_Id;
1528 begin
1529 IDC := First (Constraints (Constr));
1530 while Present (IDC) loop
1531 Check_Static_Constraint (IDC);
1532 Next (IDC);
1533 end loop;
1534 end;
1536 when others =>
1537 null;
1538 end case;
1539 end Check_Static_Constraint;
1541 --------------------------------------
1542 -- Check_Valid_Configuration_Pragma --
1543 --------------------------------------
1545 -- A configuration pragma must appear in the context clause of a
1546 -- compilation unit, and only other pragmas may precede it. Note that
1547 -- the test also allows use in a configuration pragma file.
1549 procedure Check_Valid_Configuration_Pragma is
1550 begin
1551 if not Is_Configuration_Pragma then
1552 Error_Pragma ("incorrect placement for configuration pragma%");
1553 end if;
1554 end Check_Valid_Configuration_Pragma;
1556 -------------------------------------
1557 -- Check_Valid_Library_Unit_Pragma --
1558 -------------------------------------
1560 procedure Check_Valid_Library_Unit_Pragma is
1561 Plist : List_Id;
1562 Parent_Node : Node_Id;
1563 Unit_Name : Entity_Id;
1564 Unit_Kind : Node_Kind;
1565 Unit_Node : Node_Id;
1566 Sindex : Source_File_Index;
1568 begin
1569 if not Is_List_Member (N) then
1570 Pragma_Misplaced;
1572 else
1573 Plist := List_Containing (N);
1574 Parent_Node := Parent (Plist);
1576 if Parent_Node = Empty then
1577 Pragma_Misplaced;
1579 -- Case of pragma appearing after a compilation unit. In this case
1580 -- it must have an argument with the corresponding name and must
1581 -- be part of the following pragmas of its parent.
1583 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1584 if Plist /= Pragmas_After (Parent_Node) then
1585 Pragma_Misplaced;
1587 elsif Arg_Count = 0 then
1588 Error_Pragma
1589 ("argument required if outside compilation unit");
1591 else
1592 Check_No_Identifiers;
1593 Check_Arg_Count (1);
1594 Unit_Node := Unit (Parent (Parent_Node));
1595 Unit_Kind := Nkind (Unit_Node);
1597 Analyze (Expression (Arg1));
1599 if Unit_Kind = N_Generic_Subprogram_Declaration
1600 or else Unit_Kind = N_Subprogram_Declaration
1601 then
1602 Unit_Name := Defining_Entity (Unit_Node);
1604 elsif Unit_Kind in N_Generic_Instantiation then
1605 Unit_Name := Defining_Entity (Unit_Node);
1607 else
1608 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1609 end if;
1611 if Chars (Unit_Name) /=
1612 Chars (Entity (Expression (Arg1)))
1613 then
1614 Error_Pragma_Arg
1615 ("pragma% argument is not current unit name", Arg1);
1616 end if;
1618 if Ekind (Unit_Name) = E_Package
1619 and then Present (Renamed_Entity (Unit_Name))
1620 then
1621 Error_Pragma ("pragma% not allowed for renamed package");
1622 end if;
1623 end if;
1625 -- Pragma appears other than after a compilation unit
1627 else
1628 -- Here we check for the generic instantiation case and also
1629 -- for the case of processing a generic formal package. We
1630 -- detect these cases by noting that the Sloc on the node
1631 -- does not belong to the current compilation unit.
1633 Sindex := Source_Index (Current_Sem_Unit);
1635 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1636 Rewrite (N, Make_Null_Statement (Loc));
1637 return;
1639 -- If before first declaration, the pragma applies to the
1640 -- enclosing unit, and the name if present must be this name.
1642 elsif Is_Before_First_Decl (N, Plist) then
1643 Unit_Node := Unit_Declaration_Node (Current_Scope);
1644 Unit_Kind := Nkind (Unit_Node);
1646 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1647 Pragma_Misplaced;
1649 elsif Unit_Kind = N_Subprogram_Body
1650 and then not Acts_As_Spec (Unit_Node)
1651 then
1652 Pragma_Misplaced;
1654 elsif Nkind (Parent_Node) = N_Package_Body then
1655 Pragma_Misplaced;
1657 elsif Nkind (Parent_Node) = N_Package_Specification
1658 and then Plist = Private_Declarations (Parent_Node)
1659 then
1660 Pragma_Misplaced;
1662 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1663 or else Nkind (Parent_Node) =
1664 N_Generic_Subprogram_Declaration)
1665 and then Plist = Generic_Formal_Declarations (Parent_Node)
1666 then
1667 Pragma_Misplaced;
1669 elsif Arg_Count > 0 then
1670 Analyze (Expression (Arg1));
1672 if Entity (Expression (Arg1)) /= Current_Scope then
1673 Error_Pragma_Arg
1674 ("name in pragma% must be enclosing unit", Arg1);
1675 end if;
1677 -- It is legal to have no argument in this context
1679 else
1680 return;
1681 end if;
1683 -- Error if not before first declaration. This is because a
1684 -- library unit pragma argument must be the name of a library
1685 -- unit (RM 10.1.5(7)), but the only names permitted in this
1686 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1687 -- generic subprogram declarations or generic instantiations.
1689 else
1690 Error_Pragma
1691 ("pragma% misplaced, must be before first declaration");
1692 end if;
1693 end if;
1694 end if;
1695 end Check_Valid_Library_Unit_Pragma;
1697 -------------------
1698 -- Check_Variant --
1699 -------------------
1701 procedure Check_Variant (Variant : Node_Id) is
1702 Clist : constant Node_Id := Component_List (Variant);
1703 Comp : Node_Id;
1705 begin
1706 if not Is_Non_Empty_List (Component_Items (Clist)) then
1707 Error_Msg_N
1708 ("Unchecked_Union may not have empty component list",
1709 Variant);
1710 return;
1711 end if;
1713 Comp := First (Component_Items (Clist));
1714 while Present (Comp) loop
1715 Check_Component (Comp);
1716 Next (Comp);
1717 end loop;
1718 end Check_Variant;
1720 ------------------
1721 -- Error_Pragma --
1722 ------------------
1724 procedure Error_Pragma (Msg : String) is
1725 begin
1726 Error_Msg_Name_1 := Pname;
1727 Error_Msg_N (Msg, N);
1728 raise Pragma_Exit;
1729 end Error_Pragma;
1731 ----------------------
1732 -- Error_Pragma_Arg --
1733 ----------------------
1735 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1736 begin
1737 Error_Msg_Name_1 := Pname;
1738 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1739 raise Pragma_Exit;
1740 end Error_Pragma_Arg;
1742 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1743 begin
1744 Error_Msg_Name_1 := Pname;
1745 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1746 Error_Pragma_Arg (Msg2, Arg);
1747 end Error_Pragma_Arg;
1749 ----------------------------
1750 -- Error_Pragma_Arg_Ident --
1751 ----------------------------
1753 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1754 begin
1755 Error_Msg_Name_1 := Pname;
1756 Error_Msg_N (Msg, Arg);
1757 raise Pragma_Exit;
1758 end Error_Pragma_Arg_Ident;
1760 ----------------------
1761 -- Error_Pragma_Ref --
1762 ----------------------
1764 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
1765 begin
1766 Error_Msg_Name_1 := Pname;
1767 Error_Msg_Sloc := Sloc (Ref);
1768 Error_Msg_NE (Msg, N, Ref);
1769 raise Pragma_Exit;
1770 end Error_Pragma_Ref;
1772 ------------------------
1773 -- Find_Lib_Unit_Name --
1774 ------------------------
1776 function Find_Lib_Unit_Name return Entity_Id is
1777 begin
1778 -- Return inner compilation unit entity, for case of nested
1779 -- categorization pragmas. This happens in generic unit.
1781 if Nkind (Parent (N)) = N_Package_Specification
1782 and then Defining_Entity (Parent (N)) /= Current_Scope
1783 then
1784 return Defining_Entity (Parent (N));
1785 else
1786 return Current_Scope;
1787 end if;
1788 end Find_Lib_Unit_Name;
1790 ----------------------------
1791 -- Find_Program_Unit_Name --
1792 ----------------------------
1794 procedure Find_Program_Unit_Name (Id : Node_Id) is
1795 Unit_Name : Entity_Id;
1796 Unit_Kind : Node_Kind;
1797 P : constant Node_Id := Parent (N);
1799 begin
1800 if Nkind (P) = N_Compilation_Unit then
1801 Unit_Kind := Nkind (Unit (P));
1803 if Unit_Kind = N_Subprogram_Declaration
1804 or else Unit_Kind = N_Package_Declaration
1805 or else Unit_Kind in N_Generic_Declaration
1806 then
1807 Unit_Name := Defining_Entity (Unit (P));
1809 if Chars (Id) = Chars (Unit_Name) then
1810 Set_Entity (Id, Unit_Name);
1811 Set_Etype (Id, Etype (Unit_Name));
1812 else
1813 Set_Etype (Id, Any_Type);
1814 Error_Pragma
1815 ("cannot find program unit referenced by pragma%");
1816 end if;
1818 else
1819 Set_Etype (Id, Any_Type);
1820 Error_Pragma ("pragma% inapplicable to this unit");
1821 end if;
1823 else
1824 Analyze (Id);
1825 end if;
1826 end Find_Program_Unit_Name;
1828 -----------------------------------------
1829 -- Find_Unique_Parameterless_Procedure --
1830 -----------------------------------------
1832 function Find_Unique_Parameterless_Procedure
1833 (Name : Entity_Id;
1834 Arg : Node_Id) return Entity_Id
1836 Proc : Entity_Id := Empty;
1838 begin
1839 -- The body of this procedure needs some comments ???
1841 if not Is_Entity_Name (Name) then
1842 Error_Pragma_Arg
1843 ("argument of pragma% must be entity name", Arg);
1845 elsif not Is_Overloaded (Name) then
1846 Proc := Entity (Name);
1848 if Ekind (Proc) /= E_Procedure
1849 or else Present (First_Formal (Proc))
1850 then
1851 Error_Pragma_Arg
1852 ("argument of pragma% must be parameterless procedure", Arg);
1853 end if;
1855 else
1856 declare
1857 Found : Boolean := False;
1858 It : Interp;
1859 Index : Interp_Index;
1861 begin
1862 Get_First_Interp (Name, Index, It);
1863 while Present (It.Nam) loop
1864 Proc := It.Nam;
1866 if Ekind (Proc) = E_Procedure
1867 and then No (First_Formal (Proc))
1868 then
1869 if not Found then
1870 Found := True;
1871 Set_Entity (Name, Proc);
1872 Set_Is_Overloaded (Name, False);
1873 else
1874 Error_Pragma_Arg
1875 ("ambiguous handler name for pragma% ", Arg);
1876 end if;
1877 end if;
1879 Get_Next_Interp (Index, It);
1880 end loop;
1882 if not Found then
1883 Error_Pragma_Arg
1884 ("argument of pragma% must be parameterless procedure",
1885 Arg);
1886 else
1887 Proc := Entity (Name);
1888 end if;
1889 end;
1890 end if;
1892 return Proc;
1893 end Find_Unique_Parameterless_Procedure;
1895 -------------------------
1896 -- Gather_Associations --
1897 -------------------------
1899 procedure Gather_Associations
1900 (Names : Name_List;
1901 Args : out Args_List)
1903 Arg : Node_Id;
1905 begin
1906 -- Initialize all parameters to Empty
1908 for J in Args'Range loop
1909 Args (J) := Empty;
1910 end loop;
1912 -- That's all we have to do if there are no argument associations
1914 if No (Pragma_Argument_Associations (N)) then
1915 return;
1916 end if;
1918 -- Otherwise first deal with any positional parameters present
1920 Arg := First (Pragma_Argument_Associations (N));
1921 for Index in Args'Range loop
1922 exit when No (Arg) or else Chars (Arg) /= No_Name;
1923 Args (Index) := Expression (Arg);
1924 Next (Arg);
1925 end loop;
1927 -- Positional parameters all processed, if any left, then we
1928 -- have too many positional parameters.
1930 if Present (Arg) and then Chars (Arg) = No_Name then
1931 Error_Pragma_Arg
1932 ("too many positional associations for pragma%", Arg);
1933 end if;
1935 -- Process named parameters if any are present
1937 while Present (Arg) loop
1938 if Chars (Arg) = No_Name then
1939 Error_Pragma_Arg
1940 ("positional association cannot follow named association",
1941 Arg);
1943 else
1944 for Index in Names'Range loop
1945 if Names (Index) = Chars (Arg) then
1946 if Present (Args (Index)) then
1947 Error_Pragma_Arg
1948 ("duplicate argument association for pragma%", Arg);
1949 else
1950 Args (Index) := Expression (Arg);
1951 exit;
1952 end if;
1953 end if;
1955 if Index = Names'Last then
1956 Error_Msg_Name_1 := Pname;
1957 Error_Msg_N ("pragma% does not allow & argument", Arg);
1959 -- Check for possible misspelling
1961 for Index1 in Names'Range loop
1962 if Is_Bad_Spelling_Of
1963 (Chars (Arg), Names (Index1))
1964 then
1965 Error_Msg_Name_1 := Names (Index1);
1966 Error_Msg_N -- CODEFIX
1967 ("\possible misspelling of%", Arg);
1968 exit;
1969 end if;
1970 end loop;
1972 raise Pragma_Exit;
1973 end if;
1974 end loop;
1975 end if;
1977 Next (Arg);
1978 end loop;
1979 end Gather_Associations;
1981 -----------------
1982 -- GNAT_Pragma --
1983 -----------------
1985 procedure GNAT_Pragma is
1986 begin
1987 Check_Restriction (No_Implementation_Pragmas, N);
1988 end GNAT_Pragma;
1990 --------------------------
1991 -- Is_Before_First_Decl --
1992 --------------------------
1994 function Is_Before_First_Decl
1995 (Pragma_Node : Node_Id;
1996 Decls : List_Id) return Boolean
1998 Item : Node_Id := First (Decls);
2000 begin
2001 -- Only other pragmas can come before this pragma
2003 loop
2004 if No (Item) or else Nkind (Item) /= N_Pragma then
2005 return False;
2007 elsif Item = Pragma_Node then
2008 return True;
2009 end if;
2011 Next (Item);
2012 end loop;
2013 end Is_Before_First_Decl;
2015 -----------------------------
2016 -- Is_Configuration_Pragma --
2017 -----------------------------
2019 -- A configuration pragma must appear in the context clause of a
2020 -- compilation unit, and only other pragmas may precede it. Note that
2021 -- the test below also permits use in a configuration pragma file.
2023 function Is_Configuration_Pragma return Boolean is
2024 Lis : constant List_Id := List_Containing (N);
2025 Par : constant Node_Id := Parent (N);
2026 Prg : Node_Id;
2028 begin
2029 -- If no parent, then we are in the configuration pragma file,
2030 -- so the placement is definitely appropriate.
2032 if No (Par) then
2033 return True;
2035 -- Otherwise we must be in the context clause of a compilation unit
2036 -- and the only thing allowed before us in the context list is more
2037 -- configuration pragmas.
2039 elsif Nkind (Par) = N_Compilation_Unit
2040 and then Context_Items (Par) = Lis
2041 then
2042 Prg := First (Lis);
2044 loop
2045 if Prg = N then
2046 return True;
2047 elsif Nkind (Prg) /= N_Pragma then
2048 return False;
2049 end if;
2051 Next (Prg);
2052 end loop;
2054 else
2055 return False;
2056 end if;
2057 end Is_Configuration_Pragma;
2059 --------------------------
2060 -- Is_In_Context_Clause --
2061 --------------------------
2063 function Is_In_Context_Clause return Boolean is
2064 Plist : List_Id;
2065 Parent_Node : Node_Id;
2067 begin
2068 if not Is_List_Member (N) then
2069 return False;
2071 else
2072 Plist := List_Containing (N);
2073 Parent_Node := Parent (Plist);
2075 if Parent_Node = Empty
2076 or else Nkind (Parent_Node) /= N_Compilation_Unit
2077 or else Context_Items (Parent_Node) /= Plist
2078 then
2079 return False;
2080 end if;
2081 end if;
2083 return True;
2084 end Is_In_Context_Clause;
2086 ---------------------------------
2087 -- Is_Static_String_Expression --
2088 ---------------------------------
2090 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2091 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2093 begin
2094 Analyze_And_Resolve (Argx);
2095 return Is_OK_Static_Expression (Argx)
2096 and then Nkind (Argx) = N_String_Literal;
2097 end Is_Static_String_Expression;
2099 ----------------------
2100 -- Pragma_Misplaced --
2101 ----------------------
2103 procedure Pragma_Misplaced is
2104 begin
2105 Error_Pragma ("incorrect placement of pragma%");
2106 end Pragma_Misplaced;
2108 ------------------------------------
2109 -- Process Atomic_Shared_Volatile --
2110 ------------------------------------
2112 procedure Process_Atomic_Shared_Volatile is
2113 E_Id : Node_Id;
2114 E : Entity_Id;
2115 D : Node_Id;
2116 K : Node_Kind;
2117 Utyp : Entity_Id;
2119 procedure Set_Atomic (E : Entity_Id);
2120 -- Set given type as atomic, and if no explicit alignment was given,
2121 -- set alignment to unknown, since back end knows what the alignment
2122 -- requirements are for atomic arrays. Note: this step is necessary
2123 -- for derived types.
2125 ----------------
2126 -- Set_Atomic --
2127 ----------------
2129 procedure Set_Atomic (E : Entity_Id) is
2130 begin
2131 Set_Is_Atomic (E);
2133 if not Has_Alignment_Clause (E) then
2134 Set_Alignment (E, Uint_0);
2135 end if;
2136 end Set_Atomic;
2138 -- Start of processing for Process_Atomic_Shared_Volatile
2140 begin
2141 Check_Ada_83_Warning;
2142 Check_No_Identifiers;
2143 Check_Arg_Count (1);
2144 Check_Arg_Is_Local_Name (Arg1);
2145 E_Id := Expression (Arg1);
2147 if Etype (E_Id) = Any_Type then
2148 return;
2149 end if;
2151 E := Entity (E_Id);
2152 D := Declaration_Node (E);
2153 K := Nkind (D);
2155 if Is_Type (E) then
2156 if Rep_Item_Too_Early (E, N)
2157 or else
2158 Rep_Item_Too_Late (E, N)
2159 then
2160 return;
2161 else
2162 Check_First_Subtype (Arg1);
2163 end if;
2165 if Prag_Id /= Pragma_Volatile then
2166 Set_Atomic (E);
2167 Set_Atomic (Underlying_Type (E));
2168 Set_Atomic (Base_Type (E));
2169 end if;
2171 -- Attribute belongs on the base type. If the view of the type is
2172 -- currently private, it also belongs on the underlying type.
2174 Set_Is_Volatile (Base_Type (E));
2175 Set_Is_Volatile (Underlying_Type (E));
2177 Set_Treat_As_Volatile (E);
2178 Set_Treat_As_Volatile (Underlying_Type (E));
2180 elsif K = N_Object_Declaration
2181 or else (K = N_Component_Declaration
2182 and then Original_Record_Component (E) = E)
2183 then
2184 if Rep_Item_Too_Late (E, N) then
2185 return;
2186 end if;
2188 if Prag_Id /= Pragma_Volatile then
2189 Set_Is_Atomic (E);
2191 -- If the object declaration has an explicit initialization, a
2192 -- temporary may have to be created to hold the expression, to
2193 -- ensure that access to the object remain atomic.
2195 if Nkind (Parent (E)) = N_Object_Declaration
2196 and then Present (Expression (Parent (E)))
2197 then
2198 Set_Has_Delayed_Freeze (E);
2199 end if;
2201 -- An interesting improvement here. If an object of type X is
2202 -- declared atomic, and the type X is not atomic, that's a
2203 -- pity, since it may not have appropriate alignment etc. We
2204 -- can rescue this in the special case where the object and
2205 -- type are in the same unit by just setting the type as
2206 -- atomic, so that the back end will process it as atomic.
2208 Utyp := Underlying_Type (Etype (E));
2210 if Present (Utyp)
2211 and then Sloc (E) > No_Location
2212 and then Sloc (Utyp) > No_Location
2213 and then
2214 Get_Source_File_Index (Sloc (E)) =
2215 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2216 then
2217 Set_Is_Atomic (Underlying_Type (Etype (E)));
2218 end if;
2219 end if;
2221 Set_Is_Volatile (E);
2222 Set_Treat_As_Volatile (E);
2224 else
2225 Error_Pragma_Arg
2226 ("inappropriate entity for pragma%", Arg1);
2227 end if;
2228 end Process_Atomic_Shared_Volatile;
2230 -------------------------------------------
2231 -- Process_Compile_Time_Warning_Or_Error --
2232 -------------------------------------------
2234 procedure Process_Compile_Time_Warning_Or_Error is
2235 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2237 begin
2238 Check_Arg_Count (2);
2239 Check_No_Identifiers;
2240 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2241 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2243 if Compile_Time_Known_Value (Arg1x) then
2244 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2245 declare
2246 Str : constant String_Id :=
2247 Strval (Get_Pragma_Arg (Arg2));
2248 Len : constant Int := String_Length (Str);
2249 Cont : Boolean;
2250 Ptr : Nat;
2251 CC : Char_Code;
2252 C : Character;
2253 Cent : constant Entity_Id :=
2254 Cunit_Entity (Current_Sem_Unit);
2256 Force : constant Boolean :=
2257 Prag_Id = Pragma_Compile_Time_Warning
2258 and then
2259 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2260 and then (Ekind (Cent) /= E_Package
2261 or else not In_Private_Part (Cent));
2262 -- Set True if this is the warning case, and we are in the
2263 -- visible part of a package spec, or in a subprogram spec,
2264 -- in which case we want to force the client to see the
2265 -- warning, even though it is not in the main unit.
2267 begin
2268 -- Loop through segments of message separated by line feeds.
2269 -- We output these segments as separate messages with
2270 -- continuation marks for all but the first.
2272 Cont := False;
2273 Ptr := 1;
2274 loop
2275 Error_Msg_Strlen := 0;
2277 -- Loop to copy characters from argument to error message
2278 -- string buffer.
2280 loop
2281 exit when Ptr > Len;
2282 CC := Get_String_Char (Str, Ptr);
2283 Ptr := Ptr + 1;
2285 -- Ignore wide chars ??? else store character
2287 if In_Character_Range (CC) then
2288 C := Get_Character (CC);
2289 exit when C = ASCII.LF;
2290 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2291 Error_Msg_String (Error_Msg_Strlen) := C;
2292 end if;
2293 end loop;
2295 -- Here with one line ready to go
2297 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2299 -- If this is a warning in a spec, then we want clients
2300 -- to see the warning, so mark the message with the
2301 -- special sequence !! to force the warning. In the case
2302 -- of a package spec, we do not force this if we are in
2303 -- the private part of the spec.
2305 if Force then
2306 if Cont = False then
2307 Error_Msg_N ("<~!!", Arg1);
2308 Cont := True;
2309 else
2310 Error_Msg_N ("\<~!!", Arg1);
2311 end if;
2313 -- Error, rather than warning, or in a body, so we do not
2314 -- need to force visibility for client (error will be
2315 -- output in any case, and this is the situation in which
2316 -- we do not want a client to get a warning, since the
2317 -- warning is in the body or the spec private part.
2319 else
2320 if Cont = False then
2321 Error_Msg_N ("<~", Arg1);
2322 Cont := True;
2323 else
2324 Error_Msg_N ("\<~", Arg1);
2325 end if;
2326 end if;
2328 exit when Ptr > Len;
2329 end loop;
2330 end;
2331 end if;
2332 end if;
2333 end Process_Compile_Time_Warning_Or_Error;
2335 ------------------------
2336 -- Process_Convention --
2337 ------------------------
2339 procedure Process_Convention
2340 (C : out Convention_Id;
2341 Ent : out Entity_Id)
2343 Id : Node_Id;
2344 E : Entity_Id;
2345 E1 : Entity_Id;
2346 Cname : Name_Id;
2347 Comp_Unit : Unit_Number_Type;
2349 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2350 -- Called if we have more than one Export/Import/Convention pragma.
2351 -- This is generally illegal, but we have a special case of allowing
2352 -- Import and Interface to coexist if they specify the convention in
2353 -- a consistent manner. We are allowed to do this, since Interface is
2354 -- an implementation defined pragma, and we choose to do it since we
2355 -- know Rational allows this combination. S is the entity id of the
2356 -- subprogram in question. This procedure also sets the special flag
2357 -- Import_Interface_Present in both pragmas in the case where we do
2358 -- have matching Import and Interface pragmas.
2360 procedure Set_Convention_From_Pragma (E : Entity_Id);
2361 -- Set convention in entity E, and also flag that the entity has a
2362 -- convention pragma. If entity is for a private or incomplete type,
2363 -- also set convention and flag on underlying type. This procedure
2364 -- also deals with the special case of C_Pass_By_Copy convention.
2366 -------------------------------
2367 -- Diagnose_Multiple_Pragmas --
2368 -------------------------------
2370 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2371 Pdec : constant Node_Id := Declaration_Node (S);
2372 Decl : Node_Id;
2373 Err : Boolean;
2375 function Same_Convention (Decl : Node_Id) return Boolean;
2376 -- Decl is a pragma node. This function returns True if this
2377 -- pragma has a first argument that is an identifier with a
2378 -- Chars field corresponding to the Convention_Id C.
2380 function Same_Name (Decl : Node_Id) return Boolean;
2381 -- Decl is a pragma node. This function returns True if this
2382 -- pragma has a second argument that is an identifier with a
2383 -- Chars field that matches the Chars of the current subprogram.
2385 ---------------------
2386 -- Same_Convention --
2387 ---------------------
2389 function Same_Convention (Decl : Node_Id) return Boolean is
2390 Arg1 : constant Node_Id :=
2391 First (Pragma_Argument_Associations (Decl));
2393 begin
2394 if Present (Arg1) then
2395 declare
2396 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2397 begin
2398 if Nkind (Arg) = N_Identifier
2399 and then Is_Convention_Name (Chars (Arg))
2400 and then Get_Convention_Id (Chars (Arg)) = C
2401 then
2402 return True;
2403 end if;
2404 end;
2405 end if;
2407 return False;
2408 end Same_Convention;
2410 ---------------
2411 -- Same_Name --
2412 ---------------
2414 function Same_Name (Decl : Node_Id) return Boolean is
2415 Arg1 : constant Node_Id :=
2416 First (Pragma_Argument_Associations (Decl));
2417 Arg2 : Node_Id;
2419 begin
2420 if No (Arg1) then
2421 return False;
2422 end if;
2424 Arg2 := Next (Arg1);
2426 if No (Arg2) then
2427 return False;
2428 end if;
2430 declare
2431 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2432 begin
2433 if Nkind (Arg) = N_Identifier
2434 and then Chars (Arg) = Chars (S)
2435 then
2436 return True;
2437 end if;
2438 end;
2440 return False;
2441 end Same_Name;
2443 -- Start of processing for Diagnose_Multiple_Pragmas
2445 begin
2446 Err := True;
2448 -- Definitely give message if we have Convention/Export here
2450 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
2451 null;
2453 -- If we have an Import or Export, scan back from pragma to
2454 -- find any previous pragma applying to the same procedure.
2455 -- The scan will be terminated by the start of the list, or
2456 -- hitting the subprogram declaration. This won't allow one
2457 -- pragma to appear in the public part and one in the private
2458 -- part, but that seems very unlikely in practice.
2460 else
2461 Decl := Prev (N);
2462 while Present (Decl) and then Decl /= Pdec loop
2464 -- Look for pragma with same name as us
2466 if Nkind (Decl) = N_Pragma
2467 and then Same_Name (Decl)
2468 then
2469 -- Give error if same as our pragma or Export/Convention
2471 if Pragma_Name (Decl) = Name_Export
2472 or else
2473 Pragma_Name (Decl) = Name_Convention
2474 or else
2475 Pragma_Name (Decl) = Pragma_Name (N)
2476 then
2477 exit;
2479 -- Case of Import/Interface or the other way round
2481 elsif Pragma_Name (Decl) = Name_Interface
2482 or else
2483 Pragma_Name (Decl) = Name_Import
2484 then
2485 -- Here we know that we have Import and Interface. It
2486 -- doesn't matter which way round they are. See if
2487 -- they specify the same convention. If so, all OK,
2488 -- and set special flags to stop other messages
2490 if Same_Convention (Decl) then
2491 Set_Import_Interface_Present (N);
2492 Set_Import_Interface_Present (Decl);
2493 Err := False;
2495 -- If different conventions, special message
2497 else
2498 Error_Msg_Sloc := Sloc (Decl);
2499 Error_Pragma_Arg
2500 ("convention differs from that given#", Arg1);
2501 return;
2502 end if;
2503 end if;
2504 end if;
2506 Next (Decl);
2507 end loop;
2508 end if;
2510 -- Give message if needed if we fall through those tests
2512 if Err then
2513 Error_Pragma_Arg
2514 ("at most one Convention/Export/Import pragma is allowed",
2515 Arg2);
2516 end if;
2517 end Diagnose_Multiple_Pragmas;
2519 --------------------------------
2520 -- Set_Convention_From_Pragma --
2521 --------------------------------
2523 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2524 begin
2525 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2526 -- for an overridden dispatching operation. Technically this is
2527 -- an amendment and should only be done in Ada 2005 mode. However,
2528 -- this is clearly a mistake, since the problem that is addressed
2529 -- by this AI is that there is a clear gap in the RM!
2531 if Is_Dispatching_Operation (E)
2532 and then Present (Overridden_Operation (E))
2533 and then C /= Convention (Overridden_Operation (E))
2534 then
2535 Error_Pragma_Arg
2536 ("cannot change convention for " &
2537 "overridden dispatching operation",
2538 Arg1);
2539 end if;
2541 -- Set the convention
2543 Set_Convention (E, C);
2544 Set_Has_Convention_Pragma (E);
2546 if Is_Incomplete_Or_Private_Type (E) then
2547 Set_Convention (Underlying_Type (E), C);
2548 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2549 end if;
2551 -- A class-wide type should inherit the convention of the specific
2552 -- root type (although this isn't specified clearly by the RM).
2554 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2555 Set_Convention (Class_Wide_Type (E), C);
2556 end if;
2558 -- If the entity is a record type, then check for special case of
2559 -- C_Pass_By_Copy, which is treated the same as C except that the
2560 -- special record flag is set. This convention is only permitted
2561 -- on record types (see AI95-00131).
2563 if Cname = Name_C_Pass_By_Copy then
2564 if Is_Record_Type (E) then
2565 Set_C_Pass_By_Copy (Base_Type (E));
2566 elsif Is_Incomplete_Or_Private_Type (E)
2567 and then Is_Record_Type (Underlying_Type (E))
2568 then
2569 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2570 else
2571 Error_Pragma_Arg
2572 ("C_Pass_By_Copy convention allowed only for record type",
2573 Arg2);
2574 end if;
2575 end if;
2577 -- If the entity is a derived boolean type, check for the special
2578 -- case of convention C, C++, or Fortran, where we consider any
2579 -- nonzero value to represent true.
2581 if Is_Discrete_Type (E)
2582 and then Root_Type (Etype (E)) = Standard_Boolean
2583 and then
2584 (C = Convention_C
2585 or else
2586 C = Convention_CPP
2587 or else
2588 C = Convention_Fortran)
2589 then
2590 Set_Nonzero_Is_True (Base_Type (E));
2591 end if;
2592 end Set_Convention_From_Pragma;
2594 -- Start of processing for Process_Convention
2596 begin
2597 Check_At_Least_N_Arguments (2);
2598 Check_Optional_Identifier (Arg1, Name_Convention);
2599 Check_Arg_Is_Identifier (Arg1);
2600 Cname := Chars (Expression (Arg1));
2602 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2603 -- tested again below to set the critical flag).
2604 if Cname = Name_C_Pass_By_Copy then
2605 C := Convention_C;
2607 -- Otherwise we must have something in the standard convention list
2609 elsif Is_Convention_Name (Cname) then
2610 C := Get_Convention_Id (Chars (Expression (Arg1)));
2612 -- In DEC VMS, it seems that there is an undocumented feature that
2613 -- any unrecognized convention is treated as the default, which for
2614 -- us is convention C. It does not seem so terrible to do this
2615 -- unconditionally, silently in the VMS case, and with a warning
2616 -- in the non-VMS case.
2618 else
2619 if Warn_On_Export_Import and not OpenVMS_On_Target then
2620 Error_Msg_N
2621 ("?unrecognized convention name, C assumed",
2622 Expression (Arg1));
2623 end if;
2625 C := Convention_C;
2626 end if;
2628 Check_Optional_Identifier (Arg2, Name_Entity);
2629 Check_Arg_Is_Local_Name (Arg2);
2631 Id := Expression (Arg2);
2632 Analyze (Id);
2634 if not Is_Entity_Name (Id) then
2635 Error_Pragma_Arg ("entity name required", Arg2);
2636 end if;
2638 E := Entity (Id);
2640 -- Set entity to return
2642 Ent := E;
2644 -- Go to renamed subprogram if present, since convention applies to
2645 -- the actual renamed entity, not to the renaming entity. If the
2646 -- subprogram is inherited, go to parent subprogram.
2648 if Is_Subprogram (E)
2649 and then Present (Alias (E))
2650 then
2651 if Nkind (Parent (Declaration_Node (E))) =
2652 N_Subprogram_Renaming_Declaration
2653 then
2654 if Scope (E) /= Scope (Alias (E)) then
2655 Error_Pragma_Ref
2656 ("cannot apply pragma% to non-local entity&#", E);
2657 end if;
2659 E := Alias (E);
2661 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
2662 N_Private_Extension_Declaration)
2663 and then Scope (E) = Scope (Alias (E))
2664 then
2665 E := Alias (E);
2667 -- Return the parent subprogram the entity was inherited from
2669 Ent := E;
2670 end if;
2671 end if;
2673 -- Check that we are not applying this to a specless body
2675 if Is_Subprogram (E)
2676 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2677 then
2678 Error_Pragma
2679 ("pragma% requires separate spec and must come before body");
2680 end if;
2682 -- Check that we are not applying this to a named constant
2684 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
2685 Error_Msg_Name_1 := Pname;
2686 Error_Msg_N
2687 ("cannot apply pragma% to named constant!",
2688 Get_Pragma_Arg (Arg2));
2689 Error_Pragma_Arg
2690 ("\supply appropriate type for&!", Arg2);
2691 end if;
2693 if Ekind (E) = E_Enumeration_Literal then
2694 Error_Pragma ("enumeration literal not allowed for pragma%");
2695 end if;
2697 -- Check for rep item appearing too early or too late
2699 if Etype (E) = Any_Type
2700 or else Rep_Item_Too_Early (E, N)
2701 then
2702 raise Pragma_Exit;
2703 else
2704 E := Underlying_Type (E);
2705 end if;
2707 if Rep_Item_Too_Late (E, N) then
2708 raise Pragma_Exit;
2709 end if;
2711 if Has_Convention_Pragma (E) then
2712 Diagnose_Multiple_Pragmas (E);
2714 elsif Convention (E) = Convention_Protected
2715 or else Ekind (Scope (E)) = E_Protected_Type
2716 then
2717 Error_Pragma_Arg
2718 ("a protected operation cannot be given a different convention",
2719 Arg2);
2720 end if;
2722 -- For Intrinsic, a subprogram is required
2724 if C = Convention_Intrinsic
2725 and then not Is_Subprogram (E)
2726 and then not Is_Generic_Subprogram (E)
2727 then
2728 Error_Pragma_Arg
2729 ("second argument of pragma% must be a subprogram", Arg2);
2730 end if;
2732 -- For Stdcall, a subprogram, variable or subprogram type is required
2734 if C = Convention_Stdcall
2735 and then not Is_Subprogram (E)
2736 and then not Is_Generic_Subprogram (E)
2737 and then Ekind (E) /= E_Variable
2738 and then not
2739 (Is_Access_Type (E)
2740 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2741 then
2742 Error_Pragma_Arg
2743 ("second argument of pragma% must be subprogram (type)",
2744 Arg2);
2745 end if;
2747 if not Is_Subprogram (E)
2748 and then not Is_Generic_Subprogram (E)
2749 then
2750 Set_Convention_From_Pragma (E);
2752 if Is_Type (E) then
2753 Check_First_Subtype (Arg2);
2754 Set_Convention_From_Pragma (Base_Type (E));
2756 -- For subprograms, we must set the convention on the
2757 -- internally generated directly designated type as well.
2759 if Ekind (E) = E_Access_Subprogram_Type then
2760 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2761 end if;
2762 end if;
2764 -- For the subprogram case, set proper convention for all homonyms
2765 -- in same scope and the same declarative part, i.e. the same
2766 -- compilation unit.
2768 else
2769 Comp_Unit := Get_Source_Unit (E);
2770 Set_Convention_From_Pragma (E);
2772 -- Treat a pragma Import as an implicit body, for GPS use
2774 if Prag_Id = Pragma_Import then
2775 Generate_Reference (E, Id, 'b');
2776 end if;
2778 -- Loop through the homonyms of the pragma argument's entity
2780 E1 := Ent;
2781 loop
2782 E1 := Homonym (E1);
2783 exit when No (E1) or else Scope (E1) /= Current_Scope;
2785 -- Do not set the pragma on inherited operations or on formal
2786 -- subprograms.
2788 if Comes_From_Source (E1)
2789 and then Comp_Unit = Get_Source_Unit (E1)
2790 and then not Is_Formal_Subprogram (E1)
2791 and then Nkind (Original_Node (Parent (E1))) /=
2792 N_Full_Type_Declaration
2793 then
2794 if Present (Alias (E1))
2795 and then Scope (E1) /= Scope (Alias (E1))
2796 then
2797 Error_Pragma_Ref
2798 ("cannot apply pragma% to non-local entity& declared#",
2799 E1);
2800 end if;
2802 Set_Convention_From_Pragma (E1);
2804 if Prag_Id = Pragma_Import then
2805 Generate_Reference (E1, Id, 'b');
2806 end if;
2807 end if;
2808 end loop;
2809 end if;
2810 end Process_Convention;
2812 -----------------------------------------------------
2813 -- Process_Extended_Import_Export_Exception_Pragma --
2814 -----------------------------------------------------
2816 procedure Process_Extended_Import_Export_Exception_Pragma
2817 (Arg_Internal : Node_Id;
2818 Arg_External : Node_Id;
2819 Arg_Form : Node_Id;
2820 Arg_Code : Node_Id)
2822 Def_Id : Entity_Id;
2823 Code_Val : Uint;
2825 begin
2826 if not OpenVMS_On_Target then
2827 Error_Pragma
2828 ("?pragma% ignored (applies only to Open'V'M'S)");
2829 end if;
2831 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2832 Def_Id := Entity (Arg_Internal);
2834 if Ekind (Def_Id) /= E_Exception then
2835 Error_Pragma_Arg
2836 ("pragma% must refer to declared exception", Arg_Internal);
2837 end if;
2839 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2841 if Present (Arg_Form) then
2842 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2843 end if;
2845 if Present (Arg_Form)
2846 and then Chars (Arg_Form) = Name_Ada
2847 then
2848 null;
2849 else
2850 Set_Is_VMS_Exception (Def_Id);
2851 Set_Exception_Code (Def_Id, No_Uint);
2852 end if;
2854 if Present (Arg_Code) then
2855 if not Is_VMS_Exception (Def_Id) then
2856 Error_Pragma_Arg
2857 ("Code option for pragma% not allowed for Ada case",
2858 Arg_Code);
2859 end if;
2861 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2862 Code_Val := Expr_Value (Arg_Code);
2864 if not UI_Is_In_Int_Range (Code_Val) then
2865 Error_Pragma_Arg
2866 ("Code option for pragma% must be in 32-bit range",
2867 Arg_Code);
2869 else
2870 Set_Exception_Code (Def_Id, Code_Val);
2871 end if;
2872 end if;
2873 end Process_Extended_Import_Export_Exception_Pragma;
2875 -------------------------------------------------
2876 -- Process_Extended_Import_Export_Internal_Arg --
2877 -------------------------------------------------
2879 procedure Process_Extended_Import_Export_Internal_Arg
2880 (Arg_Internal : Node_Id := Empty)
2882 begin
2883 if No (Arg_Internal) then
2884 Error_Pragma ("Internal parameter required for pragma%");
2885 end if;
2887 if Nkind (Arg_Internal) = N_Identifier then
2888 null;
2890 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2891 and then (Prag_Id = Pragma_Import_Function
2892 or else
2893 Prag_Id = Pragma_Export_Function)
2894 then
2895 null;
2897 else
2898 Error_Pragma_Arg
2899 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2900 end if;
2902 Check_Arg_Is_Local_Name (Arg_Internal);
2903 end Process_Extended_Import_Export_Internal_Arg;
2905 --------------------------------------------------
2906 -- Process_Extended_Import_Export_Object_Pragma --
2907 --------------------------------------------------
2909 procedure Process_Extended_Import_Export_Object_Pragma
2910 (Arg_Internal : Node_Id;
2911 Arg_External : Node_Id;
2912 Arg_Size : Node_Id)
2914 Def_Id : Entity_Id;
2916 begin
2917 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2918 Def_Id := Entity (Arg_Internal);
2920 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
2921 Error_Pragma_Arg
2922 ("pragma% must designate an object", Arg_Internal);
2923 end if;
2925 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2926 or else
2927 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2928 then
2929 Error_Pragma_Arg
2930 ("previous Common/Psect_Object applies, pragma % not permitted",
2931 Arg_Internal);
2932 end if;
2934 if Rep_Item_Too_Late (Def_Id, N) then
2935 raise Pragma_Exit;
2936 end if;
2938 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2940 if Present (Arg_Size) then
2941 Check_Arg_Is_External_Name (Arg_Size);
2942 end if;
2944 -- Export_Object case
2946 if Prag_Id = Pragma_Export_Object then
2947 if not Is_Library_Level_Entity (Def_Id) then
2948 Error_Pragma_Arg
2949 ("argument for pragma% must be library level entity",
2950 Arg_Internal);
2951 end if;
2953 if Ekind (Current_Scope) = E_Generic_Package then
2954 Error_Pragma ("pragma& cannot appear in a generic unit");
2955 end if;
2957 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2958 Error_Pragma_Arg
2959 ("exported object must have compile time known size",
2960 Arg_Internal);
2961 end if;
2963 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2964 Error_Msg_N ("?duplicate Export_Object pragma", N);
2965 else
2966 Set_Exported (Def_Id, Arg_Internal);
2967 end if;
2969 -- Import_Object case
2971 else
2972 if Is_Concurrent_Type (Etype (Def_Id)) then
2973 Error_Pragma_Arg
2974 ("cannot use pragma% for task/protected object",
2975 Arg_Internal);
2976 end if;
2978 if Ekind (Def_Id) = E_Constant then
2979 Error_Pragma_Arg
2980 ("cannot import a constant", Arg_Internal);
2981 end if;
2983 if Warn_On_Export_Import
2984 and then Has_Discriminants (Etype (Def_Id))
2985 then
2986 Error_Msg_N
2987 ("imported value must be initialized?", Arg_Internal);
2988 end if;
2990 if Warn_On_Export_Import
2991 and then Is_Access_Type (Etype (Def_Id))
2992 then
2993 Error_Pragma_Arg
2994 ("cannot import object of an access type?", Arg_Internal);
2995 end if;
2997 if Warn_On_Export_Import
2998 and then Is_Imported (Def_Id)
2999 then
3000 Error_Msg_N
3001 ("?duplicate Import_Object pragma", N);
3003 -- Check for explicit initialization present. Note that an
3004 -- initialization generated by the code generator, e.g. for an
3005 -- access type, does not count here.
3007 elsif Present (Expression (Parent (Def_Id)))
3008 and then
3009 Comes_From_Source
3010 (Original_Node (Expression (Parent (Def_Id))))
3011 then
3012 Error_Msg_Sloc := Sloc (Def_Id);
3013 Error_Pragma_Arg
3014 ("imported entities cannot be initialized (RM B.1(24))",
3015 "\no initialization allowed for & declared#", Arg1);
3016 else
3017 Set_Imported (Def_Id);
3018 Note_Possible_Modification (Arg_Internal, Sure => False);
3019 end if;
3020 end if;
3021 end Process_Extended_Import_Export_Object_Pragma;
3023 ------------------------------------------------------
3024 -- Process_Extended_Import_Export_Subprogram_Pragma --
3025 ------------------------------------------------------
3027 procedure Process_Extended_Import_Export_Subprogram_Pragma
3028 (Arg_Internal : Node_Id;
3029 Arg_External : Node_Id;
3030 Arg_Parameter_Types : Node_Id;
3031 Arg_Result_Type : Node_Id := Empty;
3032 Arg_Mechanism : Node_Id;
3033 Arg_Result_Mechanism : Node_Id := Empty;
3034 Arg_First_Optional_Parameter : Node_Id := Empty)
3036 Ent : Entity_Id;
3037 Def_Id : Entity_Id;
3038 Hom_Id : Entity_Id;
3039 Formal : Entity_Id;
3040 Ambiguous : Boolean;
3041 Match : Boolean;
3042 Dval : Node_Id;
3044 function Same_Base_Type
3045 (Ptype : Node_Id;
3046 Formal : Entity_Id) return Boolean;
3047 -- Determines if Ptype references the type of Formal. Note that only
3048 -- the base types need to match according to the spec. Ptype here is
3049 -- the argument from the pragma, which is either a type name, or an
3050 -- access attribute.
3052 --------------------
3053 -- Same_Base_Type --
3054 --------------------
3056 function Same_Base_Type
3057 (Ptype : Node_Id;
3058 Formal : Entity_Id) return Boolean
3060 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3061 Pref : Node_Id;
3063 begin
3064 -- Case where pragma argument is typ'Access
3066 if Nkind (Ptype) = N_Attribute_Reference
3067 and then Attribute_Name (Ptype) = Name_Access
3068 then
3069 Pref := Prefix (Ptype);
3070 Find_Type (Pref);
3072 if not Is_Entity_Name (Pref)
3073 or else Entity (Pref) = Any_Type
3074 then
3075 raise Pragma_Exit;
3076 end if;
3078 -- We have a match if the corresponding argument is of an
3079 -- anonymous access type, and its designated type matches the
3080 -- type of the prefix of the access attribute
3082 return Ekind (Ftyp) = E_Anonymous_Access_Type
3083 and then Base_Type (Entity (Pref)) =
3084 Base_Type (Etype (Designated_Type (Ftyp)));
3086 -- Case where pragma argument is a type name
3088 else
3089 Find_Type (Ptype);
3091 if not Is_Entity_Name (Ptype)
3092 or else Entity (Ptype) = Any_Type
3093 then
3094 raise Pragma_Exit;
3095 end if;
3097 -- We have a match if the corresponding argument is of the type
3098 -- given in the pragma (comparing base types)
3100 return Base_Type (Entity (Ptype)) = Ftyp;
3101 end if;
3102 end Same_Base_Type;
3104 -- Start of processing for
3105 -- Process_Extended_Import_Export_Subprogram_Pragma
3107 begin
3108 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3109 Ent := Empty;
3110 Ambiguous := False;
3112 -- Loop through homonyms (overloadings) of the entity
3114 Hom_Id := Entity (Arg_Internal);
3115 while Present (Hom_Id) loop
3116 Def_Id := Get_Base_Subprogram (Hom_Id);
3118 -- We need a subprogram in the current scope
3120 if not Is_Subprogram (Def_Id)
3121 or else Scope (Def_Id) /= Current_Scope
3122 then
3123 null;
3125 else
3126 Match := True;
3128 -- Pragma cannot apply to subprogram body
3130 if Is_Subprogram (Def_Id)
3131 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3132 N_Subprogram_Body
3133 then
3134 Error_Pragma
3135 ("pragma% requires separate spec"
3136 & " and must come before body");
3137 end if;
3139 -- Test result type if given, note that the result type
3140 -- parameter can only be present for the function cases.
3142 if Present (Arg_Result_Type)
3143 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3144 then
3145 Match := False;
3147 elsif Etype (Def_Id) /= Standard_Void_Type
3148 and then
3149 (Pname = Name_Export_Procedure
3150 or else
3151 Pname = Name_Import_Procedure)
3152 then
3153 Match := False;
3155 -- Test parameter types if given. Note that this parameter
3156 -- has not been analyzed (and must not be, since it is
3157 -- semantic nonsense), so we get it as the parser left it.
3159 elsif Present (Arg_Parameter_Types) then
3160 Check_Matching_Types : declare
3161 Formal : Entity_Id;
3162 Ptype : Node_Id;
3164 begin
3165 Formal := First_Formal (Def_Id);
3167 if Nkind (Arg_Parameter_Types) = N_Null then
3168 if Present (Formal) then
3169 Match := False;
3170 end if;
3172 -- A list of one type, e.g. (List) is parsed as
3173 -- a parenthesized expression.
3175 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3176 and then Paren_Count (Arg_Parameter_Types) = 1
3177 then
3178 if No (Formal)
3179 or else Present (Next_Formal (Formal))
3180 then
3181 Match := False;
3182 else
3183 Match :=
3184 Same_Base_Type (Arg_Parameter_Types, Formal);
3185 end if;
3187 -- A list of more than one type is parsed as a aggregate
3189 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3190 and then Paren_Count (Arg_Parameter_Types) = 0
3191 then
3192 Ptype := First (Expressions (Arg_Parameter_Types));
3193 while Present (Ptype) or else Present (Formal) loop
3194 if No (Ptype)
3195 or else No (Formal)
3196 or else not Same_Base_Type (Ptype, Formal)
3197 then
3198 Match := False;
3199 exit;
3200 else
3201 Next_Formal (Formal);
3202 Next (Ptype);
3203 end if;
3204 end loop;
3206 -- Anything else is of the wrong form
3208 else
3209 Error_Pragma_Arg
3210 ("wrong form for Parameter_Types parameter",
3211 Arg_Parameter_Types);
3212 end if;
3213 end Check_Matching_Types;
3214 end if;
3216 -- Match is now False if the entry we found did not match
3217 -- either a supplied Parameter_Types or Result_Types argument
3219 if Match then
3220 if No (Ent) then
3221 Ent := Def_Id;
3223 -- Ambiguous case, the flag Ambiguous shows if we already
3224 -- detected this and output the initial messages.
3226 else
3227 if not Ambiguous then
3228 Ambiguous := True;
3229 Error_Msg_Name_1 := Pname;
3230 Error_Msg_N
3231 ("pragma% does not uniquely identify subprogram!",
3233 Error_Msg_Sloc := Sloc (Ent);
3234 Error_Msg_N ("matching subprogram #!", N);
3235 Ent := Empty;
3236 end if;
3238 Error_Msg_Sloc := Sloc (Def_Id);
3239 Error_Msg_N ("matching subprogram #!", N);
3240 end if;
3241 end if;
3242 end if;
3244 Hom_Id := Homonym (Hom_Id);
3245 end loop;
3247 -- See if we found an entry
3249 if No (Ent) then
3250 if not Ambiguous then
3251 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3252 Error_Pragma
3253 ("pragma% cannot be given for generic subprogram");
3254 else
3255 Error_Pragma
3256 ("pragma% does not identify local subprogram");
3257 end if;
3258 end if;
3260 return;
3261 end if;
3263 -- Import pragmas must be for imported entities
3265 if Prag_Id = Pragma_Import_Function
3266 or else
3267 Prag_Id = Pragma_Import_Procedure
3268 or else
3269 Prag_Id = Pragma_Import_Valued_Procedure
3270 then
3271 if not Is_Imported (Ent) then
3272 Error_Pragma
3273 ("pragma Import or Interface must precede pragma%");
3274 end if;
3276 -- Here we have the Export case which can set the entity as exported
3278 -- But does not do so if the specified external name is null, since
3279 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3280 -- compatible) to request no external name.
3282 elsif Nkind (Arg_External) = N_String_Literal
3283 and then String_Length (Strval (Arg_External)) = 0
3284 then
3285 null;
3287 -- In all other cases, set entity as exported
3289 else
3290 Set_Exported (Ent, Arg_Internal);
3291 end if;
3293 -- Special processing for Valued_Procedure cases
3295 if Prag_Id = Pragma_Import_Valued_Procedure
3296 or else
3297 Prag_Id = Pragma_Export_Valued_Procedure
3298 then
3299 Formal := First_Formal (Ent);
3301 if No (Formal) then
3302 Error_Pragma ("at least one parameter required for pragma%");
3304 elsif Ekind (Formal) /= E_Out_Parameter then
3305 Error_Pragma ("first parameter must have mode out for pragma%");
3307 else
3308 Set_Is_Valued_Procedure (Ent);
3309 end if;
3310 end if;
3312 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3314 -- Process Result_Mechanism argument if present. We have already
3315 -- checked that this is only allowed for the function case.
3317 if Present (Arg_Result_Mechanism) then
3318 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3319 end if;
3321 -- Process Mechanism parameter if present. Note that this parameter
3322 -- is not analyzed, and must not be analyzed since it is semantic
3323 -- nonsense, so we get it in exactly as the parser left it.
3325 if Present (Arg_Mechanism) then
3326 declare
3327 Formal : Entity_Id;
3328 Massoc : Node_Id;
3329 Mname : Node_Id;
3330 Choice : Node_Id;
3332 begin
3333 -- A single mechanism association without a formal parameter
3334 -- name is parsed as a parenthesized expression. All other
3335 -- cases are parsed as aggregates, so we rewrite the single
3336 -- parameter case as an aggregate for consistency.
3338 if Nkind (Arg_Mechanism) /= N_Aggregate
3339 and then Paren_Count (Arg_Mechanism) = 1
3340 then
3341 Rewrite (Arg_Mechanism,
3342 Make_Aggregate (Sloc (Arg_Mechanism),
3343 Expressions => New_List (
3344 Relocate_Node (Arg_Mechanism))));
3345 end if;
3347 -- Case of only mechanism name given, applies to all formals
3349 if Nkind (Arg_Mechanism) /= N_Aggregate then
3350 Formal := First_Formal (Ent);
3351 while Present (Formal) loop
3352 Set_Mechanism_Value (Formal, Arg_Mechanism);
3353 Next_Formal (Formal);
3354 end loop;
3356 -- Case of list of mechanism associations given
3358 else
3359 if Null_Record_Present (Arg_Mechanism) then
3360 Error_Pragma_Arg
3361 ("inappropriate form for Mechanism parameter",
3362 Arg_Mechanism);
3363 end if;
3365 -- Deal with positional ones first
3367 Formal := First_Formal (Ent);
3369 if Present (Expressions (Arg_Mechanism)) then
3370 Mname := First (Expressions (Arg_Mechanism));
3371 while Present (Mname) loop
3372 if No (Formal) then
3373 Error_Pragma_Arg
3374 ("too many mechanism associations", Mname);
3375 end if;
3377 Set_Mechanism_Value (Formal, Mname);
3378 Next_Formal (Formal);
3379 Next (Mname);
3380 end loop;
3381 end if;
3383 -- Deal with named entries
3385 if Present (Component_Associations (Arg_Mechanism)) then
3386 Massoc := First (Component_Associations (Arg_Mechanism));
3387 while Present (Massoc) loop
3388 Choice := First (Choices (Massoc));
3390 if Nkind (Choice) /= N_Identifier
3391 or else Present (Next (Choice))
3392 then
3393 Error_Pragma_Arg
3394 ("incorrect form for mechanism association",
3395 Massoc);
3396 end if;
3398 Formal := First_Formal (Ent);
3399 loop
3400 if No (Formal) then
3401 Error_Pragma_Arg
3402 ("parameter name & not present", Choice);
3403 end if;
3405 if Chars (Choice) = Chars (Formal) then
3406 Set_Mechanism_Value
3407 (Formal, Expression (Massoc));
3409 -- Set entity on identifier for ASIS
3411 Set_Entity (Choice, Formal);
3413 exit;
3414 end if;
3416 Next_Formal (Formal);
3417 end loop;
3419 Next (Massoc);
3420 end loop;
3421 end if;
3422 end if;
3423 end;
3424 end if;
3426 -- Process First_Optional_Parameter argument if present. We have
3427 -- already checked that this is only allowed for the Import case.
3429 if Present (Arg_First_Optional_Parameter) then
3430 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3431 Error_Pragma_Arg
3432 ("first optional parameter must be formal parameter name",
3433 Arg_First_Optional_Parameter);
3434 end if;
3436 Formal := First_Formal (Ent);
3437 loop
3438 if No (Formal) then
3439 Error_Pragma_Arg
3440 ("specified formal parameter& not found",
3441 Arg_First_Optional_Parameter);
3442 end if;
3444 exit when Chars (Formal) =
3445 Chars (Arg_First_Optional_Parameter);
3447 Next_Formal (Formal);
3448 end loop;
3450 Set_First_Optional_Parameter (Ent, Formal);
3452 -- Check specified and all remaining formals have right form
3454 while Present (Formal) loop
3455 if Ekind (Formal) /= E_In_Parameter then
3456 Error_Msg_NE
3457 ("optional formal& is not of mode in!",
3458 Arg_First_Optional_Parameter, Formal);
3460 else
3461 Dval := Default_Value (Formal);
3463 if No (Dval) then
3464 Error_Msg_NE
3465 ("optional formal& does not have default value!",
3466 Arg_First_Optional_Parameter, Formal);
3468 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3469 null;
3471 else
3472 Error_Msg_FE
3473 ("default value for optional formal& is non-static!",
3474 Arg_First_Optional_Parameter, Formal);
3475 end if;
3476 end if;
3478 Set_Is_Optional_Parameter (Formal);
3479 Next_Formal (Formal);
3480 end loop;
3481 end if;
3482 end Process_Extended_Import_Export_Subprogram_Pragma;
3484 --------------------------
3485 -- Process_Generic_List --
3486 --------------------------
3488 procedure Process_Generic_List is
3489 Arg : Node_Id;
3490 Exp : Node_Id;
3492 begin
3493 Check_No_Identifiers;
3494 Check_At_Least_N_Arguments (1);
3496 Arg := Arg1;
3497 while Present (Arg) loop
3498 Exp := Expression (Arg);
3499 Analyze (Exp);
3501 if not Is_Entity_Name (Exp)
3502 or else
3503 (not Is_Generic_Instance (Entity (Exp))
3504 and then
3505 not Is_Generic_Unit (Entity (Exp)))
3506 then
3507 Error_Pragma_Arg
3508 ("pragma% argument must be name of generic unit/instance",
3509 Arg);
3510 end if;
3512 Next (Arg);
3513 end loop;
3514 end Process_Generic_List;
3516 ---------------------------------
3517 -- Process_Import_Or_Interface --
3518 ---------------------------------
3520 procedure Process_Import_Or_Interface is
3521 C : Convention_Id;
3522 Def_Id : Entity_Id;
3523 Hom_Id : Entity_Id;
3525 begin
3526 Process_Convention (C, Def_Id);
3527 Kill_Size_Check_Code (Def_Id);
3528 Note_Possible_Modification (Expression (Arg2), Sure => False);
3530 if Ekind_In (Def_Id, E_Variable, E_Constant) then
3532 -- We do not permit Import to apply to a renaming declaration
3534 if Present (Renamed_Object (Def_Id)) then
3535 Error_Pragma_Arg
3536 ("pragma% not allowed for object renaming", Arg2);
3538 -- User initialization is not allowed for imported object, but
3539 -- the object declaration may contain a default initialization,
3540 -- that will be discarded. Note that an explicit initialization
3541 -- only counts if it comes from source, otherwise it is simply
3542 -- the code generator making an implicit initialization explicit.
3544 elsif Present (Expression (Parent (Def_Id)))
3545 and then Comes_From_Source (Expression (Parent (Def_Id)))
3546 then
3547 Error_Msg_Sloc := Sloc (Def_Id);
3548 Error_Pragma_Arg
3549 ("no initialization allowed for declaration of& #",
3550 "\imported entities cannot be initialized (RM B.1(24))",
3551 Arg2);
3553 else
3554 Set_Imported (Def_Id);
3555 Process_Interface_Name (Def_Id, Arg3, Arg4);
3557 -- Note that we do not set Is_Public here. That's because we
3558 -- only want to set it if there is no address clause, and we
3559 -- don't know that yet, so we delay that processing till
3560 -- freeze time.
3562 -- pragma Import completes deferred constants
3564 if Ekind (Def_Id) = E_Constant then
3565 Set_Has_Completion (Def_Id);
3566 end if;
3568 -- It is not possible to import a constant of an unconstrained
3569 -- array type (e.g. string) because there is no simple way to
3570 -- write a meaningful subtype for it.
3572 if Is_Array_Type (Etype (Def_Id))
3573 and then not Is_Constrained (Etype (Def_Id))
3574 then
3575 Error_Msg_NE
3576 ("imported constant& must have a constrained subtype",
3577 N, Def_Id);
3578 end if;
3579 end if;
3581 elsif Is_Subprogram (Def_Id)
3582 or else Is_Generic_Subprogram (Def_Id)
3583 then
3584 -- If the name is overloaded, pragma applies to all of the
3585 -- denoted entities in the same declarative part.
3587 Hom_Id := Def_Id;
3588 while Present (Hom_Id) loop
3589 Def_Id := Get_Base_Subprogram (Hom_Id);
3591 -- Ignore inherited subprograms because the pragma will
3592 -- apply to the parent operation, which is the one called.
3594 if Is_Overloadable (Def_Id)
3595 and then Present (Alias (Def_Id))
3596 then
3597 null;
3599 -- If it is not a subprogram, it must be in an outer scope and
3600 -- pragma does not apply.
3602 elsif not Is_Subprogram (Def_Id)
3603 and then not Is_Generic_Subprogram (Def_Id)
3604 then
3605 null;
3607 -- Verify that the homonym is in the same declarative part (not
3608 -- just the same scope).
3610 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3611 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3612 then
3613 exit;
3615 else
3616 Set_Imported (Def_Id);
3618 -- Reject an Import applied to an abstract subprogram
3620 if Is_Subprogram (Def_Id)
3621 and then Is_Abstract_Subprogram (Def_Id)
3622 then
3623 Error_Msg_Sloc := Sloc (Def_Id);
3624 Error_Msg_NE
3625 ("cannot import abstract subprogram& declared#",
3626 Arg2, Def_Id);
3627 end if;
3629 -- Special processing for Convention_Intrinsic
3631 if C = Convention_Intrinsic then
3633 -- Link_Name argument not allowed for intrinsic
3635 if Present (Arg3)
3636 and then Chars (Arg3) = Name_Link_Name
3637 then
3638 Arg4 := Arg3;
3639 end if;
3641 if Present (Arg4) then
3642 Error_Pragma_Arg
3643 ("Link_Name argument not allowed for " &
3644 "Import Intrinsic",
3645 Arg4);
3646 end if;
3648 Set_Is_Intrinsic_Subprogram (Def_Id);
3650 -- If no external name is present, then check that this
3651 -- is a valid intrinsic subprogram. If an external name
3652 -- is present, then this is handled by the back end.
3654 if No (Arg3) then
3655 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3656 end if;
3657 end if;
3659 -- All interfaced procedures need an external symbol created
3660 -- for them since they are always referenced from another
3661 -- object file.
3663 Set_Is_Public (Def_Id);
3665 -- Verify that the subprogram does not have a completion
3666 -- through a renaming declaration. For other completions the
3667 -- pragma appears as a too late representation.
3669 declare
3670 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3672 begin
3673 if Present (Decl)
3674 and then Nkind (Decl) = N_Subprogram_Declaration
3675 and then Present (Corresponding_Body (Decl))
3676 and then Nkind (Unit_Declaration_Node
3677 (Corresponding_Body (Decl))) =
3678 N_Subprogram_Renaming_Declaration
3679 then
3680 Error_Msg_Sloc := Sloc (Def_Id);
3681 Error_Msg_NE
3682 ("cannot import&, renaming already provided for " &
3683 "declaration #", N, Def_Id);
3684 end if;
3685 end;
3687 Set_Has_Completion (Def_Id);
3688 Process_Interface_Name (Def_Id, Arg3, Arg4);
3689 end if;
3691 if Is_Compilation_Unit (Hom_Id) then
3693 -- Its possible homonyms are not affected by the pragma.
3694 -- Such homonyms might be present in the context of other
3695 -- units being compiled.
3697 exit;
3699 else
3700 Hom_Id := Homonym (Hom_Id);
3701 end if;
3702 end loop;
3704 -- When the convention is Java or CIL, we also allow Import to be
3705 -- given for packages, generic packages, exceptions, record
3706 -- components, and access to subprograms.
3708 elsif (C = Convention_Java or else C = Convention_CIL)
3709 and then
3710 (Is_Package_Or_Generic_Package (Def_Id)
3711 or else Ekind (Def_Id) = E_Exception
3712 or else Ekind (Def_Id) = E_Access_Subprogram_Type
3713 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3714 then
3715 Set_Imported (Def_Id);
3716 Set_Is_Public (Def_Id);
3717 Process_Interface_Name (Def_Id, Arg3, Arg4);
3719 -- Import a CPP class
3721 elsif Is_Record_Type (Def_Id)
3722 and then C = Convention_CPP
3723 then
3724 -- Types treated as CPP classes are treated as limited, but we
3725 -- don't require them to be declared this way. A warning is
3726 -- issued to encourage the user to declare them as limited.
3727 -- This is not an error, for compatibility reasons, because
3728 -- these types have been supported this way for some time.
3730 if not Is_Limited_Type (Def_Id) then
3731 Error_Msg_N
3732 ("imported 'C'P'P type should be " &
3733 "explicitly declared limited?",
3734 Get_Pragma_Arg (Arg2));
3735 Error_Msg_N
3736 ("\type will be considered limited",
3737 Get_Pragma_Arg (Arg2));
3738 end if;
3740 Set_Is_CPP_Class (Def_Id);
3741 Set_Is_Limited_Record (Def_Id);
3743 -- Imported CPP types must not have discriminants (because C++
3744 -- classes do not have discriminants).
3746 if Has_Discriminants (Def_Id) then
3747 Error_Msg_N
3748 ("imported 'C'P'P type cannot have discriminants",
3749 First (Discriminant_Specifications
3750 (Declaration_Node (Def_Id))));
3751 end if;
3753 -- Components of imported CPP types must not have default
3754 -- expressions because the constructor (if any) is on the
3755 -- C++ side.
3757 declare
3758 Tdef : constant Node_Id :=
3759 Type_Definition (Declaration_Node (Def_Id));
3760 Clist : Node_Id;
3761 Comp : Node_Id;
3763 begin
3764 if Nkind (Tdef) = N_Record_Definition then
3765 Clist := Component_List (Tdef);
3767 else
3768 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
3769 Clist := Component_List (Record_Extension_Part (Tdef));
3770 end if;
3772 if Present (Clist) then
3773 Comp := First (Component_Items (Clist));
3774 while Present (Comp) loop
3775 if Present (Expression (Comp)) then
3776 Error_Msg_N
3777 ("component of imported 'C'P'P type cannot have" &
3778 " default expression", Expression (Comp));
3779 end if;
3781 Next (Comp);
3782 end loop;
3783 end if;
3784 end;
3786 else
3787 Error_Pragma_Arg
3788 ("second argument of pragma% must be object or subprogram",
3789 Arg2);
3790 end if;
3792 -- If this pragma applies to a compilation unit, then the unit, which
3793 -- is a subprogram, does not require (or allow) a body. We also do
3794 -- not need to elaborate imported procedures.
3796 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3797 declare
3798 Cunit : constant Node_Id := Parent (Parent (N));
3799 begin
3800 Set_Body_Required (Cunit, False);
3801 end;
3802 end if;
3803 end Process_Import_Or_Interface;
3805 --------------------
3806 -- Process_Inline --
3807 --------------------
3809 procedure Process_Inline (Active : Boolean) is
3810 Assoc : Node_Id;
3811 Decl : Node_Id;
3812 Subp_Id : Node_Id;
3813 Subp : Entity_Id;
3814 Applies : Boolean;
3815 Effective : Boolean := False;
3817 procedure Make_Inline (Subp : Entity_Id);
3818 -- Subp is the defining unit name of the subprogram declaration. Set
3819 -- the flag, as well as the flag in the corresponding body, if there
3820 -- is one present.
3822 procedure Set_Inline_Flags (Subp : Entity_Id);
3823 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
3824 -- Has_Pragma_Inline_Always for the Inline_Always case.
3826 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3827 -- Returns True if it can be determined at this stage that inlining
3828 -- is not possible, for example if the body is available and contains
3829 -- exception handlers, we prevent inlining, since otherwise we can
3830 -- get undefined symbols at link time. This function also emits a
3831 -- warning if front-end inlining is enabled and the pragma appears
3832 -- too late.
3834 -- ??? is business with link symbols still valid, or does it relate
3835 -- to front end ZCX which is being phased out ???
3837 ---------------------------
3838 -- Inlining_Not_Possible --
3839 ---------------------------
3841 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3842 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3843 Stats : Node_Id;
3845 begin
3846 if Nkind (Decl) = N_Subprogram_Body then
3847 Stats := Handled_Statement_Sequence (Decl);
3848 return Present (Exception_Handlers (Stats))
3849 or else Present (At_End_Proc (Stats));
3851 elsif Nkind (Decl) = N_Subprogram_Declaration
3852 and then Present (Corresponding_Body (Decl))
3853 then
3854 if Front_End_Inlining
3855 and then Analyzed (Corresponding_Body (Decl))
3856 then
3857 Error_Msg_N ("pragma appears too late, ignored?", N);
3858 return True;
3860 -- If the subprogram is a renaming as body, the body is just a
3861 -- call to the renamed subprogram, and inlining is trivially
3862 -- possible.
3864 elsif
3865 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
3866 N_Subprogram_Renaming_Declaration
3867 then
3868 return False;
3870 else
3871 Stats :=
3872 Handled_Statement_Sequence
3873 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3875 return
3876 Present (Exception_Handlers (Stats))
3877 or else Present (At_End_Proc (Stats));
3878 end if;
3880 else
3881 -- If body is not available, assume the best, the check is
3882 -- performed again when compiling enclosing package bodies.
3884 return False;
3885 end if;
3886 end Inlining_Not_Possible;
3888 -----------------
3889 -- Make_Inline --
3890 -----------------
3892 procedure Make_Inline (Subp : Entity_Id) is
3893 Kind : constant Entity_Kind := Ekind (Subp);
3894 Inner_Subp : Entity_Id := Subp;
3896 begin
3897 -- Ignore if bad type, avoid cascaded error
3899 if Etype (Subp) = Any_Type then
3900 Applies := True;
3901 return;
3903 -- Ignore if all inlining is suppressed
3905 elsif Suppress_All_Inlining then
3906 Applies := True;
3907 return;
3909 -- If inlining is not possible, for now do not treat as an error
3911 elsif Inlining_Not_Possible (Subp) then
3912 Applies := True;
3913 return;
3915 -- Here we have a candidate for inlining, but we must exclude
3916 -- derived operations. Otherwise we would end up trying to inline
3917 -- a phantom declaration, and the result would be to drag in a
3918 -- body which has no direct inlining associated with it. That
3919 -- would not only be inefficient but would also result in the
3920 -- backend doing cross-unit inlining in cases where it was
3921 -- definitely inappropriate to do so.
3923 -- However, a simple Comes_From_Source test is insufficient, since
3924 -- we do want to allow inlining of generic instances which also do
3925 -- not come from source. We also need to recognize specs generated
3926 -- by the front-end for bodies that carry the pragma. Finally,
3927 -- predefined operators do not come from source but are not
3928 -- inlineable either.
3930 elsif Is_Generic_Instance (Subp)
3931 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
3932 then
3933 null;
3935 elsif not Comes_From_Source (Subp)
3936 and then Scope (Subp) /= Standard_Standard
3937 then
3938 Applies := True;
3939 return;
3940 end if;
3942 -- The referenced entity must either be the enclosing entity, or
3943 -- an entity declared within the current open scope.
3945 if Present (Scope (Subp))
3946 and then Scope (Subp) /= Current_Scope
3947 and then Subp /= Current_Scope
3948 then
3949 Error_Pragma_Arg
3950 ("argument of% must be entity in current scope", Assoc);
3951 return;
3952 end if;
3954 -- Processing for procedure, operator or function. If subprogram
3955 -- is aliased (as for an instance) indicate that the renamed
3956 -- entity (if declared in the same unit) is inlined.
3958 if Is_Subprogram (Subp) then
3959 Inner_Subp := Ultimate_Alias (Inner_Subp);
3961 if In_Same_Source_Unit (Subp, Inner_Subp) then
3962 Set_Inline_Flags (Inner_Subp);
3964 Decl := Parent (Parent (Inner_Subp));
3966 if Nkind (Decl) = N_Subprogram_Declaration
3967 and then Present (Corresponding_Body (Decl))
3968 then
3969 Set_Inline_Flags (Corresponding_Body (Decl));
3971 elsif Is_Generic_Instance (Subp) then
3973 -- Indicate that the body needs to be created for
3974 -- inlining subsequent calls. The instantiation node
3975 -- follows the declaration of the wrapper package
3976 -- created for it.
3978 if Scope (Subp) /= Standard_Standard
3979 and then
3980 Need_Subprogram_Instance_Body
3981 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
3982 Subp)
3983 then
3984 null;
3985 end if;
3986 end if;
3987 end if;
3989 Applies := True;
3991 -- For a generic subprogram set flag as well, for use at the point
3992 -- of instantiation, to determine whether the body should be
3993 -- generated.
3995 elsif Is_Generic_Subprogram (Subp) then
3996 Set_Inline_Flags (Subp);
3997 Applies := True;
3999 -- Literals are by definition inlined
4001 elsif Kind = E_Enumeration_Literal then
4002 null;
4004 -- Anything else is an error
4006 else
4007 Error_Pragma_Arg
4008 ("expect subprogram name for pragma%", Assoc);
4009 end if;
4010 end Make_Inline;
4012 ----------------------
4013 -- Set_Inline_Flags --
4014 ----------------------
4016 procedure Set_Inline_Flags (Subp : Entity_Id) is
4017 begin
4018 if Active then
4019 Set_Is_Inlined (Subp, True);
4020 end if;
4022 if not Has_Pragma_Inline (Subp) then
4023 Set_Has_Pragma_Inline (Subp);
4024 Effective := True;
4025 end if;
4027 if Prag_Id = Pragma_Inline_Always then
4028 Set_Has_Pragma_Inline_Always (Subp);
4029 end if;
4030 end Set_Inline_Flags;
4032 -- Start of processing for Process_Inline
4034 begin
4035 Check_No_Identifiers;
4036 Check_At_Least_N_Arguments (1);
4038 if Active then
4039 Inline_Processing_Required := True;
4040 end if;
4042 Assoc := Arg1;
4043 while Present (Assoc) loop
4044 Subp_Id := Expression (Assoc);
4045 Analyze (Subp_Id);
4046 Applies := False;
4048 if Is_Entity_Name (Subp_Id) then
4049 Subp := Entity (Subp_Id);
4051 if Subp = Any_Id then
4053 -- If previous error, avoid cascaded errors
4055 Applies := True;
4056 Effective := True;
4058 else
4059 Make_Inline (Subp);
4061 while Present (Homonym (Subp))
4062 and then Scope (Homonym (Subp)) = Current_Scope
4063 loop
4064 Make_Inline (Homonym (Subp));
4065 Subp := Homonym (Subp);
4066 end loop;
4067 end if;
4068 end if;
4070 if not Applies then
4071 Error_Pragma_Arg
4072 ("inappropriate argument for pragma%", Assoc);
4074 elsif not Effective
4075 and then Warn_On_Redundant_Constructs
4076 and then not Suppress_All_Inlining
4077 then
4078 if Inlining_Not_Possible (Subp) then
4079 Error_Msg_NE
4080 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4081 else
4082 Error_Msg_NE
4083 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4084 end if;
4085 end if;
4087 Next (Assoc);
4088 end loop;
4089 end Process_Inline;
4091 ----------------------------
4092 -- Process_Interface_Name --
4093 ----------------------------
4095 procedure Process_Interface_Name
4096 (Subprogram_Def : Entity_Id;
4097 Ext_Arg : Node_Id;
4098 Link_Arg : Node_Id)
4100 Ext_Nam : Node_Id;
4101 Link_Nam : Node_Id;
4102 String_Val : String_Id;
4104 procedure Check_Form_Of_Interface_Name
4105 (SN : Node_Id;
4106 Ext_Name_Case : Boolean);
4107 -- SN is a string literal node for an interface name. This routine
4108 -- performs some minimal checks that the name is reasonable. In
4109 -- particular that no spaces or other obviously incorrect characters
4110 -- appear. This is only a warning, since any characters are allowed.
4111 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4113 ----------------------------------
4114 -- Check_Form_Of_Interface_Name --
4115 ----------------------------------
4117 procedure Check_Form_Of_Interface_Name
4118 (SN : Node_Id;
4119 Ext_Name_Case : Boolean)
4121 S : constant String_Id := Strval (Expr_Value_S (SN));
4122 SL : constant Nat := String_Length (S);
4123 C : Char_Code;
4125 begin
4126 if SL = 0 then
4127 Error_Msg_N ("interface name cannot be null string", SN);
4128 end if;
4130 for J in 1 .. SL loop
4131 C := Get_String_Char (S, J);
4133 -- Look for dubious character and issue unconditional warning.
4134 -- Definitely dubious if not in character range.
4136 if not In_Character_Range (C)
4138 -- For all cases except CLI target,
4139 -- commas, spaces and slashes are dubious (in CLI, we use
4140 -- commas and backslashes in external names to specify
4141 -- assembly version and public key, while slashes and spaces
4142 -- can be used in names to mark nested classes and
4143 -- valuetypes).
4145 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4146 and then (Get_Character (C) = ','
4147 or else
4148 Get_Character (C) = '\'))
4149 or else (VM_Target /= CLI_Target
4150 and then (Get_Character (C) = ' '
4151 or else
4152 Get_Character (C) = '/'))
4153 then
4154 Error_Msg
4155 ("?interface name contains illegal character",
4156 Sloc (SN) + Source_Ptr (J));
4157 end if;
4158 end loop;
4159 end Check_Form_Of_Interface_Name;
4161 -- Start of processing for Process_Interface_Name
4163 begin
4164 if No (Link_Arg) then
4165 if No (Ext_Arg) then
4166 if VM_Target = CLI_Target
4167 and then Ekind (Subprogram_Def) = E_Package
4168 and then Nkind (Parent (Subprogram_Def)) =
4169 N_Package_Specification
4170 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4171 then
4172 Set_Interface_Name
4173 (Subprogram_Def,
4174 Interface_Name
4175 (Generic_Parent (Parent (Subprogram_Def))));
4176 end if;
4178 return;
4180 elsif Chars (Ext_Arg) = Name_Link_Name then
4181 Ext_Nam := Empty;
4182 Link_Nam := Expression (Ext_Arg);
4184 else
4185 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4186 Ext_Nam := Expression (Ext_Arg);
4187 Link_Nam := Empty;
4188 end if;
4190 else
4191 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4192 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4193 Ext_Nam := Expression (Ext_Arg);
4194 Link_Nam := Expression (Link_Arg);
4195 end if;
4197 -- Check expressions for external name and link name are static
4199 if Present (Ext_Nam) then
4200 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4201 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4203 -- Verify that external name is not the name of a local entity,
4204 -- which would hide the imported one and could lead to run-time
4205 -- surprises. The problem can only arise for entities declared in
4206 -- a package body (otherwise the external name is fully qualified
4207 -- and will not conflict).
4209 declare
4210 Nam : Name_Id;
4211 E : Entity_Id;
4212 Par : Node_Id;
4214 begin
4215 if Prag_Id = Pragma_Import then
4216 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4217 Nam := Name_Find;
4218 E := Entity_Id (Get_Name_Table_Info (Nam));
4220 if Nam /= Chars (Subprogram_Def)
4221 and then Present (E)
4222 and then not Is_Overloadable (E)
4223 and then Is_Immediately_Visible (E)
4224 and then not Is_Imported (E)
4225 and then Ekind (Scope (E)) = E_Package
4226 then
4227 Par := Parent (E);
4228 while Present (Par) loop
4229 if Nkind (Par) = N_Package_Body then
4230 Error_Msg_Sloc := Sloc (E);
4231 Error_Msg_NE
4232 ("imported entity is hidden by & declared#",
4233 Ext_Arg, E);
4234 exit;
4235 end if;
4237 Par := Parent (Par);
4238 end loop;
4239 end if;
4240 end if;
4241 end;
4242 end if;
4244 if Present (Link_Nam) then
4245 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4246 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4247 end if;
4249 -- If there is no link name, just set the external name
4251 if No (Link_Nam) then
4252 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4254 -- For the Link_Name case, the given literal is preceded by an
4255 -- asterisk, which indicates to GCC that the given name should be
4256 -- taken literally, and in particular that no prepending of
4257 -- underlines should occur, even in systems where this is the
4258 -- normal default.
4260 else
4261 Start_String;
4263 if VM_Target = No_VM then
4264 Store_String_Char (Get_Char_Code ('*'));
4265 end if;
4267 String_Val := Strval (Expr_Value_S (Link_Nam));
4268 Store_String_Chars (String_Val);
4269 Link_Nam :=
4270 Make_String_Literal (Sloc (Link_Nam),
4271 Strval => End_String);
4272 end if;
4274 Set_Encoded_Interface_Name
4275 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4277 -- We allow duplicated export names in CIL, as they are always
4278 -- enclosed in a namespace that differentiates them, and overloaded
4279 -- entities are supported by the VM.
4281 if Convention (Subprogram_Def) /= Convention_CIL then
4282 Check_Duplicated_Export_Name (Link_Nam);
4283 end if;
4284 end Process_Interface_Name;
4286 -----------------------------------------
4287 -- Process_Interrupt_Or_Attach_Handler --
4288 -----------------------------------------
4290 procedure Process_Interrupt_Or_Attach_Handler is
4291 Arg1_X : constant Node_Id := Expression (Arg1);
4292 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4293 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4295 begin
4296 Set_Is_Interrupt_Handler (Handler_Proc);
4298 -- If the pragma is not associated with a handler procedure within a
4299 -- protected type, then it must be for a nonprotected procedure for
4300 -- the AAMP target, in which case we don't associate a representation
4301 -- item with the procedure's scope.
4303 if Ekind (Proc_Scope) = E_Protected_Type then
4304 if Prag_Id = Pragma_Interrupt_Handler
4305 or else
4306 Prag_Id = Pragma_Attach_Handler
4307 then
4308 Record_Rep_Item (Proc_Scope, N);
4309 end if;
4310 end if;
4311 end Process_Interrupt_Or_Attach_Handler;
4313 --------------------------------------------------
4314 -- Process_Restrictions_Or_Restriction_Warnings --
4315 --------------------------------------------------
4317 -- Note: some of the simple identifier cases were handled in par-prag,
4318 -- but it is harmless (and more straightforward) to simply handle all
4319 -- cases here, even if it means we repeat a bit of work in some cases.
4321 procedure Process_Restrictions_Or_Restriction_Warnings
4322 (Warn : Boolean)
4324 Arg : Node_Id;
4325 R_Id : Restriction_Id;
4326 Id : Name_Id;
4327 Expr : Node_Id;
4328 Val : Uint;
4330 procedure Check_Unit_Name (N : Node_Id);
4331 -- Checks unit name parameter for No_Dependence. Returns if it has
4332 -- an appropriate form, otherwise raises pragma argument error.
4334 ---------------------
4335 -- Check_Unit_Name --
4336 ---------------------
4338 procedure Check_Unit_Name (N : Node_Id) is
4339 begin
4340 if Nkind (N) = N_Selected_Component then
4341 Check_Unit_Name (Prefix (N));
4342 Check_Unit_Name (Selector_Name (N));
4344 elsif Nkind (N) = N_Identifier then
4345 return;
4347 else
4348 Error_Pragma_Arg
4349 ("wrong form for unit name for No_Dependence", N);
4350 end if;
4351 end Check_Unit_Name;
4353 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4355 begin
4356 Check_Ada_83_Warning;
4357 Check_At_Least_N_Arguments (1);
4358 Check_Valid_Configuration_Pragma;
4360 Arg := Arg1;
4361 while Present (Arg) loop
4362 Id := Chars (Arg);
4363 Expr := Expression (Arg);
4365 -- Case of no restriction identifier present
4367 if Id = No_Name then
4368 if Nkind (Expr) /= N_Identifier then
4369 Error_Pragma_Arg
4370 ("invalid form for restriction", Arg);
4371 end if;
4373 R_Id :=
4374 Get_Restriction_Id
4375 (Process_Restriction_Synonyms (Expr));
4377 if R_Id not in All_Boolean_Restrictions then
4378 Error_Msg_Name_1 := Pname;
4379 Error_Msg_N
4380 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4382 -- Check for possible misspelling
4384 for J in Restriction_Id loop
4385 declare
4386 Rnm : constant String := Restriction_Id'Image (J);
4388 begin
4389 Name_Buffer (1 .. Rnm'Length) := Rnm;
4390 Name_Len := Rnm'Length;
4391 Set_Casing (All_Lower_Case);
4393 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4394 Set_Casing
4395 (Identifier_Casing (Current_Source_File));
4396 Error_Msg_String (1 .. Rnm'Length) :=
4397 Name_Buffer (1 .. Name_Len);
4398 Error_Msg_Strlen := Rnm'Length;
4399 Error_Msg_N -- CODEFIX
4400 ("\possible misspelling of ""~""",
4401 Get_Pragma_Arg (Arg));
4402 exit;
4403 end if;
4404 end;
4405 end loop;
4407 raise Pragma_Exit;
4408 end if;
4410 if Implementation_Restriction (R_Id) then
4411 Check_Restriction (No_Implementation_Restrictions, Arg);
4412 end if;
4414 -- If this is a warning, then set the warning unless we already
4415 -- have a real restriction active (we never want a warning to
4416 -- override a real restriction).
4418 if Warn then
4419 if not Restriction_Active (R_Id) then
4420 Set_Restriction (R_Id, N);
4421 Restriction_Warnings (R_Id) := True;
4422 end if;
4424 -- If real restriction case, then set it and make sure that the
4425 -- restriction warning flag is off, since a real restriction
4426 -- always overrides a warning.
4428 else
4429 Set_Restriction (R_Id, N);
4430 Restriction_Warnings (R_Id) := False;
4431 end if;
4433 -- Check for obsolescent restrictions in Ada 2005 mode
4435 if not Warn
4436 and then Ada_Version >= Ada_2005
4437 and then (R_Id = No_Asynchronous_Control
4438 or else
4439 R_Id = No_Unchecked_Deallocation
4440 or else
4441 R_Id = No_Unchecked_Conversion)
4442 then
4443 Check_Restriction (No_Obsolescent_Features, N);
4444 end if;
4446 -- A very special case that must be processed here: pragma
4447 -- Restrictions (No_Exceptions) turns off all run-time
4448 -- checking. This is a bit dubious in terms of the formal
4449 -- language definition, but it is what is intended by RM
4450 -- H.4(12). Restriction_Warnings never affects generated code
4451 -- so this is done only in the real restriction case.
4453 if R_Id = No_Exceptions and then not Warn then
4454 Scope_Suppress := (others => True);
4455 end if;
4457 -- Case of No_Dependence => unit-name. Note that the parser
4458 -- already made the necessary entry in the No_Dependence table.
4460 elsif Id = Name_No_Dependence then
4461 Check_Unit_Name (Expr);
4463 -- All other cases of restriction identifier present
4465 else
4466 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4467 Analyze_And_Resolve (Expr, Any_Integer);
4469 if R_Id not in All_Parameter_Restrictions then
4470 Error_Pragma_Arg
4471 ("invalid restriction parameter identifier", Arg);
4473 elsif not Is_OK_Static_Expression (Expr) then
4474 Flag_Non_Static_Expr
4475 ("value must be static expression!", Expr);
4476 raise Pragma_Exit;
4478 elsif not Is_Integer_Type (Etype (Expr))
4479 or else Expr_Value (Expr) < 0
4480 then
4481 Error_Pragma_Arg
4482 ("value must be non-negative integer", Arg);
4483 end if;
4485 -- Restriction pragma is active
4487 Val := Expr_Value (Expr);
4489 if not UI_Is_In_Int_Range (Val) then
4490 Error_Pragma_Arg
4491 ("pragma ignored, value too large?", Arg);
4492 end if;
4494 -- Warning case. If the real restriction is active, then we
4495 -- ignore the request, since warning never overrides a real
4496 -- restriction. Otherwise we set the proper warning. Note that
4497 -- this circuit sets the warning again if it is already set,
4498 -- which is what we want, since the constant may have changed.
4500 if Warn then
4501 if not Restriction_Active (R_Id) then
4502 Set_Restriction
4503 (R_Id, N, Integer (UI_To_Int (Val)));
4504 Restriction_Warnings (R_Id) := True;
4505 end if;
4507 -- Real restriction case, set restriction and make sure warning
4508 -- flag is off since real restriction always overrides warning.
4510 else
4511 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4512 Restriction_Warnings (R_Id) := False;
4513 end if;
4514 end if;
4516 Next (Arg);
4517 end loop;
4518 end Process_Restrictions_Or_Restriction_Warnings;
4520 ---------------------------------
4521 -- Process_Suppress_Unsuppress --
4522 ---------------------------------
4524 -- Note: this procedure makes entries in the check suppress data
4525 -- structures managed by Sem. See spec of package Sem for full
4526 -- details on how we handle recording of check suppression.
4528 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4529 C : Check_Id;
4530 E_Id : Node_Id;
4531 E : Entity_Id;
4533 In_Package_Spec : constant Boolean :=
4534 Is_Package_Or_Generic_Package (Current_Scope)
4535 and then not In_Package_Body (Current_Scope);
4537 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4538 -- Used to suppress a single check on the given entity
4540 --------------------------------
4541 -- Suppress_Unsuppress_Echeck --
4542 --------------------------------
4544 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4545 begin
4546 Set_Checks_May_Be_Suppressed (E);
4548 if In_Package_Spec then
4549 Push_Global_Suppress_Stack_Entry
4550 (Entity => E,
4551 Check => C,
4552 Suppress => Suppress_Case);
4554 else
4555 Push_Local_Suppress_Stack_Entry
4556 (Entity => E,
4557 Check => C,
4558 Suppress => Suppress_Case);
4559 end if;
4561 -- If this is a first subtype, and the base type is distinct,
4562 -- then also set the suppress flags on the base type.
4564 if Is_First_Subtype (E)
4565 and then Etype (E) /= E
4566 then
4567 Suppress_Unsuppress_Echeck (Etype (E), C);
4568 end if;
4569 end Suppress_Unsuppress_Echeck;
4571 -- Start of processing for Process_Suppress_Unsuppress
4573 begin
4574 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
4575 -- declarative part or a package spec (RM 11.5(5)).
4577 if not Is_Configuration_Pragma then
4578 Check_Is_In_Decl_Part_Or_Package_Spec;
4579 end if;
4581 Check_At_Least_N_Arguments (1);
4582 Check_At_Most_N_Arguments (2);
4583 Check_No_Identifier (Arg1);
4584 Check_Arg_Is_Identifier (Arg1);
4586 C := Get_Check_Id (Chars (Expression (Arg1)));
4588 if C = No_Check_Id then
4589 Error_Pragma_Arg
4590 ("argument of pragma% is not valid check name", Arg1);
4591 end if;
4593 if not Suppress_Case
4594 and then (C = All_Checks or else C = Overflow_Check)
4595 then
4596 Opt.Overflow_Checks_Unsuppressed := True;
4597 end if;
4599 if Arg_Count = 1 then
4601 -- Make an entry in the local scope suppress table. This is the
4602 -- table that directly shows the current value of the scope
4603 -- suppress check for any check id value.
4605 if C = All_Checks then
4607 -- For All_Checks, we set all specific predefined checks with
4608 -- the exception of Elaboration_Check, which is handled
4609 -- specially because of not wanting All_Checks to have the
4610 -- effect of deactivating static elaboration order processing.
4612 for J in Scope_Suppress'Range loop
4613 if J /= Elaboration_Check then
4614 Scope_Suppress (J) := Suppress_Case;
4615 end if;
4616 end loop;
4618 -- If not All_Checks, and predefined check, then set appropriate
4619 -- scope entry. Note that we will set Elaboration_Check if this
4620 -- is explicitly specified.
4622 elsif C in Predefined_Check_Id then
4623 Scope_Suppress (C) := Suppress_Case;
4624 end if;
4626 -- Also make an entry in the Local_Entity_Suppress table
4628 Push_Local_Suppress_Stack_Entry
4629 (Entity => Empty,
4630 Check => C,
4631 Suppress => Suppress_Case);
4633 -- Case of two arguments present, where the check is suppressed for
4634 -- a specified entity (given as the second argument of the pragma)
4636 else
4637 -- This is obsolescent in Ada 2005 mode
4639 if Ada_Version >= Ada_2005 then
4640 Check_Restriction (No_Obsolescent_Features, Arg2);
4641 end if;
4643 Check_Optional_Identifier (Arg2, Name_On);
4644 E_Id := Expression (Arg2);
4645 Analyze (E_Id);
4647 if not Is_Entity_Name (E_Id) then
4648 Error_Pragma_Arg
4649 ("second argument of pragma% must be entity name", Arg2);
4650 end if;
4652 E := Entity (E_Id);
4654 if E = Any_Id then
4655 return;
4656 end if;
4658 -- Enforce RM 11.5(7) which requires that for a pragma that
4659 -- appears within a package spec, the named entity must be
4660 -- within the package spec. We allow the package name itself
4661 -- to be mentioned since that makes sense, although it is not
4662 -- strictly allowed by 11.5(7).
4664 if In_Package_Spec
4665 and then E /= Current_Scope
4666 and then Scope (E) /= Current_Scope
4667 then
4668 Error_Pragma_Arg
4669 ("entity in pragma% is not in package spec (RM 11.5(7))",
4670 Arg2);
4671 end if;
4673 -- Loop through homonyms. As noted below, in the case of a package
4674 -- spec, only homonyms within the package spec are considered.
4676 loop
4677 Suppress_Unsuppress_Echeck (E, C);
4679 if Is_Generic_Instance (E)
4680 and then Is_Subprogram (E)
4681 and then Present (Alias (E))
4682 then
4683 Suppress_Unsuppress_Echeck (Alias (E), C);
4684 end if;
4686 -- Move to next homonym
4688 E := Homonym (E);
4689 exit when No (E);
4691 -- If we are within a package specification, the pragma only
4692 -- applies to homonyms in the same scope.
4694 exit when In_Package_Spec
4695 and then Scope (E) /= Current_Scope;
4696 end loop;
4697 end if;
4698 end Process_Suppress_Unsuppress;
4700 ------------------
4701 -- Set_Exported --
4702 ------------------
4704 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
4705 begin
4706 if Is_Imported (E) then
4707 Error_Pragma_Arg
4708 ("cannot export entity& that was previously imported", Arg);
4710 elsif Present (Address_Clause (E)) then
4711 Error_Pragma_Arg
4712 ("cannot export entity& that has an address clause", Arg);
4713 end if;
4715 Set_Is_Exported (E);
4717 -- Generate a reference for entity explicitly, because the
4718 -- identifier may be overloaded and name resolution will not
4719 -- generate one.
4721 Generate_Reference (E, Arg);
4723 -- Deal with exporting non-library level entity
4725 if not Is_Library_Level_Entity (E) then
4727 -- Not allowed at all for subprograms
4729 if Is_Subprogram (E) then
4730 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
4732 -- Otherwise set public and statically allocated
4734 else
4735 Set_Is_Public (E);
4736 Set_Is_Statically_Allocated (E);
4738 -- Warn if the corresponding W flag is set and the pragma comes
4739 -- from source. The latter may not be true e.g. on VMS where we
4740 -- expand export pragmas for exception codes associated with
4741 -- imported or exported exceptions. We do not want to generate
4742 -- a warning for something that the user did not write.
4744 if Warn_On_Export_Import
4745 and then Comes_From_Source (Arg)
4746 then
4747 Error_Msg_NE
4748 ("?& has been made static as a result of Export", Arg, E);
4749 Error_Msg_N
4750 ("\this usage is non-standard and non-portable", Arg);
4751 end if;
4752 end if;
4753 end if;
4755 if Warn_On_Export_Import and then Is_Type (E) then
4756 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
4757 end if;
4759 if Warn_On_Export_Import and Inside_A_Generic then
4760 Error_Msg_NE
4761 ("all instances of& will have the same external name?", Arg, E);
4762 end if;
4763 end Set_Exported;
4765 ----------------------------------------------
4766 -- Set_Extended_Import_Export_External_Name --
4767 ----------------------------------------------
4769 procedure Set_Extended_Import_Export_External_Name
4770 (Internal_Ent : Entity_Id;
4771 Arg_External : Node_Id)
4773 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
4774 New_Name : Node_Id;
4776 begin
4777 if No (Arg_External) then
4778 return;
4779 end if;
4781 Check_Arg_Is_External_Name (Arg_External);
4783 if Nkind (Arg_External) = N_String_Literal then
4784 if String_Length (Strval (Arg_External)) = 0 then
4785 return;
4786 else
4787 New_Name := Adjust_External_Name_Case (Arg_External);
4788 end if;
4790 elsif Nkind (Arg_External) = N_Identifier then
4791 New_Name := Get_Default_External_Name (Arg_External);
4793 -- Check_Arg_Is_External_Name should let through only identifiers and
4794 -- string literals or static string expressions (which are folded to
4795 -- string literals).
4797 else
4798 raise Program_Error;
4799 end if;
4801 -- If we already have an external name set (by a prior normal Import
4802 -- or Export pragma), then the external names must match
4804 if Present (Interface_Name (Internal_Ent)) then
4805 Check_Matching_Internal_Names : declare
4806 S1 : constant String_Id := Strval (Old_Name);
4807 S2 : constant String_Id := Strval (New_Name);
4809 procedure Mismatch;
4810 -- Called if names do not match
4812 --------------
4813 -- Mismatch --
4814 --------------
4816 procedure Mismatch is
4817 begin
4818 Error_Msg_Sloc := Sloc (Old_Name);
4819 Error_Pragma_Arg
4820 ("external name does not match that given #",
4821 Arg_External);
4822 end Mismatch;
4824 -- Start of processing for Check_Matching_Internal_Names
4826 begin
4827 if String_Length (S1) /= String_Length (S2) then
4828 Mismatch;
4830 else
4831 for J in 1 .. String_Length (S1) loop
4832 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4833 Mismatch;
4834 end if;
4835 end loop;
4836 end if;
4837 end Check_Matching_Internal_Names;
4839 -- Otherwise set the given name
4841 else
4842 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4843 Check_Duplicated_Export_Name (New_Name);
4844 end if;
4845 end Set_Extended_Import_Export_External_Name;
4847 ------------------
4848 -- Set_Imported --
4849 ------------------
4851 procedure Set_Imported (E : Entity_Id) is
4852 begin
4853 -- Error message if already imported or exported
4855 if Is_Exported (E) or else Is_Imported (E) then
4857 -- Error if being set Exported twice
4859 if Is_Exported (E) then
4860 Error_Msg_NE ("entity& was previously exported", N, E);
4862 -- OK if Import/Interface case
4864 elsif Import_Interface_Present (N) then
4865 goto OK;
4867 -- Error if being set Imported twice
4869 else
4870 Error_Msg_NE ("entity& was previously imported", N, E);
4871 end if;
4873 Error_Msg_Name_1 := Pname;
4874 Error_Msg_N
4875 ("\(pragma% applies to all previous entities)", N);
4877 Error_Msg_Sloc := Sloc (E);
4878 Error_Msg_NE ("\import not allowed for& declared#", N, E);
4880 -- Here if not previously imported or exported, OK to import
4882 else
4883 Set_Is_Imported (E);
4885 -- If the entity is an object that is not at the library level,
4886 -- then it is statically allocated. We do not worry about objects
4887 -- with address clauses in this context since they are not really
4888 -- imported in the linker sense.
4890 if Is_Object (E)
4891 and then not Is_Library_Level_Entity (E)
4892 and then No (Address_Clause (E))
4893 then
4894 Set_Is_Statically_Allocated (E);
4895 end if;
4896 end if;
4898 <<OK>> null;
4899 end Set_Imported;
4901 -------------------------
4902 -- Set_Mechanism_Value --
4903 -------------------------
4905 -- Note: the mechanism name has not been analyzed (and cannot indeed be
4906 -- analyzed, since it is semantic nonsense), so we get it in the exact
4907 -- form created by the parser.
4909 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4910 Class : Node_Id;
4911 Param : Node_Id;
4912 Mech_Name_Id : Name_Id;
4914 procedure Bad_Class;
4915 -- Signal bad descriptor class name
4917 procedure Bad_Mechanism;
4918 -- Signal bad mechanism name
4920 ---------------
4921 -- Bad_Class --
4922 ---------------
4924 procedure Bad_Class is
4925 begin
4926 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4927 end Bad_Class;
4929 -------------------------
4930 -- Bad_Mechanism_Value --
4931 -------------------------
4933 procedure Bad_Mechanism is
4934 begin
4935 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4936 end Bad_Mechanism;
4938 -- Start of processing for Set_Mechanism_Value
4940 begin
4941 if Mechanism (Ent) /= Default_Mechanism then
4942 Error_Msg_NE
4943 ("mechanism for & has already been set", Mech_Name, Ent);
4944 end if;
4946 -- MECHANISM_NAME ::= value | reference | descriptor |
4947 -- short_descriptor
4949 if Nkind (Mech_Name) = N_Identifier then
4950 if Chars (Mech_Name) = Name_Value then
4951 Set_Mechanism (Ent, By_Copy);
4952 return;
4954 elsif Chars (Mech_Name) = Name_Reference then
4955 Set_Mechanism (Ent, By_Reference);
4956 return;
4958 elsif Chars (Mech_Name) = Name_Descriptor then
4959 Check_VMS (Mech_Name);
4961 -- Descriptor => Short_Descriptor if pragma was given
4963 if Short_Descriptors then
4964 Set_Mechanism (Ent, By_Short_Descriptor);
4965 else
4966 Set_Mechanism (Ent, By_Descriptor);
4967 end if;
4969 return;
4971 elsif Chars (Mech_Name) = Name_Short_Descriptor then
4972 Check_VMS (Mech_Name);
4973 Set_Mechanism (Ent, By_Short_Descriptor);
4974 return;
4976 elsif Chars (Mech_Name) = Name_Copy then
4977 Error_Pragma_Arg
4978 ("bad mechanism name, Value assumed", Mech_Name);
4980 else
4981 Bad_Mechanism;
4982 end if;
4984 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
4985 -- short_descriptor (CLASS_NAME)
4986 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4988 -- Note: this form is parsed as an indexed component
4990 elsif Nkind (Mech_Name) = N_Indexed_Component then
4991 Class := First (Expressions (Mech_Name));
4993 if Nkind (Prefix (Mech_Name)) /= N_Identifier
4994 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
4995 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
4996 or else Present (Next (Class))
4997 then
4998 Bad_Mechanism;
4999 else
5000 Mech_Name_Id := Chars (Prefix (Mech_Name));
5002 -- Change Descriptor => Short_Descriptor if pragma was given
5004 if Mech_Name_Id = Name_Descriptor
5005 and then Short_Descriptors
5006 then
5007 Mech_Name_Id := Name_Short_Descriptor;
5008 end if;
5009 end if;
5011 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5012 -- short_descriptor (Class => CLASS_NAME)
5013 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5015 -- Note: this form is parsed as a function call
5017 elsif Nkind (Mech_Name) = N_Function_Call then
5018 Param := First (Parameter_Associations (Mech_Name));
5020 if Nkind (Name (Mech_Name)) /= N_Identifier
5021 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5022 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5023 or else Present (Next (Param))
5024 or else No (Selector_Name (Param))
5025 or else Chars (Selector_Name (Param)) /= Name_Class
5026 then
5027 Bad_Mechanism;
5028 else
5029 Class := Explicit_Actual_Parameter (Param);
5030 Mech_Name_Id := Chars (Name (Mech_Name));
5031 end if;
5033 else
5034 Bad_Mechanism;
5035 end if;
5037 -- Fall through here with Class set to descriptor class name
5039 Check_VMS (Mech_Name);
5041 if Nkind (Class) /= N_Identifier then
5042 Bad_Class;
5044 elsif Mech_Name_Id = Name_Descriptor
5045 and then Chars (Class) = Name_UBS
5046 then
5047 Set_Mechanism (Ent, By_Descriptor_UBS);
5049 elsif Mech_Name_Id = Name_Descriptor
5050 and then Chars (Class) = Name_UBSB
5051 then
5052 Set_Mechanism (Ent, By_Descriptor_UBSB);
5054 elsif Mech_Name_Id = Name_Descriptor
5055 and then Chars (Class) = Name_UBA
5056 then
5057 Set_Mechanism (Ent, By_Descriptor_UBA);
5059 elsif Mech_Name_Id = Name_Descriptor
5060 and then Chars (Class) = Name_S
5061 then
5062 Set_Mechanism (Ent, By_Descriptor_S);
5064 elsif Mech_Name_Id = Name_Descriptor
5065 and then Chars (Class) = Name_SB
5066 then
5067 Set_Mechanism (Ent, By_Descriptor_SB);
5069 elsif Mech_Name_Id = Name_Descriptor
5070 and then Chars (Class) = Name_A
5071 then
5072 Set_Mechanism (Ent, By_Descriptor_A);
5074 elsif Mech_Name_Id = Name_Descriptor
5075 and then Chars (Class) = Name_NCA
5076 then
5077 Set_Mechanism (Ent, By_Descriptor_NCA);
5079 elsif Mech_Name_Id = Name_Short_Descriptor
5080 and then Chars (Class) = Name_UBS
5081 then
5082 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5084 elsif Mech_Name_Id = Name_Short_Descriptor
5085 and then Chars (Class) = Name_UBSB
5086 then
5087 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5089 elsif Mech_Name_Id = Name_Short_Descriptor
5090 and then Chars (Class) = Name_UBA
5091 then
5092 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5094 elsif Mech_Name_Id = Name_Short_Descriptor
5095 and then Chars (Class) = Name_S
5096 then
5097 Set_Mechanism (Ent, By_Short_Descriptor_S);
5099 elsif Mech_Name_Id = Name_Short_Descriptor
5100 and then Chars (Class) = Name_SB
5101 then
5102 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5104 elsif Mech_Name_Id = Name_Short_Descriptor
5105 and then Chars (Class) = Name_A
5106 then
5107 Set_Mechanism (Ent, By_Short_Descriptor_A);
5109 elsif Mech_Name_Id = Name_Short_Descriptor
5110 and then Chars (Class) = Name_NCA
5111 then
5112 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5114 else
5115 Bad_Class;
5116 end if;
5117 end Set_Mechanism_Value;
5119 ---------------------------
5120 -- Set_Ravenscar_Profile --
5121 ---------------------------
5123 -- The tasks to be done here are
5125 -- Set required policies
5127 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5128 -- pragma Locking_Policy (Ceiling_Locking)
5130 -- Set Detect_Blocking mode
5132 -- Set required restrictions (see System.Rident for detailed list)
5134 procedure Set_Ravenscar_Profile (N : Node_Id) is
5135 begin
5136 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5138 if Task_Dispatching_Policy /= ' '
5139 and then Task_Dispatching_Policy /= 'F'
5140 then
5141 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5142 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5144 -- Set the FIFO_Within_Priorities policy, but always preserve
5145 -- System_Location since we like the error message with the run time
5146 -- name.
5148 else
5149 Task_Dispatching_Policy := 'F';
5151 if Task_Dispatching_Policy_Sloc /= System_Location then
5152 Task_Dispatching_Policy_Sloc := Loc;
5153 end if;
5154 end if;
5156 -- pragma Locking_Policy (Ceiling_Locking)
5158 if Locking_Policy /= ' '
5159 and then Locking_Policy /= 'C'
5160 then
5161 Error_Msg_Sloc := Locking_Policy_Sloc;
5162 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5164 -- Set the Ceiling_Locking policy, but preserve System_Location since
5165 -- we like the error message with the run time name.
5167 else
5168 Locking_Policy := 'C';
5170 if Locking_Policy_Sloc /= System_Location then
5171 Locking_Policy_Sloc := Loc;
5172 end if;
5173 end if;
5175 -- pragma Detect_Blocking
5177 Detect_Blocking := True;
5179 -- Set the corresponding restrictions
5181 Set_Profile_Restrictions
5182 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5183 end Set_Ravenscar_Profile;
5185 -- Start of processing for Analyze_Pragma
5187 begin
5188 -- Deal with unrecognized pragma
5190 if not Is_Pragma_Name (Pname) then
5191 if Warn_On_Unrecognized_Pragma then
5192 Error_Msg_Name_1 := Pname;
5193 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5195 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5196 if Is_Bad_Spelling_Of (Pname, PN) then
5197 Error_Msg_Name_1 := PN;
5198 Error_Msg_N -- CODEFIX
5199 ("\?possible misspelling of %!", Pragma_Identifier (N));
5200 exit;
5201 end if;
5202 end loop;
5203 end if;
5205 return;
5206 end if;
5208 -- Here to start processing for recognized pragma
5210 Prag_Id := Get_Pragma_Id (Pname);
5212 -- Preset arguments
5214 Arg1 := Empty;
5215 Arg2 := Empty;
5216 Arg3 := Empty;
5217 Arg4 := Empty;
5219 if Present (Pragma_Argument_Associations (N)) then
5220 Arg1 := First (Pragma_Argument_Associations (N));
5222 if Present (Arg1) then
5223 Arg2 := Next (Arg1);
5225 if Present (Arg2) then
5226 Arg3 := Next (Arg2);
5228 if Present (Arg3) then
5229 Arg4 := Next (Arg3);
5230 end if;
5231 end if;
5232 end if;
5233 end if;
5235 -- Count number of arguments
5237 declare
5238 Arg_Node : Node_Id;
5239 begin
5240 Arg_Count := 0;
5241 Arg_Node := Arg1;
5242 while Present (Arg_Node) loop
5243 Arg_Count := Arg_Count + 1;
5244 Next (Arg_Node);
5245 end loop;
5246 end;
5248 -- An enumeration type defines the pragmas that are supported by the
5249 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5250 -- into the corresponding enumeration value for the following case.
5252 case Prag_Id is
5254 -----------------
5255 -- Abort_Defer --
5256 -----------------
5258 -- pragma Abort_Defer;
5260 when Pragma_Abort_Defer =>
5261 GNAT_Pragma;
5262 Check_Arg_Count (0);
5264 -- The only required semantic processing is to check the
5265 -- placement. This pragma must appear at the start of the
5266 -- statement sequence of a handled sequence of statements.
5268 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5269 or else N /= First (Statements (Parent (N)))
5270 then
5271 Pragma_Misplaced;
5272 end if;
5274 ------------
5275 -- Ada_83 --
5276 ------------
5278 -- pragma Ada_83;
5280 -- Note: this pragma also has some specific processing in Par.Prag
5281 -- because we want to set the Ada version mode during parsing.
5283 when Pragma_Ada_83 =>
5284 GNAT_Pragma;
5285 Check_Arg_Count (0);
5287 -- We really should check unconditionally for proper configuration
5288 -- pragma placement, since we really don't want mixed Ada modes
5289 -- within a single unit, and the GNAT reference manual has always
5290 -- said this was a configuration pragma, but we did not check and
5291 -- are hesitant to add the check now.
5293 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5294 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5295 -- or Ada 2012 mode.
5297 if Ada_Version >= Ada_05 then
5298 Check_Valid_Configuration_Pragma;
5299 end if;
5301 -- Now set Ada 83 mode
5303 Ada_Version := Ada_83;
5304 Ada_Version_Explicit := Ada_Version;
5306 ------------
5307 -- Ada_95 --
5308 ------------
5310 -- pragma Ada_95;
5312 -- Note: this pragma also has some specific processing in Par.Prag
5313 -- because we want to set the Ada 83 version mode during parsing.
5315 when Pragma_Ada_95 =>
5316 GNAT_Pragma;
5317 Check_Arg_Count (0);
5319 -- We really should check unconditionally for proper configuration
5320 -- pragma placement, since we really don't want mixed Ada modes
5321 -- within a single unit, and the GNAT reference manual has always
5322 -- said this was a configuration pragma, but we did not check and
5323 -- are hesitant to add the check now.
5325 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5326 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5328 if Ada_Version >= Ada_05 then
5329 Check_Valid_Configuration_Pragma;
5330 end if;
5332 -- Now set Ada 95 mode
5334 Ada_Version := Ada_95;
5335 Ada_Version_Explicit := Ada_Version;
5337 ---------------------
5338 -- Ada_05/Ada_2005 --
5339 ---------------------
5341 -- pragma Ada_05;
5342 -- pragma Ada_05 (LOCAL_NAME);
5344 -- pragma Ada_2005;
5345 -- pragma Ada_2005 (LOCAL_NAME):
5347 -- Note: these pragma also have some specific processing in Par.Prag
5348 -- because we want to set the Ada 2005 version mode during parsing.
5350 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5351 E_Id : Node_Id;
5353 begin
5354 GNAT_Pragma;
5356 if Arg_Count = 1 then
5357 Check_Arg_Is_Local_Name (Arg1);
5358 E_Id := Expression (Arg1);
5360 if Etype (E_Id) = Any_Type then
5361 return;
5362 end if;
5364 Set_Is_Ada_2005_Only (Entity (E_Id));
5366 else
5367 Check_Arg_Count (0);
5369 -- For Ada_2005 we unconditionally enforce the documented
5370 -- configuration pragma placement, since we do not want to
5371 -- tolerate mixed modes in a unit involving Ada 2005. That
5372 -- would cause real difficulties for those cases where there
5373 -- are incompatibilities between Ada 95 and Ada 2005.
5375 Check_Valid_Configuration_Pragma;
5377 -- Now set Ada 2005 mode
5379 Ada_Version := Ada_05;
5380 Ada_Version_Explicit := Ada_05;
5381 end if;
5382 end;
5384 ---------------------
5385 -- Ada_12/Ada_2012 --
5386 ---------------------
5388 -- pragma Ada_12;
5389 -- pragma Ada_2012;
5391 -- Note: these pragma also have some specific processing in Par.Prag
5392 -- because we want to set the Ada 2012 version mode during parsing.
5394 when Pragma_Ada_12 | Pragma_Ada_2012 =>
5395 GNAT_Pragma;
5396 Check_Arg_Count (0);
5398 -- For Ada_2012 we unconditionally enforce the documented
5399 -- configuration pragma placement, since we do not want to
5400 -- tolerate mixed modes in a unit involving Ada 2012. That would
5401 -- cause real difficulties for those cases where there are
5402 -- incompatibilities between Ada 95 and Ada 2005/Ada 2012.
5404 Check_Valid_Configuration_Pragma;
5406 -- Now set Ada 2012 mode
5408 Ada_Version := Ada_12;
5409 Ada_Version_Explicit := Ada_12;
5411 ----------------------
5412 -- All_Calls_Remote --
5413 ----------------------
5415 -- pragma All_Calls_Remote [(library_package_NAME)];
5417 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5418 Lib_Entity : Entity_Id;
5420 begin
5421 Check_Ada_83_Warning;
5422 Check_Valid_Library_Unit_Pragma;
5424 if Nkind (N) = N_Null_Statement then
5425 return;
5426 end if;
5428 Lib_Entity := Find_Lib_Unit_Name;
5430 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5432 if Present (Lib_Entity)
5433 and then not Debug_Flag_U
5434 then
5435 if not Is_Remote_Call_Interface (Lib_Entity) then
5436 Error_Pragma ("pragma% only apply to rci unit");
5438 -- Set flag for entity of the library unit
5440 else
5441 Set_Has_All_Calls_Remote (Lib_Entity);
5442 end if;
5444 end if;
5445 end All_Calls_Remote;
5447 --------------
5448 -- Annotate --
5449 --------------
5451 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
5452 -- ARG ::= NAME | EXPRESSION
5454 -- The first two arguments are by convention intended to refer to an
5455 -- external tool and a tool-specific function. These arguments are
5456 -- not analyzed.
5458 when Pragma_Annotate => Annotate : begin
5459 GNAT_Pragma;
5460 Check_At_Least_N_Arguments (1);
5461 Check_Arg_Is_Identifier (Arg1);
5462 Check_No_Identifiers;
5463 Store_Note (N);
5465 declare
5466 Arg : Node_Id;
5467 Exp : Node_Id;
5469 begin
5470 -- Second unanalyzed parameter is optional
5472 if No (Arg2) then
5473 null;
5474 else
5475 Arg := Next (Arg2);
5476 while Present (Arg) loop
5477 Exp := Expression (Arg);
5478 Analyze (Exp);
5480 if Is_Entity_Name (Exp) then
5481 null;
5483 -- For string literals, we assume Standard_String as the
5484 -- type, unless the string contains wide or wide_wide
5485 -- characters.
5487 elsif Nkind (Exp) = N_String_Literal then
5488 if Has_Wide_Wide_Character (Exp) then
5489 Resolve (Exp, Standard_Wide_Wide_String);
5490 elsif Has_Wide_Character (Exp) then
5491 Resolve (Exp, Standard_Wide_String);
5492 else
5493 Resolve (Exp, Standard_String);
5494 end if;
5496 elsif Is_Overloaded (Exp) then
5497 Error_Pragma_Arg
5498 ("ambiguous argument for pragma%", Exp);
5500 else
5501 Resolve (Exp);
5502 end if;
5504 Next (Arg);
5505 end loop;
5506 end if;
5507 end;
5508 end Annotate;
5510 ------------
5511 -- Assert --
5512 ------------
5514 -- pragma Assert ([Check =>] Boolean_EXPRESSION
5515 -- [, [Message =>] Static_String_EXPRESSION]);
5517 when Pragma_Assert => Assert : declare
5518 Expr : Node_Id;
5519 Newa : List_Id;
5521 begin
5522 Ada_2005_Pragma;
5523 Check_At_Least_N_Arguments (1);
5524 Check_At_Most_N_Arguments (2);
5525 Check_Arg_Order ((Name_Check, Name_Message));
5526 Check_Optional_Identifier (Arg1, Name_Check);
5528 -- We treat pragma Assert as equivalent to:
5530 -- pragma Check (Assertion, condition [, msg]);
5532 -- So rewrite pragma in this manner, and analyze the result
5534 Expr := Get_Pragma_Arg (Arg1);
5535 Newa := New_List (
5536 Make_Pragma_Argument_Association (Loc,
5537 Expression =>
5538 Make_Identifier (Loc,
5539 Chars => Name_Assertion)),
5541 Make_Pragma_Argument_Association (Sloc (Expr),
5542 Expression => Expr));
5544 if Arg_Count > 1 then
5545 Check_Optional_Identifier (Arg2, Name_Message);
5546 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
5547 Append_To (Newa, Relocate_Node (Arg2));
5548 end if;
5550 Rewrite (N,
5551 Make_Pragma (Loc,
5552 Chars => Name_Check,
5553 Pragma_Argument_Associations => Newa));
5554 Analyze (N);
5555 end Assert;
5557 ----------------------
5558 -- Assertion_Policy --
5559 ----------------------
5561 -- pragma Assertion_Policy (Check | Ignore)
5563 when Pragma_Assertion_Policy => Assertion_Policy : declare
5564 Policy : Node_Id;
5566 begin
5567 Ada_2005_Pragma;
5568 Check_Valid_Configuration_Pragma;
5569 Check_Arg_Count (1);
5570 Check_No_Identifiers;
5571 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5573 -- We treat pragma Assertion_Policy as equivalent to:
5575 -- pragma Check_Policy (Assertion, policy)
5577 -- So rewrite the pragma in that manner and link on to the chain
5578 -- of Check_Policy pragmas, marking the pragma as analyzed.
5580 Policy := Get_Pragma_Arg (Arg1);
5582 Rewrite (N,
5583 Make_Pragma (Loc,
5584 Chars => Name_Check_Policy,
5586 Pragma_Argument_Associations => New_List (
5587 Make_Pragma_Argument_Association (Loc,
5588 Expression =>
5589 Make_Identifier (Loc,
5590 Chars => Name_Assertion)),
5592 Make_Pragma_Argument_Association (Loc,
5593 Expression =>
5594 Make_Identifier (Sloc (Policy),
5595 Chars => Chars (Policy))))));
5597 Set_Analyzed (N);
5598 Set_Next_Pragma (N, Opt.Check_Policy_List);
5599 Opt.Check_Policy_List := N;
5600 end Assertion_Policy;
5602 ------------------------------
5603 -- Assume_No_Invalid_Values --
5604 ------------------------------
5606 -- pragma Assume_No_Invalid_Values (On | Off);
5608 when Pragma_Assume_No_Invalid_Values =>
5609 GNAT_Pragma;
5610 Check_Valid_Configuration_Pragma;
5611 Check_Arg_Count (1);
5612 Check_No_Identifiers;
5613 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5615 if Chars (Expression (Arg1)) = Name_On then
5616 Assume_No_Invalid_Values := True;
5617 else
5618 Assume_No_Invalid_Values := False;
5619 end if;
5621 ---------------
5622 -- AST_Entry --
5623 ---------------
5625 -- pragma AST_Entry (entry_IDENTIFIER);
5627 when Pragma_AST_Entry => AST_Entry : declare
5628 Ent : Node_Id;
5630 begin
5631 GNAT_Pragma;
5632 Check_VMS (N);
5633 Check_Arg_Count (1);
5634 Check_No_Identifiers;
5635 Check_Arg_Is_Local_Name (Arg1);
5636 Ent := Entity (Expression (Arg1));
5638 -- Note: the implementation of the AST_Entry pragma could handle
5639 -- the entry family case fine, but for now we are consistent with
5640 -- the DEC rules, and do not allow the pragma, which of course
5641 -- has the effect of also forbidding the attribute.
5643 if Ekind (Ent) /= E_Entry then
5644 Error_Pragma_Arg
5645 ("pragma% argument must be simple entry name", Arg1);
5647 elsif Is_AST_Entry (Ent) then
5648 Error_Pragma_Arg
5649 ("duplicate % pragma for entry", Arg1);
5651 elsif Has_Homonym (Ent) then
5652 Error_Pragma_Arg
5653 ("pragma% argument cannot specify overloaded entry", Arg1);
5655 else
5656 declare
5657 FF : constant Entity_Id := First_Formal (Ent);
5659 begin
5660 if Present (FF) then
5661 if Present (Next_Formal (FF)) then
5662 Error_Pragma_Arg
5663 ("entry for pragma% can have only one argument",
5664 Arg1);
5666 elsif Parameter_Mode (FF) /= E_In_Parameter then
5667 Error_Pragma_Arg
5668 ("entry parameter for pragma% must have mode IN",
5669 Arg1);
5670 end if;
5671 end if;
5672 end;
5674 Set_Is_AST_Entry (Ent);
5675 end if;
5676 end AST_Entry;
5678 ------------------
5679 -- Asynchronous --
5680 ------------------
5682 -- pragma Asynchronous (LOCAL_NAME);
5684 when Pragma_Asynchronous => Asynchronous : declare
5685 Nm : Entity_Id;
5686 C_Ent : Entity_Id;
5687 L : List_Id;
5688 S : Node_Id;
5689 N : Node_Id;
5690 Formal : Entity_Id;
5692 procedure Process_Async_Pragma;
5693 -- Common processing for procedure and access-to-procedure case
5695 --------------------------
5696 -- Process_Async_Pragma --
5697 --------------------------
5699 procedure Process_Async_Pragma is
5700 begin
5701 if No (L) then
5702 Set_Is_Asynchronous (Nm);
5703 return;
5704 end if;
5706 -- The formals should be of mode IN (RM E.4.1(6))
5708 S := First (L);
5709 while Present (S) loop
5710 Formal := Defining_Identifier (S);
5712 if Nkind (Formal) = N_Defining_Identifier
5713 and then Ekind (Formal) /= E_In_Parameter
5714 then
5715 Error_Pragma_Arg
5716 ("pragma% procedure can only have IN parameter",
5717 Arg1);
5718 end if;
5720 Next (S);
5721 end loop;
5723 Set_Is_Asynchronous (Nm);
5724 end Process_Async_Pragma;
5726 -- Start of processing for pragma Asynchronous
5728 begin
5729 Check_Ada_83_Warning;
5730 Check_No_Identifiers;
5731 Check_Arg_Count (1);
5732 Check_Arg_Is_Local_Name (Arg1);
5734 if Debug_Flag_U then
5735 return;
5736 end if;
5738 C_Ent := Cunit_Entity (Current_Sem_Unit);
5739 Analyze (Expression (Arg1));
5740 Nm := Entity (Expression (Arg1));
5742 if not Is_Remote_Call_Interface (C_Ent)
5743 and then not Is_Remote_Types (C_Ent)
5744 then
5745 -- This pragma should only appear in an RCI or Remote Types
5746 -- unit (RM E.4.1(4)).
5748 Error_Pragma
5749 ("pragma% not in Remote_Call_Interface or " &
5750 "Remote_Types unit");
5751 end if;
5753 if Ekind (Nm) = E_Procedure
5754 and then Nkind (Parent (Nm)) = N_Procedure_Specification
5755 then
5756 if not Is_Remote_Call_Interface (Nm) then
5757 Error_Pragma_Arg
5758 ("pragma% cannot be applied on non-remote procedure",
5759 Arg1);
5760 end if;
5762 L := Parameter_Specifications (Parent (Nm));
5763 Process_Async_Pragma;
5764 return;
5766 elsif Ekind (Nm) = E_Function then
5767 Error_Pragma_Arg
5768 ("pragma% cannot be applied to function", Arg1);
5770 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
5772 if Is_Record_Type (Nm) then
5774 -- A record type that is the Equivalent_Type for a remote
5775 -- access-to-subprogram type.
5777 N := Declaration_Node (Corresponding_Remote_Type (Nm));
5779 else
5780 -- A non-expanded RAS type (distribution is not enabled)
5782 N := Declaration_Node (Nm);
5783 end if;
5785 if Nkind (N) = N_Full_Type_Declaration
5786 and then Nkind (Type_Definition (N)) =
5787 N_Access_Procedure_Definition
5788 then
5789 L := Parameter_Specifications (Type_Definition (N));
5790 Process_Async_Pragma;
5792 if Is_Asynchronous (Nm)
5793 and then Expander_Active
5794 and then Get_PCS_Name /= Name_No_DSA
5795 then
5796 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
5797 end if;
5799 else
5800 Error_Pragma_Arg
5801 ("pragma% cannot reference access-to-function type",
5802 Arg1);
5803 end if;
5805 -- Only other possibility is Access-to-class-wide type
5807 elsif Is_Access_Type (Nm)
5808 and then Is_Class_Wide_Type (Designated_Type (Nm))
5809 then
5810 Check_First_Subtype (Arg1);
5811 Set_Is_Asynchronous (Nm);
5812 if Expander_Active then
5813 RACW_Type_Is_Asynchronous (Nm);
5814 end if;
5816 else
5817 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
5818 end if;
5819 end Asynchronous;
5821 ------------
5822 -- Atomic --
5823 ------------
5825 -- pragma Atomic (LOCAL_NAME);
5827 when Pragma_Atomic =>
5828 Process_Atomic_Shared_Volatile;
5830 -----------------------
5831 -- Atomic_Components --
5832 -----------------------
5834 -- pragma Atomic_Components (array_LOCAL_NAME);
5836 -- This processing is shared by Volatile_Components
5838 when Pragma_Atomic_Components |
5839 Pragma_Volatile_Components =>
5841 Atomic_Components : declare
5842 E_Id : Node_Id;
5843 E : Entity_Id;
5844 D : Node_Id;
5845 K : Node_Kind;
5847 begin
5848 Check_Ada_83_Warning;
5849 Check_No_Identifiers;
5850 Check_Arg_Count (1);
5851 Check_Arg_Is_Local_Name (Arg1);
5852 E_Id := Expression (Arg1);
5854 if Etype (E_Id) = Any_Type then
5855 return;
5856 end if;
5858 E := Entity (E_Id);
5860 if Rep_Item_Too_Early (E, N)
5861 or else
5862 Rep_Item_Too_Late (E, N)
5863 then
5864 return;
5865 end if;
5867 D := Declaration_Node (E);
5868 K := Nkind (D);
5870 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
5871 or else
5872 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
5873 and then Nkind (D) = N_Object_Declaration
5874 and then Nkind (Object_Definition (D)) =
5875 N_Constrained_Array_Definition)
5876 then
5877 -- The flag is set on the object, or on the base type
5879 if Nkind (D) /= N_Object_Declaration then
5880 E := Base_Type (E);
5881 end if;
5883 Set_Has_Volatile_Components (E);
5885 if Prag_Id = Pragma_Atomic_Components then
5886 Set_Has_Atomic_Components (E);
5888 if Is_Packed (E) then
5889 Set_Is_Packed (E, False);
5891 Error_Pragma_Arg
5892 ("?Pack canceled, cannot pack atomic components",
5893 Arg1);
5894 end if;
5895 end if;
5897 else
5898 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
5899 end if;
5900 end Atomic_Components;
5902 --------------------
5903 -- Attach_Handler --
5904 --------------------
5906 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
5908 when Pragma_Attach_Handler =>
5909 Check_Ada_83_Warning;
5910 Check_No_Identifiers;
5911 Check_Arg_Count (2);
5913 if No_Run_Time_Mode then
5914 Error_Msg_CRT ("Attach_Handler pragma", N);
5915 else
5916 Check_Interrupt_Or_Attach_Handler;
5918 -- The expression that designates the attribute may
5919 -- depend on a discriminant, and is therefore a per-
5920 -- object expression, to be expanded in the init proc.
5921 -- If expansion is enabled, perform semantic checks
5922 -- on a copy only.
5924 if Expander_Active then
5925 declare
5926 Temp : constant Node_Id :=
5927 New_Copy_Tree (Expression (Arg2));
5928 begin
5929 Set_Parent (Temp, N);
5930 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
5931 end;
5933 else
5934 Analyze (Expression (Arg2));
5935 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
5936 end if;
5938 Process_Interrupt_Or_Attach_Handler;
5939 end if;
5941 --------------------
5942 -- C_Pass_By_Copy --
5943 --------------------
5945 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
5947 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
5948 Arg : Node_Id;
5949 Val : Uint;
5951 begin
5952 GNAT_Pragma;
5953 Check_Valid_Configuration_Pragma;
5954 Check_Arg_Count (1);
5955 Check_Optional_Identifier (Arg1, "max_size");
5957 Arg := Expression (Arg1);
5958 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
5960 Val := Expr_Value (Arg);
5962 if Val <= 0 then
5963 Error_Pragma_Arg
5964 ("maximum size for pragma% must be positive", Arg1);
5966 elsif UI_Is_In_Int_Range (Val) then
5967 Default_C_Record_Mechanism := UI_To_Int (Val);
5969 -- If a giant value is given, Int'Last will do well enough.
5970 -- If sometime someone complains that a record larger than
5971 -- two gigabytes is not copied, we will worry about it then!
5973 else
5974 Default_C_Record_Mechanism := Mechanism_Type'Last;
5975 end if;
5976 end C_Pass_By_Copy;
5978 -----------
5979 -- Check --
5980 -----------
5982 -- pragma Check ([Name =>] Identifier,
5983 -- [Check =>] Boolean_Expression
5984 -- [,[Message =>] String_Expression]);
5986 when Pragma_Check => Check : declare
5987 Expr : Node_Id;
5988 Eloc : Source_Ptr;
5990 Check_On : Boolean;
5991 -- Set True if category of assertions referenced by Name enabled
5993 begin
5994 GNAT_Pragma;
5995 Check_At_Least_N_Arguments (2);
5996 Check_At_Most_N_Arguments (3);
5997 Check_Optional_Identifier (Arg1, Name_Name);
5998 Check_Optional_Identifier (Arg2, Name_Check);
6000 if Arg_Count = 3 then
6001 Check_Optional_Identifier (Arg3, Name_Message);
6002 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6003 end if;
6005 Check_Arg_Is_Identifier (Arg1);
6007 -- Indicate if pragma is enabled. The Original_Node reference here
6008 -- is to deal with pragma Assert rewritten as a Check pragma.
6010 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6012 if Check_On then
6013 Set_Pragma_Enabled (N);
6014 Set_Pragma_Enabled (Original_Node (N));
6015 Set_SCO_Pragma_Enabled (Loc);
6016 end if;
6018 -- If expansion is active and the check is not enabled then we
6019 -- rewrite the Check as:
6021 -- if False and then condition then
6022 -- null;
6023 -- end if;
6025 -- The reason we do this rewriting during semantic analysis rather
6026 -- than as part of normal expansion is that we cannot analyze and
6027 -- expand the code for the boolean expression directly, or it may
6028 -- cause insertion of actions that would escape the attempt to
6029 -- suppress the check code.
6031 -- Note that the Sloc for the if statement corresponds to the
6032 -- argument condition, not the pragma itself. The reason for this
6033 -- is that we may generate a warning if the condition is False at
6034 -- compile time, and we do not want to delete this warning when we
6035 -- delete the if statement.
6037 Expr := Expression (Arg2);
6039 if Expander_Active and then not Check_On then
6040 Eloc := Sloc (Expr);
6042 Rewrite (N,
6043 Make_If_Statement (Eloc,
6044 Condition =>
6045 Make_And_Then (Eloc,
6046 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6047 Right_Opnd => Expr),
6048 Then_Statements => New_List (
6049 Make_Null_Statement (Eloc))));
6051 Analyze (N);
6053 -- Check is active
6055 else
6056 Analyze_And_Resolve (Expr, Any_Boolean);
6057 end if;
6058 end Check;
6060 ----------------
6061 -- Check_Name --
6062 ----------------
6064 -- pragma Check_Name (check_IDENTIFIER);
6066 when Pragma_Check_Name =>
6067 Check_No_Identifiers;
6068 GNAT_Pragma;
6069 Check_Valid_Configuration_Pragma;
6070 Check_Arg_Count (1);
6071 Check_Arg_Is_Identifier (Arg1);
6073 declare
6074 Nam : constant Name_Id := Chars (Expression (Arg1));
6076 begin
6077 for J in Check_Names.First .. Check_Names.Last loop
6078 if Check_Names.Table (J) = Nam then
6079 return;
6080 end if;
6081 end loop;
6083 Check_Names.Append (Nam);
6084 end;
6086 ------------------
6087 -- Check_Policy --
6088 ------------------
6090 -- pragma Check_Policy (
6091 -- [Name =>] IDENTIFIER,
6092 -- [Policy =>] POLICY_IDENTIFIER);
6094 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6096 -- Note: this is a configuration pragma, but it is allowed to appear
6097 -- anywhere else.
6099 when Pragma_Check_Policy =>
6100 GNAT_Pragma;
6101 Check_Arg_Count (2);
6102 Check_Optional_Identifier (Arg1, Name_Name);
6103 Check_Optional_Identifier (Arg2, Name_Policy);
6104 Check_Arg_Is_One_Of
6105 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6107 -- A Check_Policy pragma can appear either as a configuration
6108 -- pragma, or in a declarative part or a package spec (see RM
6109 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6110 -- followed for Check_Policy).
6112 if not Is_Configuration_Pragma then
6113 Check_Is_In_Decl_Part_Or_Package_Spec;
6114 end if;
6116 Set_Next_Pragma (N, Opt.Check_Policy_List);
6117 Opt.Check_Policy_List := N;
6119 ---------------------
6120 -- CIL_Constructor --
6121 ---------------------
6123 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6125 -- Processing for this pragma is shared with Java_Constructor
6127 -------------
6128 -- Comment --
6129 -------------
6131 -- pragma Comment (static_string_EXPRESSION)
6133 -- Processing for pragma Comment shares the circuitry for pragma
6134 -- Ident. The only differences are that Ident enforces a limit of 31
6135 -- characters on its argument, and also enforces limitations on
6136 -- placement for DEC compatibility. Pragma Comment shares neither of
6137 -- these restrictions.
6139 -------------------
6140 -- Common_Object --
6141 -------------------
6143 -- pragma Common_Object (
6144 -- [Internal =>] LOCAL_NAME
6145 -- [, [External =>] EXTERNAL_SYMBOL]
6146 -- [, [Size =>] EXTERNAL_SYMBOL]);
6148 -- Processing for this pragma is shared with Psect_Object
6150 ------------------------
6151 -- Compile_Time_Error --
6152 ------------------------
6154 -- pragma Compile_Time_Error
6155 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6157 when Pragma_Compile_Time_Error =>
6158 GNAT_Pragma;
6159 Process_Compile_Time_Warning_Or_Error;
6161 --------------------------
6162 -- Compile_Time_Warning --
6163 --------------------------
6165 -- pragma Compile_Time_Warning
6166 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6168 when Pragma_Compile_Time_Warning =>
6169 GNAT_Pragma;
6170 Process_Compile_Time_Warning_Or_Error;
6172 -------------------
6173 -- Compiler_Unit --
6174 -------------------
6176 when Pragma_Compiler_Unit =>
6177 GNAT_Pragma;
6178 Check_Arg_Count (0);
6179 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6181 -----------------------------
6182 -- Complete_Representation --
6183 -----------------------------
6185 -- pragma Complete_Representation;
6187 when Pragma_Complete_Representation =>
6188 GNAT_Pragma;
6189 Check_Arg_Count (0);
6191 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6192 Error_Pragma
6193 ("pragma & must appear within record representation clause");
6194 end if;
6196 ----------------------------
6197 -- Complex_Representation --
6198 ----------------------------
6200 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6202 when Pragma_Complex_Representation => Complex_Representation : declare
6203 E_Id : Entity_Id;
6204 E : Entity_Id;
6205 Ent : Entity_Id;
6207 begin
6208 GNAT_Pragma;
6209 Check_Arg_Count (1);
6210 Check_Optional_Identifier (Arg1, Name_Entity);
6211 Check_Arg_Is_Local_Name (Arg1);
6212 E_Id := Expression (Arg1);
6214 if Etype (E_Id) = Any_Type then
6215 return;
6216 end if;
6218 E := Entity (E_Id);
6220 if not Is_Record_Type (E) then
6221 Error_Pragma_Arg
6222 ("argument for pragma% must be record type", Arg1);
6223 end if;
6225 Ent := First_Entity (E);
6227 if No (Ent)
6228 or else No (Next_Entity (Ent))
6229 or else Present (Next_Entity (Next_Entity (Ent)))
6230 or else not Is_Floating_Point_Type (Etype (Ent))
6231 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6232 then
6233 Error_Pragma_Arg
6234 ("record for pragma% must have two fields of the same "
6235 & "floating-point type", Arg1);
6237 else
6238 Set_Has_Complex_Representation (Base_Type (E));
6240 -- We need to treat the type has having a non-standard
6241 -- representation, for back-end purposes, even though in
6242 -- general a complex will have the default representation
6243 -- of a record with two real components.
6245 Set_Has_Non_Standard_Rep (Base_Type (E));
6246 end if;
6247 end Complex_Representation;
6249 -------------------------
6250 -- Component_Alignment --
6251 -------------------------
6253 -- pragma Component_Alignment (
6254 -- [Form =>] ALIGNMENT_CHOICE
6255 -- [, [Name =>] type_LOCAL_NAME]);
6257 -- ALIGNMENT_CHOICE ::=
6258 -- Component_Size
6259 -- | Component_Size_4
6260 -- | Storage_Unit
6261 -- | Default
6263 when Pragma_Component_Alignment => Component_AlignmentP : declare
6264 Args : Args_List (1 .. 2);
6265 Names : constant Name_List (1 .. 2) := (
6266 Name_Form,
6267 Name_Name);
6269 Form : Node_Id renames Args (1);
6270 Name : Node_Id renames Args (2);
6272 Atype : Component_Alignment_Kind;
6273 Typ : Entity_Id;
6275 begin
6276 GNAT_Pragma;
6277 Gather_Associations (Names, Args);
6279 if No (Form) then
6280 Error_Pragma ("missing Form argument for pragma%");
6281 end if;
6283 Check_Arg_Is_Identifier (Form);
6285 -- Get proper alignment, note that Default = Component_Size on all
6286 -- machines we have so far, and we want to set this value rather
6287 -- than the default value to indicate that it has been explicitly
6288 -- set (and thus will not get overridden by the default component
6289 -- alignment for the current scope)
6291 if Chars (Form) = Name_Component_Size then
6292 Atype := Calign_Component_Size;
6294 elsif Chars (Form) = Name_Component_Size_4 then
6295 Atype := Calign_Component_Size_4;
6297 elsif Chars (Form) = Name_Default then
6298 Atype := Calign_Component_Size;
6300 elsif Chars (Form) = Name_Storage_Unit then
6301 Atype := Calign_Storage_Unit;
6303 else
6304 Error_Pragma_Arg
6305 ("invalid Form parameter for pragma%", Form);
6306 end if;
6308 -- Case with no name, supplied, affects scope table entry
6310 if No (Name) then
6311 Scope_Stack.Table
6312 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6314 -- Case of name supplied
6316 else
6317 Check_Arg_Is_Local_Name (Name);
6318 Find_Type (Name);
6319 Typ := Entity (Name);
6321 if Typ = Any_Type
6322 or else Rep_Item_Too_Early (Typ, N)
6323 then
6324 return;
6325 else
6326 Typ := Underlying_Type (Typ);
6327 end if;
6329 if not Is_Record_Type (Typ)
6330 and then not Is_Array_Type (Typ)
6331 then
6332 Error_Pragma_Arg
6333 ("Name parameter of pragma% must identify record or " &
6334 "array type", Name);
6335 end if;
6337 -- An explicit Component_Alignment pragma overrides an
6338 -- implicit pragma Pack, but not an explicit one.
6340 if not Has_Pragma_Pack (Base_Type (Typ)) then
6341 Set_Is_Packed (Base_Type (Typ), False);
6342 Set_Component_Alignment (Base_Type (Typ), Atype);
6343 end if;
6344 end if;
6345 end Component_AlignmentP;
6347 ----------------
6348 -- Controlled --
6349 ----------------
6351 -- pragma Controlled (first_subtype_LOCAL_NAME);
6353 when Pragma_Controlled => Controlled : declare
6354 Arg : Node_Id;
6356 begin
6357 Check_No_Identifiers;
6358 Check_Arg_Count (1);
6359 Check_Arg_Is_Local_Name (Arg1);
6360 Arg := Expression (Arg1);
6362 if not Is_Entity_Name (Arg)
6363 or else not Is_Access_Type (Entity (Arg))
6364 then
6365 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6366 else
6367 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6368 end if;
6369 end Controlled;
6371 ----------------
6372 -- Convention --
6373 ----------------
6375 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6376 -- [Entity =>] LOCAL_NAME);
6378 when Pragma_Convention => Convention : declare
6379 C : Convention_Id;
6380 E : Entity_Id;
6381 pragma Warnings (Off, C);
6382 pragma Warnings (Off, E);
6383 begin
6384 Check_Arg_Order ((Name_Convention, Name_Entity));
6385 Check_Ada_83_Warning;
6386 Check_Arg_Count (2);
6387 Process_Convention (C, E);
6388 end Convention;
6390 ---------------------------
6391 -- Convention_Identifier --
6392 ---------------------------
6394 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6395 -- [Convention =>] convention_IDENTIFIER);
6397 when Pragma_Convention_Identifier => Convention_Identifier : declare
6398 Idnam : Name_Id;
6399 Cname : Name_Id;
6401 begin
6402 GNAT_Pragma;
6403 Check_Arg_Order ((Name_Name, Name_Convention));
6404 Check_Arg_Count (2);
6405 Check_Optional_Identifier (Arg1, Name_Name);
6406 Check_Optional_Identifier (Arg2, Name_Convention);
6407 Check_Arg_Is_Identifier (Arg1);
6408 Check_Arg_Is_Identifier (Arg2);
6409 Idnam := Chars (Expression (Arg1));
6410 Cname := Chars (Expression (Arg2));
6412 if Is_Convention_Name (Cname) then
6413 Record_Convention_Identifier
6414 (Idnam, Get_Convention_Id (Cname));
6415 else
6416 Error_Pragma_Arg
6417 ("second arg for % pragma must be convention", Arg2);
6418 end if;
6419 end Convention_Identifier;
6421 ---------------
6422 -- CPP_Class --
6423 ---------------
6425 -- pragma CPP_Class ([Entity =>] local_NAME)
6427 when Pragma_CPP_Class => CPP_Class : declare
6428 Arg : Node_Id;
6429 Typ : Entity_Id;
6431 begin
6432 if Warn_On_Obsolescent_Feature then
6433 Error_Msg_N
6434 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6435 " by pragma import?", N);
6436 end if;
6438 GNAT_Pragma;
6439 Check_Arg_Count (1);
6440 Check_Optional_Identifier (Arg1, Name_Entity);
6441 Check_Arg_Is_Local_Name (Arg1);
6443 Arg := Expression (Arg1);
6444 Analyze (Arg);
6446 if Etype (Arg) = Any_Type then
6447 return;
6448 end if;
6450 if not Is_Entity_Name (Arg)
6451 or else not Is_Type (Entity (Arg))
6452 then
6453 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6454 end if;
6456 Typ := Entity (Arg);
6458 if not Is_Tagged_Type (Typ) then
6459 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6460 end if;
6462 -- Types treated as CPP classes are treated as limited, but we
6463 -- don't require them to be declared this way. A warning is issued
6464 -- to encourage the user to declare them as limited. This is not
6465 -- an error, for compatibility reasons, because these types have
6466 -- been supported this way for some time.
6468 if not Is_Limited_Type (Typ) then
6469 Error_Msg_N
6470 ("imported 'C'P'P type should be " &
6471 "explicitly declared limited?",
6472 Get_Pragma_Arg (Arg1));
6473 Error_Msg_N
6474 ("\type will be considered limited",
6475 Get_Pragma_Arg (Arg1));
6476 end if;
6478 Set_Is_CPP_Class (Typ);
6479 Set_Is_Limited_Record (Typ);
6480 Set_Convention (Typ, Convention_CPP);
6482 -- Imported CPP types must not have discriminants (because C++
6483 -- classes do not have discriminants).
6485 if Has_Discriminants (Typ) then
6486 Error_Msg_N
6487 ("imported 'C'P'P type cannot have discriminants",
6488 First (Discriminant_Specifications
6489 (Declaration_Node (Typ))));
6490 end if;
6492 -- Components of imported CPP types must not have default
6493 -- expressions because the constructor (if any) is in the
6494 -- C++ side.
6496 if Is_Incomplete_Or_Private_Type (Typ)
6497 and then No (Underlying_Type (Typ))
6498 then
6499 -- It should be an error to apply pragma CPP to a private
6500 -- type if the underlying type is not visible (as it is
6501 -- for any representation item). For now, for backward
6502 -- compatibility we do nothing but we cannot check components
6503 -- because they are not available at this stage. All this code
6504 -- will be removed when we cleanup this obsolete GNAT pragma???
6506 null;
6508 else
6509 declare
6510 Tdef : constant Node_Id :=
6511 Type_Definition (Declaration_Node (Typ));
6512 Clist : Node_Id;
6513 Comp : Node_Id;
6515 begin
6516 if Nkind (Tdef) = N_Record_Definition then
6517 Clist := Component_List (Tdef);
6518 else
6519 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
6520 Clist := Component_List (Record_Extension_Part (Tdef));
6521 end if;
6523 if Present (Clist) then
6524 Comp := First (Component_Items (Clist));
6525 while Present (Comp) loop
6526 if Present (Expression (Comp)) then
6527 Error_Msg_N
6528 ("component of imported 'C'P'P type cannot have" &
6529 " default expression", Expression (Comp));
6530 end if;
6532 Next (Comp);
6533 end loop;
6534 end if;
6535 end;
6536 end if;
6537 end CPP_Class;
6539 ---------------------
6540 -- CPP_Constructor --
6541 ---------------------
6543 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
6544 -- [, [External_Name =>] static_string_EXPRESSION ]
6545 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6547 when Pragma_CPP_Constructor => CPP_Constructor : declare
6548 Elmt : Elmt_Id;
6549 Id : Entity_Id;
6550 Def_Id : Entity_Id;
6551 Tag_Typ : Entity_Id;
6553 begin
6554 GNAT_Pragma;
6555 Check_At_Least_N_Arguments (1);
6556 Check_At_Most_N_Arguments (3);
6557 Check_Optional_Identifier (Arg1, Name_Entity);
6558 Check_Arg_Is_Local_Name (Arg1);
6560 Id := Expression (Arg1);
6561 Find_Program_Unit_Name (Id);
6563 -- If we did not find the name, we are done
6565 if Etype (Id) = Any_Type then
6566 return;
6567 end if;
6569 Def_Id := Entity (Id);
6571 -- Check if already defined as constructor
6573 if Is_Constructor (Def_Id) then
6574 Error_Msg_N
6575 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
6576 return;
6577 end if;
6579 if Ekind (Def_Id) = E_Function
6580 and then (Is_CPP_Class (Etype (Def_Id))
6581 or else (Is_Class_Wide_Type (Etype (Def_Id))
6582 and then
6583 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
6584 then
6585 if Arg_Count >= 2 then
6586 Set_Imported (Def_Id);
6587 Set_Is_Public (Def_Id);
6588 Process_Interface_Name (Def_Id, Arg2, Arg3);
6589 end if;
6591 Set_Has_Completion (Def_Id);
6592 Set_Is_Constructor (Def_Id);
6594 -- Imported C++ constructors are not dispatching primitives
6595 -- because in C++ they don't have a dispatch table slot.
6596 -- However, in Ada the constructor has the profile of a
6597 -- function that returns a tagged type and therefore it has
6598 -- been treated as a primitive operation during semantic
6599 -- analysis. We now remove it from the list of primitive
6600 -- operations of the type.
6602 if Is_Tagged_Type (Etype (Def_Id))
6603 and then not Is_Class_Wide_Type (Etype (Def_Id))
6604 then
6605 pragma Assert (Is_Dispatching_Operation (Def_Id));
6606 Tag_Typ := Etype (Def_Id);
6608 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
6609 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
6610 Next_Elmt (Elmt);
6611 end loop;
6613 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
6614 Set_Is_Dispatching_Operation (Def_Id, False);
6615 end if;
6617 -- For backward compatibility, if the constructor returns a
6618 -- class wide type, and we internally change the return type to
6619 -- the corresponding root type.
6621 if Is_Class_Wide_Type (Etype (Def_Id)) then
6622 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
6623 end if;
6624 else
6625 Error_Pragma_Arg
6626 ("pragma% requires function returning a 'C'P'P_Class type",
6627 Arg1);
6628 end if;
6629 end CPP_Constructor;
6631 -----------------
6632 -- CPP_Virtual --
6633 -----------------
6635 when Pragma_CPP_Virtual => CPP_Virtual : declare
6636 begin
6637 GNAT_Pragma;
6639 if Warn_On_Obsolescent_Feature then
6640 Error_Msg_N
6641 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
6642 "no effect?", N);
6643 end if;
6644 end CPP_Virtual;
6646 ----------------
6647 -- CPP_Vtable --
6648 ----------------
6650 when Pragma_CPP_Vtable => CPP_Vtable : declare
6651 begin
6652 GNAT_Pragma;
6654 if Warn_On_Obsolescent_Feature then
6655 Error_Msg_N
6656 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
6657 "no effect?", N);
6658 end if;
6659 end CPP_Vtable;
6661 -----------
6662 -- Debug --
6663 -----------
6665 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
6667 when Pragma_Debug => Debug : declare
6668 Cond : Node_Id;
6670 begin
6671 GNAT_Pragma;
6673 Cond :=
6674 New_Occurrence_Of
6675 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
6676 Loc);
6678 if Arg_Count = 2 then
6679 Cond :=
6680 Make_And_Then (Loc,
6681 Left_Opnd => Relocate_Node (Cond),
6682 Right_Opnd => Expression (Arg1));
6683 end if;
6685 -- Rewrite into a conditional with an appropriate condition. We
6686 -- wrap the procedure call in a block so that overhead from e.g.
6687 -- use of the secondary stack does not generate execution overhead
6688 -- for suppressed conditions.
6690 Rewrite (N, Make_Implicit_If_Statement (N,
6691 Condition => Cond,
6692 Then_Statements => New_List (
6693 Make_Block_Statement (Loc,
6694 Handled_Statement_Sequence =>
6695 Make_Handled_Sequence_Of_Statements (Loc,
6696 Statements => New_List (
6697 Relocate_Node (Debug_Statement (N))))))));
6698 Analyze (N);
6699 end Debug;
6701 ------------------
6702 -- Debug_Policy --
6703 ------------------
6705 -- pragma Debug_Policy (Check | Ignore)
6707 when Pragma_Debug_Policy =>
6708 GNAT_Pragma;
6709 Check_Arg_Count (1);
6710 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6711 Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
6713 ---------------------
6714 -- Detect_Blocking --
6715 ---------------------
6717 -- pragma Detect_Blocking;
6719 when Pragma_Detect_Blocking =>
6720 Ada_2005_Pragma;
6721 Check_Arg_Count (0);
6722 Check_Valid_Configuration_Pragma;
6723 Detect_Blocking := True;
6725 ---------------
6726 -- Dimension --
6727 ---------------
6729 when Pragma_Dimension =>
6730 GNAT_Pragma;
6731 Check_Arg_Count (4);
6732 Check_No_Identifiers;
6733 Check_Arg_Is_Local_Name (Arg1);
6735 if not Is_Type (Arg1) then
6736 Error_Pragma ("first argument for pragma% must be subtype");
6737 end if;
6739 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
6740 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
6741 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
6743 -------------------
6744 -- Discard_Names --
6745 -------------------
6747 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
6749 when Pragma_Discard_Names => Discard_Names : declare
6750 E : Entity_Id;
6751 E_Id : Entity_Id;
6753 begin
6754 Check_Ada_83_Warning;
6756 -- Deal with configuration pragma case
6758 if Arg_Count = 0 and then Is_Configuration_Pragma then
6759 Global_Discard_Names := True;
6760 return;
6762 -- Otherwise, check correct appropriate context
6764 else
6765 Check_Is_In_Decl_Part_Or_Package_Spec;
6767 if Arg_Count = 0 then
6769 -- If there is no parameter, then from now on this pragma
6770 -- applies to any enumeration, exception or tagged type
6771 -- defined in the current declarative part, and recursively
6772 -- to any nested scope.
6774 Set_Discard_Names (Current_Scope);
6775 return;
6777 else
6778 Check_Arg_Count (1);
6779 Check_Optional_Identifier (Arg1, Name_On);
6780 Check_Arg_Is_Local_Name (Arg1);
6782 E_Id := Expression (Arg1);
6784 if Etype (E_Id) = Any_Type then
6785 return;
6786 else
6787 E := Entity (E_Id);
6788 end if;
6790 if (Is_First_Subtype (E)
6791 and then
6792 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
6793 or else Ekind (E) = E_Exception
6794 then
6795 Set_Discard_Names (E);
6796 else
6797 Error_Pragma_Arg
6798 ("inappropriate entity for pragma%", Arg1);
6799 end if;
6801 end if;
6802 end if;
6803 end Discard_Names;
6805 ---------------
6806 -- Elaborate --
6807 ---------------
6809 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
6811 when Pragma_Elaborate => Elaborate : declare
6812 Arg : Node_Id;
6813 Citem : Node_Id;
6815 begin
6816 -- Pragma must be in context items list of a compilation unit
6818 if not Is_In_Context_Clause then
6819 Pragma_Misplaced;
6820 end if;
6822 -- Must be at least one argument
6824 if Arg_Count = 0 then
6825 Error_Pragma ("pragma% requires at least one argument");
6826 end if;
6828 -- In Ada 83 mode, there can be no items following it in the
6829 -- context list except other pragmas and implicit with clauses
6830 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
6831 -- placement rule does not apply.
6833 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
6834 Citem := Next (N);
6835 while Present (Citem) loop
6836 if Nkind (Citem) = N_Pragma
6837 or else (Nkind (Citem) = N_With_Clause
6838 and then Implicit_With (Citem))
6839 then
6840 null;
6841 else
6842 Error_Pragma
6843 ("(Ada 83) pragma% must be at end of context clause");
6844 end if;
6846 Next (Citem);
6847 end loop;
6848 end if;
6850 -- Finally, the arguments must all be units mentioned in a with
6851 -- clause in the same context clause. Note we already checked (in
6852 -- Par.Prag) that the arguments are all identifiers or selected
6853 -- components.
6855 Arg := Arg1;
6856 Outer : while Present (Arg) loop
6857 Citem := First (List_Containing (N));
6858 Inner : while Citem /= N loop
6859 if Nkind (Citem) = N_With_Clause
6860 and then Same_Name (Name (Citem), Expression (Arg))
6861 then
6862 Set_Elaborate_Present (Citem, True);
6863 Set_Unit_Name (Expression (Arg), Name (Citem));
6865 -- With the pragma present, elaboration calls on
6866 -- subprograms from the named unit need no further
6867 -- checks, as long as the pragma appears in the current
6868 -- compilation unit. If the pragma appears in some unit
6869 -- in the context, there might still be a need for an
6870 -- Elaborate_All_Desirable from the current compilation
6871 -- to the named unit, so we keep the check enabled.
6873 if In_Extended_Main_Source_Unit (N) then
6874 Set_Suppress_Elaboration_Warnings
6875 (Entity (Name (Citem)));
6876 end if;
6878 exit Inner;
6879 end if;
6881 Next (Citem);
6882 end loop Inner;
6884 if Citem = N then
6885 Error_Pragma_Arg
6886 ("argument of pragma% is not with'ed unit", Arg);
6887 end if;
6889 Next (Arg);
6890 end loop Outer;
6892 -- Give a warning if operating in static mode with -gnatwl
6893 -- (elaboration warnings enabled) switch set.
6895 if Elab_Warnings and not Dynamic_Elaboration_Checks then
6896 Error_Msg_N
6897 ("?use of pragma Elaborate may not be safe", N);
6898 Error_Msg_N
6899 ("?use pragma Elaborate_All instead if possible", N);
6900 end if;
6901 end Elaborate;
6903 -------------------
6904 -- Elaborate_All --
6905 -------------------
6907 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
6909 when Pragma_Elaborate_All => Elaborate_All : declare
6910 Arg : Node_Id;
6911 Citem : Node_Id;
6913 begin
6914 Check_Ada_83_Warning;
6916 -- Pragma must be in context items list of a compilation unit
6918 if not Is_In_Context_Clause then
6919 Pragma_Misplaced;
6920 end if;
6922 -- Must be at least one argument
6924 if Arg_Count = 0 then
6925 Error_Pragma ("pragma% requires at least one argument");
6926 end if;
6928 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
6929 -- have to appear at the end of the context clause, but may
6930 -- appear mixed in with other items, even in Ada 83 mode.
6932 -- Final check: the arguments must all be units mentioned in
6933 -- a with clause in the same context clause. Note that we
6934 -- already checked (in Par.Prag) that all the arguments are
6935 -- either identifiers or selected components.
6937 Arg := Arg1;
6938 Outr : while Present (Arg) loop
6939 Citem := First (List_Containing (N));
6940 Innr : while Citem /= N loop
6941 if Nkind (Citem) = N_With_Clause
6942 and then Same_Name (Name (Citem), Expression (Arg))
6943 then
6944 Set_Elaborate_All_Present (Citem, True);
6945 Set_Unit_Name (Expression (Arg), Name (Citem));
6947 -- Suppress warnings and elaboration checks on the named
6948 -- unit if the pragma is in the current compilation, as
6949 -- for pragma Elaborate.
6951 if In_Extended_Main_Source_Unit (N) then
6952 Set_Suppress_Elaboration_Warnings
6953 (Entity (Name (Citem)));
6954 end if;
6955 exit Innr;
6956 end if;
6958 Next (Citem);
6959 end loop Innr;
6961 if Citem = N then
6962 Set_Error_Posted (N);
6963 Error_Pragma_Arg
6964 ("argument of pragma% is not with'ed unit", Arg);
6965 end if;
6967 Next (Arg);
6968 end loop Outr;
6969 end Elaborate_All;
6971 --------------------
6972 -- Elaborate_Body --
6973 --------------------
6975 -- pragma Elaborate_Body [( library_unit_NAME )];
6977 when Pragma_Elaborate_Body => Elaborate_Body : declare
6978 Cunit_Node : Node_Id;
6979 Cunit_Ent : Entity_Id;
6981 begin
6982 Check_Ada_83_Warning;
6983 Check_Valid_Library_Unit_Pragma;
6985 if Nkind (N) = N_Null_Statement then
6986 return;
6987 end if;
6989 Cunit_Node := Cunit (Current_Sem_Unit);
6990 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
6992 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
6993 N_Subprogram_Body)
6994 then
6995 Error_Pragma ("pragma% must refer to a spec, not a body");
6996 else
6997 Set_Body_Required (Cunit_Node, True);
6998 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7000 -- If we are in dynamic elaboration mode, then we suppress
7001 -- elaboration warnings for the unit, since it is definitely
7002 -- fine NOT to do dynamic checks at the first level (and such
7003 -- checks will be suppressed because no elaboration boolean
7004 -- is created for Elaborate_Body packages).
7006 -- But in the static model of elaboration, Elaborate_Body is
7007 -- definitely NOT good enough to ensure elaboration safety on
7008 -- its own, since the body may WITH other units that are not
7009 -- safe from an elaboration point of view, so a client must
7010 -- still do an Elaborate_All on such units.
7012 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7013 -- Elaborate_Body always suppressed elab warnings.
7015 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7016 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7017 end if;
7018 end if;
7019 end Elaborate_Body;
7021 ------------------------
7022 -- Elaboration_Checks --
7023 ------------------------
7025 -- pragma Elaboration_Checks (Static | Dynamic);
7027 when Pragma_Elaboration_Checks =>
7028 GNAT_Pragma;
7029 Check_Arg_Count (1);
7030 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7031 Dynamic_Elaboration_Checks :=
7032 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7034 ---------------
7035 -- Eliminate --
7036 ---------------
7038 -- pragma Eliminate (
7039 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7040 -- [,[Entity =>] IDENTIFIER |
7041 -- SELECTED_COMPONENT |
7042 -- STRING_LITERAL]
7043 -- [, OVERLOADING_RESOLUTION]);
7045 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7046 -- SOURCE_LOCATION
7048 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7049 -- FUNCTION_PROFILE
7051 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7053 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7054 -- Result_Type => result_SUBTYPE_NAME]
7056 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7057 -- SUBTYPE_NAME ::= STRING_LITERAL
7059 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7060 -- SOURCE_TRACE ::= STRING_LITERAL
7062 when Pragma_Eliminate => Eliminate : declare
7063 Args : Args_List (1 .. 5);
7064 Names : constant Name_List (1 .. 5) := (
7065 Name_Unit_Name,
7066 Name_Entity,
7067 Name_Parameter_Types,
7068 Name_Result_Type,
7069 Name_Source_Location);
7071 Unit_Name : Node_Id renames Args (1);
7072 Entity : Node_Id renames Args (2);
7073 Parameter_Types : Node_Id renames Args (3);
7074 Result_Type : Node_Id renames Args (4);
7075 Source_Location : Node_Id renames Args (5);
7077 begin
7078 GNAT_Pragma;
7079 Check_Valid_Configuration_Pragma;
7080 Gather_Associations (Names, Args);
7082 if No (Unit_Name) then
7083 Error_Pragma ("missing Unit_Name argument for pragma%");
7084 end if;
7086 if No (Entity)
7087 and then (Present (Parameter_Types)
7088 or else
7089 Present (Result_Type)
7090 or else
7091 Present (Source_Location))
7092 then
7093 Error_Pragma ("missing Entity argument for pragma%");
7094 end if;
7096 if (Present (Parameter_Types)
7097 or else
7098 Present (Result_Type))
7099 and then
7100 Present (Source_Location)
7101 then
7102 Error_Pragma
7103 ("parameter profile and source location cannot " &
7104 "be used together in pragma%");
7105 end if;
7107 Process_Eliminate_Pragma
7109 Unit_Name,
7110 Entity,
7111 Parameter_Types,
7112 Result_Type,
7113 Source_Location);
7114 end Eliminate;
7116 ------------
7117 -- Export --
7118 ------------
7120 -- pragma Export (
7121 -- [ Convention =>] convention_IDENTIFIER,
7122 -- [ Entity =>] local_NAME
7123 -- [, [External_Name =>] static_string_EXPRESSION ]
7124 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7126 when Pragma_Export => Export : declare
7127 C : Convention_Id;
7128 Def_Id : Entity_Id;
7130 pragma Warnings (Off, C);
7132 begin
7133 Check_Ada_83_Warning;
7134 Check_Arg_Order
7135 ((Name_Convention,
7136 Name_Entity,
7137 Name_External_Name,
7138 Name_Link_Name));
7139 Check_At_Least_N_Arguments (2);
7140 Check_At_Most_N_Arguments (4);
7141 Process_Convention (C, Def_Id);
7143 if Ekind (Def_Id) /= E_Constant then
7144 Note_Possible_Modification (Expression (Arg2), Sure => False);
7145 end if;
7147 Process_Interface_Name (Def_Id, Arg3, Arg4);
7148 Set_Exported (Def_Id, Arg2);
7150 -- If the entity is a deferred constant, propagate the information
7151 -- to the full view, because gigi elaborates the full view only.
7153 if Ekind (Def_Id) = E_Constant
7154 and then Present (Full_View (Def_Id))
7155 then
7156 declare
7157 Id2 : constant Entity_Id := Full_View (Def_Id);
7158 begin
7159 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7160 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7161 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7162 end;
7163 end if;
7164 end Export;
7166 ----------------------
7167 -- Export_Exception --
7168 ----------------------
7170 -- pragma Export_Exception (
7171 -- [Internal =>] LOCAL_NAME
7172 -- [, [External =>] EXTERNAL_SYMBOL]
7173 -- [, [Form =>] Ada | VMS]
7174 -- [, [Code =>] static_integer_EXPRESSION]);
7176 when Pragma_Export_Exception => Export_Exception : declare
7177 Args : Args_List (1 .. 4);
7178 Names : constant Name_List (1 .. 4) := (
7179 Name_Internal,
7180 Name_External,
7181 Name_Form,
7182 Name_Code);
7184 Internal : Node_Id renames Args (1);
7185 External : Node_Id renames Args (2);
7186 Form : Node_Id renames Args (3);
7187 Code : Node_Id renames Args (4);
7189 begin
7190 GNAT_Pragma;
7192 if Inside_A_Generic then
7193 Error_Pragma ("pragma% cannot be used for generic entities");
7194 end if;
7196 Gather_Associations (Names, Args);
7197 Process_Extended_Import_Export_Exception_Pragma (
7198 Arg_Internal => Internal,
7199 Arg_External => External,
7200 Arg_Form => Form,
7201 Arg_Code => Code);
7203 if not Is_VMS_Exception (Entity (Internal)) then
7204 Set_Exported (Entity (Internal), Internal);
7205 end if;
7206 end Export_Exception;
7208 ---------------------
7209 -- Export_Function --
7210 ---------------------
7212 -- pragma Export_Function (
7213 -- [Internal =>] LOCAL_NAME
7214 -- [, [External =>] EXTERNAL_SYMBOL]
7215 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7216 -- [, [Result_Type =>] TYPE_DESIGNATOR]
7217 -- [, [Mechanism =>] MECHANISM]
7218 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
7220 -- EXTERNAL_SYMBOL ::=
7221 -- IDENTIFIER
7222 -- | static_string_EXPRESSION
7224 -- PARAMETER_TYPES ::=
7225 -- null
7226 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7228 -- TYPE_DESIGNATOR ::=
7229 -- subtype_NAME
7230 -- | subtype_Name ' Access
7232 -- MECHANISM ::=
7233 -- MECHANISM_NAME
7234 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7236 -- MECHANISM_ASSOCIATION ::=
7237 -- [formal_parameter_NAME =>] MECHANISM_NAME
7239 -- MECHANISM_NAME ::=
7240 -- Value
7241 -- | Reference
7242 -- | Descriptor [([Class =>] CLASS_NAME)]
7244 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7246 when Pragma_Export_Function => Export_Function : declare
7247 Args : Args_List (1 .. 6);
7248 Names : constant Name_List (1 .. 6) := (
7249 Name_Internal,
7250 Name_External,
7251 Name_Parameter_Types,
7252 Name_Result_Type,
7253 Name_Mechanism,
7254 Name_Result_Mechanism);
7256 Internal : Node_Id renames Args (1);
7257 External : Node_Id renames Args (2);
7258 Parameter_Types : Node_Id renames Args (3);
7259 Result_Type : Node_Id renames Args (4);
7260 Mechanism : Node_Id renames Args (5);
7261 Result_Mechanism : Node_Id renames Args (6);
7263 begin
7264 GNAT_Pragma;
7265 Gather_Associations (Names, Args);
7266 Process_Extended_Import_Export_Subprogram_Pragma (
7267 Arg_Internal => Internal,
7268 Arg_External => External,
7269 Arg_Parameter_Types => Parameter_Types,
7270 Arg_Result_Type => Result_Type,
7271 Arg_Mechanism => Mechanism,
7272 Arg_Result_Mechanism => Result_Mechanism);
7273 end Export_Function;
7275 -------------------
7276 -- Export_Object --
7277 -------------------
7279 -- pragma Export_Object (
7280 -- [Internal =>] LOCAL_NAME
7281 -- [, [External =>] EXTERNAL_SYMBOL]
7282 -- [, [Size =>] EXTERNAL_SYMBOL]);
7284 -- EXTERNAL_SYMBOL ::=
7285 -- IDENTIFIER
7286 -- | static_string_EXPRESSION
7288 -- PARAMETER_TYPES ::=
7289 -- null
7290 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7292 -- TYPE_DESIGNATOR ::=
7293 -- subtype_NAME
7294 -- | subtype_Name ' Access
7296 -- MECHANISM ::=
7297 -- MECHANISM_NAME
7298 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7300 -- MECHANISM_ASSOCIATION ::=
7301 -- [formal_parameter_NAME =>] MECHANISM_NAME
7303 -- MECHANISM_NAME ::=
7304 -- Value
7305 -- | Reference
7306 -- | Descriptor [([Class =>] CLASS_NAME)]
7308 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7310 when Pragma_Export_Object => Export_Object : declare
7311 Args : Args_List (1 .. 3);
7312 Names : constant Name_List (1 .. 3) := (
7313 Name_Internal,
7314 Name_External,
7315 Name_Size);
7317 Internal : Node_Id renames Args (1);
7318 External : Node_Id renames Args (2);
7319 Size : Node_Id renames Args (3);
7321 begin
7322 GNAT_Pragma;
7323 Gather_Associations (Names, Args);
7324 Process_Extended_Import_Export_Object_Pragma (
7325 Arg_Internal => Internal,
7326 Arg_External => External,
7327 Arg_Size => Size);
7328 end Export_Object;
7330 ----------------------
7331 -- Export_Procedure --
7332 ----------------------
7334 -- pragma Export_Procedure (
7335 -- [Internal =>] LOCAL_NAME
7336 -- [, [External =>] EXTERNAL_SYMBOL]
7337 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7338 -- [, [Mechanism =>] MECHANISM]);
7340 -- EXTERNAL_SYMBOL ::=
7341 -- IDENTIFIER
7342 -- | static_string_EXPRESSION
7344 -- PARAMETER_TYPES ::=
7345 -- null
7346 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7348 -- TYPE_DESIGNATOR ::=
7349 -- subtype_NAME
7350 -- | subtype_Name ' Access
7352 -- MECHANISM ::=
7353 -- MECHANISM_NAME
7354 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7356 -- MECHANISM_ASSOCIATION ::=
7357 -- [formal_parameter_NAME =>] MECHANISM_NAME
7359 -- MECHANISM_NAME ::=
7360 -- Value
7361 -- | Reference
7362 -- | Descriptor [([Class =>] CLASS_NAME)]
7364 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7366 when Pragma_Export_Procedure => Export_Procedure : declare
7367 Args : Args_List (1 .. 4);
7368 Names : constant Name_List (1 .. 4) := (
7369 Name_Internal,
7370 Name_External,
7371 Name_Parameter_Types,
7372 Name_Mechanism);
7374 Internal : Node_Id renames Args (1);
7375 External : Node_Id renames Args (2);
7376 Parameter_Types : Node_Id renames Args (3);
7377 Mechanism : Node_Id renames Args (4);
7379 begin
7380 GNAT_Pragma;
7381 Gather_Associations (Names, Args);
7382 Process_Extended_Import_Export_Subprogram_Pragma (
7383 Arg_Internal => Internal,
7384 Arg_External => External,
7385 Arg_Parameter_Types => Parameter_Types,
7386 Arg_Mechanism => Mechanism);
7387 end Export_Procedure;
7389 ------------------
7390 -- Export_Value --
7391 ------------------
7393 -- pragma Export_Value (
7394 -- [Value =>] static_integer_EXPRESSION,
7395 -- [Link_Name =>] static_string_EXPRESSION);
7397 when Pragma_Export_Value =>
7398 GNAT_Pragma;
7399 Check_Arg_Order ((Name_Value, Name_Link_Name));
7400 Check_Arg_Count (2);
7402 Check_Optional_Identifier (Arg1, Name_Value);
7403 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7405 Check_Optional_Identifier (Arg2, Name_Link_Name);
7406 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7408 -----------------------------
7409 -- Export_Valued_Procedure --
7410 -----------------------------
7412 -- pragma Export_Valued_Procedure (
7413 -- [Internal =>] LOCAL_NAME
7414 -- [, [External =>] EXTERNAL_SYMBOL,]
7415 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7416 -- [, [Mechanism =>] MECHANISM]);
7418 -- EXTERNAL_SYMBOL ::=
7419 -- IDENTIFIER
7420 -- | static_string_EXPRESSION
7422 -- PARAMETER_TYPES ::=
7423 -- null
7424 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7426 -- TYPE_DESIGNATOR ::=
7427 -- subtype_NAME
7428 -- | subtype_Name ' Access
7430 -- MECHANISM ::=
7431 -- MECHANISM_NAME
7432 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7434 -- MECHANISM_ASSOCIATION ::=
7435 -- [formal_parameter_NAME =>] MECHANISM_NAME
7437 -- MECHANISM_NAME ::=
7438 -- Value
7439 -- | Reference
7440 -- | Descriptor [([Class =>] CLASS_NAME)]
7442 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7444 when Pragma_Export_Valued_Procedure =>
7445 Export_Valued_Procedure : declare
7446 Args : Args_List (1 .. 4);
7447 Names : constant Name_List (1 .. 4) := (
7448 Name_Internal,
7449 Name_External,
7450 Name_Parameter_Types,
7451 Name_Mechanism);
7453 Internal : Node_Id renames Args (1);
7454 External : Node_Id renames Args (2);
7455 Parameter_Types : Node_Id renames Args (3);
7456 Mechanism : Node_Id renames Args (4);
7458 begin
7459 GNAT_Pragma;
7460 Gather_Associations (Names, Args);
7461 Process_Extended_Import_Export_Subprogram_Pragma (
7462 Arg_Internal => Internal,
7463 Arg_External => External,
7464 Arg_Parameter_Types => Parameter_Types,
7465 Arg_Mechanism => Mechanism);
7466 end Export_Valued_Procedure;
7468 -------------------
7469 -- Extend_System --
7470 -------------------
7472 -- pragma Extend_System ([Name =>] Identifier);
7474 when Pragma_Extend_System => Extend_System : declare
7475 begin
7476 GNAT_Pragma;
7477 Check_Valid_Configuration_Pragma;
7478 Check_Arg_Count (1);
7479 Check_Optional_Identifier (Arg1, Name_Name);
7480 Check_Arg_Is_Identifier (Arg1);
7482 Get_Name_String (Chars (Expression (Arg1)));
7484 if Name_Len > 4
7485 and then Name_Buffer (1 .. 4) = "aux_"
7486 then
7487 if Present (System_Extend_Pragma_Arg) then
7488 if Chars (Expression (Arg1)) =
7489 Chars (Expression (System_Extend_Pragma_Arg))
7490 then
7491 null;
7492 else
7493 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
7494 Error_Pragma ("pragma% conflicts with that #");
7495 end if;
7497 else
7498 System_Extend_Pragma_Arg := Arg1;
7500 if not GNAT_Mode then
7501 System_Extend_Unit := Arg1;
7502 end if;
7503 end if;
7504 else
7505 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
7506 end if;
7507 end Extend_System;
7509 ------------------------
7510 -- Extensions_Allowed --
7511 ------------------------
7513 -- pragma Extensions_Allowed (ON | OFF);
7515 when Pragma_Extensions_Allowed =>
7516 GNAT_Pragma;
7517 Check_Arg_Count (1);
7518 Check_No_Identifiers;
7519 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7521 if Chars (Expression (Arg1)) = Name_On then
7522 Extensions_Allowed := True;
7523 Ada_Version := Ada_Version_Type'Last;
7525 else
7526 Extensions_Allowed := False;
7527 Ada_Version := Ada_Version_Explicit;
7528 end if;
7530 --------------
7531 -- External --
7532 --------------
7534 -- pragma External (
7535 -- [ Convention =>] convention_IDENTIFIER,
7536 -- [ Entity =>] local_NAME
7537 -- [, [External_Name =>] static_string_EXPRESSION ]
7538 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7540 when Pragma_External => External : declare
7541 Def_Id : Entity_Id;
7543 C : Convention_Id;
7544 pragma Warnings (Off, C);
7546 begin
7547 GNAT_Pragma;
7548 Check_Arg_Order
7549 ((Name_Convention,
7550 Name_Entity,
7551 Name_External_Name,
7552 Name_Link_Name));
7553 Check_At_Least_N_Arguments (2);
7554 Check_At_Most_N_Arguments (4);
7555 Process_Convention (C, Def_Id);
7556 Note_Possible_Modification (Expression (Arg2), Sure => False);
7557 Process_Interface_Name (Def_Id, Arg3, Arg4);
7558 Set_Exported (Def_Id, Arg2);
7559 end External;
7561 --------------------------
7562 -- External_Name_Casing --
7563 --------------------------
7565 -- pragma External_Name_Casing (
7566 -- UPPERCASE | LOWERCASE
7567 -- [, AS_IS | UPPERCASE | LOWERCASE]);
7569 when Pragma_External_Name_Casing => External_Name_Casing : declare
7570 begin
7571 GNAT_Pragma;
7572 Check_No_Identifiers;
7574 if Arg_Count = 2 then
7575 Check_Arg_Is_One_Of
7576 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
7578 case Chars (Get_Pragma_Arg (Arg2)) is
7579 when Name_As_Is =>
7580 Opt.External_Name_Exp_Casing := As_Is;
7582 when Name_Uppercase =>
7583 Opt.External_Name_Exp_Casing := Uppercase;
7585 when Name_Lowercase =>
7586 Opt.External_Name_Exp_Casing := Lowercase;
7588 when others =>
7589 null;
7590 end case;
7592 else
7593 Check_Arg_Count (1);
7594 end if;
7596 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
7598 case Chars (Get_Pragma_Arg (Arg1)) is
7599 when Name_Uppercase =>
7600 Opt.External_Name_Imp_Casing := Uppercase;
7602 when Name_Lowercase =>
7603 Opt.External_Name_Imp_Casing := Lowercase;
7605 when others =>
7606 null;
7607 end case;
7608 end External_Name_Casing;
7610 --------------------------
7611 -- Favor_Top_Level --
7612 --------------------------
7614 -- pragma Favor_Top_Level (type_NAME);
7616 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
7617 Named_Entity : Entity_Id;
7619 begin
7620 GNAT_Pragma;
7621 Check_No_Identifiers;
7622 Check_Arg_Count (1);
7623 Check_Arg_Is_Local_Name (Arg1);
7624 Named_Entity := Entity (Expression (Arg1));
7626 -- If it's an access-to-subprogram type (in particular, not a
7627 -- subtype), set the flag on that type.
7629 if Is_Access_Subprogram_Type (Named_Entity) then
7630 Set_Can_Use_Internal_Rep (Named_Entity, False);
7632 -- Otherwise it's an error (name denotes the wrong sort of entity)
7634 else
7635 Error_Pragma_Arg
7636 ("access-to-subprogram type expected", Expression (Arg1));
7637 end if;
7638 end Favor_Top_Level;
7640 ---------------
7641 -- Fast_Math --
7642 ---------------
7644 -- pragma Fast_Math;
7646 when Pragma_Fast_Math =>
7647 GNAT_Pragma;
7648 Check_No_Identifiers;
7649 Check_Valid_Configuration_Pragma;
7650 Fast_Math := True;
7652 ---------------------------
7653 -- Finalize_Storage_Only --
7654 ---------------------------
7656 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
7658 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
7659 Assoc : constant Node_Id := Arg1;
7660 Type_Id : constant Node_Id := Expression (Assoc);
7661 Typ : Entity_Id;
7663 begin
7664 GNAT_Pragma;
7665 Check_No_Identifiers;
7666 Check_Arg_Count (1);
7667 Check_Arg_Is_Local_Name (Arg1);
7669 Find_Type (Type_Id);
7670 Typ := Entity (Type_Id);
7672 if Typ = Any_Type
7673 or else Rep_Item_Too_Early (Typ, N)
7674 then
7675 return;
7676 else
7677 Typ := Underlying_Type (Typ);
7678 end if;
7680 if not Is_Controlled (Typ) then
7681 Error_Pragma ("pragma% must specify controlled type");
7682 end if;
7684 Check_First_Subtype (Arg1);
7686 if Finalize_Storage_Only (Typ) then
7687 Error_Pragma ("duplicate pragma%, only one allowed");
7689 elsif not Rep_Item_Too_Late (Typ, N) then
7690 Set_Finalize_Storage_Only (Base_Type (Typ), True);
7691 end if;
7692 end Finalize_Storage;
7694 --------------------------
7695 -- Float_Representation --
7696 --------------------------
7698 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
7700 -- FLOAT_REP ::= VAX_Float | IEEE_Float
7702 when Pragma_Float_Representation => Float_Representation : declare
7703 Argx : Node_Id;
7704 Digs : Nat;
7705 Ent : Entity_Id;
7707 begin
7708 GNAT_Pragma;
7710 if Arg_Count = 1 then
7711 Check_Valid_Configuration_Pragma;
7712 else
7713 Check_Arg_Count (2);
7714 Check_Optional_Identifier (Arg2, Name_Entity);
7715 Check_Arg_Is_Local_Name (Arg2);
7716 end if;
7718 Check_No_Identifier (Arg1);
7719 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
7721 if not OpenVMS_On_Target then
7722 if Chars (Expression (Arg1)) = Name_VAX_Float then
7723 Error_Pragma
7724 ("?pragma% ignored (applies only to Open'V'M'S)");
7725 end if;
7727 return;
7728 end if;
7730 -- One argument case
7732 if Arg_Count = 1 then
7733 if Chars (Expression (Arg1)) = Name_VAX_Float then
7734 if Opt.Float_Format = 'I' then
7735 Error_Pragma ("'I'E'E'E format previously specified");
7736 end if;
7738 Opt.Float_Format := 'V';
7740 else
7741 if Opt.Float_Format = 'V' then
7742 Error_Pragma ("'V'A'X format previously specified");
7743 end if;
7745 Opt.Float_Format := 'I';
7746 end if;
7748 Set_Standard_Fpt_Formats;
7750 -- Two argument case
7752 else
7753 Argx := Get_Pragma_Arg (Arg2);
7755 if not Is_Entity_Name (Argx)
7756 or else not Is_Floating_Point_Type (Entity (Argx))
7757 then
7758 Error_Pragma_Arg
7759 ("second argument of% pragma must be floating-point type",
7760 Arg2);
7761 end if;
7763 Ent := Entity (Argx);
7764 Digs := UI_To_Int (Digits_Value (Ent));
7766 -- Two arguments, VAX_Float case
7768 if Chars (Expression (Arg1)) = Name_VAX_Float then
7769 case Digs is
7770 when 6 => Set_F_Float (Ent);
7771 when 9 => Set_D_Float (Ent);
7772 when 15 => Set_G_Float (Ent);
7774 when others =>
7775 Error_Pragma_Arg
7776 ("wrong digits value, must be 6,9 or 15", Arg2);
7777 end case;
7779 -- Two arguments, IEEE_Float case
7781 else
7782 case Digs is
7783 when 6 => Set_IEEE_Short (Ent);
7784 when 15 => Set_IEEE_Long (Ent);
7786 when others =>
7787 Error_Pragma_Arg
7788 ("wrong digits value, must be 6 or 15", Arg2);
7789 end case;
7790 end if;
7791 end if;
7792 end Float_Representation;
7794 -----------
7795 -- Ident --
7796 -----------
7798 -- pragma Ident (static_string_EXPRESSION)
7800 -- Note: pragma Comment shares this processing. Pragma Comment is
7801 -- identical to Ident, except that the restriction of the argument to
7802 -- 31 characters and the placement restrictions are not enforced for
7803 -- pragma Comment.
7805 when Pragma_Ident | Pragma_Comment => Ident : declare
7806 Str : Node_Id;
7808 begin
7809 GNAT_Pragma;
7810 Check_Arg_Count (1);
7811 Check_No_Identifiers;
7812 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7813 Store_Note (N);
7815 -- For pragma Ident, preserve DEC compatibility by requiring the
7816 -- pragma to appear in a declarative part or package spec.
7818 if Prag_Id = Pragma_Ident then
7819 Check_Is_In_Decl_Part_Or_Package_Spec;
7820 end if;
7822 Str := Expr_Value_S (Expression (Arg1));
7824 declare
7825 CS : Node_Id;
7826 GP : Node_Id;
7828 begin
7829 GP := Parent (Parent (N));
7831 if Nkind_In (GP, N_Package_Declaration,
7832 N_Generic_Package_Declaration)
7833 then
7834 GP := Parent (GP);
7835 end if;
7837 -- If we have a compilation unit, then record the ident value,
7838 -- checking for improper duplication.
7840 if Nkind (GP) = N_Compilation_Unit then
7841 CS := Ident_String (Current_Sem_Unit);
7843 if Present (CS) then
7845 -- For Ident, we do not permit multiple instances
7847 if Prag_Id = Pragma_Ident then
7848 Error_Pragma ("duplicate% pragma not permitted");
7850 -- For Comment, we concatenate the string, unless we want
7851 -- to preserve the tree structure for ASIS.
7853 elsif not ASIS_Mode then
7854 Start_String (Strval (CS));
7855 Store_String_Char (' ');
7856 Store_String_Chars (Strval (Str));
7857 Set_Strval (CS, End_String);
7858 end if;
7860 else
7861 -- In VMS, the effect of IDENT is achieved by passing
7862 -- --identification=name as a --for-linker switch.
7864 if OpenVMS_On_Target then
7865 Start_String;
7866 Store_String_Chars
7867 ("--for-linker=--identification=");
7868 String_To_Name_Buffer (Strval (Str));
7869 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7871 -- Only the last processed IDENT is saved. The main
7872 -- purpose is so an IDENT associated with a main
7873 -- procedure will be used in preference to an IDENT
7874 -- associated with a with'd package.
7876 Replace_Linker_Option_String
7877 (End_String, "--for-linker=--identification=");
7878 end if;
7880 Set_Ident_String (Current_Sem_Unit, Str);
7881 end if;
7883 -- For subunits, we just ignore the Ident, since in GNAT these
7884 -- are not separate object files, and hence not separate units
7885 -- in the unit table.
7887 elsif Nkind (GP) = N_Subunit then
7888 null;
7890 -- Otherwise we have a misplaced pragma Ident, but we ignore
7891 -- this if we are in an instantiation, since it comes from
7892 -- a generic, and has no relevance to the instantiation.
7894 elsif Prag_Id = Pragma_Ident then
7895 if Instantiation_Location (Loc) = No_Location then
7896 Error_Pragma ("pragma% only allowed at outer level");
7897 end if;
7898 end if;
7899 end;
7900 end Ident;
7902 --------------------------
7903 -- Implemented_By_Entry --
7904 --------------------------
7906 -- pragma Implemented_By_Entry (DIRECT_NAME);
7908 when Pragma_Implemented_By_Entry => Implemented_By_Entry : declare
7909 Ent : Entity_Id;
7911 begin
7912 Ada_2005_Pragma;
7913 Check_Arg_Count (1);
7914 Check_No_Identifiers;
7915 Check_Arg_Is_Identifier (Arg1);
7916 Check_Arg_Is_Local_Name (Arg1);
7917 Ent := Entity (Expression (Arg1));
7919 -- Pragma Implemented_By_Entry must be applied only to protected
7920 -- synchronized or task interface primitives.
7922 if (Ekind (Ent) /= E_Function
7923 and then Ekind (Ent) /= E_Procedure)
7924 or else not Present (First_Formal (Ent))
7925 or else not Is_Concurrent_Interface (Etype (First_Formal (Ent)))
7926 then
7927 Error_Pragma_Arg
7928 ("pragma % must be applied to a concurrent interface " &
7929 "primitive", Arg1);
7931 else
7932 if Einfo.Implemented_By_Entry (Ent)
7933 and then Warn_On_Redundant_Constructs
7934 then
7935 Error_Pragma ("?duplicate pragma%!");
7936 else
7937 Set_Implemented_By_Entry (Ent);
7938 end if;
7939 end if;
7940 end Implemented_By_Entry;
7942 -----------------------
7943 -- Implicit_Packing --
7944 -----------------------
7946 -- pragma Implicit_Packing;
7948 when Pragma_Implicit_Packing =>
7949 GNAT_Pragma;
7950 Check_Arg_Count (0);
7951 Implicit_Packing := True;
7953 ------------
7954 -- Import --
7955 ------------
7957 -- pragma Import (
7958 -- [Convention =>] convention_IDENTIFIER,
7959 -- [Entity =>] local_NAME
7960 -- [, [External_Name =>] static_string_EXPRESSION ]
7961 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7963 when Pragma_Import =>
7964 Check_Ada_83_Warning;
7965 Check_Arg_Order
7966 ((Name_Convention,
7967 Name_Entity,
7968 Name_External_Name,
7969 Name_Link_Name));
7970 Check_At_Least_N_Arguments (2);
7971 Check_At_Most_N_Arguments (4);
7972 Process_Import_Or_Interface;
7974 ----------------------
7975 -- Import_Exception --
7976 ----------------------
7978 -- pragma Import_Exception (
7979 -- [Internal =>] LOCAL_NAME
7980 -- [, [External =>] EXTERNAL_SYMBOL]
7981 -- [, [Form =>] Ada | VMS]
7982 -- [, [Code =>] static_integer_EXPRESSION]);
7984 when Pragma_Import_Exception => Import_Exception : declare
7985 Args : Args_List (1 .. 4);
7986 Names : constant Name_List (1 .. 4) := (
7987 Name_Internal,
7988 Name_External,
7989 Name_Form,
7990 Name_Code);
7992 Internal : Node_Id renames Args (1);
7993 External : Node_Id renames Args (2);
7994 Form : Node_Id renames Args (3);
7995 Code : Node_Id renames Args (4);
7997 begin
7998 GNAT_Pragma;
7999 Gather_Associations (Names, Args);
8001 if Present (External) and then Present (Code) then
8002 Error_Pragma
8003 ("cannot give both External and Code options for pragma%");
8004 end if;
8006 Process_Extended_Import_Export_Exception_Pragma (
8007 Arg_Internal => Internal,
8008 Arg_External => External,
8009 Arg_Form => Form,
8010 Arg_Code => Code);
8012 if not Is_VMS_Exception (Entity (Internal)) then
8013 Set_Imported (Entity (Internal));
8014 end if;
8015 end Import_Exception;
8017 ---------------------
8018 -- Import_Function --
8019 ---------------------
8021 -- pragma Import_Function (
8022 -- [Internal =>] LOCAL_NAME,
8023 -- [, [External =>] EXTERNAL_SYMBOL]
8024 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8025 -- [, [Result_Type =>] SUBTYPE_MARK]
8026 -- [, [Mechanism =>] MECHANISM]
8027 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8028 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8030 -- EXTERNAL_SYMBOL ::=
8031 -- IDENTIFIER
8032 -- | static_string_EXPRESSION
8034 -- PARAMETER_TYPES ::=
8035 -- null
8036 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8038 -- TYPE_DESIGNATOR ::=
8039 -- subtype_NAME
8040 -- | subtype_Name ' Access
8042 -- MECHANISM ::=
8043 -- MECHANISM_NAME
8044 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8046 -- MECHANISM_ASSOCIATION ::=
8047 -- [formal_parameter_NAME =>] MECHANISM_NAME
8049 -- MECHANISM_NAME ::=
8050 -- Value
8051 -- | Reference
8052 -- | Descriptor [([Class =>] CLASS_NAME)]
8054 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8056 when Pragma_Import_Function => Import_Function : declare
8057 Args : Args_List (1 .. 7);
8058 Names : constant Name_List (1 .. 7) := (
8059 Name_Internal,
8060 Name_External,
8061 Name_Parameter_Types,
8062 Name_Result_Type,
8063 Name_Mechanism,
8064 Name_Result_Mechanism,
8065 Name_First_Optional_Parameter);
8067 Internal : Node_Id renames Args (1);
8068 External : Node_Id renames Args (2);
8069 Parameter_Types : Node_Id renames Args (3);
8070 Result_Type : Node_Id renames Args (4);
8071 Mechanism : Node_Id renames Args (5);
8072 Result_Mechanism : Node_Id renames Args (6);
8073 First_Optional_Parameter : Node_Id renames Args (7);
8075 begin
8076 GNAT_Pragma;
8077 Gather_Associations (Names, Args);
8078 Process_Extended_Import_Export_Subprogram_Pragma (
8079 Arg_Internal => Internal,
8080 Arg_External => External,
8081 Arg_Parameter_Types => Parameter_Types,
8082 Arg_Result_Type => Result_Type,
8083 Arg_Mechanism => Mechanism,
8084 Arg_Result_Mechanism => Result_Mechanism,
8085 Arg_First_Optional_Parameter => First_Optional_Parameter);
8086 end Import_Function;
8088 -------------------
8089 -- Import_Object --
8090 -------------------
8092 -- pragma Import_Object (
8093 -- [Internal =>] LOCAL_NAME
8094 -- [, [External =>] EXTERNAL_SYMBOL]
8095 -- [, [Size =>] EXTERNAL_SYMBOL]);
8097 -- EXTERNAL_SYMBOL ::=
8098 -- IDENTIFIER
8099 -- | static_string_EXPRESSION
8101 when Pragma_Import_Object => Import_Object : declare
8102 Args : Args_List (1 .. 3);
8103 Names : constant Name_List (1 .. 3) := (
8104 Name_Internal,
8105 Name_External,
8106 Name_Size);
8108 Internal : Node_Id renames Args (1);
8109 External : Node_Id renames Args (2);
8110 Size : Node_Id renames Args (3);
8112 begin
8113 GNAT_Pragma;
8114 Gather_Associations (Names, Args);
8115 Process_Extended_Import_Export_Object_Pragma (
8116 Arg_Internal => Internal,
8117 Arg_External => External,
8118 Arg_Size => Size);
8119 end Import_Object;
8121 ----------------------
8122 -- Import_Procedure --
8123 ----------------------
8125 -- pragma Import_Procedure (
8126 -- [Internal =>] LOCAL_NAME
8127 -- [, [External =>] EXTERNAL_SYMBOL]
8128 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8129 -- [, [Mechanism =>] MECHANISM]
8130 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8132 -- EXTERNAL_SYMBOL ::=
8133 -- IDENTIFIER
8134 -- | static_string_EXPRESSION
8136 -- PARAMETER_TYPES ::=
8137 -- null
8138 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8140 -- TYPE_DESIGNATOR ::=
8141 -- subtype_NAME
8142 -- | subtype_Name ' Access
8144 -- MECHANISM ::=
8145 -- MECHANISM_NAME
8146 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8148 -- MECHANISM_ASSOCIATION ::=
8149 -- [formal_parameter_NAME =>] MECHANISM_NAME
8151 -- MECHANISM_NAME ::=
8152 -- Value
8153 -- | Reference
8154 -- | Descriptor [([Class =>] CLASS_NAME)]
8156 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8158 when Pragma_Import_Procedure => Import_Procedure : declare
8159 Args : Args_List (1 .. 5);
8160 Names : constant Name_List (1 .. 5) := (
8161 Name_Internal,
8162 Name_External,
8163 Name_Parameter_Types,
8164 Name_Mechanism,
8165 Name_First_Optional_Parameter);
8167 Internal : Node_Id renames Args (1);
8168 External : Node_Id renames Args (2);
8169 Parameter_Types : Node_Id renames Args (3);
8170 Mechanism : Node_Id renames Args (4);
8171 First_Optional_Parameter : Node_Id renames Args (5);
8173 begin
8174 GNAT_Pragma;
8175 Gather_Associations (Names, Args);
8176 Process_Extended_Import_Export_Subprogram_Pragma (
8177 Arg_Internal => Internal,
8178 Arg_External => External,
8179 Arg_Parameter_Types => Parameter_Types,
8180 Arg_Mechanism => Mechanism,
8181 Arg_First_Optional_Parameter => First_Optional_Parameter);
8182 end Import_Procedure;
8184 -----------------------------
8185 -- Import_Valued_Procedure --
8186 -----------------------------
8188 -- pragma Import_Valued_Procedure (
8189 -- [Internal =>] LOCAL_NAME
8190 -- [, [External =>] EXTERNAL_SYMBOL]
8191 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8192 -- [, [Mechanism =>] MECHANISM]
8193 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8195 -- EXTERNAL_SYMBOL ::=
8196 -- IDENTIFIER
8197 -- | static_string_EXPRESSION
8199 -- PARAMETER_TYPES ::=
8200 -- null
8201 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8203 -- TYPE_DESIGNATOR ::=
8204 -- subtype_NAME
8205 -- | subtype_Name ' Access
8207 -- MECHANISM ::=
8208 -- MECHANISM_NAME
8209 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8211 -- MECHANISM_ASSOCIATION ::=
8212 -- [formal_parameter_NAME =>] MECHANISM_NAME
8214 -- MECHANISM_NAME ::=
8215 -- Value
8216 -- | Reference
8217 -- | Descriptor [([Class =>] CLASS_NAME)]
8219 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8221 when Pragma_Import_Valued_Procedure =>
8222 Import_Valued_Procedure : declare
8223 Args : Args_List (1 .. 5);
8224 Names : constant Name_List (1 .. 5) := (
8225 Name_Internal,
8226 Name_External,
8227 Name_Parameter_Types,
8228 Name_Mechanism,
8229 Name_First_Optional_Parameter);
8231 Internal : Node_Id renames Args (1);
8232 External : Node_Id renames Args (2);
8233 Parameter_Types : Node_Id renames Args (3);
8234 Mechanism : Node_Id renames Args (4);
8235 First_Optional_Parameter : Node_Id renames Args (5);
8237 begin
8238 GNAT_Pragma;
8239 Gather_Associations (Names, Args);
8240 Process_Extended_Import_Export_Subprogram_Pragma (
8241 Arg_Internal => Internal,
8242 Arg_External => External,
8243 Arg_Parameter_Types => Parameter_Types,
8244 Arg_Mechanism => Mechanism,
8245 Arg_First_Optional_Parameter => First_Optional_Parameter);
8246 end Import_Valued_Procedure;
8248 ------------------------
8249 -- Initialize_Scalars --
8250 ------------------------
8252 -- pragma Initialize_Scalars;
8254 when Pragma_Initialize_Scalars =>
8255 GNAT_Pragma;
8256 Check_Arg_Count (0);
8257 Check_Valid_Configuration_Pragma;
8258 Check_Restriction (No_Initialize_Scalars, N);
8260 -- Initialize_Scalars creates false positives in CodePeer,
8261 -- so ignore this pragma in this mode.
8263 if not Restriction_Active (No_Initialize_Scalars)
8264 and then not CodePeer_Mode
8265 then
8266 Init_Or_Norm_Scalars := True;
8267 Initialize_Scalars := True;
8268 end if;
8270 ------------
8271 -- Inline --
8272 ------------
8274 -- pragma Inline ( NAME {, NAME} );
8276 when Pragma_Inline =>
8278 -- Pragma is active if inlining option is active
8280 Process_Inline (Inline_Active);
8282 -------------------
8283 -- Inline_Always --
8284 -------------------
8286 -- pragma Inline_Always ( NAME {, NAME} );
8288 when Pragma_Inline_Always =>
8289 GNAT_Pragma;
8291 -- Pragma always active unless in CodePeer mode, since this causes
8292 -- walk order issues.
8294 if not CodePeer_Mode then
8295 Process_Inline (True);
8296 end if;
8298 --------------------
8299 -- Inline_Generic --
8300 --------------------
8302 -- pragma Inline_Generic (NAME {, NAME});
8304 when Pragma_Inline_Generic =>
8305 GNAT_Pragma;
8306 Process_Generic_List;
8308 ----------------------
8309 -- Inspection_Point --
8310 ----------------------
8312 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
8314 when Pragma_Inspection_Point => Inspection_Point : declare
8315 Arg : Node_Id;
8316 Exp : Node_Id;
8318 begin
8319 if Arg_Count > 0 then
8320 Arg := Arg1;
8321 loop
8322 Exp := Expression (Arg);
8323 Analyze (Exp);
8325 if not Is_Entity_Name (Exp)
8326 or else not Is_Object (Entity (Exp))
8327 then
8328 Error_Pragma_Arg ("object name required", Arg);
8329 end if;
8331 Next (Arg);
8332 exit when No (Arg);
8333 end loop;
8334 end if;
8335 end Inspection_Point;
8337 ---------------
8338 -- Interface --
8339 ---------------
8341 -- pragma Interface (
8342 -- [ Convention =>] convention_IDENTIFIER,
8343 -- [ Entity =>] local_NAME
8344 -- [, [External_Name =>] static_string_EXPRESSION ]
8345 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8347 when Pragma_Interface =>
8348 GNAT_Pragma;
8349 Check_Arg_Order
8350 ((Name_Convention,
8351 Name_Entity,
8352 Name_External_Name,
8353 Name_Link_Name));
8354 Check_At_Least_N_Arguments (2);
8355 Check_At_Most_N_Arguments (4);
8356 Process_Import_Or_Interface;
8358 -- In Ada 2005, the permission to use Interface (a reserved word)
8359 -- as a pragma name is considered an obsolescent feature.
8361 if Ada_Version >= Ada_2005 then
8362 Check_Restriction
8363 (No_Obsolescent_Features, Pragma_Identifier (N));
8364 end if;
8366 --------------------
8367 -- Interface_Name --
8368 --------------------
8370 -- pragma Interface_Name (
8371 -- [ Entity =>] local_NAME
8372 -- [,[External_Name =>] static_string_EXPRESSION ]
8373 -- [,[Link_Name =>] static_string_EXPRESSION ]);
8375 when Pragma_Interface_Name => Interface_Name : declare
8376 Id : Node_Id;
8377 Def_Id : Entity_Id;
8378 Hom_Id : Entity_Id;
8379 Found : Boolean;
8381 begin
8382 GNAT_Pragma;
8383 Check_Arg_Order
8384 ((Name_Entity, Name_External_Name, Name_Link_Name));
8385 Check_At_Least_N_Arguments (2);
8386 Check_At_Most_N_Arguments (3);
8387 Id := Expression (Arg1);
8388 Analyze (Id);
8390 if not Is_Entity_Name (Id) then
8391 Error_Pragma_Arg
8392 ("first argument for pragma% must be entity name", Arg1);
8393 elsif Etype (Id) = Any_Type then
8394 return;
8395 else
8396 Def_Id := Entity (Id);
8397 end if;
8399 -- Special DEC-compatible processing for the object case, forces
8400 -- object to be imported.
8402 if Ekind (Def_Id) = E_Variable then
8403 Kill_Size_Check_Code (Def_Id);
8404 Note_Possible_Modification (Id, Sure => False);
8406 -- Initialization is not allowed for imported variable
8408 if Present (Expression (Parent (Def_Id)))
8409 and then Comes_From_Source (Expression (Parent (Def_Id)))
8410 then
8411 Error_Msg_Sloc := Sloc (Def_Id);
8412 Error_Pragma_Arg
8413 ("no initialization allowed for declaration of& #",
8414 Arg2);
8416 else
8417 -- For compatibility, support VADS usage of providing both
8418 -- pragmas Interface and Interface_Name to obtain the effect
8419 -- of a single Import pragma.
8421 if Is_Imported (Def_Id)
8422 and then Present (First_Rep_Item (Def_Id))
8423 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
8424 and then
8425 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
8426 then
8427 null;
8428 else
8429 Set_Imported (Def_Id);
8430 end if;
8432 Set_Is_Public (Def_Id);
8433 Process_Interface_Name (Def_Id, Arg2, Arg3);
8434 end if;
8436 -- Otherwise must be subprogram
8438 elsif not Is_Subprogram (Def_Id) then
8439 Error_Pragma_Arg
8440 ("argument of pragma% is not subprogram", Arg1);
8442 else
8443 Check_At_Most_N_Arguments (3);
8444 Hom_Id := Def_Id;
8445 Found := False;
8447 -- Loop through homonyms
8449 loop
8450 Def_Id := Get_Base_Subprogram (Hom_Id);
8452 if Is_Imported (Def_Id) then
8453 Process_Interface_Name (Def_Id, Arg2, Arg3);
8454 Found := True;
8455 end if;
8457 Hom_Id := Homonym (Hom_Id);
8459 exit when No (Hom_Id)
8460 or else Scope (Hom_Id) /= Current_Scope;
8461 end loop;
8463 if not Found then
8464 Error_Pragma_Arg
8465 ("argument of pragma% is not imported subprogram",
8466 Arg1);
8467 end if;
8468 end if;
8469 end Interface_Name;
8471 -----------------------
8472 -- Interrupt_Handler --
8473 -----------------------
8475 -- pragma Interrupt_Handler (handler_NAME);
8477 when Pragma_Interrupt_Handler =>
8478 Check_Ada_83_Warning;
8479 Check_Arg_Count (1);
8480 Check_No_Identifiers;
8482 if No_Run_Time_Mode then
8483 Error_Msg_CRT ("Interrupt_Handler pragma", N);
8484 else
8485 Check_Interrupt_Or_Attach_Handler;
8486 Process_Interrupt_Or_Attach_Handler;
8487 end if;
8489 ------------------------
8490 -- Interrupt_Priority --
8491 ------------------------
8493 -- pragma Interrupt_Priority [(EXPRESSION)];
8495 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
8496 P : constant Node_Id := Parent (N);
8497 Arg : Node_Id;
8499 begin
8500 Check_Ada_83_Warning;
8502 if Arg_Count /= 0 then
8503 Arg := Expression (Arg1);
8504 Check_Arg_Count (1);
8505 Check_No_Identifiers;
8507 -- The expression must be analyzed in the special manner
8508 -- described in "Handling of Default and Per-Object
8509 -- Expressions" in sem.ads.
8511 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
8512 end if;
8514 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
8515 Pragma_Misplaced;
8516 return;
8518 elsif Has_Priority_Pragma (P) then
8519 Error_Pragma ("duplicate pragma% not allowed");
8521 else
8522 Set_Has_Priority_Pragma (P, True);
8523 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8524 end if;
8525 end Interrupt_Priority;
8527 ---------------------
8528 -- Interrupt_State --
8529 ---------------------
8531 -- pragma Interrupt_State (
8532 -- [Name =>] INTERRUPT_ID,
8533 -- [State =>] INTERRUPT_STATE);
8535 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
8536 -- INTERRUPT_STATE => System | Runtime | User
8538 -- Note: if the interrupt id is given as an identifier, then it must
8539 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
8540 -- given as a static integer expression which must be in the range of
8541 -- Ada.Interrupts.Interrupt_ID.
8543 when Pragma_Interrupt_State => Interrupt_State : declare
8545 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
8546 -- This is the entity Ada.Interrupts.Interrupt_ID;
8548 State_Type : Character;
8549 -- Set to 's'/'r'/'u' for System/Runtime/User
8551 IST_Num : Pos;
8552 -- Index to entry in Interrupt_States table
8554 Int_Val : Uint;
8555 -- Value of interrupt
8557 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
8558 -- The first argument to the pragma
8560 Int_Ent : Entity_Id;
8561 -- Interrupt entity in Ada.Interrupts.Names
8563 begin
8564 GNAT_Pragma;
8565 Check_Arg_Order ((Name_Name, Name_State));
8566 Check_Arg_Count (2);
8568 Check_Optional_Identifier (Arg1, Name_Name);
8569 Check_Optional_Identifier (Arg2, Name_State);
8570 Check_Arg_Is_Identifier (Arg2);
8572 -- First argument is identifier
8574 if Nkind (Arg1X) = N_Identifier then
8576 -- Search list of names in Ada.Interrupts.Names
8578 Int_Ent := First_Entity (RTE (RE_Names));
8579 loop
8580 if No (Int_Ent) then
8581 Error_Pragma_Arg ("invalid interrupt name", Arg1);
8583 elsif Chars (Int_Ent) = Chars (Arg1X) then
8584 Int_Val := Expr_Value (Constant_Value (Int_Ent));
8585 exit;
8586 end if;
8588 Next_Entity (Int_Ent);
8589 end loop;
8591 -- First argument is not an identifier, so it must be a static
8592 -- expression of type Ada.Interrupts.Interrupt_ID.
8594 else
8595 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8596 Int_Val := Expr_Value (Arg1X);
8598 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
8599 or else
8600 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
8601 then
8602 Error_Pragma_Arg
8603 ("value not in range of type " &
8604 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
8605 end if;
8606 end if;
8608 -- Check OK state
8610 case Chars (Get_Pragma_Arg (Arg2)) is
8611 when Name_Runtime => State_Type := 'r';
8612 when Name_System => State_Type := 's';
8613 when Name_User => State_Type := 'u';
8615 when others =>
8616 Error_Pragma_Arg ("invalid interrupt state", Arg2);
8617 end case;
8619 -- Check if entry is already stored
8621 IST_Num := Interrupt_States.First;
8622 loop
8623 -- If entry not found, add it
8625 if IST_Num > Interrupt_States.Last then
8626 Interrupt_States.Append
8627 ((Interrupt_Number => UI_To_Int (Int_Val),
8628 Interrupt_State => State_Type,
8629 Pragma_Loc => Loc));
8630 exit;
8632 -- Case of entry for the same entry
8634 elsif Int_Val = Interrupt_States.Table (IST_Num).
8635 Interrupt_Number
8636 then
8637 -- If state matches, done, no need to make redundant entry
8639 exit when
8640 State_Type = Interrupt_States.Table (IST_Num).
8641 Interrupt_State;
8643 -- Otherwise if state does not match, error
8645 Error_Msg_Sloc :=
8646 Interrupt_States.Table (IST_Num).Pragma_Loc;
8647 Error_Pragma_Arg
8648 ("state conflicts with that given #", Arg2);
8649 exit;
8650 end if;
8652 IST_Num := IST_Num + 1;
8653 end loop;
8654 end Interrupt_State;
8656 ----------------------
8657 -- Java_Constructor --
8658 ----------------------
8660 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
8662 -- Also handles pragma CIL_Constructor
8664 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
8665 Java_Constructor : declare
8666 Id : Entity_Id;
8667 Def_Id : Entity_Id;
8668 Hom_Id : Entity_Id;
8669 Convention : Convention_Id;
8671 begin
8672 GNAT_Pragma;
8673 Check_Arg_Count (1);
8674 Check_Optional_Identifier (Arg1, Name_Entity);
8675 Check_Arg_Is_Local_Name (Arg1);
8677 Id := Expression (Arg1);
8678 Find_Program_Unit_Name (Id);
8680 -- If we did not find the name, we are done
8682 if Etype (Id) = Any_Type then
8683 return;
8684 end if;
8686 case Prag_Id is
8687 when Pragma_CIL_Constructor => Convention := Convention_CIL;
8688 when Pragma_Java_Constructor => Convention := Convention_Java;
8689 when others => null;
8690 end case;
8692 Hom_Id := Entity (Id);
8694 -- Loop through homonyms
8696 loop
8697 Def_Id := Get_Base_Subprogram (Hom_Id);
8699 -- The constructor is required to be a function returning an
8700 -- access type whose designated type has convention Java/CIL.
8702 if Ekind (Def_Id) = E_Function
8703 and then
8704 (Is_Value_Type (Etype (Def_Id))
8705 or else
8706 (Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
8707 and then
8708 Atree.Convention (Etype (Def_Id)) = Convention)
8709 or else
8710 (Ekind (Etype (Def_Id)) in Access_Kind
8711 and then
8712 (Atree.Convention
8713 (Designated_Type (Etype (Def_Id))) = Convention
8714 or else
8715 Atree.Convention
8716 (Root_Type (Designated_Type (Etype (Def_Id)))) =
8717 Convention)))
8718 then
8719 Set_Is_Constructor (Def_Id);
8720 Set_Convention (Def_Id, Convention);
8721 Set_Is_Imported (Def_Id);
8723 else
8724 if Convention = Convention_Java then
8725 Error_Pragma_Arg
8726 ("pragma% requires function returning a " &
8727 "'Java access type", Arg1);
8728 else
8729 pragma Assert (Convention = Convention_CIL);
8730 Error_Pragma_Arg
8731 ("pragma% requires function returning a " &
8732 "'C'I'L access type", Arg1);
8733 end if;
8734 end if;
8736 Hom_Id := Homonym (Hom_Id);
8738 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
8739 end loop;
8740 end Java_Constructor;
8742 ----------------------
8743 -- Java_Interface --
8744 ----------------------
8746 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
8748 when Pragma_Java_Interface => Java_Interface : declare
8749 Arg : Node_Id;
8750 Typ : Entity_Id;
8752 begin
8753 GNAT_Pragma;
8754 Check_Arg_Count (1);
8755 Check_Optional_Identifier (Arg1, Name_Entity);
8756 Check_Arg_Is_Local_Name (Arg1);
8758 Arg := Expression (Arg1);
8759 Analyze (Arg);
8761 if Etype (Arg) = Any_Type then
8762 return;
8763 end if;
8765 if not Is_Entity_Name (Arg)
8766 or else not Is_Type (Entity (Arg))
8767 then
8768 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
8769 end if;
8771 Typ := Underlying_Type (Entity (Arg));
8773 -- For now simply check some of the semantic constraints on the
8774 -- type. This currently leaves out some restrictions on interface
8775 -- types, namely that the parent type must be java.lang.Object.Typ
8776 -- and that all primitives of the type should be declared
8777 -- abstract. ???
8779 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
8780 Error_Pragma_Arg ("pragma% requires an abstract "
8781 & "tagged type", Arg1);
8783 elsif not Has_Discriminants (Typ)
8784 or else Ekind (Etype (First_Discriminant (Typ)))
8785 /= E_Anonymous_Access_Type
8786 or else
8787 not Is_Class_Wide_Type
8788 (Designated_Type (Etype (First_Discriminant (Typ))))
8789 then
8790 Error_Pragma_Arg
8791 ("type must have a class-wide access discriminant", Arg1);
8792 end if;
8793 end Java_Interface;
8795 ----------------
8796 -- Keep_Names --
8797 ----------------
8799 -- pragma Keep_Names ([On => ] local_NAME);
8801 when Pragma_Keep_Names => Keep_Names : declare
8802 Arg : Node_Id;
8804 begin
8805 GNAT_Pragma;
8806 Check_Arg_Count (1);
8807 Check_Optional_Identifier (Arg1, Name_On);
8808 Check_Arg_Is_Local_Name (Arg1);
8810 Arg := Expression (Arg1);
8811 Analyze (Arg);
8813 if Etype (Arg) = Any_Type then
8814 return;
8815 end if;
8817 if not Is_Entity_Name (Arg)
8818 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
8819 then
8820 Error_Pragma_Arg
8821 ("pragma% requires a local enumeration type", Arg1);
8822 end if;
8824 Set_Discard_Names (Entity (Arg), False);
8825 end Keep_Names;
8827 -------------
8828 -- License --
8829 -------------
8831 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
8833 when Pragma_License =>
8834 GNAT_Pragma;
8835 Check_Arg_Count (1);
8836 Check_No_Identifiers;
8837 Check_Valid_Configuration_Pragma;
8838 Check_Arg_Is_Identifier (Arg1);
8840 declare
8841 Sind : constant Source_File_Index :=
8842 Source_Index (Current_Sem_Unit);
8844 begin
8845 case Chars (Get_Pragma_Arg (Arg1)) is
8846 when Name_GPL =>
8847 Set_License (Sind, GPL);
8849 when Name_Modified_GPL =>
8850 Set_License (Sind, Modified_GPL);
8852 when Name_Restricted =>
8853 Set_License (Sind, Restricted);
8855 when Name_Unrestricted =>
8856 Set_License (Sind, Unrestricted);
8858 when others =>
8859 Error_Pragma_Arg ("invalid license name", Arg1);
8860 end case;
8861 end;
8863 ---------------
8864 -- Link_With --
8865 ---------------
8867 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
8869 when Pragma_Link_With => Link_With : declare
8870 Arg : Node_Id;
8872 begin
8873 GNAT_Pragma;
8875 if Operating_Mode = Generate_Code
8876 and then In_Extended_Main_Source_Unit (N)
8877 then
8878 Check_At_Least_N_Arguments (1);
8879 Check_No_Identifiers;
8880 Check_Is_In_Decl_Part_Or_Package_Spec;
8881 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8882 Start_String;
8884 Arg := Arg1;
8885 while Present (Arg) loop
8886 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8888 -- Store argument, converting sequences of spaces to a
8889 -- single null character (this is one of the differences
8890 -- in processing between Link_With and Linker_Options).
8892 Arg_Store : declare
8893 C : constant Char_Code := Get_Char_Code (' ');
8894 S : constant String_Id :=
8895 Strval (Expr_Value_S (Expression (Arg)));
8896 L : constant Nat := String_Length (S);
8897 F : Nat := 1;
8899 procedure Skip_Spaces;
8900 -- Advance F past any spaces
8902 -----------------
8903 -- Skip_Spaces --
8904 -----------------
8906 procedure Skip_Spaces is
8907 begin
8908 while F <= L and then Get_String_Char (S, F) = C loop
8909 F := F + 1;
8910 end loop;
8911 end Skip_Spaces;
8913 -- Start of processing for Arg_Store
8915 begin
8916 Skip_Spaces; -- skip leading spaces
8918 -- Loop through characters, changing any embedded
8919 -- sequence of spaces to a single null character (this
8920 -- is how Link_With/Linker_Options differ)
8922 while F <= L loop
8923 if Get_String_Char (S, F) = C then
8924 Skip_Spaces;
8925 exit when F > L;
8926 Store_String_Char (ASCII.NUL);
8928 else
8929 Store_String_Char (Get_String_Char (S, F));
8930 F := F + 1;
8931 end if;
8932 end loop;
8933 end Arg_Store;
8935 Arg := Next (Arg);
8937 if Present (Arg) then
8938 Store_String_Char (ASCII.NUL);
8939 end if;
8940 end loop;
8942 Store_Linker_Option_String (End_String);
8943 end if;
8944 end Link_With;
8946 ------------------
8947 -- Linker_Alias --
8948 ------------------
8950 -- pragma Linker_Alias (
8951 -- [Entity =>] LOCAL_NAME
8952 -- [Target =>] static_string_EXPRESSION);
8954 when Pragma_Linker_Alias =>
8955 GNAT_Pragma;
8956 Check_Arg_Order ((Name_Entity, Name_Target));
8957 Check_Arg_Count (2);
8958 Check_Optional_Identifier (Arg1, Name_Entity);
8959 Check_Optional_Identifier (Arg2, Name_Target);
8960 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8961 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8963 -- The only processing required is to link this item on to the
8964 -- list of rep items for the given entity. This is accomplished
8965 -- by the call to Rep_Item_Too_Late (when no error is detected
8966 -- and False is returned).
8968 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8969 return;
8970 else
8971 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8972 end if;
8974 ------------------------
8975 -- Linker_Constructor --
8976 ------------------------
8978 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
8980 -- Code is shared with Linker_Destructor
8982 -----------------------
8983 -- Linker_Destructor --
8984 -----------------------
8986 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
8988 when Pragma_Linker_Constructor |
8989 Pragma_Linker_Destructor =>
8990 Linker_Constructor : declare
8991 Arg1_X : Node_Id;
8992 Proc : Entity_Id;
8994 begin
8995 GNAT_Pragma;
8996 Check_Arg_Count (1);
8997 Check_No_Identifiers;
8998 Check_Arg_Is_Local_Name (Arg1);
8999 Arg1_X := Expression (Arg1);
9000 Analyze (Arg1_X);
9001 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
9003 if not Is_Library_Level_Entity (Proc) then
9004 Error_Pragma_Arg
9005 ("argument for pragma% must be library level entity", Arg1);
9006 end if;
9008 -- The only processing required is to link this item on to the
9009 -- list of rep items for the given entity. This is accomplished
9010 -- by the call to Rep_Item_Too_Late (when no error is detected
9011 -- and False is returned).
9013 if Rep_Item_Too_Late (Proc, N) then
9014 return;
9015 else
9016 Set_Has_Gigi_Rep_Item (Proc);
9017 end if;
9018 end Linker_Constructor;
9020 --------------------
9021 -- Linker_Options --
9022 --------------------
9024 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
9026 when Pragma_Linker_Options => Linker_Options : declare
9027 Arg : Node_Id;
9029 begin
9030 Check_Ada_83_Warning;
9031 Check_No_Identifiers;
9032 Check_Arg_Count (1);
9033 Check_Is_In_Decl_Part_Or_Package_Spec;
9034 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9035 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
9037 Arg := Arg2;
9038 while Present (Arg) loop
9039 Check_Arg_Is_Static_Expression (Arg, Standard_String);
9040 Store_String_Char (ASCII.NUL);
9041 Store_String_Chars (Strval (Expr_Value_S (Expression (Arg))));
9042 Arg := Next (Arg);
9043 end loop;
9045 if Operating_Mode = Generate_Code
9046 and then In_Extended_Main_Source_Unit (N)
9047 then
9048 Store_Linker_Option_String (End_String);
9049 end if;
9050 end Linker_Options;
9052 --------------------
9053 -- Linker_Section --
9054 --------------------
9056 -- pragma Linker_Section (
9057 -- [Entity =>] LOCAL_NAME
9058 -- [Section =>] static_string_EXPRESSION);
9060 when Pragma_Linker_Section =>
9061 GNAT_Pragma;
9062 Check_Arg_Order ((Name_Entity, Name_Section));
9063 Check_Arg_Count (2);
9064 Check_Optional_Identifier (Arg1, Name_Entity);
9065 Check_Optional_Identifier (Arg2, Name_Section);
9066 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9067 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9069 -- This pragma applies only to objects
9071 if not Is_Object (Entity (Expression (Arg1))) then
9072 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
9073 end if;
9075 -- The only processing required is to link this item on to the
9076 -- list of rep items for the given entity. This is accomplished
9077 -- by the call to Rep_Item_Too_Late (when no error is detected
9078 -- and False is returned).
9080 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
9081 return;
9082 else
9083 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
9084 end if;
9086 ----------
9087 -- List --
9088 ----------
9090 -- pragma List (On | Off)
9092 -- There is nothing to do here, since we did all the processing for
9093 -- this pragma in Par.Prag (so that it works properly even in syntax
9094 -- only mode).
9096 when Pragma_List =>
9097 null;
9099 --------------------
9100 -- Locking_Policy --
9101 --------------------
9103 -- pragma Locking_Policy (policy_IDENTIFIER);
9105 when Pragma_Locking_Policy => declare
9106 LP : Character;
9108 begin
9109 Check_Ada_83_Warning;
9110 Check_Arg_Count (1);
9111 Check_No_Identifiers;
9112 Check_Arg_Is_Locking_Policy (Arg1);
9113 Check_Valid_Configuration_Pragma;
9114 Get_Name_String (Chars (Expression (Arg1)));
9115 LP := Fold_Upper (Name_Buffer (1));
9117 if Locking_Policy /= ' '
9118 and then Locking_Policy /= LP
9119 then
9120 Error_Msg_Sloc := Locking_Policy_Sloc;
9121 Error_Pragma ("locking policy incompatible with policy#");
9123 -- Set new policy, but always preserve System_Location since we
9124 -- like the error message with the run time name.
9126 else
9127 Locking_Policy := LP;
9129 if Locking_Policy_Sloc /= System_Location then
9130 Locking_Policy_Sloc := Loc;
9131 end if;
9132 end if;
9133 end;
9135 ----------------
9136 -- Long_Float --
9137 ----------------
9139 -- pragma Long_Float (D_Float | G_Float);
9141 when Pragma_Long_Float =>
9142 GNAT_Pragma;
9143 Check_Valid_Configuration_Pragma;
9144 Check_Arg_Count (1);
9145 Check_No_Identifier (Arg1);
9146 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
9148 if not OpenVMS_On_Target then
9149 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
9150 end if;
9152 -- D_Float case
9154 if Chars (Expression (Arg1)) = Name_D_Float then
9155 if Opt.Float_Format_Long = 'G' then
9156 Error_Pragma ("G_Float previously specified");
9157 end if;
9159 Opt.Float_Format_Long := 'D';
9161 -- G_Float case (this is the default, does not need overriding)
9163 else
9164 if Opt.Float_Format_Long = 'D' then
9165 Error_Pragma ("D_Float previously specified");
9166 end if;
9168 Opt.Float_Format_Long := 'G';
9169 end if;
9171 Set_Standard_Fpt_Formats;
9173 -----------------------
9174 -- Machine_Attribute --
9175 -----------------------
9177 -- pragma Machine_Attribute (
9178 -- [Entity =>] LOCAL_NAME,
9179 -- [Attribute_Name =>] static_string_EXPRESSION
9180 -- [, [Info =>] static_EXPRESSION] );
9182 when Pragma_Machine_Attribute => Machine_Attribute : declare
9183 Def_Id : Entity_Id;
9185 begin
9186 GNAT_Pragma;
9187 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
9189 if Arg_Count = 3 then
9190 Check_Optional_Identifier (Arg3, Name_Info);
9191 Check_Arg_Is_Static_Expression (Arg3);
9192 else
9193 Check_Arg_Count (2);
9194 end if;
9196 Check_Optional_Identifier (Arg1, Name_Entity);
9197 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
9198 Check_Arg_Is_Local_Name (Arg1);
9199 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9200 Def_Id := Entity (Expression (Arg1));
9202 if Is_Access_Type (Def_Id) then
9203 Def_Id := Designated_Type (Def_Id);
9204 end if;
9206 if Rep_Item_Too_Early (Def_Id, N) then
9207 return;
9208 end if;
9210 Def_Id := Underlying_Type (Def_Id);
9212 -- The only processing required is to link this item on to the
9213 -- list of rep items for the given entity. This is accomplished
9214 -- by the call to Rep_Item_Too_Late (when no error is detected
9215 -- and False is returned).
9217 if Rep_Item_Too_Late (Def_Id, N) then
9218 return;
9219 else
9220 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
9221 end if;
9222 end Machine_Attribute;
9224 ----------
9225 -- Main --
9226 ----------
9228 -- pragma Main
9229 -- (MAIN_OPTION [, MAIN_OPTION]);
9231 -- MAIN_OPTION ::=
9232 -- [STACK_SIZE =>] static_integer_EXPRESSION
9233 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
9234 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
9236 when Pragma_Main => Main : declare
9237 Args : Args_List (1 .. 3);
9238 Names : constant Name_List (1 .. 3) := (
9239 Name_Stack_Size,
9240 Name_Task_Stack_Size_Default,
9241 Name_Time_Slicing_Enabled);
9243 Nod : Node_Id;
9245 begin
9246 GNAT_Pragma;
9247 Gather_Associations (Names, Args);
9249 for J in 1 .. 2 loop
9250 if Present (Args (J)) then
9251 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
9252 end if;
9253 end loop;
9255 if Present (Args (3)) then
9256 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
9257 end if;
9259 Nod := Next (N);
9260 while Present (Nod) loop
9261 if Nkind (Nod) = N_Pragma
9262 and then Pragma_Name (Nod) = Name_Main
9263 then
9264 Error_Msg_Name_1 := Pname;
9265 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9266 end if;
9268 Next (Nod);
9269 end loop;
9270 end Main;
9272 ------------------
9273 -- Main_Storage --
9274 ------------------
9276 -- pragma Main_Storage
9277 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
9279 -- MAIN_STORAGE_OPTION ::=
9280 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
9281 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
9283 when Pragma_Main_Storage => Main_Storage : declare
9284 Args : Args_List (1 .. 2);
9285 Names : constant Name_List (1 .. 2) := (
9286 Name_Working_Storage,
9287 Name_Top_Guard);
9289 Nod : Node_Id;
9291 begin
9292 GNAT_Pragma;
9293 Gather_Associations (Names, Args);
9295 for J in 1 .. 2 loop
9296 if Present (Args (J)) then
9297 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
9298 end if;
9299 end loop;
9301 Check_In_Main_Program;
9303 Nod := Next (N);
9304 while Present (Nod) loop
9305 if Nkind (Nod) = N_Pragma
9306 and then Pragma_Name (Nod) = Name_Main_Storage
9307 then
9308 Error_Msg_Name_1 := Pname;
9309 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9310 end if;
9312 Next (Nod);
9313 end loop;
9314 end Main_Storage;
9316 -----------------
9317 -- Memory_Size --
9318 -----------------
9320 -- pragma Memory_Size (NUMERIC_LITERAL)
9322 when Pragma_Memory_Size =>
9323 GNAT_Pragma;
9325 -- Memory size is simply ignored
9327 Check_No_Identifiers;
9328 Check_Arg_Count (1);
9329 Check_Arg_Is_Integer_Literal (Arg1);
9331 -------------
9332 -- No_Body --
9333 -------------
9335 -- pragma No_Body;
9337 -- The only correct use of this pragma is on its own in a file, in
9338 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
9339 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
9340 -- check for a file containing nothing but a No_Body pragma). If we
9341 -- attempt to process it during normal semantics processing, it means
9342 -- it was misplaced.
9344 when Pragma_No_Body =>
9345 GNAT_Pragma;
9346 Pragma_Misplaced;
9348 ---------------
9349 -- No_Return --
9350 ---------------
9352 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
9354 when Pragma_No_Return => No_Return : declare
9355 Id : Node_Id;
9356 E : Entity_Id;
9357 Found : Boolean;
9358 Arg : Node_Id;
9360 begin
9361 Ada_2005_Pragma;
9362 Check_At_Least_N_Arguments (1);
9364 -- Loop through arguments of pragma
9366 Arg := Arg1;
9367 while Present (Arg) loop
9368 Check_Arg_Is_Local_Name (Arg);
9369 Id := Expression (Arg);
9370 Analyze (Id);
9372 if not Is_Entity_Name (Id) then
9373 Error_Pragma_Arg ("entity name required", Arg);
9374 end if;
9376 if Etype (Id) = Any_Type then
9377 raise Pragma_Exit;
9378 end if;
9380 -- Loop to find matching procedures
9382 E := Entity (Id);
9383 Found := False;
9384 while Present (E)
9385 and then Scope (E) = Current_Scope
9386 loop
9387 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
9388 Set_No_Return (E);
9390 -- Set flag on any alias as well
9392 if Is_Overloadable (E) and then Present (Alias (E)) then
9393 Set_No_Return (Alias (E));
9394 end if;
9396 Found := True;
9397 end if;
9399 E := Homonym (E);
9400 end loop;
9402 if not Found then
9403 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
9404 end if;
9406 Next (Arg);
9407 end loop;
9408 end No_Return;
9410 -----------------
9411 -- No_Run_Time --
9412 -----------------
9414 -- pragma No_Run_Time;
9416 -- Note: this pragma is retained for backwards compatibility. See
9417 -- body of Rtsfind for full details on its handling.
9419 when Pragma_No_Run_Time =>
9420 GNAT_Pragma;
9421 Check_Valid_Configuration_Pragma;
9422 Check_Arg_Count (0);
9424 No_Run_Time_Mode := True;
9425 Configurable_Run_Time_Mode := True;
9427 -- Set Duration to 32 bits if word size is 32
9429 if Ttypes.System_Word_Size = 32 then
9430 Duration_32_Bits_On_Target := True;
9431 end if;
9433 -- Set appropriate restrictions
9435 Set_Restriction (No_Finalization, N);
9436 Set_Restriction (No_Exception_Handlers, N);
9437 Set_Restriction (Max_Tasks, N, 0);
9438 Set_Restriction (No_Tasking, N);
9440 ------------------------
9441 -- No_Strict_Aliasing --
9442 ------------------------
9444 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
9446 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
9447 E_Id : Entity_Id;
9449 begin
9450 GNAT_Pragma;
9451 Check_At_Most_N_Arguments (1);
9453 if Arg_Count = 0 then
9454 Check_Valid_Configuration_Pragma;
9455 Opt.No_Strict_Aliasing := True;
9457 else
9458 Check_Optional_Identifier (Arg2, Name_Entity);
9459 Check_Arg_Is_Local_Name (Arg1);
9460 E_Id := Entity (Expression (Arg1));
9462 if E_Id = Any_Type then
9463 return;
9464 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
9465 Error_Pragma_Arg ("pragma% requires access type", Arg1);
9466 end if;
9468 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
9469 end if;
9470 end No_Strict_Aliasing;
9472 -----------------------
9473 -- Normalize_Scalars --
9474 -----------------------
9476 -- pragma Normalize_Scalars;
9478 when Pragma_Normalize_Scalars =>
9479 Check_Ada_83_Warning;
9480 Check_Arg_Count (0);
9481 Check_Valid_Configuration_Pragma;
9483 -- Normalize_Scalars creates false positives in CodePeer, so
9484 -- ignore this pragma in this mode.
9486 if not CodePeer_Mode then
9487 Normalize_Scalars := True;
9488 Init_Or_Norm_Scalars := True;
9489 end if;
9491 -----------------
9492 -- Obsolescent --
9493 -----------------
9495 -- pragma Obsolescent;
9497 -- pragma Obsolescent (
9498 -- [Message =>] static_string_EXPRESSION
9499 -- [,[Version =>] Ada_05]]);
9501 -- pragma Obsolescent (
9502 -- [Entity =>] NAME
9503 -- [,[Message =>] static_string_EXPRESSION
9504 -- [,[Version =>] Ada_05]] );
9506 when Pragma_Obsolescent => Obsolescent : declare
9507 Ename : Node_Id;
9508 Decl : Node_Id;
9510 procedure Set_Obsolescent (E : Entity_Id);
9511 -- Given an entity Ent, mark it as obsolescent if appropriate
9513 ---------------------
9514 -- Set_Obsolescent --
9515 ---------------------
9517 procedure Set_Obsolescent (E : Entity_Id) is
9518 Active : Boolean;
9519 Ent : Entity_Id;
9520 S : String_Id;
9522 begin
9523 Active := True;
9524 Ent := E;
9526 -- Entity name was given
9528 if Present (Ename) then
9530 -- If entity name matches, we are fine. Save entity in
9531 -- pragma argument, for ASIS use.
9533 if Chars (Ename) = Chars (Ent) then
9534 Set_Entity (Ename, Ent);
9535 Generate_Reference (Ent, Ename);
9537 -- If entity name does not match, only possibility is an
9538 -- enumeration literal from an enumeration type declaration.
9540 elsif Ekind (Ent) /= E_Enumeration_Type then
9541 Error_Pragma
9542 ("pragma % entity name does not match declaration");
9544 else
9545 Ent := First_Literal (E);
9546 loop
9547 if No (Ent) then
9548 Error_Pragma
9549 ("pragma % entity name does not match any " &
9550 "enumeration literal");
9552 elsif Chars (Ent) = Chars (Ename) then
9553 Set_Entity (Ename, Ent);
9554 Generate_Reference (Ent, Ename);
9555 exit;
9557 else
9558 Ent := Next_Literal (Ent);
9559 end if;
9560 end loop;
9561 end if;
9562 end if;
9564 -- Ent points to entity to be marked
9566 if Arg_Count >= 1 then
9568 -- Deal with static string argument
9570 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9571 S := Strval (Expression (Arg1));
9573 for J in 1 .. String_Length (S) loop
9574 if not In_Character_Range (Get_String_Char (S, J)) then
9575 Error_Pragma_Arg
9576 ("pragma% argument does not allow wide characters",
9577 Arg1);
9578 end if;
9579 end loop;
9581 Obsolescent_Warnings.Append
9582 ((Ent => Ent, Msg => Strval (Expression (Arg1))));
9584 -- Check for Ada_05 parameter
9586 if Arg_Count /= 1 then
9587 Check_Arg_Count (2);
9589 declare
9590 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
9592 begin
9593 Check_Arg_Is_Identifier (Argx);
9595 if Chars (Argx) /= Name_Ada_05 then
9596 Error_Msg_Name_2 := Name_Ada_05;
9597 Error_Pragma_Arg
9598 ("only allowed argument for pragma% is %", Argx);
9599 end if;
9601 if Ada_Version_Explicit < Ada_05
9602 or else not Warn_On_Ada_2005_Compatibility
9603 then
9604 Active := False;
9605 end if;
9606 end;
9607 end if;
9608 end if;
9610 -- Set flag if pragma active
9612 if Active then
9613 Set_Is_Obsolescent (Ent);
9614 end if;
9616 return;
9617 end Set_Obsolescent;
9619 -- Start of processing for pragma Obsolescent
9621 begin
9622 GNAT_Pragma;
9624 Check_At_Most_N_Arguments (3);
9626 -- See if first argument specifies an entity name
9628 if Arg_Count >= 1
9629 and then
9630 (Chars (Arg1) = Name_Entity
9631 or else
9632 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
9633 N_Identifier,
9634 N_Operator_Symbol))
9635 then
9636 Ename := Get_Pragma_Arg (Arg1);
9638 -- Eliminate first argument, so we can share processing
9640 Arg1 := Arg2;
9641 Arg2 := Arg3;
9642 Arg_Count := Arg_Count - 1;
9644 -- No Entity name argument given
9646 else
9647 Ename := Empty;
9648 end if;
9650 if Arg_Count >= 1 then
9651 Check_Optional_Identifier (Arg1, Name_Message);
9653 if Arg_Count = 2 then
9654 Check_Optional_Identifier (Arg2, Name_Version);
9655 end if;
9656 end if;
9658 -- Get immediately preceding declaration
9660 Decl := Prev (N);
9661 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
9662 Prev (Decl);
9663 end loop;
9665 -- Cases where we do not follow anything other than another pragma
9667 if No (Decl) then
9669 -- First case: library level compilation unit declaration with
9670 -- the pragma immediately following the declaration.
9672 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9673 Set_Obsolescent
9674 (Defining_Entity (Unit (Parent (Parent (N)))));
9675 return;
9677 -- Case 2: library unit placement for package
9679 else
9680 declare
9681 Ent : constant Entity_Id := Find_Lib_Unit_Name;
9682 begin
9683 if Is_Package_Or_Generic_Package (Ent) then
9684 Set_Obsolescent (Ent);
9685 return;
9686 end if;
9687 end;
9688 end if;
9690 -- Cases where we must follow a declaration
9692 else
9693 if Nkind (Decl) not in N_Declaration
9694 and then Nkind (Decl) not in N_Later_Decl_Item
9695 and then Nkind (Decl) not in N_Generic_Declaration
9696 and then Nkind (Decl) not in N_Renaming_Declaration
9697 then
9698 Error_Pragma
9699 ("pragma% misplaced, "
9700 & "must immediately follow a declaration");
9702 else
9703 Set_Obsolescent (Defining_Entity (Decl));
9704 return;
9705 end if;
9706 end if;
9707 end Obsolescent;
9709 --------------
9710 -- Optimize --
9711 --------------
9713 -- pragma Optimize (Time | Space | Off);
9715 -- The actual check for optimize is done in Gigi. Note that this
9716 -- pragma does not actually change the optimization setting, it
9717 -- simply checks that it is consistent with the pragma.
9719 when Pragma_Optimize =>
9720 Check_No_Identifiers;
9721 Check_Arg_Count (1);
9722 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
9724 ------------------------
9725 -- Optimize_Alignment --
9726 ------------------------
9728 -- pragma Optimize_Alignment (Time | Space | Off);
9730 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
9731 GNAT_Pragma;
9732 Check_No_Identifiers;
9733 Check_Arg_Count (1);
9734 Check_Valid_Configuration_Pragma;
9736 declare
9737 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
9738 begin
9739 case Nam is
9740 when Name_Time =>
9741 Opt.Optimize_Alignment := 'T';
9742 when Name_Space =>
9743 Opt.Optimize_Alignment := 'S';
9744 when Name_Off =>
9745 Opt.Optimize_Alignment := 'O';
9746 when others =>
9747 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
9748 end case;
9749 end;
9751 -- Set indication that mode is set locally. If we are in fact in a
9752 -- configuration pragma file, this setting is harmless since the
9753 -- switch will get reset anyway at the start of each unit.
9755 Optimize_Alignment_Local := True;
9756 end Optimize_Alignment;
9758 -------------
9759 -- Ordered --
9760 -------------
9762 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
9764 when Pragma_Ordered => Ordered : declare
9765 Assoc : constant Node_Id := Arg1;
9766 Type_Id : Node_Id;
9767 Typ : Entity_Id;
9769 begin
9770 GNAT_Pragma;
9771 Check_No_Identifiers;
9772 Check_Arg_Count (1);
9773 Check_Arg_Is_Local_Name (Arg1);
9775 Type_Id := Expression (Assoc);
9776 Find_Type (Type_Id);
9777 Typ := Entity (Type_Id);
9779 if Typ = Any_Type then
9780 return;
9781 else
9782 Typ := Underlying_Type (Typ);
9783 end if;
9785 if not Is_Enumeration_Type (Typ) then
9786 Error_Pragma ("pragma% must specify enumeration type");
9787 end if;
9789 Check_First_Subtype (Arg1);
9790 Set_Has_Pragma_Ordered (Base_Type (Typ));
9791 end Ordered;
9793 ----------
9794 -- Pack --
9795 ----------
9797 -- pragma Pack (first_subtype_LOCAL_NAME);
9799 when Pragma_Pack => Pack : declare
9800 Assoc : constant Node_Id := Arg1;
9801 Type_Id : Node_Id;
9802 Typ : Entity_Id;
9804 begin
9805 Check_No_Identifiers;
9806 Check_Arg_Count (1);
9807 Check_Arg_Is_Local_Name (Arg1);
9809 Type_Id := Expression (Assoc);
9810 Find_Type (Type_Id);
9811 Typ := Entity (Type_Id);
9813 if Typ = Any_Type
9814 or else Rep_Item_Too_Early (Typ, N)
9815 then
9816 return;
9817 else
9818 Typ := Underlying_Type (Typ);
9819 end if;
9821 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
9822 Error_Pragma ("pragma% must specify array or record type");
9823 end if;
9825 Check_First_Subtype (Arg1);
9827 if Has_Pragma_Pack (Typ) then
9828 Error_Pragma ("duplicate pragma%, only one allowed");
9830 -- Array type
9832 elsif Is_Array_Type (Typ) then
9834 -- Pack not allowed for aliased or atomic components
9836 if Has_Aliased_Components (Base_Type (Typ)) then
9837 Error_Pragma
9838 ("pragma% ignored, cannot pack aliased components?");
9840 elsif Has_Atomic_Components (Typ)
9841 or else Is_Atomic (Component_Type (Typ))
9842 then
9843 Error_Pragma
9844 ("?pragma% ignored, cannot pack atomic components");
9845 end if;
9847 -- If we had an explicit component size given, then we do not
9848 -- let Pack override this given size. We also give a warning
9849 -- that Pack is being ignored unless we can tell for sure that
9850 -- the Pack would not have had any effect anyway.
9852 if Has_Component_Size_Clause (Typ) then
9853 if Known_Static_RM_Size (Component_Type (Typ))
9854 and then
9855 RM_Size (Component_Type (Typ)) = Component_Size (Typ)
9856 then
9857 null;
9858 else
9859 Error_Pragma
9860 ("?pragma% ignored, explicit component size given");
9861 end if;
9863 -- If no prior array component size given, Pack is effective
9865 else
9866 if not Rep_Item_Too_Late (Typ, N) then
9868 -- In the context of static code analysis, we do not need
9869 -- complex front-end expansions related to pragma Pack,
9870 -- so disable handling of pragma Pack in this case.
9872 if CodePeer_Mode then
9873 null;
9875 -- For normal non-VM target, do the packing
9877 elsif VM_Target = No_VM then
9878 Set_Is_Packed (Base_Type (Typ));
9879 Set_Has_Pragma_Pack (Base_Type (Typ));
9880 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9882 -- If we ignore the pack, then warn about this, except
9883 -- that we suppress the warning in GNAT mode.
9885 elsif not GNAT_Mode then
9886 Error_Pragma
9887 ("?pragma% ignored in this configuration");
9888 end if;
9889 end if;
9890 end if;
9892 -- For record types, the pack is always effective
9894 else pragma Assert (Is_Record_Type (Typ));
9895 if not Rep_Item_Too_Late (Typ, N) then
9896 if VM_Target = No_VM then
9897 Set_Is_Packed (Base_Type (Typ));
9898 Set_Has_Pragma_Pack (Base_Type (Typ));
9899 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9901 elsif not GNAT_Mode then
9902 Error_Pragma ("?pragma% ignored in this configuration");
9903 end if;
9904 end if;
9905 end if;
9906 end Pack;
9908 ----------
9909 -- Page --
9910 ----------
9912 -- pragma Page;
9914 -- There is nothing to do here, since we did all the processing for
9915 -- this pragma in Par.Prag (so that it works properly even in syntax
9916 -- only mode).
9918 when Pragma_Page =>
9919 null;
9921 -------------
9922 -- Passive --
9923 -------------
9925 -- pragma Passive [(PASSIVE_FORM)];
9927 -- PASSIVE_FORM ::= Semaphore | No
9929 when Pragma_Passive =>
9930 GNAT_Pragma;
9932 if Nkind (Parent (N)) /= N_Task_Definition then
9933 Error_Pragma ("pragma% must be within task definition");
9934 end if;
9936 if Arg_Count /= 0 then
9937 Check_Arg_Count (1);
9938 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
9939 end if;
9941 ----------------------------------
9942 -- Preelaborable_Initialization --
9943 ----------------------------------
9945 -- pragma Preelaborable_Initialization (DIRECT_NAME);
9947 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
9948 Ent : Entity_Id;
9950 begin
9951 Ada_2005_Pragma;
9952 Check_Arg_Count (1);
9953 Check_No_Identifiers;
9954 Check_Arg_Is_Identifier (Arg1);
9955 Check_Arg_Is_Local_Name (Arg1);
9956 Check_First_Subtype (Arg1);
9957 Ent := Entity (Expression (Arg1));
9959 if not Is_Private_Type (Ent)
9960 and then not Is_Protected_Type (Ent)
9961 then
9962 Error_Pragma_Arg
9963 ("pragma % can only be applied to private or protected type",
9964 Arg1);
9965 end if;
9967 -- Give an error if the pragma is applied to a protected type that
9968 -- does not qualify (due to having entries, or due to components
9969 -- that do not qualify).
9971 if Is_Protected_Type (Ent)
9972 and then not Has_Preelaborable_Initialization (Ent)
9973 then
9974 Error_Msg_N
9975 ("protected type & does not have preelaborable " &
9976 "initialization", Ent);
9978 -- Otherwise mark the type as definitely having preelaborable
9979 -- initialization.
9981 else
9982 Set_Known_To_Have_Preelab_Init (Ent);
9983 end if;
9985 if Has_Pragma_Preelab_Init (Ent)
9986 and then Warn_On_Redundant_Constructs
9987 then
9988 Error_Pragma ("?duplicate pragma%!");
9989 else
9990 Set_Has_Pragma_Preelab_Init (Ent);
9991 end if;
9992 end Preelab_Init;
9994 --------------------
9995 -- Persistent_BSS --
9996 --------------------
9998 when Pragma_Persistent_BSS => Persistent_BSS : declare
9999 Decl : Node_Id;
10000 Ent : Entity_Id;
10001 Prag : Node_Id;
10003 begin
10004 GNAT_Pragma;
10005 Check_At_Most_N_Arguments (1);
10007 -- Case of application to specific object (one argument)
10009 if Arg_Count = 1 then
10010 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10012 if not Is_Entity_Name (Expression (Arg1))
10013 or else
10014 (Ekind (Entity (Expression (Arg1))) /= E_Variable
10015 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
10016 then
10017 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
10018 end if;
10020 Ent := Entity (Expression (Arg1));
10021 Decl := Parent (Ent);
10023 if Rep_Item_Too_Late (Ent, N) then
10024 return;
10025 end if;
10027 if Present (Expression (Decl)) then
10028 Error_Pragma_Arg
10029 ("object for pragma% cannot have initialization", Arg1);
10030 end if;
10032 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
10033 Error_Pragma_Arg
10034 ("object type for pragma% is not potentially persistent",
10035 Arg1);
10036 end if;
10038 Prag :=
10039 Make_Linker_Section_Pragma
10040 (Ent, Sloc (N), ".persistent.bss");
10041 Insert_After (N, Prag);
10042 Analyze (Prag);
10044 -- Case of use as configuration pragma with no arguments
10046 else
10047 Check_Valid_Configuration_Pragma;
10048 Persistent_BSS_Mode := True;
10049 end if;
10050 end Persistent_BSS;
10052 -------------
10053 -- Polling --
10054 -------------
10056 -- pragma Polling (ON | OFF);
10058 when Pragma_Polling =>
10059 GNAT_Pragma;
10060 Check_Arg_Count (1);
10061 Check_No_Identifiers;
10062 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10063 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
10065 -------------------
10066 -- Postcondition --
10067 -------------------
10069 -- pragma Postcondition ([Check =>] Boolean_Expression
10070 -- [,[Message =>] String_Expression]);
10072 when Pragma_Postcondition => Postcondition : declare
10073 In_Body : Boolean;
10074 pragma Warnings (Off, In_Body);
10076 begin
10077 GNAT_Pragma;
10078 Check_At_Least_N_Arguments (1);
10079 Check_At_Most_N_Arguments (2);
10080 Check_Optional_Identifier (Arg1, Name_Check);
10082 -- All we need to do here is call the common check procedure,
10083 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
10085 Check_Precondition_Postcondition (In_Body);
10086 end Postcondition;
10088 ------------------
10089 -- Precondition --
10090 ------------------
10092 -- pragma Precondition ([Check =>] Boolean_Expression
10093 -- [,[Message =>] String_Expression]);
10095 when Pragma_Precondition => Precondition : declare
10096 In_Body : Boolean;
10098 begin
10099 GNAT_Pragma;
10100 Check_At_Least_N_Arguments (1);
10101 Check_At_Most_N_Arguments (2);
10102 Check_Optional_Identifier (Arg1, Name_Check);
10104 Check_Precondition_Postcondition (In_Body);
10106 -- If in spec, nothing more to do. If in body, then we convert the
10107 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
10108 -- this whether or not precondition checks are enabled. That works
10109 -- fine since pragma Check will do this check, and will also
10110 -- analyze the condition itself in the proper context.
10112 if In_Body then
10113 if Arg_Count = 2 then
10114 Check_Optional_Identifier (Arg3, Name_Message);
10115 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
10116 end if;
10118 Rewrite (N,
10119 Make_Pragma (Loc,
10120 Chars => Name_Check,
10121 Pragma_Argument_Associations => New_List (
10122 Make_Pragma_Argument_Association (Loc,
10123 Expression =>
10124 Make_Identifier (Loc,
10125 Chars => Name_Precondition)),
10127 Make_Pragma_Argument_Association (Sloc (Arg1),
10128 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
10130 if Arg_Count = 2 then
10131 Append_To (Pragma_Argument_Associations (N),
10132 Make_Pragma_Argument_Association (Sloc (Arg2),
10133 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
10134 end if;
10136 Analyze (N);
10137 end if;
10138 end Precondition;
10140 ------------------
10141 -- Preelaborate --
10142 ------------------
10144 -- pragma Preelaborate [(library_unit_NAME)];
10146 -- Set the flag Is_Preelaborated of program unit name entity
10148 when Pragma_Preelaborate => Preelaborate : declare
10149 Pa : constant Node_Id := Parent (N);
10150 Pk : constant Node_Kind := Nkind (Pa);
10151 Ent : Entity_Id;
10153 begin
10154 Check_Ada_83_Warning;
10155 Check_Valid_Library_Unit_Pragma;
10157 if Nkind (N) = N_Null_Statement then
10158 return;
10159 end if;
10161 Ent := Find_Lib_Unit_Name;
10163 -- This filters out pragmas inside generic parent then
10164 -- show up inside instantiation
10166 if Present (Ent)
10167 and then not (Pk = N_Package_Specification
10168 and then Present (Generic_Parent (Pa)))
10169 then
10170 if not Debug_Flag_U then
10171 Set_Is_Preelaborated (Ent);
10172 Set_Suppress_Elaboration_Warnings (Ent);
10173 end if;
10174 end if;
10175 end Preelaborate;
10177 ---------------------
10178 -- Preelaborate_05 --
10179 ---------------------
10181 -- pragma Preelaborate_05 [(library_unit_NAME)];
10183 -- This pragma is useable only in GNAT_Mode, where it is used like
10184 -- pragma Preelaborate but it is only effective in Ada 2005 mode
10185 -- (otherwise it is ignored). This is used to implement AI-362 which
10186 -- recategorizes some run-time packages in Ada 2005 mode.
10188 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
10189 Ent : Entity_Id;
10191 begin
10192 GNAT_Pragma;
10193 Check_Valid_Library_Unit_Pragma;
10195 if not GNAT_Mode then
10196 Error_Pragma ("pragma% only available in GNAT mode");
10197 end if;
10199 if Nkind (N) = N_Null_Statement then
10200 return;
10201 end if;
10203 -- This is one of the few cases where we need to test the value of
10204 -- Ada_Version_Explicit rather than Ada_Version (which is always
10205 -- set to Ada_12 in a predefined unit), we need to know the
10206 -- explicit version set to know if this pragma is active.
10208 if Ada_Version_Explicit >= Ada_05 then
10209 Ent := Find_Lib_Unit_Name;
10210 Set_Is_Preelaborated (Ent);
10211 Set_Suppress_Elaboration_Warnings (Ent);
10212 end if;
10213 end Preelaborate_05;
10215 --------------
10216 -- Priority --
10217 --------------
10219 -- pragma Priority (EXPRESSION);
10221 when Pragma_Priority => Priority : declare
10222 P : constant Node_Id := Parent (N);
10223 Arg : Node_Id;
10225 begin
10226 Check_No_Identifiers;
10227 Check_Arg_Count (1);
10229 -- Subprogram case
10231 if Nkind (P) = N_Subprogram_Body then
10232 Check_In_Main_Program;
10234 Arg := Expression (Arg1);
10235 Analyze_And_Resolve (Arg, Standard_Integer);
10237 -- Must be static
10239 if not Is_Static_Expression (Arg) then
10240 Flag_Non_Static_Expr
10241 ("main subprogram priority is not static!", Arg);
10242 raise Pragma_Exit;
10244 -- If constraint error, then we already signalled an error
10246 elsif Raises_Constraint_Error (Arg) then
10247 null;
10249 -- Otherwise check in range
10251 else
10252 declare
10253 Val : constant Uint := Expr_Value (Arg);
10255 begin
10256 if Val < 0
10257 or else Val > Expr_Value (Expression
10258 (Parent (RTE (RE_Max_Priority))))
10259 then
10260 Error_Pragma_Arg
10261 ("main subprogram priority is out of range", Arg1);
10262 end if;
10263 end;
10264 end if;
10266 Set_Main_Priority
10267 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
10269 -- Load an arbitrary entity from System.Tasking to make sure
10270 -- this package is implicitly with'ed, since we need to have
10271 -- the tasking run-time active for the pragma Priority to have
10272 -- any effect.
10274 declare
10275 Discard : Entity_Id;
10276 pragma Warnings (Off, Discard);
10277 begin
10278 Discard := RTE (RE_Task_List);
10279 end;
10281 -- Task or Protected, must be of type Integer
10283 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
10284 Arg := Expression (Arg1);
10286 -- The expression must be analyzed in the special manner
10287 -- described in "Handling of Default and Per-Object
10288 -- Expressions" in sem.ads.
10290 Preanalyze_Spec_Expression (Arg, Standard_Integer);
10292 if not Is_Static_Expression (Arg) then
10293 Check_Restriction (Static_Priorities, Arg);
10294 end if;
10296 -- Anything else is incorrect
10298 else
10299 Pragma_Misplaced;
10300 end if;
10302 if Has_Priority_Pragma (P) then
10303 Error_Pragma ("duplicate pragma% not allowed");
10304 else
10305 Set_Has_Priority_Pragma (P, True);
10307 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
10308 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10309 -- exp_ch9 should use this ???
10310 end if;
10311 end if;
10312 end Priority;
10314 -----------------------------------
10315 -- Priority_Specific_Dispatching --
10316 -----------------------------------
10318 -- pragma Priority_Specific_Dispatching (
10319 -- policy_IDENTIFIER,
10320 -- first_priority_EXPRESSION,
10321 -- last_priority_EXPRESSION);
10323 when Pragma_Priority_Specific_Dispatching =>
10324 Priority_Specific_Dispatching : declare
10325 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
10326 -- This is the entity System.Any_Priority;
10328 DP : Character;
10329 Lower_Bound : Node_Id;
10330 Upper_Bound : Node_Id;
10331 Lower_Val : Uint;
10332 Upper_Val : Uint;
10334 begin
10335 Ada_2005_Pragma;
10336 Check_Arg_Count (3);
10337 Check_No_Identifiers;
10338 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
10339 Check_Valid_Configuration_Pragma;
10340 Get_Name_String (Chars (Expression (Arg1)));
10341 DP := Fold_Upper (Name_Buffer (1));
10343 Lower_Bound := Expression (Arg2);
10344 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
10345 Lower_Val := Expr_Value (Lower_Bound);
10347 Upper_Bound := Expression (Arg3);
10348 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
10349 Upper_Val := Expr_Value (Upper_Bound);
10351 -- It is not allowed to use Task_Dispatching_Policy and
10352 -- Priority_Specific_Dispatching in the same partition.
10354 if Task_Dispatching_Policy /= ' ' then
10355 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10356 Error_Pragma
10357 ("pragma% incompatible with Task_Dispatching_Policy#");
10359 -- Check lower bound in range
10361 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10362 or else
10363 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
10364 then
10365 Error_Pragma_Arg
10366 ("first_priority is out of range", Arg2);
10368 -- Check upper bound in range
10370 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10371 or else
10372 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
10373 then
10374 Error_Pragma_Arg
10375 ("last_priority is out of range", Arg3);
10377 -- Check that the priority range is valid
10379 elsif Lower_Val > Upper_Val then
10380 Error_Pragma
10381 ("last_priority_expression must be greater than" &
10382 " or equal to first_priority_expression");
10384 -- Store the new policy, but always preserve System_Location since
10385 -- we like the error message with the run-time name.
10387 else
10388 -- Check overlapping in the priority ranges specified in other
10389 -- Priority_Specific_Dispatching pragmas within the same
10390 -- partition. We can only check those we know about!
10392 for J in
10393 Specific_Dispatching.First .. Specific_Dispatching.Last
10394 loop
10395 if Specific_Dispatching.Table (J).First_Priority in
10396 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10397 or else Specific_Dispatching.Table (J).Last_Priority in
10398 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10399 then
10400 Error_Msg_Sloc :=
10401 Specific_Dispatching.Table (J).Pragma_Loc;
10402 Error_Pragma
10403 ("priority range overlaps with "
10404 & "Priority_Specific_Dispatching#");
10405 end if;
10406 end loop;
10408 -- The use of Priority_Specific_Dispatching is incompatible
10409 -- with Task_Dispatching_Policy.
10411 if Task_Dispatching_Policy /= ' ' then
10412 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10413 Error_Pragma
10414 ("Priority_Specific_Dispatching incompatible "
10415 & "with Task_Dispatching_Policy#");
10416 end if;
10418 -- The use of Priority_Specific_Dispatching forces ceiling
10419 -- locking policy.
10421 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
10422 Error_Msg_Sloc := Locking_Policy_Sloc;
10423 Error_Pragma
10424 ("Priority_Specific_Dispatching incompatible "
10425 & "with Locking_Policy#");
10427 -- Set the Ceiling_Locking policy, but preserve System_Location
10428 -- since we like the error message with the run time name.
10430 else
10431 Locking_Policy := 'C';
10433 if Locking_Policy_Sloc /= System_Location then
10434 Locking_Policy_Sloc := Loc;
10435 end if;
10436 end if;
10438 -- Add entry in the table
10440 Specific_Dispatching.Append
10441 ((Dispatching_Policy => DP,
10442 First_Priority => UI_To_Int (Lower_Val),
10443 Last_Priority => UI_To_Int (Upper_Val),
10444 Pragma_Loc => Loc));
10445 end if;
10446 end Priority_Specific_Dispatching;
10448 -------------
10449 -- Profile --
10450 -------------
10452 -- pragma Profile (profile_IDENTIFIER);
10454 -- profile_IDENTIFIER => Restricted | Ravenscar
10456 when Pragma_Profile =>
10457 Ada_2005_Pragma;
10458 Check_Arg_Count (1);
10459 Check_Valid_Configuration_Pragma;
10460 Check_No_Identifiers;
10462 declare
10463 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10464 begin
10465 if Chars (Argx) = Name_Ravenscar then
10466 Set_Ravenscar_Profile (N);
10467 elsif Chars (Argx) = Name_Restricted then
10468 Set_Profile_Restrictions
10469 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10470 else
10471 Error_Pragma_Arg ("& is not a valid profile", Argx);
10472 end if;
10473 end;
10475 ----------------------
10476 -- Profile_Warnings --
10477 ----------------------
10479 -- pragma Profile_Warnings (profile_IDENTIFIER);
10481 -- profile_IDENTIFIER => Restricted | Ravenscar
10483 when Pragma_Profile_Warnings =>
10484 GNAT_Pragma;
10485 Check_Arg_Count (1);
10486 Check_Valid_Configuration_Pragma;
10487 Check_No_Identifiers;
10489 declare
10490 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10491 begin
10492 if Chars (Argx) = Name_Ravenscar then
10493 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
10494 elsif Chars (Argx) = Name_Restricted then
10495 Set_Profile_Restrictions (Restricted, N, Warn => True);
10496 else
10497 Error_Pragma_Arg ("& is not a valid profile", Argx);
10498 end if;
10499 end;
10501 --------------------------
10502 -- Propagate_Exceptions --
10503 --------------------------
10505 -- pragma Propagate_Exceptions;
10507 -- Note: this pragma is obsolete and has no effect
10509 when Pragma_Propagate_Exceptions =>
10510 GNAT_Pragma;
10511 Check_Arg_Count (0);
10513 if In_Extended_Main_Source_Unit (N) then
10514 Propagate_Exceptions := True;
10515 end if;
10517 ------------------
10518 -- Psect_Object --
10519 ------------------
10521 -- pragma Psect_Object (
10522 -- [Internal =>] LOCAL_NAME,
10523 -- [, [External =>] EXTERNAL_SYMBOL]
10524 -- [, [Size =>] EXTERNAL_SYMBOL]);
10526 when Pragma_Psect_Object | Pragma_Common_Object =>
10527 Psect_Object : declare
10528 Args : Args_List (1 .. 3);
10529 Names : constant Name_List (1 .. 3) := (
10530 Name_Internal,
10531 Name_External,
10532 Name_Size);
10534 Internal : Node_Id renames Args (1);
10535 External : Node_Id renames Args (2);
10536 Size : Node_Id renames Args (3);
10538 Def_Id : Entity_Id;
10540 procedure Check_Too_Long (Arg : Node_Id);
10541 -- Posts message if the argument is an identifier with more
10542 -- than 31 characters, or a string literal with more than
10543 -- 31 characters, and we are operating under VMS
10545 --------------------
10546 -- Check_Too_Long --
10547 --------------------
10549 procedure Check_Too_Long (Arg : Node_Id) is
10550 X : constant Node_Id := Original_Node (Arg);
10552 begin
10553 if not Nkind_In (X, N_String_Literal, N_Identifier) then
10554 Error_Pragma_Arg
10555 ("inappropriate argument for pragma %", Arg);
10556 end if;
10558 if OpenVMS_On_Target then
10559 if (Nkind (X) = N_String_Literal
10560 and then String_Length (Strval (X)) > 31)
10561 or else
10562 (Nkind (X) = N_Identifier
10563 and then Length_Of_Name (Chars (X)) > 31)
10564 then
10565 Error_Pragma_Arg
10566 ("argument for pragma % is longer than 31 characters",
10567 Arg);
10568 end if;
10569 end if;
10570 end Check_Too_Long;
10572 -- Start of processing for Common_Object/Psect_Object
10574 begin
10575 GNAT_Pragma;
10576 Gather_Associations (Names, Args);
10577 Process_Extended_Import_Export_Internal_Arg (Internal);
10579 Def_Id := Entity (Internal);
10581 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
10582 Error_Pragma_Arg
10583 ("pragma% must designate an object", Internal);
10584 end if;
10586 Check_Too_Long (Internal);
10588 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
10589 Error_Pragma_Arg
10590 ("cannot use pragma% for imported/exported object",
10591 Internal);
10592 end if;
10594 if Is_Concurrent_Type (Etype (Internal)) then
10595 Error_Pragma_Arg
10596 ("cannot specify pragma % for task/protected object",
10597 Internal);
10598 end if;
10600 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
10601 or else
10602 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
10603 then
10604 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
10605 end if;
10607 if Ekind (Def_Id) = E_Constant then
10608 Error_Pragma_Arg
10609 ("cannot specify pragma % for a constant", Internal);
10610 end if;
10612 if Is_Record_Type (Etype (Internal)) then
10613 declare
10614 Ent : Entity_Id;
10615 Decl : Entity_Id;
10617 begin
10618 Ent := First_Entity (Etype (Internal));
10619 while Present (Ent) loop
10620 Decl := Declaration_Node (Ent);
10622 if Ekind (Ent) = E_Component
10623 and then Nkind (Decl) = N_Component_Declaration
10624 and then Present (Expression (Decl))
10625 and then Warn_On_Export_Import
10626 then
10627 Error_Msg_N
10628 ("?object for pragma % has defaults", Internal);
10629 exit;
10631 else
10632 Next_Entity (Ent);
10633 end if;
10634 end loop;
10635 end;
10636 end if;
10638 if Present (Size) then
10639 Check_Too_Long (Size);
10640 end if;
10642 if Present (External) then
10643 Check_Arg_Is_External_Name (External);
10644 Check_Too_Long (External);
10645 end if;
10647 -- If all error tests pass, link pragma on to the rep item chain
10649 Record_Rep_Item (Def_Id, N);
10650 end Psect_Object;
10652 ----------
10653 -- Pure --
10654 ----------
10656 -- pragma Pure [(library_unit_NAME)];
10658 when Pragma_Pure => Pure : declare
10659 Ent : Entity_Id;
10661 begin
10662 Check_Ada_83_Warning;
10663 Check_Valid_Library_Unit_Pragma;
10665 if Nkind (N) = N_Null_Statement then
10666 return;
10667 end if;
10669 Ent := Find_Lib_Unit_Name;
10670 Set_Is_Pure (Ent);
10671 Set_Has_Pragma_Pure (Ent);
10672 Set_Suppress_Elaboration_Warnings (Ent);
10673 end Pure;
10675 -------------
10676 -- Pure_05 --
10677 -------------
10679 -- pragma Pure_05 [(library_unit_NAME)];
10681 -- This pragma is useable only in GNAT_Mode, where it is used like
10682 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
10683 -- it is ignored). It may be used after a pragma Preelaborate, in
10684 -- which case it overrides the effect of the pragma Preelaborate.
10685 -- This is used to implement AI-362 which recategorizes some run-time
10686 -- packages in Ada 2005 mode.
10688 when Pragma_Pure_05 => Pure_05 : declare
10689 Ent : Entity_Id;
10691 begin
10692 GNAT_Pragma;
10693 Check_Valid_Library_Unit_Pragma;
10695 if not GNAT_Mode then
10696 Error_Pragma ("pragma% only available in GNAT mode");
10697 end if;
10699 if Nkind (N) = N_Null_Statement then
10700 return;
10701 end if;
10703 -- This is one of the few cases where we need to test the value of
10704 -- Ada_Version_Explicit rather than Ada_Version (which is always
10705 -- set to Ada_12 in a predefined unit), we need to know the
10706 -- explicit version set to know if this pragma is active.
10708 if Ada_Version_Explicit >= Ada_05 then
10709 Ent := Find_Lib_Unit_Name;
10710 Set_Is_Preelaborated (Ent, False);
10711 Set_Is_Pure (Ent);
10712 Set_Suppress_Elaboration_Warnings (Ent);
10713 end if;
10714 end Pure_05;
10716 -------------------
10717 -- Pure_Function --
10718 -------------------
10720 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
10722 when Pragma_Pure_Function => Pure_Function : declare
10723 E_Id : Node_Id;
10724 E : Entity_Id;
10725 Def_Id : Entity_Id;
10726 Effective : Boolean := False;
10728 begin
10729 GNAT_Pragma;
10730 Check_Arg_Count (1);
10731 Check_Optional_Identifier (Arg1, Name_Entity);
10732 Check_Arg_Is_Local_Name (Arg1);
10733 E_Id := Expression (Arg1);
10735 if Error_Posted (E_Id) then
10736 return;
10737 end if;
10739 -- Loop through homonyms (overloadings) of referenced entity
10741 E := Entity (E_Id);
10743 if Present (E) then
10744 loop
10745 Def_Id := Get_Base_Subprogram (E);
10747 if not Ekind_In (Def_Id, E_Function,
10748 E_Generic_Function,
10749 E_Operator)
10750 then
10751 Error_Pragma_Arg
10752 ("pragma% requires a function name", Arg1);
10753 end if;
10755 Set_Is_Pure (Def_Id);
10757 if not Has_Pragma_Pure_Function (Def_Id) then
10758 Set_Has_Pragma_Pure_Function (Def_Id);
10759 Effective := True;
10760 end if;
10762 E := Homonym (E);
10763 exit when No (E) or else Scope (E) /= Current_Scope;
10764 end loop;
10766 if not Effective
10767 and then Warn_On_Redundant_Constructs
10768 then
10769 Error_Msg_NE
10770 ("pragma Pure_Function on& is redundant?",
10771 N, Entity (E_Id));
10772 end if;
10773 end if;
10774 end Pure_Function;
10776 --------------------
10777 -- Queuing_Policy --
10778 --------------------
10780 -- pragma Queuing_Policy (policy_IDENTIFIER);
10782 when Pragma_Queuing_Policy => declare
10783 QP : Character;
10785 begin
10786 Check_Ada_83_Warning;
10787 Check_Arg_Count (1);
10788 Check_No_Identifiers;
10789 Check_Arg_Is_Queuing_Policy (Arg1);
10790 Check_Valid_Configuration_Pragma;
10791 Get_Name_String (Chars (Expression (Arg1)));
10792 QP := Fold_Upper (Name_Buffer (1));
10794 if Queuing_Policy /= ' '
10795 and then Queuing_Policy /= QP
10796 then
10797 Error_Msg_Sloc := Queuing_Policy_Sloc;
10798 Error_Pragma ("queuing policy incompatible with policy#");
10800 -- Set new policy, but always preserve System_Location since we
10801 -- like the error message with the run time name.
10803 else
10804 Queuing_Policy := QP;
10806 if Queuing_Policy_Sloc /= System_Location then
10807 Queuing_Policy_Sloc := Loc;
10808 end if;
10809 end if;
10810 end;
10812 -----------------------
10813 -- Relative_Deadline --
10814 -----------------------
10816 -- pragma Relative_Deadline (time_span_EXPRESSION);
10818 when Pragma_Relative_Deadline => Relative_Deadline : declare
10819 P : constant Node_Id := Parent (N);
10820 Arg : Node_Id;
10822 begin
10823 Ada_2005_Pragma;
10824 Check_No_Identifiers;
10825 Check_Arg_Count (1);
10827 Arg := Expression (Arg1);
10829 -- The expression must be analyzed in the special manner described
10830 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
10832 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
10834 -- Subprogram case
10836 if Nkind (P) = N_Subprogram_Body then
10837 Check_In_Main_Program;
10839 -- Tasks
10841 elsif Nkind (P) = N_Task_Definition then
10842 null;
10844 -- Anything else is incorrect
10846 else
10847 Pragma_Misplaced;
10848 end if;
10850 if Has_Relative_Deadline_Pragma (P) then
10851 Error_Pragma ("duplicate pragma% not allowed");
10852 else
10853 Set_Has_Relative_Deadline_Pragma (P, True);
10855 if Nkind (P) = N_Task_Definition then
10856 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10857 end if;
10858 end if;
10859 end Relative_Deadline;
10861 ---------------------------
10862 -- Remote_Call_Interface --
10863 ---------------------------
10865 -- pragma Remote_Call_Interface [(library_unit_NAME)];
10867 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
10868 Cunit_Node : Node_Id;
10869 Cunit_Ent : Entity_Id;
10870 K : Node_Kind;
10872 begin
10873 Check_Ada_83_Warning;
10874 Check_Valid_Library_Unit_Pragma;
10876 if Nkind (N) = N_Null_Statement then
10877 return;
10878 end if;
10880 Cunit_Node := Cunit (Current_Sem_Unit);
10881 K := Nkind (Unit (Cunit_Node));
10882 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10884 if K = N_Package_Declaration
10885 or else K = N_Generic_Package_Declaration
10886 or else K = N_Subprogram_Declaration
10887 or else K = N_Generic_Subprogram_Declaration
10888 or else (K = N_Subprogram_Body
10889 and then Acts_As_Spec (Unit (Cunit_Node)))
10890 then
10891 null;
10892 else
10893 Error_Pragma (
10894 "pragma% must apply to package or subprogram declaration");
10895 end if;
10897 Set_Is_Remote_Call_Interface (Cunit_Ent);
10898 end Remote_Call_Interface;
10900 ------------------
10901 -- Remote_Types --
10902 ------------------
10904 -- pragma Remote_Types [(library_unit_NAME)];
10906 when Pragma_Remote_Types => Remote_Types : declare
10907 Cunit_Node : Node_Id;
10908 Cunit_Ent : Entity_Id;
10910 begin
10911 Check_Ada_83_Warning;
10912 Check_Valid_Library_Unit_Pragma;
10914 if Nkind (N) = N_Null_Statement then
10915 return;
10916 end if;
10918 Cunit_Node := Cunit (Current_Sem_Unit);
10919 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10921 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
10922 N_Generic_Package_Declaration)
10923 then
10924 Error_Pragma
10925 ("pragma% can only apply to a package declaration");
10926 end if;
10928 Set_Is_Remote_Types (Cunit_Ent);
10929 end Remote_Types;
10931 ---------------
10932 -- Ravenscar --
10933 ---------------
10935 -- pragma Ravenscar;
10937 when Pragma_Ravenscar =>
10938 GNAT_Pragma;
10939 Check_Arg_Count (0);
10940 Check_Valid_Configuration_Pragma;
10941 Set_Ravenscar_Profile (N);
10943 if Warn_On_Obsolescent_Feature then
10944 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
10945 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
10946 end if;
10948 -------------------------
10949 -- Restricted_Run_Time --
10950 -------------------------
10952 -- pragma Restricted_Run_Time;
10954 when Pragma_Restricted_Run_Time =>
10955 GNAT_Pragma;
10956 Check_Arg_Count (0);
10957 Check_Valid_Configuration_Pragma;
10958 Set_Profile_Restrictions
10959 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10961 if Warn_On_Obsolescent_Feature then
10962 Error_Msg_N
10963 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
10964 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
10965 end if;
10967 ------------------
10968 -- Restrictions --
10969 ------------------
10971 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
10973 -- RESTRICTION ::=
10974 -- restriction_IDENTIFIER
10975 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10977 when Pragma_Restrictions =>
10978 Process_Restrictions_Or_Restriction_Warnings
10979 (Warn => Treat_Restrictions_As_Warnings);
10981 --------------------------
10982 -- Restriction_Warnings --
10983 --------------------------
10985 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
10987 -- RESTRICTION ::=
10988 -- restriction_IDENTIFIER
10989 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10991 when Pragma_Restriction_Warnings =>
10992 GNAT_Pragma;
10993 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
10995 ----------------
10996 -- Reviewable --
10997 ----------------
10999 -- pragma Reviewable;
11001 when Pragma_Reviewable =>
11002 Check_Ada_83_Warning;
11003 Check_Arg_Count (0);
11005 -- Call dummy debugging function rv. This is done to assist front
11006 -- end debugging. By placing a Reviewable pragma in the source
11007 -- program, a breakpoint on rv catches this place in the source,
11008 -- allowing convenient stepping to the point of interest.
11012 --------------------------
11013 -- Short_Circuit_And_Or --
11014 --------------------------
11016 when Pragma_Short_Circuit_And_Or =>
11017 GNAT_Pragma;
11018 Check_Arg_Count (0);
11019 Check_Valid_Configuration_Pragma;
11020 Short_Circuit_And_Or := True;
11022 -------------------
11023 -- Share_Generic --
11024 -------------------
11026 -- pragma Share_Generic (NAME {, NAME});
11028 when Pragma_Share_Generic =>
11029 GNAT_Pragma;
11030 Process_Generic_List;
11032 ------------
11033 -- Shared --
11034 ------------
11036 -- pragma Shared (LOCAL_NAME);
11038 when Pragma_Shared =>
11039 GNAT_Pragma;
11040 Process_Atomic_Shared_Volatile;
11042 --------------------
11043 -- Shared_Passive --
11044 --------------------
11046 -- pragma Shared_Passive [(library_unit_NAME)];
11048 -- Set the flag Is_Shared_Passive of program unit name entity
11050 when Pragma_Shared_Passive => Shared_Passive : declare
11051 Cunit_Node : Node_Id;
11052 Cunit_Ent : Entity_Id;
11054 begin
11055 Check_Ada_83_Warning;
11056 Check_Valid_Library_Unit_Pragma;
11058 if Nkind (N) = N_Null_Statement then
11059 return;
11060 end if;
11062 Cunit_Node := Cunit (Current_Sem_Unit);
11063 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
11065 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
11066 N_Generic_Package_Declaration)
11067 then
11068 Error_Pragma
11069 ("pragma% can only apply to a package declaration");
11070 end if;
11072 Set_Is_Shared_Passive (Cunit_Ent);
11073 end Shared_Passive;
11075 -----------------------
11076 -- Short_Descriptors --
11077 -----------------------
11079 -- pragma Short_Descriptors;
11081 when Pragma_Short_Descriptors =>
11082 GNAT_Pragma;
11083 Check_Arg_Count (0);
11084 Check_Valid_Configuration_Pragma;
11085 Short_Descriptors := True;
11087 ----------------------
11088 -- Source_File_Name --
11089 ----------------------
11091 -- There are five forms for this pragma:
11093 -- pragma Source_File_Name (
11094 -- [UNIT_NAME =>] unit_NAME,
11095 -- BODY_FILE_NAME => STRING_LITERAL
11096 -- [, [INDEX =>] INTEGER_LITERAL]);
11098 -- pragma Source_File_Name (
11099 -- [UNIT_NAME =>] unit_NAME,
11100 -- SPEC_FILE_NAME => STRING_LITERAL
11101 -- [, [INDEX =>] INTEGER_LITERAL]);
11103 -- pragma Source_File_Name (
11104 -- BODY_FILE_NAME => STRING_LITERAL
11105 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11106 -- [, CASING => CASING_SPEC]);
11108 -- pragma Source_File_Name (
11109 -- SPEC_FILE_NAME => STRING_LITERAL
11110 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11111 -- [, CASING => CASING_SPEC]);
11113 -- pragma Source_File_Name (
11114 -- SUBUNIT_FILE_NAME => STRING_LITERAL
11115 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11116 -- [, CASING => CASING_SPEC]);
11118 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
11120 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
11121 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
11122 -- only be used when no project file is used, while SFNP can only be
11123 -- used when a project file is used.
11125 -- No processing here. Processing was completed during parsing, since
11126 -- we need to have file names set as early as possible. Units are
11127 -- loaded well before semantic processing starts.
11129 -- The only processing we defer to this point is the check for
11130 -- correct placement.
11132 when Pragma_Source_File_Name =>
11133 GNAT_Pragma;
11134 Check_Valid_Configuration_Pragma;
11136 ------------------------------
11137 -- Source_File_Name_Project --
11138 ------------------------------
11140 -- See Source_File_Name for syntax
11142 -- No processing here. Processing was completed during parsing, since
11143 -- we need to have file names set as early as possible. Units are
11144 -- loaded well before semantic processing starts.
11146 -- The only processing we defer to this point is the check for
11147 -- correct placement.
11149 when Pragma_Source_File_Name_Project =>
11150 GNAT_Pragma;
11151 Check_Valid_Configuration_Pragma;
11153 -- Check that a pragma Source_File_Name_Project is used only in a
11154 -- configuration pragmas file.
11156 -- Pragmas Source_File_Name_Project should only be generated by
11157 -- the Project Manager in configuration pragmas files.
11159 -- This is really an ugly test. It seems to depend on some
11160 -- accidental and undocumented property. At the very least it
11161 -- needs to be documented, but it would be better to have a
11162 -- clean way of testing if we are in a configuration file???
11164 if Present (Parent (N)) then
11165 Error_Pragma
11166 ("pragma% can only appear in a configuration pragmas file");
11167 end if;
11169 ----------------------
11170 -- Source_Reference --
11171 ----------------------
11173 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
11175 -- Nothing to do, all processing completed in Par.Prag, since we need
11176 -- the information for possible parser messages that are output.
11178 when Pragma_Source_Reference =>
11179 GNAT_Pragma;
11181 --------------------------------
11182 -- Static_Elaboration_Desired --
11183 --------------------------------
11185 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
11187 when Pragma_Static_Elaboration_Desired =>
11188 GNAT_Pragma;
11189 Check_At_Most_N_Arguments (1);
11191 if Is_Compilation_Unit (Current_Scope)
11192 and then Ekind (Current_Scope) = E_Package
11193 then
11194 Set_Static_Elaboration_Desired (Current_Scope, True);
11195 else
11196 Error_Pragma ("pragma% must apply to a library-level package");
11197 end if;
11199 ------------------
11200 -- Storage_Size --
11201 ------------------
11203 -- pragma Storage_Size (EXPRESSION);
11205 when Pragma_Storage_Size => Storage_Size : declare
11206 P : constant Node_Id := Parent (N);
11207 Arg : Node_Id;
11209 begin
11210 Check_No_Identifiers;
11211 Check_Arg_Count (1);
11213 -- The expression must be analyzed in the special manner described
11214 -- in "Handling of Default Expressions" in sem.ads.
11216 Arg := Expression (Arg1);
11217 Preanalyze_Spec_Expression (Arg, Any_Integer);
11219 if not Is_Static_Expression (Arg) then
11220 Check_Restriction (Static_Storage_Size, Arg);
11221 end if;
11223 if Nkind (P) /= N_Task_Definition then
11224 Pragma_Misplaced;
11225 return;
11227 else
11228 if Has_Storage_Size_Pragma (P) then
11229 Error_Pragma ("duplicate pragma% not allowed");
11230 else
11231 Set_Has_Storage_Size_Pragma (P, True);
11232 end if;
11234 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11235 -- ??? exp_ch9 should use this!
11236 end if;
11237 end Storage_Size;
11239 ------------------
11240 -- Storage_Unit --
11241 ------------------
11243 -- pragma Storage_Unit (NUMERIC_LITERAL);
11245 -- Only permitted argument is System'Storage_Unit value
11247 when Pragma_Storage_Unit =>
11248 Check_No_Identifiers;
11249 Check_Arg_Count (1);
11250 Check_Arg_Is_Integer_Literal (Arg1);
11252 if Intval (Expression (Arg1)) /=
11253 UI_From_Int (Ttypes.System_Storage_Unit)
11254 then
11255 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
11256 Error_Pragma_Arg
11257 ("the only allowed argument for pragma% is ^", Arg1);
11258 end if;
11260 --------------------
11261 -- Stream_Convert --
11262 --------------------
11264 -- pragma Stream_Convert (
11265 -- [Entity =>] type_LOCAL_NAME,
11266 -- [Read =>] function_NAME,
11267 -- [Write =>] function NAME);
11269 when Pragma_Stream_Convert => Stream_Convert : declare
11271 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
11272 -- Check that the given argument is the name of a local function
11273 -- of one argument that is not overloaded earlier in the current
11274 -- local scope. A check is also made that the argument is a
11275 -- function with one parameter.
11277 --------------------------------------
11278 -- Check_OK_Stream_Convert_Function --
11279 --------------------------------------
11281 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
11282 Ent : Entity_Id;
11284 begin
11285 Check_Arg_Is_Local_Name (Arg);
11286 Ent := Entity (Expression (Arg));
11288 if Has_Homonym (Ent) then
11289 Error_Pragma_Arg
11290 ("argument for pragma% may not be overloaded", Arg);
11291 end if;
11293 if Ekind (Ent) /= E_Function
11294 or else No (First_Formal (Ent))
11295 or else Present (Next_Formal (First_Formal (Ent)))
11296 then
11297 Error_Pragma_Arg
11298 ("argument for pragma% must be" &
11299 " function of one argument", Arg);
11300 end if;
11301 end Check_OK_Stream_Convert_Function;
11303 -- Start of processing for Stream_Convert
11305 begin
11306 GNAT_Pragma;
11307 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
11308 Check_Arg_Count (3);
11309 Check_Optional_Identifier (Arg1, Name_Entity);
11310 Check_Optional_Identifier (Arg2, Name_Read);
11311 Check_Optional_Identifier (Arg3, Name_Write);
11312 Check_Arg_Is_Local_Name (Arg1);
11313 Check_OK_Stream_Convert_Function (Arg2);
11314 Check_OK_Stream_Convert_Function (Arg3);
11316 declare
11317 Typ : constant Entity_Id :=
11318 Underlying_Type (Entity (Expression (Arg1)));
11319 Read : constant Entity_Id := Entity (Expression (Arg2));
11320 Write : constant Entity_Id := Entity (Expression (Arg3));
11322 begin
11323 Check_First_Subtype (Arg1);
11325 -- Check for too early or too late. Note that we don't enforce
11326 -- the rule about primitive operations in this case, since, as
11327 -- is the case for explicit stream attributes themselves, these
11328 -- restrictions are not appropriate. Note that the chaining of
11329 -- the pragma by Rep_Item_Too_Late is actually the critical
11330 -- processing done for this pragma.
11332 if Rep_Item_Too_Early (Typ, N)
11333 or else
11334 Rep_Item_Too_Late (Typ, N, FOnly => True)
11335 then
11336 return;
11337 end if;
11339 -- Return if previous error
11341 if Etype (Typ) = Any_Type
11342 or else
11343 Etype (Read) = Any_Type
11344 or else
11345 Etype (Write) = Any_Type
11346 then
11347 return;
11348 end if;
11350 -- Error checks
11352 if Underlying_Type (Etype (Read)) /= Typ then
11353 Error_Pragma_Arg
11354 ("incorrect return type for function&", Arg2);
11355 end if;
11357 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
11358 Error_Pragma_Arg
11359 ("incorrect parameter type for function&", Arg3);
11360 end if;
11362 if Underlying_Type (Etype (First_Formal (Read))) /=
11363 Underlying_Type (Etype (Write))
11364 then
11365 Error_Pragma_Arg
11366 ("result type of & does not match Read parameter type",
11367 Arg3);
11368 end if;
11369 end;
11370 end Stream_Convert;
11372 -------------------------
11373 -- Style_Checks (GNAT) --
11374 -------------------------
11376 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11378 -- This is processed by the parser since some of the style checks
11379 -- take place during source scanning and parsing. This means that
11380 -- we don't need to issue error messages here.
11382 when Pragma_Style_Checks => Style_Checks : declare
11383 A : constant Node_Id := Expression (Arg1);
11384 S : String_Id;
11385 C : Char_Code;
11387 begin
11388 GNAT_Pragma;
11389 Check_No_Identifiers;
11391 -- Two argument form
11393 if Arg_Count = 2 then
11394 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11396 declare
11397 E_Id : Node_Id;
11398 E : Entity_Id;
11400 begin
11401 E_Id := Expression (Arg2);
11402 Analyze (E_Id);
11404 if not Is_Entity_Name (E_Id) then
11405 Error_Pragma_Arg
11406 ("second argument of pragma% must be entity name",
11407 Arg2);
11408 end if;
11410 E := Entity (E_Id);
11412 if E = Any_Id then
11413 return;
11414 else
11415 loop
11416 Set_Suppress_Style_Checks (E,
11417 (Chars (Expression (Arg1)) = Name_Off));
11418 exit when No (Homonym (E));
11419 E := Homonym (E);
11420 end loop;
11421 end if;
11422 end;
11424 -- One argument form
11426 else
11427 Check_Arg_Count (1);
11429 if Nkind (A) = N_String_Literal then
11430 S := Strval (A);
11432 declare
11433 Slen : constant Natural := Natural (String_Length (S));
11434 Options : String (1 .. Slen);
11435 J : Natural;
11437 begin
11438 J := 1;
11439 loop
11440 C := Get_String_Char (S, Int (J));
11441 exit when not In_Character_Range (C);
11442 Options (J) := Get_Character (C);
11444 -- If at end of string, set options. As per discussion
11445 -- above, no need to check for errors, since we issued
11446 -- them in the parser.
11448 if J = Slen then
11449 Set_Style_Check_Options (Options);
11450 exit;
11451 end if;
11453 J := J + 1;
11454 end loop;
11455 end;
11457 elsif Nkind (A) = N_Identifier then
11458 if Chars (A) = Name_All_Checks then
11459 if GNAT_Mode then
11460 Set_GNAT_Style_Check_Options;
11461 else
11462 Set_Default_Style_Check_Options;
11463 end if;
11465 elsif Chars (A) = Name_On then
11466 Style_Check := True;
11468 elsif Chars (A) = Name_Off then
11469 Style_Check := False;
11470 end if;
11471 end if;
11472 end if;
11473 end Style_Checks;
11475 --------------
11476 -- Subtitle --
11477 --------------
11479 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
11481 when Pragma_Subtitle =>
11482 GNAT_Pragma;
11483 Check_Arg_Count (1);
11484 Check_Optional_Identifier (Arg1, Name_Subtitle);
11485 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11486 Store_Note (N);
11488 --------------
11489 -- Suppress --
11490 --------------
11492 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
11494 when Pragma_Suppress =>
11495 Process_Suppress_Unsuppress (True);
11497 ------------------
11498 -- Suppress_All --
11499 ------------------
11501 -- pragma Suppress_All;
11503 -- The only check made here is that the pragma appears in the proper
11504 -- place, i.e. following a compilation unit. If indeed it appears in
11505 -- this context, then the parser has already inserted an equivalent
11506 -- pragma Suppress (All_Checks) to get the required effect.
11508 when Pragma_Suppress_All =>
11509 GNAT_Pragma;
11510 Check_Arg_Count (0);
11512 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
11513 or else not Is_List_Member (N)
11514 or else List_Containing (N) /= Pragmas_After (Parent (N))
11515 then
11516 Error_Pragma
11517 ("misplaced pragma%, must follow compilation unit");
11518 end if;
11520 -------------------------
11521 -- Suppress_Debug_Info --
11522 -------------------------
11524 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
11526 when Pragma_Suppress_Debug_Info =>
11527 GNAT_Pragma;
11528 Check_Arg_Count (1);
11529 Check_Optional_Identifier (Arg1, Name_Entity);
11530 Check_Arg_Is_Local_Name (Arg1);
11531 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
11533 ----------------------------------
11534 -- Suppress_Exception_Locations --
11535 ----------------------------------
11537 -- pragma Suppress_Exception_Locations;
11539 when Pragma_Suppress_Exception_Locations =>
11540 GNAT_Pragma;
11541 Check_Arg_Count (0);
11542 Check_Valid_Configuration_Pragma;
11543 Exception_Locations_Suppressed := True;
11545 -----------------------------
11546 -- Suppress_Initialization --
11547 -----------------------------
11549 -- pragma Suppress_Initialization ([Entity =>] type_Name);
11551 when Pragma_Suppress_Initialization => Suppress_Init : declare
11552 E_Id : Node_Id;
11553 E : Entity_Id;
11555 begin
11556 GNAT_Pragma;
11557 Check_Arg_Count (1);
11558 Check_Optional_Identifier (Arg1, Name_Entity);
11559 Check_Arg_Is_Local_Name (Arg1);
11561 E_Id := Expression (Arg1);
11563 if Etype (E_Id) = Any_Type then
11564 return;
11565 end if;
11567 E := Entity (E_Id);
11569 if Is_Type (E) then
11570 if Is_Incomplete_Or_Private_Type (E) then
11571 if No (Full_View (Base_Type (E))) then
11572 Error_Pragma_Arg
11573 ("argument of pragma% cannot be an incomplete type",
11574 Arg1);
11575 else
11576 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
11577 end if;
11578 else
11579 Set_Suppress_Init_Proc (Base_Type (E));
11580 end if;
11582 else
11583 Error_Pragma_Arg
11584 ("pragma% requires argument that is a type name", Arg1);
11585 end if;
11586 end Suppress_Init;
11588 -----------------
11589 -- System_Name --
11590 -----------------
11592 -- pragma System_Name (DIRECT_NAME);
11594 -- Syntax check: one argument, which must be the identifier GNAT or
11595 -- the identifier GCC, no other identifiers are acceptable.
11597 when Pragma_System_Name =>
11598 GNAT_Pragma;
11599 Check_No_Identifiers;
11600 Check_Arg_Count (1);
11601 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
11603 -----------------------------
11604 -- Task_Dispatching_Policy --
11605 -----------------------------
11607 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
11609 when Pragma_Task_Dispatching_Policy => declare
11610 DP : Character;
11612 begin
11613 Check_Ada_83_Warning;
11614 Check_Arg_Count (1);
11615 Check_No_Identifiers;
11616 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11617 Check_Valid_Configuration_Pragma;
11618 Get_Name_String (Chars (Expression (Arg1)));
11619 DP := Fold_Upper (Name_Buffer (1));
11621 if Task_Dispatching_Policy /= ' '
11622 and then Task_Dispatching_Policy /= DP
11623 then
11624 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11625 Error_Pragma
11626 ("task dispatching policy incompatible with policy#");
11628 -- Set new policy, but always preserve System_Location since we
11629 -- like the error message with the run time name.
11631 else
11632 Task_Dispatching_Policy := DP;
11634 if Task_Dispatching_Policy_Sloc /= System_Location then
11635 Task_Dispatching_Policy_Sloc := Loc;
11636 end if;
11637 end if;
11638 end;
11640 --------------
11641 -- Task_Info --
11642 --------------
11644 -- pragma Task_Info (EXPRESSION);
11646 when Pragma_Task_Info => Task_Info : declare
11647 P : constant Node_Id := Parent (N);
11649 begin
11650 GNAT_Pragma;
11652 if Nkind (P) /= N_Task_Definition then
11653 Error_Pragma ("pragma% must appear in task definition");
11654 end if;
11656 Check_No_Identifiers;
11657 Check_Arg_Count (1);
11659 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
11661 if Etype (Expression (Arg1)) = Any_Type then
11662 return;
11663 end if;
11665 if Has_Task_Info_Pragma (P) then
11666 Error_Pragma ("duplicate pragma% not allowed");
11667 else
11668 Set_Has_Task_Info_Pragma (P, True);
11669 end if;
11670 end Task_Info;
11672 ---------------
11673 -- Task_Name --
11674 ---------------
11676 -- pragma Task_Name (string_EXPRESSION);
11678 when Pragma_Task_Name => Task_Name : declare
11679 P : constant Node_Id := Parent (N);
11680 Arg : Node_Id;
11682 begin
11683 Check_No_Identifiers;
11684 Check_Arg_Count (1);
11686 Arg := Expression (Arg1);
11688 -- The expression is used in the call to Create_Task, and must be
11689 -- expanded there, not in the context of the current spec. It must
11690 -- however be analyzed to capture global references, in case it
11691 -- appears in a generic context.
11693 Preanalyze_And_Resolve (Arg, Standard_String);
11695 if Nkind (P) /= N_Task_Definition then
11696 Pragma_Misplaced;
11697 end if;
11699 if Has_Task_Name_Pragma (P) then
11700 Error_Pragma ("duplicate pragma% not allowed");
11701 else
11702 Set_Has_Task_Name_Pragma (P, True);
11703 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11704 end if;
11705 end Task_Name;
11707 ------------------
11708 -- Task_Storage --
11709 ------------------
11711 -- pragma Task_Storage (
11712 -- [Task_Type =>] LOCAL_NAME,
11713 -- [Top_Guard =>] static_integer_EXPRESSION);
11715 when Pragma_Task_Storage => Task_Storage : declare
11716 Args : Args_List (1 .. 2);
11717 Names : constant Name_List (1 .. 2) := (
11718 Name_Task_Type,
11719 Name_Top_Guard);
11721 Task_Type : Node_Id renames Args (1);
11722 Top_Guard : Node_Id renames Args (2);
11724 Ent : Entity_Id;
11726 begin
11727 GNAT_Pragma;
11728 Gather_Associations (Names, Args);
11730 if No (Task_Type) then
11731 Error_Pragma
11732 ("missing task_type argument for pragma%");
11733 end if;
11735 Check_Arg_Is_Local_Name (Task_Type);
11737 Ent := Entity (Task_Type);
11739 if not Is_Task_Type (Ent) then
11740 Error_Pragma_Arg
11741 ("argument for pragma% must be task type", Task_Type);
11742 end if;
11744 if No (Top_Guard) then
11745 Error_Pragma_Arg
11746 ("pragma% takes two arguments", Task_Type);
11747 else
11748 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
11749 end if;
11751 Check_First_Subtype (Task_Type);
11753 if Rep_Item_Too_Late (Ent, N) then
11754 raise Pragma_Exit;
11755 end if;
11756 end Task_Storage;
11758 --------------------------
11759 -- Thread_Local_Storage --
11760 --------------------------
11762 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
11764 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
11765 Id : Node_Id;
11766 E : Entity_Id;
11768 begin
11769 GNAT_Pragma;
11770 Check_Arg_Count (1);
11771 Check_Optional_Identifier (Arg1, Name_Entity);
11772 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11774 Id := Expression (Arg1);
11775 Analyze (Id);
11777 if not Is_Entity_Name (Id)
11778 or else Ekind (Entity (Id)) /= E_Variable
11779 then
11780 Error_Pragma_Arg ("local variable name required", Arg1);
11781 end if;
11783 E := Entity (Id);
11785 if Rep_Item_Too_Early (E, N)
11786 or else Rep_Item_Too_Late (E, N)
11787 then
11788 raise Pragma_Exit;
11789 end if;
11791 Set_Has_Pragma_Thread_Local_Storage (E);
11792 Set_Has_Gigi_Rep_Item (E);
11793 end Thread_Local_Storage;
11795 ----------------
11796 -- Time_Slice --
11797 ----------------
11799 -- pragma Time_Slice (static_duration_EXPRESSION);
11801 when Pragma_Time_Slice => Time_Slice : declare
11802 Val : Ureal;
11803 Nod : Node_Id;
11805 begin
11806 GNAT_Pragma;
11807 Check_Arg_Count (1);
11808 Check_No_Identifiers;
11809 Check_In_Main_Program;
11810 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
11812 if not Error_Posted (Arg1) then
11813 Nod := Next (N);
11814 while Present (Nod) loop
11815 if Nkind (Nod) = N_Pragma
11816 and then Pragma_Name (Nod) = Name_Time_Slice
11817 then
11818 Error_Msg_Name_1 := Pname;
11819 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11820 end if;
11822 Next (Nod);
11823 end loop;
11824 end if;
11826 -- Process only if in main unit
11828 if Get_Source_Unit (Loc) = Main_Unit then
11829 Opt.Time_Slice_Set := True;
11830 Val := Expr_Value_R (Expression (Arg1));
11832 if Val <= Ureal_0 then
11833 Opt.Time_Slice_Value := 0;
11835 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
11836 Opt.Time_Slice_Value := 1_000_000_000;
11838 else
11839 Opt.Time_Slice_Value :=
11840 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
11841 end if;
11842 end if;
11843 end Time_Slice;
11845 -----------
11846 -- Title --
11847 -----------
11849 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
11851 -- TITLING_OPTION ::=
11852 -- [Title =>] STRING_LITERAL
11853 -- | [Subtitle =>] STRING_LITERAL
11855 when Pragma_Title => Title : declare
11856 Args : Args_List (1 .. 2);
11857 Names : constant Name_List (1 .. 2) := (
11858 Name_Title,
11859 Name_Subtitle);
11861 begin
11862 GNAT_Pragma;
11863 Gather_Associations (Names, Args);
11864 Store_Note (N);
11866 for J in 1 .. 2 loop
11867 if Present (Args (J)) then
11868 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
11869 end if;
11870 end loop;
11871 end Title;
11873 ---------------------
11874 -- Unchecked_Union --
11875 ---------------------
11877 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
11879 when Pragma_Unchecked_Union => Unchecked_Union : declare
11880 Assoc : constant Node_Id := Arg1;
11881 Type_Id : constant Node_Id := Expression (Assoc);
11882 Typ : Entity_Id;
11883 Discr : Entity_Id;
11884 Tdef : Node_Id;
11885 Clist : Node_Id;
11886 Vpart : Node_Id;
11887 Comp : Node_Id;
11888 Variant : Node_Id;
11890 begin
11891 Ada_2005_Pragma;
11892 Check_No_Identifiers;
11893 Check_Arg_Count (1);
11894 Check_Arg_Is_Local_Name (Arg1);
11896 Find_Type (Type_Id);
11897 Typ := Entity (Type_Id);
11899 if Typ = Any_Type
11900 or else Rep_Item_Too_Early (Typ, N)
11901 then
11902 return;
11903 else
11904 Typ := Underlying_Type (Typ);
11905 end if;
11907 if Rep_Item_Too_Late (Typ, N) then
11908 return;
11909 end if;
11911 Check_First_Subtype (Arg1);
11913 -- Note remaining cases are references to a type in the current
11914 -- declarative part. If we find an error, we post the error on
11915 -- the relevant type declaration at an appropriate point.
11917 if not Is_Record_Type (Typ) then
11918 Error_Msg_N ("Unchecked_Union must be record type", Typ);
11919 return;
11921 elsif Is_Tagged_Type (Typ) then
11922 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
11923 return;
11925 elsif Is_Limited_Type (Typ) then
11926 Error_Msg_N
11927 ("Unchecked_Union must not be limited record type", Typ);
11928 Explain_Limited_Type (Typ, Typ);
11929 return;
11931 else
11932 if not Has_Discriminants (Typ) then
11933 Error_Msg_N
11934 ("Unchecked_Union must have one discriminant", Typ);
11935 return;
11936 end if;
11938 Discr := First_Discriminant (Typ);
11939 while Present (Discr) loop
11940 if No (Discriminant_Default_Value (Discr)) then
11941 Error_Msg_N
11942 ("Unchecked_Union discriminant must have default value",
11943 Discr);
11944 end if;
11945 Next_Discriminant (Discr);
11946 end loop;
11948 Tdef := Type_Definition (Declaration_Node (Typ));
11949 Clist := Component_List (Tdef);
11951 Comp := First (Component_Items (Clist));
11952 while Present (Comp) loop
11953 Check_Component (Comp);
11954 Next (Comp);
11955 end loop;
11957 if No (Clist) or else No (Variant_Part (Clist)) then
11958 Error_Msg_N
11959 ("Unchecked_Union must have variant part",
11960 Tdef);
11961 return;
11962 end if;
11964 Vpart := Variant_Part (Clist);
11966 Variant := First (Variants (Vpart));
11967 while Present (Variant) loop
11968 Check_Variant (Variant);
11969 Next (Variant);
11970 end loop;
11971 end if;
11973 Set_Is_Unchecked_Union (Typ, True);
11974 Set_Convention (Typ, Convention_C);
11976 Set_Has_Unchecked_Union (Base_Type (Typ), True);
11977 Set_Is_Unchecked_Union (Base_Type (Typ), True);
11978 end Unchecked_Union;
11980 ------------------------
11981 -- Unimplemented_Unit --
11982 ------------------------
11984 -- pragma Unimplemented_Unit;
11986 -- Note: this only gives an error if we are generating code, or if
11987 -- we are in a generic library unit (where the pragma appears in the
11988 -- body, not in the spec).
11990 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
11991 Cunitent : constant Entity_Id :=
11992 Cunit_Entity (Get_Source_Unit (Loc));
11993 Ent_Kind : constant Entity_Kind :=
11994 Ekind (Cunitent);
11996 begin
11997 GNAT_Pragma;
11998 Check_Arg_Count (0);
12000 if Operating_Mode = Generate_Code
12001 or else Ent_Kind = E_Generic_Function
12002 or else Ent_Kind = E_Generic_Procedure
12003 or else Ent_Kind = E_Generic_Package
12004 then
12005 Get_Name_String (Chars (Cunitent));
12006 Set_Casing (Mixed_Case);
12007 Write_Str (Name_Buffer (1 .. Name_Len));
12008 Write_Str (" is not supported in this configuration");
12009 Write_Eol;
12010 raise Unrecoverable_Error;
12011 end if;
12012 end Unimplemented_Unit;
12014 ------------------------
12015 -- Universal_Aliasing --
12016 ------------------------
12018 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
12020 when Pragma_Universal_Aliasing => Universal_Alias : declare
12021 E_Id : Entity_Id;
12023 begin
12024 GNAT_Pragma;
12025 Check_Arg_Count (1);
12026 Check_Optional_Identifier (Arg2, Name_Entity);
12027 Check_Arg_Is_Local_Name (Arg1);
12028 E_Id := Entity (Expression (Arg1));
12030 if E_Id = Any_Type then
12031 return;
12032 elsif No (E_Id) or else not Is_Type (E_Id) then
12033 Error_Pragma_Arg ("pragma% requires type", Arg1);
12034 end if;
12036 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
12037 end Universal_Alias;
12039 --------------------
12040 -- Universal_Data --
12041 --------------------
12043 -- pragma Universal_Data [(library_unit_NAME)];
12045 when Pragma_Universal_Data =>
12046 GNAT_Pragma;
12048 -- If this is a configuration pragma, then set the universal
12049 -- addressing option, otherwise confirm that the pragma satisfies
12050 -- the requirements of library unit pragma placement and leave it
12051 -- to the GNAAMP back end to detect the pragma (avoids transitive
12052 -- setting of the option due to withed units).
12054 if Is_Configuration_Pragma then
12055 Universal_Addressing_On_AAMP := True;
12056 else
12057 Check_Valid_Library_Unit_Pragma;
12058 end if;
12060 if not AAMP_On_Target then
12061 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
12062 end if;
12064 ----------------
12065 -- Unmodified --
12066 ----------------
12068 -- pragma Unmodified (local_Name {, local_Name});
12070 when Pragma_Unmodified => Unmodified : declare
12071 Arg_Node : Node_Id;
12072 Arg_Expr : Node_Id;
12073 Arg_Ent : Entity_Id;
12075 begin
12076 GNAT_Pragma;
12077 Check_At_Least_N_Arguments (1);
12079 -- Loop through arguments
12081 Arg_Node := Arg1;
12082 while Present (Arg_Node) loop
12083 Check_No_Identifier (Arg_Node);
12085 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
12086 -- in fact generate reference, so that the entity will have a
12087 -- reference, which will inhibit any warnings about it not
12088 -- being referenced, and also properly show up in the ali file
12089 -- as a reference. But this reference is recorded before the
12090 -- Has_Pragma_Unreferenced flag is set, so that no warning is
12091 -- generated for this reference.
12093 Check_Arg_Is_Local_Name (Arg_Node);
12094 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12096 if Is_Entity_Name (Arg_Expr) then
12097 Arg_Ent := Entity (Arg_Expr);
12099 if not Is_Assignable (Arg_Ent) then
12100 Error_Pragma_Arg
12101 ("pragma% can only be applied to a variable",
12102 Arg_Expr);
12103 else
12104 Set_Has_Pragma_Unmodified (Arg_Ent);
12105 end if;
12106 end if;
12108 Next (Arg_Node);
12109 end loop;
12110 end Unmodified;
12112 ------------------
12113 -- Unreferenced --
12114 ------------------
12116 -- pragma Unreferenced (local_Name {, local_Name});
12118 -- or when used in a context clause:
12120 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
12122 when Pragma_Unreferenced => Unreferenced : declare
12123 Arg_Node : Node_Id;
12124 Arg_Expr : Node_Id;
12125 Arg_Ent : Entity_Id;
12126 Citem : Node_Id;
12128 begin
12129 GNAT_Pragma;
12130 Check_At_Least_N_Arguments (1);
12132 -- Check case of appearing within context clause
12134 if Is_In_Context_Clause then
12136 -- The arguments must all be units mentioned in a with clause
12137 -- in the same context clause. Note we already checked (in
12138 -- Par.Prag) that the arguments are either identifiers or
12139 -- selected components.
12141 Arg_Node := Arg1;
12142 while Present (Arg_Node) loop
12143 Citem := First (List_Containing (N));
12144 while Citem /= N loop
12145 if Nkind (Citem) = N_With_Clause
12146 and then Same_Name (Name (Citem), Expression (Arg_Node))
12147 then
12148 Set_Has_Pragma_Unreferenced
12149 (Cunit_Entity
12150 (Get_Source_Unit
12151 (Library_Unit (Citem))));
12152 Set_Unit_Name (Expression (Arg_Node), Name (Citem));
12153 exit;
12154 end if;
12156 Next (Citem);
12157 end loop;
12159 if Citem = N then
12160 Error_Pragma_Arg
12161 ("argument of pragma% is not with'ed unit", Arg_Node);
12162 end if;
12164 Next (Arg_Node);
12165 end loop;
12167 -- Case of not in list of context items
12169 else
12170 Arg_Node := Arg1;
12171 while Present (Arg_Node) loop
12172 Check_No_Identifier (Arg_Node);
12174 -- Note: the analyze call done by Check_Arg_Is_Local_Name
12175 -- will in fact generate reference, so that the entity will
12176 -- have a reference, which will inhibit any warnings about
12177 -- it not being referenced, and also properly show up in the
12178 -- ali file as a reference. But this reference is recorded
12179 -- before the Has_Pragma_Unreferenced flag is set, so that
12180 -- no warning is generated for this reference.
12182 Check_Arg_Is_Local_Name (Arg_Node);
12183 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12185 if Is_Entity_Name (Arg_Expr) then
12186 Arg_Ent := Entity (Arg_Expr);
12188 -- If the entity is overloaded, the pragma applies to the
12189 -- most recent overloading, as documented. In this case,
12190 -- name resolution does not generate a reference, so it
12191 -- must be done here explicitly.
12193 if Is_Overloaded (Arg_Expr) then
12194 Generate_Reference (Arg_Ent, N);
12195 end if;
12197 Set_Has_Pragma_Unreferenced (Arg_Ent);
12198 end if;
12200 Next (Arg_Node);
12201 end loop;
12202 end if;
12203 end Unreferenced;
12205 --------------------------
12206 -- Unreferenced_Objects --
12207 --------------------------
12209 -- pragma Unreferenced_Objects (local_Name {, local_Name});
12211 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
12212 Arg_Node : Node_Id;
12213 Arg_Expr : Node_Id;
12215 begin
12216 GNAT_Pragma;
12217 Check_At_Least_N_Arguments (1);
12219 Arg_Node := Arg1;
12220 while Present (Arg_Node) loop
12221 Check_No_Identifier (Arg_Node);
12222 Check_Arg_Is_Local_Name (Arg_Node);
12223 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12225 if not Is_Entity_Name (Arg_Expr)
12226 or else not Is_Type (Entity (Arg_Expr))
12227 then
12228 Error_Pragma_Arg
12229 ("argument for pragma% must be type or subtype", Arg_Node);
12230 end if;
12232 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
12233 Next (Arg_Node);
12234 end loop;
12235 end Unreferenced_Objects;
12237 ------------------------------
12238 -- Unreserve_All_Interrupts --
12239 ------------------------------
12241 -- pragma Unreserve_All_Interrupts;
12243 when Pragma_Unreserve_All_Interrupts =>
12244 GNAT_Pragma;
12245 Check_Arg_Count (0);
12247 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
12248 Unreserve_All_Interrupts := True;
12249 end if;
12251 ----------------
12252 -- Unsuppress --
12253 ----------------
12255 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
12257 when Pragma_Unsuppress =>
12258 Ada_2005_Pragma;
12259 Process_Suppress_Unsuppress (False);
12261 -------------------
12262 -- Use_VADS_Size --
12263 -------------------
12265 -- pragma Use_VADS_Size;
12267 when Pragma_Use_VADS_Size =>
12268 GNAT_Pragma;
12269 Check_Arg_Count (0);
12270 Check_Valid_Configuration_Pragma;
12271 Use_VADS_Size := True;
12273 ---------------------
12274 -- Validity_Checks --
12275 ---------------------
12277 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12279 when Pragma_Validity_Checks => Validity_Checks : declare
12280 A : constant Node_Id := Expression (Arg1);
12281 S : String_Id;
12282 C : Char_Code;
12284 begin
12285 GNAT_Pragma;
12286 Check_Arg_Count (1);
12287 Check_No_Identifiers;
12289 if Nkind (A) = N_String_Literal then
12290 S := Strval (A);
12292 declare
12293 Slen : constant Natural := Natural (String_Length (S));
12294 Options : String (1 .. Slen);
12295 J : Natural;
12297 begin
12298 J := 1;
12299 loop
12300 C := Get_String_Char (S, Int (J));
12301 exit when not In_Character_Range (C);
12302 Options (J) := Get_Character (C);
12304 if J = Slen then
12305 Set_Validity_Check_Options (Options);
12306 exit;
12307 else
12308 J := J + 1;
12309 end if;
12310 end loop;
12311 end;
12313 elsif Nkind (A) = N_Identifier then
12315 if Chars (A) = Name_All_Checks then
12316 Set_Validity_Check_Options ("a");
12318 elsif Chars (A) = Name_On then
12319 Validity_Checks_On := True;
12321 elsif Chars (A) = Name_Off then
12322 Validity_Checks_On := False;
12324 end if;
12325 end if;
12326 end Validity_Checks;
12328 --------------
12329 -- Volatile --
12330 --------------
12332 -- pragma Volatile (LOCAL_NAME);
12334 when Pragma_Volatile =>
12335 Process_Atomic_Shared_Volatile;
12337 -------------------------
12338 -- Volatile_Components --
12339 -------------------------
12341 -- pragma Volatile_Components (array_LOCAL_NAME);
12343 -- Volatile is handled by the same circuit as Atomic_Components
12345 --------------
12346 -- Warnings --
12347 --------------
12349 -- pragma Warnings (On | Off);
12350 -- pragma Warnings (On | Off, LOCAL_NAME);
12351 -- pragma Warnings (static_string_EXPRESSION);
12352 -- pragma Warnings (On | Off, STRING_LITERAL);
12354 when Pragma_Warnings => Warnings : begin
12355 GNAT_Pragma;
12356 Check_At_Least_N_Arguments (1);
12357 Check_No_Identifiers;
12359 -- If debug flag -gnatd.i is set, pragma is ignored
12361 if Debug_Flag_Dot_I then
12362 return;
12363 end if;
12365 -- Process various forms of the pragma
12367 declare
12368 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12370 begin
12371 -- One argument case
12373 if Arg_Count = 1 then
12375 -- On/Off one argument case was processed by parser
12377 if Nkind (Argx) = N_Identifier
12378 and then
12379 (Chars (Argx) = Name_On
12380 or else
12381 Chars (Argx) = Name_Off)
12382 then
12383 null;
12385 -- One argument case must be ON/OFF or static string expr
12387 elsif not Is_Static_String_Expression (Arg1) then
12388 Error_Pragma_Arg
12389 ("argument of pragma% must be On/Off or " &
12390 "static string expression", Arg1);
12392 -- One argument string expression case
12394 else
12395 declare
12396 Lit : constant Node_Id := Expr_Value_S (Argx);
12397 Str : constant String_Id := Strval (Lit);
12398 Len : constant Nat := String_Length (Str);
12399 C : Char_Code;
12400 J : Nat;
12401 OK : Boolean;
12402 Chr : Character;
12404 begin
12405 J := 1;
12406 while J <= Len loop
12407 C := Get_String_Char (Str, J);
12408 OK := In_Character_Range (C);
12410 if OK then
12411 Chr := Get_Character (C);
12413 -- Dot case
12415 if J < Len and then Chr = '.' then
12416 J := J + 1;
12417 C := Get_String_Char (Str, J);
12418 Chr := Get_Character (C);
12420 if not Set_Dot_Warning_Switch (Chr) then
12421 Error_Pragma_Arg
12422 ("invalid warning switch character " &
12423 '.' & Chr, Arg1);
12424 end if;
12426 -- Non-Dot case
12428 else
12429 OK := Set_Warning_Switch (Chr);
12430 end if;
12431 end if;
12433 if not OK then
12434 Error_Pragma_Arg
12435 ("invalid warning switch character " & Chr,
12436 Arg1);
12437 end if;
12439 J := J + 1;
12440 end loop;
12441 end;
12442 end if;
12444 -- Two or more arguments (must be two)
12446 else
12447 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12448 Check_At_Most_N_Arguments (2);
12450 declare
12451 E_Id : Node_Id;
12452 E : Entity_Id;
12453 Err : Boolean;
12455 begin
12456 E_Id := Expression (Arg2);
12457 Analyze (E_Id);
12459 -- In the expansion of an inlined body, a reference to
12460 -- the formal may be wrapped in a conversion if the
12461 -- actual is a conversion. Retrieve the real entity name.
12463 if (In_Instance_Body
12464 or else In_Inlined_Body)
12465 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
12466 then
12467 E_Id := Expression (E_Id);
12468 end if;
12470 -- Entity name case
12472 if Is_Entity_Name (E_Id) then
12473 E := Entity (E_Id);
12475 if E = Any_Id then
12476 return;
12477 else
12478 loop
12479 Set_Warnings_Off
12480 (E, (Chars (Expression (Arg1)) = Name_Off));
12482 if Chars (Expression (Arg1)) = Name_Off
12483 and then Warn_On_Warnings_Off
12484 then
12485 Warnings_Off_Pragmas.Append ((N, E));
12486 end if;
12488 if Is_Enumeration_Type (E) then
12489 declare
12490 Lit : Entity_Id;
12491 begin
12492 Lit := First_Literal (E);
12493 while Present (Lit) loop
12494 Set_Warnings_Off (Lit);
12495 Next_Literal (Lit);
12496 end loop;
12497 end;
12498 end if;
12500 exit when No (Homonym (E));
12501 E := Homonym (E);
12502 end loop;
12503 end if;
12505 -- Error if not entity or static string literal case
12507 elsif not Is_Static_String_Expression (Arg2) then
12508 Error_Pragma_Arg
12509 ("second argument of pragma% must be entity " &
12510 "name or static string expression", Arg2);
12512 -- String literal case
12514 else
12515 String_To_Name_Buffer
12516 (Strval (Expr_Value_S (Expression (Arg2))));
12518 -- Note on configuration pragma case: If this is a
12519 -- configuration pragma, then for an OFF pragma, we
12520 -- just set Config True in the call, which is all
12521 -- that needs to be done. For the case of ON, this
12522 -- is normally an error, unless it is canceling the
12523 -- effect of a previous OFF pragma in the same file.
12524 -- In any other case, an error will be signalled (ON
12525 -- with no matching OFF).
12527 if Chars (Argx) = Name_Off then
12528 Set_Specific_Warning_Off
12529 (Loc, Name_Buffer (1 .. Name_Len),
12530 Config => Is_Configuration_Pragma);
12532 elsif Chars (Argx) = Name_On then
12533 Set_Specific_Warning_On
12534 (Loc, Name_Buffer (1 .. Name_Len), Err);
12536 if Err then
12537 Error_Msg
12538 ("?pragma Warnings On with no " &
12539 "matching Warnings Off",
12540 Loc);
12541 end if;
12542 end if;
12543 end if;
12544 end;
12545 end if;
12546 end;
12547 end Warnings;
12549 -------------------
12550 -- Weak_External --
12551 -------------------
12553 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
12555 when Pragma_Weak_External => Weak_External : declare
12556 Ent : Entity_Id;
12558 begin
12559 GNAT_Pragma;
12560 Check_Arg_Count (1);
12561 Check_Optional_Identifier (Arg1, Name_Entity);
12562 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12563 Ent := Entity (Expression (Arg1));
12565 if Rep_Item_Too_Early (Ent, N) then
12566 return;
12567 else
12568 Ent := Underlying_Type (Ent);
12569 end if;
12571 -- The only processing required is to link this item on to the
12572 -- list of rep items for the given entity. This is accomplished
12573 -- by the call to Rep_Item_Too_Late (when no error is detected
12574 -- and False is returned).
12576 if Rep_Item_Too_Late (Ent, N) then
12577 return;
12578 else
12579 Set_Has_Gigi_Rep_Item (Ent);
12580 end if;
12581 end Weak_External;
12583 -----------------------------
12584 -- Wide_Character_Encoding --
12585 -----------------------------
12587 -- pragma Wide_Character_Encoding (IDENTIFIER);
12589 when Pragma_Wide_Character_Encoding =>
12590 GNAT_Pragma;
12592 -- Nothing to do, handled in parser. Note that we do not enforce
12593 -- configuration pragma placement, this pragma can appear at any
12594 -- place in the source, allowing mixed encodings within a single
12595 -- source program.
12597 null;
12599 --------------------
12600 -- Unknown_Pragma --
12601 --------------------
12603 -- Should be impossible, since the case of an unknown pragma is
12604 -- separately processed before the case statement is entered.
12606 when Unknown_Pragma =>
12607 raise Program_Error;
12608 end case;
12610 -- AI05-0144: detect dangerous order dependence. Disabled for now,
12611 -- until AI is formally approved.
12613 -- Check_Order_Dependence;
12615 exception
12616 when Pragma_Exit => null;
12617 end Analyze_Pragma;
12619 -------------------
12620 -- Check_Enabled --
12621 -------------------
12623 function Check_Enabled (Nam : Name_Id) return Boolean is
12624 PP : Node_Id;
12626 begin
12627 PP := Opt.Check_Policy_List;
12628 loop
12629 if No (PP) then
12630 return Assertions_Enabled;
12632 elsif
12633 Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
12634 then
12635 case
12636 Chars (Expression (Last (Pragma_Argument_Associations (PP))))
12638 when Name_On | Name_Check =>
12639 return True;
12640 when Name_Off | Name_Ignore =>
12641 return False;
12642 when others =>
12643 raise Program_Error;
12644 end case;
12646 else
12647 PP := Next_Pragma (PP);
12648 end if;
12649 end loop;
12650 end Check_Enabled;
12652 ---------------------------------
12653 -- Delay_Config_Pragma_Analyze --
12654 ---------------------------------
12656 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
12657 begin
12658 return Pragma_Name (N) = Name_Interrupt_State
12659 or else
12660 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
12661 end Delay_Config_Pragma_Analyze;
12663 -------------------------
12664 -- Get_Base_Subprogram --
12665 -------------------------
12667 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
12668 Result : Entity_Id;
12670 begin
12671 -- Follow subprogram renaming chain
12673 Result := Def_Id;
12674 while Is_Subprogram (Result)
12675 and then
12676 (Is_Generic_Instance (Result)
12677 or else Nkind (Parent (Declaration_Node (Result))) =
12678 N_Subprogram_Renaming_Declaration)
12679 and then Present (Alias (Result))
12680 loop
12681 Result := Alias (Result);
12682 end loop;
12684 return Result;
12685 end Get_Base_Subprogram;
12687 --------------------
12688 -- Get_Pragma_Arg --
12689 --------------------
12691 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
12692 begin
12693 if Nkind (Arg) = N_Pragma_Argument_Association then
12694 return Expression (Arg);
12695 else
12696 return Arg;
12697 end if;
12698 end Get_Pragma_Arg;
12700 ----------------
12701 -- Initialize --
12702 ----------------
12704 procedure Initialize is
12705 begin
12706 Externals.Init;
12707 end Initialize;
12709 -----------------------------
12710 -- Is_Config_Static_String --
12711 -----------------------------
12713 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
12715 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
12716 -- This is an internal recursive function that is just like the outer
12717 -- function except that it adds the string to the name buffer rather
12718 -- than placing the string in the name buffer.
12720 ------------------------------
12721 -- Add_Config_Static_String --
12722 ------------------------------
12724 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
12725 N : Node_Id;
12726 C : Char_Code;
12728 begin
12729 N := Arg;
12731 if Nkind (N) = N_Op_Concat then
12732 if Add_Config_Static_String (Left_Opnd (N)) then
12733 N := Right_Opnd (N);
12734 else
12735 return False;
12736 end if;
12737 end if;
12739 if Nkind (N) /= N_String_Literal then
12740 Error_Msg_N ("string literal expected for pragma argument", N);
12741 return False;
12743 else
12744 for J in 1 .. String_Length (Strval (N)) loop
12745 C := Get_String_Char (Strval (N), J);
12747 if not In_Character_Range (C) then
12748 Error_Msg
12749 ("string literal contains invalid wide character",
12750 Sloc (N) + 1 + Source_Ptr (J));
12751 return False;
12752 end if;
12754 Add_Char_To_Name_Buffer (Get_Character (C));
12755 end loop;
12756 end if;
12758 return True;
12759 end Add_Config_Static_String;
12761 -- Start of processing for Is_Config_Static_String
12763 begin
12765 Name_Len := 0;
12766 return Add_Config_Static_String (Arg);
12767 end Is_Config_Static_String;
12769 -----------------------------------------
12770 -- Is_Non_Significant_Pragma_Reference --
12771 -----------------------------------------
12773 -- This function makes use of the following static table which indicates
12774 -- whether a given pragma is significant.
12776 -- -1 indicates that references in any argument position are significant
12777 -- 0 indicates that appearence in any argument is not significant
12778 -- +n indicates that appearence as argument n is significant, but all
12779 -- other arguments are not significant
12780 -- 99 special processing required (e.g. for pragma Check)
12782 Sig_Flags : constant array (Pragma_Id) of Int :=
12783 (Pragma_AST_Entry => -1,
12784 Pragma_Abort_Defer => -1,
12785 Pragma_Ada_83 => -1,
12786 Pragma_Ada_95 => -1,
12787 Pragma_Ada_05 => -1,
12788 Pragma_Ada_2005 => -1,
12789 Pragma_Ada_12 => -1,
12790 Pragma_Ada_2012 => -1,
12791 Pragma_All_Calls_Remote => -1,
12792 Pragma_Annotate => -1,
12793 Pragma_Assert => -1,
12794 Pragma_Assertion_Policy => 0,
12795 Pragma_Assume_No_Invalid_Values => 0,
12796 Pragma_Asynchronous => -1,
12797 Pragma_Atomic => 0,
12798 Pragma_Atomic_Components => 0,
12799 Pragma_Attach_Handler => -1,
12800 Pragma_Check => 99,
12801 Pragma_Check_Name => 0,
12802 Pragma_Check_Policy => 0,
12803 Pragma_CIL_Constructor => -1,
12804 Pragma_CPP_Class => 0,
12805 Pragma_CPP_Constructor => 0,
12806 Pragma_CPP_Virtual => 0,
12807 Pragma_CPP_Vtable => 0,
12808 Pragma_C_Pass_By_Copy => 0,
12809 Pragma_Comment => 0,
12810 Pragma_Common_Object => -1,
12811 Pragma_Compile_Time_Error => -1,
12812 Pragma_Compile_Time_Warning => -1,
12813 Pragma_Compiler_Unit => 0,
12814 Pragma_Complete_Representation => 0,
12815 Pragma_Complex_Representation => 0,
12816 Pragma_Component_Alignment => -1,
12817 Pragma_Controlled => 0,
12818 Pragma_Convention => 0,
12819 Pragma_Convention_Identifier => 0,
12820 Pragma_Debug => -1,
12821 Pragma_Debug_Policy => 0,
12822 Pragma_Detect_Blocking => -1,
12823 Pragma_Dimension => -1,
12824 Pragma_Discard_Names => 0,
12825 Pragma_Elaborate => -1,
12826 Pragma_Elaborate_All => -1,
12827 Pragma_Elaborate_Body => -1,
12828 Pragma_Elaboration_Checks => -1,
12829 Pragma_Eliminate => -1,
12830 Pragma_Export => -1,
12831 Pragma_Export_Exception => -1,
12832 Pragma_Export_Function => -1,
12833 Pragma_Export_Object => -1,
12834 Pragma_Export_Procedure => -1,
12835 Pragma_Export_Value => -1,
12836 Pragma_Export_Valued_Procedure => -1,
12837 Pragma_Extend_System => -1,
12838 Pragma_Extensions_Allowed => -1,
12839 Pragma_External => -1,
12840 Pragma_Favor_Top_Level => -1,
12841 Pragma_External_Name_Casing => -1,
12842 Pragma_Fast_Math => -1,
12843 Pragma_Finalize_Storage_Only => 0,
12844 Pragma_Float_Representation => 0,
12845 Pragma_Ident => -1,
12846 Pragma_Implemented_By_Entry => -1,
12847 Pragma_Implicit_Packing => 0,
12848 Pragma_Import => +2,
12849 Pragma_Import_Exception => 0,
12850 Pragma_Import_Function => 0,
12851 Pragma_Import_Object => 0,
12852 Pragma_Import_Procedure => 0,
12853 Pragma_Import_Valued_Procedure => 0,
12854 Pragma_Initialize_Scalars => -1,
12855 Pragma_Inline => 0,
12856 Pragma_Inline_Always => 0,
12857 Pragma_Inline_Generic => 0,
12858 Pragma_Inspection_Point => -1,
12859 Pragma_Interface => +2,
12860 Pragma_Interface_Name => +2,
12861 Pragma_Interrupt_Handler => -1,
12862 Pragma_Interrupt_Priority => -1,
12863 Pragma_Interrupt_State => -1,
12864 Pragma_Java_Constructor => -1,
12865 Pragma_Java_Interface => -1,
12866 Pragma_Keep_Names => 0,
12867 Pragma_License => -1,
12868 Pragma_Link_With => -1,
12869 Pragma_Linker_Alias => -1,
12870 Pragma_Linker_Constructor => -1,
12871 Pragma_Linker_Destructor => -1,
12872 Pragma_Linker_Options => -1,
12873 Pragma_Linker_Section => -1,
12874 Pragma_List => -1,
12875 Pragma_Locking_Policy => -1,
12876 Pragma_Long_Float => -1,
12877 Pragma_Machine_Attribute => -1,
12878 Pragma_Main => -1,
12879 Pragma_Main_Storage => -1,
12880 Pragma_Memory_Size => -1,
12881 Pragma_No_Return => 0,
12882 Pragma_No_Body => 0,
12883 Pragma_No_Run_Time => -1,
12884 Pragma_No_Strict_Aliasing => -1,
12885 Pragma_Normalize_Scalars => -1,
12886 Pragma_Obsolescent => 0,
12887 Pragma_Optimize => -1,
12888 Pragma_Optimize_Alignment => -1,
12889 Pragma_Ordered => 0,
12890 Pragma_Pack => 0,
12891 Pragma_Page => -1,
12892 Pragma_Passive => -1,
12893 Pragma_Preelaborable_Initialization => -1,
12894 Pragma_Polling => -1,
12895 Pragma_Persistent_BSS => 0,
12896 Pragma_Postcondition => -1,
12897 Pragma_Precondition => -1,
12898 Pragma_Preelaborate => -1,
12899 Pragma_Preelaborate_05 => -1,
12900 Pragma_Priority => -1,
12901 Pragma_Priority_Specific_Dispatching => -1,
12902 Pragma_Profile => 0,
12903 Pragma_Profile_Warnings => 0,
12904 Pragma_Propagate_Exceptions => -1,
12905 Pragma_Psect_Object => -1,
12906 Pragma_Pure => -1,
12907 Pragma_Pure_05 => -1,
12908 Pragma_Pure_Function => -1,
12909 Pragma_Queuing_Policy => -1,
12910 Pragma_Ravenscar => -1,
12911 Pragma_Relative_Deadline => -1,
12912 Pragma_Remote_Call_Interface => -1,
12913 Pragma_Remote_Types => -1,
12914 Pragma_Restricted_Run_Time => -1,
12915 Pragma_Restriction_Warnings => -1,
12916 Pragma_Restrictions => -1,
12917 Pragma_Reviewable => -1,
12918 Pragma_Short_Circuit_And_Or => -1,
12919 Pragma_Share_Generic => -1,
12920 Pragma_Shared => -1,
12921 Pragma_Shared_Passive => -1,
12922 Pragma_Short_Descriptors => 0,
12923 Pragma_Source_File_Name => -1,
12924 Pragma_Source_File_Name_Project => -1,
12925 Pragma_Source_Reference => -1,
12926 Pragma_Storage_Size => -1,
12927 Pragma_Storage_Unit => -1,
12928 Pragma_Static_Elaboration_Desired => -1,
12929 Pragma_Stream_Convert => -1,
12930 Pragma_Style_Checks => -1,
12931 Pragma_Subtitle => -1,
12932 Pragma_Suppress => 0,
12933 Pragma_Suppress_Exception_Locations => 0,
12934 Pragma_Suppress_All => -1,
12935 Pragma_Suppress_Debug_Info => 0,
12936 Pragma_Suppress_Initialization => 0,
12937 Pragma_System_Name => -1,
12938 Pragma_Task_Dispatching_Policy => -1,
12939 Pragma_Task_Info => -1,
12940 Pragma_Task_Name => -1,
12941 Pragma_Task_Storage => 0,
12942 Pragma_Thread_Local_Storage => 0,
12943 Pragma_Time_Slice => -1,
12944 Pragma_Title => -1,
12945 Pragma_Unchecked_Union => 0,
12946 Pragma_Unimplemented_Unit => -1,
12947 Pragma_Universal_Aliasing => -1,
12948 Pragma_Universal_Data => -1,
12949 Pragma_Unmodified => -1,
12950 Pragma_Unreferenced => -1,
12951 Pragma_Unreferenced_Objects => -1,
12952 Pragma_Unreserve_All_Interrupts => -1,
12953 Pragma_Unsuppress => 0,
12954 Pragma_Use_VADS_Size => -1,
12955 Pragma_Validity_Checks => -1,
12956 Pragma_Volatile => 0,
12957 Pragma_Volatile_Components => 0,
12958 Pragma_Warnings => -1,
12959 Pragma_Weak_External => -1,
12960 Pragma_Wide_Character_Encoding => 0,
12961 Unknown_Pragma => 0);
12963 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
12964 Id : Pragma_Id;
12965 P : Node_Id;
12966 C : Int;
12967 A : Node_Id;
12969 begin
12970 P := Parent (N);
12972 if Nkind (P) /= N_Pragma_Argument_Association then
12973 return False;
12975 else
12976 Id := Get_Pragma_Id (Parent (P));
12977 C := Sig_Flags (Id);
12979 case C is
12980 when -1 =>
12981 return False;
12983 when 0 =>
12984 return True;
12986 when 99 =>
12987 case Id is
12989 -- For pragma Check, the first argument is not significant,
12990 -- the second and the third (if present) arguments are
12991 -- significant.
12993 when Pragma_Check =>
12994 return
12995 P = First (Pragma_Argument_Associations (Parent (P)));
12997 when others =>
12998 raise Program_Error;
12999 end case;
13001 when others =>
13002 A := First (Pragma_Argument_Associations (Parent (P)));
13003 for J in 1 .. C - 1 loop
13004 if No (A) then
13005 return False;
13006 end if;
13008 Next (A);
13009 end loop;
13011 return A = P; -- is this wrong way round ???
13012 end case;
13013 end if;
13014 end Is_Non_Significant_Pragma_Reference;
13016 ------------------------------
13017 -- Is_Pragma_String_Literal --
13018 ------------------------------
13020 -- This function returns true if the corresponding pragma argument is a
13021 -- static string expression. These are the only cases in which string
13022 -- literals can appear as pragma arguments. We also allow a string literal
13023 -- as the first argument to pragma Assert (although it will of course
13024 -- always generate a type error).
13026 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
13027 Pragn : constant Node_Id := Parent (Par);
13028 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
13029 Pname : constant Name_Id := Pragma_Name (Pragn);
13030 Argn : Natural;
13031 N : Node_Id;
13033 begin
13034 Argn := 1;
13035 N := First (Assoc);
13036 loop
13037 exit when N = Par;
13038 Argn := Argn + 1;
13039 Next (N);
13040 end loop;
13042 if Pname = Name_Assert then
13043 return True;
13045 elsif Pname = Name_Export then
13046 return Argn > 2;
13048 elsif Pname = Name_Ident then
13049 return Argn = 1;
13051 elsif Pname = Name_Import then
13052 return Argn > 2;
13054 elsif Pname = Name_Interface_Name then
13055 return Argn > 1;
13057 elsif Pname = Name_Linker_Alias then
13058 return Argn = 2;
13060 elsif Pname = Name_Linker_Section then
13061 return Argn = 2;
13063 elsif Pname = Name_Machine_Attribute then
13064 return Argn = 2;
13066 elsif Pname = Name_Source_File_Name then
13067 return True;
13069 elsif Pname = Name_Source_Reference then
13070 return Argn = 2;
13072 elsif Pname = Name_Title then
13073 return True;
13075 elsif Pname = Name_Subtitle then
13076 return True;
13078 else
13079 return False;
13080 end if;
13081 end Is_Pragma_String_Literal;
13083 --------------------------------------
13084 -- Process_Compilation_Unit_Pragmas --
13085 --------------------------------------
13087 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
13088 begin
13089 -- A special check for pragma Suppress_All, a very strange DEC pragma,
13090 -- strange because it comes at the end of the unit. If we have a pragma
13091 -- Suppress_All in the Pragmas_After of the current unit, then we insert
13092 -- a pragma Suppress (All_Checks) at the start of the context clause to
13093 -- ensure the correct processing.
13095 declare
13096 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
13097 P : Node_Id;
13099 begin
13100 if Present (PA) then
13101 P := First (PA);
13102 while Present (P) loop
13103 if Pragma_Name (P) = Name_Suppress_All then
13104 Prepend_To (Context_Items (N),
13105 Make_Pragma (Sloc (P),
13106 Chars => Name_Suppress,
13107 Pragma_Argument_Associations => New_List (
13108 Make_Pragma_Argument_Association (Sloc (P),
13109 Expression =>
13110 Make_Identifier (Sloc (P),
13111 Chars => Name_All_Checks)))));
13112 exit;
13113 end if;
13115 Next (P);
13116 end loop;
13117 end if;
13118 end;
13119 end Process_Compilation_Unit_Pragmas;
13121 --------
13122 -- rv --
13123 --------
13125 procedure rv is
13126 begin
13127 null;
13128 end rv;
13130 --------------------------------
13131 -- Set_Encoded_Interface_Name --
13132 --------------------------------
13134 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
13135 Str : constant String_Id := Strval (S);
13136 Len : constant Int := String_Length (Str);
13137 CC : Char_Code;
13138 C : Character;
13139 J : Int;
13141 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
13143 procedure Encode;
13144 -- Stores encoded value of character code CC. The encoding we use an
13145 -- underscore followed by four lower case hex digits.
13147 ------------
13148 -- Encode --
13149 ------------
13151 procedure Encode is
13152 begin
13153 Store_String_Char (Get_Char_Code ('_'));
13154 Store_String_Char
13155 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
13156 Store_String_Char
13157 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
13158 Store_String_Char
13159 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
13160 Store_String_Char
13161 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
13162 end Encode;
13164 -- Start of processing for Set_Encoded_Interface_Name
13166 begin
13167 -- If first character is asterisk, this is a link name, and we leave it
13168 -- completely unmodified. We also ignore null strings (the latter case
13169 -- happens only in error cases) and no encoding should occur for Java or
13170 -- AAMP interface names.
13172 if Len = 0
13173 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
13174 or else VM_Target /= No_VM
13175 or else AAMP_On_Target
13176 then
13177 Set_Interface_Name (E, S);
13179 else
13180 J := 1;
13181 loop
13182 CC := Get_String_Char (Str, J);
13184 exit when not In_Character_Range (CC);
13186 C := Get_Character (CC);
13188 exit when C /= '_' and then C /= '$'
13189 and then C not in '0' .. '9'
13190 and then C not in 'a' .. 'z'
13191 and then C not in 'A' .. 'Z';
13193 if J = Len then
13194 Set_Interface_Name (E, S);
13195 return;
13197 else
13198 J := J + 1;
13199 end if;
13200 end loop;
13202 -- Here we need to encode. The encoding we use as follows:
13203 -- three underscores + four hex digits (lower case)
13205 Start_String;
13207 for J in 1 .. String_Length (Str) loop
13208 CC := Get_String_Char (Str, J);
13210 if not In_Character_Range (CC) then
13211 Encode;
13212 else
13213 C := Get_Character (CC);
13215 if C = '_' or else C = '$'
13216 or else C in '0' .. '9'
13217 or else C in 'a' .. 'z'
13218 or else C in 'A' .. 'Z'
13219 then
13220 Store_String_Char (CC);
13221 else
13222 Encode;
13223 end if;
13224 end if;
13225 end loop;
13227 Set_Interface_Name (E,
13228 Make_String_Literal (Sloc (S),
13229 Strval => End_String));
13230 end if;
13231 end Set_Encoded_Interface_Name;
13233 -------------------
13234 -- Set_Unit_Name --
13235 -------------------
13237 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
13238 Pref : Node_Id;
13239 Scop : Entity_Id;
13241 begin
13242 if Nkind (N) = N_Identifier
13243 and then Nkind (With_Item) = N_Identifier
13244 then
13245 Set_Entity (N, Entity (With_Item));
13247 elsif Nkind (N) = N_Selected_Component then
13248 Change_Selected_Component_To_Expanded_Name (N);
13249 Set_Entity (N, Entity (With_Item));
13250 Set_Entity (Selector_Name (N), Entity (N));
13252 Pref := Prefix (N);
13253 Scop := Scope (Entity (N));
13254 while Nkind (Pref) = N_Selected_Component loop
13255 Change_Selected_Component_To_Expanded_Name (Pref);
13256 Set_Entity (Selector_Name (Pref), Scop);
13257 Set_Entity (Pref, Scop);
13258 Pref := Prefix (Pref);
13259 Scop := Scope (Scop);
13260 end loop;
13262 Set_Entity (Pref, Scop);
13263 end if;
13264 end Set_Unit_Name;
13266 end Sem_Prag;