1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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 Exp_Util; use Exp_Util;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref; use Lib.Xref;
45 with Namet.Sp; use Namet.Sp;
46 with Nlists; use Nlists;
47 with Nmake; use Nmake;
49 with Output; use Output;
50 with Par_SCO; use Par_SCO;
51 with Restrict; use Restrict;
52 with Rident; use Rident;
53 with Rtsfind; use Rtsfind;
55 with Sem_Aux; use Sem_Aux;
56 with Sem_Ch3; use Sem_Ch3;
57 with Sem_Ch6; use Sem_Ch6;
58 with Sem_Ch8; use Sem_Ch8;
59 with Sem_Ch12; use Sem_Ch12;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Disp; use Sem_Disp;
62 with Sem_Dist; use Sem_Dist;
63 with Sem_Elim; use Sem_Elim;
64 with Sem_Eval; use Sem_Eval;
65 with Sem_Intr; use Sem_Intr;
66 with Sem_Mech; use Sem_Mech;
67 with Sem_Res; use Sem_Res;
68 with Sem_Type; use Sem_Type;
69 with Sem_Util; use Sem_Util;
70 with Sem_VFpt; use Sem_VFpt;
71 with Sem_Warn; use Sem_Warn;
72 with Stand; use Stand;
73 with Sinfo; use Sinfo;
74 with Sinfo.CN; use Sinfo.CN;
75 with Sinput; use Sinput;
76 with Snames; use Snames;
77 with Stringt; use Stringt;
78 with Stylesw; use Stylesw;
80 with Targparm; use Targparm;
81 with Tbuild; use Tbuild;
83 with Uintp; use Uintp;
84 with Uname; use Uname;
85 with Urealp; use Urealp;
86 with Validsw; use Validsw;
87 with Warnsw; use Warnsw;
89 package body Sem_Prag is
91 ----------------------------------------------
92 -- Common Handling of Import-Export Pragmas --
93 ----------------------------------------------
95 -- In the following section, a number of Import_xxx and Export_xxx pragmas
96 -- are defined by GNAT. These are compatible with the DEC pragmas of the
97 -- same name, and all have the following common form and processing:
100 -- [Internal =>] LOCAL_NAME
101 -- [, [External =>] EXTERNAL_SYMBOL]
102 -- [, other optional parameters ]);
105 -- [Internal =>] LOCAL_NAME
106 -- [, [External =>] EXTERNAL_SYMBOL]
107 -- [, other optional parameters ]);
109 -- EXTERNAL_SYMBOL ::=
111 -- | static_string_EXPRESSION
113 -- The internal LOCAL_NAME designates the entity that is imported or
114 -- exported, and must refer to an entity in the current declarative
115 -- part (as required by the rules for LOCAL_NAME).
117 -- The external linker name is designated by the External parameter if
118 -- given, or the Internal parameter if not (if there is no External
119 -- parameter, the External parameter is a copy of the Internal name).
121 -- If the External parameter is given as a string, then this string is
122 -- treated as an external name (exactly as though it had been given as an
123 -- External_Name parameter for a normal Import pragma).
125 -- If the External parameter is given as an identifier (or there is no
126 -- External parameter, so that the Internal identifier is used), then
127 -- the external name is the characters of the identifier, translated
128 -- to all upper case letters for OpenVMS versions of GNAT, and to all
129 -- lower case letters for all other versions
131 -- Note: the external name specified or implied by any of these special
132 -- Import_xxx or Export_xxx pragmas override an external or link name
133 -- specified in a previous Import or Export pragma.
135 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
136 -- named notation, following the standard rules for subprogram calls, i.e.
137 -- parameters can be given in any order if named notation is used, and
138 -- positional and named notation can be mixed, subject to the rule that all
139 -- positional parameters must appear first.
141 -- Note: All these pragmas are implemented exactly following the DEC design
142 -- and implementation and are intended to be fully compatible with the use
143 -- of these pragmas in the DEC Ada compiler.
145 --------------------------------------------
146 -- Checking for Duplicated External Names --
147 --------------------------------------------
149 -- It is suspicious if two separate Export pragmas use the same external
150 -- name. The following table is used to diagnose this situation so that
151 -- an appropriate warning can be issued.
153 -- The Node_Id stored is for the N_String_Literal node created to hold
154 -- the value of the external name. The Sloc of this node is used to
155 -- cross-reference the location of the duplication.
157 package Externals is new Table.Table (
158 Table_Component_Type => Node_Id,
159 Table_Index_Type => Int,
160 Table_Low_Bound => 0,
161 Table_Initial => 100,
162 Table_Increment => 100,
163 Table_Name => "Name_Externals");
165 -------------------------------------
166 -- Local Subprograms and Variables --
167 -------------------------------------
169 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
170 -- This routine is used for possible casing adjustment of an explicit
171 -- external name supplied as a string literal (the node N), according to
172 -- the casing requirement of Opt.External_Name_Casing. If this is set to
173 -- As_Is, then the string literal is returned unchanged, but if it is set
174 -- to Uppercase or Lowercase, then a new string literal with appropriate
175 -- casing is constructed.
177 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
178 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
179 -- original one, following the renaming chain) is returned. Otherwise the
180 -- entity is returned unchanged. Should be in Einfo???
182 procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id);
183 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
184 -- of a Test_Case pragma if present (possibly Empty). We treat these as
185 -- spec expressions (i.e. similar to a default expression).
188 -- This is a dummy function called by the processing for pragma Reviewable.
189 -- It is there for assisting front end debugging. By placing a Reviewable
190 -- pragma in the source program, a breakpoint on rv catches this place in
191 -- the source, allowing convenient stepping to the point of interest.
193 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
194 -- Place semantic information on the argument of an Elaborate/Elaborate_All
195 -- pragma. Entity name for unit and its parents is taken from item in
196 -- previous with_clause that mentions the unit.
198 -------------------------------
199 -- Adjust_External_Name_Case --
200 -------------------------------
202 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
206 -- Adjust case of literal if required
208 if Opt.External_Name_Exp_Casing = As_Is then
212 -- Copy existing string
218 for J in 1 .. String_Length (Strval (N)) loop
219 CC := Get_String_Char (Strval (N), J);
221 if Opt.External_Name_Exp_Casing = Uppercase
222 and then CC >= Get_Char_Code ('a')
223 and then CC <= Get_Char_Code ('z')
225 Store_String_Char (CC - 32);
227 elsif Opt.External_Name_Exp_Casing = Lowercase
228 and then CC >= Get_Char_Code ('A')
229 and then CC <= Get_Char_Code ('Z')
231 Store_String_Char (CC + 32);
234 Store_String_Char (CC);
239 Make_String_Literal (Sloc (N),
240 Strval => End_String);
242 end Adjust_External_Name_Case;
244 ------------------------------
245 -- Analyze_PPC_In_Decl_Part --
246 ------------------------------
248 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
249 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
252 -- Install formals and push subprogram spec onto scope stack so that we
253 -- can see the formals from the pragma.
258 -- Preanalyze the boolean expression, we treat this as a spec expression
259 -- (i.e. similar to a default expression).
261 pragma Assert (In_Pre_Post_Expression = False);
262 In_Pre_Post_Expression := True;
263 Preanalyze_Spec_Expression
264 (Get_Pragma_Arg (Arg1), Standard_Boolean);
265 In_Pre_Post_Expression := False;
267 -- Remove the subprogram from the scope stack now that the pre-analysis
268 -- of the precondition/postcondition is done.
271 end Analyze_PPC_In_Decl_Part;
277 procedure Analyze_Pragma (N : Node_Id) is
278 Loc : constant Source_Ptr := Sloc (N);
279 Pname : constant Name_Id := Pragma_Name (N);
282 Pragma_Exit : exception;
283 -- This exception is used to exit pragma processing completely. It is
284 -- used when an error is detected, and no further processing is
285 -- required. It is also used if an earlier error has left the tree in
286 -- a state where the pragma should not be processed.
289 -- Number of pragma argument associations
295 -- First four pragma arguments (pragma argument association nodes, or
296 -- Empty if the corresponding argument does not exist).
298 type Name_List is array (Natural range <>) of Name_Id;
299 type Args_List is array (Natural range <>) of Node_Id;
300 -- Types used for arguments to Check_Arg_Order and Gather_Associations
302 procedure Ada_2005_Pragma;
303 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
304 -- Ada 95 mode, these are implementation defined pragmas, so should be
305 -- caught by the No_Implementation_Pragmas restriction.
307 procedure Ada_2012_Pragma;
308 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
309 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
310 -- should be caught by the No_Implementation_Pragmas restriction.
312 procedure Check_Ada_83_Warning;
313 -- Issues a warning message for the current pragma if operating in Ada
314 -- 83 mode (used for language pragmas that are not a standard part of
315 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
318 procedure Check_Arg_Count (Required : Nat);
319 -- Check argument count for pragma is equal to given parameter. If not,
320 -- then issue an error message and raise Pragma_Exit.
322 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
323 -- Arg which can either be a pragma argument association, in which case
324 -- the check is applied to the expression of the association or an
325 -- expression directly.
327 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
328 -- Check that an argument has the right form for an EXTERNAL_NAME
329 -- parameter of an extended import/export pragma. The rule is that the
330 -- name must be an identifier or string literal (in Ada 83 mode) or a
331 -- static string expression (in Ada 95 mode).
333 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
334 -- Check the specified argument Arg to make sure that it is an
335 -- identifier. If not give error and raise Pragma_Exit.
337 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
338 -- Check the specified argument Arg to make sure that it is an integer
339 -- literal. If not give error and raise Pragma_Exit.
341 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
342 -- Check the specified argument Arg to make sure that it is a string
343 -- literal. If not give error and raise Pragma_Exit.
345 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
346 -- Check the specified argument Arg to make sure that it has the proper
347 -- syntactic form for a local name and meets the semantic requirements
348 -- for a local name. The local name is analyzed as part of the
349 -- processing for this call. In addition, the local name is required
350 -- to represent an entity at the library level.
352 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
353 -- Check the specified argument Arg to make sure that it has the proper
354 -- syntactic form for a local name and meets the semantic requirements
355 -- for a local name. The local name is analyzed as part of the
356 -- processing for this call.
358 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
359 -- Check the specified argument Arg to make sure that it is a valid
360 -- locking policy name. If not give error and raise Pragma_Exit.
362 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
363 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
364 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
365 -- Check the specified argument Arg to make sure that it is an
366 -- identifier whose name matches either N1 or N2 (or N3 if present).
367 -- If not then give error and raise Pragma_Exit.
369 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
370 -- Check the specified argument Arg to make sure that it is a valid
371 -- queuing policy name. If not give error and raise Pragma_Exit.
373 procedure Check_Arg_Is_Static_Expression
375 Typ : Entity_Id := Empty);
376 -- Check the specified argument Arg to make sure that it is a static
377 -- expression of the given type (i.e. it will be analyzed and resolved
378 -- using this type, which can be any valid argument to Resolve, e.g.
379 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
380 -- Typ is left Empty, then any static expression is allowed.
382 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
383 -- Check the specified argument Arg to make sure that it is a valid task
384 -- dispatching policy name. If not give error and raise Pragma_Exit.
386 procedure Check_Arg_Order (Names : Name_List);
387 -- Checks for an instance of two arguments with identifiers for the
388 -- current pragma which are not in the sequence indicated by Names,
389 -- and if so, generates a fatal message about bad order of arguments.
391 procedure Check_At_Least_N_Arguments (N : Nat);
392 -- Check there are at least N arguments present
394 procedure Check_At_Most_N_Arguments (N : Nat);
395 -- Check there are no more than N arguments present
397 procedure Check_Component
400 In_Variant_Part : Boolean := False);
401 -- Examine an Unchecked_Union component for correct use of per-object
402 -- constrained subtypes, and for restrictions on finalizable components.
403 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
404 -- should be set when Comp comes from a record variant.
406 procedure Check_Duplicate_Pragma (E : Entity_Id);
407 -- Check if a pragma of the same name as the current pragma is already
408 -- chained as a rep pragma to the given entity. If so give a message
409 -- about the duplicate, and then raise Pragma_Exit so does not return.
410 -- Also checks for delayed aspect specification node in the chain.
412 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
413 -- Nam is an N_String_Literal node containing the external name set by
414 -- an Import or Export pragma (or extended Import or Export pragma).
415 -- This procedure checks for possible duplications if this is the export
416 -- case, and if found, issues an appropriate error message.
418 procedure Check_First_Subtype (Arg : Node_Id);
419 -- Checks that Arg, whose expression is an entity name, references a
422 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
423 -- Checks that the given argument has an identifier, and if so, requires
424 -- it to match the given identifier name. If there is no identifier, or
425 -- a non-matching identifier, then an error message is given and
426 -- Error_Pragmas raised.
428 procedure Check_In_Main_Program;
429 -- Common checks for pragmas that appear within a main program
430 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
432 procedure Check_Interrupt_Or_Attach_Handler;
433 -- Common processing for first argument of pragma Interrupt_Handler or
434 -- pragma Attach_Handler.
436 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
437 -- Check that pragma appears in a declarative part, or in a package
438 -- specification, i.e. that it does not occur in a statement sequence
441 procedure Check_No_Identifier (Arg : Node_Id);
442 -- Checks that the given argument does not have an identifier. If
443 -- an identifier is present, then an error message is issued, and
444 -- Pragma_Exit is raised.
446 procedure Check_No_Identifiers;
447 -- Checks that none of the arguments to the pragma has an identifier.
448 -- If any argument has an identifier, then an error message is issued,
449 -- and Pragma_Exit is raised.
451 procedure Check_No_Link_Name;
452 -- Checks that no link name is specified
454 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
455 -- Checks if the given argument has an identifier, and if so, requires
456 -- it to match the given identifier name. If there is a non-matching
457 -- identifier, then an error message is given and Error_Pragmas raised.
459 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
460 -- Checks if the given argument has an identifier, and if so, requires
461 -- it to match the given identifier name. If there is a non-matching
462 -- identifier, then an error message is given and Error_Pragmas raised.
463 -- In this version of the procedure, the identifier name is given as
464 -- a string with lower case letters.
466 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
467 -- Called to process a precondition or postcondition pragma. There are
470 -- The pragma appears after a subprogram spec
472 -- If the corresponding check is not enabled, the pragma is analyzed
473 -- but otherwise ignored and control returns with In_Body set False.
475 -- If the check is enabled, then the first step is to analyze the
476 -- pragma, but this is skipped if the subprogram spec appears within
477 -- a package specification (because this is the case where we delay
478 -- analysis till the end of the spec). Then (whether or not it was
479 -- analyzed), the pragma is chained to the subprogram in question
480 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
481 -- caller with In_Body set False.
483 -- The pragma appears at the start of subprogram body declarations
485 -- In this case an immediate return to the caller is made with
486 -- In_Body set True, and the pragma is NOT analyzed.
488 -- In all other cases, an error message for bad placement is given
490 procedure Check_Static_Constraint (Constr : Node_Id);
491 -- Constr is a constraint from an N_Subtype_Indication node from a
492 -- component constraint in an Unchecked_Union type. This routine checks
493 -- that the constraint is static as required by the restrictions for
496 procedure Check_Test_Case;
497 -- Called to process a test-case pragma. The treatment is similar to the
498 -- one for pre- and postcondition in Check_Precondition_Postcondition.
499 -- There are three cases:
501 -- The pragma appears after a subprogram spec
503 -- The first step is to analyze the pragma, but this is skipped if
504 -- the subprogram spec appears within a package specification
505 -- (because this is the case where we delay analysis till the end of
506 -- the spec). Then (whether or not it was analyzed), the pragma is
507 -- chained to the subprogram in question (using Spec_TC_List and
510 -- The pragma appears at the start of subprogram body declarations
512 -- In this case an immediate return to the caller is made, and the
513 -- pragma is NOT analyzed.
515 -- In all other cases, an error message for bad placement is given
517 procedure Check_Valid_Configuration_Pragma;
518 -- Legality checks for placement of a configuration pragma
520 procedure Check_Valid_Library_Unit_Pragma;
521 -- Legality checks for library unit pragmas. A special case arises for
522 -- pragmas in generic instances that come from copies of the original
523 -- library unit pragmas in the generic templates. In the case of other
524 -- than library level instantiations these can appear in contexts which
525 -- would normally be invalid (they only apply to the original template
526 -- and to library level instantiations), and they are simply ignored,
527 -- which is implemented by rewriting them as null statements.
529 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
530 -- Check an Unchecked_Union variant for lack of nested variants and
531 -- presence of at least one component. UU_Typ is the related Unchecked_
534 procedure Error_Pragma (Msg : String);
535 pragma No_Return (Error_Pragma);
536 -- Outputs error message for current pragma. The message contains a %
537 -- that will be replaced with the pragma name, and the flag is placed
538 -- on the pragma itself. Pragma_Exit is then raised.
540 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
541 pragma No_Return (Error_Pragma_Arg);
542 -- Outputs error message for current pragma. The message may contain
543 -- a % that will be replaced with the pragma name. The parameter Arg
544 -- may either be a pragma argument association, in which case the flag
545 -- is placed on the expression of this association, or an expression,
546 -- in which case the flag is placed directly on the expression. The
547 -- message is placed using Error_Msg_N, so the message may also contain
548 -- an & insertion character which will reference the given Arg value.
549 -- After placing the message, Pragma_Exit is raised.
551 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
552 pragma No_Return (Error_Pragma_Arg);
553 -- Similar to above form of Error_Pragma_Arg except that two messages
554 -- are provided, the second is a continuation comment starting with \.
556 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
557 pragma No_Return (Error_Pragma_Arg_Ident);
558 -- Outputs error message for current pragma. The message may contain
559 -- a % that will be replaced with the pragma name. The parameter Arg
560 -- must be a pragma argument association with a non-empty identifier
561 -- (i.e. its Chars field must be set), and the error message is placed
562 -- on the identifier. The message is placed using Error_Msg_N so
563 -- the message may also contain an & insertion character which will
564 -- reference the identifier. After placing the message, Pragma_Exit
567 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
568 pragma No_Return (Error_Pragma_Ref);
569 -- Outputs error message for current pragma. The message may contain
570 -- a % that will be replaced with the pragma name. The parameter Ref
571 -- must be an entity whose name can be referenced by & and sloc by #.
572 -- After placing the message, Pragma_Exit is raised.
574 function Find_Lib_Unit_Name return Entity_Id;
575 -- Used for a library unit pragma to find the entity to which the
576 -- library unit pragma applies, returns the entity found.
578 procedure Find_Program_Unit_Name (Id : Node_Id);
579 -- If the pragma is a compilation unit pragma, the id must denote the
580 -- compilation unit in the same compilation, and the pragma must appear
581 -- in the list of preceding or trailing pragmas. If it is a program
582 -- unit pragma that is not a compilation unit pragma, then the
583 -- identifier must be visible.
585 function Find_Unique_Parameterless_Procedure
587 Arg : Node_Id) return Entity_Id;
588 -- Used for a procedure pragma to find the unique parameterless
589 -- procedure identified by Name, returns it if it exists, otherwise
590 -- errors out and uses Arg as the pragma argument for the message.
592 procedure Fix_Error (Msg : in out String);
593 -- This is called prior to issuing an error message. Msg is a string
594 -- which typically contains the substring pragma. If the current pragma
595 -- comes from an aspect, each such "pragma" substring is replaced with
596 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
597 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
599 procedure Gather_Associations
601 Args : out Args_List);
602 -- This procedure is used to gather the arguments for a pragma that
603 -- permits arbitrary ordering of parameters using the normal rules
604 -- for named and positional parameters. The Names argument is a list
605 -- of Name_Id values that corresponds to the allowed pragma argument
606 -- association identifiers in order. The result returned in Args is
607 -- a list of corresponding expressions that are the pragma arguments.
608 -- Note that this is a list of expressions, not of pragma argument
609 -- associations (Gather_Associations has completely checked all the
610 -- optional identifiers when it returns). An entry in Args is Empty
611 -- on return if the corresponding argument is not present.
613 procedure GNAT_Pragma;
614 -- Called for all GNAT defined pragmas to check the relevant restriction
615 -- (No_Implementation_Pragmas).
617 function Is_Before_First_Decl
618 (Pragma_Node : Node_Id;
619 Decls : List_Id) return Boolean;
620 -- Return True if Pragma_Node is before the first declarative item in
621 -- Decls where Decls is the list of declarative items.
623 function Is_Configuration_Pragma return Boolean;
624 -- Determines if the placement of the current pragma is appropriate
625 -- for a configuration pragma.
627 function Is_In_Context_Clause return Boolean;
628 -- Returns True if pragma appears within the context clause of a unit,
629 -- and False for any other placement (does not generate any messages).
631 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
632 -- Analyzes the argument, and determines if it is a static string
633 -- expression, returns True if so, False if non-static or not String.
635 procedure Pragma_Misplaced;
636 pragma No_Return (Pragma_Misplaced);
637 -- Issue fatal error message for misplaced pragma
639 procedure Process_Atomic_Shared_Volatile;
640 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
641 -- Shared is an obsolete Ada 83 pragma, treated as being identical
642 -- in effect to pragma Atomic.
644 procedure Process_Compile_Time_Warning_Or_Error;
645 -- Common processing for Compile_Time_Error and Compile_Time_Warning
647 procedure Process_Convention
648 (C : out Convention_Id;
649 Ent : out Entity_Id);
650 -- Common processing for Convention, Interface, Import and Export.
651 -- Checks first two arguments of pragma, and sets the appropriate
652 -- convention value in the specified entity or entities. On return
653 -- C is the convention, Ent is the referenced entity.
655 procedure Process_Extended_Import_Export_Exception_Pragma
656 (Arg_Internal : Node_Id;
657 Arg_External : Node_Id;
660 -- Common processing for the pragmas Import/Export_Exception. The three
661 -- arguments correspond to the three named parameters of the pragma. An
662 -- argument is empty if the corresponding parameter is not present in
665 procedure Process_Extended_Import_Export_Object_Pragma
666 (Arg_Internal : Node_Id;
667 Arg_External : Node_Id;
669 -- Common processing for the pragmas Import/Export_Object. The three
670 -- arguments correspond to the three named parameters of the pragmas. An
671 -- argument is empty if the corresponding parameter is not present in
674 procedure Process_Extended_Import_Export_Internal_Arg
675 (Arg_Internal : Node_Id := Empty);
676 -- Common processing for all extended Import and Export pragmas. The
677 -- argument is the pragma parameter for the Internal argument. If
678 -- Arg_Internal is empty or inappropriate, an error message is posted.
679 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
680 -- set to identify the referenced entity.
682 procedure Process_Extended_Import_Export_Subprogram_Pragma
683 (Arg_Internal : Node_Id;
684 Arg_External : Node_Id;
685 Arg_Parameter_Types : Node_Id;
686 Arg_Result_Type : Node_Id := Empty;
687 Arg_Mechanism : Node_Id;
688 Arg_Result_Mechanism : Node_Id := Empty;
689 Arg_First_Optional_Parameter : Node_Id := Empty);
690 -- Common processing for all extended Import and Export pragmas applying
691 -- to subprograms. The caller omits any arguments that do not apply to
692 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
693 -- only in the Import_Function and Export_Function cases). The argument
694 -- names correspond to the allowed pragma association identifiers.
696 procedure Process_Generic_List;
697 -- Common processing for Share_Generic and Inline_Generic
699 procedure Process_Import_Or_Interface;
700 -- Common processing for Import of Interface
702 procedure Process_Import_Predefined_Type;
703 -- Processing for completing a type with pragma Import. This is used
704 -- to declare types that match predefined C types, especially for cases
705 -- without corresponding Ada predefined type.
707 procedure Process_Inline (Active : Boolean);
708 -- Common processing for Inline and Inline_Always. The parameter
709 -- indicates if the inline pragma is active, i.e. if it should actually
710 -- cause inlining to occur.
712 procedure Process_Interface_Name
713 (Subprogram_Def : Entity_Id;
716 -- Given the last two arguments of pragma Import, pragma Export, or
717 -- pragma Interface_Name, performs validity checks and sets the
718 -- Interface_Name field of the given subprogram entity to the
719 -- appropriate external or link name, depending on the arguments given.
720 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
721 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
722 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
723 -- nor Link_Arg is present, the interface name is set to the default
724 -- from the subprogram name.
726 procedure Process_Interrupt_Or_Attach_Handler;
727 -- Common processing for Interrupt and Attach_Handler pragmas
729 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
730 -- Common processing for Restrictions and Restriction_Warnings pragmas.
731 -- Warn is True for Restriction_Warnings, or for Restrictions if the
732 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
733 -- is not set in the Restrictions case.
735 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
736 -- Common processing for Suppress and Unsuppress. The boolean parameter
737 -- Suppress_Case is True for the Suppress case, and False for the
740 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
741 -- This procedure sets the Is_Exported flag for the given entity,
742 -- checking that the entity was not previously imported. Arg is
743 -- the argument that specified the entity. A check is also made
744 -- for exporting inappropriate entities.
746 procedure Set_Extended_Import_Export_External_Name
747 (Internal_Ent : Entity_Id;
748 Arg_External : Node_Id);
749 -- Common processing for all extended import export pragmas. The first
750 -- argument, Internal_Ent, is the internal entity, which has already
751 -- been checked for validity by the caller. Arg_External is from the
752 -- Import or Export pragma, and may be null if no External parameter
753 -- was present. If Arg_External is present and is a non-null string
754 -- (a null string is treated as the default), then the Interface_Name
755 -- field of Internal_Ent is set appropriately.
757 procedure Set_Imported (E : Entity_Id);
758 -- This procedure sets the Is_Imported flag for the given entity,
759 -- checking that it is not previously exported or imported.
761 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
762 -- Mech is a parameter passing mechanism (see Import_Function syntax
763 -- for MECHANISM_NAME). This routine checks that the mechanism argument
764 -- has the right form, and if not issues an error message. If the
765 -- argument has the right form then the Mechanism field of Ent is
766 -- set appropriately.
768 procedure Set_Ravenscar_Profile (N : Node_Id);
769 -- Activate the set of configuration pragmas and restrictions that make
770 -- up the Ravenscar Profile. N is the corresponding pragma node, which
771 -- is used for error messages on any constructs that violate the
774 ---------------------
775 -- Ada_2005_Pragma --
776 ---------------------
778 procedure Ada_2005_Pragma is
780 if Ada_Version <= Ada_95 then
781 Check_Restriction (No_Implementation_Pragmas, N);
785 ---------------------
786 -- Ada_2012_Pragma --
787 ---------------------
789 procedure Ada_2012_Pragma is
791 if Ada_Version <= Ada_2005 then
792 Check_Restriction (No_Implementation_Pragmas, N);
796 --------------------------
797 -- Check_Ada_83_Warning --
798 --------------------------
800 procedure Check_Ada_83_Warning is
802 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
803 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
805 end Check_Ada_83_Warning;
807 ---------------------
808 -- Check_Arg_Count --
809 ---------------------
811 procedure Check_Arg_Count (Required : Nat) is
813 if Arg_Count /= Required then
814 Error_Pragma ("wrong number of arguments for pragma%");
818 --------------------------------
819 -- Check_Arg_Is_External_Name --
820 --------------------------------
822 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
823 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
826 if Nkind (Argx) = N_Identifier then
830 Analyze_And_Resolve (Argx, Standard_String);
832 if Is_OK_Static_Expression (Argx) then
835 elsif Etype (Argx) = Any_Type then
838 -- An interesting special case, if we have a string literal and
839 -- we are in Ada 83 mode, then we allow it even though it will
840 -- not be flagged as static. This allows expected Ada 83 mode
841 -- use of external names which are string literals, even though
842 -- technically these are not static in Ada 83.
844 elsif Ada_Version = Ada_83
845 and then Nkind (Argx) = N_String_Literal
849 -- Static expression that raises Constraint_Error. This has
850 -- already been flagged, so just exit from pragma processing.
852 elsif Is_Static_Expression (Argx) then
855 -- Here we have a real error (non-static expression)
858 Error_Msg_Name_1 := Pname;
862 "argument for pragma% must be a identifier or "
863 & "static string expression!";
866 Flag_Non_Static_Expr (Msg, Argx);
871 end Check_Arg_Is_External_Name;
873 -----------------------------
874 -- Check_Arg_Is_Identifier --
875 -----------------------------
877 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
878 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
880 if Nkind (Argx) /= N_Identifier then
882 ("argument for pragma% must be identifier", Argx);
884 end Check_Arg_Is_Identifier;
886 ----------------------------------
887 -- Check_Arg_Is_Integer_Literal --
888 ----------------------------------
890 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
891 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
893 if Nkind (Argx) /= N_Integer_Literal then
895 ("argument for pragma% must be integer literal", Argx);
897 end Check_Arg_Is_Integer_Literal;
899 ---------------------------------
900 -- Check_Arg_Is_String_Literal --
901 ---------------------------------
903 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
904 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
906 if Nkind (Argx) /= N_String_Literal then
908 ("argument for pragma% must be string literal", Argx);
910 end Check_Arg_Is_String_Literal;
912 -------------------------------------------
913 -- Check_Arg_Is_Library_Level_Local_Name --
914 -------------------------------------------
918 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
919 -- | library_unit_NAME
921 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
923 Check_Arg_Is_Local_Name (Arg);
925 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
926 and then Comes_From_Source (N)
929 ("argument for pragma% must be library level entity", Arg);
931 end Check_Arg_Is_Library_Level_Local_Name;
933 -----------------------------
934 -- Check_Arg_Is_Local_Name --
935 -----------------------------
939 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
940 -- | library_unit_NAME
942 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
943 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
948 if Nkind (Argx) not in N_Direct_Name
949 and then (Nkind (Argx) /= N_Attribute_Reference
950 or else Present (Expressions (Argx))
951 or else Nkind (Prefix (Argx)) /= N_Identifier)
952 and then (not Is_Entity_Name (Argx)
953 or else not Is_Compilation_Unit (Entity (Argx)))
955 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
958 -- No further check required if not an entity name
960 if not Is_Entity_Name (Argx) then
966 Ent : constant Entity_Id := Entity (Argx);
967 Scop : constant Entity_Id := Scope (Ent);
969 -- Case of a pragma applied to a compilation unit: pragma must
970 -- occur immediately after the program unit in the compilation.
972 if Is_Compilation_Unit (Ent) then
974 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
976 -- Case of pragma placed immediately after spec
978 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
981 -- Case of pragma placed immediately after body
983 elsif Nkind (Decl) = N_Subprogram_Declaration
984 and then Present (Corresponding_Body (Decl))
988 (Parent (Unit_Declaration_Node
989 (Corresponding_Body (Decl))));
991 -- All other cases are illegal
998 -- Special restricted placement rule from 10.2.1(11.8/2)
1000 elsif Is_Generic_Formal (Ent)
1001 and then Prag_Id = Pragma_Preelaborable_Initialization
1003 OK := List_Containing (N) =
1004 Generic_Formal_Declarations
1005 (Unit_Declaration_Node (Scop));
1007 -- Default case, just check that the pragma occurs in the scope
1008 -- of the entity denoted by the name.
1011 OK := Current_Scope = Scop;
1016 ("pragma% argument must be in same declarative part", Arg);
1020 end Check_Arg_Is_Local_Name;
1022 ---------------------------------
1023 -- Check_Arg_Is_Locking_Policy --
1024 ---------------------------------
1026 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1027 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1030 Check_Arg_Is_Identifier (Argx);
1032 if not Is_Locking_Policy_Name (Chars (Argx)) then
1033 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1035 end Check_Arg_Is_Locking_Policy;
1037 -------------------------
1038 -- Check_Arg_Is_One_Of --
1039 -------------------------
1041 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1042 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1045 Check_Arg_Is_Identifier (Argx);
1047 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1048 Error_Msg_Name_2 := N1;
1049 Error_Msg_Name_3 := N2;
1050 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1052 end Check_Arg_Is_One_Of;
1054 procedure Check_Arg_Is_One_Of
1056 N1, N2, N3 : Name_Id)
1058 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1061 Check_Arg_Is_Identifier (Argx);
1063 if Chars (Argx) /= N1
1064 and then Chars (Argx) /= N2
1065 and then Chars (Argx) /= N3
1067 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1069 end Check_Arg_Is_One_Of;
1071 procedure Check_Arg_Is_One_Of
1073 N1, N2, N3, N4 : Name_Id)
1075 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1078 Check_Arg_Is_Identifier (Argx);
1080 if Chars (Argx) /= N1
1081 and then Chars (Argx) /= N2
1082 and then Chars (Argx) /= N3
1083 and then Chars (Argx) /= N4
1085 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1087 end Check_Arg_Is_One_Of;
1089 ---------------------------------
1090 -- Check_Arg_Is_Queuing_Policy --
1091 ---------------------------------
1093 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1094 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1097 Check_Arg_Is_Identifier (Argx);
1099 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1100 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1102 end Check_Arg_Is_Queuing_Policy;
1104 ------------------------------------
1105 -- Check_Arg_Is_Static_Expression --
1106 ------------------------------------
1108 procedure Check_Arg_Is_Static_Expression
1110 Typ : Entity_Id := Empty)
1112 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1115 if Present (Typ) then
1116 Analyze_And_Resolve (Argx, Typ);
1118 Analyze_And_Resolve (Argx);
1121 if Is_OK_Static_Expression (Argx) then
1124 elsif Etype (Argx) = Any_Type then
1127 -- An interesting special case, if we have a string literal and we
1128 -- are in Ada 83 mode, then we allow it even though it will not be
1129 -- flagged as static. This allows the use of Ada 95 pragmas like
1130 -- Import in Ada 83 mode. They will of course be flagged with
1131 -- warnings as usual, but will not cause errors.
1133 elsif Ada_Version = Ada_83
1134 and then Nkind (Argx) = N_String_Literal
1138 -- Static expression that raises Constraint_Error. This has already
1139 -- been flagged, so just exit from pragma processing.
1141 elsif Is_Static_Expression (Argx) then
1144 -- Finally, we have a real error
1147 Error_Msg_Name_1 := Pname;
1151 "argument for pragma% must be a static expression!";
1154 Flag_Non_Static_Expr (Msg, Argx);
1159 end Check_Arg_Is_Static_Expression;
1161 ------------------------------------------
1162 -- Check_Arg_Is_Task_Dispatching_Policy --
1163 ------------------------------------------
1165 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1166 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1169 Check_Arg_Is_Identifier (Argx);
1171 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1173 ("& is not a valid task dispatching policy name", Argx);
1175 end Check_Arg_Is_Task_Dispatching_Policy;
1177 ---------------------
1178 -- Check_Arg_Order --
1179 ---------------------
1181 procedure Check_Arg_Order (Names : Name_List) is
1184 Highest_So_Far : Natural := 0;
1185 -- Highest index in Names seen do far
1189 for J in 1 .. Arg_Count loop
1190 if Chars (Arg) /= No_Name then
1191 for K in Names'Range loop
1192 if Chars (Arg) = Names (K) then
1193 if K < Highest_So_Far then
1194 Error_Msg_Name_1 := Pname;
1196 ("parameters out of order for pragma%", Arg);
1197 Error_Msg_Name_1 := Names (K);
1198 Error_Msg_Name_2 := Names (Highest_So_Far);
1199 Error_Msg_N ("\% must appear before %", Arg);
1203 Highest_So_Far := K;
1211 end Check_Arg_Order;
1213 --------------------------------
1214 -- Check_At_Least_N_Arguments --
1215 --------------------------------
1217 procedure Check_At_Least_N_Arguments (N : Nat) is
1219 if Arg_Count < N then
1220 Error_Pragma ("too few arguments for pragma%");
1222 end Check_At_Least_N_Arguments;
1224 -------------------------------
1225 -- Check_At_Most_N_Arguments --
1226 -------------------------------
1228 procedure Check_At_Most_N_Arguments (N : Nat) is
1231 if Arg_Count > N then
1233 for J in 1 .. N loop
1235 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1238 end Check_At_Most_N_Arguments;
1240 ---------------------
1241 -- Check_Component --
1242 ---------------------
1244 procedure Check_Component
1247 In_Variant_Part : Boolean := False)
1249 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1250 Sindic : constant Node_Id :=
1251 Subtype_Indication (Component_Definition (Comp));
1252 Typ : constant Entity_Id := Etype (Comp_Id);
1254 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1255 -- Determine whether entity Id appears inside a generic body.
1256 -- Shouldn't this be in a more general place ???
1258 -------------------------
1259 -- Inside_Generic_Body --
1260 -------------------------
1262 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1267 while Present (S) and then S /= Standard_Standard loop
1268 if Ekind (S) = E_Generic_Package
1269 and then In_Package_Body (S)
1278 end Inside_Generic_Body;
1280 -- Start of processing for Check_Component
1283 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1284 -- object constraint, then the component type shall be an Unchecked_
1287 if Nkind (Sindic) = N_Subtype_Indication
1288 and then Has_Per_Object_Constraint (Comp_Id)
1289 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1292 ("component subtype subject to per-object constraint " &
1293 "must be an Unchecked_Union", Comp);
1295 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1296 -- the body of a generic unit, or within the body of any of its
1297 -- descendant library units, no part of the type of a component
1298 -- declared in a variant_part of the unchecked union type shall be of
1299 -- a formal private type or formal private extension declared within
1300 -- the formal part of the generic unit.
1302 elsif Ada_Version >= Ada_2012
1303 and then Inside_Generic_Body (UU_Typ)
1304 and then In_Variant_Part
1305 and then Is_Private_Type (Typ)
1306 and then Is_Generic_Type (Typ)
1309 ("component of Unchecked_Union cannot be of generic type", Comp);
1311 elsif Needs_Finalization (Typ) then
1313 ("component of Unchecked_Union cannot be controlled", Comp);
1315 elsif Has_Task (Typ) then
1317 ("component of Unchecked_Union cannot have tasks", Comp);
1319 end Check_Component;
1321 ----------------------------
1322 -- Check_Duplicate_Pragma --
1323 ----------------------------
1325 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1329 -- Nothing to do if this pragma comes from an aspect specification,
1330 -- since we could not be duplicating a pragma, and we dealt with the
1331 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1333 if From_Aspect_Specification (N) then
1337 -- Otherwise current pragma may duplicate previous pragma or a
1338 -- previously given aspect specification for the same pragma.
1340 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1343 Error_Msg_Name_1 := Pragma_Name (N);
1344 Error_Msg_Sloc := Sloc (P);
1346 if Nkind (P) = N_Aspect_Specification
1347 or else From_Aspect_Specification (P)
1349 Error_Msg_NE ("aspect% for & previously given#", N, E);
1351 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1356 end Check_Duplicate_Pragma;
1358 ----------------------------------
1359 -- Check_Duplicated_Export_Name --
1360 ----------------------------------
1362 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1363 String_Val : constant String_Id := Strval (Nam);
1366 -- We are only interested in the export case, and in the case of
1367 -- generics, it is the instance, not the template, that is the
1368 -- problem (the template will generate a warning in any case).
1370 if not Inside_A_Generic
1371 and then (Prag_Id = Pragma_Export
1373 Prag_Id = Pragma_Export_Procedure
1375 Prag_Id = Pragma_Export_Valued_Procedure
1377 Prag_Id = Pragma_Export_Function)
1379 for J in Externals.First .. Externals.Last loop
1380 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1381 Error_Msg_Sloc := Sloc (Externals.Table (J));
1382 Error_Msg_N ("external name duplicates name given#", Nam);
1387 Externals.Append (Nam);
1389 end Check_Duplicated_Export_Name;
1391 -------------------------
1392 -- Check_First_Subtype --
1393 -------------------------
1395 procedure Check_First_Subtype (Arg : Node_Id) is
1396 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1397 Ent : constant Entity_Id := Entity (Argx);
1400 if Is_First_Subtype (Ent) then
1403 elsif Is_Type (Ent) then
1405 ("pragma% cannot apply to subtype", Argx);
1407 elsif Is_Object (Ent) then
1409 ("pragma% cannot apply to object, requires a type", Argx);
1413 ("pragma% cannot apply to&, requires a type", Argx);
1415 end Check_First_Subtype;
1417 ----------------------
1418 -- Check_Identifier --
1419 ----------------------
1421 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1424 and then Nkind (Arg) = N_Pragma_Argument_Association
1426 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1427 Error_Msg_Name_1 := Pname;
1428 Error_Msg_Name_2 := Id;
1429 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1433 end Check_Identifier;
1435 ---------------------------
1436 -- Check_In_Main_Program --
1437 ---------------------------
1439 procedure Check_In_Main_Program is
1440 P : constant Node_Id := Parent (N);
1443 -- Must be at in subprogram body
1445 if Nkind (P) /= N_Subprogram_Body then
1446 Error_Pragma ("% pragma allowed only in subprogram");
1448 -- Otherwise warn if obviously not main program
1450 elsif Present (Parameter_Specifications (Specification (P)))
1451 or else not Is_Compilation_Unit (Defining_Entity (P))
1453 Error_Msg_Name_1 := Pname;
1455 ("?pragma% is only effective in main program", N);
1457 end Check_In_Main_Program;
1459 ---------------------------------------
1460 -- Check_Interrupt_Or_Attach_Handler --
1461 ---------------------------------------
1463 procedure Check_Interrupt_Or_Attach_Handler is
1464 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1465 Handler_Proc, Proc_Scope : Entity_Id;
1470 if Prag_Id = Pragma_Interrupt_Handler then
1471 Check_Restriction (No_Dynamic_Attachment, N);
1474 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1475 Proc_Scope := Scope (Handler_Proc);
1477 -- On AAMP only, a pragma Interrupt_Handler is supported for
1478 -- nonprotected parameterless procedures.
1480 if not AAMP_On_Target
1481 or else Prag_Id = Pragma_Attach_Handler
1483 if Ekind (Proc_Scope) /= E_Protected_Type then
1485 ("argument of pragma% must be protected procedure", Arg1);
1488 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1489 Error_Pragma ("pragma% must be in protected definition");
1493 if not Is_Library_Level_Entity (Proc_Scope)
1494 or else (AAMP_On_Target
1495 and then not Is_Library_Level_Entity (Handler_Proc))
1498 ("argument for pragma% must be library level entity", Arg1);
1501 -- AI05-0033: A pragma cannot appear within a generic body, because
1502 -- instance can be in a nested scope. The check that protected type
1503 -- is itself a library-level declaration is done elsewhere.
1505 -- Note: we omit this check in Codepeer mode to properly handle code
1506 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1508 if Inside_A_Generic then
1509 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1510 and then In_Package_Body (Scope (Current_Scope))
1511 and then not CodePeer_Mode
1513 Error_Pragma ("pragma% cannot be used inside a generic");
1516 end Check_Interrupt_Or_Attach_Handler;
1518 -------------------------------------------
1519 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1520 -------------------------------------------
1522 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1531 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1534 elsif Nkind_In (P, N_Package_Specification,
1539 -- Note: the following tests seem a little peculiar, because
1540 -- they test for bodies, but if we were in the statement part
1541 -- of the body, we would already have hit the handled statement
1542 -- sequence, so the only way we get here is by being in the
1543 -- declarative part of the body.
1545 elsif Nkind_In (P, N_Subprogram_Body,
1556 Error_Pragma ("pragma% is not in declarative part or package spec");
1557 end Check_Is_In_Decl_Part_Or_Package_Spec;
1559 -------------------------
1560 -- Check_No_Identifier --
1561 -------------------------
1563 procedure Check_No_Identifier (Arg : Node_Id) is
1565 if Nkind (Arg) = N_Pragma_Argument_Association
1566 and then Chars (Arg) /= No_Name
1568 Error_Pragma_Arg_Ident
1569 ("pragma% does not permit identifier& here", Arg);
1571 end Check_No_Identifier;
1573 --------------------------
1574 -- Check_No_Identifiers --
1575 --------------------------
1577 procedure Check_No_Identifiers is
1580 if Arg_Count > 0 then
1582 while Present (Arg_Node) loop
1583 Check_No_Identifier (Arg_Node);
1587 end Check_No_Identifiers;
1589 ------------------------
1590 -- Check_No_Link_Name --
1591 ------------------------
1593 procedure Check_No_Link_Name is
1596 and then Chars (Arg3) = Name_Link_Name
1601 if Present (Arg4) then
1603 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1605 end Check_No_Link_Name;
1607 -------------------------------
1608 -- Check_Optional_Identifier --
1609 -------------------------------
1611 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1614 and then Nkind (Arg) = N_Pragma_Argument_Association
1615 and then Chars (Arg) /= No_Name
1617 if Chars (Arg) /= Id then
1618 Error_Msg_Name_1 := Pname;
1619 Error_Msg_Name_2 := Id;
1620 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1624 end Check_Optional_Identifier;
1626 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1628 Name_Buffer (1 .. Id'Length) := Id;
1629 Name_Len := Id'Length;
1630 Check_Optional_Identifier (Arg, Name_Find);
1631 end Check_Optional_Identifier;
1633 --------------------------------------
1634 -- Check_Precondition_Postcondition --
1635 --------------------------------------
1637 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1641 procedure Chain_PPC (PO : Node_Id);
1642 -- If PO is an entry or a [generic] subprogram declaration node, then
1643 -- the precondition/postcondition applies to this subprogram and the
1644 -- processing for the pragma is completed. Otherwise the pragma is
1651 procedure Chain_PPC (PO : Node_Id) is
1656 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1657 if not From_Aspect_Specification (N) then
1659 ("pragma% cannot be applied to abstract subprogram");
1661 elsif Class_Present (N) then
1666 ("aspect % requires ''Class for abstract subprogram");
1669 -- AI05-0230: The same restriction applies to null procedures. For
1670 -- compatibility with earlier uses of the Ada pragma, apply this
1671 -- rule only to aspect specifications.
1673 -- The above discrpency needs documentation. Robert is dubious
1674 -- about whether it is a good idea ???
1676 elsif Nkind (PO) = N_Subprogram_Declaration
1677 and then Nkind (Specification (PO)) = N_Procedure_Specification
1678 and then Null_Present (Specification (PO))
1679 and then From_Aspect_Specification (N)
1680 and then not Class_Present (N)
1683 ("aspect % requires ''Class for null procedure");
1685 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1686 N_Generic_Subprogram_Declaration,
1687 N_Entry_Declaration)
1692 -- Here if we have [generic] subprogram or entry declaration
1694 if Nkind (PO) = N_Entry_Declaration then
1695 S := Defining_Entity (PO);
1697 S := Defining_Unit_Name (Specification (PO));
1700 -- Make sure we do not have the case of a precondition pragma when
1701 -- the Pre'Class aspect is present.
1703 -- We do this by looking at pragmas already chained to the entity
1704 -- since the aspect derived pragma will be put on this list first.
1706 if Pragma_Name (N) = Name_Precondition then
1707 if not From_Aspect_Specification (N) then
1708 P := Spec_PPC_List (Contract (S));
1709 while Present (P) loop
1710 if Pragma_Name (P) = Name_Precondition
1711 and then From_Aspect_Specification (P)
1712 and then Class_Present (P)
1714 Error_Msg_Sloc := Sloc (P);
1716 ("pragma% not allowed, `Pre''Class` aspect given#");
1719 P := Next_Pragma (P);
1724 -- Similarly check for Pre with inherited Pre'Class. Note that
1725 -- we cover the aspect case as well here.
1727 if Pragma_Name (N) = Name_Precondition
1728 and then not Class_Present (N)
1731 Inherited : constant Subprogram_List :=
1732 Inherited_Subprograms (S);
1736 for J in Inherited'Range loop
1737 P := Spec_PPC_List (Contract (Inherited (J)));
1738 while Present (P) loop
1739 if Pragma_Name (P) = Name_Precondition
1740 and then Class_Present (P)
1742 Error_Msg_Sloc := Sloc (P);
1744 ("pragma% not allowed, `Pre''Class` "
1745 & "aspect inherited from#");
1748 P := Next_Pragma (P);
1754 -- Note: we do not analyze the pragma at this point. Instead we
1755 -- delay this analysis until the end of the declarative part in
1756 -- which the pragma appears. This implements the required delay
1757 -- in this analysis, allowing forward references. The analysis
1758 -- happens at the end of Analyze_Declarations.
1760 -- Chain spec PPC pragma to list for subprogram
1762 Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1763 Set_Spec_PPC_List (Contract (S), N);
1765 -- Return indicating spec case
1771 -- Start of processing for Check_Precondition_Postcondition
1774 if not Is_List_Member (N) then
1778 -- Preanalyze message argument if present. Visibility in this
1779 -- argument is established at the point of pragma occurrence.
1781 if Arg_Count = 2 then
1782 Check_Optional_Identifier (Arg2, Name_Message);
1783 Preanalyze_Spec_Expression
1784 (Get_Pragma_Arg (Arg2), Standard_String);
1787 -- Record if pragma is enabled
1789 if Check_Enabled (Pname) then
1790 Set_SCO_Pragma_Enabled (Loc);
1793 -- If we are within an inlined body, the legality of the pragma
1794 -- has been checked already.
1796 if In_Inlined_Body then
1801 -- Search prior declarations
1804 while Present (Prev (P)) loop
1807 -- If the previous node is a generic subprogram, do not go to to
1808 -- the original node, which is the unanalyzed tree: we need to
1809 -- attach the pre/postconditions to the analyzed version at this
1810 -- point. They get propagated to the original tree when analyzing
1811 -- the corresponding body.
1813 if Nkind (P) not in N_Generic_Declaration then
1814 PO := Original_Node (P);
1819 -- Skip past prior pragma
1821 if Nkind (PO) = N_Pragma then
1824 -- Skip stuff not coming from source
1826 elsif not Comes_From_Source (PO) then
1828 -- The condition may apply to a subprogram instantiation
1830 if Nkind (PO) = N_Subprogram_Declaration
1831 and then Present (Generic_Parent (Specification (PO)))
1836 -- For all other cases of non source code, do nothing
1842 -- Only remaining possibility is subprogram declaration
1850 -- If we fall through loop, pragma is at start of list, so see if it
1851 -- is at the start of declarations of a subprogram body.
1853 if Nkind (Parent (N)) = N_Subprogram_Body
1854 and then List_Containing (N) = Declarations (Parent (N))
1856 if Operating_Mode /= Generate_Code
1857 or else Inside_A_Generic
1859 -- Analyze pragma expression for correctness and for ASIS use
1861 Preanalyze_Spec_Expression
1862 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1868 -- See if it is in the pragmas after a library level subprogram
1870 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1871 Chain_PPC (Unit (Parent (Parent (N))));
1875 -- If we fall through, pragma was misplaced
1878 end Check_Precondition_Postcondition;
1880 -----------------------------
1881 -- Check_Static_Constraint --
1882 -----------------------------
1884 -- Note: for convenience in writing this procedure, in addition to
1885 -- the officially (i.e. by spec) allowed argument which is always a
1886 -- constraint, it also allows ranges and discriminant associations.
1887 -- Above is not clear ???
1889 procedure Check_Static_Constraint (Constr : Node_Id) is
1891 procedure Require_Static (E : Node_Id);
1892 -- Require given expression to be static expression
1894 --------------------
1895 -- Require_Static --
1896 --------------------
1898 procedure Require_Static (E : Node_Id) is
1900 if not Is_OK_Static_Expression (E) then
1901 Flag_Non_Static_Expr
1902 ("non-static constraint not allowed in Unchecked_Union!", E);
1907 -- Start of processing for Check_Static_Constraint
1910 case Nkind (Constr) is
1911 when N_Discriminant_Association =>
1912 Require_Static (Expression (Constr));
1915 Require_Static (Low_Bound (Constr));
1916 Require_Static (High_Bound (Constr));
1918 when N_Attribute_Reference =>
1919 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1920 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1922 when N_Range_Constraint =>
1923 Check_Static_Constraint (Range_Expression (Constr));
1925 when N_Index_Or_Discriminant_Constraint =>
1929 IDC := First (Constraints (Constr));
1930 while Present (IDC) loop
1931 Check_Static_Constraint (IDC);
1939 end Check_Static_Constraint;
1941 ---------------------
1942 -- Check_Test_Case --
1943 ---------------------
1945 procedure Check_Test_Case is
1949 procedure Chain_TC (PO : Node_Id);
1950 -- If PO is an entry or a [generic] subprogram declaration node, then
1951 -- the test-case applies to this subprogram and the processing for
1952 -- the pragma is completed. Otherwise the pragma is misplaced.
1958 procedure Chain_TC (PO : Node_Id) is
1962 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1963 if From_Aspect_Specification (N) then
1965 ("aspect% cannot be applied to abstract subprogram");
1968 ("pragma% cannot be applied to abstract subprogram");
1971 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1972 N_Generic_Subprogram_Declaration,
1973 N_Entry_Declaration)
1978 -- Here if we have [generic] subprogram or entry declaration
1980 if Nkind (PO) = N_Entry_Declaration then
1981 S := Defining_Entity (PO);
1983 S := Defining_Unit_Name (Specification (PO));
1986 -- Note: we do not analyze the pragma at this point. Instead we
1987 -- delay this analysis until the end of the declarative part in
1988 -- which the pragma appears. This implements the required delay
1989 -- in this analysis, allowing forward references. The analysis
1990 -- happens at the end of Analyze_Declarations.
1992 -- Chain spec TC pragma to list for subprogram
1994 Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
1995 Set_Spec_TC_List (Contract (S), N);
1998 -- Start of processing for Check_Test_Case
2001 if not Is_List_Member (N) then
2005 -- Search prior declarations
2008 while Present (Prev (P)) loop
2011 -- If the previous node is a generic subprogram, do not go to to
2012 -- the original node, which is the unanalyzed tree: we need to
2013 -- attach the test-case to the analyzed version at this point.
2014 -- They get propagated to the original tree when analyzing the
2015 -- corresponding body.
2017 if Nkind (P) not in N_Generic_Declaration then
2018 PO := Original_Node (P);
2023 -- Skip past prior pragma
2025 if Nkind (PO) = N_Pragma then
2028 -- Skip stuff not coming from source
2030 elsif not Comes_From_Source (PO) then
2033 -- Only remaining possibility is subprogram declaration
2041 -- If we fall through loop, pragma is at start of list, so see if it
2042 -- is at the start of declarations of a subprogram body.
2044 if Nkind (Parent (N)) = N_Subprogram_Body
2045 and then List_Containing (N) = Declarations (Parent (N))
2047 if Operating_Mode /= Generate_Code
2048 or else Inside_A_Generic
2050 -- Analyze pragma expressions for correctness and for ASIS use
2052 Preanalyze_TC_Args (Get_Requires_From_Test_Case_Pragma (N),
2053 Get_Ensures_From_Test_Case_Pragma (N));
2058 -- See if it is in the pragmas after a library level subprogram
2060 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2061 Chain_TC (Unit (Parent (Parent (N))));
2065 -- If we fall through, pragma was misplaced
2068 end Check_Test_Case;
2070 --------------------------------------
2071 -- Check_Valid_Configuration_Pragma --
2072 --------------------------------------
2074 -- A configuration pragma must appear in the context clause of a
2075 -- compilation unit, and only other pragmas may precede it. Note that
2076 -- the test also allows use in a configuration pragma file.
2078 procedure Check_Valid_Configuration_Pragma is
2080 if not Is_Configuration_Pragma then
2081 Error_Pragma ("incorrect placement for configuration pragma%");
2083 end Check_Valid_Configuration_Pragma;
2085 -------------------------------------
2086 -- Check_Valid_Library_Unit_Pragma --
2087 -------------------------------------
2089 procedure Check_Valid_Library_Unit_Pragma is
2091 Parent_Node : Node_Id;
2092 Unit_Name : Entity_Id;
2093 Unit_Kind : Node_Kind;
2094 Unit_Node : Node_Id;
2095 Sindex : Source_File_Index;
2098 if not Is_List_Member (N) then
2102 Plist := List_Containing (N);
2103 Parent_Node := Parent (Plist);
2105 if Parent_Node = Empty then
2108 -- Case of pragma appearing after a compilation unit. In this case
2109 -- it must have an argument with the corresponding name and must
2110 -- be part of the following pragmas of its parent.
2112 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2113 if Plist /= Pragmas_After (Parent_Node) then
2116 elsif Arg_Count = 0 then
2118 ("argument required if outside compilation unit");
2121 Check_No_Identifiers;
2122 Check_Arg_Count (1);
2123 Unit_Node := Unit (Parent (Parent_Node));
2124 Unit_Kind := Nkind (Unit_Node);
2126 Analyze (Get_Pragma_Arg (Arg1));
2128 if Unit_Kind = N_Generic_Subprogram_Declaration
2129 or else Unit_Kind = N_Subprogram_Declaration
2131 Unit_Name := Defining_Entity (Unit_Node);
2133 elsif Unit_Kind in N_Generic_Instantiation then
2134 Unit_Name := Defining_Entity (Unit_Node);
2137 Unit_Name := Cunit_Entity (Current_Sem_Unit);
2140 if Chars (Unit_Name) /=
2141 Chars (Entity (Get_Pragma_Arg (Arg1)))
2144 ("pragma% argument is not current unit name", Arg1);
2147 if Ekind (Unit_Name) = E_Package
2148 and then Present (Renamed_Entity (Unit_Name))
2150 Error_Pragma ("pragma% not allowed for renamed package");
2154 -- Pragma appears other than after a compilation unit
2157 -- Here we check for the generic instantiation case and also
2158 -- for the case of processing a generic formal package. We
2159 -- detect these cases by noting that the Sloc on the node
2160 -- does not belong to the current compilation unit.
2162 Sindex := Source_Index (Current_Sem_Unit);
2164 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2165 Rewrite (N, Make_Null_Statement (Loc));
2168 -- If before first declaration, the pragma applies to the
2169 -- enclosing unit, and the name if present must be this name.
2171 elsif Is_Before_First_Decl (N, Plist) then
2172 Unit_Node := Unit_Declaration_Node (Current_Scope);
2173 Unit_Kind := Nkind (Unit_Node);
2175 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2178 elsif Unit_Kind = N_Subprogram_Body
2179 and then not Acts_As_Spec (Unit_Node)
2183 elsif Nkind (Parent_Node) = N_Package_Body then
2186 elsif Nkind (Parent_Node) = N_Package_Specification
2187 and then Plist = Private_Declarations (Parent_Node)
2191 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2192 or else Nkind (Parent_Node) =
2193 N_Generic_Subprogram_Declaration)
2194 and then Plist = Generic_Formal_Declarations (Parent_Node)
2198 elsif Arg_Count > 0 then
2199 Analyze (Get_Pragma_Arg (Arg1));
2201 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2203 ("name in pragma% must be enclosing unit", Arg1);
2206 -- It is legal to have no argument in this context
2212 -- Error if not before first declaration. This is because a
2213 -- library unit pragma argument must be the name of a library
2214 -- unit (RM 10.1.5(7)), but the only names permitted in this
2215 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2216 -- generic subprogram declarations or generic instantiations.
2220 ("pragma% misplaced, must be before first declaration");
2224 end Check_Valid_Library_Unit_Pragma;
2230 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2231 Clist : constant Node_Id := Component_List (Variant);
2235 if not Is_Non_Empty_List (Component_Items (Clist)) then
2237 ("Unchecked_Union may not have empty component list",
2242 Comp := First (Component_Items (Clist));
2243 while Present (Comp) loop
2244 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2253 procedure Error_Pragma (Msg : String) is
2254 MsgF : String := Msg;
2256 Error_Msg_Name_1 := Pname;
2258 Error_Msg_N (MsgF, N);
2262 ----------------------
2263 -- Error_Pragma_Arg --
2264 ----------------------
2266 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2267 MsgF : String := Msg;
2269 Error_Msg_Name_1 := Pname;
2271 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2273 end Error_Pragma_Arg;
2275 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2276 MsgF : String := Msg1;
2278 Error_Msg_Name_1 := Pname;
2280 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2281 Error_Pragma_Arg (Msg2, Arg);
2282 end Error_Pragma_Arg;
2284 ----------------------------
2285 -- Error_Pragma_Arg_Ident --
2286 ----------------------------
2288 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2289 MsgF : String := Msg;
2291 Error_Msg_Name_1 := Pname;
2293 Error_Msg_N (MsgF, Arg);
2295 end Error_Pragma_Arg_Ident;
2297 ----------------------
2298 -- Error_Pragma_Ref --
2299 ----------------------
2301 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2302 MsgF : String := Msg;
2304 Error_Msg_Name_1 := Pname;
2306 Error_Msg_Sloc := Sloc (Ref);
2307 Error_Msg_NE (MsgF, N, Ref);
2309 end Error_Pragma_Ref;
2311 ------------------------
2312 -- Find_Lib_Unit_Name --
2313 ------------------------
2315 function Find_Lib_Unit_Name return Entity_Id is
2317 -- Return inner compilation unit entity, for case of nested
2318 -- categorization pragmas. This happens in generic unit.
2320 if Nkind (Parent (N)) = N_Package_Specification
2321 and then Defining_Entity (Parent (N)) /= Current_Scope
2323 return Defining_Entity (Parent (N));
2325 return Current_Scope;
2327 end Find_Lib_Unit_Name;
2329 ----------------------------
2330 -- Find_Program_Unit_Name --
2331 ----------------------------
2333 procedure Find_Program_Unit_Name (Id : Node_Id) is
2334 Unit_Name : Entity_Id;
2335 Unit_Kind : Node_Kind;
2336 P : constant Node_Id := Parent (N);
2339 if Nkind (P) = N_Compilation_Unit then
2340 Unit_Kind := Nkind (Unit (P));
2342 if Unit_Kind = N_Subprogram_Declaration
2343 or else Unit_Kind = N_Package_Declaration
2344 or else Unit_Kind in N_Generic_Declaration
2346 Unit_Name := Defining_Entity (Unit (P));
2348 if Chars (Id) = Chars (Unit_Name) then
2349 Set_Entity (Id, Unit_Name);
2350 Set_Etype (Id, Etype (Unit_Name));
2352 Set_Etype (Id, Any_Type);
2354 ("cannot find program unit referenced by pragma%");
2358 Set_Etype (Id, Any_Type);
2359 Error_Pragma ("pragma% inapplicable to this unit");
2365 end Find_Program_Unit_Name;
2367 -----------------------------------------
2368 -- Find_Unique_Parameterless_Procedure --
2369 -----------------------------------------
2371 function Find_Unique_Parameterless_Procedure
2373 Arg : Node_Id) return Entity_Id
2375 Proc : Entity_Id := Empty;
2378 -- The body of this procedure needs some comments ???
2380 if not Is_Entity_Name (Name) then
2382 ("argument of pragma% must be entity name", Arg);
2384 elsif not Is_Overloaded (Name) then
2385 Proc := Entity (Name);
2387 if Ekind (Proc) /= E_Procedure
2388 or else Present (First_Formal (Proc))
2391 ("argument of pragma% must be parameterless procedure", Arg);
2396 Found : Boolean := False;
2398 Index : Interp_Index;
2401 Get_First_Interp (Name, Index, It);
2402 while Present (It.Nam) loop
2405 if Ekind (Proc) = E_Procedure
2406 and then No (First_Formal (Proc))
2410 Set_Entity (Name, Proc);
2411 Set_Is_Overloaded (Name, False);
2414 ("ambiguous handler name for pragma% ", Arg);
2418 Get_Next_Interp (Index, It);
2423 ("argument of pragma% must be parameterless procedure",
2426 Proc := Entity (Name);
2432 end Find_Unique_Parameterless_Procedure;
2438 procedure Fix_Error (Msg : in out String) is
2440 if From_Aspect_Specification (N) then
2441 for J in Msg'First .. Msg'Last - 5 loop
2442 if Msg (J .. J + 5) = "pragma" then
2443 Msg (J .. J + 5) := "aspect";
2447 if Error_Msg_Name_1 = Name_Precondition then
2448 Error_Msg_Name_1 := Name_Pre;
2449 elsif Error_Msg_Name_1 = Name_Postcondition then
2450 Error_Msg_Name_1 := Name_Post;
2455 -------------------------
2456 -- Gather_Associations --
2457 -------------------------
2459 procedure Gather_Associations
2461 Args : out Args_List)
2466 -- Initialize all parameters to Empty
2468 for J in Args'Range loop
2472 -- That's all we have to do if there are no argument associations
2474 if No (Pragma_Argument_Associations (N)) then
2478 -- Otherwise first deal with any positional parameters present
2480 Arg := First (Pragma_Argument_Associations (N));
2481 for Index in Args'Range loop
2482 exit when No (Arg) or else Chars (Arg) /= No_Name;
2483 Args (Index) := Get_Pragma_Arg (Arg);
2487 -- Positional parameters all processed, if any left, then we
2488 -- have too many positional parameters.
2490 if Present (Arg) and then Chars (Arg) = No_Name then
2492 ("too many positional associations for pragma%", Arg);
2495 -- Process named parameters if any are present
2497 while Present (Arg) loop
2498 if Chars (Arg) = No_Name then
2500 ("positional association cannot follow named association",
2504 for Index in Names'Range loop
2505 if Names (Index) = Chars (Arg) then
2506 if Present (Args (Index)) then
2508 ("duplicate argument association for pragma%", Arg);
2510 Args (Index) := Get_Pragma_Arg (Arg);
2515 if Index = Names'Last then
2516 Error_Msg_Name_1 := Pname;
2517 Error_Msg_N ("pragma% does not allow & argument", Arg);
2519 -- Check for possible misspelling
2521 for Index1 in Names'Range loop
2522 if Is_Bad_Spelling_Of
2523 (Chars (Arg), Names (Index1))
2525 Error_Msg_Name_1 := Names (Index1);
2526 Error_Msg_N -- CODEFIX
2527 ("\possible misspelling of%", Arg);
2539 end Gather_Associations;
2545 procedure GNAT_Pragma is
2547 Check_Restriction (No_Implementation_Pragmas, N);
2550 --------------------------
2551 -- Is_Before_First_Decl --
2552 --------------------------
2554 function Is_Before_First_Decl
2555 (Pragma_Node : Node_Id;
2556 Decls : List_Id) return Boolean
2558 Item : Node_Id := First (Decls);
2561 -- Only other pragmas can come before this pragma
2564 if No (Item) or else Nkind (Item) /= N_Pragma then
2567 elsif Item = Pragma_Node then
2573 end Is_Before_First_Decl;
2575 -----------------------------
2576 -- Is_Configuration_Pragma --
2577 -----------------------------
2579 -- A configuration pragma must appear in the context clause of a
2580 -- compilation unit, and only other pragmas may precede it. Note that
2581 -- the test below also permits use in a configuration pragma file.
2583 function Is_Configuration_Pragma return Boolean is
2584 Lis : constant List_Id := List_Containing (N);
2585 Par : constant Node_Id := Parent (N);
2589 -- If no parent, then we are in the configuration pragma file,
2590 -- so the placement is definitely appropriate.
2595 -- Otherwise we must be in the context clause of a compilation unit
2596 -- and the only thing allowed before us in the context list is more
2597 -- configuration pragmas.
2599 elsif Nkind (Par) = N_Compilation_Unit
2600 and then Context_Items (Par) = Lis
2607 elsif Nkind (Prg) /= N_Pragma then
2617 end Is_Configuration_Pragma;
2619 --------------------------
2620 -- Is_In_Context_Clause --
2621 --------------------------
2623 function Is_In_Context_Clause return Boolean is
2625 Parent_Node : Node_Id;
2628 if not Is_List_Member (N) then
2632 Plist := List_Containing (N);
2633 Parent_Node := Parent (Plist);
2635 if Parent_Node = Empty
2636 or else Nkind (Parent_Node) /= N_Compilation_Unit
2637 or else Context_Items (Parent_Node) /= Plist
2644 end Is_In_Context_Clause;
2646 ---------------------------------
2647 -- Is_Static_String_Expression --
2648 ---------------------------------
2650 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2651 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2654 Analyze_And_Resolve (Argx);
2655 return Is_OK_Static_Expression (Argx)
2656 and then Nkind (Argx) = N_String_Literal;
2657 end Is_Static_String_Expression;
2659 ----------------------
2660 -- Pragma_Misplaced --
2661 ----------------------
2663 procedure Pragma_Misplaced is
2665 Error_Pragma ("incorrect placement of pragma%");
2666 end Pragma_Misplaced;
2668 ------------------------------------
2669 -- Process Atomic_Shared_Volatile --
2670 ------------------------------------
2672 procedure Process_Atomic_Shared_Volatile is
2679 procedure Set_Atomic (E : Entity_Id);
2680 -- Set given type as atomic, and if no explicit alignment was given,
2681 -- set alignment to unknown, since back end knows what the alignment
2682 -- requirements are for atomic arrays. Note: this step is necessary
2683 -- for derived types.
2689 procedure Set_Atomic (E : Entity_Id) is
2693 if not Has_Alignment_Clause (E) then
2694 Set_Alignment (E, Uint_0);
2698 -- Start of processing for Process_Atomic_Shared_Volatile
2701 Check_Ada_83_Warning;
2702 Check_No_Identifiers;
2703 Check_Arg_Count (1);
2704 Check_Arg_Is_Local_Name (Arg1);
2705 E_Id := Get_Pragma_Arg (Arg1);
2707 if Etype (E_Id) = Any_Type then
2712 D := Declaration_Node (E);
2715 -- Check duplicate before we chain ourselves!
2717 Check_Duplicate_Pragma (E);
2719 -- Now check appropriateness of the entity
2722 if Rep_Item_Too_Early (E, N)
2724 Rep_Item_Too_Late (E, N)
2728 Check_First_Subtype (Arg1);
2731 if Prag_Id /= Pragma_Volatile then
2733 Set_Atomic (Underlying_Type (E));
2734 Set_Atomic (Base_Type (E));
2737 -- Attribute belongs on the base type. If the view of the type is
2738 -- currently private, it also belongs on the underlying type.
2740 Set_Is_Volatile (Base_Type (E));
2741 Set_Is_Volatile (Underlying_Type (E));
2743 Set_Treat_As_Volatile (E);
2744 Set_Treat_As_Volatile (Underlying_Type (E));
2746 elsif K = N_Object_Declaration
2747 or else (K = N_Component_Declaration
2748 and then Original_Record_Component (E) = E)
2750 if Rep_Item_Too_Late (E, N) then
2754 if Prag_Id /= Pragma_Volatile then
2757 -- If the object declaration has an explicit initialization, a
2758 -- temporary may have to be created to hold the expression, to
2759 -- ensure that access to the object remain atomic.
2761 if Nkind (Parent (E)) = N_Object_Declaration
2762 and then Present (Expression (Parent (E)))
2764 Set_Has_Delayed_Freeze (E);
2767 -- An interesting improvement here. If an object of type X is
2768 -- declared atomic, and the type X is not atomic, that's a
2769 -- pity, since it may not have appropriate alignment etc. We
2770 -- can rescue this in the special case where the object and
2771 -- type are in the same unit by just setting the type as
2772 -- atomic, so that the back end will process it as atomic.
2774 Utyp := Underlying_Type (Etype (E));
2777 and then Sloc (E) > No_Location
2778 and then Sloc (Utyp) > No_Location
2780 Get_Source_File_Index (Sloc (E)) =
2781 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2783 Set_Is_Atomic (Underlying_Type (Etype (E)));
2787 Set_Is_Volatile (E);
2788 Set_Treat_As_Volatile (E);
2792 ("inappropriate entity for pragma%", Arg1);
2794 end Process_Atomic_Shared_Volatile;
2796 -------------------------------------------
2797 -- Process_Compile_Time_Warning_Or_Error --
2798 -------------------------------------------
2800 procedure Process_Compile_Time_Warning_Or_Error is
2801 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2804 Check_Arg_Count (2);
2805 Check_No_Identifiers;
2806 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2807 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2809 if Compile_Time_Known_Value (Arg1x) then
2810 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2812 Str : constant String_Id :=
2813 Strval (Get_Pragma_Arg (Arg2));
2814 Len : constant Int := String_Length (Str);
2819 Cent : constant Entity_Id :=
2820 Cunit_Entity (Current_Sem_Unit);
2822 Force : constant Boolean :=
2823 Prag_Id = Pragma_Compile_Time_Warning
2825 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2826 and then (Ekind (Cent) /= E_Package
2827 or else not In_Private_Part (Cent));
2828 -- Set True if this is the warning case, and we are in the
2829 -- visible part of a package spec, or in a subprogram spec,
2830 -- in which case we want to force the client to see the
2831 -- warning, even though it is not in the main unit.
2834 -- Loop through segments of message separated by line feeds.
2835 -- We output these segments as separate messages with
2836 -- continuation marks for all but the first.
2841 Error_Msg_Strlen := 0;
2843 -- Loop to copy characters from argument to error message
2847 exit when Ptr > Len;
2848 CC := Get_String_Char (Str, Ptr);
2851 -- Ignore wide chars ??? else store character
2853 if In_Character_Range (CC) then
2854 C := Get_Character (CC);
2855 exit when C = ASCII.LF;
2856 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2857 Error_Msg_String (Error_Msg_Strlen) := C;
2861 -- Here with one line ready to go
2863 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2865 -- If this is a warning in a spec, then we want clients
2866 -- to see the warning, so mark the message with the
2867 -- special sequence !! to force the warning. In the case
2868 -- of a package spec, we do not force this if we are in
2869 -- the private part of the spec.
2872 if Cont = False then
2873 Error_Msg_N ("<~!!", Arg1);
2876 Error_Msg_N ("\<~!!", Arg1);
2879 -- Error, rather than warning, or in a body, so we do not
2880 -- need to force visibility for client (error will be
2881 -- output in any case, and this is the situation in which
2882 -- we do not want a client to get a warning, since the
2883 -- warning is in the body or the spec private part).
2886 if Cont = False then
2887 Error_Msg_N ("<~", Arg1);
2890 Error_Msg_N ("\<~", Arg1);
2894 exit when Ptr > Len;
2899 end Process_Compile_Time_Warning_Or_Error;
2901 ------------------------
2902 -- Process_Convention --
2903 ------------------------
2905 procedure Process_Convention
2906 (C : out Convention_Id;
2907 Ent : out Entity_Id)
2913 Comp_Unit : Unit_Number_Type;
2915 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2916 -- Called if we have more than one Export/Import/Convention pragma.
2917 -- This is generally illegal, but we have a special case of allowing
2918 -- Import and Interface to coexist if they specify the convention in
2919 -- a consistent manner. We are allowed to do this, since Interface is
2920 -- an implementation defined pragma, and we choose to do it since we
2921 -- know Rational allows this combination. S is the entity id of the
2922 -- subprogram in question. This procedure also sets the special flag
2923 -- Import_Interface_Present in both pragmas in the case where we do
2924 -- have matching Import and Interface pragmas.
2926 procedure Set_Convention_From_Pragma (E : Entity_Id);
2927 -- Set convention in entity E, and also flag that the entity has a
2928 -- convention pragma. If entity is for a private or incomplete type,
2929 -- also set convention and flag on underlying type. This procedure
2930 -- also deals with the special case of C_Pass_By_Copy convention.
2932 -------------------------------
2933 -- Diagnose_Multiple_Pragmas --
2934 -------------------------------
2936 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2937 Pdec : constant Node_Id := Declaration_Node (S);
2941 function Same_Convention (Decl : Node_Id) return Boolean;
2942 -- Decl is a pragma node. This function returns True if this
2943 -- pragma has a first argument that is an identifier with a
2944 -- Chars field corresponding to the Convention_Id C.
2946 function Same_Name (Decl : Node_Id) return Boolean;
2947 -- Decl is a pragma node. This function returns True if this
2948 -- pragma has a second argument that is an identifier with a
2949 -- Chars field that matches the Chars of the current subprogram.
2951 ---------------------
2952 -- Same_Convention --
2953 ---------------------
2955 function Same_Convention (Decl : Node_Id) return Boolean is
2956 Arg1 : constant Node_Id :=
2957 First (Pragma_Argument_Associations (Decl));
2960 if Present (Arg1) then
2962 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2964 if Nkind (Arg) = N_Identifier
2965 and then Is_Convention_Name (Chars (Arg))
2966 and then Get_Convention_Id (Chars (Arg)) = C
2974 end Same_Convention;
2980 function Same_Name (Decl : Node_Id) return Boolean is
2981 Arg1 : constant Node_Id :=
2982 First (Pragma_Argument_Associations (Decl));
2990 Arg2 := Next (Arg1);
2997 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2999 if Nkind (Arg) = N_Identifier
3000 and then Chars (Arg) = Chars (S)
3009 -- Start of processing for Diagnose_Multiple_Pragmas
3014 -- Definitely give message if we have Convention/Export here
3016 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3019 -- If we have an Import or Export, scan back from pragma to
3020 -- find any previous pragma applying to the same procedure.
3021 -- The scan will be terminated by the start of the list, or
3022 -- hitting the subprogram declaration. This won't allow one
3023 -- pragma to appear in the public part and one in the private
3024 -- part, but that seems very unlikely in practice.
3028 while Present (Decl) and then Decl /= Pdec loop
3030 -- Look for pragma with same name as us
3032 if Nkind (Decl) = N_Pragma
3033 and then Same_Name (Decl)
3035 -- Give error if same as our pragma or Export/Convention
3037 if Pragma_Name (Decl) = Name_Export
3039 Pragma_Name (Decl) = Name_Convention
3041 Pragma_Name (Decl) = Pragma_Name (N)
3045 -- Case of Import/Interface or the other way round
3047 elsif Pragma_Name (Decl) = Name_Interface
3049 Pragma_Name (Decl) = Name_Import
3051 -- Here we know that we have Import and Interface. It
3052 -- doesn't matter which way round they are. See if
3053 -- they specify the same convention. If so, all OK,
3054 -- and set special flags to stop other messages
3056 if Same_Convention (Decl) then
3057 Set_Import_Interface_Present (N);
3058 Set_Import_Interface_Present (Decl);
3061 -- If different conventions, special message
3064 Error_Msg_Sloc := Sloc (Decl);
3066 ("convention differs from that given#", Arg1);
3076 -- Give message if needed if we fall through those tests
3080 ("at most one Convention/Export/Import pragma is allowed",
3083 end Diagnose_Multiple_Pragmas;
3085 --------------------------------
3086 -- Set_Convention_From_Pragma --
3087 --------------------------------
3089 procedure Set_Convention_From_Pragma (E : Entity_Id) is
3091 -- Ada 2005 (AI-430): Check invalid attempt to change convention
3092 -- for an overridden dispatching operation. Technically this is
3093 -- an amendment and should only be done in Ada 2005 mode. However,
3094 -- this is clearly a mistake, since the problem that is addressed
3095 -- by this AI is that there is a clear gap in the RM!
3097 if Is_Dispatching_Operation (E)
3098 and then Present (Overridden_Operation (E))
3099 and then C /= Convention (Overridden_Operation (E))
3102 ("cannot change convention for " &
3103 "overridden dispatching operation",
3107 -- Set the convention
3109 Set_Convention (E, C);
3110 Set_Has_Convention_Pragma (E);
3112 if Is_Incomplete_Or_Private_Type (E)
3113 and then Present (Underlying_Type (E))
3115 Set_Convention (Underlying_Type (E), C);
3116 Set_Has_Convention_Pragma (Underlying_Type (E), True);
3119 -- A class-wide type should inherit the convention of the specific
3120 -- root type (although this isn't specified clearly by the RM).
3122 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3123 Set_Convention (Class_Wide_Type (E), C);
3126 -- If the entity is a record type, then check for special case of
3127 -- C_Pass_By_Copy, which is treated the same as C except that the
3128 -- special record flag is set. This convention is only permitted
3129 -- on record types (see AI95-00131).
3131 if Cname = Name_C_Pass_By_Copy then
3132 if Is_Record_Type (E) then
3133 Set_C_Pass_By_Copy (Base_Type (E));
3134 elsif Is_Incomplete_Or_Private_Type (E)
3135 and then Is_Record_Type (Underlying_Type (E))
3137 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3140 ("C_Pass_By_Copy convention allowed only for record type",
3145 -- If the entity is a derived boolean type, check for the special
3146 -- case of convention C, C++, or Fortran, where we consider any
3147 -- nonzero value to represent true.
3149 if Is_Discrete_Type (E)
3150 and then Root_Type (Etype (E)) = Standard_Boolean
3156 C = Convention_Fortran)
3158 Set_Nonzero_Is_True (Base_Type (E));
3160 end Set_Convention_From_Pragma;
3162 -- Start of processing for Process_Convention
3165 Check_At_Least_N_Arguments (2);
3166 Check_Optional_Identifier (Arg1, Name_Convention);
3167 Check_Arg_Is_Identifier (Arg1);
3168 Cname := Chars (Get_Pragma_Arg (Arg1));
3170 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
3171 -- tested again below to set the critical flag).
3173 if Cname = Name_C_Pass_By_Copy then
3176 -- Otherwise we must have something in the standard convention list
3178 elsif Is_Convention_Name (Cname) then
3179 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3181 -- In DEC VMS, it seems that there is an undocumented feature that
3182 -- any unrecognized convention is treated as the default, which for
3183 -- us is convention C. It does not seem so terrible to do this
3184 -- unconditionally, silently in the VMS case, and with a warning
3185 -- in the non-VMS case.
3188 if Warn_On_Export_Import and not OpenVMS_On_Target then
3190 ("?unrecognized convention name, C assumed",
3191 Get_Pragma_Arg (Arg1));
3197 Check_Optional_Identifier (Arg2, Name_Entity);
3198 Check_Arg_Is_Local_Name (Arg2);
3200 Id := Get_Pragma_Arg (Arg2);
3203 if not Is_Entity_Name (Id) then
3204 Error_Pragma_Arg ("entity name required", Arg2);
3209 -- Set entity to return
3213 -- Ada_Pass_By_Copy special checking
3215 if C = Convention_Ada_Pass_By_Copy then
3216 if not Is_First_Subtype (E) then
3218 ("convention `Ada_Pass_By_Copy` only "
3219 & "allowed for types", Arg2);
3222 if Is_By_Reference_Type (E) then
3224 ("convention `Ada_Pass_By_Copy` not allowed for "
3225 & "by-reference type", Arg1);
3229 -- Ada_Pass_By_Reference special checking
3231 if C = Convention_Ada_Pass_By_Reference then
3232 if not Is_First_Subtype (E) then
3234 ("convention `Ada_Pass_By_Reference` only "
3235 & "allowed for types", Arg2);
3238 if Is_By_Copy_Type (E) then
3240 ("convention `Ada_Pass_By_Reference` not allowed for "
3241 & "by-copy type", Arg1);
3245 -- Go to renamed subprogram if present, since convention applies to
3246 -- the actual renamed entity, not to the renaming entity. If the
3247 -- subprogram is inherited, go to parent subprogram.
3249 if Is_Subprogram (E)
3250 and then Present (Alias (E))
3252 if Nkind (Parent (Declaration_Node (E))) =
3253 N_Subprogram_Renaming_Declaration
3255 if Scope (E) /= Scope (Alias (E)) then
3257 ("cannot apply pragma% to non-local entity&#", E);
3262 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3263 N_Private_Extension_Declaration)
3264 and then Scope (E) = Scope (Alias (E))
3268 -- Return the parent subprogram the entity was inherited from
3274 -- Check that we are not applying this to a specless body
3276 if Is_Subprogram (E)
3277 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3280 ("pragma% requires separate spec and must come before body");
3283 -- Check that we are not applying this to a named constant
3285 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3286 Error_Msg_Name_1 := Pname;
3288 ("cannot apply pragma% to named constant!",
3289 Get_Pragma_Arg (Arg2));
3291 ("\supply appropriate type for&!", Arg2);
3294 if Ekind (E) = E_Enumeration_Literal then
3295 Error_Pragma ("enumeration literal not allowed for pragma%");
3298 -- Check for rep item appearing too early or too late
3300 if Etype (E) = Any_Type
3301 or else Rep_Item_Too_Early (E, N)
3305 elsif Present (Underlying_Type (E)) then
3306 E := Underlying_Type (E);
3309 if Rep_Item_Too_Late (E, N) then
3313 if Has_Convention_Pragma (E) then
3314 Diagnose_Multiple_Pragmas (E);
3316 elsif Convention (E) = Convention_Protected
3317 or else Ekind (Scope (E)) = E_Protected_Type
3320 ("a protected operation cannot be given a different convention",
3324 -- For Intrinsic, a subprogram is required
3326 if C = Convention_Intrinsic
3327 and then not Is_Subprogram (E)
3328 and then not Is_Generic_Subprogram (E)
3331 ("second argument of pragma% must be a subprogram", Arg2);
3334 -- For Stdcall, a subprogram, variable or subprogram type is required
3336 if C = Convention_Stdcall
3337 and then not Is_Subprogram (E)
3338 and then not Is_Generic_Subprogram (E)
3339 and then Ekind (E) /= E_Variable
3342 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3345 ("second argument of pragma% must be subprogram (type)",
3349 if not Is_Subprogram (E)
3350 and then not Is_Generic_Subprogram (E)
3352 Set_Convention_From_Pragma (E);
3355 Check_First_Subtype (Arg2);
3356 Set_Convention_From_Pragma (Base_Type (E));
3358 -- For subprograms, we must set the convention on the
3359 -- internally generated directly designated type as well.
3361 if Ekind (E) = E_Access_Subprogram_Type then
3362 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3366 -- For the subprogram case, set proper convention for all homonyms
3367 -- in same scope and the same declarative part, i.e. the same
3368 -- compilation unit.
3371 Comp_Unit := Get_Source_Unit (E);
3372 Set_Convention_From_Pragma (E);
3374 -- Treat a pragma Import as an implicit body, for GPS use
3376 if Prag_Id = Pragma_Import then
3377 Generate_Reference (E, Id, 'b');
3380 -- Loop through the homonyms of the pragma argument's entity
3385 exit when No (E1) or else Scope (E1) /= Current_Scope;
3387 -- Do not set the pragma on inherited operations or on formal
3390 if Comes_From_Source (E1)
3391 and then Comp_Unit = Get_Source_Unit (E1)
3392 and then not Is_Formal_Subprogram (E1)
3393 and then Nkind (Original_Node (Parent (E1))) /=
3394 N_Full_Type_Declaration
3396 if Present (Alias (E1))
3397 and then Scope (E1) /= Scope (Alias (E1))
3400 ("cannot apply pragma% to non-local entity& declared#",
3404 Set_Convention_From_Pragma (E1);
3406 if Prag_Id = Pragma_Import then
3407 Generate_Reference (E1, Id, 'b');
3411 -- For aspect case, do NOT apply to homonyms
3413 exit when From_Aspect_Specification (N);
3416 end Process_Convention;
3418 -----------------------------------------------------
3419 -- Process_Extended_Import_Export_Exception_Pragma --
3420 -----------------------------------------------------
3422 procedure Process_Extended_Import_Export_Exception_Pragma
3423 (Arg_Internal : Node_Id;
3424 Arg_External : Node_Id;
3432 if not OpenVMS_On_Target then
3434 ("?pragma% ignored (applies only to Open'V'M'S)");
3437 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3438 Def_Id := Entity (Arg_Internal);
3440 if Ekind (Def_Id) /= E_Exception then
3442 ("pragma% must refer to declared exception", Arg_Internal);
3445 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3447 if Present (Arg_Form) then
3448 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3451 if Present (Arg_Form)
3452 and then Chars (Arg_Form) = Name_Ada
3456 Set_Is_VMS_Exception (Def_Id);
3457 Set_Exception_Code (Def_Id, No_Uint);
3460 if Present (Arg_Code) then
3461 if not Is_VMS_Exception (Def_Id) then
3463 ("Code option for pragma% not allowed for Ada case",
3467 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3468 Code_Val := Expr_Value (Arg_Code);
3470 if not UI_Is_In_Int_Range (Code_Val) then
3472 ("Code option for pragma% must be in 32-bit range",
3476 Set_Exception_Code (Def_Id, Code_Val);
3479 end Process_Extended_Import_Export_Exception_Pragma;
3481 -------------------------------------------------
3482 -- Process_Extended_Import_Export_Internal_Arg --
3483 -------------------------------------------------
3485 procedure Process_Extended_Import_Export_Internal_Arg
3486 (Arg_Internal : Node_Id := Empty)
3489 if No (Arg_Internal) then
3490 Error_Pragma ("Internal parameter required for pragma%");
3493 if Nkind (Arg_Internal) = N_Identifier then
3496 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3497 and then (Prag_Id = Pragma_Import_Function
3499 Prag_Id = Pragma_Export_Function)
3505 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3508 Check_Arg_Is_Local_Name (Arg_Internal);
3509 end Process_Extended_Import_Export_Internal_Arg;
3511 --------------------------------------------------
3512 -- Process_Extended_Import_Export_Object_Pragma --
3513 --------------------------------------------------
3515 procedure Process_Extended_Import_Export_Object_Pragma
3516 (Arg_Internal : Node_Id;
3517 Arg_External : Node_Id;
3523 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3524 Def_Id := Entity (Arg_Internal);
3526 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3528 ("pragma% must designate an object", Arg_Internal);
3531 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3533 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3536 ("previous Common/Psect_Object applies, pragma % not permitted",
3540 if Rep_Item_Too_Late (Def_Id, N) then
3544 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3546 if Present (Arg_Size) then
3547 Check_Arg_Is_External_Name (Arg_Size);
3550 -- Export_Object case
3552 if Prag_Id = Pragma_Export_Object then
3553 if not Is_Library_Level_Entity (Def_Id) then
3555 ("argument for pragma% must be library level entity",
3559 if Ekind (Current_Scope) = E_Generic_Package then
3560 Error_Pragma ("pragma& cannot appear in a generic unit");
3563 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3565 ("exported object must have compile time known size",
3569 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3570 Error_Msg_N ("?duplicate Export_Object pragma", N);
3572 Set_Exported (Def_Id, Arg_Internal);
3575 -- Import_Object case
3578 if Is_Concurrent_Type (Etype (Def_Id)) then
3580 ("cannot use pragma% for task/protected object",
3584 if Ekind (Def_Id) = E_Constant then
3586 ("cannot import a constant", Arg_Internal);
3589 if Warn_On_Export_Import
3590 and then Has_Discriminants (Etype (Def_Id))
3593 ("imported value must be initialized?", Arg_Internal);
3596 if Warn_On_Export_Import
3597 and then Is_Access_Type (Etype (Def_Id))
3600 ("cannot import object of an access type?", Arg_Internal);
3603 if Warn_On_Export_Import
3604 and then Is_Imported (Def_Id)
3607 ("?duplicate Import_Object pragma", N);
3609 -- Check for explicit initialization present. Note that an
3610 -- initialization generated by the code generator, e.g. for an
3611 -- access type, does not count here.
3613 elsif Present (Expression (Parent (Def_Id)))
3616 (Original_Node (Expression (Parent (Def_Id))))
3618 Error_Msg_Sloc := Sloc (Def_Id);
3620 ("imported entities cannot be initialized (RM B.1(24))",
3621 "\no initialization allowed for & declared#", Arg1);
3623 Set_Imported (Def_Id);
3624 Note_Possible_Modification (Arg_Internal, Sure => False);
3627 end Process_Extended_Import_Export_Object_Pragma;
3629 ------------------------------------------------------
3630 -- Process_Extended_Import_Export_Subprogram_Pragma --
3631 ------------------------------------------------------
3633 procedure Process_Extended_Import_Export_Subprogram_Pragma
3634 (Arg_Internal : Node_Id;
3635 Arg_External : Node_Id;
3636 Arg_Parameter_Types : Node_Id;
3637 Arg_Result_Type : Node_Id := Empty;
3638 Arg_Mechanism : Node_Id;
3639 Arg_Result_Mechanism : Node_Id := Empty;
3640 Arg_First_Optional_Parameter : Node_Id := Empty)
3646 Ambiguous : Boolean;
3650 function Same_Base_Type
3652 Formal : Entity_Id) return Boolean;
3653 -- Determines if Ptype references the type of Formal. Note that only
3654 -- the base types need to match according to the spec. Ptype here is
3655 -- the argument from the pragma, which is either a type name, or an
3656 -- access attribute.
3658 --------------------
3659 -- Same_Base_Type --
3660 --------------------
3662 function Same_Base_Type
3664 Formal : Entity_Id) return Boolean
3666 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3670 -- Case where pragma argument is typ'Access
3672 if Nkind (Ptype) = N_Attribute_Reference
3673 and then Attribute_Name (Ptype) = Name_Access
3675 Pref := Prefix (Ptype);
3678 if not Is_Entity_Name (Pref)
3679 or else Entity (Pref) = Any_Type
3684 -- We have a match if the corresponding argument is of an
3685 -- anonymous access type, and its designated type matches the
3686 -- type of the prefix of the access attribute
3688 return Ekind (Ftyp) = E_Anonymous_Access_Type
3689 and then Base_Type (Entity (Pref)) =
3690 Base_Type (Etype (Designated_Type (Ftyp)));
3692 -- Case where pragma argument is a type name
3697 if not Is_Entity_Name (Ptype)
3698 or else Entity (Ptype) = Any_Type
3703 -- We have a match if the corresponding argument is of the type
3704 -- given in the pragma (comparing base types)
3706 return Base_Type (Entity (Ptype)) = Ftyp;
3710 -- Start of processing for
3711 -- Process_Extended_Import_Export_Subprogram_Pragma
3714 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3718 -- Loop through homonyms (overloadings) of the entity
3720 Hom_Id := Entity (Arg_Internal);
3721 while Present (Hom_Id) loop
3722 Def_Id := Get_Base_Subprogram (Hom_Id);
3724 -- We need a subprogram in the current scope
3726 if not Is_Subprogram (Def_Id)
3727 or else Scope (Def_Id) /= Current_Scope
3734 -- Pragma cannot apply to subprogram body
3736 if Is_Subprogram (Def_Id)
3737 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3741 ("pragma% requires separate spec"
3742 & " and must come before body");
3745 -- Test result type if given, note that the result type
3746 -- parameter can only be present for the function cases.
3748 if Present (Arg_Result_Type)
3749 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3753 elsif Etype (Def_Id) /= Standard_Void_Type
3755 (Pname = Name_Export_Procedure
3757 Pname = Name_Import_Procedure)
3761 -- Test parameter types if given. Note that this parameter
3762 -- has not been analyzed (and must not be, since it is
3763 -- semantic nonsense), so we get it as the parser left it.
3765 elsif Present (Arg_Parameter_Types) then
3766 Check_Matching_Types : declare
3771 Formal := First_Formal (Def_Id);
3773 if Nkind (Arg_Parameter_Types) = N_Null then
3774 if Present (Formal) then
3778 -- A list of one type, e.g. (List) is parsed as
3779 -- a parenthesized expression.
3781 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3782 and then Paren_Count (Arg_Parameter_Types) = 1
3785 or else Present (Next_Formal (Formal))
3790 Same_Base_Type (Arg_Parameter_Types, Formal);
3793 -- A list of more than one type is parsed as a aggregate
3795 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3796 and then Paren_Count (Arg_Parameter_Types) = 0
3798 Ptype := First (Expressions (Arg_Parameter_Types));
3799 while Present (Ptype) or else Present (Formal) loop
3802 or else not Same_Base_Type (Ptype, Formal)
3807 Next_Formal (Formal);
3812 -- Anything else is of the wrong form
3816 ("wrong form for Parameter_Types parameter",
3817 Arg_Parameter_Types);
3819 end Check_Matching_Types;
3822 -- Match is now False if the entry we found did not match
3823 -- either a supplied Parameter_Types or Result_Types argument
3829 -- Ambiguous case, the flag Ambiguous shows if we already
3830 -- detected this and output the initial messages.
3833 if not Ambiguous then
3835 Error_Msg_Name_1 := Pname;
3837 ("pragma% does not uniquely identify subprogram!",
3839 Error_Msg_Sloc := Sloc (Ent);
3840 Error_Msg_N ("matching subprogram #!", N);
3844 Error_Msg_Sloc := Sloc (Def_Id);
3845 Error_Msg_N ("matching subprogram #!", N);
3850 Hom_Id := Homonym (Hom_Id);
3853 -- See if we found an entry
3856 if not Ambiguous then
3857 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3859 ("pragma% cannot be given for generic subprogram");
3862 ("pragma% does not identify local subprogram");
3869 -- Import pragmas must be for imported entities
3871 if Prag_Id = Pragma_Import_Function
3873 Prag_Id = Pragma_Import_Procedure
3875 Prag_Id = Pragma_Import_Valued_Procedure
3877 if not Is_Imported (Ent) then
3879 ("pragma Import or Interface must precede pragma%");
3882 -- Here we have the Export case which can set the entity as exported
3884 -- But does not do so if the specified external name is null, since
3885 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3886 -- compatible) to request no external name.
3888 elsif Nkind (Arg_External) = N_String_Literal
3889 and then String_Length (Strval (Arg_External)) = 0
3893 -- In all other cases, set entity as exported
3896 Set_Exported (Ent, Arg_Internal);
3899 -- Special processing for Valued_Procedure cases
3901 if Prag_Id = Pragma_Import_Valued_Procedure
3903 Prag_Id = Pragma_Export_Valued_Procedure
3905 Formal := First_Formal (Ent);
3908 Error_Pragma ("at least one parameter required for pragma%");
3910 elsif Ekind (Formal) /= E_Out_Parameter then
3911 Error_Pragma ("first parameter must have mode out for pragma%");
3914 Set_Is_Valued_Procedure (Ent);
3918 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3920 -- Process Result_Mechanism argument if present. We have already
3921 -- checked that this is only allowed for the function case.
3923 if Present (Arg_Result_Mechanism) then
3924 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3927 -- Process Mechanism parameter if present. Note that this parameter
3928 -- is not analyzed, and must not be analyzed since it is semantic
3929 -- nonsense, so we get it in exactly as the parser left it.
3931 if Present (Arg_Mechanism) then
3939 -- A single mechanism association without a formal parameter
3940 -- name is parsed as a parenthesized expression. All other
3941 -- cases are parsed as aggregates, so we rewrite the single
3942 -- parameter case as an aggregate for consistency.
3944 if Nkind (Arg_Mechanism) /= N_Aggregate
3945 and then Paren_Count (Arg_Mechanism) = 1
3947 Rewrite (Arg_Mechanism,
3948 Make_Aggregate (Sloc (Arg_Mechanism),
3949 Expressions => New_List (
3950 Relocate_Node (Arg_Mechanism))));
3953 -- Case of only mechanism name given, applies to all formals
3955 if Nkind (Arg_Mechanism) /= N_Aggregate then
3956 Formal := First_Formal (Ent);
3957 while Present (Formal) loop
3958 Set_Mechanism_Value (Formal, Arg_Mechanism);
3959 Next_Formal (Formal);
3962 -- Case of list of mechanism associations given
3965 if Null_Record_Present (Arg_Mechanism) then
3967 ("inappropriate form for Mechanism parameter",
3971 -- Deal with positional ones first
3973 Formal := First_Formal (Ent);
3975 if Present (Expressions (Arg_Mechanism)) then
3976 Mname := First (Expressions (Arg_Mechanism));
3977 while Present (Mname) loop
3980 ("too many mechanism associations", Mname);
3983 Set_Mechanism_Value (Formal, Mname);
3984 Next_Formal (Formal);
3989 -- Deal with named entries
3991 if Present (Component_Associations (Arg_Mechanism)) then
3992 Massoc := First (Component_Associations (Arg_Mechanism));
3993 while Present (Massoc) loop
3994 Choice := First (Choices (Massoc));
3996 if Nkind (Choice) /= N_Identifier
3997 or else Present (Next (Choice))
4000 ("incorrect form for mechanism association",
4004 Formal := First_Formal (Ent);
4008 ("parameter name & not present", Choice);
4011 if Chars (Choice) = Chars (Formal) then
4013 (Formal, Expression (Massoc));
4015 -- Set entity on identifier (needed by ASIS)
4017 Set_Entity (Choice, Formal);
4022 Next_Formal (Formal);
4032 -- Process First_Optional_Parameter argument if present. We have
4033 -- already checked that this is only allowed for the Import case.
4035 if Present (Arg_First_Optional_Parameter) then
4036 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4038 ("first optional parameter must be formal parameter name",
4039 Arg_First_Optional_Parameter);
4042 Formal := First_Formal (Ent);
4046 ("specified formal parameter& not found",
4047 Arg_First_Optional_Parameter);
4050 exit when Chars (Formal) =
4051 Chars (Arg_First_Optional_Parameter);
4053 Next_Formal (Formal);
4056 Set_First_Optional_Parameter (Ent, Formal);
4058 -- Check specified and all remaining formals have right form
4060 while Present (Formal) loop
4061 if Ekind (Formal) /= E_In_Parameter then
4063 ("optional formal& is not of mode in!",
4064 Arg_First_Optional_Parameter, Formal);
4067 Dval := Default_Value (Formal);
4071 ("optional formal& does not have default value!",
4072 Arg_First_Optional_Parameter, Formal);
4074 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4079 ("default value for optional formal& is non-static!",
4080 Arg_First_Optional_Parameter, Formal);
4084 Set_Is_Optional_Parameter (Formal);
4085 Next_Formal (Formal);
4088 end Process_Extended_Import_Export_Subprogram_Pragma;
4090 --------------------------
4091 -- Process_Generic_List --
4092 --------------------------
4094 procedure Process_Generic_List is
4099 Check_No_Identifiers;
4100 Check_At_Least_N_Arguments (1);
4103 while Present (Arg) loop
4104 Exp := Get_Pragma_Arg (Arg);
4107 if not Is_Entity_Name (Exp)
4109 (not Is_Generic_Instance (Entity (Exp))
4111 not Is_Generic_Unit (Entity (Exp)))
4114 ("pragma% argument must be name of generic unit/instance",
4120 end Process_Generic_List;
4122 ------------------------------------
4123 -- Process_Import_Predefined_Type --
4124 ------------------------------------
4126 procedure Process_Import_Predefined_Type is
4127 Loc : constant Source_Ptr := Sloc (N);
4129 Ftyp : Node_Id := Empty;
4135 String_To_Name_Buffer (Strval (Expression (Arg3)));
4138 Elmt := First_Elmt (Predefined_Float_Types);
4139 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4143 Ftyp := Node (Elmt);
4145 if Present (Ftyp) then
4147 -- Don't build a derived type declaration, because predefined C
4148 -- types have no declaration anywhere, so cannot really be named.
4149 -- Instead build a full type declaration, starting with an
4150 -- appropriate type definition is built
4152 if Is_Floating_Point_Type (Ftyp) then
4153 Def := Make_Floating_Point_Definition (Loc,
4154 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4155 Make_Real_Range_Specification (Loc,
4156 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4157 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4159 -- Should never have a predefined type we cannot handle
4162 raise Program_Error;
4165 -- Build and insert a Full_Type_Declaration, which will be
4166 -- analyzed as soon as this list entry has been analyzed.
4168 Decl := Make_Full_Type_Declaration (Loc,
4169 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4170 Type_Definition => Def);
4172 Insert_After (N, Decl);
4173 Mark_Rewrite_Insertion (Decl);
4176 Error_Pragma_Arg ("no matching type found for pragma%",
4179 end Process_Import_Predefined_Type;
4181 ---------------------------------
4182 -- Process_Import_Or_Interface --
4183 ---------------------------------
4185 procedure Process_Import_Or_Interface is
4191 Process_Convention (C, Def_Id);
4192 Kill_Size_Check_Code (Def_Id);
4193 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4195 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4197 -- We do not permit Import to apply to a renaming declaration
4199 if Present (Renamed_Object (Def_Id)) then
4201 ("pragma% not allowed for object renaming", Arg2);
4203 -- User initialization is not allowed for imported object, but
4204 -- the object declaration may contain a default initialization,
4205 -- that will be discarded. Note that an explicit initialization
4206 -- only counts if it comes from source, otherwise it is simply
4207 -- the code generator making an implicit initialization explicit.
4209 elsif Present (Expression (Parent (Def_Id)))
4210 and then Comes_From_Source (Expression (Parent (Def_Id)))
4212 Error_Msg_Sloc := Sloc (Def_Id);
4214 ("no initialization allowed for declaration of& #",
4215 "\imported entities cannot be initialized (RM B.1(24))",
4219 Set_Imported (Def_Id);
4220 Process_Interface_Name (Def_Id, Arg3, Arg4);
4222 -- Note that we do not set Is_Public here. That's because we
4223 -- only want to set it if there is no address clause, and we
4224 -- don't know that yet, so we delay that processing till
4227 -- pragma Import completes deferred constants
4229 if Ekind (Def_Id) = E_Constant then
4230 Set_Has_Completion (Def_Id);
4233 -- It is not possible to import a constant of an unconstrained
4234 -- array type (e.g. string) because there is no simple way to
4235 -- write a meaningful subtype for it.
4237 if Is_Array_Type (Etype (Def_Id))
4238 and then not Is_Constrained (Etype (Def_Id))
4241 ("imported constant& must have a constrained subtype",
4246 elsif Is_Subprogram (Def_Id)
4247 or else Is_Generic_Subprogram (Def_Id)
4249 -- If the name is overloaded, pragma applies to all of the denoted
4250 -- entities in the same declarative part.
4253 while Present (Hom_Id) loop
4254 Def_Id := Get_Base_Subprogram (Hom_Id);
4256 -- Ignore inherited subprograms because the pragma will apply
4257 -- to the parent operation, which is the one called.
4259 if Is_Overloadable (Def_Id)
4260 and then Present (Alias (Def_Id))
4264 -- If it is not a subprogram, it must be in an outer scope and
4265 -- pragma does not apply.
4267 elsif not Is_Subprogram (Def_Id)
4268 and then not Is_Generic_Subprogram (Def_Id)
4272 -- The pragma does not apply to primitives of interfaces
4274 elsif Is_Dispatching_Operation (Def_Id)
4275 and then Present (Find_Dispatching_Type (Def_Id))
4276 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4280 -- Verify that the homonym is in the same declarative part (not
4281 -- just the same scope).
4283 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4284 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4289 Set_Imported (Def_Id);
4291 -- Reject an Import applied to an abstract subprogram
4293 if Is_Subprogram (Def_Id)
4294 and then Is_Abstract_Subprogram (Def_Id)
4296 Error_Msg_Sloc := Sloc (Def_Id);
4298 ("cannot import abstract subprogram& declared#",
4302 -- Special processing for Convention_Intrinsic
4304 if C = Convention_Intrinsic then
4306 -- Link_Name argument not allowed for intrinsic
4310 Set_Is_Intrinsic_Subprogram (Def_Id);
4312 -- If no external name is present, then check that this
4313 -- is a valid intrinsic subprogram. If an external name
4314 -- is present, then this is handled by the back end.
4317 Check_Intrinsic_Subprogram
4318 (Def_Id, Get_Pragma_Arg (Arg2));
4322 -- All interfaced procedures need an external symbol created
4323 -- for them since they are always referenced from another
4326 Set_Is_Public (Def_Id);
4328 -- Verify that the subprogram does not have a completion
4329 -- through a renaming declaration. For other completions the
4330 -- pragma appears as a too late representation.
4333 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4337 and then Nkind (Decl) = N_Subprogram_Declaration
4338 and then Present (Corresponding_Body (Decl))
4339 and then Nkind (Unit_Declaration_Node
4340 (Corresponding_Body (Decl))) =
4341 N_Subprogram_Renaming_Declaration
4343 Error_Msg_Sloc := Sloc (Def_Id);
4345 ("cannot import&, renaming already provided for " &
4346 "declaration #", N, Def_Id);
4350 Set_Has_Completion (Def_Id);
4351 Process_Interface_Name (Def_Id, Arg3, Arg4);
4354 if Is_Compilation_Unit (Hom_Id) then
4356 -- Its possible homonyms are not affected by the pragma.
4357 -- Such homonyms might be present in the context of other
4358 -- units being compiled.
4363 Hom_Id := Homonym (Hom_Id);
4367 -- When the convention is Java or CIL, we also allow Import to be
4368 -- given for packages, generic packages, exceptions, record
4369 -- components, and access to subprograms.
4371 elsif (C = Convention_Java or else C = Convention_CIL)
4373 (Is_Package_Or_Generic_Package (Def_Id)
4374 or else Ekind (Def_Id) = E_Exception
4375 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4376 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4378 Set_Imported (Def_Id);
4379 Set_Is_Public (Def_Id);
4380 Process_Interface_Name (Def_Id, Arg3, Arg4);
4382 -- Import a CPP class
4384 elsif Is_Record_Type (Def_Id)
4385 and then C = Convention_CPP
4387 -- Types treated as CPP classes must be declared limited (note:
4388 -- this used to be a warning but there is no real benefit to it
4389 -- since we did effectively intend to treat the type as limited
4392 if not Is_Limited_Type (Def_Id) then
4394 ("imported 'C'P'P type must be limited",
4395 Get_Pragma_Arg (Arg2));
4398 Set_Is_CPP_Class (Def_Id);
4400 -- Imported CPP types must not have discriminants (because C++
4401 -- classes do not have discriminants).
4403 if Has_Discriminants (Def_Id) then
4405 ("imported 'C'P'P type cannot have discriminants",
4406 First (Discriminant_Specifications
4407 (Declaration_Node (Def_Id))));
4410 -- Components of imported CPP types must not have default
4411 -- expressions because the constructor (if any) is on the
4415 Tdef : constant Node_Id :=
4416 Type_Definition (Declaration_Node (Def_Id));
4421 if Nkind (Tdef) = N_Record_Definition then
4422 Clist := Component_List (Tdef);
4425 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4426 Clist := Component_List (Record_Extension_Part (Tdef));
4429 if Present (Clist) then
4430 Comp := First (Component_Items (Clist));
4431 while Present (Comp) loop
4432 if Present (Expression (Comp)) then
4434 ("component of imported 'C'P'P type cannot have" &
4435 " default expression", Expression (Comp));
4443 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4445 Check_Arg_Count (3);
4446 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4448 Process_Import_Predefined_Type;
4452 ("second argument of pragma% must be object, subprogram" &
4453 " or incomplete type",
4457 -- If this pragma applies to a compilation unit, then the unit, which
4458 -- is a subprogram, does not require (or allow) a body. We also do
4459 -- not need to elaborate imported procedures.
4461 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4463 Cunit : constant Node_Id := Parent (Parent (N));
4465 Set_Body_Required (Cunit, False);
4468 end Process_Import_Or_Interface;
4470 --------------------
4471 -- Process_Inline --
4472 --------------------
4474 procedure Process_Inline (Active : Boolean) is
4481 Effective : Boolean := False;
4482 -- Set True if inline has some effect, i.e. if there is at least one
4483 -- subprogram set as inlined as a result of the use of the pragma.
4485 procedure Make_Inline (Subp : Entity_Id);
4486 -- Subp is the defining unit name of the subprogram declaration. Set
4487 -- the flag, as well as the flag in the corresponding body, if there
4490 procedure Set_Inline_Flags (Subp : Entity_Id);
4491 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4492 -- Has_Pragma_Inline_Always for the Inline_Always case.
4494 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4495 -- Returns True if it can be determined at this stage that inlining
4496 -- is not possible, for example if the body is available and contains
4497 -- exception handlers, we prevent inlining, since otherwise we can
4498 -- get undefined symbols at link time. This function also emits a
4499 -- warning if front-end inlining is enabled and the pragma appears
4502 -- ??? is business with link symbols still valid, or does it relate
4503 -- to front end ZCX which is being phased out ???
4505 ---------------------------
4506 -- Inlining_Not_Possible --
4507 ---------------------------
4509 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4510 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4514 if Nkind (Decl) = N_Subprogram_Body then
4515 Stats := Handled_Statement_Sequence (Decl);
4516 return Present (Exception_Handlers (Stats))
4517 or else Present (At_End_Proc (Stats));
4519 elsif Nkind (Decl) = N_Subprogram_Declaration
4520 and then Present (Corresponding_Body (Decl))
4522 if Front_End_Inlining
4523 and then Analyzed (Corresponding_Body (Decl))
4525 Error_Msg_N ("pragma appears too late, ignored?", N);
4528 -- If the subprogram is a renaming as body, the body is just a
4529 -- call to the renamed subprogram, and inlining is trivially
4533 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4534 N_Subprogram_Renaming_Declaration
4540 Handled_Statement_Sequence
4541 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4544 Present (Exception_Handlers (Stats))
4545 or else Present (At_End_Proc (Stats));
4549 -- If body is not available, assume the best, the check is
4550 -- performed again when compiling enclosing package bodies.
4554 end Inlining_Not_Possible;
4560 procedure Make_Inline (Subp : Entity_Id) is
4561 Kind : constant Entity_Kind := Ekind (Subp);
4562 Inner_Subp : Entity_Id := Subp;
4565 -- Ignore if bad type, avoid cascaded error
4567 if Etype (Subp) = Any_Type then
4571 -- Ignore if all inlining is suppressed
4573 elsif Suppress_All_Inlining then
4577 -- If inlining is not possible, for now do not treat as an error
4579 elsif Inlining_Not_Possible (Subp) then
4583 -- Here we have a candidate for inlining, but we must exclude
4584 -- derived operations. Otherwise we would end up trying to inline
4585 -- a phantom declaration, and the result would be to drag in a
4586 -- body which has no direct inlining associated with it. That
4587 -- would not only be inefficient but would also result in the
4588 -- backend doing cross-unit inlining in cases where it was
4589 -- definitely inappropriate to do so.
4591 -- However, a simple Comes_From_Source test is insufficient, since
4592 -- we do want to allow inlining of generic instances which also do
4593 -- not come from source. We also need to recognize specs generated
4594 -- by the front-end for bodies that carry the pragma. Finally,
4595 -- predefined operators do not come from source but are not
4596 -- inlineable either.
4598 elsif Is_Generic_Instance (Subp)
4599 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4603 elsif not Comes_From_Source (Subp)
4604 and then Scope (Subp) /= Standard_Standard
4610 -- The referenced entity must either be the enclosing entity, or
4611 -- an entity declared within the current open scope.
4613 if Present (Scope (Subp))
4614 and then Scope (Subp) /= Current_Scope
4615 and then Subp /= Current_Scope
4618 ("argument of% must be entity in current scope", Assoc);
4622 -- Processing for procedure, operator or function. If subprogram
4623 -- is aliased (as for an instance) indicate that the renamed
4624 -- entity (if declared in the same unit) is inlined.
4626 if Is_Subprogram (Subp) then
4627 Inner_Subp := Ultimate_Alias (Inner_Subp);
4629 if In_Same_Source_Unit (Subp, Inner_Subp) then
4630 Set_Inline_Flags (Inner_Subp);
4632 Decl := Parent (Parent (Inner_Subp));
4634 if Nkind (Decl) = N_Subprogram_Declaration
4635 and then Present (Corresponding_Body (Decl))
4637 Set_Inline_Flags (Corresponding_Body (Decl));
4639 elsif Is_Generic_Instance (Subp) then
4641 -- Indicate that the body needs to be created for
4642 -- inlining subsequent calls. The instantiation node
4643 -- follows the declaration of the wrapper package
4646 if Scope (Subp) /= Standard_Standard
4648 Need_Subprogram_Instance_Body
4649 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4659 -- For a generic subprogram set flag as well, for use at the point
4660 -- of instantiation, to determine whether the body should be
4663 elsif Is_Generic_Subprogram (Subp) then
4664 Set_Inline_Flags (Subp);
4667 -- Literals are by definition inlined
4669 elsif Kind = E_Enumeration_Literal then
4672 -- Anything else is an error
4676 ("expect subprogram name for pragma%", Assoc);
4680 ----------------------
4681 -- Set_Inline_Flags --
4682 ----------------------
4684 procedure Set_Inline_Flags (Subp : Entity_Id) is
4687 Set_Is_Inlined (Subp);
4690 if not Has_Pragma_Inline (Subp) then
4691 Set_Has_Pragma_Inline (Subp);
4695 if Prag_Id = Pragma_Inline_Always then
4696 Set_Has_Pragma_Inline_Always (Subp);
4698 end Set_Inline_Flags;
4700 -- Start of processing for Process_Inline
4703 Check_No_Identifiers;
4704 Check_At_Least_N_Arguments (1);
4707 Inline_Processing_Required := True;
4711 while Present (Assoc) loop
4712 Subp_Id := Get_Pragma_Arg (Assoc);
4716 if Is_Entity_Name (Subp_Id) then
4717 Subp := Entity (Subp_Id);
4719 if Subp = Any_Id then
4721 -- If previous error, avoid cascaded errors
4729 -- For the pragma case, climb homonym chain. This is
4730 -- what implements allowing the pragma in the renaming
4731 -- case, with the result applying to the ancestors.
4733 if not From_Aspect_Specification (N) then
4734 while Present (Homonym (Subp))
4735 and then Scope (Homonym (Subp)) = Current_Scope
4737 Make_Inline (Homonym (Subp));
4738 Subp := Homonym (Subp);
4746 ("inappropriate argument for pragma%", Assoc);
4749 and then Warn_On_Redundant_Constructs
4750 and then not Suppress_All_Inlining
4752 if Inlining_Not_Possible (Subp) then
4754 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4757 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4765 ----------------------------
4766 -- Process_Interface_Name --
4767 ----------------------------
4769 procedure Process_Interface_Name
4770 (Subprogram_Def : Entity_Id;
4776 String_Val : String_Id;
4778 procedure Check_Form_Of_Interface_Name
4780 Ext_Name_Case : Boolean);
4781 -- SN is a string literal node for an interface name. This routine
4782 -- performs some minimal checks that the name is reasonable. In
4783 -- particular that no spaces or other obviously incorrect characters
4784 -- appear. This is only a warning, since any characters are allowed.
4785 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4787 ----------------------------------
4788 -- Check_Form_Of_Interface_Name --
4789 ----------------------------------
4791 procedure Check_Form_Of_Interface_Name
4793 Ext_Name_Case : Boolean)
4795 S : constant String_Id := Strval (Expr_Value_S (SN));
4796 SL : constant Nat := String_Length (S);
4801 Error_Msg_N ("interface name cannot be null string", SN);
4804 for J in 1 .. SL loop
4805 C := Get_String_Char (S, J);
4807 -- Look for dubious character and issue unconditional warning.
4808 -- Definitely dubious if not in character range.
4810 if not In_Character_Range (C)
4812 -- For all cases except CLI target,
4813 -- commas, spaces and slashes are dubious (in CLI, we use
4814 -- commas and backslashes in external names to specify
4815 -- assembly version and public key, while slashes and spaces
4816 -- can be used in names to mark nested classes and
4819 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4820 and then (Get_Character (C) = ','
4822 Get_Character (C) = '\'))
4823 or else (VM_Target /= CLI_Target
4824 and then (Get_Character (C) = ' '
4826 Get_Character (C) = '/'))
4829 ("?interface name contains illegal character",
4830 Sloc (SN) + Source_Ptr (J));
4833 end Check_Form_Of_Interface_Name;
4835 -- Start of processing for Process_Interface_Name
4838 if No (Link_Arg) then
4839 if No (Ext_Arg) then
4840 if VM_Target = CLI_Target
4841 and then Ekind (Subprogram_Def) = E_Package
4842 and then Nkind (Parent (Subprogram_Def)) =
4843 N_Package_Specification
4844 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4849 (Generic_Parent (Parent (Subprogram_Def))));
4854 elsif Chars (Ext_Arg) = Name_Link_Name then
4856 Link_Nam := Expression (Ext_Arg);
4859 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4860 Ext_Nam := Expression (Ext_Arg);
4865 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4866 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4867 Ext_Nam := Expression (Ext_Arg);
4868 Link_Nam := Expression (Link_Arg);
4871 -- Check expressions for external name and link name are static
4873 if Present (Ext_Nam) then
4874 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4875 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4877 -- Verify that external name is not the name of a local entity,
4878 -- which would hide the imported one and could lead to run-time
4879 -- surprises. The problem can only arise for entities declared in
4880 -- a package body (otherwise the external name is fully qualified
4881 -- and will not conflict).
4889 if Prag_Id = Pragma_Import then
4890 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4892 E := Entity_Id (Get_Name_Table_Info (Nam));
4894 if Nam /= Chars (Subprogram_Def)
4895 and then Present (E)
4896 and then not Is_Overloadable (E)
4897 and then Is_Immediately_Visible (E)
4898 and then not Is_Imported (E)
4899 and then Ekind (Scope (E)) = E_Package
4902 while Present (Par) loop
4903 if Nkind (Par) = N_Package_Body then
4904 Error_Msg_Sloc := Sloc (E);
4906 ("imported entity is hidden by & declared#",
4911 Par := Parent (Par);
4918 if Present (Link_Nam) then
4919 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4920 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4923 -- If there is no link name, just set the external name
4925 if No (Link_Nam) then
4926 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4928 -- For the Link_Name case, the given literal is preceded by an
4929 -- asterisk, which indicates to GCC that the given name should be
4930 -- taken literally, and in particular that no prepending of
4931 -- underlines should occur, even in systems where this is the
4937 if VM_Target = No_VM then
4938 Store_String_Char (Get_Char_Code ('*'));
4941 String_Val := Strval (Expr_Value_S (Link_Nam));
4942 Store_String_Chars (String_Val);
4944 Make_String_Literal (Sloc (Link_Nam),
4945 Strval => End_String);
4948 -- Set the interface name. If the entity is a generic instance, use
4949 -- its alias, which is the callable entity.
4951 if Is_Generic_Instance (Subprogram_Def) then
4952 Set_Encoded_Interface_Name
4953 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
4955 Set_Encoded_Interface_Name
4956 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4959 -- We allow duplicated export names in CIL/Java, as they are always
4960 -- enclosed in a namespace that differentiates them, and overloaded
4961 -- entities are supported by the VM.
4963 if Convention (Subprogram_Def) /= Convention_CIL
4965 Convention (Subprogram_Def) /= Convention_Java
4967 Check_Duplicated_Export_Name (Link_Nam);
4969 end Process_Interface_Name;
4971 -----------------------------------------
4972 -- Process_Interrupt_Or_Attach_Handler --
4973 -----------------------------------------
4975 procedure Process_Interrupt_Or_Attach_Handler is
4976 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4977 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4978 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4981 Set_Is_Interrupt_Handler (Handler_Proc);
4983 -- If the pragma is not associated with a handler procedure within a
4984 -- protected type, then it must be for a nonprotected procedure for
4985 -- the AAMP target, in which case we don't associate a representation
4986 -- item with the procedure's scope.
4988 if Ekind (Proc_Scope) = E_Protected_Type then
4989 if Prag_Id = Pragma_Interrupt_Handler
4991 Prag_Id = Pragma_Attach_Handler
4993 Record_Rep_Item (Proc_Scope, N);
4996 end Process_Interrupt_Or_Attach_Handler;
4998 --------------------------------------------------
4999 -- Process_Restrictions_Or_Restriction_Warnings --
5000 --------------------------------------------------
5002 -- Note: some of the simple identifier cases were handled in par-prag,
5003 -- but it is harmless (and more straightforward) to simply handle all
5004 -- cases here, even if it means we repeat a bit of work in some cases.
5006 procedure Process_Restrictions_Or_Restriction_Warnings
5010 R_Id : Restriction_Id;
5015 procedure Check_Unit_Name (N : Node_Id);
5016 -- Checks unit name parameter for No_Dependence. Returns if it has
5017 -- an appropriate form, otherwise raises pragma argument error.
5019 ---------------------
5020 -- Check_Unit_Name --
5021 ---------------------
5023 procedure Check_Unit_Name (N : Node_Id) is
5025 if Nkind (N) = N_Selected_Component then
5026 Check_Unit_Name (Prefix (N));
5027 Check_Unit_Name (Selector_Name (N));
5029 elsif Nkind (N) = N_Identifier then
5034 ("wrong form for unit name for No_Dependence", N);
5036 end Check_Unit_Name;
5038 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
5041 -- Ignore all Restrictions pragma in CodePeer mode
5043 if CodePeer_Mode then
5047 Check_Ada_83_Warning;
5048 Check_At_Least_N_Arguments (1);
5049 Check_Valid_Configuration_Pragma;
5052 while Present (Arg) loop
5054 Expr := Get_Pragma_Arg (Arg);
5056 -- Case of no restriction identifier present
5058 if Id = No_Name then
5059 if Nkind (Expr) /= N_Identifier then
5061 ("invalid form for restriction", Arg);
5066 (Process_Restriction_Synonyms (Expr));
5068 if R_Id not in All_Boolean_Restrictions then
5069 Error_Msg_Name_1 := Pname;
5071 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5073 -- Check for possible misspelling
5075 for J in Restriction_Id loop
5077 Rnm : constant String := Restriction_Id'Image (J);
5080 Name_Buffer (1 .. Rnm'Length) := Rnm;
5081 Name_Len := Rnm'Length;
5082 Set_Casing (All_Lower_Case);
5084 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5086 (Identifier_Casing (Current_Source_File));
5087 Error_Msg_String (1 .. Rnm'Length) :=
5088 Name_Buffer (1 .. Name_Len);
5089 Error_Msg_Strlen := Rnm'Length;
5090 Error_Msg_N -- CODEFIX
5091 ("\possible misspelling of ""~""",
5092 Get_Pragma_Arg (Arg));
5101 if Implementation_Restriction (R_Id) then
5102 Check_Restriction (No_Implementation_Restrictions, Arg);
5105 -- If this is a warning, then set the warning unless we already
5106 -- have a real restriction active (we never want a warning to
5107 -- override a real restriction).
5110 if not Restriction_Active (R_Id) then
5111 Set_Restriction (R_Id, N);
5112 Restriction_Warnings (R_Id) := True;
5115 -- If real restriction case, then set it and make sure that the
5116 -- restriction warning flag is off, since a real restriction
5117 -- always overrides a warning.
5120 Set_Restriction (R_Id, N);
5121 Restriction_Warnings (R_Id) := False;
5124 -- Check for obsolescent restrictions in Ada 2005 mode
5127 and then Ada_Version >= Ada_2005
5128 and then (R_Id = No_Asynchronous_Control
5130 R_Id = No_Unchecked_Deallocation
5132 R_Id = No_Unchecked_Conversion)
5134 Check_Restriction (No_Obsolescent_Features, N);
5137 -- A very special case that must be processed here: pragma
5138 -- Restrictions (No_Exceptions) turns off all run-time
5139 -- checking. This is a bit dubious in terms of the formal
5140 -- language definition, but it is what is intended by RM
5141 -- H.4(12). Restriction_Warnings never affects generated code
5142 -- so this is done only in the real restriction case.
5144 if R_Id = No_Exceptions and then not Warn then
5145 Scope_Suppress := (others => True);
5148 -- Case of No_Dependence => unit-name. Note that the parser
5149 -- already made the necessary entry in the No_Dependence table.
5151 elsif Id = Name_No_Dependence then
5152 Check_Unit_Name (Expr);
5154 -- All other cases of restriction identifier present
5157 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5158 Analyze_And_Resolve (Expr, Any_Integer);
5160 if R_Id not in All_Parameter_Restrictions then
5162 ("invalid restriction parameter identifier", Arg);
5164 elsif not Is_OK_Static_Expression (Expr) then
5165 Flag_Non_Static_Expr
5166 ("value must be static expression!", Expr);
5169 elsif not Is_Integer_Type (Etype (Expr))
5170 or else Expr_Value (Expr) < 0
5173 ("value must be non-negative integer", Arg);
5176 -- Restriction pragma is active
5178 Val := Expr_Value (Expr);
5180 if not UI_Is_In_Int_Range (Val) then
5182 ("pragma ignored, value too large?", Arg);
5185 -- Warning case. If the real restriction is active, then we
5186 -- ignore the request, since warning never overrides a real
5187 -- restriction. Otherwise we set the proper warning. Note that
5188 -- this circuit sets the warning again if it is already set,
5189 -- which is what we want, since the constant may have changed.
5192 if not Restriction_Active (R_Id) then
5194 (R_Id, N, Integer (UI_To_Int (Val)));
5195 Restriction_Warnings (R_Id) := True;
5198 -- Real restriction case, set restriction and make sure warning
5199 -- flag is off since real restriction always overrides warning.
5202 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5203 Restriction_Warnings (R_Id) := False;
5209 end Process_Restrictions_Or_Restriction_Warnings;
5211 ---------------------------------
5212 -- Process_Suppress_Unsuppress --
5213 ---------------------------------
5215 -- Note: this procedure makes entries in the check suppress data
5216 -- structures managed by Sem. See spec of package Sem for full
5217 -- details on how we handle recording of check suppression.
5219 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5224 In_Package_Spec : constant Boolean :=
5225 Is_Package_Or_Generic_Package (Current_Scope)
5226 and then not In_Package_Body (Current_Scope);
5228 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5229 -- Used to suppress a single check on the given entity
5231 --------------------------------
5232 -- Suppress_Unsuppress_Echeck --
5233 --------------------------------
5235 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5237 Set_Checks_May_Be_Suppressed (E);
5239 if In_Package_Spec then
5240 Push_Global_Suppress_Stack_Entry
5243 Suppress => Suppress_Case);
5246 Push_Local_Suppress_Stack_Entry
5249 Suppress => Suppress_Case);
5252 -- If this is a first subtype, and the base type is distinct,
5253 -- then also set the suppress flags on the base type.
5255 if Is_First_Subtype (E)
5256 and then Etype (E) /= E
5258 Suppress_Unsuppress_Echeck (Etype (E), C);
5260 end Suppress_Unsuppress_Echeck;
5262 -- Start of processing for Process_Suppress_Unsuppress
5265 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
5266 -- we want to generate checks for analysis purposes, as set by -gnatC
5268 if CodePeer_Mode and then Comes_From_Source (N) then
5272 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5273 -- declarative part or a package spec (RM 11.5(5)).
5275 if not Is_Configuration_Pragma then
5276 Check_Is_In_Decl_Part_Or_Package_Spec;
5279 Check_At_Least_N_Arguments (1);
5280 Check_At_Most_N_Arguments (2);
5281 Check_No_Identifier (Arg1);
5282 Check_Arg_Is_Identifier (Arg1);
5284 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5286 if C = No_Check_Id then
5288 ("argument of pragma% is not valid check name", Arg1);
5291 if not Suppress_Case
5292 and then (C = All_Checks or else C = Overflow_Check)
5294 Opt.Overflow_Checks_Unsuppressed := True;
5297 if Arg_Count = 1 then
5299 -- Make an entry in the local scope suppress table. This is the
5300 -- table that directly shows the current value of the scope
5301 -- suppress check for any check id value.
5303 if C = All_Checks then
5305 -- For All_Checks, we set all specific predefined checks with
5306 -- the exception of Elaboration_Check, which is handled
5307 -- specially because of not wanting All_Checks to have the
5308 -- effect of deactivating static elaboration order processing.
5310 for J in Scope_Suppress'Range loop
5311 if J /= Elaboration_Check then
5312 Scope_Suppress (J) := Suppress_Case;
5316 -- If not All_Checks, and predefined check, then set appropriate
5317 -- scope entry. Note that we will set Elaboration_Check if this
5318 -- is explicitly specified.
5320 elsif C in Predefined_Check_Id then
5321 Scope_Suppress (C) := Suppress_Case;
5324 -- Also make an entry in the Local_Entity_Suppress table
5326 Push_Local_Suppress_Stack_Entry
5329 Suppress => Suppress_Case);
5331 -- Case of two arguments present, where the check is suppressed for
5332 -- a specified entity (given as the second argument of the pragma)
5335 -- This is obsolescent in Ada 2005 mode
5337 if Ada_Version >= Ada_2005 then
5338 Check_Restriction (No_Obsolescent_Features, Arg2);
5341 Check_Optional_Identifier (Arg2, Name_On);
5342 E_Id := Get_Pragma_Arg (Arg2);
5345 if not Is_Entity_Name (E_Id) then
5347 ("second argument of pragma% must be entity name", Arg2);
5356 -- Enforce RM 11.5(7) which requires that for a pragma that
5357 -- appears within a package spec, the named entity must be
5358 -- within the package spec. We allow the package name itself
5359 -- to be mentioned since that makes sense, although it is not
5360 -- strictly allowed by 11.5(7).
5363 and then E /= Current_Scope
5364 and then Scope (E) /= Current_Scope
5367 ("entity in pragma% is not in package spec (RM 11.5(7))",
5371 -- Loop through homonyms. As noted below, in the case of a package
5372 -- spec, only homonyms within the package spec are considered.
5375 Suppress_Unsuppress_Echeck (E, C);
5377 if Is_Generic_Instance (E)
5378 and then Is_Subprogram (E)
5379 and then Present (Alias (E))
5381 Suppress_Unsuppress_Echeck (Alias (E), C);
5384 -- Move to next homonym if not aspect spec case
5386 exit when From_Aspect_Specification (N);
5390 -- If we are within a package specification, the pragma only
5391 -- applies to homonyms in the same scope.
5393 exit when In_Package_Spec
5394 and then Scope (E) /= Current_Scope;
5397 end Process_Suppress_Unsuppress;
5403 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5405 if Is_Imported (E) then
5407 ("cannot export entity& that was previously imported", Arg);
5409 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5411 ("cannot export entity& that has an address clause", Arg);
5414 Set_Is_Exported (E);
5416 -- Generate a reference for entity explicitly, because the
5417 -- identifier may be overloaded and name resolution will not
5420 Generate_Reference (E, Arg);
5422 -- Deal with exporting non-library level entity
5424 if not Is_Library_Level_Entity (E) then
5426 -- Not allowed at all for subprograms
5428 if Is_Subprogram (E) then
5429 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5431 -- Otherwise set public and statically allocated
5435 Set_Is_Statically_Allocated (E);
5437 -- Warn if the corresponding W flag is set and the pragma comes
5438 -- from source. The latter may not be true e.g. on VMS where we
5439 -- expand export pragmas for exception codes associated with
5440 -- imported or exported exceptions. We do not want to generate
5441 -- a warning for something that the user did not write.
5443 if Warn_On_Export_Import
5444 and then Comes_From_Source (Arg)
5447 ("?& has been made static as a result of Export", Arg, E);
5449 ("\this usage is non-standard and non-portable", Arg);
5454 if Warn_On_Export_Import and then Is_Type (E) then
5455 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5458 if Warn_On_Export_Import and Inside_A_Generic then
5460 ("all instances of& will have the same external name?", Arg, E);
5464 ----------------------------------------------
5465 -- Set_Extended_Import_Export_External_Name --
5466 ----------------------------------------------
5468 procedure Set_Extended_Import_Export_External_Name
5469 (Internal_Ent : Entity_Id;
5470 Arg_External : Node_Id)
5472 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5476 if No (Arg_External) then
5480 Check_Arg_Is_External_Name (Arg_External);
5482 if Nkind (Arg_External) = N_String_Literal then
5483 if String_Length (Strval (Arg_External)) = 0 then
5486 New_Name := Adjust_External_Name_Case (Arg_External);
5489 elsif Nkind (Arg_External) = N_Identifier then
5490 New_Name := Get_Default_External_Name (Arg_External);
5492 -- Check_Arg_Is_External_Name should let through only identifiers and
5493 -- string literals or static string expressions (which are folded to
5494 -- string literals).
5497 raise Program_Error;
5500 -- If we already have an external name set (by a prior normal Import
5501 -- or Export pragma), then the external names must match
5503 if Present (Interface_Name (Internal_Ent)) then
5504 Check_Matching_Internal_Names : declare
5505 S1 : constant String_Id := Strval (Old_Name);
5506 S2 : constant String_Id := Strval (New_Name);
5509 -- Called if names do not match
5515 procedure Mismatch is
5517 Error_Msg_Sloc := Sloc (Old_Name);
5519 ("external name does not match that given #",
5523 -- Start of processing for Check_Matching_Internal_Names
5526 if String_Length (S1) /= String_Length (S2) then
5530 for J in 1 .. String_Length (S1) loop
5531 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5536 end Check_Matching_Internal_Names;
5538 -- Otherwise set the given name
5541 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5542 Check_Duplicated_Export_Name (New_Name);
5544 end Set_Extended_Import_Export_External_Name;
5550 procedure Set_Imported (E : Entity_Id) is
5552 -- Error message if already imported or exported
5554 if Is_Exported (E) or else Is_Imported (E) then
5556 -- Error if being set Exported twice
5558 if Is_Exported (E) then
5559 Error_Msg_NE ("entity& was previously exported", N, E);
5561 -- OK if Import/Interface case
5563 elsif Import_Interface_Present (N) then
5566 -- Error if being set Imported twice
5569 Error_Msg_NE ("entity& was previously imported", N, E);
5572 Error_Msg_Name_1 := Pname;
5574 ("\(pragma% applies to all previous entities)", N);
5576 Error_Msg_Sloc := Sloc (E);
5577 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5579 -- Here if not previously imported or exported, OK to import
5582 Set_Is_Imported (E);
5584 -- If the entity is an object that is not at the library level,
5585 -- then it is statically allocated. We do not worry about objects
5586 -- with address clauses in this context since they are not really
5587 -- imported in the linker sense.
5590 and then not Is_Library_Level_Entity (E)
5591 and then No (Address_Clause (E))
5593 Set_Is_Statically_Allocated (E);
5600 -------------------------
5601 -- Set_Mechanism_Value --
5602 -------------------------
5604 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5605 -- analyzed, since it is semantic nonsense), so we get it in the exact
5606 -- form created by the parser.
5608 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5611 Mech_Name_Id : Name_Id;
5613 procedure Bad_Class;
5614 -- Signal bad descriptor class name
5616 procedure Bad_Mechanism;
5617 -- Signal bad mechanism name
5623 procedure Bad_Class is
5625 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5628 -------------------------
5629 -- Bad_Mechanism_Value --
5630 -------------------------
5632 procedure Bad_Mechanism is
5634 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5637 -- Start of processing for Set_Mechanism_Value
5640 if Mechanism (Ent) /= Default_Mechanism then
5642 ("mechanism for & has already been set", Mech_Name, Ent);
5645 -- MECHANISM_NAME ::= value | reference | descriptor |
5648 if Nkind (Mech_Name) = N_Identifier then
5649 if Chars (Mech_Name) = Name_Value then
5650 Set_Mechanism (Ent, By_Copy);
5653 elsif Chars (Mech_Name) = Name_Reference then
5654 Set_Mechanism (Ent, By_Reference);
5657 elsif Chars (Mech_Name) = Name_Descriptor then
5658 Check_VMS (Mech_Name);
5660 -- Descriptor => Short_Descriptor if pragma was given
5662 if Short_Descriptors then
5663 Set_Mechanism (Ent, By_Short_Descriptor);
5665 Set_Mechanism (Ent, By_Descriptor);
5670 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5671 Check_VMS (Mech_Name);
5672 Set_Mechanism (Ent, By_Short_Descriptor);
5675 elsif Chars (Mech_Name) = Name_Copy then
5677 ("bad mechanism name, Value assumed", Mech_Name);
5683 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5684 -- short_descriptor (CLASS_NAME)
5685 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5687 -- Note: this form is parsed as an indexed component
5689 elsif Nkind (Mech_Name) = N_Indexed_Component then
5690 Class := First (Expressions (Mech_Name));
5692 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5693 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5694 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5695 or else Present (Next (Class))
5699 Mech_Name_Id := Chars (Prefix (Mech_Name));
5701 -- Change Descriptor => Short_Descriptor if pragma was given
5703 if Mech_Name_Id = Name_Descriptor
5704 and then Short_Descriptors
5706 Mech_Name_Id := Name_Short_Descriptor;
5710 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5711 -- short_descriptor (Class => CLASS_NAME)
5712 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5714 -- Note: this form is parsed as a function call
5716 elsif Nkind (Mech_Name) = N_Function_Call then
5717 Param := First (Parameter_Associations (Mech_Name));
5719 if Nkind (Name (Mech_Name)) /= N_Identifier
5720 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5721 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5722 or else Present (Next (Param))
5723 or else No (Selector_Name (Param))
5724 or else Chars (Selector_Name (Param)) /= Name_Class
5728 Class := Explicit_Actual_Parameter (Param);
5729 Mech_Name_Id := Chars (Name (Mech_Name));
5736 -- Fall through here with Class set to descriptor class name
5738 Check_VMS (Mech_Name);
5740 if Nkind (Class) /= N_Identifier then
5743 elsif Mech_Name_Id = Name_Descriptor
5744 and then Chars (Class) = Name_UBS
5746 Set_Mechanism (Ent, By_Descriptor_UBS);
5748 elsif Mech_Name_Id = Name_Descriptor
5749 and then Chars (Class) = Name_UBSB
5751 Set_Mechanism (Ent, By_Descriptor_UBSB);
5753 elsif Mech_Name_Id = Name_Descriptor
5754 and then Chars (Class) = Name_UBA
5756 Set_Mechanism (Ent, By_Descriptor_UBA);
5758 elsif Mech_Name_Id = Name_Descriptor
5759 and then Chars (Class) = Name_S
5761 Set_Mechanism (Ent, By_Descriptor_S);
5763 elsif Mech_Name_Id = Name_Descriptor
5764 and then Chars (Class) = Name_SB
5766 Set_Mechanism (Ent, By_Descriptor_SB);
5768 elsif Mech_Name_Id = Name_Descriptor
5769 and then Chars (Class) = Name_A
5771 Set_Mechanism (Ent, By_Descriptor_A);
5773 elsif Mech_Name_Id = Name_Descriptor
5774 and then Chars (Class) = Name_NCA
5776 Set_Mechanism (Ent, By_Descriptor_NCA);
5778 elsif Mech_Name_Id = Name_Short_Descriptor
5779 and then Chars (Class) = Name_UBS
5781 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5783 elsif Mech_Name_Id = Name_Short_Descriptor
5784 and then Chars (Class) = Name_UBSB
5786 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5788 elsif Mech_Name_Id = Name_Short_Descriptor
5789 and then Chars (Class) = Name_UBA
5791 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5793 elsif Mech_Name_Id = Name_Short_Descriptor
5794 and then Chars (Class) = Name_S
5796 Set_Mechanism (Ent, By_Short_Descriptor_S);
5798 elsif Mech_Name_Id = Name_Short_Descriptor
5799 and then Chars (Class) = Name_SB
5801 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5803 elsif Mech_Name_Id = Name_Short_Descriptor
5804 and then Chars (Class) = Name_A
5806 Set_Mechanism (Ent, By_Short_Descriptor_A);
5808 elsif Mech_Name_Id = Name_Short_Descriptor
5809 and then Chars (Class) = Name_NCA
5811 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5816 end Set_Mechanism_Value;
5818 ---------------------------
5819 -- Set_Ravenscar_Profile --
5820 ---------------------------
5822 -- The tasks to be done here are
5824 -- Set required policies
5826 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5827 -- pragma Locking_Policy (Ceiling_Locking)
5829 -- Set Detect_Blocking mode
5831 -- Set required restrictions (see System.Rident for detailed list)
5833 -- Set the No_Dependence rules
5834 -- No_Dependence => Ada.Asynchronous_Task_Control
5835 -- No_Dependence => Ada.Calendar
5836 -- No_Dependence => Ada.Execution_Time.Group_Budget
5837 -- No_Dependence => Ada.Execution_Time.Timers
5838 -- No_Dependence => Ada.Task_Attributes
5839 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5841 procedure Set_Ravenscar_Profile (N : Node_Id) is
5842 Prefix_Entity : Entity_Id;
5843 Selector_Entity : Entity_Id;
5844 Prefix_Node : Node_Id;
5848 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5850 if Task_Dispatching_Policy /= ' '
5851 and then Task_Dispatching_Policy /= 'F'
5853 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5854 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5856 -- Set the FIFO_Within_Priorities policy, but always preserve
5857 -- System_Location since we like the error message with the run time
5861 Task_Dispatching_Policy := 'F';
5863 if Task_Dispatching_Policy_Sloc /= System_Location then
5864 Task_Dispatching_Policy_Sloc := Loc;
5868 -- pragma Locking_Policy (Ceiling_Locking)
5870 if Locking_Policy /= ' '
5871 and then Locking_Policy /= 'C'
5873 Error_Msg_Sloc := Locking_Policy_Sloc;
5874 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5876 -- Set the Ceiling_Locking policy, but preserve System_Location since
5877 -- we like the error message with the run time name.
5880 Locking_Policy := 'C';
5882 if Locking_Policy_Sloc /= System_Location then
5883 Locking_Policy_Sloc := Loc;
5887 -- pragma Detect_Blocking
5889 Detect_Blocking := True;
5891 -- Set the corresponding restrictions
5893 Set_Profile_Restrictions
5894 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5896 -- Set the No_Dependence restrictions
5898 -- The following No_Dependence restrictions:
5899 -- No_Dependence => Ada.Asynchronous_Task_Control
5900 -- No_Dependence => Ada.Calendar
5901 -- No_Dependence => Ada.Task_Attributes
5902 -- are already set by previous call to Set_Profile_Restrictions.
5904 -- Set the following restrictions which were added to Ada 2005:
5905 -- No_Dependence => Ada.Execution_Time.Group_Budget
5906 -- No_Dependence => Ada.Execution_Time.Timers
5908 if Ada_Version >= Ada_2005 then
5909 Name_Buffer (1 .. 3) := "ada";
5912 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5914 Name_Buffer (1 .. 14) := "execution_time";
5917 Selector_Entity := Make_Identifier (Loc, Name_Find);
5920 Make_Selected_Component
5922 Prefix => Prefix_Entity,
5923 Selector_Name => Selector_Entity);
5925 Name_Buffer (1 .. 13) := "group_budgets";
5928 Selector_Entity := Make_Identifier (Loc, Name_Find);
5931 Make_Selected_Component
5933 Prefix => Prefix_Node,
5934 Selector_Name => Selector_Entity);
5936 Set_Restriction_No_Dependence
5938 Warn => Treat_Restrictions_As_Warnings,
5939 Profile => Ravenscar);
5941 Name_Buffer (1 .. 6) := "timers";
5944 Selector_Entity := Make_Identifier (Loc, Name_Find);
5947 Make_Selected_Component
5949 Prefix => Prefix_Node,
5950 Selector_Name => Selector_Entity);
5952 Set_Restriction_No_Dependence
5954 Warn => Treat_Restrictions_As_Warnings,
5955 Profile => Ravenscar);
5958 -- Set the following restrictions which was added to Ada 2012 (see
5960 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5962 if Ada_Version >= Ada_2012 then
5963 Name_Buffer (1 .. 6) := "system";
5966 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5968 Name_Buffer (1 .. 15) := "multiprocessors";
5971 Selector_Entity := Make_Identifier (Loc, Name_Find);
5974 Make_Selected_Component
5976 Prefix => Prefix_Entity,
5977 Selector_Name => Selector_Entity);
5979 Name_Buffer (1 .. 19) := "dispatching_domains";
5982 Selector_Entity := Make_Identifier (Loc, Name_Find);
5985 Make_Selected_Component
5987 Prefix => Prefix_Node,
5988 Selector_Name => Selector_Entity);
5990 Set_Restriction_No_Dependence
5992 Warn => Treat_Restrictions_As_Warnings,
5993 Profile => Ravenscar);
5995 end Set_Ravenscar_Profile;
5997 -- Start of processing for Analyze_Pragma
6000 -- The following code is a defense against recursion. Not clear that
6001 -- this can happen legitimately, but perhaps some error situations
6002 -- can cause it, and we did see this recursion during testing.
6004 if Analyzed (N) then
6007 Set_Analyzed (N, True);
6010 -- Deal with unrecognized pragma
6012 if not Is_Pragma_Name (Pname) then
6013 if Warn_On_Unrecognized_Pragma then
6014 Error_Msg_Name_1 := Pname;
6015 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6017 for PN in First_Pragma_Name .. Last_Pragma_Name loop
6018 if Is_Bad_Spelling_Of (Pname, PN) then
6019 Error_Msg_Name_1 := PN;
6020 Error_Msg_N -- CODEFIX
6021 ("\?possible misspelling of %!", Pragma_Identifier (N));
6030 -- Here to start processing for recognized pragma
6032 Prag_Id := Get_Pragma_Id (Pname);
6042 if Present (Pragma_Argument_Associations (N)) then
6043 Arg_Count := List_Length (Pragma_Argument_Associations (N));
6044 Arg1 := First (Pragma_Argument_Associations (N));
6046 if Present (Arg1) then
6047 Arg2 := Next (Arg1);
6049 if Present (Arg2) then
6050 Arg3 := Next (Arg2);
6052 if Present (Arg3) then
6053 Arg4 := Next (Arg3);
6059 -- An enumeration type defines the pragmas that are supported by the
6060 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
6061 -- into the corresponding enumeration value for the following case.
6069 -- pragma Abort_Defer;
6071 when Pragma_Abort_Defer =>
6073 Check_Arg_Count (0);
6075 -- The only required semantic processing is to check the
6076 -- placement. This pragma must appear at the start of the
6077 -- statement sequence of a handled sequence of statements.
6079 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6080 or else N /= First (Statements (Parent (N)))
6091 -- Note: this pragma also has some specific processing in Par.Prag
6092 -- because we want to set the Ada version mode during parsing.
6094 when Pragma_Ada_83 =>
6096 Check_Arg_Count (0);
6098 -- We really should check unconditionally for proper configuration
6099 -- pragma placement, since we really don't want mixed Ada modes
6100 -- within a single unit, and the GNAT reference manual has always
6101 -- said this was a configuration pragma, but we did not check and
6102 -- are hesitant to add the check now.
6104 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6105 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6106 -- or Ada 2012 mode.
6108 if Ada_Version >= Ada_2005 then
6109 Check_Valid_Configuration_Pragma;
6112 -- Now set Ada 83 mode
6114 Ada_Version := Ada_83;
6115 Ada_Version_Explicit := Ada_Version;
6123 -- Note: this pragma also has some specific processing in Par.Prag
6124 -- because we want to set the Ada 83 version mode during parsing.
6126 when Pragma_Ada_95 =>
6128 Check_Arg_Count (0);
6130 -- We really should check unconditionally for proper configuration
6131 -- pragma placement, since we really don't want mixed Ada modes
6132 -- within a single unit, and the GNAT reference manual has always
6133 -- said this was a configuration pragma, but we did not check and
6134 -- are hesitant to add the check now.
6136 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
6137 -- or Ada 95, so we must check if we are in Ada 2005 mode.
6139 if Ada_Version >= Ada_2005 then
6140 Check_Valid_Configuration_Pragma;
6143 -- Now set Ada 95 mode
6145 Ada_Version := Ada_95;
6146 Ada_Version_Explicit := Ada_Version;
6148 ---------------------
6149 -- Ada_05/Ada_2005 --
6150 ---------------------
6153 -- pragma Ada_05 (LOCAL_NAME);
6156 -- pragma Ada_2005 (LOCAL_NAME):
6158 -- Note: these pragmas also have some specific processing in Par.Prag
6159 -- because we want to set the Ada 2005 version mode during parsing.
6161 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6167 if Arg_Count = 1 then
6168 Check_Arg_Is_Local_Name (Arg1);
6169 E_Id := Get_Pragma_Arg (Arg1);
6171 if Etype (E_Id) = Any_Type then
6175 Set_Is_Ada_2005_Only (Entity (E_Id));
6178 Check_Arg_Count (0);
6180 -- For Ada_2005 we unconditionally enforce the documented
6181 -- configuration pragma placement, since we do not want to
6182 -- tolerate mixed modes in a unit involving Ada 2005. That
6183 -- would cause real difficulties for those cases where there
6184 -- are incompatibilities between Ada 95 and Ada 2005.
6186 Check_Valid_Configuration_Pragma;
6188 -- Now set appropriate Ada mode
6190 Ada_Version := Ada_2005;
6191 Ada_Version_Explicit := Ada_2005;
6195 ---------------------
6196 -- Ada_12/Ada_2012 --
6197 ---------------------
6200 -- pragma Ada_12 (LOCAL_NAME);
6203 -- pragma Ada_2012 (LOCAL_NAME):
6205 -- Note: these pragmas also have some specific processing in Par.Prag
6206 -- because we want to set the Ada 2012 version mode during parsing.
6208 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6214 if Arg_Count = 1 then
6215 Check_Arg_Is_Local_Name (Arg1);
6216 E_Id := Get_Pragma_Arg (Arg1);
6218 if Etype (E_Id) = Any_Type then
6222 Set_Is_Ada_2012_Only (Entity (E_Id));
6225 Check_Arg_Count (0);
6227 -- For Ada_2012 we unconditionally enforce the documented
6228 -- configuration pragma placement, since we do not want to
6229 -- tolerate mixed modes in a unit involving Ada 2012. That
6230 -- would cause real difficulties for those cases where there
6231 -- are incompatibilities between Ada 95 and Ada 2012. We could
6232 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6234 Check_Valid_Configuration_Pragma;
6236 -- Now set appropriate Ada mode
6238 Ada_Version := Ada_2012;
6239 Ada_Version_Explicit := Ada_2012;
6243 ----------------------
6244 -- All_Calls_Remote --
6245 ----------------------
6247 -- pragma All_Calls_Remote [(library_package_NAME)];
6249 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6250 Lib_Entity : Entity_Id;
6253 Check_Ada_83_Warning;
6254 Check_Valid_Library_Unit_Pragma;
6256 if Nkind (N) = N_Null_Statement then
6260 Lib_Entity := Find_Lib_Unit_Name;
6262 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6264 if Present (Lib_Entity)
6265 and then not Debug_Flag_U
6267 if not Is_Remote_Call_Interface (Lib_Entity) then
6268 Error_Pragma ("pragma% only apply to rci unit");
6270 -- Set flag for entity of the library unit
6273 Set_Has_All_Calls_Remote (Lib_Entity);
6277 end All_Calls_Remote;
6283 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6284 -- ARG ::= NAME | EXPRESSION
6286 -- The first two arguments are by convention intended to refer to an
6287 -- external tool and a tool-specific function. These arguments are
6290 when Pragma_Annotate => Annotate : declare
6296 Check_At_Least_N_Arguments (1);
6297 Check_Arg_Is_Identifier (Arg1);
6298 Check_No_Identifiers;
6301 -- Second parameter is optional, it is never analyzed
6306 -- Here if we have a second parameter
6309 -- Second parameter must be identifier
6311 Check_Arg_Is_Identifier (Arg2);
6313 -- Process remaining parameters if any
6316 while Present (Arg) loop
6317 Exp := Get_Pragma_Arg (Arg);
6320 if Is_Entity_Name (Exp) then
6323 -- For string literals, we assume Standard_String as the
6324 -- type, unless the string contains wide or wide_wide
6327 elsif Nkind (Exp) = N_String_Literal then
6328 if Has_Wide_Wide_Character (Exp) then
6329 Resolve (Exp, Standard_Wide_Wide_String);
6330 elsif Has_Wide_Character (Exp) then
6331 Resolve (Exp, Standard_Wide_String);
6333 Resolve (Exp, Standard_String);
6336 elsif Is_Overloaded (Exp) then
6338 ("ambiguous argument for pragma%", Exp);
6353 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6354 -- [, [Message =>] Static_String_EXPRESSION]);
6356 when Pragma_Assert => Assert : declare
6362 Check_At_Least_N_Arguments (1);
6363 Check_At_Most_N_Arguments (2);
6364 Check_Arg_Order ((Name_Check, Name_Message));
6365 Check_Optional_Identifier (Arg1, Name_Check);
6367 -- We treat pragma Assert as equivalent to:
6369 -- pragma Check (Assertion, condition [, msg]);
6371 -- So rewrite pragma in this manner, and analyze the result
6373 Expr := Get_Pragma_Arg (Arg1);
6375 Make_Pragma_Argument_Association (Loc,
6376 Expression => Make_Identifier (Loc, Name_Assertion)),
6378 Make_Pragma_Argument_Association (Sloc (Expr),
6379 Expression => Expr));
6381 if Arg_Count > 1 then
6382 Check_Optional_Identifier (Arg2, Name_Message);
6383 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6384 Append_To (Newa, Relocate_Node (Arg2));
6389 Chars => Name_Check,
6390 Pragma_Argument_Associations => Newa));
6394 ----------------------
6395 -- Assertion_Policy --
6396 ----------------------
6398 -- pragma Assertion_Policy (Check | Ignore)
6400 when Pragma_Assertion_Policy => Assertion_Policy : declare
6405 Check_Valid_Configuration_Pragma;
6406 Check_Arg_Count (1);
6407 Check_No_Identifiers;
6408 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6410 -- We treat pragma Assertion_Policy as equivalent to:
6412 -- pragma Check_Policy (Assertion, policy)
6414 -- So rewrite the pragma in that manner and link on to the chain
6415 -- of Check_Policy pragmas, marking the pragma as analyzed.
6417 Policy := Get_Pragma_Arg (Arg1);
6421 Chars => Name_Check_Policy,
6423 Pragma_Argument_Associations => New_List (
6424 Make_Pragma_Argument_Association (Loc,
6425 Expression => Make_Identifier (Loc, Name_Assertion)),
6427 Make_Pragma_Argument_Association (Loc,
6429 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6432 Set_Next_Pragma (N, Opt.Check_Policy_List);
6433 Opt.Check_Policy_List := N;
6434 end Assertion_Policy;
6436 ------------------------------
6437 -- Assume_No_Invalid_Values --
6438 ------------------------------
6440 -- pragma Assume_No_Invalid_Values (On | Off);
6442 when Pragma_Assume_No_Invalid_Values =>
6444 Check_Valid_Configuration_Pragma;
6445 Check_Arg_Count (1);
6446 Check_No_Identifiers;
6447 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6449 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6450 Assume_No_Invalid_Values := True;
6452 Assume_No_Invalid_Values := False;
6459 -- pragma AST_Entry (entry_IDENTIFIER);
6461 when Pragma_AST_Entry => AST_Entry : declare
6467 Check_Arg_Count (1);
6468 Check_No_Identifiers;
6469 Check_Arg_Is_Local_Name (Arg1);
6470 Ent := Entity (Get_Pragma_Arg (Arg1));
6472 -- Note: the implementation of the AST_Entry pragma could handle
6473 -- the entry family case fine, but for now we are consistent with
6474 -- the DEC rules, and do not allow the pragma, which of course
6475 -- has the effect of also forbidding the attribute.
6477 if Ekind (Ent) /= E_Entry then
6479 ("pragma% argument must be simple entry name", Arg1);
6481 elsif Is_AST_Entry (Ent) then
6483 ("duplicate % pragma for entry", Arg1);
6485 elsif Has_Homonym (Ent) then
6487 ("pragma% argument cannot specify overloaded entry", Arg1);
6491 FF : constant Entity_Id := First_Formal (Ent);
6494 if Present (FF) then
6495 if Present (Next_Formal (FF)) then
6497 ("entry for pragma% can have only one argument",
6500 elsif Parameter_Mode (FF) /= E_In_Parameter then
6502 ("entry parameter for pragma% must have mode IN",
6508 Set_Is_AST_Entry (Ent);
6516 -- pragma Asynchronous (LOCAL_NAME);
6518 when Pragma_Asynchronous => Asynchronous : declare
6526 procedure Process_Async_Pragma;
6527 -- Common processing for procedure and access-to-procedure case
6529 --------------------------
6530 -- Process_Async_Pragma --
6531 --------------------------
6533 procedure Process_Async_Pragma is
6536 Set_Is_Asynchronous (Nm);
6540 -- The formals should be of mode IN (RM E.4.1(6))
6543 while Present (S) loop
6544 Formal := Defining_Identifier (S);
6546 if Nkind (Formal) = N_Defining_Identifier
6547 and then Ekind (Formal) /= E_In_Parameter
6550 ("pragma% procedure can only have IN parameter",
6557 Set_Is_Asynchronous (Nm);
6558 end Process_Async_Pragma;
6560 -- Start of processing for pragma Asynchronous
6563 Check_Ada_83_Warning;
6564 Check_No_Identifiers;
6565 Check_Arg_Count (1);
6566 Check_Arg_Is_Local_Name (Arg1);
6568 if Debug_Flag_U then
6572 C_Ent := Cunit_Entity (Current_Sem_Unit);
6573 Analyze (Get_Pragma_Arg (Arg1));
6574 Nm := Entity (Get_Pragma_Arg (Arg1));
6576 if not Is_Remote_Call_Interface (C_Ent)
6577 and then not Is_Remote_Types (C_Ent)
6579 -- This pragma should only appear in an RCI or Remote Types
6580 -- unit (RM E.4.1(4)).
6583 ("pragma% not in Remote_Call_Interface or " &
6584 "Remote_Types unit");
6587 if Ekind (Nm) = E_Procedure
6588 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6590 if not Is_Remote_Call_Interface (Nm) then
6592 ("pragma% cannot be applied on non-remote procedure",
6596 L := Parameter_Specifications (Parent (Nm));
6597 Process_Async_Pragma;
6600 elsif Ekind (Nm) = E_Function then
6602 ("pragma% cannot be applied to function", Arg1);
6604 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6605 if Is_Record_Type (Nm) then
6607 -- A record type that is the Equivalent_Type for a remote
6608 -- access-to-subprogram type.
6610 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6613 -- A non-expanded RAS type (distribution is not enabled)
6615 N := Declaration_Node (Nm);
6618 if Nkind (N) = N_Full_Type_Declaration
6619 and then Nkind (Type_Definition (N)) =
6620 N_Access_Procedure_Definition
6622 L := Parameter_Specifications (Type_Definition (N));
6623 Process_Async_Pragma;
6625 if Is_Asynchronous (Nm)
6626 and then Expander_Active
6627 and then Get_PCS_Name /= Name_No_DSA
6629 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6634 ("pragma% cannot reference access-to-function type",
6638 -- Only other possibility is Access-to-class-wide type
6640 elsif Is_Access_Type (Nm)
6641 and then Is_Class_Wide_Type (Designated_Type (Nm))
6643 Check_First_Subtype (Arg1);
6644 Set_Is_Asynchronous (Nm);
6645 if Expander_Active then
6646 RACW_Type_Is_Asynchronous (Nm);
6650 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6658 -- pragma Atomic (LOCAL_NAME);
6660 when Pragma_Atomic =>
6661 Process_Atomic_Shared_Volatile;
6663 -----------------------
6664 -- Atomic_Components --
6665 -----------------------
6667 -- pragma Atomic_Components (array_LOCAL_NAME);
6669 -- This processing is shared by Volatile_Components
6671 when Pragma_Atomic_Components |
6672 Pragma_Volatile_Components =>
6674 Atomic_Components : declare
6681 Check_Ada_83_Warning;
6682 Check_No_Identifiers;
6683 Check_Arg_Count (1);
6684 Check_Arg_Is_Local_Name (Arg1);
6685 E_Id := Get_Pragma_Arg (Arg1);
6687 if Etype (E_Id) = Any_Type then
6693 Check_Duplicate_Pragma (E);
6695 if Rep_Item_Too_Early (E, N)
6697 Rep_Item_Too_Late (E, N)
6702 D := Declaration_Node (E);
6705 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6707 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6708 and then Nkind (D) = N_Object_Declaration
6709 and then Nkind (Object_Definition (D)) =
6710 N_Constrained_Array_Definition)
6712 -- The flag is set on the object, or on the base type
6714 if Nkind (D) /= N_Object_Declaration then
6718 Set_Has_Volatile_Components (E);
6720 if Prag_Id = Pragma_Atomic_Components then
6721 Set_Has_Atomic_Components (E);
6725 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6727 end Atomic_Components;
6729 --------------------
6730 -- Attach_Handler --
6731 --------------------
6733 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6735 when Pragma_Attach_Handler =>
6736 Check_Ada_83_Warning;
6737 Check_No_Identifiers;
6738 Check_Arg_Count (2);
6740 if No_Run_Time_Mode then
6741 Error_Msg_CRT ("Attach_Handler pragma", N);
6743 Check_Interrupt_Or_Attach_Handler;
6745 -- The expression that designates the attribute may depend on a
6746 -- discriminant, and is therefore a per- object expression, to
6747 -- be expanded in the init proc. If expansion is enabled, then
6748 -- perform semantic checks on a copy only.
6750 if Expander_Active then
6752 Temp : constant Node_Id :=
6753 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6755 Set_Parent (Temp, N);
6756 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6760 Analyze (Get_Pragma_Arg (Arg2));
6761 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6764 Process_Interrupt_Or_Attach_Handler;
6767 --------------------
6768 -- C_Pass_By_Copy --
6769 --------------------
6771 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6773 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6779 Check_Valid_Configuration_Pragma;
6780 Check_Arg_Count (1);
6781 Check_Optional_Identifier (Arg1, "max_size");
6783 Arg := Get_Pragma_Arg (Arg1);
6784 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6786 Val := Expr_Value (Arg);
6790 ("maximum size for pragma% must be positive", Arg1);
6792 elsif UI_Is_In_Int_Range (Val) then
6793 Default_C_Record_Mechanism := UI_To_Int (Val);
6795 -- If a giant value is given, Int'Last will do well enough.
6796 -- If sometime someone complains that a record larger than
6797 -- two gigabytes is not copied, we will worry about it then!
6800 Default_C_Record_Mechanism := Mechanism_Type'Last;
6808 -- pragma Check ([Name =>] Identifier,
6809 -- [Check =>] Boolean_Expression
6810 -- [,[Message =>] String_Expression]);
6812 when Pragma_Check => Check : declare
6817 -- Set True if category of assertions referenced by Name enabled
6821 Check_At_Least_N_Arguments (2);
6822 Check_At_Most_N_Arguments (3);
6823 Check_Optional_Identifier (Arg1, Name_Name);
6824 Check_Optional_Identifier (Arg2, Name_Check);
6826 if Arg_Count = 3 then
6827 Check_Optional_Identifier (Arg3, Name_Message);
6828 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6831 Check_Arg_Is_Identifier (Arg1);
6833 -- Indicate if pragma is enabled. The Original_Node reference here
6834 -- is to deal with pragma Assert rewritten as a Check pragma.
6836 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6839 Set_SCO_Pragma_Enabled (Loc);
6842 -- If expansion is active and the check is not enabled then we
6843 -- rewrite the Check as:
6845 -- if False and then condition then
6849 -- The reason we do this rewriting during semantic analysis rather
6850 -- than as part of normal expansion is that we cannot analyze and
6851 -- expand the code for the boolean expression directly, or it may
6852 -- cause insertion of actions that would escape the attempt to
6853 -- suppress the check code.
6855 -- Note that the Sloc for the if statement corresponds to the
6856 -- argument condition, not the pragma itself. The reason for this
6857 -- is that we may generate a warning if the condition is False at
6858 -- compile time, and we do not want to delete this warning when we
6859 -- delete the if statement.
6861 Expr := Get_Pragma_Arg (Arg2);
6863 if Expander_Active and then not Check_On then
6864 Eloc := Sloc (Expr);
6867 Make_If_Statement (Eloc,
6869 Make_And_Then (Eloc,
6870 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6871 Right_Opnd => Expr),
6872 Then_Statements => New_List (
6873 Make_Null_Statement (Eloc))));
6880 Analyze_And_Resolve (Expr, Any_Boolean);
6888 -- pragma Check_Name (check_IDENTIFIER);
6890 when Pragma_Check_Name =>
6891 Check_No_Identifiers;
6893 Check_Valid_Configuration_Pragma;
6894 Check_Arg_Count (1);
6895 Check_Arg_Is_Identifier (Arg1);
6898 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6901 for J in Check_Names.First .. Check_Names.Last loop
6902 if Check_Names.Table (J) = Nam then
6907 Check_Names.Append (Nam);
6914 -- pragma Check_Policy (
6915 -- [Name =>] IDENTIFIER,
6916 -- [Policy =>] POLICY_IDENTIFIER);
6918 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6920 -- Note: this is a configuration pragma, but it is allowed to appear
6923 when Pragma_Check_Policy =>
6925 Check_Arg_Count (2);
6926 Check_Optional_Identifier (Arg1, Name_Name);
6927 Check_Optional_Identifier (Arg2, Name_Policy);
6929 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6931 -- A Check_Policy pragma can appear either as a configuration
6932 -- pragma, or in a declarative part or a package spec (see RM
6933 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6934 -- followed for Check_Policy).
6936 if not Is_Configuration_Pragma then
6937 Check_Is_In_Decl_Part_Or_Package_Spec;
6940 Set_Next_Pragma (N, Opt.Check_Policy_List);
6941 Opt.Check_Policy_List := N;
6943 ---------------------
6944 -- CIL_Constructor --
6945 ---------------------
6947 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6949 -- Processing for this pragma is shared with Java_Constructor
6955 -- pragma Comment (static_string_EXPRESSION)
6957 -- Processing for pragma Comment shares the circuitry for pragma
6958 -- Ident. The only differences are that Ident enforces a limit of 31
6959 -- characters on its argument, and also enforces limitations on
6960 -- placement for DEC compatibility. Pragma Comment shares neither of
6961 -- these restrictions.
6967 -- pragma Common_Object (
6968 -- [Internal =>] LOCAL_NAME
6969 -- [, [External =>] EXTERNAL_SYMBOL]
6970 -- [, [Size =>] EXTERNAL_SYMBOL]);
6972 -- Processing for this pragma is shared with Psect_Object
6974 ------------------------
6975 -- Compile_Time_Error --
6976 ------------------------
6978 -- pragma Compile_Time_Error
6979 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6981 when Pragma_Compile_Time_Error =>
6983 Process_Compile_Time_Warning_Or_Error;
6985 --------------------------
6986 -- Compile_Time_Warning --
6987 --------------------------
6989 -- pragma Compile_Time_Warning
6990 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6992 when Pragma_Compile_Time_Warning =>
6994 Process_Compile_Time_Warning_Or_Error;
7000 when Pragma_Compiler_Unit =>
7002 Check_Arg_Count (0);
7003 Set_Is_Compiler_Unit (Get_Source_Unit (N));
7005 -----------------------------
7006 -- Complete_Representation --
7007 -----------------------------
7009 -- pragma Complete_Representation;
7011 when Pragma_Complete_Representation =>
7013 Check_Arg_Count (0);
7015 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7017 ("pragma & must appear within record representation clause");
7020 ----------------------------
7021 -- Complex_Representation --
7022 ----------------------------
7024 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7026 when Pragma_Complex_Representation => Complex_Representation : declare
7033 Check_Arg_Count (1);
7034 Check_Optional_Identifier (Arg1, Name_Entity);
7035 Check_Arg_Is_Local_Name (Arg1);
7036 E_Id := Get_Pragma_Arg (Arg1);
7038 if Etype (E_Id) = Any_Type then
7044 if not Is_Record_Type (E) then
7046 ("argument for pragma% must be record type", Arg1);
7049 Ent := First_Entity (E);
7052 or else No (Next_Entity (Ent))
7053 or else Present (Next_Entity (Next_Entity (Ent)))
7054 or else not Is_Floating_Point_Type (Etype (Ent))
7055 or else Etype (Ent) /= Etype (Next_Entity (Ent))
7058 ("record for pragma% must have two fields of the same "
7059 & "floating-point type", Arg1);
7062 Set_Has_Complex_Representation (Base_Type (E));
7064 -- We need to treat the type has having a non-standard
7065 -- representation, for back-end purposes, even though in
7066 -- general a complex will have the default representation
7067 -- of a record with two real components.
7069 Set_Has_Non_Standard_Rep (Base_Type (E));
7071 end Complex_Representation;
7073 -------------------------
7074 -- Component_Alignment --
7075 -------------------------
7077 -- pragma Component_Alignment (
7078 -- [Form =>] ALIGNMENT_CHOICE
7079 -- [, [Name =>] type_LOCAL_NAME]);
7081 -- ALIGNMENT_CHOICE ::=
7083 -- | Component_Size_4
7087 when Pragma_Component_Alignment => Component_AlignmentP : declare
7088 Args : Args_List (1 .. 2);
7089 Names : constant Name_List (1 .. 2) := (
7093 Form : Node_Id renames Args (1);
7094 Name : Node_Id renames Args (2);
7096 Atype : Component_Alignment_Kind;
7101 Gather_Associations (Names, Args);
7104 Error_Pragma ("missing Form argument for pragma%");
7107 Check_Arg_Is_Identifier (Form);
7109 -- Get proper alignment, note that Default = Component_Size on all
7110 -- machines we have so far, and we want to set this value rather
7111 -- than the default value to indicate that it has been explicitly
7112 -- set (and thus will not get overridden by the default component
7113 -- alignment for the current scope)
7115 if Chars (Form) = Name_Component_Size then
7116 Atype := Calign_Component_Size;
7118 elsif Chars (Form) = Name_Component_Size_4 then
7119 Atype := Calign_Component_Size_4;
7121 elsif Chars (Form) = Name_Default then
7122 Atype := Calign_Component_Size;
7124 elsif Chars (Form) = Name_Storage_Unit then
7125 Atype := Calign_Storage_Unit;
7129 ("invalid Form parameter for pragma%", Form);
7132 -- Case with no name, supplied, affects scope table entry
7136 (Scope_Stack.Last).Component_Alignment_Default := Atype;
7138 -- Case of name supplied
7141 Check_Arg_Is_Local_Name (Name);
7143 Typ := Entity (Name);
7146 or else Rep_Item_Too_Early (Typ, N)
7150 Typ := Underlying_Type (Typ);
7153 if not Is_Record_Type (Typ)
7154 and then not Is_Array_Type (Typ)
7157 ("Name parameter of pragma% must identify record or " &
7158 "array type", Name);
7161 -- An explicit Component_Alignment pragma overrides an
7162 -- implicit pragma Pack, but not an explicit one.
7164 if not Has_Pragma_Pack (Base_Type (Typ)) then
7165 Set_Is_Packed (Base_Type (Typ), False);
7166 Set_Component_Alignment (Base_Type (Typ), Atype);
7169 end Component_AlignmentP;
7175 -- pragma Controlled (first_subtype_LOCAL_NAME);
7177 when Pragma_Controlled => Controlled : declare
7181 Check_No_Identifiers;
7182 Check_Arg_Count (1);
7183 Check_Arg_Is_Local_Name (Arg1);
7184 Arg := Get_Pragma_Arg (Arg1);
7186 if not Is_Entity_Name (Arg)
7187 or else not Is_Access_Type (Entity (Arg))
7189 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7191 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7199 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
7200 -- [Entity =>] LOCAL_NAME);
7202 when Pragma_Convention => Convention : declare
7205 pragma Warnings (Off, C);
7206 pragma Warnings (Off, E);
7208 Check_Arg_Order ((Name_Convention, Name_Entity));
7209 Check_Ada_83_Warning;
7210 Check_Arg_Count (2);
7211 Process_Convention (C, E);
7214 ---------------------------
7215 -- Convention_Identifier --
7216 ---------------------------
7218 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
7219 -- [Convention =>] convention_IDENTIFIER);
7221 when Pragma_Convention_Identifier => Convention_Identifier : declare
7227 Check_Arg_Order ((Name_Name, Name_Convention));
7228 Check_Arg_Count (2);
7229 Check_Optional_Identifier (Arg1, Name_Name);
7230 Check_Optional_Identifier (Arg2, Name_Convention);
7231 Check_Arg_Is_Identifier (Arg1);
7232 Check_Arg_Is_Identifier (Arg2);
7233 Idnam := Chars (Get_Pragma_Arg (Arg1));
7234 Cname := Chars (Get_Pragma_Arg (Arg2));
7236 if Is_Convention_Name (Cname) then
7237 Record_Convention_Identifier
7238 (Idnam, Get_Convention_Id (Cname));
7241 ("second arg for % pragma must be convention", Arg2);
7243 end Convention_Identifier;
7249 -- pragma CPP_Class ([Entity =>] local_NAME)
7251 when Pragma_CPP_Class => CPP_Class : declare
7256 if Warn_On_Obsolescent_Feature then
7258 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7259 " by pragma import?", N);
7263 Check_Arg_Count (1);
7264 Check_Optional_Identifier (Arg1, Name_Entity);
7265 Check_Arg_Is_Local_Name (Arg1);
7267 Arg := Get_Pragma_Arg (Arg1);
7270 if Etype (Arg) = Any_Type then
7274 if not Is_Entity_Name (Arg)
7275 or else not Is_Type (Entity (Arg))
7277 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7280 Typ := Entity (Arg);
7282 if not Is_Tagged_Type (Typ) then
7283 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7286 -- Types treated as CPP classes must be declared limited (note:
7287 -- this used to be a warning but there is no real benefit to it
7288 -- since we did effectively intend to treat the type as limited
7291 if not Is_Limited_Type (Typ) then
7293 ("imported 'C'P'P type must be limited",
7294 Get_Pragma_Arg (Arg1));
7297 Set_Is_CPP_Class (Typ);
7298 Set_Convention (Typ, Convention_CPP);
7300 -- Imported CPP types must not have discriminants (because C++
7301 -- classes do not have discriminants).
7303 if Has_Discriminants (Typ) then
7305 ("imported 'C'P'P type cannot have discriminants",
7306 First (Discriminant_Specifications
7307 (Declaration_Node (Typ))));
7310 -- Components of imported CPP types must not have default
7311 -- expressions because the constructor (if any) is in the
7314 if Is_Incomplete_Or_Private_Type (Typ)
7315 and then No (Underlying_Type (Typ))
7317 -- It should be an error to apply pragma CPP to a private
7318 -- type if the underlying type is not visible (as it is
7319 -- for any representation item). For now, for backward
7320 -- compatibility we do nothing but we cannot check components
7321 -- because they are not available at this stage. All this code
7322 -- will be removed when we cleanup this obsolete GNAT pragma???
7328 Tdef : constant Node_Id :=
7329 Type_Definition (Declaration_Node (Typ));
7334 if Nkind (Tdef) = N_Record_Definition then
7335 Clist := Component_List (Tdef);
7337 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7338 Clist := Component_List (Record_Extension_Part (Tdef));
7341 if Present (Clist) then
7342 Comp := First (Component_Items (Clist));
7343 while Present (Comp) loop
7344 if Present (Expression (Comp)) then
7346 ("component of imported 'C'P'P type cannot have" &
7347 " default expression", Expression (Comp));
7357 ---------------------
7358 -- CPP_Constructor --
7359 ---------------------
7361 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7362 -- [, [External_Name =>] static_string_EXPRESSION ]
7363 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7365 when Pragma_CPP_Constructor => CPP_Constructor : declare
7369 Tag_Typ : Entity_Id;
7373 Check_At_Least_N_Arguments (1);
7374 Check_At_Most_N_Arguments (3);
7375 Check_Optional_Identifier (Arg1, Name_Entity);
7376 Check_Arg_Is_Local_Name (Arg1);
7378 Id := Get_Pragma_Arg (Arg1);
7379 Find_Program_Unit_Name (Id);
7381 -- If we did not find the name, we are done
7383 if Etype (Id) = Any_Type then
7387 Def_Id := Entity (Id);
7389 -- Check if already defined as constructor
7391 if Is_Constructor (Def_Id) then
7393 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7397 if Ekind (Def_Id) = E_Function
7398 and then (Is_CPP_Class (Etype (Def_Id))
7399 or else (Is_Class_Wide_Type (Etype (Def_Id))
7401 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7403 if Arg_Count >= 2 then
7404 Set_Imported (Def_Id);
7405 Set_Is_Public (Def_Id);
7406 Process_Interface_Name (Def_Id, Arg2, Arg3);
7409 Set_Has_Completion (Def_Id);
7410 Set_Is_Constructor (Def_Id);
7412 -- Imported C++ constructors are not dispatching primitives
7413 -- because in C++ they don't have a dispatch table slot.
7414 -- However, in Ada the constructor has the profile of a
7415 -- function that returns a tagged type and therefore it has
7416 -- been treated as a primitive operation during semantic
7417 -- analysis. We now remove it from the list of primitive
7418 -- operations of the type.
7420 if Is_Tagged_Type (Etype (Def_Id))
7421 and then not Is_Class_Wide_Type (Etype (Def_Id))
7423 pragma Assert (Is_Dispatching_Operation (Def_Id));
7424 Tag_Typ := Etype (Def_Id);
7426 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7427 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7431 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7432 Set_Is_Dispatching_Operation (Def_Id, False);
7435 -- For backward compatibility, if the constructor returns a
7436 -- class wide type, and we internally change the return type to
7437 -- the corresponding root type.
7439 if Is_Class_Wide_Type (Etype (Def_Id)) then
7440 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7444 ("pragma% requires function returning a 'C'P'P_Class type",
7447 end CPP_Constructor;
7453 when Pragma_CPP_Virtual => CPP_Virtual : declare
7457 if Warn_On_Obsolescent_Feature then
7459 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7468 when Pragma_CPP_Vtable => CPP_Vtable : declare
7472 if Warn_On_Obsolescent_Feature then
7474 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7483 -- pragma CPU (EXPRESSION);
7485 when Pragma_CPU => CPU : declare
7486 P : constant Node_Id := Parent (N);
7491 Check_No_Identifiers;
7492 Check_Arg_Count (1);
7496 if Nkind (P) = N_Subprogram_Body then
7497 Check_In_Main_Program;
7499 Arg := Get_Pragma_Arg (Arg1);
7500 Analyze_And_Resolve (Arg, Any_Integer);
7504 if not Is_Static_Expression (Arg) then
7505 Flag_Non_Static_Expr
7506 ("main subprogram affinity is not static!", Arg);
7509 -- If constraint error, then we already signalled an error
7511 elsif Raises_Constraint_Error (Arg) then
7514 -- Otherwise check in range
7518 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7519 -- This is the entity System.Multiprocessors.CPU_Range;
7521 Val : constant Uint := Expr_Value (Arg);
7524 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7526 Val > Expr_Value (Type_High_Bound (CPU_Id))
7529 ("main subprogram CPU is out of range", Arg1);
7535 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7539 elsif Nkind (P) = N_Task_Definition then
7540 Arg := Get_Pragma_Arg (Arg1);
7542 -- The expression must be analyzed in the special manner
7543 -- described in "Handling of Default and Per-Object
7544 -- Expressions" in sem.ads.
7546 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7548 -- Anything else is incorrect
7554 if Has_Pragma_CPU (P) then
7555 Error_Pragma ("duplicate pragma% not allowed");
7557 Set_Has_Pragma_CPU (P, True);
7559 if Nkind (P) = N_Task_Definition then
7560 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7569 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7571 when Pragma_Debug => Debug : declare
7580 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7583 if Arg_Count = 2 then
7586 Left_Opnd => Relocate_Node (Cond),
7587 Right_Opnd => Get_Pragma_Arg (Arg1));
7588 Call := Get_Pragma_Arg (Arg2);
7590 Call := Get_Pragma_Arg (Arg1);
7594 N_Indexed_Component,
7597 N_Selected_Component)
7599 -- If this pragma Debug comes from source, its argument was
7600 -- parsed as a name form (which is syntactically identical).
7601 -- Change it to a procedure call statement now.
7603 Change_Name_To_Procedure_Call_Statement (Call);
7605 elsif Nkind (Call) = N_Procedure_Call_Statement then
7607 -- Already in the form of a procedure call statement: nothing
7608 -- to do (could happen in case of an internally generated
7614 -- All other cases: diagnose error
7617 ("argument of pragma% is not procedure call", Sloc (Call));
7621 -- Rewrite into a conditional with an appropriate condition. We
7622 -- wrap the procedure call in a block so that overhead from e.g.
7623 -- use of the secondary stack does not generate execution overhead
7624 -- for suppressed conditions.
7626 Rewrite (N, Make_Implicit_If_Statement (N,
7628 Then_Statements => New_List (
7629 Make_Block_Statement (Loc,
7630 Handled_Statement_Sequence =>
7631 Make_Handled_Sequence_Of_Statements (Loc,
7632 Statements => New_List (Relocate_Node (Call)))))));
7640 -- pragma Debug_Policy (Check | Ignore)
7642 when Pragma_Debug_Policy =>
7644 Check_Arg_Count (1);
7645 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7646 Debug_Pragmas_Enabled :=
7647 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7649 ---------------------
7650 -- Detect_Blocking --
7651 ---------------------
7653 -- pragma Detect_Blocking;
7655 when Pragma_Detect_Blocking =>
7657 Check_Arg_Count (0);
7658 Check_Valid_Configuration_Pragma;
7659 Detect_Blocking := True;
7661 --------------------------
7662 -- Default_Storage_Pool --
7663 --------------------------
7665 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7667 when Pragma_Default_Storage_Pool =>
7669 Check_Arg_Count (1);
7671 -- Default_Storage_Pool can appear as a configuration pragma, or
7672 -- in a declarative part or a package spec.
7674 if not Is_Configuration_Pragma then
7675 Check_Is_In_Decl_Part_Or_Package_Spec;
7678 -- Case of Default_Storage_Pool (null);
7680 if Nkind (Expression (Arg1)) = N_Null then
7681 Analyze (Expression (Arg1));
7683 -- This is an odd case, this is not really an expression, so
7684 -- we don't have a type for it. So just set the type to Empty.
7686 Set_Etype (Expression (Arg1), Empty);
7688 -- Case of Default_Storage_Pool (storage_pool_NAME);
7691 -- If it's a configuration pragma, then the only allowed
7692 -- argument is "null".
7694 if Is_Configuration_Pragma then
7695 Error_Pragma_Arg ("NULL expected", Arg1);
7698 -- The expected type for a non-"null" argument is
7699 -- Root_Storage_Pool'Class.
7702 (Get_Pragma_Arg (Arg1),
7703 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7706 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7707 -- for an access type will use this information to set the
7708 -- appropriate attributes of the access type.
7710 Default_Pool := Expression (Arg1);
7716 when Pragma_Dimension =>
7718 Check_Arg_Count (4);
7719 Check_No_Identifiers;
7720 Check_Arg_Is_Local_Name (Arg1);
7722 if not Is_Type (Arg1) then
7723 Error_Pragma ("first argument for pragma% must be subtype");
7726 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7727 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7728 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7734 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7736 when Pragma_Discard_Names => Discard_Names : declare
7741 Check_Ada_83_Warning;
7743 -- Deal with configuration pragma case
7745 if Arg_Count = 0 and then Is_Configuration_Pragma then
7746 Global_Discard_Names := True;
7749 -- Otherwise, check correct appropriate context
7752 Check_Is_In_Decl_Part_Or_Package_Spec;
7754 if Arg_Count = 0 then
7756 -- If there is no parameter, then from now on this pragma
7757 -- applies to any enumeration, exception or tagged type
7758 -- defined in the current declarative part, and recursively
7759 -- to any nested scope.
7761 Set_Discard_Names (Current_Scope);
7765 Check_Arg_Count (1);
7766 Check_Optional_Identifier (Arg1, Name_On);
7767 Check_Arg_Is_Local_Name (Arg1);
7769 E_Id := Get_Pragma_Arg (Arg1);
7771 if Etype (E_Id) = Any_Type then
7777 if (Is_First_Subtype (E)
7779 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7780 or else Ekind (E) = E_Exception
7782 Set_Discard_Names (E);
7785 ("inappropriate entity for pragma%", Arg1);
7796 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7798 when Pragma_Elaborate => Elaborate : declare
7803 -- Pragma must be in context items list of a compilation unit
7805 if not Is_In_Context_Clause then
7809 -- Must be at least one argument
7811 if Arg_Count = 0 then
7812 Error_Pragma ("pragma% requires at least one argument");
7815 -- In Ada 83 mode, there can be no items following it in the
7816 -- context list except other pragmas and implicit with clauses
7817 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7818 -- placement rule does not apply.
7820 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7822 while Present (Citem) loop
7823 if Nkind (Citem) = N_Pragma
7824 or else (Nkind (Citem) = N_With_Clause
7825 and then Implicit_With (Citem))
7830 ("(Ada 83) pragma% must be at end of context clause");
7837 -- Finally, the arguments must all be units mentioned in a with
7838 -- clause in the same context clause. Note we already checked (in
7839 -- Par.Prag) that the arguments are all identifiers or selected
7843 Outer : while Present (Arg) loop
7844 Citem := First (List_Containing (N));
7845 Inner : while Citem /= N loop
7846 if Nkind (Citem) = N_With_Clause
7847 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7849 Set_Elaborate_Present (Citem, True);
7850 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7851 Generate_Reference (Entity (Name (Citem)), Citem);
7853 -- With the pragma present, elaboration calls on
7854 -- subprograms from the named unit need no further
7855 -- checks, as long as the pragma appears in the current
7856 -- compilation unit. If the pragma appears in some unit
7857 -- in the context, there might still be a need for an
7858 -- Elaborate_All_Desirable from the current compilation
7859 -- to the named unit, so we keep the check enabled.
7861 if In_Extended_Main_Source_Unit (N) then
7862 Set_Suppress_Elaboration_Warnings
7863 (Entity (Name (Citem)));
7874 ("argument of pragma% is not with'ed unit", Arg);
7880 -- Give a warning if operating in static mode with -gnatwl
7881 -- (elaboration warnings enabled) switch set.
7883 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7885 ("?use of pragma Elaborate may not be safe", N);
7887 ("?use pragma Elaborate_All instead if possible", N);
7895 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7897 when Pragma_Elaborate_All => Elaborate_All : declare
7902 Check_Ada_83_Warning;
7904 -- Pragma must be in context items list of a compilation unit
7906 if not Is_In_Context_Clause then
7910 -- Must be at least one argument
7912 if Arg_Count = 0 then
7913 Error_Pragma ("pragma% requires at least one argument");
7916 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7917 -- have to appear at the end of the context clause, but may
7918 -- appear mixed in with other items, even in Ada 83 mode.
7920 -- Final check: the arguments must all be units mentioned in
7921 -- a with clause in the same context clause. Note that we
7922 -- already checked (in Par.Prag) that all the arguments are
7923 -- either identifiers or selected components.
7926 Outr : while Present (Arg) loop
7927 Citem := First (List_Containing (N));
7928 Innr : while Citem /= N loop
7929 if Nkind (Citem) = N_With_Clause
7930 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7932 Set_Elaborate_All_Present (Citem, True);
7933 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7935 -- Suppress warnings and elaboration checks on the named
7936 -- unit if the pragma is in the current compilation, as
7937 -- for pragma Elaborate.
7939 if In_Extended_Main_Source_Unit (N) then
7940 Set_Suppress_Elaboration_Warnings
7941 (Entity (Name (Citem)));
7950 Set_Error_Posted (N);
7952 ("argument of pragma% is not with'ed unit", Arg);
7959 --------------------
7960 -- Elaborate_Body --
7961 --------------------
7963 -- pragma Elaborate_Body [( library_unit_NAME )];
7965 when Pragma_Elaborate_Body => Elaborate_Body : declare
7966 Cunit_Node : Node_Id;
7967 Cunit_Ent : Entity_Id;
7970 Check_Ada_83_Warning;
7971 Check_Valid_Library_Unit_Pragma;
7973 if Nkind (N) = N_Null_Statement then
7977 Cunit_Node := Cunit (Current_Sem_Unit);
7978 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7980 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7983 Error_Pragma ("pragma% must refer to a spec, not a body");
7985 Set_Body_Required (Cunit_Node, True);
7986 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7988 -- If we are in dynamic elaboration mode, then we suppress
7989 -- elaboration warnings for the unit, since it is definitely
7990 -- fine NOT to do dynamic checks at the first level (and such
7991 -- checks will be suppressed because no elaboration boolean
7992 -- is created for Elaborate_Body packages).
7994 -- But in the static model of elaboration, Elaborate_Body is
7995 -- definitely NOT good enough to ensure elaboration safety on
7996 -- its own, since the body may WITH other units that are not
7997 -- safe from an elaboration point of view, so a client must
7998 -- still do an Elaborate_All on such units.
8000 -- Debug flag -gnatdD restores the old behavior of 3.13, where
8001 -- Elaborate_Body always suppressed elab warnings.
8003 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8004 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8009 ------------------------
8010 -- Elaboration_Checks --
8011 ------------------------
8013 -- pragma Elaboration_Checks (Static | Dynamic);
8015 when Pragma_Elaboration_Checks =>
8017 Check_Arg_Count (1);
8018 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8019 Dynamic_Elaboration_Checks :=
8020 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8026 -- pragma Eliminate (
8027 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
8028 -- [,[Entity =>] IDENTIFIER |
8029 -- SELECTED_COMPONENT |
8031 -- [, OVERLOADING_RESOLUTION]);
8033 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8036 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8039 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8041 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8042 -- Result_Type => result_SUBTYPE_NAME]
8044 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8045 -- SUBTYPE_NAME ::= STRING_LITERAL
8047 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8048 -- SOURCE_TRACE ::= STRING_LITERAL
8050 when Pragma_Eliminate => Eliminate : declare
8051 Args : Args_List (1 .. 5);
8052 Names : constant Name_List (1 .. 5) := (
8055 Name_Parameter_Types,
8057 Name_Source_Location);
8059 Unit_Name : Node_Id renames Args (1);
8060 Entity : Node_Id renames Args (2);
8061 Parameter_Types : Node_Id renames Args (3);
8062 Result_Type : Node_Id renames Args (4);
8063 Source_Location : Node_Id renames Args (5);
8067 Check_Valid_Configuration_Pragma;
8068 Gather_Associations (Names, Args);
8070 if No (Unit_Name) then
8071 Error_Pragma ("missing Unit_Name argument for pragma%");
8075 and then (Present (Parameter_Types)
8077 Present (Result_Type)
8079 Present (Source_Location))
8081 Error_Pragma ("missing Entity argument for pragma%");
8084 if (Present (Parameter_Types)
8086 Present (Result_Type))
8088 Present (Source_Location)
8091 ("parameter profile and source location cannot " &
8092 "be used together in pragma%");
8095 Process_Eliminate_Pragma
8109 -- [ Convention =>] convention_IDENTIFIER,
8110 -- [ Entity =>] local_NAME
8111 -- [, [External_Name =>] static_string_EXPRESSION ]
8112 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8114 when Pragma_Export => Export : declare
8118 pragma Warnings (Off, C);
8121 Check_Ada_83_Warning;
8127 Check_At_Least_N_Arguments (2);
8128 Check_At_Most_N_Arguments (4);
8129 Process_Convention (C, Def_Id);
8131 if Ekind (Def_Id) /= E_Constant then
8132 Note_Possible_Modification
8133 (Get_Pragma_Arg (Arg2), Sure => False);
8136 Process_Interface_Name (Def_Id, Arg3, Arg4);
8137 Set_Exported (Def_Id, Arg2);
8139 -- If the entity is a deferred constant, propagate the information
8140 -- to the full view, because gigi elaborates the full view only.
8142 if Ekind (Def_Id) = E_Constant
8143 and then Present (Full_View (Def_Id))
8146 Id2 : constant Entity_Id := Full_View (Def_Id);
8148 Set_Is_Exported (Id2, Is_Exported (Def_Id));
8149 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
8150 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8155 ----------------------
8156 -- Export_Exception --
8157 ----------------------
8159 -- pragma Export_Exception (
8160 -- [Internal =>] LOCAL_NAME
8161 -- [, [External =>] EXTERNAL_SYMBOL]
8162 -- [, [Form =>] Ada | VMS]
8163 -- [, [Code =>] static_integer_EXPRESSION]);
8165 when Pragma_Export_Exception => Export_Exception : declare
8166 Args : Args_List (1 .. 4);
8167 Names : constant Name_List (1 .. 4) := (
8173 Internal : Node_Id renames Args (1);
8174 External : Node_Id renames Args (2);
8175 Form : Node_Id renames Args (3);
8176 Code : Node_Id renames Args (4);
8181 if Inside_A_Generic then
8182 Error_Pragma ("pragma% cannot be used for generic entities");
8185 Gather_Associations (Names, Args);
8186 Process_Extended_Import_Export_Exception_Pragma (
8187 Arg_Internal => Internal,
8188 Arg_External => External,
8192 if not Is_VMS_Exception (Entity (Internal)) then
8193 Set_Exported (Entity (Internal), Internal);
8195 end Export_Exception;
8197 ---------------------
8198 -- Export_Function --
8199 ---------------------
8201 -- pragma Export_Function (
8202 -- [Internal =>] LOCAL_NAME
8203 -- [, [External =>] EXTERNAL_SYMBOL]
8204 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8205 -- [, [Result_Type =>] TYPE_DESIGNATOR]
8206 -- [, [Mechanism =>] MECHANISM]
8207 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8209 -- EXTERNAL_SYMBOL ::=
8211 -- | static_string_EXPRESSION
8213 -- PARAMETER_TYPES ::=
8215 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8217 -- TYPE_DESIGNATOR ::=
8219 -- | subtype_Name ' Access
8223 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8225 -- MECHANISM_ASSOCIATION ::=
8226 -- [formal_parameter_NAME =>] MECHANISM_NAME
8228 -- MECHANISM_NAME ::=
8231 -- | Descriptor [([Class =>] CLASS_NAME)]
8233 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8235 when Pragma_Export_Function => Export_Function : declare
8236 Args : Args_List (1 .. 6);
8237 Names : constant Name_List (1 .. 6) := (
8240 Name_Parameter_Types,
8243 Name_Result_Mechanism);
8245 Internal : Node_Id renames Args (1);
8246 External : Node_Id renames Args (2);
8247 Parameter_Types : Node_Id renames Args (3);
8248 Result_Type : Node_Id renames Args (4);
8249 Mechanism : Node_Id renames Args (5);
8250 Result_Mechanism : Node_Id renames Args (6);
8254 Gather_Associations (Names, Args);
8255 Process_Extended_Import_Export_Subprogram_Pragma (
8256 Arg_Internal => Internal,
8257 Arg_External => External,
8258 Arg_Parameter_Types => Parameter_Types,
8259 Arg_Result_Type => Result_Type,
8260 Arg_Mechanism => Mechanism,
8261 Arg_Result_Mechanism => Result_Mechanism);
8262 end Export_Function;
8268 -- pragma Export_Object (
8269 -- [Internal =>] LOCAL_NAME
8270 -- [, [External =>] EXTERNAL_SYMBOL]
8271 -- [, [Size =>] EXTERNAL_SYMBOL]);
8273 -- EXTERNAL_SYMBOL ::=
8275 -- | static_string_EXPRESSION
8277 -- PARAMETER_TYPES ::=
8279 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8281 -- TYPE_DESIGNATOR ::=
8283 -- | subtype_Name ' Access
8287 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8289 -- MECHANISM_ASSOCIATION ::=
8290 -- [formal_parameter_NAME =>] MECHANISM_NAME
8292 -- MECHANISM_NAME ::=
8295 -- | Descriptor [([Class =>] CLASS_NAME)]
8297 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8299 when Pragma_Export_Object => Export_Object : declare
8300 Args : Args_List (1 .. 3);
8301 Names : constant Name_List (1 .. 3) := (
8306 Internal : Node_Id renames Args (1);
8307 External : Node_Id renames Args (2);
8308 Size : Node_Id renames Args (3);
8312 Gather_Associations (Names, Args);
8313 Process_Extended_Import_Export_Object_Pragma (
8314 Arg_Internal => Internal,
8315 Arg_External => External,
8319 ----------------------
8320 -- Export_Procedure --
8321 ----------------------
8323 -- pragma Export_Procedure (
8324 -- [Internal =>] LOCAL_NAME
8325 -- [, [External =>] EXTERNAL_SYMBOL]
8326 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8327 -- [, [Mechanism =>] MECHANISM]);
8329 -- EXTERNAL_SYMBOL ::=
8331 -- | static_string_EXPRESSION
8333 -- PARAMETER_TYPES ::=
8335 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8337 -- TYPE_DESIGNATOR ::=
8339 -- | subtype_Name ' Access
8343 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8345 -- MECHANISM_ASSOCIATION ::=
8346 -- [formal_parameter_NAME =>] MECHANISM_NAME
8348 -- MECHANISM_NAME ::=
8351 -- | Descriptor [([Class =>] CLASS_NAME)]
8353 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8355 when Pragma_Export_Procedure => Export_Procedure : declare
8356 Args : Args_List (1 .. 4);
8357 Names : constant Name_List (1 .. 4) := (
8360 Name_Parameter_Types,
8363 Internal : Node_Id renames Args (1);
8364 External : Node_Id renames Args (2);
8365 Parameter_Types : Node_Id renames Args (3);
8366 Mechanism : Node_Id renames Args (4);
8370 Gather_Associations (Names, Args);
8371 Process_Extended_Import_Export_Subprogram_Pragma (
8372 Arg_Internal => Internal,
8373 Arg_External => External,
8374 Arg_Parameter_Types => Parameter_Types,
8375 Arg_Mechanism => Mechanism);
8376 end Export_Procedure;
8382 -- pragma Export_Value (
8383 -- [Value =>] static_integer_EXPRESSION,
8384 -- [Link_Name =>] static_string_EXPRESSION);
8386 when Pragma_Export_Value =>
8388 Check_Arg_Order ((Name_Value, Name_Link_Name));
8389 Check_Arg_Count (2);
8391 Check_Optional_Identifier (Arg1, Name_Value);
8392 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8394 Check_Optional_Identifier (Arg2, Name_Link_Name);
8395 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8397 -----------------------------
8398 -- Export_Valued_Procedure --
8399 -----------------------------
8401 -- pragma Export_Valued_Procedure (
8402 -- [Internal =>] LOCAL_NAME
8403 -- [, [External =>] EXTERNAL_SYMBOL,]
8404 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8405 -- [, [Mechanism =>] MECHANISM]);
8407 -- EXTERNAL_SYMBOL ::=
8409 -- | static_string_EXPRESSION
8411 -- PARAMETER_TYPES ::=
8413 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8415 -- TYPE_DESIGNATOR ::=
8417 -- | subtype_Name ' Access
8421 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8423 -- MECHANISM_ASSOCIATION ::=
8424 -- [formal_parameter_NAME =>] MECHANISM_NAME
8426 -- MECHANISM_NAME ::=
8429 -- | Descriptor [([Class =>] CLASS_NAME)]
8431 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8433 when Pragma_Export_Valued_Procedure =>
8434 Export_Valued_Procedure : declare
8435 Args : Args_List (1 .. 4);
8436 Names : constant Name_List (1 .. 4) := (
8439 Name_Parameter_Types,
8442 Internal : Node_Id renames Args (1);
8443 External : Node_Id renames Args (2);
8444 Parameter_Types : Node_Id renames Args (3);
8445 Mechanism : Node_Id renames Args (4);
8449 Gather_Associations (Names, Args);
8450 Process_Extended_Import_Export_Subprogram_Pragma (
8451 Arg_Internal => Internal,
8452 Arg_External => External,
8453 Arg_Parameter_Types => Parameter_Types,
8454 Arg_Mechanism => Mechanism);
8455 end Export_Valued_Procedure;
8461 -- pragma Extend_System ([Name =>] Identifier);
8463 when Pragma_Extend_System => Extend_System : declare
8466 Check_Valid_Configuration_Pragma;
8467 Check_Arg_Count (1);
8468 Check_Optional_Identifier (Arg1, Name_Name);
8469 Check_Arg_Is_Identifier (Arg1);
8471 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8474 and then Name_Buffer (1 .. 4) = "aux_"
8476 if Present (System_Extend_Pragma_Arg) then
8477 if Chars (Get_Pragma_Arg (Arg1)) =
8478 Chars (Expression (System_Extend_Pragma_Arg))
8482 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8483 Error_Pragma ("pragma% conflicts with that #");
8487 System_Extend_Pragma_Arg := Arg1;
8489 if not GNAT_Mode then
8490 System_Extend_Unit := Arg1;
8494 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8498 ------------------------
8499 -- Extensions_Allowed --
8500 ------------------------
8502 -- pragma Extensions_Allowed (ON | OFF);
8504 when Pragma_Extensions_Allowed =>
8506 Check_Arg_Count (1);
8507 Check_No_Identifiers;
8508 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8510 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8511 Extensions_Allowed := True;
8512 Ada_Version := Ada_Version_Type'Last;
8515 Extensions_Allowed := False;
8516 Ada_Version := Ada_Version_Explicit;
8523 -- pragma External (
8524 -- [ Convention =>] convention_IDENTIFIER,
8525 -- [ Entity =>] local_NAME
8526 -- [, [External_Name =>] static_string_EXPRESSION ]
8527 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8529 when Pragma_External => External : declare
8533 pragma Warnings (Off, C);
8542 Check_At_Least_N_Arguments (2);
8543 Check_At_Most_N_Arguments (4);
8544 Process_Convention (C, Def_Id);
8545 Note_Possible_Modification
8546 (Get_Pragma_Arg (Arg2), Sure => False);
8547 Process_Interface_Name (Def_Id, Arg3, Arg4);
8548 Set_Exported (Def_Id, Arg2);
8551 --------------------------
8552 -- External_Name_Casing --
8553 --------------------------
8555 -- pragma External_Name_Casing (
8556 -- UPPERCASE | LOWERCASE
8557 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8559 when Pragma_External_Name_Casing => External_Name_Casing : declare
8562 Check_No_Identifiers;
8564 if Arg_Count = 2 then
8566 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8568 case Chars (Get_Pragma_Arg (Arg2)) is
8570 Opt.External_Name_Exp_Casing := As_Is;
8572 when Name_Uppercase =>
8573 Opt.External_Name_Exp_Casing := Uppercase;
8575 when Name_Lowercase =>
8576 Opt.External_Name_Exp_Casing := Lowercase;
8583 Check_Arg_Count (1);
8586 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8588 case Chars (Get_Pragma_Arg (Arg1)) is
8589 when Name_Uppercase =>
8590 Opt.External_Name_Imp_Casing := Uppercase;
8592 when Name_Lowercase =>
8593 Opt.External_Name_Imp_Casing := Lowercase;
8598 end External_Name_Casing;
8600 --------------------------
8601 -- Favor_Top_Level --
8602 --------------------------
8604 -- pragma Favor_Top_Level (type_NAME);
8606 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8607 Named_Entity : Entity_Id;
8611 Check_No_Identifiers;
8612 Check_Arg_Count (1);
8613 Check_Arg_Is_Local_Name (Arg1);
8614 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8616 -- If it's an access-to-subprogram type (in particular, not a
8617 -- subtype), set the flag on that type.
8619 if Is_Access_Subprogram_Type (Named_Entity) then
8620 Set_Can_Use_Internal_Rep (Named_Entity, False);
8622 -- Otherwise it's an error (name denotes the wrong sort of entity)
8626 ("access-to-subprogram type expected",
8627 Get_Pragma_Arg (Arg1));
8629 end Favor_Top_Level;
8635 -- pragma Fast_Math;
8637 when Pragma_Fast_Math =>
8639 Check_No_Identifiers;
8640 Check_Valid_Configuration_Pragma;
8643 ---------------------------
8644 -- Finalize_Storage_Only --
8645 ---------------------------
8647 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8649 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8650 Assoc : constant Node_Id := Arg1;
8651 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8656 Check_No_Identifiers;
8657 Check_Arg_Count (1);
8658 Check_Arg_Is_Local_Name (Arg1);
8660 Find_Type (Type_Id);
8661 Typ := Entity (Type_Id);
8664 or else Rep_Item_Too_Early (Typ, N)
8668 Typ := Underlying_Type (Typ);
8671 if not Is_Controlled (Typ) then
8672 Error_Pragma ("pragma% must specify controlled type");
8675 Check_First_Subtype (Arg1);
8677 if Finalize_Storage_Only (Typ) then
8678 Error_Pragma ("duplicate pragma%, only one allowed");
8680 elsif not Rep_Item_Too_Late (Typ, N) then
8681 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8683 end Finalize_Storage;
8685 --------------------------
8686 -- Float_Representation --
8687 --------------------------
8689 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8691 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8693 when Pragma_Float_Representation => Float_Representation : declare
8701 if Arg_Count = 1 then
8702 Check_Valid_Configuration_Pragma;
8704 Check_Arg_Count (2);
8705 Check_Optional_Identifier (Arg2, Name_Entity);
8706 Check_Arg_Is_Local_Name (Arg2);
8709 Check_No_Identifier (Arg1);
8710 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8712 if not OpenVMS_On_Target then
8713 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8715 ("?pragma% ignored (applies only to Open'V'M'S)");
8721 -- One argument case
8723 if Arg_Count = 1 then
8724 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8725 if Opt.Float_Format = 'I' then
8726 Error_Pragma ("'I'E'E'E format previously specified");
8729 Opt.Float_Format := 'V';
8732 if Opt.Float_Format = 'V' then
8733 Error_Pragma ("'V'A'X format previously specified");
8736 Opt.Float_Format := 'I';
8739 Set_Standard_Fpt_Formats;
8741 -- Two argument case
8744 Argx := Get_Pragma_Arg (Arg2);
8746 if not Is_Entity_Name (Argx)
8747 or else not Is_Floating_Point_Type (Entity (Argx))
8750 ("second argument of% pragma must be floating-point type",
8754 Ent := Entity (Argx);
8755 Digs := UI_To_Int (Digits_Value (Ent));
8757 -- Two arguments, VAX_Float case
8759 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8761 when 6 => Set_F_Float (Ent);
8762 when 9 => Set_D_Float (Ent);
8763 when 15 => Set_G_Float (Ent);
8767 ("wrong digits value, must be 6,9 or 15", Arg2);
8770 -- Two arguments, IEEE_Float case
8774 when 6 => Set_IEEE_Short (Ent);
8775 when 15 => Set_IEEE_Long (Ent);
8779 ("wrong digits value, must be 6 or 15", Arg2);
8783 end Float_Representation;
8789 -- pragma Ident (static_string_EXPRESSION)
8791 -- Note: pragma Comment shares this processing. Pragma Comment is
8792 -- identical to Ident, except that the restriction of the argument to
8793 -- 31 characters and the placement restrictions are not enforced for
8796 when Pragma_Ident | Pragma_Comment => Ident : declare
8801 Check_Arg_Count (1);
8802 Check_No_Identifiers;
8803 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8806 -- For pragma Ident, preserve DEC compatibility by requiring the
8807 -- pragma to appear in a declarative part or package spec.
8809 if Prag_Id = Pragma_Ident then
8810 Check_Is_In_Decl_Part_Or_Package_Spec;
8813 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8820 GP := Parent (Parent (N));
8822 if Nkind_In (GP, N_Package_Declaration,
8823 N_Generic_Package_Declaration)
8828 -- If we have a compilation unit, then record the ident value,
8829 -- checking for improper duplication.
8831 if Nkind (GP) = N_Compilation_Unit then
8832 CS := Ident_String (Current_Sem_Unit);
8834 if Present (CS) then
8836 -- For Ident, we do not permit multiple instances
8838 if Prag_Id = Pragma_Ident then
8839 Error_Pragma ("duplicate% pragma not permitted");
8841 -- For Comment, we concatenate the string, unless we want
8842 -- to preserve the tree structure for ASIS.
8844 elsif not ASIS_Mode then
8845 Start_String (Strval (CS));
8846 Store_String_Char (' ');
8847 Store_String_Chars (Strval (Str));
8848 Set_Strval (CS, End_String);
8852 -- In VMS, the effect of IDENT is achieved by passing
8853 -- --identification=name as a --for-linker switch.
8855 if OpenVMS_On_Target then
8858 ("--for-linker=--identification=");
8859 String_To_Name_Buffer (Strval (Str));
8860 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8862 -- Only the last processed IDENT is saved. The main
8863 -- purpose is so an IDENT associated with a main
8864 -- procedure will be used in preference to an IDENT
8865 -- associated with a with'd package.
8867 Replace_Linker_Option_String
8868 (End_String, "--for-linker=--identification=");
8871 Set_Ident_String (Current_Sem_Unit, Str);
8874 -- For subunits, we just ignore the Ident, since in GNAT these
8875 -- are not separate object files, and hence not separate units
8876 -- in the unit table.
8878 elsif Nkind (GP) = N_Subunit then
8881 -- Otherwise we have a misplaced pragma Ident, but we ignore
8882 -- this if we are in an instantiation, since it comes from
8883 -- a generic, and has no relevance to the instantiation.
8885 elsif Prag_Id = Pragma_Ident then
8886 if Instantiation_Location (Loc) = No_Location then
8887 Error_Pragma ("pragma% only allowed at outer level");
8897 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8898 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8900 when Pragma_Implemented => Implemented : declare
8901 Proc_Id : Entity_Id;
8906 Check_Arg_Count (2);
8907 Check_No_Identifiers;
8908 Check_Arg_Is_Identifier (Arg1);
8909 Check_Arg_Is_Local_Name (Arg1);
8911 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8913 -- Extract the name of the local procedure
8915 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8917 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8918 -- primitive procedure of a synchronized tagged type.
8920 if Ekind (Proc_Id) = E_Procedure
8921 and then Is_Primitive (Proc_Id)
8922 and then Present (First_Formal (Proc_Id))
8924 Typ := Etype (First_Formal (Proc_Id));
8926 if Is_Tagged_Type (Typ)
8929 -- Check for a protected, a synchronized or a task interface
8931 ((Is_Interface (Typ)
8932 and then Is_Synchronized_Interface (Typ))
8934 -- Check for a protected type or a task type that implements
8938 (Is_Concurrent_Record_Type (Typ)
8939 and then Present (Interfaces (Typ)))
8941 -- Check for a private record extension with keyword
8945 (Ekind_In (Typ, E_Record_Type_With_Private,
8946 E_Record_Subtype_With_Private)
8947 and then Synchronized_Present (Parent (Typ))))
8952 ("controlling formal must be of synchronized " &
8953 "tagged type", Arg1);
8957 -- Procedures declared inside a protected type must be accepted
8959 elsif Ekind (Proc_Id) = E_Procedure
8960 and then Is_Protected_Type (Scope (Proc_Id))
8964 -- The first argument is not a primitive procedure
8968 ("pragma % must be applied to a primitive procedure", Arg1);
8972 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8973 -- By_Protected_Procedure to the primitive procedure of a task
8976 if Chars (Arg2) = Name_By_Protected_Procedure
8977 and then Is_Interface (Typ)
8978 and then Is_Task_Interface (Typ)
8981 ("implementation kind By_Protected_Procedure cannot be " &
8982 "applied to a task interface primitive", Arg2);
8986 Record_Rep_Item (Proc_Id, N);
8989 ----------------------
8990 -- Implicit_Packing --
8991 ----------------------
8993 -- pragma Implicit_Packing;
8995 when Pragma_Implicit_Packing =>
8997 Check_Arg_Count (0);
8998 Implicit_Packing := True;
9005 -- [Convention =>] convention_IDENTIFIER,
9006 -- [Entity =>] local_NAME
9007 -- [, [External_Name =>] static_string_EXPRESSION ]
9008 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9010 when Pragma_Import =>
9011 Check_Ada_83_Warning;
9017 Check_At_Least_N_Arguments (2);
9018 Check_At_Most_N_Arguments (4);
9019 Process_Import_Or_Interface;
9021 ----------------------
9022 -- Import_Exception --
9023 ----------------------
9025 -- pragma Import_Exception (
9026 -- [Internal =>] LOCAL_NAME
9027 -- [, [External =>] EXTERNAL_SYMBOL]
9028 -- [, [Form =>] Ada | VMS]
9029 -- [, [Code =>] static_integer_EXPRESSION]);
9031 when Pragma_Import_Exception => Import_Exception : declare
9032 Args : Args_List (1 .. 4);
9033 Names : constant Name_List (1 .. 4) := (
9039 Internal : Node_Id renames Args (1);
9040 External : Node_Id renames Args (2);
9041 Form : Node_Id renames Args (3);
9042 Code : Node_Id renames Args (4);
9046 Gather_Associations (Names, Args);
9048 if Present (External) and then Present (Code) then
9050 ("cannot give both External and Code options for pragma%");
9053 Process_Extended_Import_Export_Exception_Pragma (
9054 Arg_Internal => Internal,
9055 Arg_External => External,
9059 if not Is_VMS_Exception (Entity (Internal)) then
9060 Set_Imported (Entity (Internal));
9062 end Import_Exception;
9064 ---------------------
9065 -- Import_Function --
9066 ---------------------
9068 -- pragma Import_Function (
9069 -- [Internal =>] LOCAL_NAME,
9070 -- [, [External =>] EXTERNAL_SYMBOL]
9071 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9072 -- [, [Result_Type =>] SUBTYPE_MARK]
9073 -- [, [Mechanism =>] MECHANISM]
9074 -- [, [Result_Mechanism =>] MECHANISM_NAME]
9075 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9077 -- EXTERNAL_SYMBOL ::=
9079 -- | static_string_EXPRESSION
9081 -- PARAMETER_TYPES ::=
9083 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9085 -- TYPE_DESIGNATOR ::=
9087 -- | subtype_Name ' Access
9091 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9093 -- MECHANISM_ASSOCIATION ::=
9094 -- [formal_parameter_NAME =>] MECHANISM_NAME
9096 -- MECHANISM_NAME ::=
9099 -- | Descriptor [([Class =>] CLASS_NAME)]
9101 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9103 when Pragma_Import_Function => Import_Function : declare
9104 Args : Args_List (1 .. 7);
9105 Names : constant Name_List (1 .. 7) := (
9108 Name_Parameter_Types,
9111 Name_Result_Mechanism,
9112 Name_First_Optional_Parameter);
9114 Internal : Node_Id renames Args (1);
9115 External : Node_Id renames Args (2);
9116 Parameter_Types : Node_Id renames Args (3);
9117 Result_Type : Node_Id renames Args (4);
9118 Mechanism : Node_Id renames Args (5);
9119 Result_Mechanism : Node_Id renames Args (6);
9120 First_Optional_Parameter : Node_Id renames Args (7);
9124 Gather_Associations (Names, Args);
9125 Process_Extended_Import_Export_Subprogram_Pragma (
9126 Arg_Internal => Internal,
9127 Arg_External => External,
9128 Arg_Parameter_Types => Parameter_Types,
9129 Arg_Result_Type => Result_Type,
9130 Arg_Mechanism => Mechanism,
9131 Arg_Result_Mechanism => Result_Mechanism,
9132 Arg_First_Optional_Parameter => First_Optional_Parameter);
9133 end Import_Function;
9139 -- pragma Import_Object (
9140 -- [Internal =>] LOCAL_NAME
9141 -- [, [External =>] EXTERNAL_SYMBOL]
9142 -- [, [Size =>] EXTERNAL_SYMBOL]);
9144 -- EXTERNAL_SYMBOL ::=
9146 -- | static_string_EXPRESSION
9148 when Pragma_Import_Object => Import_Object : declare
9149 Args : Args_List (1 .. 3);
9150 Names : constant Name_List (1 .. 3) := (
9155 Internal : Node_Id renames Args (1);
9156 External : Node_Id renames Args (2);
9157 Size : Node_Id renames Args (3);
9161 Gather_Associations (Names, Args);
9162 Process_Extended_Import_Export_Object_Pragma (
9163 Arg_Internal => Internal,
9164 Arg_External => External,
9168 ----------------------
9169 -- Import_Procedure --
9170 ----------------------
9172 -- pragma Import_Procedure (
9173 -- [Internal =>] LOCAL_NAME
9174 -- [, [External =>] EXTERNAL_SYMBOL]
9175 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9176 -- [, [Mechanism =>] MECHANISM]
9177 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9179 -- EXTERNAL_SYMBOL ::=
9181 -- | static_string_EXPRESSION
9183 -- PARAMETER_TYPES ::=
9185 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9187 -- TYPE_DESIGNATOR ::=
9189 -- | subtype_Name ' Access
9193 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9195 -- MECHANISM_ASSOCIATION ::=
9196 -- [formal_parameter_NAME =>] MECHANISM_NAME
9198 -- MECHANISM_NAME ::=
9201 -- | Descriptor [([Class =>] CLASS_NAME)]
9203 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9205 when Pragma_Import_Procedure => Import_Procedure : declare
9206 Args : Args_List (1 .. 5);
9207 Names : constant Name_List (1 .. 5) := (
9210 Name_Parameter_Types,
9212 Name_First_Optional_Parameter);
9214 Internal : Node_Id renames Args (1);
9215 External : Node_Id renames Args (2);
9216 Parameter_Types : Node_Id renames Args (3);
9217 Mechanism : Node_Id renames Args (4);
9218 First_Optional_Parameter : Node_Id renames Args (5);
9222 Gather_Associations (Names, Args);
9223 Process_Extended_Import_Export_Subprogram_Pragma (
9224 Arg_Internal => Internal,
9225 Arg_External => External,
9226 Arg_Parameter_Types => Parameter_Types,
9227 Arg_Mechanism => Mechanism,
9228 Arg_First_Optional_Parameter => First_Optional_Parameter);
9229 end Import_Procedure;
9231 -----------------------------
9232 -- Import_Valued_Procedure --
9233 -----------------------------
9235 -- pragma Import_Valued_Procedure (
9236 -- [Internal =>] LOCAL_NAME
9237 -- [, [External =>] EXTERNAL_SYMBOL]
9238 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9239 -- [, [Mechanism =>] MECHANISM]
9240 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9242 -- EXTERNAL_SYMBOL ::=
9244 -- | static_string_EXPRESSION
9246 -- PARAMETER_TYPES ::=
9248 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9250 -- TYPE_DESIGNATOR ::=
9252 -- | subtype_Name ' Access
9256 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9258 -- MECHANISM_ASSOCIATION ::=
9259 -- [formal_parameter_NAME =>] MECHANISM_NAME
9261 -- MECHANISM_NAME ::=
9264 -- | Descriptor [([Class =>] CLASS_NAME)]
9266 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9268 when Pragma_Import_Valued_Procedure =>
9269 Import_Valued_Procedure : declare
9270 Args : Args_List (1 .. 5);
9271 Names : constant Name_List (1 .. 5) := (
9274 Name_Parameter_Types,
9276 Name_First_Optional_Parameter);
9278 Internal : Node_Id renames Args (1);
9279 External : Node_Id renames Args (2);
9280 Parameter_Types : Node_Id renames Args (3);
9281 Mechanism : Node_Id renames Args (4);
9282 First_Optional_Parameter : Node_Id renames Args (5);
9286 Gather_Associations (Names, Args);
9287 Process_Extended_Import_Export_Subprogram_Pragma (
9288 Arg_Internal => Internal,
9289 Arg_External => External,
9290 Arg_Parameter_Types => Parameter_Types,
9291 Arg_Mechanism => Mechanism,
9292 Arg_First_Optional_Parameter => First_Optional_Parameter);
9293 end Import_Valued_Procedure;
9299 -- pragma Independent (LOCAL_NAME);
9301 when Pragma_Independent => Independent : declare
9308 Check_Ada_83_Warning;
9310 Check_No_Identifiers;
9311 Check_Arg_Count (1);
9312 Check_Arg_Is_Local_Name (Arg1);
9313 E_Id := Get_Pragma_Arg (Arg1);
9315 if Etype (E_Id) = Any_Type then
9320 D := Declaration_Node (E);
9323 -- Check duplicate before we chain ourselves!
9325 Check_Duplicate_Pragma (E);
9327 -- Check appropriate entity
9330 if Rep_Item_Too_Early (E, N)
9332 Rep_Item_Too_Late (E, N)
9336 Check_First_Subtype (Arg1);
9339 elsif K = N_Object_Declaration
9340 or else (K = N_Component_Declaration
9341 and then Original_Record_Component (E) = E)
9343 if Rep_Item_Too_Late (E, N) then
9349 ("inappropriate entity for pragma%", Arg1);
9352 Independence_Checks.Append ((N, E));
9355 ----------------------------
9356 -- Independent_Components --
9357 ----------------------------
9359 -- pragma Atomic_Components (array_LOCAL_NAME);
9361 -- This processing is shared by Volatile_Components
9363 when Pragma_Independent_Components => Independent_Components : declare
9370 Check_Ada_83_Warning;
9372 Check_No_Identifiers;
9373 Check_Arg_Count (1);
9374 Check_Arg_Is_Local_Name (Arg1);
9375 E_Id := Get_Pragma_Arg (Arg1);
9377 if Etype (E_Id) = Any_Type then
9383 -- Check duplicate before we chain ourselves!
9385 Check_Duplicate_Pragma (E);
9387 -- Check appropriate entity
9389 if Rep_Item_Too_Early (E, N)
9391 Rep_Item_Too_Late (E, N)
9396 D := Declaration_Node (E);
9399 if (K = N_Full_Type_Declaration
9400 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9402 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9403 and then Nkind (D) = N_Object_Declaration
9404 and then Nkind (Object_Definition (D)) =
9405 N_Constrained_Array_Definition)
9407 Independence_Checks.Append ((N, E));
9410 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9412 end Independent_Components;
9414 ------------------------
9415 -- Initialize_Scalars --
9416 ------------------------
9418 -- pragma Initialize_Scalars;
9420 when Pragma_Initialize_Scalars =>
9422 Check_Arg_Count (0);
9423 Check_Valid_Configuration_Pragma;
9424 Check_Restriction (No_Initialize_Scalars, N);
9426 -- Initialize_Scalars creates false positives in CodePeer,
9427 -- so ignore this pragma in this mode.
9429 if not Restriction_Active (No_Initialize_Scalars)
9430 and then not CodePeer_Mode
9432 Init_Or_Norm_Scalars := True;
9433 Initialize_Scalars := True;
9440 -- pragma Inline ( NAME {, NAME} );
9442 when Pragma_Inline =>
9444 -- Pragma is active if inlining option is active
9446 Process_Inline (Inline_Active);
9452 -- pragma Inline_Always ( NAME {, NAME} );
9454 when Pragma_Inline_Always =>
9457 -- Pragma always active unless in CodePeer mode, since this causes
9458 -- walk order issues.
9460 if not CodePeer_Mode then
9461 Process_Inline (True);
9464 --------------------
9465 -- Inline_Generic --
9466 --------------------
9468 -- pragma Inline_Generic (NAME {, NAME});
9470 when Pragma_Inline_Generic =>
9472 Process_Generic_List;
9474 ----------------------
9475 -- Inspection_Point --
9476 ----------------------
9478 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9480 when Pragma_Inspection_Point => Inspection_Point : declare
9485 if Arg_Count > 0 then
9488 Exp := Get_Pragma_Arg (Arg);
9491 if not Is_Entity_Name (Exp)
9492 or else not Is_Object (Entity (Exp))
9494 Error_Pragma_Arg ("object name required", Arg);
9501 end Inspection_Point;
9507 -- pragma Interface (
9508 -- [ Convention =>] convention_IDENTIFIER,
9509 -- [ Entity =>] local_NAME
9510 -- [, [External_Name =>] static_string_EXPRESSION ]
9511 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9513 when Pragma_Interface =>
9520 Check_At_Least_N_Arguments (2);
9521 Check_At_Most_N_Arguments (4);
9522 Process_Import_Or_Interface;
9524 -- In Ada 2005, the permission to use Interface (a reserved word)
9525 -- as a pragma name is considered an obsolescent feature.
9527 if Ada_Version >= Ada_2005 then
9529 (No_Obsolescent_Features, Pragma_Identifier (N));
9532 --------------------
9533 -- Interface_Name --
9534 --------------------
9536 -- pragma Interface_Name (
9537 -- [ Entity =>] local_NAME
9538 -- [,[External_Name =>] static_string_EXPRESSION ]
9539 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9541 when Pragma_Interface_Name => Interface_Name : declare
9550 ((Name_Entity, Name_External_Name, Name_Link_Name));
9551 Check_At_Least_N_Arguments (2);
9552 Check_At_Most_N_Arguments (3);
9553 Id := Get_Pragma_Arg (Arg1);
9556 if not Is_Entity_Name (Id) then
9558 ("first argument for pragma% must be entity name", Arg1);
9559 elsif Etype (Id) = Any_Type then
9562 Def_Id := Entity (Id);
9565 -- Special DEC-compatible processing for the object case, forces
9566 -- object to be imported.
9568 if Ekind (Def_Id) = E_Variable then
9569 Kill_Size_Check_Code (Def_Id);
9570 Note_Possible_Modification (Id, Sure => False);
9572 -- Initialization is not allowed for imported variable
9574 if Present (Expression (Parent (Def_Id)))
9575 and then Comes_From_Source (Expression (Parent (Def_Id)))
9577 Error_Msg_Sloc := Sloc (Def_Id);
9579 ("no initialization allowed for declaration of& #",
9583 -- For compatibility, support VADS usage of providing both
9584 -- pragmas Interface and Interface_Name to obtain the effect
9585 -- of a single Import pragma.
9587 if Is_Imported (Def_Id)
9588 and then Present (First_Rep_Item (Def_Id))
9589 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9591 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9595 Set_Imported (Def_Id);
9598 Set_Is_Public (Def_Id);
9599 Process_Interface_Name (Def_Id, Arg2, Arg3);
9602 -- Otherwise must be subprogram
9604 elsif not Is_Subprogram (Def_Id) then
9606 ("argument of pragma% is not subprogram", Arg1);
9609 Check_At_Most_N_Arguments (3);
9613 -- Loop through homonyms
9616 Def_Id := Get_Base_Subprogram (Hom_Id);
9618 if Is_Imported (Def_Id) then
9619 Process_Interface_Name (Def_Id, Arg2, Arg3);
9623 exit when From_Aspect_Specification (N);
9624 Hom_Id := Homonym (Hom_Id);
9626 exit when No (Hom_Id)
9627 or else Scope (Hom_Id) /= Current_Scope;
9632 ("argument of pragma% is not imported subprogram",
9638 -----------------------
9639 -- Interrupt_Handler --
9640 -----------------------
9642 -- pragma Interrupt_Handler (handler_NAME);
9644 when Pragma_Interrupt_Handler =>
9645 Check_Ada_83_Warning;
9646 Check_Arg_Count (1);
9647 Check_No_Identifiers;
9649 if No_Run_Time_Mode then
9650 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9652 Check_Interrupt_Or_Attach_Handler;
9653 Process_Interrupt_Or_Attach_Handler;
9656 ------------------------
9657 -- Interrupt_Priority --
9658 ------------------------
9660 -- pragma Interrupt_Priority [(EXPRESSION)];
9662 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9663 P : constant Node_Id := Parent (N);
9667 Check_Ada_83_Warning;
9669 if Arg_Count /= 0 then
9670 Arg := Get_Pragma_Arg (Arg1);
9671 Check_Arg_Count (1);
9672 Check_No_Identifiers;
9674 -- The expression must be analyzed in the special manner
9675 -- described in "Handling of Default and Per-Object
9676 -- Expressions" in sem.ads.
9678 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9681 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9685 elsif Has_Pragma_Priority (P) then
9686 Error_Pragma ("duplicate pragma% not allowed");
9689 Set_Has_Pragma_Priority (P, True);
9690 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9692 end Interrupt_Priority;
9694 ---------------------
9695 -- Interrupt_State --
9696 ---------------------
9698 -- pragma Interrupt_State (
9699 -- [Name =>] INTERRUPT_ID,
9700 -- [State =>] INTERRUPT_STATE);
9702 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9703 -- INTERRUPT_STATE => System | Runtime | User
9705 -- Note: if the interrupt id is given as an identifier, then it must
9706 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9707 -- given as a static integer expression which must be in the range of
9708 -- Ada.Interrupts.Interrupt_ID.
9710 when Pragma_Interrupt_State => Interrupt_State : declare
9712 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9713 -- This is the entity Ada.Interrupts.Interrupt_ID;
9715 State_Type : Character;
9716 -- Set to 's'/'r'/'u' for System/Runtime/User
9719 -- Index to entry in Interrupt_States table
9722 -- Value of interrupt
9724 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9725 -- The first argument to the pragma
9727 Int_Ent : Entity_Id;
9728 -- Interrupt entity in Ada.Interrupts.Names
9732 Check_Arg_Order ((Name_Name, Name_State));
9733 Check_Arg_Count (2);
9735 Check_Optional_Identifier (Arg1, Name_Name);
9736 Check_Optional_Identifier (Arg2, Name_State);
9737 Check_Arg_Is_Identifier (Arg2);
9739 -- First argument is identifier
9741 if Nkind (Arg1X) = N_Identifier then
9743 -- Search list of names in Ada.Interrupts.Names
9745 Int_Ent := First_Entity (RTE (RE_Names));
9747 if No (Int_Ent) then
9748 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9750 elsif Chars (Int_Ent) = Chars (Arg1X) then
9751 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9755 Next_Entity (Int_Ent);
9758 -- First argument is not an identifier, so it must be a static
9759 -- expression of type Ada.Interrupts.Interrupt_ID.
9762 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9763 Int_Val := Expr_Value (Arg1X);
9765 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9767 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9770 ("value not in range of type " &
9771 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9777 case Chars (Get_Pragma_Arg (Arg2)) is
9778 when Name_Runtime => State_Type := 'r';
9779 when Name_System => State_Type := 's';
9780 when Name_User => State_Type := 'u';
9783 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9786 -- Check if entry is already stored
9788 IST_Num := Interrupt_States.First;
9790 -- If entry not found, add it
9792 if IST_Num > Interrupt_States.Last then
9793 Interrupt_States.Append
9794 ((Interrupt_Number => UI_To_Int (Int_Val),
9795 Interrupt_State => State_Type,
9796 Pragma_Loc => Loc));
9799 -- Case of entry for the same entry
9801 elsif Int_Val = Interrupt_States.Table (IST_Num).
9804 -- If state matches, done, no need to make redundant entry
9807 State_Type = Interrupt_States.Table (IST_Num).
9810 -- Otherwise if state does not match, error
9813 Interrupt_States.Table (IST_Num).Pragma_Loc;
9815 ("state conflicts with that given #", Arg2);
9819 IST_Num := IST_Num + 1;
9821 end Interrupt_State;
9828 -- ([Entity =>] type_LOCAL_NAME,
9829 -- [Check =>] EXPRESSION
9830 -- [,[Message =>] String_Expression]);
9832 when Pragma_Invariant => Invariant : declare
9837 pragma Unreferenced (Discard);
9841 Check_At_Least_N_Arguments (2);
9842 Check_At_Most_N_Arguments (3);
9843 Check_Optional_Identifier (Arg1, Name_Entity);
9844 Check_Optional_Identifier (Arg2, Name_Check);
9846 if Arg_Count = 3 then
9847 Check_Optional_Identifier (Arg3, Name_Message);
9848 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9851 Check_Arg_Is_Local_Name (Arg1);
9853 Type_Id := Get_Pragma_Arg (Arg1);
9854 Find_Type (Type_Id);
9855 Typ := Entity (Type_Id);
9857 if Typ = Any_Type then
9860 elsif not Ekind_In (Typ, E_Private_Type,
9861 E_Record_Type_With_Private,
9862 E_Limited_Private_Type)
9865 ("pragma% only allowed for private type", Arg1);
9868 -- Note that the type has at least one invariant, and also that
9869 -- it has inheritable invariants if we have Invariant'Class.
9871 Set_Has_Invariants (Typ);
9873 if Class_Present (N) then
9874 Set_Has_Inheritable_Invariants (Typ);
9877 -- The remaining processing is simply to link the pragma on to
9878 -- the rep item chain, for processing when the type is frozen.
9879 -- This is accomplished by a call to Rep_Item_Too_Late.
9881 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9884 ----------------------
9885 -- Java_Constructor --
9886 ----------------------
9888 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9890 -- Also handles pragma CIL_Constructor
9892 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9893 Java_Constructor : declare
9894 Convention : Convention_Id;
9898 This_Formal : Entity_Id;
9902 Check_Arg_Count (1);
9903 Check_Optional_Identifier (Arg1, Name_Entity);
9904 Check_Arg_Is_Local_Name (Arg1);
9906 Id := Get_Pragma_Arg (Arg1);
9907 Find_Program_Unit_Name (Id);
9909 -- If we did not find the name, we are done
9911 if Etype (Id) = Any_Type then
9915 -- Check wrong use of pragma in wrong VM target
9917 if VM_Target = No_VM then
9920 elsif VM_Target = CLI_Target
9921 and then Prag_Id = Pragma_Java_Constructor
9923 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9925 elsif VM_Target = JVM_Target
9926 and then Prag_Id = Pragma_CIL_Constructor
9928 Error_Pragma ("must use pragma 'Java_'Constructor");
9932 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9933 when Pragma_Java_Constructor => Convention := Convention_Java;
9934 when others => null;
9937 Hom_Id := Entity (Id);
9939 -- Loop through homonyms
9942 Def_Id := Get_Base_Subprogram (Hom_Id);
9944 -- The constructor is required to be a function
9946 if Ekind (Def_Id) /= E_Function then
9947 if VM_Target = JVM_Target then
9949 ("pragma% requires function returning a " &
9950 "'Java access type", Def_Id);
9953 ("pragma% requires function returning a " &
9954 "'C'I'L access type", Def_Id);
9958 -- Check arguments: For tagged type the first formal must be
9959 -- named "this" and its type must be a named access type
9960 -- designating a class-wide tagged type that has convention
9961 -- CIL/Java. The first formal must also have a null default
9962 -- value. For example:
9964 -- type Typ is tagged ...
9965 -- type Ref is access all Typ;
9966 -- pragma Convention (CIL, Typ);
9968 -- function New_Typ (This : Ref) return Ref;
9969 -- function New_Typ (This : Ref; I : Integer) return Ref;
9970 -- pragma Cil_Constructor (New_Typ);
9972 -- Reason: The first formal must NOT be a primitive of the
9975 -- This rule also applies to constructors of delegates used
9976 -- to interface with standard target libraries. For example:
9978 -- type Delegate is access procedure ...
9979 -- pragma Import (CIL, Delegate, ...);
9981 -- function new_Delegate
9982 -- (This : Delegate := null; ... ) return Delegate;
9984 -- For value-types this rule does not apply.
9986 if not Is_Value_Type (Etype (Def_Id)) then
9987 if No (First_Formal (Def_Id)) then
9988 Error_Msg_Name_1 := Pname;
9989 Error_Msg_N ("% function must have parameters", Def_Id);
9993 -- In the JRE library we have several occurrences in which
9994 -- the "this" parameter is not the first formal.
9996 This_Formal := First_Formal (Def_Id);
9998 -- In the JRE library we have several occurrences in which
9999 -- the "this" parameter is not the first formal. Search for
10002 if VM_Target = JVM_Target then
10003 while Present (This_Formal)
10004 and then Get_Name_String (Chars (This_Formal)) /= "this"
10006 Next_Formal (This_Formal);
10009 if No (This_Formal) then
10010 This_Formal := First_Formal (Def_Id);
10014 -- Warning: The first parameter should be named "this".
10015 -- We temporarily allow it because we have the following
10016 -- case in the Java runtime (file s-osinte.ads) ???
10018 -- function new_Thread
10019 -- (Self_Id : System.Address) return Thread_Id;
10020 -- pragma Java_Constructor (new_Thread);
10022 if VM_Target = JVM_Target
10023 and then Get_Name_String (Chars (First_Formal (Def_Id)))
10025 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10029 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10030 Error_Msg_Name_1 := Pname;
10032 ("first formal of % function must be named `this`",
10033 Parent (This_Formal));
10035 elsif not Is_Access_Type (Etype (This_Formal)) then
10036 Error_Msg_Name_1 := Pname;
10038 ("first formal of % function must be an access type",
10039 Parameter_Type (Parent (This_Formal)));
10041 -- For delegates the type of the first formal must be a
10042 -- named access-to-subprogram type (see previous example)
10044 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10045 and then Ekind (Etype (This_Formal))
10046 /= E_Access_Subprogram_Type
10048 Error_Msg_Name_1 := Pname;
10050 ("first formal of % function must be a named access" &
10051 " to subprogram type",
10052 Parameter_Type (Parent (This_Formal)));
10054 -- Warning: We should reject anonymous access types because
10055 -- the constructor must not be handled as a primitive of the
10056 -- tagged type. We temporarily allow it because this profile
10057 -- is currently generated by cil2ada???
10059 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10060 and then not Ekind_In (Etype (This_Formal),
10062 E_General_Access_Type,
10063 E_Anonymous_Access_Type)
10065 Error_Msg_Name_1 := Pname;
10067 ("first formal of % function must be a named access" &
10069 Parameter_Type (Parent (This_Formal)));
10071 elsif Atree.Convention
10072 (Designated_Type (Etype (This_Formal))) /= Convention
10074 Error_Msg_Name_1 := Pname;
10076 if Convention = Convention_Java then
10078 ("pragma% requires convention 'Cil in designated" &
10080 Parameter_Type (Parent (This_Formal)));
10083 ("pragma% requires convention 'Java in designated" &
10085 Parameter_Type (Parent (This_Formal)));
10088 elsif No (Expression (Parent (This_Formal)))
10089 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10091 Error_Msg_Name_1 := Pname;
10093 ("pragma% requires first formal with default `null`",
10094 Parameter_Type (Parent (This_Formal)));
10098 -- Check result type: the constructor must be a function
10100 -- * a value type (only allowed in the CIL compiler)
10101 -- * an access-to-subprogram type with convention Java/CIL
10102 -- * an access-type designating a type that has convention
10105 if Is_Value_Type (Etype (Def_Id)) then
10108 -- Access-to-subprogram type with convention Java/CIL
10110 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10111 if Atree.Convention (Etype (Def_Id)) /= Convention then
10112 if Convention = Convention_Java then
10114 ("pragma% requires function returning a " &
10115 "'Java access type", Arg1);
10117 pragma Assert (Convention = Convention_CIL);
10119 ("pragma% requires function returning a " &
10120 "'C'I'L access type", Arg1);
10124 elsif Ekind (Etype (Def_Id)) in Access_Kind then
10125 if not Ekind_In (Etype (Def_Id), E_Access_Type,
10126 E_General_Access_Type)
10129 (Designated_Type (Etype (Def_Id))) /= Convention
10131 Error_Msg_Name_1 := Pname;
10133 if Convention = Convention_Java then
10135 ("pragma% requires function returning a named" &
10136 "'Java access type", Arg1);
10139 ("pragma% requires function returning a named" &
10140 "'C'I'L access type", Arg1);
10145 Set_Is_Constructor (Def_Id);
10146 Set_Convention (Def_Id, Convention);
10147 Set_Is_Imported (Def_Id);
10149 exit when From_Aspect_Specification (N);
10150 Hom_Id := Homonym (Hom_Id);
10152 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10154 end Java_Constructor;
10156 ----------------------
10157 -- Java_Interface --
10158 ----------------------
10160 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
10162 when Pragma_Java_Interface => Java_Interface : declare
10168 Check_Arg_Count (1);
10169 Check_Optional_Identifier (Arg1, Name_Entity);
10170 Check_Arg_Is_Local_Name (Arg1);
10172 Arg := Get_Pragma_Arg (Arg1);
10175 if Etype (Arg) = Any_Type then
10179 if not Is_Entity_Name (Arg)
10180 or else not Is_Type (Entity (Arg))
10182 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10185 Typ := Underlying_Type (Entity (Arg));
10187 -- For now simply check some of the semantic constraints on the
10188 -- type. This currently leaves out some restrictions on interface
10189 -- types, namely that the parent type must be java.lang.Object.Typ
10190 -- and that all primitives of the type should be declared
10193 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10194 Error_Pragma_Arg ("pragma% requires an abstract "
10195 & "tagged type", Arg1);
10197 elsif not Has_Discriminants (Typ)
10198 or else Ekind (Etype (First_Discriminant (Typ)))
10199 /= E_Anonymous_Access_Type
10201 not Is_Class_Wide_Type
10202 (Designated_Type (Etype (First_Discriminant (Typ))))
10205 ("type must have a class-wide access discriminant", Arg1);
10207 end Java_Interface;
10213 -- pragma Keep_Names ([On => ] local_NAME);
10215 when Pragma_Keep_Names => Keep_Names : declare
10220 Check_Arg_Count (1);
10221 Check_Optional_Identifier (Arg1, Name_On);
10222 Check_Arg_Is_Local_Name (Arg1);
10224 Arg := Get_Pragma_Arg (Arg1);
10227 if Etype (Arg) = Any_Type then
10231 if not Is_Entity_Name (Arg)
10232 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10235 ("pragma% requires a local enumeration type", Arg1);
10238 Set_Discard_Names (Entity (Arg), False);
10245 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10247 when Pragma_License =>
10249 Check_Arg_Count (1);
10250 Check_No_Identifiers;
10251 Check_Valid_Configuration_Pragma;
10252 Check_Arg_Is_Identifier (Arg1);
10255 Sind : constant Source_File_Index :=
10256 Source_Index (Current_Sem_Unit);
10259 case Chars (Get_Pragma_Arg (Arg1)) is
10261 Set_License (Sind, GPL);
10263 when Name_Modified_GPL =>
10264 Set_License (Sind, Modified_GPL);
10266 when Name_Restricted =>
10267 Set_License (Sind, Restricted);
10269 when Name_Unrestricted =>
10270 Set_License (Sind, Unrestricted);
10273 Error_Pragma_Arg ("invalid license name", Arg1);
10281 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10283 when Pragma_Link_With => Link_With : declare
10289 if Operating_Mode = Generate_Code
10290 and then In_Extended_Main_Source_Unit (N)
10292 Check_At_Least_N_Arguments (1);
10293 Check_No_Identifiers;
10294 Check_Is_In_Decl_Part_Or_Package_Spec;
10295 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10299 while Present (Arg) loop
10300 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10302 -- Store argument, converting sequences of spaces to a
10303 -- single null character (this is one of the differences
10304 -- in processing between Link_With and Linker_Options).
10306 Arg_Store : declare
10307 C : constant Char_Code := Get_Char_Code (' ');
10308 S : constant String_Id :=
10309 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10310 L : constant Nat := String_Length (S);
10313 procedure Skip_Spaces;
10314 -- Advance F past any spaces
10320 procedure Skip_Spaces is
10322 while F <= L and then Get_String_Char (S, F) = C loop
10327 -- Start of processing for Arg_Store
10330 Skip_Spaces; -- skip leading spaces
10332 -- Loop through characters, changing any embedded
10333 -- sequence of spaces to a single null character (this
10334 -- is how Link_With/Linker_Options differ)
10337 if Get_String_Char (S, F) = C then
10340 Store_String_Char (ASCII.NUL);
10343 Store_String_Char (Get_String_Char (S, F));
10351 if Present (Arg) then
10352 Store_String_Char (ASCII.NUL);
10356 Store_Linker_Option_String (End_String);
10364 -- pragma Linker_Alias (
10365 -- [Entity =>] LOCAL_NAME
10366 -- [Target =>] static_string_EXPRESSION);
10368 when Pragma_Linker_Alias =>
10370 Check_Arg_Order ((Name_Entity, Name_Target));
10371 Check_Arg_Count (2);
10372 Check_Optional_Identifier (Arg1, Name_Entity);
10373 Check_Optional_Identifier (Arg2, Name_Target);
10374 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10375 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10377 -- The only processing required is to link this item on to the
10378 -- list of rep items for the given entity. This is accomplished
10379 -- by the call to Rep_Item_Too_Late (when no error is detected
10380 -- and False is returned).
10382 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10385 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10388 ------------------------
10389 -- Linker_Constructor --
10390 ------------------------
10392 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10394 -- Code is shared with Linker_Destructor
10396 -----------------------
10397 -- Linker_Destructor --
10398 -----------------------
10400 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10402 when Pragma_Linker_Constructor |
10403 Pragma_Linker_Destructor =>
10404 Linker_Constructor : declare
10410 Check_Arg_Count (1);
10411 Check_No_Identifiers;
10412 Check_Arg_Is_Local_Name (Arg1);
10413 Arg1_X := Get_Pragma_Arg (Arg1);
10415 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10417 if not Is_Library_Level_Entity (Proc) then
10419 ("argument for pragma% must be library level entity", Arg1);
10422 -- The only processing required is to link this item on to the
10423 -- list of rep items for the given entity. This is accomplished
10424 -- by the call to Rep_Item_Too_Late (when no error is detected
10425 -- and False is returned).
10427 if Rep_Item_Too_Late (Proc, N) then
10430 Set_Has_Gigi_Rep_Item (Proc);
10432 end Linker_Constructor;
10434 --------------------
10435 -- Linker_Options --
10436 --------------------
10438 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10440 when Pragma_Linker_Options => Linker_Options : declare
10444 Check_Ada_83_Warning;
10445 Check_No_Identifiers;
10446 Check_Arg_Count (1);
10447 Check_Is_In_Decl_Part_Or_Package_Spec;
10448 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10449 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10452 while Present (Arg) loop
10453 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10454 Store_String_Char (ASCII.NUL);
10456 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10460 if Operating_Mode = Generate_Code
10461 and then In_Extended_Main_Source_Unit (N)
10463 Store_Linker_Option_String (End_String);
10465 end Linker_Options;
10467 --------------------
10468 -- Linker_Section --
10469 --------------------
10471 -- pragma Linker_Section (
10472 -- [Entity =>] LOCAL_NAME
10473 -- [Section =>] static_string_EXPRESSION);
10475 when Pragma_Linker_Section =>
10477 Check_Arg_Order ((Name_Entity, Name_Section));
10478 Check_Arg_Count (2);
10479 Check_Optional_Identifier (Arg1, Name_Entity);
10480 Check_Optional_Identifier (Arg2, Name_Section);
10481 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10482 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10484 -- This pragma applies only to objects
10486 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10487 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10490 -- The only processing required is to link this item on to the
10491 -- list of rep items for the given entity. This is accomplished
10492 -- by the call to Rep_Item_Too_Late (when no error is detected
10493 -- and False is returned).
10495 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10498 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10505 -- pragma List (On | Off)
10507 -- There is nothing to do here, since we did all the processing for
10508 -- this pragma in Par.Prag (so that it works properly even in syntax
10511 when Pragma_List =>
10514 --------------------
10515 -- Locking_Policy --
10516 --------------------
10518 -- pragma Locking_Policy (policy_IDENTIFIER);
10520 when Pragma_Locking_Policy => declare
10524 Check_Ada_83_Warning;
10525 Check_Arg_Count (1);
10526 Check_No_Identifiers;
10527 Check_Arg_Is_Locking_Policy (Arg1);
10528 Check_Valid_Configuration_Pragma;
10529 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10530 LP := Fold_Upper (Name_Buffer (1));
10532 if Locking_Policy /= ' '
10533 and then Locking_Policy /= LP
10535 Error_Msg_Sloc := Locking_Policy_Sloc;
10536 Error_Pragma ("locking policy incompatible with policy#");
10538 -- Set new policy, but always preserve System_Location since we
10539 -- like the error message with the run time name.
10542 Locking_Policy := LP;
10544 if Locking_Policy_Sloc /= System_Location then
10545 Locking_Policy_Sloc := Loc;
10554 -- pragma Long_Float (D_Float | G_Float);
10556 when Pragma_Long_Float =>
10558 Check_Valid_Configuration_Pragma;
10559 Check_Arg_Count (1);
10560 Check_No_Identifier (Arg1);
10561 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10563 if not OpenVMS_On_Target then
10564 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10569 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10570 if Opt.Float_Format_Long = 'G' then
10571 Error_Pragma ("G_Float previously specified");
10574 Opt.Float_Format_Long := 'D';
10576 -- G_Float case (this is the default, does not need overriding)
10579 if Opt.Float_Format_Long = 'D' then
10580 Error_Pragma ("D_Float previously specified");
10583 Opt.Float_Format_Long := 'G';
10586 Set_Standard_Fpt_Formats;
10588 -----------------------
10589 -- Machine_Attribute --
10590 -----------------------
10592 -- pragma Machine_Attribute (
10593 -- [Entity =>] LOCAL_NAME,
10594 -- [Attribute_Name =>] static_string_EXPRESSION
10595 -- [, [Info =>] static_EXPRESSION] );
10597 when Pragma_Machine_Attribute => Machine_Attribute : declare
10598 Def_Id : Entity_Id;
10602 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10604 if Arg_Count = 3 then
10605 Check_Optional_Identifier (Arg3, Name_Info);
10606 Check_Arg_Is_Static_Expression (Arg3);
10608 Check_Arg_Count (2);
10611 Check_Optional_Identifier (Arg1, Name_Entity);
10612 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10613 Check_Arg_Is_Local_Name (Arg1);
10614 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10615 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10617 if Is_Access_Type (Def_Id) then
10618 Def_Id := Designated_Type (Def_Id);
10621 if Rep_Item_Too_Early (Def_Id, N) then
10625 Def_Id := Underlying_Type (Def_Id);
10627 -- The only processing required is to link this item on to the
10628 -- list of rep items for the given entity. This is accomplished
10629 -- by the call to Rep_Item_Too_Late (when no error is detected
10630 -- and False is returned).
10632 if Rep_Item_Too_Late (Def_Id, N) then
10635 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10637 end Machine_Attribute;
10644 -- (MAIN_OPTION [, MAIN_OPTION]);
10647 -- [STACK_SIZE =>] static_integer_EXPRESSION
10648 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10649 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10651 when Pragma_Main => Main : declare
10652 Args : Args_List (1 .. 3);
10653 Names : constant Name_List (1 .. 3) := (
10655 Name_Task_Stack_Size_Default,
10656 Name_Time_Slicing_Enabled);
10662 Gather_Associations (Names, Args);
10664 for J in 1 .. 2 loop
10665 if Present (Args (J)) then
10666 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10670 if Present (Args (3)) then
10671 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10675 while Present (Nod) loop
10676 if Nkind (Nod) = N_Pragma
10677 and then Pragma_Name (Nod) = Name_Main
10679 Error_Msg_Name_1 := Pname;
10680 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10691 -- pragma Main_Storage
10692 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10694 -- MAIN_STORAGE_OPTION ::=
10695 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10696 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10698 when Pragma_Main_Storage => Main_Storage : declare
10699 Args : Args_List (1 .. 2);
10700 Names : constant Name_List (1 .. 2) := (
10701 Name_Working_Storage,
10708 Gather_Associations (Names, Args);
10710 for J in 1 .. 2 loop
10711 if Present (Args (J)) then
10712 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10716 Check_In_Main_Program;
10719 while Present (Nod) loop
10720 if Nkind (Nod) = N_Pragma
10721 and then Pragma_Name (Nod) = Name_Main_Storage
10723 Error_Msg_Name_1 := Pname;
10724 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10735 -- pragma Memory_Size (NUMERIC_LITERAL)
10737 when Pragma_Memory_Size =>
10740 -- Memory size is simply ignored
10742 Check_No_Identifiers;
10743 Check_Arg_Count (1);
10744 Check_Arg_Is_Integer_Literal (Arg1);
10752 -- The only correct use of this pragma is on its own in a file, in
10753 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10754 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10755 -- check for a file containing nothing but a No_Body pragma). If we
10756 -- attempt to process it during normal semantics processing, it means
10757 -- it was misplaced.
10759 when Pragma_No_Body =>
10767 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10769 when Pragma_No_Return => No_Return : declare
10777 Check_At_Least_N_Arguments (1);
10779 -- Loop through arguments of pragma
10782 while Present (Arg) loop
10783 Check_Arg_Is_Local_Name (Arg);
10784 Id := Get_Pragma_Arg (Arg);
10787 if not Is_Entity_Name (Id) then
10788 Error_Pragma_Arg ("entity name required", Arg);
10791 if Etype (Id) = Any_Type then
10795 -- Loop to find matching procedures
10800 and then Scope (E) = Current_Scope
10802 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10805 -- Set flag on any alias as well
10807 if Is_Overloadable (E) and then Present (Alias (E)) then
10808 Set_No_Return (Alias (E));
10814 exit when From_Aspect_Specification (N);
10819 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10830 -- pragma No_Run_Time;
10832 -- Note: this pragma is retained for backwards compatibility. See
10833 -- body of Rtsfind for full details on its handling.
10835 when Pragma_No_Run_Time =>
10837 Check_Valid_Configuration_Pragma;
10838 Check_Arg_Count (0);
10840 No_Run_Time_Mode := True;
10841 Configurable_Run_Time_Mode := True;
10843 -- Set Duration to 32 bits if word size is 32
10845 if Ttypes.System_Word_Size = 32 then
10846 Duration_32_Bits_On_Target := True;
10849 -- Set appropriate restrictions
10851 Set_Restriction (No_Finalization, N);
10852 Set_Restriction (No_Exception_Handlers, N);
10853 Set_Restriction (Max_Tasks, N, 0);
10854 Set_Restriction (No_Tasking, N);
10856 ------------------------
10857 -- No_Strict_Aliasing --
10858 ------------------------
10860 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10862 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10867 Check_At_Most_N_Arguments (1);
10869 if Arg_Count = 0 then
10870 Check_Valid_Configuration_Pragma;
10871 Opt.No_Strict_Aliasing := True;
10874 Check_Optional_Identifier (Arg2, Name_Entity);
10875 Check_Arg_Is_Local_Name (Arg1);
10876 E_Id := Entity (Get_Pragma_Arg (Arg1));
10878 if E_Id = Any_Type then
10880 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10881 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10884 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10886 end No_Strict_Aliasing;
10888 -----------------------
10889 -- Normalize_Scalars --
10890 -----------------------
10892 -- pragma Normalize_Scalars;
10894 when Pragma_Normalize_Scalars =>
10895 Check_Ada_83_Warning;
10896 Check_Arg_Count (0);
10897 Check_Valid_Configuration_Pragma;
10899 -- Normalize_Scalars creates false positives in CodePeer, so
10900 -- ignore this pragma in this mode.
10902 if not CodePeer_Mode then
10903 Normalize_Scalars := True;
10904 Init_Or_Norm_Scalars := True;
10911 -- pragma Obsolescent;
10913 -- pragma Obsolescent (
10914 -- [Message =>] static_string_EXPRESSION
10915 -- [,[Version =>] Ada_05]]);
10917 -- pragma Obsolescent (
10918 -- [Entity =>] NAME
10919 -- [,[Message =>] static_string_EXPRESSION
10920 -- [,[Version =>] Ada_05]] );
10922 when Pragma_Obsolescent => Obsolescent : declare
10926 procedure Set_Obsolescent (E : Entity_Id);
10927 -- Given an entity Ent, mark it as obsolescent if appropriate
10929 ---------------------
10930 -- Set_Obsolescent --
10931 ---------------------
10933 procedure Set_Obsolescent (E : Entity_Id) is
10942 -- Entity name was given
10944 if Present (Ename) then
10946 -- If entity name matches, we are fine. Save entity in
10947 -- pragma argument, for ASIS use.
10949 if Chars (Ename) = Chars (Ent) then
10950 Set_Entity (Ename, Ent);
10951 Generate_Reference (Ent, Ename);
10953 -- If entity name does not match, only possibility is an
10954 -- enumeration literal from an enumeration type declaration.
10956 elsif Ekind (Ent) /= E_Enumeration_Type then
10958 ("pragma % entity name does not match declaration");
10961 Ent := First_Literal (E);
10965 ("pragma % entity name does not match any " &
10966 "enumeration literal");
10968 elsif Chars (Ent) = Chars (Ename) then
10969 Set_Entity (Ename, Ent);
10970 Generate_Reference (Ent, Ename);
10974 Ent := Next_Literal (Ent);
10980 -- Ent points to entity to be marked
10982 if Arg_Count >= 1 then
10984 -- Deal with static string argument
10986 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10987 S := Strval (Get_Pragma_Arg (Arg1));
10989 for J in 1 .. String_Length (S) loop
10990 if not In_Character_Range (Get_String_Char (S, J)) then
10992 ("pragma% argument does not allow wide characters",
10997 Obsolescent_Warnings.Append
10998 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11000 -- Check for Ada_05 parameter
11002 if Arg_Count /= 1 then
11003 Check_Arg_Count (2);
11006 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11009 Check_Arg_Is_Identifier (Argx);
11011 if Chars (Argx) /= Name_Ada_05 then
11012 Error_Msg_Name_2 := Name_Ada_05;
11014 ("only allowed argument for pragma% is %", Argx);
11017 if Ada_Version_Explicit < Ada_2005
11018 or else not Warn_On_Ada_2005_Compatibility
11026 -- Set flag if pragma active
11029 Set_Is_Obsolescent (Ent);
11033 end Set_Obsolescent;
11035 -- Start of processing for pragma Obsolescent
11040 Check_At_Most_N_Arguments (3);
11042 -- See if first argument specifies an entity name
11046 (Chars (Arg1) = Name_Entity
11048 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11050 N_Operator_Symbol))
11052 Ename := Get_Pragma_Arg (Arg1);
11054 -- Eliminate first argument, so we can share processing
11058 Arg_Count := Arg_Count - 1;
11060 -- No Entity name argument given
11066 if Arg_Count >= 1 then
11067 Check_Optional_Identifier (Arg1, Name_Message);
11069 if Arg_Count = 2 then
11070 Check_Optional_Identifier (Arg2, Name_Version);
11074 -- Get immediately preceding declaration
11077 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11081 -- Cases where we do not follow anything other than another pragma
11085 -- First case: library level compilation unit declaration with
11086 -- the pragma immediately following the declaration.
11088 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11090 (Defining_Entity (Unit (Parent (Parent (N)))));
11093 -- Case 2: library unit placement for package
11097 Ent : constant Entity_Id := Find_Lib_Unit_Name;
11099 if Is_Package_Or_Generic_Package (Ent) then
11100 Set_Obsolescent (Ent);
11106 -- Cases where we must follow a declaration
11109 if Nkind (Decl) not in N_Declaration
11110 and then Nkind (Decl) not in N_Later_Decl_Item
11111 and then Nkind (Decl) not in N_Generic_Declaration
11112 and then Nkind (Decl) not in N_Renaming_Declaration
11115 ("pragma% misplaced, "
11116 & "must immediately follow a declaration");
11119 Set_Obsolescent (Defining_Entity (Decl));
11129 -- pragma Optimize (Time | Space | Off);
11131 -- The actual check for optimize is done in Gigi. Note that this
11132 -- pragma does not actually change the optimization setting, it
11133 -- simply checks that it is consistent with the pragma.
11135 when Pragma_Optimize =>
11136 Check_No_Identifiers;
11137 Check_Arg_Count (1);
11138 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11140 ------------------------
11141 -- Optimize_Alignment --
11142 ------------------------
11144 -- pragma Optimize_Alignment (Time | Space | Off);
11146 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11148 Check_No_Identifiers;
11149 Check_Arg_Count (1);
11150 Check_Valid_Configuration_Pragma;
11153 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11157 Opt.Optimize_Alignment := 'T';
11159 Opt.Optimize_Alignment := 'S';
11161 Opt.Optimize_Alignment := 'O';
11163 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11167 -- Set indication that mode is set locally. If we are in fact in a
11168 -- configuration pragma file, this setting is harmless since the
11169 -- switch will get reset anyway at the start of each unit.
11171 Optimize_Alignment_Local := True;
11172 end Optimize_Alignment;
11178 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11180 when Pragma_Ordered => Ordered : declare
11181 Assoc : constant Node_Id := Arg1;
11187 Check_No_Identifiers;
11188 Check_Arg_Count (1);
11189 Check_Arg_Is_Local_Name (Arg1);
11191 Type_Id := Get_Pragma_Arg (Assoc);
11192 Find_Type (Type_Id);
11193 Typ := Entity (Type_Id);
11195 if Typ = Any_Type then
11198 Typ := Underlying_Type (Typ);
11201 if not Is_Enumeration_Type (Typ) then
11202 Error_Pragma ("pragma% must specify enumeration type");
11205 Check_First_Subtype (Arg1);
11206 Set_Has_Pragma_Ordered (Base_Type (Typ));
11213 -- pragma Pack (first_subtype_LOCAL_NAME);
11215 when Pragma_Pack => Pack : declare
11216 Assoc : constant Node_Id := Arg1;
11220 Ignore : Boolean := False;
11223 Check_No_Identifiers;
11224 Check_Arg_Count (1);
11225 Check_Arg_Is_Local_Name (Arg1);
11227 Type_Id := Get_Pragma_Arg (Assoc);
11228 Find_Type (Type_Id);
11229 Typ := Entity (Type_Id);
11232 or else Rep_Item_Too_Early (Typ, N)
11236 Typ := Underlying_Type (Typ);
11239 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11240 Error_Pragma ("pragma% must specify array or record type");
11243 Check_First_Subtype (Arg1);
11244 Check_Duplicate_Pragma (Typ);
11248 if Is_Array_Type (Typ) then
11249 Ctyp := Component_Type (Typ);
11251 -- Ignore pack that does nothing
11253 if Known_Static_Esize (Ctyp)
11254 and then Known_Static_RM_Size (Ctyp)
11255 and then Esize (Ctyp) = RM_Size (Ctyp)
11256 and then Addressable (Esize (Ctyp))
11261 -- Process OK pragma Pack. Note that if there is a separate
11262 -- component clause present, the Pack will be cancelled. This
11263 -- processing is in Freeze.
11265 if not Rep_Item_Too_Late (Typ, N) then
11267 -- In the context of static code analysis, we do not need
11268 -- complex front-end expansions related to pragma Pack,
11269 -- so disable handling of pragma Pack in this case.
11271 if CodePeer_Mode then
11274 -- Don't attempt any packing for VM targets. We possibly
11275 -- could deal with some cases of array bit-packing, but we
11276 -- don't bother, since this is not a typical kind of
11277 -- representation in the VM context anyway (and would not
11278 -- for example work nicely with the debugger).
11280 elsif VM_Target /= No_VM then
11281 if not GNAT_Mode then
11283 ("?pragma% ignored in this configuration");
11286 -- Normal case where we do the pack action
11290 Set_Is_Packed (Base_Type (Typ));
11291 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11294 Set_Has_Pragma_Pack (Base_Type (Typ));
11298 -- For record types, the pack is always effective
11300 else pragma Assert (Is_Record_Type (Typ));
11301 if not Rep_Item_Too_Late (Typ, N) then
11303 -- Ignore pack request with warning in VM mode (skip warning
11304 -- if we are compiling GNAT run time library).
11306 if VM_Target /= No_VM then
11307 if not GNAT_Mode then
11309 ("?pragma% ignored in this configuration");
11312 -- Normal case of pack request active
11315 Set_Is_Packed (Base_Type (Typ));
11316 Set_Has_Pragma_Pack (Base_Type (Typ));
11317 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11329 -- There is nothing to do here, since we did all the processing for
11330 -- this pragma in Par.Prag (so that it works properly even in syntax
11333 when Pragma_Page =>
11340 -- pragma Passive [(PASSIVE_FORM)];
11342 -- PASSIVE_FORM ::= Semaphore | No
11344 when Pragma_Passive =>
11347 if Nkind (Parent (N)) /= N_Task_Definition then
11348 Error_Pragma ("pragma% must be within task definition");
11351 if Arg_Count /= 0 then
11352 Check_Arg_Count (1);
11353 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11356 ----------------------------------
11357 -- Preelaborable_Initialization --
11358 ----------------------------------
11360 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11362 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11367 Check_Arg_Count (1);
11368 Check_No_Identifiers;
11369 Check_Arg_Is_Identifier (Arg1);
11370 Check_Arg_Is_Local_Name (Arg1);
11371 Check_First_Subtype (Arg1);
11372 Ent := Entity (Get_Pragma_Arg (Arg1));
11374 if not (Is_Private_Type (Ent)
11376 Is_Protected_Type (Ent)
11378 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11381 ("pragma % can only be applied to private, formal derived or "
11382 & "protected type",
11386 -- Give an error if the pragma is applied to a protected type that
11387 -- does not qualify (due to having entries, or due to components
11388 -- that do not qualify).
11390 if Is_Protected_Type (Ent)
11391 and then not Has_Preelaborable_Initialization (Ent)
11394 ("protected type & does not have preelaborable " &
11395 "initialization", Ent);
11397 -- Otherwise mark the type as definitely having preelaborable
11401 Set_Known_To_Have_Preelab_Init (Ent);
11404 if Has_Pragma_Preelab_Init (Ent)
11405 and then Warn_On_Redundant_Constructs
11407 Error_Pragma ("?duplicate pragma%!");
11409 Set_Has_Pragma_Preelab_Init (Ent);
11413 --------------------
11414 -- Persistent_BSS --
11415 --------------------
11417 -- pragma Persistent_BSS [(object_NAME)];
11419 when Pragma_Persistent_BSS => Persistent_BSS : declare
11426 Check_At_Most_N_Arguments (1);
11428 -- Case of application to specific object (one argument)
11430 if Arg_Count = 1 then
11431 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11433 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11435 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11438 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11441 Ent := Entity (Get_Pragma_Arg (Arg1));
11442 Decl := Parent (Ent);
11444 if Rep_Item_Too_Late (Ent, N) then
11448 if Present (Expression (Decl)) then
11450 ("object for pragma% cannot have initialization", Arg1);
11453 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11455 ("object type for pragma% is not potentially persistent",
11459 Check_Duplicate_Pragma (Ent);
11462 Make_Linker_Section_Pragma
11463 (Ent, Sloc (N), ".persistent.bss");
11464 Insert_After (N, Prag);
11467 -- Case of use as configuration pragma with no arguments
11470 Check_Valid_Configuration_Pragma;
11471 Persistent_BSS_Mode := True;
11473 end Persistent_BSS;
11479 -- pragma Polling (ON | OFF);
11481 when Pragma_Polling =>
11483 Check_Arg_Count (1);
11484 Check_No_Identifiers;
11485 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11486 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11488 -------------------
11489 -- Postcondition --
11490 -------------------
11492 -- pragma Postcondition ([Check =>] Boolean_Expression
11493 -- [,[Message =>] String_Expression]);
11495 when Pragma_Postcondition => Postcondition : declare
11497 pragma Warnings (Off, In_Body);
11501 Check_At_Least_N_Arguments (1);
11502 Check_At_Most_N_Arguments (2);
11503 Check_Optional_Identifier (Arg1, Name_Check);
11505 -- All we need to do here is call the common check procedure,
11506 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11508 Check_Precondition_Postcondition (In_Body);
11515 -- pragma Precondition ([Check =>] Boolean_Expression
11516 -- [,[Message =>] String_Expression]);
11518 when Pragma_Precondition => Precondition : declare
11523 Check_At_Least_N_Arguments (1);
11524 Check_At_Most_N_Arguments (2);
11525 Check_Optional_Identifier (Arg1, Name_Check);
11526 Check_Precondition_Postcondition (In_Body);
11528 -- If in spec, nothing more to do. If in body, then we convert the
11529 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11530 -- this whether or not precondition checks are enabled. That works
11531 -- fine since pragma Check will do this check, and will also
11532 -- analyze the condition itself in the proper context.
11537 Chars => Name_Check,
11538 Pragma_Argument_Associations => New_List (
11539 Make_Pragma_Argument_Association (Loc,
11540 Expression => Make_Identifier (Loc, Name_Precondition)),
11542 Make_Pragma_Argument_Association (Sloc (Arg1),
11543 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11545 if Arg_Count = 2 then
11546 Append_To (Pragma_Argument_Associations (N),
11547 Make_Pragma_Argument_Association (Sloc (Arg2),
11548 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11559 -- pragma Predicate
11560 -- ([Entity =>] type_LOCAL_NAME,
11561 -- [Check =>] EXPRESSION);
11563 when Pragma_Predicate => Predicate : declare
11568 pragma Unreferenced (Discard);
11572 Check_Arg_Count (2);
11573 Check_Optional_Identifier (Arg1, Name_Entity);
11574 Check_Optional_Identifier (Arg2, Name_Check);
11576 Check_Arg_Is_Local_Name (Arg1);
11578 Type_Id := Get_Pragma_Arg (Arg1);
11579 Find_Type (Type_Id);
11580 Typ := Entity (Type_Id);
11582 if Typ = Any_Type then
11586 -- The remaining processing is simply to link the pragma on to
11587 -- the rep item chain, for processing when the type is frozen.
11588 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11589 -- mark the type as having predicates.
11591 Set_Has_Predicates (Typ);
11592 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11599 -- pragma Preelaborate [(library_unit_NAME)];
11601 -- Set the flag Is_Preelaborated of program unit name entity
11603 when Pragma_Preelaborate => Preelaborate : declare
11604 Pa : constant Node_Id := Parent (N);
11605 Pk : constant Node_Kind := Nkind (Pa);
11609 Check_Ada_83_Warning;
11610 Check_Valid_Library_Unit_Pragma;
11612 if Nkind (N) = N_Null_Statement then
11616 Ent := Find_Lib_Unit_Name;
11617 Check_Duplicate_Pragma (Ent);
11619 -- This filters out pragmas inside generic parent then
11620 -- show up inside instantiation
11623 and then not (Pk = N_Package_Specification
11624 and then Present (Generic_Parent (Pa)))
11626 if not Debug_Flag_U then
11627 Set_Is_Preelaborated (Ent);
11628 Set_Suppress_Elaboration_Warnings (Ent);
11633 ---------------------
11634 -- Preelaborate_05 --
11635 ---------------------
11637 -- pragma Preelaborate_05 [(library_unit_NAME)];
11639 -- This pragma is useable only in GNAT_Mode, where it is used like
11640 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11641 -- (otherwise it is ignored). This is used to implement AI-362 which
11642 -- recategorizes some run-time packages in Ada 2005 mode.
11644 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11649 Check_Valid_Library_Unit_Pragma;
11651 if not GNAT_Mode then
11652 Error_Pragma ("pragma% only available in GNAT mode");
11655 if Nkind (N) = N_Null_Statement then
11659 -- This is one of the few cases where we need to test the value of
11660 -- Ada_Version_Explicit rather than Ada_Version (which is always
11661 -- set to Ada_2012 in a predefined unit), we need to know the
11662 -- explicit version set to know if this pragma is active.
11664 if Ada_Version_Explicit >= Ada_2005 then
11665 Ent := Find_Lib_Unit_Name;
11666 Set_Is_Preelaborated (Ent);
11667 Set_Suppress_Elaboration_Warnings (Ent);
11669 end Preelaborate_05;
11675 -- pragma Priority (EXPRESSION);
11677 when Pragma_Priority => Priority : declare
11678 P : constant Node_Id := Parent (N);
11682 Check_No_Identifiers;
11683 Check_Arg_Count (1);
11687 if Nkind (P) = N_Subprogram_Body then
11688 Check_In_Main_Program;
11690 Arg := Get_Pragma_Arg (Arg1);
11691 Analyze_And_Resolve (Arg, Standard_Integer);
11695 if not Is_Static_Expression (Arg) then
11696 Flag_Non_Static_Expr
11697 ("main subprogram priority is not static!", Arg);
11700 -- If constraint error, then we already signalled an error
11702 elsif Raises_Constraint_Error (Arg) then
11705 -- Otherwise check in range
11709 Val : constant Uint := Expr_Value (Arg);
11713 or else Val > Expr_Value (Expression
11714 (Parent (RTE (RE_Max_Priority))))
11717 ("main subprogram priority is out of range", Arg1);
11723 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11725 -- Load an arbitrary entity from System.Tasking to make sure
11726 -- this package is implicitly with'ed, since we need to have
11727 -- the tasking run-time active for the pragma Priority to have
11731 Discard : Entity_Id;
11732 pragma Warnings (Off, Discard);
11734 Discard := RTE (RE_Task_List);
11737 -- Task or Protected, must be of type Integer
11739 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11740 Arg := Get_Pragma_Arg (Arg1);
11742 -- The expression must be analyzed in the special manner
11743 -- described in "Handling of Default and Per-Object
11744 -- Expressions" in sem.ads.
11746 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11748 if not Is_Static_Expression (Arg) then
11749 Check_Restriction (Static_Priorities, Arg);
11752 -- Anything else is incorrect
11758 if Has_Pragma_Priority (P) then
11759 Error_Pragma ("duplicate pragma% not allowed");
11761 Set_Has_Pragma_Priority (P, True);
11763 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11764 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11765 -- exp_ch9 should use this ???
11770 -----------------------------------
11771 -- Priority_Specific_Dispatching --
11772 -----------------------------------
11774 -- pragma Priority_Specific_Dispatching (
11775 -- policy_IDENTIFIER,
11776 -- first_priority_EXPRESSION,
11777 -- last_priority_EXPRESSION);
11779 when Pragma_Priority_Specific_Dispatching =>
11780 Priority_Specific_Dispatching : declare
11781 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11782 -- This is the entity System.Any_Priority;
11785 Lower_Bound : Node_Id;
11786 Upper_Bound : Node_Id;
11792 Check_Arg_Count (3);
11793 Check_No_Identifiers;
11794 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11795 Check_Valid_Configuration_Pragma;
11796 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11797 DP := Fold_Upper (Name_Buffer (1));
11799 Lower_Bound := Get_Pragma_Arg (Arg2);
11800 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11801 Lower_Val := Expr_Value (Lower_Bound);
11803 Upper_Bound := Get_Pragma_Arg (Arg3);
11804 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11805 Upper_Val := Expr_Value (Upper_Bound);
11807 -- It is not allowed to use Task_Dispatching_Policy and
11808 -- Priority_Specific_Dispatching in the same partition.
11810 if Task_Dispatching_Policy /= ' ' then
11811 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11813 ("pragma% incompatible with Task_Dispatching_Policy#");
11815 -- Check lower bound in range
11817 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11819 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11822 ("first_priority is out of range", Arg2);
11824 -- Check upper bound in range
11826 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11828 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11831 ("last_priority is out of range", Arg3);
11833 -- Check that the priority range is valid
11835 elsif Lower_Val > Upper_Val then
11837 ("last_priority_expression must be greater than" &
11838 " or equal to first_priority_expression");
11840 -- Store the new policy, but always preserve System_Location since
11841 -- we like the error message with the run-time name.
11844 -- Check overlapping in the priority ranges specified in other
11845 -- Priority_Specific_Dispatching pragmas within the same
11846 -- partition. We can only check those we know about!
11849 Specific_Dispatching.First .. Specific_Dispatching.Last
11851 if Specific_Dispatching.Table (J).First_Priority in
11852 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11853 or else Specific_Dispatching.Table (J).Last_Priority in
11854 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11857 Specific_Dispatching.Table (J).Pragma_Loc;
11859 ("priority range overlaps with "
11860 & "Priority_Specific_Dispatching#");
11864 -- The use of Priority_Specific_Dispatching is incompatible
11865 -- with Task_Dispatching_Policy.
11867 if Task_Dispatching_Policy /= ' ' then
11868 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11870 ("Priority_Specific_Dispatching incompatible "
11871 & "with Task_Dispatching_Policy#");
11874 -- The use of Priority_Specific_Dispatching forces ceiling
11877 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11878 Error_Msg_Sloc := Locking_Policy_Sloc;
11880 ("Priority_Specific_Dispatching incompatible "
11881 & "with Locking_Policy#");
11883 -- Set the Ceiling_Locking policy, but preserve System_Location
11884 -- since we like the error message with the run time name.
11887 Locking_Policy := 'C';
11889 if Locking_Policy_Sloc /= System_Location then
11890 Locking_Policy_Sloc := Loc;
11894 -- Add entry in the table
11896 Specific_Dispatching.Append
11897 ((Dispatching_Policy => DP,
11898 First_Priority => UI_To_Int (Lower_Val),
11899 Last_Priority => UI_To_Int (Upper_Val),
11900 Pragma_Loc => Loc));
11902 end Priority_Specific_Dispatching;
11908 -- pragma Profile (profile_IDENTIFIER);
11910 -- profile_IDENTIFIER => Restricted | Ravenscar
11912 when Pragma_Profile =>
11914 Check_Arg_Count (1);
11915 Check_Valid_Configuration_Pragma;
11916 Check_No_Identifiers;
11919 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11921 if Chars (Argx) = Name_Ravenscar then
11922 Set_Ravenscar_Profile (N);
11923 elsif Chars (Argx) = Name_Restricted then
11924 Set_Profile_Restrictions
11925 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11927 Error_Pragma_Arg ("& is not a valid profile", Argx);
11931 ----------------------
11932 -- Profile_Warnings --
11933 ----------------------
11935 -- pragma Profile_Warnings (profile_IDENTIFIER);
11937 -- profile_IDENTIFIER => Restricted | Ravenscar
11939 when Pragma_Profile_Warnings =>
11941 Check_Arg_Count (1);
11942 Check_Valid_Configuration_Pragma;
11943 Check_No_Identifiers;
11946 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11948 if Chars (Argx) = Name_Ravenscar then
11949 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11950 elsif Chars (Argx) = Name_Restricted then
11951 Set_Profile_Restrictions (Restricted, N, Warn => True);
11953 Error_Pragma_Arg ("& is not a valid profile", Argx);
11957 --------------------------
11958 -- Propagate_Exceptions --
11959 --------------------------
11961 -- pragma Propagate_Exceptions;
11963 -- Note: this pragma is obsolete and has no effect
11965 when Pragma_Propagate_Exceptions =>
11967 Check_Arg_Count (0);
11969 if In_Extended_Main_Source_Unit (N) then
11970 Propagate_Exceptions := True;
11977 -- pragma Psect_Object (
11978 -- [Internal =>] LOCAL_NAME,
11979 -- [, [External =>] EXTERNAL_SYMBOL]
11980 -- [, [Size =>] EXTERNAL_SYMBOL]);
11982 when Pragma_Psect_Object | Pragma_Common_Object =>
11983 Psect_Object : declare
11984 Args : Args_List (1 .. 3);
11985 Names : constant Name_List (1 .. 3) := (
11990 Internal : Node_Id renames Args (1);
11991 External : Node_Id renames Args (2);
11992 Size : Node_Id renames Args (3);
11994 Def_Id : Entity_Id;
11996 procedure Check_Too_Long (Arg : Node_Id);
11997 -- Posts message if the argument is an identifier with more
11998 -- than 31 characters, or a string literal with more than
11999 -- 31 characters, and we are operating under VMS
12001 --------------------
12002 -- Check_Too_Long --
12003 --------------------
12005 procedure Check_Too_Long (Arg : Node_Id) is
12006 X : constant Node_Id := Original_Node (Arg);
12009 if not Nkind_In (X, N_String_Literal, N_Identifier) then
12011 ("inappropriate argument for pragma %", Arg);
12014 if OpenVMS_On_Target then
12015 if (Nkind (X) = N_String_Literal
12016 and then String_Length (Strval (X)) > 31)
12018 (Nkind (X) = N_Identifier
12019 and then Length_Of_Name (Chars (X)) > 31)
12022 ("argument for pragma % is longer than 31 characters",
12026 end Check_Too_Long;
12028 -- Start of processing for Common_Object/Psect_Object
12032 Gather_Associations (Names, Args);
12033 Process_Extended_Import_Export_Internal_Arg (Internal);
12035 Def_Id := Entity (Internal);
12037 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12039 ("pragma% must designate an object", Internal);
12042 Check_Too_Long (Internal);
12044 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12046 ("cannot use pragma% for imported/exported object",
12050 if Is_Concurrent_Type (Etype (Internal)) then
12052 ("cannot specify pragma % for task/protected object",
12056 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12058 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12060 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12063 if Ekind (Def_Id) = E_Constant then
12065 ("cannot specify pragma % for a constant", Internal);
12068 if Is_Record_Type (Etype (Internal)) then
12074 Ent := First_Entity (Etype (Internal));
12075 while Present (Ent) loop
12076 Decl := Declaration_Node (Ent);
12078 if Ekind (Ent) = E_Component
12079 and then Nkind (Decl) = N_Component_Declaration
12080 and then Present (Expression (Decl))
12081 and then Warn_On_Export_Import
12084 ("?object for pragma % has defaults", Internal);
12094 if Present (Size) then
12095 Check_Too_Long (Size);
12098 if Present (External) then
12099 Check_Arg_Is_External_Name (External);
12100 Check_Too_Long (External);
12103 -- If all error tests pass, link pragma on to the rep item chain
12105 Record_Rep_Item (Def_Id, N);
12112 -- pragma Pure [(library_unit_NAME)];
12114 when Pragma_Pure => Pure : declare
12118 Check_Ada_83_Warning;
12119 Check_Valid_Library_Unit_Pragma;
12121 if Nkind (N) = N_Null_Statement then
12125 Ent := Find_Lib_Unit_Name;
12127 Set_Has_Pragma_Pure (Ent);
12128 Set_Suppress_Elaboration_Warnings (Ent);
12135 -- pragma Pure_05 [(library_unit_NAME)];
12137 -- This pragma is useable only in GNAT_Mode, where it is used like
12138 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
12139 -- it is ignored). It may be used after a pragma Preelaborate, in
12140 -- which case it overrides the effect of the pragma Preelaborate.
12141 -- This is used to implement AI-362 which recategorizes some run-time
12142 -- packages in Ada 2005 mode.
12144 when Pragma_Pure_05 => Pure_05 : declare
12149 Check_Valid_Library_Unit_Pragma;
12151 if not GNAT_Mode then
12152 Error_Pragma ("pragma% only available in GNAT mode");
12155 if Nkind (N) = N_Null_Statement then
12159 -- This is one of the few cases where we need to test the value of
12160 -- Ada_Version_Explicit rather than Ada_Version (which is always
12161 -- set to Ada_2012 in a predefined unit), we need to know the
12162 -- explicit version set to know if this pragma is active.
12164 if Ada_Version_Explicit >= Ada_2005 then
12165 Ent := Find_Lib_Unit_Name;
12166 Set_Is_Preelaborated (Ent, False);
12168 Set_Suppress_Elaboration_Warnings (Ent);
12172 -------------------
12173 -- Pure_Function --
12174 -------------------
12176 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12178 when Pragma_Pure_Function => Pure_Function : declare
12181 Def_Id : Entity_Id;
12182 Effective : Boolean := False;
12186 Check_Arg_Count (1);
12187 Check_Optional_Identifier (Arg1, Name_Entity);
12188 Check_Arg_Is_Local_Name (Arg1);
12189 E_Id := Get_Pragma_Arg (Arg1);
12191 if Error_Posted (E_Id) then
12195 -- Loop through homonyms (overloadings) of referenced entity
12197 E := Entity (E_Id);
12199 if Present (E) then
12201 Def_Id := Get_Base_Subprogram (E);
12203 if not Ekind_In (Def_Id, E_Function,
12204 E_Generic_Function,
12208 ("pragma% requires a function name", Arg1);
12211 Set_Is_Pure (Def_Id);
12213 if not Has_Pragma_Pure_Function (Def_Id) then
12214 Set_Has_Pragma_Pure_Function (Def_Id);
12218 exit when From_Aspect_Specification (N);
12220 exit when No (E) or else Scope (E) /= Current_Scope;
12224 and then Warn_On_Redundant_Constructs
12227 ("pragma Pure_Function on& is redundant?",
12233 --------------------
12234 -- Queuing_Policy --
12235 --------------------
12237 -- pragma Queuing_Policy (policy_IDENTIFIER);
12239 when Pragma_Queuing_Policy => declare
12243 Check_Ada_83_Warning;
12244 Check_Arg_Count (1);
12245 Check_No_Identifiers;
12246 Check_Arg_Is_Queuing_Policy (Arg1);
12247 Check_Valid_Configuration_Pragma;
12248 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12249 QP := Fold_Upper (Name_Buffer (1));
12251 if Queuing_Policy /= ' '
12252 and then Queuing_Policy /= QP
12254 Error_Msg_Sloc := Queuing_Policy_Sloc;
12255 Error_Pragma ("queuing policy incompatible with policy#");
12257 -- Set new policy, but always preserve System_Location since we
12258 -- like the error message with the run time name.
12261 Queuing_Policy := QP;
12263 if Queuing_Policy_Sloc /= System_Location then
12264 Queuing_Policy_Sloc := Loc;
12269 -----------------------
12270 -- Relative_Deadline --
12271 -----------------------
12273 -- pragma Relative_Deadline (time_span_EXPRESSION);
12275 when Pragma_Relative_Deadline => Relative_Deadline : declare
12276 P : constant Node_Id := Parent (N);
12281 Check_No_Identifiers;
12282 Check_Arg_Count (1);
12284 Arg := Get_Pragma_Arg (Arg1);
12286 -- The expression must be analyzed in the special manner described
12287 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12289 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12293 if Nkind (P) = N_Subprogram_Body then
12294 Check_In_Main_Program;
12298 elsif Nkind (P) = N_Task_Definition then
12301 -- Anything else is incorrect
12307 if Has_Relative_Deadline_Pragma (P) then
12308 Error_Pragma ("duplicate pragma% not allowed");
12310 Set_Has_Relative_Deadline_Pragma (P, True);
12312 if Nkind (P) = N_Task_Definition then
12313 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12316 end Relative_Deadline;
12318 ---------------------------
12319 -- Remote_Call_Interface --
12320 ---------------------------
12322 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12324 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12325 Cunit_Node : Node_Id;
12326 Cunit_Ent : Entity_Id;
12330 Check_Ada_83_Warning;
12331 Check_Valid_Library_Unit_Pragma;
12333 if Nkind (N) = N_Null_Statement then
12337 Cunit_Node := Cunit (Current_Sem_Unit);
12338 K := Nkind (Unit (Cunit_Node));
12339 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12341 if K = N_Package_Declaration
12342 or else K = N_Generic_Package_Declaration
12343 or else K = N_Subprogram_Declaration
12344 or else K = N_Generic_Subprogram_Declaration
12345 or else (K = N_Subprogram_Body
12346 and then Acts_As_Spec (Unit (Cunit_Node)))
12351 "pragma% must apply to package or subprogram declaration");
12354 Set_Is_Remote_Call_Interface (Cunit_Ent);
12355 end Remote_Call_Interface;
12361 -- pragma Remote_Types [(library_unit_NAME)];
12363 when Pragma_Remote_Types => Remote_Types : declare
12364 Cunit_Node : Node_Id;
12365 Cunit_Ent : Entity_Id;
12368 Check_Ada_83_Warning;
12369 Check_Valid_Library_Unit_Pragma;
12371 if Nkind (N) = N_Null_Statement then
12375 Cunit_Node := Cunit (Current_Sem_Unit);
12376 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12378 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12379 N_Generic_Package_Declaration)
12382 ("pragma% can only apply to a package declaration");
12385 Set_Is_Remote_Types (Cunit_Ent);
12392 -- pragma Ravenscar;
12394 when Pragma_Ravenscar =>
12396 Check_Arg_Count (0);
12397 Check_Valid_Configuration_Pragma;
12398 Set_Ravenscar_Profile (N);
12400 if Warn_On_Obsolescent_Feature then
12401 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12402 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12405 -------------------------
12406 -- Restricted_Run_Time --
12407 -------------------------
12409 -- pragma Restricted_Run_Time;
12411 when Pragma_Restricted_Run_Time =>
12413 Check_Arg_Count (0);
12414 Check_Valid_Configuration_Pragma;
12415 Set_Profile_Restrictions
12416 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12418 if Warn_On_Obsolescent_Feature then
12420 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12421 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12428 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12431 -- restriction_IDENTIFIER
12432 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12434 when Pragma_Restrictions =>
12435 Process_Restrictions_Or_Restriction_Warnings
12436 (Warn => Treat_Restrictions_As_Warnings);
12438 --------------------------
12439 -- Restriction_Warnings --
12440 --------------------------
12442 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12445 -- restriction_IDENTIFIER
12446 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12448 when Pragma_Restriction_Warnings =>
12450 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12456 -- pragma Reviewable;
12458 when Pragma_Reviewable =>
12459 Check_Ada_83_Warning;
12460 Check_Arg_Count (0);
12462 -- Call dummy debugging function rv. This is done to assist front
12463 -- end debugging. By placing a Reviewable pragma in the source
12464 -- program, a breakpoint on rv catches this place in the source,
12465 -- allowing convenient stepping to the point of interest.
12469 --------------------------
12470 -- Short_Circuit_And_Or --
12471 --------------------------
12473 when Pragma_Short_Circuit_And_Or =>
12475 Check_Arg_Count (0);
12476 Check_Valid_Configuration_Pragma;
12477 Short_Circuit_And_Or := True;
12479 -------------------
12480 -- Share_Generic --
12481 -------------------
12483 -- pragma Share_Generic (NAME {, NAME});
12485 when Pragma_Share_Generic =>
12487 Process_Generic_List;
12493 -- pragma Shared (LOCAL_NAME);
12495 when Pragma_Shared =>
12497 Process_Atomic_Shared_Volatile;
12499 --------------------
12500 -- Shared_Passive --
12501 --------------------
12503 -- pragma Shared_Passive [(library_unit_NAME)];
12505 -- Set the flag Is_Shared_Passive of program unit name entity
12507 when Pragma_Shared_Passive => Shared_Passive : declare
12508 Cunit_Node : Node_Id;
12509 Cunit_Ent : Entity_Id;
12512 Check_Ada_83_Warning;
12513 Check_Valid_Library_Unit_Pragma;
12515 if Nkind (N) = N_Null_Statement then
12519 Cunit_Node := Cunit (Current_Sem_Unit);
12520 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12522 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12523 N_Generic_Package_Declaration)
12526 ("pragma% can only apply to a package declaration");
12529 Set_Is_Shared_Passive (Cunit_Ent);
12530 end Shared_Passive;
12532 -----------------------
12533 -- Short_Descriptors --
12534 -----------------------
12536 -- pragma Short_Descriptors;
12538 when Pragma_Short_Descriptors =>
12540 Check_Arg_Count (0);
12541 Check_Valid_Configuration_Pragma;
12542 Short_Descriptors := True;
12544 ----------------------
12545 -- Source_File_Name --
12546 ----------------------
12548 -- There are five forms for this pragma:
12550 -- pragma Source_File_Name (
12551 -- [UNIT_NAME =>] unit_NAME,
12552 -- BODY_FILE_NAME => STRING_LITERAL
12553 -- [, [INDEX =>] INTEGER_LITERAL]);
12555 -- pragma Source_File_Name (
12556 -- [UNIT_NAME =>] unit_NAME,
12557 -- SPEC_FILE_NAME => STRING_LITERAL
12558 -- [, [INDEX =>] INTEGER_LITERAL]);
12560 -- pragma Source_File_Name (
12561 -- BODY_FILE_NAME => STRING_LITERAL
12562 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12563 -- [, CASING => CASING_SPEC]);
12565 -- pragma Source_File_Name (
12566 -- SPEC_FILE_NAME => STRING_LITERAL
12567 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12568 -- [, CASING => CASING_SPEC]);
12570 -- pragma Source_File_Name (
12571 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12572 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12573 -- [, CASING => CASING_SPEC]);
12575 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12577 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12578 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12579 -- only be used when no project file is used, while SFNP can only be
12580 -- used when a project file is used.
12582 -- No processing here. Processing was completed during parsing, since
12583 -- we need to have file names set as early as possible. Units are
12584 -- loaded well before semantic processing starts.
12586 -- The only processing we defer to this point is the check for
12587 -- correct placement.
12589 when Pragma_Source_File_Name =>
12591 Check_Valid_Configuration_Pragma;
12593 ------------------------------
12594 -- Source_File_Name_Project --
12595 ------------------------------
12597 -- See Source_File_Name for syntax
12599 -- No processing here. Processing was completed during parsing, since
12600 -- we need to have file names set as early as possible. Units are
12601 -- loaded well before semantic processing starts.
12603 -- The only processing we defer to this point is the check for
12604 -- correct placement.
12606 when Pragma_Source_File_Name_Project =>
12608 Check_Valid_Configuration_Pragma;
12610 -- Check that a pragma Source_File_Name_Project is used only in a
12611 -- configuration pragmas file.
12613 -- Pragmas Source_File_Name_Project should only be generated by
12614 -- the Project Manager in configuration pragmas files.
12616 -- This is really an ugly test. It seems to depend on some
12617 -- accidental and undocumented property. At the very least it
12618 -- needs to be documented, but it would be better to have a
12619 -- clean way of testing if we are in a configuration file???
12621 if Present (Parent (N)) then
12623 ("pragma% can only appear in a configuration pragmas file");
12626 ----------------------
12627 -- Source_Reference --
12628 ----------------------
12630 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12632 -- Nothing to do, all processing completed in Par.Prag, since we need
12633 -- the information for possible parser messages that are output.
12635 when Pragma_Source_Reference =>
12638 --------------------------------
12639 -- Static_Elaboration_Desired --
12640 --------------------------------
12642 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12644 when Pragma_Static_Elaboration_Desired =>
12646 Check_At_Most_N_Arguments (1);
12648 if Is_Compilation_Unit (Current_Scope)
12649 and then Ekind (Current_Scope) = E_Package
12651 Set_Static_Elaboration_Desired (Current_Scope, True);
12653 Error_Pragma ("pragma% must apply to a library-level package");
12660 -- pragma Storage_Size (EXPRESSION);
12662 when Pragma_Storage_Size => Storage_Size : declare
12663 P : constant Node_Id := Parent (N);
12667 Check_No_Identifiers;
12668 Check_Arg_Count (1);
12670 -- The expression must be analyzed in the special manner described
12671 -- in "Handling of Default Expressions" in sem.ads.
12673 Arg := Get_Pragma_Arg (Arg1);
12674 Preanalyze_Spec_Expression (Arg, Any_Integer);
12676 if not Is_Static_Expression (Arg) then
12677 Check_Restriction (Static_Storage_Size, Arg);
12680 if Nkind (P) /= N_Task_Definition then
12685 if Has_Storage_Size_Pragma (P) then
12686 Error_Pragma ("duplicate pragma% not allowed");
12688 Set_Has_Storage_Size_Pragma (P, True);
12691 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12692 -- ??? exp_ch9 should use this!
12700 -- pragma Storage_Unit (NUMERIC_LITERAL);
12702 -- Only permitted argument is System'Storage_Unit value
12704 when Pragma_Storage_Unit =>
12705 Check_No_Identifiers;
12706 Check_Arg_Count (1);
12707 Check_Arg_Is_Integer_Literal (Arg1);
12709 if Intval (Get_Pragma_Arg (Arg1)) /=
12710 UI_From_Int (Ttypes.System_Storage_Unit)
12712 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12714 ("the only allowed argument for pragma% is ^", Arg1);
12717 --------------------
12718 -- Stream_Convert --
12719 --------------------
12721 -- pragma Stream_Convert (
12722 -- [Entity =>] type_LOCAL_NAME,
12723 -- [Read =>] function_NAME,
12724 -- [Write =>] function NAME);
12726 when Pragma_Stream_Convert => Stream_Convert : declare
12728 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12729 -- Check that the given argument is the name of a local function
12730 -- of one argument that is not overloaded earlier in the current
12731 -- local scope. A check is also made that the argument is a
12732 -- function with one parameter.
12734 --------------------------------------
12735 -- Check_OK_Stream_Convert_Function --
12736 --------------------------------------
12738 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12742 Check_Arg_Is_Local_Name (Arg);
12743 Ent := Entity (Get_Pragma_Arg (Arg));
12745 if Has_Homonym (Ent) then
12747 ("argument for pragma% may not be overloaded", Arg);
12750 if Ekind (Ent) /= E_Function
12751 or else No (First_Formal (Ent))
12752 or else Present (Next_Formal (First_Formal (Ent)))
12755 ("argument for pragma% must be" &
12756 " function of one argument", Arg);
12758 end Check_OK_Stream_Convert_Function;
12760 -- Start of processing for Stream_Convert
12764 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12765 Check_Arg_Count (3);
12766 Check_Optional_Identifier (Arg1, Name_Entity);
12767 Check_Optional_Identifier (Arg2, Name_Read);
12768 Check_Optional_Identifier (Arg3, Name_Write);
12769 Check_Arg_Is_Local_Name (Arg1);
12770 Check_OK_Stream_Convert_Function (Arg2);
12771 Check_OK_Stream_Convert_Function (Arg3);
12774 Typ : constant Entity_Id :=
12775 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12776 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12777 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12780 Check_First_Subtype (Arg1);
12782 -- Check for too early or too late. Note that we don't enforce
12783 -- the rule about primitive operations in this case, since, as
12784 -- is the case for explicit stream attributes themselves, these
12785 -- restrictions are not appropriate. Note that the chaining of
12786 -- the pragma by Rep_Item_Too_Late is actually the critical
12787 -- processing done for this pragma.
12789 if Rep_Item_Too_Early (Typ, N)
12791 Rep_Item_Too_Late (Typ, N, FOnly => True)
12796 -- Return if previous error
12798 if Etype (Typ) = Any_Type
12800 Etype (Read) = Any_Type
12802 Etype (Write) = Any_Type
12809 if Underlying_Type (Etype (Read)) /= Typ then
12811 ("incorrect return type for function&", Arg2);
12814 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12816 ("incorrect parameter type for function&", Arg3);
12819 if Underlying_Type (Etype (First_Formal (Read))) /=
12820 Underlying_Type (Etype (Write))
12823 ("result type of & does not match Read parameter type",
12827 end Stream_Convert;
12829 -------------------------
12830 -- Style_Checks (GNAT) --
12831 -------------------------
12833 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12835 -- This is processed by the parser since some of the style checks
12836 -- take place during source scanning and parsing. This means that
12837 -- we don't need to issue error messages here.
12839 when Pragma_Style_Checks => Style_Checks : declare
12840 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12846 Check_No_Identifiers;
12848 -- Two argument form
12850 if Arg_Count = 2 then
12851 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12858 E_Id := Get_Pragma_Arg (Arg2);
12861 if not Is_Entity_Name (E_Id) then
12863 ("second argument of pragma% must be entity name",
12867 E := Entity (E_Id);
12873 Set_Suppress_Style_Checks (E,
12874 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12875 exit when No (Homonym (E));
12881 -- One argument form
12884 Check_Arg_Count (1);
12886 if Nkind (A) = N_String_Literal then
12890 Slen : constant Natural := Natural (String_Length (S));
12891 Options : String (1 .. Slen);
12897 C := Get_String_Char (S, Int (J));
12898 exit when not In_Character_Range (C);
12899 Options (J) := Get_Character (C);
12901 -- If at end of string, set options. As per discussion
12902 -- above, no need to check for errors, since we issued
12903 -- them in the parser.
12906 Set_Style_Check_Options (Options);
12914 elsif Nkind (A) = N_Identifier then
12915 if Chars (A) = Name_All_Checks then
12917 Set_GNAT_Style_Check_Options;
12919 Set_Default_Style_Check_Options;
12922 elsif Chars (A) = Name_On then
12923 Style_Check := True;
12925 elsif Chars (A) = Name_Off then
12926 Style_Check := False;
12936 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12938 when Pragma_Subtitle =>
12940 Check_Arg_Count (1);
12941 Check_Optional_Identifier (Arg1, Name_Subtitle);
12942 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12949 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12951 when Pragma_Suppress =>
12952 Process_Suppress_Unsuppress (True);
12958 -- pragma Suppress_All;
12960 -- The only check made here is that the pragma has no arguments.
12961 -- There are no placement rules, and the processing required (setting
12962 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
12963 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
12964 -- then creates and inserts a pragma Suppress (All_Checks).
12966 when Pragma_Suppress_All =>
12968 Check_Arg_Count (0);
12970 -------------------------
12971 -- Suppress_Debug_Info --
12972 -------------------------
12974 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12976 when Pragma_Suppress_Debug_Info =>
12978 Check_Arg_Count (1);
12979 Check_Optional_Identifier (Arg1, Name_Entity);
12980 Check_Arg_Is_Local_Name (Arg1);
12981 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
12983 ----------------------------------
12984 -- Suppress_Exception_Locations --
12985 ----------------------------------
12987 -- pragma Suppress_Exception_Locations;
12989 when Pragma_Suppress_Exception_Locations =>
12991 Check_Arg_Count (0);
12992 Check_Valid_Configuration_Pragma;
12993 Exception_Locations_Suppressed := True;
12995 -----------------------------
12996 -- Suppress_Initialization --
12997 -----------------------------
12999 -- pragma Suppress_Initialization ([Entity =>] type_Name);
13001 when Pragma_Suppress_Initialization => Suppress_Init : declare
13007 Check_Arg_Count (1);
13008 Check_Optional_Identifier (Arg1, Name_Entity);
13009 Check_Arg_Is_Local_Name (Arg1);
13011 E_Id := Get_Pragma_Arg (Arg1);
13013 if Etype (E_Id) = Any_Type then
13017 E := Entity (E_Id);
13019 if not Is_Type (E) then
13020 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13023 if Rep_Item_Too_Early (E, N)
13025 Rep_Item_Too_Late (E, N, FOnly => True)
13030 -- For incomplete/private type, set flag on full view
13032 if Is_Incomplete_Or_Private_Type (E) then
13033 if No (Full_View (Base_Type (E))) then
13035 ("argument of pragma% cannot be an incomplete type", Arg1);
13037 Set_Suppress_Initialization (Full_View (Base_Type (E)));
13040 -- For first subtype, set flag on base type
13042 elsif Is_First_Subtype (E) then
13043 Set_Suppress_Initialization (Base_Type (E));
13045 -- For other than first subtype, set flag on subtype itself
13048 Set_Suppress_Initialization (E);
13056 -- pragma System_Name (DIRECT_NAME);
13058 -- Syntax check: one argument, which must be the identifier GNAT or
13059 -- the identifier GCC, no other identifiers are acceptable.
13061 when Pragma_System_Name =>
13063 Check_No_Identifiers;
13064 Check_Arg_Count (1);
13065 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13067 -----------------------------
13068 -- Task_Dispatching_Policy --
13069 -----------------------------
13071 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13073 when Pragma_Task_Dispatching_Policy => declare
13077 Check_Ada_83_Warning;
13078 Check_Arg_Count (1);
13079 Check_No_Identifiers;
13080 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13081 Check_Valid_Configuration_Pragma;
13082 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13083 DP := Fold_Upper (Name_Buffer (1));
13085 if Task_Dispatching_Policy /= ' '
13086 and then Task_Dispatching_Policy /= DP
13088 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13090 ("task dispatching policy incompatible with policy#");
13092 -- Set new policy, but always preserve System_Location since we
13093 -- like the error message with the run time name.
13096 Task_Dispatching_Policy := DP;
13098 if Task_Dispatching_Policy_Sloc /= System_Location then
13099 Task_Dispatching_Policy_Sloc := Loc;
13108 -- pragma Task_Info (EXPRESSION);
13110 when Pragma_Task_Info => Task_Info : declare
13111 P : constant Node_Id := Parent (N);
13116 if Nkind (P) /= N_Task_Definition then
13117 Error_Pragma ("pragma% must appear in task definition");
13120 Check_No_Identifiers;
13121 Check_Arg_Count (1);
13123 Analyze_And_Resolve
13124 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13126 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13130 if Has_Task_Info_Pragma (P) then
13131 Error_Pragma ("duplicate pragma% not allowed");
13133 Set_Has_Task_Info_Pragma (P, True);
13141 -- pragma Task_Name (string_EXPRESSION);
13143 when Pragma_Task_Name => Task_Name : declare
13144 P : constant Node_Id := Parent (N);
13148 Check_No_Identifiers;
13149 Check_Arg_Count (1);
13151 Arg := Get_Pragma_Arg (Arg1);
13153 -- The expression is used in the call to Create_Task, and must be
13154 -- expanded there, not in the context of the current spec. It must
13155 -- however be analyzed to capture global references, in case it
13156 -- appears in a generic context.
13158 Preanalyze_And_Resolve (Arg, Standard_String);
13160 if Nkind (P) /= N_Task_Definition then
13164 if Has_Task_Name_Pragma (P) then
13165 Error_Pragma ("duplicate pragma% not allowed");
13167 Set_Has_Task_Name_Pragma (P, True);
13168 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13176 -- pragma Task_Storage (
13177 -- [Task_Type =>] LOCAL_NAME,
13178 -- [Top_Guard =>] static_integer_EXPRESSION);
13180 when Pragma_Task_Storage => Task_Storage : declare
13181 Args : Args_List (1 .. 2);
13182 Names : constant Name_List (1 .. 2) := (
13186 Task_Type : Node_Id renames Args (1);
13187 Top_Guard : Node_Id renames Args (2);
13193 Gather_Associations (Names, Args);
13195 if No (Task_Type) then
13197 ("missing task_type argument for pragma%");
13200 Check_Arg_Is_Local_Name (Task_Type);
13202 Ent := Entity (Task_Type);
13204 if not Is_Task_Type (Ent) then
13206 ("argument for pragma% must be task type", Task_Type);
13209 if No (Top_Guard) then
13211 ("pragma% takes two arguments", Task_Type);
13213 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13216 Check_First_Subtype (Task_Type);
13218 if Rep_Item_Too_Late (Ent, N) then
13227 -- pragma Test_Case ([Name =>] String_Expression
13228 -- ,[Mode =>] (Normal | Robustness)
13229 -- [, Requires => Boolean_Expression]
13230 -- [, Ensures => Boolean_Expression]);
13232 when Pragma_Test_Case => Test_Case : declare
13236 Check_At_Least_N_Arguments (3);
13237 Check_At_Most_N_Arguments (4);
13239 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13241 Check_Optional_Identifier (Arg1, Name_Name);
13242 Check_Arg_Is_String_Literal (Arg1);
13243 Check_Optional_Identifier (Arg2, Name_Mode);
13244 Check_Arg_Is_One_Of (Arg2, Name_Normal, Name_Robustness);
13245 if Arg_Count = 4 then
13246 Check_Identifier (Arg3, Name_Requires);
13247 Check_Identifier (Arg4, Name_Ensures);
13249 Check_Arg_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13255 --------------------------
13256 -- Thread_Local_Storage --
13257 --------------------------
13259 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13261 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13267 Check_Arg_Count (1);
13268 Check_Optional_Identifier (Arg1, Name_Entity);
13269 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13271 Id := Get_Pragma_Arg (Arg1);
13274 if not Is_Entity_Name (Id)
13275 or else Ekind (Entity (Id)) /= E_Variable
13277 Error_Pragma_Arg ("local variable name required", Arg1);
13282 if Rep_Item_Too_Early (E, N)
13283 or else Rep_Item_Too_Late (E, N)
13288 Set_Has_Pragma_Thread_Local_Storage (E);
13289 Set_Has_Gigi_Rep_Item (E);
13290 end Thread_Local_Storage;
13296 -- pragma Time_Slice (static_duration_EXPRESSION);
13298 when Pragma_Time_Slice => Time_Slice : declare
13304 Check_Arg_Count (1);
13305 Check_No_Identifiers;
13306 Check_In_Main_Program;
13307 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13309 if not Error_Posted (Arg1) then
13311 while Present (Nod) loop
13312 if Nkind (Nod) = N_Pragma
13313 and then Pragma_Name (Nod) = Name_Time_Slice
13315 Error_Msg_Name_1 := Pname;
13316 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13323 -- Process only if in main unit
13325 if Get_Source_Unit (Loc) = Main_Unit then
13326 Opt.Time_Slice_Set := True;
13327 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13329 if Val <= Ureal_0 then
13330 Opt.Time_Slice_Value := 0;
13332 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13333 Opt.Time_Slice_Value := 1_000_000_000;
13336 Opt.Time_Slice_Value :=
13337 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13346 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13348 -- TITLING_OPTION ::=
13349 -- [Title =>] STRING_LITERAL
13350 -- | [Subtitle =>] STRING_LITERAL
13352 when Pragma_Title => Title : declare
13353 Args : Args_List (1 .. 2);
13354 Names : constant Name_List (1 .. 2) := (
13360 Gather_Associations (Names, Args);
13363 for J in 1 .. 2 loop
13364 if Present (Args (J)) then
13365 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13370 ---------------------
13371 -- Unchecked_Union --
13372 ---------------------
13374 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13376 when Pragma_Unchecked_Union => Unchecked_Union : declare
13377 Assoc : constant Node_Id := Arg1;
13378 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13389 Check_No_Identifiers;
13390 Check_Arg_Count (1);
13391 Check_Arg_Is_Local_Name (Arg1);
13393 Find_Type (Type_Id);
13394 Typ := Entity (Type_Id);
13397 or else Rep_Item_Too_Early (Typ, N)
13401 Typ := Underlying_Type (Typ);
13404 if Rep_Item_Too_Late (Typ, N) then
13408 Check_First_Subtype (Arg1);
13410 -- Note remaining cases are references to a type in the current
13411 -- declarative part. If we find an error, we post the error on
13412 -- the relevant type declaration at an appropriate point.
13414 if not Is_Record_Type (Typ) then
13415 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13418 elsif Is_Tagged_Type (Typ) then
13419 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13422 elsif Is_Limited_Type (Typ) then
13424 ("Unchecked_Union must not be limited record type", Typ);
13425 Explain_Limited_Type (Typ, Typ);
13429 if not Has_Discriminants (Typ) then
13431 ("Unchecked_Union must have one discriminant", Typ);
13435 Discr := First_Discriminant (Typ);
13436 while Present (Discr) loop
13437 if No (Discriminant_Default_Value (Discr)) then
13439 ("Unchecked_Union discriminant must have default value",
13443 Next_Discriminant (Discr);
13446 Tdef := Type_Definition (Declaration_Node (Typ));
13447 Clist := Component_List (Tdef);
13449 Comp := First (Component_Items (Clist));
13450 while Present (Comp) loop
13451 Check_Component (Comp, Typ);
13455 if No (Clist) or else No (Variant_Part (Clist)) then
13457 ("Unchecked_Union must have variant part",
13462 Vpart := Variant_Part (Clist);
13464 Variant := First (Variants (Vpart));
13465 while Present (Variant) loop
13466 Check_Variant (Variant, Typ);
13471 Set_Is_Unchecked_Union (Typ);
13472 Set_Convention (Typ, Convention_C);
13473 Set_Has_Unchecked_Union (Base_Type (Typ));
13474 Set_Is_Unchecked_Union (Base_Type (Typ));
13475 end Unchecked_Union;
13477 ------------------------
13478 -- Unimplemented_Unit --
13479 ------------------------
13481 -- pragma Unimplemented_Unit;
13483 -- Note: this only gives an error if we are generating code, or if
13484 -- we are in a generic library unit (where the pragma appears in the
13485 -- body, not in the spec).
13487 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13488 Cunitent : constant Entity_Id :=
13489 Cunit_Entity (Get_Source_Unit (Loc));
13490 Ent_Kind : constant Entity_Kind :=
13495 Check_Arg_Count (0);
13497 if Operating_Mode = Generate_Code
13498 or else Ent_Kind = E_Generic_Function
13499 or else Ent_Kind = E_Generic_Procedure
13500 or else Ent_Kind = E_Generic_Package
13502 Get_Name_String (Chars (Cunitent));
13503 Set_Casing (Mixed_Case);
13504 Write_Str (Name_Buffer (1 .. Name_Len));
13505 Write_Str (" is not supported in this configuration");
13507 raise Unrecoverable_Error;
13509 end Unimplemented_Unit;
13511 ------------------------
13512 -- Universal_Aliasing --
13513 ------------------------
13515 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13517 when Pragma_Universal_Aliasing => Universal_Alias : declare
13522 Check_Arg_Count (1);
13523 Check_Optional_Identifier (Arg2, Name_Entity);
13524 Check_Arg_Is_Local_Name (Arg1);
13525 E_Id := Entity (Get_Pragma_Arg (Arg1));
13527 if E_Id = Any_Type then
13529 elsif No (E_Id) or else not Is_Type (E_Id) then
13530 Error_Pragma_Arg ("pragma% requires type", Arg1);
13533 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13534 end Universal_Alias;
13536 --------------------
13537 -- Universal_Data --
13538 --------------------
13540 -- pragma Universal_Data [(library_unit_NAME)];
13542 when Pragma_Universal_Data =>
13545 -- If this is a configuration pragma, then set the universal
13546 -- addressing option, otherwise confirm that the pragma satisfies
13547 -- the requirements of library unit pragma placement and leave it
13548 -- to the GNAAMP back end to detect the pragma (avoids transitive
13549 -- setting of the option due to withed units).
13551 if Is_Configuration_Pragma then
13552 Universal_Addressing_On_AAMP := True;
13554 Check_Valid_Library_Unit_Pragma;
13557 if not AAMP_On_Target then
13558 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13565 -- pragma Unmodified (local_Name {, local_Name});
13567 when Pragma_Unmodified => Unmodified : declare
13568 Arg_Node : Node_Id;
13569 Arg_Expr : Node_Id;
13570 Arg_Ent : Entity_Id;
13574 Check_At_Least_N_Arguments (1);
13576 -- Loop through arguments
13579 while Present (Arg_Node) loop
13580 Check_No_Identifier (Arg_Node);
13582 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13583 -- in fact generate reference, so that the entity will have a
13584 -- reference, which will inhibit any warnings about it not
13585 -- being referenced, and also properly show up in the ali file
13586 -- as a reference. But this reference is recorded before the
13587 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13588 -- generated for this reference.
13590 Check_Arg_Is_Local_Name (Arg_Node);
13591 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13593 if Is_Entity_Name (Arg_Expr) then
13594 Arg_Ent := Entity (Arg_Expr);
13596 if not Is_Assignable (Arg_Ent) then
13598 ("pragma% can only be applied to a variable",
13601 Set_Has_Pragma_Unmodified (Arg_Ent);
13613 -- pragma Unreferenced (local_Name {, local_Name});
13615 -- or when used in a context clause:
13617 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13619 when Pragma_Unreferenced => Unreferenced : declare
13620 Arg_Node : Node_Id;
13621 Arg_Expr : Node_Id;
13622 Arg_Ent : Entity_Id;
13627 Check_At_Least_N_Arguments (1);
13629 -- Check case of appearing within context clause
13631 if Is_In_Context_Clause then
13633 -- The arguments must all be units mentioned in a with clause
13634 -- in the same context clause. Note we already checked (in
13635 -- Par.Prag) that the arguments are either identifiers or
13636 -- selected components.
13639 while Present (Arg_Node) loop
13640 Citem := First (List_Containing (N));
13641 while Citem /= N loop
13642 if Nkind (Citem) = N_With_Clause
13644 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13646 Set_Has_Pragma_Unreferenced
13649 (Library_Unit (Citem))));
13651 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13660 ("argument of pragma% is not with'ed unit", Arg_Node);
13666 -- Case of not in list of context items
13670 while Present (Arg_Node) loop
13671 Check_No_Identifier (Arg_Node);
13673 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13674 -- will in fact generate reference, so that the entity will
13675 -- have a reference, which will inhibit any warnings about
13676 -- it not being referenced, and also properly show up in the
13677 -- ali file as a reference. But this reference is recorded
13678 -- before the Has_Pragma_Unreferenced flag is set, so that
13679 -- no warning is generated for this reference.
13681 Check_Arg_Is_Local_Name (Arg_Node);
13682 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13684 if Is_Entity_Name (Arg_Expr) then
13685 Arg_Ent := Entity (Arg_Expr);
13687 -- If the entity is overloaded, the pragma applies to the
13688 -- most recent overloading, as documented. In this case,
13689 -- name resolution does not generate a reference, so it
13690 -- must be done here explicitly.
13692 if Is_Overloaded (Arg_Expr) then
13693 Generate_Reference (Arg_Ent, N);
13696 Set_Has_Pragma_Unreferenced (Arg_Ent);
13704 --------------------------
13705 -- Unreferenced_Objects --
13706 --------------------------
13708 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13710 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13711 Arg_Node : Node_Id;
13712 Arg_Expr : Node_Id;
13716 Check_At_Least_N_Arguments (1);
13719 while Present (Arg_Node) loop
13720 Check_No_Identifier (Arg_Node);
13721 Check_Arg_Is_Local_Name (Arg_Node);
13722 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13724 if not Is_Entity_Name (Arg_Expr)
13725 or else not Is_Type (Entity (Arg_Expr))
13728 ("argument for pragma% must be type or subtype", Arg_Node);
13731 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13734 end Unreferenced_Objects;
13736 ------------------------------
13737 -- Unreserve_All_Interrupts --
13738 ------------------------------
13740 -- pragma Unreserve_All_Interrupts;
13742 when Pragma_Unreserve_All_Interrupts =>
13744 Check_Arg_Count (0);
13746 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13747 Unreserve_All_Interrupts := True;
13754 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13756 when Pragma_Unsuppress =>
13758 Process_Suppress_Unsuppress (False);
13760 -------------------
13761 -- Use_VADS_Size --
13762 -------------------
13764 -- pragma Use_VADS_Size;
13766 when Pragma_Use_VADS_Size =>
13768 Check_Arg_Count (0);
13769 Check_Valid_Configuration_Pragma;
13770 Use_VADS_Size := True;
13772 ---------------------
13773 -- Validity_Checks --
13774 ---------------------
13776 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13778 when Pragma_Validity_Checks => Validity_Checks : declare
13779 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13785 Check_Arg_Count (1);
13786 Check_No_Identifiers;
13788 if Nkind (A) = N_String_Literal then
13792 Slen : constant Natural := Natural (String_Length (S));
13793 Options : String (1 .. Slen);
13799 C := Get_String_Char (S, Int (J));
13800 exit when not In_Character_Range (C);
13801 Options (J) := Get_Character (C);
13804 Set_Validity_Check_Options (Options);
13812 elsif Nkind (A) = N_Identifier then
13814 if Chars (A) = Name_All_Checks then
13815 Set_Validity_Check_Options ("a");
13817 elsif Chars (A) = Name_On then
13818 Validity_Checks_On := True;
13820 elsif Chars (A) = Name_Off then
13821 Validity_Checks_On := False;
13825 end Validity_Checks;
13831 -- pragma Volatile (LOCAL_NAME);
13833 when Pragma_Volatile =>
13834 Process_Atomic_Shared_Volatile;
13836 -------------------------
13837 -- Volatile_Components --
13838 -------------------------
13840 -- pragma Volatile_Components (array_LOCAL_NAME);
13842 -- Volatile is handled by the same circuit as Atomic_Components
13848 -- pragma Warnings (On | Off);
13849 -- pragma Warnings (On | Off, LOCAL_NAME);
13850 -- pragma Warnings (static_string_EXPRESSION);
13851 -- pragma Warnings (On | Off, STRING_LITERAL);
13853 when Pragma_Warnings => Warnings : begin
13855 Check_At_Least_N_Arguments (1);
13856 Check_No_Identifiers;
13858 -- If debug flag -gnatd.i is set, pragma is ignored
13860 if Debug_Flag_Dot_I then
13864 -- Process various forms of the pragma
13867 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13870 -- One argument case
13872 if Arg_Count = 1 then
13874 -- On/Off one argument case was processed by parser
13876 if Nkind (Argx) = N_Identifier
13878 (Chars (Argx) = Name_On
13880 Chars (Argx) = Name_Off)
13884 -- One argument case must be ON/OFF or static string expr
13886 elsif not Is_Static_String_Expression (Arg1) then
13888 ("argument of pragma% must be On/Off or " &
13889 "static string expression", Arg1);
13891 -- One argument string expression case
13895 Lit : constant Node_Id := Expr_Value_S (Argx);
13896 Str : constant String_Id := Strval (Lit);
13897 Len : constant Nat := String_Length (Str);
13905 while J <= Len loop
13906 C := Get_String_Char (Str, J);
13907 OK := In_Character_Range (C);
13910 Chr := Get_Character (C);
13914 if J < Len and then Chr = '.' then
13916 C := Get_String_Char (Str, J);
13917 Chr := Get_Character (C);
13919 if not Set_Dot_Warning_Switch (Chr) then
13921 ("invalid warning switch character " &
13928 OK := Set_Warning_Switch (Chr);
13934 ("invalid warning switch character " & Chr,
13943 -- Two or more arguments (must be two)
13946 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13947 Check_At_Most_N_Arguments (2);
13955 E_Id := Get_Pragma_Arg (Arg2);
13958 -- In the expansion of an inlined body, a reference to
13959 -- the formal may be wrapped in a conversion if the
13960 -- actual is a conversion. Retrieve the real entity name.
13962 if (In_Instance_Body
13963 or else In_Inlined_Body)
13964 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13966 E_Id := Expression (E_Id);
13969 -- Entity name case
13971 if Is_Entity_Name (E_Id) then
13972 E := Entity (E_Id);
13979 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13982 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13983 and then Warn_On_Warnings_Off
13985 Warnings_Off_Pragmas.Append ((N, E));
13988 if Is_Enumeration_Type (E) then
13992 Lit := First_Literal (E);
13993 while Present (Lit) loop
13994 Set_Warnings_Off (Lit);
13995 Next_Literal (Lit);
14000 exit when No (Homonym (E));
14005 -- Error if not entity or static string literal case
14007 elsif not Is_Static_String_Expression (Arg2) then
14009 ("second argument of pragma% must be entity " &
14010 "name or static string expression", Arg2);
14012 -- String literal case
14015 String_To_Name_Buffer
14016 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14018 -- Note on configuration pragma case: If this is a
14019 -- configuration pragma, then for an OFF pragma, we
14020 -- just set Config True in the call, which is all
14021 -- that needs to be done. For the case of ON, this
14022 -- is normally an error, unless it is canceling the
14023 -- effect of a previous OFF pragma in the same file.
14024 -- In any other case, an error will be signalled (ON
14025 -- with no matching OFF).
14027 if Chars (Argx) = Name_Off then
14028 Set_Specific_Warning_Off
14029 (Loc, Name_Buffer (1 .. Name_Len),
14030 Config => Is_Configuration_Pragma);
14032 elsif Chars (Argx) = Name_On then
14033 Set_Specific_Warning_On
14034 (Loc, Name_Buffer (1 .. Name_Len), Err);
14038 ("?pragma Warnings On with no " &
14039 "matching Warnings Off",
14049 -------------------
14050 -- Weak_External --
14051 -------------------
14053 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
14055 when Pragma_Weak_External => Weak_External : declare
14060 Check_Arg_Count (1);
14061 Check_Optional_Identifier (Arg1, Name_Entity);
14062 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14063 Ent := Entity (Get_Pragma_Arg (Arg1));
14065 if Rep_Item_Too_Early (Ent, N) then
14068 Ent := Underlying_Type (Ent);
14071 -- The only processing required is to link this item on to the
14072 -- list of rep items for the given entity. This is accomplished
14073 -- by the call to Rep_Item_Too_Late (when no error is detected
14074 -- and False is returned).
14076 if Rep_Item_Too_Late (Ent, N) then
14079 Set_Has_Gigi_Rep_Item (Ent);
14083 -----------------------------
14084 -- Wide_Character_Encoding --
14085 -----------------------------
14087 -- pragma Wide_Character_Encoding (IDENTIFIER);
14089 when Pragma_Wide_Character_Encoding =>
14092 -- Nothing to do, handled in parser. Note that we do not enforce
14093 -- configuration pragma placement, this pragma can appear at any
14094 -- place in the source, allowing mixed encodings within a single
14099 --------------------
14100 -- Unknown_Pragma --
14101 --------------------
14103 -- Should be impossible, since the case of an unknown pragma is
14104 -- separately processed before the case statement is entered.
14106 when Unknown_Pragma =>
14107 raise Program_Error;
14110 -- AI05-0144: detect dangerous order dependence. Disabled for now,
14111 -- until AI is formally approved.
14113 -- Check_Order_Dependence;
14116 when Pragma_Exit => null;
14117 end Analyze_Pragma;
14119 -----------------------------
14120 -- Analyze_TC_In_Decl_Part --
14121 -----------------------------
14123 procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14125 -- Install formals and push subprogram spec onto scope stack so that we
14126 -- can see the formals from the pragma.
14128 Install_Formals (S);
14131 -- Preanalyze the boolean expressions, we treat these as spec
14132 -- expressions (i.e. similar to a default expression).
14134 Preanalyze_TC_Args (Get_Requires_From_Test_Case_Pragma (N),
14135 Get_Ensures_From_Test_Case_Pragma (N));
14137 -- Remove the subprogram from the scope stack now that the pre-analysis
14138 -- of the expressions in the test-case is done.
14141 end Analyze_TC_In_Decl_Part;
14143 -------------------
14144 -- Check_Enabled --
14145 -------------------
14147 function Check_Enabled (Nam : Name_Id) return Boolean is
14151 -- Loop through entries in check policy list
14153 PP := Opt.Check_Policy_List;
14155 -- If there are no specific entries that matched, then we let the
14156 -- setting of assertions govern. Note that this provides the needed
14157 -- compatibility with the RM for the cases of assertion, invariant,
14158 -- precondition, predicate, and postcondition.
14161 return Assertions_Enabled;
14163 -- Here we have an entry see if it matches
14167 PPA : constant List_Id := Pragma_Argument_Associations (PP);
14170 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14171 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14172 when Name_On | Name_Check =>
14174 when Name_Off | Name_Ignore =>
14177 raise Program_Error;
14181 PP := Next_Pragma (PP);
14188 ---------------------------------
14189 -- Delay_Config_Pragma_Analyze --
14190 ---------------------------------
14192 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14194 return Pragma_Name (N) = Name_Interrupt_State
14196 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14197 end Delay_Config_Pragma_Analyze;
14199 -------------------------
14200 -- Get_Base_Subprogram --
14201 -------------------------
14203 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14204 Result : Entity_Id;
14207 -- Follow subprogram renaming chain
14210 while Is_Subprogram (Result)
14212 Nkind (Parent (Declaration_Node (Result))) =
14213 N_Subprogram_Renaming_Declaration
14214 and then Present (Alias (Result))
14216 Result := Alias (Result);
14220 end Get_Base_Subprogram;
14226 procedure Initialize is
14231 -----------------------------
14232 -- Is_Config_Static_String --
14233 -----------------------------
14235 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14237 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14238 -- This is an internal recursive function that is just like the outer
14239 -- function except that it adds the string to the name buffer rather
14240 -- than placing the string in the name buffer.
14242 ------------------------------
14243 -- Add_Config_Static_String --
14244 ------------------------------
14246 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14253 if Nkind (N) = N_Op_Concat then
14254 if Add_Config_Static_String (Left_Opnd (N)) then
14255 N := Right_Opnd (N);
14261 if Nkind (N) /= N_String_Literal then
14262 Error_Msg_N ("string literal expected for pragma argument", N);
14266 for J in 1 .. String_Length (Strval (N)) loop
14267 C := Get_String_Char (Strval (N), J);
14269 if not In_Character_Range (C) then
14271 ("string literal contains invalid wide character",
14272 Sloc (N) + 1 + Source_Ptr (J));
14276 Add_Char_To_Name_Buffer (Get_Character (C));
14281 end Add_Config_Static_String;
14283 -- Start of processing for Is_Config_Static_String
14288 return Add_Config_Static_String (Arg);
14289 end Is_Config_Static_String;
14291 -----------------------------------------
14292 -- Is_Non_Significant_Pragma_Reference --
14293 -----------------------------------------
14295 -- This function makes use of the following static table which indicates
14296 -- whether a given pragma is significant.
14298 -- -1 indicates that references in any argument position are significant
14299 -- 0 indicates that appearance in any argument is not significant
14300 -- +n indicates that appearance as argument n is significant, but all
14301 -- other arguments are not significant
14302 -- 99 special processing required (e.g. for pragma Check)
14304 Sig_Flags : constant array (Pragma_Id) of Int :=
14305 (Pragma_AST_Entry => -1,
14306 Pragma_Abort_Defer => -1,
14307 Pragma_Ada_83 => -1,
14308 Pragma_Ada_95 => -1,
14309 Pragma_Ada_05 => -1,
14310 Pragma_Ada_2005 => -1,
14311 Pragma_Ada_12 => -1,
14312 Pragma_Ada_2012 => -1,
14313 Pragma_All_Calls_Remote => -1,
14314 Pragma_Annotate => -1,
14315 Pragma_Assert => -1,
14316 Pragma_Assertion_Policy => 0,
14317 Pragma_Assume_No_Invalid_Values => 0,
14318 Pragma_Asynchronous => -1,
14319 Pragma_Atomic => 0,
14320 Pragma_Atomic_Components => 0,
14321 Pragma_Attach_Handler => -1,
14322 Pragma_Check => 99,
14323 Pragma_Check_Name => 0,
14324 Pragma_Check_Policy => 0,
14325 Pragma_CIL_Constructor => -1,
14326 Pragma_CPP_Class => 0,
14327 Pragma_CPP_Constructor => 0,
14328 Pragma_CPP_Virtual => 0,
14329 Pragma_CPP_Vtable => 0,
14331 Pragma_C_Pass_By_Copy => 0,
14332 Pragma_Comment => 0,
14333 Pragma_Common_Object => -1,
14334 Pragma_Compile_Time_Error => -1,
14335 Pragma_Compile_Time_Warning => -1,
14336 Pragma_Compiler_Unit => 0,
14337 Pragma_Complete_Representation => 0,
14338 Pragma_Complex_Representation => 0,
14339 Pragma_Component_Alignment => -1,
14340 Pragma_Controlled => 0,
14341 Pragma_Convention => 0,
14342 Pragma_Convention_Identifier => 0,
14343 Pragma_Debug => -1,
14344 Pragma_Debug_Policy => 0,
14345 Pragma_Detect_Blocking => -1,
14346 Pragma_Default_Storage_Pool => -1,
14347 Pragma_Dimension => -1,
14348 Pragma_Discard_Names => 0,
14349 Pragma_Elaborate => -1,
14350 Pragma_Elaborate_All => -1,
14351 Pragma_Elaborate_Body => -1,
14352 Pragma_Elaboration_Checks => -1,
14353 Pragma_Eliminate => -1,
14354 Pragma_Export => -1,
14355 Pragma_Export_Exception => -1,
14356 Pragma_Export_Function => -1,
14357 Pragma_Export_Object => -1,
14358 Pragma_Export_Procedure => -1,
14359 Pragma_Export_Value => -1,
14360 Pragma_Export_Valued_Procedure => -1,
14361 Pragma_Extend_System => -1,
14362 Pragma_Extensions_Allowed => -1,
14363 Pragma_External => -1,
14364 Pragma_Favor_Top_Level => -1,
14365 Pragma_External_Name_Casing => -1,
14366 Pragma_Fast_Math => -1,
14367 Pragma_Finalize_Storage_Only => 0,
14368 Pragma_Float_Representation => 0,
14369 Pragma_Ident => -1,
14370 Pragma_Implemented => -1,
14371 Pragma_Implicit_Packing => 0,
14372 Pragma_Import => +2,
14373 Pragma_Import_Exception => 0,
14374 Pragma_Import_Function => 0,
14375 Pragma_Import_Object => 0,
14376 Pragma_Import_Procedure => 0,
14377 Pragma_Import_Valued_Procedure => 0,
14378 Pragma_Independent => 0,
14379 Pragma_Independent_Components => 0,
14380 Pragma_Initialize_Scalars => -1,
14381 Pragma_Inline => 0,
14382 Pragma_Inline_Always => 0,
14383 Pragma_Inline_Generic => 0,
14384 Pragma_Inspection_Point => -1,
14385 Pragma_Interface => +2,
14386 Pragma_Interface_Name => +2,
14387 Pragma_Interrupt_Handler => -1,
14388 Pragma_Interrupt_Priority => -1,
14389 Pragma_Interrupt_State => -1,
14390 Pragma_Invariant => -1,
14391 Pragma_Java_Constructor => -1,
14392 Pragma_Java_Interface => -1,
14393 Pragma_Keep_Names => 0,
14394 Pragma_License => -1,
14395 Pragma_Link_With => -1,
14396 Pragma_Linker_Alias => -1,
14397 Pragma_Linker_Constructor => -1,
14398 Pragma_Linker_Destructor => -1,
14399 Pragma_Linker_Options => -1,
14400 Pragma_Linker_Section => -1,
14402 Pragma_Locking_Policy => -1,
14403 Pragma_Long_Float => -1,
14404 Pragma_Machine_Attribute => -1,
14406 Pragma_Main_Storage => -1,
14407 Pragma_Memory_Size => -1,
14408 Pragma_No_Return => 0,
14409 Pragma_No_Body => 0,
14410 Pragma_No_Run_Time => -1,
14411 Pragma_No_Strict_Aliasing => -1,
14412 Pragma_Normalize_Scalars => -1,
14413 Pragma_Obsolescent => 0,
14414 Pragma_Optimize => -1,
14415 Pragma_Optimize_Alignment => -1,
14416 Pragma_Ordered => 0,
14419 Pragma_Passive => -1,
14420 Pragma_Preelaborable_Initialization => -1,
14421 Pragma_Polling => -1,
14422 Pragma_Persistent_BSS => 0,
14423 Pragma_Postcondition => -1,
14424 Pragma_Precondition => -1,
14425 Pragma_Predicate => -1,
14426 Pragma_Preelaborate => -1,
14427 Pragma_Preelaborate_05 => -1,
14428 Pragma_Priority => -1,
14429 Pragma_Priority_Specific_Dispatching => -1,
14430 Pragma_Profile => 0,
14431 Pragma_Profile_Warnings => 0,
14432 Pragma_Propagate_Exceptions => -1,
14433 Pragma_Psect_Object => -1,
14435 Pragma_Pure_05 => -1,
14436 Pragma_Pure_Function => -1,
14437 Pragma_Queuing_Policy => -1,
14438 Pragma_Ravenscar => -1,
14439 Pragma_Relative_Deadline => -1,
14440 Pragma_Remote_Call_Interface => -1,
14441 Pragma_Remote_Types => -1,
14442 Pragma_Restricted_Run_Time => -1,
14443 Pragma_Restriction_Warnings => -1,
14444 Pragma_Restrictions => -1,
14445 Pragma_Reviewable => -1,
14446 Pragma_Short_Circuit_And_Or => -1,
14447 Pragma_Share_Generic => -1,
14448 Pragma_Shared => -1,
14449 Pragma_Shared_Passive => -1,
14450 Pragma_Short_Descriptors => 0,
14451 Pragma_Source_File_Name => -1,
14452 Pragma_Source_File_Name_Project => -1,
14453 Pragma_Source_Reference => -1,
14454 Pragma_Storage_Size => -1,
14455 Pragma_Storage_Unit => -1,
14456 Pragma_Static_Elaboration_Desired => -1,
14457 Pragma_Stream_Convert => -1,
14458 Pragma_Style_Checks => -1,
14459 Pragma_Subtitle => -1,
14460 Pragma_Suppress => 0,
14461 Pragma_Suppress_Exception_Locations => 0,
14462 Pragma_Suppress_All => -1,
14463 Pragma_Suppress_Debug_Info => 0,
14464 Pragma_Suppress_Initialization => 0,
14465 Pragma_System_Name => -1,
14466 Pragma_Task_Dispatching_Policy => -1,
14467 Pragma_Task_Info => -1,
14468 Pragma_Task_Name => -1,
14469 Pragma_Task_Storage => 0,
14470 Pragma_Test_Case => -1,
14471 Pragma_Thread_Local_Storage => 0,
14472 Pragma_Time_Slice => -1,
14473 Pragma_Title => -1,
14474 Pragma_Unchecked_Union => 0,
14475 Pragma_Unimplemented_Unit => -1,
14476 Pragma_Universal_Aliasing => -1,
14477 Pragma_Universal_Data => -1,
14478 Pragma_Unmodified => -1,
14479 Pragma_Unreferenced => -1,
14480 Pragma_Unreferenced_Objects => -1,
14481 Pragma_Unreserve_All_Interrupts => -1,
14482 Pragma_Unsuppress => 0,
14483 Pragma_Use_VADS_Size => -1,
14484 Pragma_Validity_Checks => -1,
14485 Pragma_Volatile => 0,
14486 Pragma_Volatile_Components => 0,
14487 Pragma_Warnings => -1,
14488 Pragma_Weak_External => -1,
14489 Pragma_Wide_Character_Encoding => 0,
14490 Unknown_Pragma => 0);
14492 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14501 if Nkind (P) /= N_Pragma_Argument_Association then
14505 Id := Get_Pragma_Id (Parent (P));
14506 C := Sig_Flags (Id);
14518 -- For pragma Check, the first argument is not significant,
14519 -- the second and the third (if present) arguments are
14522 when Pragma_Check =>
14524 P = First (Pragma_Argument_Associations (Parent (P)));
14527 raise Program_Error;
14531 A := First (Pragma_Argument_Associations (Parent (P)));
14532 for J in 1 .. C - 1 loop
14540 return A = P; -- is this wrong way round ???
14543 end Is_Non_Significant_Pragma_Reference;
14545 ------------------------------
14546 -- Is_Pragma_String_Literal --
14547 ------------------------------
14549 -- This function returns true if the corresponding pragma argument is a
14550 -- static string expression. These are the only cases in which string
14551 -- literals can appear as pragma arguments. We also allow a string literal
14552 -- as the first argument to pragma Assert (although it will of course
14553 -- always generate a type error).
14555 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14556 Pragn : constant Node_Id := Parent (Par);
14557 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14558 Pname : constant Name_Id := Pragma_Name (Pragn);
14564 N := First (Assoc);
14571 if Pname = Name_Assert then
14574 elsif Pname = Name_Export then
14577 elsif Pname = Name_Ident then
14580 elsif Pname = Name_Import then
14583 elsif Pname = Name_Interface_Name then
14586 elsif Pname = Name_Linker_Alias then
14589 elsif Pname = Name_Linker_Section then
14592 elsif Pname = Name_Machine_Attribute then
14595 elsif Pname = Name_Source_File_Name then
14598 elsif Pname = Name_Source_Reference then
14601 elsif Pname = Name_Title then
14604 elsif Pname = Name_Subtitle then
14610 end Is_Pragma_String_Literal;
14612 ------------------------
14613 -- Preanalyze_TC_Args --
14614 ------------------------
14616 procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id) is
14618 -- Preanalyze the boolean expressions, we treat these as spec
14619 -- expressions (i.e. similar to a default expression).
14621 if Present (Arg_Req) then
14622 Preanalyze_Spec_Expression
14623 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
14626 if Present (Arg_Ens) then
14627 Preanalyze_Spec_Expression
14628 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
14630 end Preanalyze_TC_Args;
14632 --------------------------------------
14633 -- Process_Compilation_Unit_Pragmas --
14634 --------------------------------------
14636 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14638 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14639 -- strange because it comes at the end of the unit. Rational has the
14640 -- same name for a pragma, but treats it as a program unit pragma, In
14641 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14642 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14643 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14644 -- the context clause to ensure the correct processing.
14646 if Has_Pragma_Suppress_All (N) then
14647 Prepend_To (Context_Items (N),
14648 Make_Pragma (Sloc (N),
14649 Chars => Name_Suppress,
14650 Pragma_Argument_Associations => New_List (
14651 Make_Pragma_Argument_Association (Sloc (N),
14652 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14655 -- Nothing else to do at the current time!
14657 end Process_Compilation_Unit_Pragmas;
14668 --------------------------------
14669 -- Set_Encoded_Interface_Name --
14670 --------------------------------
14672 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14673 Str : constant String_Id := Strval (S);
14674 Len : constant Int := String_Length (Str);
14679 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14682 -- Stores encoded value of character code CC. The encoding we use an
14683 -- underscore followed by four lower case hex digits.
14689 procedure Encode is
14691 Store_String_Char (Get_Char_Code ('_'));
14693 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14695 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14697 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14699 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14702 -- Start of processing for Set_Encoded_Interface_Name
14705 -- If first character is asterisk, this is a link name, and we leave it
14706 -- completely unmodified. We also ignore null strings (the latter case
14707 -- happens only in error cases) and no encoding should occur for Java or
14708 -- AAMP interface names.
14711 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14712 or else VM_Target /= No_VM
14713 or else AAMP_On_Target
14715 Set_Interface_Name (E, S);
14720 CC := Get_String_Char (Str, J);
14722 exit when not In_Character_Range (CC);
14724 C := Get_Character (CC);
14726 exit when C /= '_' and then C /= '$'
14727 and then C not in '0' .. '9'
14728 and then C not in 'a' .. 'z'
14729 and then C not in 'A' .. 'Z';
14732 Set_Interface_Name (E, S);
14740 -- Here we need to encode. The encoding we use as follows:
14741 -- three underscores + four hex digits (lower case)
14745 for J in 1 .. String_Length (Str) loop
14746 CC := Get_String_Char (Str, J);
14748 if not In_Character_Range (CC) then
14751 C := Get_Character (CC);
14753 if C = '_' or else C = '$'
14754 or else C in '0' .. '9'
14755 or else C in 'a' .. 'z'
14756 or else C in 'A' .. 'Z'
14758 Store_String_Char (CC);
14765 Set_Interface_Name (E,
14766 Make_String_Literal (Sloc (S),
14767 Strval => End_String));
14769 end Set_Encoded_Interface_Name;
14771 -------------------
14772 -- Set_Unit_Name --
14773 -------------------
14775 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14780 if Nkind (N) = N_Identifier
14781 and then Nkind (With_Item) = N_Identifier
14783 Set_Entity (N, Entity (With_Item));
14785 elsif Nkind (N) = N_Selected_Component then
14786 Change_Selected_Component_To_Expanded_Name (N);
14787 Set_Entity (N, Entity (With_Item));
14788 Set_Entity (Selector_Name (N), Entity (N));
14790 Pref := Prefix (N);
14791 Scop := Scope (Entity (N));
14792 while Nkind (Pref) = N_Selected_Component loop
14793 Change_Selected_Component_To_Expanded_Name (Pref);
14794 Set_Entity (Selector_Name (Pref), Scop);
14795 Set_Entity (Pref, Scop);
14796 Pref := Prefix (Pref);
14797 Scop := Scope (Scop);
14800 Set_Entity (Pref, Scop);