Merged trunk at revision 161680 into branch.
[official-gcc.git] / gcc / ada / sem_prag.adb
blobe5afd0cebb8452dd4da6782cc7629a14b2eda795
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 -- A very special case that must be processed here: pragma
4434 -- Restrictions (No_Exceptions) turns off all run-time
4435 -- checking. This is a bit dubious in terms of the formal
4436 -- language definition, but it is what is intended by RM
4437 -- H.4(12). Restriction_Warnings never affects generated code
4438 -- so this is done only in the real restriction case.
4440 if R_Id = No_Exceptions and then not Warn then
4441 Scope_Suppress := (others => True);
4442 end if;
4444 -- Case of No_Dependence => unit-name. Note that the parser
4445 -- already made the necessary entry in the No_Dependence table.
4447 elsif Id = Name_No_Dependence then
4448 Check_Unit_Name (Expr);
4450 -- All other cases of restriction identifier present
4452 else
4453 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4454 Analyze_And_Resolve (Expr, Any_Integer);
4456 if R_Id not in All_Parameter_Restrictions then
4457 Error_Pragma_Arg
4458 ("invalid restriction parameter identifier", Arg);
4460 elsif not Is_OK_Static_Expression (Expr) then
4461 Flag_Non_Static_Expr
4462 ("value must be static expression!", Expr);
4463 raise Pragma_Exit;
4465 elsif not Is_Integer_Type (Etype (Expr))
4466 or else Expr_Value (Expr) < 0
4467 then
4468 Error_Pragma_Arg
4469 ("value must be non-negative integer", Arg);
4470 end if;
4472 -- Restriction pragma is active
4474 Val := Expr_Value (Expr);
4476 if not UI_Is_In_Int_Range (Val) then
4477 Error_Pragma_Arg
4478 ("pragma ignored, value too large?", Arg);
4479 end if;
4481 -- Warning case. If the real restriction is active, then we
4482 -- ignore the request, since warning never overrides a real
4483 -- restriction. Otherwise we set the proper warning. Note that
4484 -- this circuit sets the warning again if it is already set,
4485 -- which is what we want, since the constant may have changed.
4487 if Warn then
4488 if not Restriction_Active (R_Id) then
4489 Set_Restriction
4490 (R_Id, N, Integer (UI_To_Int (Val)));
4491 Restriction_Warnings (R_Id) := True;
4492 end if;
4494 -- Real restriction case, set restriction and make sure warning
4495 -- flag is off since real restriction always overrides warning.
4497 else
4498 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4499 Restriction_Warnings (R_Id) := False;
4500 end if;
4501 end if;
4503 Next (Arg);
4504 end loop;
4505 end Process_Restrictions_Or_Restriction_Warnings;
4507 ---------------------------------
4508 -- Process_Suppress_Unsuppress --
4509 ---------------------------------
4511 -- Note: this procedure makes entries in the check suppress data
4512 -- structures managed by Sem. See spec of package Sem for full
4513 -- details on how we handle recording of check suppression.
4515 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4516 C : Check_Id;
4517 E_Id : Node_Id;
4518 E : Entity_Id;
4520 In_Package_Spec : constant Boolean :=
4521 Is_Package_Or_Generic_Package (Current_Scope)
4522 and then not In_Package_Body (Current_Scope);
4524 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4525 -- Used to suppress a single check on the given entity
4527 --------------------------------
4528 -- Suppress_Unsuppress_Echeck --
4529 --------------------------------
4531 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4532 begin
4533 Set_Checks_May_Be_Suppressed (E);
4535 if In_Package_Spec then
4536 Push_Global_Suppress_Stack_Entry
4537 (Entity => E,
4538 Check => C,
4539 Suppress => Suppress_Case);
4541 else
4542 Push_Local_Suppress_Stack_Entry
4543 (Entity => E,
4544 Check => C,
4545 Suppress => Suppress_Case);
4546 end if;
4548 -- If this is a first subtype, and the base type is distinct,
4549 -- then also set the suppress flags on the base type.
4551 if Is_First_Subtype (E)
4552 and then Etype (E) /= E
4553 then
4554 Suppress_Unsuppress_Echeck (Etype (E), C);
4555 end if;
4556 end Suppress_Unsuppress_Echeck;
4558 -- Start of processing for Process_Suppress_Unsuppress
4560 begin
4561 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
4562 -- declarative part or a package spec (RM 11.5(5)).
4564 if not Is_Configuration_Pragma then
4565 Check_Is_In_Decl_Part_Or_Package_Spec;
4566 end if;
4568 Check_At_Least_N_Arguments (1);
4569 Check_At_Most_N_Arguments (2);
4570 Check_No_Identifier (Arg1);
4571 Check_Arg_Is_Identifier (Arg1);
4573 C := Get_Check_Id (Chars (Expression (Arg1)));
4575 if C = No_Check_Id then
4576 Error_Pragma_Arg
4577 ("argument of pragma% is not valid check name", Arg1);
4578 end if;
4580 if not Suppress_Case
4581 and then (C = All_Checks or else C = Overflow_Check)
4582 then
4583 Opt.Overflow_Checks_Unsuppressed := True;
4584 end if;
4586 if Arg_Count = 1 then
4588 -- Make an entry in the local scope suppress table. This is the
4589 -- table that directly shows the current value of the scope
4590 -- suppress check for any check id value.
4592 if C = All_Checks then
4594 -- For All_Checks, we set all specific predefined checks with
4595 -- the exception of Elaboration_Check, which is handled
4596 -- specially because of not wanting All_Checks to have the
4597 -- effect of deactivating static elaboration order processing.
4599 for J in Scope_Suppress'Range loop
4600 if J /= Elaboration_Check then
4601 Scope_Suppress (J) := Suppress_Case;
4602 end if;
4603 end loop;
4605 -- If not All_Checks, and predefined check, then set appropriate
4606 -- scope entry. Note that we will set Elaboration_Check if this
4607 -- is explicitly specified.
4609 elsif C in Predefined_Check_Id then
4610 Scope_Suppress (C) := Suppress_Case;
4611 end if;
4613 -- Also make an entry in the Local_Entity_Suppress table
4615 Push_Local_Suppress_Stack_Entry
4616 (Entity => Empty,
4617 Check => C,
4618 Suppress => Suppress_Case);
4620 -- Case of two arguments present, where the check is suppressed for
4621 -- a specified entity (given as the second argument of the pragma)
4623 else
4624 Check_Optional_Identifier (Arg2, Name_On);
4625 E_Id := Expression (Arg2);
4626 Analyze (E_Id);
4628 if not Is_Entity_Name (E_Id) then
4629 Error_Pragma_Arg
4630 ("second argument of pragma% must be entity name", Arg2);
4631 end if;
4633 E := Entity (E_Id);
4635 if E = Any_Id then
4636 return;
4637 end if;
4639 -- Enforce RM 11.5(7) which requires that for a pragma that
4640 -- appears within a package spec, the named entity must be
4641 -- within the package spec. We allow the package name itself
4642 -- to be mentioned since that makes sense, although it is not
4643 -- strictly allowed by 11.5(7).
4645 if In_Package_Spec
4646 and then E /= Current_Scope
4647 and then Scope (E) /= Current_Scope
4648 then
4649 Error_Pragma_Arg
4650 ("entity in pragma% is not in package spec (RM 11.5(7))",
4651 Arg2);
4652 end if;
4654 -- Loop through homonyms. As noted below, in the case of a package
4655 -- spec, only homonyms within the package spec are considered.
4657 loop
4658 Suppress_Unsuppress_Echeck (E, C);
4660 if Is_Generic_Instance (E)
4661 and then Is_Subprogram (E)
4662 and then Present (Alias (E))
4663 then
4664 Suppress_Unsuppress_Echeck (Alias (E), C);
4665 end if;
4667 -- Move to next homonym
4669 E := Homonym (E);
4670 exit when No (E);
4672 -- If we are within a package specification, the pragma only
4673 -- applies to homonyms in the same scope.
4675 exit when In_Package_Spec
4676 and then Scope (E) /= Current_Scope;
4677 end loop;
4678 end if;
4679 end Process_Suppress_Unsuppress;
4681 ------------------
4682 -- Set_Exported --
4683 ------------------
4685 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
4686 begin
4687 if Is_Imported (E) then
4688 Error_Pragma_Arg
4689 ("cannot export entity& that was previously imported", Arg);
4691 elsif Present (Address_Clause (E)) then
4692 Error_Pragma_Arg
4693 ("cannot export entity& that has an address clause", Arg);
4694 end if;
4696 Set_Is_Exported (E);
4698 -- Generate a reference for entity explicitly, because the
4699 -- identifier may be overloaded and name resolution will not
4700 -- generate one.
4702 Generate_Reference (E, Arg);
4704 -- Deal with exporting non-library level entity
4706 if not Is_Library_Level_Entity (E) then
4708 -- Not allowed at all for subprograms
4710 if Is_Subprogram (E) then
4711 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
4713 -- Otherwise set public and statically allocated
4715 else
4716 Set_Is_Public (E);
4717 Set_Is_Statically_Allocated (E);
4719 -- Warn if the corresponding W flag is set and the pragma comes
4720 -- from source. The latter may not be true e.g. on VMS where we
4721 -- expand export pragmas for exception codes associated with
4722 -- imported or exported exceptions. We do not want to generate
4723 -- a warning for something that the user did not write.
4725 if Warn_On_Export_Import
4726 and then Comes_From_Source (Arg)
4727 then
4728 Error_Msg_NE
4729 ("?& has been made static as a result of Export", Arg, E);
4730 Error_Msg_N
4731 ("\this usage is non-standard and non-portable", Arg);
4732 end if;
4733 end if;
4734 end if;
4736 if Warn_On_Export_Import and then Is_Type (E) then
4737 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
4738 end if;
4740 if Warn_On_Export_Import and Inside_A_Generic then
4741 Error_Msg_NE
4742 ("all instances of& will have the same external name?", Arg, E);
4743 end if;
4744 end Set_Exported;
4746 ----------------------------------------------
4747 -- Set_Extended_Import_Export_External_Name --
4748 ----------------------------------------------
4750 procedure Set_Extended_Import_Export_External_Name
4751 (Internal_Ent : Entity_Id;
4752 Arg_External : Node_Id)
4754 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
4755 New_Name : Node_Id;
4757 begin
4758 if No (Arg_External) then
4759 return;
4760 end if;
4762 Check_Arg_Is_External_Name (Arg_External);
4764 if Nkind (Arg_External) = N_String_Literal then
4765 if String_Length (Strval (Arg_External)) = 0 then
4766 return;
4767 else
4768 New_Name := Adjust_External_Name_Case (Arg_External);
4769 end if;
4771 elsif Nkind (Arg_External) = N_Identifier then
4772 New_Name := Get_Default_External_Name (Arg_External);
4774 -- Check_Arg_Is_External_Name should let through only identifiers and
4775 -- string literals or static string expressions (which are folded to
4776 -- string literals).
4778 else
4779 raise Program_Error;
4780 end if;
4782 -- If we already have an external name set (by a prior normal Import
4783 -- or Export pragma), then the external names must match
4785 if Present (Interface_Name (Internal_Ent)) then
4786 Check_Matching_Internal_Names : declare
4787 S1 : constant String_Id := Strval (Old_Name);
4788 S2 : constant String_Id := Strval (New_Name);
4790 procedure Mismatch;
4791 -- Called if names do not match
4793 --------------
4794 -- Mismatch --
4795 --------------
4797 procedure Mismatch is
4798 begin
4799 Error_Msg_Sloc := Sloc (Old_Name);
4800 Error_Pragma_Arg
4801 ("external name does not match that given #",
4802 Arg_External);
4803 end Mismatch;
4805 -- Start of processing for Check_Matching_Internal_Names
4807 begin
4808 if String_Length (S1) /= String_Length (S2) then
4809 Mismatch;
4811 else
4812 for J in 1 .. String_Length (S1) loop
4813 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4814 Mismatch;
4815 end if;
4816 end loop;
4817 end if;
4818 end Check_Matching_Internal_Names;
4820 -- Otherwise set the given name
4822 else
4823 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4824 Check_Duplicated_Export_Name (New_Name);
4825 end if;
4826 end Set_Extended_Import_Export_External_Name;
4828 ------------------
4829 -- Set_Imported --
4830 ------------------
4832 procedure Set_Imported (E : Entity_Id) is
4833 begin
4834 -- Error message if already imported or exported
4836 if Is_Exported (E) or else Is_Imported (E) then
4838 -- Error if being set Exported twice
4840 if Is_Exported (E) then
4841 Error_Msg_NE ("entity& was previously exported", N, E);
4843 -- OK if Import/Interface case
4845 elsif Import_Interface_Present (N) then
4846 goto OK;
4848 -- Error if being set Imported twice
4850 else
4851 Error_Msg_NE ("entity& was previously imported", N, E);
4852 end if;
4854 Error_Msg_Name_1 := Pname;
4855 Error_Msg_N
4856 ("\(pragma% applies to all previous entities)", N);
4858 Error_Msg_Sloc := Sloc (E);
4859 Error_Msg_NE ("\import not allowed for& declared#", N, E);
4861 -- Here if not previously imported or exported, OK to import
4863 else
4864 Set_Is_Imported (E);
4866 -- If the entity is an object that is not at the library level,
4867 -- then it is statically allocated. We do not worry about objects
4868 -- with address clauses in this context since they are not really
4869 -- imported in the linker sense.
4871 if Is_Object (E)
4872 and then not Is_Library_Level_Entity (E)
4873 and then No (Address_Clause (E))
4874 then
4875 Set_Is_Statically_Allocated (E);
4876 end if;
4877 end if;
4879 <<OK>> null;
4880 end Set_Imported;
4882 -------------------------
4883 -- Set_Mechanism_Value --
4884 -------------------------
4886 -- Note: the mechanism name has not been analyzed (and cannot indeed be
4887 -- analyzed, since it is semantic nonsense), so we get it in the exact
4888 -- form created by the parser.
4890 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4891 Class : Node_Id;
4892 Param : Node_Id;
4893 Mech_Name_Id : Name_Id;
4895 procedure Bad_Class;
4896 -- Signal bad descriptor class name
4898 procedure Bad_Mechanism;
4899 -- Signal bad mechanism name
4901 ---------------
4902 -- Bad_Class --
4903 ---------------
4905 procedure Bad_Class is
4906 begin
4907 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4908 end Bad_Class;
4910 -------------------------
4911 -- Bad_Mechanism_Value --
4912 -------------------------
4914 procedure Bad_Mechanism is
4915 begin
4916 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4917 end Bad_Mechanism;
4919 -- Start of processing for Set_Mechanism_Value
4921 begin
4922 if Mechanism (Ent) /= Default_Mechanism then
4923 Error_Msg_NE
4924 ("mechanism for & has already been set", Mech_Name, Ent);
4925 end if;
4927 -- MECHANISM_NAME ::= value | reference | descriptor |
4928 -- short_descriptor
4930 if Nkind (Mech_Name) = N_Identifier then
4931 if Chars (Mech_Name) = Name_Value then
4932 Set_Mechanism (Ent, By_Copy);
4933 return;
4935 elsif Chars (Mech_Name) = Name_Reference then
4936 Set_Mechanism (Ent, By_Reference);
4937 return;
4939 elsif Chars (Mech_Name) = Name_Descriptor then
4940 Check_VMS (Mech_Name);
4941 Set_Mechanism (Ent, By_Descriptor);
4942 return;
4944 elsif Chars (Mech_Name) = Name_Short_Descriptor then
4945 Check_VMS (Mech_Name);
4946 Set_Mechanism (Ent, By_Short_Descriptor);
4947 return;
4949 elsif Chars (Mech_Name) = Name_Copy then
4950 Error_Pragma_Arg
4951 ("bad mechanism name, Value assumed", Mech_Name);
4953 else
4954 Bad_Mechanism;
4955 end if;
4957 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
4958 -- short_descriptor (CLASS_NAME)
4959 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4961 -- Note: this form is parsed as an indexed component
4963 elsif Nkind (Mech_Name) = N_Indexed_Component then
4965 Class := First (Expressions (Mech_Name));
4967 if Nkind (Prefix (Mech_Name)) /= N_Identifier
4968 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
4969 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
4970 or else Present (Next (Class))
4971 then
4972 Bad_Mechanism;
4973 else
4974 Mech_Name_Id := Chars (Prefix (Mech_Name));
4975 end if;
4977 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
4978 -- short_descriptor (Class => CLASS_NAME)
4979 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4981 -- Note: this form is parsed as a function call
4983 elsif Nkind (Mech_Name) = N_Function_Call then
4985 Param := First (Parameter_Associations (Mech_Name));
4987 if Nkind (Name (Mech_Name)) /= N_Identifier
4988 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
4989 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
4990 or else Present (Next (Param))
4991 or else No (Selector_Name (Param))
4992 or else Chars (Selector_Name (Param)) /= Name_Class
4993 then
4994 Bad_Mechanism;
4995 else
4996 Class := Explicit_Actual_Parameter (Param);
4997 Mech_Name_Id := Chars (Name (Mech_Name));
4998 end if;
5000 else
5001 Bad_Mechanism;
5002 end if;
5004 -- Fall through here with Class set to descriptor class name
5006 Check_VMS (Mech_Name);
5008 if Nkind (Class) /= N_Identifier then
5009 Bad_Class;
5011 elsif Mech_Name_Id = Name_Descriptor
5012 and then Chars (Class) = Name_UBS
5013 then
5014 Set_Mechanism (Ent, By_Descriptor_UBS);
5016 elsif Mech_Name_Id = Name_Descriptor
5017 and then Chars (Class) = Name_UBSB
5018 then
5019 Set_Mechanism (Ent, By_Descriptor_UBSB);
5021 elsif Mech_Name_Id = Name_Descriptor
5022 and then Chars (Class) = Name_UBA
5023 then
5024 Set_Mechanism (Ent, By_Descriptor_UBA);
5026 elsif Mech_Name_Id = Name_Descriptor
5027 and then Chars (Class) = Name_S
5028 then
5029 Set_Mechanism (Ent, By_Descriptor_S);
5031 elsif Mech_Name_Id = Name_Descriptor
5032 and then Chars (Class) = Name_SB
5033 then
5034 Set_Mechanism (Ent, By_Descriptor_SB);
5036 elsif Mech_Name_Id = Name_Descriptor
5037 and then Chars (Class) = Name_A
5038 then
5039 Set_Mechanism (Ent, By_Descriptor_A);
5041 elsif Mech_Name_Id = Name_Descriptor
5042 and then Chars (Class) = Name_NCA
5043 then
5044 Set_Mechanism (Ent, By_Descriptor_NCA);
5046 elsif Mech_Name_Id = Name_Short_Descriptor
5047 and then Chars (Class) = Name_UBS
5048 then
5049 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5051 elsif Mech_Name_Id = Name_Short_Descriptor
5052 and then Chars (Class) = Name_UBSB
5053 then
5054 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5056 elsif Mech_Name_Id = Name_Short_Descriptor
5057 and then Chars (Class) = Name_UBA
5058 then
5059 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5061 elsif Mech_Name_Id = Name_Short_Descriptor
5062 and then Chars (Class) = Name_S
5063 then
5064 Set_Mechanism (Ent, By_Short_Descriptor_S);
5066 elsif Mech_Name_Id = Name_Short_Descriptor
5067 and then Chars (Class) = Name_SB
5068 then
5069 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5071 elsif Mech_Name_Id = Name_Short_Descriptor
5072 and then Chars (Class) = Name_A
5073 then
5074 Set_Mechanism (Ent, By_Short_Descriptor_A);
5076 elsif Mech_Name_Id = Name_Short_Descriptor
5077 and then Chars (Class) = Name_NCA
5078 then
5079 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5081 else
5082 Bad_Class;
5083 end if;
5084 end Set_Mechanism_Value;
5086 ---------------------------
5087 -- Set_Ravenscar_Profile --
5088 ---------------------------
5090 -- The tasks to be done here are
5092 -- Set required policies
5094 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5095 -- pragma Locking_Policy (Ceiling_Locking)
5097 -- Set Detect_Blocking mode
5099 -- Set required restrictions (see System.Rident for detailed list)
5101 procedure Set_Ravenscar_Profile (N : Node_Id) is
5102 begin
5103 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5105 if Task_Dispatching_Policy /= ' '
5106 and then Task_Dispatching_Policy /= 'F'
5107 then
5108 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5109 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5111 -- Set the FIFO_Within_Priorities policy, but always preserve
5112 -- System_Location since we like the error message with the run time
5113 -- name.
5115 else
5116 Task_Dispatching_Policy := 'F';
5118 if Task_Dispatching_Policy_Sloc /= System_Location then
5119 Task_Dispatching_Policy_Sloc := Loc;
5120 end if;
5121 end if;
5123 -- pragma Locking_Policy (Ceiling_Locking)
5125 if Locking_Policy /= ' '
5126 and then Locking_Policy /= 'C'
5127 then
5128 Error_Msg_Sloc := Locking_Policy_Sloc;
5129 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5131 -- Set the Ceiling_Locking policy, but preserve System_Location since
5132 -- we like the error message with the run time name.
5134 else
5135 Locking_Policy := 'C';
5137 if Locking_Policy_Sloc /= System_Location then
5138 Locking_Policy_Sloc := Loc;
5139 end if;
5140 end if;
5142 -- pragma Detect_Blocking
5144 Detect_Blocking := True;
5146 -- Set the corresponding restrictions
5148 Set_Profile_Restrictions
5149 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5150 end Set_Ravenscar_Profile;
5152 -- Start of processing for Analyze_Pragma
5154 begin
5155 -- Deal with unrecognized pragma
5157 if not Is_Pragma_Name (Pname) then
5158 if Warn_On_Unrecognized_Pragma then
5159 Error_Msg_Name_1 := Pname;
5160 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5162 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5163 if Is_Bad_Spelling_Of (Pname, PN) then
5164 Error_Msg_Name_1 := PN;
5165 Error_Msg_N -- CODEFIX
5166 ("\?possible misspelling of %!", Pragma_Identifier (N));
5167 exit;
5168 end if;
5169 end loop;
5170 end if;
5172 return;
5173 end if;
5175 -- Here to start processing for recognized pragma
5177 Prag_Id := Get_Pragma_Id (Pname);
5179 -- Preset arguments
5181 Arg1 := Empty;
5182 Arg2 := Empty;
5183 Arg3 := Empty;
5184 Arg4 := Empty;
5186 if Present (Pragma_Argument_Associations (N)) then
5187 Arg1 := First (Pragma_Argument_Associations (N));
5189 if Present (Arg1) then
5190 Arg2 := Next (Arg1);
5192 if Present (Arg2) then
5193 Arg3 := Next (Arg2);
5195 if Present (Arg3) then
5196 Arg4 := Next (Arg3);
5197 end if;
5198 end if;
5199 end if;
5200 end if;
5202 -- Count number of arguments
5204 declare
5205 Arg_Node : Node_Id;
5206 begin
5207 Arg_Count := 0;
5208 Arg_Node := Arg1;
5209 while Present (Arg_Node) loop
5210 Arg_Count := Arg_Count + 1;
5211 Next (Arg_Node);
5212 end loop;
5213 end;
5215 -- An enumeration type defines the pragmas that are supported by the
5216 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5217 -- into the corresponding enumeration value for the following case.
5219 case Prag_Id is
5221 -----------------
5222 -- Abort_Defer --
5223 -----------------
5225 -- pragma Abort_Defer;
5227 when Pragma_Abort_Defer =>
5228 GNAT_Pragma;
5229 Check_Arg_Count (0);
5231 -- The only required semantic processing is to check the
5232 -- placement. This pragma must appear at the start of the
5233 -- statement sequence of a handled sequence of statements.
5235 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5236 or else N /= First (Statements (Parent (N)))
5237 then
5238 Pragma_Misplaced;
5239 end if;
5241 ------------
5242 -- Ada_83 --
5243 ------------
5245 -- pragma Ada_83;
5247 -- Note: this pragma also has some specific processing in Par.Prag
5248 -- because we want to set the Ada version mode during parsing.
5250 when Pragma_Ada_83 =>
5251 GNAT_Pragma;
5252 Check_Arg_Count (0);
5254 -- We really should check unconditionally for proper configuration
5255 -- pragma placement, since we really don't want mixed Ada modes
5256 -- within a single unit, and the GNAT reference manual has always
5257 -- said this was a configuration pragma, but we did not check and
5258 -- are hesitant to add the check now.
5260 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5261 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5262 -- or Ada 2012 mode.
5264 if Ada_Version >= Ada_05 then
5265 Check_Valid_Configuration_Pragma;
5266 end if;
5268 -- Now set Ada 83 mode
5270 Ada_Version := Ada_83;
5271 Ada_Version_Explicit := Ada_Version;
5273 ------------
5274 -- Ada_95 --
5275 ------------
5277 -- pragma Ada_95;
5279 -- Note: this pragma also has some specific processing in Par.Prag
5280 -- because we want to set the Ada 83 version mode during parsing.
5282 when Pragma_Ada_95 =>
5283 GNAT_Pragma;
5284 Check_Arg_Count (0);
5286 -- We really should check unconditionally for proper configuration
5287 -- pragma placement, since we really don't want mixed Ada modes
5288 -- within a single unit, and the GNAT reference manual has always
5289 -- said this was a configuration pragma, but we did not check and
5290 -- are hesitant to add the check now.
5292 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5293 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5295 if Ada_Version >= Ada_05 then
5296 Check_Valid_Configuration_Pragma;
5297 end if;
5299 -- Now set Ada 95 mode
5301 Ada_Version := Ada_95;
5302 Ada_Version_Explicit := Ada_Version;
5304 ---------------------
5305 -- Ada_05/Ada_2005 --
5306 ---------------------
5308 -- pragma Ada_05;
5309 -- pragma Ada_05 (LOCAL_NAME);
5311 -- pragma Ada_2005;
5312 -- pragma Ada_2005 (LOCAL_NAME):
5314 -- Note: these pragma also have some specific processing in Par.Prag
5315 -- because we want to set the Ada 2005 version mode during parsing.
5317 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5318 E_Id : Node_Id;
5320 begin
5321 GNAT_Pragma;
5323 if Arg_Count = 1 then
5324 Check_Arg_Is_Local_Name (Arg1);
5325 E_Id := Expression (Arg1);
5327 if Etype (E_Id) = Any_Type then
5328 return;
5329 end if;
5331 Set_Is_Ada_2005_Only (Entity (E_Id));
5333 else
5334 Check_Arg_Count (0);
5336 -- For Ada_2005 we unconditionally enforce the documented
5337 -- configuration pragma placement, since we do not want to
5338 -- tolerate mixed modes in a unit involving Ada 2005. That
5339 -- would cause real difficulties for those cases where there
5340 -- are incompatibilities between Ada 95 and Ada 2005.
5342 Check_Valid_Configuration_Pragma;
5344 -- Now set Ada 2005 mode
5346 Ada_Version := Ada_05;
5347 Ada_Version_Explicit := Ada_05;
5348 end if;
5349 end;
5351 ---------------------
5352 -- Ada_12/Ada_2012 --
5353 ---------------------
5355 -- pragma Ada_12;
5356 -- pragma Ada_2012;
5358 -- Note: these pragma also have some specific processing in Par.Prag
5359 -- because we want to set the Ada 2012 version mode during parsing.
5361 when Pragma_Ada_12 | Pragma_Ada_2012 =>
5362 GNAT_Pragma;
5363 Check_Arg_Count (0);
5365 -- For Ada_2012 we unconditionally enforce the documented
5366 -- configuration pragma placement, since we do not want to
5367 -- tolerate mixed modes in a unit involving Ada 2012. That would
5368 -- cause real difficulties for those cases where there are
5369 -- incompatibilities between Ada 95 and Ada 2005/Ada 2012.
5371 Check_Valid_Configuration_Pragma;
5373 -- Now set Ada 2012 mode
5375 Ada_Version := Ada_12;
5376 Ada_Version_Explicit := Ada_12;
5378 ----------------------
5379 -- All_Calls_Remote --
5380 ----------------------
5382 -- pragma All_Calls_Remote [(library_package_NAME)];
5384 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5385 Lib_Entity : Entity_Id;
5387 begin
5388 Check_Ada_83_Warning;
5389 Check_Valid_Library_Unit_Pragma;
5391 if Nkind (N) = N_Null_Statement then
5392 return;
5393 end if;
5395 Lib_Entity := Find_Lib_Unit_Name;
5397 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5399 if Present (Lib_Entity)
5400 and then not Debug_Flag_U
5401 then
5402 if not Is_Remote_Call_Interface (Lib_Entity) then
5403 Error_Pragma ("pragma% only apply to rci unit");
5405 -- Set flag for entity of the library unit
5407 else
5408 Set_Has_All_Calls_Remote (Lib_Entity);
5409 end if;
5411 end if;
5412 end All_Calls_Remote;
5414 --------------
5415 -- Annotate --
5416 --------------
5418 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
5419 -- ARG ::= NAME | EXPRESSION
5421 -- The first two arguments are by convention intended to refer to an
5422 -- external tool and a tool-specific function. These arguments are
5423 -- not analyzed.
5425 when Pragma_Annotate => Annotate : begin
5426 GNAT_Pragma;
5427 Check_At_Least_N_Arguments (1);
5428 Check_Arg_Is_Identifier (Arg1);
5429 Check_No_Identifiers;
5430 Store_Note (N);
5432 declare
5433 Arg : Node_Id;
5434 Exp : Node_Id;
5436 begin
5437 -- Second unanalyzed parameter is optional
5439 if No (Arg2) then
5440 null;
5441 else
5442 Arg := Next (Arg2);
5443 while Present (Arg) loop
5444 Exp := Expression (Arg);
5445 Analyze (Exp);
5447 if Is_Entity_Name (Exp) then
5448 null;
5450 -- For string literals, we assume Standard_String as the
5451 -- type, unless the string contains wide or wide_wide
5452 -- characters.
5454 elsif Nkind (Exp) = N_String_Literal then
5455 if Has_Wide_Wide_Character (Exp) then
5456 Resolve (Exp, Standard_Wide_Wide_String);
5457 elsif Has_Wide_Character (Exp) then
5458 Resolve (Exp, Standard_Wide_String);
5459 else
5460 Resolve (Exp, Standard_String);
5461 end if;
5463 elsif Is_Overloaded (Exp) then
5464 Error_Pragma_Arg
5465 ("ambiguous argument for pragma%", Exp);
5467 else
5468 Resolve (Exp);
5469 end if;
5471 Next (Arg);
5472 end loop;
5473 end if;
5474 end;
5475 end Annotate;
5477 ------------
5478 -- Assert --
5479 ------------
5481 -- pragma Assert ([Check =>] Boolean_EXPRESSION
5482 -- [, [Message =>] Static_String_EXPRESSION]);
5484 when Pragma_Assert => Assert : declare
5485 Expr : Node_Id;
5486 Newa : List_Id;
5488 begin
5489 Ada_2005_Pragma;
5490 Check_At_Least_N_Arguments (1);
5491 Check_At_Most_N_Arguments (2);
5492 Check_Arg_Order ((Name_Check, Name_Message));
5493 Check_Optional_Identifier (Arg1, Name_Check);
5495 -- We treat pragma Assert as equivalent to:
5497 -- pragma Check (Assertion, condition [, msg]);
5499 -- So rewrite pragma in this manner, and analyze the result
5501 Expr := Get_Pragma_Arg (Arg1);
5502 Newa := New_List (
5503 Make_Pragma_Argument_Association (Loc,
5504 Expression =>
5505 Make_Identifier (Loc,
5506 Chars => Name_Assertion)),
5508 Make_Pragma_Argument_Association (Sloc (Expr),
5509 Expression => Expr));
5511 if Arg_Count > 1 then
5512 Check_Optional_Identifier (Arg2, Name_Message);
5513 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
5514 Append_To (Newa, Relocate_Node (Arg2));
5515 end if;
5517 Rewrite (N,
5518 Make_Pragma (Loc,
5519 Chars => Name_Check,
5520 Pragma_Argument_Associations => Newa));
5521 Analyze (N);
5522 end Assert;
5524 ----------------------
5525 -- Assertion_Policy --
5526 ----------------------
5528 -- pragma Assertion_Policy (Check | Ignore)
5530 when Pragma_Assertion_Policy => Assertion_Policy : declare
5531 Policy : Node_Id;
5533 begin
5534 Ada_2005_Pragma;
5535 Check_Valid_Configuration_Pragma;
5536 Check_Arg_Count (1);
5537 Check_No_Identifiers;
5538 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5540 -- We treat pragma Assertion_Policy as equivalent to:
5542 -- pragma Check_Policy (Assertion, policy)
5544 -- So rewrite the pragma in that manner and link on to the chain
5545 -- of Check_Policy pragmas, marking the pragma as analyzed.
5547 Policy := Get_Pragma_Arg (Arg1);
5549 Rewrite (N,
5550 Make_Pragma (Loc,
5551 Chars => Name_Check_Policy,
5553 Pragma_Argument_Associations => New_List (
5554 Make_Pragma_Argument_Association (Loc,
5555 Expression =>
5556 Make_Identifier (Loc,
5557 Chars => Name_Assertion)),
5559 Make_Pragma_Argument_Association (Loc,
5560 Expression =>
5561 Make_Identifier (Sloc (Policy),
5562 Chars => Chars (Policy))))));
5564 Set_Analyzed (N);
5565 Set_Next_Pragma (N, Opt.Check_Policy_List);
5566 Opt.Check_Policy_List := N;
5567 end Assertion_Policy;
5569 ------------------------------
5570 -- Assume_No_Invalid_Values --
5571 ------------------------------
5573 -- pragma Assume_No_Invalid_Values (On | Off);
5575 when Pragma_Assume_No_Invalid_Values =>
5576 GNAT_Pragma;
5577 Check_Valid_Configuration_Pragma;
5578 Check_Arg_Count (1);
5579 Check_No_Identifiers;
5580 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5582 if Chars (Expression (Arg1)) = Name_On then
5583 Assume_No_Invalid_Values := True;
5584 else
5585 Assume_No_Invalid_Values := False;
5586 end if;
5588 ---------------
5589 -- AST_Entry --
5590 ---------------
5592 -- pragma AST_Entry (entry_IDENTIFIER);
5594 when Pragma_AST_Entry => AST_Entry : declare
5595 Ent : Node_Id;
5597 begin
5598 GNAT_Pragma;
5599 Check_VMS (N);
5600 Check_Arg_Count (1);
5601 Check_No_Identifiers;
5602 Check_Arg_Is_Local_Name (Arg1);
5603 Ent := Entity (Expression (Arg1));
5605 -- Note: the implementation of the AST_Entry pragma could handle
5606 -- the entry family case fine, but for now we are consistent with
5607 -- the DEC rules, and do not allow the pragma, which of course
5608 -- has the effect of also forbidding the attribute.
5610 if Ekind (Ent) /= E_Entry then
5611 Error_Pragma_Arg
5612 ("pragma% argument must be simple entry name", Arg1);
5614 elsif Is_AST_Entry (Ent) then
5615 Error_Pragma_Arg
5616 ("duplicate % pragma for entry", Arg1);
5618 elsif Has_Homonym (Ent) then
5619 Error_Pragma_Arg
5620 ("pragma% argument cannot specify overloaded entry", Arg1);
5622 else
5623 declare
5624 FF : constant Entity_Id := First_Formal (Ent);
5626 begin
5627 if Present (FF) then
5628 if Present (Next_Formal (FF)) then
5629 Error_Pragma_Arg
5630 ("entry for pragma% can have only one argument",
5631 Arg1);
5633 elsif Parameter_Mode (FF) /= E_In_Parameter then
5634 Error_Pragma_Arg
5635 ("entry parameter for pragma% must have mode IN",
5636 Arg1);
5637 end if;
5638 end if;
5639 end;
5641 Set_Is_AST_Entry (Ent);
5642 end if;
5643 end AST_Entry;
5645 ------------------
5646 -- Asynchronous --
5647 ------------------
5649 -- pragma Asynchronous (LOCAL_NAME);
5651 when Pragma_Asynchronous => Asynchronous : declare
5652 Nm : Entity_Id;
5653 C_Ent : Entity_Id;
5654 L : List_Id;
5655 S : Node_Id;
5656 N : Node_Id;
5657 Formal : Entity_Id;
5659 procedure Process_Async_Pragma;
5660 -- Common processing for procedure and access-to-procedure case
5662 --------------------------
5663 -- Process_Async_Pragma --
5664 --------------------------
5666 procedure Process_Async_Pragma is
5667 begin
5668 if No (L) then
5669 Set_Is_Asynchronous (Nm);
5670 return;
5671 end if;
5673 -- The formals should be of mode IN (RM E.4.1(6))
5675 S := First (L);
5676 while Present (S) loop
5677 Formal := Defining_Identifier (S);
5679 if Nkind (Formal) = N_Defining_Identifier
5680 and then Ekind (Formal) /= E_In_Parameter
5681 then
5682 Error_Pragma_Arg
5683 ("pragma% procedure can only have IN parameter",
5684 Arg1);
5685 end if;
5687 Next (S);
5688 end loop;
5690 Set_Is_Asynchronous (Nm);
5691 end Process_Async_Pragma;
5693 -- Start of processing for pragma Asynchronous
5695 begin
5696 Check_Ada_83_Warning;
5697 Check_No_Identifiers;
5698 Check_Arg_Count (1);
5699 Check_Arg_Is_Local_Name (Arg1);
5701 if Debug_Flag_U then
5702 return;
5703 end if;
5705 C_Ent := Cunit_Entity (Current_Sem_Unit);
5706 Analyze (Expression (Arg1));
5707 Nm := Entity (Expression (Arg1));
5709 if not Is_Remote_Call_Interface (C_Ent)
5710 and then not Is_Remote_Types (C_Ent)
5711 then
5712 -- This pragma should only appear in an RCI or Remote Types
5713 -- unit (RM E.4.1(4)).
5715 Error_Pragma
5716 ("pragma% not in Remote_Call_Interface or " &
5717 "Remote_Types unit");
5718 end if;
5720 if Ekind (Nm) = E_Procedure
5721 and then Nkind (Parent (Nm)) = N_Procedure_Specification
5722 then
5723 if not Is_Remote_Call_Interface (Nm) then
5724 Error_Pragma_Arg
5725 ("pragma% cannot be applied on non-remote procedure",
5726 Arg1);
5727 end if;
5729 L := Parameter_Specifications (Parent (Nm));
5730 Process_Async_Pragma;
5731 return;
5733 elsif Ekind (Nm) = E_Function then
5734 Error_Pragma_Arg
5735 ("pragma% cannot be applied to function", Arg1);
5737 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
5739 if Is_Record_Type (Nm) then
5741 -- A record type that is the Equivalent_Type for a remote
5742 -- access-to-subprogram type.
5744 N := Declaration_Node (Corresponding_Remote_Type (Nm));
5746 else
5747 -- A non-expanded RAS type (distribution is not enabled)
5749 N := Declaration_Node (Nm);
5750 end if;
5752 if Nkind (N) = N_Full_Type_Declaration
5753 and then Nkind (Type_Definition (N)) =
5754 N_Access_Procedure_Definition
5755 then
5756 L := Parameter_Specifications (Type_Definition (N));
5757 Process_Async_Pragma;
5759 if Is_Asynchronous (Nm)
5760 and then Expander_Active
5761 and then Get_PCS_Name /= Name_No_DSA
5762 then
5763 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
5764 end if;
5766 else
5767 Error_Pragma_Arg
5768 ("pragma% cannot reference access-to-function type",
5769 Arg1);
5770 end if;
5772 -- Only other possibility is Access-to-class-wide type
5774 elsif Is_Access_Type (Nm)
5775 and then Is_Class_Wide_Type (Designated_Type (Nm))
5776 then
5777 Check_First_Subtype (Arg1);
5778 Set_Is_Asynchronous (Nm);
5779 if Expander_Active then
5780 RACW_Type_Is_Asynchronous (Nm);
5781 end if;
5783 else
5784 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
5785 end if;
5786 end Asynchronous;
5788 ------------
5789 -- Atomic --
5790 ------------
5792 -- pragma Atomic (LOCAL_NAME);
5794 when Pragma_Atomic =>
5795 Process_Atomic_Shared_Volatile;
5797 -----------------------
5798 -- Atomic_Components --
5799 -----------------------
5801 -- pragma Atomic_Components (array_LOCAL_NAME);
5803 -- This processing is shared by Volatile_Components
5805 when Pragma_Atomic_Components |
5806 Pragma_Volatile_Components =>
5808 Atomic_Components : declare
5809 E_Id : Node_Id;
5810 E : Entity_Id;
5811 D : Node_Id;
5812 K : Node_Kind;
5814 begin
5815 Check_Ada_83_Warning;
5816 Check_No_Identifiers;
5817 Check_Arg_Count (1);
5818 Check_Arg_Is_Local_Name (Arg1);
5819 E_Id := Expression (Arg1);
5821 if Etype (E_Id) = Any_Type then
5822 return;
5823 end if;
5825 E := Entity (E_Id);
5827 if Rep_Item_Too_Early (E, N)
5828 or else
5829 Rep_Item_Too_Late (E, N)
5830 then
5831 return;
5832 end if;
5834 D := Declaration_Node (E);
5835 K := Nkind (D);
5837 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
5838 or else
5839 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
5840 and then Nkind (D) = N_Object_Declaration
5841 and then Nkind (Object_Definition (D)) =
5842 N_Constrained_Array_Definition)
5843 then
5844 -- The flag is set on the object, or on the base type
5846 if Nkind (D) /= N_Object_Declaration then
5847 E := Base_Type (E);
5848 end if;
5850 Set_Has_Volatile_Components (E);
5852 if Prag_Id = Pragma_Atomic_Components then
5853 Set_Has_Atomic_Components (E);
5855 if Is_Packed (E) then
5856 Set_Is_Packed (E, False);
5858 Error_Pragma_Arg
5859 ("?Pack canceled, cannot pack atomic components",
5860 Arg1);
5861 end if;
5862 end if;
5864 else
5865 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
5866 end if;
5867 end Atomic_Components;
5869 --------------------
5870 -- Attach_Handler --
5871 --------------------
5873 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
5875 when Pragma_Attach_Handler =>
5876 Check_Ada_83_Warning;
5877 Check_No_Identifiers;
5878 Check_Arg_Count (2);
5880 if No_Run_Time_Mode then
5881 Error_Msg_CRT ("Attach_Handler pragma", N);
5882 else
5883 Check_Interrupt_Or_Attach_Handler;
5885 -- The expression that designates the attribute may
5886 -- depend on a discriminant, and is therefore a per-
5887 -- object expression, to be expanded in the init proc.
5888 -- If expansion is enabled, perform semantic checks
5889 -- on a copy only.
5891 if Expander_Active then
5892 declare
5893 Temp : constant Node_Id :=
5894 New_Copy_Tree (Expression (Arg2));
5895 begin
5896 Set_Parent (Temp, N);
5897 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
5898 end;
5900 else
5901 Analyze (Expression (Arg2));
5902 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
5903 end if;
5905 Process_Interrupt_Or_Attach_Handler;
5906 end if;
5908 --------------------
5909 -- C_Pass_By_Copy --
5910 --------------------
5912 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
5914 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
5915 Arg : Node_Id;
5916 Val : Uint;
5918 begin
5919 GNAT_Pragma;
5920 Check_Valid_Configuration_Pragma;
5921 Check_Arg_Count (1);
5922 Check_Optional_Identifier (Arg1, "max_size");
5924 Arg := Expression (Arg1);
5925 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
5927 Val := Expr_Value (Arg);
5929 if Val <= 0 then
5930 Error_Pragma_Arg
5931 ("maximum size for pragma% must be positive", Arg1);
5933 elsif UI_Is_In_Int_Range (Val) then
5934 Default_C_Record_Mechanism := UI_To_Int (Val);
5936 -- If a giant value is given, Int'Last will do well enough.
5937 -- If sometime someone complains that a record larger than
5938 -- two gigabytes is not copied, we will worry about it then!
5940 else
5941 Default_C_Record_Mechanism := Mechanism_Type'Last;
5942 end if;
5943 end C_Pass_By_Copy;
5945 -----------
5946 -- Check --
5947 -----------
5949 -- pragma Check ([Name =>] Identifier,
5950 -- [Check =>] Boolean_Expression
5951 -- [,[Message =>] String_Expression]);
5953 when Pragma_Check => Check : declare
5954 Expr : Node_Id;
5955 Eloc : Source_Ptr;
5957 Check_On : Boolean;
5958 -- Set True if category of assertions referenced by Name enabled
5960 begin
5961 GNAT_Pragma;
5962 Check_At_Least_N_Arguments (2);
5963 Check_At_Most_N_Arguments (3);
5964 Check_Optional_Identifier (Arg1, Name_Name);
5965 Check_Optional_Identifier (Arg2, Name_Check);
5967 if Arg_Count = 3 then
5968 Check_Optional_Identifier (Arg3, Name_Message);
5969 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
5970 end if;
5972 Check_Arg_Is_Identifier (Arg1);
5974 -- Indicate if pragma is enabled. The Original_Node reference here
5975 -- is to deal with pragma Assert rewritten as a Check pragma.
5977 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
5979 if Check_On then
5980 Set_Pragma_Enabled (N);
5981 Set_Pragma_Enabled (Original_Node (N));
5982 Set_SCO_Pragma_Enabled (Loc);
5983 end if;
5985 -- If expansion is active and the check is not enabled then we
5986 -- rewrite the Check as:
5988 -- if False and then condition then
5989 -- null;
5990 -- end if;
5992 -- The reason we do this rewriting during semantic analysis rather
5993 -- than as part of normal expansion is that we cannot analyze and
5994 -- expand the code for the boolean expression directly, or it may
5995 -- cause insertion of actions that would escape the attempt to
5996 -- suppress the check code.
5998 -- Note that the Sloc for the if statement corresponds to the
5999 -- argument condition, not the pragma itself. The reason for this
6000 -- is that we may generate a warning if the condition is False at
6001 -- compile time, and we do not want to delete this warning when we
6002 -- delete the if statement.
6004 Expr := Expression (Arg2);
6006 if Expander_Active and then not Check_On then
6007 Eloc := Sloc (Expr);
6009 Rewrite (N,
6010 Make_If_Statement (Eloc,
6011 Condition =>
6012 Make_And_Then (Eloc,
6013 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6014 Right_Opnd => Expr),
6015 Then_Statements => New_List (
6016 Make_Null_Statement (Eloc))));
6018 Analyze (N);
6020 -- Check is active
6022 else
6023 Analyze_And_Resolve (Expr, Any_Boolean);
6024 end if;
6025 end Check;
6027 ----------------
6028 -- Check_Name --
6029 ----------------
6031 -- pragma Check_Name (check_IDENTIFIER);
6033 when Pragma_Check_Name =>
6034 Check_No_Identifiers;
6035 GNAT_Pragma;
6036 Check_Valid_Configuration_Pragma;
6037 Check_Arg_Count (1);
6038 Check_Arg_Is_Identifier (Arg1);
6040 declare
6041 Nam : constant Name_Id := Chars (Expression (Arg1));
6043 begin
6044 for J in Check_Names.First .. Check_Names.Last loop
6045 if Check_Names.Table (J) = Nam then
6046 return;
6047 end if;
6048 end loop;
6050 Check_Names.Append (Nam);
6051 end;
6053 ------------------
6054 -- Check_Policy --
6055 ------------------
6057 -- pragma Check_Policy (
6058 -- [Name =>] IDENTIFIER,
6059 -- [Policy =>] POLICY_IDENTIFIER);
6061 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6063 -- Note: this is a configuration pragma, but it is allowed to appear
6064 -- anywhere else.
6066 when Pragma_Check_Policy =>
6067 GNAT_Pragma;
6068 Check_Arg_Count (2);
6069 Check_Optional_Identifier (Arg1, Name_Name);
6070 Check_Optional_Identifier (Arg2, Name_Policy);
6071 Check_Arg_Is_One_Of
6072 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6074 -- A Check_Policy pragma can appear either as a configuration
6075 -- pragma, or in a declarative part or a package spec (see RM
6076 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6077 -- followed for Check_Policy).
6079 if not Is_Configuration_Pragma then
6080 Check_Is_In_Decl_Part_Or_Package_Spec;
6081 end if;
6083 Set_Next_Pragma (N, Opt.Check_Policy_List);
6084 Opt.Check_Policy_List := N;
6086 ---------------------
6087 -- CIL_Constructor --
6088 ---------------------
6090 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6092 -- Processing for this pragma is shared with Java_Constructor
6094 -------------
6095 -- Comment --
6096 -------------
6098 -- pragma Comment (static_string_EXPRESSION)
6100 -- Processing for pragma Comment shares the circuitry for pragma
6101 -- Ident. The only differences are that Ident enforces a limit of 31
6102 -- characters on its argument, and also enforces limitations on
6103 -- placement for DEC compatibility. Pragma Comment shares neither of
6104 -- these restrictions.
6106 -------------------
6107 -- Common_Object --
6108 -------------------
6110 -- pragma Common_Object (
6111 -- [Internal =>] LOCAL_NAME
6112 -- [, [External =>] EXTERNAL_SYMBOL]
6113 -- [, [Size =>] EXTERNAL_SYMBOL]);
6115 -- Processing for this pragma is shared with Psect_Object
6117 ------------------------
6118 -- Compile_Time_Error --
6119 ------------------------
6121 -- pragma Compile_Time_Error
6122 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6124 when Pragma_Compile_Time_Error =>
6125 GNAT_Pragma;
6126 Process_Compile_Time_Warning_Or_Error;
6128 --------------------------
6129 -- Compile_Time_Warning --
6130 --------------------------
6132 -- pragma Compile_Time_Warning
6133 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6135 when Pragma_Compile_Time_Warning =>
6136 GNAT_Pragma;
6137 Process_Compile_Time_Warning_Or_Error;
6139 -------------------
6140 -- Compiler_Unit --
6141 -------------------
6143 when Pragma_Compiler_Unit =>
6144 GNAT_Pragma;
6145 Check_Arg_Count (0);
6146 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6148 -----------------------------
6149 -- Complete_Representation --
6150 -----------------------------
6152 -- pragma Complete_Representation;
6154 when Pragma_Complete_Representation =>
6155 GNAT_Pragma;
6156 Check_Arg_Count (0);
6158 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6159 Error_Pragma
6160 ("pragma & must appear within record representation clause");
6161 end if;
6163 ----------------------------
6164 -- Complex_Representation --
6165 ----------------------------
6167 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6169 when Pragma_Complex_Representation => Complex_Representation : declare
6170 E_Id : Entity_Id;
6171 E : Entity_Id;
6172 Ent : Entity_Id;
6174 begin
6175 GNAT_Pragma;
6176 Check_Arg_Count (1);
6177 Check_Optional_Identifier (Arg1, Name_Entity);
6178 Check_Arg_Is_Local_Name (Arg1);
6179 E_Id := Expression (Arg1);
6181 if Etype (E_Id) = Any_Type then
6182 return;
6183 end if;
6185 E := Entity (E_Id);
6187 if not Is_Record_Type (E) then
6188 Error_Pragma_Arg
6189 ("argument for pragma% must be record type", Arg1);
6190 end if;
6192 Ent := First_Entity (E);
6194 if No (Ent)
6195 or else No (Next_Entity (Ent))
6196 or else Present (Next_Entity (Next_Entity (Ent)))
6197 or else not Is_Floating_Point_Type (Etype (Ent))
6198 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6199 then
6200 Error_Pragma_Arg
6201 ("record for pragma% must have two fields of the same "
6202 & "floating-point type", Arg1);
6204 else
6205 Set_Has_Complex_Representation (Base_Type (E));
6207 -- We need to treat the type has having a non-standard
6208 -- representation, for back-end purposes, even though in
6209 -- general a complex will have the default representation
6210 -- of a record with two real components.
6212 Set_Has_Non_Standard_Rep (Base_Type (E));
6213 end if;
6214 end Complex_Representation;
6216 -------------------------
6217 -- Component_Alignment --
6218 -------------------------
6220 -- pragma Component_Alignment (
6221 -- [Form =>] ALIGNMENT_CHOICE
6222 -- [, [Name =>] type_LOCAL_NAME]);
6224 -- ALIGNMENT_CHOICE ::=
6225 -- Component_Size
6226 -- | Component_Size_4
6227 -- | Storage_Unit
6228 -- | Default
6230 when Pragma_Component_Alignment => Component_AlignmentP : declare
6231 Args : Args_List (1 .. 2);
6232 Names : constant Name_List (1 .. 2) := (
6233 Name_Form,
6234 Name_Name);
6236 Form : Node_Id renames Args (1);
6237 Name : Node_Id renames Args (2);
6239 Atype : Component_Alignment_Kind;
6240 Typ : Entity_Id;
6242 begin
6243 GNAT_Pragma;
6244 Gather_Associations (Names, Args);
6246 if No (Form) then
6247 Error_Pragma ("missing Form argument for pragma%");
6248 end if;
6250 Check_Arg_Is_Identifier (Form);
6252 -- Get proper alignment, note that Default = Component_Size on all
6253 -- machines we have so far, and we want to set this value rather
6254 -- than the default value to indicate that it has been explicitly
6255 -- set (and thus will not get overridden by the default component
6256 -- alignment for the current scope)
6258 if Chars (Form) = Name_Component_Size then
6259 Atype := Calign_Component_Size;
6261 elsif Chars (Form) = Name_Component_Size_4 then
6262 Atype := Calign_Component_Size_4;
6264 elsif Chars (Form) = Name_Default then
6265 Atype := Calign_Component_Size;
6267 elsif Chars (Form) = Name_Storage_Unit then
6268 Atype := Calign_Storage_Unit;
6270 else
6271 Error_Pragma_Arg
6272 ("invalid Form parameter for pragma%", Form);
6273 end if;
6275 -- Case with no name, supplied, affects scope table entry
6277 if No (Name) then
6278 Scope_Stack.Table
6279 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6281 -- Case of name supplied
6283 else
6284 Check_Arg_Is_Local_Name (Name);
6285 Find_Type (Name);
6286 Typ := Entity (Name);
6288 if Typ = Any_Type
6289 or else Rep_Item_Too_Early (Typ, N)
6290 then
6291 return;
6292 else
6293 Typ := Underlying_Type (Typ);
6294 end if;
6296 if not Is_Record_Type (Typ)
6297 and then not Is_Array_Type (Typ)
6298 then
6299 Error_Pragma_Arg
6300 ("Name parameter of pragma% must identify record or " &
6301 "array type", Name);
6302 end if;
6304 -- An explicit Component_Alignment pragma overrides an
6305 -- implicit pragma Pack, but not an explicit one.
6307 if not Has_Pragma_Pack (Base_Type (Typ)) then
6308 Set_Is_Packed (Base_Type (Typ), False);
6309 Set_Component_Alignment (Base_Type (Typ), Atype);
6310 end if;
6311 end if;
6312 end Component_AlignmentP;
6314 ----------------
6315 -- Controlled --
6316 ----------------
6318 -- pragma Controlled (first_subtype_LOCAL_NAME);
6320 when Pragma_Controlled => Controlled : declare
6321 Arg : Node_Id;
6323 begin
6324 Check_No_Identifiers;
6325 Check_Arg_Count (1);
6326 Check_Arg_Is_Local_Name (Arg1);
6327 Arg := Expression (Arg1);
6329 if not Is_Entity_Name (Arg)
6330 or else not Is_Access_Type (Entity (Arg))
6331 then
6332 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6333 else
6334 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6335 end if;
6336 end Controlled;
6338 ----------------
6339 -- Convention --
6340 ----------------
6342 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6343 -- [Entity =>] LOCAL_NAME);
6345 when Pragma_Convention => Convention : declare
6346 C : Convention_Id;
6347 E : Entity_Id;
6348 pragma Warnings (Off, C);
6349 pragma Warnings (Off, E);
6350 begin
6351 Check_Arg_Order ((Name_Convention, Name_Entity));
6352 Check_Ada_83_Warning;
6353 Check_Arg_Count (2);
6354 Process_Convention (C, E);
6355 end Convention;
6357 ---------------------------
6358 -- Convention_Identifier --
6359 ---------------------------
6361 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6362 -- [Convention =>] convention_IDENTIFIER);
6364 when Pragma_Convention_Identifier => Convention_Identifier : declare
6365 Idnam : Name_Id;
6366 Cname : Name_Id;
6368 begin
6369 GNAT_Pragma;
6370 Check_Arg_Order ((Name_Name, Name_Convention));
6371 Check_Arg_Count (2);
6372 Check_Optional_Identifier (Arg1, Name_Name);
6373 Check_Optional_Identifier (Arg2, Name_Convention);
6374 Check_Arg_Is_Identifier (Arg1);
6375 Check_Arg_Is_Identifier (Arg2);
6376 Idnam := Chars (Expression (Arg1));
6377 Cname := Chars (Expression (Arg2));
6379 if Is_Convention_Name (Cname) then
6380 Record_Convention_Identifier
6381 (Idnam, Get_Convention_Id (Cname));
6382 else
6383 Error_Pragma_Arg
6384 ("second arg for % pragma must be convention", Arg2);
6385 end if;
6386 end Convention_Identifier;
6388 ---------------
6389 -- CPP_Class --
6390 ---------------
6392 -- pragma CPP_Class ([Entity =>] local_NAME)
6394 when Pragma_CPP_Class => CPP_Class : declare
6395 Arg : Node_Id;
6396 Typ : Entity_Id;
6398 begin
6399 if Warn_On_Obsolescent_Feature then
6400 Error_Msg_N
6401 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6402 " by pragma import?", N);
6403 end if;
6405 GNAT_Pragma;
6406 Check_Arg_Count (1);
6407 Check_Optional_Identifier (Arg1, Name_Entity);
6408 Check_Arg_Is_Local_Name (Arg1);
6410 Arg := Expression (Arg1);
6411 Analyze (Arg);
6413 if Etype (Arg) = Any_Type then
6414 return;
6415 end if;
6417 if not Is_Entity_Name (Arg)
6418 or else not Is_Type (Entity (Arg))
6419 then
6420 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6421 end if;
6423 Typ := Entity (Arg);
6425 if not Is_Tagged_Type (Typ) then
6426 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6427 end if;
6429 -- Types treated as CPP classes are treated as limited, but we
6430 -- don't require them to be declared this way. A warning is issued
6431 -- to encourage the user to declare them as limited. This is not
6432 -- an error, for compatibility reasons, because these types have
6433 -- been supported this way for some time.
6435 if not Is_Limited_Type (Typ) then
6436 Error_Msg_N
6437 ("imported 'C'P'P type should be " &
6438 "explicitly declared limited?",
6439 Get_Pragma_Arg (Arg1));
6440 Error_Msg_N
6441 ("\type will be considered limited",
6442 Get_Pragma_Arg (Arg1));
6443 end if;
6445 Set_Is_CPP_Class (Typ);
6446 Set_Is_Limited_Record (Typ);
6447 Set_Convention (Typ, Convention_CPP);
6449 -- Imported CPP types must not have discriminants (because C++
6450 -- classes do not have discriminants).
6452 if Has_Discriminants (Typ) then
6453 Error_Msg_N
6454 ("imported 'C'P'P type cannot have discriminants",
6455 First (Discriminant_Specifications
6456 (Declaration_Node (Typ))));
6457 end if;
6459 -- Components of imported CPP types must not have default
6460 -- expressions because the constructor (if any) is in the
6461 -- C++ side.
6463 if Is_Incomplete_Or_Private_Type (Typ)
6464 and then No (Underlying_Type (Typ))
6465 then
6466 -- It should be an error to apply pragma CPP to a private
6467 -- type if the underlying type is not visible (as it is
6468 -- for any representation item). For now, for backward
6469 -- compatibility we do nothing but we cannot check components
6470 -- because they are not available at this stage. All this code
6471 -- will be removed when we cleanup this obsolete GNAT pragma???
6473 null;
6475 else
6476 declare
6477 Tdef : constant Node_Id :=
6478 Type_Definition (Declaration_Node (Typ));
6479 Clist : Node_Id;
6480 Comp : Node_Id;
6482 begin
6483 if Nkind (Tdef) = N_Record_Definition then
6484 Clist := Component_List (Tdef);
6485 else
6486 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
6487 Clist := Component_List (Record_Extension_Part (Tdef));
6488 end if;
6490 if Present (Clist) then
6491 Comp := First (Component_Items (Clist));
6492 while Present (Comp) loop
6493 if Present (Expression (Comp)) then
6494 Error_Msg_N
6495 ("component of imported 'C'P'P type cannot have" &
6496 " default expression", Expression (Comp));
6497 end if;
6499 Next (Comp);
6500 end loop;
6501 end if;
6502 end;
6503 end if;
6504 end CPP_Class;
6506 ---------------------
6507 -- CPP_Constructor --
6508 ---------------------
6510 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
6511 -- [, [External_Name =>] static_string_EXPRESSION ]
6512 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6514 when Pragma_CPP_Constructor => CPP_Constructor : declare
6515 Elmt : Elmt_Id;
6516 Id : Entity_Id;
6517 Def_Id : Entity_Id;
6518 Tag_Typ : Entity_Id;
6520 begin
6521 GNAT_Pragma;
6522 Check_At_Least_N_Arguments (1);
6523 Check_At_Most_N_Arguments (3);
6524 Check_Optional_Identifier (Arg1, Name_Entity);
6525 Check_Arg_Is_Local_Name (Arg1);
6527 Id := Expression (Arg1);
6528 Find_Program_Unit_Name (Id);
6530 -- If we did not find the name, we are done
6532 if Etype (Id) = Any_Type then
6533 return;
6534 end if;
6536 Def_Id := Entity (Id);
6538 if Ekind (Def_Id) = E_Function
6539 and then (Is_CPP_Class (Etype (Def_Id))
6540 or else (Is_Class_Wide_Type (Etype (Def_Id))
6541 and then
6542 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
6543 then
6544 if Arg_Count >= 2 then
6545 Set_Imported (Def_Id);
6546 Set_Is_Public (Def_Id);
6547 Process_Interface_Name (Def_Id, Arg2, Arg3);
6548 end if;
6550 Set_Has_Completion (Def_Id);
6551 Set_Is_Constructor (Def_Id);
6553 -- Imported C++ constructors are not dispatching primitives
6554 -- because in C++ they don't have a dispatch table slot.
6555 -- However, in Ada the constructor has the profile of a
6556 -- function that returns a tagged type and therefore it has
6557 -- been treated as a primitive operation during semantic
6558 -- analysis. We now remove it from the list of primitive
6559 -- operations of the type.
6561 if Is_Tagged_Type (Etype (Def_Id))
6562 and then not Is_Class_Wide_Type (Etype (Def_Id))
6563 then
6564 pragma Assert (Is_Dispatching_Operation (Def_Id));
6565 Tag_Typ := Etype (Def_Id);
6567 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
6568 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
6569 Next_Elmt (Elmt);
6570 end loop;
6572 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
6573 Set_Is_Dispatching_Operation (Def_Id, False);
6574 end if;
6576 -- For backward compatibility, if the constructor returns a
6577 -- class wide type, and we internally change the return type to
6578 -- the corresponding root type.
6580 if Is_Class_Wide_Type (Etype (Def_Id)) then
6581 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
6582 end if;
6583 else
6584 Error_Pragma_Arg
6585 ("pragma% requires function returning a 'C'P'P_Class type",
6586 Arg1);
6587 end if;
6588 end CPP_Constructor;
6590 -----------------
6591 -- CPP_Virtual --
6592 -----------------
6594 when Pragma_CPP_Virtual => CPP_Virtual : declare
6595 begin
6596 GNAT_Pragma;
6598 if Warn_On_Obsolescent_Feature then
6599 Error_Msg_N
6600 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
6601 "no effect?", N);
6602 end if;
6603 end CPP_Virtual;
6605 ----------------
6606 -- CPP_Vtable --
6607 ----------------
6609 when Pragma_CPP_Vtable => CPP_Vtable : declare
6610 begin
6611 GNAT_Pragma;
6613 if Warn_On_Obsolescent_Feature then
6614 Error_Msg_N
6615 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
6616 "no effect?", N);
6617 end if;
6618 end CPP_Vtable;
6620 -----------
6621 -- Debug --
6622 -----------
6624 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
6626 when Pragma_Debug => Debug : declare
6627 Cond : Node_Id;
6629 begin
6630 GNAT_Pragma;
6632 Cond :=
6633 New_Occurrence_Of
6634 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
6635 Loc);
6637 if Arg_Count = 2 then
6638 Cond :=
6639 Make_And_Then (Loc,
6640 Left_Opnd => Relocate_Node (Cond),
6641 Right_Opnd => Expression (Arg1));
6642 end if;
6644 -- Rewrite into a conditional with an appropriate condition. We
6645 -- wrap the procedure call in a block so that overhead from e.g.
6646 -- use of the secondary stack does not generate execution overhead
6647 -- for suppressed conditions.
6649 Rewrite (N, Make_Implicit_If_Statement (N,
6650 Condition => Cond,
6651 Then_Statements => New_List (
6652 Make_Block_Statement (Loc,
6653 Handled_Statement_Sequence =>
6654 Make_Handled_Sequence_Of_Statements (Loc,
6655 Statements => New_List (
6656 Relocate_Node (Debug_Statement (N))))))));
6657 Analyze (N);
6658 end Debug;
6660 ------------------
6661 -- Debug_Policy --
6662 ------------------
6664 -- pragma Debug_Policy (Check | Ignore)
6666 when Pragma_Debug_Policy =>
6667 GNAT_Pragma;
6668 Check_Arg_Count (1);
6669 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6670 Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
6672 ---------------------
6673 -- Detect_Blocking --
6674 ---------------------
6676 -- pragma Detect_Blocking;
6678 when Pragma_Detect_Blocking =>
6679 Ada_2005_Pragma;
6680 Check_Arg_Count (0);
6681 Check_Valid_Configuration_Pragma;
6682 Detect_Blocking := True;
6684 ---------------
6685 -- Dimension --
6686 ---------------
6688 when Pragma_Dimension =>
6689 GNAT_Pragma;
6690 Check_Arg_Count (4);
6691 Check_No_Identifiers;
6692 Check_Arg_Is_Local_Name (Arg1);
6694 if not Is_Type (Arg1) then
6695 Error_Pragma ("first argument for pragma% must be subtype");
6696 end if;
6698 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
6699 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
6700 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
6702 -------------------
6703 -- Discard_Names --
6704 -------------------
6706 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
6708 when Pragma_Discard_Names => Discard_Names : declare
6709 E : Entity_Id;
6710 E_Id : Entity_Id;
6712 begin
6713 Check_Ada_83_Warning;
6715 -- Deal with configuration pragma case
6717 if Arg_Count = 0 and then Is_Configuration_Pragma then
6718 Global_Discard_Names := True;
6719 return;
6721 -- Otherwise, check correct appropriate context
6723 else
6724 Check_Is_In_Decl_Part_Or_Package_Spec;
6726 if Arg_Count = 0 then
6728 -- If there is no parameter, then from now on this pragma
6729 -- applies to any enumeration, exception or tagged type
6730 -- defined in the current declarative part, and recursively
6731 -- to any nested scope.
6733 Set_Discard_Names (Current_Scope);
6734 return;
6736 else
6737 Check_Arg_Count (1);
6738 Check_Optional_Identifier (Arg1, Name_On);
6739 Check_Arg_Is_Local_Name (Arg1);
6741 E_Id := Expression (Arg1);
6743 if Etype (E_Id) = Any_Type then
6744 return;
6745 else
6746 E := Entity (E_Id);
6747 end if;
6749 if (Is_First_Subtype (E)
6750 and then
6751 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
6752 or else Ekind (E) = E_Exception
6753 then
6754 Set_Discard_Names (E);
6755 else
6756 Error_Pragma_Arg
6757 ("inappropriate entity for pragma%", Arg1);
6758 end if;
6760 end if;
6761 end if;
6762 end Discard_Names;
6764 ---------------
6765 -- Elaborate --
6766 ---------------
6768 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
6770 when Pragma_Elaborate => Elaborate : declare
6771 Arg : Node_Id;
6772 Citem : Node_Id;
6774 begin
6775 -- Pragma must be in context items list of a compilation unit
6777 if not Is_In_Context_Clause then
6778 Pragma_Misplaced;
6779 end if;
6781 -- Must be at least one argument
6783 if Arg_Count = 0 then
6784 Error_Pragma ("pragma% requires at least one argument");
6785 end if;
6787 -- In Ada 83 mode, there can be no items following it in the
6788 -- context list except other pragmas and implicit with clauses
6789 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
6790 -- placement rule does not apply.
6792 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
6793 Citem := Next (N);
6794 while Present (Citem) loop
6795 if Nkind (Citem) = N_Pragma
6796 or else (Nkind (Citem) = N_With_Clause
6797 and then Implicit_With (Citem))
6798 then
6799 null;
6800 else
6801 Error_Pragma
6802 ("(Ada 83) pragma% must be at end of context clause");
6803 end if;
6805 Next (Citem);
6806 end loop;
6807 end if;
6809 -- Finally, the arguments must all be units mentioned in a with
6810 -- clause in the same context clause. Note we already checked (in
6811 -- Par.Prag) that the arguments are all identifiers or selected
6812 -- components.
6814 Arg := Arg1;
6815 Outer : while Present (Arg) loop
6816 Citem := First (List_Containing (N));
6817 Inner : while Citem /= N loop
6818 if Nkind (Citem) = N_With_Clause
6819 and then Same_Name (Name (Citem), Expression (Arg))
6820 then
6821 Set_Elaborate_Present (Citem, True);
6822 Set_Unit_Name (Expression (Arg), Name (Citem));
6824 -- With the pragma present, elaboration calls on
6825 -- subprograms from the named unit need no further
6826 -- checks, as long as the pragma appears in the current
6827 -- compilation unit. If the pragma appears in some unit
6828 -- in the context, there might still be a need for an
6829 -- Elaborate_All_Desirable from the current compilation
6830 -- to the named unit, so we keep the check enabled.
6832 if In_Extended_Main_Source_Unit (N) then
6833 Set_Suppress_Elaboration_Warnings
6834 (Entity (Name (Citem)));
6835 end if;
6837 exit Inner;
6838 end if;
6840 Next (Citem);
6841 end loop Inner;
6843 if Citem = N then
6844 Error_Pragma_Arg
6845 ("argument of pragma% is not with'ed unit", Arg);
6846 end if;
6848 Next (Arg);
6849 end loop Outer;
6851 -- Give a warning if operating in static mode with -gnatwl
6852 -- (elaboration warnings enabled) switch set.
6854 if Elab_Warnings and not Dynamic_Elaboration_Checks then
6855 Error_Msg_N
6856 ("?use of pragma Elaborate may not be safe", N);
6857 Error_Msg_N
6858 ("?use pragma Elaborate_All instead if possible", N);
6859 end if;
6860 end Elaborate;
6862 -------------------
6863 -- Elaborate_All --
6864 -------------------
6866 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
6868 when Pragma_Elaborate_All => Elaborate_All : declare
6869 Arg : Node_Id;
6870 Citem : Node_Id;
6872 begin
6873 Check_Ada_83_Warning;
6875 -- Pragma must be in context items list of a compilation unit
6877 if not Is_In_Context_Clause then
6878 Pragma_Misplaced;
6879 end if;
6881 -- Must be at least one argument
6883 if Arg_Count = 0 then
6884 Error_Pragma ("pragma% requires at least one argument");
6885 end if;
6887 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
6888 -- have to appear at the end of the context clause, but may
6889 -- appear mixed in with other items, even in Ada 83 mode.
6891 -- Final check: the arguments must all be units mentioned in
6892 -- a with clause in the same context clause. Note that we
6893 -- already checked (in Par.Prag) that all the arguments are
6894 -- either identifiers or selected components.
6896 Arg := Arg1;
6897 Outr : while Present (Arg) loop
6898 Citem := First (List_Containing (N));
6899 Innr : while Citem /= N loop
6900 if Nkind (Citem) = N_With_Clause
6901 and then Same_Name (Name (Citem), Expression (Arg))
6902 then
6903 Set_Elaborate_All_Present (Citem, True);
6904 Set_Unit_Name (Expression (Arg), Name (Citem));
6906 -- Suppress warnings and elaboration checks on the named
6907 -- unit if the pragma is in the current compilation, as
6908 -- for pragma Elaborate.
6910 if In_Extended_Main_Source_Unit (N) then
6911 Set_Suppress_Elaboration_Warnings
6912 (Entity (Name (Citem)));
6913 end if;
6914 exit Innr;
6915 end if;
6917 Next (Citem);
6918 end loop Innr;
6920 if Citem = N then
6921 Set_Error_Posted (N);
6922 Error_Pragma_Arg
6923 ("argument of pragma% is not with'ed unit", Arg);
6924 end if;
6926 Next (Arg);
6927 end loop Outr;
6928 end Elaborate_All;
6930 --------------------
6931 -- Elaborate_Body --
6932 --------------------
6934 -- pragma Elaborate_Body [( library_unit_NAME )];
6936 when Pragma_Elaborate_Body => Elaborate_Body : declare
6937 Cunit_Node : Node_Id;
6938 Cunit_Ent : Entity_Id;
6940 begin
6941 Check_Ada_83_Warning;
6942 Check_Valid_Library_Unit_Pragma;
6944 if Nkind (N) = N_Null_Statement then
6945 return;
6946 end if;
6948 Cunit_Node := Cunit (Current_Sem_Unit);
6949 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
6951 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
6952 N_Subprogram_Body)
6953 then
6954 Error_Pragma ("pragma% must refer to a spec, not a body");
6955 else
6956 Set_Body_Required (Cunit_Node, True);
6957 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
6959 -- If we are in dynamic elaboration mode, then we suppress
6960 -- elaboration warnings for the unit, since it is definitely
6961 -- fine NOT to do dynamic checks at the first level (and such
6962 -- checks will be suppressed because no elaboration boolean
6963 -- is created for Elaborate_Body packages).
6965 -- But in the static model of elaboration, Elaborate_Body is
6966 -- definitely NOT good enough to ensure elaboration safety on
6967 -- its own, since the body may WITH other units that are not
6968 -- safe from an elaboration point of view, so a client must
6969 -- still do an Elaborate_All on such units.
6971 -- Debug flag -gnatdD restores the old behavior of 3.13, where
6972 -- Elaborate_Body always suppressed elab warnings.
6974 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
6975 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
6976 end if;
6977 end if;
6978 end Elaborate_Body;
6980 ------------------------
6981 -- Elaboration_Checks --
6982 ------------------------
6984 -- pragma Elaboration_Checks (Static | Dynamic);
6986 when Pragma_Elaboration_Checks =>
6987 GNAT_Pragma;
6988 Check_Arg_Count (1);
6989 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
6990 Dynamic_Elaboration_Checks :=
6991 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
6993 ---------------
6994 -- Eliminate --
6995 ---------------
6997 -- pragma Eliminate (
6998 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
6999 -- [,[Entity =>] IDENTIFIER |
7000 -- SELECTED_COMPONENT |
7001 -- STRING_LITERAL]
7002 -- [, OVERLOADING_RESOLUTION]);
7004 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7005 -- SOURCE_LOCATION
7007 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7008 -- FUNCTION_PROFILE
7010 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7012 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7013 -- Result_Type => result_SUBTYPE_NAME]
7015 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7016 -- SUBTYPE_NAME ::= STRING_LITERAL
7018 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7019 -- SOURCE_TRACE ::= STRING_LITERAL
7021 when Pragma_Eliminate => Eliminate : declare
7022 Args : Args_List (1 .. 5);
7023 Names : constant Name_List (1 .. 5) := (
7024 Name_Unit_Name,
7025 Name_Entity,
7026 Name_Parameter_Types,
7027 Name_Result_Type,
7028 Name_Source_Location);
7030 Unit_Name : Node_Id renames Args (1);
7031 Entity : Node_Id renames Args (2);
7032 Parameter_Types : Node_Id renames Args (3);
7033 Result_Type : Node_Id renames Args (4);
7034 Source_Location : Node_Id renames Args (5);
7036 begin
7037 GNAT_Pragma;
7038 Check_Valid_Configuration_Pragma;
7039 Gather_Associations (Names, Args);
7041 if No (Unit_Name) then
7042 Error_Pragma ("missing Unit_Name argument for pragma%");
7043 end if;
7045 if No (Entity)
7046 and then (Present (Parameter_Types)
7047 or else
7048 Present (Result_Type)
7049 or else
7050 Present (Source_Location))
7051 then
7052 Error_Pragma ("missing Entity argument for pragma%");
7053 end if;
7055 if (Present (Parameter_Types)
7056 or else
7057 Present (Result_Type))
7058 and then
7059 Present (Source_Location)
7060 then
7061 Error_Pragma
7062 ("parameter profile and source location cannot " &
7063 "be used together in pragma%");
7064 end if;
7066 Process_Eliminate_Pragma
7068 Unit_Name,
7069 Entity,
7070 Parameter_Types,
7071 Result_Type,
7072 Source_Location);
7073 end Eliminate;
7075 ------------
7076 -- Export --
7077 ------------
7079 -- pragma Export (
7080 -- [ Convention =>] convention_IDENTIFIER,
7081 -- [ Entity =>] local_NAME
7082 -- [, [External_Name =>] static_string_EXPRESSION ]
7083 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7085 when Pragma_Export => Export : declare
7086 C : Convention_Id;
7087 Def_Id : Entity_Id;
7089 pragma Warnings (Off, C);
7091 begin
7092 Check_Ada_83_Warning;
7093 Check_Arg_Order
7094 ((Name_Convention,
7095 Name_Entity,
7096 Name_External_Name,
7097 Name_Link_Name));
7098 Check_At_Least_N_Arguments (2);
7099 Check_At_Most_N_Arguments (4);
7100 Process_Convention (C, Def_Id);
7102 if Ekind (Def_Id) /= E_Constant then
7103 Note_Possible_Modification (Expression (Arg2), Sure => False);
7104 end if;
7106 Process_Interface_Name (Def_Id, Arg3, Arg4);
7107 Set_Exported (Def_Id, Arg2);
7109 -- If the entity is a deferred constant, propagate the information
7110 -- to the full view, because gigi elaborates the full view only.
7112 if Ekind (Def_Id) = E_Constant
7113 and then Present (Full_View (Def_Id))
7114 then
7115 declare
7116 Id2 : constant Entity_Id := Full_View (Def_Id);
7117 begin
7118 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7119 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7120 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7121 end;
7122 end if;
7123 end Export;
7125 ----------------------
7126 -- Export_Exception --
7127 ----------------------
7129 -- pragma Export_Exception (
7130 -- [Internal =>] LOCAL_NAME
7131 -- [, [External =>] EXTERNAL_SYMBOL]
7132 -- [, [Form =>] Ada | VMS]
7133 -- [, [Code =>] static_integer_EXPRESSION]);
7135 when Pragma_Export_Exception => Export_Exception : declare
7136 Args : Args_List (1 .. 4);
7137 Names : constant Name_List (1 .. 4) := (
7138 Name_Internal,
7139 Name_External,
7140 Name_Form,
7141 Name_Code);
7143 Internal : Node_Id renames Args (1);
7144 External : Node_Id renames Args (2);
7145 Form : Node_Id renames Args (3);
7146 Code : Node_Id renames Args (4);
7148 begin
7149 GNAT_Pragma;
7151 if Inside_A_Generic then
7152 Error_Pragma ("pragma% cannot be used for generic entities");
7153 end if;
7155 Gather_Associations (Names, Args);
7156 Process_Extended_Import_Export_Exception_Pragma (
7157 Arg_Internal => Internal,
7158 Arg_External => External,
7159 Arg_Form => Form,
7160 Arg_Code => Code);
7162 if not Is_VMS_Exception (Entity (Internal)) then
7163 Set_Exported (Entity (Internal), Internal);
7164 end if;
7165 end Export_Exception;
7167 ---------------------
7168 -- Export_Function --
7169 ---------------------
7171 -- pragma Export_Function (
7172 -- [Internal =>] LOCAL_NAME
7173 -- [, [External =>] EXTERNAL_SYMBOL]
7174 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7175 -- [, [Result_Type =>] TYPE_DESIGNATOR]
7176 -- [, [Mechanism =>] MECHANISM]
7177 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
7179 -- EXTERNAL_SYMBOL ::=
7180 -- IDENTIFIER
7181 -- | static_string_EXPRESSION
7183 -- PARAMETER_TYPES ::=
7184 -- null
7185 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7187 -- TYPE_DESIGNATOR ::=
7188 -- subtype_NAME
7189 -- | subtype_Name ' Access
7191 -- MECHANISM ::=
7192 -- MECHANISM_NAME
7193 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7195 -- MECHANISM_ASSOCIATION ::=
7196 -- [formal_parameter_NAME =>] MECHANISM_NAME
7198 -- MECHANISM_NAME ::=
7199 -- Value
7200 -- | Reference
7201 -- | Descriptor [([Class =>] CLASS_NAME)]
7203 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7205 when Pragma_Export_Function => Export_Function : declare
7206 Args : Args_List (1 .. 6);
7207 Names : constant Name_List (1 .. 6) := (
7208 Name_Internal,
7209 Name_External,
7210 Name_Parameter_Types,
7211 Name_Result_Type,
7212 Name_Mechanism,
7213 Name_Result_Mechanism);
7215 Internal : Node_Id renames Args (1);
7216 External : Node_Id renames Args (2);
7217 Parameter_Types : Node_Id renames Args (3);
7218 Result_Type : Node_Id renames Args (4);
7219 Mechanism : Node_Id renames Args (5);
7220 Result_Mechanism : Node_Id renames Args (6);
7222 begin
7223 GNAT_Pragma;
7224 Gather_Associations (Names, Args);
7225 Process_Extended_Import_Export_Subprogram_Pragma (
7226 Arg_Internal => Internal,
7227 Arg_External => External,
7228 Arg_Parameter_Types => Parameter_Types,
7229 Arg_Result_Type => Result_Type,
7230 Arg_Mechanism => Mechanism,
7231 Arg_Result_Mechanism => Result_Mechanism);
7232 end Export_Function;
7234 -------------------
7235 -- Export_Object --
7236 -------------------
7238 -- pragma Export_Object (
7239 -- [Internal =>] LOCAL_NAME
7240 -- [, [External =>] EXTERNAL_SYMBOL]
7241 -- [, [Size =>] EXTERNAL_SYMBOL]);
7243 -- EXTERNAL_SYMBOL ::=
7244 -- IDENTIFIER
7245 -- | static_string_EXPRESSION
7247 -- PARAMETER_TYPES ::=
7248 -- null
7249 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7251 -- TYPE_DESIGNATOR ::=
7252 -- subtype_NAME
7253 -- | subtype_Name ' Access
7255 -- MECHANISM ::=
7256 -- MECHANISM_NAME
7257 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7259 -- MECHANISM_ASSOCIATION ::=
7260 -- [formal_parameter_NAME =>] MECHANISM_NAME
7262 -- MECHANISM_NAME ::=
7263 -- Value
7264 -- | Reference
7265 -- | Descriptor [([Class =>] CLASS_NAME)]
7267 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7269 when Pragma_Export_Object => Export_Object : declare
7270 Args : Args_List (1 .. 3);
7271 Names : constant Name_List (1 .. 3) := (
7272 Name_Internal,
7273 Name_External,
7274 Name_Size);
7276 Internal : Node_Id renames Args (1);
7277 External : Node_Id renames Args (2);
7278 Size : Node_Id renames Args (3);
7280 begin
7281 GNAT_Pragma;
7282 Gather_Associations (Names, Args);
7283 Process_Extended_Import_Export_Object_Pragma (
7284 Arg_Internal => Internal,
7285 Arg_External => External,
7286 Arg_Size => Size);
7287 end Export_Object;
7289 ----------------------
7290 -- Export_Procedure --
7291 ----------------------
7293 -- pragma Export_Procedure (
7294 -- [Internal =>] LOCAL_NAME
7295 -- [, [External =>] EXTERNAL_SYMBOL]
7296 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7297 -- [, [Mechanism =>] MECHANISM]);
7299 -- EXTERNAL_SYMBOL ::=
7300 -- IDENTIFIER
7301 -- | static_string_EXPRESSION
7303 -- PARAMETER_TYPES ::=
7304 -- null
7305 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7307 -- TYPE_DESIGNATOR ::=
7308 -- subtype_NAME
7309 -- | subtype_Name ' Access
7311 -- MECHANISM ::=
7312 -- MECHANISM_NAME
7313 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7315 -- MECHANISM_ASSOCIATION ::=
7316 -- [formal_parameter_NAME =>] MECHANISM_NAME
7318 -- MECHANISM_NAME ::=
7319 -- Value
7320 -- | Reference
7321 -- | Descriptor [([Class =>] CLASS_NAME)]
7323 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7325 when Pragma_Export_Procedure => Export_Procedure : declare
7326 Args : Args_List (1 .. 4);
7327 Names : constant Name_List (1 .. 4) := (
7328 Name_Internal,
7329 Name_External,
7330 Name_Parameter_Types,
7331 Name_Mechanism);
7333 Internal : Node_Id renames Args (1);
7334 External : Node_Id renames Args (2);
7335 Parameter_Types : Node_Id renames Args (3);
7336 Mechanism : Node_Id renames Args (4);
7338 begin
7339 GNAT_Pragma;
7340 Gather_Associations (Names, Args);
7341 Process_Extended_Import_Export_Subprogram_Pragma (
7342 Arg_Internal => Internal,
7343 Arg_External => External,
7344 Arg_Parameter_Types => Parameter_Types,
7345 Arg_Mechanism => Mechanism);
7346 end Export_Procedure;
7348 ------------------
7349 -- Export_Value --
7350 ------------------
7352 -- pragma Export_Value (
7353 -- [Value =>] static_integer_EXPRESSION,
7354 -- [Link_Name =>] static_string_EXPRESSION);
7356 when Pragma_Export_Value =>
7357 GNAT_Pragma;
7358 Check_Arg_Order ((Name_Value, Name_Link_Name));
7359 Check_Arg_Count (2);
7361 Check_Optional_Identifier (Arg1, Name_Value);
7362 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7364 Check_Optional_Identifier (Arg2, Name_Link_Name);
7365 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7367 -----------------------------
7368 -- Export_Valued_Procedure --
7369 -----------------------------
7371 -- pragma Export_Valued_Procedure (
7372 -- [Internal =>] LOCAL_NAME
7373 -- [, [External =>] EXTERNAL_SYMBOL,]
7374 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7375 -- [, [Mechanism =>] MECHANISM]);
7377 -- EXTERNAL_SYMBOL ::=
7378 -- IDENTIFIER
7379 -- | static_string_EXPRESSION
7381 -- PARAMETER_TYPES ::=
7382 -- null
7383 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7385 -- TYPE_DESIGNATOR ::=
7386 -- subtype_NAME
7387 -- | subtype_Name ' Access
7389 -- MECHANISM ::=
7390 -- MECHANISM_NAME
7391 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7393 -- MECHANISM_ASSOCIATION ::=
7394 -- [formal_parameter_NAME =>] MECHANISM_NAME
7396 -- MECHANISM_NAME ::=
7397 -- Value
7398 -- | Reference
7399 -- | Descriptor [([Class =>] CLASS_NAME)]
7401 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7403 when Pragma_Export_Valued_Procedure =>
7404 Export_Valued_Procedure : declare
7405 Args : Args_List (1 .. 4);
7406 Names : constant Name_List (1 .. 4) := (
7407 Name_Internal,
7408 Name_External,
7409 Name_Parameter_Types,
7410 Name_Mechanism);
7412 Internal : Node_Id renames Args (1);
7413 External : Node_Id renames Args (2);
7414 Parameter_Types : Node_Id renames Args (3);
7415 Mechanism : Node_Id renames Args (4);
7417 begin
7418 GNAT_Pragma;
7419 Gather_Associations (Names, Args);
7420 Process_Extended_Import_Export_Subprogram_Pragma (
7421 Arg_Internal => Internal,
7422 Arg_External => External,
7423 Arg_Parameter_Types => Parameter_Types,
7424 Arg_Mechanism => Mechanism);
7425 end Export_Valued_Procedure;
7427 -------------------
7428 -- Extend_System --
7429 -------------------
7431 -- pragma Extend_System ([Name =>] Identifier);
7433 when Pragma_Extend_System => Extend_System : declare
7434 begin
7435 GNAT_Pragma;
7436 Check_Valid_Configuration_Pragma;
7437 Check_Arg_Count (1);
7438 Check_Optional_Identifier (Arg1, Name_Name);
7439 Check_Arg_Is_Identifier (Arg1);
7441 Get_Name_String (Chars (Expression (Arg1)));
7443 if Name_Len > 4
7444 and then Name_Buffer (1 .. 4) = "aux_"
7445 then
7446 if Present (System_Extend_Pragma_Arg) then
7447 if Chars (Expression (Arg1)) =
7448 Chars (Expression (System_Extend_Pragma_Arg))
7449 then
7450 null;
7451 else
7452 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
7453 Error_Pragma ("pragma% conflicts with that #");
7454 end if;
7456 else
7457 System_Extend_Pragma_Arg := Arg1;
7459 if not GNAT_Mode then
7460 System_Extend_Unit := Arg1;
7461 end if;
7462 end if;
7463 else
7464 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
7465 end if;
7466 end Extend_System;
7468 ------------------------
7469 -- Extensions_Allowed --
7470 ------------------------
7472 -- pragma Extensions_Allowed (ON | OFF);
7474 when Pragma_Extensions_Allowed =>
7475 GNAT_Pragma;
7476 Check_Arg_Count (1);
7477 Check_No_Identifiers;
7478 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7480 if Chars (Expression (Arg1)) = Name_On then
7481 Extensions_Allowed := True;
7482 Ada_Version := Ada_Version_Type'Last;
7484 else
7485 Extensions_Allowed := False;
7486 Ada_Version := Ada_Version_Explicit;
7487 end if;
7489 --------------
7490 -- External --
7491 --------------
7493 -- pragma External (
7494 -- [ Convention =>] convention_IDENTIFIER,
7495 -- [ Entity =>] local_NAME
7496 -- [, [External_Name =>] static_string_EXPRESSION ]
7497 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7499 when Pragma_External => External : declare
7500 Def_Id : Entity_Id;
7502 C : Convention_Id;
7503 pragma Warnings (Off, C);
7505 begin
7506 GNAT_Pragma;
7507 Check_Arg_Order
7508 ((Name_Convention,
7509 Name_Entity,
7510 Name_External_Name,
7511 Name_Link_Name));
7512 Check_At_Least_N_Arguments (2);
7513 Check_At_Most_N_Arguments (4);
7514 Process_Convention (C, Def_Id);
7515 Note_Possible_Modification (Expression (Arg2), Sure => False);
7516 Process_Interface_Name (Def_Id, Arg3, Arg4);
7517 Set_Exported (Def_Id, Arg2);
7518 end External;
7520 --------------------------
7521 -- External_Name_Casing --
7522 --------------------------
7524 -- pragma External_Name_Casing (
7525 -- UPPERCASE | LOWERCASE
7526 -- [, AS_IS | UPPERCASE | LOWERCASE]);
7528 when Pragma_External_Name_Casing => External_Name_Casing : declare
7529 begin
7530 GNAT_Pragma;
7531 Check_No_Identifiers;
7533 if Arg_Count = 2 then
7534 Check_Arg_Is_One_Of
7535 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
7537 case Chars (Get_Pragma_Arg (Arg2)) is
7538 when Name_As_Is =>
7539 Opt.External_Name_Exp_Casing := As_Is;
7541 when Name_Uppercase =>
7542 Opt.External_Name_Exp_Casing := Uppercase;
7544 when Name_Lowercase =>
7545 Opt.External_Name_Exp_Casing := Lowercase;
7547 when others =>
7548 null;
7549 end case;
7551 else
7552 Check_Arg_Count (1);
7553 end if;
7555 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
7557 case Chars (Get_Pragma_Arg (Arg1)) is
7558 when Name_Uppercase =>
7559 Opt.External_Name_Imp_Casing := Uppercase;
7561 when Name_Lowercase =>
7562 Opt.External_Name_Imp_Casing := Lowercase;
7564 when others =>
7565 null;
7566 end case;
7567 end External_Name_Casing;
7569 --------------------------
7570 -- Favor_Top_Level --
7571 --------------------------
7573 -- pragma Favor_Top_Level (type_NAME);
7575 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
7576 Named_Entity : Entity_Id;
7578 begin
7579 GNAT_Pragma;
7580 Check_No_Identifiers;
7581 Check_Arg_Count (1);
7582 Check_Arg_Is_Local_Name (Arg1);
7583 Named_Entity := Entity (Expression (Arg1));
7585 -- If it's an access-to-subprogram type (in particular, not a
7586 -- subtype), set the flag on that type.
7588 if Is_Access_Subprogram_Type (Named_Entity) then
7589 Set_Can_Use_Internal_Rep (Named_Entity, False);
7591 -- Otherwise it's an error (name denotes the wrong sort of entity)
7593 else
7594 Error_Pragma_Arg
7595 ("access-to-subprogram type expected", Expression (Arg1));
7596 end if;
7597 end Favor_Top_Level;
7599 ---------------
7600 -- Fast_Math --
7601 ---------------
7603 -- pragma Fast_Math;
7605 when Pragma_Fast_Math =>
7606 GNAT_Pragma;
7607 Check_No_Identifiers;
7608 Check_Valid_Configuration_Pragma;
7609 Fast_Math := True;
7611 ---------------------------
7612 -- Finalize_Storage_Only --
7613 ---------------------------
7615 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
7617 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
7618 Assoc : constant Node_Id := Arg1;
7619 Type_Id : constant Node_Id := Expression (Assoc);
7620 Typ : Entity_Id;
7622 begin
7623 GNAT_Pragma;
7624 Check_No_Identifiers;
7625 Check_Arg_Count (1);
7626 Check_Arg_Is_Local_Name (Arg1);
7628 Find_Type (Type_Id);
7629 Typ := Entity (Type_Id);
7631 if Typ = Any_Type
7632 or else Rep_Item_Too_Early (Typ, N)
7633 then
7634 return;
7635 else
7636 Typ := Underlying_Type (Typ);
7637 end if;
7639 if not Is_Controlled (Typ) then
7640 Error_Pragma ("pragma% must specify controlled type");
7641 end if;
7643 Check_First_Subtype (Arg1);
7645 if Finalize_Storage_Only (Typ) then
7646 Error_Pragma ("duplicate pragma%, only one allowed");
7648 elsif not Rep_Item_Too_Late (Typ, N) then
7649 Set_Finalize_Storage_Only (Base_Type (Typ), True);
7650 end if;
7651 end Finalize_Storage;
7653 --------------------------
7654 -- Float_Representation --
7655 --------------------------
7657 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
7659 -- FLOAT_REP ::= VAX_Float | IEEE_Float
7661 when Pragma_Float_Representation => Float_Representation : declare
7662 Argx : Node_Id;
7663 Digs : Nat;
7664 Ent : Entity_Id;
7666 begin
7667 GNAT_Pragma;
7669 if Arg_Count = 1 then
7670 Check_Valid_Configuration_Pragma;
7671 else
7672 Check_Arg_Count (2);
7673 Check_Optional_Identifier (Arg2, Name_Entity);
7674 Check_Arg_Is_Local_Name (Arg2);
7675 end if;
7677 Check_No_Identifier (Arg1);
7678 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
7680 if not OpenVMS_On_Target then
7681 if Chars (Expression (Arg1)) = Name_VAX_Float then
7682 Error_Pragma
7683 ("?pragma% ignored (applies only to Open'V'M'S)");
7684 end if;
7686 return;
7687 end if;
7689 -- One argument case
7691 if Arg_Count = 1 then
7692 if Chars (Expression (Arg1)) = Name_VAX_Float then
7693 if Opt.Float_Format = 'I' then
7694 Error_Pragma ("'I'E'E'E format previously specified");
7695 end if;
7697 Opt.Float_Format := 'V';
7699 else
7700 if Opt.Float_Format = 'V' then
7701 Error_Pragma ("'V'A'X format previously specified");
7702 end if;
7704 Opt.Float_Format := 'I';
7705 end if;
7707 Set_Standard_Fpt_Formats;
7709 -- Two argument case
7711 else
7712 Argx := Get_Pragma_Arg (Arg2);
7714 if not Is_Entity_Name (Argx)
7715 or else not Is_Floating_Point_Type (Entity (Argx))
7716 then
7717 Error_Pragma_Arg
7718 ("second argument of% pragma must be floating-point type",
7719 Arg2);
7720 end if;
7722 Ent := Entity (Argx);
7723 Digs := UI_To_Int (Digits_Value (Ent));
7725 -- Two arguments, VAX_Float case
7727 if Chars (Expression (Arg1)) = Name_VAX_Float then
7728 case Digs is
7729 when 6 => Set_F_Float (Ent);
7730 when 9 => Set_D_Float (Ent);
7731 when 15 => Set_G_Float (Ent);
7733 when others =>
7734 Error_Pragma_Arg
7735 ("wrong digits value, must be 6,9 or 15", Arg2);
7736 end case;
7738 -- Two arguments, IEEE_Float case
7740 else
7741 case Digs is
7742 when 6 => Set_IEEE_Short (Ent);
7743 when 15 => Set_IEEE_Long (Ent);
7745 when others =>
7746 Error_Pragma_Arg
7747 ("wrong digits value, must be 6 or 15", Arg2);
7748 end case;
7749 end if;
7750 end if;
7751 end Float_Representation;
7753 -----------
7754 -- Ident --
7755 -----------
7757 -- pragma Ident (static_string_EXPRESSION)
7759 -- Note: pragma Comment shares this processing. Pragma Comment is
7760 -- identical to Ident, except that the restriction of the argument to
7761 -- 31 characters and the placement restrictions are not enforced for
7762 -- pragma Comment.
7764 when Pragma_Ident | Pragma_Comment => Ident : declare
7765 Str : Node_Id;
7767 begin
7768 GNAT_Pragma;
7769 Check_Arg_Count (1);
7770 Check_No_Identifiers;
7771 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7772 Store_Note (N);
7774 -- For pragma Ident, preserve DEC compatibility by requiring the
7775 -- pragma to appear in a declarative part or package spec.
7777 if Prag_Id = Pragma_Ident then
7778 Check_Is_In_Decl_Part_Or_Package_Spec;
7779 end if;
7781 Str := Expr_Value_S (Expression (Arg1));
7783 declare
7784 CS : Node_Id;
7785 GP : Node_Id;
7787 begin
7788 GP := Parent (Parent (N));
7790 if Nkind_In (GP, N_Package_Declaration,
7791 N_Generic_Package_Declaration)
7792 then
7793 GP := Parent (GP);
7794 end if;
7796 -- If we have a compilation unit, then record the ident value,
7797 -- checking for improper duplication.
7799 if Nkind (GP) = N_Compilation_Unit then
7800 CS := Ident_String (Current_Sem_Unit);
7802 if Present (CS) then
7804 -- For Ident, we do not permit multiple instances
7806 if Prag_Id = Pragma_Ident then
7807 Error_Pragma ("duplicate% pragma not permitted");
7809 -- For Comment, we concatenate the string, unless we want
7810 -- to preserve the tree structure for ASIS.
7812 elsif not ASIS_Mode then
7813 Start_String (Strval (CS));
7814 Store_String_Char (' ');
7815 Store_String_Chars (Strval (Str));
7816 Set_Strval (CS, End_String);
7817 end if;
7819 else
7820 -- In VMS, the effect of IDENT is achieved by passing
7821 -- IDENTIFICATION=name as a --for-linker switch.
7823 if OpenVMS_On_Target then
7824 Start_String;
7825 Store_String_Chars
7826 ("--for-linker=IDENTIFICATION=");
7827 String_To_Name_Buffer (Strval (Str));
7828 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7830 -- Only the last processed IDENT is saved. The main
7831 -- purpose is so an IDENT associated with a main
7832 -- procedure will be used in preference to an IDENT
7833 -- associated with a with'd package.
7835 Replace_Linker_Option_String
7836 (End_String, "--for-linker=IDENTIFICATION=");
7837 end if;
7839 Set_Ident_String (Current_Sem_Unit, Str);
7840 end if;
7842 -- For subunits, we just ignore the Ident, since in GNAT these
7843 -- are not separate object files, and hence not separate units
7844 -- in the unit table.
7846 elsif Nkind (GP) = N_Subunit then
7847 null;
7849 -- Otherwise we have a misplaced pragma Ident, but we ignore
7850 -- this if we are in an instantiation, since it comes from
7851 -- a generic, and has no relevance to the instantiation.
7853 elsif Prag_Id = Pragma_Ident then
7854 if Instantiation_Location (Loc) = No_Location then
7855 Error_Pragma ("pragma% only allowed at outer level");
7856 end if;
7857 end if;
7858 end;
7859 end Ident;
7861 --------------------------
7862 -- Implemented_By_Entry --
7863 --------------------------
7865 -- pragma Implemented_By_Entry (DIRECT_NAME);
7867 when Pragma_Implemented_By_Entry => Implemented_By_Entry : declare
7868 Ent : Entity_Id;
7870 begin
7871 Ada_2005_Pragma;
7872 Check_Arg_Count (1);
7873 Check_No_Identifiers;
7874 Check_Arg_Is_Identifier (Arg1);
7875 Check_Arg_Is_Local_Name (Arg1);
7876 Ent := Entity (Expression (Arg1));
7878 -- Pragma Implemented_By_Entry must be applied only to protected
7879 -- synchronized or task interface primitives.
7881 if (Ekind (Ent) /= E_Function
7882 and then Ekind (Ent) /= E_Procedure)
7883 or else not Present (First_Formal (Ent))
7884 or else not Is_Concurrent_Interface (Etype (First_Formal (Ent)))
7885 then
7886 Error_Pragma_Arg
7887 ("pragma % must be applied to a concurrent interface " &
7888 "primitive", Arg1);
7890 else
7891 if Einfo.Implemented_By_Entry (Ent)
7892 and then Warn_On_Redundant_Constructs
7893 then
7894 Error_Pragma ("?duplicate pragma%!");
7895 else
7896 Set_Implemented_By_Entry (Ent);
7897 end if;
7898 end if;
7899 end Implemented_By_Entry;
7901 -----------------------
7902 -- Implicit_Packing --
7903 -----------------------
7905 -- pragma Implicit_Packing;
7907 when Pragma_Implicit_Packing =>
7908 GNAT_Pragma;
7909 Check_Arg_Count (0);
7910 Implicit_Packing := True;
7912 ------------
7913 -- Import --
7914 ------------
7916 -- pragma Import (
7917 -- [Convention =>] convention_IDENTIFIER,
7918 -- [Entity =>] local_NAME
7919 -- [, [External_Name =>] static_string_EXPRESSION ]
7920 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7922 when Pragma_Import =>
7923 Check_Ada_83_Warning;
7924 Check_Arg_Order
7925 ((Name_Convention,
7926 Name_Entity,
7927 Name_External_Name,
7928 Name_Link_Name));
7929 Check_At_Least_N_Arguments (2);
7930 Check_At_Most_N_Arguments (4);
7931 Process_Import_Or_Interface;
7933 ----------------------
7934 -- Import_Exception --
7935 ----------------------
7937 -- pragma Import_Exception (
7938 -- [Internal =>] LOCAL_NAME
7939 -- [, [External =>] EXTERNAL_SYMBOL]
7940 -- [, [Form =>] Ada | VMS]
7941 -- [, [Code =>] static_integer_EXPRESSION]);
7943 when Pragma_Import_Exception => Import_Exception : declare
7944 Args : Args_List (1 .. 4);
7945 Names : constant Name_List (1 .. 4) := (
7946 Name_Internal,
7947 Name_External,
7948 Name_Form,
7949 Name_Code);
7951 Internal : Node_Id renames Args (1);
7952 External : Node_Id renames Args (2);
7953 Form : Node_Id renames Args (3);
7954 Code : Node_Id renames Args (4);
7956 begin
7957 GNAT_Pragma;
7958 Gather_Associations (Names, Args);
7960 if Present (External) and then Present (Code) then
7961 Error_Pragma
7962 ("cannot give both External and Code options for pragma%");
7963 end if;
7965 Process_Extended_Import_Export_Exception_Pragma (
7966 Arg_Internal => Internal,
7967 Arg_External => External,
7968 Arg_Form => Form,
7969 Arg_Code => Code);
7971 if not Is_VMS_Exception (Entity (Internal)) then
7972 Set_Imported (Entity (Internal));
7973 end if;
7974 end Import_Exception;
7976 ---------------------
7977 -- Import_Function --
7978 ---------------------
7980 -- pragma Import_Function (
7981 -- [Internal =>] LOCAL_NAME,
7982 -- [, [External =>] EXTERNAL_SYMBOL]
7983 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7984 -- [, [Result_Type =>] SUBTYPE_MARK]
7985 -- [, [Mechanism =>] MECHANISM]
7986 -- [, [Result_Mechanism =>] MECHANISM_NAME]
7987 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7989 -- EXTERNAL_SYMBOL ::=
7990 -- IDENTIFIER
7991 -- | static_string_EXPRESSION
7993 -- PARAMETER_TYPES ::=
7994 -- null
7995 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7997 -- TYPE_DESIGNATOR ::=
7998 -- subtype_NAME
7999 -- | subtype_Name ' Access
8001 -- MECHANISM ::=
8002 -- MECHANISM_NAME
8003 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8005 -- MECHANISM_ASSOCIATION ::=
8006 -- [formal_parameter_NAME =>] MECHANISM_NAME
8008 -- MECHANISM_NAME ::=
8009 -- Value
8010 -- | Reference
8011 -- | Descriptor [([Class =>] CLASS_NAME)]
8013 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8015 when Pragma_Import_Function => Import_Function : declare
8016 Args : Args_List (1 .. 7);
8017 Names : constant Name_List (1 .. 7) := (
8018 Name_Internal,
8019 Name_External,
8020 Name_Parameter_Types,
8021 Name_Result_Type,
8022 Name_Mechanism,
8023 Name_Result_Mechanism,
8024 Name_First_Optional_Parameter);
8026 Internal : Node_Id renames Args (1);
8027 External : Node_Id renames Args (2);
8028 Parameter_Types : Node_Id renames Args (3);
8029 Result_Type : Node_Id renames Args (4);
8030 Mechanism : Node_Id renames Args (5);
8031 Result_Mechanism : Node_Id renames Args (6);
8032 First_Optional_Parameter : Node_Id renames Args (7);
8034 begin
8035 GNAT_Pragma;
8036 Gather_Associations (Names, Args);
8037 Process_Extended_Import_Export_Subprogram_Pragma (
8038 Arg_Internal => Internal,
8039 Arg_External => External,
8040 Arg_Parameter_Types => Parameter_Types,
8041 Arg_Result_Type => Result_Type,
8042 Arg_Mechanism => Mechanism,
8043 Arg_Result_Mechanism => Result_Mechanism,
8044 Arg_First_Optional_Parameter => First_Optional_Parameter);
8045 end Import_Function;
8047 -------------------
8048 -- Import_Object --
8049 -------------------
8051 -- pragma Import_Object (
8052 -- [Internal =>] LOCAL_NAME
8053 -- [, [External =>] EXTERNAL_SYMBOL]
8054 -- [, [Size =>] EXTERNAL_SYMBOL]);
8056 -- EXTERNAL_SYMBOL ::=
8057 -- IDENTIFIER
8058 -- | static_string_EXPRESSION
8060 when Pragma_Import_Object => Import_Object : declare
8061 Args : Args_List (1 .. 3);
8062 Names : constant Name_List (1 .. 3) := (
8063 Name_Internal,
8064 Name_External,
8065 Name_Size);
8067 Internal : Node_Id renames Args (1);
8068 External : Node_Id renames Args (2);
8069 Size : Node_Id renames Args (3);
8071 begin
8072 GNAT_Pragma;
8073 Gather_Associations (Names, Args);
8074 Process_Extended_Import_Export_Object_Pragma (
8075 Arg_Internal => Internal,
8076 Arg_External => External,
8077 Arg_Size => Size);
8078 end Import_Object;
8080 ----------------------
8081 -- Import_Procedure --
8082 ----------------------
8084 -- pragma Import_Procedure (
8085 -- [Internal =>] LOCAL_NAME
8086 -- [, [External =>] EXTERNAL_SYMBOL]
8087 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8088 -- [, [Mechanism =>] MECHANISM]
8089 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8091 -- EXTERNAL_SYMBOL ::=
8092 -- IDENTIFIER
8093 -- | static_string_EXPRESSION
8095 -- PARAMETER_TYPES ::=
8096 -- null
8097 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8099 -- TYPE_DESIGNATOR ::=
8100 -- subtype_NAME
8101 -- | subtype_Name ' Access
8103 -- MECHANISM ::=
8104 -- MECHANISM_NAME
8105 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8107 -- MECHANISM_ASSOCIATION ::=
8108 -- [formal_parameter_NAME =>] MECHANISM_NAME
8110 -- MECHANISM_NAME ::=
8111 -- Value
8112 -- | Reference
8113 -- | Descriptor [([Class =>] CLASS_NAME)]
8115 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8117 when Pragma_Import_Procedure => Import_Procedure : declare
8118 Args : Args_List (1 .. 5);
8119 Names : constant Name_List (1 .. 5) := (
8120 Name_Internal,
8121 Name_External,
8122 Name_Parameter_Types,
8123 Name_Mechanism,
8124 Name_First_Optional_Parameter);
8126 Internal : Node_Id renames Args (1);
8127 External : Node_Id renames Args (2);
8128 Parameter_Types : Node_Id renames Args (3);
8129 Mechanism : Node_Id renames Args (4);
8130 First_Optional_Parameter : Node_Id renames Args (5);
8132 begin
8133 GNAT_Pragma;
8134 Gather_Associations (Names, Args);
8135 Process_Extended_Import_Export_Subprogram_Pragma (
8136 Arg_Internal => Internal,
8137 Arg_External => External,
8138 Arg_Parameter_Types => Parameter_Types,
8139 Arg_Mechanism => Mechanism,
8140 Arg_First_Optional_Parameter => First_Optional_Parameter);
8141 end Import_Procedure;
8143 -----------------------------
8144 -- Import_Valued_Procedure --
8145 -----------------------------
8147 -- pragma Import_Valued_Procedure (
8148 -- [Internal =>] LOCAL_NAME
8149 -- [, [External =>] EXTERNAL_SYMBOL]
8150 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8151 -- [, [Mechanism =>] MECHANISM]
8152 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8154 -- EXTERNAL_SYMBOL ::=
8155 -- IDENTIFIER
8156 -- | static_string_EXPRESSION
8158 -- PARAMETER_TYPES ::=
8159 -- null
8160 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8162 -- TYPE_DESIGNATOR ::=
8163 -- subtype_NAME
8164 -- | subtype_Name ' Access
8166 -- MECHANISM ::=
8167 -- MECHANISM_NAME
8168 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8170 -- MECHANISM_ASSOCIATION ::=
8171 -- [formal_parameter_NAME =>] MECHANISM_NAME
8173 -- MECHANISM_NAME ::=
8174 -- Value
8175 -- | Reference
8176 -- | Descriptor [([Class =>] CLASS_NAME)]
8178 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8180 when Pragma_Import_Valued_Procedure =>
8181 Import_Valued_Procedure : declare
8182 Args : Args_List (1 .. 5);
8183 Names : constant Name_List (1 .. 5) := (
8184 Name_Internal,
8185 Name_External,
8186 Name_Parameter_Types,
8187 Name_Mechanism,
8188 Name_First_Optional_Parameter);
8190 Internal : Node_Id renames Args (1);
8191 External : Node_Id renames Args (2);
8192 Parameter_Types : Node_Id renames Args (3);
8193 Mechanism : Node_Id renames Args (4);
8194 First_Optional_Parameter : Node_Id renames Args (5);
8196 begin
8197 GNAT_Pragma;
8198 Gather_Associations (Names, Args);
8199 Process_Extended_Import_Export_Subprogram_Pragma (
8200 Arg_Internal => Internal,
8201 Arg_External => External,
8202 Arg_Parameter_Types => Parameter_Types,
8203 Arg_Mechanism => Mechanism,
8204 Arg_First_Optional_Parameter => First_Optional_Parameter);
8205 end Import_Valued_Procedure;
8207 ------------------------
8208 -- Initialize_Scalars --
8209 ------------------------
8211 -- pragma Initialize_Scalars;
8213 when Pragma_Initialize_Scalars =>
8214 GNAT_Pragma;
8215 Check_Arg_Count (0);
8216 Check_Valid_Configuration_Pragma;
8217 Check_Restriction (No_Initialize_Scalars, N);
8219 -- Initialize_Scalars creates false positives in CodePeer,
8220 -- so ignore this pragma in this mode.
8222 if not Restriction_Active (No_Initialize_Scalars)
8223 and then not CodePeer_Mode
8224 then
8225 Init_Or_Norm_Scalars := True;
8226 Initialize_Scalars := True;
8227 end if;
8229 ------------
8230 -- Inline --
8231 ------------
8233 -- pragma Inline ( NAME {, NAME} );
8235 when Pragma_Inline =>
8237 -- Pragma is active if inlining option is active
8239 Process_Inline (Inline_Active);
8241 -------------------
8242 -- Inline_Always --
8243 -------------------
8245 -- pragma Inline_Always ( NAME {, NAME} );
8247 when Pragma_Inline_Always =>
8248 GNAT_Pragma;
8249 Process_Inline (True);
8251 --------------------
8252 -- Inline_Generic --
8253 --------------------
8255 -- pragma Inline_Generic (NAME {, NAME});
8257 when Pragma_Inline_Generic =>
8258 GNAT_Pragma;
8259 Process_Generic_List;
8261 ----------------------
8262 -- Inspection_Point --
8263 ----------------------
8265 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
8267 when Pragma_Inspection_Point => Inspection_Point : declare
8268 Arg : Node_Id;
8269 Exp : Node_Id;
8271 begin
8272 if Arg_Count > 0 then
8273 Arg := Arg1;
8274 loop
8275 Exp := Expression (Arg);
8276 Analyze (Exp);
8278 if not Is_Entity_Name (Exp)
8279 or else not Is_Object (Entity (Exp))
8280 then
8281 Error_Pragma_Arg ("object name required", Arg);
8282 end if;
8284 Next (Arg);
8285 exit when No (Arg);
8286 end loop;
8287 end if;
8288 end Inspection_Point;
8290 ---------------
8291 -- Interface --
8292 ---------------
8294 -- pragma Interface (
8295 -- [ Convention =>] convention_IDENTIFIER,
8296 -- [ Entity =>] local_NAME
8297 -- [, [External_Name =>] static_string_EXPRESSION ]
8298 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8300 when Pragma_Interface =>
8301 GNAT_Pragma;
8302 Check_Arg_Order
8303 ((Name_Convention,
8304 Name_Entity,
8305 Name_External_Name,
8306 Name_Link_Name));
8307 Check_At_Least_N_Arguments (2);
8308 Check_At_Most_N_Arguments (4);
8309 Process_Import_Or_Interface;
8311 --------------------
8312 -- Interface_Name --
8313 --------------------
8315 -- pragma Interface_Name (
8316 -- [ Entity =>] local_NAME
8317 -- [,[External_Name =>] static_string_EXPRESSION ]
8318 -- [,[Link_Name =>] static_string_EXPRESSION ]);
8320 when Pragma_Interface_Name => Interface_Name : declare
8321 Id : Node_Id;
8322 Def_Id : Entity_Id;
8323 Hom_Id : Entity_Id;
8324 Found : Boolean;
8326 begin
8327 GNAT_Pragma;
8328 Check_Arg_Order
8329 ((Name_Entity, Name_External_Name, Name_Link_Name));
8330 Check_At_Least_N_Arguments (2);
8331 Check_At_Most_N_Arguments (3);
8332 Id := Expression (Arg1);
8333 Analyze (Id);
8335 if not Is_Entity_Name (Id) then
8336 Error_Pragma_Arg
8337 ("first argument for pragma% must be entity name", Arg1);
8338 elsif Etype (Id) = Any_Type then
8339 return;
8340 else
8341 Def_Id := Entity (Id);
8342 end if;
8344 -- Special DEC-compatible processing for the object case, forces
8345 -- object to be imported.
8347 if Ekind (Def_Id) = E_Variable then
8348 Kill_Size_Check_Code (Def_Id);
8349 Note_Possible_Modification (Id, Sure => False);
8351 -- Initialization is not allowed for imported variable
8353 if Present (Expression (Parent (Def_Id)))
8354 and then Comes_From_Source (Expression (Parent (Def_Id)))
8355 then
8356 Error_Msg_Sloc := Sloc (Def_Id);
8357 Error_Pragma_Arg
8358 ("no initialization allowed for declaration of& #",
8359 Arg2);
8361 else
8362 -- For compatibility, support VADS usage of providing both
8363 -- pragmas Interface and Interface_Name to obtain the effect
8364 -- of a single Import pragma.
8366 if Is_Imported (Def_Id)
8367 and then Present (First_Rep_Item (Def_Id))
8368 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
8369 and then
8370 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
8371 then
8372 null;
8373 else
8374 Set_Imported (Def_Id);
8375 end if;
8377 Set_Is_Public (Def_Id);
8378 Process_Interface_Name (Def_Id, Arg2, Arg3);
8379 end if;
8381 -- Otherwise must be subprogram
8383 elsif not Is_Subprogram (Def_Id) then
8384 Error_Pragma_Arg
8385 ("argument of pragma% is not subprogram", Arg1);
8387 else
8388 Check_At_Most_N_Arguments (3);
8389 Hom_Id := Def_Id;
8390 Found := False;
8392 -- Loop through homonyms
8394 loop
8395 Def_Id := Get_Base_Subprogram (Hom_Id);
8397 if Is_Imported (Def_Id) then
8398 Process_Interface_Name (Def_Id, Arg2, Arg3);
8399 Found := True;
8400 end if;
8402 Hom_Id := Homonym (Hom_Id);
8404 exit when No (Hom_Id)
8405 or else Scope (Hom_Id) /= Current_Scope;
8406 end loop;
8408 if not Found then
8409 Error_Pragma_Arg
8410 ("argument of pragma% is not imported subprogram",
8411 Arg1);
8412 end if;
8413 end if;
8414 end Interface_Name;
8416 -----------------------
8417 -- Interrupt_Handler --
8418 -----------------------
8420 -- pragma Interrupt_Handler (handler_NAME);
8422 when Pragma_Interrupt_Handler =>
8423 Check_Ada_83_Warning;
8424 Check_Arg_Count (1);
8425 Check_No_Identifiers;
8427 if No_Run_Time_Mode then
8428 Error_Msg_CRT ("Interrupt_Handler pragma", N);
8429 else
8430 Check_Interrupt_Or_Attach_Handler;
8431 Process_Interrupt_Or_Attach_Handler;
8432 end if;
8434 ------------------------
8435 -- Interrupt_Priority --
8436 ------------------------
8438 -- pragma Interrupt_Priority [(EXPRESSION)];
8440 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
8441 P : constant Node_Id := Parent (N);
8442 Arg : Node_Id;
8444 begin
8445 Check_Ada_83_Warning;
8447 if Arg_Count /= 0 then
8448 Arg := Expression (Arg1);
8449 Check_Arg_Count (1);
8450 Check_No_Identifiers;
8452 -- The expression must be analyzed in the special manner
8453 -- described in "Handling of Default and Per-Object
8454 -- Expressions" in sem.ads.
8456 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
8457 end if;
8459 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
8460 Pragma_Misplaced;
8461 return;
8463 elsif Has_Priority_Pragma (P) then
8464 Error_Pragma ("duplicate pragma% not allowed");
8466 else
8467 Set_Has_Priority_Pragma (P, True);
8468 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8469 end if;
8470 end Interrupt_Priority;
8472 ---------------------
8473 -- Interrupt_State --
8474 ---------------------
8476 -- pragma Interrupt_State (
8477 -- [Name =>] INTERRUPT_ID,
8478 -- [State =>] INTERRUPT_STATE);
8480 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
8481 -- INTERRUPT_STATE => System | Runtime | User
8483 -- Note: if the interrupt id is given as an identifier, then it must
8484 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
8485 -- given as a static integer expression which must be in the range of
8486 -- Ada.Interrupts.Interrupt_ID.
8488 when Pragma_Interrupt_State => Interrupt_State : declare
8490 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
8491 -- This is the entity Ada.Interrupts.Interrupt_ID;
8493 State_Type : Character;
8494 -- Set to 's'/'r'/'u' for System/Runtime/User
8496 IST_Num : Pos;
8497 -- Index to entry in Interrupt_States table
8499 Int_Val : Uint;
8500 -- Value of interrupt
8502 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
8503 -- The first argument to the pragma
8505 Int_Ent : Entity_Id;
8506 -- Interrupt entity in Ada.Interrupts.Names
8508 begin
8509 GNAT_Pragma;
8510 Check_Arg_Order ((Name_Name, Name_State));
8511 Check_Arg_Count (2);
8513 Check_Optional_Identifier (Arg1, Name_Name);
8514 Check_Optional_Identifier (Arg2, Name_State);
8515 Check_Arg_Is_Identifier (Arg2);
8517 -- First argument is identifier
8519 if Nkind (Arg1X) = N_Identifier then
8521 -- Search list of names in Ada.Interrupts.Names
8523 Int_Ent := First_Entity (RTE (RE_Names));
8524 loop
8525 if No (Int_Ent) then
8526 Error_Pragma_Arg ("invalid interrupt name", Arg1);
8528 elsif Chars (Int_Ent) = Chars (Arg1X) then
8529 Int_Val := Expr_Value (Constant_Value (Int_Ent));
8530 exit;
8531 end if;
8533 Next_Entity (Int_Ent);
8534 end loop;
8536 -- First argument is not an identifier, so it must be a static
8537 -- expression of type Ada.Interrupts.Interrupt_ID.
8539 else
8540 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8541 Int_Val := Expr_Value (Arg1X);
8543 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
8544 or else
8545 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
8546 then
8547 Error_Pragma_Arg
8548 ("value not in range of type " &
8549 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
8550 end if;
8551 end if;
8553 -- Check OK state
8555 case Chars (Get_Pragma_Arg (Arg2)) is
8556 when Name_Runtime => State_Type := 'r';
8557 when Name_System => State_Type := 's';
8558 when Name_User => State_Type := 'u';
8560 when others =>
8561 Error_Pragma_Arg ("invalid interrupt state", Arg2);
8562 end case;
8564 -- Check if entry is already stored
8566 IST_Num := Interrupt_States.First;
8567 loop
8568 -- If entry not found, add it
8570 if IST_Num > Interrupt_States.Last then
8571 Interrupt_States.Append
8572 ((Interrupt_Number => UI_To_Int (Int_Val),
8573 Interrupt_State => State_Type,
8574 Pragma_Loc => Loc));
8575 exit;
8577 -- Case of entry for the same entry
8579 elsif Int_Val = Interrupt_States.Table (IST_Num).
8580 Interrupt_Number
8581 then
8582 -- If state matches, done, no need to make redundant entry
8584 exit when
8585 State_Type = Interrupt_States.Table (IST_Num).
8586 Interrupt_State;
8588 -- Otherwise if state does not match, error
8590 Error_Msg_Sloc :=
8591 Interrupt_States.Table (IST_Num).Pragma_Loc;
8592 Error_Pragma_Arg
8593 ("state conflicts with that given #", Arg2);
8594 exit;
8595 end if;
8597 IST_Num := IST_Num + 1;
8598 end loop;
8599 end Interrupt_State;
8601 ----------------------
8602 -- Java_Constructor --
8603 ----------------------
8605 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
8607 -- Also handles pragma CIL_Constructor
8609 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
8610 Java_Constructor : declare
8611 Id : Entity_Id;
8612 Def_Id : Entity_Id;
8613 Hom_Id : Entity_Id;
8614 Convention : Convention_Id;
8616 begin
8617 GNAT_Pragma;
8618 Check_Arg_Count (1);
8619 Check_Optional_Identifier (Arg1, Name_Entity);
8620 Check_Arg_Is_Local_Name (Arg1);
8622 Id := Expression (Arg1);
8623 Find_Program_Unit_Name (Id);
8625 -- If we did not find the name, we are done
8627 if Etype (Id) = Any_Type then
8628 return;
8629 end if;
8631 case Prag_Id is
8632 when Pragma_CIL_Constructor => Convention := Convention_CIL;
8633 when Pragma_Java_Constructor => Convention := Convention_Java;
8634 when others => null;
8635 end case;
8637 Hom_Id := Entity (Id);
8639 -- Loop through homonyms
8641 loop
8642 Def_Id := Get_Base_Subprogram (Hom_Id);
8644 -- The constructor is required to be a function returning an
8645 -- access type whose designated type has convention Java/CIL.
8647 if Ekind (Def_Id) = E_Function
8648 and then
8649 (Is_Value_Type (Etype (Def_Id))
8650 or else
8651 (Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
8652 and then
8653 Atree.Convention (Etype (Def_Id)) = Convention)
8654 or else
8655 (Ekind (Etype (Def_Id)) in Access_Kind
8656 and then
8657 (Atree.Convention
8658 (Designated_Type (Etype (Def_Id))) = Convention
8659 or else
8660 Atree.Convention
8661 (Root_Type (Designated_Type (Etype (Def_Id)))) =
8662 Convention)))
8663 then
8664 Set_Is_Constructor (Def_Id);
8665 Set_Convention (Def_Id, Convention);
8666 Set_Is_Imported (Def_Id);
8668 else
8669 if Convention = Convention_Java then
8670 Error_Pragma_Arg
8671 ("pragma% requires function returning a " &
8672 "'Java access type", Arg1);
8673 else
8674 pragma Assert (Convention = Convention_CIL);
8675 Error_Pragma_Arg
8676 ("pragma% requires function returning a " &
8677 "'C'I'L access type", Arg1);
8678 end if;
8679 end if;
8681 Hom_Id := Homonym (Hom_Id);
8683 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
8684 end loop;
8685 end Java_Constructor;
8687 ----------------------
8688 -- Java_Interface --
8689 ----------------------
8691 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
8693 when Pragma_Java_Interface => Java_Interface : declare
8694 Arg : Node_Id;
8695 Typ : Entity_Id;
8697 begin
8698 GNAT_Pragma;
8699 Check_Arg_Count (1);
8700 Check_Optional_Identifier (Arg1, Name_Entity);
8701 Check_Arg_Is_Local_Name (Arg1);
8703 Arg := Expression (Arg1);
8704 Analyze (Arg);
8706 if Etype (Arg) = Any_Type then
8707 return;
8708 end if;
8710 if not Is_Entity_Name (Arg)
8711 or else not Is_Type (Entity (Arg))
8712 then
8713 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
8714 end if;
8716 Typ := Underlying_Type (Entity (Arg));
8718 -- For now simply check some of the semantic constraints on the
8719 -- type. This currently leaves out some restrictions on interface
8720 -- types, namely that the parent type must be java.lang.Object.Typ
8721 -- and that all primitives of the type should be declared
8722 -- abstract. ???
8724 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
8725 Error_Pragma_Arg ("pragma% requires an abstract "
8726 & "tagged type", Arg1);
8728 elsif not Has_Discriminants (Typ)
8729 or else Ekind (Etype (First_Discriminant (Typ)))
8730 /= E_Anonymous_Access_Type
8731 or else
8732 not Is_Class_Wide_Type
8733 (Designated_Type (Etype (First_Discriminant (Typ))))
8734 then
8735 Error_Pragma_Arg
8736 ("type must have a class-wide access discriminant", Arg1);
8737 end if;
8738 end Java_Interface;
8740 ----------------
8741 -- Keep_Names --
8742 ----------------
8744 -- pragma Keep_Names ([On => ] local_NAME);
8746 when Pragma_Keep_Names => Keep_Names : declare
8747 Arg : Node_Id;
8749 begin
8750 GNAT_Pragma;
8751 Check_Arg_Count (1);
8752 Check_Optional_Identifier (Arg1, Name_On);
8753 Check_Arg_Is_Local_Name (Arg1);
8755 Arg := Expression (Arg1);
8756 Analyze (Arg);
8758 if Etype (Arg) = Any_Type then
8759 return;
8760 end if;
8762 if not Is_Entity_Name (Arg)
8763 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
8764 then
8765 Error_Pragma_Arg
8766 ("pragma% requires a local enumeration type", Arg1);
8767 end if;
8769 Set_Discard_Names (Entity (Arg), False);
8770 end Keep_Names;
8772 -------------
8773 -- License --
8774 -------------
8776 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
8778 when Pragma_License =>
8779 GNAT_Pragma;
8780 Check_Arg_Count (1);
8781 Check_No_Identifiers;
8782 Check_Valid_Configuration_Pragma;
8783 Check_Arg_Is_Identifier (Arg1);
8785 declare
8786 Sind : constant Source_File_Index :=
8787 Source_Index (Current_Sem_Unit);
8789 begin
8790 case Chars (Get_Pragma_Arg (Arg1)) is
8791 when Name_GPL =>
8792 Set_License (Sind, GPL);
8794 when Name_Modified_GPL =>
8795 Set_License (Sind, Modified_GPL);
8797 when Name_Restricted =>
8798 Set_License (Sind, Restricted);
8800 when Name_Unrestricted =>
8801 Set_License (Sind, Unrestricted);
8803 when others =>
8804 Error_Pragma_Arg ("invalid license name", Arg1);
8805 end case;
8806 end;
8808 ---------------
8809 -- Link_With --
8810 ---------------
8812 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
8814 when Pragma_Link_With => Link_With : declare
8815 Arg : Node_Id;
8817 begin
8818 GNAT_Pragma;
8820 if Operating_Mode = Generate_Code
8821 and then In_Extended_Main_Source_Unit (N)
8822 then
8823 Check_At_Least_N_Arguments (1);
8824 Check_No_Identifiers;
8825 Check_Is_In_Decl_Part_Or_Package_Spec;
8826 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8827 Start_String;
8829 Arg := Arg1;
8830 while Present (Arg) loop
8831 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8833 -- Store argument, converting sequences of spaces to a
8834 -- single null character (this is one of the differences
8835 -- in processing between Link_With and Linker_Options).
8837 Arg_Store : declare
8838 C : constant Char_Code := Get_Char_Code (' ');
8839 S : constant String_Id :=
8840 Strval (Expr_Value_S (Expression (Arg)));
8841 L : constant Nat := String_Length (S);
8842 F : Nat := 1;
8844 procedure Skip_Spaces;
8845 -- Advance F past any spaces
8847 -----------------
8848 -- Skip_Spaces --
8849 -----------------
8851 procedure Skip_Spaces is
8852 begin
8853 while F <= L and then Get_String_Char (S, F) = C loop
8854 F := F + 1;
8855 end loop;
8856 end Skip_Spaces;
8858 -- Start of processing for Arg_Store
8860 begin
8861 Skip_Spaces; -- skip leading spaces
8863 -- Loop through characters, changing any embedded
8864 -- sequence of spaces to a single null character (this
8865 -- is how Link_With/Linker_Options differ)
8867 while F <= L loop
8868 if Get_String_Char (S, F) = C then
8869 Skip_Spaces;
8870 exit when F > L;
8871 Store_String_Char (ASCII.NUL);
8873 else
8874 Store_String_Char (Get_String_Char (S, F));
8875 F := F + 1;
8876 end if;
8877 end loop;
8878 end Arg_Store;
8880 Arg := Next (Arg);
8882 if Present (Arg) then
8883 Store_String_Char (ASCII.NUL);
8884 end if;
8885 end loop;
8887 Store_Linker_Option_String (End_String);
8888 end if;
8889 end Link_With;
8891 ------------------
8892 -- Linker_Alias --
8893 ------------------
8895 -- pragma Linker_Alias (
8896 -- [Entity =>] LOCAL_NAME
8897 -- [Target =>] static_string_EXPRESSION);
8899 when Pragma_Linker_Alias =>
8900 GNAT_Pragma;
8901 Check_Arg_Order ((Name_Entity, Name_Target));
8902 Check_Arg_Count (2);
8903 Check_Optional_Identifier (Arg1, Name_Entity);
8904 Check_Optional_Identifier (Arg2, Name_Target);
8905 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8906 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8908 -- The only processing required is to link this item on to the
8909 -- list of rep items for the given entity. This is accomplished
8910 -- by the call to Rep_Item_Too_Late (when no error is detected
8911 -- and False is returned).
8913 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8914 return;
8915 else
8916 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8917 end if;
8919 ------------------------
8920 -- Linker_Constructor --
8921 ------------------------
8923 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
8925 -- Code is shared with Linker_Destructor
8927 -----------------------
8928 -- Linker_Destructor --
8929 -----------------------
8931 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
8933 when Pragma_Linker_Constructor |
8934 Pragma_Linker_Destructor =>
8935 Linker_Constructor : declare
8936 Arg1_X : Node_Id;
8937 Proc : Entity_Id;
8939 begin
8940 GNAT_Pragma;
8941 Check_Arg_Count (1);
8942 Check_No_Identifiers;
8943 Check_Arg_Is_Local_Name (Arg1);
8944 Arg1_X := Expression (Arg1);
8945 Analyze (Arg1_X);
8946 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
8948 if not Is_Library_Level_Entity (Proc) then
8949 Error_Pragma_Arg
8950 ("argument for pragma% must be library level entity", Arg1);
8951 end if;
8953 -- The only processing required is to link this item on to the
8954 -- list of rep items for the given entity. This is accomplished
8955 -- by the call to Rep_Item_Too_Late (when no error is detected
8956 -- and False is returned).
8958 if Rep_Item_Too_Late (Proc, N) then
8959 return;
8960 else
8961 Set_Has_Gigi_Rep_Item (Proc);
8962 end if;
8963 end Linker_Constructor;
8965 --------------------
8966 -- Linker_Options --
8967 --------------------
8969 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
8971 when Pragma_Linker_Options => Linker_Options : declare
8972 Arg : Node_Id;
8974 begin
8975 Check_Ada_83_Warning;
8976 Check_No_Identifiers;
8977 Check_Arg_Count (1);
8978 Check_Is_In_Decl_Part_Or_Package_Spec;
8979 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8980 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
8982 Arg := Arg2;
8983 while Present (Arg) loop
8984 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8985 Store_String_Char (ASCII.NUL);
8986 Store_String_Chars (Strval (Expr_Value_S (Expression (Arg))));
8987 Arg := Next (Arg);
8988 end loop;
8990 if Operating_Mode = Generate_Code
8991 and then In_Extended_Main_Source_Unit (N)
8992 then
8993 Store_Linker_Option_String (End_String);
8994 end if;
8995 end Linker_Options;
8997 --------------------
8998 -- Linker_Section --
8999 --------------------
9001 -- pragma Linker_Section (
9002 -- [Entity =>] LOCAL_NAME
9003 -- [Section =>] static_string_EXPRESSION);
9005 when Pragma_Linker_Section =>
9006 GNAT_Pragma;
9007 Check_Arg_Order ((Name_Entity, Name_Section));
9008 Check_Arg_Count (2);
9009 Check_Optional_Identifier (Arg1, Name_Entity);
9010 Check_Optional_Identifier (Arg2, Name_Section);
9011 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9012 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9014 -- This pragma applies only to objects
9016 if not Is_Object (Entity (Expression (Arg1))) then
9017 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
9018 end if;
9020 -- The only processing required is to link this item on to the
9021 -- list of rep items for the given entity. This is accomplished
9022 -- by the call to Rep_Item_Too_Late (when no error is detected
9023 -- and False is returned).
9025 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
9026 return;
9027 else
9028 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
9029 end if;
9031 ----------
9032 -- List --
9033 ----------
9035 -- pragma List (On | Off)
9037 -- There is nothing to do here, since we did all the processing for
9038 -- this pragma in Par.Prag (so that it works properly even in syntax
9039 -- only mode).
9041 when Pragma_List =>
9042 null;
9044 --------------------
9045 -- Locking_Policy --
9046 --------------------
9048 -- pragma Locking_Policy (policy_IDENTIFIER);
9050 when Pragma_Locking_Policy => declare
9051 LP : Character;
9053 begin
9054 Check_Ada_83_Warning;
9055 Check_Arg_Count (1);
9056 Check_No_Identifiers;
9057 Check_Arg_Is_Locking_Policy (Arg1);
9058 Check_Valid_Configuration_Pragma;
9059 Get_Name_String (Chars (Expression (Arg1)));
9060 LP := Fold_Upper (Name_Buffer (1));
9062 if Locking_Policy /= ' '
9063 and then Locking_Policy /= LP
9064 then
9065 Error_Msg_Sloc := Locking_Policy_Sloc;
9066 Error_Pragma ("locking policy incompatible with policy#");
9068 -- Set new policy, but always preserve System_Location since we
9069 -- like the error message with the run time name.
9071 else
9072 Locking_Policy := LP;
9074 if Locking_Policy_Sloc /= System_Location then
9075 Locking_Policy_Sloc := Loc;
9076 end if;
9077 end if;
9078 end;
9080 ----------------
9081 -- Long_Float --
9082 ----------------
9084 -- pragma Long_Float (D_Float | G_Float);
9086 when Pragma_Long_Float =>
9087 GNAT_Pragma;
9088 Check_Valid_Configuration_Pragma;
9089 Check_Arg_Count (1);
9090 Check_No_Identifier (Arg1);
9091 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
9093 if not OpenVMS_On_Target then
9094 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
9095 end if;
9097 -- D_Float case
9099 if Chars (Expression (Arg1)) = Name_D_Float then
9100 if Opt.Float_Format_Long = 'G' then
9101 Error_Pragma ("G_Float previously specified");
9102 end if;
9104 Opt.Float_Format_Long := 'D';
9106 -- G_Float case (this is the default, does not need overriding)
9108 else
9109 if Opt.Float_Format_Long = 'D' then
9110 Error_Pragma ("D_Float previously specified");
9111 end if;
9113 Opt.Float_Format_Long := 'G';
9114 end if;
9116 Set_Standard_Fpt_Formats;
9118 -----------------------
9119 -- Machine_Attribute --
9120 -----------------------
9122 -- pragma Machine_Attribute (
9123 -- [Entity =>] LOCAL_NAME,
9124 -- [Attribute_Name =>] static_string_EXPRESSION
9125 -- [, [Info =>] static_EXPRESSION] );
9127 when Pragma_Machine_Attribute => Machine_Attribute : declare
9128 Def_Id : Entity_Id;
9130 begin
9131 GNAT_Pragma;
9132 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
9134 if Arg_Count = 3 then
9135 Check_Optional_Identifier (Arg3, Name_Info);
9136 Check_Arg_Is_Static_Expression (Arg3);
9137 else
9138 Check_Arg_Count (2);
9139 end if;
9141 Check_Optional_Identifier (Arg1, Name_Entity);
9142 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
9143 Check_Arg_Is_Local_Name (Arg1);
9144 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9145 Def_Id := Entity (Expression (Arg1));
9147 if Is_Access_Type (Def_Id) then
9148 Def_Id := Designated_Type (Def_Id);
9149 end if;
9151 if Rep_Item_Too_Early (Def_Id, N) then
9152 return;
9153 end if;
9155 Def_Id := Underlying_Type (Def_Id);
9157 -- The only processing required is to link this item on to the
9158 -- list of rep items for the given entity. This is accomplished
9159 -- by the call to Rep_Item_Too_Late (when no error is detected
9160 -- and False is returned).
9162 if Rep_Item_Too_Late (Def_Id, N) then
9163 return;
9164 else
9165 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
9166 end if;
9167 end Machine_Attribute;
9169 ----------
9170 -- Main --
9171 ----------
9173 -- pragma Main
9174 -- (MAIN_OPTION [, MAIN_OPTION]);
9176 -- MAIN_OPTION ::=
9177 -- [STACK_SIZE =>] static_integer_EXPRESSION
9178 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
9179 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
9181 when Pragma_Main => Main : declare
9182 Args : Args_List (1 .. 3);
9183 Names : constant Name_List (1 .. 3) := (
9184 Name_Stack_Size,
9185 Name_Task_Stack_Size_Default,
9186 Name_Time_Slicing_Enabled);
9188 Nod : Node_Id;
9190 begin
9191 GNAT_Pragma;
9192 Gather_Associations (Names, Args);
9194 for J in 1 .. 2 loop
9195 if Present (Args (J)) then
9196 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
9197 end if;
9198 end loop;
9200 if Present (Args (3)) then
9201 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
9202 end if;
9204 Nod := Next (N);
9205 while Present (Nod) loop
9206 if Nkind (Nod) = N_Pragma
9207 and then Pragma_Name (Nod) = Name_Main
9208 then
9209 Error_Msg_Name_1 := Pname;
9210 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9211 end if;
9213 Next (Nod);
9214 end loop;
9215 end Main;
9217 ------------------
9218 -- Main_Storage --
9219 ------------------
9221 -- pragma Main_Storage
9222 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
9224 -- MAIN_STORAGE_OPTION ::=
9225 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
9226 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
9228 when Pragma_Main_Storage => Main_Storage : declare
9229 Args : Args_List (1 .. 2);
9230 Names : constant Name_List (1 .. 2) := (
9231 Name_Working_Storage,
9232 Name_Top_Guard);
9234 Nod : Node_Id;
9236 begin
9237 GNAT_Pragma;
9238 Gather_Associations (Names, Args);
9240 for J in 1 .. 2 loop
9241 if Present (Args (J)) then
9242 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
9243 end if;
9244 end loop;
9246 Check_In_Main_Program;
9248 Nod := Next (N);
9249 while Present (Nod) loop
9250 if Nkind (Nod) = N_Pragma
9251 and then Pragma_Name (Nod) = Name_Main_Storage
9252 then
9253 Error_Msg_Name_1 := Pname;
9254 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9255 end if;
9257 Next (Nod);
9258 end loop;
9259 end Main_Storage;
9261 -----------------
9262 -- Memory_Size --
9263 -----------------
9265 -- pragma Memory_Size (NUMERIC_LITERAL)
9267 when Pragma_Memory_Size =>
9268 GNAT_Pragma;
9270 -- Memory size is simply ignored
9272 Check_No_Identifiers;
9273 Check_Arg_Count (1);
9274 Check_Arg_Is_Integer_Literal (Arg1);
9276 -------------
9277 -- No_Body --
9278 -------------
9280 -- pragma No_Body;
9282 -- The only correct use of this pragma is on its own in a file, in
9283 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
9284 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
9285 -- check for a file containing nothing but a No_Body pragma). If we
9286 -- attempt to process it during normal semantics processing, it means
9287 -- it was misplaced.
9289 when Pragma_No_Body =>
9290 GNAT_Pragma;
9291 Pragma_Misplaced;
9293 ---------------
9294 -- No_Return --
9295 ---------------
9297 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
9299 when Pragma_No_Return => No_Return : declare
9300 Id : Node_Id;
9301 E : Entity_Id;
9302 Found : Boolean;
9303 Arg : Node_Id;
9305 begin
9306 Ada_2005_Pragma;
9307 Check_At_Least_N_Arguments (1);
9309 -- Loop through arguments of pragma
9311 Arg := Arg1;
9312 while Present (Arg) loop
9313 Check_Arg_Is_Local_Name (Arg);
9314 Id := Expression (Arg);
9315 Analyze (Id);
9317 if not Is_Entity_Name (Id) then
9318 Error_Pragma_Arg ("entity name required", Arg);
9319 end if;
9321 if Etype (Id) = Any_Type then
9322 raise Pragma_Exit;
9323 end if;
9325 -- Loop to find matching procedures
9327 E := Entity (Id);
9328 Found := False;
9329 while Present (E)
9330 and then Scope (E) = Current_Scope
9331 loop
9332 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
9333 Set_No_Return (E);
9335 -- Set flag on any alias as well
9337 if Is_Overloadable (E) and then Present (Alias (E)) then
9338 Set_No_Return (Alias (E));
9339 end if;
9341 Found := True;
9342 end if;
9344 E := Homonym (E);
9345 end loop;
9347 if not Found then
9348 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
9349 end if;
9351 Next (Arg);
9352 end loop;
9353 end No_Return;
9355 -----------------
9356 -- No_Run_Time --
9357 -----------------
9359 -- pragma No_Run_Time;
9361 -- Note: this pragma is retained for backwards compatibility. See
9362 -- body of Rtsfind for full details on its handling.
9364 when Pragma_No_Run_Time =>
9365 GNAT_Pragma;
9366 Check_Valid_Configuration_Pragma;
9367 Check_Arg_Count (0);
9369 No_Run_Time_Mode := True;
9370 Configurable_Run_Time_Mode := True;
9372 -- Set Duration to 32 bits if word size is 32
9374 if Ttypes.System_Word_Size = 32 then
9375 Duration_32_Bits_On_Target := True;
9376 end if;
9378 -- Set appropriate restrictions
9380 Set_Restriction (No_Finalization, N);
9381 Set_Restriction (No_Exception_Handlers, N);
9382 Set_Restriction (Max_Tasks, N, 0);
9383 Set_Restriction (No_Tasking, N);
9385 ------------------------
9386 -- No_Strict_Aliasing --
9387 ------------------------
9389 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
9391 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
9392 E_Id : Entity_Id;
9394 begin
9395 GNAT_Pragma;
9396 Check_At_Most_N_Arguments (1);
9398 if Arg_Count = 0 then
9399 Check_Valid_Configuration_Pragma;
9400 Opt.No_Strict_Aliasing := True;
9402 else
9403 Check_Optional_Identifier (Arg2, Name_Entity);
9404 Check_Arg_Is_Local_Name (Arg1);
9405 E_Id := Entity (Expression (Arg1));
9407 if E_Id = Any_Type then
9408 return;
9409 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
9410 Error_Pragma_Arg ("pragma% requires access type", Arg1);
9411 end if;
9413 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
9414 end if;
9415 end No_Strict_Aliasing;
9417 -----------------------
9418 -- Normalize_Scalars --
9419 -----------------------
9421 -- pragma Normalize_Scalars;
9423 when Pragma_Normalize_Scalars =>
9424 Check_Ada_83_Warning;
9425 Check_Arg_Count (0);
9426 Check_Valid_Configuration_Pragma;
9428 -- Normalize_Scalars creates false positives in CodePeer, so
9429 -- ignore this pragma in this mode.
9431 if not CodePeer_Mode then
9432 Normalize_Scalars := True;
9433 Init_Or_Norm_Scalars := True;
9434 end if;
9436 -----------------
9437 -- Obsolescent --
9438 -----------------
9440 -- pragma Obsolescent;
9442 -- pragma Obsolescent (
9443 -- [Message =>] static_string_EXPRESSION
9444 -- [,[Version =>] Ada_05]]);
9446 -- pragma Obsolescent (
9447 -- [Entity =>] NAME
9448 -- [,[Message =>] static_string_EXPRESSION
9449 -- [,[Version =>] Ada_05]] );
9451 when Pragma_Obsolescent => Obsolescent : declare
9452 Ename : Node_Id;
9453 Decl : Node_Id;
9455 procedure Set_Obsolescent (E : Entity_Id);
9456 -- Given an entity Ent, mark it as obsolescent if appropriate
9458 ---------------------
9459 -- Set_Obsolescent --
9460 ---------------------
9462 procedure Set_Obsolescent (E : Entity_Id) is
9463 Active : Boolean;
9464 Ent : Entity_Id;
9465 S : String_Id;
9467 begin
9468 Active := True;
9469 Ent := E;
9471 -- Entity name was given
9473 if Present (Ename) then
9475 -- If entity name matches, we are fine. Save entity in
9476 -- pragma argument, for ASIS use.
9478 if Chars (Ename) = Chars (Ent) then
9479 Set_Entity (Ename, Ent);
9480 Generate_Reference (Ent, Ename);
9482 -- If entity name does not match, only possibility is an
9483 -- enumeration literal from an enumeration type declaration.
9485 elsif Ekind (Ent) /= E_Enumeration_Type then
9486 Error_Pragma
9487 ("pragma % entity name does not match declaration");
9489 else
9490 Ent := First_Literal (E);
9491 loop
9492 if No (Ent) then
9493 Error_Pragma
9494 ("pragma % entity name does not match any " &
9495 "enumeration literal");
9497 elsif Chars (Ent) = Chars (Ename) then
9498 Set_Entity (Ename, Ent);
9499 Generate_Reference (Ent, Ename);
9500 exit;
9502 else
9503 Ent := Next_Literal (Ent);
9504 end if;
9505 end loop;
9506 end if;
9507 end if;
9509 -- Ent points to entity to be marked
9511 if Arg_Count >= 1 then
9513 -- Deal with static string argument
9515 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9516 S := Strval (Expression (Arg1));
9518 for J in 1 .. String_Length (S) loop
9519 if not In_Character_Range (Get_String_Char (S, J)) then
9520 Error_Pragma_Arg
9521 ("pragma% argument does not allow wide characters",
9522 Arg1);
9523 end if;
9524 end loop;
9526 Obsolescent_Warnings.Append
9527 ((Ent => Ent, Msg => Strval (Expression (Arg1))));
9529 -- Check for Ada_05 parameter
9531 if Arg_Count /= 1 then
9532 Check_Arg_Count (2);
9534 declare
9535 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
9537 begin
9538 Check_Arg_Is_Identifier (Argx);
9540 if Chars (Argx) /= Name_Ada_05 then
9541 Error_Msg_Name_2 := Name_Ada_05;
9542 Error_Pragma_Arg
9543 ("only allowed argument for pragma% is %", Argx);
9544 end if;
9546 if Ada_Version_Explicit < Ada_05
9547 or else not Warn_On_Ada_2005_Compatibility
9548 then
9549 Active := False;
9550 end if;
9551 end;
9552 end if;
9553 end if;
9555 -- Set flag if pragma active
9557 if Active then
9558 Set_Is_Obsolescent (Ent);
9559 end if;
9561 return;
9562 end Set_Obsolescent;
9564 -- Start of processing for pragma Obsolescent
9566 begin
9567 GNAT_Pragma;
9569 Check_At_Most_N_Arguments (3);
9571 -- See if first argument specifies an entity name
9573 if Arg_Count >= 1
9574 and then
9575 (Chars (Arg1) = Name_Entity
9576 or else
9577 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
9578 N_Identifier,
9579 N_Operator_Symbol))
9580 then
9581 Ename := Get_Pragma_Arg (Arg1);
9583 -- Eliminate first argument, so we can share processing
9585 Arg1 := Arg2;
9586 Arg2 := Arg3;
9587 Arg_Count := Arg_Count - 1;
9589 -- No Entity name argument given
9591 else
9592 Ename := Empty;
9593 end if;
9595 if Arg_Count >= 1 then
9596 Check_Optional_Identifier (Arg1, Name_Message);
9598 if Arg_Count = 2 then
9599 Check_Optional_Identifier (Arg2, Name_Version);
9600 end if;
9601 end if;
9603 -- Get immediately preceding declaration
9605 Decl := Prev (N);
9606 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
9607 Prev (Decl);
9608 end loop;
9610 -- Cases where we do not follow anything other than another pragma
9612 if No (Decl) then
9614 -- First case: library level compilation unit declaration with
9615 -- the pragma immediately following the declaration.
9617 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9618 Set_Obsolescent
9619 (Defining_Entity (Unit (Parent (Parent (N)))));
9620 return;
9622 -- Case 2: library unit placement for package
9624 else
9625 declare
9626 Ent : constant Entity_Id := Find_Lib_Unit_Name;
9627 begin
9628 if Is_Package_Or_Generic_Package (Ent) then
9629 Set_Obsolescent (Ent);
9630 return;
9631 end if;
9632 end;
9633 end if;
9635 -- Cases where we must follow a declaration
9637 else
9638 if Nkind (Decl) not in N_Declaration
9639 and then Nkind (Decl) not in N_Later_Decl_Item
9640 and then Nkind (Decl) not in N_Generic_Declaration
9641 and then Nkind (Decl) not in N_Renaming_Declaration
9642 then
9643 Error_Pragma
9644 ("pragma% misplaced, "
9645 & "must immediately follow a declaration");
9647 else
9648 Set_Obsolescent (Defining_Entity (Decl));
9649 return;
9650 end if;
9651 end if;
9652 end Obsolescent;
9654 --------------
9655 -- Optimize --
9656 --------------
9658 -- pragma Optimize (Time | Space | Off);
9660 -- The actual check for optimize is done in Gigi. Note that this
9661 -- pragma does not actually change the optimization setting, it
9662 -- simply checks that it is consistent with the pragma.
9664 when Pragma_Optimize =>
9665 Check_No_Identifiers;
9666 Check_Arg_Count (1);
9667 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
9669 ------------------------
9670 -- Optimize_Alignment --
9671 ------------------------
9673 -- pragma Optimize_Alignment (Time | Space | Off);
9675 when Pragma_Optimize_Alignment =>
9676 GNAT_Pragma;
9677 Check_No_Identifiers;
9678 Check_Arg_Count (1);
9679 Check_Valid_Configuration_Pragma;
9681 declare
9682 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
9683 begin
9684 case Nam is
9685 when Name_Time =>
9686 Opt.Optimize_Alignment := 'T';
9687 when Name_Space =>
9688 Opt.Optimize_Alignment := 'S';
9689 when Name_Off =>
9690 Opt.Optimize_Alignment := 'O';
9691 when others =>
9692 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
9693 end case;
9694 end;
9696 -- Set indication that mode is set locally. If we are in fact in a
9697 -- configuration pragma file, this setting is harmless since the
9698 -- switch will get reset anyway at the start of each unit.
9700 Optimize_Alignment_Local := True;
9702 ----------
9703 -- Pack --
9704 ----------
9706 -- pragma Pack (first_subtype_LOCAL_NAME);
9708 when Pragma_Pack => Pack : declare
9709 Assoc : constant Node_Id := Arg1;
9710 Type_Id : Node_Id;
9711 Typ : Entity_Id;
9713 begin
9714 Check_No_Identifiers;
9715 Check_Arg_Count (1);
9716 Check_Arg_Is_Local_Name (Arg1);
9718 Type_Id := Expression (Assoc);
9719 Find_Type (Type_Id);
9720 Typ := Entity (Type_Id);
9722 if Typ = Any_Type
9723 or else Rep_Item_Too_Early (Typ, N)
9724 then
9725 return;
9726 else
9727 Typ := Underlying_Type (Typ);
9728 end if;
9730 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
9731 Error_Pragma ("pragma% must specify array or record type");
9732 end if;
9734 Check_First_Subtype (Arg1);
9736 if Has_Pragma_Pack (Typ) then
9737 Error_Pragma ("duplicate pragma%, only one allowed");
9739 -- Array type
9741 elsif Is_Array_Type (Typ) then
9743 -- Pack not allowed for aliased or atomic components
9745 if Has_Aliased_Components (Base_Type (Typ)) then
9746 Error_Pragma
9747 ("pragma% ignored, cannot pack aliased components?");
9749 elsif Has_Atomic_Components (Typ)
9750 or else Is_Atomic (Component_Type (Typ))
9751 then
9752 Error_Pragma
9753 ("?pragma% ignored, cannot pack atomic components");
9754 end if;
9756 -- If we had an explicit component size given, then we do not
9757 -- let Pack override this given size. We also give a warning
9758 -- that Pack is being ignored unless we can tell for sure that
9759 -- the Pack would not have had any effect anyway.
9761 if Has_Component_Size_Clause (Typ) then
9762 if Known_Static_RM_Size (Component_Type (Typ))
9763 and then
9764 RM_Size (Component_Type (Typ)) = Component_Size (Typ)
9765 then
9766 null;
9767 else
9768 Error_Pragma
9769 ("?pragma% ignored, explicit component size given");
9770 end if;
9772 -- If no prior array component size given, Pack is effective
9774 else
9775 if not Rep_Item_Too_Late (Typ, N) then
9777 -- In the context of static code analysis, we do not need
9778 -- complex front-end expansions related to pragma Pack,
9779 -- so disable handling of pragma Pack in this case.
9781 if CodePeer_Mode then
9782 null;
9784 -- For normal non-VM target, do the packing
9786 elsif VM_Target = No_VM then
9787 Set_Is_Packed (Base_Type (Typ));
9788 Set_Has_Pragma_Pack (Base_Type (Typ));
9789 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9791 -- If we ignore the pack, then warn about this, except
9792 -- that we suppress the warning in GNAT mode.
9794 elsif not GNAT_Mode then
9795 Error_Pragma
9796 ("?pragma% ignored in this configuration");
9797 end if;
9798 end if;
9799 end if;
9801 -- For record types, the pack is always effective
9803 else pragma Assert (Is_Record_Type (Typ));
9804 if not Rep_Item_Too_Late (Typ, N) then
9805 if VM_Target = No_VM then
9806 Set_Is_Packed (Base_Type (Typ));
9807 Set_Has_Pragma_Pack (Base_Type (Typ));
9808 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9810 elsif not GNAT_Mode then
9811 Error_Pragma ("?pragma% ignored in this configuration");
9812 end if;
9813 end if;
9814 end if;
9815 end Pack;
9817 ----------
9818 -- Page --
9819 ----------
9821 -- pragma Page;
9823 -- There is nothing to do here, since we did all the processing for
9824 -- this pragma in Par.Prag (so that it works properly even in syntax
9825 -- only mode).
9827 when Pragma_Page =>
9828 null;
9830 -------------
9831 -- Passive --
9832 -------------
9834 -- pragma Passive [(PASSIVE_FORM)];
9836 -- PASSIVE_FORM ::= Semaphore | No
9838 when Pragma_Passive =>
9839 GNAT_Pragma;
9841 if Nkind (Parent (N)) /= N_Task_Definition then
9842 Error_Pragma ("pragma% must be within task definition");
9843 end if;
9845 if Arg_Count /= 0 then
9846 Check_Arg_Count (1);
9847 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
9848 end if;
9850 ----------------------------------
9851 -- Preelaborable_Initialization --
9852 ----------------------------------
9854 -- pragma Preelaborable_Initialization (DIRECT_NAME);
9856 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
9857 Ent : Entity_Id;
9859 begin
9860 Ada_2005_Pragma;
9861 Check_Arg_Count (1);
9862 Check_No_Identifiers;
9863 Check_Arg_Is_Identifier (Arg1);
9864 Check_Arg_Is_Local_Name (Arg1);
9865 Check_First_Subtype (Arg1);
9866 Ent := Entity (Expression (Arg1));
9868 if not Is_Private_Type (Ent)
9869 and then not Is_Protected_Type (Ent)
9870 then
9871 Error_Pragma_Arg
9872 ("pragma % can only be applied to private or protected type",
9873 Arg1);
9874 end if;
9876 -- Give an error if the pragma is applied to a protected type that
9877 -- does not qualify (due to having entries, or due to components
9878 -- that do not qualify).
9880 if Is_Protected_Type (Ent)
9881 and then not Has_Preelaborable_Initialization (Ent)
9882 then
9883 Error_Msg_N
9884 ("protected type & does not have preelaborable " &
9885 "initialization", Ent);
9887 -- Otherwise mark the type as definitely having preelaborable
9888 -- initialization.
9890 else
9891 Set_Known_To_Have_Preelab_Init (Ent);
9892 end if;
9894 if Has_Pragma_Preelab_Init (Ent)
9895 and then Warn_On_Redundant_Constructs
9896 then
9897 Error_Pragma ("?duplicate pragma%!");
9898 else
9899 Set_Has_Pragma_Preelab_Init (Ent);
9900 end if;
9901 end Preelab_Init;
9903 --------------------
9904 -- Persistent_BSS --
9905 --------------------
9907 when Pragma_Persistent_BSS => Persistent_BSS : declare
9908 Decl : Node_Id;
9909 Ent : Entity_Id;
9910 Prag : Node_Id;
9912 begin
9913 GNAT_Pragma;
9914 Check_At_Most_N_Arguments (1);
9916 -- Case of application to specific object (one argument)
9918 if Arg_Count = 1 then
9919 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9921 if not Is_Entity_Name (Expression (Arg1))
9922 or else
9923 (Ekind (Entity (Expression (Arg1))) /= E_Variable
9924 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
9925 then
9926 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
9927 end if;
9929 Ent := Entity (Expression (Arg1));
9930 Decl := Parent (Ent);
9932 if Rep_Item_Too_Late (Ent, N) then
9933 return;
9934 end if;
9936 if Present (Expression (Decl)) then
9937 Error_Pragma_Arg
9938 ("object for pragma% cannot have initialization", Arg1);
9939 end if;
9941 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
9942 Error_Pragma_Arg
9943 ("object type for pragma% is not potentially persistent",
9944 Arg1);
9945 end if;
9947 Prag :=
9948 Make_Linker_Section_Pragma
9949 (Ent, Sloc (N), ".persistent.bss");
9950 Insert_After (N, Prag);
9951 Analyze (Prag);
9953 -- Case of use as configuration pragma with no arguments
9955 else
9956 Check_Valid_Configuration_Pragma;
9957 Persistent_BSS_Mode := True;
9958 end if;
9959 end Persistent_BSS;
9961 -------------
9962 -- Polling --
9963 -------------
9965 -- pragma Polling (ON | OFF);
9967 when Pragma_Polling =>
9968 GNAT_Pragma;
9969 Check_Arg_Count (1);
9970 Check_No_Identifiers;
9971 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9972 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
9974 -------------------
9975 -- Postcondition --
9976 -------------------
9978 -- pragma Postcondition ([Check =>] Boolean_Expression
9979 -- [,[Message =>] String_Expression]);
9981 when Pragma_Postcondition => Postcondition : declare
9982 In_Body : Boolean;
9983 pragma Warnings (Off, In_Body);
9985 begin
9986 GNAT_Pragma;
9987 Check_At_Least_N_Arguments (1);
9988 Check_At_Most_N_Arguments (2);
9989 Check_Optional_Identifier (Arg1, Name_Check);
9991 -- All we need to do here is call the common check procedure,
9992 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
9994 Check_Precondition_Postcondition (In_Body);
9995 end Postcondition;
9997 ------------------
9998 -- Precondition --
9999 ------------------
10001 -- pragma Precondition ([Check =>] Boolean_Expression
10002 -- [,[Message =>] String_Expression]);
10004 when Pragma_Precondition => Precondition : declare
10005 In_Body : Boolean;
10007 begin
10008 GNAT_Pragma;
10009 Check_At_Least_N_Arguments (1);
10010 Check_At_Most_N_Arguments (2);
10011 Check_Optional_Identifier (Arg1, Name_Check);
10013 Check_Precondition_Postcondition (In_Body);
10015 -- If in spec, nothing more to do. If in body, then we convert the
10016 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
10017 -- this whether or not precondition checks are enabled. That works
10018 -- fine since pragma Check will do this check, and will also
10019 -- analyze the condition itself in the proper context.
10021 if In_Body then
10022 if Arg_Count = 2 then
10023 Check_Optional_Identifier (Arg3, Name_Message);
10024 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
10025 end if;
10027 Rewrite (N,
10028 Make_Pragma (Loc,
10029 Chars => Name_Check,
10030 Pragma_Argument_Associations => New_List (
10031 Make_Pragma_Argument_Association (Loc,
10032 Expression =>
10033 Make_Identifier (Loc,
10034 Chars => Name_Precondition)),
10036 Make_Pragma_Argument_Association (Sloc (Arg1),
10037 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
10039 if Arg_Count = 2 then
10040 Append_To (Pragma_Argument_Associations (N),
10041 Make_Pragma_Argument_Association (Sloc (Arg2),
10042 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
10043 end if;
10045 Analyze (N);
10046 end if;
10047 end Precondition;
10049 ------------------
10050 -- Preelaborate --
10051 ------------------
10053 -- pragma Preelaborate [(library_unit_NAME)];
10055 -- Set the flag Is_Preelaborated of program unit name entity
10057 when Pragma_Preelaborate => Preelaborate : declare
10058 Pa : constant Node_Id := Parent (N);
10059 Pk : constant Node_Kind := Nkind (Pa);
10060 Ent : Entity_Id;
10062 begin
10063 Check_Ada_83_Warning;
10064 Check_Valid_Library_Unit_Pragma;
10066 if Nkind (N) = N_Null_Statement then
10067 return;
10068 end if;
10070 Ent := Find_Lib_Unit_Name;
10072 -- This filters out pragmas inside generic parent then
10073 -- show up inside instantiation
10075 if Present (Ent)
10076 and then not (Pk = N_Package_Specification
10077 and then Present (Generic_Parent (Pa)))
10078 then
10079 if not Debug_Flag_U then
10080 Set_Is_Preelaborated (Ent);
10081 Set_Suppress_Elaboration_Warnings (Ent);
10082 end if;
10083 end if;
10084 end Preelaborate;
10086 ---------------------
10087 -- Preelaborate_05 --
10088 ---------------------
10090 -- pragma Preelaborate_05 [(library_unit_NAME)];
10092 -- This pragma is useable only in GNAT_Mode, where it is used like
10093 -- pragma Preelaborate but it is only effective in Ada 2005 mode
10094 -- (otherwise it is ignored). This is used to implement AI-362 which
10095 -- recategorizes some run-time packages in Ada 2005 mode.
10097 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
10098 Ent : Entity_Id;
10100 begin
10101 GNAT_Pragma;
10102 Check_Valid_Library_Unit_Pragma;
10104 if not GNAT_Mode then
10105 Error_Pragma ("pragma% only available in GNAT mode");
10106 end if;
10108 if Nkind (N) = N_Null_Statement then
10109 return;
10110 end if;
10112 -- This is one of the few cases where we need to test the value of
10113 -- Ada_Version_Explicit rather than Ada_Version (which is always
10114 -- set to Ada_12 in a predefined unit), we need to know the
10115 -- explicit version set to know if this pragma is active.
10117 if Ada_Version_Explicit >= Ada_05 then
10118 Ent := Find_Lib_Unit_Name;
10119 Set_Is_Preelaborated (Ent);
10120 Set_Suppress_Elaboration_Warnings (Ent);
10121 end if;
10122 end Preelaborate_05;
10124 --------------
10125 -- Priority --
10126 --------------
10128 -- pragma Priority (EXPRESSION);
10130 when Pragma_Priority => Priority : declare
10131 P : constant Node_Id := Parent (N);
10132 Arg : Node_Id;
10134 begin
10135 Check_No_Identifiers;
10136 Check_Arg_Count (1);
10138 -- Subprogram case
10140 if Nkind (P) = N_Subprogram_Body then
10141 Check_In_Main_Program;
10143 Arg := Expression (Arg1);
10144 Analyze_And_Resolve (Arg, Standard_Integer);
10146 -- Must be static
10148 if not Is_Static_Expression (Arg) then
10149 Flag_Non_Static_Expr
10150 ("main subprogram priority is not static!", Arg);
10151 raise Pragma_Exit;
10153 -- If constraint error, then we already signalled an error
10155 elsif Raises_Constraint_Error (Arg) then
10156 null;
10158 -- Otherwise check in range
10160 else
10161 declare
10162 Val : constant Uint := Expr_Value (Arg);
10164 begin
10165 if Val < 0
10166 or else Val > Expr_Value (Expression
10167 (Parent (RTE (RE_Max_Priority))))
10168 then
10169 Error_Pragma_Arg
10170 ("main subprogram priority is out of range", Arg1);
10171 end if;
10172 end;
10173 end if;
10175 Set_Main_Priority
10176 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
10178 -- Load an arbitrary entity from System.Tasking to make sure
10179 -- this package is implicitly with'ed, since we need to have
10180 -- the tasking run-time active for the pragma Priority to have
10181 -- any effect.
10183 declare
10184 Discard : Entity_Id;
10185 pragma Warnings (Off, Discard);
10186 begin
10187 Discard := RTE (RE_Task_List);
10188 end;
10190 -- Task or Protected, must be of type Integer
10192 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
10193 Arg := Expression (Arg1);
10195 -- The expression must be analyzed in the special manner
10196 -- described in "Handling of Default and Per-Object
10197 -- Expressions" in sem.ads.
10199 Preanalyze_Spec_Expression (Arg, Standard_Integer);
10201 if not Is_Static_Expression (Arg) then
10202 Check_Restriction (Static_Priorities, Arg);
10203 end if;
10205 -- Anything else is incorrect
10207 else
10208 Pragma_Misplaced;
10209 end if;
10211 if Has_Priority_Pragma (P) then
10212 Error_Pragma ("duplicate pragma% not allowed");
10213 else
10214 Set_Has_Priority_Pragma (P, True);
10216 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
10217 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10218 -- exp_ch9 should use this ???
10219 end if;
10220 end if;
10221 end Priority;
10223 -----------------------------------
10224 -- Priority_Specific_Dispatching --
10225 -----------------------------------
10227 -- pragma Priority_Specific_Dispatching (
10228 -- policy_IDENTIFIER,
10229 -- first_priority_EXPRESSION,
10230 -- last_priority_EXPRESSION);
10232 when Pragma_Priority_Specific_Dispatching =>
10233 Priority_Specific_Dispatching : declare
10234 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
10235 -- This is the entity System.Any_Priority;
10237 DP : Character;
10238 Lower_Bound : Node_Id;
10239 Upper_Bound : Node_Id;
10240 Lower_Val : Uint;
10241 Upper_Val : Uint;
10243 begin
10244 Ada_2005_Pragma;
10245 Check_Arg_Count (3);
10246 Check_No_Identifiers;
10247 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
10248 Check_Valid_Configuration_Pragma;
10249 Get_Name_String (Chars (Expression (Arg1)));
10250 DP := Fold_Upper (Name_Buffer (1));
10252 Lower_Bound := Expression (Arg2);
10253 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
10254 Lower_Val := Expr_Value (Lower_Bound);
10256 Upper_Bound := Expression (Arg3);
10257 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
10258 Upper_Val := Expr_Value (Upper_Bound);
10260 -- It is not allowed to use Task_Dispatching_Policy and
10261 -- Priority_Specific_Dispatching in the same partition.
10263 if Task_Dispatching_Policy /= ' ' then
10264 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10265 Error_Pragma
10266 ("pragma% incompatible with Task_Dispatching_Policy#");
10268 -- Check lower bound in range
10270 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10271 or else
10272 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
10273 then
10274 Error_Pragma_Arg
10275 ("first_priority is out of range", Arg2);
10277 -- Check upper bound in range
10279 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10280 or else
10281 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
10282 then
10283 Error_Pragma_Arg
10284 ("last_priority is out of range", Arg3);
10286 -- Check that the priority range is valid
10288 elsif Lower_Val > Upper_Val then
10289 Error_Pragma
10290 ("last_priority_expression must be greater than" &
10291 " or equal to first_priority_expression");
10293 -- Store the new policy, but always preserve System_Location since
10294 -- we like the error message with the run-time name.
10296 else
10297 -- Check overlapping in the priority ranges specified in other
10298 -- Priority_Specific_Dispatching pragmas within the same
10299 -- partition. We can only check those we know about!
10301 for J in
10302 Specific_Dispatching.First .. Specific_Dispatching.Last
10303 loop
10304 if Specific_Dispatching.Table (J).First_Priority in
10305 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10306 or else Specific_Dispatching.Table (J).Last_Priority in
10307 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10308 then
10309 Error_Msg_Sloc :=
10310 Specific_Dispatching.Table (J).Pragma_Loc;
10311 Error_Pragma
10312 ("priority range overlaps with "
10313 & "Priority_Specific_Dispatching#");
10314 end if;
10315 end loop;
10317 -- The use of Priority_Specific_Dispatching is incompatible
10318 -- with Task_Dispatching_Policy.
10320 if Task_Dispatching_Policy /= ' ' then
10321 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10322 Error_Pragma
10323 ("Priority_Specific_Dispatching incompatible "
10324 & "with Task_Dispatching_Policy#");
10325 end if;
10327 -- The use of Priority_Specific_Dispatching forces ceiling
10328 -- locking policy.
10330 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
10331 Error_Msg_Sloc := Locking_Policy_Sloc;
10332 Error_Pragma
10333 ("Priority_Specific_Dispatching incompatible "
10334 & "with Locking_Policy#");
10336 -- Set the Ceiling_Locking policy, but preserve System_Location
10337 -- since we like the error message with the run time name.
10339 else
10340 Locking_Policy := 'C';
10342 if Locking_Policy_Sloc /= System_Location then
10343 Locking_Policy_Sloc := Loc;
10344 end if;
10345 end if;
10347 -- Add entry in the table
10349 Specific_Dispatching.Append
10350 ((Dispatching_Policy => DP,
10351 First_Priority => UI_To_Int (Lower_Val),
10352 Last_Priority => UI_To_Int (Upper_Val),
10353 Pragma_Loc => Loc));
10354 end if;
10355 end Priority_Specific_Dispatching;
10357 -------------
10358 -- Profile --
10359 -------------
10361 -- pragma Profile (profile_IDENTIFIER);
10363 -- profile_IDENTIFIER => Restricted | Ravenscar
10365 when Pragma_Profile =>
10366 Ada_2005_Pragma;
10367 Check_Arg_Count (1);
10368 Check_Valid_Configuration_Pragma;
10369 Check_No_Identifiers;
10371 declare
10372 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10373 begin
10374 if Chars (Argx) = Name_Ravenscar then
10375 Set_Ravenscar_Profile (N);
10376 elsif Chars (Argx) = Name_Restricted then
10377 Set_Profile_Restrictions
10378 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10379 else
10380 Error_Pragma_Arg ("& is not a valid profile", Argx);
10381 end if;
10382 end;
10384 ----------------------
10385 -- Profile_Warnings --
10386 ----------------------
10388 -- pragma Profile_Warnings (profile_IDENTIFIER);
10390 -- profile_IDENTIFIER => Restricted | Ravenscar
10392 when Pragma_Profile_Warnings =>
10393 GNAT_Pragma;
10394 Check_Arg_Count (1);
10395 Check_Valid_Configuration_Pragma;
10396 Check_No_Identifiers;
10398 declare
10399 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10400 begin
10401 if Chars (Argx) = Name_Ravenscar then
10402 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
10403 elsif Chars (Argx) = Name_Restricted then
10404 Set_Profile_Restrictions (Restricted, N, Warn => True);
10405 else
10406 Error_Pragma_Arg ("& is not a valid profile", Argx);
10407 end if;
10408 end;
10410 --------------------------
10411 -- Propagate_Exceptions --
10412 --------------------------
10414 -- pragma Propagate_Exceptions;
10416 -- Note: this pragma is obsolete and has no effect
10418 when Pragma_Propagate_Exceptions =>
10419 GNAT_Pragma;
10420 Check_Arg_Count (0);
10422 if In_Extended_Main_Source_Unit (N) then
10423 Propagate_Exceptions := True;
10424 end if;
10426 ------------------
10427 -- Psect_Object --
10428 ------------------
10430 -- pragma Psect_Object (
10431 -- [Internal =>] LOCAL_NAME,
10432 -- [, [External =>] EXTERNAL_SYMBOL]
10433 -- [, [Size =>] EXTERNAL_SYMBOL]);
10435 when Pragma_Psect_Object | Pragma_Common_Object =>
10436 Psect_Object : declare
10437 Args : Args_List (1 .. 3);
10438 Names : constant Name_List (1 .. 3) := (
10439 Name_Internal,
10440 Name_External,
10441 Name_Size);
10443 Internal : Node_Id renames Args (1);
10444 External : Node_Id renames Args (2);
10445 Size : Node_Id renames Args (3);
10447 Def_Id : Entity_Id;
10449 procedure Check_Too_Long (Arg : Node_Id);
10450 -- Posts message if the argument is an identifier with more
10451 -- than 31 characters, or a string literal with more than
10452 -- 31 characters, and we are operating under VMS
10454 --------------------
10455 -- Check_Too_Long --
10456 --------------------
10458 procedure Check_Too_Long (Arg : Node_Id) is
10459 X : constant Node_Id := Original_Node (Arg);
10461 begin
10462 if not Nkind_In (X, N_String_Literal, N_Identifier) then
10463 Error_Pragma_Arg
10464 ("inappropriate argument for pragma %", Arg);
10465 end if;
10467 if OpenVMS_On_Target then
10468 if (Nkind (X) = N_String_Literal
10469 and then String_Length (Strval (X)) > 31)
10470 or else
10471 (Nkind (X) = N_Identifier
10472 and then Length_Of_Name (Chars (X)) > 31)
10473 then
10474 Error_Pragma_Arg
10475 ("argument for pragma % is longer than 31 characters",
10476 Arg);
10477 end if;
10478 end if;
10479 end Check_Too_Long;
10481 -- Start of processing for Common_Object/Psect_Object
10483 begin
10484 GNAT_Pragma;
10485 Gather_Associations (Names, Args);
10486 Process_Extended_Import_Export_Internal_Arg (Internal);
10488 Def_Id := Entity (Internal);
10490 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
10491 Error_Pragma_Arg
10492 ("pragma% must designate an object", Internal);
10493 end if;
10495 Check_Too_Long (Internal);
10497 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
10498 Error_Pragma_Arg
10499 ("cannot use pragma% for imported/exported object",
10500 Internal);
10501 end if;
10503 if Is_Concurrent_Type (Etype (Internal)) then
10504 Error_Pragma_Arg
10505 ("cannot specify pragma % for task/protected object",
10506 Internal);
10507 end if;
10509 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
10510 or else
10511 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
10512 then
10513 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
10514 end if;
10516 if Ekind (Def_Id) = E_Constant then
10517 Error_Pragma_Arg
10518 ("cannot specify pragma % for a constant", Internal);
10519 end if;
10521 if Is_Record_Type (Etype (Internal)) then
10522 declare
10523 Ent : Entity_Id;
10524 Decl : Entity_Id;
10526 begin
10527 Ent := First_Entity (Etype (Internal));
10528 while Present (Ent) loop
10529 Decl := Declaration_Node (Ent);
10531 if Ekind (Ent) = E_Component
10532 and then Nkind (Decl) = N_Component_Declaration
10533 and then Present (Expression (Decl))
10534 and then Warn_On_Export_Import
10535 then
10536 Error_Msg_N
10537 ("?object for pragma % has defaults", Internal);
10538 exit;
10540 else
10541 Next_Entity (Ent);
10542 end if;
10543 end loop;
10544 end;
10545 end if;
10547 if Present (Size) then
10548 Check_Too_Long (Size);
10549 end if;
10551 if Present (External) then
10552 Check_Arg_Is_External_Name (External);
10553 Check_Too_Long (External);
10554 end if;
10556 -- If all error tests pass, link pragma on to the rep item chain
10558 Record_Rep_Item (Def_Id, N);
10559 end Psect_Object;
10561 ----------
10562 -- Pure --
10563 ----------
10565 -- pragma Pure [(library_unit_NAME)];
10567 when Pragma_Pure => Pure : declare
10568 Ent : Entity_Id;
10570 begin
10571 Check_Ada_83_Warning;
10572 Check_Valid_Library_Unit_Pragma;
10574 if Nkind (N) = N_Null_Statement then
10575 return;
10576 end if;
10578 Ent := Find_Lib_Unit_Name;
10579 Set_Is_Pure (Ent);
10580 Set_Has_Pragma_Pure (Ent);
10581 Set_Suppress_Elaboration_Warnings (Ent);
10582 end Pure;
10584 -------------
10585 -- Pure_05 --
10586 -------------
10588 -- pragma Pure_05 [(library_unit_NAME)];
10590 -- This pragma is useable only in GNAT_Mode, where it is used like
10591 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
10592 -- it is ignored). It may be used after a pragma Preelaborate, in
10593 -- which case it overrides the effect of the pragma Preelaborate.
10594 -- This is used to implement AI-362 which recategorizes some run-time
10595 -- packages in Ada 2005 mode.
10597 when Pragma_Pure_05 => Pure_05 : declare
10598 Ent : Entity_Id;
10600 begin
10601 GNAT_Pragma;
10602 Check_Valid_Library_Unit_Pragma;
10604 if not GNAT_Mode then
10605 Error_Pragma ("pragma% only available in GNAT mode");
10606 end if;
10608 if Nkind (N) = N_Null_Statement then
10609 return;
10610 end if;
10612 -- This is one of the few cases where we need to test the value of
10613 -- Ada_Version_Explicit rather than Ada_Version (which is always
10614 -- set to Ada_12 in a predefined unit), we need to know the
10615 -- explicit version set to know if this pragma is active.
10617 if Ada_Version_Explicit >= Ada_05 then
10618 Ent := Find_Lib_Unit_Name;
10619 Set_Is_Preelaborated (Ent, False);
10620 Set_Is_Pure (Ent);
10621 Set_Suppress_Elaboration_Warnings (Ent);
10622 end if;
10623 end Pure_05;
10625 -------------------
10626 -- Pure_Function --
10627 -------------------
10629 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
10631 when Pragma_Pure_Function => Pure_Function : declare
10632 E_Id : Node_Id;
10633 E : Entity_Id;
10634 Def_Id : Entity_Id;
10635 Effective : Boolean := False;
10637 begin
10638 GNAT_Pragma;
10639 Check_Arg_Count (1);
10640 Check_Optional_Identifier (Arg1, Name_Entity);
10641 Check_Arg_Is_Local_Name (Arg1);
10642 E_Id := Expression (Arg1);
10644 if Error_Posted (E_Id) then
10645 return;
10646 end if;
10648 -- Loop through homonyms (overloadings) of referenced entity
10650 E := Entity (E_Id);
10652 if Present (E) then
10653 loop
10654 Def_Id := Get_Base_Subprogram (E);
10656 if not Ekind_In (Def_Id, E_Function,
10657 E_Generic_Function,
10658 E_Operator)
10659 then
10660 Error_Pragma_Arg
10661 ("pragma% requires a function name", Arg1);
10662 end if;
10664 Set_Is_Pure (Def_Id);
10666 if not Has_Pragma_Pure_Function (Def_Id) then
10667 Set_Has_Pragma_Pure_Function (Def_Id);
10668 Effective := True;
10669 end if;
10671 E := Homonym (E);
10672 exit when No (E) or else Scope (E) /= Current_Scope;
10673 end loop;
10675 if not Effective
10676 and then Warn_On_Redundant_Constructs
10677 then
10678 Error_Msg_NE
10679 ("pragma Pure_Function on& is redundant?",
10680 N, Entity (E_Id));
10681 end if;
10682 end if;
10683 end Pure_Function;
10685 --------------------
10686 -- Queuing_Policy --
10687 --------------------
10689 -- pragma Queuing_Policy (policy_IDENTIFIER);
10691 when Pragma_Queuing_Policy => declare
10692 QP : Character;
10694 begin
10695 Check_Ada_83_Warning;
10696 Check_Arg_Count (1);
10697 Check_No_Identifiers;
10698 Check_Arg_Is_Queuing_Policy (Arg1);
10699 Check_Valid_Configuration_Pragma;
10700 Get_Name_String (Chars (Expression (Arg1)));
10701 QP := Fold_Upper (Name_Buffer (1));
10703 if Queuing_Policy /= ' '
10704 and then Queuing_Policy /= QP
10705 then
10706 Error_Msg_Sloc := Queuing_Policy_Sloc;
10707 Error_Pragma ("queuing policy incompatible with policy#");
10709 -- Set new policy, but always preserve System_Location since we
10710 -- like the error message with the run time name.
10712 else
10713 Queuing_Policy := QP;
10715 if Queuing_Policy_Sloc /= System_Location then
10716 Queuing_Policy_Sloc := Loc;
10717 end if;
10718 end if;
10719 end;
10721 -----------------------
10722 -- Relative_Deadline --
10723 -----------------------
10725 -- pragma Relative_Deadline (time_span_EXPRESSION);
10727 when Pragma_Relative_Deadline => Relative_Deadline : declare
10728 P : constant Node_Id := Parent (N);
10729 Arg : Node_Id;
10731 begin
10732 Ada_2005_Pragma;
10733 Check_No_Identifiers;
10734 Check_Arg_Count (1);
10736 Arg := Expression (Arg1);
10738 -- The expression must be analyzed in the special manner described
10739 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
10741 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
10743 -- Subprogram case
10745 if Nkind (P) = N_Subprogram_Body then
10746 Check_In_Main_Program;
10748 -- Tasks
10750 elsif Nkind (P) = N_Task_Definition then
10751 null;
10753 -- Anything else is incorrect
10755 else
10756 Pragma_Misplaced;
10757 end if;
10759 if Has_Relative_Deadline_Pragma (P) then
10760 Error_Pragma ("duplicate pragma% not allowed");
10761 else
10762 Set_Has_Relative_Deadline_Pragma (P, True);
10764 if Nkind (P) = N_Task_Definition then
10765 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10766 end if;
10767 end if;
10768 end Relative_Deadline;
10770 ---------------------------
10771 -- Remote_Call_Interface --
10772 ---------------------------
10774 -- pragma Remote_Call_Interface [(library_unit_NAME)];
10776 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
10777 Cunit_Node : Node_Id;
10778 Cunit_Ent : Entity_Id;
10779 K : Node_Kind;
10781 begin
10782 Check_Ada_83_Warning;
10783 Check_Valid_Library_Unit_Pragma;
10785 if Nkind (N) = N_Null_Statement then
10786 return;
10787 end if;
10789 Cunit_Node := Cunit (Current_Sem_Unit);
10790 K := Nkind (Unit (Cunit_Node));
10791 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10793 if K = N_Package_Declaration
10794 or else K = N_Generic_Package_Declaration
10795 or else K = N_Subprogram_Declaration
10796 or else K = N_Generic_Subprogram_Declaration
10797 or else (K = N_Subprogram_Body
10798 and then Acts_As_Spec (Unit (Cunit_Node)))
10799 then
10800 null;
10801 else
10802 Error_Pragma (
10803 "pragma% must apply to package or subprogram declaration");
10804 end if;
10806 Set_Is_Remote_Call_Interface (Cunit_Ent);
10807 end Remote_Call_Interface;
10809 ------------------
10810 -- Remote_Types --
10811 ------------------
10813 -- pragma Remote_Types [(library_unit_NAME)];
10815 when Pragma_Remote_Types => Remote_Types : declare
10816 Cunit_Node : Node_Id;
10817 Cunit_Ent : Entity_Id;
10819 begin
10820 Check_Ada_83_Warning;
10821 Check_Valid_Library_Unit_Pragma;
10823 if Nkind (N) = N_Null_Statement then
10824 return;
10825 end if;
10827 Cunit_Node := Cunit (Current_Sem_Unit);
10828 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10830 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
10831 N_Generic_Package_Declaration)
10832 then
10833 Error_Pragma
10834 ("pragma% can only apply to a package declaration");
10835 end if;
10837 Set_Is_Remote_Types (Cunit_Ent);
10838 end Remote_Types;
10840 ---------------
10841 -- Ravenscar --
10842 ---------------
10844 -- pragma Ravenscar;
10846 when Pragma_Ravenscar =>
10847 GNAT_Pragma;
10848 Check_Arg_Count (0);
10849 Check_Valid_Configuration_Pragma;
10850 Set_Ravenscar_Profile (N);
10852 if Warn_On_Obsolescent_Feature then
10853 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
10854 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
10855 end if;
10857 -------------------------
10858 -- Restricted_Run_Time --
10859 -------------------------
10861 -- pragma Restricted_Run_Time;
10863 when Pragma_Restricted_Run_Time =>
10864 GNAT_Pragma;
10865 Check_Arg_Count (0);
10866 Check_Valid_Configuration_Pragma;
10867 Set_Profile_Restrictions
10868 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10870 if Warn_On_Obsolescent_Feature then
10871 Error_Msg_N
10872 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
10873 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
10874 end if;
10876 ------------------
10877 -- Restrictions --
10878 ------------------
10880 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
10882 -- RESTRICTION ::=
10883 -- restriction_IDENTIFIER
10884 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10886 when Pragma_Restrictions =>
10887 Process_Restrictions_Or_Restriction_Warnings
10888 (Warn => Treat_Restrictions_As_Warnings);
10890 --------------------------
10891 -- Restriction_Warnings --
10892 --------------------------
10894 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
10896 -- RESTRICTION ::=
10897 -- restriction_IDENTIFIER
10898 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10900 when Pragma_Restriction_Warnings =>
10901 GNAT_Pragma;
10902 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
10904 ----------------
10905 -- Reviewable --
10906 ----------------
10908 -- pragma Reviewable;
10910 when Pragma_Reviewable =>
10911 Check_Ada_83_Warning;
10912 Check_Arg_Count (0);
10914 -- Call dummy debugging function rv. This is done to assist front
10915 -- end debugging. By placing a Reviewable pragma in the source
10916 -- program, a breakpoint on rv catches this place in the source,
10917 -- allowing convenient stepping to the point of interest.
10921 --------------------------
10922 -- Short_Circuit_And_Or --
10923 --------------------------
10925 when Pragma_Short_Circuit_And_Or =>
10926 GNAT_Pragma;
10927 Check_Arg_Count (0);
10928 Check_Valid_Configuration_Pragma;
10929 Short_Circuit_And_Or := True;
10931 -------------------
10932 -- Share_Generic --
10933 -------------------
10935 -- pragma Share_Generic (NAME {, NAME});
10937 when Pragma_Share_Generic =>
10938 GNAT_Pragma;
10939 Process_Generic_List;
10941 ------------
10942 -- Shared --
10943 ------------
10945 -- pragma Shared (LOCAL_NAME);
10947 when Pragma_Shared =>
10948 GNAT_Pragma;
10949 Process_Atomic_Shared_Volatile;
10951 --------------------
10952 -- Shared_Passive --
10953 --------------------
10955 -- pragma Shared_Passive [(library_unit_NAME)];
10957 -- Set the flag Is_Shared_Passive of program unit name entity
10959 when Pragma_Shared_Passive => Shared_Passive : declare
10960 Cunit_Node : Node_Id;
10961 Cunit_Ent : Entity_Id;
10963 begin
10964 Check_Ada_83_Warning;
10965 Check_Valid_Library_Unit_Pragma;
10967 if Nkind (N) = N_Null_Statement then
10968 return;
10969 end if;
10971 Cunit_Node := Cunit (Current_Sem_Unit);
10972 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10974 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
10975 N_Generic_Package_Declaration)
10976 then
10977 Error_Pragma
10978 ("pragma% can only apply to a package declaration");
10979 end if;
10981 Set_Is_Shared_Passive (Cunit_Ent);
10982 end Shared_Passive;
10984 ----------------------
10985 -- Source_File_Name --
10986 ----------------------
10988 -- There are five forms for this pragma:
10990 -- pragma Source_File_Name (
10991 -- [UNIT_NAME =>] unit_NAME,
10992 -- BODY_FILE_NAME => STRING_LITERAL
10993 -- [, [INDEX =>] INTEGER_LITERAL]);
10995 -- pragma Source_File_Name (
10996 -- [UNIT_NAME =>] unit_NAME,
10997 -- SPEC_FILE_NAME => STRING_LITERAL
10998 -- [, [INDEX =>] INTEGER_LITERAL]);
11000 -- pragma Source_File_Name (
11001 -- BODY_FILE_NAME => STRING_LITERAL
11002 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11003 -- [, CASING => CASING_SPEC]);
11005 -- pragma Source_File_Name (
11006 -- SPEC_FILE_NAME => STRING_LITERAL
11007 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11008 -- [, CASING => CASING_SPEC]);
11010 -- pragma Source_File_Name (
11011 -- SUBUNIT_FILE_NAME => STRING_LITERAL
11012 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11013 -- [, CASING => CASING_SPEC]);
11015 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
11017 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
11018 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
11019 -- only be used when no project file is used, while SFNP can only be
11020 -- used when a project file is used.
11022 -- No processing here. Processing was completed during parsing, since
11023 -- we need to have file names set as early as possible. Units are
11024 -- loaded well before semantic processing starts.
11026 -- The only processing we defer to this point is the check for
11027 -- correct placement.
11029 when Pragma_Source_File_Name =>
11030 GNAT_Pragma;
11031 Check_Valid_Configuration_Pragma;
11033 ------------------------------
11034 -- Source_File_Name_Project --
11035 ------------------------------
11037 -- See Source_File_Name for syntax
11039 -- No processing here. Processing was completed during parsing, since
11040 -- we need to have file names set as early as possible. Units are
11041 -- loaded well before semantic processing starts.
11043 -- The only processing we defer to this point is the check for
11044 -- correct placement.
11046 when Pragma_Source_File_Name_Project =>
11047 GNAT_Pragma;
11048 Check_Valid_Configuration_Pragma;
11050 -- Check that a pragma Source_File_Name_Project is used only in a
11051 -- configuration pragmas file.
11053 -- Pragmas Source_File_Name_Project should only be generated by
11054 -- the Project Manager in configuration pragmas files.
11056 -- This is really an ugly test. It seems to depend on some
11057 -- accidental and undocumented property. At the very least it
11058 -- needs to be documented, but it would be better to have a
11059 -- clean way of testing if we are in a configuration file???
11061 if Present (Parent (N)) then
11062 Error_Pragma
11063 ("pragma% can only appear in a configuration pragmas file");
11064 end if;
11066 ----------------------
11067 -- Source_Reference --
11068 ----------------------
11070 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
11072 -- Nothing to do, all processing completed in Par.Prag, since we need
11073 -- the information for possible parser messages that are output.
11075 when Pragma_Source_Reference =>
11076 GNAT_Pragma;
11078 --------------------------------
11079 -- Static_Elaboration_Desired --
11080 --------------------------------
11082 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
11084 when Pragma_Static_Elaboration_Desired =>
11085 GNAT_Pragma;
11086 Check_At_Most_N_Arguments (1);
11088 if Is_Compilation_Unit (Current_Scope)
11089 and then Ekind (Current_Scope) = E_Package
11090 then
11091 Set_Static_Elaboration_Desired (Current_Scope, True);
11092 else
11093 Error_Pragma ("pragma% must apply to a library-level package");
11094 end if;
11096 ------------------
11097 -- Storage_Size --
11098 ------------------
11100 -- pragma Storage_Size (EXPRESSION);
11102 when Pragma_Storage_Size => Storage_Size : declare
11103 P : constant Node_Id := Parent (N);
11104 Arg : Node_Id;
11106 begin
11107 Check_No_Identifiers;
11108 Check_Arg_Count (1);
11110 -- The expression must be analyzed in the special manner described
11111 -- in "Handling of Default Expressions" in sem.ads.
11113 Arg := Expression (Arg1);
11114 Preanalyze_Spec_Expression (Arg, Any_Integer);
11116 if not Is_Static_Expression (Arg) then
11117 Check_Restriction (Static_Storage_Size, Arg);
11118 end if;
11120 if Nkind (P) /= N_Task_Definition then
11121 Pragma_Misplaced;
11122 return;
11124 else
11125 if Has_Storage_Size_Pragma (P) then
11126 Error_Pragma ("duplicate pragma% not allowed");
11127 else
11128 Set_Has_Storage_Size_Pragma (P, True);
11129 end if;
11131 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11132 -- ??? exp_ch9 should use this!
11133 end if;
11134 end Storage_Size;
11136 ------------------
11137 -- Storage_Unit --
11138 ------------------
11140 -- pragma Storage_Unit (NUMERIC_LITERAL);
11142 -- Only permitted argument is System'Storage_Unit value
11144 when Pragma_Storage_Unit =>
11145 Check_No_Identifiers;
11146 Check_Arg_Count (1);
11147 Check_Arg_Is_Integer_Literal (Arg1);
11149 if Intval (Expression (Arg1)) /=
11150 UI_From_Int (Ttypes.System_Storage_Unit)
11151 then
11152 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
11153 Error_Pragma_Arg
11154 ("the only allowed argument for pragma% is ^", Arg1);
11155 end if;
11157 --------------------
11158 -- Stream_Convert --
11159 --------------------
11161 -- pragma Stream_Convert (
11162 -- [Entity =>] type_LOCAL_NAME,
11163 -- [Read =>] function_NAME,
11164 -- [Write =>] function NAME);
11166 when Pragma_Stream_Convert => Stream_Convert : declare
11168 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
11169 -- Check that the given argument is the name of a local function
11170 -- of one argument that is not overloaded earlier in the current
11171 -- local scope. A check is also made that the argument is a
11172 -- function with one parameter.
11174 --------------------------------------
11175 -- Check_OK_Stream_Convert_Function --
11176 --------------------------------------
11178 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
11179 Ent : Entity_Id;
11181 begin
11182 Check_Arg_Is_Local_Name (Arg);
11183 Ent := Entity (Expression (Arg));
11185 if Has_Homonym (Ent) then
11186 Error_Pragma_Arg
11187 ("argument for pragma% may not be overloaded", Arg);
11188 end if;
11190 if Ekind (Ent) /= E_Function
11191 or else No (First_Formal (Ent))
11192 or else Present (Next_Formal (First_Formal (Ent)))
11193 then
11194 Error_Pragma_Arg
11195 ("argument for pragma% must be" &
11196 " function of one argument", Arg);
11197 end if;
11198 end Check_OK_Stream_Convert_Function;
11200 -- Start of processing for Stream_Convert
11202 begin
11203 GNAT_Pragma;
11204 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
11205 Check_Arg_Count (3);
11206 Check_Optional_Identifier (Arg1, Name_Entity);
11207 Check_Optional_Identifier (Arg2, Name_Read);
11208 Check_Optional_Identifier (Arg3, Name_Write);
11209 Check_Arg_Is_Local_Name (Arg1);
11210 Check_OK_Stream_Convert_Function (Arg2);
11211 Check_OK_Stream_Convert_Function (Arg3);
11213 declare
11214 Typ : constant Entity_Id :=
11215 Underlying_Type (Entity (Expression (Arg1)));
11216 Read : constant Entity_Id := Entity (Expression (Arg2));
11217 Write : constant Entity_Id := Entity (Expression (Arg3));
11219 begin
11220 Check_First_Subtype (Arg1);
11222 -- Check for too early or too late. Note that we don't enforce
11223 -- the rule about primitive operations in this case, since, as
11224 -- is the case for explicit stream attributes themselves, these
11225 -- restrictions are not appropriate. Note that the chaining of
11226 -- the pragma by Rep_Item_Too_Late is actually the critical
11227 -- processing done for this pragma.
11229 if Rep_Item_Too_Early (Typ, N)
11230 or else
11231 Rep_Item_Too_Late (Typ, N, FOnly => True)
11232 then
11233 return;
11234 end if;
11236 -- Return if previous error
11238 if Etype (Typ) = Any_Type
11239 or else
11240 Etype (Read) = Any_Type
11241 or else
11242 Etype (Write) = Any_Type
11243 then
11244 return;
11245 end if;
11247 -- Error checks
11249 if Underlying_Type (Etype (Read)) /= Typ then
11250 Error_Pragma_Arg
11251 ("incorrect return type for function&", Arg2);
11252 end if;
11254 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
11255 Error_Pragma_Arg
11256 ("incorrect parameter type for function&", Arg3);
11257 end if;
11259 if Underlying_Type (Etype (First_Formal (Read))) /=
11260 Underlying_Type (Etype (Write))
11261 then
11262 Error_Pragma_Arg
11263 ("result type of & does not match Read parameter type",
11264 Arg3);
11265 end if;
11266 end;
11267 end Stream_Convert;
11269 -------------------------
11270 -- Style_Checks (GNAT) --
11271 -------------------------
11273 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11275 -- This is processed by the parser since some of the style checks
11276 -- take place during source scanning and parsing. This means that
11277 -- we don't need to issue error messages here.
11279 when Pragma_Style_Checks => Style_Checks : declare
11280 A : constant Node_Id := Expression (Arg1);
11281 S : String_Id;
11282 C : Char_Code;
11284 begin
11285 GNAT_Pragma;
11286 Check_No_Identifiers;
11288 -- Two argument form
11290 if Arg_Count = 2 then
11291 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11293 declare
11294 E_Id : Node_Id;
11295 E : Entity_Id;
11297 begin
11298 E_Id := Expression (Arg2);
11299 Analyze (E_Id);
11301 if not Is_Entity_Name (E_Id) then
11302 Error_Pragma_Arg
11303 ("second argument of pragma% must be entity name",
11304 Arg2);
11305 end if;
11307 E := Entity (E_Id);
11309 if E = Any_Id then
11310 return;
11311 else
11312 loop
11313 Set_Suppress_Style_Checks (E,
11314 (Chars (Expression (Arg1)) = Name_Off));
11315 exit when No (Homonym (E));
11316 E := Homonym (E);
11317 end loop;
11318 end if;
11319 end;
11321 -- One argument form
11323 else
11324 Check_Arg_Count (1);
11326 if Nkind (A) = N_String_Literal then
11327 S := Strval (A);
11329 declare
11330 Slen : constant Natural := Natural (String_Length (S));
11331 Options : String (1 .. Slen);
11332 J : Natural;
11334 begin
11335 J := 1;
11336 loop
11337 C := Get_String_Char (S, Int (J));
11338 exit when not In_Character_Range (C);
11339 Options (J) := Get_Character (C);
11341 -- If at end of string, set options. As per discussion
11342 -- above, no need to check for errors, since we issued
11343 -- them in the parser.
11345 if J = Slen then
11346 Set_Style_Check_Options (Options);
11347 exit;
11348 end if;
11350 J := J + 1;
11351 end loop;
11352 end;
11354 elsif Nkind (A) = N_Identifier then
11355 if Chars (A) = Name_All_Checks then
11356 if GNAT_Mode then
11357 Set_GNAT_Style_Check_Options;
11358 else
11359 Set_Default_Style_Check_Options;
11360 end if;
11362 elsif Chars (A) = Name_On then
11363 Style_Check := True;
11365 elsif Chars (A) = Name_Off then
11366 Style_Check := False;
11367 end if;
11368 end if;
11369 end if;
11370 end Style_Checks;
11372 --------------
11373 -- Subtitle --
11374 --------------
11376 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
11378 when Pragma_Subtitle =>
11379 GNAT_Pragma;
11380 Check_Arg_Count (1);
11381 Check_Optional_Identifier (Arg1, Name_Subtitle);
11382 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11383 Store_Note (N);
11385 --------------
11386 -- Suppress --
11387 --------------
11389 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
11391 when Pragma_Suppress =>
11392 Process_Suppress_Unsuppress (True);
11394 ------------------
11395 -- Suppress_All --
11396 ------------------
11398 -- pragma Suppress_All;
11400 -- The only check made here is that the pragma appears in the proper
11401 -- place, i.e. following a compilation unit. If indeed it appears in
11402 -- this context, then the parser has already inserted an equivalent
11403 -- pragma Suppress (All_Checks) to get the required effect.
11405 when Pragma_Suppress_All =>
11406 GNAT_Pragma;
11407 Check_Arg_Count (0);
11409 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
11410 or else not Is_List_Member (N)
11411 or else List_Containing (N) /= Pragmas_After (Parent (N))
11412 then
11413 Error_Pragma
11414 ("misplaced pragma%, must follow compilation unit");
11415 end if;
11417 -------------------------
11418 -- Suppress_Debug_Info --
11419 -------------------------
11421 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
11423 when Pragma_Suppress_Debug_Info =>
11424 GNAT_Pragma;
11425 Check_Arg_Count (1);
11426 Check_Optional_Identifier (Arg1, Name_Entity);
11427 Check_Arg_Is_Local_Name (Arg1);
11428 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
11430 ----------------------------------
11431 -- Suppress_Exception_Locations --
11432 ----------------------------------
11434 -- pragma Suppress_Exception_Locations;
11436 when Pragma_Suppress_Exception_Locations =>
11437 GNAT_Pragma;
11438 Check_Arg_Count (0);
11439 Check_Valid_Configuration_Pragma;
11440 Exception_Locations_Suppressed := True;
11442 -----------------------------
11443 -- Suppress_Initialization --
11444 -----------------------------
11446 -- pragma Suppress_Initialization ([Entity =>] type_Name);
11448 when Pragma_Suppress_Initialization => Suppress_Init : declare
11449 E_Id : Node_Id;
11450 E : Entity_Id;
11452 begin
11453 GNAT_Pragma;
11454 Check_Arg_Count (1);
11455 Check_Optional_Identifier (Arg1, Name_Entity);
11456 Check_Arg_Is_Local_Name (Arg1);
11458 E_Id := Expression (Arg1);
11460 if Etype (E_Id) = Any_Type then
11461 return;
11462 end if;
11464 E := Entity (E_Id);
11466 if Is_Type (E) then
11467 if Is_Incomplete_Or_Private_Type (E) then
11468 if No (Full_View (Base_Type (E))) then
11469 Error_Pragma_Arg
11470 ("argument of pragma% cannot be an incomplete type",
11471 Arg1);
11472 else
11473 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
11474 end if;
11475 else
11476 Set_Suppress_Init_Proc (Base_Type (E));
11477 end if;
11479 else
11480 Error_Pragma_Arg
11481 ("pragma% requires argument that is a type name", Arg1);
11482 end if;
11483 end Suppress_Init;
11485 -----------------
11486 -- System_Name --
11487 -----------------
11489 -- pragma System_Name (DIRECT_NAME);
11491 -- Syntax check: one argument, which must be the identifier GNAT or
11492 -- the identifier GCC, no other identifiers are acceptable.
11494 when Pragma_System_Name =>
11495 GNAT_Pragma;
11496 Check_No_Identifiers;
11497 Check_Arg_Count (1);
11498 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
11500 -----------------------------
11501 -- Task_Dispatching_Policy --
11502 -----------------------------
11504 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
11506 when Pragma_Task_Dispatching_Policy => declare
11507 DP : Character;
11509 begin
11510 Check_Ada_83_Warning;
11511 Check_Arg_Count (1);
11512 Check_No_Identifiers;
11513 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11514 Check_Valid_Configuration_Pragma;
11515 Get_Name_String (Chars (Expression (Arg1)));
11516 DP := Fold_Upper (Name_Buffer (1));
11518 if Task_Dispatching_Policy /= ' '
11519 and then Task_Dispatching_Policy /= DP
11520 then
11521 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11522 Error_Pragma
11523 ("task dispatching policy incompatible with policy#");
11525 -- Set new policy, but always preserve System_Location since we
11526 -- like the error message with the run time name.
11528 else
11529 Task_Dispatching_Policy := DP;
11531 if Task_Dispatching_Policy_Sloc /= System_Location then
11532 Task_Dispatching_Policy_Sloc := Loc;
11533 end if;
11534 end if;
11535 end;
11537 --------------
11538 -- Task_Info --
11539 --------------
11541 -- pragma Task_Info (EXPRESSION);
11543 when Pragma_Task_Info => Task_Info : declare
11544 P : constant Node_Id := Parent (N);
11546 begin
11547 GNAT_Pragma;
11549 if Nkind (P) /= N_Task_Definition then
11550 Error_Pragma ("pragma% must appear in task definition");
11551 end if;
11553 Check_No_Identifiers;
11554 Check_Arg_Count (1);
11556 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
11558 if Etype (Expression (Arg1)) = Any_Type then
11559 return;
11560 end if;
11562 if Has_Task_Info_Pragma (P) then
11563 Error_Pragma ("duplicate pragma% not allowed");
11564 else
11565 Set_Has_Task_Info_Pragma (P, True);
11566 end if;
11567 end Task_Info;
11569 ---------------
11570 -- Task_Name --
11571 ---------------
11573 -- pragma Task_Name (string_EXPRESSION);
11575 when Pragma_Task_Name => Task_Name : declare
11576 P : constant Node_Id := Parent (N);
11577 Arg : Node_Id;
11579 begin
11580 Check_No_Identifiers;
11581 Check_Arg_Count (1);
11583 Arg := Expression (Arg1);
11585 -- The expression is used in the call to Create_Task, and must be
11586 -- expanded there, not in the context of the current spec. It must
11587 -- however be analyzed to capture global references, in case it
11588 -- appears in a generic context.
11590 Preanalyze_And_Resolve (Arg, Standard_String);
11592 if Nkind (P) /= N_Task_Definition then
11593 Pragma_Misplaced;
11594 end if;
11596 if Has_Task_Name_Pragma (P) then
11597 Error_Pragma ("duplicate pragma% not allowed");
11598 else
11599 Set_Has_Task_Name_Pragma (P, True);
11600 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11601 end if;
11602 end Task_Name;
11604 ------------------
11605 -- Task_Storage --
11606 ------------------
11608 -- pragma Task_Storage (
11609 -- [Task_Type =>] LOCAL_NAME,
11610 -- [Top_Guard =>] static_integer_EXPRESSION);
11612 when Pragma_Task_Storage => Task_Storage : declare
11613 Args : Args_List (1 .. 2);
11614 Names : constant Name_List (1 .. 2) := (
11615 Name_Task_Type,
11616 Name_Top_Guard);
11618 Task_Type : Node_Id renames Args (1);
11619 Top_Guard : Node_Id renames Args (2);
11621 Ent : Entity_Id;
11623 begin
11624 GNAT_Pragma;
11625 Gather_Associations (Names, Args);
11627 if No (Task_Type) then
11628 Error_Pragma
11629 ("missing task_type argument for pragma%");
11630 end if;
11632 Check_Arg_Is_Local_Name (Task_Type);
11634 Ent := Entity (Task_Type);
11636 if not Is_Task_Type (Ent) then
11637 Error_Pragma_Arg
11638 ("argument for pragma% must be task type", Task_Type);
11639 end if;
11641 if No (Top_Guard) then
11642 Error_Pragma_Arg
11643 ("pragma% takes two arguments", Task_Type);
11644 else
11645 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
11646 end if;
11648 Check_First_Subtype (Task_Type);
11650 if Rep_Item_Too_Late (Ent, N) then
11651 raise Pragma_Exit;
11652 end if;
11653 end Task_Storage;
11655 --------------------------
11656 -- Thread_Local_Storage --
11657 --------------------------
11659 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
11661 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
11662 Id : Node_Id;
11663 E : Entity_Id;
11665 begin
11666 GNAT_Pragma;
11667 Check_Arg_Count (1);
11668 Check_Optional_Identifier (Arg1, Name_Entity);
11669 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11671 Id := Expression (Arg1);
11672 Analyze (Id);
11674 if not Is_Entity_Name (Id)
11675 or else Ekind (Entity (Id)) /= E_Variable
11676 then
11677 Error_Pragma_Arg ("local variable name required", Arg1);
11678 end if;
11680 E := Entity (Id);
11682 if Rep_Item_Too_Early (E, N)
11683 or else Rep_Item_Too_Late (E, N)
11684 then
11685 raise Pragma_Exit;
11686 end if;
11688 Set_Has_Pragma_Thread_Local_Storage (E);
11689 Set_Has_Gigi_Rep_Item (E);
11690 end Thread_Local_Storage;
11692 ----------------
11693 -- Time_Slice --
11694 ----------------
11696 -- pragma Time_Slice (static_duration_EXPRESSION);
11698 when Pragma_Time_Slice => Time_Slice : declare
11699 Val : Ureal;
11700 Nod : Node_Id;
11702 begin
11703 GNAT_Pragma;
11704 Check_Arg_Count (1);
11705 Check_No_Identifiers;
11706 Check_In_Main_Program;
11707 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
11709 if not Error_Posted (Arg1) then
11710 Nod := Next (N);
11711 while Present (Nod) loop
11712 if Nkind (Nod) = N_Pragma
11713 and then Pragma_Name (Nod) = Name_Time_Slice
11714 then
11715 Error_Msg_Name_1 := Pname;
11716 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11717 end if;
11719 Next (Nod);
11720 end loop;
11721 end if;
11723 -- Process only if in main unit
11725 if Get_Source_Unit (Loc) = Main_Unit then
11726 Opt.Time_Slice_Set := True;
11727 Val := Expr_Value_R (Expression (Arg1));
11729 if Val <= Ureal_0 then
11730 Opt.Time_Slice_Value := 0;
11732 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
11733 Opt.Time_Slice_Value := 1_000_000_000;
11735 else
11736 Opt.Time_Slice_Value :=
11737 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
11738 end if;
11739 end if;
11740 end Time_Slice;
11742 -----------
11743 -- Title --
11744 -----------
11746 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
11748 -- TITLING_OPTION ::=
11749 -- [Title =>] STRING_LITERAL
11750 -- | [Subtitle =>] STRING_LITERAL
11752 when Pragma_Title => Title : declare
11753 Args : Args_List (1 .. 2);
11754 Names : constant Name_List (1 .. 2) := (
11755 Name_Title,
11756 Name_Subtitle);
11758 begin
11759 GNAT_Pragma;
11760 Gather_Associations (Names, Args);
11761 Store_Note (N);
11763 for J in 1 .. 2 loop
11764 if Present (Args (J)) then
11765 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
11766 end if;
11767 end loop;
11768 end Title;
11770 ---------------------
11771 -- Unchecked_Union --
11772 ---------------------
11774 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
11776 when Pragma_Unchecked_Union => Unchecked_Union : declare
11777 Assoc : constant Node_Id := Arg1;
11778 Type_Id : constant Node_Id := Expression (Assoc);
11779 Typ : Entity_Id;
11780 Discr : Entity_Id;
11781 Tdef : Node_Id;
11782 Clist : Node_Id;
11783 Vpart : Node_Id;
11784 Comp : Node_Id;
11785 Variant : Node_Id;
11787 begin
11788 Ada_2005_Pragma;
11789 Check_No_Identifiers;
11790 Check_Arg_Count (1);
11791 Check_Arg_Is_Local_Name (Arg1);
11793 Find_Type (Type_Id);
11794 Typ := Entity (Type_Id);
11796 if Typ = Any_Type
11797 or else Rep_Item_Too_Early (Typ, N)
11798 then
11799 return;
11800 else
11801 Typ := Underlying_Type (Typ);
11802 end if;
11804 if Rep_Item_Too_Late (Typ, N) then
11805 return;
11806 end if;
11808 Check_First_Subtype (Arg1);
11810 -- Note remaining cases are references to a type in the current
11811 -- declarative part. If we find an error, we post the error on
11812 -- the relevant type declaration at an appropriate point.
11814 if not Is_Record_Type (Typ) then
11815 Error_Msg_N ("Unchecked_Union must be record type", Typ);
11816 return;
11818 elsif Is_Tagged_Type (Typ) then
11819 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
11820 return;
11822 elsif Is_Limited_Type (Typ) then
11823 Error_Msg_N
11824 ("Unchecked_Union must not be limited record type", Typ);
11825 Explain_Limited_Type (Typ, Typ);
11826 return;
11828 else
11829 if not Has_Discriminants (Typ) then
11830 Error_Msg_N
11831 ("Unchecked_Union must have one discriminant", Typ);
11832 return;
11833 end if;
11835 Discr := First_Discriminant (Typ);
11836 while Present (Discr) loop
11837 if No (Discriminant_Default_Value (Discr)) then
11838 Error_Msg_N
11839 ("Unchecked_Union discriminant must have default value",
11840 Discr);
11841 end if;
11842 Next_Discriminant (Discr);
11843 end loop;
11845 Tdef := Type_Definition (Declaration_Node (Typ));
11846 Clist := Component_List (Tdef);
11848 Comp := First (Component_Items (Clist));
11849 while Present (Comp) loop
11850 Check_Component (Comp);
11851 Next (Comp);
11852 end loop;
11854 if No (Clist) or else No (Variant_Part (Clist)) then
11855 Error_Msg_N
11856 ("Unchecked_Union must have variant part",
11857 Tdef);
11858 return;
11859 end if;
11861 Vpart := Variant_Part (Clist);
11863 Variant := First (Variants (Vpart));
11864 while Present (Variant) loop
11865 Check_Variant (Variant);
11866 Next (Variant);
11867 end loop;
11868 end if;
11870 Set_Is_Unchecked_Union (Typ, True);
11871 Set_Convention (Typ, Convention_C);
11873 Set_Has_Unchecked_Union (Base_Type (Typ), True);
11874 Set_Is_Unchecked_Union (Base_Type (Typ), True);
11875 end Unchecked_Union;
11877 ------------------------
11878 -- Unimplemented_Unit --
11879 ------------------------
11881 -- pragma Unimplemented_Unit;
11883 -- Note: this only gives an error if we are generating code, or if
11884 -- we are in a generic library unit (where the pragma appears in the
11885 -- body, not in the spec).
11887 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
11888 Cunitent : constant Entity_Id :=
11889 Cunit_Entity (Get_Source_Unit (Loc));
11890 Ent_Kind : constant Entity_Kind :=
11891 Ekind (Cunitent);
11893 begin
11894 GNAT_Pragma;
11895 Check_Arg_Count (0);
11897 if Operating_Mode = Generate_Code
11898 or else Ent_Kind = E_Generic_Function
11899 or else Ent_Kind = E_Generic_Procedure
11900 or else Ent_Kind = E_Generic_Package
11901 then
11902 Get_Name_String (Chars (Cunitent));
11903 Set_Casing (Mixed_Case);
11904 Write_Str (Name_Buffer (1 .. Name_Len));
11905 Write_Str (" is not supported in this configuration");
11906 Write_Eol;
11907 raise Unrecoverable_Error;
11908 end if;
11909 end Unimplemented_Unit;
11911 ------------------------
11912 -- Universal_Aliasing --
11913 ------------------------
11915 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
11917 when Pragma_Universal_Aliasing => Universal_Alias : declare
11918 E_Id : Entity_Id;
11920 begin
11921 GNAT_Pragma;
11922 Check_Arg_Count (1);
11923 Check_Optional_Identifier (Arg2, Name_Entity);
11924 Check_Arg_Is_Local_Name (Arg1);
11925 E_Id := Entity (Expression (Arg1));
11927 if E_Id = Any_Type then
11928 return;
11929 elsif No (E_Id) or else not Is_Type (E_Id) then
11930 Error_Pragma_Arg ("pragma% requires type", Arg1);
11931 end if;
11933 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
11934 end Universal_Alias;
11936 --------------------
11937 -- Universal_Data --
11938 --------------------
11940 -- pragma Universal_Data [(library_unit_NAME)];
11942 when Pragma_Universal_Data =>
11943 GNAT_Pragma;
11945 -- If this is a configuration pragma, then set the universal
11946 -- addressing option, otherwise confirm that the pragma satisfies
11947 -- the requirements of library unit pragma placement and leave it
11948 -- to the GNAAMP back end to detect the pragma (avoids transitive
11949 -- setting of the option due to withed units).
11951 if Is_Configuration_Pragma then
11952 Universal_Addressing_On_AAMP := True;
11953 else
11954 Check_Valid_Library_Unit_Pragma;
11955 end if;
11957 if not AAMP_On_Target then
11958 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
11959 end if;
11961 ----------------
11962 -- Unmodified --
11963 ----------------
11965 -- pragma Unmodified (local_Name {, local_Name});
11967 when Pragma_Unmodified => Unmodified : declare
11968 Arg_Node : Node_Id;
11969 Arg_Expr : Node_Id;
11970 Arg_Ent : Entity_Id;
11972 begin
11973 GNAT_Pragma;
11974 Check_At_Least_N_Arguments (1);
11976 -- Loop through arguments
11978 Arg_Node := Arg1;
11979 while Present (Arg_Node) loop
11980 Check_No_Identifier (Arg_Node);
11982 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
11983 -- in fact generate reference, so that the entity will have a
11984 -- reference, which will inhibit any warnings about it not
11985 -- being referenced, and also properly show up in the ali file
11986 -- as a reference. But this reference is recorded before the
11987 -- Has_Pragma_Unreferenced flag is set, so that no warning is
11988 -- generated for this reference.
11990 Check_Arg_Is_Local_Name (Arg_Node);
11991 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11993 if Is_Entity_Name (Arg_Expr) then
11994 Arg_Ent := Entity (Arg_Expr);
11996 if not Is_Assignable (Arg_Ent) then
11997 Error_Pragma_Arg
11998 ("pragma% can only be applied to a variable",
11999 Arg_Expr);
12000 else
12001 Set_Has_Pragma_Unmodified (Arg_Ent);
12002 end if;
12003 end if;
12005 Next (Arg_Node);
12006 end loop;
12007 end Unmodified;
12009 ------------------
12010 -- Unreferenced --
12011 ------------------
12013 -- pragma Unreferenced (local_Name {, local_Name});
12015 -- or when used in a context clause:
12017 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
12019 when Pragma_Unreferenced => Unreferenced : declare
12020 Arg_Node : Node_Id;
12021 Arg_Expr : Node_Id;
12022 Arg_Ent : Entity_Id;
12023 Citem : Node_Id;
12025 begin
12026 GNAT_Pragma;
12027 Check_At_Least_N_Arguments (1);
12029 -- Check case of appearing within context clause
12031 if Is_In_Context_Clause then
12033 -- The arguments must all be units mentioned in a with clause
12034 -- in the same context clause. Note we already checked (in
12035 -- Par.Prag) that the arguments are either identifiers or
12036 -- selected components.
12038 Arg_Node := Arg1;
12039 while Present (Arg_Node) loop
12040 Citem := First (List_Containing (N));
12041 while Citem /= N loop
12042 if Nkind (Citem) = N_With_Clause
12043 and then Same_Name (Name (Citem), Expression (Arg_Node))
12044 then
12045 Set_Has_Pragma_Unreferenced
12046 (Cunit_Entity
12047 (Get_Source_Unit
12048 (Library_Unit (Citem))));
12049 Set_Unit_Name (Expression (Arg_Node), Name (Citem));
12050 exit;
12051 end if;
12053 Next (Citem);
12054 end loop;
12056 if Citem = N then
12057 Error_Pragma_Arg
12058 ("argument of pragma% is not with'ed unit", Arg_Node);
12059 end if;
12061 Next (Arg_Node);
12062 end loop;
12064 -- Case of not in list of context items
12066 else
12067 Arg_Node := Arg1;
12068 while Present (Arg_Node) loop
12069 Check_No_Identifier (Arg_Node);
12071 -- Note: the analyze call done by Check_Arg_Is_Local_Name
12072 -- will in fact generate reference, so that the entity will
12073 -- have a reference, which will inhibit any warnings about
12074 -- it not being referenced, and also properly show up in the
12075 -- ali file as a reference. But this reference is recorded
12076 -- before the Has_Pragma_Unreferenced flag is set, so that
12077 -- no warning is generated for this reference.
12079 Check_Arg_Is_Local_Name (Arg_Node);
12080 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12082 if Is_Entity_Name (Arg_Expr) then
12083 Arg_Ent := Entity (Arg_Expr);
12085 -- If the entity is overloaded, the pragma applies to the
12086 -- most recent overloading, as documented. In this case,
12087 -- name resolution does not generate a reference, so it
12088 -- must be done here explicitly.
12090 if Is_Overloaded (Arg_Expr) then
12091 Generate_Reference (Arg_Ent, N);
12092 end if;
12094 Set_Has_Pragma_Unreferenced (Arg_Ent);
12095 end if;
12097 Next (Arg_Node);
12098 end loop;
12099 end if;
12100 end Unreferenced;
12102 --------------------------
12103 -- Unreferenced_Objects --
12104 --------------------------
12106 -- pragma Unreferenced_Objects (local_Name {, local_Name});
12108 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
12109 Arg_Node : Node_Id;
12110 Arg_Expr : Node_Id;
12112 begin
12113 GNAT_Pragma;
12114 Check_At_Least_N_Arguments (1);
12116 Arg_Node := Arg1;
12117 while Present (Arg_Node) loop
12118 Check_No_Identifier (Arg_Node);
12119 Check_Arg_Is_Local_Name (Arg_Node);
12120 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12122 if not Is_Entity_Name (Arg_Expr)
12123 or else not Is_Type (Entity (Arg_Expr))
12124 then
12125 Error_Pragma_Arg
12126 ("argument for pragma% must be type or subtype", Arg_Node);
12127 end if;
12129 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
12130 Next (Arg_Node);
12131 end loop;
12132 end Unreferenced_Objects;
12134 ------------------------------
12135 -- Unreserve_All_Interrupts --
12136 ------------------------------
12138 -- pragma Unreserve_All_Interrupts;
12140 when Pragma_Unreserve_All_Interrupts =>
12141 GNAT_Pragma;
12142 Check_Arg_Count (0);
12144 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
12145 Unreserve_All_Interrupts := True;
12146 end if;
12148 ----------------
12149 -- Unsuppress --
12150 ----------------
12152 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
12154 when Pragma_Unsuppress =>
12155 Ada_2005_Pragma;
12156 Process_Suppress_Unsuppress (False);
12158 -------------------
12159 -- Use_VADS_Size --
12160 -------------------
12162 -- pragma Use_VADS_Size;
12164 when Pragma_Use_VADS_Size =>
12165 GNAT_Pragma;
12166 Check_Arg_Count (0);
12167 Check_Valid_Configuration_Pragma;
12168 Use_VADS_Size := True;
12170 ---------------------
12171 -- Validity_Checks --
12172 ---------------------
12174 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12176 when Pragma_Validity_Checks => Validity_Checks : declare
12177 A : constant Node_Id := Expression (Arg1);
12178 S : String_Id;
12179 C : Char_Code;
12181 begin
12182 GNAT_Pragma;
12183 Check_Arg_Count (1);
12184 Check_No_Identifiers;
12186 if Nkind (A) = N_String_Literal then
12187 S := Strval (A);
12189 declare
12190 Slen : constant Natural := Natural (String_Length (S));
12191 Options : String (1 .. Slen);
12192 J : Natural;
12194 begin
12195 J := 1;
12196 loop
12197 C := Get_String_Char (S, Int (J));
12198 exit when not In_Character_Range (C);
12199 Options (J) := Get_Character (C);
12201 if J = Slen then
12202 Set_Validity_Check_Options (Options);
12203 exit;
12204 else
12205 J := J + 1;
12206 end if;
12207 end loop;
12208 end;
12210 elsif Nkind (A) = N_Identifier then
12212 if Chars (A) = Name_All_Checks then
12213 Set_Validity_Check_Options ("a");
12215 elsif Chars (A) = Name_On then
12216 Validity_Checks_On := True;
12218 elsif Chars (A) = Name_Off then
12219 Validity_Checks_On := False;
12221 end if;
12222 end if;
12223 end Validity_Checks;
12225 --------------
12226 -- Volatile --
12227 --------------
12229 -- pragma Volatile (LOCAL_NAME);
12231 when Pragma_Volatile =>
12232 Process_Atomic_Shared_Volatile;
12234 -------------------------
12235 -- Volatile_Components --
12236 -------------------------
12238 -- pragma Volatile_Components (array_LOCAL_NAME);
12240 -- Volatile is handled by the same circuit as Atomic_Components
12242 --------------
12243 -- Warnings --
12244 --------------
12246 -- pragma Warnings (On | Off);
12247 -- pragma Warnings (On | Off, LOCAL_NAME);
12248 -- pragma Warnings (static_string_EXPRESSION);
12249 -- pragma Warnings (On | Off, STRING_LITERAL);
12251 when Pragma_Warnings => Warnings : begin
12252 GNAT_Pragma;
12253 Check_At_Least_N_Arguments (1);
12254 Check_No_Identifiers;
12256 -- If debug flag -gnatd.i is set, pragma is ignored
12258 if Debug_Flag_Dot_I then
12259 return;
12260 end if;
12262 -- Process various forms of the pragma
12264 declare
12265 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12267 begin
12268 -- One argument case
12270 if Arg_Count = 1 then
12272 -- On/Off one argument case was processed by parser
12274 if Nkind (Argx) = N_Identifier
12275 and then
12276 (Chars (Argx) = Name_On
12277 or else
12278 Chars (Argx) = Name_Off)
12279 then
12280 null;
12282 -- One argument case must be ON/OFF or static string expr
12284 elsif not Is_Static_String_Expression (Arg1) then
12285 Error_Pragma_Arg
12286 ("argument of pragma% must be On/Off or " &
12287 "static string expression", Arg1);
12289 -- One argument string expression case
12291 else
12292 declare
12293 Lit : constant Node_Id := Expr_Value_S (Argx);
12294 Str : constant String_Id := Strval (Lit);
12295 Len : constant Nat := String_Length (Str);
12296 C : Char_Code;
12297 J : Nat;
12298 OK : Boolean;
12299 Chr : Character;
12301 begin
12302 J := 1;
12303 while J <= Len loop
12304 C := Get_String_Char (Str, J);
12305 OK := In_Character_Range (C);
12307 if OK then
12308 Chr := Get_Character (C);
12310 -- Dot case
12312 if J < Len and then Chr = '.' then
12313 J := J + 1;
12314 C := Get_String_Char (Str, J);
12315 Chr := Get_Character (C);
12317 if not Set_Dot_Warning_Switch (Chr) then
12318 Error_Pragma_Arg
12319 ("invalid warning switch character " &
12320 '.' & Chr, Arg1);
12321 end if;
12323 -- Non-Dot case
12325 else
12326 OK := Set_Warning_Switch (Chr);
12327 end if;
12328 end if;
12330 if not OK then
12331 Error_Pragma_Arg
12332 ("invalid warning switch character " & Chr,
12333 Arg1);
12334 end if;
12336 J := J + 1;
12337 end loop;
12338 end;
12339 end if;
12341 -- Two or more arguments (must be two)
12343 else
12344 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12345 Check_At_Most_N_Arguments (2);
12347 declare
12348 E_Id : Node_Id;
12349 E : Entity_Id;
12350 Err : Boolean;
12352 begin
12353 E_Id := Expression (Arg2);
12354 Analyze (E_Id);
12356 -- In the expansion of an inlined body, a reference to
12357 -- the formal may be wrapped in a conversion if the
12358 -- actual is a conversion. Retrieve the real entity name.
12360 if (In_Instance_Body
12361 or else In_Inlined_Body)
12362 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
12363 then
12364 E_Id := Expression (E_Id);
12365 end if;
12367 -- Entity name case
12369 if Is_Entity_Name (E_Id) then
12370 E := Entity (E_Id);
12372 if E = Any_Id then
12373 return;
12374 else
12375 loop
12376 Set_Warnings_Off
12377 (E, (Chars (Expression (Arg1)) = Name_Off));
12379 if Chars (Expression (Arg1)) = Name_Off
12380 and then Warn_On_Warnings_Off
12381 then
12382 Warnings_Off_Pragmas.Append ((N, E));
12383 end if;
12385 if Is_Enumeration_Type (E) then
12386 declare
12387 Lit : Entity_Id;
12388 begin
12389 Lit := First_Literal (E);
12390 while Present (Lit) loop
12391 Set_Warnings_Off (Lit);
12392 Next_Literal (Lit);
12393 end loop;
12394 end;
12395 end if;
12397 exit when No (Homonym (E));
12398 E := Homonym (E);
12399 end loop;
12400 end if;
12402 -- Error if not entity or static string literal case
12404 elsif not Is_Static_String_Expression (Arg2) then
12405 Error_Pragma_Arg
12406 ("second argument of pragma% must be entity " &
12407 "name or static string expression", Arg2);
12409 -- String literal case
12411 else
12412 String_To_Name_Buffer
12413 (Strval (Expr_Value_S (Expression (Arg2))));
12415 -- Note on configuration pragma case: If this is a
12416 -- configuration pragma, then for an OFF pragma, we
12417 -- just set Config True in the call, which is all
12418 -- that needs to be done. For the case of ON, this
12419 -- is normally an error, unless it is canceling the
12420 -- effect of a previous OFF pragma in the same file.
12421 -- In any other case, an error will be signalled (ON
12422 -- with no matching OFF).
12424 if Chars (Argx) = Name_Off then
12425 Set_Specific_Warning_Off
12426 (Loc, Name_Buffer (1 .. Name_Len),
12427 Config => Is_Configuration_Pragma);
12429 elsif Chars (Argx) = Name_On then
12430 Set_Specific_Warning_On
12431 (Loc, Name_Buffer (1 .. Name_Len), Err);
12433 if Err then
12434 Error_Msg
12435 ("?pragma Warnings On with no " &
12436 "matching Warnings Off",
12437 Loc);
12438 end if;
12439 end if;
12440 end if;
12441 end;
12442 end if;
12443 end;
12444 end Warnings;
12446 -------------------
12447 -- Weak_External --
12448 -------------------
12450 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
12452 when Pragma_Weak_External => Weak_External : declare
12453 Ent : Entity_Id;
12455 begin
12456 GNAT_Pragma;
12457 Check_Arg_Count (1);
12458 Check_Optional_Identifier (Arg1, Name_Entity);
12459 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12460 Ent := Entity (Expression (Arg1));
12462 if Rep_Item_Too_Early (Ent, N) then
12463 return;
12464 else
12465 Ent := Underlying_Type (Ent);
12466 end if;
12468 -- The only processing required is to link this item on to the
12469 -- list of rep items for the given entity. This is accomplished
12470 -- by the call to Rep_Item_Too_Late (when no error is detected
12471 -- and False is returned).
12473 if Rep_Item_Too_Late (Ent, N) then
12474 return;
12475 else
12476 Set_Has_Gigi_Rep_Item (Ent);
12477 end if;
12478 end Weak_External;
12480 -----------------------------
12481 -- Wide_Character_Encoding --
12482 -----------------------------
12484 -- pragma Wide_Character_Encoding (IDENTIFIER);
12486 when Pragma_Wide_Character_Encoding =>
12487 GNAT_Pragma;
12489 -- Nothing to do, handled in parser. Note that we do not enforce
12490 -- configuration pragma placement, this pragma can appear at any
12491 -- place in the source, allowing mixed encodings within a single
12492 -- source program.
12494 null;
12496 --------------------
12497 -- Unknown_Pragma --
12498 --------------------
12500 -- Should be impossible, since the case of an unknown pragma is
12501 -- separately processed before the case statement is entered.
12503 when Unknown_Pragma =>
12504 raise Program_Error;
12505 end case;
12507 -- AI05-0144: detect dangerous order dependence. Disabled for now,
12508 -- until AI is formally approved.
12510 -- Check_Order_Dependence;
12512 exception
12513 when Pragma_Exit => null;
12514 end Analyze_Pragma;
12516 -------------------
12517 -- Check_Enabled --
12518 -------------------
12520 function Check_Enabled (Nam : Name_Id) return Boolean is
12521 PP : Node_Id;
12523 begin
12524 PP := Opt.Check_Policy_List;
12525 loop
12526 if No (PP) then
12527 return Assertions_Enabled;
12529 elsif
12530 Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
12531 then
12532 case
12533 Chars (Expression (Last (Pragma_Argument_Associations (PP))))
12535 when Name_On | Name_Check =>
12536 return True;
12537 when Name_Off | Name_Ignore =>
12538 return False;
12539 when others =>
12540 raise Program_Error;
12541 end case;
12543 else
12544 PP := Next_Pragma (PP);
12545 end if;
12546 end loop;
12547 end Check_Enabled;
12549 ---------------------------------
12550 -- Delay_Config_Pragma_Analyze --
12551 ---------------------------------
12553 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
12554 begin
12555 return Pragma_Name (N) = Name_Interrupt_State
12556 or else
12557 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
12558 end Delay_Config_Pragma_Analyze;
12560 -------------------------
12561 -- Get_Base_Subprogram --
12562 -------------------------
12564 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
12565 Result : Entity_Id;
12567 begin
12568 -- Follow subprogram renaming chain
12570 Result := Def_Id;
12571 while Is_Subprogram (Result)
12572 and then
12573 (Is_Generic_Instance (Result)
12574 or else Nkind (Parent (Declaration_Node (Result))) =
12575 N_Subprogram_Renaming_Declaration)
12576 and then Present (Alias (Result))
12577 loop
12578 Result := Alias (Result);
12579 end loop;
12581 return Result;
12582 end Get_Base_Subprogram;
12584 --------------------
12585 -- Get_Pragma_Arg --
12586 --------------------
12588 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
12589 begin
12590 if Nkind (Arg) = N_Pragma_Argument_Association then
12591 return Expression (Arg);
12592 else
12593 return Arg;
12594 end if;
12595 end Get_Pragma_Arg;
12597 ----------------
12598 -- Initialize --
12599 ----------------
12601 procedure Initialize is
12602 begin
12603 Externals.Init;
12604 end Initialize;
12606 -----------------------------
12607 -- Is_Config_Static_String --
12608 -----------------------------
12610 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
12612 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
12613 -- This is an internal recursive function that is just like the outer
12614 -- function except that it adds the string to the name buffer rather
12615 -- than placing the string in the name buffer.
12617 ------------------------------
12618 -- Add_Config_Static_String --
12619 ------------------------------
12621 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
12622 N : Node_Id;
12623 C : Char_Code;
12625 begin
12626 N := Arg;
12628 if Nkind (N) = N_Op_Concat then
12629 if Add_Config_Static_String (Left_Opnd (N)) then
12630 N := Right_Opnd (N);
12631 else
12632 return False;
12633 end if;
12634 end if;
12636 if Nkind (N) /= N_String_Literal then
12637 Error_Msg_N ("string literal expected for pragma argument", N);
12638 return False;
12640 else
12641 for J in 1 .. String_Length (Strval (N)) loop
12642 C := Get_String_Char (Strval (N), J);
12644 if not In_Character_Range (C) then
12645 Error_Msg
12646 ("string literal contains invalid wide character",
12647 Sloc (N) + 1 + Source_Ptr (J));
12648 return False;
12649 end if;
12651 Add_Char_To_Name_Buffer (Get_Character (C));
12652 end loop;
12653 end if;
12655 return True;
12656 end Add_Config_Static_String;
12658 -- Start of processing for Is_Config_Static_String
12660 begin
12662 Name_Len := 0;
12663 return Add_Config_Static_String (Arg);
12664 end Is_Config_Static_String;
12666 -----------------------------------------
12667 -- Is_Non_Significant_Pragma_Reference --
12668 -----------------------------------------
12670 -- This function makes use of the following static table which indicates
12671 -- whether a given pragma is significant.
12673 -- -1 indicates that references in any argument position are significant
12674 -- 0 indicates that appearence in any argument is not significant
12675 -- +n indicates that appearence as argument n is significant, but all
12676 -- other arguments are not significant
12677 -- 99 special processing required (e.g. for pragma Check)
12679 Sig_Flags : constant array (Pragma_Id) of Int :=
12680 (Pragma_AST_Entry => -1,
12681 Pragma_Abort_Defer => -1,
12682 Pragma_Ada_83 => -1,
12683 Pragma_Ada_95 => -1,
12684 Pragma_Ada_05 => -1,
12685 Pragma_Ada_2005 => -1,
12686 Pragma_Ada_12 => -1,
12687 Pragma_Ada_2012 => -1,
12688 Pragma_All_Calls_Remote => -1,
12689 Pragma_Annotate => -1,
12690 Pragma_Assert => -1,
12691 Pragma_Assertion_Policy => 0,
12692 Pragma_Assume_No_Invalid_Values => 0,
12693 Pragma_Asynchronous => -1,
12694 Pragma_Atomic => 0,
12695 Pragma_Atomic_Components => 0,
12696 Pragma_Attach_Handler => -1,
12697 Pragma_Check => 99,
12698 Pragma_Check_Name => 0,
12699 Pragma_Check_Policy => 0,
12700 Pragma_CIL_Constructor => -1,
12701 Pragma_CPP_Class => 0,
12702 Pragma_CPP_Constructor => 0,
12703 Pragma_CPP_Virtual => 0,
12704 Pragma_CPP_Vtable => 0,
12705 Pragma_C_Pass_By_Copy => 0,
12706 Pragma_Comment => 0,
12707 Pragma_Common_Object => -1,
12708 Pragma_Compile_Time_Error => -1,
12709 Pragma_Compile_Time_Warning => -1,
12710 Pragma_Compiler_Unit => 0,
12711 Pragma_Complete_Representation => 0,
12712 Pragma_Complex_Representation => 0,
12713 Pragma_Component_Alignment => -1,
12714 Pragma_Controlled => 0,
12715 Pragma_Convention => 0,
12716 Pragma_Convention_Identifier => 0,
12717 Pragma_Debug => -1,
12718 Pragma_Debug_Policy => 0,
12719 Pragma_Detect_Blocking => -1,
12720 Pragma_Dimension => -1,
12721 Pragma_Discard_Names => 0,
12722 Pragma_Elaborate => -1,
12723 Pragma_Elaborate_All => -1,
12724 Pragma_Elaborate_Body => -1,
12725 Pragma_Elaboration_Checks => -1,
12726 Pragma_Eliminate => -1,
12727 Pragma_Export => -1,
12728 Pragma_Export_Exception => -1,
12729 Pragma_Export_Function => -1,
12730 Pragma_Export_Object => -1,
12731 Pragma_Export_Procedure => -1,
12732 Pragma_Export_Value => -1,
12733 Pragma_Export_Valued_Procedure => -1,
12734 Pragma_Extend_System => -1,
12735 Pragma_Extensions_Allowed => -1,
12736 Pragma_External => -1,
12737 Pragma_Favor_Top_Level => -1,
12738 Pragma_External_Name_Casing => -1,
12739 Pragma_Fast_Math => -1,
12740 Pragma_Finalize_Storage_Only => 0,
12741 Pragma_Float_Representation => 0,
12742 Pragma_Ident => -1,
12743 Pragma_Implemented_By_Entry => -1,
12744 Pragma_Implicit_Packing => 0,
12745 Pragma_Import => +2,
12746 Pragma_Import_Exception => 0,
12747 Pragma_Import_Function => 0,
12748 Pragma_Import_Object => 0,
12749 Pragma_Import_Procedure => 0,
12750 Pragma_Import_Valued_Procedure => 0,
12751 Pragma_Initialize_Scalars => -1,
12752 Pragma_Inline => 0,
12753 Pragma_Inline_Always => 0,
12754 Pragma_Inline_Generic => 0,
12755 Pragma_Inspection_Point => -1,
12756 Pragma_Interface => +2,
12757 Pragma_Interface_Name => +2,
12758 Pragma_Interrupt_Handler => -1,
12759 Pragma_Interrupt_Priority => -1,
12760 Pragma_Interrupt_State => -1,
12761 Pragma_Java_Constructor => -1,
12762 Pragma_Java_Interface => -1,
12763 Pragma_Keep_Names => 0,
12764 Pragma_License => -1,
12765 Pragma_Link_With => -1,
12766 Pragma_Linker_Alias => -1,
12767 Pragma_Linker_Constructor => -1,
12768 Pragma_Linker_Destructor => -1,
12769 Pragma_Linker_Options => -1,
12770 Pragma_Linker_Section => -1,
12771 Pragma_List => -1,
12772 Pragma_Locking_Policy => -1,
12773 Pragma_Long_Float => -1,
12774 Pragma_Machine_Attribute => -1,
12775 Pragma_Main => -1,
12776 Pragma_Main_Storage => -1,
12777 Pragma_Memory_Size => -1,
12778 Pragma_No_Return => 0,
12779 Pragma_No_Body => 0,
12780 Pragma_No_Run_Time => -1,
12781 Pragma_No_Strict_Aliasing => -1,
12782 Pragma_Normalize_Scalars => -1,
12783 Pragma_Obsolescent => 0,
12784 Pragma_Optimize => -1,
12785 Pragma_Optimize_Alignment => -1,
12786 Pragma_Pack => 0,
12787 Pragma_Page => -1,
12788 Pragma_Passive => -1,
12789 Pragma_Preelaborable_Initialization => -1,
12790 Pragma_Polling => -1,
12791 Pragma_Persistent_BSS => 0,
12792 Pragma_Postcondition => -1,
12793 Pragma_Precondition => -1,
12794 Pragma_Preelaborate => -1,
12795 Pragma_Preelaborate_05 => -1,
12796 Pragma_Priority => -1,
12797 Pragma_Priority_Specific_Dispatching => -1,
12798 Pragma_Profile => 0,
12799 Pragma_Profile_Warnings => 0,
12800 Pragma_Propagate_Exceptions => -1,
12801 Pragma_Psect_Object => -1,
12802 Pragma_Pure => -1,
12803 Pragma_Pure_05 => -1,
12804 Pragma_Pure_Function => -1,
12805 Pragma_Queuing_Policy => -1,
12806 Pragma_Ravenscar => -1,
12807 Pragma_Relative_Deadline => -1,
12808 Pragma_Remote_Call_Interface => -1,
12809 Pragma_Remote_Types => -1,
12810 Pragma_Restricted_Run_Time => -1,
12811 Pragma_Restriction_Warnings => -1,
12812 Pragma_Restrictions => -1,
12813 Pragma_Reviewable => -1,
12814 Pragma_Short_Circuit_And_Or => -1,
12815 Pragma_Share_Generic => -1,
12816 Pragma_Shared => -1,
12817 Pragma_Shared_Passive => -1,
12818 Pragma_Source_File_Name => -1,
12819 Pragma_Source_File_Name_Project => -1,
12820 Pragma_Source_Reference => -1,
12821 Pragma_Storage_Size => -1,
12822 Pragma_Storage_Unit => -1,
12823 Pragma_Static_Elaboration_Desired => -1,
12824 Pragma_Stream_Convert => -1,
12825 Pragma_Style_Checks => -1,
12826 Pragma_Subtitle => -1,
12827 Pragma_Suppress => 0,
12828 Pragma_Suppress_Exception_Locations => 0,
12829 Pragma_Suppress_All => -1,
12830 Pragma_Suppress_Debug_Info => 0,
12831 Pragma_Suppress_Initialization => 0,
12832 Pragma_System_Name => -1,
12833 Pragma_Task_Dispatching_Policy => -1,
12834 Pragma_Task_Info => -1,
12835 Pragma_Task_Name => -1,
12836 Pragma_Task_Storage => 0,
12837 Pragma_Thread_Local_Storage => 0,
12838 Pragma_Time_Slice => -1,
12839 Pragma_Title => -1,
12840 Pragma_Unchecked_Union => 0,
12841 Pragma_Unimplemented_Unit => -1,
12842 Pragma_Universal_Aliasing => -1,
12843 Pragma_Universal_Data => -1,
12844 Pragma_Unmodified => -1,
12845 Pragma_Unreferenced => -1,
12846 Pragma_Unreferenced_Objects => -1,
12847 Pragma_Unreserve_All_Interrupts => -1,
12848 Pragma_Unsuppress => 0,
12849 Pragma_Use_VADS_Size => -1,
12850 Pragma_Validity_Checks => -1,
12851 Pragma_Volatile => 0,
12852 Pragma_Volatile_Components => 0,
12853 Pragma_Warnings => -1,
12854 Pragma_Weak_External => -1,
12855 Pragma_Wide_Character_Encoding => 0,
12856 Unknown_Pragma => 0);
12858 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
12859 Id : Pragma_Id;
12860 P : Node_Id;
12861 C : Int;
12862 A : Node_Id;
12864 begin
12865 P := Parent (N);
12867 if Nkind (P) /= N_Pragma_Argument_Association then
12868 return False;
12870 else
12871 Id := Get_Pragma_Id (Parent (P));
12872 C := Sig_Flags (Id);
12874 case C is
12875 when -1 =>
12876 return False;
12878 when 0 =>
12879 return True;
12881 when 99 =>
12882 case Id is
12884 -- For pragma Check, the first argument is not significant,
12885 -- the second and the third (if present) arguments are
12886 -- significant.
12888 when Pragma_Check =>
12889 return
12890 P = First (Pragma_Argument_Associations (Parent (P)));
12892 when others =>
12893 raise Program_Error;
12894 end case;
12896 when others =>
12897 A := First (Pragma_Argument_Associations (Parent (P)));
12898 for J in 1 .. C - 1 loop
12899 if No (A) then
12900 return False;
12901 end if;
12903 Next (A);
12904 end loop;
12906 return A = P; -- is this wrong way round ???
12907 end case;
12908 end if;
12909 end Is_Non_Significant_Pragma_Reference;
12911 ------------------------------
12912 -- Is_Pragma_String_Literal --
12913 ------------------------------
12915 -- This function returns true if the corresponding pragma argument is a
12916 -- static string expression. These are the only cases in which string
12917 -- literals can appear as pragma arguments. We also allow a string literal
12918 -- as the first argument to pragma Assert (although it will of course
12919 -- always generate a type error).
12921 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
12922 Pragn : constant Node_Id := Parent (Par);
12923 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
12924 Pname : constant Name_Id := Pragma_Name (Pragn);
12925 Argn : Natural;
12926 N : Node_Id;
12928 begin
12929 Argn := 1;
12930 N := First (Assoc);
12931 loop
12932 exit when N = Par;
12933 Argn := Argn + 1;
12934 Next (N);
12935 end loop;
12937 if Pname = Name_Assert then
12938 return True;
12940 elsif Pname = Name_Export then
12941 return Argn > 2;
12943 elsif Pname = Name_Ident then
12944 return Argn = 1;
12946 elsif Pname = Name_Import then
12947 return Argn > 2;
12949 elsif Pname = Name_Interface_Name then
12950 return Argn > 1;
12952 elsif Pname = Name_Linker_Alias then
12953 return Argn = 2;
12955 elsif Pname = Name_Linker_Section then
12956 return Argn = 2;
12958 elsif Pname = Name_Machine_Attribute then
12959 return Argn = 2;
12961 elsif Pname = Name_Source_File_Name then
12962 return True;
12964 elsif Pname = Name_Source_Reference then
12965 return Argn = 2;
12967 elsif Pname = Name_Title then
12968 return True;
12970 elsif Pname = Name_Subtitle then
12971 return True;
12973 else
12974 return False;
12975 end if;
12976 end Is_Pragma_String_Literal;
12978 --------------------------------------
12979 -- Process_Compilation_Unit_Pragmas --
12980 --------------------------------------
12982 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
12983 begin
12984 -- A special check for pragma Suppress_All, a very strange DEC pragma,
12985 -- strange because it comes at the end of the unit. If we have a pragma
12986 -- Suppress_All in the Pragmas_After of the current unit, then we insert
12987 -- a pragma Suppress (All_Checks) at the start of the context clause to
12988 -- ensure the correct processing.
12990 declare
12991 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
12992 P : Node_Id;
12994 begin
12995 if Present (PA) then
12996 P := First (PA);
12997 while Present (P) loop
12998 if Pragma_Name (P) = Name_Suppress_All then
12999 Prepend_To (Context_Items (N),
13000 Make_Pragma (Sloc (P),
13001 Chars => Name_Suppress,
13002 Pragma_Argument_Associations => New_List (
13003 Make_Pragma_Argument_Association (Sloc (P),
13004 Expression =>
13005 Make_Identifier (Sloc (P),
13006 Chars => Name_All_Checks)))));
13007 exit;
13008 end if;
13010 Next (P);
13011 end loop;
13012 end if;
13013 end;
13014 end Process_Compilation_Unit_Pragmas;
13016 --------
13017 -- rv --
13018 --------
13020 procedure rv is
13021 begin
13022 null;
13023 end rv;
13025 --------------------------------
13026 -- Set_Encoded_Interface_Name --
13027 --------------------------------
13029 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
13030 Str : constant String_Id := Strval (S);
13031 Len : constant Int := String_Length (Str);
13032 CC : Char_Code;
13033 C : Character;
13034 J : Int;
13036 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
13038 procedure Encode;
13039 -- Stores encoded value of character code CC. The encoding we use an
13040 -- underscore followed by four lower case hex digits.
13042 ------------
13043 -- Encode --
13044 ------------
13046 procedure Encode is
13047 begin
13048 Store_String_Char (Get_Char_Code ('_'));
13049 Store_String_Char
13050 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
13051 Store_String_Char
13052 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
13053 Store_String_Char
13054 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
13055 Store_String_Char
13056 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
13057 end Encode;
13059 -- Start of processing for Set_Encoded_Interface_Name
13061 begin
13062 -- If first character is asterisk, this is a link name, and we leave it
13063 -- completely unmodified. We also ignore null strings (the latter case
13064 -- happens only in error cases) and no encoding should occur for Java or
13065 -- AAMP interface names.
13067 if Len = 0
13068 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
13069 or else VM_Target /= No_VM
13070 or else AAMP_On_Target
13071 then
13072 Set_Interface_Name (E, S);
13074 else
13075 J := 1;
13076 loop
13077 CC := Get_String_Char (Str, J);
13079 exit when not In_Character_Range (CC);
13081 C := Get_Character (CC);
13083 exit when C /= '_' and then C /= '$'
13084 and then C not in '0' .. '9'
13085 and then C not in 'a' .. 'z'
13086 and then C not in 'A' .. 'Z';
13088 if J = Len then
13089 Set_Interface_Name (E, S);
13090 return;
13092 else
13093 J := J + 1;
13094 end if;
13095 end loop;
13097 -- Here we need to encode. The encoding we use as follows:
13098 -- three underscores + four hex digits (lower case)
13100 Start_String;
13102 for J in 1 .. String_Length (Str) loop
13103 CC := Get_String_Char (Str, J);
13105 if not In_Character_Range (CC) then
13106 Encode;
13107 else
13108 C := Get_Character (CC);
13110 if C = '_' or else C = '$'
13111 or else C in '0' .. '9'
13112 or else C in 'a' .. 'z'
13113 or else C in 'A' .. 'Z'
13114 then
13115 Store_String_Char (CC);
13116 else
13117 Encode;
13118 end if;
13119 end if;
13120 end loop;
13122 Set_Interface_Name (E,
13123 Make_String_Literal (Sloc (S),
13124 Strval => End_String));
13125 end if;
13126 end Set_Encoded_Interface_Name;
13128 -------------------
13129 -- Set_Unit_Name --
13130 -------------------
13132 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
13133 Pref : Node_Id;
13134 Scop : Entity_Id;
13136 begin
13137 if Nkind (N) = N_Identifier
13138 and then Nkind (With_Item) = N_Identifier
13139 then
13140 Set_Entity (N, Entity (With_Item));
13142 elsif Nkind (N) = N_Selected_Component then
13143 Change_Selected_Component_To_Expanded_Name (N);
13144 Set_Entity (N, Entity (With_Item));
13145 Set_Entity (Selector_Name (N), Entity (N));
13147 Pref := Prefix (N);
13148 Scop := Scope (Entity (N));
13149 while Nkind (Pref) = N_Selected_Component loop
13150 Change_Selected_Component_To_Expanded_Name (Pref);
13151 Set_Entity (Selector_Name (Pref), Scop);
13152 Set_Entity (Pref, Scop);
13153 Pref := Prefix (Pref);
13154 Scop := Scope (Scop);
13155 end loop;
13157 Set_Entity (Pref, Scop);
13158 end if;
13159 end Set_Unit_Name;
13161 end Sem_Prag;