1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, 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 Aspects
; use Aspects
;
33 with Atree
; use Atree
;
34 with Casing
; use Casing
;
35 with Checks
; use Checks
;
36 with Contracts
; use Contracts
;
37 with Csets
; use Csets
;
38 with Debug
; use Debug
;
39 with Einfo
; use Einfo
;
40 with Elists
; use Elists
;
41 with Errout
; use Errout
;
42 with Exp_Dist
; use Exp_Dist
;
43 with Exp_Util
; use Exp_Util
;
44 with Freeze
; use Freeze
;
45 with Ghost
; use Ghost
;
46 with Gnatvsn
; use Gnatvsn
;
48 with Lib
.Writ
; use Lib
.Writ
;
49 with Lib
.Xref
; use Lib
.Xref
;
50 with Namet
.Sp
; use Namet
.Sp
;
51 with Nlists
; use Nlists
;
52 with Nmake
; use Nmake
;
53 with Output
; use Output
;
54 with Par_SCO
; use Par_SCO
;
55 with Restrict
; use Restrict
;
56 with Rident
; use Rident
;
57 with Rtsfind
; use Rtsfind
;
59 with Sem_Aux
; use Sem_Aux
;
60 with Sem_Ch3
; use Sem_Ch3
;
61 with Sem_Ch6
; use Sem_Ch6
;
62 with Sem_Ch8
; use Sem_Ch8
;
63 with Sem_Ch12
; use Sem_Ch12
;
64 with Sem_Ch13
; use Sem_Ch13
;
65 with Sem_Disp
; use Sem_Disp
;
66 with Sem_Dist
; use Sem_Dist
;
67 with Sem_Elab
; use Sem_Elab
;
68 with Sem_Elim
; use Sem_Elim
;
69 with Sem_Eval
; use Sem_Eval
;
70 with Sem_Intr
; use Sem_Intr
;
71 with Sem_Mech
; use Sem_Mech
;
72 with Sem_Res
; use Sem_Res
;
73 with Sem_Type
; use Sem_Type
;
74 with Sem_Util
; use Sem_Util
;
75 with Sem_Warn
; use Sem_Warn
;
76 with Stand
; use Stand
;
77 with Sinfo
; use Sinfo
;
78 with Sinfo
.CN
; use Sinfo
.CN
;
79 with Sinput
; use Sinput
;
80 with Stringt
; use Stringt
;
81 with Stylesw
; use Stylesw
;
83 with Targparm
; use Targparm
;
84 with Tbuild
; use Tbuild
;
86 with Uintp
; use Uintp
;
87 with Uname
; use Uname
;
88 with Urealp
; use Urealp
;
89 with Validsw
; use Validsw
;
90 with Warnsw
; use Warnsw
;
92 with System
.Case_Util
;
94 package body Sem_Prag
is
96 ----------------------------------------------
97 -- Common Handling of Import-Export Pragmas --
98 ----------------------------------------------
100 -- In the following section, a number of Import_xxx and Export_xxx pragmas
101 -- are defined by GNAT. These are compatible with the DEC pragmas of the
102 -- same name, and all have the following common form and processing:
105 -- [Internal =>] LOCAL_NAME
106 -- [, [External =>] EXTERNAL_SYMBOL]
107 -- [, other optional parameters ]);
110 -- [Internal =>] LOCAL_NAME
111 -- [, [External =>] EXTERNAL_SYMBOL]
112 -- [, other optional parameters ]);
114 -- EXTERNAL_SYMBOL ::=
116 -- | static_string_EXPRESSION
118 -- The internal LOCAL_NAME designates the entity that is imported or
119 -- exported, and must refer to an entity in the current declarative
120 -- part (as required by the rules for LOCAL_NAME).
122 -- The external linker name is designated by the External parameter if
123 -- given, or the Internal parameter if not (if there is no External
124 -- parameter, the External parameter is a copy of the Internal name).
126 -- If the External parameter is given as a string, then this string is
127 -- treated as an external name (exactly as though it had been given as an
128 -- External_Name parameter for a normal Import pragma).
130 -- If the External parameter is given as an identifier (or there is no
131 -- External parameter, so that the Internal identifier is used), then
132 -- the external name is the characters of the identifier, translated
133 -- to all lower case letters.
135 -- Note: the external name specified or implied by any of these special
136 -- Import_xxx or Export_xxx pragmas override an external or link name
137 -- specified in a previous Import or Export pragma.
139 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
140 -- named notation, following the standard rules for subprogram calls, i.e.
141 -- parameters can be given in any order if named notation is used, and
142 -- positional and named notation can be mixed, subject to the rule that all
143 -- positional parameters must appear first.
145 -- Note: All these pragmas are implemented exactly following the DEC design
146 -- and implementation and are intended to be fully compatible with the use
147 -- of these pragmas in the DEC Ada compiler.
149 --------------------------------------------
150 -- Checking for Duplicated External Names --
151 --------------------------------------------
153 -- It is suspicious if two separate Export pragmas use the same external
154 -- name. The following table is used to diagnose this situation so that
155 -- an appropriate warning can be issued.
157 -- The Node_Id stored is for the N_String_Literal node created to hold
158 -- the value of the external name. The Sloc of this node is used to
159 -- cross-reference the location of the duplication.
161 package Externals
is new Table
.Table
(
162 Table_Component_Type
=> Node_Id
,
163 Table_Index_Type
=> Int
,
164 Table_Low_Bound
=> 0,
165 Table_Initial
=> 100,
166 Table_Increment
=> 100,
167 Table_Name
=> "Name_Externals");
169 -------------------------------------
170 -- Local Subprograms and Variables --
171 -------------------------------------
173 function Adjust_External_Name_Case
(N
: Node_Id
) return Node_Id
;
174 -- This routine is used for possible casing adjustment of an explicit
175 -- external name supplied as a string literal (the node N), according to
176 -- the casing requirement of Opt.External_Name_Casing. If this is set to
177 -- As_Is, then the string literal is returned unchanged, but if it is set
178 -- to Uppercase or Lowercase, then a new string literal with appropriate
179 -- casing is constructed.
181 procedure Analyze_Part_Of
185 Encap_Id
: out Entity_Id
;
186 Legal
: out Boolean);
187 -- Subsidiary to Analyze_Part_Of_In_Decl_Part, Analyze_Part_Of_Option and
188 -- Analyze_Pragma. Perform full analysis of indicator Part_Of. Indic is the
189 -- Part_Of indicator. Item_Id is the entity of an abstract state, object or
190 -- package instantiation. Encap denotes the encapsulating state or single
191 -- concurrent type. Encap_Id is the entity of Encap. Flag Legal is set when
192 -- the indicator is legal.
194 function Appears_In
(List
: Elist_Id
; Item_Id
: Entity_Id
) return Boolean;
195 -- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends.
196 -- Query whether a particular item appears in a mixed list of nodes and
197 -- entities. It is assumed that all nodes in the list have entities.
199 procedure Check_Postcondition_Use_In_Inlined_Subprogram
201 Spec_Id
: Entity_Id
);
202 -- Subsidiary to the analysis of pragmas Contract_Cases, Postcondition,
203 -- Precondition, Refined_Post, and Test_Case. Emit a warning when pragma
204 -- Prag is associated with subprogram Spec_Id subject to Inline_Always,
205 -- and assertions are enabled.
207 procedure Check_State_And_Constituent_Use
211 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
212 -- Global and Initializes. Determine whether a state from list States and a
213 -- corresponding constituent from list Constits (if any) appear in the same
214 -- context denoted by Context. If this is the case, emit an error.
216 procedure Contract_Freeze_Error
217 (Contract_Id
: Entity_Id
;
218 Freeze_Id
: Entity_Id
);
219 -- Subsidiary to the analysis of pragmas Contract_Cases, Part_Of, Post, and
220 -- Pre. Emit a freezing-related error message where Freeze_Id is the entity
221 -- of a body which caused contract freezing and Contract_Id denotes the
222 -- entity of the affected contstruct.
224 procedure Duplication_Error
(Prag
: Node_Id
; Prev
: Node_Id
);
225 -- Subsidiary to all Find_Related_xxx routines. Emit an error on pragma
226 -- Prag that duplicates previous pragma Prev.
228 function Find_Encapsulating_State
230 Constit_Id
: Entity_Id
) return Entity_Id
;
231 -- Given the entity of a constituent Constit_Id, find the corresponding
232 -- encapsulating state which appears in States. The routine returns Empty
233 -- if no such state is found.
235 function Find_Related_Context
237 Do_Checks
: Boolean := False) return Node_Id
;
238 -- Subsidiary to the analysis of pragmas
241 -- Constant_After_Elaboration
245 -- Find the first source declaration or statement found while traversing
246 -- the previous node chain starting from pragma Prag. If flag Do_Checks is
247 -- set, the routine reports duplicate pragmas. The routine returns Empty
248 -- when reaching the start of the node chain.
250 function Get_Base_Subprogram
(Def_Id
: Entity_Id
) return Entity_Id
;
251 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
252 -- original one, following the renaming chain) is returned. Otherwise the
253 -- entity is returned unchanged. Should be in Einfo???
255 function Get_SPARK_Mode_Type
(N
: Name_Id
) return SPARK_Mode_Type
;
256 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
257 -- Get_SPARK_Mode_From_Annotation. Convert a name into a corresponding
258 -- value of type SPARK_Mode_Type.
260 function Has_Extra_Parentheses
(Clause
: Node_Id
) return Boolean;
261 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
262 -- Determine whether dependency clause Clause is surrounded by extra
263 -- parentheses. If this is the case, issue an error message.
265 function Is_Unconstrained_Or_Tagged_Item
(Item
: Entity_Id
) return Boolean;
266 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
267 -- pragma Depends. Determine whether the type of dependency item Item is
268 -- tagged, unconstrained array, unconstrained record or a record with at
269 -- least one unconstrained component.
271 procedure Record_Possible_Body_Reference
272 (State_Id
: Entity_Id
;
274 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
275 -- Global. Given an abstract state denoted by State_Id and a reference Ref
276 -- to it, determine whether the reference appears in a package body that
277 -- will eventually refine the state. If this is the case, record the
278 -- reference for future checks (see Analyze_Refined_State_In_Decls).
280 procedure Resolve_State
(N
: Node_Id
);
281 -- Handle the overloading of state names by functions. When N denotes a
282 -- function, this routine finds the corresponding state and sets the entity
283 -- of N to that of the state.
285 procedure Rewrite_Assertion_Kind
287 From_Policy
: Boolean := False);
288 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
289 -- then it is rewritten as an identifier with the corresponding special
290 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
291 -- and Check_Policy. If the names are Precondition or Postcondition, this
292 -- combination is deprecated in favor of Assertion_Policy and Ada2012
293 -- Aspect names. The parameter From_Policy indicates that the pragma
294 -- is the old non-standard Check_Policy and not a rewritten pragma.
296 procedure Set_Elab_Unit_Name
(N
: Node_Id
; With_Item
: Node_Id
);
297 -- Place semantic information on the argument of an Elaborate/Elaborate_All
298 -- pragma. Entity name for unit and its parents is taken from item in
299 -- previous with_clause that mentions the unit.
301 Dummy
: Integer := 0;
302 pragma Volatile
(Dummy
);
303 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
306 pragma No_Inline
(ip
);
307 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
308 -- is just to help debugging the front end. If a pragma Inspection_Point
309 -- is added to a source program, then breaking on ip will get you to that
310 -- point in the program.
313 pragma No_Inline
(rv
);
314 -- This is a dummy function called by the processing for pragma Reviewable.
315 -- It is there for assisting front end debugging. By placing a Reviewable
316 -- pragma in the source program, a breakpoint on rv catches this place in
317 -- the source, allowing convenient stepping to the point of interest.
319 -------------------------------
320 -- Adjust_External_Name_Case --
321 -------------------------------
323 function Adjust_External_Name_Case
(N
: Node_Id
) return Node_Id
is
327 -- Adjust case of literal if required
329 if Opt
.External_Name_Exp_Casing
= As_Is
then
333 -- Copy existing string
339 for J
in 1 .. String_Length
(Strval
(N
)) loop
340 CC
:= Get_String_Char
(Strval
(N
), J
);
342 if Opt
.External_Name_Exp_Casing
= Uppercase
343 and then CC
>= Get_Char_Code
('a')
344 and then CC
<= Get_Char_Code
('z')
346 Store_String_Char
(CC
- 32);
348 elsif Opt
.External_Name_Exp_Casing
= Lowercase
349 and then CC
>= Get_Char_Code
('A')
350 and then CC
<= Get_Char_Code
('Z')
352 Store_String_Char
(CC
+ 32);
355 Store_String_Char
(CC
);
360 Make_String_Literal
(Sloc
(N
),
361 Strval
=> End_String
);
363 end Adjust_External_Name_Case
;
365 -----------------------------------------
366 -- Analyze_Contract_Cases_In_Decl_Part --
367 -----------------------------------------
369 -- WARNING: This routine manages Ghost regions. Return statements must be
370 -- replaced by gotos which jump to the end of the routine and restore the
373 procedure Analyze_Contract_Cases_In_Decl_Part
375 Freeze_Id
: Entity_Id
:= Empty
)
377 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
378 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
380 Others_Seen
: Boolean := False;
381 -- This flag is set when an "others" choice is encountered. It is used
382 -- to detect multiple illegal occurrences of "others".
384 procedure Analyze_Contract_Case
(CCase
: Node_Id
);
385 -- Verify the legality of a single contract case
387 ---------------------------
388 -- Analyze_Contract_Case --
389 ---------------------------
391 procedure Analyze_Contract_Case
(CCase
: Node_Id
) is
392 Case_Guard
: Node_Id
;
395 Extra_Guard
: Node_Id
;
398 if Nkind
(CCase
) = N_Component_Association
then
399 Case_Guard
:= First
(Choices
(CCase
));
400 Conseq
:= Expression
(CCase
);
402 -- Each contract case must have exactly one case guard
404 Extra_Guard
:= Next
(Case_Guard
);
406 if Present
(Extra_Guard
) then
408 ("contract case must have exactly one case guard",
412 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
414 if Nkind
(Case_Guard
) = N_Others_Choice
then
417 ("only one others choice allowed in contract cases",
423 elsif Others_Seen
then
425 ("others must be the last choice in contract cases", N
);
428 -- Preanalyze the case guard and consequence
430 if Nkind
(Case_Guard
) /= N_Others_Choice
then
431 Errors
:= Serious_Errors_Detected
;
432 Preanalyze_Assert_Expression
(Case_Guard
, Standard_Boolean
);
434 -- Emit a clarification message when the case guard contains
435 -- at least one undefined reference, possibly due to contract
438 if Errors
/= Serious_Errors_Detected
439 and then Present
(Freeze_Id
)
440 and then Has_Undefined_Reference
(Case_Guard
)
442 Contract_Freeze_Error
(Spec_Id
, Freeze_Id
);
446 Errors
:= Serious_Errors_Detected
;
447 Preanalyze_Assert_Expression
(Conseq
, Standard_Boolean
);
449 -- Emit a clarification message when the consequence contains
450 -- at least one undefined reference, possibly due to contract
453 if Errors
/= Serious_Errors_Detected
454 and then Present
(Freeze_Id
)
455 and then Has_Undefined_Reference
(Conseq
)
457 Contract_Freeze_Error
(Spec_Id
, Freeze_Id
);
460 -- The contract case is malformed
463 Error_Msg_N
("wrong syntax in contract case", CCase
);
465 end Analyze_Contract_Case
;
469 CCases
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
471 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
472 -- Save the Ghost mode to restore on exit
475 Restore_Scope
: Boolean := False;
477 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
480 -- Do not analyze the pragma multiple times
482 if Is_Analyzed_Pragma
(N
) then
486 -- Set the Ghost mode in effect from the pragma. Due to the delayed
487 -- analysis of the pragma, the Ghost mode at point of declaration and
488 -- point of analysis may not necessarily be the same. Use the mode in
489 -- effect at the point of declaration.
493 -- Single and multiple contract cases must appear in aggregate form. If
494 -- this is not the case, then either the parser of the analysis of the
495 -- pragma failed to produce an aggregate.
497 pragma Assert
(Nkind
(CCases
) = N_Aggregate
);
499 if Present
(Component_Associations
(CCases
)) then
501 -- Ensure that the formal parameters are visible when analyzing all
502 -- clauses. This falls out of the general rule of aspects pertaining
503 -- to subprogram declarations.
505 if not In_Open_Scopes
(Spec_Id
) then
506 Restore_Scope
:= True;
507 Push_Scope
(Spec_Id
);
509 if Is_Generic_Subprogram
(Spec_Id
) then
510 Install_Generic_Formals
(Spec_Id
);
512 Install_Formals
(Spec_Id
);
516 CCase
:= First
(Component_Associations
(CCases
));
517 while Present
(CCase
) loop
518 Analyze_Contract_Case
(CCase
);
522 if Restore_Scope
then
526 -- Currently it is not possible to inline pre/postconditions on a
527 -- subprogram subject to pragma Inline_Always.
529 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
531 -- Otherwise the pragma is illegal
534 Error_Msg_N
("wrong syntax for constract cases", N
);
537 Set_Is_Analyzed_Pragma
(N
);
539 Restore_Ghost_Mode
(Saved_GM
);
540 end Analyze_Contract_Cases_In_Decl_Part
;
542 ----------------------------------
543 -- Analyze_Depends_In_Decl_Part --
544 ----------------------------------
546 procedure Analyze_Depends_In_Decl_Part
(N
: Node_Id
) is
547 Loc
: constant Source_Ptr
:= Sloc
(N
);
548 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
549 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
551 All_Inputs_Seen
: Elist_Id
:= No_Elist
;
552 -- A list containing the entities of all the inputs processed so far.
553 -- The list is populated with unique entities because the same input
554 -- may appear in multiple input lists.
556 All_Outputs_Seen
: Elist_Id
:= No_Elist
;
557 -- A list containing the entities of all the outputs processed so far.
558 -- The list is populated with unique entities because output items are
559 -- unique in a dependence relation.
561 Constits_Seen
: Elist_Id
:= No_Elist
;
562 -- A list containing the entities of all constituents processed so far.
563 -- It aids in detecting illegal usage of a state and a corresponding
564 -- constituent in pragma [Refinde_]Depends.
566 Global_Seen
: Boolean := False;
567 -- A flag set when pragma Global has been processed
569 Null_Output_Seen
: Boolean := False;
570 -- A flag used to track the legality of a null output
572 Result_Seen
: Boolean := False;
573 -- A flag set when Spec_Id'Result is processed
575 States_Seen
: Elist_Id
:= No_Elist
;
576 -- A list containing the entities of all states processed so far. It
577 -- helps in detecting illegal usage of a state and a corresponding
578 -- constituent in pragma [Refined_]Depends.
580 Subp_Inputs
: Elist_Id
:= No_Elist
;
581 Subp_Outputs
: Elist_Id
:= No_Elist
;
582 -- Two lists containing the full set of inputs and output of the related
583 -- subprograms. Note that these lists contain both nodes and entities.
585 Task_Input_Seen
: Boolean := False;
586 Task_Output_Seen
: Boolean := False;
587 -- Flags used to track the implicit dependence of a task unit on itself
589 procedure Add_Item_To_Name_Buffer
(Item_Id
: Entity_Id
);
590 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
591 -- to the name buffer. The individual kinds are as follows:
592 -- E_Abstract_State - "state"
593 -- E_Constant - "constant"
594 -- E_Generic_In_Out_Parameter - "generic parameter"
595 -- E_Generic_In_Parameter - "generic parameter"
596 -- E_In_Parameter - "parameter"
597 -- E_In_Out_Parameter - "parameter"
598 -- E_Loop_Parameter - "loop parameter"
599 -- E_Out_Parameter - "parameter"
600 -- E_Protected_Type - "current instance of protected type"
601 -- E_Task_Type - "current instance of task type"
602 -- E_Variable - "global"
604 procedure Analyze_Dependency_Clause
607 -- Verify the legality of a single dependency clause. Flag Is_Last
608 -- denotes whether Clause is the last clause in the relation.
610 procedure Check_Function_Return
;
611 -- Verify that Funtion'Result appears as one of the outputs
612 -- (SPARK RM 6.1.5(10)).
619 -- Ensure that an item fulfills its designated input and/or output role
620 -- as specified by pragma Global (if any) or the enclosing context. If
621 -- this is not the case, emit an error. Item and Item_Id denote the
622 -- attributes of an item. Flag Is_Input should be set when item comes
623 -- from an input list. Flag Self_Ref should be set when the item is an
624 -- output and the dependency clause has operator "+".
626 procedure Check_Usage
627 (Subp_Items
: Elist_Id
;
628 Used_Items
: Elist_Id
;
630 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
631 -- error if this is not the case.
633 procedure Normalize_Clause
(Clause
: Node_Id
);
634 -- Remove a self-dependency "+" from the input list of a clause
636 -----------------------------
637 -- Add_Item_To_Name_Buffer --
638 -----------------------------
640 procedure Add_Item_To_Name_Buffer
(Item_Id
: Entity_Id
) is
642 if Ekind
(Item_Id
) = E_Abstract_State
then
643 Add_Str_To_Name_Buffer
("state");
645 elsif Ekind
(Item_Id
) = E_Constant
then
646 Add_Str_To_Name_Buffer
("constant");
648 elsif Ekind_In
(Item_Id
, E_Generic_In_Out_Parameter
,
649 E_Generic_In_Parameter
)
651 Add_Str_To_Name_Buffer
("generic parameter");
653 elsif Is_Formal
(Item_Id
) then
654 Add_Str_To_Name_Buffer
("parameter");
656 elsif Ekind
(Item_Id
) = E_Loop_Parameter
then
657 Add_Str_To_Name_Buffer
("loop parameter");
659 elsif Ekind
(Item_Id
) = E_Protected_Type
660 or else Is_Single_Protected_Object
(Item_Id
)
662 Add_Str_To_Name_Buffer
("current instance of protected type");
664 elsif Ekind
(Item_Id
) = E_Task_Type
665 or else Is_Single_Task_Object
(Item_Id
)
667 Add_Str_To_Name_Buffer
("current instance of task type");
669 elsif Ekind
(Item_Id
) = E_Variable
then
670 Add_Str_To_Name_Buffer
("global");
672 -- The routine should not be called with non-SPARK items
677 end Add_Item_To_Name_Buffer
;
679 -------------------------------
680 -- Analyze_Dependency_Clause --
681 -------------------------------
683 procedure Analyze_Dependency_Clause
687 procedure Analyze_Input_List
(Inputs
: Node_Id
);
688 -- Verify the legality of a single input list
690 procedure Analyze_Input_Output
695 Seen
: in out Elist_Id
;
696 Null_Seen
: in out Boolean;
697 Non_Null_Seen
: in out Boolean);
698 -- Verify the legality of a single input or output item. Flag
699 -- Is_Input should be set whenever Item is an input, False when it
700 -- denotes an output. Flag Self_Ref should be set when the item is an
701 -- output and the dependency clause has a "+". Flag Top_Level should
702 -- be set whenever Item appears immediately within an input or output
703 -- list. Seen is a collection of all abstract states, objects and
704 -- formals processed so far. Flag Null_Seen denotes whether a null
705 -- input or output has been encountered. Flag Non_Null_Seen denotes
706 -- whether a non-null input or output has been encountered.
708 ------------------------
709 -- Analyze_Input_List --
710 ------------------------
712 procedure Analyze_Input_List
(Inputs
: Node_Id
) is
713 Inputs_Seen
: Elist_Id
:= No_Elist
;
714 -- A list containing the entities of all inputs that appear in the
715 -- current input list.
717 Non_Null_Input_Seen
: Boolean := False;
718 Null_Input_Seen
: Boolean := False;
719 -- Flags used to check the legality of an input list
724 -- Multiple inputs appear as an aggregate
726 if Nkind
(Inputs
) = N_Aggregate
then
727 if Present
(Component_Associations
(Inputs
)) then
729 ("nested dependency relations not allowed", Inputs
);
731 elsif Present
(Expressions
(Inputs
)) then
732 Input
:= First
(Expressions
(Inputs
));
733 while Present
(Input
) loop
740 Null_Seen
=> Null_Input_Seen
,
741 Non_Null_Seen
=> Non_Null_Input_Seen
);
746 -- Syntax error, always report
749 Error_Msg_N
("malformed input dependency list", Inputs
);
752 -- Process a solitary input
761 Null_Seen
=> Null_Input_Seen
,
762 Non_Null_Seen
=> Non_Null_Input_Seen
);
765 -- Detect an illegal dependency clause of the form
769 if Null_Output_Seen
and then Null_Input_Seen
then
771 ("null dependency clause cannot have a null input list",
774 end Analyze_Input_List
;
776 --------------------------
777 -- Analyze_Input_Output --
778 --------------------------
780 procedure Analyze_Input_Output
785 Seen
: in out Elist_Id
;
786 Null_Seen
: in out Boolean;
787 Non_Null_Seen
: in out Boolean)
789 procedure Current_Task_Instance_Seen
;
790 -- Set the appropriate global flag when the current instance of a
791 -- task unit is encountered.
793 --------------------------------
794 -- Current_Task_Instance_Seen --
795 --------------------------------
797 procedure Current_Task_Instance_Seen
is
800 Task_Input_Seen
:= True;
802 Task_Output_Seen
:= True;
804 end Current_Task_Instance_Seen
;
808 Is_Output
: constant Boolean := not Is_Input
;
812 -- Start of processing for Analyze_Input_Output
815 -- Multiple input or output items appear as an aggregate
817 if Nkind
(Item
) = N_Aggregate
then
818 if not Top_Level
then
819 SPARK_Msg_N
("nested grouping of items not allowed", Item
);
821 elsif Present
(Component_Associations
(Item
)) then
823 ("nested dependency relations not allowed", Item
);
825 -- Recursively analyze the grouped items
827 elsif Present
(Expressions
(Item
)) then
828 Grouped
:= First
(Expressions
(Item
));
829 while Present
(Grouped
) loop
832 Is_Input
=> Is_Input
,
833 Self_Ref
=> Self_Ref
,
836 Null_Seen
=> Null_Seen
,
837 Non_Null_Seen
=> Non_Null_Seen
);
842 -- Syntax error, always report
845 Error_Msg_N
("malformed dependency list", Item
);
848 -- Process attribute 'Result in the context of a dependency clause
850 elsif Is_Attribute_Result
(Item
) then
851 Non_Null_Seen
:= True;
855 -- Attribute 'Result is allowed to appear on the output side of
856 -- a dependency clause (SPARK RM 6.1.5(6)).
859 SPARK_Msg_N
("function result cannot act as input", Item
);
863 ("cannot mix null and non-null dependency items", Item
);
869 -- Detect multiple uses of null in a single dependency list or
870 -- throughout the whole relation. Verify the placement of a null
871 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
873 elsif Nkind
(Item
) = N_Null
then
876 ("multiple null dependency relations not allowed", Item
);
878 elsif Non_Null_Seen
then
880 ("cannot mix null and non-null dependency items", Item
);
888 ("null output list must be the last clause in a "
889 & "dependency relation", Item
);
891 -- Catch a useless dependence of the form:
896 ("useless dependence, null depends on itself", Item
);
904 Non_Null_Seen
:= True;
907 SPARK_Msg_N
("cannot mix null and non-null items", Item
);
911 Resolve_State
(Item
);
913 -- Find the entity of the item. If this is a renaming, climb
914 -- the renaming chain to reach the root object. Renamings of
915 -- non-entire objects do not yield an entity (Empty).
917 Item_Id
:= Entity_Of
(Item
);
919 if Present
(Item_Id
) then
923 if Ekind_In
(Item_Id
, E_Constant
, E_Loop_Parameter
)
926 -- Current instances of concurrent types
928 Ekind_In
(Item_Id
, E_Protected_Type
, E_Task_Type
)
933 Ekind_In
(Item_Id
, E_Generic_In_Out_Parameter
,
934 E_Generic_In_Parameter
,
942 Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
)
944 -- The item denotes a concurrent type. Note that single
945 -- protected/task types are not considered here because
946 -- they behave as objects in the context of pragma
947 -- [Refined_]Depends.
949 if Ekind_In
(Item_Id
, E_Protected_Type
, E_Task_Type
) then
951 -- This use is legal as long as the concurrent type is
952 -- the current instance of an enclosing type.
954 if Is_CCT_Instance
(Item_Id
, Spec_Id
) then
956 -- The dependence of a task unit on itself is
957 -- implicit and may or may not be explicitly
958 -- specified (SPARK RM 6.1.4).
960 if Ekind
(Item_Id
) = E_Task_Type
then
961 Current_Task_Instance_Seen
;
964 -- Otherwise this is not the current instance
968 ("invalid use of subtype mark in dependency "
972 -- The dependency of a task unit on itself is implicit
973 -- and may or may not be explicitly specified
976 elsif Is_Single_Task_Object
(Item_Id
)
977 and then Is_CCT_Instance
(Etype
(Item_Id
), Spec_Id
)
979 Current_Task_Instance_Seen
;
982 -- Ensure that the item fulfills its role as input and/or
983 -- output as specified by pragma Global or the enclosing
986 Check_Role
(Item
, Item_Id
, Is_Input
, Self_Ref
);
988 -- Detect multiple uses of the same state, variable or
989 -- formal parameter. If this is not the case, add the
990 -- item to the list of processed relations.
992 if Contains
(Seen
, Item_Id
) then
994 ("duplicate use of item &", Item
, Item_Id
);
996 Append_New_Elmt
(Item_Id
, Seen
);
999 -- Detect illegal use of an input related to a null
1000 -- output. Such input items cannot appear in other
1001 -- input lists (SPARK RM 6.1.5(13)).
1004 and then Null_Output_Seen
1005 and then Contains
(All_Inputs_Seen
, Item_Id
)
1008 ("input of a null output list cannot appear in "
1009 & "multiple input lists", Item
);
1012 -- Add an input or a self-referential output to the list
1013 -- of all processed inputs.
1015 if Is_Input
or else Self_Ref
then
1016 Append_New_Elmt
(Item_Id
, All_Inputs_Seen
);
1019 -- State related checks (SPARK RM 6.1.5(3))
1021 if Ekind
(Item_Id
) = E_Abstract_State
then
1023 -- Package and subprogram bodies are instantiated
1024 -- individually in a separate compiler pass. Due to
1025 -- this mode of instantiation, the refinement of a
1026 -- state may no longer be visible when a subprogram
1027 -- body contract is instantiated. Since the generic
1028 -- template is legal, do not perform this check in
1029 -- the instance to circumvent this oddity.
1031 if Is_Generic_Instance
(Spec_Id
) then
1034 -- An abstract state with visible refinement cannot
1035 -- appear in pragma [Refined_]Depends as its place
1036 -- must be taken by some of its constituents
1037 -- (SPARK RM 6.1.4(7)).
1039 elsif Has_Visible_Refinement
(Item_Id
) then
1041 ("cannot mention state & in dependence relation",
1043 SPARK_Msg_N
("\use its constituents instead", Item
);
1046 -- If the reference to the abstract state appears in
1047 -- an enclosing package body that will eventually
1048 -- refine the state, record the reference for future
1052 Record_Possible_Body_Reference
1053 (State_Id
=> Item_Id
,
1058 -- When the item renames an entire object, replace the
1059 -- item with a reference to the object.
1061 if Entity
(Item
) /= Item_Id
then
1063 New_Occurrence_Of
(Item_Id
, Sloc
(Item
)));
1067 -- Add the entity of the current item to the list of
1070 if Ekind
(Item_Id
) = E_Abstract_State
then
1071 Append_New_Elmt
(Item_Id
, States_Seen
);
1073 -- The variable may eventually become a constituent of a
1074 -- single protected/task type. Record the reference now
1075 -- and verify its legality when analyzing the contract of
1076 -- the variable (SPARK RM 9.3).
1078 elsif Ekind
(Item_Id
) = E_Variable
then
1079 Record_Possible_Part_Of_Reference
1084 if Ekind_In
(Item_Id
, E_Abstract_State
,
1087 and then Present
(Encapsulating_State
(Item_Id
))
1089 Append_New_Elmt
(Item_Id
, Constits_Seen
);
1092 -- All other input/output items are illegal
1093 -- (SPARK RM 6.1.5(1)).
1097 ("item must denote parameter, variable, state or "
1098 & "current instance of concurrent type", Item
);
1101 -- All other input/output items are illegal
1102 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1106 ("item must denote parameter, variable, state or current "
1107 & "instance of concurrent type", Item
);
1110 end Analyze_Input_Output
;
1118 Non_Null_Output_Seen
: Boolean := False;
1119 -- Flag used to check the legality of an output list
1121 -- Start of processing for Analyze_Dependency_Clause
1124 Inputs
:= Expression
(Clause
);
1127 -- An input list with a self-dependency appears as operator "+" where
1128 -- the actuals inputs are the right operand.
1130 if Nkind
(Inputs
) = N_Op_Plus
then
1131 Inputs
:= Right_Opnd
(Inputs
);
1135 -- Process the output_list of a dependency_clause
1137 Output
:= First
(Choices
(Clause
));
1138 while Present
(Output
) loop
1139 Analyze_Input_Output
1142 Self_Ref
=> Self_Ref
,
1144 Seen
=> All_Outputs_Seen
,
1145 Null_Seen
=> Null_Output_Seen
,
1146 Non_Null_Seen
=> Non_Null_Output_Seen
);
1151 -- Process the input_list of a dependency_clause
1153 Analyze_Input_List
(Inputs
);
1154 end Analyze_Dependency_Clause
;
1156 ---------------------------
1157 -- Check_Function_Return --
1158 ---------------------------
1160 procedure Check_Function_Return
is
1162 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
1163 and then not Result_Seen
1166 ("result of & must appear in exactly one output list",
1169 end Check_Function_Return
;
1175 procedure Check_Role
1177 Item_Id
: Entity_Id
;
1182 (Item_Is_Input
: out Boolean;
1183 Item_Is_Output
: out Boolean);
1184 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1185 -- Item_Is_Output are set depending on the role.
1187 procedure Role_Error
1188 (Item_Is_Input
: Boolean;
1189 Item_Is_Output
: Boolean);
1190 -- Emit an error message concerning the incorrect use of Item in
1191 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1192 -- denote whether the item is an input and/or an output.
1199 (Item_Is_Input
: out Boolean;
1200 Item_Is_Output
: out Boolean)
1203 case Ekind
(Item_Id
) is
1207 when E_Abstract_State
=>
1209 -- When pragma Global is present it determines the mode of
1210 -- the abstract state.
1213 Item_Is_Input
:= Appears_In
(Subp_Inputs
, Item_Id
);
1214 Item_Is_Output
:= Appears_In
(Subp_Outputs
, Item_Id
);
1216 -- Otherwise the state has a default IN OUT mode, because it
1217 -- behaves as a variable.
1220 Item_Is_Input
:= True;
1221 Item_Is_Output
:= True;
1224 -- Constants and IN parameters
1227 | E_Generic_In_Parameter
1231 -- When pragma Global is present it determines the mode
1232 -- of constant objects as inputs (and such objects cannot
1233 -- appear as outputs in the Global contract).
1236 Item_Is_Input
:= Appears_In
(Subp_Inputs
, Item_Id
);
1238 Item_Is_Input
:= True;
1241 Item_Is_Output
:= False;
1243 -- Variables and IN OUT parameters
1245 when E_Generic_In_Out_Parameter
1246 | E_In_Out_Parameter
1249 -- When pragma Global is present it determines the mode of
1254 -- A variable has mode IN when its type is unconstrained
1255 -- or tagged because array bounds, discriminants or tags
1259 Appears_In
(Subp_Inputs
, Item_Id
)
1260 or else Is_Unconstrained_Or_Tagged_Item
(Item_Id
);
1262 Item_Is_Output
:= Appears_In
(Subp_Outputs
, Item_Id
);
1264 -- Otherwise the variable has a default IN OUT mode
1267 Item_Is_Input
:= True;
1268 Item_Is_Output
:= True;
1271 when E_Out_Parameter
=>
1273 -- An OUT parameter of the related subprogram; it cannot
1274 -- appear in Global.
1276 if Scope
(Item_Id
) = Spec_Id
then
1278 -- The parameter has mode IN if its type is unconstrained
1279 -- or tagged because array bounds, discriminants or tags
1283 Is_Unconstrained_Or_Tagged_Item
(Item_Id
);
1285 Item_Is_Output
:= True;
1287 -- An OUT parameter of an enclosing subprogram; it can
1288 -- appear in Global and behaves as a read-write variable.
1291 -- When pragma Global is present it determines the mode
1296 -- A variable has mode IN when its type is
1297 -- unconstrained or tagged because array
1298 -- bounds, discriminants or tags can be read.
1301 Appears_In
(Subp_Inputs
, Item_Id
)
1302 or else Is_Unconstrained_Or_Tagged_Item
(Item_Id
);
1304 Item_Is_Output
:= Appears_In
(Subp_Outputs
, Item_Id
);
1306 -- Otherwise the variable has a default IN OUT mode
1309 Item_Is_Input
:= True;
1310 Item_Is_Output
:= True;
1316 when E_Protected_Type
=>
1319 -- A variable has mode IN when its type is unconstrained
1320 -- or tagged because array bounds, discriminants or tags
1324 Appears_In
(Subp_Inputs
, Item_Id
)
1325 or else Is_Unconstrained_Or_Tagged_Item
(Item_Id
);
1327 Item_Is_Output
:= Appears_In
(Subp_Outputs
, Item_Id
);
1330 -- A protected type acts as a formal parameter of mode IN
1331 -- when it applies to a protected function.
1333 if Ekind
(Spec_Id
) = E_Function
then
1334 Item_Is_Input
:= True;
1335 Item_Is_Output
:= False;
1337 -- Otherwise the protected type acts as a formal of mode
1341 Item_Is_Input
:= True;
1342 Item_Is_Output
:= True;
1350 -- When pragma Global is present it determines the mode of
1355 Appears_In
(Subp_Inputs
, Item_Id
)
1356 or else Is_Unconstrained_Or_Tagged_Item
(Item_Id
);
1358 Item_Is_Output
:= Appears_In
(Subp_Outputs
, Item_Id
);
1360 -- Otherwise task types act as IN OUT parameters
1363 Item_Is_Input
:= True;
1364 Item_Is_Output
:= True;
1368 raise Program_Error
;
1376 procedure Role_Error
1377 (Item_Is_Input
: Boolean;
1378 Item_Is_Output
: Boolean)
1380 Error_Msg
: Name_Id
;
1385 -- When the item is not part of the input and the output set of
1386 -- the related subprogram, then it appears as extra in pragma
1387 -- [Refined_]Depends.
1389 if not Item_Is_Input
and then not Item_Is_Output
then
1390 Add_Item_To_Name_Buffer
(Item_Id
);
1391 Add_Str_To_Name_Buffer
1392 (" & cannot appear in dependence relation");
1394 Error_Msg
:= Name_Find
;
1395 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), Item
, Item_Id
);
1397 Error_Msg_Name_1
:= Chars
(Spec_Id
);
1399 (Fix_Msg
(Spec_Id
, "\& is not part of the input or output "
1400 & "set of subprogram %"), Item
, Item_Id
);
1402 -- The mode of the item and its role in pragma [Refined_]Depends
1403 -- are in conflict. Construct a detailed message explaining the
1404 -- illegality (SPARK RM 6.1.5(5-6)).
1407 if Item_Is_Input
then
1408 Add_Str_To_Name_Buffer
("read-only");
1410 Add_Str_To_Name_Buffer
("write-only");
1413 Add_Char_To_Name_Buffer
(' ');
1414 Add_Item_To_Name_Buffer
(Item_Id
);
1415 Add_Str_To_Name_Buffer
(" & cannot appear as ");
1417 if Item_Is_Input
then
1418 Add_Str_To_Name_Buffer
("output");
1420 Add_Str_To_Name_Buffer
("input");
1423 Add_Str_To_Name_Buffer
(" in dependence relation");
1424 Error_Msg
:= Name_Find
;
1425 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), Item
, Item_Id
);
1431 Item_Is_Input
: Boolean;
1432 Item_Is_Output
: Boolean;
1434 -- Start of processing for Check_Role
1437 Find_Role
(Item_Is_Input
, Item_Is_Output
);
1442 if not Item_Is_Input
then
1443 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1446 -- Self-referential item
1449 if not Item_Is_Input
or else not Item_Is_Output
then
1450 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1455 elsif not Item_Is_Output
then
1456 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1464 procedure Check_Usage
1465 (Subp_Items
: Elist_Id
;
1466 Used_Items
: Elist_Id
;
1469 procedure Usage_Error
(Item_Id
: Entity_Id
);
1470 -- Emit an error concerning the illegal usage of an item
1476 procedure Usage_Error
(Item_Id
: Entity_Id
) is
1477 Error_Msg
: Name_Id
;
1484 -- Unconstrained and tagged items are not part of the explicit
1485 -- input set of the related subprogram, they do not have to be
1486 -- present in a dependence relation and should not be flagged
1487 -- (SPARK RM 6.1.5(5)).
1489 if not Is_Unconstrained_Or_Tagged_Item
(Item_Id
) then
1492 Add_Item_To_Name_Buffer
(Item_Id
);
1493 Add_Str_To_Name_Buffer
1494 (" & is missing from input dependence list");
1496 Error_Msg
:= Name_Find
;
1497 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), N
, Item_Id
);
1499 ("\add `null ='> &` dependency to ignore this input",
1503 -- Output case (SPARK RM 6.1.5(10))
1508 Add_Item_To_Name_Buffer
(Item_Id
);
1509 Add_Str_To_Name_Buffer
1510 (" & is missing from output dependence list");
1512 Error_Msg
:= Name_Find
;
1513 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), N
, Item_Id
);
1521 Item_Id
: Entity_Id
;
1523 -- Start of processing for Check_Usage
1526 if No
(Subp_Items
) then
1530 -- Each input or output of the subprogram must appear in a dependency
1533 Elmt
:= First_Elmt
(Subp_Items
);
1534 while Present
(Elmt
) loop
1535 Item
:= Node
(Elmt
);
1537 if Nkind
(Item
) = N_Defining_Identifier
then
1540 Item_Id
:= Entity_Of
(Item
);
1543 -- The item does not appear in a dependency
1545 if Present
(Item_Id
)
1546 and then not Contains
(Used_Items
, Item_Id
)
1548 if Is_Formal
(Item_Id
) then
1549 Usage_Error
(Item_Id
);
1551 -- The current instance of a protected type behaves as a formal
1552 -- parameter (SPARK RM 6.1.4).
1554 elsif Ekind
(Item_Id
) = E_Protected_Type
1555 or else Is_Single_Protected_Object
(Item_Id
)
1557 Usage_Error
(Item_Id
);
1559 -- The current instance of a task type behaves as a formal
1560 -- parameter (SPARK RM 6.1.4).
1562 elsif Ekind
(Item_Id
) = E_Task_Type
1563 or else Is_Single_Task_Object
(Item_Id
)
1565 -- The dependence of a task unit on itself is implicit and
1566 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1567 -- Emit an error if only one input/output is present.
1569 if Task_Input_Seen
/= Task_Output_Seen
then
1570 Usage_Error
(Item_Id
);
1573 -- States and global objects are not used properly only when
1574 -- the subprogram is subject to pragma Global.
1576 elsif Global_Seen
then
1577 Usage_Error
(Item_Id
);
1585 ----------------------
1586 -- Normalize_Clause --
1587 ----------------------
1589 procedure Normalize_Clause
(Clause
: Node_Id
) is
1590 procedure Create_Or_Modify_Clause
1596 Multiple
: Boolean);
1597 -- Create a brand new clause to represent the self-reference or
1598 -- modify the input and/or output lists of an existing clause. Output
1599 -- denotes a self-referencial output. Outputs is the output list of a
1600 -- clause. Inputs is the input list of a clause. After denotes the
1601 -- clause after which the new clause is to be inserted. Flag In_Place
1602 -- should be set when normalizing the last output of an output list.
1603 -- Flag Multiple should be set when Output comes from a list with
1606 -----------------------------
1607 -- Create_Or_Modify_Clause --
1608 -----------------------------
1610 procedure Create_Or_Modify_Clause
1618 procedure Propagate_Output
1621 -- Handle the various cases of output propagation to the input
1622 -- list. Output denotes a self-referencial output item. Inputs
1623 -- is the input list of a clause.
1625 ----------------------
1626 -- Propagate_Output --
1627 ----------------------
1629 procedure Propagate_Output
1633 function In_Input_List
1635 Inputs
: List_Id
) return Boolean;
1636 -- Determine whether a particulat item appears in the input
1637 -- list of a clause.
1643 function In_Input_List
1645 Inputs
: List_Id
) return Boolean
1650 Elmt
:= First
(Inputs
);
1651 while Present
(Elmt
) loop
1652 if Entity_Of
(Elmt
) = Item
then
1664 Output_Id
: constant Entity_Id
:= Entity_Of
(Output
);
1667 -- Start of processing for Propagate_Output
1670 -- The clause is of the form:
1672 -- (Output =>+ null)
1674 -- Remove null input and replace it with a copy of the output:
1676 -- (Output => Output)
1678 if Nkind
(Inputs
) = N_Null
then
1679 Rewrite
(Inputs
, New_Copy_Tree
(Output
));
1681 -- The clause is of the form:
1683 -- (Output =>+ (Input1, ..., InputN))
1685 -- Determine whether the output is not already mentioned in the
1686 -- input list and if not, add it to the list of inputs:
1688 -- (Output => (Output, Input1, ..., InputN))
1690 elsif Nkind
(Inputs
) = N_Aggregate
then
1691 Grouped
:= Expressions
(Inputs
);
1693 if not In_Input_List
1697 Prepend_To
(Grouped
, New_Copy_Tree
(Output
));
1700 -- The clause is of the form:
1702 -- (Output =>+ Input)
1704 -- If the input does not mention the output, group the two
1707 -- (Output => (Output, Input))
1709 elsif Entity_Of
(Inputs
) /= Output_Id
then
1711 Make_Aggregate
(Loc
,
1712 Expressions
=> New_List
(
1713 New_Copy_Tree
(Output
),
1714 New_Copy_Tree
(Inputs
))));
1716 end Propagate_Output
;
1720 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
1721 New_Clause
: Node_Id
;
1723 -- Start of processing for Create_Or_Modify_Clause
1726 -- A null output depending on itself does not require any
1729 if Nkind
(Output
) = N_Null
then
1732 -- A function result cannot depend on itself because it cannot
1733 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1735 elsif Is_Attribute_Result
(Output
) then
1736 SPARK_Msg_N
("function result cannot depend on itself", Output
);
1740 -- When performing the transformation in place, simply add the
1741 -- output to the list of inputs (if not already there). This
1742 -- case arises when dealing with the last output of an output
1743 -- list. Perform the normalization in place to avoid generating
1744 -- a malformed tree.
1747 Propagate_Output
(Output
, Inputs
);
1749 -- A list with multiple outputs is slowly trimmed until only
1750 -- one element remains. When this happens, replace aggregate
1751 -- with the element itself.
1755 Rewrite
(Outputs
, Output
);
1761 -- Unchain the output from its output list as it will appear in
1762 -- a new clause. Note that we cannot simply rewrite the output
1763 -- as null because this will violate the semantics of pragma
1768 -- Generate a new clause of the form:
1769 -- (Output => Inputs)
1772 Make_Component_Association
(Loc
,
1773 Choices
=> New_List
(Output
),
1774 Expression
=> New_Copy_Tree
(Inputs
));
1776 -- The new clause contains replicated content that has already
1777 -- been analyzed. There is not need to reanalyze or renormalize
1780 Set_Analyzed
(New_Clause
);
1783 (Output
=> First
(Choices
(New_Clause
)),
1784 Inputs
=> Expression
(New_Clause
));
1786 Insert_After
(After
, New_Clause
);
1788 end Create_Or_Modify_Clause
;
1792 Outputs
: constant Node_Id
:= First
(Choices
(Clause
));
1794 Last_Output
: Node_Id
;
1795 Next_Output
: Node_Id
;
1798 -- Start of processing for Normalize_Clause
1801 -- A self-dependency appears as operator "+". Remove the "+" from the
1802 -- tree by moving the real inputs to their proper place.
1804 if Nkind
(Expression
(Clause
)) = N_Op_Plus
then
1805 Rewrite
(Expression
(Clause
), Right_Opnd
(Expression
(Clause
)));
1806 Inputs
:= Expression
(Clause
);
1808 -- Multiple outputs appear as an aggregate
1810 if Nkind
(Outputs
) = N_Aggregate
then
1811 Last_Output
:= Last
(Expressions
(Outputs
));
1813 Output
:= First
(Expressions
(Outputs
));
1814 while Present
(Output
) loop
1816 -- Normalization may remove an output from its list,
1817 -- preserve the subsequent output now.
1819 Next_Output
:= Next
(Output
);
1821 Create_Or_Modify_Clause
1826 In_Place
=> Output
= Last_Output
,
1829 Output
:= Next_Output
;
1835 Create_Or_Modify_Clause
1844 end Normalize_Clause
;
1848 Deps
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
1849 Subp_Id
: constant Entity_Id
:= Defining_Entity
(Subp_Decl
);
1853 Last_Clause
: Node_Id
;
1854 Restore_Scope
: Boolean := False;
1856 -- Start of processing for Analyze_Depends_In_Decl_Part
1859 -- Do not analyze the pragma multiple times
1861 if Is_Analyzed_Pragma
(N
) then
1865 -- Empty dependency list
1867 if Nkind
(Deps
) = N_Null
then
1869 -- Gather all states, objects and formal parameters that the
1870 -- subprogram may depend on. These items are obtained from the
1871 -- parameter profile or pragma [Refined_]Global (if available).
1873 Collect_Subprogram_Inputs_Outputs
1874 (Subp_Id
=> Subp_Id
,
1875 Subp_Inputs
=> Subp_Inputs
,
1876 Subp_Outputs
=> Subp_Outputs
,
1877 Global_Seen
=> Global_Seen
);
1879 -- Verify that every input or output of the subprogram appear in a
1882 Check_Usage
(Subp_Inputs
, All_Inputs_Seen
, True);
1883 Check_Usage
(Subp_Outputs
, All_Outputs_Seen
, False);
1884 Check_Function_Return
;
1886 -- Dependency clauses appear as component associations of an aggregate
1888 elsif Nkind
(Deps
) = N_Aggregate
then
1890 -- Do not attempt to perform analysis of a syntactically illegal
1891 -- clause as this will lead to misleading errors.
1893 if Has_Extra_Parentheses
(Deps
) then
1897 if Present
(Component_Associations
(Deps
)) then
1898 Last_Clause
:= Last
(Component_Associations
(Deps
));
1900 -- Gather all states, objects and formal parameters that the
1901 -- subprogram may depend on. These items are obtained from the
1902 -- parameter profile or pragma [Refined_]Global (if available).
1904 Collect_Subprogram_Inputs_Outputs
1905 (Subp_Id
=> Subp_Id
,
1906 Subp_Inputs
=> Subp_Inputs
,
1907 Subp_Outputs
=> Subp_Outputs
,
1908 Global_Seen
=> Global_Seen
);
1910 -- When pragma [Refined_]Depends appears on a single concurrent
1911 -- type, it is relocated to the anonymous object.
1913 if Is_Single_Concurrent_Object
(Spec_Id
) then
1916 -- Ensure that the formal parameters are visible when analyzing
1917 -- all clauses. This falls out of the general rule of aspects
1918 -- pertaining to subprogram declarations.
1920 elsif not In_Open_Scopes
(Spec_Id
) then
1921 Restore_Scope
:= True;
1922 Push_Scope
(Spec_Id
);
1924 if Ekind
(Spec_Id
) = E_Task_Type
then
1925 if Has_Discriminants
(Spec_Id
) then
1926 Install_Discriminants
(Spec_Id
);
1929 elsif Is_Generic_Subprogram
(Spec_Id
) then
1930 Install_Generic_Formals
(Spec_Id
);
1933 Install_Formals
(Spec_Id
);
1937 Clause
:= First
(Component_Associations
(Deps
));
1938 while Present
(Clause
) loop
1939 Errors
:= Serious_Errors_Detected
;
1941 -- The normalization mechanism may create extra clauses that
1942 -- contain replicated input and output names. There is no need
1943 -- to reanalyze them.
1945 if not Analyzed
(Clause
) then
1946 Set_Analyzed
(Clause
);
1948 Analyze_Dependency_Clause
1950 Is_Last
=> Clause
= Last_Clause
);
1953 -- Do not normalize a clause if errors were detected (count
1954 -- of Serious_Errors has increased) because the inputs and/or
1955 -- outputs may denote illegal items. Normalization is disabled
1956 -- in ASIS mode as it alters the tree by introducing new nodes
1957 -- similar to expansion.
1959 if Serious_Errors_Detected
= Errors
and then not ASIS_Mode
then
1960 Normalize_Clause
(Clause
);
1966 if Restore_Scope
then
1970 -- Verify that every input or output of the subprogram appear in a
1973 Check_Usage
(Subp_Inputs
, All_Inputs_Seen
, True);
1974 Check_Usage
(Subp_Outputs
, All_Outputs_Seen
, False);
1975 Check_Function_Return
;
1977 -- The dependency list is malformed. This is a syntax error, always
1981 Error_Msg_N
("malformed dependency relation", Deps
);
1985 -- The top level dependency relation is malformed. This is a syntax
1986 -- error, always report.
1989 Error_Msg_N
("malformed dependency relation", Deps
);
1993 -- Ensure that a state and a corresponding constituent do not appear
1994 -- together in pragma [Refined_]Depends.
1996 Check_State_And_Constituent_Use
1997 (States
=> States_Seen
,
1998 Constits
=> Constits_Seen
,
2002 Set_Is_Analyzed_Pragma
(N
);
2003 end Analyze_Depends_In_Decl_Part
;
2005 --------------------------------------------
2006 -- Analyze_External_Property_In_Decl_Part --
2007 --------------------------------------------
2009 procedure Analyze_External_Property_In_Decl_Part
2011 Expr_Val
: out Boolean)
2013 Arg1
: constant Node_Id
:= First
(Pragma_Argument_Associations
(N
));
2014 Obj_Decl
: constant Node_Id
:= Find_Related_Context
(N
);
2015 Obj_Id
: constant Entity_Id
:= Defining_Entity
(Obj_Decl
);
2021 -- Do not analyze the pragma multiple times
2023 if Is_Analyzed_Pragma
(N
) then
2027 Error_Msg_Name_1
:= Pragma_Name
(N
);
2029 -- An external property pragma must apply to an effectively volatile
2030 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
2031 -- The check is performed at the end of the declarative region due to a
2032 -- possible out-of-order arrangement of pragmas:
2035 -- pragma Async_Readers (Obj);
2036 -- pragma Volatile (Obj);
2038 if not Is_Effectively_Volatile
(Obj_Id
) then
2040 ("external property % must apply to a volatile object", N
);
2043 -- Ensure that the Boolean expression (if present) is static. A missing
2044 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
2048 if Present
(Arg1
) then
2049 Expr
:= Get_Pragma_Arg
(Arg1
);
2051 if Is_OK_Static_Expression
(Expr
) then
2052 Expr_Val
:= Is_True
(Expr_Value
(Expr
));
2056 Set_Is_Analyzed_Pragma
(N
);
2057 end Analyze_External_Property_In_Decl_Part
;
2059 ---------------------------------
2060 -- Analyze_Global_In_Decl_Part --
2061 ---------------------------------
2063 procedure Analyze_Global_In_Decl_Part
(N
: Node_Id
) is
2064 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
2065 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
2066 Subp_Id
: constant Entity_Id
:= Defining_Entity
(Subp_Decl
);
2068 Constits_Seen
: Elist_Id
:= No_Elist
;
2069 -- A list containing the entities of all constituents processed so far.
2070 -- It aids in detecting illegal usage of a state and a corresponding
2071 -- constituent in pragma [Refinde_]Global.
2073 Seen
: Elist_Id
:= No_Elist
;
2074 -- A list containing the entities of all the items processed so far. It
2075 -- plays a role in detecting distinct entities.
2077 States_Seen
: Elist_Id
:= No_Elist
;
2078 -- A list containing the entities of all states processed so far. It
2079 -- helps in detecting illegal usage of a state and a corresponding
2080 -- constituent in pragma [Refined_]Global.
2082 In_Out_Seen
: Boolean := False;
2083 Input_Seen
: Boolean := False;
2084 Output_Seen
: Boolean := False;
2085 Proof_Seen
: Boolean := False;
2086 -- Flags used to verify the consistency of modes
2088 procedure Analyze_Global_List
2090 Global_Mode
: Name_Id
:= Name_Input
);
2091 -- Verify the legality of a single global list declaration. Global_Mode
2092 -- denotes the current mode in effect.
2094 -------------------------
2095 -- Analyze_Global_List --
2096 -------------------------
2098 procedure Analyze_Global_List
2100 Global_Mode
: Name_Id
:= Name_Input
)
2102 procedure Analyze_Global_Item
2104 Global_Mode
: Name_Id
);
2105 -- Verify the legality of a single global item declaration denoted by
2106 -- Item. Global_Mode denotes the current mode in effect.
2108 procedure Check_Duplicate_Mode
2110 Status
: in out Boolean);
2111 -- Flag Status denotes whether a particular mode has been seen while
2112 -- processing a global list. This routine verifies that Mode is not a
2113 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2115 procedure Check_Mode_Restriction_In_Enclosing_Context
2117 Item_Id
: Entity_Id
);
2118 -- Verify that an item of mode In_Out or Output does not appear as an
2119 -- input in the Global aspect of an enclosing subprogram. If this is
2120 -- the case, emit an error. Item and Item_Id are respectively the
2121 -- item and its entity.
2123 procedure Check_Mode_Restriction_In_Function
(Mode
: Node_Id
);
2124 -- Mode denotes either In_Out or Output. Depending on the kind of the
2125 -- related subprogram, emit an error if those two modes apply to a
2126 -- function (SPARK RM 6.1.4(10)).
2128 -------------------------
2129 -- Analyze_Global_Item --
2130 -------------------------
2132 procedure Analyze_Global_Item
2134 Global_Mode
: Name_Id
)
2136 Item_Id
: Entity_Id
;
2139 -- Detect one of the following cases
2141 -- with Global => (null, Name)
2142 -- with Global => (Name_1, null, Name_2)
2143 -- with Global => (Name, null)
2145 if Nkind
(Item
) = N_Null
then
2146 SPARK_Msg_N
("cannot mix null and non-null global items", Item
);
2151 Resolve_State
(Item
);
2153 -- Find the entity of the item. If this is a renaming, climb the
2154 -- renaming chain to reach the root object. Renamings of non-
2155 -- entire objects do not yield an entity (Empty).
2157 Item_Id
:= Entity_Of
(Item
);
2159 if Present
(Item_Id
) then
2161 -- A global item may denote a formal parameter of an enclosing
2162 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2163 -- provide a better error diagnostic.
2165 if Is_Formal
(Item_Id
) then
2166 if Scope
(Item_Id
) = Spec_Id
then
2168 (Fix_Msg
(Spec_Id
, "global item cannot reference "
2169 & "parameter of subprogram &"), Item
, Spec_Id
);
2173 -- A global item may denote a concurrent type as long as it is
2174 -- the current instance of an enclosing protected or task type
2175 -- (SPARK RM 6.1.4).
2177 elsif Ekind_In
(Item_Id
, E_Protected_Type
, E_Task_Type
) then
2178 if Is_CCT_Instance
(Item_Id
, Spec_Id
) then
2180 -- Pragma [Refined_]Global associated with a protected
2181 -- subprogram cannot mention the current instance of a
2182 -- protected type because the instance behaves as a
2183 -- formal parameter.
2185 if Ekind
(Item_Id
) = E_Protected_Type
then
2186 if Scope
(Spec_Id
) = Item_Id
then
2187 Error_Msg_Name_1
:= Chars
(Item_Id
);
2189 (Fix_Msg
(Spec_Id
, "global item of subprogram & "
2190 & "cannot reference current instance of "
2191 & "protected type %"), Item
, Spec_Id
);
2195 -- Pragma [Refined_]Global associated with a task type
2196 -- cannot mention the current instance of a task type
2197 -- because the instance behaves as a formal parameter.
2199 else pragma Assert
(Ekind
(Item_Id
) = E_Task_Type
);
2200 if Spec_Id
= Item_Id
then
2201 Error_Msg_Name_1
:= Chars
(Item_Id
);
2203 (Fix_Msg
(Spec_Id
, "global item of subprogram & "
2204 & "cannot reference current instance of task "
2205 & "type %"), Item
, Spec_Id
);
2210 -- Otherwise the global item denotes a subtype mark that is
2211 -- not a current instance.
2215 ("invalid use of subtype mark in global list", Item
);
2219 -- A global item may denote the anonymous object created for a
2220 -- single protected/task type as long as the current instance
2221 -- is the same single type (SPARK RM 6.1.4).
2223 elsif Is_Single_Concurrent_Object
(Item_Id
)
2224 and then Is_CCT_Instance
(Etype
(Item_Id
), Spec_Id
)
2226 -- Pragma [Refined_]Global associated with a protected
2227 -- subprogram cannot mention the current instance of a
2228 -- protected type because the instance behaves as a formal
2231 if Is_Single_Protected_Object
(Item_Id
) then
2232 if Scope
(Spec_Id
) = Etype
(Item_Id
) then
2233 Error_Msg_Name_1
:= Chars
(Item_Id
);
2235 (Fix_Msg
(Spec_Id
, "global item of subprogram & "
2236 & "cannot reference current instance of protected "
2237 & "type %"), Item
, Spec_Id
);
2241 -- Pragma [Refined_]Global associated with a task type
2242 -- cannot mention the current instance of a task type
2243 -- because the instance behaves as a formal parameter.
2245 else pragma Assert
(Is_Single_Task_Object
(Item_Id
));
2246 if Spec_Id
= Item_Id
then
2247 Error_Msg_Name_1
:= Chars
(Item_Id
);
2249 (Fix_Msg
(Spec_Id
, "global item of subprogram & "
2250 & "cannot reference current instance of task "
2251 & "type %"), Item
, Spec_Id
);
2256 -- A formal object may act as a global item inside a generic
2258 elsif Is_Formal_Object
(Item_Id
) then
2261 -- The only legal references are those to abstract states,
2262 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2264 elsif not Ekind_In
(Item_Id
, E_Abstract_State
,
2270 ("global item must denote object, state or current "
2271 & "instance of concurrent type", Item
);
2275 -- State related checks
2277 if Ekind
(Item_Id
) = E_Abstract_State
then
2279 -- Package and subprogram bodies are instantiated
2280 -- individually in a separate compiler pass. Due to this
2281 -- mode of instantiation, the refinement of a state may
2282 -- no longer be visible when a subprogram body contract
2283 -- is instantiated. Since the generic template is legal,
2284 -- do not perform this check in the instance to circumvent
2287 if Is_Generic_Instance
(Spec_Id
) then
2290 -- An abstract state with visible refinement cannot appear
2291 -- in pragma [Refined_]Global as its place must be taken by
2292 -- some of its constituents (SPARK RM 6.1.4(7)).
2294 elsif Has_Visible_Refinement
(Item_Id
) then
2296 ("cannot mention state & in global refinement",
2298 SPARK_Msg_N
("\use its constituents instead", Item
);
2301 -- An external state cannot appear as a global item of a
2302 -- nonvolatile function (SPARK RM 7.1.3(8)).
2304 elsif Is_External_State
(Item_Id
)
2305 and then Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
2306 and then not Is_Volatile_Function
(Spec_Id
)
2309 ("external state & cannot act as global item of "
2310 & "nonvolatile function", Item
, Item_Id
);
2313 -- If the reference to the abstract state appears in an
2314 -- enclosing package body that will eventually refine the
2315 -- state, record the reference for future checks.
2318 Record_Possible_Body_Reference
2319 (State_Id
=> Item_Id
,
2323 -- Constant related checks
2325 elsif Ekind
(Item_Id
) = E_Constant
then
2327 -- A constant is a read-only item, therefore it cannot act
2330 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2332 ("constant & cannot act as output", Item
, Item_Id
);
2336 -- Loop parameter related checks
2338 elsif Ekind
(Item_Id
) = E_Loop_Parameter
then
2340 -- A loop parameter is a read-only item, therefore it cannot
2341 -- act as an output.
2343 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2345 ("loop parameter & cannot act as output",
2350 -- Variable related checks. These are only relevant when
2351 -- SPARK_Mode is on as they are not standard Ada legality
2354 elsif SPARK_Mode
= On
2355 and then Ekind
(Item_Id
) = E_Variable
2356 and then Is_Effectively_Volatile
(Item_Id
)
2358 -- An effectively volatile object cannot appear as a global
2359 -- item of a nonvolatile function (SPARK RM 7.1.3(8)).
2361 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
2362 and then not Is_Volatile_Function
(Spec_Id
)
2365 ("volatile object & cannot act as global item of a "
2366 & "function", Item
, Item_Id
);
2369 -- An effectively volatile object with external property
2370 -- Effective_Reads set to True must have mode Output or
2371 -- In_Out (SPARK RM 7.1.3(10)).
2373 elsif Effective_Reads_Enabled
(Item_Id
)
2374 and then Global_Mode
= Name_Input
2377 ("volatile object & with property Effective_Reads must "
2378 & "have mode In_Out or Output", Item
, Item_Id
);
2383 -- When the item renames an entire object, replace the item
2384 -- with a reference to the object.
2386 if Entity
(Item
) /= Item_Id
then
2387 Rewrite
(Item
, New_Occurrence_Of
(Item_Id
, Sloc
(Item
)));
2391 -- Some form of illegal construct masquerading as a name
2392 -- (SPARK RM 6.1.4(4)).
2396 ("global item must denote object, state or current instance "
2397 & "of concurrent type", Item
);
2401 -- Verify that an output does not appear as an input in an
2402 -- enclosing subprogram.
2404 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2405 Check_Mode_Restriction_In_Enclosing_Context
(Item
, Item_Id
);
2408 -- The same entity might be referenced through various way.
2409 -- Check the entity of the item rather than the item itself
2410 -- (SPARK RM 6.1.4(10)).
2412 if Contains
(Seen
, Item_Id
) then
2413 SPARK_Msg_N
("duplicate global item", Item
);
2415 -- Add the entity of the current item to the list of processed
2419 Append_New_Elmt
(Item_Id
, Seen
);
2421 if Ekind
(Item_Id
) = E_Abstract_State
then
2422 Append_New_Elmt
(Item_Id
, States_Seen
);
2424 -- The variable may eventually become a constituent of a single
2425 -- protected/task type. Record the reference now and verify its
2426 -- legality when analyzing the contract of the variable
2429 elsif Ekind
(Item_Id
) = E_Variable
then
2430 Record_Possible_Part_Of_Reference
2435 if Ekind_In
(Item_Id
, E_Abstract_State
, E_Constant
, E_Variable
)
2436 and then Present
(Encapsulating_State
(Item_Id
))
2438 Append_New_Elmt
(Item_Id
, Constits_Seen
);
2441 end Analyze_Global_Item
;
2443 --------------------------
2444 -- Check_Duplicate_Mode --
2445 --------------------------
2447 procedure Check_Duplicate_Mode
2449 Status
: in out Boolean)
2453 SPARK_Msg_N
("duplicate global mode", Mode
);
2457 end Check_Duplicate_Mode
;
2459 -------------------------------------------------
2460 -- Check_Mode_Restriction_In_Enclosing_Context --
2461 -------------------------------------------------
2463 procedure Check_Mode_Restriction_In_Enclosing_Context
2465 Item_Id
: Entity_Id
)
2467 Context
: Entity_Id
;
2469 Inputs
: Elist_Id
:= No_Elist
;
2470 Outputs
: Elist_Id
:= No_Elist
;
2473 -- Traverse the scope stack looking for enclosing subprograms
2474 -- subject to pragma [Refined_]Global.
2476 Context
:= Scope
(Subp_Id
);
2477 while Present
(Context
) and then Context
/= Standard_Standard
loop
2478 if Is_Subprogram
(Context
)
2480 (Present
(Get_Pragma
(Context
, Pragma_Global
))
2482 Present
(Get_Pragma
(Context
, Pragma_Refined_Global
)))
2484 Collect_Subprogram_Inputs_Outputs
2485 (Subp_Id
=> Context
,
2486 Subp_Inputs
=> Inputs
,
2487 Subp_Outputs
=> Outputs
,
2488 Global_Seen
=> Dummy
);
2490 -- The item is classified as In_Out or Output but appears as
2491 -- an Input in an enclosing subprogram (SPARK RM 6.1.4(12)).
2493 if Appears_In
(Inputs
, Item_Id
)
2494 and then not Appears_In
(Outputs
, Item_Id
)
2497 ("global item & cannot have mode In_Out or Output",
2501 (Fix_Msg
(Subp_Id
, "\item already appears as input of "
2502 & "subprogram &"), Item
, Context
);
2504 -- Stop the traversal once an error has been detected
2510 Context
:= Scope
(Context
);
2512 end Check_Mode_Restriction_In_Enclosing_Context
;
2514 ----------------------------------------
2515 -- Check_Mode_Restriction_In_Function --
2516 ----------------------------------------
2518 procedure Check_Mode_Restriction_In_Function
(Mode
: Node_Id
) is
2520 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
2522 ("global mode & is not applicable to functions", Mode
);
2524 end Check_Mode_Restriction_In_Function
;
2532 -- Start of processing for Analyze_Global_List
2535 if Nkind
(List
) = N_Null
then
2536 Set_Analyzed
(List
);
2538 -- Single global item declaration
2540 elsif Nkind_In
(List
, N_Expanded_Name
,
2542 N_Selected_Component
)
2544 Analyze_Global_Item
(List
, Global_Mode
);
2546 -- Simple global list or moded global list declaration
2548 elsif Nkind
(List
) = N_Aggregate
then
2549 Set_Analyzed
(List
);
2551 -- The declaration of a simple global list appear as a collection
2554 if Present
(Expressions
(List
)) then
2555 if Present
(Component_Associations
(List
)) then
2557 ("cannot mix moded and non-moded global lists", List
);
2560 Item
:= First
(Expressions
(List
));
2561 while Present
(Item
) loop
2562 Analyze_Global_Item
(Item
, Global_Mode
);
2566 -- The declaration of a moded global list appears as a collection
2567 -- of component associations where individual choices denote
2570 elsif Present
(Component_Associations
(List
)) then
2571 if Present
(Expressions
(List
)) then
2573 ("cannot mix moded and non-moded global lists", List
);
2576 Assoc
:= First
(Component_Associations
(List
));
2577 while Present
(Assoc
) loop
2578 Mode
:= First
(Choices
(Assoc
));
2580 if Nkind
(Mode
) = N_Identifier
then
2581 if Chars
(Mode
) = Name_In_Out
then
2582 Check_Duplicate_Mode
(Mode
, In_Out_Seen
);
2583 Check_Mode_Restriction_In_Function
(Mode
);
2585 elsif Chars
(Mode
) = Name_Input
then
2586 Check_Duplicate_Mode
(Mode
, Input_Seen
);
2588 elsif Chars
(Mode
) = Name_Output
then
2589 Check_Duplicate_Mode
(Mode
, Output_Seen
);
2590 Check_Mode_Restriction_In_Function
(Mode
);
2592 elsif Chars
(Mode
) = Name_Proof_In
then
2593 Check_Duplicate_Mode
(Mode
, Proof_Seen
);
2596 SPARK_Msg_N
("invalid mode selector", Mode
);
2600 SPARK_Msg_N
("invalid mode selector", Mode
);
2603 -- Items in a moded list appear as a collection of
2604 -- expressions. Reuse the existing machinery to analyze
2608 (List
=> Expression
(Assoc
),
2609 Global_Mode
=> Chars
(Mode
));
2617 raise Program_Error
;
2620 -- Any other attempt to declare a global item is illegal. This is a
2621 -- syntax error, always report.
2624 Error_Msg_N
("malformed global list", List
);
2626 end Analyze_Global_List
;
2630 Items
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
2632 Restore_Scope
: Boolean := False;
2634 -- Start of processing for Analyze_Global_In_Decl_Part
2637 -- Do not analyze the pragma multiple times
2639 if Is_Analyzed_Pragma
(N
) then
2643 -- There is nothing to be done for a null global list
2645 if Nkind
(Items
) = N_Null
then
2646 Set_Analyzed
(Items
);
2648 -- Analyze the various forms of global lists and items. Note that some
2649 -- of these may be malformed in which case the analysis emits error
2653 -- When pragma [Refined_]Global appears on a single concurrent type,
2654 -- it is relocated to the anonymous object.
2656 if Is_Single_Concurrent_Object
(Spec_Id
) then
2659 -- Ensure that the formal parameters are visible when processing an
2660 -- item. This falls out of the general rule of aspects pertaining to
2661 -- subprogram declarations.
2663 elsif not In_Open_Scopes
(Spec_Id
) then
2664 Restore_Scope
:= True;
2665 Push_Scope
(Spec_Id
);
2667 if Ekind
(Spec_Id
) = E_Task_Type
then
2668 if Has_Discriminants
(Spec_Id
) then
2669 Install_Discriminants
(Spec_Id
);
2672 elsif Is_Generic_Subprogram
(Spec_Id
) then
2673 Install_Generic_Formals
(Spec_Id
);
2676 Install_Formals
(Spec_Id
);
2680 Analyze_Global_List
(Items
);
2682 if Restore_Scope
then
2687 -- Ensure that a state and a corresponding constituent do not appear
2688 -- together in pragma [Refined_]Global.
2690 Check_State_And_Constituent_Use
2691 (States
=> States_Seen
,
2692 Constits
=> Constits_Seen
,
2695 Set_Is_Analyzed_Pragma
(N
);
2696 end Analyze_Global_In_Decl_Part
;
2698 --------------------------------------------
2699 -- Analyze_Initial_Condition_In_Decl_Part --
2700 --------------------------------------------
2702 -- WARNING: This routine manages Ghost regions. Return statements must be
2703 -- replaced by gotos which jump to the end of the routine and restore the
2706 procedure Analyze_Initial_Condition_In_Decl_Part
(N
: Node_Id
) is
2707 Pack_Decl
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
2708 Pack_Id
: constant Entity_Id
:= Defining_Entity
(Pack_Decl
);
2709 Expr
: constant Node_Id
:= Expression
(Get_Argument
(N
, Pack_Id
));
2711 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
2712 -- Save the Ghost mode to restore on exit
2715 -- Do not analyze the pragma multiple times
2717 if Is_Analyzed_Pragma
(N
) then
2721 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2722 -- analysis of the pragma, the Ghost mode at point of declaration and
2723 -- point of analysis may not necessarily be the same. Use the mode in
2724 -- effect at the point of declaration.
2728 -- The expression is preanalyzed because it has not been moved to its
2729 -- final place yet. A direct analysis may generate side effects and this
2730 -- is not desired at this point.
2732 Preanalyze_Assert_Expression
(Expr
, Standard_Boolean
);
2733 Set_Is_Analyzed_Pragma
(N
);
2735 Restore_Ghost_Mode
(Saved_GM
);
2736 end Analyze_Initial_Condition_In_Decl_Part
;
2738 --------------------------------------
2739 -- Analyze_Initializes_In_Decl_Part --
2740 --------------------------------------
2742 procedure Analyze_Initializes_In_Decl_Part
(N
: Node_Id
) is
2743 Pack_Decl
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
2744 Pack_Id
: constant Entity_Id
:= Defining_Entity
(Pack_Decl
);
2746 Constits_Seen
: Elist_Id
:= No_Elist
;
2747 -- A list containing the entities of all constituents processed so far.
2748 -- It aids in detecting illegal usage of a state and a corresponding
2749 -- constituent in pragma Initializes.
2751 Items_Seen
: Elist_Id
:= No_Elist
;
2752 -- A list of all initialization items processed so far. This list is
2753 -- used to detect duplicate items.
2755 Non_Null_Seen
: Boolean := False;
2756 Null_Seen
: Boolean := False;
2757 -- Flags used to check the legality of a null initialization list
2759 States_And_Objs
: Elist_Id
:= No_Elist
;
2760 -- A list of all abstract states and objects declared in the visible
2761 -- declarations of the related package. This list is used to detect the
2762 -- legality of initialization items.
2764 States_Seen
: Elist_Id
:= No_Elist
;
2765 -- A list containing the entities of all states processed so far. It
2766 -- helps in detecting illegal usage of a state and a corresponding
2767 -- constituent in pragma Initializes.
2769 procedure Analyze_Initialization_Item
(Item
: Node_Id
);
2770 -- Verify the legality of a single initialization item
2772 procedure Analyze_Initialization_Item_With_Inputs
(Item
: Node_Id
);
2773 -- Verify the legality of a single initialization item followed by a
2774 -- list of input items.
2776 procedure Collect_States_And_Objects
;
2777 -- Inspect the visible declarations of the related package and gather
2778 -- the entities of all abstract states and objects in States_And_Objs.
2780 ---------------------------------
2781 -- Analyze_Initialization_Item --
2782 ---------------------------------
2784 procedure Analyze_Initialization_Item
(Item
: Node_Id
) is
2785 Item_Id
: Entity_Id
;
2788 -- Null initialization list
2790 if Nkind
(Item
) = N_Null
then
2792 SPARK_Msg_N
("multiple null initializations not allowed", Item
);
2794 elsif Non_Null_Seen
then
2796 ("cannot mix null and non-null initialization items", Item
);
2801 -- Initialization item
2804 Non_Null_Seen
:= True;
2808 ("cannot mix null and non-null initialization items", Item
);
2812 Resolve_State
(Item
);
2814 if Is_Entity_Name
(Item
) then
2815 Item_Id
:= Entity_Of
(Item
);
2817 if Present
(Item_Id
)
2818 and then Ekind_In
(Item_Id
, E_Abstract_State
,
2822 -- When the initialization item is undefined, it appears as
2823 -- Any_Id. Do not continue with the analysis of the item.
2825 if Item_Id
= Any_Id
then
2828 -- The state or variable must be declared in the visible
2829 -- declarations of the package (SPARK RM 7.1.5(7)).
2831 elsif not Contains
(States_And_Objs
, Item_Id
) then
2832 Error_Msg_Name_1
:= Chars
(Pack_Id
);
2834 ("initialization item & must appear in the visible "
2835 & "declarations of package %", Item
, Item_Id
);
2837 -- Detect a duplicate use of the same initialization item
2838 -- (SPARK RM 7.1.5(5)).
2840 elsif Contains
(Items_Seen
, Item_Id
) then
2841 SPARK_Msg_N
("duplicate initialization item", Item
);
2843 -- The item is legal, add it to the list of processed states
2847 Append_New_Elmt
(Item_Id
, Items_Seen
);
2849 if Ekind
(Item_Id
) = E_Abstract_State
then
2850 Append_New_Elmt
(Item_Id
, States_Seen
);
2853 if Present
(Encapsulating_State
(Item_Id
)) then
2854 Append_New_Elmt
(Item_Id
, Constits_Seen
);
2858 -- The item references something that is not a state or object
2859 -- (SPARK RM 7.1.5(3)).
2863 ("initialization item must denote object or state", Item
);
2866 -- Some form of illegal construct masquerading as a name
2867 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2871 ("initialization item must denote object or state", Item
);
2874 end Analyze_Initialization_Item
;
2876 ---------------------------------------------
2877 -- Analyze_Initialization_Item_With_Inputs --
2878 ---------------------------------------------
2880 procedure Analyze_Initialization_Item_With_Inputs
(Item
: Node_Id
) is
2881 Inputs_Seen
: Elist_Id
:= No_Elist
;
2882 -- A list of all inputs processed so far. This list is used to detect
2883 -- duplicate uses of an input.
2885 Non_Null_Seen
: Boolean := False;
2886 Null_Seen
: Boolean := False;
2887 -- Flags used to check the legality of an input list
2889 procedure Analyze_Input_Item
(Input
: Node_Id
);
2890 -- Verify the legality of a single input item
2892 ------------------------
2893 -- Analyze_Input_Item --
2894 ------------------------
2896 procedure Analyze_Input_Item
(Input
: Node_Id
) is
2897 Input_Id
: Entity_Id
;
2898 Input_OK
: Boolean := True;
2903 if Nkind
(Input
) = N_Null
then
2906 ("multiple null initializations not allowed", Item
);
2908 elsif Non_Null_Seen
then
2910 ("cannot mix null and non-null initialization item", Item
);
2918 Non_Null_Seen
:= True;
2922 ("cannot mix null and non-null initialization item", Item
);
2926 Resolve_State
(Input
);
2928 if Is_Entity_Name
(Input
) then
2929 Input_Id
:= Entity_Of
(Input
);
2931 if Present
(Input_Id
)
2932 and then Ekind_In
(Input_Id
, E_Abstract_State
,
2934 E_Generic_In_Out_Parameter
,
2935 E_Generic_In_Parameter
,
2941 -- The input cannot denote states or objects declared
2942 -- within the related package (SPARK RM 7.1.5(4)).
2944 if Within_Scope
(Input_Id
, Current_Scope
) then
2946 -- Do not consider generic formal parameters or their
2947 -- respective mappings to generic formals. Even though
2948 -- the formals appear within the scope of the package,
2949 -- it is allowed for an initialization item to depend
2950 -- on an input item.
2952 if Ekind_In
(Input_Id
, E_Generic_In_Out_Parameter
,
2953 E_Generic_In_Parameter
)
2957 elsif Ekind_In
(Input_Id
, E_Constant
, E_Variable
)
2958 and then Present
(Corresponding_Generic_Association
2959 (Declaration_Node
(Input_Id
)))
2965 Error_Msg_Name_1
:= Chars
(Pack_Id
);
2967 ("input item & cannot denote a visible object or "
2968 & "state of package %", Input
, Input_Id
);
2972 -- Detect a duplicate use of the same input item
2973 -- (SPARK RM 7.1.5(5)).
2975 if Contains
(Inputs_Seen
, Input_Id
) then
2977 SPARK_Msg_N
("duplicate input item", Input
);
2980 -- Input is legal, add it to the list of processed inputs
2983 Append_New_Elmt
(Input_Id
, Inputs_Seen
);
2985 if Ekind
(Input_Id
) = E_Abstract_State
then
2986 Append_New_Elmt
(Input_Id
, States_Seen
);
2989 if Ekind_In
(Input_Id
, E_Abstract_State
,
2992 and then Present
(Encapsulating_State
(Input_Id
))
2994 Append_New_Elmt
(Input_Id
, Constits_Seen
);
2998 -- The input references something that is not a state or an
2999 -- object (SPARK RM 7.1.5(3)).
3003 ("input item must denote object or state", Input
);
3006 -- Some form of illegal construct masquerading as a name
3007 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
3011 ("input item must denote object or state", Input
);
3014 end Analyze_Input_Item
;
3018 Inputs
: constant Node_Id
:= Expression
(Item
);
3022 Name_Seen
: Boolean := False;
3023 -- A flag used to detect multiple item names
3025 -- Start of processing for Analyze_Initialization_Item_With_Inputs
3028 -- Inspect the name of an item with inputs
3030 Elmt
:= First
(Choices
(Item
));
3031 while Present
(Elmt
) loop
3033 SPARK_Msg_N
("only one item allowed in initialization", Elmt
);
3036 Analyze_Initialization_Item
(Elmt
);
3042 -- Multiple input items appear as an aggregate
3044 if Nkind
(Inputs
) = N_Aggregate
then
3045 if Present
(Expressions
(Inputs
)) then
3046 Input
:= First
(Expressions
(Inputs
));
3047 while Present
(Input
) loop
3048 Analyze_Input_Item
(Input
);
3053 if Present
(Component_Associations
(Inputs
)) then
3055 ("inputs must appear in named association form", Inputs
);
3058 -- Single input item
3061 Analyze_Input_Item
(Inputs
);
3063 end Analyze_Initialization_Item_With_Inputs
;
3065 --------------------------------
3066 -- Collect_States_And_Objects --
3067 --------------------------------
3069 procedure Collect_States_And_Objects
is
3070 Pack_Spec
: constant Node_Id
:= Specification
(Pack_Decl
);
3074 -- Collect the abstract states defined in the package (if any)
3076 if Present
(Abstract_States
(Pack_Id
)) then
3077 States_And_Objs
:= New_Copy_Elist
(Abstract_States
(Pack_Id
));
3080 -- Collect all objects that appear in the visible declarations of the
3083 if Present
(Visible_Declarations
(Pack_Spec
)) then
3084 Decl
:= First
(Visible_Declarations
(Pack_Spec
));
3085 while Present
(Decl
) loop
3086 if Comes_From_Source
(Decl
)
3087 and then Nkind_In
(Decl
, N_Object_Declaration
,
3088 N_Object_Renaming_Declaration
)
3090 Append_New_Elmt
(Defining_Entity
(Decl
), States_And_Objs
);
3092 elsif Is_Single_Concurrent_Type_Declaration
(Decl
) then
3094 (Anonymous_Object
(Defining_Entity
(Decl
)),
3101 end Collect_States_And_Objects
;
3105 Inits
: constant Node_Id
:= Expression
(Get_Argument
(N
, Pack_Id
));
3108 -- Start of processing for Analyze_Initializes_In_Decl_Part
3111 -- Do not analyze the pragma multiple times
3113 if Is_Analyzed_Pragma
(N
) then
3117 -- Nothing to do when the initialization list is empty
3119 if Nkind
(Inits
) = N_Null
then
3123 -- Single and multiple initialization clauses appear as an aggregate. If
3124 -- this is not the case, then either the parser or the analysis of the
3125 -- pragma failed to produce an aggregate.
3127 pragma Assert
(Nkind
(Inits
) = N_Aggregate
);
3129 -- Initialize the various lists used during analysis
3131 Collect_States_And_Objects
;
3133 if Present
(Expressions
(Inits
)) then
3134 Init
:= First
(Expressions
(Inits
));
3135 while Present
(Init
) loop
3136 Analyze_Initialization_Item
(Init
);
3141 if Present
(Component_Associations
(Inits
)) then
3142 Init
:= First
(Component_Associations
(Inits
));
3143 while Present
(Init
) loop
3144 Analyze_Initialization_Item_With_Inputs
(Init
);
3149 -- Ensure that a state and a corresponding constituent do not appear
3150 -- together in pragma Initializes.
3152 Check_State_And_Constituent_Use
3153 (States
=> States_Seen
,
3154 Constits
=> Constits_Seen
,
3157 Set_Is_Analyzed_Pragma
(N
);
3158 end Analyze_Initializes_In_Decl_Part
;
3160 ---------------------
3161 -- Analyze_Part_Of --
3162 ---------------------
3164 procedure Analyze_Part_Of
3166 Item_Id
: Entity_Id
;
3168 Encap_Id
: out Entity_Id
;
3169 Legal
: out Boolean)
3171 Encap_Typ
: Entity_Id
;
3172 Item_Decl
: Node_Id
;
3173 Pack_Id
: Entity_Id
;
3174 Placement
: State_Space_Kind
;
3175 Parent_Unit
: Entity_Id
;
3178 -- Assume that the indicator is illegal
3183 if Nkind_In
(Encap
, N_Expanded_Name
,
3185 N_Selected_Component
)
3188 Resolve_State
(Encap
);
3190 Encap_Id
:= Entity
(Encap
);
3192 -- The encapsulator is an abstract state
3194 if Ekind
(Encap_Id
) = E_Abstract_State
then
3197 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
3199 elsif Is_Single_Concurrent_Object
(Encap_Id
) then
3202 -- Otherwise the encapsulator is not a legal choice
3206 ("indicator Part_Of must denote abstract state, single "
3207 & "protected type or single task type", Encap
);
3211 -- This is a syntax error, always report
3215 ("indicator Part_Of must denote abstract state, single protected "
3216 & "type or single task type", Encap
);
3220 -- Catch a case where indicator Part_Of denotes the abstract view of a
3221 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3223 if From_Limited_With
(Encap_Id
)
3224 and then Present
(Non_Limited_View
(Encap_Id
))
3225 and then Ekind
(Non_Limited_View
(Encap_Id
)) = E_Variable
3227 SPARK_Msg_N
("indicator Part_Of must denote abstract state", Encap
);
3228 SPARK_Msg_N
("\& denotes abstract view of object", Encap
);
3232 -- The encapsulator is an abstract state
3234 if Ekind
(Encap_Id
) = E_Abstract_State
then
3236 -- Determine where the object, package instantiation or state lives
3237 -- with respect to the enclosing packages or package bodies.
3239 Find_Placement_In_State_Space
3240 (Item_Id
=> Item_Id
,
3241 Placement
=> Placement
,
3242 Pack_Id
=> Pack_Id
);
3244 -- The item appears in a non-package construct with a declarative
3245 -- part (subprogram, block, etc). As such, the item is not allowed
3246 -- to be a part of an encapsulating state because the item is not
3249 if Placement
= Not_In_Package
then
3251 ("indicator Part_Of cannot appear in this context "
3252 & "(SPARK RM 7.2.6(5))", Indic
);
3253 Error_Msg_Name_1
:= Chars
(Scope
(Encap_Id
));
3255 ("\& is not part of the hidden state of package %",
3259 -- The item appears in the visible state space of some package. In
3260 -- general this scenario does not warrant Part_Of except when the
3261 -- package is a private child unit and the encapsulating state is
3262 -- declared in a parent unit or a public descendant of that parent
3265 elsif Placement
= Visible_State_Space
then
3266 if Is_Child_Unit
(Pack_Id
)
3267 and then Is_Private_Descendant
(Pack_Id
)
3269 -- A variable or state abstraction which is part of the visible
3270 -- state of a private child unit (or one of its public
3271 -- descendants) must have its Part_Of indicator specified. The
3272 -- Part_Of indicator must denote a state abstraction declared
3273 -- by either the parent unit of the private unit or by a public
3274 -- descendant of that parent unit.
3276 -- Find nearest private ancestor (which can be the current unit
3279 Parent_Unit
:= Pack_Id
;
3280 while Present
(Parent_Unit
) loop
3283 (Parent
(Unit_Declaration_Node
(Parent_Unit
)));
3284 Parent_Unit
:= Scope
(Parent_Unit
);
3287 Parent_Unit
:= Scope
(Parent_Unit
);
3289 if not Is_Child_Or_Sibling
(Pack_Id
, Scope
(Encap_Id
)) then
3291 ("indicator Part_Of must denote abstract state of & "
3292 & "or of its public descendant (SPARK RM 7.2.6(3))",
3293 Indic
, Parent_Unit
);
3296 elsif Scope
(Encap_Id
) = Parent_Unit
3298 (Is_Ancestor_Package
(Parent_Unit
, Scope
(Encap_Id
))
3299 and then not Is_Private_Descendant
(Scope
(Encap_Id
)))
3305 ("indicator Part_Of must denote abstract state of & "
3306 & "or of its public descendant (SPARK RM 7.2.6(3))",
3307 Indic
, Parent_Unit
);
3311 -- Indicator Part_Of is not needed when the related package is not
3312 -- a private child unit or a public descendant thereof.
3316 ("indicator Part_Of cannot appear in this context "
3317 & "(SPARK RM 7.2.6(5))", Indic
);
3318 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3320 ("\& is declared in the visible part of package %",
3325 -- When the item appears in the private state space of a package, the
3326 -- encapsulating state must be declared in the same package.
3328 elsif Placement
= Private_State_Space
then
3329 if Scope
(Encap_Id
) /= Pack_Id
then
3331 ("indicator Part_Of must denote an abstract state of "
3332 & "package & (SPARK RM 7.2.6(2))", Indic
, Pack_Id
);
3333 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3335 ("\& is declared in the private part of package %",
3340 -- Items declared in the body state space of a package do not need
3341 -- Part_Of indicators as the refinement has already been seen.
3345 ("indicator Part_Of cannot appear in this context "
3346 & "(SPARK RM 7.2.6(5))", Indic
);
3348 if Scope
(Encap_Id
) = Pack_Id
then
3349 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3351 ("\& is declared in the body of package %", Indic
, Item_Id
);
3357 -- The encapsulator is a single concurrent type
3360 Encap_Typ
:= Etype
(Encap_Id
);
3362 -- Only abstract states and variables can act as constituents of an
3363 -- encapsulating single concurrent type.
3365 if Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
) then
3368 -- The constituent is a constant
3370 elsif Ekind
(Item_Id
) = E_Constant
then
3371 Error_Msg_Name_1
:= Chars
(Encap_Id
);
3373 (Fix_Msg
(Encap_Typ
, "constant & cannot act as constituent of "
3374 & "single protected type %"), Indic
, Item_Id
);
3377 -- The constituent is a package instantiation
3380 Error_Msg_Name_1
:= Chars
(Encap_Id
);
3382 (Fix_Msg
(Encap_Typ
, "package instantiation & cannot act as "
3383 & "constituent of single protected type %"), Indic
, Item_Id
);
3387 -- When the item denotes an abstract state of a nested package, use
3388 -- the declaration of the package to detect proper placement.
3393 -- with Abstract_State => (State with Part_Of => T)
3395 if Ekind
(Item_Id
) = E_Abstract_State
then
3396 Item_Decl
:= Unit_Declaration_Node
(Scope
(Item_Id
));
3398 Item_Decl
:= Declaration_Node
(Item_Id
);
3401 -- Both the item and its encapsulating single concurrent type must
3402 -- appear in the same declarative region (SPARK RM 9.3). Note that
3403 -- privacy is ignored.
3405 if Parent
(Item_Decl
) /= Parent
(Declaration_Node
(Encap_Id
)) then
3406 Error_Msg_Name_1
:= Chars
(Encap_Id
);
3408 (Fix_Msg
(Encap_Typ
, "constituent & must be declared "
3409 & "immediately within the same region as single protected "
3410 & "type %"), Indic
, Item_Id
);
3414 -- The declaration of the item should follow the declaration of its
3415 -- encapsulating single concurrent type and must appear in the same
3416 -- declarative region (SPARK RM 9.3).
3422 N
:= Next
(Declaration_Node
(Encap_Id
));
3423 while Present
(N
) loop
3424 exit when N
= Item_Decl
;
3428 -- The single concurrent type might be in the visible part of a
3429 -- package, and the declaration of the item in the private part
3430 -- of the same package.
3434 Pack
: constant Node_Id
:=
3435 Parent
(Declaration_Node
(Encap_Id
));
3437 if Nkind
(Pack
) = N_Package_Specification
3438 and then not In_Private_Part
(Encap_Id
)
3440 N
:= First
(Private_Declarations
(Pack
));
3441 while Present
(N
) loop
3442 exit when N
= Item_Decl
;
3451 ("indicator Part_Of must denote a previously declared "
3452 & "single protected type or single task type", Encap
);
3459 end Analyze_Part_Of
;
3461 ----------------------------------
3462 -- Analyze_Part_Of_In_Decl_Part --
3463 ----------------------------------
3465 procedure Analyze_Part_Of_In_Decl_Part
3467 Freeze_Id
: Entity_Id
:= Empty
)
3469 Encap
: constant Node_Id
:=
3470 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
3471 Errors
: constant Nat
:= Serious_Errors_Detected
;
3472 Var_Decl
: constant Node_Id
:= Find_Related_Context
(N
);
3473 Var_Id
: constant Entity_Id
:= Defining_Entity
(Var_Decl
);
3474 Constits
: Elist_Id
;
3475 Encap_Id
: Entity_Id
;
3479 -- Detect any discrepancies between the placement of the variable with
3480 -- respect to general state space and the encapsulating state or single
3487 Encap_Id
=> Encap_Id
,
3490 -- The Part_Of indicator turns the variable into a constituent of the
3491 -- encapsulating state or single concurrent type.
3494 pragma Assert
(Present
(Encap_Id
));
3495 Constits
:= Part_Of_Constituents
(Encap_Id
);
3497 if No
(Constits
) then
3498 Constits
:= New_Elmt_List
;
3499 Set_Part_Of_Constituents
(Encap_Id
, Constits
);
3502 Append_Elmt
(Var_Id
, Constits
);
3503 Set_Encapsulating_State
(Var_Id
, Encap_Id
);
3505 -- A Part_Of constituent partially refines an abstract state. This
3506 -- property does not apply to protected or task units.
3508 if Ekind
(Encap_Id
) = E_Abstract_State
then
3509 Set_Has_Partial_Visible_Refinement
(Encap_Id
);
3513 -- Emit a clarification message when the encapsulator is undefined,
3514 -- possibly due to contract freezing.
3516 if Errors
/= Serious_Errors_Detected
3517 and then Present
(Freeze_Id
)
3518 and then Has_Undefined_Reference
(Encap
)
3520 Contract_Freeze_Error
(Var_Id
, Freeze_Id
);
3522 end Analyze_Part_Of_In_Decl_Part
;
3524 --------------------
3525 -- Analyze_Pragma --
3526 --------------------
3528 procedure Analyze_Pragma
(N
: Node_Id
) is
3529 Loc
: constant Source_Ptr
:= Sloc
(N
);
3531 Pname
: Name_Id
:= Pragma_Name
(N
);
3532 -- Name of the source pragma, or name of the corresponding aspect for
3533 -- pragmas which originate in a source aspect. In the latter case, the
3534 -- name may be different from the pragma name.
3536 Prag_Id
: constant Pragma_Id
:= Get_Pragma_Id
(Pname
);
3538 Pragma_Exit
: exception;
3539 -- This exception is used to exit pragma processing completely. It
3540 -- is used when an error is detected, and no further processing is
3541 -- required. It is also used if an earlier error has left the tree in
3542 -- a state where the pragma should not be processed.
3545 -- Number of pragma argument associations
3551 -- First four pragma arguments (pragma argument association nodes, or
3552 -- Empty if the corresponding argument does not exist).
3554 type Name_List
is array (Natural range <>) of Name_Id
;
3555 type Args_List
is array (Natural range <>) of Node_Id
;
3556 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3558 -----------------------
3559 -- Local Subprograms --
3560 -----------------------
3562 procedure Acquire_Warning_Match_String
(Arg
: Node_Id
);
3563 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to
3564 -- get the given string argument, and place it in Name_Buffer, adding
3565 -- leading and trailing asterisks if they are not already present. The
3566 -- caller has already checked that Arg is a static string expression.
3568 procedure Ada_2005_Pragma
;
3569 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3570 -- Ada 95 mode, these are implementation defined pragmas, so should be
3571 -- caught by the No_Implementation_Pragmas restriction.
3573 procedure Ada_2012_Pragma
;
3574 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3575 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3576 -- should be caught by the No_Implementation_Pragmas restriction.
3578 procedure Analyze_Depends_Global
3579 (Spec_Id
: out Entity_Id
;
3580 Subp_Decl
: out Node_Id
;
3581 Legal
: out Boolean);
3582 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3583 -- legality of the placement and related context of the pragma. Spec_Id
3584 -- is the entity of the related subprogram. Subp_Decl is the declaration
3585 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3587 procedure Analyze_If_Present
(Id
: Pragma_Id
);
3588 -- Inspect the remainder of the list containing pragma N and look for
3589 -- a pragma that matches Id. If found, analyze the pragma.
3591 procedure Analyze_Pre_Post_Condition
;
3592 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3594 procedure Analyze_Refined_Depends_Global_Post
3595 (Spec_Id
: out Entity_Id
;
3596 Body_Id
: out Entity_Id
;
3597 Legal
: out Boolean);
3598 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3599 -- Refined_Global and Refined_Post. Verify the legality of the placement
3600 -- and related context of the pragma. Spec_Id is the entity of the
3601 -- related subprogram. Body_Id is the entity of the subprogram body.
3602 -- Flag Legal is set when the pragma is legal.
3604 procedure Analyze_Unmodified_Or_Unused
(Is_Unused
: Boolean := False);
3605 -- Perform full analysis of pragma Unmodified and the write aspect of
3606 -- pragma Unused. Flag Is_Unused should be set when verifying the
3607 -- semantics of pragma Unused.
3609 procedure Analyze_Unreferenced_Or_Unused
(Is_Unused
: Boolean := False);
3610 -- Perform full analysis of pragma Unreferenced and the read aspect of
3611 -- pragma Unused. Flag Is_Unused should be set when verifying the
3612 -- semantics of pragma Unused.
3614 procedure Check_Ada_83_Warning
;
3615 -- Issues a warning message for the current pragma if operating in Ada
3616 -- 83 mode (used for language pragmas that are not a standard part of
3617 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
3620 procedure Check_Arg_Count
(Required
: Nat
);
3621 -- Check argument count for pragma is equal to given parameter. If not,
3622 -- then issue an error message and raise Pragma_Exit.
3624 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
3625 -- Arg which can either be a pragma argument association, in which case
3626 -- the check is applied to the expression of the association or an
3627 -- expression directly.
3629 procedure Check_Arg_Is_External_Name
(Arg
: Node_Id
);
3630 -- Check that an argument has the right form for an EXTERNAL_NAME
3631 -- parameter of an extended import/export pragma. The rule is that the
3632 -- name must be an identifier or string literal (in Ada 83 mode) or a
3633 -- static string expression (in Ada 95 mode).
3635 procedure Check_Arg_Is_Identifier
(Arg
: Node_Id
);
3636 -- Check the specified argument Arg to make sure that it is an
3637 -- identifier. If not give error and raise Pragma_Exit.
3639 procedure Check_Arg_Is_Integer_Literal
(Arg
: Node_Id
);
3640 -- Check the specified argument Arg to make sure that it is an integer
3641 -- literal. If not give error and raise Pragma_Exit.
3643 procedure Check_Arg_Is_Library_Level_Local_Name
(Arg
: Node_Id
);
3644 -- Check the specified argument Arg to make sure that it has the proper
3645 -- syntactic form for a local name and meets the semantic requirements
3646 -- for a local name. The local name is analyzed as part of the
3647 -- processing for this call. In addition, the local name is required
3648 -- to represent an entity at the library level.
3650 procedure Check_Arg_Is_Local_Name
(Arg
: Node_Id
);
3651 -- Check the specified argument Arg to make sure that it has the proper
3652 -- syntactic form for a local name and meets the semantic requirements
3653 -- for a local name. The local name is analyzed as part of the
3654 -- processing for this call.
3656 procedure Check_Arg_Is_Locking_Policy
(Arg
: Node_Id
);
3657 -- Check the specified argument Arg to make sure that it is a valid
3658 -- locking policy name. If not give error and raise Pragma_Exit.
3660 procedure Check_Arg_Is_Partition_Elaboration_Policy
(Arg
: Node_Id
);
3661 -- Check the specified argument Arg to make sure that it is a valid
3662 -- elaboration policy name. If not give error and raise Pragma_Exit.
3664 procedure Check_Arg_Is_One_Of
3667 procedure Check_Arg_Is_One_Of
3669 N1
, N2
, N3
: Name_Id
);
3670 procedure Check_Arg_Is_One_Of
3672 N1
, N2
, N3
, N4
: Name_Id
);
3673 procedure Check_Arg_Is_One_Of
3675 N1
, N2
, N3
, N4
, N5
: Name_Id
);
3676 -- Check the specified argument Arg to make sure that it is an
3677 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
3678 -- present). If not then give error and raise Pragma_Exit.
3680 procedure Check_Arg_Is_Queuing_Policy
(Arg
: Node_Id
);
3681 -- Check the specified argument Arg to make sure that it is a valid
3682 -- queuing policy name. If not give error and raise Pragma_Exit.
3684 procedure Check_Arg_Is_OK_Static_Expression
3686 Typ
: Entity_Id
:= Empty
);
3687 -- Check the specified argument Arg to make sure that it is a static
3688 -- expression of the given type (i.e. it will be analyzed and resolved
3689 -- using this type, which can be any valid argument to Resolve, e.g.
3690 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3691 -- Typ is left Empty, then any static expression is allowed. Includes
3692 -- checking that the argument does not raise Constraint_Error.
3694 procedure Check_Arg_Is_Task_Dispatching_Policy
(Arg
: Node_Id
);
3695 -- Check the specified argument Arg to make sure that it is a valid task
3696 -- dispatching policy name. If not give error and raise Pragma_Exit.
3698 procedure Check_Arg_Order
(Names
: Name_List
);
3699 -- Checks for an instance of two arguments with identifiers for the
3700 -- current pragma which are not in the sequence indicated by Names,
3701 -- and if so, generates a fatal message about bad order of arguments.
3703 procedure Check_At_Least_N_Arguments
(N
: Nat
);
3704 -- Check there are at least N arguments present
3706 procedure Check_At_Most_N_Arguments
(N
: Nat
);
3707 -- Check there are no more than N arguments present
3709 procedure Check_Component
3712 In_Variant_Part
: Boolean := False);
3713 -- Examine an Unchecked_Union component for correct use of per-object
3714 -- constrained subtypes, and for restrictions on finalizable components.
3715 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
3716 -- should be set when Comp comes from a record variant.
3718 procedure Check_Duplicate_Pragma
(E
: Entity_Id
);
3719 -- Check if a rep item of the same name as the current pragma is already
3720 -- chained as a rep pragma to the given entity. If so give a message
3721 -- about the duplicate, and then raise Pragma_Exit so does not return.
3722 -- Note that if E is a type, then this routine avoids flagging a pragma
3723 -- which applies to a parent type from which E is derived.
3725 procedure Check_Duplicated_Export_Name
(Nam
: Node_Id
);
3726 -- Nam is an N_String_Literal node containing the external name set by
3727 -- an Import or Export pragma (or extended Import or Export pragma).
3728 -- This procedure checks for possible duplications if this is the export
3729 -- case, and if found, issues an appropriate error message.
3731 procedure Check_Expr_Is_OK_Static_Expression
3733 Typ
: Entity_Id
:= Empty
);
3734 -- Check the specified expression Expr to make sure that it is a static
3735 -- expression of the given type (i.e. it will be analyzed and resolved
3736 -- using this type, which can be any valid argument to Resolve, e.g.
3737 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3738 -- Typ is left Empty, then any static expression is allowed. Includes
3739 -- checking that the expression does not raise Constraint_Error.
3741 procedure Check_First_Subtype
(Arg
: Node_Id
);
3742 -- Checks that Arg, whose expression is an entity name, references a
3745 procedure Check_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
3746 -- Checks that the given argument has an identifier, and if so, requires
3747 -- it to match the given identifier name. If there is no identifier, or
3748 -- a non-matching identifier, then an error message is given and
3749 -- Pragma_Exit is raised.
3751 procedure Check_Identifier_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
);
3752 -- Checks that the given argument has an identifier, and if so, requires
3753 -- it to match one of the given identifier names. If there is no
3754 -- identifier, or a non-matching identifier, then an error message is
3755 -- given and Pragma_Exit is raised.
3757 procedure Check_In_Main_Program
;
3758 -- Common checks for pragmas that appear within a main program
3759 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
3761 procedure Check_Interrupt_Or_Attach_Handler
;
3762 -- Common processing for first argument of pragma Interrupt_Handler or
3763 -- pragma Attach_Handler.
3765 procedure Check_Loop_Pragma_Placement
;
3766 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
3767 -- appear immediately within a construct restricted to loops, and that
3768 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
3770 procedure Check_Is_In_Decl_Part_Or_Package_Spec
;
3771 -- Check that pragma appears in a declarative part, or in a package
3772 -- specification, i.e. that it does not occur in a statement sequence
3775 procedure Check_No_Identifier
(Arg
: Node_Id
);
3776 -- Checks that the given argument does not have an identifier. If
3777 -- an identifier is present, then an error message is issued, and
3778 -- Pragma_Exit is raised.
3780 procedure Check_No_Identifiers
;
3781 -- Checks that none of the arguments to the pragma has an identifier.
3782 -- If any argument has an identifier, then an error message is issued,
3783 -- and Pragma_Exit is raised.
3785 procedure Check_No_Link_Name
;
3786 -- Checks that no link name is specified
3788 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
3789 -- Checks if the given argument has an identifier, and if so, requires
3790 -- it to match the given identifier name. If there is a non-matching
3791 -- identifier, then an error message is given and Pragma_Exit is raised.
3793 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: String);
3794 -- Checks if the given argument has an identifier, and if so, requires
3795 -- it to match the given identifier name. If there is a non-matching
3796 -- identifier, then an error message is given and Pragma_Exit is raised.
3797 -- In this version of the procedure, the identifier name is given as
3798 -- a string with lower case letters.
3800 procedure Check_Static_Boolean_Expression
(Expr
: Node_Id
);
3801 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
3802 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
3803 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
3804 -- is an OK static boolean expression. Emit an error if this is not the
3807 procedure Check_Static_Constraint
(Constr
: Node_Id
);
3808 -- Constr is a constraint from an N_Subtype_Indication node from a
3809 -- component constraint in an Unchecked_Union type. This routine checks
3810 -- that the constraint is static as required by the restrictions for
3813 procedure Check_Valid_Configuration_Pragma
;
3814 -- Legality checks for placement of a configuration pragma
3816 procedure Check_Valid_Library_Unit_Pragma
;
3817 -- Legality checks for library unit pragmas. A special case arises for
3818 -- pragmas in generic instances that come from copies of the original
3819 -- library unit pragmas in the generic templates. In the case of other
3820 -- than library level instantiations these can appear in contexts which
3821 -- would normally be invalid (they only apply to the original template
3822 -- and to library level instantiations), and they are simply ignored,
3823 -- which is implemented by rewriting them as null statements.
3825 procedure Check_Variant
(Variant
: Node_Id
; UU_Typ
: Entity_Id
);
3826 -- Check an Unchecked_Union variant for lack of nested variants and
3827 -- presence of at least one component. UU_Typ is the related Unchecked_
3830 procedure Ensure_Aggregate_Form
(Arg
: Node_Id
);
3831 -- Subsidiary routine to the processing of pragmas Abstract_State,
3832 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
3833 -- Refined_Global and Refined_State. Transform argument Arg into
3834 -- an aggregate if not one already. N_Null is never transformed.
3835 -- Arg may denote an aspect specification or a pragma argument
3838 procedure Error_Pragma
(Msg
: String);
3839 pragma No_Return
(Error_Pragma
);
3840 -- Outputs error message for current pragma. The message contains a %
3841 -- that will be replaced with the pragma name, and the flag is placed
3842 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
3843 -- calls Fix_Error (see spec of that procedure for details).
3845 procedure Error_Pragma_Arg
(Msg
: String; Arg
: Node_Id
);
3846 pragma No_Return
(Error_Pragma_Arg
);
3847 -- Outputs error message for current pragma. The message may contain
3848 -- a % that will be replaced with the pragma name. The parameter Arg
3849 -- may either be a pragma argument association, in which case the flag
3850 -- is placed on the expression of this association, or an expression,
3851 -- in which case the flag is placed directly on the expression. The
3852 -- message is placed using Error_Msg_N, so the message may also contain
3853 -- an & insertion character which will reference the given Arg value.
3854 -- After placing the message, Pragma_Exit is raised. Note: this routine
3855 -- calls Fix_Error (see spec of that procedure for details).
3857 procedure Error_Pragma_Arg
(Msg1
, Msg2
: String; Arg
: Node_Id
);
3858 pragma No_Return
(Error_Pragma_Arg
);
3859 -- Similar to above form of Error_Pragma_Arg except that two messages
3860 -- are provided, the second is a continuation comment starting with \.
3862 procedure Error_Pragma_Arg_Ident
(Msg
: String; Arg
: Node_Id
);
3863 pragma No_Return
(Error_Pragma_Arg_Ident
);
3864 -- Outputs error message for current pragma. The message may contain a %
3865 -- that will be replaced with the pragma name. The parameter Arg must be
3866 -- a pragma argument association with a non-empty identifier (i.e. its
3867 -- Chars field must be set), and the error message is placed on the
3868 -- identifier. The message is placed using Error_Msg_N so the message
3869 -- may also contain an & insertion character which will reference
3870 -- the identifier. After placing the message, Pragma_Exit is raised.
3871 -- Note: this routine calls Fix_Error (see spec of that procedure for
3874 procedure Error_Pragma_Ref
(Msg
: String; Ref
: Entity_Id
);
3875 pragma No_Return
(Error_Pragma_Ref
);
3876 -- Outputs error message for current pragma. The message may contain
3877 -- a % that will be replaced with the pragma name. The parameter Ref
3878 -- must be an entity whose name can be referenced by & and sloc by #.
3879 -- After placing the message, Pragma_Exit is raised. Note: this routine
3880 -- calls Fix_Error (see spec of that procedure for details).
3882 function Find_Lib_Unit_Name
return Entity_Id
;
3883 -- Used for a library unit pragma to find the entity to which the
3884 -- library unit pragma applies, returns the entity found.
3886 procedure Find_Program_Unit_Name
(Id
: Node_Id
);
3887 -- If the pragma is a compilation unit pragma, the id must denote the
3888 -- compilation unit in the same compilation, and the pragma must appear
3889 -- in the list of preceding or trailing pragmas. If it is a program
3890 -- unit pragma that is not a compilation unit pragma, then the
3891 -- identifier must be visible.
3893 function Find_Unique_Parameterless_Procedure
3895 Arg
: Node_Id
) return Entity_Id
;
3896 -- Used for a procedure pragma to find the unique parameterless
3897 -- procedure identified by Name, returns it if it exists, otherwise
3898 -- errors out and uses Arg as the pragma argument for the message.
3900 function Fix_Error
(Msg
: String) return String;
3901 -- This is called prior to issuing an error message. Msg is the normal
3902 -- error message issued in the pragma case. This routine checks for the
3903 -- case of a pragma coming from an aspect in the source, and returns a
3904 -- message suitable for the aspect case as follows:
3906 -- Each substring "pragma" is replaced by "aspect"
3908 -- If "argument of" is at the start of the error message text, it is
3909 -- replaced by "entity for".
3911 -- If "argument" is at the start of the error message text, it is
3912 -- replaced by "entity".
3914 -- So for example, "argument of pragma X must be discrete type"
3915 -- returns "entity for aspect X must be a discrete type".
3917 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
3918 -- be different from the pragma name). If the current pragma results
3919 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
3920 -- original pragma name.
3922 procedure Gather_Associations
3924 Args
: out Args_List
);
3925 -- This procedure is used to gather the arguments for a pragma that
3926 -- permits arbitrary ordering of parameters using the normal rules
3927 -- for named and positional parameters. The Names argument is a list
3928 -- of Name_Id values that corresponds to the allowed pragma argument
3929 -- association identifiers in order. The result returned in Args is
3930 -- a list of corresponding expressions that are the pragma arguments.
3931 -- Note that this is a list of expressions, not of pragma argument
3932 -- associations (Gather_Associations has completely checked all the
3933 -- optional identifiers when it returns). An entry in Args is Empty
3934 -- on return if the corresponding argument is not present.
3936 procedure GNAT_Pragma
;
3937 -- Called for all GNAT defined pragmas to check the relevant restriction
3938 -- (No_Implementation_Pragmas).
3940 function Is_Before_First_Decl
3941 (Pragma_Node
: Node_Id
;
3942 Decls
: List_Id
) return Boolean;
3943 -- Return True if Pragma_Node is before the first declarative item in
3944 -- Decls where Decls is the list of declarative items.
3946 function Is_Configuration_Pragma
return Boolean;
3947 -- Determines if the placement of the current pragma is appropriate
3948 -- for a configuration pragma.
3950 function Is_In_Context_Clause
return Boolean;
3951 -- Returns True if pragma appears within the context clause of a unit,
3952 -- and False for any other placement (does not generate any messages).
3954 function Is_Static_String_Expression
(Arg
: Node_Id
) return Boolean;
3955 -- Analyzes the argument, and determines if it is a static string
3956 -- expression, returns True if so, False if non-static or not String.
3957 -- A special case is that a string literal returns True in Ada 83 mode
3958 -- (which has no such thing as static string expressions). Note that
3959 -- the call analyzes its argument, so this cannot be used for the case
3960 -- where an identifier might not be declared.
3962 procedure Pragma_Misplaced
;
3963 pragma No_Return
(Pragma_Misplaced
);
3964 -- Issue fatal error message for misplaced pragma
3966 procedure Process_Atomic_Independent_Shared_Volatile
;
3967 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
3968 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
3969 -- and treated as being identical in effect to pragma Atomic.
3971 procedure Process_Compile_Time_Warning_Or_Error
;
3972 -- Common processing for Compile_Time_Error and Compile_Time_Warning
3974 procedure Process_Convention
3975 (C
: out Convention_Id
;
3976 Ent
: out Entity_Id
);
3977 -- Common processing for Convention, Interface, Import and Export.
3978 -- Checks first two arguments of pragma, and sets the appropriate
3979 -- convention value in the specified entity or entities. On return
3980 -- C is the convention, Ent is the referenced entity.
3982 procedure Process_Disable_Enable_Atomic_Sync
(Nam
: Name_Id
);
3983 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
3984 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
3986 procedure Process_Extended_Import_Export_Object_Pragma
3987 (Arg_Internal
: Node_Id
;
3988 Arg_External
: Node_Id
;
3989 Arg_Size
: Node_Id
);
3990 -- Common processing for the pragmas Import/Export_Object. The three
3991 -- arguments correspond to the three named parameters of the pragmas. An
3992 -- argument is empty if the corresponding parameter is not present in
3995 procedure Process_Extended_Import_Export_Internal_Arg
3996 (Arg_Internal
: Node_Id
:= Empty
);
3997 -- Common processing for all extended Import and Export pragmas. The
3998 -- argument is the pragma parameter for the Internal argument. If
3999 -- Arg_Internal is empty or inappropriate, an error message is posted.
4000 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
4001 -- set to identify the referenced entity.
4003 procedure Process_Extended_Import_Export_Subprogram_Pragma
4004 (Arg_Internal
: Node_Id
;
4005 Arg_External
: Node_Id
;
4006 Arg_Parameter_Types
: Node_Id
;
4007 Arg_Result_Type
: Node_Id
:= Empty
;
4008 Arg_Mechanism
: Node_Id
;
4009 Arg_Result_Mechanism
: Node_Id
:= Empty
);
4010 -- Common processing for all extended Import and Export pragmas applying
4011 -- to subprograms. The caller omits any arguments that do not apply to
4012 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
4013 -- only in the Import_Function and Export_Function cases). The argument
4014 -- names correspond to the allowed pragma association identifiers.
4016 procedure Process_Generic_List
;
4017 -- Common processing for Share_Generic and Inline_Generic
4019 procedure Process_Import_Or_Interface
;
4020 -- Common processing for Import or Interface
4022 procedure Process_Import_Predefined_Type
;
4023 -- Processing for completing a type with pragma Import. This is used
4024 -- to declare types that match predefined C types, especially for cases
4025 -- without corresponding Ada predefined type.
4027 type Inline_Status
is (Suppressed
, Disabled
, Enabled
);
4028 -- Inline status of a subprogram, indicated as follows:
4029 -- Suppressed: inlining is suppressed for the subprogram
4030 -- Disabled: no inlining is requested for the subprogram
4031 -- Enabled: inlining is requested/required for the subprogram
4033 procedure Process_Inline
(Status
: Inline_Status
);
4034 -- Common processing for No_Inline, Inline and Inline_Always. Parameter
4035 -- indicates the inline status specified by the pragma.
4037 procedure Process_Interface_Name
4038 (Subprogram_Def
: Entity_Id
;
4042 -- Given the last two arguments of pragma Import, pragma Export, or
4043 -- pragma Interface_Name, performs validity checks and sets the
4044 -- Interface_Name field of the given subprogram entity to the
4045 -- appropriate external or link name, depending on the arguments given.
4046 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
4047 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
4048 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
4049 -- nor Link_Arg is present, the interface name is set to the default
4050 -- from the subprogram name. In addition, the pragma itself is passed
4051 -- to analyze any expressions in the case the pragma came from an aspect
4054 procedure Process_Interrupt_Or_Attach_Handler
;
4055 -- Common processing for Interrupt and Attach_Handler pragmas
4057 procedure Process_Restrictions_Or_Restriction_Warnings
(Warn
: Boolean);
4058 -- Common processing for Restrictions and Restriction_Warnings pragmas.
4059 -- Warn is True for Restriction_Warnings, or for Restrictions if the
4060 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
4061 -- is not set in the Restrictions case.
4063 procedure Process_Suppress_Unsuppress
(Suppress_Case
: Boolean);
4064 -- Common processing for Suppress and Unsuppress. The boolean parameter
4065 -- Suppress_Case is True for the Suppress case, and False for the
4068 procedure Record_Independence_Check
(N
: Node_Id
; E
: Entity_Id
);
4069 -- Subsidiary to the analysis of pragmas Independent[_Components].
4070 -- Record such a pragma N applied to entity E for future checks.
4072 procedure Set_Exported
(E
: Entity_Id
; Arg
: Node_Id
);
4073 -- This procedure sets the Is_Exported flag for the given entity,
4074 -- checking that the entity was not previously imported. Arg is
4075 -- the argument that specified the entity. A check is also made
4076 -- for exporting inappropriate entities.
4078 procedure Set_Extended_Import_Export_External_Name
4079 (Internal_Ent
: Entity_Id
;
4080 Arg_External
: Node_Id
);
4081 -- Common processing for all extended import export pragmas. The first
4082 -- argument, Internal_Ent, is the internal entity, which has already
4083 -- been checked for validity by the caller. Arg_External is from the
4084 -- Import or Export pragma, and may be null if no External parameter
4085 -- was present. If Arg_External is present and is a non-null string
4086 -- (a null string is treated as the default), then the Interface_Name
4087 -- field of Internal_Ent is set appropriately.
4089 procedure Set_Imported
(E
: Entity_Id
);
4090 -- This procedure sets the Is_Imported flag for the given entity,
4091 -- checking that it is not previously exported or imported.
4093 procedure Set_Mechanism_Value
(Ent
: Entity_Id
; Mech_Name
: Node_Id
);
4094 -- Mech is a parameter passing mechanism (see Import_Function syntax
4095 -- for MECHANISM_NAME). This routine checks that the mechanism argument
4096 -- has the right form, and if not issues an error message. If the
4097 -- argument has the right form then the Mechanism field of Ent is
4098 -- set appropriately.
4100 procedure Set_Rational_Profile
;
4101 -- Activate the set of configuration pragmas and permissions that make
4102 -- up the Rational profile.
4104 procedure Set_Ravenscar_Profile
(Profile
: Profile_Name
; N
: Node_Id
);
4105 -- Activate the set of configuration pragmas and restrictions that make
4106 -- up the Profile. Profile must be either GNAT_Extended_Ravenscar,
4107 -- GNAT_Ravenscar_EDF, or Ravenscar. N is the corresponding pragma node,
4108 -- which is used for error messages on any constructs violating the
4111 ----------------------------------
4112 -- Acquire_Warning_Match_String --
4113 ----------------------------------
4115 procedure Acquire_Warning_Match_String
(Arg
: Node_Id
) is
4117 String_To_Name_Buffer
4118 (Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
))));
4120 -- Add asterisk at start if not already there
4122 if Name_Len
> 0 and then Name_Buffer
(1) /= '*' then
4123 Name_Buffer
(2 .. Name_Len
+ 1) :=
4124 Name_Buffer
(1 .. Name_Len
);
4125 Name_Buffer
(1) := '*';
4126 Name_Len
:= Name_Len
+ 1;
4129 -- Add asterisk at end if not already there
4131 if Name_Buffer
(Name_Len
) /= '*' then
4132 Name_Len
:= Name_Len
+ 1;
4133 Name_Buffer
(Name_Len
) := '*';
4135 end Acquire_Warning_Match_String
;
4137 ---------------------
4138 -- Ada_2005_Pragma --
4139 ---------------------
4141 procedure Ada_2005_Pragma
is
4143 if Ada_Version
<= Ada_95
then
4144 Check_Restriction
(No_Implementation_Pragmas
, N
);
4146 end Ada_2005_Pragma
;
4148 ---------------------
4149 -- Ada_2012_Pragma --
4150 ---------------------
4152 procedure Ada_2012_Pragma
is
4154 if Ada_Version
<= Ada_2005
then
4155 Check_Restriction
(No_Implementation_Pragmas
, N
);
4157 end Ada_2012_Pragma
;
4159 ----------------------------
4160 -- Analyze_Depends_Global --
4161 ----------------------------
4163 procedure Analyze_Depends_Global
4164 (Spec_Id
: out Entity_Id
;
4165 Subp_Decl
: out Node_Id
;
4166 Legal
: out Boolean)
4169 -- Assume that the pragma is illegal
4176 Check_Arg_Count
(1);
4178 -- Ensure the proper placement of the pragma. Depends/Global must be
4179 -- associated with a subprogram declaration or a body that acts as a
4182 Subp_Decl
:= Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
4186 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
4189 -- Generic subprogram
4191 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
4194 -- Object declaration of a single concurrent type
4196 elsif Nkind
(Subp_Decl
) = N_Object_Declaration
4197 and then Is_Single_Concurrent_Object
4198 (Unique_Defining_Entity
(Subp_Decl
))
4204 elsif Nkind
(Subp_Decl
) = N_Single_Task_Declaration
then
4207 -- Subprogram body acts as spec
4209 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
4210 and then No
(Corresponding_Spec
(Subp_Decl
))
4214 -- Subprogram body stub acts as spec
4216 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
4217 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
4221 -- Subprogram declaration
4223 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
4228 elsif Nkind
(Subp_Decl
) = N_Task_Type_Declaration
then
4236 -- If we get here, then the pragma is legal
4239 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
4241 -- When the related context is an entry, the entry must belong to a
4242 -- protected unit (SPARK RM 6.1.4(6)).
4244 if Is_Entry_Declaration
(Spec_Id
)
4245 and then Ekind
(Scope
(Spec_Id
)) /= E_Protected_Type
4250 -- When the related context is an anonymous object created for a
4251 -- simple concurrent type, the type must be a task
4252 -- (SPARK RM 6.1.4(6)).
4254 elsif Is_Single_Concurrent_Object
(Spec_Id
)
4255 and then Ekind
(Etype
(Spec_Id
)) /= E_Task_Type
4261 -- A pragma that applies to a Ghost entity becomes Ghost for the
4262 -- purposes of legality checks and removal of ignored Ghost code.
4264 Mark_Ghost_Pragma
(N
, Spec_Id
);
4265 Ensure_Aggregate_Form
(Get_Argument
(N
, Spec_Id
));
4266 end Analyze_Depends_Global
;
4268 ------------------------
4269 -- Analyze_If_Present --
4270 ------------------------
4272 procedure Analyze_If_Present
(Id
: Pragma_Id
) is
4276 pragma Assert
(Is_List_Member
(N
));
4278 -- Inspect the declarations or statements following pragma N looking
4279 -- for another pragma whose Id matches the caller's request. If it is
4280 -- available, analyze it.
4283 while Present
(Stmt
) loop
4284 if Nkind
(Stmt
) = N_Pragma
and then Get_Pragma_Id
(Stmt
) = Id
then
4285 Analyze_Pragma
(Stmt
);
4288 -- The first source declaration or statement immediately following
4289 -- N ends the region where a pragma may appear.
4291 elsif Comes_From_Source
(Stmt
) then
4297 end Analyze_If_Present
;
4299 --------------------------------
4300 -- Analyze_Pre_Post_Condition --
4301 --------------------------------
4303 procedure Analyze_Pre_Post_Condition
is
4304 Prag_Iden
: constant Node_Id
:= Pragma_Identifier
(N
);
4305 Subp_Decl
: Node_Id
;
4306 Subp_Id
: Entity_Id
;
4308 Duplicates_OK
: Boolean := False;
4309 -- Flag set when a pre/postcondition allows multiple pragmas of the
4312 In_Body_OK
: Boolean := False;
4313 -- Flag set when a pre/postcondition is allowed to appear on a body
4314 -- even though the subprogram may have a spec.
4316 Is_Pre_Post
: Boolean := False;
4317 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4320 function Inherits_Class_Wide_Pre
(E
: Entity_Id
) return Boolean;
4321 -- Implement rules in AI12-0131: an overriding operation can have
4322 -- a class-wide precondition only if one of its ancestors has an
4323 -- explicit class-wide precondition.
4325 -----------------------------
4326 -- Inherits_Class_Wide_Pre --
4327 -----------------------------
4329 function Inherits_Class_Wide_Pre
(E
: Entity_Id
) return Boolean is
4330 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(E
);
4333 Prev
: Entity_Id
:= Overridden_Operation
(E
);
4336 -- Check ancestors on the overriding operation to examine the
4337 -- preconditions that may apply to them.
4339 while Present
(Prev
) loop
4340 Cont
:= Contract
(Prev
);
4341 if Present
(Cont
) then
4342 Prag
:= Pre_Post_Conditions
(Cont
);
4343 while Present
(Prag
) loop
4344 if Class_Present
(Prag
) then
4348 Prag
:= Next_Pragma
(Prag
);
4352 -- For a type derived from a generic formal type, the operation
4353 -- inheriting the condition is a renaming, not an overriding of
4354 -- the operation of the formal. Ditto for an inherited
4355 -- operation which has no explicit contracts.
4357 if Is_Generic_Type
(Find_Dispatching_Type
(Prev
))
4358 or else not Comes_From_Source
(Prev
)
4360 Prev
:= Alias
(Prev
);
4362 Prev
:= Overridden_Operation
(Prev
);
4366 -- If the controlling type of the subprogram has progenitors, an
4367 -- interface operation implemented by the current operation may
4368 -- have a class-wide precondition.
4370 if Has_Interfaces
(Typ
) then
4375 Prim_Elmt
: Elmt_Id
;
4376 Prim_List
: Elist_Id
;
4379 Collect_Interfaces
(Typ
, Ints
);
4380 Elmt
:= First_Elmt
(Ints
);
4382 -- Iterate over the primitive operations of each interface
4384 while Present
(Elmt
) loop
4385 Prim_List
:= Direct_Primitive_Operations
(Node
(Elmt
));
4386 Prim_Elmt
:= First_Elmt
(Prim_List
);
4387 while Present
(Prim_Elmt
) loop
4388 Prim
:= Node
(Prim_Elmt
);
4389 if Chars
(Prim
) = Chars
(E
)
4390 and then Present
(Contract
(Prim
))
4391 and then Class_Present
4392 (Pre_Post_Conditions
(Contract
(Prim
)))
4397 Next_Elmt
(Prim_Elmt
);
4406 end Inherits_Class_Wide_Pre
;
4408 -- Start of processing for Analyze_Pre_Post_Condition
4411 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4412 -- offer uniformity among the various kinds of pre/postconditions by
4413 -- rewriting the pragma identifier. This allows the retrieval of the
4414 -- original pragma name by routine Original_Aspect_Pragma_Name.
4416 if Comes_From_Source
(N
) then
4417 if Nam_In
(Pname
, Name_Pre
, Name_Pre_Class
) then
4418 Is_Pre_Post
:= True;
4419 Set_Class_Present
(N
, Pname
= Name_Pre_Class
);
4420 Rewrite
(Prag_Iden
, Make_Identifier
(Loc
, Name_Precondition
));
4422 elsif Nam_In
(Pname
, Name_Post
, Name_Post_Class
) then
4423 Is_Pre_Post
:= True;
4424 Set_Class_Present
(N
, Pname
= Name_Post_Class
);
4425 Rewrite
(Prag_Iden
, Make_Identifier
(Loc
, Name_Postcondition
));
4429 -- Determine the semantics with respect to duplicates and placement
4430 -- in a body. Pragmas Precondition and Postcondition were introduced
4431 -- before aspects and are not subject to the same aspect-like rules.
4433 if Nam_In
(Pname
, Name_Precondition
, Name_Postcondition
) then
4434 Duplicates_OK
:= True;
4440 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4441 -- argument without an identifier.
4444 Check_Arg_Count
(1);
4445 Check_No_Identifiers
;
4447 -- Pragmas Precondition and Postcondition have complex argument
4451 Check_At_Least_N_Arguments
(1);
4452 Check_At_Most_N_Arguments
(2);
4453 Check_Optional_Identifier
(Arg1
, Name_Check
);
4455 if Present
(Arg2
) then
4456 Check_Optional_Identifier
(Arg2
, Name_Message
);
4457 Preanalyze_Spec_Expression
4458 (Get_Pragma_Arg
(Arg2
), Standard_String
);
4462 -- For a pragma PPC in the extended main source unit, record enabled
4464 -- ??? nothing checks that the pragma is in the main source unit
4466 if Is_Checked
(N
) and then not Split_PPC
(N
) then
4467 Set_SCO_Pragma_Enabled
(Loc
);
4470 -- Ensure the proper placement of the pragma
4473 Find_Related_Declaration_Or_Body
4474 (N
, Do_Checks
=> not Duplicates_OK
);
4476 -- When a pre/postcondition pragma applies to an abstract subprogram,
4477 -- its original form must be an aspect with 'Class.
4479 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
4480 if not From_Aspect_Specification
(N
) then
4482 ("pragma % cannot be applied to abstract subprogram");
4484 elsif not Class_Present
(N
) then
4486 ("aspect % requires ''Class for abstract subprogram");
4489 -- Entry declaration
4491 elsif Nkind
(Subp_Decl
) = N_Entry_Declaration
then
4494 -- Generic subprogram declaration
4496 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
4501 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
4502 and then (No
(Corresponding_Spec
(Subp_Decl
)) or In_Body_OK
)
4506 -- Subprogram body stub
4508 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
4509 and then (No
(Corresponding_Spec_Of_Stub
(Subp_Decl
)) or In_Body_OK
)
4513 -- Subprogram declaration
4515 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
4517 -- AI05-0230: When a pre/postcondition pragma applies to a null
4518 -- procedure, its original form must be an aspect with 'Class.
4520 if Nkind
(Specification
(Subp_Decl
)) = N_Procedure_Specification
4521 and then Null_Present
(Specification
(Subp_Decl
))
4522 and then From_Aspect_Specification
(N
)
4523 and then not Class_Present
(N
)
4525 Error_Pragma
("aspect % requires ''Class for null procedure");
4528 -- Implement the legality checks mandated by AI12-0131:
4529 -- Pre'Class shall not be specified for an overriding primitive
4530 -- subprogram of a tagged type T unless the Pre'Class aspect is
4531 -- specified for the corresponding primitive subprogram of some
4535 E
: constant Entity_Id
:= Defining_Entity
(Subp_Decl
);
4538 if Class_Present
(N
)
4539 and then Pragma_Name
(N
) = Name_Precondition
4540 and then Present
(Overridden_Operation
(E
))
4541 and then not Inherits_Class_Wide_Pre
(E
)
4544 ("illegal class-wide precondition on overriding operation",
4545 Corresponding_Aspect
(N
));
4549 -- A renaming declaration may inherit a generated pragma, its
4550 -- placement comes from expansion, not from source.
4552 elsif Nkind
(Subp_Decl
) = N_Subprogram_Renaming_Declaration
4553 and then not Comes_From_Source
(N
)
4557 -- Otherwise the placement is illegal
4564 Subp_Id
:= Defining_Entity
(Subp_Decl
);
4566 -- A pragma that applies to a Ghost entity becomes Ghost for the
4567 -- purposes of legality checks and removal of ignored Ghost code.
4569 Mark_Ghost_Pragma
(N
, Subp_Id
);
4571 -- Chain the pragma on the contract for further processing by
4572 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4574 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
4576 -- Fully analyze the pragma when it appears inside an entry or
4577 -- subprogram body because it cannot benefit from forward references.
4579 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
4581 N_Subprogram_Body_Stub
)
4583 -- The legality checks of pragmas Precondition and Postcondition
4584 -- are affected by the SPARK mode in effect and the volatility of
4585 -- the context. Analyze all pragmas in a specific order.
4587 Analyze_If_Present
(Pragma_SPARK_Mode
);
4588 Analyze_If_Present
(Pragma_Volatile_Function
);
4589 Analyze_Pre_Post_Condition_In_Decl_Part
(N
);
4591 end Analyze_Pre_Post_Condition
;
4593 -----------------------------------------
4594 -- Analyze_Refined_Depends_Global_Post --
4595 -----------------------------------------
4597 procedure Analyze_Refined_Depends_Global_Post
4598 (Spec_Id
: out Entity_Id
;
4599 Body_Id
: out Entity_Id
;
4600 Legal
: out Boolean)
4602 Body_Decl
: Node_Id
;
4603 Spec_Decl
: Node_Id
;
4606 -- Assume that the pragma is illegal
4613 Check_Arg_Count
(1);
4614 Check_No_Identifiers
;
4616 -- Verify the placement of the pragma and check for duplicates. The
4617 -- pragma must apply to a subprogram body [stub].
4619 Body_Decl
:= Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
4623 if Nkind
(Body_Decl
) = N_Entry_Body
then
4628 elsif Nkind
(Body_Decl
) = N_Subprogram_Body
then
4631 -- Subprogram body stub
4633 elsif Nkind
(Body_Decl
) = N_Subprogram_Body_Stub
then
4638 elsif Nkind
(Body_Decl
) = N_Task_Body
then
4646 Body_Id
:= Defining_Entity
(Body_Decl
);
4647 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
4649 -- The pragma must apply to the second declaration of a subprogram.
4650 -- In other words, the body [stub] cannot acts as a spec.
4652 if No
(Spec_Id
) then
4653 Error_Pragma
("pragma % cannot apply to a stand alone body");
4656 -- Catch the case where the subprogram body is a subunit and acts as
4657 -- the third declaration of the subprogram.
4659 elsif Nkind
(Parent
(Body_Decl
)) = N_Subunit
then
4660 Error_Pragma
("pragma % cannot apply to a subunit");
4664 -- A refined pragma can only apply to the body [stub] of a subprogram
4665 -- declared in the visible part of a package. Retrieve the context of
4666 -- the subprogram declaration.
4668 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
4670 -- When dealing with protected entries or protected subprograms, use
4671 -- the enclosing protected type as the proper context.
4673 if Ekind_In
(Spec_Id
, E_Entry
,
4677 and then Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
4679 Spec_Decl
:= Declaration_Node
(Scope
(Spec_Id
));
4682 if Nkind
(Parent
(Spec_Decl
)) /= N_Package_Specification
then
4684 (Fix_Msg
(Spec_Id
, "pragma % must apply to the body of "
4685 & "subprogram declared in a package specification"));
4689 -- If we get here, then the pragma is legal
4693 -- A pragma that applies to a Ghost entity becomes Ghost for the
4694 -- purposes of legality checks and removal of ignored Ghost code.
4696 Mark_Ghost_Pragma
(N
, Spec_Id
);
4698 if Nam_In
(Pname
, Name_Refined_Depends
, Name_Refined_Global
) then
4699 Ensure_Aggregate_Form
(Get_Argument
(N
, Spec_Id
));
4701 end Analyze_Refined_Depends_Global_Post
;
4703 ----------------------------------
4704 -- Analyze_Unmodified_Or_Unused --
4705 ----------------------------------
4707 procedure Analyze_Unmodified_Or_Unused
(Is_Unused
: Boolean := False) is
4712 Ghost_Error_Posted
: Boolean := False;
4713 -- Flag set when an error concerning the illegal mix of Ghost and
4714 -- non-Ghost variables is emitted.
4716 Ghost_Id
: Entity_Id
:= Empty
;
4717 -- The entity of the first Ghost variable encountered while
4718 -- processing the arguments of the pragma.
4722 Check_At_Least_N_Arguments
(1);
4724 -- Loop through arguments
4727 while Present
(Arg
) loop
4728 Check_No_Identifier
(Arg
);
4730 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
4731 -- in fact generate reference, so that the entity will have a
4732 -- reference, which will inhibit any warnings about it not
4733 -- being referenced, and also properly show up in the ali file
4734 -- as a reference. But this reference is recorded before the
4735 -- Has_Pragma_Unreferenced flag is set, so that no warning is
4736 -- generated for this reference.
4738 Check_Arg_Is_Local_Name
(Arg
);
4739 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
4741 if Is_Entity_Name
(Arg_Expr
) then
4742 Arg_Id
:= Entity
(Arg_Expr
);
4744 -- Skip processing the argument if already flagged
4746 if Is_Assignable
(Arg_Id
)
4747 and then not Has_Pragma_Unmodified
(Arg_Id
)
4748 and then not Has_Pragma_Unused
(Arg_Id
)
4750 Set_Has_Pragma_Unmodified
(Arg_Id
);
4753 Set_Has_Pragma_Unused
(Arg_Id
);
4756 -- A pragma that applies to a Ghost entity becomes Ghost for
4757 -- the purposes of legality checks and removal of ignored
4760 Mark_Ghost_Pragma
(N
, Arg_Id
);
4762 -- Capture the entity of the first Ghost variable being
4763 -- processed for error detection purposes.
4765 if Is_Ghost_Entity
(Arg_Id
) then
4766 if No
(Ghost_Id
) then
4770 -- Otherwise the variable is non-Ghost. It is illegal to mix
4771 -- references to Ghost and non-Ghost entities
4774 elsif Present
(Ghost_Id
)
4775 and then not Ghost_Error_Posted
4777 Ghost_Error_Posted
:= True;
4779 Error_Msg_Name_1
:= Pname
;
4781 ("pragma % cannot mention ghost and non-ghost "
4784 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
4785 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
4787 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
4788 Error_Msg_NE
("\& # declared as non-ghost", N
, Arg_Id
);
4791 -- Warn if already flagged as Unused or Unmodified
4793 elsif Has_Pragma_Unmodified
(Arg_Id
) then
4794 if Has_Pragma_Unused
(Arg_Id
) then
4796 ("??pragma Unused already given for &!", Arg_Expr
,
4800 ("??pragma Unmodified already given for &!", Arg_Expr
,
4804 -- Otherwise the pragma referenced an illegal entity
4808 ("pragma% can only be applied to a variable", Arg_Expr
);
4814 end Analyze_Unmodified_Or_Unused
;
4816 -----------------------------------
4817 -- Analyze_Unreference_Or_Unused --
4818 -----------------------------------
4820 procedure Analyze_Unreferenced_Or_Unused
4821 (Is_Unused
: Boolean := False)
4828 Ghost_Error_Posted
: Boolean := False;
4829 -- Flag set when an error concerning the illegal mix of Ghost and
4830 -- non-Ghost names is emitted.
4832 Ghost_Id
: Entity_Id
:= Empty
;
4833 -- The entity of the first Ghost name encountered while processing
4834 -- the arguments of the pragma.
4838 Check_At_Least_N_Arguments
(1);
4840 -- Check case of appearing within context clause
4842 if not Is_Unused
and then Is_In_Context_Clause
then
4844 -- The arguments must all be units mentioned in a with clause in
4845 -- the same context clause. Note that Par.Prag already checked
4846 -- that the arguments are either identifiers or selected
4850 while Present
(Arg
) loop
4851 Citem
:= First
(List_Containing
(N
));
4852 while Citem
/= N
loop
4853 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
4855 if Nkind
(Citem
) = N_With_Clause
4856 and then Same_Name
(Name
(Citem
), Arg_Expr
)
4858 Set_Has_Pragma_Unreferenced
4861 (Library_Unit
(Citem
))));
4862 Set_Elab_Unit_Name
(Arg_Expr
, Name
(Citem
));
4871 ("argument of pragma% is not withed unit", Arg
);
4877 -- Case of not in list of context items
4881 while Present
(Arg
) loop
4882 Check_No_Identifier
(Arg
);
4884 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
4885 -- in fact generate reference, so that the entity will have a
4886 -- reference, which will inhibit any warnings about it not
4887 -- being referenced, and also properly show up in the ali file
4888 -- as a reference. But this reference is recorded before the
4889 -- Has_Pragma_Unreferenced flag is set, so that no warning is
4890 -- generated for this reference.
4892 Check_Arg_Is_Local_Name
(Arg
);
4893 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
4895 if Is_Entity_Name
(Arg_Expr
) then
4896 Arg_Id
:= Entity
(Arg_Expr
);
4898 -- Warn if already flagged as Unused or Unreferenced and
4899 -- skip processing the argument.
4901 if Has_Pragma_Unreferenced
(Arg_Id
) then
4902 if Has_Pragma_Unused
(Arg_Id
) then
4904 ("??pragma Unused already given for &!", Arg_Expr
,
4908 ("??pragma Unreferenced already given for &!",
4912 -- Apply Unreferenced to the entity
4915 -- If the entity is overloaded, the pragma applies to the
4916 -- most recent overloading, as documented. In this case,
4917 -- name resolution does not generate a reference, so it
4918 -- must be done here explicitly.
4920 if Is_Overloaded
(Arg_Expr
) then
4921 Generate_Reference
(Arg_Id
, N
);
4924 Set_Has_Pragma_Unreferenced
(Arg_Id
);
4927 Set_Has_Pragma_Unused
(Arg_Id
);
4930 -- A pragma that applies to a Ghost entity becomes Ghost
4931 -- for the purposes of legality checks and removal of
4932 -- ignored Ghost code.
4934 Mark_Ghost_Pragma
(N
, Arg_Id
);
4936 -- Capture the entity of the first Ghost name being
4937 -- processed for error detection purposes.
4939 if Is_Ghost_Entity
(Arg_Id
) then
4940 if No
(Ghost_Id
) then
4944 -- Otherwise the name is non-Ghost. It is illegal to mix
4945 -- references to Ghost and non-Ghost entities
4948 elsif Present
(Ghost_Id
)
4949 and then not Ghost_Error_Posted
4951 Ghost_Error_Posted
:= True;
4953 Error_Msg_Name_1
:= Pname
;
4955 ("pragma % cannot mention ghost and non-ghost "
4958 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
4960 ("\& # declared as ghost", N
, Ghost_Id
);
4962 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
4964 ("\& # declared as non-ghost", N
, Arg_Id
);
4972 end Analyze_Unreferenced_Or_Unused
;
4974 --------------------------
4975 -- Check_Ada_83_Warning --
4976 --------------------------
4978 procedure Check_Ada_83_Warning
is
4980 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
4981 Error_Msg_N
("(Ada 83) pragma& is non-standard??", N
);
4983 end Check_Ada_83_Warning
;
4985 ---------------------
4986 -- Check_Arg_Count --
4987 ---------------------
4989 procedure Check_Arg_Count
(Required
: Nat
) is
4991 if Arg_Count
/= Required
then
4992 Error_Pragma
("wrong number of arguments for pragma%");
4994 end Check_Arg_Count
;
4996 --------------------------------
4997 -- Check_Arg_Is_External_Name --
4998 --------------------------------
5000 procedure Check_Arg_Is_External_Name
(Arg
: Node_Id
) is
5001 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5004 if Nkind
(Argx
) = N_Identifier
then
5008 Analyze_And_Resolve
(Argx
, Standard_String
);
5010 if Is_OK_Static_Expression
(Argx
) then
5013 elsif Etype
(Argx
) = Any_Type
then
5016 -- An interesting special case, if we have a string literal and
5017 -- we are in Ada 83 mode, then we allow it even though it will
5018 -- not be flagged as static. This allows expected Ada 83 mode
5019 -- use of external names which are string literals, even though
5020 -- technically these are not static in Ada 83.
5022 elsif Ada_Version
= Ada_83
5023 and then Nkind
(Argx
) = N_String_Literal
5027 -- Here we have a real error (non-static expression)
5030 Error_Msg_Name_1
:= Pname
;
5031 Flag_Non_Static_Expr
5032 (Fix_Error
("argument for pragma% must be a identifier or "
5033 & "static string expression!"), Argx
);
5038 end Check_Arg_Is_External_Name
;
5040 -----------------------------
5041 -- Check_Arg_Is_Identifier --
5042 -----------------------------
5044 procedure Check_Arg_Is_Identifier
(Arg
: Node_Id
) is
5045 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5047 if Nkind
(Argx
) /= N_Identifier
then
5048 Error_Pragma_Arg
("argument for pragma% must be identifier", Argx
);
5050 end Check_Arg_Is_Identifier
;
5052 ----------------------------------
5053 -- Check_Arg_Is_Integer_Literal --
5054 ----------------------------------
5056 procedure Check_Arg_Is_Integer_Literal
(Arg
: Node_Id
) is
5057 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5059 if Nkind
(Argx
) /= N_Integer_Literal
then
5061 ("argument for pragma% must be integer literal", Argx
);
5063 end Check_Arg_Is_Integer_Literal
;
5065 -------------------------------------------
5066 -- Check_Arg_Is_Library_Level_Local_Name --
5067 -------------------------------------------
5071 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5072 -- | library_unit_NAME
5074 procedure Check_Arg_Is_Library_Level_Local_Name
(Arg
: Node_Id
) is
5076 Check_Arg_Is_Local_Name
(Arg
);
5078 -- If it came from an aspect, we want to give the error just as if it
5079 -- came from source.
5081 if not Is_Library_Level_Entity
(Entity
(Get_Pragma_Arg
(Arg
)))
5082 and then (Comes_From_Source
(N
)
5083 or else Present
(Corresponding_Aspect
(Parent
(Arg
))))
5086 ("argument for pragma% must be library level entity", Arg
);
5088 end Check_Arg_Is_Library_Level_Local_Name
;
5090 -----------------------------
5091 -- Check_Arg_Is_Local_Name --
5092 -----------------------------
5096 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5097 -- | library_unit_NAME
5099 procedure Check_Arg_Is_Local_Name
(Arg
: Node_Id
) is
5100 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5103 -- If this pragma came from an aspect specification, we don't want to
5104 -- check for this error, because that would cause spurious errors, in
5105 -- case a type is frozen in a scope more nested than the type. The
5106 -- aspect itself of course can't be anywhere but on the declaration
5109 if Nkind
(Arg
) = N_Pragma_Argument_Association
then
5110 if From_Aspect_Specification
(Parent
(Arg
)) then
5114 -- Arg is the Expression of an N_Pragma_Argument_Association
5117 if From_Aspect_Specification
(Parent
(Parent
(Arg
))) then
5124 if Nkind
(Argx
) not in N_Direct_Name
5125 and then (Nkind
(Argx
) /= N_Attribute_Reference
5126 or else Present
(Expressions
(Argx
))
5127 or else Nkind
(Prefix
(Argx
)) /= N_Identifier
)
5128 and then (not Is_Entity_Name
(Argx
)
5129 or else not Is_Compilation_Unit
(Entity
(Argx
)))
5131 Error_Pragma_Arg
("argument for pragma% must be local name", Argx
);
5134 -- No further check required if not an entity name
5136 if not Is_Entity_Name
(Argx
) then
5142 Ent
: constant Entity_Id
:= Entity
(Argx
);
5143 Scop
: constant Entity_Id
:= Scope
(Ent
);
5146 -- Case of a pragma applied to a compilation unit: pragma must
5147 -- occur immediately after the program unit in the compilation.
5149 if Is_Compilation_Unit
(Ent
) then
5151 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Ent
);
5154 -- Case of pragma placed immediately after spec
5156 if Parent
(N
) = Aux_Decls_Node
(Parent
(Decl
)) then
5159 -- Case of pragma placed immediately after body
5161 elsif Nkind
(Decl
) = N_Subprogram_Declaration
5162 and then Present
(Corresponding_Body
(Decl
))
5166 (Parent
(Unit_Declaration_Node
5167 (Corresponding_Body
(Decl
))));
5169 -- All other cases are illegal
5176 -- Special restricted placement rule from 10.2.1(11.8/2)
5178 elsif Is_Generic_Formal
(Ent
)
5179 and then Prag_Id
= Pragma_Preelaborable_Initialization
5181 OK
:= List_Containing
(N
) =
5182 Generic_Formal_Declarations
5183 (Unit_Declaration_Node
(Scop
));
5185 -- If this is an aspect applied to a subprogram body, the
5186 -- pragma is inserted in its declarative part.
5188 elsif From_Aspect_Specification
(N
)
5189 and then Ent
= Current_Scope
5191 Nkind
(Unit_Declaration_Node
(Ent
)) = N_Subprogram_Body
5195 -- If the aspect is a predicate (possibly others ???) and the
5196 -- context is a record type, this is a discriminant expression
5197 -- within a type declaration, that freezes the predicated
5200 elsif From_Aspect_Specification
(N
)
5201 and then Prag_Id
= Pragma_Predicate
5202 and then Ekind
(Current_Scope
) = E_Record_Type
5203 and then Scop
= Scope
(Current_Scope
)
5207 -- Default case, just check that the pragma occurs in the scope
5208 -- of the entity denoted by the name.
5211 OK
:= Current_Scope
= Scop
;
5216 ("pragma% argument must be in same declarative part", Arg
);
5220 end Check_Arg_Is_Local_Name
;
5222 ---------------------------------
5223 -- Check_Arg_Is_Locking_Policy --
5224 ---------------------------------
5226 procedure Check_Arg_Is_Locking_Policy
(Arg
: Node_Id
) is
5227 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5230 Check_Arg_Is_Identifier
(Argx
);
5232 if not Is_Locking_Policy_Name
(Chars
(Argx
)) then
5233 Error_Pragma_Arg
("& is not a valid locking policy name", Argx
);
5235 end Check_Arg_Is_Locking_Policy
;
5237 -----------------------------------------------
5238 -- Check_Arg_Is_Partition_Elaboration_Policy --
5239 -----------------------------------------------
5241 procedure Check_Arg_Is_Partition_Elaboration_Policy
(Arg
: Node_Id
) is
5242 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5245 Check_Arg_Is_Identifier
(Argx
);
5247 if not Is_Partition_Elaboration_Policy_Name
(Chars
(Argx
)) then
5249 ("& is not a valid partition elaboration policy name", Argx
);
5251 end Check_Arg_Is_Partition_Elaboration_Policy
;
5253 -------------------------
5254 -- Check_Arg_Is_One_Of --
5255 -------------------------
5257 procedure Check_Arg_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
) is
5258 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5261 Check_Arg_Is_Identifier
(Argx
);
5263 if not Nam_In
(Chars
(Argx
), N1
, N2
) then
5264 Error_Msg_Name_2
:= N1
;
5265 Error_Msg_Name_3
:= N2
;
5266 Error_Pragma_Arg
("argument for pragma% must be% or%", Argx
);
5268 end Check_Arg_Is_One_Of
;
5270 procedure Check_Arg_Is_One_Of
5272 N1
, N2
, N3
: Name_Id
)
5274 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5277 Check_Arg_Is_Identifier
(Argx
);
5279 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
) then
5280 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
5282 end Check_Arg_Is_One_Of
;
5284 procedure Check_Arg_Is_One_Of
5286 N1
, N2
, N3
, N4
: Name_Id
)
5288 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5291 Check_Arg_Is_Identifier
(Argx
);
5293 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
, N4
) then
5294 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
5296 end Check_Arg_Is_One_Of
;
5298 procedure Check_Arg_Is_One_Of
5300 N1
, N2
, N3
, N4
, N5
: Name_Id
)
5302 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5305 Check_Arg_Is_Identifier
(Argx
);
5307 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
, N4
, N5
) then
5308 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
5310 end Check_Arg_Is_One_Of
;
5312 ---------------------------------
5313 -- Check_Arg_Is_Queuing_Policy --
5314 ---------------------------------
5316 procedure Check_Arg_Is_Queuing_Policy
(Arg
: Node_Id
) is
5317 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5320 Check_Arg_Is_Identifier
(Argx
);
5322 if not Is_Queuing_Policy_Name
(Chars
(Argx
)) then
5323 Error_Pragma_Arg
("& is not a valid queuing policy name", Argx
);
5325 end Check_Arg_Is_Queuing_Policy
;
5327 ---------------------------------------
5328 -- Check_Arg_Is_OK_Static_Expression --
5329 ---------------------------------------
5331 procedure Check_Arg_Is_OK_Static_Expression
5333 Typ
: Entity_Id
:= Empty
)
5336 Check_Expr_Is_OK_Static_Expression
(Get_Pragma_Arg
(Arg
), Typ
);
5337 end Check_Arg_Is_OK_Static_Expression
;
5339 ------------------------------------------
5340 -- Check_Arg_Is_Task_Dispatching_Policy --
5341 ------------------------------------------
5343 procedure Check_Arg_Is_Task_Dispatching_Policy
(Arg
: Node_Id
) is
5344 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5347 Check_Arg_Is_Identifier
(Argx
);
5349 if not Is_Task_Dispatching_Policy_Name
(Chars
(Argx
)) then
5351 ("& is not an allowed task dispatching policy name", Argx
);
5353 end Check_Arg_Is_Task_Dispatching_Policy
;
5355 ---------------------
5356 -- Check_Arg_Order --
5357 ---------------------
5359 procedure Check_Arg_Order
(Names
: Name_List
) is
5362 Highest_So_Far
: Natural := 0;
5363 -- Highest index in Names seen do far
5367 for J
in 1 .. Arg_Count
loop
5368 if Chars
(Arg
) /= No_Name
then
5369 for K
in Names
'Range loop
5370 if Chars
(Arg
) = Names
(K
) then
5371 if K
< Highest_So_Far
then
5372 Error_Msg_Name_1
:= Pname
;
5374 ("parameters out of order for pragma%", Arg
);
5375 Error_Msg_Name_1
:= Names
(K
);
5376 Error_Msg_Name_2
:= Names
(Highest_So_Far
);
5377 Error_Msg_N
("\% must appear before %", Arg
);
5381 Highest_So_Far
:= K
;
5389 end Check_Arg_Order
;
5391 --------------------------------
5392 -- Check_At_Least_N_Arguments --
5393 --------------------------------
5395 procedure Check_At_Least_N_Arguments
(N
: Nat
) is
5397 if Arg_Count
< N
then
5398 Error_Pragma
("too few arguments for pragma%");
5400 end Check_At_Least_N_Arguments
;
5402 -------------------------------
5403 -- Check_At_Most_N_Arguments --
5404 -------------------------------
5406 procedure Check_At_Most_N_Arguments
(N
: Nat
) is
5409 if Arg_Count
> N
then
5411 for J
in 1 .. N
loop
5413 Error_Pragma_Arg
("too many arguments for pragma%", Arg
);
5416 end Check_At_Most_N_Arguments
;
5418 ---------------------
5419 -- Check_Component --
5420 ---------------------
5422 procedure Check_Component
5425 In_Variant_Part
: Boolean := False)
5427 Comp_Id
: constant Entity_Id
:= Defining_Identifier
(Comp
);
5428 Sindic
: constant Node_Id
:=
5429 Subtype_Indication
(Component_Definition
(Comp
));
5430 Typ
: constant Entity_Id
:= Etype
(Comp_Id
);
5433 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
5434 -- object constraint, then the component type shall be an Unchecked_
5437 if Nkind
(Sindic
) = N_Subtype_Indication
5438 and then Has_Per_Object_Constraint
(Comp_Id
)
5439 and then not Is_Unchecked_Union
(Etype
(Subtype_Mark
(Sindic
)))
5442 ("component subtype subject to per-object constraint "
5443 & "must be an Unchecked_Union", Comp
);
5445 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
5446 -- the body of a generic unit, or within the body of any of its
5447 -- descendant library units, no part of the type of a component
5448 -- declared in a variant_part of the unchecked union type shall be of
5449 -- a formal private type or formal private extension declared within
5450 -- the formal part of the generic unit.
5452 elsif Ada_Version
>= Ada_2012
5453 and then In_Generic_Body
(UU_Typ
)
5454 and then In_Variant_Part
5455 and then Is_Private_Type
(Typ
)
5456 and then Is_Generic_Type
(Typ
)
5459 ("component of unchecked union cannot be of generic type", Comp
);
5461 elsif Needs_Finalization
(Typ
) then
5463 ("component of unchecked union cannot be controlled", Comp
);
5465 elsif Has_Task
(Typ
) then
5467 ("component of unchecked union cannot have tasks", Comp
);
5469 end Check_Component
;
5471 ----------------------------
5472 -- Check_Duplicate_Pragma --
5473 ----------------------------
5475 procedure Check_Duplicate_Pragma
(E
: Entity_Id
) is
5476 Id
: Entity_Id
:= E
;
5480 -- Nothing to do if this pragma comes from an aspect specification,
5481 -- since we could not be duplicating a pragma, and we dealt with the
5482 -- case of duplicated aspects in Analyze_Aspect_Specifications.
5484 if From_Aspect_Specification
(N
) then
5488 -- Otherwise current pragma may duplicate previous pragma or a
5489 -- previously given aspect specification or attribute definition
5490 -- clause for the same pragma.
5492 P
:= Get_Rep_Item
(E
, Pragma_Name
(N
), Check_Parents
=> False);
5496 -- If the entity is a type, then we have to make sure that the
5497 -- ostensible duplicate is not for a parent type from which this
5501 if Nkind
(P
) = N_Pragma
then
5503 Args
: constant List_Id
:=
5504 Pragma_Argument_Associations
(P
);
5507 and then Is_Entity_Name
(Expression
(First
(Args
)))
5508 and then Is_Type
(Entity
(Expression
(First
(Args
))))
5509 and then Entity
(Expression
(First
(Args
))) /= E
5515 elsif Nkind
(P
) = N_Aspect_Specification
5516 and then Is_Type
(Entity
(P
))
5517 and then Entity
(P
) /= E
5523 -- Here we have a definite duplicate
5525 Error_Msg_Name_1
:= Pragma_Name
(N
);
5526 Error_Msg_Sloc
:= Sloc
(P
);
5528 -- For a single protected or a single task object, the error is
5529 -- issued on the original entity.
5531 if Ekind_In
(Id
, E_Task_Type
, E_Protected_Type
) then
5532 Id
:= Defining_Identifier
(Original_Node
(Parent
(Id
)));
5535 if Nkind
(P
) = N_Aspect_Specification
5536 or else From_Aspect_Specification
(P
)
5538 Error_Msg_NE
("aspect% for & previously given#", N
, Id
);
5540 Error_Msg_NE
("pragma% for & duplicates pragma#", N
, Id
);
5545 end Check_Duplicate_Pragma
;
5547 ----------------------------------
5548 -- Check_Duplicated_Export_Name --
5549 ----------------------------------
5551 procedure Check_Duplicated_Export_Name
(Nam
: Node_Id
) is
5552 String_Val
: constant String_Id
:= Strval
(Nam
);
5555 -- We are only interested in the export case, and in the case of
5556 -- generics, it is the instance, not the template, that is the
5557 -- problem (the template will generate a warning in any case).
5559 if not Inside_A_Generic
5560 and then (Prag_Id
= Pragma_Export
5562 Prag_Id
= Pragma_Export_Procedure
5564 Prag_Id
= Pragma_Export_Valued_Procedure
5566 Prag_Id
= Pragma_Export_Function
)
5568 for J
in Externals
.First
.. Externals
.Last
loop
5569 if String_Equal
(String_Val
, Strval
(Externals
.Table
(J
))) then
5570 Error_Msg_Sloc
:= Sloc
(Externals
.Table
(J
));
5571 Error_Msg_N
("external name duplicates name given#", Nam
);
5576 Externals
.Append
(Nam
);
5578 end Check_Duplicated_Export_Name
;
5580 ----------------------------------------
5581 -- Check_Expr_Is_OK_Static_Expression --
5582 ----------------------------------------
5584 procedure Check_Expr_Is_OK_Static_Expression
5586 Typ
: Entity_Id
:= Empty
)
5589 if Present
(Typ
) then
5590 Analyze_And_Resolve
(Expr
, Typ
);
5592 Analyze_And_Resolve
(Expr
);
5595 -- An expression cannot be considered static if its resolution failed
5596 -- or if it's erroneous. Stop the analysis of the related pragma.
5598 if Etype
(Expr
) = Any_Type
or else Error_Posted
(Expr
) then
5601 elsif Is_OK_Static_Expression
(Expr
) then
5604 -- An interesting special case, if we have a string literal and we
5605 -- are in Ada 83 mode, then we allow it even though it will not be
5606 -- flagged as static. This allows the use of Ada 95 pragmas like
5607 -- Import in Ada 83 mode. They will of course be flagged with
5608 -- warnings as usual, but will not cause errors.
5610 elsif Ada_Version
= Ada_83
5611 and then Nkind
(Expr
) = N_String_Literal
5615 -- Finally, we have a real error
5618 Error_Msg_Name_1
:= Pname
;
5619 Flag_Non_Static_Expr
5620 (Fix_Error
("argument for pragma% must be a static expression!"),
5624 end Check_Expr_Is_OK_Static_Expression
;
5626 -------------------------
5627 -- Check_First_Subtype --
5628 -------------------------
5630 procedure Check_First_Subtype
(Arg
: Node_Id
) is
5631 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5632 Ent
: constant Entity_Id
:= Entity
(Argx
);
5635 if Is_First_Subtype
(Ent
) then
5638 elsif Is_Type
(Ent
) then
5640 ("pragma% cannot apply to subtype", Argx
);
5642 elsif Is_Object
(Ent
) then
5644 ("pragma% cannot apply to object, requires a type", Argx
);
5648 ("pragma% cannot apply to&, requires a type", Argx
);
5650 end Check_First_Subtype
;
5652 ----------------------
5653 -- Check_Identifier --
5654 ----------------------
5656 procedure Check_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
5659 and then Nkind
(Arg
) = N_Pragma_Argument_Association
5661 if Chars
(Arg
) = No_Name
or else Chars
(Arg
) /= Id
then
5662 Error_Msg_Name_1
:= Pname
;
5663 Error_Msg_Name_2
:= Id
;
5664 Error_Msg_N
("pragma% argument expects identifier%", Arg
);
5668 end Check_Identifier
;
5670 --------------------------------
5671 -- Check_Identifier_Is_One_Of --
5672 --------------------------------
5674 procedure Check_Identifier_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
) is
5677 and then Nkind
(Arg
) = N_Pragma_Argument_Association
5679 if Chars
(Arg
) = No_Name
then
5680 Error_Msg_Name_1
:= Pname
;
5681 Error_Msg_N
("pragma% argument expects an identifier", Arg
);
5684 elsif Chars
(Arg
) /= N1
5685 and then Chars
(Arg
) /= N2
5687 Error_Msg_Name_1
:= Pname
;
5688 Error_Msg_N
("invalid identifier for pragma% argument", Arg
);
5692 end Check_Identifier_Is_One_Of
;
5694 ---------------------------
5695 -- Check_In_Main_Program --
5696 ---------------------------
5698 procedure Check_In_Main_Program
is
5699 P
: constant Node_Id
:= Parent
(N
);
5702 -- Must be in subprogram body
5704 if Nkind
(P
) /= N_Subprogram_Body
then
5705 Error_Pragma
("% pragma allowed only in subprogram");
5707 -- Otherwise warn if obviously not main program
5709 elsif Present
(Parameter_Specifications
(Specification
(P
)))
5710 or else not Is_Compilation_Unit
(Defining_Entity
(P
))
5712 Error_Msg_Name_1
:= Pname
;
5714 ("??pragma% is only effective in main program", N
);
5716 end Check_In_Main_Program
;
5718 ---------------------------------------
5719 -- Check_Interrupt_Or_Attach_Handler --
5720 ---------------------------------------
5722 procedure Check_Interrupt_Or_Attach_Handler
is
5723 Arg1_X
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
5724 Handler_Proc
, Proc_Scope
: Entity_Id
;
5729 if Prag_Id
= Pragma_Interrupt_Handler
then
5730 Check_Restriction
(No_Dynamic_Attachment
, N
);
5733 Handler_Proc
:= Find_Unique_Parameterless_Procedure
(Arg1_X
, Arg1
);
5734 Proc_Scope
:= Scope
(Handler_Proc
);
5736 if Ekind
(Proc_Scope
) /= E_Protected_Type
then
5738 ("argument of pragma% must be protected procedure", Arg1
);
5741 -- For pragma case (as opposed to access case), check placement.
5742 -- We don't need to do that for aspects, because we have the
5743 -- check that they aspect applies an appropriate procedure.
5745 if not From_Aspect_Specification
(N
)
5746 and then Parent
(N
) /= Protected_Definition
(Parent
(Proc_Scope
))
5748 Error_Pragma
("pragma% must be in protected definition");
5751 if not Is_Library_Level_Entity
(Proc_Scope
) then
5753 ("argument for pragma% must be library level entity", Arg1
);
5756 -- AI05-0033: A pragma cannot appear within a generic body, because
5757 -- instance can be in a nested scope. The check that protected type
5758 -- is itself a library-level declaration is done elsewhere.
5760 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
5761 -- handle code prior to AI-0033. Analysis tools typically are not
5762 -- interested in this pragma in any case, so no need to worry too
5763 -- much about its placement.
5765 if Inside_A_Generic
then
5766 if Ekind
(Scope
(Current_Scope
)) = E_Generic_Package
5767 and then In_Package_Body
(Scope
(Current_Scope
))
5768 and then not Relaxed_RM_Semantics
5770 Error_Pragma
("pragma% cannot be used inside a generic");
5773 end Check_Interrupt_Or_Attach_Handler
;
5775 ---------------------------------
5776 -- Check_Loop_Pragma_Placement --
5777 ---------------------------------
5779 procedure Check_Loop_Pragma_Placement
is
5780 procedure Check_Loop_Pragma_Grouping
(Loop_Stmt
: Node_Id
);
5781 -- Verify whether the current pragma is properly grouped with other
5782 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
5783 -- related loop where the pragma appears.
5785 function Is_Loop_Pragma
(Stmt
: Node_Id
) return Boolean;
5786 -- Determine whether an arbitrary statement Stmt denotes pragma
5787 -- Loop_Invariant or Loop_Variant.
5789 procedure Placement_Error
(Constr
: Node_Id
);
5790 pragma No_Return
(Placement_Error
);
5791 -- Node Constr denotes the last loop restricted construct before we
5792 -- encountered an illegal relation between enclosing constructs. Emit
5793 -- an error depending on what Constr was.
5795 --------------------------------
5796 -- Check_Loop_Pragma_Grouping --
5797 --------------------------------
5799 procedure Check_Loop_Pragma_Grouping
(Loop_Stmt
: Node_Id
) is
5800 Stop_Search
: exception;
5801 -- This exception is used to terminate the recursive descent of
5802 -- routine Check_Grouping.
5804 procedure Check_Grouping
(L
: List_Id
);
5805 -- Find the first group of pragmas in list L and if successful,
5806 -- ensure that the current pragma is part of that group. The
5807 -- routine raises Stop_Search once such a check is performed to
5808 -- halt the recursive descent.
5810 procedure Grouping_Error
(Prag
: Node_Id
);
5811 pragma No_Return
(Grouping_Error
);
5812 -- Emit an error concerning the current pragma indicating that it
5813 -- should be placed after pragma Prag.
5815 --------------------
5816 -- Check_Grouping --
5817 --------------------
5819 procedure Check_Grouping
(L
: List_Id
) is
5822 Prag
: Node_Id
:= Empty
; -- init to avoid warning
5825 -- Inspect the list of declarations or statements looking for
5826 -- the first grouping of pragmas:
5829 -- pragma Loop_Invariant ...;
5830 -- pragma Loop_Variant ...;
5832 -- pragma Loop_Variant ...; -- current pragma
5834 -- If the current pragma is not in the grouping, then it must
5835 -- either appear in a different declarative or statement list
5836 -- or the construct at (1) is separating the pragma from the
5840 while Present
(Stmt
) loop
5842 -- Pragmas Loop_Invariant and Loop_Variant may only appear
5843 -- inside a loop or a block housed inside a loop. Inspect
5844 -- the declarations and statements of the block as they may
5845 -- contain the first grouping.
5847 if Nkind
(Stmt
) = N_Block_Statement
then
5848 HSS
:= Handled_Statement_Sequence
(Stmt
);
5850 Check_Grouping
(Declarations
(Stmt
));
5852 if Present
(HSS
) then
5853 Check_Grouping
(Statements
(HSS
));
5856 -- First pragma of the first topmost grouping has been found
5858 elsif Is_Loop_Pragma
(Stmt
) then
5860 -- The group and the current pragma are not in the same
5861 -- declarative or statement list.
5863 if List_Containing
(Stmt
) /= List_Containing
(N
) then
5864 Grouping_Error
(Stmt
);
5866 -- Try to reach the current pragma from the first pragma
5867 -- of the grouping while skipping other members:
5869 -- pragma Loop_Invariant ...; -- first pragma
5870 -- pragma Loop_Variant ...; -- member
5872 -- pragma Loop_Variant ...; -- current pragma
5875 while Present
(Stmt
) loop
5876 -- The current pragma is either the first pragma
5877 -- of the group or is a member of the group.
5878 -- Stop the search as the placement is legal.
5883 -- Skip group members, but keep track of the
5884 -- last pragma in the group.
5886 elsif Is_Loop_Pragma
(Stmt
) then
5889 -- Skip declarations and statements generated by
5890 -- the compiler during expansion.
5892 elsif not Comes_From_Source
(Stmt
) then
5895 -- A non-pragma is separating the group from the
5896 -- current pragma, the placement is illegal.
5899 Grouping_Error
(Prag
);
5905 -- If the traversal did not reach the current pragma,
5906 -- then the list must be malformed.
5908 raise Program_Error
;
5916 --------------------
5917 -- Grouping_Error --
5918 --------------------
5920 procedure Grouping_Error
(Prag
: Node_Id
) is
5922 Error_Msg_Sloc
:= Sloc
(Prag
);
5923 Error_Pragma
("pragma% must appear next to pragma#");
5926 -- Start of processing for Check_Loop_Pragma_Grouping
5929 -- Inspect the statements of the loop or nested blocks housed
5930 -- within to determine whether the current pragma is part of the
5931 -- first topmost grouping of Loop_Invariant and Loop_Variant.
5933 Check_Grouping
(Statements
(Loop_Stmt
));
5936 when Stop_Search
=> null;
5937 end Check_Loop_Pragma_Grouping
;
5939 --------------------
5940 -- Is_Loop_Pragma --
5941 --------------------
5943 function Is_Loop_Pragma
(Stmt
: Node_Id
) return Boolean is
5945 -- Inspect the original node as Loop_Invariant and Loop_Variant
5946 -- pragmas are rewritten to null when assertions are disabled.
5948 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
then
5950 Nam_In
(Pragma_Name_Unmapped
(Original_Node
(Stmt
)),
5951 Name_Loop_Invariant
,
5958 ---------------------
5959 -- Placement_Error --
5960 ---------------------
5962 procedure Placement_Error
(Constr
: Node_Id
) is
5963 LA
: constant String := " with Loop_Entry";
5966 if Prag_Id
= Pragma_Assert
then
5967 Error_Msg_String
(1 .. LA
'Length) := LA
;
5968 Error_Msg_Strlen
:= LA
'Length;
5970 Error_Msg_Strlen
:= 0;
5973 if Nkind
(Constr
) = N_Pragma
then
5975 ("pragma %~ must appear immediately within the statements "
5979 ("block containing pragma %~ must appear immediately within "
5980 & "the statements of a loop", Constr
);
5982 end Placement_Error
;
5984 -- Local declarations
5989 -- Start of processing for Check_Loop_Pragma_Placement
5992 -- Check that pragma appears immediately within a loop statement,
5993 -- ignoring intervening block statements.
5997 while Present
(Stmt
) loop
5999 -- The pragma or previous block must appear immediately within the
6000 -- current block's declarative or statement part.
6002 if Nkind
(Stmt
) = N_Block_Statement
then
6003 if (No
(Declarations
(Stmt
))
6004 or else List_Containing
(Prev
) /= Declarations
(Stmt
))
6006 List_Containing
(Prev
) /=
6007 Statements
(Handled_Statement_Sequence
(Stmt
))
6009 Placement_Error
(Prev
);
6012 -- Keep inspecting the parents because we are now within a
6013 -- chain of nested blocks.
6017 Stmt
:= Parent
(Stmt
);
6020 -- The pragma or previous block must appear immediately within the
6021 -- statements of the loop.
6023 elsif Nkind
(Stmt
) = N_Loop_Statement
then
6024 if List_Containing
(Prev
) /= Statements
(Stmt
) then
6025 Placement_Error
(Prev
);
6028 -- Stop the traversal because we reached the innermost loop
6029 -- regardless of whether we encountered an error or not.
6033 -- Ignore a handled statement sequence. Note that this node may
6034 -- be related to a subprogram body in which case we will emit an
6035 -- error on the next iteration of the search.
6037 elsif Nkind
(Stmt
) = N_Handled_Sequence_Of_Statements
then
6038 Stmt
:= Parent
(Stmt
);
6040 -- Any other statement breaks the chain from the pragma to the
6044 Placement_Error
(Prev
);
6049 -- Check that the current pragma Loop_Invariant or Loop_Variant is
6050 -- grouped together with other such pragmas.
6052 if Is_Loop_Pragma
(N
) then
6054 -- The previous check should have located the related loop
6056 pragma Assert
(Nkind
(Stmt
) = N_Loop_Statement
);
6057 Check_Loop_Pragma_Grouping
(Stmt
);
6059 end Check_Loop_Pragma_Placement
;
6061 -------------------------------------------
6062 -- Check_Is_In_Decl_Part_Or_Package_Spec --
6063 -------------------------------------------
6065 procedure Check_Is_In_Decl_Part_Or_Package_Spec
is
6074 elsif Nkind
(P
) = N_Handled_Sequence_Of_Statements
then
6077 elsif Nkind_In
(P
, N_Package_Specification
,
6082 -- Note: the following tests seem a little peculiar, because
6083 -- they test for bodies, but if we were in the statement part
6084 -- of the body, we would already have hit the handled statement
6085 -- sequence, so the only way we get here is by being in the
6086 -- declarative part of the body.
6088 elsif Nkind_In
(P
, N_Subprogram_Body
,
6099 Error_Pragma
("pragma% is not in declarative part or package spec");
6100 end Check_Is_In_Decl_Part_Or_Package_Spec
;
6102 -------------------------
6103 -- Check_No_Identifier --
6104 -------------------------
6106 procedure Check_No_Identifier
(Arg
: Node_Id
) is
6108 if Nkind
(Arg
) = N_Pragma_Argument_Association
6109 and then Chars
(Arg
) /= No_Name
6111 Error_Pragma_Arg_Ident
6112 ("pragma% does not permit identifier& here", Arg
);
6114 end Check_No_Identifier
;
6116 --------------------------
6117 -- Check_No_Identifiers --
6118 --------------------------
6120 procedure Check_No_Identifiers
is
6124 for J
in 1 .. Arg_Count
loop
6125 Check_No_Identifier
(Arg_Node
);
6128 end Check_No_Identifiers
;
6130 ------------------------
6131 -- Check_No_Link_Name --
6132 ------------------------
6134 procedure Check_No_Link_Name
is
6136 if Present
(Arg3
) and then Chars
(Arg3
) = Name_Link_Name
then
6140 if Present
(Arg4
) then
6142 ("Link_Name argument not allowed for Import Intrinsic", Arg4
);
6144 end Check_No_Link_Name
;
6146 -------------------------------
6147 -- Check_Optional_Identifier --
6148 -------------------------------
6150 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
6153 and then Nkind
(Arg
) = N_Pragma_Argument_Association
6154 and then Chars
(Arg
) /= No_Name
6156 if Chars
(Arg
) /= Id
then
6157 Error_Msg_Name_1
:= Pname
;
6158 Error_Msg_Name_2
:= Id
;
6159 Error_Msg_N
("pragma% argument expects identifier%", Arg
);
6163 end Check_Optional_Identifier
;
6165 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: String) is
6167 Check_Optional_Identifier
(Arg
, Name_Find
(Id
));
6168 end Check_Optional_Identifier
;
6170 -------------------------------------
6171 -- Check_Static_Boolean_Expression --
6172 -------------------------------------
6174 procedure Check_Static_Boolean_Expression
(Expr
: Node_Id
) is
6176 if Present
(Expr
) then
6177 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
6179 if not Is_OK_Static_Expression
(Expr
) then
6181 ("expression of pragma % must be static", Expr
);
6184 end Check_Static_Boolean_Expression
;
6186 -----------------------------
6187 -- Check_Static_Constraint --
6188 -----------------------------
6190 -- Note: for convenience in writing this procedure, in addition to
6191 -- the officially (i.e. by spec) allowed argument which is always a
6192 -- constraint, it also allows ranges and discriminant associations.
6193 -- Above is not clear ???
6195 procedure Check_Static_Constraint
(Constr
: Node_Id
) is
6197 procedure Require_Static
(E
: Node_Id
);
6198 -- Require given expression to be static expression
6200 --------------------
6201 -- Require_Static --
6202 --------------------
6204 procedure Require_Static
(E
: Node_Id
) is
6206 if not Is_OK_Static_Expression
(E
) then
6207 Flag_Non_Static_Expr
6208 ("non-static constraint not allowed in Unchecked_Union!", E
);
6213 -- Start of processing for Check_Static_Constraint
6216 case Nkind
(Constr
) is
6217 when N_Discriminant_Association
=>
6218 Require_Static
(Expression
(Constr
));
6221 Require_Static
(Low_Bound
(Constr
));
6222 Require_Static
(High_Bound
(Constr
));
6224 when N_Attribute_Reference
=>
6225 Require_Static
(Type_Low_Bound
(Etype
(Prefix
(Constr
))));
6226 Require_Static
(Type_High_Bound
(Etype
(Prefix
(Constr
))));
6228 when N_Range_Constraint
=>
6229 Check_Static_Constraint
(Range_Expression
(Constr
));
6231 when N_Index_Or_Discriminant_Constraint
=>
6235 IDC
:= First
(Constraints
(Constr
));
6236 while Present
(IDC
) loop
6237 Check_Static_Constraint
(IDC
);
6245 end Check_Static_Constraint
;
6247 --------------------------------------
6248 -- Check_Valid_Configuration_Pragma --
6249 --------------------------------------
6251 -- A configuration pragma must appear in the context clause of a
6252 -- compilation unit, and only other pragmas may precede it. Note that
6253 -- the test also allows use in a configuration pragma file.
6255 procedure Check_Valid_Configuration_Pragma
is
6257 if not Is_Configuration_Pragma
then
6258 Error_Pragma
("incorrect placement for configuration pragma%");
6260 end Check_Valid_Configuration_Pragma
;
6262 -------------------------------------
6263 -- Check_Valid_Library_Unit_Pragma --
6264 -------------------------------------
6266 procedure Check_Valid_Library_Unit_Pragma
is
6268 Parent_Node
: Node_Id
;
6269 Unit_Name
: Entity_Id
;
6270 Unit_Kind
: Node_Kind
;
6271 Unit_Node
: Node_Id
;
6272 Sindex
: Source_File_Index
;
6275 if not Is_List_Member
(N
) then
6279 Plist
:= List_Containing
(N
);
6280 Parent_Node
:= Parent
(Plist
);
6282 if Parent_Node
= Empty
then
6285 -- Case of pragma appearing after a compilation unit. In this case
6286 -- it must have an argument with the corresponding name and must
6287 -- be part of the following pragmas of its parent.
6289 elsif Nkind
(Parent_Node
) = N_Compilation_Unit_Aux
then
6290 if Plist
/= Pragmas_After
(Parent_Node
) then
6293 elsif Arg_Count
= 0 then
6295 ("argument required if outside compilation unit");
6298 Check_No_Identifiers
;
6299 Check_Arg_Count
(1);
6300 Unit_Node
:= Unit
(Parent
(Parent_Node
));
6301 Unit_Kind
:= Nkind
(Unit_Node
);
6303 Analyze
(Get_Pragma_Arg
(Arg1
));
6305 if Unit_Kind
= N_Generic_Subprogram_Declaration
6306 or else Unit_Kind
= N_Subprogram_Declaration
6308 Unit_Name
:= Defining_Entity
(Unit_Node
);
6310 elsif Unit_Kind
in N_Generic_Instantiation
then
6311 Unit_Name
:= Defining_Entity
(Unit_Node
);
6314 Unit_Name
:= Cunit_Entity
(Current_Sem_Unit
);
6317 if Chars
(Unit_Name
) /=
6318 Chars
(Entity
(Get_Pragma_Arg
(Arg1
)))
6321 ("pragma% argument is not current unit name", Arg1
);
6324 if Ekind
(Unit_Name
) = E_Package
6325 and then Present
(Renamed_Entity
(Unit_Name
))
6327 Error_Pragma
("pragma% not allowed for renamed package");
6331 -- Pragma appears other than after a compilation unit
6334 -- Here we check for the generic instantiation case and also
6335 -- for the case of processing a generic formal package. We
6336 -- detect these cases by noting that the Sloc on the node
6337 -- does not belong to the current compilation unit.
6339 Sindex
:= Source_Index
(Current_Sem_Unit
);
6341 if Loc
not in Source_First
(Sindex
) .. Source_Last
(Sindex
) then
6342 Rewrite
(N
, Make_Null_Statement
(Loc
));
6345 -- If before first declaration, the pragma applies to the
6346 -- enclosing unit, and the name if present must be this name.
6348 elsif Is_Before_First_Decl
(N
, Plist
) then
6349 Unit_Node
:= Unit_Declaration_Node
(Current_Scope
);
6350 Unit_Kind
:= Nkind
(Unit_Node
);
6352 if Nkind
(Parent
(Unit_Node
)) /= N_Compilation_Unit
then
6355 elsif Unit_Kind
= N_Subprogram_Body
6356 and then not Acts_As_Spec
(Unit_Node
)
6360 elsif Nkind
(Parent_Node
) = N_Package_Body
then
6363 elsif Nkind
(Parent_Node
) = N_Package_Specification
6364 and then Plist
= Private_Declarations
(Parent_Node
)
6368 elsif (Nkind
(Parent_Node
) = N_Generic_Package_Declaration
6369 or else Nkind
(Parent_Node
) =
6370 N_Generic_Subprogram_Declaration
)
6371 and then Plist
= Generic_Formal_Declarations
(Parent_Node
)
6375 elsif Arg_Count
> 0 then
6376 Analyze
(Get_Pragma_Arg
(Arg1
));
6378 if Entity
(Get_Pragma_Arg
(Arg1
)) /= Current_Scope
then
6380 ("name in pragma% must be enclosing unit", Arg1
);
6383 -- It is legal to have no argument in this context
6389 -- Error if not before first declaration. This is because a
6390 -- library unit pragma argument must be the name of a library
6391 -- unit (RM 10.1.5(7)), but the only names permitted in this
6392 -- context are (RM 10.1.5(6)) names of subprogram declarations,
6393 -- generic subprogram declarations or generic instantiations.
6397 ("pragma% misplaced, must be before first declaration");
6401 end Check_Valid_Library_Unit_Pragma
;
6407 procedure Check_Variant
(Variant
: Node_Id
; UU_Typ
: Entity_Id
) is
6408 Clist
: constant Node_Id
:= Component_List
(Variant
);
6412 Comp
:= First_Non_Pragma
(Component_Items
(Clist
));
6413 while Present
(Comp
) loop
6414 Check_Component
(Comp
, UU_Typ
, In_Variant_Part
=> True);
6415 Next_Non_Pragma
(Comp
);
6419 ---------------------------
6420 -- Ensure_Aggregate_Form --
6421 ---------------------------
6423 procedure Ensure_Aggregate_Form
(Arg
: Node_Id
) is
6424 CFSD
: constant Boolean := Get_Comes_From_Source_Default
;
6425 Expr
: constant Node_Id
:= Expression
(Arg
);
6426 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6427 Comps
: List_Id
:= No_List
;
6428 Exprs
: List_Id
:= No_List
;
6429 Nam
: Name_Id
:= No_Name
;
6430 Nam_Loc
: Source_Ptr
;
6433 -- The pragma argument is in positional form:
6435 -- pragma Depends (Nam => ...)
6439 -- Note that the Sloc of the Chars field is the Sloc of the pragma
6440 -- argument association.
6442 if Nkind
(Arg
) = N_Pragma_Argument_Association
then
6444 Nam_Loc
:= Sloc
(Arg
);
6446 -- Remove the pragma argument name as this will be captured in the
6449 Set_Chars
(Arg
, No_Name
);
6452 -- The argument is already in aggregate form, but the presence of a
6453 -- name causes this to be interpreted as named association which in
6454 -- turn must be converted into an aggregate.
6456 -- pragma Global (In_Out => (A, B, C))
6460 -- pragma Global ((In_Out => (A, B, C)))
6462 -- aggregate aggregate
6464 if Nkind
(Expr
) = N_Aggregate
then
6465 if Nam
= No_Name
then
6469 -- Do not transform a null argument into an aggregate as N_Null has
6470 -- special meaning in formal verification pragmas.
6472 elsif Nkind
(Expr
) = N_Null
then
6476 -- Everything comes from source if the original comes from source
6478 Set_Comes_From_Source_Default
(Comes_From_Source
(Arg
));
6480 -- Positional argument is transformed into an aggregate with an
6481 -- Expressions list.
6483 if Nam
= No_Name
then
6484 Exprs
:= New_List
(Relocate_Node
(Expr
));
6486 -- An associative argument is transformed into an aggregate with
6487 -- Component_Associations.
6491 Make_Component_Association
(Loc
,
6492 Choices
=> New_List
(Make_Identifier
(Nam_Loc
, Nam
)),
6493 Expression
=> Relocate_Node
(Expr
)));
6496 Set_Expression
(Arg
,
6497 Make_Aggregate
(Loc
,
6498 Component_Associations
=> Comps
,
6499 Expressions
=> Exprs
));
6501 -- Restore Comes_From_Source default
6503 Set_Comes_From_Source_Default
(CFSD
);
6504 end Ensure_Aggregate_Form
;
6510 procedure Error_Pragma
(Msg
: String) is
6512 Error_Msg_Name_1
:= Pname
;
6513 Error_Msg_N
(Fix_Error
(Msg
), N
);
6517 ----------------------
6518 -- Error_Pragma_Arg --
6519 ----------------------
6521 procedure Error_Pragma_Arg
(Msg
: String; Arg
: Node_Id
) is
6523 Error_Msg_Name_1
:= Pname
;
6524 Error_Msg_N
(Fix_Error
(Msg
), Get_Pragma_Arg
(Arg
));
6526 end Error_Pragma_Arg
;
6528 procedure Error_Pragma_Arg
(Msg1
, Msg2
: String; Arg
: Node_Id
) is
6530 Error_Msg_Name_1
:= Pname
;
6531 Error_Msg_N
(Fix_Error
(Msg1
), Get_Pragma_Arg
(Arg
));
6532 Error_Pragma_Arg
(Msg2
, Arg
);
6533 end Error_Pragma_Arg
;
6535 ----------------------------
6536 -- Error_Pragma_Arg_Ident --
6537 ----------------------------
6539 procedure Error_Pragma_Arg_Ident
(Msg
: String; Arg
: Node_Id
) is
6541 Error_Msg_Name_1
:= Pname
;
6542 Error_Msg_N
(Fix_Error
(Msg
), Arg
);
6544 end Error_Pragma_Arg_Ident
;
6546 ----------------------
6547 -- Error_Pragma_Ref --
6548 ----------------------
6550 procedure Error_Pragma_Ref
(Msg
: String; Ref
: Entity_Id
) is
6552 Error_Msg_Name_1
:= Pname
;
6553 Error_Msg_Sloc
:= Sloc
(Ref
);
6554 Error_Msg_NE
(Fix_Error
(Msg
), N
, Ref
);
6556 end Error_Pragma_Ref
;
6558 ------------------------
6559 -- Find_Lib_Unit_Name --
6560 ------------------------
6562 function Find_Lib_Unit_Name
return Entity_Id
is
6564 -- Return inner compilation unit entity, for case of nested
6565 -- categorization pragmas. This happens in generic unit.
6567 if Nkind
(Parent
(N
)) = N_Package_Specification
6568 and then Defining_Entity
(Parent
(N
)) /= Current_Scope
6570 return Defining_Entity
(Parent
(N
));
6572 return Current_Scope
;
6574 end Find_Lib_Unit_Name
;
6576 ----------------------------
6577 -- Find_Program_Unit_Name --
6578 ----------------------------
6580 procedure Find_Program_Unit_Name
(Id
: Node_Id
) is
6581 Unit_Name
: Entity_Id
;
6582 Unit_Kind
: Node_Kind
;
6583 P
: constant Node_Id
:= Parent
(N
);
6586 if Nkind
(P
) = N_Compilation_Unit
then
6587 Unit_Kind
:= Nkind
(Unit
(P
));
6589 if Nkind_In
(Unit_Kind
, N_Subprogram_Declaration
,
6590 N_Package_Declaration
)
6591 or else Unit_Kind
in N_Generic_Declaration
6593 Unit_Name
:= Defining_Entity
(Unit
(P
));
6595 if Chars
(Id
) = Chars
(Unit_Name
) then
6596 Set_Entity
(Id
, Unit_Name
);
6597 Set_Etype
(Id
, Etype
(Unit_Name
));
6599 Set_Etype
(Id
, Any_Type
);
6601 ("cannot find program unit referenced by pragma%");
6605 Set_Etype
(Id
, Any_Type
);
6606 Error_Pragma
("pragma% inapplicable to this unit");
6612 end Find_Program_Unit_Name
;
6614 -----------------------------------------
6615 -- Find_Unique_Parameterless_Procedure --
6616 -----------------------------------------
6618 function Find_Unique_Parameterless_Procedure
6620 Arg
: Node_Id
) return Entity_Id
6622 Proc
: Entity_Id
:= Empty
;
6625 -- The body of this procedure needs some comments ???
6627 if not Is_Entity_Name
(Name
) then
6629 ("argument of pragma% must be entity name", Arg
);
6631 elsif not Is_Overloaded
(Name
) then
6632 Proc
:= Entity
(Name
);
6634 if Ekind
(Proc
) /= E_Procedure
6635 or else Present
(First_Formal
(Proc
))
6638 ("argument of pragma% must be parameterless procedure", Arg
);
6643 Found
: Boolean := False;
6645 Index
: Interp_Index
;
6648 Get_First_Interp
(Name
, Index
, It
);
6649 while Present
(It
.Nam
) loop
6652 if Ekind
(Proc
) = E_Procedure
6653 and then No
(First_Formal
(Proc
))
6657 Set_Entity
(Name
, Proc
);
6658 Set_Is_Overloaded
(Name
, False);
6661 ("ambiguous handler name for pragma% ", Arg
);
6665 Get_Next_Interp
(Index
, It
);
6670 ("argument of pragma% must be parameterless procedure",
6673 Proc
:= Entity
(Name
);
6679 end Find_Unique_Parameterless_Procedure
;
6685 function Fix_Error
(Msg
: String) return String is
6686 Res
: String (Msg
'Range) := Msg
;
6687 Res_Last
: Natural := Msg
'Last;
6691 -- If we have a rewriting of another pragma, go to that pragma
6693 if Is_Rewrite_Substitution
(N
)
6694 and then Nkind
(Original_Node
(N
)) = N_Pragma
6696 Error_Msg_Name_1
:= Pragma_Name
(Original_Node
(N
));
6699 -- Case where pragma comes from an aspect specification
6701 if From_Aspect_Specification
(N
) then
6703 -- Change appearence of "pragma" in message to "aspect"
6706 while J
<= Res_Last
- 5 loop
6707 if Res
(J
.. J
+ 5) = "pragma" then
6708 Res
(J
.. J
+ 5) := "aspect";
6716 -- Change "argument of" at start of message to "entity for"
6719 and then Res
(Res
'First .. Res
'First + 10) = "argument of"
6721 Res
(Res
'First .. Res
'First + 9) := "entity for";
6722 Res
(Res
'First + 10 .. Res_Last
- 1) :=
6723 Res
(Res
'First + 11 .. Res_Last
);
6724 Res_Last
:= Res_Last
- 1;
6727 -- Change "argument" at start of message to "entity"
6730 and then Res
(Res
'First .. Res
'First + 7) = "argument"
6732 Res
(Res
'First .. Res
'First + 5) := "entity";
6733 Res
(Res
'First + 6 .. Res_Last
- 2) :=
6734 Res
(Res
'First + 8 .. Res_Last
);
6735 Res_Last
:= Res_Last
- 2;
6738 -- Get name from corresponding aspect
6740 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(N
);
6743 -- Return possibly modified message
6745 return Res
(Res
'First .. Res_Last
);
6748 -------------------------
6749 -- Gather_Associations --
6750 -------------------------
6752 procedure Gather_Associations
6754 Args
: out Args_List
)
6759 -- Initialize all parameters to Empty
6761 for J
in Args
'Range loop
6765 -- That's all we have to do if there are no argument associations
6767 if No
(Pragma_Argument_Associations
(N
)) then
6771 -- Otherwise first deal with any positional parameters present
6773 Arg
:= First
(Pragma_Argument_Associations
(N
));
6774 for Index
in Args
'Range loop
6775 exit when No
(Arg
) or else Chars
(Arg
) /= No_Name
;
6776 Args
(Index
) := Get_Pragma_Arg
(Arg
);
6780 -- Positional parameters all processed, if any left, then we
6781 -- have too many positional parameters.
6783 if Present
(Arg
) and then Chars
(Arg
) = No_Name
then
6785 ("too many positional associations for pragma%", Arg
);
6788 -- Process named parameters if any are present
6790 while Present
(Arg
) loop
6791 if Chars
(Arg
) = No_Name
then
6793 ("positional association cannot follow named association",
6797 for Index
in Names
'Range loop
6798 if Names
(Index
) = Chars
(Arg
) then
6799 if Present
(Args
(Index
)) then
6801 ("duplicate argument association for pragma%", Arg
);
6803 Args
(Index
) := Get_Pragma_Arg
(Arg
);
6808 if Index
= Names
'Last then
6809 Error_Msg_Name_1
:= Pname
;
6810 Error_Msg_N
("pragma% does not allow & argument", Arg
);
6812 -- Check for possible misspelling
6814 for Index1
in Names
'Range loop
6815 if Is_Bad_Spelling_Of
6816 (Chars
(Arg
), Names
(Index1
))
6818 Error_Msg_Name_1
:= Names
(Index1
);
6819 Error_Msg_N
-- CODEFIX
6820 ("\possible misspelling of%", Arg
);
6832 end Gather_Associations
;
6838 procedure GNAT_Pragma
is
6840 -- We need to check the No_Implementation_Pragmas restriction for
6841 -- the case of a pragma from source. Note that the case of aspects
6842 -- generating corresponding pragmas marks these pragmas as not being
6843 -- from source, so this test also catches that case.
6845 if Comes_From_Source
(N
) then
6846 Check_Restriction
(No_Implementation_Pragmas
, N
);
6850 --------------------------
6851 -- Is_Before_First_Decl --
6852 --------------------------
6854 function Is_Before_First_Decl
6855 (Pragma_Node
: Node_Id
;
6856 Decls
: List_Id
) return Boolean
6858 Item
: Node_Id
:= First
(Decls
);
6861 -- Only other pragmas can come before this pragma
6864 if No
(Item
) or else Nkind
(Item
) /= N_Pragma
then
6867 elsif Item
= Pragma_Node
then
6873 end Is_Before_First_Decl
;
6875 -----------------------------
6876 -- Is_Configuration_Pragma --
6877 -----------------------------
6879 -- A configuration pragma must appear in the context clause of a
6880 -- compilation unit, and only other pragmas may precede it. Note that
6881 -- the test below also permits use in a configuration pragma file.
6883 function Is_Configuration_Pragma
return Boolean is
6884 Lis
: constant List_Id
:= List_Containing
(N
);
6885 Par
: constant Node_Id
:= Parent
(N
);
6889 -- If no parent, then we are in the configuration pragma file,
6890 -- so the placement is definitely appropriate.
6895 -- Otherwise we must be in the context clause of a compilation unit
6896 -- and the only thing allowed before us in the context list is more
6897 -- configuration pragmas.
6899 elsif Nkind
(Par
) = N_Compilation_Unit
6900 and then Context_Items
(Par
) = Lis
6907 elsif Nkind
(Prg
) /= N_Pragma
then
6917 end Is_Configuration_Pragma
;
6919 --------------------------
6920 -- Is_In_Context_Clause --
6921 --------------------------
6923 function Is_In_Context_Clause
return Boolean is
6925 Parent_Node
: Node_Id
;
6928 if not Is_List_Member
(N
) then
6932 Plist
:= List_Containing
(N
);
6933 Parent_Node
:= Parent
(Plist
);
6935 if Parent_Node
= Empty
6936 or else Nkind
(Parent_Node
) /= N_Compilation_Unit
6937 or else Context_Items
(Parent_Node
) /= Plist
6944 end Is_In_Context_Clause
;
6946 ---------------------------------
6947 -- Is_Static_String_Expression --
6948 ---------------------------------
6950 function Is_Static_String_Expression
(Arg
: Node_Id
) return Boolean is
6951 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
6952 Lit
: constant Boolean := Nkind
(Argx
) = N_String_Literal
;
6955 Analyze_And_Resolve
(Argx
);
6957 -- Special case Ada 83, where the expression will never be static,
6958 -- but we will return true if we had a string literal to start with.
6960 if Ada_Version
= Ada_83
then
6963 -- Normal case, true only if we end up with a string literal that
6964 -- is marked as being the result of evaluating a static expression.
6967 return Is_OK_Static_Expression
(Argx
)
6968 and then Nkind
(Argx
) = N_String_Literal
;
6971 end Is_Static_String_Expression
;
6973 ----------------------
6974 -- Pragma_Misplaced --
6975 ----------------------
6977 procedure Pragma_Misplaced
is
6979 Error_Pragma
("incorrect placement of pragma%");
6980 end Pragma_Misplaced
;
6982 ------------------------------------------------
6983 -- Process_Atomic_Independent_Shared_Volatile --
6984 ------------------------------------------------
6986 procedure Process_Atomic_Independent_Shared_Volatile
is
6987 procedure Check_VFA_Conflicts
(Ent
: Entity_Id
);
6988 -- Apply additional checks for the GNAT pragma Volatile_Full_Access
6990 procedure Mark_Component_Or_Object
(Ent
: Entity_Id
);
6991 -- Appropriately set flags on the given entity (either an array or
6992 -- record component, or an object declaration) according to the
6995 procedure Set_Atomic_VFA
(Ent
: Entity_Id
);
6996 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
6997 -- no explicit alignment was given, set alignment to unknown, since
6998 -- back end knows what the alignment requirements are for atomic and
6999 -- full access arrays. Note: this is necessary for derived types.
7001 -------------------------
7002 -- Check_VFA_Conflicts --
7003 -------------------------
7005 procedure Check_VFA_Conflicts
(Ent
: Entity_Id
) is
7009 VFA_And_Atomic
: Boolean := False;
7010 -- Set True if atomic component present
7012 VFA_And_Aliased
: Boolean := False;
7013 -- Set True if aliased component present
7016 -- Fetch the type in case we are dealing with an object or
7019 if Is_Type
(Ent
) then
7022 pragma Assert
(Is_Object
(Ent
)
7024 Nkind
(Declaration_Node
(Ent
)) = N_Component_Declaration
);
7029 -- Check Atomic and VFA used together
7031 if Prag_Id
= Pragma_Volatile_Full_Access
7032 or else Is_Volatile_Full_Access
(Ent
)
7034 if Prag_Id
= Pragma_Atomic
7035 or else Prag_Id
= Pragma_Shared
7036 or else Is_Atomic
(Ent
)
7038 VFA_And_Atomic
:= True;
7040 elsif Is_Array_Type
(Typ
) then
7041 VFA_And_Atomic
:= Has_Atomic_Components
(Typ
);
7043 -- Note: Has_Atomic_Components is not used below, as this flag
7044 -- represents the pragma of the same name, Atomic_Components,
7045 -- which only applies to arrays.
7047 elsif Is_Record_Type
(Typ
) then
7048 -- Attributes cannot be applied to discriminants, only
7049 -- regular record components.
7051 Comp
:= First_Component
(Typ
);
7052 while Present
(Comp
) loop
7054 or else Is_Atomic
(Typ
)
7056 VFA_And_Atomic
:= True;
7061 Next_Component
(Comp
);
7065 if VFA_And_Atomic
then
7067 ("cannot have Volatile_Full_Access and Atomic for same "
7072 -- Check for the application of VFA to an entity that has aliased
7075 if Prag_Id
= Pragma_Volatile_Full_Access
then
7076 if Is_Array_Type
(Typ
)
7077 and then Has_Aliased_Components
(Typ
)
7079 VFA_And_Aliased
:= True;
7081 -- Note: Has_Aliased_Components, like Has_Atomic_Components,
7082 -- and Has_Independent_Components, applies only to arrays.
7083 -- However, this flag does not have a corresponding pragma, so
7084 -- perhaps it should be possible to apply it to record types as
7085 -- well. Should this be done ???
7087 elsif Is_Record_Type
(Typ
) then
7088 -- It is possible to have an aliased discriminant, so they
7089 -- must be checked along with normal components.
7091 Comp
:= First_Component_Or_Discriminant
(Typ
);
7092 while Present
(Comp
) loop
7093 if Is_Aliased
(Comp
)
7094 or else Is_Aliased
(Etype
(Comp
))
7096 VFA_And_Aliased
:= True;
7097 Check_SPARK_05_Restriction
7098 ("aliased is not allowed", Comp
);
7103 Next_Component_Or_Discriminant
(Comp
);
7107 if VFA_And_Aliased
then
7109 ("cannot apply Volatile_Full_Access (aliased component "
7113 end Check_VFA_Conflicts
;
7115 ------------------------------
7116 -- Mark_Component_Or_Object --
7117 ------------------------------
7119 procedure Mark_Component_Or_Object
(Ent
: Entity_Id
) is
7121 if Prag_Id
= Pragma_Atomic
7122 or else Prag_Id
= Pragma_Shared
7123 or else Prag_Id
= Pragma_Volatile_Full_Access
7125 if Prag_Id
= Pragma_Volatile_Full_Access
then
7126 Set_Is_Volatile_Full_Access
(Ent
);
7128 Set_Is_Atomic
(Ent
);
7131 -- If the object declaration has an explicit initialization, a
7132 -- temporary may have to be created to hold the expression, to
7133 -- ensure that access to the object remains atomic.
7135 if Nkind
(Parent
(Ent
)) = N_Object_Declaration
7136 and then Present
(Expression
(Parent
(Ent
)))
7138 Set_Has_Delayed_Freeze
(Ent
);
7142 -- Atomic/Shared/Volatile_Full_Access imply Independent
7144 if Prag_Id
/= Pragma_Volatile
then
7145 Set_Is_Independent
(Ent
);
7147 if Prag_Id
= Pragma_Independent
then
7148 Record_Independence_Check
(N
, Ent
);
7152 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7154 if Prag_Id
/= Pragma_Independent
then
7155 Set_Is_Volatile
(Ent
);
7156 Set_Treat_As_Volatile
(Ent
);
7158 end Mark_Component_Or_Object
;
7160 --------------------
7161 -- Set_Atomic_VFA --
7162 --------------------
7164 procedure Set_Atomic_VFA
(Ent
: Entity_Id
) is
7166 if Prag_Id
= Pragma_Volatile_Full_Access
then
7167 Set_Is_Volatile_Full_Access
(Ent
);
7169 Set_Is_Atomic
(Ent
);
7172 if not Has_Alignment_Clause
(Ent
) then
7173 Set_Alignment
(Ent
, Uint_0
);
7183 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
7186 Check_Ada_83_Warning
;
7187 Check_No_Identifiers
;
7188 Check_Arg_Count
(1);
7189 Check_Arg_Is_Local_Name
(Arg1
);
7190 E_Arg
:= Get_Pragma_Arg
(Arg1
);
7192 if Etype
(E_Arg
) = Any_Type
then
7196 E
:= Entity
(E_Arg
);
7198 -- A pragma that applies to a Ghost entity becomes Ghost for the
7199 -- purposes of legality checks and removal of ignored Ghost code.
7201 Mark_Ghost_Pragma
(N
, E
);
7203 -- Check duplicate before we chain ourselves
7205 Check_Duplicate_Pragma
(E
);
7207 -- Check appropriateness of the entity
7209 Decl
:= Declaration_Node
(E
);
7211 -- Deal with the case where the pragma/attribute is applied to a type
7214 if Rep_Item_Too_Early
(E
, N
)
7215 or else Rep_Item_Too_Late
(E
, N
)
7219 Check_First_Subtype
(Arg1
);
7222 -- Attribute belongs on the base type. If the view of the type is
7223 -- currently private, it also belongs on the underlying type.
7225 if Prag_Id
= Pragma_Atomic
7226 or else Prag_Id
= Pragma_Shared
7227 or else Prag_Id
= Pragma_Volatile_Full_Access
7230 Set_Atomic_VFA
(Base_Type
(E
));
7231 Set_Atomic_VFA
(Underlying_Type
(E
));
7234 -- Atomic/Shared/Volatile_Full_Access imply Independent
7236 if Prag_Id
/= Pragma_Volatile
then
7237 Set_Is_Independent
(E
);
7238 Set_Is_Independent
(Base_Type
(E
));
7239 Set_Is_Independent
(Underlying_Type
(E
));
7241 if Prag_Id
= Pragma_Independent
then
7242 Record_Independence_Check
(N
, Base_Type
(E
));
7246 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7248 if Prag_Id
/= Pragma_Independent
then
7249 Set_Is_Volatile
(E
);
7250 Set_Is_Volatile
(Base_Type
(E
));
7251 Set_Is_Volatile
(Underlying_Type
(E
));
7253 Set_Treat_As_Volatile
(E
);
7254 Set_Treat_As_Volatile
(Underlying_Type
(E
));
7257 -- Apply Volatile to the composite type's individual components,
7260 if Prag_Id
= Pragma_Volatile
7261 and then Is_Record_Type
(Etype
(E
))
7266 Comp
:= First_Component
(E
);
7267 while Present
(Comp
) loop
7268 Mark_Component_Or_Object
(Comp
);
7270 Next_Component
(Comp
);
7275 -- Deal with the case where the pragma/attribute applies to a
7276 -- component or object declaration.
7278 elsif Nkind
(Decl
) = N_Object_Declaration
7279 or else (Nkind
(Decl
) = N_Component_Declaration
7280 and then Original_Record_Component
(E
) = E
)
7282 if Rep_Item_Too_Late
(E
, N
) then
7286 Mark_Component_Or_Object
(E
);
7288 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
7291 -- Perform the checks needed to assure the proper use of the GNAT
7292 -- pragma Volatile_Full_Access.
7294 Check_VFA_Conflicts
(E
);
7296 -- The following check is only relevant when SPARK_Mode is on as
7297 -- this is not a standard Ada legality rule. Pragma Volatile can
7298 -- only apply to a full type declaration or an object declaration
7299 -- (SPARK RM 7.1.3(2)). Original_Node is necessary to account for
7300 -- untagged derived types that are rewritten as subtypes of their
7301 -- respective root types.
7304 and then Prag_Id
= Pragma_Volatile
7306 not Nkind_In
(Original_Node
(Decl
), N_Full_Type_Declaration
,
7307 N_Object_Declaration
)
7310 ("argument of pragma % must denote a full type or object "
7311 & "declaration", Arg1
);
7313 end Process_Atomic_Independent_Shared_Volatile
;
7315 -------------------------------------------
7316 -- Process_Compile_Time_Warning_Or_Error --
7317 -------------------------------------------
7319 procedure Process_Compile_Time_Warning_Or_Error
is
7320 Validation_Needed
: Boolean := False;
7322 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
7323 -- Tree visitor that checks if N is an attribute reference that can
7324 -- be statically computed by the back end. Validation_Needed is set
7325 -- to True if found.
7331 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
7333 if Nkind
(N
) = N_Attribute_Reference
7334 and then Is_Entity_Name
(Prefix
(N
))
7337 Attr_Id
: constant Attribute_Id
:=
7338 Get_Attribute_Id
(Attribute_Name
(N
));
7340 if Attr_Id
= Attribute_Alignment
7341 or else Attr_Id
= Attribute_Size
7343 Validation_Needed
:= True;
7351 procedure Check_Expression
is new Traverse_Proc
(Check_Node
);
7355 Arg1x
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
7357 -- Start of processing for Process_Compile_Time_Warning_Or_Error
7360 Check_Arg_Count
(2);
7361 Check_No_Identifiers
;
7362 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
7363 Analyze_And_Resolve
(Arg1x
, Standard_Boolean
);
7365 if Compile_Time_Known_Value
(Arg1x
) then
7366 Process_Compile_Time_Warning_Or_Error
(N
, Sloc
(Arg1
));
7368 -- Register the expression for its validation after the back end has
7369 -- been called if it has occurrences of attributes Size or Alignment
7370 -- (because they may be statically computed by the back end and hence
7371 -- the whole expression needs to be reevaluated).
7374 Check_Expression
(Arg1x
);
7376 if Validation_Needed
then
7377 Sem_Ch13
.Validate_Compile_Time_Warning_Error
(N
);
7380 end Process_Compile_Time_Warning_Or_Error
;
7382 ------------------------
7383 -- Process_Convention --
7384 ------------------------
7386 procedure Process_Convention
7387 (C
: out Convention_Id
;
7388 Ent
: out Entity_Id
)
7392 procedure Diagnose_Multiple_Pragmas
(S
: Entity_Id
);
7393 -- Called if we have more than one Export/Import/Convention pragma.
7394 -- This is generally illegal, but we have a special case of allowing
7395 -- Import and Interface to coexist if they specify the convention in
7396 -- a consistent manner. We are allowed to do this, since Interface is
7397 -- an implementation defined pragma, and we choose to do it since we
7398 -- know Rational allows this combination. S is the entity id of the
7399 -- subprogram in question. This procedure also sets the special flag
7400 -- Import_Interface_Present in both pragmas in the case where we do
7401 -- have matching Import and Interface pragmas.
7403 procedure Set_Convention_From_Pragma
(E
: Entity_Id
);
7404 -- Set convention in entity E, and also flag that the entity has a
7405 -- convention pragma. If entity is for a private or incomplete type,
7406 -- also set convention and flag on underlying type. This procedure
7407 -- also deals with the special case of C_Pass_By_Copy convention,
7408 -- and error checks for inappropriate convention specification.
7410 -------------------------------
7411 -- Diagnose_Multiple_Pragmas --
7412 -------------------------------
7414 procedure Diagnose_Multiple_Pragmas
(S
: Entity_Id
) is
7415 Pdec
: constant Node_Id
:= Declaration_Node
(S
);
7419 function Same_Convention
(Decl
: Node_Id
) return Boolean;
7420 -- Decl is a pragma node. This function returns True if this
7421 -- pragma has a first argument that is an identifier with a
7422 -- Chars field corresponding to the Convention_Id C.
7424 function Same_Name
(Decl
: Node_Id
) return Boolean;
7425 -- Decl is a pragma node. This function returns True if this
7426 -- pragma has a second argument that is an identifier with a
7427 -- Chars field that matches the Chars of the current subprogram.
7429 ---------------------
7430 -- Same_Convention --
7431 ---------------------
7433 function Same_Convention
(Decl
: Node_Id
) return Boolean is
7434 Arg1
: constant Node_Id
:=
7435 First
(Pragma_Argument_Associations
(Decl
));
7438 if Present
(Arg1
) then
7440 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
7442 if Nkind
(Arg
) = N_Identifier
7443 and then Is_Convention_Name
(Chars
(Arg
))
7444 and then Get_Convention_Id
(Chars
(Arg
)) = C
7452 end Same_Convention
;
7458 function Same_Name
(Decl
: Node_Id
) return Boolean is
7459 Arg1
: constant Node_Id
:=
7460 First
(Pragma_Argument_Associations
(Decl
));
7468 Arg2
:= Next
(Arg1
);
7475 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
7477 if Nkind
(Arg
) = N_Identifier
7478 and then Chars
(Arg
) = Chars
(S
)
7487 -- Start of processing for Diagnose_Multiple_Pragmas
7492 -- Definitely give message if we have Convention/Export here
7494 if Prag_Id
= Pragma_Convention
or else Prag_Id
= Pragma_Export
then
7497 -- If we have an Import or Export, scan back from pragma to
7498 -- find any previous pragma applying to the same procedure.
7499 -- The scan will be terminated by the start of the list, or
7500 -- hitting the subprogram declaration. This won't allow one
7501 -- pragma to appear in the public part and one in the private
7502 -- part, but that seems very unlikely in practice.
7506 while Present
(Decl
) and then Decl
/= Pdec
loop
7508 -- Look for pragma with same name as us
7510 if Nkind
(Decl
) = N_Pragma
7511 and then Same_Name
(Decl
)
7513 -- Give error if same as our pragma or Export/Convention
7515 if Nam_In
(Pragma_Name_Unmapped
(Decl
),
7518 Pragma_Name_Unmapped
(N
))
7522 -- Case of Import/Interface or the other way round
7524 elsif Nam_In
(Pragma_Name_Unmapped
(Decl
),
7525 Name_Interface
, Name_Import
)
7527 -- Here we know that we have Import and Interface. It
7528 -- doesn't matter which way round they are. See if
7529 -- they specify the same convention. If so, all OK,
7530 -- and set special flags to stop other messages
7532 if Same_Convention
(Decl
) then
7533 Set_Import_Interface_Present
(N
);
7534 Set_Import_Interface_Present
(Decl
);
7537 -- If different conventions, special message
7540 Error_Msg_Sloc
:= Sloc
(Decl
);
7542 ("convention differs from that given#", Arg1
);
7552 -- Give message if needed if we fall through those tests
7553 -- except on Relaxed_RM_Semantics where we let go: either this
7554 -- is a case accepted/ignored by other Ada compilers (e.g.
7555 -- a mix of Convention and Import), or another error will be
7556 -- generated later (e.g. using both Import and Export).
7558 if Err
and not Relaxed_RM_Semantics
then
7560 ("at most one Convention/Export/Import pragma is allowed",
7563 end Diagnose_Multiple_Pragmas
;
7565 --------------------------------
7566 -- Set_Convention_From_Pragma --
7567 --------------------------------
7569 procedure Set_Convention_From_Pragma
(E
: Entity_Id
) is
7571 -- Ada 2005 (AI-430): Check invalid attempt to change convention
7572 -- for an overridden dispatching operation. Technically this is
7573 -- an amendment and should only be done in Ada 2005 mode. However,
7574 -- this is clearly a mistake, since the problem that is addressed
7575 -- by this AI is that there is a clear gap in the RM.
7577 if Is_Dispatching_Operation
(E
)
7578 and then Present
(Overridden_Operation
(E
))
7579 and then C
/= Convention
(Overridden_Operation
(E
))
7582 ("cannot change convention for overridden dispatching "
7583 & "operation", Arg1
);
7586 -- Special checks for Convention_Stdcall
7588 if C
= Convention_Stdcall
then
7590 -- A dispatching call is not allowed. A dispatching subprogram
7591 -- cannot be used to interface to the Win32 API, so in fact
7592 -- this check does not impose any effective restriction.
7594 if Is_Dispatching_Operation
(E
) then
7595 Error_Msg_Sloc
:= Sloc
(E
);
7597 -- Note: make this unconditional so that if there is more
7598 -- than one call to which the pragma applies, we get a
7599 -- message for each call. Also don't use Error_Pragma,
7600 -- so that we get multiple messages.
7603 ("dispatching subprogram# cannot use Stdcall convention!",
7606 -- Several allowed cases
7608 elsif Is_Subprogram_Or_Generic_Subprogram
(E
)
7612 or else Ekind
(E
) = E_Variable
7614 -- A component as well. The entity does not have its Ekind
7615 -- set until the enclosing record declaration is fully
7618 or else Nkind
(Parent
(E
)) = N_Component_Declaration
7620 -- An access to subprogram is also allowed
7624 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
)
7626 -- Allow internal call to set convention of subprogram type
7628 or else Ekind
(E
) = E_Subprogram_Type
7634 ("second argument of pragma% must be subprogram (type)",
7639 -- Set the convention
7641 Set_Convention
(E
, C
);
7642 Set_Has_Convention_Pragma
(E
);
7644 -- For the case of a record base type, also set the convention of
7645 -- any anonymous access types declared in the record which do not
7646 -- currently have a specified convention.
7648 if Is_Record_Type
(E
) and then Is_Base_Type
(E
) then
7653 Comp
:= First_Component
(E
);
7654 while Present
(Comp
) loop
7655 if Present
(Etype
(Comp
))
7656 and then Ekind_In
(Etype
(Comp
),
7657 E_Anonymous_Access_Type
,
7658 E_Anonymous_Access_Subprogram_Type
)
7659 and then not Has_Convention_Pragma
(Comp
)
7661 Set_Convention
(Comp
, C
);
7664 Next_Component
(Comp
);
7669 -- Deal with incomplete/private type case, where underlying type
7670 -- is available, so set convention of that underlying type.
7672 if Is_Incomplete_Or_Private_Type
(E
)
7673 and then Present
(Underlying_Type
(E
))
7675 Set_Convention
(Underlying_Type
(E
), C
);
7676 Set_Has_Convention_Pragma
(Underlying_Type
(E
), True);
7679 -- A class-wide type should inherit the convention of the specific
7680 -- root type (although this isn't specified clearly by the RM).
7682 if Is_Type
(E
) and then Present
(Class_Wide_Type
(E
)) then
7683 Set_Convention
(Class_Wide_Type
(E
), C
);
7686 -- If the entity is a record type, then check for special case of
7687 -- C_Pass_By_Copy, which is treated the same as C except that the
7688 -- special record flag is set. This convention is only permitted
7689 -- on record types (see AI95-00131).
7691 if Cname
= Name_C_Pass_By_Copy
then
7692 if Is_Record_Type
(E
) then
7693 Set_C_Pass_By_Copy
(Base_Type
(E
));
7694 elsif Is_Incomplete_Or_Private_Type
(E
)
7695 and then Is_Record_Type
(Underlying_Type
(E
))
7697 Set_C_Pass_By_Copy
(Base_Type
(Underlying_Type
(E
)));
7700 ("C_Pass_By_Copy convention allowed only for record type",
7705 -- If the entity is a derived boolean type, check for the special
7706 -- case of convention C, C++, or Fortran, where we consider any
7707 -- nonzero value to represent true.
7709 if Is_Discrete_Type
(E
)
7710 and then Root_Type
(Etype
(E
)) = Standard_Boolean
7716 C
= Convention_Fortran
)
7718 Set_Nonzero_Is_True
(Base_Type
(E
));
7720 end Set_Convention_From_Pragma
;
7724 Comp_Unit
: Unit_Number_Type
;
7729 -- Start of processing for Process_Convention
7732 Check_At_Least_N_Arguments
(2);
7733 Check_Optional_Identifier
(Arg1
, Name_Convention
);
7734 Check_Arg_Is_Identifier
(Arg1
);
7735 Cname
:= Chars
(Get_Pragma_Arg
(Arg1
));
7737 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
7738 -- tested again below to set the critical flag).
7740 if Cname
= Name_C_Pass_By_Copy
then
7743 -- Otherwise we must have something in the standard convention list
7745 elsif Is_Convention_Name
(Cname
) then
7746 C
:= Get_Convention_Id
(Chars
(Get_Pragma_Arg
(Arg1
)));
7748 -- Otherwise warn on unrecognized convention
7751 if Warn_On_Export_Import
then
7753 ("??unrecognized convention name, C assumed",
7754 Get_Pragma_Arg
(Arg1
));
7760 Check_Optional_Identifier
(Arg2
, Name_Entity
);
7761 Check_Arg_Is_Local_Name
(Arg2
);
7763 Id
:= Get_Pragma_Arg
(Arg2
);
7766 if not Is_Entity_Name
(Id
) then
7767 Error_Pragma_Arg
("entity name required", Arg2
);
7772 -- Set entity to return
7776 -- Ada_Pass_By_Copy special checking
7778 if C
= Convention_Ada_Pass_By_Copy
then
7779 if not Is_First_Subtype
(E
) then
7781 ("convention `Ada_Pass_By_Copy` only allowed for types",
7785 if Is_By_Reference_Type
(E
) then
7787 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
7791 -- Ada_Pass_By_Reference special checking
7793 elsif C
= Convention_Ada_Pass_By_Reference
then
7794 if not Is_First_Subtype
(E
) then
7796 ("convention `Ada_Pass_By_Reference` only allowed for types",
7800 if Is_By_Copy_Type
(E
) then
7802 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
7807 -- Go to renamed subprogram if present, since convention applies to
7808 -- the actual renamed entity, not to the renaming entity. If the
7809 -- subprogram is inherited, go to parent subprogram.
7811 if Is_Subprogram
(E
)
7812 and then Present
(Alias
(E
))
7814 if Nkind
(Parent
(Declaration_Node
(E
))) =
7815 N_Subprogram_Renaming_Declaration
7817 if Scope
(E
) /= Scope
(Alias
(E
)) then
7819 ("cannot apply pragma% to non-local entity&#", E
);
7824 elsif Nkind_In
(Parent
(E
), N_Full_Type_Declaration
,
7825 N_Private_Extension_Declaration
)
7826 and then Scope
(E
) = Scope
(Alias
(E
))
7830 -- Return the parent subprogram the entity was inherited from
7836 -- Check that we are not applying this to a specless body. Relax this
7837 -- check if Relaxed_RM_Semantics to accommodate other Ada compilers.
7839 if Is_Subprogram
(E
)
7840 and then Nkind
(Parent
(Declaration_Node
(E
))) = N_Subprogram_Body
7841 and then not Relaxed_RM_Semantics
7844 ("pragma% requires separate spec and must come before body");
7847 -- Check that we are not applying this to a named constant
7849 if Ekind_In
(E
, E_Named_Integer
, E_Named_Real
) then
7850 Error_Msg_Name_1
:= Pname
;
7852 ("cannot apply pragma% to named constant!",
7853 Get_Pragma_Arg
(Arg2
));
7855 ("\supply appropriate type for&!", Arg2
);
7858 if Ekind
(E
) = E_Enumeration_Literal
then
7859 Error_Pragma
("enumeration literal not allowed for pragma%");
7862 -- Check for rep item appearing too early or too late
7864 if Etype
(E
) = Any_Type
7865 or else Rep_Item_Too_Early
(E
, N
)
7869 elsif Present
(Underlying_Type
(E
)) then
7870 E
:= Underlying_Type
(E
);
7873 if Rep_Item_Too_Late
(E
, N
) then
7877 if Has_Convention_Pragma
(E
) then
7878 Diagnose_Multiple_Pragmas
(E
);
7880 elsif Convention
(E
) = Convention_Protected
7881 or else Ekind
(Scope
(E
)) = E_Protected_Type
7884 ("a protected operation cannot be given a different convention",
7888 -- For Intrinsic, a subprogram is required
7890 if C
= Convention_Intrinsic
7891 and then not Is_Subprogram_Or_Generic_Subprogram
(E
)
7893 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
7895 if not (Is_Type
(E
) and then Relaxed_RM_Semantics
) then
7897 ("second argument of pragma% must be a subprogram", Arg2
);
7901 -- Deal with non-subprogram cases
7903 if not Is_Subprogram_Or_Generic_Subprogram
(E
) then
7904 Set_Convention_From_Pragma
(E
);
7908 -- The pragma must apply to a first subtype, but it can also
7909 -- apply to a generic type in a generic formal part, in which
7910 -- case it will also appear in the corresponding instance.
7912 if Is_Generic_Type
(E
) or else In_Instance
then
7915 Check_First_Subtype
(Arg2
);
7918 Set_Convention_From_Pragma
(Base_Type
(E
));
7920 -- For access subprograms, we must set the convention on the
7921 -- internally generated directly designated type as well.
7923 if Ekind
(E
) = E_Access_Subprogram_Type
then
7924 Set_Convention_From_Pragma
(Directly_Designated_Type
(E
));
7928 -- For the subprogram case, set proper convention for all homonyms
7929 -- in same scope and the same declarative part, i.e. the same
7930 -- compilation unit.
7933 Comp_Unit
:= Get_Source_Unit
(E
);
7934 Set_Convention_From_Pragma
(E
);
7936 -- Treat a pragma Import as an implicit body, and pragma import
7937 -- as implicit reference (for navigation in GPS).
7939 if Prag_Id
= Pragma_Import
then
7940 Generate_Reference
(E
, Id
, 'b');
7942 -- For exported entities we restrict the generation of references
7943 -- to entities exported to foreign languages since entities
7944 -- exported to Ada do not provide further information to GPS and
7945 -- add undesired references to the output of the gnatxref tool.
7947 elsif Prag_Id
= Pragma_Export
7948 and then Convention
(E
) /= Convention_Ada
7950 Generate_Reference
(E
, Id
, 'i');
7953 -- If the pragma comes from an aspect, it only applies to the
7954 -- given entity, not its homonyms.
7956 if From_Aspect_Specification
(N
) then
7957 if C
= Convention_Intrinsic
7958 and then Nkind
(Ent
) = N_Defining_Operator_Symbol
7960 if Is_Fixed_Point_Type
(Etype
(Ent
))
7961 or else Is_Fixed_Point_Type
(Etype
(First_Entity
(Ent
)))
7962 or else Is_Fixed_Point_Type
(Etype
(Last_Entity
(Ent
)))
7965 ("no intrinsic operator available for this fixed-point "
7968 ("\use expression functions with the desired "
7969 & "conversions made explicit", N
);
7976 -- Otherwise Loop through the homonyms of the pragma argument's
7977 -- entity, an apply convention to those in the current scope.
7983 exit when No
(E1
) or else Scope
(E1
) /= Current_Scope
;
7985 -- Ignore entry for which convention is already set
7987 if Has_Convention_Pragma
(E1
) then
7991 if Is_Subprogram
(E1
)
7992 and then Nkind
(Parent
(Declaration_Node
(E1
))) =
7994 and then not Relaxed_RM_Semantics
7996 Set_Has_Completion
(E
); -- to prevent cascaded error
7998 ("pragma% requires separate spec and must come before "
8002 -- Do not set the pragma on inherited operations or on formal
8005 if Comes_From_Source
(E1
)
8006 and then Comp_Unit
= Get_Source_Unit
(E1
)
8007 and then not Is_Formal_Subprogram
(E1
)
8008 and then Nkind
(Original_Node
(Parent
(E1
))) /=
8009 N_Full_Type_Declaration
8011 if Present
(Alias
(E1
))
8012 and then Scope
(E1
) /= Scope
(Alias
(E1
))
8015 ("cannot apply pragma% to non-local entity& declared#",
8019 Set_Convention_From_Pragma
(E1
);
8021 if Prag_Id
= Pragma_Import
then
8022 Generate_Reference
(E1
, Id
, 'b');
8030 end Process_Convention
;
8032 ----------------------------------------
8033 -- Process_Disable_Enable_Atomic_Sync --
8034 ----------------------------------------
8036 procedure Process_Disable_Enable_Atomic_Sync
(Nam
: Name_Id
) is
8038 Check_No_Identifiers
;
8039 Check_At_Most_N_Arguments
(1);
8041 -- Modeled internally as
8042 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
8047 Pragma_Argument_Associations
=> New_List
(
8048 Make_Pragma_Argument_Association
(Loc
,
8050 Make_Identifier
(Loc
, Name_Atomic_Synchronization
)))));
8052 if Present
(Arg1
) then
8053 Append_To
(Pragma_Argument_Associations
(N
), New_Copy
(Arg1
));
8057 end Process_Disable_Enable_Atomic_Sync
;
8059 -------------------------------------------------
8060 -- Process_Extended_Import_Export_Internal_Arg --
8061 -------------------------------------------------
8063 procedure Process_Extended_Import_Export_Internal_Arg
8064 (Arg_Internal
: Node_Id
:= Empty
)
8067 if No
(Arg_Internal
) then
8068 Error_Pragma
("Internal parameter required for pragma%");
8071 if Nkind
(Arg_Internal
) = N_Identifier
then
8074 elsif Nkind
(Arg_Internal
) = N_Operator_Symbol
8075 and then (Prag_Id
= Pragma_Import_Function
8077 Prag_Id
= Pragma_Export_Function
)
8083 ("wrong form for Internal parameter for pragma%", Arg_Internal
);
8086 Check_Arg_Is_Local_Name
(Arg_Internal
);
8087 end Process_Extended_Import_Export_Internal_Arg
;
8089 --------------------------------------------------
8090 -- Process_Extended_Import_Export_Object_Pragma --
8091 --------------------------------------------------
8093 procedure Process_Extended_Import_Export_Object_Pragma
8094 (Arg_Internal
: Node_Id
;
8095 Arg_External
: Node_Id
;
8101 Process_Extended_Import_Export_Internal_Arg
(Arg_Internal
);
8102 Def_Id
:= Entity
(Arg_Internal
);
8104 if not Ekind_In
(Def_Id
, E_Constant
, E_Variable
) then
8106 ("pragma% must designate an object", Arg_Internal
);
8109 if Has_Rep_Pragma
(Def_Id
, Name_Common_Object
)
8111 Has_Rep_Pragma
(Def_Id
, Name_Psect_Object
)
8114 ("previous Common/Psect_Object applies, pragma % not permitted",
8118 if Rep_Item_Too_Late
(Def_Id
, N
) then
8122 Set_Extended_Import_Export_External_Name
(Def_Id
, Arg_External
);
8124 if Present
(Arg_Size
) then
8125 Check_Arg_Is_External_Name
(Arg_Size
);
8128 -- Export_Object case
8130 if Prag_Id
= Pragma_Export_Object
then
8131 if not Is_Library_Level_Entity
(Def_Id
) then
8133 ("argument for pragma% must be library level entity",
8137 if Ekind
(Current_Scope
) = E_Generic_Package
then
8138 Error_Pragma
("pragma& cannot appear in a generic unit");
8141 if not Size_Known_At_Compile_Time
(Etype
(Def_Id
)) then
8143 ("exported object must have compile time known size",
8147 if Warn_On_Export_Import
and then Is_Exported
(Def_Id
) then
8148 Error_Msg_N
("??duplicate Export_Object pragma", N
);
8150 Set_Exported
(Def_Id
, Arg_Internal
);
8153 -- Import_Object case
8156 if Is_Concurrent_Type
(Etype
(Def_Id
)) then
8158 ("cannot use pragma% for task/protected object",
8162 if Ekind
(Def_Id
) = E_Constant
then
8164 ("cannot import a constant", Arg_Internal
);
8167 if Warn_On_Export_Import
8168 and then Has_Discriminants
(Etype
(Def_Id
))
8171 ("imported value must be initialized??", Arg_Internal
);
8174 if Warn_On_Export_Import
8175 and then Is_Access_Type
(Etype
(Def_Id
))
8178 ("cannot import object of an access type??", Arg_Internal
);
8181 if Warn_On_Export_Import
8182 and then Is_Imported
(Def_Id
)
8184 Error_Msg_N
("??duplicate Import_Object pragma", N
);
8186 -- Check for explicit initialization present. Note that an
8187 -- initialization generated by the code generator, e.g. for an
8188 -- access type, does not count here.
8190 elsif Present
(Expression
(Parent
(Def_Id
)))
8193 (Original_Node
(Expression
(Parent
(Def_Id
))))
8195 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8197 ("imported entities cannot be initialized (RM B.1(24))",
8198 "\no initialization allowed for & declared#", Arg1
);
8200 Set_Imported
(Def_Id
);
8201 Note_Possible_Modification
(Arg_Internal
, Sure
=> False);
8204 end Process_Extended_Import_Export_Object_Pragma
;
8206 ------------------------------------------------------
8207 -- Process_Extended_Import_Export_Subprogram_Pragma --
8208 ------------------------------------------------------
8210 procedure Process_Extended_Import_Export_Subprogram_Pragma
8211 (Arg_Internal
: Node_Id
;
8212 Arg_External
: Node_Id
;
8213 Arg_Parameter_Types
: Node_Id
;
8214 Arg_Result_Type
: Node_Id
:= Empty
;
8215 Arg_Mechanism
: Node_Id
;
8216 Arg_Result_Mechanism
: Node_Id
:= Empty
)
8222 Ambiguous
: Boolean;
8225 function Same_Base_Type
8227 Formal
: Entity_Id
) return Boolean;
8228 -- Determines if Ptype references the type of Formal. Note that only
8229 -- the base types need to match according to the spec. Ptype here is
8230 -- the argument from the pragma, which is either a type name, or an
8231 -- access attribute.
8233 --------------------
8234 -- Same_Base_Type --
8235 --------------------
8237 function Same_Base_Type
8239 Formal
: Entity_Id
) return Boolean
8241 Ftyp
: constant Entity_Id
:= Base_Type
(Etype
(Formal
));
8245 -- Case where pragma argument is typ'Access
8247 if Nkind
(Ptype
) = N_Attribute_Reference
8248 and then Attribute_Name
(Ptype
) = Name_Access
8250 Pref
:= Prefix
(Ptype
);
8253 if not Is_Entity_Name
(Pref
)
8254 or else Entity
(Pref
) = Any_Type
8259 -- We have a match if the corresponding argument is of an
8260 -- anonymous access type, and its designated type matches the
8261 -- type of the prefix of the access attribute
8263 return Ekind
(Ftyp
) = E_Anonymous_Access_Type
8264 and then Base_Type
(Entity
(Pref
)) =
8265 Base_Type
(Etype
(Designated_Type
(Ftyp
)));
8267 -- Case where pragma argument is a type name
8272 if not Is_Entity_Name
(Ptype
)
8273 or else Entity
(Ptype
) = Any_Type
8278 -- We have a match if the corresponding argument is of the type
8279 -- given in the pragma (comparing base types)
8281 return Base_Type
(Entity
(Ptype
)) = Ftyp
;
8285 -- Start of processing for
8286 -- Process_Extended_Import_Export_Subprogram_Pragma
8289 Process_Extended_Import_Export_Internal_Arg
(Arg_Internal
);
8293 -- Loop through homonyms (overloadings) of the entity
8295 Hom_Id
:= Entity
(Arg_Internal
);
8296 while Present
(Hom_Id
) loop
8297 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
8299 -- We need a subprogram in the current scope
8301 if not Is_Subprogram
(Def_Id
)
8302 or else Scope
(Def_Id
) /= Current_Scope
8309 -- Pragma cannot apply to subprogram body
8311 if Is_Subprogram
(Def_Id
)
8312 and then Nkind
(Parent
(Declaration_Node
(Def_Id
))) =
8316 ("pragma% requires separate spec and must come before "
8320 -- Test result type if given, note that the result type
8321 -- parameter can only be present for the function cases.
8323 if Present
(Arg_Result_Type
)
8324 and then not Same_Base_Type
(Arg_Result_Type
, Def_Id
)
8328 elsif Etype
(Def_Id
) /= Standard_Void_Type
8329 and then Nam_In
(Pname
, Name_Export_Procedure
,
8330 Name_Import_Procedure
)
8334 -- Test parameter types if given. Note that this parameter has
8335 -- not been analyzed (and must not be, since it is semantic
8336 -- nonsense), so we get it as the parser left it.
8338 elsif Present
(Arg_Parameter_Types
) then
8339 Check_Matching_Types
: declare
8344 Formal
:= First_Formal
(Def_Id
);
8346 if Nkind
(Arg_Parameter_Types
) = N_Null
then
8347 if Present
(Formal
) then
8351 -- A list of one type, e.g. (List) is parsed as a
8352 -- parenthesized expression.
8354 elsif Nkind
(Arg_Parameter_Types
) /= N_Aggregate
8355 and then Paren_Count
(Arg_Parameter_Types
) = 1
8358 or else Present
(Next_Formal
(Formal
))
8363 Same_Base_Type
(Arg_Parameter_Types
, Formal
);
8366 -- A list of more than one type is parsed as a aggregate
8368 elsif Nkind
(Arg_Parameter_Types
) = N_Aggregate
8369 and then Paren_Count
(Arg_Parameter_Types
) = 0
8371 Ptype
:= First
(Expressions
(Arg_Parameter_Types
));
8372 while Present
(Ptype
) or else Present
(Formal
) loop
8375 or else not Same_Base_Type
(Ptype
, Formal
)
8380 Next_Formal
(Formal
);
8385 -- Anything else is of the wrong form
8389 ("wrong form for Parameter_Types parameter",
8390 Arg_Parameter_Types
);
8392 end Check_Matching_Types
;
8395 -- Match is now False if the entry we found did not match
8396 -- either a supplied Parameter_Types or Result_Types argument
8402 -- Ambiguous case, the flag Ambiguous shows if we already
8403 -- detected this and output the initial messages.
8406 if not Ambiguous
then
8408 Error_Msg_Name_1
:= Pname
;
8410 ("pragma% does not uniquely identify subprogram!",
8412 Error_Msg_Sloc
:= Sloc
(Ent
);
8413 Error_Msg_N
("matching subprogram #!", N
);
8417 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8418 Error_Msg_N
("matching subprogram #!", N
);
8423 Hom_Id
:= Homonym
(Hom_Id
);
8426 -- See if we found an entry
8429 if not Ambiguous
then
8430 if Is_Generic_Subprogram
(Entity
(Arg_Internal
)) then
8432 ("pragma% cannot be given for generic subprogram");
8435 ("pragma% does not identify local subprogram");
8442 -- Import pragmas must be for imported entities
8444 if Prag_Id
= Pragma_Import_Function
8446 Prag_Id
= Pragma_Import_Procedure
8448 Prag_Id
= Pragma_Import_Valued_Procedure
8450 if not Is_Imported
(Ent
) then
8452 ("pragma Import or Interface must precede pragma%");
8455 -- Here we have the Export case which can set the entity as exported
8457 -- But does not do so if the specified external name is null, since
8458 -- that is taken as a signal in DEC Ada 83 (with which we want to be
8459 -- compatible) to request no external name.
8461 elsif Nkind
(Arg_External
) = N_String_Literal
8462 and then String_Length
(Strval
(Arg_External
)) = 0
8466 -- In all other cases, set entity as exported
8469 Set_Exported
(Ent
, Arg_Internal
);
8472 -- Special processing for Valued_Procedure cases
8474 if Prag_Id
= Pragma_Import_Valued_Procedure
8476 Prag_Id
= Pragma_Export_Valued_Procedure
8478 Formal
:= First_Formal
(Ent
);
8481 Error_Pragma
("at least one parameter required for pragma%");
8483 elsif Ekind
(Formal
) /= E_Out_Parameter
then
8484 Error_Pragma
("first parameter must have mode out for pragma%");
8487 Set_Is_Valued_Procedure
(Ent
);
8491 Set_Extended_Import_Export_External_Name
(Ent
, Arg_External
);
8493 -- Process Result_Mechanism argument if present. We have already
8494 -- checked that this is only allowed for the function case.
8496 if Present
(Arg_Result_Mechanism
) then
8497 Set_Mechanism_Value
(Ent
, Arg_Result_Mechanism
);
8500 -- Process Mechanism parameter if present. Note that this parameter
8501 -- is not analyzed, and must not be analyzed since it is semantic
8502 -- nonsense, so we get it in exactly as the parser left it.
8504 if Present
(Arg_Mechanism
) then
8512 -- A single mechanism association without a formal parameter
8513 -- name is parsed as a parenthesized expression. All other
8514 -- cases are parsed as aggregates, so we rewrite the single
8515 -- parameter case as an aggregate for consistency.
8517 if Nkind
(Arg_Mechanism
) /= N_Aggregate
8518 and then Paren_Count
(Arg_Mechanism
) = 1
8520 Rewrite
(Arg_Mechanism
,
8521 Make_Aggregate
(Sloc
(Arg_Mechanism
),
8522 Expressions
=> New_List
(
8523 Relocate_Node
(Arg_Mechanism
))));
8526 -- Case of only mechanism name given, applies to all formals
8528 if Nkind
(Arg_Mechanism
) /= N_Aggregate
then
8529 Formal
:= First_Formal
(Ent
);
8530 while Present
(Formal
) loop
8531 Set_Mechanism_Value
(Formal
, Arg_Mechanism
);
8532 Next_Formal
(Formal
);
8535 -- Case of list of mechanism associations given
8538 if Null_Record_Present
(Arg_Mechanism
) then
8540 ("inappropriate form for Mechanism parameter",
8544 -- Deal with positional ones first
8546 Formal
:= First_Formal
(Ent
);
8548 if Present
(Expressions
(Arg_Mechanism
)) then
8549 Mname
:= First
(Expressions
(Arg_Mechanism
));
8550 while Present
(Mname
) loop
8553 ("too many mechanism associations", Mname
);
8556 Set_Mechanism_Value
(Formal
, Mname
);
8557 Next_Formal
(Formal
);
8562 -- Deal with named entries
8564 if Present
(Component_Associations
(Arg_Mechanism
)) then
8565 Massoc
:= First
(Component_Associations
(Arg_Mechanism
));
8566 while Present
(Massoc
) loop
8567 Choice
:= First
(Choices
(Massoc
));
8569 if Nkind
(Choice
) /= N_Identifier
8570 or else Present
(Next
(Choice
))
8573 ("incorrect form for mechanism association",
8577 Formal
:= First_Formal
(Ent
);
8581 ("parameter name & not present", Choice
);
8584 if Chars
(Choice
) = Chars
(Formal
) then
8586 (Formal
, Expression
(Massoc
));
8588 -- Set entity on identifier (needed by ASIS)
8590 Set_Entity
(Choice
, Formal
);
8595 Next_Formal
(Formal
);
8604 end Process_Extended_Import_Export_Subprogram_Pragma
;
8606 --------------------------
8607 -- Process_Generic_List --
8608 --------------------------
8610 procedure Process_Generic_List
is
8615 Check_No_Identifiers
;
8616 Check_At_Least_N_Arguments
(1);
8618 -- Check all arguments are names of generic units or instances
8621 while Present
(Arg
) loop
8622 Exp
:= Get_Pragma_Arg
(Arg
);
8625 if not Is_Entity_Name
(Exp
)
8627 (not Is_Generic_Instance
(Entity
(Exp
))
8629 not Is_Generic_Unit
(Entity
(Exp
)))
8632 ("pragma% argument must be name of generic unit/instance",
8638 end Process_Generic_List
;
8640 ------------------------------------
8641 -- Process_Import_Predefined_Type --
8642 ------------------------------------
8644 procedure Process_Import_Predefined_Type
is
8645 Loc
: constant Source_Ptr
:= Sloc
(N
);
8647 Ftyp
: Node_Id
:= Empty
;
8653 Nam
:= String_To_Name
(Strval
(Expression
(Arg3
)));
8655 Elmt
:= First_Elmt
(Predefined_Float_Types
);
8656 while Present
(Elmt
) and then Chars
(Node
(Elmt
)) /= Nam
loop
8660 Ftyp
:= Node
(Elmt
);
8662 if Present
(Ftyp
) then
8664 -- Don't build a derived type declaration, because predefined C
8665 -- types have no declaration anywhere, so cannot really be named.
8666 -- Instead build a full type declaration, starting with an
8667 -- appropriate type definition is built
8669 if Is_Floating_Point_Type
(Ftyp
) then
8670 Def
:= Make_Floating_Point_Definition
(Loc
,
8671 Make_Integer_Literal
(Loc
, Digits_Value
(Ftyp
)),
8672 Make_Real_Range_Specification
(Loc
,
8673 Make_Real_Literal
(Loc
, Realval
(Type_Low_Bound
(Ftyp
))),
8674 Make_Real_Literal
(Loc
, Realval
(Type_High_Bound
(Ftyp
)))));
8676 -- Should never have a predefined type we cannot handle
8679 raise Program_Error
;
8682 -- Build and insert a Full_Type_Declaration, which will be
8683 -- analyzed as soon as this list entry has been analyzed.
8685 Decl
:= Make_Full_Type_Declaration
(Loc
,
8686 Make_Defining_Identifier
(Loc
, Chars
(Expression
(Arg2
))),
8687 Type_Definition
=> Def
);
8689 Insert_After
(N
, Decl
);
8690 Mark_Rewrite_Insertion
(Decl
);
8693 Error_Pragma_Arg
("no matching type found for pragma%",
8696 end Process_Import_Predefined_Type
;
8698 ---------------------------------
8699 -- Process_Import_Or_Interface --
8700 ---------------------------------
8702 procedure Process_Import_Or_Interface
is
8708 -- In Relaxed_RM_Semantics, support old Ada 83 style:
8709 -- pragma Import (Entity, "external name");
8711 if Relaxed_RM_Semantics
8712 and then Arg_Count
= 2
8713 and then Prag_Id
= Pragma_Import
8714 and then Nkind
(Expression
(Arg2
)) = N_String_Literal
8717 Def_Id
:= Get_Pragma_Arg
(Arg1
);
8720 if not Is_Entity_Name
(Def_Id
) then
8721 Error_Pragma_Arg
("entity name required", Arg1
);
8724 Def_Id
:= Entity
(Def_Id
);
8725 Kill_Size_Check_Code
(Def_Id
);
8726 Note_Possible_Modification
(Get_Pragma_Arg
(Arg1
), Sure
=> False);
8729 Process_Convention
(C
, Def_Id
);
8731 -- A pragma that applies to a Ghost entity becomes Ghost for the
8732 -- purposes of legality checks and removal of ignored Ghost code.
8734 Mark_Ghost_Pragma
(N
, Def_Id
);
8735 Kill_Size_Check_Code
(Def_Id
);
8736 Note_Possible_Modification
(Get_Pragma_Arg
(Arg2
), Sure
=> False);
8739 -- Various error checks
8741 if Ekind_In
(Def_Id
, E_Variable
, E_Constant
) then
8743 -- We do not permit Import to apply to a renaming declaration
8745 if Present
(Renamed_Object
(Def_Id
)) then
8747 ("pragma% not allowed for object renaming", Arg2
);
8749 -- User initialization is not allowed for imported object, but
8750 -- the object declaration may contain a default initialization,
8751 -- that will be discarded. Note that an explicit initialization
8752 -- only counts if it comes from source, otherwise it is simply
8753 -- the code generator making an implicit initialization explicit.
8755 elsif Present
(Expression
(Parent
(Def_Id
)))
8756 and then Comes_From_Source
8757 (Original_Node
(Expression
(Parent
(Def_Id
))))
8759 -- Set imported flag to prevent cascaded errors
8761 Set_Is_Imported
(Def_Id
);
8763 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8765 ("no initialization allowed for declaration of& #",
8766 "\imported entities cannot be initialized (RM B.1(24))",
8770 -- If the pragma comes from an aspect specification the
8771 -- Is_Imported flag has already been set.
8773 if not From_Aspect_Specification
(N
) then
8774 Set_Imported
(Def_Id
);
8777 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
, N
);
8779 -- Note that we do not set Is_Public here. That's because we
8780 -- only want to set it if there is no address clause, and we
8781 -- don't know that yet, so we delay that processing till
8784 -- pragma Import completes deferred constants
8786 if Ekind
(Def_Id
) = E_Constant
then
8787 Set_Has_Completion
(Def_Id
);
8790 -- It is not possible to import a constant of an unconstrained
8791 -- array type (e.g. string) because there is no simple way to
8792 -- write a meaningful subtype for it.
8794 if Is_Array_Type
(Etype
(Def_Id
))
8795 and then not Is_Constrained
(Etype
(Def_Id
))
8798 ("imported constant& must have a constrained subtype",
8803 elsif Is_Subprogram_Or_Generic_Subprogram
(Def_Id
) then
8805 -- If the name is overloaded, pragma applies to all of the denoted
8806 -- entities in the same declarative part, unless the pragma comes
8807 -- from an aspect specification or was generated by the compiler
8808 -- (such as for pragma Provide_Shift_Operators).
8811 while Present
(Hom_Id
) loop
8813 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
8815 -- Ignore inherited subprograms because the pragma will apply
8816 -- to the parent operation, which is the one called.
8818 if Is_Overloadable
(Def_Id
)
8819 and then Present
(Alias
(Def_Id
))
8823 -- If it is not a subprogram, it must be in an outer scope and
8824 -- pragma does not apply.
8826 elsif not Is_Subprogram_Or_Generic_Subprogram
(Def_Id
) then
8829 -- The pragma does not apply to primitives of interfaces
8831 elsif Is_Dispatching_Operation
(Def_Id
)
8832 and then Present
(Find_Dispatching_Type
(Def_Id
))
8833 and then Is_Interface
(Find_Dispatching_Type
(Def_Id
))
8837 -- Verify that the homonym is in the same declarative part (not
8838 -- just the same scope). If the pragma comes from an aspect
8839 -- specification we know that it is part of the declaration.
8841 elsif Parent
(Unit_Declaration_Node
(Def_Id
)) /= Parent
(N
)
8842 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit_Aux
8843 and then not From_Aspect_Specification
(N
)
8848 -- If the pragma comes from an aspect specification the
8849 -- Is_Imported flag has already been set.
8851 if not From_Aspect_Specification
(N
) then
8852 Set_Imported
(Def_Id
);
8855 -- Reject an Import applied to an abstract subprogram
8857 if Is_Subprogram
(Def_Id
)
8858 and then Is_Abstract_Subprogram
(Def_Id
)
8860 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8862 ("cannot import abstract subprogram& declared#",
8866 -- Special processing for Convention_Intrinsic
8868 if C
= Convention_Intrinsic
then
8870 -- Link_Name argument not allowed for intrinsic
8874 Set_Is_Intrinsic_Subprogram
(Def_Id
);
8876 -- If no external name is present, then check that this
8877 -- is a valid intrinsic subprogram. If an external name
8878 -- is present, then this is handled by the back end.
8881 Check_Intrinsic_Subprogram
8882 (Def_Id
, Get_Pragma_Arg
(Arg2
));
8886 -- Verify that the subprogram does not have a completion
8887 -- through a renaming declaration. For other completions the
8888 -- pragma appears as a too late representation.
8891 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Def_Id
);
8895 and then Nkind
(Decl
) = N_Subprogram_Declaration
8896 and then Present
(Corresponding_Body
(Decl
))
8897 and then Nkind
(Unit_Declaration_Node
8898 (Corresponding_Body
(Decl
))) =
8899 N_Subprogram_Renaming_Declaration
8901 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8903 ("cannot import&, renaming already provided for "
8904 & "declaration #", N
, Def_Id
);
8908 -- If the pragma comes from an aspect specification, there
8909 -- must be an Import aspect specified as well. In the rare
8910 -- case where Import is set to False, the suprogram needs to
8911 -- have a local completion.
8914 Imp_Aspect
: constant Node_Id
:=
8915 Find_Aspect
(Def_Id
, Aspect_Import
);
8919 if Present
(Imp_Aspect
)
8920 and then Present
(Expression
(Imp_Aspect
))
8922 Expr
:= Expression
(Imp_Aspect
);
8923 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
8925 if Is_Entity_Name
(Expr
)
8926 and then Entity
(Expr
) = Standard_True
8928 Set_Has_Completion
(Def_Id
);
8931 -- If there is no expression, the default is True, as for
8932 -- all boolean aspects. Same for the older pragma.
8935 Set_Has_Completion
(Def_Id
);
8939 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
, N
);
8942 if Is_Compilation_Unit
(Hom_Id
) then
8944 -- Its possible homonyms are not affected by the pragma.
8945 -- Such homonyms might be present in the context of other
8946 -- units being compiled.
8950 elsif From_Aspect_Specification
(N
) then
8953 -- If the pragma was created by the compiler, then we don't
8954 -- want it to apply to other homonyms. This kind of case can
8955 -- occur when using pragma Provide_Shift_Operators, which
8956 -- generates implicit shift and rotate operators with Import
8957 -- pragmas that might apply to earlier explicit or implicit
8958 -- declarations marked with Import (for example, coming from
8959 -- an earlier pragma Provide_Shift_Operators for another type),
8960 -- and we don't generally want other homonyms being treated
8961 -- as imported or the pragma flagged as an illegal duplicate.
8963 elsif not Comes_From_Source
(N
) then
8967 Hom_Id
:= Homonym
(Hom_Id
);
8971 -- Import a CPP class
8973 elsif C
= Convention_CPP
8974 and then (Is_Record_Type
(Def_Id
)
8975 or else Ekind
(Def_Id
) = E_Incomplete_Type
)
8977 if Ekind
(Def_Id
) = E_Incomplete_Type
then
8978 if Present
(Full_View
(Def_Id
)) then
8979 Def_Id
:= Full_View
(Def_Id
);
8983 ("cannot import 'C'P'P type before full declaration seen",
8984 Get_Pragma_Arg
(Arg2
));
8986 -- Although we have reported the error we decorate it as
8987 -- CPP_Class to avoid reporting spurious errors
8989 Set_Is_CPP_Class
(Def_Id
);
8994 -- Types treated as CPP classes must be declared limited (note:
8995 -- this used to be a warning but there is no real benefit to it
8996 -- since we did effectively intend to treat the type as limited
8999 if not Is_Limited_Type
(Def_Id
) then
9001 ("imported 'C'P'P type must be limited",
9002 Get_Pragma_Arg
(Arg2
));
9005 if Etype
(Def_Id
) /= Def_Id
9006 and then not Is_CPP_Class
(Root_Type
(Def_Id
))
9008 Error_Msg_N
("root type must be a 'C'P'P type", Arg1
);
9011 Set_Is_CPP_Class
(Def_Id
);
9013 -- Imported CPP types must not have discriminants (because C++
9014 -- classes do not have discriminants).
9016 if Has_Discriminants
(Def_Id
) then
9018 ("imported 'C'P'P type cannot have discriminants",
9019 First
(Discriminant_Specifications
9020 (Declaration_Node
(Def_Id
))));
9023 -- Check that components of imported CPP types do not have default
9024 -- expressions. For private types this check is performed when the
9025 -- full view is analyzed (see Process_Full_View).
9027 if not Is_Private_Type
(Def_Id
) then
9028 Check_CPP_Type_Has_No_Defaults
(Def_Id
);
9031 -- Import a CPP exception
9033 elsif C
= Convention_CPP
9034 and then Ekind
(Def_Id
) = E_Exception
9038 ("'External_'Name arguments is required for 'Cpp exception",
9041 -- As only a string is allowed, Check_Arg_Is_External_Name
9044 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
9047 if Present
(Arg4
) then
9049 ("Link_Name argument not allowed for imported Cpp exception",
9053 -- Do not call Set_Interface_Name as the name of the exception
9054 -- shouldn't be modified (and in particular it shouldn't be
9055 -- the External_Name). For exceptions, the External_Name is the
9056 -- name of the RTTI structure.
9058 -- ??? Emit an error if pragma Import/Export_Exception is present
9060 elsif Nkind
(Parent
(Def_Id
)) = N_Incomplete_Type_Declaration
then
9062 Check_Arg_Count
(3);
9063 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
9065 Process_Import_Predefined_Type
;
9069 ("second argument of pragma% must be object, subprogram "
9070 & "or incomplete type",
9074 -- If this pragma applies to a compilation unit, then the unit, which
9075 -- is a subprogram, does not require (or allow) a body. We also do
9076 -- not need to elaborate imported procedures.
9078 if Nkind
(Parent
(N
)) = N_Compilation_Unit_Aux
then
9080 Cunit
: constant Node_Id
:= Parent
(Parent
(N
));
9082 Set_Body_Required
(Cunit
, False);
9085 end Process_Import_Or_Interface
;
9087 --------------------
9088 -- Process_Inline --
9089 --------------------
9091 procedure Process_Inline
(Status
: Inline_Status
) is
9098 Ghost_Error_Posted
: Boolean := False;
9099 -- Flag set when an error concerning the illegal mix of Ghost and
9100 -- non-Ghost subprograms is emitted.
9102 Ghost_Id
: Entity_Id
:= Empty
;
9103 -- The entity of the first Ghost subprogram encountered while
9104 -- processing the arguments of the pragma.
9106 procedure Check_Inline_Always_Placement
(Spec_Id
: Entity_Id
);
9107 -- Verify the placement of pragma Inline_Always with respect to the
9108 -- initial declaration of subprogram Spec_Id.
9110 function Inlining_Not_Possible
(Subp
: Entity_Id
) return Boolean;
9111 -- Returns True if it can be determined at this stage that inlining
9112 -- is not possible, for example if the body is available and contains
9113 -- exception handlers, we prevent inlining, since otherwise we can
9114 -- get undefined symbols at link time. This function also emits a
9115 -- warning if the pragma appears too late.
9117 -- ??? is business with link symbols still valid, or does it relate
9118 -- to front end ZCX which is being phased out ???
9120 procedure Make_Inline
(Subp
: Entity_Id
);
9121 -- Subp is the defining unit name of the subprogram declaration. If
9122 -- the pragma is valid, call Set_Inline_Flags on Subp, as well as on
9123 -- the corresponding body, if there is one present.
9125 procedure Set_Inline_Flags
(Subp
: Entity_Id
);
9126 -- Set Has_Pragma_{No_Inline,Inline,Inline_Always} flag on Subp.
9127 -- Also set or clear Is_Inlined flag on Subp depending on Status.
9129 -----------------------------------
9130 -- Check_Inline_Always_Placement --
9131 -----------------------------------
9133 procedure Check_Inline_Always_Placement
(Spec_Id
: Entity_Id
) is
9134 Spec_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Spec_Id
);
9136 function Compilation_Unit_OK
return Boolean;
9137 pragma Inline
(Compilation_Unit_OK
);
9138 -- Determine whether pragma Inline_Always applies to a compatible
9139 -- compilation unit denoted by Spec_Id.
9141 function Declarative_List_OK
return Boolean;
9142 pragma Inline
(Declarative_List_OK
);
9143 -- Determine whether the initial declaration of subprogram Spec_Id
9144 -- and the pragma appear in compatible declarative lists.
9146 function Subprogram_Body_OK
return Boolean;
9147 pragma Inline
(Subprogram_Body_OK
);
9148 -- Determine whether pragma Inline_Always applies to a compatible
9149 -- subprogram body denoted by Spec_Id.
9151 -------------------------
9152 -- Compilation_Unit_OK --
9153 -------------------------
9155 function Compilation_Unit_OK
return Boolean is
9156 Comp_Unit
: constant Node_Id
:= Parent
(Spec_Decl
);
9159 -- The pragma appears after the initial declaration of a
9160 -- compilation unit.
9162 -- procedure Comp_Unit;
9163 -- pragma Inline_Always (Comp_Unit);
9165 -- Note that for compatibility reasons, the following case is
9168 -- procedure Stand_Alone_Body_Comp_Unit is
9170 -- end Stand_Alone_Body_Comp_Unit;
9171 -- pragma Inline_Always (Stand_Alone_Body_Comp_Unit);
9174 Nkind
(Comp_Unit
) = N_Compilation_Unit
9175 and then Present
(Aux_Decls_Node
(Comp_Unit
))
9176 and then Is_List_Member
(N
)
9177 and then List_Containing
(N
) =
9178 Pragmas_After
(Aux_Decls_Node
(Comp_Unit
));
9179 end Compilation_Unit_OK
;
9181 -------------------------
9182 -- Declarative_List_OK --
9183 -------------------------
9185 function Declarative_List_OK
return Boolean is
9186 Context
: constant Node_Id
:= Parent
(Spec_Decl
);
9188 Init_Decl
: Node_Id
;
9189 Init_List
: List_Id
;
9190 Prag_List
: List_Id
;
9193 -- Determine the proper initial declaration. In general this is
9194 -- the declaration node of the subprogram except when the input
9195 -- denotes a generic instantiation.
9197 -- procedure Inst is new Gen;
9198 -- pragma Inline_Always (Inst);
9200 -- In this case the original subprogram is moved inside an
9201 -- anonymous package while pragma Inline_Always remains at the
9202 -- level of the anonymous package. Use the declaration of the
9203 -- package because it reflects the placement of the original
9206 -- package Anon_Pack is
9207 -- procedure Inst is ... end Inst; -- original
9210 -- procedure Inst renames Anon_Pack.Inst;
9211 -- pragma Inline_Always (Inst);
9213 if Is_Generic_Instance
(Spec_Id
) then
9214 Init_Decl
:= Parent
(Parent
(Spec_Decl
));
9215 pragma Assert
(Nkind
(Init_Decl
) = N_Package_Declaration
);
9217 Init_Decl
:= Spec_Decl
;
9220 if Is_List_Member
(Init_Decl
) and then Is_List_Member
(N
) then
9221 Init_List
:= List_Containing
(Init_Decl
);
9222 Prag_List
:= List_Containing
(N
);
9224 -- The pragma and then initial declaration appear within the
9225 -- same declarative list.
9227 if Init_List
= Prag_List
then
9230 -- A special case of the above is when both the pragma and
9231 -- the initial declaration appear in different lists of a
9232 -- package spec, protected definition, or a task definition.
9237 -- pragma Inline_Always (Proc);
9240 elsif Nkind_In
(Context
, N_Package_Specification
,
9241 N_Protected_Definition
,
9243 and then Init_List
= Visible_Declarations
(Context
)
9244 and then Prag_List
= Private_Declarations
(Context
)
9251 end Declarative_List_OK
;
9253 ------------------------
9254 -- Subprogram_Body_OK --
9255 ------------------------
9257 function Subprogram_Body_OK
return Boolean is
9258 Body_Decl
: Node_Id
;
9261 -- The pragma appears within the declarative list of a stand-
9262 -- alone subprogram body.
9264 -- procedure Stand_Alone_Body is
9265 -- pragma Inline_Always (Stand_Alone_Body);
9268 -- end Stand_Alone_Body;
9270 -- The compiler creates a dummy spec in this case, however the
9271 -- pragma remains within the declarative list of the body.
9273 if Nkind
(Spec_Decl
) = N_Subprogram_Declaration
9274 and then not Comes_From_Source
(Spec_Decl
)
9275 and then Present
(Corresponding_Body
(Spec_Decl
))
9278 Unit_Declaration_Node
(Corresponding_Body
(Spec_Decl
));
9280 if Present
(Declarations
(Body_Decl
))
9281 and then Is_List_Member
(N
)
9282 and then List_Containing
(N
) = Declarations
(Body_Decl
)
9289 end Subprogram_Body_OK
;
9291 -- Start of processing for Check_Inline_Always_Placement
9294 -- This check is relevant only for pragma Inline_Always
9296 if Pname
/= Name_Inline_Always
then
9299 -- Nothing to do when the pragma is internally generated on the
9300 -- assumption that it is properly placed.
9302 elsif not Comes_From_Source
(N
) then
9305 -- Nothing to do for internally generated subprograms that act
9306 -- as accidental homonyms of a source subprogram being inlined.
9308 elsif not Comes_From_Source
(Spec_Id
) then
9311 -- Nothing to do for generic formal subprograms that act as
9312 -- homonyms of another source subprogram being inlined.
9314 elsif Is_Formal_Subprogram
(Spec_Id
) then
9317 elsif Compilation_Unit_OK
9318 or else Declarative_List_OK
9319 or else Subprogram_Body_OK
9324 -- At this point it is known that the pragma applies to or appears
9325 -- within a completing body, a completing stub, or a subunit.
9327 Error_Msg_Name_1
:= Pname
;
9328 Error_Msg_Name_2
:= Chars
(Spec_Id
);
9329 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
9332 ("pragma % must appear on initial declaration of subprogram "
9333 & "% defined #", N
);
9334 end Check_Inline_Always_Placement
;
9336 ---------------------------
9337 -- Inlining_Not_Possible --
9338 ---------------------------
9340 function Inlining_Not_Possible
(Subp
: Entity_Id
) return Boolean is
9341 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
9345 if Nkind
(Decl
) = N_Subprogram_Body
then
9346 Stats
:= Handled_Statement_Sequence
(Decl
);
9347 return Present
(Exception_Handlers
(Stats
))
9348 or else Present
(At_End_Proc
(Stats
));
9350 elsif Nkind
(Decl
) = N_Subprogram_Declaration
9351 and then Present
(Corresponding_Body
(Decl
))
9353 if Analyzed
(Corresponding_Body
(Decl
)) then
9354 Error_Msg_N
("pragma appears too late, ignored??", N
);
9357 -- If the subprogram is a renaming as body, the body is just a
9358 -- call to the renamed subprogram, and inlining is trivially
9362 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
))) =
9363 N_Subprogram_Renaming_Declaration
9369 Handled_Statement_Sequence
9370 (Unit_Declaration_Node
(Corresponding_Body
(Decl
)));
9373 Present
(Exception_Handlers
(Stats
))
9374 or else Present
(At_End_Proc
(Stats
));
9378 -- If body is not available, assume the best, the check is
9379 -- performed again when compiling enclosing package bodies.
9383 end Inlining_Not_Possible
;
9389 procedure Make_Inline
(Subp
: Entity_Id
) is
9390 Kind
: constant Entity_Kind
:= Ekind
(Subp
);
9391 Inner_Subp
: Entity_Id
:= Subp
;
9394 -- Ignore if bad type, avoid cascaded error
9396 if Etype
(Subp
) = Any_Type
then
9400 -- If inlining is not possible, for now do not treat as an error
9402 elsif Status
/= Suppressed
9403 and then Front_End_Inlining
9404 and then Inlining_Not_Possible
(Subp
)
9409 -- Here we have a candidate for inlining, but we must exclude
9410 -- derived operations. Otherwise we would end up trying to inline
9411 -- a phantom declaration, and the result would be to drag in a
9412 -- body which has no direct inlining associated with it. That
9413 -- would not only be inefficient but would also result in the
9414 -- backend doing cross-unit inlining in cases where it was
9415 -- definitely inappropriate to do so.
9417 -- However, a simple Comes_From_Source test is insufficient, since
9418 -- we do want to allow inlining of generic instances which also do
9419 -- not come from source. We also need to recognize specs generated
9420 -- by the front-end for bodies that carry the pragma. Finally,
9421 -- predefined operators do not come from source but are not
9422 -- inlineable either.
9424 elsif Is_Generic_Instance
(Subp
)
9425 or else Nkind
(Parent
(Parent
(Subp
))) = N_Subprogram_Declaration
9429 elsif not Comes_From_Source
(Subp
)
9430 and then Scope
(Subp
) /= Standard_Standard
9436 -- The referenced entity must either be the enclosing entity, or
9437 -- an entity declared within the current open scope.
9439 if Present
(Scope
(Subp
))
9440 and then Scope
(Subp
) /= Current_Scope
9441 and then Subp
/= Current_Scope
9444 ("argument of% must be entity in current scope", Assoc
);
9448 -- Processing for procedure, operator or function. If subprogram
9449 -- is aliased (as for an instance) indicate that the renamed
9450 -- entity (if declared in the same unit) is inlined.
9451 -- If this is the anonymous subprogram created for a subprogram
9452 -- instance, the inlining applies to it directly. Otherwise we
9453 -- retrieve it as the alias of the visible subprogram instance.
9455 if Is_Subprogram
(Subp
) then
9457 -- Ensure that pragma Inline_Always is associated with the
9458 -- initial declaration of the subprogram.
9460 Check_Inline_Always_Placement
(Subp
);
9462 if Is_Wrapper_Package
(Scope
(Subp
)) then
9465 Inner_Subp
:= Ultimate_Alias
(Inner_Subp
);
9468 if In_Same_Source_Unit
(Subp
, Inner_Subp
) then
9469 Set_Inline_Flags
(Inner_Subp
);
9471 Decl
:= Parent
(Parent
(Inner_Subp
));
9473 if Nkind
(Decl
) = N_Subprogram_Declaration
9474 and then Present
(Corresponding_Body
(Decl
))
9476 Set_Inline_Flags
(Corresponding_Body
(Decl
));
9478 elsif Is_Generic_Instance
(Subp
)
9479 and then Comes_From_Source
(Subp
)
9481 -- Indicate that the body needs to be created for
9482 -- inlining subsequent calls. The instantiation node
9483 -- follows the declaration of the wrapper package
9484 -- created for it. The subprogram that requires the
9485 -- body is the anonymous one in the wrapper package.
9487 if Scope
(Subp
) /= Standard_Standard
9489 Need_Subprogram_Instance_Body
9490 (Next
(Unit_Declaration_Node
9491 (Scope
(Alias
(Subp
)))), Subp
)
9496 -- Inline is a program unit pragma (RM 10.1.5) and cannot
9497 -- appear in a formal part to apply to a formal subprogram.
9498 -- Do not apply check within an instance or a formal package
9499 -- the test will have been applied to the original generic.
9501 elsif Nkind
(Decl
) in N_Formal_Subprogram_Declaration
9502 and then List_Containing
(Decl
) = List_Containing
(N
)
9503 and then not In_Instance
9506 ("Inline cannot apply to a formal subprogram", N
);
9508 -- If Subp is a renaming, it is the renamed entity that
9509 -- will appear in any call, and be inlined. However, for
9510 -- ASIS uses it is convenient to indicate that the renaming
9511 -- itself is an inlined subprogram, so that some gnatcheck
9512 -- rules can be applied in the absence of expansion.
9514 elsif Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
9515 Set_Inline_Flags
(Subp
);
9521 -- For a generic subprogram set flag as well, for use at the point
9522 -- of instantiation, to determine whether the body should be
9525 elsif Is_Generic_Subprogram
(Subp
) then
9526 Set_Inline_Flags
(Subp
);
9529 -- Literals are by definition inlined
9531 elsif Kind
= E_Enumeration_Literal
then
9534 -- Anything else is an error
9538 ("expect subprogram name for pragma%", Assoc
);
9542 ----------------------
9543 -- Set_Inline_Flags --
9544 ----------------------
9546 procedure Set_Inline_Flags
(Subp
: Entity_Id
) is
9548 -- First set the Has_Pragma_XXX flags and issue the appropriate
9549 -- errors and warnings for suspicious combinations.
9551 if Prag_Id
= Pragma_No_Inline
then
9552 if Has_Pragma_Inline_Always
(Subp
) then
9554 ("Inline_Always and No_Inline are mutually exclusive", N
);
9555 elsif Has_Pragma_Inline
(Subp
) then
9557 ("Inline and No_Inline both specified for& ??",
9558 N
, Entity
(Subp_Id
));
9561 Set_Has_Pragma_No_Inline
(Subp
);
9563 if Prag_Id
= Pragma_Inline_Always
then
9564 if Has_Pragma_No_Inline
(Subp
) then
9566 ("Inline_Always and No_Inline are mutually exclusive",
9570 Set_Has_Pragma_Inline_Always
(Subp
);
9572 if Has_Pragma_No_Inline
(Subp
) then
9574 ("Inline and No_Inline both specified for& ??",
9575 N
, Entity
(Subp_Id
));
9579 Set_Has_Pragma_Inline
(Subp
);
9582 -- Then adjust the Is_Inlined flag. It can never be set if the
9583 -- subprogram is subject to pragma No_Inline.
9587 Set_Is_Inlined
(Subp
, False);
9593 if not Has_Pragma_No_Inline
(Subp
) then
9594 Set_Is_Inlined
(Subp
, True);
9598 -- A pragma that applies to a Ghost entity becomes Ghost for the
9599 -- purposes of legality checks and removal of ignored Ghost code.
9601 Mark_Ghost_Pragma
(N
, Subp
);
9603 -- Capture the entity of the first Ghost subprogram being
9604 -- processed for error detection purposes.
9606 if Is_Ghost_Entity
(Subp
) then
9607 if No
(Ghost_Id
) then
9611 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
9612 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
9614 elsif Present
(Ghost_Id
) and then not Ghost_Error_Posted
then
9615 Ghost_Error_Posted
:= True;
9617 Error_Msg_Name_1
:= Pname
;
9619 ("pragma % cannot mention ghost and non-ghost subprograms",
9622 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
9623 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
9625 Error_Msg_Sloc
:= Sloc
(Subp
);
9626 Error_Msg_NE
("\& # declared as non-ghost", N
, Subp
);
9628 end Set_Inline_Flags
;
9630 -- Start of processing for Process_Inline
9633 Check_No_Identifiers
;
9634 Check_At_Least_N_Arguments
(1);
9636 if Status
= Enabled
then
9637 Inline_Processing_Required
:= True;
9641 while Present
(Assoc
) loop
9642 Subp_Id
:= Get_Pragma_Arg
(Assoc
);
9646 if Is_Entity_Name
(Subp_Id
) then
9647 Subp
:= Entity
(Subp_Id
);
9649 if Subp
= Any_Id
then
9651 -- If previous error, avoid cascaded errors
9653 Check_Error_Detected
;
9659 -- For the pragma case, climb homonym chain. This is
9660 -- what implements allowing the pragma in the renaming
9661 -- case, with the result applying to the ancestors, and
9662 -- also allows Inline to apply to all previous homonyms.
9664 if not From_Aspect_Specification
(N
) then
9665 while Present
(Homonym
(Subp
))
9666 and then Scope
(Homonym
(Subp
)) = Current_Scope
9668 Make_Inline
(Homonym
(Subp
));
9669 Subp
:= Homonym
(Subp
);
9676 Error_Pragma_Arg
("inappropriate argument for pragma%", Assoc
);
9682 -- If the context is a package declaration, the pragma indicates
9683 -- that inlining will require the presence of the corresponding
9684 -- body. (this may be further refined).
9687 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) =
9688 N_Package_Declaration
9690 Set_Body_Needed_For_Inlining
(Cunit_Entity
(Current_Sem_Unit
));
9694 ----------------------------
9695 -- Process_Interface_Name --
9696 ----------------------------
9698 procedure Process_Interface_Name
9699 (Subprogram_Def
: Entity_Id
;
9706 String_Val
: String_Id
;
9708 procedure Check_Form_Of_Interface_Name
(SN
: Node_Id
);
9709 -- SN is a string literal node for an interface name. This routine
9710 -- performs some minimal checks that the name is reasonable. In
9711 -- particular that no spaces or other obviously incorrect characters
9712 -- appear. This is only a warning, since any characters are allowed.
9714 ----------------------------------
9715 -- Check_Form_Of_Interface_Name --
9716 ----------------------------------
9718 procedure Check_Form_Of_Interface_Name
(SN
: Node_Id
) is
9719 S
: constant String_Id
:= Strval
(Expr_Value_S
(SN
));
9720 SL
: constant Nat
:= String_Length
(S
);
9725 Error_Msg_N
("interface name cannot be null string", SN
);
9728 for J
in 1 .. SL
loop
9729 C
:= Get_String_Char
(S
, J
);
9731 -- Look for dubious character and issue unconditional warning.
9732 -- Definitely dubious if not in character range.
9734 if not In_Character_Range
(C
)
9736 -- Commas, spaces and (back)slashes are dubious
9738 or else Get_Character
(C
) = ','
9739 or else Get_Character
(C
) = '\'
9740 or else Get_Character
(C
) = ' '
9741 or else Get_Character
(C
) = '/'
9744 ("??interface name contains illegal character",
9745 Sloc
(SN
) + Source_Ptr
(J
));
9748 end Check_Form_Of_Interface_Name
;
9750 -- Start of processing for Process_Interface_Name
9753 -- If we are looking at a pragma that comes from an aspect then it
9754 -- needs to have its corresponding aspect argument expressions
9755 -- analyzed in addition to the generated pragma so that aspects
9756 -- within generic units get properly resolved.
9758 if Present
(Prag
) and then From_Aspect_Specification
(Prag
) then
9760 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
9768 -- Obtain all interfacing aspects used to construct the pragma
9770 Get_Interfacing_Aspects
9771 (Asp
, Dummy_1
, EN
, Dummy_2
, Dummy_3
, LN
);
9773 -- Analyze the expression of aspect External_Name
9775 if Present
(EN
) then
9776 Analyze
(Expression
(EN
));
9779 -- Analyze the expressio of aspect Link_Name
9781 if Present
(LN
) then
9782 Analyze
(Expression
(LN
));
9787 if No
(Link_Arg
) then
9788 if No
(Ext_Arg
) then
9791 elsif Chars
(Ext_Arg
) = Name_Link_Name
then
9793 Link_Nam
:= Expression
(Ext_Arg
);
9796 Check_Optional_Identifier
(Ext_Arg
, Name_External_Name
);
9797 Ext_Nam
:= Expression
(Ext_Arg
);
9802 Check_Optional_Identifier
(Ext_Arg
, Name_External_Name
);
9803 Check_Optional_Identifier
(Link_Arg
, Name_Link_Name
);
9804 Ext_Nam
:= Expression
(Ext_Arg
);
9805 Link_Nam
:= Expression
(Link_Arg
);
9808 -- Check expressions for external name and link name are static
9810 if Present
(Ext_Nam
) then
9811 Check_Arg_Is_OK_Static_Expression
(Ext_Nam
, Standard_String
);
9812 Check_Form_Of_Interface_Name
(Ext_Nam
);
9814 -- Verify that external name is not the name of a local entity,
9815 -- which would hide the imported one and could lead to run-time
9816 -- surprises. The problem can only arise for entities declared in
9817 -- a package body (otherwise the external name is fully qualified
9818 -- and will not conflict).
9826 if Prag_Id
= Pragma_Import
then
9827 Nam
:= String_To_Name
(Strval
(Expr_Value_S
(Ext_Nam
)));
9828 E
:= Entity_Id
(Get_Name_Table_Int
(Nam
));
9830 if Nam
/= Chars
(Subprogram_Def
)
9831 and then Present
(E
)
9832 and then not Is_Overloadable
(E
)
9833 and then Is_Immediately_Visible
(E
)
9834 and then not Is_Imported
(E
)
9835 and then Ekind
(Scope
(E
)) = E_Package
9838 while Present
(Par
) loop
9839 if Nkind
(Par
) = N_Package_Body
then
9840 Error_Msg_Sloc
:= Sloc
(E
);
9842 ("imported entity is hidden by & declared#",
9847 Par
:= Parent
(Par
);
9854 if Present
(Link_Nam
) then
9855 Check_Arg_Is_OK_Static_Expression
(Link_Nam
, Standard_String
);
9856 Check_Form_Of_Interface_Name
(Link_Nam
);
9859 -- If there is no link name, just set the external name
9861 if No
(Link_Nam
) then
9862 Link_Nam
:= Adjust_External_Name_Case
(Expr_Value_S
(Ext_Nam
));
9864 -- For the Link_Name case, the given literal is preceded by an
9865 -- asterisk, which indicates to GCC that the given name should be
9866 -- taken literally, and in particular that no prepending of
9867 -- underlines should occur, even in systems where this is the
9872 Store_String_Char
(Get_Char_Code
('*'));
9873 String_Val
:= Strval
(Expr_Value_S
(Link_Nam
));
9874 Store_String_Chars
(String_Val
);
9876 Make_String_Literal
(Sloc
(Link_Nam
),
9877 Strval
=> End_String
);
9880 -- Set the interface name. If the entity is a generic instance, use
9881 -- its alias, which is the callable entity.
9883 if Is_Generic_Instance
(Subprogram_Def
) then
9884 Set_Encoded_Interface_Name
9885 (Alias
(Get_Base_Subprogram
(Subprogram_Def
)), Link_Nam
);
9887 Set_Encoded_Interface_Name
9888 (Get_Base_Subprogram
(Subprogram_Def
), Link_Nam
);
9891 Check_Duplicated_Export_Name
(Link_Nam
);
9892 end Process_Interface_Name
;
9894 -----------------------------------------
9895 -- Process_Interrupt_Or_Attach_Handler --
9896 -----------------------------------------
9898 procedure Process_Interrupt_Or_Attach_Handler
is
9899 Handler
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
9900 Prot_Typ
: constant Entity_Id
:= Scope
(Handler
);
9903 -- A pragma that applies to a Ghost entity becomes Ghost for the
9904 -- purposes of legality checks and removal of ignored Ghost code.
9906 Mark_Ghost_Pragma
(N
, Handler
);
9907 Set_Is_Interrupt_Handler
(Handler
);
9909 pragma Assert
(Ekind
(Prot_Typ
) = E_Protected_Type
);
9911 Record_Rep_Item
(Prot_Typ
, N
);
9913 -- Chain the pragma on the contract for completeness
9915 Add_Contract_Item
(N
, Handler
);
9916 end Process_Interrupt_Or_Attach_Handler
;
9918 --------------------------------------------------
9919 -- Process_Restrictions_Or_Restriction_Warnings --
9920 --------------------------------------------------
9922 -- Note: some of the simple identifier cases were handled in par-prag,
9923 -- but it is harmless (and more straightforward) to simply handle all
9924 -- cases here, even if it means we repeat a bit of work in some cases.
9926 procedure Process_Restrictions_Or_Restriction_Warnings
9930 R_Id
: Restriction_Id
;
9936 -- Ignore all Restrictions pragmas in CodePeer mode
9938 if CodePeer_Mode
then
9942 Check_Ada_83_Warning
;
9943 Check_At_Least_N_Arguments
(1);
9944 Check_Valid_Configuration_Pragma
;
9947 while Present
(Arg
) loop
9949 Expr
:= Get_Pragma_Arg
(Arg
);
9951 -- Case of no restriction identifier present
9953 if Id
= No_Name
then
9954 if Nkind
(Expr
) /= N_Identifier
then
9956 ("invalid form for restriction", Arg
);
9961 (Process_Restriction_Synonyms
(Expr
));
9963 if R_Id
not in All_Boolean_Restrictions
then
9964 Error_Msg_Name_1
:= Pname
;
9966 ("invalid restriction identifier&", Get_Pragma_Arg
(Arg
));
9968 -- Check for possible misspelling
9970 for J
in Restriction_Id
loop
9972 Rnm
: constant String := Restriction_Id
'Image (J
);
9975 Name_Buffer
(1 .. Rnm
'Length) := Rnm
;
9976 Name_Len
:= Rnm
'Length;
9977 Set_Casing
(All_Lower_Case
);
9979 if Is_Bad_Spelling_Of
(Chars
(Expr
), Name_Enter
) then
9982 (Source_Index
(Current_Sem_Unit
)));
9983 Error_Msg_String
(1 .. Rnm
'Length) :=
9984 Name_Buffer
(1 .. Name_Len
);
9985 Error_Msg_Strlen
:= Rnm
'Length;
9986 Error_Msg_N
-- CODEFIX
9987 ("\possible misspelling of ""~""",
9988 Get_Pragma_Arg
(Arg
));
9997 if Implementation_Restriction
(R_Id
) then
9998 Check_Restriction
(No_Implementation_Restrictions
, Arg
);
10001 -- Special processing for No_Elaboration_Code restriction
10003 if R_Id
= No_Elaboration_Code
then
10005 -- Restriction is only recognized within a configuration
10006 -- pragma file, or within a unit of the main extended
10007 -- program. Note: the test for Main_Unit is needed to
10008 -- properly include the case of configuration pragma files.
10010 if not (Current_Sem_Unit
= Main_Unit
10011 or else In_Extended_Main_Source_Unit
(N
))
10015 -- Don't allow in a subunit unless already specified in
10018 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
10019 and then Nkind
(Unit
(Parent
(N
))) = N_Subunit
10020 and then not Restriction_Active
(No_Elaboration_Code
)
10023 ("invalid specification of ""No_Elaboration_Code""",
10026 ("\restriction cannot be specified in a subunit", N
);
10028 ("\unless also specified in body or spec", N
);
10031 -- If we accept a No_Elaboration_Code restriction, then it
10032 -- needs to be added to the configuration restriction set so
10033 -- that we get proper application to other units in the main
10034 -- extended source as required.
10037 Add_To_Config_Boolean_Restrictions
(No_Elaboration_Code
);
10041 -- If this is a warning, then set the warning unless we already
10042 -- have a real restriction active (we never want a warning to
10043 -- override a real restriction).
10046 if not Restriction_Active
(R_Id
) then
10047 Set_Restriction
(R_Id
, N
);
10048 Restriction_Warnings
(R_Id
) := True;
10051 -- If real restriction case, then set it and make sure that the
10052 -- restriction warning flag is off, since a real restriction
10053 -- always overrides a warning.
10056 Set_Restriction
(R_Id
, N
);
10057 Restriction_Warnings
(R_Id
) := False;
10060 -- Check for obsolescent restrictions in Ada 2005 mode
10063 and then Ada_Version
>= Ada_2005
10064 and then (R_Id
= No_Asynchronous_Control
10066 R_Id
= No_Unchecked_Deallocation
10068 R_Id
= No_Unchecked_Conversion
)
10070 Check_Restriction
(No_Obsolescent_Features
, N
);
10073 -- A very special case that must be processed here: pragma
10074 -- Restrictions (No_Exceptions) turns off all run-time
10075 -- checking. This is a bit dubious in terms of the formal
10076 -- language definition, but it is what is intended by RM
10077 -- H.4(12). Restriction_Warnings never affects generated code
10078 -- so this is done only in the real restriction case.
10080 -- Atomic_Synchronization is not a real check, so it is not
10081 -- affected by this processing).
10083 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
10084 -- run-time checks in CodePeer and GNATprove modes: we want to
10085 -- generate checks for analysis purposes, as set respectively
10086 -- by -gnatC and -gnatd.F
10089 and then not (CodePeer_Mode
or GNATprove_Mode
)
10090 and then R_Id
= No_Exceptions
10092 for J
in Scope_Suppress
.Suppress
'Range loop
10093 if J
/= Atomic_Synchronization
then
10094 Scope_Suppress
.Suppress
(J
) := True;
10099 -- Case of No_Dependence => unit-name. Note that the parser
10100 -- already made the necessary entry in the No_Dependence table.
10102 elsif Id
= Name_No_Dependence
then
10103 if not OK_No_Dependence_Unit_Name
(Expr
) then
10107 -- Case of No_Specification_Of_Aspect => aspect-identifier
10109 elsif Id
= Name_No_Specification_Of_Aspect
then
10114 if Nkind
(Expr
) /= N_Identifier
then
10117 A_Id
:= Get_Aspect_Id
(Chars
(Expr
));
10120 if A_Id
= No_Aspect
then
10121 Error_Pragma_Arg
("invalid restriction name", Arg
);
10123 Set_Restriction_No_Specification_Of_Aspect
(Expr
, Warn
);
10127 -- Case of No_Use_Of_Attribute => attribute-identifier
10129 elsif Id
= Name_No_Use_Of_Attribute
then
10130 if Nkind
(Expr
) /= N_Identifier
10131 or else not Is_Attribute_Name
(Chars
(Expr
))
10133 Error_Msg_N
("unknown attribute name??", Expr
);
10136 Set_Restriction_No_Use_Of_Attribute
(Expr
, Warn
);
10139 -- Case of No_Use_Of_Entity => fully-qualified-name
10141 elsif Id
= Name_No_Use_Of_Entity
then
10143 -- Restriction is only recognized within a configuration
10144 -- pragma file, or within a unit of the main extended
10145 -- program. Note: the test for Main_Unit is needed to
10146 -- properly include the case of configuration pragma files.
10148 if Current_Sem_Unit
= Main_Unit
10149 or else In_Extended_Main_Source_Unit
(N
)
10151 if not OK_No_Dependence_Unit_Name
(Expr
) then
10152 Error_Msg_N
("wrong form for entity name", Expr
);
10154 Set_Restriction_No_Use_Of_Entity
10155 (Expr
, Warn
, No_Profile
);
10159 -- Case of No_Use_Of_Pragma => pragma-identifier
10161 elsif Id
= Name_No_Use_Of_Pragma
then
10162 if Nkind
(Expr
) /= N_Identifier
10163 or else not Is_Pragma_Name
(Chars
(Expr
))
10165 Error_Msg_N
("unknown pragma name??", Expr
);
10167 Set_Restriction_No_Use_Of_Pragma
(Expr
, Warn
);
10170 -- All other cases of restriction identifier present
10173 R_Id
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(Arg
));
10174 Analyze_And_Resolve
(Expr
, Any_Integer
);
10176 if R_Id
not in All_Parameter_Restrictions
then
10178 ("invalid restriction parameter identifier", Arg
);
10180 elsif not Is_OK_Static_Expression
(Expr
) then
10181 Flag_Non_Static_Expr
10182 ("value must be static expression!", Expr
);
10185 elsif not Is_Integer_Type
(Etype
(Expr
))
10186 or else Expr_Value
(Expr
) < 0
10189 ("value must be non-negative integer", Arg
);
10192 -- Restriction pragma is active
10194 Val
:= Expr_Value
(Expr
);
10196 if not UI_Is_In_Int_Range
(Val
) then
10198 ("pragma ignored, value too large??", Arg
);
10201 -- Warning case. If the real restriction is active, then we
10202 -- ignore the request, since warning never overrides a real
10203 -- restriction. Otherwise we set the proper warning. Note that
10204 -- this circuit sets the warning again if it is already set,
10205 -- which is what we want, since the constant may have changed.
10208 if not Restriction_Active
(R_Id
) then
10210 (R_Id
, N
, Integer (UI_To_Int
(Val
)));
10211 Restriction_Warnings
(R_Id
) := True;
10214 -- Real restriction case, set restriction and make sure warning
10215 -- flag is off since real restriction always overrides warning.
10218 Set_Restriction
(R_Id
, N
, Integer (UI_To_Int
(Val
)));
10219 Restriction_Warnings
(R_Id
) := False;
10225 end Process_Restrictions_Or_Restriction_Warnings
;
10227 ---------------------------------
10228 -- Process_Suppress_Unsuppress --
10229 ---------------------------------
10231 -- Note: this procedure makes entries in the check suppress data
10232 -- structures managed by Sem. See spec of package Sem for full
10233 -- details on how we handle recording of check suppression.
10235 procedure Process_Suppress_Unsuppress
(Suppress_Case
: Boolean) is
10240 In_Package_Spec
: constant Boolean :=
10241 Is_Package_Or_Generic_Package
(Current_Scope
)
10242 and then not In_Package_Body
(Current_Scope
);
10244 procedure Suppress_Unsuppress_Echeck
(E
: Entity_Id
; C
: Check_Id
);
10245 -- Used to suppress a single check on the given entity
10247 --------------------------------
10248 -- Suppress_Unsuppress_Echeck --
10249 --------------------------------
10251 procedure Suppress_Unsuppress_Echeck
(E
: Entity_Id
; C
: Check_Id
) is
10253 -- Check for error of trying to set atomic synchronization for
10254 -- a non-atomic variable.
10256 if C
= Atomic_Synchronization
10257 and then not (Is_Atomic
(E
) or else Has_Atomic_Components
(E
))
10260 ("pragma & requires atomic type or variable",
10261 Pragma_Identifier
(Original_Node
(N
)));
10264 Set_Checks_May_Be_Suppressed
(E
);
10266 if In_Package_Spec
then
10267 Push_Global_Suppress_Stack_Entry
10270 Suppress
=> Suppress_Case
);
10272 Push_Local_Suppress_Stack_Entry
10275 Suppress
=> Suppress_Case
);
10278 -- If this is a first subtype, and the base type is distinct,
10279 -- then also set the suppress flags on the base type.
10281 if Is_First_Subtype
(E
) and then Etype
(E
) /= E
then
10282 Suppress_Unsuppress_Echeck
(Etype
(E
), C
);
10284 end Suppress_Unsuppress_Echeck
;
10286 -- Start of processing for Process_Suppress_Unsuppress
10289 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
10290 -- on user code: we want to generate checks for analysis purposes, as
10291 -- set respectively by -gnatC and -gnatd.F
10293 if Comes_From_Source
(N
)
10294 and then (CodePeer_Mode
or GNATprove_Mode
)
10299 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
10300 -- declarative part or a package spec (RM 11.5(5)).
10302 if not Is_Configuration_Pragma
then
10303 Check_Is_In_Decl_Part_Or_Package_Spec
;
10306 Check_At_Least_N_Arguments
(1);
10307 Check_At_Most_N_Arguments
(2);
10308 Check_No_Identifier
(Arg1
);
10309 Check_Arg_Is_Identifier
(Arg1
);
10311 C
:= Get_Check_Id
(Chars
(Get_Pragma_Arg
(Arg1
)));
10313 if C
= No_Check_Id
then
10315 ("argument of pragma% is not valid check name", Arg1
);
10318 -- Warn that suppress of Elaboration_Check has no effect in SPARK
10320 if C
= Elaboration_Check
and then SPARK_Mode
= On
then
10322 ("Suppress of Elaboration_Check ignored in SPARK??",
10323 "\elaboration checking rules are statically enforced "
10324 & "(SPARK RM 7.7)", Arg1
);
10327 -- One-argument case
10329 if Arg_Count
= 1 then
10331 -- Make an entry in the local scope suppress table. This is the
10332 -- table that directly shows the current value of the scope
10333 -- suppress check for any check id value.
10335 if C
= All_Checks
then
10337 -- For All_Checks, we set all specific predefined checks with
10338 -- the exception of Elaboration_Check, which is handled
10339 -- specially because of not wanting All_Checks to have the
10340 -- effect of deactivating static elaboration order processing.
10341 -- Atomic_Synchronization is also not affected, since this is
10342 -- not a real check.
10344 for J
in Scope_Suppress
.Suppress
'Range loop
10345 if J
/= Elaboration_Check
10347 J
/= Atomic_Synchronization
10349 Scope_Suppress
.Suppress
(J
) := Suppress_Case
;
10353 -- If not All_Checks, and predefined check, then set appropriate
10354 -- scope entry. Note that we will set Elaboration_Check if this
10355 -- is explicitly specified. Atomic_Synchronization is allowed
10356 -- only if internally generated and entity is atomic.
10358 elsif C
in Predefined_Check_Id
10359 and then (not Comes_From_Source
(N
)
10360 or else C
/= Atomic_Synchronization
)
10362 Scope_Suppress
.Suppress
(C
) := Suppress_Case
;
10365 -- Also make an entry in the Local_Entity_Suppress table
10367 Push_Local_Suppress_Stack_Entry
10370 Suppress
=> Suppress_Case
);
10372 -- Case of two arguments present, where the check is suppressed for
10373 -- a specified entity (given as the second argument of the pragma)
10376 -- This is obsolescent in Ada 2005 mode
10378 if Ada_Version
>= Ada_2005
then
10379 Check_Restriction
(No_Obsolescent_Features
, Arg2
);
10382 Check_Optional_Identifier
(Arg2
, Name_On
);
10383 E_Id
:= Get_Pragma_Arg
(Arg2
);
10386 if not Is_Entity_Name
(E_Id
) then
10388 ("second argument of pragma% must be entity name", Arg2
);
10391 E
:= Entity
(E_Id
);
10397 -- A pragma that applies to a Ghost entity becomes Ghost for the
10398 -- purposes of legality checks and removal of ignored Ghost code.
10400 Mark_Ghost_Pragma
(N
, E
);
10402 -- Enforce RM 11.5(7) which requires that for a pragma that
10403 -- appears within a package spec, the named entity must be
10404 -- within the package spec. We allow the package name itself
10405 -- to be mentioned since that makes sense, although it is not
10406 -- strictly allowed by 11.5(7).
10409 and then E
/= Current_Scope
10410 and then Scope
(E
) /= Current_Scope
10413 ("entity in pragma% is not in package spec (RM 11.5(7))",
10417 -- Loop through homonyms. As noted below, in the case of a package
10418 -- spec, only homonyms within the package spec are considered.
10421 Suppress_Unsuppress_Echeck
(E
, C
);
10423 if Is_Generic_Instance
(E
)
10424 and then Is_Subprogram
(E
)
10425 and then Present
(Alias
(E
))
10427 Suppress_Unsuppress_Echeck
(Alias
(E
), C
);
10430 -- Move to next homonym if not aspect spec case
10432 exit when From_Aspect_Specification
(N
);
10436 -- If we are within a package specification, the pragma only
10437 -- applies to homonyms in the same scope.
10439 exit when In_Package_Spec
10440 and then Scope
(E
) /= Current_Scope
;
10443 end Process_Suppress_Unsuppress
;
10445 -------------------------------
10446 -- Record_Independence_Check --
10447 -------------------------------
10449 procedure Record_Independence_Check
(N
: Node_Id
; E
: Entity_Id
) is
10450 pragma Unreferenced
(N
, E
);
10452 -- For GCC back ends the validation is done a priori
10453 -- ??? This code is dead, might be useful in the future
10455 -- if not AAMP_On_Target then
10459 -- Independence_Checks.Append ((N, E));
10462 end Record_Independence_Check
;
10468 procedure Set_Exported
(E
: Entity_Id
; Arg
: Node_Id
) is
10470 if Is_Imported
(E
) then
10472 ("cannot export entity& that was previously imported", Arg
);
10474 elsif Present
(Address_Clause
(E
))
10475 and then not Relaxed_RM_Semantics
10478 ("cannot export entity& that has an address clause", Arg
);
10481 Set_Is_Exported
(E
);
10483 -- Generate a reference for entity explicitly, because the
10484 -- identifier may be overloaded and name resolution will not
10487 Generate_Reference
(E
, Arg
);
10489 -- Deal with exporting non-library level entity
10491 if not Is_Library_Level_Entity
(E
) then
10493 -- Not allowed at all for subprograms
10495 if Is_Subprogram
(E
) then
10496 Error_Pragma_Arg
("local subprogram& cannot be exported", Arg
);
10498 -- Otherwise set public and statically allocated
10502 Set_Is_Statically_Allocated
(E
);
10504 -- Warn if the corresponding W flag is set
10506 if Warn_On_Export_Import
10508 -- Only do this for something that was in the source. Not
10509 -- clear if this can be False now (there used for sure to be
10510 -- cases on some systems where it was False), but anyway the
10511 -- test is harmless if not needed, so it is retained.
10513 and then Comes_From_Source
(Arg
)
10516 ("?x?& has been made static as a result of Export",
10519 ("\?x?this usage is non-standard and non-portable",
10525 if Warn_On_Export_Import
and then Is_Type
(E
) then
10526 Error_Msg_NE
("exporting a type has no effect?x?", Arg
, E
);
10529 if Warn_On_Export_Import
and Inside_A_Generic
then
10531 ("all instances of& will have the same external name?x?",
10536 ----------------------------------------------
10537 -- Set_Extended_Import_Export_External_Name --
10538 ----------------------------------------------
10540 procedure Set_Extended_Import_Export_External_Name
10541 (Internal_Ent
: Entity_Id
;
10542 Arg_External
: Node_Id
)
10544 Old_Name
: constant Node_Id
:= Interface_Name
(Internal_Ent
);
10545 New_Name
: Node_Id
;
10548 if No
(Arg_External
) then
10552 Check_Arg_Is_External_Name
(Arg_External
);
10554 if Nkind
(Arg_External
) = N_String_Literal
then
10555 if String_Length
(Strval
(Arg_External
)) = 0 then
10558 New_Name
:= Adjust_External_Name_Case
(Arg_External
);
10561 elsif Nkind
(Arg_External
) = N_Identifier
then
10562 New_Name
:= Get_Default_External_Name
(Arg_External
);
10564 -- Check_Arg_Is_External_Name should let through only identifiers and
10565 -- string literals or static string expressions (which are folded to
10566 -- string literals).
10569 raise Program_Error
;
10572 -- If we already have an external name set (by a prior normal Import
10573 -- or Export pragma), then the external names must match
10575 if Present
(Interface_Name
(Internal_Ent
)) then
10577 -- Ignore mismatching names in CodePeer mode, to support some
10578 -- old compilers which would export the same procedure under
10579 -- different names, e.g:
10581 -- pragma Export_Procedure (P, "a");
10582 -- pragma Export_Procedure (P, "b");
10584 if CodePeer_Mode
then
10588 Check_Matching_Internal_Names
: declare
10589 S1
: constant String_Id
:= Strval
(Old_Name
);
10590 S2
: constant String_Id
:= Strval
(New_Name
);
10592 procedure Mismatch
;
10593 pragma No_Return
(Mismatch
);
10594 -- Called if names do not match
10600 procedure Mismatch
is
10602 Error_Msg_Sloc
:= Sloc
(Old_Name
);
10604 ("external name does not match that given #",
10608 -- Start of processing for Check_Matching_Internal_Names
10611 if String_Length
(S1
) /= String_Length
(S2
) then
10615 for J
in 1 .. String_Length
(S1
) loop
10616 if Get_String_Char
(S1
, J
) /= Get_String_Char
(S2
, J
) then
10621 end Check_Matching_Internal_Names
;
10623 -- Otherwise set the given name
10626 Set_Encoded_Interface_Name
(Internal_Ent
, New_Name
);
10627 Check_Duplicated_Export_Name
(New_Name
);
10629 end Set_Extended_Import_Export_External_Name
;
10635 procedure Set_Imported
(E
: Entity_Id
) is
10637 -- Error message if already imported or exported
10639 if Is_Exported
(E
) or else Is_Imported
(E
) then
10641 -- Error if being set Exported twice
10643 if Is_Exported
(E
) then
10644 Error_Msg_NE
("entity& was previously exported", N
, E
);
10646 -- Ignore error in CodePeer mode where we treat all imported
10647 -- subprograms as unknown.
10649 elsif CodePeer_Mode
then
10652 -- OK if Import/Interface case
10654 elsif Import_Interface_Present
(N
) then
10657 -- Error if being set Imported twice
10660 Error_Msg_NE
("entity& was previously imported", N
, E
);
10663 Error_Msg_Name_1
:= Pname
;
10665 ("\(pragma% applies to all previous entities)", N
);
10667 Error_Msg_Sloc
:= Sloc
(E
);
10668 Error_Msg_NE
("\import not allowed for& declared#", N
, E
);
10670 -- Here if not previously imported or exported, OK to import
10673 Set_Is_Imported
(E
);
10675 -- For subprogram, set Import_Pragma field
10677 if Is_Subprogram
(E
) then
10678 Set_Import_Pragma
(E
, N
);
10681 -- If the entity is an object that is not at the library level,
10682 -- then it is statically allocated. We do not worry about objects
10683 -- with address clauses in this context since they are not really
10684 -- imported in the linker sense.
10687 and then not Is_Library_Level_Entity
(E
)
10688 and then No
(Address_Clause
(E
))
10690 Set_Is_Statically_Allocated
(E
);
10697 -------------------------
10698 -- Set_Mechanism_Value --
10699 -------------------------
10701 -- Note: the mechanism name has not been analyzed (and cannot indeed be
10702 -- analyzed, since it is semantic nonsense), so we get it in the exact
10703 -- form created by the parser.
10705 procedure Set_Mechanism_Value
(Ent
: Entity_Id
; Mech_Name
: Node_Id
) is
10706 procedure Bad_Mechanism
;
10707 pragma No_Return
(Bad_Mechanism
);
10708 -- Signal bad mechanism name
10710 -------------------------
10711 -- Bad_Mechanism_Value --
10712 -------------------------
10714 procedure Bad_Mechanism
is
10716 Error_Pragma_Arg
("unrecognized mechanism name", Mech_Name
);
10719 -- Start of processing for Set_Mechanism_Value
10722 if Mechanism
(Ent
) /= Default_Mechanism
then
10724 ("mechanism for & has already been set", Mech_Name
, Ent
);
10727 -- MECHANISM_NAME ::= value | reference
10729 if Nkind
(Mech_Name
) = N_Identifier
then
10730 if Chars
(Mech_Name
) = Name_Value
then
10731 Set_Mechanism
(Ent
, By_Copy
);
10734 elsif Chars
(Mech_Name
) = Name_Reference
then
10735 Set_Mechanism
(Ent
, By_Reference
);
10738 elsif Chars
(Mech_Name
) = Name_Copy
then
10740 ("bad mechanism name, Value assumed", Mech_Name
);
10749 end Set_Mechanism_Value
;
10751 --------------------------
10752 -- Set_Rational_Profile --
10753 --------------------------
10755 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
10756 -- extension to the semantics of renaming declarations.
10758 procedure Set_Rational_Profile
is
10760 Implicit_Packing
:= True;
10761 Overriding_Renamings
:= True;
10762 Use_VADS_Size
:= True;
10763 end Set_Rational_Profile
;
10765 ---------------------------
10766 -- Set_Ravenscar_Profile --
10767 ---------------------------
10769 -- The tasks to be done here are
10771 -- Set required policies
10773 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
10774 -- (For Ravenscar and GNAT_Extended_Ravenscar profiles)
10775 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
10776 -- (For GNAT_Ravenscar_EDF profile)
10777 -- pragma Locking_Policy (Ceiling_Locking)
10779 -- Set Detect_Blocking mode
10781 -- Set required restrictions (see System.Rident for detailed list)
10783 -- Set the No_Dependence rules
10784 -- No_Dependence => Ada.Asynchronous_Task_Control
10785 -- No_Dependence => Ada.Calendar
10786 -- No_Dependence => Ada.Execution_Time.Group_Budget
10787 -- No_Dependence => Ada.Execution_Time.Timers
10788 -- No_Dependence => Ada.Task_Attributes
10789 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
10791 procedure Set_Ravenscar_Profile
(Profile
: Profile_Name
; N
: Node_Id
) is
10792 procedure Set_Error_Msg_To_Profile_Name
;
10793 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
10796 -----------------------------------
10797 -- Set_Error_Msg_To_Profile_Name --
10798 -----------------------------------
10800 procedure Set_Error_Msg_To_Profile_Name
is
10801 Prof_Nam
: constant Node_Id
:=
10803 (First
(Pragma_Argument_Associations
(N
)));
10806 Get_Name_String
(Chars
(Prof_Nam
));
10807 Adjust_Name_Case
(Global_Name_Buffer
, Sloc
(Prof_Nam
));
10808 Error_Msg_Strlen
:= Name_Len
;
10809 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
10810 end Set_Error_Msg_To_Profile_Name
;
10819 Profile_Dispatching_Policy
: Character;
10821 -- Start of processing for Set_Ravenscar_Profile
10824 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
10826 if Profile
= GNAT_Ravenscar_EDF
then
10827 Profile_Dispatching_Policy
:= 'E';
10829 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
10832 Profile_Dispatching_Policy
:= 'F';
10835 if Task_Dispatching_Policy
/= ' '
10836 and then Task_Dispatching_Policy
/= Profile_Dispatching_Policy
10838 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
10839 Set_Error_Msg_To_Profile_Name
;
10840 Error_Pragma
("Profile (~) incompatible with policy#");
10842 -- Set the FIFO_Within_Priorities policy, but always preserve
10843 -- System_Location since we like the error message with the run time
10847 Task_Dispatching_Policy
:= Profile_Dispatching_Policy
;
10849 if Task_Dispatching_Policy_Sloc
/= System_Location
then
10850 Task_Dispatching_Policy_Sloc
:= Loc
;
10854 -- pragma Locking_Policy (Ceiling_Locking)
10856 if Locking_Policy
/= ' '
10857 and then Locking_Policy
/= 'C'
10859 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
10860 Set_Error_Msg_To_Profile_Name
;
10861 Error_Pragma
("Profile (~) incompatible with policy#");
10863 -- Set the Ceiling_Locking policy, but preserve System_Location since
10864 -- we like the error message with the run time name.
10867 Locking_Policy
:= 'C';
10869 if Locking_Policy_Sloc
/= System_Location
then
10870 Locking_Policy_Sloc
:= Loc
;
10874 -- pragma Detect_Blocking
10876 Detect_Blocking
:= True;
10878 -- Set the corresponding restrictions
10880 Set_Profile_Restrictions
10881 (Profile
, N
, Warn
=> Treat_Restrictions_As_Warnings
);
10883 -- Set the No_Dependence restrictions
10885 -- The following No_Dependence restrictions:
10886 -- No_Dependence => Ada.Asynchronous_Task_Control
10887 -- No_Dependence => Ada.Calendar
10888 -- No_Dependence => Ada.Task_Attributes
10889 -- are already set by previous call to Set_Profile_Restrictions.
10891 -- Set the following restrictions which were added to Ada 2005:
10892 -- No_Dependence => Ada.Execution_Time.Group_Budget
10893 -- No_Dependence => Ada.Execution_Time.Timers
10895 if Ada_Version
>= Ada_2005
then
10896 Pref_Id
:= Make_Identifier
(Loc
, Name_Find
("ada"));
10897 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
("execution_time"));
10900 Make_Selected_Component
10903 Selector_Name
=> Sel_Id
);
10905 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
("group_budgets"));
10908 Make_Selected_Component
10911 Selector_Name
=> Sel_Id
);
10913 Set_Restriction_No_Dependence
10915 Warn
=> Treat_Restrictions_As_Warnings
,
10916 Profile
=> Ravenscar
);
10918 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
("timers"));
10921 Make_Selected_Component
10924 Selector_Name
=> Sel_Id
);
10926 Set_Restriction_No_Dependence
10928 Warn
=> Treat_Restrictions_As_Warnings
,
10929 Profile
=> Ravenscar
);
10932 -- Set the following restriction which was added to Ada 2012 (see
10934 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
10936 if Ada_Version
>= Ada_2012
then
10937 Pref_Id
:= Make_Identifier
(Loc
, Name_Find
("system"));
10938 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
("multiprocessors"));
10941 Make_Selected_Component
10944 Selector_Name
=> Sel_Id
);
10946 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
("dispatching_domains"));
10949 Make_Selected_Component
10952 Selector_Name
=> Sel_Id
);
10954 Set_Restriction_No_Dependence
10956 Warn
=> Treat_Restrictions_As_Warnings
,
10957 Profile
=> Ravenscar
);
10959 end Set_Ravenscar_Profile
;
10961 -- Start of processing for Analyze_Pragma
10964 -- The following code is a defense against recursion. Not clear that
10965 -- this can happen legitimately, but perhaps some error situations can
10966 -- cause it, and we did see this recursion during testing.
10968 if Analyzed
(N
) then
10974 Check_Restriction_No_Use_Of_Pragma
(N
);
10976 -- Ignore pragma if Ignore_Pragma applies. Also ignore pragma
10977 -- Default_Scalar_Storage_Order if the -gnatI switch was given.
10979 if Should_Ignore_Pragma_Sem
(N
)
10980 or else (Prag_Id
= Pragma_Default_Scalar_Storage_Order
10981 and then Ignore_Rep_Clauses
)
10986 -- Deal with unrecognized pragma
10988 if not Is_Pragma_Name
(Pname
) then
10989 if Warn_On_Unrecognized_Pragma
then
10990 Error_Msg_Name_1
:= Pname
;
10991 Error_Msg_N
("?g?unrecognized pragma%!", Pragma_Identifier
(N
));
10993 for PN
in First_Pragma_Name
.. Last_Pragma_Name
loop
10994 if Is_Bad_Spelling_Of
(Pname
, PN
) then
10995 Error_Msg_Name_1
:= PN
;
10996 Error_Msg_N
-- CODEFIX
10997 ("\?g?possible misspelling of %!", Pragma_Identifier
(N
));
11006 -- Here to start processing for recognized pragma
11008 Pname
:= Original_Aspect_Pragma_Name
(N
);
11010 -- Capture setting of Opt.Uneval_Old
11012 case Opt
.Uneval_Old
is
11014 Set_Uneval_Old_Accept
(N
);
11020 Set_Uneval_Old_Warn
(N
);
11023 raise Program_Error
;
11026 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
11027 -- is already set, indicating that we have already checked the policy
11028 -- at the right point. This happens for example in the case of a pragma
11029 -- that is derived from an Aspect.
11031 if Is_Ignored
(N
) or else Is_Checked
(N
) then
11034 -- For a pragma that is a rewriting of another pragma, copy the
11035 -- Is_Checked/Is_Ignored status from the rewritten pragma.
11037 elsif Is_Rewrite_Substitution
(N
)
11038 and then Nkind
(Original_Node
(N
)) = N_Pragma
11039 and then Original_Node
(N
) /= N
11041 Set_Is_Ignored
(N
, Is_Ignored
(Original_Node
(N
)));
11042 Set_Is_Checked
(N
, Is_Checked
(Original_Node
(N
)));
11044 -- Otherwise query the applicable policy at this point
11047 Check_Applicable_Policy
(N
);
11049 -- If pragma is disabled, rewrite as NULL and skip analysis
11051 if Is_Disabled
(N
) then
11052 Rewrite
(N
, Make_Null_Statement
(Loc
));
11058 -- Preset arguments
11066 if Present
(Pragma_Argument_Associations
(N
)) then
11067 Arg_Count
:= List_Length
(Pragma_Argument_Associations
(N
));
11068 Arg1
:= First
(Pragma_Argument_Associations
(N
));
11070 if Present
(Arg1
) then
11071 Arg2
:= Next
(Arg1
);
11073 if Present
(Arg2
) then
11074 Arg3
:= Next
(Arg2
);
11076 if Present
(Arg3
) then
11077 Arg4
:= Next
(Arg3
);
11083 -- An enumeration type defines the pragmas that are supported by the
11084 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
11085 -- into the corresponding enumeration value for the following case.
11093 -- pragma Abort_Defer;
11095 when Pragma_Abort_Defer
=>
11097 Check_Arg_Count
(0);
11099 -- The only required semantic processing is to check the
11100 -- placement. This pragma must appear at the start of the
11101 -- statement sequence of a handled sequence of statements.
11103 if Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
11104 or else N
/= First
(Statements
(Parent
(N
)))
11109 --------------------
11110 -- Abstract_State --
11111 --------------------
11113 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
11115 -- ABSTRACT_STATE_LIST ::=
11117 -- | STATE_NAME_WITH_OPTIONS
11118 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
11120 -- STATE_NAME_WITH_OPTIONS ::=
11122 -- | (STATE_NAME with OPTION_LIST)
11124 -- OPTION_LIST ::= OPTION {, OPTION}
11128 -- | NAME_VALUE_OPTION
11130 -- SIMPLE_OPTION ::= Ghost | Synchronous
11132 -- NAME_VALUE_OPTION ::=
11133 -- Part_Of => ABSTRACT_STATE
11134 -- | External [=> EXTERNAL_PROPERTY_LIST]
11136 -- EXTERNAL_PROPERTY_LIST ::=
11137 -- EXTERNAL_PROPERTY
11138 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
11140 -- EXTERNAL_PROPERTY ::=
11141 -- Async_Readers [=> boolean_EXPRESSION]
11142 -- | Async_Writers [=> boolean_EXPRESSION]
11143 -- | Effective_Reads [=> boolean_EXPRESSION]
11144 -- | Effective_Writes [=> boolean_EXPRESSION]
11145 -- others => boolean_EXPRESSION
11147 -- STATE_NAME ::= defining_identifier
11149 -- ABSTRACT_STATE ::= name
11151 -- Characteristics:
11153 -- * Analysis - The annotation is fully analyzed immediately upon
11154 -- elaboration as it cannot forward reference entities.
11156 -- * Expansion - None.
11158 -- * Template - The annotation utilizes the generic template of the
11159 -- related package declaration.
11161 -- * Globals - The annotation cannot reference global entities.
11163 -- * Instance - The annotation is instantiated automatically when
11164 -- the related generic package is instantiated.
11166 when Pragma_Abstract_State
=> Abstract_State
: declare
11167 Missing_Parentheses
: Boolean := False;
11168 -- Flag set when a state declaration with options is not properly
11171 -- Flags used to verify the consistency of states
11173 Non_Null_Seen
: Boolean := False;
11174 Null_Seen
: Boolean := False;
11176 procedure Analyze_Abstract_State
11178 Pack_Id
: Entity_Id
);
11179 -- Verify the legality of a single state declaration. Create and
11180 -- decorate a state abstraction entity and introduce it into the
11181 -- visibility chain. Pack_Id denotes the entity or the related
11182 -- package where pragma Abstract_State appears.
11184 procedure Malformed_State_Error
(State
: Node_Id
);
11185 -- Emit an error concerning the illegal declaration of abstract
11186 -- state State. This routine diagnoses syntax errors that lead to
11187 -- a different parse tree. The error is issued regardless of the
11188 -- SPARK mode in effect.
11190 ----------------------------
11191 -- Analyze_Abstract_State --
11192 ----------------------------
11194 procedure Analyze_Abstract_State
11196 Pack_Id
: Entity_Id
)
11198 -- Flags used to verify the consistency of options
11200 AR_Seen
: Boolean := False;
11201 AW_Seen
: Boolean := False;
11202 ER_Seen
: Boolean := False;
11203 EW_Seen
: Boolean := False;
11204 External_Seen
: Boolean := False;
11205 Ghost_Seen
: Boolean := False;
11206 Others_Seen
: Boolean := False;
11207 Part_Of_Seen
: Boolean := False;
11208 Synchronous_Seen
: Boolean := False;
11210 -- Flags used to store the static value of all external states'
11213 AR_Val
: Boolean := False;
11214 AW_Val
: Boolean := False;
11215 ER_Val
: Boolean := False;
11216 EW_Val
: Boolean := False;
11218 State_Id
: Entity_Id
:= Empty
;
11219 -- The entity to be generated for the current state declaration
11221 procedure Analyze_External_Option
(Opt
: Node_Id
);
11222 -- Verify the legality of option External
11224 procedure Analyze_External_Property
11226 Expr
: Node_Id
:= Empty
);
11227 -- Verify the legailty of a single external property. Prop
11228 -- denotes the external property. Expr is the expression used
11229 -- to set the property.
11231 procedure Analyze_Part_Of_Option
(Opt
: Node_Id
);
11232 -- Verify the legality of option Part_Of
11234 procedure Check_Duplicate_Option
11236 Status
: in out Boolean);
11237 -- Flag Status denotes whether a particular option has been
11238 -- seen while processing a state. This routine verifies that
11239 -- Opt is not a duplicate option and sets the flag Status
11240 -- (SPARK RM 7.1.4(1)).
11242 procedure Check_Duplicate_Property
11244 Status
: in out Boolean);
11245 -- Flag Status denotes whether a particular property has been
11246 -- seen while processing option External. This routine verifies
11247 -- that Prop is not a duplicate property and sets flag Status.
11248 -- Opt is not a duplicate property and sets the flag Status.
11249 -- (SPARK RM 7.1.4(2))
11251 procedure Check_Ghost_Synchronous
;
11252 -- Ensure that the abstract state is not subject to both Ghost
11253 -- and Synchronous simple options. Emit an error if this is the
11256 procedure Create_Abstract_State
11260 Is_Null
: Boolean);
11261 -- Generate an abstract state entity with name Nam and enter it
11262 -- into visibility. Decl is the "declaration" of the state as
11263 -- it appears in pragma Abstract_State. Loc is the location of
11264 -- the related state "declaration". Flag Is_Null should be set
11265 -- when the associated Abstract_State pragma defines a null
11268 -----------------------------
11269 -- Analyze_External_Option --
11270 -----------------------------
11272 procedure Analyze_External_Option
(Opt
: Node_Id
) is
11273 Errors
: constant Nat
:= Serious_Errors_Detected
;
11275 Props
: Node_Id
:= Empty
;
11278 if Nkind
(Opt
) = N_Component_Association
then
11279 Props
:= Expression
(Opt
);
11282 -- External state with properties
11284 if Present
(Props
) then
11286 -- Multiple properties appear as an aggregate
11288 if Nkind
(Props
) = N_Aggregate
then
11290 -- Simple property form
11292 Prop
:= First
(Expressions
(Props
));
11293 while Present
(Prop
) loop
11294 Analyze_External_Property
(Prop
);
11298 -- Property with expression form
11300 Prop
:= First
(Component_Associations
(Props
));
11301 while Present
(Prop
) loop
11302 Analyze_External_Property
11303 (Prop
=> First
(Choices
(Prop
)),
11304 Expr
=> Expression
(Prop
));
11312 Analyze_External_Property
(Props
);
11315 -- An external state defined without any properties defaults
11316 -- all properties to True.
11325 -- Once all external properties have been processed, verify
11326 -- their mutual interaction. Do not perform the check when
11327 -- at least one of the properties is illegal as this will
11328 -- produce a bogus error.
11330 if Errors
= Serious_Errors_Detected
then
11331 Check_External_Properties
11332 (State
, AR_Val
, AW_Val
, ER_Val
, EW_Val
);
11334 end Analyze_External_Option
;
11336 -------------------------------
11337 -- Analyze_External_Property --
11338 -------------------------------
11340 procedure Analyze_External_Property
11342 Expr
: Node_Id
:= Empty
)
11344 Expr_Val
: Boolean;
11347 -- Check the placement of "others" (if available)
11349 if Nkind
(Prop
) = N_Others_Choice
then
11350 if Others_Seen
then
11352 ("only one others choice allowed in option External",
11355 Others_Seen
:= True;
11358 elsif Others_Seen
then
11360 ("others must be the last property in option External",
11363 -- The only remaining legal options are the four predefined
11364 -- external properties.
11366 elsif Nkind
(Prop
) = N_Identifier
11367 and then Nam_In
(Chars
(Prop
), Name_Async_Readers
,
11368 Name_Async_Writers
,
11369 Name_Effective_Reads
,
11370 Name_Effective_Writes
)
11374 -- Otherwise the construct is not a valid property
11377 SPARK_Msg_N
("invalid external state property", Prop
);
11381 -- Ensure that the expression of the external state property
11382 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
11384 if Present
(Expr
) then
11385 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
11387 if Is_OK_Static_Expression
(Expr
) then
11388 Expr_Val
:= Is_True
(Expr_Value
(Expr
));
11391 ("expression of external state property must be "
11396 -- The lack of expression defaults the property to True
11402 -- Named properties
11404 if Nkind
(Prop
) = N_Identifier
then
11405 if Chars
(Prop
) = Name_Async_Readers
then
11406 Check_Duplicate_Property
(Prop
, AR_Seen
);
11407 AR_Val
:= Expr_Val
;
11409 elsif Chars
(Prop
) = Name_Async_Writers
then
11410 Check_Duplicate_Property
(Prop
, AW_Seen
);
11411 AW_Val
:= Expr_Val
;
11413 elsif Chars
(Prop
) = Name_Effective_Reads
then
11414 Check_Duplicate_Property
(Prop
, ER_Seen
);
11415 ER_Val
:= Expr_Val
;
11418 Check_Duplicate_Property
(Prop
, EW_Seen
);
11419 EW_Val
:= Expr_Val
;
11422 -- The handling of property "others" must take into account
11423 -- all other named properties that have been encountered so
11424 -- far. Only those that have not been seen are affected by
11428 if not AR_Seen
then
11429 AR_Val
:= Expr_Val
;
11432 if not AW_Seen
then
11433 AW_Val
:= Expr_Val
;
11436 if not ER_Seen
then
11437 ER_Val
:= Expr_Val
;
11440 if not EW_Seen
then
11441 EW_Val
:= Expr_Val
;
11444 end Analyze_External_Property
;
11446 ----------------------------
11447 -- Analyze_Part_Of_Option --
11448 ----------------------------
11450 procedure Analyze_Part_Of_Option
(Opt
: Node_Id
) is
11451 Encap
: constant Node_Id
:= Expression
(Opt
);
11452 Constits
: Elist_Id
;
11453 Encap_Id
: Entity_Id
;
11457 Check_Duplicate_Option
(Opt
, Part_Of_Seen
);
11460 (Indic
=> First
(Choices
(Opt
)),
11461 Item_Id
=> State_Id
,
11463 Encap_Id
=> Encap_Id
,
11466 -- The Part_Of indicator transforms the abstract state into
11467 -- a constituent of the encapsulating state or single
11468 -- concurrent type.
11471 pragma Assert
(Present
(Encap_Id
));
11472 Constits
:= Part_Of_Constituents
(Encap_Id
);
11474 if No
(Constits
) then
11475 Constits
:= New_Elmt_List
;
11476 Set_Part_Of_Constituents
(Encap_Id
, Constits
);
11479 Append_Elmt
(State_Id
, Constits
);
11480 Set_Encapsulating_State
(State_Id
, Encap_Id
);
11482 end Analyze_Part_Of_Option
;
11484 ----------------------------
11485 -- Check_Duplicate_Option --
11486 ----------------------------
11488 procedure Check_Duplicate_Option
11490 Status
: in out Boolean)
11494 SPARK_Msg_N
("duplicate state option", Opt
);
11498 end Check_Duplicate_Option
;
11500 ------------------------------
11501 -- Check_Duplicate_Property --
11502 ------------------------------
11504 procedure Check_Duplicate_Property
11506 Status
: in out Boolean)
11510 SPARK_Msg_N
("duplicate external property", Prop
);
11514 end Check_Duplicate_Property
;
11516 -----------------------------
11517 -- Check_Ghost_Synchronous --
11518 -----------------------------
11520 procedure Check_Ghost_Synchronous
is
11522 -- A synchronized abstract state cannot be Ghost and vice
11523 -- versa (SPARK RM 6.9(19)).
11525 if Ghost_Seen
and Synchronous_Seen
then
11526 SPARK_Msg_N
("synchronized state cannot be ghost", State
);
11528 end Check_Ghost_Synchronous
;
11530 ---------------------------
11531 -- Create_Abstract_State --
11532 ---------------------------
11534 procedure Create_Abstract_State
11541 -- The abstract state may be semi-declared when the related
11542 -- package was withed through a limited with clause. In that
11543 -- case reuse the entity to fully declare the state.
11545 if Present
(Decl
) and then Present
(Entity
(Decl
)) then
11546 State_Id
:= Entity
(Decl
);
11548 -- Otherwise the elaboration of pragma Abstract_State
11549 -- declares the state.
11552 State_Id
:= Make_Defining_Identifier
(Loc
, Nam
);
11554 if Present
(Decl
) then
11555 Set_Entity
(Decl
, State_Id
);
11559 -- Null states never come from source
11561 Set_Comes_From_Source
(State_Id
, not Is_Null
);
11562 Set_Parent
(State_Id
, State
);
11563 Set_Ekind
(State_Id
, E_Abstract_State
);
11564 Set_Etype
(State_Id
, Standard_Void_Type
);
11565 Set_Encapsulating_State
(State_Id
, Empty
);
11567 -- Set the SPARK mode from the current context
11569 Set_SPARK_Pragma
(State_Id
, SPARK_Mode_Pragma
);
11570 Set_SPARK_Pragma_Inherited
(State_Id
);
11572 -- An abstract state declared within a Ghost region becomes
11573 -- Ghost (SPARK RM 6.9(2)).
11575 if Ghost_Mode
> None
or else Is_Ghost_Entity
(Pack_Id
) then
11576 Set_Is_Ghost_Entity
(State_Id
);
11579 -- Establish a link between the state declaration and the
11580 -- abstract state entity. Note that a null state remains as
11581 -- N_Null and does not carry any linkages.
11583 if not Is_Null
then
11584 if Present
(Decl
) then
11585 Set_Entity
(Decl
, State_Id
);
11586 Set_Etype
(Decl
, Standard_Void_Type
);
11589 -- Every non-null state must be defined, nameable and
11592 Push_Scope
(Pack_Id
);
11593 Generate_Definition
(State_Id
);
11594 Enter_Name
(State_Id
);
11597 end Create_Abstract_State
;
11604 -- Start of processing for Analyze_Abstract_State
11607 -- A package with a null abstract state is not allowed to
11608 -- declare additional states.
11612 ("package & has null abstract state", State
, Pack_Id
);
11614 -- Null states appear as internally generated entities
11616 elsif Nkind
(State
) = N_Null
then
11617 Create_Abstract_State
11618 (Nam
=> New_Internal_Name
('S'),
11620 Loc
=> Sloc
(State
),
11624 -- Catch a case where a null state appears in a list of
11625 -- non-null states.
11627 if Non_Null_Seen
then
11629 ("package & has non-null abstract state",
11633 -- Simple state declaration
11635 elsif Nkind
(State
) = N_Identifier
then
11636 Create_Abstract_State
11637 (Nam
=> Chars
(State
),
11639 Loc
=> Sloc
(State
),
11641 Non_Null_Seen
:= True;
11643 -- State declaration with various options. This construct
11644 -- appears as an extension aggregate in the tree.
11646 elsif Nkind
(State
) = N_Extension_Aggregate
then
11647 if Nkind
(Ancestor_Part
(State
)) = N_Identifier
then
11648 Create_Abstract_State
11649 (Nam
=> Chars
(Ancestor_Part
(State
)),
11650 Decl
=> Ancestor_Part
(State
),
11651 Loc
=> Sloc
(Ancestor_Part
(State
)),
11653 Non_Null_Seen
:= True;
11656 ("state name must be an identifier",
11657 Ancestor_Part
(State
));
11660 -- Options External, Ghost and Synchronous appear as
11663 Opt
:= First
(Expressions
(State
));
11664 while Present
(Opt
) loop
11665 if Nkind
(Opt
) = N_Identifier
then
11669 if Chars
(Opt
) = Name_External
then
11670 Check_Duplicate_Option
(Opt
, External_Seen
);
11671 Analyze_External_Option
(Opt
);
11675 elsif Chars
(Opt
) = Name_Ghost
then
11676 Check_Duplicate_Option
(Opt
, Ghost_Seen
);
11677 Check_Ghost_Synchronous
;
11679 if Present
(State_Id
) then
11680 Set_Is_Ghost_Entity
(State_Id
);
11685 elsif Chars
(Opt
) = Name_Synchronous
then
11686 Check_Duplicate_Option
(Opt
, Synchronous_Seen
);
11687 Check_Ghost_Synchronous
;
11689 -- Option Part_Of without an encapsulating state is
11690 -- illegal (SPARK RM 7.1.4(9)).
11692 elsif Chars
(Opt
) = Name_Part_Of
then
11694 ("indicator Part_Of must denote abstract state, "
11695 & "single protected type or single task type",
11698 -- Do not emit an error message when a previous state
11699 -- declaration with options was not parenthesized as
11700 -- the option is actually another state declaration.
11702 -- with Abstract_State
11703 -- (State_1 with ..., -- missing parentheses
11704 -- (State_2 with ...),
11705 -- State_3) -- ok state declaration
11707 elsif Missing_Parentheses
then
11710 -- Otherwise the option is not allowed. Note that it
11711 -- is not possible to distinguish between an option
11712 -- and a state declaration when a previous state with
11713 -- options not properly parentheses.
11715 -- with Abstract_State
11716 -- (State_1 with ..., -- missing parentheses
11717 -- State_2); -- could be an option
11721 ("simple option not allowed in state declaration",
11725 -- Catch a case where missing parentheses around a state
11726 -- declaration with options cause a subsequent state
11727 -- declaration with options to be treated as an option.
11729 -- with Abstract_State
11730 -- (State_1 with ..., -- missing parentheses
11731 -- (State_2 with ...))
11733 elsif Nkind
(Opt
) = N_Extension_Aggregate
then
11734 Missing_Parentheses
:= True;
11736 ("state declaration must be parenthesized",
11737 Ancestor_Part
(State
));
11739 -- Otherwise the option is malformed
11742 SPARK_Msg_N
("malformed option", Opt
);
11748 -- Options External and Part_Of appear as component
11751 Opt
:= First
(Component_Associations
(State
));
11752 while Present
(Opt
) loop
11753 Opt_Nam
:= First
(Choices
(Opt
));
11755 if Nkind
(Opt_Nam
) = N_Identifier
then
11756 if Chars
(Opt_Nam
) = Name_External
then
11757 Analyze_External_Option
(Opt
);
11759 elsif Chars
(Opt_Nam
) = Name_Part_Of
then
11760 Analyze_Part_Of_Option
(Opt
);
11763 SPARK_Msg_N
("invalid state option", Opt
);
11766 SPARK_Msg_N
("invalid state option", Opt
);
11772 -- Any other attempt to declare a state is illegal
11775 Malformed_State_Error
(State
);
11779 -- Guard against a junk state. In such cases no entity is
11780 -- generated and the subsequent checks cannot be applied.
11782 if Present
(State_Id
) then
11784 -- Verify whether the state does not introduce an illegal
11785 -- hidden state within a package subject to a null abstract
11788 Check_No_Hidden_State
(State_Id
);
11790 -- Check whether the lack of option Part_Of agrees with the
11791 -- placement of the abstract state with respect to the state
11794 if not Part_Of_Seen
then
11795 Check_Missing_Part_Of
(State_Id
);
11798 -- Associate the state with its related package
11800 if No
(Abstract_States
(Pack_Id
)) then
11801 Set_Abstract_States
(Pack_Id
, New_Elmt_List
);
11804 Append_Elmt
(State_Id
, Abstract_States
(Pack_Id
));
11806 end Analyze_Abstract_State
;
11808 ---------------------------
11809 -- Malformed_State_Error --
11810 ---------------------------
11812 procedure Malformed_State_Error
(State
: Node_Id
) is
11814 Error_Msg_N
("malformed abstract state declaration", State
);
11816 -- An abstract state with a simple option is being declared
11817 -- with "=>" rather than the legal "with". The state appears
11818 -- as a component association.
11820 if Nkind
(State
) = N_Component_Association
then
11821 Error_Msg_N
("\use WITH to specify simple option", State
);
11823 end Malformed_State_Error
;
11827 Pack_Decl
: Node_Id
;
11828 Pack_Id
: Entity_Id
;
11832 -- Start of processing for Abstract_State
11836 Check_No_Identifiers
;
11837 Check_Arg_Count
(1);
11839 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
11841 -- Ensure the proper placement of the pragma. Abstract states must
11842 -- be associated with a package declaration.
11844 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
11845 N_Package_Declaration
)
11849 -- Otherwise the pragma is associated with an illegal construct
11856 Pack_Id
:= Defining_Entity
(Pack_Decl
);
11858 -- A pragma that applies to a Ghost entity becomes Ghost for the
11859 -- purposes of legality checks and removal of ignored Ghost code.
11861 Mark_Ghost_Pragma
(N
, Pack_Id
);
11862 Ensure_Aggregate_Form
(Get_Argument
(N
, Pack_Id
));
11864 -- Chain the pragma on the contract for completeness
11866 Add_Contract_Item
(N
, Pack_Id
);
11868 -- The legality checks of pragmas Abstract_State, Initializes, and
11869 -- Initial_Condition are affected by the SPARK mode in effect. In
11870 -- addition, these three pragmas are subject to an inherent order:
11872 -- 1) Abstract_State
11874 -- 3) Initial_Condition
11876 -- Analyze all these pragmas in the order outlined above
11878 Analyze_If_Present
(Pragma_SPARK_Mode
);
11879 States
:= Expression
(Get_Argument
(N
, Pack_Id
));
11881 -- Multiple non-null abstract states appear as an aggregate
11883 if Nkind
(States
) = N_Aggregate
then
11884 State
:= First
(Expressions
(States
));
11885 while Present
(State
) loop
11886 Analyze_Abstract_State
(State
, Pack_Id
);
11890 -- An abstract state with a simple option is being illegaly
11891 -- declared with "=>" rather than "with". In this case the
11892 -- state declaration appears as a component association.
11894 if Present
(Component_Associations
(States
)) then
11895 State
:= First
(Component_Associations
(States
));
11896 while Present
(State
) loop
11897 Malformed_State_Error
(State
);
11902 -- Various forms of a single abstract state. Note that these may
11903 -- include malformed state declarations.
11906 Analyze_Abstract_State
(States
, Pack_Id
);
11909 Analyze_If_Present
(Pragma_Initializes
);
11910 Analyze_If_Present
(Pragma_Initial_Condition
);
11911 end Abstract_State
;
11919 -- Note: this pragma also has some specific processing in Par.Prag
11920 -- because we want to set the Ada version mode during parsing.
11922 when Pragma_Ada_83
=>
11924 Check_Arg_Count
(0);
11926 -- We really should check unconditionally for proper configuration
11927 -- pragma placement, since we really don't want mixed Ada modes
11928 -- within a single unit, and the GNAT reference manual has always
11929 -- said this was a configuration pragma, but we did not check and
11930 -- are hesitant to add the check now.
11932 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
11933 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
11934 -- or Ada 2012 mode.
11936 if Ada_Version
>= Ada_2005
then
11937 Check_Valid_Configuration_Pragma
;
11940 -- Now set Ada 83 mode
11942 if Latest_Ada_Only
then
11943 Error_Pragma
("??pragma% ignored");
11945 Ada_Version
:= Ada_83
;
11946 Ada_Version_Explicit
:= Ada_83
;
11947 Ada_Version_Pragma
:= N
;
11956 -- Note: this pragma also has some specific processing in Par.Prag
11957 -- because we want to set the Ada 83 version mode during parsing.
11959 when Pragma_Ada_95
=>
11961 Check_Arg_Count
(0);
11963 -- We really should check unconditionally for proper configuration
11964 -- pragma placement, since we really don't want mixed Ada modes
11965 -- within a single unit, and the GNAT reference manual has always
11966 -- said this was a configuration pragma, but we did not check and
11967 -- are hesitant to add the check now.
11969 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
11970 -- or Ada 95, so we must check if we are in Ada 2005 mode.
11972 if Ada_Version
>= Ada_2005
then
11973 Check_Valid_Configuration_Pragma
;
11976 -- Now set Ada 95 mode
11978 if Latest_Ada_Only
then
11979 Error_Pragma
("??pragma% ignored");
11981 Ada_Version
:= Ada_95
;
11982 Ada_Version_Explicit
:= Ada_95
;
11983 Ada_Version_Pragma
:= N
;
11986 ---------------------
11987 -- Ada_05/Ada_2005 --
11988 ---------------------
11991 -- pragma Ada_05 (LOCAL_NAME);
11993 -- pragma Ada_2005;
11994 -- pragma Ada_2005 (LOCAL_NAME):
11996 -- Note: these pragmas also have some specific processing in Par.Prag
11997 -- because we want to set the Ada 2005 version mode during parsing.
11999 -- The one argument form is used for managing the transition from
12000 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
12001 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
12002 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
12003 -- mode, a preference rule is established which does not choose
12004 -- such an entity unless it is unambiguously specified. This avoids
12005 -- extra subprograms marked this way from generating ambiguities in
12006 -- otherwise legal pre-Ada_2005 programs. The one argument form is
12007 -- intended for exclusive use in the GNAT run-time library.
12018 if Arg_Count
= 1 then
12019 Check_Arg_Is_Local_Name
(Arg1
);
12020 E_Id
:= Get_Pragma_Arg
(Arg1
);
12022 if Etype
(E_Id
) = Any_Type
then
12026 Set_Is_Ada_2005_Only
(Entity
(E_Id
));
12027 Record_Rep_Item
(Entity
(E_Id
), N
);
12030 Check_Arg_Count
(0);
12032 -- For Ada_2005 we unconditionally enforce the documented
12033 -- configuration pragma placement, since we do not want to
12034 -- tolerate mixed modes in a unit involving Ada 2005. That
12035 -- would cause real difficulties for those cases where there
12036 -- are incompatibilities between Ada 95 and Ada 2005.
12038 Check_Valid_Configuration_Pragma
;
12040 -- Now set appropriate Ada mode
12042 if Latest_Ada_Only
then
12043 Error_Pragma
("??pragma% ignored");
12045 Ada_Version
:= Ada_2005
;
12046 Ada_Version_Explicit
:= Ada_2005
;
12047 Ada_Version_Pragma
:= N
;
12052 ---------------------
12053 -- Ada_12/Ada_2012 --
12054 ---------------------
12057 -- pragma Ada_12 (LOCAL_NAME);
12059 -- pragma Ada_2012;
12060 -- pragma Ada_2012 (LOCAL_NAME):
12062 -- Note: these pragmas also have some specific processing in Par.Prag
12063 -- because we want to set the Ada 2012 version mode during parsing.
12065 -- The one argument form is used for managing the transition from Ada
12066 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
12067 -- as Ada_2012 only, then referencing the entity in any pre-Ada_2012
12068 -- mode will generate a warning. In addition, in any pre-Ada_2012
12069 -- mode, a preference rule is established which does not choose
12070 -- such an entity unless it is unambiguously specified. This avoids
12071 -- extra subprograms marked this way from generating ambiguities in
12072 -- otherwise legal pre-Ada_2012 programs. The one argument form is
12073 -- intended for exclusive use in the GNAT run-time library.
12084 if Arg_Count
= 1 then
12085 Check_Arg_Is_Local_Name
(Arg1
);
12086 E_Id
:= Get_Pragma_Arg
(Arg1
);
12088 if Etype
(E_Id
) = Any_Type
then
12092 Set_Is_Ada_2012_Only
(Entity
(E_Id
));
12093 Record_Rep_Item
(Entity
(E_Id
), N
);
12096 Check_Arg_Count
(0);
12098 -- For Ada_2012 we unconditionally enforce the documented
12099 -- configuration pragma placement, since we do not want to
12100 -- tolerate mixed modes in a unit involving Ada 2012. That
12101 -- would cause real difficulties for those cases where there
12102 -- are incompatibilities between Ada 95 and Ada 2012. We could
12103 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
12105 Check_Valid_Configuration_Pragma
;
12107 -- Now set appropriate Ada mode
12109 Ada_Version
:= Ada_2012
;
12110 Ada_Version_Explicit
:= Ada_2012
;
12111 Ada_Version_Pragma
:= N
;
12119 -- pragma Ada_2020;
12121 -- Note: this pragma also has some specific processing in Par.Prag
12122 -- because we want to set the Ada 2020 version mode during parsing.
12124 when Pragma_Ada_2020
=>
12127 Check_Arg_Count
(0);
12129 Check_Valid_Configuration_Pragma
;
12131 -- Now set appropriate Ada mode
12133 Ada_Version
:= Ada_2020
;
12134 Ada_Version_Explicit
:= Ada_2020
;
12135 Ada_Version_Pragma
:= N
;
12137 ----------------------
12138 -- All_Calls_Remote --
12139 ----------------------
12141 -- pragma All_Calls_Remote [(library_package_NAME)];
12143 when Pragma_All_Calls_Remote
=> All_Calls_Remote
: declare
12144 Lib_Entity
: Entity_Id
;
12147 Check_Ada_83_Warning
;
12148 Check_Valid_Library_Unit_Pragma
;
12150 if Nkind
(N
) = N_Null_Statement
then
12154 Lib_Entity
:= Find_Lib_Unit_Name
;
12156 -- A pragma that applies to a Ghost entity becomes Ghost for the
12157 -- purposes of legality checks and removal of ignored Ghost code.
12159 Mark_Ghost_Pragma
(N
, Lib_Entity
);
12161 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
12163 if Present
(Lib_Entity
) and then not Debug_Flag_U
then
12164 if not Is_Remote_Call_Interface
(Lib_Entity
) then
12165 Error_Pragma
("pragma% only apply to rci unit");
12167 -- Set flag for entity of the library unit
12170 Set_Has_All_Calls_Remote
(Lib_Entity
);
12173 end All_Calls_Remote
;
12175 ---------------------------
12176 -- Allow_Integer_Address --
12177 ---------------------------
12179 -- pragma Allow_Integer_Address;
12181 when Pragma_Allow_Integer_Address
=>
12183 Check_Valid_Configuration_Pragma
;
12184 Check_Arg_Count
(0);
12186 -- If Address is a private type, then set the flag to allow
12187 -- integer address values. If Address is not private, then this
12188 -- pragma has no purpose, so it is simply ignored. Not clear if
12189 -- there are any such targets now.
12191 if Opt
.Address_Is_Private
then
12192 Opt
.Allow_Integer_Address
:= True;
12200 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
12201 -- ARG ::= NAME | EXPRESSION
12203 -- The first two arguments are by convention intended to refer to an
12204 -- external tool and a tool-specific function. These arguments are
12207 when Pragma_Annotate
=> Annotate
: declare
12214 Check_At_Least_N_Arguments
(1);
12216 Nam_Arg
:= Last
(Pragma_Argument_Associations
(N
));
12218 -- Determine whether the last argument is "Entity => local_NAME"
12219 -- and if it is, perform the required semantic checks. Remove the
12220 -- argument from further processing.
12222 if Nkind
(Nam_Arg
) = N_Pragma_Argument_Association
12223 and then Chars
(Nam_Arg
) = Name_Entity
12225 Check_Arg_Is_Local_Name
(Nam_Arg
);
12226 Arg_Count
:= Arg_Count
- 1;
12228 -- A pragma that applies to a Ghost entity becomes Ghost for
12229 -- the purposes of legality checks and removal of ignored Ghost
12232 if Is_Entity_Name
(Get_Pragma_Arg
(Nam_Arg
))
12233 and then Present
(Entity
(Get_Pragma_Arg
(Nam_Arg
)))
12235 Mark_Ghost_Pragma
(N
, Entity
(Get_Pragma_Arg
(Nam_Arg
)));
12238 -- Not allowed in compiler units (bootstrap issues)
12240 Check_Compiler_Unit
("Entity for pragma Annotate", N
);
12243 -- Continue the processing with last argument removed for now
12245 Check_Arg_Is_Identifier
(Arg1
);
12246 Check_No_Identifiers
;
12249 -- The second parameter is optional, it is never analyzed
12254 -- Otherwise there is a second parameter
12257 -- The second parameter must be an identifier
12259 Check_Arg_Is_Identifier
(Arg2
);
12261 -- Process the remaining parameters (if any)
12263 Arg
:= Next
(Arg2
);
12264 while Present
(Arg
) loop
12265 Expr
:= Get_Pragma_Arg
(Arg
);
12268 if Is_Entity_Name
(Expr
) then
12271 -- For string literals, we assume Standard_String as the
12272 -- type, unless the string contains wide or wide_wide
12275 elsif Nkind
(Expr
) = N_String_Literal
then
12276 if Has_Wide_Wide_Character
(Expr
) then
12277 Resolve
(Expr
, Standard_Wide_Wide_String
);
12278 elsif Has_Wide_Character
(Expr
) then
12279 Resolve
(Expr
, Standard_Wide_String
);
12281 Resolve
(Expr
, Standard_String
);
12284 elsif Is_Overloaded
(Expr
) then
12285 Error_Pragma_Arg
("ambiguous argument for pragma%", Expr
);
12296 -------------------------------------------------
12297 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
12298 -------------------------------------------------
12301 -- ( [Check => ] Boolean_EXPRESSION
12302 -- [, [Message =>] Static_String_EXPRESSION]);
12304 -- pragma Assert_And_Cut
12305 -- ( [Check => ] Boolean_EXPRESSION
12306 -- [, [Message =>] Static_String_EXPRESSION]);
12309 -- ( [Check => ] Boolean_EXPRESSION
12310 -- [, [Message =>] Static_String_EXPRESSION]);
12312 -- pragma Loop_Invariant
12313 -- ( [Check => ] Boolean_EXPRESSION
12314 -- [, [Message =>] Static_String_EXPRESSION]);
12317 | Pragma_Assert_And_Cut
12319 | Pragma_Loop_Invariant
12322 function Contains_Loop_Entry
(Expr
: Node_Id
) return Boolean;
12323 -- Determine whether expression Expr contains a Loop_Entry
12324 -- attribute reference.
12326 -------------------------
12327 -- Contains_Loop_Entry --
12328 -------------------------
12330 function Contains_Loop_Entry
(Expr
: Node_Id
) return Boolean is
12331 Has_Loop_Entry
: Boolean := False;
12333 function Process
(N
: Node_Id
) return Traverse_Result
;
12334 -- Process function for traversal to look for Loop_Entry
12340 function Process
(N
: Node_Id
) return Traverse_Result
is
12342 if Nkind
(N
) = N_Attribute_Reference
12343 and then Attribute_Name
(N
) = Name_Loop_Entry
12345 Has_Loop_Entry
:= True;
12352 procedure Traverse
is new Traverse_Proc
(Process
);
12354 -- Start of processing for Contains_Loop_Entry
12358 return Has_Loop_Entry
;
12359 end Contains_Loop_Entry
;
12364 New_Args
: List_Id
;
12366 -- Start of processing for Assert
12369 -- Assert is an Ada 2005 RM-defined pragma
12371 if Prag_Id
= Pragma_Assert
then
12374 -- The remaining ones are GNAT pragmas
12380 Check_At_Least_N_Arguments
(1);
12381 Check_At_Most_N_Arguments
(2);
12382 Check_Arg_Order
((Name_Check
, Name_Message
));
12383 Check_Optional_Identifier
(Arg1
, Name_Check
);
12384 Expr
:= Get_Pragma_Arg
(Arg1
);
12386 -- Special processing for Loop_Invariant, Loop_Variant or for
12387 -- other cases where a Loop_Entry attribute is present. If the
12388 -- assertion pragma contains attribute Loop_Entry, ensure that
12389 -- the related pragma is within a loop.
12391 if Prag_Id
= Pragma_Loop_Invariant
12392 or else Prag_Id
= Pragma_Loop_Variant
12393 or else Contains_Loop_Entry
(Expr
)
12395 Check_Loop_Pragma_Placement
;
12397 -- Perform preanalysis to deal with embedded Loop_Entry
12400 Preanalyze_Assert_Expression
(Expr
, Any_Boolean
);
12403 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
12404 -- a corresponding Check pragma:
12406 -- pragma Check (name, condition [, msg]);
12408 -- Where name is the identifier matching the pragma name. So
12409 -- rewrite pragma in this manner, transfer the message argument
12410 -- if present, and analyze the result
12412 -- Note: When dealing with a semantically analyzed tree, the
12413 -- information that a Check node N corresponds to a source Assert,
12414 -- Assume, or Assert_And_Cut pragma can be retrieved from the
12415 -- pragma kind of Original_Node(N).
12417 New_Args
:= New_List
(
12418 Make_Pragma_Argument_Association
(Loc
,
12419 Expression
=> Make_Identifier
(Loc
, Pname
)),
12420 Make_Pragma_Argument_Association
(Sloc
(Expr
),
12421 Expression
=> Expr
));
12423 if Arg_Count
> 1 then
12424 Check_Optional_Identifier
(Arg2
, Name_Message
);
12426 -- Provide semantic annnotations for optional argument, for
12427 -- ASIS use, before rewriting.
12429 Preanalyze_And_Resolve
(Expression
(Arg2
), Standard_String
);
12430 Append_To
(New_Args
, New_Copy_Tree
(Arg2
));
12433 -- Rewrite as Check pragma
12437 Chars
=> Name_Check
,
12438 Pragma_Argument_Associations
=> New_Args
));
12443 ----------------------
12444 -- Assertion_Policy --
12445 ----------------------
12447 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
12449 -- The following form is Ada 2012 only, but we allow it in all modes
12451 -- Pragma Assertion_Policy (
12452 -- ASSERTION_KIND => POLICY_IDENTIFIER
12453 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
12455 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
12457 -- RM_ASSERTION_KIND ::= Assert |
12458 -- Static_Predicate |
12459 -- Dynamic_Predicate |
12464 -- Type_Invariant |
12465 -- Type_Invariant'Class
12467 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
12469 -- Contract_Cases |
12471 -- Default_Initial_Condition |
12473 -- Initial_Condition |
12474 -- Loop_Invariant |
12480 -- Statement_Assertions
12482 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
12483 -- ID_ASSERTION_KIND list contains implementation-defined additions
12484 -- recognized by GNAT. The effect is to control the behavior of
12485 -- identically named aspects and pragmas, depending on the specified
12486 -- policy identifier:
12488 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
12490 -- Note: Check and Ignore are language-defined. Disable is a GNAT
12491 -- implementation-defined addition that results in totally ignoring
12492 -- the corresponding assertion. If Disable is specified, then the
12493 -- argument of the assertion is not even analyzed. This is useful
12494 -- when the aspect/pragma argument references entities in a with'ed
12495 -- package that is replaced by a dummy package in the final build.
12497 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
12498 -- and Type_Invariant'Class were recognized by the parser and
12499 -- transformed into references to the special internal identifiers
12500 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
12501 -- processing is required here.
12503 when Pragma_Assertion_Policy
=> Assertion_Policy
: declare
12504 procedure Resolve_Suppressible
(Policy
: Node_Id
);
12505 -- Converts the assertion policy 'Suppressible' to either Check or
12506 -- Ignore based on whether checks are suppressed via -gnatp.
12508 --------------------------
12509 -- Resolve_Suppressible --
12510 --------------------------
12512 procedure Resolve_Suppressible
(Policy
: Node_Id
) is
12513 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Policy
);
12517 -- Transform policy argument Suppressible into either Ignore or
12518 -- Check depending on whether checks are enabled or suppressed.
12520 if Chars
(Arg
) = Name_Suppressible
then
12521 if Suppress_Checks
then
12522 Nam
:= Name_Ignore
;
12527 Rewrite
(Arg
, Make_Identifier
(Sloc
(Arg
), Nam
));
12529 end Resolve_Suppressible
;
12541 -- This can always appear as a configuration pragma
12543 if Is_Configuration_Pragma
then
12546 -- It can also appear in a declarative part or package spec in Ada
12547 -- 2012 mode. We allow this in other modes, but in that case we
12548 -- consider that we have an Ada 2012 pragma on our hands.
12551 Check_Is_In_Decl_Part_Or_Package_Spec
;
12555 -- One argument case with no identifier (first form above)
12558 and then (Nkind
(Arg1
) /= N_Pragma_Argument_Association
12559 or else Chars
(Arg1
) = No_Name
)
12561 Check_Arg_Is_One_Of
(Arg1
,
12562 Name_Check
, Name_Disable
, Name_Ignore
, Name_Suppressible
);
12564 Resolve_Suppressible
(Arg1
);
12566 -- Treat one argument Assertion_Policy as equivalent to:
12568 -- pragma Check_Policy (Assertion, policy)
12570 -- So rewrite pragma in that manner and link on to the chain
12571 -- of Check_Policy pragmas, marking the pragma as analyzed.
12573 Policy
:= Get_Pragma_Arg
(Arg1
);
12577 Chars
=> Name_Check_Policy
,
12578 Pragma_Argument_Associations
=> New_List
(
12579 Make_Pragma_Argument_Association
(Loc
,
12580 Expression
=> Make_Identifier
(Loc
, Name_Assertion
)),
12582 Make_Pragma_Argument_Association
(Loc
,
12584 Make_Identifier
(Sloc
(Policy
), Chars
(Policy
))))));
12587 -- Here if we have two or more arguments
12590 Check_At_Least_N_Arguments
(1);
12593 -- Loop through arguments
12596 while Present
(Arg
) loop
12597 LocP
:= Sloc
(Arg
);
12599 -- Kind must be specified
12601 if Nkind
(Arg
) /= N_Pragma_Argument_Association
12602 or else Chars
(Arg
) = No_Name
12605 ("missing assertion kind for pragma%", Arg
);
12608 -- Check Kind and Policy have allowed forms
12610 Kind
:= Chars
(Arg
);
12611 Policy
:= Get_Pragma_Arg
(Arg
);
12613 if not Is_Valid_Assertion_Kind
(Kind
) then
12615 ("invalid assertion kind for pragma%", Arg
);
12618 Check_Arg_Is_One_Of
(Arg
,
12619 Name_Check
, Name_Disable
, Name_Ignore
, Name_Suppressible
);
12621 Resolve_Suppressible
(Arg
);
12623 if Kind
= Name_Ghost
then
12625 -- The Ghost policy must be either Check or Ignore
12626 -- (SPARK RM 6.9(6)).
12628 if not Nam_In
(Chars
(Policy
), Name_Check
,
12632 ("argument of pragma % Ghost must be Check or "
12633 & "Ignore", Policy
);
12636 -- Pragma Assertion_Policy specifying a Ghost policy
12637 -- cannot occur within a Ghost subprogram or package
12638 -- (SPARK RM 6.9(14)).
12640 if Ghost_Mode
> None
then
12642 ("pragma % cannot appear within ghost subprogram or "
12647 -- Rewrite the Assertion_Policy pragma as a series of
12648 -- Check_Policy pragmas of the form:
12650 -- Check_Policy (Kind, Policy);
12652 -- Note: the insertion of the pragmas cannot be done with
12653 -- Insert_Action because in the configuration case, there
12654 -- are no scopes on the scope stack and the mechanism will
12657 Insert_Before_And_Analyze
(N
,
12659 Chars
=> Name_Check_Policy
,
12660 Pragma_Argument_Associations
=> New_List
(
12661 Make_Pragma_Argument_Association
(LocP
,
12662 Expression
=> Make_Identifier
(LocP
, Kind
)),
12663 Make_Pragma_Argument_Association
(LocP
,
12664 Expression
=> Policy
))));
12669 -- Rewrite the Assertion_Policy pragma as null since we have
12670 -- now inserted all the equivalent Check pragmas.
12672 Rewrite
(N
, Make_Null_Statement
(Loc
));
12675 end Assertion_Policy
;
12677 ------------------------------
12678 -- Assume_No_Invalid_Values --
12679 ------------------------------
12681 -- pragma Assume_No_Invalid_Values (On | Off);
12683 when Pragma_Assume_No_Invalid_Values
=>
12685 Check_Valid_Configuration_Pragma
;
12686 Check_Arg_Count
(1);
12687 Check_No_Identifiers
;
12688 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
12690 if Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
then
12691 Assume_No_Invalid_Values
:= True;
12693 Assume_No_Invalid_Values
:= False;
12696 --------------------------
12697 -- Attribute_Definition --
12698 --------------------------
12700 -- pragma Attribute_Definition
12701 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
12702 -- [Entity =>] LOCAL_NAME,
12703 -- [Expression =>] EXPRESSION | NAME);
12705 when Pragma_Attribute_Definition
=> Attribute_Definition
: declare
12706 Attribute_Designator
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
12711 Check_Arg_Count
(3);
12712 Check_Optional_Identifier
(Arg1
, "attribute");
12713 Check_Optional_Identifier
(Arg2
, "entity");
12714 Check_Optional_Identifier
(Arg3
, "expression");
12716 if Nkind
(Attribute_Designator
) /= N_Identifier
then
12717 Error_Msg_N
("attribute name expected", Attribute_Designator
);
12721 Check_Arg_Is_Local_Name
(Arg2
);
12723 -- If the attribute is not recognized, then issue a warning (not
12724 -- an error), and ignore the pragma.
12726 Aname
:= Chars
(Attribute_Designator
);
12728 if not Is_Attribute_Name
(Aname
) then
12729 Bad_Attribute
(Attribute_Designator
, Aname
, Warn
=> True);
12733 -- Otherwise, rewrite the pragma as an attribute definition clause
12736 Make_Attribute_Definition_Clause
(Loc
,
12737 Name
=> Get_Pragma_Arg
(Arg2
),
12739 Expression
=> Get_Pragma_Arg
(Arg3
)));
12741 end Attribute_Definition
;
12743 ------------------------------------------------------------------
12744 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
12745 ------------------------------------------------------------------
12747 -- pragma Asynch_Readers [ (boolean_EXPRESSION) ];
12748 -- pragma Asynch_Writers [ (boolean_EXPRESSION) ];
12749 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
12750 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
12752 when Pragma_Async_Readers
12753 | Pragma_Async_Writers
12754 | Pragma_Effective_Reads
12755 | Pragma_Effective_Writes
12757 Async_Effective
: declare
12758 Obj_Decl
: Node_Id
;
12759 Obj_Id
: Entity_Id
;
12763 Check_No_Identifiers
;
12764 Check_At_Most_N_Arguments
(1);
12766 Obj_Decl
:= Find_Related_Context
(N
, Do_Checks
=> True);
12768 -- Object declaration
12770 if Nkind
(Obj_Decl
) = N_Object_Declaration
then
12773 -- Otherwise the pragma is associated with an illegal construact
12780 Obj_Id
:= Defining_Entity
(Obj_Decl
);
12782 -- Perform minimal verification to ensure that the argument is at
12783 -- least a variable. Subsequent finer grained checks will be done
12784 -- at the end of the declarative region the contains the pragma.
12786 if Ekind
(Obj_Id
) = E_Variable
then
12788 -- A pragma that applies to a Ghost entity becomes Ghost for
12789 -- the purposes of legality checks and removal of ignored Ghost
12792 Mark_Ghost_Pragma
(N
, Obj_Id
);
12794 -- Chain the pragma on the contract for further processing by
12795 -- Analyze_External_Property_In_Decl_Part.
12797 Add_Contract_Item
(N
, Obj_Id
);
12799 -- Analyze the Boolean expression (if any)
12801 if Present
(Arg1
) then
12802 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
12805 -- Otherwise the external property applies to a constant
12808 Error_Pragma
("pragma % must apply to a volatile object");
12810 end Async_Effective
;
12816 -- pragma Asynchronous (LOCAL_NAME);
12818 when Pragma_Asynchronous
=> Asynchronous
: declare
12821 Formal
: Entity_Id
;
12826 procedure Process_Async_Pragma
;
12827 -- Common processing for procedure and access-to-procedure case
12829 --------------------------
12830 -- Process_Async_Pragma --
12831 --------------------------
12833 procedure Process_Async_Pragma
is
12836 Set_Is_Asynchronous
(Nm
);
12840 -- The formals should be of mode IN (RM E.4.1(6))
12843 while Present
(S
) loop
12844 Formal
:= Defining_Identifier
(S
);
12846 if Nkind
(Formal
) = N_Defining_Identifier
12847 and then Ekind
(Formal
) /= E_In_Parameter
12850 ("pragma% procedure can only have IN parameter",
12857 Set_Is_Asynchronous
(Nm
);
12858 end Process_Async_Pragma
;
12860 -- Start of processing for pragma Asynchronous
12863 Check_Ada_83_Warning
;
12864 Check_No_Identifiers
;
12865 Check_Arg_Count
(1);
12866 Check_Arg_Is_Local_Name
(Arg1
);
12868 if Debug_Flag_U
then
12872 C_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
12873 Analyze
(Get_Pragma_Arg
(Arg1
));
12874 Nm
:= Entity
(Get_Pragma_Arg
(Arg1
));
12876 -- A pragma that applies to a Ghost entity becomes Ghost for the
12877 -- purposes of legality checks and removal of ignored Ghost code.
12879 Mark_Ghost_Pragma
(N
, Nm
);
12881 if not Is_Remote_Call_Interface
(C_Ent
)
12882 and then not Is_Remote_Types
(C_Ent
)
12884 -- This pragma should only appear in an RCI or Remote Types
12885 -- unit (RM E.4.1(4)).
12888 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
12891 if Ekind
(Nm
) = E_Procedure
12892 and then Nkind
(Parent
(Nm
)) = N_Procedure_Specification
12894 if not Is_Remote_Call_Interface
(Nm
) then
12896 ("pragma% cannot be applied on non-remote procedure",
12900 L
:= Parameter_Specifications
(Parent
(Nm
));
12901 Process_Async_Pragma
;
12904 elsif Ekind
(Nm
) = E_Function
then
12906 ("pragma% cannot be applied to function", Arg1
);
12908 elsif Is_Remote_Access_To_Subprogram_Type
(Nm
) then
12909 if Is_Record_Type
(Nm
) then
12911 -- A record type that is the Equivalent_Type for a remote
12912 -- access-to-subprogram type.
12914 Decl
:= Declaration_Node
(Corresponding_Remote_Type
(Nm
));
12917 -- A non-expanded RAS type (distribution is not enabled)
12919 Decl
:= Declaration_Node
(Nm
);
12922 if Nkind
(Decl
) = N_Full_Type_Declaration
12923 and then Nkind
(Type_Definition
(Decl
)) =
12924 N_Access_Procedure_Definition
12926 L
:= Parameter_Specifications
(Type_Definition
(Decl
));
12927 Process_Async_Pragma
;
12929 if Is_Asynchronous
(Nm
)
12930 and then Expander_Active
12931 and then Get_PCS_Name
/= Name_No_DSA
12933 RACW_Type_Is_Asynchronous
(Underlying_RACW_Type
(Nm
));
12938 ("pragma% cannot reference access-to-function type",
12942 -- Only other possibility is Access-to-class-wide type
12944 elsif Is_Access_Type
(Nm
)
12945 and then Is_Class_Wide_Type
(Designated_Type
(Nm
))
12947 Check_First_Subtype
(Arg1
);
12948 Set_Is_Asynchronous
(Nm
);
12949 if Expander_Active
then
12950 RACW_Type_Is_Asynchronous
(Nm
);
12954 Error_Pragma_Arg
("inappropriate argument for pragma%", Arg1
);
12962 -- pragma Atomic (LOCAL_NAME);
12964 when Pragma_Atomic
=>
12965 Process_Atomic_Independent_Shared_Volatile
;
12967 -----------------------
12968 -- Atomic_Components --
12969 -----------------------
12971 -- pragma Atomic_Components (array_LOCAL_NAME);
12973 -- This processing is shared by Volatile_Components
12975 when Pragma_Atomic_Components
12976 | Pragma_Volatile_Components
12978 Atomic_Components
: declare
12985 Check_Ada_83_Warning
;
12986 Check_No_Identifiers
;
12987 Check_Arg_Count
(1);
12988 Check_Arg_Is_Local_Name
(Arg1
);
12989 E_Id
:= Get_Pragma_Arg
(Arg1
);
12991 if Etype
(E_Id
) = Any_Type
then
12995 E
:= Entity
(E_Id
);
12997 -- A pragma that applies to a Ghost entity becomes Ghost for the
12998 -- purposes of legality checks and removal of ignored Ghost code.
13000 Mark_Ghost_Pragma
(N
, E
);
13001 Check_Duplicate_Pragma
(E
);
13003 if Rep_Item_Too_Early
(E
, N
)
13005 Rep_Item_Too_Late
(E
, N
)
13010 D
:= Declaration_Node
(E
);
13013 if (K
= N_Full_Type_Declaration
and then Is_Array_Type
(E
))
13015 ((Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
13016 and then Nkind
(D
) = N_Object_Declaration
13017 and then Nkind
(Object_Definition
(D
)) =
13018 N_Constrained_Array_Definition
)
13020 -- The flag is set on the object, or on the base type
13022 if Nkind
(D
) /= N_Object_Declaration
then
13023 E
:= Base_Type
(E
);
13026 -- Atomic implies both Independent and Volatile
13028 if Prag_Id
= Pragma_Atomic_Components
then
13029 Set_Has_Atomic_Components
(E
);
13030 Set_Has_Independent_Components
(E
);
13033 Set_Has_Volatile_Components
(E
);
13036 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
13038 end Atomic_Components
;
13040 --------------------
13041 -- Attach_Handler --
13042 --------------------
13044 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
13046 when Pragma_Attach_Handler
=>
13047 Check_Ada_83_Warning
;
13048 Check_No_Identifiers
;
13049 Check_Arg_Count
(2);
13051 if No_Run_Time_Mode
then
13052 Error_Msg_CRT
("Attach_Handler pragma", N
);
13054 Check_Interrupt_Or_Attach_Handler
;
13056 -- The expression that designates the attribute may depend on a
13057 -- discriminant, and is therefore a per-object expression, to
13058 -- be expanded in the init proc. If expansion is enabled, then
13059 -- perform semantic checks on a copy only.
13064 Parg2
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
13067 -- In Relaxed_RM_Semantics mode, we allow any static
13068 -- integer value, for compatibility with other compilers.
13070 if Relaxed_RM_Semantics
13071 and then Nkind
(Parg2
) = N_Integer_Literal
13073 Typ
:= Standard_Integer
;
13075 Typ
:= RTE
(RE_Interrupt_ID
);
13078 if Expander_Active
then
13079 Temp
:= New_Copy_Tree
(Parg2
);
13080 Set_Parent
(Temp
, N
);
13081 Preanalyze_And_Resolve
(Temp
, Typ
);
13084 Resolve
(Parg2
, Typ
);
13088 Process_Interrupt_Or_Attach_Handler
;
13091 --------------------
13092 -- C_Pass_By_Copy --
13093 --------------------
13095 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
13097 when Pragma_C_Pass_By_Copy
=> C_Pass_By_Copy
: declare
13103 Check_Valid_Configuration_Pragma
;
13104 Check_Arg_Count
(1);
13105 Check_Optional_Identifier
(Arg1
, "max_size");
13107 Arg
:= Get_Pragma_Arg
(Arg1
);
13108 Check_Arg_Is_OK_Static_Expression
(Arg
, Any_Integer
);
13110 Val
:= Expr_Value
(Arg
);
13114 ("maximum size for pragma% must be positive", Arg1
);
13116 elsif UI_Is_In_Int_Range
(Val
) then
13117 Default_C_Record_Mechanism
:= UI_To_Int
(Val
);
13119 -- If a giant value is given, Int'Last will do well enough.
13120 -- If sometime someone complains that a record larger than
13121 -- two gigabytes is not copied, we will worry about it then.
13124 Default_C_Record_Mechanism
:= Mechanism_Type
'Last;
13126 end C_Pass_By_Copy
;
13132 -- pragma Check ([Name =>] CHECK_KIND,
13133 -- [Check =>] Boolean_EXPRESSION
13134 -- [,[Message =>] String_EXPRESSION]);
13136 -- CHECK_KIND ::= IDENTIFIER |
13139 -- Invariant'Class |
13140 -- Type_Invariant'Class
13142 -- The identifiers Assertions and Statement_Assertions are not
13143 -- allowed, since they have special meaning for Check_Policy.
13145 -- WARNING: The code below manages Ghost regions. Return statements
13146 -- must be replaced by gotos which jump to the end of the code and
13147 -- restore the Ghost mode.
13149 when Pragma_Check
=> Check
: declare
13150 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
13151 -- Save the Ghost mode to restore on exit
13157 pragma Warnings
(Off
, Str
);
13160 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
13161 -- the mode now to ensure that any nodes generated during analysis
13162 -- and expansion are marked as Ghost.
13164 Set_Ghost_Mode
(N
);
13167 Check_At_Least_N_Arguments
(2);
13168 Check_At_Most_N_Arguments
(3);
13169 Check_Optional_Identifier
(Arg1
, Name_Name
);
13170 Check_Optional_Identifier
(Arg2
, Name_Check
);
13172 if Arg_Count
= 3 then
13173 Check_Optional_Identifier
(Arg3
, Name_Message
);
13174 Str
:= Get_Pragma_Arg
(Arg3
);
13177 Rewrite_Assertion_Kind
(Get_Pragma_Arg
(Arg1
));
13178 Check_Arg_Is_Identifier
(Arg1
);
13179 Cname
:= Chars
(Get_Pragma_Arg
(Arg1
));
13181 -- Check forbidden name Assertions or Statement_Assertions
13184 when Name_Assertions
=>
13186 ("""Assertions"" is not allowed as a check kind for "
13187 & "pragma%", Arg1
);
13189 when Name_Statement_Assertions
=>
13191 ("""Statement_Assertions"" is not allowed as a check kind "
13192 & "for pragma%", Arg1
);
13198 -- Check applicable policy. We skip this if Checked/Ignored status
13199 -- is already set (e.g. in the case of a pragma from an aspect).
13201 if Is_Checked
(N
) or else Is_Ignored
(N
) then
13204 -- For a non-source pragma that is a rewriting of another pragma,
13205 -- copy the Is_Checked/Ignored status from the rewritten pragma.
13207 elsif Is_Rewrite_Substitution
(N
)
13208 and then Nkind
(Original_Node
(N
)) = N_Pragma
13209 and then Original_Node
(N
) /= N
13211 Set_Is_Ignored
(N
, Is_Ignored
(Original_Node
(N
)));
13212 Set_Is_Checked
(N
, Is_Checked
(Original_Node
(N
)));
13214 -- Otherwise query the applicable policy at this point
13217 case Check_Kind
(Cname
) is
13218 when Name_Ignore
=>
13219 Set_Is_Ignored
(N
, True);
13220 Set_Is_Checked
(N
, False);
13223 Set_Is_Ignored
(N
, False);
13224 Set_Is_Checked
(N
, True);
13226 -- For disable, rewrite pragma as null statement and skip
13227 -- rest of the analysis of the pragma.
13229 when Name_Disable
=>
13230 Rewrite
(N
, Make_Null_Statement
(Loc
));
13234 -- No other possibilities
13237 raise Program_Error
;
13241 -- If check kind was not Disable, then continue pragma analysis
13243 Expr
:= Get_Pragma_Arg
(Arg2
);
13245 -- Deal with SCO generation
13247 if Is_Checked
(N
) and then not Split_PPC
(N
) then
13248 Set_SCO_Pragma_Enabled
(Loc
);
13251 -- Deal with analyzing the string argument. If checks are not
13252 -- on we don't want any expansion (since such expansion would
13253 -- not get properly deleted) but we do want to analyze (to get
13254 -- proper references). The Preanalyze_And_Resolve routine does
13255 -- just what we want. Ditto if pragma is active, because it will
13256 -- be rewritten as an if-statement whose analysis will complete
13257 -- analysis and expansion of the string message. This makes a
13258 -- difference in the unusual case where the expression for the
13259 -- string may have a side effect, such as raising an exception.
13260 -- This is mandated by RM 11.4.2, which specifies that the string
13261 -- expression is only evaluated if the check fails and
13262 -- Assertion_Error is to be raised.
13264 if Arg_Count
= 3 then
13265 Preanalyze_And_Resolve
(Str
, Standard_String
);
13268 -- Now you might think we could just do the same with the Boolean
13269 -- expression if checks are off (and expansion is on) and then
13270 -- rewrite the check as a null statement. This would work but we
13271 -- would lose the useful warnings about an assertion being bound
13272 -- to fail even if assertions are turned off.
13274 -- So instead we wrap the boolean expression in an if statement
13275 -- that looks like:
13277 -- if False and then condition then
13281 -- The reason we do this rewriting during semantic analysis rather
13282 -- than as part of normal expansion is that we cannot analyze and
13283 -- expand the code for the boolean expression directly, or it may
13284 -- cause insertion of actions that would escape the attempt to
13285 -- suppress the check code.
13287 -- Note that the Sloc for the if statement corresponds to the
13288 -- argument condition, not the pragma itself. The reason for
13289 -- this is that we may generate a warning if the condition is
13290 -- False at compile time, and we do not want to delete this
13291 -- warning when we delete the if statement.
13293 if Expander_Active
and Is_Ignored
(N
) then
13294 Eloc
:= Sloc
(Expr
);
13297 Make_If_Statement
(Eloc
,
13299 Make_And_Then
(Eloc
,
13300 Left_Opnd
=> Make_Identifier
(Eloc
, Name_False
),
13301 Right_Opnd
=> Expr
),
13302 Then_Statements
=> New_List
(
13303 Make_Null_Statement
(Eloc
))));
13305 -- Now go ahead and analyze the if statement
13307 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
13309 -- One rather special treatment. If we are now in Eliminated
13310 -- overflow mode, then suppress overflow checking since we do
13311 -- not want to drag in the bignum stuff if we are in Ignore
13312 -- mode anyway. This is particularly important if we are using
13313 -- a configurable run time that does not support bignum ops.
13315 if Scope_Suppress
.Overflow_Mode_Assertions
= Eliminated
then
13317 Svo
: constant Boolean :=
13318 Scope_Suppress
.Suppress
(Overflow_Check
);
13320 Scope_Suppress
.Overflow_Mode_Assertions
:= Strict
;
13321 Scope_Suppress
.Suppress
(Overflow_Check
) := True;
13323 Scope_Suppress
.Suppress
(Overflow_Check
) := Svo
;
13324 Scope_Suppress
.Overflow_Mode_Assertions
:= Eliminated
;
13327 -- Not that special case
13333 -- All done with this check
13335 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
13337 -- Check is active or expansion not active. In these cases we can
13338 -- just go ahead and analyze the boolean with no worries.
13341 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
13342 Analyze_And_Resolve
(Expr
, Any_Boolean
);
13343 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
13346 Restore_Ghost_Mode
(Saved_GM
);
13349 --------------------------
13350 -- Check_Float_Overflow --
13351 --------------------------
13353 -- pragma Check_Float_Overflow;
13355 when Pragma_Check_Float_Overflow
=>
13357 Check_Valid_Configuration_Pragma
;
13358 Check_Arg_Count
(0);
13359 Check_Float_Overflow
:= not Machine_Overflows_On_Target
;
13365 -- pragma Check_Name (check_IDENTIFIER);
13367 when Pragma_Check_Name
=>
13369 Check_No_Identifiers
;
13370 Check_Valid_Configuration_Pragma
;
13371 Check_Arg_Count
(1);
13372 Check_Arg_Is_Identifier
(Arg1
);
13375 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(Arg1
));
13378 for J
in Check_Names
.First
.. Check_Names
.Last
loop
13379 if Check_Names
.Table
(J
) = Nam
then
13384 Check_Names
.Append
(Nam
);
13391 -- This is the old style syntax, which is still allowed in all modes:
13393 -- pragma Check_Policy ([Name =>] CHECK_KIND
13394 -- [Policy =>] POLICY_IDENTIFIER);
13396 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
13398 -- CHECK_KIND ::= IDENTIFIER |
13401 -- Type_Invariant'Class |
13404 -- This is the new style syntax, compatible with Assertion_Policy
13405 -- and also allowed in all modes.
13407 -- Pragma Check_Policy (
13408 -- CHECK_KIND => POLICY_IDENTIFIER
13409 -- {, CHECK_KIND => POLICY_IDENTIFIER});
13411 -- Note: the identifiers Name and Policy are not allowed as
13412 -- Check_Kind values. This avoids ambiguities between the old and
13413 -- new form syntax.
13415 when Pragma_Check_Policy
=> Check_Policy
: declare
13420 Check_At_Least_N_Arguments
(1);
13422 -- A Check_Policy pragma can appear either as a configuration
13423 -- pragma, or in a declarative part or a package spec (see RM
13424 -- 11.5(5) for rules for Suppress/Unsuppress which are also
13425 -- followed for Check_Policy).
13427 if not Is_Configuration_Pragma
then
13428 Check_Is_In_Decl_Part_Or_Package_Spec
;
13431 -- Figure out if we have the old or new syntax. We have the
13432 -- old syntax if the first argument has no identifier, or the
13433 -- identifier is Name.
13435 if Nkind
(Arg1
) /= N_Pragma_Argument_Association
13436 or else Nam_In
(Chars
(Arg1
), No_Name
, Name_Name
)
13440 Check_Arg_Count
(2);
13441 Check_Optional_Identifier
(Arg1
, Name_Name
);
13442 Kind
:= Get_Pragma_Arg
(Arg1
);
13443 Rewrite_Assertion_Kind
(Kind
,
13444 From_Policy
=> Comes_From_Source
(N
));
13445 Check_Arg_Is_Identifier
(Arg1
);
13447 -- Check forbidden check kind
13449 if Nam_In
(Chars
(Kind
), Name_Name
, Name_Policy
) then
13450 Error_Msg_Name_2
:= Chars
(Kind
);
13452 ("pragma% does not allow% as check name", Arg1
);
13457 Check_Optional_Identifier
(Arg2
, Name_Policy
);
13458 Check_Arg_Is_One_Of
13460 Name_On
, Name_Off
, Name_Check
, Name_Disable
, Name_Ignore
);
13462 -- And chain pragma on the Check_Policy_List for search
13464 Set_Next_Pragma
(N
, Opt
.Check_Policy_List
);
13465 Opt
.Check_Policy_List
:= N
;
13467 -- For the new syntax, what we do is to convert each argument to
13468 -- an old syntax equivalent. We do that because we want to chain
13469 -- old style Check_Policy pragmas for the search (we don't want
13470 -- to have to deal with multiple arguments in the search).
13481 while Present
(Arg
) loop
13482 LocP
:= Sloc
(Arg
);
13483 Argx
:= Get_Pragma_Arg
(Arg
);
13485 -- Kind must be specified
13487 if Nkind
(Arg
) /= N_Pragma_Argument_Association
13488 or else Chars
(Arg
) = No_Name
13491 ("missing assertion kind for pragma%", Arg
);
13494 -- Construct equivalent old form syntax Check_Policy
13495 -- pragma and insert it to get remaining checks.
13499 Chars
=> Name_Check_Policy
,
13500 Pragma_Argument_Associations
=> New_List
(
13501 Make_Pragma_Argument_Association
(LocP
,
13503 Make_Identifier
(LocP
, Chars
(Arg
))),
13504 Make_Pragma_Argument_Association
(Sloc
(Argx
),
13505 Expression
=> Argx
)));
13509 -- For a configuration pragma, insert old form in
13510 -- the corresponding file.
13512 if Is_Configuration_Pragma
then
13513 Insert_After
(N
, New_P
);
13517 Insert_Action
(N
, New_P
);
13521 -- Rewrite original Check_Policy pragma to null, since we
13522 -- have converted it into a series of old syntax pragmas.
13524 Rewrite
(N
, Make_Null_Statement
(Loc
));
13534 -- pragma Comment (static_string_EXPRESSION)
13536 -- Processing for pragma Comment shares the circuitry for pragma
13537 -- Ident. The only differences are that Ident enforces a limit of 31
13538 -- characters on its argument, and also enforces limitations on
13539 -- placement for DEC compatibility. Pragma Comment shares neither of
13540 -- these restrictions.
13542 -------------------
13543 -- Common_Object --
13544 -------------------
13546 -- pragma Common_Object (
13547 -- [Internal =>] LOCAL_NAME
13548 -- [, [External =>] EXTERNAL_SYMBOL]
13549 -- [, [Size =>] EXTERNAL_SYMBOL]);
13551 -- Processing for this pragma is shared with Psect_Object
13553 ------------------------
13554 -- Compile_Time_Error --
13555 ------------------------
13557 -- pragma Compile_Time_Error
13558 -- (boolean_EXPRESSION, static_string_EXPRESSION);
13560 when Pragma_Compile_Time_Error
=>
13562 Process_Compile_Time_Warning_Or_Error
;
13564 --------------------------
13565 -- Compile_Time_Warning --
13566 --------------------------
13568 -- pragma Compile_Time_Warning
13569 -- (boolean_EXPRESSION, static_string_EXPRESSION);
13571 when Pragma_Compile_Time_Warning
=>
13573 Process_Compile_Time_Warning_Or_Error
;
13575 ---------------------------
13576 -- Compiler_Unit_Warning --
13577 ---------------------------
13579 -- pragma Compiler_Unit_Warning;
13583 -- Originally, we had only pragma Compiler_Unit, and it resulted in
13584 -- errors not warnings. This means that we had introduced a big extra
13585 -- inertia to compiler changes, since even if we implemented a new
13586 -- feature, and even if all versions to be used for bootstrapping
13587 -- implemented this new feature, we could not use it, since old
13588 -- compilers would give errors for using this feature in units
13589 -- having Compiler_Unit pragmas.
13591 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
13592 -- problem. We no longer have any units mentioning Compiler_Unit,
13593 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
13594 -- and thus generates a warning which can be ignored. So that deals
13595 -- with the problem of old compilers not implementing the newer form
13598 -- Newer compilers recognize the new pragma, but generate warning
13599 -- messages instead of errors, which again can be ignored in the
13600 -- case of an old compiler which implements a wanted new feature
13601 -- but at the time felt like warning about it for older compilers.
13603 -- We retain Compiler_Unit so that new compilers can be used to build
13604 -- older run-times that use this pragma. That's an unusual case, but
13605 -- it's easy enough to handle, so why not?
13607 when Pragma_Compiler_Unit
13608 | Pragma_Compiler_Unit_Warning
13611 Check_Arg_Count
(0);
13613 -- Only recognized in main unit
13615 if Current_Sem_Unit
= Main_Unit
then
13616 Compiler_Unit
:= True;
13619 -----------------------------
13620 -- Complete_Representation --
13621 -----------------------------
13623 -- pragma Complete_Representation;
13625 when Pragma_Complete_Representation
=>
13627 Check_Arg_Count
(0);
13629 if Nkind
(Parent
(N
)) /= N_Record_Representation_Clause
then
13631 ("pragma & must appear within record representation clause");
13634 ----------------------------
13635 -- Complex_Representation --
13636 ----------------------------
13638 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
13640 when Pragma_Complex_Representation
=> Complex_Representation
: declare
13647 Check_Arg_Count
(1);
13648 Check_Optional_Identifier
(Arg1
, Name_Entity
);
13649 Check_Arg_Is_Local_Name
(Arg1
);
13650 E_Id
:= Get_Pragma_Arg
(Arg1
);
13652 if Etype
(E_Id
) = Any_Type
then
13656 E
:= Entity
(E_Id
);
13658 if not Is_Record_Type
(E
) then
13660 ("argument for pragma% must be record type", Arg1
);
13663 Ent
:= First_Entity
(E
);
13666 or else No
(Next_Entity
(Ent
))
13667 or else Present
(Next_Entity
(Next_Entity
(Ent
)))
13668 or else not Is_Floating_Point_Type
(Etype
(Ent
))
13669 or else Etype
(Ent
) /= Etype
(Next_Entity
(Ent
))
13672 ("record for pragma% must have two fields of the same "
13673 & "floating-point type", Arg1
);
13676 Set_Has_Complex_Representation
(Base_Type
(E
));
13678 -- We need to treat the type has having a non-standard
13679 -- representation, for back-end purposes, even though in
13680 -- general a complex will have the default representation
13681 -- of a record with two real components.
13683 Set_Has_Non_Standard_Rep
(Base_Type
(E
));
13685 end Complex_Representation
;
13687 -------------------------
13688 -- Component_Alignment --
13689 -------------------------
13691 -- pragma Component_Alignment (
13692 -- [Form =>] ALIGNMENT_CHOICE
13693 -- [, [Name =>] type_LOCAL_NAME]);
13695 -- ALIGNMENT_CHOICE ::=
13697 -- | Component_Size_4
13701 when Pragma_Component_Alignment
=> Component_AlignmentP
: declare
13702 Args
: Args_List
(1 .. 2);
13703 Names
: constant Name_List
(1 .. 2) := (
13707 Form
: Node_Id
renames Args
(1);
13708 Name
: Node_Id
renames Args
(2);
13710 Atype
: Component_Alignment_Kind
;
13715 Gather_Associations
(Names
, Args
);
13718 Error_Pragma
("missing Form argument for pragma%");
13721 Check_Arg_Is_Identifier
(Form
);
13723 -- Get proper alignment, note that Default = Component_Size on all
13724 -- machines we have so far, and we want to set this value rather
13725 -- than the default value to indicate that it has been explicitly
13726 -- set (and thus will not get overridden by the default component
13727 -- alignment for the current scope)
13729 if Chars
(Form
) = Name_Component_Size
then
13730 Atype
:= Calign_Component_Size
;
13732 elsif Chars
(Form
) = Name_Component_Size_4
then
13733 Atype
:= Calign_Component_Size_4
;
13735 elsif Chars
(Form
) = Name_Default
then
13736 Atype
:= Calign_Component_Size
;
13738 elsif Chars
(Form
) = Name_Storage_Unit
then
13739 Atype
:= Calign_Storage_Unit
;
13743 ("invalid Form parameter for pragma%", Form
);
13746 -- The pragma appears in a configuration file
13748 if No
(Parent
(N
)) then
13749 Check_Valid_Configuration_Pragma
;
13751 -- Capture the component alignment in a global variable when
13752 -- the pragma appears in a configuration file. Note that the
13753 -- scope stack is empty at this point and cannot be used to
13754 -- store the alignment value.
13756 Configuration_Component_Alignment
:= Atype
;
13758 -- Case with no name, supplied, affects scope table entry
13760 elsif No
(Name
) then
13762 (Scope_Stack
.Last
).Component_Alignment_Default
:= Atype
;
13764 -- Case of name supplied
13767 Check_Arg_Is_Local_Name
(Name
);
13769 Typ
:= Entity
(Name
);
13772 or else Rep_Item_Too_Early
(Typ
, N
)
13776 Typ
:= Underlying_Type
(Typ
);
13779 if not Is_Record_Type
(Typ
)
13780 and then not Is_Array_Type
(Typ
)
13783 ("Name parameter of pragma% must identify record or "
13784 & "array type", Name
);
13787 -- An explicit Component_Alignment pragma overrides an
13788 -- implicit pragma Pack, but not an explicit one.
13790 if not Has_Pragma_Pack
(Base_Type
(Typ
)) then
13791 Set_Is_Packed
(Base_Type
(Typ
), False);
13792 Set_Component_Alignment
(Base_Type
(Typ
), Atype
);
13795 end Component_AlignmentP
;
13797 --------------------------------
13798 -- Constant_After_Elaboration --
13799 --------------------------------
13801 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
13803 when Pragma_Constant_After_Elaboration
=> Constant_After_Elaboration
:
13805 Obj_Decl
: Node_Id
;
13806 Obj_Id
: Entity_Id
;
13810 Check_No_Identifiers
;
13811 Check_At_Most_N_Arguments
(1);
13813 Obj_Decl
:= Find_Related_Context
(N
, Do_Checks
=> True);
13815 -- Object declaration
13817 if Nkind
(Obj_Decl
) = N_Object_Declaration
then
13820 -- Otherwise the pragma is associated with an illegal construct
13827 Obj_Id
:= Defining_Entity
(Obj_Decl
);
13829 -- The object declaration must be a library-level variable which
13830 -- is either explicitly initialized or obtains a value during the
13831 -- elaboration of a package body (SPARK RM 3.3.1).
13833 if Ekind
(Obj_Id
) = E_Variable
then
13834 if not Is_Library_Level_Entity
(Obj_Id
) then
13836 ("pragma % must apply to a library level variable");
13840 -- Otherwise the pragma applies to a constant, which is illegal
13843 Error_Pragma
("pragma % must apply to a variable declaration");
13847 -- A pragma that applies to a Ghost entity becomes Ghost for the
13848 -- purposes of legality checks and removal of ignored Ghost code.
13850 Mark_Ghost_Pragma
(N
, Obj_Id
);
13852 -- Chain the pragma on the contract for completeness
13854 Add_Contract_Item
(N
, Obj_Id
);
13856 -- Analyze the Boolean expression (if any)
13858 if Present
(Arg1
) then
13859 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
13861 end Constant_After_Elaboration
;
13863 --------------------
13864 -- Contract_Cases --
13865 --------------------
13867 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
13869 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
13871 -- CASE_GUARD ::= boolean_EXPRESSION | others
13873 -- CONSEQUENCE ::= boolean_EXPRESSION
13875 -- Characteristics:
13877 -- * Analysis - The annotation undergoes initial checks to verify
13878 -- the legal placement and context. Secondary checks preanalyze the
13881 -- Analyze_Contract_Cases_In_Decl_Part
13883 -- * Expansion - The annotation is expanded during the expansion of
13884 -- the related subprogram [body] contract as performed in:
13886 -- Expand_Subprogram_Contract
13888 -- * Template - The annotation utilizes the generic template of the
13889 -- related subprogram [body] when it is:
13891 -- aspect on subprogram declaration
13892 -- aspect on stand-alone subprogram body
13893 -- pragma on stand-alone subprogram body
13895 -- The annotation must prepare its own template when it is:
13897 -- pragma on subprogram declaration
13899 -- * Globals - Capture of global references must occur after full
13902 -- * Instance - The annotation is instantiated automatically when
13903 -- the related generic subprogram [body] is instantiated except for
13904 -- the "pragma on subprogram declaration" case. In that scenario
13905 -- the annotation must instantiate itself.
13907 when Pragma_Contract_Cases
=> Contract_Cases
: declare
13908 Spec_Id
: Entity_Id
;
13909 Subp_Decl
: Node_Id
;
13910 Subp_Spec
: Node_Id
;
13914 Check_No_Identifiers
;
13915 Check_Arg_Count
(1);
13917 -- Ensure the proper placement of the pragma. Contract_Cases must
13918 -- be associated with a subprogram declaration or a body that acts
13922 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
13926 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
13929 -- Generic subprogram
13931 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
13934 -- Body acts as spec
13936 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
13937 and then No
(Corresponding_Spec
(Subp_Decl
))
13941 -- Body stub acts as spec
13943 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
13944 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
13950 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
13951 Subp_Spec
:= Specification
(Subp_Decl
);
13953 -- Pragma Contract_Cases is forbidden on null procedures, as
13954 -- this may lead to potential ambiguities in behavior when
13955 -- interface null procedures are involved.
13957 if Nkind
(Subp_Spec
) = N_Procedure_Specification
13958 and then Null_Present
(Subp_Spec
)
13960 Error_Msg_N
(Fix_Error
13961 ("pragma % cannot apply to null procedure"), N
);
13970 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
13972 -- A pragma that applies to a Ghost entity becomes Ghost for the
13973 -- purposes of legality checks and removal of ignored Ghost code.
13975 Mark_Ghost_Pragma
(N
, Spec_Id
);
13976 Ensure_Aggregate_Form
(Get_Argument
(N
, Spec_Id
));
13978 -- Chain the pragma on the contract for further processing by
13979 -- Analyze_Contract_Cases_In_Decl_Part.
13981 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
13983 -- Fully analyze the pragma when it appears inside an entry
13984 -- or subprogram body because it cannot benefit from forward
13987 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
13989 N_Subprogram_Body_Stub
)
13991 -- The legality checks of pragma Contract_Cases are affected by
13992 -- the SPARK mode in effect and the volatility of the context.
13993 -- Analyze all pragmas in a specific order.
13995 Analyze_If_Present
(Pragma_SPARK_Mode
);
13996 Analyze_If_Present
(Pragma_Volatile_Function
);
13997 Analyze_Contract_Cases_In_Decl_Part
(N
);
13999 end Contract_Cases
;
14005 -- pragma Controlled (first_subtype_LOCAL_NAME);
14007 when Pragma_Controlled
=> Controlled
: declare
14011 Check_No_Identifiers
;
14012 Check_Arg_Count
(1);
14013 Check_Arg_Is_Local_Name
(Arg1
);
14014 Arg
:= Get_Pragma_Arg
(Arg1
);
14016 if not Is_Entity_Name
(Arg
)
14017 or else not Is_Access_Type
(Entity
(Arg
))
14019 Error_Pragma_Arg
("pragma% requires access type", Arg1
);
14021 Set_Has_Pragma_Controlled
(Base_Type
(Entity
(Arg
)));
14029 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
14030 -- [Entity =>] LOCAL_NAME);
14032 when Pragma_Convention
=> Convention
: declare
14035 pragma Warnings
(Off
, C
);
14036 pragma Warnings
(Off
, E
);
14039 Check_Arg_Order
((Name_Convention
, Name_Entity
));
14040 Check_Ada_83_Warning
;
14041 Check_Arg_Count
(2);
14042 Process_Convention
(C
, E
);
14044 -- A pragma that applies to a Ghost entity becomes Ghost for the
14045 -- purposes of legality checks and removal of ignored Ghost code.
14047 Mark_Ghost_Pragma
(N
, E
);
14050 ---------------------------
14051 -- Convention_Identifier --
14052 ---------------------------
14054 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
14055 -- [Convention =>] convention_IDENTIFIER);
14057 when Pragma_Convention_Identifier
=> Convention_Identifier
: declare
14063 Check_Arg_Order
((Name_Name
, Name_Convention
));
14064 Check_Arg_Count
(2);
14065 Check_Optional_Identifier
(Arg1
, Name_Name
);
14066 Check_Optional_Identifier
(Arg2
, Name_Convention
);
14067 Check_Arg_Is_Identifier
(Arg1
);
14068 Check_Arg_Is_Identifier
(Arg2
);
14069 Idnam
:= Chars
(Get_Pragma_Arg
(Arg1
));
14070 Cname
:= Chars
(Get_Pragma_Arg
(Arg2
));
14072 if Is_Convention_Name
(Cname
) then
14073 Record_Convention_Identifier
14074 (Idnam
, Get_Convention_Id
(Cname
));
14077 ("second arg for % pragma must be convention", Arg2
);
14079 end Convention_Identifier
;
14085 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
14087 when Pragma_CPP_Class
=>
14090 if Warn_On_Obsolescent_Feature
then
14092 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
14093 & "effect; replace it by pragma import?j?", N
);
14096 Check_Arg_Count
(1);
14100 Chars
=> Name_Import
,
14101 Pragma_Argument_Associations
=> New_List
(
14102 Make_Pragma_Argument_Association
(Loc
,
14103 Expression
=> Make_Identifier
(Loc
, Name_CPP
)),
14104 New_Copy
(First
(Pragma_Argument_Associations
(N
))))));
14107 ---------------------
14108 -- CPP_Constructor --
14109 ---------------------
14111 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
14112 -- [, [External_Name =>] static_string_EXPRESSION ]
14113 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14115 when Pragma_CPP_Constructor
=> CPP_Constructor
: declare
14118 Def_Id
: Entity_Id
;
14119 Tag_Typ
: Entity_Id
;
14123 Check_At_Least_N_Arguments
(1);
14124 Check_At_Most_N_Arguments
(3);
14125 Check_Optional_Identifier
(Arg1
, Name_Entity
);
14126 Check_Arg_Is_Local_Name
(Arg1
);
14128 Id
:= Get_Pragma_Arg
(Arg1
);
14129 Find_Program_Unit_Name
(Id
);
14131 -- If we did not find the name, we are done
14133 if Etype
(Id
) = Any_Type
then
14137 Def_Id
:= Entity
(Id
);
14139 -- Check if already defined as constructor
14141 if Is_Constructor
(Def_Id
) then
14143 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1
);
14147 if Ekind
(Def_Id
) = E_Function
14148 and then (Is_CPP_Class
(Etype
(Def_Id
))
14149 or else (Is_Class_Wide_Type
(Etype
(Def_Id
))
14151 Is_CPP_Class
(Root_Type
(Etype
(Def_Id
)))))
14153 if Scope
(Def_Id
) /= Scope
(Etype
(Def_Id
)) then
14155 ("'C'P'P constructor must be defined in the scope of "
14156 & "its returned type", Arg1
);
14159 if Arg_Count
>= 2 then
14160 Set_Imported
(Def_Id
);
14161 Set_Is_Public
(Def_Id
);
14162 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
, N
);
14165 Set_Has_Completion
(Def_Id
);
14166 Set_Is_Constructor
(Def_Id
);
14167 Set_Convention
(Def_Id
, Convention_CPP
);
14169 -- Imported C++ constructors are not dispatching primitives
14170 -- because in C++ they don't have a dispatch table slot.
14171 -- However, in Ada the constructor has the profile of a
14172 -- function that returns a tagged type and therefore it has
14173 -- been treated as a primitive operation during semantic
14174 -- analysis. We now remove it from the list of primitive
14175 -- operations of the type.
14177 if Is_Tagged_Type
(Etype
(Def_Id
))
14178 and then not Is_Class_Wide_Type
(Etype
(Def_Id
))
14179 and then Is_Dispatching_Operation
(Def_Id
)
14181 Tag_Typ
:= Etype
(Def_Id
);
14183 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
14184 while Present
(Elmt
) and then Node
(Elmt
) /= Def_Id
loop
14188 Remove_Elmt
(Primitive_Operations
(Tag_Typ
), Elmt
);
14189 Set_Is_Dispatching_Operation
(Def_Id
, False);
14192 -- For backward compatibility, if the constructor returns a
14193 -- class wide type, and we internally change the return type to
14194 -- the corresponding root type.
14196 if Is_Class_Wide_Type
(Etype
(Def_Id
)) then
14197 Set_Etype
(Def_Id
, Root_Type
(Etype
(Def_Id
)));
14201 ("pragma% requires function returning a 'C'P'P_Class type",
14204 end CPP_Constructor
;
14210 when Pragma_CPP_Virtual
=>
14213 if Warn_On_Obsolescent_Feature
then
14215 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
14223 when Pragma_CPP_Vtable
=>
14226 if Warn_On_Obsolescent_Feature
then
14228 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
14236 -- pragma CPU (EXPRESSION);
14238 when Pragma_CPU
=> CPU
: declare
14239 P
: constant Node_Id
:= Parent
(N
);
14245 Check_No_Identifiers
;
14246 Check_Arg_Count
(1);
14250 if Nkind
(P
) = N_Subprogram_Body
then
14251 Check_In_Main_Program
;
14253 Arg
:= Get_Pragma_Arg
(Arg1
);
14254 Analyze_And_Resolve
(Arg
, Any_Integer
);
14256 Ent
:= Defining_Unit_Name
(Specification
(P
));
14258 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
14259 Ent
:= Defining_Identifier
(Ent
);
14264 if not Is_OK_Static_Expression
(Arg
) then
14265 Flag_Non_Static_Expr
14266 ("main subprogram affinity is not static!", Arg
);
14269 -- If constraint error, then we already signalled an error
14271 elsif Raises_Constraint_Error
(Arg
) then
14274 -- Otherwise check in range
14278 CPU_Id
: constant Entity_Id
:= RTE
(RE_CPU_Range
);
14279 -- This is the entity System.Multiprocessors.CPU_Range;
14281 Val
: constant Uint
:= Expr_Value
(Arg
);
14284 if Val
< Expr_Value
(Type_Low_Bound
(CPU_Id
))
14286 Val
> Expr_Value
(Type_High_Bound
(CPU_Id
))
14289 ("main subprogram CPU is out of range", Arg1
);
14295 (Current_Sem_Unit
, UI_To_Int
(Expr_Value
(Arg
)));
14299 elsif Nkind
(P
) = N_Task_Definition
then
14300 Arg
:= Get_Pragma_Arg
(Arg1
);
14301 Ent
:= Defining_Identifier
(Parent
(P
));
14303 -- The expression must be analyzed in the special manner
14304 -- described in "Handling of Default and Per-Object
14305 -- Expressions" in sem.ads.
14307 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_CPU_Range
));
14309 -- Anything else is incorrect
14315 -- Check duplicate pragma before we chain the pragma in the Rep
14316 -- Item chain of Ent.
14318 Check_Duplicate_Pragma
(Ent
);
14319 Record_Rep_Item
(Ent
, N
);
14322 --------------------
14323 -- Deadline_Floor --
14324 --------------------
14326 -- pragma Deadline_Floor (time_span_EXPRESSION);
14328 when Pragma_Deadline_Floor
=> Deadline_Floor
: declare
14329 P
: constant Node_Id
:= Parent
(N
);
14335 Check_No_Identifiers
;
14336 Check_Arg_Count
(1);
14338 Arg
:= Get_Pragma_Arg
(Arg1
);
14340 -- The expression must be analyzed in the special manner described
14341 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
14343 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Time_Span
));
14345 -- Only protected types allowed
14347 if Nkind
(P
) /= N_Protected_Definition
then
14351 Ent
:= Defining_Identifier
(Parent
(P
));
14353 -- Check duplicate pragma before we chain the pragma in the Rep
14354 -- Item chain of Ent.
14356 Check_Duplicate_Pragma
(Ent
);
14357 Record_Rep_Item
(Ent
, N
);
14359 end Deadline_Floor
;
14365 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
14367 when Pragma_Debug
=> Debug
: declare
14374 -- The condition for executing the call is that the expander
14375 -- is active and that we are not ignoring this debug pragma.
14380 (Expander_Active
and then not Is_Ignored
(N
)),
14383 if not Is_Ignored
(N
) then
14384 Set_SCO_Pragma_Enabled
(Loc
);
14387 if Arg_Count
= 2 then
14389 Make_And_Then
(Loc
,
14390 Left_Opnd
=> Relocate_Node
(Cond
),
14391 Right_Opnd
=> Get_Pragma_Arg
(Arg1
));
14392 Call
:= Get_Pragma_Arg
(Arg2
);
14394 Call
:= Get_Pragma_Arg
(Arg1
);
14397 if Nkind_In
(Call
, N_Expanded_Name
,
14400 N_Indexed_Component
,
14401 N_Selected_Component
)
14403 -- If this pragma Debug comes from source, its argument was
14404 -- parsed as a name form (which is syntactically identical).
14405 -- In a generic context a parameterless call will be left as
14406 -- an expanded name (if global) or selected_component if local.
14407 -- Change it to a procedure call statement now.
14409 Change_Name_To_Procedure_Call_Statement
(Call
);
14411 elsif Nkind
(Call
) = N_Procedure_Call_Statement
then
14413 -- Already in the form of a procedure call statement: nothing
14414 -- to do (could happen in case of an internally generated
14420 -- All other cases: diagnose error
14423 ("argument of pragma ""Debug"" is not procedure call",
14428 -- Rewrite into a conditional with an appropriate condition. We
14429 -- wrap the procedure call in a block so that overhead from e.g.
14430 -- use of the secondary stack does not generate execution overhead
14431 -- for suppressed conditions.
14433 -- Normally the analysis that follows will freeze the subprogram
14434 -- being called. However, if the call is to a null procedure,
14435 -- we want to freeze it before creating the block, because the
14436 -- analysis that follows may be done with expansion disabled, in
14437 -- which case the body will not be generated, leading to spurious
14440 if Nkind
(Call
) = N_Procedure_Call_Statement
14441 and then Is_Entity_Name
(Name
(Call
))
14443 Analyze
(Name
(Call
));
14444 Freeze_Before
(N
, Entity
(Name
(Call
)));
14448 Make_Implicit_If_Statement
(N
,
14450 Then_Statements
=> New_List
(
14451 Make_Block_Statement
(Loc
,
14452 Handled_Statement_Sequence
=>
14453 Make_Handled_Sequence_Of_Statements
(Loc
,
14454 Statements
=> New_List
(Relocate_Node
(Call
)))))));
14457 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
14458 -- after analysis of the normally rewritten node, to capture all
14459 -- references to entities, which avoids issuing wrong warnings
14460 -- about unused entities.
14462 if GNATprove_Mode
then
14463 Rewrite
(N
, Make_Null_Statement
(Loc
));
14471 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
14473 when Pragma_Debug_Policy
=>
14475 Check_Arg_Count
(1);
14476 Check_No_Identifiers
;
14477 Check_Arg_Is_Identifier
(Arg1
);
14479 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
14480 -- rewrite it that way, and let the rest of the checking come
14481 -- from analyzing the rewritten pragma.
14485 Chars
=> Name_Check_Policy
,
14486 Pragma_Argument_Associations
=> New_List
(
14487 Make_Pragma_Argument_Association
(Loc
,
14488 Expression
=> Make_Identifier
(Loc
, Name_Debug
)),
14490 Make_Pragma_Argument_Association
(Loc
,
14491 Expression
=> Get_Pragma_Arg
(Arg1
)))));
14494 -------------------------------
14495 -- Default_Initial_Condition --
14496 -------------------------------
14498 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
14500 when Pragma_Default_Initial_Condition
=> DIC
: declare
14507 Check_No_Identifiers
;
14508 Check_At_Most_N_Arguments
(1);
14512 while Present
(Stmt
) loop
14514 -- Skip prior pragmas, but check for duplicates
14516 if Nkind
(Stmt
) = N_Pragma
then
14517 if Pragma_Name
(Stmt
) = Pname
then
14524 -- Skip internally generated code. Note that derived type
14525 -- declarations of untagged types with discriminants are
14526 -- rewritten as private type declarations.
14528 elsif not Comes_From_Source
(Stmt
)
14529 and then Nkind
(Stmt
) /= N_Private_Type_Declaration
14533 -- The associated private type [extension] has been found, stop
14536 elsif Nkind_In
(Stmt
, N_Private_Extension_Declaration
,
14537 N_Private_Type_Declaration
)
14539 Typ
:= Defining_Entity
(Stmt
);
14542 -- The pragma does not apply to a legal construct, issue an
14543 -- error and stop the analysis.
14550 Stmt
:= Prev
(Stmt
);
14553 -- The pragma does not apply to a legal construct, issue an error
14554 -- and stop the analysis.
14561 -- A pragma that applies to a Ghost entity becomes Ghost for the
14562 -- purposes of legality checks and removal of ignored Ghost code.
14564 Mark_Ghost_Pragma
(N
, Typ
);
14566 -- The pragma signals that the type defines its own DIC assertion
14569 Set_Has_Own_DIC
(Typ
);
14571 -- Chain the pragma on the rep item chain for further processing
14573 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
14575 -- Create the declaration of the procedure which verifies the
14576 -- assertion expression of pragma DIC at runtime.
14578 Build_DIC_Procedure_Declaration
(Typ
);
14581 ----------------------------------
14582 -- Default_Scalar_Storage_Order --
14583 ----------------------------------
14585 -- pragma Default_Scalar_Storage_Order
14586 -- (High_Order_First | Low_Order_First);
14588 when Pragma_Default_Scalar_Storage_Order
=> DSSO
: declare
14589 Default
: Character;
14593 Check_Arg_Count
(1);
14595 -- Default_Scalar_Storage_Order can appear as a configuration
14596 -- pragma, or in a declarative part of a package spec.
14598 if not Is_Configuration_Pragma
then
14599 Check_Is_In_Decl_Part_Or_Package_Spec
;
14602 Check_No_Identifiers
;
14603 Check_Arg_Is_One_Of
14604 (Arg1
, Name_High_Order_First
, Name_Low_Order_First
);
14605 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
14606 Default
:= Fold_Upper
(Name_Buffer
(1));
14608 if not Support_Nondefault_SSO_On_Target
14609 and then (Ttypes
.Bytes_Big_Endian
/= (Default
= 'H'))
14611 if Warn_On_Unrecognized_Pragma
then
14613 ("non-default Scalar_Storage_Order not supported "
14614 & "on target?g?", N
);
14616 ("\pragma Default_Scalar_Storage_Order ignored?g?", N
);
14619 -- Here set the specified default
14622 Opt
.Default_SSO
:= Default
;
14626 --------------------------
14627 -- Default_Storage_Pool --
14628 --------------------------
14630 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
14632 when Pragma_Default_Storage_Pool
=> Default_Storage_Pool
: declare
14637 Check_Arg_Count
(1);
14639 -- Default_Storage_Pool can appear as a configuration pragma, or
14640 -- in a declarative part of a package spec.
14642 if not Is_Configuration_Pragma
then
14643 Check_Is_In_Decl_Part_Or_Package_Spec
;
14646 if From_Aspect_Specification
(N
) then
14648 E
: constant Entity_Id
:= Entity
(Corresponding_Aspect
(N
));
14650 if not In_Open_Scopes
(E
) then
14652 ("aspect must apply to package or subprogram", N
);
14657 if Present
(Arg1
) then
14658 Pool
:= Get_Pragma_Arg
(Arg1
);
14660 -- Case of Default_Storage_Pool (null);
14662 if Nkind
(Pool
) = N_Null
then
14665 -- This is an odd case, this is not really an expression,
14666 -- so we don't have a type for it. So just set the type to
14669 Set_Etype
(Pool
, Empty
);
14671 -- Case of Default_Storage_Pool (storage_pool_NAME);
14674 -- If it's a configuration pragma, then the only allowed
14675 -- argument is "null".
14677 if Is_Configuration_Pragma
then
14678 Error_Pragma_Arg
("NULL expected", Arg1
);
14681 -- The expected type for a non-"null" argument is
14682 -- Root_Storage_Pool'Class, and the pool must be a variable.
14684 Analyze_And_Resolve
14685 (Pool
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
14687 if Is_Variable
(Pool
) then
14689 -- A pragma that applies to a Ghost entity becomes Ghost
14690 -- for the purposes of legality checks and removal of
14691 -- ignored Ghost code.
14693 Mark_Ghost_Pragma
(N
, Entity
(Pool
));
14697 ("default storage pool must be a variable", Arg1
);
14701 -- Record the pool name (or null). Freeze.Freeze_Entity for an
14702 -- access type will use this information to set the appropriate
14703 -- attributes of the access type. If the pragma appears in a
14704 -- generic unit it is ignored, given that it may refer to a
14707 if not Inside_A_Generic
then
14708 Default_Pool
:= Pool
;
14711 end Default_Storage_Pool
;
14717 -- pragma Depends (DEPENDENCY_RELATION);
14719 -- DEPENDENCY_RELATION ::=
14721 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
14723 -- DEPENDENCY_CLAUSE ::=
14724 -- OUTPUT_LIST =>[+] INPUT_LIST
14725 -- | NULL_DEPENDENCY_CLAUSE
14727 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
14729 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
14731 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
14733 -- OUTPUT ::= NAME | FUNCTION_RESULT
14736 -- where FUNCTION_RESULT is a function Result attribute_reference
14738 -- Characteristics:
14740 -- * Analysis - The annotation undergoes initial checks to verify
14741 -- the legal placement and context. Secondary checks fully analyze
14742 -- the dependency clauses in:
14744 -- Analyze_Depends_In_Decl_Part
14746 -- * Expansion - None.
14748 -- * Template - The annotation utilizes the generic template of the
14749 -- related subprogram [body] when it is:
14751 -- aspect on subprogram declaration
14752 -- aspect on stand-alone subprogram body
14753 -- pragma on stand-alone subprogram body
14755 -- The annotation must prepare its own template when it is:
14757 -- pragma on subprogram declaration
14759 -- * Globals - Capture of global references must occur after full
14762 -- * Instance - The annotation is instantiated automatically when
14763 -- the related generic subprogram [body] is instantiated except for
14764 -- the "pragma on subprogram declaration" case. In that scenario
14765 -- the annotation must instantiate itself.
14767 when Pragma_Depends
=> Depends
: declare
14769 Spec_Id
: Entity_Id
;
14770 Subp_Decl
: Node_Id
;
14773 Analyze_Depends_Global
(Spec_Id
, Subp_Decl
, Legal
);
14777 -- Chain the pragma on the contract for further processing by
14778 -- Analyze_Depends_In_Decl_Part.
14780 Add_Contract_Item
(N
, Spec_Id
);
14782 -- Fully analyze the pragma when it appears inside an entry
14783 -- or subprogram body because it cannot benefit from forward
14786 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
14788 N_Subprogram_Body_Stub
)
14790 -- The legality checks of pragmas Depends and Global are
14791 -- affected by the SPARK mode in effect and the volatility
14792 -- of the context. In addition these two pragmas are subject
14793 -- to an inherent order:
14798 -- Analyze all these pragmas in the order outlined above
14800 Analyze_If_Present
(Pragma_SPARK_Mode
);
14801 Analyze_If_Present
(Pragma_Volatile_Function
);
14802 Analyze_If_Present
(Pragma_Global
);
14803 Analyze_Depends_In_Decl_Part
(N
);
14808 ---------------------
14809 -- Detect_Blocking --
14810 ---------------------
14812 -- pragma Detect_Blocking;
14814 when Pragma_Detect_Blocking
=>
14816 Check_Arg_Count
(0);
14817 Check_Valid_Configuration_Pragma
;
14818 Detect_Blocking
:= True;
14820 ------------------------------------
14821 -- Disable_Atomic_Synchronization --
14822 ------------------------------------
14824 -- pragma Disable_Atomic_Synchronization [(Entity)];
14826 when Pragma_Disable_Atomic_Synchronization
=>
14828 Process_Disable_Enable_Atomic_Sync
(Name_Suppress
);
14830 -------------------
14831 -- Discard_Names --
14832 -------------------
14834 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
14836 when Pragma_Discard_Names
=> Discard_Names
: declare
14841 Check_Ada_83_Warning
;
14843 -- Deal with configuration pragma case
14845 if Arg_Count
= 0 and then Is_Configuration_Pragma
then
14846 Global_Discard_Names
:= True;
14849 -- Otherwise, check correct appropriate context
14852 Check_Is_In_Decl_Part_Or_Package_Spec
;
14854 if Arg_Count
= 0 then
14856 -- If there is no parameter, then from now on this pragma
14857 -- applies to any enumeration, exception or tagged type
14858 -- defined in the current declarative part, and recursively
14859 -- to any nested scope.
14861 Set_Discard_Names
(Current_Scope
);
14865 Check_Arg_Count
(1);
14866 Check_Optional_Identifier
(Arg1
, Name_On
);
14867 Check_Arg_Is_Local_Name
(Arg1
);
14869 E_Id
:= Get_Pragma_Arg
(Arg1
);
14871 if Etype
(E_Id
) = Any_Type
then
14875 E
:= Entity
(E_Id
);
14877 -- A pragma that applies to a Ghost entity becomes Ghost for
14878 -- the purposes of legality checks and removal of ignored
14881 Mark_Ghost_Pragma
(N
, E
);
14883 if (Is_First_Subtype
(E
)
14885 (Is_Enumeration_Type
(E
) or else Is_Tagged_Type
(E
)))
14886 or else Ekind
(E
) = E_Exception
14888 Set_Discard_Names
(E
);
14889 Record_Rep_Item
(E
, N
);
14893 ("inappropriate entity for pragma%", Arg1
);
14899 ------------------------
14900 -- Dispatching_Domain --
14901 ------------------------
14903 -- pragma Dispatching_Domain (EXPRESSION);
14905 when Pragma_Dispatching_Domain
=> Dispatching_Domain
: declare
14906 P
: constant Node_Id
:= Parent
(N
);
14912 Check_No_Identifiers
;
14913 Check_Arg_Count
(1);
14915 -- This pragma is born obsolete, but not the aspect
14917 if not From_Aspect_Specification
(N
) then
14919 (No_Obsolescent_Features
, Pragma_Identifier
(N
));
14922 if Nkind
(P
) = N_Task_Definition
then
14923 Arg
:= Get_Pragma_Arg
(Arg1
);
14924 Ent
:= Defining_Identifier
(Parent
(P
));
14926 -- A pragma that applies to a Ghost entity becomes Ghost for
14927 -- the purposes of legality checks and removal of ignored Ghost
14930 Mark_Ghost_Pragma
(N
, Ent
);
14932 -- The expression must be analyzed in the special manner
14933 -- described in "Handling of Default and Per-Object
14934 -- Expressions" in sem.ads.
14936 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Dispatching_Domain
));
14938 -- Check duplicate pragma before we chain the pragma in the Rep
14939 -- Item chain of Ent.
14941 Check_Duplicate_Pragma
(Ent
);
14942 Record_Rep_Item
(Ent
, N
);
14944 -- Anything else is incorrect
14949 end Dispatching_Domain
;
14955 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
14957 when Pragma_Elaborate
=> Elaborate
: declare
14962 -- Pragma must be in context items list of a compilation unit
14964 if not Is_In_Context_Clause
then
14968 -- Must be at least one argument
14970 if Arg_Count
= 0 then
14971 Error_Pragma
("pragma% requires at least one argument");
14974 -- In Ada 83 mode, there can be no items following it in the
14975 -- context list except other pragmas and implicit with clauses
14976 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
14977 -- placement rule does not apply.
14979 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
14981 while Present
(Citem
) loop
14982 if Nkind
(Citem
) = N_Pragma
14983 or else (Nkind
(Citem
) = N_With_Clause
14984 and then Implicit_With
(Citem
))
14989 ("(Ada 83) pragma% must be at end of context clause");
14996 -- Finally, the arguments must all be units mentioned in a with
14997 -- clause in the same context clause. Note we already checked (in
14998 -- Par.Prag) that the arguments are all identifiers or selected
15002 Outer
: while Present
(Arg
) loop
15003 Citem
:= First
(List_Containing
(N
));
15004 Inner
: while Citem
/= N
loop
15005 if Nkind
(Citem
) = N_With_Clause
15006 and then Same_Name
(Name
(Citem
), Get_Pragma_Arg
(Arg
))
15008 Set_Elaborate_Present
(Citem
, True);
15009 Set_Elab_Unit_Name
(Get_Pragma_Arg
(Arg
), Name
(Citem
));
15019 ("argument of pragma% is not withed unit", Arg
);
15025 -- Give a warning if operating in static mode with one of the
15026 -- gnatwl/-gnatwE (elaboration warnings enabled) switches set.
15029 and not Dynamic_Elaboration_Checks
15031 -- pragma Elaborate not allowed in SPARK mode anyway. We
15032 -- already complained about it, no point in generating any
15033 -- further complaint.
15035 and SPARK_Mode
/= On
15038 ("?l?use of pragma Elaborate may not be safe", N
);
15040 ("?l?use pragma Elaborate_All instead if possible", N
);
15044 -------------------
15045 -- Elaborate_All --
15046 -------------------
15048 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
15050 when Pragma_Elaborate_All
=> Elaborate_All
: declare
15055 Check_Ada_83_Warning
;
15057 -- Pragma must be in context items list of a compilation unit
15059 if not Is_In_Context_Clause
then
15063 -- Must be at least one argument
15065 if Arg_Count
= 0 then
15066 Error_Pragma
("pragma% requires at least one argument");
15069 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
15070 -- have to appear at the end of the context clause, but may
15071 -- appear mixed in with other items, even in Ada 83 mode.
15073 -- Final check: the arguments must all be units mentioned in
15074 -- a with clause in the same context clause. Note that we
15075 -- already checked (in Par.Prag) that all the arguments are
15076 -- either identifiers or selected components.
15079 Outr
: while Present
(Arg
) loop
15080 Citem
:= First
(List_Containing
(N
));
15081 Innr
: while Citem
/= N
loop
15082 if Nkind
(Citem
) = N_With_Clause
15083 and then Same_Name
(Name
(Citem
), Get_Pragma_Arg
(Arg
))
15085 Set_Elaborate_All_Present
(Citem
, True);
15086 Set_Elab_Unit_Name
(Get_Pragma_Arg
(Arg
), Name
(Citem
));
15095 Set_Error_Posted
(N
);
15097 ("argument of pragma% is not withed unit", Arg
);
15104 --------------------
15105 -- Elaborate_Body --
15106 --------------------
15108 -- pragma Elaborate_Body [( library_unit_NAME )];
15110 when Pragma_Elaborate_Body
=> Elaborate_Body
: declare
15111 Cunit_Node
: Node_Id
;
15112 Cunit_Ent
: Entity_Id
;
15115 Check_Ada_83_Warning
;
15116 Check_Valid_Library_Unit_Pragma
;
15118 if Nkind
(N
) = N_Null_Statement
then
15122 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
15123 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
15125 -- A pragma that applies to a Ghost entity becomes Ghost for the
15126 -- purposes of legality checks and removal of ignored Ghost code.
15128 Mark_Ghost_Pragma
(N
, Cunit_Ent
);
15130 if Nkind_In
(Unit
(Cunit_Node
), N_Package_Body
,
15133 Error_Pragma
("pragma% must refer to a spec, not a body");
15135 Set_Body_Required
(Cunit_Node
);
15136 Set_Has_Pragma_Elaborate_Body
(Cunit_Ent
);
15138 end Elaborate_Body
;
15140 ------------------------
15141 -- Elaboration_Checks --
15142 ------------------------
15144 -- pragma Elaboration_Checks (Static | Dynamic);
15146 when Pragma_Elaboration_Checks
=>
15148 Check_Arg_Count
(1);
15149 Check_Arg_Is_One_Of
(Arg1
, Name_Static
, Name_Dynamic
);
15151 -- Set flag accordingly (ignore attempt at dynamic elaboration
15152 -- checks in SPARK mode).
15154 Dynamic_Elaboration_Checks
:=
15155 Chars
(Get_Pragma_Arg
(Arg1
)) = Name_Dynamic
;
15161 -- pragma Eliminate (
15162 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
15163 -- [Entity =>] IDENTIFIER |
15164 -- SELECTED_COMPONENT |
15166 -- [, Source_Location => SOURCE_TRACE]);
15168 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
15169 -- SOURCE_TRACE ::= STRING_LITERAL
15171 when Pragma_Eliminate
=> Eliminate
: declare
15172 Args
: Args_List
(1 .. 5);
15173 Names
: constant Name_List
(1 .. 5) := (
15176 Name_Parameter_Types
,
15178 Name_Source_Location
);
15180 -- Note : Parameter_Types and Result_Type are leftovers from
15181 -- prior implementations of the pragma. They are not generated
15182 -- by the gnatelim tool, and play no role in selecting which
15183 -- of a set of overloaded names is chosen for elimination.
15185 Unit_Name
: Node_Id
renames Args
(1);
15186 Entity
: Node_Id
renames Args
(2);
15187 Parameter_Types
: Node_Id
renames Args
(3);
15188 Result_Type
: Node_Id
renames Args
(4);
15189 Source_Location
: Node_Id
renames Args
(5);
15193 Check_Valid_Configuration_Pragma
;
15194 Gather_Associations
(Names
, Args
);
15196 if No
(Unit_Name
) then
15197 Error_Pragma
("missing Unit_Name argument for pragma%");
15201 and then (Present
(Parameter_Types
)
15203 Present
(Result_Type
)
15205 Present
(Source_Location
))
15207 Error_Pragma
("missing Entity argument for pragma%");
15210 if (Present
(Parameter_Types
)
15212 Present
(Result_Type
))
15214 Present
(Source_Location
)
15217 ("parameter profile and source location cannot be used "
15218 & "together in pragma%");
15221 Process_Eliminate_Pragma
15230 -----------------------------------
15231 -- Enable_Atomic_Synchronization --
15232 -----------------------------------
15234 -- pragma Enable_Atomic_Synchronization [(Entity)];
15236 when Pragma_Enable_Atomic_Synchronization
=>
15238 Process_Disable_Enable_Atomic_Sync
(Name_Unsuppress
);
15245 -- [ Convention =>] convention_IDENTIFIER,
15246 -- [ Entity =>] LOCAL_NAME
15247 -- [, [External_Name =>] static_string_EXPRESSION ]
15248 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15250 when Pragma_Export
=> Export
: declare
15252 Def_Id
: Entity_Id
;
15254 pragma Warnings
(Off
, C
);
15257 Check_Ada_83_Warning
;
15261 Name_External_Name
,
15264 Check_At_Least_N_Arguments
(2);
15265 Check_At_Most_N_Arguments
(4);
15267 -- In Relaxed_RM_Semantics, support old Ada 83 style:
15268 -- pragma Export (Entity, "external name");
15270 if Relaxed_RM_Semantics
15271 and then Arg_Count
= 2
15272 and then Nkind
(Expression
(Arg2
)) = N_String_Literal
15275 Def_Id
:= Get_Pragma_Arg
(Arg1
);
15278 if not Is_Entity_Name
(Def_Id
) then
15279 Error_Pragma_Arg
("entity name required", Arg1
);
15282 Def_Id
:= Entity
(Def_Id
);
15283 Set_Exported
(Def_Id
, Arg1
);
15286 Process_Convention
(C
, Def_Id
);
15288 -- A pragma that applies to a Ghost entity becomes Ghost for
15289 -- the purposes of legality checks and removal of ignored Ghost
15292 Mark_Ghost_Pragma
(N
, Def_Id
);
15294 if Ekind
(Def_Id
) /= E_Constant
then
15295 Note_Possible_Modification
15296 (Get_Pragma_Arg
(Arg2
), Sure
=> False);
15299 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
, N
);
15300 Set_Exported
(Def_Id
, Arg2
);
15303 -- If the entity is a deferred constant, propagate the information
15304 -- to the full view, because gigi elaborates the full view only.
15306 if Ekind
(Def_Id
) = E_Constant
15307 and then Present
(Full_View
(Def_Id
))
15310 Id2
: constant Entity_Id
:= Full_View
(Def_Id
);
15312 Set_Is_Exported
(Id2
, Is_Exported
(Def_Id
));
15313 Set_First_Rep_Item
(Id2
, First_Rep_Item
(Def_Id
));
15314 Set_Interface_Name
(Id2
, Einfo
.Interface_Name
(Def_Id
));
15319 ---------------------
15320 -- Export_Function --
15321 ---------------------
15323 -- pragma Export_Function (
15324 -- [Internal =>] LOCAL_NAME
15325 -- [, [External =>] EXTERNAL_SYMBOL]
15326 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15327 -- [, [Result_Type =>] TYPE_DESIGNATOR]
15328 -- [, [Mechanism =>] MECHANISM]
15329 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
15331 -- EXTERNAL_SYMBOL ::=
15333 -- | static_string_EXPRESSION
15335 -- PARAMETER_TYPES ::=
15337 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15339 -- TYPE_DESIGNATOR ::=
15341 -- | subtype_Name ' Access
15345 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15347 -- MECHANISM_ASSOCIATION ::=
15348 -- [formal_parameter_NAME =>] MECHANISM_NAME
15350 -- MECHANISM_NAME ::=
15354 when Pragma_Export_Function
=> Export_Function
: declare
15355 Args
: Args_List
(1 .. 6);
15356 Names
: constant Name_List
(1 .. 6) := (
15359 Name_Parameter_Types
,
15362 Name_Result_Mechanism
);
15364 Internal
: Node_Id
renames Args
(1);
15365 External
: Node_Id
renames Args
(2);
15366 Parameter_Types
: Node_Id
renames Args
(3);
15367 Result_Type
: Node_Id
renames Args
(4);
15368 Mechanism
: Node_Id
renames Args
(5);
15369 Result_Mechanism
: Node_Id
renames Args
(6);
15373 Gather_Associations
(Names
, Args
);
15374 Process_Extended_Import_Export_Subprogram_Pragma
(
15375 Arg_Internal
=> Internal
,
15376 Arg_External
=> External
,
15377 Arg_Parameter_Types
=> Parameter_Types
,
15378 Arg_Result_Type
=> Result_Type
,
15379 Arg_Mechanism
=> Mechanism
,
15380 Arg_Result_Mechanism
=> Result_Mechanism
);
15381 end Export_Function
;
15383 -------------------
15384 -- Export_Object --
15385 -------------------
15387 -- pragma Export_Object (
15388 -- [Internal =>] LOCAL_NAME
15389 -- [, [External =>] EXTERNAL_SYMBOL]
15390 -- [, [Size =>] EXTERNAL_SYMBOL]);
15392 -- EXTERNAL_SYMBOL ::=
15394 -- | static_string_EXPRESSION
15396 -- PARAMETER_TYPES ::=
15398 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15400 -- TYPE_DESIGNATOR ::=
15402 -- | subtype_Name ' Access
15406 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15408 -- MECHANISM_ASSOCIATION ::=
15409 -- [formal_parameter_NAME =>] MECHANISM_NAME
15411 -- MECHANISM_NAME ::=
15415 when Pragma_Export_Object
=> Export_Object
: declare
15416 Args
: Args_List
(1 .. 3);
15417 Names
: constant Name_List
(1 .. 3) := (
15422 Internal
: Node_Id
renames Args
(1);
15423 External
: Node_Id
renames Args
(2);
15424 Size
: Node_Id
renames Args
(3);
15428 Gather_Associations
(Names
, Args
);
15429 Process_Extended_Import_Export_Object_Pragma
(
15430 Arg_Internal
=> Internal
,
15431 Arg_External
=> External
,
15435 ----------------------
15436 -- Export_Procedure --
15437 ----------------------
15439 -- pragma Export_Procedure (
15440 -- [Internal =>] LOCAL_NAME
15441 -- [, [External =>] EXTERNAL_SYMBOL]
15442 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15443 -- [, [Mechanism =>] MECHANISM]);
15445 -- EXTERNAL_SYMBOL ::=
15447 -- | static_string_EXPRESSION
15449 -- PARAMETER_TYPES ::=
15451 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15453 -- TYPE_DESIGNATOR ::=
15455 -- | subtype_Name ' Access
15459 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15461 -- MECHANISM_ASSOCIATION ::=
15462 -- [formal_parameter_NAME =>] MECHANISM_NAME
15464 -- MECHANISM_NAME ::=
15468 when Pragma_Export_Procedure
=> Export_Procedure
: declare
15469 Args
: Args_List
(1 .. 4);
15470 Names
: constant Name_List
(1 .. 4) := (
15473 Name_Parameter_Types
,
15476 Internal
: Node_Id
renames Args
(1);
15477 External
: Node_Id
renames Args
(2);
15478 Parameter_Types
: Node_Id
renames Args
(3);
15479 Mechanism
: Node_Id
renames Args
(4);
15483 Gather_Associations
(Names
, Args
);
15484 Process_Extended_Import_Export_Subprogram_Pragma
(
15485 Arg_Internal
=> Internal
,
15486 Arg_External
=> External
,
15487 Arg_Parameter_Types
=> Parameter_Types
,
15488 Arg_Mechanism
=> Mechanism
);
15489 end Export_Procedure
;
15495 -- pragma Export_Value (
15496 -- [Value =>] static_integer_EXPRESSION,
15497 -- [Link_Name =>] static_string_EXPRESSION);
15499 when Pragma_Export_Value
=>
15501 Check_Arg_Order
((Name_Value
, Name_Link_Name
));
15502 Check_Arg_Count
(2);
15504 Check_Optional_Identifier
(Arg1
, Name_Value
);
15505 Check_Arg_Is_OK_Static_Expression
(Arg1
, Any_Integer
);
15507 Check_Optional_Identifier
(Arg2
, Name_Link_Name
);
15508 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
15510 -----------------------------
15511 -- Export_Valued_Procedure --
15512 -----------------------------
15514 -- pragma Export_Valued_Procedure (
15515 -- [Internal =>] LOCAL_NAME
15516 -- [, [External =>] EXTERNAL_SYMBOL,]
15517 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15518 -- [, [Mechanism =>] MECHANISM]);
15520 -- EXTERNAL_SYMBOL ::=
15522 -- | static_string_EXPRESSION
15524 -- PARAMETER_TYPES ::=
15526 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15528 -- TYPE_DESIGNATOR ::=
15530 -- | subtype_Name ' Access
15534 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15536 -- MECHANISM_ASSOCIATION ::=
15537 -- [formal_parameter_NAME =>] MECHANISM_NAME
15539 -- MECHANISM_NAME ::=
15543 when Pragma_Export_Valued_Procedure
=>
15544 Export_Valued_Procedure
: declare
15545 Args
: Args_List
(1 .. 4);
15546 Names
: constant Name_List
(1 .. 4) := (
15549 Name_Parameter_Types
,
15552 Internal
: Node_Id
renames Args
(1);
15553 External
: Node_Id
renames Args
(2);
15554 Parameter_Types
: Node_Id
renames Args
(3);
15555 Mechanism
: Node_Id
renames Args
(4);
15559 Gather_Associations
(Names
, Args
);
15560 Process_Extended_Import_Export_Subprogram_Pragma
(
15561 Arg_Internal
=> Internal
,
15562 Arg_External
=> External
,
15563 Arg_Parameter_Types
=> Parameter_Types
,
15564 Arg_Mechanism
=> Mechanism
);
15565 end Export_Valued_Procedure
;
15567 -------------------
15568 -- Extend_System --
15569 -------------------
15571 -- pragma Extend_System ([Name =>] Identifier);
15573 when Pragma_Extend_System
=>
15575 Check_Valid_Configuration_Pragma
;
15576 Check_Arg_Count
(1);
15577 Check_Optional_Identifier
(Arg1
, Name_Name
);
15578 Check_Arg_Is_Identifier
(Arg1
);
15580 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
15583 and then Name_Buffer
(1 .. 4) = "aux_"
15585 if Present
(System_Extend_Pragma_Arg
) then
15586 if Chars
(Get_Pragma_Arg
(Arg1
)) =
15587 Chars
(Expression
(System_Extend_Pragma_Arg
))
15591 Error_Msg_Sloc
:= Sloc
(System_Extend_Pragma_Arg
);
15592 Error_Pragma
("pragma% conflicts with that #");
15596 System_Extend_Pragma_Arg
:= Arg1
;
15598 if not GNAT_Mode
then
15599 System_Extend_Unit
:= Arg1
;
15603 Error_Pragma
("incorrect name for pragma%, must be Aux_xxx");
15606 ------------------------
15607 -- Extensions_Allowed --
15608 ------------------------
15610 -- pragma Extensions_Allowed (ON | OFF);
15612 when Pragma_Extensions_Allowed
=>
15614 Check_Arg_Count
(1);
15615 Check_No_Identifiers
;
15616 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
15618 if Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
then
15619 Extensions_Allowed
:= True;
15620 Ada_Version
:= Ada_Version_Type
'Last;
15623 Extensions_Allowed
:= False;
15624 Ada_Version
:= Ada_Version_Explicit
;
15625 Ada_Version_Pragma
:= Empty
;
15628 ------------------------
15629 -- Extensions_Visible --
15630 ------------------------
15632 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
15634 -- Characteristics:
15636 -- * Analysis - The annotation is fully analyzed immediately upon
15637 -- elaboration as its expression must be static.
15639 -- * Expansion - None.
15641 -- * Template - The annotation utilizes the generic template of the
15642 -- related subprogram [body] when it is:
15644 -- aspect on subprogram declaration
15645 -- aspect on stand-alone subprogram body
15646 -- pragma on stand-alone subprogram body
15648 -- The annotation must prepare its own template when it is:
15650 -- pragma on subprogram declaration
15652 -- * Globals - Capture of global references must occur after full
15655 -- * Instance - The annotation is instantiated automatically when
15656 -- the related generic subprogram [body] is instantiated except for
15657 -- the "pragma on subprogram declaration" case. In that scenario
15658 -- the annotation must instantiate itself.
15660 when Pragma_Extensions_Visible
=> Extensions_Visible
: declare
15661 Formal
: Entity_Id
;
15662 Has_OK_Formal
: Boolean := False;
15663 Spec_Id
: Entity_Id
;
15664 Subp_Decl
: Node_Id
;
15668 Check_No_Identifiers
;
15669 Check_At_Most_N_Arguments
(1);
15672 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
15674 -- Abstract subprogram declaration
15676 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
15679 -- Generic subprogram declaration
15681 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
15684 -- Body acts as spec
15686 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
15687 and then No
(Corresponding_Spec
(Subp_Decl
))
15691 -- Body stub acts as spec
15693 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
15694 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
15698 -- Subprogram declaration
15700 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
15703 -- Otherwise the pragma is associated with an illegal construct
15706 Error_Pragma
("pragma % must apply to a subprogram");
15710 -- Mark the pragma as Ghost if the related subprogram is also
15711 -- Ghost. This also ensures that any expansion performed further
15712 -- below will produce Ghost nodes.
15714 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
15715 Mark_Ghost_Pragma
(N
, Spec_Id
);
15717 -- Chain the pragma on the contract for completeness
15719 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
15721 -- The legality checks of pragma Extension_Visible are affected
15722 -- by the SPARK mode in effect. Analyze all pragmas in specific
15725 Analyze_If_Present
(Pragma_SPARK_Mode
);
15727 -- Examine the formals of the related subprogram
15729 Formal
:= First_Formal
(Spec_Id
);
15730 while Present
(Formal
) loop
15732 -- At least one of the formals is of a specific tagged type,
15733 -- the pragma is legal.
15735 if Is_Specific_Tagged_Type
(Etype
(Formal
)) then
15736 Has_OK_Formal
:= True;
15739 -- A generic subprogram with at least one formal of a private
15740 -- type ensures the legality of the pragma because the actual
15741 -- may be specifically tagged. Note that this is verified by
15742 -- the check above at instantiation time.
15744 elsif Is_Private_Type
(Etype
(Formal
))
15745 and then Is_Generic_Type
(Etype
(Formal
))
15747 Has_OK_Formal
:= True;
15751 Next_Formal
(Formal
);
15754 if not Has_OK_Formal
then
15755 Error_Msg_Name_1
:= Pname
;
15756 Error_Msg_N
(Fix_Error
("incorrect placement of pragma %"), N
);
15758 ("\subprogram & lacks parameter of specific tagged or "
15759 & "generic private type", N
, Spec_Id
);
15764 -- Analyze the Boolean expression (if any)
15766 if Present
(Arg1
) then
15767 Check_Static_Boolean_Expression
15768 (Expression
(Get_Argument
(N
, Spec_Id
)));
15770 end Extensions_Visible
;
15776 -- pragma External (
15777 -- [ Convention =>] convention_IDENTIFIER,
15778 -- [ Entity =>] LOCAL_NAME
15779 -- [, [External_Name =>] static_string_EXPRESSION ]
15780 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15782 when Pragma_External
=> External
: declare
15785 pragma Warnings
(Off
, C
);
15792 Name_External_Name
,
15794 Check_At_Least_N_Arguments
(2);
15795 Check_At_Most_N_Arguments
(4);
15796 Process_Convention
(C
, E
);
15798 -- A pragma that applies to a Ghost entity becomes Ghost for the
15799 -- purposes of legality checks and removal of ignored Ghost code.
15801 Mark_Ghost_Pragma
(N
, E
);
15803 Note_Possible_Modification
15804 (Get_Pragma_Arg
(Arg2
), Sure
=> False);
15805 Process_Interface_Name
(E
, Arg3
, Arg4
, N
);
15806 Set_Exported
(E
, Arg2
);
15809 --------------------------
15810 -- External_Name_Casing --
15811 --------------------------
15813 -- pragma External_Name_Casing (
15814 -- UPPERCASE | LOWERCASE
15815 -- [, AS_IS | UPPERCASE | LOWERCASE]);
15817 when Pragma_External_Name_Casing
=>
15819 Check_No_Identifiers
;
15821 if Arg_Count
= 2 then
15822 Check_Arg_Is_One_Of
15823 (Arg2
, Name_As_Is
, Name_Uppercase
, Name_Lowercase
);
15825 case Chars
(Get_Pragma_Arg
(Arg2
)) is
15827 Opt
.External_Name_Exp_Casing
:= As_Is
;
15829 when Name_Uppercase
=>
15830 Opt
.External_Name_Exp_Casing
:= Uppercase
;
15832 when Name_Lowercase
=>
15833 Opt
.External_Name_Exp_Casing
:= Lowercase
;
15840 Check_Arg_Count
(1);
15843 Check_Arg_Is_One_Of
(Arg1
, Name_Uppercase
, Name_Lowercase
);
15845 case Chars
(Get_Pragma_Arg
(Arg1
)) is
15846 when Name_Uppercase
=>
15847 Opt
.External_Name_Imp_Casing
:= Uppercase
;
15849 when Name_Lowercase
=>
15850 Opt
.External_Name_Imp_Casing
:= Lowercase
;
15860 -- pragma Fast_Math;
15862 when Pragma_Fast_Math
=>
15864 Check_No_Identifiers
;
15865 Check_Valid_Configuration_Pragma
;
15868 --------------------------
15869 -- Favor_Top_Level --
15870 --------------------------
15872 -- pragma Favor_Top_Level (type_NAME);
15874 when Pragma_Favor_Top_Level
=> Favor_Top_Level
: declare
15879 Check_No_Identifiers
;
15880 Check_Arg_Count
(1);
15881 Check_Arg_Is_Local_Name
(Arg1
);
15882 Typ
:= Entity
(Get_Pragma_Arg
(Arg1
));
15884 -- A pragma that applies to a Ghost entity becomes Ghost for the
15885 -- purposes of legality checks and removal of ignored Ghost code.
15887 Mark_Ghost_Pragma
(N
, Typ
);
15889 -- If it's an access-to-subprogram type (in particular, not a
15890 -- subtype), set the flag on that type.
15892 if Is_Access_Subprogram_Type
(Typ
) then
15893 Set_Can_Use_Internal_Rep
(Typ
, False);
15895 -- Otherwise it's an error (name denotes the wrong sort of entity)
15899 ("access-to-subprogram type expected",
15900 Get_Pragma_Arg
(Arg1
));
15902 end Favor_Top_Level
;
15904 ---------------------------
15905 -- Finalize_Storage_Only --
15906 ---------------------------
15908 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
15910 when Pragma_Finalize_Storage_Only
=> Finalize_Storage
: declare
15911 Assoc
: constant Node_Id
:= Arg1
;
15912 Type_Id
: constant Node_Id
:= Get_Pragma_Arg
(Assoc
);
15917 Check_No_Identifiers
;
15918 Check_Arg_Count
(1);
15919 Check_Arg_Is_Local_Name
(Arg1
);
15921 Find_Type
(Type_Id
);
15922 Typ
:= Entity
(Type_Id
);
15925 or else Rep_Item_Too_Early
(Typ
, N
)
15929 Typ
:= Underlying_Type
(Typ
);
15932 if not Is_Controlled
(Typ
) then
15933 Error_Pragma
("pragma% must specify controlled type");
15936 Check_First_Subtype
(Arg1
);
15938 if Finalize_Storage_Only
(Typ
) then
15939 Error_Pragma
("duplicate pragma%, only one allowed");
15941 elsif not Rep_Item_Too_Late
(Typ
, N
) then
15942 Set_Finalize_Storage_Only
(Base_Type
(Typ
), True);
15944 end Finalize_Storage
;
15950 -- pragma Ghost [ (boolean_EXPRESSION) ];
15952 when Pragma_Ghost
=> Ghost
: declare
15956 Orig_Stmt
: Node_Id
;
15957 Prev_Id
: Entity_Id
;
15962 Check_No_Identifiers
;
15963 Check_At_Most_N_Arguments
(1);
15967 while Present
(Stmt
) loop
15969 -- Skip prior pragmas, but check for duplicates
15971 if Nkind
(Stmt
) = N_Pragma
then
15972 if Pragma_Name
(Stmt
) = Pname
then
15979 -- Task unit declared without a definition cannot be subject to
15980 -- pragma Ghost (SPARK RM 6.9(19)).
15982 elsif Nkind_In
(Stmt
, N_Single_Task_Declaration
,
15983 N_Task_Type_Declaration
)
15985 Error_Pragma
("pragma % cannot apply to a task type");
15988 -- Skip internally generated code
15990 elsif not Comes_From_Source
(Stmt
) then
15991 Orig_Stmt
:= Original_Node
(Stmt
);
15993 -- When pragma Ghost applies to an untagged derivation, the
15994 -- derivation is transformed into a [sub]type declaration.
15996 if Nkind_In
(Stmt
, N_Full_Type_Declaration
,
15997 N_Subtype_Declaration
)
15998 and then Comes_From_Source
(Orig_Stmt
)
15999 and then Nkind
(Orig_Stmt
) = N_Full_Type_Declaration
16000 and then Nkind
(Type_Definition
(Orig_Stmt
)) =
16001 N_Derived_Type_Definition
16003 Id
:= Defining_Entity
(Stmt
);
16006 -- When pragma Ghost applies to an object declaration which
16007 -- is initialized by means of a function call that returns
16008 -- on the secondary stack, the object declaration becomes a
16011 elsif Nkind
(Stmt
) = N_Object_Renaming_Declaration
16012 and then Comes_From_Source
(Orig_Stmt
)
16013 and then Nkind
(Orig_Stmt
) = N_Object_Declaration
16015 Id
:= Defining_Entity
(Stmt
);
16018 -- When pragma Ghost applies to an expression function, the
16019 -- expression function is transformed into a subprogram.
16021 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
16022 and then Comes_From_Source
(Orig_Stmt
)
16023 and then Nkind
(Orig_Stmt
) = N_Expression_Function
16025 Id
:= Defining_Entity
(Stmt
);
16029 -- The pragma applies to a legal construct, stop the traversal
16031 elsif Nkind_In
(Stmt
, N_Abstract_Subprogram_Declaration
,
16032 N_Full_Type_Declaration
,
16033 N_Generic_Subprogram_Declaration
,
16034 N_Object_Declaration
,
16035 N_Private_Extension_Declaration
,
16036 N_Private_Type_Declaration
,
16037 N_Subprogram_Declaration
,
16038 N_Subtype_Declaration
)
16040 Id
:= Defining_Entity
(Stmt
);
16043 -- The pragma does not apply to a legal construct, issue an
16044 -- error and stop the analysis.
16048 ("pragma % must apply to an object, package, subprogram "
16053 Stmt
:= Prev
(Stmt
);
16056 Context
:= Parent
(N
);
16058 -- Handle compilation units
16060 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
16061 Context
:= Unit
(Parent
(Context
));
16064 -- Protected and task types cannot be subject to pragma Ghost
16065 -- (SPARK RM 6.9(19)).
16067 if Nkind_In
(Context
, N_Protected_Body
, N_Protected_Definition
)
16069 Error_Pragma
("pragma % cannot apply to a protected type");
16072 elsif Nkind_In
(Context
, N_Task_Body
, N_Task_Definition
) then
16073 Error_Pragma
("pragma % cannot apply to a task type");
16079 -- When pragma Ghost is associated with a [generic] package, it
16080 -- appears in the visible declarations.
16082 if Nkind
(Context
) = N_Package_Specification
16083 and then Present
(Visible_Declarations
(Context
))
16084 and then List_Containing
(N
) = Visible_Declarations
(Context
)
16086 Id
:= Defining_Entity
(Context
);
16088 -- Pragma Ghost applies to a stand-alone subprogram body
16090 elsif Nkind
(Context
) = N_Subprogram_Body
16091 and then No
(Corresponding_Spec
(Context
))
16093 Id
:= Defining_Entity
(Context
);
16095 -- Pragma Ghost applies to a subprogram declaration that acts
16096 -- as a compilation unit.
16098 elsif Nkind
(Context
) = N_Subprogram_Declaration
then
16099 Id
:= Defining_Entity
(Context
);
16101 -- Pragma Ghost applies to a generic subprogram
16103 elsif Nkind
(Context
) = N_Generic_Subprogram_Declaration
then
16104 Id
:= Defining_Entity
(Specification
(Context
));
16110 ("pragma % must apply to an object, package, subprogram or "
16115 -- Handle completions of types and constants that are subject to
16118 if Is_Record_Type
(Id
) or else Ekind
(Id
) = E_Constant
then
16119 Prev_Id
:= Incomplete_Or_Partial_View
(Id
);
16121 if Present
(Prev_Id
) and then not Is_Ghost_Entity
(Prev_Id
) then
16122 Error_Msg_Name_1
:= Pname
;
16124 -- The full declaration of a deferred constant cannot be
16125 -- subject to pragma Ghost unless the deferred declaration
16126 -- is also Ghost (SPARK RM 6.9(9)).
16128 if Ekind
(Prev_Id
) = E_Constant
then
16129 Error_Msg_Name_1
:= Pname
;
16130 Error_Msg_NE
(Fix_Error
16131 ("pragma % must apply to declaration of deferred "
16132 & "constant &"), N
, Id
);
16135 -- Pragma Ghost may appear on the full view of an incomplete
16136 -- type because the incomplete declaration lacks aspects and
16137 -- cannot be subject to pragma Ghost.
16139 elsif Ekind
(Prev_Id
) = E_Incomplete_Type
then
16142 -- The full declaration of a type cannot be subject to
16143 -- pragma Ghost unless the partial view is also Ghost
16144 -- (SPARK RM 6.9(9)).
16147 Error_Msg_NE
(Fix_Error
16148 ("pragma % must apply to partial view of type &"),
16154 -- A synchronized object cannot be subject to pragma Ghost
16155 -- (SPARK RM 6.9(19)).
16157 elsif Ekind
(Id
) = E_Variable
then
16158 if Is_Protected_Type
(Etype
(Id
)) then
16159 Error_Pragma
("pragma % cannot apply to a protected object");
16162 elsif Is_Task_Type
(Etype
(Id
)) then
16163 Error_Pragma
("pragma % cannot apply to a task object");
16168 -- Analyze the Boolean expression (if any)
16170 if Present
(Arg1
) then
16171 Expr
:= Get_Pragma_Arg
(Arg1
);
16173 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
16175 if Is_OK_Static_Expression
(Expr
) then
16177 -- "Ghostness" cannot be turned off once enabled within a
16178 -- region (SPARK RM 6.9(6)).
16180 if Is_False
(Expr_Value
(Expr
))
16181 and then Ghost_Mode
> None
16184 ("pragma % with value False cannot appear in enabled "
16189 -- Otherwie the expression is not static
16193 ("expression of pragma % must be static", Expr
);
16198 Set_Is_Ghost_Entity
(Id
);
16205 -- pragma Global (GLOBAL_SPECIFICATION);
16207 -- GLOBAL_SPECIFICATION ::=
16210 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
16212 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
16214 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
16215 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
16216 -- GLOBAL_ITEM ::= NAME
16218 -- Characteristics:
16220 -- * Analysis - The annotation undergoes initial checks to verify
16221 -- the legal placement and context. Secondary checks fully analyze
16222 -- the dependency clauses in:
16224 -- Analyze_Global_In_Decl_Part
16226 -- * Expansion - None.
16228 -- * Template - The annotation utilizes the generic template of the
16229 -- related subprogram [body] when it is:
16231 -- aspect on subprogram declaration
16232 -- aspect on stand-alone subprogram body
16233 -- pragma on stand-alone subprogram body
16235 -- The annotation must prepare its own template when it is:
16237 -- pragma on subprogram declaration
16239 -- * Globals - Capture of global references must occur after full
16242 -- * Instance - The annotation is instantiated automatically when
16243 -- the related generic subprogram [body] is instantiated except for
16244 -- the "pragma on subprogram declaration" case. In that scenario
16245 -- the annotation must instantiate itself.
16247 when Pragma_Global
=> Global
: declare
16249 Spec_Id
: Entity_Id
;
16250 Subp_Decl
: Node_Id
;
16253 Analyze_Depends_Global
(Spec_Id
, Subp_Decl
, Legal
);
16257 -- Chain the pragma on the contract for further processing by
16258 -- Analyze_Global_In_Decl_Part.
16260 Add_Contract_Item
(N
, Spec_Id
);
16262 -- Fully analyze the pragma when it appears inside an entry
16263 -- or subprogram body because it cannot benefit from forward
16266 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
16268 N_Subprogram_Body_Stub
)
16270 -- The legality checks of pragmas Depends and Global are
16271 -- affected by the SPARK mode in effect and the volatility
16272 -- of the context. In addition these two pragmas are subject
16273 -- to an inherent order:
16278 -- Analyze all these pragmas in the order outlined above
16280 Analyze_If_Present
(Pragma_SPARK_Mode
);
16281 Analyze_If_Present
(Pragma_Volatile_Function
);
16282 Analyze_Global_In_Decl_Part
(N
);
16283 Analyze_If_Present
(Pragma_Depends
);
16292 -- pragma Ident (static_string_EXPRESSION)
16294 -- Note: pragma Comment shares this processing. Pragma Ident is
16295 -- identical in effect to pragma Commment.
16297 when Pragma_Comment
16305 Check_Arg_Count
(1);
16306 Check_No_Identifiers
;
16307 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
16310 Str
:= Expr_Value_S
(Get_Pragma_Arg
(Arg1
));
16317 GP
:= Parent
(Parent
(N
));
16319 if Nkind_In
(GP
, N_Package_Declaration
,
16320 N_Generic_Package_Declaration
)
16325 -- If we have a compilation unit, then record the ident value,
16326 -- checking for improper duplication.
16328 if Nkind
(GP
) = N_Compilation_Unit
then
16329 CS
:= Ident_String
(Current_Sem_Unit
);
16331 if Present
(CS
) then
16333 -- If we have multiple instances, concatenate them, but
16334 -- not in ASIS, where we want the original tree.
16336 if not ASIS_Mode
then
16337 Start_String
(Strval
(CS
));
16338 Store_String_Char
(' ');
16339 Store_String_Chars
(Strval
(Str
));
16340 Set_Strval
(CS
, End_String
);
16344 Set_Ident_String
(Current_Sem_Unit
, Str
);
16347 -- For subunits, we just ignore the Ident, since in GNAT these
16348 -- are not separate object files, and hence not separate units
16349 -- in the unit table.
16351 elsif Nkind
(GP
) = N_Subunit
then
16357 -------------------
16358 -- Ignore_Pragma --
16359 -------------------
16361 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
16363 -- Entirely handled in the parser, nothing to do here
16365 when Pragma_Ignore_Pragma
=>
16368 ----------------------------
16369 -- Implementation_Defined --
16370 ----------------------------
16372 -- pragma Implementation_Defined (LOCAL_NAME);
16374 -- Marks previously declared entity as implementation defined. For
16375 -- an overloaded entity, applies to the most recent homonym.
16377 -- pragma Implementation_Defined;
16379 -- The form with no arguments appears anywhere within a scope, most
16380 -- typically a package spec, and indicates that all entities that are
16381 -- defined within the package spec are Implementation_Defined.
16383 when Pragma_Implementation_Defined
=> Implementation_Defined
: declare
16388 Check_No_Identifiers
;
16390 -- Form with no arguments
16392 if Arg_Count
= 0 then
16393 Set_Is_Implementation_Defined
(Current_Scope
);
16395 -- Form with one argument
16398 Check_Arg_Count
(1);
16399 Check_Arg_Is_Local_Name
(Arg1
);
16400 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
16401 Set_Is_Implementation_Defined
(Ent
);
16403 end Implementation_Defined
;
16409 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
16411 -- IMPLEMENTATION_KIND ::=
16412 -- By_Entry | By_Protected_Procedure | By_Any | Optional
16414 -- "By_Any" and "Optional" are treated as synonyms in order to
16415 -- support Ada 2012 aspect Synchronization.
16417 when Pragma_Implemented
=> Implemented
: declare
16418 Proc_Id
: Entity_Id
;
16423 Check_Arg_Count
(2);
16424 Check_No_Identifiers
;
16425 Check_Arg_Is_Identifier
(Arg1
);
16426 Check_Arg_Is_Local_Name
(Arg1
);
16427 Check_Arg_Is_One_Of
(Arg2
,
16430 Name_By_Protected_Procedure
,
16433 -- Extract the name of the local procedure
16435 Proc_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
16437 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
16438 -- primitive procedure of a synchronized tagged type.
16440 if Ekind
(Proc_Id
) = E_Procedure
16441 and then Is_Primitive
(Proc_Id
)
16442 and then Present
(First_Formal
(Proc_Id
))
16444 Typ
:= Etype
(First_Formal
(Proc_Id
));
16446 if Is_Tagged_Type
(Typ
)
16449 -- Check for a protected, a synchronized or a task interface
16451 ((Is_Interface
(Typ
)
16452 and then Is_Synchronized_Interface
(Typ
))
16454 -- Check for a protected type or a task type that implements
16458 (Is_Concurrent_Record_Type
(Typ
)
16459 and then Present
(Interfaces
(Typ
)))
16461 -- In analysis-only mode, examine original protected type
16464 (Nkind
(Parent
(Typ
)) = N_Protected_Type_Declaration
16465 and then Present
(Interface_List
(Parent
(Typ
))))
16467 -- Check for a private record extension with keyword
16471 (Ekind_In
(Typ
, E_Record_Type_With_Private
,
16472 E_Record_Subtype_With_Private
)
16473 and then Synchronized_Present
(Parent
(Typ
))))
16478 ("controlling formal must be of synchronized tagged type",
16483 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
16484 -- By_Protected_Procedure to the primitive procedure of a task
16487 if Chars
(Arg2
) = Name_By_Protected_Procedure
16488 and then Is_Interface
(Typ
)
16489 and then Is_Task_Interface
(Typ
)
16492 ("implementation kind By_Protected_Procedure cannot be "
16493 & "applied to a task interface primitive", Arg2
);
16497 -- Procedures declared inside a protected type must be accepted
16499 elsif Ekind
(Proc_Id
) = E_Procedure
16500 and then Is_Protected_Type
(Scope
(Proc_Id
))
16504 -- The first argument is not a primitive procedure
16508 ("pragma % must be applied to a primitive procedure", Arg1
);
16512 Record_Rep_Item
(Proc_Id
, N
);
16515 ----------------------
16516 -- Implicit_Packing --
16517 ----------------------
16519 -- pragma Implicit_Packing;
16521 when Pragma_Implicit_Packing
=>
16523 Check_Arg_Count
(0);
16524 Implicit_Packing
:= True;
16531 -- [Convention =>] convention_IDENTIFIER,
16532 -- [Entity =>] LOCAL_NAME
16533 -- [, [External_Name =>] static_string_EXPRESSION ]
16534 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16536 when Pragma_Import
=>
16537 Check_Ada_83_Warning
;
16541 Name_External_Name
,
16544 Check_At_Least_N_Arguments
(2);
16545 Check_At_Most_N_Arguments
(4);
16546 Process_Import_Or_Interface
;
16548 ---------------------
16549 -- Import_Function --
16550 ---------------------
16552 -- pragma Import_Function (
16553 -- [Internal =>] LOCAL_NAME,
16554 -- [, [External =>] EXTERNAL_SYMBOL]
16555 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16556 -- [, [Result_Type =>] SUBTYPE_MARK]
16557 -- [, [Mechanism =>] MECHANISM]
16558 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
16560 -- EXTERNAL_SYMBOL ::=
16562 -- | static_string_EXPRESSION
16564 -- PARAMETER_TYPES ::=
16566 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16568 -- TYPE_DESIGNATOR ::=
16570 -- | subtype_Name ' Access
16574 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16576 -- MECHANISM_ASSOCIATION ::=
16577 -- [formal_parameter_NAME =>] MECHANISM_NAME
16579 -- MECHANISM_NAME ::=
16583 when Pragma_Import_Function
=> Import_Function
: declare
16584 Args
: Args_List
(1 .. 6);
16585 Names
: constant Name_List
(1 .. 6) := (
16588 Name_Parameter_Types
,
16591 Name_Result_Mechanism
);
16593 Internal
: Node_Id
renames Args
(1);
16594 External
: Node_Id
renames Args
(2);
16595 Parameter_Types
: Node_Id
renames Args
(3);
16596 Result_Type
: Node_Id
renames Args
(4);
16597 Mechanism
: Node_Id
renames Args
(5);
16598 Result_Mechanism
: Node_Id
renames Args
(6);
16602 Gather_Associations
(Names
, Args
);
16603 Process_Extended_Import_Export_Subprogram_Pragma
(
16604 Arg_Internal
=> Internal
,
16605 Arg_External
=> External
,
16606 Arg_Parameter_Types
=> Parameter_Types
,
16607 Arg_Result_Type
=> Result_Type
,
16608 Arg_Mechanism
=> Mechanism
,
16609 Arg_Result_Mechanism
=> Result_Mechanism
);
16610 end Import_Function
;
16612 -------------------
16613 -- Import_Object --
16614 -------------------
16616 -- pragma Import_Object (
16617 -- [Internal =>] LOCAL_NAME
16618 -- [, [External =>] EXTERNAL_SYMBOL]
16619 -- [, [Size =>] EXTERNAL_SYMBOL]);
16621 -- EXTERNAL_SYMBOL ::=
16623 -- | static_string_EXPRESSION
16625 when Pragma_Import_Object
=> Import_Object
: declare
16626 Args
: Args_List
(1 .. 3);
16627 Names
: constant Name_List
(1 .. 3) := (
16632 Internal
: Node_Id
renames Args
(1);
16633 External
: Node_Id
renames Args
(2);
16634 Size
: Node_Id
renames Args
(3);
16638 Gather_Associations
(Names
, Args
);
16639 Process_Extended_Import_Export_Object_Pragma
(
16640 Arg_Internal
=> Internal
,
16641 Arg_External
=> External
,
16645 ----------------------
16646 -- Import_Procedure --
16647 ----------------------
16649 -- pragma Import_Procedure (
16650 -- [Internal =>] LOCAL_NAME
16651 -- [, [External =>] EXTERNAL_SYMBOL]
16652 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16653 -- [, [Mechanism =>] MECHANISM]);
16655 -- EXTERNAL_SYMBOL ::=
16657 -- | static_string_EXPRESSION
16659 -- PARAMETER_TYPES ::=
16661 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16663 -- TYPE_DESIGNATOR ::=
16665 -- | subtype_Name ' Access
16669 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16671 -- MECHANISM_ASSOCIATION ::=
16672 -- [formal_parameter_NAME =>] MECHANISM_NAME
16674 -- MECHANISM_NAME ::=
16678 when Pragma_Import_Procedure
=> Import_Procedure
: declare
16679 Args
: Args_List
(1 .. 4);
16680 Names
: constant Name_List
(1 .. 4) := (
16683 Name_Parameter_Types
,
16686 Internal
: Node_Id
renames Args
(1);
16687 External
: Node_Id
renames Args
(2);
16688 Parameter_Types
: Node_Id
renames Args
(3);
16689 Mechanism
: Node_Id
renames Args
(4);
16693 Gather_Associations
(Names
, Args
);
16694 Process_Extended_Import_Export_Subprogram_Pragma
(
16695 Arg_Internal
=> Internal
,
16696 Arg_External
=> External
,
16697 Arg_Parameter_Types
=> Parameter_Types
,
16698 Arg_Mechanism
=> Mechanism
);
16699 end Import_Procedure
;
16701 -----------------------------
16702 -- Import_Valued_Procedure --
16703 -----------------------------
16705 -- pragma Import_Valued_Procedure (
16706 -- [Internal =>] LOCAL_NAME
16707 -- [, [External =>] EXTERNAL_SYMBOL]
16708 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16709 -- [, [Mechanism =>] MECHANISM]);
16711 -- EXTERNAL_SYMBOL ::=
16713 -- | static_string_EXPRESSION
16715 -- PARAMETER_TYPES ::=
16717 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16719 -- TYPE_DESIGNATOR ::=
16721 -- | subtype_Name ' Access
16725 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16727 -- MECHANISM_ASSOCIATION ::=
16728 -- [formal_parameter_NAME =>] MECHANISM_NAME
16730 -- MECHANISM_NAME ::=
16734 when Pragma_Import_Valued_Procedure
=>
16735 Import_Valued_Procedure
: declare
16736 Args
: Args_List
(1 .. 4);
16737 Names
: constant Name_List
(1 .. 4) := (
16740 Name_Parameter_Types
,
16743 Internal
: Node_Id
renames Args
(1);
16744 External
: Node_Id
renames Args
(2);
16745 Parameter_Types
: Node_Id
renames Args
(3);
16746 Mechanism
: Node_Id
renames Args
(4);
16750 Gather_Associations
(Names
, Args
);
16751 Process_Extended_Import_Export_Subprogram_Pragma
(
16752 Arg_Internal
=> Internal
,
16753 Arg_External
=> External
,
16754 Arg_Parameter_Types
=> Parameter_Types
,
16755 Arg_Mechanism
=> Mechanism
);
16756 end Import_Valued_Procedure
;
16762 -- pragma Independent (LOCAL_NAME);
16764 when Pragma_Independent
=>
16765 Process_Atomic_Independent_Shared_Volatile
;
16767 ----------------------------
16768 -- Independent_Components --
16769 ----------------------------
16771 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
16773 when Pragma_Independent_Components
=> Independent_Components
: declare
16781 Check_Ada_83_Warning
;
16783 Check_No_Identifiers
;
16784 Check_Arg_Count
(1);
16785 Check_Arg_Is_Local_Name
(Arg1
);
16786 E_Id
:= Get_Pragma_Arg
(Arg1
);
16788 if Etype
(E_Id
) = Any_Type
then
16792 E
:= Entity
(E_Id
);
16794 -- A pragma that applies to a Ghost entity becomes Ghost for the
16795 -- purposes of legality checks and removal of ignored Ghost code.
16797 Mark_Ghost_Pragma
(N
, E
);
16799 -- Check duplicate before we chain ourselves
16801 Check_Duplicate_Pragma
(E
);
16803 -- Check appropriate entity
16805 if Rep_Item_Too_Early
(E
, N
)
16807 Rep_Item_Too_Late
(E
, N
)
16812 D
:= Declaration_Node
(E
);
16815 -- The flag is set on the base type, or on the object
16817 if K
= N_Full_Type_Declaration
16818 and then (Is_Array_Type
(E
) or else Is_Record_Type
(E
))
16820 Set_Has_Independent_Components
(Base_Type
(E
));
16821 Record_Independence_Check
(N
, Base_Type
(E
));
16823 -- For record type, set all components independent
16825 if Is_Record_Type
(E
) then
16826 C
:= First_Component
(E
);
16827 while Present
(C
) loop
16828 Set_Is_Independent
(C
);
16829 Next_Component
(C
);
16833 elsif (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
16834 and then Nkind
(D
) = N_Object_Declaration
16835 and then Nkind
(Object_Definition
(D
)) =
16836 N_Constrained_Array_Definition
16838 Set_Has_Independent_Components
(E
);
16839 Record_Independence_Check
(N
, E
);
16842 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
16844 end Independent_Components
;
16846 -----------------------
16847 -- Initial_Condition --
16848 -----------------------
16850 -- pragma Initial_Condition (boolean_EXPRESSION);
16852 -- Characteristics:
16854 -- * Analysis - The annotation undergoes initial checks to verify
16855 -- the legal placement and context. Secondary checks preanalyze the
16858 -- Analyze_Initial_Condition_In_Decl_Part
16860 -- * Expansion - The annotation is expanded during the expansion of
16861 -- the package body whose declaration is subject to the annotation
16864 -- Expand_Pragma_Initial_Condition
16866 -- * Template - The annotation utilizes the generic template of the
16867 -- related package declaration.
16869 -- * Globals - Capture of global references must occur after full
16872 -- * Instance - The annotation is instantiated automatically when
16873 -- the related generic package is instantiated.
16875 when Pragma_Initial_Condition
=> Initial_Condition
: declare
16876 Pack_Decl
: Node_Id
;
16877 Pack_Id
: Entity_Id
;
16881 Check_No_Identifiers
;
16882 Check_Arg_Count
(1);
16884 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
16886 -- Ensure the proper placement of the pragma. Initial_Condition
16887 -- must be associated with a package declaration.
16889 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
16890 N_Package_Declaration
)
16894 -- Otherwise the pragma is associated with an illegal context
16901 Pack_Id
:= Defining_Entity
(Pack_Decl
);
16903 -- A pragma that applies to a Ghost entity becomes Ghost for the
16904 -- purposes of legality checks and removal of ignored Ghost code.
16906 Mark_Ghost_Pragma
(N
, Pack_Id
);
16908 -- Chain the pragma on the contract for further processing by
16909 -- Analyze_Initial_Condition_In_Decl_Part.
16911 Add_Contract_Item
(N
, Pack_Id
);
16913 -- The legality checks of pragmas Abstract_State, Initializes, and
16914 -- Initial_Condition are affected by the SPARK mode in effect. In
16915 -- addition, these three pragmas are subject to an inherent order:
16917 -- 1) Abstract_State
16919 -- 3) Initial_Condition
16921 -- Analyze all these pragmas in the order outlined above
16923 Analyze_If_Present
(Pragma_SPARK_Mode
);
16924 Analyze_If_Present
(Pragma_Abstract_State
);
16925 Analyze_If_Present
(Pragma_Initializes
);
16926 end Initial_Condition
;
16928 ------------------------
16929 -- Initialize_Scalars --
16930 ------------------------
16932 -- pragma Initialize_Scalars;
16934 when Pragma_Initialize_Scalars
=>
16936 Check_Arg_Count
(0);
16937 Check_Valid_Configuration_Pragma
;
16938 Check_Restriction
(No_Initialize_Scalars
, N
);
16940 -- Initialize_Scalars creates false positives in CodePeer, and
16941 -- incorrect negative results in GNATprove mode, so ignore this
16942 -- pragma in these modes.
16944 if not Restriction_Active
(No_Initialize_Scalars
)
16945 and then not (CodePeer_Mode
or GNATprove_Mode
)
16947 Init_Or_Norm_Scalars
:= True;
16948 Initialize_Scalars
:= True;
16955 -- pragma Initializes (INITIALIZATION_LIST);
16957 -- INITIALIZATION_LIST ::=
16959 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
16961 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
16966 -- | (INPUT {, INPUT})
16970 -- Characteristics:
16972 -- * Analysis - The annotation undergoes initial checks to verify
16973 -- the legal placement and context. Secondary checks preanalyze the
16976 -- Analyze_Initializes_In_Decl_Part
16978 -- * Expansion - None.
16980 -- * Template - The annotation utilizes the generic template of the
16981 -- related package declaration.
16983 -- * Globals - Capture of global references must occur after full
16986 -- * Instance - The annotation is instantiated automatically when
16987 -- the related generic package is instantiated.
16989 when Pragma_Initializes
=> Initializes
: declare
16990 Pack_Decl
: Node_Id
;
16991 Pack_Id
: Entity_Id
;
16995 Check_No_Identifiers
;
16996 Check_Arg_Count
(1);
16998 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
17000 -- Ensure the proper placement of the pragma. Initializes must be
17001 -- associated with a package declaration.
17003 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
17004 N_Package_Declaration
)
17008 -- Otherwise the pragma is associated with an illegal construc
17015 Pack_Id
:= Defining_Entity
(Pack_Decl
);
17017 -- A pragma that applies to a Ghost entity becomes Ghost for the
17018 -- purposes of legality checks and removal of ignored Ghost code.
17020 Mark_Ghost_Pragma
(N
, Pack_Id
);
17021 Ensure_Aggregate_Form
(Get_Argument
(N
, Pack_Id
));
17023 -- Chain the pragma on the contract for further processing by
17024 -- Analyze_Initializes_In_Decl_Part.
17026 Add_Contract_Item
(N
, Pack_Id
);
17028 -- The legality checks of pragmas Abstract_State, Initializes, and
17029 -- Initial_Condition are affected by the SPARK mode in effect. In
17030 -- addition, these three pragmas are subject to an inherent order:
17032 -- 1) Abstract_State
17034 -- 3) Initial_Condition
17036 -- Analyze all these pragmas in the order outlined above
17038 Analyze_If_Present
(Pragma_SPARK_Mode
);
17039 Analyze_If_Present
(Pragma_Abstract_State
);
17040 Analyze_If_Present
(Pragma_Initial_Condition
);
17047 -- pragma Inline ( NAME {, NAME} );
17049 when Pragma_Inline
=>
17051 -- Pragma always active unless in GNATprove mode. It is disabled
17052 -- in GNATprove mode because frontend inlining is applied
17053 -- independently of pragmas Inline and Inline_Always for
17054 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
17057 if not GNATprove_Mode
then
17059 -- Inline status is Enabled if option -gnatn is specified.
17060 -- However this status determines only the value of the
17061 -- Is_Inlined flag on the subprogram and does not prevent
17062 -- the pragma itself from being recorded for later use,
17063 -- in particular for a later modification of Is_Inlined
17064 -- independently of the -gnatn option.
17066 -- In other words, if -gnatn is specified for a unit, then
17067 -- all Inline pragmas processed for the compilation of this
17068 -- unit, including those in the spec of other units, are
17069 -- activated, so subprograms will be inlined across units.
17071 -- If -gnatn is not specified, no Inline pragma is activated
17072 -- here, which means that subprograms will not be inlined
17073 -- across units. The Is_Inlined flag will nevertheless be
17074 -- set later when bodies are analyzed, so subprograms will
17075 -- be inlined within the unit.
17077 if Inline_Active
then
17078 Process_Inline
(Enabled
);
17080 Process_Inline
(Disabled
);
17084 -------------------
17085 -- Inline_Always --
17086 -------------------
17088 -- pragma Inline_Always ( NAME {, NAME} );
17090 when Pragma_Inline_Always
=>
17093 -- Pragma always active unless in CodePeer mode or GNATprove
17094 -- mode. It is disabled in CodePeer mode because inlining is
17095 -- not helpful, and enabling it caused walk order issues. It
17096 -- is disabled in GNATprove mode because frontend inlining is
17097 -- applied independently of pragmas Inline and Inline_Always for
17098 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
17101 if not CodePeer_Mode
and not GNATprove_Mode
then
17102 Process_Inline
(Enabled
);
17105 --------------------
17106 -- Inline_Generic --
17107 --------------------
17109 -- pragma Inline_Generic (NAME {, NAME});
17111 when Pragma_Inline_Generic
=>
17113 Process_Generic_List
;
17115 ----------------------
17116 -- Inspection_Point --
17117 ----------------------
17119 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
17121 when Pragma_Inspection_Point
=> Inspection_Point
: declare
17128 if Arg_Count
> 0 then
17131 Exp
:= Get_Pragma_Arg
(Arg
);
17134 if not Is_Entity_Name
(Exp
)
17135 or else not Is_Object
(Entity
(Exp
))
17137 Error_Pragma_Arg
("object name required", Arg
);
17141 exit when No
(Arg
);
17144 end Inspection_Point
;
17150 -- pragma Interface (
17151 -- [ Convention =>] convention_IDENTIFIER,
17152 -- [ Entity =>] LOCAL_NAME
17153 -- [, [External_Name =>] static_string_EXPRESSION ]
17154 -- [, [Link_Name =>] static_string_EXPRESSION ]);
17156 when Pragma_Interface
=>
17161 Name_External_Name
,
17163 Check_At_Least_N_Arguments
(2);
17164 Check_At_Most_N_Arguments
(4);
17165 Process_Import_Or_Interface
;
17167 -- In Ada 2005, the permission to use Interface (a reserved word)
17168 -- as a pragma name is considered an obsolescent feature, and this
17169 -- pragma was already obsolescent in Ada 95.
17171 if Ada_Version
>= Ada_95
then
17173 (No_Obsolescent_Features
, Pragma_Identifier
(N
));
17175 if Warn_On_Obsolescent_Feature
then
17177 ("pragma Interface is an obsolescent feature?j?", N
);
17179 ("|use pragma Import instead?j?", N
);
17183 --------------------
17184 -- Interface_Name --
17185 --------------------
17187 -- pragma Interface_Name (
17188 -- [ Entity =>] LOCAL_NAME
17189 -- [,[External_Name =>] static_string_EXPRESSION ]
17190 -- [,[Link_Name =>] static_string_EXPRESSION ]);
17192 when Pragma_Interface_Name
=> Interface_Name
: declare
17194 Def_Id
: Entity_Id
;
17195 Hom_Id
: Entity_Id
;
17201 ((Name_Entity
, Name_External_Name
, Name_Link_Name
));
17202 Check_At_Least_N_Arguments
(2);
17203 Check_At_Most_N_Arguments
(3);
17204 Id
:= Get_Pragma_Arg
(Arg1
);
17207 -- This is obsolete from Ada 95 on, but it is an implementation
17208 -- defined pragma, so we do not consider that it violates the
17209 -- restriction (No_Obsolescent_Features).
17211 if Ada_Version
>= Ada_95
then
17212 if Warn_On_Obsolescent_Feature
then
17214 ("pragma Interface_Name is an obsolescent feature?j?", N
);
17216 ("|use pragma Import instead?j?", N
);
17220 if not Is_Entity_Name
(Id
) then
17222 ("first argument for pragma% must be entity name", Arg1
);
17223 elsif Etype
(Id
) = Any_Type
then
17226 Def_Id
:= Entity
(Id
);
17229 -- Special DEC-compatible processing for the object case, forces
17230 -- object to be imported.
17232 if Ekind
(Def_Id
) = E_Variable
then
17233 Kill_Size_Check_Code
(Def_Id
);
17234 Note_Possible_Modification
(Id
, Sure
=> False);
17236 -- Initialization is not allowed for imported variable
17238 if Present
(Expression
(Parent
(Def_Id
)))
17239 and then Comes_From_Source
(Expression
(Parent
(Def_Id
)))
17241 Error_Msg_Sloc
:= Sloc
(Def_Id
);
17243 ("no initialization allowed for declaration of& #",
17247 -- For compatibility, support VADS usage of providing both
17248 -- pragmas Interface and Interface_Name to obtain the effect
17249 -- of a single Import pragma.
17251 if Is_Imported
(Def_Id
)
17252 and then Present
(First_Rep_Item
(Def_Id
))
17253 and then Nkind
(First_Rep_Item
(Def_Id
)) = N_Pragma
17254 and then Pragma_Name
(First_Rep_Item
(Def_Id
)) =
17259 Set_Imported
(Def_Id
);
17262 Set_Is_Public
(Def_Id
);
17263 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
, N
);
17266 -- Otherwise must be subprogram
17268 elsif not Is_Subprogram
(Def_Id
) then
17270 ("argument of pragma% is not subprogram", Arg1
);
17273 Check_At_Most_N_Arguments
(3);
17277 -- Loop through homonyms
17280 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
17282 if Is_Imported
(Def_Id
) then
17283 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
, N
);
17287 exit when From_Aspect_Specification
(N
);
17288 Hom_Id
:= Homonym
(Hom_Id
);
17290 exit when No
(Hom_Id
)
17291 or else Scope
(Hom_Id
) /= Current_Scope
;
17296 ("argument of pragma% is not imported subprogram",
17300 end Interface_Name
;
17302 -----------------------
17303 -- Interrupt_Handler --
17304 -----------------------
17306 -- pragma Interrupt_Handler (handler_NAME);
17308 when Pragma_Interrupt_Handler
=>
17309 Check_Ada_83_Warning
;
17310 Check_Arg_Count
(1);
17311 Check_No_Identifiers
;
17313 if No_Run_Time_Mode
then
17314 Error_Msg_CRT
("Interrupt_Handler pragma", N
);
17316 Check_Interrupt_Or_Attach_Handler
;
17317 Process_Interrupt_Or_Attach_Handler
;
17320 ------------------------
17321 -- Interrupt_Priority --
17322 ------------------------
17324 -- pragma Interrupt_Priority [(EXPRESSION)];
17326 when Pragma_Interrupt_Priority
=> Interrupt_Priority
: declare
17327 P
: constant Node_Id
:= Parent
(N
);
17332 Check_Ada_83_Warning
;
17334 if Arg_Count
/= 0 then
17335 Arg
:= Get_Pragma_Arg
(Arg1
);
17336 Check_Arg_Count
(1);
17337 Check_No_Identifiers
;
17339 -- The expression must be analyzed in the special manner
17340 -- described in "Handling of Default and Per-Object
17341 -- Expressions" in sem.ads.
17343 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Interrupt_Priority
));
17346 if not Nkind_In
(P
, N_Task_Definition
, N_Protected_Definition
) then
17351 Ent
:= Defining_Identifier
(Parent
(P
));
17353 -- Check duplicate pragma before we chain the pragma in the Rep
17354 -- Item chain of Ent.
17356 Check_Duplicate_Pragma
(Ent
);
17357 Record_Rep_Item
(Ent
, N
);
17359 -- Check the No_Task_At_Interrupt_Priority restriction
17361 if Nkind
(P
) = N_Task_Definition
then
17362 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
17365 end Interrupt_Priority
;
17367 ---------------------
17368 -- Interrupt_State --
17369 ---------------------
17371 -- pragma Interrupt_State (
17372 -- [Name =>] INTERRUPT_ID,
17373 -- [State =>] INTERRUPT_STATE);
17375 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
17376 -- INTERRUPT_STATE => System | Runtime | User
17378 -- Note: if the interrupt id is given as an identifier, then it must
17379 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
17380 -- given as a static integer expression which must be in the range of
17381 -- Ada.Interrupts.Interrupt_ID.
17383 when Pragma_Interrupt_State
=> Interrupt_State
: declare
17384 Int_Id
: constant Entity_Id
:= RTE
(RE_Interrupt_ID
);
17385 -- This is the entity Ada.Interrupts.Interrupt_ID;
17387 State_Type
: Character;
17388 -- Set to 's'/'r'/'u' for System/Runtime/User
17391 -- Index to entry in Interrupt_States table
17394 -- Value of interrupt
17396 Arg1X
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
17397 -- The first argument to the pragma
17399 Int_Ent
: Entity_Id
;
17400 -- Interrupt entity in Ada.Interrupts.Names
17404 Check_Arg_Order
((Name_Name
, Name_State
));
17405 Check_Arg_Count
(2);
17407 Check_Optional_Identifier
(Arg1
, Name_Name
);
17408 Check_Optional_Identifier
(Arg2
, Name_State
);
17409 Check_Arg_Is_Identifier
(Arg2
);
17411 -- First argument is identifier
17413 if Nkind
(Arg1X
) = N_Identifier
then
17415 -- Search list of names in Ada.Interrupts.Names
17417 Int_Ent
:= First_Entity
(RTE
(RE_Names
));
17419 if No
(Int_Ent
) then
17420 Error_Pragma_Arg
("invalid interrupt name", Arg1
);
17422 elsif Chars
(Int_Ent
) = Chars
(Arg1X
) then
17423 Int_Val
:= Expr_Value
(Constant_Value
(Int_Ent
));
17427 Next_Entity
(Int_Ent
);
17430 -- First argument is not an identifier, so it must be a static
17431 -- expression of type Ada.Interrupts.Interrupt_ID.
17434 Check_Arg_Is_OK_Static_Expression
(Arg1
, Any_Integer
);
17435 Int_Val
:= Expr_Value
(Arg1X
);
17437 if Int_Val
< Expr_Value
(Type_Low_Bound
(Int_Id
))
17439 Int_Val
> Expr_Value
(Type_High_Bound
(Int_Id
))
17442 ("value not in range of type "
17443 & """Ada.Interrupts.Interrupt_'I'D""", Arg1
);
17449 case Chars
(Get_Pragma_Arg
(Arg2
)) is
17450 when Name_Runtime
=> State_Type
:= 'r';
17451 when Name_System
=> State_Type
:= 's';
17452 when Name_User
=> State_Type
:= 'u';
17455 Error_Pragma_Arg
("invalid interrupt state", Arg2
);
17458 -- Check if entry is already stored
17460 IST_Num
:= Interrupt_States
.First
;
17462 -- If entry not found, add it
17464 if IST_Num
> Interrupt_States
.Last
then
17465 Interrupt_States
.Append
17466 ((Interrupt_Number
=> UI_To_Int
(Int_Val
),
17467 Interrupt_State
=> State_Type
,
17468 Pragma_Loc
=> Loc
));
17471 -- Case of entry for the same entry
17473 elsif Int_Val
= Interrupt_States
.Table
(IST_Num
).
17476 -- If state matches, done, no need to make redundant entry
17479 State_Type
= Interrupt_States
.Table
(IST_Num
).
17482 -- Otherwise if state does not match, error
17485 Interrupt_States
.Table
(IST_Num
).Pragma_Loc
;
17487 ("state conflicts with that given #", Arg2
);
17491 IST_Num
:= IST_Num
+ 1;
17493 end Interrupt_State
;
17499 -- pragma Invariant
17500 -- ([Entity =>] type_LOCAL_NAME,
17501 -- [Check =>] EXPRESSION
17502 -- [,[Message =>] String_Expression]);
17504 when Pragma_Invariant
=> Invariant
: declare
17511 Check_At_Least_N_Arguments
(2);
17512 Check_At_Most_N_Arguments
(3);
17513 Check_Optional_Identifier
(Arg1
, Name_Entity
);
17514 Check_Optional_Identifier
(Arg2
, Name_Check
);
17516 if Arg_Count
= 3 then
17517 Check_Optional_Identifier
(Arg3
, Name_Message
);
17518 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
17521 Check_Arg_Is_Local_Name
(Arg1
);
17523 Typ_Arg
:= Get_Pragma_Arg
(Arg1
);
17524 Find_Type
(Typ_Arg
);
17525 Typ
:= Entity
(Typ_Arg
);
17527 -- Nothing to do of the related type is erroneous in some way
17529 if Typ
= Any_Type
then
17532 -- AI12-0041: Invariants are allowed in interface types
17534 elsif Is_Interface
(Typ
) then
17537 -- An invariant must apply to a private type, or appear in the
17538 -- private part of a package spec and apply to a completion.
17539 -- a class-wide invariant can only appear on a private declaration
17540 -- or private extension, not a completion.
17542 -- A [class-wide] invariant may be associated a [limited] private
17543 -- type or a private extension.
17545 elsif Ekind_In
(Typ
, E_Limited_Private_Type
,
17547 E_Record_Type_With_Private
)
17551 -- A non-class-wide invariant may be associated with the full view
17552 -- of a [limited] private type or a private extension.
17554 elsif Has_Private_Declaration
(Typ
)
17555 and then not Class_Present
(N
)
17559 -- A class-wide invariant may appear on the partial view only
17561 elsif Class_Present
(N
) then
17563 ("pragma % only allowed for private type", Arg1
);
17566 -- A regular invariant may appear on both views
17570 ("pragma % only allowed for private type or corresponding "
17571 & "full view", Arg1
);
17575 -- An invariant associated with an abstract type (this includes
17576 -- interfaces) must be class-wide.
17578 if Is_Abstract_Type
(Typ
) and then not Class_Present
(N
) then
17580 ("pragma % not allowed for abstract type", Arg1
);
17584 -- A pragma that applies to a Ghost entity becomes Ghost for the
17585 -- purposes of legality checks and removal of ignored Ghost code.
17587 Mark_Ghost_Pragma
(N
, Typ
);
17589 -- The pragma defines a type-specific invariant, the type is said
17590 -- to have invariants of its "own".
17592 Set_Has_Own_Invariants
(Typ
);
17594 -- If the invariant is class-wide, then it can be inherited by
17595 -- derived or interface implementing types. The type is said to
17596 -- have "inheritable" invariants.
17598 if Class_Present
(N
) then
17599 Set_Has_Inheritable_Invariants
(Typ
);
17602 -- Chain the pragma on to the rep item chain, for processing when
17603 -- the type is frozen.
17605 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
17607 -- Create the declaration of the invariant procedure that will
17608 -- verify the invariant at run time. Interfaces are treated as the
17609 -- partial view of a private type in order to achieve uniformity
17610 -- with the general case. As a result, an interface receives only
17611 -- a "partial" invariant procedure, which is never called.
17613 Build_Invariant_Procedure_Declaration
17615 Partial_Invariant
=> Is_Interface
(Typ
));
17622 -- pragma Keep_Names ([On => ] LOCAL_NAME);
17624 when Pragma_Keep_Names
=> Keep_Names
: declare
17629 Check_Arg_Count
(1);
17630 Check_Optional_Identifier
(Arg1
, Name_On
);
17631 Check_Arg_Is_Local_Name
(Arg1
);
17633 Arg
:= Get_Pragma_Arg
(Arg1
);
17636 if Etype
(Arg
) = Any_Type
then
17640 if not Is_Entity_Name
(Arg
)
17641 or else Ekind
(Entity
(Arg
)) /= E_Enumeration_Type
17644 ("pragma% requires a local enumeration type", Arg1
);
17647 Set_Discard_Names
(Entity
(Arg
), False);
17654 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
17656 when Pragma_License
=>
17659 -- Do not analyze pragma any further in CodePeer mode, to avoid
17660 -- extraneous errors in this implementation-dependent pragma,
17661 -- which has a different profile on other compilers.
17663 if CodePeer_Mode
then
17667 Check_Arg_Count
(1);
17668 Check_No_Identifiers
;
17669 Check_Valid_Configuration_Pragma
;
17670 Check_Arg_Is_Identifier
(Arg1
);
17673 Sind
: constant Source_File_Index
:=
17674 Source_Index
(Current_Sem_Unit
);
17677 case Chars
(Get_Pragma_Arg
(Arg1
)) is
17679 Set_License
(Sind
, GPL
);
17681 when Name_Modified_GPL
=>
17682 Set_License
(Sind
, Modified_GPL
);
17684 when Name_Restricted
=>
17685 Set_License
(Sind
, Restricted
);
17687 when Name_Unrestricted
=>
17688 Set_License
(Sind
, Unrestricted
);
17691 Error_Pragma_Arg
("invalid license name", Arg1
);
17699 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
17701 when Pragma_Link_With
=> Link_With
: declare
17707 if Operating_Mode
= Generate_Code
17708 and then In_Extended_Main_Source_Unit
(N
)
17710 Check_At_Least_N_Arguments
(1);
17711 Check_No_Identifiers
;
17712 Check_Is_In_Decl_Part_Or_Package_Spec
;
17713 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
17717 while Present
(Arg
) loop
17718 Check_Arg_Is_OK_Static_Expression
(Arg
, Standard_String
);
17720 -- Store argument, converting sequences of spaces to a
17721 -- single null character (this is one of the differences
17722 -- in processing between Link_With and Linker_Options).
17724 Arg_Store
: declare
17725 C
: constant Char_Code
:= Get_Char_Code
(' ');
17726 S
: constant String_Id
:=
17727 Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
)));
17728 L
: constant Nat
:= String_Length
(S
);
17731 procedure Skip_Spaces
;
17732 -- Advance F past any spaces
17738 procedure Skip_Spaces
is
17740 while F
<= L
and then Get_String_Char
(S
, F
) = C
loop
17745 -- Start of processing for Arg_Store
17748 Skip_Spaces
; -- skip leading spaces
17750 -- Loop through characters, changing any embedded
17751 -- sequence of spaces to a single null character (this
17752 -- is how Link_With/Linker_Options differ)
17755 if Get_String_Char
(S
, F
) = C
then
17758 Store_String_Char
(ASCII
.NUL
);
17761 Store_String_Char
(Get_String_Char
(S
, F
));
17769 if Present
(Arg
) then
17770 Store_String_Char
(ASCII
.NUL
);
17774 Store_Linker_Option_String
(End_String
);
17782 -- pragma Linker_Alias (
17783 -- [Entity =>] LOCAL_NAME
17784 -- [Target =>] static_string_EXPRESSION);
17786 when Pragma_Linker_Alias
=>
17788 Check_Arg_Order
((Name_Entity
, Name_Target
));
17789 Check_Arg_Count
(2);
17790 Check_Optional_Identifier
(Arg1
, Name_Entity
);
17791 Check_Optional_Identifier
(Arg2
, Name_Target
);
17792 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
17793 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
17795 -- The only processing required is to link this item on to the
17796 -- list of rep items for the given entity. This is accomplished
17797 -- by the call to Rep_Item_Too_Late (when no error is detected
17798 -- and False is returned).
17800 if Rep_Item_Too_Late
(Entity
(Get_Pragma_Arg
(Arg1
)), N
) then
17803 Set_Has_Gigi_Rep_Item
(Entity
(Get_Pragma_Arg
(Arg1
)));
17806 ------------------------
17807 -- Linker_Constructor --
17808 ------------------------
17810 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
17812 -- Code is shared with Linker_Destructor
17814 -----------------------
17815 -- Linker_Destructor --
17816 -----------------------
17818 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
17820 when Pragma_Linker_Constructor
17821 | Pragma_Linker_Destructor
17823 Linker_Constructor
: declare
17829 Check_Arg_Count
(1);
17830 Check_No_Identifiers
;
17831 Check_Arg_Is_Local_Name
(Arg1
);
17832 Arg1_X
:= Get_Pragma_Arg
(Arg1
);
17834 Proc
:= Find_Unique_Parameterless_Procedure
(Arg1_X
, Arg1
);
17836 if not Is_Library_Level_Entity
(Proc
) then
17838 ("argument for pragma% must be library level entity", Arg1
);
17841 -- The only processing required is to link this item on to the
17842 -- list of rep items for the given entity. This is accomplished
17843 -- by the call to Rep_Item_Too_Late (when no error is detected
17844 -- and False is returned).
17846 if Rep_Item_Too_Late
(Proc
, N
) then
17849 Set_Has_Gigi_Rep_Item
(Proc
);
17851 end Linker_Constructor
;
17853 --------------------
17854 -- Linker_Options --
17855 --------------------
17857 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
17859 when Pragma_Linker_Options
=> Linker_Options
: declare
17863 Check_Ada_83_Warning
;
17864 Check_No_Identifiers
;
17865 Check_Arg_Count
(1);
17866 Check_Is_In_Decl_Part_Or_Package_Spec
;
17867 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
17868 Start_String
(Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg1
))));
17871 while Present
(Arg
) loop
17872 Check_Arg_Is_OK_Static_Expression
(Arg
, Standard_String
);
17873 Store_String_Char
(ASCII
.NUL
);
17875 (Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
))));
17879 if Operating_Mode
= Generate_Code
17880 and then In_Extended_Main_Source_Unit
(N
)
17882 Store_Linker_Option_String
(End_String
);
17884 end Linker_Options
;
17886 --------------------
17887 -- Linker_Section --
17888 --------------------
17890 -- pragma Linker_Section (
17891 -- [Entity =>] LOCAL_NAME
17892 -- [Section =>] static_string_EXPRESSION);
17894 when Pragma_Linker_Section
=> Linker_Section
: declare
17899 Ghost_Error_Posted
: Boolean := False;
17900 -- Flag set when an error concerning the illegal mix of Ghost and
17901 -- non-Ghost subprograms is emitted.
17903 Ghost_Id
: Entity_Id
:= Empty
;
17904 -- The entity of the first Ghost subprogram encountered while
17905 -- processing the arguments of the pragma.
17909 Check_Arg_Order
((Name_Entity
, Name_Section
));
17910 Check_Arg_Count
(2);
17911 Check_Optional_Identifier
(Arg1
, Name_Entity
);
17912 Check_Optional_Identifier
(Arg2
, Name_Section
);
17913 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
17914 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
17916 -- Check kind of entity
17918 Arg
:= Get_Pragma_Arg
(Arg1
);
17919 Ent
:= Entity
(Arg
);
17921 case Ekind
(Ent
) is
17923 -- Objects (constants and variables) and types. For these cases
17924 -- all we need to do is to set the Linker_Section_pragma field,
17925 -- checking that we do not have a duplicate.
17931 LPE
:= Linker_Section_Pragma
(Ent
);
17933 if Present
(LPE
) then
17934 Error_Msg_Sloc
:= Sloc
(LPE
);
17936 ("Linker_Section already specified for &#", Arg1
, Ent
);
17939 Set_Linker_Section_Pragma
(Ent
, N
);
17941 -- A pragma that applies to a Ghost entity becomes Ghost for
17942 -- the purposes of legality checks and removal of ignored
17945 Mark_Ghost_Pragma
(N
, Ent
);
17949 when Subprogram_Kind
=>
17951 -- Aspect case, entity already set
17953 if From_Aspect_Specification
(N
) then
17954 Set_Linker_Section_Pragma
17955 (Entity
(Corresponding_Aspect
(N
)), N
);
17957 -- Pragma case, we must climb the homonym chain, but skip
17958 -- any for which the linker section is already set.
17962 if No
(Linker_Section_Pragma
(Ent
)) then
17963 Set_Linker_Section_Pragma
(Ent
, N
);
17965 -- A pragma that applies to a Ghost entity becomes
17966 -- Ghost for the purposes of legality checks and
17967 -- removal of ignored Ghost code.
17969 Mark_Ghost_Pragma
(N
, Ent
);
17971 -- Capture the entity of the first Ghost subprogram
17972 -- being processed for error detection purposes.
17974 if Is_Ghost_Entity
(Ent
) then
17975 if No
(Ghost_Id
) then
17979 -- Otherwise the subprogram is non-Ghost. It is
17980 -- illegal to mix references to Ghost and non-Ghost
17981 -- entities (SPARK RM 6.9).
17983 elsif Present
(Ghost_Id
)
17984 and then not Ghost_Error_Posted
17986 Ghost_Error_Posted
:= True;
17988 Error_Msg_Name_1
:= Pname
;
17990 ("pragma % cannot mention ghost and "
17991 & "non-ghost subprograms", N
);
17993 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
17995 ("\& # declared as ghost", N
, Ghost_Id
);
17997 Error_Msg_Sloc
:= Sloc
(Ent
);
17999 ("\& # declared as non-ghost", N
, Ent
);
18003 Ent
:= Homonym
(Ent
);
18005 or else Scope
(Ent
) /= Current_Scope
;
18009 -- All other cases are illegal
18013 ("pragma% applies only to objects, subprograms, and types",
18016 end Linker_Section
;
18022 -- pragma List (On | Off)
18024 -- There is nothing to do here, since we did all the processing for
18025 -- this pragma in Par.Prag (so that it works properly even in syntax
18028 when Pragma_List
=>
18035 -- pragma Lock_Free [(Boolean_EXPRESSION)];
18037 when Pragma_Lock_Free
=> Lock_Free
: declare
18038 P
: constant Node_Id
:= Parent
(N
);
18044 Check_No_Identifiers
;
18045 Check_At_Most_N_Arguments
(1);
18047 -- Protected definition case
18049 if Nkind
(P
) = N_Protected_Definition
then
18050 Ent
:= Defining_Identifier
(Parent
(P
));
18054 if Arg_Count
= 1 then
18055 Arg
:= Get_Pragma_Arg
(Arg1
);
18056 Val
:= Is_True
(Static_Boolean
(Arg
));
18058 -- No arguments (expression is considered to be True)
18064 -- Check duplicate pragma before we chain the pragma in the Rep
18065 -- Item chain of Ent.
18067 Check_Duplicate_Pragma
(Ent
);
18068 Record_Rep_Item
(Ent
, N
);
18069 Set_Uses_Lock_Free
(Ent
, Val
);
18071 -- Anything else is incorrect placement
18078 --------------------
18079 -- Locking_Policy --
18080 --------------------
18082 -- pragma Locking_Policy (policy_IDENTIFIER);
18084 when Pragma_Locking_Policy
=> declare
18085 subtype LP_Range
is Name_Id
18086 range First_Locking_Policy_Name
.. Last_Locking_Policy_Name
;
18091 Check_Ada_83_Warning
;
18092 Check_Arg_Count
(1);
18093 Check_No_Identifiers
;
18094 Check_Arg_Is_Locking_Policy
(Arg1
);
18095 Check_Valid_Configuration_Pragma
;
18096 LP_Val
:= Chars
(Get_Pragma_Arg
(Arg1
));
18099 when Name_Ceiling_Locking
=> LP
:= 'C';
18100 when Name_Concurrent_Readers_Locking
=> LP
:= 'R';
18101 when Name_Inheritance_Locking
=> LP
:= 'I';
18104 if Locking_Policy
/= ' '
18105 and then Locking_Policy
/= LP
18107 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
18108 Error_Pragma
("locking policy incompatible with policy#");
18110 -- Set new policy, but always preserve System_Location since we
18111 -- like the error message with the run time name.
18114 Locking_Policy
:= LP
;
18116 if Locking_Policy_Sloc
/= System_Location
then
18117 Locking_Policy_Sloc
:= Loc
;
18122 -------------------
18123 -- Loop_Optimize --
18124 -------------------
18126 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
18128 -- OPTIMIZATION_HINT ::=
18129 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
18131 when Pragma_Loop_Optimize
=> Loop_Optimize
: declare
18136 Check_At_Least_N_Arguments
(1);
18137 Check_No_Identifiers
;
18139 Hint
:= First
(Pragma_Argument_Associations
(N
));
18140 while Present
(Hint
) loop
18141 Check_Arg_Is_One_Of
(Hint
, Name_Ivdep
,
18149 Check_Loop_Pragma_Placement
;
18156 -- pragma Loop_Variant
18157 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
18159 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
18161 -- CHANGE_DIRECTION ::= Increases | Decreases
18163 when Pragma_Loop_Variant
=> Loop_Variant
: declare
18168 Check_At_Least_N_Arguments
(1);
18169 Check_Loop_Pragma_Placement
;
18171 -- Process all increasing / decreasing expressions
18173 Variant
:= First
(Pragma_Argument_Associations
(N
));
18174 while Present
(Variant
) loop
18175 if Chars
(Variant
) = No_Name
then
18176 Error_Pragma_Arg
("expect name `Increases`", Variant
);
18178 elsif not Nam_In
(Chars
(Variant
), Name_Decreases
,
18182 Name
: String := Get_Name_String
(Chars
(Variant
));
18185 -- It is a common mistake to write "Increasing" for
18186 -- "Increases" or "Decreasing" for "Decreases". Recognize
18187 -- specially names starting with "incr" or "decr" to
18188 -- suggest the corresponding name.
18190 System
.Case_Util
.To_Lower
(Name
);
18192 if Name
'Length >= 4
18193 and then Name
(1 .. 4) = "incr"
18195 Error_Pragma_Arg_Ident
18196 ("expect name `Increases`", Variant
);
18198 elsif Name
'Length >= 4
18199 and then Name
(1 .. 4) = "decr"
18201 Error_Pragma_Arg_Ident
18202 ("expect name `Decreases`", Variant
);
18205 Error_Pragma_Arg_Ident
18206 ("expect name `Increases` or `Decreases`", Variant
);
18211 Preanalyze_Assert_Expression
18212 (Expression
(Variant
), Any_Discrete
);
18218 -----------------------
18219 -- Machine_Attribute --
18220 -----------------------
18222 -- pragma Machine_Attribute (
18223 -- [Entity =>] LOCAL_NAME,
18224 -- [Attribute_Name =>] static_string_EXPRESSION
18225 -- [, [Info =>] static_EXPRESSION] );
18227 when Pragma_Machine_Attribute
=> Machine_Attribute
: declare
18228 Def_Id
: Entity_Id
;
18232 Check_Arg_Order
((Name_Entity
, Name_Attribute_Name
, Name_Info
));
18234 if Arg_Count
= 3 then
18235 Check_Optional_Identifier
(Arg3
, Name_Info
);
18236 Check_Arg_Is_OK_Static_Expression
(Arg3
);
18238 Check_Arg_Count
(2);
18241 Check_Optional_Identifier
(Arg1
, Name_Entity
);
18242 Check_Optional_Identifier
(Arg2
, Name_Attribute_Name
);
18243 Check_Arg_Is_Local_Name
(Arg1
);
18244 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
18245 Def_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
18247 if Is_Access_Type
(Def_Id
) then
18248 Def_Id
:= Designated_Type
(Def_Id
);
18251 if Rep_Item_Too_Early
(Def_Id
, N
) then
18255 Def_Id
:= Underlying_Type
(Def_Id
);
18257 -- The only processing required is to link this item on to the
18258 -- list of rep items for the given entity. This is accomplished
18259 -- by the call to Rep_Item_Too_Late (when no error is detected
18260 -- and False is returned).
18262 if Rep_Item_Too_Late
(Def_Id
, N
) then
18265 Set_Has_Gigi_Rep_Item
(Entity
(Get_Pragma_Arg
(Arg1
)));
18267 end Machine_Attribute
;
18274 -- (MAIN_OPTION [, MAIN_OPTION]);
18277 -- [STACK_SIZE =>] static_integer_EXPRESSION
18278 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
18279 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
18281 when Pragma_Main
=> Main
: declare
18282 Args
: Args_List
(1 .. 3);
18283 Names
: constant Name_List
(1 .. 3) := (
18285 Name_Task_Stack_Size_Default
,
18286 Name_Time_Slicing_Enabled
);
18292 Gather_Associations
(Names
, Args
);
18294 for J
in 1 .. 2 loop
18295 if Present
(Args
(J
)) then
18296 Check_Arg_Is_OK_Static_Expression
(Args
(J
), Any_Integer
);
18300 if Present
(Args
(3)) then
18301 Check_Arg_Is_OK_Static_Expression
(Args
(3), Standard_Boolean
);
18305 while Present
(Nod
) loop
18306 if Nkind
(Nod
) = N_Pragma
18307 and then Pragma_Name
(Nod
) = Name_Main
18309 Error_Msg_Name_1
:= Pname
;
18310 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
18321 -- pragma Main_Storage
18322 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
18324 -- MAIN_STORAGE_OPTION ::=
18325 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
18326 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
18328 when Pragma_Main_Storage
=> Main_Storage
: declare
18329 Args
: Args_List
(1 .. 2);
18330 Names
: constant Name_List
(1 .. 2) := (
18331 Name_Working_Storage
,
18338 Gather_Associations
(Names
, Args
);
18340 for J
in 1 .. 2 loop
18341 if Present
(Args
(J
)) then
18342 Check_Arg_Is_OK_Static_Expression
(Args
(J
), Any_Integer
);
18346 Check_In_Main_Program
;
18349 while Present
(Nod
) loop
18350 if Nkind
(Nod
) = N_Pragma
18351 and then Pragma_Name
(Nod
) = Name_Main_Storage
18353 Error_Msg_Name_1
:= Pname
;
18354 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
18361 ----------------------
18362 -- Max_Queue_Length --
18363 ----------------------
18365 -- pragma Max_Queue_Length (static_integer_EXPRESSION);
18367 when Pragma_Max_Queue_Length
=> Max_Queue_Length
: declare
18369 Entry_Decl
: Node_Id
;
18370 Entry_Id
: Entity_Id
;
18375 Check_Arg_Count
(1);
18378 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
18380 -- Entry declaration
18382 if Nkind
(Entry_Decl
) = N_Entry_Declaration
then
18384 -- Entry illegally within a task
18386 if Nkind
(Parent
(N
)) = N_Task_Definition
then
18387 Error_Pragma
("pragma % cannot apply to task entries");
18391 Entry_Id
:= Unique_Defining_Entity
(Entry_Decl
);
18393 -- Otherwise the pragma is associated with an illegal construct
18396 Error_Pragma
("pragma % must apply to a protected entry");
18400 -- Mark the pragma as Ghost if the related subprogram is also
18401 -- Ghost. This also ensures that any expansion performed further
18402 -- below will produce Ghost nodes.
18404 Mark_Ghost_Pragma
(N
, Entry_Id
);
18406 -- Analyze the Integer expression
18408 Arg
:= Get_Pragma_Arg
(Arg1
);
18409 Check_Arg_Is_OK_Static_Expression
(Arg
, Any_Integer
);
18411 Val
:= Expr_Value
(Arg
);
18415 ("argument for pragma% must be positive", Arg1
);
18417 elsif not UI_Is_In_Int_Range
(Val
) then
18419 ("argument for pragma% out of range of Integer", Arg1
);
18423 -- Manually substitute the expression value of the pragma argument
18424 -- if it's not an integer literal because this is not taken care
18425 -- of automatically elsewhere.
18427 if Nkind
(Arg
) /= N_Integer_Literal
then
18428 Rewrite
(Arg
, Make_Integer_Literal
(Sloc
(Arg
), Val
));
18431 Record_Rep_Item
(Entry_Id
, N
);
18432 end Max_Queue_Length
;
18438 -- pragma Memory_Size (NUMERIC_LITERAL)
18440 when Pragma_Memory_Size
=>
18443 -- Memory size is simply ignored
18445 Check_No_Identifiers
;
18446 Check_Arg_Count
(1);
18447 Check_Arg_Is_Integer_Literal
(Arg1
);
18455 -- The only correct use of this pragma is on its own in a file, in
18456 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
18457 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
18458 -- check for a file containing nothing but a No_Body pragma). If we
18459 -- attempt to process it during normal semantics processing, it means
18460 -- it was misplaced.
18462 when Pragma_No_Body
=>
18466 -----------------------------
18467 -- No_Elaboration_Code_All --
18468 -----------------------------
18470 -- pragma No_Elaboration_Code_All;
18472 when Pragma_No_Elaboration_Code_All
=>
18474 Check_Valid_Library_Unit_Pragma
;
18476 if Nkind
(N
) = N_Null_Statement
then
18480 -- Must appear for a spec or generic spec
18482 if not Nkind_In
(Unit
(Cunit
(Current_Sem_Unit
)),
18483 N_Generic_Package_Declaration
,
18484 N_Generic_Subprogram_Declaration
,
18485 N_Package_Declaration
,
18486 N_Subprogram_Declaration
)
18490 ("pragma% can only occur for package "
18491 & "or subprogram spec"));
18494 -- Set flag in unit table
18496 Set_No_Elab_Code_All
(Current_Sem_Unit
);
18498 -- Set restriction No_Elaboration_Code if this is the main unit
18500 if Current_Sem_Unit
= Main_Unit
then
18501 Set_Restriction
(No_Elaboration_Code
, N
);
18504 -- If we are in the main unit or in an extended main source unit,
18505 -- then we also add it to the configuration restrictions so that
18506 -- it will apply to all units in the extended main source.
18508 if Current_Sem_Unit
= Main_Unit
18509 or else In_Extended_Main_Source_Unit
(N
)
18511 Add_To_Config_Boolean_Restrictions
(No_Elaboration_Code
);
18514 -- If in main extended unit, activate transitive with test
18516 if In_Extended_Main_Source_Unit
(N
) then
18517 Opt
.No_Elab_Code_All_Pragma
:= N
;
18520 -----------------------------
18521 -- No_Component_Reordering --
18522 -----------------------------
18524 -- pragma No_Component_Reordering [([Entity =>] type_LOCAL_NAME)];
18526 when Pragma_No_Component_Reordering
=> No_Comp_Reordering
: declare
18532 Check_At_Most_N_Arguments
(1);
18534 if Arg_Count
= 0 then
18535 Check_Valid_Configuration_Pragma
;
18536 Opt
.No_Component_Reordering
:= True;
18539 Check_Optional_Identifier
(Arg2
, Name_Entity
);
18540 Check_Arg_Is_Local_Name
(Arg1
);
18541 E_Id
:= Get_Pragma_Arg
(Arg1
);
18543 if Etype
(E_Id
) = Any_Type
then
18547 E
:= Entity
(E_Id
);
18549 if not Is_Record_Type
(E
) then
18550 Error_Pragma_Arg
("pragma% requires record type", Arg1
);
18553 Set_No_Reordering
(Base_Type
(E
));
18555 end No_Comp_Reordering
;
18557 --------------------------
18558 -- No_Heap_Finalization --
18559 --------------------------
18561 -- pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ];
18563 when Pragma_No_Heap_Finalization
=> No_Heap_Finalization
: declare
18564 Context
: constant Node_Id
:= Parent
(N
);
18565 Typ_Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
18571 Check_No_Identifiers
;
18573 -- The pragma appears in a configuration file
18575 if No
(Context
) then
18576 Check_Arg_Count
(0);
18577 Check_Valid_Configuration_Pragma
;
18579 -- Detect a duplicate pragma
18581 if Present
(No_Heap_Finalization_Pragma
) then
18584 Prev
=> No_Heap_Finalization_Pragma
);
18588 No_Heap_Finalization_Pragma
:= N
;
18590 -- Otherwise the pragma should be associated with a library-level
18591 -- named access-to-object type.
18594 Check_Arg_Count
(1);
18595 Check_Arg_Is_Local_Name
(Arg1
);
18597 Find_Type
(Typ_Arg
);
18598 Typ
:= Entity
(Typ_Arg
);
18600 -- The type being subjected to the pragma is erroneous
18602 if Typ
= Any_Type
then
18603 Error_Pragma
("cannot find type referenced by pragma %");
18605 -- The pragma is applied to an incomplete or generic formal
18606 -- type way too early.
18608 elsif Rep_Item_Too_Early
(Typ
, N
) then
18612 Typ
:= Underlying_Type
(Typ
);
18615 -- The pragma must apply to an access-to-object type
18617 if Ekind_In
(Typ
, E_Access_Type
, E_General_Access_Type
) then
18620 -- Give a detailed error message on all other access type kinds
18622 elsif Ekind
(Typ
) = E_Access_Protected_Subprogram_Type
then
18624 ("pragma % cannot apply to access protected subprogram "
18627 elsif Ekind
(Typ
) = E_Access_Subprogram_Type
then
18629 ("pragma % cannot apply to access subprogram type");
18631 elsif Is_Anonymous_Access_Type
(Typ
) then
18633 ("pragma % cannot apply to anonymous access type");
18635 -- Give a general error message in case the pragma applies to a
18636 -- non-access type.
18640 ("pragma % must apply to library level access type");
18643 -- At this point the argument denotes an access-to-object type.
18644 -- Ensure that the type is declared at the library level.
18646 if Is_Library_Level_Entity
(Typ
) then
18649 -- Quietly ignore an access-to-object type originally declared
18650 -- at the library level within a generic, but instantiated at
18651 -- a non-library level. As a result the access-to-object type
18652 -- "loses" its No_Heap_Finalization property.
18654 elsif In_Instance
then
18659 ("pragma % must apply to library level access type");
18662 -- Detect a duplicate pragma
18664 if Present
(No_Heap_Finalization_Pragma
) then
18667 Prev
=> No_Heap_Finalization_Pragma
);
18671 Prev
:= Get_Pragma
(Typ
, Pragma_No_Heap_Finalization
);
18673 if Present
(Prev
) then
18681 Record_Rep_Item
(Typ
, N
);
18683 end No_Heap_Finalization
;
18689 -- pragma No_Inline ( NAME {, NAME} );
18691 when Pragma_No_Inline
=>
18693 Process_Inline
(Suppressed
);
18699 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
18701 when Pragma_No_Return
=> No_Return
: declare
18707 Ghost_Error_Posted
: Boolean := False;
18708 -- Flag set when an error concerning the illegal mix of Ghost and
18709 -- non-Ghost subprograms is emitted.
18711 Ghost_Id
: Entity_Id
:= Empty
;
18712 -- The entity of the first Ghost procedure encountered while
18713 -- processing the arguments of the pragma.
18717 Check_At_Least_N_Arguments
(1);
18719 -- Loop through arguments of pragma
18722 while Present
(Arg
) loop
18723 Check_Arg_Is_Local_Name
(Arg
);
18724 Id
:= Get_Pragma_Arg
(Arg
);
18727 if not Is_Entity_Name
(Id
) then
18728 Error_Pragma_Arg
("entity name required", Arg
);
18731 if Etype
(Id
) = Any_Type
then
18735 -- Loop to find matching procedures
18741 and then Scope
(E
) = Current_Scope
18743 if Ekind_In
(E
, E_Generic_Procedure
, E_Procedure
) then
18745 -- Check that the pragma is not applied to a body.
18746 -- First check the specless body case, to give a
18747 -- different error message. These checks do not apply
18748 -- if Relaxed_RM_Semantics, to accommodate other Ada
18749 -- compilers. Disable these checks under -gnatd.J.
18751 if not Debug_Flag_Dot_JJ
then
18752 if Nkind
(Parent
(Declaration_Node
(E
))) =
18754 and then not Relaxed_RM_Semantics
18757 ("pragma% requires separate spec and must come "
18761 -- Now the "specful" body case
18763 if Rep_Item_Too_Late
(E
, N
) then
18770 -- A pragma that applies to a Ghost entity becomes Ghost
18771 -- for the purposes of legality checks and removal of
18772 -- ignored Ghost code.
18774 Mark_Ghost_Pragma
(N
, E
);
18776 -- Capture the entity of the first Ghost procedure being
18777 -- processed for error detection purposes.
18779 if Is_Ghost_Entity
(E
) then
18780 if No
(Ghost_Id
) then
18784 -- Otherwise the subprogram is non-Ghost. It is illegal
18785 -- to mix references to Ghost and non-Ghost entities
18788 elsif Present
(Ghost_Id
)
18789 and then not Ghost_Error_Posted
18791 Ghost_Error_Posted
:= True;
18793 Error_Msg_Name_1
:= Pname
;
18795 ("pragma % cannot mention ghost and non-ghost "
18796 & "procedures", N
);
18798 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
18799 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
18801 Error_Msg_Sloc
:= Sloc
(E
);
18802 Error_Msg_NE
("\& # declared as non-ghost", N
, E
);
18805 -- Set flag on any alias as well
18807 if Is_Overloadable
(E
) and then Present
(Alias
(E
)) then
18808 Set_No_Return
(Alias
(E
));
18814 exit when From_Aspect_Specification
(N
);
18818 -- If entity in not in current scope it may be the enclosing
18819 -- suprogram body to which the aspect applies.
18822 if Entity
(Id
) = Current_Scope
18823 and then From_Aspect_Specification
(N
)
18825 Set_No_Return
(Entity
(Id
));
18827 Error_Pragma_Arg
("no procedure& found for pragma%", Arg
);
18839 -- pragma No_Run_Time;
18841 -- Note: this pragma is retained for backwards compatibility. See
18842 -- body of Rtsfind for full details on its handling.
18844 when Pragma_No_Run_Time
=>
18846 Check_Valid_Configuration_Pragma
;
18847 Check_Arg_Count
(0);
18849 -- Remove backward compatibility if Build_Type is FSF or GPL and
18850 -- generate a warning.
18853 Ignore
: constant Boolean := Build_Type
in FSF
.. GPL
;
18856 Error_Pragma
("pragma% is ignored, has no effect??");
18858 No_Run_Time_Mode
:= True;
18859 Configurable_Run_Time_Mode
:= True;
18861 -- Set Duration to 32 bits if word size is 32
18863 if Ttypes
.System_Word_Size
= 32 then
18864 Duration_32_Bits_On_Target
:= True;
18867 -- Set appropriate restrictions
18869 Set_Restriction
(No_Finalization
, N
);
18870 Set_Restriction
(No_Exception_Handlers
, N
);
18871 Set_Restriction
(Max_Tasks
, N
, 0);
18872 Set_Restriction
(No_Tasking
, N
);
18876 -----------------------
18877 -- No_Tagged_Streams --
18878 -----------------------
18880 -- pragma No_Tagged_Streams [([Entity => ]tagged_type_local_NAME)];
18882 when Pragma_No_Tagged_Streams
=> No_Tagged_Strms
: declare
18888 Check_At_Most_N_Arguments
(1);
18890 -- One argument case
18892 if Arg_Count
= 1 then
18893 Check_Optional_Identifier
(Arg1
, Name_Entity
);
18894 Check_Arg_Is_Local_Name
(Arg1
);
18895 E_Id
:= Get_Pragma_Arg
(Arg1
);
18897 if Etype
(E_Id
) = Any_Type
then
18901 E
:= Entity
(E_Id
);
18903 Check_Duplicate_Pragma
(E
);
18905 if not Is_Tagged_Type
(E
) or else Is_Derived_Type
(E
) then
18907 ("argument for pragma% must be root tagged type", Arg1
);
18910 if Rep_Item_Too_Early
(E
, N
)
18912 Rep_Item_Too_Late
(E
, N
)
18916 Set_No_Tagged_Streams_Pragma
(E
, N
);
18919 -- Zero argument case
18922 Check_Is_In_Decl_Part_Or_Package_Spec
;
18923 No_Tagged_Streams
:= N
;
18925 end No_Tagged_Strms
;
18927 ------------------------
18928 -- No_Strict_Aliasing --
18929 ------------------------
18931 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
18933 when Pragma_No_Strict_Aliasing
=> No_Strict_Aliasing
: declare
18939 Check_At_Most_N_Arguments
(1);
18941 if Arg_Count
= 0 then
18942 Check_Valid_Configuration_Pragma
;
18943 Opt
.No_Strict_Aliasing
:= True;
18946 Check_Optional_Identifier
(Arg2
, Name_Entity
);
18947 Check_Arg_Is_Local_Name
(Arg1
);
18948 E_Id
:= Get_Pragma_Arg
(Arg1
);
18950 if Etype
(E_Id
) = Any_Type
then
18954 E
:= Entity
(E_Id
);
18956 if not Is_Access_Type
(E
) then
18957 Error_Pragma_Arg
("pragma% requires access type", Arg1
);
18960 Set_No_Strict_Aliasing
(Base_Type
(E
));
18962 end No_Strict_Aliasing
;
18964 -----------------------
18965 -- Normalize_Scalars --
18966 -----------------------
18968 -- pragma Normalize_Scalars;
18970 when Pragma_Normalize_Scalars
=>
18971 Check_Ada_83_Warning
;
18972 Check_Arg_Count
(0);
18973 Check_Valid_Configuration_Pragma
;
18975 -- Normalize_Scalars creates false positives in CodePeer, and
18976 -- incorrect negative results in GNATprove mode, so ignore this
18977 -- pragma in these modes.
18979 if not (CodePeer_Mode
or GNATprove_Mode
) then
18980 Normalize_Scalars
:= True;
18981 Init_Or_Norm_Scalars
:= True;
18988 -- pragma Obsolescent;
18990 -- pragma Obsolescent (
18991 -- [Message =>] static_string_EXPRESSION
18992 -- [,[Version =>] Ada_05]]);
18994 -- pragma Obsolescent (
18995 -- [Entity =>] NAME
18996 -- [,[Message =>] static_string_EXPRESSION
18997 -- [,[Version =>] Ada_05]] );
18999 when Pragma_Obsolescent
=> Obsolescent
: declare
19003 procedure Set_Obsolescent
(E
: Entity_Id
);
19004 -- Given an entity Ent, mark it as obsolescent if appropriate
19006 ---------------------
19007 -- Set_Obsolescent --
19008 ---------------------
19010 procedure Set_Obsolescent
(E
: Entity_Id
) is
19019 -- A pragma that applies to a Ghost entity becomes Ghost for
19020 -- the purposes of legality checks and removal of ignored Ghost
19023 Mark_Ghost_Pragma
(N
, E
);
19025 -- Entity name was given
19027 if Present
(Ename
) then
19029 -- If entity name matches, we are fine. Save entity in
19030 -- pragma argument, for ASIS use.
19032 if Chars
(Ename
) = Chars
(Ent
) then
19033 Set_Entity
(Ename
, Ent
);
19034 Generate_Reference
(Ent
, Ename
);
19036 -- If entity name does not match, only possibility is an
19037 -- enumeration literal from an enumeration type declaration.
19039 elsif Ekind
(Ent
) /= E_Enumeration_Type
then
19041 ("pragma % entity name does not match declaration");
19044 Ent
:= First_Literal
(E
);
19048 ("pragma % entity name does not match any "
19049 & "enumeration literal");
19051 elsif Chars
(Ent
) = Chars
(Ename
) then
19052 Set_Entity
(Ename
, Ent
);
19053 Generate_Reference
(Ent
, Ename
);
19057 Ent
:= Next_Literal
(Ent
);
19063 -- Ent points to entity to be marked
19065 if Arg_Count
>= 1 then
19067 -- Deal with static string argument
19069 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
19070 S
:= Strval
(Get_Pragma_Arg
(Arg1
));
19072 for J
in 1 .. String_Length
(S
) loop
19073 if not In_Character_Range
(Get_String_Char
(S
, J
)) then
19075 ("pragma% argument does not allow wide characters",
19080 Obsolescent_Warnings
.Append
19081 ((Ent
=> Ent
, Msg
=> Strval
(Get_Pragma_Arg
(Arg1
))));
19083 -- Check for Ada_05 parameter
19085 if Arg_Count
/= 1 then
19086 Check_Arg_Count
(2);
19089 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
19092 Check_Arg_Is_Identifier
(Argx
);
19094 if Chars
(Argx
) /= Name_Ada_05
then
19095 Error_Msg_Name_2
:= Name_Ada_05
;
19097 ("only allowed argument for pragma% is %", Argx
);
19100 if Ada_Version_Explicit
< Ada_2005
19101 or else not Warn_On_Ada_2005_Compatibility
19109 -- Set flag if pragma active
19112 Set_Is_Obsolescent
(Ent
);
19116 end Set_Obsolescent
;
19118 -- Start of processing for pragma Obsolescent
19123 Check_At_Most_N_Arguments
(3);
19125 -- See if first argument specifies an entity name
19129 (Chars
(Arg1
) = Name_Entity
19131 Nkind_In
(Get_Pragma_Arg
(Arg1
), N_Character_Literal
,
19133 N_Operator_Symbol
))
19135 Ename
:= Get_Pragma_Arg
(Arg1
);
19137 -- Eliminate first argument, so we can share processing
19141 Arg_Count
:= Arg_Count
- 1;
19143 -- No Entity name argument given
19149 if Arg_Count
>= 1 then
19150 Check_Optional_Identifier
(Arg1
, Name_Message
);
19152 if Arg_Count
= 2 then
19153 Check_Optional_Identifier
(Arg2
, Name_Version
);
19157 -- Get immediately preceding declaration
19160 while Present
(Decl
) and then Nkind
(Decl
) = N_Pragma
loop
19164 -- Cases where we do not follow anything other than another pragma
19168 -- First case: library level compilation unit declaration with
19169 -- the pragma immediately following the declaration.
19171 if Nkind
(Parent
(N
)) = N_Compilation_Unit_Aux
then
19173 (Defining_Entity
(Unit
(Parent
(Parent
(N
)))));
19176 -- Case 2: library unit placement for package
19180 Ent
: constant Entity_Id
:= Find_Lib_Unit_Name
;
19182 if Is_Package_Or_Generic_Package
(Ent
) then
19183 Set_Obsolescent
(Ent
);
19189 -- Cases where we must follow a declaration, including an
19190 -- abstract subprogram declaration, which is not in the
19191 -- other node subtypes.
19194 if Nkind
(Decl
) not in N_Declaration
19195 and then Nkind
(Decl
) not in N_Later_Decl_Item
19196 and then Nkind
(Decl
) not in N_Generic_Declaration
19197 and then Nkind
(Decl
) not in N_Renaming_Declaration
19198 and then Nkind
(Decl
) /= N_Abstract_Subprogram_Declaration
19201 ("pragma% misplaced, "
19202 & "must immediately follow a declaration");
19205 Set_Obsolescent
(Defining_Entity
(Decl
));
19215 -- pragma Optimize (Time | Space | Off);
19217 -- The actual check for optimize is done in Gigi. Note that this
19218 -- pragma does not actually change the optimization setting, it
19219 -- simply checks that it is consistent with the pragma.
19221 when Pragma_Optimize
=>
19222 Check_No_Identifiers
;
19223 Check_Arg_Count
(1);
19224 Check_Arg_Is_One_Of
(Arg1
, Name_Time
, Name_Space
, Name_Off
);
19226 ------------------------
19227 -- Optimize_Alignment --
19228 ------------------------
19230 -- pragma Optimize_Alignment (Time | Space | Off);
19232 when Pragma_Optimize_Alignment
=> Optimize_Alignment
: begin
19234 Check_No_Identifiers
;
19235 Check_Arg_Count
(1);
19236 Check_Valid_Configuration_Pragma
;
19239 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(Arg1
));
19242 when Name_Off
=> Opt
.Optimize_Alignment
:= 'O';
19243 when Name_Space
=> Opt
.Optimize_Alignment
:= 'S';
19244 when Name_Time
=> Opt
.Optimize_Alignment
:= 'T';
19247 Error_Pragma_Arg
("invalid argument for pragma%", Arg1
);
19251 -- Set indication that mode is set locally. If we are in fact in a
19252 -- configuration pragma file, this setting is harmless since the
19253 -- switch will get reset anyway at the start of each unit.
19255 Optimize_Alignment_Local
:= True;
19256 end Optimize_Alignment
;
19262 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
19264 when Pragma_Ordered
=> Ordered
: declare
19265 Assoc
: constant Node_Id
:= Arg1
;
19271 Check_No_Identifiers
;
19272 Check_Arg_Count
(1);
19273 Check_Arg_Is_Local_Name
(Arg1
);
19275 Type_Id
:= Get_Pragma_Arg
(Assoc
);
19276 Find_Type
(Type_Id
);
19277 Typ
:= Entity
(Type_Id
);
19279 if Typ
= Any_Type
then
19282 Typ
:= Underlying_Type
(Typ
);
19285 if not Is_Enumeration_Type
(Typ
) then
19286 Error_Pragma
("pragma% must specify enumeration type");
19289 Check_First_Subtype
(Arg1
);
19290 Set_Has_Pragma_Ordered
(Base_Type
(Typ
));
19293 -------------------
19294 -- Overflow_Mode --
19295 -------------------
19297 -- pragma Overflow_Mode
19298 -- ([General => ] MODE [, [Assertions => ] MODE]);
19300 -- MODE := STRICT | MINIMIZED | ELIMINATED
19302 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
19303 -- since System.Bignums makes this assumption. This is true of nearly
19304 -- all (all?) targets.
19306 when Pragma_Overflow_Mode
=> Overflow_Mode
: declare
19307 function Get_Overflow_Mode
19309 Arg
: Node_Id
) return Overflow_Mode_Type
;
19310 -- Function to process one pragma argument, Arg. If an identifier
19311 -- is present, it must be Name. Mode type is returned if a valid
19312 -- argument exists, otherwise an error is signalled.
19314 -----------------------
19315 -- Get_Overflow_Mode --
19316 -----------------------
19318 function Get_Overflow_Mode
19320 Arg
: Node_Id
) return Overflow_Mode_Type
19322 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
19325 Check_Optional_Identifier
(Arg
, Name
);
19326 Check_Arg_Is_Identifier
(Argx
);
19328 if Chars
(Argx
) = Name_Strict
then
19331 elsif Chars
(Argx
) = Name_Minimized
then
19334 elsif Chars
(Argx
) = Name_Eliminated
then
19335 if Ttypes
.Standard_Long_Long_Integer_Size
/= 64 then
19337 ("Eliminated not implemented on this target", Argx
);
19343 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
19345 end Get_Overflow_Mode
;
19347 -- Start of processing for Overflow_Mode
19351 Check_At_Least_N_Arguments
(1);
19352 Check_At_Most_N_Arguments
(2);
19354 -- Process first argument
19356 Scope_Suppress
.Overflow_Mode_General
:=
19357 Get_Overflow_Mode
(Name_General
, Arg1
);
19359 -- Case of only one argument
19361 if Arg_Count
= 1 then
19362 Scope_Suppress
.Overflow_Mode_Assertions
:=
19363 Scope_Suppress
.Overflow_Mode_General
;
19365 -- Case of two arguments present
19368 Scope_Suppress
.Overflow_Mode_Assertions
:=
19369 Get_Overflow_Mode
(Name_Assertions
, Arg2
);
19373 --------------------------
19374 -- Overriding Renamings --
19375 --------------------------
19377 -- pragma Overriding_Renamings;
19379 when Pragma_Overriding_Renamings
=>
19381 Check_Arg_Count
(0);
19382 Check_Valid_Configuration_Pragma
;
19383 Overriding_Renamings
:= True;
19389 -- pragma Pack (first_subtype_LOCAL_NAME);
19391 when Pragma_Pack
=> Pack
: declare
19392 Assoc
: constant Node_Id
:= Arg1
;
19394 Ignore
: Boolean := False;
19399 Check_No_Identifiers
;
19400 Check_Arg_Count
(1);
19401 Check_Arg_Is_Local_Name
(Arg1
);
19402 Type_Id
:= Get_Pragma_Arg
(Assoc
);
19404 if not Is_Entity_Name
(Type_Id
)
19405 or else not Is_Type
(Entity
(Type_Id
))
19408 ("argument for pragma% must be type or subtype", Arg1
);
19411 Find_Type
(Type_Id
);
19412 Typ
:= Entity
(Type_Id
);
19415 or else Rep_Item_Too_Early
(Typ
, N
)
19419 Typ
:= Underlying_Type
(Typ
);
19422 -- A pragma that applies to a Ghost entity becomes Ghost for the
19423 -- purposes of legality checks and removal of ignored Ghost code.
19425 Mark_Ghost_Pragma
(N
, Typ
);
19427 if not Is_Array_Type
(Typ
) and then not Is_Record_Type
(Typ
) then
19428 Error_Pragma
("pragma% must specify array or record type");
19431 Check_First_Subtype
(Arg1
);
19432 Check_Duplicate_Pragma
(Typ
);
19436 if Is_Array_Type
(Typ
) then
19437 Ctyp
:= Component_Type
(Typ
);
19439 -- Ignore pack that does nothing
19441 if Known_Static_Esize
(Ctyp
)
19442 and then Known_Static_RM_Size
(Ctyp
)
19443 and then Esize
(Ctyp
) = RM_Size
(Ctyp
)
19444 and then Addressable
(Esize
(Ctyp
))
19449 -- Process OK pragma Pack. Note that if there is a separate
19450 -- component clause present, the Pack will be cancelled. This
19451 -- processing is in Freeze.
19453 if not Rep_Item_Too_Late
(Typ
, N
) then
19455 -- In CodePeer mode, we do not need complex front-end
19456 -- expansions related to pragma Pack, so disable handling
19459 if CodePeer_Mode
then
19462 -- Normal case where we do the pack action
19466 Set_Is_Packed
(Base_Type
(Typ
));
19467 Set_Has_Non_Standard_Rep
(Base_Type
(Typ
));
19470 Set_Has_Pragma_Pack
(Base_Type
(Typ
));
19474 -- For record types, the pack is always effective
19476 else pragma Assert
(Is_Record_Type
(Typ
));
19477 if not Rep_Item_Too_Late
(Typ
, N
) then
19478 Set_Is_Packed
(Base_Type
(Typ
));
19479 Set_Has_Pragma_Pack
(Base_Type
(Typ
));
19480 Set_Has_Non_Standard_Rep
(Base_Type
(Typ
));
19491 -- There is nothing to do here, since we did all the processing for
19492 -- this pragma in Par.Prag (so that it works properly even in syntax
19495 when Pragma_Page
=>
19502 -- pragma Part_Of (ABSTRACT_STATE);
19504 -- ABSTRACT_STATE ::= NAME
19506 when Pragma_Part_Of
=> Part_Of
: declare
19507 procedure Propagate_Part_Of
19508 (Pack_Id
: Entity_Id
;
19509 State_Id
: Entity_Id
;
19510 Instance
: Node_Id
);
19511 -- Propagate the Part_Of indicator to all abstract states and
19512 -- objects declared in the visible state space of a package
19513 -- denoted by Pack_Id. State_Id is the encapsulating state.
19514 -- Instance is the package instantiation node.
19516 -----------------------
19517 -- Propagate_Part_Of --
19518 -----------------------
19520 procedure Propagate_Part_Of
19521 (Pack_Id
: Entity_Id
;
19522 State_Id
: Entity_Id
;
19523 Instance
: Node_Id
)
19525 Has_Item
: Boolean := False;
19526 -- Flag set when the visible state space contains at least one
19527 -- abstract state or variable.
19529 procedure Propagate_Part_Of
(Pack_Id
: Entity_Id
);
19530 -- Propagate the Part_Of indicator to all abstract states and
19531 -- objects declared in the visible state space of a package
19532 -- denoted by Pack_Id.
19534 -----------------------
19535 -- Propagate_Part_Of --
19536 -----------------------
19538 procedure Propagate_Part_Of
(Pack_Id
: Entity_Id
) is
19539 Constits
: Elist_Id
;
19540 Item_Id
: Entity_Id
;
19543 -- Traverse the entity chain of the package and set relevant
19544 -- attributes of abstract states and objects declared in the
19545 -- visible state space of the package.
19547 Item_Id
:= First_Entity
(Pack_Id
);
19548 while Present
(Item_Id
)
19549 and then not In_Private_Part
(Item_Id
)
19551 -- Do not consider internally generated items
19553 if not Comes_From_Source
(Item_Id
) then
19556 -- The Part_Of indicator turns an abstract state or an
19557 -- object into a constituent of the encapsulating state.
19559 elsif Ekind_In
(Item_Id
, E_Abstract_State
,
19564 Constits
:= Part_Of_Constituents
(State_Id
);
19566 if No
(Constits
) then
19567 Constits
:= New_Elmt_List
;
19568 Set_Part_Of_Constituents
(State_Id
, Constits
);
19571 Append_Elmt
(Item_Id
, Constits
);
19572 Set_Encapsulating_State
(Item_Id
, State_Id
);
19574 -- Recursively handle nested packages and instantiations
19576 elsif Ekind
(Item_Id
) = E_Package
then
19577 Propagate_Part_Of
(Item_Id
);
19580 Next_Entity
(Item_Id
);
19582 end Propagate_Part_Of
;
19584 -- Start of processing for Propagate_Part_Of
19587 Propagate_Part_Of
(Pack_Id
);
19589 -- Detect a package instantiation that is subject to a Part_Of
19590 -- indicator, but has no visible state.
19592 if not Has_Item
then
19594 ("package instantiation & has Part_Of indicator but "
19595 & "lacks visible state", Instance
, Pack_Id
);
19597 end Propagate_Part_Of
;
19601 Constits
: Elist_Id
;
19603 Encap_Id
: Entity_Id
;
19604 Item_Id
: Entity_Id
;
19608 -- Start of processing for Part_Of
19612 Check_No_Identifiers
;
19613 Check_Arg_Count
(1);
19615 Stmt
:= Find_Related_Context
(N
, Do_Checks
=> True);
19617 -- Object declaration
19619 if Nkind
(Stmt
) = N_Object_Declaration
then
19622 -- Package instantiation
19624 elsif Nkind
(Stmt
) = N_Package_Instantiation
then
19627 -- Single concurrent type declaration
19629 elsif Is_Single_Concurrent_Type_Declaration
(Stmt
) then
19632 -- Otherwise the pragma is associated with an illegal construct
19639 -- Extract the entity of the related object declaration or package
19640 -- instantiation. In the case of the instantiation, use the entity
19641 -- of the instance spec.
19643 if Nkind
(Stmt
) = N_Package_Instantiation
then
19644 Stmt
:= Instance_Spec
(Stmt
);
19647 Item_Id
:= Defining_Entity
(Stmt
);
19649 -- A pragma that applies to a Ghost entity becomes Ghost for the
19650 -- purposes of legality checks and removal of ignored Ghost code.
19652 Mark_Ghost_Pragma
(N
, Item_Id
);
19654 -- Chain the pragma on the contract for further processing by
19655 -- Analyze_Part_Of_In_Decl_Part or for completeness.
19657 Add_Contract_Item
(N
, Item_Id
);
19659 -- A variable may act as constituent of a single concurrent type
19660 -- which in turn could be declared after the variable. Due to this
19661 -- discrepancy, the full analysis of indicator Part_Of is delayed
19662 -- until the end of the enclosing declarative region (see routine
19663 -- Analyze_Part_Of_In_Decl_Part).
19665 if Ekind
(Item_Id
) = E_Variable
then
19668 -- Otherwise indicator Part_Of applies to a constant or a package
19672 Encap
:= Get_Pragma_Arg
(Arg1
);
19674 -- Detect any discrepancies between the placement of the
19675 -- constant or package instantiation with respect to state
19676 -- space and the encapsulating state.
19680 Item_Id
=> Item_Id
,
19682 Encap_Id
=> Encap_Id
,
19686 pragma Assert
(Present
(Encap_Id
));
19688 if Ekind
(Item_Id
) = E_Constant
then
19689 Constits
:= Part_Of_Constituents
(Encap_Id
);
19691 if No
(Constits
) then
19692 Constits
:= New_Elmt_List
;
19693 Set_Part_Of_Constituents
(Encap_Id
, Constits
);
19696 Append_Elmt
(Item_Id
, Constits
);
19697 Set_Encapsulating_State
(Item_Id
, Encap_Id
);
19699 -- Propagate the Part_Of indicator to the visible state
19700 -- space of the package instantiation.
19704 (Pack_Id
=> Item_Id
,
19705 State_Id
=> Encap_Id
,
19712 ----------------------------------
19713 -- Partition_Elaboration_Policy --
19714 ----------------------------------
19716 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
19718 when Pragma_Partition_Elaboration_Policy
=> PEP
: declare
19719 subtype PEP_Range
is Name_Id
19720 range First_Partition_Elaboration_Policy_Name
19721 .. Last_Partition_Elaboration_Policy_Name
;
19722 PEP_Val
: PEP_Range
;
19727 Check_Arg_Count
(1);
19728 Check_No_Identifiers
;
19729 Check_Arg_Is_Partition_Elaboration_Policy
(Arg1
);
19730 Check_Valid_Configuration_Pragma
;
19731 PEP_Val
:= Chars
(Get_Pragma_Arg
(Arg1
));
19734 when Name_Concurrent
=> PEP
:= 'C';
19735 when Name_Sequential
=> PEP
:= 'S';
19738 if Partition_Elaboration_Policy
/= ' '
19739 and then Partition_Elaboration_Policy
/= PEP
19741 Error_Msg_Sloc
:= Partition_Elaboration_Policy_Sloc
;
19743 ("partition elaboration policy incompatible with policy#");
19745 -- Set new policy, but always preserve System_Location since we
19746 -- like the error message with the run time name.
19749 Partition_Elaboration_Policy
:= PEP
;
19751 if Partition_Elaboration_Policy_Sloc
/= System_Location
then
19752 Partition_Elaboration_Policy_Sloc
:= Loc
;
19761 -- pragma Passive [(PASSIVE_FORM)];
19763 -- PASSIVE_FORM ::= Semaphore | No
19765 when Pragma_Passive
=>
19768 if Nkind
(Parent
(N
)) /= N_Task_Definition
then
19769 Error_Pragma
("pragma% must be within task definition");
19772 if Arg_Count
/= 0 then
19773 Check_Arg_Count
(1);
19774 Check_Arg_Is_One_Of
(Arg1
, Name_Semaphore
, Name_No
);
19777 ----------------------------------
19778 -- Preelaborable_Initialization --
19779 ----------------------------------
19781 -- pragma Preelaborable_Initialization (DIRECT_NAME);
19783 when Pragma_Preelaborable_Initialization
=> Preelab_Init
: declare
19788 Check_Arg_Count
(1);
19789 Check_No_Identifiers
;
19790 Check_Arg_Is_Identifier
(Arg1
);
19791 Check_Arg_Is_Local_Name
(Arg1
);
19792 Check_First_Subtype
(Arg1
);
19793 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
19795 -- A pragma that applies to a Ghost entity becomes Ghost for the
19796 -- purposes of legality checks and removal of ignored Ghost code.
19798 Mark_Ghost_Pragma
(N
, Ent
);
19800 -- The pragma may come from an aspect on a private declaration,
19801 -- even if the freeze point at which this is analyzed in the
19802 -- private part after the full view.
19804 if Has_Private_Declaration
(Ent
)
19805 and then From_Aspect_Specification
(N
)
19809 -- Check appropriate type argument
19811 elsif Is_Private_Type
(Ent
)
19812 or else Is_Protected_Type
(Ent
)
19813 or else (Is_Generic_Type
(Ent
) and then Is_Derived_Type
(Ent
))
19815 -- AI05-0028: The pragma applies to all composite types. Note
19816 -- that we apply this binding interpretation to earlier versions
19817 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
19818 -- choice since there are other compilers that do the same.
19820 or else Is_Composite_Type
(Ent
)
19826 ("pragma % can only be applied to private, formal derived, "
19827 & "protected, or composite type", Arg1
);
19830 -- Give an error if the pragma is applied to a protected type that
19831 -- does not qualify (due to having entries, or due to components
19832 -- that do not qualify).
19834 if Is_Protected_Type
(Ent
)
19835 and then not Has_Preelaborable_Initialization
(Ent
)
19838 ("protected type & does not have preelaborable "
19839 & "initialization", Ent
);
19841 -- Otherwise mark the type as definitely having preelaborable
19845 Set_Known_To_Have_Preelab_Init
(Ent
);
19848 if Has_Pragma_Preelab_Init
(Ent
)
19849 and then Warn_On_Redundant_Constructs
19851 Error_Pragma
("?r?duplicate pragma%!");
19853 Set_Has_Pragma_Preelab_Init
(Ent
);
19857 --------------------
19858 -- Persistent_BSS --
19859 --------------------
19861 -- pragma Persistent_BSS [(object_NAME)];
19863 when Pragma_Persistent_BSS
=> Persistent_BSS
: declare
19870 Check_At_Most_N_Arguments
(1);
19872 -- Case of application to specific object (one argument)
19874 if Arg_Count
= 1 then
19875 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
19877 if not Is_Entity_Name
(Get_Pragma_Arg
(Arg1
))
19879 Ekind_In
(Entity
(Get_Pragma_Arg
(Arg1
)), E_Variable
,
19882 Error_Pragma_Arg
("pragma% only applies to objects", Arg1
);
19885 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
19887 -- A pragma that applies to a Ghost entity becomes Ghost for
19888 -- the purposes of legality checks and removal of ignored Ghost
19891 Mark_Ghost_Pragma
(N
, Ent
);
19893 -- Check for duplication before inserting in list of
19894 -- representation items.
19896 Check_Duplicate_Pragma
(Ent
);
19898 if Rep_Item_Too_Late
(Ent
, N
) then
19902 Decl
:= Parent
(Ent
);
19904 if Present
(Expression
(Decl
)) then
19906 ("object for pragma% cannot have initialization", Arg1
);
19909 if not Is_Potentially_Persistent_Type
(Etype
(Ent
)) then
19911 ("object type for pragma% is not potentially persistent",
19916 Make_Linker_Section_Pragma
19917 (Ent
, Sloc
(N
), ".persistent.bss");
19918 Insert_After
(N
, Prag
);
19921 -- Case of use as configuration pragma with no arguments
19924 Check_Valid_Configuration_Pragma
;
19925 Persistent_BSS_Mode
:= True;
19927 end Persistent_BSS
;
19929 --------------------
19930 -- Rename_Pragma --
19931 --------------------
19933 -- pragma Rename_Pragma (
19934 -- [New_Name =>] IDENTIFIER,
19935 -- [Renamed =>] pragma_IDENTIFIER);
19937 when Pragma_Rename_Pragma
=> Rename_Pragma
: declare
19938 New_Name
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
19939 Old_Name
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
19943 Check_Valid_Configuration_Pragma
;
19944 Check_Arg_Count
(2);
19945 Check_Optional_Identifier
(Arg1
, Name_New_Name
);
19946 Check_Optional_Identifier
(Arg2
, Name_Renamed
);
19948 if Nkind
(New_Name
) /= N_Identifier
then
19949 Error_Pragma_Arg
("identifier expected", Arg1
);
19952 if Nkind
(Old_Name
) /= N_Identifier
then
19953 Error_Pragma_Arg
("identifier expected", Arg2
);
19956 -- The New_Name arg should not be an existing pragma (but we allow
19957 -- it; it's just a warning). The Old_Name arg must be an existing
19960 if Is_Pragma_Name
(Chars
(New_Name
)) then
19961 Error_Pragma_Arg
("??pragma is already defined", Arg1
);
19964 if not Is_Pragma_Name
(Chars
(Old_Name
)) then
19965 Error_Pragma_Arg
("existing pragma name expected", Arg1
);
19968 Map_Pragma_Name
(From
=> Chars
(New_Name
), To
=> Chars
(Old_Name
));
19975 -- pragma Polling (ON | OFF);
19977 when Pragma_Polling
=>
19979 Check_Arg_Count
(1);
19980 Check_No_Identifiers
;
19981 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
19982 Polling_Required
:= (Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
);
19984 -----------------------------------
19985 -- Post/Post_Class/Postcondition --
19986 -----------------------------------
19988 -- pragma Post (Boolean_EXPRESSION);
19989 -- pragma Post_Class (Boolean_EXPRESSION);
19990 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
19991 -- [,[Message =>] String_EXPRESSION]);
19993 -- Characteristics:
19995 -- * Analysis - The annotation undergoes initial checks to verify
19996 -- the legal placement and context. Secondary checks preanalyze the
19999 -- Analyze_Pre_Post_Condition_In_Decl_Part
20001 -- * Expansion - The annotation is expanded during the expansion of
20002 -- the related subprogram [body] contract as performed in:
20004 -- Expand_Subprogram_Contract
20006 -- * Template - The annotation utilizes the generic template of the
20007 -- related subprogram [body] when it is:
20009 -- aspect on subprogram declaration
20010 -- aspect on stand-alone subprogram body
20011 -- pragma on stand-alone subprogram body
20013 -- The annotation must prepare its own template when it is:
20015 -- pragma on subprogram declaration
20017 -- * Globals - Capture of global references must occur after full
20020 -- * Instance - The annotation is instantiated automatically when
20021 -- the related generic subprogram [body] is instantiated except for
20022 -- the "pragma on subprogram declaration" case. In that scenario
20023 -- the annotation must instantiate itself.
20026 | Pragma_Post_Class
20027 | Pragma_Postcondition
20029 Analyze_Pre_Post_Condition
;
20031 --------------------------------
20032 -- Pre/Pre_Class/Precondition --
20033 --------------------------------
20035 -- pragma Pre (Boolean_EXPRESSION);
20036 -- pragma Pre_Class (Boolean_EXPRESSION);
20037 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
20038 -- [,[Message =>] String_EXPRESSION]);
20040 -- Characteristics:
20042 -- * Analysis - The annotation undergoes initial checks to verify
20043 -- the legal placement and context. Secondary checks preanalyze the
20046 -- Analyze_Pre_Post_Condition_In_Decl_Part
20048 -- * Expansion - The annotation is expanded during the expansion of
20049 -- the related subprogram [body] contract as performed in:
20051 -- Expand_Subprogram_Contract
20053 -- * Template - The annotation utilizes the generic template of the
20054 -- related subprogram [body] when it is:
20056 -- aspect on subprogram declaration
20057 -- aspect on stand-alone subprogram body
20058 -- pragma on stand-alone subprogram body
20060 -- The annotation must prepare its own template when it is:
20062 -- pragma on subprogram declaration
20064 -- * Globals - Capture of global references must occur after full
20067 -- * Instance - The annotation is instantiated automatically when
20068 -- the related generic subprogram [body] is instantiated except for
20069 -- the "pragma on subprogram declaration" case. In that scenario
20070 -- the annotation must instantiate itself.
20074 | Pragma_Precondition
20076 Analyze_Pre_Post_Condition
;
20082 -- pragma Predicate
20083 -- ([Entity =>] type_LOCAL_NAME,
20084 -- [Check =>] boolean_EXPRESSION);
20086 when Pragma_Predicate
=> Predicate
: declare
20093 Check_Arg_Count
(2);
20094 Check_Optional_Identifier
(Arg1
, Name_Entity
);
20095 Check_Optional_Identifier
(Arg2
, Name_Check
);
20097 Check_Arg_Is_Local_Name
(Arg1
);
20099 Type_Id
:= Get_Pragma_Arg
(Arg1
);
20100 Find_Type
(Type_Id
);
20101 Typ
:= Entity
(Type_Id
);
20103 if Typ
= Any_Type
then
20107 -- A pragma that applies to a Ghost entity becomes Ghost for the
20108 -- purposes of legality checks and removal of ignored Ghost code.
20110 Mark_Ghost_Pragma
(N
, Typ
);
20112 -- The remaining processing is simply to link the pragma on to
20113 -- the rep item chain, for processing when the type is frozen.
20114 -- This is accomplished by a call to Rep_Item_Too_Late. We also
20115 -- mark the type as having predicates.
20117 -- If the current policy for predicate checking is Ignore mark the
20118 -- subtype accordingly. In the case of predicates we consider them
20119 -- enabled unless Ignore is specified (either directly or with a
20120 -- general Assertion_Policy pragma) to preserve existing warnings.
20122 Set_Has_Predicates
(Typ
);
20123 Set_Predicates_Ignored
(Typ
,
20124 Present
(Check_Policy_List
)
20126 Policy_In_Effect
(Name_Dynamic_Predicate
) = Name_Ignore
);
20127 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
20130 -----------------------
20131 -- Predicate_Failure --
20132 -----------------------
20134 -- pragma Predicate_Failure
20135 -- ([Entity =>] type_LOCAL_NAME,
20136 -- [Message =>] string_EXPRESSION);
20138 when Pragma_Predicate_Failure
=> Predicate_Failure
: declare
20145 Check_Arg_Count
(2);
20146 Check_Optional_Identifier
(Arg1
, Name_Entity
);
20147 Check_Optional_Identifier
(Arg2
, Name_Message
);
20149 Check_Arg_Is_Local_Name
(Arg1
);
20151 Type_Id
:= Get_Pragma_Arg
(Arg1
);
20152 Find_Type
(Type_Id
);
20153 Typ
:= Entity
(Type_Id
);
20155 if Typ
= Any_Type
then
20159 -- A pragma that applies to a Ghost entity becomes Ghost for the
20160 -- purposes of legality checks and removal of ignored Ghost code.
20162 Mark_Ghost_Pragma
(N
, Typ
);
20164 -- The remaining processing is simply to link the pragma on to
20165 -- the rep item chain, for processing when the type is frozen.
20166 -- This is accomplished by a call to Rep_Item_Too_Late.
20168 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
20169 end Predicate_Failure
;
20175 -- pragma Preelaborate [(library_unit_NAME)];
20177 -- Set the flag Is_Preelaborated of program unit name entity
20179 when Pragma_Preelaborate
=> Preelaborate
: declare
20180 Pa
: constant Node_Id
:= Parent
(N
);
20181 Pk
: constant Node_Kind
:= Nkind
(Pa
);
20185 Check_Ada_83_Warning
;
20186 Check_Valid_Library_Unit_Pragma
;
20188 if Nkind
(N
) = N_Null_Statement
then
20192 Ent
:= Find_Lib_Unit_Name
;
20194 -- A pragma that applies to a Ghost entity becomes Ghost for the
20195 -- purposes of legality checks and removal of ignored Ghost code.
20197 Mark_Ghost_Pragma
(N
, Ent
);
20198 Check_Duplicate_Pragma
(Ent
);
20200 -- This filters out pragmas inside generic parents that show up
20201 -- inside instantiations. Pragmas that come from aspects in the
20202 -- unit are not ignored.
20204 if Present
(Ent
) then
20205 if Pk
= N_Package_Specification
20206 and then Present
(Generic_Parent
(Pa
))
20207 and then not From_Aspect_Specification
(N
)
20212 if not Debug_Flag_U
then
20213 Set_Is_Preelaborated
(Ent
);
20219 -------------------------------
20220 -- Prefix_Exception_Messages --
20221 -------------------------------
20223 -- pragma Prefix_Exception_Messages;
20225 when Pragma_Prefix_Exception_Messages
=>
20227 Check_Valid_Configuration_Pragma
;
20228 Check_Arg_Count
(0);
20229 Prefix_Exception_Messages
:= True;
20235 -- pragma Priority (EXPRESSION);
20237 when Pragma_Priority
=> Priority
: declare
20238 P
: constant Node_Id
:= Parent
(N
);
20243 Check_No_Identifiers
;
20244 Check_Arg_Count
(1);
20248 if Nkind
(P
) = N_Subprogram_Body
then
20249 Check_In_Main_Program
;
20251 Ent
:= Defining_Unit_Name
(Specification
(P
));
20253 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
20254 Ent
:= Defining_Identifier
(Ent
);
20257 Arg
:= Get_Pragma_Arg
(Arg1
);
20258 Analyze_And_Resolve
(Arg
, Standard_Integer
);
20262 if not Is_OK_Static_Expression
(Arg
) then
20263 Flag_Non_Static_Expr
20264 ("main subprogram priority is not static!", Arg
);
20267 -- If constraint error, then we already signalled an error
20269 elsif Raises_Constraint_Error
(Arg
) then
20272 -- Otherwise check in range except if Relaxed_RM_Semantics
20273 -- where we ignore the value if out of range.
20276 if not Relaxed_RM_Semantics
20277 and then not Is_In_Range
(Arg
, RTE
(RE_Priority
))
20280 ("main subprogram priority is out of range", Arg1
);
20283 (Current_Sem_Unit
, UI_To_Int
(Expr_Value
(Arg
)));
20287 -- Load an arbitrary entity from System.Tasking.Stages or
20288 -- System.Tasking.Restricted.Stages (depending on the
20289 -- supported profile) to make sure that one of these packages
20290 -- is implicitly with'ed, since we need to have the tasking
20291 -- run time active for the pragma Priority to have any effect.
20292 -- Previously we with'ed the package System.Tasking, but this
20293 -- package does not trigger the required initialization of the
20294 -- run-time library.
20297 Discard
: Entity_Id
;
20298 pragma Warnings
(Off
, Discard
);
20300 if Restricted_Profile
then
20301 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
20303 Discard
:= RTE
(RE_Activate_Tasks
);
20307 -- Task or Protected, must be of type Integer
20309 elsif Nkind_In
(P
, N_Protected_Definition
, N_Task_Definition
) then
20310 Arg
:= Get_Pragma_Arg
(Arg1
);
20311 Ent
:= Defining_Identifier
(Parent
(P
));
20313 -- The expression must be analyzed in the special manner
20314 -- described in "Handling of Default and Per-Object
20315 -- Expressions" in sem.ads.
20317 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Any_Priority
));
20319 if not Is_OK_Static_Expression
(Arg
) then
20320 Check_Restriction
(Static_Priorities
, Arg
);
20323 -- Anything else is incorrect
20329 -- Check duplicate pragma before we chain the pragma in the Rep
20330 -- Item chain of Ent.
20332 Check_Duplicate_Pragma
(Ent
);
20333 Record_Rep_Item
(Ent
, N
);
20336 -----------------------------------
20337 -- Priority_Specific_Dispatching --
20338 -----------------------------------
20340 -- pragma Priority_Specific_Dispatching (
20341 -- policy_IDENTIFIER,
20342 -- first_priority_EXPRESSION,
20343 -- last_priority_EXPRESSION);
20345 when Pragma_Priority_Specific_Dispatching
=>
20346 Priority_Specific_Dispatching
: declare
20347 Prio_Id
: constant Entity_Id
:= RTE
(RE_Any_Priority
);
20348 -- This is the entity System.Any_Priority;
20351 Lower_Bound
: Node_Id
;
20352 Upper_Bound
: Node_Id
;
20358 Check_Arg_Count
(3);
20359 Check_No_Identifiers
;
20360 Check_Arg_Is_Task_Dispatching_Policy
(Arg1
);
20361 Check_Valid_Configuration_Pragma
;
20362 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
20363 DP
:= Fold_Upper
(Name_Buffer
(1));
20365 Lower_Bound
:= Get_Pragma_Arg
(Arg2
);
20366 Check_Arg_Is_OK_Static_Expression
(Lower_Bound
, Standard_Integer
);
20367 Lower_Val
:= Expr_Value
(Lower_Bound
);
20369 Upper_Bound
:= Get_Pragma_Arg
(Arg3
);
20370 Check_Arg_Is_OK_Static_Expression
(Upper_Bound
, Standard_Integer
);
20371 Upper_Val
:= Expr_Value
(Upper_Bound
);
20373 -- It is not allowed to use Task_Dispatching_Policy and
20374 -- Priority_Specific_Dispatching in the same partition.
20376 if Task_Dispatching_Policy
/= ' ' then
20377 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
20379 ("pragma% incompatible with Task_Dispatching_Policy#");
20381 -- Check lower bound in range
20383 elsif Lower_Val
< Expr_Value
(Type_Low_Bound
(Prio_Id
))
20385 Lower_Val
> Expr_Value
(Type_High_Bound
(Prio_Id
))
20388 ("first_priority is out of range", Arg2
);
20390 -- Check upper bound in range
20392 elsif Upper_Val
< Expr_Value
(Type_Low_Bound
(Prio_Id
))
20394 Upper_Val
> Expr_Value
(Type_High_Bound
(Prio_Id
))
20397 ("last_priority is out of range", Arg3
);
20399 -- Check that the priority range is valid
20401 elsif Lower_Val
> Upper_Val
then
20403 ("last_priority_expression must be greater than or equal to "
20404 & "first_priority_expression");
20406 -- Store the new policy, but always preserve System_Location since
20407 -- we like the error message with the run-time name.
20410 -- Check overlapping in the priority ranges specified in other
20411 -- Priority_Specific_Dispatching pragmas within the same
20412 -- partition. We can only check those we know about.
20415 Specific_Dispatching
.First
.. Specific_Dispatching
.Last
20417 if Specific_Dispatching
.Table
(J
).First_Priority
in
20418 UI_To_Int
(Lower_Val
) .. UI_To_Int
(Upper_Val
)
20419 or else Specific_Dispatching
.Table
(J
).Last_Priority
in
20420 UI_To_Int
(Lower_Val
) .. UI_To_Int
(Upper_Val
)
20423 Specific_Dispatching
.Table
(J
).Pragma_Loc
;
20425 ("priority range overlaps with "
20426 & "Priority_Specific_Dispatching#");
20430 -- The use of Priority_Specific_Dispatching is incompatible
20431 -- with Task_Dispatching_Policy.
20433 if Task_Dispatching_Policy
/= ' ' then
20434 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
20436 ("Priority_Specific_Dispatching incompatible "
20437 & "with Task_Dispatching_Policy#");
20440 -- The use of Priority_Specific_Dispatching forces ceiling
20443 if Locking_Policy
/= ' ' and then Locking_Policy
/= 'C' then
20444 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
20446 ("Priority_Specific_Dispatching incompatible "
20447 & "with Locking_Policy#");
20449 -- Set the Ceiling_Locking policy, but preserve System_Location
20450 -- since we like the error message with the run time name.
20453 Locking_Policy
:= 'C';
20455 if Locking_Policy_Sloc
/= System_Location
then
20456 Locking_Policy_Sloc
:= Loc
;
20460 -- Add entry in the table
20462 Specific_Dispatching
.Append
20463 ((Dispatching_Policy
=> DP
,
20464 First_Priority
=> UI_To_Int
(Lower_Val
),
20465 Last_Priority
=> UI_To_Int
(Upper_Val
),
20466 Pragma_Loc
=> Loc
));
20468 end Priority_Specific_Dispatching
;
20474 -- pragma Profile (profile_IDENTIFIER);
20476 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
20478 when Pragma_Profile
=>
20480 Check_Arg_Count
(1);
20481 Check_Valid_Configuration_Pragma
;
20482 Check_No_Identifiers
;
20485 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
20488 if Chars
(Argx
) = Name_Ravenscar
then
20489 Set_Ravenscar_Profile
(Ravenscar
, N
);
20491 elsif Chars
(Argx
) = Name_Gnat_Extended_Ravenscar
then
20492 Set_Ravenscar_Profile
(GNAT_Extended_Ravenscar
, N
);
20494 elsif Chars
(Argx
) = Name_Gnat_Ravenscar_EDF
then
20495 Set_Ravenscar_Profile
(GNAT_Ravenscar_EDF
, N
);
20497 elsif Chars
(Argx
) = Name_Restricted
then
20498 Set_Profile_Restrictions
20500 N
, Warn
=> Treat_Restrictions_As_Warnings
);
20502 elsif Chars
(Argx
) = Name_Rational
then
20503 Set_Rational_Profile
;
20505 elsif Chars
(Argx
) = Name_No_Implementation_Extensions
then
20506 Set_Profile_Restrictions
20507 (No_Implementation_Extensions
,
20508 N
, Warn
=> Treat_Restrictions_As_Warnings
);
20511 Error_Pragma_Arg
("& is not a valid profile", Argx
);
20515 ----------------------
20516 -- Profile_Warnings --
20517 ----------------------
20519 -- pragma Profile_Warnings (profile_IDENTIFIER);
20521 -- profile_IDENTIFIER => Restricted | Ravenscar
20523 when Pragma_Profile_Warnings
=>
20525 Check_Arg_Count
(1);
20526 Check_Valid_Configuration_Pragma
;
20527 Check_No_Identifiers
;
20530 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
20533 if Chars
(Argx
) = Name_Ravenscar
then
20534 Set_Profile_Restrictions
(Ravenscar
, N
, Warn
=> True);
20536 elsif Chars
(Argx
) = Name_Restricted
then
20537 Set_Profile_Restrictions
(Restricted
, N
, Warn
=> True);
20539 elsif Chars
(Argx
) = Name_No_Implementation_Extensions
then
20540 Set_Profile_Restrictions
20541 (No_Implementation_Extensions
, N
, Warn
=> True);
20544 Error_Pragma_Arg
("& is not a valid profile", Argx
);
20548 --------------------------
20549 -- Propagate_Exceptions --
20550 --------------------------
20552 -- pragma Propagate_Exceptions;
20554 -- Note: this pragma is obsolete and has no effect
20556 when Pragma_Propagate_Exceptions
=>
20558 Check_Arg_Count
(0);
20560 if Warn_On_Obsolescent_Feature
then
20562 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
20563 "and has no effect?j?", N
);
20566 -----------------------------
20567 -- Provide_Shift_Operators --
20568 -----------------------------
20570 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
20572 when Pragma_Provide_Shift_Operators
=>
20573 Provide_Shift_Operators
: declare
20576 procedure Declare_Shift_Operator
(Nam
: Name_Id
);
20577 -- Insert declaration and pragma Instrinsic for named shift op
20579 ----------------------------
20580 -- Declare_Shift_Operator --
20581 ----------------------------
20583 procedure Declare_Shift_Operator
(Nam
: Name_Id
) is
20589 Make_Subprogram_Declaration
(Loc
,
20590 Make_Function_Specification
(Loc
,
20591 Defining_Unit_Name
=>
20592 Make_Defining_Identifier
(Loc
, Chars
=> Nam
),
20594 Result_Definition
=>
20595 Make_Identifier
(Loc
, Chars
=> Chars
(Ent
)),
20597 Parameter_Specifications
=> New_List
(
20598 Make_Parameter_Specification
(Loc
,
20599 Defining_Identifier
=>
20600 Make_Defining_Identifier
(Loc
, Name_Value
),
20602 Make_Identifier
(Loc
, Chars
=> Chars
(Ent
))),
20604 Make_Parameter_Specification
(Loc
,
20605 Defining_Identifier
=>
20606 Make_Defining_Identifier
(Loc
, Name_Amount
),
20608 New_Occurrence_Of
(Standard_Natural
, Loc
)))));
20612 Chars
=> Name_Import
,
20613 Pragma_Argument_Associations
=> New_List
(
20614 Make_Pragma_Argument_Association
(Loc
,
20615 Expression
=> Make_Identifier
(Loc
, Name_Intrinsic
)),
20616 Make_Pragma_Argument_Association
(Loc
,
20617 Expression
=> Make_Identifier
(Loc
, Nam
))));
20619 Insert_After
(N
, Import
);
20620 Insert_After
(N
, Func
);
20621 end Declare_Shift_Operator
;
20623 -- Start of processing for Provide_Shift_Operators
20627 Check_Arg_Count
(1);
20628 Check_Arg_Is_Local_Name
(Arg1
);
20630 Arg1
:= Get_Pragma_Arg
(Arg1
);
20632 -- We must have an entity name
20634 if not Is_Entity_Name
(Arg1
) then
20636 ("pragma % must apply to integer first subtype", Arg1
);
20639 -- If no Entity, means there was a prior error so ignore
20641 if Present
(Entity
(Arg1
)) then
20642 Ent
:= Entity
(Arg1
);
20644 -- Apply error checks
20646 if not Is_First_Subtype
(Ent
) then
20648 ("cannot apply pragma %",
20649 "\& is not a first subtype",
20652 elsif not Is_Integer_Type
(Ent
) then
20654 ("cannot apply pragma %",
20655 "\& is not an integer type",
20658 elsif Has_Shift_Operator
(Ent
) then
20660 ("cannot apply pragma %",
20661 "\& already has declared shift operators",
20664 elsif Is_Frozen
(Ent
) then
20666 ("pragma % appears too late",
20667 "\& is already frozen",
20671 -- Now declare the operators. We do this during analysis rather
20672 -- than expansion, since we want the operators available if we
20673 -- are operating in -gnatc or ASIS mode.
20675 Declare_Shift_Operator
(Name_Rotate_Left
);
20676 Declare_Shift_Operator
(Name_Rotate_Right
);
20677 Declare_Shift_Operator
(Name_Shift_Left
);
20678 Declare_Shift_Operator
(Name_Shift_Right
);
20679 Declare_Shift_Operator
(Name_Shift_Right_Arithmetic
);
20681 end Provide_Shift_Operators
;
20687 -- pragma Psect_Object (
20688 -- [Internal =>] LOCAL_NAME,
20689 -- [, [External =>] EXTERNAL_SYMBOL]
20690 -- [, [Size =>] EXTERNAL_SYMBOL]);
20692 when Pragma_Common_Object
20693 | Pragma_Psect_Object
20695 Psect_Object
: declare
20696 Args
: Args_List
(1 .. 3);
20697 Names
: constant Name_List
(1 .. 3) := (
20702 Internal
: Node_Id
renames Args
(1);
20703 External
: Node_Id
renames Args
(2);
20704 Size
: Node_Id
renames Args
(3);
20706 Def_Id
: Entity_Id
;
20708 procedure Check_Arg
(Arg
: Node_Id
);
20709 -- Checks that argument is either a string literal or an
20710 -- identifier, and posts error message if not.
20716 procedure Check_Arg
(Arg
: Node_Id
) is
20718 if not Nkind_In
(Original_Node
(Arg
),
20723 ("inappropriate argument for pragma %", Arg
);
20727 -- Start of processing for Common_Object/Psect_Object
20731 Gather_Associations
(Names
, Args
);
20732 Process_Extended_Import_Export_Internal_Arg
(Internal
);
20734 Def_Id
:= Entity
(Internal
);
20736 if not Ekind_In
(Def_Id
, E_Constant
, E_Variable
) then
20738 ("pragma% must designate an object", Internal
);
20741 Check_Arg
(Internal
);
20743 if Is_Imported
(Def_Id
) or else Is_Exported
(Def_Id
) then
20745 ("cannot use pragma% for imported/exported object",
20749 if Is_Concurrent_Type
(Etype
(Internal
)) then
20751 ("cannot specify pragma % for task/protected object",
20755 if Has_Rep_Pragma
(Def_Id
, Name_Common_Object
)
20757 Has_Rep_Pragma
(Def_Id
, Name_Psect_Object
)
20759 Error_Msg_N
("??duplicate Common/Psect_Object pragma", N
);
20762 if Ekind
(Def_Id
) = E_Constant
then
20764 ("cannot specify pragma % for a constant", Internal
);
20767 if Is_Record_Type
(Etype
(Internal
)) then
20773 Ent
:= First_Entity
(Etype
(Internal
));
20774 while Present
(Ent
) loop
20775 Decl
:= Declaration_Node
(Ent
);
20777 if Ekind
(Ent
) = E_Component
20778 and then Nkind
(Decl
) = N_Component_Declaration
20779 and then Present
(Expression
(Decl
))
20780 and then Warn_On_Export_Import
20783 ("?x?object for pragma % has defaults", Internal
);
20793 if Present
(Size
) then
20797 if Present
(External
) then
20798 Check_Arg_Is_External_Name
(External
);
20801 -- If all error tests pass, link pragma on to the rep item chain
20803 Record_Rep_Item
(Def_Id
, N
);
20810 -- pragma Pure [(library_unit_NAME)];
20812 when Pragma_Pure
=> Pure
: declare
20816 Check_Ada_83_Warning
;
20818 -- If the pragma comes from a subprogram instantiation, nothing to
20819 -- check, this can happen at any level of nesting.
20821 if Is_Wrapper_Package
(Current_Scope
) then
20824 Check_Valid_Library_Unit_Pragma
;
20827 if Nkind
(N
) = N_Null_Statement
then
20831 Ent
:= Find_Lib_Unit_Name
;
20833 -- A pragma that applies to a Ghost entity becomes Ghost for the
20834 -- purposes of legality checks and removal of ignored Ghost code.
20836 Mark_Ghost_Pragma
(N
, Ent
);
20838 if not Debug_Flag_U
then
20840 Set_Has_Pragma_Pure
(Ent
);
20844 -------------------
20845 -- Pure_Function --
20846 -------------------
20848 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
20850 when Pragma_Pure_Function
=> Pure_Function
: declare
20851 Def_Id
: Entity_Id
;
20854 Effective
: Boolean := False;
20858 Check_Arg_Count
(1);
20859 Check_Optional_Identifier
(Arg1
, Name_Entity
);
20860 Check_Arg_Is_Local_Name
(Arg1
);
20861 E_Id
:= Get_Pragma_Arg
(Arg1
);
20863 if Etype
(E_Id
) = Any_Type
then
20867 -- Loop through homonyms (overloadings) of referenced entity
20869 E
:= Entity
(E_Id
);
20871 -- A pragma that applies to a Ghost entity becomes Ghost for the
20872 -- purposes of legality checks and removal of ignored Ghost code.
20874 Mark_Ghost_Pragma
(N
, E
);
20876 if Present
(E
) then
20878 Def_Id
:= Get_Base_Subprogram
(E
);
20880 if not Ekind_In
(Def_Id
, E_Function
,
20881 E_Generic_Function
,
20885 ("pragma% requires a function name", Arg1
);
20888 Set_Is_Pure
(Def_Id
);
20890 if not Has_Pragma_Pure_Function
(Def_Id
) then
20891 Set_Has_Pragma_Pure_Function
(Def_Id
);
20895 exit when From_Aspect_Specification
(N
);
20897 exit when No
(E
) or else Scope
(E
) /= Current_Scope
;
20901 and then Warn_On_Redundant_Constructs
20904 ("pragma Pure_Function on& is redundant?r?",
20910 --------------------
20911 -- Queuing_Policy --
20912 --------------------
20914 -- pragma Queuing_Policy (policy_IDENTIFIER);
20916 when Pragma_Queuing_Policy
=> declare
20920 Check_Ada_83_Warning
;
20921 Check_Arg_Count
(1);
20922 Check_No_Identifiers
;
20923 Check_Arg_Is_Queuing_Policy
(Arg1
);
20924 Check_Valid_Configuration_Pragma
;
20925 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
20926 QP
:= Fold_Upper
(Name_Buffer
(1));
20928 if Queuing_Policy
/= ' '
20929 and then Queuing_Policy
/= QP
20931 Error_Msg_Sloc
:= Queuing_Policy_Sloc
;
20932 Error_Pragma
("queuing policy incompatible with policy#");
20934 -- Set new policy, but always preserve System_Location since we
20935 -- like the error message with the run time name.
20938 Queuing_Policy
:= QP
;
20940 if Queuing_Policy_Sloc
/= System_Location
then
20941 Queuing_Policy_Sloc
:= Loc
;
20950 -- pragma Rational, for compatibility with foreign compiler
20952 when Pragma_Rational
=>
20953 Set_Rational_Profile
;
20955 ---------------------
20956 -- Refined_Depends --
20957 ---------------------
20959 -- pragma Refined_Depends (DEPENDENCY_RELATION);
20961 -- DEPENDENCY_RELATION ::=
20963 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
20965 -- DEPENDENCY_CLAUSE ::=
20966 -- OUTPUT_LIST =>[+] INPUT_LIST
20967 -- | NULL_DEPENDENCY_CLAUSE
20969 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
20971 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
20973 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
20975 -- OUTPUT ::= NAME | FUNCTION_RESULT
20978 -- where FUNCTION_RESULT is a function Result attribute_reference
20980 -- Characteristics:
20982 -- * Analysis - The annotation undergoes initial checks to verify
20983 -- the legal placement and context. Secondary checks fully analyze
20984 -- the dependency clauses/global list in:
20986 -- Analyze_Refined_Depends_In_Decl_Part
20988 -- * Expansion - None.
20990 -- * Template - The annotation utilizes the generic template of the
20991 -- related subprogram body.
20993 -- * Globals - Capture of global references must occur after full
20996 -- * Instance - The annotation is instantiated automatically when
20997 -- the related generic subprogram body is instantiated.
20999 when Pragma_Refined_Depends
=> Refined_Depends
: declare
21000 Body_Id
: Entity_Id
;
21002 Spec_Id
: Entity_Id
;
21005 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
21009 -- Chain the pragma on the contract for further processing by
21010 -- Analyze_Refined_Depends_In_Decl_Part.
21012 Add_Contract_Item
(N
, Body_Id
);
21014 -- The legality checks of pragmas Refined_Depends and
21015 -- Refined_Global are affected by the SPARK mode in effect and
21016 -- the volatility of the context. In addition these two pragmas
21017 -- are subject to an inherent order:
21019 -- 1) Refined_Global
21020 -- 2) Refined_Depends
21022 -- Analyze all these pragmas in the order outlined above
21024 Analyze_If_Present
(Pragma_SPARK_Mode
);
21025 Analyze_If_Present
(Pragma_Volatile_Function
);
21026 Analyze_If_Present
(Pragma_Refined_Global
);
21027 Analyze_Refined_Depends_In_Decl_Part
(N
);
21029 end Refined_Depends
;
21031 --------------------
21032 -- Refined_Global --
21033 --------------------
21035 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
21037 -- GLOBAL_SPECIFICATION ::=
21040 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
21042 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
21044 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
21045 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
21046 -- GLOBAL_ITEM ::= NAME
21048 -- Characteristics:
21050 -- * Analysis - The annotation undergoes initial checks to verify
21051 -- the legal placement and context. Secondary checks fully analyze
21052 -- the dependency clauses/global list in:
21054 -- Analyze_Refined_Global_In_Decl_Part
21056 -- * Expansion - None.
21058 -- * Template - The annotation utilizes the generic template of the
21059 -- related subprogram body.
21061 -- * Globals - Capture of global references must occur after full
21064 -- * Instance - The annotation is instantiated automatically when
21065 -- the related generic subprogram body is instantiated.
21067 when Pragma_Refined_Global
=> Refined_Global
: declare
21068 Body_Id
: Entity_Id
;
21070 Spec_Id
: Entity_Id
;
21073 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
21077 -- Chain the pragma on the contract for further processing by
21078 -- Analyze_Refined_Global_In_Decl_Part.
21080 Add_Contract_Item
(N
, Body_Id
);
21082 -- The legality checks of pragmas Refined_Depends and
21083 -- Refined_Global are affected by the SPARK mode in effect and
21084 -- the volatility of the context. In addition these two pragmas
21085 -- are subject to an inherent order:
21087 -- 1) Refined_Global
21088 -- 2) Refined_Depends
21090 -- Analyze all these pragmas in the order outlined above
21092 Analyze_If_Present
(Pragma_SPARK_Mode
);
21093 Analyze_If_Present
(Pragma_Volatile_Function
);
21094 Analyze_Refined_Global_In_Decl_Part
(N
);
21095 Analyze_If_Present
(Pragma_Refined_Depends
);
21097 end Refined_Global
;
21103 -- pragma Refined_Post (boolean_EXPRESSION);
21105 -- Characteristics:
21107 -- * Analysis - The annotation is fully analyzed immediately upon
21108 -- elaboration as it cannot forward reference entities.
21110 -- * Expansion - The annotation is expanded during the expansion of
21111 -- the related subprogram body contract as performed in:
21113 -- Expand_Subprogram_Contract
21115 -- * Template - The annotation utilizes the generic template of the
21116 -- related subprogram body.
21118 -- * Globals - Capture of global references must occur after full
21121 -- * Instance - The annotation is instantiated automatically when
21122 -- the related generic subprogram body is instantiated.
21124 when Pragma_Refined_Post
=> Refined_Post
: declare
21125 Body_Id
: Entity_Id
;
21127 Spec_Id
: Entity_Id
;
21130 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
21132 -- Fully analyze the pragma when it appears inside a subprogram
21133 -- body because it cannot benefit from forward references.
21137 -- Chain the pragma on the contract for completeness
21139 Add_Contract_Item
(N
, Body_Id
);
21141 -- The legality checks of pragma Refined_Post are affected by
21142 -- the SPARK mode in effect and the volatility of the context.
21143 -- Analyze all pragmas in a specific order.
21145 Analyze_If_Present
(Pragma_SPARK_Mode
);
21146 Analyze_If_Present
(Pragma_Volatile_Function
);
21147 Analyze_Pre_Post_Condition_In_Decl_Part
(N
);
21149 -- Currently it is not possible to inline pre/postconditions on
21150 -- a subprogram subject to pragma Inline_Always.
21152 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
21156 -------------------
21157 -- Refined_State --
21158 -------------------
21160 -- pragma Refined_State (REFINEMENT_LIST);
21162 -- REFINEMENT_LIST ::=
21163 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
21165 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
21167 -- CONSTITUENT_LIST ::=
21170 -- | (CONSTITUENT {, CONSTITUENT})
21172 -- CONSTITUENT ::= object_NAME | state_NAME
21174 -- Characteristics:
21176 -- * Analysis - The annotation undergoes initial checks to verify
21177 -- the legal placement and context. Secondary checks preanalyze the
21178 -- refinement clauses in:
21180 -- Analyze_Refined_State_In_Decl_Part
21182 -- * Expansion - None.
21184 -- * Template - The annotation utilizes the template of the related
21187 -- * Globals - Capture of global references must occur after full
21190 -- * Instance - The annotation is instantiated automatically when
21191 -- the related generic package body is instantiated.
21193 when Pragma_Refined_State
=> Refined_State
: declare
21194 Pack_Decl
: Node_Id
;
21195 Spec_Id
: Entity_Id
;
21199 Check_No_Identifiers
;
21200 Check_Arg_Count
(1);
21202 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
21204 -- Ensure the proper placement of the pragma. Refined states must
21205 -- be associated with a package body.
21207 if Nkind
(Pack_Decl
) = N_Package_Body
then
21210 -- Otherwise the pragma is associated with an illegal construct
21217 Spec_Id
:= Corresponding_Spec
(Pack_Decl
);
21219 -- A pragma that applies to a Ghost entity becomes Ghost for the
21220 -- purposes of legality checks and removal of ignored Ghost code.
21222 Mark_Ghost_Pragma
(N
, Spec_Id
);
21224 -- Chain the pragma on the contract for further processing by
21225 -- Analyze_Refined_State_In_Decl_Part.
21227 Add_Contract_Item
(N
, Defining_Entity
(Pack_Decl
));
21229 -- The legality checks of pragma Refined_State are affected by the
21230 -- SPARK mode in effect. Analyze all pragmas in a specific order.
21232 Analyze_If_Present
(Pragma_SPARK_Mode
);
21234 -- State refinement is allowed only when the corresponding package
21235 -- declaration has non-null pragma Abstract_State. Refinement not
21236 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
21238 if SPARK_Mode
/= Off
21240 (No
(Abstract_States
(Spec_Id
))
21241 or else Has_Null_Abstract_State
(Spec_Id
))
21244 ("useless refinement, package & does not define abstract "
21245 & "states", N
, Spec_Id
);
21250 -----------------------
21251 -- Relative_Deadline --
21252 -----------------------
21254 -- pragma Relative_Deadline (time_span_EXPRESSION);
21256 when Pragma_Relative_Deadline
=> Relative_Deadline
: declare
21257 P
: constant Node_Id
:= Parent
(N
);
21262 Check_No_Identifiers
;
21263 Check_Arg_Count
(1);
21265 Arg
:= Get_Pragma_Arg
(Arg1
);
21267 -- The expression must be analyzed in the special manner described
21268 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
21270 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Time_Span
));
21274 if Nkind
(P
) = N_Subprogram_Body
then
21275 Check_In_Main_Program
;
21277 -- Only Task and subprogram cases allowed
21279 elsif Nkind
(P
) /= N_Task_Definition
then
21283 -- Check duplicate pragma before we set the corresponding flag
21285 if Has_Relative_Deadline_Pragma
(P
) then
21286 Error_Pragma
("duplicate pragma% not allowed");
21289 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
21290 -- Relative_Deadline pragma node cannot be inserted in the Rep
21291 -- Item chain of Ent since it is rewritten by the expander as a
21292 -- procedure call statement that will break the chain.
21294 Set_Has_Relative_Deadline_Pragma
(P
);
21295 end Relative_Deadline
;
21297 ------------------------
21298 -- Remote_Access_Type --
21299 ------------------------
21301 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
21303 when Pragma_Remote_Access_Type
=> Remote_Access_Type
: declare
21308 Check_Arg_Count
(1);
21309 Check_Optional_Identifier
(Arg1
, Name_Entity
);
21310 Check_Arg_Is_Local_Name
(Arg1
);
21312 E
:= Entity
(Get_Pragma_Arg
(Arg1
));
21314 -- A pragma that applies to a Ghost entity becomes Ghost for the
21315 -- purposes of legality checks and removal of ignored Ghost code.
21317 Mark_Ghost_Pragma
(N
, E
);
21319 if Nkind
(Parent
(E
)) = N_Formal_Type_Declaration
21320 and then Ekind
(E
) = E_General_Access_Type
21321 and then Is_Class_Wide_Type
(Directly_Designated_Type
(E
))
21322 and then Scope
(Root_Type
(Directly_Designated_Type
(E
)))
21324 and then Is_Valid_Remote_Object_Type
21325 (Root_Type
(Directly_Designated_Type
(E
)))
21327 Set_Is_Remote_Types
(E
);
21331 ("pragma% applies only to formal access-to-class-wide types",
21334 end Remote_Access_Type
;
21336 ---------------------------
21337 -- Remote_Call_Interface --
21338 ---------------------------
21340 -- pragma Remote_Call_Interface [(library_unit_NAME)];
21342 when Pragma_Remote_Call_Interface
=> Remote_Call_Interface
: declare
21343 Cunit_Node
: Node_Id
;
21344 Cunit_Ent
: Entity_Id
;
21348 Check_Ada_83_Warning
;
21349 Check_Valid_Library_Unit_Pragma
;
21351 if Nkind
(N
) = N_Null_Statement
then
21355 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
21356 K
:= Nkind
(Unit
(Cunit_Node
));
21357 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
21359 -- A pragma that applies to a Ghost entity becomes Ghost for the
21360 -- purposes of legality checks and removal of ignored Ghost code.
21362 Mark_Ghost_Pragma
(N
, Cunit_Ent
);
21364 if K
= N_Package_Declaration
21365 or else K
= N_Generic_Package_Declaration
21366 or else K
= N_Subprogram_Declaration
21367 or else K
= N_Generic_Subprogram_Declaration
21368 or else (K
= N_Subprogram_Body
21369 and then Acts_As_Spec
(Unit
(Cunit_Node
)))
21374 "pragma% must apply to package or subprogram declaration");
21377 Set_Is_Remote_Call_Interface
(Cunit_Ent
);
21378 end Remote_Call_Interface
;
21384 -- pragma Remote_Types [(library_unit_NAME)];
21386 when Pragma_Remote_Types
=> Remote_Types
: declare
21387 Cunit_Node
: Node_Id
;
21388 Cunit_Ent
: Entity_Id
;
21391 Check_Ada_83_Warning
;
21392 Check_Valid_Library_Unit_Pragma
;
21394 if Nkind
(N
) = N_Null_Statement
then
21398 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
21399 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
21401 -- A pragma that applies to a Ghost entity becomes Ghost for the
21402 -- purposes of legality checks and removal of ignored Ghost code.
21404 Mark_Ghost_Pragma
(N
, Cunit_Ent
);
21406 if not Nkind_In
(Unit
(Cunit_Node
), N_Package_Declaration
,
21407 N_Generic_Package_Declaration
)
21410 ("pragma% can only apply to a package declaration");
21413 Set_Is_Remote_Types
(Cunit_Ent
);
21420 -- pragma Ravenscar;
21422 when Pragma_Ravenscar
=>
21424 Check_Arg_Count
(0);
21425 Check_Valid_Configuration_Pragma
;
21426 Set_Ravenscar_Profile
(Ravenscar
, N
);
21428 if Warn_On_Obsolescent_Feature
then
21430 ("pragma Ravenscar is an obsolescent feature?j?", N
);
21432 ("|use pragma Profile (Ravenscar) instead?j?", N
);
21435 -------------------------
21436 -- Restricted_Run_Time --
21437 -------------------------
21439 -- pragma Restricted_Run_Time;
21441 when Pragma_Restricted_Run_Time
=>
21443 Check_Arg_Count
(0);
21444 Check_Valid_Configuration_Pragma
;
21445 Set_Profile_Restrictions
21446 (Restricted
, N
, Warn
=> Treat_Restrictions_As_Warnings
);
21448 if Warn_On_Obsolescent_Feature
then
21450 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
21453 ("|use pragma Profile (Restricted) instead?j?", N
);
21460 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
21463 -- restriction_IDENTIFIER
21464 -- | restriction_parameter_IDENTIFIER => EXPRESSION
21466 when Pragma_Restrictions
=>
21467 Process_Restrictions_Or_Restriction_Warnings
21468 (Warn
=> Treat_Restrictions_As_Warnings
);
21470 --------------------------
21471 -- Restriction_Warnings --
21472 --------------------------
21474 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
21477 -- restriction_IDENTIFIER
21478 -- | restriction_parameter_IDENTIFIER => EXPRESSION
21480 when Pragma_Restriction_Warnings
=>
21482 Process_Restrictions_Or_Restriction_Warnings
(Warn
=> True);
21488 -- pragma Reviewable;
21490 when Pragma_Reviewable
=>
21491 Check_Ada_83_Warning
;
21492 Check_Arg_Count
(0);
21494 -- Call dummy debugging function rv. This is done to assist front
21495 -- end debugging. By placing a Reviewable pragma in the source
21496 -- program, a breakpoint on rv catches this place in the source,
21497 -- allowing convenient stepping to the point of interest.
21501 --------------------------
21502 -- Secondary_Stack_Size --
21503 --------------------------
21505 -- pragma Secondary_Stack_Size (EXPRESSION);
21507 when Pragma_Secondary_Stack_Size
=> Secondary_Stack_Size
: declare
21508 P
: constant Node_Id
:= Parent
(N
);
21514 Check_No_Identifiers
;
21515 Check_Arg_Count
(1);
21517 if Nkind
(P
) = N_Task_Definition
then
21518 Arg
:= Get_Pragma_Arg
(Arg1
);
21519 Ent
:= Defining_Identifier
(Parent
(P
));
21521 -- The expression must be analyzed in the special manner
21522 -- described in "Handling of Default Expressions" in sem.ads.
21524 Preanalyze_Spec_Expression
(Arg
, Any_Integer
);
21526 -- The pragma cannot appear if the No_Secondary_Stack
21527 -- restriction is in effect.
21529 Check_Restriction
(No_Secondary_Stack
, Arg
);
21531 -- Anything else is incorrect
21537 -- Check duplicate pragma before we chain the pragma in the Rep
21538 -- Item chain of Ent.
21540 Check_Duplicate_Pragma
(Ent
);
21541 Record_Rep_Item
(Ent
, N
);
21542 end Secondary_Stack_Size
;
21544 --------------------------
21545 -- Short_Circuit_And_Or --
21546 --------------------------
21548 -- pragma Short_Circuit_And_Or;
21550 when Pragma_Short_Circuit_And_Or
=>
21552 Check_Arg_Count
(0);
21553 Check_Valid_Configuration_Pragma
;
21554 Short_Circuit_And_Or
:= True;
21556 -------------------
21557 -- Share_Generic --
21558 -------------------
21560 -- pragma Share_Generic (GNAME {, GNAME});
21562 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
21564 when Pragma_Share_Generic
=>
21566 Process_Generic_List
;
21572 -- pragma Shared (LOCAL_NAME);
21574 when Pragma_Shared
=>
21576 Process_Atomic_Independent_Shared_Volatile
;
21578 --------------------
21579 -- Shared_Passive --
21580 --------------------
21582 -- pragma Shared_Passive [(library_unit_NAME)];
21584 -- Set the flag Is_Shared_Passive of program unit name entity
21586 when Pragma_Shared_Passive
=> Shared_Passive
: declare
21587 Cunit_Node
: Node_Id
;
21588 Cunit_Ent
: Entity_Id
;
21591 Check_Ada_83_Warning
;
21592 Check_Valid_Library_Unit_Pragma
;
21594 if Nkind
(N
) = N_Null_Statement
then
21598 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
21599 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
21601 -- A pragma that applies to a Ghost entity becomes Ghost for the
21602 -- purposes of legality checks and removal of ignored Ghost code.
21604 Mark_Ghost_Pragma
(N
, Cunit_Ent
);
21606 if not Nkind_In
(Unit
(Cunit_Node
), N_Package_Declaration
,
21607 N_Generic_Package_Declaration
)
21610 ("pragma% can only apply to a package declaration");
21613 Set_Is_Shared_Passive
(Cunit_Ent
);
21614 end Shared_Passive
;
21616 -----------------------
21617 -- Short_Descriptors --
21618 -----------------------
21620 -- pragma Short_Descriptors;
21622 -- Recognize and validate, but otherwise ignore
21624 when Pragma_Short_Descriptors
=>
21626 Check_Arg_Count
(0);
21627 Check_Valid_Configuration_Pragma
;
21629 ------------------------------
21630 -- Simple_Storage_Pool_Type --
21631 ------------------------------
21633 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
21635 when Pragma_Simple_Storage_Pool_Type
=>
21636 Simple_Storage_Pool_Type
: declare
21642 Check_Arg_Count
(1);
21643 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
21645 Type_Id
:= Get_Pragma_Arg
(Arg1
);
21646 Find_Type
(Type_Id
);
21647 Typ
:= Entity
(Type_Id
);
21649 if Typ
= Any_Type
then
21653 -- A pragma that applies to a Ghost entity becomes Ghost for the
21654 -- purposes of legality checks and removal of ignored Ghost code.
21656 Mark_Ghost_Pragma
(N
, Typ
);
21658 -- We require the pragma to apply to a type declared in a package
21659 -- declaration, but not (immediately) within a package body.
21661 if Ekind
(Current_Scope
) /= E_Package
21662 or else In_Package_Body
(Current_Scope
)
21665 ("pragma% can only apply to type declared immediately "
21666 & "within a package declaration");
21669 -- A simple storage pool type must be an immutably limited record
21670 -- or private type. If the pragma is given for a private type,
21671 -- the full type is similarly restricted (which is checked later
21672 -- in Freeze_Entity).
21674 if Is_Record_Type
(Typ
)
21675 and then not Is_Limited_View
(Typ
)
21678 ("pragma% can only apply to explicitly limited record type");
21680 elsif Is_Private_Type
(Typ
) and then not Is_Limited_Type
(Typ
) then
21682 ("pragma% can only apply to a private type that is limited");
21684 elsif not Is_Record_Type
(Typ
)
21685 and then not Is_Private_Type
(Typ
)
21688 ("pragma% can only apply to limited record or private type");
21691 Record_Rep_Item
(Typ
, N
);
21692 end Simple_Storage_Pool_Type
;
21694 ----------------------
21695 -- Source_File_Name --
21696 ----------------------
21698 -- There are five forms for this pragma:
21700 -- pragma Source_File_Name (
21701 -- [UNIT_NAME =>] unit_NAME,
21702 -- BODY_FILE_NAME => STRING_LITERAL
21703 -- [, [INDEX =>] INTEGER_LITERAL]);
21705 -- pragma Source_File_Name (
21706 -- [UNIT_NAME =>] unit_NAME,
21707 -- SPEC_FILE_NAME => STRING_LITERAL
21708 -- [, [INDEX =>] INTEGER_LITERAL]);
21710 -- pragma Source_File_Name (
21711 -- BODY_FILE_NAME => STRING_LITERAL
21712 -- [, DOT_REPLACEMENT => STRING_LITERAL]
21713 -- [, CASING => CASING_SPEC]);
21715 -- pragma Source_File_Name (
21716 -- SPEC_FILE_NAME => STRING_LITERAL
21717 -- [, DOT_REPLACEMENT => STRING_LITERAL]
21718 -- [, CASING => CASING_SPEC]);
21720 -- pragma Source_File_Name (
21721 -- SUBUNIT_FILE_NAME => STRING_LITERAL
21722 -- [, DOT_REPLACEMENT => STRING_LITERAL]
21723 -- [, CASING => CASING_SPEC]);
21725 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
21727 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
21728 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
21729 -- only be used when no project file is used, while SFNP can only be
21730 -- used when a project file is used.
21732 -- No processing here. Processing was completed during parsing, since
21733 -- we need to have file names set as early as possible. Units are
21734 -- loaded well before semantic processing starts.
21736 -- The only processing we defer to this point is the check for
21737 -- correct placement.
21739 when Pragma_Source_File_Name
=>
21741 Check_Valid_Configuration_Pragma
;
21743 ------------------------------
21744 -- Source_File_Name_Project --
21745 ------------------------------
21747 -- See Source_File_Name for syntax
21749 -- No processing here. Processing was completed during parsing, since
21750 -- we need to have file names set as early as possible. Units are
21751 -- loaded well before semantic processing starts.
21753 -- The only processing we defer to this point is the check for
21754 -- correct placement.
21756 when Pragma_Source_File_Name_Project
=>
21758 Check_Valid_Configuration_Pragma
;
21760 -- Check that a pragma Source_File_Name_Project is used only in a
21761 -- configuration pragmas file.
21763 -- Pragmas Source_File_Name_Project should only be generated by
21764 -- the Project Manager in configuration pragmas files.
21766 -- This is really an ugly test. It seems to depend on some
21767 -- accidental and undocumented property. At the very least it
21768 -- needs to be documented, but it would be better to have a
21769 -- clean way of testing if we are in a configuration file???
21771 if Present
(Parent
(N
)) then
21773 ("pragma% can only appear in a configuration pragmas file");
21776 ----------------------
21777 -- Source_Reference --
21778 ----------------------
21780 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
21782 -- Nothing to do, all processing completed in Par.Prag, since we need
21783 -- the information for possible parser messages that are output.
21785 when Pragma_Source_Reference
=>
21792 -- pragma SPARK_Mode [(On | Off)];
21794 when Pragma_SPARK_Mode
=> Do_SPARK_Mode
: declare
21795 Mode_Id
: SPARK_Mode_Type
;
21797 procedure Check_Pragma_Conformance
21798 (Context_Pragma
: Node_Id
;
21799 Entity
: Entity_Id
;
21800 Entity_Pragma
: Node_Id
);
21801 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
21802 -- conformance of pragma N depending the following scenarios:
21804 -- If pragma Context_Pragma is not Empty, verify that pragma N is
21805 -- compatible with the pragma Context_Pragma that was inherited
21806 -- from the context:
21807 -- * If the mode of Context_Pragma is ON, then the new mode can
21809 -- * If the mode of Context_Pragma is OFF, then the only allowed
21810 -- new mode is also OFF. Emit error if this is not the case.
21812 -- If Entity is not Empty, verify that pragma N is compatible with
21813 -- pragma Entity_Pragma that belongs to Entity.
21814 -- * If Entity_Pragma is Empty, always issue an error as this
21815 -- corresponds to the case where a previous section of Entity
21816 -- has no SPARK_Mode set.
21817 -- * If the mode of Entity_Pragma is ON, then the new mode can
21819 -- * If the mode of Entity_Pragma is OFF, then the only allowed
21820 -- new mode is also OFF. Emit error if this is not the case.
21822 procedure Check_Library_Level_Entity
(E
: Entity_Id
);
21823 -- Subsidiary to routines Process_xxx. Verify that the related
21824 -- entity E subject to pragma SPARK_Mode is library-level.
21826 procedure Process_Body
(Decl
: Node_Id
);
21827 -- Verify the legality of pragma SPARK_Mode when it appears as the
21828 -- top of the body declarations of entry, package, protected unit,
21829 -- subprogram or task unit body denoted by Decl.
21831 procedure Process_Overloadable
(Decl
: Node_Id
);
21832 -- Verify the legality of pragma SPARK_Mode when it applies to an
21833 -- entry or [generic] subprogram declaration denoted by Decl.
21835 procedure Process_Private_Part
(Decl
: Node_Id
);
21836 -- Verify the legality of pragma SPARK_Mode when it appears at the
21837 -- top of the private declarations of a package spec, protected or
21838 -- task unit declaration denoted by Decl.
21840 procedure Process_Statement_Part
(Decl
: Node_Id
);
21841 -- Verify the legality of pragma SPARK_Mode when it appears at the
21842 -- top of the statement sequence of a package body denoted by node
21845 procedure Process_Visible_Part
(Decl
: Node_Id
);
21846 -- Verify the legality of pragma SPARK_Mode when it appears at the
21847 -- top of the visible declarations of a package spec, protected or
21848 -- task unit declaration denoted by Decl. The routine is also used
21849 -- on protected or task units declared without a definition.
21851 procedure Set_SPARK_Context
;
21852 -- Subsidiary to routines Process_xxx. Set the global variables
21853 -- which represent the mode of the context from pragma N. Ensure
21854 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
21856 ------------------------------
21857 -- Check_Pragma_Conformance --
21858 ------------------------------
21860 procedure Check_Pragma_Conformance
21861 (Context_Pragma
: Node_Id
;
21862 Entity
: Entity_Id
;
21863 Entity_Pragma
: Node_Id
)
21865 Err_Id
: Entity_Id
;
21869 -- The current pragma may appear without an argument. If this
21870 -- is the case, associate all error messages with the pragma
21873 if Present
(Arg1
) then
21879 -- The mode of the current pragma is compared against that of
21880 -- an enclosing context.
21882 if Present
(Context_Pragma
) then
21883 pragma Assert
(Nkind
(Context_Pragma
) = N_Pragma
);
21885 -- Issue an error if the new mode is less restrictive than
21886 -- that of the context.
21888 if Get_SPARK_Mode_From_Annotation
(Context_Pragma
) = Off
21889 and then Get_SPARK_Mode_From_Annotation
(N
) = On
21892 ("cannot change SPARK_Mode from Off to On", Err_N
);
21893 Error_Msg_Sloc
:= Sloc
(SPARK_Mode_Pragma
);
21894 Error_Msg_N
("\SPARK_Mode was set to Off#", Err_N
);
21899 -- The mode of the current pragma is compared against that of
21900 -- an initial package, protected type, subprogram or task type
21903 if Present
(Entity
) then
21905 -- A simple protected or task type is transformed into an
21906 -- anonymous type whose name cannot be used to issue error
21907 -- messages. Recover the original entity of the type.
21909 if Ekind_In
(Entity
, E_Protected_Type
, E_Task_Type
) then
21912 (Original_Node
(Unit_Declaration_Node
(Entity
)));
21917 -- Both the initial declaration and the completion carry
21918 -- SPARK_Mode pragmas.
21920 if Present
(Entity_Pragma
) then
21921 pragma Assert
(Nkind
(Entity_Pragma
) = N_Pragma
);
21923 -- Issue an error if the new mode is less restrictive
21924 -- than that of the initial declaration.
21926 if Get_SPARK_Mode_From_Annotation
(Entity_Pragma
) = Off
21927 and then Get_SPARK_Mode_From_Annotation
(N
) = On
21929 Error_Msg_N
("incorrect use of SPARK_Mode", Err_N
);
21930 Error_Msg_Sloc
:= Sloc
(Entity_Pragma
);
21932 ("\value Off was set for SPARK_Mode on&#",
21937 -- Otherwise the initial declaration lacks a SPARK_Mode
21938 -- pragma in which case the current pragma is illegal as
21939 -- it cannot "complete".
21942 Error_Msg_N
("incorrect use of SPARK_Mode", Err_N
);
21943 Error_Msg_Sloc
:= Sloc
(Err_Id
);
21945 ("\no value was set for SPARK_Mode on&#",
21950 end Check_Pragma_Conformance
;
21952 --------------------------------
21953 -- Check_Library_Level_Entity --
21954 --------------------------------
21956 procedure Check_Library_Level_Entity
(E
: Entity_Id
) is
21957 procedure Add_Entity_To_Name_Buffer
;
21958 -- Add the E_Kind of entity E to the name buffer
21960 -------------------------------
21961 -- Add_Entity_To_Name_Buffer --
21962 -------------------------------
21964 procedure Add_Entity_To_Name_Buffer
is
21966 if Ekind_In
(E
, E_Entry
, E_Entry_Family
) then
21967 Add_Str_To_Name_Buffer
("entry");
21969 elsif Ekind_In
(E
, E_Generic_Package
,
21973 Add_Str_To_Name_Buffer
("package");
21975 elsif Ekind_In
(E
, E_Protected_Body
, E_Protected_Type
) then
21976 Add_Str_To_Name_Buffer
("protected type");
21978 elsif Ekind_In
(E
, E_Function
,
21979 E_Generic_Function
,
21980 E_Generic_Procedure
,
21984 Add_Str_To_Name_Buffer
("subprogram");
21987 pragma Assert
(Ekind_In
(E
, E_Task_Body
, E_Task_Type
));
21988 Add_Str_To_Name_Buffer
("task type");
21990 end Add_Entity_To_Name_Buffer
;
21994 Msg_1
: constant String := "incorrect placement of pragma%";
21997 -- Start of processing for Check_Library_Level_Entity
22000 if not Is_Library_Level_Entity
(E
) then
22001 Error_Msg_Name_1
:= Pname
;
22002 Error_Msg_N
(Fix_Error
(Msg_1
), N
);
22005 Add_Str_To_Name_Buffer
("\& is not a library-level ");
22006 Add_Entity_To_Name_Buffer
;
22008 Msg_2
:= Name_Find
;
22009 Error_Msg_NE
(Get_Name_String
(Msg_2
), N
, E
);
22013 end Check_Library_Level_Entity
;
22019 procedure Process_Body
(Decl
: Node_Id
) is
22020 Body_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
22021 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Decl
);
22024 -- Ignore pragma when applied to the special body created for
22025 -- inlining, recognized by its internal name _Parent.
22027 if Chars
(Body_Id
) = Name_uParent
then
22031 Check_Library_Level_Entity
(Body_Id
);
22033 -- For entry bodies, verify the legality against:
22034 -- * The mode of the context
22035 -- * The mode of the spec (if any)
22037 if Nkind_In
(Decl
, N_Entry_Body
, N_Subprogram_Body
) then
22039 -- A stand-alone subprogram body
22041 if Body_Id
= Spec_Id
then
22042 Check_Pragma_Conformance
22043 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
22045 Entity_Pragma
=> Empty
);
22047 -- An entry or subprogram body that completes a previous
22051 Check_Pragma_Conformance
22052 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
22054 Entity_Pragma
=> SPARK_Pragma
(Spec_Id
));
22058 Set_SPARK_Pragma
(Body_Id
, N
);
22059 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
22061 -- For package bodies, verify the legality against:
22062 -- * The mode of the context
22063 -- * The mode of the private part
22065 -- This case is separated from protected and task bodies
22066 -- because the statement part of the package body inherits
22067 -- the mode of the body declarations.
22069 elsif Nkind
(Decl
) = N_Package_Body
then
22070 Check_Pragma_Conformance
22071 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
22073 Entity_Pragma
=> SPARK_Aux_Pragma
(Spec_Id
));
22076 Set_SPARK_Pragma
(Body_Id
, N
);
22077 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
22078 Set_SPARK_Aux_Pragma
(Body_Id
, N
);
22079 Set_SPARK_Aux_Pragma_Inherited
(Body_Id
, True);
22081 -- For protected and task bodies, verify the legality against:
22082 -- * The mode of the context
22083 -- * The mode of the private part
22087 (Nkind_In
(Decl
, N_Protected_Body
, N_Task_Body
));
22089 Check_Pragma_Conformance
22090 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
22092 Entity_Pragma
=> SPARK_Aux_Pragma
(Spec_Id
));
22095 Set_SPARK_Pragma
(Body_Id
, N
);
22096 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
22100 --------------------------
22101 -- Process_Overloadable --
22102 --------------------------
22104 procedure Process_Overloadable
(Decl
: Node_Id
) is
22105 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
22106 Spec_Typ
: constant Entity_Id
:= Etype
(Spec_Id
);
22109 Check_Library_Level_Entity
(Spec_Id
);
22111 -- Verify the legality against:
22112 -- * The mode of the context
22114 Check_Pragma_Conformance
22115 (Context_Pragma
=> SPARK_Pragma
(Spec_Id
),
22117 Entity_Pragma
=> Empty
);
22119 Set_SPARK_Pragma
(Spec_Id
, N
);
22120 Set_SPARK_Pragma_Inherited
(Spec_Id
, False);
22122 -- When the pragma applies to the anonymous object created for
22123 -- a single task type, decorate the type as well. This scenario
22124 -- arises when the single task type lacks a task definition,
22125 -- therefore there is no issue with respect to a potential
22126 -- pragma SPARK_Mode in the private part.
22128 -- task type Anon_Task_Typ;
22129 -- Obj : Anon_Task_Typ;
22130 -- pragma SPARK_Mode ...;
22132 if Is_Single_Task_Object
(Spec_Id
) then
22133 Set_SPARK_Pragma
(Spec_Typ
, N
);
22134 Set_SPARK_Pragma_Inherited
(Spec_Typ
, False);
22135 Set_SPARK_Aux_Pragma
(Spec_Typ
, N
);
22136 Set_SPARK_Aux_Pragma_Inherited
(Spec_Typ
, True);
22138 end Process_Overloadable
;
22140 --------------------------
22141 -- Process_Private_Part --
22142 --------------------------
22144 procedure Process_Private_Part
(Decl
: Node_Id
) is
22145 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
22148 Check_Library_Level_Entity
(Spec_Id
);
22150 -- Verify the legality against:
22151 -- * The mode of the visible declarations
22153 Check_Pragma_Conformance
22154 (Context_Pragma
=> Empty
,
22156 Entity_Pragma
=> SPARK_Pragma
(Spec_Id
));
22159 Set_SPARK_Aux_Pragma
(Spec_Id
, N
);
22160 Set_SPARK_Aux_Pragma_Inherited
(Spec_Id
, False);
22161 end Process_Private_Part
;
22163 ----------------------------
22164 -- Process_Statement_Part --
22165 ----------------------------
22167 procedure Process_Statement_Part
(Decl
: Node_Id
) is
22168 Body_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
22171 Check_Library_Level_Entity
(Body_Id
);
22173 -- Verify the legality against:
22174 -- * The mode of the body declarations
22176 Check_Pragma_Conformance
22177 (Context_Pragma
=> Empty
,
22179 Entity_Pragma
=> SPARK_Pragma
(Body_Id
));
22182 Set_SPARK_Aux_Pragma
(Body_Id
, N
);
22183 Set_SPARK_Aux_Pragma_Inherited
(Body_Id
, False);
22184 end Process_Statement_Part
;
22186 --------------------------
22187 -- Process_Visible_Part --
22188 --------------------------
22190 procedure Process_Visible_Part
(Decl
: Node_Id
) is
22191 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
22192 Obj_Id
: Entity_Id
;
22195 Check_Library_Level_Entity
(Spec_Id
);
22197 -- Verify the legality against:
22198 -- * The mode of the context
22200 Check_Pragma_Conformance
22201 (Context_Pragma
=> SPARK_Pragma
(Spec_Id
),
22203 Entity_Pragma
=> Empty
);
22205 -- A task unit declared without a definition does not set the
22206 -- SPARK_Mode of the context because the task does not have any
22207 -- entries that could inherit the mode.
22209 if not Nkind_In
(Decl
, N_Single_Task_Declaration
,
22210 N_Task_Type_Declaration
)
22215 Set_SPARK_Pragma
(Spec_Id
, N
);
22216 Set_SPARK_Pragma_Inherited
(Spec_Id
, False);
22217 Set_SPARK_Aux_Pragma
(Spec_Id
, N
);
22218 Set_SPARK_Aux_Pragma_Inherited
(Spec_Id
, True);
22220 -- When the pragma applies to a single protected or task type,
22221 -- decorate the corresponding anonymous object as well.
22223 -- protected Anon_Prot_Typ is
22224 -- pragma SPARK_Mode ...;
22226 -- end Anon_Prot_Typ;
22228 -- Obj : Anon_Prot_Typ;
22230 if Is_Single_Concurrent_Type
(Spec_Id
) then
22231 Obj_Id
:= Anonymous_Object
(Spec_Id
);
22233 Set_SPARK_Pragma
(Obj_Id
, N
);
22234 Set_SPARK_Pragma_Inherited
(Obj_Id
, False);
22236 end Process_Visible_Part
;
22238 -----------------------
22239 -- Set_SPARK_Context --
22240 -----------------------
22242 procedure Set_SPARK_Context
is
22244 SPARK_Mode
:= Mode_Id
;
22245 SPARK_Mode_Pragma
:= N
;
22246 end Set_SPARK_Context
;
22254 -- Start of processing for Do_SPARK_Mode
22257 -- When a SPARK_Mode pragma appears inside an instantiation whose
22258 -- enclosing context has SPARK_Mode set to "off", the pragma has
22259 -- no semantic effect.
22261 if Ignore_SPARK_Mode_Pragmas_In_Instance
then
22262 Rewrite
(N
, Make_Null_Statement
(Loc
));
22268 Check_No_Identifiers
;
22269 Check_At_Most_N_Arguments
(1);
22271 -- Check the legality of the mode (no argument = ON)
22273 if Arg_Count
= 1 then
22274 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
22275 Mode
:= Chars
(Get_Pragma_Arg
(Arg1
));
22280 Mode_Id
:= Get_SPARK_Mode_Type
(Mode
);
22281 Context
:= Parent
(N
);
22283 -- The pragma appears in a configuration file
22285 if No
(Context
) then
22286 Check_Valid_Configuration_Pragma
;
22288 if Present
(SPARK_Mode_Pragma
) then
22291 Prev
=> SPARK_Mode_Pragma
);
22297 -- The pragma acts as a configuration pragma in a compilation unit
22299 -- pragma SPARK_Mode ...;
22300 -- package Pack is ...;
22302 elsif Nkind
(Context
) = N_Compilation_Unit
22303 and then List_Containing
(N
) = Context_Items
(Context
)
22305 Check_Valid_Configuration_Pragma
;
22308 -- Otherwise the placement of the pragma within the tree dictates
22309 -- its associated construct. Inspect the declarative list where
22310 -- the pragma resides to find a potential construct.
22314 while Present
(Stmt
) loop
22316 -- Skip prior pragmas, but check for duplicates. Note that
22317 -- this also takes care of pragmas generated for aspects.
22319 if Nkind
(Stmt
) = N_Pragma
then
22320 if Pragma_Name
(Stmt
) = Pname
then
22327 -- The pragma applies to an expression function that has
22328 -- already been rewritten into a subprogram declaration.
22330 -- function Expr_Func return ... is (...);
22331 -- pragma SPARK_Mode ...;
22333 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
22334 and then Nkind
(Original_Node
(Stmt
)) =
22335 N_Expression_Function
22337 Process_Overloadable
(Stmt
);
22340 -- The pragma applies to the anonymous object created for a
22341 -- single concurrent type.
22343 -- protected type Anon_Prot_Typ ...;
22344 -- Obj : Anon_Prot_Typ;
22345 -- pragma SPARK_Mode ...;
22347 elsif Nkind
(Stmt
) = N_Object_Declaration
22348 and then Is_Single_Concurrent_Object
22349 (Defining_Entity
(Stmt
))
22351 Process_Overloadable
(Stmt
);
22354 -- Skip internally generated code
22356 elsif not Comes_From_Source
(Stmt
) then
22359 -- The pragma applies to an entry or [generic] subprogram
22363 -- pragma SPARK_Mode ...;
22366 -- procedure Proc ...;
22367 -- pragma SPARK_Mode ...;
22369 elsif Nkind_In
(Stmt
, N_Generic_Subprogram_Declaration
,
22370 N_Subprogram_Declaration
)
22371 or else (Nkind
(Stmt
) = N_Entry_Declaration
22372 and then Is_Protected_Type
22373 (Scope
(Defining_Entity
(Stmt
))))
22375 Process_Overloadable
(Stmt
);
22378 -- Otherwise the pragma does not apply to a legal construct
22379 -- or it does not appear at the top of a declarative or a
22380 -- statement list. Issue an error and stop the analysis.
22390 -- The pragma applies to a package or a subprogram that acts as
22391 -- a compilation unit.
22393 -- procedure Proc ...;
22394 -- pragma SPARK_Mode ...;
22396 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
22397 Context
:= Unit
(Parent
(Context
));
22400 -- The pragma appears at the top of entry, package, protected
22401 -- unit, subprogram or task unit body declarations.
22403 -- entry Ent when ... is
22404 -- pragma SPARK_Mode ...;
22406 -- package body Pack is
22407 -- pragma SPARK_Mode ...;
22409 -- procedure Proc ... is
22410 -- pragma SPARK_Mode;
22412 -- protected body Prot is
22413 -- pragma SPARK_Mode ...;
22415 if Nkind_In
(Context
, N_Entry_Body
,
22421 Process_Body
(Context
);
22423 -- The pragma appears at the top of the visible or private
22424 -- declaration of a package spec, protected or task unit.
22427 -- pragma SPARK_Mode ...;
22429 -- pragma SPARK_Mode ...;
22431 -- protected [type] Prot is
22432 -- pragma SPARK_Mode ...;
22434 -- pragma SPARK_Mode ...;
22436 elsif Nkind_In
(Context
, N_Package_Specification
,
22437 N_Protected_Definition
,
22440 if List_Containing
(N
) = Visible_Declarations
(Context
) then
22441 Process_Visible_Part
(Parent
(Context
));
22443 Process_Private_Part
(Parent
(Context
));
22446 -- The pragma appears at the top of package body statements
22448 -- package body Pack is
22450 -- pragma SPARK_Mode;
22452 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
22453 and then Nkind
(Parent
(Context
)) = N_Package_Body
22455 Process_Statement_Part
(Parent
(Context
));
22457 -- The pragma appeared as an aspect of a [generic] subprogram
22458 -- declaration that acts as a compilation unit.
22461 -- procedure Proc ...;
22462 -- pragma SPARK_Mode ...;
22464 elsif Nkind_In
(Context
, N_Generic_Subprogram_Declaration
,
22465 N_Subprogram_Declaration
)
22467 Process_Overloadable
(Context
);
22469 -- The pragma does not apply to a legal construct, issue error
22477 --------------------------------
22478 -- Static_Elaboration_Desired --
22479 --------------------------------
22481 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
22483 when Pragma_Static_Elaboration_Desired
=>
22485 Check_At_Most_N_Arguments
(1);
22487 if Is_Compilation_Unit
(Current_Scope
)
22488 and then Ekind
(Current_Scope
) = E_Package
22490 Set_Static_Elaboration_Desired
(Current_Scope
, True);
22492 Error_Pragma
("pragma% must apply to a library-level package");
22499 -- pragma Storage_Size (EXPRESSION);
22501 when Pragma_Storage_Size
=> Storage_Size
: declare
22502 P
: constant Node_Id
:= Parent
(N
);
22506 Check_No_Identifiers
;
22507 Check_Arg_Count
(1);
22509 -- The expression must be analyzed in the special manner described
22510 -- in "Handling of Default Expressions" in sem.ads.
22512 Arg
:= Get_Pragma_Arg
(Arg1
);
22513 Preanalyze_Spec_Expression
(Arg
, Any_Integer
);
22515 if not Is_OK_Static_Expression
(Arg
) then
22516 Check_Restriction
(Static_Storage_Size
, Arg
);
22519 if Nkind
(P
) /= N_Task_Definition
then
22524 if Has_Storage_Size_Pragma
(P
) then
22525 Error_Pragma
("duplicate pragma% not allowed");
22527 Set_Has_Storage_Size_Pragma
(P
, True);
22530 Record_Rep_Item
(Defining_Identifier
(Parent
(P
)), N
);
22538 -- pragma Storage_Unit (NUMERIC_LITERAL);
22540 -- Only permitted argument is System'Storage_Unit value
22542 when Pragma_Storage_Unit
=>
22543 Check_No_Identifiers
;
22544 Check_Arg_Count
(1);
22545 Check_Arg_Is_Integer_Literal
(Arg1
);
22547 if Intval
(Get_Pragma_Arg
(Arg1
)) /=
22548 UI_From_Int
(Ttypes
.System_Storage_Unit
)
22550 Error_Msg_Uint_1
:= UI_From_Int
(Ttypes
.System_Storage_Unit
);
22552 ("the only allowed argument for pragma% is ^", Arg1
);
22555 --------------------
22556 -- Stream_Convert --
22557 --------------------
22559 -- pragma Stream_Convert (
22560 -- [Entity =>] type_LOCAL_NAME,
22561 -- [Read =>] function_NAME,
22562 -- [Write =>] function NAME);
22564 when Pragma_Stream_Convert
=> Stream_Convert
: declare
22565 procedure Check_OK_Stream_Convert_Function
(Arg
: Node_Id
);
22566 -- Check that the given argument is the name of a local function
22567 -- of one argument that is not overloaded earlier in the current
22568 -- local scope. A check is also made that the argument is a
22569 -- function with one parameter.
22571 --------------------------------------
22572 -- Check_OK_Stream_Convert_Function --
22573 --------------------------------------
22575 procedure Check_OK_Stream_Convert_Function
(Arg
: Node_Id
) is
22579 Check_Arg_Is_Local_Name
(Arg
);
22580 Ent
:= Entity
(Get_Pragma_Arg
(Arg
));
22582 if Has_Homonym
(Ent
) then
22584 ("argument for pragma% may not be overloaded", Arg
);
22587 if Ekind
(Ent
) /= E_Function
22588 or else No
(First_Formal
(Ent
))
22589 or else Present
(Next_Formal
(First_Formal
(Ent
)))
22592 ("argument for pragma% must be function of one argument",
22595 end Check_OK_Stream_Convert_Function
;
22597 -- Start of processing for Stream_Convert
22601 Check_Arg_Order
((Name_Entity
, Name_Read
, Name_Write
));
22602 Check_Arg_Count
(3);
22603 Check_Optional_Identifier
(Arg1
, Name_Entity
);
22604 Check_Optional_Identifier
(Arg2
, Name_Read
);
22605 Check_Optional_Identifier
(Arg3
, Name_Write
);
22606 Check_Arg_Is_Local_Name
(Arg1
);
22607 Check_OK_Stream_Convert_Function
(Arg2
);
22608 Check_OK_Stream_Convert_Function
(Arg3
);
22611 Typ
: constant Entity_Id
:=
22612 Underlying_Type
(Entity
(Get_Pragma_Arg
(Arg1
)));
22613 Read
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg2
));
22614 Write
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg3
));
22617 Check_First_Subtype
(Arg1
);
22619 -- Check for too early or too late. Note that we don't enforce
22620 -- the rule about primitive operations in this case, since, as
22621 -- is the case for explicit stream attributes themselves, these
22622 -- restrictions are not appropriate. Note that the chaining of
22623 -- the pragma by Rep_Item_Too_Late is actually the critical
22624 -- processing done for this pragma.
22626 if Rep_Item_Too_Early
(Typ
, N
)
22628 Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True)
22633 -- Return if previous error
22635 if Etype
(Typ
) = Any_Type
22637 Etype
(Read
) = Any_Type
22639 Etype
(Write
) = Any_Type
22646 if Underlying_Type
(Etype
(Read
)) /= Typ
then
22648 ("incorrect return type for function&", Arg2
);
22651 if Underlying_Type
(Etype
(First_Formal
(Write
))) /= Typ
then
22653 ("incorrect parameter type for function&", Arg3
);
22656 if Underlying_Type
(Etype
(First_Formal
(Read
))) /=
22657 Underlying_Type
(Etype
(Write
))
22660 ("result type of & does not match Read parameter type",
22664 end Stream_Convert
;
22670 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
22672 -- This is processed by the parser since some of the style checks
22673 -- take place during source scanning and parsing. This means that
22674 -- we don't need to issue error messages here.
22676 when Pragma_Style_Checks
=> Style_Checks
: declare
22677 A
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
22683 Check_No_Identifiers
;
22685 -- Two argument form
22687 if Arg_Count
= 2 then
22688 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
22695 E_Id
:= Get_Pragma_Arg
(Arg2
);
22698 if not Is_Entity_Name
(E_Id
) then
22700 ("second argument of pragma% must be entity name",
22704 E
:= Entity
(E_Id
);
22706 if not Ignore_Style_Checks_Pragmas
then
22711 Set_Suppress_Style_Checks
22712 (E
, Chars
(Get_Pragma_Arg
(Arg1
)) = Name_Off
);
22713 exit when No
(Homonym
(E
));
22720 -- One argument form
22723 Check_Arg_Count
(1);
22725 if Nkind
(A
) = N_String_Literal
then
22729 Slen
: constant Natural := Natural (String_Length
(S
));
22730 Options
: String (1 .. Slen
);
22736 C
:= Get_String_Char
(S
, Pos
(J
));
22737 exit when not In_Character_Range
(C
);
22738 Options
(J
) := Get_Character
(C
);
22740 -- If at end of string, set options. As per discussion
22741 -- above, no need to check for errors, since we issued
22742 -- them in the parser.
22745 if not Ignore_Style_Checks_Pragmas
then
22746 Set_Style_Check_Options
(Options
);
22756 elsif Nkind
(A
) = N_Identifier
then
22757 if Chars
(A
) = Name_All_Checks
then
22758 if not Ignore_Style_Checks_Pragmas
then
22760 Set_GNAT_Style_Check_Options
;
22762 Set_Default_Style_Check_Options
;
22766 elsif Chars
(A
) = Name_On
then
22767 if not Ignore_Style_Checks_Pragmas
then
22768 Style_Check
:= True;
22771 elsif Chars
(A
) = Name_Off
then
22772 if not Ignore_Style_Checks_Pragmas
then
22773 Style_Check
:= False;
22784 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
22786 when Pragma_Subtitle
=>
22788 Check_Arg_Count
(1);
22789 Check_Optional_Identifier
(Arg1
, Name_Subtitle
);
22790 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
22797 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
22799 when Pragma_Suppress
=>
22800 Process_Suppress_Unsuppress
(Suppress_Case
=> True);
22806 -- pragma Suppress_All;
22808 -- The only check made here is that the pragma has no arguments.
22809 -- There are no placement rules, and the processing required (setting
22810 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
22811 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
22812 -- then creates and inserts a pragma Suppress (All_Checks).
22814 when Pragma_Suppress_All
=>
22816 Check_Arg_Count
(0);
22818 -------------------------
22819 -- Suppress_Debug_Info --
22820 -------------------------
22822 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
22824 when Pragma_Suppress_Debug_Info
=> Suppress_Debug_Info
: declare
22825 Nam_Id
: Entity_Id
;
22829 Check_Arg_Count
(1);
22830 Check_Optional_Identifier
(Arg1
, Name_Entity
);
22831 Check_Arg_Is_Local_Name
(Arg1
);
22833 Nam_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
22835 -- A pragma that applies to a Ghost entity becomes Ghost for the
22836 -- purposes of legality checks and removal of ignored Ghost code.
22838 Mark_Ghost_Pragma
(N
, Nam_Id
);
22839 Set_Debug_Info_Off
(Nam_Id
);
22840 end Suppress_Debug_Info
;
22842 ----------------------------------
22843 -- Suppress_Exception_Locations --
22844 ----------------------------------
22846 -- pragma Suppress_Exception_Locations;
22848 when Pragma_Suppress_Exception_Locations
=>
22850 Check_Arg_Count
(0);
22851 Check_Valid_Configuration_Pragma
;
22852 Exception_Locations_Suppressed
:= True;
22854 -----------------------------
22855 -- Suppress_Initialization --
22856 -----------------------------
22858 -- pragma Suppress_Initialization ([Entity =>] type_Name);
22860 when Pragma_Suppress_Initialization
=> Suppress_Init
: declare
22866 Check_Arg_Count
(1);
22867 Check_Optional_Identifier
(Arg1
, Name_Entity
);
22868 Check_Arg_Is_Local_Name
(Arg1
);
22870 E_Id
:= Get_Pragma_Arg
(Arg1
);
22872 if Etype
(E_Id
) = Any_Type
then
22876 E
:= Entity
(E_Id
);
22878 -- A pragma that applies to a Ghost entity becomes Ghost for the
22879 -- purposes of legality checks and removal of ignored Ghost code.
22881 Mark_Ghost_Pragma
(N
, E
);
22883 if not Is_Type
(E
) and then Ekind
(E
) /= E_Variable
then
22885 ("pragma% requires variable, type or subtype", Arg1
);
22888 if Rep_Item_Too_Early
(E
, N
)
22890 Rep_Item_Too_Late
(E
, N
, FOnly
=> True)
22895 -- For incomplete/private type, set flag on full view
22897 if Is_Incomplete_Or_Private_Type
(E
) then
22898 if No
(Full_View
(Base_Type
(E
))) then
22900 ("argument of pragma% cannot be an incomplete type", Arg1
);
22902 Set_Suppress_Initialization
(Full_View
(Base_Type
(E
)));
22905 -- For first subtype, set flag on base type
22907 elsif Is_First_Subtype
(E
) then
22908 Set_Suppress_Initialization
(Base_Type
(E
));
22910 -- For other than first subtype, set flag on subtype or variable
22913 Set_Suppress_Initialization
(E
);
22921 -- pragma System_Name (DIRECT_NAME);
22923 -- Syntax check: one argument, which must be the identifier GNAT or
22924 -- the identifier GCC, no other identifiers are acceptable.
22926 when Pragma_System_Name
=>
22928 Check_No_Identifiers
;
22929 Check_Arg_Count
(1);
22930 Check_Arg_Is_One_Of
(Arg1
, Name_Gcc
, Name_Gnat
);
22932 -----------------------------
22933 -- Task_Dispatching_Policy --
22934 -----------------------------
22936 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
22938 when Pragma_Task_Dispatching_Policy
=> declare
22942 Check_Ada_83_Warning
;
22943 Check_Arg_Count
(1);
22944 Check_No_Identifiers
;
22945 Check_Arg_Is_Task_Dispatching_Policy
(Arg1
);
22946 Check_Valid_Configuration_Pragma
;
22947 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
22948 DP
:= Fold_Upper
(Name_Buffer
(1));
22950 if Task_Dispatching_Policy
/= ' '
22951 and then Task_Dispatching_Policy
/= DP
22953 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
22955 ("task dispatching policy incompatible with policy#");
22957 -- Set new policy, but always preserve System_Location since we
22958 -- like the error message with the run time name.
22961 Task_Dispatching_Policy
:= DP
;
22963 if Task_Dispatching_Policy_Sloc
/= System_Location
then
22964 Task_Dispatching_Policy_Sloc
:= Loc
;
22973 -- pragma Task_Info (EXPRESSION);
22975 when Pragma_Task_Info
=> Task_Info
: declare
22976 P
: constant Node_Id
:= Parent
(N
);
22982 if Warn_On_Obsolescent_Feature
then
22984 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
22985 & "instead?j?", N
);
22988 if Nkind
(P
) /= N_Task_Definition
then
22989 Error_Pragma
("pragma% must appear in task definition");
22992 Check_No_Identifiers
;
22993 Check_Arg_Count
(1);
22995 Analyze_And_Resolve
22996 (Get_Pragma_Arg
(Arg1
), RTE
(RE_Task_Info_Type
));
22998 if Etype
(Get_Pragma_Arg
(Arg1
)) = Any_Type
then
23002 Ent
:= Defining_Identifier
(Parent
(P
));
23004 -- Check duplicate pragma before we chain the pragma in the Rep
23005 -- Item chain of Ent.
23008 (Ent
, Name_Task_Info
, Check_Parents
=> False)
23010 Error_Pragma
("duplicate pragma% not allowed");
23013 Record_Rep_Item
(Ent
, N
);
23020 -- pragma Task_Name (string_EXPRESSION);
23022 when Pragma_Task_Name
=> Task_Name
: declare
23023 P
: constant Node_Id
:= Parent
(N
);
23028 Check_No_Identifiers
;
23029 Check_Arg_Count
(1);
23031 Arg
:= Get_Pragma_Arg
(Arg1
);
23033 -- The expression is used in the call to Create_Task, and must be
23034 -- expanded there, not in the context of the current spec. It must
23035 -- however be analyzed to capture global references, in case it
23036 -- appears in a generic context.
23038 Preanalyze_And_Resolve
(Arg
, Standard_String
);
23040 if Nkind
(P
) /= N_Task_Definition
then
23044 Ent
:= Defining_Identifier
(Parent
(P
));
23046 -- Check duplicate pragma before we chain the pragma in the Rep
23047 -- Item chain of Ent.
23050 (Ent
, Name_Task_Name
, Check_Parents
=> False)
23052 Error_Pragma
("duplicate pragma% not allowed");
23055 Record_Rep_Item
(Ent
, N
);
23062 -- pragma Task_Storage (
23063 -- [Task_Type =>] LOCAL_NAME,
23064 -- [Top_Guard =>] static_integer_EXPRESSION);
23066 when Pragma_Task_Storage
=> Task_Storage
: declare
23067 Args
: Args_List
(1 .. 2);
23068 Names
: constant Name_List
(1 .. 2) := (
23072 Task_Type
: Node_Id
renames Args
(1);
23073 Top_Guard
: Node_Id
renames Args
(2);
23079 Gather_Associations
(Names
, Args
);
23081 if No
(Task_Type
) then
23083 ("missing task_type argument for pragma%");
23086 Check_Arg_Is_Local_Name
(Task_Type
);
23088 Ent
:= Entity
(Task_Type
);
23090 if not Is_Task_Type
(Ent
) then
23092 ("argument for pragma% must be task type", Task_Type
);
23095 if No
(Top_Guard
) then
23097 ("pragma% takes two arguments", Task_Type
);
23099 Check_Arg_Is_OK_Static_Expression
(Top_Guard
, Any_Integer
);
23102 Check_First_Subtype
(Task_Type
);
23104 if Rep_Item_Too_Late
(Ent
, N
) then
23113 -- pragma Test_Case
23114 -- ([Name =>] Static_String_EXPRESSION
23115 -- ,[Mode =>] MODE_TYPE
23116 -- [, Requires => Boolean_EXPRESSION]
23117 -- [, Ensures => Boolean_EXPRESSION]);
23119 -- MODE_TYPE ::= Nominal | Robustness
23121 -- Characteristics:
23123 -- * Analysis - The annotation undergoes initial checks to verify
23124 -- the legal placement and context. Secondary checks preanalyze the
23127 -- Analyze_Test_Case_In_Decl_Part
23129 -- * Expansion - None.
23131 -- * Template - The annotation utilizes the generic template of the
23132 -- related subprogram when it is:
23134 -- aspect on subprogram declaration
23136 -- The annotation must prepare its own template when it is:
23138 -- pragma on subprogram declaration
23140 -- * Globals - Capture of global references must occur after full
23143 -- * Instance - The annotation is instantiated automatically when
23144 -- the related generic subprogram is instantiated except for the
23145 -- "pragma on subprogram declaration" case. In that scenario the
23146 -- annotation must instantiate itself.
23148 when Pragma_Test_Case
=> Test_Case
: declare
23149 procedure Check_Distinct_Name
(Subp_Id
: Entity_Id
);
23150 -- Ensure that the contract of subprogram Subp_Id does not contain
23151 -- another Test_Case pragma with the same Name as the current one.
23153 -------------------------
23154 -- Check_Distinct_Name --
23155 -------------------------
23157 procedure Check_Distinct_Name
(Subp_Id
: Entity_Id
) is
23158 Items
: constant Node_Id
:= Contract
(Subp_Id
);
23159 Name
: constant String_Id
:= Get_Name_From_CTC_Pragma
(N
);
23163 -- Inspect all Test_Case pragma of the related subprogram
23164 -- looking for one with a duplicate "Name" argument.
23166 if Present
(Items
) then
23167 Prag
:= Contract_Test_Cases
(Items
);
23168 while Present
(Prag
) loop
23169 if Pragma_Name
(Prag
) = Name_Test_Case
23171 and then String_Equal
23172 (Name
, Get_Name_From_CTC_Pragma
(Prag
))
23174 Error_Msg_Sloc
:= Sloc
(Prag
);
23175 Error_Pragma
("name for pragma % is already used #");
23178 Prag
:= Next_Pragma
(Prag
);
23181 end Check_Distinct_Name
;
23185 Pack_Decl
: constant Node_Id
:= Unit
(Cunit
(Current_Sem_Unit
));
23188 Subp_Decl
: Node_Id
;
23189 Subp_Id
: Entity_Id
;
23191 -- Start of processing for Test_Case
23195 Check_At_Least_N_Arguments
(2);
23196 Check_At_Most_N_Arguments
(4);
23198 ((Name_Name
, Name_Mode
, Name_Requires
, Name_Ensures
));
23202 Check_Optional_Identifier
(Arg1
, Name_Name
);
23203 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
23207 Check_Optional_Identifier
(Arg2
, Name_Mode
);
23208 Check_Arg_Is_One_Of
(Arg2
, Name_Nominal
, Name_Robustness
);
23210 -- Arguments "Requires" and "Ensures"
23212 if Present
(Arg3
) then
23213 if Present
(Arg4
) then
23214 Check_Identifier
(Arg3
, Name_Requires
);
23215 Check_Identifier
(Arg4
, Name_Ensures
);
23217 Check_Identifier_Is_One_Of
23218 (Arg3
, Name_Requires
, Name_Ensures
);
23222 -- Pragma Test_Case must be associated with a subprogram declared
23223 -- in a library-level package. First determine whether the current
23224 -- compilation unit is a legal context.
23226 if Nkind_In
(Pack_Decl
, N_Package_Declaration
,
23227 N_Generic_Package_Declaration
)
23231 -- Otherwise the placement is illegal
23235 ("pragma % must be specified within a package declaration");
23239 Subp_Decl
:= Find_Related_Declaration_Or_Body
(N
);
23241 -- Find the enclosing context
23243 Context
:= Parent
(Subp_Decl
);
23245 if Present
(Context
) then
23246 Context
:= Parent
(Context
);
23249 -- Verify the placement of the pragma
23251 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
23253 ("pragma % cannot be applied to abstract subprogram");
23256 elsif Nkind
(Subp_Decl
) = N_Entry_Declaration
then
23257 Error_Pragma
("pragma % cannot be applied to entry");
23260 -- The context is a [generic] subprogram declared at the top level
23261 -- of the [generic] package unit.
23263 elsif Nkind_In
(Subp_Decl
, N_Generic_Subprogram_Declaration
,
23264 N_Subprogram_Declaration
)
23265 and then Present
(Context
)
23266 and then Nkind_In
(Context
, N_Generic_Package_Declaration
,
23267 N_Package_Declaration
)
23271 -- Otherwise the placement is illegal
23275 ("pragma % must be applied to a library-level subprogram "
23280 Subp_Id
:= Defining_Entity
(Subp_Decl
);
23282 -- A pragma that applies to a Ghost entity becomes Ghost for the
23283 -- purposes of legality checks and removal of ignored Ghost code.
23285 Mark_Ghost_Pragma
(N
, Subp_Id
);
23287 -- Chain the pragma on the contract for further processing by
23288 -- Analyze_Test_Case_In_Decl_Part.
23290 Add_Contract_Item
(N
, Subp_Id
);
23292 -- Preanalyze the original aspect argument "Name" for ASIS or for
23293 -- a generic subprogram to properly capture global references.
23295 if ASIS_Mode
or else Is_Generic_Subprogram
(Subp_Id
) then
23296 Asp_Arg
:= Test_Case_Arg
(N
, Name_Name
, From_Aspect
=> True);
23298 if Present
(Asp_Arg
) then
23300 -- The argument appears with an identifier in association
23303 if Nkind
(Asp_Arg
) = N_Component_Association
then
23304 Asp_Arg
:= Expression
(Asp_Arg
);
23307 Check_Expr_Is_OK_Static_Expression
23308 (Asp_Arg
, Standard_String
);
23312 -- Ensure that the all Test_Case pragmas of the related subprogram
23313 -- have distinct names.
23315 Check_Distinct_Name
(Subp_Id
);
23317 -- Fully analyze the pragma when it appears inside an entry
23318 -- or subprogram body because it cannot benefit from forward
23321 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
23323 N_Subprogram_Body_Stub
)
23325 -- The legality checks of pragma Test_Case are affected by the
23326 -- SPARK mode in effect and the volatility of the context.
23327 -- Analyze all pragmas in a specific order.
23329 Analyze_If_Present
(Pragma_SPARK_Mode
);
23330 Analyze_If_Present
(Pragma_Volatile_Function
);
23331 Analyze_Test_Case_In_Decl_Part
(N
);
23335 --------------------------
23336 -- Thread_Local_Storage --
23337 --------------------------
23339 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
23341 when Pragma_Thread_Local_Storage
=> Thread_Local_Storage
: declare
23347 Check_Arg_Count
(1);
23348 Check_Optional_Identifier
(Arg1
, Name_Entity
);
23349 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
23351 Id
:= Get_Pragma_Arg
(Arg1
);
23354 if not Is_Entity_Name
(Id
)
23355 or else Ekind
(Entity
(Id
)) /= E_Variable
23357 Error_Pragma_Arg
("local variable name required", Arg1
);
23362 -- A pragma that applies to a Ghost entity becomes Ghost for the
23363 -- purposes of legality checks and removal of ignored Ghost code.
23365 Mark_Ghost_Pragma
(N
, E
);
23367 if Rep_Item_Too_Early
(E
, N
)
23369 Rep_Item_Too_Late
(E
, N
)
23374 Set_Has_Pragma_Thread_Local_Storage
(E
);
23375 Set_Has_Gigi_Rep_Item
(E
);
23376 end Thread_Local_Storage
;
23382 -- pragma Time_Slice (static_duration_EXPRESSION);
23384 when Pragma_Time_Slice
=> Time_Slice
: declare
23390 Check_Arg_Count
(1);
23391 Check_No_Identifiers
;
23392 Check_In_Main_Program
;
23393 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_Duration
);
23395 if not Error_Posted
(Arg1
) then
23397 while Present
(Nod
) loop
23398 if Nkind
(Nod
) = N_Pragma
23399 and then Pragma_Name
(Nod
) = Name_Time_Slice
23401 Error_Msg_Name_1
:= Pname
;
23402 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
23409 -- Process only if in main unit
23411 if Get_Source_Unit
(Loc
) = Main_Unit
then
23412 Opt
.Time_Slice_Set
:= True;
23413 Val
:= Expr_Value_R
(Get_Pragma_Arg
(Arg1
));
23415 if Val
<= Ureal_0
then
23416 Opt
.Time_Slice_Value
:= 0;
23418 elsif Val
> UR_From_Uint
(UI_From_Int
(1000)) then
23419 Opt
.Time_Slice_Value
:= 1_000_000_000
;
23422 Opt
.Time_Slice_Value
:=
23423 UI_To_Int
(UR_To_Uint
(Val
* UI_From_Int
(1_000_000
)));
23432 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
23434 -- TITLING_OPTION ::=
23435 -- [Title =>] STRING_LITERAL
23436 -- | [Subtitle =>] STRING_LITERAL
23438 when Pragma_Title
=> Title
: declare
23439 Args
: Args_List
(1 .. 2);
23440 Names
: constant Name_List
(1 .. 2) := (
23446 Gather_Associations
(Names
, Args
);
23449 for J
in 1 .. 2 loop
23450 if Present
(Args
(J
)) then
23451 Check_Arg_Is_OK_Static_Expression
23452 (Args
(J
), Standard_String
);
23457 ----------------------------
23458 -- Type_Invariant[_Class] --
23459 ----------------------------
23461 -- pragma Type_Invariant[_Class]
23462 -- ([Entity =>] type_LOCAL_NAME,
23463 -- [Check =>] EXPRESSION);
23465 when Pragma_Type_Invariant
23466 | Pragma_Type_Invariant_Class
23468 Type_Invariant
: declare
23469 I_Pragma
: Node_Id
;
23472 Check_Arg_Count
(2);
23474 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
23475 -- setting Class_Present for the Type_Invariant_Class case.
23477 Set_Class_Present
(N
, Prag_Id
= Pragma_Type_Invariant_Class
);
23478 I_Pragma
:= New_Copy
(N
);
23479 Set_Pragma_Identifier
23480 (I_Pragma
, Make_Identifier
(Loc
, Name_Invariant
));
23481 Rewrite
(N
, I_Pragma
);
23482 Set_Analyzed
(N
, False);
23484 end Type_Invariant
;
23486 ---------------------
23487 -- Unchecked_Union --
23488 ---------------------
23490 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
23492 when Pragma_Unchecked_Union
=> Unchecked_Union
: declare
23493 Assoc
: constant Node_Id
:= Arg1
;
23494 Type_Id
: constant Node_Id
:= Get_Pragma_Arg
(Assoc
);
23504 Check_No_Identifiers
;
23505 Check_Arg_Count
(1);
23506 Check_Arg_Is_Local_Name
(Arg1
);
23508 Find_Type
(Type_Id
);
23510 Typ
:= Entity
(Type_Id
);
23512 -- A pragma that applies to a Ghost entity becomes Ghost for the
23513 -- purposes of legality checks and removal of ignored Ghost code.
23515 Mark_Ghost_Pragma
(N
, Typ
);
23518 or else Rep_Item_Too_Early
(Typ
, N
)
23522 Typ
:= Underlying_Type
(Typ
);
23525 if Rep_Item_Too_Late
(Typ
, N
) then
23529 Check_First_Subtype
(Arg1
);
23531 -- Note remaining cases are references to a type in the current
23532 -- declarative part. If we find an error, we post the error on
23533 -- the relevant type declaration at an appropriate point.
23535 if not Is_Record_Type
(Typ
) then
23536 Error_Msg_N
("unchecked union must be record type", Typ
);
23539 elsif Is_Tagged_Type
(Typ
) then
23540 Error_Msg_N
("unchecked union must not be tagged", Typ
);
23543 elsif not Has_Discriminants
(Typ
) then
23545 ("unchecked union must have one discriminant", Typ
);
23548 -- Note: in previous versions of GNAT we used to check for limited
23549 -- types and give an error, but in fact the standard does allow
23550 -- Unchecked_Union on limited types, so this check was removed.
23552 -- Similarly, GNAT used to require that all discriminants have
23553 -- default values, but this is not mandated by the RM.
23555 -- Proceed with basic error checks completed
23558 Tdef
:= Type_Definition
(Declaration_Node
(Typ
));
23559 Clist
:= Component_List
(Tdef
);
23561 -- Check presence of component list and variant part
23563 if No
(Clist
) or else No
(Variant_Part
(Clist
)) then
23565 ("unchecked union must have variant part", Tdef
);
23569 -- Check components
23571 Comp
:= First_Non_Pragma
(Component_Items
(Clist
));
23572 while Present
(Comp
) loop
23573 Check_Component
(Comp
, Typ
);
23574 Next_Non_Pragma
(Comp
);
23577 -- Check variant part
23579 Vpart
:= Variant_Part
(Clist
);
23581 Variant
:= First_Non_Pragma
(Variants
(Vpart
));
23582 while Present
(Variant
) loop
23583 Check_Variant
(Variant
, Typ
);
23584 Next_Non_Pragma
(Variant
);
23588 Set_Is_Unchecked_Union
(Typ
);
23589 Set_Convention
(Typ
, Convention_C
);
23590 Set_Has_Unchecked_Union
(Base_Type
(Typ
));
23591 Set_Is_Unchecked_Union
(Base_Type
(Typ
));
23592 end Unchecked_Union
;
23594 ----------------------------
23595 -- Unevaluated_Use_Of_Old --
23596 ----------------------------
23598 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
23600 when Pragma_Unevaluated_Use_Of_Old
=>
23602 Check_Arg_Count
(1);
23603 Check_No_Identifiers
;
23604 Check_Arg_Is_One_Of
(Arg1
, Name_Error
, Name_Warn
, Name_Allow
);
23606 -- Suppress/Unsuppress can appear as a configuration pragma, or in
23607 -- a declarative part or a package spec.
23609 if not Is_Configuration_Pragma
then
23610 Check_Is_In_Decl_Part_Or_Package_Spec
;
23613 -- Store proper setting of Uneval_Old
23615 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
23616 Uneval_Old
:= Fold_Upper
(Name_Buffer
(1));
23618 ------------------------
23619 -- Unimplemented_Unit --
23620 ------------------------
23622 -- pragma Unimplemented_Unit;
23624 -- Note: this only gives an error if we are generating code, or if
23625 -- we are in a generic library unit (where the pragma appears in the
23626 -- body, not in the spec).
23628 when Pragma_Unimplemented_Unit
=> Unimplemented_Unit
: declare
23629 Cunitent
: constant Entity_Id
:=
23630 Cunit_Entity
(Get_Source_Unit
(Loc
));
23631 Ent_Kind
: constant Entity_Kind
:= Ekind
(Cunitent
);
23635 Check_Arg_Count
(0);
23637 if Operating_Mode
= Generate_Code
23638 or else Ent_Kind
= E_Generic_Function
23639 or else Ent_Kind
= E_Generic_Procedure
23640 or else Ent_Kind
= E_Generic_Package
23642 Get_Name_String
(Chars
(Cunitent
));
23643 Set_Casing
(Mixed_Case
);
23644 Write_Str
(Name_Buffer
(1 .. Name_Len
));
23645 Write_Str
(" is not supported in this configuration");
23647 raise Unrecoverable_Error
;
23649 end Unimplemented_Unit
;
23651 ------------------------
23652 -- Universal_Aliasing --
23653 ------------------------
23655 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
23657 when Pragma_Universal_Aliasing
=> Universal_Alias
: declare
23663 Check_Arg_Count
(1);
23664 Check_Optional_Identifier
(Arg2
, Name_Entity
);
23665 Check_Arg_Is_Local_Name
(Arg1
);
23666 E_Id
:= Get_Pragma_Arg
(Arg1
);
23668 if Etype
(E_Id
) = Any_Type
then
23672 E
:= Entity
(E_Id
);
23674 if not Is_Type
(E
) then
23675 Error_Pragma_Arg
("pragma% requires type", Arg1
);
23678 -- A pragma that applies to a Ghost entity becomes Ghost for the
23679 -- purposes of legality checks and removal of ignored Ghost code.
23681 Mark_Ghost_Pragma
(N
, E
);
23682 Set_Universal_Aliasing
(Base_Type
(E
));
23683 Record_Rep_Item
(E
, N
);
23684 end Universal_Alias
;
23686 --------------------
23687 -- Universal_Data --
23688 --------------------
23690 -- pragma Universal_Data [(library_unit_NAME)];
23692 when Pragma_Universal_Data
=>
23694 Error_Pragma
("??pragma% ignored (applies only to AAMP)");
23700 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
23702 when Pragma_Unmodified
=>
23703 Analyze_Unmodified_Or_Unused
;
23709 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
23711 -- or when used in a context clause:
23713 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
23715 when Pragma_Unreferenced
=>
23716 Analyze_Unreferenced_Or_Unused
;
23718 --------------------------
23719 -- Unreferenced_Objects --
23720 --------------------------
23722 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
23724 when Pragma_Unreferenced_Objects
=> Unreferenced_Objects
: declare
23726 Arg_Expr
: Node_Id
;
23727 Arg_Id
: Entity_Id
;
23729 Ghost_Error_Posted
: Boolean := False;
23730 -- Flag set when an error concerning the illegal mix of Ghost and
23731 -- non-Ghost types is emitted.
23733 Ghost_Id
: Entity_Id
:= Empty
;
23734 -- The entity of the first Ghost type encountered while processing
23735 -- the arguments of the pragma.
23739 Check_At_Least_N_Arguments
(1);
23742 while Present
(Arg
) loop
23743 Check_No_Identifier
(Arg
);
23744 Check_Arg_Is_Local_Name
(Arg
);
23745 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
23747 if Is_Entity_Name
(Arg_Expr
) then
23748 Arg_Id
:= Entity
(Arg_Expr
);
23750 if Is_Type
(Arg_Id
) then
23751 Set_Has_Pragma_Unreferenced_Objects
(Arg_Id
);
23753 -- A pragma that applies to a Ghost entity becomes Ghost
23754 -- for the purposes of legality checks and removal of
23755 -- ignored Ghost code.
23757 Mark_Ghost_Pragma
(N
, Arg_Id
);
23759 -- Capture the entity of the first Ghost type being
23760 -- processed for error detection purposes.
23762 if Is_Ghost_Entity
(Arg_Id
) then
23763 if No
(Ghost_Id
) then
23764 Ghost_Id
:= Arg_Id
;
23767 -- Otherwise the type is non-Ghost. It is illegal to mix
23768 -- references to Ghost and non-Ghost entities
23771 elsif Present
(Ghost_Id
)
23772 and then not Ghost_Error_Posted
23774 Ghost_Error_Posted
:= True;
23776 Error_Msg_Name_1
:= Pname
;
23778 ("pragma % cannot mention ghost and non-ghost types",
23781 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
23782 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
23784 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
23785 Error_Msg_NE
("\& # declared as non-ghost", N
, Arg_Id
);
23789 ("argument for pragma% must be type or subtype", Arg
);
23793 ("argument for pragma% must be type or subtype", Arg
);
23798 end Unreferenced_Objects
;
23800 ------------------------------
23801 -- Unreserve_All_Interrupts --
23802 ------------------------------
23804 -- pragma Unreserve_All_Interrupts;
23806 when Pragma_Unreserve_All_Interrupts
=>
23808 Check_Arg_Count
(0);
23810 if In_Extended_Main_Code_Unit
(Main_Unit_Entity
) then
23811 Unreserve_All_Interrupts
:= True;
23818 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
23820 when Pragma_Unsuppress
=>
23822 Process_Suppress_Unsuppress
(Suppress_Case
=> False);
23828 -- pragma Unused (LOCAL_NAME {, LOCAL_NAME});
23830 when Pragma_Unused
=>
23831 Analyze_Unmodified_Or_Unused
(Is_Unused
=> True);
23832 Analyze_Unreferenced_Or_Unused
(Is_Unused
=> True);
23834 -------------------
23835 -- Use_VADS_Size --
23836 -------------------
23838 -- pragma Use_VADS_Size;
23840 when Pragma_Use_VADS_Size
=>
23842 Check_Arg_Count
(0);
23843 Check_Valid_Configuration_Pragma
;
23844 Use_VADS_Size
:= True;
23846 ---------------------
23847 -- Validity_Checks --
23848 ---------------------
23850 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
23852 when Pragma_Validity_Checks
=> Validity_Checks
: declare
23853 A
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
23859 Check_Arg_Count
(1);
23860 Check_No_Identifiers
;
23862 -- Pragma always active unless in CodePeer or GNATprove modes,
23863 -- which use a fixed configuration of validity checks.
23865 if not (CodePeer_Mode
or GNATprove_Mode
) then
23866 if Nkind
(A
) = N_String_Literal
then
23870 Slen
: constant Natural := Natural (String_Length
(S
));
23871 Options
: String (1 .. Slen
);
23875 -- Couldn't we use a for loop here over Options'Range???
23879 C
:= Get_String_Char
(S
, Pos
(J
));
23881 -- This is a weird test, it skips setting validity
23882 -- checks entirely if any element of S is out of
23883 -- range of Character, what is that about ???
23885 exit when not In_Character_Range
(C
);
23886 Options
(J
) := Get_Character
(C
);
23889 Set_Validity_Check_Options
(Options
);
23897 elsif Nkind
(A
) = N_Identifier
then
23898 if Chars
(A
) = Name_All_Checks
then
23899 Set_Validity_Check_Options
("a");
23900 elsif Chars
(A
) = Name_On
then
23901 Validity_Checks_On
:= True;
23902 elsif Chars
(A
) = Name_Off
then
23903 Validity_Checks_On
:= False;
23907 end Validity_Checks
;
23913 -- pragma Volatile (LOCAL_NAME);
23915 when Pragma_Volatile
=>
23916 Process_Atomic_Independent_Shared_Volatile
;
23918 -------------------------
23919 -- Volatile_Components --
23920 -------------------------
23922 -- pragma Volatile_Components (array_LOCAL_NAME);
23924 -- Volatile is handled by the same circuit as Atomic_Components
23926 --------------------------
23927 -- Volatile_Full_Access --
23928 --------------------------
23930 -- pragma Volatile_Full_Access (LOCAL_NAME);
23932 when Pragma_Volatile_Full_Access
=>
23934 Process_Atomic_Independent_Shared_Volatile
;
23936 -----------------------
23937 -- Volatile_Function --
23938 -----------------------
23940 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
23942 when Pragma_Volatile_Function
=> Volatile_Function
: declare
23943 Over_Id
: Entity_Id
;
23944 Spec_Id
: Entity_Id
;
23945 Subp_Decl
: Node_Id
;
23949 Check_No_Identifiers
;
23950 Check_At_Most_N_Arguments
(1);
23953 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
23955 -- Generic subprogram
23957 if Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
23960 -- Body acts as spec
23962 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
23963 and then No
(Corresponding_Spec
(Subp_Decl
))
23967 -- Body stub acts as spec
23969 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
23970 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
23976 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
23984 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
23986 if not Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
23991 -- A pragma that applies to a Ghost entity becomes Ghost for the
23992 -- purposes of legality checks and removal of ignored Ghost code.
23994 Mark_Ghost_Pragma
(N
, Spec_Id
);
23996 -- Chain the pragma on the contract for completeness
23998 Add_Contract_Item
(N
, Spec_Id
);
24000 -- The legality checks of pragma Volatile_Function are affected by
24001 -- the SPARK mode in effect. Analyze all pragmas in a specific
24004 Analyze_If_Present
(Pragma_SPARK_Mode
);
24006 -- A volatile function cannot override a non-volatile function
24007 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
24008 -- in New_Overloaded_Entity, however at that point the pragma has
24009 -- not been processed yet.
24011 Over_Id
:= Overridden_Operation
(Spec_Id
);
24013 if Present
(Over_Id
)
24014 and then not Is_Volatile_Function
(Over_Id
)
24017 ("incompatible volatile function values in effect", Spec_Id
);
24019 Error_Msg_Sloc
:= Sloc
(Over_Id
);
24021 ("\& declared # with Volatile_Function value False",
24024 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
24026 ("\overridden # with Volatile_Function value True",
24030 -- Analyze the Boolean expression (if any)
24032 if Present
(Arg1
) then
24033 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
24035 end Volatile_Function
;
24037 ----------------------
24038 -- Warning_As_Error --
24039 ----------------------
24041 -- pragma Warning_As_Error (static_string_EXPRESSION);
24043 when Pragma_Warning_As_Error
=>
24045 Check_Arg_Count
(1);
24046 Check_No_Identifiers
;
24047 Check_Valid_Configuration_Pragma
;
24049 if not Is_Static_String_Expression
(Arg1
) then
24051 ("argument of pragma% must be static string expression",
24054 -- OK static string expression
24057 Acquire_Warning_Match_String
(Arg1
);
24058 Warnings_As_Errors_Count
:= Warnings_As_Errors_Count
+ 1;
24059 Warnings_As_Errors
(Warnings_As_Errors_Count
) :=
24060 new String'(Name_Buffer (1 .. Name_Len));
24067 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
24069 -- DETAILS ::= On | Off
24070 -- DETAILS ::= On | Off, local_NAME
24071 -- DETAILS ::= static_string_EXPRESSION
24072 -- DETAILS ::= On | Off, static_string_EXPRESSION
24074 -- TOOL_NAME ::= GNAT | GNATProve
24076 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
24078 -- Note: If the first argument matches an allowed tool name, it is
24079 -- always considered to be a tool name, even if there is a string
24080 -- variable of that name.
24082 -- Note if the second argument of DETAILS is a local_NAME then the
24083 -- second form is always understood. If the intention is to use
24084 -- the fourth form, then you can write NAME & "" to force the
24085 -- intepretation as a static_string_EXPRESSION.
24087 when Pragma_Warnings => Warnings : declare
24088 Reason : String_Id;
24092 Check_At_Least_N_Arguments (1);
24094 -- See if last argument is labeled Reason. If so, make sure we
24095 -- have a string literal or a concatenation of string literals,
24096 -- and acquire the REASON string. Then remove the REASON argument
24097 -- by decreasing Num_Args by one; Remaining processing looks only
24098 -- at first Num_Args arguments).
24101 Last_Arg : constant Node_Id :=
24102 Last (Pragma_Argument_Associations (N));
24105 if Nkind (Last_Arg) = N_Pragma_Argument_Association
24106 and then Chars (Last_Arg) = Name_Reason
24109 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
24110 Reason := End_String;
24111 Arg_Count := Arg_Count - 1;
24113 -- Not allowed in compiler units (bootstrap issues)
24115 Check_Compiler_Unit ("Reason for pragma Warnings", N);
24117 -- No REASON string, set null string as reason
24120 Reason := Null_String_Id;
24124 -- Now proceed with REASON taken care of and eliminated
24126 Check_No_Identifiers;
24128 -- If debug flag -gnatd.i is set, pragma is ignored
24130 if Debug_Flag_Dot_I then
24134 -- Process various forms of the pragma
24137 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
24138 Shifted_Args : List_Id;
24141 -- See if first argument is a tool name, currently either
24142 -- GNAT or GNATprove. If so, either ignore the pragma if the
24143 -- tool used does not match, or continue as if no tool name
24144 -- was given otherwise, by shifting the arguments.
24146 if Nkind (Argx) = N_Identifier
24147 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
24149 if Chars (Argx) = Name_Gnat then
24150 if CodePeer_Mode or GNATprove_Mode or ASIS_Mode then
24151 Rewrite (N, Make_Null_Statement (Loc));
24156 elsif Chars (Argx) = Name_Gnatprove then
24157 if not GNATprove_Mode then
24158 Rewrite (N, Make_Null_Statement (Loc));
24164 raise Program_Error;
24167 -- At this point, the pragma Warnings applies to the tool,
24168 -- so continue with shifted arguments.
24170 Arg_Count := Arg_Count - 1;
24172 if Arg_Count = 1 then
24173 Shifted_Args := New_List (New_Copy (Arg2));
24174 elsif Arg_Count = 2 then
24175 Shifted_Args := New_List (New_Copy (Arg2),
24177 elsif Arg_Count = 3 then
24178 Shifted_Args := New_List (New_Copy (Arg2),
24182 raise Program_Error;
24187 Chars => Name_Warnings,
24188 Pragma_Argument_Associations => Shifted_Args));
24193 -- One argument case
24195 if Arg_Count = 1 then
24197 -- On/Off one argument case was processed by parser
24199 if Nkind (Argx) = N_Identifier
24200 and then Nam_In (Chars (Argx), Name_On, Name_Off)
24204 -- One argument case must be ON/OFF or static string expr
24206 elsif not Is_Static_String_Expression (Arg1) then
24208 ("argument of pragma% must be On/Off or static string "
24209 & "expression", Arg1);
24211 -- One argument string expression case
24215 Lit : constant Node_Id := Expr_Value_S (Argx);
24216 Str : constant String_Id := Strval (Lit);
24217 Len : constant Nat := String_Length (Str);
24225 while J <= Len loop
24226 C := Get_String_Char (Str, J);
24227 OK := In_Character_Range (C);
24230 Chr := Get_Character (C);
24232 -- Dash case: only -Wxxx is accepted
24239 C := Get_String_Char (Str, J);
24240 Chr := Get_Character (C);
24241 exit when Chr = 'W
';
24246 elsif J < Len and then Chr = '.' then
24248 C := Get_String_Char (Str, J);
24249 Chr := Get_Character (C);
24251 if not Set_Dot_Warning_Switch (Chr) then
24253 ("invalid warning switch character "
24254 & '.' & Chr, Arg1);
24260 OK := Set_Warning_Switch (Chr);
24265 ("invalid warning switch character " & Chr,
24271 ("invalid wide character in warning switch ",
24280 -- Two or more arguments (must be two)
24283 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
24284 Check_Arg_Count (2);
24292 E_Id := Get_Pragma_Arg (Arg2);
24295 -- In the expansion of an inlined body, a reference to
24296 -- the formal may be wrapped in a conversion if the
24297 -- actual is a conversion. Retrieve the real entity name.
24299 if (In_Instance_Body or In_Inlined_Body)
24300 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
24302 E_Id := Expression (E_Id);
24305 -- Entity name case
24307 if Is_Entity_Name (E_Id) then
24308 E := Entity (E_Id);
24315 (E, (Chars (Get_Pragma_Arg (Arg1)) =
24318 -- For OFF case, make entry in warnings off
24319 -- pragma table for later processing. But we do
24320 -- not do that within an instance, since these
24321 -- warnings are about what is needed in the
24322 -- template, not an instance of it.
24324 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
24325 and then Warn_On_Warnings_Off
24326 and then not In_Instance
24328 Warnings_Off_Pragmas.Append ((N, E, Reason));
24331 if Is_Enumeration_Type (E) then
24335 Lit := First_Literal (E);
24336 while Present (Lit) loop
24337 Set_Warnings_Off (Lit);
24338 Next_Literal (Lit);
24343 exit when No (Homonym (E));
24348 -- Error if not entity or static string expression case
24350 elsif not Is_Static_String_Expression (Arg2) then
24352 ("second argument of pragma% must be entity name "
24353 & "or static string expression", Arg2);
24355 -- Static string expression case
24358 Acquire_Warning_Match_String (Arg2);
24360 -- Note on configuration pragma case: If this is a
24361 -- configuration pragma, then for an OFF pragma, we
24362 -- just set Config True in the call, which is all
24363 -- that needs to be done. For the case of ON, this
24364 -- is normally an error, unless it is canceling the
24365 -- effect of a previous OFF pragma in the same file.
24366 -- In any other case, an error will be signalled (ON
24367 -- with no matching OFF).
24369 -- Note: We set Used if we are inside a generic to
24370 -- disable the test that the non-config case actually
24371 -- cancels a warning. That's because we can't be sure
24372 -- there isn't an instantiation in some other unit
24373 -- where a warning is suppressed.
24375 -- We could do a little better here by checking if the
24376 -- generic unit we are inside is public, but for now
24377 -- we don't bother with that refinement.
24379 if Chars (Argx) = Name_Off then
24380 Set_Specific_Warning_Off
24381 (Loc, Name_Buffer (1 .. Name_Len), Reason,
24382 Config => Is_Configuration_Pragma,
24383 Used => Inside_A_Generic or else In_Instance);
24385 elsif Chars (Argx) = Name_On then
24386 Set_Specific_Warning_On
24387 (Loc, Name_Buffer (1 .. Name_Len), Err);
24391 ("??pragma Warnings On with no matching "
24392 & "Warnings Off", Loc);
24401 -------------------
24402 -- Weak_External --
24403 -------------------
24405 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
24407 when Pragma_Weak_External => Weak_External : declare
24412 Check_Arg_Count (1);
24413 Check_Optional_Identifier (Arg1, Name_Entity);
24414 Check_Arg_Is_Library_Level_Local_Name (Arg1);
24415 Ent := Entity (Get_Pragma_Arg (Arg1));
24417 if Rep_Item_Too_Early (Ent, N) then
24420 Ent := Underlying_Type (Ent);
24423 -- The only processing required is to link this item on to the
24424 -- list of rep items for the given entity. This is accomplished
24425 -- by the call to Rep_Item_Too_Late (when no error is detected
24426 -- and False is returned).
24428 if Rep_Item_Too_Late (Ent, N) then
24431 Set_Has_Gigi_Rep_Item (Ent);
24435 -----------------------------
24436 -- Wide_Character_Encoding --
24437 -----------------------------
24439 -- pragma Wide_Character_Encoding (IDENTIFIER);
24441 when Pragma_Wide_Character_Encoding =>
24444 -- Nothing to do, handled in parser. Note that we do not enforce
24445 -- configuration pragma placement, this pragma can appear at any
24446 -- place in the source, allowing mixed encodings within a single
24451 --------------------
24452 -- Unknown_Pragma --
24453 --------------------
24455 -- Should be impossible, since the case of an unknown pragma is
24456 -- separately processed before the case statement is entered.
24458 when Unknown_Pragma =>
24459 raise Program_Error;
24462 -- AI05-0144: detect dangerous order dependence. Disabled for now,
24463 -- until AI is formally approved.
24465 -- Check_Order_Dependence;
24468 when Pragma_Exit => null;
24469 end Analyze_Pragma;
24471 ---------------------------------------------
24472 -- Analyze_Pre_Post_Condition_In_Decl_Part --
24473 ---------------------------------------------
24475 -- WARNING: This routine manages Ghost regions. Return statements must be
24476 -- replaced by gotos which jump to the end of the routine and restore the
24479 procedure Analyze_Pre_Post_Condition_In_Decl_Part
24481 Freeze_Id : Entity_Id := Empty)
24483 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
24484 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
24486 Disp_Typ : Entity_Id;
24487 -- The dispatching type of the subprogram subject to the pre- or
24490 function Check_References (Nod : Node_Id) return Traverse_Result;
24491 -- Check that expression Nod does not mention non-primitives of the
24492 -- type, global objects of the type, or other illegalities described
24493 -- and implied by AI12-0113.
24495 ----------------------
24496 -- Check_References --
24497 ----------------------
24499 function Check_References (Nod : Node_Id) return Traverse_Result is
24501 if Nkind (Nod) = N_Function_Call
24502 and then Is_Entity_Name (Name (Nod))
24505 Func : constant Entity_Id := Entity (Name (Nod));
24509 -- An operation of the type must be a primitive
24511 if No (Find_Dispatching_Type (Func)) then
24512 Form := First_Formal (Func);
24513 while Present (Form) loop
24514 if Etype (Form) = Disp_Typ then
24516 ("operation in class-wide condition must be "
24517 & "primitive of &", Nod, Disp_Typ);
24520 Next_Formal (Form);
24523 -- A return object of the type is illegal as well
24525 if Etype (Func) = Disp_Typ
24526 or else Etype (Func) = Class_Wide_Type (Disp_Typ)
24529 ("operation in class-wide condition must be primitive "
24530 & "of &", Nod, Disp_Typ);
24533 -- Otherwise we have a call to an overridden primitive, and we
24534 -- will create a common class-wide clone for the body of
24535 -- original operation and its eventual inherited versions. If
24536 -- the original operation dispatches on result it is never
24537 -- inherited and there is no need for a clone. There is not
24538 -- need for a clone either in GNATprove mode, as cases that
24539 -- would require it are rejected (when an inherited primitive
24540 -- calls an overridden operation in a class-wide contract), and
24541 -- the clone would make proof impossible in some cases.
24543 elsif not Is_Abstract_Subprogram (Spec_Id)
24544 and then No (Class_Wide_Clone (Spec_Id))
24545 and then not Has_Controlling_Result (Spec_Id)
24546 and then not GNATprove_Mode
24548 Build_Class_Wide_Clone_Decl (Spec_Id);
24552 elsif Is_Entity_Name (Nod)
24554 (Etype (Nod) = Disp_Typ
24555 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
24556 and then Ekind_In (Entity (Nod), E_Constant, E_Variable)
24559 ("object in class-wide condition must be formal of type &",
24562 elsif Nkind (Nod) = N_Explicit_Dereference
24563 and then (Etype (Nod) = Disp_Typ
24564 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
24565 and then (not Is_Entity_Name (Prefix (Nod))
24566 or else not Is_Formal (Entity (Prefix (Nod))))
24569 ("operation in class-wide condition must be primitive of &",
24574 end Check_References;
24576 procedure Check_Class_Wide_Condition is
24577 new Traverse_Proc (Check_References);
24581 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
24582 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
24583 -- Save the Ghost mode to restore on exit
24586 Restore_Scope : Boolean := False;
24588 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
24591 -- Do not analyze the pragma multiple times
24593 if Is_Analyzed_Pragma (N) then
24597 -- Set the Ghost mode in effect from the pragma. Due to the delayed
24598 -- analysis of the pragma, the Ghost mode at point of declaration and
24599 -- point of analysis may not necessarily be the same. Use the mode in
24600 -- effect at the point of declaration.
24602 Set_Ghost_Mode (N);
24604 -- Ensure that the subprogram and its formals are visible when analyzing
24605 -- the expression of the pragma.
24607 if not In_Open_Scopes (Spec_Id) then
24608 Restore_Scope := True;
24609 Push_Scope (Spec_Id);
24611 if Is_Generic_Subprogram (Spec_Id) then
24612 Install_Generic_Formals (Spec_Id);
24614 Install_Formals (Spec_Id);
24618 Errors := Serious_Errors_Detected;
24619 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
24621 -- Emit a clarification message when the expression contains at least
24622 -- one undefined reference, possibly due to contract freezing.
24624 if Errors /= Serious_Errors_Detected
24625 and then Present (Freeze_Id)
24626 and then Has_Undefined_Reference (Expr)
24628 Contract_Freeze_Error (Spec_Id, Freeze_Id);
24631 if Class_Present (N) then
24633 -- Verify that a class-wide condition is legal, i.e. the operation is
24634 -- a primitive of a tagged type. Note that a generic subprogram is
24635 -- not a primitive operation.
24637 Disp_Typ := Find_Dispatching_Type (Spec_Id);
24639 if No (Disp_Typ) or else Is_Generic_Subprogram (Spec_Id) then
24640 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
24642 if From_Aspect_Specification (N) then
24644 ("aspect % can only be specified for a primitive operation "
24645 & "of a tagged type", Corresponding_Aspect (N));
24647 -- The pragma is a source construct
24651 ("pragma % can only be specified for a primitive operation "
24652 & "of a tagged type", N);
24655 -- Remaining semantic checks require a full tree traversal
24658 Check_Class_Wide_Condition (Expr);
24663 if Restore_Scope then
24667 -- If analysis of the condition indicates that a class-wide clone
24668 -- has been created, build and analyze its declaration.
24670 if Is_Subprogram (Spec_Id)
24671 and then Present (Class_Wide_Clone (Spec_Id))
24673 Analyze (Unit_Declaration_Node (Class_Wide_Clone (Spec_Id)));
24676 -- Currently it is not possible to inline pre/postconditions on a
24677 -- subprogram subject to pragma Inline_Always.
24679 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
24680 Set_Is_Analyzed_Pragma (N);
24682 Restore_Ghost_Mode (Saved_GM);
24683 end Analyze_Pre_Post_Condition_In_Decl_Part;
24685 ------------------------------------------
24686 -- Analyze_Refined_Depends_In_Decl_Part --
24687 ------------------------------------------
24689 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
24690 procedure Check_Dependency_Clause
24691 (Spec_Id : Entity_Id;
24692 Dep_Clause : Node_Id;
24693 Dep_States : Elist_Id;
24694 Refinements : List_Id;
24695 Matched_Items : in out Elist_Id);
24696 -- Try to match a single dependency clause Dep_Clause against one or
24697 -- more refinement clauses found in list Refinements. Each successful
24698 -- match eliminates at least one refinement clause from Refinements.
24699 -- Spec_Id denotes the entity of the related subprogram. Dep_States
24700 -- denotes the entities of all abstract states which appear in pragma
24701 -- Depends. Matched_Items contains the entities of all successfully
24702 -- matched items found in pragma Depends.
24704 procedure Check_Output_States
24705 (Spec_Id : Entity_Id;
24706 Spec_Inputs : Elist_Id;
24707 Spec_Outputs : Elist_Id;
24708 Body_Inputs : Elist_Id;
24709 Body_Outputs : Elist_Id);
24710 -- Determine whether pragma Depends contains an output state with a
24711 -- visible refinement and if so, ensure that pragma Refined_Depends
24712 -- mentions all its constituents as outputs. Spec_Id is the entity of
24713 -- the related subprograms. Spec_Inputs and Spec_Outputs denote the
24714 -- inputs and outputs of the subprogram spec synthesized from pragma
24715 -- Depends. Body_Inputs and Body_Outputs denote the inputs and outputs
24716 -- of the subprogram body synthesized from pragma Refined_Depends.
24718 function Collect_States (Clauses : List_Id) return Elist_Id;
24719 -- Given a normalized list of dependencies obtained from calling
24720 -- Normalize_Clauses, return a list containing the entities of all
24721 -- states appearing in dependencies. It helps in checking refinements
24722 -- involving a state and a corresponding constituent which is not a
24723 -- direct constituent of the state.
24725 procedure Normalize_Clauses (Clauses : List_Id);
24726 -- Given a list of dependence or refinement clauses Clauses, normalize
24727 -- each clause by creating multiple dependencies with exactly one input
24730 procedure Remove_Extra_Clauses
24731 (Clauses : List_Id;
24732 Matched_Items : Elist_Id);
24733 -- Given a list of refinement clauses Clauses, remove all clauses whose
24734 -- inputs and/or outputs have been previously matched. See the body for
24735 -- all special cases. Matched_Items contains the entities of all matched
24736 -- items found in pragma Depends.
24738 procedure Report_Extra_Clauses
24739 (Spec_Id : Entity_Id;
24740 Clauses : List_Id);
24741 -- Emit an error for each extra clause found in list Clauses. Spec_Id
24742 -- denotes the entity of the related subprogram.
24744 -----------------------------
24745 -- Check_Dependency_Clause --
24746 -----------------------------
24748 procedure Check_Dependency_Clause
24749 (Spec_Id : Entity_Id;
24750 Dep_Clause : Node_Id;
24751 Dep_States : Elist_Id;
24752 Refinements : List_Id;
24753 Matched_Items : in out Elist_Id)
24755 Dep_Input : constant Node_Id := Expression (Dep_Clause);
24756 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
24758 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean;
24759 -- Determine whether dependency item Dep_Item has been matched in a
24760 -- previous clause.
24762 function Is_In_Out_State_Clause return Boolean;
24763 -- Determine whether dependence clause Dep_Clause denotes an abstract
24764 -- state that depends on itself (State => State).
24766 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
24767 -- Determine whether item Item denotes an abstract state with visible
24768 -- null refinement.
24770 procedure Match_Items
24771 (Dep_Item : Node_Id;
24772 Ref_Item : Node_Id;
24773 Matched : out Boolean);
24774 -- Try to match dependence item Dep_Item against refinement item
24775 -- Ref_Item. To match against a possible null refinement (see 2, 9),
24776 -- set Ref_Item to Empty. Flag Matched is set to True when one of
24777 -- the following conformance scenarios is in effect:
24778 -- 1) Both items denote null
24779 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
24780 -- 3) Both items denote attribute 'Result
24781 -- 4) Both items denote the same object
24782 -- 5) Both items denote the same formal parameter
24783 -- 6) Both items denote the same current instance of a type
24784 -- 7) Both items denote the same discriminant
24785 -- 8) Dep_Item is an abstract state with visible null refinement
24786 -- and Ref_Item denotes null.
24787 -- 9) Dep_Item is an abstract state with visible null refinement
24788 -- and Ref_Item is Empty (special case).
24789 -- 10) Dep_Item is an abstract state with full or partial visible
24790 -- non-null refinement and Ref_Item denotes one of its
24792 -- 11) Dep_Item is an abstract state without a full visible
24793 -- refinement and Ref_Item denotes the same state.
24794 -- When scenario 10 is in effect, the entity of the abstract state
24795 -- denoted by Dep_Item is added to list Refined_States.
24797 procedure Record_Item
(Item_Id
: Entity_Id
);
24798 -- Store the entity of an item denoted by Item_Id in Matched_Items
24800 ------------------------
24801 -- Is_Already_Matched --
24802 ------------------------
24804 function Is_Already_Matched
(Dep_Item
: Node_Id
) return Boolean is
24805 Item_Id
: Entity_Id
:= Empty
;
24808 -- When the dependency item denotes attribute 'Result, check for
24809 -- the entity of the related subprogram.
24811 if Is_Attribute_Result
(Dep_Item
) then
24812 Item_Id
:= Spec_Id
;
24814 elsif Is_Entity_Name
(Dep_Item
) then
24815 Item_Id
:= Available_View
(Entity_Of
(Dep_Item
));
24819 Present
(Item_Id
) and then Contains
(Matched_Items
, Item_Id
);
24820 end Is_Already_Matched
;
24822 ----------------------------
24823 -- Is_In_Out_State_Clause --
24824 ----------------------------
24826 function Is_In_Out_State_Clause
return Boolean is
24827 Dep_Input_Id
: Entity_Id
;
24828 Dep_Output_Id
: Entity_Id
;
24831 -- Detect the following clause:
24834 if Is_Entity_Name
(Dep_Input
)
24835 and then Is_Entity_Name
(Dep_Output
)
24837 -- Handle abstract views generated for limited with clauses
24839 Dep_Input_Id
:= Available_View
(Entity_Of
(Dep_Input
));
24840 Dep_Output_Id
:= Available_View
(Entity_Of
(Dep_Output
));
24843 Ekind
(Dep_Input_Id
) = E_Abstract_State
24844 and then Dep_Input_Id
= Dep_Output_Id
;
24848 end Is_In_Out_State_Clause
;
24850 ---------------------------
24851 -- Is_Null_Refined_State --
24852 ---------------------------
24854 function Is_Null_Refined_State
(Item
: Node_Id
) return Boolean is
24855 Item_Id
: Entity_Id
;
24858 if Is_Entity_Name
(Item
) then
24860 -- Handle abstract views generated for limited with clauses
24862 Item_Id
:= Available_View
(Entity_Of
(Item
));
24865 Ekind
(Item_Id
) = E_Abstract_State
24866 and then Has_Null_Visible_Refinement
(Item_Id
);
24870 end Is_Null_Refined_State
;
24876 procedure Match_Items
24877 (Dep_Item
: Node_Id
;
24878 Ref_Item
: Node_Id
;
24879 Matched
: out Boolean)
24881 Dep_Item_Id
: Entity_Id
;
24882 Ref_Item_Id
: Entity_Id
;
24885 -- Assume that the two items do not match
24889 -- A null matches null or Empty (special case)
24891 if Nkind
(Dep_Item
) = N_Null
24892 and then (No
(Ref_Item
) or else Nkind
(Ref_Item
) = N_Null
)
24896 -- Attribute 'Result matches attribute 'Result
24898 elsif Is_Attribute_Result
(Dep_Item
)
24899 and then Is_Attribute_Result
(Ref_Item
)
24901 -- Put the entity of the related function on the list of
24902 -- matched items because attribute 'Result does not carry
24903 -- an entity similar to states and constituents.
24905 Record_Item
(Spec_Id
);
24908 -- Abstract states, current instances of concurrent types,
24909 -- discriminants, formal parameters and objects.
24911 elsif Is_Entity_Name
(Dep_Item
) then
24913 -- Handle abstract views generated for limited with clauses
24915 Dep_Item_Id
:= Available_View
(Entity_Of
(Dep_Item
));
24917 if Ekind
(Dep_Item_Id
) = E_Abstract_State
then
24919 -- An abstract state with visible null refinement matches
24920 -- null or Empty (special case).
24922 if Has_Null_Visible_Refinement
(Dep_Item_Id
)
24923 and then (No
(Ref_Item
) or else Nkind
(Ref_Item
) = N_Null
)
24925 Record_Item
(Dep_Item_Id
);
24928 -- An abstract state with visible non-null refinement
24929 -- matches one of its constituents, or itself for an
24930 -- abstract state with partial visible refinement.
24932 elsif Has_Non_Null_Visible_Refinement
(Dep_Item_Id
) then
24933 if Is_Entity_Name
(Ref_Item
) then
24934 Ref_Item_Id
:= Entity_Of
(Ref_Item
);
24936 if Ekind_In
(Ref_Item_Id
, E_Abstract_State
,
24939 and then Present
(Encapsulating_State
(Ref_Item_Id
))
24940 and then Find_Encapsulating_State
24941 (Dep_States
, Ref_Item_Id
) = Dep_Item_Id
24943 Record_Item
(Dep_Item_Id
);
24946 elsif not Has_Visible_Refinement
(Dep_Item_Id
)
24947 and then Ref_Item_Id
= Dep_Item_Id
24949 Record_Item
(Dep_Item_Id
);
24954 -- An abstract state without a visible refinement matches
24957 elsif Is_Entity_Name
(Ref_Item
)
24958 and then Entity_Of
(Ref_Item
) = Dep_Item_Id
24960 Record_Item
(Dep_Item_Id
);
24964 -- A current instance of a concurrent type, discriminant,
24965 -- formal parameter or an object matches itself.
24967 elsif Is_Entity_Name
(Ref_Item
)
24968 and then Entity_Of
(Ref_Item
) = Dep_Item_Id
24970 Record_Item
(Dep_Item_Id
);
24980 procedure Record_Item
(Item_Id
: Entity_Id
) is
24982 if No
(Matched_Items
) then
24983 Matched_Items
:= New_Elmt_List
;
24986 Append_Unique_Elmt
(Item_Id
, Matched_Items
);
24991 Clause_Matched
: Boolean := False;
24992 Dummy
: Boolean := False;
24993 Inputs_Match
: Boolean;
24994 Next_Ref_Clause
: Node_Id
;
24995 Outputs_Match
: Boolean;
24996 Ref_Clause
: Node_Id
;
24997 Ref_Input
: Node_Id
;
24998 Ref_Output
: Node_Id
;
25000 -- Start of processing for Check_Dependency_Clause
25003 -- Do not perform this check in an instance because it was already
25004 -- performed successfully in the generic template.
25006 if Is_Generic_Instance
(Spec_Id
) then
25010 -- Examine all refinement clauses and compare them against the
25011 -- dependence clause.
25013 Ref_Clause
:= First
(Refinements
);
25014 while Present
(Ref_Clause
) loop
25015 Next_Ref_Clause
:= Next
(Ref_Clause
);
25017 -- Obtain the attributes of the current refinement clause
25019 Ref_Input
:= Expression
(Ref_Clause
);
25020 Ref_Output
:= First
(Choices
(Ref_Clause
));
25022 -- The current refinement clause matches the dependence clause
25023 -- when both outputs match and both inputs match. See routine
25024 -- Match_Items for all possible conformance scenarios.
25026 -- Depends Dep_Output => Dep_Input
25030 -- Refined_Depends Ref_Output => Ref_Input
25033 (Dep_Item
=> Dep_Input
,
25034 Ref_Item
=> Ref_Input
,
25035 Matched
=> Inputs_Match
);
25038 (Dep_Item
=> Dep_Output
,
25039 Ref_Item
=> Ref_Output
,
25040 Matched
=> Outputs_Match
);
25042 -- An In_Out state clause may be matched against a refinement with
25043 -- a null input or null output as long as the non-null side of the
25044 -- relation contains a valid constituent of the In_Out_State.
25046 if Is_In_Out_State_Clause
then
25048 -- Depends => (State => State)
25049 -- Refined_Depends => (null => Constit) -- OK
25052 and then not Outputs_Match
25053 and then Nkind
(Ref_Output
) = N_Null
25055 Outputs_Match
:= True;
25058 -- Depends => (State => State)
25059 -- Refined_Depends => (Constit => null) -- OK
25061 if not Inputs_Match
25062 and then Outputs_Match
25063 and then Nkind
(Ref_Input
) = N_Null
25065 Inputs_Match
:= True;
25069 -- The current refinement clause is legally constructed following
25070 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
25071 -- the pool of candidates. The seach continues because a single
25072 -- dependence clause may have multiple matching refinements.
25074 if Inputs_Match
and Outputs_Match
then
25075 Clause_Matched
:= True;
25076 Remove
(Ref_Clause
);
25079 Ref_Clause
:= Next_Ref_Clause
;
25082 -- Depending on the order or composition of refinement clauses, an
25083 -- In_Out state clause may not be directly refinable.
25085 -- Refined_State => (State => (Constit_1, Constit_2))
25086 -- Depends => ((Output, State) => (Input, State))
25087 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
25089 -- Matching normalized clause (State => State) fails because there is
25090 -- no direct refinement capable of satisfying this relation. Another
25091 -- similar case arises when clauses (Constit_1 => Input) and (Output
25092 -- => Constit_2) are matched first, leaving no candidates for clause
25093 -- (State => State). Both scenarios are legal as long as one of the
25094 -- previous clauses mentioned a valid constituent of State.
25096 if not Clause_Matched
25097 and then Is_In_Out_State_Clause
25098 and then Is_Already_Matched
(Dep_Input
)
25100 Clause_Matched
:= True;
25103 -- A clause where the input is an abstract state with visible null
25104 -- refinement or a 'Result attribute is implicitly matched when the
25105 -- output has already been matched in a previous clause.
25107 -- Refined_State => (State => null)
25108 -- Depends => (Output => State) -- implicitly OK
25109 -- Refined_Depends => (Output => ...)
25110 -- Depends => (...'Result => State) -- implicitly OK
25111 -- Refined_Depends => (...'Result => ...)
25113 if not Clause_Matched
25114 and then Is_Null_Refined_State
(Dep_Input
)
25115 and then Is_Already_Matched
(Dep_Output
)
25117 Clause_Matched
:= True;
25120 -- A clause where the output is an abstract state with visible null
25121 -- refinement is implicitly matched when the input has already been
25122 -- matched in a previous clause.
25124 -- Refined_State => (State => null)
25125 -- Depends => (State => Input) -- implicitly OK
25126 -- Refined_Depends => (... => Input)
25128 if not Clause_Matched
25129 and then Is_Null_Refined_State
(Dep_Output
)
25130 and then Is_Already_Matched
(Dep_Input
)
25132 Clause_Matched
:= True;
25135 -- At this point either all refinement clauses have been examined or
25136 -- pragma Refined_Depends contains a solitary null. Only an abstract
25137 -- state with null refinement can possibly match these cases.
25139 -- Refined_State => (State => null)
25140 -- Depends => (State => null)
25141 -- Refined_Depends => null -- OK
25143 if not Clause_Matched
then
25145 (Dep_Item
=> Dep_Input
,
25147 Matched
=> Inputs_Match
);
25150 (Dep_Item
=> Dep_Output
,
25152 Matched
=> Outputs_Match
);
25154 Clause_Matched
:= Inputs_Match
and Outputs_Match
;
25157 -- If the contents of Refined_Depends are legal, then the current
25158 -- dependence clause should be satisfied either by an explicit match
25159 -- or by one of the special cases.
25161 if not Clause_Matched
then
25163 (Fix_Msg
(Spec_Id
, "dependence clause of subprogram & has no "
25164 & "matching refinement in body"), Dep_Clause
, Spec_Id
);
25166 end Check_Dependency_Clause
;
25168 -------------------------
25169 -- Check_Output_States --
25170 -------------------------
25172 procedure Check_Output_States
25173 (Spec_Id
: Entity_Id
;
25174 Spec_Inputs
: Elist_Id
;
25175 Spec_Outputs
: Elist_Id
;
25176 Body_Inputs
: Elist_Id
;
25177 Body_Outputs
: Elist_Id
)
25179 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
25180 -- Determine whether all constituents of state State_Id with full
25181 -- visible refinement are used as outputs in pragma Refined_Depends.
25182 -- Emit an error if this is not the case (SPARK RM 7.2.4(5)).
25184 -----------------------------
25185 -- Check_Constituent_Usage --
25186 -----------------------------
25188 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
25189 Constits
: constant Elist_Id
:=
25190 Partial_Refinement_Constituents
(State_Id
);
25191 Constit_Elmt
: Elmt_Id
;
25192 Constit_Id
: Entity_Id
;
25193 Only_Partial
: constant Boolean :=
25194 not Has_Visible_Refinement
(State_Id
);
25195 Posted
: Boolean := False;
25198 if Present
(Constits
) then
25199 Constit_Elmt
:= First_Elmt
(Constits
);
25200 while Present
(Constit_Elmt
) loop
25201 Constit_Id
:= Node
(Constit_Elmt
);
25203 -- Issue an error when a constituent of State_Id is used,
25204 -- and State_Id has only partial visible refinement
25205 -- (SPARK RM 7.2.4(3d)).
25207 if Only_Partial
then
25208 if (Present
(Body_Inputs
)
25209 and then Appears_In
(Body_Inputs
, Constit_Id
))
25211 (Present
(Body_Outputs
)
25212 and then Appears_In
(Body_Outputs
, Constit_Id
))
25214 Error_Msg_Name_1
:= Chars
(State_Id
);
25216 ("constituent & of state % cannot be used in "
25217 & "dependence refinement", N
, Constit_Id
);
25218 Error_Msg_Name_1
:= Chars
(State_Id
);
25219 SPARK_Msg_N
("\use state % instead", N
);
25222 -- The constituent acts as an input (SPARK RM 7.2.5(3))
25224 elsif Present
(Body_Inputs
)
25225 and then Appears_In
(Body_Inputs
, Constit_Id
)
25227 Error_Msg_Name_1
:= Chars
(State_Id
);
25229 ("constituent & of state % must act as output in "
25230 & "dependence refinement", N
, Constit_Id
);
25232 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
25234 elsif No
(Body_Outputs
)
25235 or else not Appears_In
(Body_Outputs
, Constit_Id
)
25240 ("output state & must be replaced by all its "
25241 & "constituents in dependence refinement",
25246 ("\constituent & is missing in output list",
25250 Next_Elmt
(Constit_Elmt
);
25253 end Check_Constituent_Usage
;
25258 Item_Elmt
: Elmt_Id
;
25259 Item_Id
: Entity_Id
;
25261 -- Start of processing for Check_Output_States
25264 -- Do not perform this check in an instance because it was already
25265 -- performed successfully in the generic template.
25267 if Is_Generic_Instance
(Spec_Id
) then
25270 -- Inspect the outputs of pragma Depends looking for a state with a
25271 -- visible refinement.
25273 elsif Present
(Spec_Outputs
) then
25274 Item_Elmt
:= First_Elmt
(Spec_Outputs
);
25275 while Present
(Item_Elmt
) loop
25276 Item
:= Node
(Item_Elmt
);
25278 -- Deal with the mixed nature of the input and output lists
25280 if Nkind
(Item
) = N_Defining_Identifier
then
25283 Item_Id
:= Available_View
(Entity_Of
(Item
));
25286 if Ekind
(Item_Id
) = E_Abstract_State
then
25288 -- The state acts as an input-output, skip it
25290 if Present
(Spec_Inputs
)
25291 and then Appears_In
(Spec_Inputs
, Item_Id
)
25295 -- Ensure that all of the constituents are utilized as
25296 -- outputs in pragma Refined_Depends.
25298 elsif Has_Non_Null_Visible_Refinement
(Item_Id
) then
25299 Check_Constituent_Usage
(Item_Id
);
25303 Next_Elmt
(Item_Elmt
);
25306 end Check_Output_States
;
25308 --------------------
25309 -- Collect_States --
25310 --------------------
25312 function Collect_States
(Clauses
: List_Id
) return Elist_Id
is
25313 procedure Collect_State
25315 States
: in out Elist_Id
);
25316 -- Add the entity of Item to list States when it denotes to a state
25318 -------------------
25319 -- Collect_State --
25320 -------------------
25322 procedure Collect_State
25324 States
: in out Elist_Id
)
25329 if Is_Entity_Name
(Item
) then
25330 Id
:= Entity_Of
(Item
);
25332 if Ekind
(Id
) = E_Abstract_State
then
25333 if No
(States
) then
25334 States
:= New_Elmt_List
;
25337 Append_Unique_Elmt
(Id
, States
);
25347 States
: Elist_Id
:= No_Elist
;
25349 -- Start of processing for Collect_States
25352 Clause
:= First
(Clauses
);
25353 while Present
(Clause
) loop
25354 Input
:= Expression
(Clause
);
25355 Output
:= First
(Choices
(Clause
));
25357 Collect_State
(Input
, States
);
25358 Collect_State
(Output
, States
);
25364 end Collect_States
;
25366 -----------------------
25367 -- Normalize_Clauses --
25368 -----------------------
25370 procedure Normalize_Clauses
(Clauses
: List_Id
) is
25371 procedure Normalize_Inputs
(Clause
: Node_Id
);
25372 -- Normalize clause Clause by creating multiple clauses for each
25373 -- input item of Clause. It is assumed that Clause has exactly one
25374 -- output. The transformation is as follows:
25376 -- Output => (Input_1, Input_2) -- original
25378 -- Output => Input_1 -- normalizations
25379 -- Output => Input_2
25381 procedure Normalize_Outputs
(Clause
: Node_Id
);
25382 -- Normalize clause Clause by creating multiple clause for each
25383 -- output item of Clause. The transformation is as follows:
25385 -- (Output_1, Output_2) => Input -- original
25387 -- Output_1 => Input -- normalization
25388 -- Output_2 => Input
25390 ----------------------
25391 -- Normalize_Inputs --
25392 ----------------------
25394 procedure Normalize_Inputs
(Clause
: Node_Id
) is
25395 Inputs
: constant Node_Id
:= Expression
(Clause
);
25396 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
25397 Output
: constant List_Id
:= Choices
(Clause
);
25398 Last_Input
: Node_Id
;
25400 New_Clause
: Node_Id
;
25401 Next_Input
: Node_Id
;
25404 -- Normalization is performed only when the original clause has
25405 -- more than one input. Multiple inputs appear as an aggregate.
25407 if Nkind
(Inputs
) = N_Aggregate
then
25408 Last_Input
:= Last
(Expressions
(Inputs
));
25410 -- Create a new clause for each input
25412 Input
:= First
(Expressions
(Inputs
));
25413 while Present
(Input
) loop
25414 Next_Input
:= Next
(Input
);
25416 -- Unhook the current input from the original input list
25417 -- because it will be relocated to a new clause.
25421 -- Special processing for the last input. At this point the
25422 -- original aggregate has been stripped down to one element.
25423 -- Replace the aggregate by the element itself.
25425 if Input
= Last_Input
then
25426 Rewrite
(Inputs
, Input
);
25428 -- Generate a clause of the form:
25433 Make_Component_Association
(Loc
,
25434 Choices
=> New_Copy_List_Tree
(Output
),
25435 Expression
=> Input
);
25437 -- The new clause contains replicated content that has
25438 -- already been analyzed, mark the clause as analyzed.
25440 Set_Analyzed
(New_Clause
);
25441 Insert_After
(Clause
, New_Clause
);
25444 Input
:= Next_Input
;
25447 end Normalize_Inputs
;
25449 -----------------------
25450 -- Normalize_Outputs --
25451 -----------------------
25453 procedure Normalize_Outputs
(Clause
: Node_Id
) is
25454 Inputs
: constant Node_Id
:= Expression
(Clause
);
25455 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
25456 Outputs
: constant Node_Id
:= First
(Choices
(Clause
));
25457 Last_Output
: Node_Id
;
25458 New_Clause
: Node_Id
;
25459 Next_Output
: Node_Id
;
25463 -- Multiple outputs appear as an aggregate. Nothing to do when
25464 -- the clause has exactly one output.
25466 if Nkind
(Outputs
) = N_Aggregate
then
25467 Last_Output
:= Last
(Expressions
(Outputs
));
25469 -- Create a clause for each output. Note that each time a new
25470 -- clause is created, the original output list slowly shrinks
25471 -- until there is one item left.
25473 Output
:= First
(Expressions
(Outputs
));
25474 while Present
(Output
) loop
25475 Next_Output
:= Next
(Output
);
25477 -- Unhook the output from the original output list as it
25478 -- will be relocated to a new clause.
25482 -- Special processing for the last output. At this point
25483 -- the original aggregate has been stripped down to one
25484 -- element. Replace the aggregate by the element itself.
25486 if Output
= Last_Output
then
25487 Rewrite
(Outputs
, Output
);
25490 -- Generate a clause of the form:
25491 -- (Output => Inputs)
25494 Make_Component_Association
(Loc
,
25495 Choices
=> New_List
(Output
),
25496 Expression
=> New_Copy_Tree
(Inputs
));
25498 -- The new clause contains replicated content that has
25499 -- already been analyzed. There is not need to reanalyze
25502 Set_Analyzed
(New_Clause
);
25503 Insert_After
(Clause
, New_Clause
);
25506 Output
:= Next_Output
;
25509 end Normalize_Outputs
;
25515 -- Start of processing for Normalize_Clauses
25518 Clause
:= First
(Clauses
);
25519 while Present
(Clause
) loop
25520 Normalize_Outputs
(Clause
);
25524 Clause
:= First
(Clauses
);
25525 while Present
(Clause
) loop
25526 Normalize_Inputs
(Clause
);
25529 end Normalize_Clauses
;
25531 --------------------------
25532 -- Remove_Extra_Clauses --
25533 --------------------------
25535 procedure Remove_Extra_Clauses
25536 (Clauses
: List_Id
;
25537 Matched_Items
: Elist_Id
)
25541 Input_Id
: Entity_Id
;
25542 Next_Clause
: Node_Id
;
25544 State_Id
: Entity_Id
;
25547 Clause
:= First
(Clauses
);
25548 while Present
(Clause
) loop
25549 Next_Clause
:= Next
(Clause
);
25551 Input
:= Expression
(Clause
);
25552 Output
:= First
(Choices
(Clause
));
25554 -- Recognize a clause of the form
25558 -- where Input is a constituent of a state which was already
25559 -- successfully matched. This clause must be removed because it
25560 -- simply indicates that some of the constituents of the state
25563 -- Refined_State => (State => (Constit_1, Constit_2))
25564 -- Depends => (Output => State)
25565 -- Refined_Depends => ((Output => Constit_1), -- State matched
25566 -- (null => Constit_2)) -- OK
25568 if Nkind
(Output
) = N_Null
and then Is_Entity_Name
(Input
) then
25570 -- Handle abstract views generated for limited with clauses
25572 Input_Id
:= Available_View
(Entity_Of
(Input
));
25574 -- The input must be a constituent of a state
25576 if Ekind_In
(Input_Id
, E_Abstract_State
,
25579 and then Present
(Encapsulating_State
(Input_Id
))
25581 State_Id
:= Encapsulating_State
(Input_Id
);
25583 -- The state must have a non-null visible refinement and be
25584 -- matched in a previous clause.
25586 if Has_Non_Null_Visible_Refinement
(State_Id
)
25587 and then Contains
(Matched_Items
, State_Id
)
25593 -- Recognize a clause of the form
25597 -- where Output is an arbitrary item. This clause must be removed
25598 -- because a null input legitimately matches anything.
25600 elsif Nkind
(Input
) = N_Null
then
25604 Clause
:= Next_Clause
;
25606 end Remove_Extra_Clauses
;
25608 --------------------------
25609 -- Report_Extra_Clauses --
25610 --------------------------
25612 procedure Report_Extra_Clauses
25613 (Spec_Id
: Entity_Id
;
25619 -- Do not perform this check in an instance because it was already
25620 -- performed successfully in the generic template.
25622 if Is_Generic_Instance
(Spec_Id
) then
25625 elsif Present
(Clauses
) then
25626 Clause
:= First
(Clauses
);
25627 while Present
(Clause
) loop
25629 ("unmatched or extra clause in dependence refinement",
25635 end Report_Extra_Clauses
;
25639 Body_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
25640 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Decl
);
25641 Errors
: constant Nat
:= Serious_Errors_Detected
;
25648 Body_Inputs
: Elist_Id
:= No_Elist
;
25649 Body_Outputs
: Elist_Id
:= No_Elist
;
25650 -- The inputs and outputs of the subprogram body synthesized from pragma
25651 -- Refined_Depends.
25653 Dependencies
: List_Id
:= No_List
;
25655 -- The corresponding Depends pragma along with its clauses
25657 Matched_Items
: Elist_Id
:= No_Elist
;
25658 -- A list containing the entities of all successfully matched items
25659 -- found in pragma Depends.
25661 Refinements
: List_Id
:= No_List
;
25662 -- The clauses of pragma Refined_Depends
25664 Spec_Id
: Entity_Id
;
25665 -- The entity of the subprogram subject to pragma Refined_Depends
25667 Spec_Inputs
: Elist_Id
:= No_Elist
;
25668 Spec_Outputs
: Elist_Id
:= No_Elist
;
25669 -- The inputs and outputs of the subprogram spec synthesized from pragma
25672 States
: Elist_Id
:= No_Elist
;
25673 -- A list containing the entities of all states whose constituents
25674 -- appear in pragma Depends.
25676 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
25679 -- Do not analyze the pragma multiple times
25681 if Is_Analyzed_Pragma
(N
) then
25685 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
25687 -- Use the anonymous object as the proper spec when Refined_Depends
25688 -- applies to the body of a single task type. The object carries the
25689 -- proper Chars as well as all non-refined versions of pragmas.
25691 if Is_Single_Concurrent_Type
(Spec_Id
) then
25692 Spec_Id
:= Anonymous_Object
(Spec_Id
);
25695 Depends
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
25697 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
25698 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
25700 if No
(Depends
) then
25702 (Fix_Msg
(Spec_Id
, "useless refinement, declaration of subprogram "
25703 & "& lacks aspect or pragma Depends"), N
, Spec_Id
);
25707 Deps
:= Expression
(Get_Argument
(Depends
, Spec_Id
));
25709 -- A null dependency relation renders the refinement useless because it
25710 -- cannot possibly mention abstract states with visible refinement. Note
25711 -- that the inverse is not true as states may be refined to null
25712 -- (SPARK RM 7.2.5(2)).
25714 if Nkind
(Deps
) = N_Null
then
25716 (Fix_Msg
(Spec_Id
, "useless refinement, subprogram & does not "
25717 & "depend on abstract state with visible refinement"), N
, Spec_Id
);
25721 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
25722 -- This ensures that the categorization of all refined dependency items
25723 -- is consistent with their role.
25725 Analyze_Depends_In_Decl_Part
(N
);
25727 -- Do not match dependencies against refinements if Refined_Depends is
25728 -- illegal to avoid emitting misleading error.
25730 if Serious_Errors_Detected
= Errors
then
25732 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
25733 -- the inputs and outputs of the subprogram spec and body to verify
25734 -- the use of states with visible refinement and their constituents.
25736 if No
(Get_Pragma
(Spec_Id
, Pragma_Global
))
25737 or else No
(Get_Pragma
(Body_Id
, Pragma_Refined_Global
))
25739 Collect_Subprogram_Inputs_Outputs
25740 (Subp_Id
=> Spec_Id
,
25741 Synthesize
=> True,
25742 Subp_Inputs
=> Spec_Inputs
,
25743 Subp_Outputs
=> Spec_Outputs
,
25744 Global_Seen
=> Dummy
);
25746 Collect_Subprogram_Inputs_Outputs
25747 (Subp_Id
=> Body_Id
,
25748 Synthesize
=> True,
25749 Subp_Inputs
=> Body_Inputs
,
25750 Subp_Outputs
=> Body_Outputs
,
25751 Global_Seen
=> Dummy
);
25753 -- For an output state with a visible refinement, ensure that all
25754 -- constituents appear as outputs in the dependency refinement.
25756 Check_Output_States
25757 (Spec_Id
=> Spec_Id
,
25758 Spec_Inputs
=> Spec_Inputs
,
25759 Spec_Outputs
=> Spec_Outputs
,
25760 Body_Inputs
=> Body_Inputs
,
25761 Body_Outputs
=> Body_Outputs
);
25764 -- Matching is disabled in ASIS because clauses are not normalized as
25765 -- this is a tree altering activity similar to expansion.
25771 -- Multiple dependency clauses appear as component associations of an
25772 -- aggregate. Note that the clauses are copied because the algorithm
25773 -- modifies them and this should not be visible in Depends.
25775 pragma Assert
(Nkind
(Deps
) = N_Aggregate
);
25776 Dependencies
:= New_Copy_List_Tree
(Component_Associations
(Deps
));
25777 Normalize_Clauses
(Dependencies
);
25779 -- Gather all states which appear in Depends
25781 States
:= Collect_States
(Dependencies
);
25783 Refs
:= Expression
(Get_Argument
(N
, Spec_Id
));
25785 if Nkind
(Refs
) = N_Null
then
25786 Refinements
:= No_List
;
25788 -- Multiple dependency clauses appear as component associations of an
25789 -- aggregate. Note that the clauses are copied because the algorithm
25790 -- modifies them and this should not be visible in Refined_Depends.
25792 else pragma Assert
(Nkind
(Refs
) = N_Aggregate
);
25793 Refinements
:= New_Copy_List_Tree
(Component_Associations
(Refs
));
25794 Normalize_Clauses
(Refinements
);
25797 -- At this point the clauses of pragmas Depends and Refined_Depends
25798 -- have been normalized into simple dependencies between one output
25799 -- and one input. Examine all clauses of pragma Depends looking for
25800 -- matching clauses in pragma Refined_Depends.
25802 Clause
:= First
(Dependencies
);
25803 while Present
(Clause
) loop
25804 Check_Dependency_Clause
25805 (Spec_Id
=> Spec_Id
,
25806 Dep_Clause
=> Clause
,
25807 Dep_States
=> States
,
25808 Refinements
=> Refinements
,
25809 Matched_Items
=> Matched_Items
);
25814 -- Pragma Refined_Depends may contain multiple clarification clauses
25815 -- which indicate that certain constituents do not influence the data
25816 -- flow in any way. Such clauses must be removed as long as the state
25817 -- has been matched, otherwise they will be incorrectly flagged as
25820 -- Refined_State => (State => (Constit_1, Constit_2))
25821 -- Depends => (Output => State)
25822 -- Refined_Depends => ((Output => Constit_1), -- State matched
25823 -- (null => Constit_2)) -- must be removed
25825 Remove_Extra_Clauses
(Refinements
, Matched_Items
);
25827 if Serious_Errors_Detected
= Errors
then
25828 Report_Extra_Clauses
(Spec_Id
, Refinements
);
25833 Set_Is_Analyzed_Pragma
(N
);
25834 end Analyze_Refined_Depends_In_Decl_Part
;
25836 -----------------------------------------
25837 -- Analyze_Refined_Global_In_Decl_Part --
25838 -----------------------------------------
25840 procedure Analyze_Refined_Global_In_Decl_Part
(N
: Node_Id
) is
25842 -- The corresponding Global pragma
25844 Has_In_State
: Boolean := False;
25845 Has_In_Out_State
: Boolean := False;
25846 Has_Out_State
: Boolean := False;
25847 Has_Proof_In_State
: Boolean := False;
25848 -- These flags are set when the corresponding Global pragma has a state
25849 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
25852 Has_Null_State
: Boolean := False;
25853 -- This flag is set when the corresponding Global pragma has at least
25854 -- one state with a null refinement.
25856 In_Constits
: Elist_Id
:= No_Elist
;
25857 In_Out_Constits
: Elist_Id
:= No_Elist
;
25858 Out_Constits
: Elist_Id
:= No_Elist
;
25859 Proof_In_Constits
: Elist_Id
:= No_Elist
;
25860 -- These lists contain the entities of all Input, In_Out, Output and
25861 -- Proof_In constituents that appear in Refined_Global and participate
25862 -- in state refinement.
25864 In_Items
: Elist_Id
:= No_Elist
;
25865 In_Out_Items
: Elist_Id
:= No_Elist
;
25866 Out_Items
: Elist_Id
:= No_Elist
;
25867 Proof_In_Items
: Elist_Id
:= No_Elist
;
25868 -- These lists contain the entities of all Input, In_Out, Output and
25869 -- Proof_In items defined in the corresponding Global pragma.
25871 Repeat_Items
: Elist_Id
:= No_Elist
;
25872 -- A list of all global items without full visible refinement found
25873 -- in pragma Global. These states should be repeated in the global
25874 -- refinement (SPARK RM 7.2.4(3c)) unless they have a partial visible
25875 -- refinement, in which case they may be repeated (SPARK RM 7.2.4(3d)).
25877 Spec_Id
: Entity_Id
;
25878 -- The entity of the subprogram subject to pragma Refined_Global
25880 States
: Elist_Id
:= No_Elist
;
25881 -- A list of all states with full or partial visible refinement found in
25884 procedure Check_In_Out_States
;
25885 -- Determine whether the corresponding Global pragma mentions In_Out
25886 -- states with visible refinement and if so, ensure that one of the
25887 -- following completions apply to the constituents of the state:
25888 -- 1) there is at least one constituent of mode In_Out
25889 -- 2) there is at least one Input and one Output constituent
25890 -- 3) not all constituents are present and one of them is of mode
25892 -- This routine may remove elements from In_Constits, In_Out_Constits,
25893 -- Out_Constits and Proof_In_Constits.
25895 procedure Check_Input_States
;
25896 -- Determine whether the corresponding Global pragma mentions Input
25897 -- states with visible refinement and if so, ensure that at least one of
25898 -- its constituents appears as an Input item in Refined_Global.
25899 -- This routine may remove elements from In_Constits, In_Out_Constits,
25900 -- Out_Constits and Proof_In_Constits.
25902 procedure Check_Output_States
;
25903 -- Determine whether the corresponding Global pragma mentions Output
25904 -- states with visible refinement and if so, ensure that all of its
25905 -- constituents appear as Output items in Refined_Global.
25906 -- This routine may remove elements from In_Constits, In_Out_Constits,
25907 -- Out_Constits and Proof_In_Constits.
25909 procedure Check_Proof_In_States
;
25910 -- Determine whether the corresponding Global pragma mentions Proof_In
25911 -- states with visible refinement and if so, ensure that at least one of
25912 -- its constituents appears as a Proof_In item in Refined_Global.
25913 -- This routine may remove elements from In_Constits, In_Out_Constits,
25914 -- Out_Constits and Proof_In_Constits.
25916 procedure Check_Refined_Global_List
25918 Global_Mode
: Name_Id
:= Name_Input
);
25919 -- Verify the legality of a single global list declaration. Global_Mode
25920 -- denotes the current mode in effect.
25922 procedure Collect_Global_Items
25924 Mode
: Name_Id
:= Name_Input
);
25925 -- Gather all Input, In_Out, Output and Proof_In items from node List
25926 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
25927 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
25928 -- and Has_Proof_In_State are set when there is at least one abstract
25929 -- state with full or partial visible refinement available in the
25930 -- corresponding mode. Flag Has_Null_State is set when at least state
25931 -- has a null refinement. Mode denotes the current global mode in
25934 function Present_Then_Remove
25936 Item
: Entity_Id
) return Boolean;
25937 -- Search List for a particular entity Item. If Item has been found,
25938 -- remove it from List. This routine is used to strip lists In_Constits,
25939 -- In_Out_Constits and Out_Constits of valid constituents.
25941 procedure Present_Then_Remove
(List
: Elist_Id
; Item
: Entity_Id
);
25942 -- Same as function Present_Then_Remove, but do not report the presence
25943 -- of Item in List.
25945 procedure Report_Extra_Constituents
;
25946 -- Emit an error for each constituent found in lists In_Constits,
25947 -- In_Out_Constits and Out_Constits.
25949 procedure Report_Missing_Items
;
25950 -- Emit an error for each global item not repeated found in list
25953 -------------------------
25954 -- Check_In_Out_States --
25955 -------------------------
25957 procedure Check_In_Out_States
is
25958 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
25959 -- Determine whether one of the following coverage scenarios is in
25961 -- 1) there is at least one constituent of mode In_Out or Output
25962 -- 2) there is at least one pair of constituents with modes Input
25963 -- and Output, or Proof_In and Output.
25964 -- 3) there is at least one constituent of mode Output and not all
25965 -- constituents are present.
25966 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
25968 -----------------------------
25969 -- Check_Constituent_Usage --
25970 -----------------------------
25972 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
25973 Constits
: constant Elist_Id
:=
25974 Partial_Refinement_Constituents
(State_Id
);
25975 Constit_Elmt
: Elmt_Id
;
25976 Constit_Id
: Entity_Id
;
25977 Has_Missing
: Boolean := False;
25978 In_Out_Seen
: Boolean := False;
25979 Input_Seen
: Boolean := False;
25980 Output_Seen
: Boolean := False;
25981 Proof_In_Seen
: Boolean := False;
25984 -- Process all the constituents of the state and note their modes
25985 -- within the global refinement.
25987 if Present
(Constits
) then
25988 Constit_Elmt
:= First_Elmt
(Constits
);
25989 while Present
(Constit_Elmt
) loop
25990 Constit_Id
:= Node
(Constit_Elmt
);
25992 if Present_Then_Remove
(In_Constits
, Constit_Id
) then
25993 Input_Seen
:= True;
25995 elsif Present_Then_Remove
(In_Out_Constits
, Constit_Id
) then
25996 In_Out_Seen
:= True;
25998 elsif Present_Then_Remove
(Out_Constits
, Constit_Id
) then
25999 Output_Seen
:= True;
26001 elsif Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
26003 Proof_In_Seen
:= True;
26006 Has_Missing
:= True;
26009 Next_Elmt
(Constit_Elmt
);
26013 -- An In_Out constituent is a valid completion
26015 if In_Out_Seen
then
26018 -- A pair of one Input/Proof_In and one Output constituent is a
26019 -- valid completion.
26021 elsif (Input_Seen
or Proof_In_Seen
) and Output_Seen
then
26024 elsif Output_Seen
then
26026 -- A single Output constituent is a valid completion only when
26027 -- some of the other constituents are missing.
26029 if Has_Missing
then
26032 -- Otherwise all constituents are of mode Output
26036 ("global refinement of state & must include at least one "
26037 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
26041 -- The state lacks a completion. When full refinement is visible,
26042 -- always emit an error (SPARK RM 7.2.4(3a)). When only partial
26043 -- refinement is visible, emit an error if the abstract state
26044 -- itself is not utilized (SPARK RM 7.2.4(3d)). In the case where
26045 -- both are utilized, Check_State_And_Constituent_Use. will issue
26048 elsif not Input_Seen
26049 and then not In_Out_Seen
26050 and then not Output_Seen
26051 and then not Proof_In_Seen
26053 if Has_Visible_Refinement
(State_Id
)
26054 or else Contains
(Repeat_Items
, State_Id
)
26057 ("missing global refinement of state &", N
, State_Id
);
26060 -- Otherwise the state has a malformed completion where at least
26061 -- one of the constituents has a different mode.
26065 ("global refinement of state & redefines the mode of its "
26066 & "constituents", N
, State_Id
);
26068 end Check_Constituent_Usage
;
26072 Item_Elmt
: Elmt_Id
;
26073 Item_Id
: Entity_Id
;
26075 -- Start of processing for Check_In_Out_States
26078 -- Do not perform this check in an instance because it was already
26079 -- performed successfully in the generic template.
26081 if Is_Generic_Instance
(Spec_Id
) then
26084 -- Inspect the In_Out items of the corresponding Global pragma
26085 -- looking for a state with a visible refinement.
26087 elsif Has_In_Out_State
and then Present
(In_Out_Items
) then
26088 Item_Elmt
:= First_Elmt
(In_Out_Items
);
26089 while Present
(Item_Elmt
) loop
26090 Item_Id
:= Node
(Item_Elmt
);
26092 -- Ensure that one of the three coverage variants is satisfied
26094 if Ekind
(Item_Id
) = E_Abstract_State
26095 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
26097 Check_Constituent_Usage
(Item_Id
);
26100 Next_Elmt
(Item_Elmt
);
26103 end Check_In_Out_States
;
26105 ------------------------
26106 -- Check_Input_States --
26107 ------------------------
26109 procedure Check_Input_States
is
26110 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
26111 -- Determine whether at least one constituent of state State_Id with
26112 -- full or partial visible refinement is used and has mode Input.
26113 -- Ensure that the remaining constituents do not have In_Out or
26114 -- Output modes. Emit an error if this is not the case
26115 -- (SPARK RM 7.2.4(5)).
26117 -----------------------------
26118 -- Check_Constituent_Usage --
26119 -----------------------------
26121 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
26122 Constits
: constant Elist_Id
:=
26123 Partial_Refinement_Constituents
(State_Id
);
26124 Constit_Elmt
: Elmt_Id
;
26125 Constit_Id
: Entity_Id
;
26126 In_Seen
: Boolean := False;
26129 if Present
(Constits
) then
26130 Constit_Elmt
:= First_Elmt
(Constits
);
26131 while Present
(Constit_Elmt
) loop
26132 Constit_Id
:= Node
(Constit_Elmt
);
26134 -- At least one of the constituents appears as an Input
26136 if Present_Then_Remove
(In_Constits
, Constit_Id
) then
26139 -- A Proof_In constituent can refine an Input state as long
26140 -- as there is at least one Input constituent present.
26142 elsif Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
26146 -- The constituent appears in the global refinement, but has
26147 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
26149 elsif Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
26150 or else Present_Then_Remove
(Out_Constits
, Constit_Id
)
26152 Error_Msg_Name_1
:= Chars
(State_Id
);
26154 ("constituent & of state % must have mode `Input` in "
26155 & "global refinement", N
, Constit_Id
);
26158 Next_Elmt
(Constit_Elmt
);
26162 -- Not one of the constituents appeared as Input. Always emit an
26163 -- error when the full refinement is visible (SPARK RM 7.2.4(3a)).
26164 -- When only partial refinement is visible, emit an error if the
26165 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
26166 -- the case where both are utilized, an error will be issued in
26167 -- Check_State_And_Constituent_Use.
26170 and then (Has_Visible_Refinement
(State_Id
)
26171 or else Contains
(Repeat_Items
, State_Id
))
26174 ("global refinement of state & must include at least one "
26175 & "constituent of mode `Input`", N
, State_Id
);
26177 end Check_Constituent_Usage
;
26181 Item_Elmt
: Elmt_Id
;
26182 Item_Id
: Entity_Id
;
26184 -- Start of processing for Check_Input_States
26187 -- Do not perform this check in an instance because it was already
26188 -- performed successfully in the generic template.
26190 if Is_Generic_Instance
(Spec_Id
) then
26193 -- Inspect the Input items of the corresponding Global pragma looking
26194 -- for a state with a visible refinement.
26196 elsif Has_In_State
and then Present
(In_Items
) then
26197 Item_Elmt
:= First_Elmt
(In_Items
);
26198 while Present
(Item_Elmt
) loop
26199 Item_Id
:= Node
(Item_Elmt
);
26201 -- When full refinement is visible, ensure that at least one of
26202 -- the constituents is utilized and is of mode Input. When only
26203 -- partial refinement is visible, ensure that either one of
26204 -- the constituents is utilized and is of mode Input, or the
26205 -- abstract state is repeated and no constituent is utilized.
26207 if Ekind
(Item_Id
) = E_Abstract_State
26208 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
26210 Check_Constituent_Usage
(Item_Id
);
26213 Next_Elmt
(Item_Elmt
);
26216 end Check_Input_States
;
26218 -------------------------
26219 -- Check_Output_States --
26220 -------------------------
26222 procedure Check_Output_States
is
26223 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
26224 -- Determine whether all constituents of state State_Id with full
26225 -- visible refinement are used and have mode Output. Emit an error
26226 -- if this is not the case (SPARK RM 7.2.4(5)).
26228 -----------------------------
26229 -- Check_Constituent_Usage --
26230 -----------------------------
26232 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
26233 Constits
: constant Elist_Id
:=
26234 Partial_Refinement_Constituents
(State_Id
);
26235 Only_Partial
: constant Boolean :=
26236 not Has_Visible_Refinement
(State_Id
);
26237 Constit_Elmt
: Elmt_Id
;
26238 Constit_Id
: Entity_Id
;
26239 Posted
: Boolean := False;
26242 if Present
(Constits
) then
26243 Constit_Elmt
:= First_Elmt
(Constits
);
26244 while Present
(Constit_Elmt
) loop
26245 Constit_Id
:= Node
(Constit_Elmt
);
26247 -- Issue an error when a constituent of State_Id is utilized
26248 -- and State_Id has only partial visible refinement
26249 -- (SPARK RM 7.2.4(3d)).
26251 if Only_Partial
then
26252 if Present_Then_Remove
(Out_Constits
, Constit_Id
)
26253 or else Present_Then_Remove
(In_Constits
, Constit_Id
)
26255 Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
26257 Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
26259 Error_Msg_Name_1
:= Chars
(State_Id
);
26261 ("constituent & of state % cannot be used in global "
26262 & "refinement", N
, Constit_Id
);
26263 Error_Msg_Name_1
:= Chars
(State_Id
);
26264 SPARK_Msg_N
("\use state % instead", N
);
26267 elsif Present_Then_Remove
(Out_Constits
, Constit_Id
) then
26270 -- The constituent appears in the global refinement, but has
26271 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
26273 elsif Present_Then_Remove
(In_Constits
, Constit_Id
)
26274 or else Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
26275 or else Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
26277 Error_Msg_Name_1
:= Chars
(State_Id
);
26279 ("constituent & of state % must have mode `Output` in "
26280 & "global refinement", N
, Constit_Id
);
26282 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
26288 ("`Output` state & must be replaced by all its "
26289 & "constituents in global refinement", N
, State_Id
);
26293 ("\constituent & is missing in output list",
26297 Next_Elmt
(Constit_Elmt
);
26300 end Check_Constituent_Usage
;
26304 Item_Elmt
: Elmt_Id
;
26305 Item_Id
: Entity_Id
;
26307 -- Start of processing for Check_Output_States
26310 -- Do not perform this check in an instance because it was already
26311 -- performed successfully in the generic template.
26313 if Is_Generic_Instance
(Spec_Id
) then
26316 -- Inspect the Output items of the corresponding Global pragma
26317 -- looking for a state with a visible refinement.
26319 elsif Has_Out_State
and then Present
(Out_Items
) then
26320 Item_Elmt
:= First_Elmt
(Out_Items
);
26321 while Present
(Item_Elmt
) loop
26322 Item_Id
:= Node
(Item_Elmt
);
26324 -- When full refinement is visible, ensure that all of the
26325 -- constituents are utilized and they have mode Output. When
26326 -- only partial refinement is visible, ensure that no
26327 -- constituent is utilized.
26329 if Ekind
(Item_Id
) = E_Abstract_State
26330 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
26332 Check_Constituent_Usage
(Item_Id
);
26335 Next_Elmt
(Item_Elmt
);
26338 end Check_Output_States
;
26340 ---------------------------
26341 -- Check_Proof_In_States --
26342 ---------------------------
26344 procedure Check_Proof_In_States
is
26345 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
26346 -- Determine whether at least one constituent of state State_Id with
26347 -- full or partial visible refinement is used and has mode Proof_In.
26348 -- Ensure that the remaining constituents do not have Input, In_Out,
26349 -- or Output modes. Emit an error if this is not the case
26350 -- (SPARK RM 7.2.4(5)).
26352 -----------------------------
26353 -- Check_Constituent_Usage --
26354 -----------------------------
26356 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
26357 Constits
: constant Elist_Id
:=
26358 Partial_Refinement_Constituents
(State_Id
);
26359 Constit_Elmt
: Elmt_Id
;
26360 Constit_Id
: Entity_Id
;
26361 Proof_In_Seen
: Boolean := False;
26364 if Present
(Constits
) then
26365 Constit_Elmt
:= First_Elmt
(Constits
);
26366 while Present
(Constit_Elmt
) loop
26367 Constit_Id
:= Node
(Constit_Elmt
);
26369 -- At least one of the constituents appears as Proof_In
26371 if Present_Then_Remove
(Proof_In_Constits
, Constit_Id
) then
26372 Proof_In_Seen
:= True;
26374 -- The constituent appears in the global refinement, but has
26375 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
26377 elsif Present_Then_Remove
(In_Constits
, Constit_Id
)
26378 or else Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
26379 or else Present_Then_Remove
(Out_Constits
, Constit_Id
)
26381 Error_Msg_Name_1
:= Chars
(State_Id
);
26383 ("constituent & of state % must have mode `Proof_In` "
26384 & "in global refinement", N
, Constit_Id
);
26387 Next_Elmt
(Constit_Elmt
);
26391 -- Not one of the constituents appeared as Proof_In. Always emit
26392 -- an error when full refinement is visible (SPARK RM 7.2.4(3a)).
26393 -- When only partial refinement is visible, emit an error if the
26394 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
26395 -- the case where both are utilized, an error will be issued by
26396 -- Check_State_And_Constituent_Use.
26398 if not Proof_In_Seen
26399 and then (Has_Visible_Refinement
(State_Id
)
26400 or else Contains
(Repeat_Items
, State_Id
))
26403 ("global refinement of state & must include at least one "
26404 & "constituent of mode `Proof_In`", N
, State_Id
);
26406 end Check_Constituent_Usage
;
26410 Item_Elmt
: Elmt_Id
;
26411 Item_Id
: Entity_Id
;
26413 -- Start of processing for Check_Proof_In_States
26416 -- Do not perform this check in an instance because it was already
26417 -- performed successfully in the generic template.
26419 if Is_Generic_Instance
(Spec_Id
) then
26422 -- Inspect the Proof_In items of the corresponding Global pragma
26423 -- looking for a state with a visible refinement.
26425 elsif Has_Proof_In_State
and then Present
(Proof_In_Items
) then
26426 Item_Elmt
:= First_Elmt
(Proof_In_Items
);
26427 while Present
(Item_Elmt
) loop
26428 Item_Id
:= Node
(Item_Elmt
);
26430 -- Ensure that at least one of the constituents is utilized
26431 -- and is of mode Proof_In. When only partial refinement is
26432 -- visible, ensure that either one of the constituents is
26433 -- utilized and is of mode Proof_In, or the abstract state
26434 -- is repeated and no constituent is utilized.
26436 if Ekind
(Item_Id
) = E_Abstract_State
26437 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
26439 Check_Constituent_Usage
(Item_Id
);
26442 Next_Elmt
(Item_Elmt
);
26445 end Check_Proof_In_States
;
26447 -------------------------------
26448 -- Check_Refined_Global_List --
26449 -------------------------------
26451 procedure Check_Refined_Global_List
26453 Global_Mode
: Name_Id
:= Name_Input
)
26455 procedure Check_Refined_Global_Item
26457 Global_Mode
: Name_Id
);
26458 -- Verify the legality of a single global item declaration. Parameter
26459 -- Global_Mode denotes the current mode in effect.
26461 -------------------------------
26462 -- Check_Refined_Global_Item --
26463 -------------------------------
26465 procedure Check_Refined_Global_Item
26467 Global_Mode
: Name_Id
)
26469 Item_Id
: constant Entity_Id
:= Entity_Of
(Item
);
26471 procedure Inconsistent_Mode_Error
(Expect
: Name_Id
);
26472 -- Issue a common error message for all mode mismatches. Expect
26473 -- denotes the expected mode.
26475 -----------------------------
26476 -- Inconsistent_Mode_Error --
26477 -----------------------------
26479 procedure Inconsistent_Mode_Error
(Expect
: Name_Id
) is
26482 ("global item & has inconsistent modes", Item
, Item_Id
);
26484 Error_Msg_Name_1
:= Global_Mode
;
26485 Error_Msg_Name_2
:= Expect
;
26486 SPARK_Msg_N
("\expected mode %, found mode %", Item
);
26487 end Inconsistent_Mode_Error
;
26491 Enc_State
: Entity_Id
:= Empty
;
26492 -- Encapsulating state for constituent, Empty otherwise
26494 -- Start of processing for Check_Refined_Global_Item
26497 if Ekind_In
(Item_Id
, E_Abstract_State
,
26501 Enc_State
:= Find_Encapsulating_State
(States
, Item_Id
);
26504 -- When the state or object acts as a constituent of another
26505 -- state with a visible refinement, collect it for the state
26506 -- completeness checks performed later on. Note that the item
26507 -- acts as a constituent only when the encapsulating state is
26508 -- present in pragma Global.
26510 if Present
(Enc_State
)
26511 and then (Has_Visible_Refinement
(Enc_State
)
26512 or else Has_Partial_Visible_Refinement
(Enc_State
))
26513 and then Contains
(States
, Enc_State
)
26515 -- If the state has only partial visible refinement, remove it
26516 -- from the list of items that should be repeated from pragma
26519 if not Has_Visible_Refinement
(Enc_State
) then
26520 Present_Then_Remove
(Repeat_Items
, Enc_State
);
26523 if Global_Mode
= Name_Input
then
26524 Append_New_Elmt
(Item_Id
, In_Constits
);
26526 elsif Global_Mode
= Name_In_Out
then
26527 Append_New_Elmt
(Item_Id
, In_Out_Constits
);
26529 elsif Global_Mode
= Name_Output
then
26530 Append_New_Elmt
(Item_Id
, Out_Constits
);
26532 elsif Global_Mode
= Name_Proof_In
then
26533 Append_New_Elmt
(Item_Id
, Proof_In_Constits
);
26536 -- When not a constituent, ensure that both occurrences of the
26537 -- item in pragmas Global and Refined_Global match. Also remove
26538 -- it when present from the list of items that should be repeated
26539 -- from pragma Global.
26542 Present_Then_Remove
(Repeat_Items
, Item_Id
);
26544 if Contains
(In_Items
, Item_Id
) then
26545 if Global_Mode
/= Name_Input
then
26546 Inconsistent_Mode_Error
(Name_Input
);
26549 elsif Contains
(In_Out_Items
, Item_Id
) then
26550 if Global_Mode
/= Name_In_Out
then
26551 Inconsistent_Mode_Error
(Name_In_Out
);
26554 elsif Contains
(Out_Items
, Item_Id
) then
26555 if Global_Mode
/= Name_Output
then
26556 Inconsistent_Mode_Error
(Name_Output
);
26559 elsif Contains
(Proof_In_Items
, Item_Id
) then
26562 -- The item does not appear in the corresponding Global pragma,
26563 -- it must be an extra (SPARK RM 7.2.4(3)).
26566 SPARK_Msg_NE
("extra global item &", Item
, Item_Id
);
26569 end Check_Refined_Global_Item
;
26575 -- Start of processing for Check_Refined_Global_List
26578 -- Do not perform this check in an instance because it was already
26579 -- performed successfully in the generic template.
26581 if Is_Generic_Instance
(Spec_Id
) then
26584 elsif Nkind
(List
) = N_Null
then
26587 -- Single global item declaration
26589 elsif Nkind_In
(List
, N_Expanded_Name
,
26591 N_Selected_Component
)
26593 Check_Refined_Global_Item
(List
, Global_Mode
);
26595 -- Simple global list or moded global list declaration
26597 elsif Nkind
(List
) = N_Aggregate
then
26599 -- The declaration of a simple global list appear as a collection
26602 if Present
(Expressions
(List
)) then
26603 Item
:= First
(Expressions
(List
));
26604 while Present
(Item
) loop
26605 Check_Refined_Global_Item
(Item
, Global_Mode
);
26609 -- The declaration of a moded global list appears as a collection
26610 -- of component associations where individual choices denote
26613 elsif Present
(Component_Associations
(List
)) then
26614 Item
:= First
(Component_Associations
(List
));
26615 while Present
(Item
) loop
26616 Check_Refined_Global_List
26617 (List
=> Expression
(Item
),
26618 Global_Mode
=> Chars
(First
(Choices
(Item
))));
26626 raise Program_Error
;
26632 raise Program_Error
;
26634 end Check_Refined_Global_List
;
26636 --------------------------
26637 -- Collect_Global_Items --
26638 --------------------------
26640 procedure Collect_Global_Items
26642 Mode
: Name_Id
:= Name_Input
)
26644 procedure Collect_Global_Item
26646 Item_Mode
: Name_Id
);
26647 -- Add a single item to the appropriate list. Item_Mode denotes the
26648 -- current mode in effect.
26650 -------------------------
26651 -- Collect_Global_Item --
26652 -------------------------
26654 procedure Collect_Global_Item
26656 Item_Mode
: Name_Id
)
26658 Item_Id
: constant Entity_Id
:= Available_View
(Entity_Of
(Item
));
26659 -- The above handles abstract views of variables and states built
26660 -- for limited with clauses.
26663 -- Signal that the global list contains at least one abstract
26664 -- state with a visible refinement. Note that the refinement may
26665 -- be null in which case there are no constituents.
26667 if Ekind
(Item_Id
) = E_Abstract_State
then
26668 if Has_Null_Visible_Refinement
(Item_Id
) then
26669 Has_Null_State
:= True;
26671 elsif Has_Non_Null_Visible_Refinement
(Item_Id
) then
26672 Append_New_Elmt
(Item_Id
, States
);
26674 if Item_Mode
= Name_Input
then
26675 Has_In_State
:= True;
26676 elsif Item_Mode
= Name_In_Out
then
26677 Has_In_Out_State
:= True;
26678 elsif Item_Mode
= Name_Output
then
26679 Has_Out_State
:= True;
26680 elsif Item_Mode
= Name_Proof_In
then
26681 Has_Proof_In_State
:= True;
26686 -- Record global items without full visible refinement found in
26687 -- pragma Global which should be repeated in the global refinement
26688 -- (SPARK RM 7.2.4(3c), SPARK RM 7.2.4(3d)).
26690 if Ekind
(Item_Id
) /= E_Abstract_State
26691 or else not Has_Visible_Refinement
(Item_Id
)
26693 Append_New_Elmt
(Item_Id
, Repeat_Items
);
26696 -- Add the item to the proper list
26698 if Item_Mode
= Name_Input
then
26699 Append_New_Elmt
(Item_Id
, In_Items
);
26700 elsif Item_Mode
= Name_In_Out
then
26701 Append_New_Elmt
(Item_Id
, In_Out_Items
);
26702 elsif Item_Mode
= Name_Output
then
26703 Append_New_Elmt
(Item_Id
, Out_Items
);
26704 elsif Item_Mode
= Name_Proof_In
then
26705 Append_New_Elmt
(Item_Id
, Proof_In_Items
);
26707 end Collect_Global_Item
;
26713 -- Start of processing for Collect_Global_Items
26716 if Nkind
(List
) = N_Null
then
26719 -- Single global item declaration
26721 elsif Nkind_In
(List
, N_Expanded_Name
,
26723 N_Selected_Component
)
26725 Collect_Global_Item
(List
, Mode
);
26727 -- Single global list or moded global list declaration
26729 elsif Nkind
(List
) = N_Aggregate
then
26731 -- The declaration of a simple global list appear as a collection
26734 if Present
(Expressions
(List
)) then
26735 Item
:= First
(Expressions
(List
));
26736 while Present
(Item
) loop
26737 Collect_Global_Item
(Item
, Mode
);
26741 -- The declaration of a moded global list appears as a collection
26742 -- of component associations where individual choices denote mode.
26744 elsif Present
(Component_Associations
(List
)) then
26745 Item
:= First
(Component_Associations
(List
));
26746 while Present
(Item
) loop
26747 Collect_Global_Items
26748 (List
=> Expression
(Item
),
26749 Mode
=> Chars
(First
(Choices
(Item
))));
26757 raise Program_Error
;
26760 -- To accommodate partial decoration of disabled SPARK features, this
26761 -- routine may be called with illegal input. If this is the case, do
26762 -- not raise Program_Error.
26767 end Collect_Global_Items
;
26769 -------------------------
26770 -- Present_Then_Remove --
26771 -------------------------
26773 function Present_Then_Remove
26775 Item
: Entity_Id
) return Boolean
26780 if Present
(List
) then
26781 Elmt
:= First_Elmt
(List
);
26782 while Present
(Elmt
) loop
26783 if Node
(Elmt
) = Item
then
26784 Remove_Elmt
(List
, Elmt
);
26793 end Present_Then_Remove
;
26795 procedure Present_Then_Remove
(List
: Elist_Id
; Item
: Entity_Id
) is
26798 Ignore
:= Present_Then_Remove
(List
, Item
);
26799 end Present_Then_Remove
;
26801 -------------------------------
26802 -- Report_Extra_Constituents --
26803 -------------------------------
26805 procedure Report_Extra_Constituents
is
26806 procedure Report_Extra_Constituents_In_List
(List
: Elist_Id
);
26807 -- Emit an error for every element of List
26809 ---------------------------------------
26810 -- Report_Extra_Constituents_In_List --
26811 ---------------------------------------
26813 procedure Report_Extra_Constituents_In_List
(List
: Elist_Id
) is
26814 Constit_Elmt
: Elmt_Id
;
26817 if Present
(List
) then
26818 Constit_Elmt
:= First_Elmt
(List
);
26819 while Present
(Constit_Elmt
) loop
26820 SPARK_Msg_NE
("extra constituent &", N
, Node
(Constit_Elmt
));
26821 Next_Elmt
(Constit_Elmt
);
26824 end Report_Extra_Constituents_In_List
;
26826 -- Start of processing for Report_Extra_Constituents
26829 -- Do not perform this check in an instance because it was already
26830 -- performed successfully in the generic template.
26832 if Is_Generic_Instance
(Spec_Id
) then
26836 Report_Extra_Constituents_In_List
(In_Constits
);
26837 Report_Extra_Constituents_In_List
(In_Out_Constits
);
26838 Report_Extra_Constituents_In_List
(Out_Constits
);
26839 Report_Extra_Constituents_In_List
(Proof_In_Constits
);
26841 end Report_Extra_Constituents
;
26843 --------------------------
26844 -- Report_Missing_Items --
26845 --------------------------
26847 procedure Report_Missing_Items
is
26848 Item_Elmt
: Elmt_Id
;
26849 Item_Id
: Entity_Id
;
26852 -- Do not perform this check in an instance because it was already
26853 -- performed successfully in the generic template.
26855 if Is_Generic_Instance
(Spec_Id
) then
26859 if Present
(Repeat_Items
) then
26860 Item_Elmt
:= First_Elmt
(Repeat_Items
);
26861 while Present
(Item_Elmt
) loop
26862 Item_Id
:= Node
(Item_Elmt
);
26863 SPARK_Msg_NE
("missing global item &", N
, Item_Id
);
26864 Next_Elmt
(Item_Elmt
);
26868 end Report_Missing_Items
;
26872 Body_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
26873 Errors
: constant Nat
:= Serious_Errors_Detected
;
26875 No_Constit
: Boolean;
26877 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
26880 -- Do not analyze the pragma multiple times
26882 if Is_Analyzed_Pragma
(N
) then
26886 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
26888 -- Use the anonymous object as the proper spec when Refined_Global
26889 -- applies to the body of a single task type. The object carries the
26890 -- proper Chars as well as all non-refined versions of pragmas.
26892 if Is_Single_Concurrent_Type
(Spec_Id
) then
26893 Spec_Id
:= Anonymous_Object
(Spec_Id
);
26896 Global
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
26897 Items
:= Expression
(Get_Argument
(N
, Spec_Id
));
26899 -- The subprogram declaration lacks pragma Global. This renders
26900 -- Refined_Global useless as there is nothing to refine.
26902 if No
(Global
) then
26904 (Fix_Msg
(Spec_Id
, "useless refinement, declaration of subprogram "
26905 & "& lacks aspect or pragma Global"), N
, Spec_Id
);
26909 -- Extract all relevant items from the corresponding Global pragma
26911 Collect_Global_Items
(Expression
(Get_Argument
(Global
, Spec_Id
)));
26913 -- Package and subprogram bodies are instantiated individually in
26914 -- a separate compiler pass. Due to this mode of instantiation, the
26915 -- refinement of a state may no longer be visible when a subprogram
26916 -- body contract is instantiated. Since the generic template is legal,
26917 -- do not perform this check in the instance to circumvent this oddity.
26919 if Is_Generic_Instance
(Spec_Id
) then
26922 -- Non-instance case
26925 -- The corresponding Global pragma must mention at least one
26926 -- state with a visible refinement at the point Refined_Global
26927 -- is processed. States with null refinements need Refined_Global
26928 -- pragma (SPARK RM 7.2.4(2)).
26930 if not Has_In_State
26931 and then not Has_In_Out_State
26932 and then not Has_Out_State
26933 and then not Has_Proof_In_State
26934 and then not Has_Null_State
26937 (Fix_Msg
(Spec_Id
, "useless refinement, subprogram & does not "
26938 & "depend on abstract state with visible refinement"),
26942 -- The global refinement of inputs and outputs cannot be null when
26943 -- the corresponding Global pragma contains at least one item except
26944 -- in the case where we have states with null refinements.
26946 elsif Nkind
(Items
) = N_Null
26948 (Present
(In_Items
)
26949 or else Present
(In_Out_Items
)
26950 or else Present
(Out_Items
)
26951 or else Present
(Proof_In_Items
))
26952 and then not Has_Null_State
26955 (Fix_Msg
(Spec_Id
, "refinement cannot be null, subprogram & has "
26956 & "global items"), N
, Spec_Id
);
26961 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
26962 -- This ensures that the categorization of all refined global items is
26963 -- consistent with their role.
26965 Analyze_Global_In_Decl_Part
(N
);
26967 -- Perform all refinement checks with respect to completeness and mode
26970 if Serious_Errors_Detected
= Errors
then
26971 Check_Refined_Global_List
(Items
);
26974 -- Store the information that no constituent is used in the global
26975 -- refinement, prior to calling checking procedures which remove items
26976 -- from the list of constituents.
26980 and then No
(In_Out_Constits
)
26981 and then No
(Out_Constits
)
26982 and then No
(Proof_In_Constits
);
26984 -- For Input states with visible refinement, at least one constituent
26985 -- must be used as an Input in the global refinement.
26987 if Serious_Errors_Detected
= Errors
then
26988 Check_Input_States
;
26991 -- Verify all possible completion variants for In_Out states with
26992 -- visible refinement.
26994 if Serious_Errors_Detected
= Errors
then
26995 Check_In_Out_States
;
26998 -- For Output states with visible refinement, all constituents must be
26999 -- used as Outputs in the global refinement.
27001 if Serious_Errors_Detected
= Errors
then
27002 Check_Output_States
;
27005 -- For Proof_In states with visible refinement, at least one constituent
27006 -- must be used as Proof_In in the global refinement.
27008 if Serious_Errors_Detected
= Errors
then
27009 Check_Proof_In_States
;
27012 -- Emit errors for all constituents that belong to other states with
27013 -- visible refinement that do not appear in Global.
27015 if Serious_Errors_Detected
= Errors
then
27016 Report_Extra_Constituents
;
27019 -- Emit errors for all items in Global that are not repeated in the
27020 -- global refinement and for which there is no full visible refinement
27021 -- and, in the case of states with partial visible refinement, no
27022 -- constituent is mentioned in the global refinement.
27024 if Serious_Errors_Detected
= Errors
then
27025 Report_Missing_Items
;
27028 -- Emit an error if no constituent is used in the global refinement
27029 -- (SPARK RM 7.2.4(3f)). Emit this error last, in case a more precise
27030 -- one may be issued by the checking procedures. Do not perform this
27031 -- check in an instance because it was already performed successfully
27032 -- in the generic template.
27034 if Serious_Errors_Detected
= Errors
27035 and then not Is_Generic_Instance
(Spec_Id
)
27036 and then not Has_Null_State
27037 and then No_Constit
27039 SPARK_Msg_N
("missing refinement", N
);
27043 Set_Is_Analyzed_Pragma
(N
);
27044 end Analyze_Refined_Global_In_Decl_Part
;
27046 ----------------------------------------
27047 -- Analyze_Refined_State_In_Decl_Part --
27048 ----------------------------------------
27050 procedure Analyze_Refined_State_In_Decl_Part
27052 Freeze_Id
: Entity_Id
:= Empty
)
27054 Body_Decl
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
27055 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Decl
);
27056 Spec_Id
: constant Entity_Id
:= Corresponding_Spec
(Body_Decl
);
27058 Available_States
: Elist_Id
:= No_Elist
;
27059 -- A list of all abstract states defined in the package declaration that
27060 -- are available for refinement. The list is used to report unrefined
27063 Body_States
: Elist_Id
:= No_Elist
;
27064 -- A list of all hidden states that appear in the body of the related
27065 -- package. The list is used to report unused hidden states.
27067 Constituents_Seen
: Elist_Id
:= No_Elist
;
27068 -- A list that contains all constituents processed so far. The list is
27069 -- used to detect multiple uses of the same constituent.
27071 Freeze_Posted
: Boolean := False;
27072 -- A flag that controls the output of a freezing-related error (see use
27075 Refined_States_Seen
: Elist_Id
:= No_Elist
;
27076 -- A list that contains all refined states processed so far. The list is
27077 -- used to detect duplicate refinements.
27079 procedure Analyze_Refinement_Clause
(Clause
: Node_Id
);
27080 -- Perform full analysis of a single refinement clause
27082 procedure Report_Unrefined_States
(States
: Elist_Id
);
27083 -- Emit errors for all unrefined abstract states found in list States
27085 -------------------------------
27086 -- Analyze_Refinement_Clause --
27087 -------------------------------
27089 procedure Analyze_Refinement_Clause
(Clause
: Node_Id
) is
27090 AR_Constit
: Entity_Id
:= Empty
;
27091 AW_Constit
: Entity_Id
:= Empty
;
27092 ER_Constit
: Entity_Id
:= Empty
;
27093 EW_Constit
: Entity_Id
:= Empty
;
27094 -- The entities of external constituents that contain one of the
27095 -- following enabled properties: Async_Readers, Async_Writers,
27096 -- Effective_Reads and Effective_Writes.
27098 External_Constit_Seen
: Boolean := False;
27099 -- Flag used to mark when at least one external constituent is part
27100 -- of the state refinement.
27102 Non_Null_Seen
: Boolean := False;
27103 Null_Seen
: Boolean := False;
27104 -- Flags used to detect multiple uses of null in a single clause or a
27105 -- mixture of null and non-null constituents.
27107 Part_Of_Constits
: Elist_Id
:= No_Elist
;
27108 -- A list of all candidate constituents subject to indicator Part_Of
27109 -- where the encapsulating state is the current state.
27112 State_Id
: Entity_Id
;
27113 -- The current state being refined
27115 procedure Analyze_Constituent
(Constit
: Node_Id
);
27116 -- Perform full analysis of a single constituent
27118 procedure Check_External_Property
27119 (Prop_Nam
: Name_Id
;
27121 Constit
: Entity_Id
);
27122 -- Determine whether a property denoted by name Prop_Nam is present
27123 -- in the refined state. Emit an error if this is not the case. Flag
27124 -- Enabled should be set when the property applies to the refined
27125 -- state. Constit denotes the constituent (if any) which introduces
27126 -- the property in the refinement.
27128 procedure Match_State
;
27129 -- Determine whether the state being refined appears in list
27130 -- Available_States. Emit an error when attempting to re-refine the
27131 -- state or when the state is not defined in the package declaration,
27132 -- otherwise remove the state from Available_States.
27134 procedure Report_Unused_Constituents
(Constits
: Elist_Id
);
27135 -- Emit errors for all unused Part_Of constituents in list Constits
27137 -------------------------
27138 -- Analyze_Constituent --
27139 -------------------------
27141 procedure Analyze_Constituent
(Constit
: Node_Id
) is
27142 procedure Match_Constituent
(Constit_Id
: Entity_Id
);
27143 -- Determine whether constituent Constit denoted by its entity
27144 -- Constit_Id appears in Body_States. Emit an error when the
27145 -- constituent is not a valid hidden state of the related package
27146 -- or when it is used more than once. Otherwise remove the
27147 -- constituent from Body_States.
27149 -----------------------
27150 -- Match_Constituent --
27151 -----------------------
27153 procedure Match_Constituent
(Constit_Id
: Entity_Id
) is
27154 procedure Collect_Constituent
;
27155 -- Verify the legality of constituent Constit_Id and add it to
27156 -- the refinements of State_Id.
27158 -------------------------
27159 -- Collect_Constituent --
27160 -------------------------
27162 procedure Collect_Constituent
is
27163 Constits
: Elist_Id
;
27166 -- The Ghost policy in effect at the point of abstract state
27167 -- declaration and constituent must match (SPARK RM 6.9(15))
27169 Check_Ghost_Refinement
27170 (State
, State_Id
, Constit
, Constit_Id
);
27172 -- A synchronized state must be refined by a synchronized
27173 -- object or another synchronized state (SPARK RM 9.6).
27175 if Is_Synchronized_State
(State_Id
)
27176 and then not Is_Synchronized_Object
(Constit_Id
)
27177 and then not Is_Synchronized_State
(Constit_Id
)
27180 ("constituent of synchronized state & must be "
27181 & "synchronized", Constit
, State_Id
);
27184 -- Add the constituent to the list of processed items to aid
27185 -- with the detection of duplicates.
27187 Append_New_Elmt
(Constit_Id
, Constituents_Seen
);
27189 -- Collect the constituent in the list of refinement items
27190 -- and establish a relation between the refined state and
27193 Constits
:= Refinement_Constituents
(State_Id
);
27195 if No
(Constits
) then
27196 Constits
:= New_Elmt_List
;
27197 Set_Refinement_Constituents
(State_Id
, Constits
);
27200 Append_Elmt
(Constit_Id
, Constits
);
27201 Set_Encapsulating_State
(Constit_Id
, State_Id
);
27203 -- The state has at least one legal constituent, mark the
27204 -- start of the refinement region. The region ends when the
27205 -- body declarations end (see routine Analyze_Declarations).
27207 Set_Has_Visible_Refinement
(State_Id
);
27209 -- When the constituent is external, save its relevant
27210 -- property for further checks.
27212 if Async_Readers_Enabled
(Constit_Id
) then
27213 AR_Constit
:= Constit_Id
;
27214 External_Constit_Seen
:= True;
27217 if Async_Writers_Enabled
(Constit_Id
) then
27218 AW_Constit
:= Constit_Id
;
27219 External_Constit_Seen
:= True;
27222 if Effective_Reads_Enabled
(Constit_Id
) then
27223 ER_Constit
:= Constit_Id
;
27224 External_Constit_Seen
:= True;
27227 if Effective_Writes_Enabled
(Constit_Id
) then
27228 EW_Constit
:= Constit_Id
;
27229 External_Constit_Seen
:= True;
27231 end Collect_Constituent
;
27235 State_Elmt
: Elmt_Id
;
27237 -- Start of processing for Match_Constituent
27240 -- Detect a duplicate use of a constituent
27242 if Contains
(Constituents_Seen
, Constit_Id
) then
27244 ("duplicate use of constituent &", Constit
, Constit_Id
);
27248 -- The constituent is subject to a Part_Of indicator
27250 if Present
(Encapsulating_State
(Constit_Id
)) then
27251 if Encapsulating_State
(Constit_Id
) = State_Id
then
27252 Remove
(Part_Of_Constits
, Constit_Id
);
27253 Collect_Constituent
;
27255 -- The constituent is part of another state and is used
27256 -- incorrectly in the refinement of the current state.
27259 Error_Msg_Name_1
:= Chars
(State_Id
);
27261 ("& cannot act as constituent of state %",
27262 Constit
, Constit_Id
);
27264 ("\Part_Of indicator specifies encapsulator &",
27265 Constit
, Encapsulating_State
(Constit_Id
));
27268 -- The only other source of legal constituents is the body
27269 -- state space of the related package.
27272 if Present
(Body_States
) then
27273 State_Elmt
:= First_Elmt
(Body_States
);
27274 while Present
(State_Elmt
) loop
27276 -- Consume a valid constituent to signal that it has
27277 -- been encountered.
27279 if Node
(State_Elmt
) = Constit_Id
then
27280 Remove_Elmt
(Body_States
, State_Elmt
);
27281 Collect_Constituent
;
27285 Next_Elmt
(State_Elmt
);
27289 -- Constants are part of the hidden state of a package, but
27290 -- the compiler cannot determine whether they have variable
27291 -- input (SPARK RM 7.1.1(2)) and cannot classify them as a
27292 -- hidden state. Accept the constant quietly even if it is
27293 -- a visible state or lacks a Part_Of indicator.
27295 if Ekind
(Constit_Id
) = E_Constant
then
27296 Collect_Constituent
;
27298 -- If we get here, then the constituent is not a hidden
27299 -- state of the related package and may not be used in a
27300 -- refinement (SPARK RM 7.2.2(9)).
27303 Error_Msg_Name_1
:= Chars
(Spec_Id
);
27305 ("cannot use & in refinement, constituent is not a "
27306 & "hidden state of package %", Constit
, Constit_Id
);
27309 end Match_Constituent
;
27313 Constit_Id
: Entity_Id
;
27314 Constits
: Elist_Id
;
27316 -- Start of processing for Analyze_Constituent
27319 -- Detect multiple uses of null in a single refinement clause or a
27320 -- mixture of null and non-null constituents.
27322 if Nkind
(Constit
) = N_Null
then
27325 ("multiple null constituents not allowed", Constit
);
27327 elsif Non_Null_Seen
then
27329 ("cannot mix null and non-null constituents", Constit
);
27334 -- Collect the constituent in the list of refinement items
27336 Constits
:= Refinement_Constituents
(State_Id
);
27338 if No
(Constits
) then
27339 Constits
:= New_Elmt_List
;
27340 Set_Refinement_Constituents
(State_Id
, Constits
);
27343 Append_Elmt
(Constit
, Constits
);
27345 -- The state has at least one legal constituent, mark the
27346 -- start of the refinement region. The region ends when the
27347 -- body declarations end (see Analyze_Declarations).
27349 Set_Has_Visible_Refinement
(State_Id
);
27352 -- Non-null constituents
27355 Non_Null_Seen
:= True;
27359 ("cannot mix null and non-null constituents", Constit
);
27363 Resolve_State
(Constit
);
27365 -- Ensure that the constituent denotes a valid state or a
27366 -- whole object (SPARK RM 7.2.2(5)).
27368 if Is_Entity_Name
(Constit
) then
27369 Constit_Id
:= Entity_Of
(Constit
);
27371 -- When a constituent is declared after a subprogram body
27372 -- that caused freezing of the related contract where
27373 -- pragma Refined_State resides, the constituent appears
27374 -- undefined and carries Any_Id as its entity.
27376 -- package body Pack
27377 -- with Refined_State => (State => Constit)
27380 -- with Refined_Global => (Input => Constit)
27388 if Constit_Id
= Any_Id
then
27389 SPARK_Msg_NE
("& is undefined", Constit
, Constit_Id
);
27391 -- Emit a specialized info message when the contract of
27392 -- the related package body was "frozen" by another body.
27393 -- Note that it is not possible to precisely identify why
27394 -- the constituent is undefined because it is not visible
27395 -- when pragma Refined_State is analyzed. This message is
27396 -- a reasonable approximation.
27398 if Present
(Freeze_Id
) and then not Freeze_Posted
then
27399 Freeze_Posted
:= True;
27401 Error_Msg_Name_1
:= Chars
(Body_Id
);
27402 Error_Msg_Sloc
:= Sloc
(Freeze_Id
);
27404 ("body & declared # freezes the contract of %",
27407 ("\all constituents must be declared before body #",
27410 -- A misplaced constituent is a critical error because
27411 -- pragma Refined_Depends or Refined_Global depends on
27412 -- the proper link between a state and a constituent.
27413 -- Stop the compilation, as this leads to a multitude
27414 -- of misleading cascaded errors.
27416 raise Unrecoverable_Error
;
27419 -- The constituent is a valid state or object
27421 elsif Ekind_In
(Constit_Id
, E_Abstract_State
,
27425 Match_Constituent
(Constit_Id
);
27427 -- The variable may eventually become a constituent of a
27428 -- single protected/task type. Record the reference now
27429 -- and verify its legality when analyzing the contract of
27430 -- the variable (SPARK RM 9.3).
27432 if Ekind
(Constit_Id
) = E_Variable
then
27433 Record_Possible_Part_Of_Reference
27434 (Var_Id
=> Constit_Id
,
27438 -- Otherwise the constituent is illegal
27442 ("constituent & must denote object or state",
27443 Constit
, Constit_Id
);
27446 -- The constituent is illegal
27449 SPARK_Msg_N
("malformed constituent", Constit
);
27452 end Analyze_Constituent
;
27454 -----------------------------
27455 -- Check_External_Property --
27456 -----------------------------
27458 procedure Check_External_Property
27459 (Prop_Nam
: Name_Id
;
27461 Constit
: Entity_Id
)
27464 -- The property is missing in the declaration of the state, but
27465 -- a constituent is introducing it in the state refinement
27466 -- (SPARK RM 7.2.8(2)).
27468 if not Enabled
and then Present
(Constit
) then
27469 Error_Msg_Name_1
:= Prop_Nam
;
27470 Error_Msg_Name_2
:= Chars
(State_Id
);
27472 ("constituent & introduces external property % in refinement "
27473 & "of state %", State
, Constit
);
27475 Error_Msg_Sloc
:= Sloc
(State_Id
);
27477 ("\property is missing in abstract state declaration #",
27480 end Check_External_Property
;
27486 procedure Match_State
is
27487 State_Elmt
: Elmt_Id
;
27490 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
27492 if Contains
(Refined_States_Seen
, State_Id
) then
27494 ("duplicate refinement of state &", State
, State_Id
);
27498 -- Inspect the abstract states defined in the package declaration
27499 -- looking for a match.
27501 State_Elmt
:= First_Elmt
(Available_States
);
27502 while Present
(State_Elmt
) loop
27504 -- A valid abstract state is being refined in the body. Add
27505 -- the state to the list of processed refined states to aid
27506 -- with the detection of duplicate refinements. Remove the
27507 -- state from Available_States to signal that it has already
27510 if Node
(State_Elmt
) = State_Id
then
27511 Append_New_Elmt
(State_Id
, Refined_States_Seen
);
27512 Remove_Elmt
(Available_States
, State_Elmt
);
27516 Next_Elmt
(State_Elmt
);
27519 -- If we get here, we are refining a state that is not defined in
27520 -- the package declaration.
27522 Error_Msg_Name_1
:= Chars
(Spec_Id
);
27524 ("cannot refine state, & is not defined in package %",
27528 --------------------------------
27529 -- Report_Unused_Constituents --
27530 --------------------------------
27532 procedure Report_Unused_Constituents
(Constits
: Elist_Id
) is
27533 Constit_Elmt
: Elmt_Id
;
27534 Constit_Id
: Entity_Id
;
27535 Posted
: Boolean := False;
27538 if Present
(Constits
) then
27539 Constit_Elmt
:= First_Elmt
(Constits
);
27540 while Present
(Constit_Elmt
) loop
27541 Constit_Id
:= Node
(Constit_Elmt
);
27543 -- Generate an error message of the form:
27545 -- state ... has unused Part_Of constituents
27546 -- abstract state ... defined at ...
27547 -- constant ... defined at ...
27548 -- variable ... defined at ...
27553 ("state & has unused Part_Of constituents",
27557 Error_Msg_Sloc
:= Sloc
(Constit_Id
);
27559 if Ekind
(Constit_Id
) = E_Abstract_State
then
27561 ("\abstract state & defined #", State
, Constit_Id
);
27563 elsif Ekind
(Constit_Id
) = E_Constant
then
27565 ("\constant & defined #", State
, Constit_Id
);
27568 pragma Assert
(Ekind
(Constit_Id
) = E_Variable
);
27569 SPARK_Msg_NE
("\variable & defined #", State
, Constit_Id
);
27572 Next_Elmt
(Constit_Elmt
);
27575 end Report_Unused_Constituents
;
27577 -- Local declarations
27579 Body_Ref
: Node_Id
;
27580 Body_Ref_Elmt
: Elmt_Id
;
27582 Extra_State
: Node_Id
;
27584 -- Start of processing for Analyze_Refinement_Clause
27587 -- A refinement clause appears as a component association where the
27588 -- sole choice is the state and the expressions are the constituents.
27589 -- This is a syntax error, always report.
27591 if Nkind
(Clause
) /= N_Component_Association
then
27592 Error_Msg_N
("malformed state refinement clause", Clause
);
27596 -- Analyze the state name of a refinement clause
27598 State
:= First
(Choices
(Clause
));
27601 Resolve_State
(State
);
27603 -- Ensure that the state name denotes a valid abstract state that is
27604 -- defined in the spec of the related package.
27606 if Is_Entity_Name
(State
) then
27607 State_Id
:= Entity_Of
(State
);
27609 -- When the abstract state is undefined, it appears as Any_Id. Do
27610 -- not continue with the analysis of the clause.
27612 if State_Id
= Any_Id
then
27615 -- Catch any attempts to re-refine a state or refine a state that
27616 -- is not defined in the package declaration.
27618 elsif Ekind
(State_Id
) = E_Abstract_State
then
27622 SPARK_Msg_NE
("& must denote abstract state", State
, State_Id
);
27626 -- References to a state with visible refinement are illegal.
27627 -- When nested packages are involved, detecting such references is
27628 -- tricky because pragma Refined_State is analyzed later than the
27629 -- offending pragma Depends or Global. References that occur in
27630 -- such nested context are stored in a list. Emit errors for all
27631 -- references found in Body_References (SPARK RM 6.1.4(8)).
27633 if Present
(Body_References
(State_Id
)) then
27634 Body_Ref_Elmt
:= First_Elmt
(Body_References
(State_Id
));
27635 while Present
(Body_Ref_Elmt
) loop
27636 Body_Ref
:= Node
(Body_Ref_Elmt
);
27638 SPARK_Msg_N
("reference to & not allowed", Body_Ref
);
27639 Error_Msg_Sloc
:= Sloc
(State
);
27640 SPARK_Msg_N
("\refinement of & is visible#", Body_Ref
);
27642 Next_Elmt
(Body_Ref_Elmt
);
27646 -- The state name is illegal. This is a syntax error, always report.
27649 Error_Msg_N
("malformed state name in refinement clause", State
);
27653 -- A refinement clause may only refine one state at a time
27655 Extra_State
:= Next
(State
);
27657 if Present
(Extra_State
) then
27659 ("refinement clause cannot cover multiple states", Extra_State
);
27662 -- Replicate the Part_Of constituents of the refined state because
27663 -- the algorithm will consume items.
27665 Part_Of_Constits
:= New_Copy_Elist
(Part_Of_Constituents
(State_Id
));
27667 -- Analyze all constituents of the refinement. Multiple constituents
27668 -- appear as an aggregate.
27670 Constit
:= Expression
(Clause
);
27672 if Nkind
(Constit
) = N_Aggregate
then
27673 if Present
(Component_Associations
(Constit
)) then
27675 ("constituents of refinement clause must appear in "
27676 & "positional form", Constit
);
27678 else pragma Assert
(Present
(Expressions
(Constit
)));
27679 Constit
:= First
(Expressions
(Constit
));
27680 while Present
(Constit
) loop
27681 Analyze_Constituent
(Constit
);
27686 -- Various forms of a single constituent. Note that these may include
27687 -- malformed constituents.
27690 Analyze_Constituent
(Constit
);
27693 -- Verify that external constituents do not introduce new external
27694 -- property in the state refinement (SPARK RM 7.2.8(2)).
27696 if Is_External_State
(State_Id
) then
27697 Check_External_Property
27698 (Prop_Nam
=> Name_Async_Readers
,
27699 Enabled
=> Async_Readers_Enabled
(State_Id
),
27700 Constit
=> AR_Constit
);
27702 Check_External_Property
27703 (Prop_Nam
=> Name_Async_Writers
,
27704 Enabled
=> Async_Writers_Enabled
(State_Id
),
27705 Constit
=> AW_Constit
);
27707 Check_External_Property
27708 (Prop_Nam
=> Name_Effective_Reads
,
27709 Enabled
=> Effective_Reads_Enabled
(State_Id
),
27710 Constit
=> ER_Constit
);
27712 Check_External_Property
27713 (Prop_Nam
=> Name_Effective_Writes
,
27714 Enabled
=> Effective_Writes_Enabled
(State_Id
),
27715 Constit
=> EW_Constit
);
27717 -- When a refined state is not external, it should not have external
27718 -- constituents (SPARK RM 7.2.8(1)).
27720 elsif External_Constit_Seen
then
27722 ("non-external state & cannot contain external constituents in "
27723 & "refinement", State
, State_Id
);
27726 -- Ensure that all Part_Of candidate constituents have been mentioned
27727 -- in the refinement clause.
27729 Report_Unused_Constituents
(Part_Of_Constits
);
27730 end Analyze_Refinement_Clause
;
27732 -----------------------------
27733 -- Report_Unrefined_States --
27734 -----------------------------
27736 procedure Report_Unrefined_States
(States
: Elist_Id
) is
27737 State_Elmt
: Elmt_Id
;
27740 if Present
(States
) then
27741 State_Elmt
:= First_Elmt
(States
);
27742 while Present
(State_Elmt
) loop
27744 ("abstract state & must be refined", Node
(State_Elmt
));
27746 Next_Elmt
(State_Elmt
);
27749 end Report_Unrefined_States
;
27751 -- Local declarations
27753 Clauses
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
27756 -- Start of processing for Analyze_Refined_State_In_Decl_Part
27759 -- Do not analyze the pragma multiple times
27761 if Is_Analyzed_Pragma
(N
) then
27765 -- Save the scenario for examination by the ABE Processing phase
27767 Record_Elaboration_Scenario
(N
);
27769 -- Replicate the abstract states declared by the package because the
27770 -- matching algorithm will consume states.
27772 Available_States
:= New_Copy_Elist
(Abstract_States
(Spec_Id
));
27774 -- Gather all abstract states and objects declared in the visible
27775 -- state space of the package body. These items must be utilized as
27776 -- constituents in a state refinement.
27778 Body_States
:= Collect_Body_States
(Body_Id
);
27780 -- Multiple non-null state refinements appear as an aggregate
27782 if Nkind
(Clauses
) = N_Aggregate
then
27783 if Present
(Expressions
(Clauses
)) then
27785 ("state refinements must appear as component associations",
27788 else pragma Assert
(Present
(Component_Associations
(Clauses
)));
27789 Clause
:= First
(Component_Associations
(Clauses
));
27790 while Present
(Clause
) loop
27791 Analyze_Refinement_Clause
(Clause
);
27796 -- Various forms of a single state refinement. Note that these may
27797 -- include malformed refinements.
27800 Analyze_Refinement_Clause
(Clauses
);
27803 -- List all abstract states that were left unrefined
27805 Report_Unrefined_States
(Available_States
);
27807 Set_Is_Analyzed_Pragma
(N
);
27808 end Analyze_Refined_State_In_Decl_Part
;
27810 ------------------------------------
27811 -- Analyze_Test_Case_In_Decl_Part --
27812 ------------------------------------
27814 procedure Analyze_Test_Case_In_Decl_Part
(N
: Node_Id
) is
27815 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
27816 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
27818 procedure Preanalyze_Test_Case_Arg
(Arg_Nam
: Name_Id
);
27819 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
27820 -- denoted by Arg_Nam.
27822 ------------------------------
27823 -- Preanalyze_Test_Case_Arg --
27824 ------------------------------
27826 procedure Preanalyze_Test_Case_Arg
(Arg_Nam
: Name_Id
) is
27830 -- Preanalyze the original aspect argument for ASIS or for a generic
27831 -- subprogram to properly capture global references.
27833 if ASIS_Mode
or else Is_Generic_Subprogram
(Spec_Id
) then
27837 Arg_Nam
=> Arg_Nam
,
27838 From_Aspect
=> True);
27840 if Present
(Arg
) then
27841 Preanalyze_Assert_Expression
27842 (Expression
(Arg
), Standard_Boolean
);
27846 Arg
:= Test_Case_Arg
(N
, Arg_Nam
);
27848 if Present
(Arg
) then
27849 Preanalyze_Assert_Expression
(Expression
(Arg
), Standard_Boolean
);
27851 end Preanalyze_Test_Case_Arg
;
27855 Restore_Scope
: Boolean := False;
27857 -- Start of processing for Analyze_Test_Case_In_Decl_Part
27860 -- Do not analyze the pragma multiple times
27862 if Is_Analyzed_Pragma
(N
) then
27866 -- Ensure that the formal parameters are visible when analyzing all
27867 -- clauses. This falls out of the general rule of aspects pertaining
27868 -- to subprogram declarations.
27870 if not In_Open_Scopes
(Spec_Id
) then
27871 Restore_Scope
:= True;
27872 Push_Scope
(Spec_Id
);
27874 if Is_Generic_Subprogram
(Spec_Id
) then
27875 Install_Generic_Formals
(Spec_Id
);
27877 Install_Formals
(Spec_Id
);
27881 Preanalyze_Test_Case_Arg
(Name_Requires
);
27882 Preanalyze_Test_Case_Arg
(Name_Ensures
);
27884 if Restore_Scope
then
27888 -- Currently it is not possible to inline pre/postconditions on a
27889 -- subprogram subject to pragma Inline_Always.
27891 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
27893 Set_Is_Analyzed_Pragma
(N
);
27894 end Analyze_Test_Case_In_Decl_Part
;
27900 function Appears_In
(List
: Elist_Id
; Item_Id
: Entity_Id
) return Boolean is
27905 if Present
(List
) then
27906 Elmt
:= First_Elmt
(List
);
27907 while Present
(Elmt
) loop
27908 if Nkind
(Node
(Elmt
)) = N_Defining_Identifier
then
27911 Id
:= Entity_Of
(Node
(Elmt
));
27914 if Id
= Item_Id
then
27925 -----------------------------------
27926 -- Build_Pragma_Check_Equivalent --
27927 -----------------------------------
27929 function Build_Pragma_Check_Equivalent
27931 Subp_Id
: Entity_Id
:= Empty
;
27932 Inher_Id
: Entity_Id
:= Empty
;
27933 Keep_Pragma_Id
: Boolean := False) return Node_Id
27935 function Suppress_Reference
(N
: Node_Id
) return Traverse_Result
;
27936 -- Detect whether node N references a formal parameter subject to
27937 -- pragma Unreferenced. If this is the case, set Comes_From_Source
27938 -- to False to suppress the generation of a reference when analyzing
27941 ------------------------
27942 -- Suppress_Reference --
27943 ------------------------
27945 function Suppress_Reference
(N
: Node_Id
) return Traverse_Result
is
27946 Formal
: Entity_Id
;
27949 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
27950 Formal
:= Entity
(N
);
27952 -- The formal parameter is subject to pragma Unreferenced. Prevent
27953 -- the generation of references by resetting the Comes_From_Source
27956 if Is_Formal
(Formal
)
27957 and then Has_Pragma_Unreferenced
(Formal
)
27959 Set_Comes_From_Source
(N
, False);
27964 end Suppress_Reference
;
27966 procedure Suppress_References
is
27967 new Traverse_Proc
(Suppress_Reference
);
27971 Loc
: constant Source_Ptr
:= Sloc
(Prag
);
27972 Prag_Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
27973 Check_Prag
: Node_Id
;
27977 Needs_Wrapper
: Boolean;
27978 pragma Unreferenced
(Needs_Wrapper
);
27980 -- Start of processing for Build_Pragma_Check_Equivalent
27983 -- When the pre- or postcondition is inherited, map the formals of the
27984 -- inherited subprogram to those of the current subprogram. In addition,
27985 -- map primitive operations of the parent type into the corresponding
27986 -- primitive operations of the descendant.
27988 if Present
(Inher_Id
) then
27989 pragma Assert
(Present
(Subp_Id
));
27991 Update_Primitives_Mapping
(Inher_Id
, Subp_Id
);
27993 -- Use generic machinery to copy inherited pragma, as if it were an
27994 -- instantiation, resetting source locations appropriately, so that
27995 -- expressions inside the inherited pragma use chained locations.
27996 -- This is used in particular in GNATprove to locate precisely
27997 -- messages on a given inherited pragma.
27999 Set_Copied_Sloc_For_Inherited_Pragma
28000 (Unit_Declaration_Node
(Subp_Id
), Inher_Id
);
28001 Check_Prag
:= New_Copy_Tree
(Source
=> Prag
);
28003 -- Build the inherited class-wide condition
28005 Build_Class_Wide_Expression
28006 (Prag
=> Check_Prag
,
28008 Par_Subp
=> Inher_Id
,
28009 Adjust_Sloc
=> True,
28010 Needs_Wrapper
=> Needs_Wrapper
);
28012 -- If not an inherited condition simply copy the original pragma
28015 Check_Prag
:= New_Copy_Tree
(Source
=> Prag
);
28018 -- Mark the pragma as being internally generated and reset the Analyzed
28021 Set_Analyzed
(Check_Prag
, False);
28022 Set_Comes_From_Source
(Check_Prag
, False);
28024 -- The tree of the original pragma may contain references to the
28025 -- formal parameters of the related subprogram. At the same time
28026 -- the corresponding body may mark the formals as unreferenced:
28028 -- procedure Proc (Formal : ...)
28029 -- with Pre => Formal ...;
28031 -- procedure Proc (Formal : ...) is
28032 -- pragma Unreferenced (Formal);
28035 -- This creates problems because all pragma Check equivalents are
28036 -- analyzed at the end of the body declarations. Since all source
28037 -- references have already been accounted for, reset any references
28038 -- to such formals in the generated pragma Check equivalent.
28040 Suppress_References
(Check_Prag
);
28042 if Present
(Corresponding_Aspect
(Prag
)) then
28043 Nam
:= Chars
(Identifier
(Corresponding_Aspect
(Prag
)));
28048 -- Unless Keep_Pragma_Id is True in order to keep the identifier of
28049 -- the copied pragma in the newly created pragma, convert the copy into
28050 -- pragma Check by correcting the name and adding a check_kind argument.
28052 if not Keep_Pragma_Id
then
28053 Set_Class_Present
(Check_Prag
, False);
28055 Set_Pragma_Identifier
28056 (Check_Prag
, Make_Identifier
(Loc
, Name_Check
));
28058 Prepend_To
(Pragma_Argument_Associations
(Check_Prag
),
28059 Make_Pragma_Argument_Association
(Loc
,
28060 Expression
=> Make_Identifier
(Loc
, Nam
)));
28063 -- Update the error message when the pragma is inherited
28065 if Present
(Inher_Id
) then
28066 Msg_Arg
:= Last
(Pragma_Argument_Associations
(Check_Prag
));
28068 if Chars
(Msg_Arg
) = Name_Message
then
28069 String_To_Name_Buffer
(Strval
(Expression
(Msg_Arg
)));
28071 -- Insert "inherited" to improve the error message
28073 if Name_Buffer
(1 .. 8) = "failed p" then
28074 Insert_Str_In_Name_Buffer
("inherited ", 8);
28075 Set_Strval
(Expression
(Msg_Arg
), String_From_Name_Buffer
);
28081 end Build_Pragma_Check_Equivalent
;
28083 -----------------------------
28084 -- Check_Applicable_Policy --
28085 -----------------------------
28087 procedure Check_Applicable_Policy
(N
: Node_Id
) is
28091 Ename
: constant Name_Id
:= Original_Aspect_Pragma_Name
(N
);
28094 -- No effect if not valid assertion kind name
28096 if not Is_Valid_Assertion_Kind
(Ename
) then
28100 -- Loop through entries in check policy list
28102 PP
:= Opt
.Check_Policy_List
;
28103 while Present
(PP
) loop
28105 PPA
: constant List_Id
:= Pragma_Argument_Associations
(PP
);
28106 Pnm
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(PPA
)));
28110 or else Pnm
= Name_Assertion
28111 or else (Pnm
= Name_Statement_Assertions
28112 and then Nam_In
(Ename
, Name_Assert
,
28113 Name_Assert_And_Cut
,
28115 Name_Loop_Invariant
,
28116 Name_Loop_Variant
))
28118 Policy
:= Chars
(Get_Pragma_Arg
(Last
(PPA
)));
28124 Set_Is_Ignored
(N
, True);
28125 Set_Is_Checked
(N
, False);
28130 Set_Is_Checked
(N
, True);
28131 Set_Is_Ignored
(N
, False);
28133 when Name_Disable
=>
28134 Set_Is_Ignored
(N
, True);
28135 Set_Is_Checked
(N
, False);
28136 Set_Is_Disabled
(N
, True);
28138 -- That should be exhaustive, the null here is a defence
28139 -- against a malformed tree from previous errors.
28148 PP
:= Next_Pragma
(PP
);
28152 -- If there are no specific entries that matched, then we let the
28153 -- setting of assertions govern. Note that this provides the needed
28154 -- compatibility with the RM for the cases of assertion, invariant,
28155 -- precondition, predicate, and postcondition.
28157 if Assertions_Enabled
then
28158 Set_Is_Checked
(N
, True);
28159 Set_Is_Ignored
(N
, False);
28161 Set_Is_Checked
(N
, False);
28162 Set_Is_Ignored
(N
, True);
28164 end Check_Applicable_Policy
;
28166 -------------------------------
28167 -- Check_External_Properties --
28168 -------------------------------
28170 procedure Check_External_Properties
28178 -- All properties enabled
28180 if AR
and AW
and ER
and EW
then
28183 -- Async_Readers + Effective_Writes
28184 -- Async_Readers + Async_Writers + Effective_Writes
28186 elsif AR
and EW
and not ER
then
28189 -- Async_Writers + Effective_Reads
28190 -- Async_Readers + Async_Writers + Effective_Reads
28192 elsif AW
and ER
and not EW
then
28195 -- Async_Readers + Async_Writers
28197 elsif AR
and AW
and not ER
and not EW
then
28202 elsif AR
and not AW
and not ER
and not EW
then
28207 elsif AW
and not AR
and not ER
and not EW
then
28212 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
28215 end Check_External_Properties
;
28221 function Check_Kind
(Nam
: Name_Id
) return Name_Id
is
28225 -- Loop through entries in check policy list
28227 PP
:= Opt
.Check_Policy_List
;
28228 while Present
(PP
) loop
28230 PPA
: constant List_Id
:= Pragma_Argument_Associations
(PP
);
28231 Pnm
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(PPA
)));
28235 or else (Pnm
= Name_Assertion
28236 and then Is_Valid_Assertion_Kind
(Nam
))
28237 or else (Pnm
= Name_Statement_Assertions
28238 and then Nam_In
(Nam
, Name_Assert
,
28239 Name_Assert_And_Cut
,
28241 Name_Loop_Invariant
,
28242 Name_Loop_Variant
))
28244 case (Chars
(Get_Pragma_Arg
(Last
(PPA
)))) is
28253 return Name_Ignore
;
28255 when Name_Disable
=>
28256 return Name_Disable
;
28259 raise Program_Error
;
28263 PP
:= Next_Pragma
(PP
);
28268 -- If there are no specific entries that matched, then we let the
28269 -- setting of assertions govern. Note that this provides the needed
28270 -- compatibility with the RM for the cases of assertion, invariant,
28271 -- precondition, predicate, and postcondition.
28273 if Assertions_Enabled
then
28276 return Name_Ignore
;
28280 ---------------------------
28281 -- Check_Missing_Part_Of --
28282 ---------------------------
28284 procedure Check_Missing_Part_Of
(Item_Id
: Entity_Id
) is
28285 function Has_Visible_State
(Pack_Id
: Entity_Id
) return Boolean;
28286 -- Determine whether a package denoted by Pack_Id declares at least one
28289 -----------------------
28290 -- Has_Visible_State --
28291 -----------------------
28293 function Has_Visible_State
(Pack_Id
: Entity_Id
) return Boolean is
28294 Item_Id
: Entity_Id
;
28297 -- Traverse the entity chain of the package trying to find at least
28298 -- one visible abstract state, variable or a package [instantiation]
28299 -- that declares a visible state.
28301 Item_Id
:= First_Entity
(Pack_Id
);
28302 while Present
(Item_Id
)
28303 and then not In_Private_Part
(Item_Id
)
28305 -- Do not consider internally generated items
28307 if not Comes_From_Source
(Item_Id
) then
28310 -- A visible state has been found
28312 elsif Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
) then
28315 -- Recursively peek into nested packages and instantiations
28317 elsif Ekind
(Item_Id
) = E_Package
28318 and then Has_Visible_State
(Item_Id
)
28323 Next_Entity
(Item_Id
);
28327 end Has_Visible_State
;
28331 Pack_Id
: Entity_Id
;
28332 Placement
: State_Space_Kind
;
28334 -- Start of processing for Check_Missing_Part_Of
28337 -- Do not consider abstract states, variables or package instantiations
28338 -- coming from an instance as those always inherit the Part_Of indicator
28339 -- of the instance itself.
28341 if In_Instance
then
28344 -- Do not consider internally generated entities as these can never
28345 -- have a Part_Of indicator.
28347 elsif not Comes_From_Source
(Item_Id
) then
28350 -- Perform these checks only when SPARK_Mode is enabled as they will
28351 -- interfere with standard Ada rules and produce false positives.
28353 elsif SPARK_Mode
/= On
then
28356 -- Do not consider constants, because the compiler cannot accurately
28357 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
28358 -- act as a hidden state of a package.
28360 elsif Ekind
(Item_Id
) = E_Constant
then
28364 -- Find where the abstract state, variable or package instantiation
28365 -- lives with respect to the state space.
28367 Find_Placement_In_State_Space
28368 (Item_Id
=> Item_Id
,
28369 Placement
=> Placement
,
28370 Pack_Id
=> Pack_Id
);
28372 -- Items that appear in a non-package construct (subprogram, block, etc)
28373 -- do not require a Part_Of indicator because they can never act as a
28376 if Placement
= Not_In_Package
then
28379 -- An item declared in the body state space of a package always act as a
28380 -- constituent and does not need explicit Part_Of indicator.
28382 elsif Placement
= Body_State_Space
then
28385 -- In general an item declared in the visible state space of a package
28386 -- does not require a Part_Of indicator. The only exception is when the
28387 -- related package is a private child unit in which case Part_Of must
28388 -- denote a state in the parent unit or in one of its descendants.
28390 elsif Placement
= Visible_State_Space
then
28391 if Is_Child_Unit
(Pack_Id
)
28392 and then Is_Private_Descendant
(Pack_Id
)
28394 -- A package instantiation does not need a Part_Of indicator when
28395 -- the related generic template has no visible state.
28397 if Ekind
(Item_Id
) = E_Package
28398 and then Is_Generic_Instance
(Item_Id
)
28399 and then not Has_Visible_State
(Item_Id
)
28403 -- All other cases require Part_Of
28407 ("indicator Part_Of is required in this context "
28408 & "(SPARK RM 7.2.6(3))", Item_Id
);
28409 Error_Msg_Name_1
:= Chars
(Pack_Id
);
28411 ("\& is declared in the visible part of private child "
28412 & "unit %", Item_Id
);
28416 -- When the item appears in the private state space of a package, it
28417 -- must be a part of some state declared by the said package.
28419 else pragma Assert
(Placement
= Private_State_Space
);
28421 -- The related package does not declare a state, the item cannot act
28422 -- as a Part_Of constituent.
28424 if No
(Get_Pragma
(Pack_Id
, Pragma_Abstract_State
)) then
28427 -- A package instantiation does not need a Part_Of indicator when the
28428 -- related generic template has no visible state.
28430 elsif Ekind
(Pack_Id
) = E_Package
28431 and then Is_Generic_Instance
(Pack_Id
)
28432 and then not Has_Visible_State
(Pack_Id
)
28436 -- All other cases require Part_Of
28440 ("indicator Part_Of is required in this context "
28441 & "(SPARK RM 7.2.6(2))", Item_Id
);
28442 Error_Msg_Name_1
:= Chars
(Pack_Id
);
28444 ("\& is declared in the private part of package %", Item_Id
);
28447 end Check_Missing_Part_Of
;
28449 ---------------------------------------------------
28450 -- Check_Postcondition_Use_In_Inlined_Subprogram --
28451 ---------------------------------------------------
28453 procedure Check_Postcondition_Use_In_Inlined_Subprogram
28455 Spec_Id
: Entity_Id
)
28458 if Warn_On_Redundant_Constructs
28459 and then Has_Pragma_Inline_Always
(Spec_Id
)
28460 and then Assertions_Enabled
28462 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Prag
);
28464 if From_Aspect_Specification
(Prag
) then
28466 ("aspect % not enforced on inlined subprogram &?r?",
28467 Corresponding_Aspect
(Prag
), Spec_Id
);
28470 ("pragma % not enforced on inlined subprogram &?r?",
28474 end Check_Postcondition_Use_In_Inlined_Subprogram
;
28476 -------------------------------------
28477 -- Check_State_And_Constituent_Use --
28478 -------------------------------------
28480 procedure Check_State_And_Constituent_Use
28481 (States
: Elist_Id
;
28482 Constits
: Elist_Id
;
28485 Constit_Elmt
: Elmt_Id
;
28486 Constit_Id
: Entity_Id
;
28487 State_Id
: Entity_Id
;
28490 -- Nothing to do if there are no states or constituents
28492 if No
(States
) or else No
(Constits
) then
28496 -- Inspect the list of constituents and try to determine whether its
28497 -- encapsulating state is in list States.
28499 Constit_Elmt
:= First_Elmt
(Constits
);
28500 while Present
(Constit_Elmt
) loop
28501 Constit_Id
:= Node
(Constit_Elmt
);
28503 -- Determine whether the constituent is part of an encapsulating
28504 -- state that appears in the same context and if this is the case,
28505 -- emit an error (SPARK RM 7.2.6(7)).
28507 State_Id
:= Find_Encapsulating_State
(States
, Constit_Id
);
28509 if Present
(State_Id
) then
28510 Error_Msg_Name_1
:= Chars
(Constit_Id
);
28512 ("cannot mention state & and its constituent % in the same "
28513 & "context", Context
, State_Id
);
28517 Next_Elmt
(Constit_Elmt
);
28519 end Check_State_And_Constituent_Use
;
28521 ---------------------------------------------
28522 -- Collect_Inherited_Class_Wide_Conditions --
28523 ---------------------------------------------
28525 procedure Collect_Inherited_Class_Wide_Conditions
(Subp
: Entity_Id
) is
28526 Parent_Subp
: constant Entity_Id
:=
28527 Ultimate_Alias
(Overridden_Operation
(Subp
));
28528 -- The Overridden_Operation may itself be inherited and as such have no
28529 -- explicit contract.
28531 Prags
: constant Node_Id
:= Contract
(Parent_Subp
);
28532 In_Spec_Expr
: Boolean;
28533 Installed
: Boolean;
28535 New_Prag
: Node_Id
;
28538 Installed
:= False;
28540 -- Iterate over the contract of the overridden subprogram to find all
28541 -- inherited class-wide pre- and postconditions.
28543 if Present
(Prags
) then
28544 Prag
:= Pre_Post_Conditions
(Prags
);
28546 while Present
(Prag
) loop
28547 if Nam_In
(Pragma_Name_Unmapped
(Prag
),
28548 Name_Precondition
, Name_Postcondition
)
28549 and then Class_Present
(Prag
)
28551 -- The generated pragma must be analyzed in the context of
28552 -- the subprogram, to make its formals visible. In addition,
28553 -- we must inhibit freezing and full analysis because the
28554 -- controlling type of the subprogram is not frozen yet, and
28555 -- may have further primitives.
28557 if not Installed
then
28560 Install_Formals
(Subp
);
28561 In_Spec_Expr
:= In_Spec_Expression
;
28562 In_Spec_Expression
:= True;
28566 Build_Pragma_Check_Equivalent
28567 (Prag
, Subp
, Parent_Subp
, Keep_Pragma_Id
=> True);
28569 Insert_After
(Unit_Declaration_Node
(Subp
), New_Prag
);
28570 Preanalyze
(New_Prag
);
28572 -- Prevent further analysis in subsequent processing of the
28573 -- current list of declarations
28575 Set_Analyzed
(New_Prag
);
28578 Prag
:= Next_Pragma
(Prag
);
28582 In_Spec_Expression
:= In_Spec_Expr
;
28586 end Collect_Inherited_Class_Wide_Conditions
;
28588 ---------------------------------------
28589 -- Collect_Subprogram_Inputs_Outputs --
28590 ---------------------------------------
28592 procedure Collect_Subprogram_Inputs_Outputs
28593 (Subp_Id
: Entity_Id
;
28594 Synthesize
: Boolean := False;
28595 Subp_Inputs
: in out Elist_Id
;
28596 Subp_Outputs
: in out Elist_Id
;
28597 Global_Seen
: out Boolean)
28599 procedure Collect_Dependency_Clause
(Clause
: Node_Id
);
28600 -- Collect all relevant items from a dependency clause
28602 procedure Collect_Global_List
28604 Mode
: Name_Id
:= Name_Input
);
28605 -- Collect all relevant items from a global list
28607 -------------------------------
28608 -- Collect_Dependency_Clause --
28609 -------------------------------
28611 procedure Collect_Dependency_Clause
(Clause
: Node_Id
) is
28612 procedure Collect_Dependency_Item
28614 Is_Input
: Boolean);
28615 -- Add an item to the proper subprogram input or output collection
28617 -----------------------------
28618 -- Collect_Dependency_Item --
28619 -----------------------------
28621 procedure Collect_Dependency_Item
28623 Is_Input
: Boolean)
28628 -- Nothing to collect when the item is null
28630 if Nkind
(Item
) = N_Null
then
28633 -- Ditto for attribute 'Result
28635 elsif Is_Attribute_Result
(Item
) then
28638 -- Multiple items appear as an aggregate
28640 elsif Nkind
(Item
) = N_Aggregate
then
28641 Extra
:= First
(Expressions
(Item
));
28642 while Present
(Extra
) loop
28643 Collect_Dependency_Item
(Extra
, Is_Input
);
28647 -- Otherwise this is a solitary item
28651 Append_New_Elmt
(Item
, Subp_Inputs
);
28653 Append_New_Elmt
(Item
, Subp_Outputs
);
28656 end Collect_Dependency_Item
;
28658 -- Start of processing for Collect_Dependency_Clause
28661 if Nkind
(Clause
) = N_Null
then
28664 -- A dependency clause appears as component association
28666 elsif Nkind
(Clause
) = N_Component_Association
then
28667 Collect_Dependency_Item
28668 (Item
=> Expression
(Clause
),
28671 Collect_Dependency_Item
28672 (Item
=> First
(Choices
(Clause
)),
28673 Is_Input
=> False);
28675 -- To accommodate partial decoration of disabled SPARK features, this
28676 -- routine may be called with illegal input. If this is the case, do
28677 -- not raise Program_Error.
28682 end Collect_Dependency_Clause
;
28684 -------------------------
28685 -- Collect_Global_List --
28686 -------------------------
28688 procedure Collect_Global_List
28690 Mode
: Name_Id
:= Name_Input
)
28692 procedure Collect_Global_Item
(Item
: Node_Id
; Mode
: Name_Id
);
28693 -- Add an item to the proper subprogram input or output collection
28695 -------------------------
28696 -- Collect_Global_Item --
28697 -------------------------
28699 procedure Collect_Global_Item
(Item
: Node_Id
; Mode
: Name_Id
) is
28701 if Nam_In
(Mode
, Name_In_Out
, Name_Input
) then
28702 Append_New_Elmt
(Item
, Subp_Inputs
);
28705 if Nam_In
(Mode
, Name_In_Out
, Name_Output
) then
28706 Append_New_Elmt
(Item
, Subp_Outputs
);
28708 end Collect_Global_Item
;
28715 -- Start of processing for Collect_Global_List
28718 if Nkind
(List
) = N_Null
then
28721 -- Single global item declaration
28723 elsif Nkind_In
(List
, N_Expanded_Name
,
28725 N_Selected_Component
)
28727 Collect_Global_Item
(List
, Mode
);
28729 -- Simple global list or moded global list declaration
28731 elsif Nkind
(List
) = N_Aggregate
then
28732 if Present
(Expressions
(List
)) then
28733 Item
:= First
(Expressions
(List
));
28734 while Present
(Item
) loop
28735 Collect_Global_Item
(Item
, Mode
);
28740 Assoc
:= First
(Component_Associations
(List
));
28741 while Present
(Assoc
) loop
28742 Collect_Global_List
28743 (List
=> Expression
(Assoc
),
28744 Mode
=> Chars
(First
(Choices
(Assoc
))));
28749 -- To accommodate partial decoration of disabled SPARK features, this
28750 -- routine may be called with illegal input. If this is the case, do
28751 -- not raise Program_Error.
28756 end Collect_Global_List
;
28763 Formal
: Entity_Id
;
28765 Spec_Id
: Entity_Id
:= Empty
;
28766 Subp_Decl
: Node_Id
;
28769 -- Start of processing for Collect_Subprogram_Inputs_Outputs
28772 Global_Seen
:= False;
28774 -- Process all formal parameters of entries, [generic] subprograms, and
28777 if Ekind_In
(Subp_Id
, E_Entry
,
28780 E_Generic_Function
,
28781 E_Generic_Procedure
,
28785 Subp_Decl
:= Unit_Declaration_Node
(Subp_Id
);
28786 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
28788 -- Process all formal parameters
28790 Formal
:= First_Entity
(Spec_Id
);
28791 while Present
(Formal
) loop
28792 if Ekind_In
(Formal
, E_In_Out_Parameter
, E_In_Parameter
) then
28793 Append_New_Elmt
(Formal
, Subp_Inputs
);
28796 if Ekind_In
(Formal
, E_In_Out_Parameter
, E_Out_Parameter
) then
28797 Append_New_Elmt
(Formal
, Subp_Outputs
);
28799 -- Out parameters can act as inputs when the related type is
28800 -- tagged, unconstrained array, unconstrained record, or record
28801 -- with unconstrained components.
28803 if Ekind
(Formal
) = E_Out_Parameter
28804 and then Is_Unconstrained_Or_Tagged_Item
(Formal
)
28806 Append_New_Elmt
(Formal
, Subp_Inputs
);
28810 Next_Entity
(Formal
);
28813 -- Otherwise the input denotes a task type, a task body, or the
28814 -- anonymous object created for a single task type.
28816 elsif Ekind_In
(Subp_Id
, E_Task_Type
, E_Task_Body
)
28817 or else Is_Single_Task_Object
(Subp_Id
)
28819 Subp_Decl
:= Declaration_Node
(Subp_Id
);
28820 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
28823 -- When processing an entry, subprogram or task body, look for pragmas
28824 -- Refined_Depends and Refined_Global as they specify the inputs and
28827 if Is_Entry_Body
(Subp_Id
)
28828 or else Ekind_In
(Subp_Id
, E_Subprogram_Body
, E_Task_Body
)
28830 Depends
:= Get_Pragma
(Subp_Id
, Pragma_Refined_Depends
);
28831 Global
:= Get_Pragma
(Subp_Id
, Pragma_Refined_Global
);
28833 -- Subprogram declaration or stand-alone body case, look for pragmas
28834 -- Depends and Global
28837 Depends
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
28838 Global
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
28841 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
28842 -- because it provides finer granularity of inputs and outputs.
28844 if Present
(Global
) then
28845 Global_Seen
:= True;
28846 Collect_Global_List
(Expression
(Get_Argument
(Global
, Spec_Id
)));
28848 -- When the related subprogram lacks pragma [Refined_]Global, fall back
28849 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
28850 -- the inputs and outputs from [Refined_]Depends.
28852 elsif Synthesize
and then Present
(Depends
) then
28853 Clauses
:= Expression
(Get_Argument
(Depends
, Spec_Id
));
28855 -- Multiple dependency clauses appear as an aggregate
28857 if Nkind
(Clauses
) = N_Aggregate
then
28858 Clause
:= First
(Component_Associations
(Clauses
));
28859 while Present
(Clause
) loop
28860 Collect_Dependency_Clause
(Clause
);
28864 -- Otherwise this is a single dependency clause
28867 Collect_Dependency_Clause
(Clauses
);
28871 -- The current instance of a protected type acts as a formal parameter
28872 -- of mode IN for functions and IN OUT for entries and procedures
28873 -- (SPARK RM 6.1.4).
28875 if Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
28876 Typ
:= Scope
(Spec_Id
);
28878 -- Use the anonymous object when the type is single protected
28880 if Is_Single_Concurrent_Type_Declaration
(Declaration_Node
(Typ
)) then
28881 Typ
:= Anonymous_Object
(Typ
);
28884 Append_New_Elmt
(Typ
, Subp_Inputs
);
28886 if Ekind_In
(Spec_Id
, E_Entry
, E_Entry_Family
, E_Procedure
) then
28887 Append_New_Elmt
(Typ
, Subp_Outputs
);
28890 -- The current instance of a task type acts as a formal parameter of
28891 -- mode IN OUT (SPARK RM 6.1.4).
28893 elsif Ekind
(Spec_Id
) = E_Task_Type
then
28896 -- Use the anonymous object when the type is single task
28898 if Is_Single_Concurrent_Type_Declaration
(Declaration_Node
(Typ
)) then
28899 Typ
:= Anonymous_Object
(Typ
);
28902 Append_New_Elmt
(Typ
, Subp_Inputs
);
28903 Append_New_Elmt
(Typ
, Subp_Outputs
);
28905 elsif Is_Single_Task_Object
(Spec_Id
) then
28906 Append_New_Elmt
(Spec_Id
, Subp_Inputs
);
28907 Append_New_Elmt
(Spec_Id
, Subp_Outputs
);
28909 end Collect_Subprogram_Inputs_Outputs
;
28911 ---------------------------
28912 -- Contract_Freeze_Error --
28913 ---------------------------
28915 procedure Contract_Freeze_Error
28916 (Contract_Id
: Entity_Id
;
28917 Freeze_Id
: Entity_Id
)
28920 Error_Msg_Name_1
:= Chars
(Contract_Id
);
28921 Error_Msg_Sloc
:= Sloc
(Freeze_Id
);
28924 ("body & declared # freezes the contract of%", Contract_Id
, Freeze_Id
);
28926 ("\all contractual items must be declared before body #", Contract_Id
);
28927 end Contract_Freeze_Error
;
28929 ---------------------------------
28930 -- Delay_Config_Pragma_Analyze --
28931 ---------------------------------
28933 function Delay_Config_Pragma_Analyze
(N
: Node_Id
) return Boolean is
28935 return Nam_In
(Pragma_Name_Unmapped
(N
),
28936 Name_Interrupt_State
, Name_Priority_Specific_Dispatching
);
28937 end Delay_Config_Pragma_Analyze
;
28939 -----------------------
28940 -- Duplication_Error --
28941 -----------------------
28943 procedure Duplication_Error
(Prag
: Node_Id
; Prev
: Node_Id
) is
28944 Prag_From_Asp
: constant Boolean := From_Aspect_Specification
(Prag
);
28945 Prev_From_Asp
: constant Boolean := From_Aspect_Specification
(Prev
);
28948 Error_Msg_Sloc
:= Sloc
(Prev
);
28949 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Prag
);
28951 -- Emit a precise message to distinguish between source pragmas and
28952 -- pragmas generated from aspects. The ordering of the two pragmas is
28956 -- Prag -- duplicate
28958 -- No error is emitted when both pragmas come from aspects because this
28959 -- is already detected by the general aspect analysis mechanism.
28961 if Prag_From_Asp
and Prev_From_Asp
then
28963 elsif Prag_From_Asp
then
28964 Error_Msg_N
("aspect % duplicates pragma declared #", Prag
);
28965 elsif Prev_From_Asp
then
28966 Error_Msg_N
("pragma % duplicates aspect declared #", Prag
);
28968 Error_Msg_N
("pragma % duplicates pragma declared #", Prag
);
28970 end Duplication_Error
;
28972 ------------------------------
28973 -- Find_Encapsulating_State --
28974 ------------------------------
28976 function Find_Encapsulating_State
28977 (States
: Elist_Id
;
28978 Constit_Id
: Entity_Id
) return Entity_Id
28980 State_Id
: Entity_Id
;
28983 -- Since a constituent may be part of a larger constituent set, climb
28984 -- the encapsulating state chain looking for a state that appears in
28987 State_Id
:= Encapsulating_State
(Constit_Id
);
28988 while Present
(State_Id
) loop
28989 if Contains
(States
, State_Id
) then
28993 State_Id
:= Encapsulating_State
(State_Id
);
28997 end Find_Encapsulating_State
;
28999 --------------------------
29000 -- Find_Related_Context --
29001 --------------------------
29003 function Find_Related_Context
29005 Do_Checks
: Boolean := False) return Node_Id
29010 Stmt
:= Prev
(Prag
);
29011 while Present
(Stmt
) loop
29013 -- Skip prior pragmas, but check for duplicates
29015 if Nkind
(Stmt
) = N_Pragma
then
29017 and then Pragma_Name
(Stmt
) = Pragma_Name
(Prag
)
29024 -- Skip internally generated code
29026 elsif not Comes_From_Source
(Stmt
) then
29028 -- The anonymous object created for a single concurrent type is a
29029 -- suitable context.
29031 if Nkind
(Stmt
) = N_Object_Declaration
29032 and then Is_Single_Concurrent_Object
(Defining_Entity
(Stmt
))
29037 -- Return the current source construct
29047 end Find_Related_Context
;
29049 --------------------------------------
29050 -- Find_Related_Declaration_Or_Body --
29051 --------------------------------------
29053 function Find_Related_Declaration_Or_Body
29055 Do_Checks
: Boolean := False) return Node_Id
29057 Prag_Nam
: constant Name_Id
:= Original_Aspect_Pragma_Name
(Prag
);
29059 procedure Expression_Function_Error
;
29060 -- Emit an error concerning pragma Prag that illegaly applies to an
29061 -- expression function.
29063 -------------------------------
29064 -- Expression_Function_Error --
29065 -------------------------------
29067 procedure Expression_Function_Error
is
29069 Error_Msg_Name_1
:= Prag_Nam
;
29071 -- Emit a precise message to distinguish between source pragmas and
29072 -- pragmas generated from aspects.
29074 if From_Aspect_Specification
(Prag
) then
29076 ("aspect % cannot apply to a stand alone expression function",
29080 ("pragma % cannot apply to a stand alone expression function",
29083 end Expression_Function_Error
;
29087 Context
: constant Node_Id
:= Parent
(Prag
);
29090 Look_For_Body
: constant Boolean :=
29091 Nam_In
(Prag_Nam
, Name_Refined_Depends
,
29092 Name_Refined_Global
,
29094 Name_Refined_State
);
29095 -- Refinement pragmas must be associated with a subprogram body [stub]
29097 -- Start of processing for Find_Related_Declaration_Or_Body
29100 Stmt
:= Prev
(Prag
);
29101 while Present
(Stmt
) loop
29103 -- Skip prior pragmas, but check for duplicates. Pragmas produced
29104 -- by splitting a complex pre/postcondition are not considered to
29107 if Nkind
(Stmt
) = N_Pragma
then
29109 and then not Split_PPC
(Stmt
)
29110 and then Original_Aspect_Pragma_Name
(Stmt
) = Prag_Nam
29117 -- Emit an error when a refinement pragma appears on an expression
29118 -- function without a completion.
29121 and then Look_For_Body
29122 and then Nkind
(Stmt
) = N_Subprogram_Declaration
29123 and then Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
29124 and then not Has_Completion
(Defining_Entity
(Stmt
))
29126 Expression_Function_Error
;
29129 -- The refinement pragma applies to a subprogram body stub
29131 elsif Look_For_Body
29132 and then Nkind
(Stmt
) = N_Subprogram_Body_Stub
29136 -- Skip internally generated code
29138 elsif not Comes_From_Source
(Stmt
) then
29140 -- The anonymous object created for a single concurrent type is a
29141 -- suitable context.
29143 if Nkind
(Stmt
) = N_Object_Declaration
29144 and then Is_Single_Concurrent_Object
(Defining_Entity
(Stmt
))
29148 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
then
29150 -- The subprogram declaration is an internally generated spec
29151 -- for an expression function.
29153 if Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
then
29156 -- The subprogram is actually an instance housed within an
29157 -- anonymous wrapper package.
29159 elsif Present
(Generic_Parent
(Specification
(Stmt
))) then
29164 -- Return the current construct which is either a subprogram body,
29165 -- a subprogram declaration or is illegal.
29174 -- If we fall through, then the pragma was either the first declaration
29175 -- or it was preceded by other pragmas and no source constructs.
29177 -- The pragma is associated with a library-level subprogram
29179 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
29180 return Unit
(Parent
(Context
));
29182 -- The pragma appears inside the declarations of an entry body
29184 elsif Nkind
(Context
) = N_Entry_Body
then
29187 -- The pragma appears inside the statements of a subprogram body. This
29188 -- placement is the result of subprogram contract expansion.
29190 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
then
29191 return Parent
(Context
);
29193 -- The pragma appears inside the declarative part of a package body
29195 elsif Nkind
(Context
) = N_Package_Body
then
29198 -- The pragma appears inside the declarative part of a subprogram body
29200 elsif Nkind
(Context
) = N_Subprogram_Body
then
29203 -- The pragma appears inside the declarative part of a task body
29205 elsif Nkind
(Context
) = N_Task_Body
then
29208 -- The pragma appears inside the visible part of a package specification
29210 elsif Nkind
(Context
) = N_Package_Specification
then
29211 return Parent
(Context
);
29213 -- The pragma is a byproduct of aspect expansion, return the related
29214 -- context of the original aspect. This case has a lower priority as
29215 -- the above circuitry pinpoints precisely the related context.
29217 elsif Present
(Corresponding_Aspect
(Prag
)) then
29218 return Parent
(Corresponding_Aspect
(Prag
));
29220 -- No candidate subprogram [body] found
29225 end Find_Related_Declaration_Or_Body
;
29227 ----------------------------------
29228 -- Find_Related_Package_Or_Body --
29229 ----------------------------------
29231 function Find_Related_Package_Or_Body
29233 Do_Checks
: Boolean := False) return Node_Id
29235 Context
: constant Node_Id
:= Parent
(Prag
);
29236 Prag_Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
29240 Stmt
:= Prev
(Prag
);
29241 while Present
(Stmt
) loop
29243 -- Skip prior pragmas, but check for duplicates
29245 if Nkind
(Stmt
) = N_Pragma
then
29246 if Do_Checks
and then Pragma_Name
(Stmt
) = Prag_Nam
then
29252 -- Skip internally generated code
29254 elsif not Comes_From_Source
(Stmt
) then
29255 if Nkind
(Stmt
) = N_Subprogram_Declaration
then
29257 -- The subprogram declaration is an internally generated spec
29258 -- for an expression function.
29260 if Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
then
29263 -- The subprogram is actually an instance housed within an
29264 -- anonymous wrapper package.
29266 elsif Present
(Generic_Parent
(Specification
(Stmt
))) then
29271 -- Return the current source construct which is illegal
29280 -- If we fall through, then the pragma was either the first declaration
29281 -- or it was preceded by other pragmas and no source constructs.
29283 -- The pragma is associated with a package. The immediate context in
29284 -- this case is the specification of the package.
29286 if Nkind
(Context
) = N_Package_Specification
then
29287 return Parent
(Context
);
29289 -- The pragma appears in the declarations of a package body
29291 elsif Nkind
(Context
) = N_Package_Body
then
29294 -- The pragma appears in the statements of a package body
29296 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
29297 and then Nkind
(Parent
(Context
)) = N_Package_Body
29299 return Parent
(Context
);
29301 -- The pragma is a byproduct of aspect expansion, return the related
29302 -- context of the original aspect. This case has a lower priority as
29303 -- the above circuitry pinpoints precisely the related context.
29305 elsif Present
(Corresponding_Aspect
(Prag
)) then
29306 return Parent
(Corresponding_Aspect
(Prag
));
29308 -- No candidate package [body] found
29313 end Find_Related_Package_Or_Body
;
29319 function Get_Argument
29321 Context_Id
: Entity_Id
:= Empty
) return Node_Id
29323 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
29326 -- Use the expression of the original aspect when compiling for ASIS or
29327 -- when analyzing the template of a generic unit. In both cases the
29328 -- aspect's tree must be decorated to allow for ASIS queries or to save
29329 -- the global references in the generic context.
29331 if From_Aspect_Specification
(Prag
)
29332 and then (ASIS_Mode
or else (Present
(Context_Id
)
29333 and then Is_Generic_Unit
(Context_Id
)))
29335 return Corresponding_Aspect
(Prag
);
29337 -- Otherwise use the expression of the pragma
29339 elsif Present
(Args
) then
29340 return First
(Args
);
29347 -------------------------
29348 -- Get_Base_Subprogram --
29349 -------------------------
29351 function Get_Base_Subprogram
(Def_Id
: Entity_Id
) return Entity_Id
is
29352 Result
: Entity_Id
;
29355 -- Follow subprogram renaming chain
29359 if Is_Subprogram
(Result
)
29361 Nkind
(Parent
(Declaration_Node
(Result
))) =
29362 N_Subprogram_Renaming_Declaration
29363 and then Present
(Alias
(Result
))
29365 Result
:= Alias
(Result
);
29369 end Get_Base_Subprogram
;
29371 -----------------------
29372 -- Get_SPARK_Mode_Type --
29373 -----------------------
29375 function Get_SPARK_Mode_Type
(N
: Name_Id
) return SPARK_Mode_Type
is
29377 if N
= Name_On
then
29379 elsif N
= Name_Off
then
29382 -- Any other argument is illegal. Assume that no SPARK mode applies to
29383 -- avoid potential cascaded errors.
29388 end Get_SPARK_Mode_Type
;
29390 ------------------------------------
29391 -- Get_SPARK_Mode_From_Annotation --
29392 ------------------------------------
29394 function Get_SPARK_Mode_From_Annotation
29395 (N
: Node_Id
) return SPARK_Mode_Type
29400 if Nkind
(N
) = N_Aspect_Specification
then
29401 Mode
:= Expression
(N
);
29403 else pragma Assert
(Nkind
(N
) = N_Pragma
);
29404 Mode
:= First
(Pragma_Argument_Associations
(N
));
29406 if Present
(Mode
) then
29407 Mode
:= Get_Pragma_Arg
(Mode
);
29411 -- Aspect or pragma SPARK_Mode specifies an explicit mode
29413 if Present
(Mode
) then
29414 if Nkind
(Mode
) = N_Identifier
then
29415 return Get_SPARK_Mode_Type
(Chars
(Mode
));
29417 -- In case of a malformed aspect or pragma, return the default None
29423 -- Otherwise the lack of an expression defaults SPARK_Mode to On
29428 end Get_SPARK_Mode_From_Annotation
;
29430 ---------------------------
29431 -- Has_Extra_Parentheses --
29432 ---------------------------
29434 function Has_Extra_Parentheses
(Clause
: Node_Id
) return Boolean is
29438 -- The aggregate should not have an expression list because a clause
29439 -- is always interpreted as a component association. The only way an
29440 -- expression list can sneak in is by adding extra parentheses around
29441 -- the individual clauses:
29443 -- Depends (Output => Input) -- proper form
29444 -- Depends ((Output => Input)) -- extra parentheses
29446 -- Since the extra parentheses are not allowed by the syntax of the
29447 -- pragma, flag them now to avoid emitting misleading errors down the
29450 if Nkind
(Clause
) = N_Aggregate
29451 and then Present
(Expressions
(Clause
))
29453 Expr
:= First
(Expressions
(Clause
));
29454 while Present
(Expr
) loop
29456 -- A dependency clause surrounded by extra parentheses appears
29457 -- as an aggregate of component associations with an optional
29458 -- Paren_Count set.
29460 if Nkind
(Expr
) = N_Aggregate
29461 and then Present
(Component_Associations
(Expr
))
29464 ("dependency clause contains extra parentheses", Expr
);
29466 -- Otherwise the expression is a malformed construct
29469 SPARK_Msg_N
("malformed dependency clause", Expr
);
29479 end Has_Extra_Parentheses
;
29485 procedure Initialize
is
29496 Dummy
:= Dummy
+ 1;
29499 -----------------------------
29500 -- Is_Config_Static_String --
29501 -----------------------------
29503 function Is_Config_Static_String
(Arg
: Node_Id
) return Boolean is
29505 function Add_Config_Static_String
(Arg
: Node_Id
) return Boolean;
29506 -- This is an internal recursive function that is just like the outer
29507 -- function except that it adds the string to the name buffer rather
29508 -- than placing the string in the name buffer.
29510 ------------------------------
29511 -- Add_Config_Static_String --
29512 ------------------------------
29514 function Add_Config_Static_String
(Arg
: Node_Id
) return Boolean is
29521 if Nkind
(N
) = N_Op_Concat
then
29522 if Add_Config_Static_String
(Left_Opnd
(N
)) then
29523 N
:= Right_Opnd
(N
);
29529 if Nkind
(N
) /= N_String_Literal
then
29530 Error_Msg_N
("string literal expected for pragma argument", N
);
29534 for J
in 1 .. String_Length
(Strval
(N
)) loop
29535 C
:= Get_String_Char
(Strval
(N
), J
);
29537 if not In_Character_Range
(C
) then
29539 ("string literal contains invalid wide character",
29540 Sloc
(N
) + 1 + Source_Ptr
(J
));
29544 Add_Char_To_Name_Buffer
(Get_Character
(C
));
29549 end Add_Config_Static_String
;
29551 -- Start of processing for Is_Config_Static_String
29556 return Add_Config_Static_String
(Arg
);
29557 end Is_Config_Static_String
;
29559 -------------------------------
29560 -- Is_Elaboration_SPARK_Mode --
29561 -------------------------------
29563 function Is_Elaboration_SPARK_Mode
(N
: Node_Id
) return Boolean is
29566 (Nkind
(N
) = N_Pragma
29567 and then Pragma_Name
(N
) = Name_SPARK_Mode
29568 and then Is_List_Member
(N
));
29570 -- Pragma SPARK_Mode affects the elaboration of a package body when it
29571 -- appears in the statement part of the body.
29574 Present
(Parent
(N
))
29575 and then Nkind
(Parent
(N
)) = N_Handled_Sequence_Of_Statements
29576 and then List_Containing
(N
) = Statements
(Parent
(N
))
29577 and then Present
(Parent
(Parent
(N
)))
29578 and then Nkind
(Parent
(Parent
(N
))) = N_Package_Body
;
29579 end Is_Elaboration_SPARK_Mode
;
29581 -----------------------
29582 -- Is_Enabled_Pragma --
29583 -----------------------
29585 function Is_Enabled_Pragma
(Prag
: Node_Id
) return Boolean is
29589 if Present
(Prag
) then
29590 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
29592 if Present
(Arg
) then
29593 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg
)));
29595 -- The lack of a Boolean argument automatically enables the pragma
29601 -- The pragma is missing, therefore it is not enabled
29606 end Is_Enabled_Pragma
;
29608 -----------------------------------------
29609 -- Is_Non_Significant_Pragma_Reference --
29610 -----------------------------------------
29612 -- This function makes use of the following static table which indicates
29613 -- whether appearance of some name in a given pragma is to be considered
29614 -- as a reference for the purposes of warnings about unreferenced objects.
29616 -- -1 indicates that appearence in any argument is significant
29617 -- 0 indicates that appearance in any argument is not significant
29618 -- +n indicates that appearance as argument n is significant, but all
29619 -- other arguments are not significant
29620 -- 9n arguments from n on are significant, before n insignificant
29622 Sig_Flags
: constant array (Pragma_Id
) of Int
:=
29623 (Pragma_Abort_Defer
=> -1,
29624 Pragma_Abstract_State
=> -1,
29625 Pragma_Ada_83
=> -1,
29626 Pragma_Ada_95
=> -1,
29627 Pragma_Ada_05
=> -1,
29628 Pragma_Ada_2005
=> -1,
29629 Pragma_Ada_12
=> -1,
29630 Pragma_Ada_2012
=> -1,
29631 Pragma_Ada_2020
=> -1,
29632 Pragma_All_Calls_Remote
=> -1,
29633 Pragma_Allow_Integer_Address
=> -1,
29634 Pragma_Annotate
=> 93,
29635 Pragma_Assert
=> -1,
29636 Pragma_Assert_And_Cut
=> -1,
29637 Pragma_Assertion_Policy
=> 0,
29638 Pragma_Assume
=> -1,
29639 Pragma_Assume_No_Invalid_Values
=> 0,
29640 Pragma_Async_Readers
=> 0,
29641 Pragma_Async_Writers
=> 0,
29642 Pragma_Asynchronous
=> 0,
29643 Pragma_Atomic
=> 0,
29644 Pragma_Atomic_Components
=> 0,
29645 Pragma_Attach_Handler
=> -1,
29646 Pragma_Attribute_Definition
=> 92,
29647 Pragma_Check
=> -1,
29648 Pragma_Check_Float_Overflow
=> 0,
29649 Pragma_Check_Name
=> 0,
29650 Pragma_Check_Policy
=> 0,
29651 Pragma_CPP_Class
=> 0,
29652 Pragma_CPP_Constructor
=> 0,
29653 Pragma_CPP_Virtual
=> 0,
29654 Pragma_CPP_Vtable
=> 0,
29656 Pragma_C_Pass_By_Copy
=> 0,
29657 Pragma_Comment
=> -1,
29658 Pragma_Common_Object
=> 0,
29659 Pragma_Compile_Time_Error
=> -1,
29660 Pragma_Compile_Time_Warning
=> -1,
29661 Pragma_Compiler_Unit
=> -1,
29662 Pragma_Compiler_Unit_Warning
=> -1,
29663 Pragma_Complete_Representation
=> 0,
29664 Pragma_Complex_Representation
=> 0,
29665 Pragma_Component_Alignment
=> 0,
29666 Pragma_Constant_After_Elaboration
=> 0,
29667 Pragma_Contract_Cases
=> -1,
29668 Pragma_Controlled
=> 0,
29669 Pragma_Convention
=> 0,
29670 Pragma_Convention_Identifier
=> 0,
29671 Pragma_Deadline_Floor
=> -1,
29672 Pragma_Debug
=> -1,
29673 Pragma_Debug_Policy
=> 0,
29674 Pragma_Detect_Blocking
=> 0,
29675 Pragma_Default_Initial_Condition
=> -1,
29676 Pragma_Default_Scalar_Storage_Order
=> 0,
29677 Pragma_Default_Storage_Pool
=> 0,
29678 Pragma_Depends
=> -1,
29679 Pragma_Disable_Atomic_Synchronization
=> 0,
29680 Pragma_Discard_Names
=> 0,
29681 Pragma_Dispatching_Domain
=> -1,
29682 Pragma_Effective_Reads
=> 0,
29683 Pragma_Effective_Writes
=> 0,
29684 Pragma_Elaborate
=> 0,
29685 Pragma_Elaborate_All
=> 0,
29686 Pragma_Elaborate_Body
=> 0,
29687 Pragma_Elaboration_Checks
=> 0,
29688 Pragma_Eliminate
=> 0,
29689 Pragma_Enable_Atomic_Synchronization
=> 0,
29690 Pragma_Export
=> -1,
29691 Pragma_Export_Function
=> -1,
29692 Pragma_Export_Object
=> -1,
29693 Pragma_Export_Procedure
=> -1,
29694 Pragma_Export_Value
=> -1,
29695 Pragma_Export_Valued_Procedure
=> -1,
29696 Pragma_Extend_System
=> -1,
29697 Pragma_Extensions_Allowed
=> 0,
29698 Pragma_Extensions_Visible
=> 0,
29699 Pragma_External
=> -1,
29700 Pragma_Favor_Top_Level
=> 0,
29701 Pragma_External_Name_Casing
=> 0,
29702 Pragma_Fast_Math
=> 0,
29703 Pragma_Finalize_Storage_Only
=> 0,
29705 Pragma_Global
=> -1,
29706 Pragma_Ident
=> -1,
29707 Pragma_Ignore_Pragma
=> 0,
29708 Pragma_Implementation_Defined
=> -1,
29709 Pragma_Implemented
=> -1,
29710 Pragma_Implicit_Packing
=> 0,
29711 Pragma_Import
=> 93,
29712 Pragma_Import_Function
=> 0,
29713 Pragma_Import_Object
=> 0,
29714 Pragma_Import_Procedure
=> 0,
29715 Pragma_Import_Valued_Procedure
=> 0,
29716 Pragma_Independent
=> 0,
29717 Pragma_Independent_Components
=> 0,
29718 Pragma_Initial_Condition
=> -1,
29719 Pragma_Initialize_Scalars
=> 0,
29720 Pragma_Initializes
=> -1,
29721 Pragma_Inline
=> 0,
29722 Pragma_Inline_Always
=> 0,
29723 Pragma_Inline_Generic
=> 0,
29724 Pragma_Inspection_Point
=> -1,
29725 Pragma_Interface
=> 92,
29726 Pragma_Interface_Name
=> 0,
29727 Pragma_Interrupt_Handler
=> -1,
29728 Pragma_Interrupt_Priority
=> -1,
29729 Pragma_Interrupt_State
=> -1,
29730 Pragma_Invariant
=> -1,
29731 Pragma_Keep_Names
=> 0,
29732 Pragma_License
=> 0,
29733 Pragma_Link_With
=> -1,
29734 Pragma_Linker_Alias
=> -1,
29735 Pragma_Linker_Constructor
=> -1,
29736 Pragma_Linker_Destructor
=> -1,
29737 Pragma_Linker_Options
=> -1,
29738 Pragma_Linker_Section
=> -1,
29740 Pragma_Lock_Free
=> 0,
29741 Pragma_Locking_Policy
=> 0,
29742 Pragma_Loop_Invariant
=> -1,
29743 Pragma_Loop_Optimize
=> 0,
29744 Pragma_Loop_Variant
=> -1,
29745 Pragma_Machine_Attribute
=> -1,
29747 Pragma_Main_Storage
=> -1,
29748 Pragma_Max_Queue_Length
=> 0,
29749 Pragma_Memory_Size
=> 0,
29750 Pragma_No_Return
=> 0,
29751 Pragma_No_Body
=> 0,
29752 Pragma_No_Component_Reordering
=> -1,
29753 Pragma_No_Elaboration_Code_All
=> 0,
29754 Pragma_No_Heap_Finalization
=> 0,
29755 Pragma_No_Inline
=> 0,
29756 Pragma_No_Run_Time
=> -1,
29757 Pragma_No_Strict_Aliasing
=> -1,
29758 Pragma_No_Tagged_Streams
=> 0,
29759 Pragma_Normalize_Scalars
=> 0,
29760 Pragma_Obsolescent
=> 0,
29761 Pragma_Optimize
=> 0,
29762 Pragma_Optimize_Alignment
=> 0,
29763 Pragma_Overflow_Mode
=> 0,
29764 Pragma_Overriding_Renamings
=> 0,
29765 Pragma_Ordered
=> 0,
29768 Pragma_Part_Of
=> 0,
29769 Pragma_Partition_Elaboration_Policy
=> 0,
29770 Pragma_Passive
=> 0,
29771 Pragma_Persistent_BSS
=> 0,
29772 Pragma_Polling
=> 0,
29773 Pragma_Prefix_Exception_Messages
=> 0,
29775 Pragma_Postcondition
=> -1,
29776 Pragma_Post_Class
=> -1,
29778 Pragma_Precondition
=> -1,
29779 Pragma_Predicate
=> -1,
29780 Pragma_Predicate_Failure
=> -1,
29781 Pragma_Preelaborable_Initialization
=> -1,
29782 Pragma_Preelaborate
=> 0,
29783 Pragma_Pre_Class
=> -1,
29784 Pragma_Priority
=> -1,
29785 Pragma_Priority_Specific_Dispatching
=> 0,
29786 Pragma_Profile
=> 0,
29787 Pragma_Profile_Warnings
=> 0,
29788 Pragma_Propagate_Exceptions
=> 0,
29789 Pragma_Provide_Shift_Operators
=> 0,
29790 Pragma_Psect_Object
=> 0,
29792 Pragma_Pure_Function
=> 0,
29793 Pragma_Queuing_Policy
=> 0,
29794 Pragma_Rational
=> 0,
29795 Pragma_Ravenscar
=> 0,
29796 Pragma_Refined_Depends
=> -1,
29797 Pragma_Refined_Global
=> -1,
29798 Pragma_Refined_Post
=> -1,
29799 Pragma_Refined_State
=> -1,
29800 Pragma_Relative_Deadline
=> 0,
29801 Pragma_Rename_Pragma
=> 0,
29802 Pragma_Remote_Access_Type
=> -1,
29803 Pragma_Remote_Call_Interface
=> -1,
29804 Pragma_Remote_Types
=> -1,
29805 Pragma_Restricted_Run_Time
=> 0,
29806 Pragma_Restriction_Warnings
=> 0,
29807 Pragma_Restrictions
=> 0,
29808 Pragma_Reviewable
=> -1,
29809 Pragma_Secondary_Stack_Size
=> -1,
29810 Pragma_Short_Circuit_And_Or
=> 0,
29811 Pragma_Share_Generic
=> 0,
29812 Pragma_Shared
=> 0,
29813 Pragma_Shared_Passive
=> 0,
29814 Pragma_Short_Descriptors
=> 0,
29815 Pragma_Simple_Storage_Pool_Type
=> 0,
29816 Pragma_Source_File_Name
=> 0,
29817 Pragma_Source_File_Name_Project
=> 0,
29818 Pragma_Source_Reference
=> 0,
29819 Pragma_SPARK_Mode
=> 0,
29820 Pragma_Storage_Size
=> -1,
29821 Pragma_Storage_Unit
=> 0,
29822 Pragma_Static_Elaboration_Desired
=> 0,
29823 Pragma_Stream_Convert
=> 0,
29824 Pragma_Style_Checks
=> 0,
29825 Pragma_Subtitle
=> 0,
29826 Pragma_Suppress
=> 0,
29827 Pragma_Suppress_Exception_Locations
=> 0,
29828 Pragma_Suppress_All
=> 0,
29829 Pragma_Suppress_Debug_Info
=> 0,
29830 Pragma_Suppress_Initialization
=> 0,
29831 Pragma_System_Name
=> 0,
29832 Pragma_Task_Dispatching_Policy
=> 0,
29833 Pragma_Task_Info
=> -1,
29834 Pragma_Task_Name
=> -1,
29835 Pragma_Task_Storage
=> -1,
29836 Pragma_Test_Case
=> -1,
29837 Pragma_Thread_Local_Storage
=> -1,
29838 Pragma_Time_Slice
=> -1,
29840 Pragma_Type_Invariant
=> -1,
29841 Pragma_Type_Invariant_Class
=> -1,
29842 Pragma_Unchecked_Union
=> 0,
29843 Pragma_Unevaluated_Use_Of_Old
=> 0,
29844 Pragma_Unimplemented_Unit
=> 0,
29845 Pragma_Universal_Aliasing
=> 0,
29846 Pragma_Universal_Data
=> 0,
29847 Pragma_Unmodified
=> 0,
29848 Pragma_Unreferenced
=> 0,
29849 Pragma_Unreferenced_Objects
=> 0,
29850 Pragma_Unreserve_All_Interrupts
=> 0,
29851 Pragma_Unsuppress
=> 0,
29852 Pragma_Unused
=> 0,
29853 Pragma_Use_VADS_Size
=> 0,
29854 Pragma_Validity_Checks
=> 0,
29855 Pragma_Volatile
=> 0,
29856 Pragma_Volatile_Components
=> 0,
29857 Pragma_Volatile_Full_Access
=> 0,
29858 Pragma_Volatile_Function
=> 0,
29859 Pragma_Warning_As_Error
=> 0,
29860 Pragma_Warnings
=> 0,
29861 Pragma_Weak_External
=> 0,
29862 Pragma_Wide_Character_Encoding
=> 0,
29863 Unknown_Pragma
=> 0);
29865 function Is_Non_Significant_Pragma_Reference
(N
: Node_Id
) return Boolean is
29871 function Arg_No
return Nat
;
29872 -- Returns an integer showing what argument we are in. A value of
29873 -- zero means we are not in any of the arguments.
29879 function Arg_No
return Nat
is
29884 A
:= First
(Pragma_Argument_Associations
(Parent
(P
)));
29898 -- Start of processing for Non_Significant_Pragma_Reference
29903 if Nkind
(P
) /= N_Pragma_Argument_Association
then
29907 Id
:= Get_Pragma_Id
(Parent
(P
));
29908 C
:= Sig_Flags
(Id
);
29923 return AN
< (C
- 90);
29929 end Is_Non_Significant_Pragma_Reference
;
29931 ------------------------------
29932 -- Is_Pragma_String_Literal --
29933 ------------------------------
29935 -- This function returns true if the corresponding pragma argument is a
29936 -- static string expression. These are the only cases in which string
29937 -- literals can appear as pragma arguments. We also allow a string literal
29938 -- as the first argument to pragma Assert (although it will of course
29939 -- always generate a type error).
29941 function Is_Pragma_String_Literal
(Par
: Node_Id
) return Boolean is
29942 Pragn
: constant Node_Id
:= Parent
(Par
);
29943 Assoc
: constant List_Id
:= Pragma_Argument_Associations
(Pragn
);
29944 Pname
: constant Name_Id
:= Pragma_Name
(Pragn
);
29950 N
:= First
(Assoc
);
29957 if Pname
= Name_Assert
then
29960 elsif Pname
= Name_Export
then
29963 elsif Pname
= Name_Ident
then
29966 elsif Pname
= Name_Import
then
29969 elsif Pname
= Name_Interface_Name
then
29972 elsif Pname
= Name_Linker_Alias
then
29975 elsif Pname
= Name_Linker_Section
then
29978 elsif Pname
= Name_Machine_Attribute
then
29981 elsif Pname
= Name_Source_File_Name
then
29984 elsif Pname
= Name_Source_Reference
then
29987 elsif Pname
= Name_Title
then
29990 elsif Pname
= Name_Subtitle
then
29996 end Is_Pragma_String_Literal
;
29998 ---------------------------
29999 -- Is_Private_SPARK_Mode --
30000 ---------------------------
30002 function Is_Private_SPARK_Mode
(N
: Node_Id
) return Boolean is
30005 (Nkind
(N
) = N_Pragma
30006 and then Pragma_Name
(N
) = Name_SPARK_Mode
30007 and then Is_List_Member
(N
));
30009 -- For pragma SPARK_Mode to be private, it has to appear in the private
30010 -- declarations of a package.
30013 Present
(Parent
(N
))
30014 and then Nkind
(Parent
(N
)) = N_Package_Specification
30015 and then List_Containing
(N
) = Private_Declarations
(Parent
(N
));
30016 end Is_Private_SPARK_Mode
;
30018 -------------------------------------
30019 -- Is_Unconstrained_Or_Tagged_Item --
30020 -------------------------------------
30022 function Is_Unconstrained_Or_Tagged_Item
30023 (Item
: Entity_Id
) return Boolean
30025 function Has_Unconstrained_Component
(Typ
: Entity_Id
) return Boolean;
30026 -- Determine whether record type Typ has at least one unconstrained
30029 ---------------------------------
30030 -- Has_Unconstrained_Component --
30031 ---------------------------------
30033 function Has_Unconstrained_Component
(Typ
: Entity_Id
) return Boolean is
30037 Comp
:= First_Component
(Typ
);
30038 while Present
(Comp
) loop
30039 if Is_Unconstrained_Or_Tagged_Item
(Comp
) then
30043 Next_Component
(Comp
);
30047 end Has_Unconstrained_Component
;
30051 Typ
: constant Entity_Id
:= Etype
(Item
);
30053 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
30056 if Is_Tagged_Type
(Typ
) then
30059 elsif Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
) then
30062 elsif Is_Record_Type
(Typ
) then
30063 if Has_Discriminants
(Typ
) and then not Is_Constrained
(Typ
) then
30066 return Has_Unconstrained_Component
(Typ
);
30069 elsif Is_Private_Type
(Typ
) and then Has_Discriminants
(Typ
) then
30075 end Is_Unconstrained_Or_Tagged_Item
;
30077 -----------------------------
30078 -- Is_Valid_Assertion_Kind --
30079 -----------------------------
30081 function Is_Valid_Assertion_Kind
(Nam
: Name_Id
) return Boolean is
30088 | Name_Assertion_Policy
30089 | Name_Static_Predicate
30090 | Name_Dynamic_Predicate
30095 | Name_Type_Invariant
30096 | Name_uType_Invariant
30100 | Name_Assert_And_Cut
30102 | Name_Contract_Cases
30104 | Name_Default_Initial_Condition
30106 | Name_Initial_Condition
30109 | Name_Loop_Invariant
30110 | Name_Loop_Variant
30111 | Name_Postcondition
30112 | Name_Precondition
30114 | Name_Refined_Post
30115 | Name_Statement_Assertions
30122 end Is_Valid_Assertion_Kind
;
30124 --------------------------------------
30125 -- Process_Compilation_Unit_Pragmas --
30126 --------------------------------------
30128 procedure Process_Compilation_Unit_Pragmas
(N
: Node_Id
) is
30130 -- A special check for pragma Suppress_All, a very strange DEC pragma,
30131 -- strange because it comes at the end of the unit. Rational has the
30132 -- same name for a pragma, but treats it as a program unit pragma, In
30133 -- GNAT we just decide to allow it anywhere at all. If it appeared then
30134 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
30135 -- node, and we insert a pragma Suppress (All_Checks) at the start of
30136 -- the context clause to ensure the correct processing.
30138 if Has_Pragma_Suppress_All
(N
) then
30139 Prepend_To
(Context_Items
(N
),
30140 Make_Pragma
(Sloc
(N
),
30141 Chars
=> Name_Suppress
,
30142 Pragma_Argument_Associations
=> New_List
(
30143 Make_Pragma_Argument_Association
(Sloc
(N
),
30144 Expression
=> Make_Identifier
(Sloc
(N
), Name_All_Checks
)))));
30147 -- Nothing else to do at the current time
30149 end Process_Compilation_Unit_Pragmas
;
30151 -------------------------------------------
30152 -- Process_Compile_Time_Warning_Or_Error --
30153 -------------------------------------------
30155 procedure Process_Compile_Time_Warning_Or_Error
30159 Arg1
: constant Node_Id
:= First
(Pragma_Argument_Associations
(N
));
30160 Arg1x
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
30161 Arg2
: constant Node_Id
:= Next
(Arg1
);
30164 Analyze_And_Resolve
(Arg1x
, Standard_Boolean
);
30166 if Compile_Time_Known_Value
(Arg1x
) then
30167 if Is_True
(Expr_Value
(Arg1x
)) then
30169 Cent
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
30170 Pname
: constant Name_Id
:= Pragma_Name_Unmapped
(N
);
30171 Prag_Id
: constant Pragma_Id
:= Get_Pragma_Id
(Pname
);
30172 Str
: constant String_Id
:= Strval
(Get_Pragma_Arg
(Arg2
));
30173 Str_Len
: constant Nat
:= String_Length
(Str
);
30175 Force
: constant Boolean :=
30176 Prag_Id
= Pragma_Compile_Time_Warning
30177 and then Is_Spec_Name
(Unit_Name
(Current_Sem_Unit
))
30178 and then (Ekind
(Cent
) /= E_Package
30179 or else not In_Private_Part
(Cent
));
30180 -- Set True if this is the warning case, and we are in the
30181 -- visible part of a package spec, or in a subprogram spec,
30182 -- in which case we want to force the client to see the
30183 -- warning, even though it is not in the main unit.
30191 -- Loop through segments of message separated by line feeds.
30192 -- We output these segments as separate messages with
30193 -- continuation marks for all but the first.
30198 Error_Msg_Strlen
:= 0;
30200 -- Loop to copy characters from argument to error message
30204 exit when Ptr
> Str_Len
;
30205 CC
:= Get_String_Char
(Str
, Ptr
);
30208 -- Ignore wide chars ??? else store character
30210 if In_Character_Range
(CC
) then
30211 C
:= Get_Character
(CC
);
30212 exit when C
= ASCII
.LF
;
30213 Error_Msg_Strlen
:= Error_Msg_Strlen
+ 1;
30214 Error_Msg_String
(Error_Msg_Strlen
) := C
;
30218 -- Here with one line ready to go
30220 Error_Msg_Warn
:= Prag_Id
= Pragma_Compile_Time_Warning
;
30222 -- If this is a warning in a spec, then we want clients
30223 -- to see the warning, so mark the message with the
30224 -- special sequence !! to force the warning. In the case
30225 -- of a package spec, we do not force this if we are in
30226 -- the private part of the spec.
30229 if Cont
= False then
30230 Error_Msg
("<<~!!", Eloc
);
30233 Error_Msg
("\<<~!!", Eloc
);
30236 -- Error, rather than warning, or in a body, so we do not
30237 -- need to force visibility for client (error will be
30238 -- output in any case, and this is the situation in which
30239 -- we do not want a client to get a warning, since the
30240 -- warning is in the body or the spec private part).
30243 if Cont
= False then
30244 Error_Msg
("<<~", Eloc
);
30247 Error_Msg
("\<<~", Eloc
);
30251 exit when Ptr
> Str_Len
;
30256 end Process_Compile_Time_Warning_Or_Error
;
30258 ------------------------------------
30259 -- Record_Possible_Body_Reference --
30260 ------------------------------------
30262 procedure Record_Possible_Body_Reference
30263 (State_Id
: Entity_Id
;
30267 Spec_Id
: Entity_Id
;
30270 -- Ensure that we are dealing with a reference to a state
30272 pragma Assert
(Ekind
(State_Id
) = E_Abstract_State
);
30274 -- Climb the tree starting from the reference looking for a package body
30275 -- whose spec declares the referenced state. This criteria automatically
30276 -- excludes references in package specs which are legal. Note that it is
30277 -- not wise to emit an error now as the package body may lack pragma
30278 -- Refined_State or the referenced state may not be mentioned in the
30279 -- refinement. This approach avoids the generation of misleading errors.
30282 while Present
(Context
) loop
30283 if Nkind
(Context
) = N_Package_Body
then
30284 Spec_Id
:= Corresponding_Spec
(Context
);
30286 if Present
(Abstract_States
(Spec_Id
))
30287 and then Contains
(Abstract_States
(Spec_Id
), State_Id
)
30289 if No
(Body_References
(State_Id
)) then
30290 Set_Body_References
(State_Id
, New_Elmt_List
);
30293 Append_Elmt
(Ref
, To
=> Body_References
(State_Id
));
30298 Context
:= Parent
(Context
);
30300 end Record_Possible_Body_Reference
;
30302 ------------------------------------------
30303 -- Relocate_Pragmas_To_Anonymous_Object --
30304 ------------------------------------------
30306 procedure Relocate_Pragmas_To_Anonymous_Object
30307 (Typ_Decl
: Node_Id
;
30308 Obj_Decl
: Node_Id
)
30312 Next_Decl
: Node_Id
;
30315 if Nkind
(Typ_Decl
) = N_Protected_Type_Declaration
then
30316 Def
:= Protected_Definition
(Typ_Decl
);
30318 pragma Assert
(Nkind
(Typ_Decl
) = N_Task_Type_Declaration
);
30319 Def
:= Task_Definition
(Typ_Decl
);
30322 -- The concurrent definition has a visible declaration list. Inspect it
30323 -- and relocate all canidate pragmas.
30325 if Present
(Def
) and then Present
(Visible_Declarations
(Def
)) then
30326 Decl
:= First
(Visible_Declarations
(Def
));
30327 while Present
(Decl
) loop
30329 -- Preserve the following declaration for iteration purposes due
30330 -- to possible relocation of a pragma.
30332 Next_Decl
:= Next
(Decl
);
30334 if Nkind
(Decl
) = N_Pragma
30335 and then Pragma_On_Anonymous_Object_OK
(Get_Pragma_Id
(Decl
))
30338 Insert_After
(Obj_Decl
, Decl
);
30340 -- Skip internally generated code
30342 elsif not Comes_From_Source
(Decl
) then
30345 -- No candidate pragmas are available for relocation
30354 end Relocate_Pragmas_To_Anonymous_Object
;
30356 ------------------------------
30357 -- Relocate_Pragmas_To_Body --
30358 ------------------------------
30360 procedure Relocate_Pragmas_To_Body
30361 (Subp_Body
: Node_Id
;
30362 Target_Body
: Node_Id
:= Empty
)
30364 procedure Relocate_Pragma
(Prag
: Node_Id
);
30365 -- Remove a single pragma from its current list and add it to the
30366 -- declarations of the proper body (either Subp_Body or Target_Body).
30368 ---------------------
30369 -- Relocate_Pragma --
30370 ---------------------
30372 procedure Relocate_Pragma
(Prag
: Node_Id
) is
30377 -- When subprogram stubs or expression functions are involves, the
30378 -- destination declaration list belongs to the proper body.
30380 if Present
(Target_Body
) then
30381 Target
:= Target_Body
;
30383 Target
:= Subp_Body
;
30386 Decls
:= Declarations
(Target
);
30390 Set_Declarations
(Target
, Decls
);
30393 -- Unhook the pragma from its current list
30396 Prepend
(Prag
, Decls
);
30397 end Relocate_Pragma
;
30401 Body_Id
: constant Entity_Id
:=
30402 Defining_Unit_Name
(Specification
(Subp_Body
));
30403 Next_Stmt
: Node_Id
;
30406 -- Start of processing for Relocate_Pragmas_To_Body
30409 -- Do not process a body that comes from a separate unit as no construct
30410 -- can possibly follow it.
30412 if not Is_List_Member
(Subp_Body
) then
30415 -- Do not relocate pragmas that follow a stub if the stub does not have
30418 elsif Nkind
(Subp_Body
) = N_Subprogram_Body_Stub
30419 and then No
(Target_Body
)
30423 -- Do not process internally generated routine _Postconditions
30425 elsif Ekind
(Body_Id
) = E_Procedure
30426 and then Chars
(Body_Id
) = Name_uPostconditions
30431 -- Look at what is following the body. We are interested in certain kind
30432 -- of pragmas (either from source or byproducts of expansion) that can
30433 -- apply to a body [stub].
30435 Stmt
:= Next
(Subp_Body
);
30436 while Present
(Stmt
) loop
30438 -- Preserve the following statement for iteration purposes due to a
30439 -- possible relocation of a pragma.
30441 Next_Stmt
:= Next
(Stmt
);
30443 -- Move a candidate pragma following the body to the declarations of
30446 if Nkind
(Stmt
) = N_Pragma
30447 and then Pragma_On_Body_Or_Stub_OK
(Get_Pragma_Id
(Stmt
))
30450 -- If a source pragma Warnings follows the body, it applies to
30451 -- following statements and does not belong in the body.
30453 if Get_Pragma_Id
(Stmt
) = Pragma_Warnings
30454 and then Comes_From_Source
(Stmt
)
30458 Relocate_Pragma
(Stmt
);
30461 -- Skip internally generated code
30463 elsif not Comes_From_Source
(Stmt
) then
30466 -- No candidate pragmas are available for relocation
30474 end Relocate_Pragmas_To_Body
;
30476 -------------------
30477 -- Resolve_State --
30478 -------------------
30480 procedure Resolve_State
(N
: Node_Id
) is
30485 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
30486 Func
:= Entity
(N
);
30488 -- Handle overloading of state names by functions. Traverse the
30489 -- homonym chain looking for an abstract state.
30491 if Ekind
(Func
) = E_Function
and then Has_Homonym
(Func
) then
30492 pragma Assert
(Is_Overloaded
(N
));
30494 State
:= Homonym
(Func
);
30495 while Present
(State
) loop
30496 if Ekind
(State
) = E_Abstract_State
then
30498 -- Resolve the overloading by setting the proper entity of
30499 -- the reference to that of the state.
30501 Set_Etype
(N
, Standard_Void_Type
);
30502 Set_Entity
(N
, State
);
30503 Set_Is_Overloaded
(N
, False);
30505 Generate_Reference
(State
, N
);
30509 State
:= Homonym
(State
);
30512 -- A function can never act as a state. If the homonym chain does
30513 -- not contain a corresponding state, then something went wrong in
30514 -- the overloading mechanism.
30516 raise Program_Error
;
30521 ----------------------------
30522 -- Rewrite_Assertion_Kind --
30523 ----------------------------
30525 procedure Rewrite_Assertion_Kind
30527 From_Policy
: Boolean := False)
30533 if Nkind
(N
) = N_Attribute_Reference
30534 and then Attribute_Name
(N
) = Name_Class
30535 and then Nkind
(Prefix
(N
)) = N_Identifier
30537 case Chars
(Prefix
(N
)) is
30544 when Name_Type_Invariant
=>
30545 Nam
:= Name_uType_Invariant
;
30547 when Name_Invariant
=>
30548 Nam
:= Name_uInvariant
;
30554 -- Recommend standard use of aspect names Pre/Post
30556 elsif Nkind
(N
) = N_Identifier
30557 and then From_Policy
30558 and then Serious_Errors_Detected
= 0
30559 and then not ASIS_Mode
30561 if Chars
(N
) = Name_Precondition
30562 or else Chars
(N
) = Name_Postcondition
30564 Error_Msg_N
("Check_Policy is a non-standard pragma??", N
);
30566 ("\use Assertion_Policy and aspect names Pre/Post for "
30567 & "Ada2012 conformance?", N
);
30573 if Nam
/= No_Name
then
30574 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Chars
=> Nam
));
30576 end Rewrite_Assertion_Kind
;
30584 Dummy
:= Dummy
+ 1;
30587 --------------------------------
30588 -- Set_Encoded_Interface_Name --
30589 --------------------------------
30591 procedure Set_Encoded_Interface_Name
(E
: Entity_Id
; S
: Node_Id
) is
30592 Str
: constant String_Id
:= Strval
(S
);
30593 Len
: constant Nat
:= String_Length
(Str
);
30598 Hex
: constant array (0 .. 15) of Character := "0123456789abcdef";
30601 -- Stores encoded value of character code CC. The encoding we use an
30602 -- underscore followed by four lower case hex digits.
30608 procedure Encode
is
30610 Store_String_Char
(Get_Char_Code
('_'));
30612 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 12))));
30614 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 8 and 16#
0F#
))));
30616 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 4 and 16#
0F#
))));
30618 (Get_Char_Code
(Hex
(Integer (CC
and 16#
0F#
))));
30621 -- Start of processing for Set_Encoded_Interface_Name
30624 -- If first character is asterisk, this is a link name, and we leave it
30625 -- completely unmodified. We also ignore null strings (the latter case
30626 -- happens only in error cases).
30629 or else Get_String_Char
(Str
, 1) = Get_Char_Code
('*')
30631 Set_Interface_Name
(E
, S
);
30636 CC
:= Get_String_Char
(Str
, J
);
30638 exit when not In_Character_Range
(CC
);
30640 C
:= Get_Character
(CC
);
30642 exit when C
/= '_' and then C
/= '$'
30643 and then C
not in '0' .. '9'
30644 and then C
not in 'a' .. 'z'
30645 and then C
not in 'A' .. 'Z';
30648 Set_Interface_Name
(E
, S
);
30656 -- Here we need to encode. The encoding we use as follows:
30657 -- three underscores + four hex digits (lower case)
30661 for J
in 1 .. String_Length
(Str
) loop
30662 CC
:= Get_String_Char
(Str
, J
);
30664 if not In_Character_Range
(CC
) then
30667 C
:= Get_Character
(CC
);
30669 if C
= '_' or else C
= '$'
30670 or else C
in '0' .. '9'
30671 or else C
in 'a' .. 'z'
30672 or else C
in 'A' .. 'Z'
30674 Store_String_Char
(CC
);
30681 Set_Interface_Name
(E
,
30682 Make_String_Literal
(Sloc
(S
),
30683 Strval
=> End_String
));
30685 end Set_Encoded_Interface_Name
;
30687 ------------------------
30688 -- Set_Elab_Unit_Name --
30689 ------------------------
30691 procedure Set_Elab_Unit_Name
(N
: Node_Id
; With_Item
: Node_Id
) is
30696 if Nkind
(N
) = N_Identifier
30697 and then Nkind
(With_Item
) = N_Identifier
30699 Set_Entity
(N
, Entity
(With_Item
));
30701 elsif Nkind
(N
) = N_Selected_Component
then
30702 Change_Selected_Component_To_Expanded_Name
(N
);
30703 Set_Entity
(N
, Entity
(With_Item
));
30704 Set_Entity
(Selector_Name
(N
), Entity
(N
));
30706 Pref
:= Prefix
(N
);
30707 Scop
:= Scope
(Entity
(N
));
30708 while Nkind
(Pref
) = N_Selected_Component
loop
30709 Change_Selected_Component_To_Expanded_Name
(Pref
);
30710 Set_Entity
(Selector_Name
(Pref
), Scop
);
30711 Set_Entity
(Pref
, Scop
);
30712 Pref
:= Prefix
(Pref
);
30713 Scop
:= Scope
(Scop
);
30716 Set_Entity
(Pref
, Scop
);
30719 Generate_Reference
(Entity
(With_Item
), N
, Set_Ref
=> False);
30720 end Set_Elab_Unit_Name
;
30722 -------------------
30723 -- Test_Case_Arg --
30724 -------------------
30726 function Test_Case_Arg
30729 From_Aspect
: Boolean := False) return Node_Id
30731 Aspect
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
30736 pragma Assert
(Nam_In
(Arg_Nam
, Name_Ensures
,
30741 -- The caller requests the aspect argument
30743 if From_Aspect
then
30744 if Present
(Aspect
)
30745 and then Nkind
(Expression
(Aspect
)) = N_Aggregate
30747 Args
:= Expression
(Aspect
);
30749 -- "Name" and "Mode" may appear without an identifier as a
30750 -- positional association.
30752 if Present
(Expressions
(Args
)) then
30753 Arg
:= First
(Expressions
(Args
));
30755 if Present
(Arg
) and then Arg_Nam
= Name_Name
then
30763 if Present
(Arg
) and then Arg_Nam
= Name_Mode
then
30768 -- Some or all arguments may appear as component associatons
30770 if Present
(Component_Associations
(Args
)) then
30771 Arg
:= First
(Component_Associations
(Args
));
30772 while Present
(Arg
) loop
30773 if Chars
(First
(Choices
(Arg
))) = Arg_Nam
then
30782 -- Otherwise retrieve the argument directly from the pragma
30785 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
30787 if Present
(Arg
) and then Arg_Nam
= Name_Name
then
30791 -- Skip argument "Name"
30795 if Present
(Arg
) and then Arg_Nam
= Name_Mode
then
30799 -- Skip argument "Mode"
30803 -- Arguments "Requires" and "Ensures" are optional and may not be
30806 while Present
(Arg
) loop
30807 if Chars
(Arg
) = Arg_Nam
then